Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

server.ts

1,065 lines42.4 KB

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