mirror of
https://github.com/NanmiCoder/cc-haha
synced 2026-07-16 13:03:31 +08:00
Third-party Anthropic-compatible providers can expose Claude model names without supporting every first-party runtime capability. Desktop sessions now preserve provider-specific capability overrides, keep selected provider runtime state across reconnects and restarts, and keep the provider dialog behavior aligned with the updated presets. Constraint: Custom ANTHROPIC_BASE_URL endpoints must not be treated as first-party Anthropic for adaptive thinking support. Rejected: Rename provider default Sonnet models | that would hide the compatibility issue instead of fixing runtime capability detection. Confidence: high Scope-risk: moderate Directive: Do not enable Claude first-party capability defaults for custom Anthropic-compatible base URLs without provider verification. Tested: bun test src/utils/__tests__/thinking.test.ts src/server/__tests__/conversation-service.test.ts src/server/__tests__/provider-presets.test.ts src/server/__tests__/conversations.test.ts Tested: cd desktop && bun run lint Tested: cd desktop && bun run test src/components/shared/Modal.test.tsx --run Tested: git diff --check
51 lines
1.6 KiB
TypeScript
51 lines
1.6 KiB
TypeScript
import memoize from 'lodash-es/memoize.js'
|
|
import { getAPIProvider, isFirstPartyAnthropicBaseUrl } from './providers.js'
|
|
|
|
export type ModelCapabilityOverride =
|
|
| 'effort'
|
|
| 'max_effort'
|
|
| 'thinking'
|
|
| 'adaptive_thinking'
|
|
| 'interleaved_thinking'
|
|
|
|
const TIERS = [
|
|
{
|
|
modelEnvVar: 'ANTHROPIC_DEFAULT_OPUS_MODEL',
|
|
capabilitiesEnvVar: 'ANTHROPIC_DEFAULT_OPUS_MODEL_SUPPORTED_CAPABILITIES',
|
|
},
|
|
{
|
|
modelEnvVar: 'ANTHROPIC_DEFAULT_SONNET_MODEL',
|
|
capabilitiesEnvVar: 'ANTHROPIC_DEFAULT_SONNET_MODEL_SUPPORTED_CAPABILITIES',
|
|
},
|
|
{
|
|
modelEnvVar: 'ANTHROPIC_DEFAULT_HAIKU_MODEL',
|
|
capabilitiesEnvVar: 'ANTHROPIC_DEFAULT_HAIKU_MODEL_SUPPORTED_CAPABILITIES',
|
|
},
|
|
] as const
|
|
|
|
/**
|
|
* Check whether a 3p model capability override is set for a model that matches one of
|
|
* the pinned ANTHROPIC_DEFAULT_*_MODEL env vars.
|
|
*/
|
|
export const get3PModelCapabilityOverride = memoize(
|
|
(model: string, capability: ModelCapabilityOverride): boolean | undefined => {
|
|
if (getAPIProvider() === 'firstParty' && isFirstPartyAnthropicBaseUrl()) {
|
|
return undefined
|
|
}
|
|
const m = model.toLowerCase()
|
|
for (const tier of TIERS) {
|
|
const pinned = process.env[tier.modelEnvVar]
|
|
const capabilities = process.env[tier.capabilitiesEnvVar]
|
|
if (!pinned || capabilities === undefined) continue
|
|
if (m !== pinned.toLowerCase()) continue
|
|
return capabilities
|
|
.toLowerCase()
|
|
.split(',')
|
|
.map(s => s.trim())
|
|
.includes(capability)
|
|
}
|
|
return undefined
|
|
},
|
|
(model, capability) => `${model.toLowerCase()}:${capability}`,
|
|
)
|