mirror of
https://github.com/memohai/Memoh.git
synced 2026-04-27 07:16:19 +09:00
5a35ef34ac
- Refactor channel manager with support for Sender/Receiver interfaces and hot-swappable adapters. - Implement identity routing and pre-authentication logic for inbound messages. - Update database schema to support bot pre-auth keys and extended channel session metadata. - Add Telegram and Feishu channel configuration and adapter enhancements. - Update Swagger documentation and internal handlers for channel management. Co-authored-by: Cursor <cursoragent@cursor.com>
179 lines
4.2 KiB
Go
179 lines
4.2 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.30.0
|
|
// source: history.sql
|
|
|
|
package sqlc
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
)
|
|
|
|
const createHistory = `-- name: CreateHistory :one
|
|
INSERT INTO history (bot_id, session_id, messages, metadata, skills, timestamp)
|
|
VALUES ($1, $2, $3, $4, $5, $6)
|
|
RETURNING id, bot_id, session_id, messages, metadata, skills, timestamp
|
|
`
|
|
|
|
type CreateHistoryParams struct {
|
|
BotID pgtype.UUID `json:"bot_id"`
|
|
SessionID string `json:"session_id"`
|
|
Messages []byte `json:"messages"`
|
|
Metadata []byte `json:"metadata"`
|
|
Skills []string `json:"skills"`
|
|
Timestamp pgtype.Timestamptz `json:"timestamp"`
|
|
}
|
|
|
|
func (q *Queries) CreateHistory(ctx context.Context, arg CreateHistoryParams) (History, error) {
|
|
row := q.db.QueryRow(ctx, createHistory,
|
|
arg.BotID,
|
|
arg.SessionID,
|
|
arg.Messages,
|
|
arg.Metadata,
|
|
arg.Skills,
|
|
arg.Timestamp,
|
|
)
|
|
var i History
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.BotID,
|
|
&i.SessionID,
|
|
&i.Messages,
|
|
&i.Metadata,
|
|
&i.Skills,
|
|
&i.Timestamp,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const deleteHistoryByBotSession = `-- name: DeleteHistoryByBotSession :exec
|
|
DELETE FROM history
|
|
WHERE bot_id = $1 AND session_id = $2
|
|
`
|
|
|
|
type DeleteHistoryByBotSessionParams struct {
|
|
BotID pgtype.UUID `json:"bot_id"`
|
|
SessionID string `json:"session_id"`
|
|
}
|
|
|
|
func (q *Queries) DeleteHistoryByBotSession(ctx context.Context, arg DeleteHistoryByBotSessionParams) error {
|
|
_, err := q.db.Exec(ctx, deleteHistoryByBotSession, arg.BotID, arg.SessionID)
|
|
return err
|
|
}
|
|
|
|
const deleteHistoryByID = `-- name: DeleteHistoryByID :exec
|
|
DELETE FROM history
|
|
WHERE id = $1
|
|
`
|
|
|
|
func (q *Queries) DeleteHistoryByID(ctx context.Context, id pgtype.UUID) error {
|
|
_, err := q.db.Exec(ctx, deleteHistoryByID, id)
|
|
return err
|
|
}
|
|
|
|
const getHistoryByID = `-- name: GetHistoryByID :one
|
|
SELECT id, bot_id, session_id, messages, metadata, skills, timestamp
|
|
FROM history
|
|
WHERE id = $1
|
|
`
|
|
|
|
func (q *Queries) GetHistoryByID(ctx context.Context, id pgtype.UUID) (History, error) {
|
|
row := q.db.QueryRow(ctx, getHistoryByID, id)
|
|
var i History
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.BotID,
|
|
&i.SessionID,
|
|
&i.Messages,
|
|
&i.Metadata,
|
|
&i.Skills,
|
|
&i.Timestamp,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const listHistoryByBotSession = `-- name: ListHistoryByBotSession :many
|
|
SELECT id, bot_id, session_id, messages, metadata, skills, timestamp
|
|
FROM history
|
|
WHERE bot_id = $1 AND session_id = $2
|
|
ORDER BY timestamp DESC
|
|
LIMIT $3
|
|
`
|
|
|
|
type ListHistoryByBotSessionParams struct {
|
|
BotID pgtype.UUID `json:"bot_id"`
|
|
SessionID string `json:"session_id"`
|
|
Limit int32 `json:"limit"`
|
|
}
|
|
|
|
func (q *Queries) ListHistoryByBotSession(ctx context.Context, arg ListHistoryByBotSessionParams) ([]History, error) {
|
|
rows, err := q.db.Query(ctx, listHistoryByBotSession, arg.BotID, arg.SessionID, arg.Limit)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []History
|
|
for rows.Next() {
|
|
var i History
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.BotID,
|
|
&i.SessionID,
|
|
&i.Messages,
|
|
&i.Metadata,
|
|
&i.Skills,
|
|
&i.Timestamp,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const listHistoryByBotSessionSince = `-- name: ListHistoryByBotSessionSince :many
|
|
SELECT id, bot_id, session_id, messages, metadata, skills, timestamp
|
|
FROM history
|
|
WHERE bot_id = $1 AND session_id = $2 AND timestamp >= $3
|
|
ORDER BY timestamp ASC
|
|
`
|
|
|
|
type ListHistoryByBotSessionSinceParams struct {
|
|
BotID pgtype.UUID `json:"bot_id"`
|
|
SessionID string `json:"session_id"`
|
|
Timestamp pgtype.Timestamptz `json:"timestamp"`
|
|
}
|
|
|
|
func (q *Queries) ListHistoryByBotSessionSince(ctx context.Context, arg ListHistoryByBotSessionSinceParams) ([]History, error) {
|
|
rows, err := q.db.Query(ctx, listHistoryByBotSessionSince, arg.BotID, arg.SessionID, arg.Timestamp)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []History
|
|
for rows.Next() {
|
|
var i History
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.BotID,
|
|
&i.SessionID,
|
|
&i.Messages,
|
|
&i.Metadata,
|
|
&i.Skills,
|
|
&i.Timestamp,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|