解析工具调用参数,优化事件处理逻辑

This commit is contained in:
2026-04-30 13:38:53 +08:00
parent 36d1a8d6ea
commit 85b4f45d4a
2 changed files with 57 additions and 2 deletions
+29
View File
@@ -97,6 +97,35 @@ describe("streamAgentChat", () => {
});
});
it("parses legacy tool_call arguments when params is empty", async () => {
apiFetch.mockResolvedValue({
ok: true,
body: makeStream([
'event: tool_call\ndata: {"conversationId":"agent-1e75dd01-29e","tool":"locate_features","params":{},"arguments":"{\\"ids\\":[\\"142902\\"],\\"feature_type\\":\\"junction\\"}"}\n\n',
'event: done\ndata: {"session_id":"agent-1e75dd01-29e"}\n\n',
]),
});
const events: Array<{
type: string;
sessionId?: string;
tool?: string;
params?: Record<string, unknown>;
}> = [];
await streamAgentChat({
message: "hi",
onEvent: (event) => events.push(event),
});
expect(events[0]).toEqual({
type: "tool_call",
sessionId: "agent-1e75dd01-29e",
tool: "locate_features",
params: { ids: ["142902"], feature_type: "junction" },
});
});
it("emits error when response is not ok", async () => {
apiFetch.mockResolvedValue({
ok: false,