Commit Graph
4 Commits
Author SHA1 Message Date
yetone a3cd133845 provider, gui: Add another key on an OpenCode Zen provider says an empty field adds public, the key its free models answer, and adds it (#1795)
An OpenCode Zen provider added with no key asks with public, the key
OpenCode sends signed out (normalize). On a Zen provider that already had
a key of the user's own, Add another key said only "paste an API key", and
with nothing pasted AddKey refused before it knew which provider it was
("paste the key to add"), so there was no way to learn of public or add it
as the anonymous fallback behind the user's own key.

- provider: Provider.AnonymousKey is the key a provider is asked with when
  the user has none (OpenCode Zen's public, by its preset, as normalize
  already decided; "" for every other, Kilo included). AddKey looks the
  provider up first; nothing pasted adds that key, and asked again says
  "<name> already has public, the key its free models answer with none of
  yours" rather than "already has this key". Every other provider still
  wants a key pasted. normalize reads the same method.
- gui: /api/providers names anonKey on a provider that has such a key and
  doesn't have it yet. Its Add another key field reads "paste an API key,
  or leave empty for public: free models only" (title too, where a narrow
  field cuts it short), and the row added is marked as any new key's is.
  zh, zh-TW, ja and de translations.

Verified:
- TestZenAddKeyEmptyIsPublic (provider) fails on the old code with
  "paste the key to add"; TestZenAddAnotherKeyEmptyAddsPublic (gui,
  through /api/keys/add and /api/providers) fails with `Zen with its own
  key offers ""`. Both pass with the change.
- zen-anon-key.test.cjs: 40 pass in chromium and webkit, en/zh/zh-TW/ja/de,
  at 900 and 560px; on the old app.js the placeholder test fails
  ('paste an API key' vs the new hint).
- gui-de, gui-ja, gui-zh-tw, i18n-keys, key-import, provider-many-keys,
  nokey-editor, key-copy: 46 pass.
- Not tried against Zen itself: whether a gateway falling from a spent key
  to public on a paid model rests public is unchanged behavior, the same as
  for public typed by hand.
2026-10-12 23:16:54 +08:00
yetone b0486663d2 providers: OpenCode Zen's free models answer with no key, as OpenCode signed out asks them (#572: opencode zen的free模型,只能在他自己的cli里面用,能否做插件反代出来?) — magpie has asked Zen's free models as OpenCode does since v0.1.615 (zenfree.go), but the OpenCode Zen preset wanted a key, which means an opencode.ai account. OpenCode itself, signed out, asks Zen with the key "public", and Zen lists and serves its -free models to it (checked: /zen/v1/models with it lists twelve). The preset's key is now optional ("optional: free models need no key"), and a Zen provider saved with none asks with OpenCode's (normalize, provider.OpenCodeAnonymousKey); a key of the user's own is kept, and the editor's blank key still keeps the one saved. TestOpenCodeZenNeedsNoKey (keyless Add refused without the change) is new. go vet ./internal/..., go build -tags nogui (darwin, GOOS=linux), GOOS=windows go build, go test -tags nogui -count=1 ./... under a temp HOME pass. 2026-10-02 22:31:49 +08:00
yetone 16e373b924 opencode: Zen's free models answer through magpie from Claude Code, Codex and the model test too (ARNO on Discord: mimo-v2.6-flash-free 没有响应: 403 · OpenCode's free tier can only be used from within OpenCode; the user: 只要不是 claude code,都可以尝试伪装一下) — beyond OpenCode's headers (v0.1.615), Zen's free tier takes only a streamed request offering tools named bash and read. A request to a -free model on opencode.ai now always streams upstream, a client that didn't ask for a stream getting the reply collected; a caller's Bash/Read (any case) go as bash/read, as do earlier calls in the history and a forced tool_choice, and calls in the reply get the caller's names back, streamed or not, in each search round too; when bash or read is missing a stub is offered whose description says never to call it, and a call to a stub never reaches the client (a turn with nothing else ends on its text, or a short note, as a stop). Zen lists its -free models again. Paid Zen models and other providers are untouched. Real requests to opencode.ai/zen/v1 with the anonymous key: Claude Code-style Bash/Read streamed and not, Codex-style shell on /v1/responses, no tools non-stream, and the model test all answered 200. TestZenFree* fail without the change. 2026-10-02 09:23:29 +08:00
yetone eb4c4910c3 providers: OpenCode Zen's free models aren't listed (ARNO on Discord: mimo-v2.6-flash-free 403 · OpenCode's free tier can only be used from within OpenCode) — OpenCode serves its -free models to its own client alone and answers anything else 403, while magpie listed them with the paid ones. A preset's Drop names what such models' ids end with, and they are left out of its list; magpie doesn't pass itself off as OpenCode. TestOpenCodeZenDropsFreeModels fails without the change. go vet, go build -tags nogui (darwin, GOOS=linux), GOOS=windows go build, go test -tags nogui ./... pass (TestFXInState flaked once under load, passes alone and on the package rerun). 2026-10-02 00:40:39 +08:00