feat(memory/sqlc): add RETURNING to all insert/upsert queries

Query changes (8 queries promoted from :exec → :one):
- InsertRecallItem, InsertSessionMessage → RETURNING all columns
- InsertArchivalChunk → RETURNING all columns
- InsertSummary → RETURNING all columns
- InsertAuditEntry → RETURNING all columns
- UpsertWorkingContext → RETURNING agent_id, session_key, content, updated_at
- UpsertKV → RETURNING agent_id, key, value, updated_at
- UpsertDocument → RETURNING all columns (includes server-incremented version)

Delegate changes:
- InsertRecallItem: back-populate item.CreatedAt + item.UpdatedAt from row
- InsertArchivalChunk: back-populate chunk.CreatedAt from row
- InsertSummary: back-populate summary.CreatedAt from row
- InsertAuditEntry: back-populate entry.CreatedAt from row
- UpsertDocument: back-populate doc.Version + doc.CreatedAt + doc.UpdatedAt
- UpsertWorkingContext, UpsertKV, InsertSessionMessage: discard row, return err

Eliminates follow-up SELECTs for server-assigned timestamps.
Version counter on agent_documents is now authoritative after upsert.
All tests pass (integration + delegate + store).
This commit is contained in:
ZanzyTHEbar 2026-02-18 23:49:03 +00:00
parent 3c7845a632
commit c4882b5273
26 changed files with 712 additions and 247 deletions

View file

