Skip to content

Commit 36d92e3

Browse files
author
kostiantyn-kugot
committed
fix: blank assistant text with MCP enabled after AI SDK v6 migration
The v6 upgrade changed the default unmapped finish reason from 'unknown' to 'other', but the prompt loop continue sets were not updated to match. This caused premature loop exit after MCP tool calls, before the model produced final assistant text. Additionally, the LLM middleware still targeted legacy 'prompt' param key while v6 Responses requests use 'messages' or 'input', causing ProviderTransform.message() to be silently skipped. Fixes #20050 Fixes #20465
1 parent ce19c05 commit 36d92e3

2 files changed

Lines changed: 12 additions & 4 deletions

File tree

packages/opencode/src/session/llm.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -376,8 +376,16 @@ export namespace LLM {
376376
specificationVersion: "v3" as const,
377377
async transformParams(args) {
378378
if (args.type === "stream") {
379-
// @ts-expect-error
380-
args.params.prompt = ProviderTransform.message(args.params.prompt, input.model, options)
379+
if ("messages" in args.params && Array.isArray(args.params.messages)) {
380+
args.params.messages = ProviderTransform.message(args.params.messages, input.model, options)
381+
}
382+
if ("input" in args.params && Array.isArray(args.params.input)) {
383+
args.params.input = ProviderTransform.message(args.params.input, input.model, options)
384+
}
385+
if ("prompt" in args.params && Array.isArray(args.params.prompt)) {
386+
// @ts-expect-error legacy prompt shape differs from v3 prompt typing
387+
args.params.prompt = ProviderTransform.message(args.params.prompt, input.model, options)
388+
}
381389
}
382390
return args.params
383391
},

packages/opencode/src/session/prompt.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1340,7 +1340,7 @@ NOTE: At any point in time through this workflow you should feel free to ask the
13401340

13411341
if (
13421342
lastAssistant?.finish &&
1343-
!["tool-calls"].includes(lastAssistant.finish) &&
1343+
!["tool-calls", "other"].includes(lastAssistant.finish) &&
13441344
!hasToolCalls &&
13451345
lastUser.id < lastAssistant.id
13461346
) {
@@ -1494,7 +1494,7 @@ NOTE: At any point in time through this workflow you should feel free to ask the
14941494
return "break" as const
14951495
}
14961496

1497-
const finished = handle.message.finish && !["tool-calls", "unknown"].includes(handle.message.finish)
1497+
const finished = handle.message.finish && !["tool-calls", "other"].includes(handle.message.finish)
14981498
if (finished && !handle.message.error) {
14991499
if (format.type === "json_schema") {
15001500
handle.message.error = new MessageV2.StructuredOutputError({

0 commit comments

Comments
 (0)