mirror of
https://github.com/jasonxu114514/opencode2api.git
synced 2026-12-05 08:02:53 +00:00
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.
This commit is contained in:
1 parent
8b61b66235
commit
2319941a6a
3 files changed
+120
-71
No files matched your search
@@ -270,12 +270,17 @@ type modelsResponse struct {
|
||||
}
|
||||
|
||||
func FetchModels(ctx context.Context, client *http.Client, baseURL, key string) ([]string, int, error) {
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, strings.TrimRight(baseURL, "/")+"/v1/models", nil)
|
||||
trimmed := strings.TrimRight(strings.TrimSpace(baseURL), "/")
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, trimmed+"/v1/models", nil)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
req.Header.Set("Authorization", "Bearer "+key)
|
||||
req.Header.Set("User-Agent", httpx.UserAgent())
|
||||
if strings.EqualFold(trimmed, strings.TrimRight(LegacyZenBase, "/")) || strings.HasSuffix(strings.ToLower(trimmed), "/zen") {
|
||||
req.Header.Set("User-Agent", httpx.LegacyUserAgent())
|
||||
} else {
|
||||
req.Header.Set("User-Agent", httpx.UserAgent())
|
||||
}
|
||||
req.Header.Set("x-opencode-client", "cli")
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
|
||||
Reference in new issue
Block a user