mirror of
https://github.com/Kilo-Org/kilocode.git
synced 2026-09-19 01:51:21 +08:00
Merge pull request #6538 from Kilo-Org/christiaan/another-reasoning-fix-attempt
Update duplicate reasoning hack after OpenRouter AI SDK patch
This commit is contained in:
@@ -252,25 +252,39 @@ export namespace ProviderTransform {
|
||||
}
|
||||
|
||||
// kilocode_change - function added
|
||||
function fixDuplicateReasoning(msgs: ModelMessage[]) {
|
||||
function fixDuplicateReasoning(msgs: ModelMessage[], model: Provider.Model) {
|
||||
for (const msg of msgs) {
|
||||
if (!Array.isArray(msg.content)) {
|
||||
if (msg.role !== "assistant" || !Array.isArray(msg.content)) {
|
||||
continue
|
||||
}
|
||||
let isFirstToolCall = true
|
||||
const set = new Set<string>()
|
||||
for (const part of msg.content) {
|
||||
if (part.type === "reasoning") {
|
||||
// this entry is corrupt
|
||||
delete part.providerOptions?.openrouter?.reasoning_details
|
||||
}
|
||||
if (part.type === "tool-call" && isFirstToolCall) {
|
||||
isFirstToolCall = false
|
||||
const openrouterProviderOptions = part.providerOptions?.openrouter as
|
||||
| {
|
||||
reasoning_details?: { data?: string; text?: string; signature?: string }[]
|
||||
}
|
||||
| undefined
|
||||
if (!openrouterProviderOptions || !openrouterProviderOptions.reasoning_details) {
|
||||
continue
|
||||
}
|
||||
if (part.type === "tool-call") {
|
||||
// this is a duplicate entry
|
||||
delete part.providerOptions?.openrouter?.reasoning_details
|
||||
}
|
||||
openrouterProviderOptions.reasoning_details = openrouterProviderOptions.reasoning_details.filter((rd) => {
|
||||
if (rd.data) {
|
||||
if (!set.has(rd.data)) {
|
||||
set.add(rd.data)
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
if (rd.text) {
|
||||
if ((model.family === "claude" || model.id.includes("claude")) && !rd.signature) return false
|
||||
if (!set.has(rd.text)) {
|
||||
set.add(rd.text)
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
return true
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -282,7 +296,7 @@ export namespace ProviderTransform {
|
||||
// kilocode_change - workaround for @openrouter/ai-sdk-provider v1 duplicating reasoning
|
||||
// fixed in https://github.com/OpenRouterTeam/ai-sdk-provider/pull/344/
|
||||
if (model.api.npm === "@kilocode/kilo-gateway") {
|
||||
fixDuplicateReasoning(msgs)
|
||||
fixDuplicateReasoning(msgs, model)
|
||||
}
|
||||
|
||||
if (
|
||||
|
||||
Reference in New Issue
Block a user