Skip to content

feat: 添加中国厂商支持 + MiMo provider + KimiK2 余额 API#838

Open
Meteorkid wants to merge 1 commit intosteipete:mainfrom
Meteorkid:main
Open

feat: 添加中国厂商支持 + MiMo provider + KimiK2 余额 API#838
Meteorkid wants to merge 1 commit intosteipete:mainfrom
Meteorkid:main

Conversation

@Meteorkid
Copy link
Copy Markdown

Summary

新增中国厂商支持和 MiMo provider:

新增 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
  • 所有中国厂商支持 Cookie 和 API 双策略

Test plan

  • swift build 编译通过
  • 128 个测试全部通过(40 个测试套件)
  • 设置环境变量验证各 provider 连接
  • 验证 Cookie 余额查询功能
  • 验证代理 Token 追踪功能

🤖 Generated with Claude Code

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +61 to +68
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)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

Comment on lines +112 to +116
get: { self.settings.proxyEnabled },
set: { newValue in
self.settings.proxyEnabled = newValue
if newValue {
self.proxyManager.start(port: self.settings.proxyPort)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant