fix: add mergeToolResultText for Mistral/Devstral models in OpenRouter

Fixes the "Unexpected role user after role tool" error for Mistral and
Devstral models when using OpenRouter.

Changes:
- Extended model detection to include "devstral" (e.g. mistralai/devstral-2512)
- Added mergeToolResultText: true to merge text content into tool messages
  instead of creating a separate user message that violates Mistral ordering

Closes #10618
This commit is contained in:
Roo Code 2026-01-12 08:59:16 +00:00
parent 44fd975b17
commit 76091b3245

View file

@ -232,13 +232,17 @@ 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")
// Pass normalization function for Mistral/Devstral compatibility (requires 9-char alphanumeric IDs)
// Also merge tool result text to avoid "Unexpected role 'user' after role 'tool'" errors
const modelIdLower = modelId.toLowerCase()
const isMistralFamily = modelIdLower.includes("mistral") || modelIdLower.includes("devstral")
let openAiMessages: OpenAI.Chat.ChatCompletionMessageParam[] = [
{ role: "system", content: systemPrompt },
...convertToOpenAiMessages(
messages,
isMistral ? { normalizeToolCallId: normalizeMistralToolCallId } : undefined,
isMistralFamily
? { normalizeToolCallId: normalizeMistralToolCallId, mergeToolResultText: true }
: undefined,
),
]