@cortexkit/anthropic-auth-core 2.16.3 → 2.16.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.
@@ -19,6 +19,7 @@ export declare function normalizeInsulaClaudeQuota(entry: InsulaUsageEntry, cont
19
19
  * a window read after insula's fetch (a response header, or our own poll).
20
20
  * Stored quota is replaced as one snapshot, newest wins, so publishing the
21
21
  * older insula reading as is would be refused and lose its other windows.
22
- * Keep the newer reading of each window instead.
22
+ * Keep newer standard windows, but take scoped limits and credits together
23
+ * from the newest poll, including fields it no longer reports.
23
24
  */
24
25
  export declare function mergeInsulaQuota(reading: InsulaClaudeQuota, stored: OAuthQuotaSnapshot | undefined): OAuthQuotaSnapshot;
@@ -1,7 +1,7 @@
1
1
  import type { ClaustrumReporterSource } from '@cortexkit/claustrum-client';
2
2
  import type { QuotaObservation } from '../quota/index.js';
3
3
  import type { RoutingRow } from '../routing/index.js';
4
- import { type ClaustrumFamily, type ClaustrumScopedAttempt, type ClaustrumScopedClient, type IdentityParser, type KeptReceiptState, type VaultGrantReach } from './custody.js';
4
+ import { type ClaustrumFamily, type ClaustrumScopedAttempt, type ClaustrumScopedClient, type IdentityParser, type KeptReceiptState, type VaultConditionOutcome, type VaultConditionReason, type VaultGrantReach } from './custody.js';
5
5
  import { type ClaustrumLogger } from './errors.js';
6
6
  import type { CustodyLease } from './hub.js';
7
7
  import { type InsulaQuotaOptions, type InsulaQuotaResult } from './insula.js';
@@ -246,6 +246,25 @@ export declare class ClaustrumConsumer<Q = QuotaObservation> {
246
246
  }): void;
247
247
  usageReportState(): ClaustrumUsageReportState;
248
248
  reportFailure(attempt: ClaustrumScopedAttempt, status: number, source: ClaustrumReporterSource): Promise<void>;
249
+ /**
250
+ * Report a provider login condition through the custody that issued the
251
+ * receipt; see `ClaustrumScopedCustody.reportCondition`. Bookkeeping: call it
252
+ * after handing back the reply, never on the request path. It resolves
253
+ * `skipped` after shutdown and rejects only with `no-receipt` for a receipt
254
+ * no live custody of this consumer issued.
255
+ */
256
+ reportCondition(attempt: ClaustrumScopedAttempt, input: {
257
+ reason: VaultConditionReason;
258
+ providerStatus: number;
259
+ actionUrl?: string;
260
+ }): Promise<VaultConditionOutcome>;
261
+ /**
262
+ * Clear a listed login condition through the custody that issued the
263
+ * receipt; see `ClaustrumScopedCustody.clearCondition`. Safe to call after
264
+ * every successful reply: it sends nothing unless the login is marked.
265
+ * Same `skipped` and `no-receipt` rules as `reportCondition`.
266
+ */
267
+ clearCondition(attempt: ClaustrumScopedAttempt): Promise<VaultConditionOutcome>;
249
268
  /**
250
269
  * Send on a vault route. `dispatch` builds and sends the request with the
251
270
  * receipt's token and may be called twice, so it must be able to rebuild
@@ -3,8 +3,12 @@ import { type ClaustrumLogger } from './errors.js';
3
3
  import type { InsulaUsageTransport } from './insula.js';
4
4
  import { type ClaustrumUsageReading, type ClaustrumUsageReportState, type ScopedUsageSource } from './usage.js';
5
5
  import { type ScopedWatchSource, type WatchMode } from './watch.js';
6
- type ScopedRow = Omit<ScopedInventoryRow, 'authMethod'> & {
6
+ type ScopedRow = Omit<ScopedInventoryRow, 'authMethod' | 'condition'> & {
7
7
  readonly authMethod?: string;
8
+ readonly condition?: {
9
+ readonly reason: string;
10
+ readonly sinceMs: number;
11
+ };
8
12
  };
9
13
  type ScopedInventory = Omit<Awaited<ReturnType<ClaustrumClient['listScoped']>>, 'rows'> & {
10
14
  readonly rows: readonly ScopedRow[];
@@ -12,13 +16,29 @@ type ScopedInventory = Omit<Awaited<ReturnType<ClaustrumClient['listScoped']>>,
12
16
  /**
13
17
  * claustrum-client adds watchScoped in 0.12.0 and reportUsageScoped in 0.14.0.
14
18
  * Older clients keep polling and simply do not send reply quota readings.
19
+ * The optional login condition methods match 0.21.0 without requiring it.
15
20
  */
