models

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package models defines all shared data structures for llm-router.

Index

Constants

View Source
const (
	ProxyModeDisabled = "disabled"
	ProxyModeAuto     = "auto"
	ProxyModeManual   = "manual"
)

Mode constants for ProxyConfig.

View Source
const CurrentVersion = "0.0.4"

CurrentVersion is the router version plugins declare compatibility with via the @router_version manifest tag.

Variables

This section is empty.

Functions

This section is empty.

Types

type AdminUser

type AdminUser struct {
	Username     string    `json:"username"`
	PasswordHash string    `json:"password_hash"`
	CreatedAt    time.Time `json:"created_at"`
}

AdminUser is the dashboard operator account.

type Agent

type Agent struct {
	ID            string               `json:"id"`
	Name          string               `json:"name"`
	Description   string               `json:"description"`
	Models        []AgentModel         `json:"models"`
	Instructions  AgentInstructions    `json:"instructions"`
	DecisionModel *DecisionModelConfig `json:"decision_model,omitempty"`
	MaxTokens     int                  `json:"max_tokens"`
	Version       int                  `json:"version"`
	IsDraft       bool                 `json:"is_draft"`
	CreatedAt     time.Time            `json:"created_at"`
	UpdatedAt     time.Time            `json:"updated_at"`
}

Agent is a virtual provider that orchestrates requests across multiple real providers.

type AgentInstructions

type AgentInstructions struct {
	Content   string            `json:"content"`
	Injection InjectionStrategy `json:"injection"`
}

AgentInstructions defines how instructions are injected into requests.

type AgentModel

type AgentModel struct {
	ModelID      ModelId `json:"model_id"`
	Priority     int     `json:"priority"`
	Description  string  `json:"description"`
	Instructions string  `json:"instructions"`
}

AgentModel represents a model that an agent can use.

type AuthFlowResult

type AuthFlowResult struct {
	Render      []*UINode      `json:"render,omitempty"`
	RedirectURL string         `json:"redirect_url,omitempty"`
	Credentials map[string]any `json:"credentials,omitempty"`
}

AuthFlowResult is one of the three auth_step/auth_initiate outcomes, discriminated by which field is set.

type AuthStepInput

type AuthStepInput struct {
	Action string         `json:"action"`
	Values map[string]any `json:"values"`
	FlowID string         `json:"flow_id,omitempty"`
}

AuthStepInput is the submit payload for auth_step.

type ChatCompletionChoice

type ChatCompletionChoice struct {
	Index        int         `json:"index"`
	Message      ChatMessage `json:"message"`
	FinishReason string      `json:"finish_reason"`
	Logprobs     any         `json:"logprobs,omitempty"`
}

type ChatCompletionRequest

type ChatCompletionRequest struct {
	Model               ModelId        `json:"model" example:"openai/gpt-4o"`
	Messages            []ChatMessage  `json:"messages"`
	Tools               []ChatTool     `json:"tools,omitempty"`
	ToolChoice          any            `json:"tool_choice,omitempty"`
	ParallelToolCalls   *bool          `json:"parallel_tool_calls,omitempty"`
	Stream              bool           `json:"stream,omitempty" example:"false"`
	StreamOptions       *StreamOptions `json:"stream_options,omitempty"`
	MaxTokens           int            `json:"max_tokens,omitempty" example:"1000"`
	MaxCompletionTokens *int           `json:"max_completion_tokens,omitempty"`
	Temperature         float64        `json:"temperature,omitempty" example:"0.7"`
	TopP                float64        `json:"top_p,omitempty" example:"1.0"`
	N                   *int           `json:"n,omitempty"`
	Stop                any            `json:"stop,omitempty"`
	Seed                *int64         `json:"seed,omitempty"`
	FrequencyPenalty    *float64       `json:"frequency_penalty,omitempty"`
	PresencePenalty     *float64       `json:"presence_penalty,omitempty"`
	Logprobs            *bool          `json:"logprobs,omitempty"`
	TopLogprobs         *int           `json:"top_logprobs,omitempty"`
	ResponseFormat      any            `json:"response_format,omitempty"`
	User                *string        `json:"user,omitempty"`
	ServiceTier         *string        `json:"service_tier,omitempty"`
	ReasoningEffort     *string        `json:"reasoning_effort,omitempty"`
	Verbosity           *string        `json:"verbosity,omitempty"`
}

