/** * Steps `send` and `ask` share when they hand a message to another session: * registering the relay before the message goes out, and posting the message * with the PROMPT_WAITING refusal reported the same way. * * Kept in its own module (not in send.ts / ask.ts) because tests mock those * modules' internals; what differs per command is passed in as arguments. */ import type { ChatMessage } from '../types/api-responses'; import { ApiClient } from '../utils/api-client'; import type { CommandTarget } from './command-target'; import { type RegisteredRelay, type RelayEndpointArg } from './relays'; /** * Code the send API returns when the session is blocked on a prompt (Issue * #1708). Mirrors PROMPT_WAITING_CODE in src/lib/session/prompt-waiting-guard.ts; * duplicated rather than imported so the CLI bundle does not pull the server's * tmux/detection graph in for one string. */ export declare const PROMPT_WAITING_CODE = "PROMPT_WAITING"; export interface RegisterRelayForMessageInput { worktreeId: string; /** The raw `--reply-to` value (callers decide the default). */ replyTo: string; instance?: string; agent?: string; allowRelayChain?: boolean; /** * Issue #3983: the client the two endpoints are resolved with (`ask` passes * its `--timeout`-bounded one). Defaults to `client`. The relay POST itself * always goes through `client`: it creates state, and cutting it would leave * "was the relay opened?" unanswered — the same reason `/send` is not cut. */ resolveClient?: ApiClient; /** Issue #4133: already resolved by {@link resolveRelayEndpoints}, so not resolved again. */ endpoints?: RelayEndpoints; /** Issue #4133: runs when the relay could not be opened, before the command ends. */ onFailure?: () => Promise; } /** The two ends of a relay, as the ledger stores them. */ export interface RelayEndpoints { from: RelayEndpointArg; to: RelayEndpointArg; } /** * Both ends of a `--reply-to`. Only reads. Exits 2 when either cannot be named, so a * caller with something to clean up afterwards calls this before making it (Issue #4133). */ export declare function resolveRelayEndpoints(client: ApiClient, input: Pick): Promise; /** Resolve both endpoints and open the relay; returns its id and whether it is bound. */ export declare function registerRelayForMessage(client: ApiClient, input: RegisterRelayForMessageInput): Promise; export interface PostMessageOptions { /** * The relay this message opened. When it is bound, its id is put on the * send (`relayId`) and it is withdrawn only on a confirmed `not_sent`. */ relay?: RegisteredRelay; /** * Runs first when the post fails, before the relay is cancelled and before any * exit. Issue #4116: told the failure, and a bound relay's outcome (null unbound). */ onFailure?: (error: unknown, outcome: FailedSendOutcome | null) => Promise; /** Printed (after `Error: `) when PROMPT_WAITING carried no message body. */ promptWaitingFallback: string; /** The resolved target the send addressed; the hints name it (Issue #3982). */ target: CommandTarget; } /** What the send did, as far as a bound relay is concerned (Issue #3957). */ type BoundSendOutcome = 'sent' | 'not_sent' | 'unknown' | 'conflict'; /** A bound relay's outcome once the send is known to have failed. */ export type FailedSendOutcome = Exclude; /** * What to tell the sender about resending a failed send, from the server's * `sendOutcome` on the error (Issue #3992). Issue #4011: the route puts it on * every failure recorded as the send's attempt, bound relay or not. Null when * the error carries none (a 400, an older server) or says `sent`. * * @param target - The resolved target, so the `capture` reads the pane the * message went to (Issue #3982); omitted, the hint names no target */ export declare function describeFailedSendOutcome(error: unknown, worktreeId: string, target?: CommandTarget): string | null; /** * Post the message; on failure cancel the relay and report PROMPT_WAITING. * * Issue #3957: a bound relay is withdrawn only when nothing reached the worker * (`not_sent`). When that cannot be said the relay is left open, the message * is NOT resent, and stderr names the relay and how to look it up. * * @returns The send API's body (Issue #3957: `ask` reads `turnOpenAtSend`) */ export declare function postMessage(client: ApiClient, worktreeId: string, sendBody: Record, options: PostMessageOptions): Promise; export {}; //# sourceMappingURL=message-dispatch.d.ts.map