refactor: unify providers and models tables (#338)

* refactor: unify providers and models tables

- Rename `llm_providers` → `providers`, `llm_provider_oauth_tokens` → `provider_oauth_tokens`
- Remove `tts_providers` and `tts_models` tables; speech models now live in the unified `models` table with `type = 'speech'`
- Replace top-level `api_key`/`base_url` columns with a JSONB `config` field on `providers`
- Rename `llm_provider_id` → `provider_id` across all references
- Add `edge-speech` client type and `conf/providers/edge.yaml` default provider
- Create new read-only speech endpoints (`/speech-providers`, `/speech-models`) backed by filtered views of the unified tables
- Remove old TTS CRUD handlers; simplify speech page to read-only + test
- Update registry loader to skip malformed YAML files instead of failing entirely
- Fix YAML quoting for model names containing colons in openrouter.yaml
- Regenerate sqlc, swagger, and TypeScript SDK

* fix: exclude speech providers from providers list endpoint

ListProviders now filters out client_type matching '%-speech' so Edge
and future speech providers no longer appear on the Providers page.
ListSpeechProviders uses the same pattern match instead of hard-coding
'edge-speech'.

* fix: use explicit client_type list instead of LIKE pattern

Replace '%-speech' pattern with explicit IN ('edge-speech') for both
ListProviders (exclusion) and ListSpeechProviders (inclusion). New
speech client types must be added to both queries.

* fix: use EXECUTE for dynamic SQL in migrations referencing old schema

PL/pgSQL pre-validates column/table references in static SQL statements
inside DO blocks before evaluating IF/RETURN guards. This caused
migrations 0010-0061 to fail on fresh databases where the canonical
schema uses `providers`/`provider_id` instead of `llm_providers`/
`llm_provider_id`.

Wrap all SQL that references potentially non-existent old schema objects
(llm_providers, llm_provider_id, tts_providers, tts_models, etc.) in
EXECUTE strings so they are only parsed at runtime when actually reached.

* fix: revert canonical schema to use llm_providers for migration compatibility

The CI migrations workflow (up → down → up) failed because 0061 down
renames `providers` back to `llm_providers`, but 0001 down only dropped
`providers` — leaving `llm_providers` as a remnant. On the second
migrate up, 0010 found the stale `llm_providers` and tried to reference
`models.llm_provider_id` which no longer existed.

Revert 0001 canonical schema to use original names (llm_providers,
tts_providers, tts_models) so incremental migrations work naturally and
0061 handles the final rename. Remove EXECUTE wrappers and unnecessary
guards from migrations that now always operate on llm_providers.

* fix: icons

* fix: sync canonical schema with 0061 migration to fix sqlc column mismatch

0001_init.up.sql still used old names (llm_providers, llm_provider_id)
and included dropped tts_providers/tts_models tables. sqlc could not
parse the PL/pgSQL EXECUTE in migration 0061, so generated code retained
stale columns (input_modalities, supports_reasoning) causing runtime
"column does not exist" errors when adding models.

- Update 0001_init.up.sql to current schema (providers, provider_id,
  no tts tables, add provider_oauth_tokens)
- Use ALTER TABLE IF EXISTS in 0010/0041/0042 for backward compat
- Regenerate sqlc

* fix: guard all legacy migrations against fresh schema for CI compat

On fresh databases, 0001_init.up.sql creates providers/provider_id
(not llm_providers/llm_provider_id). Migrations 0013, 0041, 0046, 0047
referenced the old names without guards, causing CI migration failures.

- 0013: check llm_provider_id column exists before adding old constraint
- 0041: check llm_providers table exists before backfill/constraint DDL
- 0046: wrap CREATE TABLE in DO block with llm_providers existence check
- 0047: use ALTER TABLE IF EXISTS + DO block guard
This commit is contained in:
Acbox Liu
2026-04-08 01:03:44 +08:00
committed by GitHub
parent 43c4153938
commit 8d5c38f0e5
78 changed files with 3163 additions and 5668 deletions
-163
View File
@@ -1,163 +0,0 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.30.0
// source: llm_provider_oauth.sql
package sqlc
import (
"context"
"github.com/jackc/pgx/v5/pgtype"
)
const deleteLlmProviderOAuthToken = `-- name: DeleteLlmProviderOAuthToken :exec
DELETE FROM llm_provider_oauth_tokens WHERE llm_provider_id = $1
`
func (q *Queries) DeleteLlmProviderOAuthToken(ctx context.Context, llmProviderID pgtype.UUID) error {
_, err := q.db.Exec(ctx, deleteLlmProviderOAuthToken, llmProviderID)
return err
}
const getLlmProviderOAuthTokenByProvider = `-- name: GetLlmProviderOAuthTokenByProvider :one
SELECT id, llm_provider_id, access_token, refresh_token, expires_at, scope, token_type, state, pkce_code_verifier, created_at, updated_at FROM llm_provider_oauth_tokens WHERE llm_provider_id = $1
`
func (q *Queries) GetLlmProviderOAuthTokenByProvider(ctx context.Context, llmProviderID pgtype.UUID) (LlmProviderOauthToken, error) {
row := q.db.QueryRow(ctx, getLlmProviderOAuthTokenByProvider, llmProviderID)
var i LlmProviderOauthToken
err := row.Scan(
&i.ID,
&i.LlmProviderID,
&i.AccessToken,
&i.RefreshToken,
&i.ExpiresAt,
&i.Scope,
&i.TokenType,
&i.State,
&i.PkceCodeVerifier,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const getLlmProviderOAuthTokenByState = `-- name: GetLlmProviderOAuthTokenByState :one
SELECT id, llm_provider_id, access_token, refresh_token, expires_at, scope, token_type, state, pkce_code_verifier, created_at, updated_at FROM llm_provider_oauth_tokens WHERE state = $1 AND state != ''
`
func (q *Queries) GetLlmProviderOAuthTokenByState(ctx context.Context, state string) (LlmProviderOauthToken, error) {
row := q.db.QueryRow(ctx, getLlmProviderOAuthTokenByState, state)
var i LlmProviderOauthToken
err := row.Scan(
&i.ID,
&i.LlmProviderID,
&i.AccessToken,
&i.RefreshToken,
&i.ExpiresAt,
&i.Scope,
&i.TokenType,
&i.State,
&i.PkceCodeVerifier,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const updateLlmProviderOAuthState = `-- name: UpdateLlmProviderOAuthState :exec
INSERT INTO llm_provider_oauth_tokens (llm_provider_id, state, pkce_code_verifier)
VALUES (
$1,
$2,
$3
)
ON CONFLICT (llm_provider_id) DO UPDATE SET
state = EXCLUDED.state,
pkce_code_verifier = EXCLUDED.pkce_code_verifier,
updated_at = now()
`
type UpdateLlmProviderOAuthStateParams struct {
LlmProviderID pgtype.UUID `json:"llm_provider_id"`
State string `json:"state"`
PkceCodeVerifier string `json:"pkce_code_verifier"`
}
func (q *Queries) UpdateLlmProviderOAuthState(ctx context.Context, arg UpdateLlmProviderOAuthStateParams) error {
_, err := q.db.Exec(ctx, updateLlmProviderOAuthState, arg.LlmProviderID, arg.State, arg.PkceCodeVerifier)
return err
}
const upsertLlmProviderOAuthToken = `-- name: UpsertLlmProviderOAuthToken :one
INSERT INTO llm_provider_oauth_tokens (
llm_provider_id,
access_token,
refresh_token,
expires_at,
scope,
token_type,
state,
pkce_code_verifier
)
VALUES (
$1,
$2,
$3,
$4,
$5,
$6,
$7,
$8
)
ON CONFLICT (llm_provider_id) DO UPDATE SET
access_token = EXCLUDED.access_token,
refresh_token = EXCLUDED.refresh_token,
expires_at = EXCLUDED.expires_at,
scope = EXCLUDED.scope,
token_type = EXCLUDED.token_type,
state = EXCLUDED.state,
pkce_code_verifier = EXCLUDED.pkce_code_verifier,
updated_at = now()
RETURNING id, llm_provider_id, access_token, refresh_token, expires_at, scope, token_type, state, pkce_code_verifier, created_at, updated_at
`
type UpsertLlmProviderOAuthTokenParams struct {
LlmProviderID pgtype.UUID `json:"llm_provider_id"`
AccessToken string `json:"access_token"`
RefreshToken string `json:"refresh_token"`
ExpiresAt pgtype.Timestamptz `json:"expires_at"`
Scope string `json:"scope"`
TokenType string `json:"token_type"`
State string `json:"state"`
PkceCodeVerifier string `json:"pkce_code_verifier"`
}
func (q *Queries) UpsertLlmProviderOAuthToken(ctx context.Context, arg UpsertLlmProviderOAuthTokenParams) (LlmProviderOauthToken, error) {
row := q.db.QueryRow(ctx, upsertLlmProviderOAuthToken,
arg.LlmProviderID,
arg.AccessToken,
arg.RefreshToken,
arg.ExpiresAt,
arg.Scope,
arg.TokenType,
arg.State,
arg.PkceCodeVerifier,
)
var i LlmProviderOauthToken
err := row.Scan(
&i.ID,
&i.LlmProviderID,
&i.AccessToken,
&i.RefreshToken,
&i.ExpiresAt,
&i.Scope,
&i.TokenType,
&i.State,
&i.PkceCodeVerifier,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
+35 -36
View File
@@ -298,33 +298,6 @@ type LifecycleEvent struct {
CreatedAt pgtype.Timestamptz `json:"created_at"`
}
type LlmProvider struct {
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 LlmProviderOauthToken struct {
ID pgtype.UUID `json:"id"`
LlmProviderID pgtype.UUID `json:"llm_provider_id"`
AccessToken string `json:"access_token"`
RefreshToken string `json:"refresh_token"`
ExpiresAt pgtype.Timestamptz `json:"expires_at"`
Scope string `json:"scope"`
TokenType string `json:"token_type"`
State string `json:"state"`
PkceCodeVerifier string `json:"pkce_code_verifier"`
CreatedAt pgtype.Timestamptz `json:"created_at"`
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
}
type McpConnection struct {
ID pgtype.UUID `json:"id"`
BotID pgtype.UUID `json:"bot_id"`
@@ -393,14 +366,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"`
Type string `json:"type"`
Config []byte `json:"config"`
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"`
ProviderID pgtype.UUID `json:"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 {
@@ -413,6 +386,32 @@ type ModelVariant struct {
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
}
type Provider struct {
ID pgtype.UUID `json:"id"`
Name string `json:"name"`
ClientType string `json:"client_type"`
Icon pgtype.Text `json:"icon"`
Enable bool `json:"enable"`
Config []byte `json:"config"`
Metadata []byte `json:"metadata"`
CreatedAt pgtype.Timestamptz `json:"created_at"`
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
}
type ProviderOauthToken struct {
ID pgtype.UUID `json:"id"`
ProviderID pgtype.UUID `json:"provider_id"`
AccessToken string `json:"access_token"`
RefreshToken string `json:"refresh_token"`
ExpiresAt pgtype.Timestamptz `json:"expires_at"`
Scope string `json:"scope"`
TokenType string `json:"token_type"`
State string `json:"state"`
PkceCodeVerifier string `json:"pkce_code_verifier"`
CreatedAt pgtype.Timestamptz `json:"created_at"`
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
}
type Schedule struct {
ID pgtype.UUID `json:"id"`
Name string `json:"name"`
@@ -486,9 +485,9 @@ type TtsProvider struct {
Name string `json:"name"`
Provider string `json:"provider"`
Config []byte `json:"config"`
Enable bool `json:"enable"`
CreatedAt pgtype.Timestamptz `json:"created_at"`
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
Enable bool `json:"enable"`
}
type User struct {
+442 -258
View File
@@ -11,17 +11,6 @@ import (
"github.com/jackc/pgx/v5/pgtype"
)
const countLlmProviders = `-- name: CountLlmProviders :one
SELECT COUNT(*) FROM llm_providers
`
func (q *Queries) CountLlmProviders(ctx context.Context) (int64, error) {
row := q.db.QueryRow(ctx, countLlmProviders)
var count int64
err := row.Scan(&count)
return count, err
}
const countModels = `-- name: CountModels :one
SELECT COUNT(*) FROM models
`
@@ -44,58 +33,19 @@ func (q *Queries) CountModelsByType(ctx context.Context, type_ string) (int64, e
return count, err
}
const createLlmProvider = `-- name: CreateLlmProvider :one
INSERT INTO llm_providers (name, base_url, api_key, client_type, icon, enable, metadata)
VALUES (
$1,
$2,
$3,
$4,
$5,
$6,
$7
)
RETURNING id, name, base_url, api_key, icon, enable, metadata, created_at, updated_at, client_type
const countProviders = `-- name: CountProviders :one
SELECT COUNT(*) FROM providers
`
type CreateLlmProviderParams struct {
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) {
row := q.db.QueryRow(ctx, createLlmProvider,
arg.Name,
arg.BaseUrl,
arg.ApiKey,
arg.ClientType,
arg.Icon,
arg.Enable,
arg.Metadata,
)
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
func (q *Queries) CountProviders(ctx context.Context) (int64, error) {
row := q.db.QueryRow(ctx, countProviders)
var count int64
err := row.Scan(&count)
return count, err
}
const createModel = `-- name: CreateModel :one
INSERT INTO models (model_id, name, llm_provider_id, type, config)
INSERT INTO models (model_id, name, provider_id, type, config)
VALUES (
$1,
$2,
@@ -103,22 +53,22 @@ VALUES (
$4,
$5
)
RETURNING id, model_id, name, llm_provider_id, type, config, created_at, updated_at
RETURNING id, model_id, name, 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"`
Type string `json:"type"`
Config []byte `json:"config"`
ModelID string `json:"model_id"`
Name pgtype.Text `json:"name"`
ProviderID pgtype.UUID `json:"provider_id"`
Type string `json:"type"`
Config []byte `json:"config"`
}
func (q *Queries) CreateModel(ctx context.Context, arg CreateModelParams) (Model, error) {
row := q.db.QueryRow(ctx, createModel,
arg.ModelID,
arg.Name,
arg.LlmProviderID,
arg.ProviderID,
arg.Type,
arg.Config,
)
@@ -127,7 +77,7 @@ func (q *Queries) CreateModel(ctx context.Context, arg CreateModelParams) (Model
&i.ID,
&i.ModelID,
&i.Name,
&i.LlmProviderID,
&i.ProviderID,
&i.Type,
&i.Config,
&i.CreatedAt,
@@ -174,13 +124,50 @@ func (q *Queries) CreateModelVariant(ctx context.Context, arg CreateModelVariant
return i, err
}
const deleteLlmProvider = `-- name: DeleteLlmProvider :exec
DELETE FROM llm_providers WHERE id = $1
const createProvider = `-- name: CreateProvider :one
INSERT INTO providers (name, client_type, icon, enable, config, metadata)
VALUES (
$1,
$2,
$3,
$4,
$5,
$6
)
RETURNING id, name, client_type, icon, enable, config, metadata, created_at, updated_at
`
func (q *Queries) DeleteLlmProvider(ctx context.Context, id pgtype.UUID) error {
_, err := q.db.Exec(ctx, deleteLlmProvider, id)
return err
type CreateProviderParams struct {
Name string `json:"name"`
ClientType string `json:"client_type"`
Icon pgtype.Text `json:"icon"`
Enable bool `json:"enable"`
Config []byte `json:"config"`
Metadata []byte `json:"metadata"`
}
func (q *Queries) CreateProvider(ctx context.Context, arg CreateProviderParams) (Provider, error) {
row := q.db.QueryRow(ctx, createProvider,
arg.Name,
arg.ClientType,
arg.Icon,
arg.Enable,
arg.Config,
arg.Metadata,
)
var i Provider
err := row.Scan(
&i.ID,
&i.Name,
&i.ClientType,
&i.Icon,
&i.Enable,
&i.Config,
&i.Metadata,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const deleteModel = `-- name: DeleteModel :exec
@@ -201,52 +188,17 @@ func (q *Queries) DeleteModelByModelID(ctx context.Context, modelID string) erro
return err
}
const getLlmProviderByID = `-- name: GetLlmProviderByID :one
SELECT id, name, base_url, api_key, icon, enable, metadata, created_at, updated_at, client_type FROM llm_providers WHERE id = $1
const deleteProvider = `-- name: DeleteProvider :exec
DELETE FROM providers WHERE id = $1
`
func (q *Queries) GetLlmProviderByID(ctx context.Context, id pgtype.UUID) (LlmProvider, error) {
row := q.db.QueryRow(ctx, getLlmProviderByID, id)
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
}
const getLlmProviderByName = `-- name: GetLlmProviderByName :one
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) {
row := q.db.QueryRow(ctx, getLlmProviderByName, name)
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
func (q *Queries) DeleteProvider(ctx context.Context, id pgtype.UUID) error {
_, err := q.db.Exec(ctx, deleteProvider, id)
return err
}
const getModelByID = `-- name: GetModelByID :one
SELECT id, model_id, name, llm_provider_id, type, config, created_at, updated_at FROM models WHERE id = $1
SELECT id, model_id, name, 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) {
@@ -256,7 +208,7 @@ func (q *Queries) GetModelByID(ctx context.Context, id pgtype.UUID) (Model, erro
&i.ID,
&i.ModelID,
&i.Name,
&i.LlmProviderID,
&i.ProviderID,
&i.Type,
&i.Config,
&i.CreatedAt,
@@ -266,7 +218,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, type, config, created_at, updated_at FROM models WHERE model_id = $1
SELECT id, model_id, name, 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) {
@@ -276,7 +228,7 @@ func (q *Queries) GetModelByModelID(ctx context.Context, modelID string) (Model,
&i.ID,
&i.ModelID,
&i.Name,
&i.LlmProviderID,
&i.ProviderID,
&i.Type,
&i.Config,
&i.CreatedAt,
@@ -285,10 +237,119 @@ func (q *Queries) GetModelByModelID(ctx context.Context, modelID string) (Model,
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
const getModelByProviderAndModelID = `-- name: GetModelByProviderAndModelID :one
SELECT id, model_id, name, provider_id, type, config, created_at, updated_at FROM models
WHERE provider_id = $1
AND model_id = $2
LIMIT 1
`
type GetModelByProviderAndModelIDParams struct {
ProviderID pgtype.UUID `json:"provider_id"`
ModelID string `json:"model_id"`
}
func (q *Queries) GetModelByProviderAndModelID(ctx context.Context, arg GetModelByProviderAndModelIDParams) (Model, error) {
row := q.db.QueryRow(ctx, getModelByProviderAndModelID, arg.ProviderID, arg.ModelID)
var i Model
err := row.Scan(
&i.ID,
&i.ModelID,
&i.Name,
&i.ProviderID,
&i.Type,
&i.Config,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const getProviderByID = `-- name: GetProviderByID :one
SELECT id, name, client_type, icon, enable, config, metadata, created_at, updated_at FROM providers WHERE id = $1
`
func (q *Queries) GetProviderByID(ctx context.Context, id pgtype.UUID) (Provider, error) {
row := q.db.QueryRow(ctx, getProviderByID, id)
var i Provider
err := row.Scan(
&i.ID,
&i.Name,
&i.ClientType,
&i.Icon,
&i.Enable,
&i.Config,
&i.Metadata,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const getProviderByName = `-- name: GetProviderByName :one
SELECT id, name, client_type, icon, enable, config, metadata, created_at, updated_at FROM providers WHERE name = $1
`
func (q *Queries) GetProviderByName(ctx context.Context, name string) (Provider, error) {
row := q.db.QueryRow(ctx, getProviderByName, name)
var i Provider
err := row.Scan(
&i.ID,
&i.Name,
&i.ClientType,
&i.Icon,
&i.Enable,
&i.Config,
&i.Metadata,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const getSpeechModelWithProvider = `-- name: GetSpeechModelWithProvider :one
SELECT
m.id, m.model_id, m.name, m.provider_id, m.type, m.config, m.created_at, m.updated_at,
p.client_type AS provider_type
FROM models m
JOIN llm_providers p ON m.llm_provider_id = p.id
JOIN providers p ON p.id = m.provider_id
WHERE m.id = $1
AND m.type = 'speech'
`
type GetSpeechModelWithProviderRow struct {
ID pgtype.UUID `json:"id"`
ModelID string `json:"model_id"`
Name pgtype.Text `json:"name"`
ProviderID pgtype.UUID `json:"provider_id"`
Type string `json:"type"`
Config []byte `json:"config"`
CreatedAt pgtype.Timestamptz `json:"created_at"`
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
ProviderType string `json:"provider_type"`
}
func (q *Queries) GetSpeechModelWithProvider(ctx context.Context, id pgtype.UUID) (GetSpeechModelWithProviderRow, error) {
row := q.db.QueryRow(ctx, getSpeechModelWithProvider, id)
var i GetSpeechModelWithProviderRow
err := row.Scan(
&i.ID,
&i.ModelID,
&i.Name,
&i.ProviderID,
&i.Type,
&i.Config,
&i.CreatedAt,
&i.UpdatedAt,
&i.ProviderType,
)
return i, err
}
const listEnabledModels = `-- name: ListEnabledModels :many
SELECT m.id, m.model_id, m.name, m.provider_id, m.type, m.config, m.created_at, m.updated_at
FROM models m
JOIN providers p ON m.provider_id = p.id
WHERE p.enable = true
ORDER BY m.created_at DESC
`
@@ -306,7 +367,7 @@ func (q *Queries) ListEnabledModels(ctx context.Context) ([]Model, error) {
&i.ID,
&i.ModelID,
&i.Name,
&i.LlmProviderID,
&i.ProviderID,
&i.Type,
&i.Config,
&i.CreatedAt,
@@ -323,9 +384,9 @@ func (q *Queries) ListEnabledModels(ctx context.Context) ([]Model, error) {
}
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
SELECT m.id, m.model_id, m.name, m.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
JOIN providers p ON m.provider_id = p.id
WHERE p.enable = true
AND p.client_type = $1
ORDER BY m.created_at DESC
@@ -344,7 +405,7 @@ func (q *Queries) ListEnabledModelsByProviderClientType(ctx context.Context, cli
&i.ID,
&i.ModelID,
&i.Name,
&i.LlmProviderID,
&i.ProviderID,
&i.Type,
&i.Config,
&i.CreatedAt,
@@ -361,9 +422,9 @@ func (q *Queries) ListEnabledModelsByProviderClientType(ctx context.Context, cli
}
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
SELECT m.id, m.model_id, m.name, m.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
JOIN providers p ON m.provider_id = p.id
WHERE p.enable = true
AND m.type = $1
ORDER BY m.created_at DESC
@@ -382,7 +443,7 @@ func (q *Queries) ListEnabledModelsByType(ctx context.Context, type_ string) ([]
&i.ID,
&i.ModelID,
&i.Name,
&i.LlmProviderID,
&i.ProviderID,
&i.Type,
&i.Config,
&i.CreatedAt,
@@ -398,42 +459,6 @@ func (q *Queries) ListEnabledModelsByType(ctx context.Context, type_ string) ([]
return items, nil
}
const listLlmProviders = `-- name: ListLlmProviders :many
SELECT id, name, base_url, api_key, icon, enable, metadata, created_at, updated_at, client_type FROM llm_providers
ORDER BY created_at DESC
`
func (q *Queries) ListLlmProviders(ctx context.Context) ([]LlmProvider, error) {
rows, err := q.db.Query(ctx, listLlmProviders)
if err != nil {
return nil, err
}
defer rows.Close()
var items []LlmProvider
for rows.Next() {
var i LlmProvider
if err := rows.Scan(
&i.ID,
&i.Name,
&i.BaseUrl,
&i.ApiKey,
&i.Icon,
&i.Enable,
&i.Metadata,
&i.CreatedAt,
&i.UpdatedAt,
&i.ClientType,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const listModelVariantsByModelUUID = `-- name: ListModelVariantsByModelUUID :many
SELECT id, model_uuid, variant_id, weight, metadata, created_at, updated_at FROM model_variants
WHERE model_uuid = $1
@@ -469,7 +494,7 @@ func (q *Queries) ListModelVariantsByModelUUID(ctx context.Context, modelUuid pg
}
const listModels = `-- name: ListModels :many
SELECT id, model_id, name, llm_provider_id, type, config, created_at, updated_at FROM models
SELECT id, model_id, name, provider_id, type, config, created_at, updated_at FROM models
ORDER BY created_at DESC
`
@@ -486,7 +511,7 @@ func (q *Queries) ListModels(ctx context.Context) ([]Model, error) {
&i.ID,
&i.ModelID,
&i.Name,
&i.LlmProviderID,
&i.ProviderID,
&i.Type,
&i.Config,
&i.CreatedAt,
@@ -503,7 +528,7 @@ func (q *Queries) ListModels(ctx context.Context) ([]Model, error) {
}
const listModelsByModelID = `-- name: ListModelsByModelID :many
SELECT id, model_id, name, llm_provider_id, type, config, created_at, updated_at FROM models
SELECT id, model_id, name, provider_id, type, config, created_at, updated_at FROM models
WHERE model_id = $1
ORDER BY created_at DESC
`
@@ -521,7 +546,7 @@ func (q *Queries) ListModelsByModelID(ctx context.Context, modelID string) ([]Mo
&i.ID,
&i.ModelID,
&i.Name,
&i.LlmProviderID,
&i.ProviderID,
&i.Type,
&i.Config,
&i.CreatedAt,
@@ -538,9 +563,9 @@ func (q *Queries) ListModelsByModelID(ctx context.Context, modelID string) ([]Mo
}
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
SELECT m.id, m.model_id, m.name, m.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
JOIN providers p ON m.provider_id = p.id
WHERE p.client_type = $1
ORDER BY m.created_at DESC
`
@@ -558,7 +583,7 @@ func (q *Queries) ListModelsByProviderClientType(ctx context.Context, clientType
&i.ID,
&i.ModelID,
&i.Name,
&i.LlmProviderID,
&i.ProviderID,
&i.Type,
&i.Config,
&i.CreatedAt,
@@ -575,13 +600,13 @@ func (q *Queries) ListModelsByProviderClientType(ctx context.Context, clientType
}
const listModelsByProviderID = `-- name: ListModelsByProviderID :many
SELECT id, model_id, name, llm_provider_id, type, config, created_at, updated_at FROM models
WHERE llm_provider_id = $1
SELECT id, model_id, name, provider_id, type, config, created_at, updated_at FROM models
WHERE provider_id = $1
ORDER BY created_at DESC
`
func (q *Queries) ListModelsByProviderID(ctx context.Context, llmProviderID pgtype.UUID) ([]Model, error) {
rows, err := q.db.Query(ctx, listModelsByProviderID, llmProviderID)
func (q *Queries) ListModelsByProviderID(ctx context.Context, providerID pgtype.UUID) ([]Model, error) {
rows, err := q.db.Query(ctx, listModelsByProviderID, providerID)
if err != nil {
return nil, err
}
@@ -593,7 +618,7 @@ func (q *Queries) ListModelsByProviderID(ctx context.Context, llmProviderID pgty
&i.ID,
&i.ModelID,
&i.Name,
&i.LlmProviderID,
&i.ProviderID,
&i.Type,
&i.Config,
&i.CreatedAt,
@@ -610,19 +635,19 @@ func (q *Queries) ListModelsByProviderID(ctx context.Context, llmProviderID pgty
}
const listModelsByProviderIDAndType = `-- name: ListModelsByProviderIDAndType :many
SELECT id, model_id, name, llm_provider_id, type, config, created_at, updated_at FROM models
WHERE llm_provider_id = $1
SELECT id, model_id, name, provider_id, type, config, created_at, updated_at FROM models
WHERE provider_id = $1
AND type = $2
ORDER BY created_at DESC
`
type ListModelsByProviderIDAndTypeParams struct {
LlmProviderID pgtype.UUID `json:"llm_provider_id"`
Type string `json:"type"`
ProviderID pgtype.UUID `json:"provider_id"`
Type string `json:"type"`
}
func (q *Queries) ListModelsByProviderIDAndType(ctx context.Context, arg ListModelsByProviderIDAndTypeParams) ([]Model, error) {
rows, err := q.db.Query(ctx, listModelsByProviderIDAndType, arg.LlmProviderID, arg.Type)
rows, err := q.db.Query(ctx, listModelsByProviderIDAndType, arg.ProviderID, arg.Type)
if err != nil {
return nil, err
}
@@ -634,7 +659,7 @@ func (q *Queries) ListModelsByProviderIDAndType(ctx context.Context, arg ListMod
&i.ID,
&i.ModelID,
&i.Name,
&i.LlmProviderID,
&i.ProviderID,
&i.Type,
&i.Config,
&i.CreatedAt,
@@ -651,7 +676,7 @@ func (q *Queries) ListModelsByProviderIDAndType(ctx context.Context, arg ListMod
}
const listModelsByType = `-- name: ListModelsByType :many
SELECT id, model_id, name, llm_provider_id, type, config, created_at, updated_at FROM models
SELECT id, model_id, name, provider_id, type, config, created_at, updated_at FROM models
WHERE type = $1
ORDER BY created_at DESC
`
@@ -669,7 +694,7 @@ func (q *Queries) ListModelsByType(ctx context.Context, type_ string) ([]Model,
&i.ID,
&i.ModelID,
&i.Name,
&i.LlmProviderID,
&i.ProviderID,
&i.Type,
&i.Config,
&i.CreatedAt,
@@ -685,57 +710,163 @@ func (q *Queries) ListModelsByType(ctx context.Context, type_ string) ([]Model,
return items, nil
}
const updateLlmProvider = `-- name: UpdateLlmProvider :one
UPDATE llm_providers
SET
name = $1,
base_url = $2,
api_key = $3,
client_type = $4,
icon = $5,
enable = $6,
metadata = $7,
updated_at = now()
WHERE id = $8
RETURNING id, name, base_url, api_key, icon, enable, metadata, created_at, updated_at, client_type
const listProviders = `-- name: ListProviders :many
SELECT id, name, client_type, icon, enable, config, metadata, created_at, updated_at FROM providers
WHERE client_type NOT IN ('edge-speech')
ORDER BY created_at DESC
`
type UpdateLlmProviderParams struct {
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) ListProviders(ctx context.Context) ([]Provider, error) {
rows, err := q.db.Query(ctx, listProviders)
if err != nil {
return nil, err
}
defer rows.Close()
var items []Provider
for rows.Next() {
var i Provider
if err := rows.Scan(
&i.ID,
&i.Name,
&i.ClientType,
&i.Icon,
&i.Enable,
&i.Config,
&i.Metadata,
&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
}
func (q *Queries) UpdateLlmProvider(ctx context.Context, arg UpdateLlmProviderParams) (LlmProvider, error) {
row := q.db.QueryRow(ctx, updateLlmProvider,
arg.Name,
arg.BaseUrl,
arg.ApiKey,
arg.ClientType,
arg.Icon,
arg.Enable,
arg.Metadata,
arg.ID,
)
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
const listSpeechModels = `-- name: ListSpeechModels :many
SELECT m.id, m.model_id, m.name, m.provider_id, m.type, m.config, m.created_at, m.updated_at,
p.client_type AS provider_type
FROM models m
JOIN providers p ON p.id = m.provider_id
WHERE m.type = 'speech'
ORDER BY m.created_at DESC
`
type ListSpeechModelsRow struct {
ID pgtype.UUID `json:"id"`
ModelID string `json:"model_id"`
Name pgtype.Text `json:"name"`
ProviderID pgtype.UUID `json:"provider_id"`
Type string `json:"type"`
Config []byte `json:"config"`
CreatedAt pgtype.Timestamptz `json:"created_at"`
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
ProviderType string `json:"provider_type"`
}
func (q *Queries) ListSpeechModels(ctx context.Context) ([]ListSpeechModelsRow, error) {
rows, err := q.db.Query(ctx, listSpeechModels)
if err != nil {
return nil, err
}
defer rows.Close()
var items []ListSpeechModelsRow
for rows.Next() {
var i ListSpeechModelsRow
if err := rows.Scan(
&i.ID,
&i.ModelID,
&i.Name,
&i.ProviderID,
&i.Type,
&i.Config,
&i.CreatedAt,
&i.UpdatedAt,
&i.ProviderType,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const listSpeechModelsByProviderID = `-- name: ListSpeechModelsByProviderID :many
SELECT id, model_id, name, provider_id, type, config, created_at, updated_at FROM models
WHERE provider_id = $1
AND type = 'speech'
ORDER BY created_at DESC
`
func (q *Queries) ListSpeechModelsByProviderID(ctx context.Context, providerID pgtype.UUID) ([]Model, error) {
rows, err := q.db.Query(ctx, listSpeechModelsByProviderID, providerID)
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.ProviderID,
&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 listSpeechProviders = `-- name: ListSpeechProviders :many
SELECT id, name, client_type, icon, enable, config, metadata, created_at, updated_at FROM providers
WHERE client_type IN ('edge-speech')
ORDER BY created_at DESC
`
func (q *Queries) ListSpeechProviders(ctx context.Context) ([]Provider, error) {
rows, err := q.db.Query(ctx, listSpeechProviders)
if err != nil {
return nil, err
}
defer rows.Close()
var items []Provider
for rows.Next() {
var i Provider
if err := rows.Scan(
&i.ID,
&i.Name,
&i.ClientType,
&i.Icon,
&i.Enable,
&i.Config,
&i.Metadata,
&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 updateModel = `-- name: UpdateModel :one
@@ -743,28 +874,28 @@ UPDATE models
SET
model_id = $1,
name = $2,
llm_provider_id = $3,
provider_id = $3,
type = $4,
config = $5,
updated_at = now()
WHERE id = $6
RETURNING id, model_id, name, llm_provider_id, type, config, created_at, updated_at
RETURNING id, model_id, name, 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"`
Type string `json:"type"`
Config []byte `json:"config"`
ID pgtype.UUID `json:"id"`
ModelID string `json:"model_id"`
Name pgtype.Text `json:"name"`
ProviderID pgtype.UUID `json:"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) {
row := q.db.QueryRow(ctx, updateModel,
arg.ModelID,
arg.Name,
arg.LlmProviderID,
arg.ProviderID,
arg.Type,
arg.Config,
arg.ID,
@@ -774,7 +905,7 @@ func (q *Queries) UpdateModel(ctx context.Context, arg UpdateModelParams) (Model
&i.ID,
&i.ModelID,
&i.Name,
&i.LlmProviderID,
&i.ProviderID,
&i.Type,
&i.Config,
&i.CreatedAt,
@@ -783,30 +914,79 @@ func (q *Queries) UpdateModel(ctx context.Context, arg UpdateModelParams) (Model
return i, err
}
const updateProvider = `-- name: UpdateProvider :one
UPDATE providers
SET
name = $1,
client_type = $2,
icon = $3,
enable = $4,
config = $5,
metadata = $6,
updated_at = now()
WHERE id = $7
RETURNING id, name, client_type, icon, enable, config, metadata, created_at, updated_at
`
type UpdateProviderParams struct {
Name string `json:"name"`
ClientType string `json:"client_type"`
Icon pgtype.Text `json:"icon"`
Enable bool `json:"enable"`
Config []byte `json:"config"`
Metadata []byte `json:"metadata"`
ID pgtype.UUID `json:"id"`
}
func (q *Queries) UpdateProvider(ctx context.Context, arg UpdateProviderParams) (Provider, error) {
row := q.db.QueryRow(ctx, updateProvider,
arg.Name,
arg.ClientType,
arg.Icon,
arg.Enable,
arg.Config,
arg.Metadata,
arg.ID,
)
var i Provider
err := row.Scan(
&i.ID,
&i.Name,
&i.ClientType,
&i.Icon,
&i.Enable,
&i.Config,
&i.Metadata,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const upsertRegistryModel = `-- name: UpsertRegistryModel :one
INSERT INTO models (model_id, name, llm_provider_id, type, config)
INSERT INTO models (model_id, name, provider_id, type, config)
VALUES ($1, $2, $3, $4, $5)
ON CONFLICT (llm_provider_id, model_id) DO UPDATE SET
ON CONFLICT (provider_id, model_id) DO UPDATE SET
name = EXCLUDED.name,
type = EXCLUDED.type,
config = EXCLUDED.config,
updated_at = now()
RETURNING id, model_id, name, llm_provider_id, type, config, created_at, updated_at
RETURNING id, model_id, name, provider_id, type, config, created_at, updated_at
`
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"`
ModelID string `json:"model_id"`
Name pgtype.Text `json:"name"`
ProviderID pgtype.UUID `json:"provider_id"`
Type string `json:"type"`
Config []byte `json:"config"`
}
func (q *Queries) UpsertRegistryModel(ctx context.Context, arg UpsertRegistryModelParams) (Model, error) {
row := q.db.QueryRow(ctx, upsertRegistryModel,
arg.ModelID,
arg.Name,
arg.LlmProviderID,
arg.ProviderID,
arg.Type,
arg.Config,
)
@@ -815,7 +995,7 @@ func (q *Queries) UpsertRegistryModel(ctx context.Context, arg UpsertRegistryMod
&i.ID,
&i.ModelID,
&i.Name,
&i.LlmProviderID,
&i.ProviderID,
&i.Type,
&i.Config,
&i.CreatedAt,
@@ -825,41 +1005,45 @@ func (q *Queries) UpsertRegistryModel(ctx context.Context, arg UpsertRegistryMod
}
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, '{}')
INSERT INTO providers (name, client_type, icon, enable, config, metadata)
VALUES ($1, $2, $3, false, $4, '{}')
ON CONFLICT (name) DO UPDATE SET
icon = EXCLUDED.icon,
client_type = EXCLUDED.client_type,
config = CASE
WHEN providers.config->>'api_key' IS NOT NULL AND providers.config->>'api_key' != ''
THEN jsonb_set(EXCLUDED.config, '{api_key}', providers.config->'api_key')
ELSE EXCLUDED.config
END,
updated_at = now()
RETURNING id, name, base_url, api_key, icon, enable, metadata, created_at, updated_at, client_type
RETURNING id, name, client_type, icon, enable, config, metadata, created_at, updated_at
`
type UpsertRegistryProviderParams struct {
Name string `json:"name"`
BaseUrl string `json:"base_url"`
ClientType string `json:"client_type"`
Icon pgtype.Text `json:"icon"`
Config []byte `json:"config"`
}
func (q *Queries) UpsertRegistryProvider(ctx context.Context, arg UpsertRegistryProviderParams) (LlmProvider, error) {
func (q *Queries) UpsertRegistryProvider(ctx context.Context, arg UpsertRegistryProviderParams) (Provider, error) {
row := q.db.QueryRow(ctx, upsertRegistryProvider,
arg.Name,
arg.BaseUrl,
arg.ClientType,
arg.Icon,
arg.Config,
)
var i LlmProvider
var i Provider
err := row.Scan(
&i.ID,
&i.Name,
&i.BaseUrl,
&i.ApiKey,
&i.ClientType,
&i.Icon,
&i.Enable,
&i.Config,
&i.Metadata,
&i.CreatedAt,
&i.UpdatedAt,
&i.ClientType,
)
return i, err
}
+163
View File
@@ -0,0 +1,163 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.30.0
// source: provider_oauth.sql
package sqlc
import (
"context"
"github.com/jackc/pgx/v5/pgtype"
)
const deleteProviderOAuthToken = `-- name: DeleteProviderOAuthToken :exec
DELETE FROM provider_oauth_tokens WHERE provider_id = $1
`
func (q *Queries) DeleteProviderOAuthToken(ctx context.Context, providerID pgtype.UUID) error {
_, err := q.db.Exec(ctx, deleteProviderOAuthToken, providerID)
return err
}
const getProviderOAuthTokenByProvider = `-- name: GetProviderOAuthTokenByProvider :one
SELECT id, provider_id, access_token, refresh_token, expires_at, scope, token_type, state, pkce_code_verifier, created_at, updated_at FROM provider_oauth_tokens WHERE provider_id = $1
`
func (q *Queries) GetProviderOAuthTokenByProvider(ctx context.Context, providerID pgtype.UUID) (ProviderOauthToken, error) {
row := q.db.QueryRow(ctx, getProviderOAuthTokenByProvider, providerID)
var i ProviderOauthToken
err := row.Scan(
&i.ID,
&i.ProviderID,
&i.AccessToken,
&i.RefreshToken,
&i.ExpiresAt,
&i.Scope,
&i.TokenType,
&i.State,
&i.PkceCodeVerifier,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const getProviderOAuthTokenByState = `-- name: GetProviderOAuthTokenByState :one
SELECT id, provider_id, access_token, refresh_token, expires_at, scope, token_type, state, pkce_code_verifier, created_at, updated_at FROM provider_oauth_tokens WHERE state = $1 AND state != ''
`
func (q *Queries) GetProviderOAuthTokenByState(ctx context.Context, state string) (ProviderOauthToken, error) {
row := q.db.QueryRow(ctx, getProviderOAuthTokenByState, state)
var i ProviderOauthToken
err := row.Scan(
&i.ID,
&i.ProviderID,
&i.AccessToken,
&i.RefreshToken,
&i.ExpiresAt,
&i.Scope,
&i.TokenType,
&i.State,
&i.PkceCodeVerifier,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const updateProviderOAuthState = `-- name: UpdateProviderOAuthState :exec
INSERT INTO provider_oauth_tokens (provider_id, state, pkce_code_verifier)
VALUES (
$1,
$2,
$3
)
ON CONFLICT (provider_id) DO UPDATE SET
state = EXCLUDED.state,
pkce_code_verifier = EXCLUDED.pkce_code_verifier,
updated_at = now()
`
type UpdateProviderOAuthStateParams struct {
ProviderID pgtype.UUID `json:"provider_id"`
State string `json:"state"`
PkceCodeVerifier string `json:"pkce_code_verifier"`
}
func (q *Queries) UpdateProviderOAuthState(ctx context.Context, arg UpdateProviderOAuthStateParams) error {
_, err := q.db.Exec(ctx, updateProviderOAuthState, arg.ProviderID, arg.State, arg.PkceCodeVerifier)
return err
}
const upsertProviderOAuthToken = `-- name: UpsertProviderOAuthToken :one
INSERT INTO provider_oauth_tokens (
provider_id,
access_token,
refresh_token,
expires_at,
scope,
token_type,
state,
pkce_code_verifier
)
VALUES (
$1,
$2,
$3,
$4,
$5,
$6,
$7,
$8
)
ON CONFLICT (provider_id) DO UPDATE SET
access_token = EXCLUDED.access_token,
refresh_token = EXCLUDED.refresh_token,
expires_at = EXCLUDED.expires_at,
scope = EXCLUDED.scope,
token_type = EXCLUDED.token_type,
state = EXCLUDED.state,
pkce_code_verifier = EXCLUDED.pkce_code_verifier,
updated_at = now()
RETURNING id, provider_id, access_token, refresh_token, expires_at, scope, token_type, state, pkce_code_verifier, created_at, updated_at
`
type UpsertProviderOAuthTokenParams struct {
ProviderID pgtype.UUID `json:"provider_id"`
AccessToken string `json:"access_token"`
RefreshToken string `json:"refresh_token"`
ExpiresAt pgtype.Timestamptz `json:"expires_at"`
Scope string `json:"scope"`
TokenType string `json:"token_type"`
State string `json:"state"`
PkceCodeVerifier string `json:"pkce_code_verifier"`
}
func (q *Queries) UpsertProviderOAuthToken(ctx context.Context, arg UpsertProviderOAuthTokenParams) (ProviderOauthToken, error) {
row := q.db.QueryRow(ctx, upsertProviderOAuthToken,
arg.ProviderID,
arg.AccessToken,
arg.RefreshToken,
arg.ExpiresAt,
arg.Scope,
arg.TokenType,
arg.State,
arg.PkceCodeVerifier,
)
var i ProviderOauthToken
err := row.Scan(
&i.ID,
&i.ProviderID,
&i.AccessToken,
&i.RefreshToken,
&i.ExpiresAt,
&i.Scope,
&i.TokenType,
&i.State,
&i.PkceCodeVerifier,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
+2 -2
View File
@@ -69,7 +69,7 @@ LEFT JOIN models AS title_models ON title_models.id = bots.title_model_id
LEFT JOIN models AS image_models ON image_models.id = bots.image_model_id
LEFT JOIN search_providers ON search_providers.id = bots.search_provider_id
LEFT JOIN memory_providers ON memory_providers.id = bots.memory_provider_id
LEFT JOIN tts_models ON tts_models.id = bots.tts_model_id
LEFT JOIN models AS tts_models ON tts_models.id = bots.tts_model_id
LEFT JOIN browser_contexts ON browser_contexts.id = bots.browser_context_id
WHERE bots.id = $1
`
@@ -176,7 +176,7 @@ LEFT JOIN models AS title_models ON title_models.id = updated.title_model_id
LEFT JOIN models AS image_models ON image_models.id = updated.image_model_id
LEFT JOIN search_providers ON search_providers.id = updated.search_provider_id
LEFT JOIN memory_providers ON memory_providers.id = updated.memory_provider_id
LEFT JOIN tts_models ON tts_models.id = updated.tts_model_id
LEFT JOIN models AS tts_models ON tts_models.id = updated.tts_model_id
LEFT JOIN browser_contexts ON browser_contexts.id = updated.browser_context_id
`
+1 -1
View File
@@ -95,7 +95,7 @@ SELECT
COALESCE(SUM((m.usage->>'outputTokens')::bigint), 0)::bigint AS output_tokens
FROM bot_history_messages m
LEFT JOIN models mo ON mo.id = m.model_id
LEFT JOIN llm_providers lp ON lp.id = mo.llm_provider_id
LEFT JOIN providers lp ON lp.id = mo.provider_id
WHERE m.bot_id = $1
AND m.usage IS NOT NULL
AND m.created_at >= $2
-248
View File
@@ -1,248 +0,0 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.30.0
// source: tts_models.sql
package sqlc
import (
"context"
"github.com/jackc/pgx/v5/pgtype"
)
const createTtsModel = `-- name: CreateTtsModel :one
INSERT INTO tts_models (model_id, name, tts_provider_id, config)
VALUES (
$1,
$2,
$3,
$4
)
RETURNING id, model_id, name, tts_provider_id, config, created_at, updated_at
`
type CreateTtsModelParams struct {
ModelID string `json:"model_id"`
Name pgtype.Text `json:"name"`
TtsProviderID pgtype.UUID `json:"tts_provider_id"`
Config []byte `json:"config"`
}
func (q *Queries) CreateTtsModel(ctx context.Context, arg CreateTtsModelParams) (TtsModel, error) {
row := q.db.QueryRow(ctx, createTtsModel,
arg.ModelID,
arg.Name,
arg.TtsProviderID,
arg.Config,
)
var i TtsModel
err := row.Scan(
&i.ID,
&i.ModelID,
&i.Name,
&i.TtsProviderID,
&i.Config,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const deleteTtsModel = `-- name: DeleteTtsModel :exec
DELETE FROM tts_models WHERE id = $1
`
func (q *Queries) DeleteTtsModel(ctx context.Context, id pgtype.UUID) error {
_, err := q.db.Exec(ctx, deleteTtsModel, id)
return err
}
const deleteTtsModelsByProviderID = `-- name: DeleteTtsModelsByProviderID :exec
DELETE FROM tts_models WHERE tts_provider_id = $1
`
func (q *Queries) DeleteTtsModelsByProviderID(ctx context.Context, ttsProviderID pgtype.UUID) error {
_, err := q.db.Exec(ctx, deleteTtsModelsByProviderID, ttsProviderID)
return err
}
const getTtsModelByID = `-- name: GetTtsModelByID :one
SELECT id, model_id, name, tts_provider_id, config, created_at, updated_at FROM tts_models WHERE id = $1
`
func (q *Queries) GetTtsModelByID(ctx context.Context, id pgtype.UUID) (TtsModel, error) {
row := q.db.QueryRow(ctx, getTtsModelByID, id)
var i TtsModel
err := row.Scan(
&i.ID,
&i.ModelID,
&i.Name,
&i.TtsProviderID,
&i.Config,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const getTtsModelByProviderAndModelID = `-- name: GetTtsModelByProviderAndModelID :one
SELECT id, model_id, name, tts_provider_id, config, created_at, updated_at FROM tts_models
WHERE tts_provider_id = $1
AND model_id = $2
LIMIT 1
`
type GetTtsModelByProviderAndModelIDParams struct {
TtsProviderID pgtype.UUID `json:"tts_provider_id"`
ModelID string `json:"model_id"`
}
func (q *Queries) GetTtsModelByProviderAndModelID(ctx context.Context, arg GetTtsModelByProviderAndModelIDParams) (TtsModel, error) {
row := q.db.QueryRow(ctx, getTtsModelByProviderAndModelID, arg.TtsProviderID, arg.ModelID)
var i TtsModel
err := row.Scan(
&i.ID,
&i.ModelID,
&i.Name,
&i.TtsProviderID,
&i.Config,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const getTtsModelWithProvider = `-- name: GetTtsModelWithProvider :one
SELECT
tm.id, tm.model_id, tm.name, tm.tts_provider_id, tm.config, tm.created_at, tm.updated_at,
tp.provider AS provider_type
FROM tts_models tm
JOIN tts_providers tp ON tp.id = tm.tts_provider_id
WHERE tm.id = $1
`
type GetTtsModelWithProviderRow struct {
ID pgtype.UUID `json:"id"`
ModelID string `json:"model_id"`
Name pgtype.Text `json:"name"`
TtsProviderID pgtype.UUID `json:"tts_provider_id"`
Config []byte `json:"config"`
CreatedAt pgtype.Timestamptz `json:"created_at"`
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
ProviderType string `json:"provider_type"`
}
func (q *Queries) GetTtsModelWithProvider(ctx context.Context, id pgtype.UUID) (GetTtsModelWithProviderRow, error) {
row := q.db.QueryRow(ctx, getTtsModelWithProvider, id)
var i GetTtsModelWithProviderRow
err := row.Scan(
&i.ID,
&i.ModelID,
&i.Name,
&i.TtsProviderID,
&i.Config,
&i.CreatedAt,
&i.UpdatedAt,
&i.ProviderType,
)
return i, err
}
const listTtsModels = `-- name: ListTtsModels :many
SELECT id, model_id, name, tts_provider_id, config, created_at, updated_at FROM tts_models
ORDER BY created_at DESC
`
func (q *Queries) ListTtsModels(ctx context.Context) ([]TtsModel, error) {
rows, err := q.db.Query(ctx, listTtsModels)
if err != nil {
return nil, err
}
defer rows.Close()
var items []TtsModel
for rows.Next() {
var i TtsModel
if err := rows.Scan(
&i.ID,
&i.ModelID,
&i.Name,
&i.TtsProviderID,
&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 listTtsModelsByProviderID = `-- name: ListTtsModelsByProviderID :many
SELECT id, model_id, name, tts_provider_id, config, created_at, updated_at FROM tts_models
WHERE tts_provider_id = $1
ORDER BY created_at DESC
`
func (q *Queries) ListTtsModelsByProviderID(ctx context.Context, ttsProviderID pgtype.UUID) ([]TtsModel, error) {
rows, err := q.db.Query(ctx, listTtsModelsByProviderID, ttsProviderID)
if err != nil {
return nil, err
}
defer rows.Close()
var items []TtsModel
for rows.Next() {
var i TtsModel
if err := rows.Scan(
&i.ID,
&i.ModelID,
&i.Name,
&i.TtsProviderID,
&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 updateTtsModel = `-- name: UpdateTtsModel :one
UPDATE tts_models
SET
name = $1,
config = $2,
updated_at = now()
WHERE id = $3
RETURNING id, model_id, name, tts_provider_id, config, created_at, updated_at
`
type UpdateTtsModelParams struct {
Name pgtype.Text `json:"name"`
Config []byte `json:"config"`
ID pgtype.UUID `json:"id"`
}
func (q *Queries) UpdateTtsModel(ctx context.Context, arg UpdateTtsModelParams) (TtsModel, error) {
row := q.db.QueryRow(ctx, updateTtsModel, arg.Name, arg.Config, arg.ID)
var i TtsModel
err := row.Scan(
&i.ID,
&i.ModelID,
&i.Name,
&i.TtsProviderID,
&i.Config,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
-205
View File
@@ -1,205 +0,0 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.30.0
// source: tts_providers.sql
package sqlc
import (
"context"
"github.com/jackc/pgx/v5/pgtype"
)
const createTtsProvider = `-- name: CreateTtsProvider :one
INSERT INTO tts_providers (name, provider, config, enable)
VALUES (
$1,
$2,
$3,
$4
)
RETURNING id, name, provider, config, enable, created_at, updated_at
`
type CreateTtsProviderParams struct {
Name string `json:"name"`
Provider string `json:"provider"`
Config []byte `json:"config"`
Enable bool `json:"enable"`
}
func (q *Queries) CreateTtsProvider(ctx context.Context, arg CreateTtsProviderParams) (TtsProvider, error) {
row := q.db.QueryRow(ctx, createTtsProvider,
arg.Name,
arg.Provider,
arg.Config,
arg.Enable,
)
var i TtsProvider
err := row.Scan(
&i.ID,
&i.Name,
&i.Provider,
&i.Config,
&i.Enable,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const deleteTtsProvider = `-- name: DeleteTtsProvider :exec
DELETE FROM tts_providers WHERE id = $1
`
func (q *Queries) DeleteTtsProvider(ctx context.Context, id pgtype.UUID) error {
_, err := q.db.Exec(ctx, deleteTtsProvider, id)
return err
}
const getTtsProviderByID = `-- name: GetTtsProviderByID :one
SELECT id, name, provider, config, enable, created_at, updated_at FROM tts_providers WHERE id = $1
`
func (q *Queries) GetTtsProviderByID(ctx context.Context, id pgtype.UUID) (TtsProvider, error) {
row := q.db.QueryRow(ctx, getTtsProviderByID, id)
var i TtsProvider
err := row.Scan(
&i.ID,
&i.Name,
&i.Provider,
&i.Config,
&i.Enable,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const getTtsProviderByName = `-- name: GetTtsProviderByName :one
SELECT id, name, provider, config, enable, created_at, updated_at FROM tts_providers WHERE name = $1
`
func (q *Queries) GetTtsProviderByName(ctx context.Context, name string) (TtsProvider, error) {
row := q.db.QueryRow(ctx, getTtsProviderByName, name)
var i TtsProvider
err := row.Scan(
&i.ID,
&i.Name,
&i.Provider,
&i.Config,
&i.Enable,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const listTtsProviders = `-- name: ListTtsProviders :many
SELECT id, name, provider, config, enable, created_at, updated_at FROM tts_providers
ORDER BY created_at DESC
`
func (q *Queries) ListTtsProviders(ctx context.Context) ([]TtsProvider, error) {
rows, err := q.db.Query(ctx, listTtsProviders)
if err != nil {
return nil, err
}
defer rows.Close()
var items []TtsProvider
for rows.Next() {
var i TtsProvider
if err := rows.Scan(
&i.ID,
&i.Name,
&i.Provider,
&i.Config,
&i.Enable,
&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 listTtsProvidersByProvider = `-- name: ListTtsProvidersByProvider :many
SELECT id, name, provider, config, enable, created_at, updated_at FROM tts_providers
WHERE provider = $1
ORDER BY created_at DESC
`
func (q *Queries) ListTtsProvidersByProvider(ctx context.Context, provider string) ([]TtsProvider, error) {
rows, err := q.db.Query(ctx, listTtsProvidersByProvider, provider)
if err != nil {
return nil, err
}
defer rows.Close()
var items []TtsProvider
for rows.Next() {
var i TtsProvider
if err := rows.Scan(
&i.ID,
&i.Name,
&i.Provider,
&i.Config,
&i.Enable,
&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 updateTtsProvider = `-- name: UpdateTtsProvider :one
UPDATE tts_providers
SET
name = $1,
provider = $2,
config = $3,
enable = $4,
updated_at = now()
WHERE id = $5
RETURNING id, name, provider, config, enable, created_at, updated_at
`
type UpdateTtsProviderParams struct {
Name string `json:"name"`
Provider string `json:"provider"`
Config []byte `json:"config"`
Enable bool `json:"enable"`
ID pgtype.UUID `json:"id"`
}
func (q *Queries) UpdateTtsProvider(ctx context.Context, arg UpdateTtsProviderParams) (TtsProvider, error) {
row := q.db.QueryRow(ctx, updateTtsProvider,
arg.Name,
arg.Provider,
arg.Config,
arg.Enable,
arg.ID,
)
var i TtsProvider
err := row.Scan(
&i.ID,
&i.Name,
&i.Provider,
&i.Config,
&i.Enable,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}