ChatCompletionRequest is the incoming /v1/chat/completions body.

type ChatCompletionResponse

type ChatCompletionResponse struct {
	ID                string                 `json:"id"`
	Object            string                 `json:"object"`
	Created           int64                  `json:"created"`
	Model             string                 `json:"model"`
	Choices           []ChatCompletionChoice `json:"choices"`
	Usage             ChatCompletionUsage    `json:"usage"`
	SystemFingerprint *string                `json:"system_fingerprint,omitempty"`
	ServiceTier       *string                `json:"service_tier,omitempty"`
}

ChatCompletionResponse mirrors the OpenAI response schema.

type ChatCompletionUsage

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

	PromptTokensDetails     *PromptTokensDetails     `json:"prompt_tokens_details,omitempty"`
	CompletionTokensDetails *CompletionTokensDetails `json:"completion_tokens_details,omitempty"`
}

type ChatMessage

type ChatMessage struct {
	Role         string                   `json:"role" example:"user" enums:"system,user,assistant,tool,developer"`
	Content      string                   `json:"-" example:"Hello, how are you?"`
	ContentParts []ChatMessageContentPart `json:"-"`
	ToolCalls    []ChatToolCall           `json:"tool_calls,omitempty"`
	ToolCallID   string                   `json:"tool_call_id,omitempty"`
	Name         string                   `json:"name,omitempty"`
	Refusal      *string                  `json:"refusal,omitempty"`
	// ReasoningContent carries chain-of-thought text exposed by reasoning
	// models (DeepSeek `reasoning_content`, Groq `reasoning`).
	ReasoningContent string `json:"reasoning_content,omitempty"`
}

ChatMessage is a single turn in a conversation.

func (ChatMessage) MarshalJSON

func (m ChatMessage) MarshalJSON() ([]byte, error)

func (ChatMessage) TextContent

func (m ChatMessage) TextContent() string

func (*ChatMessage) UnmarshalJSON

func (m *ChatMessage) UnmarshalJSON(data []byte) error

type ChatMessageContentPart

type ChatMessageContentPart struct {
	Type        string                   `json:"type,omitempty"`
	Text        string                   `json:"text,omitempty"`
	ToolUseID   string                   `json:"tool_use_id,omitempty"`
	ID          string                   `json:"id,omitempty"`
	Name        string                   `json:"name,omitempty"`
	Input       json.RawMessage          `json:"input,omitempty"`
	ImageURL    *ChatMessageImageURL     `json:"image_url,omitempty"`
	InputAudio  *ChatMessageInputAudio   `json:"input_audio,omitempty"`
	Content     []ChatMessageContentPart `json:"-"`
	ContentText string                   `json:"-"`
}

func (ChatMessageContentPart) MarshalJSON

func (p ChatMessageContentPart) MarshalJSON() ([]byte, error)

func (ChatMessageContentPart) TextContent

func (p ChatMessageContentPart) TextContent() string

func (*ChatMessageContentPart) UnmarshalJSON

func (p *ChatMessageContentPart) UnmarshalJSON(data []byte) error

type ChatMessageImageURL

type ChatMessageImageURL struct {
	URL    string `json:"url,omitempty"`
	Detail string `json:"detail,omitempty"`
}

ChatMessageImageURL is an OpenAI image_url content part. URL is either a remote http(s) URL or a data: URL carrying base64 bytes inline.

type ChatMessageInputAudio

