proxitor 0.6.0 → 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
@@ -11747,9 +11747,21 @@ function _getDefaultLogLevel() {
11747
11747
  if (R) return LogLevels.warn;
11748
11748
  return LogLevels.info;
11749
11749
  }
11750
+ createConsola();
11750
11751
  //#endregion
11751
11752
  //#region src/logger.ts
11752
- const logger = createConsola().withTag("proxitor");
11753
+ /**
11754
+ * Custom logger with consistent left-aligned output.
11755
+ *
11756
+ * Consola's default fancy mode places the tag on the right for short lines
11757
+ * and on the left for long lines when a date/time is shown, making timestamps
11758
+ * jump between positions. Disabling date/time in formatOptions keeps the
11759
+ * tag always on the left while preserving the icon (ℹ ✓ ⚠) and colors.
11760
+ */
11761
+ const logger = createConsola({ formatOptions: {
11762
+ date: false,
11763
+ time: false
11764
+ } });
11753
11765
  /** Generate a short request ID (first 8 hex chars of a UUID) */
11754
11766
  function requestId() {
11755
11767
  return crypto.randomUUID().slice(0, 8);
@@ -14704,7 +14716,6 @@ function buildUpstreamResponse(upstream, method) {
14704
14716
  headers
14705
14717
  });
14706
14718
  }
14707
- /** Read and process the request body, returning an error response on failure */
14708
14719
  async function readRawBody(request, reqId) {
14709
14720
  try {
14710
14721
  return {
@@ -14723,7 +14734,6 @@ async function readRawBody(request, reqId) {
14723
14734
  };
14724
14735
  }
14725
14736
  }
14726
- /** Resolve per-request config: extract model, resolve overrides, build routing and body */
14727
14737
  function resolveRequest(rawBody, config, method, path, reqId) {
14728
14738
  const modelName = extractModel(rawBody);
14729
14739
  const resolved = resolveModelConfig(config, modelName);
@@ -14756,7 +14766,41 @@ function resolveRequest(rawBody, config, method, path, reqId) {
14756
14766
  headers: resolved.headers
14757
14767
  };
14758
14768
  }
14759
- /** 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
+ }
14760
14804
  async function executeUpstream(upstreamUrl, method, headers, body, signal, path, startedAt, reqId) {
14761
14805
  let upstream;
14762
14806
  try {
@@ -14772,6 +14816,21 @@ async function executeUpstream(upstreamUrl, method, headers, body, signal, path,
14772
14816
  type: "proxy_upstream_error"
14773
14817
  } }, { status: 502 });
14774
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
+ }
14775
14834
  logger.info(withReq(reqId, `${method} ${path} ← ${upstream.status} (${Date.now() - startedAt}ms)`));
14776
14835
  return buildUpstreamResponse(upstream, method);
14777
14836
  }
@@ -14810,9 +14869,7 @@ function createProxyServer(config, onReady) {
14810
14869
  hostname: config.host
14811
14870
  }, onReady);
14812
14871
  }
14813
- /** Shutdown deadline: force-close after this many ms */
14814
14872
  const SHUTDOWN_TIMEOUT_MS = 1e4;
14815
- /** Start the proxy with graceful shutdown on SIGTERM/SIGINT */
14816
14873
  function startProxyServer(config, onReady) {
14817
14874
  const server = createProxyServer(config, onReady);
14818
14875
  let shuttingDown = false;
@@ -14836,7 +14893,7 @@ function startProxyServer(config, onReady) {
14836
14893
  }
14837
14894
  //#endregion
14838
14895
  //#region src/version.ts
14839
- const version = "0.6.0";
14896
+ const version = "0.6.2";
14840
14897
  //#endregion
14841
14898
  //#region src/cli.ts
14842
14899
  const argv = process.argv.slice(2);