fix(mistral): retain provider-returned streaming model as responseModel (#128066)

Co-authored-by: Aniruddha Adak <aniruddhaadak80@users.noreply.github.com>
This commit is contained in:
ANIRUDDHA ADAK
2026-08-25 15:08:34 +05:30
committed by GitHub
parent 4c82554b51
commit 75d80fc5da
2 changed files with 26 additions and 0 deletions
+21
View File
@@ -800,6 +800,27 @@ describe("Mistral provider", () => {
cacheWrite: 0,
totalTokens: 110,
});
expect(result.responseId).toBe("response-cache-usage");
expect(result.responseModel).toBe("mistral-small-latest");
});
it("omits responseModel when streamed model matches the requested id", async () => {
mistralMockState.streamResult = {
async *[Symbol.asyncIterator]() {
yield {
data: {
id: "response-same-model",
model: "mistral-large-latest",
choices: [{ finishReason: "stop", delta: { content: "ok" } }],
},
};
},
};
const result = await runMistralFixture(context, { apiKey: "fixture" });
expect(result.responseId).toBe("response-same-model");
expect(result).not.toHaveProperty("responseModel");
});
it("preserves tool-result boundary whitespace in the request payload", async () => {
+5
View File
@@ -593,6 +593,11 @@ async function consumeChatStream(
// Mistral's streamed CompletionChunk carries an id field. Keep the first non-empty one,
// mirroring how OpenAI-style streaming exposes a stable response identifier per stream.
output.responseId ||= chunk.id;
// Retain the provider-returned model when it differs from the requested id so
// routed responses are not misattributed, matching the OpenAI sibling stream.
if (typeof chunk.model === "string" && chunk.model.length > 0 && chunk.model !== model.id) {
output.responseModel ||= chunk.model;
}
if (chunk.usage) {
const promptTokens = chunk.usage.promptTokens || 0;