@cortexkit/anthropic-auth-core 2.10.1 → 2.11.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.
- package/dist/accounts.d.ts +1 -0
- package/dist/host-retry.d.ts +6 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +448 -116
- package/dist/internal-types/commands/builtins.d.ts +20 -1
- package/dist/internal-types/commands/index.d.ts +1 -1
- package/dist/internal-types/commands/menu.d.ts +6 -1
- package/dist/internal-types/fs/refresh-file-lock.d.ts +11 -0
- package/dist/internal-types/fs/with-lock.d.ts +2 -0
- package/dist/internal-types/routing-accessor/index.d.ts +33 -5
- package/dist/internal-types/setup/command-error.d.ts +1 -1
- package/dist/internal-types/setup/types.d.ts +4 -0
- package/dist/quota-refusal.d.ts +3 -1
- package/dist/routing-relay.d.ts +36 -0
- package/dist/sticky-routing.d.ts +2 -0
- package/package.json +2 -2
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AddInput, PoolLockSpec, PoolRow, PoolStore, RemoveOptions } from '../store/index.js';
|
|
1
|
+
import type { AddInput, PoolLockSpec, PoolRow, PoolSettings, PoolStore, RemoveOptions, SettingsMutator } from '../store/index.js';
|
|
2
2
|
import type { CommandInvocation, KnobValues, MenuChoice, MenuKnob } from './model.js';
|
|
3
3
|
import { type ResolvedSection } from './seam.js';
|
|
4
4
|
/**
|
|
@@ -98,9 +98,28 @@ export interface LimitsSectionOptions {
|
|
|
98
98
|
*/
|
|
99
99
|
labels?: readonly string[];
|
|
100
100
|
}
|
|
101
|
+
/**
|
|
102
|
+
* Where the Routing and Limits sections read and write the settings they show
|
|
103
|
+
* (`routing.mode`, `routing.maxSameAccountWait`, `killswitch.enabled`,
|
|
104
|
+
* `killswitch.accounts`). Without a port they use the account store's own
|
|
105
|
+
* settings through `readSettings` and `updateSettings`. A plugin that moved
|
|
106
|
+
* its settings to its own file (`./settings`) passes a port that translates
|
|
107
|
+
* this store-shaped view to that file.
|
|
108
|
+
*/
|
|
109
|
+
export interface BuiltinSettingsPort {
|
|
110
|
+
/** The current settings, in the store's settings shape. */
|
|
111
|
+
read(): Promise<PoolSettings>;
|
|
112
|
+
/**
|
|
113
|
+
* Apply one menu change. `mutator` gets a private copy in the store's shape
|
|
114
|
+
* and edits it in place or returns the whole next object, as with
|
|
115
|
+
* `updateSettings`. A refusal is thrown and shown as the action's failure.
|
|
116
|
+
*/
|
|
117
|
+
update(mutator: SettingsMutator): Promise<void>;
|
|
118
|
+
}
|
|
101
119
|
export interface BuiltinOptions {
|
|
102
120
|
store: PoolStore;
|
|
103
121
|
extraLocks?: readonly PoolLockSpec[];
|
|
122
|
+
settings?: BuiltinSettingsPort;
|
|
104
123
|
now: () => number;
|
|
105
124
|
accounts?: AccountsSectionOptions;
|
|
106
125
|
quota?: QuotaSectionOptions;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type { AccountsSectionOptions, LimitsSectionOptions, LoginOutcome, QuotaSectionOptions, RoutingSectionOptions, VaultRoutingOrder, } from './builtins.js';
|
|
1
|
+
export type { AccountsSectionOptions, BuiltinSettingsPort, LimitsSectionOptions, LoginOutcome, QuotaSectionOptions, RoutingSectionOptions, VaultRoutingOrder, } from './builtins.js';
|
|
2
2
|
export { MENU_DISABLED_REASON } from './builtins.js';
|
|
3
3
|
export type { CommandMenu, CommandMenuOptions, StoreSectionSlot, } from './menu.js';
|
|
4
4
|
export { createCommandMenu, parseApplyRequest } from './menu.js';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type RedactionOptions } from '../logger/index.js';
|
|
2
2
|
import type { PoolLockSpec, PoolStore } from '../store/index.js';
|
|
3
|
-
import { type AccountsSectionOptions, type LimitsSectionOptions, type QuotaSectionOptions, type RoutingSectionOptions } from './builtins.js';
|
|
3
|
+
import { type AccountsSectionOptions, type BuiltinSettingsPort, type LimitsSectionOptions, type QuotaSectionOptions, type RoutingSectionOptions } from './builtins.js';
|
|
4
4
|
import type { CommandApplyRequest, CommandApplyResult, CommandDialogPayload, CommandInvocation, PluginExtraSection, PluginSection } from './model.js';
|
|
5
5
|
import { type SeamLogger } from './seam.js';
|
|
6
6
|
/** The four slots the library can build from a pool store. */
|
|
@@ -25,6 +25,11 @@ export interface CommandMenuOptions {
|
|
|
25
25
|
replace?: Partial<Record<StoreSectionSlot, PluginSection>>;
|
|
26
26
|
/** The plugin's legacy locks, passed to every store write the menu makes. */
|
|
27
27
|
extraLocks?: readonly PoolLockSpec[];
|
|
28
|
+
/**
|
|
29
|
+
* Where the Routing and Limits sections read and write their settings. Omit
|
|
30
|
+
* it to use the store's own settings, as before.
|
|
31
|
+
*/
|
|
32
|
+
settings?: BuiltinSettingsPort;
|
|
28
33
|
accounts?: AccountsSectionOptions;
|
|
29
34
|
quota?: QuotaSectionOptions;
|
|
30
35
|
routing?: RoutingSectionOptions;
|
|
@@ -4,6 +4,17 @@ type LeaseCreationTestHooks = {
|
|
|
4
4
|
};
|
|
5
5
|
/** Test-only creation faults; not re-exported from the public fs entry point. */
|
|
6
6
|
export declare function setLeaseCreationTestHooksForTest(hooks?: LeaseCreationTestHooks): void;
|
|
7
|
+
type StagingSweepTestHooks = {
|
|
8
|
+
readdir?: (directory: string) => Promise<string[]>;
|
|
9
|
+
beforeUnlink?: (path: string) => void | Promise<void>;
|
|
10
|
+
unlink?: (path: string) => Promise<void>;
|
|
11
|
+
};
|
|
12
|
+
/** Test-only sweep faults; not re-exported from the public fs entry point. */
|
|
13
|
+
export declare function setStagingSweepTestHooksForTest(hooks?: StagingSweepTestHooks): void;
|
|
14
|
+
/** Tests only: wait for every staging sweep started so far to finish. */
|
|
15
|
+
export declare function settleStagingSweepsForTest(): Promise<void>;
|
|
16
|
+
/** Tests only: let the next acquisition of every lock path sweep again. */
|
|
17
|
+
export declare function forgetStagingSweepsForTest(): void;
|
|
7
18
|
export declare function isLostMarkerRaceError(error: unknown): boolean;
|
|
8
19
|
/** Test-only fault injection between marker mkdir and owner.json write. */
|
|
9
20
|
export interface EvictionMarkerTestHooks {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type PrivateFileError } from './private-files.js';
|
|
1
2
|
import { acquireRefreshFileLock } from './refresh-file-lock.js';
|
|
2
3
|
export declare function lockPathFor(target: string, name: string): string;
|
|
3
4
|
export declare class LockContentionError extends Error {
|
|
@@ -32,6 +33,7 @@ export interface LockOptions {
|
|
|
32
33
|
onStep?: Parameters<typeof acquireRefreshFileLock>[0]['onStep'];
|
|
33
34
|
onRenewalTimer?: Parameters<typeof acquireRefreshFileLock>[0]['onRenewalTimer'];
|
|
34
35
|
}
|
|
36
|
+
export declare function isChangingLockRecord(error: unknown, target: string, name: string): error is PrivateFileError;
|
|
35
37
|
export declare function withLock<T>(target: string, options: LockOptions, fn: (lock: {
|
|
36
38
|
assertOwned(): Promise<void>;
|
|
37
39
|
}) => Promise<T>): Promise<T>;
|
|
@@ -12,14 +12,16 @@ export interface RoutingCandidate {
|
|
|
12
12
|
accountId: string;
|
|
13
13
|
credentialId: string;
|
|
14
14
|
}
|
|
15
|
-
export interface AskRoutingInput<Candidate extends RoutingCandidate = RoutingCandidate> {
|
|
15
|
+
export interface AskRoutingInput<Candidate extends RoutingCandidate = RoutingCandidate, Refusals extends boolean = false> {
|
|
16
16
|
sessionId: string;
|
|
17
17
|
provider: string;
|
|
18
18
|
modelId: string;
|
|
19
19
|
/** Only routes already eligible under the plugin's vault and killswitch rules. */
|
|
20
20
|
candidates: readonly Candidate[];
|
|
21
|
-
/** Defaults to
|
|
21
|
+
/** Defaults to 1500 ms, above routing's normal tail; clamped to 1–2000 ms. */
|
|
22
22
|
deadlineMs?: number;
|
|
23
|
+
/** Opt in to refusals, which stop the request instead of using a local choice. */
|
|
24
|
+
refusals?: Refusals;
|
|
23
25
|
/**
|
|
24
26
|
* Longest same-account hold, in seconds, that routing may advise. The
|
|
25
27
|
* holdWaitMaxS helper from `./limits` caps it by the setting and the current
|
|
@@ -38,6 +40,14 @@ export interface RoutingSelection<Candidate extends RoutingCandidate = RoutingCa
|
|
|
38
40
|
candidate: Candidate;
|
|
39
41
|
hold?: RoutingHold;
|
|
40
42
|
}
|
|
43
|
+
export type RoutingRefusal = {
|
|
44
|
+
refused: {
|
|
45
|
+
code: 'account_limit_exhausted' | 'account_selection_refused' | 'account_selection_final';
|
|
46
|
+
routingCode?: string;
|
|
47
|
+
retryAfterSecs?: number;
|
|
48
|
+
resetsAtMs?: number;
|
|
49
|
+
};
|
|
50
|
+
};
|
|
41
51
|
interface RoutingReportIdentity {
|
|
42
52
|
sessionId: string;
|
|
43
53
|
accountId: string;
|
|
@@ -77,6 +87,23 @@ export type ReportRoutingInput = (RoutingReportIdentity & ({
|
|
|
77
87
|
pool?: string;
|
|
78
88
|
/** Optional reset time in epoch milliseconds. */
|
|
79
89
|
resetsAt?: number;
|
|
90
|
+
} | {
|
|
91
|
+
/**
|
|
92
|
+
* A provider's typed refusal that condemns the API key until it is
|
|
93
|
+
* topped up, such as an exhausted prepaid balance. Never use for
|
|
94
|
+
* 401, 403 or short rate limits.
|
|
95
|
+
*/
|
|
96
|
+
outcome: 'credential_refused';
|
|
97
|
+
credentialId: string;
|
|
98
|
+
/**
|
|
99
|
+
* What the provider actually sent: its own code from the structured
|
|
100
|
+
* error (OpenRouter's `openrouter_credits`). When the body carries
|
|
101
|
+
* no code, `http_<status>`, but only for a status the provider
|
|
102
|
+
* documents with a single balance meaning (DeepSeek's `http_402`).
|
|
103
|
+
* Never message text, and never a status with several meanings such
|
|
104
|
+
* as 403 or 429. Must match `^[a-z0-9._-]{1,64}$`.
|
|
105
|
+
*/
|
|
106
|
+
providerCode: string;
|
|
80
107
|
})) | {
|
|
81
108
|
sessionId: string;
|
|
82
109
|
kind: 'turn_notes_supported';
|
|
@@ -128,10 +155,11 @@ export declare function turnNotes(sessionId: string): readonly {
|
|
|
128
155
|
}[];
|
|
129
156
|
/**
|
|
130
157
|
* Ask routing for an eligible vault route. Any failure or unfamiliar answer
|
|
131
|
-
* yields undefined so the plugin can keep its own choice.
|
|
132
|
-
*
|
|
158
|
+
* yields undefined so the plugin can keep its own choice. Opted-in routing
|
|
159
|
+
* refusals instead stop the request. This does not admit routes: callers must
|
|
160
|
+
* exclude vault refusals and killswitch-blocked accounts.
|
|
133
161
|
*/
|
|
134
|
-
export declare function askRouting<Candidate extends RoutingCandidate>(input: AskRoutingInput<Candidate>): Promise<RoutingSelection<Candidate> | undefined>;
|
|
162
|
+
export declare function askRouting<Candidate extends RoutingCandidate, Refusals extends boolean = false>(input: AskRoutingInput<Candidate, Refusals>): Promise<RoutingSelection<Candidate> | (Refusals extends true ? RoutingRefusal : never) | undefined>;
|
|
135
163
|
/**
|
|
136
164
|
* Report a vault request, billing result or turn-note event without waiting for
|
|
137
165
|
* routing. Only contract fields are sent, and all accessor failures are ignored.
|
|
@@ -17,7 +17,7 @@ export declare class SetupCommandError extends Error {
|
|
|
17
17
|
});
|
|
18
18
|
}
|
|
19
19
|
/** The line setup prints for one host's outcome, e.g. `Pi: not connected`. */
|
|
20
|
-
export declare function setupEnrollmentLine({ host, outcome, access
|
|
20
|
+
export declare function setupEnrollmentLine({ host, outcome, access }: SetupHostEnrollment, grantFallback?: 'setup' | 'plugin'): string;
|
|
21
21
|
/**
|
|
22
22
|
* Remember which hosts a failed setup left connected to the vault, against the
|
|
23
23
|
* thrown value. Only objects can carry a record; a thrown primitive is left as
|
|
@@ -13,6 +13,8 @@ export type SetupEnvironment = Record<string, string | undefined>;
|
|
|
13
13
|
export type SetupEnrollmentOutcome = 'enrolled' | 'not-enrolled' | 'unknown';
|
|
14
14
|
export interface SetupEnrollmentAccess {
|
|
15
15
|
state: 'reachable' | 'no-logins' | 'partial' | 'older-vault' | 'unconfirmed';
|
|
16
|
+
/** Whether grants were sent with the proposal or dropped for an older vault. Absent for enrollments made before 0.44.0. */
|
|
17
|
+
requestedGrantsStatus?: 'sent' | 'dropped';
|
|
16
18
|
/** One result per requested grant, in proposal order. No count means unknown. */
|
|
17
19
|
grants: readonly {
|
|
18
20
|
grant: ClaustrumRequestedGrant;
|
|
@@ -62,6 +64,8 @@ export interface SetupPlugin {
|
|
|
62
64
|
name: string;
|
|
63
65
|
displayName?: string;
|
|
64
66
|
requestedGrants?: ReadonlyArray<ClaustrumRequestedGrant>;
|
|
67
|
+
/** Who reports access when grants were not sent with enrollment; defaults to 'setup'. */
|
|
68
|
+
grantFallback?: 'setup' | 'plugin';
|
|
65
69
|
paths: Parameters<typeof hostEnrollmentPaths>[0];
|
|
66
70
|
}>;
|
|
67
71
|
};
|
package/dist/quota-refusal.d.ts
CHANGED
|
@@ -3,4 +3,6 @@ export declare const quotaRefusalDetails: (response: Response) => {
|
|
|
3
3
|
reason: string;
|
|
4
4
|
timing: ReturnType<typeof quotaRefusalTiming>;
|
|
5
5
|
} | undefined;
|
|
6
|
-
export declare function createQuotaRefusalResponse(reason: string, timing: ReturnType<typeof quotaRefusalTiming>,
|
|
6
|
+
export declare function createQuotaRefusalResponse(reason: string, timing: ReturnType<typeof quotaRefusalTiming>, now?: number, options?: {
|
|
7
|
+
retry?: 'automatic' | 'manual';
|
|
8
|
+
}): Response;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { type RoutingRefusal } from "./internal-types/routing-accessor/index.js";
|
|
2
|
+
import type { OAuthQuotaSnapshot } from './accounts.ts';
|
|
3
|
+
import { type NativeAccountSnapshot } from './native-account-runtime.ts';
|
|
4
|
+
import { type NativeAccountView } from './native-account-view.ts';
|
|
5
|
+
export declare const ROUTING_HOLD_LIMIT_MS: number;
|
|
6
|
+
export type RoutingChoice = {
|
|
7
|
+
account_id: string;
|
|
8
|
+
credential_id: string;
|
|
9
|
+
hold?: {
|
|
10
|
+
retry_after_ms: number;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
type RoutingSubject = {
|
|
14
|
+
accountIdentity?: string;
|
|
15
|
+
credentialId?: string;
|
|
16
|
+
};
|
|
17
|
+
/** Routing owns quota reserves, including unknown readings and the minimum remaining quota set by the killswitch. Offer only subscription credentials the host may use. */
|
|
18
|
+
export declare function routingCandidates(accounts: readonly NativeAccountView[]): NativeAccountView[];
|
|
19
|
+
export declare function routingChoiceMatches(choice: RoutingChoice, account: RoutingSubject): boolean;
|
|
20
|
+
/** Fixed text avoids exposing router internals and is not a host auto-retry signal. */
|
|
21
|
+
export declare class RoutingRefusalError extends Error {
|
|
22
|
+
readonly code: RoutingRefusal['refused']['code'];
|
|
23
|
+
readonly retryAfterSecs?: number;
|
|
24
|
+
readonly status: number;
|
|
25
|
+
constructor(refusal: RoutingRefusal['refused'], now?: number);
|
|
26
|
+
response(): Response;
|
|
27
|
+
}
|
|
28
|
+
export declare function createRoutingRelay(quotaFor?: (subject: RoutingSubject) => Promise<OAuthQuotaSnapshot | undefined>): {
|
|
29
|
+
override: (sessionId: string, reason: string) => void;
|
|
30
|
+
shouldReport(sessionId: string): boolean;
|
|
31
|
+
admitted(sessionId: string, subject: RoutingSubject): boolean;
|
|
32
|
+
policy(sessionId: string, account: NativeAccountView, snapshot: NativeAccountSnapshot, modelId?: string): import("./native-account-runtime.ts").NativeAccountPolicy;
|
|
33
|
+
accountFor(sessionId: string, modelId: string, candidates: readonly RoutingSubject[]): Promise<RoutingChoice | null>;
|
|
34
|
+
report(sessionId: string, subject: RoutingSubject, headers: Headers, status: number, modelId?: string, served?: boolean): void;
|
|
35
|
+
};
|
|
36
|
+
export {};
|
package/dist/sticky-routing.d.ts
CHANGED
|
@@ -196,6 +196,8 @@ export declare class StickySessionRouter {
|
|
|
196
196
|
excludeAccountIds?: ReadonlySet<string>;
|
|
197
197
|
/** Leave the current pin intact when selection cannot offer an account. */
|
|
198
198
|
preserveOnNoCandidate?: boolean;
|
|
199
|
+
/** Routing already applied the quota reserve; select its admitted candidate without local quota weighting. */
|
|
200
|
+
routingAccountId?: string;
|
|
199
201
|
}): Promise<StickyRouteResolution | null>;
|
|
200
202
|
clear(sessionId: string): Promise<void>;
|
|
201
203
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cortexkit/anthropic-auth-core",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.11.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.
|
|
33
|
+
"@cortexkit/common-auth": "0.47.0"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"@cortexkit/claustrum-client": "0.18.0",
|