mirror of
https://github.com/Wei-Shaw/claude-relay-service.git
synced 2026-01-23 09:21:24 +00:00
fix: 适配Claude agent-sdk转发
This commit is contained in:
@@ -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',
|
||||||
|
|||||||
@@ -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 的请求,此验证器不处理
|
||||||
|
|||||||
Reference in New Issue
Block a user