type ChatMessageInputAudio struct {
	Data   string `json:"data,omitempty"`
	Format string `json:"format,omitempty"`
}

ChatMessageInputAudio is an OpenAI input_audio content part. Data is base64 audio, Format is wav or mp3.

type ChatTool

type ChatTool struct {
	Type        string            `json:"type,omitempty"`
	Name        string            `json:"name,omitempty"`
	Description string            `json:"description,omitempty"`
	Parameters  map[string]any    `json:"parameters,omitempty"`
	InputSchema map[string]any    `json:"input_schema,omitempty"`
	Function    *ChatToolFunction `json:"function,omitempty"`
	Strict      *bool             `json:"strict,omitempty"`
}

type ChatToolCall

type ChatToolCall struct {
	ID       string           `json:"id,omitempty"`
	Type     string           `json:"type,omitempty"`
	Function ChatToolFunction `json:"function"`
}

type ChatToolFunction

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

type CompletionTokensDetails

type CompletionTokensDetails struct {
	ReasoningTokens int `json:"reasoning_tokens,omitempty"`
	AudioTokens     int `json:"audio_tokens,omitempty"`
}

CompletionTokensDetails is the OpenAI breakdown of completion-side token usage.

type Credential

type Credential struct {
	ID         string         `json:"id"`
	ProviderID string         `json:"provider_id"`
	Label      string         `json:"label"`
	Data       map[string]any `json:"data"`
	ExpiresAt  *time.Time     `json:"expires_at,omitempty"`
	CreatedAt  time.Time      `json:"created_at"`
	UpdatedAt  time.Time      `json:"updated_at"`

	LastUsedAt   *time.Time `json:"last_used_at,omitempty"`
	RequestCount int64      `json:"request_count"`
	SuccessCount int64      `json:"success_count"`
	FailureCount int64      `json:"failure_count"`

	QuotaResetAt *time.Time `json:"quota_reset_at,omitempty"`

	// Disabled excludes the credential from routing and fallthrough.
	Disabled bool `json:"disabled,omitempty"`
	// Order is the admin-defined pool position (1-based). 0 means unordered:
	// unordered credentials sort after ordered ones by computed priority.
	Order int `json:"order,omitempty"`
}

Credential holds provider-specific authentication data. Data is a flexible map to support any auth scheme, including non-string values such as expiry timestamps.

func (*Credential) DataString

func (c *Credential) DataString(key string) string

DataString returns a string view of a data value for Go adapters that only understand string credentials.

func (*Credential) ExpiresIn

func (c *Credential) ExpiresIn() time.Duration

ExpiresIn returns the duration until expiry (negative if already expired).

func (*Credential) IncrementUsage

func (c *Credential) IncrementUsage(success bool)

IncrementUsage updates usage statistics after a request.

func (*Credential) IsExpired

func (c *Credential) IsExpired() bool

IsExpired reports whether the credential has passed its expiry time.

func (*Credential) IsQuotaExceeded

func (c *Credential) IsQuotaExceeded() bool

IsQuotaExceeded reports whether the credential's quota is currently exceeded.

func (*Credential) MarkQuotaExceeded

func (c *Credential) MarkQuotaExceeded(resetAt time.Time)

MarkQuotaExceeded marks this credential as quota-exceeded until resetAt.

func (*Credential) Priority

func (c *Credential) Priority() int

Priority returns the selection priority for this credential.

type DecisionModelConfig

type DecisionModelConfig struct {
	ModelID      ModelId `json:"model_id"`
	SystemPrompt string  `json:"system_prompt"`
}

DecisionModelConfig configures the optional decision model for intelligent routing.

type ErrorResponse

type ErrorResponse struct {
	Error string `json:"error" example:"invalid request"`
}

ErrorResponse is the standard error response format for all API endpoints.

type ErrorType

type ErrorType int

ErrorType classifies provider errors for retry logic.

