typ

package
v0.260317.0-preview Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2026 License: MPL-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

ThinkingBudgetMapping defines budget_tokens for each effort level Note: Default max is 31,999 tokens per Claude Code documentation

Functions

func ApplyToolInterceptorDefaults

func ApplyToolInterceptorDefaults(config *ToolInterceptorConfig)

ApplyToolInterceptorDefaults applies default values to tool interceptor config

func IsValidTactic

func IsValidTactic(tacticStr string) bool

IsValidTactic checks if the given tactic string is valid

Types

type AuthType

type AuthType string

AuthType represents the authentication type for a provider

const (
	AuthTypeAPIKey AuthType = "api_key"
	AuthTypeOAuth  AuthType = "oauth"
)

type DiscoveryResult

type DiscoveryResult struct {
	TotalIdesScanned int             `json:"total_ides_scanned"`
	IdesFound        []IDESource     `json:"ides_found"`
	SkillsFound      int             `json:"skills_found"`
	Locations        []SkillLocation `json:"locations"`
}

DiscoveryResult represents the result of IDE discovery

type FlexibleBool

type FlexibleBool bool

FlexibleBool is a boolean type that can unmarshal from both bool and int (0/1) This handles cases where JSON data may contain numeric values instead of booleans

func (FlexibleBool) MarshalJSON

func (fb FlexibleBool) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler for FlexibleBool

func (*FlexibleBool) UnmarshalJSON

func (fb *FlexibleBool) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler for FlexibleBool

type GroupingStrategy

type GroupingStrategy struct {
	// Mode: "flat" (no grouping), "auto" (automatic based on file count), "pattern" (by pattern)
	Mode string `json:"mode"`
	// GroupPattern: pattern for grouping when mode="pattern", e.g., "skills" groups by skills directory
	// The pattern is searched in the file path, and everything up to (and including) the match becomes the group key
	GroupPattern string `json:"group_pattern,omitempty"`
	// MinFilesForSplit: minimum files before splitting a group (only for auto mode)
	MinFilesForSplit int `json:"min_files_for_split,omitempty"`
}

GroupingStrategy defines how skills should be grouped in the UI

type HealthFilter

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

HealthFilter filters services based on their health status

func NewHealthFilter

func NewHealthFilter(monitor *loadbalance.HealthMonitor) *HealthFilter

NewHealthFilter creates a new health filter with the given health monitor

func (*HealthFilter) Filter

func (hf *HealthFilter) Filter(services []*loadbalance.Service) []*loadbalance.Service

Filter filters out unhealthy services from the given list Returns only healthy services. If no healthy services are found, returns an empty slice (not nil).

func (*HealthFilter) FilterWithFallback

func (hf *HealthFilter) FilterWithFallback(services []*loadbalance.Service) []*loadbalance.Service

FilterWithFallback filters services and returns healthy ones. If no healthy services are found, returns all services as a fallback. This is useful when you want to avoid complete failure even if all services are marked unhealthy.

func (*HealthFilter) GetHealthMonitor

func (hf *HealthFilter) GetHealthMonitor() *loadbalance.HealthMonitor

GetHealthMonitor returns the underlying health monitor

func (*HealthFilter) IsHealthy

func (hf *HealthFilter) IsHealthy(serviceID string) bool

IsHealthy checks if a specific service is healthy

type HybridParams added in v0.260124.900

type HybridParams struct {
	RequestThreshold int64 `json:"request_threshold"` // Request threshold for hybrid tactic
	TokenThreshold   int64 `json:"token_threshold"`   // Token threshold for hybrid tactic
}

HybridParams holds parameters for hybrid tactic

func AsHybridParams added in v0.260124.900

func AsHybridParams(p TacticParams) (HybridParams, bool)

type HybridTactic added in v0.260124.900

type HybridTactic struct {
	RequestThreshold int64 // Threshold for request count before switching
	TokenThreshold   int64 // Threshold for token consumption before switching
}

HybridTactic implements a hybrid load balancing strategy

