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

orchestration.ts

1,312 lines43.1 KB

1import * as Effect from "effect/Effect";
2import * as Option from "effect/Option";
3import * as Schema from "effect/Schema";
4import * as SchemaIssue from "effect/SchemaIssue";
5import * as SchemaTransformation from "effect/SchemaTransformation";
6import * as Struct from "effect/Struct";
7import { ProviderOptionSelections } from "./model.ts";
8import { RepositoryIdentity } from "./environment.ts";
9import {
10 ApprovalRequestId,
11 CheckpointRef,
12 CommandId,
13 EventId,
14 IsoDateTime,
15 MessageId,
16 NonNegativeInt,
17 ProjectId,
18 ProviderItemId,
19 ThreadId,
20 TrimmedNonEmptyString,
21 TurnId,
22} from "./baseSchemas.ts";
23import { ProviderInstanceId } from "./providerInstance.ts";
24​
25export const ORCHESTRATION_WS_METHODS = {
26 dispatchCommand: "orchestration.dispatchCommand",
27 getTurnDiff: "orchestration.getTurnDiff",
28 getFullThreadDiff: "orchestration.getFullThreadDiff",
29 replayEvents: "orchestration.replayEvents",
30 getArchivedShellSnapshot: "orchestration.getArchivedShellSnapshot",
31 subscribeShell: "orchestration.subscribeShell",
32 subscribeThread: "orchestration.subscribeThread",
33} as const;
34​
35export const ProviderApprovalPolicy = Schema.Literals([
36 "untrusted",
37 "on-failure",
38 "on-request",
39 "never",
40]);
41export type ProviderApprovalPolicy = typeof ProviderApprovalPolicy.Type;
42export const ProviderSandboxMode = Schema.Literals([
43 "read-only",
44 "workspace-write",
45 "danger-full-access",
46]);
47export type ProviderSandboxMode = typeof ProviderSandboxMode.Type;
48​
49/**
50 * `ModelSelection` — selection of a model on a configured provider instance.
51 *
52 * The routing key is `instanceId` (a user-defined slug identifying one
53 * configured provider instance). Drivers, credentials, working-directory
54 * bindings, and any other per-instance state are recovered from the
55 * runtime registry via the instance id.
56 *
57 * Wire legacy: persisted selections produced before the driver/instance
58 * split carried a `provider: <driver-id>` field instead. The schema absorbs
59 * that shape via a pre-decoding transform — `{provider, model}` is promoted
60 * to `{instanceId: defaultInstanceIdForDriver(provider), model}`. No
61 * post-decode compatibility code lives in the runtime; the transform is the
62 * only compat surface.
63 */
64const ModelSelectionWire = Schema.Struct({
65 instanceId: ProviderInstanceId,
66 model: TrimmedNonEmptyString,
67 options: Schema.optionalKey(ProviderOptionSelections),
68});
69​
70// Source shape for persisted legacy payloads. Fields are typed as
71// `Schema.Unknown` so malformed drafts still make it into the transform and
72// fail validation through the target schema (with proper error messages)
73// rather than at the source-struct layer where the error is less actionable.
74const ModelSelectionSource = Schema.Struct({
75 provider: Schema.optional(Schema.Unknown),
76 instanceId: Schema.optional(Schema.Unknown),
77 model: Schema.Unknown,
78 options: Schema.optional(Schema.Unknown),
79});
80​
81export const ModelSelection = ModelSelectionSource.pipe(
82 Schema.decodeTo(
83 ModelSelectionWire,
84 SchemaTransformation.transformOrFail({
85 decode: (raw) => {
86 // Resolve the routing key: prefer an explicit `instanceId`; fall
87 // back to promoting the legacy `provider` slug (the canonical
88 // `defaultInstanceIdForDriver` mapping) so persisted rollout-era
89 // payloads decode without data loss. The target schema brands the
90 // string as `ProviderInstanceId`.
91 const instanceIdSource =
92 raw.instanceId !== undefined
93 ? raw.instanceId
94 : typeof raw.provider === "string"
95 ? raw.provider
96 : undefined;
97 const base: Record<string, unknown> = {
98 instanceId: instanceIdSource,
99 model: raw.model,
100 };
101 if (raw.options !== undefined) base.options = raw.options;
102 return Effect.succeed(base as typeof ModelSelectionWire.Encoded);
103 },
104 encode: (value) => {
105 const base: Record<string, unknown> = {
106 model: value.model,
107 instanceId: value.instanceId,
108 };
109 if (value.options !== undefined) base.options = value.options;
110 return Effect.succeed(base as typeof ModelSelectionSource.Encoded);
111 },
112 }),
113 ),
114);
115export type ModelSelection = typeof ModelSelection.Type;
116​
117export const RuntimeMode = Schema.Literals([
118 "approval-required",
119 "auto-accept-edits",
120 "full-access",
121]);
122export type RuntimeMode = typeof RuntimeMode.Type;
123export const DEFAULT_RUNTIME_MODE: RuntimeMode = "full-access";
124export const ProviderInteractionMode = Schema.Literals(["default", "plan"]);
125export type ProviderInteractionMode = typeof ProviderInteractionMode.Type;
126export const DEFAULT_PROVIDER_INTERACTION_MODE: ProviderInteractionMode = "default";
127export const ProviderRequestKind = Schema.Literals(["command", "file-read", "file-change"]);
128export type ProviderRequestKind = typeof ProviderRequestKind.Type;
129export const AssistantDeliveryMode = Schema.Literals(["buffered", "streaming"]);
130export type AssistantDeliveryMode = typeof AssistantDeliveryMode.Type;
131export const ProviderApprovalDecision = Schema.Literals([
132 "accept",
133 "acceptForSession",
134 "decline",
135 "cancel",
136]);
137export type ProviderApprovalDecision = typeof ProviderApprovalDecision.Type;
138export const ProviderUserInputAnswers = Schema.Record(Schema.String, Schema.Unknown);
139export type ProviderUserInputAnswers = typeof ProviderUserInputAnswers.Type;
140​
141export const PROVIDER_SEND_TURN_MAX_INPUT_CHARS = 120_000;
142export const PROVIDER_SEND_TURN_MAX_ATTACHMENTS = 8;
143export const PROVIDER_SEND_TURN_MAX_IMAGE_BYTES = 10 * 1024 * 1024;
144const PROVIDER_SEND_TURN_MAX_IMAGE_DATA_URL_CHARS = 14_000_000;
145const CHAT_ATTACHMENT_ID_MAX_CHARS = 128;
146// Correlation id is command id by design in this model.
147export const CorrelationId = CommandId;
148export type CorrelationId = typeof CorrelationId.Type;
149​
150const ChatAttachmentId = TrimmedNonEmptyString.check(
151 Schema.isMaxLength(CHAT_ATTACHMENT_ID_MAX_CHARS),
152 Schema.isPattern(/^[a-z0-9_-]+$/i),
153);
154export type ChatAttachmentId = typeof ChatAttachmentId.Type;
155​
156export const ChatImageAttachment = Schema.Struct({
157 type: Schema.Literal("image"),
158 id: ChatAttachmentId,
159 name: TrimmedNonEmptyString.check(Schema.isMaxLength(255)),
160 mimeType: TrimmedNonEmptyString.check(Schema.isMaxLength(100), Schema.isPattern(/^image\//i)),
161 sizeBytes: NonNegativeInt.check(Schema.isLessThanOrEqualTo(PROVIDER_SEND_TURN_MAX_IMAGE_BYTES)),
162});
163export type ChatImageAttachment = typeof ChatImageAttachment.Type;
164​
165const UploadChatImageAttachment = Schema.Struct({
166 type: Schema.Literal("image"),
167 name: TrimmedNonEmptyString.check(Schema.isMaxLength(255)),
168 mimeType: TrimmedNonEmptyString.check(Schema.isMaxLength(100), Schema.isPattern(/^image\//i)),
169 sizeBytes: NonNegativeInt.check(Schema.isLessThanOrEqualTo(PROVIDER_SEND_TURN_MAX_IMAGE_BYTES)),
170 dataUrl: TrimmedNonEmptyString.check(
171 Schema.isMaxLength(PROVIDER_SEND_TURN_MAX_IMAGE_DATA_URL_CHARS),
172 ),
173});
174export type UploadChatImageAttachment = typeof UploadChatImageAttachment.Type;
175​
176export const ChatAttachment = Schema.Union([ChatImageAttachment]);
177export type ChatAttachment = typeof ChatAttachment.Type;
178const UploadChatAttachment = Schema.Union([UploadChatImageAttachment]);
179export type UploadChatAttachment = typeof UploadChatAttachment.Type;
180​
181export const ProjectScriptIcon = Schema.Literals([
182 "play",
183 "test",
184 "lint",
185 "configure",
186 "build",
187 "debug",
188]);
189export type ProjectScriptIcon = typeof ProjectScriptIcon.Type;
190​
191export const ProjectScript = Schema.Struct({
192 id: TrimmedNonEmptyString,
193 name: TrimmedNonEmptyString,
194 command: TrimmedNonEmptyString,
195 icon: ProjectScriptIcon,
196 runOnWorktreeCreate: Schema.Boolean,
197 /**
198 * URL to open in the in-app browser preview when this script runs (or
199 * when the user explicitly requests a preview). Optional; only honored on
200 * the desktop build.
201 */
202 previewUrl: Schema.optional(TrimmedNonEmptyString),
203 /**
204 * When true, automatically open the preview panel pointed at `previewUrl`
205 * the moment this script starts. Ignored without `previewUrl` or on web.
206 */
207 autoOpenPreview: Schema.optional(Schema.Boolean),
208});
209export type ProjectScript = typeof ProjectScript.Type;
210​
211export const OrchestrationProject = Schema.Struct({
212 id: ProjectId,
213 title: TrimmedNonEmptyString,
214 workspaceRoot: TrimmedNonEmptyString,
215 repositoryIdentity: Schema.optional(Schema.NullOr(RepositoryIdentity)),
216 defaultModelSelection: Schema.NullOr(ModelSelection),
217 scripts: Schema.Array(ProjectScript),
218 createdAt: IsoDateTime,
219 updatedAt: IsoDateTime,
220 deletedAt: Schema.NullOr(IsoDateTime),
221});
222export type OrchestrationProject = typeof OrchestrationProject.Type;
223​
224export const OrchestrationMessageRole = Schema.Literals(["user", "assistant", "system"]);
225export type OrchestrationMessageRole = typeof OrchestrationMessageRole.Type;
226​
227export const OrchestrationMessage = Schema.Struct({
228 id: MessageId,
229 role: OrchestrationMessageRole,
230 text: Schema.String,
231 attachments: Schema.optional(Schema.Array(ChatAttachment)),
232 turnId: Schema.NullOr(TurnId),
233 streaming: Schema.Boolean,
234 createdAt: IsoDateTime,
235 updatedAt: IsoDateTime,
236});
237export type OrchestrationMessage = typeof OrchestrationMessage.Type;
238​
239export const OrchestrationProposedPlanId = TrimmedNonEmptyString;
240export type OrchestrationProposedPlanId = typeof OrchestrationProposedPlanId.Type;
241​
242export const OrchestrationProposedPlan = Schema.Struct({
243 id: OrchestrationProposedPlanId,
244 turnId: Schema.NullOr(TurnId),
245 planMarkdown: TrimmedNonEmptyString,
246 implementedAt: Schema.NullOr(IsoDateTime).pipe(Schema.withDecodingDefault(Effect.succeed(null))),
247 implementationThreadId: Schema.NullOr(ThreadId).pipe(
248 Schema.withDecodingDefault(Effect.succeed(null)),
249 ),
250 createdAt: IsoDateTime,
251 updatedAt: IsoDateTime,
252});
253export type OrchestrationProposedPlan = typeof OrchestrationProposedPlan.Type;
254​
255const SourceProposedPlanReference = Schema.Struct({
256 threadId: ThreadId,
257 planId: OrchestrationProposedPlanId,
258});
259​
260export const OrchestrationSessionStatus = Schema.Literals([
261 "idle",
262 "starting",
263 "running",
264 "ready",
265 "interrupted",
266 "stopped",
267 "error",
268]);
269export type OrchestrationSessionStatus = typeof OrchestrationSessionStatus.Type;
270​
271export const OrchestrationSession = Schema.Struct({
272 threadId: ThreadId,
273 status: OrchestrationSessionStatus,
274 providerName: Schema.NullOr(TrimmedNonEmptyString),
275 providerInstanceId: Schema.optional(ProviderInstanceId),
276 runtimeMode: RuntimeMode.pipe(Schema.withDecodingDefault(Effect.succeed(DEFAULT_RUNTIME_MODE))),
277 activeTurnId: Schema.NullOr(TurnId),
278 lastError: Schema.NullOr(TrimmedNonEmptyString),
279 updatedAt: IsoDateTime,
280});
281export type OrchestrationSession = typeof OrchestrationSession.Type;
282​
283export const OrchestrationCheckpointFile = Schema.Struct({
284 path: TrimmedNonEmptyString,
285 kind: TrimmedNonEmptyString,
286 additions: NonNegativeInt,
287 deletions: NonNegativeInt,
288});
289export type OrchestrationCheckpointFile = typeof OrchestrationCheckpointFile.Type;
290​
291export const OrchestrationCheckpointStatus = Schema.Literals(["ready", "missing", "error"]);
292export type OrchestrationCheckpointStatus = typeof OrchestrationCheckpointStatus.Type;
293​
294export const OrchestrationCheckpointSummary = Schema.Struct({
295 turnId: TurnId,
296 checkpointTurnCount: NonNegativeInt,
297 checkpointRef: CheckpointRef,
298 status: OrchestrationCheckpointStatus,
299 files: Schema.Array(OrchestrationCheckpointFile),
300 assistantMessageId: Schema.NullOr(MessageId),
301 completedAt: IsoDateTime,
302});
303export type OrchestrationCheckpointSummary = typeof OrchestrationCheckpointSummary.Type;
304​
305export const OrchestrationThreadActivityTone = Schema.Literals([
306 "info",
307 "tool",
308 "approval",
309 "error",
310]);
311export type OrchestrationThreadActivityTone = typeof OrchestrationThreadActivityTone.Type;
312​
313export const OrchestrationThreadActivity = Schema.Struct({
314 id: EventId,
315 tone: OrchestrationThreadActivityTone,
316 kind: TrimmedNonEmptyString,
317 summary: TrimmedNonEmptyString,
318 payload: Schema.Unknown,
319 turnId: Schema.NullOr(TurnId),
320 sequence: Schema.optional(NonNegativeInt),
321 createdAt: IsoDateTime,
322});
323export type OrchestrationThreadActivity = typeof OrchestrationThreadActivity.Type;
324​
325const OrchestrationLatestTurnState = Schema.Literals([
326 "running",
327 "interrupted",
328 "completed",
329 "error",
330]);
331export type OrchestrationLatestTurnState = typeof OrchestrationLatestTurnState.Type;
332​
333export const OrchestrationLatestTurn = Schema.Struct({
334 turnId: TurnId,
335 state: OrchestrationLatestTurnState,
336 requestedAt: IsoDateTime,
337 startedAt: Schema.NullOr(IsoDateTime),
338 completedAt: Schema.NullOr(IsoDateTime),
339 assistantMessageId: Schema.NullOr(MessageId),
340 sourceProposedPlan: Schema.optional(SourceProposedPlanReference),
341});
342export type OrchestrationLatestTurn = typeof OrchestrationLatestTurn.Type;
343​
344export const OrchestrationThread = Schema.Struct({
345 id: ThreadId,
346 projectId: ProjectId,
347 title: TrimmedNonEmptyString,
348 modelSelection: ModelSelection,
349 runtimeMode: RuntimeMode,
350 interactionMode: ProviderInteractionMode.pipe(
351 Schema.withDecodingDefault(Effect.succeed(DEFAULT_PROVIDER_INTERACTION_MODE)),
352 ),
353 branch: Schema.NullOr(TrimmedNonEmptyString),
354 worktreePath: Schema.NullOr(TrimmedNonEmptyString),
355 latestTurn: Schema.NullOr(OrchestrationLatestTurn),
356 createdAt: IsoDateTime,
357 updatedAt: IsoDateTime,
358 archivedAt: Schema.NullOr(IsoDateTime).pipe(Schema.withDecodingDefault(Effect.succeed(null))),
359 deletedAt: Schema.NullOr(IsoDateTime),
360 messages: Schema.Array(OrchestrationMessage),
361 proposedPlans: Schema.Array(OrchestrationProposedPlan).pipe(
362 Schema.withDecodingDefault(Effect.succeed([])),
363 ),
364 activities: Schema.Array(OrchestrationThreadActivity),
365 checkpoints: Schema.Array(OrchestrationCheckpointSummary),
366 session: Schema.NullOr(OrchestrationSession),
367});
368export type OrchestrationThread = typeof OrchestrationThread.Type;
369​
370export const OrchestrationReadModel = Schema.Struct({
371 snapshotSequence: NonNegativeInt,
372 projects: Schema.Array(OrchestrationProject),
373 threads: Schema.Array(OrchestrationThread),
374 updatedAt: IsoDateTime,
375});
376export type OrchestrationReadModel = typeof OrchestrationReadModel.Type;
377​
378export const OrchestrationProjectShell = Schema.Struct({
379 id: ProjectId,
380 title: TrimmedNonEmptyString,
381 workspaceRoot: TrimmedNonEmptyString,
382 repositoryIdentity: Schema.optional(Schema.NullOr(RepositoryIdentity)),
383 defaultModelSelection: Schema.NullOr(ModelSelection),
384 scripts: Schema.Array(ProjectScript),
385 createdAt: IsoDateTime,
386 updatedAt: IsoDateTime,
387});
388export type OrchestrationProjectShell = typeof OrchestrationProjectShell.Type;
389​
390export const OrchestrationThreadShell = Schema.Struct({
391 id: ThreadId,
392 projectId: ProjectId,
393 title: TrimmedNonEmptyString,
394 modelSelection: ModelSelection,
395 runtimeMode: RuntimeMode,
396 interactionMode: ProviderInteractionMode.pipe(
397 Schema.withDecodingDefault(Effect.succeed(DEFAULT_PROVIDER_INTERACTION_MODE)),
398 ),
399 branch: Schema.NullOr(TrimmedNonEmptyString),
400 worktreePath: Schema.NullOr(TrimmedNonEmptyString),
401 latestTurn: Schema.NullOr(OrchestrationLatestTurn),
402 createdAt: IsoDateTime,
403 updatedAt: IsoDateTime,
404 archivedAt: Schema.NullOr(IsoDateTime).pipe(Schema.withDecodingDefault(Effect.succeed(null))),
405 session: Schema.NullOr(OrchestrationSession),
406 latestUserMessageAt: Schema.NullOr(IsoDateTime),
407 hasPendingApprovals: Schema.Boolean,
408 hasPendingUserInput: Schema.Boolean,
409 hasActionableProposedPlan: Schema.Boolean,
410});
411export type OrchestrationThreadShell = typeof OrchestrationThreadShell.Type;
412​
413export const OrchestrationShellSnapshot = Schema.Struct({
414 snapshotSequence: NonNegativeInt,
415 projects: Schema.Array(OrchestrationProjectShell),
416 threads: Schema.Array(OrchestrationThreadShell),
417 updatedAt: IsoDateTime,
418});
419export type OrchestrationShellSnapshot = typeof OrchestrationShellSnapshot.Type;
420​
421export const OrchestrationShellStreamEvent = Schema.Union([
422 Schema.Struct({
423 kind: Schema.Literal("project-upserted"),
424 sequence: NonNegativeInt,
425 project: OrchestrationProjectShell,
426 }),
427 Schema.Struct({
428 kind: Schema.Literal("project-removed"),
429 sequence: NonNegativeInt,
430 projectId: ProjectId,
431 }),
432 Schema.Struct({
433 kind: Schema.Literal("thread-upserted"),
434 sequence: NonNegativeInt,
435 thread: OrchestrationThreadShell,
436 }),
437 Schema.Struct({
438 kind: Schema.Literal("thread-removed"),
439 sequence: NonNegativeInt,
440 threadId: ThreadId,
441 }),
442]);
443export type OrchestrationShellStreamEvent = typeof OrchestrationShellStreamEvent.Type;
444​
445export const OrchestrationShellStreamItem = Schema.Union([
446 Schema.Struct({
447 kind: Schema.Literal("snapshot"),
448 snapshot: OrchestrationShellSnapshot,
449 }),
450 OrchestrationShellStreamEvent,
451]);
452export type OrchestrationShellStreamItem = typeof OrchestrationShellStreamItem.Type;
453​
454export const OrchestrationSubscribeShellInput = Schema.Struct({
455 /**
456 * When provided, the server skips the initial full shell snapshot and instead
457 * replays shell events after this sequence before streaming live events.
458 * Clients that already hold a cached (or HTTP-loaded) shell snapshot pass its
459 * sequence here so the subscription resumes without re-sending the entire
460 * projects/threads list (overlapping events are deduped by sequence on the
461 * client).
462 */
463 afterSequence: Schema.optionalKey(NonNegativeInt),
464});
465export type OrchestrationSubscribeShellInput = typeof OrchestrationSubscribeShellInput.Type;
466​
467export const OrchestrationSubscribeThreadInput = Schema.Struct({
468 threadId: ThreadId,
469 /**
470 * When provided, the server skips the initial snapshot frame and instead
471 * replays events after this sequence before streaming live events. Clients
472 * that load the snapshot over HTTP pass the snapshot's sequence here so the
473 * live subscription resumes without a gap (overlapping events are deduped by
474 * sequence on the client).
475 */
476 afterSequence: Schema.optionalKey(NonNegativeInt),
477});
478export type OrchestrationSubscribeThreadInput = typeof OrchestrationSubscribeThreadInput.Type;
479​
480export const OrchestrationThreadDetailSnapshot = Schema.Struct({
481 snapshotSequence: NonNegativeInt,
482 thread: OrchestrationThread,
483});
484export type OrchestrationThreadDetailSnapshot = typeof OrchestrationThreadDetailSnapshot.Type;
485​
486export const ProjectCreateCommand = Schema.Struct({
487 type: Schema.Literal("project.create"),
488 commandId: CommandId,
489 projectId: ProjectId,
490 title: TrimmedNonEmptyString,
491 workspaceRoot: TrimmedNonEmptyString,
492 createWorkspaceRootIfMissing: Schema.optional(Schema.Boolean),
493 defaultModelSelection: Schema.optional(Schema.NullOr(ModelSelection)),
494 createdAt: IsoDateTime,
495});
496​
497const ProjectMetaUpdateCommand = Schema.Struct({
498 type: Schema.Literal("project.meta.update"),
499 commandId: CommandId,
500 projectId: ProjectId,
501 title: Schema.optional(TrimmedNonEmptyString),
502 workspaceRoot: Schema.optional(TrimmedNonEmptyString),
503 defaultModelSelection: Schema.optional(Schema.NullOr(ModelSelection)),
504 scripts: Schema.optional(Schema.Array(ProjectScript)),
505});
506​
507const ProjectDeleteCommand = Schema.Struct({
508 type: Schema.Literal("project.delete"),
509 commandId: CommandId,
510 projectId: ProjectId,
511 force: Schema.optional(Schema.Boolean),
512});
513​
514const ThreadCreateCommand = Schema.Struct({
515 type: Schema.Literal("thread.create"),
516 commandId: CommandId,
517 threadId: ThreadId,
518 projectId: ProjectId,
519 title: TrimmedNonEmptyString,
520 modelSelection: ModelSelection,
521 runtimeMode: RuntimeMode,
522 interactionMode: ProviderInteractionMode.pipe(
523 Schema.withDecodingDefault(Effect.succeed(DEFAULT_PROVIDER_INTERACTION_MODE)),
524 ),
525 branch: Schema.NullOr(TrimmedNonEmptyString),
526 worktreePath: Schema.NullOr(TrimmedNonEmptyString),
527 createdAt: IsoDateTime,
528});
529​
530const ThreadDeleteCommand = Schema.Struct({
531 type: Schema.Literal("thread.delete"),
532 commandId: CommandId,
533 threadId: ThreadId,
534});
535​
536const ThreadArchiveCommand = Schema.Struct({
537 type: Schema.Literal("thread.archive"),
538 commandId: CommandId,
539 threadId: ThreadId,
540});
541​
542const ThreadUnarchiveCommand = Schema.Struct({
543 type: Schema.Literal("thread.unarchive"),
544 commandId: CommandId,
545 threadId: ThreadId,
546});
547​
548const ThreadMetaUpdateCommand = Schema.Struct({
549 type: Schema.Literal("thread.meta.update"),
550 commandId: CommandId,
551 threadId: ThreadId,
552 title: Schema.optional(TrimmedNonEmptyString),
553 modelSelection: Schema.optional(ModelSelection),
554 branch: Schema.optional(Schema.NullOr(TrimmedNonEmptyString)),
555 expectedBranch: Schema.optional(Schema.NullOr(TrimmedNonEmptyString)),
556 worktreePath: Schema.optional(Schema.NullOr(TrimmedNonEmptyString)),
557});
558​
559const ThreadRuntimeModeSetCommand = Schema.Struct({
560 type: Schema.Literal("thread.runtime-mode.set"),
561 commandId: CommandId,
562 threadId: ThreadId,
563 runtimeMode: RuntimeMode,
564 createdAt: IsoDateTime,
565});
566​
567const ThreadInteractionModeSetCommand = Schema.Struct({
568 type: Schema.Literal("thread.interaction-mode.set"),
569 commandId: CommandId,
570 threadId: ThreadId,
571 interactionMode: ProviderInteractionMode,
572 createdAt: IsoDateTime,
573});
574​
575const ThreadTurnStartBootstrapCreateThread = Schema.Struct({
576 projectId: ProjectId,
577 title: TrimmedNonEmptyString,
578 modelSelection: ModelSelection,
579 runtimeMode: RuntimeMode,
580 interactionMode: ProviderInteractionMode,
581 branch: Schema.NullOr(TrimmedNonEmptyString),
582 worktreePath: Schema.NullOr(TrimmedNonEmptyString),
583 createdAt: IsoDateTime,
584});
585​
586const ThreadTurnStartBootstrapPrepareWorktree = Schema.Struct({
587 projectCwd: TrimmedNonEmptyString,
588 baseBranch: TrimmedNonEmptyString,
589 branch: Schema.optional(TrimmedNonEmptyString),
590 startFromOrigin: Schema.optional(Schema.Boolean),
591});
592​
593const ThreadTurnStartBootstrap = Schema.Struct({
594 createThread: Schema.optional(ThreadTurnStartBootstrapCreateThread),
595 prepareWorktree: Schema.optional(ThreadTurnStartBootstrapPrepareWorktree),
596 runSetupScript: Schema.optional(Schema.Boolean),
597});
598​
599export type ThreadTurnStartBootstrap = typeof ThreadTurnStartBootstrap.Type;
600​
601export const ThreadTurnStartCommand = Schema.Struct({
602 type: Schema.Literal("thread.turn.start"),
603 commandId: CommandId,
604 threadId: ThreadId,
605 message: Schema.Struct({
606 messageId: MessageId,
607 role: Schema.Literal("user"),
608 text: Schema.String,
609 attachments: Schema.Array(ChatAttachment),
610 }),
611 modelSelection: Schema.optional(ModelSelection),
612 titleSeed: Schema.optional(TrimmedNonEmptyString),
613 runtimeMode: RuntimeMode.pipe(Schema.withDecodingDefault(Effect.succeed(DEFAULT_RUNTIME_MODE))),
614 interactionMode: ProviderInteractionMode.pipe(
615 Schema.withDecodingDefault(Effect.succeed(DEFAULT_PROVIDER_INTERACTION_MODE)),
616 ),
617 bootstrap: Schema.optional(ThreadTurnStartBootstrap),
618 sourceProposedPlan: Schema.optional(SourceProposedPlanReference),
619 createdAt: IsoDateTime,
620});
621​
622const ClientThreadTurnStartCommand = Schema.Struct({
623 type: Schema.Literal("thread.turn.start"),
624 commandId: CommandId,
625 threadId: ThreadId,
626 message: Schema.Struct({
627 messageId: MessageId,
628 role: Schema.Literal("user"),
629 text: Schema.String,
630 attachments: Schema.Array(UploadChatAttachment),
631 }),
632 modelSelection: Schema.optional(ModelSelection),
633 titleSeed: Schema.optional(TrimmedNonEmptyString),
634 runtimeMode: RuntimeMode,
635 interactionMode: ProviderInteractionMode,
636 bootstrap: Schema.optional(ThreadTurnStartBootstrap),
637 sourceProposedPlan: Schema.optional(SourceProposedPlanReference),
638 createdAt: IsoDateTime,
639});
640​
641const ThreadTurnInterruptCommand = Schema.Struct({
642 type: Schema.Literal("thread.turn.interrupt"),
643 commandId: CommandId,
644 threadId: ThreadId,
645 turnId: Schema.optional(TurnId),
646 createdAt: IsoDateTime,
647});
648​
649const ThreadApprovalRespondCommand = Schema.Struct({
650 type: Schema.Literal("thread.approval.respond"),
651 commandId: CommandId,
652 threadId: ThreadId,
653 requestId: ApprovalRequestId,
654 decision: ProviderApprovalDecision,
655 createdAt: IsoDateTime,
656});
657​
658const ThreadUserInputRespondCommand = Schema.Struct({
659 type: Schema.Literal("thread.user-input.respond"),
660 commandId: CommandId,
661 threadId: ThreadId,
662 requestId: ApprovalRequestId,
663 answers: ProviderUserInputAnswers,
664 createdAt: IsoDateTime,
665});
666​
667const ThreadCheckpointRevertCommand = Schema.Struct({
668 type: Schema.Literal("thread.checkpoint.revert"),
669 commandId: CommandId,
670 threadId: ThreadId,
671 turnCount: NonNegativeInt,
672 createdAt: IsoDateTime,
673});
674​
675const ThreadSessionStopCommand = Schema.Struct({
676 type: Schema.Literal("thread.session.stop"),
677 commandId: CommandId,
678 threadId: ThreadId,
679 createdAt: IsoDateTime,
680});
681​
682const DispatchableClientOrchestrationCommand = Schema.Union([
683 ProjectCreateCommand,
684 ProjectMetaUpdateCommand,
685 ProjectDeleteCommand,
686 ThreadCreateCommand,
687 ThreadDeleteCommand,
688 ThreadArchiveCommand,
689 ThreadUnarchiveCommand,
690 ThreadMetaUpdateCommand,
691 ThreadRuntimeModeSetCommand,
692 ThreadInteractionModeSetCommand,
693 ThreadTurnStartCommand,
694 ThreadTurnInterruptCommand,
695 ThreadApprovalRespondCommand,
696 ThreadUserInputRespondCommand,
697 ThreadCheckpointRevertCommand,
698 ThreadSessionStopCommand,
699]);
700export type DispatchableClientOrchestrationCommand =
701 typeof DispatchableClientOrchestrationCommand.Type;
702​
703export const ClientOrchestrationCommand = Schema.Union([
704 ProjectCreateCommand,
705 ProjectMetaUpdateCommand,
706 ProjectDeleteCommand,
707 ThreadCreateCommand,
708 ThreadDeleteCommand,
709 ThreadArchiveCommand,
710 ThreadUnarchiveCommand,
711 ThreadMetaUpdateCommand,
712 ThreadRuntimeModeSetCommand,
713 ThreadInteractionModeSetCommand,
714 ClientThreadTurnStartCommand,
715 ThreadTurnInterruptCommand,
716 ThreadApprovalRespondCommand,
717 ThreadUserInputRespondCommand,
718 ThreadCheckpointRevertCommand,
719 ThreadSessionStopCommand,
720]);
721export type ClientOrchestrationCommand = typeof ClientOrchestrationCommand.Type;
722​
723const ThreadSessionSetCommand = Schema.Struct({
724 type: Schema.Literal("thread.session.set"),
725 commandId: CommandId,
726 threadId: ThreadId,
727 session: OrchestrationSession,
728 createdAt: IsoDateTime,
729});
730​
731const ThreadMessageAssistantDeltaCommand = Schema.Struct({
732 type: Schema.Literal("thread.message.assistant.delta"),
733 commandId: CommandId,
734 threadId: ThreadId,
735 messageId: MessageId,
736 delta: Schema.String,
737 turnId: Schema.optional(TurnId),
738 createdAt: IsoDateTime,
739});
740​
741const ThreadMessageAssistantCompleteCommand = Schema.Struct({
742 type: Schema.Literal("thread.message.assistant.complete"),
743 commandId: CommandId,
744 threadId: ThreadId,
745 messageId: MessageId,
746 turnId: Schema.optional(TurnId),
747 createdAt: IsoDateTime,
748});
749​
750const ThreadProposedPlanUpsertCommand = Schema.Struct({
751 type: Schema.Literal("thread.proposed-plan.upsert"),
752 commandId: CommandId,
753 threadId: ThreadId,
754 proposedPlan: OrchestrationProposedPlan,
755 createdAt: IsoDateTime,
756});
757​
758const ThreadTurnDiffCompleteCommand = Schema.Struct({
759 type: Schema.Literal("thread.turn.diff.complete"),
760 commandId: CommandId,
761 threadId: ThreadId,
762 turnId: TurnId,
763 completedAt: IsoDateTime,
764 checkpointRef: CheckpointRef,
765 status: OrchestrationCheckpointStatus,
766 files: Schema.Array(OrchestrationCheckpointFile),
767 assistantMessageId: Schema.optional(MessageId),
768 checkpointTurnCount: NonNegativeInt,
769 createdAt: IsoDateTime,
770});
771​
772const ThreadActivityAppendCommand = Schema.Struct({
773 type: Schema.Literal("thread.activity.append"),
774 commandId: CommandId,
775 threadId: ThreadId,
776 activity: OrchestrationThreadActivity,
777 createdAt: IsoDateTime,
778});
779​
780const ThreadRevertCompleteCommand = Schema.Struct({
781 type: Schema.Literal("thread.revert.complete"),
782 commandId: CommandId,
783 threadId: ThreadId,
784 turnCount: NonNegativeInt,
785 createdAt: IsoDateTime,
786});
787​
788const InternalOrchestrationCommand = Schema.Union([
789 ThreadSessionSetCommand,
790 ThreadMessageAssistantDeltaCommand,
791 ThreadMessageAssistantCompleteCommand,
792 ThreadProposedPlanUpsertCommand,
793 ThreadTurnDiffCompleteCommand,
794 ThreadActivityAppendCommand,
795 ThreadRevertCompleteCommand,
796]);
797export type InternalOrchestrationCommand = typeof InternalOrchestrationCommand.Type;
798​
799export const OrchestrationCommand = Schema.Union([
800 DispatchableClientOrchestrationCommand,
801 InternalOrchestrationCommand,
802]);
803export type OrchestrationCommand = typeof OrchestrationCommand.Type;
804​
805export const OrchestrationEventType = Schema.Literals([
806 "project.created",
807 "project.meta-updated",
808 "project.deleted",
809 "thread.created",
810 "thread.deleted",
811 "thread.archived",
812 "thread.unarchived",
813 "thread.meta-updated",
814 "thread.runtime-mode-set",
815 "thread.interaction-mode-set",
816 "thread.message-sent",
817 "thread.turn-start-requested",
818 "thread.turn-interrupt-requested",
819 "thread.approval-response-requested",
820 "thread.user-input-response-requested",
821 "thread.checkpoint-revert-requested",
822 "thread.reverted",
823 "thread.session-stop-requested",
824 "thread.session-set",
825 "thread.proposed-plan-upserted",
826 "thread.turn-diff-completed",
827 "thread.activity-appended",
828]);
829export type OrchestrationEventType = typeof OrchestrationEventType.Type;
830​
831export const OrchestrationAggregateKind = Schema.Literals(["project", "thread"]);
832export type OrchestrationAggregateKind = typeof OrchestrationAggregateKind.Type;
833export const OrchestrationActorKind = Schema.Literals(["client", "server", "provider"]);
834​
835export const ProjectCreatedPayload = Schema.Struct({
836 projectId: ProjectId,
837 title: TrimmedNonEmptyString,
838 workspaceRoot: TrimmedNonEmptyString,
839 repositoryIdentity: Schema.optional(Schema.NullOr(RepositoryIdentity)),
840 defaultModelSelection: Schema.NullOr(ModelSelection),
841 scripts: Schema.Array(ProjectScript),
842 createdAt: IsoDateTime,
843 updatedAt: IsoDateTime,
844});
845​
846export const ProjectMetaUpdatedPayload = Schema.Struct({
847 projectId: ProjectId,
848 title: Schema.optional(TrimmedNonEmptyString),
849 workspaceRoot: Schema.optional(TrimmedNonEmptyString),
850 repositoryIdentity: Schema.optional(Schema.NullOr(RepositoryIdentity)),
851 defaultModelSelection: Schema.optional(Schema.NullOr(ModelSelection)),
852 scripts: Schema.optional(Schema.Array(ProjectScript)),
853 updatedAt: IsoDateTime,
854});
855​
856export const ProjectDeletedPayload = Schema.Struct({
857 projectId: ProjectId,
858 deletedAt: IsoDateTime,
859});
860​
861export const ThreadCreatedPayload = Schema.Struct({
862 threadId: ThreadId,
863 projectId: ProjectId,
864 title: TrimmedNonEmptyString,
865 modelSelection: ModelSelection,
866 runtimeMode: RuntimeMode.pipe(Schema.withDecodingDefault(Effect.succeed(DEFAULT_RUNTIME_MODE))),
867 interactionMode: ProviderInteractionMode.pipe(
868 Schema.withDecodingDefault(Effect.succeed(DEFAULT_PROVIDER_INTERACTION_MODE)),
869 ),
870 branch: Schema.NullOr(TrimmedNonEmptyString),
871 worktreePath: Schema.NullOr(TrimmedNonEmptyString),
872 createdAt: IsoDateTime,
873 updatedAt: IsoDateTime,
874});
875​
876export const ThreadDeletedPayload = Schema.Struct({
877 threadId: ThreadId,
878 deletedAt: IsoDateTime,
879});
880​
881export const ThreadArchivedPayload = Schema.Struct({
882 threadId: ThreadId,
883 archivedAt: IsoDateTime,
884 updatedAt: IsoDateTime,
885});
886​
887export const ThreadUnarchivedPayload = Schema.Struct({
888 threadId: ThreadId,
889 updatedAt: IsoDateTime,
890});
891​
892export const ThreadMetaUpdatedPayload = Schema.Struct({
893 threadId: ThreadId,
894 title: Schema.optional(TrimmedNonEmptyString),
895 modelSelection: Schema.optional(ModelSelection),
896 branch: Schema.optional(Schema.NullOr(TrimmedNonEmptyString)),
897 worktreePath: Schema.optional(Schema.NullOr(TrimmedNonEmptyString)),
898 updatedAt: IsoDateTime,
899});
900​
901export const ThreadRuntimeModeSetPayload = Schema.Struct({
902 threadId: ThreadId,
903 runtimeMode: RuntimeMode,
904 updatedAt: IsoDateTime,
905});
906​
907export const ThreadInteractionModeSetPayload = Schema.Struct({
908 threadId: ThreadId,
909 interactionMode: ProviderInteractionMode.pipe(
910 Schema.withDecodingDefault(Effect.succeed(DEFAULT_PROVIDER_INTERACTION_MODE)),
911 ),
912 updatedAt: IsoDateTime,
913});
914​
915export const ThreadMessageSentPayload = Schema.Struct({
916 threadId: ThreadId,
917 messageId: MessageId,
918 role: OrchestrationMessageRole,
919 text: Schema.String,
920 attachments: Schema.optional(Schema.Array(ChatAttachment)),
921 turnId: Schema.NullOr(TurnId),
922 streaming: Schema.Boolean,
923 createdAt: IsoDateTime,
924 updatedAt: IsoDateTime,
925});
926​
927export const ThreadTurnStartRequestedPayload = Schema.Struct({
928 threadId: ThreadId,
929 messageId: MessageId,
930 modelSelection: Schema.optional(ModelSelection),
931 titleSeed: Schema.optional(TrimmedNonEmptyString),
932 runtimeMode: RuntimeMode.pipe(Schema.withDecodingDefault(Effect.succeed(DEFAULT_RUNTIME_MODE))),
933 interactionMode: ProviderInteractionMode.pipe(
934 Schema.withDecodingDefault(Effect.succeed(DEFAULT_PROVIDER_INTERACTION_MODE)),
935 ),
936 sourceProposedPlan: Schema.optional(SourceProposedPlanReference),
937 createdAt: IsoDateTime,
938});
939​
940export const ThreadTurnInterruptRequestedPayload = Schema.Struct({
941 threadId: ThreadId,
942 turnId: Schema.optional(TurnId),
943 createdAt: IsoDateTime,
944});
945​
946export const ThreadApprovalResponseRequestedPayload = Schema.Struct({
947 threadId: ThreadId,
948 requestId: ApprovalRequestId,
949 decision: ProviderApprovalDecision,
950 createdAt: IsoDateTime,
951});
952​
953const ThreadUserInputResponseRequestedPayload = Schema.Struct({
954 threadId: ThreadId,
955 requestId: ApprovalRequestId,
956 answers: ProviderUserInputAnswers,
957 createdAt: IsoDateTime,
958});
959​
960export const ThreadCheckpointRevertRequestedPayload = Schema.Struct({
961 threadId: ThreadId,
962 turnCount: NonNegativeInt,
963 createdAt: IsoDateTime,
964});
965​
966export const ThreadRevertedPayload = Schema.Struct({
967 threadId: ThreadId,
968 turnCount: NonNegativeInt,
969});
970​
971export const ThreadSessionStopRequestedPayload = Schema.Struct({
972 threadId: ThreadId,
973 createdAt: IsoDateTime,
974});
975​
976export const ThreadSessionSetPayload = Schema.Struct({
977 threadId: ThreadId,
978 session: OrchestrationSession,
979});
980​
981export const ThreadProposedPlanUpsertedPayload = Schema.Struct({
982 threadId: ThreadId,
983 proposedPlan: OrchestrationProposedPlan,
984});
985​
986export const ThreadTurnDiffCompletedPayload = Schema.Struct({
987 threadId: ThreadId,
988 turnId: TurnId,
989 checkpointTurnCount: NonNegativeInt,
990 checkpointRef: CheckpointRef,
991 status: OrchestrationCheckpointStatus,
992 files: Schema.Array(OrchestrationCheckpointFile),
993 assistantMessageId: Schema.NullOr(MessageId),
994 completedAt: IsoDateTime,
995});
996​
997export const ThreadActivityAppendedPayload = Schema.Struct({
998 threadId: ThreadId,
999 activity: OrchestrationThreadActivity,
1000});
1001​
1002export const OrchestrationEventMetadata = Schema.Struct({
1003 providerTurnId: Schema.optional(TrimmedNonEmptyString),
1004 providerItemId: Schema.optional(ProviderItemId),
1005 adapterKey: Schema.optional(TrimmedNonEmptyString),
1006 requestId: Schema.optional(ApprovalRequestId),
1007 ingestedAt: Schema.optional(IsoDateTime),
1008});
1009export type OrchestrationEventMetadata = typeof OrchestrationEventMetadata.Type;
1010​
1011const EventBaseFields = {
1012 sequence: NonNegativeInt,
1013 eventId: EventId,
1014 aggregateKind: OrchestrationAggregateKind,
1015 aggregateId: Schema.Union([ProjectId, ThreadId]),
1016 occurredAt: IsoDateTime,
1017 commandId: Schema.NullOr(CommandId),
1018 causationEventId: Schema.NullOr(EventId),
1019 correlationId: Schema.NullOr(CommandId),
1020 metadata: OrchestrationEventMetadata,
1021} as const;
1022​
1023export const OrchestrationEvent = Schema.Union([
1024 Schema.Struct({
1025 ...EventBaseFields,
1026 type: Schema.Literal("project.created"),
1027 payload: ProjectCreatedPayload,
1028 }),
1029 Schema.Struct({
1030 ...EventBaseFields,
1031 type: Schema.Literal("project.meta-updated"),
1032 payload: ProjectMetaUpdatedPayload,
1033 }),
1034 Schema.Struct({
1035 ...EventBaseFields,
1036 type: Schema.Literal("project.deleted"),
1037 payload: ProjectDeletedPayload,
1038 }),
1039 Schema.Struct({
1040 ...EventBaseFields,
1041 type: Schema.Literal("thread.created"),
1042 payload: ThreadCreatedPayload,
1043 }),
1044 Schema.Struct({
1045 ...EventBaseFields,
1046 type: Schema.Literal("thread.deleted"),
1047 payload: ThreadDeletedPayload,
1048 }),
1049 Schema.Struct({
1050 ...EventBaseFields,
1051 type: Schema.Literal("thread.archived"),
1052 payload: ThreadArchivedPayload,
1053 }),
1054 Schema.Struct({
1055 ...EventBaseFields,
1056 type: Schema.Literal("thread.unarchived"),
1057 payload: ThreadUnarchivedPayload,
1058 }),
1059 Schema.Struct({
1060 ...EventBaseFields,
1061 type: Schema.Literal("thread.meta-updated"),
1062 payload: ThreadMetaUpdatedPayload,
1063 }),
1064 Schema.Struct({
1065 ...EventBaseFields,
1066 type: Schema.Literal("thread.runtime-mode-set"),
1067 payload: ThreadRuntimeModeSetPayload,
1068 }),
1069 Schema.Struct({
1070 ...EventBaseFields,
1071 type: Schema.Literal("thread.interaction-mode-set"),
1072 payload: ThreadInteractionModeSetPayload,
1073 }),
1074 Schema.Struct({
1075 ...EventBaseFields,
1076 type: Schema.Literal("thread.message-sent"),
1077 payload: ThreadMessageSentPayload,
1078 }),
1079 Schema.Struct({
1080 ...EventBaseFields,
1081 type: Schema.Literal("thread.turn-start-requested"),
1082 payload: ThreadTurnStartRequestedPayload,
1083 }),
1084 Schema.Struct({
1085 ...EventBaseFields,
1086 type: Schema.Literal("thread.turn-interrupt-requested"),
1087 payload: ThreadTurnInterruptRequestedPayload,
1088 }),
1089 Schema.Struct({
1090 ...EventBaseFields,
1091 type: Schema.Literal("thread.approval-response-requested"),
1092 payload: ThreadApprovalResponseRequestedPayload,
1093 }),
1094 Schema.Struct({
1095 ...EventBaseFields,
1096 type: Schema.Literal("thread.user-input-response-requested"),
1097 payload: ThreadUserInputResponseRequestedPayload,
1098 }),
1099 Schema.Struct({
1100 ...EventBaseFields,
1101 type: Schema.Literal("thread.checkpoint-revert-requested"),
1102 payload: ThreadCheckpointRevertRequestedPayload,
1103 }),
1104 Schema.Struct({
1105 ...EventBaseFields,
1106 type: Schema.Literal("thread.reverted"),
1107 payload: ThreadRevertedPayload,
1108 }),
1109 Schema.Struct({
1110 ...EventBaseFields,
1111 type: Schema.Literal("thread.session-stop-requested"),
1112 payload: ThreadSessionStopRequestedPayload,
1113 }),
1114 Schema.Struct({
1115 ...EventBaseFields,
1116 type: Schema.Literal("thread.session-set"),
1117 payload: ThreadSessionSetPayload,
1118 }),
1119 Schema.Struct({
1120 ...EventBaseFields,
1121 type: Schema.Literal("thread.proposed-plan-upserted"),
1122 payload: ThreadProposedPlanUpsertedPayload,
1123 }),
1124 Schema.Struct({
1125 ...EventBaseFields,
1126 type: Schema.Literal("thread.turn-diff-completed"),
1127 payload: ThreadTurnDiffCompletedPayload,
1128 }),
1129 Schema.Struct({
1130 ...EventBaseFields,
1131 type: Schema.Literal("thread.activity-appended"),
1132 payload: ThreadActivityAppendedPayload,
1133 }),
1134]);
1135export type OrchestrationEvent = typeof OrchestrationEvent.Type;
1136​
1137export const OrchestrationThreadStreamItem = Schema.Union([
1138 Schema.Struct({
1139 kind: Schema.Literal("snapshot"),
1140 snapshot: OrchestrationThreadDetailSnapshot,
1141 }),
1142 Schema.Struct({
1143 kind: Schema.Literal("event"),
1144 event: OrchestrationEvent,
1145 }),
1146]);
1147export type OrchestrationThreadStreamItem = typeof OrchestrationThreadStreamItem.Type;
1148​
1149export const OrchestrationCommandReceiptStatus = Schema.Literals(["accepted", "rejected"]);
1150export type OrchestrationCommandReceiptStatus = typeof OrchestrationCommandReceiptStatus.Type;
1151​
1152export const TurnCountRange = Schema.Struct({
1153 fromTurnCount: NonNegativeInt,
1154 toTurnCount: NonNegativeInt,
1155}).check(
1156 Schema.makeFilter(
1157 (input) =>
1158 input.fromTurnCount <= input.toTurnCount ||
1159 new SchemaIssue.InvalidValue(Option.some(input.fromTurnCount), {
1160 message: "fromTurnCount must be less than or equal to toTurnCount",
1161 }),
1162 { identifier: "OrchestrationTurnDiffRange" },
1163 ),
1165​
1166export const ThreadTurnDiff = TurnCountRange.mapFields(
1167 Struct.assign({
1168 threadId: ThreadId,
1169 diff: Schema.String,
1170 }),
1171 { unsafePreserveChecks: true },
1173​
1174export const ProviderSessionRuntimeStatus = Schema.Literals([
1175 "starting",
1176 "running",
1177 "stopped",
1178 "error",
1179]);
1180export type ProviderSessionRuntimeStatus = typeof ProviderSessionRuntimeStatus.Type;
1181​
1182const ProjectionThreadTurnStatus = Schema.Literals([
1183 "running",
1184 "completed",
1185 "interrupted",
1186 "error",
1187]);
1188export type ProjectionThreadTurnStatus = typeof ProjectionThreadTurnStatus.Type;
1189​
1190const ProjectionCheckpointRow = Schema.Struct({
1191 threadId: ThreadId,
1192 turnId: TurnId,
1193 checkpointTurnCount: NonNegativeInt,
1194 checkpointRef: CheckpointRef,
1195 status: OrchestrationCheckpointStatus,
1196 files: Schema.Array(OrchestrationCheckpointFile),
1197 assistantMessageId: Schema.NullOr(MessageId),
1198 completedAt: IsoDateTime,
1199});
1200export type ProjectionCheckpointRow = typeof ProjectionCheckpointRow.Type;
1201​
1202export const ProjectionPendingApprovalStatus = Schema.Literals(["pending", "resolved"]);
1203export type ProjectionPendingApprovalStatus = typeof ProjectionPendingApprovalStatus.Type;
1204​
1205export const ProjectionPendingApprovalDecision = Schema.NullOr(ProviderApprovalDecision);
1206export type ProjectionPendingApprovalDecision = typeof ProjectionPendingApprovalDecision.Type;
1207​
1208export const DispatchResult = Schema.Struct({
1209 sequence: NonNegativeInt,
1210});
1211export type DispatchResult = typeof DispatchResult.Type;
1212​
1213export const OrchestrationGetTurnDiffInput = TurnCountRange.mapFields(
1214 Struct.assign({
1215 threadId: ThreadId,
1216 ignoreWhitespace: Schema.optionalKey(Schema.Boolean),
1217 }),
1218 { unsafePreserveChecks: true },
1220export type OrchestrationGetTurnDiffInput = typeof OrchestrationGetTurnDiffInput.Type;
1221​
1222export const OrchestrationGetTurnDiffResult = ThreadTurnDiff;
1223export type OrchestrationGetTurnDiffResult = typeof OrchestrationGetTurnDiffResult.Type;
1224​
1225export const OrchestrationGetFullThreadDiffInput = Schema.Struct({
1226 threadId: ThreadId,
1227 toTurnCount: NonNegativeInt,
1228 ignoreWhitespace: Schema.optionalKey(Schema.Boolean),
1229});
1230export type OrchestrationGetFullThreadDiffInput = typeof OrchestrationGetFullThreadDiffInput.Type;
1231​
1232export const OrchestrationGetFullThreadDiffResult = ThreadTurnDiff;
1233export type OrchestrationGetFullThreadDiffResult = typeof OrchestrationGetFullThreadDiffResult.Type;
1234​
1235export const OrchestrationReplayEventsInput = Schema.Struct({
1236 fromSequenceExclusive: NonNegativeInt,
1237});
1238export type OrchestrationReplayEventsInput = typeof OrchestrationReplayEventsInput.Type;
1239​
1240const OrchestrationReplayEventsResult = Schema.Array(OrchestrationEvent);
1241export type OrchestrationReplayEventsResult = typeof OrchestrationReplayEventsResult.Type;
1242​
1243export const OrchestrationRpcSchemas = {
1244 dispatchCommand: {
1245 input: ClientOrchestrationCommand,
1246 output: DispatchResult,
1247 },
1248 getTurnDiff: {
1249 input: OrchestrationGetTurnDiffInput,
1250 output: OrchestrationGetTurnDiffResult,
1251 },
1252 getFullThreadDiff: {
1253 input: OrchestrationGetFullThreadDiffInput,
1254 output: OrchestrationGetFullThreadDiffResult,
1255 },
1256 replayEvents: {
1257 input: OrchestrationReplayEventsInput,
1258 output: OrchestrationReplayEventsResult,
1259 },
1260 getArchivedShellSnapshot: {
1261 input: Schema.Struct({}),
1262 output: OrchestrationShellSnapshot,
1263 },
1264 subscribeThread: {
1265 input: OrchestrationSubscribeThreadInput,
1266 output: OrchestrationThreadStreamItem,
1267 },
1268 subscribeShell: {
1269 input: OrchestrationSubscribeShellInput,
1270 output: OrchestrationShellStreamItem,
1271 },
1272} as const;
1273​
1274export class OrchestrationGetSnapshotError extends Schema.TaggedErrorClass<OrchestrationGetSnapshotError>()(
1275 "OrchestrationGetSnapshotError",
1277 message: TrimmedNonEmptyString,
1278 cause: Schema.optional(Schema.Defect()),
1279 },
1280) {}
1281​
1282export class OrchestrationDispatchCommandError extends Schema.TaggedErrorClass<OrchestrationDispatchCommandError>()(
1283 "OrchestrationDispatchCommandError",
1285 message: TrimmedNonEmptyString,
1286 cause: Schema.optional(Schema.Defect()),
1287 },
1288) {}
1289​
1290export class OrchestrationGetTurnDiffError extends Schema.TaggedErrorClass<OrchestrationGetTurnDiffError>()(
1291 "OrchestrationGetTurnDiffError",
1293 message: TrimmedNonEmptyString,
1294 cause: Schema.optional(Schema.Defect()),
1295 },
1296) {}
1297​
1298export class OrchestrationGetFullThreadDiffError extends Schema.TaggedErrorClass<OrchestrationGetFullThreadDiffError>()(
1299 "OrchestrationGetFullThreadDiffError",
1301 message: TrimmedNonEmptyString,
1302 cause: Schema.optional(Schema.Defect()),
1303 },
1304) {}
1305​
1306export class OrchestrationReplayEventsError extends Schema.TaggedErrorClass<OrchestrationReplayEventsError>()(
1307 "OrchestrationReplayEventsError",
1309 message: TrimmedNonEmptyString,
1310 cause: Schema.optional(Schema.Defect()),
1311 },
1312) {}