import { randomBytes } from "node:crypto"; const ALPHABET = "0123456789abcdefghijklmnopqrstuvwxyz"; function base36(bytes: Buffer): string { let out = ""; for (const b of bytes) out += ALPHABET[b % 36]; return out; } /** Prefixed, URL-safe, 24-char random id: `cnv_k3j9...`. */ export function newId(prefix: string): string { return `${prefix}_${base36(randomBytes(20))}`; } export const ids = { conversation: () => newId("cnv"), message: () => newId("msg"), attachment: () => newId("att"), folder: () => newId("fld"), tag: () => newId("tag"), connection: () => newId("pcn"), usage: () => newId("usg"), preset: () => newId("pst"), prompt: () => newId("prm"), arena: () => newId("arn"), arenaResponse: () => newId("arr"), share: () => base36(randomBytes(16)), audit: () => newId("aud"), sync: () => newId("syn"), request: () => newId("req"), };