feat(repos): agents (+ tokens + caps), conversations, messages
This commit is contained in:
18
lib/db/repos/messages.js
Normal file
18
lib/db/repos/messages.js
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user