解析工具调用参数,优化事件处理逻辑
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user