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