@cortexkit/anthropic-auth-core 2.4.2 → 2.4.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.
@@ -1,5 +1,6 @@
1
1
  import type { AccountStorage } from './accounts.ts';
2
2
  import type { CacheKeepTrackedSession } from './cachekeep-registry.ts';
3
+ import { type NativeAccountRefusalReason } from './native-account-refusal.ts';
3
4
  import { type ProviderErrorSummary } from './provider-error.ts';
4
5
  export declare const CLAUDE_CACHE_KEEP_COMMAND_NAME = "claude-cachekeep";
5
6
  export declare const CACHE_KEEP_TTL_MS: number;
@@ -60,7 +61,9 @@ export declare function executeCacheKeepCommand(input: {
60
61
  nextPrewarmAt?: number;
61
62
  hybridActive?: boolean;
62
63
  }): string;
63
- export declare function buildCacheKeepPrewarmBody(bodyText: string): Promise<{
64
+ export declare function buildCacheKeepPrewarmBody(bodyText: string, options?: {
65
+ stripServerFallback?: boolean;
66
+ }): Promise<{
64
67
  ok: true;
65
68
  bodyText: string;
66
69
  } | {
@@ -72,6 +75,7 @@ export type CacheKeepTarget = {
72
75
  url: string;
73
76
  headers: Record<string, string>;
74
77
  bodyText: string;
78
+ bodyBytes: number;
75
79
  cacheExpiresAt: number;
76
80
  nextPrewarmAt: number;
77
81
  consecutiveFailures: number;
@@ -80,7 +84,33 @@ export type CacheKeepTarget = {
80
84
  oauthAccountIdentity?: string;
81
85
  accountStoragePath?: string;
82
86
  isSubagent: boolean;
87
+ /**
88
+ * A recovery-round warm for the original (source) model, tracked under a
89
+ * key that cannot collide with the session's live target. It follows the
90
+ * same send, auth, retry and logging path; the caller stops it through
91
+ * untrack() when the round ends or its prefix becomes unusable.
92
+ */
93
+ sourceWarm?: boolean;
83
94
  };
95
+ /**
96
+ * Fingerprint of the cacheable prefix of a request body: tools, system
97
+ * blocks, and messages up to the last cache breakpoint. The billing header
98
+ * block is excluded because its signature is re-signed on every send, and
99
+ * everything past the last breakpoint (output limits, stream flags,
100
+ * thinking config) never affects the stored cache entry. Two bodies with
101
+ * the same fingerprint warm the same cache entry.
102
+ */
103
+ export declare function cacheWarmCacheablePrefixFingerprint(bodyText: string): string | undefined;
104
+ /**
105
+ * How many warms one idle recovery round may send before stopping: each
106
+ * warm pays a cache read, and the idle warms stay worth it while the reads
107
+ * sent since the last user turn cost less than one 1-hour rewrite, so the
108
+ * round stops after floor((1-hour write rate - read rate) / read rate)
109
+ * warms. Rates come from the source model's own catalogue pricing; models
110
+ * without catalogue facts (Opus 5) use the nearest sibling with 1-hour
111
+ * pricing.
112
+ */
113
+ export declare function cacheKeepSourceWarmIdleCap(modelId: string): number;
84
114
  export type CacheKeepPrewarmAttempt = {
85
115
  id: number;
86
116
  /** One deadline covers credential authorization and the HTTP attempt. */
@@ -88,6 +118,7 @@ export type CacheKeepPrewarmAttempt = {
88
118
  };
89
119
  export type CacheKeepPrewarmResult = {
90
120
  ok: true;
121
+ refused?: false;
91
122
  usage?: {
92
123
  input_tokens?: number;
93
124
  cache_creation_input_tokens?: number;
@@ -95,10 +126,26 @@ export type CacheKeepPrewarmResult = {
95
126
  };
96
127
  } | {
97
128
  ok: false;
129
+ refused?: false;
98
130
  reason: string;
131
+ refusal?: NativeAccountRefusalReason;
99
132
  status?: number;
100
133
  transient?: true;
101
134
  provider_error?: ProviderErrorSummary['provider_error'];
135
+ } | {
136
+ /** The warm was refused before any send; the target is removed. */
137
+ ok: false;
138
+ refused: true;
139
+ reason: string;
140
+ status?: undefined;
141
+ transient?: undefined;
142
+ provider_error?: undefined;
143
+ };
144
+ export type CacheKeepPrewarmValidation = {
145
+ ok: true;
146
+ } | {
147
+ ok: false;
148
+ reason: string;
102
149
  };
103
150
  export declare class CacheKeepManager {
104
151
  private readonly options;
@@ -125,6 +172,15 @@ export declare class CacheKeepManager {
125
172
  }) => Promise<Headers | undefined> | Headers | undefined;
126
173
  onTrackedSessionsChanged?: (sessions: readonly CacheKeepTrackedSession[]) => Promise<void> | void;
127
174
  prepareBody?: (bodyText: string, target: CacheKeepTarget) => string | Promise<string>;
175
+ /**
176
+ * Veto a prewarm after its body is built but before anything is
177
+ * sent. A refusal removes the target without sending. Throwing also
178
+ * refuses, so a failing check can never send a mismatched warm.
179
+ */
180
+ validatePrewarm?: (input: {
181
+ target: CacheKeepTarget;
182
+ warmBodyText: string;
183
+ }) => CacheKeepPrewarmValidation | Promise<CacheKeepPrewarmValidation>;
128
184
  onResponse?: (input: {
129
185
  target: CacheKeepTarget;
130
186
  bodyText: string;
@@ -148,6 +204,26 @@ export declare class CacheKeepManager {
148
204
  trackedOAuthRoute(sessionId: string): {
149
205
  oauthAccountId?: string;
150
206
  } | undefined;
207
+ /**
208
+ * The last request actually sent for a session, as tracked live: the
209
+ * exact signed bytes, destination, and account they went out on. A copy
210
+ * of the headers; the body string itself is shared, never re-serialized.
211
+ */
212
+ trackedRequest(id: string): {
213
+ bodyText: string;
214
+ url: string;
215
+ headers: Record<string, string>;
216
+ oauthAccountId?: string;
217
+ oauthAccountIdentity?: string;
218
+ isSubagent: boolean;
219
+ cacheExpiresAt: number;
220
+ } | undefined;
221
+ /**
222
+ * Stop warming a session without logging: the caller owns the reason
223
+ * (a finished recovery round, a model change, a cleared session) and
224
+ * logs it where the decision is made. Returns whether a target existed.
225
+ */
226
+ untrack(id: string): boolean;
151
227
  trackedCount(): number;
152
228
  /**
153
229
  * Drop targets whose cache has already expired, without sending or
@@ -157,6 +233,7 @@ export declare class CacheKeepManager {
157
233
  dropExpiredTargets(now?: number): number | undefined;
158
234
  private publishTrackedSessions;
159
235
  private totalBodyBytes;
236
+ private removeTarget;
160
237
  private evictOldestTarget;
161
238
  private pruneTargets;
162
239
  track(input: {
@@ -170,12 +247,12 @@ export declare class CacheKeepManager {
170
247
  oauthAccountIdentity?: string;
171
248
  accountStoragePath?: string;
172
249
  isSubagent?: boolean;
250
+ sourceWarm?: boolean;
173
251
  }): {
174
- tracked: boolean;
175
- reason: string;
252
+ tracked: true;
176
253
  } | {
177
- reason?: undefined;
178
- tracked: boolean;
254
+ tracked: false;
255
+ reason: string;
179
256
  };
180
257
  prewarmNow(input: {
181
258
  sessionId: string;
package/dist/index.d.ts CHANGED
@@ -24,6 +24,7 @@ export type { ClaudeCodeBetaLists, ClaudeModelCapabilities, ClaudeModelCatalogue
24
24
  export { CLAUDE_CODE_DEFAULT_BETAS, CLAUDE_MODEL_CAPABILITIES, getClaudeModelCapabilities, getClaudeModelCatalogue, pinsEffortOnEveryRequest, resolveClaudeModelCapabilities, } from './model-capabilities.ts';
25
25
  export * from './model-remap.ts';
26
26
  export * from './models.ts';
27
+ export * from './native-account-refusal.ts';
27
28
  export type { NativeAccountRuntime, NativeAccountRuntimeOptions, NativeAccountWriteInput, NativeApiSubject, NativeLocalAuthorizeOptions, NativeRelayUpdate, } from './native-account-runtime.ts';
28
29
  export { acquireNativeAccountRuntime, createNativeAccountRuntime, nativeAccountPolicy, } from './native-account-runtime.ts';
29
30
  export type { NativeAccountMetadataPatch, NativeAccountSnapshot, NativeAccountView, } from './native-account-view.ts';