const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
const require_helpers = require('./helpers.cjs');
const require_router = require('./router.cjs');
const require_sse_writer = require('./sse-writer.cjs');
const require_chaos = require('./chaos.cjs');
const require_recorder = require('./recorder.cjs');
const require_fal = require('./fal.cjs');
let node_crypto = require("node:crypto");
node_crypto = require_runtime.__toESM(node_crypto);

//#region src/fal-audio.ts
const FAL_JOB_MAX_ENTRIES = 1e4;
const FAL_JOB_TTL_MS = 36e5;
/**
* A Map wrapper for fal.ai queue jobs that enforces a maximum size and per-entry TTL.
* Entries older than FAL_JOB_TTL_MS are lazily evicted on `get`.
* When the map exceeds FAL_JOB_MAX_ENTRIES on `set`, the oldest entries
* are removed to stay within bounds.
* A background sweep runs every 60 s to proactively evict expired entries.
*/
var FalJobMap = class {
	entries = /* @__PURE__ */ new Map();
	sweepTimer = null;
	constructor() {
		this.startSweep();
	}
	/** Start the proactive TTL sweep (every 60 s). */
	startSweep() {
		if (this.sweepTimer) return;
		this.sweepTimer = setInterval(() => {
			const now = Date.now();
			for (const [key, entry] of this.entries) if (now - entry.createdAt > FAL_JOB_TTL_MS) this.entries.delete(key);
		}, 6e4);
		if (this.sweepTimer && typeof this.sweepTimer === "object" && "unref" in this.sweepTimer) this.sweepTimer.unref();
	}
	/** Stop the proactive TTL sweep. */
	stopSweep() {
		if (this.sweepTimer) {
			clearInterval(this.sweepTimer);
			this.sweepTimer = null;
		}
	}
	get(key) {
		const entry = this.entries.get(key);
		if (!entry) return void 0;
		if (Date.now() - entry.createdAt > FAL_JOB_TTL_MS) {
			this.entries.delete(key);
			return;
		}
		return entry.job;
	}
	set(key, job) {
		this.entries.set(key, {
			job,
			createdAt: Date.now()
		});
		if (this.entries.size > FAL_JOB_MAX_ENTRIES) {
			const excess = this.entries.size - FAL_JOB_MAX_ENTRIES;
			const iter = this.entries.keys();
			for (let i = 0; i < excess; i++) {
				const next = iter.next();
				if (!next.done) this.entries.delete(next.value);
			}
		}
	}
	delete(key) {
		return this.entries.delete(key);
	}
	clear() {
		this.entries.clear();
	}
	destroy() {
		this.stopSweep();
		this.entries.clear();
	}
	get size() {
		return this.entries.size;
	}
};
const falJobs = new FalJobMap();
function audioToFalFile(response) {
	let contentType;
	let data;
	if (typeof response.audio === "string") {
		data = response.audio;
		contentType = require_helpers.FORMAT_TO_CONTENT_TYPE[response.format ?? "mp3"] ?? "audio/mpeg";
	} else {
		data = response.audio.b64Json;
		contentType = response.audio.contentType ?? "audio/mpeg";
	}
	const ext = response.format ?? (contentType !== "audio/mpeg" ? Object.entries(require_helpers.FORMAT_TO_CONTENT_TYPE).find(([, v]) => v === contentType)?.[0] ?? "mp3" : "mp3");
	const fileSize = Math.ceil(data.length * 3 / 4) - (data.endsWith("==") ? 2 : data.endsWith("=") ? 1 : 0);
	return { audio: {
		url: `https://mock.fal.media/files/generated_audio.${ext}`,
		content_type: contentType,
		file_name: `generated_audio.${ext}`,
		file_size: fileSize
	} };
}
const QUEUE_SUBMIT_RE = /^\/fal\/queue\/submit\/(.+)$/;
const QUEUE_STATUS_RE = /^\/fal\/queue\/requests\/([^/]+)\/status$/;
const QUEUE_RESULT_RE = /^\/fal\/queue\/requests\/([^/]+)$/;
const QUEUE_CANCEL_RE = /^\/fal\/queue\/requests\/([^/]+)\/cancel$/;
const SYNC_RUN_RE = /^\/fal\/run\/(.+)$/;
async function handleFalQueue(req, res, body, pathname, fixtures, defaults, journal) {
	const testId = require_helpers.getTestId(req);
	const matchCounts = journal.getFixtureMatchCountsForTest(testId);
	const submitMatch = QUEUE_SUBMIT_RE.exec(pathname);
	if (submitMatch && req.method === "POST") {
		const modelId = submitMatch[1];
		return handleQueueSubmit(req, res, body, pathname, modelId, testId, fixtures, defaults, matchCounts, journal);
	}
	const statusMatch = QUEUE_STATUS_RE.exec(pathname);
	if (statusMatch) {
		const requestId = statusMatch[1];
		return handleQueueStatus(req, res, pathname, requestId, testId, journal);
	}
	const cancelMatch = QUEUE_CANCEL_RE.exec(pathname);
	if (cancelMatch) {
		const requestId = cancelMatch[1];
		return handleQueueCancel(req, res, pathname, requestId, testId, journal);
	}
	const resultMatch = QUEUE_RESULT_RE.exec(pathname);
	if (resultMatch) {
		const requestId = resultMatch[1];
		return handleQueueResult(req, res, pathname, requestId, testId, journal);
	}
	const runMatch = SYNC_RUN_RE.exec(pathname);
	if (runMatch && req.method === "POST") {
		const modelId = runMatch[1];
		return handleSyncRun(req, res, body, pathname, modelId, fixtures, defaults, matchCounts, journal);
	}
	const errorBody = { error: {
		message: "Unknown fal.ai endpoint",
		type: "not_found"
	} };
	journal.add({
		method: req.method ?? "GET",
		path: pathname,
		headers: require_helpers.flattenHeaders(req.headers),
		body: null,
		response: {
			status: 404,
			fixture: null
		}
	});
	res.writeHead(404, { "Content-Type": "application/json" });
	res.end(JSON.stringify(errorBody));
}
async function handleQueueSubmit(req, res, body, pathname, modelId, testId, fixtures, defaults, matchCounts, journal) {
	let parsed = {};
	if (body.trim()) try {
		parsed = JSON.parse(body);
	} catch (parseErr) {
		const detail = parseErr instanceof Error ? parseErr.message : "unknown";
		journal.add({
			method: req.method ?? "POST",
			path: pathname,
			headers: require_helpers.flattenHeaders(req.headers),
			body: null,
			response: {
				status: 400,
				fixture: null
			}
		});
		res.writeHead(400, { "Content-Type": "application/json" });
		res.end(JSON.stringify({ error: {
			message: `Malformed JSON: ${detail}`,
			type: "invalid_request_error"
		} }));
		return;
	}
	const syntheticReq = {
		model: modelId,
		messages: [{
			role: "user",
			content: (typeof parsed.prompt === "string" ? parsed.prompt : null) ?? (typeof parsed.text === "string" ? parsed.text : null) ?? ""
		}],
		_endpointType: "fal-audio",
		_context: require_helpers.getContext(req)
	};
	const { fixture, skippedBySequenceOrTurn } = require_router.matchFixtureDiagnostic(fixtures, syntheticReq, matchCounts, defaults.requestTransform);
	if (fixture) journal.incrementFixtureMatchCount(fixture, fixtures, testId);
	if (require_chaos.applyChaos(res, fixture, defaults.chaos, req.headers, journal, {
		method: req.method ?? "POST",
		path: pathname,
		headers: require_helpers.flattenHeaders(req.headers),
		body: syntheticReq
	}, fixture ? "fixture" : "proxy", defaults.registry, defaults.logger)) return;
	if (!fixture) {
		if (require_helpers.resolveStrictMode(defaults.strict, req.headers)) {
			const strictMessage = require_helpers.strictNoMatchMessage(skippedBySequenceOrTurn);
			defaults.logger.error(require_helpers.strictNoMatchLogLine(req.method ?? "POST", pathname, skippedBySequenceOrTurn));
			journal.add({
				method: req.method ?? "POST",
				path: pathname,
				headers: require_helpers.flattenHeaders(req.headers),
				body: syntheticReq,
				response: {
					status: 503,
					fixture: null,
					...require_helpers.strictOverrideField(defaults.strict, req.headers)
				}
			});
			res.writeHead(503, { "Content-Type": "application/json" });
			res.end(JSON.stringify({ error: {
				message: strictMessage,
				type: "invalid_request_error",
				code: "no_fixture_match"
			} }));
			return;
		}
		if (defaults.record) {
			if (await tryRecordAudioQueueWalk({
				req,
				res,
				syntheticReq,
				modelId,
				pathname,
				body,
				fixtures,
				defaults,
				testId,
				journal
			})) return;
		}
		journal.add({
			method: req.method ?? "POST",
			path: pathname,
			headers: require_helpers.flattenHeaders(req.headers),
			body: syntheticReq,
			response: {
				status: 404,
				fixture: null,
				...require_helpers.strictOverrideField(defaults.strict, req.headers)
			}
		});
		res.writeHead(404, { "Content-Type": "application/json" });
		res.end(JSON.stringify({ error: {
			message: "No fixture matched",
			type: "invalid_request_error",
			code: "no_fixture_match"
		} }));
		return;
	}
	const response = await require_helpers.resolveResponse(fixture, syntheticReq);
	if (require_helpers.isErrorResponse(response)) {
		const status = response.status ?? 500;
		journal.add({
			method: req.method ?? "POST",
			path: pathname,
			headers: require_helpers.flattenHeaders(req.headers),
			body: syntheticReq,
			response: {
				status,
				fixture
			}
		});
		require_sse_writer.writeErrorResponse(res, status, require_helpers.serializeErrorResponse(response), { retryAfter: response.retryAfter });
		return;
	}
	let result;
	if (require_helpers.isAudioResponse(response)) result = audioToFalFile(response);
	else if (require_helpers.isJSONResponse(response)) {
		const json = response.json;
		if (!json || typeof json !== "object") {
			journal.add({
				method: req.method ?? "POST",
				path: pathname,
				headers: require_helpers.flattenHeaders(req.headers),
				body: syntheticReq,
				response: {
					status: 500,
					fixture
				}
			});
			res.writeHead(500, { "Content-Type": "application/json" });
			res.end(JSON.stringify({ error: {
				message: "Recorded fal audio fixture has non-object json",
				type: "server_error"
			} }));
			return;
		}
		result = json;
	} else {
		journal.add({
			method: req.method ?? "POST",
			path: pathname,
			headers: require_helpers.flattenHeaders(req.headers),
			body: syntheticReq,
			response: {
				status: 500,
				fixture
			}
		});
		res.writeHead(500, { "Content-Type": "application/json" });
		res.end(JSON.stringify({ error: {
			message: "Fixture response is not an audio type",
			type: "server_error"
		} }));
		return;
	}
	const requestId = node_crypto.default.randomUUID();
	const job = {
		requestId,
		modelId,
		status: "COMPLETED",
		result
	};
	const stateKey = `${testId}:${requestId}`;
	falJobs.set(stateKey, job);
	journal.add({
		method: req.method ?? "POST",
		path: pathname,
		headers: require_helpers.flattenHeaders(req.headers),
		body: syntheticReq,
		response: {
			status: 200,
			fixture
		}
	});
	res.writeHead(200, { "Content-Type": "application/json" });
	res.end(JSON.stringify({
		request_id: requestId,
		response_url: `https://queue.fal.run/${modelId}/requests/${requestId}/response`,
		status_url: `https://queue.fal.run/${modelId}/requests/${requestId}/status`,
		cancel_url: `https://queue.fal.run/${modelId}/requests/${requestId}/cancel`,
		queue_position: 0
	}));
}
/**
* Walk the upstream queue (submit → poll status → get result), persist the
* FINAL result body as a fal-audio fixture, then synthesise the local envelope
* and seed `falJobs` so the same recording run's status/result polls work. The
* legacy `proxyAndRecord` shortcut wrote the IN_QUEUE envelope as the fixture,
* which broke replay (the SDK polls until COMPLETED then expects the result
* body, not the envelope).
*
* Returns `true` if the request has been handled (response written and
* journaled); `false` if recording wasn't configured for this provider and the
* caller should fall through to 404 (strict is gated before recording).
*/
async function tryRecordAudioQueueWalk(args) {
	const { req, res, syntheticReq, modelId, pathname, body, fixtures, defaults, testId, journal } = args;
	const record = defaults.record;
	if (!record) return false;
	const upstreamBase = record.providers.fal;
	if (!upstreamBase) {
		const outcome = await require_recorder.proxyAndRecord(req, res, syntheticReq, "fal", pathname, fixtures, defaults, body);
		if (outcome === "handled_by_hook") return true;
		if (outcome === "relayed") {
			journal.add({
				method: req.method ?? "POST",
				path: pathname,
				headers: require_helpers.flattenHeaders(req.headers),
				body: syntheticReq,
				response: {
					status: res.statusCode ?? 200,
					fixture: null,
					source: "proxy"
				}
			});
			return true;
		}
		return false;
	}
	defaults.logger.warn(`NO FIXTURE MATCH — walking legacy fal audio queue at ${upstreamBase}${pathname}`);
	let finalBody;
	try {
		({body: finalBody} = await require_fal.walkFalQueue({
			upstreamBase,
			submitPath: pathname,
			body,
			headers: require_recorder.buildForwardHeaders(req),
			builtinKey: record.providerKeys?.fal,
			pollIntervalMs: record.fal?.pollIntervalMs,
			timeoutMs: record.fal?.timeoutMs,
			upstreamTimeoutMs: record.upstreamTimeoutMs,
			fallbackStatusPath: (id) => `/fal/queue/requests/${id}/status`,
			fallbackResultPath: (id) => `/fal/queue/requests/${id}`,
			logger: defaults.logger
		}));
	} catch (err) {
		const msg = err instanceof Error ? err.message : "Unknown queue-walk error";
		defaults.logger.error(`fal-audio queue-walk proxy failed: ${msg}`);
		if (res.destroyed || res.writableEnded) return true;
		journal.add({
			method: req.method ?? "POST",
			path: pathname,
			headers: require_helpers.flattenHeaders(req.headers),
			body: syntheticReq,
			response: {
				status: 502,
				fixture: null,
				source: "proxy"
			}
		});
		res.writeHead(502, { "Content-Type": "application/json" });
		res.end(JSON.stringify({ error: {
			message: `Proxy to upstream failed: ${msg}`,
			type: "proxy_error"
		} }));
		return true;
	}
	if (!finalBody || typeof finalBody !== "object") {
		defaults.logger.error("fal-audio queue-walk produced non-object result");
		if (res.destroyed || res.writableEnded) return true;
		journal.add({
			method: req.method ?? "POST",
			path: pathname,
			headers: require_helpers.flattenHeaders(req.headers),
			body: syntheticReq,
			response: {
				status: 502,
				fixture: null,
				source: "proxy"
			}
		});
		res.writeHead(502, { "Content-Type": "application/json" });
		res.end(JSON.stringify({ error: {
			message: "Upstream result body was not a JSON object",
			type: "proxy_error"
		} }));
		return true;
	}
	const persistResult = require_recorder.persistFixture({
		record,
		providerKey: "fal",
		testId,
		fixture: {
			match: require_recorder.buildFixtureMatch(defaults.requestTransform ? defaults.requestTransform(syntheticReq) : syntheticReq, record),
			response: {
				json: finalBody,
				status: 200
			}
		},
		fixtures,
		logger: defaults.logger
	});
	if (persistResult.kind === "failed" && !res.headersSent) res.setHeader("X-AIMock-Record-Error", require_recorder.sanitizeHeaderValue(persistResult.error));
	const requestId = node_crypto.default.randomUUID();
	const job = {
		requestId,
		modelId,
		status: "COMPLETED",
		result: finalBody
	};
	falJobs.set(`${testId}:${requestId}`, job);
	if (res.destroyed || res.writableEnded) return true;
	journal.add({
		method: req.method ?? "POST",
		path: pathname,
		headers: require_helpers.flattenHeaders(req.headers),
		body: syntheticReq,
		response: {
			status: 200,
			fixture: null,
			source: "proxy"
		}
	});
	res.writeHead(200, { "Content-Type": "application/json" });
	res.end(JSON.stringify({
		request_id: requestId,
		response_url: `https://queue.fal.run/${modelId}/requests/${requestId}/response`,
		status_url: `https://queue.fal.run/${modelId}/requests/${requestId}/status`,
		cancel_url: `https://queue.fal.run/${modelId}/requests/${requestId}/cancel`,
		queue_position: 0
	}));
	return true;
}
function handleQueueStatus(req, res, pathname, requestId, testId, journal) {
	const stateKey = `${testId}:${requestId}`;
	const job = falJobs.get(stateKey);
	if (!job) {
		journal.add({
			method: req.method ?? "GET",
			path: pathname,
			headers: require_helpers.flattenHeaders(req.headers),
			body: null,
			response: {
				status: 404,
				fixture: null
			}
		});
		res.writeHead(404, { "Content-Type": "application/json" });
		res.end(JSON.stringify({ error: {
			message: `Request ${requestId} not found`,
			type: "not_found"
		} }));
		return;
	}
	journal.add({
		method: req.method ?? "GET",
		path: pathname,
		headers: require_helpers.flattenHeaders(req.headers),
		body: null,
		response: {
			status: 200,
			fixture: null
		}
	});
	res.writeHead(200, { "Content-Type": "application/json" });
	res.end(JSON.stringify({
		status: job.status,
		request_id: job.requestId,
		response_url: `https://queue.fal.run/${job.modelId}/requests/${requestId}/response`
	}));
}
function handleQueueResult(req, res, pathname, requestId, testId, journal) {
	const stateKey = `${testId}:${requestId}`;
	const job = falJobs.get(stateKey);
	if (!job) {
		journal.add({
			method: req.method ?? "GET",
			path: pathname,
			headers: require_helpers.flattenHeaders(req.headers),
			body: null,
			response: {
				status: 404,
				fixture: null
			}
		});
		res.writeHead(404, { "Content-Type": "application/json" });
		res.end(JSON.stringify({ error: {
			message: `Request ${requestId} not found`,
			type: "not_found"
		} }));
		return;
	}
	if (job.result === null) {
		journal.add({
			method: req.method ?? "GET",
			path: pathname,
			headers: require_helpers.flattenHeaders(req.headers),
			body: null,
			response: {
				status: 409,
				fixture: null
			}
		});
		require_sse_writer.writeErrorResponse(res, 409, JSON.stringify({ error: {
			message: "Job result not yet available",
			type: "not_ready"
		} }));
		return;
	}
	journal.add({
		method: req.method ?? "GET",
		path: pathname,
		headers: require_helpers.flattenHeaders(req.headers),
		body: null,
		response: {
			status: 200,
			fixture: null
		}
	});
	res.writeHead(200, { "Content-Type": "application/json" });
	res.end(JSON.stringify(job.result));
}
function handleQueueCancel(req, res, pathname, requestId, testId, journal) {
	const stateKey = `${testId}:${requestId}`;
	if (!falJobs.get(stateKey)) {
		journal.add({
			method: req.method ?? "DELETE",
			path: pathname,
			headers: require_helpers.flattenHeaders(req.headers),
			body: null,
			response: {
				status: 404,
				fixture: null
			}
		});
		res.writeHead(404, { "Content-Type": "application/json" });
		res.end(JSON.stringify({ status: "NOT_FOUND" }));
		return;
	}
	journal.add({
		method: req.method ?? "DELETE",
		path: pathname,
		headers: require_helpers.flattenHeaders(req.headers),
		body: null,
		response: {
			status: 400,
			fixture: null
		}
	});
	res.writeHead(400, { "Content-Type": "application/json" });
	res.end(JSON.stringify({ status: "ALREADY_COMPLETED" }));
}
async function handleSyncRun(req, res, body, pathname, modelId, fixtures, defaults, matchCounts, journal) {
	let parsed = {};
	if (body.trim()) try {
		parsed = JSON.parse(body);
	} catch (parseErr) {
		const detail = parseErr instanceof Error ? parseErr.message : "unknown";
		journal.add({
			method: req.method ?? "POST",
			path: pathname,
			headers: require_helpers.flattenHeaders(req.headers),
			body: null,
			response: {
				status: 400,
				fixture: null
			}
		});
		res.writeHead(400, { "Content-Type": "application/json" });
		res.end(JSON.stringify({ error: {
			message: `Malformed JSON: ${detail}`,
			type: "invalid_request_error"
		} }));
		return;
	}
	const syntheticReq = {
		model: modelId,
		messages: [{
			role: "user",
			content: (typeof parsed.prompt === "string" ? parsed.prompt : null) ?? (typeof parsed.text === "string" ? parsed.text : null) ?? ""
		}],
		_endpointType: "fal-audio",
		_context: require_helpers.getContext(req)
	};
	const { fixture, skippedBySequenceOrTurn } = require_router.matchFixtureDiagnostic(fixtures, syntheticReq, matchCounts, defaults.requestTransform);
	if (fixture) journal.incrementFixtureMatchCount(fixture, fixtures, require_helpers.getTestId(req));
	if (require_chaos.applyChaos(res, fixture, defaults.chaos, req.headers, journal, {
		method: req.method ?? "POST",
		path: pathname,
		headers: require_helpers.flattenHeaders(req.headers),
		body: syntheticReq
	}, fixture ? "fixture" : "proxy", defaults.registry, defaults.logger)) return;
	if (!fixture) {
		if (require_helpers.resolveStrictMode(defaults.strict, req.headers)) {
			const strictMessage = require_helpers.strictNoMatchMessage(skippedBySequenceOrTurn);
			defaults.logger.error(require_helpers.strictNoMatchLogLine(req.method ?? "POST", pathname, skippedBySequenceOrTurn));
			journal.add({
				method: req.method ?? "POST",
				path: pathname,
				headers: require_helpers.flattenHeaders(req.headers),
				body: syntheticReq,
				response: {
					status: 503,
					fixture: null,
					...require_helpers.strictOverrideField(defaults.strict, req.headers)
				}
			});
			res.writeHead(503, { "Content-Type": "application/json" });
			res.end(JSON.stringify({ error: {
				message: strictMessage,
				type: "invalid_request_error",
				code: "no_fixture_match"
			} }));
			return;
		}
		if (defaults.record) {
			const outcome = await require_recorder.proxyAndRecord(req, res, syntheticReq, "fal", pathname, fixtures, defaults, body);
			if (outcome === "handled_by_hook") return;
			if (outcome !== "not_configured") {
				journal.add({
					method: req.method ?? "POST",
					path: pathname,
					headers: require_helpers.flattenHeaders(req.headers),
					body: syntheticReq,
					response: {
						status: res.statusCode ?? 200,
						fixture: null,
						source: "proxy"
					}
				});
				return;
			}
		}
		journal.add({
			method: req.method ?? "POST",
			path: pathname,
			headers: require_helpers.flattenHeaders(req.headers),
			body: syntheticReq,
			response: {
				status: 404,
				fixture: null,
				...require_helpers.strictOverrideField(defaults.strict, req.headers)
			}
		});
		res.writeHead(404, { "Content-Type": "application/json" });
		res.end(JSON.stringify({ error: {
			message: "No fixture matched",
			type: "invalid_request_error",
			code: "no_fixture_match"
		} }));
		return;
	}
	const response = await require_helpers.resolveResponse(fixture, syntheticReq);
	if (require_helpers.isErrorResponse(response)) {
		const status = response.status ?? 500;
		journal.add({
			method: req.method ?? "POST",
			path: pathname,
			headers: require_helpers.flattenHeaders(req.headers),
			body: syntheticReq,
			response: {
				status,
				fixture
			}
		});
		require_sse_writer.writeErrorResponse(res, status, require_helpers.serializeErrorResponse(response), { retryAfter: response.retryAfter });
		return;
	}
	let result;
	let resultStatus = 200;
	if (require_helpers.isAudioResponse(response)) result = audioToFalFile(response);
	else if (require_helpers.isJSONResponse(response)) {
		resultStatus = response.status ?? 200;
		const json = response.json;
		if (!json || typeof json !== "object") {
			journal.add({
				method: req.method ?? "POST",
				path: pathname,
				headers: require_helpers.flattenHeaders(req.headers),
				body: syntheticReq,
				response: {
					status: 500,
					fixture
				}
			});
			res.writeHead(500, { "Content-Type": "application/json" });
			res.end(JSON.stringify({ error: {
				message: "Recorded fal audio fixture has non-object json",
				type: "server_error"
			} }));
			return;
		}
		result = json;
	} else {
		journal.add({
			method: req.method ?? "POST",
			path: pathname,
			headers: require_helpers.flattenHeaders(req.headers),
			body: syntheticReq,
			response: {
				status: 500,
				fixture
			}
		});
		res.writeHead(500, { "Content-Type": "application/json" });
		res.end(JSON.stringify({ error: {
			message: "Fixture response is not an audio type",
			type: "server_error"
		} }));
		return;
	}
	journal.add({
		method: req.method ?? "POST",
		path: pathname,
		headers: require_helpers.flattenHeaders(req.headers),
		body: syntheticReq,
		response: {
			status: resultStatus,
			fixture
		}
	});
	res.writeHead(resultStatus, { "Content-Type": "application/json" });
	res.end(JSON.stringify(result));
}

//#endregion
exports.audioToFalFile = audioToFalFile;
exports.falJobs = falJobs;
exports.handleFalQueue = handleFalQueue;
//# sourceMappingURL=fal-audio.cjs.map