const (
	ErrorTypeUnknown        ErrorType = iota
	ErrorTypeRateLimit                // Temporary rate limit, rotate credential
	ErrorTypeQuotaExceeded            // Credential quota exhausted, deprioritize (MUST have RetryAfter)
	ErrorTypeAuth                     // Auth failure, credential may be invalid
	ErrorTypeUpstream                 // Upstream error, don't retry
	ErrorTypeTimeout                  // Timeout, may retry
	ErrorTypeInvalidRequest           // Invalid request, don't retry
	ErrorTypeGeo                      // Geo-blocked upstream; proxy used is at fault, mark it bad
)

type InjectionStrategy

type InjectionStrategy string

InjectionStrategy defines where instructions are injected in the message list.

const (
	InjectionBeginning InjectionStrategy = "beginning"
	InjectionEnd       InjectionStrategy = "end"
)

type MetricEvent

type MetricEvent struct {
	Timestamp    time.Time
	ProviderID   string
	ProviderType string
	Model        ModelId
	TokenID      string
	Duration     time.Duration
	StatusCode   int
	TokensInput  int64
	TokensOutput int64
	ErrorType    string
}

MetricEvent represents a single API request event.

type MetricsFilters

type MetricsFilters struct {
	ProviderID string    `json:"provider_id"`
	Model      ModelId   `json:"model"`
	TimeRange  TimeRange `json:"time_range"`
}

MetricsFilters for querying metrics.

type MetricsOverview

type MetricsOverview struct {
	TotalRequests    int64 `json:"total_requests" example:"1500"`
	TotalErrors      int64 `json:"total_errors" example:"23"`
	PeakRequests     int64 `json:"peak_requests" example:"45"`
	PeakInputTokens  int64 `json:"peak_input_tokens" example:"12000"`
	PeakOutputTokens int64 `json:"peak_output_tokens" example:"3500"`
}

MetricsOverview for dashboard display.

type ModelId

type ModelId string

ModelId uniquely identifies a model in the format: provider/model-name[:version]

func (ModelId) Parse

func (m ModelId) Parse() (providerID, model string, err error)

Parse splits a ModelId into providerID and model name.

func (ModelId) ParseFull

func (m ModelId) ParseFull() (adapterType, qualifier, model string, err error)

ParseFull splits a ModelId into adapter type, qualifier, and model name.

func (ModelId) String

func (m ModelId) String() string

type ModelInfo

type ModelInfo struct {
	Name          string `json:"name"`
	DisplayName   string `json:"display_name"`
	Description   string `json:"description,omitempty"`
	RPM           int64  `json:"rpm"`
	TPM           int64  `json:"tpm"`
	RPD           int64  `json:"rpd"`
	ContextWindow int64  `json:"context_window,omitempty"`
	MaxTokens     int64  `json:"max_tokens,omitempty"`

	// Capabilities are UI-facing feature chips (tools, vision, ...).
	// Derived from the fields below when the plugin does not set them.
	Capabilities []string `json:"capabilities,omitempty"`

	InputModalities     []string        `json:"input_modalities,omitempty"`
	OutputModalities    []string        `json:"output_modalities,omitempty"`
	SupportedParameters []string        `json:"supported_parameters,omitempty"`
	Reasoning           *ModelReasoning `json:"reasoning,omitempty"`
}

ModelInfo contains metadata about a specific model. Field style follows the OpenRouter model schema where applicable.

func (*ModelInfo) DeriveCapabilities

func (m *ModelInfo) DeriveCapabilities()

DeriveCapabilities fills Capabilities from the OpenRouter-style fields. Explicit plugin-provided capabilities win.

type ModelOverride

type ModelOverride struct {
	ProviderID   string   `json:"provider_id"`
	Name         string   `json:"name"`
	Disabled     bool     `json:"disabled,omitempty"`
	Custom       bool     `json:"custom,omitempty"`
	DisplayName  string   `json:"display_name,omitempty"`
	Capabilities []string `json:"capabilities,omitempty"`
}