func NewHybridTactic added in v0.260124.900

func NewHybridTactic(requestThreshold, tokenThreshold int64) *HybridTactic

NewHybridTactic creates a new hybrid tactic

func (*HybridTactic) GetName added in v0.260124.900

func (ht *HybridTactic) GetName() string

func (*HybridTactic) GetType added in v0.260124.900

func (ht *HybridTactic) GetType() loadbalance.TacticType

func (*HybridTactic) SelectService added in v0.260124.900

func (ht *HybridTactic) SelectService(rule *Rule) *loadbalance.Service

SelectService selects service based on both request count and token consumption

type IDEAdapter

type IDEAdapter struct {
	Key               IDESource `json:"key"`
	DisplayName       string    `json:"display_name"`
	RelativeDetectDir string    `json:"relative_detect_dir"`
	Icon              string    `json:"icon"`
	SupportsSymlink   bool      `json:"supports_symlink"`
	// ScanPatterns defines glob patterns for finding skill files (e.g., ["*.md", "skill/*.md"])
	// Patterns are relative to the detected IDE base directory (relative_detect_dir).
	// If empty, defaults to ["**/*.md"]
	ScanPatterns []string `json:"scan_patterns,omitempty"`
	// GroupingStrategy defines how skills should be grouped in the UI
	GroupingStrategy *GroupingStrategy `json:"grouping_strategy,omitempty"`
}

IDEAdapter defines the configuration for an IDE adapter

type IDESource

type IDESource string

IDESource represents the type of IDE/source for skills

const (
	IDESourceClaudeCode    IDESource = "claude-code"
	IDESourceOpenCode      IDESource = "opencode"
	IDESourceVSCode        IDESource = "vscode"
	IDESourceCursor        IDESource = "cursor"
	IDESourceCodex         IDESource = "codex"
	IDESourceAntigravity   IDESource = "antigravity"
	IDESourceAmp           IDESource = "amp"
	IDESourceKiloCode      IDESource = "kilo-code"
	IDESourceRooCode       IDESource = "roo-code"
	IDESourceGoose         IDESource = "goose"
	IDESourceGeminiCLI     IDESource = "gemini-cli"
	IDESourceGitHubCopilot IDESource = "github-copilot"
	IDESourceClawdbot      IDESource = "clawdbot"
	IDESourceDroid         IDESource = "droid"
	IDESourceWindsurf      IDESource = "windsurf"
	IDESourceCustom        IDESource = "custom"
)

type LoadBalancingTactic

type LoadBalancingTactic interface {
	SelectService(rule *Rule) *loadbalance.Service
	GetName() string
	GetType() loadbalance.TacticType
}

LoadBalancingTactic defines the interface for load balancing strategies

func CreateTacticWithTypedParams

func CreateTacticWithTypedParams(tacticType loadbalance.TacticType, params TacticParams) LoadBalancingTactic

func GetDefaultTactic

func GetDefaultTactic(tType loadbalance.TacticType) LoadBalancingTactic

type OAuthDetail

type OAuthDetail struct {
	AccessToken  string                 `json:"access_token"`  // OAuth access token
	ProviderType string                 `json:"provider_type"` // anthropic, google, etc. for token manager lookup
	UserID       string                 `json:"user_id"`       // OAuth user identifier
	RefreshToken string                 `json:"refresh_token"` // Token for refreshing access token
	ExpiresAt    string                 `json:"expires_at"`    // Token expiration time (RFC3339)
	ExtraFields  map[string]interface{} `json:"extra_fields"`  // Any extra field for some special clients
}

OAuthDetail contains OAuth-specific authentication information

func (*OAuthDetail) IsExpired

func (o *OAuthDetail) IsExpired() bool

IsExpired checks if the OAuth token is expired

type Provider

