bug修改
This commit is contained in:
1 parent
910cee9e67
commit
704438b3d2
6 files changed
+278
-36
No files matched your search
@@ -0,0 +1,77 @@
|
||||
import assert from "node:assert/strict";
|
||||
import test from "node:test";
|
||||
|
||||
import type { Message } from "@langchain/langgraph-sdk";
|
||||
|
||||
import { groupMessages } from "./utils";
|
||||
|
||||
function groupTypes(messages: Message[]) {
|
||||
const types: string[] = [];
|
||||
groupMessages(messages, (group) => {
|
||||
types.push(group.type);
|
||||
return group.type;
|
||||
});
|
||||
return types;
|
||||
}
|
||||
|
||||
test("write_file tool after 用户协助 opens a processing group instead of erroring", () => {
|
||||
const types = groupTypes([
|
||||
{ type: "human", id: "h1", content: "写一份报告" } as Message,
|
||||
{
|
||||
type: "ai",
|
||||
id: "a1",
|
||||
content: "",
|
||||
tool_calls: [{ id: "c1", name: "ask_clarification", args: {} }],
|
||||
} as Message,
|
||||
{
|
||||
type: "tool",
|
||||
id: "t1",
|
||||
name: "ask_clarification",
|
||||
content: "请选择范围",
|
||||
tool_call_id: "c1",
|
||||
} as Message,
|
||||
{ type: "human", id: "h2", content: "按方案 A" } as Message,
|
||||
{
|
||||
type: "tool",
|
||||
id: "t2",
|
||||
name: "write_file",
|
||||
content: "OK",
|
||||
tool_call_id: "w1",
|
||||
} as Message,
|
||||
{
|
||||
type: "tool",
|
||||
id: "t3",
|
||||
name: "write_file",
|
||||
content: "OK",
|
||||
tool_call_id: "w2",
|
||||
} as Message,
|
||||
]);
|
||||
|
||||
assert.deepEqual(types, [
|
||||
"human",
|
||||
"assistant:processing",
|
||||
"assistant:clarification",
|
||||
"human",
|
||||
"assistant:processing",
|
||||
]);
|
||||
});
|
||||
|
||||
test("tool messages still attach to an open processing group", () => {
|
||||
const types = groupTypes([
|
||||
{
|
||||
type: "ai",
|
||||
id: "a1",
|
||||
content: "",
|
||||
tool_calls: [{ id: "w1", name: "write_file", args: { path: "a.md" } }],
|
||||
} as Message,
|
||||
{
|
||||
type: "tool",
|
||||
id: "t1",
|
||||
name: "write_file",
|
||||
content: "OK",
|
||||
tool_call_id: "w1",
|
||||
} as Message,
|
||||
]);
|
||||
|
||||
assert.deepEqual(types, ["assistant:processing"]);
|
||||
});
|
||||
@@ -119,10 +119,15 @@ export function groupMessages<T>(
|
||||
if (open) {
|
||||
open.messages.push(message);
|
||||
} else {
|
||||
console.error(
|
||||
"Unexpected tool message outside a processing group",
|
||||
message,
|
||||
);
|
||||
// After 用户协助 the last group is human/clarification, so later
|
||||
// write_file results have nowhere to attach. Opening a processing
|
||||
// group keeps them renderable and avoids console.error(full message)
|
||||
// on every MessageList render (that froze the SSE thread).
|
||||
groups.push({
|
||||
id: message.id,
|
||||
type: "assistant:processing",
|
||||
messages: [message],
|
||||
});
|
||||
}
|
||||
}
|
||||
continue;
|
||||
|
||||
Reference in new issue
Block a user