Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

environment.ts

117 lines4.9 KB

1import * as Effect from "effect/Effect";
2import * as Schema from "effect/Schema";
3​
4import { EnvironmentId, ProjectId, ThreadId, TrimmedNonEmptyString } from "./baseSchemas.ts";
5​
6export const ExecutionEnvironmentPlatformOs = Schema.Literals([
7 "darwin",
8 "linux",
9 "windows",
10 "unknown",
11]);
12export type ExecutionEnvironmentPlatformOs = typeof ExecutionEnvironmentPlatformOs.Type;
13​
14export const ExecutionEnvironmentPlatformArch = Schema.Literals(["arm64", "x64", "other"]);
15export type ExecutionEnvironmentPlatformArch = typeof ExecutionEnvironmentPlatformArch.Type;
16​
17export const ExecutionEnvironmentPlatform = Schema.Struct({
18 os: ExecutionEnvironmentPlatformOs,
19 arch: ExecutionEnvironmentPlatformArch,
20});
21export type ExecutionEnvironmentPlatform = typeof ExecutionEnvironmentPlatform.Type;
22​
23/** How a server can replace itself with another version when asked over RPC.
24 New servers only advertise the stable launcher-backed "boot-service" path;
25 "respawn" remains decodable for compatibility with older servers. */
26export const ServerSelfUpdateMethod = Schema.Literals(["boot-service", "respawn"]);
27export type ServerSelfUpdateMethod = typeof ServerSelfUpdateMethod.Type;
28​
29/** What update path a client should offer for a server: one of the RPC
30 self-update methods above, or "desktop-managed" when the backend's
31 version belongs to the T3 Code desktop app supervising it — updating the
32 app on that machine is the only way to update the server. */
33export const ServerSelfUpdateCapability = Schema.Literals([
34 "boot-service",
35 "respawn",
36 "desktop-managed",
37]);
38export type ServerSelfUpdateCapability = typeof ServerSelfUpdateCapability.Type;
39​
40export const ExecutionEnvironmentCapabilities = Schema.Struct({
41 repositoryIdentity: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(false))),
42 connectionProbe: Schema.optionalKey(Schema.Boolean),
43 /** Server understands thread.settle / thread.unsettle commands. Absent on
44 pre-settlement servers, so clients treat missing as unsupported and
45 never send the commands under version skew. */
46 threadSettlement: Schema.optionalKey(Schema.Boolean),
47 /** Server understands thread.snooze / thread.unsnooze commands. Same
48 version-skew contract as threadSettlement. */
49 threadSnooze: Schema.optionalKey(Schema.Boolean),
50 /** Server understands thread.pin / thread.unpin commands. Same
51 version-skew contract as threadSettlement. */
52 threadPinning: Schema.optionalKey(Schema.Boolean),
53 /** Server understands regenerateTitle on thread.meta.update. Absent on
54 older servers, so clients hide the action instead of sending it. */
55 threadTitleRegeneration: Schema.optionalKey(Schema.Boolean),
56 /** The update path clients should offer for this server. Absent on
57 servers that must be relaunched manually (dev checkouts, Windows
58 foreground runs, pre-update servers). */
59 serverSelfUpdate: Schema.optionalKey(ServerSelfUpdateCapability),
60 /** Server can stream self-update progress before acknowledging the
61 restart. Clients fall back to server.updateServer when absent. */
62 serverSelfUpdateProgress: Schema.optionalKey(Schema.Boolean),
63});
64export type ExecutionEnvironmentCapabilities = typeof ExecutionEnvironmentCapabilities.Type;
65​
66export const ExecutionEnvironmentDescriptor = Schema.Struct({
67 environmentId: EnvironmentId,
68 label: TrimmedNonEmptyString,
69 platform: ExecutionEnvironmentPlatform,
70 serverVersion: TrimmedNonEmptyString,
71 capabilities: ExecutionEnvironmentCapabilities,
72});
73export type ExecutionEnvironmentDescriptor = typeof ExecutionEnvironmentDescriptor.Type;
74​
75export const EnvironmentConnectionState = Schema.Literals([
76 "connecting",
77 "connected",
78 "disconnected",
79 "error",
80]);
81export type EnvironmentConnectionState = typeof EnvironmentConnectionState.Type;
82​
83export const RepositoryIdentityLocator = Schema.Struct({
84 source: Schema.Literal("git-remote"),
85 remoteName: TrimmedNonEmptyString,
86 remoteUrl: TrimmedNonEmptyString,
87});
88export type RepositoryIdentityLocator = typeof RepositoryIdentityLocator.Type;
89​
90export const RepositoryIdentity = Schema.Struct({
91 canonicalKey: TrimmedNonEmptyString,
92 locator: RepositoryIdentityLocator,
93 rootPath: Schema.optionalKey(TrimmedNonEmptyString),
94 displayName: Schema.optionalKey(TrimmedNonEmptyString),
95 provider: Schema.optionalKey(TrimmedNonEmptyString),
96 owner: Schema.optionalKey(TrimmedNonEmptyString),
97 name: Schema.optionalKey(TrimmedNonEmptyString),
98});
99export type RepositoryIdentity = typeof RepositoryIdentity.Type;
100​
101export const ScopedProjectRef = Schema.Struct({
102 environmentId: EnvironmentId,
103 projectId: ProjectId,
104});
105export type ScopedProjectRef = typeof ScopedProjectRef.Type;
106​
107export const ScopedThreadRef = Schema.Struct({
108 environmentId: EnvironmentId,
109 threadId: ThreadId,
110});
111export type ScopedThreadRef = typeof ScopedThreadRef.Type;
112​
113export const ScopedThreadSessionRef = Schema.Struct({
114 environmentId: EnvironmentId,
115 threadId: ThreadId,
116});
117export type ScopedThreadSessionRef = typeof ScopedThreadSessionRef.Type;