Feat/chatgpt web reverse channel - #5257
Conversation
Add a new RequestLog table to store complete request and response bodies for API relay calls. Includes a settings toggle, backend API endpoints, response capture middleware, and a frontend modal for previewing logged content with JSON formatting. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
When LOG_SQL_DSN is not set, LOG_DB = DB but migrateLOGDB() was never called, so the request_logs table was never created, causing "table doesn't exist" errors. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Two issues fixed: 1. MySQL TEXT type is 64KB max, too small for large request bodies. Changed to MEDIUMTEXT (16MB) with explicit ALTER TABLE migration. 2. Response body was never captured because middleware set the context key after c.Next() returned, but handler's defer runs before that. Now store the writer reference in context so handler can read it directly during defer. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Increase request/response body capture and truncation limit from 64KB to 4MB to avoid truncation of large payloads - Replace plain text JSON display with interactive collapsible tree view with syntax highlighting and expand/collapse toggles Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
新增渠道类型 ChannelTypeChatGPTWeb(58)/APITypeChatGPTWeb,用 ChatGPT 订阅账号的
OAuth access_token 模拟网页前端调用 chatgpt.com/backend-api/conversation,下游同时
兼容 OpenAI /v1/chat/completions 与 /v1/responses(均支持流式与非流式)。
实现要点(relay/channel/chatgpt_web/):
- web_key.go:Key 支持直接粘原始 access_token,account_id 自动从 JWT 提取、
device_id 由 account_id 确定性派生;也支持 JSON 形式覆盖
- pow.go:sentinel chat-requirements + Proof-of-Work(SHA3-512)
- convert.go:OpenAI messages -> conversation 体;解析 ChatGPT v1 delta SSE
(新消息为裸 {"v":{message}} 快照、正文走 patch/append 到 parts/0)转 chat 格式
- responses.go:/v1/responses 输入解析与 responses 事件合成
- adaptor.go:SetupRequestHeader 内完成 sentinel+PoW,DoRequest 复用
channel.DoApiRequest,DoResponse 按 RelayMode 分流
集成:constant/channel.go、constant/api_type.go、common/api_type.go、
relay/relay_adaptor.go、web/src/constants/channel.constants.js。
已对真实 chatgpt.com 端到端实测通过:chat="21"、responses="4"。
已知约束:token 不可刷新(账号风控),约 10 天过期需手动从浏览器重抠更新;
Turnstile 当前为建议未强制,若上游转为强制则 conversation 直接报错(不加降级)。
仅支持文本输入;usage 为本地估算(上游不返回 token 数)。
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (30)
WalkthroughThis PR adds ChatGPT Web as a new relay channel (type 58) with full SSE-based request/response conversion, and introduces a comprehensive request/response logging system that captures full API payloads into a database with REST APIs and a frontend JSON viewer for inspection. ChangesChatGPT Web Channel + Request Logging System
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
✨ Finishing Touches🧪 Generate unit tests (beta)
⚔️ Resolve merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Important
📝 变更描述 / Description
(简述:做了什么?为什么这样改能生效?请基于你对代码逻辑的理解来写,避免粘贴未经整理的内容)
🚀 变更类型 / Type of change
🔗 关联任务 / Related Issue
✅ 提交前检查项 / Checklist
Bug fix,我已提交或关联对应 Issue,且不会将设计取舍、预期不一致或理解偏差直接归类为 bug。📸 运行证明 / Proof of Work
(请在此粘贴截图、关键日志或测试报告,以证明变更生效)
Summary by CodeRabbit
New Features