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

orchestration.ts

1,328 lines43.7 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("synchronized"),
448 }),
449 Schema.Struct({
450 kind: Schema.Literal("snapshot"),
451 snapshot: OrchestrationShellSnapshot,
452 }),
453 OrchestrationShellStreamEvent,
454]);
455export type OrchestrationShellStreamItem = typeof OrchestrationShellStreamItem.Type;
456​
457export const OrchestrationSubscribeShellInput = Schema.Struct({
458 /**
459 * When provided, the server skips the initial full shell snapshot and instead
460 * replays shell events after this sequence before streaming live events.
461 * Clients that already hold a cached (or HTTP-loaded) shell snapshot pass its
462 * sequence here so the subscription resumes without re-sending the entire
463 * projects/threads list (overlapping events are deduped by sequence on the
464 * client).
465 */
466 afterSequence: Schema.optionalKey(NonNegativeInt),
467 /**
468 * Requests an explicit marker after the subscription has emitted its initial
469 * snapshot or catch-up replay and before it begins emitting live events.
470 */
471 requestCompletionMarker: Schema.optionalKey(Schema.Boolean),
472});
473export type OrchestrationSubscribeShellInput = typeof OrchestrationSubscribeShellInput.Type;
474​
475export const OrchestrationSubscribeThreadInput = Schema.Struct({
476 threadId: ThreadId,
477 /**
478 * When provided, the server skips the initial snapshot frame and instead
479 * replays events after this sequence before streaming live events. Clients
480 * that load the snapshot over HTTP pass the snapshot's sequence here so the
481 * live subscription resumes without a gap (overlapping events are deduped by
482 * sequence on the client).
483 */
484 afterSequence: Schema.optionalKey(NonNegativeInt),
485 /**
486 * Requests an explicit marker after the subscription has emitted its initial
487 * snapshot or catch-up replay and before it begins emitting live events.
488 */
489 requestCompletionMarker: Schema.optionalKey(Schema.Boolean),
490});
491export type OrchestrationSubscribeThreadInput = typeof OrchestrationSubscribeThreadInput.Type;
492​
493export const OrchestrationThreadDetailSnapshot = Schema.Struct({
494 snapshotSequence: NonNegativeInt,
495 thread: OrchestrationThread,
496});
497export type OrchestrationThreadDetailSnapshot = typeof OrchestrationThreadDetailSnapshot.Type;
498​
499export const ProjectCreateCommand = Schema.Struct({
500 type: Schema.Literal("project.create"),
501 commandId: CommandId,
502 projectId: ProjectId,
503 title: TrimmedNonEmptyString,
504 workspaceRoot: TrimmedNonEmptyString,
505 createWorkspaceRootIfMissing: Schema.optional(Schema.Boolean),
506 defaultModelSelection: Schema.optional(Schema.NullOr(ModelSelection)),
507 createdAt: IsoDateTime,
508});
509​
510const ProjectMetaUpdateCommand = Schema.Struct({
511 type: Schema.Literal("project.meta.update"),
512 commandId: CommandId,
513 projectId: ProjectId,
514 title: Schema.optional(TrimmedNonEmptyString),
515 workspaceRoot: Schema.optional(TrimmedNonEmptyString),
516 defaultModelSelection: Schema.optional(Schema.NullOr(ModelSelection)),
517 scripts: Schema.optional(Schema.Array(ProjectScript)),
518});
519​
520const ProjectDeleteCommand = Schema.Struct({
521 type: Schema.Literal("project.delete"),
522 commandId: CommandId,
523 projectId: ProjectId,
524 force: Schema.optional(Schema.Boolean),
525});
526​
527const ThreadCreateCommand = Schema.Struct({
528 type: Schema.Literal("thread.create"),
529 commandId: CommandId,
530 threadId: ThreadId,
531 projectId: ProjectId,
532 title: TrimmedNonEmptyString,
533 modelSelection: ModelSelection,
534 runtimeMode: RuntimeMode,
535 interactionMode: ProviderInteractionMode.pipe(
536 Schema.withDecodingDefault(Effect.succeed(DEFAULT_PROVIDER_INTERACTION_MODE)),
537 ),
538 branch: Schema.NullOr(TrimmedNonEmptyString),
539 worktreePath: Schema.NullOr(TrimmedNonEmptyString),
540 createdAt: IsoDateTime,
541});
542​
543const ThreadDeleteCommand = Schema.Struct({
544 type: Schema.Literal("thread.delete"),
545 commandId: CommandId,
546 threadId: ThreadId,
547});
548​
549const ThreadArchiveCommand = Schema.Struct({
550 type: Schema.Literal("thread.archive"),
551 commandId: CommandId,
552 threadId: ThreadId,
553});
554​
555const ThreadUnarchiveCommand = Schema.Struct({
556 type: Schema.Literal("thread.unarchive"),
557 commandId: CommandId,
558 threadId: ThreadId,
559});
560​
561const ThreadMetaUpdateCommand = Schema.Struct({
562 type: Schema.Literal("thread.meta.update"),
563 commandId: CommandId,
564 threadId: ThreadId,
565 title: Schema.optional(TrimmedNonEmptyString),
566 modelSelection: Schema.optional(ModelSelection),
567 branch: Schema.optional(Schema.NullOr(TrimmedNonEmptyString)),
568 expectedBranch: Schema.optional(Schema.NullOr(TrimmedNonEmptyString)),
569 worktreePath: Schema.optional(Schema.NullOr(TrimmedNonEmptyString)),
570});
571​
572const ThreadRuntimeModeSetCommand = Schema.Struct({
573 type: Schema.Literal("thread.runtime-mode.set"),
574 commandId: CommandId,
575 threadId: ThreadId,
576 runtimeMode: RuntimeMode,
577 createdAt: IsoDateTime,
578});
579​
580const ThreadInteractionModeSetCommand = Schema.Struct({
581 type: Schema.Literal("thread.interaction-mode.set"),
582 commandId: CommandId,
583 threadId: ThreadId,
584 interactionMode: ProviderInteractionMode,
585 createdAt: IsoDateTime,
586});
587​
588const ThreadTurnStartBootstrapCreateThread = Schema.Struct({
589 projectId: ProjectId,
590 title: TrimmedNonEmptyString,
591 modelSelection: ModelSelection,
592 runtimeMode: RuntimeMode,
593 interactionMode: ProviderInteractionMode,
594 branch: Schema.NullOr(TrimmedNonEmptyString),
595 worktreePath: Schema.NullOr(TrimmedNonEmptyString),
596 createdAt: IsoDateTime,
597});
598​
599const ThreadTurnStartBootstrapPrepareWorktree = Schema.Struct({
600 projectCwd: TrimmedNonEmptyString,
601 baseBranch: TrimmedNonEmptyString,
602 branch: Schema.optional(TrimmedNonEmptyString),
603 startFromOrigin: Schema.optional(Schema.Boolean),
604});
605​
606const ThreadTurnStartBootstrap = Schema.Struct({
607 createThread: Schema.optional(ThreadTurnStartBootstrapCreateThread),
608 prepareWorktree: Schema.optional(ThreadTurnStartBootstrapPrepareWorktree),
609 runSetupScript: Schema.optional(Schema.Boolean),
610});
611​
612export type ThreadTurnStartBootstrap = typeof ThreadTurnStartBootstrap.Type;
613​
614export const ThreadTurnStartCommand = Schema.Struct({
615 type: Schema.Literal("thread.turn.start"),
616 commandId: CommandId,
617 threadId: ThreadId,
618 message: Schema.Struct({
619 messageId: MessageId,
620 role: Schema.Literal("user"),
621 text: Schema.String,
622 attachments: Schema.Array(ChatAttachment),
623 }),
624 modelSelection: Schema.optional(ModelSelection),
625 titleSeed: Schema.optional(TrimmedNonEmptyString),
626 runtimeMode: RuntimeMode.pipe(Schema.withDecodingDefault(Effect.succeed(DEFAULT_RUNTIME_MODE))),
627 interactionMode: ProviderInteractionMode.pipe(
628 Schema.withDecodingDefault(Effect.succeed(DEFAULT_PROVIDER_INTERACTION_MODE)),
629 ),
630 bootstrap: Schema.optional(ThreadTurnStartBootstrap),
631 sourceProposedPlan: Schema.optional(SourceProposedPlanReference),
632 createdAt: IsoDateTime,
633});
634​
635const ClientThreadTurnStartCommand = Schema.Struct({
636 type: Schema.Literal("thread.turn.start"),
637 commandId: CommandId,
638 threadId: ThreadId,
639 message: Schema.Struct({
640 messageId: MessageId,
641 role: Schema.Literal("user"),
642 text: Schema.String,
643 attachments: Schema.Array(UploadChatAttachment),
644 }),
645 modelSelection: Schema.optional(ModelSelection),
646 titleSeed: Schema.optional(TrimmedNonEmptyString),
647 runtimeMode: RuntimeMode,
648 interactionMode: ProviderInteractionMode,
649 bootstrap: Schema.optional(ThreadTurnStartBootstrap),
650 sourceProposedPlan: Schema.optional(SourceProposedPlanReference),
651 createdAt: IsoDateTime,
652});
653​
654const ThreadTurnInterruptCommand = Schema.Struct({
655 type: Schema.Literal("thread.turn.interrupt"),
656 commandId: CommandId,
657 threadId: ThreadId,
658 turnId: Schema.optional(TurnId),
659 createdAt: IsoDateTime,
660});
661​
662const ThreadApprovalRespondCommand = Schema.Struct({
663 type: Schema.Literal("thread.approval.respond"),
664 commandId: CommandId,
665 threadId: ThreadId,
666 requestId: ApprovalRequestId,
667 decision: ProviderApprovalDecision,
668 createdAt: IsoDateTime,
669});
670​
671const ThreadUserInputRespondCommand = Schema.Struct({
672 type: Schema.Literal("thread.user-input.respond"),
673 commandId: CommandId,
674 threadId: ThreadId,
675 requestId: ApprovalRequestId,
676 answers: ProviderUserInputAnswers,
677 createdAt: IsoDateTime,
678});
679​
680const ThreadCheckpointRevertCommand = Schema.Struct({
681 type: Schema.Literal("thread.checkpoint.revert"),
682 commandId: CommandId,
683 threadId: ThreadId,
684 turnCount: NonNegativeInt,
685 createdAt: IsoDateTime,
686});
687​
688const ThreadSessionStopCommand = Schema.Struct({
689 type: Schema.Literal("thread.session.stop"),
690 commandId: CommandId,
691 threadId: ThreadId,
692 createdAt: IsoDateTime,
693});
694​
695const DispatchableClientOrchestrationCommand = Schema.Union([
696 ProjectCreateCommand,
697 ProjectMetaUpdateCommand,
698 ProjectDeleteCommand,
699 ThreadCreateCommand,
700 ThreadDeleteCommand,
701 ThreadArchiveCommand,
702 ThreadUnarchiveCommand,
703 ThreadMetaUpdateCommand,
704 ThreadRuntimeModeSetCommand,
705 ThreadInteractionModeSetCommand,
706 ThreadTurnStartCommand,
707 ThreadTurnInterruptCommand,
708 ThreadApprovalRespondCommand,
709 ThreadUserInputRespondCommand,
710 ThreadCheckpointRevertCommand,
711 ThreadSessionStopCommand,
712]);
713export type DispatchableClientOrchestrationCommand =
714 typeof DispatchableClientOrchestrationCommand.Type;
715​
716export const ClientOrchestrationCommand = Schema.Union([
717 ProjectCreateCommand,
718 ProjectMetaUpdateCommand,
719 ProjectDeleteCommand,
720 ThreadCreateCommand,
721 ThreadDeleteCommand,
722 ThreadArchiveCommand,
723 ThreadUnarchiveCommand,
724 ThreadMetaUpdateCommand,
725 ThreadRuntimeModeSetCommand,
726 ThreadInteractionModeSetCommand,
727 ClientThreadTurnStartCommand,
728 ThreadTurnInterruptCommand,
729 ThreadApprovalRespondCommand,
730 ThreadUserInputRespondCommand,
731 ThreadCheckpointRevertCommand,
732 ThreadSessionStopCommand,
733]);
734export type ClientOrchestrationCommand = typeof ClientOrchestrationCommand.Type;
735​
736const ThreadSessionSetCommand = Schema.Struct({
737 type: Schema.Literal("thread.session.set"),
738 commandId: CommandId,
739 threadId: ThreadId,
740 session: OrchestrationSession,
741 createdAt: IsoDateTime,
742});
743​
744const ThreadMessageAssistantDeltaCommand = Schema.Struct({
745 type: Schema.Literal("thread.message.assistant.delta"),
746 commandId: CommandId,
747 threadId: ThreadId,
748 messageId: MessageId,
749 delta: Schema.String,
750 turnId: Schema.optional(TurnId),
751 createdAt: IsoDateTime,
752});
753​
754const ThreadMessageAssistantCompleteCommand = Schema.Struct({
755 type: Schema.Literal("thread.message.assistant.complete"),
756 commandId: CommandId,
757 threadId: ThreadId,
758 messageId: MessageId,
759 turnId: Schema.optional(TurnId),
760 createdAt: IsoDateTime,
761});
762​
763const ThreadProposedPlanUpsertCommand = Schema.Struct({
764 type: Schema.Literal("thread.proposed-plan.upsert"),
765 commandId: CommandId,
766 threadId: ThreadId,
767 proposedPlan: OrchestrationProposedPlan,
768 createdAt: IsoDateTime,
769});
770​
771const ThreadTurnDiffCompleteCommand = Schema.Struct({
772 type: Schema.Literal("thread.turn.diff.complete"),
773 commandId: CommandId,
774 threadId: ThreadId,
775 turnId: TurnId,
776 completedAt: IsoDateTime,
777 checkpointRef: CheckpointRef,
778 status: OrchestrationCheckpointStatus,
779 files: Schema.Array(OrchestrationCheckpointFile),
780 assistantMessageId: Schema.optional(MessageId),
781 checkpointTurnCount: NonNegativeInt,
782 createdAt: IsoDateTime,
783});
784​
785const ThreadActivityAppendCommand = Schema.Struct({
786 type: Schema.Literal("thread.activity.append"),
787 commandId: CommandId,
788 threadId: ThreadId,
789 activity: OrchestrationThreadActivity,
790 createdAt: IsoDateTime,
791});
792​
793const ThreadRevertCompleteCommand = Schema.Struct({
794 type: Schema.Literal("thread.revert.complete"),
795 commandId: CommandId,
796 threadId: ThreadId,
797 turnCount: NonNegativeInt,
798 createdAt: IsoDateTime,
799});
800​
801const InternalOrchestrationCommand = Schema.Union([
802 ThreadSessionSetCommand,
803 ThreadMessageAssistantDeltaCommand,
804 ThreadMessageAssistantCompleteCommand,
805 ThreadProposedPlanUpsertCommand,
806 ThreadTurnDiffCompleteCommand,
807 ThreadActivityAppendCommand,
808 ThreadRevertCompleteCommand,
809]);
810export type InternalOrchestrationCommand = typeof InternalOrchestrationCommand.Type;
811​
812export const OrchestrationCommand = Schema.Union([
813 DispatchableClientOrchestrationCommand,
814 InternalOrchestrationCommand,
815]);
816export type OrchestrationCommand = typeof OrchestrationCommand.Type;
817​
818export const OrchestrationEventType = Schema.Literals([
819 "project.created",
820 "project.meta-updated",
821 "project.deleted",
822 "thread.created",
823 "thread.deleted",
824 "thread.archived",
825 "thread.unarchived",
826 "thread.meta-updated",
827 "thread.runtime-mode-set",
828 "thread.interaction-mode-set",
829 "thread.message-sent",
830 "thread.turn-start-requested",
831 "thread.turn-interrupt-requested",
832 "thread.approval-response-requested",
833 "thread.user-input-response-requested",
834 "thread.checkpoint-revert-requested",
835 "thread.reverted",
836 "thread.session-stop-requested",
837 "thread.session-set",
838 "thread.proposed-plan-upserted",
839 "thread.turn-diff-completed",
840 "thread.activity-appended",
841]);
842export type OrchestrationEventType = typeof OrchestrationEventType.Type;
843​
844export const OrchestrationAggregateKind = Schema.Literals(["project", "thread"]);
845export type OrchestrationAggregateKind = typeof OrchestrationAggregateKind.Type;
846export const OrchestrationActorKind = Schema.Literals(["client", "server", "provider"]);
847​
848export const ProjectCreatedPayload = Schema.Struct({
849 projectId: ProjectId,
850 title: TrimmedNonEmptyString,
851 workspaceRoot: TrimmedNonEmptyString,
852 repositoryIdentity: Schema.optional(Schema.NullOr(RepositoryIdentity)),
853 defaultModelSelection: Schema.NullOr(ModelSelection),
854 scripts: Schema.Array(ProjectScript),
855 createdAt: IsoDateTime,
856 updatedAt: IsoDateTime,
857});
858​
859export const ProjectMetaUpdatedPayload = Schema.Struct({
860 projectId: ProjectId,
861 title: Schema.optional(TrimmedNonEmptyString),
862 workspaceRoot: Schema.optional(TrimmedNonEmptyString),
863 repositoryIdentity: Schema.optional(Schema.NullOr(RepositoryIdentity)),
864 defaultModelSelection: Schema.optional(Schema.NullOr(ModelSelection)),
865 scripts: Schema.optional(Schema.Array(ProjectScript)),
866 updatedAt: IsoDateTime,
867});
868​
869export const ProjectDeletedPayload = Schema.Struct({
870 projectId: ProjectId,
871 deletedAt: IsoDateTime,
872});
873​
874export const ThreadCreatedPayload = Schema.Struct({
875 threadId: ThreadId,
876 projectId: ProjectId,
877 title: TrimmedNonEmptyString,
878 modelSelection: ModelSelection,
879 runtimeMode: RuntimeMode.pipe(Schema.withDecodingDefault(Effect.succeed(DEFAULT_RUNTIME_MODE))),
880 interactionMode: ProviderInteractionMode.pipe(
881 Schema.withDecodingDefault(Effect.succeed(DEFAULT_PROVIDER_INTERACTION_MODE)),
882 ),
883 branch: Schema.NullOr(TrimmedNonEmptyString),
884 worktreePath: Schema.NullOr(TrimmedNonEmptyString),
885 createdAt: IsoDateTime,
886 updatedAt: IsoDateTime,
887});
888​
889export const ThreadDeletedPayload = Schema.Struct({
890 threadId: ThreadId,
891 deletedAt: IsoDateTime,
892});
893​
894export const ThreadArchivedPayload = Schema.Struct({
895 threadId: ThreadId,
896 archivedAt: IsoDateTime,
897 updatedAt: IsoDateTime,
898});
899​
900export const ThreadUnarchivedPayload = Schema.Struct({
901 threadId: ThreadId,
902 updatedAt: IsoDateTime,
903});
904​
905export const ThreadMetaUpdatedPayload = Schema.Struct({
906 threadId: ThreadId,
907 title: Schema.optional(TrimmedNonEmptyString),
908 modelSelection: Schema.optional(ModelSelection),
909 branch: Schema.optional(Schema.NullOr(TrimmedNonEmptyString)),
910 worktreePath: Schema.optional(Schema.NullOr(TrimmedNonEmptyString)),
911 updatedAt: IsoDateTime,
912});
913​
914export const ThreadRuntimeModeSetPayload = Schema.Struct({
915 threadId: ThreadId,
916 runtimeMode: RuntimeMode,
917 updatedAt: IsoDateTime,
918});
919​
920export const ThreadInteractionModeSetPayload = Schema.Struct({
921 threadId: ThreadId,
922 interactionMode: ProviderInteractionMode.pipe(
923 Schema.withDecodingDefault(Effect.succeed(DEFAULT_PROVIDER_INTERACTION_MODE)),
924 ),
925 updatedAt: IsoDateTime,
926});
927​
928export const ThreadMessageSentPayload = Schema.Struct({
929 threadId: ThreadId,
930 messageId: MessageId,
931 role: OrchestrationMessageRole,
932 text: Schema.String,
933 attachments: Schema.optional(Schema.Array(ChatAttachment)),
934 turnId: Schema.NullOr(TurnId),
935 streaming: Schema.Boolean,
936 createdAt: IsoDateTime,
937 updatedAt: IsoDateTime,
938});
939​
940export const ThreadTurnStartRequestedPayload = Schema.Struct({
941 threadId: ThreadId,
942 messageId: MessageId,
943 modelSelection: Schema.optional(ModelSelection),
944 titleSeed: Schema.optional(TrimmedNonEmptyString),
945 runtimeMode: RuntimeMode.pipe(Schema.withDecodingDefault(Effect.succeed(DEFAULT_RUNTIME_MODE))),
946 interactionMode: ProviderInteractionMode.pipe(
947 Schema.withDecodingDefault(Effect.succeed(DEFAULT_PROVIDER_INTERACTION_MODE)),
948 ),
949 sourceProposedPlan: Schema.optional(SourceProposedPlanReference),
950 createdAt: IsoDateTime,
951});
952​
953export const ThreadTurnInterruptRequestedPayload = Schema.Struct({
954 threadId: ThreadId,
955 turnId: Schema.optional(TurnId),
956 createdAt: IsoDateTime,
957});
958​
959export const ThreadApprovalResponseRequestedPayload = Schema.Struct({
960 threadId: ThreadId,
961 requestId: ApprovalRequestId,
962 decision: ProviderApprovalDecision,
963 createdAt: IsoDateTime,
964});
965​
966const ThreadUserInputResponseRequestedPayload = Schema.Struct({
967 threadId: ThreadId,
968 requestId: ApprovalRequestId,
969 answers: ProviderUserInputAnswers,
970 createdAt: IsoDateTime,
971});
972​
973export const ThreadCheckpointRevertRequestedPayload = Schema.Struct({
974 threadId: ThreadId,
975 turnCount: NonNegativeInt,
976 createdAt: IsoDateTime,
977});
978​
979export const ThreadRevertedPayload = Schema.Struct({
980 threadId: ThreadId,
981 turnCount: NonNegativeInt,
982});
983​
984export const ThreadSessionStopRequestedPayload = Schema.Struct({
985 threadId: ThreadId,
986 createdAt: IsoDateTime,
987});
988​
989export const ThreadSessionSetPayload = Schema.Struct({
990 threadId: ThreadId,
991 session: OrchestrationSession,
992});
993​
994export const ThreadProposedPlanUpsertedPayload = Schema.Struct({
995 threadId: ThreadId,
996 proposedPlan: OrchestrationProposedPlan,
997});
998​
999export const ThreadTurnDiffCompletedPayload = Schema.Struct({
1000 threadId: ThreadId,
1001 turnId: TurnId,
1002 checkpointTurnCount: NonNegativeInt,
1003 checkpointRef: CheckpointRef,
1004 status: OrchestrationCheckpointStatus,
1005 files: Schema.Array(OrchestrationCheckpointFile),
1006 assistantMessageId: Schema.NullOr(MessageId),
1007 completedAt: IsoDateTime,
1008});
1009​
1010export const ThreadActivityAppendedPayload = Schema.Struct({
1011 threadId: ThreadId,
1012 activity: OrchestrationThreadActivity,
1013});
1014​
1015export const OrchestrationEventMetadata = Schema.Struct({
1016 providerTurnId: Schema.optional(TrimmedNonEmptyString),
1017 providerItemId: Schema.optional(ProviderItemId),
1018 adapterKey: Schema.optional(TrimmedNonEmptyString),
1019 requestId: Schema.optional(ApprovalRequestId),
1020 ingestedAt: Schema.optional(IsoDateTime),
1021});
1022export type OrchestrationEventMetadata = typeof OrchestrationEventMetadata.Type;
1023​
1024const EventBaseFields = {
1025 sequence: NonNegativeInt,
1026 eventId: EventId,
1027 aggregateKind: OrchestrationAggregateKind,
1028 aggregateId: Schema.Union([ProjectId, ThreadId]),
1029 occurredAt: IsoDateTime,
1030 commandId: Schema.NullOr(CommandId),
1031 causationEventId: Schema.NullOr(EventId),
1032 correlationId: Schema.NullOr(CommandId),
1033 metadata: OrchestrationEventMetadata,
1034} as const;
1035​
1036export const OrchestrationEvent = Schema.Union([
1037 Schema.Struct({
1038 ...EventBaseFields,
1039 type: Schema.Literal("project.created"),
1040 payload: ProjectCreatedPayload,
1041 }),
1042 Schema.Struct({
1043 ...EventBaseFields,
1044 type: Schema.Literal("project.meta-updated"),
1045 payload: ProjectMetaUpdatedPayload,
1046 }),
1047 Schema.Struct({
1048 ...EventBaseFields,
1049 type: Schema.Literal("project.deleted"),
1050 payload: ProjectDeletedPayload,
1051 }),
1052 Schema.Struct({
1053 ...EventBaseFields,
1054 type: Schema.Literal("thread.created"),
1055 payload: ThreadCreatedPayload,
1056 }),
1057 Schema.Struct({
1058 ...EventBaseFields,
1059 type: Schema.Literal("thread.deleted"),
1060 payload: ThreadDeletedPayload,
1061 }),
1062 Schema.Struct({
1063 ...EventBaseFields,
1064 type: Schema.Literal("thread.archived"),
1065 payload: ThreadArchivedPayload,
1066 }),
1067 Schema.Struct({
1068 ...EventBaseFields,
1069 type: Schema.Literal("thread.unarchived"),
1070 payload: ThreadUnarchivedPayload,
1071 }),
1072 Schema.Struct({
1073 ...EventBaseFields,
1074 type: Schema.Literal("thread.meta-updated"),
1075 payload: ThreadMetaUpdatedPayload,
1076 }),
1077 Schema.Struct({
1078 ...EventBaseFields,
1079 type: Schema.Literal("thread.runtime-mode-set"),
1080 payload: ThreadRuntimeModeSetPayload,
1081 }),
1082 Schema.Struct({
1083 ...EventBaseFields,
1084 type: Schema.Literal("thread.interaction-mode-set"),
1085 payload: ThreadInteractionModeSetPayload,
1086 }),
1087 Schema.Struct({
1088 ...EventBaseFields,
1089 type: Schema.Literal("thread.message-sent"),
1090 payload: ThreadMessageSentPayload,
1091 }),
1092 Schema.Struct({
1093 ...EventBaseFields,
1094 type: Schema.Literal("thread.turn-start-requested"),
1095 payload: ThreadTurnStartRequestedPayload,
1096 }),
1097 Schema.Struct({
1098 ...EventBaseFields,
1099 type: Schema.Literal("thread.turn-interrupt-requested"),
1100 payload: ThreadTurnInterruptRequestedPayload,
1101 }),
1102 Schema.Struct({
1103 ...EventBaseFields,
1104 type: Schema.Literal("thread.approval-response-requested"),
1105 payload: ThreadApprovalResponseRequestedPayload,
1106 }),
1107 Schema.Struct({
1108 ...EventBaseFields,
1109 type: Schema.Literal("thread.user-input-response-requested"),
1110 payload: ThreadUserInputResponseRequestedPayload,
1111 }),
1112 Schema.Struct({
1113 ...EventBaseFields,
1114 type: Schema.Literal("thread.checkpoint-revert-requested"),
1115 payload: ThreadCheckpointRevertRequestedPayload,
1116 }),
1117 Schema.Struct({
1118 ...EventBaseFields,
1119 type: Schema.Literal("thread.reverted"),
1120 payload: ThreadRevertedPayload,
1121 }),
1122 Schema.Struct({
1123 ...EventBaseFields,
1124 type: Schema.Literal("thread.session-stop-requested"),
1125 payload: ThreadSessionStopRequestedPayload,
1126 }),
1127 Schema.Struct({
1128 ...EventBaseFields,
1129 type: Schema.Literal("thread.session-set"),
1130 payload: ThreadSessionSetPayload,
1131 }),
1132 Schema.Struct({
1133 ...EventBaseFields,
1134 type: Schema.Literal("thread.proposed-plan-upserted"),
1135 payload: ThreadProposedPlanUpsertedPayload,
1136 }),
1137 Schema.Struct({
1138 ...EventBaseFields,
1139 type: Schema.Literal("thread.turn-diff-completed"),
1140 payload: ThreadTurnDiffCompletedPayload,
1141 }),
1142 Schema.Struct({
1143 ...EventBaseFields,
1144 type: Schema.Literal("thread.activity-appended"),
1145 payload: ThreadActivityAppendedPayload,
1146 }),
1147]);
1148export type OrchestrationEvent = typeof OrchestrationEvent.Type;
1149​
1150export const OrchestrationThreadStreamItem = Schema.Union([
1151 Schema.Struct({
1152 kind: Schema.Literal("synchronized"),
1153 }),
1154 Schema.Struct({
1155 kind: Schema.Literal("snapshot"),
1156 snapshot: OrchestrationThreadDetailSnapshot,
1157 }),
1158 Schema.Struct({
1159 kind: Schema.Literal("event"),
1160 event: OrchestrationEvent,
1161 }),
1162]);
1163export type OrchestrationThreadStreamItem = typeof OrchestrationThreadStreamItem.Type;
1164​
1165export const OrchestrationCommandReceiptStatus = Schema.Literals(["accepted", "rejected"]);
1166export type OrchestrationCommandReceiptStatus = typeof OrchestrationCommandReceiptStatus.Type;
1167​
1168export const TurnCountRange = Schema.Struct({
1169 fromTurnCount: NonNegativeInt,
1170 toTurnCount: NonNegativeInt,
1171}).check(
1172 Schema.makeFilter(
1173 (input) =>
1174 input.fromTurnCount <= input.toTurnCount ||
1175 new SchemaIssue.InvalidValue(Option.some(input.fromTurnCount), {
1176 message: "fromTurnCount must be less than or equal to toTurnCount",
1177 }),
1178 { identifier: "OrchestrationTurnDiffRange" },
1179 ),
1181​
1182export const ThreadTurnDiff = TurnCountRange.mapFields(
1183 Struct.assign({
1184 threadId: ThreadId,
1185 diff: Schema.String,
1186 }),
1187 { unsafePreserveChecks: true },
1189​
1190export const ProviderSessionRuntimeStatus = Schema.Literals([
1191 "starting",
1192 "running",
1193 "stopped",
1194 "error",
1195]);
1196export type ProviderSessionRuntimeStatus = typeof ProviderSessionRuntimeStatus.Type;
1197​
1198const ProjectionThreadTurnStatus = Schema.Literals([
1199 "running",
1200 "completed",
1201 "interrupted",
1202 "error",
1203]);
1204export type ProjectionThreadTurnStatus = typeof ProjectionThreadTurnStatus.Type;
1205​
1206const ProjectionCheckpointRow = Schema.Struct({
1207 threadId: ThreadId,
1208 turnId: TurnId,
1209 checkpointTurnCount: NonNegativeInt,
1210 checkpointRef: CheckpointRef,
1211 status: OrchestrationCheckpointStatus,
1212 files: Schema.Array(OrchestrationCheckpointFile),
1213 assistantMessageId: Schema.NullOr(MessageId),
1214 completedAt: IsoDateTime,
1215});
1216export type ProjectionCheckpointRow = typeof ProjectionCheckpointRow.Type;
1217​
1218export const ProjectionPendingApprovalStatus = Schema.Literals(["pending", "resolved"]);
1219export type ProjectionPendingApprovalStatus = typeof ProjectionPendingApprovalStatus.Type;
1220​
1221export const ProjectionPendingApprovalDecision = Schema.NullOr(ProviderApprovalDecision);
1222export type ProjectionPendingApprovalDecision = typeof ProjectionPendingApprovalDecision.Type;
1223​
1224export const DispatchResult = Schema.Struct({
1225 sequence: NonNegativeInt,
1226});
1227export type DispatchResult = typeof DispatchResult.Type;
1228​
1229export const OrchestrationGetTurnDiffInput = TurnCountRange.mapFields(
1230 Struct.assign({
1231 threadId: ThreadId,
1232 ignoreWhitespace: Schema.optionalKey(Schema.Boolean),
1233 }),
1234 { unsafePreserveChecks: true },
1236export type OrchestrationGetTurnDiffInput = typeof OrchestrationGetTurnDiffInput.Type;
1237​
1238export const OrchestrationGetTurnDiffResult = ThreadTurnDiff;
1239export type OrchestrationGetTurnDiffResult = typeof OrchestrationGetTurnDiffResult.Type;
1240​
1241export const OrchestrationGetFullThreadDiffInput = Schema.Struct({
1242 threadId: ThreadId,
1243 toTurnCount: NonNegativeInt,
1244 ignoreWhitespace: Schema.optionalKey(Schema.Boolean),
1245});
1246export type OrchestrationGetFullThreadDiffInput = typeof OrchestrationGetFullThreadDiffInput.Type;
1247​
1248export const OrchestrationGetFullThreadDiffResult = ThreadTurnDiff;
1249export type OrchestrationGetFullThreadDiffResult = typeof OrchestrationGetFullThreadDiffResult.Type;
1250​
1251export const OrchestrationReplayEventsInput = Schema.Struct({
1252 fromSequenceExclusive: NonNegativeInt,
1253});
1254export type OrchestrationReplayEventsInput = typeof OrchestrationReplayEventsInput.Type;
1255​
1256const OrchestrationReplayEventsResult = Schema.Array(OrchestrationEvent);
1257export type OrchestrationReplayEventsResult = typeof OrchestrationReplayEventsResult.Type;
1258​
1259export const OrchestrationRpcSchemas = {
1260 dispatchCommand: {
1261 input: ClientOrchestrationCommand,
1262 output: DispatchResult,
1263 },
1264 getTurnDiff: {
1265 input: OrchestrationGetTurnDiffInput,
1266 output: OrchestrationGetTurnDiffResult,
1267 },
1268 getFullThreadDiff: {
1269 input: OrchestrationGetFullThreadDiffInput,
1270 output: OrchestrationGetFullThreadDiffResult,
1271 },
1272 replayEvents: {
1273 input: OrchestrationReplayEventsInput,
1274 output: OrchestrationReplayEventsResult,
1275 },
1276 getArchivedShellSnapshot: {
1277 input: Schema.Struct({}),
1278 output: OrchestrationShellSnapshot,
1279 },
1280 subscribeThread: {
1281 input: OrchestrationSubscribeThreadInput,
1282 output: OrchestrationThreadStreamItem,
1283 },
1284 subscribeShell: {
1285 input: OrchestrationSubscribeShellInput,
1286 output: OrchestrationShellStreamItem,
1287 },
1288} as const;
1289​
1290export class OrchestrationGetSnapshotError extends Schema.TaggedErrorClass<OrchestrationGetSnapshotError>()(
1291 "OrchestrationGetSnapshotError",
1293 message: TrimmedNonEmptyString,
1294 cause: Schema.optional(Schema.Defect()),
1295 },
1296) {}
1297​
1298export class OrchestrationDispatchCommandError extends Schema.TaggedErrorClass<OrchestrationDispatchCommandError>()(
1299 "OrchestrationDispatchCommandError",
1301 message: TrimmedNonEmptyString,
1302 cause: Schema.optional(Schema.Defect()),
1303 },
1304) {}
1305​
1306export class OrchestrationGetTurnDiffError extends Schema.TaggedErrorClass<OrchestrationGetTurnDiffError>()(
1307 "OrchestrationGetTurnDiffError",
1309 message: TrimmedNonEmptyString,
1310 cause: Schema.optional(Schema.Defect()),
1311 },
1312) {}
1313​
1314export class OrchestrationGetFullThreadDiffError extends Schema.TaggedErrorClass<OrchestrationGetFullThreadDiffError>()(
1315 "OrchestrationGetFullThreadDiffError",
1317 message: TrimmedNonEmptyString,
1318 cause: Schema.optional(Schema.Defect()),
1319 },
1320) {}
1321​
1322export class OrchestrationReplayEventsError extends Schema.TaggedErrorClass<OrchestrationReplayEventsError>()(
1323 "OrchestrationReplayEventsError",
1325 message: TrimmedNonEmptyString,
1326 cause: Schema.optional(Schema.Defect()),
1327 },
1328) {}