import type { RuntimeEvent } from './events.js'; /** * Map of camelCase handler keys to their `RuntimeEvent.type` literal strings. * * Use this when you need the literal at runtime without typing the string yourself: * * ```ts * if (event.type === RuntimeEventKind.ToolStart) { ... } * ``` * * Prefer `onRuntimeEvent(...)` (or `session.on({ ... })`) for the common dispatch case. */ export declare const RuntimeEventKind: { readonly MessageDelta: "message.delta"; readonly MessageCompleted: "message.completed"; readonly ReasoningDelta: "reasoning.delta"; readonly ReasoningCompleted: "reasoning.completed"; readonly ToolStart: "tool.start"; readonly ToolUpdate: "tool.update"; readonly ToolEnd: "tool.end"; readonly TurnStarted: "turn.started"; readonly TurnCompleted: "turn.completed"; readonly TurnFailed: "turn.failed"; readonly TurnCancelled: "turn.cancelled"; readonly StatusChanged: "status.changed"; readonly SessionCommandsUpdated: "session.commands.updated"; readonly SessionConfigUpdated: "session.config.updated"; readonly SessionModesUpdated: "session.modes.updated"; readonly SessionModeUpdated: "session.mode.updated"; readonly SessionModelsUpdated: "session.models.updated"; readonly SessionModelUpdated: "session.model.updated"; readonly SessionUsageUpdated: "session.usage.updated"; readonly SessionPlanUpdated: "session.plan.updated"; readonly SessionError: "session.error"; }; type DotToCamel = S extends `${infer Head}.${infer Rest}` ? `${Head}${Capitalize>}` : S; /** * Per-variant handler map for `onRuntimeEvent` and `session.on(handlers)`. * * Generic over the event union so the same helper can dispatch the data-only * `RuntimeEvent` set or the full `RuntimeSessionEvent` set (which adds turn / * status events). Keys are camelCase, derived from the `dot.case` event types * (`message.delta` → `messageDelta`, `session.commands.updated` → * `sessionCommandsUpdated`). * * All entries are optional; unhandled variants fall through to the optional * `default` handler (or are ignored). * * ```ts * session.on({ * messageDelta: (e) => process.stdout.write(e.delta), * toolStart: (e) => process.stdout.write(`[${e.toolCallId}] ${e.title ?? e.name}\n`), * turnCompleted: (e) => process.stdout.write(`done: ${e.stopReason}\n`), * }); * ``` */ export type RuntimeEventHandlers = { [K in E['type'] as DotToCamel]?: (event: Extract) => R; } & { /** Invoked when no per-variant handler matched. */ default?: (event: E) => R; }; /** * Type-safe dispatcher for normalized events emitted by `RuntimeSession`. * * Replaces manual `switch (event.type) { case 'message.delta': ... }` with a * camelCase handler map. * * Returns the handler's return value, or `undefined` if no handler matched and no * `default` was provided. */ export declare function onRuntimeEvent(event: E, handlers: RuntimeEventHandlers): R | undefined; export {};