import { api } from './api' import type { StreamEvent } from './contracts' /** Read the durable record in bounded pages; callers own cancellation and projection. */ export async function loadRunEvents(conversationId: string, runId: string, signal: AbortSignal): Promise { const events: StreamEvent[] = [] let after = 0 while (true) { const page = await api.runEventsPage(conversationId, runId, after, signal) const rows = page.events ?? [] events.push(...rows) if (rows.length < 500) return events const next = rows[rows.length - 1].seq if (next <= after) throw new Error('process event cursor did not advance') after = next } }