fix: 更新Codex策略以适配新的Responses API格式

将Codex的provider策略从OpenAIStrategy切换为ResponsesAPIStrategy,以适配新的API接口。
更新请求头信息,包括版本号、beta特性标志和连接设置。
调整消息转换逻辑,将assistant角色映射为developer角色。
优化token刷新逻辑,确保在刷新成功后重置provider状态。
This commit is contained in:
hex2077 2026-01-25 23:23:15 +08:00
parent e41eb3491a
commit d3c853de94
3 changed files with 19 additions and 20 deletions

View file

@ -130,7 +130,7 @@ export class CodexConverter extends BaseConverter {
if (msg.role === 'user' || msg.role === 'assistant') {
input.push({
type: 'message',
role: msg.role,
role: msg.role === 'assistant' ? 'developer' : msg.role,
content: this.convertMessageContent(msg.content, msg.role)
});

View file

@ -117,12 +117,6 @@ export class CodexApiService {
}
logger.info('[Codex] Token expiring soon or refresh requested, refreshing...');
await this.refreshAccessToken();
// 刷新成功,重置 PoolManager 中的刷新状态并标记为健康
const poolManager = getProviderPoolManager();
if (poolManager && this.uuid) {
poolManager.resetProviderRefreshStatus(MODEL_PROVIDER.CODEX_API, this.uuid);
}
}
}
@ -239,17 +233,18 @@ export class CodexApiService {
*/
buildHeaders(cacheId) {
return {
'Content-Type': 'application/json',
'Authorization': `Bearer ${this.accessToken}`,
'Openai-Beta': 'responses=experimental',
'Version': '0.21.0',
'User-Agent': 'codex_cli_rs/0.50.0 (Mac OS 26.0.1; arm64) Apple_Terminal/464',
'Originator': 'codex_cli_rs',
'Chatgpt-Account-Id': this.accountId,
'Accept': 'text/event-stream',
'Connection': 'Keep-Alive',
'Conversation_id': cacheId,
'Session_id': cacheId
'version': '0.89.0',
'x-codex-beta-features': 'powershell_utf8',
'x-oai-web-search-eligible': 'true',
'session_id': cacheId,
'accept': 'text/event-stream',
'authorization': `Bearer ${this.accessToken}`,
'chatgpt-account-id': this.accountId,
'content-type': 'application/json',
'user-agent': 'codex_cli_rs/0.89.0 (Windows 10.0.26100; x86_64) WindowsTerminal',
'originator': 'codex_cli_rs',
'host': 'chatgpt.com',
'Connection': 'close'
};
}
@ -294,6 +289,11 @@ export class CodexApiService {
// 保存更新的凭据
await this.saveCredentials();
// 刷新成功,重置 PoolManager 中的刷新状态并标记为健康
const poolManager = getProviderPoolManager();
if (poolManager && this.uuid) {
poolManager.resetProviderRefreshStatus(MODEL_PROVIDER.CODEX_API, this.uuid);
}
logger.info('[Codex] Token refreshed successfully');
} catch (error) {
logger.error('[Codex] Failed to refresh token:', error.message);

View file

@ -20,8 +20,7 @@ class ProviderStrategyFactory {
case MODEL_PROTOCOL_PREFIX.CLAUDE:
return new ClaudeStrategy();
case MODEL_PROTOCOL_PREFIX.CODEX:
// Codex 使用 OpenAI 策略(因为它基于 OpenAI 格式)
return new OpenAIStrategy();
return new ResponsesAPIStrategy();
case MODEL_PROTOCOL_PREFIX.FORWARD:
return new ForwardStrategy();
default: