Open History to see the last commit
1import * as Effect from "effect/Effect";
2import * as Schema from "effect/Schema";
3import * as Struct from "effect/Struct";
4import { AcpRegistryUrlAuthAction } from "./acpRegistry.ts";
5import {
6 type EnvironmentMachineKind,
7 ExecutionEnvironmentDescriptor,
8 ServerSelfUpdateMethod,
9} from "./environment.ts";
10import { ServerAuthDescriptor } from "./auth.ts";
11import {
12 ForwardCompatibleArray,
13 IsoDateTime,
14 NonNegativeInt,
15 PositiveInt,
16 ProjectId,
17 ThreadId,
18 TrimmedNonEmptyString,
19} from "./baseSchemas.ts";
20import {
21 KeybindingCommand,
22 KeybindingValue,
23 KeybindingWhen,
24 ResolvedKeybindingsConfig,
25} from "./keybindings.ts";
26import { EditorId, FileManagerRevealKind, RemoteOpenTarget } from "./editor.ts";
27import { ModelCapabilities } from "./model.ts";
28import { RuntimeMode } from "./providerPolicy.ts";
29import { ProviderDriverKind, ProviderInstanceId } from "./providerInstance.ts";
30import { ServerProviderUsageLimits, UsageLimitSourceSnapshots } from "./providerUsageLimits.ts";
31import { ServerSettings } from "./settings.ts";
32
33const KeybindingsMalformedConfigIssue = Schema.Struct({
34 kind: Schema.Literal("keybindings.malformed-config"),
35 message: TrimmedNonEmptyString,
36});
37
38const KeybindingsInvalidEntryIssue = Schema.Struct({
39 kind: Schema.Literal("keybindings.invalid-entry"),
40 message: TrimmedNonEmptyString,
41 index: Schema.Number,
42});
43
44export const ServerConfigIssue = Schema.Union([
45 KeybindingsMalformedConfigIssue,
46 KeybindingsInvalidEntryIssue,
47]);
48export type ServerConfigIssue = typeof ServerConfigIssue.Type;
49
50const ServerConfigIssues = ForwardCompatibleArray(ServerConfigIssue);
51
52export const ServerProviderState = Schema.Literals(["ready", "warning", "error", "disabled"]);
53export type ServerProviderState = typeof ServerProviderState.Type;
54
55export const ServerProviderAuthStatus = Schema.Literals([
56 "authenticated",
57 "unauthenticated",
58 "unknown",
59]);
60export type ServerProviderAuthStatus = typeof ServerProviderAuthStatus.Type;
61
62export const ServerProviderAuth = Schema.Struct({
63 status: ServerProviderAuthStatus,
64 type: Schema.optional(TrimmedNonEmptyString),
65 label: Schema.optional(TrimmedNonEmptyString),
66 email: Schema.optional(TrimmedNonEmptyString),
67 action: Schema.optional(AcpRegistryUrlAuthAction),
68 canLogout: Schema.optional(Schema.Boolean),
69 subscriptionSharing: Schema.optional(Schema.Boolean),
70 profileId: Schema.optional(TrimmedNonEmptyString),
71 workspaceId: Schema.optional(TrimmedNonEmptyString),
72});
73export type ServerProviderAuth = typeof ServerProviderAuth.Type;
74
75export const ServerProviderModel = Schema.Struct({
76 slug: TrimmedNonEmptyString,
77 name: TrimmedNonEmptyString,
78 shortName: Schema.optional(TrimmedNonEmptyString),
79 subProvider: Schema.optional(TrimmedNonEmptyString),
80 aliases: Schema.optional(Schema.Array(TrimmedNonEmptyString)),
81 badge: Schema.optional(Schema.Literal("new")),
82 isCustom: Schema.Boolean,
83 isDefault: Schema.optional(Schema.Boolean),
84 isLegacy: Schema.optional(Schema.Boolean),
85 capabilities: Schema.NullOr(ModelCapabilities),
86});
87export type ServerProviderModel = typeof ServerProviderModel.Type;
88
89export const ServerProviderUpdateRequiredModel = Schema.Struct({
90 slug: TrimmedNonEmptyString,
91 name: TrimmedNonEmptyString,
92 badge: Schema.optional(Schema.Literal("new")),
93 minVersion: TrimmedNonEmptyString,
94});
95export type ServerProviderUpdateRequiredModel = typeof ServerProviderUpdateRequiredModel.Type;
96
97export const ServerProviderSlashCommandInput = Schema.Struct({
98 hint: TrimmedNonEmptyString,
99});
100export type ServerProviderSlashCommandInput = typeof ServerProviderSlashCommandInput.Type;
101
102export const ServerProviderSlashCommand = Schema.Struct({
103 name: TrimmedNonEmptyString,
104 description: Schema.optional(TrimmedNonEmptyString),
105 input: Schema.optional(ServerProviderSlashCommandInput),
106});
107export type ServerProviderSlashCommand = typeof ServerProviderSlashCommand.Type;
108
109export const ServerProviderSkill = Schema.Struct({
110 name: TrimmedNonEmptyString,
111 description: Schema.optional(TrimmedNonEmptyString),
112 path: TrimmedNonEmptyString,
113 scope: Schema.optional(TrimmedNonEmptyString),
114 enabled: Schema.Boolean,
115 displayName: Schema.optional(TrimmedNonEmptyString),
116 shortDescription: Schema.optional(TrimmedNonEmptyString),
117 /**
118 * The skill is hidden from the agent's own skill tool, so only the user can
119 * start it — Claude Code's `disable-model-invocation`. Composers must offer
120 * it as a slash command; naming it in prose does nothing.
121 */
122 userInvocationOnly: Schema.optional(Schema.Boolean),
123 /**
124 * The mirror of {@link ServerProviderSkill.userInvocationOnly}: Claude Code's
125 * `user-invocable: false` keeps the skill out of its own slash commands, so
126 * only the agent can start it. Composers must not offer it under `/`.
127 */
128 userInvocable: Schema.optional(Schema.Boolean),
129});
130export type ServerProviderSkill = typeof ServerProviderSkill.Type;
131
132export const ServerProviderWorkspaceSnapshot = Schema.Struct({
133 cwd: TrimmedNonEmptyString,
134 checkedAt: IsoDateTime,
135 slashCommands: Schema.Array(ServerProviderSlashCommand),
136 slashCommandsPending: Schema.optional(Schema.Boolean),
137 skills: Schema.Array(ServerProviderSkill),
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 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 );
571}
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";
637}
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 configVersion: Schema.optionalKey(TrimmedNonEmptyString),
694});
695export type ServerConfigStreamSnapshotEvent = typeof ServerConfigStreamSnapshotEvent.Type;
696
697export const ServerConfigStreamKeybindingsUpdatedEvent = Schema.Struct({
698 version: Schema.Literal(1),
699 type: Schema.Literal("keybindingsUpdated"),
700 payload: ServerConfigKeybindingsUpdatedPayload,
701});
702export type ServerConfigStreamKeybindingsUpdatedEvent =
703 typeof ServerConfigStreamKeybindingsUpdatedEvent.Type;
704
705export const ServerConfigStreamProviderStatusesEvent = Schema.Struct({
706 version: Schema.Literal(1),
707 type: Schema.Literal("providerStatuses"),
708 payload: ServerConfigProviderStatusesPayload,
709});
710export type ServerConfigStreamProviderStatusesEvent =
711 typeof ServerConfigStreamProviderStatusesEvent.Type;
712
713export const ServerConfigStreamSettingsUpdatedEvent = Schema.Struct({
714 version: Schema.Literal(1),
715 type: Schema.Literal("settingsUpdated"),
716 payload: ServerConfigSettingsUpdatedPayload,
717});
718export type ServerConfigStreamSettingsUpdatedEvent =
719 typeof ServerConfigStreamSettingsUpdatedEvent.Type;
720
721export const ServerConfigEnvironmentThemesUpdatedPayload = Schema.Struct({
722 themes: Schema.Array(EnvironmentTheme),
723});
724export type ServerConfigEnvironmentThemesUpdatedPayload =
725 typeof ServerConfigEnvironmentThemesUpdatedPayload.Type;
726
727export const ServerConfigStreamEnvironmentThemesUpdatedEvent = Schema.Struct({
728 version: Schema.Literal(1),
729 type: Schema.Literal("environmentThemesUpdated"),
730 payload: ServerConfigEnvironmentThemesUpdatedPayload,
731});
732export type ServerConfigStreamEnvironmentThemesUpdatedEvent =
733 typeof ServerConfigStreamEnvironmentThemesUpdatedEvent.Type;
734
735export const ServerConfigUsageLimitSourcesUpdatedPayload = Schema.Struct({
736 sources: UsageLimitSourceSnapshots,
737});
738export type ServerConfigUsageLimitSourcesUpdatedPayload =
739 typeof ServerConfigUsageLimitSourcesUpdatedPayload.Type;
740
741export const ServerConfigStreamUsageLimitSourcesUpdatedEvent = Schema.Struct({
742 version: Schema.Literal(1),
743 type: Schema.Literal("usageLimitSourcesUpdated"),
744 payload: ServerConfigUsageLimitSourcesUpdatedPayload,
745});
746export type ServerConfigStreamUsageLimitSourcesUpdatedEvent =
747 typeof ServerConfigStreamUsageLimitSourcesUpdatedEvent.Type;
748
749export const ServerConfigStreamEvent = Schema.Union([
750 ServerConfigStreamSnapshotEvent,
751 ServerConfigStreamKeybindingsUpdatedEvent,
752 ServerConfigStreamProviderStatusesEvent,
753 ServerConfigStreamSettingsUpdatedEvent,
754 ServerConfigStreamEnvironmentThemesUpdatedEvent,
755 ServerConfigStreamUsageLimitSourcesUpdatedEvent,
756 Schema.Struct({
757 version: Schema.Literal(1),
758 type: Schema.Literal("configUnchanged"),
759 configVersion: TrimmedNonEmptyString,
760 }),
761 Schema.Struct({
762 version: Schema.Literal(1),
763 type: Schema.Literal("configDelta"),
764 configVersion: TrimmedNonEmptyString,
765 changes: ServerConfig.mapFields(Struct.map(Schema.optionalKey)),
766 removed: Schema.Array(Schema.String),
767 providerChanges: Schema.Array(
768 Schema.Struct({
769 instanceId: ProviderInstanceId,
770 // Omitted fields must not clear values. Drop unreadable providers as snapshots do.
771 changes: Schema.UndefinedOr(
772 Schema.Struct({
773 ...ServerProvider.mapFields(Struct.map(Schema.optionalKey)).fields,
774 slashCommands: Schema.optionalKey(Schema.Array(ServerProviderSlashCommand)),
775 skills: Schema.optionalKey(Schema.Array(ServerProviderSkill)),
776 }),
777 ).pipe(Schema.catchDecoding(() => Effect.succeedSome(undefined))),
778 removed: Schema.Array(Schema.String),
779 }),
780 ),
781 providerOrder: Schema.optionalKey(Schema.Array(ProviderInstanceId)),
782 }),
783]);
784export type ServerConfigStreamEvent = typeof ServerConfigStreamEvent.Type;
785
786export const ServerSelfUpdateOutcome = Schema.Struct({
787 id: TrimmedNonEmptyString,
788 fromVersion: TrimmedNonEmptyString,
789 targetVersion: TrimmedNonEmptyString,
790 status: Schema.Literals(["committed", "rolled-back", "failed"]),
791 reason: Schema.optionalKey(TrimmedNonEmptyString),
792});
793export type ServerSelfUpdateOutcome = typeof ServerSelfUpdateOutcome.Type;
794
795export const ServerLifecycleReadyPayload = Schema.Struct({
796 at: IsoDateTime,
797 environment: ExecutionEnvironmentDescriptor,
798 updateOutcome: Schema.optionalKey(ServerSelfUpdateOutcome),
799});
800export type ServerLifecycleReadyPayload = typeof ServerLifecycleReadyPayload.Type;
801
802export const ServerLifecycleWelcomePayload = Schema.Struct({
803 environment: ExecutionEnvironmentDescriptor,
804 cwd: TrimmedNonEmptyString,
805 projectName: TrimmedNonEmptyString,
806 bootstrapStatus: Schema.optional(Schema.Literals(["pending", "complete"])),
807 bootstrapProjectId: Schema.optional(ProjectId),
808 bootstrapThreadId: Schema.optional(ThreadId),
809 bootstrapProjectCreated: Schema.optional(Schema.Boolean),
810 bootstrapThreadCreated: Schema.optional(Schema.Boolean),
811});
812export type ServerLifecycleWelcomePayload = typeof ServerLifecycleWelcomePayload.Type;
813
814export const ServerLifecycleLegacyThreadMigrationPayload = Schema.Struct({
815 status: Schema.Union([Schema.Literal("running"), Schema.Literal("complete")]),
816 totalThreadCount: NonNegativeInt,
817});
818export type ServerLifecycleLegacyThreadMigrationPayload =
819 typeof ServerLifecycleLegacyThreadMigrationPayload.Type;
820
821export const ServerLifecycleStreamWelcomeEvent = Schema.Struct({
822 version: Schema.Literal(1),
823 sequence: NonNegativeInt,
824 type: Schema.Literal("welcome"),
825 payload: ServerLifecycleWelcomePayload,
826});
827export type ServerLifecycleStreamWelcomeEvent = typeof ServerLifecycleStreamWelcomeEvent.Type;
828
829export const ServerLifecycleStreamReadyEvent = Schema.Struct({
830 version: Schema.Literal(1),
831 sequence: NonNegativeInt,
832 type: Schema.Literal("ready"),
833 payload: ServerLifecycleReadyPayload,
834});
835export type ServerLifecycleStreamReadyEvent = typeof ServerLifecycleStreamReadyEvent.Type;
836
837export const ServerLifecycleStreamLegacyThreadMigrationEvent = Schema.Struct({
838 version: Schema.Literal(1),
839 sequence: NonNegativeInt,
840 type: Schema.Literal("legacyThreadMigration"),
841 payload: ServerLifecycleLegacyThreadMigrationPayload,
842});
843export type ServerLifecycleStreamLegacyThreadMigrationEvent =
844 typeof ServerLifecycleStreamLegacyThreadMigrationEvent.Type;
845
846export const ServerLifecycleStreamEvent = Schema.Union([
847 ServerLifecycleStreamWelcomeEvent,
848 ServerLifecycleStreamReadyEvent,
849 ServerLifecycleStreamLegacyThreadMigrationEvent,
850]);
851export type ServerLifecycleStreamEvent = typeof ServerLifecycleStreamEvent.Type;
852
853export const ServerProviderUpdatedPayload = Schema.Struct({
854 providers: ServerProviders,
855});
856export type ServerProviderUpdatedPayload = typeof ServerProviderUpdatedPayload.Type;
857
858export const ServerProviderUpdateInput = Schema.Struct({
859 provider: ProviderDriverKind,
860 targetVersion: Schema.optionalKey(TrimmedNonEmptyString),
861 instanceId: Schema.optionalKey(ProviderInstanceId),
862});
863export type ServerProviderUpdateInput = typeof ServerProviderUpdateInput.Type;
864
865export class ServerProviderUpdateError extends Schema.TaggedError<ServerProviderUpdateError>()(
866 "ServerProviderUpdateError",
867 {
868 provider: ProviderDriverKind,
869 reason: TrimmedNonEmptyString,
870 cause: Schema.optional(Schema.Defect()),
871 },
872) {
873 override get message(): string {
874 return `Provider update failed for ${this.provider}: ${this.reason}`;
875 }
876}
877
878export const ServerSelfUpdateInput = Schema.Struct({
879 /** Exact npm version of the `t3` package to install (never a dist-tag, so
880 the server and the acknowledging client agree on what was requested). */
881 targetVersion: TrimmedNonEmptyString,
882 continueRunningThreads: Schema.optionalKey(Schema.Boolean),
883});
884export type ServerSelfUpdateInput = typeof ServerSelfUpdateInput.Type;
885
886export const ServerSelfUpdateResult = Schema.Struct({
887 targetVersion: TrimmedNonEmptyString,
888 method: ServerSelfUpdateMethod,
889 updateId: Schema.optionalKey(TrimmedNonEmptyString),
890 desktopUpdateToken: Schema.optionalKey(TrimmedNonEmptyString),
891});
892export type ServerSelfUpdateResult = typeof ServerSelfUpdateResult.Type;
893
894export const DesktopUpdateCommitInput = Schema.Struct({
895 requestId: TrimmedNonEmptyString,
896});
897export type DesktopUpdateCommitInput = typeof DesktopUpdateCommitInput.Type;
898
899export const ServerSelfUpdateProgressStage = Schema.Literals(["downloading", "installing"]);
900export type ServerSelfUpdateProgressStage = typeof ServerSelfUpdateProgressStage.Type;
901
902export const ServerSelfUpdateProgressEvent = Schema.Union([
903 Schema.Struct({
904 type: Schema.Literal("progress"),
905 stage: ServerSelfUpdateProgressStage,
906 }),
907 Schema.Struct({
908 type: Schema.Literal("complete"),
909 result: ServerSelfUpdateResult,
910 }),
911]);
912export type ServerSelfUpdateProgressEvent = typeof ServerSelfUpdateProgressEvent.Type;
913
914export class ServerSelfUpdateError extends Schema.TaggedError<ServerSelfUpdateError>()(
915 "ServerSelfUpdateError",
916 {
917 reason: TrimmedNonEmptyString,
918 cause: Schema.optional(Schema.Defect()),
919 },
920) {
921 override get message(): string {
922 return `Server update failed: ${this.reason}`;
923 }
924}