@cortexkit/anthropic-auth-core 1.22.0 → 2.0.0
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/README.md +2 -0
- package/dist/accounts.d.ts +52 -8
- package/dist/cachekeep.d.ts +27 -1
- package/dist/cch.d.ts +11 -1
- package/dist/claude-code.d.ts +23 -1
- package/dist/claustrum-enrollment.d.ts +72 -0
- package/dist/claustrum-scoped-roster.d.ts +27 -0
- package/dist/claustrum-scoped-runtime.d.ts +31 -0
- package/dist/claustrum-scoped.d.ts +53 -0
- package/dist/claustrum.d.ts +16 -82
- package/dist/commands/account.d.ts +38 -11
- package/dist/constants.d.ts +3 -2
- package/dist/custom-headers.d.ts +3 -0
- package/dist/index.d.ts +50 -0
- package/dist/index.js +29700 -31
- package/dist/internal-types/LICENSE +21 -0
- package/dist/internal-types/commands/builtins.d.ts +71 -0
- package/dist/internal-types/commands/index.d.ts +10 -0
- package/dist/internal-types/commands/menu.d.ts +61 -0
- package/dist/internal-types/commands/model.d.ts +238 -0
- package/dist/internal-types/commands/pi.d.ts +23 -0
- package/dist/internal-types/commands/seam.d.ts +72 -0
- package/dist/internal-types/fs/refresh-file-lock.d.ts +33 -0
- package/dist/internal-types/logger/capture-sink.d.ts +14 -0
- package/dist/internal-types/logger/engine.d.ts +100 -0
- package/dist/internal-types/logger/index.d.ts +6 -0
- package/dist/internal-types/logger/redact.d.ts +11 -0
- package/dist/internal-types/pi-slot/index.d.ts +3 -0
- package/dist/internal-types/pi-slot/slot.d.ts +49 -0
- package/dist/internal-types/quota/codec.d.ts +11 -0
- package/dist/internal-types/quota/format.d.ts +46 -0
- package/dist/internal-types/quota/index.d.ts +10 -0
- package/dist/internal-types/quota/map.d.ts +63 -0
- package/dist/internal-types/quota/merge.d.ts +48 -0
- package/dist/internal-types/quota/projection.d.ts +64 -0
- package/dist/internal-types/store/attribution.d.ts +28 -0
- package/dist/internal-types/store/errors.d.ts +55 -0
- package/dist/internal-types/store/hooks.d.ts +12 -0
- package/dist/internal-types/store/identity.d.ts +39 -0
- package/dist/internal-types/store/index.d.ts +21 -0
- package/dist/internal-types/store/mutate.d.ts +189 -0
- package/dist/internal-types/store/pool.d.ts +196 -0
- package/dist/internal-types/store/provider-state.d.ts +131 -0
- package/dist/internal-types/store/publication.d.ts +47 -0
- package/dist/internal-types/store/pull.d.ts +36 -0
- package/dist/internal-types/store/refresh-lock.d.ts +63 -0
- package/dist/internal-types/store/refresh.d.ts +72 -0
- package/dist/internal-types/store/rows.d.ts +313 -0
- package/dist/internal-types/store/runtime.d.ts +36 -0
- package/dist/internal-types/store/schema.d.ts +443 -0
- package/dist/internal-types/store/settings.d.ts +63 -0
- package/dist/internal-types/store/torn.d.ts +78 -0
- package/dist/migration-source.d.ts +33 -0
- package/dist/model-remap.d.ts +27 -0
- package/dist/models.d.ts +60 -0
- package/dist/native-account-runtime.d.ts +121 -0
- package/dist/native-account-view.d.ts +126 -0
- package/dist/native-command-effects.d.ts +59 -0
- package/dist/native-credential-validation.d.ts +42 -0
- package/dist/native-custody-activation.d.ts +45 -0
- package/dist/native-custody.d.ts +114 -0
- package/dist/native-enrollment-authority.d.ts +2 -0
- package/dist/native-host-auth-read.d.ts +3 -0
- package/dist/native-host-auth-write.d.ts +51 -0
- package/dist/native-host-auth.d.ts +12 -0
- package/dist/native-local-credential-service.d.ts +76 -0
- package/dist/native-local-runtime-readers.d.ts +22 -0
- package/dist/native-lock-observer.d.ts +12 -0
- package/dist/native-menu-executor.d.ts +243 -0
- package/dist/native-menu-model.d.ts +142 -0
- package/dist/native-migration-proof.d.ts +28 -0
- package/dist/native-migration-source.d.ts +47 -0
- package/dist/native-migration.d.ts +66 -0
- package/dist/native-quota-codec.d.ts +32 -0
- package/dist/native-refresh-coordinator.d.ts +240 -0
- package/dist/native-roster-seed.d.ts +115 -0
- package/dist/native-runtime-registry.d.ts +19 -0
- package/dist/native-runtime.d.ts +204 -0
- package/dist/native-transient-account.d.ts +38 -0
- package/dist/native-ui.d.ts +45 -0
- package/dist/native-usage-publication.d.ts +11 -0
- package/dist/native-vault-admission.d.ts +8 -0
- package/dist/native-vault-connection.d.ts +33 -0
- package/dist/native-vault-paths.d.ts +13 -0
- package/dist/native-vault-runtime.d.ts +102 -0
- package/dist/native-vault-seed.d.ts +16 -0
- package/dist/oauth-profile.d.ts +2 -1
- package/dist/pool-authority.d.ts +159 -0
- package/dist/pool-binding.d.ts +32 -0
- package/dist/pool-paths.d.ts +21 -0
- package/dist/pool-store.d.ts +32 -0
- package/dist/prime.d.ts +11 -3
- package/dist/provider-error.d.ts +139 -0
- package/dist/quota-header-feed.d.ts +13 -0
- package/dist/quota-manager.d.ts +30 -5
- package/dist/relay.d.ts +22 -1
- package/dist/request-history.d.ts +34 -0
- package/dist/sse.d.ts +81 -0
- package/dist/sticky-routing.d.ts +29 -0
- package/package.json +9 -3
- package/dist/accounts.js +0 -3330
- package/dist/auth.js +0 -182
- package/dist/cache1h.js +0 -97
- package/dist/cachekeep-registry.js +0 -124
- package/dist/cachekeep.js +0 -578
- package/dist/cch.js +0 -127
- package/dist/claude-code.js +0 -388
- package/dist/claustrum.js +0 -529
- package/dist/commands/account.js +0 -239
- package/dist/constants.js +0 -82
- package/dist/dump.js +0 -616
- package/dist/fast.js +0 -66
- package/dist/json.js +0 -10
- package/dist/killswitch.js +0 -132
- package/dist/logger.js +0 -286
- package/dist/logging.js +0 -59
- package/dist/mid-conversation-output-config.js +0 -89
- package/dist/models.js +0 -141
- package/dist/network-errors.js +0 -27
- package/dist/oauth-profile.js +0 -54
- package/dist/pkce.js +0 -17
- package/dist/prime.js +0 -823
- package/dist/provider.js +0 -0
- package/dist/quota-header-feed.js +0 -279
- package/dist/quota-headers.js +0 -121
- package/dist/quota-manager.js +0 -805
- package/dist/quotas.js +0 -141
- package/dist/relay.js +0 -1243
- package/dist/routing.js +0 -94
- package/dist/start.js +0 -29
- package/dist/sticky-routing.js +0 -523
- package/dist/thinking-binding.js +0 -54
- package/dist/token-fingerprint.js +0 -8
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { type CommandInvocation, type CommandMenu } from "./internal-types/commands/index.js";
|
|
2
|
+
export type { CommandApplyRequest, CommandApplyResult, CommandDialogPayload, CommandInvocation, CommandMenu, CommandMenuModel, KnobValue, KnobValues, MenuAction, MenuItem, MenuKnob, MenuSection, NotifyKind, SectionSlot, } from "./internal-types/commands/index.js";
|
|
3
|
+
export { parseApplyRequest, runPiCommandMenu, } from "./internal-types/commands/index.js";
|
|
4
|
+
import { type NativeMenuDispatch, type NativeVaultDisconnect } from './native-menu-executor.ts';
|
|
5
|
+
import { type NativeMenuCommandId, type NativeMenuCustodyMode, type NativeMenuHost } from './native-menu-model.ts';
|
|
6
|
+
export interface NativeUiOptions {
|
|
7
|
+
readonly host: NativeMenuHost;
|
|
8
|
+
/** Execute account/settings changes and host actions; this adapter never writes their storage. */
|
|
9
|
+
readonly dispatch: NativeMenuDispatch;
|
|
10
|
+
/** Read-only account, quota and settings status. Exclude OAuth tokens, API keys and other secrets. */
|
|
11
|
+
readonly readStatus: (command: Exclude<NativeMenuCommandId, 'start'>, invocation: CommandInvocation) => Promise<string>;
|
|
12
|
+
/**
|
|
13
|
+
* Reads the host's current credential custody from its enrollment record,
|
|
14
|
+
* never from status text. It is called each time the menu opens or applies
|
|
15
|
+
* an action, so connecting or disconnecting the vault takes effect without
|
|
16
|
+
* rebuilding the menu. Under 'claustrum' the menu leaves out and refuses
|
|
17
|
+
* actions offered only under local custody: host-local account and
|
|
18
|
+
* credential writes, and enrollment reset. A rejection or any other value
|
|
19
|
+
* is treated as unknown custody, which also withholds them.
|
|
20
|
+
*/
|
|
21
|
+
readonly readMode: () => Promise<NativeMenuCustodyMode>;
|
|
22
|
+
/** Token-free account names, credential IDs and states used to show which vault account needs re-login and its replacement command. */
|
|
23
|
+
readonly readAccounts?: () => Promise<import('./native-account-view.ts').NativeAccountSnapshot>;
|
|
24
|
+
/**
|
|
25
|
+
* Disconnects this host from the vault; while enrolled, this is the host's
|
|
26
|
+
* only enrollment action. Before ending the enrollment, the callback
|
|
27
|
+
* restores any host sign-in set aside when the host joined the vault. If
|
|
28
|
+
* that restore would overwrite a sign-in the host already has, the callback
|
|
29
|
+
* reports `conflict` and leaves the enrollment in place. Every host must
|
|
30
|
+
* supply it: a host enrolled in the vault, or with an unreadable
|
|
31
|
+
* enrollment, always needs a way back to local accounts.
|
|
32
|
+
*/
|
|
33
|
+
readonly disconnectVault: NativeVaultDisconnect;
|
|
34
|
+
/** The host sets this flag; RPC callers cannot declare themselves interactive. */
|
|
35
|
+
readonly interactive: boolean;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Builds the Claude menu from the supported commands for OpenCode or Pi.
|
|
39
|
+
* Shared renderers display it, but each submitted action still goes through
|
|
40
|
+
* input validation, required confirmation and host capability checks.
|
|
41
|
+
* Credential fields never contain saved values. Current host input controls
|
|
42
|
+
* display typed text even when the field requests masking; do not promise
|
|
43
|
+
* hidden entry until those controls support it.
|
|
44
|
+
*/
|
|
45
|
+
export declare function createNativeUi(options: NativeUiOptions): CommandMenu;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Custody, ownership and integrity refusals need an ERROR diagnostic; ordinary
|
|
3
|
+
* storage failures need a WARN. Neither may revoke an already-served reply.
|
|
4
|
+
* The error classes are not public runtime exports, so match name and code.
|
|
5
|
+
*/
|
|
6
|
+
export declare function usagePublicationRefusalIsFatal(error: unknown): boolean;
|
|
7
|
+
/** Own advisory writes for one host instance and join them before runtime close. */
|
|
8
|
+
export declare function createNativeUsagePublisher(channel: string): {
|
|
9
|
+
publish(write: () => Promise<unknown>): void;
|
|
10
|
+
drain(): Promise<void>;
|
|
11
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { NativeAccountRuntime } from './native-account-runtime.ts';
|
|
2
|
+
import type { NativeAccountSnapshot } from './native-account-view.ts';
|
|
3
|
+
export declare const NATIVE_VAULT_NO_ACCOUNT_MESSAGE = "No vault account can serve this request. Open /claude to see which account needs signing in again.";
|
|
4
|
+
export declare class NativeVaultNoAccountError extends Error {
|
|
5
|
+
constructor();
|
|
6
|
+
}
|
|
7
|
+
/** A missing roster may be discovery still in progress, not an empty pool. */
|
|
8
|
+
export declare function readNativeAccountsForRequest(runtime: NativeAccountRuntime, signal?: AbortSignal): Promise<NativeAccountSnapshot>;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { type PiSlot } from "./internal-types/pi-slot/index.js";
|
|
2
|
+
export type { PiSlot as NativePiAuthSlot, PiSlotErrorCode as NativePiAuthSlotErrorCode, PiSlotInspection as NativePiAuthSlotInspection, } from "./internal-types/pi-slot/index.js";
|
|
3
|
+
export { PiSlotError as NativePiAuthSlotError } from "./internal-types/pi-slot/index.js";
|
|
4
|
+
export interface NativePiAuthSlotOptions {
|
|
5
|
+
/** The Pi adapter supplies its SDK-owned auth path; enrollment paths do not identify that file. */
|
|
6
|
+
authPath: string;
|
|
7
|
+
env?: NodeJS.ProcessEnv;
|
|
8
|
+
}
|
|
9
|
+
/** Setup and disconnect must use the same host auth file, private stash and inert API-key marker. */
|
|
10
|
+
export declare function nativePiAuthSlotPaths(options: NativePiAuthSlotOptions): {
|
|
11
|
+
authPath: string;
|
|
12
|
+
stashPath: string;
|
|
13
|
+
provider: string;
|
|
14
|
+
placeholderKey: string;
|
|
15
|
+
};
|
|
16
|
+
/** Delegate private Pi-auth preservation to the shared locked writer; never create a second host-slot writer. */
|
|
17
|
+
export declare function openNativePiAuthSlot(options: NativePiAuthSlotOptions): PiSlot;
|
|
18
|
+
export type NativeVaultDisconnectOptions = {
|
|
19
|
+
host: 'opencode';
|
|
20
|
+
env?: NodeJS.ProcessEnv;
|
|
21
|
+
} | {
|
|
22
|
+
host: 'pi';
|
|
23
|
+
env?: NodeJS.ProcessEnv;
|
|
24
|
+
slot: Pick<PiSlot, 'exitVault'>;
|
|
25
|
+
};
|
|
26
|
+
export type NativeVaultDisconnectResult = 'disconnected' | 'idle' | 'busy' | 'conflict';
|
|
27
|
+
/**
|
|
28
|
+
* Restore Pi's stored authentication before removing this host's enrollment.
|
|
29
|
+
* A conflicting replacement belongs to the user: leave both it and enrollment
|
|
30
|
+
* intact rather than selecting local custody with unresolved recovery data.
|
|
31
|
+
* OpenCode authentication is never changed by this operation.
|
|
32
|
+
*/
|
|
33
|
+
export declare function disconnectNativeVaultForHost(options: NativeVaultDisconnectOptions): Promise<NativeVaultDisconnectResult>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { NativePoolPaths } from './pool-paths.ts';
|
|
2
|
+
/** Vault files have no migration journal: enrollment alone authorizes their use. */
|
|
3
|
+
export interface NativeVaultPaths {
|
|
4
|
+
config: string;
|
|
5
|
+
state: string;
|
|
6
|
+
runtime: string;
|
|
7
|
+
roster: string;
|
|
8
|
+
routing: string;
|
|
9
|
+
storageId: string;
|
|
10
|
+
legacySeedConfig: string;
|
|
11
|
+
}
|
|
12
|
+
/** Keep vault settings, metadata and affinity outside every local recovery file. */
|
|
13
|
+
export declare function nativeVaultPaths(local: NativePoolPaths): NativeVaultPaths;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { type ClaustrumClientOptions } from '@cortexkit/claustrum-client';
|
|
2
|
+
import { type OAuthAccountProfile, type OAuthQuotaSnapshot, type PrimeUsageDelta } from './accounts.ts';
|
|
3
|
+
import { type NativeAccountMetadataPatch } from './native-account-view.ts';
|
|
4
|
+
import { type NativeCustodyClient, type NativeCustodyInventory, type NativeCustodyReceipt, type NativeCustodyReporterSource, type NativeCustodyRetry } from './native-custody.ts';
|
|
5
|
+
import { type NativeRosterSeedInput, type NativeVaultRosterDocument, type NativeVaultRosterSeed } from './native-roster-seed.ts';
|
|
6
|
+
import { type NativeRuntimeState } from './native-runtime.ts';
|
|
7
|
+
import type { NativeVaultPaths } from './native-vault-paths.ts';
|
|
8
|
+
import type { NativePoolPaths } from './pool-paths.ts';
|
|
9
|
+
import type { QuotaRequestDispatch } from './quota-manager.ts';
|
|
10
|
+
export interface NativeVaultRuntimeOptions {
|
|
11
|
+
paths: NativePoolPaths;
|
|
12
|
+
host: 'opencode' | 'pi';
|
|
13
|
+
identity?: ClaustrumClientOptions['identity'];
|
|
14
|
+
connect?: () => Promise<NativeCustodyClient>;
|
|
15
|
+
/** Reuse the inventory verifier supplied by offline setup without changing per-send scoped authorization. */
|
|
16
|
+
discover?: () => Promise<NativeCustodyInventory>;
|
|
17
|
+
readToken?: () => Promise<{
|
|
18
|
+
token: string;
|
|
19
|
+
token_generation: number;
|
|
20
|
+
}>;
|
|
21
|
+
env?: NodeJS.ProcessEnv;
|
|
22
|
+
now?: () => number;
|
|
23
|
+
}
|
|
24
|
+
export interface NativeVaultWatchOptions {
|
|
25
|
+
intervalMs: number;
|
|
26
|
+
onRefresh?: () => void | Promise<void>;
|
|
27
|
+
shouldRefresh?: () => boolean | Promise<boolean>;
|
|
28
|
+
setInterval?: typeof globalThis.setInterval;
|
|
29
|
+
clearInterval?: typeof globalThis.clearInterval;
|
|
30
|
+
}
|
|
31
|
+
export interface NativeVaultWatch {
|
|
32
|
+
readonly ready: Promise<void>;
|
|
33
|
+
close(): void;
|
|
34
|
+
}
|
|
35
|
+
/** Send classes that may replay once after a vault credential's 401, named in diagnostics. */
|
|
36
|
+
export type NativeScoped401Site = 'model' | 'model-relay' | 'cachekeep' | 'prime' | 'quota-profile';
|
|
37
|
+
export type NativeProfilePersistence = 'saved' | 'refused' | 'failed';
|
|
38
|
+
/** The profile fields a display may receive; never the legacy token fingerprint. */
|
|
39
|
+
export type NativeDisplayProfileMetadata = Pick<OAuthAccountProfile, 'tier' | 'orgType' | 'checkedAt' | 'accountIdentity' | 'providerAccountUuid'>;
|
|
40
|
+
/**
|
|
41
|
+
* A fetched account tier for immediate display. `profile` contains metadata
|
|
42
|
+
* only, never tokens or authorization receipts. `persisted` reports whether
|
|
43
|
+
* the write succeeded, was refused because credentials or lock ownership
|
|
44
|
+
* changed, or failed because storage was unavailable. It never rejects.
|
|
45
|
+
* Call isCurrent before displaying the tier, including after a storage failure.
|
|
46
|
+
*/
|
|
47
|
+
export interface NativeDisplayProfile {
|
|
48
|
+
profile: NativeDisplayProfileMetadata;
|
|
49
|
+
persisted: Promise<NativeProfilePersistence>;
|
|
50
|
+
/** Check the same account and token or vault record version, without fetching credentials. */
|
|
51
|
+
isCurrent(): Promise<boolean>;
|
|
52
|
+
}
|
|
53
|
+
/** Build a NativeDisplayProfile from a validated profile and its publication. */
|
|
54
|
+
export declare function nativeDisplayProfile(profile: OAuthAccountProfile, publish: () => Promise<boolean>, isCurrent: () => Promise<boolean>): NativeDisplayProfile;
|
|
55
|
+
export interface NativeVaultRuntime {
|
|
56
|
+
/** Subscribe to one discovery loop; notifications contain no credential material. */
|
|
57
|
+
watch(options: NativeVaultWatchOptions): NativeVaultWatch;
|
|
58
|
+
initializeSettings(): Promise<void>;
|
|
59
|
+
read(): Promise<NativeVaultRosterDocument | undefined>;
|
|
60
|
+
refresh(signal?: AbortSignal): Promise<NativeVaultRosterDocument | undefined>;
|
|
61
|
+
authorize(routeId: string, signal?: AbortSignal): Promise<NativeCustodyReceipt>;
|
|
62
|
+
reportFailure(receipt: NativeCustodyReceipt, status: number, source: NativeCustodyReporterSource): Promise<void>;
|
|
63
|
+
/**
|
|
64
|
+
* After a 401, acquire a fresh receipt for the same credential and account.
|
|
65
|
+
* Permit one replay only if its recordVersion exceeds the rejected receipt's
|
|
66
|
+
* version. The optional site is a diagnostic call-site label: model requests,
|
|
67
|
+
* quota, profile or cache warming. Logs contain versions, never credentials.
|
|
68
|
+
* The caller reports only the receipt rejected by its final HTTP attempt.
|
|
69
|
+
*/
|
|
70
|
+
prepareRetry(receipt: NativeCustodyReceipt, signal?: AbortSignal, site?: NativeScoped401Site): Promise<NativeCustodyRetry>;
|
|
71
|
+
publish(receipt: NativeCustodyReceipt, patch: NativeAccountMetadataPatch): Promise<boolean>;
|
|
72
|
+
fetchQuota(routeId: string, fetchImpl?: typeof fetch, signal?: AbortSignal, dispatch?: QuotaRequestDispatch): Promise<OAuthQuotaSnapshot>;
|
|
73
|
+
fetchProfile(routeId: string, fetchImpl?: typeof fetch, signal?: AbortSignal): Promise<OAuthAccountProfile>;
|
|
74
|
+
/** Return the fetched account profile without waiting for its metadata write. NativeDisplayProfile.persisted reports whether that asynchronous write succeeded, failed or was refused. */
|
|
75
|
+
fetchProfileForDisplay(routeId: string, fetchImpl?: typeof fetch, signal?: AbortSignal): Promise<NativeDisplayProfile>;
|
|
76
|
+
/**
|
|
77
|
+
* Accept or decline a vault route for the user. Resolves to whether the
|
|
78
|
+
* route's enabled flag changed, judged on the roster under its write lock.
|
|
79
|
+
*/
|
|
80
|
+
setEnabled(routeId: string, enabled: boolean): Promise<boolean>;
|
|
81
|
+
resetBackoff(receipt: NativeCustodyReceipt, kind?: 'refresh' | 'quota' | 'all'): Promise<boolean>;
|
|
82
|
+
getOrCreateAuthLineage(receipt: NativeCustodyReceipt): Promise<string | undefined>;
|
|
83
|
+
incrementPrimeUsage(receipt: NativeCustodyReceipt, delta?: PrimeUsageDelta): Promise<boolean>;
|
|
84
|
+
close(): void;
|
|
85
|
+
}
|
|
86
|
+
/** Publish the initial roster from validated account inventory. A caller importing captured state must fence that state through assertOwned, which runs again at the roster's actual publication. */
|
|
87
|
+
export declare function publishNativeVaultRosterSeed(paths: Pick<NativeVaultPaths, 'roster'>, input: NativeRosterSeedInput, options?: {
|
|
88
|
+
assertOwned?: () => Promise<void>;
|
|
89
|
+
}): Promise<NativeVaultRosterSeed>;
|
|
90
|
+
/** Match imported metadata to the held vault roster before publishing it. The caller's assertOwned fences its captured input; the roster lease separately prevents account replacement during the metadata write. */
|
|
91
|
+
export declare function publishNativeVaultRuntimeSeed(paths: Pick<NativeVaultPaths, 'roster' | 'runtime' | 'storageId'>, state: NativeRuntimeState, options?: {
|
|
92
|
+
assertOwned?: () => Promise<void>;
|
|
93
|
+
}): Promise<void>;
|
|
94
|
+
/** List accounts readable by this host's enrollment for offline setup. An inventory grants no bearer authority; every outbound request still needs a fresh scoped receipt. */
|
|
95
|
+
export declare function discoverNativeVaultInventory(options: NativeVaultRuntimeOptions, signal?: AbortSignal): Promise<NativeCustodyInventory>;
|
|
96
|
+
/** Retain the vault client's original per-attempt receipts and version provenance; access tokens never persist in roster or runtime metadata. */
|
|
97
|
+
export declare function createNativeVaultRuntime(options: NativeVaultRuntimeOptions): NativeVaultRuntime;
|
|
98
|
+
export declare function nativeVaultRuntimeKey(options: NativeVaultRuntimeOptions): string;
|
|
99
|
+
/** Each handle owns one reference; disposing it cannot close another host session. */
|
|
100
|
+
export declare function acquireNativeVaultRuntime(options: NativeVaultRuntimeOptions): NativeVaultRuntime;
|
|
101
|
+
/** Each account lease wraps the shared vault runtime and tracks its own subscriptions, so releasing the lease removes those subscriptions. */
|
|
102
|
+
export declare function leaseNativeVaultRuntime(use: () => NativeVaultRuntime, close: () => void): NativeVaultRuntime;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { NativeVaultRosterDocument } from './native-roster-seed.ts';
|
|
2
|
+
export interface NativeVaultRoutingSeed {
|
|
3
|
+
legacyConfig: string;
|
|
4
|
+
roster: string;
|
|
5
|
+
mainRouteId?: string;
|
|
6
|
+
}
|
|
7
|
+
/** Missing or invalid legacy JSON skips the import rather than blocking vault requests. */
|
|
8
|
+
export declare function readNativeVaultLegacyJson(path: string): Promise<unknown>;
|
|
9
|
+
export declare function nativeVaultFileAbsent(path: string): Promise<boolean>;
|
|
10
|
+
/** Validate only preference fields, excluding credentials, account rows and stored account observations. */
|
|
11
|
+
export declare function readNativeVaultLegacySettings(path: string): Promise<Record<string, unknown>>;
|
|
12
|
+
/** Match public legacy IDs to verified vault UUIDs, never to labels, credential handles or row order. */
|
|
13
|
+
export declare function nativeVaultLegacyRoutes(source: unknown, roster: NativeVaultRosterDocument): Map<string, {
|
|
14
|
+
routeId: string;
|
|
15
|
+
accountIdentity: string;
|
|
16
|
+
}>;
|
package/dist/oauth-profile.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import type { OAuthAccountProfile } from './accounts.ts';
|
|
1
|
+
import type { OAuthAccountProfile, ProviderAccountUuid } from './accounts.ts';
|
|
2
2
|
export declare const PROFILE_TTL_MS: number;
|
|
3
3
|
export declare function fetchOAuthAccountProfile(input: {
|
|
4
4
|
accessToken: string;
|
|
5
5
|
accountIdentity?: string;
|
|
6
|
+
providerAccountUuid?: ProviderAccountUuid;
|
|
6
7
|
fetchImpl?: typeof fetch;
|
|
7
8
|
now?: () => number;
|
|
8
9
|
signal?: AbortSignal;
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { type NativeMigrationPreparedProof } from './native-migration-proof.ts';
|
|
2
|
+
import type { NativePoolPaths } from './pool-paths.ts';
|
|
3
|
+
declare const PHASES: readonly ['building', 'verified', 'activation-installed', 'committed', 'retired'];
|
|
4
|
+
export type NativeMigrationPhase = (typeof PHASES)[number];
|
|
5
|
+
export interface NativeMigrationSources {
|
|
6
|
+
config: string | null;
|
|
7
|
+
state: string | null;
|
|
8
|
+
/** SHA-256 of the host's anthropic entry with sorted JSON object keys; other providers are excluded. */
|
|
9
|
+
hostAuth: string;
|
|
10
|
+
routing: string | null;
|
|
11
|
+
}
|
|
12
|
+
export interface NativeMigrationRoutingPaths {
|
|
13
|
+
source: string;
|
|
14
|
+
destination: string;
|
|
15
|
+
}
|
|
16
|
+
export interface NativeMigrationInput {
|
|
17
|
+
host: 'opencode' | 'pi';
|
|
18
|
+
sources: NativeMigrationSources;
|
|
19
|
+
routingPaths: NativeMigrationRoutingPaths;
|
|
20
|
+
hostAuthPath: string;
|
|
21
|
+
/**
|
|
22
|
+
* Request vault custody during the first credential migration. The journal
|
|
23
|
+
* keeps native serving blocked until the separate vault activation commits.
|
|
24
|
+
*/
|
|
25
|
+
activation?: 'requested';
|
|
26
|
+
}
|
|
27
|
+
export interface NativeMigrationExpectations {
|
|
28
|
+
expectedHostAuth: string;
|
|
29
|
+
expectedRouting: string | null;
|
|
30
|
+
preparedProof: NativeMigrationPreparedProof;
|
|
31
|
+
}
|
|
32
|
+
/** Public account metadata recorded for the planned switch to vault custody. */
|
|
33
|
+
export interface NativeCustodyActivationRosterRow {
|
|
34
|
+
routeId: string;
|
|
35
|
+
credentialId: string;
|
|
36
|
+
credentialType: 'oauth';
|
|
37
|
+
accountIdentity: string;
|
|
38
|
+
state: string;
|
|
39
|
+
label: string;
|
|
40
|
+
enabled: boolean;
|
|
41
|
+
addedAt: number;
|
|
42
|
+
}
|
|
43
|
+
/** The validated vault account list that activation publishes or reuses unchanged. */
|
|
44
|
+
export interface NativeCustodyActivationRoster {
|
|
45
|
+
version: 1;
|
|
46
|
+
view: string;
|
|
47
|
+
complete: true;
|
|
48
|
+
rows: NativeCustodyActivationRosterRow[];
|
|
49
|
+
declined: {
|
|
50
|
+
credentialId: string;
|
|
51
|
+
accountIdentity?: string;
|
|
52
|
+
}[];
|
|
53
|
+
}
|
|
54
|
+
export type NativeCustodyActivationPhase = 'prepared' | 'published' | 'committed';
|
|
55
|
+
/**
|
|
56
|
+
* The offline switch of a migrated pool from local to vault custody. Every
|
|
57
|
+
* field is fixed when the activation is prepared, so a resumed run checks the
|
|
58
|
+
* files against these values and never against what it finds on disk later.
|
|
59
|
+
* Holds no credential: only public descriptor digests and vault ids.
|
|
60
|
+
*/
|
|
61
|
+
export interface NativeCustodyActivationPlan {
|
|
62
|
+
kind: 'activation';
|
|
63
|
+
phase: NativeCustodyActivationPhase;
|
|
64
|
+
/** The vault's designated primary login, bound to the pool's main route. */
|
|
65
|
+
primary: {
|
|
66
|
+
routeId: string;
|
|
67
|
+
credentialId: string;
|
|
68
|
+
accountIdentity: string;
|
|
69
|
+
};
|
|
70
|
+
roster: NativeCustodyActivationRoster;
|
|
71
|
+
/**
|
|
72
|
+
* Every credential row captured before this custody switch, including local
|
|
73
|
+
* OAuth and API-key accounts, with a digest of the imported runtime state.
|
|
74
|
+
*/
|
|
75
|
+
localProof: NativeMigrationPreparedProof;
|
|
76
|
+
/**
|
|
77
|
+
* IDs of local OAuth credential rows to remove. Keep every other row
|
|
78
|
+
* recorded in localProof.
|
|
79
|
+
*/
|
|
80
|
+
removeIds: string[];
|
|
81
|
+
/** Digests of the canonical pool settings before and after the mode switch. */
|
|
82
|
+
settings: {
|
|
83
|
+
source: string;
|
|
84
|
+
target: string;
|
|
85
|
+
};
|
|
86
|
+
/** Digests of the canonical native runtime state before and after rebinding. */
|
|
87
|
+
runtime: {
|
|
88
|
+
source: string;
|
|
89
|
+
target: string;
|
|
90
|
+
};
|
|
91
|
+
/** Anthropic host-auth entry digests (or 'absent') before and after activation. */
|
|
92
|
+
hostAuth: {
|
|
93
|
+
source: string;
|
|
94
|
+
expected: string;
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
export type NativeCustodyActivation = {
|
|
98
|
+
kind: 'requested';
|
|
99
|
+
} | NativeCustodyActivationPlan;
|
|
100
|
+
export interface NativeMigrationJournal {
|
|
101
|
+
version: 4;
|
|
102
|
+
storageId: string;
|
|
103
|
+
host: 'opencode' | 'pi';
|
|
104
|
+
phase: NativeMigrationPhase;
|
|
105
|
+
sources: NativeMigrationSources;
|
|
106
|
+
routingPaths: NativeMigrationRoutingPaths;
|
|
107
|
+
hostAuthPath: string;
|
|
108
|
+
expectedHostAuth: string;
|
|
109
|
+
expectedRouting: string | null;
|
|
110
|
+
preparedProof: NativeMigrationPreparedProof | null;
|
|
111
|
+
/**
|
|
112
|
+
* Null unless the offline setup command requested or began switching
|
|
113
|
+
* credential authority to Claustrum.
|
|
114
|
+
*/
|
|
115
|
+
activation: NativeCustodyActivation | null;
|
|
116
|
+
}
|
|
117
|
+
export declare class NativeAuthorityError extends Error {
|
|
118
|
+
readonly code: 'migration-required' | 'migration-incomplete' | 'invalid-journal' | 'journal-conflict';
|
|
119
|
+
constructor(code: 'migration-required' | 'migration-incomplete' | 'invalid-journal' | 'journal-conflict');
|
|
120
|
+
}
|
|
121
|
+
export declare function readNativeMigrationJournal(paths: NativePoolPaths): Promise<NativeMigrationJournal | undefined>;
|
|
122
|
+
/**
|
|
123
|
+
* The migration phase that authorizes serving, or undefined while the
|
|
124
|
+
* migration or a requested switch to vault custody is unfinished. Every reader
|
|
125
|
+
* that admits requests from the journal uses this one predicate.
|
|
126
|
+
*/
|
|
127
|
+
export declare function nativeMigrationAuthorityPhase(journal: NativeMigrationJournal | undefined): 'committed' | 'retired' | undefined;
|
|
128
|
+
/** An empty or readable store is not proof that the offline authority flip completed. */
|
|
129
|
+
export declare function requireNativePoolAuthority(paths: NativePoolPaths): Promise<void>;
|
|
130
|
+
interface JournalHooks {
|
|
131
|
+
/** Outer controller and pool leases remain held through the atomic journal rename. */
|
|
132
|
+
assertOwned?: () => Promise<void>;
|
|
133
|
+
lockOptions?: {
|
|
134
|
+
ttlMs: number;
|
|
135
|
+
timeoutMs: number;
|
|
136
|
+
};
|
|
137
|
+
onWriteStep?: (step: 'before-write' | 'after-write', journal: NativeMigrationJournal) => Promise<void>;
|
|
138
|
+
}
|
|
139
|
+
/** Migration resume retains the original digests and resolved paths so a retry cannot adopt changed inputs or redirect writes. */
|
|
140
|
+
export declare function beginNativeMigration(paths: NativePoolPaths, input: NativeMigrationInput, hooks?: JournalHooks): Promise<NativeMigrationJournal>;
|
|
141
|
+
/** Save the expected host-auth entry and routing digests together before changing files, so recovery can recognize completed writes. */
|
|
142
|
+
export declare function recordNativeMigrationExpectations(paths: NativePoolPaths, expectations: NativeMigrationExpectations, hooks?: JournalHooks): Promise<NativeMigrationJournal>;
|
|
143
|
+
/**
|
|
144
|
+
* Advance one phase at a time. A retry of the same transition returns the journal.
|
|
145
|
+
* Before recording activation, the caller must compare the host's Anthropic auth
|
|
146
|
+
* entry and routing file with the saved expected values. This journal records the
|
|
147
|
+
* migration stage; it does not read or verify those files.
|
|
148
|
+
*/
|
|
149
|
+
export declare function advanceNativeMigration(paths: NativePoolPaths, expected: NativeMigrationPhase, next: NativeMigrationPhase, hooks?: JournalHooks): Promise<NativeMigrationJournal>;
|
|
150
|
+
/**
|
|
151
|
+
* Record the prepared switch to vault custody on a retired migration. From
|
|
152
|
+
* this write until the activation commits, the pool authorizes no serving.
|
|
153
|
+
* Retrying with the identical plan returns the journal; any other plan is a
|
|
154
|
+
* conflict, so a resumed setup can never replace what it recorded.
|
|
155
|
+
*/
|
|
156
|
+
export declare function recordNativeCustodyActivation(paths: NativePoolPaths, plan: NativeCustodyActivationPlan, hooks?: JournalHooks): Promise<NativeMigrationJournal>;
|
|
157
|
+
/** Advance a recorded activation one phase; never backwards or across a phase. */
|
|
158
|
+
export declare function advanceNativeCustodyActivation(paths: NativePoolPaths, expected: NativeCustodyActivationPhase, next: NativeCustodyActivationPhase, hooks?: JournalHooks): Promise<NativeMigrationJournal>;
|
|
159
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { NativePoolPaths } from './pool-paths.ts';
|
|
2
|
+
export interface NativeLocalPoolBinding {
|
|
3
|
+
readonly kind: 'local';
|
|
4
|
+
readonly storageId: string;
|
|
5
|
+
readonly rowId: string;
|
|
6
|
+
readonly credentialEpoch: number;
|
|
7
|
+
readonly identity?: string;
|
|
8
|
+
}
|
|
9
|
+
interface BindingSourceRow {
|
|
10
|
+
id: string;
|
|
11
|
+
identity?: string;
|
|
12
|
+
credentialEpoch?: number;
|
|
13
|
+
candidate: boolean;
|
|
14
|
+
stamp?: string;
|
|
15
|
+
invalid?: string;
|
|
16
|
+
torn?: boolean;
|
|
17
|
+
unbound?: boolean;
|
|
18
|
+
}
|
|
19
|
+
export declare class NativePoolBindingError extends Error {
|
|
20
|
+
constructor();
|
|
21
|
+
}
|
|
22
|
+
export declare function isNativeLocalPoolBinding(value: unknown): value is NativeLocalPoolBinding;
|
|
23
|
+
/** Capture the selected row before asynchronous work, never the newest primary afterward. */
|
|
24
|
+
export declare function captureNativeLocalPoolBinding(paths: NativePoolPaths, row: BindingSourceRow): NativeLocalPoolBinding;
|
|
25
|
+
/**
|
|
26
|
+
* A response still belongs to an account disabled after dispatch. Matching
|
|
27
|
+
* this snapshot does not make that account eligible for a new request.
|
|
28
|
+
*/
|
|
29
|
+
export declare function nativeLocalPoolBindingMatches(binding: NativeLocalPoolBinding, paths: NativePoolPaths, row: BindingSourceRow): boolean;
|
|
30
|
+
/** Unknown row ids and proven account identities occupy different refresh namespaces. */
|
|
31
|
+
export declare function nativeLocalRefreshJobKey(binding: NativeLocalPoolBinding): string;
|
|
32
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export interface NativePoolPaths {
|
|
2
|
+
legacyConfig: string;
|
|
3
|
+
legacyState: string;
|
|
4
|
+
config: string;
|
|
5
|
+
state: string;
|
|
6
|
+
runtime: string;
|
|
7
|
+
journal: string;
|
|
8
|
+
roster: string;
|
|
9
|
+
storageId: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Resolve existing parent aliases and nonexistent leaves without creating files.
|
|
13
|
+
* This can follow a leaf symlink, so it does not establish configured-leaf safety.
|
|
14
|
+
* Source capture and recheck must retain the configured path for the lstat guard.
|
|
15
|
+
*/
|
|
16
|
+
export declare function canonicalPath(path: string): Promise<string>;
|
|
17
|
+
/**
|
|
18
|
+
* Separate runtime authority from import inputs so a stale legacy writer cannot
|
|
19
|
+
* rewrite a stamped credential. Both independently configured paths matter.
|
|
20
|
+
*/
|
|
21
|
+
export declare function resolveNativePoolPaths(legacyConfig?: string, legacyState?: string): Promise<NativePoolPaths>;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { type OpenPoolStoreOptions } from "./internal-types/store/index.js";
|
|
2
|
+
import { type NativeLockEvent } from './native-lock-observer.ts';
|
|
3
|
+
import type { NativePoolPaths } from './pool-paths.ts';
|
|
4
|
+
export type { NativeLockEvent } from './native-lock-observer.ts';
|
|
5
|
+
interface NativeQuotaCodec {
|
|
6
|
+
validate(value: unknown): boolean;
|
|
7
|
+
merge(stored: unknown | undefined, observation: unknown): unknown;
|
|
8
|
+
}
|
|
9
|
+
export type NativePoolStorePaths = Pick<NativePoolPaths, 'config' | 'state'> & {
|
|
10
|
+
legacySeedConfig?: string;
|
|
11
|
+
};
|
|
12
|
+
export interface NativePoolStoreOptions extends Pick<OpenPoolStoreOptions, 'now' | 'onStep' | 'hold' | 'logger' | 'onLockStep'> {
|
|
13
|
+
paths: NativePoolStorePaths;
|
|
14
|
+
quota: NativeQuotaCodec;
|
|
15
|
+
onLockEvent?: (event: NativeLockEvent) => void;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* These config/state locks also fence local account metadata against concurrent
|
|
19
|
+
* credential changes. Legacy sidecar writers use different files and locks.
|
|
20
|
+
*/
|
|
21
|
+
export declare function nativePoolStoreLocks(paths: NativePoolStorePaths): readonly [{
|
|
22
|
+
readonly path: string;
|
|
23
|
+
readonly name: 'pool-config';
|
|
24
|
+
}, {
|
|
25
|
+
readonly path: string;
|
|
26
|
+
readonly name: 'pool-state';
|
|
27
|
+
}];
|
|
28
|
+
/**
|
|
29
|
+
* Storage machinery only. Callers must separately establish local migration
|
|
30
|
+
* authority or vault enrollment authority before using these files.
|
|
31
|
+
*/
|
|
32
|
+
export declare function createNativePoolStore(options: NativePoolStoreOptions): import("./internal-types/store/index.js").PoolStore;
|
package/dist/prime.d.ts
CHANGED
|
@@ -30,7 +30,7 @@ export type PrimeAccountStatus = {
|
|
|
30
30
|
label: string;
|
|
31
31
|
nextDueAt?: number;
|
|
32
32
|
lastPrimedAt?: number | null;
|
|
33
|
-
lastResult?: 'ok' | 'error';
|
|
33
|
+
lastResult?: 'ok' | 'error' | 'skipped';
|
|
34
34
|
usage?: import('./accounts.ts').PrimeUsageCounters;
|
|
35
35
|
estimatedCostUsd?: number;
|
|
36
36
|
};
|
|
@@ -47,7 +47,7 @@ export type PrimeSendResult = {
|
|
|
47
47
|
status?: number;
|
|
48
48
|
ms?: number;
|
|
49
49
|
error: string;
|
|
50
|
-
reason?: 'token-refresh' | 'send';
|
|
50
|
+
reason?: 'token-refresh' | 'vault-cold' | 'send';
|
|
51
51
|
};
|
|
52
52
|
/**
|
|
53
53
|
* Pure command parser — accepts `''` / `on` / `off` and treats anything else
|
|
@@ -72,7 +72,7 @@ export declare function buildPrimeAccountStatuses(storage: AccountStorage | null
|
|
|
72
72
|
now?: number;
|
|
73
73
|
transient?: ReadonlyMap<string, {
|
|
74
74
|
lastPrimedAt?: number;
|
|
75
|
-
lastResult?: 'ok' | 'error';
|
|
75
|
+
lastResult?: 'ok' | 'error' | 'skipped';
|
|
76
76
|
}>;
|
|
77
77
|
}): PrimeAccountStatus[];
|
|
78
78
|
/**
|
|
@@ -182,9 +182,17 @@ export type PrimeManagerOptions = {
|
|
|
182
182
|
now?: () => number;
|
|
183
183
|
markerDir?: string;
|
|
184
184
|
storagePath: string;
|
|
185
|
+
setIntervalImpl?: typeof globalThis.setInterval;
|
|
186
|
+
clearIntervalImpl?: typeof globalThis.clearInterval;
|
|
187
|
+
setTimeoutImpl?: typeof globalThis.setTimeout;
|
|
188
|
+
clearTimeoutImpl?: typeof globalThis.clearTimeout;
|
|
185
189
|
};
|
|
186
190
|
export declare class PrimeManager {
|
|
187
191
|
private timer;
|
|
192
|
+
private readonly setIntervalImpl;
|
|
193
|
+
private readonly clearIntervalImpl;
|
|
194
|
+
private readonly setTimeoutImpl;
|
|
195
|
+
private readonly clearTimeoutImpl;
|
|
188
196
|
private postFireRefreshTimers;
|
|
189
197
|
private lastForcedCheck;
|
|
190
198
|
private stopped;
|