mirror of
https://github.com/Wei-Shaw/claude-relay-service.git
synced 2026-01-23 09:38:02 +00:00
Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
338d44faee | ||
|
|
968398ffa5 | ||
|
|
645ab43675 | ||
|
|
0f5321b0ef | ||
|
|
c7d7bf47d6 | ||
|
|
ebc30b6026 | ||
|
|
d5a7af2d7d | ||
|
|
81a3e26e27 | ||
|
|
64db4a270d | ||
|
|
ca027ecb90 |
@@ -274,7 +274,9 @@ const handleResponses = async (req, res) => {
|
||||
'text_formatting',
|
||||
'truncation',
|
||||
'text',
|
||||
'service_tier'
|
||||
'service_tier',
|
||||
'prompt_cache_retention',
|
||||
'safety_identifier'
|
||||
]
|
||||
fieldsToRemove.forEach((field) => {
|
||||
delete req.body[field]
|
||||
|
||||
@@ -65,6 +65,13 @@ function normalizePermissions(permissions) {
|
||||
if (permissions === 'all') {
|
||||
return []
|
||||
}
|
||||
// 兼容逗号分隔格式(修复历史错误数据,如 "claude,openai")
|
||||
if (permissions.includes(',')) {
|
||||
return permissions
|
||||
.split(',')
|
||||
.map((p) => p.trim())
|
||||
.filter(Boolean)
|
||||
}
|
||||
// 旧单个字符串转为数组
|
||||
return [permissions]
|
||||
}
|
||||
@@ -753,6 +760,9 @@ class ApiKeyService {
|
||||
if (field === 'restrictedModels' || field === 'allowedClients' || field === 'tags') {
|
||||
// 特殊处理数组字段
|
||||
updatedData[field] = JSON.stringify(value || [])
|
||||
} else if (field === 'permissions') {
|
||||
// 权限字段:规范化后JSON序列化,与createApiKey保持一致
|
||||
updatedData[field] = JSON.stringify(normalizePermissions(value))
|
||||
} else if (
|
||||
field === 'enableModelRestriction' ||
|
||||
field === 'enableClientRestriction' ||
|
||||
|
||||
@@ -343,8 +343,8 @@ class BedrockRelayService {
|
||||
res.write(`event: ${claudeEvent.type}\n`)
|
||||
res.write(`data: ${JSON.stringify(claudeEvent.data)}\n\n`)
|
||||
|
||||
// 提取使用统计
|
||||
if (claudeEvent.type === 'message_stop' && claudeEvent.data.usage) {
|
||||
// 提取使用统计 (usage is reported in message_delta per Claude API spec)
|
||||
if (claudeEvent.type === 'message_delta' && claudeEvent.data.usage) {
|
||||
totalUsage = claudeEvent.data.usage
|
||||
}
|
||||
|
||||
@@ -576,14 +576,28 @@ class BedrockRelayService {
|
||||
return {
|
||||
type: 'message_start',
|
||||
data: {
|
||||
type: 'message',
|
||||
id: `msg_${Date.now()}_bedrock`,
|
||||
role: 'assistant',
|
||||
content: [],
|
||||
model: this.defaultModel,
|
||||
stop_reason: null,
|
||||
stop_sequence: null,
|
||||
usage: bedrockChunk.message?.usage || { input_tokens: 0, output_tokens: 0 }
|
||||
type: 'message_start',
|
||||
message: {
|
||||
id: `msg_${Date.now()}_bedrock`,
|
||||
type: 'message',
|
||||
role: 'assistant',
|
||||
content: [],
|
||||
model: this.defaultModel,
|
||||
stop_reason: null,
|
||||
stop_sequence: null,
|
||||
usage: bedrockChunk.message?.usage || { input_tokens: 0, output_tokens: 0 }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (bedrockChunk.type === 'content_block_start') {
|
||||
return {
|
||||
type: 'content_block_start',
|
||||
data: {
|
||||
type: 'content_block_start',
|
||||
index: bedrockChunk.index || 0,
|
||||
content_block: bedrockChunk.content_block || { type: 'text', text: '' }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -592,16 +606,28 @@ class BedrockRelayService {
|
||||
return {
|
||||
type: 'content_block_delta',
|
||||
data: {
|
||||
type: 'content_block_delta',
|
||||
index: bedrockChunk.index || 0,
|
||||
delta: bedrockChunk.delta || {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (bedrockChunk.type === 'content_block_stop') {
|
||||
return {
|
||||
type: 'content_block_stop',
|
||||
data: {
|
||||
type: 'content_block_stop',
|
||||
index: bedrockChunk.index || 0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (bedrockChunk.type === 'message_delta') {
|
||||
return {
|
||||
type: 'message_delta',
|
||||
data: {
|
||||
type: 'message_delta',
|
||||
delta: bedrockChunk.delta || {},
|
||||
usage: bedrockChunk.usage || {}
|
||||
}
|
||||
@@ -612,7 +638,7 @@ class BedrockRelayService {
|
||||
return {
|
||||
type: 'message_stop',
|
||||
data: {
|
||||
usage: bedrockChunk.usage || {}
|
||||
type: 'message_stop'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,6 +79,11 @@ const PROMPT_DEFINITIONS = {
|
||||
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."
|
||||
},
|
||||
claudeOtherSystemPrompt5: {
|
||||
category: 'system',
|
||||
title: 'Claude CLI Billing Header',
|
||||
text: 'x-anthropic-billing-header: cc_version=2.1.15.c5a; cc_entrypoint=cli'
|
||||
},
|
||||
claudeOtherSystemPromptCompact: {
|
||||
category: 'system',
|
||||
title: 'Claude Code Compact System Prompt',
|
||||
|
||||
@@ -13,8 +13,8 @@ const OAUTH_CONFIG = {
|
||||
AUTHORIZE_URL: 'https://claude.ai/oauth/authorize',
|
||||
TOKEN_URL: 'https://console.anthropic.com/v1/oauth/token',
|
||||
CLIENT_ID: '9d1c250a-e61b-44d9-88ed-5944d1962f5e',
|
||||
REDIRECT_URI: 'https://console.anthropic.com/oauth/code/callback',
|
||||
SCOPES: 'org:create_api_key user:profile user:inference',
|
||||
REDIRECT_URI: 'https://platform.claude.com/oauth/code/callback',
|
||||
SCOPES: 'org:create_api_key user:profile user:inference user:sessions:claude_code',
|
||||
SCOPES_SETUP: 'user:inference' // Setup Token 只需要推理权限
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@ function generateState() {
|
||||
|
||||
/**
|
||||
* 生成随机的 code verifier(PKCE)
|
||||
* 符合 RFC 7636 标准:32字节随机数 → base64url编码 → 43字符
|
||||
* @returns {string} base64url 编码的随机字符串
|
||||
*/
|
||||
function generateCodeVerifier() {
|
||||
|
||||
@@ -59,7 +59,7 @@ class ClaudeCodeValidator {
|
||||
typeof customThreshold === 'number' && Number.isFinite(customThreshold)
|
||||
? customThreshold
|
||||
: SYSTEM_PROMPT_THRESHOLD
|
||||
|
||||
|
||||
for (const entry of systemEntries) {
|
||||
const rawText = typeof entry?.text === 'string' ? entry.text : ''
|
||||
const { bestScore, templateId, maskedRaw } = bestSimilarityByTemplates(rawText)
|
||||
|
||||
@@ -1246,6 +1246,12 @@ onMounted(async () => {
|
||||
} catch {
|
||||
perms = VALID_PERMS.includes(perms) ? [perms] : []
|
||||
}
|
||||
} else if (perms.includes(',')) {
|
||||
// 兼容逗号分隔格式(如 "claude,openai")
|
||||
perms = perms
|
||||
.split(',')
|
||||
.map((p) => p.trim())
|
||||
.filter((p) => VALID_PERMS.includes(p))
|
||||
} else if (VALID_PERMS.includes(perms)) {
|
||||
perms = [perms]
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user