@cortexkit/anthropic-auth-core 2.11.2 → 2.11.4
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 +30 -16
- package/dist/cachekeep.d.ts +8 -5
- package/dist/holder-registry.d.ts +2 -0
- package/dist/index.d.ts +20 -2
- package/dist/index.js +9205 -3902
- package/dist/internal-types/claustrum/custody.d.ts +4 -0
- package/dist/internal-types/claustrum/index.d.ts +1 -1
- package/dist/internal-types/routing-accessor/index.d.ts +34 -9
- package/dist/internal-types/settings/define.d.ts +35 -0
- package/dist/internal-types/settings/descriptors.d.ts +97 -0
- package/dist/internal-types/settings/edit.d.ts +24 -0
- package/dist/internal-types/settings/handle.d.ts +30 -0
- package/dist/internal-types/settings/index.d.ts +10 -0
- package/dist/internal-types/settings/move.d.ts +76 -0
- package/dist/internal-types/settings/parse.d.ts +24 -0
- package/dist/internal-types/settings/paths.d.ts +12 -0
- package/dist/internal-types/settings/refusal.d.ts +7 -0
- package/dist/internal-types/settings/resolve.d.ts +15 -0
- package/dist/internal-types/settings/schema.d.ts +29 -0
- package/dist/internal-types/settings/snapshot.d.ts +24 -0
- package/dist/layout-fence.d.ts +7 -1
- package/dist/native-account-runtime.d.ts +24 -8
- package/dist/native-migration-source.d.ts +5 -0
- package/dist/native-migration.d.ts +15 -0
- package/dist/native-runtime-settings.d.ts +72 -0
- package/dist/native-settings-write.d.ts +48 -0
- package/dist/native-setup-settings.d.ts +39 -0
- package/dist/path-options.d.ts +16 -0
- package/dist/pool-paths.d.ts +2 -1
- package/dist/routing-relay.d.ts +6 -1
- package/dist/routing-wait.d.ts +14 -0
- package/dist/routing.d.ts +2 -2
- package/dist/settings-authority.d.ts +8 -0
- package/dist/settings-definition.d.ts +621 -0
- package/dist/settings-host-import.d.ts +25 -0
- package/dist/settings-mode.d.ts +36 -0
- package/dist/settings-move-fence.d.ts +49 -0
- package/dist/settings-move-map.d.ts +7 -0
- package/dist/settings-move-run.d.ts +31 -0
- package/dist/settings-move-source.d.ts +52 -0
- package/dist/settings-move-sources.d.ts +59 -0
- package/dist/settings-paths.d.ts +30 -0
- package/dist/settings-protection-copy.d.ts +12 -0
- package/dist/settings-protection-legacy.d.ts +22 -0
- package/dist/settings-record.d.ts +14 -0
- package/dist/settings-service.d.ts +215 -0
- package/dist/settings-start.d.ts +57 -0
- package/dist/settings-three-way.d.ts +5 -0
- package/dist/sticky-routing.d.ts +14 -0
- package/package.json +3 -2
- package/schema/anthropic-auth.schema.json +1081 -0
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type { SettingsEdit } from "./internal-types/settings/index.js";
|
|
2
|
+
import type { AccountStorage } from './accounts.ts';
|
|
3
|
+
import { type SettingsKey } from './settings-definition.ts';
|
|
4
|
+
import { type SettingsMode, type SettingsModeOptions } from './settings-mode.ts';
|
|
5
|
+
import type { SettingsHost } from './settings-paths.ts';
|
|
6
|
+
import type { SettingsFileStatus, SettingsService, SettingsUpdateOptions, SettingsValues } from './settings-service.ts';
|
|
7
|
+
import type { SettingsProtectionFallback } from './settings-start.ts';
|
|
8
|
+
export interface NativeRuntimeSettingsOptions {
|
|
9
|
+
settingsService?: SettingsService;
|
|
10
|
+
/** Return the cached settings mode; this callback must not read the filesystem. */
|
|
11
|
+
settingsMode?: () => SettingsMode;
|
|
12
|
+
settingsAuthority?: {
|
|
13
|
+
options?: SettingsModeOptions;
|
|
14
|
+
/** Schedule a background authority check and return its cancellation function. */
|
|
15
|
+
schedule?: (callback: () => Promise<void>, delayMs: number) => () => void;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* From `startSettings` when the file is in charge but its service could not
|
|
19
|
+
* open: requests overlay the fallback's protection on the legacy record,
|
|
20
|
+
* menu writes are refused, and the authority timer and menu actions try to
|
|
21
|
+
* open the service again until it replaces the fallback.
|
|
22
|
+
*/
|
|
23
|
+
settingsFallback?: SettingsProtectionFallback;
|
|
24
|
+
/**
|
|
25
|
+
* From `startSettings` in legacy mode when the service could not open: the
|
|
26
|
+
* authority timer and menu actions open it again off the request path, so a
|
|
27
|
+
* move another host publishes later is still noticed.
|
|
28
|
+
*/
|
|
29
|
+
settingsReopen?: () => Promise<SettingsService | undefined>;
|
|
30
|
+
}
|
|
31
|
+
export interface NativeRuntimeSettingsStatus {
|
|
32
|
+
file: SettingsFileStatus;
|
|
33
|
+
values: SettingsValues;
|
|
34
|
+
modelOverrides: Partial<Record<SettingsKey, {
|
|
35
|
+
model: string;
|
|
36
|
+
value: SettingsValues[SettingsKey];
|
|
37
|
+
}[]>>;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Project policy settings from memory, retaining a service reference until close.
|
|
41
|
+
* The host awaits prepareAction at instance start and before every menu action.
|
|
42
|
+
* Watches and a background timer also check authority; requests use memory only.
|
|
43
|
+
*/
|
|
44
|
+
export declare function createNativeRuntimeSettings(options: NativeRuntimeSettingsOptions & {
|
|
45
|
+
host: SettingsHost;
|
|
46
|
+
env?: NodeJS.ProcessEnv;
|
|
47
|
+
}): {
|
|
48
|
+
resolve: {
|
|
49
|
+
(stored: AccountStorage, model?: string): AccountStorage;
|
|
50
|
+
(stored: Record<string, unknown>, model?: string): Record<string, unknown>;
|
|
51
|
+
};
|
|
52
|
+
status: () => NativeRuntimeSettingsStatus | undefined;
|
|
53
|
+
applyEffects: () => void;
|
|
54
|
+
file: () => string | undefined;
|
|
55
|
+
prepareAction(): Promise<void>;
|
|
56
|
+
/** The settings file while the protection fallback is in use, else undefined. */
|
|
57
|
+
fallbackFile: () => string | undefined;
|
|
58
|
+
/**
|
|
59
|
+
* Called under the legacy store's locks by a write that chose the legacy
|
|
60
|
+
* store: true when the user file became authoritative meanwhile (a move
|
|
61
|
+
* published while the write waited for those locks), so the write must
|
|
62
|
+
* leave the legacy store alone and go to the user file instead. A watch,
|
|
63
|
+
* the timer or another action may already have adopted the file while
|
|
64
|
+
* the write waited; that counts as lost too.
|
|
65
|
+
*/
|
|
66
|
+
legacyAuthorityLost(): Promise<boolean>;
|
|
67
|
+
/** Recheck authority on the menu path before choosing a write target. */
|
|
68
|
+
prepareWrite(): Promise<SettingsService | undefined>;
|
|
69
|
+
legacyWriteCommitted(source: string, stored: Record<string, unknown>): Promise<void>;
|
|
70
|
+
update(edits: readonly SettingsEdit[], before: Record<string, unknown>, planned?: Pick<SettingsUpdateOptions, 'expectedSource' | 'expectMissing'>): Promise<void>;
|
|
71
|
+
close: () => Promise<void>;
|
|
72
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { SettingsEdit } from "./internal-types/settings/index.js";
|
|
2
|
+
import type { SettingsHost } from './settings-paths.ts';
|
|
3
|
+
import { type SettingsGeneration, type SettingsValues } from './settings-service.ts';
|
|
4
|
+
type Settings = Record<string, unknown>;
|
|
5
|
+
interface StoreChange {
|
|
6
|
+
path: string[];
|
|
7
|
+
value: unknown;
|
|
8
|
+
}
|
|
9
|
+
/** Plan the whole menu transaction before either the file or the legacy store changes. */
|
|
10
|
+
export declare function planNativeSettingsWrite(before: Settings, after: Settings, generation: SettingsGeneration, host: SettingsHost): {
|
|
11
|
+
edits: SettingsEdit[];
|
|
12
|
+
storeChanges: StoreChange[];
|
|
13
|
+
refusal: string | undefined;
|
|
14
|
+
/**
|
|
15
|
+
* What a floor-list edit was planned from: the file text, or a missing
|
|
16
|
+
* file. The write is refused as busy if the file is no longer that.
|
|
17
|
+
*/
|
|
18
|
+
floorsFrom: {
|
|
19
|
+
status: 'missing';
|
|
20
|
+
} | {
|
|
21
|
+
status: 'ready';
|
|
22
|
+
source: string;
|
|
23
|
+
} | undefined;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* The acting host's floor-list edit, as a pure function of the file it
|
|
27
|
+
* finds: the parsed document, or a missing file, which starts from the list
|
|
28
|
+
* a recreation carries. Only the acting host's entries for the changed
|
|
29
|
+
* accounts change; a `both` entry for such an account is split first so the
|
|
30
|
+
* other host keeps its floor. Returns undefined when the list is unchanged.
|
|
31
|
+
*
|
|
32
|
+
* common-auth 0.48 can't run this under its write lock, so the caller plans
|
|
33
|
+
* from a generation and the service refuses the write if the file changed
|
|
34
|
+
* since (see `SettingsUpdateOptions.expectedSource`); that leaves a small
|
|
35
|
+
* window before the lock. common-auth 0.49's planned update will pass this
|
|
36
|
+
* function the document read under the lock, closing it.
|
|
37
|
+
*/
|
|
38
|
+
export declare function planSettingsAccountFloors(current: {
|
|
39
|
+
status: 'missing';
|
|
40
|
+
} | {
|
|
41
|
+
status: 'ready';
|
|
42
|
+
document: unknown;
|
|
43
|
+
}, changes: ReadonlyMap<string, Record<string, unknown> | undefined>, host: SettingsHost, recreation: SettingsValues['killswitch_account_floors']): SettingsEdit | undefined;
|
|
44
|
+
/** Apply only store-held deltas to a fresh legacy record, never the resolved settings projection. */
|
|
45
|
+
export declare function applyNativeStoreSettingsChanges(stored: Settings, changes: readonly StoreChange[]): Settings;
|
|
46
|
+
/** Old releases only understand booleans in these legacy fields. */
|
|
47
|
+
export declare function legacyNativeSettings(settings: Settings): Settings;
|
|
48
|
+
export {};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { type SettingsKey } from './settings-definition.ts';
|
|
2
|
+
import { type SettingsModeOptions } from './settings-mode.ts';
|
|
3
|
+
import { type SettingsHost, type SettingsPathOptions, type SettingsPaths } from './settings-paths.ts';
|
|
4
|
+
import { type SettingsProtectionRecovery } from './settings-service.ts';
|
|
5
|
+
export interface NativeSetupSettingsDifference {
|
|
6
|
+
key: SettingsKey;
|
|
7
|
+
account?: string;
|
|
8
|
+
legacy: unknown;
|
|
9
|
+
file: unknown;
|
|
10
|
+
note?: string;
|
|
11
|
+
}
|
|
12
|
+
export interface NativeSetupSettingsResult {
|
|
13
|
+
target: 'legacy-store' | 'user-file';
|
|
14
|
+
outcome: 'saved' | 'refused' | 'failed';
|
|
15
|
+
reason?: string;
|
|
16
|
+
skipped: SettingsKey[];
|
|
17
|
+
differing: NativeSetupSettingsDifference[];
|
|
18
|
+
}
|
|
19
|
+
export interface NativeSetupSettingsOptions extends SettingsPathOptions {
|
|
20
|
+
host: SettingsHost;
|
|
21
|
+
/** Raw legacy fields captured before retirement, never a resolved settings record. */
|
|
22
|
+
settings: Record<string, unknown>;
|
|
23
|
+
source: string;
|
|
24
|
+
paths?: SettingsPaths;
|
|
25
|
+
authority?: SettingsModeOptions;
|
|
26
|
+
/** Use the acting host's selected local or vault store and its normal writer lock. */
|
|
27
|
+
writeLegacySettings: (settings: Record<string, unknown>) => Promise<void>;
|
|
28
|
+
/** Startup recovery; readLegacyProtection reads this host's active local or vault settings store. */
|
|
29
|
+
protection?: SettingsProtectionRecovery;
|
|
30
|
+
log?: {
|
|
31
|
+
warn(message: string): void;
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Called only after credential commit, while hosts are stopped. Decide authority
|
|
36
|
+
* once per attempt (including resume), never run startup's one-time settings
|
|
37
|
+
* migration, and fill only missing user-file values. Legacy writes receive raw legacy fields, not a projection.
|
|
38
|
+
*/
|
|
39
|
+
export declare function writeNativeSetupSettings(options: NativeSetupSettingsOptions): Promise<NativeSetupSettingsResult>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { realpath } from 'node:fs/promises';
|
|
2
|
+
import { posix } from 'node:path';
|
|
3
|
+
/** Pass one process's inputs through every settings path decision. */
|
|
4
|
+
export interface PathResolutionOptions {
|
|
5
|
+
env?: Readonly<Record<string, string | undefined>>;
|
|
6
|
+
home?: string;
|
|
7
|
+
platform?: NodeJS.Platform;
|
|
8
|
+
realpath?: (path: string) => Promise<string>;
|
|
9
|
+
}
|
|
10
|
+
export declare function resolvePathOptions(options?: PathResolutionOptions): {
|
|
11
|
+
env: Readonly<Record<string, string | undefined>>;
|
|
12
|
+
home: string;
|
|
13
|
+
platform: NodeJS.Platform;
|
|
14
|
+
realpath: ((path: string) => Promise<string>) | typeof realpath;
|
|
15
|
+
paths: typeof posix;
|
|
16
|
+
};
|
package/dist/pool-paths.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type PathResolutionOptions } from './path-options.ts';
|
|
1
2
|
import { type StateLayout } from './state-layout-paths.ts';
|
|
2
3
|
export interface NativePoolPaths {
|
|
3
4
|
legacyConfig: string;
|
|
@@ -22,7 +23,7 @@ export declare function resolveLocalRoutingDestination(host: 'opencode' | 'pi',
|
|
|
22
23
|
* This can follow a leaf symlink, so it does not establish configured-leaf safety.
|
|
23
24
|
* Source capture and recheck must retain the configured path for the lstat guard.
|
|
24
25
|
*/
|
|
25
|
-
export declare function canonicalPath(path: string): Promise<string>;
|
|
26
|
+
export declare function canonicalPath(path: string, options?: PathResolutionOptions): Promise<string>;
|
|
26
27
|
/**
|
|
27
28
|
* Separate runtime authority from import inputs so a stale legacy writer cannot
|
|
28
29
|
* rewrite a stamped credential. Both independently configured paths matter.
|
package/dist/routing-relay.d.ts
CHANGED
|
@@ -16,6 +16,11 @@ type RoutingSubject = {
|
|
|
16
16
|
};
|
|
17
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
18
|
export declare function routingCandidates(accounts: readonly NativeAccountView[]): NativeAccountView[];
|
|
19
|
+
/** Hint only the still-servable vault credential behind the session's own pin. */
|
|
20
|
+
export declare function routingWarmCredential(accounts: readonly NativeAccountView[], assignment: {
|
|
21
|
+
accountId: string;
|
|
22
|
+
accountIdentity?: string;
|
|
23
|
+
} | undefined): string | undefined;
|
|
19
24
|
export declare function routingChoiceMatches(choice: RoutingChoice, account: RoutingSubject): boolean;
|
|
20
25
|
/** Fixed text avoids exposing router internals and is not a host auto-retry signal. */
|
|
21
26
|
export declare class RoutingRefusalError extends Error {
|
|
@@ -30,7 +35,7 @@ export declare function createRoutingRelay(quotaFor?: (subject: RoutingSubject)
|
|
|
30
35
|
shouldReport(sessionId: string): boolean;
|
|
31
36
|
admitted(sessionId: string, subject: RoutingSubject): boolean;
|
|
32
37
|
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>;
|
|
38
|
+
accountFor(sessionId: string, modelId: string, candidates: readonly RoutingSubject[], warmCredentialId?: string): Promise<RoutingChoice | null>;
|
|
34
39
|
report(sessionId: string, subject: RoutingSubject, headers: Headers, status: number, modelId?: string, served?: boolean): void;
|
|
35
40
|
};
|
|
36
41
|
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type PluginWaitReason } from "./internal-types/routing-accessor/index.js";
|
|
2
|
+
type WaitReason = Extract<PluginWaitReason, 'account_limit' | 'account_free' | 'rate_limited' | 'routing_hold'>;
|
|
3
|
+
type WaitOutcome = 'resumed' | 'cancelled' | 'abandoned';
|
|
4
|
+
/** Report a real delay without calling reportRouting on the request path.
|
|
5
|
+
* Call the returned callback when the wait ends. When the app owns the delay,
|
|
6
|
+
* the plugin cannot observe completion and reports only its start. */
|
|
7
|
+
export declare function startRoutingWait(input: {
|
|
8
|
+
sessionId?: string;
|
|
9
|
+
reason: WaitReason;
|
|
10
|
+
delayMs: number;
|
|
11
|
+
nextMs?: number;
|
|
12
|
+
attempt?: number;
|
|
13
|
+
}): ((outcome: WaitOutcome) => void) | undefined;
|
|
14
|
+
export {};
|
package/dist/routing.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import type { AccountStorage, RoutingMode } from './accounts.ts';
|
|
1
|
+
import type { AccountSettingsReaderInput, AccountStorage, RoutingMode } from './accounts.ts';
|
|
2
2
|
export declare const CLAUDE_ROUTING_COMMAND_NAME = "claude-routing";
|
|
3
3
|
export declare const ROUTING_MODES: readonly ['main-first', 'fallback-first', 'sticky-balanced'];
|
|
4
4
|
export declare const DEFAULT_ROUTING_MODE: RoutingMode;
|
|
5
5
|
export declare const MAX_SAME_ACCOUNT_WAITS: readonly ['0', '15', 'max'];
|
|
6
6
|
export type MaxSameAccountWait = (typeof MAX_SAME_ACCOUNT_WAITS)[number];
|
|
7
7
|
export declare const DEFAULT_MAX_SAME_ACCOUNT_WAIT: MaxSameAccountWait;
|
|
8
|
-
export declare function getMaxSameAccountWait(storage:
|
|
8
|
+
export declare function getMaxSameAccountWait(storage: AccountSettingsReaderInput | null): MaxSameAccountWait;
|
|
9
9
|
type RoutingCommandAction = {
|
|
10
10
|
type: 'status';
|
|
11
11
|
} | {
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { SettingsKey } from './settings-definition.ts';
|
|
2
|
+
import type { SettingsHost } from './settings-paths.ts';
|
|
3
|
+
import type { SettingsValues } from './settings-service.ts';
|
|
4
|
+
/** Only explicitly stored moved fields warrant a not-imported diagnostic. */
|
|
5
|
+
export declare function holdsMovedSettings(stored: unknown): boolean;
|
|
6
|
+
/** Compare account floors for this host only; list order and the peer's entries do not decide its values. */
|
|
7
|
+
export declare function differingLegacySettings(legacy: Partial<SettingsValues>, resolved: SettingsValues, host: SettingsHost): SettingsKey[];
|
|
8
|
+
export declare function settingsNotImportedText(source: string, target: string, differing?: readonly SettingsKey[]): string;
|