fix(transform): stream reasoning correctly on the OpenRouter managed path#111
Merged
Merged
Conversation
…path
Now that managed wallet inference routes through OpenRouter, its reasoning
must actually stream. OpenRouter emits reasoning via its unified
`reasoning`/`reasoning_details` fields, but only when a `reasoning` object
is requested. Three gaps left managed reasoning blank:
- options() only set `reasoning:{effort}` for gemini-3. Request it for
every reasoning-capable OpenRouter model (medium effort; gemini-3 high),
so Claude/GPT/etc routed through OR stream their traces. A selected
effort variant still overrides via mergeDeep in llm.ts.
- An OR-routed gpt-5 fell into the OpenAI-Responses block and got
reasoningEffort/reasoningSummary/include — keys OR ignores — so it
requested no reasoning in OR's shape and streamed an empty trace.
Exclude the OR npm from that block.
- smallOptions() returned the OpenAI `reasoningEffort` key for OR gpt-5
small calls (the gpt-5 check ran before the openrouter branch, which was
therefore dead code). Check OpenRouter first and disable reasoning via
OR's unified shape so title/summary/compaction don't reason or bill.
Direct OpenAI (BYOK and the openai-via-proxy edge) is unchanged.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to the managed⇒OpenRouter routing PR: once wallet inference goes through OpenRouter, its reasoning has to actually stream. OpenRouter exposes reasoning via its unified
reasoning/reasoning_detailsfields, but only when areasoningobject is requested. Three gaps left managed reasoning blank:options()only requested reasoning for gemini-3. Every other reasoning-capable OpenRouter model (Claude, GPT, DeepSeek, …) gotusage.includebut noreasoningobject → the upstream reasoned silently and OR dropped the trace. Now requestreasoning:{effort}for every reasoning-capable OR model (medium; gemini-3 high). A selected effort variant still overrides viamergeDeepinllm.ts.reasoningEffort/reasoningSummary/include: reasoning.encrypted_content— keys OR ignores — so it requested no reasoning in OR's shape. Exclude the OR npm from that block.smallOptions()OpenRouter branch was dead code: a small ORgpt-5-nanomatched thegpt-5check first and returned the OpenAIreasoningEffort: "minimal"key (ignored by OR → reasoning still ran and billed on title/summary/compaction). Check OpenRouter first and disable reasoning via OR's unifiedreasoning:{enabled:false}. (This was a real bug the plan's original edit missed — the new test caught it.)Direct OpenAI (BYOK + the openai-via-proxy edge) is untouched.
Tests
test/provider/transform-reasoning.test.ts: OR reasoning requested for Claude/GPT/gemini-3; OR gpt-5 usesreasoning.effortnot the OpenAI keys; non-reasoning OR models get no reasoning object; direct-OpenAI paths keep their existing keys; small OR disables reasoning. All 69 existing transform tests still pass.