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

environment.ts

215 lines9.4 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 threadStop: Schema.optionalKey(Schema.Boolean),
129 threadPullRequests: Schema.optionalKey(Schema.Boolean),
130 threadPullRequestWatch: Schema.optionalKey(Schema.Boolean),
131 pullRequestStackActions: Schema.optionalKey(Schema.Boolean),
132 serverSelfUpdate: Schema.optionalKey(ServerSelfUpdateCapability),
133 /** Manual commands must update this install, not the host's default global prefix. */
134 serverInstallation: ForwardCompatibleOptional(ServerInstallation),
135 serverSelfUpdateProgress: Schema.optionalKey(Schema.Boolean),
136 serverUpdateThreadContinuation: Schema.optionalKey(Schema.Boolean),
137 /**
138 * Clients skip seeding a Live Activity when
139 this is false — no update would ever repaint it. Absent on older
140 servers, which may still publish, so only an explicit false skips.
141 */
142 agentActivityPublishing: Schema.optionalKey(Schema.Boolean),
143 projectCloneTracking: Schema.optionalKey(Schema.Boolean),
144 /** Server answers projects.listIgnoredFiles. */
145 ignoredFileListing: Schema.optionalKey(Schema.Boolean),
146 environmentIcon: Schema.optionalKey(Schema.Boolean),
147 desktopAppUpdate: Schema.optionalKey(Schema.Boolean),
148 /** Server answers orchestration.subscribeCommandOutput. Absent on older servers,
149 which never send command output, so clients must not subscribe. */
150 commandOutputStreaming: Schema.optionalKey(Schema.Boolean),
151 /** Server hosts preview tabs in its own headless Chromium (`runtime:
152 "server"`) and streams them over `/api/preview-stream`. Clients
153 without a local browser runtime open server tabs here. */
154 serverBrowser: Schema.optionalKey(Schema.Boolean),
155});
156export type ExecutionEnvironmentCapabilities = typeof ExecutionEnvironmentCapabilities.Type;
157​
158export const ExecutionEnvironmentDescriptor = Schema.Struct({
159 environmentId: EnvironmentId,
160 label: TrimmedNonEmptyString,
161 platform: ExecutionEnvironmentPlatform,
162 serverVersion: TrimmedNonEmptyString,
163 orchestrationProtocolVersion: Schema.optionalKey(Schema.Int),
164 capabilities: ExecutionEnvironmentCapabilities,
165});
166export type ExecutionEnvironmentDescriptor = typeof ExecutionEnvironmentDescriptor.Type;
167​
168export const RepositoryIdentityLocator = Schema.Struct({
169 source: Schema.Literal("git-remote"),
170 remoteName: TrimmedNonEmptyString,
171 remoteUrl: TrimmedNonEmptyString,
172});
173export type RepositoryIdentityLocator = typeof RepositoryIdentityLocator.Type;
174​
175export const RepositoryOrigin = Schema.Struct({
176 canonicalKey: TrimmedNonEmptyString,
177 displayName: Schema.optionalKey(TrimmedNonEmptyString),
178});
179export type RepositoryOrigin = typeof RepositoryOrigin.Type;
180​
181export const RepositoryIdentity = Schema.Struct({
182 canonicalKey: TrimmedNonEmptyString,
183 locator: RepositoryIdentityLocator,
184 webUrl: Schema.optionalKey(TrimmedNonEmptyString),
185 /** Work tree root, or the git dir for a bare repository. */
186 rootPath: Schema.optionalKey(TrimmedNonEmptyString),
187 displayName: Schema.optionalKey(TrimmedNonEmptyString),
188 provider: Schema.optionalKey(TrimmedNonEmptyString),
189 owner: Schema.optionalKey(TrimmedNonEmptyString),
190 name: Schema.optionalKey(TrimmedNonEmptyString),
191 origin: Schema.optionalKey(RepositoryOrigin),
192});
193export type RepositoryIdentity = typeof RepositoryIdentity.Type;
194​
195export function repositoryGroupingKeyOf(identity: RepositoryIdentity): string {
196 return identity.origin?.canonicalKey ?? identity.canonicalKey;
198​
199export function repositoryGroupingDisplayNameOf(identity: RepositoryIdentity): string | undefined {
200 return identity.origin
201 ? (identity.origin.displayName ?? identity.origin.canonicalKey)
202 : identity.displayName;
204​
205export const ScopedProjectRef = Schema.Struct({
206 environmentId: EnvironmentId,
207 projectId: ProjectId,
208});
209export type ScopedProjectRef = typeof ScopedProjectRef.Type;
210​
211export const ScopedThreadRef = Schema.Struct({
212 environmentId: EnvironmentId,
213 threadId: ThreadId,
214});
215export type ScopedThreadRef = typeof ScopedThreadRef.Type;