@@ -8881,7 +8881,9 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
88818881 const context = yield* projectionStore
88828882 .getRuntimeResponseContext(command.threadId, command.requestId)
88838883 .pipe(
8884- Effect.mapError(() => new OrchestratorProjectionError({ threadId: command.threadId })),
8884+ Effect.mapError(
8885+ (cause) => new OrchestratorProjectionError({ threadId: command.threadId, cause }),
8886+ ),
88858887 );
88868888 const runtimeRequest = context.request;
88878889 if (runtimeRequest === undefined) {
@@ -9294,7 +9296,9 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
92949296 const request = yield* projectionStore
92959297 .getRuntimeRequest(command.threadId, command.requestId)
92969298 .pipe(
9297- Effect.mapError(() => new OrchestratorProjectionError({ threadId: command.threadId })),
9299+ Effect.mapError(
9300+ (cause) => new OrchestratorProjectionError({ threadId: command.threadId, cause }),
9301+ ),
92989302 );
92999303 if (request === undefined || request.status !== "pending") {
93009304 return yield* new OrchestratorDispatchError({
@@ -9331,24 +9335,22 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
93319335 events: Ref.Ref<Array<OrchestrationV2DomainEvent>>,
93329336 effects: Ref.Ref<Array<PendingOrchestrationEffectV2>>,
93339337 ) {
9334- const projection = yield* projectionStore
9335- .getThreadRecords(
9336- command.threadId,
9337- [
9338- "runs",
9339- "nodes",
9340- "attempts",
9341- "messages",
9342- "providerThreads",
9343- "providerTurns",
9344- "providerSessions",
9345- "turnItems",
9346- "runtimeRequests",
9347- "subagents",
9348- ],
9349- { turnItemTypes: [], messageRoles: ["user"] },
9350- )
9351- .pipe(Effect.mapError(() => new OrchestratorProjectionError({ threadId: command.threadId })));
9338+ const projection = yield* loadProjectionForCommand(
9339+ command,
9340+ [
9341+ "runs",
9342+ "nodes",
9343+ "attempts",
9344+ "messages",
9345+ "providerThreads",
9346+ "providerTurns",
9347+ "providerSessions",
9348+ "turnItems",
9349+ "runtimeRequests",
9350+ "subagents",
9351+ ],
9352+ { turnItemTypes: [], messageRoles: ["user"] },
9353+ );
93529354 if (projection.thread.archivedAt !== null || projection.thread.deletedAt !== null) {
93539355 return yield* new OrchestratorDispatchError({
93549356 commandId: command.commandId,
@@ -9542,9 +9544,9 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
95429544 command: Extract<OrchestrationV2Command, { readonly type: "queued-run.reorder" }>,
95439545 events: Ref.Ref<Array<OrchestrationV2DomainEvent>>,
95449546 ) {
9545- const projection = yield* projectionStore
9546- .getThreadRecords(command.threadId, ["runs", "messages"], { messageRoles: ["user"] })
9547- .pipe(Effect.mapError(() => new OrchestratorProjectionError({ threadId: command.threadId })) );
9547+ const projection = yield* loadProjectionForCommand(command, ["runs", "messages"], {
9548+ messageRoles: ["user"],
9549+ } );
95489550 const queuedRuns = queuedRunsInDeliveryOrder(projection);
95499551 const moving = queuedRuns.find((run) => run.id === command.runId);
95509552 if (moving === undefined) {
@@ -9628,13 +9630,11 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
96289630 command: Extract<OrchestrationV2Command, { readonly type: "queued-run.cancel" }>,
96299631 events: Ref.Ref<Array<OrchestrationV2DomainEvent>>,
96309632 ) {
9631- const projection = yield* projectionStore
9632- .getThreadRecords(
9633- command.threadId,
9634- ["runs", "messages", "nodes", "attempts", "subagents", "turnItems"],
9635- { turnItemTypes: [], messageRoles: ["user"] },
9636- )
9637- .pipe(Effect.mapError(() => new OrchestratorProjectionError({ threadId: command.threadId })));
9633+ const projection = yield* loadProjectionForCommand(
9634+ command,
9635+ ["runs", "messages", "nodes", "attempts", "subagents", "turnItems"],
9636+ { turnItemTypes: [], messageRoles: ["user"] },
9637+ );
96389638 const queuedRun = projection.runs.find((candidate) => candidate.id === command.runId);
96399639 if (queuedRun === undefined || queuedRun.status !== "queued") {
96409640 return yield* new OrchestratorDispatchError({
@@ -9739,12 +9739,10 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
97399739 cause: `Queued run ${command.runId} cannot be edited to an empty message.`,
97409740 });
97419741 }
9742- const projection = yield* projectionStore
9743- .getThreadRecords(command.threadId, ["runs", "messages", "turnItems"], {
9744- turnItemTypes: ["user_message"],
9745- messageRoles: ["user"],
9746- })
9747- .pipe(Effect.mapError(() => new OrchestratorProjectionError({ threadId: command.threadId })));
9742+ const projection = yield* loadProjectionForCommand(command, ["runs", "messages", "turnItems"], {
9743+ turnItemTypes: ["user_message"],
9744+ messageRoles: ["user"],
9745+ });
97489746 const queuedRun = projection.runs.find((candidate) => candidate.id === command.runId);
97499747 if (queuedRun === undefined || queuedRun.status !== "queued") {
97509748 return yield* new OrchestratorDispatchError({
@@ -9842,7 +9840,7 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
98429840 .getThreadRecords(commandThreadId(command), fields, filter)
98439841 .pipe(
98449842 Effect.mapError(
9845- () => new OrchestratorProjectionError({ threadId: commandThreadId(command) }),
9843+ (cause ) => new OrchestratorProjectionError({ threadId: commandThreadId(command), cause }),
98469844 ),
98479845 );
98489846
0 commit comments