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

Function proxyOpenRouterVideoSubmit

src/openrouter-video.ts:1684–1902  ·  view source on GitHub ↗

* Proxy an unmatched video submit to the configured OpenRouter upstream and * answer the client with a mock-rewritten envelope: a fresh aimock jobId and * a polling_url pointing back at the mock (testId embedded). The upstream * lifecycle is then driven interactively by the client's own polls — u

(args: {
  req: http.IncomingMessage;
  res: http.ServerResponse;
  raw: string;
  syntheticReq: ChatCompletionRequest;
  record: RecordConfig;
  journal: Journal;
  defaults: HandlerDefaults;
  jobs: OpenRouterVideoJobMap;
  method: string;
  path: string;
})

Source from the content-addressed store, hash-verified

1682 * the caller falls through to its 404 branch (fal convention).
1683 */
1684async function proxyOpenRouterVideoSubmit(args: {
1685 req: http.IncomingMessage;
1686 res: http.ServerResponse;
1687 raw: string;
1688 syntheticReq: ChatCompletionRequest;
1689 record: RecordConfig;
1690 journal: Journal;
1691 defaults: HandlerDefaults;
1692 jobs: OpenRouterVideoJobMap;
1693 method: string;
1694 path: string;
1695}): Promise<"handled" | "no_upstream"> {
1696 const { req, res, raw, syntheticReq, record, journal, defaults, jobs, method, path } = args;
1697
1698 const upstreamBase = record.providers.openrouter;
1699 if (!upstreamBase) {
1700 defaults.logger.warn(`No upstream URL configured for provider "openrouter" — cannot proxy`);
1701 return "no_upstream";
1702 }
1703
1704 const proxyError = (msg: string): "handled" => {
1705 defaults.logger.error(`OpenRouter video submit proxy failed: ${msg}`);
1706 // Guard BEFORE journaling (file convention): a disconnected client gets
1707 // neither a write nor a journal entry.
1708 if (res.destroyed || res.writableEnded) return "handled";
1709 journal.add({
1710 method,
1711 path,
1712 headers: flattenHeaders(req.headers),
1713 body: syntheticReq,
1714 response: {
1715 status: 502,
1716 fixture: null,
1717 source: "proxy",
1718 ...strictOverrideField(defaults.strict, req.headers),
1719 },
1720 });
1721 writeErrorResponse(
1722 res,
1723 502,
1724 JSON.stringify({
1725 error: { message: `Proxy to upstream failed: ${msg}`, type: "proxy_error" },
1726 }),
1727 );
1728 return "handled";
1729 };
1730
1731 let submitUrl: URL;
1732 let upstreamOrigin: string;
1733 try {
1734 submitUrl = resolveUpstreamUrl(upstreamBase, OPENROUTER_VIDEOS_PATH);
1735 upstreamOrigin = new URL(upstreamBase).origin;
1736 } catch (err) {
1737 const msg = err instanceof Error ? err.message : String(err);
1738 return proxyError(`Invalid upstream URL: ${upstreamBase} (${msg})`);
1739 }
1740
1741 defaults.logger.warn(

Callers 1

Calls 15

resolveUpstreamUrlFunction · 0.85
buildForwardHeadersFunction · 0.85
upstreamTimeoutSignalFunction · 0.85
readEnvelopeTextFunction · 0.85
flattenHeadersFunction · 0.85
strictOverrideFieldFunction · 0.85
getTestIdFunction · 0.85
buildFixtureMatchFunction · 0.85
requestBaseFunction · 0.85
testIdSuffixFunction · 0.85
addMethod · 0.80
endMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…