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

Function proxyOpenRouterVideoRecordContent

src/openrouter-video.ts:810–1133  ·  view source on GitHub ↗

* Live-proxy a content download for a completed record job — reachable under * proxyOnly (forever) and during the eager-capture window: the stored * upstream `unsigned_urls[index || 0]` is fetched with the same same-origin * Bearer-forwarding gate as the eager-capture path (headers gated by * `u

(args: {
  req: http.IncomingMessage;
  res: http.ServerResponse;
  job: OpenRouterVideoRecordJob;
  key: string;
  indexParam: string | null;
  journal: Journal;
  defaults: HandlerDefaults;
  jobs: OpenRouterVideoJobMap;
  method: string;
  path: string;
})

Source from the content-addressed store, hash-verified

808 * working through a long download list must not lose the job mid-way.
809 */
810async function proxyOpenRouterVideoRecordContent(args: {
811 req: http.IncomingMessage;
812 res: http.ServerResponse;
813 job: OpenRouterVideoRecordJob;
814 key: string;
815 indexParam: string | null;
816 journal: Journal;
817 defaults: HandlerDefaults;
818 jobs: OpenRouterVideoJobMap;
819 method: string;
820 path: string;
821}): Promise<void> {
822 const { req, res, job, key, indexParam, journal, defaults, jobs, method, path } = args;
823 const logger = defaults.logger;
824
825 const proxyError = (msg: string): void => {
826 logger.error(`OpenRouter video content proxy failed: ${msg}`);
827 // Guard BEFORE journaling (file convention): a disconnected client gets
828 // neither a write nor a journal entry.
829 if (res.destroyed || res.writableEnded) return;
830 journal.add({
831 method,
832 path,
833 headers: flattenHeaders(req.headers),
834 body: null,
835 response: {
836 status: 502,
837 fixture: null,
838 source: "proxy",
839 ...strictOverrideField(defaults.strict, req.headers),
840 },
841 });
842 writeErrorResponse(
843 res,
844 502,
845 JSON.stringify({
846 error: { message: `Proxy to upstream failed: ${msg}`, type: "proxy_error" },
847 }),
848 );
849 };
850
851 // Recording can be disabled mid-flight (LLMock.disableRecording) — an
852 // orphaned record job must fail loudly BEFORE contacting the upstream
853 // (and before forwarding the client's Bearer anywhere), mirroring the
854 // record-job poll gate. The snapshot below is used for every later read
855 // (same discipline as the poll path): the gate and its consumers must see
856 // ONE config object even if the defaults are swapped mid-relay.
857 const record = defaults.record;
858 if (!record) {
859 proxyError("record mode is no longer configured for an in-flight record job");
860 return;
861 }
862
863 const urls = job.upstreamUnsignedUrls ?? [];
864 const parsedIndex = indexParam === null ? 0 : Number(indexParam);
865 const index = Number.isInteger(parsedIndex) && parsedIndex >= 0 ? parsedIndex : 0;
866 if (indexParam !== null && index !== parsedIndex) {
867 // Mirror the replay path's warn convention: a coerced index silently

Callers 1

Calls 15

buildForwardHeadersFunction · 0.85
fetchHeadersWithTimeoutFunction · 0.85
readBodyIdleFunction · 0.85
flattenHeadersFunction · 0.85
strictOverrideFieldFunction · 0.85
clampTimeoutFunction · 0.85
resolveFunction · 0.85
addMethod · 0.80
endMethod · 0.80
writeMethod · 0.80
errorMethod · 0.80
proxyErrorFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…