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

@@ -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,