@cortexkit/anthropic-auth-core 2.16.0 → 2.16.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/index.js +66 -32
- package/dist/native-transient-account.d.ts +7 -4
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -721,6 +721,9 @@ function loadBackend() {
|
|
|
721
721
|
});
|
|
722
722
|
return backend;
|
|
723
723
|
}
|
|
724
|
+
function isSharingIoError(detail) {
|
|
725
|
+
return detail?.reason === "io-error" && (detail.win32Code === 32 || detail.win32Code === 303);
|
|
726
|
+
}
|
|
724
727
|
|
|
725
728
|
class PrivateFileError extends Error {
|
|
726
729
|
path;
|
|
@@ -736,7 +739,7 @@ class PrivateFileError extends Error {
|
|
|
736
739
|
orphanPath;
|
|
737
740
|
constructor(path, stage, cause) {
|
|
738
741
|
const detail = cause;
|
|
739
|
-
super(detail?.code === "ERR_PRIVATE_FILES_UNAVAILABLE" ? `Private file refused at ${stage}: ${path}. The Windows native addon of @cortexkit/private-files could not be loaded, so owner-only access cannot be enforced and nothing was read or written. Reinstall the plugin so the private-files Windows prebuild for this architecture is present; Windows has no safe fallback to permission bits.` : `Private file refused at ${stage}: ${path} (${detail?.reason ?? detail?.code ?? "io-error"}). Keep this file in a folder that only you, the system or administrators can change, such as a folder in your home directory. If other users could read the file before, sign in again to replace the credentials it held. On Windows the file must also be on a local drive that keeps Windows file permissions, such as NTFS.`, { cause });
|
|
742
|
+
super(detail?.code === "ERR_PRIVATE_FILES_UNAVAILABLE" ? `Private file refused at ${stage}: ${path}. The Windows native addon of @cortexkit/private-files could not be loaded, so owner-only access cannot be enforced and nothing was read or written. Reinstall the plugin so the private-files Windows prebuild for this architecture is present; Windows has no safe fallback to permission bits.` : isSharingIoError(detail) ? `Private file busy at ${stage}: ${path}. Another process was replacing or deleting this file at the same moment (Windows error ${detail.win32Code}).` : `Private file refused at ${stage}: ${path} (${detail?.reason ?? detail?.code ?? "io-error"}). Keep this file in a folder that only you, the system or administrators can change, such as a folder in your home directory. If other users could read the file before, sign in again to replace the credentials it held. On Windows the file must also be on a local drive that keeps Windows file permissions, such as NTFS.`, { cause });
|
|
740
743
|
this.path = path;
|
|
741
744
|
this.stage = stage;
|
|
742
745
|
this.name = "PrivateFileError";
|
|
@@ -746,7 +749,7 @@ class PrivateFileError extends Error {
|
|
|
746
749
|
}
|
|
747
750
|
}
|
|
748
751
|
function isWindowsSharingViolation(error) {
|
|
749
|
-
return windowsPrivateFiles && error instanceof PrivateFileError &&
|
|
752
|
+
return windowsPrivateFiles && error instanceof PrivateFileError && isSharingIoError(error);
|
|
750
753
|
}
|
|
751
754
|
async function privateOperation(path, stage, operation) {
|
|
752
755
|
try {
|
|
@@ -21999,7 +22002,7 @@ async function callFailureHook(operation, hook, rowId, error, logger3) {
|
|
|
21999
22002
|
}
|
|
22000
22003
|
|
|
22001
22004
|
// ../../node_modules/@cortexkit/common-auth/dist/store/mutate.js
|
|
22002
|
-
import { setTimeout as
|
|
22005
|
+
import { setTimeout as delay4 } from "node:timers/promises";
|
|
22003
22006
|
|
|
22004
22007
|
// ../../node_modules/@cortexkit/common-auth/dist/store/reserved.js
|
|
22005
22008
|
function assertNotReserved(operation, id, reservation) {
|
|
@@ -22679,13 +22682,19 @@ function loadRows(config, state, codec, options = {}) {
|
|
|
22679
22682
|
}
|
|
22680
22683
|
|
|
22681
22684
|
// ../../node_modules/@cortexkit/common-auth/dist/store/mutate.js
|
|
22685
|
+
var sharingRetryDelays = [5, 10, 20, 40, 80, 160, 320, 400];
|
|
22682
22686
|
async function readText(path2) {
|
|
22683
|
-
|
|
22684
|
-
|
|
22685
|
-
|
|
22686
|
-
|
|
22687
|
-
|
|
22688
|
-
|
|
22687
|
+
for (let attempt = 0;; attempt++) {
|
|
22688
|
+
try {
|
|
22689
|
+
return await readPrivateText(path2, windowsPrivateFiles);
|
|
22690
|
+
} catch (error) {
|
|
22691
|
+
if (error.code === "ENOENT")
|
|
22692
|
+
return;
|
|
22693
|
+
const wait = sharingRetryDelays[attempt];
|
|
22694
|
+
if (wait === undefined || !isWindowsSharingViolation(error))
|
|
22695
|
+
throw error;
|
|
22696
|
+
await delay4(wait);
|
|
22697
|
+
}
|
|
22689
22698
|
}
|
|
22690
22699
|
}
|
|
22691
22700
|
function parseFile(text) {
|
|
@@ -22702,12 +22711,21 @@ async function readPoolConfig(path2) {
|
|
|
22702
22711
|
}
|
|
22703
22712
|
async function readPool(ctx) {
|
|
22704
22713
|
for (let attempt = 0;attempt < 3; attempt++) {
|
|
22705
|
-
|
|
22706
|
-
|
|
22707
|
-
|
|
22714
|
+
let configText;
|
|
22715
|
+
let stateText;
|
|
22716
|
+
let checkedConfigText;
|
|
22717
|
+
try {
|
|
22718
|
+
configText = await readText(ctx.configPath);
|
|
22719
|
+
stateText = await readText(ctx.statePath);
|
|
22720
|
+
checkedConfigText = await readText(ctx.configPath);
|
|
22721
|
+
} catch (error) {
|
|
22722
|
+
if (isWindowsSharingViolation(error))
|
|
22723
|
+
break;
|
|
22724
|
+
throw error;
|
|
22725
|
+
}
|
|
22708
22726
|
if (configText !== checkedConfigText) {
|
|
22709
22727
|
if (attempt < 2)
|
|
22710
|
-
await
|
|
22728
|
+
await delay4(2 + Math.floor(Math.random() * 4));
|
|
22711
22729
|
continue;
|
|
22712
22730
|
}
|
|
22713
22731
|
const config = classifyConfig(parseFile(configText));
|
|
@@ -24668,11 +24686,11 @@ class PoolQuotaWriter {
|
|
|
24668
24686
|
overlay(rows) {
|
|
24669
24687
|
return rows.map((row) => this.overlayRow(row));
|
|
24670
24688
|
}
|
|
24671
|
-
schedule(
|
|
24689
|
+
schedule(delay5) {
|
|
24672
24690
|
if (this.running || this.timer || !this.pending.size || this.stopped)
|
|
24673
24691
|
return;
|
|
24674
24692
|
const remaining = this.closed ? 0 : (this.committedAt ?? -Infinity) + QUOTA_COMMIT_INTERVAL_MS - this.clock.now();
|
|
24675
|
-
this.timer = this.clock.schedule(Math.max(
|
|
24693
|
+
this.timer = this.clock.schedule(Math.max(delay5, remaining), () => {
|
|
24676
24694
|
this.timer = undefined;
|
|
24677
24695
|
return this.flush();
|
|
24678
24696
|
});
|
|
@@ -24770,8 +24788,8 @@ class PoolQuotaWriter {
|
|
|
24770
24788
|
this.running = undefined;
|
|
24771
24789
|
for (const wake of this.wake)
|
|
24772
24790
|
wake();
|
|
24773
|
-
const
|
|
24774
|
-
this.schedule(
|
|
24791
|
+
const delay5 = this.failures ? Math.min(5000, 100 * 2 ** Math.min(this.failures, 6)) * (0.5 + Math.random()) : COALESCE_MS2;
|
|
24792
|
+
this.schedule(delay5);
|
|
24775
24793
|
}
|
|
24776
24794
|
})();
|
|
24777
24795
|
return this.running;
|
|
@@ -25983,11 +26001,11 @@ async function renameWithWindowsSharingRetry(from, to, options = {}, beforeRetry
|
|
|
25983
26001
|
throw error;
|
|
25984
26002
|
original = error;
|
|
25985
26003
|
}
|
|
25986
|
-
for (const
|
|
26004
|
+
for (const delay5 of [10, 20, 40, 80, 100]) {
|
|
25987
26005
|
const remaining = 500 - (now() - start);
|
|
25988
26006
|
if (remaining <= 0)
|
|
25989
26007
|
break;
|
|
25990
|
-
await sleep(Math.min(
|
|
26008
|
+
await sleep(Math.min(delay5, remaining));
|
|
25991
26009
|
if (now() - start >= 500)
|
|
25992
26010
|
break;
|
|
25993
26011
|
if (await beforeRetry?.() === "skip")
|
|
@@ -32258,8 +32276,8 @@ class CacheKeepStore {
|
|
|
32258
32276
|
this.pending.set(entry2.id, entry2);
|
|
32259
32277
|
if (this.timers.has(entry2.id))
|
|
32260
32278
|
return;
|
|
32261
|
-
const
|
|
32262
|
-
const timer = (this.options.setTimeoutImpl ?? setTimeout)(() => this.flush(entry2.id),
|
|
32279
|
+
const delay5 = Math.max(250, (this.lastWrite.get(entry2.id) ?? 0) + 5000 - (this.options.now?.() ?? Date.now()));
|
|
32280
|
+
const timer = (this.options.setTimeoutImpl ?? setTimeout)(() => this.flush(entry2.id), delay5);
|
|
32263
32281
|
timer.unref?.();
|
|
32264
32282
|
this.timers.set(entry2.id, timer);
|
|
32265
32283
|
}
|
|
@@ -35091,13 +35109,14 @@ var TRANSIENT_ACCOUNT_MESSAGE = "Anthropic account update in progress; retry the
|
|
|
35091
35109
|
var transientAccountErrors = new WeakSet;
|
|
35092
35110
|
|
|
35093
35111
|
class NativeTransientAccountError extends Error {
|
|
35094
|
-
constructor() {
|
|
35112
|
+
constructor(operation) {
|
|
35095
35113
|
super(TRANSIENT_ACCOUNT_MESSAGE);
|
|
35096
35114
|
const fixed = {
|
|
35097
35115
|
name: "NativeTransientAccountError",
|
|
35098
35116
|
message: TRANSIENT_ACCOUNT_MESSAGE,
|
|
35099
35117
|
code: "ECONNRESET",
|
|
35100
|
-
syscall: "native-account-update"
|
|
35118
|
+
syscall: "native-account-update",
|
|
35119
|
+
...operation === "pool-read" && { poolRead: true }
|
|
35101
35120
|
};
|
|
35102
35121
|
for (const [key, value] of Object.entries(fixed))
|
|
35103
35122
|
Object.defineProperty(this, key, {
|
|
@@ -35112,6 +35131,21 @@ class NativeTransientAccountError extends Error {
|
|
|
35112
35131
|
function isNativeTransientAccountError(value) {
|
|
35113
35132
|
return typeof value === "object" && value !== null && transientAccountErrors.has(value);
|
|
35114
35133
|
}
|
|
35134
|
+
async function readNativePool(read) {
|
|
35135
|
+
const result = await readNativePoolSettings(read);
|
|
35136
|
+
if (result.status === "error" && result.kind === "snapshot-contended" && result.retryable)
|
|
35137
|
+
throw new NativeTransientAccountError("pool-read");
|
|
35138
|
+
return result;
|
|
35139
|
+
}
|
|
35140
|
+
async function readNativePoolSettings(read) {
|
|
35141
|
+
try {
|
|
35142
|
+
return await read;
|
|
35143
|
+
} catch (error) {
|
|
35144
|
+
if (error instanceof PrivateFileError && error.stage === "read" && error.reason === "io-error" && (error.win32Code === 32 || error.win32Code === 303))
|
|
35145
|
+
throw new NativeTransientAccountError("pool-read");
|
|
35146
|
+
throw error;
|
|
35147
|
+
}
|
|
35148
|
+
}
|
|
35115
35149
|
var NATIVE_POOL_WRITE_JOIN_BUDGET_MS = 2000;
|
|
35116
35150
|
async function joinNativePoolWrite(paths, signals, check, onLockEvent) {
|
|
35117
35151
|
const observer = nativeLockObserver(onLockEvent);
|
|
@@ -35323,7 +35357,7 @@ function createNativeRefreshCoordinator(options) {
|
|
|
35323
35357
|
const bootstrap = options.resolveIdentity ?? resolveClaudeCodeAccountIdentity;
|
|
35324
35358
|
const onLockEvent = nativeLockObserver(options.onLockEvent);
|
|
35325
35359
|
async function rowFor(binding2) {
|
|
35326
|
-
const read = await store.read();
|
|
35360
|
+
const read = await readNativePool(store.read());
|
|
35327
35361
|
return read.status === "ready" ? read.rows.find((row) => row.id === binding2.rowId) : undefined;
|
|
35328
35362
|
}
|
|
35329
35363
|
async function readPolicy(subject) {
|
|
@@ -41500,7 +41534,7 @@ function createNativeVaultRuntime(options) {
|
|
|
41500
41534
|
});
|
|
41501
41535
|
}
|
|
41502
41536
|
async function rowFor(roster, routeId) {
|
|
41503
|
-
const settings = await store.readSettings();
|
|
41537
|
+
const settings = await readNativePoolSettings(store.readSettings());
|
|
41504
41538
|
if (settings.status !== "ready")
|
|
41505
41539
|
throw new NativeCustodyError("invalid-state");
|
|
41506
41540
|
const pin = nativeVaultPrimaryPin(settings.settings);
|
|
@@ -42435,7 +42469,7 @@ function buildNativeAccountRuntime(options, env, runtimeSettings) {
|
|
|
42435
42469
|
};
|
|
42436
42470
|
}
|
|
42437
42471
|
async function poolRow(id2) {
|
|
42438
|
-
const read = await store.read();
|
|
42472
|
+
const read = await readNativePool(store.read());
|
|
42439
42473
|
if (read.status !== "ready")
|
|
42440
42474
|
throw new NativeRuntimeError("publication-refused");
|
|
42441
42475
|
return read.rows.find((row) => row.id === id2);
|
|
@@ -42443,7 +42477,7 @@ function buildNativeAccountRuntime(options, env, runtimeSettings) {
|
|
|
42443
42477
|
async function physicalId(id2) {
|
|
42444
42478
|
if (id2 !== "main")
|
|
42445
42479
|
return id2;
|
|
42446
|
-
const settings = await store.readSettings();
|
|
42480
|
+
const settings = await readNativePoolSettings(store.readSettings());
|
|
42447
42481
|
if (settings.status !== "ready" || typeof settings.settings.mainAccountId !== "string")
|
|
42448
42482
|
throw new NativeCustodyError("route-unavailable");
|
|
42449
42483
|
return settings.settings.mainAccountId;
|
|
@@ -42609,8 +42643,8 @@ function buildNativeAccountRuntime(options, env, runtimeSettings) {
|
|
|
42609
42643
|
const selectedPaths = mode === "claustrum" ? vaultPaths : paths2;
|
|
42610
42644
|
const selectedStore = mode === "claustrum" ? vaultStore : store;
|
|
42611
42645
|
const [read, settings, metadata2] = await Promise.all([
|
|
42612
|
-
selectedStore.read(),
|
|
42613
|
-
selectedStore.readSettings(),
|
|
42646
|
+
readNativePool(selectedStore.read()),
|
|
42647
|
+
readNativePoolSettings(selectedStore.readSettings()),
|
|
42614
42648
|
readNativeRuntime(selectedPaths.runtime, selectedPaths.storageId)
|
|
42615
42649
|
]);
|
|
42616
42650
|
if (read.status !== "ready" || settings.status !== "ready")
|
|
@@ -42710,7 +42744,7 @@ function buildNativeAccountRuntime(options, env, runtimeSettings) {
|
|
|
42710
42744
|
for (let attempt = 0;attempt < 4; attempt++) {
|
|
42711
42745
|
if (attempt)
|
|
42712
42746
|
await new Promise((resolve23) => setTimeout(resolve23, 10));
|
|
42713
|
-
const settings = await readSettings();
|
|
42747
|
+
const settings = await readNativePoolSettings(readSettings());
|
|
42714
42748
|
if (settings.status !== "ready")
|
|
42715
42749
|
throw new NativeRuntimeError("publication-refused");
|
|
42716
42750
|
if (location !== "default") {
|
|
@@ -47481,12 +47515,12 @@ async function acquirePiLock(authPath, onCompromised, onRenew) {
|
|
|
47481
47515
|
if (!released && lastUpdate + RENEWAL_STALE < Date.now())
|
|
47482
47516
|
compromise();
|
|
47483
47517
|
}
|
|
47484
|
-
function schedule2(
|
|
47518
|
+
function schedule2(delay5 = UPDATE) {
|
|
47485
47519
|
if (released)
|
|
47486
47520
|
return;
|
|
47487
47521
|
timer = setTimeout(() => {
|
|
47488
47522
|
update();
|
|
47489
|
-
},
|
|
47523
|
+
}, delay5);
|
|
47490
47524
|
timer.unref();
|
|
47491
47525
|
}
|
|
47492
47526
|
function retry(error) {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import { type PoolLoad } from "./internal-types/store/index.js";
|
|
1
2
|
import { type NativeLockEvent } from './native-lock-observer.ts';
|
|
2
3
|
import { type NativePoolStorePaths } from './pool-store.ts';
|
|
3
4
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* The shared write or refresh may still finish after the caller stops waiting.
|
|
5
|
+
* An account update prevented a request from reading or authorizing the account
|
|
6
|
+
* within its short wait budget. The shared write or refresh may still finish.
|
|
7
7
|
*
|
|
8
8
|
* The request should be retried. `code: 'ECONNRESET'` is how this package
|
|
9
9
|
* marks an error retryable for its hosts. A host must surface it rather than
|
|
@@ -13,10 +13,13 @@ import { type NativePoolStorePaths } from './pool-store.ts';
|
|
|
13
13
|
export declare class NativeTransientAccountError extends Error {
|
|
14
14
|
readonly code: 'ECONNRESET';
|
|
15
15
|
readonly syscall: 'native-account-update';
|
|
16
|
-
|
|
16
|
+
readonly poolRead?: true;
|
|
17
|
+
constructor(operation?: 'pool-read');
|
|
17
18
|
}
|
|
18
19
|
/** True only for an error Core itself constructed as NativeTransientAccountError. */
|
|
19
20
|
export declare function isNativeTransientAccountError(value: unknown): value is NativeTransientAccountError;
|
|
21
|
+
export declare function readNativePool(read: Promise<PoolLoad>): Promise<PoolLoad>;
|
|
22
|
+
export declare function readNativePoolSettings<T>(read: Promise<T>): Promise<T>;
|
|
20
23
|
/**
|
|
21
24
|
* Wait until no writer holds the pool's store locks, then let them go.
|
|
22
25
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cortexkit/anthropic-auth-core",
|
|
3
|
-
"version": "2.16.
|
|
3
|
+
"version": "2.16.1",
|
|
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.54.
|
|
34
|
+
"@cortexkit/common-auth": "0.54.1"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"@cortexkit/claustrum-client": "0.18.0",
|