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

orchestration.ts

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