diff --git a/backend/internal/service/bedrock_request.go b/backend/internal/service/bedrock_request.go index beb61cd7af..f7a5d0c1c9 100644 --- a/backend/internal/service/bedrock_request.go +++ b/backend/internal/service/bedrock_request.go @@ -471,11 +471,11 @@ func parseAnthropicBetaHeader(header string) []string { // 参考: AWS Bedrock 官方文档 + litellm anthropic_beta_headers_config.json // 更新策略: 当 AWS Bedrock 新增支持的 beta token 时需同步更新此白名单 var bedrockSupportedBetaTokens = map[string]bool{ - "computer-use-2025-01-24": true, - "computer-use-2025-11-24": true, - "context-1m-2025-08-07": true, - "context-management-2025-06-27": true, // compaction + clear_thinking,AWS 文档已支持 - "compact-2026-01-12": true, // 官方支持,仅 InvokeModel API(Opus 4.6+) + "computer-use-2025-01-24": true, + "computer-use-2025-11-24": true, + "context-1m-2025-08-07": true, + "context-management-2025-06-27": true, // compaction + clear_thinking,AWS 文档已支持 + "compact-2026-01-12": true, // 官方支持,仅 InvokeModel API(Opus 4.6+) "fine-grained-tool-streaming-2025-05-14": true, // AWS Tool Use 文档已支持 // "interleaved-thinking-2025-05-14": false, // 无官方文档支持 "tool-search-tool-2025-10-19": true, diff --git a/backend/internal/service/bedrock_request_test.go b/backend/internal/service/bedrock_request_test.go index c5b71da74f..e466c82ca9 100644 --- a/backend/internal/service/bedrock_request_test.go +++ b/backend/internal/service/bedrock_request_test.go @@ -411,7 +411,7 @@ func TestPrepareBedrockRequestBodyWithTokens_ContextManagementRequiresSupportedB assert.Equal(t, int64(100), gjson.GetBytes(result, "max_tokens").Int()) }) - t.Run("filters explicit unsupported context-management beta and strips field", func(t *testing.T) { + t.Run("keeps supported context-management beta and retains field", func(t *testing.T) { input := `{ "messages":[{"role":"user","content":"hi"}], "max_tokens":100, @@ -426,8 +426,8 @@ func TestPrepareBedrockRequestBodyWithTokens_ContextManagementRequiresSupportedB ) require.NoError(t, err) - assert.False(t, gjson.GetBytes(result, "context_management").Exists()) - assert.Equal(t, []string{"context-1m-2025-08-07"}, bedrockAnthropicBetaNames(result)) + assert.True(t, gjson.GetBytes(result, "context_management").Exists()) + assert.Equal(t, []string{bedrockContextManagementBetaToken, "context-1m-2025-08-07"}, bedrockAnthropicBetaNames(result)) }) } diff --git a/backend/internal/service/error_passthrough_runtime_test.go b/backend/internal/service/error_passthrough_runtime_test.go index b9e882cc90..73a4bfab19 100644 --- a/backend/internal/service/error_passthrough_runtime_test.go +++ b/backend/internal/service/error_passthrough_runtime_test.go @@ -298,7 +298,8 @@ func TestHandleErrorResponse_PassthroughRuleSetsCommitted(t *testing.T) { assert.Equal(t, http.StatusBadRequest, rec.Code) var payload map[string]any require.NoError(t, json.Unmarshal(rec.Body.Bytes(), &payload)) - errField := payload["error"].(map[string]any) + errField, ok := payload["error"].(map[string]any) + require.True(t, ok, "payload[\"error\"] should be map[string]any") assert.Equal(t, "参数错误", errField["message"]) }