providers

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 11, 2026 License: MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClearProviderAPICooldown

func ClearProviderAPICooldown(providerName string)

func ClearProviderRuntimeHistory

func ClearProviderRuntimeHistory(providerName string)

func ConfigureProviderRuntime

func ConfigureProviderRuntime(providerName string, pc config.ProviderConfig)

func CreateProviders

func CreateProviders(cfg *config.Config) (map[string]LLMProvider, error)

func GetProviderModels

func GetProviderModels(cfg *config.Config, name string) []string

func GetProviderRuntimeSnapshot

func GetProviderRuntimeSnapshot(cfg *config.Config) map[string]interface{}

func GetProviderRuntimeView

func GetProviderRuntimeView(cfg *config.Config, query ProviderRuntimeQuery) map[string]interface{}

func ListProviderNames

func ListProviderNames(cfg *config.Config) []string

func ProviderSupportsResponsesCompact

func ProviderSupportsResponsesCompact(cfg *config.Config, name string) bool

func RerankProviderRuntime

func RerankProviderRuntime(cfg *config.Config, providerName string) ([]providerRuntimeCandidate, error)

Types

type FunctionCall

type FunctionCall struct {
	Name      string `json:"name"`
	Arguments string `json:"arguments"`
}

type HTTPProvider

type HTTPProvider struct {
	// contains filtered or unexported fields
}

func NewHTTPProvider

func NewHTTPProvider(providerName, apiKey, apiBase, defaultModel string, supportsResponsesCompact bool, authMode string, timeout time.Duration, oauth *oauthManager) *HTTPProvider

func (*HTTPProvider) BuildSummaryViaResponsesCompact

func (p *HTTPProvider) BuildSummaryViaResponsesCompact(ctx context.Context, model string, existingSummary string, messages []Message, maxSummaryChars int) (string, error)

func (*HTTPProvider) Chat

func (p *HTTPProvider) Chat(ctx context.Context, messages []Message, tools []ToolDefinition, model string, options map[string]interface{}) (*LLMResponse, error)

func (*HTTPProvider) ChatStream

func (p *HTTPProvider) ChatStream(ctx context.Context, messages []Message, tools []ToolDefinition, model string, options map[string]interface{}, onDelta func(string)) (*LLMResponse, error)

func (*HTTPProvider) GetDefaultModel

func (p *HTTPProvider) GetDefaultModel() string

func (*HTTPProvider) SupportsResponsesCompact

func (p *HTTPProvider) SupportsResponsesCompact() bool

type LLMProvider

type LLMProvider interface {
	Chat(ctx context.Context, messages []Message, tools []ToolDefinition, model string, options map[string]interface{}) (*LLMResponse, error)
	GetDefaultModel() string
}

func CreateProvider

func CreateProvider(cfg *config.Config) (LLMProvider, error)

func CreateProviderByName

func CreateProviderByName(cfg *config.Config, name string) (LLMProvider, error)

type LLMResponse

type LLMResponse struct {
	Content      string     `json:"content"`
	ToolCalls    []ToolCall `json:"tool_calls,omitempty"`
	FinishReason string     `json:"finish_reason"`
	Usage        *UsageInfo `json:"usage,omitempty"`
}

type Message

type Message struct {
	Role         string               `json:"role"`
	Content      string               `json:"content"`
	ContentParts []MessageContentPart `json:"content_parts,omitempty"`
	ToolCalls    []ToolCall           `json:"tool_calls,omitempty"`
	ToolCallID   string               `json:"tool_call_id,omitempty"`
}

type MessageContentPart

type MessageContentPart struct {
	Type     string `json:"type"`
	Text     string `json:"text,omitempty"`
	ImageURL string `json:"image_url,omitempty"`
	Detail   string `json:"detail,omitempty"`
	MIMEType string `json:"mime_type,omitempty"`
	Filename string `json:"filename,omitempty"`
	FileData string `json:"file_data,omitempty"`
	FileID   string `json:"file_id,omitempty"`
	FileURL  string `json:"file_url,omitempty"`
}

type OAuthAccountInfo

type OAuthAccountInfo struct {
	Email          string `json:"email"`
	AccountID      string `json:"account_id"`
	CredentialFile string `json:"credential_file"`
	Expire         string `json:"expire,omitempty"`
	LastRefresh    string `json:"last_refresh,omitempty"`
	ProjectID      string `json:"project_id,omitempty"`
	AccountLabel   string `json:"account_label,omitempty"`
	DeviceID       string `json:"device_id,omitempty"`
	ResourceURL    string `json:"resource_url,omitempty"`
	NetworkProxy   string `json:"network_proxy,omitempty"`
	CooldownUntil  string `json:"cooldown_until,omitempty"`
	FailureCount   int    `json:"failure_count,omitempty"`
	LastFailure    string `json:"last_failure,omitempty"`
	HealthScore    int    `json:"health_score,omitempty"`
}

