feat: 添加中国厂商支持 + MiMo provider + KimiK2 余额 API#838
feat: 添加中国厂商支持 + MiMo provider + KimiK2 余额 API#838Meteorkid wants to merge 1 commit intosteipete:mainfrom
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 226100b53e
ℹ️ 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".
| connection.receive(minimumIncompleteLength: 1, maximumLength: 65536) { [weak self] data, _, isComplete, error in | ||
| guard let self, let data, !data.isEmpty else { | ||
| if let error { Self.log.error("Receive error: \(error)") } | ||
| connection.cancel() | ||
| return | ||
| } | ||
|
|
||
| self.processRequest(data: data, connection: connection) |
There was a problem hiding this comment.
Read full HTTP request before parsing
handleConnection calls receive only once and immediately parses that single chunk as a complete HTTP request. On real TCP connections, headers and/or body can arrive fragmented across multiple packets, so this path will intermittently parse partial requests and return 400s or forward truncated payloads (especially for larger chat/completions bodies). The proxy needs to keep reading until headers are complete and the declared body length is satisfied.
Useful? React with 👍 / 👎.
| case "open.bigmodel.cn": return .zhipu | ||
| case "ark.cn-beijing.volces.com": return .doubao | ||
| case "qianfan.baidubce.com": return .ernie | ||
| case "api.moonshot.cn": return .kimi |
There was a problem hiding this comment.
Attribute Moonshot host traffic to Kimi K2
api.moonshot.cn is now used by the Kimi K2 integration, but provider identification maps it to .kimi. That causes proxy token usage from Kimi K2 requests to be recorded under the wrong provider, corrupting per-provider usage totals and mixing provider data in the UI/state.
Useful? React with 👍 / 👎.
| get: { self.settings.proxyEnabled }, | ||
| set: { newValue in | ||
| self.settings.proxyEnabled = newValue | ||
| if newValue { | ||
| self.proxyManager.start(port: self.settings.proxyPort) |
There was a problem hiding this comment.
Initialize proxy from persisted enabled state
The proxy is only started inside the toggle setter. When proxyEnabled is already true from saved defaults (e.g., app relaunch), this setter is never invoked, so the UI can show the feature enabled while no proxy is running until the user toggles it again. Add an initialization path (e.g., on appear/app startup) that starts the proxy when persisted state is enabled.
Useful? React with 👍 / 👎.
新增 Provider: - Zhipu(智谱)— Cookie 余额查询 + API key 验证 - Doubao(豆包)— Cookie 余额查询 + API key 验证 - ERNIE(文心)— Cookie 余额查询 + API key 验证 - MiMo(小米)— Cookie 余额查询 + API key 验证(api-key header) 新增功能: - KimiK2 余额 API(api.moonshot.cn/v1/users/me/balance) - 本地代理 Token 追踪(NWListener,支持所有中国厂商) - 中国厂商余额解析单元测试(25 个测试用例) 技术细节: - MiMo 使用 api-key header(非 Bearer)认证 - Cookie 导入使用 SweetCookieKit - 代理路由支持 api.xiaomimimo.com
Summary
新增中国厂商支持和 MiMo provider:
新增 Provider
新增功能
api.moonshot.cn/v1/users/me/balance)技术细节
api-keyheader(非 Bearer)认证api.xiaomimimo.comTest plan
swift build编译通过🤖 Generated with Claude Code