You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(settings): CLIProxyAPI preset + smart model auto-discovery (#178)
## Summary
Add support for **CLIProxyAPI (CPA)** — `router-for-me/CLIProxyAPI`, a
popular Go local proxy (~27K stars, MIT) that wraps Claude Code / Codex
/ Gemini OAuth subscriptions into a unified API. Heavily requested by
the linux.do user base.
User flow: Settings → Add provider → pick "CLIProxyAPI" → baseUrl
pre-fills `http://127.0.0.1:8317` + `anthropic` wire → typing
baseUrl/key auto-triggers `/v1/models` discovery (500ms debounce) →
defaultModel becomes a dropdown auto-selecting best model
(claude-sonnet-4-5 > opus > sonnet > gemini-2.5-pro > gpt-5 > first) →
save & ready.
Incidentally closes the long-standing model selector gap for
custom/imported providers.
## Why this works with zero backend code
- CPA serves wildcard CORS — Electron talks to it directly
- pi-ai's anthropic-messages wire already speaks CPA's `/v1/messages`
endpoint
- `packages/providers/src/claude-code-compat.ts` already auto-injects
`claude-cli` identity headers for any non-`api.anthropic.com`
anthropic-wire baseUrl — CPA inherits this for free
- IPC `config:v1:test-endpoint` already calls `/v1/models` and returns
the discovered list
## Changes
- `packages/shared/src/proxy-presets.ts` — new `cli-proxy-api` preset
- `packages/i18n/src/locales/{en,zh-CN}.json` —
`settings.providers.cliProxyApi.*` keys
- `apps/desktop/src/renderer/src/components/Settings.tsx` — preset
quick-pick menu item
- `apps/desktop/src/renderer/src/components/AddCustomProviderModal.tsx`
— debounced auto-discovery + hybrid dropdown/text defaultModel + smart
auto-pick
- `.changeset/cpa-preset.md` + `.changeset/cpa-modal-autodiscover.md`
## Test plan
- [ ] `pnpm typecheck` — green
- [ ] `pnpm lint` — green
- [ ] Manual: install CPA locally, OAuth login Claude, pick CLIProxyAPI
preset → verify auto-discovery + dropdown + claude-sonnet-4-5 auto-pick
- [ ] Manual: type bad URL → verify graceful "Could not connect" +
manual entry fallback
## Note on history
These commits originally landed directly on `main` (per the v0.x
fast-merge convention), then were reverted specifically to open this PR
for Codex bot review. The PR merges back as a clean single commit that
re-introduces the feature.
---------
Signed-off-by: hqhq1025 <1506751656@qq.com>
feat(settings): auto-discover models in custom provider modal
7
+
8
+
When adding a custom provider (e.g. a CPA at http://127.0.0.1:8317), the modal now probes the endpoint automatically after the user types a valid http(s) baseUrl, debouncing 500ms. A spinner appears inline next to the "Default model" label while discovery runs, then either a green "Found N models" badge or a muted "Could not connect" hint.
9
+
10
+
On success the "Default model" input becomes a `<select>` pre-populated with discovered model IDs, with smart auto-selection prioritising claude-sonnet-4-5 → claude-opus → claude-sonnet → gemini-2.5-pro → gpt-5 → first in list. A "Enter manually" escape hatch lets users type any ID instead, and a "Pick from list" link restores the dropdown. The probe re-fires when the API key or wire protocol changes. Empty or non-http(s) baseUrls are skipped so the existing manual flow is completely unaffected.
Adds CLIProxyAPI (`router-for-me/CLIProxyAPI`) as a first-class preset in the Add Provider menu. CLIProxyAPI is a Go local proxy on port 8317 that wraps Claude/Codex/Gemini OAuth subscriptions into a unified Anthropic Messages API — heavily requested by the Chinese user base.
10
+
11
+
-`packages/shared`: new `cli-proxy-api` entry in `PROXY_PRESETS` (anthropic wire, `http://127.0.0.1:8317`)
12
+
-`packages/i18n`: `settings.providers.cliProxyApi.*` keys in both `en.json` and `zh-CN.json` (preset name, description, api-key-optional hint, thinking-budget hint, model discovery strings)
13
+
-`apps/desktop`: `AddProviderMenu` gains a CLIProxyAPI item that opens `AddCustomProviderModal` pre-filled with the CPA endpoint and anthropic wire; claude-cli identity headers are injected automatically by the existing `shouldForceClaudeCodeIdentity` path (no extra code needed)
0 commit comments