@cortexkit/anthropic-auth-core 2.4.3 → 2.4.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.
@@ -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
  } | {
@@ -81,7 +84,33 @@ export type CacheKeepTarget = {
81
84
  oauthAccountIdentity?: string;
82
85
  accountStoragePath?: string;
83
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;
84
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;
85
114
  export type CacheKeepPrewarmAttempt = {
86
115
  id: number;
87
116
  /** One deadline covers credential authorization and the HTTP attempt. */
@@ -89,6 +118,7 @@ export type CacheKeepPrewarmAttempt = {
89
118
  };
90
119
  export type CacheKeepPrewarmResult = {
91
120
  ok: true;
121
+ refused?: false;
92
122
  usage?: {
93
123
  input_tokens?: number;
94
124
  cache_creation_input_tokens?: number;
@@ -96,10 +126,26 @@ export type CacheKeepPrewarmResult = {
96
126
  };
97
127
  } | {
98
128
  ok: false;
129
+ refused?: false;
99
130
  reason: string;
131
+ refusal?: NativeAccountRefusalReason;
100
132
  status?: number;
101
133
  transient?: true;
102
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;
103
149
  };
104
150
  export declare class CacheKeepManager {
105
151
  private readonly options;
@@ -125,7 +171,19 @@ export declare class CacheKeepManager {
125
171
  attempt: CacheKeepPrewarmAttempt;
126
172
  }) => Promise<Headers | undefined> | Headers | undefined;
127
173
  onTrackedSessionsChanged?: (sessions: readonly CacheKeepTrackedSession[]) => Promise<void> | void;
174
+ /** Hosts may mirror targets without delaying a live request on storage I/O. */
175
+ onTargetChanged?: (target: Readonly<CacheKeepTarget>) => void;
176
+ onTargetRemoved?: (id: string) => void;
128
177
  prepareBody?: (bodyText: string, target: CacheKeepTarget) => string | Promise<string>;
178
+ /**
179
+ * Veto a prewarm after its body is built but before anything is
180
+ * sent. A refusal removes the target without sending. Throwing also
181
+ * refuses, so a failing check can never send a mismatched warm.
182
+ */
183
+ validatePrewarm?: (input: {
184
+ target: CacheKeepTarget;
185
+ warmBodyText: string;
186
+ }) => CacheKeepPrewarmValidation | Promise<CacheKeepPrewarmValidation>;
129
187
  onResponse?: (input: {
130
188
  target: CacheKeepTarget;
131
189
  bodyText: string;
@@ -149,6 +207,26 @@ export declare class CacheKeepManager {
149
207
  trackedOAuthRoute(sessionId: string): {
150
208
  oauthAccountId?: string;
151
209
  } | undefined;
210
+ /**
211
+ * The last request actually sent for a session, as tracked live: the
212
+ * exact signed bytes, destination, and account they went out on. A copy
213
+ * of the headers; the body string itself is shared, never re-serialized.
214
+ */
215
+ trackedRequest(id: string): {
216
+ bodyText: string;
217
+ url: string;
218
+ headers: Record<string, string>;
219
+ oauthAccountId?: string;
220
+ oauthAccountIdentity?: string;
221
+ isSubagent: boolean;
222
+ cacheExpiresAt: number;
223
+ } | undefined;
224
+ /**
225
+ * Stop warming a session without logging: the caller owns the reason
226
+ * (a finished recovery round, a model change, a cleared session) and
227
+ * logs it where the decision is made. Returns whether a target existed.
228
+ */
229
+ untrack(id: string): boolean;
152
230
  trackedCount(): number;
153
231
  /**
154
232
  * Drop targets whose cache has already expired, without sending or
@@ -172,6 +250,9 @@ export declare class CacheKeepManager {
172
250
  oauthAccountIdentity?: string;
173
251
  accountStoragePath?: string;
174
252
  isSubagent?: boolean;
253
+ sourceWarm?: boolean;
254
+ /** Restore only the remaining lifetime, never grant a restarted cache a new hour. */
255
+ retained?: Pick<CacheKeepTarget, 'cacheExpiresAt' | 'nextPrewarmAt'>;
175
256
  }): {
176
257
  tracked: true;
177
258
  } | {
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';
@@ -65,7 +66,7 @@ export type { NativeVaultQuotaPurpose, NativeVaultRuntime, NativeVaultRuntimeOpt
65
66
  export { acquireNativeVaultRuntime, createNativeVaultRuntime, discoverNativeVaultInventory, publishNativeVaultRosterSeed, publishNativeVaultRuntimeSeed, } from './native-vault-runtime.ts';
66
67
  export * from './oauth-origin.ts';
67
68
  export * from './oauth-profile.ts';
68
- export { createWindowsOwnerOnly, ensureWindowsOwnerOnlyDirectory, isOwnerOnly, type OwnerOnlyOptions, } from './owner-only.ts';
69
+ export { createWindowsOwnerOnly, ensureWindowsOwnerOnlyDirectory, isOwnerOnly, type OwnerOnlyOptions, readWindowsOwnerOnly, } from './owner-only.ts';
69
70
  export * from './pkce.ts';
70
71
  export type { NativeEmptyInitJournal, NativeLegacyMigrationJournal, NativeMigrationJournal, } from './pool-authority.ts';
71
72
  export { nativeJournalMayAdoptLaterHostLogin, nativeMigrationAuthorityPhase, readNativeMigrationJournal, } from './pool-authority.ts';
@@ -77,6 +78,7 @@ export * from './prime.ts';
77
78
  export * from './provider.ts';
78
79
  export type { ProviderErrorRedactor, ProviderErrorResponseScope, ProviderErrorSummary, ProviderResponseMode, ProviderResponseSettlement, } from './provider-error.ts';
79
80
  export { createProviderErrorRedactor, createProviderErrorResponseScope, summarizePrewarmProviderError, } from './provider-error.ts';
81
+ export { renameWithWindowsSharingRetry } from './publication-rename.ts';
80
82
  export * from './quota-header-feed.ts';
81
83
  export * from './quota-headers.ts';
82
84
  export * from './quota-manager.ts';