ModelOverride is the per-provider admin override for a single model: disable from routing and /v1/models, register a custom model the upstream does not list, or adjust display metadata.

type ModelReasoning

type ModelReasoning struct {
	// SupportedEfforts in descending effort order (highest first).
	SupportedEfforts []string `json:"supported_efforts,omitempty"`
	DefaultEffort    string   `json:"default_effort,omitempty"`
	DefaultEnabled   bool     `json:"default_enabled,omitempty"`
	Mandatory        bool     `json:"mandatory,omitempty"`
}

ModelReasoning describes reasoning support of a model (OpenRouter-style).

type OpenAIError

type OpenAIError struct {
	Error OpenAIErrorBody `json:"error"`
}

OpenAIError wraps error responses in the OpenAI error format.

type OpenAIErrorBody

type OpenAIErrorBody struct {
	Message string  `json:"message" example:"Invalid request: missing required field 'model'"`
	Type    string  `json:"type" example:"invalid_request_error"`
	Param   *string `json:"param" example:"model"`
	Code    string  `json:"code,omitempty" example:"invalid_request"`
}

type PluginInternalError

type PluginInternalError struct {
	PluginID string
	TypeKey  string
	Cause    string
}

PluginInternalError is a caught Lua failure at the Go/Lua boundary. Always retryable: the retry engine moves to the next candidate.

func (*PluginInternalError) Error

func (e *PluginInternalError) Error() string

func (*PluginInternalError) Retryable

func (e *PluginInternalError) Retryable() bool

Retryable always returns true for plugin crashes.

type PromptTokensDetails

type PromptTokensDetails struct {
	CachedTokens int `json:"cached_tokens,omitempty"`
	AudioTokens  int `json:"audio_tokens,omitempty"`
}

PromptTokensDetails is the OpenAI breakdown of prompt-side token usage.

type Provider

type Provider = ProviderInstance

Provider is kept as an alias so existing call sites keep compiling while the field migration (Type -> TypeKey, BaseURL -> Config) proceeds.

type ProviderError

type ProviderError struct {
	StatusCode int
	Message    string
	Type       ErrorType
	RetryAfter *time.Time
}

ProviderError represents errors returned by provider backends.

func (*ProviderError) Error

func (e *ProviderError) Error() string

func (*ProviderError) IsRetryable

func (e *ProviderError) IsRetryable() bool

IsRetryable reports whether this error triggers credential rotation.

func (*ProviderError) Retryable

func (e *ProviderError) Retryable() bool

Retryable reports the same as IsRetryable to satisfy retry.Classifiable.

type ProviderInstance

