Skip to content

Commit 1796ed1

Browse files
committed
fix(server): include approval feedback in visible conversation history
1 parent 7ddf702 commit 1796ed1

2 files changed

Lines changed: 57 additions & 1 deletion

File tree

‎apps/server/src/orchestration-v2/Orchestrator.control-reads.test.ts‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,24 @@ it.effect(
159159
"pending",
160160
);
161161
assert.equal(projection.messages.at(-1)?.text, feedback);
162+
const feedbackMessageId = MessageId.make("approval-feedback:child");
163+
assert.ok(
164+
projection.visibleTurnItems.some(
165+
({ item }) =>
166+
item.type === "user_message" &&
167+
item.messageId === feedbackMessageId &&
168+
item.text === feedback,
169+
),
170+
);
171+
const history = yield* projections.getTimelinePage(threadId, { limit: 20, view: "messages" });
172+
assert.ok(
173+
history.items.some(
174+
({ item }) =>
175+
item.type === "user_message" &&
176+
item.messageId === feedbackMessageId &&
177+
item.text === feedback,
178+
),
179+
);
162180
assert.equal(projection.runs.length, 0);
163181
assert.deepEqual(
164182
(yield* outbox.listByCommandId(commandId)).map((effect) => effect.request),

‎apps/server/src/orchestration-v2/Orchestrator.ts‎

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7716,6 +7716,7 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
77167716
const emitEvent = emit(events, command);
77177717
const requestNode = context.node;
77187718
if (command.feedback !== undefined) {
7719+
const messageId = MessageId.make(`approval-feedback:${command.requestId}`);
77197720
// Record the reply for every client without dispatching a prompt to the parent agent.
77207721
yield* emitEvent({
77217722
type: "message.updated",
@@ -7724,7 +7725,7 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
77247725
nodeId: runtimeRequest.nodeId,
77257726
occurredAt: now,
77267727
payload: {
7727-
id: MessageId.make(`approval-feedback:${command.requestId}`),
7728+
id: messageId,
77287729
threadId: command.threadId,
77297730
runId: requestNode?.runId ?? null,
77307731
nodeId: runtimeRequest.nodeId,
@@ -7738,6 +7739,43 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
77387739
updatedAt: now,
77397740
},
77407741
});
7742+
yield* emitEvent({
7743+
type: "turn-item.updated",
7744+
threadId: command.threadId,
7745+
...(requestNode?.runId == null ? {} : { runId: requestNode.runId }),
7746+
nodeId: runtimeRequest.nodeId,
7747+
occurredAt: now,
7748+
payload: {
7749+
id: idAllocator.derive.userTurnItem({ messageId }),
7750+
threadId: command.threadId,
7751+
runId: requestNode?.runId ?? null,
7752+
nodeId: runtimeRequest.nodeId,
7753+
providerThreadId:
7754+
context.item?.providerThreadId ?? requestNode?.providerThreadId ?? null,
7755+
providerTurnId: runtimeRequest.providerTurnId,
7756+
nativeItemRef: null,
7757+
parentItemId: null,
7758+
ordinal: yield* projectionStore
7759+
.getNextTurnItemOrdinal(command.threadId)
7760+
.pipe(
7761+
Effect.mapError(
7762+
(cause) => new OrchestratorProjectionError({ threadId: command.threadId, cause }),
7763+
),
7764+
),
7765+
status: "completed",
7766+
title: null,
7767+
startedAt: now,
7768+
completedAt: now,
7769+
updatedAt: now,
7770+
type: "user_message",
7771+
messageId,
7772+
inputIntent: "steer",
7773+
text: command.feedback,
7774+
attachments: [],
7775+
createdBy: "user",
7776+
creationSource: "server",
7777+
},
7778+
});
77417779
}
77427780
const resolvedNodeStatus =
77437781
command.decision === "decline" || command.decision === "cancel"

0 commit comments

Comments
 (0)