feat(opencode): use adaptive thinking effort for kimi family on anthr…#37696
Open
chouqin wants to merge 1 commit into
Open
feat(opencode): use adaptive thinking effort for kimi family on anthr…#37696chouqin wants to merge 1 commit into
chouqin wants to merge 1 commit into
Conversation
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.
Issue for this PR
Closes #
Type of change
What does this PR do?
Kimi/Moonshot's Anthropic-compatible endpoints implement Anthropic's adaptive thinking contract (
thinking.type="adaptive"+output_config.effort, includingxhighand thedisplayfield). Today opencode sends manual thinkingwith a hardcoded
budgetTokens: 16000default for kimi models on@ai-sdk/anthropic, and exposes no effort variants for them.Changes:
{type: "adaptive", display: "summarized"}witheffort: "high"instead of budget tokens.display: "summarized"matters because newer adaptive modelsdefault to omitting thinking text, and that text is what gets replayed on subsequent requests.
variants()exposeslow/medium/high/xhigh/maxfor kimi models on@ai-sdk/anthropic, each mapping to adaptive thinking + effort.anthropicEfforttreats kimi family as adaptive. This also fixes models.dev-declared effort options (e.g.kimi-k3low/high/max) being silently dropped — the anthropic branch previously returnedundefinedfor non-Claude modelids.
Why it works:
@ai-sdk/anthropicalready lowersproviderOptions.anthropic.thinking = {type: "adaptive"}andproviderOptions.anthropic.efforttothinking+output_config.efforton the wire, so no SDK change is needed. Kimifamily detection matches providerID / api id / model id / api url (
isKimiFamily). OpenAI-compatible kimi paths are untouched, and user-selected variants still override the default (merge order unchanged).Note: an identical
isKimiFamilyhelper also appears in my other PR (preserve unsigned thinking). They are independent; whichever lands second rebases to keep a single copy.How did you verify your code works?
test/provider/transform.test.ts: default adaptive+effort for kimi on anthropic npm (asserting nobudgetTokens), no thinking default for non-reasoning kimi / non-kimi anthropic / kimi on openai-compatible, thefive effort variants' shape, and models.dev effort options mapping for a kimi-k3-like entry.
bun test test/provider/transform.test.ts→ 352 pass, plusbun typecheckfrompackages/opencode.@ai-sdk/anthropic@3.0.82with a stub fetch capturing the request body: with the providerOptions this PR emits, the outgoing body containsthinking: {"type":"adaptive","display":"summarized"}and
output_config: {"effort":"high"}. (No live Moonshot call — worth a quick manual check with a real key before merge.)Screenshots / recordings
If this is a UI change, please include a screenshot or recording.
Checklist
If you do not follow this template your PR will be automatically rejected.