

























@@ -577,6 +577,48 @@ describe("convertToOllamaMessages", () => {
577577]);
578578});
579579580+it("preserves exact allowlisted tool-prefix names before Ollama replay", () => {
581+const messages = [
582+{
583+role: "assistant",
584+content: [
585+{ type: "toolCall", id: "call_1", name: "tool_a", arguments: { value: 1 } },
586+{ type: "tool_use", id: "call_2", name: "tools_invoke_test", input: { value: 2 } },
587+{ type: "toolCall", id: "call_3", name: "function-run", arguments: { value: 3 } },
588+],
589+},
590+];
591+const result = convertToOllamaMessages(messages, undefined, {
592+availableToolNames: new Set(["tool_a", "tools_invoke_test", "function-run"]),
593+});
594+expect(result[0].tool_calls).toEqual([
595+{ function: { name: "tool_a", arguments: { value: 1 } } },
596+{ function: { name: "tools_invoke_test", arguments: { value: 2 } } },
597+{ function: { name: "function-run", arguments: { value: 3 } } },
598+]);
599+});
600+601+it("strips underscore and dash provider prefixes only when the suffix is allowlisted", () => {
602+const messages = [
603+{
604+role: "assistant",
605+content: [
606+{ type: "toolCall", id: "call_1", name: "tools_exec", arguments: { command: "pwd" } },
607+{ type: "tool_use", id: "call_2", name: "function-read", input: { path: "." } },
608+{ type: "toolCall", id: "call_3", name: "tool_missing", arguments: {} },
609+],
610+},
611+];
612+const result = convertToOllamaMessages(messages, undefined, {
613+availableToolNames: new Set(["exec", "read"]),
614+});
615+expect(result[0].tool_calls).toEqual([
616+{ function: { name: "exec", arguments: { command: "pwd" } } },
617+{ function: { name: "read", arguments: { path: "." } } },
618+{ function: { name: "tool_missing", arguments: {} } },
619+]);
620+});
621+580622it("keeps non-prefixed Ollama replay tool names intact", () => {
581623const messages = [
582624{
@@ -585,6 +627,7 @@ describe("convertToOllamaMessages", () => {
585627{ type: "toolCall", id: "call_1", name: "functionshell", arguments: {} },
586628{ type: "toolCall", id: "call_2", name: "tooling", arguments: {} },
587629{ type: "toolCall", id: "call_3", name: "tools", arguments: {} },
630+{ type: "toolCall", id: "call_4", name: "tool_a", arguments: {} },
588631],
589632},
590633];
@@ -593,6 +636,7 @@ describe("convertToOllamaMessages", () => {
593636{ function: { name: "functionshell", arguments: {} } },
594637{ function: { name: "tooling", arguments: {} } },
595638{ function: { name: "tools", arguments: {} } },
639+{ function: { name: "tool_a", arguments: {} } },
596640]);
597641});
598642@@ -825,6 +869,39 @@ describe("buildAssistantMessage", () => {
825869]);
826870});
827871872+it("preserves exact allowlisted tool-prefix names in Ollama responses", () => {
873+const response = {
874+model: "qwen3:32b",
875+created_at: "2026-01-01T00:00:00Z",
876+message: {
877+role: "assistant" as const,
878+content: "",
879+tool_calls: [
880+{ function: { name: "tool_a", arguments: { value: 1 } } },
881+{ function: { name: "tools_invoke_test", arguments: { value: 2 } } },
882+{ function: { name: "function-run", arguments: { value: 3 } } },
883+],
884+},
885+done: true,
886+};
887+const result = buildAssistantMessage(response, modelInfo, undefined, {
888+availableToolNames: new Set(["tool_a", "tools_invoke_test", "function-run"]),
889+});
890+expect(result.content).toEqual([
891+expect.objectContaining({ type: "toolCall", name: "tool_a", arguments: { value: 1 } }),
892+expect.objectContaining({
893+type: "toolCall",
894+name: "tools_invoke_test",
895+arguments: { value: 2 },
896+}),
897+expect.objectContaining({
898+type: "toolCall",
899+name: "function-run",
900+arguments: { value: 3 },
901+}),
902+]);
903+});
904+828905it("keeps non-prefixed Ollama response tool names intact", () => {
829906const response = {
830907model: "qwen3:32b",
@@ -836,6 +913,7 @@ describe("buildAssistantMessage", () => {
836913{ function: { name: "functionshell", arguments: {} } },
837914{ function: { name: "tooling", arguments: {} } },
838915{ function: { name: "tools", arguments: {} } },
916+{ function: { name: "tool_a", arguments: {} } },
839917],
840918},
841919done: true,
@@ -845,6 +923,7 @@ describe("buildAssistantMessage", () => {
845923expect.objectContaining({ type: "toolCall", name: "functionshell", arguments: {} }),
846924expect.objectContaining({ type: "toolCall", name: "tooling", arguments: {} }),
847925expect.objectContaining({ type: "toolCall", name: "tools", arguments: {} }),
926+expect.objectContaining({ type: "toolCall", name: "tool_a", arguments: {} }),
848927]);
849928});
850929此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。