import type { SessionBackendEvent } from "./pi-events.js"; import type { SearchIndex } from "./search-index.js"; import type { Storage } from "./storage.js"; /** * Apply search-index side effects for a runtime event. * * Both Oppi-owned SDK sessions and pi-tui mirrored sessions ingest the same Pi * agent event stream. Keep indexing policy here so new runtimes do not need to * remember route-specific side effects. */ export function updateSearchIndexForSessionEvent( searchIndex: SearchIndex | null | undefined, storage: Pick, sessionId: string, event: SessionBackendEvent, ): void { if (!searchIndex) { return; } const session = storage.getSession(sessionId); if (session?.ephemeral) { searchIndex.deleteSession(sessionId); return; } if (event.type === "agent_end") { searchIndex.markForReindex(sessionId); searchIndex.flushForSession(sessionId); } }