Skip to content
Open
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
5 changes: 5 additions & 0 deletions .changeset/fix-reasoning-only-resume.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@moonshot-ai/kimi-code": patch
---

Fix resumed reasoning-only sessions with OpenAI-compatible providers.
2 changes: 2 additions & 0 deletions packages/kosong/src/providers/openai-legacy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,8 @@ function convertMessage(
result.content = nonThinkParts
.map((p) => convertContentPart(p))
.filter((p): p is OpenAIContentPart => p !== null);
} else if (message.role === 'assistant' && message.toolCalls.length === 0) {
result.content = '';
}
}

Expand Down
20 changes: 20 additions & 0 deletions packages/kosong/test/openai-legacy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1113,6 +1113,26 @@ describe('OpenAILegacyChatProvider', () => {
});
});

it('includes empty content for reasoning-only assistant messages without tool calls', async () => {
const provider = createProvider({ model: 'deepseek-reasoner' });
const history: Message[] = [
{
role: 'assistant',
content: [{ type: 'think', think: 'reasoning before the crash' }],
toolCalls: [],
},
];

const body = await captureRequestBody(provider, '', [], history);
const messages = body['messages'] as Record<string, unknown>[];

expect(messages[0]).toEqual({
role: 'assistant',
content: '',
reasoning_content: 'reasoning before the crash',
});
});

it('serializes an explicitly empty ThinkPart to reasoning_content', async () => {
const provider = createProvider({ model: 'deepseek-reasoner' });
const history: Message[] = [
Expand Down