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
+296 -172
View File
@@ -45,21 +45,27 @@ func (q *Queries) CountModelsByType(ctx context.Context, type_ string) (int64, e
}
const createLlmProvider = `-- name: CreateLlmProvider :one
INSERT INTO llm_providers (name, base_url, api_key, metadata)
INSERT INTO llm_providers (name, base_url, api_key, client_type, icon, enable, metadata)
VALUES (
$1,
$2,
$3,
$4
$4,
$5,
$6,
$7
)
RETURNING id, name, base_url, api_key, metadata, created_at, updated_at
RETURNING id, name, base_url, api_key, icon, enable, metadata, created_at, updated_at, client_type
`
type CreateLlmProviderParams struct {
Name string `json:"name"`
BaseUrl string `json:"base_url"`
ApiKey string `json:"api_key"`
Metadata []byte `json:"metadata"`
Name string `json:"name"`
BaseUrl string `json:"base_url"`
ApiKey string `json:"api_key"`
ClientType string `json:"client_type"`
Icon pgtype.Text `json:"icon"`
Enable bool `json:"enable"`
Metadata []byte `json:"metadata"`
}
func (q *Queries) CreateLlmProvider(ctx context.Context, arg CreateLlmProviderParams) (LlmProvider, error) {
@@ -67,6 +73,9 @@ func (q *Queries) CreateLlmProvider(ctx context.Context, arg CreateLlmProviderPa
arg.Name,
arg.BaseUrl,
arg.ApiKey,
arg.ClientType,
arg.Icon,
arg.Enable,
arg.Metadata,
)
var i LlmProvider
@@ -75,37 +84,34 @@ func (q *Queries) CreateLlmProvider(ctx context.Context, arg CreateLlmProviderPa
&i.Name,
&i.BaseUrl,
&i.ApiKey,
&i.Icon,
&i.Enable,
&i.Metadata,
&i.CreatedAt,
&i.UpdatedAt,
&i.ClientType,
)
return i, err
}
const createModel = `-- name: CreateModel :one
INSERT INTO models (model_id, name, llm_provider_id, client_type, dimensions, input_modalities, supports_reasoning, type)
INSERT INTO models (model_id, name, llm_provider_id, type, config)
VALUES (
$1,
$2,
$3,
$4,
$5,
$6,
$7,
$8
$5
)
RETURNING id, model_id, name, llm_provider_id, client_type, dimensions, input_modalities, supports_reasoning, type, created_at, updated_at
RETURNING id, model_id, name, llm_provider_id, type, config, created_at, updated_at
`
type CreateModelParams struct {
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"`
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"`
}
func (q *Queries) CreateModel(ctx context.Context, arg CreateModelParams) (Model, error) {
@@ -113,11 +119,8 @@ func (q *Queries) CreateModel(ctx context.Context, arg CreateModelParams) (Model
arg.ModelID,
arg.Name,
arg.LlmProviderID,
arg.ClientType,
arg.Dimensions,
arg.InputModalities,
arg.SupportsReasoning,
arg.Type,
arg.Config,
)
var i Model
err := row.Scan(
@@ -125,11 +128,8 @@ func (q *Queries) CreateModel(ctx context.Context, arg CreateModelParams) (Model
&i.ModelID,
&i.Name,
&i.LlmProviderID,
&i.ClientType,
&i.Dimensions,
&i.InputModalities,
&i.SupportsReasoning,
&i.Type,
&i.Config,
&i.CreatedAt,
&i.UpdatedAt,
)
@@ -202,7 +202,7 @@ func (q *Queries) DeleteModelByModelID(ctx context.Context, modelID string) erro
}
const getLlmProviderByID = `-- name: GetLlmProviderByID :one
SELECT id, name, base_url, api_key, metadata, created_at, updated_at FROM llm_providers WHERE id = $1
SELECT id, name, base_url, api_key, icon, enable, metadata, created_at, updated_at, client_type FROM llm_providers WHERE id = $1
`
func (q *Queries) GetLlmProviderByID(ctx context.Context, id pgtype.UUID) (LlmProvider, error) {
@@ -213,15 +213,18 @@ func (q *Queries) GetLlmProviderByID(ctx context.Context, id pgtype.UUID) (LlmPr
&i.Name,
&i.BaseUrl,
&i.ApiKey,
&i.Icon,
&i.Enable,
&i.Metadata,
&i.CreatedAt,
&i.UpdatedAt,
&i.ClientType,
)
return i, err
}
const getLlmProviderByName = `-- name: GetLlmProviderByName :one
SELECT id, name, base_url, api_key, metadata, created_at, updated_at FROM llm_providers WHERE name = $1
SELECT id, name, base_url, api_key, icon, enable, metadata, created_at, updated_at, client_type FROM llm_providers WHERE name = $1
`
func (q *Queries) GetLlmProviderByName(ctx context.Context, name string) (LlmProvider, error) {
@@ -232,15 +235,18 @@ func (q *Queries) GetLlmProviderByName(ctx context.Context, name string) (LlmPro
&i.Name,
&i.BaseUrl,
&i.ApiKey,
&i.Icon,
&i.Enable,
&i.Metadata,
&i.CreatedAt,
&i.UpdatedAt,
&i.ClientType,
)
return i, err
}
const getModelByID = `-- name: GetModelByID :one
SELECT id, model_id, name, llm_provider_id, client_type, dimensions, input_modalities, supports_reasoning, type, created_at, updated_at FROM models WHERE id = $1
SELECT id, model_id, name, llm_provider_id, type, config, created_at, updated_at FROM models WHERE id = $1
`
func (q *Queries) GetModelByID(ctx context.Context, id pgtype.UUID) (Model, error) {
@@ -251,11 +257,8 @@ func (q *Queries) GetModelByID(ctx context.Context, id pgtype.UUID) (Model, erro
&i.ModelID,
&i.Name,
&i.LlmProviderID,
&i.ClientType,
&i.Dimensions,
&i.InputModalities,
&i.SupportsReasoning,
&i.Type,
&i.Config,
&i.CreatedAt,
&i.UpdatedAt,
)
@@ -263,7 +266,7 @@ func (q *Queries) GetModelByID(ctx context.Context, id pgtype.UUID) (Model, erro
}
const getModelByModelID = `-- name: GetModelByModelID :one
SELECT id, model_id, name, llm_provider_id, client_type, dimensions, input_modalities, supports_reasoning, type, created_at, updated_at FROM models WHERE model_id = $1
SELECT id, model_id, name, llm_provider_id, type, config, created_at, updated_at FROM models WHERE model_id = $1
`
func (q *Queries) GetModelByModelID(ctx context.Context, modelID string) (Model, error) {
@@ -274,19 +277,129 @@ func (q *Queries) GetModelByModelID(ctx context.Context, modelID string) (Model,
&i.ModelID,
&i.Name,
&i.LlmProviderID,
&i.ClientType,
&i.Dimensions,
&i.InputModalities,
&i.SupportsReasoning,
&i.Type,
&i.Config,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const listEnabledModels = `-- name: ListEnabledModels :many
SELECT m.id, m.model_id, m.name, m.llm_provider_id, m.type, m.config, m.created_at, m.updated_at
FROM models m
JOIN llm_providers p ON m.llm_provider_id = p.id
WHERE p.enable = true
ORDER BY m.created_at DESC
`
func (q *Queries) ListEnabledModels(ctx context.Context) ([]Model, error) {
rows, err := q.db.Query(ctx, listEnabledModels)
if err != nil {
return nil, err
}
defer rows.Close()
var items []Model
for rows.Next() {
var i Model
if err := rows.Scan(
&i.ID,
&i.ModelID,
&i.Name,
&i.LlmProviderID,
&i.Type,
&i.Config,
&i.CreatedAt,
&i.UpdatedAt,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const listEnabledModelsByProviderClientType = `-- name: ListEnabledModelsByProviderClientType :many
SELECT m.id, m.model_id, m.name, m.llm_provider_id, m.type, m.config, m.created_at, m.updated_at
FROM models m
JOIN llm_providers p ON m.llm_provider_id = p.id
WHERE p.enable = true
AND p.client_type = $1
ORDER BY m.created_at DESC
`
func (q *Queries) ListEnabledModelsByProviderClientType(ctx context.Context, clientType string) ([]Model, error) {
rows, err := q.db.Query(ctx, listEnabledModelsByProviderClientType, clientType)
if err != nil {
return nil, err
}
defer rows.Close()
var items []Model
for rows.Next() {
var i Model
if err := rows.Scan(
&i.ID,
&i.ModelID,
&i.Name,
&i.LlmProviderID,
&i.Type,
&i.Config,
&i.CreatedAt,
&i.UpdatedAt,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const listEnabledModelsByType = `-- name: ListEnabledModelsByType :many
SELECT m.id, m.model_id, m.name, m.llm_provider_id, m.type, m.config, m.created_at, m.updated_at
FROM models m
JOIN llm_providers p ON m.llm_provider_id = p.id
WHERE p.enable = true
AND m.type = $1
ORDER BY m.created_at DESC
`
func (q *Queries) ListEnabledModelsByType(ctx context.Context, type_ string) ([]Model, error) {
rows, err := q.db.Query(ctx, listEnabledModelsByType, type_)
if err != nil {
return nil, err
}
defer rows.Close()
var items []Model
for rows.Next() {
var i Model
if err := rows.Scan(
&i.ID,
&i.ModelID,
&i.Name,
&i.LlmProviderID,
&i.Type,
&i.Config,
&i.CreatedAt,
&i.UpdatedAt,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const listLlmProviders = `-- name: ListLlmProviders :many
SELECT id, name, base_url, api_key, metadata, created_at, updated_at FROM llm_providers
SELECT id, name, base_url, api_key, icon, enable, metadata, created_at, updated_at, client_type FROM llm_providers
ORDER BY created_at DESC
`
@@ -304,9 +417,12 @@ func (q *Queries) ListLlmProviders(ctx context.Context) ([]LlmProvider, error) {
&i.Name,
&i.BaseUrl,
&i.ApiKey,
&i.Icon,
&i.Enable,
&i.Metadata,
&i.CreatedAt,
&i.UpdatedAt,
&i.ClientType,
); err != nil {
return nil, err
}
@@ -353,7 +469,7 @@ func (q *Queries) ListModelVariantsByModelUUID(ctx context.Context, modelUuid pg
}
const listModels = `-- name: ListModels :many
SELECT id, model_id, name, llm_provider_id, client_type, dimensions, input_modalities, supports_reasoning, type, created_at, updated_at FROM models
SELECT id, model_id, name, llm_provider_id, type, config, created_at, updated_at FROM models
ORDER BY created_at DESC
`
@@ -371,49 +487,8 @@ func (q *Queries) ListModels(ctx context.Context) ([]Model, error) {
&i.ModelID,
&i.Name,
&i.LlmProviderID,
&i.ClientType,
&i.Dimensions,
&i.InputModalities,
&i.SupportsReasoning,
&i.Type,
&i.CreatedAt,
&i.UpdatedAt,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const listModelsByClientType = `-- name: ListModelsByClientType :many
SELECT id, model_id, name, llm_provider_id, client_type, dimensions, input_modalities, supports_reasoning, type, created_at, updated_at FROM models
WHERE client_type = $1
ORDER BY created_at DESC
`
func (q *Queries) ListModelsByClientType(ctx context.Context, clientType pgtype.Text) ([]Model, error) {
rows, err := q.db.Query(ctx, listModelsByClientType, clientType)
if err != nil {
return nil, err
}
defer rows.Close()
var items []Model
for rows.Next() {
var i Model
if err := rows.Scan(
&i.ID,
&i.ModelID,
&i.Name,
&i.LlmProviderID,
&i.ClientType,
&i.Dimensions,
&i.InputModalities,
&i.SupportsReasoning,
&i.Type,
&i.Config,
&i.CreatedAt,
&i.UpdatedAt,
); err != nil {
@@ -428,7 +503,7 @@ func (q *Queries) ListModelsByClientType(ctx context.Context, clientType pgtype.
}
const listModelsByModelID = `-- name: ListModelsByModelID :many
SELECT id, model_id, name, llm_provider_id, client_type, dimensions, input_modalities, supports_reasoning, type, created_at, updated_at FROM models
SELECT id, model_id, name, llm_provider_id, type, config, created_at, updated_at FROM models
WHERE model_id = $1
ORDER BY created_at DESC
`
@@ -447,11 +522,45 @@ func (q *Queries) ListModelsByModelID(ctx context.Context, modelID string) ([]Mo
&i.ModelID,
&i.Name,
&i.LlmProviderID,
&i.ClientType,
&i.Dimensions,
&i.InputModalities,
&i.SupportsReasoning,
&i.Type,
&i.Config,
&i.CreatedAt,
&i.UpdatedAt,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const listModelsByProviderClientType = `-- name: ListModelsByProviderClientType :many
SELECT m.id, m.model_id, m.name, m.llm_provider_id, m.type, m.config, m.created_at, m.updated_at
FROM models m
JOIN llm_providers p ON m.llm_provider_id = p.id
WHERE p.client_type = $1
ORDER BY m.created_at DESC
`
func (q *Queries) ListModelsByProviderClientType(ctx context.Context, clientType string) ([]Model, error) {
rows, err := q.db.Query(ctx, listModelsByProviderClientType, clientType)
if err != nil {
return nil, err
}
defer rows.Close()
var items []Model
for rows.Next() {
var i Model
if err := rows.Scan(
&i.ID,
&i.ModelID,
&i.Name,
&i.LlmProviderID,
&i.Type,
&i.Config,
&i.CreatedAt,
&i.UpdatedAt,
); err != nil {
@@ -466,7 +575,7 @@ func (q *Queries) ListModelsByModelID(ctx context.Context, modelID string) ([]Mo
}
const listModelsByProviderID = `-- name: ListModelsByProviderID :many
SELECT id, model_id, name, llm_provider_id, client_type, dimensions, input_modalities, supports_reasoning, type, created_at, updated_at FROM models
SELECT id, model_id, name, llm_provider_id, type, config, created_at, updated_at FROM models
WHERE llm_provider_id = $1
ORDER BY created_at DESC
`
@@ -485,11 +594,8 @@ func (q *Queries) ListModelsByProviderID(ctx context.Context, llmProviderID pgty
&i.ModelID,
&i.Name,
&i.LlmProviderID,
&i.ClientType,
&i.Dimensions,
&i.InputModalities,
&i.SupportsReasoning,
&i.Type,
&i.Config,
&i.CreatedAt,
&i.UpdatedAt,
); err != nil {
@@ -504,7 +610,7 @@ func (q *Queries) ListModelsByProviderID(ctx context.Context, llmProviderID pgty
}
const listModelsByProviderIDAndType = `-- name: ListModelsByProviderIDAndType :many
SELECT id, model_id, name, llm_provider_id, client_type, dimensions, input_modalities, supports_reasoning, type, created_at, updated_at FROM models
SELECT id, model_id, name, llm_provider_id, type, config, created_at, updated_at FROM models
WHERE llm_provider_id = $1
AND type = $2
ORDER BY created_at DESC
@@ -529,11 +635,8 @@ func (q *Queries) ListModelsByProviderIDAndType(ctx context.Context, arg ListMod
&i.ModelID,
&i.Name,
&i.LlmProviderID,
&i.ClientType,
&i.Dimensions,
&i.InputModalities,
&i.SupportsReasoning,
&i.Type,
&i.Config,
&i.CreatedAt,
&i.UpdatedAt,
); err != nil {
@@ -548,7 +651,7 @@ func (q *Queries) ListModelsByProviderIDAndType(ctx context.Context, arg ListMod
}
const listModelsByType = `-- name: ListModelsByType :many
SELECT id, model_id, name, llm_provider_id, client_type, dimensions, input_modalities, supports_reasoning, type, created_at, updated_at FROM models
SELECT id, model_id, name, llm_provider_id, type, config, created_at, updated_at FROM models
WHERE type = $1
ORDER BY created_at DESC
`
@@ -567,11 +670,8 @@ func (q *Queries) ListModelsByType(ctx context.Context, type_ string) ([]Model,
&i.ModelID,
&i.Name,
&i.LlmProviderID,
&i.ClientType,
&i.Dimensions,
&i.InputModalities,
&i.SupportsReasoning,
&i.Type,
&i.Config,
&i.CreatedAt,
&i.UpdatedAt,
); err != nil {
@@ -591,18 +691,24 @@ SET
name = $1,
base_url = $2,
api_key = $3,
metadata = $4,
client_type = $4,
icon = $5,
enable = $6,
metadata = $7,
updated_at = now()
WHERE id = $5
RETURNING id, name, base_url, api_key, metadata, created_at, updated_at
WHERE id = $8
RETURNING id, name, base_url, api_key, icon, enable, metadata, created_at, updated_at, client_type
`
type UpdateLlmProviderParams struct {
Name string `json:"name"`
BaseUrl string `json:"base_url"`
ApiKey string `json:"api_key"`
Metadata []byte `json:"metadata"`
ID pgtype.UUID `json:"id"`
Name string `json:"name"`
BaseUrl string `json:"base_url"`
ApiKey string `json:"api_key"`
ClientType string `json:"client_type"`
Icon pgtype.Text `json:"icon"`
Enable bool `json:"enable"`
Metadata []byte `json:"metadata"`
ID pgtype.UUID `json:"id"`
}
func (q *Queries) UpdateLlmProvider(ctx context.Context, arg UpdateLlmProviderParams) (LlmProvider, error) {
@@ -610,6 +716,9 @@ func (q *Queries) UpdateLlmProvider(ctx context.Context, arg UpdateLlmProviderPa
arg.Name,
arg.BaseUrl,
arg.ApiKey,
arg.ClientType,
arg.Icon,
arg.Enable,
arg.Metadata,
arg.ID,
)
@@ -619,9 +728,12 @@ func (q *Queries) UpdateLlmProvider(ctx context.Context, arg UpdateLlmProviderPa
&i.Name,
&i.BaseUrl,
&i.ApiKey,
&i.Icon,
&i.Enable,
&i.Metadata,
&i.CreatedAt,
&i.UpdatedAt,
&i.ClientType,
)
return i, err
}
@@ -632,26 +744,20 @@ SET
model_id = $1,
name = $2,
llm_provider_id = $3,
client_type = $4,
dimensions = $5,
input_modalities = $6,
supports_reasoning = $7,
type = $8,
type = $4,
config = $5,
updated_at = now()
WHERE id = $9
RETURNING id, model_id, name, llm_provider_id, client_type, dimensions, input_modalities, supports_reasoning, type, created_at, updated_at
WHERE id = $6
RETURNING id, model_id, name, llm_provider_id, type, config, created_at, updated_at
`
type UpdateModelParams struct {
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"`
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"`
ID pgtype.UUID `json:"id"`
}
func (q *Queries) UpdateModel(ctx context.Context, arg UpdateModelParams) (Model, error) {
@@ -659,11 +765,8 @@ func (q *Queries) UpdateModel(ctx context.Context, arg UpdateModelParams) (Model
arg.ModelID,
arg.Name,
arg.LlmProviderID,
arg.ClientType,
arg.Dimensions,
arg.InputModalities,
arg.SupportsReasoning,
arg.Type,
arg.Config,
arg.ID,
)
var i Model
@@ -672,56 +775,40 @@ func (q *Queries) UpdateModel(ctx context.Context, arg UpdateModelParams) (Model
&i.ModelID,
&i.Name,
&i.LlmProviderID,
&i.ClientType,
&i.Dimensions,
&i.InputModalities,
&i.SupportsReasoning,
&i.Type,
&i.Config,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const updateModelByModelID = `-- name: UpdateModelByModelID :one
UPDATE models
SET
model_id = $1,
name = $2,
llm_provider_id = $3,
client_type = $4,
dimensions = $5,
input_modalities = $6,
supports_reasoning = $7,
type = $8,
const upsertRegistryModel = `-- name: UpsertRegistryModel :one
INSERT INTO models (model_id, name, llm_provider_id, type, config)
VALUES ($1, $2, $3, $4, $5)
ON CONFLICT (llm_provider_id, model_id) DO UPDATE SET
name = EXCLUDED.name,
type = EXCLUDED.type,
config = EXCLUDED.config,
updated_at = now()
WHERE model_id = $9
RETURNING id, model_id, name, llm_provider_id, client_type, dimensions, input_modalities, supports_reasoning, type, created_at, updated_at
RETURNING id, model_id, name, llm_provider_id, type, config, created_at, updated_at
`
type UpdateModelByModelIDParams struct {
NewModelID string `json:"new_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"`
ModelID string `json:"model_id"`
type UpsertRegistryModelParams struct {
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"`
}
func (q *Queries) UpdateModelByModelID(ctx context.Context, arg UpdateModelByModelIDParams) (Model, error) {
row := q.db.QueryRow(ctx, updateModelByModelID,
arg.NewModelID,
func (q *Queries) UpsertRegistryModel(ctx context.Context, arg UpsertRegistryModelParams) (Model, error) {
row := q.db.QueryRow(ctx, upsertRegistryModel,
arg.ModelID,
arg.Name,
arg.LlmProviderID,
arg.ClientType,
arg.Dimensions,
arg.InputModalities,
arg.SupportsReasoning,
arg.Type,
arg.ModelID,
arg.Config,
)
var i Model
err := row.Scan(
@@ -729,13 +816,50 @@ func (q *Queries) UpdateModelByModelID(ctx context.Context, arg UpdateModelByMod
&i.ModelID,
&i.Name,
&i.LlmProviderID,
&i.ClientType,
&i.Dimensions,
&i.InputModalities,
&i.SupportsReasoning,
&i.Type,
&i.Config,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const upsertRegistryProvider = `-- name: UpsertRegistryProvider :one
INSERT INTO llm_providers (name, base_url, api_key, client_type, icon, enable, metadata)
VALUES ($1, $2, '', $3, $4, false, '{}')
ON CONFLICT (name) DO UPDATE SET
icon = EXCLUDED.icon,
client_type = EXCLUDED.client_type,
updated_at = now()
RETURNING id, name, base_url, api_key, icon, enable, metadata, created_at, updated_at, client_type
`
type UpsertRegistryProviderParams struct {
Name string `json:"name"`
BaseUrl string `json:"base_url"`
ClientType string `json:"client_type"`
Icon pgtype.Text `json:"icon"`
}
func (q *Queries) UpsertRegistryProvider(ctx context.Context, arg UpsertRegistryProviderParams) (LlmProvider, error) {
row := q.db.QueryRow(ctx, upsertRegistryProvider,
arg.Name,
arg.BaseUrl,
arg.ClientType,
arg.Icon,
)
var i LlmProvider
err := row.Scan(
&i.ID,
&i.Name,
&i.BaseUrl,
&i.ApiKey,
&i.Icon,
&i.Enable,
&i.Metadata,
&i.CreatedAt,
&i.UpdatedAt,
&i.ClientType,
)
return i, err
}