type Provider struct {
	UUID          string            `json:"uuid"`
	Name          string            `json:"name"`
	APIBase       string            `json:"api_base"`
	APIStyle      protocol.APIStyle `json:"api_style"` // "openai" or "anthropic", defaults to "openai"
	Token         string            `json:"token"`     // API key for api_key auth type
	NoKeyRequired bool              `json:"no_key_required"`
	Enabled       bool              `json:"enabled"`
	ProxyURL      string            `json:"proxy_url"`              // HTTP or SOCKS proxy URL (e.g., "http://127.0.0.1:7890" or "socks5://127.0.0.1:1080")
	Timeout       int64             `json:"timeout,omitempty"`      // Request timeout in seconds (default: 1800 = 30 minutes)
	Tags          []string          `json:"tags,omitempty"`         // Provider tags for categorization
	Models        []string          `json:"models,omitempty"`       // Available models for this provider (cached)
	LastUpdated   string            `json:"last_updated,omitempty"` // Last update timestamp

	// Auth configuration
	AuthType    AuthType     `json:"auth_type"`              // api_key or oauth
	OAuthDetail *OAuthDetail `json:"oauth_detail,omitempty"` // OAuth credentials (only for oauth auth type)
}

Provider represents an AI model api key and provider configuration

func (*Provider) GetAccessToken

func (p *Provider) GetAccessToken() string

GetAccessToken returns the access token based on auth type

func (*Provider) IsOAuthExpired

func (p *Provider) IsOAuthExpired() bool

IsOAuthExpired checks if the OAuth token is expired (only valid for oauth auth type)

type RandomParams

type RandomParams struct{}

RandomParams represents parameters for random tactic (currently empty but extensible)

func AsRandomParams

func AsRandomParams(p TacticParams) (RandomParams, bool)

type RandomTactic

type RandomTactic struct{}

RandomTactic implements random selection with weighted probability

func NewRandomTactic

func NewRandomTactic() *RandomTactic

NewRandomTactic creates a new random tactic

func (*RandomTactic) GetName

func (rt *RandomTactic) GetName() string

func (*RandomTactic) GetType

func (rt *RandomTactic) GetType() loadbalance.TacticType

func (*RandomTactic) SelectService

func (rt *RandomTactic) SelectService(rule *Rule) *loadbalance.Service

SelectService selects a service randomly based on weights

type RoundRobinParams added in v0.260124.900

type RoundRobinParams struct {
	RequestThreshold int64 `json:"request_threshold"` // Number of requests per service before switching
}

RoundRobinParams holds parameters for round-robin tactic

func AsRoundRobinParams added in v0.260124.900

func AsRoundRobinParams(p TacticParams) (RoundRobinParams, bool)

Type assertion helpers for TacticParams

type RoundRobinTactic added in v0.260124.900

type RoundRobinTactic struct {
	RequestThreshold int64 // Number of requests per service before switching
}

RoundRobinTactic implements round-robin load balancing based on request count

func NewRoundRobinTactic added in v0.260124.900

func NewRoundRobinTactic(requestThreshold ...int64) *RoundRobinTactic

NewRoundRobinTactic creates a new round-robin tactic with optional threshold parameter

func (*RoundRobinTactic) GetName added in v0.260124.900

func (rr *RoundRobinTactic) GetName() string

func (*RoundRobinTactic) GetType added in v0.260124.900

func (rr *RoundRobinTactic) GetType() loadbalance.TacticType

func (*RoundRobinTactic) SelectService added in v0.260124.900

func (rr *RoundRobinTactic) SelectService(rule *Rule) *loadbalance.Service

SelectService selects the next service based on round-robin with request threshold

type Rule

type Rule struct {
	UUID          string                 `json:"uuid"`
	Scenario      RuleScenario           `json:"scenario,required" yaml:"scenario"` // openai, anthropic, claude_code; defaults to openai
	RequestModel  string                 `json:"request_model" yaml:"request_model"`
	ResponseModel string                 `json:"response_model" yaml:"response_model"`
	Description   string                 `json:"description"`
	Services      []*loadbalance.Service `json:"services" yaml:"services"`
	// CurrentServiceID is persisted to SQLite, not JSON (provider:model format)
	// This identifies the current service for round-robin load balancing
	CurrentServiceID string `json:"-" yaml:"-"`
	// Unified Tactic Configuration
	LBTactic Tactic `json:"lb_tactic" yaml:"lb_tactic"`
	Active   bool   `json:"active" yaml:"active"`
	// Smart Routing Configuration
	SmartEnabled bool                        `json:"smart_enabled" yaml:"smart_enabled"`
	SmartRouting []smartrouting.SmartRouting `json:"smart_routing,omitempty" yaml:"smart_routing,omitempty"`
}

