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

environment.ts

211 lines9.2 KB

1import * as Effect from "effect/Effect";
2import * as Schema from "effect/Schema";
3​
4import {
5 EnvironmentId,
6 ForwardCompatibleOptional,
7 ProjectId,
8 ThreadId,
9 TrimmedNonEmptyString,
10} from "./baseSchemas.ts";
11​
12export const ORCHESTRATION_PROTOCOL_VERSION = 2;
13export const ORCHESTRATION_PROTOCOL_VERSION_TEXT = "2";
14export const ORCHESTRATION_PROTOCOL_QUERY_PARAM = "orchestrationProtocol";
15export const ORCHESTRATION_PROTOCOL_HEADER = "x-t3-orchestration-protocol";
16​
17export const ExecutionEnvironmentPlatformOs = Schema.Literals([
18 "darwin",
19 "linux",
20 "windows",
21 "unknown",
22]);
23export type ExecutionEnvironmentPlatformOs = typeof ExecutionEnvironmentPlatformOs.Type;
24​
25export const ExecutionEnvironmentPlatformArch = Schema.Literals(["arm64", "x64", "other"]);
26export type ExecutionEnvironmentPlatformArch = typeof ExecutionEnvironmentPlatformArch.Type;
27​
28export const ENVIRONMENT_MACHINE_KINDS = [
29 "server",
30 "cloud",
31 "linux",
32 "desktop",
33 "laptop",
34 "mac-mini",
35 "mac-studio",
36] as const;
37export const EnvironmentMachineKind = Schema.Literals(ENVIRONMENT_MACHINE_KINDS);
38export type EnvironmentMachineKind = typeof EnvironmentMachineKind.Type;
39export const isEnvironmentMachineKind = Schema.is(EnvironmentMachineKind);
40​
41export const ExecutionEnvironmentPlatform = Schema.Struct({
42 os: ExecutionEnvironmentPlatformOs,
43 arch: ExecutionEnvironmentPlatformArch,
44 machine: ForwardCompatibleOptional(EnvironmentMachineKind),
45});
46​
47/**
48 * Lives here (not settings.ts) so orchestration contracts can reference it
49 * without an import cycle.
50 */
51export const ThreadEnvMode = Schema.Literals(["local", "worktree"]);
52export type ThreadEnvMode = typeof ThreadEnvMode.Type;
53​
54export const WorktreeSubmodules = Schema.Literals(["recursive", "top-level", "none"]);
55export type WorktreeSubmodules = typeof WorktreeSubmodules.Type;
56export type ExecutionEnvironmentPlatform = typeof ExecutionEnvironmentPlatform.Type;
57​
58export const ServerSelfUpdateMethod = Schema.Literals(["boot-service", "respawn", "desktop-app"]);
59export type ServerSelfUpdateMethod = typeof ServerSelfUpdateMethod.Type;
60​
61export const ServerInstallation = Schema.Union([
62 Schema.Struct({ kind: Schema.Literals(["npx", "pnpm-dlx", "bunx"]) }),
63 Schema.Struct({ kind: Schema.Literal("npm-global"), prefix: TrimmedNonEmptyString }),
64]);
65export type ServerInstallation = typeof ServerInstallation.Type;
66​
67export const ServerSelfUpdateCapability = Schema.Literals([
68 "boot-service",
69 "respawn",
70 "desktop-managed",
71]);
72export type ServerSelfUpdateCapability = typeof ServerSelfUpdateCapability.Type;
73​
74export const ExecutionEnvironmentCapabilities = Schema.Struct({
75 repositoryIdentity: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(false))),
76 connectionProbe: Schema.optionalKey(Schema.Boolean),
77 attachmentUploads: Schema.optionalKey(Schema.Boolean),
78 questionAttachments: Schema.optionalKey(Schema.Boolean),
79 fileAttachments: Schema.optionalKey(
80 Schema.Struct({
81 maxUploadBytes: Schema.Int.check(Schema.isGreaterThanOrEqualTo(1)),
82 }),
83 ),
84 pullRequests: Schema.optionalKey(Schema.Boolean),
85 pullRequestChecks: Schema.optionalKey(Schema.Boolean),
86 /** Absent on servers from before inline context shipped, which drop the records and forward
87 the links as literal text -- so a client must serialize context the legacy way for them. */
88 inlineMessageContext: Schema.optionalKey(Schema.Boolean),
89 requiredWorktreeBootstrap: Schema.optionalKey(Schema.Boolean),
90 threadSettlement: Schema.optionalKey(Schema.Boolean),
91 threadAutoSettlement: Schema.optionalKey(Schema.Boolean),
92 storageCleanup: Schema.optionalKey(Schema.Boolean),
93 storageCleanupRun: Schema.optionalKey(Schema.Boolean),
94 /** Server streams database size and reclaimable space for the Storage settings notice. */
95 databaseStorage: Schema.optionalKey(Schema.Boolean),
96 /** Server checks OTLP endpoints for the telemetry export settings. */
97 otlpEndpointCheck: Schema.optionalKey(Schema.Boolean),
98 projectWorktreeCleanup: Schema.optionalKey(Schema.Boolean),
99 settledWorktreeCleanup: Schema.optionalKey(Schema.Boolean),
100 worktreesDirectory: Schema.optionalKey(Schema.Boolean),
101 threadAutoSettlementScope: Schema.optionalKey(Schema.Boolean),
102 threadRestartContinuation: Schema.optionalKey(Schema.Boolean),
103 projectSettingsOverrides: Schema.optionalKey(Schema.Boolean),
104 /**
105 * Older
106 servers decode the key away (unknown fields are stripped, not
107 rejected), so the per-project provider switch would silently do
108 nothing; clients hide it instead of sending a patch that goes nowhere.
109 */
110 projectProviderInstanceOverrides: Schema.optionalKey(Schema.Boolean),
111 threadSnooze: Schema.optionalKey(Schema.Boolean),
112 /** Absent on servers from
113 before environment themes shipped, which never emit the events -- so a
114 client reconnecting to one must drop published themes rather than keep
115 showing a set nothing will ever update. */
116 environmentThemes: Schema.optionalKey(Schema.Boolean),
117 usageLimitSources: Schema.optionalKey(Schema.Boolean),
118 usagePriceOverrides: Schema.optionalKey(Schema.Boolean),
119 usageModelAliases: Schema.optionalKey(Schema.Boolean),
120 threadPinning: Schema.optionalKey(Schema.Boolean),
121 threadPinReorder: Schema.optionalKey(Schema.Boolean),
122 threadActiveReorder: Schema.optionalKey(Schema.Boolean),
123 threadAutoSettleOptOut: Schema.optionalKey(Schema.Boolean),
124 threadTitleRegeneration: Schema.optionalKey(Schema.Boolean),
125 threadVisitedTracking: Schema.optionalKey(Schema.Boolean),
126 threadPullRequestLinking: Schema.optionalKey(Schema.Boolean),
127 serverResolvedCommandContext: Schema.optionalKey(Schema.Boolean),
128 threadPullRequests: Schema.optionalKey(Schema.Boolean),
129 threadPullRequestWatch: Schema.optionalKey(Schema.Boolean),
130 pullRequestStackActions: Schema.optionalKey(Schema.Boolean),
131 serverSelfUpdate: Schema.optionalKey(ServerSelfUpdateCapability),
132 /** Manual commands must update this install, not the host's default global prefix. */
133 serverInstallation: ForwardCompatibleOptional(ServerInstallation),
134 serverSelfUpdateProgress: Schema.optionalKey(Schema.Boolean),
135 serverUpdateThreadContinuation: Schema.optionalKey(Schema.Boolean),
136 /**
137 * Clients skip seeding a Live Activity when
138 this is false — no update would ever repaint it. Absent on older
139 servers, which may still publish, so only an explicit false skips.
140 */
141 agentActivityPublishing: Schema.optionalKey(Schema.Boolean),
142 projectCloneTracking: Schema.optionalKey(Schema.Boolean),
143 environmentIcon: Schema.optionalKey(Schema.Boolean),
144 desktopAppUpdate: Schema.optionalKey(Schema.Boolean),
145 /** Server answers orchestration.subscribeCommandOutput. Absent on older servers,
146 which never send command output, so clients must not subscribe. */
147 commandOutputStreaming: Schema.optionalKey(Schema.Boolean),
148 /** Server hosts preview tabs in its own headless Chromium (`runtime:
149 "server"`) and streams them over `/api/preview-stream`. Clients
150 without a local browser runtime open server tabs here. */
151 serverBrowser: Schema.optionalKey(Schema.Boolean),
152});
153export type ExecutionEnvironmentCapabilities = typeof ExecutionEnvironmentCapabilities.Type;
154​
155export const ExecutionEnvironmentDescriptor = Schema.Struct({
156 environmentId: EnvironmentId,
157 label: TrimmedNonEmptyString,
158 platform: ExecutionEnvironmentPlatform,
159 serverVersion: TrimmedNonEmptyString,
160 orchestrationProtocolVersion: Schema.optionalKey(Schema.Int),
161 capabilities: ExecutionEnvironmentCapabilities,
162});
163export type ExecutionEnvironmentDescriptor = typeof ExecutionEnvironmentDescriptor.Type;
164​
165export const RepositoryIdentityLocator = Schema.Struct({
166 source: Schema.Literal("git-remote"),
167 remoteName: TrimmedNonEmptyString,
168 remoteUrl: TrimmedNonEmptyString,
169});
170export type RepositoryIdentityLocator = typeof RepositoryIdentityLocator.Type;
171​
172export const RepositoryOrigin = Schema.Struct({
173 canonicalKey: TrimmedNonEmptyString,
174 displayName: Schema.optionalKey(TrimmedNonEmptyString),
175});
176export type RepositoryOrigin = typeof RepositoryOrigin.Type;
177​
178export const RepositoryIdentity = Schema.Struct({
179 canonicalKey: TrimmedNonEmptyString,
180 locator: RepositoryIdentityLocator,
181 webUrl: Schema.optionalKey(TrimmedNonEmptyString),
182 rootPath: Schema.optionalKey(TrimmedNonEmptyString),
183 displayName: Schema.optionalKey(TrimmedNonEmptyString),
184 provider: Schema.optionalKey(TrimmedNonEmptyString),
185 owner: Schema.optionalKey(TrimmedNonEmptyString),
186 name: Schema.optionalKey(TrimmedNonEmptyString),
187 origin: Schema.optionalKey(RepositoryOrigin),
188});
189export type RepositoryIdentity = typeof RepositoryIdentity.Type;
190​
191export function repositoryGroupingKeyOf(identity: RepositoryIdentity): string {
192 return identity.origin?.canonicalKey ?? identity.canonicalKey;
194​
195export function repositoryGroupingDisplayNameOf(identity: RepositoryIdentity): string | undefined {
196 return identity.origin
197 ? (identity.origin.displayName ?? identity.origin.canonicalKey)
198 : identity.displayName;
200​
201export const ScopedProjectRef = Schema.Struct({
202 environmentId: EnvironmentId,
203 projectId: ProjectId,
204});
205export type ScopedProjectRef = typeof ScopedProjectRef.Type;
206​
207export const ScopedThreadRef = Schema.Struct({
208 environmentId: EnvironmentId,
209 threadId: ThreadId,
210});
211export type ScopedThreadRef = typeof ScopedThreadRef.Type;