Skip to content

armgit / pibot

Public Imported from GitHub
0

Open-source, local-first AI agent team for your desktop: multi-agent group chats, computer use, browser, MCP, routines and approvals. macOS, Windows, Linux + Android. Built on pi.

804 B
Raw Blame
import { setImmediate } from "node:timers/promises";
import type { RoutineRunStatus } from "@pibot/protocol";
import type { RoutineRunsRepo } from "../../store/index.ts";

// Cursor scope excludes mutable status, so settling a page's last record cannot truncate the scan.
export async function* routineRunPages(
  runs: RoutineRunsRepo,
  status: RoutineRunStatus,
  signal: AbortSignal,
  routineId?: string,
) {
  let before: string | undefined;
  for (;;) {
    signal.throwIfAborted();
    const page = runs.page(status, { before, limit: 200 }, routineId);
    for (const [i, record] of page.entries()) {
      if (i % 32 === 0) await setImmediate(undefined, { signal });
      signal.throwIfAborted();
      yield record;
    }
    if (page.length < 200) return;
    before = page.at(-1)?.id;
  }
}