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

server.ts

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