Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/opencode/src/session/message-v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -793,7 +793,7 @@ export namespace MessageV2 {
assistantMessage.parts.push({
type: "reasoning",
text: part.text,
...(differentModel ? {} : { providerMetadata: part.metadata }),
providerMetadata: part.metadata,
})
}
}
Expand Down
43 changes: 43 additions & 0 deletions packages/opencode/test/session/message-v2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,49 @@ describe("session.message-v2.toModelMessage", () => {
])
})

test("preserves reasoning providerMetadata even when assistant model differs", async () => {
const userID = "m-user"
const assistantID = "m-assistant"

const input: MessageV2.WithParts[] = [
{
info: userInfo(userID),
parts: [
{
...basePart(userID, "u1"),
type: "text",
text: "think about this",
},
] as MessageV2.Part[],
},
{
info: assistantInfo(assistantID, userID, undefined, { providerID: "other", modelID: "other" }),
parts: [
{
...basePart(assistantID, "a1"),
type: "reasoning",
text: "reasoning trace",
time: { start: 0 },
metadata: { anthropic: { signature: "sig-abc" } },
},
] as MessageV2.Part[],
} as MessageV2.WithParts,
]

expect(await MessageV2.toModelMessages(input, model)).toStrictEqual([
{
role: "user",
content: [{ type: "text", text: "think about this" }],
},
{
role: "assistant",
content: [
{ type: "reasoning", text: "reasoning trace", providerOptions: { anthropic: { signature: "sig-abc" } } },
],
},
])
})

test("replaces compacted tool output with placeholder", async () => {
const userID = "m-user"
const assistantID = "m-assistant"
Expand Down
Loading