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