Rule represents a request/response configuration with load balancing support

func (*Rule) GetActiveServices

func (r *Rule) GetActiveServices() []*loadbalance.Service

GetActiveServices returns all active services with initialized stats

func (*Rule) GetCurrentService

func (r *Rule) GetCurrentService() *loadbalance.Service

GetCurrentService returns the current active service based on CurrentServiceID

func (*Rule) GetCurrentServiceID

func (r *Rule) GetCurrentServiceID() string

GetCurrentServiceID returns the current service ID

func (*Rule) GetDefaultModel

func (r *Rule) GetDefaultModel() string

GetDefaultModel returns the model from the currently selected service using load balancing tactic

func (*Rule) GetDefaultProvider

func (r *Rule) GetDefaultProvider() string

GetDefaultProvider returns the provider from the currently selected service using load balancing tactic

func (*Rule) GetScenario

func (r *Rule) GetScenario() RuleScenario

GetScenario returns the scenario, defaulting to openai if empty

func (*Rule) GetServices

func (r *Rule) GetServices() []*loadbalance.Service

GetServices returns the services to use for this rule

func (*Rule) GetTacticType

func (r *Rule) GetTacticType() loadbalance.TacticType

GetTacticType returns the load balancing tactic type

func (*Rule) GetUUID

func (r *Rule) GetUUID() string

GetUUID returns the rule UUID

func (*Rule) SetCurrentServiceID

func (r *Rule) SetCurrentServiceID(serviceID string)

SetCurrentServiceID sets the current service ID (used by RuleStateStore hydration)

func (*Rule) ToJSON

func (r *Rule) ToJSON() interface{}

ToJSON implementation

type RuleScenario

type RuleScenario string

RuleScenario represents the scenario for a routing rule

const (
	ScenarioOpenAI     RuleScenario = "openai"
	ScenarioAnthropic  RuleScenario = "anthropic"
	ScenarioAgent      RuleScenario = "agent"
	ScenarioCodex      RuleScenario = "codex"
	ScenarioClaudeCode RuleScenario = "claude_code"
	ScenarioOpenCode   RuleScenario = "opencode"
	ScenarioXcode      RuleScenario = "xcode"
	ScenarioVSCode     RuleScenario = "vscode"
	ScenarioSmartGuide RuleScenario = "_smart_guide"
	ScenarioGlobal     RuleScenario = "_global" // Global flags that apply to all scenarios
)

type ScanResult

type ScanResult struct {
	LocationID string  `json:"location_id"`
	Skills     []Skill `json:"skills"`
	Error      string  `json:"error,omitempty"`
}

ScanResult represents the result of scanning a location

type ScenarioConfig

type ScenarioConfig struct {
	Scenario   RuleScenario           `json:"scenario" yaml:"scenario"`
	Flags      ScenarioFlags          `json:"flags" yaml:"flags"`                               // Scenario configuration flags
	Extensions map[string]interface{} `json:"extensions,omitempty" yaml:"extensions,omitempty"` // Reserved for future extensions
}

ScenarioConfig represents configuration for a specific scenario

func (*ScenarioConfig) GetDefaultFlags

func (sc *ScenarioConfig) GetDefaultFlags() ScenarioFlags

GetDefaultFlags returns default flags for a scenario

type ScenarioFlags

