refactor: 将 codex provider 重命名为 openai-responses

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
claude-code-best
2026-04-26 21:44:27 +08:00
parent 00cf974a4b
commit 25c322c8db
15 changed files with 193 additions and 53 deletions

View File

@@ -1347,7 +1347,7 @@ async function* queryModel(
return
}
if (getAPIProvider() === 'codex') {
if (getAPIProvider() === 'openai-responses') {
const { queryModelCodex } = await import('./codex/index.js')
yield* queryModelCodex(messagesForAPI, systemPrompt, filteredTools, signal, options)
return

View File

@@ -3,6 +3,8 @@ import { openaiAdapter } from 'src/services/providerUsage/adapters/openai.js'
import { updateProviderBuckets } from 'src/services/providerUsage/store.js'
import { getProxyFetchOptions } from 'src/utils/proxy.js'
export const DEFAULT_CODEX_BASE_URL = 'https://api.openai.com/v1'
let cachedClient: OpenAI | null = null
function wrapFetchForUsage(base: typeof fetch): typeof fetch {
@@ -11,7 +13,7 @@ function wrapFetchForUsage(base: typeof fetch): typeof fetch {
): Promise<Response> => {
const res = await base(...args)
try {
updateProviderBuckets('codex', openaiAdapter.parseHeaders(res.headers))
updateProviderBuckets('openai-responses', openaiAdapter.parseHeaders(res.headers))
} catch {
// Usage tracking must not affect the request path.
}
@@ -29,13 +31,13 @@ export function getCodexClient(options?: {
}
const apiKey = process.env.CODEX_API_KEY || ''
const baseURL = process.env.CODEX_BASE_URL
const baseURL = process.env.CODEX_BASE_URL || DEFAULT_CODEX_BASE_URL
const baseFetch = options?.fetchOverride ?? (globalThis.fetch as typeof fetch)
const wrappedFetch = wrapFetchForUsage(baseFetch)
const client = new OpenAI({
apiKey,
...(baseURL && { baseURL }),
baseURL,
maxRetries: options?.maxRetries ?? 0,
timeout: parseInt(process.env.API_TIMEOUT_MS || String(600 * 1000), 10),
dangerouslyAllowBrowser: true,

View File

@@ -260,7 +260,9 @@ export async function* queryModelCodex(
recordLLMObservation(options.langfuseTrace ?? null, {
model,
provider: 'codex',
provider: process.env.CODEX_LOGIN_METHOD === 'chatgpt_subscription'
? 'codex-chatgpt'
: 'openai-responses',
input: convertMessagesToLangfuse(messagesForAPI, systemPrompt),
output: convertOutputToLangfuse(collectedMessages),
usage: totalUsage,

View File

@@ -57,7 +57,8 @@ const PROVIDER_GENERATION_NAMES: Record<string, string> = {
vertex: 'ChatVertexAnthropic',
foundry: 'ChatFoundry',
openai: 'ChatOpenAI',
codex: 'ChatOpenAIResponses',
'openai-responses': 'ChatOpenAIResponses',
'codex-chatgpt': 'ChatCodex',
gemini: 'ChatGoogleGenerativeAI',
grok: 'ChatXAI',
}