import { getSession } from "../lib/neo4j.js";
export async function sessionName(params) {
    const { sessionKey, name } = params;
    // Do NOT MERGE on sessionKey — MERGE on a webchat first turn creates a
    // property-stub Conversation (no AdminConversation sublabel, no
    // accountId / agentType / userId) and the sibling
    // createNewAdminConversation's CREATE then collides at flush time on
    // the unique-constraint on Conversation.sessionKey. The MATCH path
    // mirrors task-create.ts: pre-resolve the Conversation, no-op when
    // missing. The agent's intent ("title the session") is the only
    // automatic source of `c.name`; otherwise the UI sidebar falls back
    // to Claude Code's `aiTitle` from the JSONL.
    const neo4jSession = getSession();
    try {
        const result = await neo4jSession.run(`MATCH (c:Conversation {sessionKey: $sessionKey})
       SET c.name = $name, c.updatedAt = datetime()
       RETURN count(c) AS affected`, { sessionKey, name });
        const affectedRaw = result.records[0]?.get("affected");
        const affected = typeof affectedRaw?.toNumber === "function"
            ? affectedRaw.toNumber()
            : Number(affectedRaw ?? 0);
        return { affected };
    }
    finally {
        await neo4jSession.close();
    }
}
//# sourceMappingURL=session-name.js.map