more opencode fixes

This commit is contained in:
Luxferre
2026-09-17 10:35:16 +03:00
parent a02b388b1a
commit 1d8a19dd67
2 changed files with 40 additions and 7 deletions
+16 -6
View File
@@ -107,8 +107,8 @@ func queryModelsContextWindow(cfg *Cfg) int {
req.Header.Set("User-Agent", opencodeAgentVersion)
req.Header.Set("X-Session-Id", projectID())
req.Header.Set("x-opencode-project", projectID())
req.Header.Set("x-opencode-client", opencodeAgentVersion)
req.Header.Set("x-opencode-session", projectID())
req.Header.Set("x-opencode-client", "cli")
req.Header.Set("x-opencode-session", opencodeSessionID())
if cfg.APIKey != "" && cfg.APIKey != "-" { req.Header.Set("Authorization", "Bearer "+cfg.APIKey) }
resp, err := client.Do(req)
if err != nil || resp.StatusCode >= 400 { return 0 }
@@ -183,8 +183,8 @@ func listModels(cfg *Cfg) (string, error) {
req.Header.Set("User-Agent", opencodeAgentVersion)
req.Header.Set("X-Session-Id", projectID())
req.Header.Set("x-opencode-project", projectID())
req.Header.Set("x-opencode-client", opencodeAgentVersion)
req.Header.Set("x-opencode-session", projectID())
req.Header.Set("x-opencode-client", "cli")
req.Header.Set("x-opencode-session", opencodeSessionID())
if cfg.APIKey != "" && cfg.APIKey != "-" { req.Header.Set("Authorization", "Bearer "+cfg.APIKey) }
resp, err := client.Do(req)
if err != nil { return "", err }
@@ -1055,8 +1055,8 @@ func llm(ctx context.Context, cfg *Cfg, msgs []Message, tools []map[string]any)
req.Header.Set("User-Agent", opencodeAgentVersion)
req.Header.Set("X-Session-Id", projectID())
req.Header.Set("x-opencode-project", projectID())
req.Header.Set("x-opencode-client", opencodeAgentVersion)
req.Header.Set("x-opencode-session", projectID())
req.Header.Set("x-opencode-client", "cli")
req.Header.Set("x-opencode-session", opencodeSessionID())
if cfg.APIKey != "" && cfg.APIKey != "-" { req.Header.Set("Authorization", "Bearer "+cfg.APIKey) }
resp, err = client.Do(req)
var is4xxClientErr bool
@@ -1621,6 +1621,16 @@ func projectID() string {
return hex.EncodeToString(h[:])
}
func opencodeSessionID() string {
pid := projectID()
if len(pid) > 26 {
pid = pid[:26]
} else if len(pid) < 26 {
pid = (pid + "0123456789abcdef0123456789")[:26]
}
return "ses_" + pid
}
func saveSession(msgs []Message, sid string) (string, string) {
sid = strings.TrimSpace(sid)
if sid == "" {