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 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
200export const ServerProviders = Schema.Array(ServerProvider);
201export type ServerProviders = typeof ServerProviders.Type;
202
203/**
204 * Treat the optional `availability` as "available" when absent. This is
205 * the rule legacy producers (which omit the field) and new producers
206 * (which set it explicitly) agree on so consumers never have to thread
207 * `?? "available"` defaults through their code paths.
208 */
209export const isProviderAvailable = (snapshot: ServerProvider): boolean =>
210 snapshot.availability !== "unavailable";
211
212export const ServerObservability = Schema.Struct({
213 logsDirectoryPath: TrimmedNonEmptyString,
214 localTracingEnabled: Schema.Boolean,
215 otlpTracesUrl: Schema.optional(TrimmedNonEmptyString),
216 otlpTracesEnabled: Schema.Boolean,
217 otlpMetricsUrl: Schema.optional(TrimmedNonEmptyString),
218 otlpMetricsEnabled: Schema.Boolean,
219});
220export type ServerObservability = typeof ServerObservability.Type;
221
222export const ServerTraceDiagnosticsErrorKind = Schema.Literals([
223 "trace-file-not-found",
224 "trace-file-read-failed",
225]);
226export type ServerTraceDiagnosticsErrorKind = typeof ServerTraceDiagnosticsErrorKind.Type;
227
228export const ServerTraceDiagnosticsSpanSummary = Schema.Struct({
229 name: TrimmedNonEmptyString,
230 count: NonNegativeInt,
231 failureCount: NonNegativeInt,
232 totalDurationMs: Schema.Number,
233 averageDurationMs: Schema.Number,
234 maxDurationMs: Schema.Number,
235});
236export type ServerTraceDiagnosticsSpanSummary = typeof ServerTraceDiagnosticsSpanSummary.Type;
237
238export const ServerTraceDiagnosticsFailureSummary = Schema.Struct({
239 name: TrimmedNonEmptyString,
240 cause: TrimmedNonEmptyString,
241 count: NonNegativeInt,
242 lastSeenAt: Schema.DateTimeUtc,
243 traceId: TrimmedNonEmptyString,
244 spanId: TrimmedNonEmptyString,
245});
246export type ServerTraceDiagnosticsFailureSummary = typeof ServerTraceDiagnosticsFailureSummary.Type;
247
248export const ServerTraceDiagnosticsRecentFailure = Schema.Struct({
249 name: TrimmedNonEmptyString,
250 cause: TrimmedNonEmptyString,
251 durationMs: Schema.Number,
252 endedAt: Schema.DateTimeUtc,
253 traceId: TrimmedNonEmptyString,
254 spanId: TrimmedNonEmptyString,
255});
256export type ServerTraceDiagnosticsRecentFailure = typeof ServerTraceDiagnosticsRecentFailure.Type;
257
258export const ServerTraceDiagnosticsSpanOccurrence = Schema.Struct({
259 name: TrimmedNonEmptyString,
260 durationMs: Schema.Number,
261 endedAt: Schema.DateTimeUtc,
262 traceId: TrimmedNonEmptyString,
263 spanId: TrimmedNonEmptyString,
264});
265export type ServerTraceDiagnosticsSpanOccurrence = typeof ServerTraceDiagnosticsSpanOccurrence.Type;
266
267export const ServerTraceDiagnosticsLogEvent = Schema.Struct({
268 spanName: TrimmedNonEmptyString,
269 level: TrimmedNonEmptyString,
270 message: TrimmedNonEmptyString,
271 seenAt: Schema.DateTimeUtc,
272 traceId: TrimmedNonEmptyString,
273 spanId: TrimmedNonEmptyString,
274});
275export type ServerTraceDiagnosticsLogEvent = typeof ServerTraceDiagnosticsLogEvent.Type;
276
277export const ServerTraceDiagnosticsResult = Schema.Struct({
278 traceFilePath: TrimmedNonEmptyString,
279 scannedFilePaths: Schema.Array(TrimmedNonEmptyString),
280 readAt: Schema.DateTimeUtc,
281 recordCount: NonNegativeInt,
282 parseErrorCount: NonNegativeInt,
283 firstSpanAt: Schema.Option(Schema.DateTimeUtc),
284 lastSpanAt: Schema.Option(Schema.DateTimeUtc),
285 failureCount: NonNegativeInt,
286 interruptionCount: NonNegativeInt,
287 slowSpanThresholdMs: NonNegativeInt,
288 slowSpanCount: NonNegativeInt,
289 logLevelCounts: Schema.Record(TrimmedNonEmptyString, NonNegativeInt),
290 topSpansByCount: Schema.Array(ServerTraceDiagnosticsSpanSummary),
291 slowestSpans: Schema.Array(ServerTraceDiagnosticsSpanOccurrence),
292 commonFailures: Schema.Array(ServerTraceDiagnosticsFailureSummary),
293 latestFailures: Schema.Array(ServerTraceDiagnosticsRecentFailure),
294 latestWarningAndErrorLogs: Schema.Array(ServerTraceDiagnosticsLogEvent),
295 partialFailure: Schema.Option(Schema.Boolean),
296 error: Schema.Option(
297 Schema.Struct({
298 kind: ServerTraceDiagnosticsErrorKind,
299 message: TrimmedNonEmptyString,
300 }),
301 ),
302});
303export type ServerTraceDiagnosticsResult = typeof ServerTraceDiagnosticsResult.Type;
304
305export const ServerProcessSignal = Schema.Literals(["SIGINT", "SIGKILL"]);
306export type ServerProcessSignal = typeof ServerProcessSignal.Type;
307
308export const ServerProcessDiagnosticsEntry = Schema.Struct({
309 pid: PositiveInt,
310 startTimeMs: NonNegativeInt,
311 ppid: NonNegativeInt,
312 pgid: Schema.Option(Schema.Int),
313 status: TrimmedNonEmptyString,
314 cpuPercent: Schema.Number,
315 rssBytes: NonNegativeInt,
316 elapsed: TrimmedNonEmptyString,
317 command: TrimmedNonEmptyString,
318 depth: NonNegativeInt,
319 childPids: Schema.Array(PositiveInt),
320});
321export type ServerProcessDiagnosticsEntry = typeof ServerProcessDiagnosticsEntry.Type;
322
323export const ServerProcessDiagnosticsResult = Schema.Struct({
324 serverPid: PositiveInt,
325 readAt: Schema.DateTimeUtc,
326 processCount: NonNegativeInt,
327 totalRssBytes: NonNegativeInt,
328 totalCpuPercent: Schema.Number,
329 processes: Schema.Array(ServerProcessDiagnosticsEntry),
330 error: Schema.Option(
331 Schema.Struct({
332 message: TrimmedNonEmptyString,
333 }),
334 ),
335});
336export type ServerProcessDiagnosticsResult = typeof ServerProcessDiagnosticsResult.Type;
337
338export const ServerProcessResourceHistoryInput = Schema.Struct({
339 windowMs: NonNegativeInt,
340 bucketMs: NonNegativeInt,
341});
342export type ServerProcessResourceHistoryInput = typeof ServerProcessResourceHistoryInput.Type;
343
344export const ServerProcessResourceHistoryBucket = Schema.Struct({
345 startedAt: Schema.DateTimeUtc,
346 endedAt: Schema.DateTimeUtc,
347 avgCpuPercent: Schema.Number,
348 maxCpuPercent: Schema.Number,
349 maxRssBytes: NonNegativeInt,
350 maxProcessCount: NonNegativeInt,
351});
352export type ServerProcessResourceHistoryBucket = typeof ServerProcessResourceHistoryBucket.Type;
353
354export const ServerProcessResourceHistorySummary = Schema.Struct({
355 processKey: TrimmedNonEmptyString,
356 pid: PositiveInt,
357 ppid: NonNegativeInt,
358 command: TrimmedNonEmptyString,
359 depth: NonNegativeInt,
360 isServerRoot: Schema.Boolean,
361 firstSeenAt: Schema.DateTimeUtc,
362 lastSeenAt: Schema.DateTimeUtc,
363 currentCpuPercent: Schema.Number,
364 avgCpuPercent: Schema.Number,
365 maxCpuPercent: Schema.Number,
366 cpuSecondsApprox: Schema.Number,
367 currentRssBytes: NonNegativeInt,
368 maxRssBytes: NonNegativeInt,
369 sampleCount: NonNegativeInt,
370});
371export type ServerProcessResourceHistorySummary = typeof ServerProcessResourceHistorySummary.Type;
372
373export const ServerProcessResourceHistoryFailureTag = Schema.Literals([
374 "ProcessDiagnosticsQueryTimeoutError",
375 "ProcessDiagnosticsQueryFailedError",
376 "ProcessDiagnosticsServerProcessSignalError",
377 "ProcessDiagnosticsNotDescendantError",
378 "ProcessDiagnosticsSignalFailedError",
379]);
380export type ServerProcessResourceHistoryFailureTag =
381 typeof ServerProcessResourceHistoryFailureTag.Type;
382
383export const ServerProcessResourceHistoryResult = Schema.Struct({
384 readAt: Schema.DateTimeUtc,
385 windowMs: NonNegativeInt,
386 bucketMs: NonNegativeInt,
387 sampleIntervalMs: NonNegativeInt,
388 retainedSampleCount: NonNegativeInt,
389 totalCpuSecondsApprox: Schema.Number,
390 buckets: Schema.Array(ServerProcessResourceHistoryBucket),
391 topProcesses: Schema.Array(ServerProcessResourceHistorySummary),
392 error: Schema.Option(
393 Schema.Struct({
394 failureTag: ServerProcessResourceHistoryFailureTag,
395 message: TrimmedNonEmptyString,
396 }),
397 ),
398});
399export type ServerProcessResourceHistoryResult = typeof ServerProcessResourceHistoryResult.Type;
400
401export const ServerSignalProcessInput = Schema.Struct({
402 pid: PositiveInt,
403 startTimeMs: NonNegativeInt,
404 signal: ServerProcessSignal,
405});
406export type ServerSignalProcessInput = typeof ServerSignalProcessInput.Type;
407
408export const ServerSignalProcessResult = Schema.Struct({
409 pid: PositiveInt,
410 signal: ServerProcessSignal,
411 signaled: Schema.Boolean,
412 message: Schema.Option(TrimmedNonEmptyString),
413});
414export type ServerSignalProcessResult = typeof ServerSignalProcessResult.Type;
415
416export const ServerConfig = Schema.Struct({
417 environment: ExecutionEnvironmentDescriptor,
418 auth: ServerAuthDescriptor,
419 cwd: TrimmedNonEmptyString,
420 keybindingsConfigPath: TrimmedNonEmptyString,
421 keybindings: ResolvedKeybindingsConfig,
422 issues: ServerConfigIssues,
423 providers: ServerProviders,
424 // Editor ids grow over time; drop ones this build does not know rather than
425 // failing the whole config decode.
426 availableEditors: ForwardCompatibleArray(EditorId),
427 observability: ServerObservability,
428 settings: ServerSettings,
429 /** Whether shell subscriptions can emit an opt-in catch-up completion marker. */
430 shellResumeCompletionMarker: Schema.optionalKey(Schema.Boolean),
431 /** Whether thread subscriptions can emit an opt-in catch-up completion marker. */
432 threadResumeCompletionMarker: Schema.optionalKey(Schema.Boolean),
433});
434export type ServerConfig = typeof ServerConfig.Type;
435
436const ServerUpsertKeybindingReplaceTarget = Schema.Struct({
437 key: KeybindingValue,
438 command: KeybindingCommand,
439 when: Schema.optional(KeybindingWhen),
440});
441
442export const ServerUpsertKeybindingInput = Schema.Struct({
443 key: KeybindingValue,
444 command: KeybindingCommand,
445 when: Schema.optional(KeybindingWhen),
446 replace: Schema.optional(ServerUpsertKeybindingReplaceTarget),
447});
448export type ServerUpsertKeybindingInput = typeof ServerUpsertKeybindingInput.Type;
449
450export const ServerRemoveKeybindingInput = ServerUpsertKeybindingReplaceTarget;
451export type ServerRemoveKeybindingInput = typeof ServerRemoveKeybindingInput.Type;
452
453export const ServerUpsertKeybindingResult = Schema.Struct({
454 keybindings: ResolvedKeybindingsConfig,
455 issues: ServerConfigIssues,
456});
457export type ServerUpsertKeybindingResult = typeof ServerUpsertKeybindingResult.Type;
458
459export const ServerRemoveKeybindingResult = ServerUpsertKeybindingResult;
460export type ServerRemoveKeybindingResult = typeof ServerRemoveKeybindingResult.Type;
461
462export const ServerConfigUpdatedPayload = Schema.Struct({
463 issues: ServerConfigIssues,
464 providers: ServerProviders,
465 settings: Schema.optional(ServerSettings),
466});
467export type ServerConfigUpdatedPayload = typeof ServerConfigUpdatedPayload.Type;
468
469export const ServerConfigKeybindingsUpdatedPayload = Schema.Struct({
470 keybindings: ResolvedKeybindingsConfig,
471 issues: ServerConfigIssues,
472});
473export type ServerConfigKeybindingsUpdatedPayload =
474 typeof ServerConfigKeybindingsUpdatedPayload.Type;
475
476export const ServerConfigProviderStatusesPayload = Schema.Struct({
477 providers: ServerProviders,
478});
479export type ServerConfigProviderStatusesPayload = typeof ServerConfigProviderStatusesPayload.Type;
480
481export const ServerConfigSettingsUpdatedPayload = Schema.Struct({
482 settings: ServerSettings,
483});
484export type ServerConfigSettingsUpdatedPayload = typeof ServerConfigSettingsUpdatedPayload.Type;
485
486export const ServerConfigStreamSnapshotEvent = Schema.Struct({
487 version: Schema.Literal(1),
488 type: Schema.Literal("snapshot"),
489 config: ServerConfig,
490});
491export type ServerConfigStreamSnapshotEvent = typeof ServerConfigStreamSnapshotEvent.Type;
492
493export const ServerConfigStreamKeybindingsUpdatedEvent = Schema.Struct({
494 version: Schema.Literal(1),
495 type: Schema.Literal("keybindingsUpdated"),
496 payload: ServerConfigKeybindingsUpdatedPayload,
497});
498export type ServerConfigStreamKeybindingsUpdatedEvent =
499 typeof ServerConfigStreamKeybindingsUpdatedEvent.Type;
500
501export const ServerConfigStreamProviderStatusesEvent = Schema.Struct({
502 version: Schema.Literal(1),
503 type: Schema.Literal("providerStatuses"),
504 payload: ServerConfigProviderStatusesPayload,
505});
506export type ServerConfigStreamProviderStatusesEvent =
507 typeof ServerConfigStreamProviderStatusesEvent.Type;
508
509export const ServerConfigStreamSettingsUpdatedEvent = Schema.Struct({
510 version: Schema.Literal(1),
511 type: Schema.Literal("settingsUpdated"),
512 payload: ServerConfigSettingsUpdatedPayload,
513});
514export type ServerConfigStreamSettingsUpdatedEvent =
515 typeof ServerConfigStreamSettingsUpdatedEvent.Type;
516
517export const ServerConfigStreamEvent = Schema.Union([
518 ServerConfigStreamSnapshotEvent,
519 ServerConfigStreamKeybindingsUpdatedEvent,
520 ServerConfigStreamProviderStatusesEvent,
521 ServerConfigStreamSettingsUpdatedEvent,
522]);
523export type ServerConfigStreamEvent = typeof ServerConfigStreamEvent.Type;
524
525/** Terminal selection recorded by the service launcher for one update. */
526export const ServerSelfUpdateOutcome = Schema.Struct({
527 id: TrimmedNonEmptyString,
528 fromVersion: TrimmedNonEmptyString,
529 targetVersion: TrimmedNonEmptyString,
530 status: Schema.Literals(["committed", "rolled-back", "failed"]),
531 reason: Schema.optionalKey(TrimmedNonEmptyString),
532});
533export type ServerSelfUpdateOutcome = typeof ServerSelfUpdateOutcome.Type;
534
535export const ServerLifecycleReadyPayload = Schema.Struct({
536 at: IsoDateTime,
537 environment: ExecutionEnvironmentDescriptor,
538 /** Present when this process resumed a launcher-managed update. */
539 updateOutcome: Schema.optionalKey(ServerSelfUpdateOutcome),
540});
541export type ServerLifecycleReadyPayload = typeof ServerLifecycleReadyPayload.Type;
542
543export const ServerLifecycleWelcomePayload = Schema.Struct({
544 environment: ExecutionEnvironmentDescriptor,
545 cwd: TrimmedNonEmptyString,
546 projectName: TrimmedNonEmptyString,
547 bootstrapProjectId: Schema.optional(ProjectId),
548 bootstrapThreadId: Schema.optional(ThreadId),
549});
550export type ServerLifecycleWelcomePayload = typeof ServerLifecycleWelcomePayload.Type;
551
552export const ServerLifecycleStreamWelcomeEvent = Schema.Struct({
553 version: Schema.Literal(1),
554 sequence: NonNegativeInt,
555 type: Schema.Literal("welcome"),
556 payload: ServerLifecycleWelcomePayload,
557});
558export type ServerLifecycleStreamWelcomeEvent = typeof ServerLifecycleStreamWelcomeEvent.Type;
559
560export const ServerLifecycleStreamReadyEvent = Schema.Struct({
561 version: Schema.Literal(1),
562 sequence: NonNegativeInt,
563 type: Schema.Literal("ready"),
564 payload: ServerLifecycleReadyPayload,
565});
566export type ServerLifecycleStreamReadyEvent = typeof ServerLifecycleStreamReadyEvent.Type;
567
568export const ServerLifecycleStreamEvent = Schema.Union([
569 ServerLifecycleStreamWelcomeEvent,
570 ServerLifecycleStreamReadyEvent,
571]);
572export type ServerLifecycleStreamEvent = typeof ServerLifecycleStreamEvent.Type;
573
574export const ServerProviderUpdatedPayload = Schema.Struct({
575 providers: ServerProviders,
576});
577export type ServerProviderUpdatedPayload = typeof ServerProviderUpdatedPayload.Type;
578
579export const ServerProviderUpdateInput = Schema.Struct({
580 provider: ProviderDriverKind,
581 instanceId: Schema.optionalKey(ProviderInstanceId),
582});
583export type ServerProviderUpdateInput = typeof ServerProviderUpdateInput.Type;
584
585export class ServerProviderUpdateError extends Schema.TaggedErrorClass<ServerProviderUpdateError>()(
586 "ServerProviderUpdateError",
587 {
588 provider: ProviderDriverKind,
589 reason: TrimmedNonEmptyString,
590 cause: Schema.optional(Schema.Defect()),
591 },
592) {
593 override get message(): string {
594 return `Provider update failed for ${this.provider}: ${this.reason}`;
595 }
596}
597
598export const ServerSelfUpdateInput = Schema.Struct({
599 /** Exact npm version of the `t3` package to install (never a dist-tag, so
600 the server and the acknowledging client agree on what was requested). */
601 targetVersion: TrimmedNonEmptyString,
602});
603export type ServerSelfUpdateInput = typeof ServerSelfUpdateInput.Type;
604
605/** Acknowledgement that the update artifact is installed and the server is
606 about to restart into it — the connection will drop moments later. */
607export const ServerSelfUpdateResult = Schema.Struct({
608 targetVersion: TrimmedNonEmptyString,
609 method: ServerSelfUpdateMethod,
610 /** Launcher-generated correlation ID. Absent when talking to older servers. */
611 updateId: Schema.optionalKey(TrimmedNonEmptyString),
612});
613export type ServerSelfUpdateResult = typeof ServerSelfUpdateResult.Type;
614
615export const ServerSelfUpdateProgressStage = Schema.Literals(["downloading", "installing"]);
616export type ServerSelfUpdateProgressStage = typeof ServerSelfUpdateProgressStage.Type;
617
618export const ServerSelfUpdateProgressEvent = Schema.Union([
619 Schema.Struct({
620 type: Schema.Literal("progress"),
621 stage: ServerSelfUpdateProgressStage,
622 }),
623 Schema.Struct({
624 type: Schema.Literal("complete"),
625 result: ServerSelfUpdateResult,
626 }),
627]);
628export type ServerSelfUpdateProgressEvent = typeof ServerSelfUpdateProgressEvent.Type;
629
630export class ServerSelfUpdateError extends Schema.TaggedErrorClass<ServerSelfUpdateError>()(
631 "ServerSelfUpdateError",
632 {
633 reason: TrimmedNonEmptyString,
634 cause: Schema.optional(Schema.Defect()),
635 },
636) {
637 override get message(): string {
638 return `Server update failed: ${this.reason}`;
639 }
640}