feat: 添加 Bedrock API 客户端及 API 层增强

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
unraid
2026-04-22 22:38:09 +08:00
parent 59f8675fa3
commit be97a0b010
15 changed files with 1362 additions and 197 deletions

View File

@@ -16,6 +16,7 @@ export const EFFORT_LEVELS = [
'low',
'medium',
'high',
'xhigh',
'max',
] as const satisfies readonly EffortLevel[]
@@ -32,7 +33,11 @@ export function modelSupportsEffort(model: string): boolean {
return supported3P
}
// Supported by a subset of Claude 4 models
if (m.includes('opus-4-6') || m.includes('sonnet-4-6')) {
if (
m.includes('opus-4-7') ||
m.includes('opus-4-6') ||
m.includes('sonnet-4-6')
) {
return true
}
// Exclude any other known legacy models (haiku, older opus/sonnet variants)
@@ -51,13 +56,32 @@ export function modelSupportsEffort(model: string): boolean {
}
// @[MODEL LAUNCH]: Add the new model to the allowlist if it supports 'max' effort.
// Per API docs, 'max' is Opus 4.6 only for public models — other models return an error.
// Per API docs, 'max' is Opus 4.6/4.7 only for public models — other models return an error.
export function modelSupportsMaxEffort(model: string): boolean {
const supported3P = get3PModelCapabilityOverride(model, 'max_effort')
if (supported3P !== undefined) {
return supported3P
}
if (model.toLowerCase().includes('opus-4-6')) {
if (
model.toLowerCase().includes('opus-4-7') ||
model.toLowerCase().includes('opus-4-6')
) {
return true
}
if (process.env.USER_TYPE === 'ant' && resolveAntModel(model)) {
return true
}
return false
}
// @[MODEL LAUNCH]: Add the new model to the allowlist if it supports 'xhigh' effort.
// 'xhigh' was introduced with Opus 4.7 as a level between 'high' and 'max'.
export function modelSupportsXhighEffort(model: string): boolean {
const supported3P = get3PModelCapabilityOverride(model, 'xhigh_effort')
if (supported3P !== undefined) {
return supported3P
}
if (model.toLowerCase().includes('opus-4-7')) {
return true
}
if (process.env.USER_TYPE === 'ant' && resolveAntModel(model)) {
@@ -97,7 +121,12 @@ export function parseEffortValue(value: unknown): EffortValue | undefined {
export function toPersistableEffort(
value: EffortValue | undefined,
): EffortLevel | undefined {
if (value === 'low' || value === 'medium' || value === 'high') {
if (
value === 'low' ||
value === 'medium' ||
value === 'high' ||
value === 'xhigh'
) {
return value
}
if (value === 'max' && process.env.USER_TYPE === 'ant') {
@@ -161,6 +190,10 @@ export function resolveAppliedEffort(
}
const resolved =
envOverride ?? appStateEffortValue ?? getDefaultEffortForModel(model)
// API rejects 'xhigh' on pre-Opus-4.7 models — downgrade to 'high'.
if (resolved === 'xhigh' && !modelSupportsXhighEffort(model)) {
return 'high'
}
// API rejects 'max' on non-Opus-4.6 models — downgrade to 'high'.
if (resolved === 'max' && !modelSupportsMaxEffort(model)) {
return 'high'
@@ -231,8 +264,10 @@ export function getEffortLevelDescription(level: EffortLevel): string {
return 'Balanced approach with standard implementation and testing'
case 'high':
return 'Comprehensive implementation with extensive testing and documentation'
case 'xhigh':
return 'Extended reasoning beyond high, short of max (Opus 4.7 only)'
case 'max':
return 'Maximum capability with deepest reasoning (Opus 4.6 only)'
return 'Maximum capability with deepest reasoning (Opus 4.6/4.7 only)'
}
}
@@ -308,7 +343,10 @@ export function getDefaultEffortForModel(
// Default effort on Opus 4.6 to medium for Pro.
// Max/Team also get medium when the tengu_grey_step2 config is enabled.
if (model.toLowerCase().includes('opus-4-6')) {
if (
model.toLowerCase().includes('opus-4-7') ||
model.toLowerCase().includes('opus-4-6')
) {
if (isProSubscriber()) {
return 'medium'
}