@askalf/dario 3.0.2 → 3.0.4
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/cc-template.js +13 -13
- package/dist/oauth.js +20 -3
- package/dist/proxy.js +4 -2
- package/package.json +1 -1
package/dist/cc-template.js
CHANGED
|
@@ -309,6 +309,8 @@ export function buildCCRequest(clientBody, billingTag, agentIdentity, cache1h, i
|
|
|
309
309
|
systemText = systemText.replace(pattern, '');
|
|
310
310
|
}
|
|
311
311
|
// ── Build the CC request from template ──
|
|
312
|
+
// Key order matches CC v2.1.104 MITM capture exactly:
|
|
313
|
+
// model, messages, system, tools, metadata, max_tokens, thinking, context_management, output_config, stream
|
|
312
314
|
const ccRequest = {
|
|
313
315
|
model,
|
|
314
316
|
messages,
|
|
@@ -317,17 +319,12 @@ export function buildCCRequest(clientBody, billingTag, agentIdentity, cache1h, i
|
|
|
317
319
|
{ type: 'text', text: agentIdentity, cache_control: cache1h },
|
|
318
320
|
{ type: 'text', text: systemText || 'You are a helpful assistant.', cache_control: cache1h },
|
|
319
321
|
],
|
|
320
|
-
max_tokens: 64000,
|
|
321
322
|
};
|
|
322
|
-
//
|
|
323
|
-
if (
|
|
324
|
-
ccRequest.
|
|
325
|
-
ccRequest.output_config = { effort: 'medium' };
|
|
326
|
-
ccRequest.context_management = { edits: [{ type: 'clear_thinking_20251015', keep: 'all' }] };
|
|
327
|
-
// CC sends temperature:1 explicitly when not in thinking-only mode
|
|
328
|
-
ccRequest.temperature = 1;
|
|
323
|
+
// Tools come before metadata in CC's key order
|
|
324
|
+
if (clientTools && clientTools.length > 0) {
|
|
325
|
+
ccRequest.tools = CC_TOOL_DEFINITIONS;
|
|
329
326
|
}
|
|
330
|
-
//
|
|
327
|
+
// Metadata
|
|
331
328
|
ccRequest.metadata = {
|
|
332
329
|
user_id: JSON.stringify({
|
|
333
330
|
device_id: identity.deviceId,
|
|
@@ -335,11 +332,14 @@ export function buildCCRequest(clientBody, billingTag, agentIdentity, cache1h, i
|
|
|
335
332
|
session_id: identity.sessionId,
|
|
336
333
|
}),
|
|
337
334
|
};
|
|
338
|
-
ccRequest.
|
|
339
|
-
//
|
|
340
|
-
if (
|
|
341
|
-
ccRequest.
|
|
335
|
+
ccRequest.max_tokens = 64000;
|
|
336
|
+
// Model-specific fields — order: thinking, context_management, output_config
|
|
337
|
+
if (!isHaiku) {
|
|
338
|
+
ccRequest.thinking = { type: 'adaptive' };
|
|
339
|
+
ccRequest.context_management = { edits: [{ type: 'clear_thinking_20251015', keep: 'all' }] };
|
|
340
|
+
ccRequest.output_config = { effort: 'medium' };
|
|
342
341
|
}
|
|
342
|
+
ccRequest.stream = stream;
|
|
343
343
|
return { body: ccRequest, toolMap: activeToolMap, unmappedTools };
|
|
344
344
|
}
|
|
345
345
|
/**
|
package/dist/oauth.js
CHANGED
|
@@ -15,6 +15,9 @@ const OAUTH_TOKEN_URL = 'https://platform.claude.com/v1/oauth/token';
|
|
|
15
15
|
const OAUTH_SCOPES = 'org:create_api_key user:profile user:inference user:sessions:claude_code user:mcp_servers user:file_upload';
|
|
16
16
|
// Refresh 30 min before expiry
|
|
17
17
|
const REFRESH_BUFFER_MS = 30 * 60 * 1000;
|
|
18
|
+
// After a failed refresh, don't retry for 60s to avoid spam
|
|
19
|
+
let lastRefreshFailure = 0;
|
|
20
|
+
const REFRESH_COOLDOWN_MS = 60 * 1000;
|
|
18
21
|
// In-memory credential cache — avoids disk reads on every request
|
|
19
22
|
let credentialsCache = null;
|
|
20
23
|
let credentialsCacheTime = 0;
|
|
@@ -210,6 +213,8 @@ async function doRefreshTokens() {
|
|
|
210
213
|
signal: AbortSignal.timeout(15000),
|
|
211
214
|
});
|
|
212
215
|
if (!res.ok) {
|
|
216
|
+
const errBody = await res.text().catch(() => '');
|
|
217
|
+
console.error(`[dario] Refresh attempt ${attempt + 1}/3 failed: HTTP ${res.status} — ${errBody.slice(0, 200)}`);
|
|
213
218
|
if (res.status === 401 || res.status === 403) {
|
|
214
219
|
throw new Error(`Refresh token rejected (${res.status}). Run \`dario login\` to re-authenticate.`);
|
|
215
220
|
}
|
|
@@ -240,10 +245,22 @@ export async function getAccessToken() {
|
|
|
240
245
|
if (oauth.expiresAt > Date.now() + REFRESH_BUFFER_MS) {
|
|
241
246
|
return oauth.accessToken;
|
|
242
247
|
}
|
|
243
|
-
// Need refresh
|
|
248
|
+
// Need refresh — but don't spam if we just failed
|
|
249
|
+
if (Date.now() - lastRefreshFailure < REFRESH_COOLDOWN_MS) {
|
|
250
|
+
// Still in cooldown from a recent failure, use current token even if expiring
|
|
251
|
+
return oauth.accessToken;
|
|
252
|
+
}
|
|
244
253
|
console.log('[dario] Token expiring soon, refreshing...');
|
|
245
|
-
|
|
246
|
-
|
|
254
|
+
try {
|
|
255
|
+
const refreshed = await refreshTokens();
|
|
256
|
+
return refreshed.accessToken;
|
|
257
|
+
}
|
|
258
|
+
catch (err) {
|
|
259
|
+
lastRefreshFailure = Date.now();
|
|
260
|
+
console.error(`[dario] Refresh failed: ${err instanceof Error ? err.message : err}. Will retry in 60s. Run \`dario login\` if this persists.`);
|
|
261
|
+
// Return current token — it might still work for a few more minutes
|
|
262
|
+
return oauth.accessToken;
|
|
263
|
+
}
|
|
247
264
|
}
|
|
248
265
|
/**
|
|
249
266
|
* Get token status info.
|
package/dist/proxy.js
CHANGED
|
@@ -725,8 +725,10 @@ export async function startProxy(opts = {}) {
|
|
|
725
725
|
}
|
|
726
726
|
else {
|
|
727
727
|
// Claude-optimized: full beta set matching real Claude Code (exact order from MITM capture)
|
|
728
|
-
//
|
|
729
|
-
|
|
728
|
+
// Exact beta set from CC v2.1.104 MITM capture (exact order)
|
|
729
|
+
// Only 8 betas — CC sends more conditionally (fast-mode, web-search, etc.)
|
|
730
|
+
// but the base set for a standard request is exactly this
|
|
731
|
+
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';
|
|
730
732
|
if (clientBeta) {
|
|
731
733
|
const baseSet = new Set(beta.split(','));
|
|
732
734
|
const filtered = filterBillableBetas(clientBeta)
|