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

environment.ts

210 lines9.5 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";
11import { SourceControlProviderKind } from "./sourceControl.ts";
12​
13export const ORCHESTRATION_PROTOCOL_VERSION = 2;
14export const ORCHESTRATION_PROTOCOL_VERSION_TEXT = "2";
15export const ORCHESTRATION_PROTOCOL_QUERY_PARAM = "orchestrationProtocol";
16export const ORCHESTRATION_PROTOCOL_HEADER = "x-t3-orchestration-protocol";
17​
18export const ExecutionEnvironmentPlatformOs = Schema.Literals([
19 "darwin",
20 "linux",
21 "windows",
22 "unknown",
23]);
24export type ExecutionEnvironmentPlatformOs = typeof ExecutionEnvironmentPlatformOs.Type;
25​
26export const ExecutionEnvironmentPlatformArch = Schema.Literals(["arm64", "x64", "other"]);
27export type ExecutionEnvironmentPlatformArch = typeof ExecutionEnvironmentPlatformArch.Type;
28​
29export const ENVIRONMENT_MACHINE_KINDS = [
30 "server",
31 "cloud",
32 "linux",
33 "desktop",
34 "laptop",
35 "mac-mini",
36 "mac-studio",
37] as const;
38export const EnvironmentMachineKind = Schema.Literals(ENVIRONMENT_MACHINE_KINDS);
39export type EnvironmentMachineKind = typeof EnvironmentMachineKind.Type;
40export const isEnvironmentMachineKind = Schema.is(EnvironmentMachineKind);
41​
42export const ExecutionEnvironmentPlatform = Schema.Struct({
43 os: ExecutionEnvironmentPlatformOs,
44 arch: ExecutionEnvironmentPlatformArch,
45 machine: ForwardCompatibleOptional(EnvironmentMachineKind),
46});
47​
48// Kept outside settings.ts to avoid an orchestration import cycle.
49export const ThreadEnvMode = Schema.Literals(["local", "worktree"]);
50export type ThreadEnvMode = typeof ThreadEnvMode.Type;
51​
52export const WorktreeSubmodules = Schema.Literals(["recursive", "top-level", "none"]);
53export type WorktreeSubmodules = typeof WorktreeSubmodules.Type;
54export type ExecutionEnvironmentPlatform = typeof ExecutionEnvironmentPlatform.Type;
55​
56export const ServerSelfUpdateMethod = Schema.Literals(["boot-service", "respawn", "desktop-app"]);
57export type ServerSelfUpdateMethod = typeof ServerSelfUpdateMethod.Type;
58​
59export const ServerInstallation = Schema.Union([
60 Schema.Struct({ kind: Schema.Literals(["npx", "pnpm-dlx", "bunx"]) }),
61 Schema.Struct({ kind: Schema.Literal("npm-global"), prefix: TrimmedNonEmptyString }),
62]);
63export type ServerInstallation = typeof ServerInstallation.Type;
64​
65export const ServerSelfUpdateCapability = Schema.Literals([
66 "boot-service",
67 "respawn",
68 "desktop-managed",
69]);
70export type ServerSelfUpdateCapability = typeof ServerSelfUpdateCapability.Type;
71​
72export const ExecutionEnvironmentCapabilities = Schema.Struct({
73 repositoryIdentity: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(false))),
74 connectionProbe: Schema.optionalKey(Schema.Boolean),
75 attachmentUploads: Schema.optionalKey(Schema.Boolean),
76 questionAttachments: Schema.optionalKey(Schema.Boolean),
77 fileAttachments: Schema.optionalKey(
78 Schema.Struct({
79 maxUploadBytes: Schema.Int.check(Schema.isGreaterThanOrEqualTo(1)),
80 }),
81 ),
82 pullRequests: Schema.optionalKey(Schema.Boolean),
83 pullRequestChecks: Schema.optionalKey(Schema.Boolean),
84 /** Absent on older servers; serialize context as legacy text for them. */
85 inlineMessageContext: Schema.optionalKey(Schema.Boolean),
86 requiredWorktreeBootstrap: Schema.optionalKey(Schema.Boolean),
87 threadSettlement: Schema.optionalKey(Schema.Boolean),
88 threadAutoSettlement: Schema.optionalKey(Schema.Boolean),
89 storageCleanup: Schema.optionalKey(Schema.Boolean),
90 storageCleanupRun: Schema.optionalKey(Schema.Boolean),
91 databaseStorage: Schema.optionalKey(Schema.Boolean),
92 otlpEndpointCheck: Schema.optionalKey(Schema.Boolean),
93 projectWorktreeCleanup: Schema.optionalKey(Schema.Boolean),
94 settledWorktreeCleanup: Schema.optionalKey(Schema.Boolean),
95 worktreesDirectory: Schema.optionalKey(Schema.Boolean),
96 threadAutoSettlementScope: Schema.optionalKey(Schema.Boolean),
97 threadRestartContinuation: Schema.optionalKey(Schema.Boolean),
98 projectSettingsOverrides: Schema.optionalKey(Schema.Boolean),
99 /** Hide the switch when absent; older servers silently drop per-project provider patches. */
100 projectProviderInstanceOverrides: Schema.optionalKey(Schema.Boolean),
101 threadSnooze: Schema.optionalKey(Schema.Boolean),
102 /** Clear published themes when absent; older servers never send updates. */
103 environmentThemes: Schema.optionalKey(Schema.Boolean),
104 usageLimitSources: Schema.optionalKey(Schema.Boolean),
105 /** Honors `workspaceSnapshotsOnDemand`; older servers send every snapshot and drop them in the stream. */
106 providerWorkspaceSnapshotsOnDemand: Schema.optionalKey(Schema.Boolean),
107 usagePriceOverrides: Schema.optionalKey(Schema.Boolean),
108 usageModelAliases: Schema.optionalKey(Schema.Boolean),
109 threadPinning: Schema.optionalKey(Schema.Boolean),
110 threadPinReorder: Schema.optionalKey(Schema.Boolean),
111 threadActiveReorder: Schema.optionalKey(Schema.Boolean),
112 threadAutoSettleOptOut: Schema.optionalKey(Schema.Boolean),
113 threadTitleRegeneration: Schema.optionalKey(Schema.Boolean),
114 threadVisitedTracking: Schema.optionalKey(Schema.Boolean),
115 threadPullRequestLinking: Schema.optionalKey(Schema.Boolean),
116 serverResolvedCommandContext: Schema.optionalKey(Schema.Boolean),
117 threadStop: Schema.optionalKey(Schema.Boolean),
118 threadPullRequests: Schema.optionalKey(Schema.Boolean),
119 threadPullRequestWatch: Schema.optionalKey(Schema.Boolean),
120 pullRequestStackActions: Schema.optionalKey(Schema.Boolean),
121 serverSelfUpdate: Schema.optionalKey(ServerSelfUpdateCapability),
122 /** Manual commands must update this install, not the host's default global prefix. */
123 serverInstallation: ForwardCompatibleOptional(ServerInstallation),
124 serverSelfUpdateProgress: Schema.optionalKey(Schema.Boolean),
125 serverUpdateThreadContinuation: Schema.optionalKey(Schema.Boolean),
126 /** Only explicit false skips Live Activity seeding; older servers may still publish. */
127 agentActivityPublishing: Schema.optionalKey(Schema.Boolean),
128 projectCloneTracking: Schema.optionalKey(Schema.Boolean),
129 /** Server answers projects.listIgnoredFiles. */
130 ignoredFileListing: Schema.optionalKey(Schema.Boolean),
131 environmentIcon: Schema.optionalKey(Schema.Boolean),
132 desktopAppUpdate: Schema.optionalKey(Schema.Boolean),
133 /** Subscribe to command output only when advertised; older servers never send it. */
134 commandOutputStreaming: Schema.optionalKey(Schema.Boolean),
135 /** Hosts headless Chromium tabs streamed over /api/preview-stream for clients without a local runtime. */
136 serverBrowser: Schema.optionalKey(Schema.Boolean),
137 /** Server links to other environments (`PeerLink`) and its agents can work
138 in them. Absent on servers from before linking, which clients must not
139 offer linking for. */
140 peerLinks: Schema.optionalKey(Schema.Boolean),
141 /** Server's `/mcp` narrows an OAuth client's modes from `T3-Mode-Limit`, so
142 a linked environment's calls keep its agent's limits. Another environment
143 links to this one only when it is set. */
144 mcpModeLimitHeader: Schema.optionalKey(Schema.Boolean),
145 /** Work a linked environment starts here stays within its link
146 (`linkOrigin`). Another environment links to this one only when it is
147 set, since without it that work could change the user's own threads. */
148 linkFence: Schema.optionalKey(Schema.Boolean),
149});
150export type ExecutionEnvironmentCapabilities = typeof ExecutionEnvironmentCapabilities.Type;
151​
152export const ExecutionEnvironmentDescriptor = Schema.Struct({
153 environmentId: EnvironmentId,
154 label: TrimmedNonEmptyString,
155 platform: ExecutionEnvironmentPlatform,
156 serverVersion: TrimmedNonEmptyString,
157 orchestrationProtocolVersion: Schema.optionalKey(Schema.Int),
158 capabilities: ExecutionEnvironmentCapabilities,
159});
160export type ExecutionEnvironmentDescriptor = typeof ExecutionEnvironmentDescriptor.Type;
161​
162export const RepositoryIdentityLocator = Schema.Struct({
163 source: Schema.Literal("git-remote"),
164 remoteName: TrimmedNonEmptyString,
165 remoteUrl: TrimmedNonEmptyString,
166});
167export type RepositoryIdentityLocator = typeof RepositoryIdentityLocator.Type;
168​
169export const RepositoryOrigin = Schema.Struct({
170 canonicalKey: TrimmedNonEmptyString,
171 remoteUrl: Schema.optionalKey(TrimmedNonEmptyString),
172 displayName: Schema.optionalKey(TrimmedNonEmptyString),
173});
174export type RepositoryOrigin = typeof RepositoryOrigin.Type;
175​
176export const RepositoryIdentity = Schema.Struct({
177 canonicalKey: TrimmedNonEmptyString,
178 locator: RepositoryIdentityLocator,
179 webUrl: Schema.optionalKey(TrimmedNonEmptyString),
180 /** Work tree root, or the git dir for a bare repository. */
181 rootPath: Schema.optionalKey(TrimmedNonEmptyString),
182 displayName: Schema.optionalKey(TrimmedNonEmptyString),
183 provider: Schema.optionalKey(SourceControlProviderKind),
184 owner: Schema.optionalKey(TrimmedNonEmptyString),
185 name: Schema.optionalKey(TrimmedNonEmptyString),
186 origin: Schema.optionalKey(RepositoryOrigin),
187});
188export type RepositoryIdentity = typeof RepositoryIdentity.Type;
189​
190export function repositoryGroupingKeyOf(identity: RepositoryIdentity): string {
191 return identity.origin?.canonicalKey ?? identity.canonicalKey;
193​
194export function repositoryGroupingDisplayNameOf(identity: RepositoryIdentity): string | undefined {
195 return identity.origin
196 ? (identity.origin.displayName ?? identity.origin.canonicalKey)
197 : identity.displayName;
199​
200export const ScopedProjectRef = Schema.Struct({
201 environmentId: EnvironmentId,
202 projectId: ProjectId,
203});
204export type ScopedProjectRef = typeof ScopedProjectRef.Type;
205​
206export const ScopedThreadRef = Schema.Struct({
207 environmentId: EnvironmentId,
208 threadId: ThreadId,
209});
210export type ScopedThreadRef = typeof ScopedThreadRef.Type;