@@ -8793,7 +8793,9 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
87938793 const context = yield* projectionStore
87948794 .getRuntimeResponseContext(command.threadId, command.requestId)
87958795 .pipe(
8796- Effect.mapError(() => new OrchestratorProjectionError({ threadId: command.threadId })),
8796+ Effect.mapError(
8797+ (cause) => new OrchestratorProjectionError({ threadId: command.threadId, cause }),
8798+ ),
87978799 );
87988800 const runtimeRequest = context.request;
87998801 if (runtimeRequest === undefined) {
@@ -9206,7 +9208,9 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
92069208 const request = yield* projectionStore
92079209 .getRuntimeRequest(command.threadId, command.requestId)
92089210 .pipe(
9209- Effect.mapError(() => new OrchestratorProjectionError({ threadId: command.threadId })),
9211+ Effect.mapError(
9212+ (cause) => new OrchestratorProjectionError({ threadId: command.threadId, cause }),
9213+ ),
92109214 );
92119215 if (request === undefined || request.status !== "pending") {
92129216 return yield* new OrchestratorDispatchError({
@@ -9243,24 +9247,22 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
92439247 events: Ref.Ref<Array<OrchestrationV2DomainEvent>>,
92449248 effects: Ref.Ref<Array<PendingOrchestrationEffectV2>>,
92459249 ) {
9246- const projection = yield* projectionStore
9247- .getThreadRecords(
9248- command.threadId,
9249- [
9250- "runs",
9251- "nodes",
9252- "attempts",
9253- "messages",
9254- "providerThreads",
9255- "providerTurns",
9256- "providerSessions",
9257- "turnItems",
9258- "runtimeRequests",
9259- "subagents",
9260- ],
9261- { turnItemTypes: [], messageRoles: ["user"] },
9262- )
9263- .pipe(Effect.mapError(() => new OrchestratorProjectionError({ threadId: command.threadId })));
9250+ const projection = yield* loadProjectionForCommand(
9251+ command,
9252+ [
9253+ "runs",
9254+ "nodes",
9255+ "attempts",
9256+ "messages",
9257+ "providerThreads",
9258+ "providerTurns",
9259+ "providerSessions",
9260+ "turnItems",
9261+ "runtimeRequests",
9262+ "subagents",
9263+ ],
9264+ { turnItemTypes: [], messageRoles: ["user"] },
9265+ );
92649266 if (projection.thread.archivedAt !== null || projection.thread.deletedAt !== null) {
92659267 return yield* new OrchestratorDispatchError({
92669268 commandId: command.commandId,
@@ -9454,9 +9456,9 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
94549456 command: Extract<OrchestrationV2Command, { readonly type: "queued-run.reorder" }>,
94559457 events: Ref.Ref<Array<OrchestrationV2DomainEvent>>,
94569458 ) {
9457- const projection = yield* projectionStore
9458- .getThreadRecords(command.threadId, ["runs", "messages"], { messageRoles: ["user"] })
9459- .pipe(Effect.mapError(() => new OrchestratorProjectionError({ threadId: command.threadId })) );
9459+ const projection = yield* loadProjectionForCommand(command, ["runs", "messages"], {
9460+ messageRoles: ["user"],
9461+ } );
94609462 const queuedRuns = queuedRunsInDeliveryOrder(projection);
94619463 const moving = queuedRuns.find((run) => run.id === command.runId);
94629464 if (moving === undefined) {
@@ -9540,13 +9542,11 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
95409542 command: Extract<OrchestrationV2Command, { readonly type: "queued-run.cancel" }>,
95419543 events: Ref.Ref<Array<OrchestrationV2DomainEvent>>,
95429544 ) {
9543- const projection = yield* projectionStore
9544- .getThreadRecords(
9545- command.threadId,
9546- ["runs", "messages", "nodes", "attempts", "subagents", "turnItems"],
9547- { turnItemTypes: [], messageRoles: ["user"] },
9548- )
9549- .pipe(Effect.mapError(() => new OrchestratorProjectionError({ threadId: command.threadId })));
9545+ const projection = yield* loadProjectionForCommand(
9546+ command,
9547+ ["runs", "messages", "nodes", "attempts", "subagents", "turnItems"],
9548+ { turnItemTypes: [], messageRoles: ["user"] },
9549+ );
95509550 const queuedRun = projection.runs.find((candidate) => candidate.id === command.runId);
95519551 if (queuedRun === undefined || queuedRun.status !== "queued") {
95529552 return yield* new OrchestratorDispatchError({
@@ -9651,12 +9651,10 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
96519651 cause: `Queued run ${command.runId} cannot be edited to an empty message.`,
96529652 });
96539653 }
9654- const projection = yield* projectionStore
9655- .getThreadRecords(command.threadId, ["runs", "messages", "turnItems"], {
9656- turnItemTypes: ["user_message"],
9657- messageRoles: ["user"],
9658- })
9659- .pipe(Effect.mapError(() => new OrchestratorProjectionError({ threadId: command.threadId })));
9654+ const projection = yield* loadProjectionForCommand(command, ["runs", "messages", "turnItems"], {
9655+ turnItemTypes: ["user_message"],
9656+ messageRoles: ["user"],
9657+ });
96609658 const queuedRun = projection.runs.find((candidate) => candidate.id === command.runId);
96619659 if (queuedRun === undefined || queuedRun.status !== "queued") {
96629660 return yield* new OrchestratorDispatchError({
@@ -9754,7 +9752,7 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
97549752 .getThreadRecords(commandThreadId(command), fields, filter)
97559753 .pipe(
97569754 Effect.mapError(
9757- () => new OrchestratorProjectionError({ threadId: commandThreadId(command) }),
9755+ (cause ) => new OrchestratorProjectionError({ threadId: commandThreadId(command), cause }),
97589756 ),
97599757 );
97609758
0 commit comments