type OAuthLoginManager

type OAuthLoginManager struct {
	// contains filtered or unexported fields
}

func NewOAuthLoginManager

func NewOAuthLoginManager(pc config.ProviderConfig, timeout time.Duration) (*OAuthLoginManager, error)

func (*OAuthLoginManager) ClearCooldown

func (m *OAuthLoginManager) ClearCooldown(credentialFile string) error

func (*OAuthLoginManager) CompleteManualFlow

func (m *OAuthLoginManager) CompleteManualFlow(ctx context.Context, apiBase string, flow *OAuthPendingFlow, callbackURL string) (*OAuthSessionInfo, []string, error)

func (*OAuthLoginManager) CompleteManualFlowWithOptions

func (m *OAuthLoginManager) CompleteManualFlowWithOptions(ctx context.Context, apiBase string, flow *OAuthPendingFlow, callbackURL string, opts OAuthLoginOptions) (*OAuthSessionInfo, []string, error)

func (*OAuthLoginManager) CredentialFile

func (m *OAuthLoginManager) CredentialFile() string

func (*OAuthLoginManager) DeleteAccount

func (m *OAuthLoginManager) DeleteAccount(credentialFile string) error

func (*OAuthLoginManager) ImportAuthJSON

func (m *OAuthLoginManager) ImportAuthJSON(ctx context.Context, apiBase string, fileName string, data []byte) (*OAuthSessionInfo, []string, error)

func (*OAuthLoginManager) ImportAuthJSONWithOptions

func (m *OAuthLoginManager) ImportAuthJSONWithOptions(ctx context.Context, apiBase string, fileName string, data []byte, opts OAuthLoginOptions) (*OAuthSessionInfo, []string, error)

func (*OAuthLoginManager) ListAccounts

func (m *OAuthLoginManager) ListAccounts() ([]OAuthAccountInfo, error)

func (*OAuthLoginManager) Login

func (*OAuthLoginManager) RefreshAccount

func (m *OAuthLoginManager) RefreshAccount(ctx context.Context, credentialFile string) (*OAuthAccountInfo, error)

func (*OAuthLoginManager) StartManualFlow

func (m *OAuthLoginManager) StartManualFlow() (*OAuthPendingFlow, error)

func (*OAuthLoginManager) StartManualFlowWithOptions

func (m *OAuthLoginManager) StartManualFlowWithOptions(opts OAuthLoginOptions) (*OAuthPendingFlow, error)

type OAuthLoginOptions

type OAuthLoginOptions struct {
	Manual       bool
	NoBrowser    bool
	Reader       io.Reader
	AccountLabel string
	NetworkProxy string
}

type OAuthPendingFlow

type OAuthPendingFlow struct {
	Mode         string `json:"mode,omitempty"`
	State        string `json:"state,omitempty"`
	PKCEVerifier string `json:"pkce_verifier,omitempty"`
	AuthURL      string `json:"auth_url,omitempty"`
	UserCode     string `json:"user_code,omitempty"`
	Instructions string `json:"instructions,omitempty"`
	DeviceCode   string `json:"device_code,omitempty"`
	IntervalSec  int    `json:"interval_sec,omitempty"`
	ExpiresAt    string `json:"expires_at,omitempty"`
}

type OAuthSessionInfo

type OAuthSessionInfo struct {
	Email          string
	AccountID      string
	CredentialFile string
	ProjectID      string
	AccountLabel   string
	NetworkProxy   string
}

type ProviderRefreshAccountResult

type ProviderRefreshAccountResult struct {
	Target string `json:"target,omitempty"`
	Status string `json:"status,omitempty"`
	Detail string `json:"detail,omitempty"`
	Expire string `json:"expire,omitempty"`
}

type ProviderRefreshResult

type ProviderRefreshResult struct {
	Provider  string                         `json:"provider,omitempty"`
	Checked   int                            `json:"checked,omitempty"`
	Refreshed int                            `json:"refreshed,omitempty"`
	Skipped   int                            `json:"skipped,omitempty"`
	Failed    int                            `json:"failed,omitempty"`
	Accounts  []ProviderRefreshAccountResult `json:"accounts,omitempty"`
}

