proxitor 0.6.1 → 0.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.mjs CHANGED
@@ -14716,7 +14716,6 @@ function buildUpstreamResponse(upstream, method) {
14716
14716
  headers
14717
14717
  });
14718
14718
  }
14719
- /** Read and process the request body, returning an error response on failure */
14720
14719
  async function readRawBody(request, reqId) {
14721
14720
  try {
14722
14721
  return {
@@ -14735,7 +14734,6 @@ async function readRawBody(request, reqId) {
14735
14734
  };
14736
14735
  }
14737
14736
  }
14738
- /** Resolve per-request config: extract model, resolve overrides, build routing and body */
14739
14737
  function resolveRequest(rawBody, config, method, path, reqId) {
14740
14738
  const modelName = extractModel(rawBody);
14741
14739
  const resolved = resolveModelConfig(config, modelName);
@@ -14768,7 +14766,41 @@ function resolveRequest(rawBody, config, method, path, reqId) {
14768
14766
  headers: resolved.headers
14769
14767
  };
14770
14768
  }
14771
- /** Execute upstream fetch, returning appropriate error responses on failure */
14769
+ /**
14770
+ * Extract a readable error detail from an upstream response body.
14771
+ *
14772
+ * OpenRouter error format:
14773
+ * { error: { code: 400, message: "...", metadata: { raw: "...", provider_name: "..." } } }
14774
+ *
14775
+ * - `error.message` — human-readable summary
14776
+ * - `error.metadata.provider_name` — which provider caused it (null = OpenRouter itself)
14777
+ * - `error.metadata.raw` — the original provider error (most specific cause)
14778
+ */
14779
+ function formatMetadata(meta) {
14780
+ const parts = [];
14781
+ if (meta.provider_name) parts.push(`provider=${meta.provider_name}`);
14782
+ if (meta.raw) {
14783
+ const raw = typeof meta.raw === "string" ? meta.raw : JSON.stringify(meta.raw);
14784
+ parts.push(raw);
14785
+ }
14786
+ return parts;
14787
+ }
14788
+ function extractErrorDetail(bodyText) {
14789
+ try {
14790
+ const parsed = JSON.parse(bodyText);
14791
+ if (typeof parsed !== "object" || parsed === null) return bodyText;
14792
+ const err = parsed.error;
14793
+ if (typeof err === "object" && err !== null && err.message) {
14794
+ const parts = [];
14795
+ if (err.code != null) parts.push(String(err.code));
14796
+ parts.push(String(err.message));
14797
+ if (err.metadata && typeof err.metadata === "object") parts.push(...formatMetadata(err.metadata));
14798
+ return parts.join(" | ");
14799
+ }
14800
+ if (parsed.message) return String(parsed.message);
14801
+ } catch {}
14802
+ return bodyText;
14803
+ }
14772
14804
  async function executeUpstream(upstreamUrl, method, headers, body, signal, path, startedAt, reqId) {
14773
14805
  let upstream;
14774
14806
  try {
@@ -14784,6 +14816,21 @@ async function executeUpstream(upstreamUrl, method, headers, body, signal, path,
14784
14816
  type: "proxy_upstream_error"
14785
14817
  } }, { status: 502 });
14786
14818
  }
14819
+ if (upstream.status >= 400) {
14820
+ const bodyText = await upstream.text();
14821
+ const detail = extractErrorDetail(bodyText);
14822
+ const truncated = detail.length > 300 ? `${detail.slice(0, 300)}…` : detail;
14823
+ (upstream.status >= 500 ? logger.error : logger.warn)(withReq(reqId, `${method} ${path} ← ${upstream.status} (${Date.now() - startedAt}ms): ${truncated}`));
14824
+ const responseHeaders = buildResponseHeaders(upstream.headers);
14825
+ if (method === "HEAD") return new Response(null, {
14826
+ status: upstream.status,
14827
+ headers: responseHeaders
14828
+ });
14829
+ return new Response(bodyText, {
14830
+ status: upstream.status,
14831
+ headers: responseHeaders
14832
+ });
14833
+ }
14787
14834
  logger.info(withReq(reqId, `${method} ${path} ← ${upstream.status} (${Date.now() - startedAt}ms)`));
14788
14835
  return buildUpstreamResponse(upstream, method);
14789
14836
  }
@@ -14822,9 +14869,7 @@ function createProxyServer(config, onReady) {
14822
14869
  hostname: config.host
14823
14870
  }, onReady);
14824
14871
  }
14825
- /** Shutdown deadline: force-close after this many ms */
14826
14872
  const SHUTDOWN_TIMEOUT_MS = 1e4;
14827
- /** Start the proxy with graceful shutdown on SIGTERM/SIGINT */
14828
14873
  function startProxyServer(config, onReady) {
14829
14874
  const server = createProxyServer(config, onReady);
14830
14875
  let shuttingDown = false;
@@ -14848,7 +14893,7 @@ function startProxyServer(config, onReady) {
14848
14893
  }
14849
14894
  //#endregion
14850
14895
  //#region src/version.ts
14851
- const version = "0.6.1";
14896
+ const version = "0.6.2";
14852
14897
  //#endregion
14853
14898
  //#region src/cli.ts
14854
14899
  const argv = process.argv.slice(2);