


























@@ -606,6 +606,73 @@ describe("buildAssistantMessage", () => {
606606expect(toolCall.id).toMatch(/^ollama_call_[0-9a-f-]{36}$/);
607607});
608608609+it("parses stringified tool call arguments from Ollama responses", () => {
610+const response = {
611+model: "qwen3:32b",
612+created_at: "2026-01-01T00:00:00Z",
613+message: {
614+role: "assistant" as const,
615+content: "",
616+tool_calls: [{ function: { name: "bash", arguments: '{"command":"ls","path":"/tmp"}' } }],
617+},
618+done: true,
619+};
620+const result = buildAssistantMessage(response, modelInfo);
621+expect(result.content[0]).toMatchObject({
622+type: "toolCall",
623+name: "bash",
624+arguments: { command: "ls", path: "/tmp" },
625+});
626+});
627+628+it("preserves unsafe integers in stringified tool call arguments", () => {
629+const response = {
630+model: "qwen3:32b",
631+created_at: "2026-01-01T00:00:00Z",
632+message: {
633+role: "assistant" as const,
634+content: "",
635+tool_calls: [
636+{
637+function: {
638+name: "send",
639+arguments: '{"target":9223372036854775807,"nested":{"thread":1234567890123456789}}',
640+},
641+},
642+],
643+},
644+done: true,
645+};
646+const result = buildAssistantMessage(response, modelInfo);
647+expect(result.content[0]).toMatchObject({
648+type: "toolCall",
649+name: "send",
650+arguments: {
651+target: "9223372036854775807",
652+nested: { thread: "1234567890123456789" },
653+},
654+});
655+});
656+657+it("falls back to empty arguments for malformed stringified tool call arguments", () => {
658+const response = {
659+model: "qwen3:32b",
660+created_at: "2026-01-01T00:00:00Z",
661+message: {
662+role: "assistant" as const,
663+content: "",
664+tool_calls: [{ function: { name: "bash", arguments: '{"command":"ls"' } }],
665+},
666+done: true,
667+};
668+const result = buildAssistantMessage(response, modelInfo);
669+expect(result.content[0]).toMatchObject({
670+type: "toolCall",
671+name: "bash",
672+arguments: {},
673+});
674+});
675+609676it("sets all costs to zero for local models", () => {
610677const response = {
611678model: "qwen3:32b",
@@ -701,7 +768,7 @@ describe("parseNdjsonStream", () => {
701768702769// Simulate the accumulation logic from createOllamaStreamFn
703770const accumulatedToolCalls: Array<{
704-function: { name: string; arguments: Record<string, unknown> };
771+function: { name: string; arguments: unknown };
705772}> = [];
706773const chunks = [];
707774for await (const chunk of parseNdjsonStream(reader)) {
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。