/** * PendingAsks — in-memory registry of in-flight `ask_user` MCP tool calls. * * The MCP tool registers a Promise here keyed by `ask_id`, then awaits it. * When a `choice_response` ServerFrame arrives, the corresponding entry is * settled. If the user sends a new message while an ask is in flight, the * entry is cancelled (`cancelByConversation`) so the SDK turn can wind down. * * Late-click semantics: an ask's "history" outlives its pending promise. * After cancellation the promise is gone, but the history (options + * original IncomingMessage) is kept so a later click can be synthesized * into a normal user message and pushed back through the agent pipeline. * History entries are garbage-collected on a TTL (default 7 days, matching * the bot-app `AskTrackerStore` TTL). */ import type { ChoiceResponseFrame, ChoiceOption } from './types.js'; import type { IncomingMessage } from '../types.js'; /** Reasons used in local-server-internal Promise rejection. Not on the wire. */ export type LocalCancelReason = 'superseded' | 'query_ended' | 'shutdown'; /** What the awaiting MCP tool sees when a Promise settles. */ export type AskResolution = { kind: 'answered'; selectedIds: string[]; titles: string[]; } | { kind: 'wire_cancel'; reason: 'expired' | 'user_cancel'; } | { kind: 'local_cancel'; reason: LocalCancelReason; }; interface HistoryEntry { readonly options: ChoiceOption[]; readonly multiSelect: boolean; readonly conversationKey: string; readonly incoming: IncomingMessage; readonly registeredAt: number; readonly expiresAt: number; } export interface RegisterArgs { options: ChoiceOption[]; multiSelect: boolean; conversationKey: string; incoming: IncomingMessage; } export declare class PendingAsks { private readonly pending; private readonly history; private cleanupTimer; /** Register a new ask and return a Promise that settles when the user responds (or cancels). */ register(askId: string, args: RegisterArgs, ttlMs?: number): Promise; /** Lookup history for an ask (used by the late-click handler). */ lookupHistory(askId: string): HistoryEntry | undefined; /** Remove a history entry (call after consuming a late click). */ deleteHistory(askId: string): void; /** * Try to settle a pending ask with a wire response. Returns `true` if a * pending promise was settled, `false` if there was none (late click). * Always removes the pending entry; history is left in place. */ settle(frame: ChoiceResponseFrame): boolean; /** Cancel a specific pending ask (history kept for late clicks). */ cancel(askId: string, reason: LocalCancelReason): boolean; /** Cancel every pending ask for a given conversation (history kept). */ cancelByConversation(conversationKey: string, reason: LocalCancelReason): number; /** Cancel everything (e.g. on shutdown). Both pending and history are cleared. */ cancelAll(reason: LocalCancelReason): number; startCleanup(): void; dispose(): void; } export {};