@askalf/dario 3.2.4 → 3.2.5
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/README.md +0 -1
- package/dist/proxy.js +44 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -452,7 +452,6 @@ Your app sends whatever it wants — any tools, any parameters. dario replaces t
|
|
|
452
452
|
| `DARIO_API_KEY` | If set, all endpoints (except `/health`) require matching `x-api-key` header or `Authorization: Bearer` header | unset (open) |
|
|
453
453
|
| `DARIO_NO_BUN` | Disable automatic Bun relaunch (stay on Node.js) | unset |
|
|
454
454
|
| `DARIO_MIN_INTERVAL_MS` | Minimum ms between requests (rate governor) | `500` |
|
|
455
|
-
| `DARIO_EXTENDED_CONTEXT` | Enable 1M context window for Sonnet 4.6 (requires [Extra Usage](https://support.claude.com/en/articles/12429409-manage-extra-usage-for-paid-claude-plans) enabled) | unset |
|
|
456
455
|
|
|
457
456
|
## Supported Features
|
|
458
457
|
|
package/dist/proxy.js
CHANGED
|
@@ -731,12 +731,9 @@ export async function startProxy(opts = {}) {
|
|
|
731
731
|
beta += ',' + clientBeta;
|
|
732
732
|
}
|
|
733
733
|
else {
|
|
734
|
-
// CC v2.1.104
|
|
735
|
-
//
|
|
736
|
-
|
|
737
|
-
beta = process.env.DARIO_EXTENDED_CONTEXT
|
|
738
|
-
? `claude-code-20250219,oauth-2025-04-20,context-1m-2025-08-07,interleaved-thinking-2025-05-14,context-management-2025-06-27,prompt-caching-scope-2026-01-05,advisor-tool-2026-03-01,effort-2025-11-24`
|
|
739
|
-
: baseBeta;
|
|
734
|
+
// CC v2.1.104 beta set (exact 8 from MITM capture, exact order).
|
|
735
|
+
// context-1m requires Extra Usage — if it 400s, we auto-retry without it.
|
|
736
|
+
beta = 'claude-code-20250219,oauth-2025-04-20,context-1m-2025-08-07,interleaved-thinking-2025-05-14,context-management-2025-06-27,prompt-caching-scope-2026-01-05,advisor-tool-2026-03-01,effort-2025-11-24';
|
|
740
737
|
if (clientBeta) {
|
|
741
738
|
const baseSet = new Set(beta.split(','));
|
|
742
739
|
const filtered = filterBillableBetas(clientBeta)
|
|
@@ -764,12 +761,52 @@ export async function startProxy(opts = {}) {
|
|
|
764
761
|
// CC sends 600 on first request per session. With rotation, every request is "first"
|
|
765
762
|
'x-stainless-timeout': '600',
|
|
766
763
|
};
|
|
767
|
-
|
|
764
|
+
let upstream = await fetch(targetBase, {
|
|
768
765
|
method: req.method ?? 'POST',
|
|
769
766
|
headers,
|
|
770
767
|
body: finalBody ? new Uint8Array(finalBody) : undefined,
|
|
771
768
|
signal: AbortSignal.timeout(UPSTREAM_TIMEOUT_MS),
|
|
772
769
|
});
|
|
770
|
+
// Auto-retry without context-1m if it triggers a long-context billing error
|
|
771
|
+
if (upstream.status === 429 && !passthrough) {
|
|
772
|
+
const peekBody = await upstream.text().catch(() => '');
|
|
773
|
+
if (peekBody.includes('long context') || peekBody.includes('Extra usage is required')) {
|
|
774
|
+
if (verbose)
|
|
775
|
+
console.log(`[dario] #${requestCount} context-1m rejected — retrying without it`);
|
|
776
|
+
const reducedBeta = beta.replace(',context-1m-2025-08-07', '').replace('context-1m-2025-08-07,', '');
|
|
777
|
+
const retryHeaders = { ...headers, 'anthropic-beta': reducedBeta };
|
|
778
|
+
const retry = await fetch(targetBase, {
|
|
779
|
+
method: req.method ?? 'POST',
|
|
780
|
+
headers: retryHeaders,
|
|
781
|
+
body: finalBody ? new Uint8Array(finalBody) : undefined,
|
|
782
|
+
signal: AbortSignal.timeout(UPSTREAM_TIMEOUT_MS),
|
|
783
|
+
});
|
|
784
|
+
// Use the retry response from here on
|
|
785
|
+
upstream = retry;
|
|
786
|
+
}
|
|
787
|
+
else {
|
|
788
|
+
// Not a context-1m issue — handle as normal 429 below
|
|
789
|
+
// Re-wrap the already-consumed body for downstream handling
|
|
790
|
+
const enriched = enrich429(peekBody, upstream.headers);
|
|
791
|
+
if (!(cliAvailable && !useCli)) {
|
|
792
|
+
const responseHeaders = {
|
|
793
|
+
'Content-Type': 'application/json',
|
|
794
|
+
'Access-Control-Allow-Origin': corsOrigin,
|
|
795
|
+
...SECURITY_HEADERS,
|
|
796
|
+
};
|
|
797
|
+
for (const [key, value] of upstream.headers.entries()) {
|
|
798
|
+
if (key.startsWith('x-ratelimit') || key.startsWith('anthropic-ratelimit') || key === 'request-id') {
|
|
799
|
+
responseHeaders[key] = value;
|
|
800
|
+
}
|
|
801
|
+
}
|
|
802
|
+
requestCount++;
|
|
803
|
+
res.writeHead(429, responseHeaders);
|
|
804
|
+
res.end(enriched);
|
|
805
|
+
return;
|
|
806
|
+
}
|
|
807
|
+
// Fall through to CLI fallback below
|
|
808
|
+
}
|
|
809
|
+
}
|
|
773
810
|
// Enrich 429 errors with rate limit details from headers (Anthropic only returns "Error")
|
|
774
811
|
if (upstream.status === 429 && !(cliAvailable && !useCli)) {
|
|
775
812
|
const errBody = await upstream.text().catch(() => '');
|