mirror of
https://github.com/claude-code-best/claude-code.git
synced 2026-06-17 22:05:50 +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>
40 lines
1.1 KiB
TypeScript
40 lines
1.1 KiB
TypeScript
import type { BetaToolUnion } from '@anthropic-ai/sdk/resources/beta/messages/messages.mjs'
|
|
import type { Tool as CodexTool } from 'openai/resources/responses/responses.mjs'
|
|
|
|
function isClientFunctionTool(
|
|
tool: BetaToolUnion,
|
|
): tool is BetaToolUnion & {
|
|
name: string
|
|
description?: string
|
|
input_schema?: { [key: string]: unknown }
|
|
strict?: boolean
|
|
defer_loading?: boolean
|
|
} {
|
|
const value = tool as unknown as Record<string, unknown>
|
|
return typeof value.name === 'string'
|
|
}
|
|
|
|
export function anthropicToolsToCodex(
|
|
tools: BetaToolUnion[],
|
|
): CodexTool[] {
|
|
return tools.flatMap(tool => {
|
|
const value = tool as unknown as Record<string, unknown>
|
|
if (
|
|
value.type === 'advisor_20260301' ||
|
|
value.type === 'computer_20250124' ||
|
|
!isClientFunctionTool(tool)
|
|
) {
|
|
return []
|
|
}
|
|
|
|
return [{
|
|
type: 'function',
|
|
name: tool.name,
|
|
description: tool.description,
|
|
parameters: tool.input_schema ?? {},
|
|
strict: tool.strict ?? null,
|
|
...(tool.defer_loading && { defer_loading: true }),
|
|
}]
|
|
})
|
|
}
|