From e9b4567035f6631142cfb73110d4282adb921caf Mon Sep 17 00:00:00 2001 From: weiadou <125185953+weiadou@users.noreply.github.com> Date: Mon, 3 Aug 2026 09:39:40 +0800 Subject: [PATCH 1/3] fix Prompt Optimize ProseMirror writer --- index.json | 484 ++++++++++++++++++------------------- scripts/prompt-optimize.js | 152 ++++++++++-- 2 files changed, 380 insertions(+), 256 deletions(-) diff --git a/index.json b/index.json index 2694c08..63b168b 100644 --- a/index.json +++ b/index.json @@ -1,243 +1,243 @@ -{ - "version": 1, - "updated_at": "2026-07-16T08:27:07Z", - "scripts": [ - { - "id": "codex-context-used-meter", - "name": "Codex Context Used Meter", - "description": "在 Codex App 对话界面显示当前会话上下文余量,并支持可选 Provider 余额、消耗动画、悬停历史图、inline/floating 显示和主题切换。", - "version": "101", - "author": "Minghou-Lei", - "tags": [ - "context", - "tokens", - "ui", - "meter" - ], - "homepage": "https://github.com/Minghou-Lei/codex-context-used-meter", - "script_url": "https://raw.githubusercontent.com/BigPizzaV3/CodexPlusPlusScriptMarket/main/scripts/codex-context-used-meter.js", - "sha256": "d2a5efe42d88d9b706b8ca8799947d2bc31c1b608b30c2673ac36fa0050911ab" - }, - { - "id": "hide-usage-alert", - "name": "Hide Usage Alert", - "description": "隐藏额度提醒", - "version": "0.1.4", - "author": "0xTotoroX", - "tags": [ - "usage", - "quota", - "ui", - "hide" - ], - "homepage": "https://github.com/0xTotoroX/codex-hide-usage-alert", - "script_url": "https://raw.githubusercontent.com/BigPizzaV3/CodexPlusPlusScriptMarket/main/scripts/hide-usage-alert.js", - "sha256": "29fb7eb5b44cda3281ddcaed5174746c02b0a8b9de461c49774bb3746a3cda7b" - }, - { - "id": "model-deck", - "name": "Model Deck", - "description": "悬停官方模型按钮打开模型矩阵,提供 Fast 切换和全局预设", - "version": "0.1.0", - "author": "0xTotoroX", - "tags": [ - "codex", - "models", - "reasoning", - "fast", - "presets", - "ui" - ], - "homepage": "https://github.com/0xTotoroX/model-deck", - "script_url": "https://raw.githubusercontent.com/BigPizzaV3/CodexPlusPlusScriptMarket/main/scripts/model-deck.js", - "sha256": "6a085811d626bbe9ded8e73baf9fbaf719f30297e0ce58c35259a083a056ad2d" - }, - { - "id": "codex-token-usage", - "name": "Codex Token Usage", - "description": "显示token消耗统计", - "version": "0.1.7", - "author": "Albert_Luo", - "tags": [ - "codex", - "tokens", - "usage", - "metrics", - "cache" - ], - "homepage": "", - "script_url": "https://raw.githubusercontent.com/BigPizzaV3/CodexPlusPlusScriptMarket/main/scripts/codex-token-usage.js", - "sha256": "03808d22f53da374837227636ebd9f1ba593fe5aba6219e90e636d7ed7c806eb" - }, - { - "id": "codex-daily-token-usage", - "name": "Codex Daily Token Usage", - "description": "每日 Token 统计,近 5 日滚动存储,自动复用已有采集,支持 Model 价格、成本估算、趋势明细和分享图", - "version": "1.4.13", - "author": "kts-kris", - "tags": [ - "codex", - "tokens", - "usage", - "daily", - "share", - "ui" - ], - "homepage": "", - "script_url": "https://raw.githubusercontent.com/BigPizzaV3/CodexPlusPlusScriptMarket/main/scripts/codex-daily-token-usage.js", - "sha256": "80f5efb88d1e2e0da5c22f229b65d08710460a7c258bdaea7b82a84071fb7576" - }, - { - "id": "codex-list-pagebuster", - "name": "Codex List Pagebuster", - "description": "补强会话列表", - "version": "0.1.1", - "author": "puppnn", - "tags": [ - "codex", - "history", - "sidebar", - "sessions", - "ui" - ], - "homepage": "", - "script_url": "https://raw.githubusercontent.com/BigPizzaV3/CodexPlusPlusScriptMarket/main/scripts/codex-list-pagebuster.js", - "sha256": "756ee2e2a91df449738192ae500de1ab75cbbc7129968982ca37f6f5a9aad78e" - }, - { - "id": "codex-zhcn-translate", - "name": "Codex简体中文汉化", - "description": "全界面简体汉化补丁", - "version": "1.0", - "author": "hL091015", - "tags": [ - "translation", - "chinese", - "zh-CN", - "ui" - ], - "homepage": "", - "script_url": "https://raw.githubusercontent.com/hL091015/CodexPlusPlusScriptMarket/main/scripts/zh_CN%E6%B1%89%E5%8C%96.user.js", - "sha256": "72214D31D425D1CE936B457AA43FCC40DF55F4DE3B9B140F9510C7F392CDC845" - }, - { - "id": "tux-toolbar-buddy", - "name": "Tux Toolbar Buddy", - "description": "把菜单入口轻量化为Tux工具栏按钮,隐藏状态点和版本信息。", - "version": "0.1.1", - "author": "0xTotoroX", - "tags": [ - "menu", - "toolbar", - "icon", - "ui" - ], - "homepage": "https://github.com/0xTotoroX/tux-toolbar-buddy", - "script_url": "https://raw.githubusercontent.com/BigPizzaV3/CodexPlusPlusScriptMarket/main/scripts/tux-toolbar-buddy.js", - "sha256": "6570fba293c751958b6cf7077b51458e1b126cf99c9168c321729316a7f0262b" - }, - { - "id": "bennett-ui-improvements", - "name": "Bennett UI Improvements", - "description": "迁移自 b-nnett Bennett UI 的 renderer-only UI 增强", - "version": "1.0.9-bigpizza.1", - "author": "bennett; JHees", - "tags": [ - "codex", - "ui", - "sidebar", - "settings", - "polish" - ], - "homepage": "", - "script_url": "https://raw.githubusercontent.com/BigPizzaV3/CodexPlusPlusScriptMarket/main/scripts/bennett-ui-improvements.js", - "sha256": "2fb8c36ab5a7103d103deb53a55c5f42ab26763479bec253dccbb825c93e1af9" - }, - { - "id": "codex-provider-guard", - "name": "Codex Provider Guard", - "description": "只读检查供应商 ID、会话分桶和本地端口风险;修复必须在 Codex++ 原生管理器中确认执行。", +{ + "version": 1, + "updated_at": "2026-07-16T08:27:07Z", + "scripts": [ + { + "id": "codex-context-used-meter", + "name": "Codex Context Used Meter", + "description": "在 Codex App 对话界面显示当前会话上下文余量,并支持可选 Provider 余额、消耗动画、悬停历史图、inline/floating 显示和主题切换。", + "version": "101", + "author": "Minghou-Lei", + "tags": [ + "context", + "tokens", + "ui", + "meter" + ], + "homepage": "https://github.com/Minghou-Lei/codex-context-used-meter", + "script_url": "https://raw.githubusercontent.com/BigPizzaV3/CodexPlusPlusScriptMarket/main/scripts/codex-context-used-meter.js", + "sha256": "d2a5efe42d88d9b706b8ca8799947d2bc31c1b608b30c2673ac36fa0050911ab" + }, + { + "id": "hide-usage-alert", + "name": "Hide Usage Alert", + "description": "隐藏额度提醒", + "version": "0.1.4", + "author": "0xTotoroX", + "tags": [ + "usage", + "quota", + "ui", + "hide" + ], + "homepage": "https://github.com/0xTotoroX/codex-hide-usage-alert", + "script_url": "https://raw.githubusercontent.com/BigPizzaV3/CodexPlusPlusScriptMarket/main/scripts/hide-usage-alert.js", + "sha256": "29fb7eb5b44cda3281ddcaed5174746c02b0a8b9de461c49774bb3746a3cda7b" + }, + { + "id": "model-deck", + "name": "Model Deck", + "description": "悬停官方模型按钮打开模型矩阵,提供 Fast 切换和全局预设", + "version": "0.1.0", + "author": "0xTotoroX", + "tags": [ + "codex", + "models", + "reasoning", + "fast", + "presets", + "ui" + ], + "homepage": "https://github.com/0xTotoroX/model-deck", + "script_url": "https://raw.githubusercontent.com/BigPizzaV3/CodexPlusPlusScriptMarket/main/scripts/model-deck.js", + "sha256": "6a085811d626bbe9ded8e73baf9fbaf719f30297e0ce58c35259a083a056ad2d" + }, + { + "id": "codex-token-usage", + "name": "Codex Token Usage", + "description": "显示token消耗统计", + "version": "0.1.7", + "author": "Albert_Luo", + "tags": [ + "codex", + "tokens", + "usage", + "metrics", + "cache" + ], + "homepage": "", + "script_url": "https://raw.githubusercontent.com/BigPizzaV3/CodexPlusPlusScriptMarket/main/scripts/codex-token-usage.js", + "sha256": "03808d22f53da374837227636ebd9f1ba593fe5aba6219e90e636d7ed7c806eb" + }, + { + "id": "codex-daily-token-usage", + "name": "Codex Daily Token Usage", + "description": "每日 Token 统计,近 5 日滚动存储,自动复用已有采集,支持 Model 价格、成本估算、趋势明细和分享图", + "version": "1.4.13", + "author": "kts-kris", + "tags": [ + "codex", + "tokens", + "usage", + "daily", + "share", + "ui" + ], + "homepage": "", + "script_url": "https://raw.githubusercontent.com/BigPizzaV3/CodexPlusPlusScriptMarket/main/scripts/codex-daily-token-usage.js", + "sha256": "80f5efb88d1e2e0da5c22f229b65d08710460a7c258bdaea7b82a84071fb7576" + }, + { + "id": "codex-list-pagebuster", + "name": "Codex List Pagebuster", + "description": "补强会话列表", + "version": "0.1.1", + "author": "puppnn", + "tags": [ + "codex", + "history", + "sidebar", + "sessions", + "ui" + ], + "homepage": "", + "script_url": "https://raw.githubusercontent.com/BigPizzaV3/CodexPlusPlusScriptMarket/main/scripts/codex-list-pagebuster.js", + "sha256": "756ee2e2a91df449738192ae500de1ab75cbbc7129968982ca37f6f5a9aad78e" + }, + { + "id": "codex-zhcn-translate", + "name": "Codex简体中文汉化", + "description": "全界面简体汉化补丁", + "version": "1.0", + "author": "hL091015", + "tags": [ + "translation", + "chinese", + "zh-CN", + "ui" + ], + "homepage": "", + "script_url": "https://raw.githubusercontent.com/hL091015/CodexPlusPlusScriptMarket/main/scripts/zh_CN%E6%B1%89%E5%8C%96.user.js", + "sha256": "72214D31D425D1CE936B457AA43FCC40DF55F4DE3B9B140F9510C7F392CDC845" + }, + { + "id": "tux-toolbar-buddy", + "name": "Tux Toolbar Buddy", + "description": "把菜单入口轻量化为Tux工具栏按钮,隐藏状态点和版本信息。", + "version": "0.1.1", + "author": "0xTotoroX", + "tags": [ + "menu", + "toolbar", + "icon", + "ui" + ], + "homepage": "https://github.com/0xTotoroX/tux-toolbar-buddy", + "script_url": "https://raw.githubusercontent.com/BigPizzaV3/CodexPlusPlusScriptMarket/main/scripts/tux-toolbar-buddy.js", + "sha256": "6570fba293c751958b6cf7077b51458e1b126cf99c9168c321729316a7f0262b" + }, + { + "id": "bennett-ui-improvements", + "name": "Bennett UI Improvements", + "description": "迁移自 b-nnett Bennett UI 的 renderer-only UI 增强", + "version": "1.0.9-bigpizza.1", + "author": "bennett; JHees", + "tags": [ + "codex", + "ui", + "sidebar", + "settings", + "polish" + ], + "homepage": "", + "script_url": "https://raw.githubusercontent.com/BigPizzaV3/CodexPlusPlusScriptMarket/main/scripts/bennett-ui-improvements.js", + "sha256": "2fb8c36ab5a7103d103deb53a55c5f42ab26763479bec253dccbb825c93e1af9" + }, + { + "id": "codex-provider-guard", + "name": "Codex Provider Guard", + "description": "只读检查供应商 ID、会话分桶和本地端口风险;修复必须在 Codex++ 原生管理器中确认执行。", + "version": "1.0.2", + "author": "k9ight000", + "tags": [ + "codex", + "provider", + "sessions", + "safety", + "cpa" + ], + "homepage": "https://github.com/BigPizzaV3/CodexPlusPlus", + "script_url": "https://raw.githubusercontent.com/BigPizzaV3/CodexPlusPlusScriptMarket/main/scripts/codex-provider-guard.js", + "sha256": "a047592791a2836fd1d665c7b0a8ca8f64a8924ee4b2a08f09e3c52b12dec5b1" + }, + { + "id": "codex-bundled-plugin-doctor", + "name": "Codex Bundled Plugin Doctor", + "description": "诊断并修复 Codex Desktop 的 bundled 插件异常,如 Chrome / Computer Use 消失、marketplace.json 缺失、设置页 unavailable。", + "version": "0.1.0", + "author": "BigPizzaV3", + "tags": [ + "codex", + "plugins", + "repair", + "windows", + "diagnostic", + "doctor" + ], + "homepage": "https://github.com/BigPizzaV3/CodexPlusPlusScriptMarket", + "script_url": "https://raw.githubusercontent.com/BigPizzaV3/CodexPlusPlusScriptMarket/main/scripts/codex-bundled-plugin-doctor.js", + "sha256": "4c2eac259c62d007ec84ed925886ac79a2f5c520acb67c42f419e707934563ff" + }, + { + "id": "codex-live-token-cost", + "name": "Codex Live Token Cost", + "description": "在输入框上方显示 token 和费用,解锁本地 Profile 统计,可选 helper 同步 CC Switch。", + "version": "0.7.2", + "author": "Tianzora", + "tags": [ + "codex", + "tokens", + "cost", + "usage" + ], + "homepage": "https://github.com/Tianzora/codex-token-cost", + "script_url": "https://raw.githubusercontent.com/BigPizzaV3/CodexPlusPlusScriptMarket/main/scripts/codex-live-token-cost.js", + "sha256": "AEE6BF61236AA9EDF183A71BBA5A45CBB1F273F94E2197D4421D557999DE5DA8" + }, + { + "id": "prompt-optimize", + "name": "Prompt Optimize", + "description": "在输入框旁调用外部 LLM 一键优化提示词,支持 OpenAI/Anthropic 兼容 API 与一键还原。", "version": "1.0.2", - "author": "k9ight000", - "tags": [ - "codex", - "provider", - "sessions", - "safety", - "cpa" - ], - "homepage": "https://github.com/BigPizzaV3/CodexPlusPlus", - "script_url": "https://raw.githubusercontent.com/BigPizzaV3/CodexPlusPlusScriptMarket/main/scripts/codex-provider-guard.js", - "sha256": "a047592791a2836fd1d665c7b0a8ca8f64a8924ee4b2a08f09e3c52b12dec5b1" - }, - { - "id": "codex-bundled-plugin-doctor", - "name": "Codex Bundled Plugin Doctor", - "description": "诊断并修复 Codex Desktop 的 bundled 插件异常,如 Chrome / Computer Use 消失、marketplace.json 缺失、设置页 unavailable。", - "version": "0.1.0", - "author": "BigPizzaV3", - "tags": [ - "codex", - "plugins", - "repair", - "windows", - "diagnostic", - "doctor" - ], - "homepage": "https://github.com/BigPizzaV3/CodexPlusPlusScriptMarket", - "script_url": "https://raw.githubusercontent.com/BigPizzaV3/CodexPlusPlusScriptMarket/main/scripts/codex-bundled-plugin-doctor.js", - "sha256": "4c2eac259c62d007ec84ed925886ac79a2f5c520acb67c42f419e707934563ff" - }, - { - "id": "codex-live-token-cost", - "name": "Codex Live Token Cost", - "description": "在输入框上方显示 token 和费用,解锁本地 Profile 统计,可选 helper 同步 CC Switch。", - "version": "0.7.2", - "author": "Tianzora", - "tags": [ - "codex", - "tokens", - "cost", - "usage" - ], - "homepage": "https://github.com/Tianzora/codex-token-cost", - "script_url": "https://raw.githubusercontent.com/BigPizzaV3/CodexPlusPlusScriptMarket/main/scripts/codex-live-token-cost.js", - "sha256": "AEE6BF61236AA9EDF183A71BBA5A45CBB1F273F94E2197D4421D557999DE5DA8" - }, - { - "id": "prompt-optimize", - "name": "Prompt Optimize", - "description": "在输入框旁调用外部 LLM 一键优化提示词,支持 OpenAI/Anthropic 兼容 API 与一键还原。", - "version": "1.0.0", - "author": "Codex++ Community", - "tags": [ - "prompt", - "ui", - "productivity", - "optimize", - "llm", - "openai", - "anthropic" - ], - "homepage": "https://github.com/BigPizzaV3/CodexPlusPlusScriptMarket", - "script_url": "https://raw.githubusercontent.com/BigPizzaV3/CodexPlusPlusScriptMarket/main/scripts/prompt-optimize.js", - "sha256": "1993a9d5e3717b0d62edd9d1d9933ef2a1d0bd04cc122781032b8c7fc57a49b7" - }, - { - "id": "codex-native-matrix-selector", - "name": "Codex Native Matrix Selector", - "description": "A theme-aware model and reasoning matrix backed by Codex's native selector data and handlers.", - "version": "0.8.0", - "author": "Codex", - "tags": [ - "codex", - "models", - "reasoning", - "ui" - ], - "homepage": "", - "script_url": "https://raw.githubusercontent.com/BigPizzaV3/CodexPlusPlusScriptMarket/main/scripts/Codex%20Model%20Matrix.js", - "sha256": "0a25838a887699f8c8b72efc67f64d9df045697f6e1555b856fb10a9baa8f075" - } - ] -} + "author": "Codex++ Community", + "tags": [ + "prompt", + "ui", + "productivity", + "optimize", + "llm", + "openai", + "anthropic" + ], + "homepage": "https://github.com/BigPizzaV3/CodexPlusPlusScriptMarket", + "script_url": "https://raw.githubusercontent.com/BigPizzaV3/CodexPlusPlusScriptMarket/main/scripts/prompt-optimize.js", + "sha256": "f86b0a4a83e594f25cc9d624343fa3696a23ce409b32245b21eedc70568b1032" + }, + { + "id": "codex-native-matrix-selector", + "name": "Codex Native Matrix Selector", + "description": "A theme-aware model and reasoning matrix backed by Codex's native selector data and handlers.", + "version": "0.8.0", + "author": "Codex", + "tags": [ + "codex", + "models", + "reasoning", + "ui" + ], + "homepage": "", + "script_url": "https://raw.githubusercontent.com/BigPizzaV3/CodexPlusPlusScriptMarket/main/scripts/Codex%20Model%20Matrix.js", + "sha256": "0a25838a887699f8c8b72efc67f64d9df045697f6e1555b856fb10a9baa8f075" + } + ] +} diff --git a/scripts/prompt-optimize.js b/scripts/prompt-optimize.js index ecab7a2..35603da 100644 --- a/scripts/prompt-optimize.js +++ b/scripts/prompt-optimize.js @@ -2,12 +2,12 @@ @codex-plus-script name: Prompt Optimize description: Optimize the composer prompt with an external LLM; click ✨ to optimize, click again to restore. -version: 1.0.0 +version: 1.0.2 author: Codex++ Community */ (() => { - const SCRIPT_VERSION = "1.0.0"; + const SCRIPT_VERSION = "1.0.2"; const API_KEY = "__codexPlusPromptOptimize"; const MARKET_ID = "prompt-optimize"; const BRIDGE_KEY = "__codexSessionDeleteBridge"; @@ -100,6 +100,7 @@ author: Codex++ Community disposed: false, loading: false, abort: null, + bridgePathUnsupported: false, lastWrittenText: null, writeToken: 0, }; @@ -1158,7 +1159,12 @@ author: Codex++ Community } let replaced = false; try { - replaced = document.execCommand?.("selectAll", false, null) && document.execCommand?.("insertText", false, next); + // Codex's ProseMirror editor can report selectAll=false even after the + // range above is selected. Always try insertText independently. + if (typeof document.execCommand === "function") { + document.execCommand("selectAll", false, null); + replaced = document.execCommand("insertText", false, next) !== false; + } } catch (_) { replaced = false; } @@ -1198,7 +1204,7 @@ author: Codex++ Community } try { await navigator.clipboard.writeText(normalizeText(text)); - showToast("无法直接写入输入框,已复制优化结果,请粘贴替换", "warn"); + showToast("优化结果已复制,输入框未改动;请按 Ctrl+V 粘贴替换", "warn"); return { ok: false, reason: result.reason || "write-failed", clipboard: true }; } catch (_) { showToast("写入输入框失败,且无法复制到剪贴板", "error"); @@ -1690,9 +1696,27 @@ author: Codex++ Community return typeof window[BRIDGE_KEY] === "function"; } + function hasElectronFetchBridge() { + return typeof window.electronBridge?.sendMessageFromView === "function"; + } + + function hasRequestTransport() { + return hasCodexPlusBridge() || hasElectronFetchBridge(); + } + + function bridgeUnsupportedError() { + const error = new Error("当前 Codex++ 的 LLM Bridge 路由不可用"); + error.code = "CPO_BRIDGE_UNSUPPORTED"; + return error; + } + + function isBridgeUnsupportedError(error) { + return error?.code === "CPO_BRIDGE_UNSUPPORTED"; + } + async function bridgeJson(payload, signal) { if (!hasCodexPlusBridge()) { - throw new Error("当前 Codex++ 版本不支持 LLM Bridge,请升级 Codex++"); + throw bridgeUnsupportedError(); } const call = Promise.resolve().then(() => window[BRIDGE_KEY](BRIDGE_PATH, payload || {})); if (!signal) return call; @@ -1721,7 +1745,84 @@ author: Codex++ Community }); } - async function requestJson({ upstreamUrl, method, headers, body, signal }) { + function responseErrorMessage(raw, fallback) { + const text = typeof raw === "string" ? raw : ""; + if (text.trim()) { + try { + const data = JSON.parse(text); + return collapseWs(data?.error?.message || data?.message || data?.error || text).slice(0, 240); + } catch (_) { + return collapseWs(text).slice(0, 240); + } + } + return fallback; + } + + function electronFetchJson({ upstreamUrl, method, headers, body, signal }) { + if (!hasElectronFetchBridge()) { + throw new Error("当前 Codex++ 不提供可用的 LLM 请求通道"); + } + const upstream = normalizeBaseUrl(upstreamUrl); + const requestId = `prompt-optimize-${Date.now()}-${Math.random().toString(36).slice(2)}`; + return new Promise((resolve, reject) => { + let settled = false; + const cleanup = () => { + window.clearTimeout(timer); + window.removeEventListener("message", onMessage); + signal?.removeEventListener?.("abort", onAbort); + }; + const finish = (callback, value) => { + if (settled) return; + settled = true; + cleanup(); + callback(value); + }; + const onAbort = () => { + const error = new Error("aborted"); + error.name = "AbortError"; + finish(reject, error); + }; + const onMessage = (event) => { + const result = event?.data; + if (result?.type !== "fetch-response" || String(result.requestId || "") !== requestId) return; + const httpStatus = Number(result.status || 0); + const rawBody = typeof result.bodyJsonString === "string" ? result.bodyJsonString : ""; + if (result.responseType === "error" || !(httpStatus >= 200 && httpStatus < 300)) { + const message = responseErrorMessage(result.error || rawBody, `HTTP ${httpStatus || "error"}`); + finish(reject, new Error(message)); + return; + } + try { + finish(resolve, rawBody.trim() ? JSON.parse(rawBody) : {}); + } catch (_) { + finish(reject, new Error("模型返回了无法解析的 JSON")); + } + }; + const timer = window.setTimeout(() => { + finish(reject, new Error("LLM 请求超时")); + }, REQUEST_TIMEOUT_MS); + window.addEventListener("message", onMessage); + if (signal?.aborted) { + onAbort(); + return; + } + signal?.addEventListener?.("abort", onAbort, { once: true }); + try { + window.electronBridge.sendMessageFromView({ + type: "fetch", + requestId, + url: upstream, + method: method || "POST", + headers: headers || {}, + body: body == null ? null : typeof body === "string" ? body : JSON.stringify(body), + }); + } catch (error) { + finish(reject, error); + } + }); + } + + async function requestJsonViaCodexBridge({ upstreamUrl, method, headers, body, signal }) { const upstream = normalizeBaseUrl(upstreamUrl); debugLog("bridge request", { upstream, method: method || "POST" }); const result = await bridgeJson( @@ -1737,7 +1838,7 @@ author: Codex++ Community if (!result || result.status !== "ok") { const message = collapseWs(result?.message || result?.error || "LLM Bridge 请求失败"); if (/unknown bridge path|未知.*bridge/i.test(message)) { - throw new Error("当前 Codex++ 版本不支持 LLM Bridge,请升级 Codex++"); + throw bridgeUnsupportedError(); } throw new Error(message || "LLM Bridge 请求失败"); } @@ -1757,6 +1858,20 @@ author: Codex++ Community return data; } + async function requestJson(options) { + if (hasCodexPlusBridge() && !runtime.bridgePathUnsupported) { + try { + const data = await requestJsonViaCodexBridge(options); + return data; + } catch (error) { + if (!isBridgeUnsupportedError(error)) throw error; + runtime.bridgePathUnsupported = true; + debugLog("/llm-proxy unavailable; falling back to Electron fetch bridge"); + } + } + return electronFetchJson(options); + } + async function callOpenAI({ baseUrl, apiKey, model, system, user, signal }) { const upstream = joinUrl(baseUrl, "/chat/completions"); const data = await requestJson({ @@ -1867,8 +1982,8 @@ author: Codex++ Community } async function runOptimize() { - if (!hasCodexPlusBridge()) { - showToast("当前 Codex++ 版本不支持 LLM Bridge,请升级 Codex++", "error"); + if (!hasRequestTransport()) { + showToast("当前 Codex++ 不提供可用的 LLM 请求通道", "error"); return; } const settings = loadSettings(); @@ -1926,7 +2041,7 @@ author: Codex++ Community } } catch (error) { if (userCancelled) { - showToast("已取消优化", "info"); + showToast("已取消本次优化,原输入未改动", "info"); } else if (timeout.didTimeout() || error?.name === "AbortError") { showToast("优化超时", "error"); } else { @@ -2000,7 +2115,7 @@ author: Codex++ Community overlay.innerHTML = `