/** * UsageRollup — per-session/per-harness/per-tool token + cost tracker * driven by ProviderRuntimeEvents from the EventBus. * * The engine has no centralized usage rollup today. Each surface that * needs cost/latency information re-derives it from raw subprocess * output. With the event contract + bus in place, one subscriber can * compute everything once and serve it to every consumer (UI Billing * pane, /api/usage, telemetry, audit). * * Subscribes to two event types from the bus: * - usage.updated → input/output/reasoning tokens + cost * - tool.call.completed → per-tool latency timeline * * Plus state-machine events for session lifecycle bookkeeping: * - session.created, session.shutdown * * Snapshots are exposed via: * - sessionUsage(sessionId) → UsageSnapshot for one session * - harnessTotals(harnessId) → aggregate across sessions * - toolTimeline(sessionId, toolName) → ordered latencies * - all() → full snapshot for export */ import type { EventBus, EventBusSubscription } from "./event-bus.js"; import type { HarnessId, SessionId, ToolCallId } from "./contracts/ids.js"; export interface UsageSnapshot { sessionId: SessionId; harnessId: HarnessId; inputTokens: number; outputTokens: number; reasoningTokens: number; estimatedCostUsd: number; toolCallCount: number; toolErrorCount: number; totalToolMs: number; startedAt?: string; endedAt?: string; lastUpdatedAt: string; } export interface ToolLatency { toolCallId: ToolCallId; tool: string; ok: boolean; elapsedMs: number; at: string; } export interface HarnessTotals { harnessId: HarnessId; sessionCount: number; inputTokens: number; outputTokens: number; reasoningTokens: number; estimatedCostUsd: number; toolCallCount: number; toolErrorCount: number; } export declare class UsageRollup { private readonly bus?; private readonly sessions; private readonly toolLatencies; private subscription; constructor(bus?: EventBus | undefined); /** Subscribe (or re-subscribe) to a bus. Returns the subscription handle. */ subscribe(bus: EventBus): EventBusSubscription; /** Stop subscribing. The rollup keeps its accumulated data. */ detach(): void; /** Drop all accumulated data. Useful for tests. */ reset(): void; consume(event: import("./contracts/provider-runtime.js").ProviderRuntimeEvent): void; private toolNames; private findToolName; sessionUsage(sessionId: SessionId): UsageSnapshot | null; toolTimeline(sessionId: SessionId, toolName?: string): ToolLatency[]; harnessTotals(harnessId: HarnessId): HarnessTotals; all(): UsageSnapshot[]; }