/** * Message delivery engine — send, broadcast, and read. * Spec: §4.7 — Delivery */ import type { Labels } from "@pi-orca/core"; import { type MessageFile } from "./store.js"; export interface SendParams { to: string; title: string; body: string; from: string; labels?: Labels; projectSlug?: string; } export interface BroadcastParams { title: string; body: string; from: string; labels?: Labels; projectSlug?: string; } /** * Send a message to a specific recipient session. * * Validates recipient exists in registry, writes message to store, * creates inbox ref for recipient. * * @param params - Send parameters * @returns Result with messageId and status */ export declare function send(params: SendParams): Promise<{ messageId: string; status: string; } | { success: false; error: string; }>; /** * Broadcast a message to all registered sessions except the sender. * * Writes message once with to: "broadcast", then creates inbox refs * for each recipient. * * @param params - Broadcast parameters * @returns Result with messageId and recipient count */ export declare function broadcast(params: BroadcastParams): Promise<{ messageId: string; recipientCount: number; }>; /** * Read messages from a session's inbox (consumes refs). * * @param sessionId - Session ID to read inbox for * @param projectSlug - Optional project slug * @returns Messages in chronological order */ export declare function read(sessionId: string, projectSlug?: string): Promise; export interface DeliverPendingResult { /** Number of messages actually injected and consumed. */ delivered: number; } export interface DeliverPendingTarget { sessionId: string; projectSlug?: string; } /** * Peek the recipient's inbox, format pending entries into a single user * prompt, hand the text to the provided `inject` callback, and consume the * refs we just delivered. Wrapped in a per-session mutex so the idle-poll * and the pre-LLM `context` hook can both call this without racing. * * The two paths must inject differently: * - **idle-poll** (agent not running) → `pi.sendUserMessage(text)`, which * starts a new turn just as if the user had typed. * - **context hook** (fires *while* the agent is mid-turn) → * `event.messages.push({ role: "user", content: [{ type: "text", text }] })`. * Calling `sendUserMessage` here throws "Agent is already processing" * because pi is in the middle of building the next LLM request. * * `source` is a tag for log lines so we can tell which path delivered each * batch. */ export declare function deliverPendingMessages(session: DeliverPendingTarget, source: string, inject: (text: string) => void | Promise): Promise; //# sourceMappingURL=delivery.d.ts.map