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; }