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

server.ts

896 lines34.1 KB

1import * as Effect from "effect/Effect";
2import * as Schema from "effect/Schema";
3import { AcpRegistryUrlAuthAction } from "./acpRegistry.ts";
4import {
5 type EnvironmentMachineKind,
6 ExecutionEnvironmentDescriptor,
7 ServerSelfUpdateMethod,
8} from "./environment.ts";
9import { ServerAuthDescriptor } from "./auth.ts";
10import {
11 ForwardCompatibleArray,
12 IsoDateTime,
13 NonNegativeInt,
14 PositiveInt,
15 ProjectId,
16 ThreadId,
17 TrimmedNonEmptyString,
18} from "./baseSchemas.ts";
19import {
20 KeybindingCommand,
21 KeybindingValue,
22 KeybindingWhen,
23 ResolvedKeybindingsConfig,
24} from "./keybindings.ts";
25import { EditorId, FileManagerRevealKind, RemoteOpenTarget } from "./editor.ts";
26import { ModelCapabilities, ProviderOptionDescriptor } from "./model.ts";
27import { RuntimeMode } from "./providerPolicy.ts";
28import { ProviderDriverKind, ProviderInstanceId } from "./providerInstance.ts";
29import { ServerProviderUsageLimits, UsageLimitSourceSnapshots } from "./providerUsageLimits.ts";
30import { ServerSettings } from "./settings.ts";
31​
32const KeybindingsMalformedConfigIssue = Schema.Struct({
33 kind: Schema.Literal("keybindings.malformed-config"),
34 message: TrimmedNonEmptyString,
35});
36​
37const KeybindingsInvalidEntryIssue = Schema.Struct({
38 kind: Schema.Literal("keybindings.invalid-entry"),
39 message: TrimmedNonEmptyString,
40 index: Schema.Number,
41});
42​
43export const ServerConfigIssue = Schema.Union([
44 KeybindingsMalformedConfigIssue,
45 KeybindingsInvalidEntryIssue,
46]);
47export type ServerConfigIssue = typeof ServerConfigIssue.Type;
48​
49const ServerConfigIssues = ForwardCompatibleArray(ServerConfigIssue);
50​
51export const ServerProviderState = Schema.Literals(["ready", "warning", "error", "disabled"]);
52export type ServerProviderState = typeof ServerProviderState.Type;
53​
54export const ServerProviderAuthStatus = Schema.Literals([
55 "authenticated",
56 "unauthenticated",
57 "unknown",
58]);
59export type ServerProviderAuthStatus = typeof ServerProviderAuthStatus.Type;
60​
61export const ServerProviderAuth = Schema.Struct({
62 status: ServerProviderAuthStatus,
63 type: Schema.optional(TrimmedNonEmptyString),
64 label: Schema.optional(TrimmedNonEmptyString),
65 email: Schema.optional(TrimmedNonEmptyString),
66 action: Schema.optional(AcpRegistryUrlAuthAction),
67 canLogout: Schema.optional(Schema.Boolean),
68 subscriptionSharing: Schema.optional(Schema.Boolean),
69 profileId: Schema.optional(TrimmedNonEmptyString),
70 workspaceId: Schema.optional(TrimmedNonEmptyString),
71});
72export type ServerProviderAuth = typeof ServerProviderAuth.Type;
73​
74export const ServerProviderModel = Schema.Struct({
75 slug: TrimmedNonEmptyString,
76 name: TrimmedNonEmptyString,
77 shortName: Schema.optional(TrimmedNonEmptyString),
78 subProvider: Schema.optional(TrimmedNonEmptyString),
79 aliases: Schema.optional(Schema.Array(TrimmedNonEmptyString)),
80 badge: Schema.optional(Schema.Literal("new")),
81 isCustom: Schema.Boolean,
82 isDefault: Schema.optional(Schema.Boolean),
83 isLegacy: Schema.optional(Schema.Boolean),
84 capabilities: Schema.NullOr(ModelCapabilities),
85});
86export type ServerProviderModel = typeof ServerProviderModel.Type;
87​
88export const ServerProviderUpdateRequiredModel = Schema.Struct({
89 slug: TrimmedNonEmptyString,
90 name: TrimmedNonEmptyString,
91 badge: Schema.optional(Schema.Literal("new")),
92 minVersion: TrimmedNonEmptyString,
93});
94export type ServerProviderUpdateRequiredModel = typeof ServerProviderUpdateRequiredModel.Type;
95​
96export const ServerProviderSlashCommandInput = Schema.Struct({
97 hint: TrimmedNonEmptyString,
98});
99export type ServerProviderSlashCommandInput = typeof ServerProviderSlashCommandInput.Type;
100​
101export const ServerProviderSlashCommand = Schema.Struct({
102 name: TrimmedNonEmptyString,
103 description: Schema.optional(TrimmedNonEmptyString),
104 input: Schema.optional(ServerProviderSlashCommandInput),
105});
106export type ServerProviderSlashCommand = typeof ServerProviderSlashCommand.Type;
107​
108export const ServerProviderSkill = Schema.Struct({
109 name: TrimmedNonEmptyString,
110 description: Schema.optional(TrimmedNonEmptyString),
111 path: TrimmedNonEmptyString,
112 scope: Schema.optional(TrimmedNonEmptyString),
113 enabled: Schema.Boolean,
114 displayName: Schema.optional(TrimmedNonEmptyString),
115 shortDescription: Schema.optional(TrimmedNonEmptyString),
116 /**
117 * The skill is hidden from the agent's own skill tool, so only the user can
118 * start it — Claude Code's `disable-model-invocation`. Composers must offer
119 * it as a slash command; naming it in prose does nothing.
120 */
121 userInvocationOnly: Schema.optional(Schema.Boolean),
122 /**
123 * The mirror of {@link ServerProviderSkill.userInvocationOnly}: Claude Code's
124 * `user-invocable: false` keeps the skill out of its own slash commands, so
125 * only the agent can start it. Composers must not offer it under `/`.
126 */
127 userInvocable: Schema.optional(Schema.Boolean),
128});
129export type ServerProviderSkill = typeof ServerProviderSkill.Type;
130​
131export const ServerProviderWorkspaceSnapshot = Schema.Struct({
132 cwd: TrimmedNonEmptyString,
133 checkedAt: IsoDateTime,
134 slashCommands: Schema.Array(ServerProviderSlashCommand),
135 slashCommandsPending: Schema.optional(Schema.Boolean),
136 skills: Schema.Array(ServerProviderSkill),
137 optionDescriptors: Schema.optional(Schema.Array(ProviderOptionDescriptor)),
138});
139export type ServerProviderWorkspaceSnapshot = typeof ServerProviderWorkspaceSnapshot.Type;
140​
141export const PROVIDER_WORKSPACE_SNAPSHOT_TTL_MS = 5 * 60_000;
142​
143export function isProviderWorkspaceSnapshotCurrent(
144 snapshot: Pick<ServerProviderWorkspaceSnapshot, "checkedAt">,
145 nowMs: number,
146): boolean {
147 return nowMs - Date.parse(snapshot.checkedAt) < PROVIDER_WORKSPACE_SNAPSHOT_TTL_MS;
149​
150/**
151 * Snapshots with `availability: "unavailable"` MUST set
152 * `installed: false` and `enabled: false`; the runtime refuses turn
153 * starts against them with a structured error.
154 */
155export const ServerProviderAvailability = Schema.Literals(["available", "unavailable"]);
156export type ServerProviderAvailability = typeof ServerProviderAvailability.Type;
157​
158export const ServerProviderContinuation = Schema.Struct({
159 groupKey: TrimmedNonEmptyString,
160});
161export type ServerProviderContinuation = typeof ServerProviderContinuation.Type;
162​
163export const ServerProviderCompatibilityStatus = Schema.Literals([
164 "unknown",
165 "supported",
166 "graceful",
167 "unsupported",
168 "broken",
169]);
170export const ServerProviderCompatibilityAdvisory = Schema.Struct({
171 status: ServerProviderCompatibilityStatus,
172 latestVersionStatus: Schema.optionalKey(ServerProviderCompatibilityStatus),
173 message: Schema.NullOr(TrimmedNonEmptyString),
174 recommendedVersion: Schema.NullOr(TrimmedNonEmptyString),
175 recommendedRange: Schema.NullOr(TrimmedNonEmptyString),
176});
177export type ServerProviderCompatibilityAdvisory = typeof ServerProviderCompatibilityAdvisory.Type;
178​
179export const ServerProviderVersionAdvisoryStatus = Schema.Literals([
180 "unknown",
181 "current",
182 "behind_latest",
183]);
184export type ServerProviderVersionAdvisoryStatus = typeof ServerProviderVersionAdvisoryStatus.Type;
185​
186export const ServerProviderVersionAdvisory = Schema.Struct({
187 status: ServerProviderVersionAdvisoryStatus,
188 currentVersion: Schema.NullOr(TrimmedNonEmptyString),
189 latestVersion: Schema.NullOr(TrimmedNonEmptyString),
190 updateCommand: Schema.NullOr(TrimmedNonEmptyString),
191 canUpdate: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(false))),
192 canInstallVersion: Schema.optionalKey(Schema.Boolean),
193 checkedAt: Schema.NullOr(IsoDateTime),
194 message: Schema.NullOr(TrimmedNonEmptyString),
195});
196export type ServerProviderVersionAdvisory = typeof ServerProviderVersionAdvisory.Type;
197​
198export const ServerProviderUpdateStatus = Schema.Literals([
199 "idle",
200 "queued",
201 "running",
202 "succeeded",
203 "failed",
204 "unchanged",
205]);
206export type ServerProviderUpdateStatus = typeof ServerProviderUpdateStatus.Type;
207​
208export const ServerProviderUpdateState = Schema.Struct({
209 status: ServerProviderUpdateStatus,
210 startedAt: Schema.NullOr(IsoDateTime),
211 finishedAt: Schema.NullOr(IsoDateTime),
212 message: Schema.NullOr(TrimmedNonEmptyString),
213 output: Schema.NullOr(Schema.String.check(Schema.isMaxLength(10_000))),
214});
215export type ServerProviderUpdateState = typeof ServerProviderUpdateState.Type;
216​
217export const ServerProvider = Schema.Struct({
218 // Routing key for the configured instance this snapshot represents. This
219 // is the only stable identity consumers may use for provider routing.
220 instanceId: ProviderInstanceId,
221 driver: ProviderDriverKind,
222 displayName: Schema.optional(TrimmedNonEmptyString),
223 accentColor: Schema.optional(TrimmedNonEmptyString),
224 // Optional visual identity supplied by the owning provider driver. Clients
225 // must still validate remote URLs against that driver's trusted origin.
226 iconUrl: Schema.optional(TrimmedNonEmptyString.check(Schema.isMaxLength(2_048))),
227 badgeLabel: Schema.optional(TrimmedNonEmptyString),
228 continuation: Schema.optional(ServerProviderContinuation),
229 showInteractionModeToggle: Schema.optional(Schema.Boolean),
230 reportsContextWindow: Schema.optional(Schema.Boolean),
231 supportedRuntimeModes: Schema.optional(ForwardCompatibleArray(RuntimeMode)),
232 requiresNewThreadForModelChange: Schema.optional(Schema.Boolean),
233 supportsConversationRollback: Schema.optional(Schema.Boolean),
234 supportsTextGeneration: Schema.optional(Schema.Boolean),
235 setup: Schema.optional(
236 Schema.Struct({
237 canAuthenticate: Schema.Boolean,
238 canInstall: Schema.Boolean,
239 documentationUrl: Schema.optionalKey(TrimmedNonEmptyString.check(Schema.isMaxLength(2_048))),
240 }),
241 ),
242 nativeSessions: Schema.optional(
243 Schema.Struct({
244 canList: Schema.Boolean,
245 canLoad: Schema.Boolean,
246 canResume: Schema.Boolean,
247 canDelete: Schema.optional(Schema.Boolean),
248 }),
249 ),
250 configurableProviders: Schema.optional(Schema.Boolean),
251 runtimePaths: Schema.optionalKey(
252 Schema.Struct({
253 homePath: TrimmedNonEmptyString,
254 shadowHomePath: Schema.NullOr(TrimmedNonEmptyString),
255 }),
256 ),
257 enabled: Schema.Boolean,
258 installed: Schema.Boolean,
259 version: Schema.NullOr(TrimmedNonEmptyString),
260 status: ServerProviderState,
261 auth: ServerProviderAuth,
262 checkedAt: IsoDateTime,
263 message: Schema.optional(TrimmedNonEmptyString),
264 availability: Schema.optional(ServerProviderAvailability),
265 unavailableReason: Schema.optional(TrimmedNonEmptyString),
266 models: Schema.Array(ServerProviderModel),
267 // Kept apart from `models` so clients that predate it never offer them.
268 updateRequiredModels: Schema.optionalKey(Schema.Array(ServerProviderUpdateRequiredModel)),
269 slashCommands: Schema.Array(ServerProviderSlashCommand).pipe(
270 Schema.withDecodingDefault(Effect.succeed([])),
271 ),
272 skills: Schema.Array(ServerProviderSkill).pipe(Schema.withDecodingDefault(Effect.succeed([]))),
273 workspaceSnapshots: Schema.optionalKey(Schema.Array(ServerProviderWorkspaceSnapshot)),
274 usageLimits: Schema.optional(ServerProviderUsageLimits),
275 versionAdvisory: Schema.optionalKey(ServerProviderVersionAdvisory),
276 compatibilityAdvisory: Schema.optionalKey(ServerProviderCompatibilityAdvisory),
277 updateState: Schema.optionalKey(ServerProviderUpdateState),
278});
279export type ServerProvider = typeof ServerProvider.Type;
280​
281export const ServerProviders = ForwardCompatibleArray(ServerProvider);
282export type ServerProviders = typeof ServerProviders.Type;
283​
284export const isProviderAvailable = (snapshot: ServerProvider): boolean =>
285 snapshot.availability !== "unavailable";
286​
287/**
288 * Treat an absent `supportsTextGeneration` as supported so legacy
289 * producers, which all support application text generation, keep working
290 * without resending the field.
291 */
292export const isProviderTextGenerationCapable = (snapshot: ServerProvider): boolean =>
293 snapshot.supportsTextGeneration !== false;
294​
295export const ServerObservability = Schema.Struct({
296 logsDirectoryPath: TrimmedNonEmptyString,
297 localTracingEnabled: Schema.Boolean,
298 otlpTracesUrl: Schema.optional(TrimmedNonEmptyString),
299 otlpTracesEnabled: Schema.Boolean,
300 otlpMetricsUrl: Schema.optional(TrimmedNonEmptyString),
301 otlpMetricsEnabled: Schema.Boolean,
302 otlpLogsUrl: Schema.optional(TrimmedNonEmptyString),
303 otlpLogsEnabled: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(false))),
304});
305export type ServerObservability = typeof ServerObservability.Type;
306​
307export const OtlpSignal = Schema.Literals(["traces", "metrics", "logs"]);
308export type OtlpSignal = typeof OtlpSignal.Type;
309​
310export const OtlpEndpointCheckInput = Schema.Struct({
311 signal: OtlpSignal,
312 url: TrimmedNonEmptyString.check(Schema.isPattern(/^https?:\/\/./i)),
313});
314export type OtlpEndpointCheckInput = typeof OtlpEndpointCheckInput.Type;
315​
316export const OtlpEndpointCheckResult = Schema.Union([
317 Schema.TaggedStruct("Accepted", { latencyMs: Schema.Number }),
318 Schema.TaggedStruct("Rejected", { status: Schema.Number }),
319 Schema.TaggedStruct("Unreachable", { timedOut: Schema.Boolean }),
320]);
321export type OtlpEndpointCheckResult = typeof OtlpEndpointCheckResult.Type;
322​
323export const ServerTraceDiagnosticsErrorKind = Schema.Literals([
324 "trace-file-not-found",
325 "trace-file-read-failed",
326]);
327export type ServerTraceDiagnosticsErrorKind = typeof ServerTraceDiagnosticsErrorKind.Type;
328​
329export const ServerTraceDiagnosticsSpanSummary = Schema.Struct({
330 name: TrimmedNonEmptyString,
331 count: NonNegativeInt,
332 failureCount: NonNegativeInt,
333 totalDurationMs: Schema.Number,
334 averageDurationMs: Schema.Number,
335 maxDurationMs: Schema.Number,
336});
337export type ServerTraceDiagnosticsSpanSummary = typeof ServerTraceDiagnosticsSpanSummary.Type;
338​
339export const ServerTraceDiagnosticsFailureSummary = Schema.Struct({
340 name: TrimmedNonEmptyString,
341 cause: TrimmedNonEmptyString,
342 count: NonNegativeInt,
343 lastSeenAt: Schema.DateTimeUtc,
344 traceId: TrimmedNonEmptyString,
345 spanId: TrimmedNonEmptyString,
346});
347export type ServerTraceDiagnosticsFailureSummary = typeof ServerTraceDiagnosticsFailureSummary.Type;
348​
349export const ServerTraceDiagnosticsRecentFailure = Schema.Struct({
350 name: TrimmedNonEmptyString,
351 cause: TrimmedNonEmptyString,
352 durationMs: Schema.Number,
353 endedAt: Schema.DateTimeUtc,
354 traceId: TrimmedNonEmptyString,
355 spanId: TrimmedNonEmptyString,
356});
357export type ServerTraceDiagnosticsRecentFailure = typeof ServerTraceDiagnosticsRecentFailure.Type;
358​
359export const ServerTraceDiagnosticsSpanOccurrence = Schema.Struct({
360 name: TrimmedNonEmptyString,
361 durationMs: Schema.Number,
362 endedAt: Schema.DateTimeUtc,
363 traceId: TrimmedNonEmptyString,
364 spanId: TrimmedNonEmptyString,
365});
366export type ServerTraceDiagnosticsSpanOccurrence = typeof ServerTraceDiagnosticsSpanOccurrence.Type;
367​
368export const ServerTraceDiagnosticsLogEvent = Schema.Struct({
369 spanName: TrimmedNonEmptyString,
370 level: TrimmedNonEmptyString,
371 message: TrimmedNonEmptyString,
372 seenAt: Schema.DateTimeUtc,
373 traceId: TrimmedNonEmptyString,
374 spanId: TrimmedNonEmptyString,
375});
376export type ServerTraceDiagnosticsLogEvent = typeof ServerTraceDiagnosticsLogEvent.Type;
377​
378export const ServerTraceDiagnosticsResult = Schema.Struct({
379 traceFilePath: TrimmedNonEmptyString,
380 scannedFilePaths: Schema.Array(TrimmedNonEmptyString),
381 readAt: Schema.DateTimeUtc,
382 recordCount: NonNegativeInt,
383 parseErrorCount: NonNegativeInt,
384 firstSpanAt: Schema.Option(Schema.DateTimeUtc),
385 lastSpanAt: Schema.Option(Schema.DateTimeUtc),
386 failureCount: NonNegativeInt,
387 interruptionCount: NonNegativeInt,
388 slowSpanThresholdMs: NonNegativeInt,
389 slowSpanCount: NonNegativeInt,
390 logLevelCounts: Schema.Record(TrimmedNonEmptyString, NonNegativeInt),
391 topSpansByCount: Schema.Array(ServerTraceDiagnosticsSpanSummary),
392 slowestSpans: Schema.Array(ServerTraceDiagnosticsSpanOccurrence),
393 commonFailures: Schema.Array(ServerTraceDiagnosticsFailureSummary),
394 latestFailures: Schema.Array(ServerTraceDiagnosticsRecentFailure),
395 latestWarningAndErrorLogs: Schema.Array(ServerTraceDiagnosticsLogEvent),
396 partialFailure: Schema.Option(Schema.Boolean),
397 error: Schema.Option(
398 Schema.Struct({
399 kind: ServerTraceDiagnosticsErrorKind,
400 message: TrimmedNonEmptyString,
401 }),
402 ),
403});
404export type ServerTraceDiagnosticsResult = typeof ServerTraceDiagnosticsResult.Type;
405​
406export const ServerProcessSignal = Schema.Literals(["SIGINT", "SIGKILL"]);
407export type ServerProcessSignal = typeof ServerProcessSignal.Type;
408​
409export const ServerProcessDiagnosticsEntry = Schema.Struct({
410 pid: PositiveInt,
411 startTimeMs: NonNegativeInt,
412 ppid: NonNegativeInt,
413 pgid: Schema.Option(Schema.Int),
414 status: TrimmedNonEmptyString,
415 cpuPercent: Schema.Number,
416 rssBytes: NonNegativeInt,
417 elapsed: TrimmedNonEmptyString,
418 command: TrimmedNonEmptyString,
419 depth: NonNegativeInt,
420 childPids: Schema.Array(PositiveInt),
421});
422export type ServerProcessDiagnosticsEntry = typeof ServerProcessDiagnosticsEntry.Type;
423​
424export const ServerProcessDiagnosticsResult = Schema.Struct({
425 serverPid: PositiveInt,
426 readAt: Schema.DateTimeUtc,
427 processCount: NonNegativeInt,
428 totalRssBytes: NonNegativeInt,
429 totalCpuPercent: Schema.Number,
430 processes: Schema.Array(ServerProcessDiagnosticsEntry),
431 error: Schema.Option(
432 Schema.Struct({
433 message: TrimmedNonEmptyString,
434 }),
435 ),
436});
437export type ServerProcessDiagnosticsResult = typeof ServerProcessDiagnosticsResult.Type;
438​
439export const ServerProcessResourceHistoryInput = Schema.Struct({
440 windowMs: NonNegativeInt,
441 bucketMs: NonNegativeInt,
442});
443export type ServerProcessResourceHistoryInput = typeof ServerProcessResourceHistoryInput.Type;
444​
445export const ServerProcessResourceHistoryBucket = Schema.Struct({
446 startedAt: Schema.DateTimeUtc,
447 endedAt: Schema.DateTimeUtc,
448 avgCpuPercent: Schema.Number,
449 maxCpuPercent: Schema.Number,
450 maxRssBytes: NonNegativeInt,
451 maxProcessCount: NonNegativeInt,
452});
453export type ServerProcessResourceHistoryBucket = typeof ServerProcessResourceHistoryBucket.Type;
454​
455export const ServerProcessResourceHistorySummary = Schema.Struct({
456 processKey: TrimmedNonEmptyString,
457 pid: PositiveInt,
458 ppid: NonNegativeInt,
459 command: TrimmedNonEmptyString,
460 depth: NonNegativeInt,
461 isServerRoot: Schema.Boolean,
462 firstSeenAt: Schema.DateTimeUtc,
463 lastSeenAt: Schema.DateTimeUtc,
464 currentCpuPercent: Schema.Number,
465 avgCpuPercent: Schema.Number,
466 maxCpuPercent: Schema.Number,
467 cpuSecondsApprox: Schema.Number,
468 currentRssBytes: NonNegativeInt,
469 maxRssBytes: NonNegativeInt,
470 sampleCount: NonNegativeInt,
471});
472export type ServerProcessResourceHistorySummary = typeof ServerProcessResourceHistorySummary.Type;
473​
474export const ServerProcessResourceHistoryFailureTag = Schema.Literals([
475 "ProcessDiagnosticsQueryTimeoutError",
476 "ProcessDiagnosticsQueryFailedError",
477 "ProcessDiagnosticsServerProcessSignalError",
478 "ProcessDiagnosticsNotDescendantError",
479 "ProcessDiagnosticsSignalFailedError",
480]);
481export type ServerProcessResourceHistoryFailureTag =
482 typeof ServerProcessResourceHistoryFailureTag.Type;
483​
484export const ServerProcessResourceHistoryResult = Schema.Struct({
485 readAt: Schema.DateTimeUtc,
486 windowMs: NonNegativeInt,
487 bucketMs: NonNegativeInt,
488 sampleIntervalMs: NonNegativeInt,
489 retainedSampleCount: NonNegativeInt,
490 totalCpuSecondsApprox: Schema.Number,
491 buckets: Schema.Array(ServerProcessResourceHistoryBucket),
492 topProcesses: Schema.Array(ServerProcessResourceHistorySummary),
493 error: Schema.Option(
494 Schema.Struct({
495 failureTag: ServerProcessResourceHistoryFailureTag,
496 message: TrimmedNonEmptyString,
497 }),
498 ),
499});
500export type ServerProcessResourceHistoryResult = typeof ServerProcessResourceHistoryResult.Type;
501​
502export const ServerSignalProcessInput = Schema.Struct({
503 pid: PositiveInt,
504 startTimeMs: NonNegativeInt,
505 signal: ServerProcessSignal,
506});
507export type ServerSignalProcessInput = typeof ServerSignalProcessInput.Type;
508​
509export const ServerSignalProcessResult = Schema.Struct({
510 pid: PositiveInt,
511 signal: ServerProcessSignal,
512 signaled: Schema.Boolean,
513 message: Schema.Option(TrimmedNonEmptyString),
514});
515export type ServerSignalProcessResult = typeof ServerSignalProcessResult.Type;
516​
517export const EnvironmentThemeColor = Schema.String.check(
518 Schema.isPattern(/^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/),
519);
520export type EnvironmentThemeColor = typeof EnvironmentThemeColor.Type;
521​
522/**
523 * The appearance keywords are excluded outright: a published `dark.json`
524 * would otherwise capture every client whose stored preference is the stock
525 * `"dark"`, retinting people who never chose it.
526 */
527export const EnvironmentThemeId = Schema.String.check(
528 Schema.isPattern(/^(?!(?:system|light|dark)$)[a-z0-9](?:[a-z0-9-]{0,47})$/),
529);
530export type EnvironmentThemeId = typeof EnvironmentThemeId.Type;
531​
532const EnvironmentThemeColors = Schema.Record(
533 Schema.String.check(Schema.isPattern(/^[a-zA-Z][a-zA-Z0-9]{0,63}$/)),
534 TrimmedNonEmptyString.check(Schema.isMaxLength(64)),
535);
536​
537const environmentThemeFields = {
538 version: Schema.optional(Schema.Literal(1)),
539 name: TrimmedNonEmptyString.check(Schema.isMaxLength(48)),
540 appearance: Schema.Literals(["light", "dark"]),
541 /**
542 * When present, clients derive the full palette from them with the guided
543 * theme editor's generator and layer `colors` on top; when absent, `colors`
544 * is the palette, as in an exported theme file.
545 */
546 canvas: Schema.optional(EnvironmentThemeColor),
547 accent: Schema.optional(EnvironmentThemeColor),
548 colors: Schema.optional(EnvironmentThemeColors),
549 variants: Schema.optional(
550 Schema.Struct({
551 light: Schema.optional(EnvironmentThemeColors),
552 dark: Schema.optional(EnvironmentThemeColors),
553 }),
554 ),
555};
556​
557export const EnvironmentThemeFile = Schema.Struct(environmentThemeFields);
558export type EnvironmentThemeFile = typeof EnvironmentThemeFile.Type;
559​
560export const EnvironmentTheme = Schema.Struct({
561 id: EnvironmentThemeId,
562 ...environmentThemeFields,
563});
564export type EnvironmentTheme = typeof EnvironmentTheme.Type;
565​
566export function environmentThemeFileHasColors(file: EnvironmentThemeFile): boolean {
567 return (
568 (file.canvas !== undefined && file.accent !== undefined) ||
569 (file.colors !== undefined && Object.keys(file.colors).length > 0)
570 );
572​
573/**
574 * "tailnet" when the address is on this machine's Tailscale interface, "lan"
575 * for any other private address, including other VPNs in 100.64.0.0/10.
576 */
577export const ServerDirectEndpointKind = Schema.Literals(["lan", "tailnet"]);
578export type ServerDirectEndpointKind = typeof ServerDirectEndpointKind.Type;
579​
580export const ServerDirectEndpoint = Schema.Struct({
581 kind: ServerDirectEndpointKind,
582 httpBaseUrl: TrimmedNonEmptyString,
583});
584export type ServerDirectEndpoint = typeof ServerDirectEndpoint.Type;
585​
586export const ServerConfig = Schema.Struct({
587 environment: ExecutionEnvironmentDescriptor,
588 auth: ServerAuthDescriptor,
589 cwd: TrimmedNonEmptyString,
590 keybindingsConfigPath: TrimmedNonEmptyString,
591 keybindings: ResolvedKeybindingsConfig,
592 issues: ServerConfigIssues,
593 providers: ServerProviders,
594 availableEditors: ForwardCompatibleArray(EditorId),
595 remoteOpenTargets: Schema.optionalKey(ForwardCompatibleArray(RemoteOpenTarget)),
596 /**
597 * Hints only: the client checks each address answers as this environment
598 * before using it.
599 */
600 directEndpoints: Schema.optionalKey(ForwardCompatibleArray(ServerDirectEndpoint)),
601 observability: ServerObservability,
602 settings: ServerSettings,
603 shellResumeCompletionMarker: Schema.optionalKey(Schema.Boolean),
604 shellRevealInFileManager: Schema.optionalKey(Schema.Boolean),
605 shellRevealInFileManagerKind: Schema.optionalKey(FileManagerRevealKind),
606 threadResumeCompletionMarker: Schema.optionalKey(Schema.Boolean),
607 /**
608 * Clients must not send window fields to servers that don't advertise this.
609 */
610 threadSnapshotPagination: Schema.optionalKey(Schema.Boolean),
611 reasoningMessages: Schema.optionalKey(Schema.Boolean),
612 threadFind: Schema.optionalKey(Schema.Boolean),
613 threadFindProgressive: Schema.optionalKey(Schema.Boolean),
614 scratchWorkspaceRoot: Schema.optionalKey(TrimmedNonEmptyString),
615 newProjectsRoot: Schema.optionalKey(TrimmedNonEmptyString),
616 /**
617 * Never sent in a config snapshot: the theme stream emits the current set
618 * before any change, so a snapshot carrying it too would hand every
619 * subscriber the same array twice per connect.
620 */
621 environmentThemes: Schema.optional(Schema.Array(EnvironmentTheme)),
622 /**
623 * Like themes, never in a snapshot: the source stream emits the current set
624 * on subscribe, and it stays absent for subscribers that did not opt in.
625 */
626 usageLimitSources: Schema.optional(UsageLimitSourceSnapshots),
627});
628export type ServerConfig = typeof ServerConfig.Type;
629​
630export function resolveEnvironmentMachineKind(
631 config: {
632 readonly environment: Pick<ExecutionEnvironmentDescriptor, "platform">;
633 readonly settings?: Pick<ServerSettings, "environmentIcon">;
634 } | null,
635): EnvironmentMachineKind {
636 return config?.settings?.environmentIcon ?? config?.environment.platform.machine ?? "server";
638​
639const ServerUpsertKeybindingReplaceTarget = Schema.Struct({
640 key: KeybindingValue,
641 command: KeybindingCommand,
642 when: Schema.optional(KeybindingWhen),
643});
644​
645export const ServerUpsertKeybindingInput = Schema.Struct({
646 key: KeybindingValue,
647 command: KeybindingCommand,
648 when: Schema.optional(KeybindingWhen),
649 replace: Schema.optional(ServerUpsertKeybindingReplaceTarget),
650});
651export type ServerUpsertKeybindingInput = typeof ServerUpsertKeybindingInput.Type;
652​
653export const ServerRemoveKeybindingInput = ServerUpsertKeybindingReplaceTarget;
654export type ServerRemoveKeybindingInput = typeof ServerRemoveKeybindingInput.Type;
655​
656export const ServerUpsertKeybindingResult = Schema.Struct({
657 keybindings: ResolvedKeybindingsConfig,
658 issues: ServerConfigIssues,
659});
660export type ServerUpsertKeybindingResult = typeof ServerUpsertKeybindingResult.Type;
661​
662export const ServerRemoveKeybindingResult = ServerUpsertKeybindingResult;
663export type ServerRemoveKeybindingResult = typeof ServerRemoveKeybindingResult.Type;
664​
665export const ServerConfigUpdatedPayload = Schema.Struct({
666 issues: ServerConfigIssues,
667 providers: ServerProviders,
668 settings: Schema.optional(ServerSettings),
669});
670export type ServerConfigUpdatedPayload = typeof ServerConfigUpdatedPayload.Type;
671​
672export const ServerConfigKeybindingsUpdatedPayload = Schema.Struct({
673 keybindings: ResolvedKeybindingsConfig,
674 issues: ServerConfigIssues,
675});
676export type ServerConfigKeybindingsUpdatedPayload =
677 typeof ServerConfigKeybindingsUpdatedPayload.Type;
678​
679export const ServerConfigProviderStatusesPayload = Schema.Struct({
680 providers: ServerProviders,
681});
682export type ServerConfigProviderStatusesPayload = typeof ServerConfigProviderStatusesPayload.Type;
683​
684export const ServerConfigSettingsUpdatedPayload = Schema.Struct({
685 settings: ServerSettings,
686});
687export type ServerConfigSettingsUpdatedPayload = typeof ServerConfigSettingsUpdatedPayload.Type;
688​
689export const ServerConfigStreamSnapshotEvent = Schema.Struct({
690 version: Schema.Literal(1),
691 type: Schema.Literal("snapshot"),
692 config: ServerConfig,
693});
694export type ServerConfigStreamSnapshotEvent = typeof ServerConfigStreamSnapshotEvent.Type;
695​
696export const ServerConfigStreamKeybindingsUpdatedEvent = Schema.Struct({
697 version: Schema.Literal(1),
698 type: Schema.Literal("keybindingsUpdated"),
699 payload: ServerConfigKeybindingsUpdatedPayload,
700});
701export type ServerConfigStreamKeybindingsUpdatedEvent =
702 typeof ServerConfigStreamKeybindingsUpdatedEvent.Type;
703​
704export const ServerConfigStreamProviderStatusesEvent = Schema.Struct({
705 version: Schema.Literal(1),
706 type: Schema.Literal("providerStatuses"),
707 payload: ServerConfigProviderStatusesPayload,
708});
709export type ServerConfigStreamProviderStatusesEvent =
710 typeof ServerConfigStreamProviderStatusesEvent.Type;
711​
712export const ServerConfigStreamSettingsUpdatedEvent = Schema.Struct({
713 version: Schema.Literal(1),
714 type: Schema.Literal("settingsUpdated"),
715 payload: ServerConfigSettingsUpdatedPayload,
716});
717export type ServerConfigStreamSettingsUpdatedEvent =
718 typeof ServerConfigStreamSettingsUpdatedEvent.Type;
719​
720export const ServerConfigEnvironmentThemesUpdatedPayload = Schema.Struct({
721 themes: Schema.Array(EnvironmentTheme),
722});
723export type ServerConfigEnvironmentThemesUpdatedPayload =
724 typeof ServerConfigEnvironmentThemesUpdatedPayload.Type;
725​
726export const ServerConfigStreamEnvironmentThemesUpdatedEvent = Schema.Struct({
727 version: Schema.Literal(1),
728 type: Schema.Literal("environmentThemesUpdated"),
729 payload: ServerConfigEnvironmentThemesUpdatedPayload,
730});
731export type ServerConfigStreamEnvironmentThemesUpdatedEvent =
732 typeof ServerConfigStreamEnvironmentThemesUpdatedEvent.Type;
733​
734export const ServerConfigUsageLimitSourcesUpdatedPayload = Schema.Struct({
735 sources: UsageLimitSourceSnapshots,
736});
737export type ServerConfigUsageLimitSourcesUpdatedPayload =
738 typeof ServerConfigUsageLimitSourcesUpdatedPayload.Type;
739​
740export const ServerConfigStreamUsageLimitSourcesUpdatedEvent = Schema.Struct({
741 version: Schema.Literal(1),
742 type: Schema.Literal("usageLimitSourcesUpdated"),
743 payload: ServerConfigUsageLimitSourcesUpdatedPayload,
744});
745export type ServerConfigStreamUsageLimitSourcesUpdatedEvent =
746 typeof ServerConfigStreamUsageLimitSourcesUpdatedEvent.Type;
747​
748export const ServerConfigStreamEvent = Schema.Union([
749 ServerConfigStreamSnapshotEvent,
750 ServerConfigStreamKeybindingsUpdatedEvent,
751 ServerConfigStreamProviderStatusesEvent,
752 ServerConfigStreamSettingsUpdatedEvent,
753 ServerConfigStreamEnvironmentThemesUpdatedEvent,
754 ServerConfigStreamUsageLimitSourcesUpdatedEvent,
755]);
756export type ServerConfigStreamEvent = typeof ServerConfigStreamEvent.Type;
757​
758export const ServerSelfUpdateOutcome = Schema.Struct({
759 id: TrimmedNonEmptyString,
760 fromVersion: TrimmedNonEmptyString,
761 targetVersion: TrimmedNonEmptyString,
762 status: Schema.Literals(["committed", "rolled-back", "failed"]),
763 reason: Schema.optionalKey(TrimmedNonEmptyString),
764});
765export type ServerSelfUpdateOutcome = typeof ServerSelfUpdateOutcome.Type;
766​
767export const ServerLifecycleReadyPayload = Schema.Struct({
768 at: IsoDateTime,
769 environment: ExecutionEnvironmentDescriptor,
770 updateOutcome: Schema.optionalKey(ServerSelfUpdateOutcome),
771});
772export type ServerLifecycleReadyPayload = typeof ServerLifecycleReadyPayload.Type;
773​
774export const ServerLifecycleWelcomePayload = Schema.Struct({
775 environment: ExecutionEnvironmentDescriptor,
776 cwd: TrimmedNonEmptyString,
777 projectName: TrimmedNonEmptyString,
778 bootstrapStatus: Schema.optional(Schema.Literals(["pending", "complete"])),
779 bootstrapProjectId: Schema.optional(ProjectId),
780 bootstrapThreadId: Schema.optional(ThreadId),
781 bootstrapProjectCreated: Schema.optional(Schema.Boolean),
782 bootstrapThreadCreated: Schema.optional(Schema.Boolean),
783});
784export type ServerLifecycleWelcomePayload = typeof ServerLifecycleWelcomePayload.Type;
785​
786export const ServerLifecycleLegacyThreadMigrationPayload = Schema.Struct({
787 status: Schema.Union([Schema.Literal("running"), Schema.Literal("complete")]),
788 totalThreadCount: NonNegativeInt,
789});
790export type ServerLifecycleLegacyThreadMigrationPayload =
791 typeof ServerLifecycleLegacyThreadMigrationPayload.Type;
792​
793export const ServerLifecycleStreamWelcomeEvent = Schema.Struct({
794 version: Schema.Literal(1),
795 sequence: NonNegativeInt,
796 type: Schema.Literal("welcome"),
797 payload: ServerLifecycleWelcomePayload,
798});
799export type ServerLifecycleStreamWelcomeEvent = typeof ServerLifecycleStreamWelcomeEvent.Type;
800​
801export const ServerLifecycleStreamReadyEvent = Schema.Struct({
802 version: Schema.Literal(1),
803 sequence: NonNegativeInt,
804 type: Schema.Literal("ready"),
805 payload: ServerLifecycleReadyPayload,
806});
807export type ServerLifecycleStreamReadyEvent = typeof ServerLifecycleStreamReadyEvent.Type;
808​
809export const ServerLifecycleStreamLegacyThreadMigrationEvent = Schema.Struct({
810 version: Schema.Literal(1),
811 sequence: NonNegativeInt,
812 type: Schema.Literal("legacyThreadMigration"),
813 payload: ServerLifecycleLegacyThreadMigrationPayload,
814});
815export type ServerLifecycleStreamLegacyThreadMigrationEvent =
816 typeof ServerLifecycleStreamLegacyThreadMigrationEvent.Type;
817​
818export const ServerLifecycleStreamEvent = Schema.Union([
819 ServerLifecycleStreamWelcomeEvent,
820 ServerLifecycleStreamReadyEvent,
821 ServerLifecycleStreamLegacyThreadMigrationEvent,
822]);
823export type ServerLifecycleStreamEvent = typeof ServerLifecycleStreamEvent.Type;
824​
825export const ServerProviderUpdatedPayload = Schema.Struct({
826 providers: ServerProviders,
827});
828export type ServerProviderUpdatedPayload = typeof ServerProviderUpdatedPayload.Type;
829​
830export const ServerProviderUpdateInput = Schema.Struct({
831 provider: ProviderDriverKind,
832 targetVersion: Schema.optionalKey(TrimmedNonEmptyString),
833 instanceId: Schema.optionalKey(ProviderInstanceId),
834});
835export type ServerProviderUpdateInput = typeof ServerProviderUpdateInput.Type;
836​
837export class ServerProviderUpdateError extends Schema.TaggedError<ServerProviderUpdateError>()(
838 "ServerProviderUpdateError",
839 {
840 provider: ProviderDriverKind,
841 reason: TrimmedNonEmptyString,
842 cause: Schema.optional(Schema.Defect()),
843 },
844) {
845 override get message(): string {
846 return `Provider update failed for ${this.provider}: ${this.reason}`;
847 }
849​
850export const ServerSelfUpdateInput = Schema.Struct({
851 /** Exact npm version of the `t3` package to install (never a dist-tag, so
852 the server and the acknowledging client agree on what was requested). */
853 targetVersion: TrimmedNonEmptyString,
854 continueRunningThreads: Schema.optionalKey(Schema.Boolean),
855});
856export type ServerSelfUpdateInput = typeof ServerSelfUpdateInput.Type;
857​
858export const ServerSelfUpdateResult = Schema.Struct({
859 targetVersion: TrimmedNonEmptyString,
860 method: ServerSelfUpdateMethod,
861 updateId: Schema.optionalKey(TrimmedNonEmptyString),
862 desktopUpdateToken: Schema.optionalKey(TrimmedNonEmptyString),
863});
864export type ServerSelfUpdateResult = typeof ServerSelfUpdateResult.Type;
865​
866export const DesktopUpdateCommitInput = Schema.Struct({
867 requestId: TrimmedNonEmptyString,
868});
869export type DesktopUpdateCommitInput = typeof DesktopUpdateCommitInput.Type;
870​
871export const ServerSelfUpdateProgressStage = Schema.Literals(["downloading", "installing"]);
872export type ServerSelfUpdateProgressStage = typeof ServerSelfUpdateProgressStage.Type;
873​
874export const ServerSelfUpdateProgressEvent = Schema.Union([
875 Schema.Struct({
876 type: Schema.Literal("progress"),
877 stage: ServerSelfUpdateProgressStage,
878 }),
879 Schema.Struct({
880 type: Schema.Literal("complete"),
881 result: ServerSelfUpdateResult,
882 }),
883]);
884export type ServerSelfUpdateProgressEvent = typeof ServerSelfUpdateProgressEvent.Type;
885​
886export class ServerSelfUpdateError extends Schema.TaggedError<ServerSelfUpdateError>()(
887 "ServerSelfUpdateError",
888 {
889 reason: TrimmedNonEmptyString,
890 cause: Schema.optional(Schema.Defect()),
891 },
892) {
893 override get message(): string {
894 return `Server update failed: ${this.reason}`;
895 }