@cortexkit/anthropic-auth-core 2.1.2 → 2.2.1

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.
@@ -3,7 +3,7 @@ import type { QuotaObservation } from '../quota/index.js';
3
3
  import type { RoutingRow } from '../routing/index.js';
4
4
  import { type ClaustrumFamily, type ClaustrumScopedAttempt, type ClaustrumScopedClient, type IdentityParser, type KeptReceiptState, type VaultGrantReach } from './custody.js';
5
5
  import { type ClaustrumLogger } from './errors.js';
6
- import { type InsulaQuotaOptions } from './insula.js';
6
+ import { type InsulaQuotaOptions, type InsulaQuotaResult } from './insula.js';
7
7
  import { type AccountMapper, type QuotaReceipt, type VaultRosterFile } from './roster.js';
8
8
  import { type WatchMode } from './watch.js';
9
9
  export interface ClaustrumConsumerOptions<Q = QuotaObservation> {
@@ -134,6 +134,10 @@ export declare class ClaustrumConsumer<Q = QuotaObservation> {
134
134
  * A route without a known provider account cannot join an insula entry.
135
135
  */
136
136
  cachedInsulaQuotaForRoute(routeId: string): Promise<Q | undefined>;
137
+ /** Cache-only background lookup, preserving the reason a route has no reading. */
138
+ lookupInsulaQuotaForRoute(routeId: string): Promise<InsulaQuotaResult<Q>>;
139
+ /** Skip the fallback poll while insula is cold or its upstream fetch failed. */
140
+ pollInsulaQuotaForRoute(routeId: string, fallback: () => Promise<Q | undefined>): Promise<Q | undefined>;
137
141
  /**
138
142
  * Authorize one physical send on a vault route. The roster file is re-read
139
143
  * first, so a decline committed by another process applies before the next
@@ -7,7 +7,7 @@ export { type AccountIdentitySource, type ClaustrumFamily, type ClaustrumRosterW
7
7
  export { type ClaustrumEnrollmentClient, type ClaustrumEnrollmentConnection, type ClaustrumEnrollmentDisconnectResult, ClaustrumEnrollmentManager, type ClaustrumEnrollmentPaths, type ClaustrumEnrollmentResetResult, type ClaustrumEnrollmentStatus, classifyEnrollmentError, connectClaustrumEnrollmentClient, disconnectClaustrumEnrollment, type EnrollmentDisposition, enrollmentAuthority, enrollmentName, getClaustrumEnrollmentPaths, hostEnrollmentPaths, RETRYABLE_ENROLLMENT_CODES, readClaustrumEnrollmentStatus, readClaustrumEnrollmentToken, resetClaustrumEnrollmentState, TERMINAL_ENROLLMENT_CODES, } from './enrollment.js';
8
8
  export { ClaustrumConsumerError, type ClaustrumConsumerFailureKind, type ClaustrumLogger, } from './errors.js';
9
9
  export { assertHostSlotMatchesMode, assertNotCustodyPlaceholder, CUSTODY_PLACEHOLDER_PREFIX, classifyHostSlot, custodyPlaceholder, custodyPlaceholderKey, type HostSlotContent, isCustodyPlaceholder, isCustodyPlaceholderValue, } from './host-slot.js';
10
- export { acquireInsulaQuotaSource, type InsulaQuotaContext, type InsulaQuotaOptions, type InsulaQuotaSource, type InsulaUsageEntry, type InsulaUsageTransport, type InsulaUsageWatch, type InsulaUsageWindow, type InsulaWatchOptions, } from './insula.js';
10
+ export { acquireInsulaQuotaSource, type InsulaQuotaContext, type InsulaQuotaLookup, type InsulaQuotaMiss, type InsulaQuotaOptions, type InsulaQuotaReading, type InsulaQuotaResult, type InsulaQuotaSource, type InsulaUsageEntry, type InsulaUsageTransport, type InsulaUsageWatch, type InsulaUsageWindow, type InsulaWatchOptions, } from './insula.js';
11
11
  export { acceptAccount, type DeclinedAccount, declineAccount, isDeclined, } from './interlock.js';
12
12
  export { type AccountMapper, acceptVaultRoute, DEFAULT_ROUTE_PREFIX, declineVaultRoute, type MutateVaultRosterOptions, mutateVaultRoster, type ProjectionOptions, projectVaultRoster, type QuotaReceipt, readVaultRoster, recordVaultAccountQuota, recordVaultQuota, refreshVaultRoster, resolveVaultPrimary, type VaultPrimary, type VaultPrimaryBinding, type VaultPrimaryUnavailableReason, type VaultRosterFile, type VaultRosterLockContext, type VaultRosterRow, vaultRoutingRows, } from './roster.js';
13
13
  export { type ChangeNotice, ChangeNoticeReader, RESUBSCRIBE_BACKOFF_MS, SAFETY_POLL_MS, ScopedRosterWatch, type ScopedRosterWatchOptions, type ScopedWatchEnd, type ScopedWatchHandle, type ScopedWatchNoticeShape, type ScopedWatchSource, WATCH_RETRY_MS, type WatchMode, } from './watch.js';
@@ -34,6 +34,27 @@ export interface InsulaQuotaContext {
34
34
  fetchedAt: number;
35
35
  source?: string;
36
36
  }
37
+ export type InsulaQuotaMiss = 'cold' | 'stale' | 'absent' | 'upstream-failed' | 'credential' | 'unreachable';
38
+ export interface InsulaQuotaReading {
39
+ entry: InsulaUsageEntry;
40
+ context: InsulaQuotaContext;
41
+ }
42
+ /** A miss may retain a dated reading; it is not a current quota observation. */
43
+ export type InsulaQuotaLookup = {
44
+ reading: InsulaQuotaReading;
45
+ miss?: never;
46
+ } | {
47
+ miss: InsulaQuotaMiss;
48
+ reading?: InsulaQuotaReading;
49
+ };
50
+ /** The normalized equivalent of a source lookup, for a plugin's quota type. */
51
+ export type InsulaQuotaResult<Q> = {
52
+ reading: Q;
53
+ miss?: never;
54
+ } | {
55
+ miss: InsulaQuotaMiss;
56
+ reading?: Q;
57
+ };
37
58
  export interface InsulaQuotaOptions<Q> {
38
59
  provider: 'codex' | 'claude' | 'antigravity';
39
60
  /**
@@ -110,6 +131,8 @@ export declare class InsulaQuotaSource {
110
131
  entry: InsulaUsageEntry;
111
132
  context: InsulaQuotaContext;
112
133
  } | undefined;
134
+ /** Cache-only background lookup; current() retains its original miss behavior. */
135
+ lookup(provider: string, accountId: string, now: number): InsulaQuotaLookup;
113
136
  }
114
137
  export declare function acquireInsulaQuotaSource(transport: InsulaUsageTransport, tokenPath: string): {
115
138
  source: InsulaQuotaSource;
@@ -201,7 +201,7 @@ export interface NativeRefreshRequest {
201
201
  intent: 'serve' | 'refresh';
202
202
  mode: 'local' | 'claustrum';
203
203
  binding: NativeLocalPoolBinding;
204
- /** A 401's dispatched access token, used only for replacement adoption. */
204
+ /** The access token dispatched on a 401; it must not be served again. */
205
205
  rejectedAccessToken?: string;
206
206
  signal?: AbortSignal;
207
207
  }
@@ -1,9 +1,9 @@
1
1
  import { type NativeLockEvent } from './native-lock-observer.ts';
2
2
  import { type NativePoolStorePaths } from './pool-store.ts';
3
3
  /**
4
- * A local account could not be authorized because another writer was part
5
- * way through saving it (for example the refresh that records its first
6
- * account UUID) and did not finish within the short wait Core allows.
4
+ * A local account could not be authorized because the caller's short wait for
5
+ * an account write or a refresh replacing a provider-rejected token expired.
6
+ * The shared write or refresh may still finish after the caller stops waiting.
7
7
  *
8
8
  * The request should be retried. `code: 'ECONNRESET'` is how this package
9
9
  * marks an error retryable for its hosts. A host must surface it rather than
@@ -8,7 +8,7 @@ import { type NativeRosterSeedInput, type NativeVaultRosterDocument, type Native
8
8
  import { type NativeRuntimeState } from './native-runtime.ts';
9
9
  import type { NativeVaultPaths } from './native-vault-paths.ts';
10
10
  import type { NativePoolPaths } from './pool-paths.ts';
11
- import type { QuotaReadingPurpose, QuotaRequestDispatch } from './quota-manager.ts';
11
+ import { type QuotaReadingPurpose, type QuotaRequestDispatch } from './quota-manager.ts';
12
12
  export interface NativeVaultRuntimeOptions {
13
13
  paths: NativePoolPaths;
14
14
  host: 'opencode' | 'pi';
@@ -43,10 +43,12 @@ export interface NativeVaultRuntimeOptions {
43
43
  * background quota cache may answer instead of Anthropic's usage endpoint.
44
44
  * - 'background': a periodic sweep. Refresh insula's cache (at most once a
45
45
  * minute per daemon and enrollment), look the route's account up in it,
46
- * and skip the usage GET when it holds a current reading.
46
+ * and skip the usage GET for a current reading, a cold cache or an upstream
47
+ * failure. Skipped misses leave the account due for the next sweep.
47
48
  * - 'admission': a request needs a reading. Look the served credential's
48
49
  * account up in insula's cache only, never refreshing it, then poll on a
49
- * miss.
50
+ * miss except an upstream failure, which uses a dated reading if attached
51
+ * and otherwise leaves quota unknown.
50
52
  * Omitted: poll Anthropic directly (explicit user refreshes and other
51
53
  * callers that must see the provider's own reading).
52
54
  */
@@ -24,6 +24,9 @@ export type QuotaRefreshResult = {
24
24
  * means poll the provider directly.
25
25
  */
26
26
  export type QuotaReadingPurpose = 'background' | 'admission';
27
+ /** Insula is still fetching or its upstream failed; preserve quota without recording a poll. */
28
+ export declare class QuotaRefreshDeferred extends Error {
29
+ }
27
30
  /** Pace a physical usage GET and verify the selected credential is still eligible before sending. */
28
31
  export type QuotaRequestDispatch = (send: () => Promise<Response>, revalidate: () => Promise<void>) => Promise<Response>;
29
32
  export type QuotaManagerOptions = {
@@ -0,0 +1,19 @@
1
+ export declare const TURN_END_NOTE_BETA = "mid-conversation-system-clear-at-2026-08-21";
2
+ export declare const TURN_END_NOTE_MIN_VISIBLE_CHARACTERS = 350;
3
+ export declare const TURN_END_NOTE_CONTENT = "Your reply above has already reached the user. The tool call after it was housekeeping and changed nothing they need to know. Do not repeat, summarize or rewrite that reply. If no new work remains, end the turn without restating anything.";
4
+ /**
5
+ * Model families that get turn-end notes. The note is a turn-scoped system
6
+ * message (`clear_at: "next_user_message"`), which needs the
7
+ * mid-conversation-system-clear-at beta that Claude Code sends for these models.
8
+ */
9
+ export declare function supportsTurnEndNote(model: unknown): boolean;
10
+ /**
11
+ * Call only on OAuth histories, after effort-marker validation and stripping.
12
+ * Map configured host names with the same stateless mapping used for history,
13
+ * never with the currently declared tool set: declarations can change later.
14
+ */
15
+ export declare function applyTurnEndNotes(body: Record<string, unknown>, options?: {
16
+ tools?: readonly string[];
17
+ mapToolName?: (name: string) => string;
18
+ visibleText?: (message: Record<string, unknown>) => string;
19
+ }): number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cortexkit/anthropic-auth-core",
3
- "version": "2.1.2",
3
+ "version": "2.2.1",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",
@@ -30,7 +30,7 @@
30
30
  "prepublishOnly": "bun run build"
31
31
  },
32
32
  "devDependencies": {
33
- "@cortexkit/common-auth": "0.21.1"
33
+ "@cortexkit/common-auth": "0.22.0"
34
34
  },
35
35
  "dependencies": {
36
36
  "@cortexkit/claustrum-client": "0.12.0",