Load the lead's scrollback 50 turns at a time
This commit is contained in:
+34
-3
@@ -1,4 +1,4 @@
|
||||
import { get, put, subscribe, type AgentSession, type ByreEvent, type Focus, type InboxItem, type Project, type Snapshot, type Task, type TaskTab, type User } from "./api.js";
|
||||
import { get, put, subscribe, type AgentSession, type ByreEvent, type Focus, type InboxItem, type Project, type Schemas, type Snapshot, type Task, type TaskTab, type User } from "./api.js";
|
||||
import { notifyInbox, notifyTurn } from "./notifications.js";
|
||||
|
||||
export type Topic =
|
||||
@@ -441,8 +441,39 @@ export function selectTask(taskId: string | undefined): void {
|
||||
notify("selection");
|
||||
}
|
||||
|
||||
export function startLeadStream(): void {
|
||||
subscribe(0, { lead: true }, leadFeed.push, () => undefined, () => leadFeed.load([]));
|
||||
const leadPage = 50;
|
||||
let leadMore = false;
|
||||
|
||||
async function fetchLeadTail(): Promise<Schemas["EventPage"]> {
|
||||
for (;;) {
|
||||
try {
|
||||
return await get("/api/me/lead/events", { query: { turns: leadPage } });
|
||||
} catch (err) {
|
||||
console.error("load lead history", err);
|
||||
await new Promise((resolve) => setTimeout(resolve, 2_000));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export async function startLeadStream(): Promise<void> {
|
||||
const page = await fetchLeadTail();
|
||||
leadMore = page.more;
|
||||
subscribe(page.events.at(-1)?.seq ?? 0, { lead: true }, leadFeed.push, () => undefined, () => leadFeed.load(page.events));
|
||||
}
|
||||
|
||||
export function leadHasOlder(): boolean {
|
||||
return leadFeed.ready && leadMore;
|
||||
}
|
||||
|
||||
export async function loadOlderLead(): Promise<ByreEvent[]> {
|
||||
const first = leadFeed.events[0];
|
||||
if (!first) {
|
||||
return [];
|
||||
}
|
||||
const page = await get("/api/me/lead/events", { query: { before: first.seq, turns: leadPage } });
|
||||
leadMore = page.more;
|
||||
leadFeed.events.unshift(...page.events);
|
||||
return page.events;
|
||||
}
|
||||
|
||||
export function handleEvent(ev: ByreEvent): void {
|
||||
|
||||
Reference in New Issue
Block a user