Open History to see the last commit
1import type { OrchestrationV2SearchThreadInput, RunId } from "@t3tools/contracts";
2
3export type ThreadFindStart = NonNullable<OrchestrationV2SearchThreadInput["start"]>;
4export type ThreadFindPositionReader = (query: string) => ThreadFindStart | undefined;
5
6export interface ThreadFindMatch {
7 readonly entryId: string;
8 readonly runId: RunId | null;
9 readonly occurrence: number;
10}
11
12function clampThreadFindIndex(index: number, total: number): number {
13 if (total <= 0 || !Number.isFinite(index) || index < 0) return 0;
14 return Math.min(Math.trunc(index), total - 1);
15}
16
17export function stepThreadFindIndex(index: number, total: number, delta: number): number {
18 if (total <= 0) return 0;
19 const clamped = clampThreadFindIndex(index, total);
20 return (((clamped + delta) % total) + total) % total;
21}
22
23export function formatThreadFindCount(index: number, total: number): string {
24 return total <= 0 ? "0/0" : `${clampThreadFindIndex(index, total) + 1}/${total}`;
25}