Something went wrong. Try again.
Original-language reader for Kant, Aristotle & more: select any passage to gloss, translate, or hear it read aloud, with exact citations.
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132/** * The AI cache key (DATA-ARCHITECTURE.md "Identity & keys") — FROZEN. * * cacheKey = SHA-256 hex of `quote + " " + citation + " " + targetLang` * * where `quote` is the selection normalized to word boundaries (§1.5), * `citation` is the selection's start citation (§1.4), and `targetLang` is the * reader's gloss/translation target language (default "en") — so an English vs. * a French/Spanish translation of the same span never collide. This identity is * shared by `aiCache.key` and the R2 TTS object key, so it must never change * without orphaning both, and must stay byte-identical to `convex/cacheKey.ts`. * Web Crypto runs in the browser, Convex's V8 runtime, and Bun alike. */export async function cacheKey( quote: string, citation: string, targetLang: string,): Promise<string> { const bytes = new TextEncoder().encode(`${quote} ${citation} ${targetLang}`) const digest = await crypto.subtle.digest("SHA-256", bytes) return Array.from(new Uint8Array(digest), (b) => b.toString(16).padStart(2, "0"), ).join("")}
/** Length of the `?art=` hash prefix used for shareable artifact links (§12). */export const ART_HASH_PREFIX_LEN = 12
export function artHashPrefix(key: string): string { return key.slice(0, ART_HASH_PREFIX_LEN)}