From 8fb4d59b23eccbddb941f5e96a1210f3691405ec Mon Sep 17 00:00:00 2001 From: hex2077 Date: Sun, 8 Mar 2026 22:23:43 +0800 Subject: [PATCH] =?UTF-8?q?fix(openai):=20=E4=BF=AE=E5=A4=8D=20prepareRequ?= =?UTF-8?q?estBody=20=E5=BC=82=E6=AD=A5=E8=B0=83=E7=94=A8=E9=97=AE?= =?UTF-8?q?=E9=A2=98=E5=B9=B6=E6=B7=BB=E5=8A=A0=E7=9B=91=E6=8E=A7=E9=92=A9?= =?UTF-8?q?=E5=AD=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 将 prepareRequestBody 方法改为异步以支持插件钩子调用,修复因缺少 await 导致的潜在问题。同时添加内部请求转换监控钩子,便于跟踪请求处理流程。 --- VERSION | 2 +- src/providers/openai/codex-core.js | 23 ++++++++++++++++++++--- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/VERSION b/VERSION index 4485360..cbb57fa 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.10.9.1 +2.10.9.2 diff --git a/src/providers/openai/codex-core.js b/src/providers/openai/codex-core.js index 7d873f3..8997622 100644 --- a/src/providers/openai/codex-core.js +++ b/src/providers/openai/codex-core.js @@ -172,7 +172,7 @@ export class CodexApiService { } const url = `${this.baseUrl}/responses`; - const body = this.prepareRequestBody(selectedModel, requestBody, true); + const body = await this.prepareRequestBody(selectedModel, requestBody, true); const headers = this.buildHeaders(body.prompt_cache_key, true); try { @@ -253,7 +253,7 @@ export class CodexApiService { } const url = `${this.baseUrl}/responses`; - const body = this.prepareRequestBody(selectedModel, requestBody, true); + const body = await this.prepareRequestBody(selectedModel, requestBody, true); const headers = this.buildHeaders(body.prompt_cache_key, true); try { @@ -334,7 +334,7 @@ export class CodexApiService { /** * 准备请求体 */ - prepareRequestBody(model, requestBody, stream) { + async prepareRequestBody(model, requestBody, stream) { // 提取 metadata 并从请求体中移除,避免透传到上游 const metadata = requestBody.metadata || {}; @@ -393,6 +393,23 @@ export class CodexApiService { delete result.service_tier; } + // 监控钩子:内部请求转换 + if (this.config?._monitorRequestId) { + try { + const { getPluginManager } = await import('../../core/plugin-manager.js'); + const pluginManager = getPluginManager(); + if (pluginManager) { + await pluginManager.executeHook('onInternalRequestConverted', { + requestId: this.config._monitorRequestId, + internalRequest: result, + converterName: 'prepareRequestBody' + }); + } + } catch (e) { + logger.error('[Codex] Error calling onInternalRequestConverted hook:', e.message); + } + } + return result; }