@askalf/dario 3.2.4 → 3.2.6

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/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 base beta set. context-1m is opt-in via DARIO_EXTENDED_CONTEXT=1
735
- // because it requires Extra Usage enabled on the account.
736
- const baseBeta = 'claude-code-20250219,oauth-2025-04-20,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';
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
- const upstream = await fetch(targetBase, {
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(() => '');
package/package.json CHANGED
@@ -1,64 +1,64 @@
1
- {
2
- "name": "@askalf/dario",
3
- "version": "3.2.4",
4
- "description": "Use your Claude subscription as an API. No API key needed. Local proxy for Claude Max/Pro subscriptions.",
5
- "type": "module",
6
- "bin": {
7
- "dario": "./dist/cli.js"
8
- },
9
- "main": "./dist/index.js",
10
- "types": "./dist/index.d.ts",
11
- "exports": {
12
- ".": {
13
- "import": "./dist/index.js",
14
- "types": "./dist/index.d.ts"
15
- }
16
- },
17
- "files": [
18
- "dist",
19
- "README.md",
20
- "LICENSE"
21
- ],
22
- "scripts": {
23
- "build": "tsc && cp src/cc-template-data.json dist/",
24
- "audit": "npm audit --production --audit-level=high",
25
- "prepublishOnly": "npm run build",
26
- "start": "node dist/cli.js",
27
- "dev": "tsx src/cli.ts",
28
- "e2e": "node test/e2e.mjs",
29
- "compat": "node test/compat.mjs"
30
- },
31
- "keywords": [
32
- "claude",
33
- "anthropic",
34
- "oauth",
35
- "proxy",
36
- "api",
37
- "bridge",
38
- "subscription",
39
- "claude-max",
40
- "claude-pro",
41
- "llm",
42
- "ai",
43
- "cli",
44
- "developer-tools"
45
- ],
46
- "author": "askalf (https://github.com/askalf)",
47
- "license": "MIT",
48
- "repository": {
49
- "type": "git",
50
- "url": "https://github.com/askalf/dario.git"
51
- },
52
- "homepage": "https://github.com/askalf/dario",
53
- "bugs": {
54
- "url": "https://github.com/askalf/dario/issues"
55
- },
56
- "engines": {
57
- "node": ">=18.0.0"
58
- },
59
- "devDependencies": {
60
- "@types/node": "^22.0.0",
61
- "tsx": "^4.19.0",
62
- "typescript": "^5.7.0"
63
- }
64
- }
1
+ {
2
+ "name": "@askalf/dario",
3
+ "version": "3.2.6",
4
+ "description": "Use your Claude subscription as an API. No API key needed. Local proxy for Claude Max/Pro subscriptions.",
5
+ "type": "module",
6
+ "bin": {
7
+ "dario": "./dist/cli.js"
8
+ },
9
+ "main": "./dist/index.js",
10
+ "types": "./dist/index.d.ts",
11
+ "exports": {
12
+ ".": {
13
+ "import": "./dist/index.js",
14
+ "types": "./dist/index.d.ts"
15
+ }
16
+ },
17
+ "files": [
18
+ "dist",
19
+ "README.md",
20
+ "LICENSE"
21
+ ],
22
+ "scripts": {
23
+ "build": "tsc && cp src/cc-template-data.json dist/",
24
+ "audit": "npm audit --production --audit-level=high",
25
+ "prepublishOnly": "npm run build",
26
+ "start": "node dist/cli.js",
27
+ "dev": "tsx src/cli.ts",
28
+ "e2e": "node test/e2e.mjs",
29
+ "compat": "node test/compat.mjs"
30
+ },
31
+ "keywords": [
32
+ "claude",
33
+ "anthropic",
34
+ "oauth",
35
+ "proxy",
36
+ "api",
37
+ "bridge",
38
+ "subscription",
39
+ "claude-max",
40
+ "claude-pro",
41
+ "llm",
42
+ "ai",
43
+ "cli",
44
+ "developer-tools"
45
+ ],
46
+ "author": "askalf (https://github.com/askalf)",
47
+ "license": "MIT",
48
+ "repository": {
49
+ "type": "git",
50
+ "url": "https://github.com/askalf/dario.git"
51
+ },
52
+ "homepage": "https://github.com/askalf/dario",
53
+ "bugs": {
54
+ "url": "https://github.com/askalf/dario/issues"
55
+ },
56
+ "engines": {
57
+ "node": ">=18.0.0"
58
+ },
59
+ "devDependencies": {
60
+ "@types/node": "^22.0.0",
61
+ "tsx": "^4.19.0",
62
+ "typescript": "^5.7.0"
63
+ }
64
+ }