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
625const environmentThemeFields = {
626 version: Schema.optional(Schema.Literal(1)),
627 name: TrimmedNonEmptyString.check(Schema.isMaxLength(48)),
628 appearance: Schema.Literals(["light", "dark"]),
629 /** Derive the palette from canvas/accent, then overlay colors; without them, colors is the palette. */
630 canvas: Schema.optional(EnvironmentThemeColor),
631 accent: Schema.optional(EnvironmentThemeColor),
632 colors: Schema.optional(EnvironmentThemeColors),
633 variants: Schema.optional(
634 Schema.Struct({
635 light: Schema.optional(EnvironmentThemeColors),
636 dark: Schema.optional(EnvironmentThemeColors),
637 }),
638 ),
639};
640
641export const EnvironmentThemeFile = Schema.Struct(environmentThemeFields);
642export type EnvironmentThemeFile = typeof EnvironmentThemeFile.Type;
643
644export const EnvironmentTheme = Schema.Struct({
645 id: EnvironmentThemeId,
646 ...environmentThemeFields,
647});
648export type EnvironmentTheme = typeof EnvironmentTheme.Type;
649
650export function environmentThemeFileHasColors(file: EnvironmentThemeFile): boolean {
651 return (
652 (file.canvas !== undefined && file.accent !== undefined) ||
653 (file.colors !== undefined && Object.keys(file.colors).length > 0)
654 );
655}
656
657/** tailnet means this machine's Tailscale interface; other private addresses are lan. */
658export const ServerDirectEndpointKind = Schema.Literals(["lan", "tailnet"]);
659export type ServerDirectEndpointKind = typeof ServerDirectEndpointKind.Type;
660
661export const ServerDirectEndpoint = Schema.Struct({
662 kind: ServerDirectEndpointKind,
663 httpBaseUrl: TrimmedNonEmptyString,
664});
665export type ServerDirectEndpoint = typeof ServerDirectEndpoint.Type;
666
667/**
668 * A stretch where the server's event loop could not run, so it answered
669 * nothing and clients may have dropped the connection.
670 */
671export const ServerEventLoopStall = Schema.Struct({
672 detectedAt: IsoDateTime,
673 durationMs: NonNegativeInt,
674 /** One-minute load average when the stall was seen. Absent on Windows, which has none. */
675 loadAverage: Schema.optionalKey(Schema.Number),
676 cpuCount: PositiveInt,
677});
678export type ServerEventLoopStall = typeof ServerEventLoopStall.Type;
679
680export const ServerConfig = Schema.Struct({
681 environment: ExecutionEnvironmentDescriptor,
682 auth: ServerAuthDescriptor,
683 cwd: TrimmedNonEmptyString,
684 keybindingsConfigPath: TrimmedNonEmptyString,
685 keybindings: ResolvedKeybindingsConfig,
686 issues: ServerConfigIssues,
687 providers: ServerProviders,
688 availableEditors: ForwardCompatibleArray(EditorId),
689 remoteOpenTargets: Schema.optionalKey(ForwardCompatibleArray(RemoteOpenTarget)),
690 /** Hints only; verify each address answers as this environment. */
691 directEndpoints: Schema.optionalKey(ForwardCompatibleArray(ServerDirectEndpoint)),
692 observability: ServerObservability,
693 settings: ServerSettings,
694 /** Present when an administrator's policy file manages this environment. */
695 managedPolicy: Schema.optionalKey(ManagedPolicySummary),
696 shellResumeCompletionMarker: Schema.optionalKey(Schema.Boolean),
697 /**
698 * The shell can leave idle subagent children out of snapshots (`omitIdleSubagents`), and
699 * `getThreadFamily` and `getWorktreeThreadIds` serve the rows it leaves out.
700 */
701 shellThreadFamilies: Schema.optionalKey(Schema.Boolean),
702 threadLinkMetadata: Schema.optionalKey(Schema.Boolean),
703 /**
704 * The shell can leave older settled threads out of snapshots (`omitOlderSettled`), and
705 * `getOlderSettledThreads` serves them. Only servers that also advertise `shellThreadFamilies`.
706 */
707 shellOlderSettled: Schema.optionalKey(Schema.Boolean),
708 shellRevealInFileManager: Schema.optionalKey(Schema.Boolean),
709 shellRevealInFileManagerKind: Schema.optionalKey(FileManagerRevealKind),
710 threadResumeCompletionMarker: Schema.optionalKey(Schema.Boolean),
711 /** Send window fields only when advertised. */
712 threadSnapshotPagination: Schema.optionalKey(Schema.Boolean),
713 threadFind: Schema.optionalKey(Schema.Boolean),
714 threadFindProgressive: Schema.optionalKey(Schema.Boolean),
715 /** Settings patches may carry `secretProviders`; older servers drop the key without an error. */
716 secretProviderSettings: Schema.optionalKey(Schema.Boolean),
717 /** Secret settings may point at a secret provider; older servers drop the reference. */
718 secretReferences: Schema.optionalKey(Schema.Boolean),
719 /** A secret request card may be answered with a secret provider reference. */
720 secretRequestReferences: Schema.optionalKey(Schema.Boolean),
721 scratchWorkspaceRoot: Schema.optionalKey(TrimmedNonEmptyString),
722 newProjectsRoot: Schema.optionalKey(TrimmedNonEmptyString),
723 /**
724 * The latest stall long enough to notice, sent only for a few minutes after
725 * it. A client that reconnects reads it to say why the host stopped
726 * answering. Clients do not cache it, since it describes the host at connect.
727 */
728 lastEventLoopStall: Schema.optionalKey(ServerEventLoopStall),
729 /**
730 * The host's clock when it built the config, so clients can count live
731 * elapsed times against host timestamps despite clock skew. Only a
732 * subscription's first snapshot is fresh; later snapshots may repeat it.
733 */
734 serverTime: Schema.optionalKey(IsoDateTime),
735 /**
736 * Never sent in a config snapshot: the theme stream emits the current set
737 * before any change, so a snapshot carrying it too would hand every
738 * subscriber the same array twice per connect.
739 */
740 environmentThemes: Schema.optional(Schema.Array(EnvironmentTheme)),
741 /** Stream-only and opt-in; the source stream emits the current set on subscribe. */
742 usageLimitSources: Schema.optional(UsageLimitSourceSnapshots),
743});
744export type ServerConfig = typeof ServerConfig.Type;
745
746export function resolveEnvironmentMachineKind(
747 config: {
748 readonly environment: Pick<ExecutionEnvironmentDescriptor, "platform">;
749 readonly settings?: Pick<ServerSettings, "environmentIcon">;
750 } | null,
751): EnvironmentMachineKind {
752 return config?.settings?.environmentIcon ?? config?.environment.platform.machine ?? "server";
753}
754
755const ServerUpsertKeybindingReplaceTarget = Schema.Struct({
756 key: KeybindingValue,
757 command: KeybindingCommand,
758 when: Schema.optional(KeybindingWhen),
759});
760
761export const ServerUpsertKeybindingInput = Schema.Struct({
762 key: KeybindingValue,
763 command: KeybindingCommand,
764 when: Schema.optional(KeybindingWhen),
765 replace: Schema.optional(ServerUpsertKeybindingReplaceTarget),
766});
767export type ServerUpsertKeybindingInput = typeof ServerUpsertKeybindingInput.Type;
768
769export const ServerRemoveKeybindingInput = ServerUpsertKeybindingReplaceTarget;
770export type ServerRemoveKeybindingInput = typeof ServerRemoveKeybindingInput.Type;
771
772export const ServerUpsertKeybindingResult = Schema.Struct({
773 keybindings: ResolvedKeybindingsConfig,
774 issues: ServerConfigIssues,
775});
776export type ServerUpsertKeybindingResult = typeof ServerUpsertKeybindingResult.Type;
777
778export const ServerRemoveKeybindingResult = ServerUpsertKeybindingResult;
779export type ServerRemoveKeybindingResult = typeof ServerRemoveKeybindingResult.Type;
780
781export const ServerConfigUpdatedPayload = Schema.Struct({
782 issues: ServerConfigIssues,
783 providers: ServerProviders,
784 settings: Schema.optional(ServerSettings),
785});
786export type ServerConfigUpdatedPayload = typeof ServerConfigUpdatedPayload.Type;
787
788export const ServerConfigKeybindingsUpdatedPayload = Schema.Struct({
789 keybindings: ResolvedKeybindingsConfig,
790 issues: ServerConfigIssues,
791});
792export type ServerConfigKeybindingsUpdatedPayload =
793 typeof ServerConfigKeybindingsUpdatedPayload.Type;
794
795export const ServerConfigProviderStatusesPayload = Schema.Struct({
796 providers: ServerProviders,
797});
798export type ServerConfigProviderStatusesPayload = typeof ServerConfigProviderStatusesPayload.Type;
799
800export const ServerConfigProviderStatusDeltasPayload = Schema.Struct({
801 /** Every provider in order, as `serverProviderDeltas` from the list this client last received. */
802 providers: ForwardCompatibleArray(ServerProviderDelta),
803});
804export type ServerConfigProviderStatusDeltasPayload =
805 typeof ServerConfigProviderStatusDeltasPayload.Type;
806
807export const ServerConfigSettingsUpdatedPayload = Schema.Struct({
808 settings: ServerSettings,
809});
810export type ServerConfigSettingsUpdatedPayload = typeof ServerConfigSettingsUpdatedPayload.Type;
811
812export const ServerConfigStreamSnapshotEvent = Schema.Struct({
813 version: Schema.Literal(1),
814 type: Schema.Literal("snapshot"),
815 config: ServerConfig,
816});
817export type ServerConfigStreamSnapshotEvent = typeof ServerConfigStreamSnapshotEvent.Type;
818
819export const ServerConfigStreamKeybindingsUpdatedEvent = Schema.Struct({
820 version: Schema.Literal(1),
821 type: Schema.Literal("keybindingsUpdated"),
822 payload: ServerConfigKeybindingsUpdatedPayload,
823});
824export type ServerConfigStreamKeybindingsUpdatedEvent =
825 typeof ServerConfigStreamKeybindingsUpdatedEvent.Type;
826
827export const ServerConfigStreamProviderStatusesEvent = Schema.Struct({
828 version: Schema.Literal(1),
829 type: Schema.Literal("providerStatuses"),
830 payload: ServerConfigProviderStatusesPayload,
831});
832export type ServerConfigStreamProviderStatusesEvent =
833 typeof ServerConfigStreamProviderStatusesEvent.Type;
834
835export const ServerConfigStreamProviderStatusDeltasEvent = Schema.Struct({
836 version: Schema.Literal(1),
837 type: Schema.Literal("providerStatusDeltas"),
838 payload: ServerConfigProviderStatusDeltasPayload,
839});
840export type ServerConfigStreamProviderStatusDeltasEvent =
841 typeof ServerConfigStreamProviderStatusDeltasEvent.Type;
842
843export const ServerConfigStreamSettingsUpdatedEvent = Schema.Struct({
844 version: Schema.Literal(1),
845 type: Schema.Literal("settingsUpdated"),
846 payload: ServerConfigSettingsUpdatedPayload,
847});
848export type ServerConfigStreamSettingsUpdatedEvent =
849 typeof ServerConfigStreamSettingsUpdatedEvent.Type;
850
851export const ServerConfigEnvironmentThemesUpdatedPayload = Schema.Struct({
852 themes: Schema.Array(EnvironmentTheme),
853});
854export type ServerConfigEnvironmentThemesUpdatedPayload =
855 typeof ServerConfigEnvironmentThemesUpdatedPayload.Type;
856
857export const ServerConfigStreamEnvironmentThemesUpdatedEvent = Schema.Struct({
858 version: Schema.Literal(1),
859 type: Schema.Literal("environmentThemesUpdated"),
860 payload: ServerConfigEnvironmentThemesUpdatedPayload,
861});
862export type ServerConfigStreamEnvironmentThemesUpdatedEvent =
863 typeof ServerConfigStreamEnvironmentThemesUpdatedEvent.Type;
864
865export const ServerConfigUsageLimitSourcesUpdatedPayload = Schema.Struct({
866 sources: UsageLimitSourceSnapshots,
867});
868export type ServerConfigUsageLimitSourcesUpdatedPayload =
869 typeof ServerConfigUsageLimitSourcesUpdatedPayload.Type;
870
871export const ServerConfigStreamUsageLimitSourcesUpdatedEvent = Schema.Struct({
872 version: Schema.Literal(1),
873 type: Schema.Literal("usageLimitSourcesUpdated"),
874 payload: ServerConfigUsageLimitSourcesUpdatedPayload,
875});
876export type ServerConfigStreamUsageLimitSourcesUpdatedEvent =
877 typeof ServerConfigStreamUsageLimitSourcesUpdatedEvent.Type;
878
879export const ServerConfigStreamEvent = Schema.Union([
880 ServerConfigStreamSnapshotEvent,
881 ServerConfigStreamKeybindingsUpdatedEvent,
882 ServerConfigStreamProviderStatusesEvent,
883 ServerConfigStreamProviderStatusDeltasEvent,
884 ServerConfigStreamSettingsUpdatedEvent,
885 ServerConfigStreamEnvironmentThemesUpdatedEvent,
886 ServerConfigStreamUsageLimitSourcesUpdatedEvent,
887]);
888export type ServerConfigStreamEvent = typeof ServerConfigStreamEvent.Type;
889
890export const ServerSelfUpdateOutcome = Schema.Struct({
891 id: TrimmedNonEmptyString,
892 fromVersion: TrimmedNonEmptyString,
893 targetVersion: TrimmedNonEmptyString,
894 status: Schema.Literals(["committed", "rolled-back", "failed"]),
895 reason: Schema.optionalKey(TrimmedNonEmptyString),
896});
897export type ServerSelfUpdateOutcome = typeof ServerSelfUpdateOutcome.Type;
898
899export const ServerLifecycleReadyPayload = Schema.Struct({
900 at: IsoDateTime,
901 environment: ExecutionEnvironmentDescriptor,
902 updateOutcome: Schema.optionalKey(ServerSelfUpdateOutcome),
903});
904export type ServerLifecycleReadyPayload = typeof ServerLifecycleReadyPayload.Type;
905
906export const ServerLifecycleWelcomePayload = Schema.Struct({
907 environment: ExecutionEnvironmentDescriptor,
908 cwd: TrimmedNonEmptyString,
909 projectName: TrimmedNonEmptyString,
910 bootstrapStatus: Schema.optional(Schema.Literals(["pending", "complete"])),
911 bootstrapProjectId: Schema.optional(ProjectId),
912 bootstrapThreadId: Schema.optional(ThreadId),
913 bootstrapProjectCreated: Schema.optional(Schema.Boolean),
914 bootstrapThreadCreated: Schema.optional(Schema.Boolean),
915});
916export type ServerLifecycleWelcomePayload = typeof ServerLifecycleWelcomePayload.Type;
917
918export const ServerLifecycleLegacyThreadMigrationPayload = Schema.Struct({
919 status: Schema.Union([Schema.Literal("running"), Schema.Literal("complete")]),
920 totalThreadCount: NonNegativeInt,
921});
922export type ServerLifecycleLegacyThreadMigrationPayload =
923 typeof ServerLifecycleLegacyThreadMigrationPayload.Type;
924
925export const ServerLifecycleStreamWelcomeEvent = Schema.Struct({
926 version: Schema.Literal(1),
927 sequence: NonNegativeInt,
928 type: Schema.Literal("welcome"),
929 payload: ServerLifecycleWelcomePayload,
930});
931export type ServerLifecycleStreamWelcomeEvent = typeof ServerLifecycleStreamWelcomeEvent.Type;
932
933export const ServerLifecycleStreamReadyEvent = Schema.Struct({
934 version: Schema.Literal(1),
935 sequence: NonNegativeInt,
936 type: Schema.Literal("ready"),
937 payload: ServerLifecycleReadyPayload,
938});
939export type ServerLifecycleStreamReadyEvent = typeof ServerLifecycleStreamReadyEvent.Type;
940
941export const ServerLifecycleStreamLegacyThreadMigrationEvent = Schema.Struct({
942 version: Schema.Literal(1),
943 sequence: NonNegativeInt,
944 type: Schema.Literal("legacyThreadMigration"),
945 payload: ServerLifecycleLegacyThreadMigrationPayload,
946});
947export type ServerLifecycleStreamLegacyThreadMigrationEvent =
948 typeof ServerLifecycleStreamLegacyThreadMigrationEvent.Type;
949
950export const ServerLifecycleStreamEvent = Schema.Union([
951 ServerLifecycleStreamWelcomeEvent,
952 ServerLifecycleStreamReadyEvent,
953 ServerLifecycleStreamLegacyThreadMigrationEvent,
954]);
955export type ServerLifecycleStreamEvent = typeof ServerLifecycleStreamEvent.Type;
956
957export const ServerProviderUpdatedPayload = Schema.Struct({
958 providers: ServerProviders,
959});
960export type ServerProviderUpdatedPayload = typeof ServerProviderUpdatedPayload.Type;
961
962export const ServerProviderUpdateInput = Schema.Struct({
963 provider: ProviderDriverKind,
964 targetVersion: Schema.optionalKey(TrimmedNonEmptyString),
965 instanceId: Schema.optionalKey(ProviderInstanceId),
966});
967export type ServerProviderUpdateInput = typeof ServerProviderUpdateInput.Type;
968
969export class ServerProviderUpdateError extends Schema.TaggedError<ServerProviderUpdateError>()(
970 "ServerProviderUpdateError",
971 {
972 provider: ProviderDriverKind,
973 reason: TrimmedNonEmptyString,
974 cause: Schema.optional(Schema.Defect()),
975 },
976) {
977 override get message(): string {
978 return `Provider update failed for ${this.provider}: ${this.reason}`;
979 }
980}
981
982export const ServerNpmReleaseInput = Schema.Struct({
983 spec: Schema.String.check(
984 Schema.isMaxLength(64),
985 Schema.isPattern(/^(?:latest|nightly|\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?)$/),
986 ),
987});
988export type ServerNpmReleaseInput = typeof ServerNpmReleaseInput.Type;
989
990export const ServerNpmRelease = Schema.Struct({
991 version: Schema.String,
992 databaseMigration: Schema.optionalKey(Schema.Int),
993});
994export type ServerNpmRelease = typeof ServerNpmRelease.Type;
995
996export class ServerNpmReleaseError extends Schema.TaggedError<ServerNpmReleaseError>()(
997 "ServerNpmReleaseError",
998 { reason: Schema.String },
999) {
1000 override get message(): string {
1001 return `Could not check the configured npm registry: ${this.reason}`;
1002 }
1003}
1004
1005export const ServerSelfUpdateInput = Schema.Struct({
1006 /** Exact npm version, never a dist-tag, so server and client agree on the request. */
1007 targetVersion: TrimmedNonEmptyString,
1008 /** Desktop-managed hosts move their app to this update track first. Sent only for a track switch. */
1009 channel: Schema.optionalKey(DesktopUpdateChannelSchema),
1010 /** The target release's highest migration; the host refuses to leave Nightly without it. */
1011 targetDatabaseMigration: Schema.optionalKey(Schema.Int),
1012});
1013export type ServerSelfUpdateInput = typeof ServerSelfUpdateInput.Type;
1014
1015export const ServerSelfUpdateResult = Schema.Struct({
1016 targetVersion: TrimmedNonEmptyString,
1017 method: ServerSelfUpdateMethod,
1018 updateId: Schema.optionalKey(TrimmedNonEmptyString),
1019 desktopUpdateToken: Schema.optionalKey(TrimmedNonEmptyString),
1020});
1021export type ServerSelfUpdateResult = typeof ServerSelfUpdateResult.Type;
1022
1023export const DesktopUpdateCommitInput = Schema.Struct({
1024 requestId: TrimmedNonEmptyString,
1025});
1026export type DesktopUpdateCommitInput = typeof DesktopUpdateCommitInput.Type;
1027
1028export const ServerSelfUpdateProgressStage = Schema.Literals(["downloading", "installing"]);
1029export type ServerSelfUpdateProgressStage = typeof ServerSelfUpdateProgressStage.Type;
1030
1031export const ServerSelfUpdateProgressEvent = Schema.Union([
1032 Schema.Struct({
1033 type: Schema.Literal("progress"),
1034 stage: ServerSelfUpdateProgressStage,
1035 }),
1036 Schema.Struct({
1037 type: Schema.Literal("complete"),
1038 result: ServerSelfUpdateResult,
1039 }),
1040]);
1041export type ServerSelfUpdateProgressEvent = typeof ServerSelfUpdateProgressEvent.Type;
1042
1043export class ServerSelfUpdateError extends Schema.TaggedError<ServerSelfUpdateError>()(
1044 "ServerSelfUpdateError",
1045 {
1046 reason: TrimmedNonEmptyString,
1047 cause: Schema.optional(Schema.Defect()),
1048 },
1049) {
1050 override get message(): string {
1051 return `Server update failed: ${this.reason}`;
1052 }
1053}