@cortexkit/anthropic-auth-core 2.16.0 → 2.16.2

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,13 +1,20 @@
1
- import { type ClaustrumClient, type ClaustrumReporterSource, type EnrollmentTokenFile } from '@cortexkit/claustrum-client';
1
+ import { type ClaustrumClient, type ClaustrumReporterSource, type EnrollmentTokenFile, type ScopedInventoryRow } from '@cortexkit/claustrum-client';
2
2
  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'> & {
7
+ readonly authMethod?: string;
8
+ };
9
+ type ScopedInventory = Omit<Awaited<ReturnType<ClaustrumClient['listScoped']>>, 'rows'> & {
10
+ readonly rows: readonly ScopedRow[];
11
+ };
6
12
  /**
7
13
  * claustrum-client adds watchScoped in 0.12.0 and reportUsageScoped in 0.14.0.
8
14
  * Older clients keep polling and simply do not send reply quota readings.
9
15
  */
10
- export type ClaustrumScopedClient = Pick<ClaustrumClient, 'listScoped' | 'getScoped' | 'reportAuthFailureScoped' | 'close'> & {
16
+ export type ClaustrumScopedClient = Pick<ClaustrumClient, 'getScoped' | 'reportAuthFailureScoped' | 'close'> & {
17
+ listScoped(enrollmentToken?: string): Promise<ScopedInventory>;
11
18
  insula?: InsulaUsageTransport;
12
19
  } & ScopedWatchSource & ScopedUsageSource;
13
20
  /** The two credential types a plugin's family can hold; routing differs by type. */
@@ -16,7 +23,8 @@ export type VaultCredentialType = 'oauth' | 'api_key';
16
23
  * Which vault rows belong to this plugin. `refreshAdapter` classifies an OAuth
17
24
  * row by the protocol it speaks; `category` is the grant that authorizes this
18
25
  * consumer to read it. Static API keys carry no refresh adapter, so they are
19
- * admitted only when `apiKeys` is set and only by category.
26
+ * admitted only when `apiKeys` is set. If a row declares an auth method, it
27
+ * must agree with the credential type.
20
28
  */
21
29
  export interface ClaustrumFamily {
22
30
  refreshAdapter: string;
@@ -111,8 +119,10 @@ export interface VaultInventory {
111
119
  readonly credentials: readonly VaultCredential[];
112
120
  readonly skipped: readonly SkippedVaultRecord[];
113
121
  /**
114
- * Classifying families only: declared policy codes or the fixed library codes
115
- * `unknown-auth-method`, `unmapped` and `unclassified`, never classifier errors.
122
+ * Refused rows and their codes, never classifier errors. Category families
123
+ * omit this field if no rows were refused and use only `unknown-auth-method`.
124
+ * Classifying families can also use declared policy codes, `unmapped` and
125
+ * `unclassified`.
116
126
  */
117
127
  readonly refused?: readonly {
118
128
  credentialId?: string;
@@ -364,3 +374,4 @@ export declare class ClaustrumScopedCustody {
364
374
  /** Stop accepting work; give token reads and reply reports one shared 2 s drain. */
365
375
  dispose(onTimeout?: (pendingOperations: number) => void): Promise<void>;
366
376
  }
377
+ export {};
@@ -13,11 +13,36 @@ export interface RoutingCandidate {
13
13
  accountId: string;
14
14
  credentialId: string;
15
15
  }
16
- export interface AskRoutingInput<Candidate extends RoutingCandidate = RoutingCandidate, Refusals extends boolean = false> {
16
+ type ContinueExhaustion = {
17
+ /** Vault account id, not the plugin's route id. */
18
+ accountId: string;
19
+ credentialId: string;
20
+ /** When the limit or sign-in signal was observed, in Unix milliseconds. */
21
+ observedAtMs: number;
22
+ } & ({
23
+ limitWindow: 'five_hour' | 'seven_day';
24
+ /** Scoped quota group matching `^[a-z0-9._-]{1,64}$`. */
25
+ pool?: string;
26
+ /** Reset time in Unix milliseconds. */
27
+ resetsAtMs?: number;
28
+ /** Non-negative seconds until retry, rounded down. */
29
+ retryAfterS?: number;
30
+ } | {
31
+ limitWindow: 'signed_out';
32
+ pool?: never;
33
+ resetsAtMs?: never;
34
+ retryAfterS?: never;
35
+ });
36
+ export type AskRoutingInput<Candidate extends RoutingCandidate = RoutingCandidate, Refusals extends boolean = false> = {
17
37
  sessionId: string;
18
38
  provider: string;
19
39
  modelId: string;
20
- /** Only routes already eligible under the plugin's vault and killswitch rules. */
40
+ /**
41
+ * The routable set: routes the vault allows, minus any the user's own rules
42
+ * exclude. It is not the account the plugin's local selection would choose,
43
+ * so it can include routes that selection would skip for model or quota
44
+ * reasons; routing picks among them.
45
+ */
21
46
  candidates: readonly Candidate[];
22
47
  /** Defaults to 1500 ms, above routing's normal tail; clamped to 1–2000 ms. */
23
48
  deadlineMs?: number;
@@ -33,7 +58,24 @@ export interface AskRoutingInput<Candidate extends RoutingCandidate = RoutingCan
33
58
  holdWaitMaxS?: number;
34
59
  /** Plugin sticky choice's vault credential id; an eligible-account hint, not a pin. */
35
60
  warmCredentialId?: string;
36
- }
61
+ } & ({
62
+ mode?: never;
63
+ requestId?: never;
64
+ exhausted?: never;
65
+ } | {
66
+ /**
67
+ * Ask routing whether a run should move off its pinned account. Send to
68
+ * the selected account, or wait on it if the answer includes a hold.
69
+ * With `refusals: true`, a `{refused}` answer means keep the run paused
70
+ * on its account until the reset or, for `signed_out`, until the user
71
+ * signs in. Do not ask again while paused.
72
+ */
73
+ mode: 'continue';
74
+ /** One id per question (e.g. a fresh UUID); reuse it only to retry that same question. */
75
+ requestId: string;
76
+ /** Required on a continue: a proved usage limit or a definite sign-in signal. */
77
+ exhausted: ContinueExhaustion;
78
+ });
37
79
  export interface RoutingHold {
38
80
  /** Uncapped advice from routing. The plugin must apply its own hold cap. */
39
81
  retry_after_ms: number;
@@ -47,6 +89,7 @@ export type RoutingRefusal = {
47
89
  refused: {
48
90
  code: 'account_limit_exhausted' | 'account_selection_refused' | 'account_selection_final';
49
91
  routingCode?: string;
92
+ reason?: string;
50
93
  retryAfterSecs?: number;
51
94
  resetsAtMs?: number;
52
95
  };
@@ -110,7 +153,21 @@ export type ReportRoutingInput = (RoutingReportIdentity & ({
110
153
  * as 403 or 429. Must match `^[a-z0-9._-]{1,64}$`.
111
154
  */
112
155
  providerCode: string;
113
- })) | {
156
+ })) | (RoutingReportIdentity & {
157
+ /**
158
+ * Report a 429 or similar response that isn't a proved quota limit. With
159
+ * no provider retry time, use the final attempt's receipt time + 5,000 ms.
160
+ * Routing blocks only new admissions on the account until `retryAtMs`.
161
+ * The session's pin stays: wait until `retryAtMs` and retry the run on
162
+ * the same account. For a proved quota limit, report `exhausted` and ask
163
+ * routing to continue with the exhausted window. Use `credential_refused`
164
+ * for an API key refused for any use.
165
+ */
166
+ kind: 'transient_backoff';
167
+ /** Absolute retry time in Unix milliseconds. */
168
+ retryAtMs: number;
169
+ providerCode?: string;
170
+ }) | {
114
171
  sessionId: string;
115
172
  kind: 'turn_notes_supported';
116
173
  model: string;
@@ -175,20 +232,18 @@ export declare function turnNotes(sessionId: string): readonly {
175
232
  * Ask routing for an eligible vault route. Any failure or unfamiliar answer
176
233
  * yields undefined so the plugin can keep its own choice. Opted-in routing
177
234
  * refusals instead stop the request. This does not admit routes. Callers never
178
- * pass an account the vault refused. A plugin may also leave out accounts its
179
- * user's own eligibility rules exclude, such as a per-model account list. Each
180
- * plugin decides whether its quota floors (a minimum share of a quota window
181
- * an account must keep) also filter candidates; routing keeps its own reserve
182
- * of each window.
183
- * Routing's pick among the candidates is final. Don't reject it under a local
184
- * floor, and don't add floors of the plugin's own that duplicate routing's
185
- * reserves.
235
+ * pass an account the vault refused. Beyond that, a plugin may leave accounts
236
+ * out only under a user-configured eligibility rule, such as a killswitch floor
237
+ * the user turned on (the minimum share of a quota window an account must keep
238
+ * to be offered) or a per-model account list. Plugins ship no floors of
239
+ * their own by default. Routing's pick is final: never reject it under a local
240
+ * floor or choose another account afterwards.
186
241
  */
187
242
  export declare function askRouting<Candidate extends RoutingCandidate, Refusals extends boolean = false>(input: AskRoutingInput<Candidate, Refusals>): Promise<RoutingSelection<Candidate> | (Refusals extends true ? RoutingRefusal : never) | undefined>;
188
243
  /**
189
- * Report a vault request, billing result, plugin wait or turn-note event without
190
- * waiting for routing. Only contract fields are sent, and all accessor failures
191
- * are ignored. Headers must already be limited to rate-limit headers by the
192
- * caller; values are not filtered or redacted here.
244
+ * Report a vault request, account backoff, billing result, plugin wait or
245
+ * turn-note event without waiting for routing. Only contract fields are sent,
246
+ * and all accessor failures are ignored. Headers must already be limited to
247
+ * rate-limit headers by the caller; values are not filtered or redacted here.
193
248
  */
194
249
  export declare function reportRouting(input: ReportRoutingInput): void;
@@ -22,7 +22,7 @@ export interface NativeCustodyClient {
22
22
  readonly credentialType: string;
23
23
  readonly serves: readonly string[];
24
24
  readonly providerIds: readonly string[];
25
- readonly authMethod?: 'apikey' | 'chatgpt' | 'antigravity' | 'oauth';
25
+ readonly authMethod?: string;
26
26
  readonly refreshAdapter?: string;
27
27
  readonly state: string;
28
28
  readonly recordVersion: number;
@@ -1,9 +1,9 @@
1
+ import { type PoolLoad } from "./internal-types/store/index.js";
1
2
  import { type NativeLockEvent } from './native-lock-observer.ts';
2
3
  import { type NativePoolStorePaths } from './pool-store.ts';
3
4
  /**
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.
5
+ * An account update prevented a request from reading or authorizing the account
6
+ * within its short wait budget. The shared write or refresh may still finish.
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
@@ -13,10 +13,13 @@ import { type NativePoolStorePaths } from './pool-store.ts';
13
13
  export declare class NativeTransientAccountError extends Error {
14
14
  readonly code: 'ECONNRESET';
15
15
  readonly syscall: 'native-account-update';
16
- constructor();
16
+ readonly poolRead?: true;
17
+ constructor(operation?: 'pool-read');
17
18
  }
18
19
  /** True only for an error Core itself constructed as NativeTransientAccountError. */
19
20
  export declare function isNativeTransientAccountError(value: unknown): value is NativeTransientAccountError;
21
+ export declare function readNativePool(read: Promise<PoolLoad>): Promise<PoolLoad>;
22
+ export declare function readNativePoolSettings<T>(read: Promise<T>): Promise<T>;
20
23
  /**
21
24
  * Wait until no writer holds the pool's store locks, then let them go.
22
25
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cortexkit/anthropic-auth-core",
3
- "version": "2.16.0",
3
+ "version": "2.16.2",
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.54.0"
34
+ "@cortexkit/common-auth": "0.55.1"
35
35
  },
36
36
  "dependencies": {
37
- "@cortexkit/claustrum-client": "0.18.0",
37
+ "@cortexkit/claustrum-client": "0.20.0",
38
38
  "@cortexkit/private-files": "0.2.2",
39
39
  "@cortexkit/subc-client": "^0.24",
40
40
  "jsonc-parser": "^3.3.1",