@cortexkit/anthropic-auth-core 1.19.0 → 1.20.0

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/auth.js CHANGED
@@ -1,5 +1,5 @@
1
- import { AUTHORIZE_URLS, AXIOS_USER_AGENT, CLIENT_ID, CODE_CALLBACK_URL, OAUTH_SCOPES, REFRESH_SCOPE, TOKEN_URL, } from "./constants.js";
2
- import { generatePKCE } from "./pkce.js";
1
+ import { AUTHORIZE_URLS, AXIOS_USER_AGENT, CLIENT_ID, CODE_CALLBACK_URL, OAUTH_SCOPES, REFRESH_SCOPE, TOKEN_URL, } from './constants.js';
2
+ import { generatePKCE } from './pkce.js';
3
3
  export function parseRetryAfterHeader(value) {
4
4
  if (!value)
5
5
  return undefined;
@@ -47,11 +47,12 @@ export async function refreshClaudeOAuthToken(input) {
47
47
  const fetchImpl = input.fetchImpl ?? fetch;
48
48
  const maxRetries = input.maxRetries ?? 2;
49
49
  const baseDelayMs = input.baseDelayMs ?? 500;
50
+ const setTimeoutImpl = input.setTimeoutImpl ?? globalThis.setTimeout;
50
51
  for (let attempt = 0; attempt <= maxRetries; attempt++) {
51
52
  try {
52
53
  if (attempt > 0) {
53
54
  const delay = baseDelayMs * 2 ** (attempt - 1);
54
- await new Promise((resolve) => setTimeout(resolve, delay));
55
+ await new Promise((resolve) => setTimeoutImpl(resolve, delay));
55
56
  }
56
57
  const response = await fetchImpl(TOKEN_URL, {
57
58
  method: 'POST',
@@ -82,6 +83,7 @@ export async function refreshClaudeOAuthToken(input) {
82
83
  refresh: json.refresh_token ?? input.refreshToken,
83
84
  expires: refreshedAt + json.expires_in * 1000,
84
85
  expiresIn: json.expires_in,
86
+ authLineageId: input.authLineageId,
85
87
  };
86
88
  }
87
89
  catch (error) {
package/dist/cache1h.d.ts CHANGED
@@ -13,7 +13,7 @@ export type Cache1hCommandAction = {
13
13
  type: 'usage';
14
14
  };
15
15
  export declare function isCache1hEnabled(): boolean;
16
- export declare function getCache1hMode(): "explicit" | "automatic" | "hybrid";
16
+ export declare function getCache1hMode(): "automatic" | "explicit" | "hybrid";
17
17
  export declare function setCache1hEnabled(enabled: boolean): void;
18
18
  export declare function setCache1hMode(mode: Cache1hMode): void;
19
19
  export declare function setCache1hState(input: {
package/dist/cache1h.js CHANGED
@@ -1,4 +1,4 @@
1
- import { DEFAULT_CACHE_1H_MODE } from "./constants.js";
1
+ import { DEFAULT_CACHE_1H_MODE } from './constants.js';
2
2
  export const CACHE_1H_COMMAND_NAME = 'claude-cache';
3
3
  const CACHE_1H_STATUS_TITLE = '## Claude Cache Status';
4
4
  const CACHE_1H_ENABLED_TITLE = '## Claude Cache Enabled';
@@ -7,8 +7,10 @@ export declare const CACHE_KEEP_TICK_MS = 60000;
7
7
  export declare const CACHE_KEEP_EXTENDED_TTL_BETA = "extended-cache-ttl-2025-04-11";
8
8
  export declare const CACHE_KEEP_MAX_TARGETS = 32;
9
9
  export declare const CACHE_KEEP_MAX_BODY_BYTES: number;
10
- export declare const CACHE_KEEP_STALE_TARGET_MS: number;
11
10
  export declare const CACHE_KEEP_PREWARM_TIMEOUT_MS = 30000;
11
+ export declare const CACHE_KEEP_RETRY_BASE_MS = 60000;
12
+ export declare const CACHE_KEEP_RETRY_MAX_MS: number;
13
+ export declare const CACHE_KEEP_RETRY_JITTER_MAX_MS = 30000;
12
14
  export type CacheKeepWindow = {
13
15
  startHour: number;
14
16
  endHour: number;
@@ -70,8 +72,11 @@ export type CacheKeepTarget = {
70
72
  headers: Record<string, string>;
71
73
  bodyText: string;
72
74
  cacheExpiresAt: number;
75
+ nextPrewarmAt: number;
76
+ consecutiveFailures: number;
73
77
  dayKey: string;
74
78
  oauthAccountId?: string;
79
+ isSubagent: boolean;
75
80
  };
76
81
  export type CacheKeepPrewarmResult = {
77
82
  ok: true;
@@ -84,18 +89,30 @@ export type CacheKeepPrewarmResult = {
84
89
  ok: false;
85
90
  reason: string;
86
91
  status?: number;
92
+ transient?: true;
87
93
  };
88
94
  export declare class CacheKeepManager {
89
95
  private readonly options;
90
96
  private readonly targets;
91
97
  private timer;
98
+ private tickPromise;
92
99
  constructor(options: {
93
100
  loadStorage: () => Promise<AccountStorage | null>;
94
101
  fetchImpl?: typeof fetch;
95
102
  now?: () => number;
96
103
  prewarmTimeoutMs?: number;
104
+ setIntervalImpl?: typeof globalThis.setInterval;
105
+ clearIntervalImpl?: typeof globalThis.clearInterval;
97
106
  prepareHeaders?: (headers: Headers, target: CacheKeepTarget) => Promise<Headers> | Headers;
98
107
  onTrackedSessionsChanged?: (sessions: readonly CacheKeepTrackedSession[]) => Promise<void> | void;
108
+ prepareBody?: (bodyText: string, target: CacheKeepTarget) => string | Promise<string>;
109
+ onResponse?: (input: {
110
+ target: CacheKeepTarget;
111
+ bodyText: string;
112
+ status: number;
113
+ data: unknown;
114
+ receivedAt: number;
115
+ }) => void | Promise<void>;
99
116
  });
100
117
  start(): void;
101
118
  stop(): void;
@@ -120,12 +137,13 @@ export declare class CacheKeepManager {
120
137
  storage: AccountStorage | null;
121
138
  cacheMode: string;
122
139
  oauthAccountId?: string;
140
+ isSubagent?: boolean;
123
141
  }): {
124
142
  tracked: boolean;
125
143
  reason: string;
126
144
  } | {
127
- tracked: boolean;
128
145
  reason?: undefined;
146
+ tracked: boolean;
129
147
  };
130
148
  prewarmNow(input: {
131
149
  sessionId: string;
@@ -133,8 +151,10 @@ export declare class CacheKeepManager {
133
151
  headers: Headers;
134
152
  bodyText: string;
135
153
  oauthAccountId?: string;
154
+ isSubagent?: boolean;
136
155
  }): Promise<CacheKeepPrewarmResult>;
137
156
  tick(): Promise<void>;
157
+ private runTick;
138
158
  private sendPrewarm;
139
159
  private prewarm;
140
160
  }
package/dist/cachekeep.js CHANGED
@@ -1,6 +1,7 @@
1
- import { signRequestBody } from "./cch.js";
2
- import { orderClaudeCodeBody } from "./claude-code.js";
3
- import { logger } from "./logger.js";
1
+ import { signRequestBody } from './cch.js';
2
+ import { orderClaudeCodeBody } from './claude-code.js';
3
+ import { dumpDirectRequest, dumpResponseArtifact } from './dump.js';
4
+ import { logger } from './logger.js';
4
5
  export const CLAUDE_CACHE_KEEP_COMMAND_NAME = 'claude-cachekeep';
5
6
  export const CACHE_KEEP_TTL_MS = 60 * 60_000;
6
7
  export const CACHE_KEEP_PREWARM_LEAD_MS = 5 * 60_000;
@@ -8,8 +9,10 @@ export const CACHE_KEEP_TICK_MS = 60_000;
8
9
  export const CACHE_KEEP_EXTENDED_TTL_BETA = 'extended-cache-ttl-2025-04-11';
9
10
  export const CACHE_KEEP_MAX_TARGETS = 32;
10
11
  export const CACHE_KEEP_MAX_BODY_BYTES = 16 * 1024 * 1024;
11
- export const CACHE_KEEP_STALE_TARGET_MS = 2 * CACHE_KEEP_TTL_MS;
12
12
  export const CACHE_KEEP_PREWARM_TIMEOUT_MS = 30_000;
13
+ export const CACHE_KEEP_RETRY_BASE_MS = 60_000;
14
+ export const CACHE_KEEP_RETRY_MAX_MS = 15 * 60_000;
15
+ export const CACHE_KEEP_RETRY_JITTER_MAX_MS = 30_000;
13
16
  const STATUS_TITLE = '## Claude Cache Keep Status';
14
17
  const ENABLED_TITLE = '## Claude Cache Keep Enabled';
15
18
  const DISABLED_TITLE = '## Claude Cache Keep Disabled';
@@ -228,10 +231,22 @@ export async function buildCacheKeepPrewarmBody(bodyText) {
228
231
  const signedBodyText = await signRequestBody(JSON.stringify(orderClaudeCodeBody(warm)));
229
232
  return { ok: true, bodyText: signedBodyText };
230
233
  }
234
+ function cacheKeepRetryDelayMs(targetId, failureCount) {
235
+ const exponential = Math.min(CACHE_KEEP_RETRY_MAX_MS, CACHE_KEEP_RETRY_BASE_MS * 2 ** Math.min(Math.max(failureCount - 1, 0), 8));
236
+ let hash = 2_166_136_261;
237
+ for (const character of `${targetId}:${failureCount}`) {
238
+ hash ^= character.charCodeAt(0);
239
+ hash = Math.imul(hash, 16_777_619);
240
+ }
241
+ const jitter = (hash >>> 0) %
242
+ (Math.min(CACHE_KEEP_RETRY_JITTER_MAX_MS, exponential / 4) + 1);
243
+ return exponential + jitter;
244
+ }
231
245
  export class CacheKeepManager {
232
246
  options;
233
247
  targets = new Map();
234
248
  timer = null;
249
+ tickPromise = null;
235
250
  constructor(options) {
236
251
  this.options = options;
237
252
  }
@@ -239,7 +254,7 @@ export class CacheKeepManager {
239
254
  if (this.timer)
240
255
  return;
241
256
  logger.debug('cachekeep', 'started');
242
- this.timer = setInterval(() => {
257
+ this.timer = (this.options.setIntervalImpl ?? globalThis.setInterval)(() => {
243
258
  void this.tick().catch((error) => {
244
259
  logger.warn('cachekeep', 'tick failed', {
245
260
  error: error instanceof Error ? error.message : String(error),
@@ -253,14 +268,15 @@ export class CacheKeepManager {
253
268
  if (!this.timer)
254
269
  return;
255
270
  logger.debug('cachekeep', 'stopped');
256
- clearInterval(this.timer);
271
+ const clearIntervalImpl = this.options.clearIntervalImpl ?? globalThis.clearInterval;
272
+ clearIntervalImpl(this.timer);
257
273
  this.timer = null;
258
274
  }
259
275
  stats(window, now = this.options.now?.() ?? Date.now(), always = false) {
260
276
  const today = always ? 'always' : localWindowKey(window, new Date(now));
261
277
  const targets = [...this.targets.values()].filter((target) => target.dayKey === today);
262
278
  const nextPrewarmAt = targets.length
263
- ? Math.min(...targets.map((target) => target.cacheExpiresAt - CACHE_KEEP_PREWARM_LEAD_MS))
279
+ ? Math.min(...targets.map((target) => target.nextPrewarmAt))
264
280
  : undefined;
265
281
  return { trackedSessions: targets.length, nextPrewarmAt };
266
282
  }
@@ -269,7 +285,7 @@ export class CacheKeepManager {
269
285
  .map((target) => ({
270
286
  id: target.id,
271
287
  cacheExpiresAt: target.cacheExpiresAt,
272
- nextPrewarmAt: target.cacheExpiresAt - CACHE_KEEP_PREWARM_LEAD_MS,
288
+ nextPrewarmAt: target.nextPrewarmAt,
273
289
  }))
274
290
  .sort((left, right) => left.id.localeCompare(right.id));
275
291
  }
@@ -311,9 +327,8 @@ export class CacheKeepManager {
311
327
  this.targets.delete(id);
312
328
  continue;
313
329
  }
314
- if (now - target.cacheExpiresAt > CACHE_KEEP_STALE_TARGET_MS) {
330
+ if (now >= target.cacheExpiresAt)
315
331
  this.targets.delete(id);
316
- }
317
332
  }
318
333
  while (this.targets.size > CACHE_KEEP_MAX_TARGETS)
319
334
  this.evictOldestTarget();
@@ -355,8 +370,11 @@ export class CacheKeepManager {
355
370
  headers,
356
371
  bodyText: input.bodyText,
357
372
  cacheExpiresAt: now + CACHE_KEEP_TTL_MS,
373
+ nextPrewarmAt: now + CACHE_KEEP_TTL_MS - CACHE_KEEP_PREWARM_LEAD_MS,
374
+ consecutiveFailures: 0,
358
375
  dayKey: today,
359
376
  oauthAccountId: input.oauthAccountId,
377
+ isSubagent: input.isSubagent ?? false,
360
378
  });
361
379
  this.pruneTargets(now, today);
362
380
  this.publishTrackedSessions();
@@ -374,12 +392,26 @@ export class CacheKeepManager {
374
392
  headers,
375
393
  bodyText: input.bodyText,
376
394
  cacheExpiresAt: this.options.now?.() ?? Date.now(),
395
+ nextPrewarmAt: this.options.now?.() ?? Date.now(),
396
+ consecutiveFailures: 0,
377
397
  dayKey: '',
378
398
  oauthAccountId: input.oauthAccountId,
399
+ isSubagent: input.isSubagent ?? false,
379
400
  };
380
401
  return this.sendPrewarm(target);
381
402
  }
382
- async tick() {
403
+ tick() {
404
+ if (this.tickPromise)
405
+ return this.tickPromise;
406
+ let run;
407
+ run = this.runTick().finally(() => {
408
+ if (this.tickPromise === run)
409
+ this.tickPromise = null;
410
+ });
411
+ this.tickPromise = run;
412
+ return run;
413
+ }
414
+ async runTick() {
383
415
  const storage = await this.options.loadStorage();
384
416
  const window = getCacheKeepWindow(storage);
385
417
  const now = this.options.now?.() ?? Date.now();
@@ -403,49 +435,120 @@ export class CacheKeepManager {
403
435
  return;
404
436
  }
405
437
  logger.debug('cachekeep', 'fired', { targets: this.targets.size });
406
- const dueAt = now + CACHE_KEEP_PREWARM_LEAD_MS;
407
438
  for (const target of this.targets.values()) {
408
- if (target.cacheExpiresAt > dueAt)
439
+ if (target.nextPrewarmAt > now)
409
440
  continue;
410
- await this.prewarm(target, now);
441
+ try {
442
+ await this.prewarm(target, now);
443
+ }
444
+ catch (error) {
445
+ logger.warn('cachekeep', 'prewarm failed', {
446
+ session: target.id,
447
+ reason: error instanceof Error ? error.message : String(error),
448
+ });
449
+ target.consecutiveFailures += 1;
450
+ target.nextPrewarmAt =
451
+ now + cacheKeepRetryDelayMs(target.id, target.consecutiveFailures);
452
+ }
411
453
  }
412
454
  this.publishTrackedSessions();
413
455
  }
414
456
  async sendPrewarm(target) {
415
- const prewarm = await buildCacheKeepPrewarmBody(target.bodyText);
457
+ let bodyText = target.bodyText;
458
+ if (this.options.prepareBody) {
459
+ try {
460
+ bodyText = await this.options.prepareBody(bodyText, target);
461
+ }
462
+ catch (error) {
463
+ logger.warn('cachekeep', 'prepare body failed', {
464
+ session: target.id,
465
+ error: error instanceof Error ? error.message : String(error),
466
+ });
467
+ }
468
+ }
469
+ const preparedTarget = { ...target, bodyText };
470
+ const prewarm = await buildCacheKeepPrewarmBody(bodyText);
416
471
  if (!prewarm.ok)
417
472
  return prewarm;
418
473
  const fetchImpl = this.options.fetchImpl ?? fetch;
419
- const prewarmTarget = { ...target, bodyText: prewarm.bodyText };
474
+ const prewarmTarget = { ...preparedTarget, bodyText: prewarm.bodyText };
420
475
  const headers = this.options.prepareHeaders
421
476
  ? await this.options.prepareHeaders(new Headers(target.headers), prewarmTarget)
422
477
  : new Headers(target.headers);
423
478
  headers.delete('content-length');
424
479
  headers.delete('transfer-encoding');
425
- const response = await fetchImpl(target.url, {
426
- method: 'POST',
427
- headers,
428
- body: prewarm.bodyText,
429
- signal: AbortSignal.timeout(this.options.prewarmTimeoutMs ?? CACHE_KEEP_PREWARM_TIMEOUT_MS),
430
- });
480
+ let response;
481
+ try {
482
+ response = await fetchImpl(target.url, {
483
+ method: 'POST',
484
+ headers,
485
+ body: prewarm.bodyText,
486
+ signal: AbortSignal.timeout(this.options.prewarmTimeoutMs ?? CACHE_KEEP_PREWARM_TIMEOUT_MS),
487
+ });
488
+ }
489
+ catch (error) {
490
+ return {
491
+ ok: false,
492
+ reason: error instanceof Error ? error.message : String(error),
493
+ transient: true,
494
+ };
495
+ }
496
+ const receivedAt = this.options.now?.() ?? Date.now();
497
+ const raw = await response.text().catch(() => '');
498
+ let data = null;
499
+ try {
500
+ data = raw ? JSON.parse(raw) : null;
501
+ }
502
+ catch { }
503
+ try {
504
+ await this.options.onResponse?.({
505
+ target,
506
+ bodyText: prewarm.bodyText,
507
+ status: response.status,
508
+ data,
509
+ receivedAt,
510
+ });
511
+ }
512
+ catch { }
513
+ try {
514
+ const dumpHandle = await dumpDirectRequest({
515
+ affinity: target.id,
516
+ route: 'cachekeep',
517
+ status: response.status,
518
+ bodyText: prewarm.bodyText,
519
+ url: target.url,
520
+ method: 'POST',
521
+ headers,
522
+ tag: 'cachekeep',
523
+ });
524
+ await dumpResponseArtifact(dumpHandle, {
525
+ status: response.status,
526
+ message: data,
527
+ });
528
+ }
529
+ catch (error) {
530
+ logger.debug('cachekeep', 'dump failed', {
531
+ session: target.id,
532
+ error: error instanceof Error ? error.message : String(error),
533
+ });
534
+ }
431
535
  if (!response.ok) {
432
536
  return {
433
537
  ok: false,
434
- reason: await response
435
- .text()
436
- .catch(() => '')
437
- .then((body) => body || `HTTP ${response.status}`),
538
+ reason: raw || `HTTP ${response.status}`,
438
539
  status: response.status,
439
540
  };
440
541
  }
441
- const data = (await response.json().catch(() => null));
442
- const usage = data?.usage;
542
+ const objectData = data && typeof data === 'object' && !Array.isArray(data)
543
+ ? data
544
+ : null;
545
+ const usage = objectData?.usage;
443
546
  return { ok: true, ...(usage && { usage }) };
444
547
  }
445
548
  async prewarm(target, now) {
446
549
  const result = await this.sendPrewarm(target);
447
550
  if (!result.ok) {
448
- if (result.status == null) {
551
+ if (result.status == null && !result.transient) {
449
552
  logger.debug('cachekeep', 'prewarm skipped', {
450
553
  session: target.id,
451
554
  reason: result.reason,
@@ -458,11 +561,15 @@ export class CacheKeepManager {
458
561
  status: result.status,
459
562
  reason: result.reason,
460
563
  });
461
- target.cacheExpiresAt = now + CACHE_KEEP_PREWARM_LEAD_MS + 5 * 60_000;
564
+ target.consecutiveFailures += 1;
565
+ target.nextPrewarmAt =
566
+ now + cacheKeepRetryDelayMs(target.id, target.consecutiveFailures);
462
567
  }
463
568
  return;
464
569
  }
465
570
  target.cacheExpiresAt = now + CACHE_KEEP_TTL_MS;
571
+ target.nextPrewarmAt = target.cacheExpiresAt - CACHE_KEEP_PREWARM_LEAD_MS;
572
+ target.consecutiveFailures = 0;
466
573
  logger.debug('cachekeep', 'prewarm succeeded', {
467
574
  session: target.id,
468
575
  ...(result.usage && { usage: result.usage }),
package/dist/cch.d.ts CHANGED
@@ -18,6 +18,7 @@ export declare function extractFirstUserMessageText(messages: Message[]): string
18
18
  * masks to 20 bits, and writes that value into the billing-header placeholder.
19
19
  */
20
20
  export declare function computeCCH(bodyBytes: Uint8Array): Promise<string>;
21
+ export declare function computeXxhash64Hex(value: string): Promise<string>;
21
22
  export declare function resetBillingHeaderCCH(bodyString: string): string;
22
23
  export declare function extractBillingHeaderCCH(bodyString: string): string | null;
23
24
  export declare function signRequestBody(bodyString: string): Promise<string>;
package/dist/cch.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { createHash } from 'node:crypto';
2
2
  import xxhashInit from 'xxhash-wasm';
3
- import { CLAUDE_CODE_BUILD_HASH, CLAUDE_CODE_VERSION } from "./constants.js";
3
+ import { CLAUDE_CODE_BUILD_HASH, CLAUDE_CODE_VERSION } from './constants.js';
4
4
  const CCH_SEED = 0x6e52736ac806831en;
5
5
  const CCH_PLACEHOLDER = 'cch=00000;';
6
6
  export const CCH_PATTERN = /\bcch=([0-9a-f]{5});/;
@@ -46,6 +46,11 @@ export async function computeCCH(bodyBytes) {
46
46
  const hash = xxhash64Raw?.(bodyBytes, CCH_SEED) ?? 0n;
47
47
  return (hash & 0xfffffn).toString(16).padStart(5, '0');
48
48
  }
49
+ export async function computeXxhash64Hex(value) {
50
+ await ensureXxhash();
51
+ const hash = xxhash64Raw?.(new TextEncoder().encode(value), 0n) ?? 0n;
52
+ return hash.toString(16).padStart(16, '0').slice(0, 16);
53
+ }
49
54
  export function resetBillingHeaderCCH(bodyString) {
50
55
  return bodyString.replace(BILLING_HEADER_CCH_PATTERN, `$1${CCH_PLACEHOLDER}`);
51
56
  }
@@ -3,11 +3,12 @@ export type ClaudeCodeIdentity = {
3
3
  accountUuid?: string;
4
4
  sessionId: string;
5
5
  };
6
+ export declare function setBounded<K, V>(map: Map<K, V>, key: K, value: V, limit?: number): void;
6
7
  export declare function getClaudeCodeIdentity(seed: string): ClaudeCodeIdentity;
7
8
  export declare function resolveClaudeCodeIdentity(accessToken: string, model?: string): Promise<ClaudeCodeIdentity>;
8
9
  export declare function buildClaudeCodeMetadataUserId(identity: ClaudeCodeIdentity): string | null;
9
10
  export declare function applyClaudeCodeMetadata(body: Record<string, unknown>, identity: ClaudeCodeIdentity): boolean;
10
- export declare const CLAUDE_CODE_FULL_AGENT_BETAS: readonly ["oauth-2025-04-20", "interleaved-thinking-2025-05-14", "thinking-token-count-2026-05-13", "context-management-2025-06-27", "prompt-caching-scope-2026-01-05", "claude-code-20250219", "advisor-tool-2026-03-01", "advanced-tool-use-2025-11-20", "extended-cache-ttl-2025-04-11", "cache-diagnosis-2026-04-07"];
11
+ export declare const CLAUDE_CODE_FULL_AGENT_BETAS: readonly ['oauth-2025-04-20', 'interleaved-thinking-2025-05-14', 'thinking-token-count-2026-05-13', 'context-management-2025-06-27', 'prompt-caching-scope-2026-01-05', 'claude-code-20250219', 'advisor-tool-2026-03-01', 'advanced-tool-use-2025-11-20', 'extended-cache-ttl-2025-04-11', 'cache-diagnosis-2026-04-07'];
11
12
  export declare function selectClaudeCodeBetas(body?: Record<string, unknown> | null, extraBetas?: string[]): string;
12
13
  export declare function applyClaudeCodeHeaders(headers: Headers, accessToken: string, options?: {
13
14
  body?: Record<string, unknown> | null;
@@ -1,9 +1,9 @@
1
1
  import { randomBytes, randomUUID } from 'node:crypto';
2
- import { CLAUDE_CODE_BUILD_HASH, CLAUDE_CODE_ENTRYPOINT, CLAUDE_CODE_STAINLESS_PACKAGE_VERSION, CLAUDE_CODE_STAINLESS_RUNTIME_VERSION, CLAUDE_CODE_VERSION, FAST_MODE_BETA, USER_AGENT, } from "./constants.js";
2
+ import { CLAUDE_CODE_BUILD_HASH, CLAUDE_CODE_ENTRYPOINT, CLAUDE_CODE_STAINLESS_PACKAGE_VERSION, CLAUDE_CODE_STAINLESS_RUNTIME_VERSION, CLAUDE_CODE_VERSION, FAST_MODE_BETA, USER_AGENT, } from './constants.js';
3
3
  const IDENTITY_CACHE_LIMIT = 1_000;
4
4
  const identityCache = new Map();
5
- function setBounded(map, key, value) {
6
- if (!map.has(key) && map.size >= IDENTITY_CACHE_LIMIT) {
5
+ export function setBounded(map, key, value, limit = IDENTITY_CACHE_LIMIT) {
6
+ if (!map.has(key) && map.size >= limit) {
7
7
  const oldest = map.keys().next().value;
8
8
  if (oldest !== undefined)
9
9
  map.delete(oldest);
@@ -1,4 +1,4 @@
1
- import { formatOAuthAccountTier } from "../oauth-profile.js";
1
+ import { formatOAuthAccountTier } from '../oauth-profile.js';
2
2
  export const CLAUDE_ACCOUNT_COMMAND_NAME = 'claude-account';
3
3
  export function parseAccountCommandAction(argumentsText) {
4
4
  const parts = argumentsText.trim().split(/\s+/).filter(Boolean);
@@ -1,7 +1,7 @@
1
1
  export declare const CLIENT_ID = "9d1c250a-e61b-44d9-88ed-5944d1962f5e";
2
2
  export declare const AUTHORIZE_URLS: {
3
- readonly console: "https://platform.claude.com/oauth/authorize";
4
- readonly max: "https://claude.com/cai/oauth/authorize";
3
+ readonly console: 'https://platform.claude.com/oauth/authorize';
4
+ readonly max: 'https://claude.com/cai/oauth/authorize';
5
5
  };
6
6
  export declare const CODE_CALLBACK_URL = "https://platform.claude.com/oauth/code/callback";
7
7
  export declare const TOKEN_URL = "https://platform.claude.com/v1/oauth/token";
@@ -24,7 +24,7 @@ export declare const CLAUDE_CODE_ENTRYPOINT = "cli";
24
24
  export declare const CLAUDE_CODE_STAINLESS_PACKAGE_VERSION = "0.94.0";
25
25
  export declare const CLAUDE_CODE_STAINLESS_RUNTIME_VERSION = "v24.3.0";
26
26
  export declare const USER_AGENT = "claude-cli/2.1.177 (external, cli)";
27
- export declare const CACHE_1H_MODES: readonly ["explicit", "automatic", "hybrid"];
27
+ export declare const CACHE_1H_MODES: readonly ['explicit', 'automatic', 'hybrid'];
28
28
  export type Cache1hMode = (typeof CACHE_1H_MODES)[number];
29
29
  export declare const DEFAULT_CACHE_1H_MODE: Cache1hMode;
30
30
  /**
package/dist/dump.d.ts CHANGED
@@ -9,6 +9,11 @@ export type DumpCommandAction = {
9
9
  } | {
10
10
  type: 'usage';
11
11
  };
12
+ export type DumpTag = 'cachekeep' | 'start';
13
+ export type DumpHandle = {
14
+ responsePath: string;
15
+ tag?: DumpTag;
16
+ };
12
17
  export declare function isDumpEnabled(): boolean;
13
18
  export declare function setDumpEnabled(enabled: boolean): void;
14
19
  export declare function resetDumpState(): void;
@@ -49,7 +54,8 @@ export declare function dumpDirectRequest(input: {
49
54
  url?: string;
50
55
  method?: string;
51
56
  headers?: DumpHeaders;
52
- }): Promise<void>;
57
+ tag?: DumpTag;
58
+ }): Promise<DumpHandle | null>;
53
59
  export declare function dumpRelayRequest(input: {
54
60
  affinity: string;
55
61
  transport: 'http' | 'websocket';
@@ -60,5 +66,10 @@ export declare function dumpRelayRequest(input: {
60
66
  previousBodyText?: string;
61
67
  payload: unknown;
62
68
  relayBytes: number;
69
+ tag?: DumpTag;
70
+ }): Promise<DumpHandle | null>;
71
+ export declare function dumpResponseArtifact(handle: DumpHandle | null, input: {
72
+ status: number;
73
+ message: unknown;
63
74
  }): Promise<void>;
64
75
  export {};