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 {
return d.queries.UpsertWorkingContext(ctx, memsqlc.UpsertWorkingContextParams{
_, err := d.queries.UpsertWorkingContext(ctx, memsqlc.UpsertWorkingContextParams{
AgentID: agentID,
SessionKey: sessionKey,
Content: content,
})
return err
}
// --- Recall Items ---
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,
AgentID: item.AgentID,
SessionKey: item.SessionKey,
@ -238,6 +239,12 @@ func (d *LibSQLDelegate) InsertRecallItem(ctx context.Context, item *memory.Reca
Content: item.Content,
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) {
@ -307,7 +314,7 @@ func (d *LibSQLDelegate) SearchRecallByKeyword(ctx context.Context, query, agent
func (d *LibSQLDelegate) InsertArchivalChunk(ctx context.Context, chunk *memory.ArchivalChunk) error {
// Embedding.Value() returns nil (SQL NULL) for empty embeddings,
// 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,
RecallID: chunk.RecallID,
ChunkIndex: int64(chunk.ChunkIndex),
@ -316,6 +323,11 @@ func (d *LibSQLDelegate) InsertArchivalChunk(ctx context.Context, chunk *memory.
Source: chunk.Source,
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) {
@ -364,7 +376,7 @@ func (d *LibSQLDelegate) DeleteArchivalChunks(ctx context.Context, recallID ids.
// --- Summaries ---
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,
AgentID: summary.AgentID,
SessionKey: summary.SessionKey,
@ -372,6 +384,11 @@ func (d *LibSQLDelegate) InsertSummary(ctx context.Context, summary *memory.Memo
FromMsgIdx: int64(summary.FromMsgIdx),
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) {
@ -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 {
return d.queries.UpsertKV(ctx, memsqlc.UpsertKVParams{
_, err := d.queries.UpsertKV(ctx, memsqlc.UpsertKVParams{
AgentID: agentID,
Key: key,
Value: value,
})
return err
}
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 {
return d.queries.UpsertDocument(ctx, memsqlc.UpsertDocumentParams{
row, err := d.queries.UpsertDocument(ctx, memsqlc.UpsertDocumentParams{
ID: doc.ID,
AgentID: doc.AgentID,
Name: doc.Name,
Category: doc.Category,
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 {
@ -527,13 +553,14 @@ func (d *LibSQLDelegate) ListAllDocuments(ctx context.Context, agentID string) (
// --- Session Messages ---
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(),
AgentID: agentID,
SessionKey: sessionKey,
Role: role,
Content: content,
})
return err
}
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 ---
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,
AgentID: entry.AgentID,
SessionKey: entry.SessionKey,
@ -573,6 +600,11 @@ func (d *LibSQLDelegate) InsertAuditEntry(ctx context.Context, entry *memory.Aud
Output: &entry.Output,
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) {

View file

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

View file

@ -14,8 +14,12 @@ import (
const CreateAgentConversationFork = `-- name: CreateAgentConversationFork :one
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 (?, ?, ?, ?, ?)
RETURNING id, parent_conversation_id, child_conversation_id, checkpoint_id, metadata_json, created_at, updated_at
`
@ -31,7 +35,11 @@ type CreateAgentConversationForkParams struct {
// CreateAgentConversationFork
//
// 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 (?, ?, ?, ?, ?)
// 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
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 = ?
LIMIT 1
`
@ -68,7 +77,8 @@ type GetAgentConversationForkByChildConversationIDParams struct {
// 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 = ?
// LIMIT 1
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
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 = ?
ORDER BY created_at DESC
LIMIT ?2
@ -100,7 +111,8 @@ type ListAgentConversationForksByParentConversationIDParams struct {
// 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 = ?
// ORDER BY created_at DESC
// LIMIT ?2

View file

@ -14,8 +14,12 @@ import (
const CreateAgentConversationLink = `-- name: CreateAgentConversationLink :one
INSERT INTO agent_conversation_links (
id, conversation_id, linked_conversation_id, kind, metadata_json
)
id,
conversation_id,
linked_conversation_id,
kind,
metadata_json
)
VALUES (?, ?, ?, ?, ?)
RETURNING id, conversation_id, linked_conversation_id, kind, metadata_json, created_at, updated_at
`
@ -31,7 +35,11 @@ type CreateAgentConversationLinkParams struct {
// CreateAgentConversationLink
//
// INSERT INTO agent_conversation_links (
// id, conversation_id, linked_conversation_id, kind, metadata_json
// id,
// conversation_id,
// linked_conversation_id,
// kind,
// metadata_json
// )
// VALUES (?, ?, ?, ?, ?)
// 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
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 {
@ -70,14 +80,17 @@ type DeleteAgentConversationLinkParams struct {
// DeleteAgentConversationLink
//
// 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 {
_, err := q.db.ExecContext(ctx, DeleteAgentConversationLink, arg.ConversationID, arg.LinkedConversationID, arg.Kind)
return err
}
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 = ?
ORDER BY created_at DESC
LIMIT ?2
@ -90,7 +103,8 @@ type ListAgentConversationLinksByConversationIDParams struct {
// 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 = ?
// ORDER BY created_at DESC
// LIMIT ?2

View file

@ -40,7 +40,10 @@ func (q *Queries) CreateAgentConversation(ctx context.Context, arg CreateAgentCo
}
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 {
@ -49,7 +52,10 @@ type GetAgentConversationParams struct {
// 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) {
row := q.db.QueryRowContext(ctx, GetAgentConversation, arg.ID)
var i AgentConversation
@ -63,7 +69,10 @@ func (q *Queries) GetAgentConversation(ctx context.Context, arg GetAgentConversa
}
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 {
@ -72,7 +81,10 @@ type ListAgentConversationsParams struct {
// 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) {
rows, err := q.db.QueryContext(ctx, ListAgentConversations, arg.Limit)
if err != nil {

View file

@ -232,7 +232,7 @@ func (q *Queries) ListDocumentsByCategory(ctx context.Context, arg ListDocuments
return items, nil
}
const UpsertDocument = `-- name: UpsertDocument :exec
const UpsertDocument = `-- name: UpsertDocument :one
INSERT INTO agent_documents (
id,
agent_id,
@ -261,6 +261,7 @@ SET content = excluded.content,
version = agent_documents.version + 1,
is_active = 1,
updated_at = datetime('now')
RETURNING id, agent_id, name, category, content, version, is_active, created_at, updated_at
`
type UpsertDocumentParams struct {
@ -301,13 +302,26 @@ type UpsertDocumentParams struct {
// version = agent_documents.version + 1,
// is_active = 1,
// updated_at = datetime('now')
func (q *Queries) UpsertDocument(ctx context.Context, arg UpsertDocumentParams) error {
_, err := q.db.ExecContext(ctx, UpsertDocument,
// RETURNING id, agent_id, name, category, content, version, is_active, created_at, updated_at
func (q *Queries) UpsertDocument(ctx context.Context, arg UpsertDocumentParams) (AgentDocument, error) {
row := q.db.QueryRowContext(ctx, UpsertDocument,
arg.ID,
arg.AgentID,
arg.Name,
arg.Category,
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
}
const UpsertKV = `-- name: UpsertKV :exec
const UpsertKV = `-- name: UpsertKV :one
INSERT INTO agent_kv (agent_id, key, value, updated_at)
VALUES (
?1,
@ -136,6 +136,7 @@ VALUES (
UPDATE
SET value = excluded.value,
updated_at = excluded.updated_at
RETURNING agent_id, key, value, updated_at
`
type UpsertKVParams struct {
@ -156,7 +157,15 @@ type UpsertKVParams struct {
// UPDATE
// SET value = excluded.value,
// updated_at = excluded.updated_at
func (q *Queries) UpsertKV(ctx context.Context, arg UpsertKVParams) error {
_, err := q.db.ExecContext(ctx, UpsertKV, arg.AgentID, arg.Key, arg.Value)
return err
// RETURNING agent_id, key, value, updated_at
func (q *Queries) UpsertKV(ctx context.Context, arg UpsertKVParams) (AgentKv, error) {
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
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 (?, ?, ?, ?, ?, ?, ?)
RETURNING id, conversation_id, message_id, kind, target_id, raw, metadata_json, created_at, updated_at
`
@ -33,7 +39,13 @@ type AddAgentMentionParams struct {
// AddAgentMention
//
// 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 (?, ?, ?, ?, ?, ?, ?)
// 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
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 = ?
ORDER BY created_at DESC
LIMIT ?2
@ -76,7 +89,8 @@ type ListAgentMentionsByConversationIDParams struct {
// 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 = ?
// ORDER BY created_at DESC
// LIMIT ?2

View file

@ -14,8 +14,13 @@ import (
const AddAgentMessageRevision = `-- name: AddAgentMessageRevision :one
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 (?, ?, ?, ?, ?, ?)
RETURNING id, message_id, editor, old_content, new_content, metadata_json, created_at, updated_at
`
@ -32,7 +37,12 @@ type AddAgentMessageRevisionParams struct {
// AddAgentMessageRevision
//
// 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 (?, ?, ?, ?, ?, ?)
// 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
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 = ?
ORDER BY created_at DESC
LIMIT ?2
@ -73,7 +84,8 @@ type ListAgentMessageRevisionsByMessageIDParams struct {
// 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 = ?
// ORDER BY created_at DESC
// LIMIT ?2

View file

@ -13,7 +13,13 @@ import (
)
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 (?, ?, ?, ?, ?)
RETURNING id, conversation_id, role, content, metadata_json, created_at, updated_at
`
@ -28,7 +34,13 @@ type AddAgentMessageParams struct {
// AddAgentMessage
//
// INSERT INTO agent_messages (id, conversation_id, role, content, metadata_json)
// INSERT INTO agent_messages (
// id,
// conversation_id,
// role,
// content,
// metadata_json
// )
// VALUES (?, ?, ?, ?, ?)
// RETURNING id, conversation_id, role, content, metadata_json, created_at, updated_at
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
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 = ?
ORDER BY created_at ASC
`
@ -64,7 +77,8 @@ type ListAgentMessagesByConversationIDParams struct {
// 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 = ?
// ORDER BY created_at ASC
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
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 = ?
ORDER BY created_at ASC
LIMIT ?
@ -112,7 +127,8 @@ type ListAgentMessagesByConversationIDLimitParams struct {
// 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 = ?
// ORDER BY created_at ASC
// LIMIT ?

View file

@ -55,8 +55,16 @@ func (q *Queries) AddAgentRunState(ctx context.Context, arg AddAgentRunStatePara
const AddAgentStateTransition = `-- name: AddAgentStateTransition :one
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 (?, ?, ?, ?, ?, ?, ?, ?, ?)
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
//
// 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 (?, ?, ?, ?, ?, ?, ?, ?, ?)
// 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
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 (?, ?, ?, ?, ?)
RETURNING id, conversation_id, name, run_state_id, metadata_json, created_at, updated_at
`
@ -125,7 +147,13 @@ type CreateAgentCheckpointParams struct {
// 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 (?, ?, ?, ?, ?)
// 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) {
@ -187,8 +215,10 @@ func (q *Queries) CreateAgentRun(ctx context.Context, arg CreateAgentRunParams)
}
const GetAgentCheckpointByConversationIDAndName = `-- name: GetAgentCheckpointByConversationIDAndName :one
SELECT id, conversation_id, name, run_state_id, metadata_json, created_at, updated_at FROM agent_checkpoints
WHERE conversation_id = ? AND name = ?
SELECT id, conversation_id, name, run_state_id, metadata_json, created_at, updated_at
FROM agent_checkpoints
WHERE conversation_id = ?
AND name = ?
LIMIT 1
`
@ -199,8 +229,10 @@ type GetAgentCheckpointByConversationIDAndNameParams struct {
// GetAgentCheckpointByConversationIDAndName
//
// SELECT id, conversation_id, name, run_state_id, metadata_json, created_at, updated_at FROM agent_checkpoints
// WHERE conversation_id = ? AND name = ?
// SELECT id, conversation_id, name, run_state_id, metadata_json, created_at, updated_at
// FROM agent_checkpoints
// WHERE conversation_id = ?
// AND name = ?
// LIMIT 1
func (q *Queries) GetAgentCheckpointByConversationIDAndName(ctx context.Context, arg GetAgentCheckpointByConversationIDAndNameParams) (AgentCheckpoint, error) {
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
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 = ?
LIMIT 1
`
@ -229,7 +262,8 @@ type GetAgentRunStateByIDParams struct {
// 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 = ?
// LIMIT 1
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
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 = ?
ORDER BY created_at DESC
LIMIT 1
@ -260,7 +295,8 @@ type GetLatestAgentRunByConversationIDParams struct {
// 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 = ?
// ORDER BY created_at DESC
// LIMIT 1
@ -279,7 +315,8 @@ func (q *Queries) GetLatestAgentRunByConversationID(ctx context.Context, arg Get
}
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 = ?
ORDER BY step_index DESC
LIMIT 1
@ -291,7 +328,8 @@ type GetLatestAgentRunStateByRunIDParams struct {
// 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 = ?
// ORDER BY step_index DESC
// LIMIT 1
@ -311,7 +349,8 @@ func (q *Queries) GetLatestAgentRunStateByRunID(ctx context.Context, arg GetLate
}
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 = ?
ORDER BY created_at DESC
LIMIT ?2
@ -324,7 +363,8 @@ type ListAgentCheckpointsByConversationIDParams struct {
// 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 = ?
// ORDER BY created_at DESC
// LIMIT ?2
@ -360,7 +400,8 @@ func (q *Queries) ListAgentCheckpointsByConversationID(ctx context.Context, arg
}
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 = ?
ORDER BY step_index ASC
LIMIT ?2
@ -373,7 +414,8 @@ type ListAgentRunStatesByRunIDParams struct {
// 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 = ?
// ORDER BY step_index ASC
// LIMIT ?2
@ -409,7 +451,8 @@ func (q *Queries) ListAgentRunStatesByRunID(ctx context.Context, arg ListAgentRu
}
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 = ?
ORDER BY at ASC
LIMIT ?2
@ -422,7 +465,8 @@ type ListAgentStateTransitionsByRunIDParams struct {
// 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 = ?
// ORDER BY at ASC
// LIMIT ?2

View file

@ -90,7 +90,8 @@ func (q *Queries) CreateAgentThread(ctx context.Context, arg CreateAgentThreadPa
}
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 = ?
ORDER BY created_at ASC
`
@ -101,7 +102,8 @@ type ListAgentThreadMessagesByThreadIDParams struct {
// 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 = ?
// ORDER BY created_at ASC
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
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 = ?
ORDER BY created_at DESC
LIMIT ?
@ -149,7 +152,8 @@ type ListAgentThreadMessagesByThreadIDDescLimitParams struct {
// 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 = ?
// ORDER BY created_at DESC
// LIMIT ?
@ -185,7 +189,8 @@ func (q *Queries) ListAgentThreadMessagesByThreadIDDescLimit(ctx context.Context
}
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 = ?
ORDER BY created_at DESC
LIMIT ?2
@ -198,7 +203,8 @@ type ListAgentThreadsByConversationIDParams struct {
// 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 = ?
// ORDER BY created_at DESC
// LIMIT ?2

View file

@ -14,9 +14,17 @@ import (
const AddAgentToolResult = `-- name: AddAgentToolResult :one
INSERT INTO agent_tool_results (
id, conversation_id, run_id, step_index,
tool_call_id, tool_name, full_key, preview, chunk_count, metadata_json
)
id,
conversation_id,
run_id,
step_index,
tool_call_id,
tool_name,
full_key,
preview,
chunk_count,
metadata_json
)
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
`
@ -37,8 +45,16 @@ type AddAgentToolResultParams struct {
// AddAgentToolResult
//
// INSERT INTO agent_tool_results (
// id, conversation_id, run_id, step_index,
// tool_call_id, tool_name, full_key, preview, chunk_count, metadata_json
// id,
// conversation_id,
// run_id,
// step_index,
// tool_call_id,
// tool_name,
// full_key,
// preview,
// chunk_count,
// metadata_json
// )
// 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
@ -74,8 +90,10 @@ func (q *Queries) AddAgentToolResult(ctx context.Context, arg AddAgentToolResult
}
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
WHERE run_id = ? AND tool_call_id = ?
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 = ?
AND tool_call_id = ?
LIMIT 1
`
@ -86,8 +104,10 @@ type GetAgentToolResultByRunIDAndToolCallIDParams struct {
// 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
// WHERE run_id = ? AND tool_call_id = ?
// 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 = ?
// AND tool_call_id = ?
// LIMIT 1
func (q *Queries) GetAgentToolResultByRunIDAndToolCallID(ctx context.Context, arg GetAgentToolResultByRunIDAndToolCallIDParams) (AgentToolResult, error) {
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
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 = ?
ORDER BY created_at DESC
`
@ -121,7 +142,8 @@ type ListAgentToolResultsByConversationIDParams struct {
// 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 = ?
// ORDER BY created_at DESC
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
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 = ?
ORDER BY created_at DESC
LIMIT ?
@ -174,7 +197,8 @@ type ListAgentToolResultsByConversationIDLimitParams struct {
// 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 = ?
// ORDER BY created_at DESC
// LIMIT ?
@ -215,9 +239,11 @@ func (q *Queries) ListAgentToolResultsByConversationIDLimit(ctx context.Context,
}
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 = ?
ORDER BY step_index ASC, created_at ASC
ORDER BY step_index ASC,
created_at ASC
LIMIT ?2
`
@ -228,9 +254,11 @@ type ListAgentToolResultsByRunIDParams struct {
// 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 = ?
// ORDER BY step_index ASC, created_at ASC
// ORDER BY step_index ASC,
// created_at ASC
// LIMIT ?2
func (q *Queries) ListAgentToolResultsByRunID(ctx context.Context, arg ListAgentToolResultsByRunIDParams) ([]AgentToolResult, error) {
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
}
const InsertArchivalChunk = `-- name: InsertArchivalChunk :exec
const InsertArchivalChunk = `-- name: InsertArchivalChunk :one
INSERT INTO archival_chunks (
id,
recall_id,
@ -205,6 +205,7 @@ VALUES (
?7,
datetime('now')
)
RETURNING id, recall_id, chunk_index, content, embedding, source, hash, created_at
`
type InsertArchivalChunkParams struct {
@ -239,8 +240,9 @@ type InsertArchivalChunkParams struct {
// ?7,
// datetime('now')
// )
func (q *Queries) InsertArchivalChunk(ctx context.Context, arg InsertArchivalChunkParams) error {
_, err := q.db.ExecContext(ctx, InsertArchivalChunk,
// RETURNING id, recall_id, chunk_index, content, embedding, source, hash, created_at
func (q *Queries) InsertArchivalChunk(ctx context.Context, arg InsertArchivalChunkParams) (ArchivalChunk, error) {
row := q.db.QueryRowContext(ctx, InsertArchivalChunk,
arg.ID,
arg.RecallID,
arg.ChunkIndex,
@ -249,7 +251,18 @@ func (q *Queries) InsertArchivalChunk(ctx context.Context, arg InsertArchivalChu
arg.Source,
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

View file

@ -20,7 +20,8 @@ SET status = 'running',
locked_by = ?1,
updated_at = strftime('%Y-%m-%dT%H:%M:%fZ', 'now'),
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
`
@ -38,7 +39,8 @@ type ClaimJobByIDParams struct {
// locked_by = ?1,
// updated_at = strftime('%Y-%m-%dT%H:%M:%fZ', 'now'),
// 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
func (q *Queries) ClaimJobByID(ctx context.Context, arg ClaimJobByIDParams) (Job, error) {
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
SELECT status, count(*) AS count FROM jobs GROUP BY status
SELECT status,
count(*) AS count
FROM jobs
GROUP BY status
`
type CountJobsByStatusRow struct {
@ -73,7 +78,10 @@ type CountJobsByStatusRow struct {
// 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) {
rows, err := q.db.QueryContext(ctx, CountJobsByStatus)
if err != nil {
@ -99,18 +107,28 @@ func (q *Queries) CountJobsByStatus(ctx context.Context) ([]CountJobsByStatusRow
const EnqueueJob = `-- name: EnqueueJob :one
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 (
?1,
?2,
'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(?5, '{}'),
?6
) ON CONFLICT(kind, dedupe_key)
WHERE dedupe_key IS NOT NULL DO UPDATE
) ON CONFLICT(kind, dedupe_key)
WHERE dedupe_key IS NOT NULL DO
UPDATE
SET status = 'queued',
run_at = excluded.run_at,
max_attempts = excluded.max_attempts,
@ -133,18 +151,28 @@ type EnqueueJobParams struct {
// EnqueueJob
//
// 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 (
// ?1,
// ?2,
// '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(?5, '{}'),
// ?6
// ) ON CONFLICT(kind, dedupe_key)
// WHERE dedupe_key IS NOT NULL DO UPDATE
// WHERE dedupe_key IS NOT NULL DO
// UPDATE
// SET status = 'queued',
// run_at = excluded.run_at,
// 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
SELECT id FROM jobs
SELECT id
FROM jobs
WHERE status = 'queued'
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
`
// FindNextRunnableJob
//
// SELECT id FROM jobs
// SELECT id
// FROM jobs
// WHERE status = 'queued'
// 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
func (q *Queries) FindNextRunnableJob(ctx context.Context) (ids.UUID, error) {
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
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 {
@ -214,7 +249,10 @@ type GetJobParams struct {
// 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) {
row := q.db.QueryRowContext(ctx, GetJob, arg.ID)
var i Job
@ -238,7 +276,10 @@ func (q *Queries) GetJob(ctx context.Context, arg GetJobParams) (Job, error) {
}
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 {
@ -248,7 +289,10 @@ type ListJobsParams struct {
// 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) {
rows, err := q.db.QueryContext(ctx, ListJobs, arg.Off, arg.Lim)
if err != nil {
@ -381,7 +425,10 @@ func (q *Queries) MarkJobSucceeded(ctx context.Context, arg MarkJobSucceededPara
const RequeueJob = `-- name: RequeueJob :one
UPDATE jobs
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'),
last_error = ?2,
locked_at = NULL,
@ -401,7 +448,10 @@ type RequeueJobParams struct {
//
// UPDATE jobs
// 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'),
// last_error = ?2,
// locked_at = NULL,

View file

@ -14,21 +14,38 @@ type Querier interface {
//AddAgentMention
//
// 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 (?, ?, ?, ?, ?, ?, ?)
// RETURNING id, conversation_id, message_id, kind, target_id, raw, metadata_json, created_at, updated_at
AddAgentMention(ctx context.Context, arg AddAgentMentionParams) (AgentMention, error)
//AddAgentMessage
//
// INSERT INTO agent_messages (id, conversation_id, role, content, metadata_json)
// INSERT INTO agent_messages (
// id,
// conversation_id,
// role,
// content,
// metadata_json
// )
// VALUES (?, ?, ?, ?, ?)
// RETURNING id, conversation_id, role, content, metadata_json, created_at, updated_at
AddAgentMessage(ctx context.Context, arg AddAgentMessageParams) (AgentMessage, error)
//AddAgentMessageRevision
//
// 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 (?, ?, ?, ?, ?, ?)
// RETURNING id, message_id, editor, old_content, new_content, metadata_json, created_at, updated_at
@ -42,7 +59,15 @@ type Querier interface {
//AddAgentStateTransition
//
// 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 (?, ?, ?, ?, ?, ?, ?, ?, ?)
// 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
//
// INSERT INTO agent_tool_results (
// id, conversation_id, run_id, step_index,
// tool_call_id, tool_name, full_key, preview, chunk_count, metadata_json
// id,
// conversation_id,
// run_id,
// step_index,
// tool_call_id,
// tool_name,
// full_key,
// preview,
// chunk_count,
// metadata_json
// )
// 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
@ -71,7 +104,8 @@ type Querier interface {
// locked_by = ?1,
// updated_at = strftime('%Y-%m-%dT%H:%M:%fZ', 'now'),
// 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
ClaimJobByID(ctx context.Context, arg ClaimJobByIDParams) (Job, error)
//CountArchivalChunks
@ -96,7 +130,10 @@ type Querier interface {
CountAuditEntriesByAction(ctx context.Context, arg CountAuditEntriesByActionParams) (int64, error)
//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)
//CountRecallItems
//
@ -118,7 +155,13 @@ type Querier interface {
CountSessionMessages(ctx context.Context, arg CountSessionMessagesParams) (int64, error)
//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 (?, ?, ?, ?, ?)
// RETURNING id, conversation_id, name, run_state_id, metadata_json, created_at, updated_at
CreateAgentCheckpoint(ctx context.Context, arg CreateAgentCheckpointParams) (AgentCheckpoint, error)
@ -131,7 +174,11 @@ type Querier interface {
//CreateAgentConversationFork
//
// 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 (?, ?, ?, ?, ?)
// RETURNING id, parent_conversation_id, child_conversation_id, checkpoint_id, metadata_json, created_at, updated_at
@ -139,7 +186,11 @@ type Querier interface {
//CreateAgentConversationLink
//
// INSERT INTO agent_conversation_links (
// id, conversation_id, linked_conversation_id, kind, metadata_json
// id,
// conversation_id,
// linked_conversation_id,
// kind,
// metadata_json
// )
// VALUES (?, ?, ?, ?, ?)
// RETURNING id, conversation_id, linked_conversation_id, kind, metadata_json, created_at, updated_at
@ -159,7 +210,9 @@ type Querier interface {
//DeleteAgentConversationLink
//
// 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
//DeleteArchivalChunksByRecall
//
@ -187,18 +240,28 @@ type Querier interface {
//EnqueueJob
//
// 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 (
// ?1,
// ?2,
// '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(?5, '{}'),
// ?6
// ) ON CONFLICT(kind, dedupe_key)
// WHERE dedupe_key IS NOT NULL DO UPDATE
// WHERE dedupe_key IS NOT NULL DO
// UPDATE
// SET status = 'queued',
// run_at = excluded.run_at,
// max_attempts = excluded.max_attempts,
@ -210,38 +273,49 @@ type Querier interface {
EnqueueJob(ctx context.Context, arg EnqueueJobParams) (Job, error)
//FindNextRunnableJob
//
// SELECT id FROM jobs
// SELECT id
// FROM jobs
// WHERE status = 'queued'
// 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
FindNextRunnableJob(ctx context.Context) (ids.UUID, error)
//GetAgentCheckpointByConversationIDAndName
//
// SELECT id, conversation_id, name, run_state_id, metadata_json, created_at, updated_at FROM agent_checkpoints
// WHERE conversation_id = ? AND name = ?
// SELECT id, conversation_id, name, run_state_id, metadata_json, created_at, updated_at
// FROM agent_checkpoints
// WHERE conversation_id = ?
// AND name = ?
// LIMIT 1
GetAgentCheckpointByConversationIDAndName(ctx context.Context, arg GetAgentCheckpointByConversationIDAndNameParams) (AgentCheckpoint, error)
//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)
//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 = ?
// LIMIT 1
GetAgentConversationForkByChildConversationID(ctx context.Context, arg GetAgentConversationForkByChildConversationIDParams) (AgentConversationFork, error)
//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 = ?
// LIMIT 1
GetAgentRunStateByID(ctx context.Context, arg GetAgentRunStateByIDParams) (AgentRunState, error)
//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
// WHERE run_id = ? AND tool_call_id = ?
// 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 = ?
// AND tool_call_id = ?
// LIMIT 1
GetAgentToolResultByRunIDAndToolCallID(ctx context.Context, arg GetAgentToolResultByRunIDAndToolCallIDParams) (AgentToolResult, error)
//GetArchivalChunk
@ -293,7 +367,10 @@ type Querier interface {
GetDocument(ctx context.Context, arg GetDocumentParams) (AgentDocument, error)
//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)
// Agent KV Store queries
//
@ -308,14 +385,16 @@ type Querier interface {
GetKV(ctx context.Context, arg GetKVParams) (AgentKv, error)
//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 = ?
// ORDER BY created_at DESC
// LIMIT 1
GetLatestAgentRunByConversationID(ctx context.Context, arg GetLatestAgentRunByConversationIDParams) (AgentRun, error)
//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 = ?
// ORDER BY step_index DESC
// LIMIT 1
@ -390,7 +469,8 @@ type Querier interface {
// ?7,
// 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
//
// INSERT INTO agent_audit_log (
@ -415,7 +495,8 @@ type Querier interface {
// ?8,
// 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
//
// INSERT INTO recall_items (
@ -446,7 +527,8 @@ type Querier interface {
// 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
//
// INSERT INTO recall_items (
@ -477,7 +559,8 @@ type Querier interface {
// 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
//
// INSERT INTO memory_summaries (
@ -498,111 +581,131 @@ type Querier interface {
// ?6,
// 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
//
// 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 = ?
// ORDER BY created_at DESC
// LIMIT ?2
ListAgentCheckpointsByConversationID(ctx context.Context, arg ListAgentCheckpointsByConversationIDParams) ([]AgentCheckpoint, error)
//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 = ?
// ORDER BY created_at DESC
// LIMIT ?2
ListAgentConversationForksByParentConversationID(ctx context.Context, arg ListAgentConversationForksByParentConversationIDParams) ([]AgentConversationFork, error)
//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 = ?
// ORDER BY created_at DESC
// LIMIT ?2
ListAgentConversationLinksByConversationID(ctx context.Context, arg ListAgentConversationLinksByConversationIDParams) ([]AgentConversationLink, error)
//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)
//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 = ?
// ORDER BY created_at DESC
// LIMIT ?2
ListAgentMentionsByConversationID(ctx context.Context, arg ListAgentMentionsByConversationIDParams) ([]AgentMention, error)
//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 = ?
// ORDER BY created_at DESC
// LIMIT ?2
ListAgentMessageRevisionsByMessageID(ctx context.Context, arg ListAgentMessageRevisionsByMessageIDParams) ([]AgentMessageRevision, error)
//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 = ?
// ORDER BY created_at ASC
ListAgentMessagesByConversationID(ctx context.Context, arg ListAgentMessagesByConversationIDParams) ([]AgentMessage, error)
//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 = ?
// ORDER BY created_at ASC
// LIMIT ?
ListAgentMessagesByConversationIDLimit(ctx context.Context, arg ListAgentMessagesByConversationIDLimitParams) ([]AgentMessage, error)
//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 = ?
// ORDER BY step_index ASC
// LIMIT ?2
ListAgentRunStatesByRunID(ctx context.Context, arg ListAgentRunStatesByRunIDParams) ([]AgentRunState, error)
//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 = ?
// ORDER BY at ASC
// LIMIT ?2
ListAgentStateTransitionsByRunID(ctx context.Context, arg ListAgentStateTransitionsByRunIDParams) ([]AgentStateTransition, error)
//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 = ?
// ORDER BY created_at ASC
ListAgentThreadMessagesByThreadID(ctx context.Context, arg ListAgentThreadMessagesByThreadIDParams) ([]AgentThreadMessage, error)
//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 = ?
// ORDER BY created_at DESC
// LIMIT ?
ListAgentThreadMessagesByThreadIDDescLimit(ctx context.Context, arg ListAgentThreadMessagesByThreadIDDescLimitParams) ([]AgentThreadMessage, error)
//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 = ?
// ORDER BY created_at DESC
// LIMIT ?2
ListAgentThreadsByConversationID(ctx context.Context, arg ListAgentThreadsByConversationIDParams) ([]AgentThread, error)
//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 = ?
// ORDER BY created_at DESC
ListAgentToolResultsByConversationID(ctx context.Context, arg ListAgentToolResultsByConversationIDParams) ([]AgentToolResult, error)
//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 = ?
// ORDER BY created_at DESC
// LIMIT ?
ListAgentToolResultsByConversationIDLimit(ctx context.Context, arg ListAgentToolResultsByConversationIDLimitParams) ([]AgentToolResult, error)
//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 = ?
// ORDER BY step_index ASC, created_at ASC
// ORDER BY step_index ASC,
// created_at ASC
// LIMIT ?2
ListAgentToolResultsByRunID(ctx context.Context, arg ListAgentToolResultsByRunIDParams) ([]AgentToolResult, error)
//ListAllArchivalChunks
@ -726,7 +829,10 @@ type Querier interface {
ListDocumentsByCategory(ctx context.Context, arg ListDocumentsByCategoryParams) ([]AgentDocument, error)
//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)
//ListKVByPrefix
//
@ -836,7 +942,10 @@ type Querier interface {
//
// UPDATE jobs
// 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'),
// last_error = ?2,
// locked_at = NULL,
@ -926,7 +1035,8 @@ type Querier interface {
// version = agent_documents.version + 1,
// is_active = 1,
// 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
//
// INSERT INTO agent_kv (agent_id, key, value, updated_at)
@ -939,7 +1049,8 @@ type Querier interface {
// UPDATE
// SET value = excluded.value,
// 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
//
// INSERT INTO working_context (agent_id, session_key, content, updated_at)
@ -952,7 +1063,8 @@ type Querier interface {
// UPDATE
// SET content = excluded.content,
// 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)

View file

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

View file

@ -13,7 +13,7 @@ FROM agent_documents
WHERE agent_id = sqlc.arg(agent_id)
AND name = sqlc.arg(name)
LIMIT 1;
-- name: UpsertDocument :exec
-- name: UpsertDocument :one
INSERT INTO agent_documents (
id,
agent_id,
@ -41,7 +41,8 @@ SET content = excluded.content,
category = excluded.category,
version = agent_documents.version + 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
SELECT id,
agent_id,

View file

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

View file

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

View file

@ -1,5 +1,5 @@
-- Recall Item queries
-- name: InsertRecallItem :exec
-- name: InsertRecallItem :one
INSERT INTO recall_items (
id,
agent_id,
@ -27,7 +27,8 @@ VALUES (
sqlc.arg(tags),
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
SELECT id,
agent_id,
@ -124,7 +125,7 @@ SELECT id,
FROM recall_items
WHERE id IN (sqlc.slice('ids'))
AND agent_id = sqlc.arg(agent_id);
-- name: InsertSessionMessage :exec
-- name: InsertSessionMessage :one
INSERT INTO recall_items (
id,
agent_id,
@ -152,7 +153,8 @@ VALUES (
'session-message',
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
SELECT id,
agent_id,

View file

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

View file

@ -8,7 +8,7 @@ FROM working_context
WHERE agent_id = sqlc.arg(agent_id)
AND session_key = sqlc.arg(session_key)
LIMIT 1;
-- name: UpsertWorkingContext :exec
-- name: UpsertWorkingContext :one
INSERT INTO working_context (agent_id, session_key, content, updated_at)
VALUES (
sqlc.arg(agent_id),
@ -18,4 +18,5 @@ VALUES (
) ON CONFLICT (agent_id, session_key) DO
UPDATE
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
}
const InsertRecallItem = `-- name: InsertRecallItem :exec
const InsertRecallItem = `-- name: InsertRecallItem :one
INSERT INTO recall_items (
id,
agent_id,
@ -270,6 +270,7 @@ VALUES (
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 {
@ -315,8 +316,9 @@ type InsertRecallItemParams struct {
// datetime('now'),
// datetime('now')
// )
func (q *Queries) InsertRecallItem(ctx context.Context, arg InsertRecallItemParams) error {
_, err := q.db.ExecContext(ctx, InsertRecallItem,
// RETURNING id, agent_id, session_key, role, sector, importance, salience, decay_rate, content, tags, created_at, updated_at
func (q *Queries) InsertRecallItem(ctx context.Context, arg InsertRecallItemParams) (RecallItem, error) {
row := q.db.QueryRowContext(ctx, InsertRecallItem,
arg.ID,
arg.AgentID,
arg.SessionKey,
@ -328,10 +330,25 @@ func (q *Queries) InsertRecallItem(ctx context.Context, arg InsertRecallItemPara
arg.Content,
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 (
id,
agent_id,
@ -360,6 +377,7 @@ VALUES (
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 {
@ -400,15 +418,31 @@ type InsertSessionMessageParams struct {
// datetime('now'),
// datetime('now')
// )
func (q *Queries) InsertSessionMessage(ctx context.Context, arg InsertSessionMessageParams) error {
_, err := q.db.ExecContext(ctx, InsertSessionMessage,
// RETURNING id, agent_id, session_key, role, sector, importance, salience, decay_rate, content, tags, created_at, updated_at
func (q *Queries) InsertSessionMessage(ctx context.Context, arg InsertSessionMessageParams) (RecallItem, error) {
row := q.db.QueryRowContext(ctx, InsertSessionMessage,
arg.ID,
arg.AgentID,
arg.SessionKey,
arg.Role,
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

View file

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

View file

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