@cortexkit/anthropic-auth-core 1.6.0 → 1.7.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/cch.d.ts CHANGED
@@ -24,12 +24,11 @@ export declare function signRequestBody(bodyString: string): Promise<string>;
24
24
  /**
25
25
  * Compute a stable 3-character suffix for cc_version.
26
26
  *
27
- * The previous implementation sampled the first user message, which could make
28
- * the system billing header change with conversation content. Keep this suffix
29
- * stable for a day so it resembles a rotating Claude Code fingerprint without
30
- * busting prompt-cache prefixes on every turn.
27
+ * The captured Claude Code version uses its observed build hash. Custom/future
28
+ * versions get a deterministic version-only suffix so date changes never rotate
29
+ * the billing header and bust prompt-cache prefixes.
31
30
  */
32
- export declare function computeVersionSuffix(version?: string, date?: Date): string;
31
+ export declare function computeVersionSuffix(version?: string, _date?: Date): string;
33
32
  /**
34
33
  * Build the billing header with a cch placeholder.
35
34
  * signRequestBody() must run after final request serialization to replace it.
package/dist/cch.js CHANGED
@@ -62,19 +62,14 @@ export async function signRequestBody(bodyString) {
62
62
  /**
63
63
  * Compute a stable 3-character suffix for cc_version.
64
64
  *
65
- * The previous implementation sampled the first user message, which could make
66
- * the system billing header change with conversation content. Keep this suffix
67
- * stable for a day so it resembles a rotating Claude Code fingerprint without
68
- * busting prompt-cache prefixes on every turn.
65
+ * The captured Claude Code version uses its observed build hash. Custom/future
66
+ * versions get a deterministic version-only suffix so date changes never rotate
67
+ * the billing header and bust prompt-cache prefixes.
69
68
  */
70
- export function computeVersionSuffix(version = CLAUDE_CODE_VERSION, date = new Date()) {
69
+ export function computeVersionSuffix(version = CLAUDE_CODE_VERSION, _date = new Date()) {
71
70
  if (version === CLAUDE_CODE_VERSION)
72
71
  return CLAUDE_CODE_BUILD_HASH;
73
- const dayStamp = date.toISOString().slice(0, 10);
74
- return createHash('sha256')
75
- .update(`${dayStamp}${version}`)
76
- .digest('hex')
77
- .slice(0, 3);
72
+ return createHash('sha256').update(version).digest('hex').slice(0, 3);
78
73
  }
79
74
  /**
80
75
  * Build the billing header with a cch placeholder.
package/dist/dump.js CHANGED
@@ -78,6 +78,15 @@ export function executeDumpCommand(input) {
78
78
  function shortAffinity(affinity) {
79
79
  return affinity.length <= 16 ? affinity : `${affinity.slice(0, 12)}…`;
80
80
  }
81
+ function dumpFileSessionSegment(affinity) {
82
+ const normalized = affinity
83
+ .trim()
84
+ .replace(/[^a-zA-Z0-9._-]+/g, '-')
85
+ .replace(/^-+|-+$/g, '');
86
+ if (!normalized)
87
+ return 'session-unknown';
88
+ return normalized.length <= 80 ? normalized : normalized.slice(0, 80);
89
+ }
81
90
  function hashText(value) {
82
91
  return createHash('sha256').update(value).digest('hex');
83
92
  }
@@ -184,7 +193,7 @@ export async function dumpRelayRequest(input) {
184
193
  if (!dumpEnabled)
185
194
  return;
186
195
  nextDumpId += 1;
187
- const id = `${new Date().toISOString().replace(/[:.]/g, '-')}-${String(nextDumpId).padStart(5, '0')}-${input.transport}-p${input.protocol}-${input.mode}`;
196
+ const id = `${new Date().toISOString().replace(/[:.]/g, '-')}-${String(nextDumpId).padStart(5, '0')}-${dumpFileSessionSegment(input.affinity)}-${input.transport}-p${input.protocol}-${input.mode}`;
188
197
  const dumpDir = getDumpDirectory();
189
198
  const prefix = join(dumpDir, id);
190
199
  try {
package/dist/relay.js CHANGED
@@ -4,6 +4,20 @@ import { dumpRelayRequest } from "./dump.js";
4
4
  import { relayLog } from "./logger.js";
5
5
  class RelayStateMismatchError extends Error {
6
6
  }
7
+ class RelayWebSocketConnectionResetError extends Error {
8
+ code = 'ECONNRESET';
9
+ syscall = 'websocket';
10
+ closeCode;
11
+ closeReason;
12
+ wasClean;
13
+ constructor(message, event) {
14
+ super(message);
15
+ this.name = 'RelayWebSocketConnectionResetError';
16
+ this.closeCode = event?.code;
17
+ this.closeReason = event?.reason;
18
+ this.wasClean = event?.wasClean;
19
+ }
20
+ }
7
21
  const sessionState = new Map();
8
22
  const websocketSessions = new Map();
9
23
  const loggedRelayConfigMessages = new Set();
@@ -370,7 +384,7 @@ class PersistentRelaySession {
370
384
  });
371
385
  socket.addEventListener('error', () => {
372
386
  clearTimeout(timeout);
373
- const error = new Error('relay websocket error');
387
+ const error = new RelayWebSocketConnectionResetError('relay websocket error');
374
388
  reject(error);
375
389
  this.failPending(error);
376
390
  });
@@ -390,9 +404,9 @@ class PersistentRelaySession {
390
404
  : 'closed before response';
391
405
  if (this.retryPendingBeforeResponse(this.pending, reason, event))
392
406
  return;
393
- const error = new Error(closedAfterResponseStart
394
- ? 'relay websocket closed during response stream'
395
- : 'relay websocket closed before response');
407
+ const error = closedAfterResponseStart
408
+ ? new RelayWebSocketConnectionResetError('relay websocket closed during response stream', event)
409
+ : new Error('relay websocket closed before response');
396
410
  relayLog(`websocket ${closedAfterResponseStart ? 'closed during response stream' : 'closed before response without retry'} session=${shortAffinity(this.affinity)} request=${this.pending.payload.id} chunks=${this.pending.streamChunkCount} bytes=${this.pending.streamByteCount} ${formatCloseEvent(event)}`);
397
411
  this.failPending(error);
398
412
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cortexkit/anthropic-auth-core",
3
- "version": "1.6.0",
3
+ "version": "1.7.0",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",