@cortexkit/opencode-antigravity-auth 3.0.38 → 3.0.40
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/README.md +1 -1
- package/dist/cli.js +865 -357
- package/dist/cli.js.map +4 -4
- package/dist/cli.meta.json +136 -39
- package/dist/index.js +1509 -657
- package/dist/index.js.map +4 -4
- package/dist/index.meta.json +188 -49
- package/dist/server.js +1662 -803
- package/dist/server.js.map +4 -4
- package/dist/server.meta.json +1 -1
- package/dist/src/common-auth-embedded/claustrum/availability.d.ts +7 -1
- package/dist/src/common-auth-embedded/claustrum/availability.js +9 -1
- package/dist/src/common-auth-embedded/claustrum/custody.d.ts +11 -2
- package/dist/src/common-auth-embedded/claustrum/custody.js +89 -31
- package/dist/src/common-auth-embedded/claustrum/enrollment.d.ts +29 -4
- package/dist/src/common-auth-embedded/claustrum/enrollment.js +110 -2
- package/dist/src/common-auth-embedded/claustrum/host.js +11 -7
- package/dist/src/common-auth-embedded/claustrum/index.d.ts +1 -1
- package/dist/src/common-auth-embedded/claustrum/index.js +1 -1
- package/dist/src/common-auth-embedded/fs/lock-record.js +55 -0
- package/dist/src/common-auth-embedded/fs/refresh-file-lock.js +148 -92
- package/dist/src/common-auth-embedded/fs/with-lock.js +19 -13
- package/dist/src/common-auth-embedded/quota-sidebar/index.d.ts +2 -36
- package/dist/src/common-auth-embedded/quota-sidebar/index.tsx +49 -607
- package/dist/src/common-auth-embedded/routing-accessor/cache-policy.d.ts +3 -0
- package/dist/src/common-auth-embedded/routing-accessor/cache-policy.js +11 -0
- package/dist/src/common-auth-embedded/routing-accessor/index.d.ts +48 -5
- package/dist/src/common-auth-embedded/routing-accessor/index.js +136 -5
- package/dist/src/common-auth-embedded/setup/command-error.d.ts +1 -1
- package/dist/src/common-auth-embedded/setup/command-error.js +3 -2
- package/dist/src/common-auth-embedded/setup/command.js +18 -5
- package/dist/src/common-auth-embedded/setup/enroll.d.ts +2 -2
- package/dist/src/common-auth-embedded/setup/enroll.js +14 -3
- package/dist/src/common-auth-embedded/setup/enrollment-access.js +77 -0
- package/dist/src/common-auth-embedded/setup/index.d.ts +1 -1
- package/dist/src/common-auth-embedded/setup/types.d.ts +13 -1
- package/dist/src/common-auth-embedded/source-output.json +95 -79
- package/dist/src/ga/tui/host-ga.d.ts +20 -3
- package/dist/src/ga/tui/host-ga.d.ts.map +1 -1
- package/dist/src/ga/tui/host-ga.js +102 -25
- package/dist/src/ga/tui/host-ga.js.map +1 -1
- package/dist/src/plugin/__fixtures__/release-model-ids.d.ts.map +1 -1
- package/dist/src/plugin/__fixtures__/release-model-ids.js +1 -0
- package/dist/src/plugin/__fixtures__/release-model-ids.js.map +1 -1
- package/dist/src/plugin/__fixtures__/verified-store.js +2 -2
- 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 +6 -0
- package/dist/src/plugin/ga-location-services.js.map +1 -1
- package/dist/src/plugin/logger.d.ts +3 -1
- package/dist/src/plugin/logger.d.ts.map +1 -1
- package/dist/src/plugin/logger.js +15 -7
- package/dist/src/plugin/logger.js.map +1 -1
- package/dist/src/plugin/request.d.ts.map +1 -1
- package/dist/src/plugin/request.js +3 -1
- package/dist/src/plugin/request.js.map +1 -1
- package/dist/src/plugin/shared/request-services.d.ts.map +1 -1
- package/dist/src/plugin/shared/request-services.js +34 -9
- package/dist/src/plugin/shared/request-services.js.map +1 -1
- package/dist/src/plugin/shared/vault-billing.d.ts +30 -0
- package/dist/src/plugin/shared/vault-billing.d.ts.map +1 -0
- package/dist/src/plugin/shared/vault-billing.js +196 -0
- package/dist/src/plugin/shared/vault-billing.js.map +1 -0
- package/dist/src/plugin/vault-custody.d.ts.map +1 -1
- package/dist/src/plugin/vault-custody.js +3 -0
- package/dist/src/plugin/vault-custody.js.map +1 -1
- package/dist/src/setup.d.ts.map +1 -1
- package/dist/src/setup.js +14 -0
- package/dist/src/setup.js.map +1 -1
- package/dist/tui-build-map.json +19 -5
- package/dist/tui-ga-build-map.json +23 -9
- package/dist/types/src/common-auth-embedded/claustrum/availability.d.ts +7 -1
- package/dist/types/src/common-auth-embedded/claustrum/custody.d.ts +11 -2
- package/dist/types/src/common-auth-embedded/claustrum/enrollment.d.ts +29 -4
- package/dist/types/src/common-auth-embedded/claustrum/index.d.ts +1 -1
- package/dist/types/src/common-auth-embedded/routing-accessor/cache-policy.d.ts +3 -0
- package/dist/types/src/common-auth-embedded/routing-accessor/index.d.ts +48 -5
- package/dist/types/src/common-auth-embedded/setup/command-error.d.ts +1 -1
- package/dist/types/src/common-auth-embedded/setup/enroll.d.ts +2 -2
- package/dist/types/src/common-auth-embedded/setup/index.d.ts +1 -1
- package/dist/types/src/common-auth-embedded/setup/types.d.ts +13 -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/logger.d.ts +3 -1
- package/dist/types/src/plugin/logger.d.ts.map +1 -1
- package/dist/types/src/plugin/request.d.ts.map +1 -1
- package/dist/types/src/plugin/shared/request-services.d.ts.map +1 -1
- package/dist/types/src/plugin/shared/vault-billing.d.ts +30 -0
- package/dist/types/src/plugin/shared/vault-billing.d.ts.map +1 -0
- package/dist/types/src/plugin/vault-custody.d.ts.map +1 -1
- package/dist/types/src/setup.d.ts.map +1 -1
- package/package.json +4 -3
- package/src/common-auth-embedded/claustrum/availability.d.ts +7 -1
- package/src/common-auth-embedded/claustrum/availability.js +9 -1
- package/src/common-auth-embedded/claustrum/custody.d.ts +11 -2
- package/src/common-auth-embedded/claustrum/custody.js +89 -31
- package/src/common-auth-embedded/claustrum/enrollment.d.ts +29 -4
- package/src/common-auth-embedded/claustrum/enrollment.js +110 -2
- package/src/common-auth-embedded/claustrum/host.js +11 -7
- package/src/common-auth-embedded/claustrum/index.d.ts +1 -1
- package/src/common-auth-embedded/claustrum/index.js +1 -1
- package/src/common-auth-embedded/fs/lock-record.js +55 -0
- package/src/common-auth-embedded/fs/refresh-file-lock.js +148 -92
- package/src/common-auth-embedded/fs/with-lock.js +19 -13
- package/src/common-auth-embedded/quota-sidebar/index.d.ts +2 -36
- package/src/common-auth-embedded/quota-sidebar/index.tsx +49 -607
- package/src/common-auth-embedded/routing-accessor/cache-policy.d.ts +3 -0
- package/src/common-auth-embedded/routing-accessor/cache-policy.js +11 -0
- package/src/common-auth-embedded/routing-accessor/index.d.ts +48 -5
- package/src/common-auth-embedded/routing-accessor/index.js +136 -5
- package/src/common-auth-embedded/setup/command-error.d.ts +1 -1
- package/src/common-auth-embedded/setup/command-error.js +3 -2
- package/src/common-auth-embedded/setup/command.js +18 -5
- package/src/common-auth-embedded/setup/enroll.d.ts +2 -2
- package/src/common-auth-embedded/setup/enroll.js +14 -3
- package/src/common-auth-embedded/setup/enrollment-access.js +77 -0
- package/src/common-auth-embedded/setup/index.d.ts +1 -1
- package/src/common-auth-embedded/setup/types.d.ts +13 -1
- package/src/common-auth-embedded/source-output.json +95 -79
- package/src/tui-compiled/common-auth-embedded/quota-sidebar/index.js +36 -674
- package/src/tui-compiled/shared/a75d0d866c227b3f-index.js +678 -0
- package/src/tui-ga-compiled/host-ga.js +86 -26
- package/src/tui-ga-compiled/shared/a75d0d866c227b3f-index.js +678 -0
- package/src/tui-ga-compiled/shared/e4ec36f367492969-index.js +36 -674
- package/src/tui-ga-raw/host-ga.tsx +122 -25
- package/src/tui-ga-raw/shared/a75d0d866c227b3f-index.tsx +681 -0
- package/src/tui-ga-raw/shared/e4ec36f367492969-index.tsx +49 -607
- package/src/tui-raw/common-auth-embedded/quota-sidebar/index.tsx +49 -607
- package/src/tui-raw/shared/a75d0d866c227b3f-index.tsx +681 -0
package/dist/index.js
CHANGED
|
@@ -989,10 +989,10 @@ async function readPointerRecord(legacyPath) {
|
|
|
989
989
|
return decodeAccountStorePointerRecord(jsonBytes(await secureRead(path5)), legacyPath);
|
|
990
990
|
}
|
|
991
991
|
async function readPointer(legacyPath) {
|
|
992
|
-
const
|
|
993
|
-
if (
|
|
994
|
-
throw new AccountMigrationError(`the account store moved to ${
|
|
995
|
-
return
|
|
992
|
+
const record4 = await readPointerRecord(legacyPath);
|
|
993
|
+
if (record4?.schemaVersion === 2)
|
|
994
|
+
throw new AccountMigrationError(`the account store moved to ${record4.relocatedTo.legacyPath}; this operation does not follow a moved store`);
|
|
995
|
+
return record4;
|
|
996
996
|
}
|
|
997
997
|
async function forwardTarget(legacyPath, forward) {
|
|
998
998
|
const target = forward.relocatedTo.legacyPath;
|
|
@@ -1258,11 +1258,11 @@ function generationJson(journal) {
|
|
|
1258
1258
|
};
|
|
1259
1259
|
}
|
|
1260
1260
|
function exact(value, keys, path5) {
|
|
1261
|
-
const
|
|
1262
|
-
if (Object.keys(
|
|
1261
|
+
const record4 = object(value, path5);
|
|
1262
|
+
if (Object.keys(record4).some((key) => !keys.includes(key))) {
|
|
1263
1263
|
throw new AccountMigrationError(`${path5} has unknown fields`);
|
|
1264
1264
|
}
|
|
1265
|
-
return
|
|
1265
|
+
return record4;
|
|
1266
1266
|
}
|
|
1267
1267
|
function text(value, pattern, path5) {
|
|
1268
1268
|
if (typeof value !== "string" || !pattern.test(value))
|
|
@@ -2148,14 +2148,14 @@ async function trustedCurrentGeneration(store, paths, journal) {
|
|
|
2148
2148
|
}
|
|
2149
2149
|
async function readAccountStoreBinding(legacyPath, modules, now, expectedGeneration) {
|
|
2150
2150
|
try {
|
|
2151
|
-
const
|
|
2152
|
-
const restored = await restoredRelocationAnchor(legacyPath,
|
|
2151
|
+
const record4 = await readPointerRecord(legacyPath);
|
|
2152
|
+
const restored = await restoredRelocationAnchor(legacyPath, record4);
|
|
2153
2153
|
if (restored !== void 0)
|
|
2154
2154
|
return await bindPublishedGeneration(restored, modules, now, expectedGeneration);
|
|
2155
|
-
if (
|
|
2155
|
+
if (record4?.schemaVersion === 2) {
|
|
2156
2156
|
if (await exists(legacyPath))
|
|
2157
|
-
throw new AccountMigrationError(`a pool file reappeared at ${legacyPath} after the account store moved to ${
|
|
2158
|
-
return await bindPublishedGeneration(await forwardTarget(legacyPath,
|
|
2157
|
+
throw new AccountMigrationError(`a pool file reappeared at ${legacyPath} after the account store moved to ${record4.relocatedTo.legacyPath}`);
|
|
2158
|
+
return await bindPublishedGeneration(await forwardTarget(legacyPath, record4), modules, now, expectedGeneration, legacyPath);
|
|
2159
2159
|
}
|
|
2160
2160
|
return await bindPublishedGeneration(legacyPath, modules, now, expectedGeneration);
|
|
2161
2161
|
} catch (error) {
|
|
@@ -2174,12 +2174,12 @@ async function assertSourceForwarded(journal, forwardedFrom) {
|
|
|
2174
2174
|
throw new AccountMigrationError(`the forwarding pointer ${accountStorePointerPath(forwardedFrom)} leads to a store moved from ${source.legacyPath}`);
|
|
2175
2175
|
if (await exists(source.legacyPath))
|
|
2176
2176
|
throw new AccountMigrationError(`a pool file reappeared at ${source.legacyPath} after the account store moved to ${journal.legacyPath}`);
|
|
2177
|
-
const
|
|
2178
|
-
if (
|
|
2177
|
+
const record4 = await readPointerRecord(source.legacyPath);
|
|
2178
|
+
if (record4 === void 0)
|
|
2179
2179
|
throw new AccountMigrationError(`the forwarding pointer ${pointer} to the moved account store at ${journal.storeDir} is missing; restore it`);
|
|
2180
|
-
if (
|
|
2181
|
-
throw new AccountMigrationError(`the account store in ${dirname2(source.legacyPath)} was reactivated: ${pointer} publishes generation ${
|
|
2182
|
-
if (
|
|
2180
|
+
if (record4.schemaVersion === 1)
|
|
2181
|
+
throw new AccountMigrationError(`the account store in ${dirname2(source.legacyPath)} was reactivated: ${pointer} publishes generation ${record4.id} while the moved store at ${journal.storeDir} is active; restore the forwarding pointer`);
|
|
2182
|
+
if (record4.id !== source.journalId || record4.relocatedTo.legacyPath !== journal.legacyPath || record4.relocatedTo.id !== journal.id)
|
|
2183
2183
|
throw new AccountMigrationError(`the forwarding pointer ${pointer} names another store than the moved account store at ${journal.storeDir}`);
|
|
2184
2184
|
}
|
|
2185
2185
|
async function bindPublishedGeneration(legacyPath, modules, now, expectedGeneration, forwardedFrom) {
|
|
@@ -2214,12 +2214,12 @@ async function bindPublishedGeneration(legacyPath, modules, now, expectedGenerat
|
|
|
2214
2214
|
const settings = await trustedCurrentGeneration(openAdmissionStore(modules, paths, now), paths, journal);
|
|
2215
2215
|
const pending = settings[MANAGEMENT_SETTINGS_KEY];
|
|
2216
2216
|
if (pending !== void 0) {
|
|
2217
|
-
const
|
|
2218
|
-
if (
|
|
2219
|
-
throw new AccountMigrationError(`the account store at ${paths.storeDir} was moved to generation ${String(
|
|
2220
|
-
if (
|
|
2217
|
+
const record4 = object(pending, "repository management");
|
|
2218
|
+
if (record4.kind === "migration" && record4.id !== journal.id)
|
|
2219
|
+
throw new AccountMigrationError(`the account store at ${paths.storeDir} was moved to generation ${String(record4.id)}, but ${accountStorePointerPath(legacyPath)} publishes the old store again; restore the forwarding pointer`);
|
|
2220
|
+
if (record4.kind === "migration")
|
|
2221
2221
|
return { status: "pending", phase: "activate", operation: "migrate" };
|
|
2222
|
-
if (
|
|
2222
|
+
if (record4.kind !== "clear" && record4.kind !== "replace-pool")
|
|
2223
2223
|
throw new AccountMigrationError("unknown management owner prevents binding");
|
|
2224
2224
|
}
|
|
2225
2225
|
return { status: "bound", receipt: receipt(journal), paths };
|
|
@@ -3114,7 +3114,7 @@ async function reverseRelocation(modules, options, sourceParent, targetParent) {
|
|
|
3114
3114
|
const store = openMigrationStore(modules, paths, options.now);
|
|
3115
3115
|
const progressPath = join2(paths.transfersDir, `${journal.id}.reverse.json`);
|
|
3116
3116
|
const progress = async (phase, snapshotSha256) => {
|
|
3117
|
-
const
|
|
3117
|
+
const record4 = {
|
|
3118
3118
|
schemaVersion: 1,
|
|
3119
3119
|
id: journal.id,
|
|
3120
3120
|
sourcePath: paths.legacyPath,
|
|
@@ -3129,7 +3129,7 @@ async function reverseRelocation(modules, options, sourceParent, targetParent) {
|
|
|
3129
3129
|
await lease.assertOwned();
|
|
3130
3130
|
await unlink2(stage);
|
|
3131
3131
|
}
|
|
3132
|
-
await modules.fs.writeJsonAtomic(progressPath,
|
|
3132
|
+
await modules.fs.writeJsonAtomic(progressPath, record4, {
|
|
3133
3133
|
stageName: () => journal.id,
|
|
3134
3134
|
beforeRename: async () => {
|
|
3135
3135
|
await lease.assertOwned();
|
|
@@ -3138,7 +3138,7 @@ async function reverseRelocation(modules, options, sourceParent, targetParent) {
|
|
|
3138
3138
|
});
|
|
3139
3139
|
await syncFile(progressPath, options.onBoundary, "reverse-progress");
|
|
3140
3140
|
await syncDirectory(paths.transfersDir);
|
|
3141
|
-
if (!isDeepStrictEqual(jsonBytes(await secureRead(progressPath)),
|
|
3141
|
+
if (!isDeepStrictEqual(jsonBytes(await secureRead(progressPath)), record4))
|
|
3142
3142
|
throw new AccountMigrationError("reverse progress readback differs");
|
|
3143
3143
|
};
|
|
3144
3144
|
await verifyCopies(paths, journal, true);
|
|
@@ -3322,9 +3322,9 @@ function createAccountRollbackFactory(modules) {
|
|
|
3322
3322
|
throw new AccountMigrationError("stopped processes and timers must be explicitly confirmed");
|
|
3323
3323
|
try {
|
|
3324
3324
|
return await withParentTopology(modules, options.legacyPath, async () => {
|
|
3325
|
-
const
|
|
3326
|
-
if (
|
|
3327
|
-
throw new AccountMigrationError(`the account store moved to ${
|
|
3325
|
+
const record4 = await readPointerRecord(options.legacyPath);
|
|
3326
|
+
if (record4?.schemaVersion === 2)
|
|
3327
|
+
throw new AccountMigrationError(`the account store moved to ${record4.relocatedTo.legacyPath}; move it back with \`antigravity-auth store relocate --back --offline\` before rolling it back`);
|
|
3328
3328
|
const paths = await resolvePublishedAccountStorePaths(options.legacyPath);
|
|
3329
3329
|
if (!paths)
|
|
3330
3330
|
throw new AccountMigrationError("rollback requires a published generation");
|
|
@@ -4269,14 +4269,14 @@ function canonicalJson(value) {
|
|
|
4269
4269
|
function replacementInputDigest(inputs) {
|
|
4270
4270
|
return createHash2("sha256").update(canonicalJson(inputs.map(encodeLoginInput))).digest("hex");
|
|
4271
4271
|
}
|
|
4272
|
-
function publicManagementRecord(
|
|
4272
|
+
function publicManagementRecord(record4) {
|
|
4273
4273
|
return {
|
|
4274
|
-
id:
|
|
4275
|
-
kind:
|
|
4276
|
-
targets: [...
|
|
4274
|
+
id: record4.id,
|
|
4275
|
+
kind: record4.kind,
|
|
4276
|
+
targets: [...record4.targets],
|
|
4277
4277
|
progress: {
|
|
4278
|
-
step:
|
|
4279
|
-
completedTargets: [...
|
|
4278
|
+
step: record4.progress.step,
|
|
4279
|
+
completedTargets: [...record4.progress.completedTargets]
|
|
4280
4280
|
}
|
|
4281
4281
|
};
|
|
4282
4282
|
}
|
|
@@ -4298,31 +4298,31 @@ function decodeManagementRecord(raw) {
|
|
|
4298
4298
|
if (!isRecord(raw)) {
|
|
4299
4299
|
throw new AccountCodecError("$", "must be an object");
|
|
4300
4300
|
}
|
|
4301
|
-
const
|
|
4302
|
-
const progress =
|
|
4303
|
-
if (typeof
|
|
4301
|
+
const record4 = raw;
|
|
4302
|
+
const progress = record4.progress;
|
|
4303
|
+
if (typeof record4.id !== "string" || !MANAGEMENT_ID.test(record4.id)) {
|
|
4304
4304
|
throw new AccountCodecError("$.id", "must be a lowercase UUID");
|
|
4305
4305
|
}
|
|
4306
|
-
if (!isManagementKind(
|
|
4306
|
+
if (!isManagementKind(record4.kind)) {
|
|
4307
4307
|
throw new AccountCodecError("$.kind", "must be a management kind");
|
|
4308
4308
|
}
|
|
4309
|
-
const targets = uniqueIds(
|
|
4309
|
+
const targets = uniqueIds(record4.targets, "$.targets");
|
|
4310
4310
|
if (!isRecord(progress)) {
|
|
4311
4311
|
throw new AccountCodecError("$.progress", "must be an object");
|
|
4312
4312
|
}
|
|
4313
4313
|
const { step } = progress;
|
|
4314
|
-
const steps = MANAGEMENT_STEPS[
|
|
4314
|
+
const steps = MANAGEMENT_STEPS[record4.kind];
|
|
4315
4315
|
if (typeof step !== "string" || !steps.includes(step)) {
|
|
4316
|
-
throw new AccountCodecError("$.progress.step", `must be a step of a ${
|
|
4316
|
+
throw new AccountCodecError("$.progress.step", `must be a step of a ${record4.kind} record`);
|
|
4317
4317
|
}
|
|
4318
4318
|
const completedTargets = uniqueIds(progress.completedTargets, "$.progress.completedTargets");
|
|
4319
4319
|
if (step === "remove" && completedTargets.some((id) => !targets.includes(id))) {
|
|
4320
4320
|
throw new AccountCodecError("$.progress.completedTargets", "must name only targets while rows are being removed");
|
|
4321
4321
|
}
|
|
4322
|
-
const inputDigest =
|
|
4323
|
-
if (
|
|
4322
|
+
const inputDigest = record4.inputDigest;
|
|
4323
|
+
if (record4.publication !== void 0 && record4.kind !== "replace-pool")
|
|
4324
4324
|
throw new AccountCodecError("$.publication", "belongs only to a replace-pool record");
|
|
4325
|
-
if (
|
|
4325
|
+
if (record4.kind === "replace-pool") {
|
|
4326
4326
|
if (typeof inputDigest !== "string" || !SHA256_HEX.test(inputDigest)) {
|
|
4327
4327
|
throw new AccountCodecError("$.inputDigest", "must be the SHA-256 of the replacement inputs");
|
|
4328
4328
|
}
|
|
@@ -4330,12 +4330,12 @@ function decodeManagementRecord(raw) {
|
|
|
4330
4330
|
throw new AccountCodecError("$.inputDigest", "belongs only to a replace-pool record");
|
|
4331
4331
|
}
|
|
4332
4332
|
return {
|
|
4333
|
-
id:
|
|
4334
|
-
kind:
|
|
4333
|
+
id: record4.id,
|
|
4334
|
+
kind: record4.kind,
|
|
4335
4335
|
targets,
|
|
4336
4336
|
progress: { step, completedTargets },
|
|
4337
4337
|
...typeof inputDigest === "string" ? { inputDigest } : {},
|
|
4338
|
-
...
|
|
4338
|
+
...record4.publication !== void 0 ? { publication: decodePublicationPlan(record4.publication, record4.id) } : {}
|
|
4339
4339
|
};
|
|
4340
4340
|
}
|
|
4341
4341
|
function decodePublicationPlan(raw, operationId) {
|
|
@@ -4390,17 +4390,17 @@ function encodePublicationPlan(plan) {
|
|
|
4390
4390
|
order: [...plan.order]
|
|
4391
4391
|
};
|
|
4392
4392
|
}
|
|
4393
|
-
function encodeManagementRecord(
|
|
4393
|
+
function encodeManagementRecord(record4) {
|
|
4394
4394
|
return {
|
|
4395
|
-
id:
|
|
4396
|
-
kind:
|
|
4397
|
-
targets: [...
|
|
4395
|
+
id: record4.id,
|
|
4396
|
+
kind: record4.kind,
|
|
4397
|
+
targets: [...record4.targets],
|
|
4398
4398
|
progress: {
|
|
4399
|
-
step:
|
|
4400
|
-
completedTargets: [...
|
|
4399
|
+
step: record4.progress.step,
|
|
4400
|
+
completedTargets: [...record4.progress.completedTargets]
|
|
4401
4401
|
},
|
|
4402
|
-
...
|
|
4403
|
-
...
|
|
4402
|
+
...record4.inputDigest !== void 0 ? { inputDigest: record4.inputDigest } : {},
|
|
4403
|
+
...record4.publication !== void 0 ? { publication: encodePublicationPlan(record4.publication) } : {}
|
|
4404
4404
|
};
|
|
4405
4405
|
}
|
|
4406
4406
|
function decodeTransferFile(raw, managementId) {
|
|
@@ -5319,22 +5319,22 @@ var init_account_repository = __esm({
|
|
|
5319
5319
|
clear() {
|
|
5320
5320
|
return this.run("clear", void 0, () => this.withTopology("clear", async (lease) => {
|
|
5321
5321
|
await this.boundSettings("clear");
|
|
5322
|
-
let
|
|
5323
|
-
if (
|
|
5324
|
-
throw refusal("clear", "management-pending", `a ${
|
|
5322
|
+
let record4 = await this.readManagement("clear");
|
|
5323
|
+
if (record4 !== void 0 && record4.kind !== "clear") {
|
|
5324
|
+
throw refusal("clear", "management-pending", `a ${record4.kind} of the account pool is pending`, {
|
|
5325
5325
|
retryable: true
|
|
5326
5326
|
});
|
|
5327
5327
|
}
|
|
5328
|
-
if (
|
|
5328
|
+
if (record4 === void 0) {
|
|
5329
5329
|
const rows = await this.readRows("clear");
|
|
5330
|
-
|
|
5330
|
+
record4 = await this.startManagement("clear", {
|
|
5331
5331
|
id: randomUUID3(),
|
|
5332
5332
|
kind: "clear",
|
|
5333
5333
|
targets: rows.map((row) => row.id),
|
|
5334
5334
|
progress: { step: "remove", completedTargets: [] }
|
|
5335
5335
|
}, lease);
|
|
5336
5336
|
}
|
|
5337
|
-
return this.continueManagement("clear",
|
|
5337
|
+
return this.continueManagement("clear", record4, async (current) => this.removeTargets("clear", current, lease), lease);
|
|
5338
5338
|
}));
|
|
5339
5339
|
}
|
|
5340
5340
|
replacePool(inputs) {
|
|
@@ -5347,14 +5347,14 @@ var init_account_repository = __esm({
|
|
|
5347
5347
|
const inputDigest = replacementInputDigest(inputs);
|
|
5348
5348
|
const inputIds = inputs.map((input2) => input2.id);
|
|
5349
5349
|
await this.boundSettings("replacePool");
|
|
5350
|
-
let
|
|
5351
|
-
if (
|
|
5352
|
-
if (
|
|
5353
|
-
throw refusal("replacePool", "management-pending", `a ${
|
|
5350
|
+
let record4 = await this.readManagement("replacePool");
|
|
5351
|
+
if (record4 !== void 0) {
|
|
5352
|
+
if (record4.kind !== "replace-pool") {
|
|
5353
|
+
throw refusal("replacePool", "management-pending", `a ${record4.kind} of the account pool is pending`, {
|
|
5354
5354
|
retryable: true
|
|
5355
5355
|
});
|
|
5356
5356
|
}
|
|
5357
|
-
if (
|
|
5357
|
+
if (record4.inputDigest !== inputDigest) {
|
|
5358
5358
|
throw refusal("replacePool", "management-pending", "another pool replacement is pending", {
|
|
5359
5359
|
retryable: true
|
|
5360
5360
|
});
|
|
@@ -5372,7 +5372,7 @@ var init_account_repository = __esm({
|
|
|
5372
5372
|
const id = randomUUID3();
|
|
5373
5373
|
await lease.assertOwned();
|
|
5374
5374
|
await this.writeTransfer(id, inputs);
|
|
5375
|
-
|
|
5375
|
+
record4 = await this.startManagement("replacePool", {
|
|
5376
5376
|
id,
|
|
5377
5377
|
kind: "replace-pool",
|
|
5378
5378
|
targets: rows.map((row) => row.id),
|
|
@@ -5380,7 +5380,7 @@ var init_account_repository = __esm({
|
|
|
5380
5380
|
inputDigest
|
|
5381
5381
|
}, lease);
|
|
5382
5382
|
}
|
|
5383
|
-
return this.continueManagement("replacePool",
|
|
5383
|
+
return this.continueManagement("replacePool", record4, async (current) => {
|
|
5384
5384
|
let next = current;
|
|
5385
5385
|
if (next.progress.step !== "verified") {
|
|
5386
5386
|
if (next.progress.step === "remove") {
|
|
@@ -5429,9 +5429,9 @@ var init_account_repository = __esm({
|
|
|
5429
5429
|
throw refusal("replacePool", "replacement-unavailable", "Atomic roster publication is unavailable");
|
|
5430
5430
|
await this.boundSettings("replacePool");
|
|
5431
5431
|
const inputDigest = replacementInputDigest(inputs);
|
|
5432
|
-
let
|
|
5433
|
-
if (
|
|
5434
|
-
if (
|
|
5432
|
+
let record4 = await this.readManagement("replacePool");
|
|
5433
|
+
if (record4) {
|
|
5434
|
+
if (record4.kind !== "replace-pool" || record4.inputDigest !== inputDigest || !record4.publication)
|
|
5435
5435
|
throw refusal("replacePool", "management-pending", "another management operation needs recovery");
|
|
5436
5436
|
} else {
|
|
5437
5437
|
const rows = (await this.readRows("replacePool")).filter((row) => row.invalid !== "roster");
|
|
@@ -5453,7 +5453,7 @@ var init_account_repository = __esm({
|
|
|
5453
5453
|
const id = randomUUID3();
|
|
5454
5454
|
await lease.assertOwned();
|
|
5455
5455
|
await this.writeTransfer(id, inputs);
|
|
5456
|
-
|
|
5456
|
+
record4 = await this.startManagement("replacePool", {
|
|
5457
5457
|
id,
|
|
5458
5458
|
kind: "replace-pool",
|
|
5459
5459
|
targets: remove2.map((row) => row.id),
|
|
@@ -5467,7 +5467,7 @@ var init_account_repository = __esm({
|
|
|
5467
5467
|
}
|
|
5468
5468
|
}, lease);
|
|
5469
5469
|
}
|
|
5470
|
-
return this.continueManagement("replacePool",
|
|
5470
|
+
return this.continueManagement("replacePool", record4, async (current) => {
|
|
5471
5471
|
let next = current;
|
|
5472
5472
|
let plan = next.publication;
|
|
5473
5473
|
if (!plan || !isDeepStrictEqual2(plan.order, inputs.map((input2) => input2.id)))
|
|
@@ -5598,7 +5598,7 @@ var init_account_repository = __esm({
|
|
|
5598
5598
|
secrets.add(input2.refreshToken);
|
|
5599
5599
|
}
|
|
5600
5600
|
}
|
|
5601
|
-
async startManagement(operation,
|
|
5601
|
+
async startManagement(operation, record4, lease) {
|
|
5602
5602
|
await lease.assertOwned();
|
|
5603
5603
|
await this.store.updateSettings((settings) => {
|
|
5604
5604
|
if (settings[MANAGEMENT_SETTINGS_KEY] !== void 0) {
|
|
@@ -5608,31 +5608,31 @@ var init_account_repository = __esm({
|
|
|
5608
5608
|
}
|
|
5609
5609
|
return {
|
|
5610
5610
|
...settings,
|
|
5611
|
-
[MANAGEMENT_SETTINGS_KEY]: encodeManagementRecord(
|
|
5611
|
+
[MANAGEMENT_SETTINGS_KEY]: encodeManagementRecord(record4)
|
|
5612
5612
|
};
|
|
5613
5613
|
}, { extraLocks: [managementLock(this.paths)] });
|
|
5614
|
-
return
|
|
5614
|
+
return record4;
|
|
5615
5615
|
}
|
|
5616
|
-
ownsManagement(settings,
|
|
5616
|
+
ownsManagement(settings, record4) {
|
|
5617
5617
|
const raw = settings[MANAGEMENT_SETTINGS_KEY];
|
|
5618
5618
|
if (raw === void 0)
|
|
5619
5619
|
return false;
|
|
5620
5620
|
try {
|
|
5621
5621
|
const current = decodeManagementRecord(raw);
|
|
5622
|
-
return current.id ===
|
|
5622
|
+
return current.id === record4.id && current.kind === record4.kind && current.inputDigest === record4.inputDigest;
|
|
5623
5623
|
} catch {
|
|
5624
5624
|
return false;
|
|
5625
5625
|
}
|
|
5626
5626
|
}
|
|
5627
|
-
async saveProgress(operation,
|
|
5627
|
+
async saveProgress(operation, record4, step, completedTargets, lease, publication2) {
|
|
5628
5628
|
const next = {
|
|
5629
|
-
...
|
|
5629
|
+
...record4,
|
|
5630
5630
|
...publication2 !== void 0 ? { publication: publication2 } : {},
|
|
5631
5631
|
progress: { step, completedTargets }
|
|
5632
5632
|
};
|
|
5633
5633
|
await lease.assertOwned();
|
|
5634
5634
|
await this.store.updateSettings((settings) => {
|
|
5635
|
-
if (!this.ownsManagement(settings,
|
|
5635
|
+
if (!this.ownsManagement(settings, record4)) {
|
|
5636
5636
|
throw new CallbackRefusal(refusal(operation, "management-pending", "the management record changed under this operation"));
|
|
5637
5637
|
}
|
|
5638
5638
|
return {
|
|
@@ -5642,16 +5642,16 @@ var init_account_repository = __esm({
|
|
|
5642
5642
|
}, { extraLocks: [managementLock(this.paths)] });
|
|
5643
5643
|
return next;
|
|
5644
5644
|
}
|
|
5645
|
-
async removeTargets(operation,
|
|
5646
|
-
let next =
|
|
5647
|
-
for (const target of
|
|
5645
|
+
async removeTargets(operation, record4, lease) {
|
|
5646
|
+
let next = record4;
|
|
5647
|
+
for (const target of record4.targets) {
|
|
5648
5648
|
if (next.progress.completedTargets.includes(target))
|
|
5649
5649
|
continue;
|
|
5650
5650
|
await lease.assertOwned();
|
|
5651
5651
|
try {
|
|
5652
5652
|
await this.store.remove(target, {
|
|
5653
5653
|
extraLocks: [managementLock(this.paths)],
|
|
5654
|
-
protect: (_id, view) => this.ownsManagement(view.config,
|
|
5654
|
+
protect: (_id, view) => this.ownsManagement(view.config, record4) ? void 0 : "the management record changed under this removal"
|
|
5655
5655
|
});
|
|
5656
5656
|
} catch (error) {
|
|
5657
5657
|
const failure2 = this.failureOf(operation, target, error);
|
|
@@ -5667,13 +5667,13 @@ var init_account_repository = __esm({
|
|
|
5667
5667
|
* A retryable failure (lock contention, a lost lease) leaves the record
|
|
5668
5668
|
* pending and reports it instead of looping; the next call resumes.
|
|
5669
5669
|
*/
|
|
5670
|
-
async continueManagement(operation,
|
|
5670
|
+
async continueManagement(operation, record4, steps, lease) {
|
|
5671
5671
|
let finished;
|
|
5672
5672
|
try {
|
|
5673
|
-
finished = await steps(
|
|
5673
|
+
finished = await steps(record4);
|
|
5674
5674
|
await lease.assertOwned();
|
|
5675
5675
|
await this.store.updateSettings((settings) => {
|
|
5676
|
-
if (!this.ownsManagement(settings,
|
|
5676
|
+
if (!this.ownsManagement(settings, record4)) {
|
|
5677
5677
|
throw new CallbackRefusal(refusal(operation, "management-pending", "the management journal no longer holds this operation; it was not cleared"));
|
|
5678
5678
|
}
|
|
5679
5679
|
const { [MANAGEMENT_SETTINGS_KEY]: _done, ...rest } = settings;
|
|
@@ -5682,7 +5682,7 @@ var init_account_repository = __esm({
|
|
|
5682
5682
|
} catch (error) {
|
|
5683
5683
|
const failure2 = this.failureOf(operation, void 0, error);
|
|
5684
5684
|
if (failure2.failure.retryable) {
|
|
5685
|
-
const now = await this.readManagement(operation) ??
|
|
5685
|
+
const now = await this.readManagement(operation) ?? record4;
|
|
5686
5686
|
return { management: publicManagementRecord(now), outcome: "pending" };
|
|
5687
5687
|
}
|
|
5688
5688
|
throw failure2;
|
|
@@ -5933,6 +5933,8 @@ function getGemini38FlashAntigravityModel(tier) {
|
|
|
5933
5933
|
}
|
|
5934
5934
|
function getQuotaGroupForModel(modelId, hasArgonPool = false) {
|
|
5935
5935
|
const normalized = modelId.toLowerCase();
|
|
5936
|
+
if (isGeminiCarbonModel(normalized))
|
|
5937
|
+
return "gemini";
|
|
5936
5938
|
if (isGeminiArgonModel(normalized))
|
|
5937
5939
|
return hasArgonPool ? "gemini-argon" : void 0;
|
|
5938
5940
|
return QUOTA_GROUP_BY_MODEL_ID[normalized] ?? // Check Claude / GPT-OSS substrings BEFORE the `gemini` substring so
|
|
@@ -5945,6 +5947,19 @@ function getQuotaGroupForModel(modelId, hasArgonPool = false) {
|
|
|
5945
5947
|
function isGeminiArgonModel(model) {
|
|
5946
5948
|
return /^(?:antigravity-)?gemini-4-argon(?:-(?:low|medium|high))?$/.test(model.toLowerCase());
|
|
5947
5949
|
}
|
|
5950
|
+
function isGeminiCarbonModel(model) {
|
|
5951
|
+
return /^(?:antigravity-)?gemini-4-carbon(?:-(?:low|medium|high))?$/.test(model.toLowerCase());
|
|
5952
|
+
}
|
|
5953
|
+
function getGeminiCarbonAntigravityModel(tier) {
|
|
5954
|
+
return getTieredAntigravityModel({
|
|
5955
|
+
defaultModel: "gemini-4-carbon-medium",
|
|
5956
|
+
byTier: {
|
|
5957
|
+
low: "gemini-4-carbon-low",
|
|
5958
|
+
medium: "gemini-4-carbon-medium",
|
|
5959
|
+
high: "gemini-4-carbon-high"
|
|
5960
|
+
}
|
|
5961
|
+
}, tier);
|
|
5962
|
+
}
|
|
5948
5963
|
function getGeminiArgonAntigravityModel(tier) {
|
|
5949
5964
|
return getTieredAntigravityModel({
|
|
5950
5965
|
defaultModel: "gemini-4-argon-medium",
|
|
@@ -5967,6 +5982,33 @@ var init_model_registry = __esm({
|
|
|
5967
5982
|
DEFAULT_COST = { input: 0, output: 0 };
|
|
5968
5983
|
DEFAULT_OPTIONS = {};
|
|
5969
5984
|
AGY_NATIVE_MODEL_DEFINITIONS = {
|
|
5985
|
+
"gemini-4-carbon-low": {
|
|
5986
|
+
displayName: "Gemini 4 Carbon (Low)",
|
|
5987
|
+
maxTokens: 1048576,
|
|
5988
|
+
maxOutputTokens: 262144,
|
|
5989
|
+
model: "MODEL_PLACEHOLDER_M438",
|
|
5990
|
+
thinkingLevel: 1,
|
|
5991
|
+
thinkingBudget: -1,
|
|
5992
|
+
supportsThinking: true
|
|
5993
|
+
},
|
|
5994
|
+
"gemini-4-carbon-medium": {
|
|
5995
|
+
displayName: "Gemini 4 Carbon (Medium)",
|
|
5996
|
+
maxTokens: 1048576,
|
|
5997
|
+
maxOutputTokens: 262144,
|
|
5998
|
+
model: "MODEL_PLACEHOLDER_M437",
|
|
5999
|
+
thinkingLevel: 2,
|
|
6000
|
+
thinkingBudget: -1,
|
|
6001
|
+
supportsThinking: true
|
|
6002
|
+
},
|
|
6003
|
+
"gemini-4-carbon-high": {
|
|
6004
|
+
displayName: "Gemini 4 Carbon (High)",
|
|
6005
|
+
maxTokens: 1048576,
|
|
6006
|
+
maxOutputTokens: 262144,
|
|
6007
|
+
model: "MODEL_PLACEHOLDER_M427",
|
|
6008
|
+
thinkingLevel: 3,
|
|
6009
|
+
thinkingBudget: -1,
|
|
6010
|
+
supportsThinking: true
|
|
6011
|
+
},
|
|
5970
6012
|
"gemini-4-argon-low": {
|
|
5971
6013
|
displayName: "Gemini 4 Argon (Low)",
|
|
5972
6014
|
maxTokens: 1048576,
|
|
@@ -6105,6 +6147,17 @@ var init_model_registry = __esm({
|
|
|
6105
6147
|
high: { thinkingLevel: "high" }
|
|
6106
6148
|
}
|
|
6107
6149
|
}),
|
|
6150
|
+
"antigravity-gemini-4-carbon": defineModel("antigravity-gemini-4-carbon", {
|
|
6151
|
+
name: "Gemini 4 Carbon (Antigravity)",
|
|
6152
|
+
reasoning: true,
|
|
6153
|
+
limit: { context: 1048576, output: 262144 },
|
|
6154
|
+
modalities: DEFAULT_MODALITIES,
|
|
6155
|
+
variants: {
|
|
6156
|
+
low: { thinkingLevel: "low" },
|
|
6157
|
+
medium: { thinkingLevel: "medium" },
|
|
6158
|
+
high: { thinkingLevel: "high" }
|
|
6159
|
+
}
|
|
6160
|
+
}),
|
|
6108
6161
|
"antigravity-gemini-3.1-flash-image": defineModel("antigravity-gemini-3.1-flash-image", {
|
|
6109
6162
|
name: "Gemini 3.1 Flash Image (Antigravity)",
|
|
6110
6163
|
reasoning: false,
|
|
@@ -6152,6 +6205,9 @@ var init_model_registry = __esm({
|
|
|
6152
6205
|
})
|
|
6153
6206
|
};
|
|
6154
6207
|
RESOLVER_ALIASES = {
|
|
6208
|
+
"gemini-4-carbon-low": "gemini-4-carbon",
|
|
6209
|
+
"gemini-4-carbon-medium": "gemini-4-carbon",
|
|
6210
|
+
"gemini-4-carbon-high": "gemini-4-carbon",
|
|
6155
6211
|
"gemini-4-argon-low": "gemini-4-argon",
|
|
6156
6212
|
"gemini-4-argon-medium": "gemini-4-argon",
|
|
6157
6213
|
"gemini-4-argon-high": "gemini-4-argon",
|
|
@@ -6247,6 +6303,7 @@ var init_model_registry = __esm({
|
|
|
6247
6303
|
};
|
|
6248
6304
|
ANTIGRAVITY_OPENCODE_MODEL_IDS = [
|
|
6249
6305
|
"antigravity-gemini-4-argon",
|
|
6306
|
+
"antigravity-gemini-4-carbon",
|
|
6250
6307
|
"antigravity-gemini-3.8-flash",
|
|
6251
6308
|
"antigravity-gemini-3.1-flash-image",
|
|
6252
6309
|
"antigravity-claude-sonnet-5-5",
|
|
@@ -7635,9 +7692,9 @@ var init_account_selector = __esm({
|
|
|
7635
7692
|
const today = new Date(this.now()).toISOString().slice(0, 10);
|
|
7636
7693
|
const result = [];
|
|
7637
7694
|
for (const account of this.accounts) {
|
|
7638
|
-
const
|
|
7639
|
-
if (
|
|
7640
|
-
result.push({ index: account.index, email: account.email, count:
|
|
7695
|
+
const count4 = account.dailyRequestCounts?.date === today ? account.dailyRequestCounts[family] : 0;
|
|
7696
|
+
if (count4 > 0) {
|
|
7697
|
+
result.push({ index: account.index, email: account.email, count: count4 });
|
|
7641
7698
|
}
|
|
7642
7699
|
}
|
|
7643
7700
|
return result.sort((a, b) => b.count - a.count);
|
|
@@ -7883,7 +7940,7 @@ async function rmEvictingDir(evictingPath) {
|
|
|
7883
7940
|
});
|
|
7884
7941
|
}
|
|
7885
7942
|
async function sleep(ms) {
|
|
7886
|
-
await new Promise((
|
|
7943
|
+
await new Promise((resolve29) => setTimeout(resolve29, ms));
|
|
7887
7944
|
}
|
|
7888
7945
|
async function acquireFencedFileLock(options) {
|
|
7889
7946
|
const lockPath = `${options.path}.${options.name}.lock`;
|
|
@@ -7999,8 +8056,8 @@ function buildLock(lockPath, evictingPath, ownerId, options, now) {
|
|
|
7999
8056
|
let released = false;
|
|
8000
8057
|
let lost = false;
|
|
8001
8058
|
let lostResolve = null;
|
|
8002
|
-
let lostPromise = new Promise((
|
|
8003
|
-
lostResolve =
|
|
8059
|
+
let lostPromise = new Promise((resolve29) => {
|
|
8060
|
+
lostResolve = resolve29;
|
|
8004
8061
|
});
|
|
8005
8062
|
const markLost = () => {
|
|
8006
8063
|
if (lost)
|
|
@@ -8010,9 +8067,9 @@ function buildLock(lockPath, evictingPath, ownerId, options, now) {
|
|
|
8010
8067
|
clearInterval(renewTimer);
|
|
8011
8068
|
renewTimer = null;
|
|
8012
8069
|
}
|
|
8013
|
-
const
|
|
8070
|
+
const resolve29 = lostResolve;
|
|
8014
8071
|
lostResolve = null;
|
|
8015
|
-
|
|
8072
|
+
resolve29?.();
|
|
8016
8073
|
};
|
|
8017
8074
|
const setupRenew = () => {
|
|
8018
8075
|
if (options.renew === false)
|
|
@@ -8514,11 +8571,11 @@ async function readAndNormalizeV4(path5) {
|
|
|
8514
8571
|
}
|
|
8515
8572
|
};
|
|
8516
8573
|
}
|
|
8517
|
-
function validateV4AccountRecord(
|
|
8518
|
-
if (
|
|
8574
|
+
function validateV4AccountRecord(record4, index) {
|
|
8575
|
+
if (record4 === null || typeof record4 !== "object" || Array.isArray(record4)) {
|
|
8519
8576
|
return `accounts[${index}] is not an object`;
|
|
8520
8577
|
}
|
|
8521
|
-
const acc =
|
|
8578
|
+
const acc = record4;
|
|
8522
8579
|
if (typeof acc.refreshToken !== "string" || acc.refreshToken.length === 0) {
|
|
8523
8580
|
return `accounts[${index}].refreshToken is missing or not a non-empty string`;
|
|
8524
8581
|
}
|
|
@@ -8635,7 +8692,7 @@ async function saveAccountStorageReplace(path5, incoming) {
|
|
|
8635
8692
|
return mutateAccountStorage(path5, () => incoming);
|
|
8636
8693
|
}
|
|
8637
8694
|
async function clearAccountStorage(path5) {
|
|
8638
|
-
const sleep5 = (ms) => new Promise((
|
|
8695
|
+
const sleep5 = (ms) => new Promise((resolve29) => setTimeout(resolve29, ms));
|
|
8639
8696
|
const lock = await acquireWithRetry(path5, sleep5);
|
|
8640
8697
|
try {
|
|
8641
8698
|
await assertLegacyAccountStorageWritable(path5);
|
|
@@ -8683,7 +8740,7 @@ var init_account_storage = __esm({
|
|
|
8683
8740
|
}
|
|
8684
8741
|
};
|
|
8685
8742
|
RETRY_DELAYS_MS = [100, 200, 400, 800, 1e3];
|
|
8686
|
-
DEFAULT_SLEEP = (ms) => new Promise((
|
|
8743
|
+
DEFAULT_SLEEP = (ms) => new Promise((resolve29) => setTimeout(resolve29, ms));
|
|
8687
8744
|
DEFAULT_BUILD_BACKUP_PATH = (path5, now) => `${path5}.corrupt-${now.toISOString().replace(/[:.]/g, "-")}`;
|
|
8688
8745
|
}
|
|
8689
8746
|
});
|
|
@@ -9223,15 +9280,15 @@ var init_account_manager = __esm({
|
|
|
9223
9280
|
}
|
|
9224
9281
|
/** The stored selection's index for `family` among `accounts`. */
|
|
9225
9282
|
routedIndex(accounts, routing, family) {
|
|
9226
|
-
const
|
|
9283
|
+
const count4 = accounts.length;
|
|
9227
9284
|
const indexOf = (ref) => {
|
|
9228
9285
|
if (ref == null)
|
|
9229
9286
|
return void 0;
|
|
9230
9287
|
const found = accounts.findIndex((account) => account.ref !== void 0 && sameRowRef(account.ref, ref));
|
|
9231
9288
|
return found < 0 ? void 0 : found;
|
|
9232
9289
|
};
|
|
9233
|
-
const defaultIndex = indexOf(routing?.activeRow) ?? clampNonNegativeInt(routing?.activeIndex, 0) %
|
|
9234
|
-
return indexOf(routing?.activeRowByFamily?.[family]) ?? clampNonNegativeInt(routing?.activeIndexByFamily?.[family], defaultIndex) %
|
|
9290
|
+
const defaultIndex = indexOf(routing?.activeRow) ?? clampNonNegativeInt(routing?.activeIndex, 0) % count4;
|
|
9291
|
+
return indexOf(routing?.activeRowByFamily?.[family]) ?? clampNonNegativeInt(routing?.activeIndexByFamily?.[family], defaultIndex) % count4;
|
|
9235
9292
|
}
|
|
9236
9293
|
loadRepositoryRows(read) {
|
|
9237
9294
|
const baseNow = this.now();
|
|
@@ -9901,8 +9958,8 @@ var init_account_manager = __esm({
|
|
|
9901
9958
|
await this.saveInFlight;
|
|
9902
9959
|
return;
|
|
9903
9960
|
}
|
|
9904
|
-
return new Promise((
|
|
9905
|
-
this.savePromiseResolvers.push({ resolve:
|
|
9961
|
+
return new Promise((resolve29, reject) => {
|
|
9962
|
+
this.savePromiseResolvers.push({ resolve: resolve29, reject });
|
|
9906
9963
|
});
|
|
9907
9964
|
}
|
|
9908
9965
|
async dispose() {
|
|
@@ -9945,8 +10002,8 @@ var init_account_manager = __esm({
|
|
|
9945
10002
|
reject(error);
|
|
9946
10003
|
throw error;
|
|
9947
10004
|
}
|
|
9948
|
-
for (const { resolve:
|
|
9949
|
-
|
|
10005
|
+
for (const { resolve: resolve29 } of resolvers)
|
|
10006
|
+
resolve29();
|
|
9950
10007
|
}
|
|
9951
10008
|
async executeSave() {
|
|
9952
10009
|
this.savePending = false;
|
|
@@ -9960,16 +10017,16 @@ var init_account_manager = __esm({
|
|
|
9960
10017
|
}
|
|
9961
10018
|
try {
|
|
9962
10019
|
await this.saveToDisk();
|
|
9963
|
-
for (const { resolve:
|
|
9964
|
-
|
|
10020
|
+
for (const { resolve: resolve29 } of resolvers) {
|
|
10021
|
+
resolve29();
|
|
9965
10022
|
}
|
|
9966
10023
|
} catch (error) {
|
|
9967
10024
|
if (isStorageLockContention(error)) {
|
|
9968
10025
|
this.onDiagnostic?.("Skipped account-state persist due to storage lock contention", {
|
|
9969
10026
|
error: String(error)
|
|
9970
10027
|
});
|
|
9971
|
-
for (const { resolve:
|
|
9972
|
-
|
|
10028
|
+
for (const { resolve: resolve29 } of resolvers) {
|
|
10029
|
+
resolve29();
|
|
9973
10030
|
}
|
|
9974
10031
|
return;
|
|
9975
10032
|
}
|
|
@@ -10470,7 +10527,7 @@ function getHttpsProxy(url) {
|
|
|
10470
10527
|
}
|
|
10471
10528
|
}
|
|
10472
10529
|
function waitForHead(socket, timeoutMs, onTimeout) {
|
|
10473
|
-
return new Promise((
|
|
10530
|
+
return new Promise((resolve29, reject) => {
|
|
10474
10531
|
let buffer = Buffer3.alloc(0);
|
|
10475
10532
|
const timeout = setTimeout(() => {
|
|
10476
10533
|
onTimeout();
|
|
@@ -10493,7 +10550,7 @@ function waitForHead(socket, timeoutMs, onTimeout) {
|
|
|
10493
10550
|
return;
|
|
10494
10551
|
const head = buffer.subarray(0, marker).toString("latin1");
|
|
10495
10552
|
const leftover = buffer.subarray(marker + 4);
|
|
10496
|
-
cleanup2(() =>
|
|
10553
|
+
cleanup2(() => resolve29({ head, leftover }));
|
|
10497
10554
|
};
|
|
10498
10555
|
socket.on("data", onData);
|
|
10499
10556
|
socket.once("error", onError);
|
|
@@ -10507,7 +10564,7 @@ async function connectViaProxy(proxyUrl, targetUrl, timeoutMs, signal, onDebug)
|
|
|
10507
10564
|
port: Number(proxyUrl.port || DEFAULT_PROXY_PORT),
|
|
10508
10565
|
signal: signal ?? void 0
|
|
10509
10566
|
});
|
|
10510
|
-
await new Promise((
|
|
10567
|
+
await new Promise((resolve29, reject) => {
|
|
10511
10568
|
const timeout = setTimeout(() => {
|
|
10512
10569
|
onDebug?.(`agy transport proxy connect timeout after ${timeoutMs}ms`);
|
|
10513
10570
|
proxySocket.destroy();
|
|
@@ -10516,7 +10573,7 @@ async function connectViaProxy(proxyUrl, targetUrl, timeoutMs, signal, onDebug)
|
|
|
10516
10573
|
const cleanup2 = () => clearTimeout(timeout);
|
|
10517
10574
|
proxySocket.once("connect", () => {
|
|
10518
10575
|
cleanup2();
|
|
10519
|
-
|
|
10576
|
+
resolve29();
|
|
10520
10577
|
});
|
|
10521
10578
|
proxySocket.once("error", (error) => {
|
|
10522
10579
|
cleanup2();
|
|
@@ -10541,7 +10598,7 @@ Host: ${targetHost}:${targetPort}\r
|
|
|
10541
10598
|
if (leftover.length > 0) {
|
|
10542
10599
|
proxySocket.unshift(leftover);
|
|
10543
10600
|
}
|
|
10544
|
-
return await new Promise((
|
|
10601
|
+
return await new Promise((resolve29, reject) => {
|
|
10545
10602
|
const tlsOptions = {
|
|
10546
10603
|
socket: proxySocket,
|
|
10547
10604
|
servername: targetHost,
|
|
@@ -10556,7 +10613,7 @@ Host: ${targetHost}:${targetPort}\r
|
|
|
10556
10613
|
const cleanup2 = () => clearTimeout(timeout);
|
|
10557
10614
|
tlsSocket.once("secureConnect", () => {
|
|
10558
10615
|
cleanup2();
|
|
10559
|
-
|
|
10616
|
+
resolve29(tlsSocket);
|
|
10560
10617
|
});
|
|
10561
10618
|
tlsSocket.once("error", (error) => {
|
|
10562
10619
|
cleanup2();
|
|
@@ -10565,7 +10622,7 @@ Host: ${targetHost}:${targetPort}\r
|
|
|
10565
10622
|
});
|
|
10566
10623
|
}
|
|
10567
10624
|
async function connectDirect(targetUrl, timeoutMs, signal, onDebug) {
|
|
10568
|
-
return await new Promise((
|
|
10625
|
+
return await new Promise((resolve29, reject) => {
|
|
10569
10626
|
const tlsOptions = {
|
|
10570
10627
|
host: targetUrl.hostname,
|
|
10571
10628
|
port: Number(targetUrl.port || DEFAULT_HTTPS_PORT),
|
|
@@ -10581,7 +10638,7 @@ async function connectDirect(targetUrl, timeoutMs, signal, onDebug) {
|
|
|
10581
10638
|
const cleanup2 = () => clearTimeout(timeout);
|
|
10582
10639
|
socket.once("secureConnect", () => {
|
|
10583
10640
|
cleanup2();
|
|
10584
|
-
|
|
10641
|
+
resolve29(socket);
|
|
10585
10642
|
});
|
|
10586
10643
|
socket.once("error", (error) => {
|
|
10587
10644
|
cleanup2();
|
|
@@ -11277,8 +11334,8 @@ function isFiniteNumber(value) {
|
|
|
11277
11334
|
function isName(value) {
|
|
11278
11335
|
return typeof value === "string" && value.length > 0;
|
|
11279
11336
|
}
|
|
11280
|
-
function optional2(
|
|
11281
|
-
return
|
|
11337
|
+
function optional2(record4, key, check) {
|
|
11338
|
+
return record4[key] === void 0 || check(record4[key]);
|
|
11282
11339
|
}
|
|
11283
11340
|
function isPositiveFinite(value) {
|
|
11284
11341
|
return isFiniteNumber(value) && value > 0;
|
|
@@ -11380,11 +11437,11 @@ function isScope(value) {
|
|
|
11380
11437
|
function isLabel(value) {
|
|
11381
11438
|
return typeof value === "string" && value !== "";
|
|
11382
11439
|
}
|
|
11383
|
-
function optionalFinite(
|
|
11384
|
-
return
|
|
11440
|
+
function optionalFinite(record4, key) {
|
|
11441
|
+
return record4[key] === void 0 || isFiniteNumber2(record4[key]);
|
|
11385
11442
|
}
|
|
11386
|
-
function optionalString(
|
|
11387
|
-
return
|
|
11443
|
+
function optionalString(record4, key) {
|
|
11444
|
+
return record4[key] === void 0 || typeof record4[key] === "string";
|
|
11388
11445
|
}
|
|
11389
11446
|
function isObservedReading(value) {
|
|
11390
11447
|
return isRecord3(value) && isScope(value.scope) && isLabel(value.label) && isFiniteNumber2(value.usedPercent) && optionalString(value, "resetsAt") && (value.windowMinutes === void 0 || isFiniteNumber2(value.windowMinutes) && value.windowMinutes > 0);
|
|
@@ -12658,6 +12715,45 @@ var init_atomic_write2 = __esm({
|
|
|
12658
12715
|
}
|
|
12659
12716
|
});
|
|
12660
12717
|
|
|
12718
|
+
// ../core/dist/common-auth-embedded/fs/lock-record.js
|
|
12719
|
+
import { resolve as resolve3 } from "node:path";
|
|
12720
|
+
function isWindowsAccessDeniedRead(error, paths) {
|
|
12721
|
+
return error instanceof PrivateFileError && error.reason === "io-error" && error.win32Code === 5 && (error.stage === "read" || error.stage === "verify") && paths.some((path5) => resolve3(path5) === error.path);
|
|
12722
|
+
}
|
|
12723
|
+
function isWindowsAccessDeniedCreate(error, paths, stage) {
|
|
12724
|
+
return error instanceof PrivateFileError && error.reason === "io-error" && error.win32Code === 5 && error.stage === stage && paths.some((path5) => resolve3(path5) === error.path);
|
|
12725
|
+
}
|
|
12726
|
+
async function readLockRecord(path5, read) {
|
|
12727
|
+
try {
|
|
12728
|
+
return await read();
|
|
12729
|
+
} catch (error) {
|
|
12730
|
+
if (!isWindowsAccessDeniedRead(error, [path5]))
|
|
12731
|
+
throw error;
|
|
12732
|
+
try {
|
|
12733
|
+
return await read();
|
|
12734
|
+
} catch (recheckError) {
|
|
12735
|
+
if (recheckError.code === "ENOENT")
|
|
12736
|
+
throw new DisappearedLockRecordError(path5, error);
|
|
12737
|
+
throw error;
|
|
12738
|
+
}
|
|
12739
|
+
}
|
|
12740
|
+
}
|
|
12741
|
+
var DisappearedLockRecordError;
|
|
12742
|
+
var init_lock_record = __esm({
|
|
12743
|
+
"../core/dist/common-auth-embedded/fs/lock-record.js"() {
|
|
12744
|
+
"use strict";
|
|
12745
|
+
init_private_files();
|
|
12746
|
+
DisappearedLockRecordError = class extends Error {
|
|
12747
|
+
path;
|
|
12748
|
+
code = "ENOENT";
|
|
12749
|
+
constructor(path5, cause) {
|
|
12750
|
+
super(`Lock record disappeared: ${path5}`, { cause });
|
|
12751
|
+
this.path = path5;
|
|
12752
|
+
}
|
|
12753
|
+
};
|
|
12754
|
+
}
|
|
12755
|
+
});
|
|
12756
|
+
|
|
12661
12757
|
// ../core/dist/common-auth-embedded/fs/refresh-file-lock.js
|
|
12662
12758
|
import { randomUUID as randomUUID9 } from "node:crypto";
|
|
12663
12759
|
import { link as link2, lstat as lstat3, mkdir as mkdir7, open as open4, readFile as readFile5, rename as rename6, rm as rm4, stat as stat3 } from "node:fs/promises";
|
|
@@ -12740,8 +12836,8 @@ async function acquireRefreshFileLockWithClock(options) {
|
|
|
12740
12836
|
let releaseConfirmed = false;
|
|
12741
12837
|
let loss;
|
|
12742
12838
|
let resolveLoss;
|
|
12743
|
-
const lostPromise = new Promise((
|
|
12744
|
-
resolveLoss =
|
|
12839
|
+
const lostPromise = new Promise((resolve29) => {
|
|
12840
|
+
resolveLoss = resolve29;
|
|
12745
12841
|
});
|
|
12746
12842
|
function notifyTimerStep(event) {
|
|
12747
12843
|
try {
|
|
@@ -12779,15 +12875,18 @@ async function acquireRefreshFileLockWithClock(options) {
|
|
|
12779
12875
|
const evictOwnerId = randomUUID9();
|
|
12780
12876
|
const EVICT_TTL = 5e3;
|
|
12781
12877
|
const MAX_STEAL_ATTEMPTS = 8;
|
|
12878
|
+
function isChangingLockCreate(error) {
|
|
12879
|
+
return windowsPrivateFiles && (isWindowsAccessDeniedCreate(error, [lockPath], "create") || isWindowsAccessDeniedCreate(error, [evictPath], "directory-create"));
|
|
12880
|
+
}
|
|
12782
12881
|
async function readOwner() {
|
|
12783
12882
|
if (windowsPrivateFiles) {
|
|
12784
12883
|
try {
|
|
12785
|
-
return JSON.parse(await readPrivateText(lockPath, true));
|
|
12884
|
+
return JSON.parse(await readLockRecord(lockPath, () => readPrivateText(lockPath, true)));
|
|
12786
12885
|
} catch (error) {
|
|
12787
12886
|
if (error.code !== "EISDIR" && error.reason !== "wrong-kind")
|
|
12788
12887
|
throw error;
|
|
12789
|
-
await verifyPrivate(lockPath, "directory", true);
|
|
12790
|
-
return JSON.parse(await readPrivateText(legacyOwnerPath, true));
|
|
12888
|
+
await readLockRecord(lockPath, () => verifyPrivate(lockPath, "directory", true));
|
|
12889
|
+
return JSON.parse(await readLockRecord(legacyOwnerPath, () => readPrivateText(legacyOwnerPath, true)));
|
|
12791
12890
|
}
|
|
12792
12891
|
}
|
|
12793
12892
|
try {
|
|
@@ -12863,8 +12962,8 @@ async function acquireRefreshFileLockWithClock(options) {
|
|
|
12863
12962
|
await options.onStep("lease-contention-read-ready");
|
|
12864
12963
|
try {
|
|
12865
12964
|
if (code2 === "EISDIR") {
|
|
12866
|
-
await verifyPrivate(lockPath, "directory", true);
|
|
12867
|
-
await readPrivateText(legacyOwnerPath, true);
|
|
12965
|
+
await readLockRecord(lockPath, () => verifyPrivate(lockPath, "directory", true));
|
|
12966
|
+
await readLockRecord(legacyOwnerPath, () => readPrivateText(legacyOwnerPath, true));
|
|
12868
12967
|
} else
|
|
12869
12968
|
await readOwner();
|
|
12870
12969
|
} catch (readError) {
|
|
@@ -12902,7 +13001,7 @@ async function acquireRefreshFileLockWithClock(options) {
|
|
|
12902
13001
|
}
|
|
12903
13002
|
}
|
|
12904
13003
|
async function backoff() {
|
|
12905
|
-
await new Promise((
|
|
13004
|
+
await new Promise((resolve29) => setTimeout(resolve29, Math.floor(Math.random() * 4)));
|
|
12906
13005
|
}
|
|
12907
13006
|
async function readLockState(notifyReady = true) {
|
|
12908
13007
|
if (notifyReady && options.onStep)
|
|
@@ -12911,6 +13010,8 @@ async function acquireRefreshFileLockWithClock(options) {
|
|
|
12911
13010
|
try {
|
|
12912
13011
|
owner = await readOwner();
|
|
12913
13012
|
} catch (error) {
|
|
13013
|
+
if (error instanceof DisappearedLockRecordError)
|
|
13014
|
+
return { status: "missing" };
|
|
12914
13015
|
if (windowsPrivateFiles && error.code !== "ENOENT")
|
|
12915
13016
|
throw error;
|
|
12916
13017
|
}
|
|
@@ -12958,7 +13059,7 @@ async function acquireRefreshFileLockWithClock(options) {
|
|
|
12958
13059
|
}
|
|
12959
13060
|
async function ownsEvictionMarker() {
|
|
12960
13061
|
try {
|
|
12961
|
-
const owner = JSON.parse(await readPrivateText(evictOwnerPath, windowsPrivateFiles));
|
|
13062
|
+
const owner = JSON.parse(await readLockRecord(evictOwnerPath, () => readPrivateText(evictOwnerPath, windowsPrivateFiles)));
|
|
12962
13063
|
return owner?.ownerId === evictOwnerId;
|
|
12963
13064
|
} catch (error) {
|
|
12964
13065
|
if (windowsPrivateFiles && error.code !== "ENOENT")
|
|
@@ -12993,7 +13094,7 @@ async function acquireRefreshFileLockWithClock(options) {
|
|
|
12993
13094
|
const remainingMs = deadline - performance.now();
|
|
12994
13095
|
if (remainingMs <= 0)
|
|
12995
13096
|
throw original;
|
|
12996
|
-
await new Promise((
|
|
13097
|
+
await new Promise((resolve29) => setTimeout(resolve29, Math.min(delayMs, remainingMs)));
|
|
12997
13098
|
if (performance.now() >= deadline)
|
|
12998
13099
|
throw original;
|
|
12999
13100
|
delayMs = Math.min(delayMs * 2, 50);
|
|
@@ -13097,7 +13198,7 @@ async function acquireRefreshFileLockWithClock(options) {
|
|
|
13097
13198
|
}
|
|
13098
13199
|
if (windowsPrivateFiles) {
|
|
13099
13200
|
try {
|
|
13100
|
-
await verifyPrivate(evictPath, "directory", true);
|
|
13201
|
+
await readLockRecord(evictPath, () => verifyPrivate(evictPath, "directory", true));
|
|
13101
13202
|
} catch (error) {
|
|
13102
13203
|
if (error.code === "ENOENT")
|
|
13103
13204
|
return "missing";
|
|
@@ -13152,8 +13253,8 @@ async function acquireRefreshFileLockWithClock(options) {
|
|
|
13152
13253
|
if (error.code === "EEXIST") {
|
|
13153
13254
|
if (windowsPrivateFiles) {
|
|
13154
13255
|
try {
|
|
13155
|
-
await verifyPrivate(evictPath, "directory", true);
|
|
13156
|
-
await readPrivateText(evictOwnerPath, true);
|
|
13256
|
+
await readLockRecord(evictPath, () => verifyPrivate(evictPath, "directory", true));
|
|
13257
|
+
await readLockRecord(evictOwnerPath, () => readPrivateText(evictOwnerPath, true));
|
|
13157
13258
|
} catch (ownerError) {
|
|
13158
13259
|
if (ownerError.code !== "ENOENT")
|
|
13159
13260
|
throw ownerError;
|
|
@@ -13174,7 +13275,11 @@ async function acquireRefreshFileLockWithClock(options) {
|
|
|
13174
13275
|
try {
|
|
13175
13276
|
await releaseEvictionMarker(deadline);
|
|
13176
13277
|
} catch (error) {
|
|
13177
|
-
if (isRetryableRemoval(actionError, lockPath)
|
|
13278
|
+
if ((isRetryableRemoval(actionError, lockPath) || isWindowsAccessDeniedRead(actionError, [
|
|
13279
|
+
lockPath,
|
|
13280
|
+
legacyOwnerPath,
|
|
13281
|
+
evictOwnerPath
|
|
13282
|
+
])) && (isRetryableRemoval(error, evictPath) || isWindowsAccessDeniedRead(error, [evictOwnerPath])))
|
|
13178
13283
|
throw actionError;
|
|
13179
13284
|
throw error;
|
|
13180
13285
|
}
|
|
@@ -13190,7 +13295,7 @@ async function acquireRefreshFileLockWithClock(options) {
|
|
|
13190
13295
|
try {
|
|
13191
13296
|
owner = await readOwner();
|
|
13192
13297
|
} catch (error) {
|
|
13193
|
-
if (windowsPrivateFiles)
|
|
13298
|
+
if (windowsPrivateFiles && !(error instanceof DisappearedLockRecordError))
|
|
13194
13299
|
throw error;
|
|
13195
13300
|
return;
|
|
13196
13301
|
}
|
|
@@ -13268,7 +13373,7 @@ async function acquireRefreshFileLockWithClock(options) {
|
|
|
13268
13373
|
await options.onStep("renewal-marker-unavailable");
|
|
13269
13374
|
}
|
|
13270
13375
|
} catch (error) {
|
|
13271
|
-
if (windowsPrivateFiles && error instanceof PrivateFileError) {
|
|
13376
|
+
if (windowsPrivateFiles && error instanceof PrivateFileError && !isChangingLockCreate(error)) {
|
|
13272
13377
|
terminalIOError = error;
|
|
13273
13378
|
recordLoss("renewal-failed");
|
|
13274
13379
|
shouldReschedule = false;
|
|
@@ -13314,72 +13419,90 @@ async function acquireRefreshFileLockWithClock(options) {
|
|
|
13314
13419
|
}
|
|
13315
13420
|
return null;
|
|
13316
13421
|
}
|
|
13317
|
-
let acquired =
|
|
13422
|
+
let acquired = false;
|
|
13423
|
+
let changingCreateError;
|
|
13424
|
+
try {
|
|
13425
|
+
acquired = await tryAcquire();
|
|
13426
|
+
} catch (error) {
|
|
13427
|
+
if (!isChangingLockCreate(error))
|
|
13428
|
+
throw error;
|
|
13429
|
+
changingCreateError = error;
|
|
13430
|
+
}
|
|
13318
13431
|
if (!acquired) {
|
|
13319
13432
|
for (let attempt = 0; attempt < MAX_STEAL_ATTEMPTS; attempt++) {
|
|
13320
|
-
acquired = await tryAcquire();
|
|
13321
|
-
if (acquired)
|
|
13322
|
-
break;
|
|
13323
|
-
const observed = await readLockState();
|
|
13324
|
-
if (observed.status === "live")
|
|
13325
|
-
return contended();
|
|
13326
|
-
if (observed.status === "missing")
|
|
13327
|
-
continue;
|
|
13328
|
-
if (options.onStep)
|
|
13329
|
-
await options.onStep("stale-lock-observed");
|
|
13330
13433
|
try {
|
|
13331
|
-
|
|
13332
|
-
|
|
13333
|
-
|
|
13334
|
-
|
|
13335
|
-
|
|
13336
|
-
const code2 = evictError.code;
|
|
13337
|
-
if (code2 !== "EEXIST")
|
|
13338
|
-
throw evictError;
|
|
13339
|
-
const recovered = await recoverStaleEvictionMarker();
|
|
13340
|
-
if (recovered === "fresh")
|
|
13341
|
-
return null;
|
|
13342
|
-
await backoff();
|
|
13343
|
-
continue;
|
|
13344
|
-
}
|
|
13345
|
-
try {
|
|
13346
|
-
const confirmed = await readLockState();
|
|
13347
|
-
if (confirmed.status === "live")
|
|
13434
|
+
acquired = await tryAcquire();
|
|
13435
|
+
if (acquired)
|
|
13436
|
+
break;
|
|
13437
|
+
const observed = await readLockState();
|
|
13438
|
+
if (observed.status === "live")
|
|
13348
13439
|
return contended();
|
|
13349
|
-
if (
|
|
13440
|
+
if (observed.status === "missing")
|
|
13350
13441
|
continue;
|
|
13351
|
-
if (!await ownsEvictionMarker())
|
|
13352
|
-
return null;
|
|
13353
13442
|
if (options.onStep)
|
|
13354
|
-
await options.onStep("stale-lock-
|
|
13355
|
-
|
|
13356
|
-
|
|
13357
|
-
|
|
13358
|
-
|
|
13443
|
+
await options.onStep("stale-lock-observed");
|
|
13444
|
+
try {
|
|
13445
|
+
if (!await tryAcquireEvictionMarker()) {
|
|
13446
|
+
await backoff();
|
|
13447
|
+
continue;
|
|
13448
|
+
}
|
|
13449
|
+
} catch (evictError) {
|
|
13450
|
+
const code2 = evictError.code;
|
|
13451
|
+
if (code2 !== "EEXIST")
|
|
13452
|
+
throw evictError;
|
|
13453
|
+
const recovered = await recoverStaleEvictionMarker();
|
|
13454
|
+
if (recovered === "fresh")
|
|
13455
|
+
return null;
|
|
13456
|
+
await backoff();
|
|
13359
13457
|
continue;
|
|
13360
|
-
await removeLeaseObject(lockPath);
|
|
13361
|
-
if (!await ownsEvictionMarker())
|
|
13362
|
-
return null;
|
|
13363
|
-
if (options.onStep)
|
|
13364
|
-
await options.onStep("stale-lock-removed");
|
|
13365
|
-
acquired = await tryAcquire();
|
|
13366
|
-
if (!acquired)
|
|
13367
|
-
return null;
|
|
13368
|
-
if (options.onStep)
|
|
13369
|
-
await options.onStep("stale-lock-recreated");
|
|
13370
|
-
if (!await ownsEvictionMarker()) {
|
|
13371
|
-
await relinquishLockAfterMarkerLoss();
|
|
13372
|
-
acquired = false;
|
|
13373
|
-
return null;
|
|
13374
13458
|
}
|
|
13375
|
-
|
|
13376
|
-
|
|
13377
|
-
|
|
13459
|
+
try {
|
|
13460
|
+
const confirmed = await readLockState();
|
|
13461
|
+
if (confirmed.status === "live")
|
|
13462
|
+
return contended();
|
|
13463
|
+
if (!sameStaleLock(observed.identity, confirmed))
|
|
13464
|
+
continue;
|
|
13465
|
+
if (!await ownsEvictionMarker())
|
|
13466
|
+
return null;
|
|
13467
|
+
if (options.onStep)
|
|
13468
|
+
await options.onStep("stale-lock-confirmed");
|
|
13469
|
+
if (!await ownsEvictionMarker())
|
|
13470
|
+
return null;
|
|
13471
|
+
const current = await readLockState(false);
|
|
13472
|
+
if (!sameStaleLock(observed.identity, current))
|
|
13473
|
+
continue;
|
|
13474
|
+
await removeLeaseObject(lockPath);
|
|
13475
|
+
if (!await ownsEvictionMarker())
|
|
13476
|
+
return null;
|
|
13477
|
+
if (options.onStep)
|
|
13478
|
+
await options.onStep("stale-lock-removed");
|
|
13479
|
+
acquired = await tryAcquire();
|
|
13480
|
+
if (!acquired)
|
|
13481
|
+
return null;
|
|
13482
|
+
if (options.onStep)
|
|
13483
|
+
await options.onStep("stale-lock-recreated");
|
|
13484
|
+
if (!await ownsEvictionMarker()) {
|
|
13485
|
+
await relinquishLockAfterMarkerLoss();
|
|
13486
|
+
acquired = false;
|
|
13487
|
+
return null;
|
|
13488
|
+
}
|
|
13489
|
+
break;
|
|
13490
|
+
} finally {
|
|
13491
|
+
await releaseEvictionMarker();
|
|
13492
|
+
}
|
|
13493
|
+
} catch (error) {
|
|
13494
|
+
if (!isChangingLockCreate(error))
|
|
13495
|
+
throw error;
|
|
13496
|
+
changingCreateError ??= error;
|
|
13497
|
+
await backoff();
|
|
13378
13498
|
}
|
|
13379
13499
|
}
|
|
13380
13500
|
}
|
|
13381
|
-
if (!acquired)
|
|
13501
|
+
if (!acquired) {
|
|
13502
|
+
if (changingCreateError)
|
|
13503
|
+
throw changingCreateError;
|
|
13382
13504
|
return null;
|
|
13505
|
+
}
|
|
13383
13506
|
scheduleRenewal();
|
|
13384
13507
|
return {
|
|
13385
13508
|
ownerId,
|
|
@@ -13417,6 +13540,7 @@ async function acquireRefreshFileLockWithClock(options) {
|
|
|
13417
13540
|
const deadline = performance.now() + EVICT_TTL + 1e3;
|
|
13418
13541
|
let delayMs = 5;
|
|
13419
13542
|
let removalError;
|
|
13543
|
+
let changingRecordError;
|
|
13420
13544
|
for (; ; ) {
|
|
13421
13545
|
try {
|
|
13422
13546
|
let removalConfirmed = false;
|
|
@@ -13442,6 +13566,7 @@ async function acquireRefreshFileLockWithClock(options) {
|
|
|
13442
13566
|
await removeLeaseObject(lockPath);
|
|
13443
13567
|
removalConfirmed = true;
|
|
13444
13568
|
}, deadline);
|
|
13569
|
+
changingRecordError = void 0;
|
|
13445
13570
|
if (markerAcquired) {
|
|
13446
13571
|
if (windowsPrivateFiles && !removalConfirmed)
|
|
13447
13572
|
throw new PrivateFileError(lockPath, "release-not-confirmed", {
|
|
@@ -13454,23 +13579,32 @@ async function acquireRefreshFileLockWithClock(options) {
|
|
|
13454
13579
|
return;
|
|
13455
13580
|
await recoverStaleEvictionMarker(deadline);
|
|
13456
13581
|
} catch (error) {
|
|
13457
|
-
|
|
13582
|
+
const changingRecord = windowsPrivateFiles && (isChangingLockCreate(error) || isWindowsAccessDeniedRead(error, [
|
|
13583
|
+
lockPath,
|
|
13584
|
+
legacyOwnerPath,
|
|
13585
|
+
evictPath,
|
|
13586
|
+
evictOwnerPath
|
|
13587
|
+
]));
|
|
13588
|
+
if (!isRetryableRemoval(error, lockPath) && !changingRecord) {
|
|
13458
13589
|
if (windowsPrivateFiles)
|
|
13459
13590
|
throw error;
|
|
13460
13591
|
return;
|
|
13461
13592
|
}
|
|
13462
|
-
|
|
13593
|
+
if (changingRecord)
|
|
13594
|
+
changingRecordError ??= error;
|
|
13595
|
+
else
|
|
13596
|
+
removalError ??= error;
|
|
13463
13597
|
}
|
|
13464
13598
|
const remainingMs = deadline - performance.now();
|
|
13465
13599
|
if (remainingMs <= 0)
|
|
13466
13600
|
break;
|
|
13467
|
-
await new Promise((
|
|
13601
|
+
await new Promise((resolve29) => setTimeout(resolve29, Math.min(delayMs, remainingMs)));
|
|
13468
13602
|
if (windowsPrivateFiles && performance.now() >= deadline)
|
|
13469
13603
|
break;
|
|
13470
13604
|
delayMs = Math.min(delayMs * 2, 50);
|
|
13471
13605
|
}
|
|
13472
13606
|
if (windowsPrivateFiles)
|
|
13473
|
-
throw removalError ?? new PrivateFileError(lockPath, "release-not-confirmed", {
|
|
13607
|
+
throw changingRecordError ?? removalError ?? new PrivateFileError(lockPath, "release-not-confirmed", {
|
|
13474
13608
|
code: "ETIMEDOUT"
|
|
13475
13609
|
});
|
|
13476
13610
|
}
|
|
@@ -13480,6 +13614,7 @@ var leaseCreationTestHooks, setRefreshLockRenewalTimeout, clearRefreshLockRenewa
|
|
|
13480
13614
|
var init_refresh_file_lock = __esm({
|
|
13481
13615
|
"../core/dist/common-auth-embedded/fs/refresh-file-lock.js"() {
|
|
13482
13616
|
"use strict";
|
|
13617
|
+
init_lock_record();
|
|
13483
13618
|
init_private_files();
|
|
13484
13619
|
init_with_lock();
|
|
13485
13620
|
setRefreshLockRenewalTimeout = globalThis.setTimeout.bind(globalThis);
|
|
@@ -13489,22 +13624,21 @@ var init_refresh_file_lock = __esm({
|
|
|
13489
13624
|
});
|
|
13490
13625
|
|
|
13491
13626
|
// ../core/dist/common-auth-embedded/fs/with-lock.js
|
|
13492
|
-
import { join as join6, resolve as
|
|
13627
|
+
import { join as join6, resolve as resolve4 } from "node:path";
|
|
13493
13628
|
function lockPathFor(target, name) {
|
|
13494
13629
|
return `${target}.${name}.lock`;
|
|
13495
13630
|
}
|
|
13496
|
-
function
|
|
13497
|
-
|
|
13498
|
-
|
|
13499
|
-
|
|
13500
|
-
return error.path === path5 || error.path === join6(path5, "owner.json");
|
|
13631
|
+
function isChangingLockRecord(error, target, name) {
|
|
13632
|
+
const path5 = resolve4(lockPathFor(target, name));
|
|
13633
|
+
const paths = [path5, join6(path5, "owner.json")];
|
|
13634
|
+
return (isWindowsSharingViolation(error) || isWindowsAccessDeniedRead(error, paths)) && (error.stage === "read" || error.stage === "verify") && paths.includes(error.path) || windowsPrivateFiles && (isWindowsAccessDeniedCreate(error, [path5], "create") || isWindowsAccessDeniedCreate(error, [`${path5}.evicting`], "directory-create"));
|
|
13501
13635
|
}
|
|
13502
13636
|
async function withLock(target, options, fn) {
|
|
13503
13637
|
const started = performance.now();
|
|
13638
|
+
let changingRecordError;
|
|
13504
13639
|
for (; ; ) {
|
|
13505
13640
|
options.signal?.throwIfAborted();
|
|
13506
13641
|
let lock;
|
|
13507
|
-
let changingReadError;
|
|
13508
13642
|
try {
|
|
13509
13643
|
lock = await acquireRefreshFileLock({
|
|
13510
13644
|
path: target,
|
|
@@ -13514,11 +13648,12 @@ async function withLock(target, options, fn) {
|
|
|
13514
13648
|
...options.onStep ? { onStep: options.onStep } : {},
|
|
13515
13649
|
...options.onRenewalTimer ? { onRenewalTimer: options.onRenewalTimer } : {}
|
|
13516
13650
|
});
|
|
13651
|
+
changingRecordError = void 0;
|
|
13517
13652
|
} catch (error) {
|
|
13518
|
-
if (!
|
|
13653
|
+
if (!isChangingLockRecord(error, target, options.name))
|
|
13519
13654
|
throw error;
|
|
13520
13655
|
lock = null;
|
|
13521
|
-
|
|
13656
|
+
changingRecordError ??= error;
|
|
13522
13657
|
}
|
|
13523
13658
|
if (lock) {
|
|
13524
13659
|
try {
|
|
@@ -13530,21 +13665,22 @@ async function withLock(target, options, fn) {
|
|
|
13530
13665
|
}
|
|
13531
13666
|
const remaining = options.timeoutMs - (performance.now() - started);
|
|
13532
13667
|
if (remaining <= 0) {
|
|
13533
|
-
if (
|
|
13534
|
-
throw
|
|
13668
|
+
if (changingRecordError)
|
|
13669
|
+
throw changingRecordError;
|
|
13535
13670
|
throw new LockContentionError({
|
|
13536
13671
|
target,
|
|
13537
13672
|
name: options.name,
|
|
13538
13673
|
timeoutMs: options.timeoutMs
|
|
13539
13674
|
});
|
|
13540
13675
|
}
|
|
13541
|
-
await new Promise((
|
|
13676
|
+
await new Promise((resolve29) => setTimeout(resolve29, Math.min(25, Math.ceil(remaining))));
|
|
13542
13677
|
}
|
|
13543
13678
|
}
|
|
13544
13679
|
var LockContentionError, LockOwnershipError;
|
|
13545
13680
|
var init_with_lock = __esm({
|
|
13546
13681
|
"../core/dist/common-auth-embedded/fs/with-lock.js"() {
|
|
13547
13682
|
"use strict";
|
|
13683
|
+
init_lock_record();
|
|
13548
13684
|
init_private_files();
|
|
13549
13685
|
init_refresh_file_lock();
|
|
13550
13686
|
LockContentionError = class extends Error {
|
|
@@ -13627,7 +13763,7 @@ async function acquirePoolLock(spec, defaults, env3) {
|
|
|
13627
13763
|
});
|
|
13628
13764
|
}
|
|
13629
13765
|
const jitter = Math.floor(Math.random() * (options.retryMs + 1));
|
|
13630
|
-
await new Promise((
|
|
13766
|
+
await new Promise((resolve29) => setTimeout(resolve29, Math.min(options.retryMs + jitter, remaining)));
|
|
13631
13767
|
}
|
|
13632
13768
|
}
|
|
13633
13769
|
function definedOnly(spec) {
|
|
@@ -16431,8 +16567,8 @@ var init_pull = __esm({
|
|
|
16431
16567
|
// ../core/dist/common-auth-embedded/logger/capture-sink.js
|
|
16432
16568
|
function createCaptureSink() {
|
|
16433
16569
|
const records = [];
|
|
16434
|
-
const sink = (
|
|
16435
|
-
records.push(
|
|
16570
|
+
const sink = (record4) => {
|
|
16571
|
+
records.push(record4);
|
|
16436
16572
|
};
|
|
16437
16573
|
return {
|
|
16438
16574
|
records,
|
|
@@ -16521,7 +16657,7 @@ var init_redact = __esm({
|
|
|
16521
16657
|
// ../core/dist/common-auth-embedded/logger/engine.js
|
|
16522
16658
|
import { appendFileSync, chmodSync, existsSync, renameSync, statSync } from "node:fs";
|
|
16523
16659
|
import { open as open5 } from "node:fs/promises";
|
|
16524
|
-
import { dirname as dirname8, resolve as
|
|
16660
|
+
import { dirname as dirname8, resolve as resolve5 } from "node:path";
|
|
16525
16661
|
function chmodPrivate(path5) {
|
|
16526
16662
|
try {
|
|
16527
16663
|
chmodSync(path5, 384);
|
|
@@ -16572,7 +16708,7 @@ async function openWindowsFile(sink, file) {
|
|
|
16572
16708
|
return sink.handle;
|
|
16573
16709
|
}
|
|
16574
16710
|
async function flushWindowsFile(sink, file, text2) {
|
|
16575
|
-
file =
|
|
16711
|
+
file = resolve5(file);
|
|
16576
16712
|
try {
|
|
16577
16713
|
if (sink.file !== file)
|
|
16578
16714
|
await closeWindowsFile(sink);
|
|
@@ -16948,11 +17084,11 @@ var init_quota_writer = __esm({
|
|
|
16948
17084
|
const left = deadline - performance.now();
|
|
16949
17085
|
if (left <= 0)
|
|
16950
17086
|
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);
|
|
16951
|
-
await new Promise((
|
|
17087
|
+
await new Promise((resolve29) => {
|
|
16952
17088
|
const done = () => {
|
|
16953
17089
|
clearTimeout(timer);
|
|
16954
17090
|
this.wake.delete(done);
|
|
16955
|
-
|
|
17091
|
+
resolve29();
|
|
16956
17092
|
};
|
|
16957
17093
|
const timer = setTimeout(done, left);
|
|
16958
17094
|
this.wake.add(done);
|
|
@@ -17345,7 +17481,7 @@ var init_refresh = __esm({
|
|
|
17345
17481
|
|
|
17346
17482
|
// ../core/dist/common-auth-embedded/fs/file-read-cache.js
|
|
17347
17483
|
import { lstat as lstat4, stat as stat4 } from "node:fs/promises";
|
|
17348
|
-
import { resolve as
|
|
17484
|
+
import { resolve as resolve6 } from "node:path";
|
|
17349
17485
|
async function identity(path5, followSymlinks) {
|
|
17350
17486
|
try {
|
|
17351
17487
|
const metadata = await (followSymlinks ? stat4(path5) : lstat4(path5));
|
|
@@ -17370,7 +17506,7 @@ var init_file_read_cache = __esm({
|
|
|
17370
17506
|
this.#followSymlinks = options.followSymlinks ?? false;
|
|
17371
17507
|
}
|
|
17372
17508
|
async read(paths, read, validateHit) {
|
|
17373
|
-
const resolvedPaths = paths.map((path5) =>
|
|
17509
|
+
const resolvedPaths = paths.map((path5) => resolve6(path5));
|
|
17374
17510
|
const key = JSON.stringify(resolvedPaths);
|
|
17375
17511
|
const probed = await Promise.all(resolvedPaths.map((path5) => identity(path5, this.#followSymlinks)));
|
|
17376
17512
|
const identities = probed.every((entry) => entry !== void 0) ? probed : void 0;
|
|
@@ -17574,8 +17710,8 @@ function openPoolStore(options) {
|
|
|
17574
17710
|
firePull: (id, reason) => pulls.fire(id, reason)
|
|
17575
17711
|
};
|
|
17576
17712
|
const quotaWriter = options.coalesceQuota ? new PoolQuotaWriter(rt, options.quotaDrainTimeoutMs, options.quotaCommitTimer) : void 0;
|
|
17577
|
-
const
|
|
17578
|
-
rt.publishQuota =
|
|
17713
|
+
const record4 = (id, attribution, observation) => quotaWriter ? quotaWriter.record(id, attribution, observation) : recordQuota(rt, id, attribution, observation);
|
|
17714
|
+
rt.publishQuota = record4;
|
|
17579
17715
|
const overlay = (result) => {
|
|
17580
17716
|
if (result.status === "ready" && quotaWriter)
|
|
17581
17717
|
return { ...result, rows: quotaWriter.overlay(result.rows) };
|
|
@@ -17612,7 +17748,7 @@ function openPoolStore(options) {
|
|
|
17612
17748
|
updateLimitsNamespace: (mutator, options2) => updatePoolLimitsNamespace(rt, mutator, options2),
|
|
17613
17749
|
recordIdentity: (id, identity3, attribution, callOptions) => recordRowIdentity(rt, id, identity3, attribution, callOptions),
|
|
17614
17750
|
refresh: (id, provider2, callOptions) => refreshRow(rt, id, provider2, callOptions),
|
|
17615
|
-
recordQuota:
|
|
17751
|
+
recordQuota: record4,
|
|
17616
17752
|
close: () => quotaWriter?.close() ?? Promise.resolve(),
|
|
17617
17753
|
dispose: () => quotaWriter?.close() ?? Promise.resolve(),
|
|
17618
17754
|
requestReading: (id) => pulls.fire(id, "admission"),
|
|
@@ -19559,9 +19695,17 @@ var init_availability = __esm({
|
|
|
19559
19695
|
ERR_PRIVATE_FILES_SECURITY: "answered"
|
|
19560
19696
|
});
|
|
19561
19697
|
ClaustrumUnreachableError = class extends ClaustrumConsumerError {
|
|
19562
|
-
|
|
19698
|
+
/**
|
|
19699
|
+
* Non-secret host connection diagnostic. A missing accessor can recover
|
|
19700
|
+
* once the host bridge installs; a failed accessor could not provide a client.
|
|
19701
|
+
* Other unreachable failures leave this unset. Never use adapter error text.
|
|
19702
|
+
*/
|
|
19703
|
+
reason;
|
|
19704
|
+
constructor(reason) {
|
|
19563
19705
|
super("unavailable", "Claustrum scoped operation unavailable");
|
|
19564
19706
|
this.name = "ClaustrumUnreachableError";
|
|
19707
|
+
if (reason === "host-accessor-missing" || reason === "host-accessor-failed")
|
|
19708
|
+
this.reason = reason;
|
|
19565
19709
|
}
|
|
19566
19710
|
};
|
|
19567
19711
|
}
|
|
@@ -19582,7 +19726,7 @@ function hostError(error) {
|
|
|
19582
19726
|
if (typeof value.code === "string" && (value.class === "transient" || value.class === "permanent" || value.class === "auth_required" || value.class === "context_overflow") && (value.action === "gone" || value.action === "reauth" || value.action === "retry" || value.action === "reduce_and_retry"))
|
|
19583
19727
|
return new ClaustrumCredentialError2(value.code, value.class, value.action);
|
|
19584
19728
|
if (value.name === "ClaustrumUnreachableError" || typeof value.code === "string" && classifyVaultFailure(Object.assign(new Error(), { code: value.code })) === "unreachable")
|
|
19585
|
-
return new ClaustrumUnreachableError();
|
|
19729
|
+
return new ClaustrumUnreachableError(value.reason === "host-accessor-missing" || value.reason === "host-accessor-failed" ? value.reason : void 0);
|
|
19586
19730
|
return error;
|
|
19587
19731
|
}
|
|
19588
19732
|
function call(operation) {
|
|
@@ -19648,14 +19792,15 @@ function connectVaultHost(pluginId) {
|
|
|
19648
19792
|
throw new ClaustrumUnreachableError();
|
|
19649
19793
|
try {
|
|
19650
19794
|
const accessor = globalThis[/* @__PURE__ */ Symbol.for("cortexkit.vault")];
|
|
19651
|
-
if (typeof accessor
|
|
19652
|
-
|
|
19653
|
-
|
|
19654
|
-
|
|
19655
|
-
|
|
19795
|
+
if (typeof accessor === "function") {
|
|
19796
|
+
const client = wrapHostClient(accessor(pluginId));
|
|
19797
|
+
hostClients.add(client);
|
|
19798
|
+
return client;
|
|
19799
|
+
}
|
|
19656
19800
|
} catch {
|
|
19657
|
-
throw new ClaustrumUnreachableError();
|
|
19801
|
+
throw new ClaustrumUnreachableError("host-accessor-failed");
|
|
19658
19802
|
}
|
|
19803
|
+
throw new ClaustrumUnreachableError("host-accessor-missing");
|
|
19659
19804
|
}
|
|
19660
19805
|
var VAULT_HOST_STATUS, VAULT_HOST_CONNECT_REFUSAL, hostClients;
|
|
19661
19806
|
var init_host = __esm({
|
|
@@ -19991,7 +20136,7 @@ async function select(terminal, items, options) {
|
|
|
19991
20136
|
writeLine("");
|
|
19992
20137
|
renderedLines = lines;
|
|
19993
20138
|
};
|
|
19994
|
-
return new Promise((
|
|
20139
|
+
return new Promise((resolve29) => {
|
|
19995
20140
|
const wasRaw = stdin.isRaw ?? false;
|
|
19996
20141
|
const cleanup2 = () => {
|
|
19997
20142
|
if (cleaned)
|
|
@@ -20011,7 +20156,7 @@ async function select(terminal, items, options) {
|
|
|
20011
20156
|
};
|
|
20012
20157
|
const finish = (value) => {
|
|
20013
20158
|
cleanup2();
|
|
20014
|
-
|
|
20159
|
+
resolve29(value);
|
|
20015
20160
|
};
|
|
20016
20161
|
const onSignal = () => finish(null);
|
|
20017
20162
|
const onKey = (data) => {
|
|
@@ -20051,7 +20196,7 @@ async function select(terminal, items, options) {
|
|
|
20051
20196
|
stdin.setRawMode(true);
|
|
20052
20197
|
} catch {
|
|
20053
20198
|
cleanup2();
|
|
20054
|
-
|
|
20199
|
+
resolve29(null);
|
|
20055
20200
|
return;
|
|
20056
20201
|
}
|
|
20057
20202
|
stdin.resume();
|
|
@@ -20787,7 +20932,7 @@ var init_watch = __esm({
|
|
|
20787
20932
|
});
|
|
20788
20933
|
|
|
20789
20934
|
// ../core/dist/common-auth-embedded/claustrum/insula.js
|
|
20790
|
-
import { resolve as
|
|
20935
|
+
import { resolve as resolve7 } from "node:path";
|
|
20791
20936
|
import { storeIdentity } from "@cortexkit/claustrum-client";
|
|
20792
20937
|
import { SubcClient } from "@cortexkit/subc-client";
|
|
20793
20938
|
function insulaUsageTransport(options) {
|
|
@@ -20915,8 +21060,8 @@ function refusalCode(error) {
|
|
|
20915
21060
|
}
|
|
20916
21061
|
function acquireInsulaQuotaSource(transport, tokenPath) {
|
|
20917
21062
|
const key = JSON.stringify([
|
|
20918
|
-
|
|
20919
|
-
|
|
21063
|
+
resolve7(transport.connectionFile),
|
|
21064
|
+
resolve7(tokenPath)
|
|
20920
21065
|
]);
|
|
20921
21066
|
let shared3 = sources.get(key);
|
|
20922
21067
|
if (!shared3) {
|
|
@@ -21230,7 +21375,7 @@ var init_any_signal = __esm({
|
|
|
21230
21375
|
import { createHash as createHash6, randomBytes as randomBytes4, randomUUID as randomUUID12 } from "node:crypto";
|
|
21231
21376
|
import { constants as fsConstants } from "node:fs";
|
|
21232
21377
|
import { chmod as chmod2, mkdir as mkdir8, open as open6, readFile as readFile6, realpath as realpath3, rename as rename7, stat as stat5, unlink as unlink6 } from "node:fs/promises";
|
|
21233
|
-
import { basename as basename3, dirname as dirname9, extname, isAbsolute as isAbsolute2, join as join7, resolve as
|
|
21378
|
+
import { basename as basename3, dirname as dirname9, extname, isAbsolute as isAbsolute2, join as join7, resolve as resolve8 } from "node:path";
|
|
21234
21379
|
import { ClaustrumCredentialError as ClaustrumCredentialError3, ClaustrumClient as ClaustrumWireClient, writeEnrollmentTokenFile } from "@cortexkit/claustrum-client";
|
|
21235
21380
|
function classifyEnrollmentError(error) {
|
|
21236
21381
|
if (!(error instanceof ClaustrumCredentialError3))
|
|
@@ -21249,6 +21394,29 @@ function enrollmentName(plugin, host) {
|
|
|
21249
21394
|
throw new ClaustrumConsumerError("invalid-state", "Claustrum enrollment names use lowercase letters, digits and dashes");
|
|
21250
21395
|
return `${plugin}-${host}`;
|
|
21251
21396
|
}
|
|
21397
|
+
function validEnrollmentDisplayName(displayName) {
|
|
21398
|
+
const length = Array.from(displayName).length;
|
|
21399
|
+
return length >= 1 && length <= 40 && !/[\p{Cc}\u061c\u200e\u200f\u202a-\u202e\u2066-\u2069\u200b-\u200d\u2060\ufeff]/u.test(displayName);
|
|
21400
|
+
}
|
|
21401
|
+
function validEnrollmentRequestedGrants(grants) {
|
|
21402
|
+
return Array.isArray(grants) && grants.length >= 1 && grants.length <= 4 && Array.from(grants).every((grant) => {
|
|
21403
|
+
if (!isRecord6(grant) || Object.keys(grant).length !== 2 || grant.operation !== "read" && grant.operation !== "list" || !isRecord6(grant.selector))
|
|
21404
|
+
return false;
|
|
21405
|
+
const keys = Object.keys(grant.selector);
|
|
21406
|
+
const key = keys[0];
|
|
21407
|
+
return keys.length === 1 && (key === "category" || key === "exact") && typeof grant.selector[key] === "string" && grant.selector[key].trim().length > 0;
|
|
21408
|
+
});
|
|
21409
|
+
}
|
|
21410
|
+
function grantProposal(state) {
|
|
21411
|
+
return {
|
|
21412
|
+
...state.requestedGrants !== void 0 && {
|
|
21413
|
+
requestedGrants: state.requestedGrants
|
|
21414
|
+
},
|
|
21415
|
+
...state.requestedGrantsStatus !== void 0 && {
|
|
21416
|
+
requestedGrantsStatus: state.requestedGrantsStatus
|
|
21417
|
+
}
|
|
21418
|
+
};
|
|
21419
|
+
}
|
|
21252
21420
|
function connectClaustrumEnrollmentClient(options) {
|
|
21253
21421
|
return ClaustrumWireClient.connect(options);
|
|
21254
21422
|
}
|
|
@@ -21264,7 +21432,7 @@ function hostEnrollmentPaths(input2) {
|
|
|
21264
21432
|
const override = input2.override?.trim();
|
|
21265
21433
|
if (override && !isAbsolute2(override) && !input2.cwd)
|
|
21266
21434
|
throw new ClaustrumConsumerError("invalid-state", "A relative Claustrum enrollment override needs a base directory");
|
|
21267
|
-
const tokenPath = override ? isAbsolute2(override) ? override :
|
|
21435
|
+
const tokenPath = override ? isAbsolute2(override) ? override : resolve8(input2.cwd, override) : join7(input2.stateDir, `${input2.host}-enrollment.json`);
|
|
21268
21436
|
return getClaustrumEnrollmentPaths(tokenPath);
|
|
21269
21437
|
}
|
|
21270
21438
|
function isRecord6(value) {
|
|
@@ -21284,6 +21452,7 @@ function decodeEnrollmentState(value) {
|
|
|
21284
21452
|
throw invalidState();
|
|
21285
21453
|
}
|
|
21286
21454
|
if (value.phase === "pending") {
|
|
21455
|
+
const grants = decodeGrantProposal(value);
|
|
21287
21456
|
if (!TOKEN_RE.test(String(value.requestSecret ?? "")) || value.requestId !== void 0 && (typeof value.requestId !== "string" || value.requestId.length === 0) || !validTimestamp(value.createdAt) || !validTimestamp(value.updatedAt)) {
|
|
21288
21457
|
throw invalidState();
|
|
21289
21458
|
}
|
|
@@ -21296,10 +21465,12 @@ function decodeEnrollmentState(value) {
|
|
|
21296
21465
|
requestId: value.requestId
|
|
21297
21466
|
},
|
|
21298
21467
|
createdAt: value.createdAt,
|
|
21299
|
-
updatedAt: value.updatedAt
|
|
21468
|
+
updatedAt: value.updatedAt,
|
|
21469
|
+
...grants
|
|
21300
21470
|
};
|
|
21301
21471
|
}
|
|
21302
21472
|
if (value.phase === "approved") {
|
|
21473
|
+
const grants = decodeGrantProposal(value);
|
|
21303
21474
|
if (value.approvedName !== void 0 && (typeof value.approvedName !== "string" || value.approvedName.length === 0) || !validGeneration(value.tokenGeneration) || !validTimestamp(value.updatedAt)) {
|
|
21304
21475
|
throw invalidState();
|
|
21305
21476
|
}
|
|
@@ -21311,7 +21482,8 @@ function decodeEnrollmentState(value) {
|
|
|
21311
21482
|
approvedName: value.approvedName
|
|
21312
21483
|
},
|
|
21313
21484
|
tokenGeneration: value.tokenGeneration,
|
|
21314
|
-
updatedAt: value.updatedAt
|
|
21485
|
+
updatedAt: value.updatedAt,
|
|
21486
|
+
...grants
|
|
21315
21487
|
};
|
|
21316
21488
|
}
|
|
21317
21489
|
if (value.phase === "denied" || value.phase === "blocked") {
|
|
@@ -21330,6 +21502,11 @@ function decodeEnrollmentState(value) {
|
|
|
21330
21502
|
}
|
|
21331
21503
|
throw invalidState();
|
|
21332
21504
|
}
|
|
21505
|
+
function decodeGrantProposal(value) {
|
|
21506
|
+
if (value.requestedGrants !== void 0 && !validEnrollmentRequestedGrants(value.requestedGrants) || value.requestedGrantsStatus !== void 0 && (value.requestedGrants === void 0 || value.requestedGrantsStatus !== "sent" && value.requestedGrantsStatus !== "dropped"))
|
|
21507
|
+
return {};
|
|
21508
|
+
return grantProposal(value);
|
|
21509
|
+
}
|
|
21333
21510
|
function decodeTokenFile(value) {
|
|
21334
21511
|
if (!isRecord6(value) || !TOKEN_RE.test(String(value.token ?? "")) || !validGeneration(value.token_generation)) {
|
|
21335
21512
|
throw new ClaustrumConsumerError("invalid-token", "invalid Claustrum enrollment token file");
|
|
@@ -21543,7 +21720,8 @@ async function readEnrollmentStatus(paths, proposedName) {
|
|
|
21543
21720
|
...state?.phase === "approved" && state.approvedName !== void 0 && {
|
|
21544
21721
|
approvedName: state.approvedName
|
|
21545
21722
|
},
|
|
21546
|
-
tokenGeneration: token.token_generation
|
|
21723
|
+
tokenGeneration: token.token_generation,
|
|
21724
|
+
...state && (state.phase === "approved" || state.phase === "pending") && grantProposal(state)
|
|
21547
21725
|
}
|
|
21548
21726
|
};
|
|
21549
21727
|
}
|
|
@@ -21602,7 +21780,8 @@ function statusFromState(state) {
|
|
|
21602
21780
|
return {
|
|
21603
21781
|
state: "pending",
|
|
21604
21782
|
proposedName: state.proposedName,
|
|
21605
|
-
...state.requestId !== void 0 && { requestId: state.requestId }
|
|
21783
|
+
...state.requestId !== void 0 && { requestId: state.requestId },
|
|
21784
|
+
...grantProposal(state)
|
|
21606
21785
|
};
|
|
21607
21786
|
}
|
|
21608
21787
|
if (state.phase === "approved") {
|
|
@@ -21612,7 +21791,8 @@ function statusFromState(state) {
|
|
|
21612
21791
|
...state.approvedName !== void 0 && {
|
|
21613
21792
|
approvedName: state.approvedName
|
|
21614
21793
|
},
|
|
21615
|
-
tokenGeneration: state.tokenGeneration
|
|
21794
|
+
tokenGeneration: state.tokenGeneration,
|
|
21795
|
+
...grantProposal(state)
|
|
21616
21796
|
};
|
|
21617
21797
|
}
|
|
21618
21798
|
if (state.phase === "denied")
|
|
@@ -21731,15 +21911,26 @@ var init_enrollment = __esm({
|
|
|
21731
21911
|
#client;
|
|
21732
21912
|
#paths;
|
|
21733
21913
|
#proposedName;
|
|
21914
|
+
#displayName;
|
|
21915
|
+
#requestedGrants;
|
|
21734
21916
|
#now;
|
|
21735
21917
|
#mintSecret;
|
|
21736
21918
|
#writeTokenFile;
|
|
21737
21919
|
#ancestorOptions;
|
|
21738
21920
|
constructor(options) {
|
|
21921
|
+
if (options.displayName !== void 0 && !validEnrollmentDisplayName(options.displayName))
|
|
21922
|
+
throw new ClaustrumConsumerError("invalid-state", "invalid Claustrum enrollment display name");
|
|
21923
|
+
if (options.requestedGrants !== void 0 && !validEnrollmentRequestedGrants(options.requestedGrants))
|
|
21924
|
+
throw new ClaustrumConsumerError("invalid-state", "invalid Claustrum enrollment requested grants");
|
|
21925
|
+
this.#requestedGrants = options.requestedGrants?.map((grant) => ({
|
|
21926
|
+
selector: { ...grant.selector },
|
|
21927
|
+
operation: grant.operation
|
|
21928
|
+
}));
|
|
21739
21929
|
this.#ancestorOptions = options.ancestorOptions ?? {};
|
|
21740
21930
|
this.#client = options.client;
|
|
21741
21931
|
this.#paths = options.paths;
|
|
21742
21932
|
this.#proposedName = options.proposedName;
|
|
21933
|
+
this.#displayName = options.displayName;
|
|
21743
21934
|
this.#now = options.now ?? Date.now;
|
|
21744
21935
|
this.#mintSecret = options.mintSecret ?? (() => randomBytes4(32).toString("hex"));
|
|
21745
21936
|
this.#writeTokenFile = options.writeTokenFile ?? writeEnrollmentTokenFile;
|
|
@@ -21785,6 +21976,7 @@ var init_enrollment = __esm({
|
|
|
21785
21976
|
phase: "approved",
|
|
21786
21977
|
proposedName: state?.proposedName ?? this.#proposedName,
|
|
21787
21978
|
tokenGeneration: token.token_generation,
|
|
21979
|
+
...state && grantProposal(state),
|
|
21788
21980
|
updatedAt: this.#now()
|
|
21789
21981
|
};
|
|
21790
21982
|
await writeStateAtomic(this.#paths.statePath, approved, this.#ancestorOptions);
|
|
@@ -21796,7 +21988,8 @@ var init_enrollment = __esm({
|
|
|
21796
21988
|
...state.phase === "approved" && state.approvedName !== void 0 && {
|
|
21797
21989
|
approvedName: state.approvedName
|
|
21798
21990
|
},
|
|
21799
|
-
tokenGeneration: token.token_generation
|
|
21991
|
+
tokenGeneration: token.token_generation,
|
|
21992
|
+
...state.phase === "approved" && grantProposal(state)
|
|
21800
21993
|
};
|
|
21801
21994
|
}
|
|
21802
21995
|
if (state?.phase === "approved") {
|
|
@@ -21820,7 +22013,10 @@ var init_enrollment = __esm({
|
|
|
21820
22013
|
proposedName: this.#proposedName,
|
|
21821
22014
|
requestSecret: this.#mintSecret(),
|
|
21822
22015
|
createdAt: now,
|
|
21823
|
-
updatedAt: now
|
|
22016
|
+
updatedAt: now,
|
|
22017
|
+
...this.#requestedGrants !== void 0 && {
|
|
22018
|
+
requestedGrants: this.#requestedGrants
|
|
22019
|
+
}
|
|
21824
22020
|
};
|
|
21825
22021
|
if (!TOKEN_RE.test(state.requestSecret))
|
|
21826
22022
|
throw new ClaustrumConsumerError("invalid-state", "invalid minted Claustrum enrollment secret");
|
|
@@ -21829,14 +22025,38 @@ var init_enrollment = __esm({
|
|
|
21829
22025
|
if (!state.requestId) {
|
|
21830
22026
|
try {
|
|
21831
22027
|
const requestSecretHash = createHash6("sha256").update(Buffer.from(state.requestSecret, "hex")).digest("hex");
|
|
21832
|
-
const
|
|
22028
|
+
const proposal = {
|
|
21833
22029
|
name: state.proposedName,
|
|
21834
22030
|
requestSecretHash
|
|
21835
|
-
}
|
|
22031
|
+
};
|
|
22032
|
+
let proposed;
|
|
22033
|
+
let requestedGrantsStatus = state.requestedGrantsStatus;
|
|
22034
|
+
try {
|
|
22035
|
+
proposed = await this.#client.enrollPropose({
|
|
22036
|
+
...proposal,
|
|
22037
|
+
...this.#displayName !== void 0 && {
|
|
22038
|
+
displayName: this.#displayName
|
|
22039
|
+
},
|
|
22040
|
+
...state.requestedGrants !== void 0 && {
|
|
22041
|
+
requestedGrants: state.requestedGrants
|
|
22042
|
+
}
|
|
22043
|
+
});
|
|
22044
|
+
if (state.requestedGrants !== void 0)
|
|
22045
|
+
requestedGrantsStatus = "sent";
|
|
22046
|
+
} catch (error) {
|
|
22047
|
+
if (this.#displayName === void 0 && state.requestedGrants === void 0 || !(error instanceof ClaustrumCredentialError3) || error.code !== "invalid_params")
|
|
22048
|
+
throw error;
|
|
22049
|
+
proposed = await this.#client.enrollPropose(proposal);
|
|
22050
|
+
if (state.requestedGrants !== void 0)
|
|
22051
|
+
requestedGrantsStatus = "dropped";
|
|
22052
|
+
}
|
|
21836
22053
|
state = {
|
|
21837
22054
|
...state,
|
|
21838
22055
|
requestId: proposed.requestId,
|
|
21839
|
-
updatedAt: this.#now()
|
|
22056
|
+
updatedAt: this.#now(),
|
|
22057
|
+
...requestedGrantsStatus !== void 0 && {
|
|
22058
|
+
requestedGrantsStatus
|
|
22059
|
+
}
|
|
21840
22060
|
};
|
|
21841
22061
|
await writeStateAtomic(this.#paths.statePath, state, this.#ancestorOptions);
|
|
21842
22062
|
} catch (error) {
|
|
@@ -21847,7 +22067,8 @@ var init_enrollment = __esm({
|
|
|
21847
22067
|
return {
|
|
21848
22068
|
state: "pending",
|
|
21849
22069
|
proposedName: state.proposedName,
|
|
21850
|
-
retryCode: refusal3.code
|
|
22070
|
+
retryCode: refusal3.code,
|
|
22071
|
+
...grantProposal(state)
|
|
21851
22072
|
};
|
|
21852
22073
|
}
|
|
21853
22074
|
if (refusal3.code === UNSUPPORTED_ENROLLMENT_CODE) {
|
|
@@ -21897,6 +22118,7 @@ var init_enrollment = __esm({
|
|
|
21897
22118
|
proposedName: state.proposedName,
|
|
21898
22119
|
approvedName: outcome.name,
|
|
21899
22120
|
tokenGeneration: outcome.tokenGeneration,
|
|
22121
|
+
...grantProposal(state),
|
|
21900
22122
|
updatedAt: this.#now()
|
|
21901
22123
|
};
|
|
21902
22124
|
await writeStateAtomic(this.#paths.statePath, approved, this.#ancestorOptions);
|
|
@@ -21910,7 +22132,8 @@ var init_enrollment = __esm({
|
|
|
21910
22132
|
state: "pending",
|
|
21911
22133
|
proposedName: state.proposedName,
|
|
21912
22134
|
requestId,
|
|
21913
|
-
retryCode: refusal3.code
|
|
22135
|
+
retryCode: refusal3.code,
|
|
22136
|
+
...grantProposal(state)
|
|
21914
22137
|
};
|
|
21915
22138
|
}
|
|
21916
22139
|
return this.#block(state, refusal3.code);
|
|
@@ -21999,10 +22222,10 @@ async function drainShutdown(pending, onTimeout) {
|
|
|
21999
22222
|
try {
|
|
22000
22223
|
await Promise.race([
|
|
22001
22224
|
drained,
|
|
22002
|
-
new Promise((
|
|
22225
|
+
new Promise((resolve29) => {
|
|
22003
22226
|
timer = setTimeout(() => {
|
|
22004
22227
|
expired = true;
|
|
22005
|
-
|
|
22228
|
+
resolve29();
|
|
22006
22229
|
}, 2e3);
|
|
22007
22230
|
})
|
|
22008
22231
|
]);
|
|
@@ -22203,8 +22426,8 @@ function accessTokenFromMaterial(material) {
|
|
|
22203
22426
|
}
|
|
22204
22427
|
if (!parsed || typeof parsed !== "object")
|
|
22205
22428
|
throw invalidMaterial();
|
|
22206
|
-
const
|
|
22207
|
-
const value =
|
|
22429
|
+
const record4 = parsed;
|
|
22430
|
+
const value = record4.access_token ?? record4.access;
|
|
22208
22431
|
access = typeof value === "string" ? value : "";
|
|
22209
22432
|
}
|
|
22210
22433
|
if (!/^[\x21-\x7e]+$/.test(access) || access.startsWith(CUSTODY_PLACEHOLDER_PREFIX)) {
|
|
@@ -22346,8 +22569,15 @@ var init_custody = __esm({
|
|
|
22346
22569
|
this.#warnShutdown = shutdownWarning(this.#logger);
|
|
22347
22570
|
this.#setTimeout = options.setTimeoutImpl ?? setTimeout;
|
|
22348
22571
|
this.#clearTimeout = options.clearTimeoutImpl ?? clearTimeout;
|
|
22572
|
+
const currentClient = () => this.#client;
|
|
22349
22573
|
this.#usage = new ScopedUsageReporter({
|
|
22350
|
-
client:
|
|
22574
|
+
client: {
|
|
22575
|
+
// Queued readings follow a replacement without losing client capability checks.
|
|
22576
|
+
get reportUsageScoped() {
|
|
22577
|
+
const client = currentClient();
|
|
22578
|
+
return client.reportUsageScoped?.bind(client);
|
|
22579
|
+
}
|
|
22580
|
+
},
|
|
22351
22581
|
owns: (id) => this.#usageServed.has(id),
|
|
22352
22582
|
token: async () => hasVaultHost() ? "" : checkedEnrollmentToken(await this.#readToken()),
|
|
22353
22583
|
logger: this.#logger,
|
|
@@ -22355,12 +22585,30 @@ var init_custody = __esm({
|
|
|
22355
22585
|
clearTimeout: this.#clearTimeout
|
|
22356
22586
|
});
|
|
22357
22587
|
}
|
|
22588
|
+
/**
|
|
22589
|
+
* Replace the connection to the same vault without discarding receipts or
|
|
22590
|
+
* their enrollment tokens. Open roster watches restart on the new client;
|
|
22591
|
+
* their existing handles remain usable. Passing the current client does nothing.
|
|
22592
|
+
* Neither client is closed here: the caller closes the old one, and custody's
|
|
22593
|
+
* close()/dispose() still closes the client it holds at shutdown.
|
|
22594
|
+
* While hosted, next must come from connectVaultHost, as in the constructor.
|
|
22595
|
+
*/
|
|
22596
|
+
replaceClient(next) {
|
|
22597
|
+
this.#check();
|
|
22598
|
+
if (next === this.#client)
|
|
22599
|
+
return;
|
|
22600
|
+
if (hasVaultHost() && !isVaultHostClient(next))
|
|
22601
|
+
throw new ClaustrumUnreachableError();
|
|
22602
|
+
this.#client = next;
|
|
22603
|
+
for (const watch of this.#watches)
|
|
22604
|
+
watch.restart();
|
|
22605
|
+
}
|
|
22358
22606
|
/** A watch losing its transport is the same outage as an unreachable read. */
|
|
22359
22607
|
transportLost(error) {
|
|
22360
22608
|
if (this.#closed || this.#outage)
|
|
22361
22609
|
return;
|
|
22362
22610
|
this.#outage = true;
|
|
22363
|
-
this.#outageError = error instanceof ClaustrumCredentialError5 ? error : new ClaustrumUnreachableError();
|
|
22611
|
+
this.#outageError = error instanceof ClaustrumCredentialError5 ? error : new ClaustrumUnreachableError(error instanceof ClaustrumUnreachableError ? error.reason : void 0);
|
|
22364
22612
|
this.#logger.warn("serving kept vault receipt", { reason: "unreachable" });
|
|
22365
22613
|
this.#scheduleProbe();
|
|
22366
22614
|
}
|
|
@@ -22458,7 +22706,7 @@ var init_custody = __esm({
|
|
|
22458
22706
|
if (error instanceof ClaustrumCredentialError5)
|
|
22459
22707
|
throw error;
|
|
22460
22708
|
if (classifyVaultFailure(error) === "unreachable")
|
|
22461
|
-
throw new ClaustrumUnreachableError();
|
|
22709
|
+
throw new ClaustrumUnreachableError(error instanceof ClaustrumUnreachableError ? error.reason : void 0);
|
|
22462
22710
|
throw new ClaustrumConsumerError("unavailable", "Claustrum scoped operation unavailable");
|
|
22463
22711
|
} finally {
|
|
22464
22712
|
removeAbortListener?.();
|
|
@@ -22561,8 +22809,8 @@ var init_custody = __esm({
|
|
|
22561
22809
|
...row.orgName !== void 0 && { orgName: row.orgName }
|
|
22562
22810
|
}));
|
|
22563
22811
|
}
|
|
22564
|
-
for (const
|
|
22565
|
-
this.#logger.warn("skipped malformed vault record",
|
|
22812
|
+
for (const record4 of skipped)
|
|
22813
|
+
this.#logger.warn("skipped malformed vault record", record4);
|
|
22566
22814
|
const grantReach = grantReachOf(inventory);
|
|
22567
22815
|
return {
|
|
22568
22816
|
view: inventory.view,
|
|
@@ -22674,7 +22922,7 @@ var init_custody = __esm({
|
|
|
22674
22922
|
if (kept.since === null)
|
|
22675
22923
|
kept.since = this.#now();
|
|
22676
22924
|
const attempt = Object.freeze(Object.defineProperty({ ...kept.attempt, fromKeptReceipt: true }, "accessToken", { value: kept.attempt.accessToken, enumerable: false }));
|
|
22677
|
-
this.#provenance.set(attempt, this.#provenance.get(kept.attempt) ?? { token
|
|
22925
|
+
this.#provenance.set(attempt, this.#provenance.get(kept.attempt) ?? { token });
|
|
22678
22926
|
this.#keptAttempts.set(attempt, routeId);
|
|
22679
22927
|
return attempt;
|
|
22680
22928
|
}
|
|
@@ -22735,15 +22983,15 @@ var init_custody = __esm({
|
|
|
22735
22983
|
recordVersion: served.recordVersion,
|
|
22736
22984
|
expiresAtMs
|
|
22737
22985
|
}, "accessToken", { value: accessToken, enumerable: false }));
|
|
22738
|
-
this.#provenance.set(attempt, { token
|
|
22986
|
+
this.#provenance.set(attempt, { token });
|
|
22739
22987
|
return attempt;
|
|
22740
22988
|
}
|
|
22741
22989
|
/**
|
|
22742
22990
|
* Report that a send this consumer actually made was rejected. Only a 401
|
|
22743
22991
|
* is reported (the vault refuses 429, 402 and 5xx reports), addressed by
|
|
22744
22992
|
* credential id with the exact record version that send was served, and
|
|
22745
|
-
* sent through the client
|
|
22746
|
-
* this custody did not issue is refused rather than reported.
|
|
22993
|
+
* sent through the current client with the enrollment token that authorized
|
|
22994
|
+
* it. A receipt this custody did not issue is refused rather than reported.
|
|
22747
22995
|
*/
|
|
22748
22996
|
async reportFailure(attempt, status, reporterSource) {
|
|
22749
22997
|
if (status !== 401)
|
|
@@ -22767,7 +23015,7 @@ var init_custody = __esm({
|
|
|
22767
23015
|
const pending = this.#reports.get(attempt);
|
|
22768
23016
|
if (pending)
|
|
22769
23017
|
return pending;
|
|
22770
|
-
const report = this.#call(() =>
|
|
23018
|
+
const report = this.#call(() => this.#client.reportAuthFailureScoped({
|
|
22771
23019
|
credentialId: attempt.credentialId,
|
|
22772
23020
|
enrollmentToken: provenance.token,
|
|
22773
23021
|
providerStatus: 401,
|
|
@@ -22808,34 +23056,64 @@ var init_custody = __esm({
|
|
|
22808
23056
|
*/
|
|
22809
23057
|
watchRoster(options) {
|
|
22810
23058
|
this.#check();
|
|
22811
|
-
const
|
|
22812
|
-
|
|
22813
|
-
|
|
22814
|
-
|
|
22815
|
-
|
|
22816
|
-
|
|
22817
|
-
|
|
22818
|
-
|
|
22819
|
-
|
|
22820
|
-
|
|
23059
|
+
const currentView = options.view ?? (() => this.#discoveredView);
|
|
23060
|
+
let discovering;
|
|
23061
|
+
let watch;
|
|
23062
|
+
const create = (resubscribed = false) => {
|
|
23063
|
+
const opened = new ScopedRosterWatch({
|
|
23064
|
+
client: this.#client,
|
|
23065
|
+
enrollmentToken: () => this.#token(),
|
|
23066
|
+
// Nothing observed the gap between clients, even if the view is unchanged.
|
|
23067
|
+
view: () => resubscribed ? void 0 : currentView(),
|
|
23068
|
+
discover: async (view) => {
|
|
23069
|
+
while (discovering)
|
|
23070
|
+
await discovering.catch(() => {
|
|
23071
|
+
});
|
|
23072
|
+
if (watch !== opened)
|
|
23073
|
+
return;
|
|
23074
|
+
resubscribed = false;
|
|
23075
|
+
discovering = Promise.resolve().then(() => options.onView(view));
|
|
23076
|
+
try {
|
|
23077
|
+
await discovering;
|
|
23078
|
+
} finally {
|
|
23079
|
+
discovering = void 0;
|
|
23080
|
+
}
|
|
23081
|
+
},
|
|
23082
|
+
onRefused: (error) => {
|
|
23083
|
+
this.listFailed(error);
|
|
23084
|
+
options.onRefused?.(error);
|
|
23085
|
+
},
|
|
23086
|
+
onTransportLost: () => this.transportLost(),
|
|
23087
|
+
onReachable: () => this.reachable(),
|
|
23088
|
+
onError: options.onError,
|
|
23089
|
+
onMode: options.onMode,
|
|
23090
|
+
logger: this.#logger,
|
|
23091
|
+
now: this.#now,
|
|
23092
|
+
setTimeoutImpl: this.#setTimeout,
|
|
23093
|
+
clearTimeoutImpl: this.#clearTimeout
|
|
23094
|
+
});
|
|
23095
|
+
return opened;
|
|
23096
|
+
};
|
|
23097
|
+
watch = create();
|
|
23098
|
+
const tracked = {
|
|
23099
|
+
restart: () => {
|
|
23100
|
+
const previousMode = watch.mode;
|
|
23101
|
+
watch.stop();
|
|
23102
|
+
watch = create(true);
|
|
23103
|
+
if (previousMode !== watch.mode)
|
|
23104
|
+
options.onMode?.(watch.mode);
|
|
23105
|
+
watch.start();
|
|
22821
23106
|
},
|
|
22822
|
-
|
|
22823
|
-
|
|
22824
|
-
|
|
22825
|
-
onMode: options.onMode,
|
|
22826
|
-
logger: this.#logger,
|
|
22827
|
-
now: this.#now,
|
|
22828
|
-
setTimeoutImpl: this.#setTimeout,
|
|
22829
|
-
clearTimeoutImpl: this.#clearTimeout
|
|
22830
|
-
});
|
|
22831
|
-
this.#watches.add(watch);
|
|
23107
|
+
stop: () => watch.stop()
|
|
23108
|
+
};
|
|
23109
|
+
this.#watches.add(tracked);
|
|
22832
23110
|
watch.start();
|
|
22833
23111
|
return {
|
|
22834
23112
|
get mode() {
|
|
22835
23113
|
return watch.mode;
|
|
22836
23114
|
},
|
|
22837
23115
|
close: () => {
|
|
22838
|
-
this.#watches.delete(
|
|
23116
|
+
this.#watches.delete(tracked);
|
|
22839
23117
|
watch.stop();
|
|
22840
23118
|
}
|
|
22841
23119
|
};
|
|
@@ -22874,7 +23152,7 @@ var init_custody = __esm({
|
|
|
22874
23152
|
void usage.then(() => this.#tokenReads.delete(usage));
|
|
22875
23153
|
} else
|
|
22876
23154
|
this.#client.close();
|
|
22877
|
-
this.#disposing = drainShutdown(this.#tokenReads, (
|
|
23155
|
+
this.#disposing = drainShutdown(this.#tokenReads, (count4) => (this.#onDrainTimeout ?? this.#warnShutdown)(count4)).finally(() => {
|
|
22878
23156
|
this.#usage.drop();
|
|
22879
23157
|
this.#usageServed.clear();
|
|
22880
23158
|
if (usage)
|
|
@@ -22975,7 +23253,7 @@ var init_interlock = __esm({
|
|
|
22975
23253
|
// ../core/dist/common-auth-embedded/claustrum/roster.js
|
|
22976
23254
|
import { createHash as createHash7 } from "node:crypto";
|
|
22977
23255
|
import { stat as stat6 } from "node:fs/promises";
|
|
22978
|
-
import { resolve as
|
|
23256
|
+
import { resolve as resolve9 } from "node:path";
|
|
22979
23257
|
function vaultRosterSeed(roster) {
|
|
22980
23258
|
return {
|
|
22981
23259
|
declined: roster.declined.map((entry) => ({ ...entry })),
|
|
@@ -23016,8 +23294,8 @@ function projectVaultRoster(previous, inventory, options = {}) {
|
|
|
23016
23294
|
const declined = [...previous?.declined ?? seed?.declined ?? []];
|
|
23017
23295
|
const complete = inventory.skipped.length === 0;
|
|
23018
23296
|
const listed = new Set(inventory.credentials.map((credential) => credential.credentialId));
|
|
23019
|
-
const rejectedIds = new Set(inventory.skipped.flatMap((
|
|
23020
|
-
const unrecoverable = inventory.skipped.some((
|
|
23297
|
+
const rejectedIds = new Set(inventory.skipped.flatMap((record4) => record4.credentialId === void 0 ? [] : [record4.credentialId]));
|
|
23298
|
+
const unrecoverable = inventory.skipped.some((record4) => record4.credentialId === void 0);
|
|
23021
23299
|
const unaccounted = (id) => !listed.has(id) && (rejectedIds.has(id) || unrecoverable);
|
|
23022
23300
|
const lastKnown = /* @__PURE__ */ new Map();
|
|
23023
23301
|
for (const row of previousRows) {
|
|
@@ -23128,11 +23406,11 @@ function projectVaultRoster(previous, inventory, options = {}) {
|
|
|
23128
23406
|
...previous?.limits !== void 0 && { limits: previous.limits },
|
|
23129
23407
|
complete,
|
|
23130
23408
|
...!complete && {
|
|
23131
|
-
rejected: inventory.skipped.map((
|
|
23132
|
-
...
|
|
23133
|
-
credentialId:
|
|
23409
|
+
rejected: inventory.skipped.map((record4) => ({
|
|
23410
|
+
...record4.credentialId !== void 0 && {
|
|
23411
|
+
credentialId: record4.credentialId
|
|
23134
23412
|
},
|
|
23135
|
-
reason:
|
|
23413
|
+
reason: record4.reason
|
|
23136
23414
|
}))
|
|
23137
23415
|
},
|
|
23138
23416
|
rows: projected2.map((entry) => entry.row),
|
|
@@ -23377,16 +23655,16 @@ function applyVaultQuota(current, input2) {
|
|
|
23377
23655
|
};
|
|
23378
23656
|
}
|
|
23379
23657
|
function forgetPendingVaultDiscovery(path5) {
|
|
23380
|
-
pendingDiscoveries.delete(
|
|
23658
|
+
pendingDiscoveries.delete(resolve9(path5));
|
|
23381
23659
|
}
|
|
23382
23660
|
function isVaultRosterLockRefusal(path5, error) {
|
|
23383
|
-
const target =
|
|
23661
|
+
const target = resolve9(path5);
|
|
23384
23662
|
if (error instanceof ClaustrumConsumerError)
|
|
23385
23663
|
return error.kind === "roster-busy";
|
|
23386
23664
|
if (error instanceof LockContentionError || error instanceof LockOwnershipError)
|
|
23387
|
-
return
|
|
23665
|
+
return resolve9(error.details.target) === target;
|
|
23388
23666
|
if (error instanceof PrivateFileError) {
|
|
23389
|
-
const failed =
|
|
23667
|
+
const failed = resolve9(error.path);
|
|
23390
23668
|
return [WRITE_LOCK.name, DISCOVERY_LEASE.name].some((name) => {
|
|
23391
23669
|
const lock = lockPathFor(target, name);
|
|
23392
23670
|
return failed === lock || failed.startsWith(`${lock}.`);
|
|
@@ -23447,7 +23725,7 @@ async function refreshVaultRoster(options) {
|
|
|
23447
23725
|
throw new ClaustrumConsumerError("roster-busy", "Claustrum account discovery is already in progress");
|
|
23448
23726
|
return persisted;
|
|
23449
23727
|
}
|
|
23450
|
-
const key =
|
|
23728
|
+
const key = resolve9(options.path);
|
|
23451
23729
|
const listedOver = options.listedOver;
|
|
23452
23730
|
let discovered;
|
|
23453
23731
|
try {
|
|
@@ -23511,19 +23789,19 @@ function resolveVaultPrimary(input2) {
|
|
|
23511
23789
|
reason,
|
|
23512
23790
|
...previous && { lastVerified: previous }
|
|
23513
23791
|
});
|
|
23514
|
-
const
|
|
23515
|
-
if (!
|
|
23792
|
+
const record4 = inventory.credentials.find((credential) => credential.credentialId === input2.primaryCredentialId);
|
|
23793
|
+
if (!record4) {
|
|
23516
23794
|
if (inventory.skipped.some((skipped) => skipped.credentialId === input2.primaryCredentialId))
|
|
23517
23795
|
return unavailable("malformed");
|
|
23518
23796
|
const incomplete = input2.complete === false || inventory.skipped.some((skipped) => skipped.credentialId === void 0);
|
|
23519
23797
|
return incomplete ? unavailable("incomplete") : { status: "absent" };
|
|
23520
23798
|
}
|
|
23521
|
-
const identity3 =
|
|
23799
|
+
const identity3 = record4.accountIdentity;
|
|
23522
23800
|
if (identity3 === void 0)
|
|
23523
23801
|
return unavailable("unclaimed");
|
|
23524
23802
|
if (input2.expectedAccountIdentity !== void 0 && input2.expectedAccountIdentity !== identity3)
|
|
23525
23803
|
return unavailable("identity-changed");
|
|
23526
|
-
const representative =
|
|
23804
|
+
const representative = record4.state === "active" ? record4 : inventory.credentials.filter((credential) => credential.accountIdentity === identity3 && credential.state === "active").toSorted((left, right) => left.credentialId.localeCompare(right.credentialId))[0] ?? record4;
|
|
23527
23805
|
const binding = {
|
|
23528
23806
|
routeId: input2.routeId,
|
|
23529
23807
|
credentialId: representative.credentialId,
|
|
@@ -23571,9 +23849,9 @@ var init_roster = __esm({
|
|
|
23571
23849
|
});
|
|
23572
23850
|
|
|
23573
23851
|
// ../core/dist/common-auth-embedded/claustrum/quota-writer.js
|
|
23574
|
-
import { resolve as
|
|
23852
|
+
import { resolve as resolve10 } from "node:path";
|
|
23575
23853
|
function writerFor(path5, clock2 = quotaCommitTimer) {
|
|
23576
|
-
const key =
|
|
23854
|
+
const key = resolve10(path5);
|
|
23577
23855
|
let writer = writers.get(key);
|
|
23578
23856
|
if (!writer) {
|
|
23579
23857
|
writer = {
|
|
@@ -23637,7 +23915,7 @@ function orderedFields(pending) {
|
|
|
23637
23915
|
return [...pending.values()].flatMap((account) => [...account.values()]).sort((a, b) => a.order - b.order);
|
|
23638
23916
|
}
|
|
23639
23917
|
function pendingVaultQuota(path5, roster) {
|
|
23640
|
-
const writer = writers.get(
|
|
23918
|
+
const writer = writers.get(resolve10(path5));
|
|
23641
23919
|
if (writer) {
|
|
23642
23920
|
for (const field of orderedFields(writer.pending)) {
|
|
23643
23921
|
if (field.priorReading)
|
|
@@ -23648,7 +23926,7 @@ function pendingVaultQuota(path5, roster) {
|
|
|
23648
23926
|
return roster;
|
|
23649
23927
|
}
|
|
23650
23928
|
function hasPendingVaultQuota(path5) {
|
|
23651
|
-
return !!writers.get(
|
|
23929
|
+
return !!writers.get(resolve10(path5))?.pending.size;
|
|
23652
23930
|
}
|
|
23653
23931
|
function schedule(writer, delay3) {
|
|
23654
23932
|
if (writer.running || writer.timer || !writer.pending.size || writer.abort.signal.aborted)
|
|
@@ -23713,7 +23991,7 @@ function flush(writer) {
|
|
|
23713
23991
|
return writer.running;
|
|
23714
23992
|
}
|
|
23715
23993
|
async function drainVaultQuota(path5, timeoutMs = 1e3) {
|
|
23716
|
-
const key =
|
|
23994
|
+
const key = resolve10(path5);
|
|
23717
23995
|
const writer = writers.get(key);
|
|
23718
23996
|
if (!writer)
|
|
23719
23997
|
return;
|
|
@@ -23861,7 +24139,7 @@ var init_consumer = __esm({
|
|
|
23861
24139
|
this.#shutdown.signal,
|
|
23862
24140
|
...signal ? [signal] : []
|
|
23863
24141
|
]);
|
|
23864
|
-
return new Promise((
|
|
24142
|
+
return new Promise((resolve29, reject) => {
|
|
23865
24143
|
const cleanup2 = () => {
|
|
23866
24144
|
combined.signal.removeEventListener("abort", abort);
|
|
23867
24145
|
combined.dispose();
|
|
@@ -23876,7 +24154,7 @@ var init_consumer = __esm({
|
|
|
23876
24154
|
if (combined.signal.aborted)
|
|
23877
24155
|
reject(combined.signal.reason);
|
|
23878
24156
|
else
|
|
23879
|
-
|
|
24157
|
+
resolve29(value);
|
|
23880
24158
|
}, (error) => {
|
|
23881
24159
|
cleanup2();
|
|
23882
24160
|
reject(error);
|
|
@@ -24621,7 +24899,7 @@ var init_consumer = __esm({
|
|
|
24621
24899
|
import { createHash as createHash8 } from "node:crypto";
|
|
24622
24900
|
import { channel as channel2 } from "node:diagnostics_channel";
|
|
24623
24901
|
import { readdir, stat as stat7 } from "node:fs/promises";
|
|
24624
|
-
import { dirname as dirname10, join as join8, resolve as
|
|
24902
|
+
import { dirname as dirname10, join as join8, resolve as resolve11 } from "node:path";
|
|
24625
24903
|
function canonicalJson3(value, path5 = /* @__PURE__ */ new Set()) {
|
|
24626
24904
|
if (value === null)
|
|
24627
24905
|
return "null";
|
|
@@ -24682,12 +24960,12 @@ function unreachableConnect2() {
|
|
|
24682
24960
|
return new ClaustrumUnreachableError();
|
|
24683
24961
|
}
|
|
24684
24962
|
function untilAborted(pending, signal) {
|
|
24685
|
-
return new Promise((
|
|
24963
|
+
return new Promise((resolve29, reject) => {
|
|
24686
24964
|
const abort = () => reject(signal.reason);
|
|
24687
24965
|
signal.addEventListener("abort", abort, { once: true });
|
|
24688
24966
|
pending.then((value) => {
|
|
24689
24967
|
signal.removeEventListener("abort", abort);
|
|
24690
|
-
|
|
24968
|
+
resolve29(value);
|
|
24691
24969
|
}, (error) => {
|
|
24692
24970
|
signal.removeEventListener("abort", abort);
|
|
24693
24971
|
reject(error);
|
|
@@ -24845,7 +25123,7 @@ var init_hub = __esm({
|
|
|
24845
25123
|
};
|
|
24846
25124
|
const { consumer, hooks } = createHubMember(port, consumerOptions);
|
|
24847
25125
|
entry.hooks = hooks;
|
|
24848
|
-
const path5 =
|
|
25126
|
+
const path5 = resolve11(entry.path);
|
|
24849
25127
|
const subscribers = sharedRosters.get(path5) ?? /* @__PURE__ */ new Set();
|
|
24850
25128
|
const install = (roster) => {
|
|
24851
25129
|
if (entry.closed || this.#active !== true || !this.#current || !this.#live(this.#current) || !hooks.roster() || this.#collides(hooks, roster))
|
|
@@ -24876,7 +25154,7 @@ var init_hub = __esm({
|
|
|
24876
25154
|
return;
|
|
24877
25155
|
entry.seen = JSON.stringify(decodedVaultRoster(roster));
|
|
24878
25156
|
entry.hooks?.install(roster);
|
|
24879
|
-
for (const install of sharedRosters.get(
|
|
25157
|
+
for (const install of sharedRosters.get(resolve11(entry.path)) ?? []) {
|
|
24880
25158
|
if (!this.#live(generation))
|
|
24881
25159
|
return;
|
|
24882
25160
|
if (install !== entry.receiveRoster)
|
|
@@ -25288,7 +25566,7 @@ var init_hub = __esm({
|
|
|
25288
25566
|
const share = {
|
|
25289
25567
|
...inventory,
|
|
25290
25568
|
credentials: inventory.credentials.filter((credential) => credential.member === entry.provider),
|
|
25291
|
-
skipped: inventory.skipped.filter((
|
|
25569
|
+
skipped: inventory.skipped.filter((record4) => record4.member === entry.provider)
|
|
25292
25570
|
};
|
|
25293
25571
|
try {
|
|
25294
25572
|
if (!base)
|
|
@@ -25679,6 +25957,8 @@ __export(claustrum_exports, {
|
|
|
25679
25957
|
reorderVaultRoster: () => reorderVaultRoster,
|
|
25680
25958
|
resetClaustrumEnrollmentState: () => resetClaustrumEnrollmentState,
|
|
25681
25959
|
resolveVaultPrimary: () => resolveVaultPrimary,
|
|
25960
|
+
validEnrollmentDisplayName: () => validEnrollmentDisplayName,
|
|
25961
|
+
validEnrollmentRequestedGrants: () => validEnrollmentRequestedGrants,
|
|
25682
25962
|
vaultAuthority: () => vaultAuthority,
|
|
25683
25963
|
vaultRosterSeed: () => vaultRosterSeed,
|
|
25684
25964
|
vaultRoutingRows: () => vaultRoutingRows
|
|
@@ -25935,7 +26215,7 @@ var init_lock = __esm({
|
|
|
25935
26215
|
import { createHash as createHash9 } from "node:crypto";
|
|
25936
26216
|
import { constants as constants2 } from "node:fs";
|
|
25937
26217
|
import { lstat as lstat5, mkdir as mkdir10, open as open7, unlink as unlink7 } from "node:fs/promises";
|
|
25938
|
-
import { dirname as dirname11, resolve as
|
|
26218
|
+
import { dirname as dirname11, resolve as resolve12 } from "node:path";
|
|
25939
26219
|
import { setTimeout as sleep2 } from "node:timers/promises";
|
|
25940
26220
|
function rootSpans(text2) {
|
|
25941
26221
|
let i = text2.indexOf("{") + 1;
|
|
@@ -26136,8 +26416,8 @@ function createPiSlot(options, onStep, hooks) {
|
|
|
26136
26416
|
if (!provider2 || !options.authPath || !options.stashPath || !placeholderKey || placeholderKey.startsWith("!") || placeholderKey.includes("$") || !Number.isFinite(timeout) || timeout < 0) {
|
|
26137
26417
|
throw new PiSlotError("invalid-options");
|
|
26138
26418
|
}
|
|
26139
|
-
const authPath =
|
|
26140
|
-
const stashPath =
|
|
26419
|
+
const authPath = resolve12(options.authPath);
|
|
26420
|
+
const stashPath = resolve12(options.stashPath);
|
|
26141
26421
|
if (authPath === stashPath || stashPath === `${authPath}.lock`) {
|
|
26142
26422
|
throw new PiSlotError("invalid-options");
|
|
26143
26423
|
}
|
|
@@ -26760,8 +27040,8 @@ function getDefaultTierId(allowedTiers) {
|
|
|
26760
27040
|
return allowedTiers[0]?.id;
|
|
26761
27041
|
}
|
|
26762
27042
|
function wait(ms) {
|
|
26763
|
-
return new Promise((
|
|
26764
|
-
setTimeout(
|
|
27043
|
+
return new Promise((resolve29) => {
|
|
27044
|
+
setTimeout(resolve29, ms);
|
|
26765
27045
|
});
|
|
26766
27046
|
}
|
|
26767
27047
|
function extractManagedProjectId(payload) {
|
|
@@ -27580,7 +27860,7 @@ function applyAgyNativeGenerationConfig(wireModel, generationConfig) {
|
|
|
27580
27860
|
generationConfig.maxOutputTokens = output2;
|
|
27581
27861
|
}
|
|
27582
27862
|
delete generationConfig.max_output_tokens;
|
|
27583
|
-
if (isGeminiArgonModel(wireModel) && native.thinkingLevel !== void 0) {
|
|
27863
|
+
if ((isGeminiArgonModel(wireModel) || isGeminiCarbonModel(wireModel)) && native.thinkingLevel !== void 0) {
|
|
27584
27864
|
generationConfig.thinkingConfig = {
|
|
27585
27865
|
includeThoughts: true,
|
|
27586
27866
|
thinkingLevel: ADAPTIVE_LEVELS[native.thinkingLevel]
|
|
@@ -28339,7 +28619,7 @@ var init_cross_model_sanitizer = __esm({
|
|
|
28339
28619
|
// ../core/dist/transform/model-resolver.js
|
|
28340
28620
|
function supportsThinkingTiers(model) {
|
|
28341
28621
|
const lower = model.toLowerCase();
|
|
28342
|
-
return isGeminiArgonModel(lower) || lower.includes("gemini-3") || lower.includes("gemini-2.5") || lower.includes("claude") && (lower.includes("thinking") || /^claude-(opus|sonnet)-5-5/.test(lower));
|
|
28622
|
+
return isGeminiArgonModel(lower) || isGeminiCarbonModel(lower) || lower.includes("gemini-3") || lower.includes("gemini-2.5") || lower.includes("claude") && (lower.includes("thinking") || /^claude-(opus|sonnet)-5-5/.test(lower));
|
|
28343
28623
|
}
|
|
28344
28624
|
function extractThinkingTierFromModel(model) {
|
|
28345
28625
|
if (!supportsThinkingTiers(model)) {
|
|
@@ -28399,9 +28679,10 @@ function resolveModelWithTier(requestedModel) {
|
|
|
28399
28679
|
const baseName = tier ? modelWithoutQuota.replace(TIER_REGEX, "") : modelWithoutQuota;
|
|
28400
28680
|
const isImageModel = IMAGE_GENERATION_MODELS.test(modelWithoutQuota);
|
|
28401
28681
|
const isArgon = isGeminiArgonModel(modelWithoutQuota);
|
|
28402
|
-
|
|
28682
|
+
const isCarbon = isGeminiCarbonModel(modelWithoutQuota);
|
|
28683
|
+
if (isArgon || isCarbon) {
|
|
28403
28684
|
return {
|
|
28404
|
-
actualModel: getGeminiArgonAntigravityModel(tier),
|
|
28685
|
+
actualModel: isCarbon ? getGeminiCarbonAntigravityModel(tier) : getGeminiArgonAntigravityModel(tier),
|
|
28405
28686
|
thinkingLevel: tier ?? "medium",
|
|
28406
28687
|
tier: tier ?? "medium",
|
|
28407
28688
|
isThinkingModel: true
|
|
@@ -29083,12 +29364,12 @@ var init_vault_provider_state = __esm({
|
|
|
29083
29364
|
function untilAborted2(pending, signal) {
|
|
29084
29365
|
if (!signal)
|
|
29085
29366
|
return pending;
|
|
29086
|
-
return new Promise((
|
|
29367
|
+
return new Promise((resolve29, reject) => {
|
|
29087
29368
|
const abort = () => reject(signal.reason);
|
|
29088
29369
|
signal.addEventListener("abort", abort, { once: true });
|
|
29089
29370
|
if (signal.aborted)
|
|
29090
29371
|
abort();
|
|
29091
|
-
pending.then(
|
|
29372
|
+
pending.then(resolve29, reject).finally(() => signal.removeEventListener("abort", abort));
|
|
29092
29373
|
});
|
|
29093
29374
|
}
|
|
29094
29375
|
async function resolveClaustrumConnectionPath(explicit) {
|
|
@@ -29563,7 +29844,7 @@ var init_capture_sink2 = __esm({
|
|
|
29563
29844
|
import { randomUUID as randomUUID13 } from "node:crypto";
|
|
29564
29845
|
import { lstat as lstat6, readFile as readFile8, rename as rename8, unlink as unlink8 } from "node:fs/promises";
|
|
29565
29846
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
29566
|
-
import { dirname as dirname13, join as join10, resolve as
|
|
29847
|
+
import { dirname as dirname13, join as join10, resolve as resolve13 } from "node:path";
|
|
29567
29848
|
function ioCode2(detail) {
|
|
29568
29849
|
if (detail?.reason === "io-error") {
|
|
29569
29850
|
if (detail.win32Code === 2 || detail.win32Code === 3)
|
|
@@ -29613,7 +29894,7 @@ async function privateOperation2(path5, stage, operation) {
|
|
|
29613
29894
|
}
|
|
29614
29895
|
}
|
|
29615
29896
|
async function verifySafeDirectory2(path5, options) {
|
|
29616
|
-
path5 =
|
|
29897
|
+
path5 = resolve13(path5);
|
|
29617
29898
|
options ??= safeParentOptionsForTest2;
|
|
29618
29899
|
await privateOperation2(path5, "safe-parent", async () => {
|
|
29619
29900
|
const result = await (await loadBackend2()).verifySafeParent(path5, options);
|
|
@@ -29628,7 +29909,7 @@ async function verifySafeDirectory2(path5, options) {
|
|
|
29628
29909
|
});
|
|
29629
29910
|
}
|
|
29630
29911
|
async function verifyPrivate2(path5, kind, migrate = false) {
|
|
29631
|
-
path5 =
|
|
29912
|
+
path5 = resolve13(path5);
|
|
29632
29913
|
if (kind === "directory")
|
|
29633
29914
|
return verifySafeDirectory2(path5);
|
|
29634
29915
|
await privateOperation2(path5, "verify", async () => {
|
|
@@ -29663,7 +29944,7 @@ async function verifyPrivate2(path5, kind, migrate = false) {
|
|
|
29663
29944
|
});
|
|
29664
29945
|
}
|
|
29665
29946
|
async function ensurePrivateDirectory2(path5, _migrate = false, options) {
|
|
29666
|
-
path5 =
|
|
29947
|
+
path5 = resolve13(path5);
|
|
29667
29948
|
await privateOperation2(path5, "directory", async () => {
|
|
29668
29949
|
const api = await loadBackend2();
|
|
29669
29950
|
try {
|
|
@@ -29694,7 +29975,7 @@ async function readPrivateText2(path5, migrate = false) {
|
|
|
29694
29975
|
async function readPrivateBuffer2(path5, migrate = false) {
|
|
29695
29976
|
if (!windowsPrivateFiles2)
|
|
29696
29977
|
return readFile8(path5);
|
|
29697
|
-
path5 =
|
|
29978
|
+
path5 = resolve13(path5);
|
|
29698
29979
|
if (migrate) {
|
|
29699
29980
|
await verifySafeDirectory2(dirname13(path5));
|
|
29700
29981
|
await verifyPrivate2(path5, "file", true);
|
|
@@ -29702,20 +29983,20 @@ async function readPrivateBuffer2(path5, migrate = false) {
|
|
|
29702
29983
|
return privateOperation2(path5, "read", async () => (await loadBackend2()).readOwnerOnly(path5));
|
|
29703
29984
|
}
|
|
29704
29985
|
async function createPrivateBytes2(path5, bytes) {
|
|
29705
|
-
await verifySafeDirectory2(dirname13(
|
|
29986
|
+
await verifySafeDirectory2(dirname13(resolve13(path5)));
|
|
29706
29987
|
await privateOperation2(path5, "create", async () => {
|
|
29707
|
-
await (await loadBackend2()).createPrivateFile(
|
|
29988
|
+
await (await loadBackend2()).createPrivateFile(resolve13(path5), bytes);
|
|
29708
29989
|
});
|
|
29709
29990
|
}
|
|
29710
29991
|
async function createPrivateDirectoryExclusive2(path5) {
|
|
29711
|
-
await verifySafeDirectory2(dirname13(
|
|
29992
|
+
await verifySafeDirectory2(dirname13(resolve13(path5)));
|
|
29712
29993
|
await privateOperation2(path5, "directory-create", async () => {
|
|
29713
|
-
await (await loadBackend2()).createOwnerOnly(
|
|
29994
|
+
await (await loadBackend2()).createOwnerOnly(resolve13(path5), { kind: "dir" });
|
|
29714
29995
|
});
|
|
29715
29996
|
}
|
|
29716
29997
|
async function replaceWindowsFile2(from, to, options = {}) {
|
|
29717
|
-
from =
|
|
29718
|
-
to =
|
|
29998
|
+
from = resolve13(from);
|
|
29999
|
+
to = resolve13(to);
|
|
29719
30000
|
const now = options.now ?? (() => performance.now());
|
|
29720
30001
|
const start = now();
|
|
29721
30002
|
const leaseDeadline = options.deadline ?? Infinity;
|
|
@@ -29758,7 +30039,7 @@ async function replaceWindowsFile2(from, to, options = {}) {
|
|
|
29758
30039
|
throw error;
|
|
29759
30040
|
}
|
|
29760
30041
|
async function writePrivateAtomic2(path5, bytes, options = {}) {
|
|
29761
|
-
path5 =
|
|
30042
|
+
path5 = resolve13(path5);
|
|
29762
30043
|
await ensurePrivateDirectory2(dirname13(path5));
|
|
29763
30044
|
try {
|
|
29764
30045
|
await verifyPrivate2(path5, "file", true);
|
|
@@ -29766,7 +30047,7 @@ async function writePrivateAtomic2(path5, bytes, options = {}) {
|
|
|
29766
30047
|
if (error.code !== "ENOENT")
|
|
29767
30048
|
throw error;
|
|
29768
30049
|
}
|
|
29769
|
-
const stage =
|
|
30050
|
+
const stage = resolve13(options.stagePath ?? `${path5}.${randomUUID13()}.tmp`);
|
|
29770
30051
|
if (dirname13(stage) !== dirname13(path5))
|
|
29771
30052
|
throw new PrivateFileError2(path5, "stage-directory", { code: "EXDEV" });
|
|
29772
30053
|
let created = false;
|
|
@@ -29932,7 +30213,7 @@ var init_redact2 = __esm({
|
|
|
29932
30213
|
// src/common-auth-embedded/logger/engine.js
|
|
29933
30214
|
import { appendFileSync as appendFileSync2, chmodSync as chmodSync2, existsSync as existsSync2, renameSync as renameSync2, statSync as statSync3 } from "node:fs";
|
|
29934
30215
|
import { open as open8 } from "node:fs/promises";
|
|
29935
|
-
import { dirname as dirname14, resolve as
|
|
30216
|
+
import { dirname as dirname14, resolve as resolve14 } from "node:path";
|
|
29936
30217
|
function chmodPrivate2(path5) {
|
|
29937
30218
|
try {
|
|
29938
30219
|
chmodSync2(path5, 384);
|
|
@@ -29983,7 +30264,7 @@ async function openWindowsFile2(sink, file) {
|
|
|
29983
30264
|
return sink.handle;
|
|
29984
30265
|
}
|
|
29985
30266
|
async function flushWindowsFile2(sink, file, text2) {
|
|
29986
|
-
file =
|
|
30267
|
+
file = resolve14(file);
|
|
29987
30268
|
try {
|
|
29988
30269
|
if (sink.file !== file)
|
|
29989
30270
|
await closeWindowsFile2(sink);
|
|
@@ -30587,12 +30868,12 @@ function createVaultAccountPool(options) {
|
|
|
30587
30868
|
try {
|
|
30588
30869
|
return await Promise.race([
|
|
30589
30870
|
read.then(() => true),
|
|
30590
|
-
new Promise((
|
|
30871
|
+
new Promise((resolve29, reject) => {
|
|
30591
30872
|
const abort = () => reject(signal?.reason);
|
|
30592
30873
|
signal?.addEventListener("abort", abort, { once: true });
|
|
30593
30874
|
detachAbort = () => signal?.removeEventListener("abort", abort);
|
|
30594
30875
|
if (remaining !== void 0)
|
|
30595
|
-
cancelTimer2 = schedule2(() =>
|
|
30876
|
+
cancelTimer2 = schedule2(() => resolve29(false), remaining);
|
|
30596
30877
|
if (signal?.aborted) abort();
|
|
30597
30878
|
})
|
|
30598
30879
|
]);
|
|
@@ -31073,6 +31354,9 @@ function createOpenCodeVaultCustody(options) {
|
|
|
31073
31354
|
client,
|
|
31074
31355
|
paths: await enrollmentPaths(),
|
|
31075
31356
|
proposedName: OPENCODE_VAULT_ENROLLMENT_NAME,
|
|
31357
|
+
requestedGrants: [
|
|
31358
|
+
{ selector: { category: "antigravity-native" }, operation: "read" }
|
|
31359
|
+
],
|
|
31076
31360
|
...options.now ? { now: options.now } : {}
|
|
31077
31361
|
});
|
|
31078
31362
|
const current = await manager.status();
|
|
@@ -31094,11 +31378,11 @@ function createOpenCodeVaultCustody(options) {
|
|
|
31094
31378
|
].join("\n");
|
|
31095
31379
|
const waitForApproval = async () => {
|
|
31096
31380
|
while (!closed2) {
|
|
31097
|
-
await new Promise((
|
|
31381
|
+
await new Promise((resolve29) => {
|
|
31098
31382
|
const done = () => {
|
|
31099
31383
|
clearTimeout(timer);
|
|
31100
31384
|
cancelWait = void 0;
|
|
31101
|
-
|
|
31385
|
+
resolve29();
|
|
31102
31386
|
};
|
|
31103
31387
|
const timer = setTimeout(done, 2e3);
|
|
31104
31388
|
timer.unref?.();
|
|
@@ -31498,7 +31782,7 @@ import { randomUUID as randomUUID14 } from "node:crypto";
|
|
|
31498
31782
|
import { realpathSync, rmSync } from "node:fs";
|
|
31499
31783
|
import { chmod as chmod4, mkdir as mkdir12, readFile as readFile10, rename as rename9, rm as rm5, writeFile as writeFile3 } from "node:fs/promises";
|
|
31500
31784
|
import { homedir as homedir2 } from "node:os";
|
|
31501
|
-
import { join as join12, resolve as
|
|
31785
|
+
import { join as join12, resolve as resolve15 } from "node:path";
|
|
31502
31786
|
function processHeartbeatDir() {
|
|
31503
31787
|
const base = process.env.XDG_STATE_HOME || join12(homedir2(), ".local", "state");
|
|
31504
31788
|
return join12(base, "cortexkit", "antigravity-auth", "processes");
|
|
@@ -31511,7 +31795,7 @@ function processConfigFolderKey() {
|
|
|
31511
31795
|
try {
|
|
31512
31796
|
return realpathSync.native(folder);
|
|
31513
31797
|
} catch {
|
|
31514
|
-
return
|
|
31798
|
+
return resolve15(folder);
|
|
31515
31799
|
}
|
|
31516
31800
|
}
|
|
31517
31801
|
function processHasOlderGeneration() {
|
|
@@ -31862,9 +32146,9 @@ function bootTime(options) {
|
|
|
31862
32146
|
return Number.NaN;
|
|
31863
32147
|
}
|
|
31864
32148
|
}
|
|
31865
|
-
async function staleRecord(path5,
|
|
31866
|
-
if (
|
|
31867
|
-
let start = heartbeat ?
|
|
32149
|
+
async function staleRecord(path5, record4, boot, heartbeat) {
|
|
32150
|
+
if (record4.text === void 0 || !Number.isFinite(boot)) return false;
|
|
32151
|
+
let start = heartbeat ? record4.startedAt : void 0;
|
|
31868
32152
|
if (start === void 0) {
|
|
31869
32153
|
try {
|
|
31870
32154
|
start = (await stat10(path5)).mtimeMs;
|
|
@@ -31876,7 +32160,7 @@ async function staleRecord(path5, record3, boot, heartbeat) {
|
|
|
31876
32160
|
return false;
|
|
31877
32161
|
if (heartbeat) {
|
|
31878
32162
|
try {
|
|
31879
|
-
if (await readFile11(path5, "utf8") ===
|
|
32163
|
+
if (await readFile11(path5, "utf8") === record4.text) {
|
|
31880
32164
|
await unlink9(path5);
|
|
31881
32165
|
log5.debug("Removed stale pre-boot heartbeat", { path: path5 });
|
|
31882
32166
|
}
|
|
@@ -32095,7 +32379,7 @@ import {
|
|
|
32095
32379
|
stat as stat11,
|
|
32096
32380
|
unlink as unlink10
|
|
32097
32381
|
} from "node:fs/promises";
|
|
32098
|
-
import { basename as basename4, dirname as dirname15, join as join14, resolve as
|
|
32382
|
+
import { basename as basename4, dirname as dirname15, join as join14, resolve as resolve16 } from "node:path";
|
|
32099
32383
|
function refusalMessage(stateDir, errorClass2) {
|
|
32100
32384
|
if (errorClass2 === "ERR_PRIVATE_FILES_SECURITY")
|
|
32101
32385
|
return `antigravity-auth cannot start: ${stateDir} is not a folder only your user can access, or it is a link, so the plugin will not use it (${errorClass2}). Replace it with a plain folder of your own, then restart OpenCode.`;
|
|
@@ -32955,7 +33239,7 @@ async function removeMovedVaultStateLeftover(vaultDir, accountFile) {
|
|
|
32955
33239
|
if (process.env.OPENCODE_ANTIGRAVITY_AUTH_VAULT_DIR) return;
|
|
32956
33240
|
const location = runtimeLayoutLocation();
|
|
32957
33241
|
const files = layoutFiles(location, accountFile);
|
|
32958
|
-
if (
|
|
33242
|
+
if (resolve16(vaultDir) !== resolve16(files.vault.next)) return;
|
|
32959
33243
|
const stateDir = location.stateHomeDir;
|
|
32960
33244
|
const marker = await readMarker(
|
|
32961
33245
|
join14(stateDir, RUNTIME_LAYOUT_MARKER_FILE),
|
|
@@ -33384,7 +33668,7 @@ import {
|
|
|
33384
33668
|
writeFileSync
|
|
33385
33669
|
} from "node:fs";
|
|
33386
33670
|
import { homedir as homedir4 } from "node:os";
|
|
33387
|
-
import { dirname as dirname16, join as join15, resolve as
|
|
33671
|
+
import { dirname as dirname16, join as join15, resolve as resolve17 } from "node:path";
|
|
33388
33672
|
async function ensureGitignore(configDir) {
|
|
33389
33673
|
const gitignorePath = join15(configDir, ".gitignore");
|
|
33390
33674
|
try {
|
|
@@ -33484,8 +33768,8 @@ function migrateLegacyWindowsConfig() {
|
|
|
33484
33768
|
}
|
|
33485
33769
|
}
|
|
33486
33770
|
function resolveWindowsAccountAnchor(newPath, legacyPath) {
|
|
33487
|
-
const standard =
|
|
33488
|
-
const legacy =
|
|
33771
|
+
const standard = resolve17(newPath);
|
|
33772
|
+
const legacy = resolve17(legacyPath);
|
|
33489
33773
|
if (standard.toLowerCase() === legacy.toLowerCase()) return newPath;
|
|
33490
33774
|
const standardPointer = existsSync3(accountStorePointerPath(standard));
|
|
33491
33775
|
const legacyPointer = existsSync3(accountStorePointerPath(legacy));
|
|
@@ -33507,7 +33791,7 @@ function getStoragePathWithMigration() {
|
|
|
33507
33791
|
"antigravity-accounts.json"
|
|
33508
33792
|
);
|
|
33509
33793
|
const anchored = resolveWindowsAccountAnchor(newPath, legacyPath);
|
|
33510
|
-
if (
|
|
33794
|
+
if (resolve17(anchored).toLowerCase() !== resolve17(newPath).toLowerCase() && !existsSync3(accountStorePointerPath(resolve17(anchored)))) {
|
|
33511
33795
|
log6.info("Using legacy Windows config path (migration failed)", {
|
|
33512
33796
|
legacyPath,
|
|
33513
33797
|
newPath
|
|
@@ -33524,7 +33808,7 @@ function accountFileForVault(configDir = getConfigDir()) {
|
|
|
33524
33808
|
const configured = join15(configDir, "antigravity-accounts.json");
|
|
33525
33809
|
if (process.platform !== "win32") return configured;
|
|
33526
33810
|
const legacyDir = getLegacyWindowsConfigDir();
|
|
33527
|
-
if (
|
|
33811
|
+
if (resolve17(configDir).toLowerCase() === resolve17(legacyDir).toLowerCase())
|
|
33528
33812
|
return configured;
|
|
33529
33813
|
const configuredVault = join15(configDir, "antigravity-auth-vault");
|
|
33530
33814
|
const legacyVault = join15(legacyDir, "antigravity-auth-vault");
|
|
@@ -33555,7 +33839,7 @@ function getStoragePath() {
|
|
|
33555
33839
|
}
|
|
33556
33840
|
async function assertLegacyPoolInUse(legacyPath) {
|
|
33557
33841
|
try {
|
|
33558
|
-
await assertLegacyAccountStorageWritable(
|
|
33842
|
+
await assertLegacyAccountStorageWritable(resolve17(legacyPath));
|
|
33559
33843
|
} catch (error) {
|
|
33560
33844
|
throw new LegacyAccountPoolRetiredError(legacyPath, { cause: error });
|
|
33561
33845
|
}
|
|
@@ -33575,7 +33859,7 @@ function refusalMessage2(admission) {
|
|
|
33575
33859
|
async function bindingOf(options) {
|
|
33576
33860
|
if (options.legacyPath === void 0) await prepareLocalAccountStore();
|
|
33577
33861
|
const now = options.now ?? (() => Date.now());
|
|
33578
|
-
const legacyPath =
|
|
33862
|
+
const legacyPath = resolve17(options.legacyPath ?? getStoragePath());
|
|
33579
33863
|
return {
|
|
33580
33864
|
legacyPath,
|
|
33581
33865
|
now,
|
|
@@ -33644,7 +33928,7 @@ async function openAccountStore(options) {
|
|
|
33644
33928
|
async function initializeFreshAccountStoreFor(modules, options = {}) {
|
|
33645
33929
|
if (options.legacyPath === void 0) await prepareLocalAccountStore();
|
|
33646
33930
|
return initializeFreshAccountStore(modules, {
|
|
33647
|
-
legacyPath:
|
|
33931
|
+
legacyPath: resolve17(options.legacyPath ?? getStoragePath()),
|
|
33648
33932
|
now: options.now ?? (() => Date.now())
|
|
33649
33933
|
});
|
|
33650
33934
|
}
|
|
@@ -33722,12 +34006,12 @@ var init_storage = __esm({
|
|
|
33722
34006
|
import { createHash as createHash12 } from "node:crypto";
|
|
33723
34007
|
import { existsSync as existsSync4, promises as fs2, readFileSync as readFileSync2, realpathSync as realpathSync2 } from "node:fs";
|
|
33724
34008
|
import { homedir as homedir5 } from "node:os";
|
|
33725
|
-
import { dirname as dirname17, join as join16, resolve as
|
|
34009
|
+
import { dirname as dirname17, join as join16, resolve as resolve18 } from "node:path";
|
|
33726
34010
|
function configDirIdentity(path5) {
|
|
33727
34011
|
try {
|
|
33728
34012
|
return realpathSync2.native(path5);
|
|
33729
34013
|
} catch {
|
|
33730
|
-
return
|
|
34014
|
+
return resolve18(path5);
|
|
33731
34015
|
}
|
|
33732
34016
|
}
|
|
33733
34017
|
function decisionKey(location) {
|
|
@@ -33986,9 +34270,9 @@ function redactSensitiveFields(value) {
|
|
|
33986
34270
|
if (value == null) return value;
|
|
33987
34271
|
if (Array.isArray(value)) return value.map(redactSensitiveFields);
|
|
33988
34272
|
if (typeof value === "object") {
|
|
33989
|
-
const
|
|
34273
|
+
const record4 = value;
|
|
33990
34274
|
const redacted = {};
|
|
33991
|
-
for (const [key, entry] of Object.entries(
|
|
34275
|
+
for (const [key, entry] of Object.entries(record4)) {
|
|
33992
34276
|
if (SENSITIVE_FIELD_PATTERN.test(key) && typeof entry === "string") {
|
|
33993
34277
|
redacted[key] = redactSensitive(entry);
|
|
33994
34278
|
} else {
|
|
@@ -34180,13 +34464,13 @@ function closeDebugStream(state) {
|
|
|
34180
34464
|
state.logWriter = () => {
|
|
34181
34465
|
};
|
|
34182
34466
|
if (state.logFilePath) liveLogFilePaths.delete(state.logFilePath);
|
|
34183
|
-
return new Promise((
|
|
34184
|
-
current.once("close", () =>
|
|
34185
|
-
current.once("error", () =>
|
|
34467
|
+
return new Promise((resolve29) => {
|
|
34468
|
+
current.once("close", () => resolve29());
|
|
34469
|
+
current.once("error", () => resolve29());
|
|
34186
34470
|
try {
|
|
34187
34471
|
current.end();
|
|
34188
34472
|
} catch {
|
|
34189
|
-
|
|
34473
|
+
resolve29();
|
|
34190
34474
|
}
|
|
34191
34475
|
});
|
|
34192
34476
|
}
|
|
@@ -34451,13 +34735,13 @@ function closeDebugLog() {
|
|
|
34451
34735
|
if (!state || !current) return Promise.resolve();
|
|
34452
34736
|
state.logStream = null;
|
|
34453
34737
|
if (state.logFilePath) liveLogFilePaths.delete(state.logFilePath);
|
|
34454
|
-
return new Promise((
|
|
34455
|
-
current.once("close", () =>
|
|
34456
|
-
current.once("error", () =>
|
|
34738
|
+
return new Promise((resolve29) => {
|
|
34739
|
+
current.once("close", () => resolve29());
|
|
34740
|
+
current.once("error", () => resolve29());
|
|
34457
34741
|
try {
|
|
34458
34742
|
current.end();
|
|
34459
34743
|
} catch {
|
|
34460
|
-
|
|
34744
|
+
resolve29();
|
|
34461
34745
|
}
|
|
34462
34746
|
});
|
|
34463
34747
|
}
|
|
@@ -34551,10 +34835,10 @@ var init_debug = __esm({
|
|
|
34551
34835
|
// src/plugin/logger.ts
|
|
34552
34836
|
function createLocationLogger(options) {
|
|
34553
34837
|
let configuredLevel = options.level ? LOG_LEVEL_FROM_OPERATOR[options.level] ?? "debug" : "debug";
|
|
34554
|
-
const emit = (
|
|
34555
|
-
if (options.sink && options.sinkEnabled()) {
|
|
34838
|
+
const emit = (record4, alwaysHost = false) => {
|
|
34839
|
+
if (options.sink && (alwaysHost || options.sinkEnabled())) {
|
|
34556
34840
|
try {
|
|
34557
|
-
const pending = options.sink(
|
|
34841
|
+
const pending = options.sink(record4);
|
|
34558
34842
|
if (isThenable(pending)) {
|
|
34559
34843
|
pending.then(void 0, () => {
|
|
34560
34844
|
});
|
|
@@ -34563,34 +34847,41 @@ function createLocationLogger(options) {
|
|
|
34563
34847
|
}
|
|
34564
34848
|
}
|
|
34565
34849
|
if (isConsoleLogEnabled2()) {
|
|
34566
|
-
const prefix = `[${
|
|
34567
|
-
const args =
|
|
34850
|
+
const prefix = `[${record4.service}]`;
|
|
34851
|
+
const args = record4.extra ? [prefix, record4.message, record4.extra] : [prefix, record4.message];
|
|
34568
34852
|
try {
|
|
34569
|
-
writeConsoleLog2(
|
|
34853
|
+
writeConsoleLog2(record4.level, ...args);
|
|
34570
34854
|
} catch {
|
|
34571
34855
|
}
|
|
34572
34856
|
}
|
|
34573
34857
|
};
|
|
34574
|
-
const
|
|
34858
|
+
const createEngine3 = (alwaysHost) => createLoggerInstance2({
|
|
34575
34859
|
level: () => configuredLevel,
|
|
34576
34860
|
extraSecretKeys: isProviderSecretKey,
|
|
34577
34861
|
extraValuePatterns: OAUTH_REDIRECT_VALUE_PATTERNS,
|
|
34578
34862
|
captureSink: ({ channel: channel3, level, message, data }) => {
|
|
34579
34863
|
const extra = data !== null && typeof data === "object" && !Array.isArray(data) ? Object.fromEntries(Object.entries(data)) : void 0;
|
|
34580
|
-
emit(
|
|
34581
|
-
|
|
34582
|
-
|
|
34583
|
-
|
|
34584
|
-
|
|
34585
|
-
|
|
34864
|
+
emit(
|
|
34865
|
+
{
|
|
34866
|
+
service: channel3,
|
|
34867
|
+
level: level === "trace" ? "debug" : level,
|
|
34868
|
+
message,
|
|
34869
|
+
extra
|
|
34870
|
+
},
|
|
34871
|
+
alwaysHost
|
|
34872
|
+
);
|
|
34586
34873
|
}
|
|
34587
34874
|
});
|
|
34875
|
+
const engine = createEngine3(false);
|
|
34876
|
+
const hostEngine = createEngine3(true);
|
|
34588
34877
|
return {
|
|
34589
34878
|
createLogger(module) {
|
|
34590
34879
|
const channel3 = engine.createLogger(`antigravity.${module}`);
|
|
34880
|
+
const hostChannel = hostEngine.createLogger(`antigravity.${module}`);
|
|
34591
34881
|
return {
|
|
34592
34882
|
debug: (message, extra) => channel3.debug(message, extra),
|
|
34593
34883
|
info: (message, extra) => channel3.info(message, extra),
|
|
34884
|
+
hostInfo: (message, extra) => hostChannel.info(message, extra),
|
|
34594
34885
|
warn: (message, extra) => channel3.warn(message, extra),
|
|
34595
34886
|
error: (message, extra) => channel3.error(message, extra)
|
|
34596
34887
|
};
|
|
@@ -34604,10 +34895,10 @@ function createLocationLogger(options) {
|
|
|
34604
34895
|
};
|
|
34605
34896
|
}
|
|
34606
34897
|
function createAppLogSink(client) {
|
|
34607
|
-
return (
|
|
34898
|
+
return (record4) => {
|
|
34608
34899
|
const app = client.app;
|
|
34609
34900
|
if (app && typeof app.log === "function") {
|
|
34610
|
-
return app.log({ body:
|
|
34901
|
+
return app.log({ body: record4 });
|
|
34611
34902
|
}
|
|
34612
34903
|
return void 0;
|
|
34613
34904
|
};
|
|
@@ -34620,7 +34911,7 @@ function isConsoleLogEnabled2() {
|
|
|
34620
34911
|
}
|
|
34621
34912
|
function getLegacyLogger() {
|
|
34622
34913
|
legacyLogger ??= createLocationLogger({
|
|
34623
|
-
sink: (
|
|
34914
|
+
sink: (record4) => legacyClient ? createAppLogSink(legacyClient)(record4) : void 0,
|
|
34624
34915
|
sinkEnabled: isDebugTuiEnabled
|
|
34625
34916
|
});
|
|
34626
34917
|
return legacyLogger;
|
|
@@ -34641,6 +34932,10 @@ function createLogger4(module) {
|
|
|
34641
34932
|
return {
|
|
34642
34933
|
debug: (message, extra) => log17("debug", message, extra),
|
|
34643
34934
|
info: (message, extra) => log17("info", message, extra),
|
|
34935
|
+
hostInfo: (message, extra) => {
|
|
34936
|
+
channel3 ??= getLegacyLogger().createLogger(module);
|
|
34937
|
+
channel3.hostInfo?.(message, extra);
|
|
34938
|
+
},
|
|
34644
34939
|
warn: (message, extra) => log17("warn", message, extra),
|
|
34645
34940
|
error: (message, extra) => log17("error", message, extra)
|
|
34646
34941
|
};
|
|
@@ -34668,14 +34963,14 @@ var init_logger4 = __esm({
|
|
|
34668
34963
|
|
|
34669
34964
|
// src/plugin/index.ts
|
|
34670
34965
|
init_dist();
|
|
34671
|
-
import { createHash as createHash24, randomUUID as
|
|
34672
|
-
import { join as join39, resolve as
|
|
34966
|
+
import { createHash as createHash24, randomUUID as randomUUID22 } from "node:crypto";
|
|
34967
|
+
import { join as join39, resolve as resolve28 } from "node:path";
|
|
34673
34968
|
|
|
34674
34969
|
// src/cli.ts
|
|
34675
34970
|
init_dist();
|
|
34676
34971
|
import { execFile } from "node:child_process";
|
|
34677
34972
|
import { realpathSync as realpathSync4 } from "node:fs";
|
|
34678
|
-
import { resolve as
|
|
34973
|
+
import { resolve as resolve23 } from "node:path";
|
|
34679
34974
|
import { createInterface } from "node:readline/promises";
|
|
34680
34975
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
34681
34976
|
import { promisify } from "node:util";
|
|
@@ -35008,17 +35303,17 @@ function normalizeSidebarState(input2) {
|
|
|
35008
35303
|
if (!isObject(input2)) {
|
|
35009
35304
|
return { ...DEFAULT_SIDEBAR_STATE, lastError: "shape" };
|
|
35010
35305
|
}
|
|
35011
|
-
const
|
|
35012
|
-
const version =
|
|
35306
|
+
const record4 = input2;
|
|
35307
|
+
const version = record4.version;
|
|
35013
35308
|
if (version !== 1 && version !== SIDEBAR_STATE_VERSION) {
|
|
35014
35309
|
return {
|
|
35015
35310
|
...DEFAULT_SIDEBAR_STATE,
|
|
35016
35311
|
lastError: `unsupported-version:${stringifySafe(version)}`
|
|
35017
35312
|
};
|
|
35018
35313
|
}
|
|
35019
|
-
const accountsRaw =
|
|
35314
|
+
const accountsRaw = record4.accounts;
|
|
35020
35315
|
const accounts = Array.isArray(accountsRaw) ? accountsRaw.map((entry) => normalizeAccount(entry)).filter((entry) => entry !== null) : [];
|
|
35021
|
-
const routingRaw =
|
|
35316
|
+
const routingRaw = record4.activeRouting;
|
|
35022
35317
|
const activeRouting = {};
|
|
35023
35318
|
if (isObject(routingRaw)) {
|
|
35024
35319
|
for (const [sessionId, entry] of Object.entries(
|
|
@@ -35028,10 +35323,10 @@ function normalizeSidebarState(input2) {
|
|
|
35028
35323
|
if (normalized) activeRouting[sessionId] = normalized;
|
|
35029
35324
|
}
|
|
35030
35325
|
}
|
|
35031
|
-
const checkedAt = toFiniteNumber(
|
|
35032
|
-
const routingAuthoritative =
|
|
35033
|
-
const quotaBackoffUntil = toFiniteNumber(
|
|
35034
|
-
const lastError = typeof
|
|
35326
|
+
const checkedAt = toFiniteNumber(record4.checkedAt);
|
|
35327
|
+
const routingAuthoritative = record4.routingAuthoritative === true;
|
|
35328
|
+
const quotaBackoffUntil = toFiniteNumber(record4.quotaBackoffUntil);
|
|
35329
|
+
const lastError = typeof record4.lastError === "string" ? record4.lastError : void 0;
|
|
35035
35330
|
return {
|
|
35036
35331
|
version: SIDEBAR_STATE_VERSION,
|
|
35037
35332
|
checkedAt: checkedAt ?? 0,
|
|
@@ -35044,15 +35339,15 @@ function normalizeSidebarState(input2) {
|
|
|
35044
35339
|
}
|
|
35045
35340
|
function normalizeAccount(input2) {
|
|
35046
35341
|
if (!isObject(input2)) return null;
|
|
35047
|
-
const
|
|
35048
|
-
const id = typeof
|
|
35049
|
-
const label = typeof
|
|
35342
|
+
const record4 = input2;
|
|
35343
|
+
const id = typeof record4.id === "string" ? record4.id : null;
|
|
35344
|
+
const label = typeof record4.label === "string" ? record4.label : null;
|
|
35050
35345
|
if (!id || !label) return null;
|
|
35051
|
-
const enabled =
|
|
35052
|
-
const health = clampNumber(toFiniteNumber(
|
|
35053
|
-
const current =
|
|
35054
|
-
const cooldownUntil = toFiniteNumber(
|
|
35055
|
-
const quotaRaw =
|
|
35346
|
+
const enabled = record4.enabled !== false;
|
|
35347
|
+
const health = clampNumber(toFiniteNumber(record4.health), 0, 100);
|
|
35348
|
+
const current = record4.current === true;
|
|
35349
|
+
const cooldownUntil = toFiniteNumber(record4.cooldownUntil) ?? void 0;
|
|
35350
|
+
const quotaRaw = record4.quota;
|
|
35056
35351
|
const quota = {};
|
|
35057
35352
|
if (isObject(quotaRaw)) {
|
|
35058
35353
|
for (const key of ["gemini", "non-gemini", "gemini-argon"]) {
|
|
@@ -35061,11 +35356,11 @@ function normalizeAccount(input2) {
|
|
|
35061
35356
|
if (normalized) quota[key] = normalized;
|
|
35062
35357
|
}
|
|
35063
35358
|
}
|
|
35064
|
-
const tier = normalizeTier(
|
|
35359
|
+
const tier = normalizeTier(record4.tier);
|
|
35065
35360
|
return {
|
|
35066
35361
|
id,
|
|
35067
35362
|
label,
|
|
35068
|
-
...typeof
|
|
35363
|
+
...typeof record4.email === "string" ? { email: record4.email } : {},
|
|
35069
35364
|
enabled,
|
|
35070
35365
|
health,
|
|
35071
35366
|
current,
|
|
@@ -35076,22 +35371,22 @@ function normalizeAccount(input2) {
|
|
|
35076
35371
|
}
|
|
35077
35372
|
function normalizeTier(input2) {
|
|
35078
35373
|
if (!isObject(input2)) return void 0;
|
|
35079
|
-
const
|
|
35080
|
-
const id = typeof
|
|
35081
|
-
const capturedAt = toFiniteNumber(
|
|
35374
|
+
const record4 = input2;
|
|
35375
|
+
const id = typeof record4.id === "string" && record4.id.length > 0 ? record4.id : null;
|
|
35376
|
+
const capturedAt = toFiniteNumber(record4.capturedAt);
|
|
35082
35377
|
if (!id || capturedAt === null) return void 0;
|
|
35083
|
-
const paidId = typeof
|
|
35378
|
+
const paidId = typeof record4.paidId === "string" && record4.paidId.length > 0 ? record4.paidId : void 0;
|
|
35084
35379
|
return { id, ...paidId ? { paidId } : {}, capturedAt };
|
|
35085
35380
|
}
|
|
35086
35381
|
function normalizeQuota(input2) {
|
|
35087
35382
|
if (!isObject(input2)) return null;
|
|
35088
|
-
const
|
|
35089
|
-
const remaining = toFiniteNumber(
|
|
35090
|
-
const fraction = toFiniteNumber(
|
|
35383
|
+
const record4 = input2;
|
|
35384
|
+
const remaining = toFiniteNumber(record4.remainingPercent);
|
|
35385
|
+
const fraction = toFiniteNumber(record4.remainingFraction);
|
|
35091
35386
|
if (remaining === null) return null;
|
|
35092
|
-
const resetAt = toFiniteNumber(
|
|
35093
|
-
const checkedAt = toFiniteNumber(
|
|
35094
|
-
const windowsRaw =
|
|
35387
|
+
const resetAt = toFiniteNumber(record4.resetAt) ?? void 0;
|
|
35388
|
+
const checkedAt = toFiniteNumber(record4.checkedAt) ?? void 0;
|
|
35389
|
+
const windowsRaw = record4.windows;
|
|
35095
35390
|
let windows2;
|
|
35096
35391
|
if (Array.isArray(windowsRaw)) {
|
|
35097
35392
|
const parsed = windowsRaw.filter(isObject).map((w) => {
|
|
@@ -35123,12 +35418,12 @@ function normalizeQuota(input2) {
|
|
|
35123
35418
|
}
|
|
35124
35419
|
function normalizeRouting(input2) {
|
|
35125
35420
|
if (!isObject(input2)) return null;
|
|
35126
|
-
const
|
|
35127
|
-
const accountId = typeof
|
|
35128
|
-
const modelFamily =
|
|
35129
|
-
const headerStyle =
|
|
35130
|
-
const strategy =
|
|
35131
|
-
const updatedAt = toFiniteNumber(
|
|
35421
|
+
const record4 = input2;
|
|
35422
|
+
const accountId = typeof record4.accountId === "string" ? record4.accountId : null;
|
|
35423
|
+
const modelFamily = record4.modelFamily;
|
|
35424
|
+
const headerStyle = record4.headerStyle;
|
|
35425
|
+
const strategy = record4.strategy;
|
|
35426
|
+
const updatedAt = toFiniteNumber(record4.updatedAt) ?? 0;
|
|
35132
35427
|
if (!accountId || modelFamily !== "claude" && modelFamily !== "gemini" || headerStyle !== "antigravity" && headerStyle !== "gemini-cli") {
|
|
35133
35428
|
return null;
|
|
35134
35429
|
}
|
|
@@ -35326,7 +35621,7 @@ function drainSidebarWrites() {
|
|
|
35326
35621
|
return sidebarWriteChain;
|
|
35327
35622
|
}
|
|
35328
35623
|
async function sleep3(ms) {
|
|
35329
|
-
await new Promise((
|
|
35624
|
+
await new Promise((resolve29) => setTimeout(resolve29, ms));
|
|
35330
35625
|
}
|
|
35331
35626
|
async function acquireSidebarLockWithRetry(stateFile) {
|
|
35332
35627
|
const start = Date.now();
|
|
@@ -36178,14 +36473,14 @@ var LocalQuotaGrantStaleError = class extends Error {
|
|
|
36178
36473
|
name = "LocalQuotaGrantStaleError";
|
|
36179
36474
|
};
|
|
36180
36475
|
function untilQuotaAborted(pending, signal) {
|
|
36181
|
-
return new Promise((
|
|
36476
|
+
return new Promise((resolve29, reject) => {
|
|
36182
36477
|
const abort = () => reject(signal.reason);
|
|
36183
36478
|
if (signal.aborted) abort();
|
|
36184
36479
|
else signal.addEventListener("abort", abort, { once: true });
|
|
36185
36480
|
void pending.then(
|
|
36186
36481
|
(value) => {
|
|
36187
36482
|
signal.removeEventListener("abort", abort);
|
|
36188
|
-
|
|
36483
|
+
resolve29(value);
|
|
36189
36484
|
},
|
|
36190
36485
|
(error) => {
|
|
36191
36486
|
signal.removeEventListener("abort", abort);
|
|
@@ -36635,7 +36930,7 @@ function createStoreQuotaService(options) {
|
|
|
36635
36930
|
fetchTimeoutMs: options.fetchTimeoutMs,
|
|
36636
36931
|
sidebar: options.sidebar
|
|
36637
36932
|
});
|
|
36638
|
-
const
|
|
36933
|
+
const record4 = async (target, result) => {
|
|
36639
36934
|
if (result.status !== "ok" || result.quota === void 0) {
|
|
36640
36935
|
return { status: "failed", result };
|
|
36641
36936
|
}
|
|
@@ -36669,7 +36964,7 @@ function createStoreQuotaService(options) {
|
|
|
36669
36964
|
index,
|
|
36670
36965
|
force: refreshOptions.force === true
|
|
36671
36966
|
});
|
|
36672
|
-
return
|
|
36967
|
+
return record4(target, result);
|
|
36673
36968
|
};
|
|
36674
36969
|
return {
|
|
36675
36970
|
quotaManager,
|
|
@@ -36723,7 +37018,7 @@ function createStoreQuotaService(options) {
|
|
|
36723
37018
|
return Promise.all(
|
|
36724
37019
|
results.map((result, position) => {
|
|
36725
37020
|
const target = targets[position];
|
|
36726
|
-
return target === void 0 ? { status: "failed", result } :
|
|
37021
|
+
return target === void 0 ? { status: "failed", result } : record4(target, result);
|
|
36727
37022
|
})
|
|
36728
37023
|
);
|
|
36729
37024
|
},
|
|
@@ -36806,12 +37101,12 @@ async function startOAuthListener({
|
|
|
36806
37101
|
let resolveCallback;
|
|
36807
37102
|
let rejectCallback;
|
|
36808
37103
|
let timeoutHandle;
|
|
36809
|
-
const callbackPromise = new Promise((
|
|
37104
|
+
const callbackPromise = new Promise((resolve29, reject) => {
|
|
36810
37105
|
resolveCallback = (url) => {
|
|
36811
37106
|
if (settled) return;
|
|
36812
37107
|
settled = true;
|
|
36813
37108
|
if (timeoutHandle) clearTimeout(timeoutHandle);
|
|
36814
|
-
|
|
37109
|
+
resolve29(url);
|
|
36815
37110
|
};
|
|
36816
37111
|
rejectCallback = (error) => {
|
|
36817
37112
|
if (settled) return;
|
|
@@ -36970,7 +37265,7 @@ async function startOAuthListener({
|
|
|
36970
37265
|
});
|
|
36971
37266
|
});
|
|
36972
37267
|
const bindAddress = getBindAddress();
|
|
36973
|
-
await new Promise((
|
|
37268
|
+
await new Promise((resolve29, reject) => {
|
|
36974
37269
|
const handleError = (error) => {
|
|
36975
37270
|
server.off("error", handleError);
|
|
36976
37271
|
if (error.code === "EADDRINUSE") {
|
|
@@ -36986,7 +37281,7 @@ async function startOAuthListener({
|
|
|
36986
37281
|
server.once("error", handleError);
|
|
36987
37282
|
server.listen(port, bindAddress, () => {
|
|
36988
37283
|
server.off("error", handleError);
|
|
36989
|
-
|
|
37284
|
+
resolve29();
|
|
36990
37285
|
});
|
|
36991
37286
|
});
|
|
36992
37287
|
server.on("error", (error) => {
|
|
@@ -36994,7 +37289,7 @@ async function startOAuthListener({
|
|
|
36994
37289
|
});
|
|
36995
37290
|
return {
|
|
36996
37291
|
waitForCallback: () => callbackPromise,
|
|
36997
|
-
close: () => new Promise((
|
|
37292
|
+
close: () => new Promise((resolve29, reject) => {
|
|
36998
37293
|
server.close((error) => {
|
|
36999
37294
|
if (error && error.code !== "ERR_SERVER_NOT_RUNNING") {
|
|
37000
37295
|
reject(error);
|
|
@@ -37003,7 +37298,7 @@ async function startOAuthListener({
|
|
|
37003
37298
|
if (!settled) {
|
|
37004
37299
|
rejectCallback(new Error("OAuth listener closed before callback"));
|
|
37005
37300
|
}
|
|
37006
|
-
|
|
37301
|
+
resolve29();
|
|
37007
37302
|
});
|
|
37008
37303
|
})
|
|
37009
37304
|
};
|
|
@@ -37022,7 +37317,7 @@ init_runtime_paths();
|
|
|
37022
37317
|
// src/setup.ts
|
|
37023
37318
|
init_dist();
|
|
37024
37319
|
import { lstat as lstat9, readFile as readFile16 } from "node:fs/promises";
|
|
37025
|
-
import { join as join24, resolve as
|
|
37320
|
+
import { join as join24, resolve as resolve22 } from "node:path";
|
|
37026
37321
|
|
|
37027
37322
|
// src/auth-method-labels.ts
|
|
37028
37323
|
var OPENCODE2_POOL_AUTH_LABEL = "Google (antigravity-auth pool, browser)";
|
|
@@ -37195,7 +37490,7 @@ async function select2(terminal, items, options) {
|
|
|
37195
37490
|
writeLine("");
|
|
37196
37491
|
renderedLines = lines;
|
|
37197
37492
|
};
|
|
37198
|
-
return new Promise((
|
|
37493
|
+
return new Promise((resolve29) => {
|
|
37199
37494
|
const wasRaw = stdin.isRaw ?? false;
|
|
37200
37495
|
const cleanup2 = () => {
|
|
37201
37496
|
if (cleaned)
|
|
@@ -37215,7 +37510,7 @@ async function select2(terminal, items, options) {
|
|
|
37215
37510
|
};
|
|
37216
37511
|
const finish = (value) => {
|
|
37217
37512
|
cleanup2();
|
|
37218
|
-
|
|
37513
|
+
resolve29(value);
|
|
37219
37514
|
};
|
|
37220
37515
|
const onSignal = () => finish(null);
|
|
37221
37516
|
const onKey = (data) => {
|
|
@@ -37255,7 +37550,7 @@ async function select2(terminal, items, options) {
|
|
|
37255
37550
|
stdin.setRawMode(true);
|
|
37256
37551
|
} catch {
|
|
37257
37552
|
cleanup2();
|
|
37258
|
-
|
|
37553
|
+
resolve29(null);
|
|
37259
37554
|
return;
|
|
37260
37555
|
}
|
|
37261
37556
|
stdin.resume();
|
|
@@ -37269,12 +37564,12 @@ async function select2(terminal, items, options) {
|
|
|
37269
37564
|
import { createHash as createHash13, randomBytes as randomBytes5, randomUUID as randomUUID17 } from "node:crypto";
|
|
37270
37565
|
import { constants as fsConstants2 } from "node:fs";
|
|
37271
37566
|
import { chmod as chmod6, mkdir as mkdir15, open as open10, readFile as readFile14, realpath as realpath4, rename as rename12, stat as stat14, unlink as unlink11 } from "node:fs/promises";
|
|
37272
|
-
import { basename as basename5, dirname as dirname20, extname as extname2, isAbsolute as isAbsolute4, join as join20, resolve as
|
|
37567
|
+
import { basename as basename5, dirname as dirname20, extname as extname2, isAbsolute as isAbsolute4, join as join20, resolve as resolve21 } from "node:path";
|
|
37273
37568
|
import { ClaustrumCredentialError as ClaustrumCredentialError9, ClaustrumClient as ClaustrumWireClient2, writeEnrollmentTokenFile as writeEnrollmentTokenFile2 } from "@cortexkit/claustrum-client";
|
|
37274
37569
|
|
|
37275
37570
|
// src/common-auth-embedded/fs/file-read-cache.js
|
|
37276
37571
|
import { lstat as lstat7, stat as stat12 } from "node:fs/promises";
|
|
37277
|
-
import { resolve as
|
|
37572
|
+
import { resolve as resolve19 } from "node:path";
|
|
37278
37573
|
async function identity2(path5, followSymlinks) {
|
|
37279
37574
|
try {
|
|
37280
37575
|
const metadata = await (followSymlinks ? stat12(path5) : lstat7(path5));
|
|
@@ -37295,7 +37590,7 @@ var FileReadCache2 = class {
|
|
|
37295
37590
|
this.#followSymlinks = options.followSymlinks ?? false;
|
|
37296
37591
|
}
|
|
37297
37592
|
async read(paths, read, validateHit) {
|
|
37298
|
-
const resolvedPaths = paths.map((path5) =>
|
|
37593
|
+
const resolvedPaths = paths.map((path5) => resolve19(path5));
|
|
37299
37594
|
const key = JSON.stringify(resolvedPaths);
|
|
37300
37595
|
const probed = await Promise.all(resolvedPaths.map((path5) => identity2(path5, this.#followSymlinks)));
|
|
37301
37596
|
const identities = probed.every((entry) => entry !== void 0) ? probed : void 0;
|
|
@@ -37344,11 +37639,46 @@ var WRITER_LOCK_CONSTANTS2 = Object.freeze({
|
|
|
37344
37639
|
init_private_files2();
|
|
37345
37640
|
|
|
37346
37641
|
// src/common-auth-embedded/fs/refresh-file-lock.js
|
|
37347
|
-
init_private_files2();
|
|
37348
37642
|
import { randomUUID as randomUUID16 } from "node:crypto";
|
|
37349
37643
|
import { link as link3, lstat as lstat8, mkdir as mkdir14, open as open9, readFile as readFile13, rename as rename11, rm as rm6, stat as stat13 } from "node:fs/promises";
|
|
37350
37644
|
import { dirname as dirname19, join as join19 } from "node:path";
|
|
37351
37645
|
|
|
37646
|
+
// src/common-auth-embedded/fs/lock-record.js
|
|
37647
|
+
init_private_files2();
|
|
37648
|
+
import { resolve as resolve20 } from "node:path";
|
|
37649
|
+
var DisappearedLockRecordError2 = class extends Error {
|
|
37650
|
+
path;
|
|
37651
|
+
code = "ENOENT";
|
|
37652
|
+
constructor(path5, cause) {
|
|
37653
|
+
super(`Lock record disappeared: ${path5}`, { cause });
|
|
37654
|
+
this.path = path5;
|
|
37655
|
+
}
|
|
37656
|
+
};
|
|
37657
|
+
function isWindowsAccessDeniedRead2(error, paths) {
|
|
37658
|
+
return error instanceof PrivateFileError2 && error.reason === "io-error" && error.win32Code === 5 && (error.stage === "read" || error.stage === "verify") && paths.some((path5) => resolve20(path5) === error.path);
|
|
37659
|
+
}
|
|
37660
|
+
function isWindowsAccessDeniedCreate2(error, paths, stage) {
|
|
37661
|
+
return error instanceof PrivateFileError2 && error.reason === "io-error" && error.win32Code === 5 && error.stage === stage && paths.some((path5) => resolve20(path5) === error.path);
|
|
37662
|
+
}
|
|
37663
|
+
async function readLockRecord2(path5, read) {
|
|
37664
|
+
try {
|
|
37665
|
+
return await read();
|
|
37666
|
+
} catch (error) {
|
|
37667
|
+
if (!isWindowsAccessDeniedRead2(error, [path5]))
|
|
37668
|
+
throw error;
|
|
37669
|
+
try {
|
|
37670
|
+
return await read();
|
|
37671
|
+
} catch (recheckError) {
|
|
37672
|
+
if (recheckError.code === "ENOENT")
|
|
37673
|
+
throw new DisappearedLockRecordError2(path5, error);
|
|
37674
|
+
throw error;
|
|
37675
|
+
}
|
|
37676
|
+
}
|
|
37677
|
+
}
|
|
37678
|
+
|
|
37679
|
+
// src/common-auth-embedded/fs/refresh-file-lock.js
|
|
37680
|
+
init_private_files2();
|
|
37681
|
+
|
|
37352
37682
|
// src/common-auth-embedded/fs/with-lock.js
|
|
37353
37683
|
init_private_files2();
|
|
37354
37684
|
function lockPathFor2(target, name) {
|
|
@@ -37447,8 +37777,8 @@ async function acquireRefreshFileLockWithClock2(options) {
|
|
|
37447
37777
|
let releaseConfirmed = false;
|
|
37448
37778
|
let loss;
|
|
37449
37779
|
let resolveLoss;
|
|
37450
|
-
const lostPromise = new Promise((
|
|
37451
|
-
resolveLoss =
|
|
37780
|
+
const lostPromise = new Promise((resolve29) => {
|
|
37781
|
+
resolveLoss = resolve29;
|
|
37452
37782
|
});
|
|
37453
37783
|
function notifyTimerStep(event) {
|
|
37454
37784
|
try {
|
|
@@ -37486,15 +37816,18 @@ async function acquireRefreshFileLockWithClock2(options) {
|
|
|
37486
37816
|
const evictOwnerId = randomUUID16();
|
|
37487
37817
|
const EVICT_TTL = 5e3;
|
|
37488
37818
|
const MAX_STEAL_ATTEMPTS = 8;
|
|
37819
|
+
function isChangingLockCreate(error) {
|
|
37820
|
+
return windowsPrivateFiles2 && (isWindowsAccessDeniedCreate2(error, [lockPath], "create") || isWindowsAccessDeniedCreate2(error, [evictPath], "directory-create"));
|
|
37821
|
+
}
|
|
37489
37822
|
async function readOwner() {
|
|
37490
37823
|
if (windowsPrivateFiles2) {
|
|
37491
37824
|
try {
|
|
37492
|
-
return JSON.parse(await readPrivateText2(lockPath, true));
|
|
37825
|
+
return JSON.parse(await readLockRecord2(lockPath, () => readPrivateText2(lockPath, true)));
|
|
37493
37826
|
} catch (error) {
|
|
37494
37827
|
if (error.code !== "EISDIR" && error.reason !== "wrong-kind")
|
|
37495
37828
|
throw error;
|
|
37496
|
-
await verifyPrivate2(lockPath, "directory", true);
|
|
37497
|
-
return JSON.parse(await readPrivateText2(legacyOwnerPath, true));
|
|
37829
|
+
await readLockRecord2(lockPath, () => verifyPrivate2(lockPath, "directory", true));
|
|
37830
|
+
return JSON.parse(await readLockRecord2(legacyOwnerPath, () => readPrivateText2(legacyOwnerPath, true)));
|
|
37498
37831
|
}
|
|
37499
37832
|
}
|
|
37500
37833
|
try {
|
|
@@ -37570,8 +37903,8 @@ async function acquireRefreshFileLockWithClock2(options) {
|
|
|
37570
37903
|
await options.onStep("lease-contention-read-ready");
|
|
37571
37904
|
try {
|
|
37572
37905
|
if (code2 === "EISDIR") {
|
|
37573
|
-
await verifyPrivate2(lockPath, "directory", true);
|
|
37574
|
-
await readPrivateText2(legacyOwnerPath, true);
|
|
37906
|
+
await readLockRecord2(lockPath, () => verifyPrivate2(lockPath, "directory", true));
|
|
37907
|
+
await readLockRecord2(legacyOwnerPath, () => readPrivateText2(legacyOwnerPath, true));
|
|
37575
37908
|
} else
|
|
37576
37909
|
await readOwner();
|
|
37577
37910
|
} catch (readError) {
|
|
@@ -37609,7 +37942,7 @@ async function acquireRefreshFileLockWithClock2(options) {
|
|
|
37609
37942
|
}
|
|
37610
37943
|
}
|
|
37611
37944
|
async function backoff() {
|
|
37612
|
-
await new Promise((
|
|
37945
|
+
await new Promise((resolve29) => setTimeout(resolve29, Math.floor(Math.random() * 4)));
|
|
37613
37946
|
}
|
|
37614
37947
|
async function readLockState(notifyReady = true) {
|
|
37615
37948
|
if (notifyReady && options.onStep)
|
|
@@ -37618,6 +37951,8 @@ async function acquireRefreshFileLockWithClock2(options) {
|
|
|
37618
37951
|
try {
|
|
37619
37952
|
owner = await readOwner();
|
|
37620
37953
|
} catch (error) {
|
|
37954
|
+
if (error instanceof DisappearedLockRecordError2)
|
|
37955
|
+
return { status: "missing" };
|
|
37621
37956
|
if (windowsPrivateFiles2 && error.code !== "ENOENT")
|
|
37622
37957
|
throw error;
|
|
37623
37958
|
}
|
|
@@ -37665,7 +38000,7 @@ async function acquireRefreshFileLockWithClock2(options) {
|
|
|
37665
38000
|
}
|
|
37666
38001
|
async function ownsEvictionMarker() {
|
|
37667
38002
|
try {
|
|
37668
|
-
const owner = JSON.parse(await readPrivateText2(evictOwnerPath, windowsPrivateFiles2));
|
|
38003
|
+
const owner = JSON.parse(await readLockRecord2(evictOwnerPath, () => readPrivateText2(evictOwnerPath, windowsPrivateFiles2)));
|
|
37669
38004
|
return owner?.ownerId === evictOwnerId;
|
|
37670
38005
|
} catch (error) {
|
|
37671
38006
|
if (windowsPrivateFiles2 && error.code !== "ENOENT")
|
|
@@ -37700,7 +38035,7 @@ async function acquireRefreshFileLockWithClock2(options) {
|
|
|
37700
38035
|
const remainingMs = deadline - performance.now();
|
|
37701
38036
|
if (remainingMs <= 0)
|
|
37702
38037
|
throw original;
|
|
37703
|
-
await new Promise((
|
|
38038
|
+
await new Promise((resolve29) => setTimeout(resolve29, Math.min(delayMs, remainingMs)));
|
|
37704
38039
|
if (performance.now() >= deadline)
|
|
37705
38040
|
throw original;
|
|
37706
38041
|
delayMs = Math.min(delayMs * 2, 50);
|
|
@@ -37804,7 +38139,7 @@ async function acquireRefreshFileLockWithClock2(options) {
|
|
|
37804
38139
|
}
|
|
37805
38140
|
if (windowsPrivateFiles2) {
|
|
37806
38141
|
try {
|
|
37807
|
-
await verifyPrivate2(evictPath, "directory", true);
|
|
38142
|
+
await readLockRecord2(evictPath, () => verifyPrivate2(evictPath, "directory", true));
|
|
37808
38143
|
} catch (error) {
|
|
37809
38144
|
if (error.code === "ENOENT")
|
|
37810
38145
|
return "missing";
|
|
@@ -37859,8 +38194,8 @@ async function acquireRefreshFileLockWithClock2(options) {
|
|
|
37859
38194
|
if (error.code === "EEXIST") {
|
|
37860
38195
|
if (windowsPrivateFiles2) {
|
|
37861
38196
|
try {
|
|
37862
|
-
await verifyPrivate2(evictPath, "directory", true);
|
|
37863
|
-
await readPrivateText2(evictOwnerPath, true);
|
|
38197
|
+
await readLockRecord2(evictPath, () => verifyPrivate2(evictPath, "directory", true));
|
|
38198
|
+
await readLockRecord2(evictOwnerPath, () => readPrivateText2(evictOwnerPath, true));
|
|
37864
38199
|
} catch (ownerError) {
|
|
37865
38200
|
if (ownerError.code !== "ENOENT")
|
|
37866
38201
|
throw ownerError;
|
|
@@ -37881,7 +38216,11 @@ async function acquireRefreshFileLockWithClock2(options) {
|
|
|
37881
38216
|
try {
|
|
37882
38217
|
await releaseEvictionMarker(deadline);
|
|
37883
38218
|
} catch (error) {
|
|
37884
|
-
if (isRetryableRemoval(actionError, lockPath)
|
|
38219
|
+
if ((isRetryableRemoval(actionError, lockPath) || isWindowsAccessDeniedRead2(actionError, [
|
|
38220
|
+
lockPath,
|
|
38221
|
+
legacyOwnerPath,
|
|
38222
|
+
evictOwnerPath
|
|
38223
|
+
])) && (isRetryableRemoval(error, evictPath) || isWindowsAccessDeniedRead2(error, [evictOwnerPath])))
|
|
37885
38224
|
throw actionError;
|
|
37886
38225
|
throw error;
|
|
37887
38226
|
}
|
|
@@ -37897,7 +38236,7 @@ async function acquireRefreshFileLockWithClock2(options) {
|
|
|
37897
38236
|
try {
|
|
37898
38237
|
owner = await readOwner();
|
|
37899
38238
|
} catch (error) {
|
|
37900
|
-
if (windowsPrivateFiles2)
|
|
38239
|
+
if (windowsPrivateFiles2 && !(error instanceof DisappearedLockRecordError2))
|
|
37901
38240
|
throw error;
|
|
37902
38241
|
return;
|
|
37903
38242
|
}
|
|
@@ -37975,7 +38314,7 @@ async function acquireRefreshFileLockWithClock2(options) {
|
|
|
37975
38314
|
await options.onStep("renewal-marker-unavailable");
|
|
37976
38315
|
}
|
|
37977
38316
|
} catch (error) {
|
|
37978
|
-
if (windowsPrivateFiles2 && error instanceof PrivateFileError2) {
|
|
38317
|
+
if (windowsPrivateFiles2 && error instanceof PrivateFileError2 && !isChangingLockCreate(error)) {
|
|
37979
38318
|
terminalIOError = error;
|
|
37980
38319
|
recordLoss("renewal-failed");
|
|
37981
38320
|
shouldReschedule = false;
|
|
@@ -38021,72 +38360,90 @@ async function acquireRefreshFileLockWithClock2(options) {
|
|
|
38021
38360
|
}
|
|
38022
38361
|
return null;
|
|
38023
38362
|
}
|
|
38024
|
-
let acquired =
|
|
38363
|
+
let acquired = false;
|
|
38364
|
+
let changingCreateError;
|
|
38365
|
+
try {
|
|
38366
|
+
acquired = await tryAcquire();
|
|
38367
|
+
} catch (error) {
|
|
38368
|
+
if (!isChangingLockCreate(error))
|
|
38369
|
+
throw error;
|
|
38370
|
+
changingCreateError = error;
|
|
38371
|
+
}
|
|
38025
38372
|
if (!acquired) {
|
|
38026
38373
|
for (let attempt = 0; attempt < MAX_STEAL_ATTEMPTS; attempt++) {
|
|
38027
|
-
acquired = await tryAcquire();
|
|
38028
|
-
if (acquired)
|
|
38029
|
-
break;
|
|
38030
|
-
const observed = await readLockState();
|
|
38031
|
-
if (observed.status === "live")
|
|
38032
|
-
return contended();
|
|
38033
|
-
if (observed.status === "missing")
|
|
38034
|
-
continue;
|
|
38035
|
-
if (options.onStep)
|
|
38036
|
-
await options.onStep("stale-lock-observed");
|
|
38037
38374
|
try {
|
|
38038
|
-
|
|
38039
|
-
|
|
38040
|
-
|
|
38041
|
-
|
|
38042
|
-
|
|
38043
|
-
const code2 = evictError.code;
|
|
38044
|
-
if (code2 !== "EEXIST")
|
|
38045
|
-
throw evictError;
|
|
38046
|
-
const recovered = await recoverStaleEvictionMarker();
|
|
38047
|
-
if (recovered === "fresh")
|
|
38048
|
-
return null;
|
|
38049
|
-
await backoff();
|
|
38050
|
-
continue;
|
|
38051
|
-
}
|
|
38052
|
-
try {
|
|
38053
|
-
const confirmed = await readLockState();
|
|
38054
|
-
if (confirmed.status === "live")
|
|
38375
|
+
acquired = await tryAcquire();
|
|
38376
|
+
if (acquired)
|
|
38377
|
+
break;
|
|
38378
|
+
const observed = await readLockState();
|
|
38379
|
+
if (observed.status === "live")
|
|
38055
38380
|
return contended();
|
|
38056
|
-
if (
|
|
38381
|
+
if (observed.status === "missing")
|
|
38057
38382
|
continue;
|
|
38058
|
-
if (!await ownsEvictionMarker())
|
|
38059
|
-
return null;
|
|
38060
38383
|
if (options.onStep)
|
|
38061
|
-
await options.onStep("stale-lock-
|
|
38062
|
-
|
|
38063
|
-
|
|
38064
|
-
|
|
38065
|
-
|
|
38384
|
+
await options.onStep("stale-lock-observed");
|
|
38385
|
+
try {
|
|
38386
|
+
if (!await tryAcquireEvictionMarker()) {
|
|
38387
|
+
await backoff();
|
|
38388
|
+
continue;
|
|
38389
|
+
}
|
|
38390
|
+
} catch (evictError) {
|
|
38391
|
+
const code2 = evictError.code;
|
|
38392
|
+
if (code2 !== "EEXIST")
|
|
38393
|
+
throw evictError;
|
|
38394
|
+
const recovered = await recoverStaleEvictionMarker();
|
|
38395
|
+
if (recovered === "fresh")
|
|
38396
|
+
return null;
|
|
38397
|
+
await backoff();
|
|
38066
38398
|
continue;
|
|
38067
|
-
await removeLeaseObject(lockPath);
|
|
38068
|
-
if (!await ownsEvictionMarker())
|
|
38069
|
-
return null;
|
|
38070
|
-
if (options.onStep)
|
|
38071
|
-
await options.onStep("stale-lock-removed");
|
|
38072
|
-
acquired = await tryAcquire();
|
|
38073
|
-
if (!acquired)
|
|
38074
|
-
return null;
|
|
38075
|
-
if (options.onStep)
|
|
38076
|
-
await options.onStep("stale-lock-recreated");
|
|
38077
|
-
if (!await ownsEvictionMarker()) {
|
|
38078
|
-
await relinquishLockAfterMarkerLoss();
|
|
38079
|
-
acquired = false;
|
|
38080
|
-
return null;
|
|
38081
38399
|
}
|
|
38082
|
-
|
|
38083
|
-
|
|
38084
|
-
|
|
38400
|
+
try {
|
|
38401
|
+
const confirmed = await readLockState();
|
|
38402
|
+
if (confirmed.status === "live")
|
|
38403
|
+
return contended();
|
|
38404
|
+
if (!sameStaleLock(observed.identity, confirmed))
|
|
38405
|
+
continue;
|
|
38406
|
+
if (!await ownsEvictionMarker())
|
|
38407
|
+
return null;
|
|
38408
|
+
if (options.onStep)
|
|
38409
|
+
await options.onStep("stale-lock-confirmed");
|
|
38410
|
+
if (!await ownsEvictionMarker())
|
|
38411
|
+
return null;
|
|
38412
|
+
const current = await readLockState(false);
|
|
38413
|
+
if (!sameStaleLock(observed.identity, current))
|
|
38414
|
+
continue;
|
|
38415
|
+
await removeLeaseObject(lockPath);
|
|
38416
|
+
if (!await ownsEvictionMarker())
|
|
38417
|
+
return null;
|
|
38418
|
+
if (options.onStep)
|
|
38419
|
+
await options.onStep("stale-lock-removed");
|
|
38420
|
+
acquired = await tryAcquire();
|
|
38421
|
+
if (!acquired)
|
|
38422
|
+
return null;
|
|
38423
|
+
if (options.onStep)
|
|
38424
|
+
await options.onStep("stale-lock-recreated");
|
|
38425
|
+
if (!await ownsEvictionMarker()) {
|
|
38426
|
+
await relinquishLockAfterMarkerLoss();
|
|
38427
|
+
acquired = false;
|
|
38428
|
+
return null;
|
|
38429
|
+
}
|
|
38430
|
+
break;
|
|
38431
|
+
} finally {
|
|
38432
|
+
await releaseEvictionMarker();
|
|
38433
|
+
}
|
|
38434
|
+
} catch (error) {
|
|
38435
|
+
if (!isChangingLockCreate(error))
|
|
38436
|
+
throw error;
|
|
38437
|
+
changingCreateError ??= error;
|
|
38438
|
+
await backoff();
|
|
38085
38439
|
}
|
|
38086
38440
|
}
|
|
38087
38441
|
}
|
|
38088
|
-
if (!acquired)
|
|
38442
|
+
if (!acquired) {
|
|
38443
|
+
if (changingCreateError)
|
|
38444
|
+
throw changingCreateError;
|
|
38089
38445
|
return null;
|
|
38446
|
+
}
|
|
38090
38447
|
scheduleRenewal();
|
|
38091
38448
|
return {
|
|
38092
38449
|
ownerId,
|
|
@@ -38124,6 +38481,7 @@ async function acquireRefreshFileLockWithClock2(options) {
|
|
|
38124
38481
|
const deadline = performance.now() + EVICT_TTL + 1e3;
|
|
38125
38482
|
let delayMs = 5;
|
|
38126
38483
|
let removalError;
|
|
38484
|
+
let changingRecordError;
|
|
38127
38485
|
for (; ; ) {
|
|
38128
38486
|
try {
|
|
38129
38487
|
let removalConfirmed = false;
|
|
@@ -38149,6 +38507,7 @@ async function acquireRefreshFileLockWithClock2(options) {
|
|
|
38149
38507
|
await removeLeaseObject(lockPath);
|
|
38150
38508
|
removalConfirmed = true;
|
|
38151
38509
|
}, deadline);
|
|
38510
|
+
changingRecordError = void 0;
|
|
38152
38511
|
if (markerAcquired) {
|
|
38153
38512
|
if (windowsPrivateFiles2 && !removalConfirmed)
|
|
38154
38513
|
throw new PrivateFileError2(lockPath, "release-not-confirmed", {
|
|
@@ -38161,23 +38520,32 @@ async function acquireRefreshFileLockWithClock2(options) {
|
|
|
38161
38520
|
return;
|
|
38162
38521
|
await recoverStaleEvictionMarker(deadline);
|
|
38163
38522
|
} catch (error) {
|
|
38164
|
-
|
|
38523
|
+
const changingRecord = windowsPrivateFiles2 && (isChangingLockCreate(error) || isWindowsAccessDeniedRead2(error, [
|
|
38524
|
+
lockPath,
|
|
38525
|
+
legacyOwnerPath,
|
|
38526
|
+
evictPath,
|
|
38527
|
+
evictOwnerPath
|
|
38528
|
+
]));
|
|
38529
|
+
if (!isRetryableRemoval(error, lockPath) && !changingRecord) {
|
|
38165
38530
|
if (windowsPrivateFiles2)
|
|
38166
38531
|
throw error;
|
|
38167
38532
|
return;
|
|
38168
38533
|
}
|
|
38169
|
-
|
|
38534
|
+
if (changingRecord)
|
|
38535
|
+
changingRecordError ??= error;
|
|
38536
|
+
else
|
|
38537
|
+
removalError ??= error;
|
|
38170
38538
|
}
|
|
38171
38539
|
const remainingMs = deadline - performance.now();
|
|
38172
38540
|
if (remainingMs <= 0)
|
|
38173
38541
|
break;
|
|
38174
|
-
await new Promise((
|
|
38542
|
+
await new Promise((resolve29) => setTimeout(resolve29, Math.min(delayMs, remainingMs)));
|
|
38175
38543
|
if (windowsPrivateFiles2 && performance.now() >= deadline)
|
|
38176
38544
|
break;
|
|
38177
38545
|
delayMs = Math.min(delayMs * 2, 50);
|
|
38178
38546
|
}
|
|
38179
38547
|
if (windowsPrivateFiles2)
|
|
38180
|
-
throw removalError ?? new PrivateFileError2(lockPath, "release-not-confirmed", {
|
|
38548
|
+
throw changingRecordError ?? removalError ?? new PrivateFileError2(lockPath, "release-not-confirmed", {
|
|
38181
38549
|
code: "ETIMEDOUT"
|
|
38182
38550
|
});
|
|
38183
38551
|
}
|
|
@@ -38317,6 +38685,29 @@ function classifyEnrollmentError2(error) {
|
|
|
38317
38685
|
disposition: error.action === "retry" ? "retry" : "terminal"
|
|
38318
38686
|
};
|
|
38319
38687
|
}
|
|
38688
|
+
function validEnrollmentDisplayName2(displayName) {
|
|
38689
|
+
const length = Array.from(displayName).length;
|
|
38690
|
+
return length >= 1 && length <= 40 && !/[\p{Cc}\u061c\u200e\u200f\u202a-\u202e\u2066-\u2069\u200b-\u200d\u2060\ufeff]/u.test(displayName);
|
|
38691
|
+
}
|
|
38692
|
+
function validEnrollmentRequestedGrants2(grants) {
|
|
38693
|
+
return Array.isArray(grants) && grants.length >= 1 && grants.length <= 4 && Array.from(grants).every((grant) => {
|
|
38694
|
+
if (!isRecord11(grant) || Object.keys(grant).length !== 2 || grant.operation !== "read" && grant.operation !== "list" || !isRecord11(grant.selector))
|
|
38695
|
+
return false;
|
|
38696
|
+
const keys = Object.keys(grant.selector);
|
|
38697
|
+
const key = keys[0];
|
|
38698
|
+
return keys.length === 1 && (key === "category" || key === "exact") && typeof grant.selector[key] === "string" && grant.selector[key].trim().length > 0;
|
|
38699
|
+
});
|
|
38700
|
+
}
|
|
38701
|
+
function grantProposal2(state) {
|
|
38702
|
+
return {
|
|
38703
|
+
...state.requestedGrants !== void 0 && {
|
|
38704
|
+
requestedGrants: state.requestedGrants
|
|
38705
|
+
},
|
|
38706
|
+
...state.requestedGrantsStatus !== void 0 && {
|
|
38707
|
+
requestedGrantsStatus: state.requestedGrantsStatus
|
|
38708
|
+
}
|
|
38709
|
+
};
|
|
38710
|
+
}
|
|
38320
38711
|
function connectClaustrumEnrollmentClient2(options) {
|
|
38321
38712
|
return ClaustrumWireClient2.connect(options);
|
|
38322
38713
|
}
|
|
@@ -38332,7 +38723,7 @@ function hostEnrollmentPaths2(input2) {
|
|
|
38332
38723
|
const override = input2.override?.trim();
|
|
38333
38724
|
if (override && !isAbsolute4(override) && !input2.cwd)
|
|
38334
38725
|
throw new ClaustrumConsumerError2("invalid-state", "A relative Claustrum enrollment override needs a base directory");
|
|
38335
|
-
const tokenPath = override ? isAbsolute4(override) ? override :
|
|
38726
|
+
const tokenPath = override ? isAbsolute4(override) ? override : resolve21(input2.cwd, override) : join20(input2.stateDir, `${input2.host}-enrollment.json`);
|
|
38336
38727
|
return getClaustrumEnrollmentPaths2(tokenPath);
|
|
38337
38728
|
}
|
|
38338
38729
|
function isRecord11(value) {
|
|
@@ -38352,6 +38743,7 @@ function decodeEnrollmentState2(value) {
|
|
|
38352
38743
|
throw invalidState2();
|
|
38353
38744
|
}
|
|
38354
38745
|
if (value.phase === "pending") {
|
|
38746
|
+
const grants = decodeGrantProposal2(value);
|
|
38355
38747
|
if (!TOKEN_RE2.test(String(value.requestSecret ?? "")) || value.requestId !== void 0 && (typeof value.requestId !== "string" || value.requestId.length === 0) || !validTimestamp2(value.createdAt) || !validTimestamp2(value.updatedAt)) {
|
|
38356
38748
|
throw invalidState2();
|
|
38357
38749
|
}
|
|
@@ -38364,10 +38756,12 @@ function decodeEnrollmentState2(value) {
|
|
|
38364
38756
|
requestId: value.requestId
|
|
38365
38757
|
},
|
|
38366
38758
|
createdAt: value.createdAt,
|
|
38367
|
-
updatedAt: value.updatedAt
|
|
38759
|
+
updatedAt: value.updatedAt,
|
|
38760
|
+
...grants
|
|
38368
38761
|
};
|
|
38369
38762
|
}
|
|
38370
38763
|
if (value.phase === "approved") {
|
|
38764
|
+
const grants = decodeGrantProposal2(value);
|
|
38371
38765
|
if (value.approvedName !== void 0 && (typeof value.approvedName !== "string" || value.approvedName.length === 0) || !validGeneration2(value.tokenGeneration) || !validTimestamp2(value.updatedAt)) {
|
|
38372
38766
|
throw invalidState2();
|
|
38373
38767
|
}
|
|
@@ -38379,7 +38773,8 @@ function decodeEnrollmentState2(value) {
|
|
|
38379
38773
|
approvedName: value.approvedName
|
|
38380
38774
|
},
|
|
38381
38775
|
tokenGeneration: value.tokenGeneration,
|
|
38382
|
-
updatedAt: value.updatedAt
|
|
38776
|
+
updatedAt: value.updatedAt,
|
|
38777
|
+
...grants
|
|
38383
38778
|
};
|
|
38384
38779
|
}
|
|
38385
38780
|
if (value.phase === "denied" || value.phase === "blocked") {
|
|
@@ -38398,6 +38793,11 @@ function decodeEnrollmentState2(value) {
|
|
|
38398
38793
|
}
|
|
38399
38794
|
throw invalidState2();
|
|
38400
38795
|
}
|
|
38796
|
+
function decodeGrantProposal2(value) {
|
|
38797
|
+
if (value.requestedGrants !== void 0 && !validEnrollmentRequestedGrants2(value.requestedGrants) || value.requestedGrantsStatus !== void 0 && (value.requestedGrants === void 0 || value.requestedGrantsStatus !== "sent" && value.requestedGrantsStatus !== "dropped"))
|
|
38798
|
+
return {};
|
|
38799
|
+
return grantProposal2(value);
|
|
38800
|
+
}
|
|
38401
38801
|
function decodeTokenFile2(value) {
|
|
38402
38802
|
if (!isRecord11(value) || !TOKEN_RE2.test(String(value.token ?? "")) || !validGeneration2(value.token_generation)) {
|
|
38403
38803
|
throw new ClaustrumConsumerError2("invalid-token", "invalid Claustrum enrollment token file");
|
|
@@ -38612,7 +39012,8 @@ async function readEnrollmentStatus2(paths, proposedName) {
|
|
|
38612
39012
|
...state?.phase === "approved" && state.approvedName !== void 0 && {
|
|
38613
39013
|
approvedName: state.approvedName
|
|
38614
39014
|
},
|
|
38615
|
-
tokenGeneration: token.token_generation
|
|
39015
|
+
tokenGeneration: token.token_generation,
|
|
39016
|
+
...state && (state.phase === "approved" || state.phase === "pending") && grantProposal2(state)
|
|
38616
39017
|
}
|
|
38617
39018
|
};
|
|
38618
39019
|
}
|
|
@@ -38660,12 +39061,19 @@ async function vaultAuthority3(paths, proposedName) {
|
|
|
38660
39061
|
return "host";
|
|
38661
39062
|
return enrollmentAuthority2(paths, proposedName);
|
|
38662
39063
|
}
|
|
39064
|
+
async function readClaustrumEnrollmentToken2(tokenPath) {
|
|
39065
|
+
const value = await readBoundedJson2(tokenPath);
|
|
39066
|
+
if (value === void 0)
|
|
39067
|
+
throw new ClaustrumConsumerError2("not-enrolled", "Claustrum enrollment is not configured");
|
|
39068
|
+
return decodeTokenFile2(value);
|
|
39069
|
+
}
|
|
38663
39070
|
function statusFromState2(state) {
|
|
38664
39071
|
if (state.phase === "pending") {
|
|
38665
39072
|
return {
|
|
38666
39073
|
state: "pending",
|
|
38667
39074
|
proposedName: state.proposedName,
|
|
38668
|
-
...state.requestId !== void 0 && { requestId: state.requestId }
|
|
39075
|
+
...state.requestId !== void 0 && { requestId: state.requestId },
|
|
39076
|
+
...grantProposal2(state)
|
|
38669
39077
|
};
|
|
38670
39078
|
}
|
|
38671
39079
|
if (state.phase === "approved") {
|
|
@@ -38675,7 +39083,8 @@ function statusFromState2(state) {
|
|
|
38675
39083
|
...state.approvedName !== void 0 && {
|
|
38676
39084
|
approvedName: state.approvedName
|
|
38677
39085
|
},
|
|
38678
|
-
tokenGeneration: state.tokenGeneration
|
|
39086
|
+
tokenGeneration: state.tokenGeneration,
|
|
39087
|
+
...grantProposal2(state)
|
|
38679
39088
|
};
|
|
38680
39089
|
}
|
|
38681
39090
|
if (state.phase === "denied")
|
|
@@ -38693,15 +39102,26 @@ var ClaustrumEnrollmentManager2 = class {
|
|
|
38693
39102
|
#client;
|
|
38694
39103
|
#paths;
|
|
38695
39104
|
#proposedName;
|
|
39105
|
+
#displayName;
|
|
39106
|
+
#requestedGrants;
|
|
38696
39107
|
#now;
|
|
38697
39108
|
#mintSecret;
|
|
38698
39109
|
#writeTokenFile;
|
|
38699
39110
|
#ancestorOptions;
|
|
38700
39111
|
constructor(options) {
|
|
39112
|
+
if (options.displayName !== void 0 && !validEnrollmentDisplayName2(options.displayName))
|
|
39113
|
+
throw new ClaustrumConsumerError2("invalid-state", "invalid Claustrum enrollment display name");
|
|
39114
|
+
if (options.requestedGrants !== void 0 && !validEnrollmentRequestedGrants2(options.requestedGrants))
|
|
39115
|
+
throw new ClaustrumConsumerError2("invalid-state", "invalid Claustrum enrollment requested grants");
|
|
39116
|
+
this.#requestedGrants = options.requestedGrants?.map((grant) => ({
|
|
39117
|
+
selector: { ...grant.selector },
|
|
39118
|
+
operation: grant.operation
|
|
39119
|
+
}));
|
|
38701
39120
|
this.#ancestorOptions = options.ancestorOptions ?? {};
|
|
38702
39121
|
this.#client = options.client;
|
|
38703
39122
|
this.#paths = options.paths;
|
|
38704
39123
|
this.#proposedName = options.proposedName;
|
|
39124
|
+
this.#displayName = options.displayName;
|
|
38705
39125
|
this.#now = options.now ?? Date.now;
|
|
38706
39126
|
this.#mintSecret = options.mintSecret ?? (() => randomBytes5(32).toString("hex"));
|
|
38707
39127
|
this.#writeTokenFile = options.writeTokenFile ?? writeEnrollmentTokenFile2;
|
|
@@ -38747,6 +39167,7 @@ var ClaustrumEnrollmentManager2 = class {
|
|
|
38747
39167
|
phase: "approved",
|
|
38748
39168
|
proposedName: state?.proposedName ?? this.#proposedName,
|
|
38749
39169
|
tokenGeneration: token.token_generation,
|
|
39170
|
+
...state && grantProposal2(state),
|
|
38750
39171
|
updatedAt: this.#now()
|
|
38751
39172
|
};
|
|
38752
39173
|
await writeStateAtomic2(this.#paths.statePath, approved, this.#ancestorOptions);
|
|
@@ -38758,7 +39179,8 @@ var ClaustrumEnrollmentManager2 = class {
|
|
|
38758
39179
|
...state.phase === "approved" && state.approvedName !== void 0 && {
|
|
38759
39180
|
approvedName: state.approvedName
|
|
38760
39181
|
},
|
|
38761
|
-
tokenGeneration: token.token_generation
|
|
39182
|
+
tokenGeneration: token.token_generation,
|
|
39183
|
+
...state.phase === "approved" && grantProposal2(state)
|
|
38762
39184
|
};
|
|
38763
39185
|
}
|
|
38764
39186
|
if (state?.phase === "approved") {
|
|
@@ -38782,7 +39204,10 @@ var ClaustrumEnrollmentManager2 = class {
|
|
|
38782
39204
|
proposedName: this.#proposedName,
|
|
38783
39205
|
requestSecret: this.#mintSecret(),
|
|
38784
39206
|
createdAt: now,
|
|
38785
|
-
updatedAt: now
|
|
39207
|
+
updatedAt: now,
|
|
39208
|
+
...this.#requestedGrants !== void 0 && {
|
|
39209
|
+
requestedGrants: this.#requestedGrants
|
|
39210
|
+
}
|
|
38786
39211
|
};
|
|
38787
39212
|
if (!TOKEN_RE2.test(state.requestSecret))
|
|
38788
39213
|
throw new ClaustrumConsumerError2("invalid-state", "invalid minted Claustrum enrollment secret");
|
|
@@ -38791,14 +39216,38 @@ var ClaustrumEnrollmentManager2 = class {
|
|
|
38791
39216
|
if (!state.requestId) {
|
|
38792
39217
|
try {
|
|
38793
39218
|
const requestSecretHash = createHash13("sha256").update(Buffer.from(state.requestSecret, "hex")).digest("hex");
|
|
38794
|
-
const
|
|
39219
|
+
const proposal = {
|
|
38795
39220
|
name: state.proposedName,
|
|
38796
39221
|
requestSecretHash
|
|
38797
|
-
}
|
|
39222
|
+
};
|
|
39223
|
+
let proposed;
|
|
39224
|
+
let requestedGrantsStatus = state.requestedGrantsStatus;
|
|
39225
|
+
try {
|
|
39226
|
+
proposed = await this.#client.enrollPropose({
|
|
39227
|
+
...proposal,
|
|
39228
|
+
...this.#displayName !== void 0 && {
|
|
39229
|
+
displayName: this.#displayName
|
|
39230
|
+
},
|
|
39231
|
+
...state.requestedGrants !== void 0 && {
|
|
39232
|
+
requestedGrants: state.requestedGrants
|
|
39233
|
+
}
|
|
39234
|
+
});
|
|
39235
|
+
if (state.requestedGrants !== void 0)
|
|
39236
|
+
requestedGrantsStatus = "sent";
|
|
39237
|
+
} catch (error) {
|
|
39238
|
+
if (this.#displayName === void 0 && state.requestedGrants === void 0 || !(error instanceof ClaustrumCredentialError9) || error.code !== "invalid_params")
|
|
39239
|
+
throw error;
|
|
39240
|
+
proposed = await this.#client.enrollPropose(proposal);
|
|
39241
|
+
if (state.requestedGrants !== void 0)
|
|
39242
|
+
requestedGrantsStatus = "dropped";
|
|
39243
|
+
}
|
|
38798
39244
|
state = {
|
|
38799
39245
|
...state,
|
|
38800
39246
|
requestId: proposed.requestId,
|
|
38801
|
-
updatedAt: this.#now()
|
|
39247
|
+
updatedAt: this.#now(),
|
|
39248
|
+
...requestedGrantsStatus !== void 0 && {
|
|
39249
|
+
requestedGrantsStatus
|
|
39250
|
+
}
|
|
38802
39251
|
};
|
|
38803
39252
|
await writeStateAtomic2(this.#paths.statePath, state, this.#ancestorOptions);
|
|
38804
39253
|
} catch (error) {
|
|
@@ -38809,7 +39258,8 @@ var ClaustrumEnrollmentManager2 = class {
|
|
|
38809
39258
|
return {
|
|
38810
39259
|
state: "pending",
|
|
38811
39260
|
proposedName: state.proposedName,
|
|
38812
|
-
retryCode: refusal3.code
|
|
39261
|
+
retryCode: refusal3.code,
|
|
39262
|
+
...grantProposal2(state)
|
|
38813
39263
|
};
|
|
38814
39264
|
}
|
|
38815
39265
|
if (refusal3.code === UNSUPPORTED_ENROLLMENT_CODE2) {
|
|
@@ -38859,6 +39309,7 @@ var ClaustrumEnrollmentManager2 = class {
|
|
|
38859
39309
|
proposedName: state.proposedName,
|
|
38860
39310
|
approvedName: outcome.name,
|
|
38861
39311
|
tokenGeneration: outcome.tokenGeneration,
|
|
39312
|
+
...grantProposal2(state),
|
|
38862
39313
|
updatedAt: this.#now()
|
|
38863
39314
|
};
|
|
38864
39315
|
await writeStateAtomic2(this.#paths.statePath, approved, this.#ancestorOptions);
|
|
@@ -38872,7 +39323,8 @@ var ClaustrumEnrollmentManager2 = class {
|
|
|
38872
39323
|
state: "pending",
|
|
38873
39324
|
proposedName: state.proposedName,
|
|
38874
39325
|
requestId,
|
|
38875
|
-
retryCode: refusal3.code
|
|
39326
|
+
retryCode: refusal3.code,
|
|
39327
|
+
...grantProposal2(state)
|
|
38876
39328
|
};
|
|
38877
39329
|
}
|
|
38878
39330
|
return this.#block(state, refusal3.code);
|
|
@@ -38965,7 +39417,7 @@ var ByteTail = class {
|
|
|
38965
39417
|
};
|
|
38966
39418
|
var defaultCommandRunner = {
|
|
38967
39419
|
run(file, args, options = {}) {
|
|
38968
|
-
return new Promise((
|
|
39420
|
+
return new Promise((resolve29) => {
|
|
38969
39421
|
const started = performance.now();
|
|
38970
39422
|
const timeoutMs = options.timeoutMs ?? 15e3;
|
|
38971
39423
|
const stderr = new ByteTail();
|
|
@@ -38983,7 +39435,7 @@ var defaultCommandRunner = {
|
|
|
38983
39435
|
stdio: ["ignore", "pipe", "pipe"]
|
|
38984
39436
|
});
|
|
38985
39437
|
} catch {
|
|
38986
|
-
|
|
39438
|
+
resolve29({
|
|
38987
39439
|
exitCode: 1,
|
|
38988
39440
|
stdout: "",
|
|
38989
39441
|
stderr: "",
|
|
@@ -39018,7 +39470,7 @@ var defaultCommandRunner = {
|
|
|
39018
39470
|
settled = true;
|
|
39019
39471
|
if (timer)
|
|
39020
39472
|
clearTimeout(timer);
|
|
39021
|
-
|
|
39473
|
+
resolve29({
|
|
39022
39474
|
exitCode: spawnError ? 1 : outputExceeded ? 1 : code2 ?? 1,
|
|
39023
39475
|
stdout: Buffer.concat(stdout, stdoutLength).toString("utf8"),
|
|
39024
39476
|
stderr: stderr.toString(),
|
|
@@ -39051,6 +39503,68 @@ function runResolvedCommand(runner, platform, file, args, env3, timeoutMs = 15e3
|
|
|
39051
39503
|
return runner.run(file, args, { env: env3, timeoutMs });
|
|
39052
39504
|
}
|
|
39053
39505
|
|
|
39506
|
+
// src/common-auth-embedded/setup/enrollment-access.js
|
|
39507
|
+
function shellArgument(value) {
|
|
39508
|
+
if (/^[a-zA-Z0-9_:@./-]+$/.test(value))
|
|
39509
|
+
return value;
|
|
39510
|
+
return process.platform === "win32" ? `'${value.replaceAll("'", "''")}'` : `'${value.replaceAll("'", "'\\''")}'`;
|
|
39511
|
+
}
|
|
39512
|
+
async function confirmEnrollmentAccess(client, status, tokenPath, configuredGrants) {
|
|
39513
|
+
const requestedGrants = status.requestedGrants ?? configuredGrants;
|
|
39514
|
+
if (!requestedGrants)
|
|
39515
|
+
return void 0;
|
|
39516
|
+
const grants = requestedGrants.map((grant) => ({
|
|
39517
|
+
grant,
|
|
39518
|
+
...status.approvedName !== void 0 && {
|
|
39519
|
+
grantCommand: `ck auth grant --principal ${shellArgument(`enrolled:${status.approvedName}`)} --selector-kind ${grant.selector.exact === void 0 ? "category" : "exact"} --selector ${shellArgument(grant.selector.exact ?? grant.selector.category)} --operation ${grant.operation}`
|
|
39520
|
+
}
|
|
39521
|
+
}));
|
|
39522
|
+
if (status.requestedGrantsStatus === "dropped")
|
|
39523
|
+
return { state: "older-vault", grants };
|
|
39524
|
+
try {
|
|
39525
|
+
if (!client.listScoped)
|
|
39526
|
+
return { state: "unconfirmed", grants };
|
|
39527
|
+
const { token } = await readClaustrumEnrollmentToken2(tokenPath);
|
|
39528
|
+
const inventory = await client.listScoped(token);
|
|
39529
|
+
const confirmed = grants.map((entry) => ({
|
|
39530
|
+
...entry,
|
|
39531
|
+
reachableLogins: inventory.rows.filter((row) => row.operations.includes(entry.grant.operation) && (entry.grant.selector.exact !== void 0 ? row.id === entry.grant.selector.exact : row.categories.includes(entry.grant.selector.category))).length
|
|
39532
|
+
}));
|
|
39533
|
+
return {
|
|
39534
|
+
state: confirmed.every((entry) => entry.reachableLogins > 0) ? "reachable" : confirmed.some((entry) => entry.reachableLogins > 0) ? "partial" : "no-logins",
|
|
39535
|
+
grants: confirmed.map((entry) => {
|
|
39536
|
+
if (entry.reachableLogins === 0)
|
|
39537
|
+
return entry;
|
|
39538
|
+
const { grantCommand: _, ...reachable } = entry;
|
|
39539
|
+
return reachable;
|
|
39540
|
+
})
|
|
39541
|
+
};
|
|
39542
|
+
} catch {
|
|
39543
|
+
return { state: "unconfirmed", grants };
|
|
39544
|
+
}
|
|
39545
|
+
}
|
|
39546
|
+
function enrollmentAccessLines(access) {
|
|
39547
|
+
const lines = [];
|
|
39548
|
+
const remedy = access.grants.some((entry) => entry.grantCommand) ? "run:" : "check ck auth status for the approved name before granting access.";
|
|
39549
|
+
if (access.state === "older-vault")
|
|
39550
|
+
lines.push(`Approved. This vault is too old to grant access with the approval; ${remedy}`);
|
|
39551
|
+
else if (access.state === "no-logins")
|
|
39552
|
+
lines.push(`Approved, but no logins are reachable yet; ${remedy}`);
|
|
39553
|
+
else if (access.state === "partial")
|
|
39554
|
+
lines.push(`Approved, but some requested access has no reachable logins yet; ${remedy}`);
|
|
39555
|
+
else if (access.state === "unconfirmed")
|
|
39556
|
+
lines.push(`Approved, but access could not be confirmed; ${access.grants.some((entry) => entry.grantCommand) ? "check ck auth status or run:" : remedy}`);
|
|
39557
|
+
for (const { grant, reachableLogins, grantCommand } of access.grants) {
|
|
39558
|
+
if (reachableLogins !== void 0 && reachableLogins > 0) {
|
|
39559
|
+
const target = grant.selector.exact === void 0 ? `the vault's ${JSON.stringify(grant.selector.category)} accounts` : `credential ${JSON.stringify(grant.selector.exact)}`;
|
|
39560
|
+
lines.push(`Confirmed ${grant.operation} access to ${target} (${reachableLogins} reachable ${reachableLogins === 1 ? "login" : "logins"}).`);
|
|
39561
|
+
}
|
|
39562
|
+
if (grantCommand)
|
|
39563
|
+
lines.push(` ${grantCommand}`);
|
|
39564
|
+
}
|
|
39565
|
+
return lines;
|
|
39566
|
+
}
|
|
39567
|
+
|
|
39054
39568
|
// src/common-auth-embedded/setup/command-error.js
|
|
39055
39569
|
var PI_INSTALL_ERROR_MESSAGE = "Pi install failed; run pi install after checking your npm connection.";
|
|
39056
39570
|
function utf8Tail(value) {
|
|
@@ -39091,8 +39605,8 @@ var OUTCOME_TEXT = {
|
|
|
39091
39605
|
"not-enrolled": "not connected",
|
|
39092
39606
|
unknown: "unknown, check with ck auth status"
|
|
39093
39607
|
};
|
|
39094
|
-
function setupEnrollmentLine({ host, outcome }) {
|
|
39095
|
-
return `${HOST_LABELS[host]}: ${OUTCOME_TEXT[outcome]}`;
|
|
39608
|
+
function setupEnrollmentLine({ host, outcome, access }) {
|
|
39609
|
+
return `${HOST_LABELS[host]}: ${OUTCOME_TEXT[outcome]}${access ? ` \u2014 ${enrollmentAccessLines(access).join("\n")}` : ""}`;
|
|
39096
39610
|
}
|
|
39097
39611
|
var recordedEnrollment = /* @__PURE__ */ new WeakMap();
|
|
39098
39612
|
function recordSetupEnrollment(failure2, enrollment) {
|
|
@@ -39630,7 +40144,7 @@ function approveCommand(requestId, name) {
|
|
|
39630
40144
|
async function connectSetupHost(plugin, host, io, terminal, fence) {
|
|
39631
40145
|
if (hasVaultHost2())
|
|
39632
40146
|
throw new Error(VAULT_HOST_CONNECT_REFUSAL2);
|
|
39633
|
-
const { name, paths: input2 } = plugin.vault.hosts[host];
|
|
40147
|
+
const { name, displayName, requestedGrants, paths: input2 } = plugin.vault.hosts[host];
|
|
39634
40148
|
const paths = hostEnrollmentPaths2(input2);
|
|
39635
40149
|
await fence();
|
|
39636
40150
|
const client = await (io.connect ?? connectClaustrumEnrollmentClient2)({
|
|
@@ -39644,6 +40158,8 @@ async function connectSetupHost(plugin, host, io, terminal, fence) {
|
|
|
39644
40158
|
try {
|
|
39645
40159
|
const manager = new ClaustrumEnrollmentManager2({
|
|
39646
40160
|
proposedName: name,
|
|
40161
|
+
displayName,
|
|
40162
|
+
requestedGrants,
|
|
39647
40163
|
paths,
|
|
39648
40164
|
// Each tick of the wait below checks the fence once, just before
|
|
39649
40165
|
// reconcile proposes or polls. Checking again inside every vault call
|
|
@@ -39659,7 +40175,11 @@ async function connectSetupHost(plugin, host, io, terminal, fence) {
|
|
|
39659
40175
|
const initial = await manager.status();
|
|
39660
40176
|
if (initial.state === "approved") {
|
|
39661
40177
|
printLine2(terminal, `Already connected as ${initial.approvedName ?? initial.proposedName}.`);
|
|
39662
|
-
|
|
40178
|
+
const access = await confirmEnrollmentAccess(client, initial, paths.tokenPath, requestedGrants);
|
|
40179
|
+
if (access)
|
|
40180
|
+
for (const line of enrollmentAccessLines(access))
|
|
40181
|
+
printLine2(terminal, line);
|
|
40182
|
+
return access;
|
|
39663
40183
|
}
|
|
39664
40184
|
printLine2(terminal, `Asking the vault to connect ${name}\u2026`);
|
|
39665
40185
|
const deadline = now() + ENROLLMENT_WAIT_MS;
|
|
@@ -39671,7 +40191,11 @@ async function connectSetupHost(plugin, host, io, terminal, fence) {
|
|
|
39671
40191
|
const status = await manager.reconcile();
|
|
39672
40192
|
if (status.state === "approved") {
|
|
39673
40193
|
printLine2(terminal, `Connected ${host} to Claustrum.`);
|
|
39674
|
-
|
|
40194
|
+
const access = await confirmEnrollmentAccess(client, status, paths.tokenPath, requestedGrants);
|
|
40195
|
+
if (access)
|
|
40196
|
+
for (const line of enrollmentAccessLines(access))
|
|
40197
|
+
printLine2(terminal, line);
|
|
40198
|
+
return access;
|
|
39675
40199
|
}
|
|
39676
40200
|
if (status.state === "unavailable" && status.code === UNSUPPORTED_ENROLLMENT_CODE2)
|
|
39677
40201
|
throw new HostNotEnrolledError(UNSUPPORTED_VAULT_MESSAGE, {
|
|
@@ -40105,12 +40629,15 @@ function validatePlugin(plugin) {
|
|
|
40105
40629
|
for (const host of Object.values(plugin.vault.hosts)) {
|
|
40106
40630
|
if (!/^[a-z0-9][a-z0-9-]*$/.test(host.name))
|
|
40107
40631
|
throw new Error("Setup requires lowercase vault names containing only letters, digits and dashes.");
|
|
40632
|
+
if (host.requestedGrants !== void 0 && !validEnrollmentRequestedGrants2(host.requestedGrants))
|
|
40633
|
+
throw new Error("invalid Claustrum enrollment requested grants");
|
|
40108
40634
|
}
|
|
40109
40635
|
}
|
|
40110
|
-
async function enrollmentReport(plugin, hosts, recorded) {
|
|
40636
|
+
async function enrollmentReport(plugin, hosts, recorded, recordedAccess) {
|
|
40111
40637
|
const report = [];
|
|
40112
40638
|
for (const host of hosts) {
|
|
40113
40639
|
let outcome = recorded.get(host) ?? "not-enrolled";
|
|
40640
|
+
let access = recordedAccess.get(host);
|
|
40114
40641
|
if (outcome === "unknown") {
|
|
40115
40642
|
const { name, paths } = plugin.vault.hosts[host];
|
|
40116
40643
|
const authority = await vaultAuthority3(hostEnrollmentPaths2(paths), name).catch(() => "unreadable");
|
|
@@ -40118,8 +40645,13 @@ async function enrollmentReport(plugin, hosts, recorded) {
|
|
|
40118
40645
|
outcome = "enrolled";
|
|
40119
40646
|
else if (authority === "local")
|
|
40120
40647
|
outcome = "not-enrolled";
|
|
40648
|
+
if (outcome === "enrolled") {
|
|
40649
|
+
const status = await readClaustrumEnrollmentStatus2(hostEnrollmentPaths2(paths), name).catch(() => void 0);
|
|
40650
|
+
if (status?.state === "approved")
|
|
40651
|
+
access = await confirmEnrollmentAccess({}, status, hostEnrollmentPaths2(paths).tokenPath, plugin.vault.hosts[host].requestedGrants);
|
|
40652
|
+
}
|
|
40121
40653
|
}
|
|
40122
|
-
report.push({ host, outcome });
|
|
40654
|
+
report.push({ host, outcome, ...access && { access } });
|
|
40123
40655
|
}
|
|
40124
40656
|
return report;
|
|
40125
40657
|
}
|
|
@@ -40248,6 +40780,7 @@ ${write.content}`);
|
|
|
40248
40780
|
piAgentDir: detection.pi.directory
|
|
40249
40781
|
};
|
|
40250
40782
|
const enrollment = /* @__PURE__ */ new Map();
|
|
40783
|
+
const enrollmentAccess = /* @__PURE__ */ new Map();
|
|
40251
40784
|
try {
|
|
40252
40785
|
for (const host of hosts) {
|
|
40253
40786
|
await stopped();
|
|
@@ -40256,7 +40789,9 @@ ${write.content}`);
|
|
|
40256
40789
|
if (useVault) {
|
|
40257
40790
|
enrollment.set(host, "unknown");
|
|
40258
40791
|
try {
|
|
40259
|
-
await connectSetupHost(plugin, host, io, terminal, stopped);
|
|
40792
|
+
const access = await connectSetupHost(plugin, host, io, terminal, stopped);
|
|
40793
|
+
if (access)
|
|
40794
|
+
enrollmentAccess.set(host, access);
|
|
40260
40795
|
} catch (error) {
|
|
40261
40796
|
if (error instanceof HostNotEnrolledError)
|
|
40262
40797
|
enrollment.set(host, "not-enrolled");
|
|
@@ -40281,7 +40816,7 @@ ${write.content}`);
|
|
|
40281
40816
|
if (enrollment.size === 0)
|
|
40282
40817
|
throw error;
|
|
40283
40818
|
try {
|
|
40284
|
-
const report = await enrollmentReport(plugin, hosts, enrollment);
|
|
40819
|
+
const report = await enrollmentReport(plugin, hosts, enrollment, enrollmentAccess);
|
|
40285
40820
|
recordSetupEnrollment(error, report);
|
|
40286
40821
|
for (const entry of report)
|
|
40287
40822
|
printLine2(terminal, setupEnrollmentLine(entry));
|
|
@@ -40437,7 +40972,7 @@ async function writeNativeSlot(host, slot, context, expectedAuthority = "local")
|
|
|
40437
40972
|
beforeRename: async () => {
|
|
40438
40973
|
await assertSetupHostsStopped();
|
|
40439
40974
|
const claustrum = await loadCommonAuthClaustrum();
|
|
40440
|
-
const stateDir = host === "opencode" ? openCodeVaultDir(
|
|
40975
|
+
const stateDir = host === "opencode" ? openCodeVaultDir(resolve22(accountFileForVault())) : getPiAntigravityVaultDir();
|
|
40441
40976
|
if (await claustrum.vaultAuthority(
|
|
40442
40977
|
claustrum.hostEnrollmentPaths({ stateDir, host }),
|
|
40443
40978
|
`antigravity-auth-${host}`
|
|
@@ -40471,17 +41006,31 @@ async function createSetupPlugin(deps, migrateOpenCode, forceLogin = false) {
|
|
|
40471
41006
|
const hosts = {
|
|
40472
41007
|
opencode: {
|
|
40473
41008
|
name: OPENCODE_VAULT_ENROLLMENT_NAME,
|
|
41009
|
+
displayName: "Antigravity sign-in for OpenCode",
|
|
41010
|
+
requestedGrants: [
|
|
41011
|
+
{
|
|
41012
|
+
selector: { category: "antigravity-native" },
|
|
41013
|
+
operation: "read"
|
|
41014
|
+
}
|
|
41015
|
+
],
|
|
40474
41016
|
// Read at each use: a real run settles the vault folder in
|
|
40475
41017
|
// `beforeSignIn`, which may move it after this plugin is built.
|
|
40476
41018
|
paths: {
|
|
40477
41019
|
get stateDir() {
|
|
40478
|
-
return openCodeVaultDir(
|
|
41020
|
+
return openCodeVaultDir(resolve22(accountFileForVault()));
|
|
40479
41021
|
},
|
|
40480
41022
|
host: "opencode"
|
|
40481
41023
|
}
|
|
40482
41024
|
},
|
|
40483
41025
|
pi: {
|
|
40484
41026
|
name: "antigravity-auth-pi",
|
|
41027
|
+
displayName: "Antigravity sign-in for Pi",
|
|
41028
|
+
requestedGrants: [
|
|
41029
|
+
{
|
|
41030
|
+
selector: { category: "antigravity-native" },
|
|
41031
|
+
operation: "read"
|
|
41032
|
+
}
|
|
41033
|
+
],
|
|
40485
41034
|
paths: { stateDir: piDir, host: "pi" }
|
|
40486
41035
|
}
|
|
40487
41036
|
};
|
|
@@ -40492,7 +41041,7 @@ async function createSetupPlugin(deps, migrateOpenCode, forceLogin = false) {
|
|
|
40492
41041
|
const assertLocal = async (host, context) => {
|
|
40493
41042
|
if (host === "opencode")
|
|
40494
41043
|
return assertLocalOpenCodeLogin(
|
|
40495
|
-
|
|
41044
|
+
resolve22(accountFileForVault()),
|
|
40496
41045
|
context.opencodeGeneration
|
|
40497
41046
|
);
|
|
40498
41047
|
if (await authority(host) !== "local")
|
|
@@ -41152,7 +41701,7 @@ async function runCliProcess(argv, deps) {
|
|
|
41152
41701
|
...deps,
|
|
41153
41702
|
prepareVaultFolder: deps.prepareVaultFolder ?? (async (options) => {
|
|
41154
41703
|
const folder = await prepareVaultFolder({
|
|
41155
|
-
accountFile:
|
|
41704
|
+
accountFile: resolve23(accountFileForVault()),
|
|
41156
41705
|
...options
|
|
41157
41706
|
});
|
|
41158
41707
|
if (folder.refusal) throw folder.refusal;
|
|
@@ -41198,11 +41747,11 @@ function createDefaultCliDependencies() {
|
|
|
41198
41747
|
);
|
|
41199
41748
|
if (host !== "pi")
|
|
41200
41749
|
await assertLocalOpenCodeLogin(
|
|
41201
|
-
|
|
41750
|
+
resolve23(accountFileForVault()),
|
|
41202
41751
|
context?.opencodeGeneration
|
|
41203
41752
|
);
|
|
41204
41753
|
const repository = host === "pi" ? void 0 : await prepareCliLoginStore(
|
|
41205
|
-
|
|
41754
|
+
resolve23(getStoragePath()),
|
|
41206
41755
|
context?.opencodeGeneration
|
|
41207
41756
|
);
|
|
41208
41757
|
try {
|
|
@@ -41218,7 +41767,7 @@ function createDefaultCliDependencies() {
|
|
|
41218
41767
|
}
|
|
41219
41768
|
if (host === "opencode") await assertSetupHostsStopped();
|
|
41220
41769
|
await assertLocalOpenCodeLogin(
|
|
41221
|
-
|
|
41770
|
+
resolve23(accountFileForVault()),
|
|
41222
41771
|
context?.opencodeGeneration
|
|
41223
41772
|
);
|
|
41224
41773
|
await persistCliStoreLogin(
|
|
@@ -41238,7 +41787,7 @@ function createDefaultCliDependencies() {
|
|
|
41238
41787
|
};
|
|
41239
41788
|
}
|
|
41240
41789
|
async function prepareCliLoginStore(legacyPath, generation) {
|
|
41241
|
-
await assertLocalOpenCodeLogin(
|
|
41790
|
+
await assertLocalOpenCodeLogin(resolve23(accountFileForVault()), generation);
|
|
41242
41791
|
const modules = await loadCommonAuthStoreModules();
|
|
41243
41792
|
const options = {
|
|
41244
41793
|
legacyPath,
|
|
@@ -41383,7 +41932,7 @@ async function readAccountStore(legacyPath) {
|
|
|
41383
41932
|
function createDefaultAccountStoreOperations() {
|
|
41384
41933
|
const offline = { processesStopped: true };
|
|
41385
41934
|
return {
|
|
41386
|
-
legacyPath: () =>
|
|
41935
|
+
legacyPath: () => resolve23(
|
|
41387
41936
|
decidedAccountStoreAnchor(runtimeLayoutLocation()) ? getStoragePath() : discoveredAccountFile()
|
|
41388
41937
|
),
|
|
41389
41938
|
migrate: async (legacyPath) => createAccountMigrationFactory(await loadCommonAuthStoreModules())({
|
|
@@ -41414,7 +41963,7 @@ function createDefaultAccountStoreOperations() {
|
|
|
41414
41963
|
};
|
|
41415
41964
|
}
|
|
41416
41965
|
function samePath(left, right) {
|
|
41417
|
-
return process.platform === "win32" ?
|
|
41966
|
+
return process.platform === "win32" ? resolve23(left).toLowerCase() === resolve23(right).toLowerCase() : resolve23(left) === resolve23(right);
|
|
41418
41967
|
}
|
|
41419
41968
|
function isCliEntry() {
|
|
41420
41969
|
if (import.meta.main !== void 0) return import.meta.main;
|
|
@@ -41904,14 +42453,14 @@ function isTuiConnected(sessionId) {
|
|
|
41904
42453
|
// src/rpc/rpc-dir.ts
|
|
41905
42454
|
import { createHash as createHash14 } from "node:crypto";
|
|
41906
42455
|
import { homedir as homedir10, tmpdir as tmpdir4 } from "node:os";
|
|
41907
|
-
import { isAbsolute as isAbsolute5, join as join28, resolve as
|
|
42456
|
+
import { isAbsolute as isAbsolute5, join as join28, resolve as resolve24 } from "node:path";
|
|
41908
42457
|
var RPC_DIR_ENV = "ANTIGRAVITY_AUTH_RPC_DIR";
|
|
41909
42458
|
function getRpcDir(projectDirectory) {
|
|
41910
42459
|
const override = process.env[RPC_DIR_ENV]?.trim();
|
|
41911
42460
|
if (override) {
|
|
41912
|
-
return isAbsolute5(override) ? override :
|
|
42461
|
+
return isAbsolute5(override) ? override : resolve24(projectDirectory, override);
|
|
41913
42462
|
}
|
|
41914
|
-
const projectHash = createHash14("sha256").update(
|
|
42463
|
+
const projectHash = createHash14("sha256").update(resolve24(projectDirectory)).digest("hex").slice(0, 16);
|
|
41915
42464
|
const stateHome = process.env.XDG_STATE_HOME ?? join28(homedir10(), ".local", "state");
|
|
41916
42465
|
return join28(stateHome, "cortexkit", "antigravity-auth", "rpc", projectHash);
|
|
41917
42466
|
}
|
|
@@ -41926,7 +42475,7 @@ init_private_files2();
|
|
|
41926
42475
|
import { createHash as createHash15, randomUUID as randomUUID19 } from "node:crypto";
|
|
41927
42476
|
import { chmod as chmod7, mkdir as mkdir17, open as open12, readdir as readdir4, rename as rename14, rmdir as rmdir3, stat as stat17, unlink as unlink13 } from "node:fs/promises";
|
|
41928
42477
|
import { uptime as uptime2 } from "node:os";
|
|
41929
|
-
import { join as join29, resolve as
|
|
42478
|
+
import { join as join29, resolve as resolve25 } from "node:path";
|
|
41930
42479
|
function staleBefore(clock2) {
|
|
41931
42480
|
return (clock2.now ?? Date.now)() - (clock2.uptime ?? uptime2)() * 1e3 - 3e5;
|
|
41932
42481
|
}
|
|
@@ -42036,7 +42585,7 @@ async function sweepRpcState(root, activeDir, isManagedDir, log17, options = {})
|
|
|
42036
42585
|
return;
|
|
42037
42586
|
throw error;
|
|
42038
42587
|
}
|
|
42039
|
-
const active2 =
|
|
42588
|
+
const active2 = resolve25(activeDir);
|
|
42040
42589
|
for (const projectDir of projectDirs) {
|
|
42041
42590
|
if (!projectDir.isDirectory() || !isManagedDir(projectDir.name)) {
|
|
42042
42591
|
continue;
|
|
@@ -42083,7 +42632,7 @@ async function sweepRpcState(root, activeDir, isManagedDir, log17, options = {})
|
|
|
42083
42632
|
else if (isStalePortFile(entry, info, cutoff))
|
|
42084
42633
|
await removeStalePortFile(portFile, raw, info, options.beforeRemove);
|
|
42085
42634
|
}
|
|
42086
|
-
if (
|
|
42635
|
+
if (resolve25(dir) !== active2)
|
|
42087
42636
|
await rmdir3(dir).catch(() => {
|
|
42088
42637
|
});
|
|
42089
42638
|
}
|
|
@@ -42117,7 +42666,7 @@ var BodyTooLargeError = class extends Error {
|
|
|
42117
42666
|
}
|
|
42118
42667
|
};
|
|
42119
42668
|
function readBody(req) {
|
|
42120
|
-
return new Promise((
|
|
42669
|
+
return new Promise((resolve29, reject) => {
|
|
42121
42670
|
const tooLarge = (declaredOversize = false) => {
|
|
42122
42671
|
req.removeAllListeners("data");
|
|
42123
42672
|
req.on("data", () => {
|
|
@@ -42140,7 +42689,7 @@ function readBody(req) {
|
|
|
42140
42689
|
}
|
|
42141
42690
|
chunks.push(chunk);
|
|
42142
42691
|
});
|
|
42143
|
-
req.on("end", () =>
|
|
42692
|
+
req.on("end", () => resolve29(Buffer.concat(chunks).toString("utf8")));
|
|
42144
42693
|
req.on("error", reject);
|
|
42145
42694
|
});
|
|
42146
42695
|
}
|
|
@@ -42319,12 +42868,12 @@ async function startRpcServer(options) {
|
|
|
42319
42868
|
json(500, { error: "internal error" });
|
|
42320
42869
|
}
|
|
42321
42870
|
}
|
|
42322
|
-
const port = await new Promise((
|
|
42871
|
+
const port = await new Promise((resolve29, reject) => {
|
|
42323
42872
|
server.on("error", reject);
|
|
42324
42873
|
server.listen(0, "127.0.0.1", () => {
|
|
42325
42874
|
const addr = server.address();
|
|
42326
42875
|
if (addr && typeof addr === "object")
|
|
42327
|
-
|
|
42876
|
+
resolve29(addr.port);
|
|
42328
42877
|
else
|
|
42329
42878
|
reject(new Error("no port"));
|
|
42330
42879
|
});
|
|
@@ -42347,16 +42896,16 @@ async function startRpcServer(options) {
|
|
|
42347
42896
|
rpcPort: port
|
|
42348
42897
|
});
|
|
42349
42898
|
} catch (error) {
|
|
42350
|
-
await new Promise((
|
|
42899
|
+
await new Promise((resolve29) => server.close(() => resolve29()));
|
|
42351
42900
|
throw error;
|
|
42352
42901
|
}
|
|
42353
42902
|
return {
|
|
42354
42903
|
port,
|
|
42355
42904
|
token,
|
|
42356
42905
|
async stop() {
|
|
42357
|
-
await new Promise((
|
|
42906
|
+
await new Promise((resolve29) => {
|
|
42358
42907
|
server.closeAllConnections?.();
|
|
42359
|
-
server.close(() =>
|
|
42908
|
+
server.close(() => resolve29());
|
|
42360
42909
|
for (const socket of connections)
|
|
42361
42910
|
socket.destroy();
|
|
42362
42911
|
});
|
|
@@ -43733,7 +44282,7 @@ async function select3(items, options) {
|
|
|
43733
44282
|
}
|
|
43734
44283
|
renderedLines = linesWritten;
|
|
43735
44284
|
};
|
|
43736
|
-
return new Promise((
|
|
44285
|
+
return new Promise((resolve29) => {
|
|
43737
44286
|
const wasRaw = stdin.isRaw ?? false;
|
|
43738
44287
|
const cleanup2 = () => {
|
|
43739
44288
|
if (isCleanedUp) return;
|
|
@@ -43754,11 +44303,11 @@ async function select3(items, options) {
|
|
|
43754
44303
|
};
|
|
43755
44304
|
const onSignal = () => {
|
|
43756
44305
|
cleanup2();
|
|
43757
|
-
|
|
44306
|
+
resolve29(null);
|
|
43758
44307
|
};
|
|
43759
44308
|
const finishWithValue = (value) => {
|
|
43760
44309
|
cleanup2();
|
|
43761
|
-
|
|
44310
|
+
resolve29(value);
|
|
43762
44311
|
};
|
|
43763
44312
|
const findNextSelectable = (from, direction) => {
|
|
43764
44313
|
if (items.length === 0) return from;
|
|
@@ -43804,7 +44353,7 @@ async function select3(items, options) {
|
|
|
43804
44353
|
stdin.setRawMode(true);
|
|
43805
44354
|
} catch {
|
|
43806
44355
|
cleanup2();
|
|
43807
|
-
|
|
44356
|
+
resolve29(null);
|
|
43808
44357
|
return;
|
|
43809
44358
|
}
|
|
43810
44359
|
stdin.resume();
|
|
@@ -46570,7 +47119,7 @@ init_runtime_paths();
|
|
|
46570
47119
|
init_logger4();
|
|
46571
47120
|
import { existsSync as existsSync11, readFileSync as readFileSync11, realpathSync as realpathSync5 } from "node:fs";
|
|
46572
47121
|
import { homedir as homedir12 } from "node:os";
|
|
46573
|
-
import { basename as basename7, dirname as dirname25, join as join33, resolve as
|
|
47122
|
+
import { basename as basename7, dirname as dirname25, join as join33, resolve as resolve26 } from "node:path";
|
|
46574
47123
|
|
|
46575
47124
|
// src/plugin/config/schema.ts
|
|
46576
47125
|
import { z } from "zod";
|
|
@@ -47128,7 +47677,7 @@ function loadConfigWithLogger(directory, log17) {
|
|
|
47128
47677
|
return config;
|
|
47129
47678
|
}
|
|
47130
47679
|
function canonicalizeOwnedPath(path5) {
|
|
47131
|
-
const absolute =
|
|
47680
|
+
const absolute = resolve26(path5);
|
|
47132
47681
|
const missing = [];
|
|
47133
47682
|
let current = absolute;
|
|
47134
47683
|
for (; ; ) {
|
|
@@ -47979,11 +48528,11 @@ function redactForDump(value) {
|
|
|
47979
48528
|
function headersToRecord2(headers) {
|
|
47980
48529
|
if (!headers) return {};
|
|
47981
48530
|
if (headers instanceof Headers) {
|
|
47982
|
-
const
|
|
48531
|
+
const record4 = {};
|
|
47983
48532
|
headers.forEach((value, key) => {
|
|
47984
|
-
|
|
48533
|
+
record4[key] = value;
|
|
47985
48534
|
});
|
|
47986
|
-
return
|
|
48535
|
+
return record4;
|
|
47987
48536
|
}
|
|
47988
48537
|
if (Array.isArray(headers)) return Object.fromEntries(headers);
|
|
47989
48538
|
return { ...headers };
|
|
@@ -48004,8 +48553,8 @@ function collectToolNames(value) {
|
|
|
48004
48553
|
return;
|
|
48005
48554
|
}
|
|
48006
48555
|
if (!entry || typeof entry !== "object") return;
|
|
48007
|
-
const
|
|
48008
|
-
const declarations =
|
|
48556
|
+
const record4 = entry;
|
|
48557
|
+
const declarations = record4.functionDeclarations;
|
|
48009
48558
|
if (Array.isArray(declarations)) {
|
|
48010
48559
|
for (const declaration of declarations) {
|
|
48011
48560
|
if (declaration && typeof declaration === "object") {
|
|
@@ -48014,7 +48563,7 @@ function collectToolNames(value) {
|
|
|
48014
48563
|
}
|
|
48015
48564
|
}
|
|
48016
48565
|
}
|
|
48017
|
-
for (const item of Object.values(
|
|
48566
|
+
for (const item of Object.values(record4)) walk(item);
|
|
48018
48567
|
};
|
|
48019
48568
|
walk(value);
|
|
48020
48569
|
return names;
|
|
@@ -49321,9 +49870,9 @@ function normalizeThinkingConfig(config) {
|
|
|
49321
49870
|
if (!config || typeof config !== "object") {
|
|
49322
49871
|
return void 0;
|
|
49323
49872
|
}
|
|
49324
|
-
const
|
|
49325
|
-
const budgetRaw =
|
|
49326
|
-
const includeRaw =
|
|
49873
|
+
const record4 = config;
|
|
49874
|
+
const budgetRaw = record4.thinkingBudget ?? record4.thinking_budget;
|
|
49875
|
+
const includeRaw = record4.includeThoughts ?? record4.include_thoughts;
|
|
49327
49876
|
const thinkingBudget = typeof budgetRaw === "number" && Number.isFinite(budgetRaw) ? budgetRaw : void 0;
|
|
49328
49877
|
const includeThoughts = typeof includeRaw === "boolean" ? includeRaw : void 0;
|
|
49329
49878
|
const enableThinking = thinkingBudget !== void 0 && thinkingBudget > 0;
|
|
@@ -50205,8 +50754,8 @@ function collectForwardedHeaders(sourceHeaders) {
|
|
|
50205
50754
|
if (typeof sourceHeaders.get === "function") {
|
|
50206
50755
|
return sourceHeaders.get(name);
|
|
50207
50756
|
}
|
|
50208
|
-
const
|
|
50209
|
-
for (const [key, value] of Object.entries(
|
|
50757
|
+
const record4 = sourceHeaders;
|
|
50758
|
+
for (const [key, value] of Object.entries(record4)) {
|
|
50210
50759
|
if (key.toLowerCase() === name) return value;
|
|
50211
50760
|
}
|
|
50212
50761
|
return void 0;
|
|
@@ -50243,14 +50792,14 @@ function hasStructuredQuotaReason(details) {
|
|
|
50243
50792
|
if (!Array.isArray(details)) return false;
|
|
50244
50793
|
return details.some((detail) => {
|
|
50245
50794
|
if (!detail || typeof detail !== "object") return false;
|
|
50246
|
-
const
|
|
50247
|
-
const type =
|
|
50795
|
+
const record4 = detail;
|
|
50796
|
+
const type = record4["@type"];
|
|
50248
50797
|
if (typeof type === "string" && type.includes("google.rpc.QuotaFailure"))
|
|
50249
50798
|
return true;
|
|
50250
|
-
const reason =
|
|
50799
|
+
const reason = record4.reason;
|
|
50251
50800
|
if (typeof reason === "string" && QUOTA_REASON_CODES.has(reason))
|
|
50252
50801
|
return true;
|
|
50253
|
-
const nested =
|
|
50802
|
+
const nested = record4.details;
|
|
50254
50803
|
return Array.isArray(nested) ? hasStructuredQuotaReason(nested) : false;
|
|
50255
50804
|
});
|
|
50256
50805
|
}
|
|
@@ -50436,8 +50985,8 @@ function resolveRetryMetadata(options) {
|
|
|
50436
50985
|
if (typeof headers.get === "function") {
|
|
50437
50986
|
return headers.get(name);
|
|
50438
50987
|
}
|
|
50439
|
-
const
|
|
50440
|
-
for (const [key, value] of Object.entries(
|
|
50988
|
+
const record4 = headers;
|
|
50989
|
+
for (const [key, value] of Object.entries(record4)) {
|
|
50441
50990
|
if (key.toLowerCase() === name) return value;
|
|
50442
50991
|
}
|
|
50443
50992
|
return void 0;
|
|
@@ -50564,14 +51113,14 @@ function stripAllThinkingBlocks2(contents) {
|
|
|
50564
51113
|
});
|
|
50565
51114
|
}
|
|
50566
51115
|
function countTrailingToolResults(contents) {
|
|
50567
|
-
let
|
|
51116
|
+
let count4 = 0;
|
|
50568
51117
|
for (let i = contents.length - 1; i >= 0; i--) {
|
|
50569
51118
|
const msg = contents[i];
|
|
50570
51119
|
if (msg?.role === "user") {
|
|
50571
51120
|
const parts = msg.parts || [];
|
|
50572
51121
|
const functionResponses = parts.filter(isFunctionResponsePart);
|
|
50573
51122
|
if (functionResponses.length > 0) {
|
|
50574
|
-
|
|
51123
|
+
count4 += functionResponses.length;
|
|
50575
51124
|
} else {
|
|
50576
51125
|
break;
|
|
50577
51126
|
}
|
|
@@ -50579,7 +51128,7 @@ function countTrailingToolResults(contents) {
|
|
|
50579
51128
|
break;
|
|
50580
51129
|
}
|
|
50581
51130
|
}
|
|
50582
|
-
return
|
|
51131
|
+
return count4;
|
|
50583
51132
|
}
|
|
50584
51133
|
function closeToolLoopForThinking(contents) {
|
|
50585
51134
|
const strippedContents = stripAllThinkingBlocks2(contents);
|
|
@@ -50905,12 +51454,12 @@ function stripInjectedDebugFromParts(parts) {
|
|
|
50905
51454
|
if (!part || typeof part !== "object") {
|
|
50906
51455
|
return part;
|
|
50907
51456
|
}
|
|
50908
|
-
const
|
|
50909
|
-
const text2 = typeof
|
|
51457
|
+
const record4 = part;
|
|
51458
|
+
const text2 = typeof record4.text === "string" ? record4.text : typeof record4.thinking === "string" ? record4.thinking : void 0;
|
|
50910
51459
|
if (text2 && (text2.startsWith(DEBUG_MESSAGE_PREFIX) || text2.startsWith(SYNTHETIC_THINKING_PLACEHOLDER.trim()))) {
|
|
50911
51460
|
const sentinel = { text: "." };
|
|
50912
|
-
if (
|
|
50913
|
-
sentinel.cache_control =
|
|
51461
|
+
if (record4.cache_control !== void 0)
|
|
51462
|
+
sentinel.cache_control = record4.cache_control;
|
|
50914
51463
|
return sentinel;
|
|
50915
51464
|
}
|
|
50916
51465
|
return part;
|
|
@@ -50954,8 +51503,8 @@ function isValidRequestPart(part) {
|
|
|
50954
51503
|
if (!part || typeof part !== "object") {
|
|
50955
51504
|
return false;
|
|
50956
51505
|
}
|
|
50957
|
-
const
|
|
50958
|
-
return Object.hasOwn(
|
|
51506
|
+
const record4 = part;
|
|
51507
|
+
return Object.hasOwn(record4, "text") || Object.hasOwn(record4, "functionCall") || Object.hasOwn(record4, "functionResponse") || Object.hasOwn(record4, "inlineData") || Object.hasOwn(record4, "fileData") || Object.hasOwn(record4, "executableCode") || Object.hasOwn(record4, "codeExecutionResult") || Object.hasOwn(record4, "thought");
|
|
50959
51508
|
}
|
|
50960
51509
|
function stripCacheControlFromParts(parts) {
|
|
50961
51510
|
if (!Array.isArray(parts)) {
|
|
@@ -50965,9 +51514,9 @@ function stripCacheControlFromParts(parts) {
|
|
|
50965
51514
|
if (!part || typeof part !== "object" || Array.isArray(part)) {
|
|
50966
51515
|
continue;
|
|
50967
51516
|
}
|
|
50968
|
-
const
|
|
50969
|
-
delete
|
|
50970
|
-
delete
|
|
51517
|
+
const record4 = part;
|
|
51518
|
+
delete record4.cache_control;
|
|
51519
|
+
delete record4.cacheControl;
|
|
50971
51520
|
}
|
|
50972
51521
|
}
|
|
50973
51522
|
function stripUnsupportedAntigravityFields(payload) {
|
|
@@ -50995,9 +51544,9 @@ function stripUnsupportedAntigravityFields(payload) {
|
|
|
50995
51544
|
if (!item || typeof item !== "object" || Array.isArray(item)) {
|
|
50996
51545
|
continue;
|
|
50997
51546
|
}
|
|
50998
|
-
const
|
|
50999
|
-
stripCacheControlFromParts(
|
|
51000
|
-
stripCacheControlFromParts(
|
|
51547
|
+
const record4 = item;
|
|
51548
|
+
stripCacheControlFromParts(record4.parts);
|
|
51549
|
+
stripCacheControlFromParts(record4.content);
|
|
51001
51550
|
}
|
|
51002
51551
|
};
|
|
51003
51552
|
stripContentParts(payload.contents);
|
|
@@ -51013,7 +51562,7 @@ function stripUnsupportedAntigravityFields(payload) {
|
|
|
51013
51562
|
}
|
|
51014
51563
|
}
|
|
51015
51564
|
function configureAntigravityToolCalling(payload, wireModel) {
|
|
51016
|
-
if (isGeminiArgonModel(wireModel) || !Array.isArray(payload.tools) || payload.tools.length === 0) {
|
|
51565
|
+
if (isGeminiArgonModel(wireModel) || isGeminiCarbonModel(wireModel) || !Array.isArray(payload.tools) || payload.tools.length === 0) {
|
|
51017
51566
|
delete payload.toolConfig;
|
|
51018
51567
|
return;
|
|
51019
51568
|
}
|
|
@@ -51045,14 +51594,14 @@ function normalizeNativeFunctionResponseRoles(payload) {
|
|
|
51045
51594
|
}
|
|
51046
51595
|
for (const content of contents) {
|
|
51047
51596
|
if (!content || typeof content !== "object") continue;
|
|
51048
|
-
const
|
|
51049
|
-
if (
|
|
51050
|
-
if (
|
|
51051
|
-
const sameTarget =
|
|
51597
|
+
const record4 = content;
|
|
51598
|
+
if (record4.role !== "user" || !Array.isArray(record4.parts)) continue;
|
|
51599
|
+
if (record4.parts.length === 0) continue;
|
|
51600
|
+
const sameTarget = record4.parts.every((part) => {
|
|
51052
51601
|
const response = part?.functionResponse;
|
|
51053
51602
|
return response !== void 0 && signedCalls.has(String(response.id ?? response.name));
|
|
51054
51603
|
});
|
|
51055
|
-
if (sameTarget)
|
|
51604
|
+
if (sameTarget) record4.role = "model";
|
|
51056
51605
|
}
|
|
51057
51606
|
}
|
|
51058
51607
|
function sanitizeRequestPayloadForAntigravity(payload) {
|
|
@@ -51146,10 +51695,10 @@ function sanitizeRequestPayloadForAntigravity(payload) {
|
|
|
51146
51695
|
if (Array.isArray(sys.parts)) {
|
|
51147
51696
|
const sanitizedSystemParts = sys.parts.map((part) => {
|
|
51148
51697
|
if (isValidRequestPart(part)) return part;
|
|
51149
|
-
const
|
|
51698
|
+
const record4 = part;
|
|
51150
51699
|
const sentinel = { text: "." };
|
|
51151
|
-
if (
|
|
51152
|
-
sentinel.cache_control =
|
|
51700
|
+
if (record4?.cache_control !== void 0)
|
|
51701
|
+
sentinel.cache_control = record4.cache_control;
|
|
51153
51702
|
return sentinel;
|
|
51154
51703
|
});
|
|
51155
51704
|
const hasRealContent = sanitizedSystemParts.some(
|
|
@@ -51636,7 +52185,7 @@ function prepareAntigravityRequestIn(wire, input2, init, accessToken, projectId,
|
|
|
51636
52185
|
`[ThinkingResolution] rawModel=${rawModel} resolvedModel=${effectiveModel} resolvedTier=${tierThinkingLevel ?? "none"} variantLevel=${variantConfig?.thinkingLevel ?? "none"} variantBudget=${variantConfig?.thinkingBudget ?? "none"} providerOptions.google=${JSON.stringify(requestPayload.providerOptions?.google ?? null)} generationConfig.thinkingConfig=${JSON.stringify(rawGenerationConfig?.thinkingConfig ?? null)}`
|
|
51637
52186
|
);
|
|
51638
52187
|
delete requestPayload.providerOptions;
|
|
51639
|
-
if (variantConfig?.thinkingLevel && (isGemini3 || isGeminiArgonModel(effectiveModel) || getAgyNativeModel(effectiveModel)?.supportsAdaptiveThinking)) {
|
|
52188
|
+
if (variantConfig?.thinkingLevel && (isGemini3 || isGeminiArgonModel(effectiveModel) || isGeminiCarbonModel(effectiveModel) || getAgyNativeModel(effectiveModel)?.supportsAdaptiveThinking)) {
|
|
51640
52189
|
const variantModelBase = rawModel.replace(/-preview-customtools$/i, "").replace(/-preview$/i, "").replace(/-(minimal|low|medium|high)$/i, "");
|
|
51641
52190
|
const variantResolved = resolveAntigravityModel(
|
|
51642
52191
|
`${variantModelBase}-${variantConfig.thinkingLevel}`
|
|
@@ -52580,10 +53129,10 @@ async function retainResponseLifetime(response, cancellation) {
|
|
|
52580
53129
|
cancellation.release();
|
|
52581
53130
|
throw error;
|
|
52582
53131
|
}
|
|
52583
|
-
let
|
|
53132
|
+
let resolve29 = () => {
|
|
52584
53133
|
};
|
|
52585
53134
|
const settled = new Promise((done) => {
|
|
52586
|
-
|
|
53135
|
+
resolve29 = done;
|
|
52587
53136
|
});
|
|
52588
53137
|
let stopping = false;
|
|
52589
53138
|
let finished = false;
|
|
@@ -52593,7 +53142,7 @@ async function retainResponseLifetime(response, cancellation) {
|
|
|
52593
53142
|
finished = true;
|
|
52594
53143
|
cancellation.signal.removeEventListener("abort", abort);
|
|
52595
53144
|
cancellation.release();
|
|
52596
|
-
|
|
53145
|
+
resolve29();
|
|
52597
53146
|
};
|
|
52598
53147
|
const abort = () => {
|
|
52599
53148
|
if (finished || stopping) return;
|
|
@@ -52662,8 +53211,8 @@ function createAfterHandoff(work, signals, onFailure) {
|
|
|
52662
53211
|
let running = false;
|
|
52663
53212
|
let resolveCompletion = () => {
|
|
52664
53213
|
};
|
|
52665
|
-
const completion = new Promise((
|
|
52666
|
-
resolveCompletion =
|
|
53214
|
+
const completion = new Promise((resolve29) => {
|
|
53215
|
+
resolveCompletion = resolve29;
|
|
52667
53216
|
});
|
|
52668
53217
|
const finish = () => {
|
|
52669
53218
|
if (finished) return;
|
|
@@ -52710,14 +53259,14 @@ function createAfterHandoff(work, signals, onFailure) {
|
|
|
52710
53259
|
};
|
|
52711
53260
|
}
|
|
52712
53261
|
function publishResponse(dispatch) {
|
|
52713
|
-
return new Promise((
|
|
53262
|
+
return new Promise((resolve29, reject) => {
|
|
52714
53263
|
let acknowledge;
|
|
52715
53264
|
void Promise.resolve().then(
|
|
52716
53265
|
() => dispatch((callback) => {
|
|
52717
53266
|
acknowledge = callback;
|
|
52718
53267
|
})
|
|
52719
53268
|
).then((response) => {
|
|
52720
|
-
|
|
53269
|
+
resolve29(response);
|
|
52721
53270
|
acknowledge?.();
|
|
52722
53271
|
}, reject);
|
|
52723
53272
|
});
|
|
@@ -54551,10 +55100,10 @@ function resolvePluginDependencies(overrides = {}) {
|
|
|
54551
55100
|
}
|
|
54552
55101
|
async function defaultSleep(ms, signal) {
|
|
54553
55102
|
if (ms <= 0) return;
|
|
54554
|
-
await new Promise((
|
|
55103
|
+
await new Promise((resolve29, reject) => {
|
|
54555
55104
|
const timer = setTimeout(() => {
|
|
54556
55105
|
signal?.removeEventListener("abort", onAbort);
|
|
54557
|
-
|
|
55106
|
+
resolve29();
|
|
54558
55107
|
}, ms);
|
|
54559
55108
|
timer.unref?.();
|
|
54560
55109
|
const onAbort = () => {
|
|
@@ -54685,10 +55234,72 @@ function routingHandle(sessionId) {
|
|
|
54685
55234
|
return typeof handle === "object" && handle !== null ? handle : void 0;
|
|
54686
55235
|
}
|
|
54687
55236
|
|
|
55237
|
+
// src/common-auth-embedded/routing-accessor/cache-policy.js
|
|
55238
|
+
var CACHE_WARM_STOP_REASONS = [
|
|
55239
|
+
"cost-cap",
|
|
55240
|
+
"count-cap",
|
|
55241
|
+
"outside-hours",
|
|
55242
|
+
"session-ended",
|
|
55243
|
+
"unsupported"
|
|
55244
|
+
];
|
|
55245
|
+
function isCacheWarmStopReason(value) {
|
|
55246
|
+
return CACHE_WARM_STOP_REASONS.some((reason) => reason === value);
|
|
55247
|
+
}
|
|
55248
|
+
|
|
54688
55249
|
// src/common-auth-embedded/routing-accessor/index.js
|
|
54689
55250
|
function isObject2(value) {
|
|
54690
55251
|
return typeof value === "object" && value !== null;
|
|
54691
55252
|
}
|
|
55253
|
+
function isNonEmptyString(value) {
|
|
55254
|
+
return typeof value === "string" && value.length > 0;
|
|
55255
|
+
}
|
|
55256
|
+
function billingCache(value) {
|
|
55257
|
+
if (!isObject2(value) || Array.isArray(value))
|
|
55258
|
+
return;
|
|
55259
|
+
const { ttlMs, implicit, warming } = value;
|
|
55260
|
+
const cache = {};
|
|
55261
|
+
if (!(ttlMs !== void 0 && implicit !== void 0)) {
|
|
55262
|
+
if (typeof ttlMs === "number" && Number.isSafeInteger(ttlMs) && ttlMs > 0) {
|
|
55263
|
+
cache.ttl_ms = ttlMs;
|
|
55264
|
+
} else if (implicit === true) {
|
|
55265
|
+
cache.implicit = true;
|
|
55266
|
+
}
|
|
55267
|
+
}
|
|
55268
|
+
if (isObject2(warming) && !Array.isArray(warming)) {
|
|
55269
|
+
const { on, stopReason } = warming;
|
|
55270
|
+
if (typeof on === "boolean") {
|
|
55271
|
+
cache.warming = {
|
|
55272
|
+
on,
|
|
55273
|
+
...!on && isCacheWarmStopReason(stopReason) ? { stop_reason: stopReason } : {}
|
|
55274
|
+
};
|
|
55275
|
+
}
|
|
55276
|
+
}
|
|
55277
|
+
return Object.keys(cache).length > 0 ? cache : void 0;
|
|
55278
|
+
}
|
|
55279
|
+
function billingUsage(value) {
|
|
55280
|
+
if (!isObject2(value) || Array.isArray(value))
|
|
55281
|
+
return;
|
|
55282
|
+
const usage = {};
|
|
55283
|
+
for (const [inputKey, payloadKey] of [
|
|
55284
|
+
["input", "input"],
|
|
55285
|
+
["output", "output"],
|
|
55286
|
+
["cacheRead", "cache_read"],
|
|
55287
|
+
["cacheWrite", "cache_write"],
|
|
55288
|
+
["cacheWrite5m", "cache_write_5m"],
|
|
55289
|
+
["cacheWrite1h", "cache_write_1h"],
|
|
55290
|
+
["reasoning", "reasoning"]
|
|
55291
|
+
]) {
|
|
55292
|
+
const count4 = value[inputKey];
|
|
55293
|
+
if (typeof count4 === "number" && Number.isSafeInteger(count4) && count4 >= 0) {
|
|
55294
|
+
usage[payloadKey] = count4;
|
|
55295
|
+
}
|
|
55296
|
+
}
|
|
55297
|
+
const reasoningIncludedInOutput = value.reasoningIncludedInOutput;
|
|
55298
|
+
if (typeof reasoningIncludedInOutput === "boolean") {
|
|
55299
|
+
usage.reasoning_included_in_output = reasoningIncludedInOutput;
|
|
55300
|
+
}
|
|
55301
|
+
return Object.keys(usage).length > 0 ? usage : void 0;
|
|
55302
|
+
}
|
|
54692
55303
|
function selectionFor(answer, candidates) {
|
|
54693
55304
|
if (!isObject2(answer))
|
|
54694
55305
|
return void 0;
|
|
@@ -54720,8 +55331,8 @@ async function askRouting(input2) {
|
|
|
54720
55331
|
return void 0;
|
|
54721
55332
|
const requested = input2.deadlineMs ?? 500;
|
|
54722
55333
|
const deadlineMs = Number.isNaN(requested) ? 500 : Math.min(2e3, Math.max(1, requested));
|
|
54723
|
-
const expired = new Promise((
|
|
54724
|
-
timer = setTimeout(() =>
|
|
55334
|
+
const expired = new Promise((resolve29) => {
|
|
55335
|
+
timer = setTimeout(() => resolve29(void 0), deadlineMs);
|
|
54725
55336
|
timer.unref();
|
|
54726
55337
|
});
|
|
54727
55338
|
const request2 = {
|
|
@@ -54754,6 +55365,47 @@ function reportRouting(input2) {
|
|
|
54754
55365
|
let payload;
|
|
54755
55366
|
if ("kind" in input2) {
|
|
54756
55367
|
switch (input2.kind) {
|
|
55368
|
+
case "billing": {
|
|
55369
|
+
const { attemptId, requestKind, credentialId, provider: provider2, model, outcome, accountId, providerRequestId, providerResponseId, userMessageId, status, attempt, chargeBasis, usage: inputUsage, usageByModel: inputUsageByModel, cache: inputCache } = input2;
|
|
55370
|
+
if (!isNonEmptyString(attemptId) || !isNonEmptyString(credentialId) || !isNonEmptyString(provider2) || !isNonEmptyString(model) || requestKind !== "primary" && requestKind !== "title" && requestKind !== "compaction" && requestKind !== "generate" && requestKind !== "keep_warm" && requestKind !== "prime" || outcome !== "completed" && outcome !== "cut" && outcome !== "failed")
|
|
55371
|
+
return;
|
|
55372
|
+
const usage = billingUsage(inputUsage);
|
|
55373
|
+
const cache = billingCache(inputCache);
|
|
55374
|
+
const usageByModel = [];
|
|
55375
|
+
if (Array.isArray(inputUsageByModel)) {
|
|
55376
|
+
for (const entry of inputUsageByModel) {
|
|
55377
|
+
if (!isObject2(entry) || Array.isArray(entry))
|
|
55378
|
+
continue;
|
|
55379
|
+
const modelUsed = entry.modelUsed;
|
|
55380
|
+
if (!isNonEmptyString(modelUsed))
|
|
55381
|
+
continue;
|
|
55382
|
+
const modelUsage = billingUsage(entry.usage);
|
|
55383
|
+
if (!modelUsage)
|
|
55384
|
+
continue;
|
|
55385
|
+
usageByModel.push({ model_used: modelUsed, usage: modelUsage });
|
|
55386
|
+
}
|
|
55387
|
+
}
|
|
55388
|
+
payload = {
|
|
55389
|
+
kind: "billing",
|
|
55390
|
+
attempt_id: attemptId,
|
|
55391
|
+
request_kind: requestKind,
|
|
55392
|
+
credential_id: credentialId,
|
|
55393
|
+
provider: provider2,
|
|
55394
|
+
model,
|
|
55395
|
+
outcome,
|
|
55396
|
+
...isNonEmptyString(accountId) ? { account_id: accountId } : {},
|
|
55397
|
+
...isNonEmptyString(providerRequestId) ? { provider_request_id: providerRequestId } : {},
|
|
55398
|
+
...isNonEmptyString(providerResponseId) ? { provider_response_id: providerResponseId } : {},
|
|
55399
|
+
...isNonEmptyString(userMessageId) ? { user_message_id: userMessageId } : {},
|
|
55400
|
+
...typeof status === "number" && Number.isInteger(status) && status >= 0 ? { status } : {},
|
|
55401
|
+
...typeof attempt === "number" && Number.isInteger(attempt) && attempt >= 1 ? { attempt } : {},
|
|
55402
|
+
...chargeBasis === "subscription_included" || chargeBasis === "metered_api" ? { charge_basis: chargeBasis } : {},
|
|
55403
|
+
...usage ? { usage } : {},
|
|
55404
|
+
...usageByModel.length > 0 ? { usage_by_model: usageByModel } : {},
|
|
55405
|
+
...cache ? { cache } : {}
|
|
55406
|
+
};
|
|
55407
|
+
break;
|
|
55408
|
+
}
|
|
54757
55409
|
case "turn_notes_supported": {
|
|
54758
55410
|
const { model, supported } = input2;
|
|
54759
55411
|
if (typeof model !== "string" || model.length === 0 || typeof supported !== "boolean")
|
|
@@ -55281,7 +55933,7 @@ function throwIfAllKilled(input2) {
|
|
|
55281
55933
|
}
|
|
55282
55934
|
|
|
55283
55935
|
// src/plugin/session-context.ts
|
|
55284
|
-
import { resolve as
|
|
55936
|
+
import { resolve as resolve27 } from "node:path";
|
|
55285
55937
|
import { pathToFileURL } from "node:url";
|
|
55286
55938
|
var FALLBACK_SESSION_KEY = "__default__";
|
|
55287
55939
|
function extractOpenCodeSessionIdentity(headers) {
|
|
@@ -55295,7 +55947,7 @@ var AgySessionRegistry = class {
|
|
|
55295
55947
|
requestSessions;
|
|
55296
55948
|
parentSessionIds = /* @__PURE__ */ new Map();
|
|
55297
55949
|
constructor(directory, options = {}) {
|
|
55298
|
-
const workspaceUri = directory ? pathToFileURL(
|
|
55950
|
+
const workspaceUri = directory ? pathToFileURL(resolve27(directory)).href : "";
|
|
55299
55951
|
this.requestSessions = new AgyRequestSessionStore(workspaceUri, options);
|
|
55300
55952
|
}
|
|
55301
55953
|
getOrCreate(identity3) {
|
|
@@ -55347,6 +55999,175 @@ var AgySessionRegistry = class {
|
|
|
55347
55999
|
}
|
|
55348
56000
|
};
|
|
55349
56001
|
|
|
56002
|
+
// src/plugin/shared/vault-billing.ts
|
|
56003
|
+
import { randomUUID as randomUUID21 } from "node:crypto";
|
|
56004
|
+
function record3(value) {
|
|
56005
|
+
return value !== null && typeof value === "object" && !Array.isArray(value) ? value : void 0;
|
|
56006
|
+
}
|
|
56007
|
+
function count3(value) {
|
|
56008
|
+
return typeof value === "number" && Number.isSafeInteger(value) && value >= 0;
|
|
56009
|
+
}
|
|
56010
|
+
function geminiBillingUsage(value) {
|
|
56011
|
+
const meta = record3(value);
|
|
56012
|
+
if (!meta) return void 0;
|
|
56013
|
+
const usage = {};
|
|
56014
|
+
const prompt = meta.promptTokenCount;
|
|
56015
|
+
const cached = meta.cachedContentTokenCount;
|
|
56016
|
+
if (count3(prompt) && (cached === void 0 || count3(cached) && cached <= prompt))
|
|
56017
|
+
usage.input = prompt - (count3(cached) ? cached : 0);
|
|
56018
|
+
if (count3(cached)) usage.cacheRead = cached;
|
|
56019
|
+
if (count3(meta.candidatesTokenCount)) usage.output = meta.candidatesTokenCount;
|
|
56020
|
+
if (count3(meta.thoughtsTokenCount)) usage.reasoning = meta.thoughtsTokenCount;
|
|
56021
|
+
if (Object.keys(usage).length === 0) return void 0;
|
|
56022
|
+
usage.reasoningIncludedInOutput = false;
|
|
56023
|
+
return usage;
|
|
56024
|
+
}
|
|
56025
|
+
var VaultBillingAttempt = class {
|
|
56026
|
+
constructor(sessionId, receipt2, requestKind, model, attempt, signal) {
|
|
56027
|
+
this.sessionId = sessionId;
|
|
56028
|
+
this.receipt = receipt2;
|
|
56029
|
+
this.requestKind = requestKind;
|
|
56030
|
+
this.model = model;
|
|
56031
|
+
this.attempt = attempt;
|
|
56032
|
+
this.signal = signal;
|
|
56033
|
+
signal?.addEventListener("abort", this.aborted, { once: true });
|
|
56034
|
+
}
|
|
56035
|
+
sessionId;
|
|
56036
|
+
receipt;
|
|
56037
|
+
requestKind;
|
|
56038
|
+
model;
|
|
56039
|
+
attempt;
|
|
56040
|
+
signal;
|
|
56041
|
+
attemptId = randomUUID21();
|
|
56042
|
+
reported = false;
|
|
56043
|
+
started = false;
|
|
56044
|
+
terminal = false;
|
|
56045
|
+
failed = false;
|
|
56046
|
+
status;
|
|
56047
|
+
metadata;
|
|
56048
|
+
aborted = () => this.end(false);
|
|
56049
|
+
event(value) {
|
|
56050
|
+
const outer = record3(value);
|
|
56051
|
+
if (!outer) return;
|
|
56052
|
+
const response = record3(outer.response) ?? outer;
|
|
56053
|
+
if (outer.error || response.error || outer.type === "error")
|
|
56054
|
+
this.failed = true;
|
|
56055
|
+
const meta = record3(response.usageMetadata);
|
|
56056
|
+
if (meta) this.metadata = { ...this.metadata, ...meta };
|
|
56057
|
+
if (Array.isArray(response.candidates))
|
|
56058
|
+
this.terminal ||= response.candidates.some(
|
|
56059
|
+
(candidate) => typeof record3(candidate)?.finishReason === "string"
|
|
56060
|
+
);
|
|
56061
|
+
}
|
|
56062
|
+
/** Tap raw bytes before the wire transformer can inject synthetic zero usage. */
|
|
56063
|
+
observe(response) {
|
|
56064
|
+
this.status = response.status;
|
|
56065
|
+
if (!response.ok) {
|
|
56066
|
+
this.failed = true;
|
|
56067
|
+
this.end(false);
|
|
56068
|
+
return response;
|
|
56069
|
+
}
|
|
56070
|
+
if (!response.body) {
|
|
56071
|
+
this.end(true);
|
|
56072
|
+
return response;
|
|
56073
|
+
}
|
|
56074
|
+
const sse = response.headers.get("content-type")?.includes("text/event-stream");
|
|
56075
|
+
const reader = response.body.getReader();
|
|
56076
|
+
const decoder = new TextDecoder();
|
|
56077
|
+
let pending = "";
|
|
56078
|
+
let oversized = false;
|
|
56079
|
+
const inspect = (line) => {
|
|
56080
|
+
if (line.length > 1024 * 1024 || this.reported) return;
|
|
56081
|
+
if (sse && line.startsWith("event:") && line.slice(6).trim() === "error")
|
|
56082
|
+
this.failed = true;
|
|
56083
|
+
if (sse && !line.startsWith("data:")) return;
|
|
56084
|
+
try {
|
|
56085
|
+
this.event(JSON.parse(sse ? line.slice(5).trim() : line));
|
|
56086
|
+
} catch {
|
|
56087
|
+
}
|
|
56088
|
+
};
|
|
56089
|
+
const body = new ReadableStream(
|
|
56090
|
+
{
|
|
56091
|
+
pull: async (controller) => {
|
|
56092
|
+
try {
|
|
56093
|
+
const chunk = await reader.read();
|
|
56094
|
+
if (chunk.done) {
|
|
56095
|
+
if (!oversized) inspect(pending + decoder.decode());
|
|
56096
|
+
this.end(true);
|
|
56097
|
+
controller.close();
|
|
56098
|
+
reader.releaseLock();
|
|
56099
|
+
return;
|
|
56100
|
+
}
|
|
56101
|
+
this.started = true;
|
|
56102
|
+
if (!oversized) {
|
|
56103
|
+
pending += decoder.decode(chunk.value, { stream: true });
|
|
56104
|
+
if (sse) {
|
|
56105
|
+
let newline = pending.indexOf("\n");
|
|
56106
|
+
while (newline >= 0) {
|
|
56107
|
+
inspect(pending.slice(0, newline));
|
|
56108
|
+
pending = pending.slice(newline + 1);
|
|
56109
|
+
newline = pending.indexOf("\n");
|
|
56110
|
+
}
|
|
56111
|
+
}
|
|
56112
|
+
if (pending.length > 1024 * 1024) {
|
|
56113
|
+
oversized = true;
|
|
56114
|
+
pending = "";
|
|
56115
|
+
}
|
|
56116
|
+
}
|
|
56117
|
+
controller.enqueue(chunk.value);
|
|
56118
|
+
} catch (error) {
|
|
56119
|
+
this.failed = true;
|
|
56120
|
+
this.end(false);
|
|
56121
|
+
controller.error(error);
|
|
56122
|
+
reader.releaseLock();
|
|
56123
|
+
}
|
|
56124
|
+
},
|
|
56125
|
+
cancel: async (reason) => {
|
|
56126
|
+
this.end(this.terminal);
|
|
56127
|
+
try {
|
|
56128
|
+
await reader.cancel(reason);
|
|
56129
|
+
} finally {
|
|
56130
|
+
reader.releaseLock();
|
|
56131
|
+
}
|
|
56132
|
+
}
|
|
56133
|
+
},
|
|
56134
|
+
{ highWaterMark: 0 }
|
|
56135
|
+
);
|
|
56136
|
+
const observed = new Response(body, {
|
|
56137
|
+
status: response.status,
|
|
56138
|
+
statusText: response.statusText,
|
|
56139
|
+
headers: response.headers
|
|
56140
|
+
});
|
|
56141
|
+
Object.defineProperties(observed, {
|
|
56142
|
+
url: { value: response.url },
|
|
56143
|
+
redirected: { value: response.redirected }
|
|
56144
|
+
});
|
|
56145
|
+
return observed;
|
|
56146
|
+
}
|
|
56147
|
+
end(ended) {
|
|
56148
|
+
if (this.reported) return;
|
|
56149
|
+
this.reported = true;
|
|
56150
|
+
this.signal?.removeEventListener("abort", this.aborted);
|
|
56151
|
+
const usage = geminiBillingUsage(this.metadata);
|
|
56152
|
+
reportRouting({
|
|
56153
|
+
sessionId: this.sessionId,
|
|
56154
|
+
kind: "billing",
|
|
56155
|
+
attemptId: this.attemptId,
|
|
56156
|
+
requestKind: this.requestKind,
|
|
56157
|
+
credentialId: this.receipt.credentialId,
|
|
56158
|
+
accountId: this.receipt.accountIdentity,
|
|
56159
|
+
provider: "antigravity",
|
|
56160
|
+
model: this.model,
|
|
56161
|
+
attempt: this.attempt,
|
|
56162
|
+
chargeBasis: "subscription_included",
|
|
56163
|
+
cache: { implicit: true },
|
|
56164
|
+
outcome: this.failed ? "failed" : ended ? "completed" : this.started ? "cut" : "failed",
|
|
56165
|
+
...this.status !== void 0 ? { status: this.status } : {},
|
|
56166
|
+
...usage ? { usage } : {}
|
|
56167
|
+
});
|
|
56168
|
+
}
|
|
56169
|
+
};
|
|
56170
|
+
|
|
55350
56171
|
// src/plugin/shared/vault-routing.ts
|
|
55351
56172
|
function hasVaultRoutingAccessor() {
|
|
55352
56173
|
try {
|
|
@@ -55611,7 +56432,7 @@ function formatWaitTime(ms) {
|
|
|
55611
56432
|
return remainingMinutes > 0 ? `${hours}h ${remainingMinutes}m` : `${hours}h`;
|
|
55612
56433
|
}
|
|
55613
56434
|
function sleep4(ms, signal) {
|
|
55614
|
-
return new Promise((
|
|
56435
|
+
return new Promise((resolve29, reject) => {
|
|
55615
56436
|
if (signal?.aborted) {
|
|
55616
56437
|
reject(
|
|
55617
56438
|
signal.reason instanceof Error ? signal.reason : new Error("Aborted")
|
|
@@ -55621,7 +56442,7 @@ function sleep4(ms, signal) {
|
|
|
55621
56442
|
const timerMs = Math.min(Math.max(0, Math.floor(ms)), 2147483647);
|
|
55622
56443
|
const timeout = setTimeout(() => {
|
|
55623
56444
|
cleanup2();
|
|
55624
|
-
|
|
56445
|
+
resolve29();
|
|
55625
56446
|
}, timerMs);
|
|
55626
56447
|
const onAbort = () => {
|
|
55627
56448
|
cleanup2();
|
|
@@ -55874,6 +56695,7 @@ function createRequestExecutor(deps) {
|
|
|
55874
56695
|
parentId: requestSessionIdentity.parentSessionId
|
|
55875
56696
|
} : void 0;
|
|
55876
56697
|
const isChildRequest = requestSessionIdentity.parentSessionId !== null;
|
|
56698
|
+
let physicalSendCount = 0;
|
|
55877
56699
|
if (accountManager.getAccountCount() === 0) {
|
|
55878
56700
|
const urlString2 = typeof input2 === "string" ? input2 : toUrlString(input2);
|
|
55879
56701
|
const modelFromUrl = extractModelFromUrl(urlString2) ?? "unknown";
|
|
@@ -56460,6 +57282,32 @@ function createRequestExecutor(deps) {
|
|
|
56460
57282
|
}
|
|
56461
57283
|
}
|
|
56462
57284
|
const selected = account;
|
|
57285
|
+
const sendPhysical = async (url, sendInit, admission, sendModel, requestKind) => {
|
|
57286
|
+
const source = credentials.domain === "local" ? "local" : hasVaultHost2() ? "hosted" : "vault";
|
|
57287
|
+
const message = `request-send source=${source} model=${sendModel} account=Account ${account.index + 1}`;
|
|
57288
|
+
if (source === "local") log17.info(message);
|
|
57289
|
+
else (log17.hostInfo ?? log17.info)(message);
|
|
57290
|
+
const attempt = ++physicalSendCount;
|
|
57291
|
+
const sessionId = requestSessionIdentity.sessionId;
|
|
57292
|
+
const billing = admission && sessionId && hasVaultRoutingAccessor() ? new VaultBillingAttempt(
|
|
57293
|
+
sessionId,
|
|
57294
|
+
admission,
|
|
57295
|
+
requestKind,
|
|
57296
|
+
sendModel,
|
|
57297
|
+
attempt,
|
|
57298
|
+
abortSignal
|
|
57299
|
+
) : void 0;
|
|
57300
|
+
try {
|
|
57301
|
+
const response = await transport(url, sendInit, {
|
|
57302
|
+
signal: abortSignal,
|
|
57303
|
+
onDebug: pushDebug
|
|
57304
|
+
});
|
|
57305
|
+
return billing?.observe(response) ?? response;
|
|
57306
|
+
} catch (error) {
|
|
57307
|
+
billing?.end(false);
|
|
57308
|
+
throw error;
|
|
57309
|
+
}
|
|
57310
|
+
};
|
|
56463
57311
|
const credentialForAuxiliarySend = async (sendInit, preparedProjectId) => {
|
|
56464
57312
|
await assertAdmission();
|
|
56465
57313
|
if (credentials.domain === "vault") {
|
|
@@ -56521,10 +57369,13 @@ function createRequestExecutor(deps) {
|
|
|
56521
57369
|
warmupInit,
|
|
56522
57370
|
projectId
|
|
56523
57371
|
);
|
|
56524
|
-
const warmupResponse = await
|
|
56525
|
-
|
|
56526
|
-
|
|
56527
|
-
|
|
57372
|
+
const warmupResponse = await sendPhysical(
|
|
57373
|
+
warmupUrl,
|
|
57374
|
+
warmupSend.init,
|
|
57375
|
+
warmupSend.admission,
|
|
57376
|
+
prepared.effectiveModel ?? model ?? "unknown",
|
|
57377
|
+
"prime"
|
|
57378
|
+
);
|
|
56528
57379
|
reportVault401(warmupSend.admission, warmupResponse.status);
|
|
56529
57380
|
const transformed = await deadline.wait(
|
|
56530
57381
|
() => wire.transformResponse(
|
|
@@ -56562,13 +57413,12 @@ function createRequestExecutor(deps) {
|
|
|
56562
57413
|
{ ...prepared.init, method: "POST", body: bodyStr },
|
|
56563
57414
|
prepared.projectId ?? ""
|
|
56564
57415
|
);
|
|
56565
|
-
const probeResponse = await
|
|
57416
|
+
const probeResponse = await sendPhysical(
|
|
56566
57417
|
toUrlString(prepared.request),
|
|
56567
57418
|
probeSend.init,
|
|
56568
|
-
|
|
56569
|
-
|
|
56570
|
-
|
|
56571
|
-
}
|
|
57419
|
+
probeSend.admission,
|
|
57420
|
+
prepared.effectiveModel ?? model ?? "unknown",
|
|
57421
|
+
"keep_warm"
|
|
56572
57422
|
);
|
|
56573
57423
|
reportVault401(probeSend.admission, probeResponse.status);
|
|
56574
57424
|
if (probeResponse.body) {
|
|
@@ -56739,10 +57589,12 @@ function createRequestExecutor(deps) {
|
|
|
56739
57589
|
`dispatching request via ${prepared.headerStyle} transport`
|
|
56740
57590
|
);
|
|
56741
57591
|
physicalAttemptStarted = true;
|
|
56742
|
-
const response = await
|
|
57592
|
+
const response = await sendPhysical(
|
|
56743
57593
|
toUrlString(prepared.request),
|
|
56744
57594
|
prepared.init,
|
|
56745
|
-
|
|
57595
|
+
sendAdmission,
|
|
57596
|
+
prepared.effectiveModel ?? model ?? "unknown",
|
|
57597
|
+
kind ?? "primary"
|
|
56746
57598
|
);
|
|
56747
57599
|
if (response.ok) deadline.acceptHeaders();
|
|
56748
57600
|
apiRequestCount++;
|
|
@@ -58152,7 +59004,7 @@ function createPluginLifecycle(options) {
|
|
|
58152
59004
|
const queueDrained = (async () => {
|
|
58153
59005
|
await queue2?.dispose();
|
|
58154
59006
|
})();
|
|
58155
|
-
const
|
|
59007
|
+
const record4 = {
|
|
58156
59008
|
requests,
|
|
58157
59009
|
done: (async () => {
|
|
58158
59010
|
const failures = [];
|
|
@@ -58164,14 +59016,14 @@ function createPluginLifecycle(options) {
|
|
|
58164
59016
|
reportCleanupFailures(failures);
|
|
58165
59017
|
})()
|
|
58166
59018
|
};
|
|
58167
|
-
retiring.add(
|
|
58168
|
-
|
|
58169
|
-
() => retiring.delete(
|
|
59019
|
+
retiring.add(record4);
|
|
59020
|
+
record4.done.then(
|
|
59021
|
+
() => retiring.delete(record4),
|
|
58170
59022
|
() => {
|
|
58171
|
-
if (!requests) retiring.delete(
|
|
59023
|
+
if (!requests) retiring.delete(record4);
|
|
58172
59024
|
}
|
|
58173
59025
|
);
|
|
58174
|
-
return { queueDrained, done:
|
|
59026
|
+
return { queueDrained, done: record4.done };
|
|
58175
59027
|
};
|
|
58176
59028
|
const disposeAccountRuntime = async () => {
|
|
58177
59029
|
const oldQueue = refreshQueue;
|
|
@@ -58186,7 +59038,7 @@ function createPluginLifecycle(options) {
|
|
|
58186
59038
|
const aborted = Promise.all([
|
|
58187
59039
|
collectCleanupFailure(() => oldRequests?.dispose(), failures),
|
|
58188
59040
|
...retired.map(
|
|
58189
|
-
(
|
|
59041
|
+
(record4) => collectCleanupFailure(() => record4.requests?.dispose(), failures)
|
|
58190
59042
|
)
|
|
58191
59043
|
]);
|
|
58192
59044
|
const liveQueueDrained = collectCleanupFailure(
|
|
@@ -58197,7 +59049,7 @@ function createPluginLifecycle(options) {
|
|
|
58197
59049
|
aborted,
|
|
58198
59050
|
liveQueueDrained,
|
|
58199
59051
|
...retired.map(
|
|
58200
|
-
(
|
|
59052
|
+
(record4) => collectCleanupFailure(() => record4.done, failures)
|
|
58201
59053
|
)
|
|
58202
59054
|
]);
|
|
58203
59055
|
await collectCleanupFailure(() => oldManager?.dispose(), failures);
|
|
@@ -58251,8 +59103,8 @@ function createPluginLifecycle(options) {
|
|
|
58251
59103
|
};
|
|
58252
59104
|
let failDisposal = () => {
|
|
58253
59105
|
};
|
|
58254
|
-
disposal = new Promise((
|
|
58255
|
-
finishDisposal =
|
|
59106
|
+
disposal = new Promise((resolve29, reject) => {
|
|
59107
|
+
finishDisposal = resolve29;
|
|
58256
59108
|
failDisposal = reject;
|
|
58257
59109
|
});
|
|
58258
59110
|
void (async () => {
|
|
@@ -58453,7 +59305,7 @@ var createAntigravityPlugin = (providerId, options = {}) => async (input2) => {
|
|
|
58453
59305
|
await drainSidebarWrites();
|
|
58454
59306
|
}
|
|
58455
59307
|
});
|
|
58456
|
-
const accountFile =
|
|
59308
|
+
const accountFile = resolve28(accountFileForVault());
|
|
58457
59309
|
const vaultFolder = await prepareVaultFolder({ accountFile });
|
|
58458
59310
|
const unavailableMessage = vaultFolder.refusal?.message ?? VAULT_ACCOUNT_REMEDY;
|
|
58459
59311
|
let vaultQuotaPoller;
|
|
@@ -58794,7 +59646,7 @@ var createAntigravityPlugin = (providerId, options = {}) => async (input2) => {
|
|
|
58794
59646
|
const key = vaultAccountRowKey(row);
|
|
58795
59647
|
const existing = vaultSelectors.get(key);
|
|
58796
59648
|
if (existing) return existing;
|
|
58797
|
-
const selector =
|
|
59649
|
+
const selector = randomUUID22();
|
|
58798
59650
|
vaultSelectors.set(key, selector);
|
|
58799
59651
|
return selector;
|
|
58800
59652
|
},
|