(args: {
req: http.IncomingMessage;
res: http.ServerResponse;
syntheticReq: ChatCompletionRequest;
modelId: string;
pathname: string;
strippedPath: string;
body: string;
fixtures: Fixture[];
defaults: HandlerDefaults;
stateKey: (id: string) => string;
journal: Journal;
})
| 1021 | } |
| 1022 | |
| 1023 | async function proxyAndRecordFalQueueSubmit(args: { |
| 1024 | req: http.IncomingMessage; |
| 1025 | res: http.ServerResponse; |
| 1026 | syntheticReq: ChatCompletionRequest; |
| 1027 | modelId: string; |
| 1028 | pathname: string; |
| 1029 | strippedPath: string; |
| 1030 | body: string; |
| 1031 | fixtures: Fixture[]; |
| 1032 | defaults: HandlerDefaults; |
| 1033 | stateKey: (id: string) => string; |
| 1034 | journal: Journal; |
| 1035 | }): Promise<"handled" | "no_upstream"> { |
| 1036 | const { |
| 1037 | req, |
| 1038 | res, |
| 1039 | syntheticReq, |
| 1040 | modelId, |
| 1041 | pathname, |
| 1042 | strippedPath, |
| 1043 | body, |
| 1044 | fixtures, |
| 1045 | defaults, |
| 1046 | stateKey, |
| 1047 | journal, |
| 1048 | } = args; |
| 1049 | |
| 1050 | const record = defaults.record; |
| 1051 | if (!record) return "no_upstream"; |
| 1052 | const upstreamBase = record.providers.fal; |
| 1053 | if (!upstreamBase) { |
| 1054 | defaults.logger.warn(`No upstream URL configured for provider "fal" — cannot proxy`); |
| 1055 | return "no_upstream"; |
| 1056 | } |
| 1057 | |
| 1058 | defaults.logger.warn(`NO FIXTURE MATCH — walking fal queue at ${upstreamBase}${strippedPath}`); |
| 1059 | |
| 1060 | let finalBody: unknown; |
| 1061 | let billableUnits: number | null; |
| 1062 | try { |
| 1063 | const walk = await walkFalQueue({ |
| 1064 | upstreamBase, |
| 1065 | submitPath: strippedPath, |
| 1066 | body, |
| 1067 | headers: buildForwardHeaders(req), |
| 1068 | pollIntervalMs: record.fal?.pollIntervalMs, |
| 1069 | timeoutMs: record.fal?.timeoutMs, |
| 1070 | upstreamTimeoutMs: record.upstreamTimeoutMs, |
| 1071 | fallbackStatusPath: (id) => `${modelId}/requests/${id}/status`, |
| 1072 | fallbackResultPath: (id) => `${modelId}/requests/${id}`, |
| 1073 | logger: defaults.logger, |
| 1074 | }); |
| 1075 | finalBody = walk.body; |
| 1076 | billableUnits = walk.billableUnits; |
| 1077 | } catch (err) { |
| 1078 | const msg = err instanceof Error ? err.message : "Unknown queue-walk error"; |
| 1079 | defaults.logger.error(`fal queue-walk proxy failed: ${msg}`); |
| 1080 | // Guard BEFORE journaling (openrouter-video convention): a client that |
no test coverage detected
searching dependent graphs…