fix: add claude-opus-4-6 mapping and strip [1m] suffix for Bedrock

- Add model mapping: claude-opus-4-6 → us.anthropic.claude-opus-4-6-v1
- Strip [1m] suffix before model lookup (Claude Code sends e.g.
  claude-opus-4-6[1m] for 1M context variant)
- Bedrock supports 1M context natively for Opus 4.6, so the same
  model ID works — the [1m] suffix just needs to be removed
This commit is contained in:
bensonz
2026-02-10 14:12:41 +08:00
parent bf6b19370b
commit 6acdd0ba5f

View File

@@ -433,8 +433,15 @@ class BedrockRelayService {
// 将标准Claude模型名映射为Bedrock格式
_mapToBedrockModel(modelName) {
// Strip [1m] suffix (long context variant) — Bedrock uses the same model ID
// but supports 1M context natively for models that have it
const cleanModelName = modelName.replace(/\[1m\]$/, '')
// 标准Claude模型名到Bedrock模型名的映射表
const modelMapping = {
// Claude Opus 4.6
'claude-opus-4-6': 'us.anthropic.claude-opus-4-6-v1',
// Claude 4.5 Opus
'claude-opus-4-5': 'us.anthropic.claude-opus-4-5-20251101-v1:0',
'claude-opus-4-5-20251101': 'us.anthropic.claude-opus-4-5-20251101-v1:0',
@@ -479,21 +486,21 @@ class BedrockRelayService {
// 如果已经是Bedrock格式直接返回
// Bedrock模型格式{region}.anthropic.{model-name} 或 anthropic.{model-name}
if (modelName.includes('.anthropic.') || modelName.startsWith('anthropic.')) {
return modelName
if (cleanModelName.includes('.anthropic.') || cleanModelName.startsWith('anthropic.')) {
return cleanModelName
}
// 查找映射
const mappedModel = modelMapping[modelName]
const mappedModel = modelMapping[cleanModelName]
if (mappedModel) {
return mappedModel
}
// 如果没有找到映射,返回原始模型名(可能会导致错误,但保持向后兼容)
logger.warn(`⚠️ 未找到模型映射: ${modelName},使用原始模型名`, {
logger.warn(`⚠️ 未找到模型映射: ${cleanModelName},使用原始模型名`, {
metadata: { originalModel: modelName }
})
return modelName
return cleanModelName
}
// 选择使用的区域