Files
Jason Xu 2319941a6a fix(upstream): restore v1.3.7 request shape and stub tools on legacy /zen/v1 lane
Commit 076451f preferred the legacy /zen/v1 origin ahead of /inference,
but still applied the 2026-10-14 /inference gate rules to /zen/v1
requests:

- ensureAnonymousTools rewrote any client-declared tool sharing a
  recognised OpenCode 2.x name ("read", "edit", "write", "glob", "grep",
  "shell", etc.) with the embedded CLI 2.x schema from
  opencode_tools.json, clobbering downstream function-calling schemas,
  and anonymousTool injected full 2.x tool schemas for edit/glob/grep/read
  alongside a stub bash tool.
- newUpstreamRequest and FetchModels sent the 2.x CLI User-Agent and
  header set instead of the v1.3.7 OpenCode 1.18.x headers.

Restore the v1.3.7 request shape when targeting the legacy /zen/v1 origin
(LegacyUserAgent, x-opencode-request, prj_* project id, lightweight tool
stubs, and untouched client tool definitions) while keeping the 2.x CLI
fingerprint and genuine tool definitions for the /inference fallback lane.
2026-10-17 06:17:54 +08:00

30 lines
1.0 KiB
Go

package httpx
import (
"fmt"
"runtime"
)
// clientVersion is the OpenCode release the gateway claims to be on the
// /inference lane. Upstream accepts a range of releases (the version number
// itself is not validated), so this only needs bumping when it starts rejecting
// older ones.
const clientVersion = "2.0.29"
// legacyClientVersion is the pre-2.x OpenCode release reported on the legacy
// /zen/v1 lane, matching the v1.3.7 User-Agent shape.
const legacyClientVersion = "1.18.31"
// UserAgent reports the gateway as an OpenCode 2.x client using the shape the
// /inference gate expects: "opencode/<channel>/<version>/<name>".
func UserAgent() string {
return "opencode/latest/" + clientVersion + "/cli"
}
// LegacyUserAgent reports the gateway using the v1.3.7 OpenCode 1.18.x
// User-Agent shape ("opencode/<version> (<os> <arch>; <runtime>)") for the
// legacy /zen/v1 lane.
func LegacyUserAgent() string {
return fmt.Sprintf("opencode/%s (%s %s; %s)", legacyClientVersion, runtime.GOOS, runtime.GOARCH, runtime.Version())
}