Documentation
¶
Index ¶
- Constants
- Variables
- type Completer
- type CreateOptions
- type Embedder
- type GoAdapter
- type GormService
- func (s *GormService) ConfigSchema(typeKey, locale string) ([]*models.UINode, error)
- func (s *GormService) Create(ctx context.Context, options CreateOptions) (*models.ProviderInstance, error)
- func (s *GormService) CredentialSchema(typeKey, locale string) ([]*models.UINode, error)
- func (s *GormService) CredentialsEnabled(typeKey string) bool
- func (s *GormService) Delete(ctx context.Context, identifier string) error
- func (s *GormService) EnsureSeeded(ctx context.Context) error
- func (s *GormService) Get(ctx context.Context, identifier string) (*models.ProviderInstance, error)
- func (s *GormService) GetByType(ctx context.Context, typeKey string) ([]*models.ProviderInstance, error)
- func (s *GormService) GetByTypeAndQualifier(ctx context.Context, typeKey, qualifier string) (*models.ProviderInstance, error)
- func (s *GormService) GoAdapterFor(typeKey string) (GoAdapter, bool)
- func (s *GormService) IsTypeAvailable(typeKey string) bool
- func (s *GormService) JobSpecs(typeKey string) map[string]luaplugin.JobSpec
- func (s *GormService) List(ctx context.Context) ([]*models.ProviderInstance, error)
- func (s *GormService) LuaService() *luaplugin.Service
- func (s *GormService) ProxiesEnabled(typeKey string) bool
- func (s *GormService) ProxySchema(typeKey, locale string) ([]*models.UINode, error)
- func (s *GormService) RegisterGoAdapter(adapter GoAdapter)
- func (s *GormService) SetLogger(l *slog.Logger)
- func (s *GormService) SetLuaService(service *luaplugin.Service)
- func (s *GormService) SetOnChanged(function func(providerID string))
- func (s *GormService) SettingsSchema(typeKey, locale string) ([]*models.UINode, error)
- func (s *GormService) SupportsAuthFlow(typeKey string) bool
- func (s *GormService) SyncDefaultProviders(ctx context.Context) error
- func (s *GormService) SystemDisable(ctx context.Context, identifier, reason string) error
- func (s *GormService) Update(ctx context.Context, identifier string, options UpdateOptions) (*models.ProviderInstance, error)
- type ImageGenerator
- type Moderator
- type Resolved
- type Speaker
- type Transcriber
- type UpdateOptions
- type VideoGenerator
- type VideoSubmitter
Constants ¶
const ( TypeCustom = "custom" TypeVirtual = "virtual" )
Built-in type keys served by Go code.
Variables ¶
var ErrNotRefreshable = errors.New("credential type does not support refresh")
ErrNotRefreshable is returned by Go adapters that never refresh credentials.
Functions ¶
This section is empty.
Types ¶
type Completer ¶ added in v0.1.2
type Completer interface {
Complete(ctx context.Context, req *models.ChatCompletionRequest, token *models.RouterToken) (*models.ChatCompletionResponse, error)
CompleteStream(ctx context.Context, req *models.ChatCompletionRequest, w io.Writer, token *models.RouterToken) error
// SubmitVideo routes one video generation submit and persists the
// router-side job row.
SubmitVideo(ctx context.Context, req *models.VideoGenerationRequest, token *models.RouterToken) (*models.VideoGenerationResponse, error)
}
Completer routes chat completions through single-pass delegation. It is implemented by the router service. Virtual models fan out through it instead of holding a concrete router dependency, breaking the provider → router → provider construction cycle.
type CreateOptions ¶
type CreateOptions struct {
Name string
TypeKey string
Qualifier string
Config map[string]any
IconURL string
}
CreateOptions holds parameters for creating a provider instance.
type Embedder ¶ added in v0.0.5
type Embedder interface {
Embed(ctx context.Context, credentials []*models.Credential, request *models.EmbeddingsRequest, providerConfig map[string]any) (*models.EmbeddingsResponse, error)
}
Embedder is an optional GoAdapter capability serving POST /v1/embeddings. Lua plugin types implement the equivalent via the embed handler.
type GoAdapter ¶
type GoAdapter interface {
TypeKey() string
ValidateCredentials(data map[string]any) error
Complete(ctx context.Context, credentials []*models.Credential, request *models.ChatCompletionRequest, providerConfig map[string]any) (*models.ChatCompletionResponse, error)
CompleteStream(ctx context.Context, credentials []*models.Credential, request *models.ChatCompletionRequest, w io.Writer, providerConfig map[string]any) error
NeedsRefresh(credential *models.Credential) bool
RefreshCredential(ctx context.Context, credential *models.Credential) (map[string]any, error)
GetModelInfos(ctx context.Context, credential *models.Credential, providerConfig map[string]any) ([]models.ModelInfo, error)
}
GoAdapter is implemented by built-in Go backends ("custom", "virtual"). Lua plugin types are served by luaplugin.Service instead.
Request methods take the whole sorted credential pool: the backend tries keys in order, at most once each, and returns a single result. Key-level failures never leave the backend; there are no repeat passes or backoff pauses in the request path.
type GormService ¶ added in v0.4.0
type GormService struct {
// contains filtered or unexported fields
}
GormService manages provider instances on the SQLite handle. It owns the provider registry: built-in Go adapters, the Lua plugin service for plugin-backed types, and the change callback. Traditional GORM use: none; every statement runs through gorm.G with typed clauses.
func NewGorm ¶ added in v0.4.0
func NewGorm(database *db.Database) *GormService
NewGorm constructs a GORM-backed provider service on the SQLite handle. Construction performs no I/O.
func (*GormService) ConfigSchema ¶ added in v0.4.0
func (s *GormService) ConfigSchema(typeKey, locale string) ([]*models.UINode, error)
ConfigSchema returns the config UI tree for a type key. Go types serve static trees; Lua types delegate to config_schema. ErrHandlerNotFound-equivalent (nil, nil) means "raw JSON fallback".
func (*GormService) Create ¶ added in v0.4.0
func (s *GormService) Create(ctx context.Context, options CreateOptions) (*models.ProviderInstance, error)
Create persists a new provider instance with a generated unique identifier. Validation mirrors the previous path: name and type key are required, the type key carries no slash or colon, custom rows normalize base_url. Singleton plugin types reuse the existing bare row instead of creating a duplicate. One transaction holds the reuse check, the uniqueness loop, and the insert on the transaction handle only.
func (*GormService) CredentialSchema ¶ added in v0.4.0
func (s *GormService) CredentialSchema(typeKey, locale string) ([]*models.UINode, error)
CredentialSchema returns the credential UI tree for a type key.
func (*GormService) CredentialsEnabled ¶ added in v0.4.0
func (s *GormService) CredentialsEnabled(typeKey string) bool
CredentialsEnabled reports whether a type serves the credential table: a credential_schema table or an auth flow is present.
func (*GormService) Delete ¶ added in v0.4.0
func (s *GormService) Delete(ctx context.Context, identifier string) error
Delete removes a provider in one delete. Credential, model override, managed virtual model, and virtual member rows cascade from the foreign keys; cached park, health, and model info rows reference the provider softly across files and clear explicitly after the durable delete succeeds. A zero-row delete reports the not-found sentinel through the WithResult tracker.
func (*GormService) EnsureSeeded ¶ added in v0.4.0
func (s *GormService) EnsureSeeded(ctx context.Context) error
EnsureSeeded creates the virtual-models row and one provider row per enabled Lua plugin type key when none exists yet, keeping fresh installs routable without manual provider setup. Missing icons on existing rows are backfilled from the plugin; user-set icons are never overwritten. Seeded rows are marked UI-readonly; the virtual-models row is additionally UI-hidden.
func (*GormService) Get ¶ added in v0.4.0
func (s *GormService) Get(ctx context.Context, identifier string) (*models.ProviderInstance, error)
Get returns a provider instance by identifier. A miss reports the not-found sentinel with provider context.
func (*GormService) GetByType ¶ added in v0.4.0
func (s *GormService) GetByType(ctx context.Context, typeKey string) ([]*models.ProviderInstance, error)
GetByType returns all providers served by a type key, sorted by identifier.
func (*GormService) GetByTypeAndQualifier ¶ added in v0.4.0
func (s *GormService) GetByTypeAndQualifier(ctx context.Context, typeKey, qualifier string) (*models.ProviderInstance, error)
GetByTypeAndQualifier returns a specific provider by type and qualifier. The qualifier runs through the same slugify as identifier generation, so lookups use the stored form. Dedup-suffixed duplicates resolve only by exact identifier via Get.
func (*GormService) GoAdapterFor ¶ added in v0.4.0
func (s *GormService) GoAdapterFor(typeKey string) (GoAdapter, bool)
GoAdapterFor returns the Go backend for a type key, if one is registered.
func (*GormService) IsTypeAvailable ¶ added in v0.4.0
func (s *GormService) IsTypeAvailable(typeKey string) bool
IsTypeAvailable reports whether a backend serves typeKey right now: a built-in Go adapter or a currently registered Lua plugin type. Rows with unavailable types stay in the database so reinstalling the plugin restores them, but the dashboard hides them.
func (*GormService) JobSpecs ¶ added in v0.4.0
func (s *GormService) JobSpecs(typeKey string) map[string]luaplugin.JobSpec
JobSpecs returns the stored job schedules for a type key.
func (*GormService) List ¶ added in v0.4.0
func (s *GormService) List(ctx context.Context) ([]*models.ProviderInstance, error)
List returns all provider instances sorted by identifier.
func (*GormService) LuaService ¶ added in v0.4.0
func (s *GormService) LuaService() *luaplugin.Service
LuaService returns the wired Lua plugin service, if any.
func (*GormService) ProxiesEnabled ¶ added in v0.4.0
func (s *GormService) ProxiesEnabled(typeKey string) bool
ProxiesEnabled reports whether a type serves proxy settings.
func (*GormService) ProxySchema ¶ added in v0.4.0
func (s *GormService) ProxySchema(typeKey, locale string) ([]*models.UINode, error)
ProxySchema returns the extra proxy settings UI tree for a type key. Nil means the plugin declares no proxy surface.
func (*GormService) RegisterGoAdapter ¶ added in v0.4.0
func (s *GormService) RegisterGoAdapter(adapter GoAdapter)
RegisterGoAdapter registers a built-in Go backend.
func (*GormService) SetLogger ¶ added in v0.4.0
func (s *GormService) SetLogger(l *slog.Logger)
SetLogger wires structured logging for CRUD.
func (*GormService) SetLuaService ¶ added in v0.4.0
func (s *GormService) SetLuaService(service *luaplugin.Service)
SetLuaService wires the Lua plugin service for plugin-backed types.
func (*GormService) SetOnChanged ¶ added in v0.4.0
func (s *GormService) SetOnChanged(function func(providerID string))
SetOnChanged registers a callback fired after provider create/update/delete.
func (*GormService) SettingsSchema ¶ added in v0.4.0
func (s *GormService) SettingsSchema(typeKey, locale string) ([]*models.UINode, error)
SettingsSchema returns the plugin settings UI tree for a type key. Nil means the plugin declares no settings section.
func (*GormService) SupportsAuthFlow ¶ added in v0.4.0
func (s *GormService) SupportsAuthFlow(typeKey string) bool
SupportsAuthFlow reports whether a type offers a multi-step auth wizard.
func (*GormService) SyncDefaultProviders ¶ added in v0.4.0
func (s *GormService) SyncDefaultProviders(ctx context.Context) error
SyncDefaultProviders seeds the built-in provider rows. Runtime plugin changes call it so newly installed types gain their default rows.
func (*GormService) SystemDisable ¶ added in v0.4.0
func (s *GormService) SystemDisable(ctx context.Context, identifier, reason string) error
SystemDisable disables a provider on explicit system request. First wins: an already-disabled provider keeps its original cause. One transaction holds the read-modify-write on the transaction handle only.
func (*GormService) Update ¶ added in v0.4.0
func (s *GormService) Update(ctx context.Context, identifier string, options UpdateOptions) (*models.ProviderInstance, error)
Update replaces a provider mutable fields. Custom rows normalize base_url when a configuration reads present. The disabled toggle sets the admin cause on disable and clears it on re-enable. One transaction holds the read-modify-write on the transaction handle only.
type ImageGenerator ¶ added in v0.0.5
type ImageGenerator interface {
GenerateImage(ctx context.Context, credentials []*models.Credential, request *models.ImageGenerationRequest, providerConfig map[string]any) (*models.ImageGenerationResponse, error)
}
ImageGenerator is an optional GoAdapter capability serving POST /v1/images/generations. Lua plugin types implement the equivalent via the generate_image handler.
type Moderator ¶ added in v0.3.8
type Moderator interface {
Moderate(ctx context.Context, credentials []*models.Credential, request *models.ModerationRequest, providerConfig map[string]any) (*models.ModerationResponse, error)
}
Moderator is an optional GoAdapter capability serving POST /v1/moderations. Lua plugin types implement the equivalent via the moderate handler.
type Resolved ¶
type Resolved struct {
Instance *models.ProviderInstance
Plugin *luaplugin.PluginRecord
Go GoAdapter
}
Resolved is the dispatch bundle for one provider: its instance plus either a Lua plugin record or a built-in Go adapter.
type Speaker ¶ added in v0.0.5
type Speaker interface {
Speech(ctx context.Context, credentials []*models.Credential, request *models.SpeechRequest, providerConfig map[string]any) (*models.SpeechResponse, error)
}
Speaker is an optional GoAdapter capability serving POST /v1/audio/speech. Lua plugin types implement the equivalent via the speech handler.
type Transcriber ¶ added in v0.0.5
type Transcriber interface {
Transcribe(ctx context.Context, credentials []*models.Credential, request *models.TranscriptionRequest, providerConfig map[string]any) (*models.TranscriptionResponse, error)
}
Transcriber is an optional GoAdapter capability serving POST /v1/audio/transcriptions. Lua plugin types implement the equivalent via the transcribe handler.
type UpdateOptions ¶
UpdateOptions holds mutable provider fields.
type VideoGenerator ¶ added in v0.3.8
type VideoGenerator interface {
VideoSubmitter
PollVideo(ctx context.Context, credentials []*models.Credential, model models.ModelId, upstreamJobID string, providerConfig map[string]any) (*models.VideoGenerationResponse, error)
VideoContent(ctx context.Context, credentials []*models.Credential, model models.ModelId, upstreamJobID string, index int, providerConfig map[string]any) (*models.VideoContentResponse, error)
}
VideoGenerator is an optional GoAdapter capability serving /v1/videos. Lua plugin types implement the equivalent via the generate_video, poll_video and video_content handlers.
type VideoSubmitter ¶ added in v0.3.8
type VideoSubmitter interface {
SubmitVideo(ctx context.Context, credentials []*models.Credential, request *models.VideoGenerationRequest, providerConfig map[string]any) (*models.VideoGenerationResponse, error)
}
VideoSubmitter is the narrow video capability virtual fan-out needs: submit one video job. Full backends implement VideoGenerator.