Documentation
¶
Index ¶
- Constants
- Variables
- func CloseClient(client protocol.Client) error
- func CreateHTTPClientForProvider(provider *typ.Provider) *http.Client
- func CreateHTTPClientWithProxy(proxyURL string) *http.Client
- func IsModelsEndpointNotSupported(err error) bool
- type AnthropicClient
- func (c *AnthropicClient) APIStyle() protocol.APIStyle
- func (c *AnthropicClient) BetaMessagesCountTokens(ctx context.Context, req anthropic.BetaMessageCountTokensParams) (*anthropic.BetaMessageTokensCount, error)
- func (c *AnthropicClient) BetaMessagesNew(ctx context.Context, req anthropic.BetaMessageNewParams) (*anthropic.BetaMessage, error)
- func (c *AnthropicClient) BetaMessagesNewStreaming(ctx context.Context, req anthropic.BetaMessageNewParams) *anthropicstream.Stream[anthropic.BetaRawMessageStreamEventUnion]
- func (c *AnthropicClient) Client() *anthropic.Client
- func (c *AnthropicClient) Close() error
- func (c *AnthropicClient) GetProvider() *typ.Provider
- func (c *AnthropicClient) HttpClient() *http.Client
- func (c *AnthropicClient) ListModels(ctx context.Context) ([]string, error)
- func (c *AnthropicClient) MessagesCountTokens(ctx context.Context, req anthropic.MessageCountTokensParams) (*anthropic.MessageTokensCount, error)
- func (c *AnthropicClient) MessagesNew(ctx context.Context, req anthropic.MessageNewParams) (*anthropic.Message, error)
- func (c *AnthropicClient) MessagesNewStreaming(ctx context.Context, req anthropic.MessageNewParams) *anthropicstream.Stream[anthropic.MessageStreamEventUnion]
- func (c *AnthropicClient) ProbeChatEndpoint(ctx context.Context, model string) ProbeResult
- func (c *AnthropicClient) ProbeModelsEndpoint(ctx context.Context) ProbeResult
- func (c *AnthropicClient) ProbeOptionsEndpoint(ctx context.Context) ProbeResult
- func (c *AnthropicClient) SetRecordSink(sink *obs.Sink)
- type ClientPool
- func (p *ClientPool) Clear()
- func (p *ClientPool) GetAnthropicClient(provider *typ.Provider, model string) *AnthropicClient
- func (p *ClientPool) GetGoogleClient(provider *typ.Provider, model string) *GoogleClient
- func (p *ClientPool) GetOpenAIClient(provider *typ.Provider, model string) *OpenAIClient
- func (p *ClientPool) GetProviderKeys() []string
- func (p *ClientPool) GetRecordSink() *obs.Sink
- func (p *ClientPool) RemoveProvider(provider *typ.Provider, model string)
- func (p *ClientPool) SetRecordSink(sink *obs.Sink)
- func (p *ClientPool) Size() int
- func (p *ClientPool) StartCleanupTask(interval time.Duration)
- func (p *ClientPool) Stats() map[string]interface{}
- type ErrModelsEndpointNotSupported
- type GoogleClient
- func (c *GoogleClient) APIStyle() protocol.APIStyle
- func (c *GoogleClient) Client() *genai.Client
- func (c *GoogleClient) Close() error
- func (c *GoogleClient) GenerateContent(ctx context.Context, model string, contents []*genai.Content, ...) (*genai.GenerateContentResponse, error)
- func (c *GoogleClient) GenerateContentStream(ctx context.Context, model string, contents []*genai.Content, ...) iter.Seq2[*genai.GenerateContentResponse, error]
- func (c *GoogleClient) GetProvider() *typ.Provider
- func (c *GoogleClient) ListModels(ctx context.Context) ([]string, error)
- func (c *GoogleClient) ProbeChatEndpoint(ctx context.Context, model string) ProbeResult
- func (c *GoogleClient) ProbeModelsEndpoint(ctx context.Context) ProbeResult
- func (c *GoogleClient) ProbeOptionsEndpoint(ctx context.Context) ProbeResult
- func (c *GoogleClient) SetRecordSink(sink *obs.Sink)
- type HookFunc
- type ModelLister
- type OpenAIClient
- func (c *OpenAIClient) APIStyle() protocol.APIStyle
- func (c *OpenAIClient) ChatCompletionsNew(ctx context.Context, req openai.ChatCompletionNewParams) (*openai.ChatCompletion, error)
- func (c *OpenAIClient) ChatCompletionsNewStreaming(ctx context.Context, req openai.ChatCompletionNewParams) *ssestream.Stream[openai.ChatCompletionChunk]
- func (c *OpenAIClient) Client() *openai.Client
- func (c *OpenAIClient) Close() error
- func (c *OpenAIClient) GetProvider() *typ.Provider
- func (c *OpenAIClient) HttpClient() *http.Client
- func (c *OpenAIClient) ListModels(ctx context.Context) ([]string, error)
- func (c *OpenAIClient) ProbeChatEndpoint(ctx context.Context, model string) ProbeResult
- func (c *OpenAIClient) ProbeModelsEndpoint(ctx context.Context) ProbeResult
- func (c *OpenAIClient) ProbeOptionsEndpoint(ctx context.Context) ProbeResult
- func (c *OpenAIClient) ResponsesNew(ctx context.Context, req responses.ResponseNewParams) (*responses.Response, error)
- func (c *OpenAIClient) ResponsesNewStreaming(ctx context.Context, req responses.ResponseNewParams) *ssestream.Stream[responses.ResponseStreamEventUnion]
- func (c *OpenAIClient) SetRecordSink(sink *obs.Sink)
- type ProbeResult
- type ProbeUsage
- type Prober
- type RecordRoundTripper
- type TransportPool
Constants ¶
const ( DefaultClientTTL = 60 * time.Minute // Default time-to-live for cached clients DefaultCleanupInterval = 60 * time.Minute // Default interval for cleanup task )
Constants for client TTL and cleanup interval
const ClaudeCodeSystemHeader = "You are Claude Code, Anthropic's official CLI for Claude."
ClaudeCodeSystemHeader is a special system message for Claude Code OAuth subscriptions
const ScenarioContextKey contextKey = "scenario"
Variables ¶
var NewAnthropicClient func(provider *typ.Provider) (*AnthropicClient, error) = defaultNewAnthropicClient
NewAnthropicClient creates a new Anthropic client wrapper
var NewOpenAIClient func(provider *typ.Provider) (*OpenAIClient, error) = defaultNewOpenAIClient
NewOpenAIClient creates a new OpenAI client wrapper
Functions ¶
func CloseClient ¶
CloseClient closes a client if it implements Close()
func CreateHTTPClientForProvider ¶
CreateHTTPClientForProvider creates an HTTP client configured for the given provider It handles proxy and OAuth hooks if applicable
Returns a configured http.Client
func CreateHTTPClientWithProxy ¶
CreateHTTPClientWithProxy creates an HTTP client with proxy support
func IsModelsEndpointNotSupported ¶ added in v0.260204.1200
IsModelsEndpointNotSupported checks if an error is ErrModelsEndpointNotSupported
Types ¶
type AnthropicClient ¶
type AnthropicClient struct {
// contains filtered or unexported fields
}
AnthropicClient wraps the Anthropic SDK client
func (*AnthropicClient) APIStyle ¶
func (c *AnthropicClient) APIStyle() protocol.APIStyle
ProviderType returns the provider type
func (*AnthropicClient) BetaMessagesCountTokens ¶
func (c *AnthropicClient) BetaMessagesCountTokens(ctx context.Context, req anthropic.BetaMessageCountTokensParams) (*anthropic.BetaMessageTokensCount, error)
func (*AnthropicClient) BetaMessagesNew ¶
func (c *AnthropicClient) BetaMessagesNew(ctx context.Context, req anthropic.BetaMessageNewParams) (*anthropic.BetaMessage, error)
BetaMessagesNew creates a new beta message request
func (*AnthropicClient) BetaMessagesNewStreaming ¶
func (c *AnthropicClient) BetaMessagesNewStreaming(ctx context.Context, req anthropic.BetaMessageNewParams) *anthropicstream.Stream[anthropic.BetaRawMessageStreamEventUnion]
BetaMessagesNewStreaming creates a new beta streaming message request
func (*AnthropicClient) Client ¶
func (c *AnthropicClient) Client() *anthropic.Client
Client returns the underlying Anthropic SDK client
func (*AnthropicClient) Close ¶
func (c *AnthropicClient) Close() error
Close closes any resources held by the client
func (*AnthropicClient) GetProvider ¶
func (c *AnthropicClient) GetProvider() *typ.Provider
GetProvider returns the provider for this client
func (*AnthropicClient) HttpClient ¶
func (c *AnthropicClient) HttpClient() *http.Client
HttpClient returns the underlying HTTP client for passthrough/proxy operations
func (*AnthropicClient) ListModels ¶ added in v0.260204.1200
func (c *AnthropicClient) ListModels(ctx context.Context) ([]string, error)
ListModels returns the list of available models from the Anthropic API
func (*AnthropicClient) MessagesCountTokens ¶
func (c *AnthropicClient) MessagesCountTokens(ctx context.Context, req anthropic.MessageCountTokensParams) (*anthropic.MessageTokensCount, error)
MessagesCountTokens counts tokens for a message request
func (*AnthropicClient) MessagesNew ¶
func (c *AnthropicClient) MessagesNew(ctx context.Context, req anthropic.MessageNewParams) (*anthropic.Message, error)
MessagesNew creates a new message request
func (*AnthropicClient) MessagesNewStreaming ¶
func (c *AnthropicClient) MessagesNewStreaming(ctx context.Context, req anthropic.MessageNewParams) *anthropicstream.Stream[anthropic.MessageStreamEventUnion]
MessagesNewStreaming creates a new streaming message request
func (*AnthropicClient) ProbeChatEndpoint ¶ added in v0.260204.1200
func (c *AnthropicClient) ProbeChatEndpoint(ctx context.Context, model string) ProbeResult
ProbeChatEndpoint tests the messages endpoint with a minimal request
func (*AnthropicClient) ProbeModelsEndpoint ¶ added in v0.260204.1200
func (c *AnthropicClient) ProbeModelsEndpoint(ctx context.Context) ProbeResult
ProbeModelsEndpoint tests the models list endpoint
func (*AnthropicClient) ProbeOptionsEndpoint ¶ added in v0.260204.1200
func (c *AnthropicClient) ProbeOptionsEndpoint(ctx context.Context) ProbeResult
ProbeOptionsEndpoint tests basic connectivity with an OPTIONS request
func (*AnthropicClient) SetRecordSink ¶
func (c *AnthropicClient) SetRecordSink(sink *obs.Sink)
SetRecordSink sets the record sink for the client
type ClientPool ¶
type ClientPool struct {
// contains filtered or unexported fields
}
ClientPool manages unified client instances for different providers
func (*ClientPool) GetAnthropicClient ¶
func (p *ClientPool) GetAnthropicClient(provider *typ.Provider, model string) *AnthropicClient
GetAnthropicClient returns an Anthropic client wrapper for the specified provider
func (*ClientPool) GetGoogleClient ¶
func (p *ClientPool) GetGoogleClient(provider *typ.Provider, model string) *GoogleClient
GetGoogleClient returns a Google client wrapper for the specified provider
func (*ClientPool) GetOpenAIClient ¶
func (p *ClientPool) GetOpenAIClient(provider *typ.Provider, model string) *OpenAIClient
GetOpenAIClient returns an OpenAI client wrapper for the specified provider
func (*ClientPool) GetProviderKeys ¶
func (p *ClientPool) GetProviderKeys() []string
GetProviderKeys returns all provider keys currently in the pool
func (*ClientPool) GetRecordSink ¶
func (p *ClientPool) GetRecordSink() *obs.Sink
GetRecordSink returns the record sink
func (*ClientPool) RemoveProvider ¶
func (p *ClientPool) RemoveProvider(provider *typ.Provider, model string)
RemoveProvider removes a specific provider's client from the pool
func (*ClientPool) SetRecordSink ¶
func (p *ClientPool) SetRecordSink(sink *obs.Sink)
SetRecordSink sets the record sink for the client pool
func (*ClientPool) Size ¶
func (p *ClientPool) Size() int
Size returns the total number of clients currently in both pools
func (*ClientPool) StartCleanupTask ¶ added in v0.260204.1200
func (p *ClientPool) StartCleanupTask(interval time.Duration)
StartCleanupTask starts a periodic cleanup task that removes expired clients The cleanup runs in a background goroutine and continues until the process exits
func (*ClientPool) Stats ¶
func (p *ClientPool) Stats() map[string]interface{}
Stats provides statistics about the client pool
type ErrModelsEndpointNotSupported ¶ added in v0.260204.1200
ErrModelsEndpointNotSupported is returned when the provider does not support the models endpoint
func (*ErrModelsEndpointNotSupported) Error ¶ added in v0.260204.1200
func (e *ErrModelsEndpointNotSupported) Error() string
type GoogleClient ¶
type GoogleClient struct {
// contains filtered or unexported fields
}
GoogleClient wraps the Google genai SDK client
func NewGoogleClient ¶
func NewGoogleClient(provider *typ.Provider) (*GoogleClient, error)
NewGoogleClient creates a new Google client wrapper
func (*GoogleClient) APIStyle ¶
func (c *GoogleClient) APIStyle() protocol.APIStyle
ProviderType returns the provider type
func (*GoogleClient) Client ¶
func (c *GoogleClient) Client() *genai.Client
Client returns the underlying Google genai SDK client
func (*GoogleClient) Close ¶
func (c *GoogleClient) Close() error
Close closes any resources held by the client
func (*GoogleClient) GenerateContent ¶
func (c *GoogleClient) GenerateContent(ctx context.Context, model string, contents []*genai.Content, config *genai.GenerateContentConfig) (*genai.GenerateContentResponse, error)
GenerateContent generates content using the Google API
func (*GoogleClient) GenerateContentStream ¶
func (c *GoogleClient) GenerateContentStream(ctx context.Context, model string, contents []*genai.Content, config *genai.GenerateContentConfig) iter.Seq2[*genai.GenerateContentResponse, error]
GenerateContentStream generates content using streaming
func (*GoogleClient) GetProvider ¶
func (c *GoogleClient) GetProvider() *typ.Provider
GetProvider returns the provider for this client
func (*GoogleClient) ListModels ¶ added in v0.260204.1200
func (c *GoogleClient) ListModels(ctx context.Context) ([]string, error)
ListModels returns the list of available models from the Google Gemini API Note: Google genai SDK doesn't have a direct ListModels method, so we return ErrModelsEndpointNotSupported to signal the caller to use template fallback.
func (*GoogleClient) ProbeChatEndpoint ¶ added in v0.260224.0
func (c *GoogleClient) ProbeChatEndpoint(ctx context.Context, model string) ProbeResult
ProbeChatEndpoint tests the chat endpoint with a minimal request
func (*GoogleClient) ProbeModelsEndpoint ¶ added in v0.260224.0
func (c *GoogleClient) ProbeModelsEndpoint(ctx context.Context) ProbeResult
ProbeModelsEndpoint tests the models list endpoint
func (*GoogleClient) ProbeOptionsEndpoint ¶ added in v0.260224.0
func (c *GoogleClient) ProbeOptionsEndpoint(ctx context.Context) ProbeResult
ProbeOptionsEndpoint tests basic connectivity with an OPTIONS request
func (*GoogleClient) SetRecordSink ¶
func (c *GoogleClient) SetRecordSink(sink *obs.Sink)
SetRecordSink sets the record sink for the client
type HookFunc ¶
HookFunc is a function that can modify the request before it's sent
func GetOAuthHook ¶
func GetOAuthHook(providerType oauth.ProviderType) HookFunc
GetOAuthHook returns the hook function for the given provider type
type ModelLister ¶ added in v0.260204.1200
type ModelLister interface {
// ListModels returns the list of available models from the provider API
// Returns ErrModelsEndpointNotSupported if the provider does not support the models endpoint
ListModels(ctx context.Context) ([]string, error)
}
ModelLister defines the interface for fetching model lists from provider APIs
type OpenAIClient ¶
type OpenAIClient struct {
// contains filtered or unexported fields
}
OpenAIClient wraps the OpenAI SDK client
func (*OpenAIClient) APIStyle ¶
func (c *OpenAIClient) APIStyle() protocol.APIStyle
ProviderType returns the provider type
func (*OpenAIClient) ChatCompletionsNew ¶
func (c *OpenAIClient) ChatCompletionsNew(ctx context.Context, req openai.ChatCompletionNewParams) (*openai.ChatCompletion, error)
ChatCompletionsNew creates a new chat completion request
func (*OpenAIClient) ChatCompletionsNewStreaming ¶
func (c *OpenAIClient) ChatCompletionsNewStreaming(ctx context.Context, req openai.ChatCompletionNewParams) *ssestream.Stream[openai.ChatCompletionChunk]
ChatCompletionsNewStreaming creates a new streaming chat completion request
func (*OpenAIClient) Client ¶
func (c *OpenAIClient) Client() *openai.Client
Client returns the underlying OpenAI SDK client
func (*OpenAIClient) Close ¶
func (c *OpenAIClient) Close() error
Close closes any resources held by the client
func (*OpenAIClient) GetProvider ¶
func (c *OpenAIClient) GetProvider() *typ.Provider
GetProvider returns the provider for this client
func (*OpenAIClient) HttpClient ¶
func (c *OpenAIClient) HttpClient() *http.Client
HttpClient returns the underlying HTTP client for passthrough/proxy operations
func (*OpenAIClient) ListModels ¶ added in v0.260204.1200
func (c *OpenAIClient) ListModels(ctx context.Context) ([]string, error)
ListModels returns the list of available models from the OpenAI-compatible API
func (*OpenAIClient) ProbeChatEndpoint ¶ added in v0.260204.1200
func (c *OpenAIClient) ProbeChatEndpoint(ctx context.Context, model string) ProbeResult
ProbeChatEndpoint tests the chat completions endpoint with a minimal request
func (*OpenAIClient) ProbeModelsEndpoint ¶ added in v0.260204.1200
func (c *OpenAIClient) ProbeModelsEndpoint(ctx context.Context) ProbeResult
ProbeModelsEndpoint tests the models list endpoint
func (*OpenAIClient) ProbeOptionsEndpoint ¶ added in v0.260204.1200
func (c *OpenAIClient) ProbeOptionsEndpoint(ctx context.Context) ProbeResult
ProbeOptionsEndpoint tests basic connectivity with an OPTIONS request
func (*OpenAIClient) ResponsesNew ¶ added in v0.260127.1200
func (c *OpenAIClient) ResponsesNew(ctx context.Context, req responses.ResponseNewParams) (*responses.Response, error)
ResponsesNew creates a new Responses API request
func (*OpenAIClient) ResponsesNewStreaming ¶ added in v0.260127.1200
func (c *OpenAIClient) ResponsesNewStreaming(ctx context.Context, req responses.ResponseNewParams) *ssestream.Stream[responses.ResponseStreamEventUnion]
ResponsesNewStreaming creates a new streaming Responses API request
func (*OpenAIClient) SetRecordSink ¶
func (c *OpenAIClient) SetRecordSink(sink *obs.Sink)
SetRecordSink sets the record sink for the client
type ProbeResult ¶ added in v0.260204.1200
type ProbeResult struct {
Success bool
Message string
Content string
LatencyMs int64
ModelsCount int
PromptTokens int
CompletionTokens int
TotalTokens int
ErrorMessage string
}
ProbeResult represents the result of a probe operation
type ProbeUsage ¶ added in v0.260204.1200
ProbeUsage represents token usage from a probe operation
type Prober ¶ added in v0.260204.1200
type Prober interface {
// ProbeChatEndpoint tests the chat/messages endpoint with a minimal request
// Returns a ProbeResult with success status, latency, and any response content
ProbeChatEndpoint(ctx context.Context, model string) ProbeResult
// ProbeModelsEndpoint tests the models list endpoint
// Returns a ProbeResult with the number of available models
ProbeModelsEndpoint(ctx context.Context) ProbeResult
// ProbeOptionsEndpoint tests basic connectivity with an OPTIONS request
// Returns a ProbeResult indicating if the endpoint is reachable
ProbeOptionsEndpoint(ctx context.Context) ProbeResult
}
Prober defines the interface for client probe capabilities
type RecordRoundTripper ¶
type RecordRoundTripper struct {
// contains filtered or unexported fields
}
RecordRoundTripper is an http.RoundTripper that records requests and responses
func NewRecordRoundTripper ¶
func NewRecordRoundTripper(transport http.RoundTripper, recordSink *obs.Sink, provider *typ.Provider) *RecordRoundTripper
NewRecordRoundTripper creates a new record round tripper
type TransportPool ¶ added in v0.260204.1200
type TransportPool struct {
// contains filtered or unexported fields
}
TransportPool manages shared HTTP transports for clients Transports are keyed by: apiBaseURL + proxyURL + oauthType This allows multiple clients to share the same connection pool when they connect to the same API endpoint through the same proxy.
func GetGlobalTransportPool ¶ added in v0.260204.1200
func GetGlobalTransportPool() *TransportPool
GetGlobalTransportPool returns the global transport pool singleton
func (*TransportPool) Clear ¶ added in v0.260204.1200
func (tp *TransportPool) Clear()
Clear removes all transports from the pool
func (*TransportPool) GetTransport ¶ added in v0.260204.1200
func (tp *TransportPool) GetTransport(apiBase, proxyURL string, oauthType oauth.ProviderType) *http.Transport
GetTransport returns or creates a shared HTTP transport for the given configuration The transport key is based on: apiBaseURL + proxyURL + oauthType
func (*TransportPool) Stats ¶ added in v0.260204.1200
func (tp *TransportPool) Stats() map[string]interface{}
Stats returns statistics about the transport pool