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