refactor: provider & models (#277)

* refactor: move client_type to provider, replace model fields with config JSONB

- Move `client_type` from `models` to `llm_providers` table
- Add `icon` field to `llm_providers`
- Replace `dimensions`, `input_modalities`, `supports_reasoning` on `models`
  with a single `config` JSONB column containing `dimensions`,
  `compatibilities` (vision, tool-call, image-output, reasoning),
  and `context_window`
- Auto-imported models default to vision + tool-call + reasoning
- Update all backend consumers (agent, flow resolver, handlers, memory)
- Regenerate sqlc, swagger, and TypeScript SDK
- Update frontend forms, display, and i18n for new schema

* ui: show provider icon avatar in sidebar and detail header, remove icon input

* feat: add built-in provider registry with YAML definitions and enable toggle

- Add `enable` column to llm_providers (default true, backward-compatible)
- Create internal/registry package to load YAML provider/model definitions
  on startup and upsert into database (new providers disabled by default)
- Add conf/providers/ with OpenAI, Anthropic, Google YAML definitions
- Add RegistryConfig to TOML config (providers_dir, default conf/providers)
- Model listing APIs and conversation flow now filter by enabled providers
- Frontend: enable switch in provider form, green status dot in sidebar,
  enabled providers sorted to top

* fix: make 0041 migration idempotent for fresh databases

Guard data migration steps with column-existence checks so the
migration succeeds on databases created from the updated init schema.
This commit is contained in:
Acbox Liu
2026-03-22 17:24:45 +08:00
committed by GitHub
parent de62f94315
commit b88ca96064
60 changed files with 1599 additions and 1224 deletions
+21 -21
View File
@@ -27,12 +27,12 @@ type Bot struct {
HeartbeatInterval int32 `json:"heartbeat_interval"`
HeartbeatPrompt string `json:"heartbeat_prompt"`
HeartbeatModelID pgtype.UUID `json:"heartbeat_model_id"`
TitleModelID pgtype.UUID `json:"title_model_id"`
TtsModelID pgtype.UUID `json:"tts_model_id"`
BrowserContextID pgtype.UUID `json:"browser_context_id"`
CompactionEnabled bool `json:"compaction_enabled"`
CompactionThreshold int32 `json:"compaction_threshold"`
CompactionModelID pgtype.UUID `json:"compaction_model_id"`
TitleModelID pgtype.UUID `json:"title_model_id"`
TtsModelID pgtype.UUID `json:"tts_model_id"`
BrowserContextID pgtype.UUID `json:"browser_context_id"`
Metadata []byte `json:"metadata"`
CreatedAt pgtype.Timestamptz `json:"created_at"`
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
@@ -278,13 +278,16 @@ type LifecycleEvent struct {
}
type LlmProvider struct {
ID pgtype.UUID `json:"id"`
Name string `json:"name"`
BaseUrl string `json:"base_url"`
ApiKey string `json:"api_key"`
Metadata []byte `json:"metadata"`
CreatedAt pgtype.Timestamptz `json:"created_at"`
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
ID pgtype.UUID `json:"id"`
Name string `json:"name"`
BaseUrl string `json:"base_url"`
ApiKey string `json:"api_key"`
Icon pgtype.Text `json:"icon"`
Enable bool `json:"enable"`
Metadata []byte `json:"metadata"`
CreatedAt pgtype.Timestamptz `json:"created_at"`
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
ClientType string `json:"client_type"`
}
type McpConnection struct {
@@ -355,17 +358,14 @@ type MemoryProvider struct {
}
type Model struct {
ID pgtype.UUID `json:"id"`
ModelID string `json:"model_id"`
Name pgtype.Text `json:"name"`
LlmProviderID pgtype.UUID `json:"llm_provider_id"`
ClientType pgtype.Text `json:"client_type"`
Dimensions pgtype.Int4 `json:"dimensions"`
InputModalities []string `json:"input_modalities"`
SupportsReasoning bool `json:"supports_reasoning"`
Type string `json:"type"`
CreatedAt pgtype.Timestamptz `json:"created_at"`
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
ID pgtype.UUID `json:"id"`
ModelID string `json:"model_id"`
Name pgtype.Text `json:"name"`
LlmProviderID pgtype.UUID `json:"llm_provider_id"`
Type string `json:"type"`
Config []byte `json:"config"`
CreatedAt pgtype.Timestamptz `json:"created_at"`
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
}
type ModelVariant struct {