Support Claude Opus 4.7 via adaptive thinking provider options#445
Support Claude Opus 4.7 via adaptive thinking provider options#445sidneyswift wants to merge 2 commits intotestfrom
Conversation
…435) (#440) * chore(lint): scope eslint rules by file type + residual code fixes Splits eslint.config.js into three file-scoped rule blocks so strict JSDoc requirements apply only where they belong: - all `**/*.ts`: keeps import/first, prettier, member-ordering, and tightens `no-unused-vars` to `argsIgnorePattern: "^_"` (was `"^_$"` which only matched bare `_`) - `app/api/**/*.ts`: retains the full jsdoc ruleset per CLAUDE.md's "all API routes require JSDoc" mandate - test files (`**/*.test.ts`, `**/__tests__/**`): disables `no-explicit-any` and `jsdoc/require-jsdoc` — tests legitimately need loose typing and don't ship as docs Residual code-level fixes the new config surfaces: - `lib/credits/getCreditUsage.ts`: replace `(usage as any)` with a typed Partial record narrowing - `lib/content/templates/types.ts`, `lib/trigger/fetchTriggerRuns.ts`: move `[key: string]: unknown` index signature before named fields (member-ordering) - `lib/artists/createArtistInDb.ts`, `lib/workspaces/createWorkspaceInDb.ts`: drop unused `error` binding from catch - misc test files: remove unused imports/vars, fix import/first ordering * docs(api): meaningful JSDoc for 19 route handlers Writes endpoint-specific JSDoc against the strict rules scoped to `app/api/**`. Each handler now documents the HTTP verb + path, the request body/query shape (referencing the `validate*Body` / `validate*Query` schema file where applicable), the success response shape, and the relevant non-200 status codes. No placeholder filler — every description conveys something the signature does not. Files: - accounts/[id], admins/coding/pr, admins/coding/slack, admins/content/slack, admins/privy - chats/[id]/messages/trailing - coding-agent/callback, coding-agent/github - connectors - content (PATCH), content/analyze, content/caption, content/image, content/templates/[id], content/transcribe, content/upscale, content/video - songs/analyze/presets - transcribe * fix(credits): use typed LanguageModelUsage fields; restore json() assertion in sandbox test - `getCreditUsage`: drop the hand-rolled Partial-record cast and the v2-compat `promptTokens`/`completionTokens` fallback — `LanguageModelUsage` (= V3Usage) already types `inputTokens` / `outputTokens` directly, and the real runtime caller (`handleChatCredits`) passes this exact type. The compat branch was dead against the typed surface. - `getCreditUsage.test.ts`: update mock usage objects from the legacy `promptTokens`/`completionTokens` shape to the SDK V3 shape the function is actually typed against. - `postSandboxesFilesHandler.test.ts`: restore `result.json()` so the 500-path still asserts the response is valid JSON (not just status code), matching the original test intent. * docs(api): correct @returns shape for coding-agent github webhook Cubic review feedback: the JSDoc claimed `{ ok: true }` on 200 but the handler returns `{ status: <outcome> }` payloads (`update_triggered`, `ignored`, `busy`, `no_state`, `updating`) and `{ status: "error", error }` on non-200s. Update the doc to match the actual contract. --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Opus 4.7 rejects the old thinking.type: "enabled" + budgetTokens shape with a 400 error and requires thinking.type: "adaptive" + effort. Adaptive mode is also preferred (but not required) for Opus 4.6 and Sonnet 4.6, while older Anthropic models (Sonnet 4.5, Opus 4.5, Haiku 3.x) only support the legacy enabled shape. Extract a model-aware helper that returns the correct AnthropicProviderOptions shape for each model instead of hardcoding one config for every Anthropic model. Legacy config remains the safe default for unknown or non-Anthropic model IDs. Upgrade @ai-sdk/anthropic 3.0.13 → 3.0.70 so the SDK schema accepts the adaptive discriminant and the top-level effort parameter. Verified via changelog review that 3.0.14 → 3.0.70 contains no breaking changes (all patch-level additions) and that the ai-v6 track is unaffected. Verification: - All 1906 existing tests pass after the SDK bump - 9 new unit tests for the helper (adaptive / legacy / defensive branches) - 3 new integration tests on getGeneralAgent verifying wiring per model - Lint clean Made-with: Cursor
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (4)
📒 Files selected for processing (2)
📝 WalkthroughWalkthroughA new utility function Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 1✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
No issues found across 6 files
Confidence score: 5/5
- Automated review surfaced no issues in the provided summaries.
- No files require special attention.
Requires human review: This PR modifies core agent logic and includes a production dependency update (@ai-sdk/anthropic 3.0.13 -> 3.0.70) which requires human review for stability.
Architecture diagram
sequenceDiagram
participant UI as Chat UI
participant API as Chat API Route
participant Factory as getGeneralAgent
participant Helper as getAnthropicProviderOptions
participant SDK as @ai-sdk/anthropic (v3.0.70)
participant Anthropic as Anthropic API
UI->>API: POST /api/chat { model: "anthropic/claude-opus-4.7", messages }
API->>Factory: getGeneralAgent(body)
Note over Factory,Helper: NEW: Model-aware provider options selection
Factory->>Helper: NEW: getAnthropicProviderOptions(modelId)
alt Model is Opus 4.7, 4.6, or Sonnet 4.6
Helper-->>Factory: { thinking: { type: "adaptive", display: "summarized" }, effort: "medium" }
else Model is Sonnet 4.5, Opus 4.5, or Legacy/Unknown
Helper-->>Factory: { thinking: { type: "enabled", budgetTokens: 12000 } }
end
Factory->>Factory: Initialize ToolLoopAgent with providerOptions
Factory-->>API: Return Agent Instance
API->>SDK: streamText() with providerOptions
rect rgb(240, 240, 240)
Note right of SDK: CHANGED: SDK v3.0.70 validates "adaptive" schema
SDK->>Anthropic: Request with selected thinking config
alt Path: Adaptive (Opus 4.7)
Anthropic-->>SDK: 200 OK + Thinking Blocks
else Path: Legacy config sent to Opus 4.7
Note right of Anthropic: Rejects old 'enabled' type for 4.7
Anthropic-->>SDK: 400 Bad Request
end
end
SDK-->>UI: Stream response to client
Summary
Fixes the "thinking.type.enabled is not supported for this model" error users hit when selecting Claude Opus 4.7. Opus 4.7 rejects the old thinking config (`type: "enabled"` + `budgetTokens`) with a 400 error and requires the new `type: "adaptive"` shape. Adaptive is also preferred (but not required) on Opus 4.6 and Sonnet 4.6, while older Anthropic models (Sonnet 4.5, Opus 4.5, Haiku 3.x) only support the legacy shape.
Why this wasn't a one-line flip
A simple `enabled` → `adaptive` swap would break every Anthropic model below 4.6 that's still in the model list. The fix needs to be model-aware.
Changes
Model compatibility matrix (from Anthropic docs)
Due diligence — why this upgrade is low-risk
Verification
Test plan
Follow-ups (not in this PR)
Made with Cursor
Summary by cubic
Support Claude Opus 4.7 with model-aware Anthropic thinking options. Enables adaptive mode where required and keeps legacy settings for older models to prevent 400s.
New Features
getAnthropicProviderOptions(modelId)to return the rightAnthropicProviderOptionsper model.anthropic/claude-opus-4.7,anthropic/claude-opus-4.6,anthropic/claude-sonnet-4.6withdisplay: "summarized"andeffort: "medium".enabledwithbudgetTokens: 12000for older, unknown, and non-Anthropic models.getGeneralAgentto setproviderOptions.anthropic.Dependencies
@ai-sdk/anthropicfrom^3.0.13to^3.0.70to supporttype: "adaptive".Written for commit 69bcc4a. Summary will update on new commits.
Summary by CodeRabbit