MCPcopy Create free account
hub / github.com/CopilotKit/aimock / proxyAndRecordFalQueueSubmit

Function proxyAndRecordFalQueueSubmit

src/fal.ts:1023–1176  ·  view source on GitHub ↗
(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;
})

Source from the content-addressed store, hash-verified

1021}
1022
1023async 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

Callers 1

handleFalFunction · 0.85

Calls 15

walkFalQueueFunction · 0.85
buildForwardHeadersFunction · 0.85
flattenHeadersFunction · 0.85
buildFixtureMatchFunction · 0.85
persistFixtureFunction · 0.85
getTestIdFunction · 0.85
sanitizeHeaderValueFunction · 0.85
resolveProgressionFunction · 0.85
stateKeyFunction · 0.85
queuePositionFunction · 0.85
errorMethod · 0.80
addMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…