16
21
  export type ClaustrumScopedClient = Pick<ClaustrumClient, 'getScoped' | 'reportAuthFailureScoped' | 'close'> & {
17
22
  listScoped(enrollmentToken?: string): Promise<ScopedInventory>;
23
+ reportCondition?(input: {
24
+ credentialId: string;
25
+ recordVersion: number;
26
+ reason: string;
27
+ providerStatus: number;
28
+ actionUrl?: string;
29
+ enrollmentToken?: string;
30
+ }): Promise<void>;
31
+ clearCondition?(input: {
32
+ credentialId: string;
33
+ recordVersion: number;
34
+ enrollmentToken?: string;
35
+ }): Promise<boolean>;
18
36
  insula?: InsulaUsageTransport;
19
37
  } & ScopedWatchSource & ScopedUsageSource;
20
38
  /** The two credential types a plugin's family can hold; routing differs by type. */
21
39
  export type VaultCredentialType = 'oauth' | 'api_key';
40
+ export type VaultConditionReason = 'provider_verification_required' | 'provider_ineligible';
41
+ export type VaultConditionOutcome = 'reported' | 'skipped' | 'unsupported' | 'failed';
22
42
  /**
23
43
  * Which vault rows belong to this plugin. `refreshAdapter` classifies an OAuth
24
44
  * row by the protocol it speaks; `category` is the grant that authorizes this
@@ -69,6 +89,10 @@ export interface VaultCredential {
69
89
  readonly state: string;
70
90
  readonly email?: string;
71
91
  readonly orgName?: string;
92
+ readonly condition?: {
93
+ readonly reason: VaultConditionReason;
94
+ readonly sinceMs: number;
95
+ };
72
96
  }
73
97
  /**
74
98
  * Why a listed vault record could not be used. A closed set of fixed codes, so
@@ -339,6 +363,20 @@ export declare class ClaustrumScopedCustody {
339
363
  * it. A receipt this custody did not issue is refused rather than reported.
340
364
  */
341
365
  reportFailure(attempt: ClaustrumScopedAttempt, status: number, reporterSource: ClaustrumReporterSource): Promise<void>;
366
+ /**
367
+ * Report a provider login condition as bookkeeping after handing back the
368
+ * reply, never on the request path. Pass the receipt actually sent with it.
369
+ */
370
+ reportCondition(attempt: ClaustrumScopedAttempt, input: {
371
+ reason: VaultConditionReason;
372
+ providerStatus: number;
373
+ actionUrl?: string;
374
+ }): Promise<VaultConditionOutcome>;
375
+ /**
376
+ * Clear a listed condition as bookkeeping after handing back a successful
377
+ * reply, never on the request path. Pass the receipt actually sent with it.
378
+ */
379
+ clearCondition(attempt: ClaustrumScopedAttempt): Promise<VaultConditionOutcome>;
342
380
  /**
343
381
  * Watch this consumer's visible vault accounts instead of listing them on a
344
382
  * short timer. Opens one `watchScoped` on this custody's client and calls
@@ -111,12 +111,13 @@ export interface ClaustrumHubMemberOptions<_Q = QuotaObservation> {
111
111
  logger?: ClaustrumLogger;
112
112
  }
113
113
  /** What a lease may do with the shared custody. */
