@cortexkit/opencode-antigravity-auth 3.0.28 → 3.0.30
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/cli.js +689 -183
- package/dist/cli.js.map +4 -4
- package/dist/cli.meta.json +131 -68
- package/dist/index.js +844 -199
- package/dist/index.js.map +4 -4
- package/dist/index.meta.json +173 -76
- package/dist/server.js +855 -213
- package/dist/server.js.map +4 -4
- package/dist/server.meta.json +1 -1
- package/dist/src/cli.d.ts +1 -0
- package/dist/src/cli.d.ts.map +1 -1
- package/dist/src/cli.js +22 -2
- package/dist/src/cli.js.map +1 -1
- package/dist/src/common-auth-embedded/claustrum/consumer.d.ts +12 -0
- package/dist/src/common-auth-embedded/claustrum/consumer.js +36 -0
- package/dist/src/common-auth-embedded/claustrum/custody.d.ts +16 -4
- package/dist/src/common-auth-embedded/claustrum/custody.js +74 -9
- package/dist/src/common-auth-embedded/claustrum/hub.d.ts +3 -2
- package/dist/src/common-auth-embedded/claustrum/hub.js +8 -0
- package/dist/src/common-auth-embedded/claustrum/index.d.ts +1 -0
- package/dist/src/common-auth-embedded/claustrum/roster.d.ts +2 -0
- package/dist/src/common-auth-embedded/claustrum/roster.js +2 -0
- package/dist/src/common-auth-embedded/claustrum/usage.d.ts +41 -0
- package/dist/src/common-auth-embedded/claustrum/usage.js +145 -0
- package/dist/src/common-auth-embedded/commands/builtins.d.ts +5 -0
- package/dist/src/common-auth-embedded/commands/builtins.js +38 -0
- package/dist/src/common-auth-embedded/fs/private-files.d.ts +5 -0
- package/dist/src/common-auth-embedded/fs/private-files.js +7 -0
- package/dist/src/common-auth-embedded/fs/refresh-file-lock.js +142 -47
- package/dist/src/common-auth-embedded/fs/with-lock.js +2 -5
- package/dist/src/common-auth-embedded/limits/activity.d.ts +26 -0
- package/dist/src/common-auth-embedded/limits/axes.d.ts +63 -0
- package/dist/src/common-auth-embedded/limits/decide.d.ts +141 -0
- package/dist/src/common-auth-embedded/limits/duration.d.ts +8 -0
- package/dist/src/common-auth-embedded/limits/families.d.ts +57 -0
- package/dist/src/common-auth-embedded/limits/marker.d.ts +64 -0
- package/dist/src/common-auth-embedded/limits/request-history.d.ts +77 -0
- package/dist/src/common-auth-embedded/limits/scope.d.ts +12 -0
- package/dist/src/common-auth-embedded/limits/signal.d.ts +41 -0
- package/dist/src/common-auth-embedded/limits/terminal.d.ts +52 -0
- package/dist/src/common-auth-embedded/limits/wake.d.ts +21 -0
- package/dist/src/common-auth-embedded/limits/wording.d.ts +25 -0
- package/dist/src/common-auth-embedded/opencode2/index.d.ts +1 -1
- package/dist/src/common-auth-embedded/opencode2/install.d.ts +2 -2
- package/dist/src/common-auth-embedded/opencode2/install.js +161 -18
- package/dist/src/common-auth-embedded/opencode2/types.d.ts +95 -9
- package/dist/src/common-auth-embedded/routing/admission.d.ts +7 -2
- package/dist/src/common-auth-embedded/routing/admission.js +17 -7
- package/dist/src/common-auth-embedded/routing-accessor/handle.js +10 -0
- package/dist/src/common-auth-embedded/routing-accessor/index.d.ts +13 -3
- package/dist/src/common-auth-embedded/routing-accessor/index.js +11 -10
- package/dist/src/common-auth-embedded/rpc/port-file.d.ts +12 -3
- package/dist/src/common-auth-embedded/rpc/port-file.js +46 -4
- package/dist/src/common-auth-embedded/source-output.json +254 -118
- package/dist/src/common-auth-embedded/store/attribution.js +3 -2
- package/dist/src/common-auth-embedded/store/errors.d.ts +1 -1
- package/dist/src/common-auth-embedded/store/hooks.d.ts +5 -1
- package/dist/src/common-auth-embedded/store/hooks.js +20 -5
- package/dist/src/common-auth-embedded/store/index.d.ts +1 -0
- package/dist/src/common-auth-embedded/store/limits-namespace.d.ts +7 -0
- package/dist/src/common-auth-embedded/store/limits-namespace.js +34 -0
- package/dist/src/common-auth-embedded/store/pool.d.ts +10 -1
- package/dist/src/common-auth-embedded/store/pool.js +2 -0
- package/dist/src/common-auth-embedded/store/provider-state.js +5 -5
- package/dist/src/common-auth-embedded/store/refresh.js +1 -1
- package/dist/src/common-auth-embedded/store/schema.js +9 -4
- package/dist/src/common-auth-embedded/store/settings.d.ts +2 -0
- package/dist/src/common-auth-embedded/store/settings.js +11 -4
- package/dist/src/plugin/__fixtures__/verified-store.js +2 -2
- package/dist/src/plugin/shared/request-services.d.ts +14 -18
- package/dist/src/plugin/shared/request-services.d.ts.map +1 -1
- package/dist/src/plugin/shared/request-services.js +127 -7
- package/dist/src/plugin/shared/request-services.js.map +1 -1
- package/dist/src/runtime-layout.d.ts +9 -2
- package/dist/src/runtime-layout.d.ts.map +1 -1
- package/dist/src/runtime-layout.js +8 -8
- package/dist/src/runtime-layout.js.map +1 -1
- package/dist/src/setup.d.ts.map +1 -1
- package/dist/src/setup.js +29 -40
- package/dist/src/setup.js.map +1 -1
- package/dist/tui-build-map.json +9 -9
- package/dist/tui-ga-build-map.json +1 -1
- package/dist/types/src/cli.d.ts +1 -0
- package/dist/types/src/cli.d.ts.map +1 -1
- package/dist/types/src/common-auth-embedded/claustrum/consumer.d.ts +12 -0
- package/dist/types/src/common-auth-embedded/claustrum/custody.d.ts +16 -4
- package/dist/types/src/common-auth-embedded/claustrum/hub.d.ts +3 -2
- package/dist/types/src/common-auth-embedded/claustrum/index.d.ts +1 -0
- package/dist/types/src/common-auth-embedded/claustrum/roster.d.ts +2 -0
- package/dist/types/src/common-auth-embedded/claustrum/usage.d.ts +41 -0
- package/dist/types/src/common-auth-embedded/commands/builtins.d.ts +5 -0
- package/dist/types/src/common-auth-embedded/limits/activity.d.ts +26 -0
- package/dist/types/src/common-auth-embedded/limits/axes.d.ts +63 -0
- package/dist/types/src/common-auth-embedded/limits/decide.d.ts +141 -0
- package/dist/types/src/common-auth-embedded/limits/duration.d.ts +8 -0
- package/dist/types/src/common-auth-embedded/limits/families.d.ts +57 -0
- package/dist/types/src/common-auth-embedded/limits/marker.d.ts +64 -0
- package/dist/types/src/common-auth-embedded/limits/request-history.d.ts +77 -0
- package/dist/types/src/common-auth-embedded/limits/scope.d.ts +12 -0
- package/dist/types/src/common-auth-embedded/limits/signal.d.ts +41 -0
- package/dist/types/src/common-auth-embedded/limits/terminal.d.ts +52 -0
- package/dist/types/src/common-auth-embedded/limits/wake.d.ts +21 -0
- package/dist/types/src/common-auth-embedded/limits/wording.d.ts +25 -0
- package/dist/types/src/common-auth-embedded/opencode2/index.d.ts +1 -1
- package/dist/types/src/common-auth-embedded/opencode2/install.d.ts +2 -2
- package/dist/types/src/common-auth-embedded/opencode2/types.d.ts +95 -9
- package/dist/types/src/common-auth-embedded/routing/admission.d.ts +7 -2
- package/dist/types/src/common-auth-embedded/routing-accessor/index.d.ts +13 -3
- package/dist/types/src/common-auth-embedded/store/errors.d.ts +1 -1
- package/dist/types/src/common-auth-embedded/store/hooks.d.ts +5 -1
- package/dist/types/src/common-auth-embedded/store/index.d.ts +1 -0
- package/dist/types/src/common-auth-embedded/store/limits-namespace.d.ts +7 -0
- package/dist/types/src/common-auth-embedded/store/pool.d.ts +10 -1
- package/dist/types/src/common-auth-embedded/store/settings.d.ts +2 -0
- package/dist/types/src/plugin/shared/request-services.d.ts +14 -18
- package/dist/types/src/plugin/shared/request-services.d.ts.map +1 -1
- package/dist/types/src/runtime-layout.d.ts +9 -2
- package/dist/types/src/runtime-layout.d.ts.map +1 -1
- package/dist/types/src/setup.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/common-auth-embedded/claustrum/consumer.d.ts +12 -0
- package/src/common-auth-embedded/claustrum/consumer.js +36 -0
- package/src/common-auth-embedded/claustrum/custody.d.ts +16 -4
- package/src/common-auth-embedded/claustrum/custody.js +74 -9
- package/src/common-auth-embedded/claustrum/hub.d.ts +3 -2
- package/src/common-auth-embedded/claustrum/hub.js +8 -0
- package/src/common-auth-embedded/claustrum/index.d.ts +1 -0
- package/src/common-auth-embedded/claustrum/roster.d.ts +2 -0
- package/src/common-auth-embedded/claustrum/roster.js +2 -0
- package/src/common-auth-embedded/claustrum/usage.d.ts +41 -0
- package/src/common-auth-embedded/claustrum/usage.js +145 -0
- package/src/common-auth-embedded/commands/builtins.d.ts +5 -0
- package/src/common-auth-embedded/commands/builtins.js +38 -0
- package/src/common-auth-embedded/fs/private-files.d.ts +5 -0
- package/src/common-auth-embedded/fs/private-files.js +7 -0
- package/src/common-auth-embedded/fs/refresh-file-lock.js +142 -47
- package/src/common-auth-embedded/fs/with-lock.js +2 -5
- package/src/common-auth-embedded/limits/activity.d.ts +26 -0
- package/src/common-auth-embedded/limits/axes.d.ts +63 -0
- package/src/common-auth-embedded/limits/decide.d.ts +141 -0
- package/src/common-auth-embedded/limits/duration.d.ts +8 -0
- package/src/common-auth-embedded/limits/families.d.ts +57 -0
- package/src/common-auth-embedded/limits/marker.d.ts +64 -0
- package/src/common-auth-embedded/limits/request-history.d.ts +77 -0
- package/src/common-auth-embedded/limits/scope.d.ts +12 -0
- package/src/common-auth-embedded/limits/signal.d.ts +41 -0
- package/src/common-auth-embedded/limits/terminal.d.ts +52 -0
- package/src/common-auth-embedded/limits/wake.d.ts +21 -0
- package/src/common-auth-embedded/limits/wording.d.ts +25 -0
- package/src/common-auth-embedded/opencode2/index.d.ts +1 -1
- package/src/common-auth-embedded/opencode2/install.d.ts +2 -2
- package/src/common-auth-embedded/opencode2/install.js +161 -18
- package/src/common-auth-embedded/opencode2/types.d.ts +95 -9
- package/src/common-auth-embedded/routing/admission.d.ts +7 -2
- package/src/common-auth-embedded/routing/admission.js +17 -7
- package/src/common-auth-embedded/routing-accessor/handle.js +10 -0
- package/src/common-auth-embedded/routing-accessor/index.d.ts +13 -3
- package/src/common-auth-embedded/routing-accessor/index.js +11 -10
- package/src/common-auth-embedded/rpc/port-file.d.ts +12 -3
- package/src/common-auth-embedded/rpc/port-file.js +46 -4
- package/src/common-auth-embedded/source-output.json +254 -118
- package/src/common-auth-embedded/store/attribution.js +3 -2
- package/src/common-auth-embedded/store/errors.d.ts +1 -1
- package/src/common-auth-embedded/store/hooks.d.ts +5 -1
- package/src/common-auth-embedded/store/hooks.js +20 -5
- package/src/common-auth-embedded/store/index.d.ts +1 -0
- package/src/common-auth-embedded/store/limits-namespace.d.ts +7 -0
- package/src/common-auth-embedded/store/limits-namespace.js +34 -0
- package/src/common-auth-embedded/store/pool.d.ts +10 -1
- package/src/common-auth-embedded/store/pool.js +2 -0
- package/src/common-auth-embedded/store/provider-state.js +5 -5
- package/src/common-auth-embedded/store/refresh.js +1 -1
- package/src/common-auth-embedded/store/schema.js +9 -4
- package/src/common-auth-embedded/store/settings.d.ts +2 -0
- package/src/common-auth-embedded/store/settings.js +11 -4
- package/src/tui-compiled/common-auth-embedded/fs/private-files.js +7 -0
- package/src/tui-compiled/common-auth-embedded/rpc/port-file.js +46 -4
- package/src/tui-raw/common-auth-embedded/fs/private-files.js +7 -0
- package/src/tui-raw/common-auth-embedded/rpc/port-file.js +46 -4
package/dist/server.js
CHANGED
|
@@ -636,6 +636,9 @@ function loadBackend() {
|
|
|
636
636
|
});
|
|
637
637
|
return backend;
|
|
638
638
|
}
|
|
639
|
+
function isWindowsSharingViolation(error) {
|
|
640
|
+
return windowsPrivateFiles && error instanceof PrivateFileError && error.reason === "io-error" && (error.win32Code === 32 || error.win32Code === 303);
|
|
641
|
+
}
|
|
639
642
|
async function privateOperation(path5, stage, operation) {
|
|
640
643
|
try {
|
|
641
644
|
return await operation();
|
|
@@ -6632,6 +6635,15 @@ function resolveQuotaGroup(family, model, cachedQuota) {
|
|
|
6632
6635
|
}
|
|
6633
6636
|
return family === "claude" ? "non-gemini" : "gemini";
|
|
6634
6637
|
}
|
|
6638
|
+
function reportsArgon(account) {
|
|
6639
|
+
return account.cachedQuotaUpdatedAt !== void 0 && account.cachedQuota?.["gemini-argon"] !== void 0;
|
|
6640
|
+
}
|
|
6641
|
+
function preferArgonAccounts(accounts, model) {
|
|
6642
|
+
if (!model || getQuotaGroupForModel(model, true) !== "gemini-argon")
|
|
6643
|
+
return accounts;
|
|
6644
|
+
const reporting = accounts.filter(reportsArgon);
|
|
6645
|
+
return reporting.length > 0 ? reporting : accounts;
|
|
6646
|
+
}
|
|
6635
6647
|
function isOverSoftQuotaThreshold(account, family, thresholdPercent, cacheTtlMs, now, model) {
|
|
6636
6648
|
if (thresholdPercent >= 100)
|
|
6637
6649
|
return false;
|
|
@@ -7106,7 +7118,10 @@ var init_account_selector = __esm({
|
|
|
7106
7118
|
};
|
|
7107
7119
|
});
|
|
7108
7120
|
const currentIndex = this.getActiveIndex(family, identity3);
|
|
7109
|
-
const
|
|
7121
|
+
const preferred2 = preferArgonAccounts(eligibleAccounts, model);
|
|
7122
|
+
const preferredIndexes = new Set(preferred2.map((row) => row.index));
|
|
7123
|
+
const select4 = (candidates) => selectHybridAccount(candidates, tokenTracker, currentIndex, 50, this.now);
|
|
7124
|
+
const selectedIndex = select4(accountsWithMetrics.filter((row) => preferredIndexes.has(row.index))) ?? select4(accountsWithMetrics);
|
|
7110
7125
|
if (selectedIndex !== null) {
|
|
7111
7126
|
const selected = this.accounts[selectedIndex];
|
|
7112
7127
|
if (selected) {
|
|
@@ -7134,7 +7149,8 @@ var init_account_selector = __esm({
|
|
|
7134
7149
|
offsetApplied[family] = true;
|
|
7135
7150
|
}
|
|
7136
7151
|
const current = this.getCurrentAccountForFamily(family, identity3);
|
|
7137
|
-
|
|
7152
|
+
const preferred = preferArgonAccounts(this.accounts.filter((row) => row.enabled !== false && !row.accountIneligible && !row.verificationRequired && !excludeIndexes?.has(row.index) && !isRateLimitedForFamily(row, family, this.now, model) && !this.isAccountCoolingDown(row) && !isOverSoftQuotaThreshold(row, family, effectiveSoftQuotaThreshold, softQuotaCacheTtlMs, this.now, model)), model);
|
|
7153
|
+
if (current && preferred.includes(current)) {
|
|
7138
7154
|
clearExpiredRateLimits(current, this.now);
|
|
7139
7155
|
const isLimitedForRequestedStyle = isRateLimitedForFamily(current, family, this.now, model);
|
|
7140
7156
|
const isOverThreshold = isOverSoftQuotaThreshold(current, family, effectiveSoftQuotaThreshold, softQuotaCacheTtlMs, this.now, model);
|
|
@@ -7156,7 +7172,7 @@ var init_account_selector = __esm({
|
|
|
7156
7172
|
clearExpiredRateLimits(account2, this.now);
|
|
7157
7173
|
return account2.enabled !== false && account2.accountIneligible !== true && account2.verificationRequired !== true && !excludeIndexes?.has(account2.index) && !isRateLimitedForFamily(account2, family, this.now, model) && !isOverSoftQuotaThreshold(account2, family, effectiveSoftQuotaThreshold, softQuotaCacheTtlMs, this.now, model) && !this.isAccountCoolingDown(account2);
|
|
7158
7174
|
});
|
|
7159
|
-
const available = this.preferAccountOutsideParent(allAvailable, family, identity3);
|
|
7175
|
+
const available = this.preferAccountOutsideParent(preferArgonAccounts(allAvailable, model), family, identity3);
|
|
7160
7176
|
if (available.length === 0) {
|
|
7161
7177
|
return null;
|
|
7162
7178
|
}
|
|
@@ -12520,6 +12536,48 @@ var init_identity = __esm({
|
|
|
12520
12536
|
}
|
|
12521
12537
|
});
|
|
12522
12538
|
|
|
12539
|
+
// ../core/dist/common-auth-embedded/store/hooks.js
|
|
12540
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
12541
|
+
function assertNotInsideHook(operation) {
|
|
12542
|
+
if (insideHook.getStore() !== void 0)
|
|
12543
|
+
throw new PoolReentryError(operation);
|
|
12544
|
+
}
|
|
12545
|
+
function assertLimitsWriteAllowed() {
|
|
12546
|
+
if (insideHook.getStore()?.storeLocksReleased === false || insideCodec.getStore())
|
|
12547
|
+
throw new PoolReentryError("updateLimitsNamespace");
|
|
12548
|
+
}
|
|
12549
|
+
function runInsideCodec(fn) {
|
|
12550
|
+
return insideCodec.run(true, fn);
|
|
12551
|
+
}
|
|
12552
|
+
function runInsideHook(operation, fn, storeLocksReleased = false) {
|
|
12553
|
+
return insideHook.run({
|
|
12554
|
+
operation,
|
|
12555
|
+
storeLocksReleased: storeLocksReleased && insideHook.getStore()?.storeLocksReleased !== false
|
|
12556
|
+
}, async () => await fn());
|
|
12557
|
+
}
|
|
12558
|
+
async function callFailureHook(operation, hook, rowId2, error, logger3) {
|
|
12559
|
+
if (!hook)
|
|
12560
|
+
return;
|
|
12561
|
+
try {
|
|
12562
|
+
await runInsideHook(operation, () => hook(rowId2, error), true);
|
|
12563
|
+
} catch (hookError) {
|
|
12564
|
+
logger3?.warn("store failure hook threw; the original failure stands", {
|
|
12565
|
+
operation,
|
|
12566
|
+
rowId: rowId2,
|
|
12567
|
+
error: hookError instanceof Error ? hookError.message : String(hookError)
|
|
12568
|
+
});
|
|
12569
|
+
}
|
|
12570
|
+
}
|
|
12571
|
+
var insideHook, insideCodec;
|
|
12572
|
+
var init_hooks = __esm({
|
|
12573
|
+
"../core/dist/common-auth-embedded/store/hooks.js"() {
|
|
12574
|
+
"use strict";
|
|
12575
|
+
init_errors();
|
|
12576
|
+
insideHook = new AsyncLocalStorage();
|
|
12577
|
+
insideCodec = new AsyncLocalStorage();
|
|
12578
|
+
}
|
|
12579
|
+
});
|
|
12580
|
+
|
|
12523
12581
|
// ../core/dist/common-auth-embedded/fs/atomic-write.js
|
|
12524
12582
|
import { randomUUID as randomUUID8 } from "node:crypto";
|
|
12525
12583
|
import { mkdir as mkdir6, open as open3, rename as rename5, rm as rm3 } from "node:fs/promises";
|
|
@@ -12901,37 +12959,83 @@ async function acquireRefreshFileLockWithClock(options) {
|
|
|
12901
12959
|
await rm4(path5, { recursive: true, force: true }).catch(() => {
|
|
12902
12960
|
});
|
|
12903
12961
|
}
|
|
12904
|
-
|
|
12905
|
-
if (
|
|
12906
|
-
|
|
12907
|
-
|
|
12962
|
+
function isRetryableRemoval(error, path5) {
|
|
12963
|
+
if (!windowsPrivateFiles || !(error instanceof PrivateFileError) || error.stage !== "remove" || error.path !== path5)
|
|
12964
|
+
return false;
|
|
12965
|
+
return isWindowsSharingViolation(error) || error.win32Code === void 0 && error.reason === void 0 && (error.code === "EBUSY" || error.code === "EPERM");
|
|
12908
12966
|
}
|
|
12909
|
-
async function
|
|
12967
|
+
async function removeOwnedLeaseObject(path5, stillOwned, deadline = performance.now() + EVICT_TTL + 1e3) {
|
|
12968
|
+
let original;
|
|
12969
|
+
let delayMs = 5;
|
|
12970
|
+
while (await stillOwned()) {
|
|
12971
|
+
try {
|
|
12972
|
+
await removeLeaseObject(path5);
|
|
12973
|
+
return;
|
|
12974
|
+
} catch (error) {
|
|
12975
|
+
if (!isRetryableRemoval(error, path5))
|
|
12976
|
+
throw error;
|
|
12977
|
+
original ??= error;
|
|
12978
|
+
}
|
|
12979
|
+
const remainingMs = deadline - performance.now();
|
|
12980
|
+
if (remainingMs <= 0)
|
|
12981
|
+
throw original;
|
|
12982
|
+
await new Promise((resolve28) => setTimeout(resolve28, Math.min(delayMs, remainingMs)));
|
|
12983
|
+
if (performance.now() >= deadline)
|
|
12984
|
+
throw original;
|
|
12985
|
+
delayMs = Math.min(delayMs * 2, 50);
|
|
12986
|
+
}
|
|
12987
|
+
}
|
|
12988
|
+
async function releaseEvictionMarker(deadline) {
|
|
12989
|
+
let ownedDirectory;
|
|
12990
|
+
await removeOwnedLeaseObject(evictPath, async () => {
|
|
12991
|
+
if (!windowsPrivateFiles)
|
|
12992
|
+
return ownsEvictionMarker();
|
|
12993
|
+
const current = await lstat3(evictPath).catch((error) => {
|
|
12994
|
+
if (error.code !== "ENOENT")
|
|
12995
|
+
throw error;
|
|
12996
|
+
return void 0;
|
|
12997
|
+
});
|
|
12998
|
+
if (!current || ownedDirectory && !sameMarkerDirectory(ownedDirectory, current))
|
|
12999
|
+
return false;
|
|
13000
|
+
if (await ownsEvictionMarker()) {
|
|
13001
|
+
ownedDirectory = current;
|
|
13002
|
+
return true;
|
|
13003
|
+
}
|
|
13004
|
+
if (!ownedDirectory)
|
|
13005
|
+
return false;
|
|
13006
|
+
try {
|
|
13007
|
+
await stat3(evictOwnerPath);
|
|
13008
|
+
return false;
|
|
13009
|
+
} catch (error) {
|
|
13010
|
+
if (error.code !== "ENOENT")
|
|
13011
|
+
throw error;
|
|
13012
|
+
return true;
|
|
13013
|
+
}
|
|
13014
|
+
}, deadline);
|
|
13015
|
+
}
|
|
13016
|
+
async function removeOwnMarkerAfterFailedOwnerWrite(created, deadline) {
|
|
12910
13017
|
if (!created)
|
|
12911
13018
|
return false;
|
|
12912
|
-
let
|
|
12913
|
-
try {
|
|
12914
|
-
const st = await lstat3(evictPath);
|
|
12915
|
-
current = { dev: st.dev, ino: st.ino, birthtimeMs: st.birthtimeMs };
|
|
12916
|
-
} catch {
|
|
12917
|
-
return false;
|
|
12918
|
-
}
|
|
12919
|
-
if (!sameMarkerDirectory(created, current))
|
|
12920
|
-
return false;
|
|
12921
|
-
try {
|
|
12922
|
-
await stat3(evictOwnerPath);
|
|
12923
|
-
return true;
|
|
12924
|
-
} catch (error) {
|
|
12925
|
-
if (error.code !== "ENOENT")
|
|
12926
|
-
return true;
|
|
12927
|
-
}
|
|
13019
|
+
let stillOurs = false;
|
|
12928
13020
|
try {
|
|
12929
|
-
await
|
|
13021
|
+
await removeOwnedLeaseObject(evictPath, async () => {
|
|
13022
|
+
stillOurs = false;
|
|
13023
|
+
const st = await lstat3(evictPath).catch(() => void 0);
|
|
13024
|
+
if (!st || !sameMarkerDirectory(created, st))
|
|
13025
|
+
return false;
|
|
13026
|
+
stillOurs = true;
|
|
13027
|
+
try {
|
|
13028
|
+
await stat3(evictOwnerPath);
|
|
13029
|
+
return false;
|
|
13030
|
+
} catch (error) {
|
|
13031
|
+
return error.code === "ENOENT";
|
|
13032
|
+
}
|
|
13033
|
+
}, deadline);
|
|
12930
13034
|
} catch {
|
|
12931
13035
|
}
|
|
12932
|
-
return
|
|
13036
|
+
return stillOurs;
|
|
12933
13037
|
}
|
|
12934
|
-
async function tryAcquireEvictionMarker() {
|
|
13038
|
+
async function tryAcquireEvictionMarker(deadline) {
|
|
12935
13039
|
if (windowsPrivateFiles)
|
|
12936
13040
|
await createPrivateDirectoryExclusive(evictPath);
|
|
12937
13041
|
else
|
|
@@ -12955,11 +13059,11 @@ async function acquireRefreshFileLockWithClock(options) {
|
|
|
12955
13059
|
else
|
|
12956
13060
|
await createExclusiveText(evictOwnerPath, bytes);
|
|
12957
13061
|
} catch (error) {
|
|
12958
|
-
const stillOurs = await removeOwnMarkerAfterFailedOwnerWrite(created);
|
|
13062
|
+
const stillOurs = await removeOwnMarkerAfterFailedOwnerWrite(created, deadline);
|
|
12959
13063
|
if (isLostMarkerRaceError(error) && !stillOurs)
|
|
12960
13064
|
return false;
|
|
12961
13065
|
try {
|
|
12962
|
-
await releaseEvictionMarker();
|
|
13066
|
+
await releaseEvictionMarker(deadline);
|
|
12963
13067
|
} catch {
|
|
12964
13068
|
}
|
|
12965
13069
|
throw error;
|
|
@@ -12968,7 +13072,7 @@ async function acquireRefreshFileLockWithClock(options) {
|
|
|
12968
13072
|
await options.onStep("eviction-marker-acquired");
|
|
12969
13073
|
return true;
|
|
12970
13074
|
}
|
|
12971
|
-
async function recoverStaleEvictionMarker() {
|
|
13075
|
+
async function recoverStaleEvictionMarker(deadline) {
|
|
12972
13076
|
let evictStat;
|
|
12973
13077
|
try {
|
|
12974
13078
|
evictStat = await stat3(evictPath);
|
|
@@ -13013,12 +13117,22 @@ async function acquireRefreshFileLockWithClock(options) {
|
|
|
13013
13117
|
}
|
|
13014
13118
|
if (options.onStep)
|
|
13015
13119
|
await options.onStep("stale-marker-claimed");
|
|
13016
|
-
await
|
|
13120
|
+
const claimedIdentity = windowsPrivateFiles ? await lstat3(claimedPath) : void 0;
|
|
13121
|
+
await removeOwnedLeaseObject(claimedPath, async () => {
|
|
13122
|
+
if (!claimedIdentity)
|
|
13123
|
+
return true;
|
|
13124
|
+
const current = await lstat3(claimedPath).catch((error) => {
|
|
13125
|
+
if (error.code !== "ENOENT")
|
|
13126
|
+
throw error;
|
|
13127
|
+
return void 0;
|
|
13128
|
+
});
|
|
13129
|
+
return !!current && sameMarkerDirectory(claimedIdentity, current);
|
|
13130
|
+
}, deadline);
|
|
13017
13131
|
return "recovered";
|
|
13018
13132
|
}
|
|
13019
|
-
async function withEvictionMarker(action) {
|
|
13133
|
+
async function withEvictionMarker(action, deadline) {
|
|
13020
13134
|
try {
|
|
13021
|
-
if (!await tryAcquireEvictionMarker())
|
|
13135
|
+
if (!await tryAcquireEvictionMarker(deadline))
|
|
13022
13136
|
return false;
|
|
13023
13137
|
} catch (error) {
|
|
13024
13138
|
if (error.code === "EEXIST") {
|
|
@@ -13035,11 +13149,23 @@ async function acquireRefreshFileLockWithClock(options) {
|
|
|
13035
13149
|
}
|
|
13036
13150
|
throw error;
|
|
13037
13151
|
}
|
|
13152
|
+
let actionFailed = false;
|
|
13153
|
+
let actionError;
|
|
13038
13154
|
try {
|
|
13039
13155
|
await action();
|
|
13040
|
-
}
|
|
13041
|
-
|
|
13156
|
+
} catch (error) {
|
|
13157
|
+
actionFailed = true;
|
|
13158
|
+
actionError = error;
|
|
13042
13159
|
}
|
|
13160
|
+
try {
|
|
13161
|
+
await releaseEvictionMarker(deadline);
|
|
13162
|
+
} catch (error) {
|
|
13163
|
+
if (isRetryableRemoval(actionError, lockPath) && isRetryableRemoval(error, evictPath))
|
|
13164
|
+
throw actionError;
|
|
13165
|
+
throw error;
|
|
13166
|
+
}
|
|
13167
|
+
if (actionFailed)
|
|
13168
|
+
throw actionError;
|
|
13043
13169
|
return true;
|
|
13044
13170
|
}
|
|
13045
13171
|
async function relinquishLockAfterMarkerLoss() {
|
|
@@ -13276,6 +13402,7 @@ async function acquireRefreshFileLockWithClock(options) {
|
|
|
13276
13402
|
await renewalInFlight;
|
|
13277
13403
|
const deadline = performance.now() + EVICT_TTL + 1e3;
|
|
13278
13404
|
let delayMs = 5;
|
|
13405
|
+
let removalError;
|
|
13279
13406
|
for (; ; ) {
|
|
13280
13407
|
try {
|
|
13281
13408
|
let removalConfirmed = false;
|
|
@@ -13300,7 +13427,7 @@ async function acquireRefreshFileLockWithClock(options) {
|
|
|
13300
13427
|
return;
|
|
13301
13428
|
await removeLeaseObject(lockPath);
|
|
13302
13429
|
removalConfirmed = true;
|
|
13303
|
-
});
|
|
13430
|
+
}, deadline);
|
|
13304
13431
|
if (markerAcquired) {
|
|
13305
13432
|
if (windowsPrivateFiles && !removalConfirmed)
|
|
13306
13433
|
throw new PrivateFileError(lockPath, "release-not-confirmed", {
|
|
@@ -13311,20 +13438,25 @@ async function acquireRefreshFileLockWithClock(options) {
|
|
|
13311
13438
|
}
|
|
13312
13439
|
if (signal?.aborted)
|
|
13313
13440
|
return;
|
|
13314
|
-
await recoverStaleEvictionMarker();
|
|
13441
|
+
await recoverStaleEvictionMarker(deadline);
|
|
13315
13442
|
} catch (error) {
|
|
13316
|
-
if (
|
|
13317
|
-
|
|
13318
|
-
|
|
13443
|
+
if (!isRetryableRemoval(error, lockPath)) {
|
|
13444
|
+
if (windowsPrivateFiles)
|
|
13445
|
+
throw error;
|
|
13446
|
+
return;
|
|
13447
|
+
}
|
|
13448
|
+
removalError ??= error;
|
|
13319
13449
|
}
|
|
13320
13450
|
const remainingMs = deadline - performance.now();
|
|
13321
13451
|
if (remainingMs <= 0)
|
|
13322
13452
|
break;
|
|
13323
13453
|
await new Promise((resolve28) => setTimeout(resolve28, Math.min(delayMs, remainingMs)));
|
|
13454
|
+
if (windowsPrivateFiles && performance.now() >= deadline)
|
|
13455
|
+
break;
|
|
13324
13456
|
delayMs = Math.min(delayMs * 2, 50);
|
|
13325
13457
|
}
|
|
13326
13458
|
if (windowsPrivateFiles)
|
|
13327
|
-
throw new PrivateFileError(lockPath, "release-not-confirmed", {
|
|
13459
|
+
throw removalError ?? new PrivateFileError(lockPath, "release-not-confirmed", {
|
|
13328
13460
|
code: "ETIMEDOUT"
|
|
13329
13461
|
});
|
|
13330
13462
|
}
|
|
@@ -13348,7 +13480,7 @@ function lockPathFor(target, name) {
|
|
|
13348
13480
|
return `${target}.${name}.lock`;
|
|
13349
13481
|
}
|
|
13350
13482
|
function isChangingLockRead(error, target, name) {
|
|
13351
|
-
if (!
|
|
13483
|
+
if (!isWindowsSharingViolation(error) || error.stage !== "read" && error.stage !== "verify")
|
|
13352
13484
|
return false;
|
|
13353
13485
|
const path5 = resolve3(lockPathFor(target, name));
|
|
13354
13486
|
return error.path === path5 || error.path === join6(path5, "owner.json");
|
|
@@ -13420,37 +13552,6 @@ var init_with_lock = __esm({
|
|
|
13420
13552
|
}
|
|
13421
13553
|
});
|
|
13422
13554
|
|
|
13423
|
-
// ../core/dist/common-auth-embedded/store/hooks.js
|
|
13424
|
-
import { AsyncLocalStorage } from "node:async_hooks";
|
|
13425
|
-
function assertNotInsideHook(operation) {
|
|
13426
|
-
if (insideHook.getStore() !== void 0)
|
|
13427
|
-
throw new PoolReentryError(operation);
|
|
13428
|
-
}
|
|
13429
|
-
function runInsideHook(operation, fn) {
|
|
13430
|
-
return insideHook.run(operation, async () => await fn());
|
|
13431
|
-
}
|
|
13432
|
-
async function callFailureHook(operation, hook, rowId2, error, logger3) {
|
|
13433
|
-
if (!hook)
|
|
13434
|
-
return;
|
|
13435
|
-
try {
|
|
13436
|
-
await runInsideHook(operation, () => hook(rowId2, error));
|
|
13437
|
-
} catch (hookError) {
|
|
13438
|
-
logger3?.warn("store failure hook threw; the original failure stands", {
|
|
13439
|
-
operation,
|
|
13440
|
-
rowId: rowId2,
|
|
13441
|
-
error: hookError instanceof Error ? hookError.message : String(hookError)
|
|
13442
|
-
});
|
|
13443
|
-
}
|
|
13444
|
-
}
|
|
13445
|
-
var insideHook;
|
|
13446
|
-
var init_hooks = __esm({
|
|
13447
|
-
"../core/dist/common-auth-embedded/store/hooks.js"() {
|
|
13448
|
-
"use strict";
|
|
13449
|
-
init_errors();
|
|
13450
|
-
insideHook = new AsyncLocalStorage();
|
|
13451
|
-
}
|
|
13452
|
-
});
|
|
13453
|
-
|
|
13454
13555
|
// ../core/dist/common-auth-embedded/store/refresh-lock.js
|
|
13455
13556
|
async function acquirePoolLock(spec, defaults, env3) {
|
|
13456
13557
|
const emit = (type) => {
|
|
@@ -13682,7 +13783,7 @@ function stampFor(credential, credentialEpoch2, binding, options = {}) {
|
|
|
13682
13783
|
};
|
|
13683
13784
|
}
|
|
13684
13785
|
function providerStateDigest(codec, value) {
|
|
13685
|
-
const bound = codec?.credentialBound ? codec.credentialBound(value) : value;
|
|
13786
|
+
const bound = codec?.credentialBound ? runInsideCodec(() => codec.credentialBound?.(value)) : value;
|
|
13686
13787
|
return createHash5("sha256").update(`provider-state\0${JSON.stringify(bound ?? null)}`).digest("hex");
|
|
13687
13788
|
}
|
|
13688
13789
|
function boundProviderStateDigest(account, credential, credentialEpoch2, identity3) {
|
|
@@ -13849,8 +13950,8 @@ function parseEntry(raw, codec) {
|
|
|
13849
13950
|
return void 0;
|
|
13850
13951
|
if ("disabledReason" in raw && typeof raw.disabledReason !== "string")
|
|
13851
13952
|
return void 0;
|
|
13852
|
-
const quota = "quota" in raw && codec.decode ? codec.decode(raw.quota) : raw.quota;
|
|
13853
|
-
if ("quota" in raw && !codec.validate(quota))
|
|
13953
|
+
const quota = "quota" in raw && codec.decode ? runInsideCodec(() => codec.decode?.(raw.quota)) : raw.quota;
|
|
13954
|
+
if ("quota" in raw && !runInsideCodec(() => codec.validate(quota)))
|
|
13854
13955
|
return void 0;
|
|
13855
13956
|
if ("staged" in raw && !parseReservation(raw.staged))
|
|
13856
13957
|
return void 0;
|
|
@@ -14022,7 +14123,7 @@ function providerStateFields(account, credential, credentialEpoch2, identity3, c
|
|
|
14022
14123
|
if (digest3 === void 0)
|
|
14023
14124
|
return { providerStateDropped: "uncovered" };
|
|
14024
14125
|
const value = account[PROVIDER_STATE_KEY];
|
|
14025
|
-
if (!codec
|
|
14126
|
+
if (!codec || !runInsideCodec(() => codec.validate(value)))
|
|
14026
14127
|
return { providerStateDropped: "invalid" };
|
|
14027
14128
|
if (providerStateDigest(codec, value) !== digest3)
|
|
14028
14129
|
return { providerStateDropped: "uncovered" };
|
|
@@ -14099,6 +14200,7 @@ var POOL_KEY, POOL_SCHEMA_VERSION, POOL_ROWS_KEY, POOL_RETIRED_EPOCHS_KEY, LEGAC
|
|
|
14099
14200
|
var init_schema = __esm({
|
|
14100
14201
|
"../core/dist/common-auth-embedded/store/schema.js"() {
|
|
14101
14202
|
"use strict";
|
|
14203
|
+
init_hooks();
|
|
14102
14204
|
POOL_KEY = "commonAuthPool";
|
|
14103
14205
|
POOL_SCHEMA_VERSION = 1;
|
|
14104
14206
|
POOL_ROWS_KEY = "rows";
|
|
@@ -14799,8 +14901,8 @@ function assertQuotaRow(id, attribution, row) {
|
|
|
14799
14901
|
});
|
|
14800
14902
|
}
|
|
14801
14903
|
function mergedQuota(ctx, id, stored, observation) {
|
|
14802
|
-
const merged = ctx.codec.merge(stored, observation);
|
|
14803
|
-
if (!ctx.codec.validate(merged))
|
|
14904
|
+
const merged = runInsideCodec(() => ctx.codec.merge(stored, observation));
|
|
14905
|
+
if (!runInsideCodec(() => ctx.codec.validate(merged)))
|
|
14804
14906
|
throw refusal2("pull", id, "invalid-quota", "the quota codec rejected the merged map");
|
|
14805
14907
|
return merged;
|
|
14806
14908
|
}
|
|
@@ -14840,6 +14942,7 @@ var init_attribution = __esm({
|
|
|
14840
14942
|
"../core/dist/common-auth-embedded/store/attribution.js"() {
|
|
14841
14943
|
"use strict";
|
|
14842
14944
|
init_errors();
|
|
14945
|
+
init_hooks();
|
|
14843
14946
|
init_mutate();
|
|
14844
14947
|
init_refresh_lock();
|
|
14845
14948
|
init_runtime();
|
|
@@ -14847,6 +14950,46 @@ var init_attribution = __esm({
|
|
|
14847
14950
|
}
|
|
14848
14951
|
});
|
|
14849
14952
|
|
|
14953
|
+
// ../core/dist/common-auth-embedded/store/limits-namespace.js
|
|
14954
|
+
async function updatePoolLimitsNamespace(rt, mutator) {
|
|
14955
|
+
assertLimitsWriteAllowed();
|
|
14956
|
+
const { ctx } = rt;
|
|
14957
|
+
await runOperation(ctx, "updateLimitsNamespace", void 0, void 0, async (locks, progress) => {
|
|
14958
|
+
for (const spec of ctx.storeLocks)
|
|
14959
|
+
await locks.acquire(spec);
|
|
14960
|
+
const result = await readPool(ctx);
|
|
14961
|
+
if (result.status !== "ready")
|
|
14962
|
+
throw notReadyError(result, "updateLimitsNamespace", void 0);
|
|
14963
|
+
const rows = result.rows.map(({ id, credentialEpoch: credentialEpoch2, identity: identity3 }) => ({
|
|
14964
|
+
id,
|
|
14965
|
+
credentialEpoch: credentialEpoch2,
|
|
14966
|
+
identity: identity3
|
|
14967
|
+
}));
|
|
14968
|
+
const envelope = await runInsideHook("updateLimitsNamespace", () => mutator(structuredClone(result.config.commonAuthLimits), rows));
|
|
14969
|
+
const config = { ...result.config, commonAuthLimits: envelope };
|
|
14970
|
+
const info = {
|
|
14971
|
+
operation: "updateLimitsNamespace",
|
|
14972
|
+
rowId: void 0
|
|
14973
|
+
};
|
|
14974
|
+
await writeJsonAtomic2(ctx.configPath, config, {
|
|
14975
|
+
beforeRename: async () => {
|
|
14976
|
+
await ctx.onStep?.("before-config-write", info);
|
|
14977
|
+
await locks.assertAll();
|
|
14978
|
+
}
|
|
14979
|
+
});
|
|
14980
|
+
progress.writes++;
|
|
14981
|
+
await ctx.onStep?.("after-config-write", info);
|
|
14982
|
+
});
|
|
14983
|
+
}
|
|
14984
|
+
var init_limits_namespace = __esm({
|
|
14985
|
+
"../core/dist/common-auth-embedded/store/limits-namespace.js"() {
|
|
14986
|
+
"use strict";
|
|
14987
|
+
init_atomic_write2();
|
|
14988
|
+
init_hooks();
|
|
14989
|
+
init_mutate();
|
|
14990
|
+
}
|
|
14991
|
+
});
|
|
14992
|
+
|
|
14850
14993
|
// ../core/dist/common-auth-embedded/store/provider-state.js
|
|
14851
14994
|
function acceptProviderState(codec, operation, id, value, what = "the provider state") {
|
|
14852
14995
|
if (!codec)
|
|
@@ -14860,7 +15003,7 @@ function acceptProviderState(codec, operation, id, value, what = "the provider s
|
|
|
14860
15003
|
}
|
|
14861
15004
|
if (normalized === void 0)
|
|
14862
15005
|
throw refusal2(operation, id, "invalid-provider-state", `${what} cannot be stored as JSON`);
|
|
14863
|
-
if (!codec.validate(normalized))
|
|
15006
|
+
if (!runInsideCodec(() => codec.validate(normalized)))
|
|
14864
15007
|
throw refusal2(operation, id, "invalid-provider-state", `the provider-state codec rejected ${what}`);
|
|
14865
15008
|
return normalized;
|
|
14866
15009
|
}
|
|
@@ -14869,18 +15012,18 @@ function mergedProviderState(codec, operation, id, onDisk, incoming) {
|
|
|
14869
15012
|
return { kind: "set", value: incoming };
|
|
14870
15013
|
return {
|
|
14871
15014
|
kind: "set",
|
|
14872
|
-
value: acceptProviderState(codec, operation, id, codec.merge(structuredClone(onDisk), structuredClone(incoming)), "the merged provider state")
|
|
15015
|
+
value: acceptProviderState(codec, operation, id, runInsideCodec(() => codec.merge?.(structuredClone(onDisk), structuredClone(incoming))), "the merged provider state")
|
|
14873
15016
|
};
|
|
14874
15017
|
}
|
|
14875
15018
|
function replacementProviderState(codec, row, credentialEpoch2, identity3, incoming) {
|
|
14876
15019
|
const hook = codec?.onReplace;
|
|
14877
|
-
const next = hook ? hook(row.providerState === void 0 ? void 0 : structuredClone(row.providerState), {
|
|
15020
|
+
const next = hook ? runInsideCodec(() => hook(row.providerState === void 0 ? void 0 : structuredClone(row.providerState), {
|
|
14878
15021
|
id: row.id,
|
|
14879
15022
|
credentialEpoch: credentialEpoch2,
|
|
14880
15023
|
...row.identity !== void 0 ? { previousIdentity: row.identity } : {},
|
|
14881
15024
|
...identity3 !== void 0 ? { identity: identity3 } : {},
|
|
14882
15025
|
...incoming !== void 0 ? { incoming: structuredClone(incoming) } : {}
|
|
14883
|
-
}) : incoming;
|
|
15026
|
+
})) : incoming;
|
|
14884
15027
|
if (next === void 0)
|
|
14885
15028
|
return { kind: "clear" };
|
|
14886
15029
|
if (!hook)
|
|
@@ -17140,7 +17283,7 @@ async function refreshRow(rt, id, provider2, options = {}) {
|
|
|
17140
17283
|
if (options.onPersisted) {
|
|
17141
17284
|
try {
|
|
17142
17285
|
const persisted = options.onPersisted;
|
|
17143
|
-
await runInsideHook("refresh", () => persisted(id, commit.stored));
|
|
17286
|
+
await runInsideHook("refresh", () => persisted(id, commit.stored), true);
|
|
17144
17287
|
} catch (cause) {
|
|
17145
17288
|
throw new PoolOperationError({
|
|
17146
17289
|
operation: "refresh",
|
|
@@ -17249,7 +17392,7 @@ function defineKey(target, key, value) {
|
|
|
17249
17392
|
function composeConfig(config, next) {
|
|
17250
17393
|
const out = {};
|
|
17251
17394
|
for (const [key, value] of Object.entries(config)) {
|
|
17252
|
-
if (POOL_OWNED_KEYS.includes(key))
|
|
17395
|
+
if (POOL_OWNED_KEYS.includes(key) || key === "commonAuthLimits")
|
|
17253
17396
|
defineKey(out, key, value);
|
|
17254
17397
|
else if (Object.hasOwn(next, key))
|
|
17255
17398
|
defineKey(out, key, next[key]);
|
|
@@ -17301,9 +17444,11 @@ async function updatePoolSettings(rt, mutator, options = {}) {
|
|
|
17301
17444
|
const owned = POOL_OWNED_KEYS.filter((key) => Object.hasOwn(next, key));
|
|
17302
17445
|
if (owned.length > 0)
|
|
17303
17446
|
throw settingsRefusal(`settings cannot set the pool-owned key(s) ${owned.join(", ")}`);
|
|
17304
|
-
if (isDeepStrictEqual3(next, current))
|
|
17305
|
-
|
|
17447
|
+
if (Object.hasOwn(next, "commonAuthLimits") && (!Object.hasOwn(current, "commonAuthLimits") || !isDeepStrictEqual3(next.commonAuthLimits, current.commonAuthLimits)))
|
|
17448
|
+
throw settingsRefusal("settings cannot alter commonAuthLimits; use updateLimitsNamespace");
|
|
17306
17449
|
const config = composeConfig(result.config, next);
|
|
17450
|
+
if (isDeepStrictEqual3(settingsOf2(config), current))
|
|
17451
|
+
return { settings: current, outcome: "unchanged" };
|
|
17307
17452
|
const info = { operation: "updateSettings", rowId: void 0 };
|
|
17308
17453
|
await writeJsonAtomic2(ctx.configPath, config, {
|
|
17309
17454
|
beforeRename: async () => {
|
|
@@ -17438,6 +17583,7 @@ function openPoolStore(options) {
|
|
|
17438
17583
|
reorder: (ids, callOptions) => reorderRows(rt, ids, callOptions),
|
|
17439
17584
|
readSettings: () => readPoolSettings(rt),
|
|
17440
17585
|
updateSettings: (mutator, callOptions) => updatePoolSettings(rt, mutator, callOptions),
|
|
17586
|
+
updateLimitsNamespace: (mutator) => updatePoolLimitsNamespace(rt, mutator),
|
|
17441
17587
|
recordIdentity: (id, identity3, attribution, callOptions) => recordRowIdentity(rt, id, identity3, attribution, callOptions),
|
|
17442
17588
|
refresh: (id, provider2, callOptions) => refreshRow(rt, id, provider2, callOptions),
|
|
17443
17589
|
recordQuota: record3,
|
|
@@ -17452,6 +17598,7 @@ var init_pool = __esm({
|
|
|
17452
17598
|
"../core/dist/common-auth-embedded/store/pool.js"() {
|
|
17453
17599
|
"use strict";
|
|
17454
17600
|
init_attribution();
|
|
17601
|
+
init_limits_namespace();
|
|
17455
17602
|
init_mutate();
|
|
17456
17603
|
init_provider_state();
|
|
17457
17604
|
init_publication();
|
|
@@ -17557,7 +17704,7 @@ function exclusionFor(id, inputs, now) {
|
|
|
17557
17704
|
}
|
|
17558
17705
|
return void 0;
|
|
17559
17706
|
}
|
|
17560
|
-
function judgeStageOne(id, projection, requiredLabels, now) {
|
|
17707
|
+
function judgeStageOne(id, projection, requiredLabels, now, liftedWindows) {
|
|
17561
17708
|
if (projection.limits.length === 0) {
|
|
17562
17709
|
return {
|
|
17563
17710
|
id,
|
|
@@ -17581,7 +17728,7 @@ function judgeStageOne(id, projection, requiredLabels, now) {
|
|
|
17581
17728
|
}
|
|
17582
17729
|
const exhausted = projection.limits.filter(readsExhausted);
|
|
17583
17730
|
for (const limit of exhausted) {
|
|
17584
|
-
if (futureResetAt(limit, now) === void 0) {
|
|
17731
|
+
if (futureResetAt(limit, now) === void 0 && !liftedWindows.some((window) => window.scope === limit.scope && window.label === limit.label)) {
|
|
17585
17732
|
return {
|
|
17586
17733
|
id,
|
|
17587
17734
|
stage: 1,
|
|
@@ -17614,6 +17761,7 @@ function admit(input2) {
|
|
|
17614
17761
|
const excluded = [];
|
|
17615
17762
|
const refused2 = [];
|
|
17616
17763
|
const survivors = [];
|
|
17764
|
+
const needsPull = /* @__PURE__ */ new Set();
|
|
17617
17765
|
for (const row of input2.rows) {
|
|
17618
17766
|
const exclusion = exclusionFor(row.id, input2, input2.now);
|
|
17619
17767
|
if (exclusion) {
|
|
@@ -17625,7 +17773,10 @@ function admit(input2) {
|
|
|
17625
17773
|
continue;
|
|
17626
17774
|
}
|
|
17627
17775
|
const projection = projectQuota(row.quota, scope);
|
|
17628
|
-
const
|
|
17776
|
+
const lifted = input2.liftedWindows?.get(row.id) ?? [];
|
|
17777
|
+
if (projection.limits.some((limit) => readsExhausted(limit) && futureResetAt(limit, input2.now) === void 0 && lifted.some((window) => window.scope === limit.scope && window.label === limit.label)))
|
|
17778
|
+
needsPull.add(row.id);
|
|
17779
|
+
const refusal3 = judgeStageOne(row.id, projection, requiredLabels, input2.now, lifted);
|
|
17629
17780
|
if (refusal3) {
|
|
17630
17781
|
refused2.push(refusal3);
|
|
17631
17782
|
continue;
|
|
@@ -17651,7 +17802,10 @@ function admit(input2) {
|
|
|
17651
17802
|
const order = new Map(input2.rows.map((row, index) => [row.id, index]));
|
|
17652
17803
|
const byInput = (left, right) => (order.get(left.id) ?? 0) - (order.get(right.id) ?? 0);
|
|
17653
17804
|
refused2.sort(byInput);
|
|
17654
|
-
|
|
17805
|
+
for (const refusal3 of refused2)
|
|
17806
|
+
if ("pullRequested" in refusal3)
|
|
17807
|
+
needsPull.add(refusal3.id);
|
|
17808
|
+
const pulls = input2.rows.filter((row) => needsPull.has(row.id)).map((row) => row.id);
|
|
17655
17809
|
for (const id of pulls)
|
|
17656
17810
|
input2.requestPull?.(id);
|
|
17657
17811
|
return { admitted, refused: refused2, excluded, pulls };
|
|
@@ -18622,6 +18776,44 @@ function routingSection2(options, snap) {
|
|
|
18622
18776
|
return result.outcome === "unchanged" ? "The order is unchanged." : `Order set to ${result.ids.map(nameOf).join(", ")}.`;
|
|
18623
18777
|
}
|
|
18624
18778
|
});
|
|
18779
|
+
if (options.routing?.sameAccountWait) {
|
|
18780
|
+
const waitLabel = "Longest wait on the same account";
|
|
18781
|
+
const waitChoices = [
|
|
18782
|
+
{ value: "0", label: "Don't wait" },
|
|
18783
|
+
{ value: "15", label: "15 minutes" },
|
|
18784
|
+
{ value: "max", label: "Until the cache expires" }
|
|
18785
|
+
];
|
|
18786
|
+
const rawWait = record(snap.settings.routing).maxSameAccountWait;
|
|
18787
|
+
const wait2 = String(rawWait === 0 || rawWait === "max" ? rawWait : 15);
|
|
18788
|
+
const waitName = (value) => waitChoices.find((choice) => choice.value === value)?.label ?? value;
|
|
18789
|
+
lines.push(`${waitLabel}: ${waitName(wait2)}`);
|
|
18790
|
+
actions.push({
|
|
18791
|
+
id: "maxSameAccountWait",
|
|
18792
|
+
label: waitLabel,
|
|
18793
|
+
group: ACTIONS_GROUP,
|
|
18794
|
+
knobs: [
|
|
18795
|
+
{
|
|
18796
|
+
kind: "choice",
|
|
18797
|
+
id: "maxSameAccountWait",
|
|
18798
|
+
label: waitLabel,
|
|
18799
|
+
choices: waitChoices,
|
|
18800
|
+
value: wait2
|
|
18801
|
+
}
|
|
18802
|
+
],
|
|
18803
|
+
run: async ({ values }) => {
|
|
18804
|
+
const value = String(values.maxSameAccountWait);
|
|
18805
|
+
const maxSameAccountWait = value === "max" ? "max" : Number(value);
|
|
18806
|
+
await store.updateSettings((settings) => {
|
|
18807
|
+
settings.routing = {
|
|
18808
|
+
...record(settings.routing),
|
|
18809
|
+
maxSameAccountWait
|
|
18810
|
+
};
|
|
18811
|
+
return void 0;
|
|
18812
|
+
}, locks);
|
|
18813
|
+
return `${waitLabel} set to ${waitName(value)}.`;
|
|
18814
|
+
}
|
|
18815
|
+
});
|
|
18816
|
+
}
|
|
18625
18817
|
return {
|
|
18626
18818
|
id: "routing",
|
|
18627
18819
|
slot: "routing",
|
|
@@ -21686,9 +21878,144 @@ var init_shutdown = __esm({
|
|
|
21686
21878
|
}
|
|
21687
21879
|
});
|
|
21688
21880
|
|
|
21881
|
+
// ../core/dist/common-auth-embedded/claustrum/usage.js
|
|
21882
|
+
import { ClaustrumCredentialError as ClaustrumCredentialError3 } from "@cortexkit/claustrum-client";
|
|
21883
|
+
function plain(value) {
|
|
21884
|
+
return value !== null && typeof value === "object" && (Object.getPrototypeOf(value) === Object.prototype || Object.getPrototypeOf(value) === null);
|
|
21885
|
+
}
|
|
21886
|
+
var ScopedUsageReporter;
|
|
21887
|
+
var init_usage = __esm({
|
|
21888
|
+
"../core/dist/common-auth-embedded/claustrum/usage.js"() {
|
|
21889
|
+
"use strict";
|
|
21890
|
+
ScopedUsageReporter = class {
|
|
21891
|
+
options;
|
|
21892
|
+
#queue = /* @__PURE__ */ new Map();
|
|
21893
|
+
#latest = /* @__PURE__ */ new Map();
|
|
21894
|
+
#errors = /* @__PURE__ */ new Set();
|
|
21895
|
+
#timer;
|
|
21896
|
+
#running;
|
|
21897
|
+
#closing = false;
|
|
21898
|
+
#stopped = false;
|
|
21899
|
+
#dropped = 0;
|
|
21900
|
+
constructor(options) {
|
|
21901
|
+
this.options = options;
|
|
21902
|
+
}
|
|
21903
|
+
state() {
|
|
21904
|
+
return {
|
|
21905
|
+
pending: this.#queue.size,
|
|
21906
|
+
inFlight: this.#running !== void 0,
|
|
21907
|
+
dropped: this.#dropped
|
|
21908
|
+
};
|
|
21909
|
+
}
|
|
21910
|
+
report(credentialId, reading) {
|
|
21911
|
+
if (this.#closing || !this.options.client.reportUsageScoped)
|
|
21912
|
+
return;
|
|
21913
|
+
try {
|
|
21914
|
+
if (!this.options.owns(credentialId)) {
|
|
21915
|
+
this.#dropped++;
|
|
21916
|
+
return;
|
|
21917
|
+
}
|
|
21918
|
+
if (!plain(reading) || "credentialId" in reading || "vouched" in reading)
|
|
21919
|
+
throw new Error("invalid reading");
|
|
21920
|
+
const json = JSON.stringify(reading);
|
|
21921
|
+
if (Buffer.byteLength(json, "utf8") > 15360)
|
|
21922
|
+
throw new Error("oversized reading");
|
|
21923
|
+
const copy = JSON.parse(json);
|
|
21924
|
+
if (!plain(copy) || "credentialId" in copy || "vouched" in copy || typeof copy.observedAtMs !== "number" || !Number.isFinite(copy.observedAtMs))
|
|
21925
|
+
throw new Error("invalid reading");
|
|
21926
|
+
if (copy.observedAtMs <= (this.#latest.get(credentialId) ?? -Infinity)) {
|
|
21927
|
+
this.#dropped++;
|
|
21928
|
+
return;
|
|
21929
|
+
}
|
|
21930
|
+
if (this.#queue.has(credentialId))
|
|
21931
|
+
this.#dropped++;
|
|
21932
|
+
this.#latest.set(credentialId, copy.observedAtMs);
|
|
21933
|
+
this.#queue.set(credentialId, copy);
|
|
21934
|
+
if (!this.#timer && !this.#running) {
|
|
21935
|
+
this.#timer = this.options.setTimeout(() => {
|
|
21936
|
+
this.#timer = void 0;
|
|
21937
|
+
this.#flush();
|
|
21938
|
+
}, 1e3);
|
|
21939
|
+
this.#timer.unref?.();
|
|
21940
|
+
}
|
|
21941
|
+
} catch {
|
|
21942
|
+
this.#dropped++;
|
|
21943
|
+
}
|
|
21944
|
+
}
|
|
21945
|
+
forget(credentialId) {
|
|
21946
|
+
if (this.#queue.delete(credentialId))
|
|
21947
|
+
this.#dropped++;
|
|
21948
|
+
this.#latest.delete(credentialId);
|
|
21949
|
+
}
|
|
21950
|
+
#flush() {
|
|
21951
|
+
if (this.#running || !this.#queue.size || this.#stopped)
|
|
21952
|
+
return this.#running;
|
|
21953
|
+
const running = Promise.resolve().then(async () => {
|
|
21954
|
+
while (!this.#stopped && this.#queue.size) {
|
|
21955
|
+
const entry = this.#queue.entries().next().value;
|
|
21956
|
+
if (!entry)
|
|
21957
|
+
break;
|
|
21958
|
+
const [credentialId, reading] = entry;
|
|
21959
|
+
this.#queue.delete(credentialId);
|
|
21960
|
+
try {
|
|
21961
|
+
const enrollmentToken = await this.options.token();
|
|
21962
|
+
if (this.#stopped || !this.options.owns(credentialId)) {
|
|
21963
|
+
if (!this.#stopped)
|
|
21964
|
+
this.#dropped++;
|
|
21965
|
+
continue;
|
|
21966
|
+
}
|
|
21967
|
+
await this.options.client.reportUsageScoped?.({
|
|
21968
|
+
credentialId,
|
|
21969
|
+
reading,
|
|
21970
|
+
enrollmentToken
|
|
21971
|
+
});
|
|
21972
|
+
} catch (error) {
|
|
21973
|
+
if (!this.#stopped)
|
|
21974
|
+
this.#dropped++;
|
|
21975
|
+
this.#log(error);
|
|
21976
|
+
}
|
|
21977
|
+
}
|
|
21978
|
+
});
|
|
21979
|
+
this.#running = running;
|
|
21980
|
+
void running.finally(() => {
|
|
21981
|
+
this.#running = void 0;
|
|
21982
|
+
});
|
|
21983
|
+
return running;
|
|
21984
|
+
}
|
|
21985
|
+
#log(error) {
|
|
21986
|
+
let code2 = "transport_error";
|
|
21987
|
+
try {
|
|
21988
|
+
if (error instanceof ClaustrumCredentialError3)
|
|
21989
|
+
code2 = /^[a-z][a-z0-9_]{0,63}$/.test(error.code) ? error.code : code2;
|
|
21990
|
+
if (this.#errors.has(code2))
|
|
21991
|
+
return;
|
|
21992
|
+
this.#errors.add(code2);
|
|
21993
|
+
this.options.logger.debug("claustrum usage report dropped", { code: code2 });
|
|
21994
|
+
} catch {
|
|
21995
|
+
}
|
|
21996
|
+
}
|
|
21997
|
+
/** Start the final flush; the custody's existing shutdown drain bounds it. */
|
|
21998
|
+
close() {
|
|
21999
|
+
this.#closing = true;
|
|
22000
|
+
if (this.#timer)
|
|
22001
|
+
this.options.clearTimeout(this.#timer);
|
|
22002
|
+
this.#timer = void 0;
|
|
22003
|
+
return this.#flush();
|
|
22004
|
+
}
|
|
22005
|
+
drop() {
|
|
22006
|
+
this.#stopped = true;
|
|
22007
|
+
this.#dropped += this.#queue.size + (this.#running ? 1 : 0);
|
|
22008
|
+
this.#running = void 0;
|
|
22009
|
+
this.#queue.clear();
|
|
22010
|
+
this.#latest.clear();
|
|
22011
|
+
}
|
|
22012
|
+
};
|
|
22013
|
+
}
|
|
22014
|
+
});
|
|
22015
|
+
|
|
21689
22016
|
// ../core/dist/common-auth-embedded/claustrum/custody.js
|
|
21690
22017
|
import { channel } from "node:diagnostics_channel";
|
|
21691
|
-
import { ClaustrumCredentialError as
|
|
22018
|
+
import { ClaustrumCredentialError as ClaustrumCredentialError4 } from "@cortexkit/claustrum-client";
|
|
21692
22019
|
function isScopedCredentialRotation(served, current) {
|
|
21693
22020
|
return current !== void 0 && !current.fromKeptReceipt && !served.fromKeptReceipt && current.credentialId === served.credentialId && current.accountIdentity === served.accountIdentity && current.recordVersion !== served.recordVersion;
|
|
21694
22021
|
}
|
|
@@ -21703,6 +22030,12 @@ function scopedRetryReason(served, current) {
|
|
|
21703
22030
|
return "version-unchanged";
|
|
21704
22031
|
return "rotated";
|
|
21705
22032
|
}
|
|
22033
|
+
function checkedEnrollmentToken(value) {
|
|
22034
|
+
if (!/^[0-9a-f]{64}$/.test(value.token) || !Number.isSafeInteger(value.token_generation) || value.token_generation < 1) {
|
|
22035
|
+
throw new ClaustrumConsumerError("invalid-token", "Invalid Claustrum enrollment token");
|
|
22036
|
+
}
|
|
22037
|
+
return value.token;
|
|
22038
|
+
}
|
|
21706
22039
|
function decideScopedRetryAfter401(site, served, current, logger3 = defaultLogger) {
|
|
21707
22040
|
const retry = isScopedCredentialRotation(served, current);
|
|
21708
22041
|
logger3.debug("scoped 401 re-authorized", {
|
|
@@ -21811,6 +22144,7 @@ var init_custody = __esm({
|
|
|
21811
22144
|
init_errors2();
|
|
21812
22145
|
init_host_slot();
|
|
21813
22146
|
init_shutdown();
|
|
22147
|
+
init_usage();
|
|
21814
22148
|
init_watch();
|
|
21815
22149
|
defaultLogger = createLogger2("claustrum");
|
|
21816
22150
|
phaseDiagnostics = channel("common-auth.claustrum.phases");
|
|
@@ -21828,6 +22162,8 @@ var init_custody = __esm({
|
|
|
21828
22162
|
#reports = /* @__PURE__ */ new WeakMap();
|
|
21829
22163
|
#kept = /* @__PURE__ */ new Map();
|
|
21830
22164
|
#keptAttempts = /* @__PURE__ */ new WeakMap();
|
|
22165
|
+
#usage;
|
|
22166
|
+
#usageServed = /* @__PURE__ */ new Map();
|
|
21831
22167
|
#setTimeout;
|
|
21832
22168
|
#clearTimeout;
|
|
21833
22169
|
#outage = false;
|
|
@@ -21842,6 +22178,7 @@ var init_custody = __esm({
|
|
|
21842
22178
|
#watches = /* @__PURE__ */ new Set();
|
|
21843
22179
|
#tokenReads = /* @__PURE__ */ new Set();
|
|
21844
22180
|
#warnShutdown;
|
|
22181
|
+
#onDrainTimeout;
|
|
21845
22182
|
#disposing;
|
|
21846
22183
|
constructor(options) {
|
|
21847
22184
|
const tokenPath = options.tokenPath;
|
|
@@ -21861,13 +22198,21 @@ var init_custody = __esm({
|
|
|
21861
22198
|
this.#warnShutdown = shutdownWarning(this.#logger);
|
|
21862
22199
|
this.#setTimeout = options.setTimeoutImpl ?? setTimeout;
|
|
21863
22200
|
this.#clearTimeout = options.clearTimeoutImpl ?? clearTimeout;
|
|
22201
|
+
this.#usage = new ScopedUsageReporter({
|
|
22202
|
+
client: this.#client,
|
|
22203
|
+
owns: (id) => this.#usageServed.has(id),
|
|
22204
|
+
token: async () => checkedEnrollmentToken(await this.#readToken()),
|
|
22205
|
+
logger: this.#logger,
|
|
22206
|
+
setTimeout: this.#setTimeout,
|
|
22207
|
+
clearTimeout: this.#clearTimeout
|
|
22208
|
+
});
|
|
21864
22209
|
}
|
|
21865
22210
|
/** A watch losing its transport is the same outage as an unreachable read. */
|
|
21866
22211
|
transportLost(error) {
|
|
21867
22212
|
if (this.#closed || this.#outage)
|
|
21868
22213
|
return;
|
|
21869
22214
|
this.#outage = true;
|
|
21870
|
-
this.#outageError = error instanceof
|
|
22215
|
+
this.#outageError = error instanceof ClaustrumCredentialError4 ? error : new ClaustrumUnreachableError();
|
|
21871
22216
|
this.#logger.warn("serving kept vault receipt", { reason: "unreachable" });
|
|
21872
22217
|
this.#scheduleProbe();
|
|
21873
22218
|
}
|
|
@@ -21936,10 +22281,7 @@ var init_custody = __esm({
|
|
|
21936
22281
|
});
|
|
21937
22282
|
}
|
|
21938
22283
|
this.#check(signal);
|
|
21939
|
-
|
|
21940
|
-
throw new ClaustrumConsumerError("invalid-token", "Invalid Claustrum enrollment token");
|
|
21941
|
-
}
|
|
21942
|
-
return value.token;
|
|
22284
|
+
return checkedEnrollmentToken(value);
|
|
21943
22285
|
}
|
|
21944
22286
|
async #call(operation, signal) {
|
|
21945
22287
|
this.#check(signal);
|
|
@@ -21963,7 +22305,7 @@ var init_custody = __esm({
|
|
|
21963
22305
|
this.transportLost(error);
|
|
21964
22306
|
else
|
|
21965
22307
|
this.reachable();
|
|
21966
|
-
if (error instanceof
|
|
22308
|
+
if (error instanceof ClaustrumCredentialError4)
|
|
21967
22309
|
throw error;
|
|
21968
22310
|
if (classifyVaultFailure(error) === "unreachable")
|
|
21969
22311
|
throw new ClaustrumUnreachableError();
|
|
@@ -21993,6 +22335,7 @@ var init_custody = __esm({
|
|
|
21993
22335
|
token = await this.#token(signal);
|
|
21994
22336
|
} catch (error) {
|
|
21995
22337
|
this.#kept.clear();
|
|
22338
|
+
this.#clearUsageOwnership();
|
|
21996
22339
|
throw error;
|
|
21997
22340
|
}
|
|
21998
22341
|
if (phaseDiagnostics.hasSubscribers)
|
|
@@ -22094,11 +22437,19 @@ var init_custody = __esm({
|
|
|
22094
22437
|
else {
|
|
22095
22438
|
this.reachable();
|
|
22096
22439
|
this.#kept.clear();
|
|
22440
|
+
this.#clearUsageOwnership();
|
|
22097
22441
|
}
|
|
22098
22442
|
}
|
|
22099
22443
|
/** Discard bearer material when a route is removed, declined or rebound. */
|
|
22100
22444
|
forget(credentialId) {
|
|
22101
22445
|
this.#kept.delete(credentialId);
|
|
22446
|
+
this.#usageServed.delete(credentialId);
|
|
22447
|
+
this.#usage.forget(credentialId);
|
|
22448
|
+
}
|
|
22449
|
+
#clearUsageOwnership() {
|
|
22450
|
+
for (const id of this.#usageServed.keys())
|
|
22451
|
+
this.#usage.forget(id);
|
|
22452
|
+
this.#usageServed.clear();
|
|
22102
22453
|
}
|
|
22103
22454
|
/** Apply an already-held roster; this never fetches credentials or writes it. */
|
|
22104
22455
|
retain(identities) {
|
|
@@ -22108,6 +22459,11 @@ var init_custody = __esm({
|
|
|
22108
22459
|
if (!identity3?.enabled || identity3.state !== "active" || identity3.credentialType !== kept.attempt.credentialType || identity3.accountIdentity !== kept.attempt.expectedAccountIdentity)
|
|
22109
22460
|
this.forget(id);
|
|
22110
22461
|
}
|
|
22462
|
+
for (const [id, served] of this.#usageServed) {
|
|
22463
|
+
const identity3 = current.get(id);
|
|
22464
|
+
if (!identity3?.enabled || identity3.state !== "active" || identity3.credentialType !== served.credentialType || identity3.accountIdentity !== served.accountIdentity)
|
|
22465
|
+
this.forget(id);
|
|
22466
|
+
}
|
|
22111
22467
|
}
|
|
22112
22468
|
/** A frozen, non-secret summary for a plugin's status display. */
|
|
22113
22469
|
keptReceiptState() {
|
|
@@ -22139,6 +22495,7 @@ var init_custody = __esm({
|
|
|
22139
22495
|
token = await this.#token(signal);
|
|
22140
22496
|
} catch (error) {
|
|
22141
22497
|
this.#kept.clear();
|
|
22498
|
+
this.#clearUsageOwnership();
|
|
22142
22499
|
throw error;
|
|
22143
22500
|
}
|
|
22144
22501
|
if (this.#outage && kept) {
|
|
@@ -22148,6 +22505,7 @@ var init_custody = __esm({
|
|
|
22148
22505
|
try {
|
|
22149
22506
|
const attempt = await this.#authorizeFresh({ credentialId, credentialType, accountIdentity }, token, signal);
|
|
22150
22507
|
this.#kept.set(credentialId, { attempt, routeId, since: null });
|
|
22508
|
+
this.#usageServed.set(credentialId, { ...identity3 });
|
|
22151
22509
|
return attempt;
|
|
22152
22510
|
} catch (error) {
|
|
22153
22511
|
this.#check(signal);
|
|
@@ -22332,6 +22690,23 @@ var init_custody = __esm({
|
|
|
22332
22690
|
}
|
|
22333
22691
|
};
|
|
22334
22692
|
}
|
|
22693
|
+
/**
|
|
22694
|
+
* Queue reply quota metadata and return synchronously. Pass rate-limit
|
|
22695
|
+
* headers only, never tokens: the library does not filter header names.
|
|
22696
|
+
* Only credentials served by this custody and retained in its roster report.
|
|
22697
|
+
* Hosts managing their own roster must call retain() when that roster changes.
|
|
22698
|
+
*/
|
|
22699
|
+
reportUsage(input2) {
|
|
22700
|
+
if (this.#closed)
|
|
22701
|
+
return;
|
|
22702
|
+
try {
|
|
22703
|
+
this.#usage.report(input2.credentialId, input2.reading);
|
|
22704
|
+
} catch {
|
|
22705
|
+
}
|
|
22706
|
+
}
|
|
22707
|
+
usageReportState() {
|
|
22708
|
+
return this.#usage.state();
|
|
22709
|
+
}
|
|
22335
22710
|
close() {
|
|
22336
22711
|
if (this.#closed)
|
|
22337
22712
|
return;
|
|
@@ -22343,12 +22718,23 @@ var init_custody = __esm({
|
|
|
22343
22718
|
watch.stop();
|
|
22344
22719
|
this.#watches.clear();
|
|
22345
22720
|
this.#kept.clear();
|
|
22346
|
-
this.#
|
|
22721
|
+
const usage = this.#usage.close();
|
|
22722
|
+
if (usage) {
|
|
22723
|
+
this.#tokenReads.add(usage);
|
|
22724
|
+
void usage.then(() => this.#tokenReads.delete(usage));
|
|
22725
|
+
} else
|
|
22726
|
+
this.#client.close();
|
|
22727
|
+
this.#disposing = drainShutdown(this.#tokenReads, (count3) => (this.#onDrainTimeout ?? this.#warnShutdown)(count3)).finally(() => {
|
|
22728
|
+
this.#usage.drop();
|
|
22729
|
+
this.#usageServed.clear();
|
|
22730
|
+
if (usage)
|
|
22731
|
+
this.#client.close();
|
|
22732
|
+
});
|
|
22347
22733
|
}
|
|
22348
|
-
/** Stop
|
|
22734
|
+
/** Stop accepting work; give token reads and reply reports one shared 2 s drain. */
|
|
22349
22735
|
async dispose(onTimeout = this.#warnShutdown) {
|
|
22736
|
+
this.#onDrainTimeout = onTimeout;
|
|
22350
22737
|
this.close();
|
|
22351
|
-
this.#disposing ??= drainShutdown(this.#tokenReads, onTimeout);
|
|
22352
22738
|
await this.#disposing;
|
|
22353
22739
|
}
|
|
22354
22740
|
};
|
|
@@ -22589,6 +22975,7 @@ function projectVaultRoster(previous, inventory, options = {}) {
|
|
|
22589
22975
|
return {
|
|
22590
22976
|
version: 1,
|
|
22591
22977
|
view: inventory.view,
|
|
22978
|
+
...previous?.limits !== void 0 && { limits: previous.limits },
|
|
22592
22979
|
complete,
|
|
22593
22980
|
...!complete && {
|
|
22594
22981
|
rejected: inventory.skipped.map((record3) => ({
|
|
@@ -22659,6 +23046,7 @@ function decodeRoster(value) {
|
|
|
22659
23046
|
// that was used whole, so it reads as complete.
|
|
22660
23047
|
complete: value.complete !== false,
|
|
22661
23048
|
...rejected && { rejected },
|
|
23049
|
+
...value.limits !== void 0 && { limits: value.limits },
|
|
22662
23050
|
rows,
|
|
22663
23051
|
declined
|
|
22664
23052
|
};
|
|
@@ -23870,6 +24258,33 @@ var init_consumer = __esm({
|
|
|
23870
24258
|
combined.dispose();
|
|
23871
24259
|
}
|
|
23872
24260
|
}
|
|
24261
|
+
/**
|
|
24262
|
+
* Queue reply quota metadata without waiting or throwing. Pass rate-limit
|
|
24263
|
+
* headers only, never tokens: the library does not filter header names.
|
|
24264
|
+
* The credential must have been served by this host and still belong to the route.
|
|
24265
|
+
*/
|
|
24266
|
+
reportUsage(input2) {
|
|
24267
|
+
if (this.#shutdown.signal.aborted)
|
|
24268
|
+
return;
|
|
24269
|
+
try {
|
|
24270
|
+
const row = this.#roster?.rows.find((row2) => row2.routeId === input2.routeId);
|
|
24271
|
+
if (!row?.enabled || row.state !== "active" || row.credentialId !== input2.credentialId && !row.aliases?.includes(input2.credentialId))
|
|
24272
|
+
return;
|
|
24273
|
+
if (this.#hub) {
|
|
24274
|
+
if (this.#lease && this.#hub.leaseLive(this.#lease))
|
|
24275
|
+
this.#lease.custody.reportUsage(input2);
|
|
24276
|
+
} else
|
|
24277
|
+
this.#custody?.reportUsage(input2);
|
|
24278
|
+
} catch {
|
|
24279
|
+
}
|
|
24280
|
+
}
|
|
24281
|
+
usageReportState() {
|
|
24282
|
+
try {
|
|
24283
|
+
return (this.#hub ? this.#lease?.custody : this.#custody)?.usageReportState() ?? { pending: 0, inFlight: false, dropped: 0 };
|
|
24284
|
+
} catch {
|
|
24285
|
+
return { pending: 0, inFlight: false, dropped: 0 };
|
|
24286
|
+
}
|
|
24287
|
+
}
|
|
23873
24288
|
async reportFailure(attempt, status, source) {
|
|
23874
24289
|
this.#assertOpen();
|
|
23875
24290
|
if (this.#hub) {
|
|
@@ -24481,6 +24896,14 @@ var init_hub = __esm({
|
|
|
24481
24896
|
check();
|
|
24482
24897
|
return custody.reportFailure(attempt, status, source);
|
|
24483
24898
|
},
|
|
24899
|
+
reportUsage: (input2) => {
|
|
24900
|
+
if (!state.released && !generation.ended)
|
|
24901
|
+
custody.reportUsage(input2);
|
|
24902
|
+
},
|
|
24903
|
+
usageReportState: () => {
|
|
24904
|
+
check();
|
|
24905
|
+
return custody.usageReportState();
|
|
24906
|
+
},
|
|
24484
24907
|
forget: (credentialId) => {
|
|
24485
24908
|
check();
|
|
24486
24909
|
custody.forget(credentialId);
|
|
@@ -25024,7 +25447,7 @@ __export(claustrum_exports, {
|
|
|
25024
25447
|
ChangeNoticeReader: () => ChangeNoticeReader,
|
|
25025
25448
|
ClaustrumConsumer: () => ClaustrumConsumer,
|
|
25026
25449
|
ClaustrumConsumerError: () => ClaustrumConsumerError,
|
|
25027
|
-
ClaustrumCredentialError: () =>
|
|
25450
|
+
ClaustrumCredentialError: () => ClaustrumCredentialError5,
|
|
25028
25451
|
ClaustrumDiscoveryHub: () => ClaustrumDiscoveryHub,
|
|
25029
25452
|
ClaustrumEnrollmentManager: () => ClaustrumEnrollmentManager,
|
|
25030
25453
|
ClaustrumScopedCustody: () => ClaustrumScopedCustody,
|
|
@@ -25081,7 +25504,7 @@ __export(claustrum_exports, {
|
|
|
25081
25504
|
vaultRoutingRows: () => vaultRoutingRows
|
|
25082
25505
|
});
|
|
25083
25506
|
import { ClaustrumClient } from "@cortexkit/claustrum-client";
|
|
25084
|
-
import { ClaustrumCredentialError as
|
|
25507
|
+
import { ClaustrumCredentialError as ClaustrumCredentialError5 } from "@cortexkit/claustrum-client";
|
|
25085
25508
|
async function connectClaustrumScopedClient(options) {
|
|
25086
25509
|
const { connectTimeoutMs, ...client } = options;
|
|
25087
25510
|
const limit = connectTimeoutMs ?? SCOPED_CONNECT_TIMEOUT_MS;
|
|
@@ -28988,6 +29411,9 @@ function loadBackend2() {
|
|
|
28988
29411
|
});
|
|
28989
29412
|
return backend2;
|
|
28990
29413
|
}
|
|
29414
|
+
function isWindowsSharingViolation2(error) {
|
|
29415
|
+
return windowsPrivateFiles2 && error instanceof PrivateFileError2 && error.reason === "io-error" && (error.win32Code === 32 || error.win32Code === 303);
|
|
29416
|
+
}
|
|
28991
29417
|
async function privateOperation2(path5, stage, operation) {
|
|
28992
29418
|
try {
|
|
28993
29419
|
return await operation();
|
|
@@ -32326,7 +32752,8 @@ async function removeOldCopies(location, files, present6, layoutLock, input2) {
|
|
|
32326
32752
|
if (!await unlinkIfIdentical(
|
|
32327
32753
|
file,
|
|
32328
32754
|
location.stateHomeDir,
|
|
32329
|
-
() => beforeRemove(file.old, layoutLock, input2.steps)
|
|
32755
|
+
() => beforeRemove(file.old, layoutLock, input2.steps),
|
|
32756
|
+
input2.steps?.oldFileIO
|
|
32330
32757
|
))
|
|
32331
32758
|
kept.push(file.old);
|
|
32332
32759
|
}
|
|
@@ -32348,21 +32775,21 @@ async function sameBytes(a, b) {
|
|
|
32348
32775
|
return false;
|
|
32349
32776
|
}
|
|
32350
32777
|
}
|
|
32351
|
-
function isWindowsSharingError(error) {
|
|
32778
|
+
function isWindowsSharingError(error, platform) {
|
|
32352
32779
|
const code2 = error?.code;
|
|
32353
|
-
return
|
|
32780
|
+
return platform === "win32" && (code2 === "EBUSY" || code2 === "EPERM" || code2 === "EACCES");
|
|
32354
32781
|
}
|
|
32355
|
-
async function unlinkIfIdentical(file, stateDir, guard) {
|
|
32782
|
+
async function unlinkIfIdentical(file, stateDir, guard, io = { platform: process.platform, readFile: readFile12, unlink: unlink10 }) {
|
|
32356
32783
|
const started = performance.now();
|
|
32357
32784
|
for (const delay3 of SHARING_RETRY_DELAYS_MS) {
|
|
32358
32785
|
if (delay3 > 0) await new Promise((done) => setTimeout(done, delay3));
|
|
32359
32786
|
let same;
|
|
32360
32787
|
try {
|
|
32361
|
-
same = (await
|
|
32788
|
+
same = (await io.readFile(file.old)).equals(await io.readFile(file.next));
|
|
32362
32789
|
} catch (error) {
|
|
32363
32790
|
if (error.code === "ENOENT" && !await exists2(file.old))
|
|
32364
32791
|
return true;
|
|
32365
|
-
if (isWindowsSharingError(error)) {
|
|
32792
|
+
if (isWindowsSharingError(error, io.platform)) {
|
|
32366
32793
|
if (performance.now() - started >= SHARING_RETRY_BUDGET_MS) return false;
|
|
32367
32794
|
continue;
|
|
32368
32795
|
}
|
|
@@ -32371,11 +32798,11 @@ async function unlinkIfIdentical(file, stateDir, guard) {
|
|
|
32371
32798
|
if (!same) throw credentialConflict(stateDir, file);
|
|
32372
32799
|
await guard();
|
|
32373
32800
|
try {
|
|
32374
|
-
await
|
|
32801
|
+
await io.unlink(file.old);
|
|
32375
32802
|
return true;
|
|
32376
32803
|
} catch (error) {
|
|
32377
32804
|
if (error.code === "ENOENT") return true;
|
|
32378
|
-
if (!isWindowsSharingError(error) || performance.now() - started >= SHARING_RETRY_BUDGET_MS)
|
|
32805
|
+
if (!isWindowsSharingError(error, io.platform) || performance.now() - started >= SHARING_RETRY_BUDGET_MS)
|
|
32379
32806
|
return false;
|
|
32380
32807
|
}
|
|
32381
32808
|
}
|
|
@@ -34144,9 +34571,6 @@ async function registerOpenCode2AuthMethods(ctx, options) {
|
|
|
34144
34571
|
});
|
|
34145
34572
|
}
|
|
34146
34573
|
|
|
34147
|
-
// src/common-auth-embedded/opencode2/install.js
|
|
34148
|
-
var MAX_RETRY_HOLD_MS = 20 * 60 * 1e3;
|
|
34149
|
-
|
|
34150
34574
|
// src/plugin/ga-location-services.ts
|
|
34151
34575
|
init_dist();
|
|
34152
34576
|
init_vault_folder();
|
|
@@ -44666,17 +45090,20 @@ async function retainResponseLifetime(response, cancellation) {
|
|
|
44666
45090
|
|
|
44667
45091
|
// src/plugin/shared/request-services.ts
|
|
44668
45092
|
init_dist();
|
|
45093
|
+
import { createHash as createHash17 } from "node:crypto";
|
|
44669
45094
|
|
|
44670
|
-
// src/common-auth-embedded/routing-accessor/
|
|
44671
|
-
function isObject2(value) {
|
|
44672
|
-
return typeof value === "object" && value !== null;
|
|
44673
|
-
}
|
|
45095
|
+
// src/common-auth-embedded/routing-accessor/handle.js
|
|
44674
45096
|
function routingHandle(sessionId) {
|
|
44675
45097
|
const routing = Reflect.get(globalThis, /* @__PURE__ */ Symbol.for("cortexkit.routing"));
|
|
44676
45098
|
if (typeof routing !== "function")
|
|
44677
45099
|
return void 0;
|
|
44678
45100
|
const handle = routing(sessionId);
|
|
44679
|
-
return
|
|
45101
|
+
return typeof handle === "object" && handle !== null ? handle : void 0;
|
|
45102
|
+
}
|
|
45103
|
+
|
|
45104
|
+
// src/common-auth-embedded/routing-accessor/index.js
|
|
45105
|
+
function isObject2(value) {
|
|
45106
|
+
return typeof value === "object" && value !== null;
|
|
44680
45107
|
}
|
|
44681
45108
|
function selectionFor(answer, candidates) {
|
|
44682
45109
|
if (!isObject2(answer))
|
|
@@ -44713,7 +45140,15 @@ async function askRouting(input2) {
|
|
|
44713
45140
|
timer = setTimeout(() => resolve28(void 0), deadlineMs);
|
|
44714
45141
|
timer.unref();
|
|
44715
45142
|
});
|
|
44716
|
-
const
|
|
45143
|
+
const request = {
|
|
45144
|
+
provider: input2.provider,
|
|
45145
|
+
modelId: input2.modelId
|
|
45146
|
+
};
|
|
45147
|
+
const cap = input2.holdWaitMaxS;
|
|
45148
|
+
if (typeof cap === "number" && Number.isFinite(cap)) {
|
|
45149
|
+
request.hold_wait_max_s = Math.max(0, Math.floor(cap));
|
|
45150
|
+
}
|
|
45151
|
+
const pending = accountFor.call(handle, request, { deadlineMs });
|
|
44717
45152
|
if (!isObject2(pending) || typeof pending.then !== "function")
|
|
44718
45153
|
return void 0;
|
|
44719
45154
|
const answer = await Promise.race([pending, expired]);
|
|
@@ -44745,7 +45180,7 @@ function reportRouting(input2) {
|
|
|
44745
45180
|
const { window, pool } = input2;
|
|
44746
45181
|
if (window !== "5h" && window !== "7d")
|
|
44747
45182
|
return;
|
|
44748
|
-
if (pool !== void 0 && (typeof pool !== "string" ||
|
|
45183
|
+
if (pool !== void 0 && (typeof pool !== "string" || !/^[a-z0-9._-]{1,64}$/.test(pool)))
|
|
44749
45184
|
return;
|
|
44750
45185
|
payload = {
|
|
44751
45186
|
...identity3,
|
|
@@ -45492,6 +45927,7 @@ function isPrimaryVaultRequest(kind, headers) {
|
|
|
45492
45927
|
|
|
45493
45928
|
// src/plugin/shared/request-services.ts
|
|
45494
45929
|
var FIRST_RETRY_DELAY_MS = 1e3;
|
|
45930
|
+
var MODEL_UNAVAILABLE_TTL_MS = 60 * 60 * 1e3;
|
|
45495
45931
|
function prepareAgyWireRequest(wire, request) {
|
|
45496
45932
|
return wire.prepare(
|
|
45497
45933
|
request.input,
|
|
@@ -45651,6 +46087,84 @@ function createRequestExecutor(deps) {
|
|
|
45651
46087
|
} = deps;
|
|
45652
46088
|
const retryState = createRetryState();
|
|
45653
46089
|
const warmupState = createWarmupState();
|
|
46090
|
+
const modelAvailabilityNow = deps.modelAvailabilityNow ?? Date.now;
|
|
46091
|
+
const unavailableModels = /* @__PURE__ */ new Map();
|
|
46092
|
+
const accountKey = (account) => {
|
|
46093
|
+
if (credentials.domain === "vault") {
|
|
46094
|
+
const route = account.route;
|
|
46095
|
+
return route ? JSON.stringify([
|
|
46096
|
+
"vault",
|
|
46097
|
+
route.routeId,
|
|
46098
|
+
route.credentialId,
|
|
46099
|
+
route.accountIdentity
|
|
46100
|
+
]) : account;
|
|
46101
|
+
}
|
|
46102
|
+
if (account.ref) {
|
|
46103
|
+
const ref = account.ref;
|
|
46104
|
+
return JSON.stringify([
|
|
46105
|
+
"local",
|
|
46106
|
+
ref.id,
|
|
46107
|
+
ref.credentialEpoch,
|
|
46108
|
+
ref.identity
|
|
46109
|
+
]);
|
|
46110
|
+
}
|
|
46111
|
+
const refresh = credentials.toAuthDetails(account).refresh;
|
|
46112
|
+
return JSON.stringify([
|
|
46113
|
+
"pool-file",
|
|
46114
|
+
account.email?.toLowerCase(),
|
|
46115
|
+
createHash17("sha256").update(parseRefreshParts(refresh).refreshToken).digest("hex")
|
|
46116
|
+
]);
|
|
46117
|
+
};
|
|
46118
|
+
const tierOf2 = (account) => JSON.stringify([account.capturedTierId, account.capturedPaidTierId]);
|
|
46119
|
+
const dropModel = (key, model, cause) => {
|
|
46120
|
+
const entries = unavailableModels.get(key);
|
|
46121
|
+
const entry = entries?.get(model);
|
|
46122
|
+
if (!entries || !entry) return;
|
|
46123
|
+
log17.debug("model-unavailable-memory-drop", {
|
|
46124
|
+
account: entry.label,
|
|
46125
|
+
model,
|
|
46126
|
+
cause
|
|
46127
|
+
});
|
|
46128
|
+
entries.delete(model);
|
|
46129
|
+
if (entries.size === 0) unavailableModels.delete(key);
|
|
46130
|
+
};
|
|
46131
|
+
const rememberedIndexes = (model) => {
|
|
46132
|
+
const rows = accountManager.getAccounts();
|
|
46133
|
+
const live = new Map(rows.map((row) => [accountKey(row), row]));
|
|
46134
|
+
const indexes = /* @__PURE__ */ new Set();
|
|
46135
|
+
for (const [key, entries] of unavailableModels) {
|
|
46136
|
+
const row = live.get(key);
|
|
46137
|
+
for (const [exactModel, entry] of entries) {
|
|
46138
|
+
const cause = !row ? "identity-replaced" : modelAvailabilityNow() - entry.recordedAt >= MODEL_UNAVAILABLE_TTL_MS ? "expired" : row.cachedQuotaUpdatedAt !== void 0 && row.cachedQuota?.["gemini-argon"] !== void 0 && (!entry.argonPool || row.cachedQuotaUpdatedAt !== entry.quotaUpdatedAt) ? "argon-pool" : row.cachedQuotaUpdatedAt !== void 0 && row.cachedQuotaUpdatedAt !== entry.quotaUpdatedAt ? "quota-reading" : tierOf2(row) !== entry.tier ? "tier-changed" : void 0;
|
|
46139
|
+
if (cause) dropModel(key, exactModel, cause);
|
|
46140
|
+
else if (row && exactModel === model) indexes.add(row.index);
|
|
46141
|
+
}
|
|
46142
|
+
}
|
|
46143
|
+
return indexes;
|
|
46144
|
+
};
|
|
46145
|
+
const captureAvailability = (account) => ({
|
|
46146
|
+
key: accountKey(account),
|
|
46147
|
+
quotaUpdatedAt: account.cachedQuotaUpdatedAt,
|
|
46148
|
+
tier: tierOf2(account),
|
|
46149
|
+
argonPool: account.cachedQuota?.["gemini-argon"] !== void 0,
|
|
46150
|
+
label: `Account ${account.index + 1}`
|
|
46151
|
+
});
|
|
46152
|
+
const rememberUnavailable = (snapshot2, model) => {
|
|
46153
|
+
const { key, ...entry } = snapshot2;
|
|
46154
|
+
let entries = unavailableModels.get(key);
|
|
46155
|
+
if (!entries) {
|
|
46156
|
+
entries = /* @__PURE__ */ new Map();
|
|
46157
|
+
unavailableModels.set(key, entries);
|
|
46158
|
+
}
|
|
46159
|
+
entries.set(model, {
|
|
46160
|
+
...entry,
|
|
46161
|
+
recordedAt: modelAvailabilityNow()
|
|
46162
|
+
});
|
|
46163
|
+
log17.debug("model-unavailable-memory-record", {
|
|
46164
|
+
account: entry.label,
|
|
46165
|
+
model
|
|
46166
|
+
});
|
|
46167
|
+
};
|
|
45654
46168
|
const shutdown = new AbortController();
|
|
45655
46169
|
const inFlight = /* @__PURE__ */ new Set();
|
|
45656
46170
|
const advisoryWork = /* @__PURE__ */ new Set();
|
|
@@ -45900,11 +46414,15 @@ function createRequestExecutor(deps) {
|
|
|
45900
46414
|
const killedIndexes = eligibleIndexes === null ? void 0 : new Set(
|
|
45901
46415
|
accountManager.getAccounts().map((entry) => entry.index).filter((index) => !eligibleIndexes.has(index))
|
|
45902
46416
|
);
|
|
45903
|
-
|
|
46417
|
+
const unavailableIndexes = /* @__PURE__ */ new Set([
|
|
46418
|
+
...modelUnavailableIndexes,
|
|
46419
|
+
...rememberedIndexes(model)
|
|
46420
|
+
]);
|
|
46421
|
+
if (unavailableIndexes.size > 0) {
|
|
45904
46422
|
const candidates = accountManager.getAccounts().filter(
|
|
45905
46423
|
(entry) => entry.enabled !== false && !entry.accountIneligible && !entry.verificationRequired && (eligibleIndexes === null || eligibleIndexes.has(entry.index))
|
|
45906
46424
|
);
|
|
45907
|
-
if (candidates.length > 0 && candidates.every((entry) =>
|
|
46425
|
+
if (candidates.length > 0 && candidates.every((entry) => unavailableIndexes.has(entry.index))) {
|
|
45908
46426
|
pushDebug(
|
|
45909
46427
|
`model-unavailable: all ${candidates.length} eligible account(s) skipped`
|
|
45910
46428
|
);
|
|
@@ -45919,7 +46437,7 @@ function createRequestExecutor(deps) {
|
|
|
45919
46437
|
});
|
|
45920
46438
|
}
|
|
45921
46439
|
}
|
|
45922
|
-
const excludedIndexes =
|
|
46440
|
+
const excludedIndexes = unavailableIndexes.size === 0 ? killedIndexes : /* @__PURE__ */ new Set([...killedIndexes ?? [], ...unavailableIndexes]);
|
|
45923
46441
|
const routingPresent = credentials.domain === "vault" && hasVaultRoutingAccessor();
|
|
45924
46442
|
const firstPlacement = routingPresent && !routingPlacementConsidered && accountSessionIdentity && !accountManager.getCurrentAccountForFamily(
|
|
45925
46443
|
family,
|
|
@@ -46510,6 +47028,7 @@ function createRequestExecutor(deps) {
|
|
|
46510
47028
|
let tokenConsumed = false;
|
|
46511
47029
|
let physicalAttemptStarted = false;
|
|
46512
47030
|
try {
|
|
47031
|
+
const availabilitySnapshot = captureAvailability(account);
|
|
46513
47032
|
let sendAdmission;
|
|
46514
47033
|
let sendAccessToken;
|
|
46515
47034
|
let sendProjectId;
|
|
@@ -46911,6 +47430,7 @@ function createRequestExecutor(deps) {
|
|
|
46911
47430
|
void response.body?.cancel().catch(() => {
|
|
46912
47431
|
});
|
|
46913
47432
|
modelUnavailableIndexes.add(account.index);
|
|
47433
|
+
if (model) rememberUnavailable(availabilitySnapshot, model);
|
|
46914
47434
|
skippedForModelUnavailable = true;
|
|
46915
47435
|
shouldSwitchAccount = true;
|
|
46916
47436
|
break;
|
|
@@ -47323,6 +47843,9 @@ function createRequestExecutor(deps) {
|
|
|
47323
47843
|
while (advisoryWork.size > 0) await Promise.allSettled([...advisoryWork]);
|
|
47324
47844
|
retryState.dispose();
|
|
47325
47845
|
warmupState.dispose();
|
|
47846
|
+
for (const [key, entries] of unavailableModels) {
|
|
47847
|
+
for (const model of entries.keys()) dropModel(key, model, "disposed");
|
|
47848
|
+
}
|
|
47326
47849
|
})();
|
|
47327
47850
|
return drainPromise;
|
|
47328
47851
|
}
|
|
@@ -47521,9 +48044,9 @@ init_dist();
|
|
|
47521
48044
|
|
|
47522
48045
|
// src/plugin/background-quota-refresh.ts
|
|
47523
48046
|
init_file_lock();
|
|
47524
|
-
import { createHash as
|
|
48047
|
+
import { createHash as createHash18 } from "node:crypto";
|
|
47525
48048
|
function quotaAccountIdentity2(refreshToken) {
|
|
47526
|
-
return
|
|
48049
|
+
return createHash18("sha256").update(refreshToken).digest("hex").slice(0, 16);
|
|
47527
48050
|
}
|
|
47528
48051
|
var MIN_INTERVAL_MS = 6e4;
|
|
47529
48052
|
var STARTUP_JITTER_MS = 3e4;
|
|
@@ -52810,7 +53333,7 @@ function createGaAntigravityPlugin(overrides = {}) {
|
|
|
52810
53333
|
|
|
52811
53334
|
// src/plugin/index.ts
|
|
52812
53335
|
init_dist();
|
|
52813
|
-
import { createHash as
|
|
53336
|
+
import { createHash as createHash24, randomUUID as randomUUID22 } from "node:crypto";
|
|
52814
53337
|
import { join as join39, resolve as resolve27 } from "node:path";
|
|
52815
53338
|
|
|
52816
53339
|
// src/cli.ts
|
|
@@ -53113,11 +53636,11 @@ async function select2(terminal, items, options) {
|
|
|
53113
53636
|
}
|
|
53114
53637
|
|
|
53115
53638
|
// src/common-auth-embedded/claustrum/enrollment.js
|
|
53116
|
-
import { createHash as
|
|
53639
|
+
import { createHash as createHash19, randomBytes as randomBytes6, randomUUID as randomUUID19 } from "node:crypto";
|
|
53117
53640
|
import { constants as fsConstants2 } from "node:fs";
|
|
53118
53641
|
import { chmod as chmod6, mkdir as mkdir15, open as open10, readFile as readFile14, realpath as realpath4, rename as rename12, stat as stat12, unlink as unlink11 } from "node:fs/promises";
|
|
53119
53642
|
import { basename as basename6, dirname as dirname22, extname as extname2, isAbsolute as isAbsolute4, join as join26, resolve as resolve22 } from "node:path";
|
|
53120
|
-
import { ClaustrumCredentialError as
|
|
53643
|
+
import { ClaustrumCredentialError as ClaustrumCredentialError6, ClaustrumClient as ClaustrumWireClient2, writeEnrollmentTokenFile as writeEnrollmentTokenFile2 } from "@cortexkit/claustrum-client";
|
|
53121
53644
|
|
|
53122
53645
|
// src/common-auth-embedded/fs/file-read-cache.js
|
|
53123
53646
|
import { lstat as lstat7 } from "node:fs/promises";
|
|
@@ -53492,37 +54015,83 @@ async function acquireRefreshFileLockWithClock2(options) {
|
|
|
53492
54015
|
await rm6(path5, { recursive: true, force: true }).catch(() => {
|
|
53493
54016
|
});
|
|
53494
54017
|
}
|
|
53495
|
-
|
|
53496
|
-
if (
|
|
53497
|
-
|
|
53498
|
-
|
|
54018
|
+
function isRetryableRemoval(error, path5) {
|
|
54019
|
+
if (!windowsPrivateFiles2 || !(error instanceof PrivateFileError2) || error.stage !== "remove" || error.path !== path5)
|
|
54020
|
+
return false;
|
|
54021
|
+
return isWindowsSharingViolation2(error) || error.win32Code === void 0 && error.reason === void 0 && (error.code === "EBUSY" || error.code === "EPERM");
|
|
53499
54022
|
}
|
|
53500
|
-
async function
|
|
54023
|
+
async function removeOwnedLeaseObject(path5, stillOwned, deadline = performance.now() + EVICT_TTL + 1e3) {
|
|
54024
|
+
let original;
|
|
54025
|
+
let delayMs = 5;
|
|
54026
|
+
while (await stillOwned()) {
|
|
54027
|
+
try {
|
|
54028
|
+
await removeLeaseObject(path5);
|
|
54029
|
+
return;
|
|
54030
|
+
} catch (error) {
|
|
54031
|
+
if (!isRetryableRemoval(error, path5))
|
|
54032
|
+
throw error;
|
|
54033
|
+
original ??= error;
|
|
54034
|
+
}
|
|
54035
|
+
const remainingMs = deadline - performance.now();
|
|
54036
|
+
if (remainingMs <= 0)
|
|
54037
|
+
throw original;
|
|
54038
|
+
await new Promise((resolve28) => setTimeout(resolve28, Math.min(delayMs, remainingMs)));
|
|
54039
|
+
if (performance.now() >= deadline)
|
|
54040
|
+
throw original;
|
|
54041
|
+
delayMs = Math.min(delayMs * 2, 50);
|
|
54042
|
+
}
|
|
54043
|
+
}
|
|
54044
|
+
async function releaseEvictionMarker(deadline) {
|
|
54045
|
+
let ownedDirectory;
|
|
54046
|
+
await removeOwnedLeaseObject(evictPath, async () => {
|
|
54047
|
+
if (!windowsPrivateFiles2)
|
|
54048
|
+
return ownsEvictionMarker();
|
|
54049
|
+
const current = await lstat8(evictPath).catch((error) => {
|
|
54050
|
+
if (error.code !== "ENOENT")
|
|
54051
|
+
throw error;
|
|
54052
|
+
return void 0;
|
|
54053
|
+
});
|
|
54054
|
+
if (!current || ownedDirectory && !sameMarkerDirectory2(ownedDirectory, current))
|
|
54055
|
+
return false;
|
|
54056
|
+
if (await ownsEvictionMarker()) {
|
|
54057
|
+
ownedDirectory = current;
|
|
54058
|
+
return true;
|
|
54059
|
+
}
|
|
54060
|
+
if (!ownedDirectory)
|
|
54061
|
+
return false;
|
|
54062
|
+
try {
|
|
54063
|
+
await stat11(evictOwnerPath);
|
|
54064
|
+
return false;
|
|
54065
|
+
} catch (error) {
|
|
54066
|
+
if (error.code !== "ENOENT")
|
|
54067
|
+
throw error;
|
|
54068
|
+
return true;
|
|
54069
|
+
}
|
|
54070
|
+
}, deadline);
|
|
54071
|
+
}
|
|
54072
|
+
async function removeOwnMarkerAfterFailedOwnerWrite(created, deadline) {
|
|
53501
54073
|
if (!created)
|
|
53502
54074
|
return false;
|
|
53503
|
-
let
|
|
53504
|
-
try {
|
|
53505
|
-
const st = await lstat8(evictPath);
|
|
53506
|
-
current = { dev: st.dev, ino: st.ino, birthtimeMs: st.birthtimeMs };
|
|
53507
|
-
} catch {
|
|
53508
|
-
return false;
|
|
53509
|
-
}
|
|
53510
|
-
if (!sameMarkerDirectory2(created, current))
|
|
53511
|
-
return false;
|
|
53512
|
-
try {
|
|
53513
|
-
await stat11(evictOwnerPath);
|
|
53514
|
-
return true;
|
|
53515
|
-
} catch (error) {
|
|
53516
|
-
if (error.code !== "ENOENT")
|
|
53517
|
-
return true;
|
|
53518
|
-
}
|
|
54075
|
+
let stillOurs = false;
|
|
53519
54076
|
try {
|
|
53520
|
-
await
|
|
54077
|
+
await removeOwnedLeaseObject(evictPath, async () => {
|
|
54078
|
+
stillOurs = false;
|
|
54079
|
+
const st = await lstat8(evictPath).catch(() => void 0);
|
|
54080
|
+
if (!st || !sameMarkerDirectory2(created, st))
|
|
54081
|
+
return false;
|
|
54082
|
+
stillOurs = true;
|
|
54083
|
+
try {
|
|
54084
|
+
await stat11(evictOwnerPath);
|
|
54085
|
+
return false;
|
|
54086
|
+
} catch (error) {
|
|
54087
|
+
return error.code === "ENOENT";
|
|
54088
|
+
}
|
|
54089
|
+
}, deadline);
|
|
53521
54090
|
} catch {
|
|
53522
54091
|
}
|
|
53523
|
-
return
|
|
54092
|
+
return stillOurs;
|
|
53524
54093
|
}
|
|
53525
|
-
async function tryAcquireEvictionMarker() {
|
|
54094
|
+
async function tryAcquireEvictionMarker(deadline) {
|
|
53526
54095
|
if (windowsPrivateFiles2)
|
|
53527
54096
|
await createPrivateDirectoryExclusive2(evictPath);
|
|
53528
54097
|
else
|
|
@@ -53546,11 +54115,11 @@ async function acquireRefreshFileLockWithClock2(options) {
|
|
|
53546
54115
|
else
|
|
53547
54116
|
await createExclusiveText2(evictOwnerPath, bytes);
|
|
53548
54117
|
} catch (error) {
|
|
53549
|
-
const stillOurs = await removeOwnMarkerAfterFailedOwnerWrite(created);
|
|
54118
|
+
const stillOurs = await removeOwnMarkerAfterFailedOwnerWrite(created, deadline);
|
|
53550
54119
|
if (isLostMarkerRaceError2(error) && !stillOurs)
|
|
53551
54120
|
return false;
|
|
53552
54121
|
try {
|
|
53553
|
-
await releaseEvictionMarker();
|
|
54122
|
+
await releaseEvictionMarker(deadline);
|
|
53554
54123
|
} catch {
|
|
53555
54124
|
}
|
|
53556
54125
|
throw error;
|
|
@@ -53559,7 +54128,7 @@ async function acquireRefreshFileLockWithClock2(options) {
|
|
|
53559
54128
|
await options.onStep("eviction-marker-acquired");
|
|
53560
54129
|
return true;
|
|
53561
54130
|
}
|
|
53562
|
-
async function recoverStaleEvictionMarker() {
|
|
54131
|
+
async function recoverStaleEvictionMarker(deadline) {
|
|
53563
54132
|
let evictStat;
|
|
53564
54133
|
try {
|
|
53565
54134
|
evictStat = await stat11(evictPath);
|
|
@@ -53604,12 +54173,22 @@ async function acquireRefreshFileLockWithClock2(options) {
|
|
|
53604
54173
|
}
|
|
53605
54174
|
if (options.onStep)
|
|
53606
54175
|
await options.onStep("stale-marker-claimed");
|
|
53607
|
-
await
|
|
54176
|
+
const claimedIdentity = windowsPrivateFiles2 ? await lstat8(claimedPath) : void 0;
|
|
54177
|
+
await removeOwnedLeaseObject(claimedPath, async () => {
|
|
54178
|
+
if (!claimedIdentity)
|
|
54179
|
+
return true;
|
|
54180
|
+
const current = await lstat8(claimedPath).catch((error) => {
|
|
54181
|
+
if (error.code !== "ENOENT")
|
|
54182
|
+
throw error;
|
|
54183
|
+
return void 0;
|
|
54184
|
+
});
|
|
54185
|
+
return !!current && sameMarkerDirectory2(claimedIdentity, current);
|
|
54186
|
+
}, deadline);
|
|
53608
54187
|
return "recovered";
|
|
53609
54188
|
}
|
|
53610
|
-
async function withEvictionMarker(action) {
|
|
54189
|
+
async function withEvictionMarker(action, deadline) {
|
|
53611
54190
|
try {
|
|
53612
|
-
if (!await tryAcquireEvictionMarker())
|
|
54191
|
+
if (!await tryAcquireEvictionMarker(deadline))
|
|
53613
54192
|
return false;
|
|
53614
54193
|
} catch (error) {
|
|
53615
54194
|
if (error.code === "EEXIST") {
|
|
@@ -53626,11 +54205,23 @@ async function acquireRefreshFileLockWithClock2(options) {
|
|
|
53626
54205
|
}
|
|
53627
54206
|
throw error;
|
|
53628
54207
|
}
|
|
54208
|
+
let actionFailed = false;
|
|
54209
|
+
let actionError;
|
|
53629
54210
|
try {
|
|
53630
54211
|
await action();
|
|
53631
|
-
}
|
|
53632
|
-
|
|
54212
|
+
} catch (error) {
|
|
54213
|
+
actionFailed = true;
|
|
54214
|
+
actionError = error;
|
|
54215
|
+
}
|
|
54216
|
+
try {
|
|
54217
|
+
await releaseEvictionMarker(deadline);
|
|
54218
|
+
} catch (error) {
|
|
54219
|
+
if (isRetryableRemoval(actionError, lockPath) && isRetryableRemoval(error, evictPath))
|
|
54220
|
+
throw actionError;
|
|
54221
|
+
throw error;
|
|
53633
54222
|
}
|
|
54223
|
+
if (actionFailed)
|
|
54224
|
+
throw actionError;
|
|
53634
54225
|
return true;
|
|
53635
54226
|
}
|
|
53636
54227
|
async function relinquishLockAfterMarkerLoss() {
|
|
@@ -53867,6 +54458,7 @@ async function acquireRefreshFileLockWithClock2(options) {
|
|
|
53867
54458
|
await renewalInFlight;
|
|
53868
54459
|
const deadline = performance.now() + EVICT_TTL + 1e3;
|
|
53869
54460
|
let delayMs = 5;
|
|
54461
|
+
let removalError;
|
|
53870
54462
|
for (; ; ) {
|
|
53871
54463
|
try {
|
|
53872
54464
|
let removalConfirmed = false;
|
|
@@ -53891,7 +54483,7 @@ async function acquireRefreshFileLockWithClock2(options) {
|
|
|
53891
54483
|
return;
|
|
53892
54484
|
await removeLeaseObject(lockPath);
|
|
53893
54485
|
removalConfirmed = true;
|
|
53894
|
-
});
|
|
54486
|
+
}, deadline);
|
|
53895
54487
|
if (markerAcquired) {
|
|
53896
54488
|
if (windowsPrivateFiles2 && !removalConfirmed)
|
|
53897
54489
|
throw new PrivateFileError2(lockPath, "release-not-confirmed", {
|
|
@@ -53902,20 +54494,25 @@ async function acquireRefreshFileLockWithClock2(options) {
|
|
|
53902
54494
|
}
|
|
53903
54495
|
if (signal?.aborted)
|
|
53904
54496
|
return;
|
|
53905
|
-
await recoverStaleEvictionMarker();
|
|
54497
|
+
await recoverStaleEvictionMarker(deadline);
|
|
53906
54498
|
} catch (error) {
|
|
53907
|
-
if (
|
|
53908
|
-
|
|
53909
|
-
|
|
54499
|
+
if (!isRetryableRemoval(error, lockPath)) {
|
|
54500
|
+
if (windowsPrivateFiles2)
|
|
54501
|
+
throw error;
|
|
54502
|
+
return;
|
|
54503
|
+
}
|
|
54504
|
+
removalError ??= error;
|
|
53910
54505
|
}
|
|
53911
54506
|
const remainingMs = deadline - performance.now();
|
|
53912
54507
|
if (remainingMs <= 0)
|
|
53913
54508
|
break;
|
|
53914
54509
|
await new Promise((resolve28) => setTimeout(resolve28, Math.min(delayMs, remainingMs)));
|
|
54510
|
+
if (windowsPrivateFiles2 && performance.now() >= deadline)
|
|
54511
|
+
break;
|
|
53915
54512
|
delayMs = Math.min(delayMs * 2, 50);
|
|
53916
54513
|
}
|
|
53917
54514
|
if (windowsPrivateFiles2)
|
|
53918
|
-
throw new PrivateFileError2(lockPath, "release-not-confirmed", {
|
|
54515
|
+
throw removalError ?? new PrivateFileError2(lockPath, "release-not-confirmed", {
|
|
53919
54516
|
code: "ETIMEDOUT"
|
|
53920
54517
|
});
|
|
53921
54518
|
}
|
|
@@ -53958,7 +54555,7 @@ var RETRYABLE_ENROLLMENT_CODES2 = /* @__PURE__ */ new Set([
|
|
|
53958
54555
|
"pending_queue_full"
|
|
53959
54556
|
]);
|
|
53960
54557
|
function classifyEnrollmentError2(error) {
|
|
53961
|
-
if (!(error instanceof
|
|
54558
|
+
if (!(error instanceof ClaustrumCredentialError6))
|
|
53962
54559
|
return void 0;
|
|
53963
54560
|
if (TERMINAL_ENROLLMENT_CODES2.has(error.code))
|
|
53964
54561
|
return { code: error.code, disposition: "terminal" };
|
|
@@ -54437,7 +55034,7 @@ var ClaustrumEnrollmentManager2 = class {
|
|
|
54437
55034
|
}
|
|
54438
55035
|
if (!state.requestId) {
|
|
54439
55036
|
try {
|
|
54440
|
-
const requestSecretHash =
|
|
55037
|
+
const requestSecretHash = createHash19("sha256").update(Buffer.from(state.requestSecret, "hex")).digest("hex");
|
|
54441
55038
|
const proposed = await this.#client.enrollPropose({
|
|
54442
55039
|
name: state.proposedName,
|
|
54443
55040
|
requestSecretHash
|
|
@@ -56149,7 +56746,13 @@ async function createSetupPlugin(deps, migrateOpenCode, forceLogin = false) {
|
|
|
56149
56746
|
}
|
|
56150
56747
|
};
|
|
56151
56748
|
let openCodeLogin;
|
|
56152
|
-
|
|
56749
|
+
const nativeNextStep = (label) => {
|
|
56750
|
+
deps.stdout.write(
|
|
56751
|
+
`In OpenCode 2, run opencode auth login, select Google, then choose ${label}.
|
|
56752
|
+
Setup has not completed the OpenCode 2 native Google connection.
|
|
56753
|
+
`
|
|
56754
|
+
);
|
|
56755
|
+
};
|
|
56153
56756
|
const manifest = JSON.parse(
|
|
56154
56757
|
await readFile16(new URL("../package.json", import.meta.url), "utf8")
|
|
56155
56758
|
);
|
|
@@ -56207,18 +56810,10 @@ async function createSetupPlugin(deps, migrateOpenCode, forceLogin = false) {
|
|
|
56207
56810
|
await assertLocal(host, context);
|
|
56208
56811
|
if (host === "opencode" && context.opencodeGeneration === "2") {
|
|
56209
56812
|
if (!forceLogin) {
|
|
56210
|
-
|
|
56211
|
-
|
|
56212
|
-
|
|
56213
|
-
|
|
56214
|
-
const candidateAccounts = source2.kind === "store" ? source2.accounts : source2.kind === "legacy" ? (await deps.loadAccounts())?.accounts ?? [] : [];
|
|
56215
|
-
if (candidateAccounts.some(
|
|
56216
|
-
(account) => account.enabled !== false && account.accountIneligible !== true && account.verificationRequired !== true && typeof account.refreshToken === "string" && account.refreshToken.length > 0
|
|
56217
|
-
)) {
|
|
56218
|
-
hasLocalPool = true;
|
|
56219
|
-
}
|
|
56220
|
-
} catch {
|
|
56221
|
-
}
|
|
56813
|
+
const source2 = await deps.accountStore.read(
|
|
56814
|
+
deps.accountStore.legacyPath()
|
|
56815
|
+
);
|
|
56816
|
+
if (source2.kind === "unavailable") throw new Error(source2.reason);
|
|
56222
56817
|
}
|
|
56223
56818
|
return;
|
|
56224
56819
|
}
|
|
@@ -56233,11 +56828,6 @@ async function createSetupPlugin(deps, migrateOpenCode, forceLogin = false) {
|
|
|
56233
56828
|
`Using existing local Antigravity login for ${host}.
|
|
56234
56829
|
`
|
|
56235
56830
|
);
|
|
56236
|
-
if (host === "opencode" && accounts.some(
|
|
56237
|
-
(account) => account.enabled !== false && account.accountIneligible !== true && account.verificationRequired !== true && typeof account.refreshToken === "string" && account.refreshToken.length > 0
|
|
56238
|
-
)) {
|
|
56239
|
-
hasLocalPool = true;
|
|
56240
|
-
}
|
|
56241
56831
|
if (host === "opencode" && claustrum.classifyHostSlot(slot, provider(host)) !== "login") {
|
|
56242
56832
|
const account = accounts[0];
|
|
56243
56833
|
await writeNativeSlot(
|
|
@@ -56270,18 +56860,10 @@ async function createSetupPlugin(deps, migrateOpenCode, forceLogin = false) {
|
|
|
56270
56860
|
);
|
|
56271
56861
|
if (host === "opencode") {
|
|
56272
56862
|
openCodeLogin = result;
|
|
56273
|
-
hasLocalPool = true;
|
|
56274
56863
|
}
|
|
56275
56864
|
},
|
|
56276
56865
|
beforeRegister: async (host, mode, context) => {
|
|
56277
56866
|
const needsOpenCode2 = host === "opencode" && context.opencodeGeneration !== "1";
|
|
56278
|
-
const nativeNextStep = (label) => {
|
|
56279
|
-
deps.stdout.write(
|
|
56280
|
-
`In OpenCode 2, run opencode auth login, select Google, then choose ${label}.
|
|
56281
|
-
Setup has not completed the OpenCode 2 native Google connection.
|
|
56282
|
-
`
|
|
56283
|
-
);
|
|
56284
|
-
};
|
|
56285
56867
|
if (mode === "local") {
|
|
56286
56868
|
await assertLocal(host, context);
|
|
56287
56869
|
if (host === "opencode" && context.opencodeGeneration !== "2" && openCodeLogin)
|
|
@@ -56295,10 +56877,6 @@ Setup has not completed the OpenCode 2 native Google connection.
|
|
|
56295
56877
|
},
|
|
56296
56878
|
context
|
|
56297
56879
|
);
|
|
56298
|
-
if (needsOpenCode2)
|
|
56299
|
-
nativeNextStep(
|
|
56300
|
-
hasLocalPool ? OPENCODE2_POOL_RECONNECT_LABEL : OPENCODE2_POOL_AUTH_LABEL
|
|
56301
|
-
);
|
|
56302
56880
|
return;
|
|
56303
56881
|
}
|
|
56304
56882
|
if (await authority(host) !== "vault")
|
|
@@ -56369,11 +56947,28 @@ Setup has not completed the OpenCode 2 native Google connection.
|
|
|
56369
56947
|
await publishedGeneration(stateAnchor),
|
|
56370
56948
|
stateAnchor
|
|
56371
56949
|
);
|
|
56372
|
-
|
|
56950
|
+
} else {
|
|
56951
|
+
if (await migrateOpenCode() !== 0)
|
|
56952
|
+
throw new Error("Offline Antigravity account migration failed.");
|
|
56953
|
+
await deps.prepareVaultFolder?.();
|
|
56954
|
+
}
|
|
56955
|
+
if (context.mode === "local" && context.opencodeGeneration !== "1") {
|
|
56956
|
+
let reconnectReady = false;
|
|
56957
|
+
if (!forceLogin || context.opencodeGeneration !== "2") {
|
|
56958
|
+
if (source.kind === "store") {
|
|
56959
|
+
reconnectReady = source.reconnectReady;
|
|
56960
|
+
} else if (source.kind === "legacy") {
|
|
56961
|
+
const post = await deps.accountStore.read(
|
|
56962
|
+
deps.accountStore.legacyPath()
|
|
56963
|
+
);
|
|
56964
|
+
if (post.kind === "unavailable") throw new Error(post.reason);
|
|
56965
|
+
reconnectReady = post.kind === "store" && post.reconnectReady;
|
|
56966
|
+
}
|
|
56967
|
+
}
|
|
56968
|
+
nativeNextStep(
|
|
56969
|
+
reconnectReady ? OPENCODE2_POOL_RECONNECT_LABEL : OPENCODE2_POOL_AUTH_LABEL
|
|
56970
|
+
);
|
|
56373
56971
|
}
|
|
56374
|
-
if (await migrateOpenCode() !== 0)
|
|
56375
|
-
throw new Error("Offline Antigravity account migration failed.");
|
|
56376
|
-
await deps.prepareVaultFolder?.();
|
|
56377
56972
|
} else {
|
|
56378
56973
|
deps.stdout.write(
|
|
56379
56974
|
"Pi uses its native auth.json; no Antigravity account-pool migration is needed.\n"
|
|
@@ -56965,6 +57560,7 @@ async function readAccountStore(legacyPath) {
|
|
|
56965
57560
|
case "bound":
|
|
56966
57561
|
break;
|
|
56967
57562
|
}
|
|
57563
|
+
const generationId = admission.receipt.id;
|
|
56968
57564
|
const repository = createAccountRepositoryFactory(modules)({
|
|
56969
57565
|
paths: admission.paths,
|
|
56970
57566
|
now: Date.now,
|
|
@@ -56978,6 +57574,12 @@ async function readAccountStore(legacyPath) {
|
|
|
56978
57574
|
}
|
|
56979
57575
|
});
|
|
56980
57576
|
try {
|
|
57577
|
+
const servingBefore = await readAccountStoreAdmission(
|
|
57578
|
+
legacyPath,
|
|
57579
|
+
modules,
|
|
57580
|
+
Date.now,
|
|
57581
|
+
generationId
|
|
57582
|
+
);
|
|
56981
57583
|
const read = await repository.read();
|
|
56982
57584
|
if (read.status !== "ready") {
|
|
56983
57585
|
return {
|
|
@@ -56985,7 +57587,20 @@ async function readAccountStore(legacyPath) {
|
|
|
56985
57587
|
reason: `the account store is ${read.status}`
|
|
56986
57588
|
};
|
|
56987
57589
|
}
|
|
56988
|
-
|
|
57590
|
+
const servingAfter = servingBefore.status === "active" ? await readAccountStoreAdmission(
|
|
57591
|
+
legacyPath,
|
|
57592
|
+
modules,
|
|
57593
|
+
Date.now,
|
|
57594
|
+
generationId
|
|
57595
|
+
) : servingBefore;
|
|
57596
|
+
const reconnectReady = servingBefore.status === "active" && servingAfter.status === "active" && read.rows.some(
|
|
57597
|
+
(row) => row.enabled && row.usable && row.credential !== void 0 && !row.torn && !row.unbound && row.invalid === void 0 && row.metadata.status === "present" && row.metadata.metadata.verificationRequired !== true && row.metadata.metadata.accountIneligible !== true
|
|
57598
|
+
);
|
|
57599
|
+
return {
|
|
57600
|
+
kind: "store",
|
|
57601
|
+
accounts: read.rows.map(cliAccountOf),
|
|
57602
|
+
reconnectReady
|
|
57603
|
+
};
|
|
56989
57604
|
} finally {
|
|
56990
57605
|
await repository.dispose();
|
|
56991
57606
|
}
|
|
@@ -57512,7 +58127,7 @@ function isTuiConnected(sessionId) {
|
|
|
57512
58127
|
}
|
|
57513
58128
|
|
|
57514
58129
|
// src/rpc/rpc-dir.ts
|
|
57515
|
-
import { createHash as
|
|
58130
|
+
import { createHash as createHash20 } from "node:crypto";
|
|
57516
58131
|
import { homedir as homedir13, tmpdir as tmpdir6 } from "node:os";
|
|
57517
58132
|
import { isAbsolute as isAbsolute5, join as join34, resolve as resolve25 } from "node:path";
|
|
57518
58133
|
var RPC_DIR_ENV = "ANTIGRAVITY_AUTH_RPC_DIR";
|
|
@@ -57521,7 +58136,7 @@ function getRpcDir(projectDirectory) {
|
|
|
57521
58136
|
if (override) {
|
|
57522
58137
|
return isAbsolute5(override) ? override : resolve25(projectDirectory, override);
|
|
57523
58138
|
}
|
|
57524
|
-
const projectHash =
|
|
58139
|
+
const projectHash = createHash20("sha256").update(resolve25(projectDirectory)).digest("hex").slice(0, 16);
|
|
57525
58140
|
const stateHome = process.env.XDG_STATE_HOME ?? join34(homedir13(), ".local", "state");
|
|
57526
58141
|
return join34(stateHome, "cortexkit", "antigravity-auth", "rpc", projectHash);
|
|
57527
58142
|
}
|
|
@@ -57533,9 +58148,32 @@ function isSessionId(value) {
|
|
|
57533
58148
|
|
|
57534
58149
|
// src/common-auth-embedded/rpc/port-file.js
|
|
57535
58150
|
init_private_files2();
|
|
57536
|
-
import { createHash as
|
|
58151
|
+
import { createHash as createHash21, randomUUID as randomUUID21 } from "node:crypto";
|
|
57537
58152
|
import { chmod as chmod7, mkdir as mkdir17, open as open12, readdir as readdir4, rename as rename14, rmdir as rmdir3, stat as stat15, unlink as unlink13 } from "node:fs/promises";
|
|
58153
|
+
import { uptime as uptime2 } from "node:os";
|
|
57538
58154
|
import { join as join35, resolve as resolve26 } from "node:path";
|
|
58155
|
+
function staleBefore(clock2) {
|
|
58156
|
+
return (clock2.now ?? Date.now)() - (clock2.uptime ?? uptime2)() * 1e3 - 3e5;
|
|
58157
|
+
}
|
|
58158
|
+
function isStalePortFile(entry, info, cutoff) {
|
|
58159
|
+
const time = entry.startedAt === void 0 ? info?.mtimeMs : entry.startedAt;
|
|
58160
|
+
return typeof time === "number" && Number.isFinite(time) && time < cutoff;
|
|
58161
|
+
}
|
|
58162
|
+
async function removeStalePortFile(path5, raw, info, beforeRemove2) {
|
|
58163
|
+
if (!info)
|
|
58164
|
+
return;
|
|
58165
|
+
await beforeRemove2?.(path5);
|
|
58166
|
+
try {
|
|
58167
|
+
const current = await readPrivateText2(path5);
|
|
58168
|
+
const identity3 = await stat15(path5);
|
|
58169
|
+
if (current === raw && identity3.dev === info.dev && identity3.ino === info.ino && identity3.mtimeMs === info.mtimeMs && identity3.size === info.size)
|
|
58170
|
+
await unlink13(path5).catch(() => {
|
|
58171
|
+
});
|
|
58172
|
+
} catch (error) {
|
|
58173
|
+
if (error instanceof PrivateFileError2 && error.code !== "ENOENT")
|
|
58174
|
+
throw error;
|
|
58175
|
+
}
|
|
58176
|
+
}
|
|
57539
58177
|
function isProbeablePid(pid) {
|
|
57540
58178
|
return typeof pid === "number" && Number.isSafeInteger(pid) && pid > 0;
|
|
57541
58179
|
}
|
|
@@ -57613,7 +58251,8 @@ async function writePortFile(dir, entry, options = {}) {
|
|
|
57613
58251
|
throw error;
|
|
57614
58252
|
}
|
|
57615
58253
|
}
|
|
57616
|
-
async function sweepRpcState(root, activeDir, isManagedDir, log17) {
|
|
58254
|
+
async function sweepRpcState(root, activeDir, isManagedDir, log17, options = {}) {
|
|
58255
|
+
const cutoff = staleBefore(options);
|
|
57617
58256
|
let projectDirs;
|
|
57618
58257
|
try {
|
|
57619
58258
|
projectDirs = await readdir4(root, { withFileTypes: true });
|
|
@@ -57640,6 +58279,7 @@ async function sweepRpcState(root, activeDir, isManagedDir, log17) {
|
|
|
57640
58279
|
if (!name.startsWith("port-") || !name.endsWith(".json"))
|
|
57641
58280
|
continue;
|
|
57642
58281
|
const portFile = join35(dir, name);
|
|
58282
|
+
const info = await stat15(portFile).catch(() => void 0);
|
|
57643
58283
|
let raw;
|
|
57644
58284
|
try {
|
|
57645
58285
|
raw = await readPrivateText2(portFile);
|
|
@@ -57665,6 +58305,8 @@ async function sweepRpcState(root, activeDir, isManagedDir, log17) {
|
|
|
57665
58305
|
if (!pidAlive2(entry.pid))
|
|
57666
58306
|
await unlink13(portFile).catch(() => {
|
|
57667
58307
|
});
|
|
58308
|
+
else if (isStalePortFile(entry, info, cutoff))
|
|
58309
|
+
await removeStalePortFile(portFile, raw, info, options.beforeRemove);
|
|
57668
58310
|
}
|
|
57669
58311
|
if (resolve26(dir) !== active2)
|
|
57670
58312
|
await rmdir3(dir).catch(() => {
|
|
@@ -60755,13 +61397,13 @@ function createAccountCommandOAuthService(options) {
|
|
|
60755
61397
|
|
|
60756
61398
|
// src/plugin/auth-loader.ts
|
|
60757
61399
|
init_dist();
|
|
60758
|
-
import { createHash as
|
|
61400
|
+
import { createHash as createHash22 } from "node:crypto";
|
|
60759
61401
|
init_debug();
|
|
60760
61402
|
init_logger4();
|
|
60761
61403
|
init_storage();
|
|
60762
61404
|
var log13 = createLogger4("auth-loader");
|
|
60763
61405
|
function refreshTokenIdentity(refreshToken) {
|
|
60764
|
-
return
|
|
61406
|
+
return createHash22("sha256").update(refreshToken).digest("hex").slice(0, 16);
|
|
60765
61407
|
}
|
|
60766
61408
|
async function initializeDefaultFreshStore() {
|
|
60767
61409
|
return initializeFreshAccountStoreFor(await loadCommonAuthStoreModules());
|
|
@@ -61503,7 +62145,7 @@ function registerAntigravityCommands(config) {
|
|
|
61503
62145
|
}
|
|
61504
62146
|
|
|
61505
62147
|
// src/plugin/command-data.ts
|
|
61506
|
-
import { createHash as
|
|
62148
|
+
import { createHash as createHash23 } from "node:crypto";
|
|
61507
62149
|
var QUOTA_GROUP_LABELS = {
|
|
61508
62150
|
gemini: "Gemini",
|
|
61509
62151
|
"non-gemini": "Non-Gemini",
|
|
@@ -61561,7 +62203,7 @@ function toCommandAccountRow(entry) {
|
|
|
61561
62203
|
};
|
|
61562
62204
|
}
|
|
61563
62205
|
function quotaAccountIdentity3(refreshToken) {
|
|
61564
|
-
return
|
|
62206
|
+
return createHash23("sha256").update(refreshToken).digest("hex").slice(0, 16);
|
|
61565
62207
|
}
|
|
61566
62208
|
function projectCommandAccountRows(storage) {
|
|
61567
62209
|
if (!storage) return [];
|
|
@@ -62433,7 +63075,7 @@ init_storage();
|
|
|
62433
63075
|
init_vault_custody();
|
|
62434
63076
|
var logger2 = createLogger4("plugin");
|
|
62435
63077
|
function quotaAccountIdentity4(refreshToken) {
|
|
62436
|
-
return
|
|
63078
|
+
return createHash24("sha256").update(refreshToken).digest("hex").slice(0, 16);
|
|
62437
63079
|
}
|
|
62438
63080
|
function registerQuotaManagerProducer(lifecycle, quotaManager) {
|
|
62439
63081
|
lifecycle.register({ dispose: () => quotaManager.dispose() }, "producer");
|