/** * session-events.ts — Event types and stream parser for deriving granular session events. * * Monitors an AgentSession via its subscribe() callback, compares message snapshots * to detect deltas, and emits higher-level events (token, tool_start, tool_end, etc.) * that the live TUI components consume. */ import type { AgentSession } from "@mariozechner/pi-coding-agent"; import type { AgentRecord } from "./types.js"; export type AgentSessionEvent = { type: "token"; text: string; } | { type: "tool_start"; toolName: string; toolUseId: string; args: unknown; timestamp: number; } | { type: "tool_end"; toolName: string; toolUseId: string; output: string; timestamp: number; } | { type: "turn_end"; turnNumber: number; } | { type: "status"; status: string; } | { type: "usage"; input: number; output: number; total: number; } | { type: "error"; error: Error; } | { type: "message"; message: unknown; }; export declare class SessionEventStream { private session; private record; private sessionUnsubscribe; private callbacks; private prevMessages; private prevStatus; private toolCallTracker; private nextCallId; constructor(session: AgentSession, record: AgentRecord); /** * Register a callback for session events. * Returns an unsubscribe function. */ subscribe(callback: (event: AgentSessionEvent) => void): () => void; /** * Broadcast an event to all subscribers. */ private emit; /** * Poll the session for message changes and emit derived events. * Called on each session.subscribe() tick. */ private pollChanges; /** * Inject a user message into the running session. * Stub — will be wired to session.sendMessage() in Phase 5. * TODO Phase 5: Wire to session.sendMessage() */ inject(_text: string): void; /** * Interrupt the running agent. * Stub — will be wired to abort controller in Phase 5. * TODO Phase 5: Wire to abort controller */ interrupt(): void; /** * Clean up subscriptions and internal state. */ close(): void; }