mirror of
https://github.com/memohai/Memoh.git
synced 2026-04-27 07:16:19 +09:00
b88ca96064
* 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.
213 lines
5.3 KiB
Go
213 lines
5.3 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.30.0
|
|
// source: compaction_logs.sql
|
|
|
|
package sqlc
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
)
|
|
|
|
const completeCompactionLog = `-- name: CompleteCompactionLog :one
|
|
UPDATE bot_history_message_compacts
|
|
SET status = $2,
|
|
summary = $3,
|
|
message_count = $4,
|
|
error_message = $5,
|
|
usage = $6,
|
|
model_id = $7,
|
|
completed_at = now()
|
|
WHERE id = $1
|
|
RETURNING id, bot_id, session_id, status, summary, message_count, error_message, usage, model_id, started_at, completed_at
|
|
`
|
|
|
|
type CompleteCompactionLogParams struct {
|
|
ID pgtype.UUID `json:"id"`
|
|
Status string `json:"status"`
|
|
Summary string `json:"summary"`
|
|
MessageCount int32 `json:"message_count"`
|
|
ErrorMessage string `json:"error_message"`
|
|
Usage []byte `json:"usage"`
|
|
ModelID pgtype.UUID `json:"model_id"`
|
|
}
|
|
|
|
func (q *Queries) CompleteCompactionLog(ctx context.Context, arg CompleteCompactionLogParams) (BotHistoryMessageCompact, error) {
|
|
row := q.db.QueryRow(ctx, completeCompactionLog,
|
|
arg.ID,
|
|
arg.Status,
|
|
arg.Summary,
|
|
arg.MessageCount,
|
|
arg.ErrorMessage,
|
|
arg.Usage,
|
|
arg.ModelID,
|
|
)
|
|
var i BotHistoryMessageCompact
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.BotID,
|
|
&i.SessionID,
|
|
&i.Status,
|
|
&i.Summary,
|
|
&i.MessageCount,
|
|
&i.ErrorMessage,
|
|
&i.Usage,
|
|
&i.ModelID,
|
|
&i.StartedAt,
|
|
&i.CompletedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const createCompactionLog = `-- name: CreateCompactionLog :one
|
|
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 {
|
|
BotID pgtype.UUID `json:"bot_id"`
|
|
SessionID pgtype.UUID `json:"session_id"`
|
|
}
|
|
|
|
func (q *Queries) CreateCompactionLog(ctx context.Context, arg CreateCompactionLogParams) (BotHistoryMessageCompact, error) {
|
|
row := q.db.QueryRow(ctx, createCompactionLog, arg.BotID, arg.SessionID)
|
|
var i BotHistoryMessageCompact
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.BotID,
|
|
&i.SessionID,
|
|
&i.Status,
|
|
&i.Summary,
|
|
&i.MessageCount,
|
|
&i.ErrorMessage,
|
|
&i.Usage,
|
|
&i.ModelID,
|
|
&i.StartedAt,
|
|
&i.CompletedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const deleteCompactionLogsByBot = `-- name: DeleteCompactionLogsByBot :exec
|
|
DELETE FROM bot_history_message_compacts WHERE bot_id = $1
|
|
`
|
|
|
|
func (q *Queries) DeleteCompactionLogsByBot(ctx context.Context, botID pgtype.UUID) error {
|
|
_, err := q.db.Exec(ctx, deleteCompactionLogsByBot, botID)
|
|
return err
|
|
}
|
|
|
|
const getCompactionLogByID = `-- name: GetCompactionLogByID :one
|
|
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 id = $1
|
|
`
|
|
|
|
func (q *Queries) GetCompactionLogByID(ctx context.Context, id pgtype.UUID) (BotHistoryMessageCompact, error) {
|
|
row := q.db.QueryRow(ctx, getCompactionLogByID, id)
|
|
var i BotHistoryMessageCompact
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.BotID,
|
|
&i.SessionID,
|
|
&i.Status,
|
|
&i.Summary,
|
|
&i.MessageCount,
|
|
&i.ErrorMessage,
|
|
&i.Usage,
|
|
&i.ModelID,
|
|
&i.StartedAt,
|
|
&i.CompletedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
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)
|
|
ORDER BY started_at DESC
|
|
LIMIT $3
|
|
`
|
|
|
|
type ListCompactionLogsByBotParams struct {
|
|
BotID pgtype.UUID `json:"bot_id"`
|
|
Column2 pgtype.Timestamptz `json:"column_2"`
|
|
Limit int32 `json:"limit"`
|
|
}
|
|
|
|
func (q *Queries) ListCompactionLogsByBot(ctx context.Context, arg ListCompactionLogsByBotParams) ([]BotHistoryMessageCompact, error) {
|
|
rows, err := q.db.Query(ctx, listCompactionLogsByBot, arg.BotID, arg.Column2, arg.Limit)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []BotHistoryMessageCompact
|
|
for rows.Next() {
|
|
var i BotHistoryMessageCompact
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.BotID,
|
|
&i.SessionID,
|
|
&i.Status,
|
|
&i.Summary,
|
|
&i.MessageCount,
|
|
&i.ErrorMessage,
|
|
&i.Usage,
|
|
&i.ModelID,
|
|
&i.StartedAt,
|
|
&i.CompletedAt,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
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
|
|
ORDER BY started_at ASC
|
|
`
|
|
|
|
func (q *Queries) ListCompactionLogsBySession(ctx context.Context, sessionID pgtype.UUID) ([]BotHistoryMessageCompact, error) {
|
|
rows, err := q.db.Query(ctx, listCompactionLogsBySession, sessionID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []BotHistoryMessageCompact
|
|
for rows.Next() {
|
|
var i BotHistoryMessageCompact
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.BotID,
|
|
&i.SessionID,
|
|
&i.Status,
|
|
&i.Summary,
|
|
&i.MessageCount,
|
|
&i.ErrorMessage,
|
|
&i.Usage,
|
|
&i.ModelID,
|
|
&i.StartedAt,
|
|
&i.CompletedAt,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|