type ScenarioFlags struct {
	Unified  bool `json:"unified" yaml:"unified"`   // Single configuration for all models
	Separate bool `json:"separate" yaml:"separate"` // Separate configuration for each model
	Smart    bool `json:"smart" yaml:"smart"`       // Smart mode with automatic optimization

	// Experimental feature flags (scenario-based opt-in)
	SmartCompact bool `json:"smart_compact,omitempty" yaml:"smart_compact,omitempty"`   // Enable smart compact (remove thinking blocks)
	Recording    bool `json:"recording,omitempty" yaml:"recording,omitempty"`           // Enable scenario recording
	Beta         bool `json:"anthropic_beta,omitempty" yaml:"anthropic_beta,omitempty"` // Enable Anthropic beta features (e.g. extended thinking)

	// Stream configuration flags
	DisableStreamUsage bool `json:"disable_stream_usage,omitempty" yaml:"disable_stream_usage,omitempty"` // Don't include usage in streaming chunks (for incompatible clients like xcode)

	// Thinking effort level (empty string = use model default)
	ThinkingEffort ThinkingEffortLevel `json:"thinking_effort,omitempty" yaml:"thinking_effort,omitempty"`

	// Thinking mode for claude_code scenario (default/adaptive/force)
	// Using string directly instead of ThinkingMode type to avoid naming conflicts
	ThinkingMode string `json:"thinking_mode,omitempty" yaml:"thinking_mode,omitempty"`

	CleanHeader bool `json:"clean_header,omitempty" yaml:"clean_header,omitempty"` // Remove billing header from system messages (Claude Code only)
}

ScenarioFlags represents configuration flags for a scenario

type Skill

type Skill struct {
	ID          string    `json:"id"`
	Name        string    `json:"name"`
	Filename    string    `json:"filename"`
	Path        string    `json:"path"`
	LocationID  string    `json:"location_id"`
	FileType    string    `json:"file_type"`
	Description string    `json:"description,omitempty"`
	ContentHash string    `json:"content_hash,omitempty"`
	Size        int64     `json:"size,omitempty"`
	ModifiedAt  time.Time `json:"modified_at,omitempty"`
	Content     string    `json:"content,omitempty"`
}

Skill represents a single skill file

type SkillLocation

type SkillLocation struct {
	ID               string    `json:"id"`
	Name             string    `json:"name"`
	Path             string    `json:"path"`
	IDESource        IDESource `json:"ide_source"`
	SkillCount       int       `json:"skill_count"`
	Icon             string    `json:"icon,omitempty"`
	IsAutoDiscovered bool      `json:"is_auto_discovered,omitempty"`
	IsInstalled      bool      `json:"is_installed,omitempty"`
	LastScannedAt    time.Time `json:"last_scanned_at,omitempty"`
	// GroupingStrategy: optional override for this specific location
	GroupingStrategy *GroupingStrategy `json:"grouping_strategy,omitempty"`
}

SkillLocation represents a skill location (directory)

type Tactic

type Tactic struct {
	Type   loadbalance.TacticType `json:"type" yaml:"type"`
	Params TacticParams           `json:"params" yaml:"params"`
}

Tactic bundles the strategy type and its parameters together

func ParseTacticFromMap

func ParseTacticFromMap(tacticType loadbalance.TacticType, params map[string]interface{}) Tactic

ParseTacticFromMap creates a Tactic from a tactic type and parameter map. This is useful for parsing API request parameters into a Tactic configuration.

func (*Tactic) Instantiate

func (tc *Tactic) Instantiate() LoadBalancingTactic

Instantiate converts the configuration into functional logic

func (*Tactic) UnmarshalJSON

func (tc *Tactic) UnmarshalJSON(data []byte) error

UnmarshalJSON handles the polymorphic decoding of TacticParams

type TacticParams

type TacticParams interface {
	// contains filtered or unexported methods
}

TacticParams represents parameters for different load balancing tactics This is a sealed type that can only be one of the specific tactic parameter types

func DefaultHybridParams

func DefaultHybridParams() TacticParams

func DefaultRandomParams

func DefaultRandomParams() TacticParams

func DefaultRoundRobinParams

func DefaultRoundRobinParams() TacticParams

