@cortexkit/anthropic-auth-core 2.3.0 → 2.4.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 +2 -0
- package/dist/cachekeep.d.ts +6 -0
- package/dist/holder-registry.d.ts +159 -0
- package/dist/index.d.ts +4 -1
- package/dist/index.js +1387 -546
- package/dist/internal-types/claustrum/enrollment.d.ts +9 -0
- package/dist/internal-types/setup/flags.d.ts +50 -0
- package/dist/internal-types/setup/index.d.ts +1 -0
- package/dist/internal-types/setup/types.d.ts +7 -1
- package/dist/native-account-runtime.d.ts +7 -0
- package/dist/native-vault-paths.d.ts +11 -2
- package/dist/pool-paths.d.ts +8 -1
- package/dist/relocation-guard.d.ts +48 -0
- package/dist/state-layout-paths.d.ts +193 -0
- package/dist/sticky-routing.d.ts +8 -0
- package/package.json +2 -2
package/dist/accounts.d.ts
CHANGED
|
@@ -311,6 +311,8 @@ export type AccountStateSaveScope = {
|
|
|
311
311
|
accounts?: true | string[];
|
|
312
312
|
};
|
|
313
313
|
export declare const FALLBACK_BACKGROUND_TICK_MS = 60000;
|
|
314
|
+
/** OpenCode's config folder, as OpenCode itself resolves it. */
|
|
315
|
+
export declare function getOpenCodeConfigDir(env?: NodeJS.ProcessEnv, home?: string): string;
|
|
314
316
|
export declare function getAccountStoragePath(): string;
|
|
315
317
|
export declare function getAccountStatePath(configPath?: string): string;
|
|
316
318
|
export declare function createEmptyStorage(): AccountStorage;
|
package/dist/cachekeep.d.ts
CHANGED
|
@@ -149,6 +149,12 @@ export declare class CacheKeepManager {
|
|
|
149
149
|
oauthAccountId?: string;
|
|
150
150
|
} | undefined;
|
|
151
151
|
trackedCount(): number;
|
|
152
|
+
/**
|
|
153
|
+
* Drop targets whose cache has already expired, without sending or
|
|
154
|
+
* publishing anything. Returns the earliest expiry among the targets that
|
|
155
|
+
* remain, or undefined when none remain.
|
|
156
|
+
*/
|
|
157
|
+
dropExpiredTargets(now?: number): number | undefined;
|
|
152
158
|
private publishTrackedSessions;
|
|
153
159
|
private totalBodyBytes;
|
|
154
160
|
private evictOldestTarget;
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { type NativeLockEvent } from './native-lock-observer.ts';
|
|
2
|
+
import type { NativePoolPaths } from './pool-paths.ts';
|
|
3
|
+
import { RelocatedError } from './relocation-guard.ts';
|
|
4
|
+
/** The file, beside a dataset's files, that lists the processes using them. */
|
|
5
|
+
export declare const HOLDER_FILE_NAME = "anthropic-auth-holders.json";
|
|
6
|
+
/** Lock name on the holder file: lock file `<holder file>.holders.lock`. */
|
|
7
|
+
export declare const HOLDER_LOCK_NAME = "holders";
|
|
8
|
+
/**
|
|
9
|
+
* How long a registrant waits for the holder lock. A process moving or
|
|
10
|
+
* restoring state holds it for the whole transition; an ordinary registrant
|
|
11
|
+
* holds it for one small read and write.
|
|
12
|
+
*/
|
|
13
|
+
export declare const HOLDER_LOCK_TIMEOUT_MS = 120000;
|
|
14
|
+
/** At most one retry a minute after a failed ordinary registration. */
|
|
15
|
+
export declare const HOLDER_RETRY_INTERVAL_MS = 60000;
|
|
16
|
+
/**
|
|
17
|
+
* Where a registered process keeps the dataset: `legacy` beside OpenCode's
|
|
18
|
+
* account files; `explicit` beside files named by a path override; `pi`
|
|
19
|
+
* beside Pi's files. `state-home` is written by later releases only, which
|
|
20
|
+
* keep moved state under the CortexKit state folder.
|
|
21
|
+
*/
|
|
22
|
+
export type HolderKind = 'legacy' | 'explicit' | 'pi' | 'state-home';
|
|
23
|
+
/** Which kind of process registered. */
|
|
24
|
+
export type HolderRole = 'opencode1' | 'opencode2' | 'cli' | 'setup' | 'pi';
|
|
25
|
+
/** One process's use of one dataset, as recorded in a holder file. */
|
|
26
|
+
export interface HolderEntry {
|
|
27
|
+
readonly pid: number;
|
|
28
|
+
/**
|
|
29
|
+
* A value the OS fixes for the life of the process (Linux boot id and start
|
|
30
|
+
* ticks; macOS start time), or null where none is read (Windows). It tells a
|
|
31
|
+
* reused pid from the process that registered.
|
|
32
|
+
*/
|
|
33
|
+
readonly incarnation: string | null;
|
|
34
|
+
/** Distinguishes copies of this code loaded into the same process. */
|
|
35
|
+
readonly instance: string;
|
|
36
|
+
readonly role: HolderRole;
|
|
37
|
+
readonly release: string;
|
|
38
|
+
readonly kind: HolderKind;
|
|
39
|
+
/** The config folder's identity for `legacy`, otherwise null. */
|
|
40
|
+
readonly identity: string | null;
|
|
41
|
+
/** Canonical paths of every dataset file the process uses. */
|
|
42
|
+
readonly files: readonly string[];
|
|
43
|
+
readonly registeredAt: number;
|
|
44
|
+
}
|
|
45
|
+
/** Added to pid artifacts written by this version and later, so a newer version can tell them from those of older versions. */
|
|
46
|
+
export interface WriterStamp {
|
|
47
|
+
readonly protocol: 1;
|
|
48
|
+
readonly release: string;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* This code's release, read once from the package.json one folder above the
|
|
52
|
+
* running module (the same in a source checkout and in each published
|
|
53
|
+
* package, whose versions are kept equal). `unknown` when it can't be read.
|
|
54
|
+
*/
|
|
55
|
+
export declare function anthropicAuthRelease(): string;
|
|
56
|
+
/**
|
|
57
|
+
* The `writer` field this version adds to RPC port files and CacheKeep records.
|
|
58
|
+
* Older readers copy only the fields they know, so they ignore it.
|
|
59
|
+
*/
|
|
60
|
+
export declare function writerStamp(): WriterStamp;
|
|
61
|
+
/**
|
|
62
|
+
* Every file of a dataset that a later release may move: local pool state,
|
|
63
|
+
* local runtime, journal, local custody roster, vault store state, vault
|
|
64
|
+
* runtime, vault roster and vault routing, sorted.
|
|
65
|
+
*/
|
|
66
|
+
export declare function nativeHolderDatasetFiles(paths: NativePoolPaths): string[];
|
|
67
|
+
/**
|
|
68
|
+
* A directory a later release may move state into: its path ends in
|
|
69
|
+
* `cortexkit/anthropic-auth/opencode` or `cortexkit/anthropic-auth/opencode-`
|
|
70
|
+
* followed by 16 hex digits, under any state root.
|
|
71
|
+
*/
|
|
72
|
+
export declare function isDestinationShapedDirectory(dir: string): boolean;
|
|
73
|
+
/** OpenCode's dataset is `explicit` when a path override names its files. */
|
|
74
|
+
export declare function openCodeHolderKind(env?: NodeJS.ProcessEnv): 'legacy' | 'explicit';
|
|
75
|
+
export type HolderRegistrationErrorCode = 'lock-timeout' | 'managed-folder' | 'malformed' | 'unavailable';
|
|
76
|
+
/**
|
|
77
|
+
* A registration that must succeed did not, or a path override points into
|
|
78
|
+
* a folder anthropic-auth manages. The message is fixed; `directory` and the
|
|
79
|
+
* cause carry the details for logs and diagnostics.
|
|
80
|
+
*/
|
|
81
|
+
export declare class HolderRegistrationError extends Error {
|
|
82
|
+
readonly code: HolderRegistrationErrorCode;
|
|
83
|
+
readonly directory: string;
|
|
84
|
+
constructor(code: HolderRegistrationErrorCode, directory: string, cause?: unknown);
|
|
85
|
+
}
|
|
86
|
+
/** Every fixed message `HolderRegistrationError` can carry. */
|
|
87
|
+
export declare const HOLDER_REGISTRATION_ERROR_MESSAGES: readonly string[];
|
|
88
|
+
/**
|
|
89
|
+
* The relocation or registration refusal behind `error`, if any. Pool and
|
|
90
|
+
* roster operations wrap what their hooks throw in their own error, which
|
|
91
|
+
* keeps the original as its `cause`, so the chain is followed a few levels.
|
|
92
|
+
*/
|
|
93
|
+
export declare function stateRefusalCause(error: unknown): RelocatedError | HolderRegistrationError | undefined;
|
|
94
|
+
/** How liveness is read; tests replace it. */
|
|
95
|
+
export interface HolderLiveness {
|
|
96
|
+
pidAlive(pid: number): boolean;
|
|
97
|
+
/** Undefined or null when it can't be read. */
|
|
98
|
+
incarnation(pid: number): Promise<string | null>;
|
|
99
|
+
}
|
|
100
|
+
/** The OS's fixed per-process value for `pid`, or null when none is read. */
|
|
101
|
+
export declare function processIncarnation(pid: number): Promise<string | null>;
|
|
102
|
+
/**
|
|
103
|
+
* Whether an entry's process may still be running. A dead pid is stale. A
|
|
104
|
+
* live pid is stale only when the entry recorded an incarnation and the OS
|
|
105
|
+
* now reports a different one; an unreadable incarnation counts as alive.
|
|
106
|
+
* So pid reuse can keep a stale entry, but never clears a live one.
|
|
107
|
+
*/
|
|
108
|
+
export declare function holderEntryIsLive(entry: Pick<HolderEntry, 'pid' | 'incarnation'>, liveness?: HolderLiveness): Promise<boolean>;
|
|
109
|
+
export interface RegisterNativePoolHolderOptions {
|
|
110
|
+
paths: NativePoolPaths;
|
|
111
|
+
role: HolderRole;
|
|
112
|
+
/** `legacy` or `explicit` for OpenCode (see `openCodeHolderKind`); `pi` for Pi. */
|
|
113
|
+
kind: Exclude<HolderKind, 'state-home'>;
|
|
114
|
+
/** Observes the holder locks, as other native lock observers do. */
|
|
115
|
+
onLockEvent?: (event: NativeLockEvent) => void;
|
|
116
|
+
/** Tests shorten these; production uses the defaults. */
|
|
117
|
+
lockTimeoutMs?: number;
|
|
118
|
+
retryIntervalMs?: number;
|
|
119
|
+
liveness?: HolderLiveness;
|
|
120
|
+
now?: () => number;
|
|
121
|
+
}
|
|
122
|
+
/** The outcome of a registration that did not refuse. */
|
|
123
|
+
export interface NativeHolderRegistration {
|
|
124
|
+
/**
|
|
125
|
+
* `registered` once every holder file lists this process. `pending` while
|
|
126
|
+
* an ordinary registration keeps failing; it is retried in the background
|
|
127
|
+
* at most once a minute until it succeeds or `close()` is called.
|
|
128
|
+
*/
|
|
129
|
+
readonly status: 'registered' | 'pending';
|
|
130
|
+
/** Resolves once a pending registration has been retried successfully. */
|
|
131
|
+
readonly settled: Promise<void>;
|
|
132
|
+
/** Stop retrying. Published entries stay; later writers prune them once the pid is dead. */
|
|
133
|
+
close(): void;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Record, beside a dataset's files, that this process uses them, before the
|
|
137
|
+
* process's first pool I/O for that dataset. A later release reads these
|
|
138
|
+
* records and never moves a dataset that a live process still uses.
|
|
139
|
+
*
|
|
140
|
+
* Refuses, whatever the outcome of the write, when either legacy runtime file
|
|
141
|
+
* is a relocation tombstone (`RelocatedError`), or when an `explicit` or `pi`
|
|
142
|
+
* dataset lies in a folder anthropic-auth manages (`HolderRegistrationError`
|
|
143
|
+
* with `managed-folder`).
|
|
144
|
+
*
|
|
145
|
+
* A failed write is handled by kind:
|
|
146
|
+
* - An `explicit` or `pi` dataset with a file in a destination-shaped folder
|
|
147
|
+
* (see `isDestinationShapedDirectory`) must be registered there, so the
|
|
148
|
+
* call throws `HolderRegistrationError` and the process must not serve it.
|
|
149
|
+
* - Every other dataset is served as before: the failure is logged once at
|
|
150
|
+
* WARN and retried in the background at most once a minute. Such a
|
|
151
|
+
* process also records itself in a folder only once one of its dataset
|
|
152
|
+
* files exists there; until then the same retry checks again.
|
|
153
|
+
*
|
|
154
|
+
* Call it holding no data lock: a mover holds the holder lock while it waits
|
|
155
|
+
* for data locks.
|
|
156
|
+
*/
|
|
157
|
+
export declare function registerNativePoolHolder(options: RegisterNativePoolHolderOptions): Promise<NativeHolderRegistration>;
|
|
158
|
+
/** Forget what this process has published; tests only. */
|
|
159
|
+
export declare function resetNativeHolderRegistryForTests(): void;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export type { CommandResult, CommandRunner, HostDetection, OpenCodeGeneration, ProcessFence, SetupCallbackContext, SetupDetection, SetupEnvironment, SetupFileSystem, SetupHost, SetupIO, SetupPlugin, SetupResult, } from "./internal-types/setup/index.js";
|
|
2
|
-
export { assertHostsStopped, createProcessFence, runSetup, setupEnrollment, } from "./internal-types/setup/index.js";
|
|
2
|
+
export { assertHostsStopped, createProcessFence, runSetup, setupEnrollment, setupUsage, } from "./internal-types/setup/index.js";
|
|
3
3
|
export * from './accounts.ts';
|
|
4
4
|
export * from './auth.ts';
|
|
5
5
|
export * from './cache1h.ts';
|
|
@@ -14,6 +14,7 @@ export * from './constants.ts';
|
|
|
14
14
|
export * from './custom-headers.ts';
|
|
15
15
|
export * from './dump.ts';
|
|
16
16
|
export * from './fast.ts';
|
|
17
|
+
export * from './holder-registry.ts';
|
|
17
18
|
export * from './json.ts';
|
|
18
19
|
export * from './killswitch.ts';
|
|
19
20
|
export * from './logger.ts';
|
|
@@ -81,12 +82,14 @@ export * from './quota-headers.ts';
|
|
|
81
82
|
export * from './quota-manager.ts';
|
|
82
83
|
export * from './quotas.ts';
|
|
83
84
|
export * from './relay.ts';
|
|
85
|
+
export * from './relocation-guard.ts';
|
|
84
86
|
export * from './request-gzip.ts';
|
|
85
87
|
export * from './request-history.ts';
|
|
86
88
|
export * from './routing.ts';
|
|
87
89
|
export type { SseEvent, SseFramer, SseFramerOptions } from './sse.ts';
|
|
88
90
|
export { createSseFramer, DEFAULT_SSE_MAX_FRAME_BYTES, decodeSseFrame, isSseCandidateFrame, isTerminatedSseFrame, parseSseFrame, SseFrameTooLargeError, } from './sse.ts';
|
|
89
91
|
export * from './start.ts';
|
|
92
|
+
export * from './state-layout-paths.ts';
|
|
90
93
|
export * from './sticky-routing.ts';
|
|
91
94
|
export * from './thinking-binding.ts';
|
|
92
95
|
export * from './turn-end-note.ts';
|