more OC headers

This commit is contained in:
Luxferre
2026-09-17 10:02:08 +03:00
parent 9792cec64f
commit a02b388b1a
2 changed files with 14 additions and 5 deletions
+13 -4
View File
@@ -85,7 +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"
const opencodeAgentVersion = "opencode/1.18.31"
func atoiD(s string, d int) int {
if v, e := strconv.Atoi(strings.TrimSpace(s)); e == nil {
@@ -105,7 +105,10 @@ 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", opencodeAgentVersion)
req.Header.Set("X-Session-ID", projectID())
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())
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 }
@@ -178,7 +181,10 @@ 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", opencodeAgentVersion)
req.Header.Set("X-Session-ID", projectID())
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())
if cfg.APIKey != "" && cfg.APIKey != "-" { req.Header.Set("Authorization", "Bearer "+cfg.APIKey) }
resp, err := client.Do(req)
if err != nil { return "", err }
@@ -1047,7 +1053,10 @@ func llm(ctx context.Context, cfg *Cfg, msgs []Message, tools []map[string]any)
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", opencodeAgentVersion)
req.Header.Set("X-Session-ID", projectID())
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())
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, "opencode/1.18.30") {
if !strings.Contains(gotUA, "opencode/1.18.31") {
t.Errorf("user-agent = %q", gotUA)
}
if m.Content == nil || *m.Content != "hi" || m.ReasoningContent != "think" {