more OC headers
This commit is contained in:
@@ -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"}}
|
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 {
|
func atoiD(s string, d int) int {
|
||||||
if v, e := strconv.Atoi(strings.TrimSpace(s)); e == nil {
|
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)
|
req, err := http.NewRequest("GET", strings.TrimRight(cfg.Endpoint, "/")+"/models", nil)
|
||||||
if err != nil { return 0 }
|
if err != nil { return 0 }
|
||||||
req.Header.Set("User-Agent", opencodeAgentVersion)
|
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) }
|
if cfg.APIKey != "" && cfg.APIKey != "-" { req.Header.Set("Authorization", "Bearer "+cfg.APIKey) }
|
||||||
resp, err := client.Do(req)
|
resp, err := client.Do(req)
|
||||||
if err != nil || resp.StatusCode >= 400 { return 0 }
|
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)
|
req, err := http.NewRequest("GET", strings.TrimRight(cfg.Endpoint, "/")+"/models", nil)
|
||||||
if err != nil { return "", err }
|
if err != nil { return "", err }
|
||||||
req.Header.Set("User-Agent", opencodeAgentVersion)
|
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) }
|
if cfg.APIKey != "" && cfg.APIKey != "-" { req.Header.Set("Authorization", "Bearer "+cfg.APIKey) }
|
||||||
resp, err := client.Do(req)
|
resp, err := client.Do(req)
|
||||||
if err != nil { return "", err }
|
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, _ := http.NewRequestWithContext(ctx, "POST", strings.TrimRight(cfg.Endpoint, "/")+"/chat/completions", bytes.NewReader(body))
|
||||||
req.Header.Set("Content-Type", "application/json")
|
req.Header.Set("Content-Type", "application/json")
|
||||||
req.Header.Set("User-Agent", opencodeAgentVersion)
|
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) }
|
if cfg.APIKey != "" && cfg.APIKey != "-" { req.Header.Set("Authorization", "Bearer "+cfg.APIKey) }
|
||||||
resp, err = client.Do(req)
|
resp, err = client.Do(req)
|
||||||
var is4xxClientErr bool
|
var is4xxClientErr bool
|
||||||
|
|||||||
+1
-1
@@ -1170,7 +1170,7 @@ func TestLLMNonStreamingAndHeaders(t *testing.T) {
|
|||||||
if gotAuth != "Bearer secret" {
|
if gotAuth != "Bearer secret" {
|
||||||
t.Errorf("auth = %q", gotAuth)
|
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)
|
t.Errorf("user-agent = %q", gotUA)
|
||||||
}
|
}
|
||||||
if m.Content == nil || *m.Content != "hi" || m.ReasoningContent != "think" {
|
if m.Content == nil || *m.Content != "hi" || m.ReasoningContent != "think" {
|
||||||
|
|||||||
Reference in New Issue
Block a user