@askalf/dario 5.2.4 → 5.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.
@@ -475,8 +475,27 @@ export declare const CC_CACHE_CONTROL: CacheControl;
475
475
  * without the enabling beta is not a shape real CC produces, and forwarding
476
476
  * half of it risks an upstream 400. DARIO_CACHE_TTL_5M=1 restores the
477
477
  * pre-fix behavior (always bare 5m) as the operator escape hatch.
478
+ *
479
+ * DARIO_CACHE_TTL_1H=1 is the opposite override: force `ttl:'1h'` on every
480
+ * breakpoint regardless of what the client sent, for a client that can't
481
+ * emit the 1h stamp itself (an SDK/agent harness that only stamps bare 5m —
482
+ * dario#678). The proxy adds the enabling `extended-cache-ttl-` beta to the
483
+ * outbound set so the 1h is honored. Deliberate override of the mirror
484
+ * guardrail: 1h cache *writes* bill ~2× the 5m rate, so it only wins when
485
+ * idle gaps routinely exceed the 5-minute window; on rapid back-to-back
486
+ * turns it costs more. 5M takes precedence if both are set.
478
487
  */
479
488
  export declare function effectiveCacheControl(clientBody: Record<string, unknown>, clientBeta?: string): CacheControl;
489
+ /** The anthropic-beta flag that enables the 1-hour prompt-cache TTL. */
490
+ export declare const EXTENDED_CACHE_TTL_BETA = "extended-cache-ttl-2025-04-11";
491
+ /**
492
+ * When DARIO_CACHE_TTL_1H forces the 1h stamp, the outbound beta set must also
493
+ * carry `extended-cache-ttl-` or Anthropic ignores the ttl. Add it (idempotent)
494
+ * unless DARIO_CACHE_TTL_5M overrides (5M wins, matching effectiveCacheControl).
495
+ * Pure — `env` is injectable for tests. Returns `beta` unchanged when the flag
496
+ * is off or the beta is already present.
497
+ */
498
+ export declare function withForced1hBeta(beta: string, env?: Record<string, string | undefined>): string;
480
499
  /**
481
500
  * Place CC-style prompt-cache breakpoints on the conversation. The system
482
501
  * prompt is already cached at build time (2 system breakpoints); this adds a
@@ -1260,10 +1260,21 @@ export const CC_CACHE_CONTROL = { type: 'ephemeral' };
1260
1260
  * without the enabling beta is not a shape real CC produces, and forwarding
1261
1261
  * half of it risks an upstream 400. DARIO_CACHE_TTL_5M=1 restores the
1262
1262
  * pre-fix behavior (always bare 5m) as the operator escape hatch.
1263
+ *
1264
+ * DARIO_CACHE_TTL_1H=1 is the opposite override: force `ttl:'1h'` on every
1265
+ * breakpoint regardless of what the client sent, for a client that can't
1266
+ * emit the 1h stamp itself (an SDK/agent harness that only stamps bare 5m —
1267
+ * dario#678). The proxy adds the enabling `extended-cache-ttl-` beta to the
1268
+ * outbound set so the 1h is honored. Deliberate override of the mirror
1269
+ * guardrail: 1h cache *writes* bill ~2× the 5m rate, so it only wins when
1270
+ * idle gaps routinely exceed the 5-minute window; on rapid back-to-back
1271
+ * turns it costs more. 5M takes precedence if both are set.
1263
1272
  */
1264
1273
  export function effectiveCacheControl(clientBody, clientBeta) {
1265
1274
  if (process.env['DARIO_CACHE_TTL_5M'] === '1')
1266
1275
  return CC_CACHE_CONTROL;
1276
+ if (process.env['DARIO_CACHE_TTL_1H'] === '1')
1277
+ return { type: 'ephemeral', ttl: '1h' };
1267
1278
  if (!clientBeta || !clientBeta.includes('extended-cache-ttl-'))
1268
1279
  return CC_CACHE_CONTROL;
1269
1280
  const scan = (blocks) => {
@@ -1289,6 +1300,22 @@ export function effectiveCacheControl(clientBody, clientBeta) {
1289
1300
  }
1290
1301
  return CC_CACHE_CONTROL;
1291
1302
  }
1303
+ /** The anthropic-beta flag that enables the 1-hour prompt-cache TTL. */
1304
+ export const EXTENDED_CACHE_TTL_BETA = 'extended-cache-ttl-2025-04-11';
1305
+ /**
1306
+ * When DARIO_CACHE_TTL_1H forces the 1h stamp, the outbound beta set must also
1307
+ * carry `extended-cache-ttl-` or Anthropic ignores the ttl. Add it (idempotent)
1308
+ * unless DARIO_CACHE_TTL_5M overrides (5M wins, matching effectiveCacheControl).
1309
+ * Pure — `env` is injectable for tests. Returns `beta` unchanged when the flag
1310
+ * is off or the beta is already present.
1311
+ */
1312
+ export function withForced1hBeta(beta, env = process.env) {
1313
+ if (env['DARIO_CACHE_TTL_1H'] !== '1' || env['DARIO_CACHE_TTL_5M'] === '1')
1314
+ return beta;
1315
+ if (beta.split(',').includes(EXTENDED_CACHE_TTL_BETA))
1316
+ return beta;
1317
+ return beta.length > 0 ? beta + ',' + EXTENDED_CACHE_TTL_BETA : EXTENDED_CACHE_TTL_BETA;
1318
+ }
1292
1319
  /**
1293
1320
  * Place CC-style prompt-cache breakpoints on the conversation. The system
1294
1321
  * prompt is already cached at build time (2 system breakpoints); this adds a
package/dist/proxy.js CHANGED
@@ -9,7 +9,7 @@ import { arch, platform } from 'node:process';
9
9
  import { getAccessToken, getStatus } from './oauth.js';
10
10
  import { buildHealthResponse, derivePoolStatus, shouldDiscloseHealthInternals } from './health-response.js';
11
11
  import { darioVersion } from './version.js';
12
- import { buildCCRequest, applyCcPromptCaching, parseEffortSuffix, reverseMapResponse, createStreamingReverseMapper, orderHeadersForOutbound, isMcpToolName, CC_TEMPLATE, effectiveCacheControl } from './cc-template.js';
12
+ import { buildCCRequest, applyCcPromptCaching, parseEffortSuffix, reverseMapResponse, createStreamingReverseMapper, orderHeadersForOutbound, isMcpToolName, CC_TEMPLATE, effectiveCacheControl, withForced1hBeta } from './cc-template.js';
13
13
  import { stampCch, hasCchSeed } from './cch.js';
14
14
  import { describeTemplate, detectDrift, checkCCCompat } from './live-fingerprint.js';
15
15
  import { AccountPool, computeStickyKey, parseRateLimits, modelFamily, isInAuthCooldown, authCooldownMs, reconcilePoolAccounts } from './pool.js';
@@ -2399,6 +2399,12 @@ export async function startProxy(opts = {}) {
2399
2399
  if (toAdd.length > 0)
2400
2400
  beta += ',' + toAdd.join(',');
2401
2401
  }
2402
+ // Forced 1h cache (DARIO_CACHE_TTL_1H): effectiveCacheControl stamps
2403
+ // ttl:'1h', but the 1h is only honored WITH the extended-cache-ttl
2404
+ // beta — add it here (no-op unless the flag is set). If the upstream
2405
+ // 400s the flag on a non-sub account, the rejected-set strip below
2406
+ // drops it on the retry.
2407
+ beta = withForced1hBeta(beta);
2402
2408
  // Strip any beta flags the upstream has previously rejected on this
2403
2409
  // account so we don't re-pay the 400 round-trip (dario#42 afk-mode
2404
2410
  // fallout: captured templates carry tier-gated flags whose availability
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@askalf/dario",
3
- "version": "5.2.4",
3
+ "version": "5.2.5",
4
4
  "description": "Use your Claude Pro/Max subscription in any tool — Cursor, Cline, Aider, the Agent SDK, your scripts — at subscription pricing, not per-token API bills. One local Anthropic + OpenAI-compatible endpoint.",
5
5
  "type": "module",
6
6
  "bin": {