type ProviderInstance struct {
	ID           string         `json:"id" example:"opencode-zen"`
	Name         string         `json:"name" example:"OpenCode Zen"`
	TypeKey      string         `json:"type_key" example:"opencode-zen"`
	Qualifier    string         `json:"qualifier" example:""`
	Config       map[string]any `json:"config"`
	IconURL      string         `json:"icon_url" example:"https://cdn.example.com/openai.svg"`
	IsUIReadonly bool           `json:"is_ui_readonly"`
	IsUIHidden   bool           `json:"is_ui_hidden"`
	// Disabled takes the provider out of routing and model listings.
	// Settings and discovery keep working.
	Disabled  bool      `json:"disabled,omitempty"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

ProviderInstance is the single persisted provider record for every type: lua-plugin type keys, built-in "custom" and "agents".

func (*ProviderInstance) BaseURL

func (p *ProviderInstance) BaseURL() string

BaseURL returns Config["base_url"] for OpenAI-compatible providers.

type ProviderInstanceCreateRequest

type ProviderInstanceCreateRequest struct {
	Name      string         `json:"name"`
	TypeKey   string         `json:"type_key"`
	Qualifier string         `json:"qualifier"`
	Config    map[string]any `json:"config"`
	IconURL   string         `json:"icon_url"`
}

ProviderInstanceCreateRequest is the generic create body for any provider type.

type ProviderInstanceUpdateRequest

type ProviderInstanceUpdateRequest struct {
	Name     string         `json:"name"`
	Config   map[string]any `json:"config"`
	IconURL  string         `json:"icon_url"`
	Disabled *bool          `json:"disabled"`
}

ProviderInstanceUpdateRequest is the generic update body.

type ProviderStats

type ProviderStats struct {
	ModelCount      int `json:"model_count" example:"5"`
	CredentialCount int `json:"credential_count" example:"2"`
}

ProviderStats holds aggregated statistics for a provider.

type Proxy

type Proxy struct {
	ID       string `json:"id"`
	URL      string `json:"url"`      // scheme://[user:pass@]host:port
	Protocol string `json:"protocol"` // http, https, socks4, socks5
	Host     string `json:"host"`
	Port     int    `json:"port"`
	Country  string `json:"country"` // ISO 3166-1 alpha-2, empty when unknown
	Source   string `json:"source"`  // "manual" or "list:<source type key>"

	Alive       bool      `json:"alive"`
	LatencyMs   int64     `json:"latency_ms"`
	LastCheckAt time.Time `json:"last_check_at,omitempty"`

	// Health per provider type key: a proxy region-locked by one provider
	// stays usable for the others.
	ProviderHealth map[string]ProxyHealth `json:"provider_health,omitempty"`

	CreatedAt time.Time `json:"created_at"`
}

Proxy is one outbound proxy endpoint, either manually registered or synced from a proxy-list source plugin.

type ProxyCandidate

type ProxyCandidate struct {
	Protocol string `json:"protocol"`
	Host     string `json:"host"`
	Port     int    `json:"port"`
	Country  string `json:"country"`
}

ProxyCandidate is one proxy entry produced by a source plugin.

type ProxyConfig

type ProxyConfig struct {
	Mode string   `json:"mode"`          // "disabled" (default), "auto", "manual"
	IDs  []string `json:"ids,omitempty"` // manual mode: chosen proxy IDs
}

ProxyConfig is the provider-level proxy mode stored in ProviderInstance.Config.

type ProxyHealth

type ProxyHealth struct {
	OK        bool      `json:"ok"`
	LatencyMs int64     `json:"latency_ms"`
	CheckedAt time.Time `json:"checked_at"`
}

ProxyHealth is the last probe outcome for one provider.

type ProxyPreferences

type ProxyPreferences struct {
	Location string `json:"location,omitempty"` // ISO country code, e.g. "US"
}

ProxyPreferences come from a plugin manifest: where the upstream expects requests to originate.

type RouterConfiguration

type RouterConfiguration struct {
	IsClusterNode    bool `json:"is_cluster_node"`
	DisableTelemetry bool `json:"disable_telemetry"`
	MaxRetries       int  `json:"max_retries"`
	// ServerCountry is an optional manual override (ISO 3166-1 alpha-2) for
	// the geo-IP detected server location, used for proxy preference matching.
	ServerCountry string `json:"server_country,omitempty"`
}

RouterConfiguration holds deployment-wide instance settings.

func (RouterConfiguration) Validate

func (c RouterConfiguration) Validate() error

Validate checks MaxRetries is in range 0-20.

type RouterToken

type RouterToken struct {
	ID        string     `json:"id" example:"token123"`
	Name      string     `json:"name" example:"Production API Token"`
	Token     string     `json:"token,omitempty" example:"llmr_abc123def456"`
	TokenHash string     `json:"token_hash,omitempty"`
	Rules     TokenRules `json:"rules"`
	CreatedAt time.Time  `json:"created_at" example:"2026-05-04T15:00:00Z"`
}

RouterToken is an opaque bearer token issued by llm-router itself.

type StreamChunk

type StreamChunk struct {
	ID      string               `json:"id"`
	Object  string               `json:"object"`
	Created int64                `json:"created"`
	Model   string               `json:"model"`
	Choices []StreamChunkChoice  `json:"choices"`
	Usage   *ChatCompletionUsage `json:"usage,omitempty"`
}

StreamChunk is a single SSE data payload for streaming responses.

type StreamChunkChoice

type StreamChunkChoice struct {
	Index        int         `json:"index"`
	Delta        ChatMessage `json:"delta"`
	FinishReason *string     `json:"finish_reason"`
	Logprobs     any         `json:"logprobs,omitempty"`
}

type StreamOptions

type StreamOptions struct {
	IncludeUsage bool `json:"include_usage,omitempty"`
}

StreamOptions for streaming

type TimeRange

type TimeRange string

TimeRange represents a time window for metrics queries.

const (
	TimeRangeHour      TimeRange = "hour"
	TimeRange1Day      TimeRange = "1d"
	TimeRange7Days     TimeRange = "7d"
	TimeRange28Days    TimeRange = "28d"
	TimeRange90Days    TimeRange = "90d"
	TimeRangeThisMonth TimeRange = "month"
)

func (TimeRange) Bounds

func (tr TimeRange) Bounds() (start, end time.Time)

Bounds returns the start and end times for this time range.

type TimeSeriesPoint

type TimeSeriesPoint struct {
	Timestamp time.Time `json:"timestamp" example:"2026-05-04T19:00:00Z"`
	Value     int64     `json:"value" example:"42"`
}

TimeSeriesPoint for chart data.

type TokenRules

type TokenRules struct {
	AllowedProviders    []string  `json:"allowed_providers"`
	AllowAllProviders   bool      `json:"allow_all_providers"`
	AllowedModels       []ModelId `json:"allowed_models"`
	AllowAllModels      bool      `json:"allow_all_models"`
	AllowedCredentials  []string  `json:"allowed_credentials"`
	AllowAllCredentials bool      `json:"allow_all_credentials"`
}

TokenRules constrains what an API token is allowed to do.

func (TokenRules) Allows

func (r TokenRules) Allows(model ModelId) bool

Allows reports whether the token may request the given model.

func (TokenRules) AllowsCredential

func (r TokenRules) AllowsCredential(credentialID string) bool

AllowsCredential reports whether the token may use the given credential.

func (TokenRules) AllowsProvider

func (r TokenRules) AllowsProvider(providerID string) bool

AllowsProvider reports whether the token may use the given provider.

type UINode

type UINode struct {
	Type         string            `json:"type"`
	Text         string            `json:"text,omitempty"`
	Name         string            `json:"name,omitempty"`
	Label        string            `json:"label,omitempty"`
	InputType    string            `json:"input_type,omitempty"`
	Required     bool              `json:"required,omitempty"`
	Options      []string          `json:"options,omitempty"`
	OptionLabels map[string]string `json:"option_labels,omitempty"`
	URL          string            `json:"url,omitempty"`
	Variant      string            `json:"variant,omitempty"`
	FormAction   string            `json:"form_action,omitempty"`
	Content      []*UINode         `json:"content,omitempty"`
	Placeholder  string            `json:"placeholder,omitempty"`
	Value        any               `json:"value,omitempty"`
	Direction    string            `json:"direction,omitempty"`
	Align        string            `json:"align,omitempty"`
	Justify      string            `json:"justify,omitempty"`
	Gap          string            `json:"gap,omitempty"`
	Columns      int               `json:"columns,omitempty"`
	Title        string            `json:"title,omitempty"`
	Subtitle     string            `json:"subtitle,omitempty"`
	Wrap         bool              `json:"wrap,omitempty"`
	Grow         bool              `json:"grow,omitempty"`
	Size         string            `json:"size,omitempty"`
	Extra        map[string]any    `json:"-"`
}

UINode is a single node of the lua-driven UI tree shared by config_schema, credential_schema and auth wizards.

Jump to

Keyboard shortcuts

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