@cortexkit/opencode-antigravity-auth 3.1.10 → 3.1.12
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 +357 -58
- package/dist/cli.js.map +3 -3
- package/dist/cli.meta.json +42 -32
- package/dist/index.js +1115 -493
- package/dist/index.js.map +4 -4
- package/dist/index.meta.json +98 -65
- package/dist/server.js +1266 -616
- package/dist/server.js.map +4 -4
- package/dist/server.meta.json +1 -1
- package/dist/src/cli.d.ts +3 -1
- package/dist/src/cli.d.ts.map +1 -1
- package/dist/src/cli.js +19 -6
- package/dist/src/cli.js.map +1 -1
- package/dist/src/common-auth-embedded/claustrum/consumer.d.ts +20 -1
- package/dist/src/common-auth-embedded/claustrum/consumer.js +32 -0
- package/dist/src/common-auth-embedded/claustrum/custody.d.ts +39 -1
- package/dist/src/common-auth-embedded/claustrum/custody.js +145 -8
- package/dist/src/common-auth-embedded/claustrum/host.js +8 -0
- package/dist/src/common-auth-embedded/claustrum/hub.d.ts +3 -2
- package/dist/src/common-auth-embedded/claustrum/hub.js +10 -0
- package/dist/src/common-auth-embedded/claustrum/index.d.ts +1 -1
- package/dist/src/common-auth-embedded/routing-accessor/index.js +5 -3
- package/dist/src/common-auth-embedded/source-output.json +35 -35
- package/dist/src/ga/rpc/protocol.d.ts +11 -5
- package/dist/src/ga/rpc/protocol.d.ts.map +1 -1
- package/dist/src/ga/rpc/protocol.js +11 -3
- package/dist/src/ga/rpc/protocol.js.map +1 -1
- package/dist/src/ga/server/index.d.ts.map +1 -1
- package/dist/src/ga/server/index.js +30 -14
- package/dist/src/ga/server/index.js.map +1 -1
- package/dist/src/ga/tui/host-ga.d.ts +2 -1
- package/dist/src/ga/tui/host-ga.d.ts.map +1 -1
- package/dist/src/ga/tui/host-ga.js +9 -4
- package/dist/src/ga/tui/host-ga.js.map +1 -1
- package/dist/src/plugin/__fixtures__/verified-store.js +2 -2
- package/dist/src/plugin/account-access.d.ts +1 -0
- package/dist/src/plugin/account-access.d.ts.map +1 -1
- package/dist/src/plugin/account-access.js +28 -0
- package/dist/src/plugin/account-access.js.map +1 -1
- package/dist/src/plugin/auth-loader.d.ts.map +1 -1
- package/dist/src/plugin/auth-loader.js +21 -12
- package/dist/src/plugin/auth-loader.js.map +1 -1
- package/dist/src/plugin/background-quota-refresh.d.ts +11 -24
- package/dist/src/plugin/background-quota-refresh.d.ts.map +1 -1
- package/dist/src/plugin/background-quota-refresh.js +54 -60
- package/dist/src/plugin/background-quota-refresh.js.map +1 -1
- package/dist/src/plugin/background-vault-quota-refresh.d.ts.map +1 -1
- package/dist/src/plugin/background-vault-quota-refresh.js +6 -3
- package/dist/src/plugin/background-vault-quota-refresh.js.map +1 -1
- package/dist/src/plugin/cache/signature-cache.d.ts +3 -0
- package/dist/src/plugin/cache/signature-cache.d.ts.map +1 -1
- package/dist/src/plugin/cache/signature-cache.js +73 -46
- package/dist/src/plugin/cache/signature-cache.js.map +1 -1
- package/dist/src/plugin/cache.d.ts.map +1 -1
- package/dist/src/plugin/cache.js +17 -7
- package/dist/src/plugin/cache.js.map +1 -1
- package/dist/src/plugin/core/streaming/displayed-thinking.d.ts +23 -0
- package/dist/src/plugin/core/streaming/displayed-thinking.d.ts.map +1 -0
- package/dist/src/plugin/core/streaming/displayed-thinking.js +58 -0
- package/dist/src/plugin/core/streaming/displayed-thinking.js.map +1 -0
- package/dist/src/plugin/fetch/warmup.d.ts +9 -2
- package/dist/src/plugin/fetch/warmup.d.ts.map +1 -1
- package/dist/src/plugin/fetch/warmup.js +22 -14
- package/dist/src/plugin/fetch/warmup.js.map +1 -1
- package/dist/src/plugin/ga-location-services.d.ts +1 -0
- package/dist/src/plugin/ga-location-services.d.ts.map +1 -1
- package/dist/src/plugin/ga-location-services.js +2 -0
- package/dist/src/plugin/ga-location-services.js.map +1 -1
- package/dist/src/plugin/ga-shared-vault-custody.d.ts.map +1 -1
- package/dist/src/plugin/ga-shared-vault-custody.js +7 -1
- package/dist/src/plugin/ga-shared-vault-custody.js.map +1 -1
- package/dist/src/plugin/index.d.ts.map +1 -1
- package/dist/src/plugin/index.js +6 -1
- package/dist/src/plugin/index.js.map +1 -1
- package/dist/src/plugin/quota.d.ts +10 -2
- package/dist/src/plugin/quota.d.ts.map +1 -1
- package/dist/src/plugin/quota.js +38 -10
- package/dist/src/plugin/quota.js.map +1 -1
- package/dist/src/plugin/request-helpers.d.ts.map +1 -1
- package/dist/src/plugin/request-helpers.js +51 -19
- package/dist/src/plugin/request-helpers.js.map +1 -1
- package/dist/src/plugin/request.d.ts +12 -1
- package/dist/src/plugin/request.d.ts.map +1 -1
- package/dist/src/plugin/request.js +27 -42
- package/dist/src/plugin/request.js.map +1 -1
- package/dist/src/plugin/shared/request-services.d.ts +4 -1
- package/dist/src/plugin/shared/request-services.d.ts.map +1 -1
- package/dist/src/plugin/shared/request-services.js +142 -24
- package/dist/src/plugin/shared/request-services.js.map +1 -1
- package/dist/src/plugin/shared/runtime.d.ts +3 -4
- package/dist/src/plugin/shared/runtime.d.ts.map +1 -1
- package/dist/src/plugin/shared/runtime.js +2 -2
- package/dist/src/plugin/shared/runtime.js.map +1 -1
- package/dist/src/plugin/shared/vault-request-credentials.d.ts +25 -15
- package/dist/src/plugin/shared/vault-request-credentials.d.ts.map +1 -1
- package/dist/src/plugin/shared/vault-request-credentials.js +141 -68
- package/dist/src/plugin/shared/vault-request-credentials.js.map +1 -1
- package/dist/src/plugin/vault-sidebar-projection.d.ts.map +1 -1
- package/dist/src/setup.d.ts +3 -0
- package/dist/src/setup.d.ts.map +1 -1
- package/dist/src/setup.js +18 -6
- package/dist/src/setup.js.map +1 -1
- package/dist/src/sidebar-state.d.ts +20 -7
- package/dist/src/sidebar-state.d.ts.map +1 -1
- package/dist/src/sidebar-state.js +57 -8
- package/dist/src/sidebar-state.js.map +1 -1
- package/dist/src/tui.d.ts.map +1 -1
- package/dist/src/tui.js +43 -23
- package/dist/src/tui.js.map +1 -1
- package/dist/tui-build-map.json +9 -9
- package/dist/tui-ga-build-map.json +5 -5
- package/dist/types/src/cli.d.ts +3 -1
- package/dist/types/src/cli.d.ts.map +1 -1
- package/dist/types/src/common-auth-embedded/claustrum/consumer.d.ts +20 -1
- package/dist/types/src/common-auth-embedded/claustrum/custody.d.ts +39 -1
- 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 -1
- package/dist/types/src/ga/rpc/protocol.d.ts +11 -5
- package/dist/types/src/ga/rpc/protocol.d.ts.map +1 -1
- package/dist/types/src/ga/server/index.d.ts.map +1 -1
- package/dist/types/src/plugin/account-access.d.ts +1 -0
- package/dist/types/src/plugin/account-access.d.ts.map +1 -1
- package/dist/types/src/plugin/auth-loader.d.ts.map +1 -1
- package/dist/types/src/plugin/background-quota-refresh.d.ts +11 -24
- package/dist/types/src/plugin/background-quota-refresh.d.ts.map +1 -1
- package/dist/types/src/plugin/background-vault-quota-refresh.d.ts.map +1 -1
- package/dist/types/src/plugin/cache/signature-cache.d.ts +3 -0
- package/dist/types/src/plugin/cache/signature-cache.d.ts.map +1 -1
- package/dist/types/src/plugin/cache.d.ts.map +1 -1
- package/dist/types/src/plugin/core/streaming/displayed-thinking.d.ts +23 -0
- package/dist/types/src/plugin/core/streaming/displayed-thinking.d.ts.map +1 -0
- package/dist/types/src/plugin/fetch/warmup.d.ts +9 -2
- package/dist/types/src/plugin/fetch/warmup.d.ts.map +1 -1
- package/dist/types/src/plugin/ga-location-services.d.ts +1 -0
- package/dist/types/src/plugin/ga-location-services.d.ts.map +1 -1
- package/dist/types/src/plugin/ga-shared-vault-custody.d.ts.map +1 -1
- package/dist/types/src/plugin/index.d.ts.map +1 -1
- package/dist/types/src/plugin/quota.d.ts +10 -2
- package/dist/types/src/plugin/quota.d.ts.map +1 -1
- package/dist/types/src/plugin/request-helpers.d.ts.map +1 -1
- package/dist/types/src/plugin/request.d.ts +12 -1
- package/dist/types/src/plugin/request.d.ts.map +1 -1
- package/dist/types/src/plugin/shared/request-services.d.ts +4 -1
- package/dist/types/src/plugin/shared/request-services.d.ts.map +1 -1
- package/dist/types/src/plugin/shared/runtime.d.ts +3 -4
- package/dist/types/src/plugin/shared/runtime.d.ts.map +1 -1
- package/dist/types/src/plugin/shared/vault-request-credentials.d.ts +25 -15
- package/dist/types/src/plugin/shared/vault-request-credentials.d.ts.map +1 -1
- package/dist/types/src/plugin/vault-sidebar-projection.d.ts.map +1 -1
- package/dist/types/src/setup.d.ts +3 -0
- package/dist/types/src/setup.d.ts.map +1 -1
- package/dist/types/src/sidebar-state.d.ts +20 -7
- package/dist/types/src/sidebar-state.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/common-auth-embedded/claustrum/consumer.d.ts +20 -1
- package/src/common-auth-embedded/claustrum/consumer.js +32 -0
- package/src/common-auth-embedded/claustrum/custody.d.ts +39 -1
- package/src/common-auth-embedded/claustrum/custody.js +145 -8
- package/src/common-auth-embedded/claustrum/host.js +8 -0
- package/src/common-auth-embedded/claustrum/hub.d.ts +3 -2
- package/src/common-auth-embedded/claustrum/hub.js +10 -0
- package/src/common-auth-embedded/claustrum/index.d.ts +1 -1
- package/src/common-auth-embedded/routing-accessor/index.js +5 -3
- package/src/common-auth-embedded/source-output.json +35 -35
- package/src/sidebar-state.ts +77 -8
- package/src/tui-compiled/sidebar-state.js +40 -1
- package/src/tui-compiled/tui.js +49 -24
- package/src/tui-ga-compiled/host-ga.js +11 -5
- package/src/tui-ga-raw/host-ga.tsx +17 -6
- package/src/tui-raw/sidebar-state.js +40 -1
- package/src/tui-raw/tui.tsx +40 -24
- package/src/tui.tsx +40 -24
package/dist/index.js
CHANGED
|
@@ -385,6 +385,11 @@ function mergeQuotaState(stored, observation) {
|
|
|
385
385
|
if (stored === void 0)
|
|
386
386
|
return incoming;
|
|
387
387
|
const prior = encodeQuotaState(decodeQuotaState(stored));
|
|
388
|
+
const previousAt = prior.cachedQuotaUpdatedAt;
|
|
389
|
+
const observedAt = incoming.cachedQuotaUpdatedAt;
|
|
390
|
+
if (typeof previousAt === "number" && typeof observedAt === "number" && observedAt < previousAt) {
|
|
391
|
+
throw new StaleQuotaObservationError();
|
|
392
|
+
}
|
|
388
393
|
return encodeQuotaState(decodeQuotaState({ ...prior, ...incoming }));
|
|
389
394
|
}
|
|
390
395
|
function decodeRoutingSettings(raw) {
|
|
@@ -420,7 +425,7 @@ function createProviderStateCodec(policy) {
|
|
|
420
425
|
}
|
|
421
426
|
};
|
|
422
427
|
}
|
|
423
|
-
var AccountCodecError, MAX_JSON_DEPTH, IDENTIFIER, jsonValue, string, nonEmptyString, finiteNumber, count, credentialEpoch, boolean, rowId, required, optional, EXTENSIONS, CREDENTIAL_REFUSAL, CREDENTIAL_KEYS, POOL_FIELD_REFUSAL, QUOTA_FIELD_REFUSAL, LEGACY_FIELD_REFUSAL, METADATA_FIELD_REFUSAL, clientMetadataCodec, fingerprintCodec, fingerprintVersionCodec, dailyRequestCountsCodec, metadataShape, quotaShape, metadataForbidden, quotaForbidden, metadataCodec, providerStateCodec, quotaCodec, rowRefCodec, routingCodec, QUOTA_CODEC;
|
|
428
|
+
var AccountCodecError, MAX_JSON_DEPTH, IDENTIFIER, jsonValue, string, nonEmptyString, finiteNumber, count, credentialEpoch, boolean, rowId, required, optional, EXTENSIONS, CREDENTIAL_REFUSAL, CREDENTIAL_KEYS, POOL_FIELD_REFUSAL, QUOTA_FIELD_REFUSAL, LEGACY_FIELD_REFUSAL, METADATA_FIELD_REFUSAL, clientMetadataCodec, fingerprintCodec, fingerprintVersionCodec, dailyRequestCountsCodec, metadataShape, quotaShape, metadataForbidden, quotaForbidden, metadataCodec, providerStateCodec, quotaCodec, rowRefCodec, routingCodec, StaleQuotaObservationError, QUOTA_CODEC;
|
|
424
429
|
var init_account_repository_codecs = __esm({
|
|
425
430
|
"../core/dist/account-repository-codecs.js"() {
|
|
426
431
|
"use strict";
|
|
@@ -590,6 +595,11 @@ var init_account_repository_codecs = __esm({
|
|
|
590
595
|
gemini: optional(nullable(rowRefCodec))
|
|
591
596
|
})))
|
|
592
597
|
}, { forbidden: CREDENTIAL_KEYS });
|
|
598
|
+
StaleQuotaObservationError = class extends Error {
|
|
599
|
+
constructor() {
|
|
600
|
+
super("A newer quota observation is already stored");
|
|
601
|
+
}
|
|
602
|
+
};
|
|
593
603
|
QUOTA_CODEC = {
|
|
594
604
|
validate: isValidQuotaState,
|
|
595
605
|
merge: mergeQuotaState
|
|
@@ -1642,10 +1652,10 @@ async function privateDirectory(path5) {
|
|
|
1642
1652
|
if (errno(error) !== "EEXIST")
|
|
1643
1653
|
throw error;
|
|
1644
1654
|
}
|
|
1645
|
-
const
|
|
1646
|
-
if (!
|
|
1655
|
+
const stat22 = await lstat2(path5);
|
|
1656
|
+
if (!stat22.isDirectory() || stat22.isSymbolicLink())
|
|
1647
1657
|
throw new AccountMigrationError("successor directory is not a regular directory");
|
|
1648
|
-
privateMode(
|
|
1658
|
+
privateMode(stat22.mode, 448);
|
|
1649
1659
|
if (windowsPrivateFiles)
|
|
1650
1660
|
await verifySafeDirectory(path5);
|
|
1651
1661
|
if (!sameFilesystemPath(await realpath(path5), path5))
|
|
@@ -5058,9 +5068,7 @@ function reconcileRateLimitsFromReading(account, reading, now2) {
|
|
|
5058
5068
|
function quotaRetryAfter(account, family, model, reason, retryAfterMs, now2) {
|
|
5059
5069
|
if (reason !== "QUOTA_EXHAUSTED" || !(retryAfterMs && retryAfterMs > MAX_QUOTA_EXHAUSTED_BACKOFF_MS))
|
|
5060
5070
|
return retryAfterMs;
|
|
5061
|
-
|
|
5062
|
-
const group = resolveQuotaGroup(family, model, account.cachedQuota);
|
|
5063
|
-
return at !== void 0 && Number.isFinite(at) && at > 0 && at <= now2 && account.cachedQuota?.[group]?.remainingFraction === 0 ? retryAfterMs : void 0;
|
|
5071
|
+
return quotaExhaustedUntil(account, family, model, now2) > now2 ? retryAfterMs : void 0;
|
|
5064
5072
|
}
|
|
5065
5073
|
function quotaExhaustedUntil(account, family, model, now2) {
|
|
5066
5074
|
const at = account.cachedQuotaUpdatedAt;
|
|
@@ -7685,11 +7693,21 @@ var init_account_repository = __esm({
|
|
|
7685
7693
|
rowId: ref.id
|
|
7686
7694
|
});
|
|
7687
7695
|
}
|
|
7688
|
-
|
|
7689
|
-
|
|
7690
|
-
|
|
7691
|
-
|
|
7692
|
-
|
|
7696
|
+
try {
|
|
7697
|
+
await this.store.recordQuota(ref.id, credentialFenceOf(ref), encoded);
|
|
7698
|
+
} catch (error) {
|
|
7699
|
+
if (error instanceof StaleQuotaObservationError || error instanceof this.storeFailure && error.cause instanceof StaleQuotaObservationError)
|
|
7700
|
+
return;
|
|
7701
|
+
throw error;
|
|
7702
|
+
}
|
|
7703
|
+
await this.updateMetadata(ref, (metadata, row) => {
|
|
7704
|
+
if (!metadata || observation.cachedQuotaUpdatedAt == null || row.quota.status !== "present" || row.quota.quota.cachedQuotaUpdatedAt !== observation.cachedQuotaUpdatedAt)
|
|
7705
|
+
return { kind: "keep" };
|
|
7706
|
+
return {
|
|
7707
|
+
kind: "set",
|
|
7708
|
+
metadata: applyRateLimitReadingUpdate(metadata, rateLimitReadingUpdateOf(observation), this.now())
|
|
7709
|
+
};
|
|
7710
|
+
});
|
|
7693
7711
|
});
|
|
7694
7712
|
}
|
|
7695
7713
|
// ---- selection and roster ---------------------------------------------
|
|
@@ -8304,7 +8322,7 @@ async function rmEvictingDir(evictingPath) {
|
|
|
8304
8322
|
});
|
|
8305
8323
|
}
|
|
8306
8324
|
async function sleep(ms) {
|
|
8307
|
-
await new Promise((
|
|
8325
|
+
await new Promise((resolve34) => setTimeout(resolve34, ms));
|
|
8308
8326
|
}
|
|
8309
8327
|
async function acquireFencedFileLock(options) {
|
|
8310
8328
|
const lockPath = `${options.path}.${options.name}.lock`;
|
|
@@ -8420,8 +8438,8 @@ function buildLock(lockPath, evictingPath, ownerId, options, now2) {
|
|
|
8420
8438
|
let released = false;
|
|
8421
8439
|
let lost = false;
|
|
8422
8440
|
let lostResolve = null;
|
|
8423
|
-
let lostPromise = new Promise((
|
|
8424
|
-
lostResolve =
|
|
8441
|
+
let lostPromise = new Promise((resolve34) => {
|
|
8442
|
+
lostResolve = resolve34;
|
|
8425
8443
|
});
|
|
8426
8444
|
const markLost = () => {
|
|
8427
8445
|
if (lost)
|
|
@@ -8431,9 +8449,9 @@ function buildLock(lockPath, evictingPath, ownerId, options, now2) {
|
|
|
8431
8449
|
clearInterval(renewTimer);
|
|
8432
8450
|
renewTimer = null;
|
|
8433
8451
|
}
|
|
8434
|
-
const
|
|
8452
|
+
const resolve34 = lostResolve;
|
|
8435
8453
|
lostResolve = null;
|
|
8436
|
-
|
|
8454
|
+
resolve34?.();
|
|
8437
8455
|
};
|
|
8438
8456
|
const setupRenew = () => {
|
|
8439
8457
|
if (options.renew === false)
|
|
@@ -9056,7 +9074,7 @@ async function saveAccountStorageReplace(path5, incoming) {
|
|
|
9056
9074
|
return mutateAccountStorage(path5, () => incoming);
|
|
9057
9075
|
}
|
|
9058
9076
|
async function clearAccountStorage(path5) {
|
|
9059
|
-
const sleep5 = (ms) => new Promise((
|
|
9077
|
+
const sleep5 = (ms) => new Promise((resolve34) => setTimeout(resolve34, ms));
|
|
9060
9078
|
const lock = await acquireWithRetry(path5, sleep5);
|
|
9061
9079
|
try {
|
|
9062
9080
|
await assertLegacyAccountStorageWritable(path5);
|
|
@@ -9104,7 +9122,7 @@ var init_account_storage = __esm({
|
|
|
9104
9122
|
}
|
|
9105
9123
|
};
|
|
9106
9124
|
RETRY_DELAYS_MS = [100, 200, 400, 800, 1e3];
|
|
9107
|
-
DEFAULT_SLEEP = (ms) => new Promise((
|
|
9125
|
+
DEFAULT_SLEEP = (ms) => new Promise((resolve34) => setTimeout(resolve34, ms));
|
|
9108
9126
|
DEFAULT_BUILD_BACKUP_PATH = (path5, now2) => `${path5}.corrupt-${now2.toISOString().replace(/[:.]/g, "-")}`;
|
|
9109
9127
|
}
|
|
9110
9128
|
});
|
|
@@ -9202,7 +9220,7 @@ function isStorageLockContention(error) {
|
|
|
9202
9220
|
function quotaAccountIdentity(refreshToken) {
|
|
9203
9221
|
return createHash3("sha256").update(refreshToken).digest("hex").slice(0, 16);
|
|
9204
9222
|
}
|
|
9205
|
-
function applyPendingRowWrite(metadata, pending, now2) {
|
|
9223
|
+
function applyPendingRowWrite(metadata, pending, now2, storedReadingAt) {
|
|
9206
9224
|
let next = metadata;
|
|
9207
9225
|
const resets = {};
|
|
9208
9226
|
const cleared = [];
|
|
@@ -9224,7 +9242,7 @@ function applyPendingRowWrite(metadata, pending, now2) {
|
|
|
9224
9242
|
delete written[key2];
|
|
9225
9243
|
next = { ...next, rateLimitResetTimes: rates, rateLimitWrittenAt: written };
|
|
9226
9244
|
}
|
|
9227
|
-
if (pending.readingUpdate)
|
|
9245
|
+
if (storedReadingAt != null && pending.readingUpdate?.checkedAt === storedReadingAt)
|
|
9228
9246
|
next = applyRateLimitReadingUpdate(next, pending.readingUpdate, now2);
|
|
9229
9247
|
if (pending.cooldown !== void 0) {
|
|
9230
9248
|
next = applyCooldownObservation(next, pending.cooldown.value);
|
|
@@ -9979,7 +9997,7 @@ var init_account_manager = __esm({
|
|
|
9979
9997
|
for (const pending of rows) {
|
|
9980
9998
|
repository.updateMetadata(pending.ref, (current, row) => ({
|
|
9981
9999
|
kind: "set",
|
|
9982
|
-
metadata: applyPendingRowWrite(current ?? { addedAt: row.storeAddedAt ?? this.now(), lastUsed: 0 }, pending, this.now())
|
|
10000
|
+
metadata: applyPendingRowWrite(current ?? { addedAt: row.storeAddedAt ?? this.now(), lastUsed: 0 }, pending, this.now(), row.quota.status === "present" ? row.quota.quota.cachedQuotaUpdatedAt : void 0)
|
|
9983
10001
|
})).catch((error) => {
|
|
9984
10002
|
if (error instanceof AccountRepositoryError && error.failure.kind === "lock-contention" && !error.failure.ambiguous) {
|
|
9985
10003
|
this.requeueRowWrite(pending);
|
|
@@ -10358,8 +10376,8 @@ var init_account_manager = __esm({
|
|
|
10358
10376
|
await this.saveInFlight;
|
|
10359
10377
|
return;
|
|
10360
10378
|
}
|
|
10361
|
-
return new Promise((
|
|
10362
|
-
this.savePromiseResolvers.push({ resolve:
|
|
10379
|
+
return new Promise((resolve34, reject) => {
|
|
10380
|
+
this.savePromiseResolvers.push({ resolve: resolve34, reject });
|
|
10363
10381
|
});
|
|
10364
10382
|
}
|
|
10365
10383
|
async dispose() {
|
|
@@ -10402,8 +10420,8 @@ var init_account_manager = __esm({
|
|
|
10402
10420
|
reject(error);
|
|
10403
10421
|
throw error;
|
|
10404
10422
|
}
|
|
10405
|
-
for (const { resolve:
|
|
10406
|
-
|
|
10423
|
+
for (const { resolve: resolve34 } of resolvers)
|
|
10424
|
+
resolve34();
|
|
10407
10425
|
}
|
|
10408
10426
|
async executeSave() {
|
|
10409
10427
|
this.savePending = false;
|
|
@@ -10417,16 +10435,16 @@ var init_account_manager = __esm({
|
|
|
10417
10435
|
}
|
|
10418
10436
|
try {
|
|
10419
10437
|
await this.saveToDisk();
|
|
10420
|
-
for (const { resolve:
|
|
10421
|
-
|
|
10438
|
+
for (const { resolve: resolve34 } of resolvers) {
|
|
10439
|
+
resolve34();
|
|
10422
10440
|
}
|
|
10423
10441
|
} catch (error) {
|
|
10424
10442
|
if (isStorageLockContention(error)) {
|
|
10425
10443
|
this.onDiagnostic?.("Skipped account-state persist due to storage lock contention", {
|
|
10426
10444
|
error: String(error)
|
|
10427
10445
|
});
|
|
10428
|
-
for (const { resolve:
|
|
10429
|
-
|
|
10446
|
+
for (const { resolve: resolve34 } of resolvers) {
|
|
10447
|
+
resolve34();
|
|
10430
10448
|
}
|
|
10431
10449
|
return;
|
|
10432
10450
|
}
|
|
@@ -10464,13 +10482,13 @@ var init_account_manager = __esm({
|
|
|
10464
10482
|
getAccountFingerprintHistory(accountIndex) {
|
|
10465
10483
|
return this.selection.getAccountFingerprintHistory(accountIndex);
|
|
10466
10484
|
}
|
|
10467
|
-
updateQuotaCache(accountIndex, quotaGroups, expectedRefreshToken) {
|
|
10485
|
+
updateQuotaCache(accountIndex, quotaGroups, expectedRefreshToken, checkedAt = this.now()) {
|
|
10468
10486
|
const account = this.accounts[accountIndex];
|
|
10469
|
-
if (!account || account.parts.refreshToken !== expectedRefreshToken && expectedRefreshToken !== void 0)
|
|
10470
|
-
return;
|
|
10487
|
+
if (!account || account.parts.refreshToken !== expectedRefreshToken && expectedRefreshToken !== void 0 || !Number.isFinite(checkedAt) || account.cachedQuotaUpdatedAt !== void 0 && checkedAt < account.cachedQuotaUpdatedAt)
|
|
10488
|
+
return false;
|
|
10471
10489
|
account.cachedQuota = quotaGroups;
|
|
10472
10490
|
account.cachedQuotaAccountId = quotaAccountIdentity(account.parts.refreshToken);
|
|
10473
|
-
account.cachedQuotaUpdatedAt =
|
|
10491
|
+
account.cachedQuotaUpdatedAt = checkedAt;
|
|
10474
10492
|
this.selection.reconcileQuotaReading(account, this.repository === void 0);
|
|
10475
10493
|
const pending = account.ref ? this.pendingRowWrites.get(rowRefKey(account.ref)) : void 0;
|
|
10476
10494
|
if (pending)
|
|
@@ -10486,6 +10504,7 @@ var init_account_manager = __esm({
|
|
|
10486
10504
|
cachedQuotaUpdatedAt: account.cachedQuotaUpdatedAt
|
|
10487
10505
|
};
|
|
10488
10506
|
this.dispatch(account, "quota reading", (repository, ref) => repository.recordQuota(ref, reading));
|
|
10507
|
+
return true;
|
|
10489
10508
|
}
|
|
10490
10509
|
/**
|
|
10491
10510
|
* Apply a subset of fields from a quota-fetch `updatedAccount` result onto
|
|
@@ -10610,6 +10629,35 @@ var init_account_manager = __esm({
|
|
|
10610
10629
|
}
|
|
10611
10630
|
return targets;
|
|
10612
10631
|
}
|
|
10632
|
+
/** Fresh durable observations for poll admission, without flushing local writes. */
|
|
10633
|
+
async readAccountsForQuotaPoll() {
|
|
10634
|
+
if (!this.repository) {
|
|
10635
|
+
const accounts = new Map(this.accounts.map((a) => [a.parts.refreshToken, a]));
|
|
10636
|
+
return this.getAccountsForQuotaCheck().map((target) => {
|
|
10637
|
+
const account = accounts.get(target.refreshToken);
|
|
10638
|
+
return {
|
|
10639
|
+
...target,
|
|
10640
|
+
cachedQuotaUpdatedAt: account?.cachedQuota && account.cachedQuotaUpdatedAt
|
|
10641
|
+
};
|
|
10642
|
+
});
|
|
10643
|
+
}
|
|
10644
|
+
const read = await this.repository.read();
|
|
10645
|
+
if (read.status !== "ready")
|
|
10646
|
+
throw new Error("The account store is not ready for quota polling");
|
|
10647
|
+
const rows = new Map(read.rows.filter((row) => row.usable && row.enabled).map((row) => [rowRefKey(row.ref), row]));
|
|
10648
|
+
return this.getAccountsForQuotaCheck().flatMap((target) => {
|
|
10649
|
+
const row = target.rowRef && rows.get(rowRefKey(target.rowRef));
|
|
10650
|
+
if (!row)
|
|
10651
|
+
return [];
|
|
10652
|
+
const quota = row.quota.status === "present" ? row.quota.quota : void 0;
|
|
10653
|
+
return [
|
|
10654
|
+
{
|
|
10655
|
+
...target,
|
|
10656
|
+
cachedQuotaUpdatedAt: quota?.cachedQuota == null ? void 0 : quota.cachedQuotaUpdatedAt ?? void 0
|
|
10657
|
+
}
|
|
10658
|
+
];
|
|
10659
|
+
});
|
|
10660
|
+
}
|
|
10613
10661
|
getOldestQuotaCacheAge() {
|
|
10614
10662
|
return this.selection.getOldestQuotaCacheAge();
|
|
10615
10663
|
}
|
|
@@ -10688,6 +10736,14 @@ function orderAgyRequestPayloadInPlace(payload) {
|
|
|
10688
10736
|
function countAgyRequestSteps(payload) {
|
|
10689
10737
|
return Array.isArray(payload.contents) ? payload.contents.length : 0;
|
|
10690
10738
|
}
|
|
10739
|
+
function appendAgyContinuation(contents, wireModel) {
|
|
10740
|
+
const last = contents.at(-1);
|
|
10741
|
+
if (last?.role !== "model" && last?.role !== "assistant")
|
|
10742
|
+
return;
|
|
10743
|
+
if (last.role === "model" && wireModel.startsWith("gemini-") && Array.isArray(last.parts) && last.parts.length > 0 && last.parts.every((part) => part?.functionResponse))
|
|
10744
|
+
return;
|
|
10745
|
+
contents.push({ role: "user", parts: [{ text: "[Continue]" }] });
|
|
10746
|
+
}
|
|
10691
10747
|
function hasSecondUserTurn(payload) {
|
|
10692
10748
|
if (!Array.isArray(payload.contents))
|
|
10693
10749
|
return false;
|
|
@@ -10933,7 +10989,7 @@ function getHttpsProxy(url) {
|
|
|
10933
10989
|
}
|
|
10934
10990
|
}
|
|
10935
10991
|
function waitForHead(socket, timeoutMs, onTimeout) {
|
|
10936
|
-
return new Promise((
|
|
10992
|
+
return new Promise((resolve34, reject) => {
|
|
10937
10993
|
let buffer = Buffer3.alloc(0);
|
|
10938
10994
|
const timeout = setTimeout(() => {
|
|
10939
10995
|
onTimeout();
|
|
@@ -10956,7 +11012,7 @@ function waitForHead(socket, timeoutMs, onTimeout) {
|
|
|
10956
11012
|
return;
|
|
10957
11013
|
const head = buffer.subarray(0, marker).toString("latin1");
|
|
10958
11014
|
const leftover = buffer.subarray(marker + 4);
|
|
10959
|
-
cleanup2(() =>
|
|
11015
|
+
cleanup2(() => resolve34({ head, leftover }));
|
|
10960
11016
|
};
|
|
10961
11017
|
socket.on("data", onData);
|
|
10962
11018
|
socket.once("error", onError);
|
|
@@ -10970,7 +11026,7 @@ async function connectViaProxy(proxyUrl, targetUrl, timeoutMs, signal, onDebug)
|
|
|
10970
11026
|
port: Number(proxyUrl.port || DEFAULT_PROXY_PORT),
|
|
10971
11027
|
signal: signal ?? void 0
|
|
10972
11028
|
});
|
|
10973
|
-
await new Promise((
|
|
11029
|
+
await new Promise((resolve34, reject) => {
|
|
10974
11030
|
const timeout = setTimeout(() => {
|
|
10975
11031
|
onDebug?.(`agy transport proxy connect timeout after ${timeoutMs}ms`);
|
|
10976
11032
|
proxySocket.destroy();
|
|
@@ -10979,7 +11035,7 @@ async function connectViaProxy(proxyUrl, targetUrl, timeoutMs, signal, onDebug)
|
|
|
10979
11035
|
const cleanup2 = () => clearTimeout(timeout);
|
|
10980
11036
|
proxySocket.once("connect", () => {
|
|
10981
11037
|
cleanup2();
|
|
10982
|
-
|
|
11038
|
+
resolve34();
|
|
10983
11039
|
});
|
|
10984
11040
|
proxySocket.once("error", (error) => {
|
|
10985
11041
|
cleanup2();
|
|
@@ -11004,7 +11060,7 @@ Host: ${targetHost}:${targetPort}\r
|
|
|
11004
11060
|
if (leftover.length > 0) {
|
|
11005
11061
|
proxySocket.unshift(leftover);
|
|
11006
11062
|
}
|
|
11007
|
-
return await new Promise((
|
|
11063
|
+
return await new Promise((resolve34, reject) => {
|
|
11008
11064
|
const tlsOptions = {
|
|
11009
11065
|
socket: proxySocket,
|
|
11010
11066
|
servername: targetHost,
|
|
@@ -11020,7 +11076,7 @@ Host: ${targetHost}:${targetPort}\r
|
|
|
11020
11076
|
const cleanup2 = () => clearTimeout(timeout);
|
|
11021
11077
|
tlsSocket.once("secureConnect", () => {
|
|
11022
11078
|
cleanup2();
|
|
11023
|
-
|
|
11079
|
+
resolve34(tlsSocket);
|
|
11024
11080
|
});
|
|
11025
11081
|
tlsSocket.once("error", (error) => {
|
|
11026
11082
|
cleanup2();
|
|
@@ -11029,7 +11085,7 @@ Host: ${targetHost}:${targetPort}\r
|
|
|
11029
11085
|
});
|
|
11030
11086
|
}
|
|
11031
11087
|
async function connectDirect(targetUrl, timeoutMs, signal, onDebug) {
|
|
11032
|
-
return await new Promise((
|
|
11088
|
+
return await new Promise((resolve34, reject) => {
|
|
11033
11089
|
const tlsOptions = {
|
|
11034
11090
|
host: targetUrl.hostname,
|
|
11035
11091
|
port: Number(targetUrl.port || DEFAULT_HTTPS_PORT),
|
|
@@ -11046,7 +11102,7 @@ async function connectDirect(targetUrl, timeoutMs, signal, onDebug) {
|
|
|
11046
11102
|
const cleanup2 = () => clearTimeout(timeout);
|
|
11047
11103
|
socket.once("secureConnect", () => {
|
|
11048
11104
|
cleanup2();
|
|
11049
|
-
|
|
11105
|
+
resolve34(socket);
|
|
11050
11106
|
});
|
|
11051
11107
|
socket.once("error", (error) => {
|
|
11052
11108
|
cleanup2();
|
|
@@ -11132,15 +11188,24 @@ function buildResponseStream(socket, leftover, head, signal, idleTimeoutMs, onDe
|
|
|
11132
11188
|
source.write(leftover);
|
|
11133
11189
|
}
|
|
11134
11190
|
socket.pipe(source);
|
|
11191
|
+
const stages = [source];
|
|
11192
|
+
let framing;
|
|
11135
11193
|
let responseBody = source;
|
|
11136
11194
|
if (head.chunked) {
|
|
11137
|
-
|
|
11195
|
+
framing = new ChunkedDecodeStream();
|
|
11138
11196
|
} else if (typeof head.contentLength === "number") {
|
|
11139
|
-
|
|
11197
|
+
framing = new ContentLengthStream(head.contentLength);
|
|
11198
|
+
}
|
|
11199
|
+
if (framing) {
|
|
11200
|
+
responseBody = responseBody.pipe(framing);
|
|
11201
|
+
stages.push(framing);
|
|
11140
11202
|
}
|
|
11141
11203
|
if (head.gzip) {
|
|
11142
11204
|
responseBody = responseBody.pipe(createGunzip());
|
|
11205
|
+
stages.push(responseBody);
|
|
11143
11206
|
}
|
|
11207
|
+
let settled = false;
|
|
11208
|
+
let socketEnded = false;
|
|
11144
11209
|
let idleTimer;
|
|
11145
11210
|
const clearIdle = () => {
|
|
11146
11211
|
if (idleTimer) {
|
|
@@ -11154,31 +11219,55 @@ function buildResponseStream(socket, leftover, head, signal, idleTimeoutMs, onDe
|
|
|
11154
11219
|
clearIdle();
|
|
11155
11220
|
idleTimer = setTimeout(() => {
|
|
11156
11221
|
onDebug?.(`agy transport idle timeout after ${idleTimeoutMs}ms with no body data`);
|
|
11157
|
-
|
|
11222
|
+
settle(new Error("Antigravity response stalled: no body data within the limit"));
|
|
11158
11223
|
}, idleTimeoutMs);
|
|
11159
11224
|
};
|
|
11160
|
-
|
|
11161
|
-
|
|
11162
|
-
|
|
11163
|
-
|
|
11225
|
+
const abort = () => settle(new DOMException("The operation was aborted", "AbortError"));
|
|
11226
|
+
const onSocketEnd = () => {
|
|
11227
|
+
socketEnded = true;
|
|
11228
|
+
};
|
|
11229
|
+
const onSocketClose = () => {
|
|
11230
|
+
if (!socketEnded && !framing?.complete) {
|
|
11231
|
+
settle(new Error("Antigravity response connection closed before the body ended"));
|
|
11232
|
+
}
|
|
11233
|
+
};
|
|
11234
|
+
const fail2 = (error) => settle(error instanceof Error ? error : new Error(String(error)));
|
|
11235
|
+
function settle(error) {
|
|
11236
|
+
if (settled)
|
|
11237
|
+
return;
|
|
11238
|
+
settled = true;
|
|
11164
11239
|
clearIdle();
|
|
11165
11240
|
socket.off("data", armIdle);
|
|
11241
|
+
socket.off("end", onSocketEnd);
|
|
11242
|
+
socket.off("close", onSocketClose);
|
|
11166
11243
|
signal?.removeEventListener("abort", abort);
|
|
11167
|
-
|
|
11244
|
+
socket.unpipe(source);
|
|
11245
|
+
socket.destroy();
|
|
11246
|
+
for (const stage of stages) {
|
|
11247
|
+
if (stage !== responseBody && !stage.destroyed)
|
|
11248
|
+
stage.destroy();
|
|
11249
|
+
}
|
|
11250
|
+
if (!responseBody.destroyed) {
|
|
11251
|
+
if (error)
|
|
11252
|
+
responseBody.destroy(error);
|
|
11253
|
+
else if (!responseBody.readableEnded)
|
|
11254
|
+
responseBody.destroy();
|
|
11255
|
+
}
|
|
11256
|
+
}
|
|
11257
|
+
socket.on("error", fail2);
|
|
11258
|
+
socket.on("data", armIdle);
|
|
11259
|
+
socket.once("end", onSocketEnd);
|
|
11260
|
+
socket.once("close", onSocketClose);
|
|
11261
|
+
for (const stage of stages)
|
|
11262
|
+
stage.on("error", fail2);
|
|
11263
|
+
responseBody.once("end", () => settle());
|
|
11264
|
+
responseBody.once("close", () => settle());
|
|
11265
|
+
armIdle();
|
|
11168
11266
|
if (signal?.aborted) {
|
|
11169
11267
|
abort();
|
|
11170
11268
|
} else {
|
|
11171
11269
|
signal?.addEventListener("abort", abort, { once: true });
|
|
11172
11270
|
}
|
|
11173
|
-
responseBody.once("end", () => {
|
|
11174
|
-
cleanup2();
|
|
11175
|
-
socket.destroy();
|
|
11176
|
-
});
|
|
11177
|
-
responseBody.once("error", () => {
|
|
11178
|
-
cleanup2();
|
|
11179
|
-
socket.destroy();
|
|
11180
|
-
});
|
|
11181
|
-
responseBody.once("close", cleanup2);
|
|
11182
11271
|
return Readable.toWeb(responseBody);
|
|
11183
11272
|
}
|
|
11184
11273
|
async function fetchWithAgyCliTransport(url, init = {}, options = {}) {
|
|
@@ -11236,6 +11325,11 @@ var init_agy_transport = __esm({
|
|
|
11236
11325
|
constructor(contentLength) {
|
|
11237
11326
|
super();
|
|
11238
11327
|
this.remaining = contentLength;
|
|
11328
|
+
if (this.remaining <= 0)
|
|
11329
|
+
this.push(null);
|
|
11330
|
+
}
|
|
11331
|
+
get complete() {
|
|
11332
|
+
return this.remaining <= 0;
|
|
11239
11333
|
}
|
|
11240
11334
|
_transform(chunk, _encoding, callback) {
|
|
11241
11335
|
if (this.remaining <= 0) {
|
|
@@ -11254,10 +11348,21 @@ var init_agy_transport = __esm({
|
|
|
11254
11348
|
}
|
|
11255
11349
|
callback();
|
|
11256
11350
|
}
|
|
11351
|
+
_flush(callback) {
|
|
11352
|
+
callback(this.remaining > 0 ? new Error("Antigravity response ended before its declared length") : null);
|
|
11353
|
+
}
|
|
11257
11354
|
};
|
|
11258
11355
|
ChunkedDecodeStream = class extends Transform {
|
|
11259
11356
|
buffer = Buffer3.alloc(0);
|
|
11357
|
+
finished = false;
|
|
11358
|
+
get complete() {
|
|
11359
|
+
return this.finished;
|
|
11360
|
+
}
|
|
11260
11361
|
_transform(chunk, _encoding, callback) {
|
|
11362
|
+
if (this.finished) {
|
|
11363
|
+
callback();
|
|
11364
|
+
return;
|
|
11365
|
+
}
|
|
11261
11366
|
this.buffer = Buffer3.concat([this.buffer, chunk]);
|
|
11262
11367
|
try {
|
|
11263
11368
|
this.flushAvailableChunks();
|
|
@@ -11268,8 +11373,9 @@ var init_agy_transport = __esm({
|
|
|
11268
11373
|
}
|
|
11269
11374
|
_flush(callback) {
|
|
11270
11375
|
try {
|
|
11271
|
-
this.
|
|
11272
|
-
|
|
11376
|
+
if (!this.finished)
|
|
11377
|
+
this.flushAvailableChunks();
|
|
11378
|
+
callback(this.finished ? null : new Error("Antigravity response ended before its final chunk"));
|
|
11273
11379
|
} catch (error) {
|
|
11274
11380
|
callback(error instanceof Error ? error : new Error(String(error)));
|
|
11275
11381
|
}
|
|
@@ -11285,16 +11391,19 @@ var init_agy_transport = __esm({
|
|
|
11285
11391
|
if (!Number.isFinite(size)) {
|
|
11286
11392
|
throw new Error(`Invalid chunk size: ${sizeLine}`);
|
|
11287
11393
|
}
|
|
11288
|
-
const chunkStart = lineEnd + 2;
|
|
11289
|
-
const chunkEnd = chunkStart + size;
|
|
11290
|
-
const nextOffset = chunkEnd + 2;
|
|
11291
|
-
if (this.buffer.length < nextOffset)
|
|
11292
|
-
return;
|
|
11293
11394
|
if (size === 0) {
|
|
11395
|
+
if (this.buffer.indexOf("\r\n\r\n", lineEnd) === -1)
|
|
11396
|
+
return;
|
|
11397
|
+
this.finished = true;
|
|
11294
11398
|
this.buffer = Buffer3.alloc(0);
|
|
11295
11399
|
this.push(null);
|
|
11296
11400
|
return;
|
|
11297
11401
|
}
|
|
11402
|
+
const chunkStart = lineEnd + 2;
|
|
11403
|
+
const chunkEnd = chunkStart + size;
|
|
11404
|
+
const nextOffset = chunkEnd + 2;
|
|
11405
|
+
if (this.buffer.length < nextOffset)
|
|
11406
|
+
return;
|
|
11298
11407
|
this.push(this.buffer.subarray(chunkStart, chunkEnd));
|
|
11299
11408
|
this.buffer = this.buffer.subarray(nextOffset);
|
|
11300
11409
|
}
|
|
@@ -13855,8 +13964,8 @@ async function acquireRefreshFileLockWithClock(options) {
|
|
|
13855
13964
|
let releaseConfirmed = false;
|
|
13856
13965
|
let loss;
|
|
13857
13966
|
let resolveLoss;
|
|
13858
|
-
const lostPromise = new Promise((
|
|
13859
|
-
resolveLoss =
|
|
13967
|
+
const lostPromise = new Promise((resolve34) => {
|
|
13968
|
+
resolveLoss = resolve34;
|
|
13860
13969
|
});
|
|
13861
13970
|
function notifyTimerStep(event) {
|
|
13862
13971
|
try {
|
|
@@ -14020,7 +14129,7 @@ async function acquireRefreshFileLockWithClock(options) {
|
|
|
14020
14129
|
}
|
|
14021
14130
|
}
|
|
14022
14131
|
async function backoff() {
|
|
14023
|
-
await new Promise((
|
|
14132
|
+
await new Promise((resolve34) => setTimeout(resolve34, Math.floor(Math.random() * 4)));
|
|
14024
14133
|
}
|
|
14025
14134
|
async function readLockState(notifyReady = true) {
|
|
14026
14135
|
if (notifyReady && options.onStep)
|
|
@@ -14113,7 +14222,7 @@ async function acquireRefreshFileLockWithClock(options) {
|
|
|
14113
14222
|
const remainingMs = deadline - performance.now();
|
|
14114
14223
|
if (remainingMs <= 0)
|
|
14115
14224
|
throw original;
|
|
14116
|
-
await new Promise((
|
|
14225
|
+
await new Promise((resolve34) => setTimeout(resolve34, Math.min(delayMs, remainingMs)));
|
|
14117
14226
|
if (performance.now() >= deadline)
|
|
14118
14227
|
throw original;
|
|
14119
14228
|
delayMs = Math.min(delayMs * 2, 50);
|
|
@@ -14616,7 +14725,7 @@ async function acquireRefreshFileLockWithClock(options) {
|
|
|
14616
14725
|
const remainingMs = deadline - performance.now();
|
|
14617
14726
|
if (remainingMs <= 0)
|
|
14618
14727
|
break;
|
|
14619
|
-
await new Promise((
|
|
14728
|
+
await new Promise((resolve34) => setTimeout(resolve34, Math.min(delayMs, remainingMs)));
|
|
14620
14729
|
if (windowsPrivateFiles && performance.now() >= deadline)
|
|
14621
14730
|
break;
|
|
14622
14731
|
delayMs = Math.min(delayMs * 2, 50);
|
|
@@ -14701,7 +14810,7 @@ async function withLock(target, options, fn) {
|
|
|
14701
14810
|
timeoutMs: options.timeoutMs
|
|
14702
14811
|
});
|
|
14703
14812
|
}
|
|
14704
|
-
await new Promise((
|
|
14813
|
+
await new Promise((resolve34) => setTimeout(resolve34, Math.min(25, Math.ceil(remaining))));
|
|
14705
14814
|
}
|
|
14706
14815
|
}
|
|
14707
14816
|
var LockContentionError, LockOwnershipError;
|
|
@@ -14791,7 +14900,7 @@ async function acquirePoolLock(spec, defaults2, env3) {
|
|
|
14791
14900
|
});
|
|
14792
14901
|
}
|
|
14793
14902
|
const jitter = Math.floor(Math.random() * (options.retryMs + 1));
|
|
14794
|
-
await new Promise((
|
|
14903
|
+
await new Promise((resolve34) => setTimeout(resolve34, Math.min(options.retryMs + jitter, remaining)));
|
|
14795
14904
|
}
|
|
14796
14905
|
}
|
|
14797
14906
|
function definedOnly(spec) {
|
|
@@ -17704,11 +17813,11 @@ var init_quota_writer = __esm({
|
|
|
17704
17813
|
const left = deadline - performance.now();
|
|
17705
17814
|
if (left <= 0)
|
|
17706
17815
|
throw refusal2("pull", id, "lock-contention", `pool quota queue for ${id} is full (${POOL_QUOTA_QUEUE_LIMIT} readings) and the store locks stayed held`, true);
|
|
17707
|
-
await new Promise((
|
|
17816
|
+
await new Promise((resolve34) => {
|
|
17708
17817
|
const done = () => {
|
|
17709
17818
|
clearTimeout(timer);
|
|
17710
17819
|
this.wake.delete(done);
|
|
17711
|
-
|
|
17820
|
+
resolve34();
|
|
17712
17821
|
};
|
|
17713
17822
|
const timer = setTimeout(done, left);
|
|
17714
17823
|
this.wake.add(done);
|
|
@@ -20440,6 +20549,8 @@ async function request(operation) {
|
|
|
20440
20549
|
function wrapHostClient(client) {
|
|
20441
20550
|
const watchScoped = client.watchScoped?.bind(client);
|
|
20442
20551
|
const reportUsageScoped = client.reportUsageScoped?.bind(client);
|
|
20552
|
+
const reportCondition = client.reportCondition?.bind(client);
|
|
20553
|
+
const clearCondition = client.clearCondition?.bind(client);
|
|
20443
20554
|
return {
|
|
20444
20555
|
listScoped: (...args) => request(() => client.listScoped(...args)),
|
|
20445
20556
|
getScoped: (...args) => request(() => client.getScoped(...args)),
|
|
@@ -20460,6 +20571,12 @@ function wrapHostClient(client) {
|
|
|
20460
20571
|
...reportUsageScoped && {
|
|
20461
20572
|
reportUsageScoped: (...args) => request(() => reportUsageScoped(...args))
|
|
20462
20573
|
},
|
|
20574
|
+
...reportCondition && {
|
|
20575
|
+
reportCondition: (...args) => request(() => reportCondition(...args))
|
|
20576
|
+
},
|
|
20577
|
+
...clearCondition && {
|
|
20578
|
+
clearCondition: (...args) => request(() => clearCondition(...args))
|
|
20579
|
+
},
|
|
20463
20580
|
...client.insula && {
|
|
20464
20581
|
insula: wrapInsula(client.insula)
|
|
20465
20582
|
}
|
|
@@ -20831,7 +20948,7 @@ async function select(terminal, items, options) {
|
|
|
20831
20948
|
writeLine("");
|
|
20832
20949
|
renderedLines = lines;
|
|
20833
20950
|
};
|
|
20834
|
-
return new Promise((
|
|
20951
|
+
return new Promise((resolve34) => {
|
|
20835
20952
|
const wasRaw = stdin.isRaw ?? false;
|
|
20836
20953
|
const cleanup2 = () => {
|
|
20837
20954
|
if (cleaned)
|
|
@@ -20851,7 +20968,7 @@ async function select(terminal, items, options) {
|
|
|
20851
20968
|
};
|
|
20852
20969
|
const finish = (value) => {
|
|
20853
20970
|
cleanup2();
|
|
20854
|
-
|
|
20971
|
+
resolve34(value);
|
|
20855
20972
|
};
|
|
20856
20973
|
const onSignal = () => finish(null);
|
|
20857
20974
|
const onKey = (data) => {
|
|
@@ -20891,7 +21008,7 @@ async function select(terminal, items, options) {
|
|
|
20891
21008
|
stdin.setRawMode(true);
|
|
20892
21009
|
} catch {
|
|
20893
21010
|
cleanup2();
|
|
20894
|
-
|
|
21011
|
+
resolve34(null);
|
|
20895
21012
|
return;
|
|
20896
21013
|
}
|
|
20897
21014
|
stdin.resume();
|
|
@@ -22917,10 +23034,10 @@ async function drainShutdown(pending, onTimeout) {
|
|
|
22917
23034
|
try {
|
|
22918
23035
|
await Promise.race([
|
|
22919
23036
|
drained,
|
|
22920
|
-
new Promise((
|
|
23037
|
+
new Promise((resolve34) => {
|
|
22921
23038
|
timer = setTimeout(() => {
|
|
22922
23039
|
expired = true;
|
|
22923
|
-
|
|
23040
|
+
resolve34();
|
|
22924
23041
|
}, 2e3);
|
|
22925
23042
|
})
|
|
22926
23043
|
]);
|
|
@@ -23197,6 +23314,28 @@ function rowFactsOf(row, { includeProviderIds = true } = {}) {
|
|
|
23197
23314
|
authMethod: metadata.authMethod
|
|
23198
23315
|
};
|
|
23199
23316
|
}
|
|
23317
|
+
function isVaultConditionReason(reason) {
|
|
23318
|
+
return reason === "provider_verification_required" || reason === "provider_ineligible";
|
|
23319
|
+
}
|
|
23320
|
+
function vaultConditionOf(row) {
|
|
23321
|
+
const condition = row.condition;
|
|
23322
|
+
if (!condition)
|
|
23323
|
+
return void 0;
|
|
23324
|
+
const { reason, sinceMs } = condition;
|
|
23325
|
+
if (isVaultConditionReason(reason) && Number.isSafeInteger(sinceMs) && sinceMs > 0)
|
|
23326
|
+
return Object.freeze({ reason, sinceMs });
|
|
23327
|
+
return void 0;
|
|
23328
|
+
}
|
|
23329
|
+
function httpsActionUrl(actionUrl) {
|
|
23330
|
+
if (typeof actionUrl !== "string")
|
|
23331
|
+
return void 0;
|
|
23332
|
+
try {
|
|
23333
|
+
if (new URL(actionUrl).protocol === "https:")
|
|
23334
|
+
return actionUrl;
|
|
23335
|
+
} catch {
|
|
23336
|
+
}
|
|
23337
|
+
return void 0;
|
|
23338
|
+
}
|
|
23200
23339
|
function grantReachOf(listed) {
|
|
23201
23340
|
const { grants, grantTuples } = listed;
|
|
23202
23341
|
if (grants === void 0 || grantTuples === void 0)
|
|
@@ -23235,6 +23374,10 @@ var init_custody = __esm({
|
|
|
23235
23374
|
#logger;
|
|
23236
23375
|
#provenance = /* @__PURE__ */ new WeakMap();
|
|
23237
23376
|
#reports = /* @__PURE__ */ new WeakMap();
|
|
23377
|
+
#conditionReports = /* @__PURE__ */ new Map();
|
|
23378
|
+
#conditionClears = /* @__PURE__ */ new Map();
|
|
23379
|
+
#conditionsUnsupported = false;
|
|
23380
|
+
#pendingConditionCalls = 0;
|
|
23238
23381
|
#kept = /* @__PURE__ */ new Map();
|
|
23239
23382
|
#keptAttempts = /* @__PURE__ */ new WeakMap();
|
|
23240
23383
|
#usage;
|
|
@@ -23253,8 +23396,9 @@ var init_custody = __esm({
|
|
|
23253
23396
|
#closed = false;
|
|
23254
23397
|
/** The view of the last successful `discover()`, for `watchRoster`. */
|
|
23255
23398
|
#discoveredView;
|
|
23399
|
+
#discoveredConditions = /* @__PURE__ */ new Map();
|
|
23256
23400
|
#watches = /* @__PURE__ */ new Set();
|
|
23257
|
-
#
|
|
23401
|
+
#shutdownWork = /* @__PURE__ */ new Set();
|
|
23258
23402
|
#warnShutdown;
|
|
23259
23403
|
#onDrainTimeout;
|
|
23260
23404
|
#disposing;
|
|
@@ -23313,6 +23457,7 @@ var init_custody = __esm({
|
|
|
23313
23457
|
if (hasVaultHost() && !isVaultHostClient(next))
|
|
23314
23458
|
throw new ClaustrumUnreachableError();
|
|
23315
23459
|
this.#client = next;
|
|
23460
|
+
this.#conditionsUnsupported = false;
|
|
23316
23461
|
for (const watch2 of this.#watches)
|
|
23317
23462
|
watch2.restart();
|
|
23318
23463
|
}
|
|
@@ -23381,12 +23526,12 @@ var init_custody = __esm({
|
|
|
23381
23526
|
phase: "token read begin"
|
|
23382
23527
|
});
|
|
23383
23528
|
const pending = this.#readToken();
|
|
23384
|
-
this.#
|
|
23529
|
+
this.#shutdownWork.add(pending);
|
|
23385
23530
|
let value;
|
|
23386
23531
|
try {
|
|
23387
23532
|
value = await pending;
|
|
23388
23533
|
} finally {
|
|
23389
|
-
this.#
|
|
23534
|
+
this.#shutdownWork.delete(pending);
|
|
23390
23535
|
if (phaseDiagnostics.hasSubscribers)
|
|
23391
23536
|
phaseDiagnostics.publish({
|
|
23392
23537
|
logger: this.#logger,
|
|
@@ -23439,6 +23584,11 @@ var init_custody = __esm({
|
|
|
23439
23584
|
async discover(signal) {
|
|
23440
23585
|
const inventory = await this.#list(signal);
|
|
23441
23586
|
this.#discoveredView = inventory.view;
|
|
23587
|
+
this.#discoveredConditions.clear();
|
|
23588
|
+
for (const { credentialId, condition } of inventory.credentials) {
|
|
23589
|
+
if (condition)
|
|
23590
|
+
this.#discoveredConditions.set(credentialId, condition);
|
|
23591
|
+
}
|
|
23442
23592
|
return inventory;
|
|
23443
23593
|
}
|
|
23444
23594
|
async #list(signal) {
|
|
@@ -23512,6 +23662,7 @@ var init_custody = __esm({
|
|
|
23512
23662
|
});
|
|
23513
23663
|
continue;
|
|
23514
23664
|
}
|
|
23665
|
+
const condition = vaultConditionOf(row);
|
|
23515
23666
|
credentials.push(Object.freeze({
|
|
23516
23667
|
credentialId: row.id,
|
|
23517
23668
|
credentialType: type,
|
|
@@ -23521,7 +23672,8 @@ var init_custody = __esm({
|
|
|
23521
23672
|
},
|
|
23522
23673
|
state: row.state,
|
|
23523
23674
|
...row.email !== void 0 && { email: row.email },
|
|
23524
|
-
...row.orgName !== void 0 && { orgName: row.orgName }
|
|
23675
|
+
...row.orgName !== void 0 && { orgName: row.orgName },
|
|
23676
|
+
...condition && { condition }
|
|
23525
23677
|
}));
|
|
23526
23678
|
}
|
|
23527
23679
|
for (const record5 of skipped)
|
|
@@ -23729,7 +23881,7 @@ var init_custody = __esm({
|
|
|
23729
23881
|
}
|
|
23730
23882
|
#receiptBackoff(delay5, signal) {
|
|
23731
23883
|
this.#check(signal);
|
|
23732
|
-
return new Promise((
|
|
23884
|
+
return new Promise((resolve34, reject) => {
|
|
23733
23885
|
const abort = () => {
|
|
23734
23886
|
this.#clearTimeout(timer);
|
|
23735
23887
|
signal.removeEventListener("abort", abort);
|
|
@@ -23737,7 +23889,7 @@ var init_custody = __esm({
|
|
|
23737
23889
|
};
|
|
23738
23890
|
const timer = this.#setTimeout(() => {
|
|
23739
23891
|
signal.removeEventListener("abort", abort);
|
|
23740
|
-
|
|
23892
|
+
resolve34();
|
|
23741
23893
|
}, delay5);
|
|
23742
23894
|
timer.unref?.();
|
|
23743
23895
|
signal.addEventListener("abort", abort, { once: true });
|
|
@@ -23866,6 +24018,90 @@ var init_custody = __esm({
|
|
|
23866
24018
|
throw error;
|
|
23867
24019
|
}
|
|
23868
24020
|
}
|
|
24021
|
+
/**
|
|
24022
|
+
* Report a provider login condition as bookkeeping after handing back the
|
|
24023
|
+
* reply, never on the request path. Pass the receipt actually sent with it.
|
|
24024
|
+
*/
|
|
24025
|
+
reportCondition(attempt, input2) {
|
|
24026
|
+
const provenance = this.#provenance.get(attempt);
|
|
24027
|
+
if (!provenance)
|
|
24028
|
+
return Promise.reject(new ClaustrumConsumerError("no-receipt", "Claustrum condition report requires an original dispatch receipt"));
|
|
24029
|
+
const { reason, providerStatus } = input2 ?? {};
|
|
24030
|
+
if (this.#closed || this.#keptAttempts.has(attempt) || providerStatus !== 403 || !isVaultConditionReason(reason))
|
|
24031
|
+
return Promise.resolve("skipped");
|
|
24032
|
+
const { credentialId, recordVersion } = attempt;
|
|
24033
|
+
const actionUrl = reason === "provider_verification_required" ? httpsActionUrl(input2.actionUrl) : void 0;
|
|
24034
|
+
return this.#conditionOnce(this.#conditionReports, JSON.stringify([credentialId, recordVersion, reason]), { credentialId, recordVersion, reason }, (client) => client.reportCondition?.({
|
|
24035
|
+
credentialId,
|
|
24036
|
+
recordVersion,
|
|
24037
|
+
reason,
|
|
24038
|
+
providerStatus,
|
|
24039
|
+
...actionUrl !== void 0 && { actionUrl },
|
|
24040
|
+
enrollmentToken: provenance.token
|
|
24041
|
+
}));
|
|
24042
|
+
}
|
|
24043
|
+
/**
|
|
24044
|
+
* Clear a listed condition as bookkeeping after handing back a successful
|
|
24045
|
+
* reply, never on the request path. Pass the receipt actually sent with it.
|
|
24046
|
+
*/
|
|
24047
|
+
clearCondition(attempt) {
|
|
24048
|
+
const provenance = this.#provenance.get(attempt);
|
|
24049
|
+
if (!provenance)
|
|
24050
|
+
return Promise.reject(new ClaustrumConsumerError("no-receipt", "Claustrum condition clear requires an original dispatch receipt"));
|
|
24051
|
+
if (this.#closed || this.#keptAttempts.has(attempt))
|
|
24052
|
+
return Promise.resolve("skipped");
|
|
24053
|
+
const { credentialId, recordVersion } = attempt;
|
|
24054
|
+
const condition = this.#discoveredConditions.get(credentialId);
|
|
24055
|
+
if (!condition)
|
|
24056
|
+
return Promise.resolve("skipped");
|
|
24057
|
+
return this.#conditionOnce(this.#conditionClears, JSON.stringify([credentialId, condition.sinceMs]), { credentialId, recordVersion, reason: condition.reason }, (client) => client.clearCondition?.({
|
|
24058
|
+
credentialId,
|
|
24059
|
+
recordVersion,
|
|
24060
|
+
enrollmentToken: provenance.token
|
|
24061
|
+
}));
|
|
24062
|
+
}
|
|
24063
|
+
#conditionOnce(outcomes, key2, details, send) {
|
|
24064
|
+
const previous = outcomes.get(key2);
|
|
24065
|
+
if (previous)
|
|
24066
|
+
return previous;
|
|
24067
|
+
if (this.#conditionsUnsupported)
|
|
24068
|
+
return Promise.resolve("unsupported");
|
|
24069
|
+
const pending = Promise.resolve().then(async () => {
|
|
24070
|
+
const client = this.#client;
|
|
24071
|
+
if (this.#conditionsUnsupported)
|
|
24072
|
+
return "unsupported";
|
|
24073
|
+
try {
|
|
24074
|
+
const sent = send(client);
|
|
24075
|
+
if (!sent)
|
|
24076
|
+
return "unsupported";
|
|
24077
|
+
if (await sent === false)
|
|
24078
|
+
this.#debugCondition("scoped login condition not cleared", details);
|
|
24079
|
+
return "reported";
|
|
24080
|
+
} catch (error) {
|
|
24081
|
+
if (error instanceof ClaustrumCredentialError5 && error.code === "unknown_method") {
|
|
24082
|
+
if (client === this.#client)
|
|
24083
|
+
this.#conditionsUnsupported = true;
|
|
24084
|
+
return "unsupported";
|
|
24085
|
+
}
|
|
24086
|
+
this.#debugCondition("scoped login condition update failed", details);
|
|
24087
|
+
return "failed";
|
|
24088
|
+
}
|
|
24089
|
+
});
|
|
24090
|
+
outcomes.set(key2, pending);
|
|
24091
|
+
this.#pendingConditionCalls++;
|
|
24092
|
+
this.#shutdownWork.add(pending);
|
|
24093
|
+
void pending.then(() => {
|
|
24094
|
+
this.#pendingConditionCalls--;
|
|
24095
|
+
this.#shutdownWork.delete(pending);
|
|
24096
|
+
});
|
|
24097
|
+
return pending;
|
|
24098
|
+
}
|
|
24099
|
+
#debugCondition(message, details) {
|
|
24100
|
+
try {
|
|
24101
|
+
this.#logger.debug(message, details);
|
|
24102
|
+
} catch {
|
|
24103
|
+
}
|
|
24104
|
+
}
|
|
23869
24105
|
/**
|
|
23870
24106
|
* Watch this consumer's visible vault accounts instead of listing them on a
|
|
23871
24107
|
* short timer. Opens one `watchScoped` on this custody's client and calls
|
|
@@ -23981,15 +24217,17 @@ var init_custody = __esm({
|
|
|
23981
24217
|
this.#watches.clear();
|
|
23982
24218
|
this.#kept.clear();
|
|
23983
24219
|
const usage = this.#usage.close();
|
|
24220
|
+
const keepClientOpen = usage !== void 0 || this.#pendingConditionCalls > 0;
|
|
23984
24221
|
if (usage) {
|
|
23985
|
-
this.#
|
|
23986
|
-
void usage.then(() => this.#
|
|
23987
|
-
}
|
|
24222
|
+
this.#shutdownWork.add(usage);
|
|
24223
|
+
void usage.then(() => this.#shutdownWork.delete(usage));
|
|
24224
|
+
}
|
|
24225
|
+
if (!keepClientOpen)
|
|
23988
24226
|
this.#client.close();
|
|
23989
|
-
this.#disposing = drainShutdown(this.#
|
|
24227
|
+
this.#disposing = drainShutdown(this.#shutdownWork, (count4) => (this.#onDrainTimeout ?? this.#warnShutdown)(count4)).finally(() => {
|
|
23990
24228
|
this.#usage.drop();
|
|
23991
24229
|
this.#usageServed.clear();
|
|
23992
|
-
if (
|
|
24230
|
+
if (keepClientOpen)
|
|
23993
24231
|
this.#client.close();
|
|
23994
24232
|
});
|
|
23995
24233
|
}
|
|
@@ -24973,7 +25211,7 @@ var init_consumer = __esm({
|
|
|
24973
25211
|
this.#shutdown.signal,
|
|
24974
25212
|
...signal ? [signal] : []
|
|
24975
25213
|
]);
|
|
24976
|
-
return new Promise((
|
|
25214
|
+
return new Promise((resolve34, reject) => {
|
|
24977
25215
|
const cleanup2 = () => {
|
|
24978
25216
|
combined.signal.removeEventListener("abort", abort);
|
|
24979
25217
|
combined.dispose();
|
|
@@ -24988,7 +25226,7 @@ var init_consumer = __esm({
|
|
|
24988
25226
|
if (combined.signal.aborted)
|
|
24989
25227
|
reject(combined.signal.reason);
|
|
24990
25228
|
else
|
|
24991
|
-
|
|
25229
|
+
resolve34(value);
|
|
24992
25230
|
}, (error) => {
|
|
24993
25231
|
cleanup2();
|
|
24994
25232
|
reject(error);
|
|
@@ -25584,6 +25822,36 @@ var init_consumer = __esm({
|
|
|
25584
25822
|
throw new ClaustrumConsumerError("no-receipt", "Claustrum dispatch receipt has no active owner");
|
|
25585
25823
|
await this.#custody.reportFailure(attempt, status, source);
|
|
25586
25824
|
}
|
|
25825
|
+
/** The custody (or hub lease) that issued `attempt`, or a `no-receipt` refusal. */
|
|
25826
|
+
#issuingCustody(attempt) {
|
|
25827
|
+
const custody = this.#hub ? this.#issuedBy.get(attempt)?.custody : this.#custody;
|
|
25828
|
+
if (!custody)
|
|
25829
|
+
throw new ClaustrumConsumerError("no-receipt", "Claustrum dispatch receipt has no active owner");
|
|
25830
|
+
return custody;
|
|
25831
|
+
}
|
|
25832
|
+
/**
|
|
25833
|
+
* Report a provider login condition through the custody that issued the
|
|
25834
|
+
* receipt; see `ClaustrumScopedCustody.reportCondition`. Bookkeeping: call it
|
|
25835
|
+
* after handing back the reply, never on the request path. It resolves
|
|
25836
|
+
* `skipped` after shutdown and rejects only with `no-receipt` for a receipt
|
|
25837
|
+
* no live custody of this consumer issued.
|
|
25838
|
+
*/
|
|
25839
|
+
async reportCondition(attempt, input2) {
|
|
25840
|
+
if (this.#shutdown.signal.aborted)
|
|
25841
|
+
return "skipped";
|
|
25842
|
+
return this.#issuingCustody(attempt).reportCondition(attempt, input2);
|
|
25843
|
+
}
|
|
25844
|
+
/**
|
|
25845
|
+
* Clear a listed login condition through the custody that issued the
|
|
25846
|
+
* receipt; see `ClaustrumScopedCustody.clearCondition`. Safe to call after
|
|
25847
|
+
* every successful reply: it sends nothing unless the login is marked.
|
|
25848
|
+
* Same `skipped` and `no-receipt` rules as `reportCondition`.
|
|
25849
|
+
*/
|
|
25850
|
+
async clearCondition(attempt) {
|
|
25851
|
+
if (this.#shutdown.signal.aborted)
|
|
25852
|
+
return "skipped";
|
|
25853
|
+
return this.#issuingCustody(attempt).clearCondition(attempt);
|
|
25854
|
+
}
|
|
25587
25855
|
/**
|
|
25588
25856
|
* Send on a vault route. `dispatch` builds and sends the request with the
|
|
25589
25857
|
* receipt's token and may be called twice, so it must be able to rebuild
|
|
@@ -25794,12 +26062,12 @@ function unreachableConnect2() {
|
|
|
25794
26062
|
return new ClaustrumUnreachableError();
|
|
25795
26063
|
}
|
|
25796
26064
|
function untilAborted(pending, signal) {
|
|
25797
|
-
return new Promise((
|
|
26065
|
+
return new Promise((resolve34, reject) => {
|
|
25798
26066
|
const abort = () => reject(signal.reason);
|
|
25799
26067
|
signal.addEventListener("abort", abort, { once: true });
|
|
25800
26068
|
pending.then((value) => {
|
|
25801
26069
|
signal.removeEventListener("abort", abort);
|
|
25802
|
-
|
|
26070
|
+
resolve34(value);
|
|
25803
26071
|
}, (error) => {
|
|
25804
26072
|
signal.removeEventListener("abort", abort);
|
|
25805
26073
|
reject(error);
|
|
@@ -26190,6 +26458,16 @@ var init_hub = __esm({
|
|
|
26190
26458
|
check();
|
|
26191
26459
|
return custody.reportFailure(attempt, status, source);
|
|
26192
26460
|
},
|
|
26461
|
+
reportCondition: async (attempt, input2) => {
|
|
26462
|
+
if (state2.released || generation.ended)
|
|
26463
|
+
return "skipped";
|
|
26464
|
+
return custody.reportCondition(attempt, input2);
|
|
26465
|
+
},
|
|
26466
|
+
clearCondition: async (attempt) => {
|
|
26467
|
+
if (state2.released || generation.ended)
|
|
26468
|
+
return "skipped";
|
|
26469
|
+
return custody.clearCondition(attempt);
|
|
26470
|
+
},
|
|
26193
26471
|
reportUsage: (input2) => {
|
|
26194
26472
|
if (!state2.released && !generation.ended)
|
|
26195
26473
|
custody.reportUsage(input2);
|
|
@@ -27174,13 +27452,13 @@ async function safeRead(path5, afterReadCheck) {
|
|
|
27174
27452
|
let file;
|
|
27175
27453
|
try {
|
|
27176
27454
|
file = await open7(path5, constants2.O_RDONLY | constants2.O_NOFOLLOW);
|
|
27177
|
-
const
|
|
27178
|
-
if (!
|
|
27455
|
+
const stat22 = await file.stat();
|
|
27456
|
+
if (!stat22.isFile()) {
|
|
27179
27457
|
throw new PiSlotError("unsafe-path");
|
|
27180
27458
|
}
|
|
27181
27459
|
await afterReadCheck?.(path5);
|
|
27182
27460
|
const current = await lstat5(path5);
|
|
27183
|
-
if (!current.isFile() || current.dev !==
|
|
27461
|
+
if (!current.isFile() || current.dev !== stat22.dev || current.ino !== stat22.ino) {
|
|
27184
27462
|
throw new PiSlotError("unsafe-path");
|
|
27185
27463
|
}
|
|
27186
27464
|
const bytes = await file.readFile();
|
|
@@ -27864,9 +28142,11 @@ var init_pre_response_deadline = __esm({
|
|
|
27864
28142
|
this.cancelTimer = void 0;
|
|
27865
28143
|
}
|
|
27866
28144
|
resume() {
|
|
28145
|
+
const paused = !this.active;
|
|
27867
28146
|
this.active = true;
|
|
27868
28147
|
this.check();
|
|
27869
|
-
|
|
28148
|
+
if (paused)
|
|
28149
|
+
this.arm();
|
|
27870
28150
|
}
|
|
27871
28151
|
/** Cancel a response that arrives after its sender lost the abort race. */
|
|
27872
28152
|
open(work) {
|
|
@@ -28079,8 +28359,8 @@ function getDefaultTierId(allowedTiers) {
|
|
|
28079
28359
|
return allowedTiers[0]?.id;
|
|
28080
28360
|
}
|
|
28081
28361
|
function wait(ms) {
|
|
28082
|
-
return new Promise((
|
|
28083
|
-
setTimeout(
|
|
28362
|
+
return new Promise((resolve34) => {
|
|
28363
|
+
setTimeout(resolve34, ms);
|
|
28084
28364
|
});
|
|
28085
28365
|
}
|
|
28086
28366
|
function extractManagedProjectId(payload) {
|
|
@@ -28121,7 +28401,7 @@ function invalidateProjectContextCache(refresh) {
|
|
|
28121
28401
|
function clearProvisionFailedKeys() {
|
|
28122
28402
|
provisionFailedKeys.clear();
|
|
28123
28403
|
}
|
|
28124
|
-
async function loadManagedProject(accessToken, _projectId) {
|
|
28404
|
+
async function loadManagedProject(accessToken, _projectId, admit2) {
|
|
28125
28405
|
const requestBody = buildBootstrapRequestBody();
|
|
28126
28406
|
const loadHeaders = buildAntigravityHarnessBootstrapHeaders(accessToken);
|
|
28127
28407
|
const loadEndpoints = Array.from(/* @__PURE__ */ new Set([
|
|
@@ -28129,6 +28409,8 @@ async function loadManagedProject(accessToken, _projectId) {
|
|
|
28129
28409
|
...ANTIGRAVITY_ENDPOINT_FALLBACKS
|
|
28130
28410
|
]));
|
|
28131
28411
|
for (const baseEndpoint of loadEndpoints) {
|
|
28412
|
+
if (admit2)
|
|
28413
|
+
await admit2();
|
|
28132
28414
|
try {
|
|
28133
28415
|
const response = await fetchWithAgyCliTransport(`${baseEndpoint}/v1internal:loadCodeAssist`, {
|
|
28134
28416
|
method: "POST",
|
|
@@ -28148,7 +28430,7 @@ async function loadManagedProject(accessToken, _projectId) {
|
|
|
28148
28430
|
}
|
|
28149
28431
|
return null;
|
|
28150
28432
|
}
|
|
28151
|
-
async function onboardManagedProject(accessToken, tierId, projectId, attempts2 = 10, delayMs = 5e3) {
|
|
28433
|
+
async function onboardManagedProject(accessToken, tierId, projectId, attempts2 = 10, delayMs = 5e3, admit2) {
|
|
28152
28434
|
const requestBody = { tierId };
|
|
28153
28435
|
const onboardEndpoints = Array.from(/* @__PURE__ */ new Set([
|
|
28154
28436
|
ANTIGRAVITY_ENDPOINT_PROD,
|
|
@@ -28157,6 +28439,8 @@ async function onboardManagedProject(accessToken, tierId, projectId, attempts2 =
|
|
|
28157
28439
|
]));
|
|
28158
28440
|
for (const baseEndpoint of onboardEndpoints) {
|
|
28159
28441
|
for (let attempt = 0; attempt < attempts2; attempt += 1) {
|
|
28442
|
+
if (admit2)
|
|
28443
|
+
await admit2();
|
|
28160
28444
|
try {
|
|
28161
28445
|
const response = await fetchWithAgyCliTransport(`${baseEndpoint}/v1internal:onboardUser`, {
|
|
28162
28446
|
method: "POST",
|
|
@@ -28191,7 +28475,7 @@ async function onboardManagedProject(accessToken, tierId, projectId, attempts2 =
|
|
|
28191
28475
|
}
|
|
28192
28476
|
return void 0;
|
|
28193
28477
|
}
|
|
28194
|
-
async function ensureProjectContext(auth) {
|
|
28478
|
+
async function ensureProjectContext(auth, admit2) {
|
|
28195
28479
|
const accessToken = auth.access;
|
|
28196
28480
|
if (!accessToken) {
|
|
28197
28481
|
return { auth, effectiveProjectId: "" };
|
|
@@ -28235,7 +28519,7 @@ async function ensureProjectContext(auth) {
|
|
|
28235
28519
|
capturedTier
|
|
28236
28520
|
};
|
|
28237
28521
|
};
|
|
28238
|
-
const loadPayload = await loadManagedProject(accessToken, parts.projectId ?? fallbackProjectId);
|
|
28522
|
+
const loadPayload = await loadManagedProject(accessToken, parts.projectId ?? fallbackProjectId, admit2);
|
|
28239
28523
|
const capturedTierId = loadPayload?.currentTier?.id;
|
|
28240
28524
|
const paidTierId = typeof loadPayload?.paidTier === "string" ? loadPayload.paidTier : loadPayload?.paidTier?.id;
|
|
28241
28525
|
const tierFromPayload = capturedTierId ? {
|
|
@@ -28252,7 +28536,7 @@ async function ensureProjectContext(auth) {
|
|
|
28252
28536
|
tierId,
|
|
28253
28537
|
projectId: parts.projectId
|
|
28254
28538
|
});
|
|
28255
|
-
const provisionedProjectId = await onboardManagedProject(accessToken, tierId, parts.projectId);
|
|
28539
|
+
const provisionedProjectId = await onboardManagedProject(accessToken, tierId, parts.projectId, void 0, void 0, admit2);
|
|
28256
28540
|
if (provisionedProjectId) {
|
|
28257
28541
|
log3.debug("Successfully provisioned managed project", {
|
|
28258
28542
|
provisionedProjectId
|
|
@@ -30492,12 +30776,12 @@ var init_vault_provider_state = __esm({
|
|
|
30492
30776
|
function untilAborted2(pending, signal) {
|
|
30493
30777
|
if (!signal)
|
|
30494
30778
|
return pending;
|
|
30495
|
-
return new Promise((
|
|
30779
|
+
return new Promise((resolve34, reject) => {
|
|
30496
30780
|
const abort = () => reject(signal.reason);
|
|
30497
30781
|
signal.addEventListener("abort", abort, { once: true });
|
|
30498
30782
|
if (signal.aborted)
|
|
30499
30783
|
abort();
|
|
30500
|
-
pending.then(
|
|
30784
|
+
pending.then(resolve34, reject).finally(() => signal.removeEventListener("abort", abort));
|
|
30501
30785
|
});
|
|
30502
30786
|
}
|
|
30503
30787
|
async function resolveClaustrumConnectionPath(explicit) {
|
|
@@ -30679,6 +30963,8 @@ function createAntigravityVaultAccountSource(options) {
|
|
|
30679
30963
|
return response;
|
|
30680
30964
|
},
|
|
30681
30965
|
reportServedStatus,
|
|
30966
|
+
reportCondition: async (admission, input2) => consumer.reportCondition(issuedEntry(admission).receipt, input2),
|
|
30967
|
+
clearCondition: async (admission) => consumer.clearCondition(issuedEntry(admission).receipt),
|
|
30682
30968
|
attribution: (admission) => {
|
|
30683
30969
|
issuedEntry(admission);
|
|
30684
30970
|
return Object.freeze({
|
|
@@ -32933,13 +33219,13 @@ function closeDebugStream(state2) {
|
|
|
32933
33219
|
state2.logWriter = () => {
|
|
32934
33220
|
};
|
|
32935
33221
|
if (state2.logFilePath) liveLogFilePaths.delete(state2.logFilePath);
|
|
32936
|
-
return new Promise((
|
|
32937
|
-
current.once("close", () =>
|
|
32938
|
-
current.once("error", () =>
|
|
33222
|
+
return new Promise((resolve34) => {
|
|
33223
|
+
current.once("close", () => resolve34());
|
|
33224
|
+
current.once("error", () => resolve34());
|
|
32939
33225
|
try {
|
|
32940
33226
|
current.end();
|
|
32941
33227
|
} catch {
|
|
32942
|
-
|
|
33228
|
+
resolve34();
|
|
32943
33229
|
}
|
|
32944
33230
|
});
|
|
32945
33231
|
}
|
|
@@ -33204,13 +33490,13 @@ function closeDebugLog() {
|
|
|
33204
33490
|
if (!state2 || !current) return Promise.resolve();
|
|
33205
33491
|
state2.logStream = null;
|
|
33206
33492
|
if (state2.logFilePath) liveLogFilePaths.delete(state2.logFilePath);
|
|
33207
|
-
return new Promise((
|
|
33208
|
-
current.once("close", () =>
|
|
33209
|
-
current.once("error", () =>
|
|
33493
|
+
return new Promise((resolve34) => {
|
|
33494
|
+
current.once("close", () => resolve34());
|
|
33495
|
+
current.once("error", () => resolve34());
|
|
33210
33496
|
try {
|
|
33211
33497
|
current.end();
|
|
33212
33498
|
} catch {
|
|
33213
|
-
|
|
33499
|
+
resolve34();
|
|
33214
33500
|
}
|
|
33215
33501
|
});
|
|
33216
33502
|
}
|
|
@@ -33431,6 +33717,7 @@ var init_logger4 = __esm({
|
|
|
33431
33717
|
});
|
|
33432
33718
|
|
|
33433
33719
|
// src/plugin/shared/vault-request-credentials.ts
|
|
33720
|
+
import { stat as stat10 } from "node:fs/promises";
|
|
33434
33721
|
function vaultAccountRows(routes) {
|
|
33435
33722
|
return routes.map((route, index) => ({
|
|
33436
33723
|
index,
|
|
@@ -33478,10 +33765,7 @@ function createVaultRequestCredentials(source, onAdmitted) {
|
|
|
33478
33765
|
const admission = await source.admit(account.route, signal);
|
|
33479
33766
|
if (onAdmitted)
|
|
33480
33767
|
onAdmitted.admitted(account, onAdmitted.source.attribution(admission));
|
|
33481
|
-
const grant = new VaultSendGrant(
|
|
33482
|
-
admission,
|
|
33483
|
-
(status) => source.reportServedStatus(admission, status)
|
|
33484
|
-
);
|
|
33768
|
+
const grant = new VaultSendGrant(admission, source);
|
|
33485
33769
|
issued.set(grant, admission);
|
|
33486
33770
|
return grant;
|
|
33487
33771
|
}
|
|
@@ -33536,14 +33820,6 @@ function durableSelectionOf(row) {
|
|
|
33536
33820
|
...row.cooldownReason !== void 0 ? { cooldownReason: row.cooldownReason } : {},
|
|
33537
33821
|
...row.fingerprint !== void 0 ? { fingerprint: structuredClone(row.fingerprint) } : {},
|
|
33538
33822
|
...row.fingerprintHistory !== void 0 ? { fingerprintHistory: structuredClone(row.fingerprintHistory) } : {},
|
|
33539
|
-
...row.verificationRequired !== void 0 ? { verificationRequired: row.verificationRequired } : {},
|
|
33540
|
-
...row.verificationRequiredAt !== void 0 ? { verificationRequiredAt: row.verificationRequiredAt } : {},
|
|
33541
|
-
...row.verificationRequiredReason !== void 0 ? { verificationRequiredReason: row.verificationRequiredReason } : {},
|
|
33542
|
-
...row.verificationUrl !== void 0 ? { verificationUrl: row.verificationUrl } : {},
|
|
33543
|
-
...row.accountIneligible !== void 0 ? { accountIneligible: row.accountIneligible } : {},
|
|
33544
|
-
...row.accountIneligibleAt !== void 0 ? { accountIneligibleAt: row.accountIneligibleAt } : {},
|
|
33545
|
-
...row.accountIneligibleReason !== void 0 ? { accountIneligibleReason: row.accountIneligibleReason } : {},
|
|
33546
|
-
...row.eligibilityStateUpdatedAt !== void 0 ? { eligibilityStateUpdatedAt: row.eligibilityStateUpdatedAt } : {},
|
|
33547
33823
|
...row.dailyRequestCounts !== void 0 ? { dailyRequestCounts: { ...row.dailyRequestCounts } } : {}
|
|
33548
33824
|
};
|
|
33549
33825
|
}
|
|
@@ -33630,6 +33906,7 @@ function createVaultSelectionState(options) {
|
|
|
33630
33906
|
const attributions = /* @__PURE__ */ new WeakMap();
|
|
33631
33907
|
const changed = /* @__PURE__ */ new Set();
|
|
33632
33908
|
const clears = /* @__PURE__ */ new WeakMap();
|
|
33909
|
+
const accessVerdicts = /* @__PURE__ */ new WeakMap();
|
|
33633
33910
|
const legacyLoads = /* @__PURE__ */ new Map();
|
|
33634
33911
|
let writing = Promise.resolve();
|
|
33635
33912
|
const mark = (row) => {
|
|
@@ -33645,9 +33922,11 @@ function createVaultSelectionState(options) {
|
|
|
33645
33922
|
const attribution = attributions.get(row);
|
|
33646
33923
|
if (attribution === void 0) return;
|
|
33647
33924
|
changed.delete(row);
|
|
33648
|
-
const selection = durableSelectionOf(row);
|
|
33925
|
+
const { coolingDownUntil, cooldownReason, ...selection } = durableSelectionOf(row);
|
|
33649
33926
|
const cleared = clears.get(row);
|
|
33650
33927
|
clears.delete(row);
|
|
33928
|
+
const verdicts = accessVerdicts.get(row);
|
|
33929
|
+
accessVerdicts.delete(row);
|
|
33651
33930
|
try {
|
|
33652
33931
|
await options.source.commitState(attribution, (current) => {
|
|
33653
33932
|
let metadata = applyRateLimitObservation(
|
|
@@ -33669,6 +33948,20 @@ function createVaultSelectionState(options) {
|
|
|
33669
33948
|
selection.rateLimitResetTimes ?? {},
|
|
33670
33949
|
selection.rateLimitWrittenAt ?? {}
|
|
33671
33950
|
);
|
|
33951
|
+
if (coolingDownUntil != null && cooldownReason != null && (metadata.coolingDownUntil == null || coolingDownUntil > metadata.coolingDownUntil)) {
|
|
33952
|
+
metadata = applyCooldownObservation(metadata, {
|
|
33953
|
+
until: coolingDownUntil,
|
|
33954
|
+
reason: cooldownReason
|
|
33955
|
+
});
|
|
33956
|
+
}
|
|
33957
|
+
for (const verdict of verdicts ?? []) {
|
|
33958
|
+
const applied = applyAccessVerdict(metadata, verdict);
|
|
33959
|
+
if (applied) {
|
|
33960
|
+
metadata = applied.metadata;
|
|
33961
|
+
if (verdict.kind === "cleared")
|
|
33962
|
+
metadata.eligibilityStateUpdatedAt = verdict.observedAt;
|
|
33963
|
+
}
|
|
33964
|
+
}
|
|
33672
33965
|
if (cleared) {
|
|
33673
33966
|
const resets = { ...metadata.rateLimitResetTimes };
|
|
33674
33967
|
const written = { ...metadata.rateLimitWrittenAt };
|
|
@@ -33721,7 +34014,12 @@ function createVaultSelectionState(options) {
|
|
|
33721
34014
|
switched: mark,
|
|
33722
34015
|
lastUsed: mark,
|
|
33723
34016
|
usage: mark,
|
|
33724
|
-
accessVerdict
|
|
34017
|
+
accessVerdict(row, verdict) {
|
|
34018
|
+
const pending = accessVerdicts.get(row);
|
|
34019
|
+
if (pending) pending.push(verdict);
|
|
34020
|
+
else accessVerdicts.set(row, [verdict]);
|
|
34021
|
+
mark(row);
|
|
34022
|
+
},
|
|
33725
34023
|
fingerprint: mark,
|
|
33726
34024
|
requestSave: () => {
|
|
33727
34025
|
void flush2();
|
|
@@ -33730,16 +34028,20 @@ function createVaultSelectionState(options) {
|
|
|
33730
34028
|
admitted(row, attribution) {
|
|
33731
34029
|
attributions.set(row, attribution);
|
|
33732
34030
|
},
|
|
33733
|
-
async hydrate(rows) {
|
|
34031
|
+
async hydrate(rows, keptKeys) {
|
|
33734
34032
|
const file = await options.readState();
|
|
33735
34033
|
for (const row of rows) {
|
|
33736
34034
|
const identity4 = row.route.accountIdentity;
|
|
33737
34035
|
if (!Object.hasOwn(file.accounts, identity4)) continue;
|
|
33738
34036
|
const state2 = file.accounts[identity4];
|
|
33739
34037
|
if (state2 === void 0 || !stateBelongsTo(state2, row)) continue;
|
|
33740
|
-
|
|
33741
|
-
|
|
33742
|
-
|
|
34038
|
+
const kept = keptKeys?.has(vaultAccountRowKey(row));
|
|
34039
|
+
if (state2.metadata !== void 0) {
|
|
34040
|
+
if (kept)
|
|
34041
|
+
row.rateLimitClearedAt = state2.metadata.rateLimitClearedAt ?? void 0;
|
|
34042
|
+
else applyDurableSelection(row, state2.metadata);
|
|
34043
|
+
}
|
|
34044
|
+
const stamped = kept ? [] : stampRateLimitWrites(row, now2());
|
|
33743
34045
|
if (stamped.length) {
|
|
33744
34046
|
const legacyKey = legacyLimitKey({
|
|
33745
34047
|
...state2.observed,
|
|
@@ -33817,6 +34119,17 @@ function createVaultSelectionState(options) {
|
|
|
33817
34119
|
}
|
|
33818
34120
|
};
|
|
33819
34121
|
}
|
|
34122
|
+
async function providerStateSignature(path5) {
|
|
34123
|
+
if (path5 === void 0) return null;
|
|
34124
|
+
try {
|
|
34125
|
+
const info = await stat10(path5, { bigint: true });
|
|
34126
|
+
return info.isFile() ? `${info.dev}:${info.ino}:${info.size}:${info.mtimeNs}:${info.ctimeNs}` : null;
|
|
34127
|
+
} catch (error) {
|
|
34128
|
+
if (typeof error === "object" && error !== null && "code" in error && error.code === "ENOENT")
|
|
34129
|
+
return "missing";
|
|
34130
|
+
return null;
|
|
34131
|
+
}
|
|
34132
|
+
}
|
|
33820
34133
|
function createVaultAccountPool(options) {
|
|
33821
34134
|
const { source, durable } = options;
|
|
33822
34135
|
const state2 = durable ? createVaultSelectionState({
|
|
@@ -33839,23 +34152,54 @@ function createVaultAccountPool(options) {
|
|
|
33839
34152
|
const refusal3 = options.emptyRosterRefusal;
|
|
33840
34153
|
if (refusal3)
|
|
33841
34154
|
credentials.emptyRosterRefusal = () => refusal3(source.emptyRosterCause?.() ?? "unknown");
|
|
34155
|
+
const clock2 = options.now ?? Date.now;
|
|
34156
|
+
const refreshKeptRow = (prior, fresh) => {
|
|
34157
|
+
refreshVaultAccountRow(prior, fresh);
|
|
34158
|
+
const clearedAt = fresh.rateLimitClearedAt;
|
|
34159
|
+
if (clearedAt !== void 0 && clearedAt > (prior.rateLimitClearedAt ?? 0)) {
|
|
34160
|
+
prior.rateLimitClearedAt = clearedAt;
|
|
34161
|
+
reconcileManualLimitClear(prior);
|
|
34162
|
+
}
|
|
34163
|
+
const checkedAt = fresh.cachedQuotaUpdatedAt;
|
|
34164
|
+
if (fresh.cachedQuota !== void 0 && checkedAt !== void 0 && checkedAt > (prior.cachedQuotaUpdatedAt ?? 0) && checkedAt <= clock2()) {
|
|
34165
|
+
prior.cachedQuota = fresh.cachedQuota;
|
|
34166
|
+
prior.cachedQuotaUpdatedAt = checkedAt;
|
|
34167
|
+
selector.reconcileQuotaReading(prior, false);
|
|
34168
|
+
}
|
|
34169
|
+
};
|
|
34170
|
+
let hydratedSignature = null;
|
|
33842
34171
|
const rowsFromSource = async () => {
|
|
33843
34172
|
const rows = vaultAccountRows(source.routes());
|
|
33844
|
-
if (state2) {
|
|
33845
|
-
|
|
33846
|
-
|
|
33847
|
-
|
|
34173
|
+
if (!state2 || !durable || rows.length === 0) return { rows };
|
|
34174
|
+
const signature = await providerStateSignature(durable.stateFile);
|
|
34175
|
+
const kept = new Set(selector.rows.map(vaultAccountRowKey));
|
|
34176
|
+
const added = rows.some((row) => !kept.has(vaultAccountRowKey(row)));
|
|
34177
|
+
if (!added && signature !== null && signature === hydratedSignature)
|
|
34178
|
+
return { rows };
|
|
34179
|
+
try {
|
|
34180
|
+
await state2.hydrate(rows, kept);
|
|
34181
|
+
} catch (error) {
|
|
34182
|
+
if (added) throw error;
|
|
34183
|
+
try {
|
|
34184
|
+
durable.onReadFailure?.();
|
|
34185
|
+
} catch {
|
|
34186
|
+
}
|
|
34187
|
+
return { rows, signature: null };
|
|
33848
34188
|
}
|
|
33849
|
-
return rows;
|
|
34189
|
+
return { rows, signature };
|
|
33850
34190
|
};
|
|
33851
|
-
const
|
|
33852
|
-
|
|
34191
|
+
const install = ({
|
|
34192
|
+
rows,
|
|
34193
|
+
signature
|
|
34194
|
+
}) => {
|
|
34195
|
+
selector.replaceAccounts(rows, {
|
|
33853
34196
|
keyOf: vaultAccountRowKey,
|
|
33854
|
-
refresh:
|
|
34197
|
+
refresh: refreshKeptRow
|
|
33855
34198
|
});
|
|
34199
|
+
if (signature !== void 0) hydratedSignature = signature;
|
|
33856
34200
|
};
|
|
34201
|
+
const replace = async () => install(await rowsFromSource());
|
|
33857
34202
|
let firstRead = null;
|
|
33858
|
-
const clock2 = options.now ?? Date.now;
|
|
33859
34203
|
const schedule2 = options.schedule ?? ((callback, delayMs) => {
|
|
33860
34204
|
const timer = setTimeout(callback, delayMs);
|
|
33861
34205
|
timer.unref?.();
|
|
@@ -33874,12 +34218,8 @@ function createVaultAccountPool(options) {
|
|
|
33874
34218
|
firstReadStartedAt = clock2();
|
|
33875
34219
|
firstRead = (async () => {
|
|
33876
34220
|
await source.refresh();
|
|
33877
|
-
const
|
|
33878
|
-
if (current())
|
|
33879
|
-
selector.replaceAccounts(rows, {
|
|
33880
|
-
keyOf: vaultAccountRowKey,
|
|
33881
|
-
refresh: refreshVaultAccountRow
|
|
33882
|
-
});
|
|
34221
|
+
const loaded = await rowsFromSource();
|
|
34222
|
+
if (current()) install(loaded);
|
|
33883
34223
|
})().then(
|
|
33884
34224
|
() => {
|
|
33885
34225
|
if (current()) firstReadStartedAt = null;
|
|
@@ -33900,12 +34240,12 @@ function createVaultAccountPool(options) {
|
|
|
33900
34240
|
try {
|
|
33901
34241
|
return await Promise.race([
|
|
33902
34242
|
read.then(() => true),
|
|
33903
|
-
new Promise((
|
|
34243
|
+
new Promise((resolve34, reject) => {
|
|
33904
34244
|
const abort = () => reject(signal?.reason);
|
|
33905
34245
|
signal?.addEventListener("abort", abort, { once: true });
|
|
33906
34246
|
detachAbort = () => signal?.removeEventListener("abort", abort);
|
|
33907
34247
|
if (remaining !== void 0)
|
|
33908
|
-
cancelTimer2 = schedule2(() =>
|
|
34248
|
+
cancelTimer2 = schedule2(() => resolve34(false), remaining);
|
|
33909
34249
|
if (signal?.aborted) abort();
|
|
33910
34250
|
})
|
|
33911
34251
|
]);
|
|
@@ -33994,7 +34334,7 @@ function vaultQuotaState(quota, at) {
|
|
|
33994
34334
|
}
|
|
33995
34335
|
async function checkVaultQuota(input2) {
|
|
33996
34336
|
const state2 = input2.pool.state;
|
|
33997
|
-
const
|
|
34337
|
+
const routes = input2.routes ?? input2.pool.selector.rows.map((row) => row.route);
|
|
33998
34338
|
const now2 = input2.now ?? (() => Date.now());
|
|
33999
34339
|
const reportError = (error) => {
|
|
34000
34340
|
try {
|
|
@@ -34005,11 +34345,11 @@ async function checkVaultQuota(input2) {
|
|
|
34005
34345
|
let checked = 0;
|
|
34006
34346
|
if (state2 === void 0) input2.onOutcome?.("state-invalid");
|
|
34007
34347
|
const readings = [];
|
|
34008
|
-
for (const
|
|
34348
|
+
for (const route of routes) {
|
|
34009
34349
|
if (input2.signal.aborted || state2 === void 0) break;
|
|
34010
34350
|
try {
|
|
34011
34351
|
input2.onStage?.("fetch");
|
|
34012
|
-
const answer = await input2.fetchReading(
|
|
34352
|
+
const answer = await input2.fetchReading(route, input2.signal);
|
|
34013
34353
|
input2.signal.throwIfAborted();
|
|
34014
34354
|
if (answer === void 0) {
|
|
34015
34355
|
input2.onOutcome?.("fetch-failed");
|
|
@@ -34033,7 +34373,7 @@ async function checkVaultQuota(input2) {
|
|
|
34033
34373
|
}
|
|
34034
34374
|
}
|
|
34035
34375
|
if (state2 === void 0 || readings.length === 0 || input2.signal.aborted)
|
|
34036
|
-
return { checked, notChecked:
|
|
34376
|
+
return { checked, notChecked: routes.length - checked };
|
|
34037
34377
|
let results;
|
|
34038
34378
|
try {
|
|
34039
34379
|
input2.onStage?.("commit");
|
|
@@ -34041,8 +34381,11 @@ async function checkVaultQuota(input2) {
|
|
|
34041
34381
|
results = await state2.recordQuotas(readings, input2.signal);
|
|
34042
34382
|
} catch (error) {
|
|
34043
34383
|
for (const _ of readings) reportError(error);
|
|
34044
|
-
return { checked, notChecked:
|
|
34384
|
+
return { checked, notChecked: routes.length - checked };
|
|
34045
34385
|
}
|
|
34386
|
+
const liveByRoute = new Map(
|
|
34387
|
+
input2.pool.selector.rows.map((row) => [row.route.routeId, row])
|
|
34388
|
+
);
|
|
34046
34389
|
for (const [at, { attribution, quota: reading }] of readings.entries()) {
|
|
34047
34390
|
const result = results[at];
|
|
34048
34391
|
if (result === void 0 || result.status === "refused") {
|
|
@@ -34060,17 +34403,15 @@ async function checkVaultQuota(input2) {
|
|
|
34060
34403
|
}
|
|
34061
34404
|
checked += 1;
|
|
34062
34405
|
input2.onOutcome?.("recorded");
|
|
34063
|
-
const live =
|
|
34064
|
-
|
|
34065
|
-
);
|
|
34066
|
-
if (live !== void 0) {
|
|
34406
|
+
const live = liveByRoute.get(attribution.routeId);
|
|
34407
|
+
if (live?.route.credentialId === attribution.credentialId && live.route.accountIdentity === attribution.accountIdentity) {
|
|
34067
34408
|
const cached = cachedQuotaOf(reading);
|
|
34068
34409
|
if (cached !== void 0) live.cachedQuota = cached;
|
|
34069
34410
|
live.cachedQuotaUpdatedAt = reading.cachedQuotaUpdatedAt ?? void 0;
|
|
34070
34411
|
input2.pool.selector.reconcileQuotaReading(live);
|
|
34071
34412
|
}
|
|
34072
34413
|
}
|
|
34073
|
-
return { checked, notChecked:
|
|
34414
|
+
return { checked, notChecked: routes.length - checked };
|
|
34074
34415
|
}
|
|
34075
34416
|
var VaultSendGrant, VAULT_REFRESH_STALL_MS, VAULT_DISPLAY_ROSTER_WAIT_MS;
|
|
34076
34417
|
var init_vault_request_credentials = __esm({
|
|
@@ -34084,7 +34425,9 @@ var init_vault_request_credentials = __esm({
|
|
|
34084
34425
|
recordVersion;
|
|
34085
34426
|
projectId;
|
|
34086
34427
|
report401;
|
|
34087
|
-
|
|
34428
|
+
reportCondition;
|
|
34429
|
+
clearCondition;
|
|
34430
|
+
constructor(admission, source) {
|
|
34088
34431
|
Object.defineProperty(this, "accessToken", {
|
|
34089
34432
|
value: admission.accessToken,
|
|
34090
34433
|
enumerable: false
|
|
@@ -34094,7 +34437,9 @@ var init_vault_request_credentials = __esm({
|
|
|
34094
34437
|
this.recordVersion = admission.recordVersion;
|
|
34095
34438
|
this.projectId = admission.projectId;
|
|
34096
34439
|
this.fromKeptReceipt = admission.fromKeptReceipt;
|
|
34097
|
-
this.report401 =
|
|
34440
|
+
this.report401 = (status) => source.reportServedStatus(admission, status);
|
|
34441
|
+
this.reportCondition = source.reportCondition?.bind(source, admission);
|
|
34442
|
+
this.clearCondition = source.clearCondition?.bind(source, admission);
|
|
34098
34443
|
}
|
|
34099
34444
|
};
|
|
34100
34445
|
VAULT_REFRESH_STALL_MS = 3e4;
|
|
@@ -34155,7 +34500,7 @@ var init_vault_insula_quota = __esm({
|
|
|
34155
34500
|
});
|
|
34156
34501
|
|
|
34157
34502
|
// src/plugin/vault-custody.ts
|
|
34158
|
-
import { chmod as chmod4, mkdir as mkdir12, readFile as readFile11, stat as
|
|
34503
|
+
import { chmod as chmod4, mkdir as mkdir12, readFile as readFile11, stat as stat11 } from "node:fs/promises";
|
|
34159
34504
|
import { join as join17 } from "node:path";
|
|
34160
34505
|
async function enrollmentFilesIdentity(paths) {
|
|
34161
34506
|
const takenAt = performance.now();
|
|
@@ -34163,7 +34508,7 @@ async function enrollmentFilesIdentity(paths) {
|
|
|
34163
34508
|
const parts = [];
|
|
34164
34509
|
for (const path5 of [paths.tokenPath, paths.statePath]) {
|
|
34165
34510
|
try {
|
|
34166
|
-
const info = await
|
|
34511
|
+
const info = await stat11(path5, { bigint: true });
|
|
34167
34512
|
if (info.ino === 0n) coarse = true;
|
|
34168
34513
|
parts.push(
|
|
34169
34514
|
`${info.dev}:${info.ino}:${info.size}:${info.mtimeNs}:${info.ctimeNs}`
|
|
@@ -34431,11 +34776,11 @@ function createOpenCodeVaultCustody(options) {
|
|
|
34431
34776
|
].join("\n");
|
|
34432
34777
|
const waitForApproval = async () => {
|
|
34433
34778
|
while (!closed2) {
|
|
34434
|
-
await new Promise((
|
|
34779
|
+
await new Promise((resolve34) => {
|
|
34435
34780
|
const done = () => {
|
|
34436
34781
|
clearTimeout(timer);
|
|
34437
34782
|
cancelWait = void 0;
|
|
34438
|
-
|
|
34783
|
+
resolve34();
|
|
34439
34784
|
};
|
|
34440
34785
|
const timer = setTimeout(done, 2e3);
|
|
34441
34786
|
timer.unref?.();
|
|
@@ -34948,7 +35293,7 @@ import {
|
|
|
34948
35293
|
readFile as readFile12,
|
|
34949
35294
|
rename as rename10,
|
|
34950
35295
|
rmdir as rmdir2,
|
|
34951
|
-
stat as
|
|
35296
|
+
stat as stat12,
|
|
34952
35297
|
unlink as unlink11
|
|
34953
35298
|
} from "node:fs/promises";
|
|
34954
35299
|
import { basename as basename6, dirname as dirname18, join as join18, resolve as resolve19 } from "node:path";
|
|
@@ -35867,7 +36212,7 @@ async function physicalAliases(location, files) {
|
|
|
35867
36212
|
async function samePhysical(a, b) {
|
|
35868
36213
|
const id = async (path5) => {
|
|
35869
36214
|
try {
|
|
35870
|
-
const info = await
|
|
36215
|
+
const info = await stat12(path5, { bigint: true });
|
|
35871
36216
|
return info.ino === 0n ? void 0 : `${info.dev}:${info.ino}`;
|
|
35872
36217
|
} catch (error) {
|
|
35873
36218
|
const code2 = error.code;
|
|
@@ -36133,7 +36478,7 @@ function lockHolderText(name) {
|
|
|
36133
36478
|
}
|
|
36134
36479
|
async function exists2(path5) {
|
|
36135
36480
|
try {
|
|
36136
|
-
await
|
|
36481
|
+
await stat12(path5);
|
|
36137
36482
|
return true;
|
|
36138
36483
|
} catch (error) {
|
|
36139
36484
|
const code2 = error.code;
|
|
@@ -36231,7 +36576,7 @@ var init_runtime_layout = __esm({
|
|
|
36231
36576
|
init_dist();
|
|
36232
36577
|
init_runtime_layout();
|
|
36233
36578
|
import { createHash as createHash24, randomUUID as randomUUID25 } from "node:crypto";
|
|
36234
|
-
import { join as
|
|
36579
|
+
import { join as join45, resolve as resolve33 } from "node:path";
|
|
36235
36580
|
|
|
36236
36581
|
// src/cli.ts
|
|
36237
36582
|
init_dist();
|
|
@@ -36475,9 +36820,9 @@ init_dist();
|
|
|
36475
36820
|
init_dist();
|
|
36476
36821
|
|
|
36477
36822
|
// src/sidebar-state.ts
|
|
36823
|
+
import { chmodSync as chmodSync3, mkdirSync as mkdirSync3, readFileSync as readFileSync3, statSync as statSync5 } from "node:fs";
|
|
36478
36824
|
init_atomic_write();
|
|
36479
36825
|
init_file_lock();
|
|
36480
|
-
import { chmodSync as chmodSync3, mkdirSync as mkdirSync3, readFileSync as readFileSync3 } from "node:fs";
|
|
36481
36826
|
import { homedir as homedir6 } from "node:os";
|
|
36482
36827
|
import { dirname as dirname19, join as join19 } from "node:path";
|
|
36483
36828
|
|
|
@@ -36548,6 +36893,9 @@ function readSidebarState(path5 = getSidebarStateFile()) {
|
|
|
36548
36893
|
} catch {
|
|
36549
36894
|
return { ...DEFAULT_SIDEBAR_STATE };
|
|
36550
36895
|
}
|
|
36896
|
+
return parseSidebarState(raw);
|
|
36897
|
+
}
|
|
36898
|
+
function parseSidebarState(raw) {
|
|
36551
36899
|
let parsed;
|
|
36552
36900
|
try {
|
|
36553
36901
|
parsed = JSON.parse(raw);
|
|
@@ -36888,7 +37236,7 @@ function drainSidebarWrites() {
|
|
|
36888
37236
|
return sidebarWriteChain;
|
|
36889
37237
|
}
|
|
36890
37238
|
async function sleep3(ms) {
|
|
36891
|
-
await new Promise((
|
|
37239
|
+
await new Promise((resolve34) => setTimeout(resolve34, ms));
|
|
36892
37240
|
}
|
|
36893
37241
|
async function acquireSidebarLockWithRetry(stateFile) {
|
|
36894
37242
|
const start = Date.now();
|
|
@@ -37428,7 +37776,8 @@ function withSidebarPushAfterRefresh(manager, push) {
|
|
|
37428
37776
|
refreshOptions
|
|
37429
37777
|
);
|
|
37430
37778
|
const lastAccount = accounts[accounts.length - 1];
|
|
37431
|
-
if (shouldPush &&
|
|
37779
|
+
if (shouldPush && refreshOptions.publishSidebar !== false && lastAccount)
|
|
37780
|
+
await pushAfterRefresh(lastAccount);
|
|
37432
37781
|
return results;
|
|
37433
37782
|
})()
|
|
37434
37783
|
);
|
|
@@ -37463,10 +37812,29 @@ async function checkAccountsQuotaStandalone(accounts, options) {
|
|
|
37463
37812
|
}
|
|
37464
37813
|
}));
|
|
37465
37814
|
}
|
|
37466
|
-
|
|
37815
|
+
const refused2 = new AbortController();
|
|
37816
|
+
const admit2 = options.assertAdmission;
|
|
37817
|
+
const assertAdmission = admit2 && (async () => {
|
|
37818
|
+
refused2.signal.throwIfAborted();
|
|
37819
|
+
try {
|
|
37820
|
+
await admit2();
|
|
37821
|
+
} catch (error) {
|
|
37822
|
+
refused2.abort(error);
|
|
37823
|
+
throw error;
|
|
37824
|
+
}
|
|
37825
|
+
refused2.signal.throwIfAborted();
|
|
37826
|
+
});
|
|
37827
|
+
const results = await checkAccountsQuotaWith(
|
|
37467
37828
|
accounts,
|
|
37468
|
-
makeFetchAccountQuota(
|
|
37829
|
+
makeFetchAccountQuota(
|
|
37830
|
+
void 0,
|
|
37831
|
+
ANTIGRAVITY_PROVIDER_ID,
|
|
37832
|
+
void 0,
|
|
37833
|
+
assertAdmission
|
|
37834
|
+
)
|
|
37469
37835
|
);
|
|
37836
|
+
refused2.signal.throwIfAborted();
|
|
37837
|
+
return results;
|
|
37470
37838
|
}
|
|
37471
37839
|
async function pushSidebarQuotaSnapshot(getAccounts, backoffUntil = 0, getActiveIndexByFamily, options = {}) {
|
|
37472
37840
|
const accounts = getAccounts();
|
|
@@ -37740,14 +38108,14 @@ var LocalQuotaGrantStaleError = class extends Error {
|
|
|
37740
38108
|
name = "LocalQuotaGrantStaleError";
|
|
37741
38109
|
};
|
|
37742
38110
|
function untilQuotaAborted(pending, signal) {
|
|
37743
|
-
return new Promise((
|
|
38111
|
+
return new Promise((resolve34, reject) => {
|
|
37744
38112
|
const abort = () => reject(signal.reason);
|
|
37745
38113
|
if (signal.aborted) abort();
|
|
37746
38114
|
else signal.addEventListener("abort", abort, { once: true });
|
|
37747
38115
|
void pending.then(
|
|
37748
38116
|
(value) => {
|
|
37749
38117
|
signal.removeEventListener("abort", abort);
|
|
37750
|
-
|
|
38118
|
+
resolve34(value);
|
|
37751
38119
|
},
|
|
37752
38120
|
(error) => {
|
|
37753
38121
|
signal.removeEventListener("abort", abort);
|
|
@@ -37845,7 +38213,7 @@ function createAuthorizedFetchAccountQuota(options) {
|
|
|
37845
38213
|
}
|
|
37846
38214
|
};
|
|
37847
38215
|
}
|
|
37848
|
-
function makeFetchAccountQuota(client, providerId, fetchVia) {
|
|
38216
|
+
function makeFetchAccountQuota(client, providerId, fetchVia, assertAdmission) {
|
|
37849
38217
|
return async (account, signal, purpose = "required") => {
|
|
37850
38218
|
const index = 0;
|
|
37851
38219
|
const disabled = account.enabled === false;
|
|
@@ -37927,6 +38295,8 @@ function makeFetchAccountQuota(client, providerId, fetchVia) {
|
|
|
37927
38295
|
}
|
|
37928
38296
|
try {
|
|
37929
38297
|
if (accessTokenExpired(auth)) {
|
|
38298
|
+
if (assertAdmission) await assertAdmission();
|
|
38299
|
+
signal.throwIfAborted();
|
|
37930
38300
|
const refreshed = await refreshAccessToken(
|
|
37931
38301
|
auth,
|
|
37932
38302
|
client,
|
|
@@ -37940,7 +38310,7 @@ function makeFetchAccountQuota(client, providerId, fetchVia) {
|
|
|
37940
38310
|
}
|
|
37941
38311
|
auth = refreshed;
|
|
37942
38312
|
}
|
|
37943
|
-
const projectContext = await ensureProjectContext(auth);
|
|
38313
|
+
const projectContext = await ensureProjectContext(auth, assertAdmission);
|
|
37944
38314
|
auth = projectContext.auth;
|
|
37945
38315
|
const updatedAccount = applyAccountUpdates(
|
|
37946
38316
|
account,
|
|
@@ -37955,11 +38325,20 @@ function makeFetchAccountQuota(client, providerId, fetchVia) {
|
|
|
37955
38325
|
let fellBackToLegacy = false;
|
|
37956
38326
|
const authParts = parseRefreshParts(auth.refresh);
|
|
37957
38327
|
const managedProjectId = authParts.managedProjectId ?? account.managedProjectId;
|
|
38328
|
+
const guarded = assertAdmission ? async (url, init, extra) => {
|
|
38329
|
+
await assertAdmission();
|
|
38330
|
+
signal.throwIfAborted();
|
|
38331
|
+
return fetchWithActiveTimeout(
|
|
38332
|
+
url,
|
|
38333
|
+
{ ...init, signal },
|
|
38334
|
+
{ timeoutMs: extra.timeoutMs }
|
|
38335
|
+
);
|
|
38336
|
+
} : fetchVia;
|
|
37958
38337
|
const payloads = await fetchQuotaPayloads({
|
|
37959
38338
|
accessToken: auth.access ?? "",
|
|
37960
38339
|
managedProjectId,
|
|
37961
38340
|
projectId: projectContext.effectiveProjectId,
|
|
37962
|
-
fetchVia,
|
|
38341
|
+
fetchVia: guarded,
|
|
37963
38342
|
logger: log8
|
|
37964
38343
|
});
|
|
37965
38344
|
quotaResult = payloads.quota;
|
|
@@ -38204,12 +38583,13 @@ function createStoreQuotaService(options) {
|
|
|
38204
38583
|
if (options.mayRun && !await options.mayRun())
|
|
38205
38584
|
return { status: "discarded", result };
|
|
38206
38585
|
const held2 = target.rowRef === void 0 ? void 0 : heldAccount(manager, target.rowRef);
|
|
38207
|
-
if (held2 === void 0
|
|
38208
|
-
manager.updateQuotaCache(
|
|
38586
|
+
if (held2 === void 0 || result.checkedAt === void 0 || !manager.updateQuotaCache(
|
|
38209
38587
|
held2.index,
|
|
38210
38588
|
result.quota.groups,
|
|
38211
|
-
held2.parts.refreshToken
|
|
38212
|
-
|
|
38589
|
+
held2.parts.refreshToken,
|
|
38590
|
+
result.checkedAt
|
|
38591
|
+
))
|
|
38592
|
+
return { status: "discarded", result };
|
|
38213
38593
|
return {
|
|
38214
38594
|
status: "recorded",
|
|
38215
38595
|
result,
|
|
@@ -38368,12 +38748,12 @@ async function startOAuthListener({
|
|
|
38368
38748
|
let resolveCallback;
|
|
38369
38749
|
let rejectCallback;
|
|
38370
38750
|
let timeoutHandle;
|
|
38371
|
-
const callbackPromise = new Promise((
|
|
38751
|
+
const callbackPromise = new Promise((resolve34, reject) => {
|
|
38372
38752
|
resolveCallback = (url) => {
|
|
38373
38753
|
if (settled) return;
|
|
38374
38754
|
settled = true;
|
|
38375
38755
|
if (timeoutHandle) clearTimeout(timeoutHandle);
|
|
38376
|
-
|
|
38756
|
+
resolve34(url);
|
|
38377
38757
|
};
|
|
38378
38758
|
rejectCallback = (error) => {
|
|
38379
38759
|
if (settled) return;
|
|
@@ -38532,7 +38912,7 @@ async function startOAuthListener({
|
|
|
38532
38912
|
});
|
|
38533
38913
|
});
|
|
38534
38914
|
const bindAddress = getBindAddress();
|
|
38535
|
-
await new Promise((
|
|
38915
|
+
await new Promise((resolve34, reject) => {
|
|
38536
38916
|
const handleError = (error) => {
|
|
38537
38917
|
server.off("error", handleError);
|
|
38538
38918
|
if (error.code === "EADDRINUSE") {
|
|
@@ -38548,7 +38928,7 @@ async function startOAuthListener({
|
|
|
38548
38928
|
server.once("error", handleError);
|
|
38549
38929
|
server.listen(port, bindAddress, () => {
|
|
38550
38930
|
server.off("error", handleError);
|
|
38551
|
-
|
|
38931
|
+
resolve34();
|
|
38552
38932
|
});
|
|
38553
38933
|
});
|
|
38554
38934
|
server.on("error", (error) => {
|
|
@@ -38556,7 +38936,7 @@ async function startOAuthListener({
|
|
|
38556
38936
|
});
|
|
38557
38937
|
return {
|
|
38558
38938
|
waitForCallback: () => callbackPromise,
|
|
38559
|
-
close: () => new Promise((
|
|
38939
|
+
close: () => new Promise((resolve34, reject) => {
|
|
38560
38940
|
server.close((error) => {
|
|
38561
38941
|
if (error && error.code !== "ERR_SERVER_NOT_RUNNING") {
|
|
38562
38942
|
reject(error);
|
|
@@ -38565,7 +38945,7 @@ async function startOAuthListener({
|
|
|
38565
38945
|
if (!settled) {
|
|
38566
38946
|
rejectCallback(new Error("OAuth listener closed before callback"));
|
|
38567
38947
|
}
|
|
38568
|
-
|
|
38948
|
+
resolve34();
|
|
38569
38949
|
});
|
|
38570
38950
|
})
|
|
38571
38951
|
};
|
|
@@ -38757,7 +39137,7 @@ async function select2(terminal, items, options) {
|
|
|
38757
39137
|
writeLine("");
|
|
38758
39138
|
renderedLines = lines;
|
|
38759
39139
|
};
|
|
38760
|
-
return new Promise((
|
|
39140
|
+
return new Promise((resolve34) => {
|
|
38761
39141
|
const wasRaw = stdin.isRaw ?? false;
|
|
38762
39142
|
const cleanup2 = () => {
|
|
38763
39143
|
if (cleaned)
|
|
@@ -38777,7 +39157,7 @@ async function select2(terminal, items, options) {
|
|
|
38777
39157
|
};
|
|
38778
39158
|
const finish = (value) => {
|
|
38779
39159
|
cleanup2();
|
|
38780
|
-
|
|
39160
|
+
resolve34(value);
|
|
38781
39161
|
};
|
|
38782
39162
|
const onSignal = () => finish(null);
|
|
38783
39163
|
const onKey = (data) => {
|
|
@@ -38817,7 +39197,7 @@ async function select2(terminal, items, options) {
|
|
|
38817
39197
|
stdin.setRawMode(true);
|
|
38818
39198
|
} catch {
|
|
38819
39199
|
cleanup2();
|
|
38820
|
-
|
|
39200
|
+
resolve34(null);
|
|
38821
39201
|
return;
|
|
38822
39202
|
}
|
|
38823
39203
|
stdin.resume();
|
|
@@ -38830,12 +39210,12 @@ async function select2(terminal, items, options) {
|
|
|
38830
39210
|
// src/common-auth-embedded/claustrum/enrollment.js
|
|
38831
39211
|
import { createHash as createHash12, randomBytes as randomBytes5, randomUUID as randomUUID17 } from "node:crypto";
|
|
38832
39212
|
import { constants as fsConstants2 } from "node:fs";
|
|
38833
|
-
import { chmod as chmod6, mkdir as mkdir15, open as open10, readFile as readFile14, realpath as realpath4, rename as rename12, stat as
|
|
39213
|
+
import { chmod as chmod6, mkdir as mkdir15, open as open10, readFile as readFile14, realpath as realpath4, rename as rename12, stat as stat15, unlink as unlink13 } from "node:fs/promises";
|
|
38834
39214
|
import { basename as basename8, dirname as dirname21, extname as extname2, isAbsolute as isAbsolute4, join as join21, resolve as resolve22 } from "node:path";
|
|
38835
39215
|
import { ClaustrumCredentialError as ClaustrumCredentialError9, ClaustrumClient as ClaustrumWireClient2, writeEnrollmentTokenFile as writeEnrollmentTokenFile2 } from "@cortexkit/claustrum-client";
|
|
38836
39216
|
|
|
38837
39217
|
// src/common-auth-embedded/fs/file-read-cache.js
|
|
38838
|
-
import { lstat as lstat7, stat as
|
|
39218
|
+
import { lstat as lstat7, stat as stat13 } from "node:fs/promises";
|
|
38839
39219
|
import { resolve as resolve20 } from "node:path";
|
|
38840
39220
|
async function identity2(path5, probe) {
|
|
38841
39221
|
try {
|
|
@@ -38854,7 +39234,7 @@ var FileReadCache2 = class {
|
|
|
38854
39234
|
#probe;
|
|
38855
39235
|
#entries = /* @__PURE__ */ new Map();
|
|
38856
39236
|
constructor(options = {}) {
|
|
38857
|
-
this.#probe = options.followSymlinks ? (path5) => (options.stat ??
|
|
39237
|
+
this.#probe = options.followSymlinks ? (path5) => (options.stat ?? stat13)(path5) : (path5) => (options.lstat ?? lstat7)(path5);
|
|
38858
39238
|
}
|
|
38859
39239
|
async read(paths, read, validateHit) {
|
|
38860
39240
|
const resolvedPaths = paths.map((path5) => resolve20(path5));
|
|
@@ -38908,7 +39288,7 @@ init_private_files2();
|
|
|
38908
39288
|
// src/common-auth-embedded/fs/refresh-file-lock.js
|
|
38909
39289
|
init_logger3();
|
|
38910
39290
|
import { randomUUID as randomUUID16 } from "node:crypto";
|
|
38911
|
-
import { link as link3, lstat as lstat8, mkdir as mkdir14, open as open9, readdir as readdir5, readFile as readFile13, rename as rename11, rm as rm6, stat as
|
|
39291
|
+
import { link as link3, lstat as lstat8, mkdir as mkdir14, open as open9, readdir as readdir5, readFile as readFile13, rename as rename11, rm as rm6, stat as stat14, unlink as unlink12 } from "node:fs/promises";
|
|
38912
39292
|
import { basename as basename7, dirname as dirname20, join as join20 } from "node:path";
|
|
38913
39293
|
|
|
38914
39294
|
// src/common-auth-embedded/fs/lock-record.js
|
|
@@ -39129,8 +39509,8 @@ async function acquireRefreshFileLockWithClock2(options) {
|
|
|
39129
39509
|
let releaseConfirmed = false;
|
|
39130
39510
|
let loss;
|
|
39131
39511
|
let resolveLoss;
|
|
39132
|
-
const lostPromise = new Promise((
|
|
39133
|
-
resolveLoss =
|
|
39512
|
+
const lostPromise = new Promise((resolve34) => {
|
|
39513
|
+
resolveLoss = resolve34;
|
|
39134
39514
|
});
|
|
39135
39515
|
function notifyTimerStep(event) {
|
|
39136
39516
|
try {
|
|
@@ -39294,7 +39674,7 @@ async function acquireRefreshFileLockWithClock2(options) {
|
|
|
39294
39674
|
}
|
|
39295
39675
|
}
|
|
39296
39676
|
async function backoff() {
|
|
39297
|
-
await new Promise((
|
|
39677
|
+
await new Promise((resolve34) => setTimeout(resolve34, Math.floor(Math.random() * 4)));
|
|
39298
39678
|
}
|
|
39299
39679
|
async function readLockState(notifyReady = true) {
|
|
39300
39680
|
if (notifyReady && options.onStep)
|
|
@@ -39318,7 +39698,7 @@ async function acquireRefreshFileLockWithClock2(options) {
|
|
|
39318
39698
|
};
|
|
39319
39699
|
}
|
|
39320
39700
|
try {
|
|
39321
|
-
const current = await
|
|
39701
|
+
const current = await stat14(lockPath);
|
|
39322
39702
|
const legacyExpiry = Number.isFinite(expiresAt) ? expiresAt : current.mtimeMs + options.ttlMs;
|
|
39323
39703
|
if (legacyExpiry > now2())
|
|
39324
39704
|
return { status: "live" };
|
|
@@ -39387,7 +39767,7 @@ async function acquireRefreshFileLockWithClock2(options) {
|
|
|
39387
39767
|
const remainingMs = deadline - performance.now();
|
|
39388
39768
|
if (remainingMs <= 0)
|
|
39389
39769
|
throw original;
|
|
39390
|
-
await new Promise((
|
|
39770
|
+
await new Promise((resolve34) => setTimeout(resolve34, Math.min(delayMs, remainingMs)));
|
|
39391
39771
|
if (performance.now() >= deadline)
|
|
39392
39772
|
throw original;
|
|
39393
39773
|
delayMs = Math.min(delayMs * 2, 50);
|
|
@@ -39412,7 +39792,7 @@ async function acquireRefreshFileLockWithClock2(options) {
|
|
|
39412
39792
|
if (!ownedDirectory)
|
|
39413
39793
|
return false;
|
|
39414
39794
|
try {
|
|
39415
|
-
await
|
|
39795
|
+
await stat14(evictOwnerPath);
|
|
39416
39796
|
return false;
|
|
39417
39797
|
} catch (error) {
|
|
39418
39798
|
if (error.code !== "ENOENT")
|
|
@@ -39433,7 +39813,7 @@ async function acquireRefreshFileLockWithClock2(options) {
|
|
|
39433
39813
|
return false;
|
|
39434
39814
|
stillOurs = true;
|
|
39435
39815
|
try {
|
|
39436
|
-
await
|
|
39816
|
+
await stat14(evictOwnerPath);
|
|
39437
39817
|
return false;
|
|
39438
39818
|
} catch (error) {
|
|
39439
39819
|
return error.code === "ENOENT";
|
|
@@ -39483,7 +39863,7 @@ async function acquireRefreshFileLockWithClock2(options) {
|
|
|
39483
39863
|
async function recoverStaleEvictionMarker(deadline) {
|
|
39484
39864
|
let evictStat;
|
|
39485
39865
|
try {
|
|
39486
|
-
evictStat = await
|
|
39866
|
+
evictStat = await stat14(evictPath);
|
|
39487
39867
|
} catch (error) {
|
|
39488
39868
|
if (error.code === "ENOENT")
|
|
39489
39869
|
return "missing";
|
|
@@ -39501,7 +39881,7 @@ async function acquireRefreshFileLockWithClock2(options) {
|
|
|
39501
39881
|
if (evictStat.mtimeMs + EVICT_TTL > now2()) {
|
|
39502
39882
|
let hasOwner = true;
|
|
39503
39883
|
try {
|
|
39504
|
-
await
|
|
39884
|
+
await stat14(evictOwnerPath);
|
|
39505
39885
|
} catch (error) {
|
|
39506
39886
|
if (error.code === "ENOENT")
|
|
39507
39887
|
hasOwner = false;
|
|
@@ -39890,7 +40270,7 @@ async function acquireRefreshFileLockWithClock2(options) {
|
|
|
39890
40270
|
const remainingMs = deadline - performance.now();
|
|
39891
40271
|
if (remainingMs <= 0)
|
|
39892
40272
|
break;
|
|
39893
|
-
await new Promise((
|
|
40273
|
+
await new Promise((resolve34) => setTimeout(resolve34, Math.min(delayMs, remainingMs)));
|
|
39894
40274
|
if (windowsPrivateFiles2 && performance.now() >= deadline)
|
|
39895
40275
|
break;
|
|
39896
40276
|
delayMs = Math.min(delayMs * 2, 50);
|
|
@@ -40271,7 +40651,7 @@ async function refuseWritableAncestor2(parent, options = {}) {
|
|
|
40271
40651
|
}
|
|
40272
40652
|
let privateGroup;
|
|
40273
40653
|
for (; ; ) {
|
|
40274
|
-
const metadata = await
|
|
40654
|
+
const metadata = await stat15(component).catch(() => void 0);
|
|
40275
40655
|
if (metadata && (metadata.mode & 18) !== 0 && (metadata.mode & 512) === 0) {
|
|
40276
40656
|
if (privateGroup === void 0) {
|
|
40277
40657
|
privateGroup = gid !== void 0 && await isPrivateGroup2(uid, gid, options);
|
|
@@ -40300,7 +40680,7 @@ async function ensureClaustrumPrivateDirectory2(directory, options = {}, what =
|
|
|
40300
40680
|
return;
|
|
40301
40681
|
}
|
|
40302
40682
|
await mkdir15(directory, { recursive: true, mode: 448 });
|
|
40303
|
-
const metadata = await
|
|
40683
|
+
const metadata = await stat15(directory);
|
|
40304
40684
|
const uid = process.geteuid?.();
|
|
40305
40685
|
if (uid !== void 0 && metadata.uid !== uid) {
|
|
40306
40686
|
throw new ClaustrumConsumerError2("unsafe-file", `Claustrum ${what} must be owned by the current user`);
|
|
@@ -40771,7 +41151,7 @@ var ByteTail = class {
|
|
|
40771
41151
|
};
|
|
40772
41152
|
var defaultCommandRunner = {
|
|
40773
41153
|
run(file, args, options = {}) {
|
|
40774
|
-
return new Promise((
|
|
41154
|
+
return new Promise((resolve34) => {
|
|
40775
41155
|
const started = performance.now();
|
|
40776
41156
|
const timeoutMs = options.timeoutMs ?? 15e3;
|
|
40777
41157
|
const stderr = new ByteTail();
|
|
@@ -40789,7 +41169,7 @@ var defaultCommandRunner = {
|
|
|
40789
41169
|
stdio: ["ignore", "pipe", "pipe"]
|
|
40790
41170
|
});
|
|
40791
41171
|
} catch {
|
|
40792
|
-
|
|
41172
|
+
resolve34({
|
|
40793
41173
|
exitCode: 1,
|
|
40794
41174
|
stdout: "",
|
|
40795
41175
|
stderr: "",
|
|
@@ -40824,7 +41204,7 @@ var defaultCommandRunner = {
|
|
|
40824
41204
|
settled = true;
|
|
40825
41205
|
if (timer)
|
|
40826
41206
|
clearTimeout(timer);
|
|
40827
|
-
|
|
41207
|
+
resolve34({
|
|
40828
41208
|
exitCode: spawnError ? 1 : outputExceeded ? 1 : code2 ?? 1,
|
|
40829
41209
|
stdout: Buffer.concat(stdout, stdoutLength).toString("utf8"),
|
|
40830
41210
|
stderr: stderr.toString(),
|
|
@@ -40980,7 +41360,7 @@ function recordSetupEnrollment(failure2, enrollment) {
|
|
|
40980
41360
|
}
|
|
40981
41361
|
|
|
40982
41362
|
// src/common-auth-embedded/setup/detect.js
|
|
40983
|
-
import { accessSync, constants as constants3, existsSync as existsSync6, readFileSync as readFileSync5, realpathSync as realpathSync3, statSync as
|
|
41363
|
+
import { accessSync, constants as constants3, existsSync as existsSync6, readFileSync as readFileSync5, realpathSync as realpathSync3, statSync as statSync6 } from "node:fs";
|
|
40984
41364
|
import { mkdtemp, rm as rm7 } from "node:fs/promises";
|
|
40985
41365
|
import { tmpdir as tmpdir3 } from "node:os";
|
|
40986
41366
|
import { join as join22 } from "node:path";
|
|
@@ -41018,21 +41398,21 @@ function setupPaths(io = {}) {
|
|
|
41018
41398
|
}
|
|
41019
41399
|
|
|
41020
41400
|
// src/common-auth-embedded/setup/detect.js
|
|
41021
|
-
function
|
|
41401
|
+
function stat16(path5, kind) {
|
|
41022
41402
|
try {
|
|
41023
|
-
return
|
|
41403
|
+
return statSync6(path5)[kind]();
|
|
41024
41404
|
} catch {
|
|
41025
41405
|
return false;
|
|
41026
41406
|
}
|
|
41027
41407
|
}
|
|
41028
41408
|
var defaultSetupFileSystem = {
|
|
41029
41409
|
exists: existsSync6,
|
|
41030
|
-
isFile: (path5) =>
|
|
41031
|
-
isDirectory: (path5) =>
|
|
41410
|
+
isFile: (path5) => stat16(path5, "isFile"),
|
|
41411
|
+
isDirectory: (path5) => stat16(path5, "isDirectory"),
|
|
41032
41412
|
isExecutable(path5) {
|
|
41033
41413
|
try {
|
|
41034
41414
|
accessSync(path5, constants3.X_OK);
|
|
41035
|
-
return
|
|
41415
|
+
return stat16(path5, "isFile");
|
|
41036
41416
|
} catch {
|
|
41037
41417
|
return false;
|
|
41038
41418
|
}
|
|
@@ -41221,14 +41601,14 @@ import { writeEnrollmentTokenFile as writeEnrollmentTokenFile3 } from "@cortexki
|
|
|
41221
41601
|
|
|
41222
41602
|
// src/common-auth-embedded/setup/process-fence.js
|
|
41223
41603
|
init_logger3();
|
|
41224
|
-
import { statSync as
|
|
41604
|
+
import { statSync as statSync7 } from "node:fs";
|
|
41225
41605
|
import { win32 as win323 } from "node:path";
|
|
41226
41606
|
var WINDOWS_CIM_TIMEOUT_MS = 45e3;
|
|
41227
41607
|
var log9 = createLogger3("setup-process-fence");
|
|
41228
41608
|
var WINDOWS_ARM_POWERSHELL_TIMEOUT_MS = 9e4;
|
|
41229
41609
|
function isFile(file) {
|
|
41230
41610
|
try {
|
|
41231
|
-
return
|
|
41611
|
+
return statSync7(file).isFile();
|
|
41232
41612
|
} catch {
|
|
41233
41613
|
return false;
|
|
41234
41614
|
}
|
|
@@ -41833,7 +42213,7 @@ import { applyEdits, createScanner, findNodeAtLocation, modify, parse as parse2,
|
|
|
41833
42213
|
|
|
41834
42214
|
// src/common-auth-embedded/setup/config-write.js
|
|
41835
42215
|
import { randomUUID as randomUUID18 } from "node:crypto";
|
|
41836
|
-
import { mkdir as mkdir16, open as open11, rename as rename13, stat as
|
|
42216
|
+
import { mkdir as mkdir16, open as open11, rename as rename13, stat as stat17, unlink as unlink14 } from "node:fs/promises";
|
|
41837
42217
|
import { basename as basename9, dirname as dirname22, join as join23 } from "node:path";
|
|
41838
42218
|
import { setTimeout as delay3 } from "node:timers/promises";
|
|
41839
42219
|
async function writeHostConfigAtomic(file, content, options = {}) {
|
|
@@ -41843,7 +42223,7 @@ async function writeHostConfigAtomic(file, content, options = {}) {
|
|
|
41843
42223
|
let mode;
|
|
41844
42224
|
if (!windows2) {
|
|
41845
42225
|
try {
|
|
41846
|
-
mode = (await
|
|
42226
|
+
mode = (await stat17(file)).mode & 4095;
|
|
41847
42227
|
} catch (error) {
|
|
41848
42228
|
if (error.code !== "ENOENT")
|
|
41849
42229
|
throw error;
|
|
@@ -42398,19 +42778,31 @@ async function readNativeAuth(path5) {
|
|
|
42398
42778
|
throw error;
|
|
42399
42779
|
}
|
|
42400
42780
|
}
|
|
42781
|
+
async function readOpenCodeAuthority(legacyPath) {
|
|
42782
|
+
try {
|
|
42783
|
+
const claustrum = await loadCommonAuthClaustrum();
|
|
42784
|
+
if (claustrum.hasVaultHost()) return "host";
|
|
42785
|
+
return await vaultAuthority2(
|
|
42786
|
+
claustrum.hostEnrollmentPaths({
|
|
42787
|
+
stateDir: openCodeVaultDir(
|
|
42788
|
+
legacyPath ?? resolve23(accountFileForVault())
|
|
42789
|
+
),
|
|
42790
|
+
host: "opencode"
|
|
42791
|
+
}),
|
|
42792
|
+
OPENCODE_VAULT_ENROLLMENT_NAME,
|
|
42793
|
+
claustrum
|
|
42794
|
+
);
|
|
42795
|
+
} catch {
|
|
42796
|
+
return "unreadable";
|
|
42797
|
+
}
|
|
42798
|
+
}
|
|
42401
42799
|
async function assertLocalOpenCodeLogin(legacyPath, generation) {
|
|
42402
|
-
|
|
42403
|
-
if (await claustrum.vaultAuthority(
|
|
42404
|
-
claustrum.hostEnrollmentPaths({
|
|
42405
|
-
stateDir: openCodeVaultDir(legacyPath),
|
|
42406
|
-
host: "opencode"
|
|
42407
|
-
}),
|
|
42408
|
-
OPENCODE_VAULT_ENROLLMENT_NAME
|
|
42409
|
-
) !== "local")
|
|
42800
|
+
if (await readOpenCodeAuthority(legacyPath) !== "local")
|
|
42410
42801
|
throw new Error(
|
|
42411
42802
|
"Vault enrollment excludes local sign-in. Resolve vault access before choosing local setup."
|
|
42412
42803
|
);
|
|
42413
42804
|
if (generation === "2") return;
|
|
42805
|
+
const claustrum = await loadCommonAuthClaustrum();
|
|
42414
42806
|
claustrum.assertHostSlotMatchesMode({
|
|
42415
42807
|
mode: "local",
|
|
42416
42808
|
auth: (await readNativeAuth(nativeOpenCodeAuthPath()))[OPENCODE_VAULT_PROVIDER],
|
|
@@ -43026,6 +43418,16 @@ async function runCli(argv, deps) {
|
|
|
43026
43418
|
return 0;
|
|
43027
43419
|
}
|
|
43028
43420
|
try {
|
|
43421
|
+
const assertLocalAccounts = async () => {
|
|
43422
|
+
const authority = await (deps.readAuthority ?? readOpenCodeAuthority)();
|
|
43423
|
+
if (authority === "local") return;
|
|
43424
|
+
const source2 = authority === "vault" ? "Accounts are served by the vault, not this computer's local sign-ins." : authority === "host" ? "Accounts are served by Thalamus, not this computer's local sign-ins." : "Account authority could not be read, so this computer's local sign-ins were not used.";
|
|
43425
|
+
throw new Error(
|
|
43426
|
+
`${source2} Use the /antigravity menu in OpenCode to see them and their quota.`
|
|
43427
|
+
);
|
|
43428
|
+
};
|
|
43429
|
+
if (parsed.value.command === "list" || parsed.value.command === "quota")
|
|
43430
|
+
await assertLocalAccounts();
|
|
43029
43431
|
if (parsed.value.command !== "setup") {
|
|
43030
43432
|
if (parsed.value.command === "login") await deps.prepareVaultFolder?.();
|
|
43031
43433
|
await deps.processHeartbeat?.();
|
|
@@ -43130,7 +43532,8 @@ async function runCli(argv, deps) {
|
|
|
43130
43532
|
return 0;
|
|
43131
43533
|
}
|
|
43132
43534
|
const results = await deps.getQuota(storage?.accounts ?? [], {
|
|
43133
|
-
refresh: parsed.value.refresh
|
|
43535
|
+
refresh: parsed.value.refresh,
|
|
43536
|
+
...parsed.value.refresh ? { assertAdmission: assertLocalAccounts } : {}
|
|
43134
43537
|
});
|
|
43135
43538
|
deps.stdout.write(
|
|
43136
43539
|
parsed.value.json ? `${JSON.stringify(quotaSummary(results))}
|
|
@@ -43594,8 +43997,8 @@ function getLocalDevPath(directory) {
|
|
|
43594
43997
|
}
|
|
43595
43998
|
function findPackageJsonUp(startPath) {
|
|
43596
43999
|
try {
|
|
43597
|
-
const
|
|
43598
|
-
let dir =
|
|
44000
|
+
const stat22 = fs4.statSync(startPath);
|
|
44001
|
+
let dir = stat22.isDirectory() ? startPath : path4.dirname(startPath);
|
|
43599
44002
|
for (let i = 0; i < 10; i++) {
|
|
43600
44003
|
const pkgPath = path4.join(dir, "package.json");
|
|
43601
44004
|
if (fs4.existsSync(pkgPath)) {
|
|
@@ -43925,7 +44328,7 @@ function isSessionId(value) {
|
|
|
43925
44328
|
// src/common-auth-embedded/rpc/port-file.js
|
|
43926
44329
|
init_private_files2();
|
|
43927
44330
|
import { createHash as createHash14, randomUUID as randomUUID19 } from "node:crypto";
|
|
43928
|
-
import { chmod as chmod7, mkdir as mkdir17, open as open12, readdir as readdir6, rename as rename15, rmdir as rmdir3, stat as
|
|
44331
|
+
import { chmod as chmod7, mkdir as mkdir17, open as open12, readdir as readdir6, rename as rename15, rmdir as rmdir3, stat as stat18, unlink as unlink15 } from "node:fs/promises";
|
|
43929
44332
|
import { uptime as uptime2 } from "node:os";
|
|
43930
44333
|
import { join as join30, resolve as resolve26 } from "node:path";
|
|
43931
44334
|
function staleBefore(clock2) {
|
|
@@ -43941,7 +44344,7 @@ async function removeStalePortFile(path5, raw, info, beforeRemove2) {
|
|
|
43941
44344
|
await beforeRemove2?.(path5);
|
|
43942
44345
|
try {
|
|
43943
44346
|
const current = await readPrivateText2(path5);
|
|
43944
|
-
const identity4 = await
|
|
44347
|
+
const identity4 = await stat18(path5);
|
|
43945
44348
|
if (current === raw && identity4.dev === info.dev && identity4.ino === info.ino && identity4.mtimeMs === info.mtimeMs && identity4.size === info.size)
|
|
43946
44349
|
await unlink15(path5).catch(() => {
|
|
43947
44350
|
});
|
|
@@ -44024,7 +44427,7 @@ async function writePortFile(dir, entry, options = {}) {
|
|
|
44024
44427
|
} catch (error) {
|
|
44025
44428
|
if (error.code !== "ENOENT" || attempt === 5)
|
|
44026
44429
|
throw error;
|
|
44027
|
-
await new Promise((
|
|
44430
|
+
await new Promise((resolve34) => setTimeout(resolve34, 25));
|
|
44028
44431
|
}
|
|
44029
44432
|
}
|
|
44030
44433
|
}
|
|
@@ -44064,7 +44467,7 @@ async function sweepRpcDirectory(dir, log19, options = {}, cutoff = staleBefore(
|
|
|
44064
44467
|
if (!name.startsWith("port-") || !name.endsWith(".json"))
|
|
44065
44468
|
continue;
|
|
44066
44469
|
const portFile = join30(dir, name);
|
|
44067
|
-
const info = await
|
|
44470
|
+
const info = await stat18(portFile).catch(() => void 0);
|
|
44068
44471
|
let raw;
|
|
44069
44472
|
try {
|
|
44070
44473
|
raw = await readPrivateText2(portFile);
|
|
@@ -44150,7 +44553,7 @@ var BodyTooLargeError = class extends Error {
|
|
|
44150
44553
|
}
|
|
44151
44554
|
};
|
|
44152
44555
|
function readBody(req) {
|
|
44153
|
-
return new Promise((
|
|
44556
|
+
return new Promise((resolve34, reject) => {
|
|
44154
44557
|
const tooLarge = (declaredOversize = false) => {
|
|
44155
44558
|
req.removeAllListeners("data");
|
|
44156
44559
|
req.on("data", () => {
|
|
@@ -44173,7 +44576,7 @@ function readBody(req) {
|
|
|
44173
44576
|
}
|
|
44174
44577
|
chunks.push(chunk);
|
|
44175
44578
|
});
|
|
44176
|
-
req.on("end", () =>
|
|
44579
|
+
req.on("end", () => resolve34(Buffer.concat(chunks).toString("utf8")));
|
|
44177
44580
|
req.on("error", reject);
|
|
44178
44581
|
});
|
|
44179
44582
|
}
|
|
@@ -44352,12 +44755,12 @@ async function startRpcServer(options) {
|
|
|
44352
44755
|
json(500, { error: "internal error" });
|
|
44353
44756
|
}
|
|
44354
44757
|
}
|
|
44355
|
-
const port = await new Promise((
|
|
44758
|
+
const port = await new Promise((resolve34, reject) => {
|
|
44356
44759
|
server.on("error", reject);
|
|
44357
44760
|
server.listen(0, "127.0.0.1", () => {
|
|
44358
44761
|
const addr = server.address();
|
|
44359
44762
|
if (addr && typeof addr === "object")
|
|
44360
|
-
|
|
44763
|
+
resolve34(addr.port);
|
|
44361
44764
|
else
|
|
44362
44765
|
reject(new Error("no port"));
|
|
44363
44766
|
});
|
|
@@ -44380,16 +44783,16 @@ async function startRpcServer(options) {
|
|
|
44380
44783
|
rpcPort: port
|
|
44381
44784
|
});
|
|
44382
44785
|
} catch (error) {
|
|
44383
|
-
await new Promise((
|
|
44786
|
+
await new Promise((resolve34) => server.close(() => resolve34()));
|
|
44384
44787
|
throw error;
|
|
44385
44788
|
}
|
|
44386
44789
|
return {
|
|
44387
44790
|
port,
|
|
44388
44791
|
token,
|
|
44389
44792
|
async stop() {
|
|
44390
|
-
await new Promise((
|
|
44793
|
+
await new Promise((resolve34) => {
|
|
44391
44794
|
server.closeAllConnections?.();
|
|
44392
|
-
server.close(() =>
|
|
44795
|
+
server.close(() => resolve34());
|
|
44393
44796
|
for (const socket of connections)
|
|
44394
44797
|
socket.destroy();
|
|
44395
44798
|
});
|
|
@@ -45314,8 +45717,8 @@ import { join as join33, resolve as resolve29 } from "node:path";
|
|
|
45314
45717
|
// ../core/dist/common-auth-embedded/tui-prefs/watcher.js
|
|
45315
45718
|
init_canonical_file_path();
|
|
45316
45719
|
init_private_files();
|
|
45317
|
-
import { lstatSync, readFileSync as readFileSync8, readlinkSync, realpathSync as realpathSync5, statSync as
|
|
45318
|
-
import { readFile as readFile17, stat as
|
|
45720
|
+
import { lstatSync, readFileSync as readFileSync8, readlinkSync, realpathSync as realpathSync5, statSync as statSync9, watch } from "node:fs";
|
|
45721
|
+
import { readFile as readFile17, stat as stat19 } from "node:fs/promises";
|
|
45319
45722
|
import { basename as basename11, dirname as dirname25, join as join32, resolve as resolve28 } from "node:path";
|
|
45320
45723
|
import { clearTimeout as clearTimeout2, setTimeout as setTimeout2 } from "node:timers";
|
|
45321
45724
|
var pathFsDefaults = { lstatSync, readlinkSync, realpathSync: realpathSync5 };
|
|
@@ -45351,14 +45754,14 @@ function watchFile(file, onChange, options, settings) {
|
|
|
45351
45754
|
return shared3.subscribe(onChange);
|
|
45352
45755
|
const name = basename11(path5);
|
|
45353
45756
|
const read = windowsPrivateFiles && !settings ? (file2) => readPrivateText(file2) : options.fs?.readFile ?? ((file2) => readFile17(file2, "utf8"));
|
|
45354
|
-
const probe = options.fs?.stat ??
|
|
45757
|
+
const probe = options.fs?.stat ?? stat19;
|
|
45355
45758
|
let timer = null;
|
|
45356
45759
|
let pollTimer = null;
|
|
45357
45760
|
let lastMetadata = null;
|
|
45358
45761
|
let lastSeen = null;
|
|
45359
45762
|
if (settings || !windowsPrivateFiles)
|
|
45360
45763
|
try {
|
|
45361
|
-
const metadata = identity3((options.fs?.statSync ??
|
|
45764
|
+
const metadata = identity3((options.fs?.statSync ?? statSync9)(path5), settings);
|
|
45362
45765
|
lastSeen = (options.fs?.readFileSync ?? ((file2) => readFileSync8(file2, "utf8")))(path5);
|
|
45363
45766
|
lastMetadata = metadata;
|
|
45364
45767
|
} catch {
|
|
@@ -46244,7 +46647,7 @@ function openSettings(definition, options) {
|
|
|
46244
46647
|
loaded = windowsSeen.get(path5) !== content;
|
|
46245
46648
|
windowsSeen.set(path5, content);
|
|
46246
46649
|
};
|
|
46247
|
-
const
|
|
46650
|
+
const readFile24 = async ([path5]) => {
|
|
46248
46651
|
let text2;
|
|
46249
46652
|
try {
|
|
46250
46653
|
text2 = await SettingsFs.readFile(path5, "utf8");
|
|
@@ -46281,7 +46684,7 @@ function openSettings(definition, options) {
|
|
|
46281
46684
|
snapshot: buildSettingsSnapshot(definition, file, parsed)
|
|
46282
46685
|
} : { status: "unparseable" };
|
|
46283
46686
|
};
|
|
46284
|
-
const outcome = process.platform === "win32" ? await
|
|
46687
|
+
const outcome = process.platform === "win32" ? await readFile24([file.path]) : await cache.read([file.path], readFile24);
|
|
46285
46688
|
const key2 = JSON.stringify([file.kind, file.path]);
|
|
46286
46689
|
if (currentSequence <= (committedSequences.get(key2) ?? 0))
|
|
46287
46690
|
return;
|
|
@@ -47105,7 +47508,7 @@ function readLegacyProjectSettings(text2) {
|
|
|
47105
47508
|
|
|
47106
47509
|
// src/settings/runtime.ts
|
|
47107
47510
|
init_dist();
|
|
47108
|
-
import { readFile as readFile22, stat as
|
|
47511
|
+
import { readFile as readFile22, stat as stat21 } from "node:fs/promises";
|
|
47109
47512
|
import { homedir as homedir12 } from "node:os";
|
|
47110
47513
|
import { basename as basename15, join as join38 } from "node:path";
|
|
47111
47514
|
|
|
@@ -47680,7 +48083,7 @@ function applyHotValues(target, next) {
|
|
|
47680
48083
|
var DEFAULT_RETRY_DELAYS_MS = [5e3, 15e3, 6e4, 3e5];
|
|
47681
48084
|
async function exists4(path5) {
|
|
47682
48085
|
try {
|
|
47683
|
-
await
|
|
48086
|
+
await stat21(path5);
|
|
47684
48087
|
return true;
|
|
47685
48088
|
} catch {
|
|
47686
48089
|
return false;
|
|
@@ -48378,6 +48781,25 @@ function selectBestVerificationUrl(urls) {
|
|
|
48378
48781
|
unique.sort((a, b) => score(b) - score(a));
|
|
48379
48782
|
return unique[0];
|
|
48380
48783
|
}
|
|
48784
|
+
function structuredVerificationUrl(bodyText) {
|
|
48785
|
+
const urls = /* @__PURE__ */ new Set();
|
|
48786
|
+
const collect = (payload) => {
|
|
48787
|
+
try {
|
|
48788
|
+
JSON.parse(payload, (key2, value) => {
|
|
48789
|
+
if (typeof value === "string" && /^(?:validation_url|verify_url|verification_url|url)$/i.test(key2) && /^https:\/\//i.test(decodeEscapedText(value).trim()))
|
|
48790
|
+
urls.add(value);
|
|
48791
|
+
return value;
|
|
48792
|
+
});
|
|
48793
|
+
} catch {
|
|
48794
|
+
}
|
|
48795
|
+
};
|
|
48796
|
+
collect(bodyText);
|
|
48797
|
+
for (const rawLine of bodyText.split("\n")) {
|
|
48798
|
+
const line = rawLine.trim();
|
|
48799
|
+
if (line.startsWith("data:")) collect(line.slice(5));
|
|
48800
|
+
}
|
|
48801
|
+
return selectBestVerificationUrl([...urls]);
|
|
48802
|
+
}
|
|
48381
48803
|
function extractAccountAccessErrorDetails(bodyText) {
|
|
48382
48804
|
const decodedBody = decodeEscapedText(bodyText);
|
|
48383
48805
|
const lowerBody = decodedBody.toLowerCase();
|
|
@@ -48455,11 +48877,13 @@ function extractAccountAccessErrorDetails(bodyText) {
|
|
|
48455
48877
|
(line) => line && !line.startsWith("data:") && /(verify|validation|required|ineligible)/i.test(line)
|
|
48456
48878
|
);
|
|
48457
48879
|
}
|
|
48880
|
+
const structuredVerifyUrl = structuredVerificationUrl(bodyText);
|
|
48458
48881
|
return {
|
|
48459
48882
|
validationRequired,
|
|
48460
48883
|
accountIneligible,
|
|
48461
48884
|
message,
|
|
48462
|
-
verifyUrl: selectBestVerificationUrl([...verificationUrls])
|
|
48885
|
+
verifyUrl: selectBestVerificationUrl([...verificationUrls]),
|
|
48886
|
+
...structuredVerifyUrl && { structuredVerifyUrl }
|
|
48463
48887
|
};
|
|
48464
48888
|
}
|
|
48465
48889
|
function buildAccountAccessProbeRequest(projectId) {
|
|
@@ -49493,7 +49917,7 @@ async function select3(items, options) {
|
|
|
49493
49917
|
}
|
|
49494
49918
|
renderedLines = linesWritten;
|
|
49495
49919
|
};
|
|
49496
|
-
return new Promise((
|
|
49920
|
+
return new Promise((resolve34) => {
|
|
49497
49921
|
const wasRaw = stdin.isRaw ?? false;
|
|
49498
49922
|
const cleanup2 = () => {
|
|
49499
49923
|
if (isCleanedUp) return;
|
|
@@ -49514,11 +49938,11 @@ async function select3(items, options) {
|
|
|
49514
49938
|
};
|
|
49515
49939
|
const onSignal = () => {
|
|
49516
49940
|
cleanup2();
|
|
49517
|
-
|
|
49941
|
+
resolve34(null);
|
|
49518
49942
|
};
|
|
49519
49943
|
const finishWithValue = (value) => {
|
|
49520
49944
|
cleanup2();
|
|
49521
|
-
|
|
49945
|
+
resolve34(value);
|
|
49522
49946
|
};
|
|
49523
49947
|
const findNextSelectable = (from, direction) => {
|
|
49524
49948
|
if (items.length === 0) return from;
|
|
@@ -49564,7 +49988,7 @@ async function select3(items, options) {
|
|
|
49564
49988
|
stdin.setRawMode(true);
|
|
49565
49989
|
} catch {
|
|
49566
49990
|
cleanup2();
|
|
49567
|
-
|
|
49991
|
+
resolve34(null);
|
|
49568
49992
|
return;
|
|
49569
49993
|
}
|
|
49570
49994
|
stdin.resume();
|
|
@@ -51967,20 +52391,20 @@ import crypto2 from "node:crypto";
|
|
|
51967
52391
|
import { createHash as createHash17 } from "node:crypto";
|
|
51968
52392
|
|
|
51969
52393
|
// src/plugin/cache/signature-cache.ts
|
|
52394
|
+
init_atomic_write();
|
|
51970
52395
|
init_runtime_paths();
|
|
51971
|
-
import {
|
|
51972
|
-
|
|
51973
|
-
|
|
51974
|
-
readFileSync as readFileSync14,
|
|
51975
|
-
renameSync as renameSync4,
|
|
51976
|
-
unlinkSync as unlinkSync3,
|
|
51977
|
-
writeFileSync as writeFileSync5
|
|
51978
|
-
} from "node:fs";
|
|
51979
|
-
import { tmpdir as tmpdir5 } from "node:os";
|
|
51980
|
-
import { dirname as dirname33, join as join40 } from "node:path";
|
|
52396
|
+
import { existsSync as existsSync13, readFileSync as readFileSync14 } from "node:fs";
|
|
52397
|
+
import { readFile as readFile23 } from "node:fs/promises";
|
|
52398
|
+
import { resolve as resolve32 } from "node:path";
|
|
51981
52399
|
function getSignatureCacheFilePath() {
|
|
51982
52400
|
return stateHomeSignatureCacheFile();
|
|
51983
52401
|
}
|
|
52402
|
+
var MAX_ENTRIES = 4096;
|
|
52403
|
+
function newestEntries(entries) {
|
|
52404
|
+
if (entries.length <= MAX_ENTRIES) return entries;
|
|
52405
|
+
return entries.sort(([, a], [, b]) => a.timestamp - b.timestamp).slice(-MAX_ENTRIES);
|
|
52406
|
+
}
|
|
52407
|
+
var pendingWrites = /* @__PURE__ */ new Map();
|
|
51984
52408
|
var SignatureCache = class {
|
|
51985
52409
|
// In-memory cache: key -> entry with signature and optional thinking text
|
|
51986
52410
|
cache = /* @__PURE__ */ new Map();
|
|
@@ -51995,6 +52419,8 @@ var SignatureCache = class {
|
|
|
51995
52419
|
now;
|
|
51996
52420
|
// State
|
|
51997
52421
|
dirty = false;
|
|
52422
|
+
revision = 0;
|
|
52423
|
+
pendingWrite;
|
|
51998
52424
|
writeTimer = null;
|
|
51999
52425
|
cleanupTimer = null;
|
|
52000
52426
|
// Statistics
|
|
@@ -52031,11 +52457,10 @@ var SignatureCache = class {
|
|
|
52031
52457
|
*/
|
|
52032
52458
|
store(key2, signature) {
|
|
52033
52459
|
if (!this.enabled) return;
|
|
52034
|
-
this.
|
|
52460
|
+
this.storeEntry(key2, {
|
|
52035
52461
|
value: signature,
|
|
52036
52462
|
timestamp: this.now()
|
|
52037
52463
|
});
|
|
52038
|
-
this.dirty = true;
|
|
52039
52464
|
}
|
|
52040
52465
|
/**
|
|
52041
52466
|
* Retrieve a signature from the cache.
|
|
@@ -52086,13 +52511,29 @@ var SignatureCache = class {
|
|
|
52086
52511
|
*/
|
|
52087
52512
|
storeThinking(key2, thinkingText, signature, toolIds) {
|
|
52088
52513
|
if (!this.enabled || !thinkingText || !signature) return;
|
|
52089
|
-
this.
|
|
52514
|
+
this.storeEntry(key2, {
|
|
52090
52515
|
value: signature,
|
|
52091
52516
|
timestamp: this.now(),
|
|
52092
52517
|
thinkingText,
|
|
52093
52518
|
textPreview: thinkingText.slice(0, 100),
|
|
52094
52519
|
toolIds
|
|
52095
52520
|
});
|
|
52521
|
+
}
|
|
52522
|
+
storeEntry(key2, entry) {
|
|
52523
|
+
this.cache.delete(key2);
|
|
52524
|
+
this.cache.set(key2, entry);
|
|
52525
|
+
if (this.cache.size > MAX_ENTRIES) {
|
|
52526
|
+
let oldest;
|
|
52527
|
+
let oldestTimestamp = Number.POSITIVE_INFINITY;
|
|
52528
|
+
for (const [candidate, value] of this.cache) {
|
|
52529
|
+
if (oldest === void 0 || value.timestamp < oldestTimestamp) {
|
|
52530
|
+
oldest = candidate;
|
|
52531
|
+
oldestTimestamp = value.timestamp;
|
|
52532
|
+
}
|
|
52533
|
+
}
|
|
52534
|
+
if (oldest !== void 0) this.cache.delete(oldest);
|
|
52535
|
+
}
|
|
52536
|
+
this.revision++;
|
|
52096
52537
|
this.dirty = true;
|
|
52097
52538
|
}
|
|
52098
52539
|
/**
|
|
@@ -52161,7 +52602,17 @@ var SignatureCache = class {
|
|
|
52161
52602
|
*/
|
|
52162
52603
|
async flush() {
|
|
52163
52604
|
if (!this.enabled) return true;
|
|
52164
|
-
|
|
52605
|
+
const path5 = resolve32(this.cacheFilePath);
|
|
52606
|
+
const previous = pendingWrites.get(path5) ?? Promise.resolve(true);
|
|
52607
|
+
const writing = previous.then(() => this.saveToDisk());
|
|
52608
|
+
this.pendingWrite = writing;
|
|
52609
|
+
pendingWrites.set(path5, writing);
|
|
52610
|
+
try {
|
|
52611
|
+
return await writing;
|
|
52612
|
+
} finally {
|
|
52613
|
+
if (this.pendingWrite === writing) this.pendingWrite = void 0;
|
|
52614
|
+
if (pendingWrites.get(path5) === writing) pendingWrites.delete(path5);
|
|
52615
|
+
}
|
|
52165
52616
|
}
|
|
52166
52617
|
/**
|
|
52167
52618
|
* Graceful shutdown: stop timers and flush to disk.
|
|
@@ -52176,7 +52627,7 @@ var SignatureCache = class {
|
|
|
52176
52627
|
this.cleanupTimer = null;
|
|
52177
52628
|
}
|
|
52178
52629
|
if (this.dirty && this.enabled) {
|
|
52179
|
-
this.
|
|
52630
|
+
void this.flush();
|
|
52180
52631
|
}
|
|
52181
52632
|
}
|
|
52182
52633
|
// ===========================================================================
|
|
@@ -52211,6 +52662,9 @@ var SignatureCache = class {
|
|
|
52211
52662
|
_expired++;
|
|
52212
52663
|
}
|
|
52213
52664
|
}
|
|
52665
|
+
if (this.cache.size > MAX_ENTRIES) {
|
|
52666
|
+
this.cache = new Map(newestEntries([...this.cache]));
|
|
52667
|
+
}
|
|
52214
52668
|
} catch {
|
|
52215
52669
|
}
|
|
52216
52670
|
}
|
|
@@ -52218,22 +52672,17 @@ var SignatureCache = class {
|
|
|
52218
52672
|
* Save cache to disk with atomic write pattern.
|
|
52219
52673
|
* Merges with existing disk entries that haven't expired.
|
|
52220
52674
|
*/
|
|
52221
|
-
saveToDisk() {
|
|
52675
|
+
async saveToDisk() {
|
|
52222
52676
|
try {
|
|
52223
|
-
const dir = dirname33(this.cacheFilePath);
|
|
52224
|
-
if (!existsSync13(dir)) {
|
|
52225
|
-
mkdirSync5(dir, { recursive: true });
|
|
52226
|
-
}
|
|
52227
|
-
const now2 = this.now();
|
|
52228
52677
|
let existingEntries = {};
|
|
52229
|
-
|
|
52230
|
-
|
|
52231
|
-
|
|
52232
|
-
|
|
52233
|
-
|
|
52234
|
-
} catch {
|
|
52235
|
-
}
|
|
52678
|
+
try {
|
|
52679
|
+
const content = await readFile23(this.cacheFilePath, "utf-8");
|
|
52680
|
+
const data = JSON.parse(content);
|
|
52681
|
+
existingEntries = data.entries || {};
|
|
52682
|
+
} catch {
|
|
52236
52683
|
}
|
|
52684
|
+
const now2 = this.now();
|
|
52685
|
+
const revision = this.revision;
|
|
52237
52686
|
const validDiskEntries = {};
|
|
52238
52687
|
for (const [key2, entry] of Object.entries(existingEntries)) {
|
|
52239
52688
|
const age = now2 - entry.timestamp;
|
|
@@ -52252,7 +52701,9 @@ var SignatureCache = class {
|
|
|
52252
52701
|
version: "1.0",
|
|
52253
52702
|
memory_ttl_seconds: this.retentionMemoryTtlMs / 1e3,
|
|
52254
52703
|
disk_ttl_seconds: this.retentionDiskTtlMs / 1e3,
|
|
52255
|
-
entries:
|
|
52704
|
+
entries: Object.fromEntries(
|
|
52705
|
+
newestEntries(Object.entries(mergedEntries))
|
|
52706
|
+
),
|
|
52256
52707
|
statistics: {
|
|
52257
52708
|
memory_hits: this.stats.memoryHits,
|
|
52258
52709
|
disk_hits: this.stats.diskHits,
|
|
@@ -52261,22 +52712,9 @@ var SignatureCache = class {
|
|
|
52261
52712
|
last_write: now2
|
|
52262
52713
|
}
|
|
52263
52714
|
};
|
|
52264
|
-
|
|
52265
|
-
tmpdir5(),
|
|
52266
|
-
`antigravity-cache-${Date.now()}-${Math.random().toString(36).slice(2)}.tmp`
|
|
52267
|
-
);
|
|
52268
|
-
writeFileSync5(tmpPath, JSON.stringify(cacheData, null, 2), "utf-8");
|
|
52269
|
-
try {
|
|
52270
|
-
renameSync4(tmpPath, this.cacheFilePath);
|
|
52271
|
-
} catch {
|
|
52272
|
-
writeFileSync5(this.cacheFilePath, readFileSync14(tmpPath));
|
|
52273
|
-
try {
|
|
52274
|
-
unlinkSync3(tmpPath);
|
|
52275
|
-
} catch {
|
|
52276
|
-
}
|
|
52277
|
-
}
|
|
52715
|
+
await writeJsonAtomic(this.cacheFilePath, cacheData);
|
|
52278
52716
|
this.stats.writes++;
|
|
52279
|
-
this.dirty = false;
|
|
52717
|
+
if (revision === this.revision) this.dirty = false;
|
|
52280
52718
|
return true;
|
|
52281
52719
|
} catch {
|
|
52282
52720
|
return false;
|
|
@@ -52299,8 +52737,8 @@ var SignatureCache = class {
|
|
|
52299
52737
|
}
|
|
52300
52738
|
startWriteTimer() {
|
|
52301
52739
|
this.writeTimer = setInterval(() => {
|
|
52302
|
-
if (this.dirty) {
|
|
52303
|
-
this.
|
|
52740
|
+
if (this.dirty && !this.pendingWrite) {
|
|
52741
|
+
void this.flush();
|
|
52304
52742
|
}
|
|
52305
52743
|
}, this.writeIntervalMs);
|
|
52306
52744
|
}
|
|
@@ -52479,11 +52917,18 @@ function createSignatureProcessState(options = {}) {
|
|
|
52479
52917
|
updateRetention(shared3.path);
|
|
52480
52918
|
return;
|
|
52481
52919
|
}
|
|
52482
|
-
|
|
52920
|
+
const finalWrite = shared3.cache.flush();
|
|
52921
|
+
shared3.finalWrite = finalWrite;
|
|
52483
52922
|
try {
|
|
52484
|
-
await
|
|
52923
|
+
await finalWrite;
|
|
52485
52924
|
} finally {
|
|
52486
|
-
shared3.
|
|
52925
|
+
if (shared3.finalWrite === finalWrite) {
|
|
52926
|
+
shared3.finalWrite = void 0;
|
|
52927
|
+
if (shared3.owners.size === 0) {
|
|
52928
|
+
disks.delete(shared3.path);
|
|
52929
|
+
shared3.cache.shutdown();
|
|
52930
|
+
}
|
|
52931
|
+
}
|
|
52487
52932
|
}
|
|
52488
52933
|
};
|
|
52489
52934
|
return {
|
|
@@ -52508,7 +52953,10 @@ function createSignatureProcessState(options = {}) {
|
|
|
52508
52953
|
pathReaders.add(consumer);
|
|
52509
52954
|
updateRetention(path5);
|
|
52510
52955
|
}
|
|
52511
|
-
const readableCache = () =>
|
|
52956
|
+
const readableCache = () => {
|
|
52957
|
+
const current = shared3 ?? (path5 ? disks.get(path5) : void 0);
|
|
52958
|
+
if (current?.owners.size) return current.cache;
|
|
52959
|
+
};
|
|
52512
52960
|
const signatureStore = createSignatureStore();
|
|
52513
52961
|
let disposed = false;
|
|
52514
52962
|
return {
|
|
@@ -52613,13 +53061,13 @@ function clearSignatureCache(sessionId) {
|
|
|
52613
53061
|
}
|
|
52614
53062
|
|
|
52615
53063
|
// src/plugin/image-saver.ts
|
|
52616
|
-
import { chmodSync as chmodSync4, existsSync as existsSync14, mkdirSync as
|
|
53064
|
+
import { chmodSync as chmodSync4, existsSync as existsSync14, mkdirSync as mkdirSync5, writeFileSync as writeFileSync5 } from "node:fs";
|
|
52617
53065
|
import { homedir as homedir14 } from "node:os";
|
|
52618
|
-
import { join as
|
|
53066
|
+
import { join as join40 } from "node:path";
|
|
52619
53067
|
function getImageOutputDir(outputDir) {
|
|
52620
|
-
const resolved = outputDir ??
|
|
53068
|
+
const resolved = outputDir ?? join40(homedir14(), ".opencode", "generated-images");
|
|
52621
53069
|
if (!existsSync14(resolved)) {
|
|
52622
|
-
|
|
53070
|
+
mkdirSync5(resolved, { recursive: true, mode: 448 });
|
|
52623
53071
|
}
|
|
52624
53072
|
chmodSync4(resolved, 448);
|
|
52625
53073
|
return resolved;
|
|
@@ -52640,8 +53088,8 @@ function generateImageFilename(mimeType) {
|
|
|
52640
53088
|
function saveImageToDisk(base64Data, mimeType, outputDir) {
|
|
52641
53089
|
try {
|
|
52642
53090
|
const resolvedOutputDir = getImageOutputDir(outputDir);
|
|
52643
|
-
const filePath =
|
|
52644
|
-
|
|
53091
|
+
const filePath = join40(resolvedOutputDir, generateImageFilename(mimeType));
|
|
53092
|
+
writeFileSync5(filePath, Buffer.from(base64Data, "base64"), { mode: 384 });
|
|
52645
53093
|
chmodSync4(filePath, 384);
|
|
52646
53094
|
return filePath;
|
|
52647
53095
|
} catch (error) {
|
|
@@ -53084,6 +53532,49 @@ data: ${JSON.stringify(syntheticUsage)}
|
|
|
53084
53532
|
});
|
|
53085
53533
|
}
|
|
53086
53534
|
|
|
53535
|
+
// src/plugin/core/streaming/displayed-thinking.ts
|
|
53536
|
+
var MAX_DISPLAYED_THINKING_SESSIONS = 256;
|
|
53537
|
+
var MAX_DISPLAYED_THINKING_PER_SESSION = 512;
|
|
53538
|
+
var BoundedHashSet = class extends Set {
|
|
53539
|
+
constructor(limit) {
|
|
53540
|
+
super();
|
|
53541
|
+
this.limit = limit;
|
|
53542
|
+
}
|
|
53543
|
+
limit;
|
|
53544
|
+
add(value) {
|
|
53545
|
+
if (!this.has(value) && this.size >= this.limit) {
|
|
53546
|
+
const oldest = this.values().next().value;
|
|
53547
|
+
if (oldest !== void 0) this.delete(oldest);
|
|
53548
|
+
}
|
|
53549
|
+
return super.add(value);
|
|
53550
|
+
}
|
|
53551
|
+
};
|
|
53552
|
+
function createDisplayedThinkingRegistry(limits = {}) {
|
|
53553
|
+
const maxSessions = limits.sessions ?? MAX_DISPLAYED_THINKING_SESSIONS;
|
|
53554
|
+
const perSession = limits.perSession ?? MAX_DISPLAYED_THINKING_PER_SESSION;
|
|
53555
|
+
const sessions = /* @__PURE__ */ new Map();
|
|
53556
|
+
return {
|
|
53557
|
+
forSession(sessionKey) {
|
|
53558
|
+
if (!sessionKey) return void 0;
|
|
53559
|
+
let hashes = sessions.get(sessionKey);
|
|
53560
|
+
if (hashes) {
|
|
53561
|
+
sessions.delete(sessionKey);
|
|
53562
|
+
} else {
|
|
53563
|
+
hashes = new BoundedHashSet(perSession);
|
|
53564
|
+
if (sessions.size >= maxSessions) {
|
|
53565
|
+
const oldest = sessions.keys().next().value;
|
|
53566
|
+
if (oldest !== void 0) sessions.delete(oldest);
|
|
53567
|
+
}
|
|
53568
|
+
}
|
|
53569
|
+
sessions.set(sessionKey, hashes);
|
|
53570
|
+
return hashes;
|
|
53571
|
+
},
|
|
53572
|
+
get sessionCount() {
|
|
53573
|
+
return sessions.size;
|
|
53574
|
+
}
|
|
53575
|
+
};
|
|
53576
|
+
}
|
|
53577
|
+
|
|
53087
53578
|
// src/plugin/request.ts
|
|
53088
53579
|
init_debug();
|
|
53089
53580
|
|
|
@@ -53091,12 +53582,12 @@ init_debug();
|
|
|
53091
53582
|
init_dist();
|
|
53092
53583
|
init_logging_utils();
|
|
53093
53584
|
import { createHash as createHash18 } from "node:crypto";
|
|
53094
|
-
import { appendFileSync as appendFileSync4, mkdirSync as
|
|
53095
|
-
import { tmpdir as
|
|
53096
|
-
import { join as
|
|
53585
|
+
import { appendFileSync as appendFileSync4, mkdirSync as mkdirSync6, writeFileSync as writeFileSync6 } from "node:fs";
|
|
53586
|
+
import { tmpdir as tmpdir5 } from "node:os";
|
|
53587
|
+
import { join as join41 } from "node:path";
|
|
53097
53588
|
var DUMP_STATUS_TITLE = "## Gemini Dump Status";
|
|
53098
53589
|
var DUMP_DIR_ENV = "OPENCODE_ANTIGRAVITY_GEMINI_DUMP_DIR";
|
|
53099
|
-
var DEFAULT_DUMP_DIR =
|
|
53590
|
+
var DEFAULT_DUMP_DIR = join41(tmpdir5(), "opencode-antigravity-gemini-dumps");
|
|
53100
53591
|
var DUMP_DIR_MODE = 448;
|
|
53101
53592
|
var DUMP_FILE_MODE = 384;
|
|
53102
53593
|
var nextDumpId = 0;
|
|
@@ -53228,7 +53719,7 @@ function bodyStructureSummary(bodyText) {
|
|
|
53228
53719
|
};
|
|
53229
53720
|
}
|
|
53230
53721
|
function writeJson(path5, value) {
|
|
53231
|
-
|
|
53722
|
+
writeFileSync6(path5, `${JSON.stringify(value, null, 2)}
|
|
53232
53723
|
`, {
|
|
53233
53724
|
encoding: "utf8",
|
|
53234
53725
|
mode: DUMP_FILE_MODE
|
|
@@ -53250,8 +53741,8 @@ function writeGeminiDump(input2) {
|
|
|
53250
53741
|
nextDumpId += 1;
|
|
53251
53742
|
const id = `${(/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-")}-${String(nextDumpId).padStart(5, "0")}-${input2.streaming ? "stream" : "json"}`;
|
|
53252
53743
|
const dumpDir = getGeminiDumpDirectory();
|
|
53253
|
-
const prefix =
|
|
53254
|
-
|
|
53744
|
+
const prefix = join41(dumpDir, id);
|
|
53745
|
+
mkdirSync6(dumpDir, { recursive: true, mode: DUMP_DIR_MODE });
|
|
53255
53746
|
const context = {
|
|
53256
53747
|
id,
|
|
53257
53748
|
files: {
|
|
@@ -53279,11 +53770,11 @@ function writeGeminiDump(input2) {
|
|
|
53279
53770
|
}
|
|
53280
53771
|
}
|
|
53281
53772
|
};
|
|
53282
|
-
|
|
53773
|
+
writeFileSync6(context.files.request, redactJsonBodyString(input2.body), {
|
|
53283
53774
|
encoding: "utf8",
|
|
53284
53775
|
mode: DUMP_FILE_MODE
|
|
53285
53776
|
});
|
|
53286
|
-
|
|
53777
|
+
writeFileSync6(context.files.response, "", {
|
|
53287
53778
|
encoding: "utf8",
|
|
53288
53779
|
mode: DUMP_FILE_MODE
|
|
53289
53780
|
});
|
|
@@ -53335,27 +53826,27 @@ init_logger4();
|
|
|
53335
53826
|
// src/plugin/recovery/storage.ts
|
|
53336
53827
|
import {
|
|
53337
53828
|
existsSync as existsSync15,
|
|
53338
|
-
mkdirSync as
|
|
53829
|
+
mkdirSync as mkdirSync7,
|
|
53339
53830
|
readdirSync as readdirSync2,
|
|
53340
53831
|
readFileSync as readFileSync15,
|
|
53341
|
-
unlinkSync as
|
|
53342
|
-
writeFileSync as
|
|
53832
|
+
unlinkSync as unlinkSync3,
|
|
53833
|
+
writeFileSync as writeFileSync7
|
|
53343
53834
|
} from "node:fs";
|
|
53344
|
-
import { join as
|
|
53835
|
+
import { join as join43 } from "node:path";
|
|
53345
53836
|
|
|
53346
53837
|
// src/plugin/recovery/constants.ts
|
|
53347
53838
|
import { homedir as homedir15 } from "node:os";
|
|
53348
|
-
import { join as
|
|
53839
|
+
import { join as join42 } from "node:path";
|
|
53349
53840
|
function getXdgData() {
|
|
53350
53841
|
const platform = process.platform;
|
|
53351
53842
|
if (platform === "win32") {
|
|
53352
|
-
return process.env.APPDATA ||
|
|
53843
|
+
return process.env.APPDATA || join42(homedir15(), "AppData", "Roaming");
|
|
53353
53844
|
}
|
|
53354
|
-
return process.env.XDG_DATA_HOME ||
|
|
53845
|
+
return process.env.XDG_DATA_HOME || join42(homedir15(), ".local", "share");
|
|
53355
53846
|
}
|
|
53356
|
-
var OPENCODE_STORAGE =
|
|
53357
|
-
var MESSAGE_STORAGE =
|
|
53358
|
-
var PART_STORAGE =
|
|
53847
|
+
var OPENCODE_STORAGE = join42(getXdgData(), "opencode", "storage");
|
|
53848
|
+
var MESSAGE_STORAGE = join42(OPENCODE_STORAGE, "message");
|
|
53849
|
+
var PART_STORAGE = join42(OPENCODE_STORAGE, "part");
|
|
53359
53850
|
var THINKING_TYPES = /* @__PURE__ */ new Set([
|
|
53360
53851
|
"thinking",
|
|
53361
53852
|
"redacted_thinking",
|
|
@@ -53365,13 +53856,13 @@ var THINKING_TYPES = /* @__PURE__ */ new Set([
|
|
|
53365
53856
|
// src/plugin/recovery/storage.ts
|
|
53366
53857
|
function getMessageDir(sessionID) {
|
|
53367
53858
|
if (!existsSync15(MESSAGE_STORAGE)) return "";
|
|
53368
|
-
const directPath =
|
|
53859
|
+
const directPath = join43(MESSAGE_STORAGE, sessionID);
|
|
53369
53860
|
if (existsSync15(directPath)) {
|
|
53370
53861
|
return directPath;
|
|
53371
53862
|
}
|
|
53372
53863
|
try {
|
|
53373
53864
|
for (const dir of readdirSync2(MESSAGE_STORAGE)) {
|
|
53374
|
-
const sessionPath =
|
|
53865
|
+
const sessionPath = join43(MESSAGE_STORAGE, dir, sessionID);
|
|
53375
53866
|
if (existsSync15(sessionPath)) {
|
|
53376
53867
|
return sessionPath;
|
|
53377
53868
|
}
|
|
@@ -53388,7 +53879,7 @@ function readMessages(sessionID) {
|
|
|
53388
53879
|
for (const file of readdirSync2(messageDir)) {
|
|
53389
53880
|
if (!file.endsWith(".json")) continue;
|
|
53390
53881
|
try {
|
|
53391
|
-
const content = readFileSync15(
|
|
53882
|
+
const content = readFileSync15(join43(messageDir, file), "utf-8");
|
|
53392
53883
|
messages.push(JSON.parse(content));
|
|
53393
53884
|
} catch {
|
|
53394
53885
|
}
|
|
@@ -53404,14 +53895,14 @@ function readMessages(sessionID) {
|
|
|
53404
53895
|
});
|
|
53405
53896
|
}
|
|
53406
53897
|
function readParts(messageID) {
|
|
53407
|
-
const partDir =
|
|
53898
|
+
const partDir = join43(PART_STORAGE, messageID);
|
|
53408
53899
|
if (!existsSync15(partDir)) return [];
|
|
53409
53900
|
const parts = [];
|
|
53410
53901
|
try {
|
|
53411
53902
|
for (const file of readdirSync2(partDir)) {
|
|
53412
53903
|
if (!file.endsWith(".json")) continue;
|
|
53413
53904
|
try {
|
|
53414
|
-
const content = readFileSync15(
|
|
53905
|
+
const content = readFileSync15(join43(partDir, file), "utf-8");
|
|
53415
53906
|
parts.push(JSON.parse(content));
|
|
53416
53907
|
} catch {
|
|
53417
53908
|
}
|
|
@@ -53453,10 +53944,10 @@ function findMessagesWithOrphanThinking(sessionID) {
|
|
|
53453
53944
|
return result;
|
|
53454
53945
|
}
|
|
53455
53946
|
function prependThinkingPart(sessionID, messageID) {
|
|
53456
|
-
const partDir =
|
|
53947
|
+
const partDir = join43(PART_STORAGE, messageID);
|
|
53457
53948
|
try {
|
|
53458
53949
|
if (!existsSync15(partDir)) {
|
|
53459
|
-
|
|
53950
|
+
mkdirSync7(partDir, { recursive: true });
|
|
53460
53951
|
}
|
|
53461
53952
|
const partId = "prt_0000000000_thinking";
|
|
53462
53953
|
const part = {
|
|
@@ -53467,8 +53958,8 @@ function prependThinkingPart(sessionID, messageID) {
|
|
|
53467
53958
|
thinking: "",
|
|
53468
53959
|
synthetic: true
|
|
53469
53960
|
};
|
|
53470
|
-
|
|
53471
|
-
|
|
53961
|
+
writeFileSync7(
|
|
53962
|
+
join43(partDir, `${partId}.json`),
|
|
53472
53963
|
JSON.stringify(part, null, 2)
|
|
53473
53964
|
);
|
|
53474
53965
|
return true;
|
|
@@ -53477,18 +53968,18 @@ function prependThinkingPart(sessionID, messageID) {
|
|
|
53477
53968
|
}
|
|
53478
53969
|
}
|
|
53479
53970
|
function stripThinkingParts(messageID) {
|
|
53480
|
-
const partDir =
|
|
53971
|
+
const partDir = join43(PART_STORAGE, messageID);
|
|
53481
53972
|
if (!existsSync15(partDir)) return false;
|
|
53482
53973
|
let anyRemoved = false;
|
|
53483
53974
|
try {
|
|
53484
53975
|
for (const file of readdirSync2(partDir)) {
|
|
53485
53976
|
if (!file.endsWith(".json")) continue;
|
|
53486
53977
|
try {
|
|
53487
|
-
const filePath =
|
|
53978
|
+
const filePath = join43(partDir, file);
|
|
53488
53979
|
const content = readFileSync15(filePath, "utf-8");
|
|
53489
53980
|
const part = JSON.parse(content);
|
|
53490
53981
|
if (THINKING_TYPES.has(part.type)) {
|
|
53491
|
-
|
|
53982
|
+
unlinkSync3(filePath);
|
|
53492
53983
|
anyRemoved = true;
|
|
53493
53984
|
}
|
|
53494
53985
|
} catch {
|
|
@@ -54781,6 +55272,9 @@ function fixToolResponseGrouping(contents) {
|
|
|
54781
55272
|
const newContents = [];
|
|
54782
55273
|
const pendingGroups = [];
|
|
54783
55274
|
const collectedResponses = /* @__PURE__ */ new Map();
|
|
55275
|
+
const arrivalById = /* @__PURE__ */ new Map();
|
|
55276
|
+
let arrivals = 0;
|
|
55277
|
+
const idsByName = /* @__PURE__ */ new Map();
|
|
54784
55278
|
for (const content of contents) {
|
|
54785
55279
|
const role = content.role;
|
|
54786
55280
|
const parts = content.parts || [];
|
|
@@ -54790,6 +55284,15 @@ function fixToolResponseGrouping(contents) {
|
|
|
54790
55284
|
const respId = resp.functionResponse?.id || "";
|
|
54791
55285
|
if (respId && !collectedResponses.has(respId)) {
|
|
54792
55286
|
collectedResponses.set(respId, resp);
|
|
55287
|
+
const arrival = arrivals++;
|
|
55288
|
+
arrivalById.set(respId, arrival);
|
|
55289
|
+
const name = resp.functionResponse?.name || "";
|
|
55290
|
+
let queue2 = idsByName.get(name);
|
|
55291
|
+
if (!queue2) {
|
|
55292
|
+
queue2 = { entries: [], head: 0 };
|
|
55293
|
+
idsByName.set(name, queue2);
|
|
55294
|
+
}
|
|
55295
|
+
queue2.entries.push({ id: respId, arrival });
|
|
54793
55296
|
}
|
|
54794
55297
|
}
|
|
54795
55298
|
for (let i = pendingGroups.length - 1; i >= 0; i--) {
|
|
@@ -54827,7 +55330,20 @@ function fixToolResponseGrouping(contents) {
|
|
|
54827
55330
|
newContents.push(content);
|
|
54828
55331
|
}
|
|
54829
55332
|
}
|
|
55333
|
+
const firstCollectedNamed = (name) => {
|
|
55334
|
+
const queue2 = idsByName.get(name);
|
|
55335
|
+
if (!queue2) return null;
|
|
55336
|
+
while (queue2.head < queue2.entries.length) {
|
|
55337
|
+
const entry = queue2.entries[queue2.head];
|
|
55338
|
+
if (collectedResponses.has(entry.id) && arrivalById.get(entry.id) === entry.arrival) {
|
|
55339
|
+
return entry.id;
|
|
55340
|
+
}
|
|
55341
|
+
queue2.head++;
|
|
55342
|
+
}
|
|
55343
|
+
return null;
|
|
55344
|
+
};
|
|
54830
55345
|
pendingGroups.sort((a, b) => b.insertAfterIdx - a.insertAfterIdx);
|
|
55346
|
+
const insertedAfter = /* @__PURE__ */ new Map();
|
|
54831
55347
|
for (const group of pendingGroups) {
|
|
54832
55348
|
const groupResponses = [];
|
|
54833
55349
|
for (let i = 0; i < group.ids.length; i++) {
|
|
@@ -54838,20 +55354,9 @@ function fixToolResponseGrouping(contents) {
|
|
|
54838
55354
|
collectedResponses.delete(expectedId);
|
|
54839
55355
|
} else if (collectedResponses.size > 0) {
|
|
54840
55356
|
let matchedId = null;
|
|
54841
|
-
|
|
54842
|
-
const orphanName = orphanResp.functionResponse?.name || "";
|
|
54843
|
-
if (orphanName === expectedName) {
|
|
54844
|
-
matchedId = orphanId;
|
|
54845
|
-
break;
|
|
54846
|
-
}
|
|
54847
|
-
}
|
|
55357
|
+
matchedId = firstCollectedNamed(expectedName);
|
|
54848
55358
|
if (!matchedId) {
|
|
54849
|
-
|
|
54850
|
-
if (orphanResp.functionResponse?.name === "unknown_function") {
|
|
54851
|
-
matchedId = orphanId;
|
|
54852
|
-
break;
|
|
54853
|
-
}
|
|
54854
|
-
}
|
|
55359
|
+
matchedId = firstCollectedNamed("unknown_function");
|
|
54855
55360
|
}
|
|
54856
55361
|
if (!matchedId) {
|
|
54857
55362
|
matchedId = collectedResponses.keys().next().value ?? null;
|
|
@@ -54891,13 +55396,20 @@ function fixToolResponseGrouping(contents) {
|
|
|
54891
55396
|
}
|
|
54892
55397
|
}
|
|
54893
55398
|
if (groupResponses.length > 0) {
|
|
54894
|
-
|
|
55399
|
+
insertedAfter.set(group.insertAfterIdx, {
|
|
54895
55400
|
parts: groupResponses,
|
|
54896
55401
|
role: "user"
|
|
54897
55402
|
});
|
|
54898
55403
|
}
|
|
54899
55404
|
}
|
|
54900
|
-
return newContents;
|
|
55405
|
+
if (insertedAfter.size === 0) return newContents;
|
|
55406
|
+
const withRecovered = [];
|
|
55407
|
+
for (let i = 0; i < newContents.length; i++) {
|
|
55408
|
+
withRecovered.push(newContents[i]);
|
|
55409
|
+
const recovered = insertedAfter.get(i);
|
|
55410
|
+
if (recovered) withRecovered.push(recovered);
|
|
55411
|
+
}
|
|
55412
|
+
return withRecovered;
|
|
54901
55413
|
}
|
|
54902
55414
|
function findOrphanedToolUseIds(messages) {
|
|
54903
55415
|
const toolUseIds = /* @__PURE__ */ new Set();
|
|
@@ -55812,7 +56324,7 @@ init_dist();
|
|
|
55812
56324
|
var log14 = createLogger4("request");
|
|
55813
56325
|
var PLUGIN_SESSION_ID = `-${crypto2.randomUUID()}`;
|
|
55814
56326
|
var DEFAULT_AGY_REQUEST_SESSION = createAgyRequestSessionContext();
|
|
55815
|
-
var
|
|
56327
|
+
var openCode1DisplayedThinking = createDisplayedThinkingRegistry();
|
|
55816
56328
|
var MIN_SIGNATURE_LENGTH = 50;
|
|
55817
56329
|
var AGY_CLAUDE_THINKING_BUDGET = 1024;
|
|
55818
56330
|
var ANTIGRAVITY_ENVELOPE_FIELD_ORDER = [
|
|
@@ -55958,6 +56470,9 @@ function ensureThinkingFields(obj) {
|
|
|
55958
56470
|
ensureThinkingFields(val);
|
|
55959
56471
|
}
|
|
55960
56472
|
}
|
|
56473
|
+
function systemInstructionOf(request2) {
|
|
56474
|
+
return request2 && typeof request2 === "object" ? request2.systemInstruction : void 0;
|
|
56475
|
+
}
|
|
55961
56476
|
function safeStringify(obj) {
|
|
55962
56477
|
ensureThinkingFields(obj);
|
|
55963
56478
|
return JSON.stringify(obj, thinkingSafeReplacer);
|
|
@@ -56210,9 +56725,6 @@ function stripUnsupportedAntigravityFields(payload) {
|
|
|
56210
56725
|
}
|
|
56211
56726
|
}
|
|
56212
56727
|
}
|
|
56213
|
-
function isGeminiFunctionResponseTurn(content, wireModel) {
|
|
56214
|
-
return wireModel.startsWith("gemini-") && content?.role === "model" && Array.isArray(content.parts) && content.parts.length > 0 && content.parts.every((part) => part?.functionResponse);
|
|
56215
|
-
}
|
|
56216
56728
|
function configureAntigravityToolCalling(payload) {
|
|
56217
56729
|
delete payload.toolConfig;
|
|
56218
56730
|
if (Array.isArray(payload.tools)) {
|
|
@@ -56634,7 +57146,7 @@ var openCode1WireLocation = {
|
|
|
56634
57146
|
},
|
|
56635
57147
|
logger: log14,
|
|
56636
57148
|
sessionFingerprint: () => getSessionFingerprint(),
|
|
56637
|
-
|
|
57149
|
+
displayedThinking: openCode1DisplayedThinking,
|
|
56638
57150
|
cacheStats: { last: null }
|
|
56639
57151
|
};
|
|
56640
57152
|
function getLastCacheStats() {
|
|
@@ -56659,6 +57171,7 @@ function prepareAntigravityRequestIn(wire, input2, init, accessToken, projectId,
|
|
|
56659
57171
|
let sessionId;
|
|
56660
57172
|
let needsSignedThinkingWarmup = false;
|
|
56661
57173
|
let thinkingRecoveryMessage;
|
|
57174
|
+
let wireSystemInstruction;
|
|
56662
57175
|
if (!isGenerativeLanguageRequest(input2)) {
|
|
56663
57176
|
return {
|
|
56664
57177
|
request: input2,
|
|
@@ -56787,13 +57300,8 @@ function prepareAntigravityRequestIn(wire, input2, init, accessToken, projectId,
|
|
|
56787
57300
|
normalizeNativeFunctionResponseRoles(req, effectiveModel);
|
|
56788
57301
|
}
|
|
56789
57302
|
for (const req of requestObjects) {
|
|
56790
|
-
if (Array.isArray(req.contents))
|
|
56791
|
-
|
|
56792
|
-
const lastContent = contents[contents.length - 1];
|
|
56793
|
-
if (lastContent?.role === "model" && !isGeminiFunctionResponseTurn(lastContent, effectiveModel) || lastContent?.role === "assistant") {
|
|
56794
|
-
contents.push({ role: "user", parts: [{ text: "[Continue]" }] });
|
|
56795
|
-
}
|
|
56796
|
-
}
|
|
57303
|
+
if (Array.isArray(req.contents))
|
|
57304
|
+
appendAgyContinuation(req.contents, effectiveModel);
|
|
56797
57305
|
if (Array.isArray(req.messages)) {
|
|
56798
57306
|
const messages = req.messages;
|
|
56799
57307
|
const lastMessage = messages[messages.length - 1];
|
|
@@ -56843,6 +57351,10 @@ function prepareAntigravityRequestIn(wire, input2, init, accessToken, projectId,
|
|
|
56843
57351
|
}
|
|
56844
57352
|
}
|
|
56845
57353
|
body = safeStringify(orderAntigravityEnvelope(wrappedBody));
|
|
57354
|
+
wireSystemInstruction = {
|
|
57355
|
+
body,
|
|
57356
|
+
instruction: systemInstructionOf(wrappedBody.request)
|
|
57357
|
+
};
|
|
56846
57358
|
} else {
|
|
56847
57359
|
const requestPayload = { ...parsedBody };
|
|
56848
57360
|
if (isImageGenerationModel(effectiveModel) && isOpenCodeTitleGenerationRequest(requestPayload)) {
|
|
@@ -57229,15 +57741,8 @@ function prepareAntigravityRequestIn(wire, input2, init, accessToken, projectId,
|
|
|
57229
57741
|
wire.signatures.signatureStore.delete(signatureSessionKey);
|
|
57230
57742
|
}
|
|
57231
57743
|
}
|
|
57232
|
-
if (Array.isArray(requestPayload.contents))
|
|
57233
|
-
|
|
57234
|
-
if (lastContent?.role === "model" && !isGeminiFunctionResponseTurn(lastContent, effectiveModel) || lastContent?.role === "assistant") {
|
|
57235
|
-
requestPayload.contents.push({
|
|
57236
|
-
role: "user",
|
|
57237
|
-
parts: [{ text: "[Continue]" }]
|
|
57238
|
-
});
|
|
57239
|
-
}
|
|
57240
|
-
}
|
|
57744
|
+
if (Array.isArray(requestPayload.contents))
|
|
57745
|
+
appendAgyContinuation(requestPayload.contents, effectiveModel);
|
|
57241
57746
|
if (Array.isArray(requestPayload.messages)) {
|
|
57242
57747
|
const lastMessage = requestPayload.messages[requestPayload.messages.length - 1];
|
|
57243
57748
|
if (lastMessage?.role === "model" || lastMessage?.role === "assistant") {
|
|
@@ -57265,15 +57770,8 @@ function prepareAntigravityRequestIn(wire, input2, init, accessToken, projectId,
|
|
|
57265
57770
|
stripUnsupportedAntigravityFields(requestPayload);
|
|
57266
57771
|
configureAntigravityToolCalling(requestPayload);
|
|
57267
57772
|
normalizeNativeFunctionResponseRoles(requestPayload, effectiveModel);
|
|
57268
|
-
if (Array.isArray(requestPayload.contents))
|
|
57269
|
-
|
|
57270
|
-
if (lastContent?.role === "model" && !isGeminiFunctionResponseTurn(lastContent, effectiveModel)) {
|
|
57271
|
-
requestPayload.contents.push({
|
|
57272
|
-
role: "user",
|
|
57273
|
-
parts: [{ text: "[Continue]" }]
|
|
57274
|
-
});
|
|
57275
|
-
}
|
|
57276
|
-
}
|
|
57773
|
+
if (Array.isArray(requestPayload.contents))
|
|
57774
|
+
appendAgyContinuation(requestPayload.contents, effectiveModel);
|
|
57277
57775
|
}
|
|
57278
57776
|
const effectiveProjectId = projectId?.trim() || ANTIGRAVITY_DEFAULT_PROJECT_ID;
|
|
57279
57777
|
resolvedProjectId = effectiveProjectId;
|
|
@@ -57298,6 +57796,10 @@ function prepareAntigravityRequestIn(wire, input2, init, accessToken, projectId,
|
|
|
57298
57796
|
requestType: "agent"
|
|
57299
57797
|
};
|
|
57300
57798
|
body = safeStringify(orderAntigravityEnvelope(wrappedBody));
|
|
57799
|
+
wireSystemInstruction = {
|
|
57800
|
+
body,
|
|
57801
|
+
instruction: requestPayload.systemInstruction
|
|
57802
|
+
};
|
|
57301
57803
|
}
|
|
57302
57804
|
} catch {
|
|
57303
57805
|
throw new Error("Failed to build Antigravity request body");
|
|
@@ -57341,7 +57843,8 @@ function prepareAntigravityRequestIn(wire, input2, init, accessToken, projectId,
|
|
|
57341
57843
|
toolDebugSummary: toolDebugSummaries.slice(0, 20).join(" | "),
|
|
57342
57844
|
needsSignedThinkingWarmup,
|
|
57343
57845
|
headerStyle: "antigravity",
|
|
57344
|
-
thinkingRecoveryMessage
|
|
57846
|
+
thinkingRecoveryMessage,
|
|
57847
|
+
...wireSystemInstruction ? { wireSystemInstruction } : {}
|
|
57345
57848
|
};
|
|
57346
57849
|
}
|
|
57347
57850
|
function prepareAntigravityRequest(...args) {
|
|
@@ -57459,7 +57962,7 @@ async function transformAntigravityResponseIn(wire, response, streaming, debugCo
|
|
|
57459
57962
|
signatureSessionKey: sessionId,
|
|
57460
57963
|
debugText,
|
|
57461
57964
|
cacheSignatures,
|
|
57462
|
-
displayedThinkingHashes: effectiveModel && isGemini3Model(effectiveModel) ? wire.
|
|
57965
|
+
displayedThinkingHashes: effectiveModel && isGemini3Model(effectiveModel) ? wire.displayedThinking.forSession(sessionId) : void 0
|
|
57463
57966
|
// injectSyntheticThinking removed - keep_thinking now unified with debug via debugText
|
|
57464
57967
|
}
|
|
57465
57968
|
);
|
|
@@ -57820,10 +58323,10 @@ async function retainResponseLifetime(response, cancellation) {
|
|
|
57820
58323
|
cancellation.release();
|
|
57821
58324
|
throw error;
|
|
57822
58325
|
}
|
|
57823
|
-
let
|
|
58326
|
+
let resolve34 = () => {
|
|
57824
58327
|
};
|
|
57825
58328
|
const settled = new Promise((done) => {
|
|
57826
|
-
|
|
58329
|
+
resolve34 = done;
|
|
57827
58330
|
});
|
|
57828
58331
|
let stopping = false;
|
|
57829
58332
|
let finished = false;
|
|
@@ -57833,7 +58336,7 @@ async function retainResponseLifetime(response, cancellation) {
|
|
|
57833
58336
|
finished = true;
|
|
57834
58337
|
cancellation.signal.removeEventListener("abort", abort);
|
|
57835
58338
|
cancellation.release();
|
|
57836
|
-
|
|
58339
|
+
resolve34();
|
|
57837
58340
|
};
|
|
57838
58341
|
const abort = () => {
|
|
57839
58342
|
if (finished || stopping) return;
|
|
@@ -57902,8 +58405,8 @@ function createAfterHandoff(work, signals, onFailure) {
|
|
|
57902
58405
|
let running = false;
|
|
57903
58406
|
let resolveCompletion = () => {
|
|
57904
58407
|
};
|
|
57905
|
-
const completion = new Promise((
|
|
57906
|
-
resolveCompletion =
|
|
58408
|
+
const completion = new Promise((resolve34) => {
|
|
58409
|
+
resolveCompletion = resolve34;
|
|
57907
58410
|
});
|
|
57908
58411
|
const finish = () => {
|
|
57909
58412
|
if (finished) return;
|
|
@@ -57950,14 +58453,14 @@ function createAfterHandoff(work, signals, onFailure) {
|
|
|
57950
58453
|
};
|
|
57951
58454
|
}
|
|
57952
58455
|
function publishResponse(dispatch) {
|
|
57953
|
-
return new Promise((
|
|
58456
|
+
return new Promise((resolve34, reject) => {
|
|
57954
58457
|
let acknowledge;
|
|
57955
58458
|
void Promise.resolve().then(
|
|
57956
58459
|
() => dispatch((callback) => {
|
|
57957
58460
|
acknowledge = callback;
|
|
57958
58461
|
})
|
|
57959
58462
|
).then((response) => {
|
|
57960
|
-
|
|
58463
|
+
resolve34(response);
|
|
57961
58464
|
acknowledge?.();
|
|
57962
58465
|
}, reject);
|
|
57963
58466
|
});
|
|
@@ -58048,16 +58551,21 @@ function createAuthLoader({
|
|
|
58048
58551
|
};
|
|
58049
58552
|
let storeOpening = null;
|
|
58050
58553
|
const openStore = () => {
|
|
58051
|
-
|
|
58052
|
-
|
|
58053
|
-
|
|
58054
|
-
|
|
58055
|
-
|
|
58056
|
-
|
|
58057
|
-
|
|
58058
|
-
|
|
58059
|
-
|
|
58060
|
-
|
|
58554
|
+
if (!storeOpening) {
|
|
58555
|
+
const attempt = deps.openAccountStore().then((opening) => {
|
|
58556
|
+
if (opening.status === "ready") {
|
|
58557
|
+
lifecycle.register({
|
|
58558
|
+
async dispose() {
|
|
58559
|
+
await opening.repository.dispose();
|
|
58560
|
+
}
|
|
58561
|
+
});
|
|
58562
|
+
} else if (opening.status === "refused" && opening.admission.status === "busy" && opening.admission.retryable && storeOpening === attempt) {
|
|
58563
|
+
storeOpening = null;
|
|
58564
|
+
}
|
|
58565
|
+
return opening;
|
|
58566
|
+
});
|
|
58567
|
+
storeOpening = attempt;
|
|
58568
|
+
}
|
|
58061
58569
|
return storeOpening;
|
|
58062
58570
|
};
|
|
58063
58571
|
const initializeFreshStore = async () => {
|
|
@@ -58555,16 +59063,10 @@ var BackgroundQuotaRefresh = class {
|
|
|
58555
59063
|
if (this.timer.unref) this.timer.unref();
|
|
58556
59064
|
}
|
|
58557
59065
|
async runTick() {
|
|
58558
|
-
if (
|
|
59066
|
+
if (!await this.canRun()) {
|
|
58559
59067
|
if (!this.disposed) this.scheduleNext(this.jitteredInterval());
|
|
58560
59068
|
return;
|
|
58561
59069
|
}
|
|
58562
|
-
if (this.disposed) return;
|
|
58563
|
-
const freshnessThresholdMs = Math.max(
|
|
58564
|
-
this.intervalMs - MIN_INTERVAL_MS,
|
|
58565
|
-
Math.floor(this.intervalMs / 2)
|
|
58566
|
-
);
|
|
58567
|
-
const ageMs = this.now() - this.snapshots.lastCheckedAt();
|
|
58568
59070
|
const lockPath = this.snapshots.pollLockPath;
|
|
58569
59071
|
let lock = null;
|
|
58570
59072
|
try {
|
|
@@ -58582,9 +59084,7 @@ var BackgroundQuotaRefresh = class {
|
|
|
58582
59084
|
return;
|
|
58583
59085
|
}
|
|
58584
59086
|
try {
|
|
58585
|
-
if (
|
|
58586
|
-
if (ageMs >= freshnessThresholdMs) await this.refresh();
|
|
58587
|
-
else await this.refreshTierSlot();
|
|
59087
|
+
if (await this.canRun()) await this.refresh();
|
|
58588
59088
|
} finally {
|
|
58589
59089
|
await lock.release().catch(() => {
|
|
58590
59090
|
});
|
|
@@ -58593,22 +59093,36 @@ var BackgroundQuotaRefresh = class {
|
|
|
58593
59093
|
this.scheduleNext(this.jitteredInterval());
|
|
58594
59094
|
}
|
|
58595
59095
|
}
|
|
59096
|
+
async canRun() {
|
|
59097
|
+
return !this.disposed && (!this.mayRun || await this.mayRun()) && !this.disposed;
|
|
59098
|
+
}
|
|
58596
59099
|
async refresh() {
|
|
58597
59100
|
const refreshedQuota = await this.refreshQuota();
|
|
58598
|
-
if (
|
|
58599
|
-
|
|
58600
|
-
if (refreshedQuota) await this.pushSnapshot();
|
|
59101
|
+
if (await this.canRun()) await this.refreshTierSlot();
|
|
59102
|
+
if (refreshedQuota && await this.canRun()) await this.pushSnapshot();
|
|
58601
59103
|
}
|
|
58602
59104
|
async refreshQuota() {
|
|
58603
|
-
if (this.disposed || this.mayRun && !await this.mayRun()) return false;
|
|
58604
59105
|
const manager = this.getAccountManager();
|
|
58605
59106
|
if (!manager) return false;
|
|
58606
|
-
const
|
|
59107
|
+
const observed = await (manager.readAccountsForQuotaPoll?.() ?? this.localObservations(manager));
|
|
59108
|
+
if (!await this.canRun()) return false;
|
|
59109
|
+
const now2 = this.now();
|
|
59110
|
+
const freshnessThresholdMs = Math.max(
|
|
59111
|
+
this.intervalMs - MIN_INTERVAL_MS,
|
|
59112
|
+
Math.floor(this.intervalMs / 2)
|
|
59113
|
+
);
|
|
59114
|
+
const accounts = observed.filter(
|
|
59115
|
+
({ enabled, cachedQuotaUpdatedAt: at }) => enabled !== false && (at === void 0 || !Number.isFinite(at) || at <= 0 || at > now2 || now2 - at >= freshnessThresholdMs)
|
|
59116
|
+
);
|
|
58607
59117
|
if (accounts.length === 0) return false;
|
|
58608
59118
|
let results;
|
|
58609
59119
|
try {
|
|
59120
|
+
const indexes = new Map(
|
|
59121
|
+
accounts.map((account, index) => [account, index])
|
|
59122
|
+
);
|
|
58610
59123
|
results = await this.quotaManager.refreshAccounts(accounts, {
|
|
58611
|
-
indexFor: (account) =>
|
|
59124
|
+
indexFor: (account) => indexes.get(account),
|
|
59125
|
+
publishSidebar: false,
|
|
58612
59126
|
// Do not force: the quota manager's per-account dedup and backoff
|
|
58613
59127
|
// apply — an account that already refreshed recently is skipped.
|
|
58614
59128
|
force: false
|
|
@@ -58616,7 +59130,7 @@ var BackgroundQuotaRefresh = class {
|
|
|
58616
59130
|
} catch {
|
|
58617
59131
|
return false;
|
|
58618
59132
|
}
|
|
58619
|
-
if (this.
|
|
59133
|
+
if (!await this.canRun()) return false;
|
|
58620
59134
|
const liveAccounts = manager.getAccounts();
|
|
58621
59135
|
const liveIndexByToken = /* @__PURE__ */ new Map();
|
|
58622
59136
|
for (const entry of liveAccounts) {
|
|
@@ -58625,7 +59139,8 @@ var BackgroundQuotaRefresh = class {
|
|
|
58625
59139
|
let anyUpdated = false;
|
|
58626
59140
|
for (let i = 0; i < results.length; i++) {
|
|
58627
59141
|
const result = results[i];
|
|
58628
|
-
if (result?.status !== "ok" || !result.quota?.groups)
|
|
59142
|
+
if (result?.status !== "ok" || !result.quota?.groups || result.checkedAt === void 0)
|
|
59143
|
+
continue;
|
|
58629
59144
|
const candidateTokens = [
|
|
58630
59145
|
result.updatedAccount?.refreshToken,
|
|
58631
59146
|
accounts[i]?.refreshToken
|
|
@@ -58634,7 +59149,13 @@ var BackgroundQuotaRefresh = class {
|
|
|
58634
59149
|
if (liveIndex === void 0) continue;
|
|
58635
59150
|
const liveToken = liveAccounts[liveIndex]?.parts.refreshToken;
|
|
58636
59151
|
if (!liveToken) continue;
|
|
58637
|
-
manager.updateQuotaCache(
|
|
59152
|
+
if (manager.updateQuotaCache(
|
|
59153
|
+
liveIndex,
|
|
59154
|
+
result.quota.groups,
|
|
59155
|
+
liveToken,
|
|
59156
|
+
result.checkedAt
|
|
59157
|
+
) === false)
|
|
59158
|
+
continue;
|
|
58638
59159
|
const uaTier = toCapturedTier(result.updatedAccount ?? {});
|
|
58639
59160
|
if (uaTier !== void 0) {
|
|
58640
59161
|
manager.applyUpdatedAccount(
|
|
@@ -58650,9 +59171,24 @@ var BackgroundQuotaRefresh = class {
|
|
|
58650
59171
|
}
|
|
58651
59172
|
anyUpdated = true;
|
|
58652
59173
|
}
|
|
58653
|
-
if (anyUpdated
|
|
59174
|
+
if (anyUpdated && await this.canRun()) {
|
|
59175
|
+
if (manager.saveToDisk) await manager.saveToDisk();
|
|
59176
|
+
else manager.requestSaveToDisk();
|
|
59177
|
+
}
|
|
58654
59178
|
return true;
|
|
58655
59179
|
}
|
|
59180
|
+
localObservations(manager) {
|
|
59181
|
+
const accounts = new Map(
|
|
59182
|
+
manager.getAccounts().map((row) => [row.parts.refreshToken, row])
|
|
59183
|
+
);
|
|
59184
|
+
return manager.getAccountsForQuotaCheck().map((target) => {
|
|
59185
|
+
const row = accounts.get(target.refreshToken);
|
|
59186
|
+
return {
|
|
59187
|
+
...target,
|
|
59188
|
+
cachedQuotaUpdatedAt: row?.cachedQuota && row.cachedQuotaUpdatedAt
|
|
59189
|
+
};
|
|
59190
|
+
});
|
|
59191
|
+
}
|
|
58656
59192
|
async refreshTierSlot() {
|
|
58657
59193
|
if (this.disposed || !this.loadAccountTier) return;
|
|
58658
59194
|
const manager = this.getAccountManager();
|
|
@@ -58677,7 +59213,7 @@ var BackgroundQuotaRefresh = class {
|
|
|
58677
59213
|
if (!accountForTier) return;
|
|
58678
59214
|
try {
|
|
58679
59215
|
const tier = await this.loadAccountTier(accountForTier);
|
|
58680
|
-
if (tier === null || this.
|
|
59216
|
+
if (tier === null || !await this.canRun()) return;
|
|
58681
59217
|
const liveEntry = manager.getAccounts().find((entry) => entry.parts.refreshToken === refreshToken);
|
|
58682
59218
|
if (!liveEntry) return;
|
|
58683
59219
|
manager.applyUpdatedAccount(
|
|
@@ -58713,6 +59249,7 @@ var BackgroundQuotaRefresh = class {
|
|
|
58713
59249
|
enabled: entry.enabled,
|
|
58714
59250
|
coolingDownUntil: entry.coolingDownUntil,
|
|
58715
59251
|
cachedQuota: entry.cachedQuota,
|
|
59252
|
+
cachedQuotaUpdatedAt: entry.cachedQuotaUpdatedAt,
|
|
58716
59253
|
cachedQuotaAccountId: entry.cachedQuotaAccountId,
|
|
58717
59254
|
// An account reorder changes which cached reading occupies an index.
|
|
58718
59255
|
// Use a refresh-token-derived account ID to detect that mismatch
|
|
@@ -58976,12 +59513,12 @@ var BackgroundVaultQuotaRefresh = class {
|
|
|
58976
59513
|
outcome.reason = "no-rows";
|
|
58977
59514
|
return;
|
|
58978
59515
|
}
|
|
58979
|
-
const
|
|
59516
|
+
const dueRoutes = pool.selector.rows.filter((row) => {
|
|
58980
59517
|
const quota = quotaReadingForVaultRoute(row.route, state2);
|
|
58981
59518
|
const at = quota?.cachedQuotaUpdatedAt;
|
|
58982
59519
|
return quota?.cachedQuota == null || typeof at !== "number" || !Number.isFinite(at) || at < 0 || now2 - at >= threshold;
|
|
58983
|
-
});
|
|
58984
|
-
if (
|
|
59520
|
+
}).map((row) => row.route);
|
|
59521
|
+
if (dueRoutes.length === 0) {
|
|
58985
59522
|
outcome.reason = "fresh";
|
|
58986
59523
|
return;
|
|
58987
59524
|
}
|
|
@@ -58990,6 +59527,7 @@ var BackgroundVaultQuotaRefresh = class {
|
|
|
58990
59527
|
const report = await checkAndPublishVaultQuota(
|
|
58991
59528
|
{
|
|
58992
59529
|
pool,
|
|
59530
|
+
routes: dueRoutes,
|
|
58993
59531
|
signal: controller.signal,
|
|
58994
59532
|
now: this.now,
|
|
58995
59533
|
onStage: (stage) => {
|
|
@@ -59635,15 +60173,15 @@ init_debug();
|
|
|
59635
60173
|
// src/plugin/dependencies.ts
|
|
59636
60174
|
init_dist();
|
|
59637
60175
|
import { homedir as homedir16 } from "node:os";
|
|
59638
|
-
import { join as
|
|
60176
|
+
import { join as join44 } from "node:path";
|
|
59639
60177
|
function defaultFilesystemRoots() {
|
|
59640
|
-
const xdgConfig2 = process.env.XDG_CONFIG_HOME ??
|
|
59641
|
-
const xdgState2 = process.env.XDG_STATE_HOME ??
|
|
60178
|
+
const xdgConfig2 = process.env.XDG_CONFIG_HOME ?? join44(homedir16(), ".config");
|
|
60179
|
+
const xdgState2 = process.env.XDG_STATE_HOME ?? join44(homedir16(), ".local", "state");
|
|
59642
60180
|
return {
|
|
59643
60181
|
projectRoot: process.cwd(),
|
|
59644
|
-
userConfigRoot:
|
|
59645
|
-
sidebarStateRoot:
|
|
59646
|
-
rpcRoot:
|
|
60182
|
+
userConfigRoot: join44(xdgConfig2, "opencode"),
|
|
60183
|
+
sidebarStateRoot: join44(xdgState2, "cortexkit", "antigravity-auth"),
|
|
60184
|
+
rpcRoot: join44(xdgState2, "cortexkit", "antigravity-auth", "rpc")
|
|
59647
60185
|
};
|
|
59648
60186
|
}
|
|
59649
60187
|
function resolvePluginDependencies(overrides = {}) {
|
|
@@ -59672,10 +60210,10 @@ function resolvePluginDependencies(overrides = {}) {
|
|
|
59672
60210
|
}
|
|
59673
60211
|
async function defaultSleep(ms, signal) {
|
|
59674
60212
|
if (ms <= 0) return;
|
|
59675
|
-
await new Promise((
|
|
60213
|
+
await new Promise((resolve34, reject) => {
|
|
59676
60214
|
const timer = setTimeout(() => {
|
|
59677
60215
|
signal?.removeEventListener("abort", onAbort);
|
|
59678
|
-
|
|
60216
|
+
resolve34();
|
|
59679
60217
|
}, ms);
|
|
59680
60218
|
timer.unref?.();
|
|
59681
60219
|
const onAbort = () => {
|
|
@@ -59924,8 +60462,6 @@ function candidateView(candidates) {
|
|
|
59924
60462
|
accounts.push({ account_id: accountId, credential_id: credentialId });
|
|
59925
60463
|
}
|
|
59926
60464
|
}
|
|
59927
|
-
if (accounts.length === 0)
|
|
59928
|
-
return void 0;
|
|
59929
60465
|
const lines = accounts.map(({ account_id, credential_id }) => Buffer.from(`${account_id} ${credential_id}
|
|
59930
60466
|
`, "utf8")).sort(Buffer.compare);
|
|
59931
60467
|
const hash2 = createHash22("sha256");
|
|
@@ -60002,8 +60538,8 @@ async function askRouting(input2) {
|
|
|
60002
60538
|
return void 0;
|
|
60003
60539
|
const requested = input2.deadlineMs ?? 1500;
|
|
60004
60540
|
const deadlineMs = Number.isNaN(requested) ? 1500 : Math.min(2e3, Math.max(1, requested));
|
|
60005
|
-
const expired = new Promise((
|
|
60006
|
-
timer = setTimeout(() =>
|
|
60541
|
+
const expired = new Promise((resolve34) => {
|
|
60542
|
+
timer = setTimeout(() => resolve34(void 0), deadlineMs);
|
|
60007
60543
|
timer.unref();
|
|
60008
60544
|
});
|
|
60009
60545
|
const cap = input2.holdWaitMaxS;
|
|
@@ -60017,7 +60553,7 @@ async function askRouting(input2) {
|
|
|
60017
60553
|
request2.warm_credential = warmCredentialId;
|
|
60018
60554
|
}
|
|
60019
60555
|
const candidates = candidateView(input2.candidates);
|
|
60020
|
-
if (candidates)
|
|
60556
|
+
if (candidates.accounts.length > 0 || request2.mode === "continue")
|
|
60021
60557
|
request2.candidates = candidates;
|
|
60022
60558
|
const pending = accountFor.call(handle, request2, { deadlineMs });
|
|
60023
60559
|
if (!isObject2(pending) || typeof pending.then !== "function")
|
|
@@ -60393,7 +60929,7 @@ function createRetryState() {
|
|
|
60393
60929
|
var MAX_WARMUP_SESSIONS = 1e3;
|
|
60394
60930
|
var MAX_WARMUP_RETRIES = 2;
|
|
60395
60931
|
function createWarmupState() {
|
|
60396
|
-
const
|
|
60932
|
+
const warmupAttemptCounts = /* @__PURE__ */ new Map();
|
|
60397
60933
|
const warmupSucceededSessionIds = /* @__PURE__ */ new Set();
|
|
60398
60934
|
let disposed = false;
|
|
60399
60935
|
function trackAttempt(sessionId) {
|
|
@@ -60401,22 +60937,22 @@ function createWarmupState() {
|
|
|
60401
60937
|
if (warmupSucceededSessionIds.has(sessionId)) {
|
|
60402
60938
|
return false;
|
|
60403
60939
|
}
|
|
60404
|
-
if (warmupAttemptedSessionIds.size >= MAX_WARMUP_SESSIONS) {
|
|
60405
|
-
const first = warmupAttemptedSessionIds.values().next().value;
|
|
60406
|
-
if (first) {
|
|
60407
|
-
warmupAttemptedSessionIds.delete(first);
|
|
60408
|
-
warmupSucceededSessionIds.delete(first);
|
|
60409
|
-
}
|
|
60410
|
-
}
|
|
60411
60940
|
const attempts2 = getAttemptCount(sessionId);
|
|
60412
60941
|
if (attempts2 >= MAX_WARMUP_RETRIES) {
|
|
60413
60942
|
return false;
|
|
60414
60943
|
}
|
|
60415
|
-
|
|
60944
|
+
if (attempts2 === 0 && warmupAttemptCounts.size >= MAX_WARMUP_SESSIONS) {
|
|
60945
|
+
const first = warmupAttemptCounts.keys().next().value;
|
|
60946
|
+
if (first !== void 0) {
|
|
60947
|
+
warmupAttemptCounts.delete(first);
|
|
60948
|
+
warmupSucceededSessionIds.delete(first);
|
|
60949
|
+
}
|
|
60950
|
+
}
|
|
60951
|
+
warmupAttemptCounts.set(sessionId, attempts2 + 1);
|
|
60416
60952
|
return true;
|
|
60417
60953
|
}
|
|
60418
60954
|
function getAttemptCount(sessionId) {
|
|
60419
|
-
return
|
|
60955
|
+
return warmupAttemptCounts.get(sessionId) ?? 0;
|
|
60420
60956
|
}
|
|
60421
60957
|
function markSuccess(sessionId) {
|
|
60422
60958
|
if (disposed) return;
|
|
@@ -60426,12 +60962,14 @@ function createWarmupState() {
|
|
|
60426
60962
|
if (first) warmupSucceededSessionIds.delete(first);
|
|
60427
60963
|
}
|
|
60428
60964
|
}
|
|
60429
|
-
function
|
|
60965
|
+
function refundAttempt(sessionId) {
|
|
60430
60966
|
if (disposed) return;
|
|
60431
|
-
|
|
60967
|
+
const attempts2 = getAttemptCount(sessionId);
|
|
60968
|
+
if (attempts2 <= 1) warmupAttemptCounts.delete(sessionId);
|
|
60969
|
+
else warmupAttemptCounts.set(sessionId, attempts2 - 1);
|
|
60432
60970
|
}
|
|
60433
60971
|
function clear() {
|
|
60434
|
-
|
|
60972
|
+
warmupAttemptCounts.clear();
|
|
60435
60973
|
warmupSucceededSessionIds.clear();
|
|
60436
60974
|
}
|
|
60437
60975
|
function dispose() {
|
|
@@ -60446,7 +60984,7 @@ function createWarmupState() {
|
|
|
60446
60984
|
trackAttempt,
|
|
60447
60985
|
getAttemptCount,
|
|
60448
60986
|
markSuccess,
|
|
60449
|
-
|
|
60987
|
+
refundAttempt,
|
|
60450
60988
|
clear,
|
|
60451
60989
|
dispose
|
|
60452
60990
|
};
|
|
@@ -60937,6 +61475,7 @@ function isTitleVaultRequest(kind, headers) {
|
|
|
60937
61475
|
var FIRST_RETRY_DELAY_MS = 1e3;
|
|
60938
61476
|
var MODEL_UNAVAILABLE_TTL_MS = 60 * 60 * 1e3;
|
|
60939
61477
|
var ROUTING_ASK_DEADLINE_MS = 2e3;
|
|
61478
|
+
var FIRST_PLACEMENT_REFUSAL_MAX_RETRY_SECS = 5;
|
|
60940
61479
|
var REFUSAL_BODY_TIMEOUT_MS = 2e3;
|
|
60941
61480
|
var REFUSAL_BODY_MAX_BYTES = 64 * 1024;
|
|
60942
61481
|
async function readRefusalBody(response, deadline) {
|
|
@@ -60965,8 +61504,8 @@ async function readRefusalBody(response, deadline) {
|
|
|
60965
61504
|
return false;
|
|
60966
61505
|
}
|
|
60967
61506
|
})(),
|
|
60968
|
-
new Promise((
|
|
60969
|
-
timer = setTimeout(() =>
|
|
61507
|
+
new Promise((resolve34) => {
|
|
61508
|
+
timer = setTimeout(() => resolve34(false), REFUSAL_BODY_TIMEOUT_MS);
|
|
60970
61509
|
})
|
|
60971
61510
|
])
|
|
60972
61511
|
);
|
|
@@ -61082,7 +61621,7 @@ function formatWaitTime(ms) {
|
|
|
61082
61621
|
return remainingMinutes > 0 ? `${hours}h ${remainingMinutes}m` : `${hours}h`;
|
|
61083
61622
|
}
|
|
61084
61623
|
function sleep4(ms, signal) {
|
|
61085
|
-
return new Promise((
|
|
61624
|
+
return new Promise((resolve34, reject) => {
|
|
61086
61625
|
if (signal?.aborted) {
|
|
61087
61626
|
reject(
|
|
61088
61627
|
signal.reason instanceof Error ? signal.reason : new Error("Aborted")
|
|
@@ -61092,7 +61631,7 @@ function sleep4(ms, signal) {
|
|
|
61092
61631
|
const timerMs = Math.min(Math.max(0, Math.floor(ms)), 2147483647);
|
|
61093
61632
|
const timeout = setTimeout(() => {
|
|
61094
61633
|
cleanup2();
|
|
61095
|
-
|
|
61634
|
+
resolve34();
|
|
61096
61635
|
}, timerMs);
|
|
61097
61636
|
const onAbort = () => {
|
|
61098
61637
|
cleanup2();
|
|
@@ -61165,15 +61704,16 @@ function createLocalQuotaRefresh(accountManager, quotaManager, log19) {
|
|
|
61165
61704
|
...signal ? { signal } : {}
|
|
61166
61705
|
});
|
|
61167
61706
|
if (signal?.aborted) return;
|
|
61168
|
-
if (result.status === "ok" && result.quota?.groups) {
|
|
61707
|
+
if (result.status === "ok" && result.quota?.groups && result.checkedAt !== void 0) {
|
|
61169
61708
|
const currentIndex = accountManager.getAccounts().indexOf(account);
|
|
61170
61709
|
if (currentIndex === -1) return;
|
|
61171
|
-
accountManager.updateQuotaCache(
|
|
61710
|
+
if (accountManager.updateQuotaCache(
|
|
61172
61711
|
currentIndex,
|
|
61173
61712
|
result.quota.groups,
|
|
61174
|
-
expectedRefreshToken
|
|
61175
|
-
|
|
61176
|
-
|
|
61713
|
+
expectedRefreshToken,
|
|
61714
|
+
result.checkedAt
|
|
61715
|
+
))
|
|
61716
|
+
accountManager.requestSaveToDisk();
|
|
61177
61717
|
}
|
|
61178
61718
|
} catch (err) {
|
|
61179
61719
|
log19.debug(
|
|
@@ -61299,6 +61839,18 @@ function createRequestExecutor(deps) {
|
|
|
61299
61839
|
let retired = false;
|
|
61300
61840
|
let drainPromise;
|
|
61301
61841
|
let disposePromise;
|
|
61842
|
+
let warnedConditionReceipt = false;
|
|
61843
|
+
const runVaultCondition = (operation) => {
|
|
61844
|
+
void Promise.resolve().then(operation).catch((error) => {
|
|
61845
|
+
if (warnedConditionReceipt || !(error instanceof Error) || !("kind" in error) || error.kind !== "no-receipt")
|
|
61846
|
+
return;
|
|
61847
|
+
warnedConditionReceipt = true;
|
|
61848
|
+
try {
|
|
61849
|
+
log19.warn("vault-condition-no-receipt");
|
|
61850
|
+
} catch {
|
|
61851
|
+
}
|
|
61852
|
+
});
|
|
61853
|
+
};
|
|
61302
61854
|
const reportVault401 = (admission, status) => {
|
|
61303
61855
|
if (!admission || status !== 401) return;
|
|
61304
61856
|
void Promise.resolve().then(() => admission.report401(status)).catch((error) => {
|
|
@@ -61410,6 +61962,7 @@ function createRequestExecutor(deps) {
|
|
|
61410
61962
|
} : void 0;
|
|
61411
61963
|
const isChildRequest = requestSessionIdentity.parentSessionId !== null;
|
|
61412
61964
|
let physicalSendCount = 0;
|
|
61965
|
+
let emptyResponseAttempts = 0;
|
|
61413
61966
|
if (accountManager.getAccountCount() === 0) {
|
|
61414
61967
|
const urlString2 = typeof input2 === "string" ? input2 : toUrlString(input2);
|
|
61415
61968
|
const modelFromUrl = extractModelFromUrl(urlString2) ?? "unknown";
|
|
@@ -61522,6 +62075,7 @@ function createRequestExecutor(deps) {
|
|
|
61522
62075
|
}
|
|
61523
62076
|
};
|
|
61524
62077
|
let accountSwitchCount = 0;
|
|
62078
|
+
let capacityExhaustedSelections = 0;
|
|
61525
62079
|
let unconfirmedRetries = 0;
|
|
61526
62080
|
const maxAccountSwitches = config.max_account_switches ?? 2;
|
|
61527
62081
|
let previousAccountIndex = -1;
|
|
@@ -61533,6 +62087,7 @@ function createRequestExecutor(deps) {
|
|
|
61533
62087
|
let routingPlacementConsidered = false;
|
|
61534
62088
|
let routedCandidate;
|
|
61535
62089
|
let continueRouting;
|
|
62090
|
+
let continueOnlyLogin = false;
|
|
61536
62091
|
const refusedRoutes = /* @__PURE__ */ new Map();
|
|
61537
62092
|
let routingTitle = false;
|
|
61538
62093
|
let routingWaitMs = 0;
|
|
@@ -61600,10 +62155,12 @@ function createRequestExecutor(deps) {
|
|
|
61600
62155
|
const choice = routedCandidate;
|
|
61601
62156
|
routedCandidate = void 0;
|
|
61602
62157
|
const exhausted = continueRouting;
|
|
62158
|
+
const onlyLoginContinuation = continueOnlyLogin;
|
|
61603
62159
|
continueRouting = void 0;
|
|
62160
|
+
continueOnlyLogin = false;
|
|
61604
62161
|
if (exhausted) refusedRoutes.set(routingIdentityKey(exhausted), exhausted);
|
|
61605
62162
|
const accountCount = accountManager.getAccountCount();
|
|
61606
|
-
if (accountCount === 0) {
|
|
62163
|
+
if (accountCount === 0 && !onlyLoginContinuation) {
|
|
61607
62164
|
if (choice) return failedRoutedPick();
|
|
61608
62165
|
return createNoAccountResponse(
|
|
61609
62166
|
"No Antigravity accounts available. Run `opencode auth login`.",
|
|
@@ -61791,7 +62348,7 @@ function createRequestExecutor(deps) {
|
|
|
61791
62348
|
const canHold = !!holdCandidate && candidates.some(
|
|
61792
62349
|
(candidate) => routingIdentityKey(candidate) === holdCandidate
|
|
61793
62350
|
);
|
|
61794
|
-
const
|
|
62351
|
+
const ask = () => deadline.wait(() => {
|
|
61795
62352
|
const input3 = {
|
|
61796
62353
|
sessionId: accountSessionIdentity.id,
|
|
61797
62354
|
provider: "antigravity",
|
|
@@ -61813,9 +62370,21 @@ function createRequestExecutor(deps) {
|
|
|
61813
62370
|
} : input3
|
|
61814
62371
|
);
|
|
61815
62372
|
});
|
|
62373
|
+
let answer = await ask();
|
|
62374
|
+
const firstRefusal = !exhausted && answer && "refused" in answer ? answer.refused : void 0;
|
|
62375
|
+
if (firstRefusal?.code === "account_selection_refused" && firstRefusal.retryAfterSecs !== void 0 && firstRefusal.retryAfterSecs <= FIRST_PLACEMENT_REFUSAL_MAX_RETRY_SECS) {
|
|
62376
|
+
await routingSleep(
|
|
62377
|
+
firstRefusal.retryAfterSecs * 1e3,
|
|
62378
|
+
"account_free"
|
|
62379
|
+
);
|
|
62380
|
+
checkAborted();
|
|
62381
|
+
answer = await ask();
|
|
62382
|
+
}
|
|
61816
62383
|
checkAborted();
|
|
61817
62384
|
if (answer && "refused" in answer)
|
|
61818
62385
|
return routingRefusalResponse(answer.refused);
|
|
62386
|
+
if (!answer && onlyLoginContinuation && candidates.length === 0)
|
|
62387
|
+
return failedRoutedPick();
|
|
61819
62388
|
if (exhausted && answer?.hold) {
|
|
61820
62389
|
if (!canHold || routingIdentityKey(answer.candidate) !== holdCandidate)
|
|
61821
62390
|
return failedRoutedPick();
|
|
@@ -62288,12 +62857,14 @@ function createRequestExecutor(deps) {
|
|
|
62288
62857
|
streaming: true,
|
|
62289
62858
|
projectId
|
|
62290
62859
|
});
|
|
62860
|
+
let warmupDispatched = false;
|
|
62291
62861
|
try {
|
|
62292
62862
|
pushDebug("thinking-warmup: start");
|
|
62293
62863
|
const warmupSend = await credentialForAuxiliarySend(
|
|
62294
62864
|
warmupInit,
|
|
62295
62865
|
projectId
|
|
62296
62866
|
);
|
|
62867
|
+
warmupDispatched = true;
|
|
62297
62868
|
const warmupResponse = await sendPhysical(
|
|
62298
62869
|
warmupUrl,
|
|
62299
62870
|
warmupSend.init,
|
|
@@ -62318,7 +62889,7 @@ function createRequestExecutor(deps) {
|
|
|
62318
62889
|
warmupState.markSuccess(prepared.sessionId);
|
|
62319
62890
|
pushDebug("thinking-warmup: done");
|
|
62320
62891
|
} catch (error) {
|
|
62321
|
-
warmupState.
|
|
62892
|
+
if (!warmupDispatched) warmupState.refundAttempt(prepared.sessionId);
|
|
62322
62893
|
if (error instanceof PreResponseTimeoutError) throw error;
|
|
62323
62894
|
checkAborted();
|
|
62324
62895
|
if (isLocalGrantError(error)) throw error;
|
|
@@ -62651,9 +63222,9 @@ function createRequestExecutor(deps) {
|
|
|
62651
63222
|
const routed429 = response.status === 429 ? routedIdentity : void 0;
|
|
62652
63223
|
if (response.status === 429 && rateLimitReason === "UNKNOWN") {
|
|
62653
63224
|
await logResponseBody2(debugContext, response, 429);
|
|
62654
|
-
const
|
|
63225
|
+
const carried = prepared.wireSystemInstruction;
|
|
62655
63226
|
const recognised = systemInstructionHasHarnessIdentity(
|
|
62656
|
-
|
|
63227
|
+
carried && carried.body === prepared.init.body ? carried.instruction : JSON.parse(String(prepared.init.body)).request?.systemInstruction
|
|
62657
63228
|
);
|
|
62658
63229
|
if (recognised) {
|
|
62659
63230
|
void response.body?.cancel().catch(() => {
|
|
@@ -62777,10 +63348,19 @@ function createRequestExecutor(deps) {
|
|
|
62777
63348
|
i -= 1;
|
|
62778
63349
|
continue;
|
|
62779
63350
|
}
|
|
63351
|
+
retainHttpFailure(response);
|
|
63352
|
+
capacityExhaustedSelections++;
|
|
63353
|
+
if (capacityExhaustedSelections > 1) {
|
|
63354
|
+
pushDebug(
|
|
63355
|
+
`Total capacity retries (${MAX_TOTAL_CAPACITY_RETRIES}) exhausted again after one account switch, giving up`
|
|
63356
|
+
);
|
|
63357
|
+
return terminalMainAttemptFailure(
|
|
63358
|
+
"Antigravity has no capacity for this model right now"
|
|
63359
|
+
);
|
|
63360
|
+
}
|
|
62780
63361
|
pushDebug(
|
|
62781
63362
|
`Total capacity retries (${MAX_TOTAL_CAPACITY_RETRIES}) exhausted, switching account`
|
|
62782
63363
|
);
|
|
62783
|
-
retainHttpFailure(response);
|
|
62784
63364
|
shouldSwitchAccount = true;
|
|
62785
63365
|
break;
|
|
62786
63366
|
}
|
|
@@ -62926,6 +63506,10 @@ function createRequestExecutor(deps) {
|
|
|
62926
63506
|
i -= 1;
|
|
62927
63507
|
continue;
|
|
62928
63508
|
}
|
|
63509
|
+
if (routed429 && exhaustion) {
|
|
63510
|
+
const { accountId, credentialId } = routed429;
|
|
63511
|
+
continueRouting = { accountId, credentialId, ...exhaustion };
|
|
63512
|
+
}
|
|
62929
63513
|
const switchAccountDelayMs = config.switch_account_delay_ms ?? 500;
|
|
62930
63514
|
if (accountCount > 1) {
|
|
62931
63515
|
const quotaMsg = reasonInfo.quotaResetTime ? ` (quota resets ${reasonInfo.quotaResetTime})` : ``;
|
|
@@ -62934,7 +63518,7 @@ function createRequestExecutor(deps) {
|
|
|
62934
63518
|
"warning"
|
|
62935
63519
|
);
|
|
62936
63520
|
await sleep4(switchAccountDelayMs, abortSignal);
|
|
62937
|
-
} else {
|
|
63521
|
+
} else if (!continueRouting || isHardEligible(account)) {
|
|
62938
63522
|
const expBackoffMs = Math.min(
|
|
62939
63523
|
FIRST_RETRY_DELAY_MS * 2 ** (backoff.attempt - 1),
|
|
62940
63524
|
6e4
|
|
@@ -62951,10 +63535,6 @@ function createRequestExecutor(deps) {
|
|
|
62951
63535
|
);
|
|
62952
63536
|
}
|
|
62953
63537
|
retainHttpFailure(response);
|
|
62954
|
-
if (routed429 && exhaustion) {
|
|
62955
|
-
const { accountId, credentialId } = routed429;
|
|
62956
|
-
continueRouting = { accountId, credentialId, ...exhaustion };
|
|
62957
|
-
}
|
|
62958
63538
|
shouldSwitchAccount = true;
|
|
62959
63539
|
break;
|
|
62960
63540
|
}
|
|
@@ -62998,6 +63578,19 @@ function createRequestExecutor(deps) {
|
|
|
62998
63578
|
() => response.clone().text().catch(() => "")
|
|
62999
63579
|
);
|
|
63000
63580
|
const extracted = errorBodyText === void 0 ? void 0 : classifyAccessError(errorBodyText);
|
|
63581
|
+
const served2 = sendAdmission;
|
|
63582
|
+
const reportCondition = (reason) => {
|
|
63583
|
+
if (credentials.domain !== "vault" || !served2?.reportCondition)
|
|
63584
|
+
return;
|
|
63585
|
+
const actionUrl = extracted?.structuredVerifyUrl;
|
|
63586
|
+
waitPolicy.vaultConditions.push(
|
|
63587
|
+
() => served2.reportCondition?.({
|
|
63588
|
+
reason,
|
|
63589
|
+
providerStatus: 403,
|
|
63590
|
+
...actionUrl && { actionUrl }
|
|
63591
|
+
})
|
|
63592
|
+
);
|
|
63593
|
+
};
|
|
63001
63594
|
if (routedIdentity && (extracted?.accountIneligible || extracted?.validationRequired)) {
|
|
63002
63595
|
const { accountId, credentialId } = routedIdentity;
|
|
63003
63596
|
continueRouting = {
|
|
@@ -63027,6 +63620,7 @@ function createRequestExecutor(deps) {
|
|
|
63027
63620
|
trackers.health.recordFailure(account.index);
|
|
63028
63621
|
retainHttpFailure(response);
|
|
63029
63622
|
shouldSwitchAccount = true;
|
|
63623
|
+
reportCondition("provider_ineligible");
|
|
63030
63624
|
break;
|
|
63031
63625
|
}
|
|
63032
63626
|
if (extracted?.validationRequired) {
|
|
@@ -63062,6 +63656,7 @@ function createRequestExecutor(deps) {
|
|
|
63062
63656
|
trackers.health.recordFailure(account.index);
|
|
63063
63657
|
retainHttpFailure(response);
|
|
63064
63658
|
shouldSwitchAccount = true;
|
|
63659
|
+
reportCondition("provider_verification_required");
|
|
63065
63660
|
break;
|
|
63066
63661
|
}
|
|
63067
63662
|
}
|
|
@@ -63141,8 +63736,7 @@ function createRequestExecutor(deps) {
|
|
|
63141
63736
|
})
|
|
63142
63737
|
);
|
|
63143
63738
|
if (isEmptyResponseBody(bodyText)) {
|
|
63144
|
-
const
|
|
63145
|
-
const currentAttempts = retryState.recordEmptyResponseAttempt(emptyAttemptKey);
|
|
63739
|
+
const currentAttempts = ++emptyResponseAttempts;
|
|
63146
63740
|
pushDebug(
|
|
63147
63741
|
`empty-response: attempt ${currentAttempts}/${maxAttempts}`
|
|
63148
63742
|
);
|
|
@@ -63155,14 +63749,11 @@ function createRequestExecutor(deps) {
|
|
|
63155
63749
|
await sleep4(retryDelayMs, abortSignal);
|
|
63156
63750
|
continue;
|
|
63157
63751
|
}
|
|
63158
|
-
retryState.clearEmptyResponseAttempts();
|
|
63159
63752
|
return createNativeGoogleErrorResponse({
|
|
63160
63753
|
status: 502,
|
|
63161
63754
|
reason: "empty_response"
|
|
63162
63755
|
});
|
|
63163
63756
|
}
|
|
63164
|
-
const _emptyAttemptKeyClean = `${prepared.sessionId ?? "none"}:${prepared.effectiveModel ?? "unknown"}`;
|
|
63165
|
-
retryState.clearEmptyResponseAttempts();
|
|
63166
63757
|
}
|
|
63167
63758
|
const routingObservation = credentials.domain === "vault" && sendAdmission && sessionKey && response.ok && hasVaultRoutingAccessor() ? observeVaultUpstream(response, abortSignal) : void 0;
|
|
63168
63759
|
const transformedResponse = await deadline.wait(
|
|
@@ -63199,7 +63790,7 @@ function createRequestExecutor(deps) {
|
|
|
63199
63790
|
}
|
|
63200
63791
|
if (apiRequestCount > 1) {
|
|
63201
63792
|
pushDebug(
|
|
63202
|
-
`[Quota]
|
|
63793
|
+
`[Quota] Main-request responses on this account selection: ${apiRequestCount}`
|
|
63203
63794
|
);
|
|
63204
63795
|
}
|
|
63205
63796
|
const dailyCounts = accountManager.getDailyRequestCounts(
|
|
@@ -63239,6 +63830,9 @@ function createRequestExecutor(deps) {
|
|
|
63239
63830
|
const refresh = credentials.refreshQuotaAfterSuccess;
|
|
63240
63831
|
waitPolicy.quota = (signal) => refresh(account, config.quota_refresh_interval_minutes, signal);
|
|
63241
63832
|
}
|
|
63833
|
+
const served = sendAdmission;
|
|
63834
|
+
if (credentials.domain === "vault" && response.ok && transformedResponse.ok && served?.clearCondition)
|
|
63835
|
+
waitPolicy.vaultConditions.push(() => served.clearCondition?.());
|
|
63242
63836
|
return routingObservation && credentials.domain === "vault" && sendAdmission && sessionKey && hasVaultRoutingAccessor() && response.ok ? observeVaultServed(
|
|
63243
63837
|
{
|
|
63244
63838
|
sessionId: sessionKey,
|
|
@@ -63256,6 +63850,7 @@ function createRequestExecutor(deps) {
|
|
|
63256
63850
|
trackers.token.refund(account.index);
|
|
63257
63851
|
tokenConsumed = false;
|
|
63258
63852
|
}
|
|
63853
|
+
deadline.resume();
|
|
63259
63854
|
if (credentials.domain === "local" && localGrant?.captured.source === "store" && isLocalGrantError(error)) {
|
|
63260
63855
|
if (error instanceof LocalGrantSupersededError && !localRecaptureUsed) {
|
|
63261
63856
|
localRecaptureUsed = true;
|
|
@@ -63341,6 +63936,10 @@ function createRequestExecutor(deps) {
|
|
|
63341
63936
|
}
|
|
63342
63937
|
if (shouldSwitchAccount) {
|
|
63343
63938
|
if (switchedForUnconfirmed) continue;
|
|
63939
|
+
if (accountCount === 1 && continueRouting && (continueRouting.limitWindow === "signed_out" || !isHardEligible(account))) {
|
|
63940
|
+
continueOnlyLogin = true;
|
|
63941
|
+
continue;
|
|
63942
|
+
}
|
|
63344
63943
|
accountSwitchCount++;
|
|
63345
63944
|
if (accountSwitchCount > maxAccountSwitches) {
|
|
63346
63945
|
pushDebug(
|
|
@@ -63409,7 +64008,11 @@ function createRequestExecutor(deps) {
|
|
|
63409
64008
|
requestedSignal ? [requestedSignal, shutdown.signal] : [shutdown.signal],
|
|
63410
64009
|
() => log19.debug("post-response-advisory-work-failed")
|
|
63411
64010
|
);
|
|
63412
|
-
const waitPolicy = {};
|
|
64011
|
+
const waitPolicy = { vaultConditions: [] };
|
|
64012
|
+
const publishVaultConditions = () => {
|
|
64013
|
+
for (const operation of waitPolicy.vaultConditions.splice(0))
|
|
64014
|
+
runVaultCondition(operation);
|
|
64015
|
+
};
|
|
63413
64016
|
const selectedCredentials = /* @__PURE__ */ new Set();
|
|
63414
64017
|
const selectedProjectIds = /* @__PURE__ */ new Set();
|
|
63415
64018
|
const redactFailure = (error) => {
|
|
@@ -63482,7 +64085,21 @@ function createRequestExecutor(deps) {
|
|
|
63482
64085
|
cancellation.release();
|
|
63483
64086
|
throw redactFailure(error);
|
|
63484
64087
|
}
|
|
63485
|
-
).
|
|
64088
|
+
).then((response) => {
|
|
64089
|
+
if (waitPolicy.vaultConditions.length > 0) {
|
|
64090
|
+
if (requestOptions?.onResponseHandoff) {
|
|
64091
|
+
try {
|
|
64092
|
+
requestOptions.onResponseHandoff(publishVaultConditions);
|
|
64093
|
+
return response;
|
|
64094
|
+
} catch {
|
|
64095
|
+
}
|
|
64096
|
+
}
|
|
64097
|
+
setImmediate(publishVaultConditions);
|
|
64098
|
+
}
|
|
64099
|
+
return response;
|
|
64100
|
+
}).catch((error) => {
|
|
64101
|
+
if (waitPolicy.vaultConditions.length > 0)
|
|
64102
|
+
setImmediate(publishVaultConditions);
|
|
63486
64103
|
handoff.cancel();
|
|
63487
64104
|
deadline.dispose();
|
|
63488
64105
|
cancellation.release();
|
|
@@ -64183,8 +64800,8 @@ function createPluginLifecycle(options) {
|
|
|
64183
64800
|
};
|
|
64184
64801
|
let failDisposal = () => {
|
|
64185
64802
|
};
|
|
64186
|
-
disposal = new Promise((
|
|
64187
|
-
finishDisposal =
|
|
64803
|
+
disposal = new Promise((resolve34, reject) => {
|
|
64804
|
+
finishDisposal = resolve34;
|
|
64188
64805
|
failDisposal = reject;
|
|
64189
64806
|
});
|
|
64190
64807
|
void (async () => {
|
|
@@ -64372,7 +64989,7 @@ var createAntigravityPluginRuntime = (providerId, options = {}) => async (input2
|
|
|
64372
64989
|
// Diagnostics. Before the move they load from and write to the
|
|
64373
64990
|
// project or user antigravity.json through the operator writer.
|
|
64374
64991
|
operator: () => createOperatorSettingsController({
|
|
64375
|
-
projectConfigPath:
|
|
64992
|
+
projectConfigPath: join45(directory, ".opencode", "antigravity.json"),
|
|
64376
64993
|
// getUserConfigPath() already returns the full file path including
|
|
64377
64994
|
// 'antigravity.json' — do NOT join again or the path double-nests
|
|
64378
64995
|
// into <dir>/antigravity.json/antigravity.json.
|
|
@@ -64434,7 +65051,7 @@ var createAntigravityPluginRuntime = (providerId, options = {}) => async (input2
|
|
|
64434
65051
|
await drainSidebarWrites();
|
|
64435
65052
|
}
|
|
64436
65053
|
});
|
|
64437
|
-
const accountFile =
|
|
65054
|
+
const accountFile = resolve33(accountFileForVault());
|
|
64438
65055
|
const vaultFolder = await prepareVaultFolder({ accountFile });
|
|
64439
65056
|
const unavailableMessage = vaultFolder.refusal?.message ?? VAULT_ACCOUNT_REMEDY;
|
|
64440
65057
|
let vaultQuotaPoller;
|
|
@@ -64467,7 +65084,12 @@ var createAntigravityPluginRuntime = (providerId, options = {}) => async (input2
|
|
|
64467
65084
|
source,
|
|
64468
65085
|
pool: createOpenCodeVaultAccountPool({
|
|
64469
65086
|
source,
|
|
64470
|
-
durable: {
|
|
65087
|
+
durable: {
|
|
65088
|
+
source,
|
|
65089
|
+
readState: () => vaultCustody.readState(),
|
|
65090
|
+
stateFile: vaultCustody.paths.stateFile,
|
|
65091
|
+
onReadFailure: () => logger2.debug("vault-state-read-skipped")
|
|
65092
|
+
}
|
|
64471
65093
|
})
|
|
64472
65094
|
};
|
|
64473
65095
|
return vaultPool;
|