DefaultParams returns default parameters for each tactic type

func DefaultTokenBasedParams

func DefaultTokenBasedParams() TacticParams

func NewHybridParams

func NewHybridParams(requestThreshold, tokenThreshold int64) TacticParams

func NewRandomParams

func NewRandomParams() TacticParams

func NewRoundRobinParams added in v0.260124.900

func NewRoundRobinParams(threshold int64) TacticParams

Helper constructors for creating tactic parameters

func NewTokenBasedParams

func NewTokenBasedParams(threshold int64) TacticParams

type ThinkingEffortLevel

type ThinkingEffortLevel = string

ThinkingEffortLevel represents the thinking effort level for extended thinking

const (
	ThinkingEffortLow     ThinkingEffortLevel = "low"
	ThinkingEffortMedium  ThinkingEffortLevel = "medium"
	ThinkingEffortHigh    ThinkingEffortLevel = "high"
	ThinkingEffortMax     ThinkingEffortLevel = "max"
	ThinkingEffortDefault ThinkingEffortLevel = "" // Use model default
)

type ThinkingMode

type ThinkingMode string

ThinkingMode represents the thinking mode for extended thinking

const (
	ThinkingModeDefault  ThinkingMode = "default"  // Use model default
	ThinkingModeAdaptive ThinkingMode = "adaptive" // Model decides when to use
	ThinkingModeForce    ThinkingMode = "force"    // Force for all requests
)

type TokenBasedParams

type TokenBasedParams struct {
	TokenThreshold int64 `json:"token_threshold"` // Threshold for token consumption before switching
}

TokenBasedParams holds parameters for token-based tactic

func AsTokenBasedParams

func AsTokenBasedParams(p TacticParams) (TokenBasedParams, bool)

type TokenBasedTactic

type TokenBasedTactic struct {
	TokenThreshold int64 // Threshold for token consumption before switching
}

TokenBasedTactic implements load balancing based on token consumption

func NewTokenBasedTactic

func NewTokenBasedTactic(tokenThreshold int64) *TokenBasedTactic

NewTokenBasedTactic creates a new token-based tactic

func (*TokenBasedTactic) GetName

func (tb *TokenBasedTactic) GetName() string

func (*TokenBasedTactic) GetType

func (tb *TokenBasedTactic) GetType() loadbalance.TacticType

func (*TokenBasedTactic) SelectService

func (tb *TokenBasedTactic) SelectService(rule *Rule) *loadbalance.Service

SelectService selects service based on token consumption thresholds

type ToolInterceptorConfig

type ToolInterceptorConfig struct {
	PreferLocalSearch FlexibleBool `json:"prefer_local_search,omitempty"` // Prefer local tool interception even if provider has built-in search
	SearchAPI         string       `json:"search_api,omitempty"`          // "brave" or "google"
	SearchKey         string       `json:"search_key,omitempty"`          // API key for search service
	MaxResults        int          `json:"max_results,omitempty"`         // Max search results to return (default: 10)

	// Proxy configuration
	ProxyURL string `json:"proxy_url,omitempty"` // HTTP proxy URL (e.g., "http://127.0.0.1:7897")

	// Fetch configuration
	MaxFetchSize int64 `json:"max_fetch_size,omitempty"` // Max content size for fetch in bytes (default: 1MB)
	FetchTimeout int64 `json:"fetch_timeout,omitempty"`  // Fetch timeout in seconds (default: 30)
	MaxURLLength int   `json:"max_url_length,omitempty"` // Max URL length (default: 2000)
}

ToolInterceptorConfig contains configuration for tool interceptor (search & fetch)

type ToolInterceptorOverride

type ToolInterceptorOverride struct {
	// Disabled allows provider to explicitly disable when globally enabled
	Disabled bool `json:"disabled,omitempty"`

	// MaxResults override for this specific provider
	MaxResults *int `json:"max_results,omitempty"`
}

ToolInterceptorOverride contains provider-level overrides for tool interceptor

Jump to

Keyboard shortcuts

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