Files
PubScript/packages/core/src/ids.ts
T
Schwitzz 1e16b0d5d2 CHUNK #9: AI session storage layer (AgentController, AIStore, builders)
- Add packages/ai: AgentController (streaming + budget), SuggestionBuilder,
  NoteBuilder, AIStore (Dexie/IndexedDB), SuggestionMutation
- Fix createUlid to use monotonicFactory for reliable listSessions sort tiebreaker
- Extend outline system prompt with setting + characters context
- Add dexie dependency to packages/ai
- 188 tests passing (core 47, ui 5, editor 30, ai 71, exporters 22, web 13)
2026-10-29 07:31:25 -05:00

29 lines
851 B
TypeScript

import { monotonicFactory } from "ulid";
const ULID_REGEX = /^[0-7][0-9A-HJKMNP-TV-Z]{25}$/;
// Monotonic factory: guarantees that successive calls produce ULIDs that sort
// in creation order even within the same millisecond. This is important for
// tiebreakers that rely on ULID ordering (e.g. reverse-chronological lists).
const monotonicUlid = monotonicFactory();
/** Generate a monotonic ULID. */
export function createUlid(): string {
return monotonicUlid();
}
/** Validate a ULID string. */
export function isUlid(value: string): boolean {
return ULID_REGEX.test(value);
}
/**
* Assert a value is a ULID, throwing a clear error otherwise.
* Used by the server to reject malformed IDs at the boundary.
*/
export function assertUlid(value: string): void {
if (!isUlid(value)) {
throw new Error(`Invalid ULID: ${value}`);
}
}