yao/llmprovider/types.go
Max 6f78f6066b feat(llm): refactor audio capabilities and enhance role management
- Replaced 'Voice' with 'Audio' in the system configuration and related tests to better reflect functionality.
- Introduced new methods for role management in the llmprovider, allowing for dynamic retrieval of roles based on user and team context.
- Updated the OpenAPI settings to support new role management endpoints and capabilities.
- Enhanced the handling of API keys in provider management, allowing for optional plain-text retrieval.
2026-04-30 12:33:05 +08:00

89 lines
3.3 KiB
Go

package llmprovider
// Identity abstracts a caller's user/team context for scope-aware lookups.
// Implemented by oauthTypes.AuthorizedInfo and any struct with UserID/TeamID.
type Identity interface {
GetUserID() string
GetTeamID() string
}
// Provider represents a configured LLM provider (one vendor connection with multiple models).
// Fields align with the frontend ProviderConfig interface.
type Provider struct {
Key string `json:"key"`
ConnectorID string `json:"connector_id"`
Name string `json:"name"`
Type string `json:"type"`
APIURL string `json:"api_url"`
APIKey string `json:"api_key"`
Models []ModelInfo `json:"models"`
Enabled bool `json:"enabled"`
Status string `json:"status"`
IsCustom bool `json:"is_custom,omitempty"`
PresetKey string `json:"preset_key,omitempty"`
RequireKey bool `json:"require_key"`
Source ProviderSource `json:"source"`
Owner ProviderOwner `json:"owner"`
}
// ModelInfo describes a single model within a provider.
// Fields align with the frontend ModelInfo interface.
type ModelInfo struct {
ID string `json:"id" yaml:"id"`
Name string `json:"name" yaml:"name"`
Capabilities []string `json:"capabilities" yaml:"capabilities"`
Enabled bool `json:"enabled" yaml:"enabled"`
}
// ProviderOwner identifies who owns a provider.
type ProviderOwner struct {
Type string `json:"type"`
TeamID string `json:"team_id,omitempty"`
UserID string `json:"user_id,omitempty"`
}
// ProviderSource distinguishes dynamic (registry-created) from builtin (DSL-loaded) providers.
type ProviderSource string
const (
ProviderSourceDynamic ProviderSource = "dynamic"
ProviderSourceBuiltIn ProviderSource = "builtin"
ProviderSourceAll ProviderSource = "all"
)
// ProviderFilter specifies criteria for listing providers.
type ProviderFilter struct {
Owner *ProviderOwner
Enabled *bool
Source ProviderSource // defaults to "dynamic" when zero-value
Type *string
PresetKey *string
Capabilities []string // AND filter: provider matches if any model satisfies all
Keyword string
}
// ProviderPreset is a static UI-only template for creating providers.
// Fields align with the frontend ProviderPreset interface.
type ProviderPreset struct {
Key string `json:"key" yaml:"key"`
Name string `json:"name" yaml:"name"`
Type string `json:"type" yaml:"type"`
APIURL string `json:"api_url" yaml:"api_url"`
RequireKey bool `json:"require_key" yaml:"require_key"`
IsCloud bool `json:"is_cloud,omitempty" yaml:"is_cloud,omitempty"`
URLEditable bool `json:"url_editable,omitempty" yaml:"url_editable,omitempty"`
DefaultModels []ModelInfo `json:"default_models" yaml:"default_models"`
}
// ProviderTestResult holds the outcome of a provider connectivity test.
type ProviderTestResult struct {
Success bool `json:"success"`
Message string `json:"message"`
LatencyMs int64 `json:"latency_ms,omitempty"`
}
// RoleTarget identifies a provider and model for a given role.
type RoleTarget struct {
Provider string `json:"provider"`
Model string `json:"model"`
}