Changeset 0.23.0 (#153)
This commit is contained in:
@@ -4,6 +4,10 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"log"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"time"
|
||||
|
||||
"git.gobha.me/xcaliber/chat-switchboard/models"
|
||||
)
|
||||
@@ -43,6 +47,41 @@ type ProviderConfig struct {
|
||||
APIKey string
|
||||
CustomHeaders map[string]string // Extra HTTP headers (e.g. OpenRouter HTTP-Referer)
|
||||
Settings map[string]interface{} // Provider-specific settings from config JSONB
|
||||
ProxyMode string // "system" (default), "direct", "custom"
|
||||
ProxyURL string // Only used when ProxyMode == "custom"
|
||||
}
|
||||
|
||||
// Client returns an *http.Client configured for this provider's proxy settings.
|
||||
// system = http.ProxyFromEnvironment (Go default), direct = no proxy,
|
||||
// custom = explicit proxy URL (http/https/socks5).
|
||||
func (c ProviderConfig) Client() *http.Client {
|
||||
transport := &http.Transport{
|
||||
MaxIdleConns: 100,
|
||||
IdleConnTimeout: 90 * time.Second,
|
||||
TLSHandshakeTimeout: 10 * time.Second,
|
||||
}
|
||||
switch c.ProxyMode {
|
||||
case "direct":
|
||||
transport.Proxy = nil
|
||||
case "custom":
|
||||
if c.ProxyURL != "" {
|
||||
u, err := url.Parse(c.ProxyURL)
|
||||
if err != nil {
|
||||
// Fall back to system rather than silently going direct —
|
||||
// a bad custom URL in a mandatory-proxy environment is a
|
||||
// security/audit hole if it silently bypasses.
|
||||
log.Printf("[proxy] invalid custom proxy URL %q: %v — falling back to system proxy", c.ProxyURL, err)
|
||||
transport.Proxy = http.ProxyFromEnvironment
|
||||
} else {
|
||||
transport.Proxy = http.ProxyURL(u)
|
||||
}
|
||||
} else {
|
||||
transport.Proxy = http.ProxyFromEnvironment
|
||||
}
|
||||
default: // "system" or empty
|
||||
transport.Proxy = http.ProxyFromEnvironment
|
||||
}
|
||||
return &http.Client{Transport: transport}
|
||||
}
|
||||
|
||||
// ── Request / Response Types ────────────────
|
||||
@@ -60,7 +99,7 @@ type Message struct {
|
||||
// Tool calling fields (assistant → tool_calls, tool → tool_call_id)
|
||||
ToolCalls []ToolCall `json:"tool_calls,omitempty"` // set when assistant requests tools
|
||||
ToolCallID string `json:"tool_call_id,omitempty"` // set for role="tool" result messages
|
||||
Name string `json:"name,omitempty"` // tool name for role="tool"
|
||||
Name string `json:"name,omitempty"` // speaker name (tool result, or persona attribution v0.23.0)
|
||||
}
|
||||
|
||||
// ContentPart is a single element in a multimodal message.
|
||||
|
||||
Reference in New Issue
Block a user