mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-11 09:42:15 +03:00
fix(types): narrow DeepSeek tool calls (#9860)
Co-authored-by: backryun <bakryun0718@proton.me>
This commit is contained in:
committed by
GitHub
parent
a1833b1159
commit
a7d2dba1eb
@@ -515,7 +515,6 @@ export function messagesToPrompt(
|
||||
historyWindow = 0
|
||||
): string {
|
||||
if (messages.length === 0) return "";
|
||||
|
||||
const systemParts: string[] = [];
|
||||
const conversation: Array<{ role: string; text: string }> = [];
|
||||
const callNameById = new Map<string, string>();
|
||||
@@ -527,8 +526,9 @@ export function messagesToPrompt(
|
||||
} else if (m.role === "user" || m.role === "assistant") {
|
||||
if (text) conversation.push({ role: m.role, text });
|
||||
if (m.role === "user") lastUserContent = text;
|
||||
const calls = Array.isArray((m as { tool_calls?: unknown }).tool_calls)
|
||||
? (m as { tool_calls: Array<{ id?: string; function?: { name?: string } }> }).tool_calls
|
||||
const toolCalls = (m as { tool_calls?: unknown }).tool_calls;
|
||||
const calls = Array.isArray(toolCalls)
|
||||
? (toolCalls as Array<{ id?: string; function?: { name?: string } }>)
|
||||
: [];
|
||||
for (const c of calls) {
|
||||
if (c?.id && typeof c.function?.name === "string") callNameById.set(c.id, c.function.name);
|
||||
|
||||
@@ -64,3 +64,11 @@ test("messagesToPrompt still drops empty tool results without crashing (#4712)",
|
||||
assert.match(prompt, /hello/);
|
||||
assert.match(prompt, /world/);
|
||||
});
|
||||
|
||||
test("messagesToPrompt ignores malformed assistant tool calls", () => {
|
||||
const prompt = messagesToPrompt([
|
||||
{ role: "assistant", content: "thinking", tool_calls: { id: "not-an-array" } },
|
||||
{ role: "user", content: "continue" },
|
||||
]);
|
||||
assert.match(prompt, /continue/);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user