mirror of
https://github.com/memohai/Memoh.git
synced 2026-04-25 07:00:48 +09:00
0e646625bf
Allow users to configure what percentage of older messages to compact, keeping the most recent portion intact. Default ratio is 80%, meaning the oldest 80% of uncompacted messages are summarized while the newest 20% remain as-is for full-fidelity context.
423 lines
14 KiB
Go
423 lines
14 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.30.0
|
|
// source: bots.sql
|
|
|
|
package sqlc
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
)
|
|
|
|
const createBot = `-- name: CreateBot :one
|
|
INSERT INTO bots (owner_user_id, display_name, avatar_url, timezone, is_active, metadata, status)
|
|
VALUES ($1, $2, $3, $4, $5, $6, $7)
|
|
RETURNING id, owner_user_id, display_name, avatar_url, timezone, is_active, status, language, reasoning_enabled, reasoning_effort, chat_model_id, search_provider_id, memory_provider_id, heartbeat_enabled, heartbeat_interval, heartbeat_prompt, metadata, created_at, updated_at
|
|
`
|
|
|
|
type CreateBotParams struct {
|
|
OwnerUserID pgtype.UUID `json:"owner_user_id"`
|
|
DisplayName pgtype.Text `json:"display_name"`
|
|
AvatarUrl pgtype.Text `json:"avatar_url"`
|
|
Timezone pgtype.Text `json:"timezone"`
|
|
IsActive bool `json:"is_active"`
|
|
Metadata []byte `json:"metadata"`
|
|
Status string `json:"status"`
|
|
}
|
|
|
|
type CreateBotRow struct {
|
|
ID pgtype.UUID `json:"id"`
|
|
OwnerUserID pgtype.UUID `json:"owner_user_id"`
|
|
DisplayName pgtype.Text `json:"display_name"`
|
|
AvatarUrl pgtype.Text `json:"avatar_url"`
|
|
Timezone pgtype.Text `json:"timezone"`
|
|
IsActive bool `json:"is_active"`
|
|
Status string `json:"status"`
|
|
Language string `json:"language"`
|
|
ReasoningEnabled bool `json:"reasoning_enabled"`
|
|
ReasoningEffort string `json:"reasoning_effort"`
|
|
ChatModelID pgtype.UUID `json:"chat_model_id"`
|
|
SearchProviderID pgtype.UUID `json:"search_provider_id"`
|
|
MemoryProviderID pgtype.UUID `json:"memory_provider_id"`
|
|
HeartbeatEnabled bool `json:"heartbeat_enabled"`
|
|
HeartbeatInterval int32 `json:"heartbeat_interval"`
|
|
HeartbeatPrompt string `json:"heartbeat_prompt"`
|
|
Metadata []byte `json:"metadata"`
|
|
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
|
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
|
}
|
|
|
|
func (q *Queries) CreateBot(ctx context.Context, arg CreateBotParams) (CreateBotRow, error) {
|
|
row := q.db.QueryRow(ctx, createBot,
|
|
arg.OwnerUserID,
|
|
arg.DisplayName,
|
|
arg.AvatarUrl,
|
|
arg.Timezone,
|
|
arg.IsActive,
|
|
arg.Metadata,
|
|
arg.Status,
|
|
)
|
|
var i CreateBotRow
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.OwnerUserID,
|
|
&i.DisplayName,
|
|
&i.AvatarUrl,
|
|
&i.Timezone,
|
|
&i.IsActive,
|
|
&i.Status,
|
|
&i.Language,
|
|
&i.ReasoningEnabled,
|
|
&i.ReasoningEffort,
|
|
&i.ChatModelID,
|
|
&i.SearchProviderID,
|
|
&i.MemoryProviderID,
|
|
&i.HeartbeatEnabled,
|
|
&i.HeartbeatInterval,
|
|
&i.HeartbeatPrompt,
|
|
&i.Metadata,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const deleteBotByID = `-- name: DeleteBotByID :exec
|
|
DELETE FROM bots WHERE id = $1
|
|
`
|
|
|
|
func (q *Queries) DeleteBotByID(ctx context.Context, id pgtype.UUID) error {
|
|
_, err := q.db.Exec(ctx, deleteBotByID, id)
|
|
return err
|
|
}
|
|
|
|
const getBotByID = `-- name: GetBotByID :one
|
|
SELECT id, owner_user_id, display_name, avatar_url, timezone, is_active, status, language, reasoning_enabled, reasoning_effort, chat_model_id, search_provider_id, memory_provider_id, heartbeat_enabled, heartbeat_interval, heartbeat_prompt, compaction_enabled, compaction_threshold, compaction_ratio, compaction_model_id, metadata, created_at, updated_at
|
|
FROM bots
|
|
WHERE id = $1
|
|
`
|
|
|
|
type GetBotByIDRow struct {
|
|
ID pgtype.UUID `json:"id"`
|
|
OwnerUserID pgtype.UUID `json:"owner_user_id"`
|
|
DisplayName pgtype.Text `json:"display_name"`
|
|
AvatarUrl pgtype.Text `json:"avatar_url"`
|
|
Timezone pgtype.Text `json:"timezone"`
|
|
IsActive bool `json:"is_active"`
|
|
Status string `json:"status"`
|
|
Language string `json:"language"`
|
|
ReasoningEnabled bool `json:"reasoning_enabled"`
|
|
ReasoningEffort string `json:"reasoning_effort"`
|
|
ChatModelID pgtype.UUID `json:"chat_model_id"`
|
|
SearchProviderID pgtype.UUID `json:"search_provider_id"`
|
|
MemoryProviderID pgtype.UUID `json:"memory_provider_id"`
|
|
HeartbeatEnabled bool `json:"heartbeat_enabled"`
|
|
HeartbeatInterval int32 `json:"heartbeat_interval"`
|
|
HeartbeatPrompt string `json:"heartbeat_prompt"`
|
|
CompactionEnabled bool `json:"compaction_enabled"`
|
|
CompactionThreshold int32 `json:"compaction_threshold"`
|
|
CompactionRatio int32 `json:"compaction_ratio"`
|
|
CompactionModelID pgtype.UUID `json:"compaction_model_id"`
|
|
Metadata []byte `json:"metadata"`
|
|
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
|
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
|
}
|
|
|
|
func (q *Queries) GetBotByID(ctx context.Context, id pgtype.UUID) (GetBotByIDRow, error) {
|
|
row := q.db.QueryRow(ctx, getBotByID, id)
|
|
var i GetBotByIDRow
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.OwnerUserID,
|
|
&i.DisplayName,
|
|
&i.AvatarUrl,
|
|
&i.Timezone,
|
|
&i.IsActive,
|
|
&i.Status,
|
|
&i.Language,
|
|
&i.ReasoningEnabled,
|
|
&i.ReasoningEffort,
|
|
&i.ChatModelID,
|
|
&i.SearchProviderID,
|
|
&i.MemoryProviderID,
|
|
&i.HeartbeatEnabled,
|
|
&i.HeartbeatInterval,
|
|
&i.HeartbeatPrompt,
|
|
&i.CompactionEnabled,
|
|
&i.CompactionThreshold,
|
|
&i.CompactionRatio,
|
|
&i.CompactionModelID,
|
|
&i.Metadata,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const listBotsByOwner = `-- name: ListBotsByOwner :many
|
|
SELECT id, owner_user_id, display_name, avatar_url, timezone, is_active, status, language, reasoning_enabled, reasoning_effort, chat_model_id, search_provider_id, memory_provider_id, heartbeat_enabled, heartbeat_interval, heartbeat_prompt, metadata, created_at, updated_at
|
|
FROM bots
|
|
WHERE owner_user_id = $1
|
|
ORDER BY created_at DESC
|
|
`
|
|
|
|
type ListBotsByOwnerRow struct {
|
|
ID pgtype.UUID `json:"id"`
|
|
OwnerUserID pgtype.UUID `json:"owner_user_id"`
|
|
DisplayName pgtype.Text `json:"display_name"`
|
|
AvatarUrl pgtype.Text `json:"avatar_url"`
|
|
Timezone pgtype.Text `json:"timezone"`
|
|
IsActive bool `json:"is_active"`
|
|
Status string `json:"status"`
|
|
Language string `json:"language"`
|
|
ReasoningEnabled bool `json:"reasoning_enabled"`
|
|
ReasoningEffort string `json:"reasoning_effort"`
|
|
ChatModelID pgtype.UUID `json:"chat_model_id"`
|
|
SearchProviderID pgtype.UUID `json:"search_provider_id"`
|
|
MemoryProviderID pgtype.UUID `json:"memory_provider_id"`
|
|
HeartbeatEnabled bool `json:"heartbeat_enabled"`
|
|
HeartbeatInterval int32 `json:"heartbeat_interval"`
|
|
HeartbeatPrompt string `json:"heartbeat_prompt"`
|
|
Metadata []byte `json:"metadata"`
|
|
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
|
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
|
}
|
|
|
|
func (q *Queries) ListBotsByOwner(ctx context.Context, ownerUserID pgtype.UUID) ([]ListBotsByOwnerRow, error) {
|
|
rows, err := q.db.Query(ctx, listBotsByOwner, ownerUserID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []ListBotsByOwnerRow
|
|
for rows.Next() {
|
|
var i ListBotsByOwnerRow
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.OwnerUserID,
|
|
&i.DisplayName,
|
|
&i.AvatarUrl,
|
|
&i.Timezone,
|
|
&i.IsActive,
|
|
&i.Status,
|
|
&i.Language,
|
|
&i.ReasoningEnabled,
|
|
&i.ReasoningEffort,
|
|
&i.ChatModelID,
|
|
&i.SearchProviderID,
|
|
&i.MemoryProviderID,
|
|
&i.HeartbeatEnabled,
|
|
&i.HeartbeatInterval,
|
|
&i.HeartbeatPrompt,
|
|
&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 listHeartbeatEnabledBots = `-- name: ListHeartbeatEnabledBots :many
|
|
SELECT id, owner_user_id, heartbeat_enabled, heartbeat_interval, heartbeat_prompt
|
|
FROM bots
|
|
WHERE heartbeat_enabled = true AND status = 'ready'
|
|
`
|
|
|
|
type ListHeartbeatEnabledBotsRow struct {
|
|
ID pgtype.UUID `json:"id"`
|
|
OwnerUserID pgtype.UUID `json:"owner_user_id"`
|
|
HeartbeatEnabled bool `json:"heartbeat_enabled"`
|
|
HeartbeatInterval int32 `json:"heartbeat_interval"`
|
|
HeartbeatPrompt string `json:"heartbeat_prompt"`
|
|
}
|
|
|
|
func (q *Queries) ListHeartbeatEnabledBots(ctx context.Context) ([]ListHeartbeatEnabledBotsRow, error) {
|
|
rows, err := q.db.Query(ctx, listHeartbeatEnabledBots)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []ListHeartbeatEnabledBotsRow
|
|
for rows.Next() {
|
|
var i ListHeartbeatEnabledBotsRow
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.OwnerUserID,
|
|
&i.HeartbeatEnabled,
|
|
&i.HeartbeatInterval,
|
|
&i.HeartbeatPrompt,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const updateBotOwner = `-- name: UpdateBotOwner :one
|
|
UPDATE bots
|
|
SET owner_user_id = $2,
|
|
updated_at = now()
|
|
WHERE id = $1
|
|
RETURNING id, owner_user_id, display_name, avatar_url, timezone, is_active, status, language, reasoning_enabled, reasoning_effort, chat_model_id, search_provider_id, memory_provider_id, heartbeat_enabled, heartbeat_interval, heartbeat_prompt, metadata, created_at, updated_at
|
|
`
|
|
|
|
type UpdateBotOwnerParams struct {
|
|
ID pgtype.UUID `json:"id"`
|
|
OwnerUserID pgtype.UUID `json:"owner_user_id"`
|
|
}
|
|
|
|
type UpdateBotOwnerRow struct {
|
|
ID pgtype.UUID `json:"id"`
|
|
OwnerUserID pgtype.UUID `json:"owner_user_id"`
|
|
DisplayName pgtype.Text `json:"display_name"`
|
|
AvatarUrl pgtype.Text `json:"avatar_url"`
|
|
Timezone pgtype.Text `json:"timezone"`
|
|
IsActive bool `json:"is_active"`
|
|
Status string `json:"status"`
|
|
Language string `json:"language"`
|
|
ReasoningEnabled bool `json:"reasoning_enabled"`
|
|
ReasoningEffort string `json:"reasoning_effort"`
|
|
ChatModelID pgtype.UUID `json:"chat_model_id"`
|
|
SearchProviderID pgtype.UUID `json:"search_provider_id"`
|
|
MemoryProviderID pgtype.UUID `json:"memory_provider_id"`
|
|
HeartbeatEnabled bool `json:"heartbeat_enabled"`
|
|
HeartbeatInterval int32 `json:"heartbeat_interval"`
|
|
HeartbeatPrompt string `json:"heartbeat_prompt"`
|
|
Metadata []byte `json:"metadata"`
|
|
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
|
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
|
}
|
|
|
|
func (q *Queries) UpdateBotOwner(ctx context.Context, arg UpdateBotOwnerParams) (UpdateBotOwnerRow, error) {
|
|
row := q.db.QueryRow(ctx, updateBotOwner, arg.ID, arg.OwnerUserID)
|
|
var i UpdateBotOwnerRow
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.OwnerUserID,
|
|
&i.DisplayName,
|
|
&i.AvatarUrl,
|
|
&i.Timezone,
|
|
&i.IsActive,
|
|
&i.Status,
|
|
&i.Language,
|
|
&i.ReasoningEnabled,
|
|
&i.ReasoningEffort,
|
|
&i.ChatModelID,
|
|
&i.SearchProviderID,
|
|
&i.MemoryProviderID,
|
|
&i.HeartbeatEnabled,
|
|
&i.HeartbeatInterval,
|
|
&i.HeartbeatPrompt,
|
|
&i.Metadata,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const updateBotProfile = `-- name: UpdateBotProfile :one
|
|
UPDATE bots
|
|
SET display_name = $2,
|
|
avatar_url = $3,
|
|
timezone = $4,
|
|
is_active = $5,
|
|
metadata = $6,
|
|
updated_at = now()
|
|
WHERE id = $1
|
|
RETURNING id, owner_user_id, display_name, avatar_url, timezone, is_active, status, language, reasoning_enabled, reasoning_effort, chat_model_id, search_provider_id, memory_provider_id, heartbeat_enabled, heartbeat_interval, heartbeat_prompt, metadata, created_at, updated_at
|
|
`
|
|
|
|
type UpdateBotProfileParams struct {
|
|
ID pgtype.UUID `json:"id"`
|
|
DisplayName pgtype.Text `json:"display_name"`
|
|
AvatarUrl pgtype.Text `json:"avatar_url"`
|
|
Timezone pgtype.Text `json:"timezone"`
|
|
IsActive bool `json:"is_active"`
|
|
Metadata []byte `json:"metadata"`
|
|
}
|
|
|
|
type UpdateBotProfileRow struct {
|
|
ID pgtype.UUID `json:"id"`
|
|
OwnerUserID pgtype.UUID `json:"owner_user_id"`
|
|
DisplayName pgtype.Text `json:"display_name"`
|
|
AvatarUrl pgtype.Text `json:"avatar_url"`
|
|
Timezone pgtype.Text `json:"timezone"`
|
|
IsActive bool `json:"is_active"`
|
|
Status string `json:"status"`
|
|
Language string `json:"language"`
|
|
ReasoningEnabled bool `json:"reasoning_enabled"`
|
|
ReasoningEffort string `json:"reasoning_effort"`
|
|
ChatModelID pgtype.UUID `json:"chat_model_id"`
|
|
SearchProviderID pgtype.UUID `json:"search_provider_id"`
|
|
MemoryProviderID pgtype.UUID `json:"memory_provider_id"`
|
|
HeartbeatEnabled bool `json:"heartbeat_enabled"`
|
|
HeartbeatInterval int32 `json:"heartbeat_interval"`
|
|
HeartbeatPrompt string `json:"heartbeat_prompt"`
|
|
Metadata []byte `json:"metadata"`
|
|
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
|
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
|
}
|
|
|
|
func (q *Queries) UpdateBotProfile(ctx context.Context, arg UpdateBotProfileParams) (UpdateBotProfileRow, error) {
|
|
row := q.db.QueryRow(ctx, updateBotProfile,
|
|
arg.ID,
|
|
arg.DisplayName,
|
|
arg.AvatarUrl,
|
|
arg.Timezone,
|
|
arg.IsActive,
|
|
arg.Metadata,
|
|
)
|
|
var i UpdateBotProfileRow
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.OwnerUserID,
|
|
&i.DisplayName,
|
|
&i.AvatarUrl,
|
|
&i.Timezone,
|
|
&i.IsActive,
|
|
&i.Status,
|
|
&i.Language,
|
|
&i.ReasoningEnabled,
|
|
&i.ReasoningEffort,
|
|
&i.ChatModelID,
|
|
&i.SearchProviderID,
|
|
&i.MemoryProviderID,
|
|
&i.HeartbeatEnabled,
|
|
&i.HeartbeatInterval,
|
|
&i.HeartbeatPrompt,
|
|
&i.Metadata,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const updateBotStatus = `-- name: UpdateBotStatus :exec
|
|
UPDATE bots
|
|
SET status = $2,
|
|
updated_at = now()
|
|
WHERE id = $1
|
|
`
|
|
|
|
type UpdateBotStatusParams struct {
|
|
ID pgtype.UUID `json:"id"`
|
|
Status string `json:"status"`
|
|
}
|
|
|
|
func (q *Queries) UpdateBotStatus(ctx context.Context, arg UpdateBotStatusParams) error {
|
|
_, err := q.db.Exec(ctx, updateBotStatus, arg.ID, arg.Status)
|
|
return err
|
|
}
|