import { int } from "neo4j-driver";
import { getSession } from "../lib/neo4j.js";
export async function sessionList(params) {
    const { accountId, limit = 20 } = params;
    const neo4jSession = getSession();
    try {
        const result = await neo4jSession.run(`MATCH (c:Conversation {accountId: $accountId})
       OPTIONAL MATCH (t:Task)-[:PART_OF]->(c)
       RETURN c, collect(
         CASE WHEN t IS NOT NULL
           THEN { taskId: t.taskId, name: t.name, status: t.status, priority: t.priority }
           ELSE null
         END
       ) AS tasks
       ORDER BY c.updatedAt DESC
       LIMIT $limit`, { accountId, limit: int(limit) });
        return result.records.map(rec => {
            const c = rec.get("c").properties;
            const rawTasks = rec.get("tasks");
            const summary = {
                sessionKey: c.sessionKey,
                sessionId: c.sessionId,
                agentType: c.agentType,
                createdAt: c.createdAt,
                updatedAt: c.updatedAt,
                tasks: rawTasks.filter(t => t !== null),
            };
            if (c.name)
                summary.name = c.name;
            return summary;
        });
    }
    finally {
        await neo4jSession.close();
    }
}
//# sourceMappingURL=session-list.js.map