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

orchestration.ts

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