import { RequiredConfig } from "./config"; import { StorageClient } from "./storage"; import { FalStream, StreamingConnectionMode } from "./streaming"; import { EndpointType, InputType, OutputType } from "./types/client"; import { CompletedQueueStatus, InQueueQueueStatus, QueueStatus, Result, RunOptions } from "./types/common"; export type QueuePriority = "low" | "normal"; export type QueueStatusSubscriptionOptions = QueueStatusOptions & QueueModeOptions & Omit; type QueueModeOptions = { mode?: "polling"; /** * The interval (in milliseconds) at which to poll for updates. * If not provided, a default value of `500` will be used. * * This value is ignored if `mode` is set to `streaming`. */ pollInterval?: number; } | { mode: "streaming"; /** * The connection mode to use for streaming updates. It defaults to `server`. * Set to `client` if your server proxy doesn't support streaming. */ connectionMode?: StreamingConnectionMode; }; type QueueCommonSubscribeOptions = { /** * The mode to use for subscribing to updates. It defaults to `polling`. * You can also use client-side streaming by setting it to `streaming`. * * **Note:** Streaming is currently experimental and once stable, it will * be the default mode. * * @see pollInterval */ mode?: "polling" | "streaming"; /** * Callback function that is called when a request is enqueued. * @param requestId - The unique identifier for the enqueued request. */ onEnqueue?: (requestId: string) => void; /** * Callback function that is called when the status of the queue changes. * @param status - The current status of the queue. */ onQueueUpdate?: (status: QueueStatus) => void; /** * If `true`, the response will include the logs for the request. * Defaults to `false`. */ logs?: boolean; /** * The timeout (in milliseconds) for the request. If the request is not * completed within this time, the subscription will be cancelled. * * Keep in mind that although the client resolves the function on a timeout, * and will try to cancel the request on the server, the server might not be * able to cancel the request if it's already running. * * Note: currently, the timeout is not enforced and the default is `undefined`. * This behavior might change in the future. */ timeout?: number; /** * Server-side request timeout in seconds. Limits total time spent waiting * before processing starts (includes queue wait, retries, and routing). * Does not apply once the application begins processing. * * This will be sent as the `x-fal-request-timeout` header. */ startTimeout?: number; /** * The URL to send a webhook notification to when the request is completed. * @see WebHookResponse */ webhookUrl?: string; /** * The priority of the request. It defaults to `normal`. * This will be sent as the `x-fal-queue-priority` header. * * @see QueuePriority */ priority?: QueuePriority; /** * Additional HTTP headers to include in the submit request. * Note: `priority`, `hint`, `startTimeout`, and `objectLifecycle` will override the following headers: * - `x-fal-queue-priority` * - `x-fal-runner-hint` * - `x-fal-request-timeout` * - `x-fal-object-lifecycle-preference` */ headers?: Record; }; /** * Options for subscribing to the request queue. */ export type QueueSubscribeOptions = QueueCommonSubscribeOptions & QueueModeOptions; /** * Options for submitting a request to the queue. */ export type SubmitOptions = RunOptions & { /** * The URL to send a webhook notification to when the request is completed. * @see WebHookResponse */ webhookUrl?: string; /** * The priority of the request. It defaults to `normal`. * This will be sent as the `x-fal-queue-priority` header. * * @see QueuePriority */ priority?: QueuePriority; /** * A hint for the runner to use when processing the request. * This will be sent as the `x-fal-runner-hint` header. */ hint?: string; /** * Server-side request timeout in seconds. Limits total time spent waiting * before processing starts (includes queue wait, retries, and routing). * Does not apply once the application begins processing. * * This will be sent as the `x-fal-request-timeout` header. */ startTimeout?: number; /** * Additional HTTP headers to include in the submit request. * * Note: `priority`, `hint`, `startTimeout`, and `objectLifecycle` will override the following headers: * - `x-fal-queue-priority` * - `x-fal-runner-hint` * - `x-fal-request-timeout` * - `x-fal-object-lifecycle-preference` */ headers?: Record; }; type BaseQueueOptions = { /** * The unique identifier for the enqueued request. */ requestId: string; /** * The signal to abort the request. */ abortSignal?: AbortSignal; }; export type QueueStatusOptions = BaseQueueOptions & { /** * If `true`, the response will include the logs for the request. * Defaults to `false`. */ logs?: boolean; }; export type QueueStatusStreamOptions = QueueStatusOptions & { /** * The connection mode to use for streaming updates. It defaults to `server`. * Set to `client` if your server proxy doesn't support streaming. */ connectionMode?: StreamingConnectionMode; }; /** * Represents a request queue with methods for submitting requests, * checking their status, retrieving results, and subscribing to updates. */ export interface QueueClient { /** * Submits a request to the queue. * * @param endpointId - The ID of the function web endpoint. * @param options - Options to configure how the request is run. * @returns A promise that resolves to the result of enqueuing the request. */ submit(endpointId: Id, options: SubmitOptions>): Promise; /** * Retrieves the status of a specific request in the queue. * * @param endpointId - The ID of the function web endpoint. * @param options - Options to configure how the request is run. * @returns A promise that resolves to the status of the request. */ status(endpointId: string, options: QueueStatusOptions): Promise; /** * Subscribes to updates for a specific request in the queue using HTTP streaming events. * * @param endpointId - The ID of the function web endpoint. * @param options - Options to configure how the request is run and how updates are received. * @returns The streaming object that can be used to listen for updates. */ streamStatus(endpointId: string, options: QueueStatusStreamOptions): Promise>; /** * Subscribes to updates for a specific request in the queue using polling or streaming. * See `options.mode` for more details. * * @param endpointId - The ID of the function web endpoint. * @param options - Options to configure how the request is run and how updates are received. * @returns A promise that resolves to the final status of the request. */ subscribeToStatus(endpointId: string, options: QueueStatusSubscriptionOptions): Promise; /** * Retrieves the result of a specific request from the queue. * * @param endpointId - The ID of the function web endpoint. * @param options - Options to configure how the request is run. * @returns A promise that resolves to the result of the request. */ result(endpointId: Id, options: BaseQueueOptions): Promise>>; /** * Cancels a request in the queue. * * @param endpointId - The ID of the function web endpoint. * @param options - Options to configure how the request * is run and how updates are received. * @returns A promise that resolves once the request is cancelled. * @throws {Error} If the request cannot be cancelled. */ cancel(endpointId: string, options: BaseQueueOptions): Promise; } type QueueClientDependencies = { config: RequiredConfig; storage: StorageClient; }; export declare const createQueueClient: ({ config, storage, }: QueueClientDependencies) => QueueClient; export {};