Skip to content

飞书桥接 + AWS Bedrock Provider:Claude 模型被误报为协议不匹配 #648

Description

@luckisnow

问题描述

在飞书桥接(Feishu Bridge)中,将 Provider 配置为 AWS Bedrockprotocol: 'bedrock')并使用 Claude 模型(如 global.anthropic.claude-sonnet-5)时,发送消息会报错:

Error: Provider "AWS Bedrock" uses bedrock protocol but model "global.anthropic.claude-sonnet-5" is an Anthropic model. Please configure the correct provider for this bridge channel.

即使模型 ID 是 Bedrock 上真实存在、可用的模型,该报错依然会触发,无法正常使用。

根因

src/lib/bridge/conversation-engine.ts 附近(约第 183-191 行)有一段 fail-fast 保护逻辑:

const isAnthropicModel = modelLower.includes('claude') || ['sonnet','opus','haiku'].includes(modelLower);
const isNonAnthropicProtocol = !['anthropic', 'openai-compatible', 'openrouter'].includes(resolved.protocol);
if (isAnthropicModel && isNonAnthropicProtocol) {
  throw new Error(...);
}

问题在于协议白名单 ['anthropic', 'openai-compatible', 'openrouter']漏掉了 bedrockvertex。而 AWS Bedrock 和 Google Vertex AI 恰恰是官方支持、专门用来托管运行 Claude/Anthropic 模型的两个云协议——这一点可以从代码库自身另一处常量得到印证(runtime-compat.ts):

const CLAUDE_CODE_READY_PRESETS = new Set(['anthropic-official', 'bedrock', 'vertex']);

这里已经明确把 bedrockvertexanthropic-official 并列,认定它们都是能正常运行 Claude Code 的正规协议。

因此,只要 provider 的 protocolbedrock(或 vertex),并且模型名包含 "claude"/"sonnet"/"opus"/"haiku",这条 guard 就会必定误报,把"协议本来就是用来服务 Anthropic 模型的"错误判断为"协议和模型不匹配"。

复现步骤

  1. 在 CodePilot 中新建一个 Provider,protocol 选择 bedrock,配置好 AWS 凭证。
  2. 将该 Provider 设为某个飞书桥接频道/群的默认 Provider,模型填一个真实存在的 Claude 模型 ID(例如 global.anthropic.claude-sonnet-5)。
  3. 在飞书里给机器人发消息。
  4. 收到报错:Provider "AWS Bedrock" uses bedrock protocol but model "..." is an Anthropic model...

建议修复

conversation-engine.ts 中的协议白名单补全为:

const isNonAnthropicProtocol = !['anthropic', 'openai-compatible', 'openrouter', 'bedrock', 'vertex'].includes(resolved.protocol);

环境

  • CodePilot 桌面版(macOS)
  • 触发场景:飞书消息桥接(Feishu Bridge)+ AWS Bedrock Provider

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions