import type { AgentPromptOptions, AgentResponse, AgentStreamResponse } from './types.js'; import type { QueueDispatch, QueueBroadcast } from './queue-adapter.js'; /** * Optional shape on the agent reference — when set, the queued job uses * `stream()` to broadcast incremental progress, otherwise falls back to * `prompt()`. Declared conditionally so `agent.queue('...')` still works * without requiring `stream()` on every wrapper. */ type StreamableAgent = { prompt(input: string, options?: AgentPromptOptions): Promise; stream?(input: string, options?: AgentPromptOptions): AgentStreamResponse; }; export interface BroadcastOptions { /** * Event name prefix on broadcast envelopes. Defaults to no prefix — events * are emitted as `chunk`, `done`, `error`. Set to e.g. `'agent.'` to namespace * (`agent.chunk`, `agent.done`, `agent.error`) when the channel carries other * unrelated events. */ eventPrefix?: string; } /** * Queued AI prompt builder. * Created via `agent.queue('prompt')`. * * @example * await agent.queue('Analyze this report') * .onQueue('ai') * .then(response => console.log(response.text)) * .catch(err => console.error(err)) * .send() * * @example Broadcast progress to a channel as the job runs * await new SupportAgent() * .queue('Help with refund request') * .broadcast(`user.${userId}.support`) * .send() * * // Subscribers on `user.${userId}.support` receive: * // { event: 'chunk', data: } // one per stream chunk * // { event: 'done', data: } // final result * // { event: 'error', data: { message } } // on failure */ export declare class QueuedPromptBuilder { private readonly agentRef; private readonly input; private readonly options?; private _queue; private _delay; private _thenFn; private _catchFn; private _broadcastChannel; private _broadcastEventPrefix; constructor(agentRef: StreamableAgent, input: string, options?: AgentPromptOptions | undefined); /** Set the queue name */ onQueue(name: string): this; /** Set a delay before the job runs */ delay(ms: number): this; /** Callback when the prompt succeeds */ then(fn: (response: AgentResponse) => void | Promise): this; /** Callback when the prompt fails */ catch(fn: (error: unknown) => void | Promise): this; /** * Stream the agent's progress to a broadcast channel as the job runs. * * When set, the queued job uses `agent.stream()` instead of `prompt()` and * pushes each chunk to `channel` via the registered broadcast adapter * (`configureAiQueue({ broadcast })`). Events: * * - `chunk` (per `StreamChunk` from the agent) * - `done` (the final `AgentResponse`) * - `error` (`{ message }` if the run fails) * * Requires a broadcast adapter registered via `configureAiQueue({ broadcast })` * and reachable from the worker process. In the typical single-process dev * setup (one process running both web + queue worker) this works out of the * box. If your queue worker is a separate process from the broadcast server, * you'll need a pub/sub bridge (Redis, Reverb, etc.) — outside the scope of v1. */ broadcast(channel: string, opts?: BroadcastOptions): this; /** Dispatch the job to the queue */ send(): Promise; } type DispatchFn = QueueDispatch; type BroadcastFn = QueueBroadcast; /** * Register the queue (and optional broadcast) adapter that backs * `agent.queue('...').send()` and `.broadcast(channel)`. * * Call once at app startup. Returns a restore function that reinstates the * previously-registered adapters (handy in tests). * * @example * configureAiQueue({ * dispatch: (fn, opts) => myQueue.push(fn, opts), * broadcast: (channel, event, data) => myBus.emit(channel, event, data), * }) */ export declare function configureAiQueue(config: { dispatch: QueueDispatch; broadcast?: QueueBroadcast | null; }): () => void; /** * Test-only seam — swap the dispatch + broadcast loaders for fakes so tests can * exercise the queued-job flow without booting Queue / Broadcast providers. * * The `_` prefix and explicit `ForTests` suffix are deliberate: these hooks * exist for `src/queue-job.test.ts`, not for app code. Production callers * should never import these. */ export declare function _setQueueJobLoadersForTests(opts: { dispatch?: () => Promise; broadcast?: () => Promise; }): () => void; export {}; //# sourceMappingURL=queue-job.d.ts.map