@cortexkit/opencode-antigravity-auth 3.0.39 → 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/dist/cli.js +266 -40
- package/dist/cli.js.map +4 -4
- package/dist/cli.meta.json +48 -19
- package/dist/index.js +708 -279
- package/dist/index.js.map +4 -4
- package/dist/index.meta.json +85 -22
- package/dist/server.js +840 -411
- package/dist/server.js.map +4 -4
- package/dist/server.meta.json +1 -1
- package/dist/src/common-auth-embedded/claustrum/enrollment.d.ts +25 -4
- package/dist/src/common-auth-embedded/claustrum/enrollment.js +81 -4
- 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/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 +13 -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 +12 -1
- package/dist/src/common-auth-embedded/source-output.json +48 -40
- package/dist/src/plugin/__fixtures__/verified-store.js +2 -2
- 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/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 +12 -0
- package/dist/src/setup.js.map +1 -1
- package/dist/tui-build-map.json +1 -1
- package/dist/tui-ga-build-map.json +1 -1
- package/dist/types/src/common-auth-embedded/claustrum/enrollment.d.ts +25 -4
- package/dist/types/src/common-auth-embedded/claustrum/index.d.ts +1 -1
- 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 +12 -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/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 +3 -3
- package/src/common-auth-embedded/claustrum/enrollment.d.ts +25 -4
- package/src/common-auth-embedded/claustrum/enrollment.js +81 -4
- 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/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 +13 -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 +12 -1
- package/src/common-auth-embedded/source-output.json +48 -40
package/dist/server.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;
|
|
@@ -7692,9 +7692,9 @@ var init_account_selector = __esm({
|
|
|
7692
7692
|
const today = new Date(this.now()).toISOString().slice(0, 10);
|
|
7693
7693
|
const result = [];
|
|
7694
7694
|
for (const account of this.accounts) {
|
|
7695
|
-
const
|
|
7696
|
-
if (
|
|
7697
|
-
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 });
|
|
7698
7698
|
}
|
|
7699
7699
|
}
|
|
7700
7700
|
return result.sort((a, b) => b.count - a.count);
|
|
@@ -8571,11 +8571,11 @@ async function readAndNormalizeV4(path5) {
|
|
|
8571
8571
|
}
|
|
8572
8572
|
};
|
|
8573
8573
|
}
|
|
8574
|
-
function validateV4AccountRecord(
|
|
8575
|
-
if (
|
|
8574
|
+
function validateV4AccountRecord(record4, index) {
|
|
8575
|
+
if (record4 === null || typeof record4 !== "object" || Array.isArray(record4)) {
|
|
8576
8576
|
return `accounts[${index}] is not an object`;
|
|
8577
8577
|
}
|
|
8578
|
-
const acc =
|
|
8578
|
+
const acc = record4;
|
|
8579
8579
|
if (typeof acc.refreshToken !== "string" || acc.refreshToken.length === 0) {
|
|
8580
8580
|
return `accounts[${index}].refreshToken is missing or not a non-empty string`;
|
|
8581
8581
|
}
|
|
@@ -9280,15 +9280,15 @@ var init_account_manager = __esm({
|
|
|
9280
9280
|
}
|
|
9281
9281
|
/** The stored selection's index for `family` among `accounts`. */
|
|
9282
9282
|
routedIndex(accounts, routing, family) {
|
|
9283
|
-
const
|
|
9283
|
+
const count4 = accounts.length;
|
|
9284
9284
|
const indexOf = (ref) => {
|
|
9285
9285
|
if (ref == null)
|
|
9286
9286
|
return void 0;
|
|
9287
9287
|
const found = accounts.findIndex((account) => account.ref !== void 0 && sameRowRef(account.ref, ref));
|
|
9288
9288
|
return found < 0 ? void 0 : found;
|
|
9289
9289
|
};
|
|
9290
|
-
const defaultIndex = indexOf(routing?.activeRow) ?? clampNonNegativeInt(routing?.activeIndex, 0) %
|
|
9291
|
-
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;
|
|
9292
9292
|
}
|
|
9293
9293
|
loadRepositoryRows(read) {
|
|
9294
9294
|
const baseNow = this.now();
|
|
@@ -11334,8 +11334,8 @@ function isFiniteNumber(value) {
|
|
|
11334
11334
|
function isName(value) {
|
|
11335
11335
|
return typeof value === "string" && value.length > 0;
|
|
11336
11336
|
}
|
|
11337
|
-
function optional2(
|
|
11338
|
-
return
|
|
11337
|
+
function optional2(record4, key, check) {
|
|
11338
|
+
return record4[key] === void 0 || check(record4[key]);
|
|
11339
11339
|
}
|
|
11340
11340
|
function isPositiveFinite(value) {
|
|
11341
11341
|
return isFiniteNumber(value) && value > 0;
|
|
@@ -11437,11 +11437,11 @@ function isScope(value) {
|
|
|
11437
11437
|
function isLabel(value) {
|
|
11438
11438
|
return typeof value === "string" && value !== "";
|
|
11439
11439
|
}
|
|
11440
|
-
function optionalFinite(
|
|
11441
|
-
return
|
|
11440
|
+
function optionalFinite(record4, key) {
|
|
11441
|
+
return record4[key] === void 0 || isFiniteNumber2(record4[key]);
|
|
11442
11442
|
}
|
|
11443
|
-
function optionalString(
|
|
11444
|
-
return
|
|
11443
|
+
function optionalString(record4, key) {
|
|
11444
|
+
return record4[key] === void 0 || typeof record4[key] === "string";
|
|
11445
11445
|
}
|
|
11446
11446
|
function isObservedReading(value) {
|
|
11447
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);
|
|
@@ -16567,8 +16567,8 @@ var init_pull = __esm({
|
|
|
16567
16567
|
// ../core/dist/common-auth-embedded/logger/capture-sink.js
|
|
16568
16568
|
function createCaptureSink() {
|
|
16569
16569
|
const records = [];
|
|
16570
|
-
const sink = (
|
|
16571
|
-
records.push(
|
|
16570
|
+
const sink = (record4) => {
|
|
16571
|
+
records.push(record4);
|
|
16572
16572
|
};
|
|
16573
16573
|
return {
|
|
16574
16574
|
records,
|
|
@@ -17710,8 +17710,8 @@ function openPoolStore(options) {
|
|
|
17710
17710
|
firePull: (id, reason) => pulls.fire(id, reason)
|
|
17711
17711
|
};
|
|
17712
17712
|
const quotaWriter = options.coalesceQuota ? new PoolQuotaWriter(rt, options.quotaDrainTimeoutMs, options.quotaCommitTimer) : void 0;
|
|
17713
|
-
const
|
|
17714
|
-
rt.publishQuota =
|
|
17713
|
+
const record4 = (id, attribution, observation) => quotaWriter ? quotaWriter.record(id, attribution, observation) : recordQuota(rt, id, attribution, observation);
|
|
17714
|
+
rt.publishQuota = record4;
|
|
17715
17715
|
const overlay = (result) => {
|
|
17716
17716
|
if (result.status === "ready" && quotaWriter)
|
|
17717
17717
|
return { ...result, rows: quotaWriter.overlay(result.rows) };
|
|
@@ -17748,7 +17748,7 @@ function openPoolStore(options) {
|
|
|
17748
17748
|
updateLimitsNamespace: (mutator, options2) => updatePoolLimitsNamespace(rt, mutator, options2),
|
|
17749
17749
|
recordIdentity: (id, identity3, attribution, callOptions) => recordRowIdentity(rt, id, identity3, attribution, callOptions),
|
|
17750
17750
|
refresh: (id, provider2, callOptions) => refreshRow(rt, id, provider2, callOptions),
|
|
17751
|
-
recordQuota:
|
|
17751
|
+
recordQuota: record4,
|
|
17752
17752
|
close: () => quotaWriter?.close() ?? Promise.resolve(),
|
|
17753
17753
|
dispose: () => quotaWriter?.close() ?? Promise.resolve(),
|
|
17754
17754
|
requestReading: (id) => pulls.fire(id, "admission"),
|
|
@@ -21398,6 +21398,25 @@ function validEnrollmentDisplayName(displayName) {
|
|
|
21398
21398
|
const length = Array.from(displayName).length;
|
|
21399
21399
|
return length >= 1 && length <= 40 && !/[\p{Cc}\u061c\u200e\u200f\u202a-\u202e\u2066-\u2069\u200b-\u200d\u2060\ufeff]/u.test(displayName);
|
|
21400
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
|
+
}
|
|
21401
21420
|
function connectClaustrumEnrollmentClient(options) {
|
|
21402
21421
|
return ClaustrumWireClient.connect(options);
|
|
21403
21422
|
}
|
|
@@ -21433,6 +21452,7 @@ function decodeEnrollmentState(value) {
|
|
|
21433
21452
|
throw invalidState();
|
|
21434
21453
|
}
|
|
21435
21454
|
if (value.phase === "pending") {
|
|
21455
|
+
const grants = decodeGrantProposal(value);
|
|
21436
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)) {
|
|
21437
21457
|
throw invalidState();
|
|
21438
21458
|
}
|
|
@@ -21445,10 +21465,12 @@ function decodeEnrollmentState(value) {
|
|
|
21445
21465
|
requestId: value.requestId
|
|
21446
21466
|
},
|
|
21447
21467
|
createdAt: value.createdAt,
|
|
21448
|
-
updatedAt: value.updatedAt
|
|
21468
|
+
updatedAt: value.updatedAt,
|
|
21469
|
+
...grants
|
|
21449
21470
|
};
|
|
21450
21471
|
}
|
|
21451
21472
|
if (value.phase === "approved") {
|
|
21473
|
+
const grants = decodeGrantProposal(value);
|
|
21452
21474
|
if (value.approvedName !== void 0 && (typeof value.approvedName !== "string" || value.approvedName.length === 0) || !validGeneration(value.tokenGeneration) || !validTimestamp(value.updatedAt)) {
|
|
21453
21475
|
throw invalidState();
|
|
21454
21476
|
}
|
|
@@ -21460,7 +21482,8 @@ function decodeEnrollmentState(value) {
|
|
|
21460
21482
|
approvedName: value.approvedName
|
|
21461
21483
|
},
|
|
21462
21484
|
tokenGeneration: value.tokenGeneration,
|
|
21463
|
-
updatedAt: value.updatedAt
|
|
21485
|
+
updatedAt: value.updatedAt,
|
|
21486
|
+
...grants
|
|
21464
21487
|
};
|
|
21465
21488
|
}
|
|
21466
21489
|
if (value.phase === "denied" || value.phase === "blocked") {
|
|
@@ -21479,6 +21502,11 @@ function decodeEnrollmentState(value) {
|
|
|
21479
21502
|
}
|
|
21480
21503
|
throw invalidState();
|
|
21481
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
|
+
}
|
|
21482
21510
|
function decodeTokenFile(value) {
|
|
21483
21511
|
if (!isRecord6(value) || !TOKEN_RE.test(String(value.token ?? "")) || !validGeneration(value.token_generation)) {
|
|
21484
21512
|
throw new ClaustrumConsumerError("invalid-token", "invalid Claustrum enrollment token file");
|
|
@@ -21692,7 +21720,8 @@ async function readEnrollmentStatus(paths, proposedName) {
|
|
|
21692
21720
|
...state?.phase === "approved" && state.approvedName !== void 0 && {
|
|
21693
21721
|
approvedName: state.approvedName
|
|
21694
21722
|
},
|
|
21695
|
-
tokenGeneration: token.token_generation
|
|
21723
|
+
tokenGeneration: token.token_generation,
|
|
21724
|
+
...state && (state.phase === "approved" || state.phase === "pending") && grantProposal(state)
|
|
21696
21725
|
}
|
|
21697
21726
|
};
|
|
21698
21727
|
}
|
|
@@ -21751,7 +21780,8 @@ function statusFromState(state) {
|
|
|
21751
21780
|
return {
|
|
21752
21781
|
state: "pending",
|
|
21753
21782
|
proposedName: state.proposedName,
|
|
21754
|
-
...state.requestId !== void 0 && { requestId: state.requestId }
|
|
21783
|
+
...state.requestId !== void 0 && { requestId: state.requestId },
|
|
21784
|
+
...grantProposal(state)
|
|
21755
21785
|
};
|
|
21756
21786
|
}
|
|
21757
21787
|
if (state.phase === "approved") {
|
|
@@ -21761,7 +21791,8 @@ function statusFromState(state) {
|
|
|
21761
21791
|
...state.approvedName !== void 0 && {
|
|
21762
21792
|
approvedName: state.approvedName
|
|
21763
21793
|
},
|
|
21764
|
-
tokenGeneration: state.tokenGeneration
|
|
21794
|
+
tokenGeneration: state.tokenGeneration,
|
|
21795
|
+
...grantProposal(state)
|
|
21765
21796
|
};
|
|
21766
21797
|
}
|
|
21767
21798
|
if (state.phase === "denied")
|
|
@@ -21881,6 +21912,7 @@ var init_enrollment = __esm({
|
|
|
21881
21912
|
#paths;
|
|
21882
21913
|
#proposedName;
|
|
21883
21914
|
#displayName;
|
|
21915
|
+
#requestedGrants;
|
|
21884
21916
|
#now;
|
|
21885
21917
|
#mintSecret;
|
|
21886
21918
|
#writeTokenFile;
|
|
@@ -21888,6 +21920,12 @@ var init_enrollment = __esm({
|
|
|
21888
21920
|
constructor(options) {
|
|
21889
21921
|
if (options.displayName !== void 0 && !validEnrollmentDisplayName(options.displayName))
|
|
21890
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
|
+
}));
|
|
21891
21929
|
this.#ancestorOptions = options.ancestorOptions ?? {};
|
|
21892
21930
|
this.#client = options.client;
|
|
21893
21931
|
this.#paths = options.paths;
|
|
@@ -21938,6 +21976,7 @@ var init_enrollment = __esm({
|
|
|
21938
21976
|
phase: "approved",
|
|
21939
21977
|
proposedName: state?.proposedName ?? this.#proposedName,
|
|
21940
21978
|
tokenGeneration: token.token_generation,
|
|
21979
|
+
...state && grantProposal(state),
|
|
21941
21980
|
updatedAt: this.#now()
|
|
21942
21981
|
};
|
|
21943
21982
|
await writeStateAtomic(this.#paths.statePath, approved, this.#ancestorOptions);
|
|
@@ -21949,7 +21988,8 @@ var init_enrollment = __esm({
|
|
|
21949
21988
|
...state.phase === "approved" && state.approvedName !== void 0 && {
|
|
21950
21989
|
approvedName: state.approvedName
|
|
21951
21990
|
},
|
|
21952
|
-
tokenGeneration: token.token_generation
|
|
21991
|
+
tokenGeneration: token.token_generation,
|
|
21992
|
+
...state.phase === "approved" && grantProposal(state)
|
|
21953
21993
|
};
|
|
21954
21994
|
}
|
|
21955
21995
|
if (state?.phase === "approved") {
|
|
@@ -21973,7 +22013,10 @@ var init_enrollment = __esm({
|
|
|
21973
22013
|
proposedName: this.#proposedName,
|
|
21974
22014
|
requestSecret: this.#mintSecret(),
|
|
21975
22015
|
createdAt: now,
|
|
21976
|
-
updatedAt: now
|
|
22016
|
+
updatedAt: now,
|
|
22017
|
+
...this.#requestedGrants !== void 0 && {
|
|
22018
|
+
requestedGrants: this.#requestedGrants
|
|
22019
|
+
}
|
|
21977
22020
|
};
|
|
21978
22021
|
if (!TOKEN_RE.test(state.requestSecret))
|
|
21979
22022
|
throw new ClaustrumConsumerError("invalid-state", "invalid minted Claustrum enrollment secret");
|
|
@@ -21987,22 +22030,33 @@ var init_enrollment = __esm({
|
|
|
21987
22030
|
requestSecretHash
|
|
21988
22031
|
};
|
|
21989
22032
|
let proposed;
|
|
22033
|
+
let requestedGrantsStatus = state.requestedGrantsStatus;
|
|
21990
22034
|
try {
|
|
21991
22035
|
proposed = await this.#client.enrollPropose({
|
|
21992
22036
|
...proposal,
|
|
21993
22037
|
...this.#displayName !== void 0 && {
|
|
21994
22038
|
displayName: this.#displayName
|
|
22039
|
+
},
|
|
22040
|
+
...state.requestedGrants !== void 0 && {
|
|
22041
|
+
requestedGrants: state.requestedGrants
|
|
21995
22042
|
}
|
|
21996
22043
|
});
|
|
22044
|
+
if (state.requestedGrants !== void 0)
|
|
22045
|
+
requestedGrantsStatus = "sent";
|
|
21997
22046
|
} catch (error) {
|
|
21998
|
-
if (this.#displayName === void 0 || !(error instanceof ClaustrumCredentialError3) || error.code !== "invalid_params")
|
|
22047
|
+
if (this.#displayName === void 0 && state.requestedGrants === void 0 || !(error instanceof ClaustrumCredentialError3) || error.code !== "invalid_params")
|
|
21999
22048
|
throw error;
|
|
22000
22049
|
proposed = await this.#client.enrollPropose(proposal);
|
|
22050
|
+
if (state.requestedGrants !== void 0)
|
|
22051
|
+
requestedGrantsStatus = "dropped";
|
|
22001
22052
|
}
|
|
22002
22053
|
state = {
|
|
22003
22054
|
...state,
|
|
22004
22055
|
requestId: proposed.requestId,
|
|
22005
|
-
updatedAt: this.#now()
|
|
22056
|
+
updatedAt: this.#now(),
|
|
22057
|
+
...requestedGrantsStatus !== void 0 && {
|
|
22058
|
+
requestedGrantsStatus
|
|
22059
|
+
}
|
|
22006
22060
|
};
|
|
22007
22061
|
await writeStateAtomic(this.#paths.statePath, state, this.#ancestorOptions);
|
|
22008
22062
|
} catch (error) {
|
|
@@ -22013,7 +22067,8 @@ var init_enrollment = __esm({
|
|
|
22013
22067
|
return {
|
|
22014
22068
|
state: "pending",
|
|
22015
22069
|
proposedName: state.proposedName,
|
|
22016
|
-
retryCode: refusal3.code
|
|
22070
|
+
retryCode: refusal3.code,
|
|
22071
|
+
...grantProposal(state)
|
|
22017
22072
|
};
|
|
22018
22073
|
}
|
|
22019
22074
|
if (refusal3.code === UNSUPPORTED_ENROLLMENT_CODE) {
|
|
@@ -22063,6 +22118,7 @@ var init_enrollment = __esm({
|
|
|
22063
22118
|
proposedName: state.proposedName,
|
|
22064
22119
|
approvedName: outcome.name,
|
|
22065
22120
|
tokenGeneration: outcome.tokenGeneration,
|
|
22121
|
+
...grantProposal(state),
|
|
22066
22122
|
updatedAt: this.#now()
|
|
22067
22123
|
};
|
|
22068
22124
|
await writeStateAtomic(this.#paths.statePath, approved, this.#ancestorOptions);
|
|
@@ -22076,7 +22132,8 @@ var init_enrollment = __esm({
|
|
|
22076
22132
|
state: "pending",
|
|
22077
22133
|
proposedName: state.proposedName,
|
|
22078
22134
|
requestId,
|
|
22079
|
-
retryCode: refusal3.code
|
|
22135
|
+
retryCode: refusal3.code,
|
|
22136
|
+
...grantProposal(state)
|
|
22080
22137
|
};
|
|
22081
22138
|
}
|
|
22082
22139
|
return this.#block(state, refusal3.code);
|
|
@@ -22369,8 +22426,8 @@ function accessTokenFromMaterial(material) {
|
|
|
22369
22426
|
}
|
|
22370
22427
|
if (!parsed || typeof parsed !== "object")
|
|
22371
22428
|
throw invalidMaterial();
|
|
22372
|
-
const
|
|
22373
|
-
const value =
|
|
22429
|
+
const record4 = parsed;
|
|
22430
|
+
const value = record4.access_token ?? record4.access;
|
|
22374
22431
|
access = typeof value === "string" ? value : "";
|
|
22375
22432
|
}
|
|
22376
22433
|
if (!/^[\x21-\x7e]+$/.test(access) || access.startsWith(CUSTODY_PLACEHOLDER_PREFIX)) {
|
|
@@ -22752,8 +22809,8 @@ var init_custody = __esm({
|
|
|
22752
22809
|
...row.orgName !== void 0 && { orgName: row.orgName }
|
|
22753
22810
|
}));
|
|
22754
22811
|
}
|
|
22755
|
-
for (const
|
|
22756
|
-
this.#logger.warn("skipped malformed vault record",
|
|
22812
|
+
for (const record4 of skipped)
|
|
22813
|
+
this.#logger.warn("skipped malformed vault record", record4);
|
|
22757
22814
|
const grantReach = grantReachOf(inventory);
|
|
22758
22815
|
return {
|
|
22759
22816
|
view: inventory.view,
|
|
@@ -23095,7 +23152,7 @@ var init_custody = __esm({
|
|
|
23095
23152
|
void usage.then(() => this.#tokenReads.delete(usage));
|
|
23096
23153
|
} else
|
|
23097
23154
|
this.#client.close();
|
|
23098
|
-
this.#disposing = drainShutdown(this.#tokenReads, (
|
|
23155
|
+
this.#disposing = drainShutdown(this.#tokenReads, (count4) => (this.#onDrainTimeout ?? this.#warnShutdown)(count4)).finally(() => {
|
|
23099
23156
|
this.#usage.drop();
|
|
23100
23157
|
this.#usageServed.clear();
|
|
23101
23158
|
if (usage)
|
|
@@ -23237,8 +23294,8 @@ function projectVaultRoster(previous, inventory, options = {}) {
|
|
|
23237
23294
|
const declined = [...previous?.declined ?? seed?.declined ?? []];
|
|
23238
23295
|
const complete = inventory.skipped.length === 0;
|
|
23239
23296
|
const listed = new Set(inventory.credentials.map((credential) => credential.credentialId));
|
|
23240
|
-
const rejectedIds = new Set(inventory.skipped.flatMap((
|
|
23241
|
-
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);
|
|
23242
23299
|
const unaccounted = (id) => !listed.has(id) && (rejectedIds.has(id) || unrecoverable);
|
|
23243
23300
|
const lastKnown = /* @__PURE__ */ new Map();
|
|
23244
23301
|
for (const row of previousRows) {
|
|
@@ -23349,11 +23406,11 @@ function projectVaultRoster(previous, inventory, options = {}) {
|
|
|
23349
23406
|
...previous?.limits !== void 0 && { limits: previous.limits },
|
|
23350
23407
|
complete,
|
|
23351
23408
|
...!complete && {
|
|
23352
|
-
rejected: inventory.skipped.map((
|
|
23353
|
-
...
|
|
23354
|
-
credentialId:
|
|
23409
|
+
rejected: inventory.skipped.map((record4) => ({
|
|
23410
|
+
...record4.credentialId !== void 0 && {
|
|
23411
|
+
credentialId: record4.credentialId
|
|
23355
23412
|
},
|
|
23356
|
-
reason:
|
|
23413
|
+
reason: record4.reason
|
|
23357
23414
|
}))
|
|
23358
23415
|
},
|
|
23359
23416
|
rows: projected2.map((entry) => entry.row),
|
|
@@ -23732,19 +23789,19 @@ function resolveVaultPrimary(input2) {
|
|
|
23732
23789
|
reason,
|
|
23733
23790
|
...previous && { lastVerified: previous }
|
|
23734
23791
|
});
|
|
23735
|
-
const
|
|
23736
|
-
if (!
|
|
23792
|
+
const record4 = inventory.credentials.find((credential) => credential.credentialId === input2.primaryCredentialId);
|
|
23793
|
+
if (!record4) {
|
|
23737
23794
|
if (inventory.skipped.some((skipped) => skipped.credentialId === input2.primaryCredentialId))
|
|
23738
23795
|
return unavailable("malformed");
|
|
23739
23796
|
const incomplete = input2.complete === false || inventory.skipped.some((skipped) => skipped.credentialId === void 0);
|
|
23740
23797
|
return incomplete ? unavailable("incomplete") : { status: "absent" };
|
|
23741
23798
|
}
|
|
23742
|
-
const identity3 =
|
|
23799
|
+
const identity3 = record4.accountIdentity;
|
|
23743
23800
|
if (identity3 === void 0)
|
|
23744
23801
|
return unavailable("unclaimed");
|
|
23745
23802
|
if (input2.expectedAccountIdentity !== void 0 && input2.expectedAccountIdentity !== identity3)
|
|
23746
23803
|
return unavailable("identity-changed");
|
|
23747
|
-
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;
|
|
23748
23805
|
const binding = {
|
|
23749
23806
|
routeId: input2.routeId,
|
|
23750
23807
|
credentialId: representative.credentialId,
|
|
@@ -25509,7 +25566,7 @@ var init_hub = __esm({
|
|
|
25509
25566
|
const share = {
|
|
25510
25567
|
...inventory,
|
|
25511
25568
|
credentials: inventory.credentials.filter((credential) => credential.member === entry.provider),
|
|
25512
|
-
skipped: inventory.skipped.filter((
|
|
25569
|
+
skipped: inventory.skipped.filter((record4) => record4.member === entry.provider)
|
|
25513
25570
|
};
|
|
25514
25571
|
try {
|
|
25515
25572
|
if (!base)
|
|
@@ -25901,6 +25958,7 @@ __export(claustrum_exports, {
|
|
|
25901
25958
|
resetClaustrumEnrollmentState: () => resetClaustrumEnrollmentState,
|
|
25902
25959
|
resolveVaultPrimary: () => resolveVaultPrimary,
|
|
25903
25960
|
validEnrollmentDisplayName: () => validEnrollmentDisplayName,
|
|
25961
|
+
validEnrollmentRequestedGrants: () => validEnrollmentRequestedGrants,
|
|
25904
25962
|
vaultAuthority: () => vaultAuthority,
|
|
25905
25963
|
vaultRosterSeed: () => vaultRosterSeed,
|
|
25906
25964
|
vaultRoutingRows: () => vaultRoutingRows
|
|
@@ -31296,6 +31354,9 @@ function createOpenCodeVaultCustody(options) {
|
|
|
31296
31354
|
client,
|
|
31297
31355
|
paths: await enrollmentPaths(),
|
|
31298
31356
|
proposedName: OPENCODE_VAULT_ENROLLMENT_NAME,
|
|
31357
|
+
requestedGrants: [
|
|
31358
|
+
{ selector: { category: "antigravity-native" }, operation: "read" }
|
|
31359
|
+
],
|
|
31299
31360
|
...options.now ? { now: options.now } : {}
|
|
31300
31361
|
});
|
|
31301
31362
|
const current = await manager.status();
|
|
@@ -32085,9 +32146,9 @@ function bootTime(options) {
|
|
|
32085
32146
|
return Number.NaN;
|
|
32086
32147
|
}
|
|
32087
32148
|
}
|
|
32088
|
-
async function staleRecord(path5,
|
|
32089
|
-
if (
|
|
32090
|
-
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;
|
|
32091
32152
|
if (start === void 0) {
|
|
32092
32153
|
try {
|
|
32093
32154
|
start = (await stat10(path5)).mtimeMs;
|
|
@@ -32099,7 +32160,7 @@ async function staleRecord(path5, record3, boot, heartbeat) {
|
|
|
32099
32160
|
return false;
|
|
32100
32161
|
if (heartbeat) {
|
|
32101
32162
|
try {
|
|
32102
|
-
if (await readFile11(path5, "utf8") ===
|
|
32163
|
+
if (await readFile11(path5, "utf8") === record4.text) {
|
|
32103
32164
|
await unlink9(path5);
|
|
32104
32165
|
log5.debug("Removed stale pre-boot heartbeat", { path: path5 });
|
|
32105
32166
|
}
|
|
@@ -34113,9 +34174,9 @@ function redactSensitiveFields(value) {
|
|
|
34113
34174
|
if (value == null) return value;
|
|
34114
34175
|
if (Array.isArray(value)) return value.map(redactSensitiveFields);
|
|
34115
34176
|
if (typeof value === "object") {
|
|
34116
|
-
const
|
|
34177
|
+
const record4 = value;
|
|
34117
34178
|
const redacted = {};
|
|
34118
|
-
for (const [key, entry] of Object.entries(
|
|
34179
|
+
for (const [key, entry] of Object.entries(record4)) {
|
|
34119
34180
|
if (SENSITIVE_FIELD_PATTERN.test(key) && typeof entry === "string") {
|
|
34120
34181
|
redacted[key] = redactSensitive(entry);
|
|
34121
34182
|
} else {
|
|
@@ -34678,10 +34739,10 @@ var init_debug = __esm({
|
|
|
34678
34739
|
// src/plugin/logger.ts
|
|
34679
34740
|
function createLocationLogger(options) {
|
|
34680
34741
|
let configuredLevel = options.level ? LOG_LEVEL_FROM_OPERATOR[options.level] ?? "debug" : "debug";
|
|
34681
|
-
const emit = (
|
|
34682
|
-
if (options.sink && options.sinkEnabled()) {
|
|
34742
|
+
const emit = (record4, alwaysHost = false) => {
|
|
34743
|
+
if (options.sink && (alwaysHost || options.sinkEnabled())) {
|
|
34683
34744
|
try {
|
|
34684
|
-
const pending = options.sink(
|
|
34745
|
+
const pending = options.sink(record4);
|
|
34685
34746
|
if (isThenable(pending)) {
|
|
34686
34747
|
pending.then(void 0, () => {
|
|
34687
34748
|
});
|
|
@@ -34690,34 +34751,41 @@ function createLocationLogger(options) {
|
|
|
34690
34751
|
}
|
|
34691
34752
|
}
|
|
34692
34753
|
if (isConsoleLogEnabled2()) {
|
|
34693
|
-
const prefix = `[${
|
|
34694
|
-
const args =
|
|
34754
|
+
const prefix = `[${record4.service}]`;
|
|
34755
|
+
const args = record4.extra ? [prefix, record4.message, record4.extra] : [prefix, record4.message];
|
|
34695
34756
|
try {
|
|
34696
|
-
writeConsoleLog2(
|
|
34757
|
+
writeConsoleLog2(record4.level, ...args);
|
|
34697
34758
|
} catch {
|
|
34698
34759
|
}
|
|
34699
34760
|
}
|
|
34700
34761
|
};
|
|
34701
|
-
const
|
|
34762
|
+
const createEngine3 = (alwaysHost) => createLoggerInstance2({
|
|
34702
34763
|
level: () => configuredLevel,
|
|
34703
34764
|
extraSecretKeys: isProviderSecretKey,
|
|
34704
34765
|
extraValuePatterns: OAUTH_REDIRECT_VALUE_PATTERNS,
|
|
34705
34766
|
captureSink: ({ channel: channel3, level, message, data }) => {
|
|
34706
34767
|
const extra = data !== null && typeof data === "object" && !Array.isArray(data) ? Object.fromEntries(Object.entries(data)) : void 0;
|
|
34707
|
-
emit(
|
|
34708
|
-
|
|
34709
|
-
|
|
34710
|
-
|
|
34711
|
-
|
|
34712
|
-
|
|
34768
|
+
emit(
|
|
34769
|
+
{
|
|
34770
|
+
service: channel3,
|
|
34771
|
+
level: level === "trace" ? "debug" : level,
|
|
34772
|
+
message,
|
|
34773
|
+
extra
|
|
34774
|
+
},
|
|
34775
|
+
alwaysHost
|
|
34776
|
+
);
|
|
34713
34777
|
}
|
|
34714
34778
|
});
|
|
34779
|
+
const engine = createEngine3(false);
|
|
34780
|
+
const hostEngine = createEngine3(true);
|
|
34715
34781
|
return {
|
|
34716
34782
|
createLogger(module) {
|
|
34717
34783
|
const channel3 = engine.createLogger(`antigravity.${module}`);
|
|
34784
|
+
const hostChannel = hostEngine.createLogger(`antigravity.${module}`);
|
|
34718
34785
|
return {
|
|
34719
34786
|
debug: (message, extra) => channel3.debug(message, extra),
|
|
34720
34787
|
info: (message, extra) => channel3.info(message, extra),
|
|
34788
|
+
hostInfo: (message, extra) => hostChannel.info(message, extra),
|
|
34721
34789
|
warn: (message, extra) => channel3.warn(message, extra),
|
|
34722
34790
|
error: (message, extra) => channel3.error(message, extra)
|
|
34723
34791
|
};
|
|
@@ -34731,10 +34799,10 @@ function createLocationLogger(options) {
|
|
|
34731
34799
|
};
|
|
34732
34800
|
}
|
|
34733
34801
|
function createAppLogSink(client) {
|
|
34734
|
-
return (
|
|
34802
|
+
return (record4) => {
|
|
34735
34803
|
const app = client.app;
|
|
34736
34804
|
if (app && typeof app.log === "function") {
|
|
34737
|
-
return app.log({ body:
|
|
34805
|
+
return app.log({ body: record4 });
|
|
34738
34806
|
}
|
|
34739
34807
|
return void 0;
|
|
34740
34808
|
};
|
|
@@ -34747,7 +34815,7 @@ function isConsoleLogEnabled2() {
|
|
|
34747
34815
|
}
|
|
34748
34816
|
function getLegacyLogger() {
|
|
34749
34817
|
legacyLogger ??= createLocationLogger({
|
|
34750
|
-
sink: (
|
|
34818
|
+
sink: (record4) => legacyClient ? createAppLogSink(legacyClient)(record4) : void 0,
|
|
34751
34819
|
sinkEnabled: isDebugTuiEnabled
|
|
34752
34820
|
});
|
|
34753
34821
|
return legacyLogger;
|
|
@@ -34768,6 +34836,10 @@ function createLogger4(module) {
|
|
|
34768
34836
|
return {
|
|
34769
34837
|
debug: (message, extra) => log17("debug", message, extra),
|
|
34770
34838
|
info: (message, extra) => log17("info", message, extra),
|
|
34839
|
+
hostInfo: (message, extra) => {
|
|
34840
|
+
channel3 ??= getLegacyLogger().createLogger(module);
|
|
34841
|
+
channel3.hostInfo?.(message, extra);
|
|
34842
|
+
},
|
|
34771
34843
|
warn: (message, extra) => log17("warn", message, extra),
|
|
34772
34844
|
error: (message, extra) => log17("error", message, extra)
|
|
34773
34845
|
};
|
|
@@ -34891,7 +34963,7 @@ var init_vault_folder = __esm({
|
|
|
34891
34963
|
|
|
34892
34964
|
// src/ga/server/index.ts
|
|
34893
34965
|
init_dist();
|
|
34894
|
-
import { randomUUID as
|
|
34966
|
+
import { randomUUID as randomUUID18 } from "node:crypto";
|
|
34895
34967
|
import {
|
|
34896
34968
|
createServer as createServer2
|
|
34897
34969
|
} from "node:http";
|
|
@@ -37683,17 +37755,17 @@ function normalizeSidebarState(input2) {
|
|
|
37683
37755
|
if (!isObject(input2)) {
|
|
37684
37756
|
return { ...DEFAULT_SIDEBAR_STATE, lastError: "shape" };
|
|
37685
37757
|
}
|
|
37686
|
-
const
|
|
37687
|
-
const version =
|
|
37758
|
+
const record4 = input2;
|
|
37759
|
+
const version = record4.version;
|
|
37688
37760
|
if (version !== 1 && version !== SIDEBAR_STATE_VERSION) {
|
|
37689
37761
|
return {
|
|
37690
37762
|
...DEFAULT_SIDEBAR_STATE,
|
|
37691
37763
|
lastError: `unsupported-version:${stringifySafe(version)}`
|
|
37692
37764
|
};
|
|
37693
37765
|
}
|
|
37694
|
-
const accountsRaw =
|
|
37766
|
+
const accountsRaw = record4.accounts;
|
|
37695
37767
|
const accounts = Array.isArray(accountsRaw) ? accountsRaw.map((entry) => normalizeAccount(entry)).filter((entry) => entry !== null) : [];
|
|
37696
|
-
const routingRaw =
|
|
37768
|
+
const routingRaw = record4.activeRouting;
|
|
37697
37769
|
const activeRouting = {};
|
|
37698
37770
|
if (isObject(routingRaw)) {
|
|
37699
37771
|
for (const [sessionId, entry] of Object.entries(
|
|
@@ -37703,10 +37775,10 @@ function normalizeSidebarState(input2) {
|
|
|
37703
37775
|
if (normalized) activeRouting[sessionId] = normalized;
|
|
37704
37776
|
}
|
|
37705
37777
|
}
|
|
37706
|
-
const checkedAt = toFiniteNumber(
|
|
37707
|
-
const routingAuthoritative =
|
|
37708
|
-
const quotaBackoffUntil = toFiniteNumber(
|
|
37709
|
-
const lastError = typeof
|
|
37778
|
+
const checkedAt = toFiniteNumber(record4.checkedAt);
|
|
37779
|
+
const routingAuthoritative = record4.routingAuthoritative === true;
|
|
37780
|
+
const quotaBackoffUntil = toFiniteNumber(record4.quotaBackoffUntil);
|
|
37781
|
+
const lastError = typeof record4.lastError === "string" ? record4.lastError : void 0;
|
|
37710
37782
|
return {
|
|
37711
37783
|
version: SIDEBAR_STATE_VERSION,
|
|
37712
37784
|
checkedAt: checkedAt ?? 0,
|
|
@@ -37719,15 +37791,15 @@ function normalizeSidebarState(input2) {
|
|
|
37719
37791
|
}
|
|
37720
37792
|
function normalizeAccount(input2) {
|
|
37721
37793
|
if (!isObject(input2)) return null;
|
|
37722
|
-
const
|
|
37723
|
-
const id = typeof
|
|
37724
|
-
const label = typeof
|
|
37794
|
+
const record4 = input2;
|
|
37795
|
+
const id = typeof record4.id === "string" ? record4.id : null;
|
|
37796
|
+
const label = typeof record4.label === "string" ? record4.label : null;
|
|
37725
37797
|
if (!id || !label) return null;
|
|
37726
|
-
const enabled =
|
|
37727
|
-
const health = clampNumber(toFiniteNumber(
|
|
37728
|
-
const current =
|
|
37729
|
-
const cooldownUntil = toFiniteNumber(
|
|
37730
|
-
const quotaRaw =
|
|
37798
|
+
const enabled = record4.enabled !== false;
|
|
37799
|
+
const health = clampNumber(toFiniteNumber(record4.health), 0, 100);
|
|
37800
|
+
const current = record4.current === true;
|
|
37801
|
+
const cooldownUntil = toFiniteNumber(record4.cooldownUntil) ?? void 0;
|
|
37802
|
+
const quotaRaw = record4.quota;
|
|
37731
37803
|
const quota = {};
|
|
37732
37804
|
if (isObject(quotaRaw)) {
|
|
37733
37805
|
for (const key of ["gemini", "non-gemini", "gemini-argon"]) {
|
|
@@ -37736,11 +37808,11 @@ function normalizeAccount(input2) {
|
|
|
37736
37808
|
if (normalized) quota[key] = normalized;
|
|
37737
37809
|
}
|
|
37738
37810
|
}
|
|
37739
|
-
const tier = normalizeTier(
|
|
37811
|
+
const tier = normalizeTier(record4.tier);
|
|
37740
37812
|
return {
|
|
37741
37813
|
id,
|
|
37742
37814
|
label,
|
|
37743
|
-
...typeof
|
|
37815
|
+
...typeof record4.email === "string" ? { email: record4.email } : {},
|
|
37744
37816
|
enabled,
|
|
37745
37817
|
health,
|
|
37746
37818
|
current,
|
|
@@ -37751,22 +37823,22 @@ function normalizeAccount(input2) {
|
|
|
37751
37823
|
}
|
|
37752
37824
|
function normalizeTier(input2) {
|
|
37753
37825
|
if (!isObject(input2)) return void 0;
|
|
37754
|
-
const
|
|
37755
|
-
const id = typeof
|
|
37756
|
-
const capturedAt = toFiniteNumber(
|
|
37826
|
+
const record4 = input2;
|
|
37827
|
+
const id = typeof record4.id === "string" && record4.id.length > 0 ? record4.id : null;
|
|
37828
|
+
const capturedAt = toFiniteNumber(record4.capturedAt);
|
|
37757
37829
|
if (!id || capturedAt === null) return void 0;
|
|
37758
|
-
const paidId = typeof
|
|
37830
|
+
const paidId = typeof record4.paidId === "string" && record4.paidId.length > 0 ? record4.paidId : void 0;
|
|
37759
37831
|
return { id, ...paidId ? { paidId } : {}, capturedAt };
|
|
37760
37832
|
}
|
|
37761
37833
|
function normalizeQuota(input2) {
|
|
37762
37834
|
if (!isObject(input2)) return null;
|
|
37763
|
-
const
|
|
37764
|
-
const remaining = toFiniteNumber(
|
|
37765
|
-
const fraction = toFiniteNumber(
|
|
37835
|
+
const record4 = input2;
|
|
37836
|
+
const remaining = toFiniteNumber(record4.remainingPercent);
|
|
37837
|
+
const fraction = toFiniteNumber(record4.remainingFraction);
|
|
37766
37838
|
if (remaining === null) return null;
|
|
37767
|
-
const resetAt = toFiniteNumber(
|
|
37768
|
-
const checkedAt = toFiniteNumber(
|
|
37769
|
-
const windowsRaw =
|
|
37839
|
+
const resetAt = toFiniteNumber(record4.resetAt) ?? void 0;
|
|
37840
|
+
const checkedAt = toFiniteNumber(record4.checkedAt) ?? void 0;
|
|
37841
|
+
const windowsRaw = record4.windows;
|
|
37770
37842
|
let windows2;
|
|
37771
37843
|
if (Array.isArray(windowsRaw)) {
|
|
37772
37844
|
const parsed = windowsRaw.filter(isObject).map((w) => {
|
|
@@ -37798,12 +37870,12 @@ function normalizeQuota(input2) {
|
|
|
37798
37870
|
}
|
|
37799
37871
|
function normalizeRouting(input2) {
|
|
37800
37872
|
if (!isObject(input2)) return null;
|
|
37801
|
-
const
|
|
37802
|
-
const accountId = typeof
|
|
37803
|
-
const modelFamily =
|
|
37804
|
-
const headerStyle =
|
|
37805
|
-
const strategy =
|
|
37806
|
-
const updatedAt = toFiniteNumber(
|
|
37873
|
+
const record4 = input2;
|
|
37874
|
+
const accountId = typeof record4.accountId === "string" ? record4.accountId : null;
|
|
37875
|
+
const modelFamily = record4.modelFamily;
|
|
37876
|
+
const headerStyle = record4.headerStyle;
|
|
37877
|
+
const strategy = record4.strategy;
|
|
37878
|
+
const updatedAt = toFiniteNumber(record4.updatedAt) ?? 0;
|
|
37807
37879
|
if (!accountId || modelFamily !== "claude" && modelFamily !== "gemini" || headerStyle !== "antigravity" && headerStyle !== "gemini-cli") {
|
|
37808
37880
|
return null;
|
|
37809
37881
|
}
|
|
@@ -39017,7 +39089,7 @@ function createStoreQuotaService(options) {
|
|
|
39017
39089
|
fetchTimeoutMs: options.fetchTimeoutMs,
|
|
39018
39090
|
sidebar: options.sidebar
|
|
39019
39091
|
});
|
|
39020
|
-
const
|
|
39092
|
+
const record4 = async (target, result) => {
|
|
39021
39093
|
if (result.status !== "ok" || result.quota === void 0) {
|
|
39022
39094
|
return { status: "failed", result };
|
|
39023
39095
|
}
|
|
@@ -39051,7 +39123,7 @@ function createStoreQuotaService(options) {
|
|
|
39051
39123
|
index,
|
|
39052
39124
|
force: refreshOptions.force === true
|
|
39053
39125
|
});
|
|
39054
|
-
return
|
|
39126
|
+
return record4(target, result);
|
|
39055
39127
|
};
|
|
39056
39128
|
return {
|
|
39057
39129
|
quotaManager,
|
|
@@ -39105,7 +39177,7 @@ function createStoreQuotaService(options) {
|
|
|
39105
39177
|
return Promise.all(
|
|
39106
39178
|
results.map((result, position) => {
|
|
39107
39179
|
const target = targets[position];
|
|
39108
|
-
return target === void 0 ? { status: "failed", result } :
|
|
39180
|
+
return target === void 0 ? { status: "failed", result } : record4(target, result);
|
|
39109
39181
|
})
|
|
39110
39182
|
);
|
|
39111
39183
|
},
|
|
@@ -40968,11 +41040,11 @@ function redactForDump(value) {
|
|
|
40968
41040
|
function headersToRecord2(headers) {
|
|
40969
41041
|
if (!headers) return {};
|
|
40970
41042
|
if (headers instanceof Headers) {
|
|
40971
|
-
const
|
|
41043
|
+
const record4 = {};
|
|
40972
41044
|
headers.forEach((value, key) => {
|
|
40973
|
-
|
|
41045
|
+
record4[key] = value;
|
|
40974
41046
|
});
|
|
40975
|
-
return
|
|
41047
|
+
return record4;
|
|
40976
41048
|
}
|
|
40977
41049
|
if (Array.isArray(headers)) return Object.fromEntries(headers);
|
|
40978
41050
|
return { ...headers };
|
|
@@ -40993,8 +41065,8 @@ function collectToolNames(value) {
|
|
|
40993
41065
|
return;
|
|
40994
41066
|
}
|
|
40995
41067
|
if (!entry || typeof entry !== "object") return;
|
|
40996
|
-
const
|
|
40997
|
-
const declarations =
|
|
41068
|
+
const record4 = entry;
|
|
41069
|
+
const declarations = record4.functionDeclarations;
|
|
40998
41070
|
if (Array.isArray(declarations)) {
|
|
40999
41071
|
for (const declaration of declarations) {
|
|
41000
41072
|
if (declaration && typeof declaration === "object") {
|
|
@@ -41003,7 +41075,7 @@ function collectToolNames(value) {
|
|
|
41003
41075
|
}
|
|
41004
41076
|
}
|
|
41005
41077
|
}
|
|
41006
|
-
for (const item of Object.values(
|
|
41078
|
+
for (const item of Object.values(record4)) walk(item);
|
|
41007
41079
|
};
|
|
41008
41080
|
walk(value);
|
|
41009
41081
|
return names;
|
|
@@ -42310,9 +42382,9 @@ function normalizeThinkingConfig(config) {
|
|
|
42310
42382
|
if (!config || typeof config !== "object") {
|
|
42311
42383
|
return void 0;
|
|
42312
42384
|
}
|
|
42313
|
-
const
|
|
42314
|
-
const budgetRaw =
|
|
42315
|
-
const includeRaw =
|
|
42385
|
+
const record4 = config;
|
|
42386
|
+
const budgetRaw = record4.thinkingBudget ?? record4.thinking_budget;
|
|
42387
|
+
const includeRaw = record4.includeThoughts ?? record4.include_thoughts;
|
|
42316
42388
|
const thinkingBudget = typeof budgetRaw === "number" && Number.isFinite(budgetRaw) ? budgetRaw : void 0;
|
|
42317
42389
|
const includeThoughts = typeof includeRaw === "boolean" ? includeRaw : void 0;
|
|
42318
42390
|
const enableThinking = thinkingBudget !== void 0 && thinkingBudget > 0;
|
|
@@ -43194,8 +43266,8 @@ function collectForwardedHeaders(sourceHeaders) {
|
|
|
43194
43266
|
if (typeof sourceHeaders.get === "function") {
|
|
43195
43267
|
return sourceHeaders.get(name);
|
|
43196
43268
|
}
|
|
43197
|
-
const
|
|
43198
|
-
for (const [key, value] of Object.entries(
|
|
43269
|
+
const record4 = sourceHeaders;
|
|
43270
|
+
for (const [key, value] of Object.entries(record4)) {
|
|
43199
43271
|
if (key.toLowerCase() === name) return value;
|
|
43200
43272
|
}
|
|
43201
43273
|
return void 0;
|
|
@@ -43232,14 +43304,14 @@ function hasStructuredQuotaReason(details) {
|
|
|
43232
43304
|
if (!Array.isArray(details)) return false;
|
|
43233
43305
|
return details.some((detail) => {
|
|
43234
43306
|
if (!detail || typeof detail !== "object") return false;
|
|
43235
|
-
const
|
|
43236
|
-
const type =
|
|
43307
|
+
const record4 = detail;
|
|
43308
|
+
const type = record4["@type"];
|
|
43237
43309
|
if (typeof type === "string" && type.includes("google.rpc.QuotaFailure"))
|
|
43238
43310
|
return true;
|
|
43239
|
-
const reason =
|
|
43311
|
+
const reason = record4.reason;
|
|
43240
43312
|
if (typeof reason === "string" && QUOTA_REASON_CODES.has(reason))
|
|
43241
43313
|
return true;
|
|
43242
|
-
const nested =
|
|
43314
|
+
const nested = record4.details;
|
|
43243
43315
|
return Array.isArray(nested) ? hasStructuredQuotaReason(nested) : false;
|
|
43244
43316
|
});
|
|
43245
43317
|
}
|
|
@@ -43425,8 +43497,8 @@ function resolveRetryMetadata(options) {
|
|
|
43425
43497
|
if (typeof headers.get === "function") {
|
|
43426
43498
|
return headers.get(name);
|
|
43427
43499
|
}
|
|
43428
|
-
const
|
|
43429
|
-
for (const [key, value] of Object.entries(
|
|
43500
|
+
const record4 = headers;
|
|
43501
|
+
for (const [key, value] of Object.entries(record4)) {
|
|
43430
43502
|
if (key.toLowerCase() === name) return value;
|
|
43431
43503
|
}
|
|
43432
43504
|
return void 0;
|
|
@@ -43553,14 +43625,14 @@ function stripAllThinkingBlocks2(contents) {
|
|
|
43553
43625
|
});
|
|
43554
43626
|
}
|
|
43555
43627
|
function countTrailingToolResults(contents) {
|
|
43556
|
-
let
|
|
43628
|
+
let count4 = 0;
|
|
43557
43629
|
for (let i = contents.length - 1; i >= 0; i--) {
|
|
43558
43630
|
const msg = contents[i];
|
|
43559
43631
|
if (msg?.role === "user") {
|
|
43560
43632
|
const parts = msg.parts || [];
|
|
43561
43633
|
const functionResponses = parts.filter(isFunctionResponsePart);
|
|
43562
43634
|
if (functionResponses.length > 0) {
|
|
43563
|
-
|
|
43635
|
+
count4 += functionResponses.length;
|
|
43564
43636
|
} else {
|
|
43565
43637
|
break;
|
|
43566
43638
|
}
|
|
@@ -43568,7 +43640,7 @@ function countTrailingToolResults(contents) {
|
|
|
43568
43640
|
break;
|
|
43569
43641
|
}
|
|
43570
43642
|
}
|
|
43571
|
-
return
|
|
43643
|
+
return count4;
|
|
43572
43644
|
}
|
|
43573
43645
|
function closeToolLoopForThinking(contents) {
|
|
43574
43646
|
const strippedContents = stripAllThinkingBlocks2(contents);
|
|
@@ -43894,12 +43966,12 @@ function stripInjectedDebugFromParts(parts) {
|
|
|
43894
43966
|
if (!part || typeof part !== "object") {
|
|
43895
43967
|
return part;
|
|
43896
43968
|
}
|
|
43897
|
-
const
|
|
43898
|
-
const text2 = typeof
|
|
43969
|
+
const record4 = part;
|
|
43970
|
+
const text2 = typeof record4.text === "string" ? record4.text : typeof record4.thinking === "string" ? record4.thinking : void 0;
|
|
43899
43971
|
if (text2 && (text2.startsWith(DEBUG_MESSAGE_PREFIX) || text2.startsWith(SYNTHETIC_THINKING_PLACEHOLDER.trim()))) {
|
|
43900
43972
|
const sentinel = { text: "." };
|
|
43901
|
-
if (
|
|
43902
|
-
sentinel.cache_control =
|
|
43973
|
+
if (record4.cache_control !== void 0)
|
|
43974
|
+
sentinel.cache_control = record4.cache_control;
|
|
43903
43975
|
return sentinel;
|
|
43904
43976
|
}
|
|
43905
43977
|
return part;
|
|
@@ -43943,8 +44015,8 @@ function isValidRequestPart(part) {
|
|
|
43943
44015
|
if (!part || typeof part !== "object") {
|
|
43944
44016
|
return false;
|
|
43945
44017
|
}
|
|
43946
|
-
const
|
|
43947
|
-
return Object.hasOwn(
|
|
44018
|
+
const record4 = part;
|
|
44019
|
+
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");
|
|
43948
44020
|
}
|
|
43949
44021
|
function stripCacheControlFromParts(parts) {
|
|
43950
44022
|
if (!Array.isArray(parts)) {
|
|
@@ -43954,9 +44026,9 @@ function stripCacheControlFromParts(parts) {
|
|
|
43954
44026
|
if (!part || typeof part !== "object" || Array.isArray(part)) {
|
|
43955
44027
|
continue;
|
|
43956
44028
|
}
|
|
43957
|
-
const
|
|
43958
|
-
delete
|
|
43959
|
-
delete
|
|
44029
|
+
const record4 = part;
|
|
44030
|
+
delete record4.cache_control;
|
|
44031
|
+
delete record4.cacheControl;
|
|
43960
44032
|
}
|
|
43961
44033
|
}
|
|
43962
44034
|
function stripUnsupportedAntigravityFields(payload) {
|
|
@@ -43984,9 +44056,9 @@ function stripUnsupportedAntigravityFields(payload) {
|
|
|
43984
44056
|
if (!item || typeof item !== "object" || Array.isArray(item)) {
|
|
43985
44057
|
continue;
|
|
43986
44058
|
}
|
|
43987
|
-
const
|
|
43988
|
-
stripCacheControlFromParts(
|
|
43989
|
-
stripCacheControlFromParts(
|
|
44059
|
+
const record4 = item;
|
|
44060
|
+
stripCacheControlFromParts(record4.parts);
|
|
44061
|
+
stripCacheControlFromParts(record4.content);
|
|
43990
44062
|
}
|
|
43991
44063
|
};
|
|
43992
44064
|
stripContentParts(payload.contents);
|
|
@@ -44034,14 +44106,14 @@ function normalizeNativeFunctionResponseRoles(payload) {
|
|
|
44034
44106
|
}
|
|
44035
44107
|
for (const content of contents) {
|
|
44036
44108
|
if (!content || typeof content !== "object") continue;
|
|
44037
|
-
const
|
|
44038
|
-
if (
|
|
44039
|
-
if (
|
|
44040
|
-
const sameTarget =
|
|
44109
|
+
const record4 = content;
|
|
44110
|
+
if (record4.role !== "user" || !Array.isArray(record4.parts)) continue;
|
|
44111
|
+
if (record4.parts.length === 0) continue;
|
|
44112
|
+
const sameTarget = record4.parts.every((part) => {
|
|
44041
44113
|
const response = part?.functionResponse;
|
|
44042
44114
|
return response !== void 0 && signedCalls.has(String(response.id ?? response.name));
|
|
44043
44115
|
});
|
|
44044
|
-
if (sameTarget)
|
|
44116
|
+
if (sameTarget) record4.role = "model";
|
|
44045
44117
|
}
|
|
44046
44118
|
}
|
|
44047
44119
|
function sanitizeRequestPayloadForAntigravity(payload) {
|
|
@@ -44135,10 +44207,10 @@ function sanitizeRequestPayloadForAntigravity(payload) {
|
|
|
44135
44207
|
if (Array.isArray(sys.parts)) {
|
|
44136
44208
|
const sanitizedSystemParts = sys.parts.map((part) => {
|
|
44137
44209
|
if (isValidRequestPart(part)) return part;
|
|
44138
|
-
const
|
|
44210
|
+
const record4 = part;
|
|
44139
44211
|
const sentinel = { text: "." };
|
|
44140
|
-
if (
|
|
44141
|
-
sentinel.cache_control =
|
|
44212
|
+
if (record4?.cache_control !== void 0)
|
|
44213
|
+
sentinel.cache_control = record4.cache_control;
|
|
44142
44214
|
return sentinel;
|
|
44143
44215
|
});
|
|
44144
44216
|
const hasRealContent = sanitizedSystemParts.some(
|
|
@@ -45783,6 +45855,104 @@ async function retainResponseLifetime(response, cancellation) {
|
|
|
45783
45855
|
init_dist();
|
|
45784
45856
|
import { createHash as createHash17 } from "node:crypto";
|
|
45785
45857
|
|
|
45858
|
+
// src/common-auth-embedded/claustrum/host.js
|
|
45859
|
+
import { ClaustrumCredentialError as ClaustrumCredentialError8 } from "@cortexkit/claustrum-client";
|
|
45860
|
+
|
|
45861
|
+
// src/common-auth-embedded/claustrum/availability.js
|
|
45862
|
+
import { ClaustrumCredentialError as ClaustrumCredentialError7 } from "@cortexkit/claustrum-client";
|
|
45863
|
+
import { SocketClosedError as SocketClosedError2, SocketTimeoutError as SocketTimeoutError2, SubcCallError as SubcCallError2 } from "@cortexkit/subc-client";
|
|
45864
|
+
|
|
45865
|
+
// src/common-auth-embedded/claustrum/errors.js
|
|
45866
|
+
var ClaustrumConsumerError2 = class extends Error {
|
|
45867
|
+
kind;
|
|
45868
|
+
constructor(kind, message) {
|
|
45869
|
+
super(message);
|
|
45870
|
+
this.name = "ClaustrumConsumerError";
|
|
45871
|
+
this.kind = kind;
|
|
45872
|
+
}
|
|
45873
|
+
};
|
|
45874
|
+
|
|
45875
|
+
// src/common-auth-embedded/claustrum/availability.js
|
|
45876
|
+
var VAULT_FAILURE_CLASSES2 = Object.freeze({
|
|
45877
|
+
ECONNREFUSED: "unreachable",
|
|
45878
|
+
ENOENT: "unreachable",
|
|
45879
|
+
ECONNRESET: "unreachable",
|
|
45880
|
+
EPIPE: "unreachable",
|
|
45881
|
+
ETIMEDOUT: "unreachable",
|
|
45882
|
+
transport_error: "unreachable",
|
|
45883
|
+
unavailable: "unreachable",
|
|
45884
|
+
timeout: "unreachable",
|
|
45885
|
+
route_closed: "unreachable",
|
|
45886
|
+
// The daemon refused before forwarding, so the vault never saw the request.
|
|
45887
|
+
route_busy: "unreachable",
|
|
45888
|
+
daemon_draining: "unreachable",
|
|
45889
|
+
connection_closed: "unreachable",
|
|
45890
|
+
connection_dropped: "unreachable",
|
|
45891
|
+
request_deadline: "unreachable",
|
|
45892
|
+
deadline_exceeded_no_drop_observed: "unreachable",
|
|
45893
|
+
module_reloading: "unreachable",
|
|
45894
|
+
module_warming: "unreachable",
|
|
45895
|
+
target_unavailable: "unreachable",
|
|
45896
|
+
module_timeout: "unreachable",
|
|
45897
|
+
invalid_response: "answered",
|
|
45898
|
+
invalid_record_version: "answered",
|
|
45899
|
+
invalid_expiry: "answered",
|
|
45900
|
+
invalid_status: "answered",
|
|
45901
|
+
invalid_params: "answered",
|
|
45902
|
+
ttl_unsatisfiable: "answered",
|
|
45903
|
+
not_found: "answered",
|
|
45904
|
+
enrollment_revoked: "answered",
|
|
45905
|
+
enrollment_invalid: "answered",
|
|
45906
|
+
grant_denied: "answered",
|
|
45907
|
+
credential_unavailable: "answered",
|
|
45908
|
+
needs_reauth: "answered",
|
|
45909
|
+
declined: "answered",
|
|
45910
|
+
disabled: "answered",
|
|
45911
|
+
identity_changed: "answered",
|
|
45912
|
+
closed: "answered",
|
|
45913
|
+
client_closed: "answered",
|
|
45914
|
+
pending_exists: "answered",
|
|
45915
|
+
pending_queue_full: "answered",
|
|
45916
|
+
already_consumed: "answered",
|
|
45917
|
+
superseded: "answered",
|
|
45918
|
+
stale_generation: "answered",
|
|
45919
|
+
missing_identity: "answered",
|
|
45920
|
+
invalid_control_body: "answered",
|
|
45921
|
+
unknown_module: "answered",
|
|
45922
|
+
module_removed: "answered",
|
|
45923
|
+
capability_denied: "answered",
|
|
45924
|
+
unknown_channel: "unreachable",
|
|
45925
|
+
stale_route_epoch: "unreachable",
|
|
45926
|
+
capability_forbidden: "answered",
|
|
45927
|
+
capability_unprovided: "answered",
|
|
45928
|
+
capability_ambiguous: "answered",
|
|
45929
|
+
invalid_capability_identifier: "answered",
|
|
45930
|
+
binary_body_required: "answered",
|
|
45931
|
+
binary_call_requires_call_binary: "answered",
|
|
45932
|
+
corr_exhausted: "answered",
|
|
45933
|
+
late_route_cleanup_failed: "answered",
|
|
45934
|
+
reverse_request_capability_not_declared: "answered",
|
|
45935
|
+
stale_route_handle: "answered",
|
|
45936
|
+
reverse_request_unhandled: "answered",
|
|
45937
|
+
handler_error: "answered",
|
|
45938
|
+
health_error: "answered",
|
|
45939
|
+
duplicate_module_id: "answered",
|
|
45940
|
+
route_rejected: "answered",
|
|
45941
|
+
lock_busy: "answered",
|
|
45942
|
+
owner_invalid: "answered",
|
|
45943
|
+
renewal_failed: "answered",
|
|
45944
|
+
unsupported_platform: "answered",
|
|
45945
|
+
EACCES: "answered",
|
|
45946
|
+
EPERM: "answered",
|
|
45947
|
+
ERR_PRIVATE_FILES_SECURITY: "answered"
|
|
45948
|
+
});
|
|
45949
|
+
|
|
45950
|
+
// src/common-auth-embedded/claustrum/host.js
|
|
45951
|
+
var VAULT_HOST_CONNECT_REFUSAL2 = "This host gets its vault accounts from Thalamus, so it can't connect to the vault itself.";
|
|
45952
|
+
function hasVaultHost2() {
|
|
45953
|
+
return process.env.CORTEXKIT_VAULT_HOST === "thalamus";
|
|
45954
|
+
}
|
|
45955
|
+
|
|
45786
45956
|
// src/common-auth-embedded/routing-accessor/handle.js
|
|
45787
45957
|
function routingHandle(sessionId) {
|
|
45788
45958
|
const routing = Reflect.get(globalThis, /* @__PURE__ */ Symbol.for("cortexkit.routing"));
|
|
@@ -45847,9 +46017,9 @@ function billingUsage(value) {
|
|
|
45847
46017
|
["cacheWrite1h", "cache_write_1h"],
|
|
45848
46018
|
["reasoning", "reasoning"]
|
|
45849
46019
|
]) {
|
|
45850
|
-
const
|
|
45851
|
-
if (typeof
|
|
45852
|
-
usage[payloadKey] =
|
|
46020
|
+
const count4 = value[inputKey];
|
|
46021
|
+
if (typeof count4 === "number" && Number.isSafeInteger(count4) && count4 >= 0) {
|
|
46022
|
+
usage[payloadKey] = count4;
|
|
45853
46023
|
}
|
|
45854
46024
|
}
|
|
45855
46025
|
const reasoningIncludedInOutput = value.reasoningIncludedInOutput;
|
|
@@ -46564,6 +46734,175 @@ function publishResponse(dispatch) {
|
|
|
46564
46734
|
});
|
|
46565
46735
|
}
|
|
46566
46736
|
|
|
46737
|
+
// src/plugin/shared/vault-billing.ts
|
|
46738
|
+
import { randomUUID as randomUUID17 } from "node:crypto";
|
|
46739
|
+
function record3(value) {
|
|
46740
|
+
return value !== null && typeof value === "object" && !Array.isArray(value) ? value : void 0;
|
|
46741
|
+
}
|
|
46742
|
+
function count3(value) {
|
|
46743
|
+
return typeof value === "number" && Number.isSafeInteger(value) && value >= 0;
|
|
46744
|
+
}
|
|
46745
|
+
function geminiBillingUsage(value) {
|
|
46746
|
+
const meta = record3(value);
|
|
46747
|
+
if (!meta) return void 0;
|
|
46748
|
+
const usage = {};
|
|
46749
|
+
const prompt = meta.promptTokenCount;
|
|
46750
|
+
const cached = meta.cachedContentTokenCount;
|
|
46751
|
+
if (count3(prompt) && (cached === void 0 || count3(cached) && cached <= prompt))
|
|
46752
|
+
usage.input = prompt - (count3(cached) ? cached : 0);
|
|
46753
|
+
if (count3(cached)) usage.cacheRead = cached;
|
|
46754
|
+
if (count3(meta.candidatesTokenCount)) usage.output = meta.candidatesTokenCount;
|
|
46755
|
+
if (count3(meta.thoughtsTokenCount)) usage.reasoning = meta.thoughtsTokenCount;
|
|
46756
|
+
if (Object.keys(usage).length === 0) return void 0;
|
|
46757
|
+
usage.reasoningIncludedInOutput = false;
|
|
46758
|
+
return usage;
|
|
46759
|
+
}
|
|
46760
|
+
var VaultBillingAttempt = class {
|
|
46761
|
+
constructor(sessionId, receipt2, requestKind, model, attempt, signal) {
|
|
46762
|
+
this.sessionId = sessionId;
|
|
46763
|
+
this.receipt = receipt2;
|
|
46764
|
+
this.requestKind = requestKind;
|
|
46765
|
+
this.model = model;
|
|
46766
|
+
this.attempt = attempt;
|
|
46767
|
+
this.signal = signal;
|
|
46768
|
+
signal?.addEventListener("abort", this.aborted, { once: true });
|
|
46769
|
+
}
|
|
46770
|
+
sessionId;
|
|
46771
|
+
receipt;
|
|
46772
|
+
requestKind;
|
|
46773
|
+
model;
|
|
46774
|
+
attempt;
|
|
46775
|
+
signal;
|
|
46776
|
+
attemptId = randomUUID17();
|
|
46777
|
+
reported = false;
|
|
46778
|
+
started = false;
|
|
46779
|
+
terminal = false;
|
|
46780
|
+
failed = false;
|
|
46781
|
+
status;
|
|
46782
|
+
metadata;
|
|
46783
|
+
aborted = () => this.end(false);
|
|
46784
|
+
event(value) {
|
|
46785
|
+
const outer = record3(value);
|
|
46786
|
+
if (!outer) return;
|
|
46787
|
+
const response = record3(outer.response) ?? outer;
|
|
46788
|
+
if (outer.error || response.error || outer.type === "error")
|
|
46789
|
+
this.failed = true;
|
|
46790
|
+
const meta = record3(response.usageMetadata);
|
|
46791
|
+
if (meta) this.metadata = { ...this.metadata, ...meta };
|
|
46792
|
+
if (Array.isArray(response.candidates))
|
|
46793
|
+
this.terminal ||= response.candidates.some(
|
|
46794
|
+
(candidate) => typeof record3(candidate)?.finishReason === "string"
|
|
46795
|
+
);
|
|
46796
|
+
}
|
|
46797
|
+
/** Tap raw bytes before the wire transformer can inject synthetic zero usage. */
|
|
46798
|
+
observe(response) {
|
|
46799
|
+
this.status = response.status;
|
|
46800
|
+
if (!response.ok) {
|
|
46801
|
+
this.failed = true;
|
|
46802
|
+
this.end(false);
|
|
46803
|
+
return response;
|
|
46804
|
+
}
|
|
46805
|
+
if (!response.body) {
|
|
46806
|
+
this.end(true);
|
|
46807
|
+
return response;
|
|
46808
|
+
}
|
|
46809
|
+
const sse = response.headers.get("content-type")?.includes("text/event-stream");
|
|
46810
|
+
const reader = response.body.getReader();
|
|
46811
|
+
const decoder = new TextDecoder();
|
|
46812
|
+
let pending = "";
|
|
46813
|
+
let oversized = false;
|
|
46814
|
+
const inspect = (line) => {
|
|
46815
|
+
if (line.length > 1024 * 1024 || this.reported) return;
|
|
46816
|
+
if (sse && line.startsWith("event:") && line.slice(6).trim() === "error")
|
|
46817
|
+
this.failed = true;
|
|
46818
|
+
if (sse && !line.startsWith("data:")) return;
|
|
46819
|
+
try {
|
|
46820
|
+
this.event(JSON.parse(sse ? line.slice(5).trim() : line));
|
|
46821
|
+
} catch {
|
|
46822
|
+
}
|
|
46823
|
+
};
|
|
46824
|
+
const body = new ReadableStream(
|
|
46825
|
+
{
|
|
46826
|
+
pull: async (controller) => {
|
|
46827
|
+
try {
|
|
46828
|
+
const chunk = await reader.read();
|
|
46829
|
+
if (chunk.done) {
|
|
46830
|
+
if (!oversized) inspect(pending + decoder.decode());
|
|
46831
|
+
this.end(true);
|
|
46832
|
+
controller.close();
|
|
46833
|
+
reader.releaseLock();
|
|
46834
|
+
return;
|
|
46835
|
+
}
|
|
46836
|
+
this.started = true;
|
|
46837
|
+
if (!oversized) {
|
|
46838
|
+
pending += decoder.decode(chunk.value, { stream: true });
|
|
46839
|
+
if (sse) {
|
|
46840
|
+
let newline = pending.indexOf("\n");
|
|
46841
|
+
while (newline >= 0) {
|
|
46842
|
+
inspect(pending.slice(0, newline));
|
|
46843
|
+
pending = pending.slice(newline + 1);
|
|
46844
|
+
newline = pending.indexOf("\n");
|
|
46845
|
+
}
|
|
46846
|
+
}
|
|
46847
|
+
if (pending.length > 1024 * 1024) {
|
|
46848
|
+
oversized = true;
|
|
46849
|
+
pending = "";
|
|
46850
|
+
}
|
|
46851
|
+
}
|
|
46852
|
+
controller.enqueue(chunk.value);
|
|
46853
|
+
} catch (error) {
|
|
46854
|
+
this.failed = true;
|
|
46855
|
+
this.end(false);
|
|
46856
|
+
controller.error(error);
|
|
46857
|
+
reader.releaseLock();
|
|
46858
|
+
}
|
|
46859
|
+
},
|
|
46860
|
+
cancel: async (reason) => {
|
|
46861
|
+
this.end(this.terminal);
|
|
46862
|
+
try {
|
|
46863
|
+
await reader.cancel(reason);
|
|
46864
|
+
} finally {
|
|
46865
|
+
reader.releaseLock();
|
|
46866
|
+
}
|
|
46867
|
+
}
|
|
46868
|
+
},
|
|
46869
|
+
{ highWaterMark: 0 }
|
|
46870
|
+
);
|
|
46871
|
+
const observed = new Response(body, {
|
|
46872
|
+
status: response.status,
|
|
46873
|
+
statusText: response.statusText,
|
|
46874
|
+
headers: response.headers
|
|
46875
|
+
});
|
|
46876
|
+
Object.defineProperties(observed, {
|
|
46877
|
+
url: { value: response.url },
|
|
46878
|
+
redirected: { value: response.redirected }
|
|
46879
|
+
});
|
|
46880
|
+
return observed;
|
|
46881
|
+
}
|
|
46882
|
+
end(ended) {
|
|
46883
|
+
if (this.reported) return;
|
|
46884
|
+
this.reported = true;
|
|
46885
|
+
this.signal?.removeEventListener("abort", this.aborted);
|
|
46886
|
+
const usage = geminiBillingUsage(this.metadata);
|
|
46887
|
+
reportRouting({
|
|
46888
|
+
sessionId: this.sessionId,
|
|
46889
|
+
kind: "billing",
|
|
46890
|
+
attemptId: this.attemptId,
|
|
46891
|
+
requestKind: this.requestKind,
|
|
46892
|
+
credentialId: this.receipt.credentialId,
|
|
46893
|
+
accountId: this.receipt.accountIdentity,
|
|
46894
|
+
provider: "antigravity",
|
|
46895
|
+
model: this.model,
|
|
46896
|
+
attempt: this.attempt,
|
|
46897
|
+
chargeBasis: "subscription_included",
|
|
46898
|
+
cache: { implicit: true },
|
|
46899
|
+
outcome: this.failed ? "failed" : ended ? "completed" : this.started ? "cut" : "failed",
|
|
46900
|
+
...this.status !== void 0 ? { status: this.status } : {},
|
|
46901
|
+
...usage ? { usage } : {}
|
|
46902
|
+
});
|
|
46903
|
+
}
|
|
46904
|
+
};
|
|
46905
|
+
|
|
46567
46906
|
// src/plugin/shared/vault-routing.ts
|
|
46568
46907
|
function hasVaultRoutingAccessor() {
|
|
46569
46908
|
try {
|
|
@@ -47091,6 +47430,7 @@ function createRequestExecutor(deps) {
|
|
|
47091
47430
|
parentId: requestSessionIdentity.parentSessionId
|
|
47092
47431
|
} : void 0;
|
|
47093
47432
|
const isChildRequest = requestSessionIdentity.parentSessionId !== null;
|
|
47433
|
+
let physicalSendCount = 0;
|
|
47094
47434
|
if (accountManager.getAccountCount() === 0) {
|
|
47095
47435
|
const urlString2 = typeof input2 === "string" ? input2 : toUrlString(input2);
|
|
47096
47436
|
const modelFromUrl = extractModelFromUrl(urlString2) ?? "unknown";
|
|
@@ -47677,6 +48017,32 @@ function createRequestExecutor(deps) {
|
|
|
47677
48017
|
}
|
|
47678
48018
|
}
|
|
47679
48019
|
const selected = account;
|
|
48020
|
+
const sendPhysical = async (url, sendInit, admission, sendModel, requestKind) => {
|
|
48021
|
+
const source = credentials.domain === "local" ? "local" : hasVaultHost2() ? "hosted" : "vault";
|
|
48022
|
+
const message = `request-send source=${source} model=${sendModel} account=Account ${account.index + 1}`;
|
|
48023
|
+
if (source === "local") log17.info(message);
|
|
48024
|
+
else (log17.hostInfo ?? log17.info)(message);
|
|
48025
|
+
const attempt = ++physicalSendCount;
|
|
48026
|
+
const sessionId = requestSessionIdentity.sessionId;
|
|
48027
|
+
const billing = admission && sessionId && hasVaultRoutingAccessor() ? new VaultBillingAttempt(
|
|
48028
|
+
sessionId,
|
|
48029
|
+
admission,
|
|
48030
|
+
requestKind,
|
|
48031
|
+
sendModel,
|
|
48032
|
+
attempt,
|
|
48033
|
+
abortSignal
|
|
48034
|
+
) : void 0;
|
|
48035
|
+
try {
|
|
48036
|
+
const response = await transport(url, sendInit, {
|
|
48037
|
+
signal: abortSignal,
|
|
48038
|
+
onDebug: pushDebug
|
|
48039
|
+
});
|
|
48040
|
+
return billing?.observe(response) ?? response;
|
|
48041
|
+
} catch (error) {
|
|
48042
|
+
billing?.end(false);
|
|
48043
|
+
throw error;
|
|
48044
|
+
}
|
|
48045
|
+
};
|
|
47680
48046
|
const credentialForAuxiliarySend = async (sendInit, preparedProjectId) => {
|
|
47681
48047
|
await assertAdmission();
|
|
47682
48048
|
if (credentials.domain === "vault") {
|
|
@@ -47738,10 +48104,13 @@ function createRequestExecutor(deps) {
|
|
|
47738
48104
|
warmupInit,
|
|
47739
48105
|
projectId
|
|
47740
48106
|
);
|
|
47741
|
-
const warmupResponse = await
|
|
47742
|
-
|
|
47743
|
-
|
|
47744
|
-
|
|
48107
|
+
const warmupResponse = await sendPhysical(
|
|
48108
|
+
warmupUrl,
|
|
48109
|
+
warmupSend.init,
|
|
48110
|
+
warmupSend.admission,
|
|
48111
|
+
prepared.effectiveModel ?? model ?? "unknown",
|
|
48112
|
+
"prime"
|
|
48113
|
+
);
|
|
47745
48114
|
reportVault401(warmupSend.admission, warmupResponse.status);
|
|
47746
48115
|
const transformed = await deadline.wait(
|
|
47747
48116
|
() => wire.transformResponse(
|
|
@@ -47779,13 +48148,12 @@ function createRequestExecutor(deps) {
|
|
|
47779
48148
|
{ ...prepared.init, method: "POST", body: bodyStr },
|
|
47780
48149
|
prepared.projectId ?? ""
|
|
47781
48150
|
);
|
|
47782
|
-
const probeResponse = await
|
|
48151
|
+
const probeResponse = await sendPhysical(
|
|
47783
48152
|
toUrlString(prepared.request),
|
|
47784
48153
|
probeSend.init,
|
|
47785
|
-
|
|
47786
|
-
|
|
47787
|
-
|
|
47788
|
-
}
|
|
48154
|
+
probeSend.admission,
|
|
48155
|
+
prepared.effectiveModel ?? model ?? "unknown",
|
|
48156
|
+
"keep_warm"
|
|
47789
48157
|
);
|
|
47790
48158
|
reportVault401(probeSend.admission, probeResponse.status);
|
|
47791
48159
|
if (probeResponse.body) {
|
|
@@ -47956,10 +48324,12 @@ function createRequestExecutor(deps) {
|
|
|
47956
48324
|
`dispatching request via ${prepared.headerStyle} transport`
|
|
47957
48325
|
);
|
|
47958
48326
|
physicalAttemptStarted = true;
|
|
47959
|
-
const response = await
|
|
48327
|
+
const response = await sendPhysical(
|
|
47960
48328
|
toUrlString(prepared.request),
|
|
47961
48329
|
prepared.init,
|
|
47962
|
-
|
|
48330
|
+
sendAdmission,
|
|
48331
|
+
prepared.effectiveModel ?? model ?? "unknown",
|
|
48332
|
+
kind ?? "primary"
|
|
47963
48333
|
);
|
|
47964
48334
|
if (response.ok) deadline.acceptHeaders();
|
|
47965
48335
|
apiRequestCount++;
|
|
@@ -51742,8 +52112,8 @@ function checkRecord(value, path5, issues, required2, optional3 = []) {
|
|
|
51742
52112
|
}
|
|
51743
52113
|
return true;
|
|
51744
52114
|
}
|
|
51745
|
-
function present4(
|
|
51746
|
-
return Object.hasOwn(
|
|
52115
|
+
function present4(record4, key) {
|
|
52116
|
+
return Object.hasOwn(record4, key) && record4[key] !== void 0;
|
|
51747
52117
|
}
|
|
51748
52118
|
function checkLiteral(value, allowed, path5, issues) {
|
|
51749
52119
|
if (!allowed.some((candidate) => Object.is(candidate, value))) {
|
|
@@ -51838,10 +52208,10 @@ function checkScope(value, path5, issues) {
|
|
|
51838
52208
|
}
|
|
51839
52209
|
issues.add([...path5, "kind"], "expected one of session, sessionless");
|
|
51840
52210
|
}
|
|
51841
|
-
function checkVersion(
|
|
51842
|
-
if (present4(
|
|
52211
|
+
function checkVersion(record4, path5, issues) {
|
|
52212
|
+
if (present4(record4, "version")) {
|
|
51843
52213
|
checkLiteral(
|
|
51844
|
-
|
|
52214
|
+
record4.version,
|
|
51845
52215
|
[ANTIGRAVITY_RPC_VERSION],
|
|
51846
52216
|
[...path5, "version"],
|
|
51847
52217
|
issues
|
|
@@ -52085,9 +52455,9 @@ function checkNotification(value, path5, issues) {
|
|
|
52085
52455
|
checkNotificationPayload(value.payload, [...path5, "payload"], issues);
|
|
52086
52456
|
}
|
|
52087
52457
|
}
|
|
52088
|
-
function checkNullableKeysPresent(
|
|
52458
|
+
function checkNullableKeysPresent(record4, keys, path5, issues) {
|
|
52089
52459
|
for (const key of keys) {
|
|
52090
|
-
if (!Object.hasOwn(
|
|
52460
|
+
if (!Object.hasOwn(record4, key) || record4[key] === void 0) {
|
|
52091
52461
|
issues.add([...path5, key], "missing required key");
|
|
52092
52462
|
}
|
|
52093
52463
|
}
|
|
@@ -53262,7 +53632,7 @@ async function startGaLoopbackBridge(options) {
|
|
|
53262
53632
|
origin,
|
|
53263
53633
|
rewrite(original, job, env3) {
|
|
53264
53634
|
if (closing) throw new Error("The Antigravity bridge is disposed");
|
|
53265
|
-
const id =
|
|
53635
|
+
const id = randomUUID18();
|
|
53266
53636
|
const target = `${origin}/agy/${id}`;
|
|
53267
53637
|
assertLoopbackProxyGuard({ env: env3, target });
|
|
53268
53638
|
const timer = setTimeout(() => {
|
|
@@ -53460,9 +53830,9 @@ var GaSetupContextError = class extends Error {
|
|
|
53460
53830
|
name = "GaSetupContextError";
|
|
53461
53831
|
};
|
|
53462
53832
|
function classifyGaSetupContext(context) {
|
|
53463
|
-
const
|
|
53464
|
-
const session =
|
|
53465
|
-
const location =
|
|
53833
|
+
const record4 = context;
|
|
53834
|
+
const session = record4.session;
|
|
53835
|
+
const location = record4.location;
|
|
53466
53836
|
if (session === void 0 && location === void 0) return "legacy";
|
|
53467
53837
|
const missing = [];
|
|
53468
53838
|
if (!isObject3(location) || typeof location.directory !== "string") {
|
|
@@ -53472,15 +53842,15 @@ function classifyGaSetupContext(context) {
|
|
|
53472
53842
|
missing.push("session.hook");
|
|
53473
53843
|
}
|
|
53474
53844
|
if (session !== void 0 && location !== void 0 && missing.length === 0) {
|
|
53475
|
-
const rpc =
|
|
53845
|
+
const rpc = record4.rpc;
|
|
53476
53846
|
if (!isObject3(rpc) && typeof rpc !== "function" || typeof Reflect.get(rpc, "register") !== "function") {
|
|
53477
53847
|
missing.push("rpc.register");
|
|
53478
53848
|
}
|
|
53479
|
-
const provider2 =
|
|
53849
|
+
const provider2 = record4.provider;
|
|
53480
53850
|
if (!isObject3(provider2) || typeof provider2.transform !== "function") {
|
|
53481
53851
|
missing.push("provider.transform");
|
|
53482
53852
|
}
|
|
53483
|
-
const command =
|
|
53853
|
+
const command = record4.command;
|
|
53484
53854
|
if (!isObject3(command) || typeof command.transform !== "function") {
|
|
53485
53855
|
missing.push("command.transform");
|
|
53486
53856
|
}
|
|
@@ -53492,7 +53862,7 @@ function isObject3(value) {
|
|
|
53492
53862
|
return typeof value === "object" && value !== null;
|
|
53493
53863
|
}
|
|
53494
53864
|
function createGaGeneration() {
|
|
53495
|
-
return `g-${
|
|
53865
|
+
return `g-${randomUUID18()}`;
|
|
53496
53866
|
}
|
|
53497
53867
|
var GaRpcInputError = class extends Error {
|
|
53498
53868
|
constructor(issues) {
|
|
@@ -53889,17 +54259,17 @@ function gaCatalogModels() {
|
|
|
53889
54259
|
);
|
|
53890
54260
|
}
|
|
53891
54261
|
function registerGaModels(editor, catalog) {
|
|
53892
|
-
const
|
|
53893
|
-
if (!
|
|
53894
|
-
const kept = [...
|
|
54262
|
+
const record4 = editor.get(GA_PROVIDER_ID);
|
|
54263
|
+
if (!record4) return;
|
|
54264
|
+
const kept = [...record4.models.values()].filter(
|
|
53895
54265
|
(model) => !catalog.has(model.id)
|
|
53896
54266
|
);
|
|
53897
54267
|
editor.models.set(GA_PROVIDER_ID, [...kept, ...catalog.values()]);
|
|
53898
54268
|
}
|
|
53899
|
-
function stderrLogSink(
|
|
54269
|
+
function stderrLogSink(record4) {
|
|
53900
54270
|
try {
|
|
53901
54271
|
process.stderr.write(
|
|
53902
|
-
`[antigravity] ${
|
|
54272
|
+
`[antigravity] ${record4.level} ${record4.service}: ${record4.message}
|
|
53903
54273
|
`
|
|
53904
54274
|
);
|
|
53905
54275
|
} catch {
|
|
@@ -54101,7 +54471,7 @@ function createGaAntigravityPlugin(overrides = {}) {
|
|
|
54101
54471
|
|
|
54102
54472
|
// src/plugin/index.ts
|
|
54103
54473
|
init_dist();
|
|
54104
|
-
import { createHash as createHash24, randomUUID as
|
|
54474
|
+
import { createHash as createHash24, randomUUID as randomUUID23 } from "node:crypto";
|
|
54105
54475
|
import { join as join39, resolve as resolve29 } from "node:path";
|
|
54106
54476
|
|
|
54107
54477
|
// src/cli.ts
|
|
@@ -54404,7 +54774,7 @@ async function select2(terminal, items, options) {
|
|
|
54404
54774
|
}
|
|
54405
54775
|
|
|
54406
54776
|
// src/common-auth-embedded/claustrum/enrollment.js
|
|
54407
|
-
import { createHash as createHash19, randomBytes as randomBytes6, randomUUID as
|
|
54777
|
+
import { createHash as createHash19, randomBytes as randomBytes6, randomUUID as randomUUID20 } from "node:crypto";
|
|
54408
54778
|
import { constants as fsConstants2 } from "node:fs";
|
|
54409
54779
|
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";
|
|
54410
54780
|
import { basename as basename6, dirname as dirname22, extname as extname2, isAbsolute as isAbsolute4, join as join26, resolve as resolve24 } from "node:path";
|
|
@@ -54482,7 +54852,7 @@ var WRITER_LOCK_CONSTANTS2 = Object.freeze({
|
|
|
54482
54852
|
init_private_files2();
|
|
54483
54853
|
|
|
54484
54854
|
// src/common-auth-embedded/fs/refresh-file-lock.js
|
|
54485
|
-
import { randomUUID as
|
|
54855
|
+
import { randomUUID as randomUUID19 } from "node:crypto";
|
|
54486
54856
|
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";
|
|
54487
54857
|
import { dirname as dirname21, join as join25 } from "node:path";
|
|
54488
54858
|
|
|
@@ -54539,7 +54909,7 @@ var LockOwnershipError2 = class extends Error {
|
|
|
54539
54909
|
// src/common-auth-embedded/fs/refresh-file-lock.js
|
|
54540
54910
|
var leaseCreationTestHooks2;
|
|
54541
54911
|
async function createExclusiveText2(path5, text2) {
|
|
54542
|
-
const tempPath = `${path5}.${
|
|
54912
|
+
const tempPath = `${path5}.${randomUUID19()}.tmp`;
|
|
54543
54913
|
let handle;
|
|
54544
54914
|
try {
|
|
54545
54915
|
handle = await open9(tempPath, "wx", 384);
|
|
@@ -54613,7 +54983,7 @@ function acquireRefreshFileLock2(options) {
|
|
|
54613
54983
|
async function acquireRefreshFileLockWithClock2(options) {
|
|
54614
54984
|
const lockPath = lockPathFor2(options.path, options.name);
|
|
54615
54985
|
const legacyOwnerPath = join25(lockPath, "owner.json");
|
|
54616
|
-
const ownerId =
|
|
54986
|
+
const ownerId = randomUUID19();
|
|
54617
54987
|
const now = options.now ?? Date.now;
|
|
54618
54988
|
let renewTimer = null;
|
|
54619
54989
|
let released = false;
|
|
@@ -54656,7 +55026,7 @@ async function acquireRefreshFileLockWithClock2(options) {
|
|
|
54656
55026
|
let renewalInFlight = null;
|
|
54657
55027
|
const evictPath = `${lockPath}.evicting`;
|
|
54658
55028
|
const evictOwnerPath = join25(evictPath, "owner.json");
|
|
54659
|
-
const evictOwnerId =
|
|
55029
|
+
const evictOwnerId = randomUUID19();
|
|
54660
55030
|
const EVICT_TTL = 5e3;
|
|
54661
55031
|
const MAX_STEAL_ATTEMPTS = 8;
|
|
54662
55032
|
function isChangingLockCreate(error) {
|
|
@@ -54701,7 +55071,7 @@ async function acquireRefreshFileLockWithClock2(options) {
|
|
|
54701
55071
|
});
|
|
54702
55072
|
return;
|
|
54703
55073
|
}
|
|
54704
|
-
const tempPath = `${lockPath}.${
|
|
55074
|
+
const tempPath = `${lockPath}.${randomUUID19()}.tmp`;
|
|
54705
55075
|
let handle;
|
|
54706
55076
|
let created = false;
|
|
54707
55077
|
try {
|
|
@@ -55006,7 +55376,7 @@ async function acquireRefreshFileLockWithClock2(options) {
|
|
|
55006
55376
|
}
|
|
55007
55377
|
if (options.onStep)
|
|
55008
55378
|
await options.onStep("stale-marker-stat");
|
|
55009
|
-
const claimedPath = `${evictPath}.${
|
|
55379
|
+
const claimedPath = `${evictPath}.${randomUUID19()}`;
|
|
55010
55380
|
try {
|
|
55011
55381
|
await rename11(evictPath, claimedPath);
|
|
55012
55382
|
} catch (error) {
|
|
@@ -55397,104 +55767,6 @@ async function acquireRefreshFileLockWithClock2(options) {
|
|
|
55397
55767
|
|
|
55398
55768
|
// src/common-auth-embedded/claustrum/enrollment.js
|
|
55399
55769
|
init_private_files2();
|
|
55400
|
-
|
|
55401
|
-
// src/common-auth-embedded/claustrum/errors.js
|
|
55402
|
-
var ClaustrumConsumerError2 = class extends Error {
|
|
55403
|
-
kind;
|
|
55404
|
-
constructor(kind, message) {
|
|
55405
|
-
super(message);
|
|
55406
|
-
this.name = "ClaustrumConsumerError";
|
|
55407
|
-
this.kind = kind;
|
|
55408
|
-
}
|
|
55409
|
-
};
|
|
55410
|
-
|
|
55411
|
-
// src/common-auth-embedded/claustrum/host.js
|
|
55412
|
-
import { ClaustrumCredentialError as ClaustrumCredentialError8 } from "@cortexkit/claustrum-client";
|
|
55413
|
-
|
|
55414
|
-
// src/common-auth-embedded/claustrum/availability.js
|
|
55415
|
-
import { ClaustrumCredentialError as ClaustrumCredentialError7 } from "@cortexkit/claustrum-client";
|
|
55416
|
-
import { SocketClosedError as SocketClosedError2, SocketTimeoutError as SocketTimeoutError2, SubcCallError as SubcCallError2 } from "@cortexkit/subc-client";
|
|
55417
|
-
var VAULT_FAILURE_CLASSES2 = Object.freeze({
|
|
55418
|
-
ECONNREFUSED: "unreachable",
|
|
55419
|
-
ENOENT: "unreachable",
|
|
55420
|
-
ECONNRESET: "unreachable",
|
|
55421
|
-
EPIPE: "unreachable",
|
|
55422
|
-
ETIMEDOUT: "unreachable",
|
|
55423
|
-
transport_error: "unreachable",
|
|
55424
|
-
unavailable: "unreachable",
|
|
55425
|
-
timeout: "unreachable",
|
|
55426
|
-
route_closed: "unreachable",
|
|
55427
|
-
// The daemon refused before forwarding, so the vault never saw the request.
|
|
55428
|
-
route_busy: "unreachable",
|
|
55429
|
-
daemon_draining: "unreachable",
|
|
55430
|
-
connection_closed: "unreachable",
|
|
55431
|
-
connection_dropped: "unreachable",
|
|
55432
|
-
request_deadline: "unreachable",
|
|
55433
|
-
deadline_exceeded_no_drop_observed: "unreachable",
|
|
55434
|
-
module_reloading: "unreachable",
|
|
55435
|
-
module_warming: "unreachable",
|
|
55436
|
-
target_unavailable: "unreachable",
|
|
55437
|
-
module_timeout: "unreachable",
|
|
55438
|
-
invalid_response: "answered",
|
|
55439
|
-
invalid_record_version: "answered",
|
|
55440
|
-
invalid_expiry: "answered",
|
|
55441
|
-
invalid_status: "answered",
|
|
55442
|
-
invalid_params: "answered",
|
|
55443
|
-
ttl_unsatisfiable: "answered",
|
|
55444
|
-
not_found: "answered",
|
|
55445
|
-
enrollment_revoked: "answered",
|
|
55446
|
-
enrollment_invalid: "answered",
|
|
55447
|
-
grant_denied: "answered",
|
|
55448
|
-
credential_unavailable: "answered",
|
|
55449
|
-
needs_reauth: "answered",
|
|
55450
|
-
declined: "answered",
|
|
55451
|
-
disabled: "answered",
|
|
55452
|
-
identity_changed: "answered",
|
|
55453
|
-
closed: "answered",
|
|
55454
|
-
client_closed: "answered",
|
|
55455
|
-
pending_exists: "answered",
|
|
55456
|
-
pending_queue_full: "answered",
|
|
55457
|
-
already_consumed: "answered",
|
|
55458
|
-
superseded: "answered",
|
|
55459
|
-
stale_generation: "answered",
|
|
55460
|
-
missing_identity: "answered",
|
|
55461
|
-
invalid_control_body: "answered",
|
|
55462
|
-
unknown_module: "answered",
|
|
55463
|
-
module_removed: "answered",
|
|
55464
|
-
capability_denied: "answered",
|
|
55465
|
-
unknown_channel: "unreachable",
|
|
55466
|
-
stale_route_epoch: "unreachable",
|
|
55467
|
-
capability_forbidden: "answered",
|
|
55468
|
-
capability_unprovided: "answered",
|
|
55469
|
-
capability_ambiguous: "answered",
|
|
55470
|
-
invalid_capability_identifier: "answered",
|
|
55471
|
-
binary_body_required: "answered",
|
|
55472
|
-
binary_call_requires_call_binary: "answered",
|
|
55473
|
-
corr_exhausted: "answered",
|
|
55474
|
-
late_route_cleanup_failed: "answered",
|
|
55475
|
-
reverse_request_capability_not_declared: "answered",
|
|
55476
|
-
stale_route_handle: "answered",
|
|
55477
|
-
reverse_request_unhandled: "answered",
|
|
55478
|
-
handler_error: "answered",
|
|
55479
|
-
health_error: "answered",
|
|
55480
|
-
duplicate_module_id: "answered",
|
|
55481
|
-
route_rejected: "answered",
|
|
55482
|
-
lock_busy: "answered",
|
|
55483
|
-
owner_invalid: "answered",
|
|
55484
|
-
renewal_failed: "answered",
|
|
55485
|
-
unsupported_platform: "answered",
|
|
55486
|
-
EACCES: "answered",
|
|
55487
|
-
EPERM: "answered",
|
|
55488
|
-
ERR_PRIVATE_FILES_SECURITY: "answered"
|
|
55489
|
-
});
|
|
55490
|
-
|
|
55491
|
-
// src/common-auth-embedded/claustrum/host.js
|
|
55492
|
-
var VAULT_HOST_CONNECT_REFUSAL2 = "This host gets its vault accounts from Thalamus, so it can't connect to the vault itself.";
|
|
55493
|
-
function hasVaultHost2() {
|
|
55494
|
-
return process.env.CORTEXKIT_VAULT_HOST === "thalamus";
|
|
55495
|
-
}
|
|
55496
|
-
|
|
55497
|
-
// src/common-auth-embedded/claustrum/enrollment.js
|
|
55498
55770
|
var ENROLLMENT_SCHEMA2 = 1;
|
|
55499
55771
|
var ENROLLMENT_FILE_MAX_BYTES2 = 16 * 1024;
|
|
55500
55772
|
var ENROLLMENT_LOCK_TTL_MS2 = 3e4;
|
|
@@ -55532,6 +55804,25 @@ function validEnrollmentDisplayName2(displayName) {
|
|
|
55532
55804
|
const length = Array.from(displayName).length;
|
|
55533
55805
|
return length >= 1 && length <= 40 && !/[\p{Cc}\u061c\u200e\u200f\u202a-\u202e\u2066-\u2069\u200b-\u200d\u2060\ufeff]/u.test(displayName);
|
|
55534
55806
|
}
|
|
55807
|
+
function validEnrollmentRequestedGrants2(grants) {
|
|
55808
|
+
return Array.isArray(grants) && grants.length >= 1 && grants.length <= 4 && Array.from(grants).every((grant) => {
|
|
55809
|
+
if (!isRecord11(grant) || Object.keys(grant).length !== 2 || grant.operation !== "read" && grant.operation !== "list" || !isRecord11(grant.selector))
|
|
55810
|
+
return false;
|
|
55811
|
+
const keys = Object.keys(grant.selector);
|
|
55812
|
+
const key = keys[0];
|
|
55813
|
+
return keys.length === 1 && (key === "category" || key === "exact") && typeof grant.selector[key] === "string" && grant.selector[key].trim().length > 0;
|
|
55814
|
+
});
|
|
55815
|
+
}
|
|
55816
|
+
function grantProposal2(state) {
|
|
55817
|
+
return {
|
|
55818
|
+
...state.requestedGrants !== void 0 && {
|
|
55819
|
+
requestedGrants: state.requestedGrants
|
|
55820
|
+
},
|
|
55821
|
+
...state.requestedGrantsStatus !== void 0 && {
|
|
55822
|
+
requestedGrantsStatus: state.requestedGrantsStatus
|
|
55823
|
+
}
|
|
55824
|
+
};
|
|
55825
|
+
}
|
|
55535
55826
|
function connectClaustrumEnrollmentClient2(options) {
|
|
55536
55827
|
return ClaustrumWireClient2.connect(options);
|
|
55537
55828
|
}
|
|
@@ -55567,6 +55858,7 @@ function decodeEnrollmentState2(value) {
|
|
|
55567
55858
|
throw invalidState2();
|
|
55568
55859
|
}
|
|
55569
55860
|
if (value.phase === "pending") {
|
|
55861
|
+
const grants = decodeGrantProposal2(value);
|
|
55570
55862
|
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)) {
|
|
55571
55863
|
throw invalidState2();
|
|
55572
55864
|
}
|
|
@@ -55579,10 +55871,12 @@ function decodeEnrollmentState2(value) {
|
|
|
55579
55871
|
requestId: value.requestId
|
|
55580
55872
|
},
|
|
55581
55873
|
createdAt: value.createdAt,
|
|
55582
|
-
updatedAt: value.updatedAt
|
|
55874
|
+
updatedAt: value.updatedAt,
|
|
55875
|
+
...grants
|
|
55583
55876
|
};
|
|
55584
55877
|
}
|
|
55585
55878
|
if (value.phase === "approved") {
|
|
55879
|
+
const grants = decodeGrantProposal2(value);
|
|
55586
55880
|
if (value.approvedName !== void 0 && (typeof value.approvedName !== "string" || value.approvedName.length === 0) || !validGeneration2(value.tokenGeneration) || !validTimestamp2(value.updatedAt)) {
|
|
55587
55881
|
throw invalidState2();
|
|
55588
55882
|
}
|
|
@@ -55594,7 +55888,8 @@ function decodeEnrollmentState2(value) {
|
|
|
55594
55888
|
approvedName: value.approvedName
|
|
55595
55889
|
},
|
|
55596
55890
|
tokenGeneration: value.tokenGeneration,
|
|
55597
|
-
updatedAt: value.updatedAt
|
|
55891
|
+
updatedAt: value.updatedAt,
|
|
55892
|
+
...grants
|
|
55598
55893
|
};
|
|
55599
55894
|
}
|
|
55600
55895
|
if (value.phase === "denied" || value.phase === "blocked") {
|
|
@@ -55613,6 +55908,11 @@ function decodeEnrollmentState2(value) {
|
|
|
55613
55908
|
}
|
|
55614
55909
|
throw invalidState2();
|
|
55615
55910
|
}
|
|
55911
|
+
function decodeGrantProposal2(value) {
|
|
55912
|
+
if (value.requestedGrants !== void 0 && !validEnrollmentRequestedGrants2(value.requestedGrants) || value.requestedGrantsStatus !== void 0 && (value.requestedGrants === void 0 || value.requestedGrantsStatus !== "sent" && value.requestedGrantsStatus !== "dropped"))
|
|
55913
|
+
return {};
|
|
55914
|
+
return grantProposal2(value);
|
|
55915
|
+
}
|
|
55616
55916
|
function decodeTokenFile2(value) {
|
|
55617
55917
|
if (!isRecord11(value) || !TOKEN_RE2.test(String(value.token ?? "")) || !validGeneration2(value.token_generation)) {
|
|
55618
55918
|
throw new ClaustrumConsumerError2("invalid-token", "invalid Claustrum enrollment token file");
|
|
@@ -55780,7 +56080,7 @@ async function writeStateAtomic2(path5, state, ancestorOptions = {}) {
|
|
|
55780
56080
|
}
|
|
55781
56081
|
if (windowsPrivateFiles2)
|
|
55782
56082
|
return writePrivateAtomic2(path5, bytes);
|
|
55783
|
-
const temporary = join26(parent, `.${basename6(path5)}.${process.pid}.${
|
|
56083
|
+
const temporary = join26(parent, `.${basename6(path5)}.${process.pid}.${randomUUID20()}.tmp`);
|
|
55784
56084
|
let descriptor;
|
|
55785
56085
|
let created = false;
|
|
55786
56086
|
try {
|
|
@@ -55827,7 +56127,8 @@ async function readEnrollmentStatus2(paths, proposedName) {
|
|
|
55827
56127
|
...state?.phase === "approved" && state.approvedName !== void 0 && {
|
|
55828
56128
|
approvedName: state.approvedName
|
|
55829
56129
|
},
|
|
55830
|
-
tokenGeneration: token.token_generation
|
|
56130
|
+
tokenGeneration: token.token_generation,
|
|
56131
|
+
...state && (state.phase === "approved" || state.phase === "pending") && grantProposal2(state)
|
|
55831
56132
|
}
|
|
55832
56133
|
};
|
|
55833
56134
|
}
|
|
@@ -55875,12 +56176,19 @@ async function vaultAuthority3(paths, proposedName) {
|
|
|
55875
56176
|
return "host";
|
|
55876
56177
|
return enrollmentAuthority2(paths, proposedName);
|
|
55877
56178
|
}
|
|
56179
|
+
async function readClaustrumEnrollmentToken2(tokenPath) {
|
|
56180
|
+
const value = await readBoundedJson2(tokenPath);
|
|
56181
|
+
if (value === void 0)
|
|
56182
|
+
throw new ClaustrumConsumerError2("not-enrolled", "Claustrum enrollment is not configured");
|
|
56183
|
+
return decodeTokenFile2(value);
|
|
56184
|
+
}
|
|
55878
56185
|
function statusFromState2(state) {
|
|
55879
56186
|
if (state.phase === "pending") {
|
|
55880
56187
|
return {
|
|
55881
56188
|
state: "pending",
|
|
55882
56189
|
proposedName: state.proposedName,
|
|
55883
|
-
...state.requestId !== void 0 && { requestId: state.requestId }
|
|
56190
|
+
...state.requestId !== void 0 && { requestId: state.requestId },
|
|
56191
|
+
...grantProposal2(state)
|
|
55884
56192
|
};
|
|
55885
56193
|
}
|
|
55886
56194
|
if (state.phase === "approved") {
|
|
@@ -55890,7 +56198,8 @@ function statusFromState2(state) {
|
|
|
55890
56198
|
...state.approvedName !== void 0 && {
|
|
55891
56199
|
approvedName: state.approvedName
|
|
55892
56200
|
},
|
|
55893
|
-
tokenGeneration: state.tokenGeneration
|
|
56201
|
+
tokenGeneration: state.tokenGeneration,
|
|
56202
|
+
...grantProposal2(state)
|
|
55894
56203
|
};
|
|
55895
56204
|
}
|
|
55896
56205
|
if (state.phase === "denied")
|
|
@@ -55909,6 +56218,7 @@ var ClaustrumEnrollmentManager2 = class {
|
|
|
55909
56218
|
#paths;
|
|
55910
56219
|
#proposedName;
|
|
55911
56220
|
#displayName;
|
|
56221
|
+
#requestedGrants;
|
|
55912
56222
|
#now;
|
|
55913
56223
|
#mintSecret;
|
|
55914
56224
|
#writeTokenFile;
|
|
@@ -55916,6 +56226,12 @@ var ClaustrumEnrollmentManager2 = class {
|
|
|
55916
56226
|
constructor(options) {
|
|
55917
56227
|
if (options.displayName !== void 0 && !validEnrollmentDisplayName2(options.displayName))
|
|
55918
56228
|
throw new ClaustrumConsumerError2("invalid-state", "invalid Claustrum enrollment display name");
|
|
56229
|
+
if (options.requestedGrants !== void 0 && !validEnrollmentRequestedGrants2(options.requestedGrants))
|
|
56230
|
+
throw new ClaustrumConsumerError2("invalid-state", "invalid Claustrum enrollment requested grants");
|
|
56231
|
+
this.#requestedGrants = options.requestedGrants?.map((grant) => ({
|
|
56232
|
+
selector: { ...grant.selector },
|
|
56233
|
+
operation: grant.operation
|
|
56234
|
+
}));
|
|
55919
56235
|
this.#ancestorOptions = options.ancestorOptions ?? {};
|
|
55920
56236
|
this.#client = options.client;
|
|
55921
56237
|
this.#paths = options.paths;
|
|
@@ -55966,6 +56282,7 @@ var ClaustrumEnrollmentManager2 = class {
|
|
|
55966
56282
|
phase: "approved",
|
|
55967
56283
|
proposedName: state?.proposedName ?? this.#proposedName,
|
|
55968
56284
|
tokenGeneration: token.token_generation,
|
|
56285
|
+
...state && grantProposal2(state),
|
|
55969
56286
|
updatedAt: this.#now()
|
|
55970
56287
|
};
|
|
55971
56288
|
await writeStateAtomic2(this.#paths.statePath, approved, this.#ancestorOptions);
|
|
@@ -55977,7 +56294,8 @@ var ClaustrumEnrollmentManager2 = class {
|
|
|
55977
56294
|
...state.phase === "approved" && state.approvedName !== void 0 && {
|
|
55978
56295
|
approvedName: state.approvedName
|
|
55979
56296
|
},
|
|
55980
|
-
tokenGeneration: token.token_generation
|
|
56297
|
+
tokenGeneration: token.token_generation,
|
|
56298
|
+
...state.phase === "approved" && grantProposal2(state)
|
|
55981
56299
|
};
|
|
55982
56300
|
}
|
|
55983
56301
|
if (state?.phase === "approved") {
|
|
@@ -56001,7 +56319,10 @@ var ClaustrumEnrollmentManager2 = class {
|
|
|
56001
56319
|
proposedName: this.#proposedName,
|
|
56002
56320
|
requestSecret: this.#mintSecret(),
|
|
56003
56321
|
createdAt: now,
|
|
56004
|
-
updatedAt: now
|
|
56322
|
+
updatedAt: now,
|
|
56323
|
+
...this.#requestedGrants !== void 0 && {
|
|
56324
|
+
requestedGrants: this.#requestedGrants
|
|
56325
|
+
}
|
|
56005
56326
|
};
|
|
56006
56327
|
if (!TOKEN_RE2.test(state.requestSecret))
|
|
56007
56328
|
throw new ClaustrumConsumerError2("invalid-state", "invalid minted Claustrum enrollment secret");
|
|
@@ -56015,22 +56336,33 @@ var ClaustrumEnrollmentManager2 = class {
|
|
|
56015
56336
|
requestSecretHash
|
|
56016
56337
|
};
|
|
56017
56338
|
let proposed;
|
|
56339
|
+
let requestedGrantsStatus = state.requestedGrantsStatus;
|
|
56018
56340
|
try {
|
|
56019
56341
|
proposed = await this.#client.enrollPropose({
|
|
56020
56342
|
...proposal,
|
|
56021
56343
|
...this.#displayName !== void 0 && {
|
|
56022
56344
|
displayName: this.#displayName
|
|
56345
|
+
},
|
|
56346
|
+
...state.requestedGrants !== void 0 && {
|
|
56347
|
+
requestedGrants: state.requestedGrants
|
|
56023
56348
|
}
|
|
56024
56349
|
});
|
|
56350
|
+
if (state.requestedGrants !== void 0)
|
|
56351
|
+
requestedGrantsStatus = "sent";
|
|
56025
56352
|
} catch (error) {
|
|
56026
|
-
if (this.#displayName === void 0 || !(error instanceof ClaustrumCredentialError9) || error.code !== "invalid_params")
|
|
56353
|
+
if (this.#displayName === void 0 && state.requestedGrants === void 0 || !(error instanceof ClaustrumCredentialError9) || error.code !== "invalid_params")
|
|
56027
56354
|
throw error;
|
|
56028
56355
|
proposed = await this.#client.enrollPropose(proposal);
|
|
56356
|
+
if (state.requestedGrants !== void 0)
|
|
56357
|
+
requestedGrantsStatus = "dropped";
|
|
56029
56358
|
}
|
|
56030
56359
|
state = {
|
|
56031
56360
|
...state,
|
|
56032
56361
|
requestId: proposed.requestId,
|
|
56033
|
-
updatedAt: this.#now()
|
|
56362
|
+
updatedAt: this.#now(),
|
|
56363
|
+
...requestedGrantsStatus !== void 0 && {
|
|
56364
|
+
requestedGrantsStatus
|
|
56365
|
+
}
|
|
56034
56366
|
};
|
|
56035
56367
|
await writeStateAtomic2(this.#paths.statePath, state, this.#ancestorOptions);
|
|
56036
56368
|
} catch (error) {
|
|
@@ -56041,7 +56373,8 @@ var ClaustrumEnrollmentManager2 = class {
|
|
|
56041
56373
|
return {
|
|
56042
56374
|
state: "pending",
|
|
56043
56375
|
proposedName: state.proposedName,
|
|
56044
|
-
retryCode: refusal3.code
|
|
56376
|
+
retryCode: refusal3.code,
|
|
56377
|
+
...grantProposal2(state)
|
|
56045
56378
|
};
|
|
56046
56379
|
}
|
|
56047
56380
|
if (refusal3.code === UNSUPPORTED_ENROLLMENT_CODE2) {
|
|
@@ -56091,6 +56424,7 @@ var ClaustrumEnrollmentManager2 = class {
|
|
|
56091
56424
|
proposedName: state.proposedName,
|
|
56092
56425
|
approvedName: outcome.name,
|
|
56093
56426
|
tokenGeneration: outcome.tokenGeneration,
|
|
56427
|
+
...grantProposal2(state),
|
|
56094
56428
|
updatedAt: this.#now()
|
|
56095
56429
|
};
|
|
56096
56430
|
await writeStateAtomic2(this.#paths.statePath, approved, this.#ancestorOptions);
|
|
@@ -56104,7 +56438,8 @@ var ClaustrumEnrollmentManager2 = class {
|
|
|
56104
56438
|
state: "pending",
|
|
56105
56439
|
proposedName: state.proposedName,
|
|
56106
56440
|
requestId,
|
|
56107
|
-
retryCode: refusal3.code
|
|
56441
|
+
retryCode: refusal3.code,
|
|
56442
|
+
...grantProposal2(state)
|
|
56108
56443
|
};
|
|
56109
56444
|
}
|
|
56110
56445
|
return this.#block(state, refusal3.code);
|
|
@@ -56283,6 +56618,68 @@ function runResolvedCommand(runner, platform, file, args, env3, timeoutMs = 15e3
|
|
|
56283
56618
|
return runner.run(file, args, { env: env3, timeoutMs });
|
|
56284
56619
|
}
|
|
56285
56620
|
|
|
56621
|
+
// src/common-auth-embedded/setup/enrollment-access.js
|
|
56622
|
+
function shellArgument(value) {
|
|
56623
|
+
if (/^[a-zA-Z0-9_:@./-]+$/.test(value))
|
|
56624
|
+
return value;
|
|
56625
|
+
return process.platform === "win32" ? `'${value.replaceAll("'", "''")}'` : `'${value.replaceAll("'", "'\\''")}'`;
|
|
56626
|
+
}
|
|
56627
|
+
async function confirmEnrollmentAccess(client, status, tokenPath, configuredGrants) {
|
|
56628
|
+
const requestedGrants = status.requestedGrants ?? configuredGrants;
|
|
56629
|
+
if (!requestedGrants)
|
|
56630
|
+
return void 0;
|
|
56631
|
+
const grants = requestedGrants.map((grant) => ({
|
|
56632
|
+
grant,
|
|
56633
|
+
...status.approvedName !== void 0 && {
|
|
56634
|
+
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}`
|
|
56635
|
+
}
|
|
56636
|
+
}));
|
|
56637
|
+
if (status.requestedGrantsStatus === "dropped")
|
|
56638
|
+
return { state: "older-vault", grants };
|
|
56639
|
+
try {
|
|
56640
|
+
if (!client.listScoped)
|
|
56641
|
+
return { state: "unconfirmed", grants };
|
|
56642
|
+
const { token } = await readClaustrumEnrollmentToken2(tokenPath);
|
|
56643
|
+
const inventory = await client.listScoped(token);
|
|
56644
|
+
const confirmed = grants.map((entry) => ({
|
|
56645
|
+
...entry,
|
|
56646
|
+
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
|
|
56647
|
+
}));
|
|
56648
|
+
return {
|
|
56649
|
+
state: confirmed.every((entry) => entry.reachableLogins > 0) ? "reachable" : confirmed.some((entry) => entry.reachableLogins > 0) ? "partial" : "no-logins",
|
|
56650
|
+
grants: confirmed.map((entry) => {
|
|
56651
|
+
if (entry.reachableLogins === 0)
|
|
56652
|
+
return entry;
|
|
56653
|
+
const { grantCommand: _, ...reachable } = entry;
|
|
56654
|
+
return reachable;
|
|
56655
|
+
})
|
|
56656
|
+
};
|
|
56657
|
+
} catch {
|
|
56658
|
+
return { state: "unconfirmed", grants };
|
|
56659
|
+
}
|
|
56660
|
+
}
|
|
56661
|
+
function enrollmentAccessLines(access) {
|
|
56662
|
+
const lines = [];
|
|
56663
|
+
const remedy = access.grants.some((entry) => entry.grantCommand) ? "run:" : "check ck auth status for the approved name before granting access.";
|
|
56664
|
+
if (access.state === "older-vault")
|
|
56665
|
+
lines.push(`Approved. This vault is too old to grant access with the approval; ${remedy}`);
|
|
56666
|
+
else if (access.state === "no-logins")
|
|
56667
|
+
lines.push(`Approved, but no logins are reachable yet; ${remedy}`);
|
|
56668
|
+
else if (access.state === "partial")
|
|
56669
|
+
lines.push(`Approved, but some requested access has no reachable logins yet; ${remedy}`);
|
|
56670
|
+
else if (access.state === "unconfirmed")
|
|
56671
|
+
lines.push(`Approved, but access could not be confirmed; ${access.grants.some((entry) => entry.grantCommand) ? "check ck auth status or run:" : remedy}`);
|
|
56672
|
+
for (const { grant, reachableLogins, grantCommand } of access.grants) {
|
|
56673
|
+
if (reachableLogins !== void 0 && reachableLogins > 0) {
|
|
56674
|
+
const target = grant.selector.exact === void 0 ? `the vault's ${JSON.stringify(grant.selector.category)} accounts` : `credential ${JSON.stringify(grant.selector.exact)}`;
|
|
56675
|
+
lines.push(`Confirmed ${grant.operation} access to ${target} (${reachableLogins} reachable ${reachableLogins === 1 ? "login" : "logins"}).`);
|
|
56676
|
+
}
|
|
56677
|
+
if (grantCommand)
|
|
56678
|
+
lines.push(` ${grantCommand}`);
|
|
56679
|
+
}
|
|
56680
|
+
return lines;
|
|
56681
|
+
}
|
|
56682
|
+
|
|
56286
56683
|
// src/common-auth-embedded/setup/command-error.js
|
|
56287
56684
|
var PI_INSTALL_ERROR_MESSAGE = "Pi install failed; run pi install after checking your npm connection.";
|
|
56288
56685
|
function utf8Tail(value) {
|
|
@@ -56323,8 +56720,8 @@ var OUTCOME_TEXT = {
|
|
|
56323
56720
|
"not-enrolled": "not connected",
|
|
56324
56721
|
unknown: "unknown, check with ck auth status"
|
|
56325
56722
|
};
|
|
56326
|
-
function setupEnrollmentLine({ host, outcome }) {
|
|
56327
|
-
return `${HOST_LABELS[host]}: ${OUTCOME_TEXT[outcome]}`;
|
|
56723
|
+
function setupEnrollmentLine({ host, outcome, access }) {
|
|
56724
|
+
return `${HOST_LABELS[host]}: ${OUTCOME_TEXT[outcome]}${access ? ` \u2014 ${enrollmentAccessLines(access).join("\n")}` : ""}`;
|
|
56328
56725
|
}
|
|
56329
56726
|
var recordedEnrollment = /* @__PURE__ */ new WeakMap();
|
|
56330
56727
|
function recordSetupEnrollment(failure2, enrollment) {
|
|
@@ -56862,7 +57259,7 @@ function approveCommand(requestId, name) {
|
|
|
56862
57259
|
async function connectSetupHost(plugin2, host, io, terminal, fence) {
|
|
56863
57260
|
if (hasVaultHost2())
|
|
56864
57261
|
throw new Error(VAULT_HOST_CONNECT_REFUSAL2);
|
|
56865
|
-
const { name, displayName, paths: input2 } = plugin2.vault.hosts[host];
|
|
57262
|
+
const { name, displayName, requestedGrants, paths: input2 } = plugin2.vault.hosts[host];
|
|
56866
57263
|
const paths = hostEnrollmentPaths2(input2);
|
|
56867
57264
|
await fence();
|
|
56868
57265
|
const client = await (io.connect ?? connectClaustrumEnrollmentClient2)({
|
|
@@ -56877,6 +57274,7 @@ async function connectSetupHost(plugin2, host, io, terminal, fence) {
|
|
|
56877
57274
|
const manager = new ClaustrumEnrollmentManager2({
|
|
56878
57275
|
proposedName: name,
|
|
56879
57276
|
displayName,
|
|
57277
|
+
requestedGrants,
|
|
56880
57278
|
paths,
|
|
56881
57279
|
// Each tick of the wait below checks the fence once, just before
|
|
56882
57280
|
// reconcile proposes or polls. Checking again inside every vault call
|
|
@@ -56892,7 +57290,11 @@ async function connectSetupHost(plugin2, host, io, terminal, fence) {
|
|
|
56892
57290
|
const initial = await manager.status();
|
|
56893
57291
|
if (initial.state === "approved") {
|
|
56894
57292
|
printLine2(terminal, `Already connected as ${initial.approvedName ?? initial.proposedName}.`);
|
|
56895
|
-
|
|
57293
|
+
const access = await confirmEnrollmentAccess(client, initial, paths.tokenPath, requestedGrants);
|
|
57294
|
+
if (access)
|
|
57295
|
+
for (const line of enrollmentAccessLines(access))
|
|
57296
|
+
printLine2(terminal, line);
|
|
57297
|
+
return access;
|
|
56896
57298
|
}
|
|
56897
57299
|
printLine2(terminal, `Asking the vault to connect ${name}\u2026`);
|
|
56898
57300
|
const deadline = now() + ENROLLMENT_WAIT_MS;
|
|
@@ -56904,7 +57306,11 @@ async function connectSetupHost(plugin2, host, io, terminal, fence) {
|
|
|
56904
57306
|
const status = await manager.reconcile();
|
|
56905
57307
|
if (status.state === "approved") {
|
|
56906
57308
|
printLine2(terminal, `Connected ${host} to Claustrum.`);
|
|
56907
|
-
|
|
57309
|
+
const access = await confirmEnrollmentAccess(client, status, paths.tokenPath, requestedGrants);
|
|
57310
|
+
if (access)
|
|
57311
|
+
for (const line of enrollmentAccessLines(access))
|
|
57312
|
+
printLine2(terminal, line);
|
|
57313
|
+
return access;
|
|
56908
57314
|
}
|
|
56909
57315
|
if (status.state === "unavailable" && status.code === UNSUPPORTED_ENROLLMENT_CODE2)
|
|
56910
57316
|
throw new HostNotEnrolledError(UNSUPPORTED_VAULT_MESSAGE, {
|
|
@@ -57100,7 +57506,7 @@ import { domainToUnicode } from "node:url";
|
|
|
57100
57506
|
import { applyEdits, createScanner, findNodeAtLocation, modify, parse as parse2, parseTree } from "jsonc-parser";
|
|
57101
57507
|
|
|
57102
57508
|
// src/common-auth-embedded/setup/config-write.js
|
|
57103
|
-
import { randomUUID as
|
|
57509
|
+
import { randomUUID as randomUUID21 } from "node:crypto";
|
|
57104
57510
|
import { mkdir as mkdir16, open as open11, rename as rename13, stat as stat16, unlink as unlink12 } from "node:fs/promises";
|
|
57105
57511
|
import { basename as basename7, dirname as dirname23, join as join28 } from "node:path";
|
|
57106
57512
|
import { setTimeout as delay2 } from "node:timers/promises";
|
|
@@ -57117,7 +57523,7 @@ async function writeHostConfigAtomic(file, content, options = {}) {
|
|
|
57117
57523
|
throw error;
|
|
57118
57524
|
}
|
|
57119
57525
|
}
|
|
57120
|
-
const stage = join28(parent, `.${basename7(file)}.${(options.stageName ??
|
|
57526
|
+
const stage = join28(parent, `.${basename7(file)}.${(options.stageName ?? randomUUID21)()}.tmp`);
|
|
57121
57527
|
let created = false;
|
|
57122
57528
|
try {
|
|
57123
57529
|
const handle = await open11(stage, "wx", mode ?? 438);
|
|
@@ -57338,12 +57744,15 @@ function validatePlugin(plugin2) {
|
|
|
57338
57744
|
for (const host of Object.values(plugin2.vault.hosts)) {
|
|
57339
57745
|
if (!/^[a-z0-9][a-z0-9-]*$/.test(host.name))
|
|
57340
57746
|
throw new Error("Setup requires lowercase vault names containing only letters, digits and dashes.");
|
|
57747
|
+
if (host.requestedGrants !== void 0 && !validEnrollmentRequestedGrants2(host.requestedGrants))
|
|
57748
|
+
throw new Error("invalid Claustrum enrollment requested grants");
|
|
57341
57749
|
}
|
|
57342
57750
|
}
|
|
57343
|
-
async function enrollmentReport(plugin2, hosts, recorded) {
|
|
57751
|
+
async function enrollmentReport(plugin2, hosts, recorded, recordedAccess) {
|
|
57344
57752
|
const report = [];
|
|
57345
57753
|
for (const host of hosts) {
|
|
57346
57754
|
let outcome = recorded.get(host) ?? "not-enrolled";
|
|
57755
|
+
let access = recordedAccess.get(host);
|
|
57347
57756
|
if (outcome === "unknown") {
|
|
57348
57757
|
const { name, paths } = plugin2.vault.hosts[host];
|
|
57349
57758
|
const authority = await vaultAuthority3(hostEnrollmentPaths2(paths), name).catch(() => "unreadable");
|
|
@@ -57351,8 +57760,13 @@ async function enrollmentReport(plugin2, hosts, recorded) {
|
|
|
57351
57760
|
outcome = "enrolled";
|
|
57352
57761
|
else if (authority === "local")
|
|
57353
57762
|
outcome = "not-enrolled";
|
|
57763
|
+
if (outcome === "enrolled") {
|
|
57764
|
+
const status = await readClaustrumEnrollmentStatus2(hostEnrollmentPaths2(paths), name).catch(() => void 0);
|
|
57765
|
+
if (status?.state === "approved")
|
|
57766
|
+
access = await confirmEnrollmentAccess({}, status, hostEnrollmentPaths2(paths).tokenPath, plugin2.vault.hosts[host].requestedGrants);
|
|
57767
|
+
}
|
|
57354
57768
|
}
|
|
57355
|
-
report.push({ host, outcome });
|
|
57769
|
+
report.push({ host, outcome, ...access && { access } });
|
|
57356
57770
|
}
|
|
57357
57771
|
return report;
|
|
57358
57772
|
}
|
|
@@ -57481,6 +57895,7 @@ ${write.content}`);
|
|
|
57481
57895
|
piAgentDir: detection.pi.directory
|
|
57482
57896
|
};
|
|
57483
57897
|
const enrollment = /* @__PURE__ */ new Map();
|
|
57898
|
+
const enrollmentAccess = /* @__PURE__ */ new Map();
|
|
57484
57899
|
try {
|
|
57485
57900
|
for (const host of hosts) {
|
|
57486
57901
|
await stopped();
|
|
@@ -57489,7 +57904,9 @@ ${write.content}`);
|
|
|
57489
57904
|
if (useVault) {
|
|
57490
57905
|
enrollment.set(host, "unknown");
|
|
57491
57906
|
try {
|
|
57492
|
-
await connectSetupHost(plugin2, host, io, terminal, stopped);
|
|
57907
|
+
const access = await connectSetupHost(plugin2, host, io, terminal, stopped);
|
|
57908
|
+
if (access)
|
|
57909
|
+
enrollmentAccess.set(host, access);
|
|
57493
57910
|
} catch (error) {
|
|
57494
57911
|
if (error instanceof HostNotEnrolledError)
|
|
57495
57912
|
enrollment.set(host, "not-enrolled");
|
|
@@ -57514,7 +57931,7 @@ ${write.content}`);
|
|
|
57514
57931
|
if (enrollment.size === 0)
|
|
57515
57932
|
throw error;
|
|
57516
57933
|
try {
|
|
57517
|
-
const report = await enrollmentReport(plugin2, hosts, enrollment);
|
|
57934
|
+
const report = await enrollmentReport(plugin2, hosts, enrollment, enrollmentAccess);
|
|
57518
57935
|
recordSetupEnrollment(error, report);
|
|
57519
57936
|
for (const entry of report)
|
|
57520
57937
|
printLine2(terminal, setupEnrollmentLine(entry));
|
|
@@ -57705,6 +58122,12 @@ async function createSetupPlugin(deps, migrateOpenCode, forceLogin = false) {
|
|
|
57705
58122
|
opencode: {
|
|
57706
58123
|
name: OPENCODE_VAULT_ENROLLMENT_NAME,
|
|
57707
58124
|
displayName: "Antigravity sign-in for OpenCode",
|
|
58125
|
+
requestedGrants: [
|
|
58126
|
+
{
|
|
58127
|
+
selector: { category: "antigravity-native" },
|
|
58128
|
+
operation: "read"
|
|
58129
|
+
}
|
|
58130
|
+
],
|
|
57708
58131
|
// Read at each use: a real run settles the vault folder in
|
|
57709
58132
|
// `beforeSignIn`, which may move it after this plugin is built.
|
|
57710
58133
|
paths: {
|
|
@@ -57717,6 +58140,12 @@ async function createSetupPlugin(deps, migrateOpenCode, forceLogin = false) {
|
|
|
57717
58140
|
pi: {
|
|
57718
58141
|
name: "antigravity-auth-pi",
|
|
57719
58142
|
displayName: "Antigravity sign-in for Pi",
|
|
58143
|
+
requestedGrants: [
|
|
58144
|
+
{
|
|
58145
|
+
selector: { category: "antigravity-native" },
|
|
58146
|
+
operation: "read"
|
|
58147
|
+
}
|
|
58148
|
+
],
|
|
57720
58149
|
paths: { stateDir: piDir, host: "pi" }
|
|
57721
58150
|
}
|
|
57722
58151
|
};
|
|
@@ -59158,7 +59587,7 @@ function isSessionId(value) {
|
|
|
59158
59587
|
|
|
59159
59588
|
// src/common-auth-embedded/rpc/port-file.js
|
|
59160
59589
|
init_private_files2();
|
|
59161
|
-
import { createHash as createHash21, randomUUID as
|
|
59590
|
+
import { createHash as createHash21, randomUUID as randomUUID22 } from "node:crypto";
|
|
59162
59591
|
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";
|
|
59163
59592
|
import { uptime as uptime2 } from "node:os";
|
|
59164
59593
|
import { join as join35, resolve as resolve28 } from "node:path";
|
|
@@ -59219,7 +59648,7 @@ async function writePortFile(dir, entry, options = {}) {
|
|
|
59219
59648
|
await ensurePrivateDirectory2(dir, options.secureDir ?? false);
|
|
59220
59649
|
await options.beforeWrite?.();
|
|
59221
59650
|
await writePrivateAtomic2(target, JSON.stringify({ ...entry, startedAt: Date.now() }), {
|
|
59222
|
-
stagePath: `${target}.${(options.stageName ??
|
|
59651
|
+
stagePath: `${target}.${(options.stageName ?? randomUUID22)()}.tmp`
|
|
59223
59652
|
});
|
|
59224
59653
|
return target;
|
|
59225
59654
|
}
|
|
@@ -59231,7 +59660,7 @@ async function writePortFile(dir, entry, options = {}) {
|
|
|
59231
59660
|
await chmod7(dir, 448);
|
|
59232
59661
|
await options.beforeWrite?.();
|
|
59233
59662
|
const full = { ...entry, startedAt: Date.now() };
|
|
59234
|
-
const tmp = `${target}.${(options.stageName ??
|
|
59663
|
+
const tmp = `${target}.${(options.stageName ?? randomUUID22)()}.tmp`;
|
|
59235
59664
|
let handle;
|
|
59236
59665
|
let created = false;
|
|
59237
59666
|
try {
|
|
@@ -63901,7 +64330,7 @@ function createPluginLifecycle(options) {
|
|
|
63901
64330
|
const queueDrained = (async () => {
|
|
63902
64331
|
await queue2?.dispose();
|
|
63903
64332
|
})();
|
|
63904
|
-
const
|
|
64333
|
+
const record4 = {
|
|
63905
64334
|
requests,
|
|
63906
64335
|
done: (async () => {
|
|
63907
64336
|
const failures = [];
|
|
@@ -63913,14 +64342,14 @@ function createPluginLifecycle(options) {
|
|
|
63913
64342
|
reportCleanupFailures(failures);
|
|
63914
64343
|
})()
|
|
63915
64344
|
};
|
|
63916
|
-
retiring.add(
|
|
63917
|
-
|
|
63918
|
-
() => retiring.delete(
|
|
64345
|
+
retiring.add(record4);
|
|
64346
|
+
record4.done.then(
|
|
64347
|
+
() => retiring.delete(record4),
|
|
63919
64348
|
() => {
|
|
63920
|
-
if (!requests) retiring.delete(
|
|
64349
|
+
if (!requests) retiring.delete(record4);
|
|
63921
64350
|
}
|
|
63922
64351
|
);
|
|
63923
|
-
return { queueDrained, done:
|
|
64352
|
+
return { queueDrained, done: record4.done };
|
|
63924
64353
|
};
|
|
63925
64354
|
const disposeAccountRuntime = async () => {
|
|
63926
64355
|
const oldQueue = refreshQueue;
|
|
@@ -63935,7 +64364,7 @@ function createPluginLifecycle(options) {
|
|
|
63935
64364
|
const aborted = Promise.all([
|
|
63936
64365
|
collectCleanupFailure(() => oldRequests?.dispose(), failures),
|
|
63937
64366
|
...retired.map(
|
|
63938
|
-
(
|
|
64367
|
+
(record4) => collectCleanupFailure(() => record4.requests?.dispose(), failures)
|
|
63939
64368
|
)
|
|
63940
64369
|
]);
|
|
63941
64370
|
const liveQueueDrained = collectCleanupFailure(
|
|
@@ -63946,7 +64375,7 @@ function createPluginLifecycle(options) {
|
|
|
63946
64375
|
aborted,
|
|
63947
64376
|
liveQueueDrained,
|
|
63948
64377
|
...retired.map(
|
|
63949
|
-
(
|
|
64378
|
+
(record4) => collectCleanupFailure(() => record4.done, failures)
|
|
63950
64379
|
)
|
|
63951
64380
|
]);
|
|
63952
64381
|
await collectCleanupFailure(() => oldManager?.dispose(), failures);
|
|
@@ -64491,7 +64920,7 @@ var createAntigravityPlugin = (providerId, options = {}) => async (input2) => {
|
|
|
64491
64920
|
const key = vaultAccountRowKey(row);
|
|
64492
64921
|
const existing = vaultSelectors2.get(key);
|
|
64493
64922
|
if (existing) return existing;
|
|
64494
|
-
const selector =
|
|
64923
|
+
const selector = randomUUID23();
|
|
64495
64924
|
vaultSelectors2.set(key, selector);
|
|
64496
64925
|
return selector;
|
|
64497
64926
|
},
|