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 /**
280 * Set when the server rescanned a workspace after a session start and its skills or commands
281 * changed. Clients holding fetched workspace snapshots for this provider fetch them again.
282 */
283 workspaceRescannedAt: Schema.optionalKey(IsoDateTime),
284 usageLimits: Schema.optional(ServerProviderUsageLimits),
285 versionAdvisory: Schema.optionalKey(ServerProviderVersionAdvisory),
286 compatibilityAdvisory: Schema.optionalKey(ServerProviderCompatibilityAdvisory),
287 updateState: Schema.optionalKey(ServerProviderUpdateState),
288 /**
289 * Stands for the machine slash commands and skills, which are then left out. Sent to clients
290 * that ask for catalog digests; they load both lists with their next cwd snapshot.
291 */
292 catalogDigest: Schema.optionalKey(TrimmedNonEmptyString),
293 /** Set by the client, never sent: the `catalogDigest` its slash commands and skills belong to. */
294 loadedCatalogDigest: Schema.optionalKey(TrimmedNonEmptyString),
295});
296export type ServerProvider = typeof ServerProvider.Type;
297
298/** A provider without the lists that equal the ones its reader already holds. */
299export const ServerProviderDelta = ServerProvider.mapFields((fields) => ({
300 ...fields,
301 models: Schema.optionalKey(fields.models),
302 // Declared again without the decoding default, which would read as a change to an empty list.
303 slashCommands: Schema.optionalKey(Schema.Array(ServerProviderSlashCommand)),
304 skills: Schema.optionalKey(Schema.Array(ServerProviderSkill)),
305}));
306export type ServerProviderDelta = typeof ServerProviderDelta.Type;
307
308const sameJson = (left: unknown, right: unknown) =>
309 left === right || JSON.stringify(left) === JSON.stringify(right);
310
311/** Leaves each provider's models, slash commands, and skills out when `previous` has the same. */
312export function serverProviderDeltas(
313 previous: ReadonlyArray<ServerProvider>,
314 next: ReadonlyArray<ServerProvider>,
315): ServerProviderDelta[] {
316 const held = new Map(previous.map((provider) => [provider.instanceId, provider]));
317 return next.map((provider) => {
318 const base = held.get(provider.instanceId);
319 if (base === undefined) return provider;
320 const { models, slashCommands, skills, ...rest } = provider;
321 return {
322 ...rest,
323 ...(sameJson(base.models, models) ? {} : { models }),
324 ...(sameJson(base.slashCommands, slashCommands) ? {} : { slashCommands }),
325 ...(sameJson(base.skills, skills) ? {} : { skills }),
326 };
327 });
328}
329
330/** Rebuilds the provider list `serverProviderDeltas` was made from. */
331export function applyServerProviderDeltas(
332 previous: ReadonlyArray<ServerProvider>,
333 deltas: ReadonlyArray<ServerProviderDelta>,
334): ServerProvider[] {
335 const held = new Map(previous.map((provider) => [provider.instanceId, provider]));
336 return deltas.flatMap((delta) => {
337 const base = held.get(delta.instanceId);
338 const models = delta.models ?? base?.models;
339 const slashCommands = delta.slashCommands ?? base?.slashCommands;
340 const skills = delta.skills ?? base?.skills;
341 // A list this reader never held cannot be rebuilt; drop the provider like an unreadable one.
342 return models && slashCommands && skills ? [{ ...delta, models, slashCommands, skills }] : [];
343 });
344}
345
346export const ServerProviders = ForwardCompatibleArray(ServerProvider);
347export type ServerProviders = typeof ServerProviders.Type;
348
349export const isProviderAvailable = (snapshot: ServerProvider): boolean =>
350 snapshot.availability !== "unavailable";
351
352/** Legacy producers omit this field and support text generation. */
353export const isProviderTextGenerationCapable = (snapshot: ServerProvider): boolean =>
354 snapshot.supportsTextGeneration !== false;
355
356export const OtlpEndpointSource = Schema.Literals(["environment", "bootstrap", "settings"]);
357export type OtlpEndpointSource = typeof OtlpEndpointSource.Type;
358
359export const ServerObservability = Schema.Struct({
360 logsDirectoryPath: TrimmedNonEmptyString,
361 localTracingEnabled: Schema.Boolean,
362 otlpTracesUrl: Schema.optional(TrimmedNonEmptyString),
363 otlpTracesSource: Schema.optional(OtlpEndpointSource),
364 otlpTracesVariable: Schema.optional(TrimmedNonEmptyString),
365 otlpTracesEnabled: Schema.Boolean,
366 otlpMetricsUrl: Schema.optional(TrimmedNonEmptyString),
367 otlpMetricsSource: Schema.optional(OtlpEndpointSource),
368 otlpMetricsVariable: Schema.optional(TrimmedNonEmptyString),
369 otlpMetricsEnabled: Schema.Boolean,
370 otlpLogsUrl: Schema.optional(TrimmedNonEmptyString),
371 otlpLogsSource: Schema.optional(OtlpEndpointSource),
372 otlpLogsVariable: Schema.optional(TrimmedNonEmptyString),
373 otlpLogsEnabled: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(false))),
374});
375export type ServerObservability = typeof ServerObservability.Type;
376
377export const OtlpSignal = Schema.Literals(["traces", "metrics", "logs"]);
378export type OtlpSignal = typeof OtlpSignal.Type;
379
380export const OtlpEndpointCheckInput = Schema.Struct({
381 signal: OtlpSignal,
382 url: TrimmedNonEmptyString.check(Schema.isPattern(/^https?:\/\/./i)),
383});
384export type OtlpEndpointCheckInput = typeof OtlpEndpointCheckInput.Type;
385
386export const OtlpEndpointCheckResult = Schema.Union([
387 Schema.TaggedStruct("Accepted", { latencyMs: Schema.Number }),
388 Schema.TaggedStruct("Rejected", { status: Schema.Number }),
389 Schema.TaggedStruct("Unreachable", { timedOut: Schema.Boolean }),
390]);
391export type OtlpEndpointCheckResult = typeof OtlpEndpointCheckResult.Type;
392
393/** The client tells the server what it is, so the triage context can name it. */
394export const ServerPrepareTriageInput = Schema.Struct({
395 client: AuthClientPresentationMetadata,
396});
397export type ServerPrepareTriageInput = typeof ServerPrepareTriageInput.Type;
398
399export const ServerPrepareTriageResult = Schema.Struct({
400 /** Composer text that links the session's prompt file. */
401 prompt: Schema.String,
402});
403export type ServerPrepareTriageResult = typeof ServerPrepareTriageResult.Type;
404
405/**
406 * The prompt file links as a chip in the user's message; clients spot a triage
407 * draft by it.
408 */
409export const TRIAGE_PROMPT_FILE_NAME = "triage-playbook.md";
410
411export class ServerPrepareTriageError extends Schema.TaggedError<ServerPrepareTriageError>()(
412 "ServerPrepareTriageError",
413 { cause: Schema.optional(Schema.Defect()) },
414) {
415 override get message(): string {
416 return "Could not write the triage session files.";
417 }
418}
419
420export const ServerTraceDiagnosticsErrorKind = Schema.Literals([
421 "trace-file-not-found",
422 "trace-file-read-failed",
423]);
424export type ServerTraceDiagnosticsErrorKind = typeof ServerTraceDiagnosticsErrorKind.Type;
425
426export const ServerTraceDiagnosticsSpanSummary = Schema.Struct({
427 name: TrimmedNonEmptyString,
428 count: NonNegativeInt,
429 failureCount: NonNegativeInt,
430 totalDurationMs: Schema.Number,
431 averageDurationMs: Schema.Number,
432 maxDurationMs: Schema.Number,
433});
434export type ServerTraceDiagnosticsSpanSummary = typeof ServerTraceDiagnosticsSpanSummary.Type;
435
436export const ServerTraceDiagnosticsFailureSummary = Schema.Struct({
437 name: TrimmedNonEmptyString,
438 cause: TrimmedNonEmptyString,
439 count: NonNegativeInt,
440 lastSeenAt: Schema.DateTimeUtc,
441 traceId: TrimmedNonEmptyString,
442 spanId: TrimmedNonEmptyString,
443});
444export type ServerTraceDiagnosticsFailureSummary = typeof ServerTraceDiagnosticsFailureSummary.Type;
445
446export const ServerTraceDiagnosticsRecentFailure = Schema.Struct({
447 name: TrimmedNonEmptyString,
448 cause: TrimmedNonEmptyString,
449 durationMs: Schema.Number,
450 endedAt: Schema.DateTimeUtc,
451 traceId: TrimmedNonEmptyString,
452 spanId: TrimmedNonEmptyString,
453});
454export type ServerTraceDiagnosticsRecentFailure = typeof ServerTraceDiagnosticsRecentFailure.Type;
455
456export const ServerTraceDiagnosticsSpanOccurrence = Schema.Struct({
457 name: TrimmedNonEmptyString,
458 durationMs: Schema.Number,
459 endedAt: Schema.DateTimeUtc,
460 traceId: TrimmedNonEmptyString,
461 spanId: TrimmedNonEmptyString,
462});
463export type ServerTraceDiagnosticsSpanOccurrence = typeof ServerTraceDiagnosticsSpanOccurrence.Type;
464
465export const ServerTraceDiagnosticsLogEvent = Schema.Struct({
466 spanName: TrimmedNonEmptyString,
467 level: TrimmedNonEmptyString,
468 message: TrimmedNonEmptyString,
469 seenAt: Schema.DateTimeUtc,
470 traceId: TrimmedNonEmptyString,
471 spanId: TrimmedNonEmptyString,
472});
473export type ServerTraceDiagnosticsLogEvent = typeof ServerTraceDiagnosticsLogEvent.Type;
474
475export const ServerTraceDiagnosticsResult = Schema.Struct({
476 traceFilePath: TrimmedNonEmptyString,
477 scannedFilePaths: Schema.Array(TrimmedNonEmptyString),
478 readAt: Schema.DateTimeUtc,
479 recordCount: NonNegativeInt,
480 parseErrorCount: NonNegativeInt,
481 firstSpanAt: Schema.Option(Schema.DateTimeUtc),
482 lastSpanAt: Schema.Option(Schema.DateTimeUtc),
483 failureCount: NonNegativeInt,
484 interruptionCount: NonNegativeInt,
485 slowSpanThresholdMs: NonNegativeInt,
486 slowSpanCount: NonNegativeInt,
487 logLevelCounts: Schema.Record(TrimmedNonEmptyString, NonNegativeInt),
488 topSpansByCount: Schema.Array(ServerTraceDiagnosticsSpanSummary),
489 slowestSpans: Schema.Array(ServerTraceDiagnosticsSpanOccurrence),
490 commonFailures: Schema.Array(ServerTraceDiagnosticsFailureSummary),
491 latestFailures: Schema.Array(ServerTraceDiagnosticsRecentFailure),
492 latestWarningAndErrorLogs: Schema.Array(ServerTraceDiagnosticsLogEvent),
493 partialFailure: Schema.Option(Schema.Boolean),
494 error: Schema.Option(
495 Schema.Struct({
496 kind: ServerTraceDiagnosticsErrorKind,
497 message: TrimmedNonEmptyString,
498 }),
499 ),
500});
501export type ServerTraceDiagnosticsResult = typeof ServerTraceDiagnosticsResult.Type;
502
503export const ServerProcessSignal = Schema.Literals(["SIGINT", "SIGKILL"]);
504export type ServerProcessSignal = typeof ServerProcessSignal.Type;
505
506export const ServerProcessDiagnosticsEntry = Schema.Struct({
507 pid: PositiveInt,
508 startTimeMs: NonNegativeInt,
509 ppid: NonNegativeInt,
510 pgid: Schema.Option(Schema.Int),
511 status: TrimmedNonEmptyString,
512 cpuPercent: Schema.Number,
513 rssBytes: NonNegativeInt,
514 elapsed: TrimmedNonEmptyString,
515 command: TrimmedNonEmptyString,
516 depth: NonNegativeInt,
517 childPids: Schema.Array(PositiveInt),
518});
519export type ServerProcessDiagnosticsEntry = typeof ServerProcessDiagnosticsEntry.Type;
520
521export const ServerProcessDiagnosticsResult = Schema.Struct({
522 serverPid: PositiveInt,
523 readAt: Schema.DateTimeUtc,
524 processCount: NonNegativeInt,
525 totalRssBytes: NonNegativeInt,
526 totalCpuPercent: Schema.Number,
527 processes: Schema.Array(ServerProcessDiagnosticsEntry),
528 error: Schema.Option(
529 Schema.Struct({
530 message: TrimmedNonEmptyString,
531 }),
532 ),
533});
534export type ServerProcessDiagnosticsResult = typeof ServerProcessDiagnosticsResult.Type;
535
536export const ServerProcessResourceHistoryInput = Schema.Struct({
537 windowMs: NonNegativeInt,
538 bucketMs: NonNegativeInt,
539});
540export type ServerProcessResourceHistoryInput = typeof ServerProcessResourceHistoryInput.Type;
541
542export const ServerProcessResourceHistoryBucket = Schema.Struct({
543 startedAt: Schema.DateTimeUtc,
544 endedAt: Schema.DateTimeUtc,
545 avgCpuPercent: Schema.Number,
546 maxCpuPercent: Schema.Number,
547 maxRssBytes: NonNegativeInt,
548 maxProcessCount: NonNegativeInt,
549});
550export type ServerProcessResourceHistoryBucket = typeof ServerProcessResourceHistoryBucket.Type;
551
552export const ServerProcessResourceHistorySummary = Schema.Struct({
553 processKey: TrimmedNonEmptyString,
554 pid: PositiveInt,
555 ppid: NonNegativeInt,
556 command: TrimmedNonEmptyString,
557 depth: NonNegativeInt,
558 isServerRoot: Schema.Boolean,
559 firstSeenAt: Schema.DateTimeUtc,
560 lastSeenAt: Schema.DateTimeUtc,
561 currentCpuPercent: Schema.Number,
562 avgCpuPercent: Schema.Number,
563 maxCpuPercent: Schema.Number,
564 cpuSecondsApprox: Schema.Number,
565 currentRssBytes: NonNegativeInt,
566 maxRssBytes: NonNegativeInt,
567 sampleCount: NonNegativeInt,
568});
569export type ServerProcessResourceHistorySummary = typeof ServerProcessResourceHistorySummary.Type;
570
571export const ServerProcessResourceHistoryFailureTag = Schema.Literals([
572 "ProcessDiagnosticsQueryTimeoutError",
573 "ProcessDiagnosticsQueryFailedError",
574 "ProcessDiagnosticsServerProcessSignalError",
575 "ProcessDiagnosticsNotDescendantError",
576 "ProcessDiagnosticsSignalFailedError",
577]);
578export type ServerProcessResourceHistoryFailureTag =
579 typeof ServerProcessResourceHistoryFailureTag.Type;
580
581export const ServerProcessResourceHistoryResult = Schema.Struct({
582 readAt: Schema.DateTimeUtc,
583 windowMs: NonNegativeInt,
584 bucketMs: NonNegativeInt,
585 sampleIntervalMs: NonNegativeInt,
586 retainedSampleCount: NonNegativeInt,
587 totalCpuSecondsApprox: Schema.Number,
588 buckets: Schema.Array(ServerProcessResourceHistoryBucket),
589 topProcesses: Schema.Array(ServerProcessResourceHistorySummary),
590 error: Schema.Option(
591 Schema.Struct({
592 failureTag: ServerProcessResourceHistoryFailureTag,
593 message: TrimmedNonEmptyString,
594 }),
595 ),
596});
597export type ServerProcessResourceHistoryResult = typeof ServerProcessResourceHistoryResult.Type;
598
599export const ServerSignalProcessInput = Schema.Struct({
600 pid: PositiveInt,
601 startTimeMs: NonNegativeInt,
602 signal: ServerProcessSignal,
603});
604export type ServerSignalProcessInput = typeof ServerSignalProcessInput.Type;
605
606export const ServerSignalProcessResult = Schema.Struct({
607 pid: PositiveInt,
608 signal: ServerProcessSignal,
609 signaled: Schema.Boolean,
610 message: Schema.Option(TrimmedNonEmptyString),
611});
612export type ServerSignalProcessResult = typeof ServerSignalProcessResult.Type;
613
614export const EnvironmentThemeColor = Schema.String.check(
615 Schema.isPattern(/^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/),
616);
617export type EnvironmentThemeColor = typeof EnvironmentThemeColor.Type;
618
619/** Reserve appearance keywords so published themes cannot replace stock preferences. */
620export const EnvironmentThemeId = Schema.String.check(
621 Schema.isPattern(/^(?!(?:system|light|dark)$)[a-z0-9](?:[a-z0-9-]{0,47})$/),
622);
623export type EnvironmentThemeId = typeof EnvironmentThemeId.Type;
624
625const EnvironmentThemeColors = Schema.Record(
626 Schema.String.check(Schema.isPattern(/^[a-zA-Z][a-zA-Z0-9]{0,63}$/)),
627 TrimmedNonEmptyString.check(Schema.isMaxLength(64)),
628);
629
630export const THEME_CSS_MAX_LENGTH = 100_000;
631
632const environmentThemeFields = {
633 version: Schema.optional(Schema.Literal(1)),
634 name: TrimmedNonEmptyString.check(Schema.isMaxLength(48)),
635 appearance: Schema.Literals(["light", "dark"]),
636 /** Derive the palette from canvas/accent, then overlay colors; without them, colors is the palette. */
637 canvas: Schema.optional(EnvironmentThemeColor),
638 accent: Schema.optional(EnvironmentThemeColor),
639 colors: Schema.optional(EnvironmentThemeColors),
640 variants: Schema.optional(
641 Schema.Struct({
642 light: Schema.optional(EnvironmentThemeColors),
643 dark: Schema.optional(EnvironmentThemeColors),
644 }),
645 ),
646 /** Custom styles for web and desktop clients. */
647 css: Schema.optional(Schema.String.check(Schema.isMaxLength(THEME_CSS_MAX_LENGTH))),
648};
649
650export const EnvironmentThemeFile = Schema.Struct(environmentThemeFields);
651export type EnvironmentThemeFile = typeof EnvironmentThemeFile.Type;
652
653export const EnvironmentTheme = Schema.Struct({
654 id: EnvironmentThemeId,
655 ...environmentThemeFields,
656 /** Revision of the image file published beside the theme; absent without one. */
657 background: Schema.optional(TrimmedNonEmptyString.check(Schema.isMaxLength(64))),
658});
659export type EnvironmentTheme = typeof EnvironmentTheme.Type;
660
661export function environmentThemeFileHasColors(file: EnvironmentThemeFile): boolean {
662 return (
663 (file.canvas !== undefined && file.accent !== undefined) ||
664 (file.colors !== undefined && Object.keys(file.colors).length > 0)
665 );
666}
667
668/** tailnet means this machine's Tailscale interface; other private addresses are lan. */
669export const ServerDirectEndpointKind = Schema.Literals(["lan", "tailnet"]);
670export type ServerDirectEndpointKind = typeof ServerDirectEndpointKind.Type;
671
672export const ServerDirectEndpoint = Schema.Struct({
673 kind: ServerDirectEndpointKind,
674 httpBaseUrl: TrimmedNonEmptyString,
675});
676export type ServerDirectEndpoint = typeof ServerDirectEndpoint.Type;
677
678/**
679 * A stretch where the server's event loop could not run, so it answered
680 * nothing and clients may have dropped the connection.
681 */
682export const ServerEventLoopStall = Schema.Struct({
683 detectedAt: IsoDateTime,
684 durationMs: NonNegativeInt,
685 /** One-minute load average when the stall was seen. Absent on Windows, which has none. */
686 loadAverage: Schema.optionalKey(Schema.Number),
687 cpuCount: PositiveInt,
688});
689export type ServerEventLoopStall = typeof ServerEventLoopStall.Type;
690
691export const ServerConfig = Schema.Struct({
692 environment: ExecutionEnvironmentDescriptor,
693 auth: ServerAuthDescriptor,
694 cwd: TrimmedNonEmptyString,
695 /** The machine's own name, which file URIs from its shells may carry. Older servers omit it. */
696 hostname: Schema.optionalKey(Schema.String),
697 keybindingsConfigPath: TrimmedNonEmptyString,
698 keybindings: ResolvedKeybindingsConfig,
699 issues: ServerConfigIssues,
700 providers: ServerProviders,
701 availableEditors: ForwardCompatibleArray(EditorId),
702 remoteOpenTargets: Schema.optionalKey(ForwardCompatibleArray(RemoteOpenTarget)),
703 /** Hints only; verify each address answers as this environment. */
704 directEndpoints: Schema.optionalKey(ForwardCompatibleArray(ServerDirectEndpoint)),
705 observability: ServerObservability,
706 settings: ServerSettings,
707 /** Present when an administrator's policy file manages this environment. */
708 managedPolicy: Schema.optionalKey(ManagedPolicySummary),
709 shellResumeCompletionMarker: Schema.optionalKey(Schema.Boolean),
710 /**
711 * The shell can leave idle subagent children out of snapshots (`omitIdleSubagents`), and
712 * `getThreadFamily` and `getWorktreeThreadIds` serve the rows it leaves out.
713 */
714 shellThreadFamilies: Schema.optionalKey(Schema.Boolean),
715 threadLinkMetadata: Schema.optionalKey(Schema.Boolean),
716 /**
717 * The shell can leave older settled threads out of snapshots (`omitOlderSettled`), and
718 * `getOlderSettledThreads` serves them. Only servers that also advertise `shellThreadFamilies`.
719 */
720 shellOlderSettled: Schema.optionalKey(Schema.Boolean),
721 shellRevealInFileManager: Schema.optionalKey(Schema.Boolean),
722 shellRevealInFileManagerKind: Schema.optionalKey(FileManagerRevealKind),
723 threadResumeCompletionMarker: Schema.optionalKey(Schema.Boolean),
724 /** Send window fields only when advertised. */
725 threadSnapshotPagination: Schema.optionalKey(Schema.Boolean),
726 threadFind: Schema.optionalKey(Schema.Boolean),
727 threadFindProgressive: Schema.optionalKey(Schema.Boolean),
728 /** Settings patches may carry `secretProviders`; older servers drop the key without an error. */
729 secretProviderSettings: Schema.optionalKey(Schema.Boolean),
730 /** Secret settings may point at a secret provider; older servers drop the reference. */
731 secretReferences: Schema.optionalKey(Schema.Boolean),
732 /** A secret request card may be answered with a secret provider reference. */
733 secretRequestReferences: Schema.optionalKey(Schema.Boolean),
734 scratchWorkspaceRoot: Schema.optionalKey(TrimmedNonEmptyString),
735 newProjectsRoot: Schema.optionalKey(TrimmedNonEmptyString),
736 /**
737 * The latest stall long enough to notice, sent only for a few minutes after
738 * it. A client that reconnects reads it to say why the host stopped
739 * answering. Clients do not cache it, since it describes the host at connect.
740 */
741 lastEventLoopStall: Schema.optionalKey(ServerEventLoopStall),
742 /**
743 * The host's clock when it built the config, so clients can count live
744 * elapsed times against host timestamps despite clock skew. Only a
745 * subscription's first snapshot is fresh; later snapshots may repeat it.
746 */
747 serverTime: Schema.optionalKey(IsoDateTime),
748 /**
749 * Never sent in a config snapshot: the theme stream emits the current set
750 * before any change, so a snapshot carrying it too would hand every
751 * subscriber the same array twice per connect.
752 */
753 environmentThemes: Schema.optional(Schema.Array(EnvironmentTheme)),
754 /** Stream-only and opt-in; the source stream emits the current set on subscribe. */
755 usageLimitSources: Schema.optional(UsageLimitSourceSnapshots),
756});
757export type ServerConfig = typeof ServerConfig.Type;
758
759export function resolveEnvironmentMachineKind(
760 config: {
761 readonly environment: Pick<ExecutionEnvironmentDescriptor, "platform">;
762 readonly settings?: Pick<ServerSettings, "environmentIcon">;
763 } | null,
764): EnvironmentMachineKind {
765 return config?.settings?.environmentIcon ?? config?.environment.platform.machine ?? "server";
766}
767
768const ServerUpsertKeybindingReplaceTarget = Schema.Struct({
769 key: KeybindingValue,
770 command: KeybindingCommand,
771 when: Schema.optional(KeybindingWhen),
772});
773
774export const ServerUpsertKeybindingInput = Schema.Struct({
775 key: KeybindingValue,
776 command: KeybindingCommand,
777 when: Schema.optional(KeybindingWhen),
778 replace: Schema.optional(ServerUpsertKeybindingReplaceTarget),
779});
780export type ServerUpsertKeybindingInput = typeof ServerUpsertKeybindingInput.Type;
781
782export const ServerRemoveKeybindingInput = ServerUpsertKeybindingReplaceTarget;
783export type ServerRemoveKeybindingInput = typeof ServerRemoveKeybindingInput.Type;
784
785export const ServerUpsertKeybindingResult = Schema.Struct({
786 keybindings: ResolvedKeybindingsConfig,
787 issues: ServerConfigIssues,
788});
789export type ServerUpsertKeybindingResult = typeof ServerUpsertKeybindingResult.Type;
790
791export const ServerRemoveKeybindingResult = ServerUpsertKeybindingResult;
792export type ServerRemoveKeybindingResult = typeof ServerRemoveKeybindingResult.Type;
793
794export const ServerConfigUpdatedPayload = Schema.Struct({
795 issues: ServerConfigIssues,
796 providers: ServerProviders,
797 settings: Schema.optional(ServerSettings),
798});
799export type ServerConfigUpdatedPayload = typeof ServerConfigUpdatedPayload.Type;
800
801export const ServerConfigKeybindingsUpdatedPayload = Schema.Struct({
802 keybindings: ResolvedKeybindingsConfig,
803 issues: ServerConfigIssues,
804});
805export type ServerConfigKeybindingsUpdatedPayload =
806 typeof ServerConfigKeybindingsUpdatedPayload.Type;
807
808export const ServerConfigProviderStatusesPayload = Schema.Struct({
809 providers: ServerProviders,
810});
811export type ServerConfigProviderStatusesPayload = typeof ServerConfigProviderStatusesPayload.Type;
812
813export const ServerConfigProviderStatusDeltasPayload = Schema.Struct({
814 /** Every provider in order, as `serverProviderDeltas` from the list this client last received. */
815 providers: ForwardCompatibleArray(ServerProviderDelta),
816});
817export type ServerConfigProviderStatusDeltasPayload =
818 typeof ServerConfigProviderStatusDeltasPayload.Type;
819
820export const ServerConfigSettingsUpdatedPayload = Schema.Struct({
821 settings: ServerSettings,
822});
823export type ServerConfigSettingsUpdatedPayload = typeof ServerConfigSettingsUpdatedPayload.Type;
824
825export const ServerConfigStreamSnapshotEvent = Schema.Struct({
826 version: Schema.Literal(1),
827 type: Schema.Literal("snapshot"),
828 config: ServerConfig,
829});
830export type ServerConfigStreamSnapshotEvent = typeof ServerConfigStreamSnapshotEvent.Type;
831
832export const ServerConfigStreamKeybindingsUpdatedEvent = Schema.Struct({
833 version: Schema.Literal(1),
834 type: Schema.Literal("keybindingsUpdated"),
835 payload: ServerConfigKeybindingsUpdatedPayload,
836});
837export type ServerConfigStreamKeybindingsUpdatedEvent =
838 typeof ServerConfigStreamKeybindingsUpdatedEvent.Type;
839
840export const ServerConfigStreamProviderStatusesEvent = Schema.Struct({
841 version: Schema.Literal(1),
842 type: Schema.Literal("providerStatuses"),
843 payload: ServerConfigProviderStatusesPayload,
844});
845export type ServerConfigStreamProviderStatusesEvent =
846 typeof ServerConfigStreamProviderStatusesEvent.Type;
847
848export const ServerConfigStreamProviderStatusDeltasEvent = Schema.Struct({
849 version: Schema.Literal(1),
850 type: Schema.Literal("providerStatusDeltas"),
851 payload: ServerConfigProviderStatusDeltasPayload,
852});
853export type ServerConfigStreamProviderStatusDeltasEvent =
854 typeof ServerConfigStreamProviderStatusDeltasEvent.Type;
855
856export const ServerConfigStreamSettingsUpdatedEvent = Schema.Struct({
857 version: Schema.Literal(1),
858 type: Schema.Literal("settingsUpdated"),
859 payload: ServerConfigSettingsUpdatedPayload,
860});
861export type ServerConfigStreamSettingsUpdatedEvent =
862 typeof ServerConfigStreamSettingsUpdatedEvent.Type;
863
864export const ServerConfigEnvironmentThemesUpdatedPayload = Schema.Struct({
865 themes: Schema.Array(EnvironmentTheme),
866});
867export type ServerConfigEnvironmentThemesUpdatedPayload =
868 typeof ServerConfigEnvironmentThemesUpdatedPayload.Type;
869
870export const ServerConfigStreamEnvironmentThemesUpdatedEvent = Schema.Struct({
871 version: Schema.Literal(1),
872 type: Schema.Literal("environmentThemesUpdated"),
873 payload: ServerConfigEnvironmentThemesUpdatedPayload,
874});
875export type ServerConfigStreamEnvironmentThemesUpdatedEvent =
876 typeof ServerConfigStreamEnvironmentThemesUpdatedEvent.Type;
877
878export const ServerConfigUsageLimitSourcesUpdatedPayload = Schema.Struct({
879 sources: UsageLimitSourceSnapshots,
880});
881export type ServerConfigUsageLimitSourcesUpdatedPayload =
882 typeof ServerConfigUsageLimitSourcesUpdatedPayload.Type;
883
884export const ServerConfigStreamUsageLimitSourcesUpdatedEvent = Schema.Struct({
885 version: Schema.Literal(1),
886 type: Schema.Literal("usageLimitSourcesUpdated"),
887 payload: ServerConfigUsageLimitSourcesUpdatedPayload,
888});
889export type ServerConfigStreamUsageLimitSourcesUpdatedEvent =
890 typeof ServerConfigStreamUsageLimitSourcesUpdatedEvent.Type;
891
892export const ServerConfigStreamEvent = Schema.Union([
893 ServerConfigStreamSnapshotEvent,
894 ServerConfigStreamKeybindingsUpdatedEvent,
895 ServerConfigStreamProviderStatusesEvent,
896 ServerConfigStreamProviderStatusDeltasEvent,
897 ServerConfigStreamSettingsUpdatedEvent,
898 ServerConfigStreamEnvironmentThemesUpdatedEvent,
899 ServerConfigStreamUsageLimitSourcesUpdatedEvent,
900]);
901export type ServerConfigStreamEvent = typeof ServerConfigStreamEvent.Type;
902
903export const ServerSelfUpdateOutcome = Schema.Struct({
904 id: TrimmedNonEmptyString,
905 fromVersion: TrimmedNonEmptyString,
906 targetVersion: TrimmedNonEmptyString,
907 status: Schema.Literals(["committed", "rolled-back", "failed"]),
908 reason: Schema.optionalKey(TrimmedNonEmptyString),
909});
910export type ServerSelfUpdateOutcome = typeof ServerSelfUpdateOutcome.Type;
911
912export const ServerLifecycleReadyPayload = Schema.Struct({
913 at: IsoDateTime,
914 environment: ExecutionEnvironmentDescriptor,
915 updateOutcome: Schema.optionalKey(ServerSelfUpdateOutcome),
916});
917export type ServerLifecycleReadyPayload = typeof ServerLifecycleReadyPayload.Type;
918
919export const ServerLifecycleWelcomePayload = Schema.Struct({
920 environment: ExecutionEnvironmentDescriptor,
921 cwd: TrimmedNonEmptyString,
922 projectName: TrimmedNonEmptyString,
923 bootstrapStatus: Schema.optional(Schema.Literals(["pending", "complete"])),
924 bootstrapProjectId: Schema.optional(ProjectId),
925 bootstrapThreadId: Schema.optional(ThreadId),
926 bootstrapProjectCreated: Schema.optional(Schema.Boolean),
927 bootstrapThreadCreated: Schema.optional(Schema.Boolean),
928});
929export type ServerLifecycleWelcomePayload = typeof ServerLifecycleWelcomePayload.Type;
930
931export const ServerLifecycleLegacyThreadMigrationPayload = Schema.Struct({
932 status: Schema.Union([Schema.Literal("running"), Schema.Literal("complete")]),
933 totalThreadCount: NonNegativeInt,
934});
935export type ServerLifecycleLegacyThreadMigrationPayload =
936 typeof ServerLifecycleLegacyThreadMigrationPayload.Type;
937
938export const ServerLifecycleStreamWelcomeEvent = Schema.Struct({
939 version: Schema.Literal(1),
940 sequence: NonNegativeInt,
941 type: Schema.Literal("welcome"),
942 payload: ServerLifecycleWelcomePayload,
943});
944export type ServerLifecycleStreamWelcomeEvent = typeof ServerLifecycleStreamWelcomeEvent.Type;
945
946export const ServerLifecycleStreamReadyEvent = Schema.Struct({
947 version: Schema.Literal(1),
948 sequence: NonNegativeInt,
949 type: Schema.Literal("ready"),
950 payload: ServerLifecycleReadyPayload,
951});
952export type ServerLifecycleStreamReadyEvent = typeof ServerLifecycleStreamReadyEvent.Type;
953
954export const ServerLifecycleStreamLegacyThreadMigrationEvent = Schema.Struct({
955 version: Schema.Literal(1),
956 sequence: NonNegativeInt,
957 type: Schema.Literal("legacyThreadMigration"),
958 payload: ServerLifecycleLegacyThreadMigrationPayload,
959});
960export type ServerLifecycleStreamLegacyThreadMigrationEvent =
961 typeof ServerLifecycleStreamLegacyThreadMigrationEvent.Type;
962
963export const ServerLifecycleStreamEvent = Schema.Union([
964 ServerLifecycleStreamWelcomeEvent,
965 ServerLifecycleStreamReadyEvent,
966 ServerLifecycleStreamLegacyThreadMigrationEvent,
967]);
968export type ServerLifecycleStreamEvent = typeof ServerLifecycleStreamEvent.Type;
969
970export const ServerProviderUpdatedPayload = Schema.Struct({
971 providers: ServerProviders,
972});
973export type ServerProviderUpdatedPayload = typeof ServerProviderUpdatedPayload.Type;
974
975export const ServerProviderUpdateInput = Schema.Struct({
976 provider: ProviderDriverKind,
977 targetVersion: Schema.optionalKey(TrimmedNonEmptyString),
978 instanceId: Schema.optionalKey(ProviderInstanceId),
979});
980export type ServerProviderUpdateInput = typeof ServerProviderUpdateInput.Type;
981
982export class ServerProviderUpdateError extends Schema.TaggedError<ServerProviderUpdateError>()(
983 "ServerProviderUpdateError",
984 {
985 provider: ProviderDriverKind,
986 reason: TrimmedNonEmptyString,
987 cause: Schema.optional(Schema.Defect()),
988 },
989) {
990 override get message(): string {
991 return `Provider update failed for ${this.provider}: ${this.reason}`;
992 }
993}
994
995export const ServerNpmReleaseInput = Schema.Struct({
996 spec: Schema.String.check(
997 Schema.isMaxLength(64),
998 Schema.isPattern(/^(?:latest|nightly|\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?)$/),
999 ),
1000});
1001export type ServerNpmReleaseInput = typeof ServerNpmReleaseInput.Type;
1002
1003export const ServerNpmRelease = Schema.Struct({
1004 version: Schema.String,
1005 databaseMigration: Schema.optionalKey(Schema.Int),
1006});
1007export type ServerNpmRelease = typeof ServerNpmRelease.Type;
1008
1009export class ServerNpmReleaseError extends Schema.TaggedError<ServerNpmReleaseError>()(
1010 "ServerNpmReleaseError",
1011 { reason: Schema.String },
1012) {
1013 override get message(): string {
1014 return `Could not check the configured npm registry: ${this.reason}`;
1015 }
1016}
1017
1018export const ServerSelfUpdateInput = Schema.Struct({
1019 /** Exact npm version, never a dist-tag, so server and client agree on the request. */
1020 targetVersion: TrimmedNonEmptyString,
1021 /** Desktop-managed hosts move their app to this update track first. Sent only for a track switch. */
1022 channel: Schema.optionalKey(DesktopUpdateChannelSchema),
1023 /** The target release's highest migration; the host refuses to leave Nightly without it. */
1024 targetDatabaseMigration: Schema.optionalKey(Schema.Int),
1025 stageOnly: Schema.optionalKey(Schema.Boolean),
1026});
1027export type ServerSelfUpdateInput = typeof ServerSelfUpdateInput.Type;
1028
1029export const ServerSelfUpdateResult = Schema.Struct({
1030 targetVersion: TrimmedNonEmptyString,
1031 method: ServerSelfUpdateMethod,
1032 updateId: Schema.optionalKey(TrimmedNonEmptyString),
1033 desktopUpdateToken: Schema.optionalKey(TrimmedNonEmptyString),
1034});
1035export type ServerSelfUpdateResult = typeof ServerSelfUpdateResult.Type;
1036
1037export const DesktopUpdateCommitInput = Schema.Struct({
1038 requestId: TrimmedNonEmptyString,
1039});
1040export type DesktopUpdateCommitInput = typeof DesktopUpdateCommitInput.Type;
1041
1042export const ServerSelfUpdateProgressStage = Schema.Literals(["downloading", "installing"]);
1043export type ServerSelfUpdateProgressStage = typeof ServerSelfUpdateProgressStage.Type;
1044
1045export const ServerSelfUpdateProgressEvent = Schema.Union([
1046 Schema.Struct({
1047 type: Schema.Literal("progress"),
1048 stage: ServerSelfUpdateProgressStage,
1049 }),
1050 Schema.Struct({
1051 type: Schema.Literal("complete"),
1052 result: ServerSelfUpdateResult,
1053 }),
1054]);
1055export type ServerSelfUpdateProgressEvent = typeof ServerSelfUpdateProgressEvent.Type;
1056
1057export class ServerSelfUpdateError extends Schema.TaggedError<ServerSelfUpdateError>()(
1058 "ServerSelfUpdateError",
1059 {
1060 reason: TrimmedNonEmptyString,
1061 cause: Schema.optional(Schema.Defect()),
1062 },
1063) {
1064 override get message(): string {
1065 return `Server update failed: ${this.reason}`;
1066 }
1067}