114
- export type ClaustrumLeasedCustody = Pick<ClaustrumScopedCustody, 'authorize' | 'reportFailure' | 'reportUsage' | 'usageReportState' | 'forget' | 'keptReceiptState'>;
114
+ export type ClaustrumLeasedCustody = Pick<ClaustrumScopedCustody, 'authorize' | 'reportFailure' | 'reportCondition' | 'clearCondition' | 'reportUsage' | 'usageReportState' | 'forget' | 'keptReceiptState'>;
115
115
  /**
116
116
  * One acquisition of the hub's shared custody. `custody` throws `closed`
117
117
  * after `release()`, and once the connection it belongs to ended for any
118
118
  * reason, vault mode going off included. Best-effort `reportUsage` instead
119
- * ignores reports through an ended lease. `release()` is idempotent.
119
+ * ignores reports through an ended lease, and the condition calls resolve
120
+ * `skipped` through one. `release()` is idempotent.
120
121
  */
121
122
  export interface CustodyLease {
122
123
  readonly custody: ClaustrumLeasedCustody;
@@ -3,7 +3,7 @@ import type { ClaustrumScopedClient } from './custody.js';
3
3
  export { ClaustrumCredentialError, type ClaustrumReporterSource, type EnrollmentTokenFile, } from '@cortexkit/claustrum-client';
4
4
  export { ClaustrumUnreachableError, classifyVaultFailure, VAULT_FAILURE_CLASSES, type VaultFailureClass, } from './availability.js';
5
5
  export { ClaustrumConsumer, type ClaustrumConsumerOptions, type ClaustrumWatchState, DEFAULT_CONNECT_TIMEOUT_MS, type SendOptions, } from './consumer.js';
6
- export { type AccountIdentitySource, type ClassifyingClaustrumFamily, type ClaustrumFamily, type ClaustrumFamilyInput, type ClaustrumRosterWatch, type ClaustrumRosterWatchOptions, type ClaustrumScopedAttempt, type ClaustrumScopedClient, ClaustrumScopedCustody, type ClaustrumScopedIdentity, decideScopedRetryAfter401, type IdentityParser, isScopedCredentialRotation, KEPT_RECEIPT_MARGIN_MS, type KeptReceiptState, type ScopedRetryReason, SERVING_MARGIN_MS, type SkippedVaultReason, type SkippedVaultRecord, VAULT_RECEIPT_WAIT_MS, VAULT_YOUNG_OUTAGE_MS, type VaultCredential, type VaultCredentialType, type VaultGrantReach, type VaultGrantTuple, type VaultInventory, type VaultRowFacts, } from './custody.js';
6
+ export { type AccountIdentitySource, type ClassifyingClaustrumFamily, type ClaustrumFamily, type ClaustrumFamilyInput, type ClaustrumRosterWatch, type ClaustrumRosterWatchOptions, type ClaustrumScopedAttempt, type ClaustrumScopedClient, ClaustrumScopedCustody, type ClaustrumScopedIdentity, decideScopedRetryAfter401, type IdentityParser, isScopedCredentialRotation, KEPT_RECEIPT_MARGIN_MS, type KeptReceiptState, type ScopedRetryReason, SERVING_MARGIN_MS, type SkippedVaultReason, type SkippedVaultRecord, VAULT_RECEIPT_WAIT_MS, VAULT_YOUNG_OUTAGE_MS, type VaultConditionOutcome, type VaultConditionReason, type VaultCredential, type VaultCredentialType, type VaultGrantReach, type VaultGrantTuple, type VaultInventory, type VaultRowFacts, } from './custody.js';
7
7
  export { type ClaustrumEnrollmentClient, type ClaustrumEnrollmentConnection, type ClaustrumEnrollmentDisconnectResult, ClaustrumEnrollmentManager, type ClaustrumEnrollmentPaths, type ClaustrumEnrollmentResetResult, type ClaustrumEnrollmentStatus, type ClaustrumRequestedGrant, classifyEnrollmentError, connectClaustrumEnrollmentClient, disconnectClaustrumEnrollment, type EnrollmentDisposition, enrollmentAuthority, enrollmentName, getClaustrumEnrollmentPaths, hostEnrollmentPaths, RETRYABLE_ENROLLMENT_CODES, readClaustrumEnrollmentStatus, readClaustrumEnrollmentToken, resetClaustrumEnrollmentState, TERMINAL_ENROLLMENT_CODES, validEnrollmentDisplayName, validEnrollmentRequestedGrants, vaultAuthority, } from './enrollment.js';
8
8
  export { ClaustrumConsumerError, type ClaustrumConsumerFailureKind, type ClaustrumLogger, } from './errors.js';
9
9
  export { connectVaultHost, hasVaultHost, VAULT_HOST_CONNECT_REFUSAL, VAULT_HOST_STATUS, } from './host.js';
@@ -0,0 +1,36 @@
1
+ export type MessageThreadTailHost = 'opencode2' | 'pi';
2
+ export interface FullCacheTail {
3
+ identity: string;
4
+ messageIndex: number;
5
+ blockPath: number[];
6
+ prefix: string;
7
+ control: {
8
+ type: 'ephemeral';
9
+ ttl?: '1h' | '5m';
10
+ };
11
+ acceptedAt: number;
12
+ }
13
+ interface Entry {
14
+ continued: boolean;
15
+ tail: FullCacheTail;
16
+ }
17
+ export declare function fullCacheTailExpired(tail: FullCacheTail, now: number): boolean;
18
+ /** Saves where each accepted full request marked its prefix, without saving the request. */
19
+ export declare class MessageThreadTailStore {
20
+ private readonly now;
21
+ readonly directory: string;
22
+ private writes;
23
+ private nextSweep;
24
+ constructor(host: MessageThreadTailHost, root?: string, now?: () => number);
25
+ private pathFor;
26
+ private directoryReady;
27
+ private read;
28
+ load(session: string): Promise<Entry | undefined>;
29
+ private enqueue;
30
+ changed(session: string, tail: FullCacheTail | undefined, continued: boolean): void;
31
+ private publish;
32
+ private removeUnchanged;
33
+ private prune;
34
+ drain(): Promise<void>;
35
+ }
36
+ export {};
@@ -1,3 +1,4 @@
1
+ import { type FullCacheTail, type MessageThreadTailHost, MessageThreadTailStore } from './message-thread-tail-store.ts';
1
2
  import type { NativeLocalPoolBinding } from './pool-binding.ts';
2
3
  export declare const MESSAGE_THREADS_BETA = "message-threads-2026-08-12";
3
4
  type Body = Record<string, unknown>;
@@ -34,7 +35,7 @@ export type MessageThreadDecision = {
34
35
  deltaMessages: unknown[];
35
36
  };
36
37
  export type MessageThreadCreateReason = 'no_anchor' | 'clock_rollback' | 'expired' | 'identity_changed' | 'too_few_messages' | 'assistant_missing' | 'extra_assistant' | 'reply_invalid' | 'reply_changed' | 'fixed_changed' | 'prefix_changed' | 'ttl_order' | 'stateless';
37
- export type MessageThreadDisposition = 'never_seen' | 'superseded' | 'stream_cancelled' | 'stream_error' | 'signal_aborted' | 'invalid_completion' | 'invalid_reply' | 'response_refusal' | 'response_fallback' | 'response_rewritten' | 'thread_rejected' | 'account_disabled' | 'evicted' | 'session_deleted';
38
+ export type MessageThreadDisposition = 'never_seen' | 'superseded' | 'stream_cancelled' | 'stream_error' | 'signal_aborted' | 'invalid_completion' | 'invalid_reply' | 'response_refusal' | 'response_fallback' | 'response_rewritten' | 'thread_rejected' | 'account_disabled' | 'evicted' | 'session_closed' | 'session_deleted';
38
39
  /** Refresh preserves the local epoch; replacing a login advances it even when the row id is reused. */
39
40
  export declare function localMessageThreadCredential(binding: NativeLocalPoolBinding): string;
40
41
  type ReplyToolName = (name: unknown) => string | undefined;
@@ -53,17 +54,6 @@ export interface MessageThreadCompletion {
53
54
  replyFingerprint?: string;
54
55
  reply?: unknown;
55
56
  }
56
- interface FullCacheTail {
57
- identity: string;
58
- messageIndex: number;
59
- blockPath: number[];
60
- prefix: string;
61
- control: {
62
- type: 'ephemeral';
63
- ttl?: '1h' | '5m';
64
- };
65
- acceptedAt: number;
66
- }
67
57
  interface FixedCacheLayout {
68
58
  lifetime: string;
69
59
  system: Array<{
@@ -76,6 +66,7 @@ interface FixedCacheLayout {
76
66
  }>;
77
67
  }
78
68
  export declare class MessageThreadTracker {
69
+ #private;
79
70
  private readonly capacity;
80
71
  private readonly now;
81
72
  private readonly hashBudget;
@@ -84,7 +75,11 @@ export declare class MessageThreadTracker {
84
75
  private readonly dispositions;
85
76
  private readonly instance;
86
77
  private readonly fullTails;
87
- constructor(capacity?: number, now?: () => number, hashBudget?: number);
78
+ constructor(capacity?: number, now?: () => number, hashBudget?: number, tailStore?: MessageThreadTailStore);
79
+ static withTailPersistence(host: MessageThreadTailHost): MessageThreadTracker;
80
+ private canLoadFullTail;
81
+ loadFullTail(session: string): Promise<void> | undefined;
82
+ private rememberFullTail;
88
83
  forget(session: string, disposition?: MessageThreadDisposition): void;
89
84
  private prune;
90
85
  private failureFor;
@@ -13,7 +13,7 @@ import { type NativeRuntimeSettingsOptions, type NativeRuntimeSettingsStatus } f
13
13
  import { type NativeDisplayProfile, type NativeVaultQuotaPurpose, type NativeVaultRuntime, type NativeVaultRuntimeOptions } from './native-vault-runtime.ts';
14
14
  import { type NativeLocalPoolBinding } from './pool-binding.ts';
15
15
  import { type NativePoolPaths } from './pool-paths.ts';
16
- import type { QuotaRequestDispatch } from './quota-manager.ts';
16
+ import { type QuotaRequestDispatch } from './quota-manager.ts';
17
17
  import { type RelayConfig } from './relay.ts';
18
18
  import { type RelocationGuard } from './relocation-guard.ts';
19
19
  import type { SettingsMoveDiagnostic } from './settings-mode-status.ts';
@@ -45,6 +45,8 @@ export interface NativeVaultRuntimeOptions {
45
45
  * minute per daemon and enrollment), look the route's account up in it,
46
46
  * and skip the usage GET for a current reading, a cold cache or an upstream
47
47
  * failure. Skipped misses leave the account due for the next sweep.
48
+ * - 'background-cache': apply a current reading from the already-warmed
49
+ * cache even if recent headers mean a provider poll is not due.
48
50
  * - 'admission': a request needs a reading. Look the served credential's
49
51
  * account up in insula's cache only, never refreshing it, then poll on a
50
52
  * miss except an upstream failure, which uses a dated reading if attached
@@ -52,7 +54,7 @@ export interface NativeVaultRuntimeOptions {
52
54
  * Omitted: poll Anthropic directly (explicit user refreshes and other
53
55
  * callers that must see the provider's own reading).
54
56
  */
55
- export type NativeVaultQuotaPurpose = QuotaReadingPurpose;
57
+ export type NativeVaultQuotaPurpose = QuotaReadingPurpose | 'background-cache';
56
58
  export interface NativeVaultWatchOptions {
57
59
  intervalMs: number;
58
60
  onRefresh?: () => void | Promise<void>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cortexkit/anthropic-auth-core",
3
- "version": "2.16.3",
3
+ "version": "2.16.5",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",
@@ -31,10 +31,10 @@
31
31
  "prepublishOnly": "bun run build"
32
32
  },
33
33
  "devDependencies": {
34
- "@cortexkit/common-auth": "0.55.1"
34
+ "@cortexkit/common-auth": "0.56.3"
35
35
  },
36
36
  "dependencies": {
37
- "@cortexkit/claustrum-client": "0.20.0",
37
+ "@cortexkit/claustrum-client": "0.21.0",
38
38
  "@cortexkit/private-files": "0.2.2",
39
39
  "@cortexkit/subc-client": "^0.24",
40
40
  "jsonc-parser": "^3.3.1",