feat(repos): agents (+ tokens + caps), conversations, messages

This commit is contained in:
root
2026-05-31 10:36:40 +10:00
parent 5e094f347e
commit 1d799105ac
5 changed files with 194 additions and 0 deletions

18
lib/db/repos/messages.js Normal file
View File

@@ -0,0 +1,18 @@
import { pool } from '../pool.js';
export async function append(conversation_id, { role, body, agent_id, metadata }) {
const { rows: [r] } = await pool.query(
`INSERT INTO messages(conversation_id, role, body, agent_id, metadata)
VALUES($1,$2,$3,$4,$5) RETURNING *`,
[conversation_id, role, body, agent_id || null, metadata || {}]
);
return r;
}
export async function listByConversation(conversation_id, { limit = 1000 } = {}) {
const { rows } = await pool.query(
`SELECT * FROM messages WHERE conversation_id=$1 ORDER BY created_at LIMIT $2`,
[conversation_id, limit]
);
return rows;
}