Merge branch 'main' into fix/provider-scoped-model-id-resolution

This commit is contained in:
ringotypowriter
2026-02-22 12:47:37 +08:00
82 changed files with 3574 additions and 1153 deletions
+158 -20
View File
@@ -14,7 +14,7 @@ import (
const createBot = `-- name: CreateBot :one
INSERT INTO bots (owner_user_id, type, display_name, avatar_url, is_active, metadata, status)
VALUES ($1, $2, $3, $4, $5, $6, $7)
RETURNING id, owner_user_id, type, display_name, avatar_url, is_active, status, max_context_load_time, max_context_tokens, language, allow_guest, chat_model_id, memory_model_id, embedding_model_id, search_provider_id, metadata, created_at, updated_at
RETURNING id, owner_user_id, type, display_name, avatar_url, is_active, status, max_context_load_time, max_context_tokens, max_inbox_items, language, allow_guest, chat_model_id, memory_model_id, embedding_model_id, search_provider_id, metadata, created_at, updated_at
`
type CreateBotParams struct {
@@ -27,7 +27,29 @@ type CreateBotParams struct {
Status string `json:"status"`
}
func (q *Queries) CreateBot(ctx context.Context, arg CreateBotParams) (Bot, error) {
type CreateBotRow struct {
ID pgtype.UUID `json:"id"`
OwnerUserID pgtype.UUID `json:"owner_user_id"`
Type string `json:"type"`
DisplayName pgtype.Text `json:"display_name"`
AvatarUrl pgtype.Text `json:"avatar_url"`
IsActive bool `json:"is_active"`
Status string `json:"status"`
MaxContextLoadTime int32 `json:"max_context_load_time"`
MaxContextTokens int32 `json:"max_context_tokens"`
MaxInboxItems int32 `json:"max_inbox_items"`
Language string `json:"language"`
AllowGuest bool `json:"allow_guest"`
ChatModelID pgtype.UUID `json:"chat_model_id"`
MemoryModelID pgtype.UUID `json:"memory_model_id"`
EmbeddingModelID pgtype.UUID `json:"embedding_model_id"`
SearchProviderID pgtype.UUID `json:"search_provider_id"`
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.Type,
@@ -37,7 +59,7 @@ func (q *Queries) CreateBot(ctx context.Context, arg CreateBotParams) (Bot, erro
arg.Metadata,
arg.Status,
)
var i Bot
var i CreateBotRow
err := row.Scan(
&i.ID,
&i.OwnerUserID,
@@ -48,6 +70,7 @@ func (q *Queries) CreateBot(ctx context.Context, arg CreateBotParams) (Bot, erro
&i.Status,
&i.MaxContextLoadTime,
&i.MaxContextTokens,
&i.MaxInboxItems,
&i.Language,
&i.AllowGuest,
&i.ChatModelID,
@@ -85,14 +108,36 @@ func (q *Queries) DeleteBotMember(ctx context.Context, arg DeleteBotMemberParams
}
const getBotByID = `-- name: GetBotByID :one
SELECT id, owner_user_id, type, display_name, avatar_url, is_active, status, max_context_load_time, max_context_tokens, language, allow_guest, chat_model_id, memory_model_id, embedding_model_id, search_provider_id, metadata, created_at, updated_at
SELECT id, owner_user_id, type, display_name, avatar_url, is_active, status, max_context_load_time, max_context_tokens, max_inbox_items, language, allow_guest, chat_model_id, memory_model_id, embedding_model_id, search_provider_id, metadata, created_at, updated_at
FROM bots
WHERE id = $1
`
func (q *Queries) GetBotByID(ctx context.Context, id pgtype.UUID) (Bot, error) {
type GetBotByIDRow struct {
ID pgtype.UUID `json:"id"`
OwnerUserID pgtype.UUID `json:"owner_user_id"`
Type string `json:"type"`
DisplayName pgtype.Text `json:"display_name"`
AvatarUrl pgtype.Text `json:"avatar_url"`
IsActive bool `json:"is_active"`
Status string `json:"status"`
MaxContextLoadTime int32 `json:"max_context_load_time"`
MaxContextTokens int32 `json:"max_context_tokens"`
MaxInboxItems int32 `json:"max_inbox_items"`
Language string `json:"language"`
AllowGuest bool `json:"allow_guest"`
ChatModelID pgtype.UUID `json:"chat_model_id"`
MemoryModelID pgtype.UUID `json:"memory_model_id"`
EmbeddingModelID pgtype.UUID `json:"embedding_model_id"`
SearchProviderID pgtype.UUID `json:"search_provider_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 Bot
var i GetBotByIDRow
err := row.Scan(
&i.ID,
&i.OwnerUserID,
@@ -103,6 +148,7 @@ func (q *Queries) GetBotByID(ctx context.Context, id pgtype.UUID) (Bot, error) {
&i.Status,
&i.MaxContextLoadTime,
&i.MaxContextTokens,
&i.MaxInboxItems,
&i.Language,
&i.AllowGuest,
&i.ChatModelID,
@@ -173,22 +219,44 @@ func (q *Queries) ListBotMembers(ctx context.Context, botID pgtype.UUID) ([]BotM
}
const listBotsByMember = `-- name: ListBotsByMember :many
SELECT b.id, b.owner_user_id, b.type, b.display_name, b.avatar_url, b.is_active, b.status, b.max_context_load_time, b.max_context_tokens, b.language, b.allow_guest, b.chat_model_id, b.memory_model_id, b.embedding_model_id, b.search_provider_id, b.metadata, b.created_at, b.updated_at
SELECT b.id, b.owner_user_id, b.type, b.display_name, b.avatar_url, b.is_active, b.status, b.max_context_load_time, b.max_context_tokens, b.max_inbox_items, b.language, b.allow_guest, b.chat_model_id, b.memory_model_id, b.embedding_model_id, b.search_provider_id, b.metadata, b.created_at, b.updated_at
FROM bots b
JOIN bot_members m ON m.bot_id = b.id
WHERE m.user_id = $1
ORDER BY b.created_at DESC
`
func (q *Queries) ListBotsByMember(ctx context.Context, userID pgtype.UUID) ([]Bot, error) {
type ListBotsByMemberRow struct {
ID pgtype.UUID `json:"id"`
OwnerUserID pgtype.UUID `json:"owner_user_id"`
Type string `json:"type"`
DisplayName pgtype.Text `json:"display_name"`
AvatarUrl pgtype.Text `json:"avatar_url"`
IsActive bool `json:"is_active"`
Status string `json:"status"`
MaxContextLoadTime int32 `json:"max_context_load_time"`
MaxContextTokens int32 `json:"max_context_tokens"`
MaxInboxItems int32 `json:"max_inbox_items"`
Language string `json:"language"`
AllowGuest bool `json:"allow_guest"`
ChatModelID pgtype.UUID `json:"chat_model_id"`
MemoryModelID pgtype.UUID `json:"memory_model_id"`
EmbeddingModelID pgtype.UUID `json:"embedding_model_id"`
SearchProviderID pgtype.UUID `json:"search_provider_id"`
Metadata []byte `json:"metadata"`
CreatedAt pgtype.Timestamptz `json:"created_at"`
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
}
func (q *Queries) ListBotsByMember(ctx context.Context, userID pgtype.UUID) ([]ListBotsByMemberRow, error) {
rows, err := q.db.Query(ctx, listBotsByMember, userID)
if err != nil {
return nil, err
}
defer rows.Close()
var items []Bot
var items []ListBotsByMemberRow
for rows.Next() {
var i Bot
var i ListBotsByMemberRow
if err := rows.Scan(
&i.ID,
&i.OwnerUserID,
@@ -199,6 +267,7 @@ func (q *Queries) ListBotsByMember(ctx context.Context, userID pgtype.UUID) ([]B
&i.Status,
&i.MaxContextLoadTime,
&i.MaxContextTokens,
&i.MaxInboxItems,
&i.Language,
&i.AllowGuest,
&i.ChatModelID,
@@ -220,21 +289,43 @@ func (q *Queries) ListBotsByMember(ctx context.Context, userID pgtype.UUID) ([]B
}
const listBotsByOwner = `-- name: ListBotsByOwner :many
SELECT id, owner_user_id, type, display_name, avatar_url, is_active, status, max_context_load_time, max_context_tokens, language, allow_guest, chat_model_id, memory_model_id, embedding_model_id, search_provider_id, metadata, created_at, updated_at
SELECT id, owner_user_id, type, display_name, avatar_url, is_active, status, max_context_load_time, max_context_tokens, max_inbox_items, language, allow_guest, chat_model_id, memory_model_id, embedding_model_id, search_provider_id, metadata, created_at, updated_at
FROM bots
WHERE owner_user_id = $1
ORDER BY created_at DESC
`
func (q *Queries) ListBotsByOwner(ctx context.Context, ownerUserID pgtype.UUID) ([]Bot, error) {
type ListBotsByOwnerRow struct {
ID pgtype.UUID `json:"id"`
OwnerUserID pgtype.UUID `json:"owner_user_id"`
Type string `json:"type"`
DisplayName pgtype.Text `json:"display_name"`
AvatarUrl pgtype.Text `json:"avatar_url"`
IsActive bool `json:"is_active"`
Status string `json:"status"`
MaxContextLoadTime int32 `json:"max_context_load_time"`
MaxContextTokens int32 `json:"max_context_tokens"`
MaxInboxItems int32 `json:"max_inbox_items"`
Language string `json:"language"`
AllowGuest bool `json:"allow_guest"`
ChatModelID pgtype.UUID `json:"chat_model_id"`
MemoryModelID pgtype.UUID `json:"memory_model_id"`
EmbeddingModelID pgtype.UUID `json:"embedding_model_id"`
SearchProviderID pgtype.UUID `json:"search_provider_id"`
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 []Bot
var items []ListBotsByOwnerRow
for rows.Next() {
var i Bot
var i ListBotsByOwnerRow
if err := rows.Scan(
&i.ID,
&i.OwnerUserID,
@@ -245,6 +336,7 @@ func (q *Queries) ListBotsByOwner(ctx context.Context, ownerUserID pgtype.UUID)
&i.Status,
&i.MaxContextLoadTime,
&i.MaxContextTokens,
&i.MaxInboxItems,
&i.Language,
&i.AllowGuest,
&i.ChatModelID,
@@ -270,7 +362,7 @@ UPDATE bots
SET owner_user_id = $2,
updated_at = now()
WHERE id = $1
RETURNING id, owner_user_id, type, display_name, avatar_url, is_active, status, max_context_load_time, max_context_tokens, language, allow_guest, chat_model_id, memory_model_id, embedding_model_id, search_provider_id, metadata, created_at, updated_at
RETURNING id, owner_user_id, type, display_name, avatar_url, is_active, status, max_context_load_time, max_context_tokens, max_inbox_items, language, allow_guest, chat_model_id, memory_model_id, embedding_model_id, search_provider_id, metadata, created_at, updated_at
`
type UpdateBotOwnerParams struct {
@@ -278,9 +370,31 @@ type UpdateBotOwnerParams struct {
OwnerUserID pgtype.UUID `json:"owner_user_id"`
}
func (q *Queries) UpdateBotOwner(ctx context.Context, arg UpdateBotOwnerParams) (Bot, error) {
type UpdateBotOwnerRow struct {
ID pgtype.UUID `json:"id"`
OwnerUserID pgtype.UUID `json:"owner_user_id"`
Type string `json:"type"`
DisplayName pgtype.Text `json:"display_name"`
AvatarUrl pgtype.Text `json:"avatar_url"`
IsActive bool `json:"is_active"`
Status string `json:"status"`
MaxContextLoadTime int32 `json:"max_context_load_time"`
MaxContextTokens int32 `json:"max_context_tokens"`
MaxInboxItems int32 `json:"max_inbox_items"`
Language string `json:"language"`
AllowGuest bool `json:"allow_guest"`
ChatModelID pgtype.UUID `json:"chat_model_id"`
MemoryModelID pgtype.UUID `json:"memory_model_id"`
EmbeddingModelID pgtype.UUID `json:"embedding_model_id"`
SearchProviderID pgtype.UUID `json:"search_provider_id"`
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 Bot
var i UpdateBotOwnerRow
err := row.Scan(
&i.ID,
&i.OwnerUserID,
@@ -291,6 +405,7 @@ func (q *Queries) UpdateBotOwner(ctx context.Context, arg UpdateBotOwnerParams)
&i.Status,
&i.MaxContextLoadTime,
&i.MaxContextTokens,
&i.MaxInboxItems,
&i.Language,
&i.AllowGuest,
&i.ChatModelID,
@@ -312,7 +427,7 @@ SET display_name = $2,
metadata = $5,
updated_at = now()
WHERE id = $1
RETURNING id, owner_user_id, type, display_name, avatar_url, is_active, status, max_context_load_time, max_context_tokens, language, allow_guest, chat_model_id, memory_model_id, embedding_model_id, search_provider_id, metadata, created_at, updated_at
RETURNING id, owner_user_id, type, display_name, avatar_url, is_active, status, max_context_load_time, max_context_tokens, max_inbox_items, language, allow_guest, chat_model_id, memory_model_id, embedding_model_id, search_provider_id, metadata, created_at, updated_at
`
type UpdateBotProfileParams struct {
@@ -323,7 +438,29 @@ type UpdateBotProfileParams struct {
Metadata []byte `json:"metadata"`
}
func (q *Queries) UpdateBotProfile(ctx context.Context, arg UpdateBotProfileParams) (Bot, error) {
type UpdateBotProfileRow struct {
ID pgtype.UUID `json:"id"`
OwnerUserID pgtype.UUID `json:"owner_user_id"`
Type string `json:"type"`
DisplayName pgtype.Text `json:"display_name"`
AvatarUrl pgtype.Text `json:"avatar_url"`
IsActive bool `json:"is_active"`
Status string `json:"status"`
MaxContextLoadTime int32 `json:"max_context_load_time"`
MaxContextTokens int32 `json:"max_context_tokens"`
MaxInboxItems int32 `json:"max_inbox_items"`
Language string `json:"language"`
AllowGuest bool `json:"allow_guest"`
ChatModelID pgtype.UUID `json:"chat_model_id"`
MemoryModelID pgtype.UUID `json:"memory_model_id"`
EmbeddingModelID pgtype.UUID `json:"embedding_model_id"`
SearchProviderID pgtype.UUID `json:"search_provider_id"`
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,
@@ -331,7 +468,7 @@ func (q *Queries) UpdateBotProfile(ctx context.Context, arg UpdateBotProfilePara
arg.IsActive,
arg.Metadata,
)
var i Bot
var i UpdateBotProfileRow
err := row.Scan(
&i.ID,
&i.OwnerUserID,
@@ -342,6 +479,7 @@ func (q *Queries) UpdateBotProfile(ctx context.Context, arg UpdateBotProfilePara
&i.Status,
&i.MaxContextLoadTime,
&i.MaxContextTokens,
&i.MaxInboxItems,
&i.Language,
&i.AllowGuest,
&i.ChatModelID,
+1 -1
View File
@@ -590,7 +590,7 @@ WITH updated AS (
SET display_name = $1,
updated_at = now()
WHERE bots.id = $2
RETURNING id, owner_user_id, type, display_name, avatar_url, is_active, status, max_context_load_time, max_context_tokens, language, allow_guest, chat_model_id, memory_model_id, embedding_model_id, search_provider_id, metadata, created_at, updated_at
RETURNING id, owner_user_id, type, display_name, avatar_url, is_active, status, max_context_load_time, max_context_tokens, language, allow_guest, max_inbox_items, chat_model_id, memory_model_id, embedding_model_id, search_provider_id, metadata, created_at, updated_at
)
SELECT
updated.id AS id,
+283
View File
@@ -0,0 +1,283 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.30.0
// source: inbox.sql
package sqlc
import (
"context"
"github.com/jackc/pgx/v5/pgtype"
)
const countInboxItems = `-- name: CountInboxItems :one
SELECT count(*) FROM bot_inbox
WHERE bot_id = $1
`
func (q *Queries) CountInboxItems(ctx context.Context, botID pgtype.UUID) (int64, error) {
row := q.db.QueryRow(ctx, countInboxItems, botID)
var count int64
err := row.Scan(&count)
return count, err
}
const countUnreadInboxItems = `-- name: CountUnreadInboxItems :one
SELECT count(*) FROM bot_inbox
WHERE bot_id = $1
AND is_read = FALSE
`
func (q *Queries) CountUnreadInboxItems(ctx context.Context, botID pgtype.UUID) (int64, error) {
row := q.db.QueryRow(ctx, countUnreadInboxItems, botID)
var count int64
err := row.Scan(&count)
return count, err
}
const createInboxItem = `-- name: CreateInboxItem :one
INSERT INTO bot_inbox (bot_id, source, content)
VALUES ($1, $2, $3)
RETURNING id, bot_id, source, content, is_read, created_at, read_at
`
type CreateInboxItemParams struct {
BotID pgtype.UUID `json:"bot_id"`
Source string `json:"source"`
Content []byte `json:"content"`
}
func (q *Queries) CreateInboxItem(ctx context.Context, arg CreateInboxItemParams) (BotInbox, error) {
row := q.db.QueryRow(ctx, createInboxItem, arg.BotID, arg.Source, arg.Content)
var i BotInbox
err := row.Scan(
&i.ID,
&i.BotID,
&i.Source,
&i.Content,
&i.IsRead,
&i.CreatedAt,
&i.ReadAt,
)
return i, err
}
const deleteInboxItem = `-- name: DeleteInboxItem :exec
DELETE FROM bot_inbox
WHERE id = $1
AND bot_id = $2
`
type DeleteInboxItemParams struct {
ID pgtype.UUID `json:"id"`
BotID pgtype.UUID `json:"bot_id"`
}
func (q *Queries) DeleteInboxItem(ctx context.Context, arg DeleteInboxItemParams) error {
_, err := q.db.Exec(ctx, deleteInboxItem, arg.ID, arg.BotID)
return err
}
const deleteInboxItemsByBot = `-- name: DeleteInboxItemsByBot :exec
DELETE FROM bot_inbox
WHERE bot_id = $1
`
func (q *Queries) DeleteInboxItemsByBot(ctx context.Context, botID pgtype.UUID) error {
_, err := q.db.Exec(ctx, deleteInboxItemsByBot, botID)
return err
}
const getInboxItemByID = `-- name: GetInboxItemByID :one
SELECT id, bot_id, source, content, is_read, created_at, read_at FROM bot_inbox
WHERE id = $1
AND bot_id = $2
`
type GetInboxItemByIDParams struct {
ID pgtype.UUID `json:"id"`
BotID pgtype.UUID `json:"bot_id"`
}
func (q *Queries) GetInboxItemByID(ctx context.Context, arg GetInboxItemByIDParams) (BotInbox, error) {
row := q.db.QueryRow(ctx, getInboxItemByID, arg.ID, arg.BotID)
var i BotInbox
err := row.Scan(
&i.ID,
&i.BotID,
&i.Source,
&i.Content,
&i.IsRead,
&i.CreatedAt,
&i.ReadAt,
)
return i, err
}
const listInboxItems = `-- name: ListInboxItems :many
SELECT id, bot_id, source, content, is_read, created_at, read_at FROM bot_inbox
WHERE bot_id = $1
AND ($2::boolean IS NULL OR is_read = $2::boolean)
AND ($3::text IS NULL OR source = $3::text)
ORDER BY created_at DESC
LIMIT $5
OFFSET $4
`
type ListInboxItemsParams struct {
BotID pgtype.UUID `json:"bot_id"`
IsRead pgtype.Bool `json:"is_read"`
Source pgtype.Text `json:"source"`
ItemOffset int32 `json:"item_offset"`
MaxCount int32 `json:"max_count"`
}
func (q *Queries) ListInboxItems(ctx context.Context, arg ListInboxItemsParams) ([]BotInbox, error) {
rows, err := q.db.Query(ctx, listInboxItems,
arg.BotID,
arg.IsRead,
arg.Source,
arg.ItemOffset,
arg.MaxCount,
)
if err != nil {
return nil, err
}
defer rows.Close()
var items []BotInbox
for rows.Next() {
var i BotInbox
if err := rows.Scan(
&i.ID,
&i.BotID,
&i.Source,
&i.Content,
&i.IsRead,
&i.CreatedAt,
&i.ReadAt,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const listUnreadInboxItems = `-- name: ListUnreadInboxItems :many
SELECT id, bot_id, source, content, is_read, created_at, read_at FROM bot_inbox
WHERE bot_id = $1
AND is_read = FALSE
ORDER BY created_at ASC
LIMIT $2
`
type ListUnreadInboxItemsParams struct {
BotID pgtype.UUID `json:"bot_id"`
MaxCount int32 `json:"max_count"`
}
func (q *Queries) ListUnreadInboxItems(ctx context.Context, arg ListUnreadInboxItemsParams) ([]BotInbox, error) {
rows, err := q.db.Query(ctx, listUnreadInboxItems, arg.BotID, arg.MaxCount)
if err != nil {
return nil, err
}
defer rows.Close()
var items []BotInbox
for rows.Next() {
var i BotInbox
if err := rows.Scan(
&i.ID,
&i.BotID,
&i.Source,
&i.Content,
&i.IsRead,
&i.CreatedAt,
&i.ReadAt,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const markInboxItemsRead = `-- name: MarkInboxItemsRead :exec
UPDATE bot_inbox
SET is_read = TRUE,
read_at = now()
WHERE bot_id = $1
AND id = ANY($2::uuid[])
AND is_read = FALSE
`
type MarkInboxItemsReadParams struct {
BotID pgtype.UUID `json:"bot_id"`
Ids []pgtype.UUID `json:"ids"`
}
func (q *Queries) MarkInboxItemsRead(ctx context.Context, arg MarkInboxItemsReadParams) error {
_, err := q.db.Exec(ctx, markInboxItemsRead, arg.BotID, arg.Ids)
return err
}
const searchInboxItems = `-- name: SearchInboxItems :many
SELECT id, bot_id, source, content, is_read, created_at, read_at FROM bot_inbox
WHERE bot_id = $1
AND content::text ILIKE '%' || $2 || '%'
AND ($3::timestamptz IS NULL OR created_at >= $3::timestamptz)
AND ($4::timestamptz IS NULL OR created_at <= $4::timestamptz)
AND ($5::boolean IS NULL OR $5::boolean = TRUE OR is_read = FALSE)
ORDER BY created_at DESC
LIMIT $6
`
type SearchInboxItemsParams struct {
BotID pgtype.UUID `json:"bot_id"`
Query pgtype.Text `json:"query"`
StartTime pgtype.Timestamptz `json:"start_time"`
EndTime pgtype.Timestamptz `json:"end_time"`
IncludeRead pgtype.Bool `json:"include_read"`
MaxCount int32 `json:"max_count"`
}
func (q *Queries) SearchInboxItems(ctx context.Context, arg SearchInboxItemsParams) ([]BotInbox, error) {
rows, err := q.db.Query(ctx, searchInboxItems,
arg.BotID,
arg.Query,
arg.StartTime,
arg.EndTime,
arg.IncludeRead,
arg.MaxCount,
)
if err != nil {
return nil, err
}
defer rows.Close()
var items []BotInbox
for rows.Next() {
var i BotInbox
if err := rows.Scan(
&i.ID,
&i.BotID,
&i.Source,
&i.Content,
&i.IsRead,
&i.CreatedAt,
&i.ReadAt,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
+84
View File
@@ -127,6 +127,90 @@ func (q *Queries) DeleteMessagesByBot(ctx context.Context, botID pgtype.UUID) er
return err
}
const listActiveMessagesSince = `-- name: ListActiveMessagesSince :many
SELECT
m.id,
m.bot_id,
m.route_id,
m.sender_channel_identity_id,
m.sender_account_user_id AS sender_user_id,
m.channel_type AS platform,
m.source_message_id AS external_message_id,
m.source_reply_to_message_id,
m.role,
m.content,
m.metadata,
m.usage,
m.created_at,
ci.display_name AS sender_display_name,
ci.avatar_url AS sender_avatar_url
FROM bot_history_messages m
LEFT JOIN channel_identities ci ON ci.id = m.sender_channel_identity_id
WHERE m.bot_id = $1
AND m.created_at >= $2
AND (m.metadata->>'trigger_mode' IS NULL OR m.metadata->>'trigger_mode' != 'passive_sync')
ORDER BY m.created_at ASC
`
type ListActiveMessagesSinceParams struct {
BotID pgtype.UUID `json:"bot_id"`
CreatedAt pgtype.Timestamptz `json:"created_at"`
}
type ListActiveMessagesSinceRow struct {
ID pgtype.UUID `json:"id"`
BotID pgtype.UUID `json:"bot_id"`
RouteID pgtype.UUID `json:"route_id"`
SenderChannelIdentityID pgtype.UUID `json:"sender_channel_identity_id"`
SenderUserID pgtype.UUID `json:"sender_user_id"`
Platform pgtype.Text `json:"platform"`
ExternalMessageID pgtype.Text `json:"external_message_id"`
SourceReplyToMessageID pgtype.Text `json:"source_reply_to_message_id"`
Role string `json:"role"`
Content []byte `json:"content"`
Metadata []byte `json:"metadata"`
Usage []byte `json:"usage"`
CreatedAt pgtype.Timestamptz `json:"created_at"`
SenderDisplayName pgtype.Text `json:"sender_display_name"`
SenderAvatarUrl pgtype.Text `json:"sender_avatar_url"`
}
func (q *Queries) ListActiveMessagesSince(ctx context.Context, arg ListActiveMessagesSinceParams) ([]ListActiveMessagesSinceRow, error) {
rows, err := q.db.Query(ctx, listActiveMessagesSince, arg.BotID, arg.CreatedAt)
if err != nil {
return nil, err
}
defer rows.Close()
var items []ListActiveMessagesSinceRow
for rows.Next() {
var i ListActiveMessagesSinceRow
if err := rows.Scan(
&i.ID,
&i.BotID,
&i.RouteID,
&i.SenderChannelIdentityID,
&i.SenderUserID,
&i.Platform,
&i.ExternalMessageID,
&i.SourceReplyToMessageID,
&i.Role,
&i.Content,
&i.Metadata,
&i.Usage,
&i.CreatedAt,
&i.SenderDisplayName,
&i.SenderAvatarUrl,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const listMessages = `-- name: ListMessages :many
SELECT
m.id,
+11
View File
@@ -20,6 +20,7 @@ type Bot struct {
MaxContextTokens int32 `json:"max_context_tokens"`
Language string `json:"language"`
AllowGuest bool `json:"allow_guest"`
MaxInboxItems int32 `json:"max_inbox_items"`
ChatModelID pgtype.UUID `json:"chat_model_id"`
MemoryModelID pgtype.UUID `json:"memory_model_id"`
EmbeddingModelID pgtype.UUID `json:"embedding_model_id"`
@@ -83,6 +84,16 @@ type BotHistoryMessageAsset struct {
CreatedAt pgtype.Timestamptz `json:"created_at"`
}
type BotInbox struct {
ID pgtype.UUID `json:"id"`
BotID pgtype.UUID `json:"bot_id"`
Source string `json:"source"`
Content []byte `json:"content"`
IsRead bool `json:"is_read"`
CreatedAt pgtype.Timestamptz `json:"created_at"`
ReadAt pgtype.Timestamptz `json:"read_at"`
}
type BotMember struct {
BotID pgtype.UUID `json:"bot_id"`
UserID pgtype.UUID `json:"user_id"`
+18 -8
View File
@@ -15,6 +15,7 @@ const deleteSettingsByBotID = `-- name: DeleteSettingsByBotID :exec
UPDATE bots
SET max_context_load_time = 1440,
max_context_tokens = 0,
max_inbox_items = 50,
language = 'auto',
allow_guest = false,
chat_model_id = NULL,
@@ -35,6 +36,7 @@ SELECT
bots.id AS bot_id,
bots.max_context_load_time,
bots.max_context_tokens,
bots.max_inbox_items,
bots.language,
bots.allow_guest,
chat_models.id AS chat_model_id,
@@ -53,6 +55,7 @@ type GetSettingsByBotIDRow struct {
BotID pgtype.UUID `json:"bot_id"`
MaxContextLoadTime int32 `json:"max_context_load_time"`
MaxContextTokens int32 `json:"max_context_tokens"`
MaxInboxItems int32 `json:"max_inbox_items"`
Language string `json:"language"`
AllowGuest bool `json:"allow_guest"`
ChatModelID pgtype.UUID `json:"chat_model_id"`
@@ -68,6 +71,7 @@ func (q *Queries) GetSettingsByBotID(ctx context.Context, id pgtype.UUID) (GetSe
&i.BotID,
&i.MaxContextLoadTime,
&i.MaxContextTokens,
&i.MaxInboxItems,
&i.Language,
&i.AllowGuest,
&i.ChatModelID,
@@ -83,20 +87,22 @@ WITH updated AS (
UPDATE bots
SET max_context_load_time = $1,
max_context_tokens = $2,
language = $3,
allow_guest = $4,
chat_model_id = COALESCE($5::uuid, bots.chat_model_id),
memory_model_id = COALESCE($6::uuid, bots.memory_model_id),
embedding_model_id = COALESCE($7::uuid, bots.embedding_model_id),
search_provider_id = COALESCE($8::uuid, bots.search_provider_id),
max_inbox_items = $3,
language = $4,
allow_guest = $5,
chat_model_id = COALESCE($6::uuid, bots.chat_model_id),
memory_model_id = COALESCE($7::uuid, bots.memory_model_id),
embedding_model_id = COALESCE($8::uuid, bots.embedding_model_id),
search_provider_id = COALESCE($9::uuid, bots.search_provider_id),
updated_at = now()
WHERE bots.id = $9
RETURNING bots.id, bots.max_context_load_time, bots.max_context_tokens, bots.language, bots.allow_guest, bots.chat_model_id, bots.memory_model_id, bots.embedding_model_id, bots.search_provider_id
WHERE bots.id = $10
RETURNING bots.id, bots.max_context_load_time, bots.max_context_tokens, bots.max_inbox_items, bots.language, bots.allow_guest, bots.chat_model_id, bots.memory_model_id, bots.embedding_model_id, bots.search_provider_id
)
SELECT
updated.id AS bot_id,
updated.max_context_load_time,
updated.max_context_tokens,
updated.max_inbox_items,
updated.language,
updated.allow_guest,
chat_models.id AS chat_model_id,
@@ -113,6 +119,7 @@ LEFT JOIN search_providers ON search_providers.id = updated.search_provider_id
type UpsertBotSettingsParams struct {
MaxContextLoadTime int32 `json:"max_context_load_time"`
MaxContextTokens int32 `json:"max_context_tokens"`
MaxInboxItems int32 `json:"max_inbox_items"`
Language string `json:"language"`
AllowGuest bool `json:"allow_guest"`
ChatModelID pgtype.UUID `json:"chat_model_id"`
@@ -126,6 +133,7 @@ type UpsertBotSettingsRow struct {
BotID pgtype.UUID `json:"bot_id"`
MaxContextLoadTime int32 `json:"max_context_load_time"`
MaxContextTokens int32 `json:"max_context_tokens"`
MaxInboxItems int32 `json:"max_inbox_items"`
Language string `json:"language"`
AllowGuest bool `json:"allow_guest"`
ChatModelID pgtype.UUID `json:"chat_model_id"`
@@ -138,6 +146,7 @@ func (q *Queries) UpsertBotSettings(ctx context.Context, arg UpsertBotSettingsPa
row := q.db.QueryRow(ctx, upsertBotSettings,
arg.MaxContextLoadTime,
arg.MaxContextTokens,
arg.MaxInboxItems,
arg.Language,
arg.AllowGuest,
arg.ChatModelID,
@@ -151,6 +160,7 @@ func (q *Queries) UpsertBotSettings(ctx context.Context, arg UpsertBotSettingsPa
&i.BotID,
&i.MaxContextLoadTime,
&i.MaxContextTokens,
&i.MaxInboxItems,
&i.Language,
&i.AllowGuest,
&i.ChatModelID,