@ -216,17 +216,18 @@ func (d *LibSQLDelegate) GetWorkingContext(ctx context.Context, agentID, session
} }
func (d *LibSQLDelegate) UpsertWorkingContext(ctx context.Context, agentID, sessionKey, content string) error { func (d *LibSQLDelegate) UpsertWorkingContext(ctx context.Context, agentID, sessionKey, content string) error {
return d.queries.UpsertWorkingContext(ctx, memsqlc.UpsertWorkingContextParams{ _, err := d.queries.UpsertWorkingContext(ctx, memsqlc.UpsertWorkingContextParams{
AgentID: agentID, AgentID: agentID,
SessionKey: sessionKey, SessionKey: sessionKey,
Content: content, Content: content,
}) })
return err
} }
// --- Recall Items --- // --- Recall Items ---
func (d *LibSQLDelegate) InsertRecallItem(ctx context.Context, item *memory.RecallItem) error { func (d *LibSQLDelegate) InsertRecallItem(ctx context.Context, item *memory.RecallItem) error {
return d.queries.InsertRecallItem(ctx, memsqlc.InsertRecallItemParams{ row, err := d.queries.InsertRecallItem(ctx, memsqlc.InsertRecallItemParams{
ID: item.ID, ID: item.ID,
AgentID: item.AgentID, AgentID: item.AgentID,
SessionKey: item.SessionKey, SessionKey: item.SessionKey,
@ -238,6 +239,12 @@ func (d *LibSQLDelegate) InsertRecallItem(ctx context.Context, item *memory.Reca
Content: item.Content, Content: item.Content,
Tags: item.Tags, Tags: item.Tags,
}) })
if err != nil {
return err
}
item.CreatedAt = row.CreatedAt
item.UpdatedAt = row.UpdatedAt
return nil
} }
func (d *LibSQLDelegate) GetRecallItem(ctx context.Context, agentID string, id ids.UUID) (*memory.RecallItem, error) { func (d *LibSQLDelegate) GetRecallItem(ctx context.Context, agentID string, id ids.UUID) (*memory.RecallItem, error) {
@ -307,7 +314,7 @@ func (d *LibSQLDelegate) SearchRecallByKeyword(ctx context.Context, query, agent
func (d *LibSQLDelegate) InsertArchivalChunk(ctx context.Context, chunk *memory.ArchivalChunk) error { func (d *LibSQLDelegate) InsertArchivalChunk(ctx context.Context, chunk *memory.ArchivalChunk) error {
// Embedding.Value() returns nil (SQL NULL) for empty embeddings, // Embedding.Value() returns nil (SQL NULL) for empty embeddings,
// and F32_BLOB bytes for populated ones — no manual conversion needed. // and F32_BLOB bytes for populated ones — no manual conversion needed.
return d.queries.InsertArchivalChunk(ctx, memsqlc.InsertArchivalChunkParams{ row, err := d.queries.InsertArchivalChunk(ctx, memsqlc.InsertArchivalChunkParams{
ID: chunk.ID, ID: chunk.ID,
RecallID: chunk.RecallID, RecallID: chunk.RecallID,
ChunkIndex: int64(chunk.ChunkIndex), ChunkIndex: int64(chunk.ChunkIndex),
@ -316,6 +323,11 @@ func (d *LibSQLDelegate) InsertArchivalChunk(ctx context.Context, chunk *memory.
Source: chunk.Source, Source: chunk.Source,
Hash: chunk.Hash, Hash: chunk.Hash,
}) })
if err != nil {
return err
}
chunk.CreatedAt = row.CreatedAt
return nil
} }
func (d *LibSQLDelegate) GetArchivalChunk(ctx context.Context, agentID string, id ids.UUID) (*memory.ArchivalChunk, error) { func (d *LibSQLDelegate) GetArchivalChunk(ctx context.Context, agentID string, id ids.UUID) (*memory.ArchivalChunk, error) {
@ -364,7 +376,7 @@ func (d *LibSQLDelegate) DeleteArchivalChunks(ctx context.Context, recallID ids.
// --- Summaries --- // --- Summaries ---
func (d *LibSQLDelegate) InsertSummary(ctx context.Context, summary *memory.MemorySummary) error { func (d *LibSQLDelegate) InsertSummary(ctx context.Context, summary *memory.MemorySummary) error {
return d.queries.InsertSummary(ctx, memsqlc.InsertSummaryParams{ row, err := d.queries.InsertSummary(ctx, memsqlc.InsertSummaryParams{
ID: summary.ID, ID: summary.ID,
AgentID: summary.AgentID, AgentID: summary.AgentID,
SessionKey: summary.SessionKey, SessionKey: summary.SessionKey,
@ -372,6 +384,11 @@ func (d *LibSQLDelegate) InsertSummary(ctx context.Context, summary *memory.Memo
FromMsgIdx: int64(summary.FromMsgIdx), FromMsgIdx: int64(summary.FromMsgIdx),
ToMsgIdx: int64(summary.ToMsgIdx), ToMsgIdx: int64(summary.ToMsgIdx),
}) })
if err != nil {
return err
}
summary.CreatedAt = row.CreatedAt
return nil
} }
func (d *LibSQLDelegate) ListSummaries(ctx context.Context, agentID, sessionKey string, limit int) ([]*memory.MemorySummary, error) { func (d *LibSQLDelegate) ListSummaries(ctx context.Context, agentID, sessionKey string, limit int) ([]*memory.MemorySummary, error) {
@ -430,11 +447,12 @@ func (d *LibSQLDelegate) GetKV(ctx context.Context, agentID, key string) (string
} }
func (d *LibSQLDelegate) UpsertKV(ctx context.Context, agentID, key, value string) error { func (d *LibSQLDelegate) UpsertKV(ctx context.Context, agentID, key, value string) error {
return d.queries.UpsertKV(ctx, memsqlc.UpsertKVParams{ _, err := d.queries.UpsertKV(ctx, memsqlc.UpsertKVParams{
AgentID: agentID, AgentID: agentID,
Key: key, Key: key,
Value: value, Value: value,
}) })
return err
} }
func (d *LibSQLDelegate) DeleteKV(ctx context.Context, agentID, key string) error { func (d *LibSQLDelegate) DeleteKV(ctx context.Context, agentID, key string) error {
@ -477,13 +495,21 @@ func (d *LibSQLDelegate) GetDocument(ctx context.Context, agentID, name string)
} }
func (d *LibSQLDelegate) UpsertDocument(ctx context.Context, doc *memory.AgentDocument) error { func (d *LibSQLDelegate) UpsertDocument(ctx context.Context, doc *memory.AgentDocument) error {
return d.queries.UpsertDocument(ctx, memsqlc.UpsertDocumentParams{ row, err := d.queries.UpsertDocument(ctx, memsqlc.UpsertDocumentParams{
ID: doc.ID, ID: doc.ID,
AgentID: doc.AgentID, AgentID: doc.AgentID,
Name: doc.Name, Name: doc.Name,
Category: doc.Category, Category: doc.Category,
Content: doc.Content, Content: doc.Content,
}) })
if err != nil {
return err
}
// Back-populate server-assigned version and timestamps.
doc.Version = int(row.Version)
doc.CreatedAt = row.CreatedAt
doc.UpdatedAt = row.UpdatedAt
return nil
} }
func (d *LibSQLDelegate) DeleteDocument(ctx context.Context, agentID, name string) error { func (d *LibSQLDelegate) DeleteDocument(ctx context.Context, agentID, name string) error {
@ -527,13 +553,14 @@ func (d *LibSQLDelegate) ListAllDocuments(ctx context.Context, agentID string) (
// --- Session Messages --- // --- Session Messages ---
func (d *LibSQLDelegate) InsertSessionMessage(ctx context.Context, agentID, sessionKey, role, content string) error { func (d *LibSQLDelegate) InsertSessionMessage(ctx context.Context, agentID, sessionKey, role, content string) error {
return d.queries.InsertSessionMessage(ctx, memsqlc.InsertSessionMessageParams{ _, err := d.queries.InsertSessionMessage(ctx, memsqlc.InsertSessionMessageParams{
ID: ids.New(), ID: ids.New(),
AgentID: agentID, AgentID: agentID,
SessionKey: sessionKey, SessionKey: sessionKey,
Role: role, Role: role,
Content: content, Content: content,
}) })
return err
} }
func (d *LibSQLDelegate) ListSessionMessages(ctx context.Context, agentID, sessionKey, role string, limit int) ([]*memory.RecallItem, error) { func (d *LibSQLDelegate) ListSessionMessages(ctx context.Context, agentID, sessionKey, role string, limit int) ([]*memory.RecallItem, error) {
@ -563,7 +590,7 @@ func (d *LibSQLDelegate) CountSessionMessages(ctx context.Context, agentID, sess
// --- Audit Log --- // --- Audit Log ---
func (d *LibSQLDelegate) InsertAuditEntry(ctx context.Context, entry *memory.AuditEntry) error { func (d *LibSQLDelegate) InsertAuditEntry(ctx context.Context, entry *memory.AuditEntry) error {
return d.queries.InsertAuditEntry(ctx, memsqlc.InsertAuditEntryParams{ row, err := d.queries.InsertAuditEntry(ctx, memsqlc.InsertAuditEntryParams{
ID: entry.ID, ID: entry.ID,
AgentID: entry.AgentID, AgentID: entry.AgentID,
SessionKey: entry.SessionKey, SessionKey: entry.SessionKey,
@ -573,6 +600,11 @@ func (d *LibSQLDelegate) InsertAuditEntry(ctx context.Context, entry *memory.Aud
Output: &entry.Output, Output: &entry.Output,
DurationMs: ptrInt64(int64(entry.DurationMS)), DurationMs: ptrInt64(int64(entry.DurationMS)),
}) })
if err != nil {
return err
}
entry.CreatedAt = row.CreatedAt
return nil
} }
func (d *LibSQLDelegate) ListAuditEntries(ctx context.Context, agentID string, limit int) ([]*memory.AuditEntry, error) { func (d *LibSQLDelegate) ListAuditEntries(ctx context.Context, agentID string, limit int) ([]*memory.AuditEntry, error) {

View file

@ -59,7 +59,7 @@ func (q *Queries) CountAuditEntriesByAction(ctx context.Context, arg CountAuditE
return count, err return count, err
} }
const InsertAuditEntry = `-- name: InsertAuditEntry :exec const InsertAuditEntry = `-- name: InsertAuditEntry :one
INSERT INTO agent_audit_log ( INSERT INTO agent_audit_log (
id, id,
agent_id, agent_id,
@ -82,6 +82,7 @@ VALUES (
?8, ?8,
datetime('now') datetime('now')
) )
RETURNING id, agent_id, session_key, action, target, input, output, duration_ms, created_at
` `
type InsertAuditEntryParams struct { type InsertAuditEntryParams struct {
@ -119,8 +120,9 @@ type InsertAuditEntryParams struct {
// ?8, // ?8,
// datetime('now') // datetime('now')
// ) // )
func (q *Queries) InsertAuditEntry(ctx context.Context, arg InsertAuditEntryParams) error { // RETURNING id, agent_id, session_key, action, target, input, output, duration_ms, created_at
_, err := q.db.ExecContext(ctx, InsertAuditEntry, func (q *Queries) InsertAuditEntry(ctx context.Context, arg InsertAuditEntryParams) (AgentAuditLog, error) {
row := q.db.QueryRowContext(ctx, InsertAuditEntry,
arg.ID, arg.ID,
arg.AgentID, arg.AgentID,
arg.SessionKey, arg.SessionKey,
@ -130,7 +132,19 @@ func (q *Queries) InsertAuditEntry(ctx context.Context, arg InsertAuditEntryPara
arg.Output, arg.Output,
arg.DurationMs, arg.DurationMs,
) )
return err var i AgentAuditLog
err := row.Scan(
&i.ID,
&i.AgentID,
&i.SessionKey,
&i.Action,
&i.Target,
&i.Input,
&i.Output,
&i.DurationMs,
&i.CreatedAt,
)
return i, err
} }
const ListAuditEntries = `-- name: ListAuditEntries :many const ListAuditEntries = `-- name: ListAuditEntries :many

View file

@ -14,8 +14,12 @@ import (
const CreateAgentConversationFork = `-- name: CreateAgentConversationFork :one const CreateAgentConversationFork = `-- name: CreateAgentConversationFork :one
INSERT INTO agent_conversation_forks ( INSERT INTO agent_conversation_forks (
id, parent_conversation_id, child_conversation_id, checkpoint_id, metadata_json id,
) parent_conversation_id,
child_conversation_id,
checkpoint_id,
metadata_json
)
VALUES (?, ?, ?, ?, ?) VALUES (?, ?, ?, ?, ?)
RETURNING id, parent_conversation_id, child_conversation_id, checkpoint_id, metadata_json, created_at, updated_at RETURNING id, parent_conversation_id, child_conversation_id, checkpoint_id, metadata_json, created_at, updated_at
` `
@ -31,7 +35,11 @@ type CreateAgentConversationForkParams struct {
// CreateAgentConversationFork // CreateAgentConversationFork
// //
// INSERT INTO agent_conversation_forks ( // INSERT INTO agent_conversation_forks (
// id, parent_conversation_id, child_conversation_id, checkpoint_id, metadata_json // id,
// parent_conversation_id,
// child_conversation_id,
// checkpoint_id,
// metadata_json
// ) // )
// VALUES (?, ?, ?, ?, ?) // VALUES (?, ?, ?, ?, ?)
// RETURNING id, parent_conversation_id, child_conversation_id, checkpoint_id, metadata_json, created_at, updated_at // RETURNING id, parent_conversation_id, child_conversation_id, checkpoint_id, metadata_json, created_at, updated_at
@ -57,7 +65,8 @@ func (q *Queries) CreateAgentConversationFork(ctx context.Context, arg CreateAge
} }
const GetAgentConversationForkByChildConversationID = `-- name: GetAgentConversationForkByChildConversationID :one const GetAgentConversationForkByChildConversationID = `-- name: GetAgentConversationForkByChildConversationID :one
SELECT id, parent_conversation_id, child_conversation_id, checkpoint_id, metadata_json, created_at, updated_at FROM agent_conversation_forks SELECT id, parent_conversation_id, child_conversation_id, checkpoint_id, metadata_json, created_at, updated_at
FROM agent_conversation_forks
WHERE child_conversation_id = ? WHERE child_conversation_id = ?
LIMIT 1 LIMIT 1
` `
@ -68,7 +77,8 @@ type GetAgentConversationForkByChildConversationIDParams struct {
// GetAgentConversationForkByChildConversationID // GetAgentConversationForkByChildConversationID
// //
// SELECT id, parent_conversation_id, child_conversation_id, checkpoint_id, metadata_json, created_at, updated_at FROM agent_conversation_forks // SELECT id, parent_conversation_id, child_conversation_id, checkpoint_id, metadata_json, created_at, updated_at
// FROM agent_conversation_forks
// WHERE child_conversation_id = ? // WHERE child_conversation_id = ?
// LIMIT 1 // LIMIT 1
func (q *Queries) GetAgentConversationForkByChildConversationID(ctx context.Context, arg GetAgentConversationForkByChildConversationIDParams) (AgentConversationFork, error) { func (q *Queries) GetAgentConversationForkByChildConversationID(ctx context.Context, arg GetAgentConversationForkByChildConversationIDParams) (AgentConversationFork, error) {
@ -87,7 +97,8 @@ func (q *Queries) GetAgentConversationForkByChildConversationID(ctx context.Cont
} }
const ListAgentConversationForksByParentConversationID = `-- name: ListAgentConversationForksByParentConversationID :many const ListAgentConversationForksByParentConversationID = `-- name: ListAgentConversationForksByParentConversationID :many
SELECT id, parent_conversation_id, child_conversation_id, checkpoint_id, metadata_json, created_at, updated_at FROM agent_conversation_forks SELECT id, parent_conversation_id, child_conversation_id, checkpoint_id, metadata_json, created_at, updated_at
FROM agent_conversation_forks
WHERE parent_conversation_id = ? WHERE parent_conversation_id = ?
ORDER BY created_at DESC ORDER BY created_at DESC
LIMIT ?2 LIMIT ?2
@ -100,7 +111,8 @@ type ListAgentConversationForksByParentConversationIDParams struct {
// ListAgentConversationForksByParentConversationID // ListAgentConversationForksByParentConversationID
// //
// SELECT id, parent_conversation_id, child_conversation_id, checkpoint_id, metadata_json, created_at, updated_at FROM agent_conversation_forks // SELECT id, parent_conversation_id, child_conversation_id, checkpoint_id, metadata_json, created_at, updated_at
// FROM agent_conversation_forks
// WHERE parent_conversation_id = ? // WHERE parent_conversation_id = ?
// ORDER BY created_at DESC // ORDER BY created_at DESC
// LIMIT ?2 // LIMIT ?2

View file

@ -14,8 +14,12 @@ import (
const CreateAgentConversationLink = `-- name: CreateAgentConversationLink :one const CreateAgentConversationLink = `-- name: CreateAgentConversationLink :one
INSERT INTO agent_conversation_links ( INSERT INTO agent_conversation_links (
id, conversation_id, linked_conversation_id, kind, metadata_json id,
) conversation_id,
linked_conversation_id,
kind,
metadata_json
)
VALUES (?, ?, ?, ?, ?) VALUES (?, ?, ?, ?, ?)
RETURNING id, conversation_id, linked_conversation_id, kind, metadata_json, created_at, updated_at RETURNING id, conversation_id, linked_conversation_id, kind, metadata_json, created_at, updated_at
` `
@ -31,7 +35,11 @@ type CreateAgentConversationLinkParams struct {
// CreateAgentConversationLink // CreateAgentConversationLink
// //
// INSERT INTO agent_conversation_links ( // INSERT INTO agent_conversation_links (
// id, conversation_id, linked_conversation_id, kind, metadata_json // id,
// conversation_id,
// linked_conversation_id,
// kind,
// metadata_json
// ) // )
// VALUES (?, ?, ?, ?, ?) // VALUES (?, ?, ?, ?, ?)
// RETURNING id, conversation_id, linked_conversation_id, kind, metadata_json, created_at, updated_at // RETURNING id, conversation_id, linked_conversation_id, kind, metadata_json, created_at, updated_at
@ -58,7 +66,9 @@ func (q *Queries) CreateAgentConversationLink(ctx context.Context, arg CreateAge
const DeleteAgentConversationLink = `-- name: DeleteAgentConversationLink :exec const DeleteAgentConversationLink = `-- name: DeleteAgentConversationLink :exec
DELETE FROM agent_conversation_links DELETE FROM agent_conversation_links
WHERE conversation_id = ? AND linked_conversation_id = ? AND kind = ? WHERE conversation_id = ?
AND linked_conversation_id = ?
AND kind = ?
` `
type DeleteAgentConversationLinkParams struct { type DeleteAgentConversationLinkParams struct {
@ -70,14 +80,17 @@ type DeleteAgentConversationLinkParams struct {
// DeleteAgentConversationLink // DeleteAgentConversationLink
// //
// DELETE FROM agent_conversation_links // DELETE FROM agent_conversation_links
// WHERE conversation_id = ? AND linked_conversation_id = ? AND kind = ? // WHERE conversation_id = ?
// AND linked_conversation_id = ?
// AND kind = ?
func (q *Queries) DeleteAgentConversationLink(ctx context.Context, arg DeleteAgentConversationLinkParams) error { func (q *Queries) DeleteAgentConversationLink(ctx context.Context, arg DeleteAgentConversationLinkParams) error {
_, err := q.db.ExecContext(ctx, DeleteAgentConversationLink, arg.ConversationID, arg.LinkedConversationID, arg.Kind) _, err := q.db.ExecContext(ctx, DeleteAgentConversationLink, arg.ConversationID, arg.LinkedConversationID, arg.Kind)
return err return err
} }
const ListAgentConversationLinksByConversationID = `-- name: ListAgentConversationLinksByConversationID :many const ListAgentConversationLinksByConversationID = `-- name: ListAgentConversationLinksByConversationID :many
SELECT id, conversation_id, linked_conversation_id, kind, metadata_json, created_at, updated_at FROM agent_conversation_links SELECT id, conversation_id, linked_conversation_id, kind, metadata_json, created_at, updated_at
FROM agent_conversation_links
WHERE conversation_id = ? WHERE conversation_id = ?
ORDER BY created_at DESC ORDER BY created_at DESC
LIMIT ?2 LIMIT ?2
@ -90,7 +103,8 @@ type ListAgentConversationLinksByConversationIDParams struct {
// ListAgentConversationLinksByConversationID // ListAgentConversationLinksByConversationID
// //
// SELECT id, conversation_id, linked_conversation_id, kind, metadata_json, created_at, updated_at FROM agent_conversation_links // SELECT id, conversation_id, linked_conversation_id, kind, metadata_json, created_at, updated_at
// FROM agent_conversation_links
// WHERE conversation_id = ? // WHERE conversation_id = ?
// ORDER BY created_at DESC // ORDER BY created_at DESC
// LIMIT ?2 // LIMIT ?2

View file

@ -40,7 +40,10 @@ func (q *Queries) CreateAgentConversation(ctx context.Context, arg CreateAgentCo
} }
const GetAgentConversation = `-- name: GetAgentConversation :one const GetAgentConversation = `-- name: GetAgentConversation :one
SELECT id, title, created_at, updated_at FROM agent_conversations WHERE id = ? LIMIT 1 SELECT id, title, created_at, updated_at
FROM agent_conversations
WHERE id = ?
LIMIT 1
` `
type GetAgentConversationParams struct { type GetAgentConversationParams struct {
@ -49,7 +52,10 @@ type GetAgentConversationParams struct {
// GetAgentConversation // GetAgentConversation
// //
// SELECT id, title, created_at, updated_at FROM agent_conversations WHERE id = ? LIMIT 1 // SELECT id, title, created_at, updated_at
// FROM agent_conversations
// WHERE id = ?
// LIMIT 1
func (q *Queries) GetAgentConversation(ctx context.Context, arg GetAgentConversationParams) (AgentConversation, error) { func (q *Queries) GetAgentConversation(ctx context.Context, arg GetAgentConversationParams) (AgentConversation, error) {
row := q.db.QueryRowContext(ctx, GetAgentConversation, arg.ID) row := q.db.QueryRowContext(ctx, GetAgentConversation, arg.ID)
var i AgentConversation var i AgentConversation
@ -63,7 +69,10 @@ func (q *Queries) GetAgentConversation(ctx context.Context, arg GetAgentConversa
} }
const ListAgentConversations = `-- name: ListAgentConversations :many const ListAgentConversations = `-- name: ListAgentConversations :many
SELECT id, title, created_at, updated_at FROM agent_conversations ORDER BY created_at DESC LIMIT ? SELECT id, title, created_at, updated_at
FROM agent_conversations
ORDER BY created_at DESC
LIMIT ?
` `
type ListAgentConversationsParams struct { type ListAgentConversationsParams struct {
@ -72,7 +81,10 @@ type ListAgentConversationsParams struct {
// ListAgentConversations // ListAgentConversations
// //
// SELECT id, title, created_at, updated_at FROM agent_conversations ORDER BY created_at DESC LIMIT ? // SELECT id, title, created_at, updated_at
// FROM agent_conversations
// ORDER BY created_at DESC
// LIMIT ?
func (q *Queries) ListAgentConversations(ctx context.Context, arg ListAgentConversationsParams) ([]AgentConversation, error) { func (q *Queries) ListAgentConversations(ctx context.Context, arg ListAgentConversationsParams) ([]AgentConversation, error) {
rows, err := q.db.QueryContext(ctx, ListAgentConversations, arg.Limit) rows, err := q.db.QueryContext(ctx, ListAgentConversations, arg.Limit)
if err != nil { if err != nil {

View file

@ -232,7 +232,7 @@ func (q *Queries) ListDocumentsByCategory(ctx context.Context, arg ListDocuments
return items, nil return items, nil
} }
const UpsertDocument = `-- name: UpsertDocument :exec const UpsertDocument = `-- name: UpsertDocument :one
INSERT INTO agent_documents ( INSERT INTO agent_documents (
id, id,
agent_id, agent_id,
@ -261,6 +261,7 @@ SET content = excluded.content,
version = agent_documents.version + 1, version = agent_documents.version + 1,
is_active = 1, is_active = 1,
updated_at = datetime('now') updated_at = datetime('now')
RETURNING id, agent_id, name, category, content, version, is_active, created_at, updated_at
` `
type UpsertDocumentParams struct { type UpsertDocumentParams struct {
@ -301,13 +302,26 @@ type UpsertDocumentParams struct {
// version = agent_documents.version + 1, // version = agent_documents.version + 1,
// is_active = 1, // is_active = 1,
// updated_at = datetime('now') // updated_at = datetime('now')
func (q *Queries) UpsertDocument(ctx context.Context, arg UpsertDocumentParams) error { // RETURNING id, agent_id, name, category, content, version, is_active, created_at, updated_at
_, err := q.db.ExecContext(ctx, UpsertDocument, func (q *Queries) UpsertDocument(ctx context.Context, arg UpsertDocumentParams) (AgentDocument, error) {
row := q.db.QueryRowContext(ctx, UpsertDocument,
arg.ID, arg.ID,
arg.AgentID, arg.AgentID,
arg.Name, arg.Name,
arg.Category, arg.Category,
arg.Content, arg.Content,
) )
return err var i AgentDocument
err := row.Scan(
&i.ID,
&i.AgentID,
&i.Name,
&i.Category,
&i.Content,
&i.Version,
&i.IsActive,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
} }

View file

@ -125,7 +125,7 @@ func (q *Queries) ListKVByPrefix(ctx context.Context, arg ListKVByPrefixParams)
return items, nil return items, nil
} }
const UpsertKV = `-- name: UpsertKV :exec const UpsertKV = `-- name: UpsertKV :one
INSERT INTO agent_kv (agent_id, key, value, updated_at) INSERT INTO agent_kv (agent_id, key, value, updated_at)
VALUES ( VALUES (
?1, ?1,
@ -136,6 +136,7 @@ VALUES (
UPDATE UPDATE
SET value = excluded.value, SET value = excluded.value,
updated_at = excluded.updated_at updated_at = excluded.updated_at
RETURNING agent_id, key, value, updated_at
` `
type UpsertKVParams struct { type UpsertKVParams struct {
@ -156,7 +157,15 @@ type UpsertKVParams struct {
// UPDATE // UPDATE
// SET value = excluded.value, // SET value = excluded.value,
// updated_at = excluded.updated_at // updated_at = excluded.updated_at
func (q *Queries) UpsertKV(ctx context.Context, arg UpsertKVParams) error { // RETURNING agent_id, key, value, updated_at
_, err := q.db.ExecContext(ctx, UpsertKV, arg.AgentID, arg.Key, arg.Value) func (q *Queries) UpsertKV(ctx context.Context, arg UpsertKVParams) (AgentKv, error) {
return err row := q.db.QueryRowContext(ctx, UpsertKV, arg.AgentID, arg.Key, arg.Value)
var i AgentKv
err := row.Scan(
&i.AgentID,
&i.Key,
&i.Value,
&i.UpdatedAt,
)
return i, err
} }

View file

@ -14,8 +14,14 @@ import (
const AddAgentMention = `-- name: AddAgentMention :one const AddAgentMention = `-- name: AddAgentMention :one
INSERT INTO agent_mentions ( INSERT INTO agent_mentions (
id, conversation_id, message_id, kind, target_id, raw, metadata_json id,
) conversation_id,
message_id,
kind,
target_id,
raw,
metadata_json
)
VALUES (?, ?, ?, ?, ?, ?, ?) VALUES (?, ?, ?, ?, ?, ?, ?)
RETURNING id, conversation_id, message_id, kind, target_id, raw, metadata_json, created_at, updated_at RETURNING id, conversation_id, message_id, kind, target_id, raw, metadata_json, created_at, updated_at
` `
@ -33,7 +39,13 @@ type AddAgentMentionParams struct {
// AddAgentMention // AddAgentMention
// //
// INSERT INTO agent_mentions ( // INSERT INTO agent_mentions (
// id, conversation_id, message_id, kind, target_id, raw, metadata_json // id,
// conversation_id,
// message_id,
// kind,
// target_id,
// raw,
// metadata_json
// ) // )
// VALUES (?, ?, ?, ?, ?, ?, ?) // VALUES (?, ?, ?, ?, ?, ?, ?)
// RETURNING id, conversation_id, message_id, kind, target_id, raw, metadata_json, created_at, updated_at // RETURNING id, conversation_id, message_id, kind, target_id, raw, metadata_json, created_at, updated_at
@ -63,7 +75,8 @@ func (q *Queries) AddAgentMention(ctx context.Context, arg AddAgentMentionParams
} }
const ListAgentMentionsByConversationID = `-- name: ListAgentMentionsByConversationID :many const ListAgentMentionsByConversationID = `-- name: ListAgentMentionsByConversationID :many
SELECT id, conversation_id, message_id, kind, target_id, raw, metadata_json, created_at, updated_at FROM agent_mentions SELECT id, conversation_id, message_id, kind, target_id, raw, metadata_json, created_at, updated_at
FROM agent_mentions
WHERE conversation_id = ? WHERE conversation_id = ?
ORDER BY created_at DESC ORDER BY created_at DESC
LIMIT ?2 LIMIT ?2
@ -76,7 +89,8 @@ type ListAgentMentionsByConversationIDParams struct {
// ListAgentMentionsByConversationID // ListAgentMentionsByConversationID
// //
// SELECT id, conversation_id, message_id, kind, target_id, raw, metadata_json, created_at, updated_at FROM agent_mentions // SELECT id, conversation_id, message_id, kind, target_id, raw, metadata_json, created_at, updated_at
// FROM agent_mentions
// WHERE conversation_id = ? // WHERE conversation_id = ?
// ORDER BY created_at DESC // ORDER BY created_at DESC
// LIMIT ?2 // LIMIT ?2

View file

@ -14,8 +14,13 @@ import (
const AddAgentMessageRevision = `-- name: AddAgentMessageRevision :one const AddAgentMessageRevision = `-- name: AddAgentMessageRevision :one
INSERT INTO agent_message_revisions ( INSERT INTO agent_message_revisions (
id, message_id, editor, old_content, new_content, metadata_json id,
) message_id,
editor,
old_content,
new_content,
metadata_json
)
VALUES (?, ?, ?, ?, ?, ?) VALUES (?, ?, ?, ?, ?, ?)
RETURNING id, message_id, editor, old_content, new_content, metadata_json, created_at, updated_at RETURNING id, message_id, editor, old_content, new_content, metadata_json, created_at, updated_at
` `
@ -32,7 +37,12 @@ type AddAgentMessageRevisionParams struct {
// AddAgentMessageRevision // AddAgentMessageRevision
// //
// INSERT INTO agent_message_revisions ( // INSERT INTO agent_message_revisions (
// id, message_id, editor, old_content, new_content, metadata_json // id,
// message_id,
// editor,
// old_content,
// new_content,
// metadata_json
// ) // )
// VALUES (?, ?, ?, ?, ?, ?) // VALUES (?, ?, ?, ?, ?, ?)
// RETURNING id, message_id, editor, old_content, new_content, metadata_json, created_at, updated_at // RETURNING id, message_id, editor, old_content, new_content, metadata_json, created_at, updated_at
@ -60,7 +70,8 @@ func (q *Queries) AddAgentMessageRevision(ctx context.Context, arg AddAgentMessa
} }
const ListAgentMessageRevisionsByMessageID = `-- name: ListAgentMessageRevisionsByMessageID :many const ListAgentMessageRevisionsByMessageID = `-- name: ListAgentMessageRevisionsByMessageID :many
SELECT id, message_id, editor, old_content, new_content, metadata_json, created_at, updated_at FROM agent_message_revisions SELECT id, message_id, editor, old_content, new_content, metadata_json, created_at, updated_at
FROM agent_message_revisions
WHERE message_id = ? WHERE message_id = ?
ORDER BY created_at DESC ORDER BY created_at DESC
LIMIT ?2 LIMIT ?2
@ -73,7 +84,8 @@ type ListAgentMessageRevisionsByMessageIDParams struct {
// ListAgentMessageRevisionsByMessageID // ListAgentMessageRevisionsByMessageID
// //
// SELECT id, message_id, editor, old_content, new_content, metadata_json, created_at, updated_at FROM agent_message_revisions // SELECT id, message_id, editor, old_content, new_content, metadata_json, created_at, updated_at
// FROM agent_message_revisions
// WHERE message_id = ? // WHERE message_id = ?
// ORDER BY created_at DESC // ORDER BY created_at DESC
// LIMIT ?2 // LIMIT ?2

View file

@ -13,7 +13,13 @@ import (
) )
const AddAgentMessage = `-- name: AddAgentMessage :one const AddAgentMessage = `-- name: AddAgentMessage :one
INSERT INTO agent_messages (id, conversation_id, role, content, metadata_json) INSERT INTO agent_messages (
id,
conversation_id,
role,
content,
metadata_json
)
VALUES (?, ?, ?, ?, ?) VALUES (?, ?, ?, ?, ?)
RETURNING id, conversation_id, role, content, metadata_json, created_at, updated_at RETURNING id, conversation_id, role, content, metadata_json, created_at, updated_at
` `
@ -28,7 +34,13 @@ type AddAgentMessageParams struct {
// AddAgentMessage // AddAgentMessage
// //
// INSERT INTO agent_messages (id, conversation_id, role, content, metadata_json) // INSERT INTO agent_messages (
// id,
// conversation_id,
// role,
// content,
// metadata_json
// )
// VALUES (?, ?, ?, ?, ?) // VALUES (?, ?, ?, ?, ?)
// RETURNING id, conversation_id, role, content, metadata_json, created_at, updated_at // RETURNING id, conversation_id, role, content, metadata_json, created_at, updated_at
func (q *Queries) AddAgentMessage(ctx context.Context, arg AddAgentMessageParams) (AgentMessage, error) { func (q *Queries) AddAgentMessage(ctx context.Context, arg AddAgentMessageParams) (AgentMessage, error) {
@ -53,7 +65,8 @@ func (q *Queries) AddAgentMessage(ctx context.Context, arg AddAgentMessageParams
} }
const ListAgentMessagesByConversationID = `-- name: ListAgentMessagesByConversationID :many const ListAgentMessagesByConversationID = `-- name: ListAgentMessagesByConversationID :many
SELECT id, conversation_id, role, content, metadata_json, created_at, updated_at FROM agent_messages SELECT id, conversation_id, role, content, metadata_json, created_at, updated_at
FROM agent_messages
WHERE conversation_id = ? WHERE conversation_id = ?
ORDER BY created_at ASC ORDER BY created_at ASC
` `
@ -64,7 +77,8 @@ type ListAgentMessagesByConversationIDParams struct {
// ListAgentMessagesByConversationID // ListAgentMessagesByConversationID
// //
// SELECT id, conversation_id, role, content, metadata_json, created_at, updated_at FROM agent_messages // SELECT id, conversation_id, role, content, metadata_json, created_at, updated_at
// FROM agent_messages
// WHERE conversation_id = ? // WHERE conversation_id = ?
// ORDER BY created_at ASC // ORDER BY created_at ASC
func (q *Queries) ListAgentMessagesByConversationID(ctx context.Context, arg ListAgentMessagesByConversationIDParams) ([]AgentMessage, error) { func (q *Queries) ListAgentMessagesByConversationID(ctx context.Context, arg ListAgentMessagesByConversationIDParams) ([]AgentMessage, error) {
@ -99,7 +113,8 @@ func (q *Queries) ListAgentMessagesByConversationID(ctx context.Context, arg Lis
} }
const ListAgentMessagesByConversationIDLimit = `-- name: ListAgentMessagesByConversationIDLimit :many const ListAgentMessagesByConversationIDLimit = `-- name: ListAgentMessagesByConversationIDLimit :many
SELECT id, conversation_id, role, content, metadata_json, created_at, updated_at FROM agent_messages SELECT id, conversation_id, role, content, metadata_json, created_at, updated_at
FROM agent_messages
WHERE conversation_id = ? WHERE conversation_id = ?
ORDER BY created_at ASC ORDER BY created_at ASC
LIMIT ? LIMIT ?
@ -112,7 +127,8 @@ type ListAgentMessagesByConversationIDLimitParams struct {
// ListAgentMessagesByConversationIDLimit // ListAgentMessagesByConversationIDLimit
// //
// SELECT id, conversation_id, role, content, metadata_json, created_at, updated_at FROM agent_messages // SELECT id, conversation_id, role, content, metadata_json, created_at, updated_at
// FROM agent_messages
// WHERE conversation_id = ? // WHERE conversation_id = ?
// ORDER BY created_at ASC // ORDER BY created_at ASC
// LIMIT ? // LIMIT ?

View file

@ -55,8 +55,16 @@ func (q *Queries) AddAgentRunState(ctx context.Context, arg AddAgentRunStatePara
const AddAgentStateTransition = `-- name: AddAgentStateTransition :one const AddAgentStateTransition = `-- name: AddAgentStateTransition :one
INSERT INTO agent_state_transitions ( INSERT INTO agent_state_transitions (
id, run_id, step_index, from_state, to_state, trigger, at, meta_json, error id,
) run_id,
step_index,
from_state,
to_state,
trigger,
at,
meta_json,
error
)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
RETURNING id, run_id, step_index, from_state, to_state, "trigger", at, meta_json, error, created_at, updated_at RETURNING id, run_id, step_index, from_state, to_state, "trigger", at, meta_json, error, created_at, updated_at
` `
@ -76,7 +84,15 @@ type AddAgentStateTransitionParams struct {
// AddAgentStateTransition // AddAgentStateTransition
// //
// INSERT INTO agent_state_transitions ( // INSERT INTO agent_state_transitions (
// id, run_id, step_index, from_state, to_state, trigger, at, meta_json, error // id,
// run_id,
// step_index,
// from_state,
// to_state,
// trigger,
// at,
// meta_json,
// error
// ) // )
// VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?) // VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
// RETURNING id, run_id, step_index, from_state, to_state, "trigger", at, meta_json, error, created_at, updated_at // RETURNING id, run_id, step_index, from_state, to_state, "trigger", at, meta_json, error, created_at, updated_at
@ -110,7 +126,13 @@ func (q *Queries) AddAgentStateTransition(ctx context.Context, arg AddAgentState
} }
const CreateAgentCheckpoint = `-- name: CreateAgentCheckpoint :one const CreateAgentCheckpoint = `-- name: CreateAgentCheckpoint :one
INSERT INTO agent_checkpoints (id, conversation_id, name, run_state_id, metadata_json) INSERT INTO agent_checkpoints (
id,
conversation_id,
name,
run_state_id,
metadata_json
)
VALUES (?, ?, ?, ?, ?) VALUES (?, ?, ?, ?, ?)
RETURNING id, conversation_id, name, run_state_id, metadata_json, created_at, updated_at RETURNING id, conversation_id, name, run_state_id, metadata_json, created_at, updated_at
` `
@ -125,7 +147,13 @@ type CreateAgentCheckpointParams struct {
// CreateAgentCheckpoint // CreateAgentCheckpoint
// //
// INSERT INTO agent_checkpoints (id, conversation_id, name, run_state_id, metadata_json) // INSERT INTO agent_checkpoints (
// id,
// conversation_id,
// name,
// run_state_id,
// metadata_json
// )
// VALUES (?, ?, ?, ?, ?) // VALUES (?, ?, ?, ?, ?)
// RETURNING id, conversation_id, name, run_state_id, metadata_json, created_at, updated_at // RETURNING id, conversation_id, name, run_state_id, metadata_json, created_at, updated_at
func (q *Queries) CreateAgentCheckpoint(ctx context.Context, arg CreateAgentCheckpointParams) (AgentCheckpoint, error) { func (q *Queries) CreateAgentCheckpoint(ctx context.Context, arg CreateAgentCheckpointParams) (AgentCheckpoint, error) {
@ -187,8 +215,10 @@ func (q *Queries) CreateAgentRun(ctx context.Context, arg CreateAgentRunParams)
} }
const GetAgentCheckpointByConversationIDAndName = `-- name: GetAgentCheckpointByConversationIDAndName :one const GetAgentCheckpointByConversationIDAndName = `-- name: GetAgentCheckpointByConversationIDAndName :one
SELECT id, conversation_id, name, run_state_id, metadata_json, created_at, updated_at FROM agent_checkpoints SELECT id, conversation_id, name, run_state_id, metadata_json, created_at, updated_at
WHERE conversation_id = ? AND name = ? FROM agent_checkpoints
WHERE conversation_id = ?
AND name = ?
LIMIT 1 LIMIT 1
` `
@ -199,8 +229,10 @@ type GetAgentCheckpointByConversationIDAndNameParams struct {
// GetAgentCheckpointByConversationIDAndName // GetAgentCheckpointByConversationIDAndName
// //
// SELECT id, conversation_id, name, run_state_id, metadata_json, created_at, updated_at FROM agent_checkpoints // SELECT id, conversation_id, name, run_state_id, metadata_json, created_at, updated_at
// WHERE conversation_id = ? AND name = ? // FROM agent_checkpoints
// WHERE conversation_id = ?
// AND name = ?
// LIMIT 1 // LIMIT 1
func (q *Queries) GetAgentCheckpointByConversationIDAndName(ctx context.Context, arg GetAgentCheckpointByConversationIDAndNameParams) (AgentCheckpoint, error) { func (q *Queries) GetAgentCheckpointByConversationIDAndName(ctx context.Context, arg GetAgentCheckpointByConversationIDAndNameParams) (AgentCheckpoint, error) {
row := q.db.QueryRowContext(ctx, GetAgentCheckpointByConversationIDAndName, arg.ConversationID, arg.Name) row := q.db.QueryRowContext(ctx, GetAgentCheckpointByConversationIDAndName, arg.ConversationID, arg.Name)
@ -218,7 +250,8 @@ func (q *Queries) GetAgentCheckpointByConversationIDAndName(ctx context.Context,
} }
const GetAgentRunStateByID = `-- name: GetAgentRunStateByID :one const GetAgentRunStateByID = `-- name: GetAgentRunStateByID :one
SELECT id, run_id, step_index, state, snapshot_json, created_at, updated_at FROM agent_run_states SELECT id, run_id, step_index, state, snapshot_json, created_at, updated_at
FROM agent_run_states
WHERE id = ? WHERE id = ?
LIMIT 1 LIMIT 1
` `
@ -229,7 +262,8 @@ type GetAgentRunStateByIDParams struct {
// GetAgentRunStateByID // GetAgentRunStateByID
// //
// SELECT id, run_id, step_index, state, snapshot_json, created_at, updated_at FROM agent_run_states // SELECT id, run_id, step_index, state, snapshot_json, created_at, updated_at
// FROM agent_run_states
// WHERE id = ? // WHERE id = ?
// LIMIT 1 // LIMIT 1
func (q *Queries) GetAgentRunStateByID(ctx context.Context, arg GetAgentRunStateByIDParams) (AgentRunState, error) { func (q *Queries) GetAgentRunStateByID(ctx context.Context, arg GetAgentRunStateByIDParams) (AgentRunState, error) {
@ -248,7 +282,8 @@ func (q *Queries) GetAgentRunStateByID(ctx context.Context, arg GetAgentRunState
} }
const GetLatestAgentRunByConversationID = `-- name: GetLatestAgentRunByConversationID :one const GetLatestAgentRunByConversationID = `-- name: GetLatestAgentRunByConversationID :one
SELECT id, conversation_id, status, metadata_json, created_at, updated_at FROM agent_runs SELECT id, conversation_id, status, metadata_json, created_at, updated_at
FROM agent_runs
WHERE conversation_id = ? WHERE conversation_id = ?
ORDER BY created_at DESC ORDER BY created_at DESC
LIMIT 1 LIMIT 1
@ -260,7 +295,8 @@ type GetLatestAgentRunByConversationIDParams struct {
// GetLatestAgentRunByConversationID // GetLatestAgentRunByConversationID
// //
// SELECT id, conversation_id, status, metadata_json, created_at, updated_at FROM agent_runs // SELECT id, conversation_id, status, metadata_json, created_at, updated_at
// FROM agent_runs
// WHERE conversation_id = ? // WHERE conversation_id = ?
// ORDER BY created_at DESC // ORDER BY created_at DESC
// LIMIT 1 // LIMIT 1
@ -279,7 +315,8 @@ func (q *Queries) GetLatestAgentRunByConversationID(ctx context.Context, arg Get
} }
const GetLatestAgentRunStateByRunID = `-- name: GetLatestAgentRunStateByRunID :one const GetLatestAgentRunStateByRunID = `-- name: GetLatestAgentRunStateByRunID :one
SELECT id, run_id, step_index, state, snapshot_json, created_at, updated_at FROM agent_run_states SELECT id, run_id, step_index, state, snapshot_json, created_at, updated_at
FROM agent_run_states
WHERE run_id = ? WHERE run_id = ?
ORDER BY step_index DESC ORDER BY step_index DESC
LIMIT 1 LIMIT 1
@ -291,7 +328,8 @@ type GetLatestAgentRunStateByRunIDParams struct {
// GetLatestAgentRunStateByRunID // GetLatestAgentRunStateByRunID
// //
// SELECT id, run_id, step_index, state, snapshot_json, created_at, updated_at FROM agent_run_states // SELECT id, run_id, step_index, state, snapshot_json, created_at, updated_at
// FROM agent_run_states
// WHERE run_id = ? // WHERE run_id = ?
// ORDER BY step_index DESC // ORDER BY step_index DESC
// LIMIT 1 // LIMIT 1
@ -311,7 +349,8 @@ func (q *Queries) GetLatestAgentRunStateByRunID(ctx context.Context, arg GetLate
} }
const ListAgentCheckpointsByConversationID = `-- name: ListAgentCheckpointsByConversationID :many const ListAgentCheckpointsByConversationID = `-- name: ListAgentCheckpointsByConversationID :many
SELECT id, conversation_id, name, run_state_id, metadata_json, created_at, updated_at FROM agent_checkpoints SELECT id, conversation_id, name, run_state_id, metadata_json, created_at, updated_at
FROM agent_checkpoints
WHERE conversation_id = ? WHERE conversation_id = ?
ORDER BY created_at DESC ORDER BY created_at DESC
LIMIT ?2 LIMIT ?2
@ -324,7 +363,8 @@ type ListAgentCheckpointsByConversationIDParams struct {
// ListAgentCheckpointsByConversationID // ListAgentCheckpointsByConversationID
// //
// SELECT id, conversation_id, name, run_state_id, metadata_json, created_at, updated_at FROM agent_checkpoints // SELECT id, conversation_id, name, run_state_id, metadata_json, created_at, updated_at
// FROM agent_checkpoints
// WHERE conversation_id = ? // WHERE conversation_id = ?
// ORDER BY created_at DESC // ORDER BY created_at DESC
// LIMIT ?2 // LIMIT ?2
@ -360,7 +400,8 @@ func (q *Queries) ListAgentCheckpointsByConversationID(ctx context.Context, arg
} }
const ListAgentRunStatesByRunID = `-- name: ListAgentRunStatesByRunID :many const ListAgentRunStatesByRunID = `-- name: ListAgentRunStatesByRunID :many
SELECT id, run_id, step_index, state, snapshot_json, created_at, updated_at FROM agent_run_states SELECT id, run_id, step_index, state, snapshot_json, created_at, updated_at
FROM agent_run_states
WHERE run_id = ? WHERE run_id = ?
ORDER BY step_index ASC ORDER BY step_index ASC
LIMIT ?2 LIMIT ?2
@ -373,7 +414,8 @@ type ListAgentRunStatesByRunIDParams struct {
// ListAgentRunStatesByRunID // ListAgentRunStatesByRunID
// //
// SELECT id, run_id, step_index, state, snapshot_json, created_at, updated_at FROM agent_run_states // SELECT id, run_id, step_index, state, snapshot_json, created_at, updated_at
// FROM agent_run_states
// WHERE run_id = ? // WHERE run_id = ?
// ORDER BY step_index ASC // ORDER BY step_index ASC
// LIMIT ?2 // LIMIT ?2
@ -409,7 +451,8 @@ func (q *Queries) ListAgentRunStatesByRunID(ctx context.Context, arg ListAgentRu
} }
const ListAgentStateTransitionsByRunID = `-- name: ListAgentStateTransitionsByRunID :many const ListAgentStateTransitionsByRunID = `-- name: ListAgentStateTransitionsByRunID :many
SELECT id, run_id, step_index, from_state, to_state, "trigger", at, meta_json, error, created_at, updated_at FROM agent_state_transitions SELECT id, run_id, step_index, from_state, to_state, "trigger", at, meta_json, error, created_at, updated_at
FROM agent_state_transitions
WHERE run_id = ? WHERE run_id = ?
ORDER BY at ASC ORDER BY at ASC
LIMIT ?2 LIMIT ?2
@ -422,7 +465,8 @@ type ListAgentStateTransitionsByRunIDParams struct {
// ListAgentStateTransitionsByRunID // ListAgentStateTransitionsByRunID
// //
// SELECT id, run_id, step_index, from_state, to_state, "trigger", at, meta_json, error, created_at, updated_at FROM agent_state_transitions // SELECT id, run_id, step_index, from_state, to_state, "trigger", at, meta_json, error, created_at, updated_at
// FROM agent_state_transitions
// WHERE run_id = ? // WHERE run_id = ?
// ORDER BY at ASC // ORDER BY at ASC
// LIMIT ?2 // LIMIT ?2

View file

@ -90,7 +90,8 @@ func (q *Queries) CreateAgentThread(ctx context.Context, arg CreateAgentThreadPa
} }
const ListAgentThreadMessagesByThreadID = `-- name: ListAgentThreadMessagesByThreadID :many const ListAgentThreadMessagesByThreadID = `-- name: ListAgentThreadMessagesByThreadID :many
SELECT id, thread_id, role, content, metadata_json, created_at, updated_at FROM agent_thread_messages SELECT id, thread_id, role, content, metadata_json, created_at, updated_at
FROM agent_thread_messages
WHERE thread_id = ? WHERE thread_id = ?
ORDER BY created_at ASC ORDER BY created_at ASC
` `
@ -101,7 +102,8 @@ type ListAgentThreadMessagesByThreadIDParams struct {
// ListAgentThreadMessagesByThreadID // ListAgentThreadMessagesByThreadID
// //
// SELECT id, thread_id, role, content, metadata_json, created_at, updated_at FROM agent_thread_messages // SELECT id, thread_id, role, content, metadata_json, created_at, updated_at
// FROM agent_thread_messages
// WHERE thread_id = ? // WHERE thread_id = ?
// ORDER BY created_at ASC // ORDER BY created_at ASC
func (q *Queries) ListAgentThreadMessagesByThreadID(ctx context.Context, arg ListAgentThreadMessagesByThreadIDParams) ([]AgentThreadMessage, error) { func (q *Queries) ListAgentThreadMessagesByThreadID(ctx context.Context, arg ListAgentThreadMessagesByThreadIDParams) ([]AgentThreadMessage, error) {
@ -136,7 +138,8 @@ func (q *Queries) ListAgentThreadMessagesByThreadID(ctx context.Context, arg Lis
} }
const ListAgentThreadMessagesByThreadIDDescLimit = `-- name: ListAgentThreadMessagesByThreadIDDescLimit :many const ListAgentThreadMessagesByThreadIDDescLimit = `-- name: ListAgentThreadMessagesByThreadIDDescLimit :many
SELECT id, thread_id, role, content, metadata_json, created_at, updated_at FROM agent_thread_messages SELECT id, thread_id, role, content, metadata_json, created_at, updated_at
FROM agent_thread_messages
WHERE thread_id = ? WHERE thread_id = ?
ORDER BY created_at DESC ORDER BY created_at DESC
LIMIT ? LIMIT ?
@ -149,7 +152,8 @@ type ListAgentThreadMessagesByThreadIDDescLimitParams struct {
// ListAgentThreadMessagesByThreadIDDescLimit // ListAgentThreadMessagesByThreadIDDescLimit
// //
// SELECT id, thread_id, role, content, metadata_json, created_at, updated_at FROM agent_thread_messages // SELECT id, thread_id, role, content, metadata_json, created_at, updated_at
// FROM agent_thread_messages
// WHERE thread_id = ? // WHERE thread_id = ?
// ORDER BY created_at DESC // ORDER BY created_at DESC
// LIMIT ? // LIMIT ?
@ -185,7 +189,8 @@ func (q *Queries) ListAgentThreadMessagesByThreadIDDescLimit(ctx context.Context
} }
const ListAgentThreadsByConversationID = `-- name: ListAgentThreadsByConversationID :many const ListAgentThreadsByConversationID = `-- name: ListAgentThreadsByConversationID :many
SELECT id, conversation_id, title, metadata_json, created_at, updated_at FROM agent_threads SELECT id, conversation_id, title, metadata_json, created_at, updated_at
FROM agent_threads
WHERE conversation_id = ? WHERE conversation_id = ?
ORDER BY created_at DESC ORDER BY created_at DESC
LIMIT ?2 LIMIT ?2
@ -198,7 +203,8 @@ type ListAgentThreadsByConversationIDParams struct {
// ListAgentThreadsByConversationID // ListAgentThreadsByConversationID
// //
// SELECT id, conversation_id, title, metadata_json, created_at, updated_at FROM agent_threads // SELECT id, conversation_id, title, metadata_json, created_at, updated_at
// FROM agent_threads
// WHERE conversation_id = ? // WHERE conversation_id = ?
// ORDER BY created_at DESC // ORDER BY created_at DESC
// LIMIT ?2 // LIMIT ?2

View file

@ -14,9 +14,17 @@ import (
const AddAgentToolResult = `-- name: AddAgentToolResult :one const AddAgentToolResult = `-- name: AddAgentToolResult :one
INSERT INTO agent_tool_results ( INSERT INTO agent_tool_results (
id, conversation_id, run_id, step_index, id,
tool_call_id, tool_name, full_key, preview, chunk_count, metadata_json conversation_id,
) run_id,
step_index,
tool_call_id,
tool_name,
full_key,
preview,
chunk_count,
metadata_json
)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
RETURNING id, conversation_id, run_id, step_index, tool_call_id, tool_name, full_key, preview, chunk_count, metadata_json, created_at, updated_at RETURNING id, conversation_id, run_id, step_index, tool_call_id, tool_name, full_key, preview, chunk_count, metadata_json, created_at, updated_at
` `
@ -37,8 +45,16 @@ type AddAgentToolResultParams struct {
// AddAgentToolResult // AddAgentToolResult
// //
// INSERT INTO agent_tool_results ( // INSERT INTO agent_tool_results (
// id, conversation_id, run_id, step_index, // id,
// tool_call_id, tool_name, full_key, preview, chunk_count, metadata_json // conversation_id,
// run_id,
// step_index,
// tool_call_id,
// tool_name,
// full_key,
// preview,
// chunk_count,
// metadata_json
// ) // )
// VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?) // VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
// RETURNING id, conversation_id, run_id, step_index, tool_call_id, tool_name, full_key, preview, chunk_count, metadata_json, created_at, updated_at // RETURNING id, conversation_id, run_id, step_index, tool_call_id, tool_name, full_key, preview, chunk_count, metadata_json, created_at, updated_at
@ -74,8 +90,10 @@ func (q *Queries) AddAgentToolResult(ctx context.Context, arg AddAgentToolResult
} }
const GetAgentToolResultByRunIDAndToolCallID = `-- name: GetAgentToolResultByRunIDAndToolCallID :one const GetAgentToolResultByRunIDAndToolCallID = `-- name: GetAgentToolResultByRunIDAndToolCallID :one
SELECT id, conversation_id, run_id, step_index, tool_call_id, tool_name, full_key, preview, chunk_count, metadata_json, created_at, updated_at FROM agent_tool_results SELECT id, conversation_id, run_id, step_index, tool_call_id, tool_name, full_key, preview, chunk_count, metadata_json, created_at, updated_at
WHERE run_id = ? AND tool_call_id = ? FROM agent_tool_results
WHERE run_id = ?
AND tool_call_id = ?
LIMIT 1 LIMIT 1
` `
@ -86,8 +104,10 @@ type GetAgentToolResultByRunIDAndToolCallIDParams struct {
// GetAgentToolResultByRunIDAndToolCallID // GetAgentToolResultByRunIDAndToolCallID
// //
// SELECT id, conversation_id, run_id, step_index, tool_call_id, tool_name, full_key, preview, chunk_count, metadata_json, created_at, updated_at FROM agent_tool_results // SELECT id, conversation_id, run_id, step_index, tool_call_id, tool_name, full_key, preview, chunk_count, metadata_json, created_at, updated_at
// WHERE run_id = ? AND tool_call_id = ? // FROM agent_tool_results
// WHERE run_id = ?
// AND tool_call_id = ?
// LIMIT 1 // LIMIT 1
func (q *Queries) GetAgentToolResultByRunIDAndToolCallID(ctx context.Context, arg GetAgentToolResultByRunIDAndToolCallIDParams) (AgentToolResult, error) { func (q *Queries) GetAgentToolResultByRunIDAndToolCallID(ctx context.Context, arg GetAgentToolResultByRunIDAndToolCallIDParams) (AgentToolResult, error) {
row := q.db.QueryRowContext(ctx, GetAgentToolResultByRunIDAndToolCallID, arg.RunID, arg.ToolCallID) row := q.db.QueryRowContext(ctx, GetAgentToolResultByRunIDAndToolCallID, arg.RunID, arg.ToolCallID)
@ -110,7 +130,8 @@ func (q *Queries) GetAgentToolResultByRunIDAndToolCallID(ctx context.Context, ar
} }
const ListAgentToolResultsByConversationID = `-- name: ListAgentToolResultsByConversationID :many const ListAgentToolResultsByConversationID = `-- name: ListAgentToolResultsByConversationID :many
SELECT id, conversation_id, run_id, step_index, tool_call_id, tool_name, full_key, preview, chunk_count, metadata_json, created_at, updated_at FROM agent_tool_results SELECT id, conversation_id, run_id, step_index, tool_call_id, tool_name, full_key, preview, chunk_count, metadata_json, created_at, updated_at
FROM agent_tool_results
WHERE conversation_id = ? WHERE conversation_id = ?
ORDER BY created_at DESC ORDER BY created_at DESC
` `
@ -121,7 +142,8 @@ type ListAgentToolResultsByConversationIDParams struct {
// ListAgentToolResultsByConversationID // ListAgentToolResultsByConversationID
// //
// SELECT id, conversation_id, run_id, step_index, tool_call_id, tool_name, full_key, preview, chunk_count, metadata_json, created_at, updated_at FROM agent_tool_results // SELECT id, conversation_id, run_id, step_index, tool_call_id, tool_name, full_key, preview, chunk_count, metadata_json, created_at, updated_at
// FROM agent_tool_results
// WHERE conversation_id = ? // WHERE conversation_id = ?
// ORDER BY created_at DESC // ORDER BY created_at DESC
func (q *Queries) ListAgentToolResultsByConversationID(ctx context.Context, arg ListAgentToolResultsByConversationIDParams) ([]AgentToolResult, error) { func (q *Queries) ListAgentToolResultsByConversationID(ctx context.Context, arg ListAgentToolResultsByConversationIDParams) ([]AgentToolResult, error) {
@ -161,7 +183,8 @@ func (q *Queries) ListAgentToolResultsByConversationID(ctx context.Context, arg
} }
const ListAgentToolResultsByConversationIDLimit = `-- name: ListAgentToolResultsByConversationIDLimit :many const ListAgentToolResultsByConversationIDLimit = `-- name: ListAgentToolResultsByConversationIDLimit :many
SELECT id, conversation_id, run_id, step_index, tool_call_id, tool_name, full_key, preview, chunk_count, metadata_json, created_at, updated_at FROM agent_tool_results SELECT id, conversation_id, run_id, step_index, tool_call_id, tool_name, full_key, preview, chunk_count, metadata_json, created_at, updated_at
FROM agent_tool_results
WHERE conversation_id = ? WHERE conversation_id = ?
ORDER BY created_at DESC ORDER BY created_at DESC
LIMIT ? LIMIT ?
@ -174,7 +197,8 @@ type ListAgentToolResultsByConversationIDLimitParams struct {
// ListAgentToolResultsByConversationIDLimit // ListAgentToolResultsByConversationIDLimit
// //
// SELECT id, conversation_id, run_id, step_index, tool_call_id, tool_name, full_key, preview, chunk_count, metadata_json, created_at, updated_at FROM agent_tool_results // SELECT id, conversation_id, run_id, step_index, tool_call_id, tool_name, full_key, preview, chunk_count, metadata_json, created_at, updated_at
// FROM agent_tool_results
// WHERE conversation_id = ? // WHERE conversation_id = ?
// ORDER BY created_at DESC // ORDER BY created_at DESC
// LIMIT ? // LIMIT ?
@ -215,9 +239,11 @@ func (q *Queries) ListAgentToolResultsByConversationIDLimit(ctx context.Context,
} }
const ListAgentToolResultsByRunID = `-- name: ListAgentToolResultsByRunID :many const ListAgentToolResultsByRunID = `-- name: ListAgentToolResultsByRunID :many
SELECT id, conversation_id, run_id, step_index, tool_call_id, tool_name, full_key, preview, chunk_count, metadata_json, created_at, updated_at FROM agent_tool_results SELECT id, conversation_id, run_id, step_index, tool_call_id, tool_name, full_key, preview, chunk_count, metadata_json, created_at, updated_at
FROM agent_tool_results
WHERE run_id = ? WHERE run_id = ?
ORDER BY step_index ASC, created_at ASC ORDER BY step_index ASC,
created_at ASC
LIMIT ?2 LIMIT ?2
` `
@ -228,9 +254,11 @@ type ListAgentToolResultsByRunIDParams struct {
// ListAgentToolResultsByRunID // ListAgentToolResultsByRunID
// //
// SELECT id, conversation_id, run_id, step_index, tool_call_id, tool_name, full_key, preview, chunk_count, metadata_json, created_at, updated_at FROM agent_tool_results // SELECT id, conversation_id, run_id, step_index, tool_call_id, tool_name, full_key, preview, chunk_count, metadata_json, created_at, updated_at
// FROM agent_tool_results
// WHERE run_id = ? // WHERE run_id = ?
// ORDER BY step_index ASC, created_at ASC // ORDER BY step_index ASC,
// created_at ASC
// LIMIT ?2 // LIMIT ?2
func (q *Queries) ListAgentToolResultsByRunID(ctx context.Context, arg ListAgentToolResultsByRunIDParams) ([]AgentToolResult, error) { func (q *Queries) ListAgentToolResultsByRunID(ctx context.Context, arg ListAgentToolResultsByRunIDParams) ([]AgentToolResult, error) {
rows, err := q.db.QueryContext(ctx, ListAgentToolResultsByRunID, arg.RunID, arg.Lim) rows, err := q.db.QueryContext(ctx, ListAgentToolResultsByRunID, arg.RunID, arg.Lim)

View file

@ -184,7 +184,7 @@ func (q *Queries) GetArchivalChunksByIDs(ctx context.Context, arg GetArchivalChu
return items, nil return items, nil
} }
const InsertArchivalChunk = `-- name: InsertArchivalChunk :exec const InsertArchivalChunk = `-- name: InsertArchivalChunk :one
INSERT INTO archival_chunks ( INSERT INTO archival_chunks (
id, id,
recall_id, recall_id,
@ -205,6 +205,7 @@ VALUES (
?7, ?7,
datetime('now') datetime('now')
) )
RETURNING id, recall_id, chunk_index, content, embedding, source, hash, created_at
` `
type InsertArchivalChunkParams struct { type InsertArchivalChunkParams struct {
@ -239,8 +240,9 @@ type InsertArchivalChunkParams struct {
// ?7, // ?7,
// datetime('now') // datetime('now')
// ) // )
func (q *Queries) InsertArchivalChunk(ctx context.Context, arg InsertArchivalChunkParams) error { // RETURNING id, recall_id, chunk_index, content, embedding, source, hash, created_at
_, err := q.db.ExecContext(ctx, InsertArchivalChunk, func (q *Queries) InsertArchivalChunk(ctx context.Context, arg InsertArchivalChunkParams) (ArchivalChunk, error) {
row := q.db.QueryRowContext(ctx, InsertArchivalChunk,
arg.ID, arg.ID,
arg.RecallID, arg.RecallID,
arg.ChunkIndex, arg.ChunkIndex,
@ -249,7 +251,18 @@ func (q *Queries) InsertArchivalChunk(ctx context.Context, arg InsertArchivalChu
arg.Source, arg.Source,
arg.Hash, arg.Hash,
) )
return err var i ArchivalChunk
err := row.Scan(
&i.ID,
&i.RecallID,
&i.ChunkIndex,
&i.Content,
&i.Embedding,
&i.Source,
&i.Hash,
&i.CreatedAt,
)
return i, err
} }
const ListAllArchivalChunks = `-- name: ListAllArchivalChunks :many const ListAllArchivalChunks = `-- name: ListAllArchivalChunks :many

View file

@ -20,7 +20,8 @@ SET status = 'running',
locked_by = ?1, locked_by = ?1,
updated_at = strftime('%Y-%m-%dT%H:%M:%fZ', 'now'), updated_at = strftime('%Y-%m-%dT%H:%M:%fZ', 'now'),
last_error = NULL last_error = NULL
WHERE id = ?2 AND status = 'queued' WHERE id = ?2
AND status = 'queued'
RETURNING id, kind, status, run_at, attempts, max_attempts, locked_at, locked_by, payload_json, dedupe_key, last_error, created_at, updated_at, completed_at RETURNING id, kind, status, run_at, attempts, max_attempts, locked_at, locked_by, payload_json, dedupe_key, last_error, created_at, updated_at, completed_at
` `
@ -38,7 +39,8 @@ type ClaimJobByIDParams struct {
// locked_by = ?1, // locked_by = ?1,
// updated_at = strftime('%Y-%m-%dT%H:%M:%fZ', 'now'), // updated_at = strftime('%Y-%m-%dT%H:%M:%fZ', 'now'),
// last_error = NULL // last_error = NULL
// WHERE id = ?2 AND status = 'queued' // WHERE id = ?2
// AND status = 'queued'
// RETURNING id, kind, status, run_at, attempts, max_attempts, locked_at, locked_by, payload_json, dedupe_key, last_error, created_at, updated_at, completed_at // RETURNING id, kind, status, run_at, attempts, max_attempts, locked_at, locked_by, payload_json, dedupe_key, last_error, created_at, updated_at, completed_at
func (q *Queries) ClaimJobByID(ctx context.Context, arg ClaimJobByIDParams) (Job, error) { func (q *Queries) ClaimJobByID(ctx context.Context, arg ClaimJobByIDParams) (Job, error) {
row := q.db.QueryRowContext(ctx, ClaimJobByID, arg.LockedBy, arg.ID) row := q.db.QueryRowContext(ctx, ClaimJobByID, arg.LockedBy, arg.ID)
@ -63,7 +65,10 @@ func (q *Queries) ClaimJobByID(ctx context.Context, arg ClaimJobByIDParams) (Job
} }
const CountJobsByStatus = `-- name: CountJobsByStatus :many const CountJobsByStatus = `-- name: CountJobsByStatus :many
SELECT status, count(*) AS count FROM jobs GROUP BY status SELECT status,
count(*) AS count
FROM jobs
GROUP BY status
` `
type CountJobsByStatusRow struct { type CountJobsByStatusRow struct {
@ -73,7 +78,10 @@ type CountJobsByStatusRow struct {
// CountJobsByStatus // CountJobsByStatus
// //
// SELECT status, count(*) AS count FROM jobs GROUP BY status // SELECT status,
// count(*) AS count
// FROM jobs
// GROUP BY status
func (q *Queries) CountJobsByStatus(ctx context.Context) ([]CountJobsByStatusRow, error) { func (q *Queries) CountJobsByStatus(ctx context.Context) ([]CountJobsByStatusRow, error) {
rows, err := q.db.QueryContext(ctx, CountJobsByStatus) rows, err := q.db.QueryContext(ctx, CountJobsByStatus)
if err != nil { if err != nil {
@ -99,18 +107,28 @@ func (q *Queries) CountJobsByStatus(ctx context.Context) ([]CountJobsByStatusRow
const EnqueueJob = `-- name: EnqueueJob :one const EnqueueJob = `-- name: EnqueueJob :one
INSERT INTO jobs ( INSERT INTO jobs (
id, kind, status, run_at, max_attempts, payload_json, dedupe_key id,
) kind,
status,
run_at,
max_attempts,
payload_json,
dedupe_key
)
VALUES ( VALUES (
?1, ?1,
?2, ?2,
'queued', 'queued',
coalesce(?3, strftime('%Y-%m-%dT%H:%M:%fZ', 'now')), coalesce(
?3,
strftime('%Y-%m-%dT%H:%M:%fZ', 'now')
),
coalesce(?4, 3), coalesce(?4, 3),
coalesce(?5, '{}'), coalesce(?5, '{}'),
?6 ?6
) ON CONFLICT(kind, dedupe_key) ) ON CONFLICT(kind, dedupe_key)
WHERE dedupe_key IS NOT NULL DO UPDATE WHERE dedupe_key IS NOT NULL DO
UPDATE
SET status = 'queued', SET status = 'queued',
run_at = excluded.run_at, run_at = excluded.run_at,
max_attempts = excluded.max_attempts, max_attempts = excluded.max_attempts,
@ -133,18 +151,28 @@ type EnqueueJobParams struct {
// EnqueueJob // EnqueueJob
// //
// INSERT INTO jobs ( // INSERT INTO jobs (
// id, kind, status, run_at, max_attempts, payload_json, dedupe_key // id,
// kind,
// status,
// run_at,
// max_attempts,
// payload_json,
// dedupe_key
// ) // )
// VALUES ( // VALUES (
// ?1, // ?1,
// ?2, // ?2,
// 'queued', // 'queued',
// coalesce(?3, strftime('%Y-%m-%dT%H:%M:%fZ', 'now')), // coalesce(
// ?3,
// strftime('%Y-%m-%dT%H:%M:%fZ', 'now')
// ),
// coalesce(?4, 3), // coalesce(?4, 3),
// coalesce(?5, '{}'), // coalesce(?5, '{}'),
// ?6 // ?6
// ) ON CONFLICT(kind, dedupe_key) // ) ON CONFLICT(kind, dedupe_key)
// WHERE dedupe_key IS NOT NULL DO UPDATE // WHERE dedupe_key IS NOT NULL DO
// UPDATE
// SET status = 'queued', // SET status = 'queued',
// run_at = excluded.run_at, // run_at = excluded.run_at,
// max_attempts = excluded.max_attempts, // max_attempts = excluded.max_attempts,
@ -183,19 +211,23 @@ func (q *Queries) EnqueueJob(ctx context.Context, arg EnqueueJobParams) (Job, er
} }
const FindNextRunnableJob = `-- name: FindNextRunnableJob :one const FindNextRunnableJob = `-- name: FindNextRunnableJob :one
SELECT id FROM jobs SELECT id
FROM jobs
WHERE status = 'queued' WHERE status = 'queued'
AND run_at <= strftime('%Y-%m-%dT%H:%M:%fZ', 'now') AND run_at <= strftime('%Y-%m-%dT%H:%M:%fZ', 'now')
ORDER BY run_at ASC, created_at ASC ORDER BY run_at ASC,
created_at ASC
LIMIT 1 LIMIT 1
` `
// FindNextRunnableJob // FindNextRunnableJob
// //
// SELECT id FROM jobs // SELECT id
// FROM jobs
// WHERE status = 'queued' // WHERE status = 'queued'
// AND run_at <= strftime('%Y-%m-%dT%H:%M:%fZ', 'now') // AND run_at <= strftime('%Y-%m-%dT%H:%M:%fZ', 'now')
// ORDER BY run_at ASC, created_at ASC // ORDER BY run_at ASC,
// created_at ASC
// LIMIT 1 // LIMIT 1
func (q *Queries) FindNextRunnableJob(ctx context.Context) (ids.UUID, error) { func (q *Queries) FindNextRunnableJob(ctx context.Context) (ids.UUID, error) {
row := q.db.QueryRowContext(ctx, FindNextRunnableJob) row := q.db.QueryRowContext(ctx, FindNextRunnableJob)
@ -205,7 +237,10 @@ func (q *Queries) FindNextRunnableJob(ctx context.Context) (ids.UUID, error) {
} }
const GetJob = `-- name: GetJob :one const GetJob = `-- name: GetJob :one
SELECT id, kind, status, run_at, attempts, max_attempts, locked_at, locked_by, payload_json, dedupe_key, last_error, created_at, updated_at, completed_at FROM jobs WHERE id = ?1 LIMIT 1 SELECT id, kind, status, run_at, attempts, max_attempts, locked_at, locked_by, payload_json, dedupe_key, last_error, created_at, updated_at, completed_at
FROM jobs
WHERE id = ?1
LIMIT 1
` `
type GetJobParams struct { type GetJobParams struct {
@ -214,7 +249,10 @@ type GetJobParams struct {
// GetJob // GetJob
// //
// SELECT id, kind, status, run_at, attempts, max_attempts, locked_at, locked_by, payload_json, dedupe_key, last_error, created_at, updated_at, completed_at FROM jobs WHERE id = ?1 LIMIT 1 // SELECT id, kind, status, run_at, attempts, max_attempts, locked_at, locked_by, payload_json, dedupe_key, last_error, created_at, updated_at, completed_at
// FROM jobs
// WHERE id = ?1
// LIMIT 1
func (q *Queries) GetJob(ctx context.Context, arg GetJobParams) (Job, error) { func (q *Queries) GetJob(ctx context.Context, arg GetJobParams) (Job, error) {
row := q.db.QueryRowContext(ctx, GetJob, arg.ID) row := q.db.QueryRowContext(ctx, GetJob, arg.ID)
var i Job var i Job
@ -238,7 +276,10 @@ func (q *Queries) GetJob(ctx context.Context, arg GetJobParams) (Job, error) {
} }
const ListJobs = `-- name: ListJobs :many const ListJobs = `-- name: ListJobs :many
SELECT id, kind, status, run_at, attempts, max_attempts, locked_at, locked_by, payload_json, dedupe_key, last_error, created_at, updated_at, completed_at FROM jobs ORDER BY created_at DESC LIMIT ?2 OFFSET ?1 SELECT id, kind, status, run_at, attempts, max_attempts, locked_at, locked_by, payload_json, dedupe_key, last_error, created_at, updated_at, completed_at
FROM jobs
ORDER BY created_at DESC
LIMIT ?2 OFFSET ?1
` `
type ListJobsParams struct { type ListJobsParams struct {
@ -248,7 +289,10 @@ type ListJobsParams struct {
// ListJobs // ListJobs
// //
// SELECT id, kind, status, run_at, attempts, max_attempts, locked_at, locked_by, payload_json, dedupe_key, last_error, created_at, updated_at, completed_at FROM jobs ORDER BY created_at DESC LIMIT ?2 OFFSET ?1 // SELECT id, kind, status, run_at, attempts, max_attempts, locked_at, locked_by, payload_json, dedupe_key, last_error, created_at, updated_at, completed_at
// FROM jobs
// ORDER BY created_at DESC
// LIMIT ?2 OFFSET ?1
func (q *Queries) ListJobs(ctx context.Context, arg ListJobsParams) ([]Job, error) { func (q *Queries) ListJobs(ctx context.Context, arg ListJobsParams) ([]Job, error) {
rows, err := q.db.QueryContext(ctx, ListJobs, arg.Off, arg.Lim) rows, err := q.db.QueryContext(ctx, ListJobs, arg.Off, arg.Lim)
if err != nil { if err != nil {
@ -381,7 +425,10 @@ func (q *Queries) MarkJobSucceeded(ctx context.Context, arg MarkJobSucceededPara
const RequeueJob = `-- name: RequeueJob :one const RequeueJob = `-- name: RequeueJob :one
UPDATE jobs UPDATE jobs
SET status = 'queued', SET status = 'queued',
run_at = coalesce(?1, strftime('%Y-%m-%dT%H:%M:%fZ', 'now')), run_at = coalesce(
?1,
strftime('%Y-%m-%dT%H:%M:%fZ', 'now')
),
updated_at = strftime('%Y-%m-%dT%H:%M:%fZ', 'now'), updated_at = strftime('%Y-%m-%dT%H:%M:%fZ', 'now'),
last_error = ?2, last_error = ?2,
locked_at = NULL, locked_at = NULL,
@ -401,7 +448,10 @@ type RequeueJobParams struct {
// //
// UPDATE jobs // UPDATE jobs
// SET status = 'queued', // SET status = 'queued',
// run_at = coalesce(?1, strftime('%Y-%m-%dT%H:%M:%fZ', 'now')), // run_at = coalesce(
// ?1,
// strftime('%Y-%m-%dT%H:%M:%fZ', 'now')
// ),
// updated_at = strftime('%Y-%m-%dT%H:%M:%fZ', 'now'), // updated_at = strftime('%Y-%m-%dT%H:%M:%fZ', 'now'),
// last_error = ?2, // last_error = ?2,
// locked_at = NULL, // locked_at = NULL,

View file

@ -14,21 +14,38 @@ type Querier interface {
//AddAgentMention //AddAgentMention
// //
// INSERT INTO agent_mentions ( // INSERT INTO agent_mentions (
// id, conversation_id, message_id, kind, target_id, raw, metadata_json // id,
// conversation_id,
// message_id,
// kind,
// target_id,
// raw,
// metadata_json
// ) // )
// VALUES (?, ?, ?, ?, ?, ?, ?) // VALUES (?, ?, ?, ?, ?, ?, ?)
// RETURNING id, conversation_id, message_id, kind, target_id, raw, metadata_json, created_at, updated_at // RETURNING id, conversation_id, message_id, kind, target_id, raw, metadata_json, created_at, updated_at
AddAgentMention(ctx context.Context, arg AddAgentMentionParams) (AgentMention, error) AddAgentMention(ctx context.Context, arg AddAgentMentionParams) (AgentMention, error)
//AddAgentMessage //AddAgentMessage
// //
// INSERT INTO agent_messages (id, conversation_id, role, content, metadata_json) // INSERT INTO agent_messages (
// id,
// conversation_id,
// role,
// content,
// metadata_json
// )
// VALUES (?, ?, ?, ?, ?) // VALUES (?, ?, ?, ?, ?)
// RETURNING id, conversation_id, role, content, metadata_json, created_at, updated_at // RETURNING id, conversation_id, role, content, metadata_json, created_at, updated_at
AddAgentMessage(ctx context.Context, arg AddAgentMessageParams) (AgentMessage, error) AddAgentMessage(ctx context.Context, arg AddAgentMessageParams) (AgentMessage, error)
//AddAgentMessageRevision //AddAgentMessageRevision
// //
// INSERT INTO agent_message_revisions ( // INSERT INTO agent_message_revisions (
// id, message_id, editor, old_content, new_content, metadata_json // id,
// message_id,
// editor,
// old_content,
// new_content,
// metadata_json
// ) // )
// VALUES (?, ?, ?, ?, ?, ?) // VALUES (?, ?, ?, ?, ?, ?)
// RETURNING id, message_id, editor, old_content, new_content, metadata_json, created_at, updated_at // RETURNING id, message_id, editor, old_content, new_content, metadata_json, created_at, updated_at
@ -42,7 +59,15 @@ type Querier interface {
//AddAgentStateTransition //AddAgentStateTransition
// //
// INSERT INTO agent_state_transitions ( // INSERT INTO agent_state_transitions (
// id, run_id, step_index, from_state, to_state, trigger, at, meta_json, error // id,
// run_id,
// step_index,
// from_state,
// to_state,
// trigger,
// at,
// meta_json,
// error
// ) // )
// VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?) // VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
// RETURNING id, run_id, step_index, from_state, to_state, "trigger", at, meta_json, error, created_at, updated_at // RETURNING id, run_id, step_index, from_state, to_state, "trigger", at, meta_json, error, created_at, updated_at
@ -56,8 +81,16 @@ type Querier interface {
//AddAgentToolResult //AddAgentToolResult
// //
// INSERT INTO agent_tool_results ( // INSERT INTO agent_tool_results (
// id, conversation_id, run_id, step_index, // id,
// tool_call_id, tool_name, full_key, preview, chunk_count, metadata_json // conversation_id,
// run_id,
// step_index,
// tool_call_id,
// tool_name,
// full_key,
// preview,
// chunk_count,
// metadata_json
// ) // )
// VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?) // VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
// RETURNING id, conversation_id, run_id, step_index, tool_call_id, tool_name, full_key, preview, chunk_count, metadata_json, created_at, updated_at // RETURNING id, conversation_id, run_id, step_index, tool_call_id, tool_name, full_key, preview, chunk_count, metadata_json, created_at, updated_at
@ -71,7 +104,8 @@ type Querier interface {
// locked_by = ?1, // locked_by = ?1,
// updated_at = strftime('%Y-%m-%dT%H:%M:%fZ', 'now'), // updated_at = strftime('%Y-%m-%dT%H:%M:%fZ', 'now'),
// last_error = NULL // last_error = NULL
// WHERE id = ?2 AND status = 'queued' // WHERE id = ?2
// AND status = 'queued'
// RETURNING id, kind, status, run_at, attempts, max_attempts, locked_at, locked_by, payload_json, dedupe_key, last_error, created_at, updated_at, completed_at // RETURNING id, kind, status, run_at, attempts, max_attempts, locked_at, locked_by, payload_json, dedupe_key, last_error, created_at, updated_at, completed_at
ClaimJobByID(ctx context.Context, arg ClaimJobByIDParams) (Job, error) ClaimJobByID(ctx context.Context, arg ClaimJobByIDParams) (Job, error)
//CountArchivalChunks //CountArchivalChunks
@ -96,7 +130,10 @@ type Querier interface {
CountAuditEntriesByAction(ctx context.Context, arg CountAuditEntriesByActionParams) (int64, error) CountAuditEntriesByAction(ctx context.Context, arg CountAuditEntriesByActionParams) (int64, error)
//CountJobsByStatus //CountJobsByStatus
// //
// SELECT status, count(*) AS count FROM jobs GROUP BY status // SELECT status,
// count(*) AS count
// FROM jobs
// GROUP BY status
CountJobsByStatus(ctx context.Context) ([]CountJobsByStatusRow, error) CountJobsByStatus(ctx context.Context) ([]CountJobsByStatusRow, error)
//CountRecallItems //CountRecallItems
// //
@ -118,7 +155,13 @@ type Querier interface {
CountSessionMessages(ctx context.Context, arg CountSessionMessagesParams) (int64, error) CountSessionMessages(ctx context.Context, arg CountSessionMessagesParams) (int64, error)
//CreateAgentCheckpoint //CreateAgentCheckpoint
// //
// INSERT INTO agent_checkpoints (id, conversation_id, name, run_state_id, metadata_json) // INSERT INTO agent_checkpoints (
// id,
// conversation_id,
// name,
// run_state_id,
// metadata_json
// )
// VALUES (?, ?, ?, ?, ?) // VALUES (?, ?, ?, ?, ?)
// RETURNING id, conversation_id, name, run_state_id, metadata_json, created_at, updated_at // RETURNING id, conversation_id, name, run_state_id, metadata_json, created_at, updated_at
CreateAgentCheckpoint(ctx context.Context, arg CreateAgentCheckpointParams) (AgentCheckpoint, error) CreateAgentCheckpoint(ctx context.Context, arg CreateAgentCheckpointParams) (AgentCheckpoint, error)
@ -131,7 +174,11 @@ type Querier interface {
//CreateAgentConversationFork //CreateAgentConversationFork
// //
// INSERT INTO agent_conversation_forks ( // INSERT INTO agent_conversation_forks (
// id, parent_conversation_id, child_conversation_id, checkpoint_id, metadata_json // id,
// parent_conversation_id,
// child_conversation_id,
// checkpoint_id,
// metadata_json
// ) // )
// VALUES (?, ?, ?, ?, ?) // VALUES (?, ?, ?, ?, ?)
// RETURNING id, parent_conversation_id, child_conversation_id, checkpoint_id, metadata_json, created_at, updated_at // RETURNING id, parent_conversation_id, child_conversation_id, checkpoint_id, metadata_json, created_at, updated_at
@ -139,7 +186,11 @@ type Querier interface {
//CreateAgentConversationLink //CreateAgentConversationLink
// //
// INSERT INTO agent_conversation_links ( // INSERT INTO agent_conversation_links (
// id, conversation_id, linked_conversation_id, kind, metadata_json // id,
// conversation_id,
// linked_conversation_id,
// kind,
// metadata_json
// ) // )
// VALUES (?, ?, ?, ?, ?) // VALUES (?, ?, ?, ?, ?)
// RETURNING id, conversation_id, linked_conversation_id, kind, metadata_json, created_at, updated_at // RETURNING id, conversation_id, linked_conversation_id, kind, metadata_json, created_at, updated_at
@ -159,7 +210,9 @@ type Querier interface {
//DeleteAgentConversationLink //DeleteAgentConversationLink
// //
// DELETE FROM agent_conversation_links // DELETE FROM agent_conversation_links
// WHERE conversation_id = ? AND linked_conversation_id = ? AND kind = ? // WHERE conversation_id = ?
// AND linked_conversation_id = ?
// AND kind = ?
DeleteAgentConversationLink(ctx context.Context, arg DeleteAgentConversationLinkParams) error DeleteAgentConversationLink(ctx context.Context, arg DeleteAgentConversationLinkParams) error
//DeleteArchivalChunksByRecall //DeleteArchivalChunksByRecall
// //
@ -187,18 +240,28 @@ type Querier interface {
//EnqueueJob //EnqueueJob
// //
// INSERT INTO jobs ( // INSERT INTO jobs (
// id, kind, status, run_at, max_attempts, payload_json, dedupe_key // id,
// kind,
// status,
// run_at,
// max_attempts,
// payload_json,
// dedupe_key
// ) // )
// VALUES ( // VALUES (
// ?1, // ?1,
// ?2, // ?2,
// 'queued', // 'queued',
// coalesce(?3, strftime('%Y-%m-%dT%H:%M:%fZ', 'now')), // coalesce(
// ?3,
// strftime('%Y-%m-%dT%H:%M:%fZ', 'now')
// ),
// coalesce(?4, 3), // coalesce(?4, 3),
// coalesce(?5, '{}'), // coalesce(?5, '{}'),
// ?6 // ?6
// ) ON CONFLICT(kind, dedupe_key) // ) ON CONFLICT(kind, dedupe_key)
// WHERE dedupe_key IS NOT NULL DO UPDATE // WHERE dedupe_key IS NOT NULL DO
// UPDATE
// SET status = 'queued', // SET status = 'queued',
// run_at = excluded.run_at, // run_at = excluded.run_at,
// max_attempts = excluded.max_attempts, // max_attempts = excluded.max_attempts,
@ -210,38 +273,49 @@ type Querier interface {
EnqueueJob(ctx context.Context, arg EnqueueJobParams) (Job, error) EnqueueJob(ctx context.Context, arg EnqueueJobParams) (Job, error)
//FindNextRunnableJob //FindNextRunnableJob
// //
// SELECT id FROM jobs // SELECT id
// FROM jobs
// WHERE status = 'queued' // WHERE status = 'queued'
// AND run_at <= strftime('%Y-%m-%dT%H:%M:%fZ', 'now') // AND run_at <= strftime('%Y-%m-%dT%H:%M:%fZ', 'now')
// ORDER BY run_at ASC, created_at ASC // ORDER BY run_at ASC,
// created_at ASC
// LIMIT 1 // LIMIT 1
FindNextRunnableJob(ctx context.Context) (ids.UUID, error) FindNextRunnableJob(ctx context.Context) (ids.UUID, error)
//GetAgentCheckpointByConversationIDAndName //GetAgentCheckpointByConversationIDAndName
// //
// SELECT id, conversation_id, name, run_state_id, metadata_json, created_at, updated_at FROM agent_checkpoints // SELECT id, conversation_id, name, run_state_id, metadata_json, created_at, updated_at
// WHERE conversation_id = ? AND name = ? // FROM agent_checkpoints
// WHERE conversation_id = ?
// AND name = ?
// LIMIT 1 // LIMIT 1
GetAgentCheckpointByConversationIDAndName(ctx context.Context, arg GetAgentCheckpointByConversationIDAndNameParams) (AgentCheckpoint, error) GetAgentCheckpointByConversationIDAndName(ctx context.Context, arg GetAgentCheckpointByConversationIDAndNameParams) (AgentCheckpoint, error)
//GetAgentConversation //GetAgentConversation
// //
// SELECT id, title, created_at, updated_at FROM agent_conversations WHERE id = ? LIMIT 1 // SELECT id, title, created_at, updated_at
// FROM agent_conversations
// WHERE id = ?
// LIMIT 1
GetAgentConversation(ctx context.Context, arg GetAgentConversationParams) (AgentConversation, error) GetAgentConversation(ctx context.Context, arg GetAgentConversationParams) (AgentConversation, error)
//GetAgentConversationForkByChildConversationID //GetAgentConversationForkByChildConversationID
// //
// SELECT id, parent_conversation_id, child_conversation_id, checkpoint_id, metadata_json, created_at, updated_at FROM agent_conversation_forks // SELECT id, parent_conversation_id, child_conversation_id, checkpoint_id, metadata_json, created_at, updated_at
// FROM agent_conversation_forks
// WHERE child_conversation_id = ? // WHERE child_conversation_id = ?
// LIMIT 1 // LIMIT 1
GetAgentConversationForkByChildConversationID(ctx context.Context, arg GetAgentConversationForkByChildConversationIDParams) (AgentConversationFork, error) GetAgentConversationForkByChildConversationID(ctx context.Context, arg GetAgentConversationForkByChildConversationIDParams) (AgentConversationFork, error)
//GetAgentRunStateByID //GetAgentRunStateByID
// //
// SELECT id, run_id, step_index, state, snapshot_json, created_at, updated_at FROM agent_run_states // SELECT id, run_id, step_index, state, snapshot_json, created_at, updated_at
// FROM agent_run_states
// WHERE id = ? // WHERE id = ?
// LIMIT 1 // LIMIT 1
GetAgentRunStateByID(ctx context.Context, arg GetAgentRunStateByIDParams) (AgentRunState, error) GetAgentRunStateByID(ctx context.Context, arg GetAgentRunStateByIDParams) (AgentRunState, error)
//GetAgentToolResultByRunIDAndToolCallID //GetAgentToolResultByRunIDAndToolCallID
// //
// SELECT id, conversation_id, run_id, step_index, tool_call_id, tool_name, full_key, preview, chunk_count, metadata_json, created_at, updated_at FROM agent_tool_results // SELECT id, conversation_id, run_id, step_index, tool_call_id, tool_name, full_key, preview, chunk_count, metadata_json, created_at, updated_at
// WHERE run_id = ? AND tool_call_id = ? // FROM agent_tool_results
// WHERE run_id = ?
// AND tool_call_id = ?
// LIMIT 1 // LIMIT 1
GetAgentToolResultByRunIDAndToolCallID(ctx context.Context, arg GetAgentToolResultByRunIDAndToolCallIDParams) (AgentToolResult, error) GetAgentToolResultByRunIDAndToolCallID(ctx context.Context, arg GetAgentToolResultByRunIDAndToolCallIDParams) (AgentToolResult, error)
//GetArchivalChunk //GetArchivalChunk
@ -293,7 +367,10 @@ type Querier interface {
GetDocument(ctx context.Context, arg GetDocumentParams) (AgentDocument, error) GetDocument(ctx context.Context, arg GetDocumentParams) (AgentDocument, error)
//GetJob //GetJob
// //
// SELECT id, kind, status, run_at, attempts, max_attempts, locked_at, locked_by, payload_json, dedupe_key, last_error, created_at, updated_at, completed_at FROM jobs WHERE id = ?1 LIMIT 1 // SELECT id, kind, status, run_at, attempts, max_attempts, locked_at, locked_by, payload_json, dedupe_key, last_error, created_at, updated_at, completed_at
// FROM jobs
// WHERE id = ?1
// LIMIT 1
GetJob(ctx context.Context, arg GetJobParams) (Job, error) GetJob(ctx context.Context, arg GetJobParams) (Job, error)
// Agent KV Store queries // Agent KV Store queries
// //
@ -308,14 +385,16 @@ type Querier interface {
GetKV(ctx context.Context, arg GetKVParams) (AgentKv, error) GetKV(ctx context.Context, arg GetKVParams) (AgentKv, error)
//GetLatestAgentRunByConversationID //GetLatestAgentRunByConversationID
// //
// SELECT id, conversation_id, status, metadata_json, created_at, updated_at FROM agent_runs // SELECT id, conversation_id, status, metadata_json, created_at, updated_at
// FROM agent_runs
// WHERE conversation_id = ? // WHERE conversation_id = ?
// ORDER BY created_at DESC // ORDER BY created_at DESC
// LIMIT 1 // LIMIT 1
GetLatestAgentRunByConversationID(ctx context.Context, arg GetLatestAgentRunByConversationIDParams) (AgentRun, error) GetLatestAgentRunByConversationID(ctx context.Context, arg GetLatestAgentRunByConversationIDParams) (AgentRun, error)
//GetLatestAgentRunStateByRunID //GetLatestAgentRunStateByRunID
// //
// SELECT id, run_id, step_index, state, snapshot_json, created_at, updated_at FROM agent_run_states // SELECT id, run_id, step_index, state, snapshot_json, created_at, updated_at
// FROM agent_run_states
// WHERE run_id = ? // WHERE run_id = ?
// ORDER BY step_index DESC // ORDER BY step_index DESC
// LIMIT 1 // LIMIT 1
@ -390,7 +469,8 @@ type Querier interface {
// ?7, // ?7,
// datetime('now') // datetime('now')
// ) // )
InsertArchivalChunk(ctx context.Context, arg InsertArchivalChunkParams) error // RETURNING id, recall_id, chunk_index, content, embedding, source, hash, created_at
InsertArchivalChunk(ctx context.Context, arg InsertArchivalChunkParams) (ArchivalChunk, error)
// Agent Audit Log queries // Agent Audit Log queries
// //
// INSERT INTO agent_audit_log ( // INSERT INTO agent_audit_log (
@ -415,7 +495,8 @@ type Querier interface {
// ?8, // ?8,
// datetime('now') // datetime('now')
// ) // )
InsertAuditEntry(ctx context.Context, arg InsertAuditEntryParams) error // RETURNING id, agent_id, session_key, action, target, input, output, duration_ms, created_at
InsertAuditEntry(ctx context.Context, arg InsertAuditEntryParams) (AgentAuditLog, error)
// Recall Item queries // Recall Item queries
// //
// INSERT INTO recall_items ( // INSERT INTO recall_items (
@ -446,7 +527,8 @@ type Querier interface {
// datetime('now'), // datetime('now'),
// datetime('now') // datetime('now')
// ) // )
InsertRecallItem(ctx context.Context, arg InsertRecallItemParams) error // RETURNING id, agent_id, session_key, role, sector, importance, salience, decay_rate, content, tags, created_at, updated_at
InsertRecallItem(ctx context.Context, arg InsertRecallItemParams) (RecallItem, error)
//InsertSessionMessage //InsertSessionMessage
// //
// INSERT INTO recall_items ( // INSERT INTO recall_items (
@ -477,7 +559,8 @@ type Querier interface {
// datetime('now'), // datetime('now'),
// datetime('now') // datetime('now')
// ) // )
InsertSessionMessage(ctx context.Context, arg InsertSessionMessageParams) error // RETURNING id, agent_id, session_key, role, sector, importance, salience, decay_rate, content, tags, created_at, updated_at
InsertSessionMessage(ctx context.Context, arg InsertSessionMessageParams) (RecallItem, error)
// Memory Summary queries // Memory Summary queries
// //
// INSERT INTO memory_summaries ( // INSERT INTO memory_summaries (
@ -498,111 +581,131 @@ type Querier interface {
// ?6, // ?6,
// datetime('now') // datetime('now')
// ) // )
InsertSummary(ctx context.Context, arg InsertSummaryParams) error // RETURNING id, agent_id, session_key, content, from_msg_idx, to_msg_idx, created_at
InsertSummary(ctx context.Context, arg InsertSummaryParams) (MemorySummary, error)
//ListAgentCheckpointsByConversationID //ListAgentCheckpointsByConversationID
// //
// SELECT id, conversation_id, name, run_state_id, metadata_json, created_at, updated_at FROM agent_checkpoints // SELECT id, conversation_id, name, run_state_id, metadata_json, created_at, updated_at
// FROM agent_checkpoints
// WHERE conversation_id = ? // WHERE conversation_id = ?
// ORDER BY created_at DESC // ORDER BY created_at DESC
// LIMIT ?2 // LIMIT ?2
ListAgentCheckpointsByConversationID(ctx context.Context, arg ListAgentCheckpointsByConversationIDParams) ([]AgentCheckpoint, error) ListAgentCheckpointsByConversationID(ctx context.Context, arg ListAgentCheckpointsByConversationIDParams) ([]AgentCheckpoint, error)
//ListAgentConversationForksByParentConversationID //ListAgentConversationForksByParentConversationID
// //
// SELECT id, parent_conversation_id, child_conversation_id, checkpoint_id, metadata_json, created_at, updated_at FROM agent_conversation_forks // SELECT id, parent_conversation_id, child_conversation_id, checkpoint_id, metadata_json, created_at, updated_at
// FROM agent_conversation_forks
// WHERE parent_conversation_id = ? // WHERE parent_conversation_id = ?
// ORDER BY created_at DESC // ORDER BY created_at DESC
// LIMIT ?2 // LIMIT ?2
ListAgentConversationForksByParentConversationID(ctx context.Context, arg ListAgentConversationForksByParentConversationIDParams) ([]AgentConversationFork, error) ListAgentConversationForksByParentConversationID(ctx context.Context, arg ListAgentConversationForksByParentConversationIDParams) ([]AgentConversationFork, error)
//ListAgentConversationLinksByConversationID //ListAgentConversationLinksByConversationID
// //
// SELECT id, conversation_id, linked_conversation_id, kind, metadata_json, created_at, updated_at FROM agent_conversation_links // SELECT id, conversation_id, linked_conversation_id, kind, metadata_json, created_at, updated_at
// FROM agent_conversation_links
// WHERE conversation_id = ? // WHERE conversation_id = ?
// ORDER BY created_at DESC // ORDER BY created_at DESC
// LIMIT ?2 // LIMIT ?2
ListAgentConversationLinksByConversationID(ctx context.Context, arg ListAgentConversationLinksByConversationIDParams) ([]AgentConversationLink, error) ListAgentConversationLinksByConversationID(ctx context.Context, arg ListAgentConversationLinksByConversationIDParams) ([]AgentConversationLink, error)
//ListAgentConversations //ListAgentConversations
// //
// SELECT id, title, created_at, updated_at FROM agent_conversations ORDER BY created_at DESC LIMIT ? // SELECT id, title, created_at, updated_at
// FROM agent_conversations
// ORDER BY created_at DESC
// LIMIT ?
ListAgentConversations(ctx context.Context, arg ListAgentConversationsParams) ([]AgentConversation, error) ListAgentConversations(ctx context.Context, arg ListAgentConversationsParams) ([]AgentConversation, error)
//ListAgentMentionsByConversationID //ListAgentMentionsByConversationID
// //
// SELECT id, conversation_id, message_id, kind, target_id, raw, metadata_json, created_at, updated_at FROM agent_mentions // SELECT id, conversation_id, message_id, kind, target_id, raw, metadata_json, created_at, updated_at
// FROM agent_mentions
// WHERE conversation_id = ? // WHERE conversation_id = ?
// ORDER BY created_at DESC // ORDER BY created_at DESC
// LIMIT ?2 // LIMIT ?2
ListAgentMentionsByConversationID(ctx context.Context, arg ListAgentMentionsByConversationIDParams) ([]AgentMention, error) ListAgentMentionsByConversationID(ctx context.Context, arg ListAgentMentionsByConversationIDParams) ([]AgentMention, error)
//ListAgentMessageRevisionsByMessageID //ListAgentMessageRevisionsByMessageID
// //
// SELECT id, message_id, editor, old_content, new_content, metadata_json, created_at, updated_at FROM agent_message_revisions // SELECT id, message_id, editor, old_content, new_content, metadata_json, created_at, updated_at
// FROM agent_message_revisions
// WHERE message_id = ? // WHERE message_id = ?
// ORDER BY created_at DESC // ORDER BY created_at DESC
// LIMIT ?2 // LIMIT ?2
ListAgentMessageRevisionsByMessageID(ctx context.Context, arg ListAgentMessageRevisionsByMessageIDParams) ([]AgentMessageRevision, error) ListAgentMessageRevisionsByMessageID(ctx context.Context, arg ListAgentMessageRevisionsByMessageIDParams) ([]AgentMessageRevision, error)
//ListAgentMessagesByConversationID //ListAgentMessagesByConversationID
// //
// SELECT id, conversation_id, role, content, metadata_json, created_at, updated_at FROM agent_messages // SELECT id, conversation_id, role, content, metadata_json, created_at, updated_at
// FROM agent_messages
// WHERE conversation_id = ? // WHERE conversation_id = ?
// ORDER BY created_at ASC // ORDER BY created_at ASC
ListAgentMessagesByConversationID(ctx context.Context, arg ListAgentMessagesByConversationIDParams) ([]AgentMessage, error) ListAgentMessagesByConversationID(ctx context.Context, arg ListAgentMessagesByConversationIDParams) ([]AgentMessage, error)
//ListAgentMessagesByConversationIDLimit //ListAgentMessagesByConversationIDLimit
// //
// SELECT id, conversation_id, role, content, metadata_json, created_at, updated_at FROM agent_messages // SELECT id, conversation_id, role, content, metadata_json, created_at, updated_at
// FROM agent_messages
// WHERE conversation_id = ? // WHERE conversation_id = ?
// ORDER BY created_at ASC // ORDER BY created_at ASC
// LIMIT ? // LIMIT ?
ListAgentMessagesByConversationIDLimit(ctx context.Context, arg ListAgentMessagesByConversationIDLimitParams) ([]AgentMessage, error) ListAgentMessagesByConversationIDLimit(ctx context.Context, arg ListAgentMessagesByConversationIDLimitParams) ([]AgentMessage, error)
//ListAgentRunStatesByRunID //ListAgentRunStatesByRunID
// //
// SELECT id, run_id, step_index, state, snapshot_json, created_at, updated_at FROM agent_run_states // SELECT id, run_id, step_index, state, snapshot_json, created_at, updated_at
// FROM agent_run_states
// WHERE run_id = ? // WHERE run_id = ?
// ORDER BY step_index ASC // ORDER BY step_index ASC
// LIMIT ?2 // LIMIT ?2
ListAgentRunStatesByRunID(ctx context.Context, arg ListAgentRunStatesByRunIDParams) ([]AgentRunState, error) ListAgentRunStatesByRunID(ctx context.Context, arg ListAgentRunStatesByRunIDParams) ([]AgentRunState, error)
//ListAgentStateTransitionsByRunID //ListAgentStateTransitionsByRunID
// //
// SELECT id, run_id, step_index, from_state, to_state, "trigger", at, meta_json, error, created_at, updated_at FROM agent_state_transitions // SELECT id, run_id, step_index, from_state, to_state, "trigger", at, meta_json, error, created_at, updated_at
// FROM agent_state_transitions
// WHERE run_id = ? // WHERE run_id = ?
// ORDER BY at ASC // ORDER BY at ASC
// LIMIT ?2 // LIMIT ?2
ListAgentStateTransitionsByRunID(ctx context.Context, arg ListAgentStateTransitionsByRunIDParams) ([]AgentStateTransition, error) ListAgentStateTransitionsByRunID(ctx context.Context, arg ListAgentStateTransitionsByRunIDParams) ([]AgentStateTransition, error)
//ListAgentThreadMessagesByThreadID //ListAgentThreadMessagesByThreadID
// //
// SELECT id, thread_id, role, content, metadata_json, created_at, updated_at FROM agent_thread_messages // SELECT id, thread_id, role, content, metadata_json, created_at, updated_at
// FROM agent_thread_messages
// WHERE thread_id = ? // WHERE thread_id = ?
// ORDER BY created_at ASC // ORDER BY created_at ASC
ListAgentThreadMessagesByThreadID(ctx context.Context, arg ListAgentThreadMessagesByThreadIDParams) ([]AgentThreadMessage, error) ListAgentThreadMessagesByThreadID(ctx context.Context, arg ListAgentThreadMessagesByThreadIDParams) ([]AgentThreadMessage, error)
//ListAgentThreadMessagesByThreadIDDescLimit //ListAgentThreadMessagesByThreadIDDescLimit
// //
// SELECT id, thread_id, role, content, metadata_json, created_at, updated_at FROM agent_thread_messages // SELECT id, thread_id, role, content, metadata_json, created_at, updated_at
// FROM agent_thread_messages
// WHERE thread_id = ? // WHERE thread_id = ?
// ORDER BY created_at DESC // ORDER BY created_at DESC
// LIMIT ? // LIMIT ?
ListAgentThreadMessagesByThreadIDDescLimit(ctx context.Context, arg ListAgentThreadMessagesByThreadIDDescLimitParams) ([]AgentThreadMessage, error) ListAgentThreadMessagesByThreadIDDescLimit(ctx context.Context, arg ListAgentThreadMessagesByThreadIDDescLimitParams) ([]AgentThreadMessage, error)
//ListAgentThreadsByConversationID //ListAgentThreadsByConversationID
// //
// SELECT id, conversation_id, title, metadata_json, created_at, updated_at FROM agent_threads // SELECT id, conversation_id, title, metadata_json, created_at, updated_at
// FROM agent_threads
// WHERE conversation_id = ? // WHERE conversation_id = ?
// ORDER BY created_at DESC // ORDER BY created_at DESC
// LIMIT ?2 // LIMIT ?2
ListAgentThreadsByConversationID(ctx context.Context, arg ListAgentThreadsByConversationIDParams) ([]AgentThread, error) ListAgentThreadsByConversationID(ctx context.Context, arg ListAgentThreadsByConversationIDParams) ([]AgentThread, error)
//ListAgentToolResultsByConversationID //ListAgentToolResultsByConversationID
// //
// SELECT id, conversation_id, run_id, step_index, tool_call_id, tool_name, full_key, preview, chunk_count, metadata_json, created_at, updated_at FROM agent_tool_results // SELECT id, conversation_id, run_id, step_index, tool_call_id, tool_name, full_key, preview, chunk_count, metadata_json, created_at, updated_at
// FROM agent_tool_results
// WHERE conversation_id = ? // WHERE conversation_id = ?
// ORDER BY created_at DESC // ORDER BY created_at DESC
ListAgentToolResultsByConversationID(ctx context.Context, arg ListAgentToolResultsByConversationIDParams) ([]AgentToolResult, error) ListAgentToolResultsByConversationID(ctx context.Context, arg ListAgentToolResultsByConversationIDParams) ([]AgentToolResult, error)
//ListAgentToolResultsByConversationIDLimit //ListAgentToolResultsByConversationIDLimit
// //
// SELECT id, conversation_id, run_id, step_index, tool_call_id, tool_name, full_key, preview, chunk_count, metadata_json, created_at, updated_at FROM agent_tool_results // SELECT id, conversation_id, run_id, step_index, tool_call_id, tool_name, full_key, preview, chunk_count, metadata_json, created_at, updated_at
// FROM agent_tool_results
// WHERE conversation_id = ? // WHERE conversation_id = ?
// ORDER BY created_at DESC // ORDER BY created_at DESC
// LIMIT ? // LIMIT ?
ListAgentToolResultsByConversationIDLimit(ctx context.Context, arg ListAgentToolResultsByConversationIDLimitParams) ([]AgentToolResult, error) ListAgentToolResultsByConversationIDLimit(ctx context.Context, arg ListAgentToolResultsByConversationIDLimitParams) ([]AgentToolResult, error)
//ListAgentToolResultsByRunID //ListAgentToolResultsByRunID
// //
// SELECT id, conversation_id, run_id, step_index, tool_call_id, tool_name, full_key, preview, chunk_count, metadata_json, created_at, updated_at FROM agent_tool_results // SELECT id, conversation_id, run_id, step_index, tool_call_id, tool_name, full_key, preview, chunk_count, metadata_json, created_at, updated_at
// FROM agent_tool_results
// WHERE run_id = ? // WHERE run_id = ?
// ORDER BY step_index ASC, created_at ASC // ORDER BY step_index ASC,
// created_at ASC
// LIMIT ?2 // LIMIT ?2
ListAgentToolResultsByRunID(ctx context.Context, arg ListAgentToolResultsByRunIDParams) ([]AgentToolResult, error) ListAgentToolResultsByRunID(ctx context.Context, arg ListAgentToolResultsByRunIDParams) ([]AgentToolResult, error)
//ListAllArchivalChunks //ListAllArchivalChunks
@ -726,7 +829,10 @@ type Querier interface {
ListDocumentsByCategory(ctx context.Context, arg ListDocumentsByCategoryParams) ([]AgentDocument, error) ListDocumentsByCategory(ctx context.Context, arg ListDocumentsByCategoryParams) ([]AgentDocument, error)
//ListJobs //ListJobs
// //
// SELECT id, kind, status, run_at, attempts, max_attempts, locked_at, locked_by, payload_json, dedupe_key, last_error, created_at, updated_at, completed_at FROM jobs ORDER BY created_at DESC LIMIT ?2 OFFSET ?1 // SELECT id, kind, status, run_at, attempts, max_attempts, locked_at, locked_by, payload_json, dedupe_key, last_error, created_at, updated_at, completed_at
// FROM jobs
// ORDER BY created_at DESC
// LIMIT ?2 OFFSET ?1
ListJobs(ctx context.Context, arg ListJobsParams) ([]Job, error) ListJobs(ctx context.Context, arg ListJobsParams) ([]Job, error)
//ListKVByPrefix //ListKVByPrefix
// //
@ -836,7 +942,10 @@ type Querier interface {
// //
// UPDATE jobs // UPDATE jobs
// SET status = 'queued', // SET status = 'queued',
// run_at = coalesce(?1, strftime('%Y-%m-%dT%H:%M:%fZ', 'now')), // run_at = coalesce(
// ?1,
// strftime('%Y-%m-%dT%H:%M:%fZ', 'now')
// ),
// updated_at = strftime('%Y-%m-%dT%H:%M:%fZ', 'now'), // updated_at = strftime('%Y-%m-%dT%H:%M:%fZ', 'now'),
// last_error = ?2, // last_error = ?2,
// locked_at = NULL, // locked_at = NULL,
@ -926,7 +1035,8 @@ type Querier interface {
// version = agent_documents.version + 1, // version = agent_documents.version + 1,
// is_active = 1, // is_active = 1,
// updated_at = datetime('now') // updated_at = datetime('now')
UpsertDocument(ctx context.Context, arg UpsertDocumentParams) error // RETURNING id, agent_id, name, category, content, version, is_active, created_at, updated_at
UpsertDocument(ctx context.Context, arg UpsertDocumentParams) (AgentDocument, error)
//UpsertKV //UpsertKV
// //
// INSERT INTO agent_kv (agent_id, key, value, updated_at) // INSERT INTO agent_kv (agent_id, key, value, updated_at)
@ -939,7 +1049,8 @@ type Querier interface {
// UPDATE // UPDATE
// SET value = excluded.value, // SET value = excluded.value,
// updated_at = excluded.updated_at // updated_at = excluded.updated_at
UpsertKV(ctx context.Context, arg UpsertKVParams) error // RETURNING agent_id, key, value, updated_at
UpsertKV(ctx context.Context, arg UpsertKVParams) (AgentKv, error)
//UpsertWorkingContext //UpsertWorkingContext
// //
// INSERT INTO working_context (agent_id, session_key, content, updated_at) // INSERT INTO working_context (agent_id, session_key, content, updated_at)
@ -952,7 +1063,8 @@ type Querier interface {
// UPDATE // UPDATE
// SET content = excluded.content, // SET content = excluded.content,
// updated_at = excluded.updated_at // updated_at = excluded.updated_at
UpsertWorkingContext(ctx context.Context, arg UpsertWorkingContextParams) error // RETURNING agent_id, session_key, content, updated_at
UpsertWorkingContext(ctx context.Context, arg UpsertWorkingContextParams) (WorkingContext, error)
} }
var _ Querier = (*Queries)(nil) var _ Querier = (*Queries)(nil)

View file

@ -1,5 +1,5 @@
-- Agent Audit Log queries -- Agent Audit Log queries
-- name: InsertAuditEntry :exec -- name: InsertAuditEntry :one
INSERT INTO agent_audit_log ( INSERT INTO agent_audit_log (
id, id,
agent_id, agent_id,
@ -21,7 +21,8 @@ VALUES (
sqlc.arg(output), sqlc.arg(output),
sqlc.arg(duration_ms), sqlc.arg(duration_ms),
datetime('now') datetime('now')
); )
RETURNING id, agent_id, session_key, action, target, input, output, duration_ms, created_at;
-- name: ListAuditEntries :many -- name: ListAuditEntries :many
SELECT id, SELECT id,
agent_id, agent_id,

View file

@ -13,7 +13,7 @@ FROM agent_documents
WHERE agent_id = sqlc.arg(agent_id) WHERE agent_id = sqlc.arg(agent_id)
AND name = sqlc.arg(name) AND name = sqlc.arg(name)
LIMIT 1; LIMIT 1;
-- name: UpsertDocument :exec -- name: UpsertDocument :one
INSERT INTO agent_documents ( INSERT INTO agent_documents (
id, id,
agent_id, agent_id,
@ -41,7 +41,8 @@ SET content = excluded.content,
category = excluded.category, category = excluded.category,
version = agent_documents.version + 1, version = agent_documents.version + 1,
is_active = 1, is_active = 1,
updated_at = datetime('now'); updated_at = datetime('now')
RETURNING id, agent_id, name, category, content, version, is_active, created_at, updated_at;
-- name: ListDocumentsByCategory :many -- name: ListDocumentsByCategory :many
SELECT id, SELECT id,
agent_id, agent_id,

View file

@ -8,7 +8,7 @@ FROM agent_kv
WHERE agent_id = sqlc.arg(agent_id) WHERE agent_id = sqlc.arg(agent_id)
AND key = sqlc.arg(key) AND key = sqlc.arg(key)
LIMIT 1; LIMIT 1;
-- name: UpsertKV :exec -- name: UpsertKV :one
INSERT INTO agent_kv (agent_id, key, value, updated_at) INSERT INTO agent_kv (agent_id, key, value, updated_at)
VALUES ( VALUES (
sqlc.arg(agent_id), sqlc.arg(agent_id),
@ -18,7 +18,8 @@ VALUES (
) ON CONFLICT (agent_id, key) DO ) ON CONFLICT (agent_id, key) DO
UPDATE UPDATE
SET value = excluded.value, SET value = excluded.value,
updated_at = excluded.updated_at; updated_at = excluded.updated_at
RETURNING agent_id, key, value, updated_at;
-- name: DeleteKV :exec -- name: DeleteKV :exec
DELETE FROM agent_kv DELETE FROM agent_kv
WHERE agent_id = sqlc.arg(agent_id) WHERE agent_id = sqlc.arg(agent_id)

View file

@ -1,5 +1,5 @@
-- Archival Chunk queries -- Archival Chunk queries
-- name: InsertArchivalChunk :exec -- name: InsertArchivalChunk :one
INSERT INTO archival_chunks ( INSERT INTO archival_chunks (
id, id,
recall_id, recall_id,
@ -19,7 +19,8 @@ VALUES (
sqlc.arg(source), sqlc.arg(source),
sqlc.arg(hash), sqlc.arg(hash),
datetime('now') datetime('now')
); )
RETURNING id, recall_id, chunk_index, content, embedding, source, hash, created_at;
-- name: GetArchivalChunk :one -- name: GetArchivalChunk :one
SELECT ac.id, SELECT ac.id,
ac.recall_id, ac.recall_id,

View file

@ -1,5 +1,5 @@
-- Recall Item queries -- Recall Item queries
-- name: InsertRecallItem :exec -- name: InsertRecallItem :one
INSERT INTO recall_items ( INSERT INTO recall_items (
id, id,
agent_id, agent_id,
@ -27,7 +27,8 @@ VALUES (
sqlc.arg(tags), sqlc.arg(tags),
datetime('now'), datetime('now'),
datetime('now') datetime('now')
); )
RETURNING id, agent_id, session_key, role, sector, importance, salience, decay_rate, content, tags, created_at, updated_at;
-- name: GetRecallItem :one -- name: GetRecallItem :one
SELECT id, SELECT id,
agent_id, agent_id,
@ -124,7 +125,7 @@ SELECT id,
FROM recall_items FROM recall_items
WHERE id IN (sqlc.slice('ids')) WHERE id IN (sqlc.slice('ids'))
AND agent_id = sqlc.arg(agent_id); AND agent_id = sqlc.arg(agent_id);
-- name: InsertSessionMessage :exec -- name: InsertSessionMessage :one
INSERT INTO recall_items ( INSERT INTO recall_items (
id, id,
agent_id, agent_id,
@ -152,7 +153,8 @@ VALUES (
'session-message', 'session-message',
datetime('now'), datetime('now'),
datetime('now') datetime('now')
); )
RETURNING id, agent_id, session_key, role, sector, importance, salience, decay_rate, content, tags, created_at, updated_at;
-- name: ListSessionMessages :many -- name: ListSessionMessages :many
SELECT id, SELECT id,
agent_id, agent_id,

View file

@ -1,5 +1,5 @@
-- Memory Summary queries -- Memory Summary queries
-- name: InsertSummary :exec -- name: InsertSummary :one
INSERT INTO memory_summaries ( INSERT INTO memory_summaries (
id, id,
agent_id, agent_id,
@ -17,7 +17,8 @@ VALUES (
sqlc.arg(from_msg_idx), sqlc.arg(from_msg_idx),
sqlc.arg(to_msg_idx), sqlc.arg(to_msg_idx),
datetime('now') datetime('now')
); )
RETURNING id, agent_id, session_key, content, from_msg_idx, to_msg_idx, created_at;
-- name: ListSummaries :many -- name: ListSummaries :many
SELECT id, SELECT id,
agent_id, agent_id,

View file

@ -8,7 +8,7 @@ FROM working_context
WHERE agent_id = sqlc.arg(agent_id) WHERE agent_id = sqlc.arg(agent_id)
AND session_key = sqlc.arg(session_key) AND session_key = sqlc.arg(session_key)
LIMIT 1; LIMIT 1;
-- name: UpsertWorkingContext :exec -- name: UpsertWorkingContext :one
INSERT INTO working_context (agent_id, session_key, content, updated_at) INSERT INTO working_context (agent_id, session_key, content, updated_at)
VALUES ( VALUES (
sqlc.arg(agent_id), sqlc.arg(agent_id),
@ -18,4 +18,5 @@ VALUES (
) ON CONFLICT (agent_id, session_key) DO ) ON CONFLICT (agent_id, session_key) DO
UPDATE UPDATE
SET content = excluded.content, SET content = excluded.content,
updated_at = excluded.updated_at; updated_at = excluded.updated_at
RETURNING agent_id, session_key, content, updated_at;

View file

@ -241,7 +241,7 @@ func (q *Queries) GetRecallItemsByIDs(ctx context.Context, arg GetRecallItemsByI
return items, nil return items, nil
} }
const InsertRecallItem = `-- name: InsertRecallItem :exec const InsertRecallItem = `-- name: InsertRecallItem :one
INSERT INTO recall_items ( INSERT INTO recall_items (
id, id,
agent_id, agent_id,
@ -270,6 +270,7 @@ VALUES (
datetime('now'), datetime('now'),
datetime('now') datetime('now')
) )
RETURNING id, agent_id, session_key, role, sector, importance, salience, decay_rate, content, tags, created_at, updated_at
` `
type InsertRecallItemParams struct { type InsertRecallItemParams struct {
@ -315,8 +316,9 @@ type InsertRecallItemParams struct {
// datetime('now'), // datetime('now'),
// datetime('now') // datetime('now')
// ) // )
func (q *Queries) InsertRecallItem(ctx context.Context, arg InsertRecallItemParams) error { // RETURNING id, agent_id, session_key, role, sector, importance, salience, decay_rate, content, tags, created_at, updated_at
_, err := q.db.ExecContext(ctx, InsertRecallItem, func (q *Queries) InsertRecallItem(ctx context.Context, arg InsertRecallItemParams) (RecallItem, error) {
row := q.db.QueryRowContext(ctx, InsertRecallItem,
arg.ID, arg.ID,
arg.AgentID, arg.AgentID,
arg.SessionKey, arg.SessionKey,
@ -328,10 +330,25 @@ func (q *Queries) InsertRecallItem(ctx context.Context, arg InsertRecallItemPara
arg.Content, arg.Content,
arg.Tags, arg.Tags,
) )
return err var i RecallItem
err := row.Scan(
&i.ID,
&i.AgentID,
&i.SessionKey,
&i.Role,
&i.Sector,
&i.Importance,
&i.Salience,
&i.DecayRate,
&i.Content,
&i.Tags,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
} }
const InsertSessionMessage = `-- name: InsertSessionMessage :exec const InsertSessionMessage = `-- name: InsertSessionMessage :one
INSERT INTO recall_items ( INSERT INTO recall_items (
id, id,
agent_id, agent_id,
@ -360,6 +377,7 @@ VALUES (
datetime('now'), datetime('now'),
datetime('now') datetime('now')
) )
RETURNING id, agent_id, session_key, role, sector, importance, salience, decay_rate, content, tags, created_at, updated_at
` `
type InsertSessionMessageParams struct { type InsertSessionMessageParams struct {
@ -400,15 +418,31 @@ type InsertSessionMessageParams struct {
// datetime('now'), // datetime('now'),
// datetime('now') // datetime('now')
// ) // )
func (q *Queries) InsertSessionMessage(ctx context.Context, arg InsertSessionMessageParams) error { // RETURNING id, agent_id, session_key, role, sector, importance, salience, decay_rate, content, tags, created_at, updated_at
_, err := q.db.ExecContext(ctx, InsertSessionMessage, func (q *Queries) InsertSessionMessage(ctx context.Context, arg InsertSessionMessageParams) (RecallItem, error) {
row := q.db.QueryRowContext(ctx, InsertSessionMessage,
arg.ID, arg.ID,
arg.AgentID, arg.AgentID,
arg.SessionKey, arg.SessionKey,
arg.Role, arg.Role,
arg.Content, arg.Content,
) )
return err var i RecallItem
err := row.Scan(
&i.ID,
&i.AgentID,
&i.SessionKey,
&i.Role,
&i.Sector,
&i.Importance,
&i.Salience,
&i.DecayRate,
&i.Content,
&i.Tags,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
} }
const ListRecallItems = `-- name: ListRecallItems :many const ListRecallItems = `-- name: ListRecallItems :many

View file

@ -11,7 +11,7 @@ import (
"github.com/sipeed/picoclaw/pkg/ids" "github.com/sipeed/picoclaw/pkg/ids"
) )
const InsertSummary = `-- name: InsertSummary :exec const InsertSummary = `-- name: InsertSummary :one
INSERT INTO memory_summaries ( INSERT INTO memory_summaries (
id, id,
agent_id, agent_id,
@ -30,6 +30,7 @@ VALUES (
?6, ?6,
datetime('now') datetime('now')
) )
RETURNING id, agent_id, session_key, content, from_msg_idx, to_msg_idx, created_at
` `
type InsertSummaryParams struct { type InsertSummaryParams struct {
@ -61,8 +62,9 @@ type InsertSummaryParams struct {
// ?6, // ?6,
// datetime('now') // datetime('now')
// ) // )
func (q *Queries) InsertSummary(ctx context.Context, arg InsertSummaryParams) error { // RETURNING id, agent_id, session_key, content, from_msg_idx, to_msg_idx, created_at
_, err := q.db.ExecContext(ctx, InsertSummary, func (q *Queries) InsertSummary(ctx context.Context, arg InsertSummaryParams) (MemorySummary, error) {
row := q.db.QueryRowContext(ctx, InsertSummary,
arg.ID, arg.ID,
arg.AgentID, arg.AgentID,
arg.SessionKey, arg.SessionKey,
@ -70,7 +72,17 @@ func (q *Queries) InsertSummary(ctx context.Context, arg InsertSummaryParams) er
arg.FromMsgIdx, arg.FromMsgIdx,
arg.ToMsgIdx, arg.ToMsgIdx,
) )
return err var i MemorySummary
err := row.Scan(
&i.ID,
&i.AgentID,
&i.SessionKey,
&i.Content,
&i.FromMsgIdx,
&i.ToMsgIdx,
&i.CreatedAt,
)
return i, err
} }
const ListSummaries = `-- name: ListSummaries :many const ListSummaries = `-- name: ListSummaries :many

View file

@ -47,7 +47,7 @@ func (q *Queries) GetWorkingContext(ctx context.Context, arg GetWorkingContextPa
return i, err return i, err
} }
const UpsertWorkingContext = `-- name: UpsertWorkingContext :exec const UpsertWorkingContext = `-- name: UpsertWorkingContext :one
INSERT INTO working_context (agent_id, session_key, content, updated_at) INSERT INTO working_context (agent_id, session_key, content, updated_at)
VALUES ( VALUES (
?1, ?1,
@ -58,6 +58,7 @@ VALUES (
UPDATE UPDATE
SET content = excluded.content, SET content = excluded.content,
updated_at = excluded.updated_at updated_at = excluded.updated_at
RETURNING agent_id, session_key, content, updated_at
` `
type UpsertWorkingContextParams struct { type UpsertWorkingContextParams struct {
@ -78,7 +79,15 @@ type UpsertWorkingContextParams struct {
// UPDATE // UPDATE
// SET content = excluded.content, // SET content = excluded.content,
// updated_at = excluded.updated_at // updated_at = excluded.updated_at
func (q *Queries) UpsertWorkingContext(ctx context.Context, arg UpsertWorkingContextParams) error { // RETURNING agent_id, session_key, content, updated_at
_, err := q.db.ExecContext(ctx, UpsertWorkingContext, arg.AgentID, arg.SessionKey, arg.Content) func (q *Queries) UpsertWorkingContext(ctx context.Context, arg UpsertWorkingContextParams) (WorkingContext, error) {
return err row := q.db.QueryRowContext(ctx, UpsertWorkingContext, arg.AgentID, arg.SessionKey, arg.Content)
var i WorkingContext
err := row.Scan(
&i.AgentID,
&i.SessionKey,
&i.Content,
&i.UpdatedAt,
)
return i, err
} }