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
+7 -20
View File
@@ -62,9 +62,9 @@ func (q *Queries) CompleteCompactionLog(ctx context.Context, arg CompleteCompact
}
const createCompactionLog = `-- name: CreateCompactionLog :one
INSERT INTO bot_history_message_compacts (bot_id, session_id, started_at)
VALUES ($1, $2::uuid, now())
RETURNING id, bot_id, session_id, status, summary, message_count, error_message, usage, started_at, completed_at
INSERT INTO bot_history_message_compacts (bot_id, session_id)
VALUES ($1, $2)
RETURNING id, bot_id, session_id, status, summary, message_count, error_message, usage, model_id, started_at, completed_at
`
type CreateCompactionLogParams struct {
@@ -72,22 +72,9 @@ type CreateCompactionLogParams struct {
SessionID pgtype.UUID `json:"session_id"`
}
type CreateCompactionLogRow struct {
ID pgtype.UUID `json:"id"`
BotID pgtype.UUID `json:"bot_id"`
SessionID pgtype.UUID `json:"session_id"`
Status string `json:"status"`
Summary string `json:"summary"`
MessageCount int32 `json:"message_count"`
ErrorMessage string `json:"error_message"`
Usage []byte `json:"usage"`
StartedAt pgtype.Timestamptz `json:"started_at"`
CompletedAt pgtype.Timestamptz `json:"completed_at"`
}
func (q *Queries) CreateCompactionLog(ctx context.Context, arg CreateCompactionLogParams) (CreateCompactionLogRow, error) {
func (q *Queries) CreateCompactionLog(ctx context.Context, arg CreateCompactionLogParams) (BotHistoryMessageCompact, error) {
row := q.db.QueryRow(ctx, createCompactionLog, arg.BotID, arg.SessionID)
var i CreateCompactionLogRow
var i BotHistoryMessageCompact
err := row.Scan(
&i.ID,
&i.BotID,
@@ -97,6 +84,7 @@ func (q *Queries) CreateCompactionLog(ctx context.Context, arg CreateCompactionL
&i.MessageCount,
&i.ErrorMessage,
&i.Usage,
&i.ModelID,
&i.StartedAt,
&i.CompletedAt,
)
@@ -141,7 +129,7 @@ const listCompactionLogsByBot = `-- name: ListCompactionLogsByBot :many
SELECT id, bot_id, session_id, status, summary, message_count, error_message, usage, model_id, started_at, completed_at
FROM bot_history_message_compacts
WHERE bot_id = $1
AND ($2::timestamptz IS NULL OR started_at < $2::timestamptz)
AND ($2::timestamptz IS NULL OR started_at < $2)
ORDER BY started_at DESC
LIMIT $3
`
@@ -188,7 +176,6 @@ const listCompactionLogsBySession = `-- name: ListCompactionLogsBySession :many
SELECT id, bot_id, session_id, status, summary, message_count, error_message, usage, model_id, started_at, completed_at
FROM bot_history_message_compacts
WHERE session_id = $1
AND status = 'ok'
ORDER BY started_at ASC
`