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 { AuthClientPresentationMetadata, 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 { ManagedPolicySummary } from "./managedPolicy.ts";
27import { ModelCapabilities, ProviderOptionDescriptor } 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";
32import { DesktopUpdateChannelSchema } from "./ipc.ts";
33
34const KeybindingsMalformedConfigIssue = Schema.Struct({
35 kind: Schema.Literal("keybindings.malformed-config"),
36 message: TrimmedNonEmptyString,
37});
38
39const KeybindingsInvalidEntryIssue = Schema.Struct({
40 kind: Schema.Literal("keybindings.invalid-entry"),
41 message: TrimmedNonEmptyString,
42 index: Schema.Number,
43});
44
45export const ServerConfigIssue = Schema.Union([
46 KeybindingsMalformedConfigIssue,
47 KeybindingsInvalidEntryIssue,
48]);
49export type ServerConfigIssue = typeof ServerConfigIssue.Type;
50
51const ServerConfigIssues = ForwardCompatibleArray(ServerConfigIssue);
52
53export const ServerProviderState = Schema.Literals(["ready", "warning", "error", "disabled"]);
54export type ServerProviderState = typeof ServerProviderState.Type;
55
56export const ServerProviderAuthStatus = Schema.Literals([
57 "authenticated",
58 "unauthenticated",
59 "unknown",
60]);
61export type ServerProviderAuthStatus = typeof ServerProviderAuthStatus.Type;
62
63export const ServerProviderAuth = Schema.Struct({
64 status: ServerProviderAuthStatus,
65 type: Schema.optional(TrimmedNonEmptyString),
66 label: Schema.optional(TrimmedNonEmptyString),
67 email: Schema.optional(TrimmedNonEmptyString),
68 action: Schema.optional(AcpRegistryUrlAuthAction),
69 canLogout: Schema.optional(Schema.Boolean),
70 subscriptionSharing: Schema.optional(Schema.Boolean),
71 profileId: Schema.optional(TrimmedNonEmptyString),
72 workspaceId: Schema.optional(TrimmedNonEmptyString),
73 /** Origin of the custom endpoint the instance sends its requests to. */
74 endpoint: Schema.optional(TrimmedNonEmptyString),
75});
76export type ServerProviderAuth = typeof ServerProviderAuth.Type;
77
78export const ServerProviderModel = Schema.Struct({
79 slug: TrimmedNonEmptyString,
80 name: TrimmedNonEmptyString,
81 shortName: Schema.optional(TrimmedNonEmptyString),
82 subProvider: Schema.optional(TrimmedNonEmptyString),
83 aliases: Schema.optional(Schema.Array(TrimmedNonEmptyString)),
84 badge: Schema.optional(Schema.Literal("new")),
85 isCustom: Schema.Boolean,
86 isDefault: Schema.optional(Schema.Boolean),
87 isLegacy: Schema.optional(Schema.Boolean),
88 // False when the provider can run this model in sessions but not for
89 // application text generation. Absent means supported.
90 supportsTextGeneration: Schema.optional(Schema.Boolean),
91 capabilities: Schema.NullOr(ModelCapabilities),
92});
93export type ServerProviderModel = typeof ServerProviderModel.Type;
94
95export const ServerProviderUpdateRequiredModel = Schema.Struct({
96 slug: TrimmedNonEmptyString,
97 name: TrimmedNonEmptyString,
98 badge: Schema.optional(Schema.Literal("new")),
99 minVersion: TrimmedNonEmptyString,
100});
101export type ServerProviderUpdateRequiredModel = typeof ServerProviderUpdateRequiredModel.Type;
102
103export const ServerProviderSlashCommandInput = Schema.Struct({
104 hint: TrimmedNonEmptyString,
105});
106export type ServerProviderSlashCommandInput = typeof ServerProviderSlashCommandInput.Type;
107
108export const ServerProviderSlashCommand = Schema.Struct({
109 name: TrimmedNonEmptyString,
110 description: Schema.optional(TrimmedNonEmptyString),
111 input: Schema.optional(ServerProviderSlashCommandInput),
112});
113export type ServerProviderSlashCommand = typeof ServerProviderSlashCommand.Type;
114
115export const ServerProviderSkill = Schema.Struct({
116 name: TrimmedNonEmptyString,
117 description: Schema.optional(TrimmedNonEmptyString),
118 path: TrimmedNonEmptyString,
119 scope: Schema.optional(TrimmedNonEmptyString),
120 enabled: Schema.Boolean,
121 displayName: Schema.optional(TrimmedNonEmptyString),
122 shortDescription: Schema.optional(TrimmedNonEmptyString),
123 /** Claude disable-model-invocation: only users can invoke; composers must offer a slash command. */
124 userInvocationOnly: Schema.optional(Schema.Boolean),
125 /** Claude user-invocable:false: only agents can invoke; composers must hide the slash command. */
126 userInvocable: Schema.optional(Schema.Boolean),
127});
128export type ServerProviderSkill = typeof ServerProviderSkill.Type;
129
130export const ServerProviderWorkspaceSnapshot = Schema.Struct({
131 cwd: TrimmedNonEmptyString,
132 checkedAt: IsoDateTime,
133 slashCommands: Schema.Array(ServerProviderSlashCommand),
134 slashCommandsPending: Schema.optional(Schema.Boolean),
135 skills: Schema.Array(ServerProviderSkill),
136 optionDescriptors: Schema.optional(Schema.Array(ProviderOptionDescriptor)),
137 // Absent means the provider's machine `models`, which keeps most snapshots small.
138 models: Schema.optional(Schema.Array(ServerProviderModel)),
139 modelsPending: Schema.optional(Schema.Boolean),
140});
141export type ServerProviderWorkspaceSnapshot = typeof ServerProviderWorkspaceSnapshot.Type;
142
143export const PROVIDER_WORKSPACE_SNAPSHOT_TTL_MS = 5 * 60_000;
144
145export function isProviderWorkspaceSnapshotCurrent(
146 snapshot: Pick<ServerProviderWorkspaceSnapshot, "checkedAt">,
147 nowMs: number,
148): boolean {
149 return nowMs - Date.parse(snapshot.checkedAt) < PROVIDER_WORKSPACE_SNAPSHOT_TTL_MS;
150}
151
152/** A pending snapshot keeps what it found before and is rescanned before its TTL. */
153export function isProviderWorkspaceSnapshotPending(
154 snapshot: Pick<ServerProviderWorkspaceSnapshot, "slashCommandsPending" | "modelsPending">,
155): boolean {
156 return snapshot.slashCommandsPending === true || snapshot.modelsPending === true;
157}
158
159/** Unavailable snapshots must set installed and enabled false. */
160export const ServerProviderAvailability = Schema.Literals(["available", "unavailable"]);
161export type ServerProviderAvailability = typeof ServerProviderAvailability.Type;
162
163export const ServerProviderContinuation = Schema.Struct({
164 groupKey: TrimmedNonEmptyString,
165});
166export type ServerProviderContinuation = typeof ServerProviderContinuation.Type;
167
168export const ServerProviderCompatibilityStatus = Schema.Literals([
169 "unknown",
170 "supported",
171 "graceful",
172 "unsupported",
173 "broken",
174]);
175export const ServerProviderCompatibilityAdvisory = Schema.Struct({
176 status: ServerProviderCompatibilityStatus,
177 latestVersionStatus: Schema.optionalKey(ServerProviderCompatibilityStatus),
178 message: Schema.NullOr(TrimmedNonEmptyString),
179 recommendedVersion: Schema.NullOr(TrimmedNonEmptyString),
180 recommendedRange: Schema.NullOr(TrimmedNonEmptyString),
181});
182export type ServerProviderCompatibilityAdvisory = typeof ServerProviderCompatibilityAdvisory.Type;
183
184export const ServerProviderVersionAdvisoryStatus = Schema.Literals([
185 "unknown",
186 "current",
187 "behind_latest",
188]);
189export type ServerProviderVersionAdvisoryStatus = typeof ServerProviderVersionAdvisoryStatus.Type;
190
191export const ServerProviderVersionAdvisory = Schema.Struct({
192 status: ServerProviderVersionAdvisoryStatus,
193 currentVersion: Schema.NullOr(TrimmedNonEmptyString),
194 latestVersion: Schema.NullOr(TrimmedNonEmptyString),
195 updateCommand: Schema.NullOr(TrimmedNonEmptyString),
196 canUpdate: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(false))),
197 canInstallVersion: Schema.optionalKey(Schema.Boolean),
198 checkedAt: Schema.NullOr(IsoDateTime),
199 message: Schema.NullOr(TrimmedNonEmptyString),
200});
201export type ServerProviderVersionAdvisory = typeof ServerProviderVersionAdvisory.Type;
202
203export const ServerProviderUpdateStatus = Schema.Literals([
204 "idle",
205 "queued",
206 "running",
207 "succeeded",
208 "failed",
209 "unchanged",
210]);
211export type ServerProviderUpdateStatus = typeof ServerProviderUpdateStatus.Type;
212
213export const ServerProviderUpdateState = Schema.Struct({
214 status: ServerProviderUpdateStatus,
215 startedAt: Schema.NullOr(IsoDateTime),
216 finishedAt: Schema.NullOr(IsoDateTime),
217 message: Schema.NullOr(TrimmedNonEmptyString),
218 output: Schema.NullOr(Schema.String.check(Schema.isMaxLength(10_000))),
219});
220export type ServerProviderUpdateState = typeof ServerProviderUpdateState.Type;
221
222export const ServerProvider = Schema.Struct({
223 // Only instanceId is stable enough for provider routing.
224 instanceId: ProviderInstanceId,
225 driver: ProviderDriverKind,
226 displayName: Schema.optional(TrimmedNonEmptyString),
227 accentColor: Schema.optional(TrimmedNonEmptyString),
228 // Validate driver-supplied remote icons against the driver's trusted origin.
229 iconUrl: Schema.optional(TrimmedNonEmptyString.check(Schema.isMaxLength(2_048))),
230 badgeLabel: Schema.optional(TrimmedNonEmptyString),
231 continuation: Schema.optional(ServerProviderContinuation),
232 showInteractionModeToggle: Schema.optional(Schema.Boolean),
233 reportsContextWindow: Schema.optional(Schema.Boolean),
234 supportedRuntimeModes: Schema.optional(ForwardCompatibleArray(RuntimeMode)),
235 supportsConversationRollback: Schema.optional(Schema.Boolean),
236 supportsTextGeneration: Schema.optional(Schema.Boolean),
237 setup: Schema.optional(
238 Schema.Struct({
239 canAuthenticate: Schema.Boolean,
240 canInstall: Schema.Boolean,
241 documentationUrl: Schema.optionalKey(TrimmedNonEmptyString.check(Schema.isMaxLength(2_048))),
242 }),
243 ),
244 nativeSessions: Schema.optional(
245 Schema.Struct({
246 canList: Schema.Boolean,
247 canLoad: Schema.Boolean,
248 canResume: Schema.Boolean,
249 canDelete: Schema.optional(Schema.Boolean),
250 }),
251 ),
252 configurableProviders: Schema.optional(Schema.Boolean),
253 runtimePaths: Schema.optionalKey(
254 Schema.Struct({
255 homePath: TrimmedNonEmptyString,
256 shadowHomePath: Schema.NullOr(TrimmedNonEmptyString),
257 }),
258 ),
259 enabled: Schema.Boolean,
260 installed: Schema.Boolean,
261 version: Schema.NullOr(TrimmedNonEmptyString),
262 // Version reported by the installed CLI for a local provider with a separate
263 // server. Null means unknown; absence keeps legacy snapshots on `version`.
264 installedVersion: Schema.optionalKey(Schema.NullOr(TrimmedNonEmptyString)),
265 status: ServerProviderState,
266 auth: ServerProviderAuth,
267 checkedAt: IsoDateTime,
268 message: Schema.optional(TrimmedNonEmptyString),
269 availability: Schema.optional(ServerProviderAvailability),
270 unavailableReason: Schema.optional(TrimmedNonEmptyString),
271 models: Schema.Array(ServerProviderModel),
272 // Kept apart from `models` so clients that predate it never offer them.
273 updateRequiredModels: Schema.optionalKey(Schema.Array(ServerProviderUpdateRequiredModel)),
274 slashCommands: Schema.Array(ServerProviderSlashCommand).pipe(
275 Schema.withDecodingDefault(Effect.succeed([])),
276 ),
277 skills: Schema.Array(ServerProviderSkill).pipe(Schema.withDecodingDefault(Effect.succeed([]))),
278 workspaceSnapshots: Schema.optionalKey(Schema.Array(ServerProviderWorkspaceSnapshot)),
279 usageLimits: Schema.optional(ServerProviderUsageLimits),
280 versionAdvisory: Schema.optionalKey(ServerProviderVersionAdvisory),
281 compatibilityAdvisory: Schema.optionalKey(ServerProviderCompatibilityAdvisory),
282 updateState: Schema.optionalKey(ServerProviderUpdateState),
283 /**
284 * Stands for the machine slash commands and skills, which are then left out. Sent to clients
285 * that ask for catalog digests; they load both lists with their next cwd snapshot.
286 */
287 catalogDigest: Schema.optionalKey(TrimmedNonEmptyString),
288 /** Set by the client, never sent: the `catalogDigest` its slash commands and skills belong to. */
289 loadedCatalogDigest: Schema.optionalKey(TrimmedNonEmptyString),
290});
291export type ServerProvider = typeof ServerProvider.Type;
292
293/** A provider without the lists that equal the ones its reader already holds. */
294export const ServerProviderDelta = ServerProvider.mapFields((fields) => ({
295 ...fields,
296 models: Schema.optionalKey(fields.models),
297 // Declared again without the decoding default, which would read as a change to an empty list.
298 slashCommands: Schema.optionalKey(Schema.Array(ServerProviderSlashCommand)),
299 skills: Schema.optionalKey(Schema.Array(ServerProviderSkill)),
300}));
301export type ServerProviderDelta = typeof ServerProviderDelta.Type;
302
303const sameJson = (left: unknown, right: unknown) =>
304 left === right || JSON.stringify(left) === JSON.stringify(right);
305
306/** Leaves each provider's models, slash commands, and skills out when `previous` has the same. */
307export function serverProviderDeltas(
308 previous: ReadonlyArray<ServerProvider>,
309 next: ReadonlyArray<ServerProvider>,
310): ServerProviderDelta[] {
311 const held = new Map(previous.map((provider) => [provider.instanceId, provider]));
312 return next.map((provider) => {
313 const base = held.get(provider.instanceId);
314 if (base === undefined) return provider;
315 const { models, slashCommands, skills, ...rest } = provider;
316 return {
317 ...rest,
318 ...(sameJson(base.models, models) ? {} : { models }),
319 ...(sameJson(base.slashCommands, slashCommands) ? {} : { slashCommands }),
320 ...(sameJson(base.skills, skills) ? {} : { skills }),
321 };
322 });
323}
324
325/** Rebuilds the provider list `serverProviderDeltas` was made from. */
326export function applyServerProviderDeltas(
327 previous: ReadonlyArray<ServerProvider>,
328 deltas: ReadonlyArray<ServerProviderDelta>,
329): ServerProvider[] {
330 const held = new Map(previous.map((provider) => [provider.instanceId, provider]));
331 return deltas.flatMap((delta) => {
332 const base = held.get(delta.instanceId);
333 const models = delta.models ?? base?.models;
334 const slashCommands = delta.slashCommands ?? base?.slashCommands;
335 const skills = delta.skills ?? base?.skills;
336 // A list this reader never held cannot be rebuilt; drop the provider like an unreadable one.
337 return models && slashCommands && skills ? [{ ...delta, models, slashCommands, skills }] : [];
338 });
339}
340
341export const ServerProviders = ForwardCompatibleArray(ServerProvider);
342export type ServerProviders = typeof ServerProviders.Type;
343
344export const isProviderAvailable = (snapshot: ServerProvider): boolean =>
345 snapshot.availability !== "unavailable";
346
347/** Legacy producers omit this field and support text generation. */
348export const isProviderTextGenerationCapable = (snapshot: ServerProvider): boolean =>
349 snapshot.supportsTextGeneration !== false;
350
351export const OtlpEndpointSource = Schema.Literals(["environment", "bootstrap", "settings"]);
352export type OtlpEndpointSource = typeof OtlpEndpointSource.Type;
353
354export const ServerObservability = Schema.Struct({
355 logsDirectoryPath: TrimmedNonEmptyString,
356 localTracingEnabled: Schema.Boolean,
357 otlpTracesUrl: Schema.optional(TrimmedNonEmptyString),
358 otlpTracesSource: Schema.optional(OtlpEndpointSource),
359 otlpTracesVariable: Schema.optional(TrimmedNonEmptyString),
360 otlpTracesEnabled: Schema.Boolean,
361 otlpMetricsUrl: Schema.optional(TrimmedNonEmptyString),
362 otlpMetricsSource: Schema.optional(OtlpEndpointSource),
363 otlpMetricsVariable: Schema.optional(TrimmedNonEmptyString),
364 otlpMetricsEnabled: Schema.Boolean,
365 otlpLogsUrl: Schema.optional(TrimmedNonEmptyString),
366 otlpLogsSource: Schema.optional(OtlpEndpointSource),
367 otlpLogsVariable: Schema.optional(TrimmedNonEmptyString),
368 otlpLogsEnabled: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(false))),
369});
370export type ServerObservability = typeof ServerObservability.Type;
371
372export const OtlpSignal = Schema.Literals(["traces", "metrics", "logs"]);
373export type OtlpSignal = typeof OtlpSignal.Type;
374
375export const OtlpEndpointCheckInput = Schema.Struct({
376 signal: OtlpSignal,
377 url: TrimmedNonEmptyString.check(Schema.isPattern(/^https?:\/\/./i)),
378});
379export type OtlpEndpointCheckInput = typeof OtlpEndpointCheckInput.Type;
380
381export const OtlpEndpointCheckResult = Schema.Union([
382 Schema.TaggedStruct("Accepted", { latencyMs: Schema.Number }),
383 Schema.TaggedStruct("Rejected", { status: Schema.Number }),
384 Schema.TaggedStruct("Unreachable", { timedOut: Schema.Boolean }),
385]);
386export type OtlpEndpointCheckResult = typeof OtlpEndpointCheckResult.Type;
387
388/** The client tells the server what it is, so the triage context can name it. */
389export const ServerPrepareTriageInput = Schema.Struct({
390 client: AuthClientPresentationMetadata,
391});
392export type ServerPrepareTriageInput = typeof ServerPrepareTriageInput.Type;
393
394export const ServerPrepareTriageResult = Schema.Struct({
395 /** Composer text that links the session's prompt file. */
396 prompt: Schema.String,
397});
398export type ServerPrepareTriageResult = typeof ServerPrepareTriageResult.Type;
399
400/**
401 * The prompt file links as a chip in the user's message; clients spot a triage
402 * draft by it.
403 */
404export const TRIAGE_PROMPT_FILE_NAME = "triage-playbook.md";
405
406export class ServerPrepareTriageError extends Schema.TaggedError<ServerPrepareTriageError>()(
407 "ServerPrepareTriageError",
408 { cause: Schema.optional(Schema.Defect()) },
409) {
410 override get message(): string {
411 return "Could not write the triage session files.";
412 }
413}
414
415export const ServerTraceDiagnosticsErrorKind = Schema.Literals([
416 "trace-file-not-found",
417 "trace-file-read-failed",
418]);
419export type ServerTraceDiagnosticsErrorKind = typeof ServerTraceDiagnosticsErrorKind.Type;
420
421export const ServerTraceDiagnosticsSpanSummary = Schema.Struct({
422 name: TrimmedNonEmptyString,
423 count: NonNegativeInt,
424 failureCount: NonNegativeInt,
425 totalDurationMs: Schema.Number,
426 averageDurationMs: Schema.Number,
427 maxDurationMs: Schema.Number,
428});
429export type ServerTraceDiagnosticsSpanSummary = typeof ServerTraceDiagnosticsSpanSummary.Type;
430
431export const ServerTraceDiagnosticsFailureSummary = Schema.Struct({
432 name: TrimmedNonEmptyString,
433 cause: TrimmedNonEmptyString,
434 count: NonNegativeInt,
435 lastSeenAt: Schema.DateTimeUtc,
436 traceId: TrimmedNonEmptyString,
437 spanId: TrimmedNonEmptyString,
438});
439export type ServerTraceDiagnosticsFailureSummary = typeof ServerTraceDiagnosticsFailureSummary.Type;
440
441export const ServerTraceDiagnosticsRecentFailure = Schema.Struct({
442 name: TrimmedNonEmptyString,
443 cause: TrimmedNonEmptyString,
444 durationMs: Schema.Number,
445 endedAt: Schema.DateTimeUtc,
446 traceId: TrimmedNonEmptyString,
447 spanId: TrimmedNonEmptyString,
448});
449export type ServerTraceDiagnosticsRecentFailure = typeof ServerTraceDiagnosticsRecentFailure.Type;
450
451export const ServerTraceDiagnosticsSpanOccurrence = Schema.Struct({
452 name: TrimmedNonEmptyString,
453 durationMs: Schema.Number,
454 endedAt: Schema.DateTimeUtc,
455 traceId: TrimmedNonEmptyString,
456 spanId: TrimmedNonEmptyString,
457});
458export type ServerTraceDiagnosticsSpanOccurrence = typeof ServerTraceDiagnosticsSpanOccurrence.Type;
459
460export const ServerTraceDiagnosticsLogEvent = Schema.Struct({
461 spanName: TrimmedNonEmptyString,
462 level: TrimmedNonEmptyString,
463 message: TrimmedNonEmptyString,
464 seenAt: Schema.DateTimeUtc,
465 traceId: TrimmedNonEmptyString,
466 spanId: TrimmedNonEmptyString,
467});
468export type ServerTraceDiagnosticsLogEvent = typeof ServerTraceDiagnosticsLogEvent.Type;
469
470export const ServerTraceDiagnosticsResult = Schema.Struct({
471 traceFilePath: TrimmedNonEmptyString,
472 scannedFilePaths: Schema.Array(TrimmedNonEmptyString),
473 readAt: Schema.DateTimeUtc,
474 recordCount: NonNegativeInt,
475 parseErrorCount: NonNegativeInt,
476 firstSpanAt: Schema.Option(Schema.DateTimeUtc),
477 lastSpanAt: Schema.Option(Schema.DateTimeUtc),
478 failureCount: NonNegativeInt,
479 interruptionCount: NonNegativeInt,
480 slowSpanThresholdMs: NonNegativeInt,
481 slowSpanCount: NonNegativeInt,
482 logLevelCounts: Schema.Record(TrimmedNonEmptyString, NonNegativeInt),
483 topSpansByCount: Schema.Array(ServerTraceDiagnosticsSpanSummary),
484 slowestSpans: Schema.Array(ServerTraceDiagnosticsSpanOccurrence),
485 commonFailures: Schema.Array(ServerTraceDiagnosticsFailureSummary),
486 latestFailures: Schema.Array(ServerTraceDiagnosticsRecentFailure),
487 latestWarningAndErrorLogs: Schema.Array(ServerTraceDiagnosticsLogEvent),
488 partialFailure: Schema.Option(Schema.Boolean),
489 error: Schema.Option(
490 Schema.Struct({
491 kind: ServerTraceDiagnosticsErrorKind,
492 message: TrimmedNonEmptyString,
493 }),
494 ),
495});
496export type ServerTraceDiagnosticsResult = typeof ServerTraceDiagnosticsResult.Type;
497
498export const ServerProcessSignal = Schema.Literals(["SIGINT", "SIGKILL"]);
499export type ServerProcessSignal = typeof ServerProcessSignal.Type;
500
501export const ServerProcessDiagnosticsEntry = Schema.Struct({
502 pid: PositiveInt,
503 startTimeMs: NonNegativeInt,
504 ppid: NonNegativeInt,
505 pgid: Schema.Option(Schema.Int),
506 status: TrimmedNonEmptyString,
507 cpuPercent: Schema.Number,
508 rssBytes: NonNegativeInt,
509 elapsed: TrimmedNonEmptyString,
510 command: TrimmedNonEmptyString,
511 depth: NonNegativeInt,
512 childPids: Schema.Array(PositiveInt),
513});
514export type ServerProcessDiagnosticsEntry = typeof ServerProcessDiagnosticsEntry.Type;
515
516export const ServerProcessDiagnosticsResult = Schema.Struct({
517 serverPid: PositiveInt,
518 readAt: Schema.DateTimeUtc,
519 processCount: NonNegativeInt,
520 totalRssBytes: NonNegativeInt,
521 totalCpuPercent: Schema.Number,
522 processes: Schema.Array(ServerProcessDiagnosticsEntry),
523 error: Schema.Option(
524 Schema.Struct({
525 message: TrimmedNonEmptyString,
526 }),
527 ),
528});
529export type ServerProcessDiagnosticsResult = typeof ServerProcessDiagnosticsResult.Type;
530
531export const ServerProcessResourceHistoryInput = Schema.Struct({
532 windowMs: NonNegativeInt,
533 bucketMs: NonNegativeInt,
534});
535export type ServerProcessResourceHistoryInput = typeof ServerProcessResourceHistoryInput.Type;
536
537export const ServerProcessResourceHistoryBucket = Schema.Struct({
538 startedAt: Schema.DateTimeUtc,
539 endedAt: Schema.DateTimeUtc,
540 avgCpuPercent: Schema.Number,
541 maxCpuPercent: Schema.Number,
542 maxRssBytes: NonNegativeInt,
543 maxProcessCount: NonNegativeInt,
544});
545export type ServerProcessResourceHistoryBucket = typeof ServerProcessResourceHistoryBucket.Type;
546
547export const ServerProcessResourceHistorySummary = Schema.Struct({
548 processKey: TrimmedNonEmptyString,
549 pid: PositiveInt,
550 ppid: NonNegativeInt,
551 command: TrimmedNonEmptyString,
552 depth: NonNegativeInt,
553 isServerRoot: Schema.Boolean,
554 firstSeenAt: Schema.DateTimeUtc,
555 lastSeenAt: Schema.DateTimeUtc,
556 currentCpuPercent: Schema.Number,
557 avgCpuPercent: Schema.Number,
558 maxCpuPercent: Schema.Number,
559 cpuSecondsApprox: Schema.Number,
560 currentRssBytes: NonNegativeInt,
561 maxRssBytes: NonNegativeInt,
562 sampleCount: NonNegativeInt,
563});
564export type ServerProcessResourceHistorySummary = typeof ServerProcessResourceHistorySummary.Type;
565
566export const ServerProcessResourceHistoryFailureTag = Schema.Literals([
567 "ProcessDiagnosticsQueryTimeoutError",
568 "ProcessDiagnosticsQueryFailedError",
569 "ProcessDiagnosticsServerProcessSignalError",
570 "ProcessDiagnosticsNotDescendantError",
571 "ProcessDiagnosticsSignalFailedError",
572]);
573export type ServerProcessResourceHistoryFailureTag =
574 typeof ServerProcessResourceHistoryFailureTag.Type;
575
576export const ServerProcessResourceHistoryResult = Schema.Struct({
577 readAt: Schema.DateTimeUtc,
578 windowMs: NonNegativeInt,
579 bucketMs: NonNegativeInt,
580 sampleIntervalMs: NonNegativeInt,
581 retainedSampleCount: NonNegativeInt,
582 totalCpuSecondsApprox: Schema.Number,
583 buckets: Schema.Array(ServerProcessResourceHistoryBucket),
584 topProcesses: Schema.Array(ServerProcessResourceHistorySummary),
585 error: Schema.Option(
586 Schema.Struct({
587 failureTag: ServerProcessResourceHistoryFailureTag,
588 message: TrimmedNonEmptyString,
589 }),
590 ),
591});
592export type ServerProcessResourceHistoryResult = typeof ServerProcessResourceHistoryResult.Type;
593
594export const ServerSignalProcessInput = Schema.Struct({
595 pid: PositiveInt,
596 startTimeMs: NonNegativeInt,
597 signal: ServerProcessSignal,
598});
599export type ServerSignalProcessInput = typeof ServerSignalProcessInput.Type;
600
601export const ServerSignalProcessResult = Schema.Struct({
602 pid: PositiveInt,
603 signal: ServerProcessSignal,
604 signaled: Schema.Boolean,
605 message: Schema.Option(TrimmedNonEmptyString),
606});
607export type ServerSignalProcessResult = typeof ServerSignalProcessResult.Type;
608
609export const EnvironmentThemeColor = Schema.String.check(
610 Schema.isPattern(/^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/),
611);
612export type EnvironmentThemeColor = typeof EnvironmentThemeColor.Type;
613
614/** Reserve appearance keywords so published themes cannot replace stock preferences. */
615export const EnvironmentThemeId = Schema.String.check(
616 Schema.isPattern(/^(?!(?:system|light|dark)$)[a-z0-9](?:[a-z0-9-]{0,47})$/),
617);
618export type EnvironmentThemeId = typeof EnvironmentThemeId.Type;
619
620const EnvironmentThemeColors = Schema.Record(
621 Schema.String.check(Schema.isPattern(/^[a-zA-Z][a-zA-Z0-9]{0,63}$/)),
622 TrimmedNonEmptyString.check(Schema.isMaxLength(64)),
623);
624
625export const THEME_CSS_MAX_LENGTH = 20_000;
626
627const environmentThemeFields = {
628 version: Schema.optional(Schema.Literal(1)),
629 name: TrimmedNonEmptyString.check(Schema.isMaxLength(48)),
630 appearance: Schema.Literals(["light", "dark"]),
631 /** Derive the palette from canvas/accent, then overlay colors; without them, colors is the palette. */
632 canvas: Schema.optional(EnvironmentThemeColor),
633 accent: Schema.optional(EnvironmentThemeColor),
634 colors: Schema.optional(EnvironmentThemeColors),
635 variants: Schema.optional(
636 Schema.Struct({
637 light: Schema.optional(EnvironmentThemeColors),
638 dark: Schema.optional(EnvironmentThemeColors),
639 }),
640 ),
641 /** Custom styles for web and desktop clients. */
642 css: Schema.optional(Schema.String.check(Schema.isMaxLength(THEME_CSS_MAX_LENGTH))),
643};
644
645export const EnvironmentThemeFile = Schema.Struct(environmentThemeFields);
646export type EnvironmentThemeFile = typeof EnvironmentThemeFile.Type;
647
648export const EnvironmentTheme = Schema.Struct({
649 id: EnvironmentThemeId,
650 ...environmentThemeFields,
651});
652export type EnvironmentTheme = typeof EnvironmentTheme.Type;
653
654export function environmentThemeFileHasColors(file: EnvironmentThemeFile): boolean {
655 return (
656 (file.canvas !== undefined && file.accent !== undefined) ||
657 (file.colors !== undefined && Object.keys(file.colors).length > 0)
658 );
659}
660
661/** tailnet means this machine's Tailscale interface; other private addresses are lan. */
662export const ServerDirectEndpointKind = Schema.Literals(["lan", "tailnet"]);
663export type ServerDirectEndpointKind = typeof ServerDirectEndpointKind.Type;
664
665export const ServerDirectEndpoint = Schema.Struct({
666 kind: ServerDirectEndpointKind,
667 httpBaseUrl: TrimmedNonEmptyString,
668});
669export type ServerDirectEndpoint = typeof ServerDirectEndpoint.Type;
670
671/**
672 * A stretch where the server's event loop could not run, so it answered
673 * nothing and clients may have dropped the connection.
674 */
675export const ServerEventLoopStall = Schema.Struct({
676 detectedAt: IsoDateTime,
677 durationMs: NonNegativeInt,
678 /** One-minute load average when the stall was seen. Absent on Windows, which has none. */
679 loadAverage: Schema.optionalKey(Schema.Number),
680 cpuCount: PositiveInt,
681});
682export type ServerEventLoopStall = typeof ServerEventLoopStall.Type;
683
684export const ServerConfig = Schema.Struct({
685 environment: ExecutionEnvironmentDescriptor,
686 auth: ServerAuthDescriptor,
687 cwd: TrimmedNonEmptyString,
688 keybindingsConfigPath: TrimmedNonEmptyString,
689 keybindings: ResolvedKeybindingsConfig,
690 issues: ServerConfigIssues,
691 providers: ServerProviders,
692 availableEditors: ForwardCompatibleArray(EditorId),
693 remoteOpenTargets: Schema.optionalKey(ForwardCompatibleArray(RemoteOpenTarget)),
694 /** Hints only; verify each address answers as this environment. */
695 directEndpoints: Schema.optionalKey(ForwardCompatibleArray(ServerDirectEndpoint)),
696 observability: ServerObservability,
697 settings: ServerSettings,
698 /** Present when an administrator's policy file manages this environment. */
699 managedPolicy: Schema.optionalKey(ManagedPolicySummary),
700 shellResumeCompletionMarker: Schema.optionalKey(Schema.Boolean),
701 /**
702 * The shell can leave idle subagent children out of snapshots (`omitIdleSubagents`), and
703 * `getThreadFamily` and `getWorktreeThreadIds` serve the rows it leaves out.
704 */
705 shellThreadFamilies: Schema.optionalKey(Schema.Boolean),
706 threadLinkMetadata: Schema.optionalKey(Schema.Boolean),
707 /**
708 * The shell can leave older settled threads out of snapshots (`omitOlderSettled`), and
709 * `getOlderSettledThreads` serves them. Only servers that also advertise `shellThreadFamilies`.
710 */
711 shellOlderSettled: Schema.optionalKey(Schema.Boolean),
712 shellRevealInFileManager: Schema.optionalKey(Schema.Boolean),
713 shellRevealInFileManagerKind: Schema.optionalKey(FileManagerRevealKind),
714 threadResumeCompletionMarker: Schema.optionalKey(Schema.Boolean),
715 /** Send window fields only when advertised. */
716 threadSnapshotPagination: Schema.optionalKey(Schema.Boolean),
717 threadFind: Schema.optionalKey(Schema.Boolean),
718 threadFindProgressive: Schema.optionalKey(Schema.Boolean),
719 /** Settings patches may carry `secretProviders`; older servers drop the key without an error. */
720 secretProviderSettings: Schema.optionalKey(Schema.Boolean),
721 /** Secret settings may point at a secret provider; older servers drop the reference. */
722 secretReferences: Schema.optionalKey(Schema.Boolean),
723 /** A secret request card may be answered with a secret provider reference. */
724 secretRequestReferences: Schema.optionalKey(Schema.Boolean),
725 scratchWorkspaceRoot: Schema.optionalKey(TrimmedNonEmptyString),
726 newProjectsRoot: Schema.optionalKey(TrimmedNonEmptyString),
727 /**
728 * The latest stall long enough to notice, sent only for a few minutes after
729 * it. A client that reconnects reads it to say why the host stopped
730 * answering. Clients do not cache it, since it describes the host at connect.
731 */
732 lastEventLoopStall: Schema.optionalKey(ServerEventLoopStall),
733 /**
734 * The host's clock when it built the config, so clients can count live
735 * elapsed times against host timestamps despite clock skew. Only a
736 * subscription's first snapshot is fresh; later snapshots may repeat it.
737 */
738 serverTime: Schema.optionalKey(IsoDateTime),
739 /**
740 * Never sent in a config snapshot: the theme stream emits the current set
741 * before any change, so a snapshot carrying it too would hand every
742 * subscriber the same array twice per connect.
743 */
744 environmentThemes: Schema.optional(Schema.Array(EnvironmentTheme)),
745 /** Stream-only and opt-in; the source stream emits the current set on subscribe. */
746 usageLimitSources: Schema.optional(UsageLimitSourceSnapshots),
747});
748export type ServerConfig = typeof ServerConfig.Type;
749
750export function resolveEnvironmentMachineKind(
751 config: {
752 readonly environment: Pick<ExecutionEnvironmentDescriptor, "platform">;
753 readonly settings?: Pick<ServerSettings, "environmentIcon">;
754 } | null,
755): EnvironmentMachineKind {
756 return config?.settings?.environmentIcon ?? config?.environment.platform.machine ?? "server";
757}
758
759const ServerUpsertKeybindingReplaceTarget = Schema.Struct({
760 key: KeybindingValue,
761 command: KeybindingCommand,
762 when: Schema.optional(KeybindingWhen),
763});
764
765export const ServerUpsertKeybindingInput = Schema.Struct({
766 key: KeybindingValue,
767 command: KeybindingCommand,
768 when: Schema.optional(KeybindingWhen),
769 replace: Schema.optional(ServerUpsertKeybindingReplaceTarget),
770});
771export type ServerUpsertKeybindingInput = typeof ServerUpsertKeybindingInput.Type;
772
773export const ServerRemoveKeybindingInput = ServerUpsertKeybindingReplaceTarget;
774export type ServerRemoveKeybindingInput = typeof ServerRemoveKeybindingInput.Type;
775
776export const ServerUpsertKeybindingResult = Schema.Struct({
777 keybindings: ResolvedKeybindingsConfig,
778 issues: ServerConfigIssues,
779});
780export type ServerUpsertKeybindingResult = typeof ServerUpsertKeybindingResult.Type;
781
782export const ServerRemoveKeybindingResult = ServerUpsertKeybindingResult;
783export type ServerRemoveKeybindingResult = typeof ServerRemoveKeybindingResult.Type;
784
785export const ServerConfigUpdatedPayload = Schema.Struct({
786 issues: ServerConfigIssues,
787 providers: ServerProviders,
788 settings: Schema.optional(ServerSettings),
789});
790export type ServerConfigUpdatedPayload = typeof ServerConfigUpdatedPayload.Type;
791
792export const ServerConfigKeybindingsUpdatedPayload = Schema.Struct({
793 keybindings: ResolvedKeybindingsConfig,
794 issues: ServerConfigIssues,
795});
796export type ServerConfigKeybindingsUpdatedPayload =
797 typeof ServerConfigKeybindingsUpdatedPayload.Type;
798
799export const ServerConfigProviderStatusesPayload = Schema.Struct({
800 providers: ServerProviders,
801});
802export type ServerConfigProviderStatusesPayload = typeof ServerConfigProviderStatusesPayload.Type;
803
804export const ServerConfigProviderStatusDeltasPayload = Schema.Struct({
805 /** Every provider in order, as `serverProviderDeltas` from the list this client last received. */
806 providers: ForwardCompatibleArray(ServerProviderDelta),
807});
808export type ServerConfigProviderStatusDeltasPayload =
809 typeof ServerConfigProviderStatusDeltasPayload.Type;
810
811export const ServerConfigSettingsUpdatedPayload = Schema.Struct({
812 settings: ServerSettings,
813});
814export type ServerConfigSettingsUpdatedPayload = typeof ServerConfigSettingsUpdatedPayload.Type;
815
816export const ServerConfigStreamSnapshotEvent = Schema.Struct({
817 version: Schema.Literal(1),
818 type: Schema.Literal("snapshot"),
819 config: ServerConfig,
820});
821export type ServerConfigStreamSnapshotEvent = typeof ServerConfigStreamSnapshotEvent.Type;
822
823export const ServerConfigStreamKeybindingsUpdatedEvent = Schema.Struct({
824 version: Schema.Literal(1),
825 type: Schema.Literal("keybindingsUpdated"),
826 payload: ServerConfigKeybindingsUpdatedPayload,
827});
828export type ServerConfigStreamKeybindingsUpdatedEvent =
829 typeof ServerConfigStreamKeybindingsUpdatedEvent.Type;
830
831export const ServerConfigStreamProviderStatusesEvent = Schema.Struct({
832 version: Schema.Literal(1),
833 type: Schema.Literal("providerStatuses"),
834 payload: ServerConfigProviderStatusesPayload,
835});
836export type ServerConfigStreamProviderStatusesEvent =
837 typeof ServerConfigStreamProviderStatusesEvent.Type;
838
839export const ServerConfigStreamProviderStatusDeltasEvent = Schema.Struct({
840 version: Schema.Literal(1),
841 type: Schema.Literal("providerStatusDeltas"),
842 payload: ServerConfigProviderStatusDeltasPayload,
843});
844export type ServerConfigStreamProviderStatusDeltasEvent =
845 typeof ServerConfigStreamProviderStatusDeltasEvent.Type;
846
847export const ServerConfigStreamSettingsUpdatedEvent = Schema.Struct({
848 version: Schema.Literal(1),
849 type: Schema.Literal("settingsUpdated"),
850 payload: ServerConfigSettingsUpdatedPayload,
851});
852export type ServerConfigStreamSettingsUpdatedEvent =
853 typeof ServerConfigStreamSettingsUpdatedEvent.Type;
854
855export const ServerConfigEnvironmentThemesUpdatedPayload = Schema.Struct({
856 themes: Schema.Array(EnvironmentTheme),
857});
858export type ServerConfigEnvironmentThemesUpdatedPayload =
859 typeof ServerConfigEnvironmentThemesUpdatedPayload.Type;
860
861export const ServerConfigStreamEnvironmentThemesUpdatedEvent = Schema.Struct({
862 version: Schema.Literal(1),
863 type: Schema.Literal("environmentThemesUpdated"),
864 payload: ServerConfigEnvironmentThemesUpdatedPayload,
865});
866export type ServerConfigStreamEnvironmentThemesUpdatedEvent =
867 typeof ServerConfigStreamEnvironmentThemesUpdatedEvent.Type;
868
869export const ServerConfigUsageLimitSourcesUpdatedPayload = Schema.Struct({
870 sources: UsageLimitSourceSnapshots,
871});
872export type ServerConfigUsageLimitSourcesUpdatedPayload =
873 typeof ServerConfigUsageLimitSourcesUpdatedPayload.Type;
874
875export const ServerConfigStreamUsageLimitSourcesUpdatedEvent = Schema.Struct({
876 version: Schema.Literal(1),
877 type: Schema.Literal("usageLimitSourcesUpdated"),
878 payload: ServerConfigUsageLimitSourcesUpdatedPayload,
879});
880export type ServerConfigStreamUsageLimitSourcesUpdatedEvent =
881 typeof ServerConfigStreamUsageLimitSourcesUpdatedEvent.Type;
882
883export const ServerConfigStreamEvent = Schema.Union([
884 ServerConfigStreamSnapshotEvent,
885 ServerConfigStreamKeybindingsUpdatedEvent,
886 ServerConfigStreamProviderStatusesEvent,
887 ServerConfigStreamProviderStatusDeltasEvent,
888 ServerConfigStreamSettingsUpdatedEvent,
889 ServerConfigStreamEnvironmentThemesUpdatedEvent,
890 ServerConfigStreamUsageLimitSourcesUpdatedEvent,
891]);
892export type ServerConfigStreamEvent = typeof ServerConfigStreamEvent.Type;
893
894export const ServerSelfUpdateOutcome = Schema.Struct({
895 id: TrimmedNonEmptyString,
896 fromVersion: TrimmedNonEmptyString,
897 targetVersion: TrimmedNonEmptyString,
898 status: Schema.Literals(["committed", "rolled-back", "failed"]),
899 reason: Schema.optionalKey(TrimmedNonEmptyString),
900});
901export type ServerSelfUpdateOutcome = typeof ServerSelfUpdateOutcome.Type;
902
903export const ServerLifecycleReadyPayload = Schema.Struct({
904 at: IsoDateTime,
905 environment: ExecutionEnvironmentDescriptor,
906 updateOutcome: Schema.optionalKey(ServerSelfUpdateOutcome),
907});
908export type ServerLifecycleReadyPayload = typeof ServerLifecycleReadyPayload.Type;
909
910export const ServerLifecycleWelcomePayload = Schema.Struct({
911 environment: ExecutionEnvironmentDescriptor,
912 cwd: TrimmedNonEmptyString,
913 projectName: TrimmedNonEmptyString,
914 bootstrapStatus: Schema.optional(Schema.Literals(["pending", "complete"])),
915 bootstrapProjectId: Schema.optional(ProjectId),
916 bootstrapThreadId: Schema.optional(ThreadId),
917 bootstrapProjectCreated: Schema.optional(Schema.Boolean),
918 bootstrapThreadCreated: Schema.optional(Schema.Boolean),
919});
920export type ServerLifecycleWelcomePayload = typeof ServerLifecycleWelcomePayload.Type;
921
922export const ServerLifecycleLegacyThreadMigrationPayload = Schema.Struct({
923 status: Schema.Union([Schema.Literal("running"), Schema.Literal("complete")]),
924 totalThreadCount: NonNegativeInt,
925});
926export type ServerLifecycleLegacyThreadMigrationPayload =
927 typeof ServerLifecycleLegacyThreadMigrationPayload.Type;
928
929export const ServerLifecycleStreamWelcomeEvent = Schema.Struct({
930 version: Schema.Literal(1),
931 sequence: NonNegativeInt,
932 type: Schema.Literal("welcome"),
933 payload: ServerLifecycleWelcomePayload,
934});
935export type ServerLifecycleStreamWelcomeEvent = typeof ServerLifecycleStreamWelcomeEvent.Type;
936
937export const ServerLifecycleStreamReadyEvent = Schema.Struct({
938 version: Schema.Literal(1),
939 sequence: NonNegativeInt,
940 type: Schema.Literal("ready"),
941 payload: ServerLifecycleReadyPayload,
942});
943export type ServerLifecycleStreamReadyEvent = typeof ServerLifecycleStreamReadyEvent.Type;
944
945export const ServerLifecycleStreamLegacyThreadMigrationEvent = Schema.Struct({
946 version: Schema.Literal(1),
947 sequence: NonNegativeInt,
948 type: Schema.Literal("legacyThreadMigration"),
949 payload: ServerLifecycleLegacyThreadMigrationPayload,
950});
951export type ServerLifecycleStreamLegacyThreadMigrationEvent =
952 typeof ServerLifecycleStreamLegacyThreadMigrationEvent.Type;
953
954export const ServerLifecycleStreamEvent = Schema.Union([
955 ServerLifecycleStreamWelcomeEvent,
956 ServerLifecycleStreamReadyEvent,
957 ServerLifecycleStreamLegacyThreadMigrationEvent,
958]);
959export type ServerLifecycleStreamEvent = typeof ServerLifecycleStreamEvent.Type;
960
961export const ServerProviderUpdatedPayload = Schema.Struct({
962 providers: ServerProviders,
963});
964export type ServerProviderUpdatedPayload = typeof ServerProviderUpdatedPayload.Type;
965
966export const ServerProviderUpdateInput = Schema.Struct({
967 provider: ProviderDriverKind,
968 targetVersion: Schema.optionalKey(TrimmedNonEmptyString),
969 instanceId: Schema.optionalKey(ProviderInstanceId),
970});
971export type ServerProviderUpdateInput = typeof ServerProviderUpdateInput.Type;
972
973export class ServerProviderUpdateError extends Schema.TaggedError<ServerProviderUpdateError>()(
974 "ServerProviderUpdateError",
975 {
976 provider: ProviderDriverKind,
977 reason: TrimmedNonEmptyString,
978 cause: Schema.optional(Schema.Defect()),
979 },
980) {
981 override get message(): string {
982 return `Provider update failed for ${this.provider}: ${this.reason}`;
983 }
984}
985
986export const ServerNpmReleaseInput = Schema.Struct({
987 spec: Schema.String.check(
988 Schema.isMaxLength(64),
989 Schema.isPattern(/^(?:latest|nightly|\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?)$/),
990 ),
991});
992export type ServerNpmReleaseInput = typeof ServerNpmReleaseInput.Type;
993
994export const ServerNpmRelease = Schema.Struct({
995 version: Schema.String,
996 databaseMigration: Schema.optionalKey(Schema.Int),
997});
998export type ServerNpmRelease = typeof ServerNpmRelease.Type;
999
1000export class ServerNpmReleaseError extends Schema.TaggedError<ServerNpmReleaseError>()(
1001 "ServerNpmReleaseError",
1002 { reason: Schema.String },
1003) {
1004 override get message(): string {
1005 return `Could not check the configured npm registry: ${this.reason}`;
1006 }
1007}
1008
1009export const ServerSelfUpdateInput = Schema.Struct({
1010 /** Exact npm version, never a dist-tag, so server and client agree on the request. */
1011 targetVersion: TrimmedNonEmptyString,
1012 /** Desktop-managed hosts move their app to this update track first. Sent only for a track switch. */
1013 channel: Schema.optionalKey(DesktopUpdateChannelSchema),
1014 /** The target release's highest migration; the host refuses to leave Nightly without it. */
1015 targetDatabaseMigration: Schema.optionalKey(Schema.Int),
1016 stageOnly: Schema.optionalKey(Schema.Boolean),
1017});
1018export type ServerSelfUpdateInput = typeof ServerSelfUpdateInput.Type;
1019
1020export const ServerSelfUpdateResult = Schema.Struct({
1021 targetVersion: TrimmedNonEmptyString,
1022 method: ServerSelfUpdateMethod,
1023 updateId: Schema.optionalKey(TrimmedNonEmptyString),
1024 desktopUpdateToken: Schema.optionalKey(TrimmedNonEmptyString),
1025});
1026export type ServerSelfUpdateResult = typeof ServerSelfUpdateResult.Type;
1027
1028export const DesktopUpdateCommitInput = Schema.Struct({
1029 requestId: TrimmedNonEmptyString,
1030});
1031export type DesktopUpdateCommitInput = typeof DesktopUpdateCommitInput.Type;
1032
1033export const ServerSelfUpdateProgressStage = Schema.Literals(["downloading", "installing"]);
1034export type ServerSelfUpdateProgressStage = typeof ServerSelfUpdateProgressStage.Type;
1035
1036export const ServerSelfUpdateProgressEvent = Schema.Union([
1037 Schema.Struct({
1038 type: Schema.Literal("progress"),
1039 stage: ServerSelfUpdateProgressStage,
1040 }),
1041 Schema.Struct({
1042 type: Schema.Literal("complete"),
1043 result: ServerSelfUpdateResult,
1044 }),
1045]);
1046export type ServerSelfUpdateProgressEvent = typeof ServerSelfUpdateProgressEvent.Type;
1047
1048export class ServerSelfUpdateError extends Schema.TaggedError<ServerSelfUpdateError>()(
1049 "ServerSelfUpdateError",
1050 {
1051 reason: TrimmedNonEmptyString,
1052 cause: Schema.optional(Schema.Defect()),
1053 },
1054) {
1055 override get message(): string {
1056 return `Server update failed: ${this.reason}`;
1057 }
1058}