/** * PiNotificationSessionClient — ISessionClient wrapper that adds parent * notification support for external sessions on the Pi platform. * * Wraps a PiProcessSessionAdapter (which manages child process sessions) * and adds the ability to send messages to external (parent) sessions via * Pi's ExtensionAPI (`pi.sendUserMessage`). * * Replaces the brittle JS Proxy previously used in `pi-extension.ts`. * The class is independently testable and has no dependency on the * extension entry point. * * @module */ import type { Logger } from "tslog"; import type { ILogObj } from "tslog"; import type { ISessionClient } from "../../ports/session-client.ts"; import type { IEventBridge } from "../../ports/event-bridge.ts"; import type { PiProcessSessionAdapter } from "./process-session.ts"; import type { SessionInfo, Message, FileDiff, Todo, SessionStatus } from "../../types.ts"; /** * Wraps a PiProcessSessionAdapter to add Pi notification support. * * All methods delegate to the inner adapter except `prompt` and * `promptSync`, which first check whether the inner adapter manages * the session (via its `processes` map). If it does, the operation * is delegated; otherwise, `prompt` uses `pi.sendUserMessage` and * `promptSync` returns `null`. */ export declare class PiNotificationSessionClient implements ISessionClient { private readonly inner; private readonly pi; private readonly log; private readonly eventBridge?; constructor(inner: PiProcessSessionAdapter, pi: any, log: Logger, eventBridge?: IEventBridge); list(directory?: string): Promise; get(id: string, directory?: string): Promise; messages(id: string, options?: { directory?: string; limit?: number; }): Promise; children(id: string, directory?: string): Promise; todo(id: string, directory?: string): Promise; diff(id: string, options?: { directory?: string; messageID?: string; }): Promise; fork(id: string, options?: { directory?: string; messageID?: string; }): Promise; status(id: string, directory?: string): Promise; create(options: { directory: string; agent?: string; parentID?: string; }): Promise; abort(id: string): Promise; compact(id: string): Promise; /** * Prompt a session. * * For sessions managed by the inner adapter (present in `processes`), * delegates to `inner.prompt()`. For external (parent) sessions, sends * the message via `pi.sendMessage()` with `triggerTurn` derived from * `options.noReply` (`triggerTurn = !noReply`). Falls back to * `pi.sendUserMessage()` on legacy Pi versions where `pi.sendMessage` * is unavailable. * * `noReply: true` produces `{ triggerTurn: false, deliverAs: "followUp" }` * — the message is delivered silently and immediately without waking * the session. `noReply: false` produces `{ triggerTurn: true, * deliverAs: "followUp" }` — the message is delivered and the session * wakes to process it. * * When no messaging API is available or the call throws, a warning is * logged and a `session.error` canonical event is emitted (when * an event bridge is configured) so the dispatch manager can detect * the stuck state. */ prompt(id: string, options: { parts: Array<{ type: string; text: string; }>; noReply?: boolean; system?: string; agent?: string; model?: { providerID: string; modelID: string; }; /** Set by the loop coordinator via DispatchAdapter.injectNote(). */ fromLoop?: boolean; }): Promise<{ id: string; } | null>; /** * Prompt a session synchronously. * * For sessions managed by the inner adapter (present in `processes`), * delegates to `inner.promptSync()`. For external sessions, returns * `null` since synchronous prompting is not supported via notification. */ promptSync(id: string, options: { parts: Array<{ type: string; text: string; }>; agent?: string; signal?: AbortSignal; }): Promise<{ parts: Array<{ type: string; text?: string; }>; } | null>; /** * Check whether the inner adapter has a managed process for the * given session ID. Uses the same private-field bypass pattern * as the original Proxy implementation. */ private _hasProcess; /** * Emit a `session.error` canonical event when notification fails. * * This is a fire-and-forget best-effort emission: any error from the * event bridge itself is swallowed (logged at debug level) so the * notification failure path always completes without throwing. * * When no event bridge is configured, this is a no-op. */ private _emitNotificationError; /** * Send a message to the parent session via Pi's ExtensionAPI. * * Uses `pi.sendMessage()` with `deliverAs: "followUp"` and the given * `triggerTurn` flag. With `triggerTurn: false` the message is appended * to the session state and emitted immediately without triggering a * model turn (silent immediate delivery); with `triggerTurn: true` the * session is woken to process the message. Falls back to * `pi.sendUserMessage()` (which always triggers a turn) on legacy Pi * versions where `pi.sendMessage` is unavailable. * * @param text - The message text to send * @param triggerTurn - Whether to trigger an agent turn after delivery */ private _sendMessage; } //# sourceMappingURL=notification-session.d.ts.map