commit
06a94b2319
3 changed files with 43 additions and 30 deletions
|
|
@ -61,7 +61,7 @@ export class CodexConverter extends BaseConverter {
|
|||
effort: 'medium',
|
||||
summary: 'auto'
|
||||
},
|
||||
parallel_tool_calls: data.parallel_tool_calls !== false,
|
||||
parallel_tool_calls: true,
|
||||
include: ['reasoning.encrypted_content']
|
||||
};
|
||||
|
||||
|
|
@ -83,16 +83,10 @@ export class CodexConverter extends BaseConverter {
|
|||
codexRequest.reasoning.effort = data.reasoning_effort;
|
||||
}
|
||||
|
||||
// 添加温度和其他参数
|
||||
if (data.temperature !== undefined) {
|
||||
codexRequest.temperature = data.temperature;
|
||||
}
|
||||
if (data.max_tokens !== undefined) {
|
||||
codexRequest.max_output_tokens = data.max_tokens;
|
||||
}
|
||||
if (data.top_p !== undefined) {
|
||||
codexRequest.top_p = data.top_p;
|
||||
}
|
||||
/*
|
||||
Codex doesn't support temperature, top_p, top_k, max_tokens anymore in the new protocol.
|
||||
Removed mapping for these fields.
|
||||
*/
|
||||
|
||||
return codexRequest;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import os from 'os';
|
|||
import { refreshCodexTokensWithRetry } from '../../auth/oauth-handlers.js';
|
||||
import { getProviderPoolManager } from '../../services/service-manager.js';
|
||||
import { MODEL_PROVIDER, formatExpiryLog } from '../../utils/common.js';
|
||||
import { getProxyConfigForProvider } from '../../utils/proxy-utils.js';
|
||||
|
||||
/**
|
||||
* Codex API 服务类
|
||||
|
|
@ -77,10 +78,10 @@ export class CodexApiService {
|
|||
creds = JSON.parse(await fs.readFile(credsPath, 'utf8'));
|
||||
}
|
||||
|
||||
this.accessToken = creds.access_token;
|
||||
this.refreshToken = creds.refresh_token;
|
||||
this.accountId = creds.account_id;
|
||||
this.email = creds.email;
|
||||
this.accessToken = creds.access_token;
|
||||
this.refreshToken = creds.refresh_token;
|
||||
this.accountId = creds.account_id;
|
||||
this.email = creds.email;
|
||||
this.expiresAt = new Date(creds.expired); // 注意:字段名是 expired
|
||||
|
||||
// 检查 token 是否需要刷新
|
||||
|
|
@ -117,7 +118,7 @@ export class CodexApiService {
|
|||
}
|
||||
logger.info('[Codex] Token expiring soon or refresh requested, refreshing...');
|
||||
await this.refreshAccessToken();
|
||||
|
||||
|
||||
// 刷新成功,重置 PoolManager 中的刷新状态并标记为健康
|
||||
const poolManager = getProviderPoolManager();
|
||||
if (poolManager && this.uuid) {
|
||||
|
|
@ -150,16 +151,25 @@ export class CodexApiService {
|
|||
const headers = this.buildHeaders(body.prompt_cache_key);
|
||||
|
||||
try {
|
||||
const response = await axios.post(url, body, {
|
||||
const config = {
|
||||
headers,
|
||||
timeout: 120000 // 2 分钟超时
|
||||
});
|
||||
};
|
||||
|
||||
// 配置代理
|
||||
const proxyConfig = getProxyConfigForProvider(this.config, 'codex');
|
||||
if (proxyConfig) {
|
||||
config.httpAgent = proxyConfig.httpAgent;
|
||||
config.httpsAgent = proxyConfig.httpsAgent;
|
||||
}
|
||||
|
||||
const response = await axios.post(url, body, config);
|
||||
|
||||
return this.parseNonStreamResponse(response.data);
|
||||
} catch (error) {
|
||||
if (error.response?.status === 401) {
|
||||
logger.info('[Codex] Received 401. Triggering background refresh via PoolManager...');
|
||||
|
||||
|
||||
// 标记当前凭证为不健康(会自动进入刷新队列)
|
||||
const poolManager = getProviderPoolManager();
|
||||
if (poolManager && this.uuid) {
|
||||
|
|
@ -203,17 +213,26 @@ export class CodexApiService {
|
|||
const headers = this.buildHeaders(body.prompt_cache_key);
|
||||
|
||||
try {
|
||||
const response = await axios.post(url, body, {
|
||||
const config = {
|
||||
headers,
|
||||
responseType: 'stream',
|
||||
timeout: 120000
|
||||
});
|
||||
};
|
||||
|
||||
// 配置代理
|
||||
const proxyConfig = getProxyConfigForProvider(this.config, 'codex');
|
||||
if (proxyConfig) {
|
||||
config.httpAgent = proxyConfig.httpAgent;
|
||||
config.httpsAgent = proxyConfig.httpsAgent;
|
||||
}
|
||||
|
||||
const response = await axios.post(url, body, config);
|
||||
|
||||
yield* this.parseSSEStream(response.data);
|
||||
} catch (error) {
|
||||
if (error.response?.status === 401) {
|
||||
logger.info('[Codex] Received 401 during stream. Triggering background refresh via PoolManager...');
|
||||
|
||||
|
||||
// 标记当前凭证为不健康
|
||||
const poolManager = getProviderPoolManager();
|
||||
if (poolManager && this.uuid) {
|
||||
|
|
|
|||
|
|
@ -62,12 +62,12 @@ export function isProxyEnabledForProvider(config, providerType) {
|
|||
if (!config || !config.PROXY_URL || !config.PROXY_ENABLED_PROVIDERS) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
const enabledProviders = config.PROXY_ENABLED_PROVIDERS;
|
||||
if (!Array.isArray(enabledProviders)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
return enabledProviders.includes(providerType);
|
||||
}
|
||||
|
||||
|
|
@ -81,10 +81,10 @@ export function getProxyConfigForProvider(config, providerType) {
|
|||
if (!isProxyEnabledForProvider(config, providerType)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
const proxyConfig = parseProxyUrl(config.PROXY_URL);
|
||||
if (proxyConfig) {
|
||||
logger.info(`[Proxy] Using ${proxyConfig.proxyType} proxy for ${providerType}: ${config.PROXY_URL}`);
|
||||
// logger.info(`[Proxy] Using ${proxyConfig.proxyType} proxy for ${providerType}: ${config.PROXY_URL}`);
|
||||
}
|
||||
return proxyConfig;
|
||||
}
|
||||
|
|
@ -98,7 +98,7 @@ export function getProxyConfigForProvider(config, providerType) {
|
|||
*/
|
||||
export function configureAxiosProxy(axiosConfig, config, providerType) {
|
||||
const proxyConfig = getProxyConfigForProvider(config, providerType);
|
||||
|
||||
|
||||
if (proxyConfig) {
|
||||
// 使用代理 agent
|
||||
axiosConfig.httpAgent = proxyConfig.httpAgent;
|
||||
|
|
@ -106,7 +106,7 @@ export function configureAxiosProxy(axiosConfig, config, providerType) {
|
|||
// 禁用 axios 内置的代理配置,使用我们的 agent
|
||||
axiosConfig.proxy = false;
|
||||
}
|
||||
|
||||
|
||||
return axiosConfig;
|
||||
}
|
||||
|
||||
|
|
@ -118,12 +118,12 @@ export function configureAxiosProxy(axiosConfig, config, providerType) {
|
|||
*/
|
||||
export function getGoogleAuthProxyConfig(config, providerType) {
|
||||
const proxyConfig = getProxyConfigForProvider(config, providerType);
|
||||
|
||||
|
||||
if (proxyConfig) {
|
||||
return {
|
||||
agent: proxyConfig.httpsAgent
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue