feat(agents): conversations.findOrCreateGlobal for space-less agents
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -43,6 +43,22 @@ export async function setSummary(id, summary) {
|
||||
return r;
|
||||
}
|
||||
|
||||
export async function findOrCreateGlobal(agent_id, actor) {
|
||||
const { rows: [existing] } = await pool.query(
|
||||
`SELECT * FROM conversations
|
||||
WHERE agent_id=$1 AND space_id IS NULL AND status='open'
|
||||
ORDER BY started_at DESC LIMIT 1`,
|
||||
[agent_id]
|
||||
);
|
||||
if (existing) return existing;
|
||||
const { rows: [r] } = await pool.query(
|
||||
`INSERT INTO conversations(title, agent_id, metadata) VALUES($1,$2,$3) RETURNING *`,
|
||||
[null, agent_id, {}]
|
||||
);
|
||||
await recordAudit(actor, 'create', 'conversation', r.id, null, r);
|
||||
return r;
|
||||
}
|
||||
|
||||
export async function findOrCreateForSpace(space_id, agent_id, actor) {
|
||||
const { rows: [existing] } = await pool.query(
|
||||
`SELECT * FROM conversations
|
||||
|
||||
Reference in New Issue
Block a user