Files
MonkeyCode/monkeyai/backend/internal/session/sqlc/query.sql.go
T
Yoko d4292a2489 功能:实现会话上报一期后端与管理后台 (#1380)
* 文档:补充会话上报一期后端方案

* 文档:补充会话上报管理后台方案

* 功能:实现会话上报一期后端与管理页面

* 功能:开放管理员审计清除并限制占位会话

* 功能:会话上报开关生效并增加数据库限速
2026-10-08 16:12:20 +08:00

685 lines
22 KiB
Go

// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.30.0
// source: query.sql
package sqlc
import (
"context"
"time"
)
const claimSession = `-- name: ClaimSession :exec
UPDATE sessions SET
parent_session_id=COALESCE(parent_session_id,NULLIF($1::text,'')::uuid),
group_id=COALESCE(group_id,NULLIF($2::text,'')::uuid),
device_id=COALESCE(device_id,NULLIF($3::text,'')),updated_at=now()
WHERE id=$4::uuid
`
type ClaimSessionParams struct {
ParentID string
GroupID string
MachineID string
ID string
}
func (q *Queries) ClaimSession(ctx context.Context, arg ClaimSessionParams) error {
_, err := q.db.Exec(ctx, claimSession,
arg.ParentID,
arg.GroupID,
arg.MachineID,
arg.ID,
)
return err
}
const countOpenPlaceholders = `-- name: CountOpenPlaceholders :one
SELECT count(*) FROM sessions
WHERE owner_user_id = $1::uuid AND placeholder = true
AND deleted_at IS NULL AND purged_at IS NULL
`
func (q *Queries) CountOpenPlaceholders(ctx context.Context, dollar_1 string) (int64, error) {
row := q.db.QueryRow(ctx, countOpenPlaceholders, dollar_1)
var count int64
err := row.Scan(&count)
return count, err
}
const countSessions = `-- name: CountSessions :one
SELECT count(*) FROM sessions
WHERE
($1::text <> '' OR
(($2::boolean OR deleted_at IS NULL)
AND ($3::boolean OR purged_at IS NULL)
AND ($4::boolean OR placeholder=false)
AND ($5::boolean OR reporting_enabled_at IS NOT NULL)))
AND ($1::text = '' OR $1::text = 'all'
OR ($1::text = 'deleted' AND deleted_at IS NOT NULL)
OR ($1::text = 'purged' AND purged_at IS NOT NULL)
OR ($1::text = 'placeholder' AND placeholder AND purged_at IS NULL)
OR ($1::text IN ('legacy','old_reporting') AND reporting_enabled_at IS NULL AND purged_at IS NULL)
OR ($1::text = 'reporting' AND reporting_enabled_at IS NOT NULL AND purged_at IS NULL))
AND ($6::text = '' OR owner_user_id=NULLIF($6::text,'')::uuid)
AND ($7::text = '' OR group_id=NULLIF($7::text,'')::uuid)
AND ($8::text = '' OR parent_session_id=NULLIF($8::text,'')::uuid)
AND ($9::text = '' OR session_type=$9::text)
AND ($10::text = '' OR client_type=$10::text)
AND ($11::text = '' OR started_at>=NULLIF($11::text,'')::timestamptz)
AND ($12::text = '' OR started_at<NULLIF($12::text,'')::timestamptz)
`
type CountSessionsParams struct {
Status string
IncludeDeleted bool
IncludePurged bool
IncludePlaceholder bool
IncludeLegacy bool
OwnerID string
GroupID string
ParentID string
SessionType string
ClientType string
FromTime string
UntilTime string
}
func (q *Queries) CountSessions(ctx context.Context, arg CountSessionsParams) (int64, error) {
row := q.db.QueryRow(ctx, countSessions,
arg.Status,
arg.IncludeDeleted,
arg.IncludePurged,
arg.IncludePlaceholder,
arg.IncludeLegacy,
arg.OwnerID,
arg.GroupID,
arg.ParentID,
arg.SessionType,
arg.ClientType,
arg.FromTime,
arg.UntilTime,
)
var count int64
err := row.Scan(&count)
return count, err
}
const currentSessionGroup = `-- name: CurrentSessionGroup :one
SELECT COALESCE(
(SELECT s.group_id::text FROM sessions s
WHERE s.id = NULLIF($1::text, '')::uuid
AND s.owner_user_id = $2::uuid),
(SELECT a.group_id::text FROM credit_accounts a
WHERE a.user_id = $2::uuid
AND a.period_start_at <= now() AND a.period_end_at > now()
AND a.group_id IS NOT NULL
ORDER BY a.period_start_at DESC LIMIT 1),
(SELECT CASE WHEN count(*) = 1 THEN min(g.id::text) END
FROM group_users gu JOIN groups g ON g.id = gu.group_id AND g.deleted_at IS NULL
WHERE gu.user_id = $2::uuid AND gu.removed_at IS NULL),
''
)::text AS group_id
`
type CurrentSessionGroupParams struct {
ParentID string
UserID string
}
func (q *Queries) CurrentSessionGroup(ctx context.Context, arg CurrentSessionGroupParams) (string, error) {
row := q.db.QueryRow(ctx, currentSessionGroup, arg.ParentID, arg.UserID)
var group_id string
err := row.Scan(&group_id)
return group_id, err
}
const deleteImageCalls = `-- name: DeleteImageCalls :exec
DELETE FROM image_calls WHERE session_id=ANY($1::uuid[])
`
func (q *Queries) DeleteImageCalls(ctx context.Context, dollar_1 []string) error {
_, err := q.db.Exec(ctx, deleteImageCalls, dollar_1)
return err
}
const deleteMCPCalls = `-- name: DeleteMCPCalls :exec
DELETE FROM mcp_tool_calls WHERE session_id=ANY($1::uuid[])
`
func (q *Queries) DeleteMCPCalls(ctx context.Context, dollar_1 []string) error {
_, err := q.db.Exec(ctx, deleteMCPCalls, dollar_1)
return err
}
const deleteModelCalls = `-- name: DeleteModelCalls :exec
DELETE FROM model_calls WHERE session_id=ANY($1::uuid[])
`
func (q *Queries) DeleteModelCalls(ctx context.Context, dollar_1 []string) error {
_, err := q.db.Exec(ctx, deleteModelCalls, dollar_1)
return err
}
const deleteSkillEvents = `-- name: DeleteSkillEvents :exec
DELETE FROM session_skill_events WHERE session_id=ANY($1::uuid[])
`
func (q *Queries) DeleteSkillEvents(ctx context.Context, dollar_1 []string) error {
_, err := q.db.Exec(ctx, deleteSkillEvents, dollar_1)
return err
}
const deleteSnapshotItems = `-- name: DeleteSnapshotItems :exec
DELETE FROM session_resource_snapshot_items WHERE session_id=ANY($1::uuid[])
`
func (q *Queries) DeleteSnapshotItems(ctx context.Context, dollar_1 []string) error {
_, err := q.db.Exec(ctx, deleteSnapshotItems, dollar_1)
return err
}
const deleteSnapshots = `-- name: DeleteSnapshots :exec
DELETE FROM session_resource_snapshots WHERE session_id=ANY($1::uuid[])
`
func (q *Queries) DeleteSnapshots(ctx context.Context, dollar_1 []string) error {
_, err := q.db.Exec(ctx, deleteSnapshots, dollar_1)
return err
}
const deleteTurnTools = `-- name: DeleteTurnTools :exec
DELETE FROM session_turn_tools WHERE session_id=ANY($1::uuid[])
`
func (q *Queries) DeleteTurnTools(ctx context.Context, dollar_1 []string) error {
_, err := q.db.Exec(ctx, deleteTurnTools, dollar_1)
return err
}
const deleteTurns = `-- name: DeleteTurns :exec
DELETE FROM session_turns WHERE session_id=ANY($1::uuid[])
`
func (q *Queries) DeleteTurns(ctx context.Context, dollar_1 []string) error {
_, err := q.db.Exec(ctx, deleteTurns, dollar_1)
return err
}
const getParent = `-- name: GetParent :one
SELECT jsonb_build_object('owner',owner_user_id,'parent',parent_session_id,'purged',purged_at,'deleted',deleted_at) AS data
FROM sessions WHERE id = $1::uuid
`
func (q *Queries) GetParent(ctx context.Context, dollar_1 string) ([]byte, error) {
row := q.db.QueryRow(ctx, getParent, dollar_1)
var data []byte
err := row.Scan(&data)
return data, err
}
const getSession = `-- name: GetSession :one
SELECT jsonb_build_object(
'id',id,'owner_user_id',owner_user_id,'group_id',group_id,'parent_session_id',parent_session_id,
'model_id',model_id,'device_id',device_id,'title',title,'session_type',session_type,
'client_type',client_type,'client_name',client_name,'started_at',started_at,
'last_active_at',last_active_at,'ended_at',ended_at,'deleted_at',deleted_at,'purged_at',purged_at,
'placeholder',placeholder,'started_provis',started_at_provisional,'clock_suspect',clock_suspect,
'state_seq',state_seq,'state_hash',encode(state_hash,'base64'),'state_received_at',state_received_at,
'resources_id',resources_snapshot_id,'acked_turn',acked_turn,'facts_version',facts_version,
'last_stop_reason',last_stop_reason,'active_seconds',active_seconds,
'client_deleted_at',client_deleted_at,'reporting_enabled_at',reporting_enabled_at
) AS data FROM sessions WHERE id = $1::uuid
`
func (q *Queries) GetSession(ctx context.Context, dollar_1 string) ([]byte, error) {
row := q.db.QueryRow(ctx, getSession, dollar_1)
var data []byte
err := row.Scan(&data)
return data, err
}
const getSnapshotItems = `-- name: GetSnapshotItems :one
SELECT items FROM session_resource_snapshots WHERE session_id=$1::uuid AND snapshot_id=$2
`
type GetSnapshotItemsParams struct {
Column1 string
SnapshotID string
}
func (q *Queries) GetSnapshotItems(ctx context.Context, arg GetSnapshotItemsParams) ([]byte, error) {
row := q.db.QueryRow(ctx, getSnapshotItems, arg.Column1, arg.SnapshotID)
var items []byte
err := row.Scan(&items)
return items, err
}
const getTurnHash = `-- name: GetTurnHash :one
SELECT report_hash FROM session_turns WHERE session_id=$1::uuid AND turn_index=$2 FOR UPDATE
`
type GetTurnHashParams struct {
Column1 string
TurnIndex int32
}
func (q *Queries) GetTurnHash(ctx context.Context, arg GetTurnHashParams) ([]byte, error) {
row := q.db.QueryRow(ctx, getTurnHash, arg.Column1, arg.TurnIndex)
var report_hash []byte
err := row.Scan(&report_hash)
return report_hash, err
}
const hasSnapshot = `-- name: HasSnapshot :one
SELECT EXISTS(SELECT 1 FROM session_resource_snapshots WHERE session_id=$1::uuid AND snapshot_id=$2)
`
type HasSnapshotParams struct {
Column1 string
SnapshotID string
}
func (q *Queries) HasSnapshot(ctx context.Context, arg HasSnapshotParams) (bool, error) {
row := q.db.QueryRow(ctx, hasSnapshot, arg.Column1, arg.SnapshotID)
var exists bool
err := row.Scan(&exists)
return exists, err
}
const insertPlaceholder = `-- name: InsertPlaceholder :exec
INSERT INTO sessions (
id,owner_user_id,group_id,parent_session_id,title,session_type,client_type,client_name,
device_id,started_at,last_active_at,placeholder,started_at_provisional,reporting_enabled_at
) VALUES (
$1::uuid,$2::uuid,NULLIF($3::text,'')::uuid,
NULLIF($4::text,'')::uuid,'','conversation','unknown','',
NULLIF($5::text,''),$6::timestamptz,NULL,true,true,now()
) ON CONFLICT (id) DO NOTHING
`
type InsertPlaceholderParams struct {
ID string
OwnerUserID string
GroupID string
ParentSessionID string
MachineID string
StartedAt time.Time
}
func (q *Queries) InsertPlaceholder(ctx context.Context, arg InsertPlaceholderParams) error {
_, err := q.db.Exec(ctx, insertPlaceholder,
arg.ID,
arg.OwnerUserID,
arg.GroupID,
arg.ParentSessionID,
arg.MachineID,
arg.StartedAt,
)
return err
}
const listSessions = `-- name: ListSessions :many
SELECT jsonb_build_object(
'id',id,'owner_user_id',owner_user_id,'group_id',group_id,'parent_session_id',parent_session_id,
'session_type',session_type,'client_type',client_type,'client_name',client_name,
'started_at',started_at,'last_active_at',last_active_at,'ended_at',ended_at,
'turn_count',turn_count,'acked_turn',acked_turn,'active_seconds',active_seconds,
'facts_version',facts_version,'last_stop_reason',last_stop_reason,
'created_at',created_at,'updated_at',updated_at
) AS data FROM sessions
WHERE
($1::text <> '' OR
(($2::boolean OR deleted_at IS NULL)
AND ($3::boolean OR purged_at IS NULL)
AND ($4::boolean OR placeholder=false)
AND ($5::boolean OR reporting_enabled_at IS NOT NULL)))
AND ($1::text = '' OR $1::text = 'all'
OR ($1::text = 'deleted' AND deleted_at IS NOT NULL)
OR ($1::text = 'purged' AND purged_at IS NOT NULL)
OR ($1::text = 'placeholder' AND placeholder AND purged_at IS NULL)
OR ($1::text IN ('legacy','old_reporting') AND reporting_enabled_at IS NULL AND purged_at IS NULL)
OR ($1::text = 'reporting' AND reporting_enabled_at IS NOT NULL AND purged_at IS NULL))
AND ($6::text = '' OR owner_user_id=NULLIF($6::text,'')::uuid)
AND ($7::text = '' OR group_id=NULLIF($7::text,'')::uuid)
AND ($8::text = '' OR parent_session_id=NULLIF($8::text,'')::uuid)
AND ($9::text = '' OR session_type=$9::text)
AND ($10::text = '' OR client_type=$10::text)
AND ($11::text = '' OR started_at>=NULLIF($11::text,'')::timestamptz)
AND ($12::text = '' OR started_at<NULLIF($12::text,'')::timestamptz)
ORDER BY COALESCE(last_active_at,started_at) DESC,id DESC
LIMIT $14::integer OFFSET $13::integer
`
type ListSessionsParams struct {
Status string
IncludeDeleted bool
IncludePurged bool
IncludePlaceholder bool
IncludeLegacy bool
OwnerID string
GroupID string
ParentID string
SessionType string
ClientType string
FromTime string
UntilTime string
PageOffset int32
PageLimit int32
}
func (q *Queries) ListSessions(ctx context.Context, arg ListSessionsParams) ([][]byte, error) {
rows, err := q.db.Query(ctx, listSessions,
arg.Status,
arg.IncludeDeleted,
arg.IncludePurged,
arg.IncludePlaceholder,
arg.IncludeLegacy,
arg.OwnerID,
arg.GroupID,
arg.ParentID,
arg.SessionType,
arg.ClientType,
arg.FromTime,
arg.UntilTime,
arg.PageOffset,
arg.PageLimit,
)
if err != nil {
return nil, err
}
defer rows.Close()
items := [][]byte{}
for rows.Next() {
var data []byte
if err := rows.Scan(&data); err != nil {
return nil, err
}
items = append(items, data)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const listTurnFacts = `-- name: ListTurnFacts :many
SELECT jsonb_build_object(
'turn_index',turn_index,'started_at',started_at,'ended_at',ended_at,
'stop_reason',stop_reason,'facts_version',facts_version,
'resources_snapshot_id',resources_snapshot_id,'error_code',error_code
) AS data FROM session_turns WHERE session_id=$1::uuid ORDER BY turn_index
`
func (q *Queries) ListTurnFacts(ctx context.Context, dollar_1 string) ([][]byte, error) {
rows, err := q.db.Query(ctx, listTurnFacts, dollar_1)
if err != nil {
return nil, err
}
defer rows.Close()
items := [][]byte{}
for rows.Next() {
var data []byte
if err := rows.Scan(&data); err != nil {
return nil, err
}
items = append(items, data)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const listTurnIndexes = `-- name: ListTurnIndexes :many
SELECT turn_index FROM session_turns WHERE session_id=$1::uuid ORDER BY turn_index
`
func (q *Queries) ListTurnIndexes(ctx context.Context, dollar_1 string) ([]int32, error) {
rows, err := q.db.Query(ctx, listTurnIndexes, dollar_1)
if err != nil {
return nil, err
}
defer rows.Close()
items := []int32{}
for rows.Next() {
var turn_index int32
if err := rows.Scan(&turn_index); err != nil {
return nil, err
}
items = append(items, turn_index)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const lockFamily = `-- name: LockFamily :many
SELECT id::text FROM sessions WHERE id=$1::uuid OR parent_session_id=$1::uuid ORDER BY id FOR UPDATE
`
func (q *Queries) LockFamily(ctx context.Context, dollar_1 string) ([]string, error) {
rows, err := q.db.Query(ctx, lockFamily, dollar_1)
if err != nil {
return nil, err
}
defer rows.Close()
items := []string{}
for rows.Next() {
var id string
if err := rows.Scan(&id); err != nil {
return nil, err
}
items = append(items, id)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const lockReportingUser = `-- name: LockReportingUser :one
SELECT id::text FROM users WHERE id = $1::uuid FOR UPDATE
`
func (q *Queries) LockReportingUser(ctx context.Context, dollar_1 string) (string, error) {
row := q.db.QueryRow(ctx, lockReportingUser, dollar_1)
var id string
err := row.Scan(&id)
return id, err
}
const lockSession = `-- name: LockSession :one
SELECT jsonb_build_object(
'id',id,'owner_user_id',owner_user_id,'group_id',group_id,'parent_session_id',parent_session_id,
'model_id',model_id,'device_id',device_id,'title',title,'session_type',session_type,
'client_type',client_type,'client_name',client_name,'started_at',started_at,
'last_active_at',last_active_at,'ended_at',ended_at,'deleted_at',deleted_at,'purged_at',purged_at,
'placeholder',placeholder,'started_provis',started_at_provisional,'clock_suspect',clock_suspect,
'state_seq',state_seq,'state_hash',encode(state_hash,'base64'),'state_received_at',state_received_at,
'resources_id',resources_snapshot_id,'acked_turn',acked_turn,'facts_version',facts_version,
'last_stop_reason',last_stop_reason,'active_seconds',active_seconds,
'client_deleted_at',client_deleted_at,'reporting_enabled_at',reporting_enabled_at
) AS data FROM sessions WHERE id = $1::uuid FOR UPDATE
`
func (q *Queries) LockSession(ctx context.Context, dollar_1 string) ([]byte, error) {
row := q.db.QueryRow(ctx, lockSession, dollar_1)
var data []byte
err := row.Scan(&data)
return data, err
}
const purgeSessions = `-- name: PurgeSessions :exec
UPDATE sessions SET deleted_at=COALESCE(deleted_at,now()),client_deleted_at=COALESCE(client_deleted_at,now()),
purged_at=COALESCE(purged_at,now()),updated_at=now() WHERE id=ANY($1::uuid[])
`
func (q *Queries) PurgeSessions(ctx context.Context, dollar_1 []string) error {
_, err := q.db.Exec(ctx, purgeSessions, dollar_1)
return err
}
const recomputeSession = `-- name: RecomputeSession :exec
UPDATE sessions SET
turn_count=($1::jsonb->>'turn_count')::integer,
acked_turn=($1::jsonb->>'acked_turn')::integer,
active_seconds=($1::jsonb->>'active_seconds')::bigint,
started_at=CASE WHEN started_at_provisional AND
($1::jsonb->>'first_started')::timestamptz < started_at
THEN ($1::jsonb->>'first_started')::timestamptz ELSE started_at END,
last_active_at=($1::jsonb->>'last_active_at')::timestamptz,
ended_at=($1::jsonb->>'ended_at')::timestamptz,
facts_version=NULLIF(($1::jsonb->>'facts_version')::integer,0),
failure_code=$1::jsonb->>'failure_code',
last_stop_reason=NULLIF($1::jsonb->>'last_stop_reason',''),
resources_snapshot_id=NULLIF($1::jsonb->>'resources_snapshot_id',''),
reporting_enabled_at=COALESCE(reporting_enabled_at,($1::jsonb->>'received_at')::timestamptz),
updated_at=($1::jsonb->>'received_at')::timestamptz
WHERE id=($1::jsonb->>'id')::uuid
`
func (q *Queries) RecomputeSession(ctx context.Context, payload []byte) error {
_, err := q.db.Exec(ctx, recomputeSession, payload)
return err
}
const saveSession = `-- name: SaveSession :exec
UPDATE sessions SET
session_type=$1::jsonb->>'session_type',
client_type=$1::jsonb->>'client_type',
client_name=$1::jsonb->>'client_type',
client_version=$1::jsonb->>'client_version',
engine_version=$1::jsonb->>'engine_version',
runtime_version=$1::jsonb->>'runtime_version',
expert_id=NULLIF($1::jsonb->>'expert_id','')::uuid,
model_id=NULLIF($1::jsonb->>'model_id','')::uuid,
mode=$1::jsonb->>'mode',
workspace_kind=$1::jsonb->>'workspace_kind',
started_at=($1::jsonb->>'started_at')::timestamptz,
client_deleted_at=($1::jsonb->>'client_deleted_at')::timestamptz,
placeholder=false,started_at_provisional=false,
reporting_enabled_at=COALESCE(reporting_enabled_at,($1::jsonb->>'received_at')::timestamptz),
updated_at=($1::jsonb->>'received_at')::timestamptz
WHERE id=($1::jsonb->>'id')::uuid
`
func (q *Queries) SaveSession(ctx context.Context, payload []byte) error {
_, err := q.db.Exec(ctx, saveSession, payload)
return err
}
const saveSkillEvent = `-- name: SaveSkillEvent :exec
INSERT INTO session_skill_events
SELECT (jsonb_populate_record(NULL::session_skill_events,$1::jsonb)).*
`
func (q *Queries) SaveSkillEvent(ctx context.Context, payload []byte) error {
_, err := q.db.Exec(ctx, saveSkillEvent, payload)
return err
}
const saveSnapshot = `-- name: SaveSnapshot :exec
INSERT INTO session_resource_snapshots(session_id,snapshot_id,revision,state_version,items)
VALUES (($1::jsonb->>'session_id')::uuid,$1::jsonb->>'snapshot_id',
($1::jsonb->>'revision')::bigint,($1::jsonb->>'state_version')::bigint,
$1::jsonb->'items')
ON CONFLICT (session_id,snapshot_id) DO NOTHING
`
func (q *Queries) SaveSnapshot(ctx context.Context, payload []byte) error {
_, err := q.db.Exec(ctx, saveSnapshot, payload)
return err
}
const saveSnapshotItem = `-- name: SaveSnapshotItem :exec
INSERT INTO session_resource_snapshot_items
SELECT (jsonb_populate_record(NULL::session_resource_snapshot_items,$1::jsonb)).*
ON CONFLICT (session_id,snapshot_id,resource_id) DO NOTHING
`
func (q *Queries) SaveSnapshotItem(ctx context.Context, payload []byte) error {
_, err := q.db.Exec(ctx, saveSnapshotItem, payload)
return err
}
const saveTool = `-- name: SaveTool :exec
INSERT INTO session_turn_tools
SELECT (jsonb_populate_record(NULL::session_turn_tools,$1::jsonb)).*
`
func (q *Queries) SaveTool(ctx context.Context, payload []byte) error {
_, err := q.db.Exec(ctx, saveTool, payload)
return err
}
const saveTurn = `-- name: SaveTurn :exec
INSERT INTO session_turns
SELECT (jsonb_populate_record(NULL::session_turns,$1::jsonb)).*
`
func (q *Queries) SaveTurn(ctx context.Context, payload []byte) error {
_, err := q.db.Exec(ctx, saveTurn, payload)
return err
}
const sessionStats = `-- name: SessionStats :one
SELECT jsonb_build_object(
'turns',(SELECT count(*) FROM session_turns WHERE session_id=$1::uuid),
'tools',(SELECT count(*) FROM session_turn_tools WHERE session_id=$1::uuid),
'skill_events',(SELECT count(*) FROM session_skill_events WHERE session_id=$1::uuid),
'resource_snapshots',(SELECT count(*) FROM session_resource_snapshots WHERE session_id=$1::uuid),
'model_calls',(SELECT count(*) FROM model_calls WHERE session_id=$1::uuid),
'mcp_tool_calls',(SELECT count(*) FROM mcp_tool_calls WHERE session_id=$1::uuid),
'image_calls',(SELECT count(*) FROM image_calls WHERE session_id=$1::uuid)
) AS data
`
func (q *Queries) SessionStats(ctx context.Context, dollar_1 string) ([]byte, error) {
row := q.db.QueryRow(ctx, sessionStats, dollar_1)
var data []byte
err := row.Scan(&data)
return data, err
}
const setState = `-- name: SetState :exec
UPDATE sessions SET state_seq=($1::jsonb->>'state_seq')::bigint,
state_hash=decode($1::jsonb->>'state_hash','hex'),
state_received_at=($1::jsonb->>'received_at')::timestamptz,
updated_at=($1::jsonb->>'received_at')::timestamptz
WHERE id=($1::jsonb->>'id')::uuid
`
func (q *Queries) SetState(ctx context.Context, payload []byte) error {
_, err := q.db.Exec(ctx, setState, payload)
return err
}
const takeReportingRateLimit = `-- name: TakeReportingRateLimit :one
INSERT INTO session_reporting_rate_limits (user_id, kind, bucket_start, request_count)
VALUES ($1::uuid, $2::text, $3::timestamptz, 1)
ON CONFLICT (user_id, kind) DO UPDATE SET
request_count = CASE
WHEN session_reporting_rate_limits.bucket_start = EXCLUDED.bucket_start
THEN session_reporting_rate_limits.request_count + 1
ELSE 1
END,
bucket_start = EXCLUDED.bucket_start
RETURNING request_count
`
type TakeReportingRateLimitParams struct {
UserID string
Kind string
BucketStart time.Time
}
func (q *Queries) TakeReportingRateLimit(ctx context.Context, arg TakeReportingRateLimitParams) (int32, error) {
row := q.db.QueryRow(ctx, takeReportingRateLimit, arg.UserID, arg.Kind, arg.BucketStart)
var request_count int32
err := row.Scan(&request_count)
return request_count, err
}