UNPKG

@fal-ai/client

Version:

The fal.ai client for JavaScript and TypeScript

59 lines 2.19 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.RUNNER_HINT_HEADER = exports.QUEUE_PRIORITY_HEADER = exports.REQUEST_TIMEOUT_TYPE_HEADER = exports.REQUEST_TIMEOUT_HEADER = exports.MIN_REQUEST_TIMEOUT_SECONDS = void 0; exports.validateTimeoutHeader = validateTimeoutHeader; exports.buildTimeoutHeaders = buildTimeoutHeaders; /** * Minimum allowed request timeout in seconds. * Matches the Python client's MIN_REQUEST_TIMEOUT_SECONDS. */ exports.MIN_REQUEST_TIMEOUT_SECONDS = 1; /** * Header name for server-side request timeout. */ exports.REQUEST_TIMEOUT_HEADER = "x-fal-request-timeout"; /** * Header name for timeout type (user vs infrastructure). */ exports.REQUEST_TIMEOUT_TYPE_HEADER = "x-fal-request-timeout-type"; /** * Header name for queue priority. */ exports.QUEUE_PRIORITY_HEADER = "x-fal-queue-priority"; /** * Header name for runner hint. */ exports.RUNNER_HINT_HEADER = "x-fal-runner-hint"; /** * Validates the timeout and returns the header value as a string. * Throws an error if the timeout is invalid. * * @param timeout - The timeout value in seconds (must be > MIN_REQUEST_TIMEOUT_SECONDS) * @returns The timeout as a string suitable for the header value * @throws Error if timeout is not a valid number or is <= MIN_REQUEST_TIMEOUT_SECONDS */ function validateTimeoutHeader(timeout) { if (typeof timeout !== "number" || isNaN(timeout)) { throw new Error(`Timeout must be a number, got ${timeout}`); } if (timeout <= exports.MIN_REQUEST_TIMEOUT_SECONDS) { throw new Error(`Timeout must be greater than ${exports.MIN_REQUEST_TIMEOUT_SECONDS} seconds`); } return timeout.toString(); } /** * Creates headers object with the timeout header if timeout is provided. * Returns an empty object if timeout is undefined. * * @param timeout - Optional timeout value in seconds * @returns Headers object with REQUEST_TIMEOUT_HEADER if timeout is provided */ function buildTimeoutHeaders(timeout) { if (timeout === undefined) { return {}; } return { [exports.REQUEST_TIMEOUT_HEADER]: validateTimeoutHeader(timeout), }; } //# sourceMappingURL=headers.js.map