@askalf/dario 3.2.0 → 3.2.1

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.
Files changed (2) hide show
  1. package/dist/proxy.js +22 -1
  2. package/package.json +1 -1
package/dist/proxy.js CHANGED
@@ -791,7 +791,7 @@ export async function startProxy(opts = {}) {
791
791
  }
792
792
  // Auto-fallback: if API returns 429 and CLI is available, retry through CLI binary
793
793
  if (upstream.status === 429 && cliAvailable && !useCli) {
794
- await upstream.text().catch(() => { });
794
+ const errBody429 = await upstream.text().catch(() => '');
795
795
  if (verbose)
796
796
  console.log(`[dario] #${requestCount} 429 from API — falling back to CLI`);
797
797
  let clientWantsStream = false;
@@ -800,6 +800,27 @@ export async function startProxy(opts = {}) {
800
800
  }
801
801
  catch { }
802
802
  const cliResult = await handleViaCli(body, modelOverride, verbose);
803
+ // If CLI fallback also failed, return the original 429 with enriched details
804
+ // instead of a cryptic 502 from CLI failure
805
+ if (cliResult.status >= 500) {
806
+ if (verbose)
807
+ console.log(`[dario] #${requestCount} CLI fallback failed (${cliResult.status}) — returning original 429`);
808
+ const enriched = enrich429(errBody429, upstream.headers);
809
+ const responseHeaders = {
810
+ 'Content-Type': 'application/json',
811
+ 'Access-Control-Allow-Origin': corsOrigin,
812
+ ...SECURITY_HEADERS,
813
+ };
814
+ for (const [key, value] of upstream.headers.entries()) {
815
+ if (key.startsWith('x-ratelimit') || key.startsWith('anthropic-ratelimit') || key === 'request-id') {
816
+ responseHeaders[key] = value;
817
+ }
818
+ }
819
+ requestCount++;
820
+ res.writeHead(429, responseHeaders);
821
+ res.end(enriched);
822
+ return;
823
+ }
803
824
  requestCount++;
804
825
  sendCliResponse(res, cliResult, clientWantsStream, isOpenAI, corsOrigin, SECURITY_HEADERS);
805
826
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@askalf/dario",
3
- "version": "3.2.0",
3
+ "version": "3.2.1",
4
4
  "description": "Use your Claude subscription as an API. No API key needed. Local proxy for Claude Max/Pro subscriptions.",
5
5
  "type": "module",
6
6
  "bin": {