修复 Claude /anthropic 模型发现回退#554
Conversation
Allow Claude sites configured under an /anthropic path to fall back to the parent OpenAI-compatible models endpoint so model refresh works without changing chat routing. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
📝 WalkthroughWalkthroughClaudeAdapter now implements a two-stage model discovery mechanism: it first attempts to fetch models from the ChangesClaude Adapter Fallback Model Discovery
Sequence DiagramsequenceDiagram
participant ClaudeAdapter
participant AnthroPrimary as /anthropic/v1/models
participant OpenAiFallback as /v1/models (fallback)
ClaudeAdapter->>AnthroPrimary: GET with x-api-key, anthropic-version
alt Primary Success
AnthroPrimary-->>ClaudeAdapter: 200 models response
ClaudeAdapter->>ClaudeAdapter: Return model IDs
else Primary Fails (404)
AnthroPrimary-->>ClaudeAdapter: 404 error
ClaudeAdapter->>OpenAiFallback: GET with Authorization: Bearer
OpenAiFallback-->>ClaudeAdapter: 200 models response
ClaudeAdapter->>ClaudeAdapter: Return model IDs
else Non-Anthropic URL
ClaudeAdapter->>OpenAiFallback: GET with Authorization: Bearer
OpenAiFallback-->>ClaudeAdapter: error or non-success
ClaudeAdapter->>ClaudeAdapter: Return []
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint skipped: no ESLint configuration detected in root package.json. To enable, add Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. 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.
🧹 Nitpick comments (1)
src/server/services/platforms/claude.test.ts (1)
3-3: ⚡ Quick winUse a type-only import for
AddressInfoas it's only used in a type assertion.While the repo configuration doesn't enforce this rule (
verbatimModuleSyntaxis not enabled), it's a best practice to mark type-only imports explicitly.💡 Suggested fix
-import { AddressInfo } from 'node:net'; +import type { AddressInfo } from 'node:net';🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/server/services/platforms/claude.test.ts` at line 3, The import of AddressInfo is used only as a type assertion in claude.test.ts; change it to a type-only import to avoid importing at runtime by replacing the current import of AddressInfo with a type-only import (i.e., import type { AddressInfo } from 'node:net') so references to AddressInfo (used in the test assertions/type casts) remain purely compile-time.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@src/server/services/platforms/claude.test.ts`:
- Line 3: The import of AddressInfo is used only as a type assertion in
claude.test.ts; change it to a type-only import to avoid importing at runtime by
replacing the current import of AddressInfo with a type-only import (i.e.,
import type { AddressInfo } from 'node:net') so references to AddressInfo (used
in the test assertions/type casts) remain purely compile-time.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 7d1fb89b-8506-4174-be56-766be0427b8f
📒 Files selected for processing (2)
src/server/services/platforms/claude.test.tssrc/server/services/platforms/claude.ts
Brings in 8 upstream commits: - fix: Claude anthropic model discovery fallback (cita-777#554) - chore(deps): minor-and-patch group bumps (14 deps) - chore(deps): marked 17 -> 18 - chore(deps-dev): electron 41 -> 42 - chore(deps-dev): react-router-dom 7.14 -> 7.15 - chore(deps): undici 6.24 -> 6.25 (runtime-http group) - chore(deps-dev): build-tooling group - chore(deps): github-actions group Conflict resolution: - src/server/services/platforms/claude.ts (content conflict) - src/server/services/platforms/claude.test.ts (add/add conflict) Both conflicts were resolved with --ours: the local fork's implementation of the Claude model discovery fallback (commit 4ecf3f3, "feat(claude-models): fall back to parent /v1/models when /anthropic/v1/models is empty") is a strict superset of upstream PR cita-777#554. Specifically, the local fork: - reuses CLAUDE_DEFAULT_ANTHROPIC_VERSION from oauth/claudeProvider.js rather than re-hardcoding the literal '2023-06-01' string (single source of truth). - exposes pure URL helpers (isAnthropicSuffixedBaseUrl, stripAnthropicSuffixSegment) on standardApiProvider.ts with 34 parameterized unit tests covering case variants, trailing-slash, query/port preservation, host-only and /anthropic-proxy negatives. - emits two info-level diagnostic logs ([claude-models-fallback] intent / hit) with token-free site labels for operator visibility. - absorbs underlying errors from BOTH the standard and the fallback call so getModels() never throws a network/HTTP error to the caller. - carries 27 integration tests via a node:http fixture covering every failure mode and zero cross-call state. Verification: - npm run typecheck:server: clean - npm run build:server: clean - npm run repo:drift-check: 0 new violations (5 pre-existing tracked) - src/server/services/platforms/{claude,standardApiProvider,llmUpstream}.test.ts: 70/70 - session-stick-routing-binding-timing-fix suites: 72/72
摘要
/anthropic/v1/models没有返回模型时,改查父级 OpenAI 兼容的/v1/models。/anthropic/v1/messages。/anthropic地址不回退的场景。测试
npm test -- src/server/services/platforms/claude.test.ts🤖 Generated with Claude Code
Summary by CodeRabbit
Release Notes