@cortexkit/anthropic-auth-core 2.13.0 → 2.14.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/cachekeep-store.d.ts +6 -2
- package/dist/cachekeep.d.ts +50 -5
- package/dist/index.js +616 -152
- package/dist/internal-types/routing-accessor/cache-policy.d.ts +2 -2
- package/dist/internal-types/store/index.d.ts +1 -1
- package/dist/internal-types/store/settings.d.ts +8 -0
- package/dist/pool-store.d.ts +0 -7
- package/dist/session-cache-policy.d.ts +10 -2
- package/package.json +2 -2
|
@@ -7,7 +7,11 @@ export type SavedCacheKeepTarget = Pick<CacheKeepTarget, 'id' | 'bodyText' | 'ur
|
|
|
7
7
|
v: typeof RECORD_FORMAT_VERSION;
|
|
8
8
|
pluginVersion: string;
|
|
9
9
|
};
|
|
10
|
-
type Acceptance = boolean | 'foreign-identity' | 'account-gone' | 'invalid' | undefined;
|
|
10
|
+
type Acceptance = boolean | 'expired' | 'foreign-identity' | 'account-gone' | 'invalid' | undefined;
|
|
11
|
+
export type CacheKeepStoreRelease = (() => Promise<void>) & {
|
|
12
|
+
/** Pure ownership check, repeated immediately before unlinking. */
|
|
13
|
+
canRemove?: () => boolean | Promise<boolean>;
|
|
14
|
+
};
|
|
11
15
|
export interface CacheKeepStoreOptions {
|
|
12
16
|
storageId: string;
|
|
13
17
|
pluginVersion: string;
|
|
@@ -41,7 +45,7 @@ export declare class CacheKeepStore {
|
|
|
41
45
|
private writeFailed;
|
|
42
46
|
private directoryReady;
|
|
43
47
|
private enqueue;
|
|
44
|
-
load(now: number, accept: (entry: SavedCacheKeepTarget) => Acceptance, claim?: (sessionHash: string) => Promise<(
|
|
48
|
+
load(now: number, accept: (entry: SavedCacheKeepTarget) => Acceptance, claim?: (sessionHash: string) => Promise<CacheKeepStoreRelease | undefined>, guard?: (sessionHash: string) => boolean | Promise<boolean>): Promise<void>;
|
|
45
49
|
changed(target: Readonly<CacheKeepTarget>): void;
|
|
46
50
|
private flush;
|
|
47
51
|
/**
|
package/dist/cachekeep.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { type CacheWarmStopReason } from "./internal-types/routing-accessor/index.js";
|
|
2
1
|
import type { AccountSettingsReaderInput, AccountStorage } from './accounts.ts';
|
|
3
2
|
import { type AnthropicBillingRequest, type AnthropicBillingWarming } from './billing.ts';
|
|
4
3
|
import { type CacheKeepFailure } from './cachekeep-failure.ts';
|
|
5
4
|
import type { CacheKeepStopReason, CacheKeepTrackedSession } from './cachekeep-registry.ts';
|
|
6
5
|
import { type NativeAccountRefusalReason } from './native-account-refusal.ts';
|
|
7
6
|
import { type ProviderErrorSummary } from './provider-error.ts';
|
|
7
|
+
import { type SessionCachePolicy } from './session-cache-policy.ts';
|
|
8
8
|
export declare const CLAUDE_CACHE_KEEP_COMMAND_NAME = "claude-cachekeep";
|
|
9
9
|
export declare const CACHE_KEEP_TTL_MS: number;
|
|
10
10
|
export declare const CACHE_KEEP_PREWARM_LEAD_MS: number;
|
|
@@ -79,6 +79,8 @@ export declare function buildCacheKeepPrewarmBody(bodyText: string, options?: {
|
|
|
79
79
|
export type CacheKeepPolicyState = {
|
|
80
80
|
ownerSessionId: string;
|
|
81
81
|
planned: boolean;
|
|
82
|
+
/** Last Thalamus policy, used on restart until its routing bridge can read the session again. */
|
|
83
|
+
policy?: SessionCachePolicy;
|
|
82
84
|
lastRealRequestAt: number;
|
|
83
85
|
lastWarmAt?: number;
|
|
84
86
|
warmsSinceLastRealRequest: number;
|
|
@@ -104,6 +106,8 @@ export type CacheKeepTarget = {
|
|
|
104
106
|
dayKey: string;
|
|
105
107
|
oauthAccountId?: string;
|
|
106
108
|
oauthAccountIdentity?: string;
|
|
109
|
+
/** Host-owned facts carried with this target, never interpreted or persisted by Core. */
|
|
110
|
+
hostMetadata?: Readonly<Record<string, unknown>>;
|
|
107
111
|
accountStoragePath?: string;
|
|
108
112
|
isSubagent: boolean;
|
|
109
113
|
policyState?: CacheKeepPolicyState;
|
|
@@ -143,6 +147,8 @@ export type CacheKeepPrewarmAttempt = {
|
|
|
143
147
|
id: number;
|
|
144
148
|
/** One deadline covers credential authorization and the HTTP attempt. */
|
|
145
149
|
signal?: AbortSignal;
|
|
150
|
+
/** Buffered host senders call this as soon as the physical response headers arrive. */
|
|
151
|
+
onResponseHeaders?: () => void;
|
|
146
152
|
};
|
|
147
153
|
export type CacheKeepPrewarmResult = {
|
|
148
154
|
ok: true;
|
|
@@ -160,6 +166,8 @@ export type CacheKeepPrewarmResult = {
|
|
|
160
166
|
refusal?: NativeAccountRefusalReason;
|
|
161
167
|
status?: number;
|
|
162
168
|
transient?: true;
|
|
169
|
+
/** Eligibility changed while queued; keep the target without sending. */
|
|
170
|
+
skipped?: true;
|
|
163
171
|
provider_error?: ProviderErrorSummary['provider_error'];
|
|
164
172
|
stage?: CacheKeepFailure['stage'];
|
|
165
173
|
class?: CacheKeepFailure['class'];
|
|
@@ -179,9 +187,24 @@ export type CacheKeepPrewarmValidation = {
|
|
|
179
187
|
reason: string;
|
|
180
188
|
};
|
|
181
189
|
export declare class CacheKeepWarmRefusal extends Error {
|
|
182
|
-
readonly reason:
|
|
183
|
-
constructor(reason:
|
|
190
|
+
readonly reason: string;
|
|
191
|
+
constructor(reason: string);
|
|
184
192
|
}
|
|
193
|
+
declare const CACHE_KEEP_WARM_WAIT: unique symbol;
|
|
194
|
+
declare class CacheKeepWarmWait extends Error {
|
|
195
|
+
readonly [CACHE_KEEP_WARM_WAIT] = true;
|
|
196
|
+
}
|
|
197
|
+
/** Preserve nonterminal waits across independently loaded host/Core bundles. */
|
|
198
|
+
export declare function isCacheKeepWarmWait(error: unknown): error is CacheKeepWarmWait;
|
|
199
|
+
export interface CacheKeepRealTurn {
|
|
200
|
+
readonly active: boolean;
|
|
201
|
+
track(input: Parameters<CacheKeepManager['track']>[0]): ReturnType<CacheKeepManager['track']>;
|
|
202
|
+
finish(): void;
|
|
203
|
+
/** Release a host being paused without terminally ending its retained target. */
|
|
204
|
+
pause(): void;
|
|
205
|
+
}
|
|
206
|
+
export declare const currentCacheKeepRealTurn: () => CacheKeepRealTurn | undefined;
|
|
207
|
+
export declare function withCacheKeepRealTurn<T>(turn: CacheKeepRealTurn | undefined, run: () => T): T;
|
|
185
208
|
export declare class CacheKeepManager {
|
|
186
209
|
private readonly options;
|
|
187
210
|
private readonly targets;
|
|
@@ -191,8 +214,19 @@ export declare class CacheKeepManager {
|
|
|
191
214
|
private timer;
|
|
192
215
|
private dueTimer;
|
|
193
216
|
private tickPromise;
|
|
217
|
+
private lifetime;
|
|
218
|
+
private schedulerGeneration;
|
|
219
|
+
private nextRealTurn;
|
|
220
|
+
private readonly realTurns;
|
|
221
|
+
private readonly turnTimers;
|
|
222
|
+
private readonly ticks;
|
|
223
|
+
private readonly warmRuns;
|
|
224
|
+
private readonly warmControllers;
|
|
194
225
|
private nextPrewarmAttemptId;
|
|
195
226
|
private readonly reportedStops;
|
|
227
|
+
private readonly restoredTargets;
|
|
228
|
+
private readonly restoringPolicies;
|
|
229
|
+
private readonly sessionWarms;
|
|
196
230
|
private readonly admittedWarmCosts;
|
|
197
231
|
constructor(options: {
|
|
198
232
|
loadStorage: () => Promise<AccountStorage | null>;
|
|
@@ -263,6 +297,14 @@ export declare class CacheKeepManager {
|
|
|
263
297
|
});
|
|
264
298
|
start(): void;
|
|
265
299
|
stop(): void;
|
|
300
|
+
/** Release a closed host lifetime without retiring its saved restart records. */
|
|
301
|
+
dispose(): Promise<void>;
|
|
302
|
+
abortWarms(): void;
|
|
303
|
+
/** Join current work without waiting for a successor host's later sends. */
|
|
304
|
+
drain(): Promise<void>;
|
|
305
|
+
/** A request owns its busy lease; an older completion cannot retire a newer turn. */
|
|
306
|
+
beginRealTurn(sessionId: string): CacheKeepRealTurn;
|
|
307
|
+
private realTurnBusy;
|
|
266
308
|
stats(window?: CacheKeepWindow, now?: number, always?: boolean): {
|
|
267
309
|
trackedSessions: number;
|
|
268
310
|
nextPrewarmAt: number | undefined;
|
|
@@ -303,8 +345,8 @@ export declare class CacheKeepManager {
|
|
|
303
345
|
/**
|
|
304
346
|
* Whether keep-warm tracks a session, read from memory only (no lock, no
|
|
305
347
|
* storage). `on: true` means a live target holds the session's cache. A stop
|
|
306
|
-
* carries
|
|
307
|
-
*
|
|
348
|
+
* carries the nearest reason accepted by common-auth's billing contract;
|
|
349
|
+
* settings that kept warming off report `on: false` alone.
|
|
308
350
|
* `undefined` means this manager has seen nothing that decides it.
|
|
309
351
|
*/
|
|
310
352
|
warming(id: string): AnthropicBillingWarming | undefined;
|
|
@@ -334,6 +376,7 @@ export declare class CacheKeepManager {
|
|
|
334
376
|
private totalBodyBytes;
|
|
335
377
|
private removeTarget;
|
|
336
378
|
private retainStopped;
|
|
379
|
+
private finishSessionTargets;
|
|
337
380
|
private reportStop;
|
|
338
381
|
private evictOldestTarget;
|
|
339
382
|
private pruneTargets;
|
|
@@ -346,6 +389,7 @@ export declare class CacheKeepManager {
|
|
|
346
389
|
cacheMode: string;
|
|
347
390
|
oauthAccountId?: string;
|
|
348
391
|
oauthAccountIdentity?: string;
|
|
392
|
+
hostMetadata?: Readonly<Record<string, unknown>>;
|
|
349
393
|
accountStoragePath?: string;
|
|
350
394
|
isSubagent?: boolean;
|
|
351
395
|
sourceWarm?: boolean;
|
|
@@ -378,6 +422,7 @@ export declare class CacheKeepManager {
|
|
|
378
422
|
private lastPrewarmStart;
|
|
379
423
|
private scheduleRetry;
|
|
380
424
|
private sendPrewarm;
|
|
425
|
+
private sendPrewarmAttempt;
|
|
381
426
|
private prewarm;
|
|
382
427
|
private acceptWarm;
|
|
383
428
|
}
|