fix(core): preserve late opaque reasoning (#45694)

This commit is contained in:
Kit Langton 2026-08-28 16:55:13 -04:00 committed by GitHub
parent d354c3d640
commit a35f96f427
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 29 additions and 3 deletions

View file

@ -653,7 +653,11 @@ export class OpenAICompatibleChatLanguageModel implements LanguageModelV3 {
}
if (isActiveText) {
controller.enqueue({ type: "text-end", id: "txt-0" })
controller.enqueue({
type: "text-end",
id: "txt-0",
providerMetadata: reasoningOpaque ? { copilot: { reasoningOpaque } } : undefined,
})
}
// go through all tool calls and send the ones that are not finished

View file

@ -244,14 +244,25 @@ describe("doStream", () => {
expect(reasoningEndIndex).toBeLessThan(textStartIndex)
// In this fixture, reasoning_opaque comes AFTER content has started (in chunk 4)
// So it arrives too late to be attached to reasoning-end. But it should still
// be captured and included in the finish event's providerMetadata.
// So it arrives too late to be attached to reasoning-end. It should still be
// captured on the completed text part and the finish event.
const reasoningEnd = parts.find((p) => p.type === "reasoning-end")
expect(reasoningEnd).toMatchObject({
type: "reasoning-end",
id: "reasoning-0",
})
const textEnd = parts.find((p) => p.type === "text-end")
expect(textEnd).toEqual({
type: "text-end",
id: "txt-0",
providerMetadata: {
copilot: {
reasoningOpaque: "/PMlTqxqSJZnUBDHgnnJKLVI4eZQ",
},
},
})
// reasoning_opaque should be in the finish event's providerMetadata
const finish = parts.find((p) => p.type === "finish")
expect(finish).toMatchObject({
@ -305,6 +316,17 @@ describe("doStream", () => {
},
})
const textEnd = parts.find((p) => p.type === "text-end")
expect(textEnd).toEqual({
type: "text-end",
id: "txt-0",
providerMetadata: {
copilot: {
reasoningOpaque: "ExXaGwW7jBo39OXRe9EPoFGN1rOtLJBx",
},
},
})
// Check text deltas
const textDeltas = parts.filter((p) => p.type === "text-delta")
expect(textDeltas).toHaveLength(2)