fix(chat): preserve routing for side-channel command replies (#6736)
This commit is contained in:
1 parent
3e9024ea04
commit
cd75dbfaac
13 files changed
+155
-34
No files matched your search
@@ -369,6 +369,7 @@ function parseThreadProjectionEvent(value: unknown, validatedGraphs: ReadonlySet
|
||||
return value as unknown as ThreadProjectionEvent;
|
||||
case "message":
|
||||
if (typeof value.text !== "string") break;
|
||||
if (value.side_channel !== undefined && value.side_channel !== true) break;
|
||||
if (value.tool_events !== undefined && !isRecordArray(value.tool_events)) break;
|
||||
if (value.trace_detail !== undefined && (
|
||||
!["tool_hint", "progress"].includes(String(value.kind))
|
||||
|
||||
@@ -1161,6 +1161,7 @@ function reduceThreadEvent(
|
||||
const latencyMs = typeof event.latency_ms === "number" && event.latency_ms >= 0
|
||||
? Math.round(event.latency_ms)
|
||||
: undefined;
|
||||
const sideChannel = event.side_channel === true || options.sideChannel;
|
||||
const projected = {
|
||||
content: event.text,
|
||||
...(event.render_as === "text" ? { renderAs: event.render_as } : {}),
|
||||
@@ -1170,12 +1171,12 @@ function reduceThreadEvent(
|
||||
...(event.response_sources !== undefined ? { responseSources: event.response_sources } : {}),
|
||||
...(event.response_input_ids !== undefined ? { responseInputIds: event.response_input_ids } : {}),
|
||||
...positionedTurnFields(
|
||||
options.sideChannel ? undefined : state.messages.find((message) => message.id === state.activeAssistantId),
|
||||
sideChannel ? undefined : state.messages.find((message) => message.id === state.activeAssistantId),
|
||||
turnFieldsForProjection(state, event, "answer"),
|
||||
options,
|
||||
),
|
||||
};
|
||||
if (options.sideChannel) {
|
||||
if (sideChannel) {
|
||||
absorbProjectedAssistantMessage(state, event, projected, options);
|
||||
return state;
|
||||
}
|
||||
|
||||
@@ -1601,6 +1601,7 @@ export type InboundEvent =
|
||||
event: "message";
|
||||
chat_id: string;
|
||||
text: string;
|
||||
side_channel?: true;
|
||||
render_as?: "text";
|
||||
reply_to?: string;
|
||||
media?: string[];
|
||||
|
||||
@@ -3399,6 +3399,43 @@ describe("useNanobotStream", () => {
|
||||
}
|
||||
});
|
||||
|
||||
it("keeps streaming when a deferred Dream reply arrives after its command has ended", async () => {
|
||||
const fake = fakeClient();
|
||||
const chatId = "chat-dream";
|
||||
const { result } = renderHook(() => useNanobotStream(chatId, EMPTY_MESSAGES), {
|
||||
wrapper: wrap(fake.client),
|
||||
});
|
||||
|
||||
act(() => { result.current.send("/dream", undefined, { sideChannel: true }); });
|
||||
const dreamTurnId = fake.client.sendMessage.mock.calls.at(-1)![3]?.turnId;
|
||||
act(() => {
|
||||
fake.emit(chatId, { event: "message", chat_id: chatId, text: "Dreaming...",
|
||||
turn_id: dreamTurnId, turn_seq: 1, side_channel: true });
|
||||
fake.emit(chatId, { event: "turn_end", chat_id: chatId, turn_id: dreamTurnId, turn_seq: 2 });
|
||||
});
|
||||
act(() => { result.current.send("write normally"); });
|
||||
const answerTurnId = fake.client.sendMessage.mock.calls.at(-1)![3]?.turnId;
|
||||
act(() => {
|
||||
fake.emit(chatId, { event: "delta", chat_id: chatId, text: "First half",
|
||||
turn_id: answerTurnId, turn_seq: 1, stream_id: "answer-1" });
|
||||
});
|
||||
await flushStreamFrame();
|
||||
const answerId = result.current.messages.find((message) => message.content === "First half")?.id;
|
||||
expect(answerId).toBeDefined();
|
||||
|
||||
act(() => {
|
||||
fake.emit(chatId, { event: "message", chat_id: chatId, text: "Dream completed.",
|
||||
turn_id: "command-result:completion", turn_seq: 1, side_channel: true });
|
||||
fake.emit(chatId, { event: "delta", chat_id: chatId, text: " and second half",
|
||||
turn_id: answerTurnId, turn_seq: 2, stream_id: "answer-1" });
|
||||
});
|
||||
await flushStreamFrame();
|
||||
|
||||
expect(result.current.messages.find((message) => message.id === answerId)?.content)
|
||||
.toBe("First half and second half");
|
||||
expect(result.current.messages.map((message) => message.content)).toContain("Dream completed.");
|
||||
});
|
||||
|
||||
it("keeps guided output in place while the active turn resumes", async () => {
|
||||
const fake = fakeClient();
|
||||
const { result } = renderHook(() => useNanobotStream("chat-guide", EMPTY_MESSAGES), {
|
||||
|
||||
Reference in new issue
Block a user