Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions open-sse/executors/deepseek-web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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>();
Expand All @@ -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);
Expand Down
8 changes: 8 additions & 0 deletions tests/unit/deepseek-web-tool-result-prompt-4712.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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/);
});
Loading