fix(stage-ui): proxy openai-compatible requests in electron#2011
fix(stage-ui): proxy openai-compatible requests in electron#2011jim139129 wants to merge 7 commits into
Conversation
⏳ Approval required for deploying to Cloudflare Workers (Preview) for stage-web.
Hey, maintainers, kindly take some time to review and approve this deployment when you are available. Thank you! 🙏 |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: eb0931243d
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
eb09312 to
6bad1ca
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6bad1ca392
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
6bad1ca to
cfd0ac6
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: cfd0ac6972
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: bcb4331e5b
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 044e06e10a
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
044e06e to
8b475ab
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3259b7beba
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 82f6e4f3b0
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
typed-sigterm
left a comment
There was a problem hiding this comment.
It makes sense but I'm not sure if it's the best way to implement it...
Description
这个PR试图解决部分中转站不兼容的问题,已经本地测试两个基于sub2api的中转站均可用
修改思路:
在 shared 层定义一个 Eventa invoke 合同,用于 OpenAI-compatible HTTP 请求转发:
packages/stage-shared/src/openai-compatible.ts:17
在 Electron main process 注册 fetch bridge,由 main process 发真实 HTTP(S) 请求,绕过 renderer 的 CORS 限制:
apps/stage-tamagotchi/src/main/services/airi/openai-compatible-fetch.ts:6
注册点在:
apps/stage-tamagotchi/src/main/index.ts:263
在 renderer/provider 层新增 resolveOpenAICompatibleFetch():
packages/stage-ui/src/libs/providers/openaiCompatibleFetch.ts:75
它的策略是:先用原生 globalThis.fetch,这样 CORS 正常的 provider 仍然保留原行为和流式能力;只有遇到 TypeError 这类
浏览器网络失败时,才 fallback 到 Electron main fetch。AbortError 不会 fallback,避免用户取消请求后又被重新发起。
把这个 fetch 注入到所有 OpenAI-compatible 相关路径:
provider 创建:
packages/stage-ui/src/libs/providers/providers/openai-compatible/index.ts:44
模型列表和聊天校验 validator:
packages/stage-ui/src/libs/providers/validators/openai-compatible.ts:82
packages/stage-ui/src/libs/providers/validators/openai-compatible.ts:143
packages/stage-ui/src/libs/providers/validators/openai-compatible.ts:259
LLM store 里的模型获取:
packages/stage-ui/src/stores/llm.ts:111
provider metadata/converter 的模型获取:
packages/stage-ui/src/stores/providers/converters.ts:147
provider 创建处没有继续用 createOpenAI(...),而是显式组合 createChatProvider 和 createModelProvider,这样可以注入自
定义 fetch,并且分别传入独立 options,避免 chat provider 对 options 的内部改写影响 model provider:
packages/stage-ui/src/libs/providers/providers/openai-compatible/index.ts:45
整体效果是:Web 和非 Electron 环境不受影响;Electron 下 CORS 正常的接口保持原路径;只有 renderer 网络失败的 OpenAI-
compatible 请求才走 main process 代理,从而修复 sub2api 类网关的模型列表和对话不可用问题。
Linked Issues
#2010
Additional Context