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

server.ts

899 lines34.3 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 // Version reported by the installed CLI for a local provider with a separate
261 // server. Null means unknown; absence keeps legacy snapshots on `version`.
262 installedVersion: Schema.optionalKey(Schema.NullOr(TrimmedNonEmptyString)),
263 status: ServerProviderState,
264 auth: ServerProviderAuth,
265 checkedAt: IsoDateTime,
266 message: Schema.optional(TrimmedNonEmptyString),
267 availability: Schema.optional(ServerProviderAvailability),
268 unavailableReason: Schema.optional(TrimmedNonEmptyString),
269 models: Schema.Array(ServerProviderModel),
270 // Kept apart from `models` so clients that predate it never offer them.
271 updateRequiredModels: Schema.optionalKey(Schema.Array(ServerProviderUpdateRequiredModel)),
272 slashCommands: Schema.Array(ServerProviderSlashCommand).pipe(
273 Schema.withDecodingDefault(Effect.succeed([])),
274 ),
275 skills: Schema.Array(ServerProviderSkill).pipe(Schema.withDecodingDefault(Effect.succeed([]))),
276 workspaceSnapshots: Schema.optionalKey(Schema.Array(ServerProviderWorkspaceSnapshot)),
277 usageLimits: Schema.optional(ServerProviderUsageLimits),
278 versionAdvisory: Schema.optionalKey(ServerProviderVersionAdvisory),
279 compatibilityAdvisory: Schema.optionalKey(ServerProviderCompatibilityAdvisory),
280 updateState: Schema.optionalKey(ServerProviderUpdateState),
281});
282export type ServerProvider = typeof ServerProvider.Type;
283​
284export const ServerProviders = ForwardCompatibleArray(ServerProvider);
285export type ServerProviders = typeof ServerProviders.Type;
286​
287export const isProviderAvailable = (snapshot: ServerProvider): boolean =>
288 snapshot.availability !== "unavailable";
289​
290/**
291 * Treat an absent `supportsTextGeneration` as supported so legacy
292 * producers, which all support application text generation, keep working
293 * without resending the field.
294 */
295export const isProviderTextGenerationCapable = (snapshot: ServerProvider): boolean =>
296 snapshot.supportsTextGeneration !== false;
297​
298export const ServerObservability = Schema.Struct({
299 logsDirectoryPath: TrimmedNonEmptyString,
300 localTracingEnabled: Schema.Boolean,
301 otlpTracesUrl: Schema.optional(TrimmedNonEmptyString),
302 otlpTracesEnabled: Schema.Boolean,
303 otlpMetricsUrl: Schema.optional(TrimmedNonEmptyString),
304 otlpMetricsEnabled: Schema.Boolean,
305 otlpLogsUrl: Schema.optional(TrimmedNonEmptyString),
306 otlpLogsEnabled: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(false))),
307});
308export type ServerObservability = typeof ServerObservability.Type;
309​
310export const OtlpSignal = Schema.Literals(["traces", "metrics", "logs"]);
311export type OtlpSignal = typeof OtlpSignal.Type;
312​
313export const OtlpEndpointCheckInput = Schema.Struct({
314 signal: OtlpSignal,
315 url: TrimmedNonEmptyString.check(Schema.isPattern(/^https?:\/\/./i)),
316});
317export type OtlpEndpointCheckInput = typeof OtlpEndpointCheckInput.Type;
318​
319export const OtlpEndpointCheckResult = Schema.Union([
320 Schema.TaggedStruct("Accepted", { latencyMs: Schema.Number }),
321 Schema.TaggedStruct("Rejected", { status: Schema.Number }),
322 Schema.TaggedStruct("Unreachable", { timedOut: Schema.Boolean }),
323]);
324export type OtlpEndpointCheckResult = typeof OtlpEndpointCheckResult.Type;
325​
326export const ServerTraceDiagnosticsErrorKind = Schema.Literals([
327 "trace-file-not-found",
328 "trace-file-read-failed",
329]);
330export type ServerTraceDiagnosticsErrorKind = typeof ServerTraceDiagnosticsErrorKind.Type;
331​
332export const ServerTraceDiagnosticsSpanSummary = Schema.Struct({
333 name: TrimmedNonEmptyString,
334 count: NonNegativeInt,
335 failureCount: NonNegativeInt,
336 totalDurationMs: Schema.Number,
337 averageDurationMs: Schema.Number,
338 maxDurationMs: Schema.Number,
339});
340export type ServerTraceDiagnosticsSpanSummary = typeof ServerTraceDiagnosticsSpanSummary.Type;
341​
342export const ServerTraceDiagnosticsFailureSummary = Schema.Struct({
343 name: TrimmedNonEmptyString,
344 cause: TrimmedNonEmptyString,
345 count: NonNegativeInt,
346 lastSeenAt: Schema.DateTimeUtc,
347 traceId: TrimmedNonEmptyString,
348 spanId: TrimmedNonEmptyString,
349});
350export type ServerTraceDiagnosticsFailureSummary = typeof ServerTraceDiagnosticsFailureSummary.Type;
351​
352export const ServerTraceDiagnosticsRecentFailure = Schema.Struct({
353 name: TrimmedNonEmptyString,
354 cause: TrimmedNonEmptyString,
355 durationMs: Schema.Number,
356 endedAt: Schema.DateTimeUtc,
357 traceId: TrimmedNonEmptyString,
358 spanId: TrimmedNonEmptyString,
359});
360export type ServerTraceDiagnosticsRecentFailure = typeof ServerTraceDiagnosticsRecentFailure.Type;
361​
362export const ServerTraceDiagnosticsSpanOccurrence = Schema.Struct({
363 name: TrimmedNonEmptyString,
364 durationMs: Schema.Number,
365 endedAt: Schema.DateTimeUtc,
366 traceId: TrimmedNonEmptyString,
367 spanId: TrimmedNonEmptyString,
368});
369export type ServerTraceDiagnosticsSpanOccurrence = typeof ServerTraceDiagnosticsSpanOccurrence.Type;
370​
371export const ServerTraceDiagnosticsLogEvent = Schema.Struct({
372 spanName: TrimmedNonEmptyString,
373 level: TrimmedNonEmptyString,
374 message: TrimmedNonEmptyString,
375 seenAt: Schema.DateTimeUtc,
376 traceId: TrimmedNonEmptyString,
377 spanId: TrimmedNonEmptyString,
378});
379export type ServerTraceDiagnosticsLogEvent = typeof ServerTraceDiagnosticsLogEvent.Type;
380​
381export const ServerTraceDiagnosticsResult = Schema.Struct({
382 traceFilePath: TrimmedNonEmptyString,
383 scannedFilePaths: Schema.Array(TrimmedNonEmptyString),
384 readAt: Schema.DateTimeUtc,
385 recordCount: NonNegativeInt,
386 parseErrorCount: NonNegativeInt,
387 firstSpanAt: Schema.Option(Schema.DateTimeUtc),
388 lastSpanAt: Schema.Option(Schema.DateTimeUtc),
389 failureCount: NonNegativeInt,
390 interruptionCount: NonNegativeInt,
391 slowSpanThresholdMs: NonNegativeInt,
392 slowSpanCount: NonNegativeInt,
393 logLevelCounts: Schema.Record(TrimmedNonEmptyString, NonNegativeInt),
394 topSpansByCount: Schema.Array(ServerTraceDiagnosticsSpanSummary),
395 slowestSpans: Schema.Array(ServerTraceDiagnosticsSpanOccurrence),
396 commonFailures: Schema.Array(ServerTraceDiagnosticsFailureSummary),
397 latestFailures: Schema.Array(ServerTraceDiagnosticsRecentFailure),
398 latestWarningAndErrorLogs: Schema.Array(ServerTraceDiagnosticsLogEvent),
399 partialFailure: Schema.Option(Schema.Boolean),
400 error: Schema.Option(
401 Schema.Struct({
402 kind: ServerTraceDiagnosticsErrorKind,
403 message: TrimmedNonEmptyString,
404 }),
405 ),
406});
407export type ServerTraceDiagnosticsResult = typeof ServerTraceDiagnosticsResult.Type;
408​
409export const ServerProcessSignal = Schema.Literals(["SIGINT", "SIGKILL"]);
410export type ServerProcessSignal = typeof ServerProcessSignal.Type;
411​
412export const ServerProcessDiagnosticsEntry = Schema.Struct({
413 pid: PositiveInt,
414 startTimeMs: NonNegativeInt,
415 ppid: NonNegativeInt,
416 pgid: Schema.Option(Schema.Int),
417 status: TrimmedNonEmptyString,
418 cpuPercent: Schema.Number,
419 rssBytes: NonNegativeInt,
420 elapsed: TrimmedNonEmptyString,
421 command: TrimmedNonEmptyString,
422 depth: NonNegativeInt,
423 childPids: Schema.Array(PositiveInt),
424});
425export type ServerProcessDiagnosticsEntry = typeof ServerProcessDiagnosticsEntry.Type;
426​
427export const ServerProcessDiagnosticsResult = Schema.Struct({
428 serverPid: PositiveInt,
429 readAt: Schema.DateTimeUtc,
430 processCount: NonNegativeInt,
431 totalRssBytes: NonNegativeInt,
432 totalCpuPercent: Schema.Number,
433 processes: Schema.Array(ServerProcessDiagnosticsEntry),
434 error: Schema.Option(
435 Schema.Struct({
436 message: TrimmedNonEmptyString,
437 }),
438 ),
439});
440export type ServerProcessDiagnosticsResult = typeof ServerProcessDiagnosticsResult.Type;
441​
442export const ServerProcessResourceHistoryInput = Schema.Struct({
443 windowMs: NonNegativeInt,
444 bucketMs: NonNegativeInt,
445});
446export type ServerProcessResourceHistoryInput = typeof ServerProcessResourceHistoryInput.Type;
447​
448export const ServerProcessResourceHistoryBucket = Schema.Struct({
449 startedAt: Schema.DateTimeUtc,
450 endedAt: Schema.DateTimeUtc,
451 avgCpuPercent: Schema.Number,
452 maxCpuPercent: Schema.Number,
453 maxRssBytes: NonNegativeInt,
454 maxProcessCount: NonNegativeInt,
455});
456export type ServerProcessResourceHistoryBucket = typeof ServerProcessResourceHistoryBucket.Type;
457​
458export const ServerProcessResourceHistorySummary = Schema.Struct({
459 processKey: TrimmedNonEmptyString,
460 pid: PositiveInt,
461 ppid: NonNegativeInt,
462 command: TrimmedNonEmptyString,
463 depth: NonNegativeInt,
464 isServerRoot: Schema.Boolean,
465 firstSeenAt: Schema.DateTimeUtc,
466 lastSeenAt: Schema.DateTimeUtc,
467 currentCpuPercent: Schema.Number,
468 avgCpuPercent: Schema.Number,
469 maxCpuPercent: Schema.Number,
470 cpuSecondsApprox: Schema.Number,
471 currentRssBytes: NonNegativeInt,
472 maxRssBytes: NonNegativeInt,
473 sampleCount: NonNegativeInt,
474});
475export type ServerProcessResourceHistorySummary = typeof ServerProcessResourceHistorySummary.Type;
476​
477export const ServerProcessResourceHistoryFailureTag = Schema.Literals([
478 "ProcessDiagnosticsQueryTimeoutError",
479 "ProcessDiagnosticsQueryFailedError",
480 "ProcessDiagnosticsServerProcessSignalError",
481 "ProcessDiagnosticsNotDescendantError",
482 "ProcessDiagnosticsSignalFailedError",
483]);
484export type ServerProcessResourceHistoryFailureTag =
485 typeof ServerProcessResourceHistoryFailureTag.Type;
486​
487export const ServerProcessResourceHistoryResult = Schema.Struct({
488 readAt: Schema.DateTimeUtc,
489 windowMs: NonNegativeInt,
490 bucketMs: NonNegativeInt,
491 sampleIntervalMs: NonNegativeInt,
492 retainedSampleCount: NonNegativeInt,
493 totalCpuSecondsApprox: Schema.Number,
494 buckets: Schema.Array(ServerProcessResourceHistoryBucket),
495 topProcesses: Schema.Array(ServerProcessResourceHistorySummary),
496 error: Schema.Option(
497 Schema.Struct({
498 failureTag: ServerProcessResourceHistoryFailureTag,
499 message: TrimmedNonEmptyString,
500 }),
501 ),
502});
503export type ServerProcessResourceHistoryResult = typeof ServerProcessResourceHistoryResult.Type;
504​
505export const ServerSignalProcessInput = Schema.Struct({
506 pid: PositiveInt,
507 startTimeMs: NonNegativeInt,
508 signal: ServerProcessSignal,
509});
510export type ServerSignalProcessInput = typeof ServerSignalProcessInput.Type;
511​
512export const ServerSignalProcessResult = Schema.Struct({
513 pid: PositiveInt,
514 signal: ServerProcessSignal,
515 signaled: Schema.Boolean,
516 message: Schema.Option(TrimmedNonEmptyString),
517});
518export type ServerSignalProcessResult = typeof ServerSignalProcessResult.Type;
519​
520export const EnvironmentThemeColor = Schema.String.check(
521 Schema.isPattern(/^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/),
522);
523export type EnvironmentThemeColor = typeof EnvironmentThemeColor.Type;
524​
525/**
526 * The appearance keywords are excluded outright: a published `dark.json`
527 * would otherwise capture every client whose stored preference is the stock
528 * `"dark"`, retinting people who never chose it.
529 */
530export const EnvironmentThemeId = Schema.String.check(
531 Schema.isPattern(/^(?!(?:system|light|dark)$)[a-z0-9](?:[a-z0-9-]{0,47})$/),
532);
533export type EnvironmentThemeId = typeof EnvironmentThemeId.Type;
534​
535const EnvironmentThemeColors = Schema.Record(
536 Schema.String.check(Schema.isPattern(/^[a-zA-Z][a-zA-Z0-9]{0,63}$/)),
537 TrimmedNonEmptyString.check(Schema.isMaxLength(64)),
538);
539​
540const environmentThemeFields = {
541 version: Schema.optional(Schema.Literal(1)),
542 name: TrimmedNonEmptyString.check(Schema.isMaxLength(48)),
543 appearance: Schema.Literals(["light", "dark"]),
544 /**
545 * When present, clients derive the full palette from them with the guided
546 * theme editor's generator and layer `colors` on top; when absent, `colors`
547 * is the palette, as in an exported theme file.
548 */
549 canvas: Schema.optional(EnvironmentThemeColor),
550 accent: Schema.optional(EnvironmentThemeColor),
551 colors: Schema.optional(EnvironmentThemeColors),
552 variants: Schema.optional(
553 Schema.Struct({
554 light: Schema.optional(EnvironmentThemeColors),
555 dark: Schema.optional(EnvironmentThemeColors),
556 }),
557 ),
558};
559​
560export const EnvironmentThemeFile = Schema.Struct(environmentThemeFields);
561export type EnvironmentThemeFile = typeof EnvironmentThemeFile.Type;
562​
563export const EnvironmentTheme = Schema.Struct({
564 id: EnvironmentThemeId,
565 ...environmentThemeFields,
566});
567export type EnvironmentTheme = typeof EnvironmentTheme.Type;
568​
569export function environmentThemeFileHasColors(file: EnvironmentThemeFile): boolean {
570 return (
571 (file.canvas !== undefined && file.accent !== undefined) ||
572 (file.colors !== undefined && Object.keys(file.colors).length > 0)
573 );
575​
576/**
577 * "tailnet" when the address is on this machine's Tailscale interface, "lan"
578 * for any other private address, including other VPNs in 100.64.0.0/10.
579 */
580export const ServerDirectEndpointKind = Schema.Literals(["lan", "tailnet"]);
581export type ServerDirectEndpointKind = typeof ServerDirectEndpointKind.Type;
582​
583export const ServerDirectEndpoint = Schema.Struct({
584 kind: ServerDirectEndpointKind,
585 httpBaseUrl: TrimmedNonEmptyString,
586});
587export type ServerDirectEndpoint = typeof ServerDirectEndpoint.Type;
588​
589export const ServerConfig = Schema.Struct({
590 environment: ExecutionEnvironmentDescriptor,
591 auth: ServerAuthDescriptor,
592 cwd: TrimmedNonEmptyString,
593 keybindingsConfigPath: TrimmedNonEmptyString,
594 keybindings: ResolvedKeybindingsConfig,
595 issues: ServerConfigIssues,
596 providers: ServerProviders,
597 availableEditors: ForwardCompatibleArray(EditorId),
598 remoteOpenTargets: Schema.optionalKey(ForwardCompatibleArray(RemoteOpenTarget)),
599 /**
600 * Hints only: the client checks each address answers as this environment
601 * before using it.
602 */
603 directEndpoints: Schema.optionalKey(ForwardCompatibleArray(ServerDirectEndpoint)),
604 observability: ServerObservability,
605 settings: ServerSettings,
606 shellResumeCompletionMarker: Schema.optionalKey(Schema.Boolean),
607 shellRevealInFileManager: Schema.optionalKey(Schema.Boolean),
608 shellRevealInFileManagerKind: Schema.optionalKey(FileManagerRevealKind),
609 threadResumeCompletionMarker: Schema.optionalKey(Schema.Boolean),
610 /**
611 * Clients must not send window fields to servers that don't advertise this.
612 */
613 threadSnapshotPagination: Schema.optionalKey(Schema.Boolean),
614 reasoningMessages: Schema.optionalKey(Schema.Boolean),
615 threadFind: Schema.optionalKey(Schema.Boolean),
616 threadFindProgressive: Schema.optionalKey(Schema.Boolean),
617 scratchWorkspaceRoot: Schema.optionalKey(TrimmedNonEmptyString),
618 newProjectsRoot: Schema.optionalKey(TrimmedNonEmptyString),
619 /**
620 * Never sent in a config snapshot: the theme stream emits the current set
621 * before any change, so a snapshot carrying it too would hand every
622 * subscriber the same array twice per connect.
623 */
624 environmentThemes: Schema.optional(Schema.Array(EnvironmentTheme)),
625 /**
626 * Like themes, never in a snapshot: the source stream emits the current set
627 * on subscribe, and it stays absent for subscribers that did not opt in.
628 */
629 usageLimitSources: Schema.optional(UsageLimitSourceSnapshots),
630});
631export type ServerConfig = typeof ServerConfig.Type;
632​
633export function resolveEnvironmentMachineKind(
634 config: {
635 readonly environment: Pick<ExecutionEnvironmentDescriptor, "platform">;
636 readonly settings?: Pick<ServerSettings, "environmentIcon">;
637 } | null,
638): EnvironmentMachineKind {
639 return config?.settings?.environmentIcon ?? config?.environment.platform.machine ?? "server";
641​
642const ServerUpsertKeybindingReplaceTarget = Schema.Struct({
643 key: KeybindingValue,
644 command: KeybindingCommand,
645 when: Schema.optional(KeybindingWhen),
646});
647​
648export const ServerUpsertKeybindingInput = Schema.Struct({
649 key: KeybindingValue,
650 command: KeybindingCommand,
651 when: Schema.optional(KeybindingWhen),
652 replace: Schema.optional(ServerUpsertKeybindingReplaceTarget),
653});
654export type ServerUpsertKeybindingInput = typeof ServerUpsertKeybindingInput.Type;
655​
656export const ServerRemoveKeybindingInput = ServerUpsertKeybindingReplaceTarget;
657export type ServerRemoveKeybindingInput = typeof ServerRemoveKeybindingInput.Type;
658​
659export const ServerUpsertKeybindingResult = Schema.Struct({
660 keybindings: ResolvedKeybindingsConfig,
661 issues: ServerConfigIssues,
662});
663export type ServerUpsertKeybindingResult = typeof ServerUpsertKeybindingResult.Type;
664​
665export const ServerRemoveKeybindingResult = ServerUpsertKeybindingResult;
666export type ServerRemoveKeybindingResult = typeof ServerRemoveKeybindingResult.Type;
667​
668export const ServerConfigUpdatedPayload = Schema.Struct({
669 issues: ServerConfigIssues,
670 providers: ServerProviders,
671 settings: Schema.optional(ServerSettings),
672});
673export type ServerConfigUpdatedPayload = typeof ServerConfigUpdatedPayload.Type;
674​
675export const ServerConfigKeybindingsUpdatedPayload = Schema.Struct({
676 keybindings: ResolvedKeybindingsConfig,
677 issues: ServerConfigIssues,
678});
679export type ServerConfigKeybindingsUpdatedPayload =
680 typeof ServerConfigKeybindingsUpdatedPayload.Type;
681​
682export const ServerConfigProviderStatusesPayload = Schema.Struct({
683 providers: ServerProviders,
684});
685export type ServerConfigProviderStatusesPayload = typeof ServerConfigProviderStatusesPayload.Type;
686​
687export const ServerConfigSettingsUpdatedPayload = Schema.Struct({
688 settings: ServerSettings,
689});
690export type ServerConfigSettingsUpdatedPayload = typeof ServerConfigSettingsUpdatedPayload.Type;
691​
692export const ServerConfigStreamSnapshotEvent = Schema.Struct({
693 version: Schema.Literal(1),
694 type: Schema.Literal("snapshot"),
695 config: ServerConfig,
696});
697export type ServerConfigStreamSnapshotEvent = typeof ServerConfigStreamSnapshotEvent.Type;
698​
699export const ServerConfigStreamKeybindingsUpdatedEvent = Schema.Struct({
700 version: Schema.Literal(1),
701 type: Schema.Literal("keybindingsUpdated"),
702 payload: ServerConfigKeybindingsUpdatedPayload,
703});
704export type ServerConfigStreamKeybindingsUpdatedEvent =
705 typeof ServerConfigStreamKeybindingsUpdatedEvent.Type;
706​
707export const ServerConfigStreamProviderStatusesEvent = Schema.Struct({
708 version: Schema.Literal(1),
709 type: Schema.Literal("providerStatuses"),
710 payload: ServerConfigProviderStatusesPayload,
711});
712export type ServerConfigStreamProviderStatusesEvent =
713 typeof ServerConfigStreamProviderStatusesEvent.Type;
714​
715export const ServerConfigStreamSettingsUpdatedEvent = Schema.Struct({
716 version: Schema.Literal(1),
717 type: Schema.Literal("settingsUpdated"),
718 payload: ServerConfigSettingsUpdatedPayload,
719});
720export type ServerConfigStreamSettingsUpdatedEvent =
721 typeof ServerConfigStreamSettingsUpdatedEvent.Type;
722​
723export const ServerConfigEnvironmentThemesUpdatedPayload = Schema.Struct({
724 themes: Schema.Array(EnvironmentTheme),
725});
726export type ServerConfigEnvironmentThemesUpdatedPayload =
727 typeof ServerConfigEnvironmentThemesUpdatedPayload.Type;
728​
729export const ServerConfigStreamEnvironmentThemesUpdatedEvent = Schema.Struct({
730 version: Schema.Literal(1),
731 type: Schema.Literal("environmentThemesUpdated"),
732 payload: ServerConfigEnvironmentThemesUpdatedPayload,
733});
734export type ServerConfigStreamEnvironmentThemesUpdatedEvent =
735 typeof ServerConfigStreamEnvironmentThemesUpdatedEvent.Type;
736​
737export const ServerConfigUsageLimitSourcesUpdatedPayload = Schema.Struct({
738 sources: UsageLimitSourceSnapshots,
739});
740export type ServerConfigUsageLimitSourcesUpdatedPayload =
741 typeof ServerConfigUsageLimitSourcesUpdatedPayload.Type;
742​
743export const ServerConfigStreamUsageLimitSourcesUpdatedEvent = Schema.Struct({
744 version: Schema.Literal(1),
745 type: Schema.Literal("usageLimitSourcesUpdated"),
746 payload: ServerConfigUsageLimitSourcesUpdatedPayload,
747});
748export type ServerConfigStreamUsageLimitSourcesUpdatedEvent =
749 typeof ServerConfigStreamUsageLimitSourcesUpdatedEvent.Type;
750​
751export const ServerConfigStreamEvent = Schema.Union([
752 ServerConfigStreamSnapshotEvent,
753 ServerConfigStreamKeybindingsUpdatedEvent,
754 ServerConfigStreamProviderStatusesEvent,
755 ServerConfigStreamSettingsUpdatedEvent,
756 ServerConfigStreamEnvironmentThemesUpdatedEvent,
757 ServerConfigStreamUsageLimitSourcesUpdatedEvent,
758]);
759export type ServerConfigStreamEvent = typeof ServerConfigStreamEvent.Type;
760​
761export const ServerSelfUpdateOutcome = Schema.Struct({
762 id: TrimmedNonEmptyString,
763 fromVersion: TrimmedNonEmptyString,
764 targetVersion: TrimmedNonEmptyString,
765 status: Schema.Literals(["committed", "rolled-back", "failed"]),
766 reason: Schema.optionalKey(TrimmedNonEmptyString),
767});
768export type ServerSelfUpdateOutcome = typeof ServerSelfUpdateOutcome.Type;
769​
770export const ServerLifecycleReadyPayload = Schema.Struct({
771 at: IsoDateTime,
772 environment: ExecutionEnvironmentDescriptor,
773 updateOutcome: Schema.optionalKey(ServerSelfUpdateOutcome),
774});
775export type ServerLifecycleReadyPayload = typeof ServerLifecycleReadyPayload.Type;
776​
777export const ServerLifecycleWelcomePayload = Schema.Struct({
778 environment: ExecutionEnvironmentDescriptor,
779 cwd: TrimmedNonEmptyString,
780 projectName: TrimmedNonEmptyString,
781 bootstrapStatus: Schema.optional(Schema.Literals(["pending", "complete"])),
782 bootstrapProjectId: Schema.optional(ProjectId),
783 bootstrapThreadId: Schema.optional(ThreadId),
784 bootstrapProjectCreated: Schema.optional(Schema.Boolean),
785 bootstrapThreadCreated: Schema.optional(Schema.Boolean),
786});
787export type ServerLifecycleWelcomePayload = typeof ServerLifecycleWelcomePayload.Type;
788​
789export const ServerLifecycleLegacyThreadMigrationPayload = Schema.Struct({
790 status: Schema.Union([Schema.Literal("running"), Schema.Literal("complete")]),
791 totalThreadCount: NonNegativeInt,
792});
793export type ServerLifecycleLegacyThreadMigrationPayload =
794 typeof ServerLifecycleLegacyThreadMigrationPayload.Type;
795​
796export const ServerLifecycleStreamWelcomeEvent = Schema.Struct({
797 version: Schema.Literal(1),
798 sequence: NonNegativeInt,
799 type: Schema.Literal("welcome"),
800 payload: ServerLifecycleWelcomePayload,
801});
802export type ServerLifecycleStreamWelcomeEvent = typeof ServerLifecycleStreamWelcomeEvent.Type;
803​
804export const ServerLifecycleStreamReadyEvent = Schema.Struct({
805 version: Schema.Literal(1),
806 sequence: NonNegativeInt,
807 type: Schema.Literal("ready"),
808 payload: ServerLifecycleReadyPayload,
809});
810export type ServerLifecycleStreamReadyEvent = typeof ServerLifecycleStreamReadyEvent.Type;
811​
812export const ServerLifecycleStreamLegacyThreadMigrationEvent = Schema.Struct({
813 version: Schema.Literal(1),
814 sequence: NonNegativeInt,
815 type: Schema.Literal("legacyThreadMigration"),
816 payload: ServerLifecycleLegacyThreadMigrationPayload,
817});
818export type ServerLifecycleStreamLegacyThreadMigrationEvent =
819 typeof ServerLifecycleStreamLegacyThreadMigrationEvent.Type;
820​
821export const ServerLifecycleStreamEvent = Schema.Union([
822 ServerLifecycleStreamWelcomeEvent,
823 ServerLifecycleStreamReadyEvent,
824 ServerLifecycleStreamLegacyThreadMigrationEvent,
825]);
826export type ServerLifecycleStreamEvent = typeof ServerLifecycleStreamEvent.Type;
827​
828export const ServerProviderUpdatedPayload = Schema.Struct({
829 providers: ServerProviders,
830});
831export type ServerProviderUpdatedPayload = typeof ServerProviderUpdatedPayload.Type;
832​
833export const ServerProviderUpdateInput = Schema.Struct({
834 provider: ProviderDriverKind,
835 targetVersion: Schema.optionalKey(TrimmedNonEmptyString),
836 instanceId: Schema.optionalKey(ProviderInstanceId),
837});
838export type ServerProviderUpdateInput = typeof ServerProviderUpdateInput.Type;
839​
840export class ServerProviderUpdateError extends Schema.TaggedError<ServerProviderUpdateError>()(
841 "ServerProviderUpdateError",
842 {
843 provider: ProviderDriverKind,
844 reason: TrimmedNonEmptyString,
845 cause: Schema.optional(Schema.Defect()),
846 },
847) {
848 override get message(): string {
849 return `Provider update failed for ${this.provider}: ${this.reason}`;
850 }
852​
853export const ServerSelfUpdateInput = Schema.Struct({
854 /** Exact npm version of the `t3` package to install (never a dist-tag, so
855 the server and the acknowledging client agree on what was requested). */
856 targetVersion: TrimmedNonEmptyString,
857 continueRunningThreads: Schema.optionalKey(Schema.Boolean),
858});
859export type ServerSelfUpdateInput = typeof ServerSelfUpdateInput.Type;
860​
861export const ServerSelfUpdateResult = Schema.Struct({
862 targetVersion: TrimmedNonEmptyString,
863 method: ServerSelfUpdateMethod,
864 updateId: Schema.optionalKey(TrimmedNonEmptyString),
865 desktopUpdateToken: Schema.optionalKey(TrimmedNonEmptyString),
866});
867export type ServerSelfUpdateResult = typeof ServerSelfUpdateResult.Type;
868​
869export const DesktopUpdateCommitInput = Schema.Struct({
870 requestId: TrimmedNonEmptyString,
871});
872export type DesktopUpdateCommitInput = typeof DesktopUpdateCommitInput.Type;
873​
874export const ServerSelfUpdateProgressStage = Schema.Literals(["downloading", "installing"]);
875export type ServerSelfUpdateProgressStage = typeof ServerSelfUpdateProgressStage.Type;
876​
877export const ServerSelfUpdateProgressEvent = Schema.Union([
878 Schema.Struct({
879 type: Schema.Literal("progress"),
880 stage: ServerSelfUpdateProgressStage,
881 }),
882 Schema.Struct({
883 type: Schema.Literal("complete"),
884 result: ServerSelfUpdateResult,
885 }),
886]);
887export type ServerSelfUpdateProgressEvent = typeof ServerSelfUpdateProgressEvent.Type;
888​
889export class ServerSelfUpdateError extends Schema.TaggedError<ServerSelfUpdateError>()(
890 "ServerSelfUpdateError",
891 {
892 reason: TrimmedNonEmptyString,
893 cause: Schema.optional(Schema.Defect()),
894 },
895) {
896 override get message(): string {
897 return `Server update failed: ${this.reason}`;
898 }