SPB Git forge

spb/polyllm

Public
15commits 1branches 0releases
2.2 MBsize
maindefault branch
13 days agolast push
TypeScript 97.4% SQL 1% JavaScript 0.9% CSS 0.6%
886 B · 33 lines typescript
Raw Blame History
1import { randomBytes } from "node:crypto";23const ALPHABET = "0123456789abcdefghijklmnopqrstuvwxyz";45function base36(bytes: Buffer): string {6  let out = "";7  for (const b of bytes) out += ALPHABET[b % 36];8  return out;9}1011/** Prefixed, URL-safe, 24-char random id: `cnv_k3j9...`. */12export function newId(prefix: string): string {13  return `${prefix}_${base36(randomBytes(20))}`;14}1516export const ids = {17  conversation: () => newId("cnv"),18  message: () => newId("msg"),19  attachment: () => newId("att"),20  folder: () => newId("fld"),21  tag: () => newId("tag"),22  connection: () => newId("pcn"),23  usage: () => newId("usg"),24  preset: () => newId("pst"),25  prompt: () => newId("prm"),26  arena: () => newId("arn"),27  arenaResponse: () => newId("arr"),28  share: () => base36(randomBytes(16)),29  audit: () => newId("aud"),30  sync: () => newId("syn"),31  request: () => newId("req"),32};33