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