Open History to see the last commit
1import * as Effect from "effect/Effect";
2import * as Schema from "effect/Schema";
3import { ExecutionEnvironmentDescriptor, ServerSelfUpdateMethod } from "./environment.ts";
4import { ServerAuthDescriptor } from "./auth.ts";
5import {
6 ForwardCompatibleArray,
7 IsoDateTime,
8 NonNegativeInt,
9 PositiveInt,
10 ProjectId,
11 ThreadId,
12 TrimmedNonEmptyString,
13} from "./baseSchemas.ts";
14import {
15 KeybindingCommand,
16 KeybindingValue,
17 KeybindingWhen,
18 ResolvedKeybindingsConfig,
19} from "./keybindings.ts";
20import { EditorId, RemoteOpenTarget } from "./editor.ts";
21import { ModelCapabilities } from "./model.ts";
22import { ProviderDriverKind, ProviderInstanceId } from "./providerInstance.ts";
23import { ServerSettings } from "./settings.ts";
24
25const KeybindingsMalformedConfigIssue = Schema.Struct({
26 kind: Schema.Literal("keybindings.malformed-config"),
27 message: TrimmedNonEmptyString,
28});
29
30const KeybindingsInvalidEntryIssue = Schema.Struct({
31 kind: Schema.Literal("keybindings.invalid-entry"),
32 message: TrimmedNonEmptyString,
33 index: Schema.Number,
34});
35
36export const ServerConfigIssue = Schema.Union([
37 KeybindingsMalformedConfigIssue,
38 KeybindingsInvalidEntryIssue,
39]);
40export type ServerConfigIssue = typeof ServerConfigIssue.Type;
41
42// Issue kinds grow over time; older clients must not fail the whole config
43// decode over a kind they cannot render.
44const ServerConfigIssues = ForwardCompatibleArray(ServerConfigIssue);
45
46export const ServerProviderState = Schema.Literals(["ready", "warning", "error", "disabled"]);
47export type ServerProviderState = typeof ServerProviderState.Type;
48
49export const ServerProviderAuthStatus = Schema.Literals([
50 "authenticated",
51 "unauthenticated",
52 "unknown",
53]);
54export type ServerProviderAuthStatus = typeof ServerProviderAuthStatus.Type;
55
56export const ServerProviderAuth = Schema.Struct({
57 status: ServerProviderAuthStatus,
58 type: Schema.optional(TrimmedNonEmptyString),
59 label: Schema.optional(TrimmedNonEmptyString),
60 email: Schema.optional(TrimmedNonEmptyString),
61});
62export type ServerProviderAuth = typeof ServerProviderAuth.Type;
63
64export const ServerProviderModel = Schema.Struct({
65 slug: TrimmedNonEmptyString,
66 name: TrimmedNonEmptyString,
67 shortName: Schema.optional(TrimmedNonEmptyString),
68 subProvider: Schema.optional(TrimmedNonEmptyString),
69 isCustom: Schema.Boolean,
70 isDefault: Schema.optional(Schema.Boolean),
71 isLegacy: Schema.optional(Schema.Boolean),
72 capabilities: Schema.NullOr(ModelCapabilities),
73});
74export type ServerProviderModel = typeof ServerProviderModel.Type;
75
76export const ServerProviderSlashCommandInput = Schema.Struct({
77 hint: TrimmedNonEmptyString,
78});
79export type ServerProviderSlashCommandInput = typeof ServerProviderSlashCommandInput.Type;
80
81export const ServerProviderSlashCommand = Schema.Struct({
82 name: TrimmedNonEmptyString,
83 description: Schema.optional(TrimmedNonEmptyString),
84 input: Schema.optional(ServerProviderSlashCommandInput),
85});
86export type ServerProviderSlashCommand = typeof ServerProviderSlashCommand.Type;
87
88export const ServerProviderSkill = Schema.Struct({
89 name: TrimmedNonEmptyString,
90 description: Schema.optional(TrimmedNonEmptyString),
91 path: TrimmedNonEmptyString,
92 scope: Schema.optional(TrimmedNonEmptyString),
93 enabled: Schema.Boolean,
94 displayName: Schema.optional(TrimmedNonEmptyString),
95 shortDescription: Schema.optional(TrimmedNonEmptyString),
96});
97export type ServerProviderSkill = typeof ServerProviderSkill.Type;
98
99/**
100 * Availability of a configured provider instance from the runtime's POV.
101 *
102 * - `available` — the build ships this driver and an instance is wired
103 * up. Default for legacy snapshots produced from the closed
104 * `ServerSettings.providers` map.
105 * - `unavailable` — the user's `ServerSettings.providerInstances` (or a
106 * persisted thread / session binding) references a driver this build
107 * doesn't ship. Common after rolling back from a fork or PR branch
108 * that introduced a new driver. The snapshot is preserved so the UI
109 * can render "missing driver" affordances and so the data round-trips
110 * when the user moves back to the fork.
111 *
112 * Snapshots with `availability: "unavailable"` MUST set
113 * `installed: false` and `enabled: false`; the runtime refuses turn
114 * starts against them with a structured error.
115 */
116export const ServerProviderAvailability = Schema.Literals(["available", "unavailable"]);
117export type ServerProviderAvailability = typeof ServerProviderAvailability.Type;
118
119export const ServerProviderContinuation = Schema.Struct({
120 groupKey: TrimmedNonEmptyString,
121});
122export type ServerProviderContinuation = typeof ServerProviderContinuation.Type;
123
124export const ServerProviderVersionAdvisoryStatus = Schema.Literals([
125 "unknown",
126 "current",
127 "behind_latest",
128]);
129export type ServerProviderVersionAdvisoryStatus = typeof ServerProviderVersionAdvisoryStatus.Type;
130
131export const ServerProviderVersionAdvisory = Schema.Struct({
132 status: ServerProviderVersionAdvisoryStatus,
133 currentVersion: Schema.NullOr(TrimmedNonEmptyString),
134 latestVersion: Schema.NullOr(TrimmedNonEmptyString),
135 updateCommand: Schema.NullOr(TrimmedNonEmptyString),
136 canUpdate: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(false))),
137 checkedAt: Schema.NullOr(IsoDateTime),
138 message: Schema.NullOr(TrimmedNonEmptyString),
139});
140export type ServerProviderVersionAdvisory = typeof ServerProviderVersionAdvisory.Type;
141
142export const ServerProviderUpdateStatus = Schema.Literals([
143 "idle",
144 "queued",
145 "running",
146 "succeeded",
147 "failed",
148 "unchanged",
149]);
150export type ServerProviderUpdateStatus = typeof ServerProviderUpdateStatus.Type;
151
152export const ServerProviderUpdateState = Schema.Struct({
153 status: ServerProviderUpdateStatus,
154 startedAt: Schema.NullOr(IsoDateTime),
155 finishedAt: Schema.NullOr(IsoDateTime),
156 message: Schema.NullOr(TrimmedNonEmptyString),
157 output: Schema.NullOr(Schema.String.check(Schema.isMaxLength(10_000))),
158});
159export type ServerProviderUpdateState = typeof ServerProviderUpdateState.Type;
160
161export const ServerProvider = Schema.Struct({
162 // Routing key for the configured instance this snapshot represents. This
163 // is the only stable identity consumers may use for provider routing.
164 instanceId: ProviderInstanceId,
165 // Open driver kind slug that selects the implementation handling this
166 // instance. It is metadata/capability context, not a routing key.
167 driver: ProviderDriverKind,
168 displayName: Schema.optional(TrimmedNonEmptyString),
169 accentColor: Schema.optional(TrimmedNonEmptyString),
170 badgeLabel: Schema.optional(TrimmedNonEmptyString),
171 continuation: Schema.optional(ServerProviderContinuation),
172 showInteractionModeToggle: Schema.optional(Schema.Boolean),
173 requiresNewThreadForModelChange: Schema.optional(Schema.Boolean),
174 enabled: Schema.Boolean,
175 installed: Schema.Boolean,
176 version: Schema.NullOr(TrimmedNonEmptyString),
177 status: ServerProviderState,
178 auth: ServerProviderAuth,
179 checkedAt: IsoDateTime,
180 message: Schema.optional(TrimmedNonEmptyString),
181 // Optional for back-compat: every legacy producer omits this field and
182 // an absent value is interpreted as `"available"` by consumers (see
183 // `isProviderAvailable`). New `ProviderInstanceRegistry` outputs set it
184 // explicitly so the UI can render unavailable shadows from
185 // `ServerSettings.providerInstances`.
186 availability: Schema.optional(ServerProviderAvailability),
187 // Human-readable reason populated when `availability === "unavailable"`.
188 // Surfaces in the UI alongside the missing-driver affordance.
189 unavailableReason: Schema.optional(TrimmedNonEmptyString),
190 models: Schema.Array(ServerProviderModel),
191 slashCommands: Schema.Array(ServerProviderSlashCommand).pipe(
192 Schema.withDecodingDefault(Effect.succeed([])),
193 ),
194 skills: Schema.Array(ServerProviderSkill).pipe(Schema.withDecodingDefault(Effect.succeed([]))),
195 versionAdvisory: Schema.optionalKey(ServerProviderVersionAdvisory),
196 updateState: Schema.optionalKey(ServerProviderUpdateState),
197});
198export type ServerProvider = typeof ServerProvider.Type;
199
200// Provider status kinds grow over time (ServerProviderState,
201// ServerProviderAuthStatus, ServerProviderVersionAdvisoryStatus,
202// ServerProviderUpdateStatus); an older client must not fail the whole config
203// decode over one provider it cannot render.
204export const ServerProviders = ForwardCompatibleArray(ServerProvider);
205export type ServerProviders = typeof ServerProviders.Type;
206
207/**
208 * Treat the optional `availability` as "available" when absent. This is
209 * the rule legacy producers (which omit the field) and new producers
210 * (which set it explicitly) agree on so consumers never have to thread
211 * `?? "available"` defaults through their code paths.
212 */
213export const isProviderAvailable = (snapshot: ServerProvider): boolean =>
214 snapshot.availability !== "unavailable";
215
216export const ServerObservability = Schema.Struct({
217 logsDirectoryPath: TrimmedNonEmptyString,
218 localTracingEnabled: Schema.Boolean,
219 otlpTracesUrl: Schema.optional(TrimmedNonEmptyString),
220 otlpTracesEnabled: Schema.Boolean,
221 otlpMetricsUrl: Schema.optional(TrimmedNonEmptyString),
222 otlpMetricsEnabled: Schema.Boolean,
223});
224export type ServerObservability = typeof ServerObservability.Type;
225
226export const ServerTraceDiagnosticsErrorKind = Schema.Literals([
227 "trace-file-not-found",
228 "trace-file-read-failed",
229]);
230export type ServerTraceDiagnosticsErrorKind = typeof ServerTraceDiagnosticsErrorKind.Type;
231
232export const ServerTraceDiagnosticsSpanSummary = Schema.Struct({
233 name: TrimmedNonEmptyString,
234 count: NonNegativeInt,
235 failureCount: NonNegativeInt,
236 totalDurationMs: Schema.Number,
237 averageDurationMs: Schema.Number,
238 maxDurationMs: Schema.Number,
239});
240export type ServerTraceDiagnosticsSpanSummary = typeof ServerTraceDiagnosticsSpanSummary.Type;
241
242export const ServerTraceDiagnosticsFailureSummary = Schema.Struct({
243 name: TrimmedNonEmptyString,
244 cause: TrimmedNonEmptyString,
245 count: NonNegativeInt,
246 lastSeenAt: Schema.DateTimeUtc,
247 traceId: TrimmedNonEmptyString,
248 spanId: TrimmedNonEmptyString,
249});
250export type ServerTraceDiagnosticsFailureSummary = typeof ServerTraceDiagnosticsFailureSummary.Type;
251
252export const ServerTraceDiagnosticsRecentFailure = Schema.Struct({
253 name: TrimmedNonEmptyString,
254 cause: TrimmedNonEmptyString,
255 durationMs: Schema.Number,
256 endedAt: Schema.DateTimeUtc,
257 traceId: TrimmedNonEmptyString,
258 spanId: TrimmedNonEmptyString,
259});
260export type ServerTraceDiagnosticsRecentFailure = typeof ServerTraceDiagnosticsRecentFailure.Type;
261
262export const ServerTraceDiagnosticsSpanOccurrence = Schema.Struct({
263 name: TrimmedNonEmptyString,
264 durationMs: Schema.Number,
265 endedAt: Schema.DateTimeUtc,
266 traceId: TrimmedNonEmptyString,
267 spanId: TrimmedNonEmptyString,
268});
269export type ServerTraceDiagnosticsSpanOccurrence = typeof ServerTraceDiagnosticsSpanOccurrence.Type;
270
271export const ServerTraceDiagnosticsLogEvent = Schema.Struct({
272 spanName: TrimmedNonEmptyString,
273 level: TrimmedNonEmptyString,
274 message: TrimmedNonEmptyString,
275 seenAt: Schema.DateTimeUtc,
276 traceId: TrimmedNonEmptyString,
277 spanId: TrimmedNonEmptyString,
278});
279export type ServerTraceDiagnosticsLogEvent = typeof ServerTraceDiagnosticsLogEvent.Type;
280
281export const ServerTraceDiagnosticsResult = Schema.Struct({
282 traceFilePath: TrimmedNonEmptyString,
283 scannedFilePaths: Schema.Array(TrimmedNonEmptyString),
284 readAt: Schema.DateTimeUtc,
285 recordCount: NonNegativeInt,
286 parseErrorCount: NonNegativeInt,
287 firstSpanAt: Schema.Option(Schema.DateTimeUtc),
288 lastSpanAt: Schema.Option(Schema.DateTimeUtc),
289 failureCount: NonNegativeInt,
290 interruptionCount: NonNegativeInt,
291 slowSpanThresholdMs: NonNegativeInt,
292 slowSpanCount: NonNegativeInt,
293 logLevelCounts: Schema.Record(TrimmedNonEmptyString, NonNegativeInt),
294 topSpansByCount: Schema.Array(ServerTraceDiagnosticsSpanSummary),
295 slowestSpans: Schema.Array(ServerTraceDiagnosticsSpanOccurrence),
296 commonFailures: Schema.Array(ServerTraceDiagnosticsFailureSummary),
297 latestFailures: Schema.Array(ServerTraceDiagnosticsRecentFailure),
298 latestWarningAndErrorLogs: Schema.Array(ServerTraceDiagnosticsLogEvent),
299 partialFailure: Schema.Option(Schema.Boolean),
300 error: Schema.Option(
301 Schema.Struct({
302 kind: ServerTraceDiagnosticsErrorKind,
303 message: TrimmedNonEmptyString,
304 }),
305 ),
306});
307export type ServerTraceDiagnosticsResult = typeof ServerTraceDiagnosticsResult.Type;
308
309export const ServerProcessSignal = Schema.Literals(["SIGINT", "SIGKILL"]);
310export type ServerProcessSignal = typeof ServerProcessSignal.Type;
311
312export const ServerProcessDiagnosticsEntry = Schema.Struct({
313 pid: PositiveInt,
314 startTimeMs: NonNegativeInt,
315 ppid: NonNegativeInt,
316 pgid: Schema.Option(Schema.Int),
317 status: TrimmedNonEmptyString,
318 cpuPercent: Schema.Number,
319 rssBytes: NonNegativeInt,
320 elapsed: TrimmedNonEmptyString,
321 command: TrimmedNonEmptyString,
322 depth: NonNegativeInt,
323 childPids: Schema.Array(PositiveInt),
324});
325export type ServerProcessDiagnosticsEntry = typeof ServerProcessDiagnosticsEntry.Type;
326
327export const ServerProcessDiagnosticsResult = Schema.Struct({
328 serverPid: PositiveInt,
329 readAt: Schema.DateTimeUtc,
330 processCount: NonNegativeInt,
331 totalRssBytes: NonNegativeInt,
332 totalCpuPercent: Schema.Number,
333 processes: Schema.Array(ServerProcessDiagnosticsEntry),
334 error: Schema.Option(
335 Schema.Struct({
336 message: TrimmedNonEmptyString,
337 }),
338 ),
339});
340export type ServerProcessDiagnosticsResult = typeof ServerProcessDiagnosticsResult.Type;
341
342export const ServerProcessResourceHistoryInput = Schema.Struct({
343 windowMs: NonNegativeInt,
344 bucketMs: NonNegativeInt,
345});
346export type ServerProcessResourceHistoryInput = typeof ServerProcessResourceHistoryInput.Type;
347
348export const ServerProcessResourceHistoryBucket = Schema.Struct({
349 startedAt: Schema.DateTimeUtc,
350 endedAt: Schema.DateTimeUtc,
351 avgCpuPercent: Schema.Number,
352 maxCpuPercent: Schema.Number,
353 maxRssBytes: NonNegativeInt,
354 maxProcessCount: NonNegativeInt,
355});
356export type ServerProcessResourceHistoryBucket = typeof ServerProcessResourceHistoryBucket.Type;
357
358export const ServerProcessResourceHistorySummary = Schema.Struct({
359 processKey: TrimmedNonEmptyString,
360 pid: PositiveInt,
361 ppid: NonNegativeInt,
362 command: TrimmedNonEmptyString,
363 depth: NonNegativeInt,
364 isServerRoot: Schema.Boolean,
365 firstSeenAt: Schema.DateTimeUtc,
366 lastSeenAt: Schema.DateTimeUtc,
367 currentCpuPercent: Schema.Number,
368 avgCpuPercent: Schema.Number,
369 maxCpuPercent: Schema.Number,
370 cpuSecondsApprox: Schema.Number,
371 currentRssBytes: NonNegativeInt,
372 maxRssBytes: NonNegativeInt,
373 sampleCount: NonNegativeInt,
374});
375export type ServerProcessResourceHistorySummary = typeof ServerProcessResourceHistorySummary.Type;
376
377export const ServerProcessResourceHistoryFailureTag = Schema.Literals([
378 "ProcessDiagnosticsQueryTimeoutError",
379 "ProcessDiagnosticsQueryFailedError",
380 "ProcessDiagnosticsServerProcessSignalError",
381 "ProcessDiagnosticsNotDescendantError",
382 "ProcessDiagnosticsSignalFailedError",
383]);
384export type ServerProcessResourceHistoryFailureTag =
385 typeof ServerProcessResourceHistoryFailureTag.Type;
386
387export const ServerProcessResourceHistoryResult = Schema.Struct({
388 readAt: Schema.DateTimeUtc,
389 windowMs: NonNegativeInt,
390 bucketMs: NonNegativeInt,
391 sampleIntervalMs: NonNegativeInt,
392 retainedSampleCount: NonNegativeInt,
393 totalCpuSecondsApprox: Schema.Number,
394 buckets: Schema.Array(ServerProcessResourceHistoryBucket),
395 topProcesses: Schema.Array(ServerProcessResourceHistorySummary),
396 error: Schema.Option(
397 Schema.Struct({
398 failureTag: ServerProcessResourceHistoryFailureTag,
399 message: TrimmedNonEmptyString,
400 }),
401 ),
402});
403export type ServerProcessResourceHistoryResult = typeof ServerProcessResourceHistoryResult.Type;
404
405export const ServerSignalProcessInput = Schema.Struct({
406 pid: PositiveInt,
407 startTimeMs: NonNegativeInt,
408 signal: ServerProcessSignal,
409});
410export type ServerSignalProcessInput = typeof ServerSignalProcessInput.Type;
411
412export const ServerSignalProcessResult = Schema.Struct({
413 pid: PositiveInt,
414 signal: ServerProcessSignal,
415 signaled: Schema.Boolean,
416 message: Schema.Option(TrimmedNonEmptyString),
417});
418export type ServerSignalProcessResult = typeof ServerSignalProcessResult.Type;
419
420export const ServerConfig = Schema.Struct({
421 environment: ExecutionEnvironmentDescriptor,
422 auth: ServerAuthDescriptor,
423 cwd: TrimmedNonEmptyString,
424 keybindingsConfigPath: TrimmedNonEmptyString,
425 keybindings: ResolvedKeybindingsConfig,
426 issues: ServerConfigIssues,
427 providers: ServerProviders,
428 // Editor ids grow over time; drop ones this build does not know rather than
429 // failing the whole config decode.
430 availableEditors: ForwardCompatibleArray(EditorId),
431 /**
432 * SSH hosts this environment advertises for remote open-in-editor links.
433 * Absent on servers that predate the feature; empty when the machine has no
434 * sshd or no advertisable name.
435 */
436 remoteOpenTargets: Schema.optionalKey(ForwardCompatibleArray(RemoteOpenTarget)),
437 observability: ServerObservability,
438 settings: ServerSettings,
439 /** Whether shell subscriptions can emit an opt-in catch-up completion marker. */
440 shellResumeCompletionMarker: Schema.optionalKey(Schema.Boolean),
441 /** Whether thread subscriptions can emit an opt-in catch-up completion marker. */
442 threadResumeCompletionMarker: Schema.optionalKey(Schema.Boolean),
443 /**
444 * Whether thread detail reads accept a turn window (`turnLimit`/
445 * `beforeCursor`) and return `page` metadata. Clients must not send window
446 * fields to servers that don't advertise this.
447 */
448 threadSnapshotPagination: Schema.optionalKey(Schema.Boolean),
449});
450export type ServerConfig = typeof ServerConfig.Type;
451
452const ServerUpsertKeybindingReplaceTarget = Schema.Struct({
453 key: KeybindingValue,
454 command: KeybindingCommand,
455 when: Schema.optional(KeybindingWhen),
456});
457
458export const ServerUpsertKeybindingInput = Schema.Struct({
459 key: KeybindingValue,
460 command: KeybindingCommand,
461 when: Schema.optional(KeybindingWhen),
462 replace: Schema.optional(ServerUpsertKeybindingReplaceTarget),
463});
464export type ServerUpsertKeybindingInput = typeof ServerUpsertKeybindingInput.Type;
465
466export const ServerRemoveKeybindingInput = ServerUpsertKeybindingReplaceTarget;
467export type ServerRemoveKeybindingInput = typeof ServerRemoveKeybindingInput.Type;
468
469export const ServerUpsertKeybindingResult = Schema.Struct({
470 keybindings: ResolvedKeybindingsConfig,
471 issues: ServerConfigIssues,
472});
473export type ServerUpsertKeybindingResult = typeof ServerUpsertKeybindingResult.Type;
474
475export const ServerRemoveKeybindingResult = ServerUpsertKeybindingResult;
476export type ServerRemoveKeybindingResult = typeof ServerRemoveKeybindingResult.Type;
477
478export const ServerConfigUpdatedPayload = Schema.Struct({
479 issues: ServerConfigIssues,
480 providers: ServerProviders,
481 settings: Schema.optional(ServerSettings),
482});
483export type ServerConfigUpdatedPayload = typeof ServerConfigUpdatedPayload.Type;
484
485export const ServerConfigKeybindingsUpdatedPayload = Schema.Struct({
486 keybindings: ResolvedKeybindingsConfig,
487 issues: ServerConfigIssues,
488});
489export type ServerConfigKeybindingsUpdatedPayload =
490 typeof ServerConfigKeybindingsUpdatedPayload.Type;
491
492export const ServerConfigProviderStatusesPayload = Schema.Struct({
493 providers: ServerProviders,
494});
495export type ServerConfigProviderStatusesPayload = typeof ServerConfigProviderStatusesPayload.Type;
496
497export const ServerConfigSettingsUpdatedPayload = Schema.Struct({
498 settings: ServerSettings,
499});
500export type ServerConfigSettingsUpdatedPayload = typeof ServerConfigSettingsUpdatedPayload.Type;
501
502export const ServerConfigStreamSnapshotEvent = Schema.Struct({
503 version: Schema.Literal(1),
504 type: Schema.Literal("snapshot"),
505 config: ServerConfig,
506});
507export type ServerConfigStreamSnapshotEvent = typeof ServerConfigStreamSnapshotEvent.Type;
508
509export const ServerConfigStreamKeybindingsUpdatedEvent = Schema.Struct({
510 version: Schema.Literal(1),
511 type: Schema.Literal("keybindingsUpdated"),
512 payload: ServerConfigKeybindingsUpdatedPayload,
513});
514export type ServerConfigStreamKeybindingsUpdatedEvent =
515 typeof ServerConfigStreamKeybindingsUpdatedEvent.Type;
516
517export const ServerConfigStreamProviderStatusesEvent = Schema.Struct({
518 version: Schema.Literal(1),
519 type: Schema.Literal("providerStatuses"),
520 payload: ServerConfigProviderStatusesPayload,
521});
522export type ServerConfigStreamProviderStatusesEvent =
523 typeof ServerConfigStreamProviderStatusesEvent.Type;
524
525export const ServerConfigStreamSettingsUpdatedEvent = Schema.Struct({
526 version: Schema.Literal(1),
527 type: Schema.Literal("settingsUpdated"),
528 payload: ServerConfigSettingsUpdatedPayload,
529});
530export type ServerConfigStreamSettingsUpdatedEvent =
531 typeof ServerConfigStreamSettingsUpdatedEvent.Type;
532
533export const ServerConfigStreamEvent = Schema.Union([
534 ServerConfigStreamSnapshotEvent,
535 ServerConfigStreamKeybindingsUpdatedEvent,
536 ServerConfigStreamProviderStatusesEvent,
537 ServerConfigStreamSettingsUpdatedEvent,
538]);
539export type ServerConfigStreamEvent = typeof ServerConfigStreamEvent.Type;
540
541/** Terminal selection recorded by the service launcher for one update. */
542export const ServerSelfUpdateOutcome = Schema.Struct({
543 id: TrimmedNonEmptyString,
544 fromVersion: TrimmedNonEmptyString,
545 targetVersion: TrimmedNonEmptyString,
546 status: Schema.Literals(["committed", "rolled-back", "failed"]),
547 reason: Schema.optionalKey(TrimmedNonEmptyString),
548});
549export type ServerSelfUpdateOutcome = typeof ServerSelfUpdateOutcome.Type;
550
551export const ServerLifecycleReadyPayload = Schema.Struct({
552 at: IsoDateTime,
553 environment: ExecutionEnvironmentDescriptor,
554 /** Present when this process resumed a launcher-managed update. */
555 updateOutcome: Schema.optionalKey(ServerSelfUpdateOutcome),
556});
557export type ServerLifecycleReadyPayload = typeof ServerLifecycleReadyPayload.Type;
558
559export const ServerLifecycleWelcomePayload = Schema.Struct({
560 environment: ExecutionEnvironmentDescriptor,
561 cwd: TrimmedNonEmptyString,
562 projectName: TrimmedNonEmptyString,
563 bootstrapProjectId: Schema.optional(ProjectId),
564 bootstrapThreadId: Schema.optional(ThreadId),
565});
566export type ServerLifecycleWelcomePayload = typeof ServerLifecycleWelcomePayload.Type;
567
568export const ServerLifecycleStreamWelcomeEvent = Schema.Struct({
569 version: Schema.Literal(1),
570 sequence: NonNegativeInt,
571 type: Schema.Literal("welcome"),
572 payload: ServerLifecycleWelcomePayload,
573});
574export type ServerLifecycleStreamWelcomeEvent = typeof ServerLifecycleStreamWelcomeEvent.Type;
575
576export const ServerLifecycleStreamReadyEvent = Schema.Struct({
577 version: Schema.Literal(1),
578 sequence: NonNegativeInt,
579 type: Schema.Literal("ready"),
580 payload: ServerLifecycleReadyPayload,
581});
582export type ServerLifecycleStreamReadyEvent = typeof ServerLifecycleStreamReadyEvent.Type;
583
584export const ServerLifecycleStreamEvent = Schema.Union([
585 ServerLifecycleStreamWelcomeEvent,
586 ServerLifecycleStreamReadyEvent,
587]);
588export type ServerLifecycleStreamEvent = typeof ServerLifecycleStreamEvent.Type;
589
590export const ServerProviderUpdatedPayload = Schema.Struct({
591 providers: ServerProviders,
592});
593export type ServerProviderUpdatedPayload = typeof ServerProviderUpdatedPayload.Type;
594
595export const ServerProviderUpdateInput = Schema.Struct({
596 provider: ProviderDriverKind,
597 instanceId: Schema.optionalKey(ProviderInstanceId),
598});
599export type ServerProviderUpdateInput = typeof ServerProviderUpdateInput.Type;
600
601export class ServerProviderUpdateError extends Schema.TaggedErrorClass<ServerProviderUpdateError>()(
602 "ServerProviderUpdateError",
603 {
604 provider: ProviderDriverKind,
605 reason: TrimmedNonEmptyString,
606 cause: Schema.optional(Schema.Defect()),
607 },
608) {
609 override get message(): string {
610 return `Provider update failed for ${this.provider}: ${this.reason}`;
611 }
612}
613
614export const ServerSelfUpdateInput = Schema.Struct({
615 /** Exact npm version of the `t3` package to install (never a dist-tag, so
616 the server and the acknowledging client agree on what was requested). */
617 targetVersion: TrimmedNonEmptyString,
618});
619export type ServerSelfUpdateInput = typeof ServerSelfUpdateInput.Type;
620
621/** Acknowledgement that the update artifact is installed and the server is
622 about to restart into it — the connection will drop moments later. */
623export const ServerSelfUpdateResult = Schema.Struct({
624 targetVersion: TrimmedNonEmptyString,
625 method: ServerSelfUpdateMethod,
626 /** Launcher-generated correlation ID. Absent when talking to older servers. */
627 updateId: Schema.optionalKey(TrimmedNonEmptyString),
628});
629export type ServerSelfUpdateResult = typeof ServerSelfUpdateResult.Type;
630
631export const ServerSelfUpdateProgressStage = Schema.Literals(["downloading", "installing"]);
632export type ServerSelfUpdateProgressStage = typeof ServerSelfUpdateProgressStage.Type;
633
634export const ServerSelfUpdateProgressEvent = Schema.Union([
635 Schema.Struct({
636 type: Schema.Literal("progress"),
637 stage: ServerSelfUpdateProgressStage,
638 }),
639 Schema.Struct({
640 type: Schema.Literal("complete"),
641 result: ServerSelfUpdateResult,
642 }),
643]);
644export type ServerSelfUpdateProgressEvent = typeof ServerSelfUpdateProgressEvent.Type;
645
646export class ServerSelfUpdateError extends Schema.TaggedErrorClass<ServerSelfUpdateError>()(
647 "ServerSelfUpdateError",
648 {
649 reason: TrimmedNonEmptyString,
650 cause: Schema.optional(Schema.Defect()),
651 },
652) {
653 override get message(): string {
654 return `Server update failed: ${this.reason}`;
655 }
656}