fix: add mergeToolResultText for Mistral/Devstral models in OpenRouter

Fixes #10618

Extended model detection to include "devstral" models (mistralai/devstral-2512
contains "devstral" not "mistral") and added mergeToolResultText: true to
prevent "Unexpected role user after role tool" errors.

Root cause: Mistral/Devstral models enforce strict message ordering and reject
a "user" role message immediately after a "tool" role message.
This commit is contained in:
Roo Code 2026-01-15 09:33:45 +00:00
parent 4ee494b08c
commit 226469dab2

View file

@ -231,12 +231,15 @@ export class OpenRouterHandler extends BaseProvider implements SingleCompletionH
// Convert Anthropic messages to OpenAI format.
// Pass normalization function for Mistral compatibility (requires 9-char alphanumeric IDs)
const isMistral = modelId.toLowerCase().includes("mistral")
// Also detect Devstral models which are part of the Mistral family
const isMistralFamily = modelId.toLowerCase().includes("mistral") || modelId.toLowerCase().includes("devstral")
let openAiMessages: OpenAI.Chat.ChatCompletionMessageParam[] = [
{ role: "system", content: systemPrompt },
...convertToOpenAiMessages(
messages,
isMistral ? { normalizeToolCallId: normalizeMistralToolCallId } : undefined,
isMistralFamily
? { normalizeToolCallId: normalizeMistralToolCallId, mergeToolResultText: true }
: undefined,
),
]