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

Function proxyOpenRouterVideoRecordPoll

src/openrouter-video.ts:1943–2273  ·  view source on GitHub ↗

* Proxy a status poll for a record-mode job 1:1 to the upstream and relay * the result with mock-rewritten identifiers (rewriteRecordPollBody: id, * polling_url, unsigned_urls; everything else verbatim). When the upstream * reports `completed`, the rewritten body is relayed IMMEDIATELY and the *

(args: {
  req: http.IncomingMessage;
  res: http.ServerResponse;
  job: OpenRouterVideoRecordJob;
  key: string;
  testId: string;
  fixtures: Fixture[];
  journal: Journal;
  defaults: HandlerDefaults;
  jobs: OpenRouterVideoJobMap;
  method: string;
  path: string;
})

Source from the content-addressed store, hash-verified

1941 * refreshes its TTL so a long generation cannot be evicted mid-recording.
1942 */
1943async function proxyOpenRouterVideoRecordPoll(args: {
1944 req: http.IncomingMessage;
1945 res: http.ServerResponse;
1946 job: OpenRouterVideoRecordJob;
1947 key: string;
1948 testId: string;
1949 fixtures: Fixture[];
1950 journal: Journal;
1951 defaults: HandlerDefaults;
1952 jobs: OpenRouterVideoJobMap;
1953 method: string;
1954 path: string;
1955}): Promise<void> {
1956 const { req, res, job, key, testId, fixtures, journal, defaults, jobs, method, path } = args;
1957 const logger = defaults.logger;
1958
1959 const journalProxy = (status: number): void => {
1960 journal.add({
1961 method,
1962 path,
1963 headers: flattenHeaders(req.headers),
1964 body: null,
1965 response: {
1966 status,
1967 fixture: null,
1968 source: "proxy",
1969 ...strictOverrideField(defaults.strict, req.headers),
1970 },
1971 });
1972 };
1973
1974 const proxyError = (msg: string): void => {
1975 logger.error(`OpenRouter video poll proxy failed: ${msg}`);
1976 // Guard BEFORE journaling (file convention): a disconnected client gets
1977 // neither a write nor a journal entry.
1978 if (res.destroyed || res.writableEnded) return;
1979 journalProxy(502);
1980 writeErrorResponse(
1981 res,
1982 502,
1983 JSON.stringify({
1984 error: { message: `Proxy to upstream failed: ${msg}`, type: "proxy_error" },
1985 }),
1986 );
1987 };
1988
1989 // Recording can be disabled mid-flight (LLMock.disableRecording) — an
1990 // orphaned record job must fail loudly on ANY poll, before contacting the
1991 // upstream, rather than silently relaying non-terminal statuses and only
1992 // erroring at the terminal poll.
1993 const record = defaults.record;
1994 if (!record) {
1995 proxyError("record mode is no longer configured for an in-flight record job");
1996 return;
1997 }
1998
1999 let fetched: { status: number; contentType: string | null; text: string };
2000 try {

Callers 1

Calls 14

buildForwardHeadersFunction · 0.85
upstreamTimeoutSignalFunction · 0.85
readEnvelopeTextFunction · 0.85
rewriteRecordPollBodyFunction · 0.85
persistFixtureFunction · 0.85
sanitizeHeaderValueFunction · 0.85
endMethod · 0.80
proxyErrorFunction · 0.70
journalProxyFunction · 0.70
relayJsonFunction · 0.70
getMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…