(body: AnthropicRequest)
| 154 | // ==================== 身份探针拦截 ==================== |
| 155 | |
| 156 | export function isIdentityProbe(body: AnthropicRequest): boolean { |
| 157 | if (!body.messages || body.messages.length === 0) return false; |
| 158 | const lastMsg = body.messages[body.messages.length - 1]; |
| 159 | if (lastMsg.role !== 'user') return false; |
| 160 | |
| 161 | let text = ''; |
| 162 | if (typeof lastMsg.content === 'string') { |
| 163 | text = lastMsg.content; |
| 164 | } else if (Array.isArray(lastMsg.content)) { |
| 165 | for (const block of lastMsg.content) { |
| 166 | if (block.type === 'text' && block.text) text += block.text; |
| 167 | } |
| 168 | } |
| 169 | |
| 170 | // 如果有工具定义(agent模式),不拦截身份探针(让agent正常工作) |
| 171 | if (body.tools && body.tools.length > 0) return false; |
| 172 | |
| 173 | return IDENTITY_PROBE_PATTERNS.some(p => p.test(text)); |
| 174 | } |
| 175 | |
| 176 | export function isToolCapabilityQuestion(body: AnthropicRequest): boolean { |
| 177 | if (!body.messages || body.messages.length === 0) return false; |
no outgoing calls
no test coverage detected