@askalf/dario 1.0.6 → 1.0.7
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 +44 -1
- package/package.json +1 -1
package/dist/proxy.js
CHANGED
|
@@ -8,6 +8,9 @@
|
|
|
8
8
|
* No API key needed — your Claude subscription pays for it.
|
|
9
9
|
*/
|
|
10
10
|
import { createServer } from 'node:http';
|
|
11
|
+
import { randomUUID } from 'node:crypto';
|
|
12
|
+
import { execSync } from 'node:child_process';
|
|
13
|
+
import { arch, platform, version as nodeVersion } from 'node:process';
|
|
11
14
|
import { getAccessToken, getStatus } from './oauth.js';
|
|
12
15
|
const ANTHROPIC_API = 'https://api.anthropic.com';
|
|
13
16
|
const DEFAULT_PORT = 3456;
|
|
@@ -15,6 +18,27 @@ const MAX_BODY_BYTES = 10 * 1024 * 1024; // 10 MB — generous for large prompts
|
|
|
15
18
|
const UPSTREAM_TIMEOUT_MS = 300_000; // 5 min — matches Anthropic SDK default
|
|
16
19
|
const LOCALHOST = '127.0.0.1';
|
|
17
20
|
const CORS_ORIGIN = 'http://localhost';
|
|
21
|
+
// Detect installed Claude Code version at startup
|
|
22
|
+
function detectClaudeVersion() {
|
|
23
|
+
try {
|
|
24
|
+
const out = execSync('claude --version', { timeout: 5000, stdio: 'pipe' }).toString().trim();
|
|
25
|
+
const match = out.match(/^([\d.]+)/);
|
|
26
|
+
return match?.[1] ?? '2.1.96';
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
return '2.1.96';
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function getOsName() {
|
|
33
|
+
const p = platform;
|
|
34
|
+
if (p === 'win32')
|
|
35
|
+
return 'Windows';
|
|
36
|
+
if (p === 'darwin')
|
|
37
|
+
return 'MacOS';
|
|
38
|
+
return 'Linux';
|
|
39
|
+
}
|
|
40
|
+
// Persistent session ID per proxy lifetime (like Claude Code does per session)
|
|
41
|
+
const SESSION_ID = randomUUID();
|
|
18
42
|
function sanitizeError(err) {
|
|
19
43
|
const msg = err instanceof Error ? err.message : String(err);
|
|
20
44
|
// Never leak tokens in error messages
|
|
@@ -29,6 +53,7 @@ export async function startProxy(opts = {}) {
|
|
|
29
53
|
console.error('[dario] Not authenticated. Run `dario login` first.');
|
|
30
54
|
process.exit(1);
|
|
31
55
|
}
|
|
56
|
+
const cliVersion = detectClaudeVersion();
|
|
32
57
|
let requestCount = 0;
|
|
33
58
|
let tokenCostEstimate = 0;
|
|
34
59
|
const server = createServer(async (req, res) => {
|
|
@@ -106,7 +131,12 @@ export async function startProxy(opts = {}) {
|
|
|
106
131
|
const targetUrl = targetBase;
|
|
107
132
|
// Merge any client-provided beta flags with the required oauth flag
|
|
108
133
|
const clientBeta = req.headers['anthropic-beta'];
|
|
109
|
-
const betaFlags = new Set([
|
|
134
|
+
const betaFlags = new Set([
|
|
135
|
+
'oauth-2025-04-20',
|
|
136
|
+
'interleaved-thinking-2025-05-14',
|
|
137
|
+
'prompt-caching-scope-2026-01-05',
|
|
138
|
+
'claude-code-20250219',
|
|
139
|
+
]);
|
|
110
140
|
if (clientBeta) {
|
|
111
141
|
for (const flag of clientBeta.split(',')) {
|
|
112
142
|
const trimmed = flag.trim();
|
|
@@ -115,11 +145,24 @@ export async function startProxy(opts = {}) {
|
|
|
115
145
|
}
|
|
116
146
|
}
|
|
117
147
|
const headers = {
|
|
148
|
+
'accept': 'application/json',
|
|
118
149
|
'Authorization': `Bearer ${accessToken}`,
|
|
119
150
|
'Content-Type': 'application/json',
|
|
120
151
|
'anthropic-version': req.headers['anthropic-version'] || '2023-06-01',
|
|
121
152
|
'anthropic-beta': [...betaFlags].join(','),
|
|
153
|
+
'anthropic-dangerous-direct-browser-access': 'true',
|
|
154
|
+
'user-agent': `claude-cli/${cliVersion} (external, cli)`,
|
|
122
155
|
'x-app': 'cli',
|
|
156
|
+
'x-claude-code-session-id': SESSION_ID,
|
|
157
|
+
'x-client-request-id': randomUUID(),
|
|
158
|
+
'x-stainless-arch': arch,
|
|
159
|
+
'x-stainless-lang': 'js',
|
|
160
|
+
'x-stainless-os': getOsName(),
|
|
161
|
+
'x-stainless-package-version': '0.81.0',
|
|
162
|
+
'x-stainless-retry-count': '0',
|
|
163
|
+
'x-stainless-runtime': 'node',
|
|
164
|
+
'x-stainless-runtime-version': nodeVersion,
|
|
165
|
+
'x-stainless-timeout': '600',
|
|
123
166
|
};
|
|
124
167
|
const upstream = await fetch(targetUrl, {
|
|
125
168
|
method: req.method ?? 'POST',
|