func RefreshProviderRuntimeNow

func RefreshProviderRuntimeNow(cfg *config.Config, providerName string, onlyExpiring bool) (*ProviderRefreshResult, error)

type ProviderRuntimeQuery

type ProviderRuntimeQuery struct {
	Provider       string
	Window         time.Duration
	EventKind      string
	Reason         string
	Target         string
	Limit          int
	Cursor         int
	HealthBelow    int
	CooldownBefore time.Time
	Sort           string
	ChangesOnly    bool
}

type ProviderRuntimeSummary

type ProviderRuntimeSummary struct {
	TotalProviders int                          `json:"total_providers"`
	Healthy        int                          `json:"healthy"`
	Degraded       int                          `json:"degraded"`
	Critical       int                          `json:"critical"`
	InCooldown     int                          `json:"in_cooldown"`
	LowHealth      int                          `json:"low_health"`
	RecentErrors   int                          `json:"recent_errors"`
	Providers      []ProviderRuntimeSummaryItem `json:"providers,omitempty"`
}

func GetProviderRuntimeSummary

func GetProviderRuntimeSummary(cfg *config.Config, query ProviderRuntimeQuery) ProviderRuntimeSummary

type ProviderRuntimeSummaryItem

type ProviderRuntimeSummaryItem struct {
	Name                  string                     `json:"name,omitempty"`
	Auth                  string                     `json:"auth,omitempty"`
	Status                string                     `json:"status,omitempty"`
	APIState              providerAPIRuntimeState    `json:"api_state,omitempty"`
	OAuthAccounts         []OAuthAccountInfo         `json:"oauth_accounts,omitempty"`
	CandidateOrder        []providerRuntimeCandidate `json:"candidate_order,omitempty"`
	LastSuccess           *providerRuntimeEvent      `json:"last_success,omitempty"`
	LastSuccessAt         string                     `json:"last_success_at,omitempty"`
	LastError             *providerRuntimeEvent      `json:"last_error,omitempty"`
	LastErrorAt           string                     `json:"last_error_at,omitempty"`
	LastErrorReason       string                     `json:"last_error_reason,omitempty"`
	TopCandidateChangedAt string                     `json:"top_candidate_changed_at,omitempty"`
	StaleForSec           int64                      `json:"stale_for_sec,omitempty"`
	InCooldown            bool                       `json:"in_cooldown"`
	LowHealth             bool                       `json:"low_health"`
	HasRecentErrors       bool                       `json:"has_recent_errors"`
	TopCandidate          *providerRuntimeCandidate  `json:"top_candidate,omitempty"`
}

type ResponsesCompactor

type ResponsesCompactor interface {
	SupportsResponsesCompact() bool
	BuildSummaryViaResponsesCompact(ctx context.Context, model string, existingSummary string, messages []Message, maxSummaryChars int) (string, error)
}

ResponsesCompactor is an optional capability interface. Providers that support OpenAI /v1/responses/compact can implement this.

type StreamingLLMProvider

type StreamingLLMProvider interface {
	ChatStream(ctx context.Context, messages []Message, tools []ToolDefinition, model string, options map[string]interface{}, onDelta func(string)) (*LLMResponse, error)
}

StreamingLLMProvider is an optional capability interface for token-level streaming.

type ToolCall

type ToolCall struct {
	ID        string                 `json:"id"`
	Type      string                 `json:"type,omitempty"`
	Function  *FunctionCall          `json:"function,omitempty"`
	Name      string                 `json:"name,omitempty"`
	Arguments map[string]interface{} `json:"arguments,omitempty"`
}

type ToolDefinition

type ToolDefinition struct {
	Type        string                 `json:"type"`
	Name        string                 `json:"name,omitempty"`
	Description string                 `json:"description,omitempty"`
	Parameters  map[string]interface{} `json:"parameters,omitempty"`
	Strict      *bool                  `json:"strict,omitempty"`
	Function    ToolFunctionDefinition `json:"function"`
}

type ToolFunctionDefinition

type ToolFunctionDefinition struct {
	Name        string                 `json:"name"`
	Description string                 `json:"description"`
	Parameters  map[string]interface{} `json:"parameters"`
	Strict      *bool                  `json:"strict,omitempty"`
}

type UsageInfo

type UsageInfo struct {
	PromptTokens     int `json:"prompt_tokens"`
	CompletionTokens int `json:"completion_tokens"`
	TotalTokens      int `json:"total_tokens"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL