1ccacad63281094de8a3372d5a507d38f9969e5c
3
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
9feb1024c7 |
zen: free models are asked as OpenCode 2.2.5 asks them (#3491)
laomao04_65777 on Discord: Zen's free models answered 429 "Free usage limit reached. Free models work in OpenCode" to the built-in OpenCode Zen provider, while real OpenCode 2 on the same machine was served. magpie sent OpenCode 1.x's shape. It now sends what OpenCode 2.2.5 sent in a captured request (internal/provider/testdata/opencode-2.2.5-chat.json, from a recording proxy), as the zen-free plugin does since plugins d62193c and 8501988: - User-Agent opencode/latest/<v>/cli. <v> is the version OpenCode's updater (opencode.ai/update/api/latest/cli/npm) names, never below 2.2.5 and never anything but a plain x.y.z. It is read in the background at most every 6h, with a 3s timeout and no redirects. - x-opencode-project is OpenCode's project id for the folder the agent says it works in: sha1 of git-remote:host/path (origin, else the first remote; worktree .git files followed), else of directory:<root or folder>. It is no longer "global". - b3 and traceparent: one trace a conversation, a new span a request. - The session id goes in x-opencode-session, x-opencode-session-id, x-session-affinity and x-session-id. Accept is */*, and x-opencode-request is gone. - On a free request the agent's own headers (Claude Code's x-stainless-*, Codex's originator) are dropped. Only Content-Type and Anthropic-Version and Anthropic-Beta are kept. - The core tools are edit, glob, grep, read and shell with 2.2.5's schemas, strict false on Chat. Claude Code's Read, Edit, Glob and Grep are offered under those names. Its Bash is no longer bash: shell is a stub. - OpenCode's <env> block, word for word, for the agent's folder, is added to the system prompt unless it has one already (OpenCode's own). - Paths are the v2 catalog's: /inference/openai/v1 for Chat and Responses, and /inference/anthropic/v1 for Messages. The models list is unchanged. Every route takes this: chat, responses and messages through forwardOnce, the Test button's probe (tiny/zenFreeProbe), and the models list (listHeadersAt: UA and x-opencode-client). Sibling: paid Zen and OpenCode Go share OpenCodeClient, so they get 2.2.5's headers. Their /zen/v1 and /zen/go/v1 paths are left as they are: #4740. Run on mote (mote-run) at this tree: - gofmt -l . is clean. - GOOS=darwin and windows go vet ./... pass. GOOS=linux go vet passes for internal/provider and internal/gateway. The whole-tree Linux vet stops in Wails' cgo when run from macOS, and in WSL for want of gtk4, before it reaches this change. - go test ./internal/provider ./internal/gateway -count=1 -timeout 45m: ok provider (154s) and ok gateway (715s) on base |
||
|
|
f0f63bf6b8 |
provider: Zen's free models answer again: asked at opencode.ai/inference/v1, with stand-in tools that take a parameter, and without x-session-affinity (c9cu on Discord)
c9cu: "opencode muse 1.3 又不行了,magpie v0.1.1239". Zen's free tier moved and tightened in mid-October 2026, found against the real upstream on 10-15: - free models answer only at https://opencode.ai/inference/v1 (models.dev's opencode api is that URL now); OpenCodeFreeURL maps /zen/... there for a free model, never /zen/go or another host, in forwardOnce and the probe; - the bash and read tools offered must each have at least one parameter: the stand-ins (zenfree.go, the probe) now carry OpenCode's own (OpenCodeToolSchemas); - a request carrying x-session-affinity is answered 403 FreeTierError. OpenCode 1.19.0, captured through a forwarding proxy, sends Zen neither x-session-affinity nor X-Session-Id, so OpenCodeClient takes both out; the agent's own session id still names x-opencode-session. Bisected header by header: X-Session-Id, Accept and the UA version don't matter; x-session-affinity alone turns a 200 into a 403. Live against the real Zen with the public key (a test file since removed): muse via /v1/responses streamed (xhigh) and not, big-pickle on chat streamed, mimo-v2.6-flash-free on chat: all 200; muse via /v1/messages 200. The same code with x-session-affinity left in: 403 on every case. Run: gofmt -l clean; go vet darwin, GOOS=linux -tags nogui, GOOS=windows -tags nogui on internal/provider and internal/gateway; the full go test -tags nogui -count=1 ./... in a sandbox HOME, whose one red was gateway's TestOpenCodeClientHeaders still expecting the two headers (updated here), then internal/gateway alone again: ok (678s). New tests TestZenFreeAtInferenceURL, TestOpenCodeFreeURL and the probe's non-empty properties check fail on the old code. The community plugin got the same fix in magpie-community/plugins 5fc0a75 (zen-free 0.1.7); its npm publish is blocked on the repo's publisher setup. |
||
|
|
8e6354714f |
provider: OpenCode Zen's free models answer again, with a session id OpenCode itself could have made (c9cu on Discord)
c9cu (v0.1.1222, Pi, a group routed to OpenCode Zen's muse-spark-1.3-contributor-free on /v1/responses) got 403 FreeTierError "OpenCode's free tier can only be used from within OpenCode" on a setup that worked the day before. Zen now reads x-opencode-session as OpenCode's identifier.ts lays an id out (12 hex of ~(Date.now()*0x1000 + counter), then 14 base62) and refuses one whose counter isn't small. magpie's built-in sent a sha256 of the conversation cut to that shape, so its counter was anything. The zen-free plugin hit the same (#100 on magpie-community/plugins, 0.1.5); the built-in had the same code. Header diff against the real upstream, same request with curl: - magpie's ses_e9283da055b15JwOAra76bwUx4 (hash): 403 on /v1/responses and /v1/chat/completions. - ses_ecc5d8f28ffe9Cy14V8Em7lI2u from a real OpenCode 1.19.0 run, the old opencode/1.18.34 UA unchanged: 200 on /v1/responses. So it is the session, not the UA or the endpoint; muse-spark is still served on Responses (Chat answers 400 ModelProtocolUnsupported, as before). Now (opencode_client.go): - openCodeSession makes a real descending id from the current time and a per-millisecond counter, kept per conversation (the last 1000) so a conversation's turns share one session; one OpenCode could have made is passed on unchanged, a hash-shaped one is not. - x-opencode-request is an ascending msg_ id the same way. - the session also goes in x-opencode-session-id, x-session-affinity and X-Session-Id, as OpenCode's packages/core/src/session/ model-request.ts sends it, and the User-Agent is OpenCode 1.19.0's (opencode/1.19.0 ai-sdk/provider-utils/4.0.23 runtime/bun/1.3.14, the latest on npm, as the plugin captured it). - Kilo's task/session id goes through the same openCodeSession (the Kilo CLI is OpenCode's fork and makes ids the same way). Run: - Through an in-process gateway under a sandbox HOME against the real opencode.ai/zen with the public key: muse-spark-1.3-contributor-free on /v1/responses with reasoning xhigh, streamed and not, big-pickle streamed on Chat, mimo-v2.6-flash-free on Chat: all 200 "pong". The same file on origin/main's code: all 403 FreeTierError, the reporter's message word for word. - TestOpenCodeSessionIsOpenCodes, TestOpenCodeSessionsKeptBounded and TestOpenCodeClientHeaders (now with a real 1.19.0 session) fail with the hash put back by hand. - gofmt -l, go vet (darwin, GOOS=linux, GOOS=windows -tags nogui) on internal/provider and internal/gateway. - go test -tags nogui -count=1 ./... under a temp HOME on base |