fix: 更新Codex策略以适配新的Responses API格式
将Codex的provider策略从OpenAIStrategy切换为ResponsesAPIStrategy,以适配新的API接口。 更新请求头信息,包括版本号、beta特性标志和连接设置。 调整消息转换逻辑,将assistant角色映射为developer角色。 优化token刷新逻辑,确保在刷新成功后重置provider状态。
This commit is contained in:
parent
e41eb3491a
commit
d3c853de94
3 changed files with 19 additions and 20 deletions
|
|
@ -130,7 +130,7 @@ export class CodexConverter extends BaseConverter {
|
||||||
if (msg.role === 'user' || msg.role === 'assistant') {
|
if (msg.role === 'user' || msg.role === 'assistant') {
|
||||||
input.push({
|
input.push({
|
||||||
type: 'message',
|
type: 'message',
|
||||||
role: msg.role,
|
role: msg.role === 'assistant' ? 'developer' : msg.role,
|
||||||
content: this.convertMessageContent(msg.content, msg.role)
|
content: this.convertMessageContent(msg.content, msg.role)
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -117,12 +117,6 @@ export class CodexApiService {
|
||||||
}
|
}
|
||||||
logger.info('[Codex] Token expiring soon or refresh requested, refreshing...');
|
logger.info('[Codex] Token expiring soon or refresh requested, refreshing...');
|
||||||
await this.refreshAccessToken();
|
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) {
|
buildHeaders(cacheId) {
|
||||||
return {
|
return {
|
||||||
'Content-Type': 'application/json',
|
'version': '0.89.0',
|
||||||
'Authorization': `Bearer ${this.accessToken}`,
|
'x-codex-beta-features': 'powershell_utf8',
|
||||||
'Openai-Beta': 'responses=experimental',
|
'x-oai-web-search-eligible': 'true',
|
||||||
'Version': '0.21.0',
|
'session_id': cacheId,
|
||||||
'User-Agent': 'codex_cli_rs/0.50.0 (Mac OS 26.0.1; arm64) Apple_Terminal/464',
|
'accept': 'text/event-stream',
|
||||||
'Originator': 'codex_cli_rs',
|
'authorization': `Bearer ${this.accessToken}`,
|
||||||
'Chatgpt-Account-Id': this.accountId,
|
'chatgpt-account-id': this.accountId,
|
||||||
'Accept': 'text/event-stream',
|
'content-type': 'application/json',
|
||||||
'Connection': 'Keep-Alive',
|
'user-agent': 'codex_cli_rs/0.89.0 (Windows 10.0.26100; x86_64) WindowsTerminal',
|
||||||
'Conversation_id': cacheId,
|
'originator': 'codex_cli_rs',
|
||||||
'Session_id': cacheId
|
'host': 'chatgpt.com',
|
||||||
|
'Connection': 'close'
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -294,6 +289,11 @@ export class CodexApiService {
|
||||||
// 保存更新的凭据
|
// 保存更新的凭据
|
||||||
await this.saveCredentials();
|
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');
|
logger.info('[Codex] Token refreshed successfully');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error('[Codex] Failed to refresh token:', error.message);
|
logger.error('[Codex] Failed to refresh token:', error.message);
|
||||||
|
|
|
||||||
|
|
@ -20,8 +20,7 @@ class ProviderStrategyFactory {
|
||||||
case MODEL_PROTOCOL_PREFIX.CLAUDE:
|
case MODEL_PROTOCOL_PREFIX.CLAUDE:
|
||||||
return new ClaudeStrategy();
|
return new ClaudeStrategy();
|
||||||
case MODEL_PROTOCOL_PREFIX.CODEX:
|
case MODEL_PROTOCOL_PREFIX.CODEX:
|
||||||
// Codex 使用 OpenAI 策略(因为它基于 OpenAI 格式)
|
return new ResponsesAPIStrategy();
|
||||||
return new OpenAIStrategy();
|
|
||||||
case MODEL_PROTOCOL_PREFIX.FORWARD:
|
case MODEL_PROTOCOL_PREFIX.FORWARD:
|
||||||
return new ForwardStrategy();
|
return new ForwardStrategy();
|
||||||
default:
|
default:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue