Commit Graph
4 Commits
Author SHA1 Message Date
yetone 066ece93bb provider: LongCat is a vendor preset, Meituan's LongCat API platform with chat completions, Responses and Anthropic messages (hoobnn on Discord)
LongCat makes its own models (LongCat-2.5, launched 11-02) and serves them
at api.longcat.chat. magpie had LongCat's icon but no preset for it.

The new preset is longcat ("LongCat", KindVendor, icon longcat, catalog
models.dev's longcat). It uses:
- chat completions and Responses at https://api.longcat.chat/openai/v1;
- Anthropic messages at https://api.longcat.chat/anthropic;
- docs at longcat.chat/platform/docs/zh/api-docs, keys at
  longcat.chat/platform/api_keys.
The key goes as a Bearer. magpie sends both headers, and the docs ask for
Bearer on both endpoints; x-api-key alone gets "missing_api_key". The model
list is /openai/v1/models. longcat.chat's and longcat.ai's accounts use the
same API host (both sites' api-docs pages name api.longcat.chat).

An entry at those endpoints imports as the preset, for example CC Switch's
Claude Code and Codex entries from LongCat's cc-switch page. OpenCode's
auth.json "longcat" (models.dev's id) maps to the preset too. The README
(en, zh), docs/reference.md and the site's import pages (en, zh, ja, and
import.html, with the icon) list it.

Sources, read 11-02: api-docs, api/models, api/model, api/model-params,
api/chat, api/messages, image-video-understanding, cc-switch, pricing/
longcat-2.5, change-log, faq.

Probed without a key, from this machine: /openai/v1/models and
/anthropic/v1/models answer 401 authentication_error "missing_api_key".
/openai/v1/chat/completions, /openai/v1/responses and
/anthropic/v1/messages with a bad Bearer answer 401 "incorrect api key".

Run at this head (base d24be3c25, origin/main at push), on mote:
- TestLongCatPreset and TestLongCatList (the docs' literal /models
  example) pass. TestLongCatPreset goes red with the OpenCode mapping taken
  out ("OpenCode import: … Skip:it has no base URL").
- gofmt -l and GOOS=linux / GOOS=windows go vet ./internal/provider are
  clean.
- go test -tags nogui -timeout 45m ./... is ok except three tests that
  have issues already:
  - TestEveryRouteHasACommandOrIsNamed (#4826) is red on a clean
    d24be3c25 too.
  - TestKeepOffWaitsForTheSetting (#3687) is red on a clean d24be3c25 too.
  - TestCodexPoolSaysTheClientsVersion (#4807) is red in the full package
    run and passes 3 of 3 alone on d24be3c25.
- GUI add-sheet and add-button pass in Chromium and WebKit (12/12). No GUI
  file changed: the add sheet draws presets from /api.

Not tried:
- a real LongCat key or a real request (none available).
- LongCat-2.5's window (1M), output cap (256K) and image input. These come
  from models.dev, which so far lists only LongCat-2.0 and
  LongCat-2.5-Preview, and LongCat's /models gives no facts. Until
  models.dev adds LongCat-2.5, magpie doesn't know them for it.
- LongCat's thinking switch ({"type":"enabled"|"disabled"}).
2026-11-02 13:44:11 +08:00
ggbdpq eaa71168a2 import: OpenCode's ids for vendors magpie has a preset at the same address come in on it (#2405)
openCodePresets held 19 of OpenCode's provider ids. 15 more are at the
address of a magpie preset, and the import picker listed each as
skipped, "it has no base URL", which isn't so: zhipuai, zai, alibaba,
alibaba-cn, minimax, modelscope, kilo, cline-pass, kimi-code-plan-cn,
kimi-code-plan-global, stepfun-step-plan, stepfun-ai-step-plan,
volcengine-coding-plan, alibaba-token-plan-cn and tencent-token-plan.
Each now comes in on its preset, the way openai's key does.

Left out, where auth.json says nothing to pick a region by: the coding
plan ids of Zhipu, Z.ai, MiniMax and Tencent, the pay-as-you-go ids of
plan-first presets (stepfun, stepfun-ai, volcengine), and the Xiaomi
MiMo token plans, served by a plugin now.

Patch by ggbdpq (Discord gua2100), as posted in #2405. Review: each of
the 15 targets' default endpoints was printed from Preset() at this
tree and matches the host models.dev gives the id (zhipu and zai
default to the pay-as-you-go paas/v4, volcengine to api/coding/v3,
stepfun and stepfun-cn to step_plan, tencent-cloud to plan/v3), so no
key is sent to a host OpenCode wouldn't send it to. No preset added.

Run (sandbox HOME, at origin/main f8cd964ae plus this; the touched tests again on mote after the rebase):
- go test -tags nogui -run OpenCode ./internal/provider/: ok
- Broken by hand: import_opencode.go put back to origin/main, test
  kept: TestImportOpenCodeVendorPresets FAIL, 15 lines "skipped: it has
  no base URL". Restored: ok.
- go test -tags nogui ./internal/provider/ with the known main reds
  skipped (#3632 TestUnreadLoginsWriteErrorsKeepCredentials, #3854
  TestFetchAsksASharedBaseOnce and two siblings): ok.
- gofmt -l internal/provider: clean. go vet ./internal/provider/ on
  darwin, GOOS=windows, GOOS=linux: ok.
Not tried: a real OpenCode auth.json with these vendors' keys, a
request on each imported provider, the GUI import picker; go test
./... (one suite per machine).
2026-10-28 03:10:46 +08:00
yetoneandggbdpq 7ea0e047bc import: a Gemini-protocol relay's key comes in on the provider's Gemini endpoint (#2413)
CC Switch's and Alma's entries whose base speaks Gemini's own protocol
(GOOGLE_GEMINI_BASE_URL; Alma's gemini format, or a google type with a
base_url) were skipped as "magpie doesn't talk the Gemini protocol to
relays yet". That was true when the import was written (0b0f258c0), but
a custom provider has taken a Gemini base since #1346, as the editor,
the TUI (#2201) and import links (#2251) do.

endpoints carries the Gemini base now, and imported() checks it as it
does the other three (http(s), never magpie's own address); merge() and
firstURL() take it. The skip and its four translations go. An entry
with no base still comes in on Google's preset, a sign-in with no key is
still skipped, and presetAt still matches on chat/responses/anthropic,
so a Gemini-only entry stays a custom provider.

Review change (on top of ggbdpq's 79a2fc71): Gemini CLI's own
@google/genai (getRequestUrlInternal, read in gemini-cli 0.35.3's
bundle) puts the API version after GOOGLE_GEMINI_BASE_URL on every
request, always "v1beta". magpie's Gemini base holds the version, and
GeminiBase adds it only to a bare host, so a relay under a path
(https://relay/gemini) would have been asked at /gemini/models/… instead
of /gemini/v1beta/models/…. geminiCLIBase appends /v1beta to CC Switch's
value. Alma's base_url already holds it (its google provider defaults to
…/v1beta and asks ${base}/models, read in Alma.app's main bundle), so
Alma's is taken as it is. TestImportAlma gains a gemini-format row and a
google-type row with a base; before, only CC Switch was tested.

Run:
- TestImportCCSwitch and TestImportAlma with importapps.go and
  import_opencode.go put back to origin/main: FAIL ("gemini relay: …
  Skip:magpie doesn't talk…", "alma gemini relay: …"). With
  geminiCLIBase taken out: FAIL ("gemini relay: … Gemini:https://g.example.com").
  Restored: ok.
- TestImport*, TestGeminiURLIsItsHost: ok.
- Full suite, go test -tags nogui -timeout 45m ./... (set -o pipefail,
  sandbox HOME, load ~350) at 0224e826f (these four commits on
  ebf3f48f7) plus #2545's patch: every package ok except internal/agent,
  whose one red (TestRekeyGivesWSLAgentTheSharingKey) is #2545's, which
  was dropped (problems posted on #2545). internal/agent alone at
  0224e826f: ok. Rebased on dccfefdf7 (#2635, internal/library only):
  build, vet, internal/library ok. gofmt -l clean; go vet darwin (gui),
  GOOS=linux and GOOS=windows -tags nogui: clean. GUI (i18n-keys,
  gui-de/ja/zh-TW, import-*, key-import, login-import): all pass except
  login-import's Chromium case, which fails the same alone on origin/main
  ebf3f48f7 (#1307, output posted there).
Not tried: a real CC Switch or Alma database, or a real Gemini relay.

Co-authored-by: ggbdpq <ggbdpq@gmail.com>
2026-10-17 11:54:55 +08:00
yetone 37fec12409 import: OpenCode's keys come in from its auth.json, Go's on OpenCode Go (@hu_xiaomi on X)
@hu_xiaomi on X asked whether magpie could pick up OpenCode Go's API key
by itself. OpenCode keeps what `opencode auth login` signs in to in
auth.json, in $XDG_DATA_HOME/opencode (~/.local/share/opencode when that
is unset, on Windows too). Its format and path were checked against
anomalyco/opencode v1.19.0, packages/opencode/src/auth/index.ts.

- OpenCode is now a source in the import picker (appReaders,
  import_opencode.go). An "api" key comes in on the magpie preset with
  the same id: opencode-go on OpenCode Go, opencode (Zen) on OpenCode
  Zen, and a vendor's key (openai, anthropic, deepseek, openrouter, ...)
  on that vendor's preset, the same way Alma's almaPresets work.
- auth.json keeps no address beside a key, so a key for a provider with
  no preset is listed and skipped ("it has no base URL"). Sign-ins
  (oauth: Claude Pro/Max, Copilot; wellknown: an enterprise server's
  token) are listed and skipped with the reason the picker already
  translates. No new GUI strings.
- OpenCode is read only when the user opens the picker. The Providers
  page's automatic discovery leaves it out (DiscoverSources, the `asked`
  flag), because the file holds every sign-in OpenCode has. magpie never
  writes to it. OPENCODE_AUTH_CONTENT is not read.
- presetAt: the first preset at a host won even when a later one matched
  the URL exactly. OpenCode Zen and Go share opencode.ai, so a Zen key
  would have landed on Go. An exact match now wins.
- importSources: a source whose stat fails with anything but not-exist
  (a folder magpie can't search) is found with an error, which means
  unknown. Before, it read as "Not found".
- The picker's tab shows OpenCode's own mark (icons/opencode.svg).
- docs/reference.md describes the source.

Not added: an "use the key OpenCode has" offer in the OpenCode Go add
sheet, because no other app has one there (no sibling to follow).

Run (macOS, go1.26.8, worktree at dd25997a4 before the rebase):
- go test -tags nogui -timeout 40m ./...: every package ok
  (63 ok, none failed; gateway 1806s, agent 1769s at load ~160-230)
- gofmt -l internal/provider internal/gui: clean
- go vet ./...; GOOS=linux go vet -tags nogui ./...;
  GOOS=windows go vet ./...: clean
- GUI, playwright 1.62.0: import-opencode.test.cjs in chromium and webkit,
  en/zh/zh-TW/ja/de, at 900 and 390px: 20/20. import-collision,
  import-row, provider-discovery and key-import pass. login-import fails
  in chromium (fill/click timeouts) at load ~230. It fails the same way
  with HEAD's app.js (dd25997a4 = origin/main, just fetched), and #1307
  already tracks it.
- Broken by hand, each went red and was then put back:
  1. presetAt's old first-hit rule: TestImportOpenCodeAuth, Zen came in
     as opencode-go-2.
  2. no sign-in skip: TestImportOpenCodeAuth, anthropic's oauth entry.
  3. stat errors read as not found: TestImportOpenCodeAuthUnknown,
     unreadable folder.
  4. discovery reads OpenCode: TestImportOpenCodeAuth and
     TestOpenCodeWaitsForThePicker.
  5. XDG_DATA_HOME ignored: TestImportOpenCodeAuth, TestImportOpenCodeAuthUnknown
     and TestOpenCodeWaitsForThePicker.
  6. tab icon left at app-opencode.png: import-opencode.test.cjs.

Fixtures are auth.json as OpenCode v1.19.0 writes it
(JSON.stringify(data, null, 2), 0600), under a sandbox HOME and
XDG_DATA_HOME. Not tried: a real OpenCode install with a real key, and
the Windows box (the path logic is the same there; GOOS=windows vet only).
2026-10-15 19:20:09 +08:00