mirror of
https://github.com/claude-code-best/claude-code.git
synced 2026-06-15 12:55:51 +00:00
- 新增 codex API 客户端、流适配、消息/工具转换、模型映射 - 支持 CODEX_API_KEY 和 CODEX_ACCESS_TOKEN 双认证 fallback - 集成到 claude.ts 调度链和 Langfuse 可观测性 - 包含模型映射单元测试(16 cases) Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
32 lines
786 B
TypeScript
32 lines
786 B
TypeScript
import { createHash } from 'crypto'
|
|
|
|
const MAX_CODEX_CALL_ID_LENGTH = 96
|
|
|
|
export function normalizeCodexCallId(value: unknown): string | null {
|
|
if (typeof value !== 'string') {
|
|
return null
|
|
}
|
|
|
|
const sanitized = value
|
|
.trim()
|
|
.replace(/\s+/g, '_')
|
|
.replace(/[^A-Za-z0-9._:-]/g, '_')
|
|
.replace(/_+/g, '_')
|
|
.slice(0, MAX_CODEX_CALL_ID_LENGTH)
|
|
|
|
return sanitized.length > 0 ? sanitized : null
|
|
}
|
|
|
|
export function createCodexFallbackCallId(seed: string): string {
|
|
const hash = createHash('sha1')
|
|
.update(seed.length > 0 ? seed : 'codex-call')
|
|
.digest('hex')
|
|
.slice(0, 24)
|
|
|
|
return `call_${hash}`
|
|
}
|
|
|
|
export function resolveCodexCallId(value: unknown, seed: string): string {
|
|
return normalizeCodexCallId(value) ?? createCodexFallbackCallId(seed)
|
|
}
|