fix(types): narrow DeepSeek tool calls (#9860)

Co-authored-by: backryun <bakryun0718@proton.me>
This commit is contained in:
Diego Rodrigues de Sa e Souza
2026-08-09 09:52:54 -03:00
committed by GitHub
parent a1833b1159
commit a7d2dba1eb
2 changed files with 11 additions and 3 deletions

View File

@@ -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);

View File

@@ -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/);
});