Open History to see the last commit
1/** Numeric cache-collapse cursors, independent of shape read-boundary proofs.
2 * Follows the pinned reference server's 20-second intervals and 1–3600-second
3 * collision jitter, without importing its Node/LMDB runtime into the Function.
4 */
5export function generateResponseCursor(clientCursor?: string): string {
6 const epoch = Date.UTC(2024, 9, 9)
7 const current = BigInt(Math.max(0, Math.floor((Date.now() - epoch) / 20_000)))
8 const previous =
9 clientCursor && /^\d+$/.test(clientCursor) ? BigInt(clientCursor) : -1n
10 if (previous < current) return String(current)
11 const jitterSeconds = 1 + Math.floor(Math.random() * 3600)
12 return String(previous + BigInt(Math.ceil(jitterSeconds / 20)))
13}