Documentation
¶
Index ¶
- Constants
- Variables
- func CreateHTTPClientForProvider(provider *typ.Provider, model string, sessionID typ.SessionID) *http.Clientdeprecated
- func CreateHTTPClientWithProxy(proxyURL string) *http.Client
- func GetProbeToolChoiceAutoAnthropic() anthropic.ToolChoiceUnionParam
- func GetProbeToolsAnthropic() []anthropic.ToolUnionParam
- func GetProbeToolsOpenAI() []openai.ChatCompletionToolUnionParam
- func GetProbeToolsResponses() []responses.ToolUnionParam
- func IsClaudeOAuthToken(apiKey string) bool
- func IsModelsEndpointNotSupported(err error) bool
- func NewTransportKey(providerUUID string, proxyURL string, issuer ai.Issuer, session typ.SessionID) typ.TransportKey
- func SetTransportConfig(config *TransportConfig)
- 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) Probe(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) ProbeStream(ctx context.Context, model, message string, testMode ProbeMode) (*ProbeResult, error)
- func (c *AnthropicClient) SetRecordSink(sink *obs.Sink)
- type AnthropicClientInterface
- type ClaudeClient
- func (c *ClaudeClient) APIStyle() protocol.APIStyle
- func (c *ClaudeClient) BetaMessagesCountTokens(ctx context.Context, req *anthropic.BetaMessageCountTokensParams) (*anthropic.BetaMessageTokensCount, error)
- func (c *ClaudeClient) BetaMessagesNew(ctx context.Context, req *anthropic.BetaMessageNewParams) (*anthropic.BetaMessage, error)
- func (c *ClaudeClient) BetaMessagesNewStreaming(ctx context.Context, req *anthropic.BetaMessageNewParams) *anthropicstream.Stream[anthropic.BetaRawMessageStreamEventUnion]
- func (c *ClaudeClient) Client() *anthropic.Client
- func (c *ClaudeClient) Close() error
- func (c *ClaudeClient) GetProvider() *typ.Provider
- func (c *ClaudeClient) Guard(ctx context.Context, req *anthropic.MessageNewParams) *AnthropicClient
- func (c *ClaudeClient) GuardBeta(ctx context.Context, req *anthropic.BetaMessageNewParams) *AnthropicClient
- func (c *ClaudeClient) ListModels(ctx context.Context) ([]string, error)
- func (c *ClaudeClient) MessagesCountTokens(ctx context.Context, req *anthropic.MessageCountTokensParams) (*anthropic.MessageTokensCount, error)
- func (c *ClaudeClient) MessagesNew(ctx context.Context, req *anthropic.MessageNewParams) (*anthropic.Message, error)
- func (c *ClaudeClient) MessagesNewStreaming(ctx context.Context, req *anthropic.MessageNewParams) *anthropicstream.Stream[anthropic.MessageStreamEventUnion]
- func (c *ClaudeClient) Probe(ctx context.Context, model string) ProbeResult
- func (c *ClaudeClient) ProbeStream(ctx context.Context, model, message string, testMode ProbeMode) (*ProbeResult, error)
- func (c *ClaudeClient) SetRecordSink(sink *obs.Sink)
- type ClientPool
- func (p *ClientPool) GetAnthropicClient(ctx context.Context, provider *typ.Provider, model string) AnthropicClientInterface
- func (p *ClientPool) GetGoogleClient(ctx context.Context, provider *typ.Provider, model string) *GoogleClient
- func (p *ClientPool) GetOpenAIClient(ctx context.Context, provider *typ.Provider, model string) OpenAIClientInterface
- func (p *ClientPool) GetRecordSink() *obs.Sink
- func (p *ClientPool) InvalidateProvider(providerUUID string)
- func (p *ClientPool) InvalidateSession(providerUUID, sessionID string)
- func (p *ClientPool) SetRecordSink(sink *obs.Sink)
- func (p *ClientPool) Stats() map[string]interface{}
- type ClientPoolBuilder
- type CodexClient
- func (c *CodexClient) ChatCompletionsNew(ctx context.Context, req openai.ChatCompletionNewParams) (*openai.ChatCompletion, error)
- func (c *CodexClient) ChatCompletionsNewStreaming(ctx context.Context, req openai.ChatCompletionNewParams) *ssestream.Stream[openai.ChatCompletionChunk]
- func (c *CodexClient) Client() *openai.Client
- func (c *CodexClient) ImagesGenerate(ctx context.Context, req openai.ImageGenerateParams) (*openai.ImagesResponse, error)
- func (c *CodexClient) ListModels(ctx context.Context) ([]string, error)
- func (c *CodexClient) Probe(ctx context.Context, model string) ProbeResult
- func (c *CodexClient) ProbeResponsesStream(ctx context.Context, model, message string, testMode ProbeMode) (*ProbeResult, error)
- func (c *CodexClient) ProbeStream(ctx context.Context, model, message string, testMode ProbeMode) (*ProbeResult, error)
- func (c *CodexClient) ResponsesNewStreaming(ctx context.Context, req responses.ResponseNewParams) *ssestream.Stream[responses.ResponseStreamEventUnion]
- func (c *CodexClient) SetRecordSink(sink *obs.Sink)
- type ErrCodexNotSupported
- 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) Probe(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) ProbeStream(ctx context.Context, model, message string, testMode ProbeMode) (*ProbeResult, error)
- 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) EmbeddingsNew(ctx context.Context, req openai.EmbeddingNewParams) (*openai.CreateEmbeddingResponse, error)
- func (c *OpenAIClient) GetProvider() *typ.Provider
- func (c *OpenAIClient) ImagesGenerate(ctx context.Context, req openai.ImageGenerateParams) (*openai.ImagesResponse, error)
- func (c *OpenAIClient) ListModels(ctx context.Context) ([]string, error)
- func (c *OpenAIClient) Probe(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) ProbeResponsesStream(ctx context.Context, model, message string, testMode ProbeMode) (*ProbeResult, error)
- func (c *OpenAIClient) ProbeStream(ctx context.Context, model, message string, testMode ProbeMode) (*ProbeResult, error)
- 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 OpenAIClientInterface
- type ProbeMode
- type ProbeResult
- type ProbeToolCall
- type ProbeUsage
- type Prober
- type RecordRoundTripper
- type SessionBoundTransport
- type TestTransportPool
- func (p *TestTransportPool) AcquireTransport(providerUUID, model, proxyURL string, issuer ai.Issuer, ...) (*http.Transport, func())
- func (p *TestTransportPool) Clear()
- func (p *TestTransportPool) GetTransport(providerUUID, model, proxyURL string, issuer ai.Issuer, ...) *http.Transport
- func (p *TestTransportPool) InvalidateSession(providerUUID, sessionID string)
- func (p *TestTransportPool) Keys() []string
- func (p *TestTransportPool) Stats() map[string]interface{}
- type TransportConfig
- type TransportPool
- func (tp *TransportPool) AcquireTransport(providerUUID, model, proxyURL string, issuer ai.Issuer, ...) (*http.Transport, func())
- func (tp *TransportPool) Clear()
- func (tp *TransportPool) GetTransport(providerUUID, model, proxyURL string, issuer ai.Issuer, ...) *http.Transport
- func (tp *TransportPool) InvalidateProvider(providerUUID string)
- func (tp *TransportPool) InvalidateSession(providerUUID, sessionID string)
- func (tp *TransportPool) StartCleanupTask(interval, ttl time.Duration)
- func (tp *TransportPool) Stats() map[string]interface{}
- type TransportPoolInterface
- type TransportReusePolicy
Constants ¶
const ( DefaultMaxIdleConns = 100 DefaultMaxIdleConnsPerHost = 2 )
Go defaults for reference (not used directly, only for documentation)
const ( DefaultTransportTTL = 15 * time.Minute // Default time-to-live for cached transports (reduced from 120min for better session lifecycle management) DefaultTransportCleanupInterval = 5 * time.Minute // Default interval for cleanup task )
Constants for transport TTL and cleanup interval
const ClaudeCodeSystemBody = "" /* 150-byte string literal not displayed */
const ClaudeCodeSystemHeader = "You are Claude Code, Anthropic's official CLI for Claude."
ClaudeCodeSystemHeader is a special system message for Claude Code OAuth subscriptions
const (
ProxyURLNone = "none" // Special value to force direct connection (disable proxy)
)
Constants for proxy URL values
const ScenarioContextKey contextKey = "scenario"
Variables ¶
var ProviderTransportPolicy = map[ai.Issuer]TransportReusePolicy{ ai.IssuerClaudeCode: TransportPerSession, ai.IssuerOpenAI: TransportPerSession, ai.IssuerGoogle: TransportPerSession, ai.IssuerCodex: TransportPerSession, ai.IssuerGemini: TransportPerSession, ai.IssuerGitHub: TransportPerSession, ai.IssuerQwenCode: TransportPerSession, ai.IssuerAntigravity: TransportPerSession, ai.IssuerIFlow: TransportPerSession, ai.IssuerKimiCode: TransportPerSession, ai.IssuerMock: TransportReusable, }
ProviderTransportPolicy defines transport reuse behavior per provider type OAuth providers generally require per-session transports for proper isolation
Functions ¶
func CreateHTTPClientForProvider
deprecated
func CreateHTTPClientForProvider(provider *typ.Provider, model string, sessionID typ.SessionID) *http.Client
CreateHTTPClientForProvider creates an HTTP client configured for the given provider It handles proxy and OAuth hooks if applicable The model parameter is used for transport pool keying (provider+model+proxy) The sessionID parameter is used for session-scoped transport creation for OAuth providers
Deprecated: Use createSessionBoundTransport instead. This function is kept for backward compatibility during the migration to SessionBoundTransport.
Returns a configured http.Client
func CreateHTTPClientWithProxy ¶
CreateHTTPClientWithProxy creates an HTTP client with proxy support
func GetProbeToolChoiceAutoAnthropic ¶ added in v0.260514.1
func GetProbeToolChoiceAutoAnthropic() anthropic.ToolChoiceUnionParam
GetProbeToolChoiceAutoAnthropic returns auto tool choice for testing
func GetProbeToolsAnthropic ¶ added in v0.260514.1
func GetProbeToolsAnthropic() []anthropic.ToolUnionParam
GetProbeToolsAnthropic returns predefined tools in Anthropic format for probe testing Uses bash tool to execute simple file system operations
func GetProbeToolsOpenAI ¶ added in v0.260514.1
func GetProbeToolsOpenAI() []openai.ChatCompletionToolUnionParam
GetProbeToolsOpenAI returns predefined tools in OpenAI format for probe testing Uses bash tool to execute simple file system operations
func GetProbeToolsResponses ¶ added in v0.260514.1
func GetProbeToolsResponses() []responses.ToolUnionParam
GetProbeToolsResponses returns predefined tools in Responses API format for probe testing Uses bash tool to execute simple file system operations
func IsClaudeOAuthToken ¶
IsClaudeOAuthToken checks if the given API key is a Claude OAuth token by checking for the "sk-ant-oat" prefix.
func IsModelsEndpointNotSupported ¶
IsModelsEndpointNotSupported checks if an error is ErrModelsEndpointNotSupported
func NewTransportKey ¶ added in v0.260414.2000
func NewTransportKey(providerUUID string, proxyURL string, issuer ai.Issuer, session typ.SessionID) typ.TransportKey
NewTransportKey creates a TransportKey with optional session scoping. sessionID is only included in the key when:
- issuer requires per-session transports (TransportPerSession)
- session is not empty
- session is not an IP-fallback (which would create one transport per IP)
Note: ProxyURL is NOT part of the key. Proxy is a provider configuration that affects how the transport is created, but doesn't create a separate pool.
func SetTransportConfig ¶
func SetTransportConfig(config *TransportConfig)
SetTransportConfig updates the transport pool configuration Pass nil to reset to Go defaults (backward compatible) This affects newly created transports only, existing transports are not modified
Types ¶
type AnthropicClient ¶
type AnthropicClient struct {
// contains filtered or unexported fields
}
AnthropicClient wraps the Anthropic SDK client
func NewAnthropicClient ¶
func NewAnthropicClient(provider *typ.Provider, model string, sessionID typ.SessionID, extraOptions ...anthropicOption.RequestOption) (*AnthropicClient, error)
NewAnthropicClient creates a new Anthropic client wrapper
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 ¶
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) Probe ¶ added in v0.260514.1
func (c *AnthropicClient) Probe(ctx context.Context, model string) ProbeResult
ProbeChatEndpoint tests the messages endpoint with a minimal request
func (*AnthropicClient) ProbeModelsEndpoint ¶
func (c *AnthropicClient) ProbeModelsEndpoint(ctx context.Context) ProbeResult
ProbeModelsEndpoint tests the models list endpoint
func (*AnthropicClient) ProbeOptionsEndpoint ¶
func (c *AnthropicClient) ProbeOptionsEndpoint(ctx context.Context) ProbeResult
ProbeOptionsEndpoint tests basic connectivity with an OPTIONS request
func (*AnthropicClient) ProbeStream ¶ added in v0.260514.1
func (c *AnthropicClient) ProbeStream(ctx context.Context, model, message string, testMode ProbeMode) (*ProbeResult, error)
ProbeStream performs a streaming probe with configurable test mode (public interface)
func (*AnthropicClient) SetRecordSink ¶
func (c *AnthropicClient) SetRecordSink(sink *obs.Sink)
SetRecordSink sets the record sink for the client
type AnthropicClientInterface ¶ added in v0.260514.1
type AnthropicClientInterface interface {
// Core API methods
MessagesNew(ctx context.Context, req *anthropic.MessageNewParams) (*anthropic.Message, error)
MessagesNewStreaming(ctx context.Context, req *anthropic.MessageNewParams) *anthropicstream.Stream[anthropic.MessageStreamEventUnion]
BetaMessagesNew(ctx context.Context, req *anthropic.BetaMessageNewParams) (*anthropic.BetaMessage, error)
BetaMessagesNewStreaming(ctx context.Context, req *anthropic.BetaMessageNewParams) *anthropicstream.Stream[anthropic.BetaRawMessageStreamEventUnion]
MessagesCountTokens(ctx context.Context, req *anthropic.MessageCountTokensParams) (*anthropic.MessageTokensCount, error)
BetaMessagesCountTokens(ctx context.Context, req *anthropic.BetaMessageCountTokensParams) (*anthropic.BetaMessageTokensCount, error)
// Utility methods
ListModels(ctx context.Context) ([]string, error)
Close() error
GetProvider() *typ.Provider
APIStyle() protocol.APIStyle
SetRecordSink(sink *obs.Sink)
Client() *anthropic.Client
// Prober interface methods
Probe(ctx context.Context, model string) ProbeResult
ProbeStream(ctx context.Context, model, message string, testMode ProbeMode) (*ProbeResult, error)
}
AnthropicClientInterface defines the contract for Anthropic-compatible clients. Both AnthropicClient and ClaudeClient (for Claude Code OAuth) implement this interface.
type ClaudeClient ¶ added in v0.260514.1
type ClaudeClient struct {
*AnthropicClient
}
ClaudeClient wraps AnthropicClient with Claude Code OAuth-specific behaviors. It creates an Anthropic SDK client directly with Claude Code headers and middleware, then embeds it for delegation.
Claude Code (Claude Code OAuth) limitations: - Does NOT support /models endpoint (returns 404) - Requires special headers (applied via SDK options) - Requires tool prefix stripping (applied via middleware)
func NewClaudeClient ¶ added in v0.260514.1
func NewClaudeClient(provider *typ.Provider, model string, sessionID typ.SessionID) (*ClaudeClient, error)
NewClaudeClient creates a new Claude client wrapper. It builds an Anthropic SDK client with Claude Code specific headers and middleware, then wraps it in an AnthropicClient for delegation.
func (*ClaudeClient) APIStyle ¶ added in v0.260514.1
func (c *ClaudeClient) APIStyle() protocol.APIStyle
APIStyle returns the API style.
func (*ClaudeClient) BetaMessagesCountTokens ¶ added in v0.260514.1
func (c *ClaudeClient) BetaMessagesCountTokens(ctx context.Context, req *anthropic.BetaMessageCountTokensParams) (*anthropic.BetaMessageTokensCount, error)
BetaMessagesCountTokens counts tokens for a beta message request.
func (*ClaudeClient) BetaMessagesNew ¶ added in v0.260514.1
func (c *ClaudeClient) BetaMessagesNew(ctx context.Context, req *anthropic.BetaMessageNewParams) (*anthropic.BetaMessage, error)
BetaMessagesNew creates a new beta message request.
func (*ClaudeClient) BetaMessagesNewStreaming ¶ added in v0.260514.1
func (c *ClaudeClient) BetaMessagesNewStreaming(ctx context.Context, req *anthropic.BetaMessageNewParams) *anthropicstream.Stream[anthropic.BetaRawMessageStreamEventUnion]
BetaMessagesNewStreaming creates a new beta streaming message request.
func (*ClaudeClient) Client ¶ added in v0.260514.1
func (c *ClaudeClient) Client() *anthropic.Client
Client returns the underlying Anthropic SDK client.
func (*ClaudeClient) Close ¶ added in v0.260514.1
func (c *ClaudeClient) Close() error
Close closes any resources held by the client.
func (*ClaudeClient) GetProvider ¶ added in v0.260514.1
func (c *ClaudeClient) GetProvider() *typ.Provider
GetProvider returns the provider for this client.
func (*ClaudeClient) Guard ¶ added in v0.260514.1
func (c *ClaudeClient) Guard(ctx context.Context, req *anthropic.MessageNewParams) *AnthropicClient
func (*ClaudeClient) GuardBeta ¶ added in v0.260514.1
func (c *ClaudeClient) GuardBeta(ctx context.Context, req *anthropic.BetaMessageNewParams) *AnthropicClient
func (*ClaudeClient) ListModels ¶ added in v0.260514.1
func (c *ClaudeClient) ListModels(ctx context.Context) ([]string, error)
ListModels returns the list of available models. For Claude Code OAuth, this returns an error as the token cannot access /models endpoint.
func (*ClaudeClient) MessagesCountTokens ¶ added in v0.260514.1
func (c *ClaudeClient) MessagesCountTokens(ctx context.Context, req *anthropic.MessageCountTokensParams) (*anthropic.MessageTokensCount, error)
MessagesCountTokens counts tokens for a message request.
func (*ClaudeClient) MessagesNew ¶ added in v0.260514.1
func (c *ClaudeClient) MessagesNew(ctx context.Context, req *anthropic.MessageNewParams) (*anthropic.Message, error)
MessagesNew creates a new message request.
func (*ClaudeClient) MessagesNewStreaming ¶ added in v0.260514.1
func (c *ClaudeClient) MessagesNewStreaming(ctx context.Context, req *anthropic.MessageNewParams) *anthropicstream.Stream[anthropic.MessageStreamEventUnion]
MessagesNewStreaming creates a new streaming message request.
func (*ClaudeClient) Probe ¶ added in v0.260514.1
func (c *ClaudeClient) Probe(ctx context.Context, model string) ProbeResult
ProbeChatEndpoint tests the messages endpoint.
func (*ClaudeClient) ProbeStream ¶ added in v0.260514.1
func (c *ClaudeClient) ProbeStream(ctx context.Context, model, message string, testMode ProbeMode) (*ProbeResult, error)
ProbeStream performs a streaming probe with configurable test mode for Claude Code OAuth. This uses the ClaudeClient's own MessagesNewStreaming method which properly applies: - Beta headers (only for probe operations) - Thinking field disabling - Session ID injection via Guard pattern
Note: Beta headers are ONLY applied during probe, not during normal message passing.
func (*ClaudeClient) SetRecordSink ¶ added in v0.260514.1
func (c *ClaudeClient) SetRecordSink(sink *obs.Sink)
SetRecordSink sets the record sink for the client.
type ClientPool ¶
type ClientPool struct {
// contains filtered or unexported fields
}
ClientPool manages client instances for different providers. With SessionBoundTransport, connection pooling is handled at the Transport layer, so ClientPool simply creates new client instances as needed.
Transports are automatically shared via TransportPool based on:
providerUUID + sessionID (for OAuth providers)
ProxyURL is used to configure the transport but is NOT part of the key.
Clients are automatically cleaned up via finalizers when garbage collected.
func NewClientPool ¶
func NewClientPool() *ClientPool
NewClientPool creates a new ClientPool with default settings.
func (*ClientPool) GetAnthropicClient ¶
func (p *ClientPool) GetAnthropicClient(ctx context.Context, provider *typ.Provider, model string) AnthropicClientInterface
GetAnthropicClient returns an Anthropic client wrapper for the specified provider. For Claude Code OAuth providers, returns a ClaudeClient with special handling. sessionID is resolved from ctx via typ.GetSessionID; pass context.Background() when no session is available.
func (*ClientPool) GetGoogleClient ¶
func (p *ClientPool) GetGoogleClient(ctx context.Context, provider *typ.Provider, model string) *GoogleClient
GetGoogleClient returns a Google client wrapper for the specified provider. sessionID is resolved from ctx via typ.GetSessionID; pass context.Background() when no session is available.
func (*ClientPool) GetOpenAIClient ¶
func (p *ClientPool) GetOpenAIClient(ctx context.Context, provider *typ.Provider, model string) OpenAIClientInterface
GetOpenAIClient returns an OpenAI client wrapper for the specified provider. For Codex OAuth providers, returns a CodexClient with special handling. sessionID is resolved from ctx via typ.GetSessionID; pass context.Background() when no session is available.
func (*ClientPool) GetRecordSink ¶
func (p *ClientPool) GetRecordSink() *obs.Sink
GetRecordSink returns the record sink.
func (*ClientPool) InvalidateProvider ¶
func (p *ClientPool) InvalidateProvider(providerUUID string)
InvalidateProvider invalidates all transports for a specific provider UUID. This should be called when provider credentials are updated (e.g., OAuth token refresh).
Note: Since ClientPool no longer caches clients, this only invalidates the TransportPool entries. Client instances will be garbage collected naturally.
func (*ClientPool) InvalidateSession ¶ added in v0.260409.1540
func (p *ClientPool) InvalidateSession(providerUUID, sessionID string)
InvalidateSession invalidates transports for a specific session. This is useful when a session ends or its OAuth token is revoked.
Note: Since ClientPool no longer caches clients, this only invalidates the TransportPool entries. Client instances will be garbage collected naturally.
func (*ClientPool) SetRecordSink ¶
func (p *ClientPool) SetRecordSink(sink *obs.Sink)
SetRecordSink sets the record sink for the client pool. Note: This only affects newly created clients, not existing ones.
func (*ClientPool) Stats ¶
func (p *ClientPool) Stats() map[string]interface{}
Stats provides statistics about the client pool and transport pool.
type ClientPoolBuilder ¶
type ClientPoolBuilder struct {
// contains filtered or unexported fields
}
ClientPoolBuilder builds a ClientPool with specified configuration.
func NewClientPoolBuilder ¶
func NewClientPoolBuilder() *ClientPoolBuilder
NewClientPoolBuilder creates a new builder with default settings.
func (*ClientPoolBuilder) Build ¶
func (b *ClientPoolBuilder) Build() *ClientPool
Build creates the ClientPool with configured settings.
func (*ClientPoolBuilder) WithRecordSink ¶
func (b *ClientPoolBuilder) WithRecordSink(sink *obs.Sink) *ClientPoolBuilder
WithRecordSink sets the record sink for all clients.
type CodexClient ¶ added in v0.260514.1
type CodexClient struct {
*OpenAIClient
}
CodexClient wraps OpenAIClient with Codex-specific behaviors. It embeds OpenAIClient to inherit standard OpenAI API functionality, while overriding methods that require special handling for ChatGPT backend API.
Codex (ChatGPT OAuth) limitations: - Does NOT support standard Chat Completions API - Does NOT support /models endpoint - Does NOT support /images/generations endpoint - ONLY supports Responses API with special parameters
func NewCodexClient ¶ added in v0.260514.1
func NewCodexClient(provider *typ.Provider, model string, sessionID typ.SessionID) (*CodexClient, error)
NewCodexClient creates a new Codex client wrapper. The base OpenAIClient is configured with codexRoundTripper for path/header transformation.
func (*CodexClient) ChatCompletionsNew ¶ added in v0.260514.1
func (c *CodexClient) ChatCompletionsNew(ctx context.Context, req openai.ChatCompletionNewParams) (*openai.ChatCompletion, error)
ChatCompletionsNew creates a new chat completion request. For Codex, this returns an error as ChatGPT backend API does not support standard Chat Completions. Use Responses API instead.
func (*CodexClient) ChatCompletionsNewStreaming ¶ added in v0.260514.1
func (c *CodexClient) ChatCompletionsNewStreaming(ctx context.Context, req openai.ChatCompletionNewParams) *ssestream.Stream[openai.ChatCompletionChunk]
ChatCompletionsNewStreaming creates a new streaming chat completion request. For Codex, this returns nil as ChatGPT backend API does not support standard Chat Completions. Use Responses API instead.
func (*CodexClient) Client ¶ added in v0.260514.1
func (c *CodexClient) Client() *openai.Client
Client returns the underlying OpenAI SDK client. For CodexClient, we delegate to the embedded OpenAIClient.
func (*CodexClient) ImagesGenerate ¶ added in v0.260514.1
func (c *CodexClient) ImagesGenerate(ctx context.Context, req openai.ImageGenerateParams) (*openai.ImagesResponse, error)
ImagesGenerate creates a new image generation request. For Codex, this transforms the request to use the Responses API with the image_generation tool, as ChatGPT backend API does not support the standard /images/generations endpoint.
func (*CodexClient) ListModels ¶ added in v0.260514.1
func (c *CodexClient) ListModels(ctx context.Context) ([]string, error)
ListModels returns the list of available models. For Codex, this returns an error as ChatGPT OAuth tokens cannot access /models endpoint.
func (*CodexClient) Probe ¶ added in v0.260514.1
func (c *CodexClient) Probe(ctx context.Context, model string) ProbeResult
ProbeChatEndpoint tests the chat endpoint. For Codex, this delegates to the embedded OpenAIClient's probeResponsesEndpoint.
func (*CodexClient) ProbeResponsesStream ¶ added in v0.260514.1
func (c *CodexClient) ProbeResponsesStream(ctx context.Context, model, message string, testMode ProbeMode) (*ProbeResult, error)
func (*CodexClient) ProbeStream ¶ added in v0.260514.1
func (c *CodexClient) ProbeStream(ctx context.Context, model, message string, testMode ProbeMode) (*ProbeResult, error)
ProbeStream performs a streaming probe with configurable test mode (public interface) Codex uses the Responses API with proper beta headers
func (*CodexClient) ResponsesNewStreaming ¶ added in v0.260514.1
func (c *CodexClient) ResponsesNewStreaming(ctx context.Context, req responses.ResponseNewParams) *ssestream.Stream[responses.ResponseStreamEventUnion]
ResponsesNewStreaming creates a new streaming Responses API request with Codex-specific defaults.
func (*CodexClient) SetRecordSink ¶ added in v0.260514.1
func (c *CodexClient) SetRecordSink(sink *obs.Sink)
SetRecordSink sets the record sink for the client. For CodexClient, we delegate to the embedded OpenAIClient.
type ErrCodexNotSupported ¶ added in v0.260514.1
ErrCodexNotSupported is returned when attempting to use an OpenAI API that is not supported by Codex
func (*ErrCodexNotSupported) Error ¶ added in v0.260514.1
func (e *ErrCodexNotSupported) Error() string
type ErrModelsEndpointNotSupported ¶
ErrModelsEndpointNotSupported is returned when the provider does not support the models endpoint
func (*ErrModelsEndpointNotSupported) Error ¶
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, model string, sessionID typ.SessionID) (*GoogleClient, error)
NewGoogleClient creates a new Google client wrapper sessionID is used for session-scoped transport creation for OAuth providers
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 ¶
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) Probe ¶ added in v0.260514.1
func (c *GoogleClient) Probe(ctx context.Context, model string) ProbeResult
ProbeChatEndpoint tests the chat endpoint with a minimal request
func (*GoogleClient) ProbeModelsEndpoint ¶
func (c *GoogleClient) ProbeModelsEndpoint(ctx context.Context) ProbeResult
ProbeModelsEndpoint tests the models list endpoint
func (*GoogleClient) ProbeOptionsEndpoint ¶
func (c *GoogleClient) ProbeOptionsEndpoint(ctx context.Context) ProbeResult
ProbeOptionsEndpoint tests basic connectivity with an OPTIONS request
func (*GoogleClient) ProbeStream ¶ added in v0.260514.1
func (c *GoogleClient) ProbeStream(ctx context.Context, model, message string, testMode ProbeMode) (*ProbeResult, error)
ProbeStream performs a streaming probe with configurable test mode (public interface)
func (*GoogleClient) SetRecordSink ¶
func (c *GoogleClient) SetRecordSink(sink *obs.Sink)
SetRecordSink sets the record sink for the client
type ModelLister ¶
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 ¶
OpenAIClient wraps the OpenAI SDK client
func NewOpenAIClient ¶
func NewOpenAIClient(provider *typ.Provider, model string, sessionID typ.SessionID, extraOptions ...option.RequestOption) (*OpenAIClient, error)
NewOpenAIClient creates a new OpenAI client wrapper
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) EmbeddingsNew ¶ added in v0.260507.1
func (c *OpenAIClient) EmbeddingsNew(ctx context.Context, req openai.EmbeddingNewParams) (*openai.CreateEmbeddingResponse, error)
EmbeddingsNew creates a new embeddings request
func (*OpenAIClient) GetProvider ¶
func (c *OpenAIClient) GetProvider() *typ.Provider
GetProvider returns the provider for this client
func (*OpenAIClient) ImagesGenerate ¶ added in v0.260514.1
func (c *OpenAIClient) ImagesGenerate(ctx context.Context, req openai.ImageGenerateParams) (*openai.ImagesResponse, error)
ImagesGenerate creates a new image generation request
func (*OpenAIClient) ListModels ¶
func (c *OpenAIClient) ListModels(ctx context.Context) ([]string, error)
ListModels returns the list of available models from the OpenAI-compatible API
func (*OpenAIClient) Probe ¶ added in v0.260514.1
func (c *OpenAIClient) Probe(ctx context.Context, model string) ProbeResult
ProbeChatEndpoint tests the chat completions endpoint with a minimal request
func (*OpenAIClient) ProbeModelsEndpoint ¶
func (c *OpenAIClient) ProbeModelsEndpoint(ctx context.Context) ProbeResult
ProbeModelsEndpoint tests the models list endpoint
func (*OpenAIClient) ProbeOptionsEndpoint ¶
func (c *OpenAIClient) ProbeOptionsEndpoint(ctx context.Context) ProbeResult
ProbeOptionsEndpoint tests basic connectivity with an OPTIONS request
func (*OpenAIClient) ProbeResponsesStream ¶ added in v0.260514.1
func (c *OpenAIClient) ProbeResponsesStream(ctx context.Context, model, message string, testMode ProbeMode) (*ProbeResult, error)
ProbeResponsesStream performs a streaming probe using Responses API (for Codex)
func (*OpenAIClient) ProbeStream ¶ added in v0.260514.1
func (c *OpenAIClient) ProbeStream(ctx context.Context, model, message string, testMode ProbeMode) (*ProbeResult, error)
ProbeStream performs a streaming probe with configurable test mode (public interface)
func (*OpenAIClient) ResponsesNew ¶
func (c *OpenAIClient) ResponsesNew(ctx context.Context, req responses.ResponseNewParams) (*responses.Response, error)
ResponsesNew creates a new Responses API request
func (*OpenAIClient) ResponsesNewStreaming ¶
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 OpenAIClientInterface ¶ added in v0.260514.1
type OpenAIClientInterface interface {
// Core API methods
ChatCompletionsNew(ctx context.Context, req openai.ChatCompletionNewParams) (*openai.ChatCompletion, error)
ChatCompletionsNewStreaming(ctx context.Context, req openai.ChatCompletionNewParams) *ssestream.Stream[openai.ChatCompletionChunk]
ImagesGenerate(ctx context.Context, req openai.ImageGenerateParams) (*openai.ImagesResponse, error)
ResponsesNew(ctx context.Context, req responses.ResponseNewParams) (*responses.Response, error)
ResponsesNewStreaming(ctx context.Context, req responses.ResponseNewParams) *ssestream.Stream[responses.ResponseStreamEventUnion]
EmbeddingsNew(ctx context.Context, req openai.EmbeddingNewParams) (*openai.CreateEmbeddingResponse, error)
// Utility methods
ListModels(ctx context.Context) ([]string, error)
Close() error
GetProvider() *typ.Provider
APIStyle() protocol.APIStyle
SetRecordSink(sink *obs.Sink)
// Prober interface methods
Probe(ctx context.Context, model string) ProbeResult
ProbeStream(ctx context.Context, model, message string, testMode ProbeMode) (*ProbeResult, error)
ProbeResponsesStream(ctx context.Context, model, message string, testMode ProbeMode) (*ProbeResult, error)
// Client returns the underlying OpenAI SDK client (for advanced usage)
Client() *openai.Client
}
OpenAIClientInterface defines the contract for OpenAI-compatible clients. Both OpenAIClient and CodexClient implement this interface.
type ProbeMode ¶ added in v0.260514.1
type ProbeMode string
ProbeMode defines the test mode for probeStream
type ProbeResult ¶
type ProbeResult struct {
// Basic fields
Success bool `json:"success"`
Message string `json:"message,omitempty"`
Content string `json:"content,omitempty"`
LatencyMs int64 `json:"latency_ms"`
ModelsCount int `json:"models_count,omitempty"`
ErrorMessage string `json:"error_message,omitempty"`
// Streaming mode indicator
Stream bool `json:"stream,omitempty"`
// Token usage
PromptTokens int `json:"prompt_tokens,omitempty"`
CompletionTokens int `json:"completion_tokens,omitempty"`
TotalTokens int `json:"total_tokens,omitempty"`
// Tool calls (for tool mode)
ToolCalls []ProbeToolCall `json:"tool_calls,omitempty"`
// Request URL (for debugging)
RequestURL string `json:"request_url,omitempty"`
}
ProbeResult represents the result of a probe operation (for both simple and streaming)
func ToProbeResult ¶ added in v0.260514.1
func ToProbeResult(content string, latencyMs int64, requestURL string, isStreaming bool) *ProbeResult
ToProbeResult creates a ProbeResult with basic fields
type ProbeToolCall ¶ added in v0.260514.1
type ProbeToolCall struct {
ID string `json:"id"`
Name string `json:"name"`
Input map[string]interface{} `json:"input"`
}
ProbeToolCall represents a tool call in probe response
type ProbeUsage ¶
ProbeUsage represents token usage from a probe operation
type Prober ¶
type Prober interface {
// Probe tests the chat/messages endpoint with a minimal request
// Returns a ProbeResult with success status, latency, and any response content
Probe(ctx context.Context, model string) ProbeResult
// ProbeStream performs a streaming probe with configurable test mode
// Returns ProbeResult with streaming content, tool calls, usage, and latency
ProbeStream(ctx context.Context, model, message string, testMode ProbeMode) (*ProbeResult, error)
}
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 SessionBoundTransport ¶ added in v0.260414.2000
type SessionBoundTransport struct {
// contains filtered or unexported fields
}
SessionBoundTransport is a RoundTripper that binds to a specific session. It stores the sessionID and routes all requests through that session's transport. This enables session-scoped transport isolation while keeping the http.Client as a lightweight, stateless shell.
type TestTransportPool ¶ added in v0.260414.2000
type TestTransportPool struct {
// contains filtered or unexported fields
}
TestTransportPool is a test double for TransportPool that tracks which transport keys were requested.
func NewTestTransportPool ¶ added in v0.260414.2000
func NewTestTransportPool() *TestTransportPool
NewTestTransportPool creates a new test transport pool.
func (*TestTransportPool) AcquireTransport ¶ added in v0.260423.0
func (p *TestTransportPool) AcquireTransport(providerUUID, model, proxyURL string, issuer ai.Issuer, sessionID typ.SessionID) (*http.Transport, func())
AcquireTransport returns a transport for the given configuration. The release function is a no-op for tests (no reference counting).
func (*TestTransportPool) Clear ¶ added in v0.260414.2000
func (p *TestTransportPool) Clear()
Clear clears all transports and keys.
func (*TestTransportPool) GetTransport ¶ added in v0.260414.2000
func (p *TestTransportPool) GetTransport(providerUUID, model, proxyURL string, issuer ai.Issuer, sessionID typ.SessionID) *http.Transport
GetTransport returns or creates a transport for the given configuration. It tracks the key for test verification.
func (*TestTransportPool) InvalidateSession ¶ added in v0.260414.2000
func (p *TestTransportPool) InvalidateSession(providerUUID, sessionID string)
InvalidateSession is a no-op for tests (unless specifically needed).
func (*TestTransportPool) Keys ¶ added in v0.260414.2000
func (p *TestTransportPool) Keys() []string
Keys returns all transport keys that were requested.
func (*TestTransportPool) Stats ¶ added in v0.260414.2000
func (p *TestTransportPool) Stats() map[string]interface{}
Stats returns statistics about the transport pool.
type TransportConfig ¶
type TransportConfig struct {
MaxIdleConns *int // nil = use Go default (100)
MaxIdleConnsPerHost *int // nil = use Go default (2)
MaxConnsPerHost *int // nil = use Go default (0, no limit)
DisableKeepAlives *bool // nil = use Go default (false)
// RespectEnvProxy controls whether providers without explicit proxy configuration
// should use environment/system proxy settings (HTTP_PROXY, HTTPS_PROXY, macOS system proxy, etc.)
// Default (nil): false - providers without proxy_url connect directly
// Set to true: providers without proxy_url will use system/environment proxy
RespectEnvProxy *bool // nil = use default (false)
}
TransportConfig holds the configuration for HTTP transport connection pooling All fields are pointers so that zero-value (nil) means "use Go default"
type TransportPool ¶
type TransportPool struct {
// contains filtered or unexported fields
}
TransportPool manages shared HTTP transports for clients Transports are keyed by: providerUUID + sessionID (for OAuth providers) This allows multiple clients to share the same connection pool when they use the same provider+session combination. For OAuth providers, transports are session-scoped to prevent cross-session contamination.
Note: ProxyURL is NOT part of the transport key. It's used to configure how the transport is created, but doesn't create a separate pool.
func GetGlobalTransportPool ¶
func GetGlobalTransportPool() *TransportPool
GetGlobalTransportPool returns the global transport pool singleton
func (*TransportPool) AcquireTransport ¶ added in v0.260423.0
func (tp *TransportPool) AcquireTransport(providerUUID, model, proxyURL string, issuer ai.Issuer, sessionID typ.SessionID) (*http.Transport, func())
AcquireTransport returns a transport for the given configuration and increments its reference count. The caller MUST call the returned release function exactly once when the request is complete (typically by wrapping the response body). This prevents the cleanup task from evicting a transport that has active in-flight requests.
func (*TransportPool) Clear ¶
func (tp *TransportPool) Clear()
Clear removes all transports from the pool and closes idle connections. Transports with active in-flight requests (refCount > 0) are marked for deferred removal (lastAccess set to epoch) and will be cleaned up on the next cycle after their requests complete.
func (*TransportPool) GetTransport ¶
func (tp *TransportPool) GetTransport(providerUUID, model, proxyURL string, issuer ai.Issuer, sessionID typ.SessionID) *http.Transport
GetTransport returns or creates a shared HTTP transport for the given configuration. The transport key is based on: providerUUID + sessionID (for OAuth providers). proxyURL is used to configure the transport but is NOT part of the key. sessionID is used to scope transports for OAuth providers that require per-session isolation.
Note: For in-flight request tracking (preventing cleanup of active transports), use AcquireTransport instead.
func (*TransportPool) InvalidateProvider ¶ added in v0.260414.2000
func (tp *TransportPool) InvalidateProvider(providerUUID string)
InvalidateProvider removes all transports associated with a specific provider UUID. This should be called when provider credentials are updated (e.g., OAuth token refresh). Transports with active requests are marked for deferred removal.
func (*TransportPool) InvalidateSession ¶ added in v0.260414.2000
func (tp *TransportPool) InvalidateSession(providerUUID, sessionID string)
InvalidateSession removes all transports associated with a specific session for a provider. This should be called when a session ends or its OAuth token is revoked. Transports with active requests are marked for deferred removal.
func (*TransportPool) StartCleanupTask ¶
func (tp *TransportPool) StartCleanupTask(interval, ttl time.Duration)
StartCleanupTask starts a periodic cleanup task that removes expired transports
func (*TransportPool) Stats ¶
func (tp *TransportPool) Stats() map[string]interface{}
Stats returns statistics about the transport pool
type TransportPoolInterface ¶ added in v0.260414.2000
type TransportPoolInterface interface {
GetTransport(providerUUID, model, proxyURL string, issuer ai.Issuer, sessionID typ.SessionID) *http.Transport
AcquireTransport(providerUUID, model, proxyURL string, issuer ai.Issuer, sessionID typ.SessionID) (*http.Transport, func())
}
TransportPoolInterface defines the interface for transport pools. This allows both the real TransportPool and test doubles to be used.
type TransportReusePolicy ¶ added in v0.260414.2000
type TransportReusePolicy string
TransportReusePolicy defines whether transports can be shared across sessions
const ( // TransportReusable - transport can be shared across sessions (API-key providers) TransportReusable TransportReusePolicy = "reusable" // TransportPerSession - each session needs its own transport (OAuth providers) TransportPerSession TransportReusePolicy = "per_session" )
func GetTransportReusePolicy ¶ added in v0.260414.2000
func GetTransportReusePolicy(issuer ai.Issuer) TransportReusePolicy
GetTransportReusePolicy returns the transport reuse policy for a provider type Returns TransportPerSession for unknown provider types (safer default)