@cortexkit/anthropic-auth-core 2.11.3 → 2.12.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/dist/holder-registry.d.ts +2 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.js +2785 -1150
- package/dist/internal-types/fs/canonical-file-path.d.ts +17 -0
- package/dist/internal-types/fs/index.d.ts +1 -0
- package/dist/internal-types/settings/edit.d.ts +1 -0
- package/dist/internal-types/settings/handle.d.ts +2 -1
- package/dist/internal-types/settings/index.d.ts +1 -0
- package/dist/internal-types/settings/update.d.ts +14 -0
- package/dist/layout-fence.d.ts +7 -1
- package/dist/native-account-runtime.d.ts +2 -0
- package/dist/native-migration-source.d.ts +5 -0
- package/dist/native-migration.d.ts +15 -0
- package/dist/native-runtime-settings.d.ts +50 -8
- package/dist/native-settings-write.d.ts +18 -1
- package/dist/native-setup-settings.d.ts +39 -0
- package/dist/settings-authority.d.ts +8 -0
- package/dist/settings-definition.d.ts +11 -0
- package/dist/settings-host-import.d.ts +39 -0
- package/dist/settings-mode.d.ts +37 -1
- package/dist/settings-move-fence.d.ts +6 -1
- package/dist/settings-move-run.d.ts +63 -2
- package/dist/settings-move-source.d.ts +2 -0
- package/dist/settings-move-sources.d.ts +34 -1
- package/dist/settings-protection-copy.d.ts +7 -1
- package/dist/settings-record.d.ts +7 -1
- package/dist/settings-service.d.ts +147 -4
- package/dist/settings-start.d.ts +97 -0
- package/package.json +2 -2
|
@@ -11,15 +11,40 @@ export type SettingsProtectionRung = 0 | 1 | 2 | 3;
|
|
|
11
11
|
export declare class SettingsRecreationRefusal extends Error {
|
|
12
12
|
constructor(file: string);
|
|
13
13
|
}
|
|
14
|
+
/**
|
|
15
|
+
* A write into an existing settings file by a host that has not adopted it
|
|
16
|
+
* (its import check has not passed). The file may protect less than the
|
|
17
|
+
* host's legacy store, so the write is refused under the writer lock; the
|
|
18
|
+
* caller reports the same refusal as while the host is held by that check.
|
|
19
|
+
*/
|
|
20
|
+
export declare class SettingsAdoptionRefusal extends Error {
|
|
21
|
+
readonly file: string;
|
|
22
|
+
constructor(file: string);
|
|
23
|
+
}
|
|
14
24
|
export interface SettingsUpdateOptions {
|
|
15
25
|
/** Only menu writes and setup with a <target>.moved marker and no user file may create it. */
|
|
16
26
|
createMissing?: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* This write is the host's import into the file (the import check, or
|
|
29
|
+
* setup filling the file from the legacy store), which by design runs
|
|
30
|
+
* before the host adopts the file. Every other write by a host lease that
|
|
31
|
+
* has not adopted the file is refused when the file exists.
|
|
32
|
+
*/
|
|
33
|
+
importing?: boolean;
|
|
17
34
|
}
|
|
18
35
|
export interface SettingsProtectionRecovery {
|
|
19
|
-
/** Return only this host's complete set; missing
|
|
36
|
+
/** Return only this host's complete set; a missing copy returns undefined, an unreadable or corrupt one throws. */
|
|
20
37
|
readAppliedCopy?: (host: SettingsHost) => Promise<SettingsProtectionValues | undefined>;
|
|
21
38
|
/** Read this runtime's local or vault settings store, as selected by its current enrollment mode. */
|
|
22
39
|
readLegacyProtection?: (host: SettingsHost) => Promise<SettingsProtectionValues | undefined>;
|
|
40
|
+
/**
|
|
41
|
+
* Read the other host's own legacy store through that host's current custody
|
|
42
|
+
* (see `readPeerLegacySettingsProtection`). Recreating a missing file uses it
|
|
43
|
+
* to learn the other host's protection. Without it, that host's set is
|
|
44
|
+
* unknown and recreation is refused: an absent reader never means the
|
|
45
|
+
* other host has nothing to protect.
|
|
46
|
+
*/
|
|
47
|
+
readPeerLegacyProtection?: (host: SettingsHost) => Promise<SettingsProtectionValues | undefined>;
|
|
23
48
|
}
|
|
24
49
|
export interface SettingsContextValues {
|
|
25
50
|
readonly noModel: SettingsValues;
|
|
@@ -69,8 +94,18 @@ export interface SettingsService {
|
|
|
69
94
|
status(): SettingsFileStatus;
|
|
70
95
|
/** Effects are awaited in publication order; unsubscribe before disposing a host. */
|
|
71
96
|
watch(listener: SettingsChangeListener): () => void;
|
|
97
|
+
/** Every underlying user-file watch callback, even if resolved values stay identical. */
|
|
98
|
+
onFileEvent?(listener: () => void): () => void;
|
|
72
99
|
refresh(): Promise<void>;
|
|
73
|
-
update(edits:
|
|
100
|
+
update(edits: SettingsUpdate, host: SettingsHost, options?: SettingsUpdateOptions): Promise<UpdateResult>;
|
|
101
|
+
/**
|
|
102
|
+
* Called once the acting host has passed its import check for this file
|
|
103
|
+
* (after its `adopted` option turned true): the lease records the
|
|
104
|
+
* generation it holds as that host's last-good set at once, before the
|
|
105
|
+
* applied copy is saved, so a failed copy write leaves no stale window.
|
|
106
|
+
* Does nothing while `adopted` still returns false.
|
|
107
|
+
*/
|
|
108
|
+
noteAdoption?(): void;
|
|
74
109
|
dispose(): Promise<void>;
|
|
75
110
|
}
|
|
76
111
|
export type SettingsChangeListener = (generation: SettingsGeneration) => void | Promise<void>;
|
|
@@ -82,6 +117,18 @@ export interface SettingsServiceOptions {
|
|
|
82
117
|
separateInstall?: boolean;
|
|
83
118
|
lockTimeoutMs?: number;
|
|
84
119
|
protection?: SettingsProtectionRecovery;
|
|
120
|
+
/**
|
|
121
|
+
* False while the acting host has not passed its import check for this
|
|
122
|
+
* file (see `importSettingsHostStore`), so it does not use the file yet.
|
|
123
|
+
* Until then the file's values are never this host's last-good protection:
|
|
124
|
+
* a file it has not imported may protect less than its legacy store, so a
|
|
125
|
+
* missing or unusable file recovers this host's set from the ladder (its
|
|
126
|
+
* applied copy, then its legacy store, then the strictest set). Nor does
|
|
127
|
+
* the lease save an applied copy from it, and a write into the existing
|
|
128
|
+
* file is refused unless it is the host's import. Omitted means the host
|
|
129
|
+
* has not adopted the file: every production caller passes it explicitly.
|
|
130
|
+
*/
|
|
131
|
+
adopted?: () => boolean;
|
|
85
132
|
/** Dependency seams for deterministic file-race and no-I/O tests. */
|
|
86
133
|
dependencies?: {
|
|
87
134
|
open?: (options: OpenSettingsOptions) => CoreSettingsHandle;
|
|
@@ -91,9 +138,105 @@ export interface SettingsServiceOptions {
|
|
|
91
138
|
schedule?: (callback: () => void, delayMs: number) => () => void;
|
|
92
139
|
};
|
|
93
140
|
}
|
|
94
|
-
/**
|
|
95
|
-
export declare function
|
|
141
|
+
/** The levels at which a parsed settings document sets each key; values and their validity remain common-auth's responsibility. */
|
|
142
|
+
export declare function settingsFileLevels(raw: Record<string, unknown>): SettingsFileLevels;
|
|
143
|
+
/** One host's whole protection set, as the recreation planner receives it. */
|
|
144
|
+
export interface SettingsRecreationSide {
|
|
145
|
+
host: SettingsHost;
|
|
146
|
+
values: SettingsProtectionValues;
|
|
147
|
+
}
|
|
148
|
+
/** A shared-settings edit, including an explicit default or host level. */
|
|
149
|
+
export type SettingsLevelEdit = SettingsEdit;
|
|
150
|
+
/**
|
|
151
|
+
* The protection edits for a recreated file, as a pure function of both
|
|
152
|
+
* hosts' whole sets, so each host resolves exactly its own set from the new
|
|
153
|
+
* file. A key both hosts agree on is one plain value. A key they disagree on
|
|
154
|
+
* is the writer's value at the default level, then the other host's value at
|
|
155
|
+
* that host's level. Floors are one list whose entries keep each host's tag;
|
|
156
|
+
* an entry becomes `both` only for a vault account whose floors are
|
|
157
|
+
* identical for the two hosts.
|
|
158
|
+
*/
|
|
159
|
+
export declare function planSettingsRecreation(writer: SettingsRecreationSide, peer: SettingsRecreationSide): {
|
|
160
|
+
edits: SettingsLevelEdit[];
|
|
161
|
+
/**
|
|
162
|
+
* True when the other host resolves any protection value other than its
|
|
163
|
+
* account floors differently. Floors never set it: the one floor list
|
|
164
|
+
* carries each host's entries under that host's tag.
|
|
165
|
+
*/
|
|
166
|
+
peerDiffers: boolean;
|
|
167
|
+
};
|
|
168
|
+
/**
|
|
169
|
+
* The protection edits for a recreation whose other host has no set of its
|
|
170
|
+
* own: the writer's values as plain values, its own account floors tagged
|
|
171
|
+
* with it, and its vault floors as `both`, since vault routes are shared.
|
|
172
|
+
*/
|
|
173
|
+
export declare function settingsRecreationForWriter(values: SettingsProtectionValues, host: SettingsHost): SettingsLevelEdit[];
|
|
174
|
+
/**
|
|
175
|
+
* The floor list a recreation writes when the other host applies the same
|
|
176
|
+
* floors as `host`.
|
|
177
|
+
*/
|
|
178
|
+
export declare function settingsRecreationFloors(values: SettingsProtectionValues, host: SettingsHost): SettingsProtectionValues['killswitch_account_floors'];
|
|
179
|
+
/** One host's protection set and where it came from, for planning a recreation. */
|
|
180
|
+
export interface SettingsRecreationInput {
|
|
181
|
+
host: SettingsHost;
|
|
182
|
+
values: SettingsProtectionValues;
|
|
183
|
+
rung: SettingsProtectionRung;
|
|
184
|
+
/** A source exists but could not be read, so the set is unknown. */
|
|
185
|
+
unreadable?: boolean;
|
|
186
|
+
/**
|
|
187
|
+
* The host has no set at all: no applied copy and no legacy store (it never
|
|
188
|
+
* ran). Distinct from rung 3 without a reader, which is an unknown set.
|
|
189
|
+
*/
|
|
190
|
+
none?: boolean;
|
|
191
|
+
}
|
|
192
|
+
export type SettingsRecreationRefusalReason = 'own-unknown' | 'peer-unknown';
|
|
193
|
+
/**
|
|
194
|
+
* What a menu write or setup that finds the file missing does, as a pure
|
|
195
|
+
* function of both hosts' sets: the protection edits it carries, or why it
|
|
196
|
+
* is refused. Only a peer known to have no set (it never ran) takes the
|
|
197
|
+
* writer's. A peer whose set is unknown refuses the write, whether or not
|
|
198
|
+
* the hosts are running, so its protection is never replaced by the
|
|
199
|
+
* writer's. Otherwise both known sets are carried together, with host levels
|
|
200
|
+
* preserving any differing values.
|
|
201
|
+
*/
|
|
202
|
+
export declare function planSettingsFileRecreation(writer: SettingsRecreationInput, peer: SettingsRecreationInput): {
|
|
203
|
+
edits: SettingsLevelEdit[];
|
|
204
|
+
} | {
|
|
205
|
+
refused: SettingsRecreationRefusalReason;
|
|
206
|
+
};
|
|
207
|
+
/** The state of the user file a menu write found, as common-auth's planned update reports it. */
|
|
208
|
+
export type SettingsWriteState = {
|
|
209
|
+
status: 'missing';
|
|
210
|
+
} | {
|
|
211
|
+
status: 'ready';
|
|
212
|
+
document: unknown;
|
|
213
|
+
};
|
|
214
|
+
/** Menu edits run under the writer lock; a missing file also supplies its protection carry. */
|
|
215
|
+
export type SettingsUpdatePlan = (current: SettingsWriteState, carry?: readonly SettingsEdit[]) => readonly SettingsEdit[];
|
|
216
|
+
export type SettingsUpdate = readonly SettingsEdit[] | SettingsUpdatePlan;
|
|
217
|
+
/**
|
|
218
|
+
* The edits for one menu write, as a pure function of the file it finds:
|
|
219
|
+
* protection is carried only into a missing file, and an existing file keeps
|
|
220
|
+
* its own. `carry` throws when recreation must be refused.
|
|
221
|
+
*/
|
|
222
|
+
export declare function planSettingsMenuWrite(current: SettingsWriteState, edits: readonly SettingsEdit[], carry: () => readonly SettingsEdit[]): readonly SettingsEdit[];
|
|
223
|
+
/**
|
|
224
|
+
* Why `host` can't use the file, in plain words for a refused menu write, or
|
|
225
|
+
* undefined when it can (or the file is missing). It names at most a
|
|
226
|
+
* declared setting, never a value: file contents may hold secrets.
|
|
227
|
+
*/
|
|
228
|
+
export declare function settingsFileProblem(generation: SettingsGeneration, host: SettingsHost): string | undefined;
|
|
96
229
|
export declare function mostRestrictiveSettingsProtection(): SettingsProtectionValues;
|
|
230
|
+
/**
|
|
231
|
+
* Rungs 1-3 of the protection ladder, which need no open settings handle:
|
|
232
|
+
* the applied copy (by default read from disk only for the acting host),
|
|
233
|
+
* then the host's legacy store, then the strictest set. A source that can't
|
|
234
|
+
* be read is skipped whole; keys are never mixed across sources.
|
|
235
|
+
*/
|
|
236
|
+
export declare function recoverSettingsProtection(file: string, host: SettingsHost, recovery?: SettingsProtectionRecovery, actingHost?: SettingsHost): Promise<{
|
|
237
|
+
values: SettingsProtectionValues;
|
|
238
|
+
rung: 1 | 2 | 3;
|
|
239
|
+
}>;
|
|
97
240
|
/** One lease per plugin instance; no handle, reads or watch for a separate install. */
|
|
98
241
|
export declare function openSettingsService(options: SettingsServiceOptions): Promise<SettingsService | undefined>;
|
|
99
242
|
export {};
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { type SettingsMode } from './settings-mode.ts';
|
|
2
|
+
import { runSettingsMoveAtStartup, type SettingsMoveStartupOptions } from './settings-move-run.ts';
|
|
3
|
+
import { type SettingsProtectionRecovery, type SettingsProtectionValues, type SettingsService, type SettingsServiceOptions } from './settings-service.ts';
|
|
4
|
+
export interface StartSettingsOptions extends SettingsMoveStartupOptions {
|
|
5
|
+
/** This host's recovery sources, shared by the service and the fallback. */
|
|
6
|
+
protection?: SettingsProtectionRecovery;
|
|
7
|
+
lockTimeoutMs?: number;
|
|
8
|
+
/** Test seams for the move and the service open. */
|
|
9
|
+
start?: {
|
|
10
|
+
move?: typeof runSettingsMoveAtStartup;
|
|
11
|
+
open?: (options: SettingsServiceOptions) => Promise<SettingsService | undefined>;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* The settings file is in charge, but its service could not open. Protection
|
|
16
|
+
* comes from the ladder without an open handle (this host's applied copy,
|
|
17
|
+
* then its legacy store, then the strictest set); every other setting stays
|
|
18
|
+
* as the legacy store holds it.
|
|
19
|
+
*/
|
|
20
|
+
export interface SettingsProtectionFallback {
|
|
21
|
+
readonly file: string;
|
|
22
|
+
readonly rung: 1 | 2 | 3;
|
|
23
|
+
readonly values: SettingsProtectionValues;
|
|
24
|
+
/**
|
|
25
|
+
* Off the request path: open the service again and run this host's import
|
|
26
|
+
* check; undefined while either still fails.
|
|
27
|
+
*/
|
|
28
|
+
reopen(): Promise<SettingsService | undefined>;
|
|
29
|
+
/**
|
|
30
|
+
* True when the service the last `reopen` returned was adopted for a
|
|
31
|
+
* missing file whose import is still owed: the runtime must pass the
|
|
32
|
+
* import check again before it uses a file that appears.
|
|
33
|
+
*/
|
|
34
|
+
importPending?(): boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Present with `resolveAuthority`: once it finds legacy mode, open the
|
|
37
|
+
* service only to notice a later move, without adopting the file.
|
|
38
|
+
*/
|
|
39
|
+
reopenLegacy?(): Promise<SettingsService | undefined>;
|
|
40
|
+
/**
|
|
41
|
+
* Present only when startup could not tell which source is in charge and
|
|
42
|
+
* fell back to the file as a precaution. Off the request path, asks again;
|
|
43
|
+
* throws while the check still fails. A result other than 'user-file'
|
|
44
|
+
* means no move happened and the fallback should be dropped.
|
|
45
|
+
*/
|
|
46
|
+
resolveAuthority?(): Promise<SettingsMode>;
|
|
47
|
+
}
|
|
48
|
+
export interface StartedSettings {
|
|
49
|
+
mode: SettingsMode;
|
|
50
|
+
/**
|
|
51
|
+
* The settings file; empty only when no path could be resolved, which the
|
|
52
|
+
* shared-runtime key treats as "no settings file".
|
|
53
|
+
*/
|
|
54
|
+
file: string;
|
|
55
|
+
/** Open in user-file mode, and in legacy mode to notice another host's move. */
|
|
56
|
+
service?: SettingsService;
|
|
57
|
+
/** Set instead of `service` when the file is in charge but could not open. */
|
|
58
|
+
fallback?: SettingsProtectionFallback;
|
|
59
|
+
/**
|
|
60
|
+
* Set in legacy mode when the service could not open, or the enrollment or
|
|
61
|
+
* migration preflight refused: open it again off the request path, so a
|
|
62
|
+
* move another host publishes later is noticed.
|
|
63
|
+
*/
|
|
64
|
+
reopen?: SettingsReopen;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Opens the settings service again off the request path; undefined while it
|
|
68
|
+
* still cannot. `retryDelaysMs` asks the runtime to try sooner than its
|
|
69
|
+
* normal interval, one delay per attempt, before falling back to it.
|
|
70
|
+
*/
|
|
71
|
+
export interface SettingsReopen {
|
|
72
|
+
(): Promise<SettingsService | undefined>;
|
|
73
|
+
readonly retryDelaysMs?: readonly number[];
|
|
74
|
+
/**
|
|
75
|
+
* True once a reopen found that this host is a separate install: it never
|
|
76
|
+
* opens the shared settings file, and the runtime treats it as separate.
|
|
77
|
+
*/
|
|
78
|
+
readonly separate?: () => boolean;
|
|
79
|
+
}
|
|
80
|
+
/** Tests only: let the next failed start log its one warning again. */
|
|
81
|
+
export declare function __resetSettingsStartWarningForTest(): void;
|
|
82
|
+
/**
|
|
83
|
+
* The one settings startup every host calls; it never throws. It runs the
|
|
84
|
+
* move, then opens the service. When either fails, a file that is (or may
|
|
85
|
+
* be) in charge gets the protection fallback, never plain legacy values,
|
|
86
|
+
* which may predate protection the user tightened in the file. Only a check
|
|
87
|
+
* that proves no move happened (no file, no marker) returns legacy mode, or
|
|
88
|
+
* a refused enrollment or migration preflight, while requests are refused.
|
|
89
|
+
*
|
|
90
|
+
* Every service it opens carries the import check (see
|
|
91
|
+
* `setSettingsAdoptionCheck`): a runtime that starts in legacy mode adopts
|
|
92
|
+
* a file that appears later only after that check passes. Until this host
|
|
93
|
+
* has adopted the file, its applied protection copy is not written from the
|
|
94
|
+
* file, so a file whose import is still owed never becomes the copy that
|
|
95
|
+
* recovery trusts.
|
|
96
|
+
*/
|
|
97
|
+
export declare function startSettings(options: StartSettingsOptions): Promise<StartedSettings>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cortexkit/anthropic-auth-core",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.12.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"prepublishOnly": "bun run build"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@cortexkit/common-auth": "0.
|
|
34
|
+
"@cortexkit/common-auth": "0.49.2"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"@cortexkit/claustrum-client": "0.18.0",
|