opencode session fixes

This commit is contained in:
Luxferre
2026-09-11 18:52:14 +03:00
parent b776644261
commit 9792cec64f
2 changed files with 8 additions and 4 deletions
+7 -3
View File
@@ -85,6 +85,7 @@ var llmTransport = &http.Transport{
}
var defCfg = Cfg{"https://api.kilo.ai/api/openrouter", "openrouter/free", "-", 0.7, 300, 120, 1000, true, "auto", 262144, map[string]string{"reasoning_effort": "high"}}
const opencodeAgentVersion = "opencode/1.18.30"
func atoiD(s string, d int) int {
if v, e := strconv.Atoi(strings.TrimSpace(s)); e == nil {
@@ -103,7 +104,8 @@ func queryModelsContextWindow(cfg *Cfg) int {
}
req, err := http.NewRequest("GET", strings.TrimRight(cfg.Endpoint, "/")+"/models", nil)
if err != nil { return 0 }
req.Header.Set("User-Agent", "Mozilla/5.0 (compatible; Bantam/1.0)")
req.Header.Set("User-Agent", opencodeAgentVersion)
req.Header.Set("X-Session-ID", projectID())
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 }
@@ -175,7 +177,8 @@ func listModels(cfg *Cfg) (string, error) {
}
req, err := http.NewRequest("GET", strings.TrimRight(cfg.Endpoint, "/")+"/models", nil)
if err != nil { return "", err }
req.Header.Set("User-Agent", "Mozilla/5.0 (compatible; Bantam/1.0)")
req.Header.Set("User-Agent", opencodeAgentVersion)
req.Header.Set("X-Session-ID", projectID())
if cfg.APIKey != "" && cfg.APIKey != "-" { req.Header.Set("Authorization", "Bearer "+cfg.APIKey) }
resp, err := client.Do(req)
if err != nil { return "", err }
@@ -1043,7 +1046,8 @@ func llm(ctx context.Context, cfg *Cfg, msgs []Message, tools []map[string]any)
if COL { fmt.Print("\r" + pend) } else { fmt.Println(pend) }
req, _ := http.NewRequestWithContext(ctx, "POST", strings.TrimRight(cfg.Endpoint, "/")+"/chat/completions", bytes.NewReader(body))
req.Header.Set("Content-Type", "application/json")
req.Header.Set("User-Agent", "Mozilla/5.0 (compatible; Bantam/1.0)")
req.Header.Set("User-Agent", opencodeAgentVersion)
req.Header.Set("X-Session-ID", projectID())
if cfg.APIKey != "" && cfg.APIKey != "-" { req.Header.Set("Authorization", "Bearer "+cfg.APIKey) }
resp, err = client.Do(req)
var is4xxClientErr bool
+1 -1
View File
@@ -1170,7 +1170,7 @@ func TestLLMNonStreamingAndHeaders(t *testing.T) {
if gotAuth != "Bearer secret" {
t.Errorf("auth = %q", gotAuth)
}
if !strings.Contains(gotUA, "Bantam/1.0") {
if !strings.Contains(gotUA, "opencode/1.18.30") {
t.Errorf("user-agent = %q", gotUA)
}
if m.Content == nil || *m.Content != "hi" || m.ReasoningContent != "think" {