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

environment.ts

122 lines5.3 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 /** Server understands thread.visit / thread.mark-unread commands and
57 projects lastVisitedAt on thread shells. Same version-skew contract as
58 threadSettlement: clients keep their local visited state against
59 servers that lack this. */
60 threadVisitedTracking: Schema.optionalKey(Schema.Boolean),
61 /** The update path clients should offer for this server. Absent on
62 servers that must be relaunched manually (dev checkouts, Windows
63 foreground runs, pre-update servers). */
64 serverSelfUpdate: Schema.optionalKey(ServerSelfUpdateCapability),
65 /** Server can stream self-update progress before acknowledging the
66 restart. Clients fall back to server.updateServer when absent. */
67 serverSelfUpdateProgress: Schema.optionalKey(Schema.Boolean),
68});
69export type ExecutionEnvironmentCapabilities = typeof ExecutionEnvironmentCapabilities.Type;
70​
71export const ExecutionEnvironmentDescriptor = Schema.Struct({
72 environmentId: EnvironmentId,
73 label: TrimmedNonEmptyString,
74 platform: ExecutionEnvironmentPlatform,
75 serverVersion: TrimmedNonEmptyString,
76 capabilities: ExecutionEnvironmentCapabilities,
77});
78export type ExecutionEnvironmentDescriptor = typeof ExecutionEnvironmentDescriptor.Type;
79​
80export const EnvironmentConnectionState = Schema.Literals([
81 "connecting",
82 "connected",
83 "disconnected",
84 "error",
85]);
86export type EnvironmentConnectionState = typeof EnvironmentConnectionState.Type;
87​
88export const RepositoryIdentityLocator = Schema.Struct({
89 source: Schema.Literal("git-remote"),
90 remoteName: TrimmedNonEmptyString,
91 remoteUrl: TrimmedNonEmptyString,
92});
93export type RepositoryIdentityLocator = typeof RepositoryIdentityLocator.Type;
94​
95export const RepositoryIdentity = Schema.Struct({
96 canonicalKey: TrimmedNonEmptyString,
97 locator: RepositoryIdentityLocator,
98 rootPath: Schema.optionalKey(TrimmedNonEmptyString),
99 displayName: Schema.optionalKey(TrimmedNonEmptyString),
100 provider: Schema.optionalKey(TrimmedNonEmptyString),
101 owner: Schema.optionalKey(TrimmedNonEmptyString),
102 name: Schema.optionalKey(TrimmedNonEmptyString),
103});
104export type RepositoryIdentity = typeof RepositoryIdentity.Type;
105​
106export const ScopedProjectRef = Schema.Struct({
107 environmentId: EnvironmentId,
108 projectId: ProjectId,
109});
110export type ScopedProjectRef = typeof ScopedProjectRef.Type;
111​
112export const ScopedThreadRef = Schema.Struct({
113 environmentId: EnvironmentId,
114 threadId: ThreadId,
115});
116export type ScopedThreadRef = typeof ScopedThreadRef.Type;
117​
118export const ScopedThreadSessionRef = Schema.Struct({
119 environmentId: EnvironmentId,
120 threadId: ThreadId,
121});
122export type ScopedThreadSessionRef = typeof ScopedThreadSessionRef.Type;