/** * Pure helpers that translate SDK event shapes (`ToolCallEvent`, * `ToolResultEvent`, session lifecycle events) into the runtime's input * envelopes. Kept side-effect-free so they can be exercised in isolation * and so the dispatch handlers in `register-adapter.ts` stay focused on * orchestration rather than shape massaging. * * Extracted from `adapter.ts` as part of the P0/P1 refactor; behaviour is * unchanged. */ import type { ToolCallEvent, ToolResultEvent } from "@earendil-works/pi-coding-agent"; import type { ToolExecuteAfterInput, ToolExecuteBeforeInput, ToolExecuteBeforeOutput } from "../core/runtime.js"; /** Build the `tool.execute.before` input envelope from a PI `tool_call`. */ export declare function mapToolCallToBeforeInput(event: ToolCallEvent, sessionId: string): ToolExecuteBeforeInput; /** Build the `tool.execute.before` output envelope (carries the live args). */ export declare function mapToolCallToBeforeOutput(event: ToolCallEvent): ToolExecuteBeforeOutput; /** * Overlay replacement arguments from an `action: modify` hook on the live tool * input. Shallow merge: a replacement key wins, untouched keys survive, and an * empty revision is a no-op. */ export declare function mergeToolArgs(current: Record, revision: Record): Record; /** * Build the `tool.execute.after` input envelope from a PI `tool_result`. * * OMP 17's unified `edit` tool accepts hashline/apply-patch text under * `input`, while its successful result carries authoritative paths and * operations in `details`. Translate those details into the existing * direct/multi-edit argument shapes so the core path mapper can preserve * file.changed semantics. Pi events do not expose `details` and retain their * legacy input shape unchanged. */ export declare function mapToolResultToAfterInput(event: ToolResultEvent, sessionId: string): ToolExecuteAfterInput; /** Envelope for the runtime `session.idle` dispatch. */ export declare function buildSessionIdleEvent(sessionId: string): { event: { type: "session.idle"; properties: { sessionID: string; }; }; }; /** Envelope for the runtime `session.created` dispatch. */ export declare function buildSessionCreatedEvent(sessionId: string): { event: { type: "session.created"; properties: { info: { id: string; }; }; }; }; /** * Envelope for the runtime `session.deleted` dispatch. P1-4: we forward the * SDK's optional `reason` field on the envelope so hook authors can tell a * graceful shutdown apart from PI tearing the session down for /new, /resume, * /fork, or /reload. */ export declare function buildSessionDeletedEvent(sessionId: string, reason: string | undefined): { event: { type: "session.deleted"; properties: { info: { id: string; }; reason?: string; }; }; }; /** Read a string `reason` field from any SDK session-lifecycle event, tolerating absence. */ export declare function extractReason(event: { reason?: unknown; } | undefined): string | undefined;