fix: 适配Claude agent-sdk转发

This commit is contained in:
shaw
2025-10-07 14:00:09 +08:00
parent 1fdfce1e4f
commit 52af60b3c9
2 changed files with 6 additions and 10 deletions

View File

@@ -74,6 +74,11 @@ const PROMPT_DEFINITIONS = {
title: 'Claude Agent SDK System Prompt', title: 'Claude Agent SDK System Prompt',
text: "You are a Claude agent, built on Anthropic's Claude Agent SDK." text: "You are a Claude agent, built on Anthropic's Claude Agent SDK."
}, },
claudeOtherSystemPrompt4: {
category: 'system',
title: 'Claude Code Compact System Prompt Agent SDK2',
text: "You are Claude Code, Anthropic's official CLI for Claude, running within the Claude Agent SDK."
},
claudeOtherSystemPromptCompact: { claudeOtherSystemPromptCompact: {
category: 'system', category: 'system',
title: 'Claude Code Compact System Prompt', title: 'Claude Code Compact System Prompt',

View File

@@ -74,16 +74,7 @@ class ClaudeCodeValidator {
const userAgent = req.headers['user-agent'] || '' const userAgent = req.headers['user-agent'] || ''
const path = req.path || '' const path = req.path || ''
// 1. 先检查是否是 Claude Code 的 User-Agent const claudeCodePattern = /^claude-cli\/\d+\.\d+\.\d+/i;
// 支持的格式:
// - claude-cli/1.0.86 (external, cli) - 原有 CLI 格式
// - claude-cli/2.0.0 (external, claude-vscode) - VSCode 插件格式
// - claude-cli/x.x.x (external, sdk-py) - Python SDK 格式
// - claude-cli/x.x.x (external, sdk-js) - JavaScript SDK 格式
// - 其他 (external, claude-xxx) 或 (external, sdk-xxx) 格式
const claudeCodePattern =
/^claude-cli\/[\d.]+(?:[-\w]*)?\s+\(external,\s*(?:cli|claude-[\w-]+|sdk-[\w-]+)\)$/i
if (!claudeCodePattern.test(userAgent)) { if (!claudeCodePattern.test(userAgent)) {
// 不是 Claude Code 的请求,此验证器不处理 // 不是 Claude Code 的请求,此验证器不处理