@cortexkit/opencode-antigravity-auth 3.0.6 → 3.0.7
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 +620 -120
- package/dist/cli.js.map +4 -4
- package/dist/cli.meta.json +128 -44
- package/dist/index.js +1469 -675
- package/dist/index.js.map +4 -4
- package/dist/index.meta.json +154 -73
- package/dist/server.js +1075 -280
- package/dist/server.js.map +4 -4
- package/dist/server.meta.json +1 -1
- package/dist/src/common-auth-embedded/claustrum/consumer.d.ts +11 -1
- package/dist/src/common-auth-embedded/claustrum/consumer.js +38 -1
- package/dist/src/common-auth-embedded/claustrum/custody.d.ts +29 -0
- package/dist/src/common-auth-embedded/claustrum/custody.js +17 -0
- package/dist/src/common-auth-embedded/claustrum/index.d.ts +1 -1
- package/dist/src/common-auth-embedded/fs/refresh-file-lock.d.ts +8 -2
- package/dist/src/common-auth-embedded/fs/refresh-file-lock.js +6 -1
- package/dist/src/common-auth-embedded/pi-slot/lock.js +7 -3
- package/dist/src/common-auth-embedded/quota/format.d.ts +14 -3
- package/dist/src/common-auth-embedded/quota/format.js +135 -18
- package/dist/src/common-auth-embedded/quota/index.d.ts +1 -1
- package/dist/src/common-auth-embedded/quota/index.js +1 -1
- package/dist/src/common-auth-embedded/setup/command-error.d.ts +32 -0
- package/dist/src/common-auth-embedded/setup/command-error.js +79 -0
- package/dist/src/common-auth-embedded/setup/command-runner.js +118 -24
- package/dist/src/common-auth-embedded/setup/command.js +75 -19
- package/dist/src/common-auth-embedded/setup/enroll.js +17 -5
- package/dist/src/common-auth-embedded/setup/index.d.ts +2 -1
- package/dist/src/common-auth-embedded/setup/index.js +1 -0
- package/dist/src/common-auth-embedded/setup/register.js +8 -2
- package/dist/src/common-auth-embedded/setup/types.d.ts +14 -0
- package/dist/src/common-auth-embedded/source-output.json +92 -76
- package/dist/src/common-auth-embedded/store/pool.d.ts +1 -1
- package/dist/src/common-auth-embedded/store/pool.js +0 -1
- package/dist/src/common-auth-embedded/store/refresh-lock.d.ts +0 -1
- package/dist/src/common-auth-embedded/store/refresh-lock.js +0 -1
- package/dist/src/ga/server/index.d.ts.map +1 -1
- package/dist/src/ga/server/index.js +4 -2
- package/dist/src/ga/server/index.js.map +1 -1
- package/dist/src/ga/tui/host-ga.d.ts.map +1 -1
- package/dist/src/ga/tui/host-ga.js +37 -3
- package/dist/src/ga/tui/host-ga.js.map +1 -1
- package/dist/src/plugin/config/schema.d.ts.map +1 -1
- package/dist/src/plugin/config/schema.js +2 -1
- package/dist/src/plugin/config/schema.js.map +1 -1
- package/dist/src/plugin/ga-location-services.d.ts.map +1 -1
- package/dist/src/plugin/ga-location-services.js +4 -3
- package/dist/src/plugin/ga-location-services.js.map +1 -1
- package/dist/src/plugin/gemini-dump.d.ts.map +1 -1
- package/dist/src/plugin/gemini-dump.js +2 -5
- package/dist/src/plugin/gemini-dump.js.map +1 -1
- package/dist/src/plugin/index.d.ts.map +1 -1
- package/dist/src/plugin/index.js +3 -3
- package/dist/src/plugin/index.js.map +1 -1
- package/dist/src/plugin/logging-utils.d.ts.map +1 -1
- package/dist/src/plugin/logging-utils.js +2 -5
- package/dist/src/plugin/logging-utils.js.map +1 -1
- package/dist/src/plugin/request.d.ts +1 -2
- package/dist/src/plugin/request.d.ts.map +1 -1
- package/dist/src/plugin/request.js +8 -12
- package/dist/src/plugin/request.js.map +1 -1
- package/dist/src/plugin/shared/request-services.d.ts +8 -1
- package/dist/src/plugin/shared/request-services.d.ts.map +1 -1
- package/dist/src/plugin/shared/request-services.js +140 -58
- package/dist/src/plugin/shared/request-services.js.map +1 -1
- package/dist/src/plugin/shared/vault-request-credentials.d.ts +12 -3
- package/dist/src/plugin/shared/vault-request-credentials.d.ts.map +1 -1
- package/dist/src/plugin/shared/vault-request-credentials.js +3 -0
- package/dist/src/plugin/shared/vault-request-credentials.js.map +1 -1
- package/dist/src/plugin/vault-custody.d.ts +14 -1
- package/dist/src/plugin/vault-custody.d.ts.map +1 -1
- package/dist/src/plugin/vault-custody.js +57 -10
- package/dist/src/plugin/vault-custody.js.map +1 -1
- package/dist/src/sidebar-projection.d.ts +4 -0
- package/dist/src/sidebar-projection.d.ts.map +1 -1
- package/dist/src/sidebar-projection.js +6 -2
- package/dist/src/sidebar-projection.js.map +1 -1
- package/dist/src/tui/quota-layout.d.ts +94 -0
- package/dist/src/tui/quota-layout.d.ts.map +1 -0
- package/dist/src/tui/quota-layout.js +139 -0
- package/dist/src/tui/quota-layout.js.map +1 -0
- package/dist/src/tui/route-layout.d.ts +8 -0
- package/dist/src/tui/route-layout.d.ts.map +1 -0
- package/dist/src/tui/route-layout.js +36 -0
- package/dist/src/tui/route-layout.js.map +1 -0
- package/dist/src/tui.d.ts.map +1 -1
- package/dist/src/tui.js +26 -128
- package/dist/src/tui.js.map +1 -1
- package/dist/tui-build-map.json +42 -13
- package/dist/tui-ga-build-map.json +46 -17
- package/dist/types/src/common-auth-embedded/claustrum/consumer.d.ts +11 -1
- package/dist/types/src/common-auth-embedded/claustrum/custody.d.ts +29 -0
- package/dist/types/src/common-auth-embedded/claustrum/index.d.ts +1 -1
- package/dist/types/src/common-auth-embedded/fs/refresh-file-lock.d.ts +8 -2
- package/dist/types/src/common-auth-embedded/quota/format.d.ts +14 -3
- package/dist/types/src/common-auth-embedded/quota/index.d.ts +1 -1
- package/dist/types/src/common-auth-embedded/setup/command-error.d.ts +32 -0
- package/dist/types/src/common-auth-embedded/setup/index.d.ts +2 -1
- package/dist/types/src/common-auth-embedded/setup/types.d.ts +14 -0
- package/dist/types/src/common-auth-embedded/store/pool.d.ts +1 -1
- package/dist/types/src/common-auth-embedded/store/refresh-lock.d.ts +0 -1
- package/dist/types/src/ga/server/index.d.ts.map +1 -1
- package/dist/types/src/plugin/config/schema.d.ts.map +1 -1
- package/dist/types/src/plugin/ga-location-services.d.ts.map +1 -1
- package/dist/types/src/plugin/gemini-dump.d.ts.map +1 -1
- package/dist/types/src/plugin/index.d.ts.map +1 -1
- package/dist/types/src/plugin/logging-utils.d.ts.map +1 -1
- package/dist/types/src/plugin/request.d.ts +1 -2
- package/dist/types/src/plugin/request.d.ts.map +1 -1
- package/dist/types/src/plugin/shared/request-services.d.ts +8 -1
- package/dist/types/src/plugin/shared/request-services.d.ts.map +1 -1
- package/dist/types/src/plugin/shared/vault-request-credentials.d.ts +12 -3
- package/dist/types/src/plugin/shared/vault-request-credentials.d.ts.map +1 -1
- package/dist/types/src/plugin/vault-custody.d.ts +14 -1
- package/dist/types/src/plugin/vault-custody.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/common-auth-embedded/claustrum/consumer.d.ts +11 -1
- package/src/common-auth-embedded/claustrum/consumer.js +38 -1
- package/src/common-auth-embedded/claustrum/custody.d.ts +29 -0
- package/src/common-auth-embedded/claustrum/custody.js +17 -0
- package/src/common-auth-embedded/claustrum/index.d.ts +1 -1
- package/src/common-auth-embedded/fs/refresh-file-lock.d.ts +8 -2
- package/src/common-auth-embedded/fs/refresh-file-lock.js +6 -1
- package/src/common-auth-embedded/pi-slot/lock.js +7 -3
- package/src/common-auth-embedded/quota/format.d.ts +14 -3
- package/src/common-auth-embedded/quota/format.js +135 -18
- package/src/common-auth-embedded/quota/index.d.ts +1 -1
- package/src/common-auth-embedded/quota/index.js +1 -1
- package/src/common-auth-embedded/setup/command-error.d.ts +32 -0
- package/src/common-auth-embedded/setup/command-error.js +79 -0
- package/src/common-auth-embedded/setup/command-runner.js +118 -24
- package/src/common-auth-embedded/setup/command.js +75 -19
- package/src/common-auth-embedded/setup/enroll.js +17 -5
- package/src/common-auth-embedded/setup/index.d.ts +2 -1
- package/src/common-auth-embedded/setup/index.js +1 -0
- package/src/common-auth-embedded/setup/register.js +8 -2
- package/src/common-auth-embedded/setup/types.d.ts +14 -0
- package/src/common-auth-embedded/source-output.json +92 -76
- package/src/common-auth-embedded/store/pool.d.ts +1 -1
- package/src/common-auth-embedded/store/pool.js +0 -1
- package/src/common-auth-embedded/store/refresh-lock.d.ts +0 -1
- package/src/common-auth-embedded/store/refresh-lock.js +0 -1
- package/src/tui-compiled/common-auth-embedded/quota/format.js +135 -18
- package/src/tui-compiled/common-auth-embedded/quota/index.js +1 -1
- package/src/tui-compiled/tui/quota-layout.js +378 -0
- package/src/tui-compiled/tui/route-layout.js +30 -0
- package/src/tui-compiled/tui.js +145 -427
- package/src/tui-ga-compiled/host-ga.js +82 -52
- package/src/tui-ga-compiled/shared/6ca47cd4ec33fe72-route-layout.js +30 -0
- package/src/tui-ga-compiled/shared/8ae1927e5910ea81-sidebar-projection.js +2 -2
- package/src/tui-ga-compiled/shared/aef2402f8fc342f0-format.js +135 -18
- package/src/tui-ga-compiled/shared/bf17cbee28e58197-index.js +1 -1
- package/src/tui-ga-compiled/shared/dd4c9e1a907f8ef0-quota-layout.js +378 -0
- package/src/tui-ga-raw/host-ga.tsx +71 -30
- package/src/tui-ga-raw/shared/6ca47cd4ec33fe72-route-layout.js +30 -0
- package/src/tui-ga-raw/shared/8ae1927e5910ea81-sidebar-projection.js +2 -2
- package/src/tui-ga-raw/shared/aef2402f8fc342f0-format.js +135 -18
- package/src/tui-ga-raw/shared/bf17cbee28e58197-index.js +1 -1
- package/src/tui-ga-raw/shared/dd4c9e1a907f8ef0-quota-layout.tsx +391 -0
- package/src/tui-raw/common-auth-embedded/quota/format.js +135 -18
- package/src/tui-raw/common-auth-embedded/quota/index.js +1 -1
- package/src/tui-raw/tui/quota-layout.tsx +391 -0
- package/src/tui-raw/tui/route-layout.js +30 -0
- package/src/tui-raw/tui.tsx +50 -309
- package/src/tui.tsx +50 -309
package/dist/index.js
CHANGED
|
@@ -293,8 +293,11 @@ function quotaWindowName(limit) {
|
|
|
293
293
|
function clampPercent(remaining) {
|
|
294
294
|
return Math.min(100, Math.max(0, remaining));
|
|
295
295
|
}
|
|
296
|
+
function wholePercent(remaining) {
|
|
297
|
+
return Math.round(clampPercent(remaining));
|
|
298
|
+
}
|
|
296
299
|
function percentLeft(remaining) {
|
|
297
|
-
return `${
|
|
300
|
+
return `${wholePercent(remaining)}% left`;
|
|
298
301
|
}
|
|
299
302
|
function resetDetails(resetsAt, checkedAt, now) {
|
|
300
303
|
const at = resetsAt === void 0 ? Number.NaN : Date.parse(resetsAt);
|
|
@@ -320,6 +323,11 @@ function displayOrder(left, right) {
|
|
|
320
323
|
return left.label < right.label ? -1 : left.label > right.label ? 1 : 0;
|
|
321
324
|
}
|
|
322
325
|
function quotaWindowParts(quota, options) {
|
|
326
|
+
const { windows, age } = scopedWindowParts(quota, options);
|
|
327
|
+
const parts = windows.map(({ part }) => part);
|
|
328
|
+
return age === void 0 ? { windows: parts } : { windows: parts, age };
|
|
329
|
+
}
|
|
330
|
+
function scopedWindowParts(quota, options) {
|
|
323
331
|
if (!quota)
|
|
324
332
|
return { windows: [] };
|
|
325
333
|
const { now } = options;
|
|
@@ -327,12 +335,15 @@ function quotaWindowParts(quota, options) {
|
|
|
327
335
|
const windows = readings.map((limit) => {
|
|
328
336
|
const remainingPercent = clampPercent(limit.remainingPercent ?? 0);
|
|
329
337
|
return {
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
338
|
+
scope: limit.scope,
|
|
339
|
+
part: {
|
|
340
|
+
kind: "window",
|
|
341
|
+
name: quotaWindowName(limit),
|
|
342
|
+
figure: percentLeft(limit.remainingPercent ?? 0),
|
|
343
|
+
remainingPercent,
|
|
344
|
+
checkedAt: limit.checkedAt,
|
|
345
|
+
...resetDetails(limit.resetsAt, limit.checkedAt, now)
|
|
346
|
+
}
|
|
336
347
|
};
|
|
337
348
|
});
|
|
338
349
|
const budget = quota.budget;
|
|
@@ -340,23 +351,85 @@ function quotaWindowParts(quota, options) {
|
|
|
340
351
|
const remainingPercent = budget.remainingPercent;
|
|
341
352
|
const figure = budget.reached ? "credits spent" : remainingPercent !== void 0 ? `credits ${percentLeft(remainingPercent)}` : "credits available";
|
|
342
353
|
windows.push({
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
354
|
+
scope: ALL_SCOPE,
|
|
355
|
+
spent: budget.reached,
|
|
356
|
+
part: {
|
|
357
|
+
kind: "budget",
|
|
358
|
+
name: "credits",
|
|
359
|
+
figure,
|
|
360
|
+
...remainingPercent === void 0 ? {} : { remainingPercent: clampPercent(remainingPercent) },
|
|
361
|
+
checkedAt: budget.checkedAt,
|
|
362
|
+
...resetDetails(budget.resetsAt, budget.checkedAt, now)
|
|
363
|
+
}
|
|
349
364
|
});
|
|
350
365
|
}
|
|
351
366
|
if (windows.length > 0) {
|
|
352
|
-
const age = now - Math.min(...windows.map((part) => part.checkedAt));
|
|
367
|
+
const age = now - Math.min(...windows.map(({ part }) => part.checkedAt));
|
|
353
368
|
if (age > (options.staleAfterMs ?? QUOTA_STALE_AFTER_MS)) {
|
|
354
369
|
return { windows, age: `checked ${shortSpan(age)} ago` };
|
|
355
370
|
}
|
|
356
371
|
}
|
|
357
372
|
return { windows };
|
|
358
373
|
}
|
|
374
|
+
function isQuotaStale(quota, options) {
|
|
375
|
+
return scopedWindowParts(quota, options).age !== void 0;
|
|
376
|
+
}
|
|
377
|
+
function scopeDisplayName(scope) {
|
|
378
|
+
const model = scope.slice(scope.indexOf(":") + 1);
|
|
379
|
+
return model.charAt(0).toUpperCase() + model.slice(1);
|
|
380
|
+
}
|
|
381
|
+
function scopeAbbreviations(scopes) {
|
|
382
|
+
const names = [...new Set(scopes.map(scopeDisplayName))];
|
|
383
|
+
const lengths = new Map(names.map((name) => [name, 2]));
|
|
384
|
+
const short = (name) => name.slice(0, lengths.get(name));
|
|
385
|
+
for (; ; ) {
|
|
386
|
+
const byShort = /* @__PURE__ */ new Map();
|
|
387
|
+
for (const name of names) {
|
|
388
|
+
byShort.set(short(name), [...byShort.get(short(name)) ?? [], name]);
|
|
389
|
+
}
|
|
390
|
+
let extended = false;
|
|
391
|
+
for (const group of byShort.values()) {
|
|
392
|
+
if (group.length < 2)
|
|
393
|
+
continue;
|
|
394
|
+
for (const name of group) {
|
|
395
|
+
const length = lengths.get(name) ?? 2;
|
|
396
|
+
if (length < name.length) {
|
|
397
|
+
lengths.set(name, length + 1);
|
|
398
|
+
extended = true;
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
if (!extended)
|
|
403
|
+
break;
|
|
404
|
+
}
|
|
405
|
+
return new Map(scopes.map((scope) => [scope, short(scopeDisplayName(scope))]));
|
|
406
|
+
}
|
|
407
|
+
function narrowTextParts(quota, options) {
|
|
408
|
+
const { windows } = scopedWindowParts(quota, options);
|
|
409
|
+
const general = windows.filter(({ part, scope }) => part.kind === "window" && scope === ALL_SCOPE);
|
|
410
|
+
const scoped = windows.filter(({ part, scope }) => part.kind === "window" && scope !== ALL_SCOPE);
|
|
411
|
+
const abbreviations = scopeAbbreviations(scoped.map(({ scope }) => scope));
|
|
412
|
+
const budget = windows.find(({ part }) => part.kind === "budget");
|
|
413
|
+
const budgetLeft = budget?.spent ? 0 : budget?.part.remainingPercent;
|
|
414
|
+
const extras = [
|
|
415
|
+
...scoped.map(({ scope, part }) => ({
|
|
416
|
+
label: abbreviations.get(scope) ?? scope,
|
|
417
|
+
remaining: part.remainingPercent ?? 0
|
|
418
|
+
})),
|
|
419
|
+
...budgetLeft === void 0 ? [] : [{ label: "cr", remaining: budgetLeft }]
|
|
420
|
+
];
|
|
421
|
+
const tightest = extras.reduce((best, item) => best === void 0 || item.remaining < best.remaining ? item : best, void 0);
|
|
422
|
+
const pieces = general.map(({ part }) => `${part.name} ${wholePercent(part.remainingPercent ?? 0)}%`);
|
|
423
|
+
if (tightest) {
|
|
424
|
+
pieces.push(`${tightest.label} ${wholePercent(tightest.remaining)}%`);
|
|
425
|
+
}
|
|
426
|
+
if (pieces.length === 0)
|
|
427
|
+
return windows.map(({ part }) => part.figure);
|
|
428
|
+
return pieces.map((piece, index) => index === pieces.length - 1 ? `${piece} left` : piece);
|
|
429
|
+
}
|
|
359
430
|
function quotaTextParts(quota, options) {
|
|
431
|
+
if (options.form === "narrow")
|
|
432
|
+
return narrowTextParts(quota, options);
|
|
360
433
|
const parts = quotaWindowParts(quota, options);
|
|
361
434
|
const full = (options.form ?? "full") === "full";
|
|
362
435
|
const text2 = parts.windows.map((part) => {
|
|
@@ -501,6 +574,7 @@ __export(quota_exports, {
|
|
|
501
574
|
futureResetAt: () => futureResetAt,
|
|
502
575
|
isQuotaMap: () => isQuotaMap,
|
|
503
576
|
isQuotaObservation: () => isQuotaObservation,
|
|
577
|
+
isQuotaStale: () => isQuotaStale,
|
|
504
578
|
mergeQuotaObservation: () => mergeQuotaObservation,
|
|
505
579
|
projectQuota: () => projectQuota,
|
|
506
580
|
quotaCodec: () => quotaCodec2,
|
|
@@ -985,7 +1059,10 @@ function isLostMarkerRaceError(error) {
|
|
|
985
1059
|
const code2 = error?.code;
|
|
986
1060
|
return code2 === "ENOENT" || !windowsPrivateFiles && (code2 === "EINVAL" || code2 === "ENOTDIR");
|
|
987
1061
|
}
|
|
988
|
-
|
|
1062
|
+
function acquireRefreshFileLock(options) {
|
|
1063
|
+
return acquireRefreshFileLockWithClock({ ...options, now: Date.now });
|
|
1064
|
+
}
|
|
1065
|
+
async function acquireRefreshFileLockWithClock(options) {
|
|
989
1066
|
const lockPath = lockPathFor(options.path, options.name);
|
|
990
1067
|
const legacyOwnerPath = join4(lockPath, "owner.json");
|
|
991
1068
|
const ownerId = randomUUID9();
|
|
@@ -1707,7 +1784,6 @@ async function acquirePoolLock(spec, defaults, env3) {
|
|
|
1707
1784
|
name: spec.name,
|
|
1708
1785
|
path: spec.path,
|
|
1709
1786
|
ttlMs: options.ttlMs,
|
|
1710
|
-
now: env3.now,
|
|
1711
1787
|
renew: options.renew,
|
|
1712
1788
|
onContended: () => emit("contended"),
|
|
1713
1789
|
...env3.onRenewalTimer ? {
|
|
@@ -4823,7 +4899,6 @@ function openPoolStore(options) {
|
|
|
4823
4899
|
],
|
|
4824
4900
|
lockDefaults,
|
|
4825
4901
|
lockEnv: {
|
|
4826
|
-
now: options.now ?? Date.now,
|
|
4827
4902
|
...options.onLockEvent ? { onLockEvent: options.onLockEvent } : {},
|
|
4828
4903
|
...options.onLockStep ? { onLockStep: options.onLockStep } : {},
|
|
4829
4904
|
...options.onRenewalTimer ? { onRenewalTimer: options.onRenewalTimer } : {}
|
|
@@ -7111,11 +7186,11 @@ var init_doctor = __esm({
|
|
|
7111
7186
|
|
|
7112
7187
|
// ../core/dist/common-auth-embedded/auth-menu/login.js
|
|
7113
7188
|
import { execFileSync as defaultExecFileSync, spawn as defaultSpawn } from "node:child_process";
|
|
7114
|
-
function openBrowserForMenu(url, platform = process.platform, execFileSync = defaultExecFileSync,
|
|
7189
|
+
function openBrowserForMenu(url, platform = process.platform, execFileSync = defaultExecFileSync, spawn2 = defaultSpawn) {
|
|
7115
7190
|
try {
|
|
7116
7191
|
if (platform === "win32") {
|
|
7117
7192
|
const command = `Start-Process '${url.replaceAll("'", "''")}'`;
|
|
7118
|
-
const child =
|
|
7193
|
+
const child = spawn2("powershell.exe", [
|
|
7119
7194
|
"-NoProfile",
|
|
7120
7195
|
"-NonInteractive",
|
|
7121
7196
|
"-WindowStyle",
|
|
@@ -8895,6 +8970,15 @@ function credentialTypeOf(row, family) {
|
|
|
8895
8970
|
return row.refreshAdapter === void 0 ? "api_key" : void 0;
|
|
8896
8971
|
return void 0;
|
|
8897
8972
|
}
|
|
8973
|
+
function grantReachOf(listed) {
|
|
8974
|
+
const { grants, grantTuples } = listed;
|
|
8975
|
+
if (grants === void 0 || grantTuples === void 0)
|
|
8976
|
+
return void 0;
|
|
8977
|
+
return Object.freeze({
|
|
8978
|
+
grants,
|
|
8979
|
+
tuples: Object.freeze(grantTuples.map(({ selectorKind, selector, operation }) => Object.freeze({ selectorKind, selector, operation })))
|
|
8980
|
+
});
|
|
8981
|
+
}
|
|
8898
8982
|
var defaultLogger, SERVING_MARGIN_MS, ClaustrumScopedCustody;
|
|
8899
8983
|
var init_custody = __esm({
|
|
8900
8984
|
"../core/dist/common-auth-embedded/claustrum/custody.js"() {
|
|
@@ -9020,10 +9104,12 @@ var init_custody = __esm({
|
|
|
9020
9104
|
}
|
|
9021
9105
|
for (const record3 of skipped)
|
|
9022
9106
|
this.#logger.warn("skipped malformed vault record", record3);
|
|
9107
|
+
const grantReach = grantReachOf(inventory);
|
|
9023
9108
|
return {
|
|
9024
9109
|
view: inventory.view,
|
|
9025
9110
|
credentials: Object.freeze(credentials),
|
|
9026
|
-
skipped: Object.freeze(skipped)
|
|
9111
|
+
skipped: Object.freeze(skipped),
|
|
9112
|
+
...grantReach && { grantReach }
|
|
9027
9113
|
};
|
|
9028
9114
|
}
|
|
9029
9115
|
/**
|
|
@@ -9589,6 +9675,11 @@ var init_consumer = __esm({
|
|
|
9589
9675
|
#connecting;
|
|
9590
9676
|
#refreshing;
|
|
9591
9677
|
#roster;
|
|
9678
|
+
/**
|
|
9679
|
+
* The grants named by this instance's latest discovery, with the view that
|
|
9680
|
+
* discovery committed. Memory only: the roster file never carries it.
|
|
9681
|
+
*/
|
|
9682
|
+
#grantReach;
|
|
9592
9683
|
#timer;
|
|
9593
9684
|
#started = false;
|
|
9594
9685
|
#insula;
|
|
@@ -9665,6 +9756,19 @@ var init_consumer = __esm({
|
|
|
9665
9756
|
snapshot() {
|
|
9666
9757
|
return this.#roster;
|
|
9667
9758
|
}
|
|
9759
|
+
/**
|
|
9760
|
+
* What this consumer is granted, from its latest discovery, without any I/O.
|
|
9761
|
+
* It explains an empty roster: `grants === 0` means no grant at all, while
|
|
9762
|
+
* `grants > 0` means a grant that reaches no credential (`tuples` names its
|
|
9763
|
+
* selector). Undefined means unknown, never zero: the vault or client is too
|
|
9764
|
+
* old to send it, nothing was discovered yet, or the roster now in memory is
|
|
9765
|
+
* a different view than the one this instance discovered (a peer process
|
|
9766
|
+
* held the discovery lease and its newer roster was served instead).
|
|
9767
|
+
*/
|
|
9768
|
+
grantReach() {
|
|
9769
|
+
const latest2 = this.#grantReach;
|
|
9770
|
+
return latest2 && this.#roster?.view === latest2.view ? latest2.reach : void 0;
|
|
9771
|
+
}
|
|
9668
9772
|
/** Rows for `/routing`, from the last committed roster. */
|
|
9669
9773
|
routingRows() {
|
|
9670
9774
|
return vaultRoutingRows(this.#roster);
|
|
@@ -9676,6 +9780,7 @@ var init_consumer = __esm({
|
|
|
9676
9780
|
this.#refreshing = (async () => {
|
|
9677
9781
|
if (!await this.#active()) {
|
|
9678
9782
|
this.#roster = void 0;
|
|
9783
|
+
this.#grantReach = void 0;
|
|
9679
9784
|
this.#custody?.close();
|
|
9680
9785
|
this.#custody = void 0;
|
|
9681
9786
|
this.#insula?.release();
|
|
@@ -9683,9 +9788,15 @@ var init_consumer = __esm({
|
|
|
9683
9788
|
return void 0;
|
|
9684
9789
|
}
|
|
9685
9790
|
const custody = await this.#getCustody();
|
|
9791
|
+
let discovered;
|
|
9686
9792
|
const roster = await refreshVaultRoster({
|
|
9687
9793
|
path: this.#options.rosterPath,
|
|
9688
|
-
custody
|
|
9794
|
+
custody: {
|
|
9795
|
+
discover: async (signal) => {
|
|
9796
|
+
discovered = await custody.discover(signal);
|
|
9797
|
+
return discovered;
|
|
9798
|
+
}
|
|
9799
|
+
},
|
|
9689
9800
|
isActive: () => this.#active(),
|
|
9690
9801
|
signal: this.#shutdown.signal,
|
|
9691
9802
|
projection: () => ({
|
|
@@ -9698,6 +9809,8 @@ var init_consumer = __esm({
|
|
|
9698
9809
|
this.#assertOpen();
|
|
9699
9810
|
const changed = roster?.view !== this.#roster?.view;
|
|
9700
9811
|
this.#roster = roster;
|
|
9812
|
+
if (discovered && roster?.view !== void 0)
|
|
9813
|
+
this.#grantReach = discovered.grantReach ? { view: roster.view, reach: discovered.grantReach } : void 0;
|
|
9701
9814
|
if (roster && changed)
|
|
9702
9815
|
this.#options.onRoster?.(roster);
|
|
9703
9816
|
return roster;
|
|
@@ -9925,6 +10038,7 @@ var init_consumer = __esm({
|
|
|
9925
10038
|
this.#insula?.release();
|
|
9926
10039
|
this.#insula = void 0;
|
|
9927
10040
|
this.#roster = void 0;
|
|
10041
|
+
this.#grantReach = void 0;
|
|
9928
10042
|
}
|
|
9929
10043
|
};
|
|
9930
10044
|
}
|
|
@@ -9998,7 +10112,7 @@ var init_claustrum = __esm({
|
|
|
9998
10112
|
});
|
|
9999
10113
|
|
|
10000
10114
|
// ../core/dist/common-auth-embedded/pi-slot/lock.js
|
|
10001
|
-
import { rmdirSync, statSync as statSync2 } from "node:fs";
|
|
10115
|
+
import { rmdirSync, statSync as statSync2, utimesSync } from "node:fs";
|
|
10002
10116
|
import { mkdir as mkdir9, rmdir, stat as stat5, utimes } from "node:fs/promises";
|
|
10003
10117
|
function sameDirectory(observed, identity) {
|
|
10004
10118
|
return observed.dev === identity.dev && observed.ino === identity.ino;
|
|
@@ -10094,7 +10208,7 @@ async function acquirePiLock(authPath, onCompromised, onRenew) {
|
|
|
10094
10208
|
return;
|
|
10095
10209
|
let observed;
|
|
10096
10210
|
try {
|
|
10097
|
-
observed =
|
|
10211
|
+
observed = statSync2(path5);
|
|
10098
10212
|
} catch (error) {
|
|
10099
10213
|
retry(error);
|
|
10100
10214
|
return;
|
|
@@ -10108,11 +10222,12 @@ async function acquirePiLock(authPath, onCompromised, onRenew) {
|
|
|
10108
10222
|
}
|
|
10109
10223
|
const next = new Date(precision === "s" ? Math.ceil(Date.now() / 1e3) * 1e3 : Date.now());
|
|
10110
10224
|
try {
|
|
10111
|
-
|
|
10225
|
+
utimesSync(path5, next, next);
|
|
10112
10226
|
} catch (error) {
|
|
10113
10227
|
retry(error);
|
|
10114
10228
|
return;
|
|
10115
10229
|
}
|
|
10230
|
+
assertFresh();
|
|
10116
10231
|
if (released)
|
|
10117
10232
|
return;
|
|
10118
10233
|
mtime = next.getTime();
|
|
@@ -11260,7 +11375,7 @@ function legacyOptional(row, key, predicate, path5) {
|
|
|
11260
11375
|
throw new AccountMigrationError(`${path5}.${key} has an invalid type`);
|
|
11261
11376
|
}
|
|
11262
11377
|
}
|
|
11263
|
-
function parseAccount(value, ordinal, version,
|
|
11378
|
+
function parseAccount(value, ordinal, version, clock2) {
|
|
11264
11379
|
const path5 = `accounts[${ordinal}]`;
|
|
11265
11380
|
const source = object(value, path5);
|
|
11266
11381
|
if (typeof source.refreshToken !== "string" || !source.refreshToken.trim().length) {
|
|
@@ -11287,7 +11402,7 @@ function parseAccount(value, ordinal, version, clock) {
|
|
|
11287
11402
|
const quota = hasQuota ? decodeQuotaState(quotaRaw) : void 0;
|
|
11288
11403
|
const normalized = encodeProviderMetadata(originalMetadata);
|
|
11289
11404
|
if (version === 1) {
|
|
11290
|
-
if (source.isRateLimited && finite(source.rateLimitResetTime) && source.rateLimitResetTime >
|
|
11405
|
+
if (source.isRateLimited && finite(source.rateLimitResetTime) && source.rateLimitResetTime > clock2) {
|
|
11291
11406
|
if (originalMetadata.rateLimitResetTimes === null)
|
|
11292
11407
|
throw new AccountMigrationError(`${path5} has conflicting rate-limit encodings`);
|
|
11293
11408
|
const resets = { ...originalMetadata.rateLimitResetTimes };
|
|
@@ -11304,9 +11419,9 @@ function parseAccount(value, ordinal, version, clock) {
|
|
|
11304
11419
|
const gemini = resets.gemini;
|
|
11305
11420
|
delete resets.claude;
|
|
11306
11421
|
delete resets.gemini;
|
|
11307
|
-
if (claude === null || finite(claude) && claude >
|
|
11422
|
+
if (claude === null || finite(claude) && claude > clock2)
|
|
11308
11423
|
resets.claude = claude;
|
|
11309
|
-
if (gemini === null || finite(gemini) && gemini >
|
|
11424
|
+
if (gemini === null || finite(gemini) && gemini > clock2) {
|
|
11310
11425
|
if (Object.hasOwn(resets, "gemini-antigravity") && resets["gemini-antigravity"] !== gemini)
|
|
11311
11426
|
throw new AccountMigrationError(`${path5} has conflicting rate-limit encodings`);
|
|
11312
11427
|
resets["gemini-antigravity"] = gemini;
|
|
@@ -11840,7 +11955,7 @@ async function syncDirectory(path5, boundary) {
|
|
|
11840
11955
|
}
|
|
11841
11956
|
await boundary?.("after-directory-sync");
|
|
11842
11957
|
}
|
|
11843
|
-
async function exclusiveBytes(path5, bytes, expectedHash, boundary) {
|
|
11958
|
+
async function exclusiveBytes(path5, bytes, expectedHash, boundary, pointerStage = false) {
|
|
11844
11959
|
let handle;
|
|
11845
11960
|
try {
|
|
11846
11961
|
handle = await open(path5, "wx", 384);
|
|
@@ -11859,7 +11974,8 @@ async function exclusiveBytes(path5, bytes, expectedHash, boundary) {
|
|
|
11859
11974
|
const reopened = await secureRead(path5);
|
|
11860
11975
|
if (digest(reopened) !== expectedHash || !reopened.equals(bytes))
|
|
11861
11976
|
throw new AccountMigrationError("exclusive backup or recovery copy differs");
|
|
11862
|
-
|
|
11977
|
+
if (handle === void 0 || !pointerStage)
|
|
11978
|
+
await syncFile(path5);
|
|
11863
11979
|
await syncDirectory(dirname(path5), boundary);
|
|
11864
11980
|
}
|
|
11865
11981
|
async function readJournal(paths) {
|
|
@@ -12561,7 +12677,7 @@ function createAccountMigrationFactory(modules) {
|
|
|
12561
12677
|
throw new AccountMigrationError("source changed before pointer publication");
|
|
12562
12678
|
if (!journal)
|
|
12563
12679
|
throw new AccountMigrationError("capture journal missing");
|
|
12564
|
-
await publishGenerationPointer(modules, physical, journal, parentLease, prior, options.onBoundary);
|
|
12680
|
+
await publishGenerationPointer(modules, physical, journal, parentLease, lease, prior, options.onBoundary);
|
|
12565
12681
|
});
|
|
12566
12682
|
await options.onBoundary?.("after-capture");
|
|
12567
12683
|
}
|
|
@@ -12906,47 +13022,9 @@ async function initializeFreshAccountStore(modules, options) {
|
|
|
12906
13022
|
timeoutMs: 2e3,
|
|
12907
13023
|
renew: true
|
|
12908
13024
|
}, async (lease) => {
|
|
12909
|
-
|
|
12910
|
-
if (pointer === void 0)
|
|
12911
|
-
|
|
12912
|
-
await assertSourceAbsent(physical);
|
|
12913
|
-
await modules.fs.withLock(physical.legacyPath, {
|
|
12914
|
-
name: "accounts",
|
|
12915
|
-
ttlMs: 1e4,
|
|
12916
|
-
timeoutMs: 2e3,
|
|
12917
|
-
renew: true
|
|
12918
|
-
}, async (accountsLease) => {
|
|
12919
|
-
await assertSourceAbsent(physical);
|
|
12920
|
-
await accountsLease.assertOwned();
|
|
12921
|
-
await lease.assertOwned();
|
|
12922
|
-
if (journal !== void 0 || await exists(physical.configPath) || await exists(physical.statePath))
|
|
12923
|
-
throw new AccountMigrationError("fresh stage has unrelated artifacts");
|
|
12924
|
-
journal = {
|
|
12925
|
-
schemaVersion: 1,
|
|
12926
|
-
id: pathGenerationId(physical),
|
|
12927
|
-
legacyPath: physical.legacyPath,
|
|
12928
|
-
storeDir: physical.storeDir,
|
|
12929
|
-
sourceKind: "absent",
|
|
12930
|
-
status: "pending",
|
|
12931
|
-
operation: "migrate",
|
|
12932
|
-
phase: "capture",
|
|
12933
|
-
manifest: {
|
|
12934
|
-
sourceVersion: null,
|
|
12935
|
-
normalizationClock: options.now(),
|
|
12936
|
-
accounts: [],
|
|
12937
|
-
routing: { schemaVersion: 1 },
|
|
12938
|
-
effectiveActiveIndex: 0
|
|
12939
|
-
},
|
|
12940
|
-
mapping: [],
|
|
12941
|
-
completedRows: []
|
|
12942
|
-
};
|
|
12943
|
-
await saveJournal(modules, physical, lease, journal, true, options.onBoundary);
|
|
12944
|
-
await options.onBoundary?.("pointer:before-publication");
|
|
12945
|
-
await assertSourceAbsent(physical);
|
|
12946
|
-
await publishGenerationPointer(modules, physical, journal, parentLease, void 0, options.onBoundary);
|
|
12947
|
-
await options.onBoundary?.("pointer:after-publication");
|
|
12948
|
-
});
|
|
12949
|
-
}
|
|
13025
|
+
const journal = await readJournal(physical);
|
|
13026
|
+
if (pointer === void 0)
|
|
13027
|
+
return initializePrivateEmptyGeneration(modules, physical, parentLease, lease, options);
|
|
12950
13028
|
if (journal?.sourceKind !== "absent" || journal.operation !== "migrate" || journal.status === "inactive")
|
|
12951
13029
|
throw new AccountMigrationError("fresh resume has no compatible pointed generation");
|
|
12952
13030
|
await assertPublishedAccountStoreGeneration(physical);
|
|
@@ -13022,6 +13100,187 @@ async function initializeFreshAccountStore(modules, options) {
|
|
|
13022
13100
|
throw error;
|
|
13023
13101
|
}
|
|
13024
13102
|
}
|
|
13103
|
+
async function exclusiveUnpublishedBytes(path5, bytes) {
|
|
13104
|
+
const handle = await open(path5, constants.O_WRONLY | constants.O_CREAT | constants.O_EXCL | constants.O_NOFOLLOW, 384);
|
|
13105
|
+
try {
|
|
13106
|
+
await handle.writeFile(bytes);
|
|
13107
|
+
} finally {
|
|
13108
|
+
await handle.close();
|
|
13109
|
+
}
|
|
13110
|
+
if (!(await secureRead(path5)).equals(bytes))
|
|
13111
|
+
throw new AccountMigrationError("private stage readback differs");
|
|
13112
|
+
}
|
|
13113
|
+
async function initializePrivateEmptyGeneration(modules, paths, parentLease, managementLease, options) {
|
|
13114
|
+
return modules.fs.withLock(paths.legacyPath, { name: "accounts", ttlMs: 1e4, timeoutMs: 2e3, renew: true }, async (accountsLease) => {
|
|
13115
|
+
const directory = await lstat(paths.storeDir);
|
|
13116
|
+
const assertOwned = async () => {
|
|
13117
|
+
await parentLease.assertOwned();
|
|
13118
|
+
await managementLease.assertOwned();
|
|
13119
|
+
await accountsLease.assertOwned();
|
|
13120
|
+
const current = await lstat(paths.storeDir);
|
|
13121
|
+
if (!current.isDirectory() || current.isSymbolicLink() || current.dev !== directory.dev || current.ino !== directory.ino || !sameFilesystemPath(await realpath(paths.storeDir), paths.storeDir))
|
|
13122
|
+
throw new AccountMigrationError("private generation directory changed");
|
|
13123
|
+
privateMode(current.mode, 448);
|
|
13124
|
+
};
|
|
13125
|
+
const boundary = options.onBoundary;
|
|
13126
|
+
await assertOwned();
|
|
13127
|
+
await assertSourceAbsent(paths);
|
|
13128
|
+
if (await readPointer(paths.legacyPath))
|
|
13129
|
+
throw new AccountMigrationError("private initialization found a competing pointer");
|
|
13130
|
+
if (await readJournal(paths) || await exists(paths.configPath) || await exists(paths.statePath))
|
|
13131
|
+
throw new AccountMigrationError("fresh stage has unrelated artifacts");
|
|
13132
|
+
const journal = {
|
|
13133
|
+
schemaVersion: 1,
|
|
13134
|
+
id: pathGenerationId(paths),
|
|
13135
|
+
legacyPath: paths.legacyPath,
|
|
13136
|
+
storeDir: paths.storeDir,
|
|
13137
|
+
sourceKind: "absent",
|
|
13138
|
+
status: "pending",
|
|
13139
|
+
operation: "migrate",
|
|
13140
|
+
phase: "build",
|
|
13141
|
+
manifest: {
|
|
13142
|
+
sourceVersion: null,
|
|
13143
|
+
normalizationClock: options.now(),
|
|
13144
|
+
accounts: [],
|
|
13145
|
+
routing: { schemaVersion: 1 },
|
|
13146
|
+
effectiveActiveIndex: 0
|
|
13147
|
+
},
|
|
13148
|
+
mapping: [],
|
|
13149
|
+
completedRows: []
|
|
13150
|
+
};
|
|
13151
|
+
await assertOwned();
|
|
13152
|
+
await exclusiveUnpublishedBytes(paths.configPath, Buffer.from('{"version":1,"accounts":[]}\n'));
|
|
13153
|
+
await boundary?.("empty-stage:after-seed");
|
|
13154
|
+
const store = openMigrationStore(modules, paths, options.now, async (step, info) => {
|
|
13155
|
+
await assertOwned();
|
|
13156
|
+
if (!step.includes("config") || await exists(paths.statePath))
|
|
13157
|
+
throw new AccountMigrationError("private empty stage attempted a credential write");
|
|
13158
|
+
await secureRead(paths.configPath);
|
|
13159
|
+
await boundary?.(`public:${info.operation}:${step}`);
|
|
13160
|
+
await assertOwned();
|
|
13161
|
+
});
|
|
13162
|
+
await assertOwned();
|
|
13163
|
+
await store.initialize();
|
|
13164
|
+
await boundary?.("empty-stage:after-initialize");
|
|
13165
|
+
await assertOwned();
|
|
13166
|
+
await store.updateSettings((settings) => {
|
|
13167
|
+
settings[ROUTING_SETTINGS_KEY] = encodeRoutingSettings(journal.manifest.routing);
|
|
13168
|
+
settings[ACCOUNT_STORE_GENERATION_SETTINGS_KEY] = generationJson(journal);
|
|
13169
|
+
settings[MANAGEMENT_SETTINGS_KEY] = {
|
|
13170
|
+
id: journal.id,
|
|
13171
|
+
kind: "migration",
|
|
13172
|
+
targets: [],
|
|
13173
|
+
progress: { step: "build", completedTargets: [] }
|
|
13174
|
+
};
|
|
13175
|
+
return settings;
|
|
13176
|
+
});
|
|
13177
|
+
await boundary?.("empty-stage:after-build-settings");
|
|
13178
|
+
await expectedFreshArtifacts(paths, journal);
|
|
13179
|
+
await assertStateOwnership(paths, journal, true);
|
|
13180
|
+
await verifyImported(store, journal);
|
|
13181
|
+
const snapshot2 = await secureRead(paths.configPath);
|
|
13182
|
+
await verifyImported(store, journal);
|
|
13183
|
+
journal.verification = {
|
|
13184
|
+
manifestSha256: digest(canonical2(manifestJson(journal.manifest))),
|
|
13185
|
+
configSha256: digest(snapshot2),
|
|
13186
|
+
statePresent: false,
|
|
13187
|
+
durability: accountMigrationDurability()
|
|
13188
|
+
};
|
|
13189
|
+
await assertOwned();
|
|
13190
|
+
await assertSourceAbsent(paths);
|
|
13191
|
+
journal.sourceAbsenceVerified = true;
|
|
13192
|
+
await management(store, journal, true);
|
|
13193
|
+
await boundary?.("empty-stage:after-clear-settings");
|
|
13194
|
+
await expectedFreshArtifacts(paths, journal);
|
|
13195
|
+
await currentSuccessor(store, paths, journal);
|
|
13196
|
+
if ((await settingsOf(store))[MANAGEMENT_SETTINGS_KEY] !== void 0)
|
|
13197
|
+
throw new AccountMigrationError("private stage still has management work");
|
|
13198
|
+
journal.phase = "activate";
|
|
13199
|
+
journal.status = "active";
|
|
13200
|
+
decodeAccountMigrationJournal(journalJson(journal));
|
|
13201
|
+
await assertOwned();
|
|
13202
|
+
await exclusiveUnpublishedBytes(paths.migrationPath, Buffer.from(`${JSON.stringify(journalJson(journal), null, 2)}
|
|
13203
|
+
`));
|
|
13204
|
+
await boundary?.("empty-stage:after-journal");
|
|
13205
|
+
await syncFile(paths.configPath);
|
|
13206
|
+
await boundary?.("empty-stage:after-config-sync");
|
|
13207
|
+
await syncFile(paths.migrationPath);
|
|
13208
|
+
await boundary?.("empty-stage:after-journal-sync");
|
|
13209
|
+
for (const [name, path6] of [
|
|
13210
|
+
["backups", paths.backupsDir],
|
|
13211
|
+
["retired", paths.retiredDir],
|
|
13212
|
+
["transfers", paths.transfersDir]
|
|
13213
|
+
]) {
|
|
13214
|
+
await syncDirectory(path6);
|
|
13215
|
+
await boundary?.(`empty-stage:after-${name}-sync`);
|
|
13216
|
+
}
|
|
13217
|
+
await syncDirectory(paths.storeDir);
|
|
13218
|
+
await boundary?.("empty-stage:after-generation-sync");
|
|
13219
|
+
await boundary?.("pointer:before-publication");
|
|
13220
|
+
const reopened = await readJournal(paths);
|
|
13221
|
+
if (!isDeepStrictEqual(reopened, journal))
|
|
13222
|
+
throw new AccountMigrationError("publication requires its complete synced canonical journal");
|
|
13223
|
+
const pointer = {
|
|
13224
|
+
schemaVersion: 1,
|
|
13225
|
+
id: journal.id,
|
|
13226
|
+
directoryBasename: basename(paths.storeDir)
|
|
13227
|
+
};
|
|
13228
|
+
const path5 = accountStorePointerPath(paths.legacyPath);
|
|
13229
|
+
const stage = `${path5}.${journal.id}.tmp`;
|
|
13230
|
+
const bytes = Buffer.from(`${JSON.stringify(pointer, null, 2)}
|
|
13231
|
+
`);
|
|
13232
|
+
await assertOwned();
|
|
13233
|
+
let stageHandle;
|
|
13234
|
+
try {
|
|
13235
|
+
stageHandle = await open(stage, "wx", 384);
|
|
13236
|
+
} catch (error) {
|
|
13237
|
+
if (errno(error) !== "EEXIST")
|
|
13238
|
+
throw error;
|
|
13239
|
+
}
|
|
13240
|
+
if (stageHandle) {
|
|
13241
|
+
try {
|
|
13242
|
+
await stageHandle.writeFile(bytes);
|
|
13243
|
+
await stageHandle.sync();
|
|
13244
|
+
} finally {
|
|
13245
|
+
await stageHandle.close();
|
|
13246
|
+
}
|
|
13247
|
+
}
|
|
13248
|
+
if (!(await secureRead(stage)).equals(bytes))
|
|
13249
|
+
throw new AccountMigrationError("exclusive pointer stage differs");
|
|
13250
|
+
if (!stageHandle)
|
|
13251
|
+
await syncFile(stage);
|
|
13252
|
+
await boundary?.("empty-stage:after-pointer-stage");
|
|
13253
|
+
await syncDirectory(dirname(path5));
|
|
13254
|
+
await boundary?.("empty-stage:after-parent-prelink-sync");
|
|
13255
|
+
await boundary?.("pointer:before-link");
|
|
13256
|
+
await assertOwned();
|
|
13257
|
+
await assertSourceAbsent(paths);
|
|
13258
|
+
if (await exists(path5))
|
|
13259
|
+
throw new AccountMigrationError("foreign or competing pointer publication refuses overwrite");
|
|
13260
|
+
if (await exists(resolveAccountStorePaths(paths.legacyPath).storeDir))
|
|
13261
|
+
throw new AccountMigrationError("foreign logical store directory appeared before publication");
|
|
13262
|
+
try {
|
|
13263
|
+
await link(stage, path5);
|
|
13264
|
+
} catch (error) {
|
|
13265
|
+
if (errno(error) === "EEXIST")
|
|
13266
|
+
throw new AccountMigrationError("foreign or competing pointer publication refuses overwrite");
|
|
13267
|
+
throw new AccountMigrationError("exclusive pointer hard-link publication failed");
|
|
13268
|
+
}
|
|
13269
|
+
await boundary?.("pointer:after-link-before-parent-sync");
|
|
13270
|
+
await syncDirectory(dirname(path5));
|
|
13271
|
+
if (!isDeepStrictEqual(await readPointer(paths.legacyPath), pointer) || !isDeepStrictEqual(await readJournal(paths), journal))
|
|
13272
|
+
throw new AccountMigrationError("pointer publication readback differs");
|
|
13273
|
+
await expectedFreshArtifacts(paths, journal);
|
|
13274
|
+
await currentSuccessor(store, paths, journal);
|
|
13275
|
+
const admission = await readAccountStoreAdmission(paths.legacyPath, modules, options.now, journal.id);
|
|
13276
|
+
if (admission.status !== "active" || !isDeepStrictEqual(admission.receipt, receipt(journal)))
|
|
13277
|
+
throw new AccountMigrationError("published empty generation is not admitted");
|
|
13278
|
+
await boundary?.("pointer:after-sync-before-stage-cleanup");
|
|
13279
|
+
await cleanupPointerStage(paths.legacyPath, pointer, parentLease);
|
|
13280
|
+
await assertOwned();
|
|
13281
|
+
return { status: "completed", receipt: receipt(journal) };
|
|
13282
|
+
});
|
|
13283
|
+
}
|
|
13025
13284
|
async function allocateGeneration(legacyPath) {
|
|
13026
13285
|
if (await exists(resolveAccountStorePaths(legacyPath).storeDir))
|
|
13027
13286
|
throw new AccountMigrationError("foreign logical directory refuses generation allocation");
|
|
@@ -13030,13 +13289,16 @@ async function allocateGeneration(legacyPath) {
|
|
|
13030
13289
|
await prepareDirectories(paths);
|
|
13031
13290
|
return paths;
|
|
13032
13291
|
}
|
|
13033
|
-
async function publishGenerationPointer(modules, paths, journal, parentLease, prior, boundary) {
|
|
13292
|
+
async function publishGenerationPointer(modules, paths, journal, parentLease, managementLease, prior, boundary, journalSavedBy) {
|
|
13034
13293
|
await parentLease.assertOwned();
|
|
13294
|
+
await managementLease.assertOwned();
|
|
13035
13295
|
const currentJournal = await readJournal(paths);
|
|
13036
13296
|
if (!currentJournal || currentJournal.id !== journal.id || !isDeepStrictEqual(journalJson(currentJournal), journalJson(journal)))
|
|
13037
13297
|
throw new AccountMigrationError("publication requires its complete synced canonical journal");
|
|
13038
|
-
|
|
13039
|
-
|
|
13298
|
+
if (journalSavedBy !== managementLease) {
|
|
13299
|
+
await syncFile(paths.migrationPath);
|
|
13300
|
+
await syncDirectory(paths.storeDir);
|
|
13301
|
+
}
|
|
13040
13302
|
const pointer = {
|
|
13041
13303
|
schemaVersion: 1,
|
|
13042
13304
|
id: journal.id,
|
|
@@ -13047,8 +13309,9 @@ async function publishGenerationPointer(modules, paths, journal, parentLease, pr
|
|
|
13047
13309
|
const stage = `${path5}.${journal.id}.tmp`;
|
|
13048
13310
|
const bytes = Buffer.from(`${JSON.stringify(pointer, null, 2)}
|
|
13049
13311
|
`);
|
|
13050
|
-
await exclusiveBytes(stage, bytes, digest(bytes));
|
|
13312
|
+
await exclusiveBytes(stage, bytes, digest(bytes), void 0, true);
|
|
13051
13313
|
await parentLease.assertOwned();
|
|
13314
|
+
await managementLease.assertOwned();
|
|
13052
13315
|
await boundary?.("pointer:before-link");
|
|
13053
13316
|
if (await exists(resolveAccountStorePaths(paths.legacyPath).storeDir))
|
|
13054
13317
|
throw new AccountMigrationError("foreign logical store directory appeared before publication");
|
|
@@ -13080,6 +13343,7 @@ async function publishGenerationPointer(modules, paths, journal, parentLease, pr
|
|
|
13080
13343
|
stageName: () => stageName,
|
|
13081
13344
|
beforeRename: async () => {
|
|
13082
13345
|
await parentLease.assertOwned();
|
|
13346
|
+
await managementLease.assertOwned();
|
|
13083
13347
|
if (!isDeepStrictEqual(await readPointer(paths.legacyPath), prior) || (await readJournal(oldPaths))?.status !== "inactive")
|
|
13084
13348
|
throw new AccountMigrationError("inactive pointer changed before transition");
|
|
13085
13349
|
await syncFile(`${path5}.${stageName}.tmp`);
|
|
@@ -13089,6 +13353,7 @@ async function publishGenerationPointer(modules, paths, journal, parentLease, pr
|
|
|
13089
13353
|
await syncDirectory(dirname(path5));
|
|
13090
13354
|
}
|
|
13091
13355
|
await parentLease.assertOwned();
|
|
13356
|
+
await managementLease.assertOwned();
|
|
13092
13357
|
}
|
|
13093
13358
|
function withParentTopology(modules, legacyPath, body) {
|
|
13094
13359
|
return modules.fs.withLock(legacyPath, {
|
|
@@ -13115,9 +13380,14 @@ async function finishPointerPublication(legacyPath, pointer, lease) {
|
|
|
13115
13380
|
const path5 = accountStorePointerPath(legacyPath);
|
|
13116
13381
|
await syncFile(path5);
|
|
13117
13382
|
await syncDirectory(dirname(path5));
|
|
13383
|
+
if (await cleanupPointerStage(legacyPath, pointer, lease))
|
|
13384
|
+
await syncDirectory(dirname(path5));
|
|
13385
|
+
}
|
|
13386
|
+
async function cleanupPointerStage(legacyPath, pointer, lease) {
|
|
13387
|
+
const path5 = accountStorePointerPath(legacyPath);
|
|
13118
13388
|
const stage = `${path5}.${pointer.id}.tmp`;
|
|
13119
13389
|
if (!await exists(stage))
|
|
13120
|
-
return;
|
|
13390
|
+
return false;
|
|
13121
13391
|
const bytes = await secureRead(stage);
|
|
13122
13392
|
if (!isDeepStrictEqual(decodeAccountStorePointer(jsonBytes(bytes), legacyPath), pointer))
|
|
13123
13393
|
throw new AccountMigrationError("pointer stage differs from publication authority");
|
|
@@ -13126,7 +13396,7 @@ async function finishPointerPublication(legacyPath, pointer, lease) {
|
|
|
13126
13396
|
throw new AccountMigrationError("pointer stage is not the published hard link");
|
|
13127
13397
|
await lease.assertOwned();
|
|
13128
13398
|
await unlink(stage);
|
|
13129
|
-
|
|
13399
|
+
return true;
|
|
13130
13400
|
}
|
|
13131
13401
|
|
|
13132
13402
|
// ../core/dist/account-repository.js
|
|
@@ -15754,8 +16024,8 @@ function isRateLimitedForFamily(account, family, now, model) {
|
|
|
15754
16024
|
clearExpiredRateLimits(account, now);
|
|
15755
16025
|
return model != null && isRateLimitedForQuotaKey(account, getQuotaKey(family, model), now) || isRateLimitedForQuotaKey(account, family, now);
|
|
15756
16026
|
}
|
|
15757
|
-
function clearExpiredRateLimits(account,
|
|
15758
|
-
const now =
|
|
16027
|
+
function clearExpiredRateLimits(account, clock2) {
|
|
16028
|
+
const now = clock2();
|
|
15759
16029
|
const keys = Object.keys(account.rateLimitResetTimes);
|
|
15760
16030
|
for (const key of keys) {
|
|
15761
16031
|
const resetTime = account.rateLimitResetTimes[key];
|
|
@@ -19765,6 +20035,7 @@ async function fetchWithAgyCliTransport(url, init = {}, options = {}) {
|
|
|
19765
20035
|
};
|
|
19766
20036
|
try {
|
|
19767
20037
|
options.signal?.addEventListener("abort", abort, { once: true });
|
|
20038
|
+
options.signal?.throwIfAborted();
|
|
19768
20039
|
socket.write(requestBytes);
|
|
19769
20040
|
options.onDebug?.(`agy transport request dispatched (${requestBytes.byteLength} bytes)`);
|
|
19770
20041
|
const { head, leftover } = await waitForHead(socket, timeoutMs, () => {
|
|
@@ -20676,19 +20947,35 @@ var loadCommonAuthPiSlot = memoize(() => Promise.resolve().then(() => (init_pi_s
|
|
|
20676
20947
|
|
|
20677
20948
|
// ../core/dist/credential-redaction.js
|
|
20678
20949
|
var MARKER = "[credential]";
|
|
20679
|
-
function
|
|
20950
|
+
function maskSensitiveIdentifier(value) {
|
|
20951
|
+
if (typeof value !== "string" || value.length === 0)
|
|
20952
|
+
return "";
|
|
20953
|
+
if (value.length <= 8)
|
|
20954
|
+
return "****";
|
|
20955
|
+
return `${value.slice(0, 4)}****${value.slice(-4)}`;
|
|
20956
|
+
}
|
|
20957
|
+
function redactProjectIdText(text2, projectIds) {
|
|
20958
|
+
const identifiers = [...new Set(projectIds ?? [])].filter((projectId) => projectId.length > 0).sort((left, right) => right.length - left.length);
|
|
20959
|
+
if (identifiers.length > 0) {
|
|
20960
|
+
const expression = new RegExp(identifiers.map((projectId) => projectId.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("|"), "g");
|
|
20961
|
+
text2 = text2.replace(expression, (projectId) => maskSensitiveIdentifier(projectId));
|
|
20962
|
+
}
|
|
20963
|
+
return text2.replace(/(\bproject(?:[\s_-]*id)?\s*[:=]\s*)([a-z0-9_*][a-z0-9_*-]*)/gi, (match, label, value) => /^(?:unknown|n\/?a)$/i.test(value) || value.includes("****") ? match : `${label}${maskSensitiveIdentifier(value)}`);
|
|
20964
|
+
}
|
|
20965
|
+
function redactCredentialText(text2, credentials, projectIds) {
|
|
20966
|
+
text2 = redactProjectIdText(text2, projectIds);
|
|
20680
20967
|
for (const credential of typeof credentials === "string" ? [credentials] : credentials ?? []) {
|
|
20681
20968
|
if (credential)
|
|
20682
20969
|
text2 = text2.split(credential).join(MARKER);
|
|
20683
20970
|
}
|
|
20684
20971
|
return text2.replace(/\beyJ[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\b/g, MARKER).replace(/\bBearer\s+[A-Za-z0-9._~+/-]+=*/gi, MARKER);
|
|
20685
20972
|
}
|
|
20686
|
-
function scrub2(value, credentials, seen = /* @__PURE__ */ new WeakSet()) {
|
|
20973
|
+
function scrub2(value, credentials, projectIds, seen = /* @__PURE__ */ new WeakSet()) {
|
|
20687
20974
|
if (typeof value === "string")
|
|
20688
|
-
return redactCredentialText(value, credentials);
|
|
20975
|
+
return redactCredentialText(value, credentials, projectIds);
|
|
20689
20976
|
if (!value || typeof value !== "object")
|
|
20690
20977
|
return value;
|
|
20691
|
-
if (!containsCredential(value, credentials))
|
|
20978
|
+
if (!containsCredential(value, credentials, projectIds))
|
|
20692
20979
|
return value;
|
|
20693
20980
|
if (seen.has(value))
|
|
20694
20981
|
return "[Circular]";
|
|
@@ -20696,32 +20983,35 @@ function scrub2(value, credentials, seen = /* @__PURE__ */ new WeakSet()) {
|
|
|
20696
20983
|
const safe = Array.isArray(value) ? [] : Object.create(Object.getPrototypeOf(value));
|
|
20697
20984
|
for (const key of Reflect.ownKeys(value)) {
|
|
20698
20985
|
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
20699
|
-
if (key === "cause" && (!("value" in descriptor) || containsCredential(descriptor.value, credentials)))
|
|
20986
|
+
if (key === "cause" && (!("value" in descriptor) || containsCredential(descriptor.value, credentials, projectIds)))
|
|
20700
20987
|
continue;
|
|
20701
|
-
Object.defineProperty(safe, key, "value" in descriptor ? {
|
|
20988
|
+
Object.defineProperty(safe, key, "value" in descriptor ? {
|
|
20989
|
+
...descriptor,
|
|
20990
|
+
value: scrub2(descriptor.value, credentials, projectIds, seen)
|
|
20991
|
+
} : descriptor);
|
|
20702
20992
|
}
|
|
20703
20993
|
return safe;
|
|
20704
20994
|
}
|
|
20705
|
-
function containsCredential(value, credentials, seen = /* @__PURE__ */ new WeakSet()) {
|
|
20995
|
+
function containsCredential(value, credentials, projectIds, seen = /* @__PURE__ */ new WeakSet()) {
|
|
20706
20996
|
if (typeof value === "string")
|
|
20707
|
-
return redactCredentialText(value, credentials) !== value;
|
|
20997
|
+
return redactCredentialText(value, credentials, projectIds) !== value;
|
|
20708
20998
|
if (!value || typeof value !== "object" || seen.has(value))
|
|
20709
20999
|
return false;
|
|
20710
21000
|
seen.add(value);
|
|
20711
21001
|
return Reflect.ownKeys(value).some((key) => {
|
|
20712
21002
|
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
20713
|
-
return "value" in descriptor && containsCredential(descriptor.value, credentials, seen);
|
|
21003
|
+
return "value" in descriptor && containsCredential(descriptor.value, credentials, projectIds, seen);
|
|
20714
21004
|
});
|
|
20715
21005
|
}
|
|
20716
|
-
function redactCredentialError(error, credentials) {
|
|
21006
|
+
function redactCredentialError(error, credentials, projectIds) {
|
|
20717
21007
|
const source = error instanceof Error || error instanceof DOMException ? error : void 0;
|
|
20718
|
-
const message = redactCredentialText(source?.message ?? String(error), credentials);
|
|
21008
|
+
const message = redactCredentialText(source?.message ?? String(error), credentials, projectIds);
|
|
20719
21009
|
const fields = source ? Reflect.ownKeys(source).map((key) => ({
|
|
20720
21010
|
key,
|
|
20721
21011
|
descriptor: Object.getOwnPropertyDescriptor(source, key)
|
|
20722
21012
|
})) : [];
|
|
20723
21013
|
const cause = fields.find(({ key }) => key === "cause")?.descriptor;
|
|
20724
|
-
const secretCause = cause && (!("value" in cause) || containsCredential(cause.value, credentials));
|
|
21014
|
+
const secretCause = cause && (!("value" in cause) || containsCredential(cause.value, credentials, projectIds));
|
|
20725
21015
|
try {
|
|
20726
21016
|
if (source) {
|
|
20727
21017
|
if (message !== source.message)
|
|
@@ -20733,7 +21023,7 @@ function redactCredentialError(error, credentials) {
|
|
|
20733
21023
|
for (const { key, descriptor } of fields) {
|
|
20734
21024
|
if (key === "message" || key === "cause" || !("value" in descriptor))
|
|
20735
21025
|
continue;
|
|
20736
|
-
const value = scrub2(descriptor.value, credentials);
|
|
21026
|
+
const value = scrub2(descriptor.value, credentials, projectIds);
|
|
20737
21027
|
if (value !== descriptor.value)
|
|
20738
21028
|
Object.defineProperty(source, key, { ...descriptor, value });
|
|
20739
21029
|
}
|
|
@@ -20744,7 +21034,7 @@ function redactCredentialError(error, credentials) {
|
|
|
20744
21034
|
} catch {
|
|
20745
21035
|
}
|
|
20746
21036
|
const safe = new Error(message);
|
|
20747
|
-
safe.name = redactCredentialText(source?.name ?? "Error", credentials);
|
|
21037
|
+
safe.name = redactCredentialText(source?.name ?? "Error", credentials, projectIds);
|
|
20748
21038
|
for (const { key, descriptor } of fields) {
|
|
20749
21039
|
if (key === "message" || key === "cause" || !("value" in descriptor))
|
|
20750
21040
|
continue;
|
|
@@ -20752,32 +21042,32 @@ function redactCredentialError(error, credentials) {
|
|
|
20752
21042
|
...descriptor,
|
|
20753
21043
|
configurable: true,
|
|
20754
21044
|
writable: true,
|
|
20755
|
-
value: scrub2(descriptor.value, credentials)
|
|
21045
|
+
value: scrub2(descriptor.value, credentials, projectIds)
|
|
20756
21046
|
});
|
|
20757
21047
|
}
|
|
20758
21048
|
if (cause && !secretCause && "value" in cause)
|
|
20759
21049
|
safe.cause = cause.value;
|
|
20760
21050
|
return safe;
|
|
20761
21051
|
}
|
|
20762
|
-
function redactDiagnosticText(text2, credentials, parsed) {
|
|
20763
|
-
const direct = redactCredentialText(text2, credentials);
|
|
21052
|
+
function redactDiagnosticText(text2, credentials, projectIds, parsed) {
|
|
21053
|
+
const direct = redactCredentialText(text2, credentials, projectIds);
|
|
20764
21054
|
if (direct !== text2 || !text2.includes("\\u"))
|
|
20765
21055
|
return direct;
|
|
20766
21056
|
try {
|
|
20767
21057
|
const canonical4 = JSON.stringify(parsed ?? JSON.parse(text2));
|
|
20768
|
-
const safe = redactCredentialText(canonical4, credentials);
|
|
21058
|
+
const safe = redactCredentialText(canonical4, credentials, projectIds);
|
|
20769
21059
|
return safe === canonical4 ? text2 : safe;
|
|
20770
21060
|
} catch {
|
|
20771
21061
|
return text2;
|
|
20772
21062
|
}
|
|
20773
21063
|
}
|
|
20774
|
-
function redactCredentialFrame(frame, credentials) {
|
|
21064
|
+
function redactCredentialFrame(frame, credentials, projectIds) {
|
|
20775
21065
|
if (!frame.includes('"error"') && !frame.includes("\\u"))
|
|
20776
21066
|
return frame;
|
|
20777
21067
|
try {
|
|
20778
21068
|
const value = JSON.parse(frame);
|
|
20779
21069
|
if (value?.type === "error" || value?.error || value?.response?.error) {
|
|
20780
|
-
return redactDiagnosticText(frame, credentials, value);
|
|
21070
|
+
return redactDiagnosticText(frame, credentials, projectIds, value);
|
|
20781
21071
|
}
|
|
20782
21072
|
} catch {
|
|
20783
21073
|
}
|
|
@@ -20792,26 +21082,26 @@ function preserveResponseMetadata2(response, original) {
|
|
|
20792
21082
|
}
|
|
20793
21083
|
return response;
|
|
20794
21084
|
}
|
|
20795
|
-
async function redactCredentialResponse(response, credentials, bufferedBody) {
|
|
21085
|
+
async function redactCredentialResponse(response, credentials, bufferedBody, projectIds) {
|
|
20796
21086
|
const init = {
|
|
20797
21087
|
status: response.status,
|
|
20798
21088
|
statusText: response.statusText,
|
|
20799
21089
|
headers: new Headers(response.headers)
|
|
20800
21090
|
};
|
|
20801
21091
|
if (!response.ok) {
|
|
20802
|
-
init.statusText = redactCredentialText(init.statusText, credentials);
|
|
21092
|
+
init.statusText = redactCredentialText(init.statusText, credentials, projectIds);
|
|
20803
21093
|
let metadataChanged = init.statusText !== response.statusText;
|
|
20804
21094
|
for (const [key, value] of init.headers) {
|
|
20805
|
-
const safe = redactCredentialText(value, credentials);
|
|
21095
|
+
const safe = redactCredentialText(value, credentials, projectIds);
|
|
20806
21096
|
if (safe !== value) {
|
|
20807
21097
|
init.headers.set(key, safe);
|
|
20808
21098
|
metadataChanged = true;
|
|
20809
21099
|
}
|
|
20810
21100
|
}
|
|
20811
21101
|
const text2 = bufferedBody ?? (response.body ? await response.text().catch((error) => {
|
|
20812
|
-
throw redactCredentialError(error, credentials);
|
|
21102
|
+
throw redactCredentialError(error, credentials, projectIds);
|
|
20813
21103
|
}) : null);
|
|
20814
|
-
const redacted = text2 === null ? null : redactDiagnosticText(text2, credentials);
|
|
21104
|
+
const redacted = text2 === null ? null : redactDiagnosticText(text2, credentials, projectIds);
|
|
20815
21105
|
if ((bufferedBody !== void 0 || !response.body) && redacted === text2 && !metadataChanged)
|
|
20816
21106
|
return response;
|
|
20817
21107
|
if (response.body)
|
|
@@ -20825,7 +21115,7 @@ async function redactCredentialResponse(response, credentials, bufferedBody) {
|
|
|
20825
21115
|
const decoder = new TextDecoder();
|
|
20826
21116
|
const encoder = new TextEncoder();
|
|
20827
21117
|
let pending = "";
|
|
20828
|
-
const redact3 = (event) => event.replace(/^data: ?([^\r\n]*)/gm, (line, data) => line.slice(0, line.length - data.length) + redactCredentialFrame(data, credentials));
|
|
21118
|
+
const redact3 = (event) => event.replace(/^data: ?([^\r\n]*)/gm, (line, data) => line.slice(0, line.length - data.length) + redactCredentialFrame(data, credentials, projectIds));
|
|
20829
21119
|
const body = new ReadableStream({
|
|
20830
21120
|
async pull(controller) {
|
|
20831
21121
|
try {
|
|
@@ -20854,14 +21144,14 @@ async function redactCredentialResponse(response, credentials, bufferedBody) {
|
|
|
20854
21144
|
}
|
|
20855
21145
|
} catch (error) {
|
|
20856
21146
|
reader.releaseLock();
|
|
20857
|
-
controller.error(redactCredentialError(error, credentials));
|
|
21147
|
+
controller.error(redactCredentialError(error, credentials, projectIds));
|
|
20858
21148
|
}
|
|
20859
21149
|
},
|
|
20860
21150
|
async cancel(reason) {
|
|
20861
21151
|
try {
|
|
20862
21152
|
await reader.cancel(reason);
|
|
20863
21153
|
} catch (error) {
|
|
20864
|
-
throw redactCredentialError(error, credentials);
|
|
21154
|
+
throw redactCredentialError(error, credentials, projectIds);
|
|
20865
21155
|
} finally {
|
|
20866
21156
|
reader.releaseLock();
|
|
20867
21157
|
}
|
|
@@ -20883,6 +21173,155 @@ function getPiAntigravityVaultDir() {
|
|
|
20883
21173
|
return join6(dirname11(getPiAntigravityAuthFile()), "antigravity-auth-vault");
|
|
20884
21174
|
}
|
|
20885
21175
|
|
|
21176
|
+
// ../core/dist/pre-response-deadline.js
|
|
21177
|
+
var PRE_RESPONSE_DEADLINE_MS = 6e5;
|
|
21178
|
+
var PRE_RESPONSE_TIMEOUT_MESSAGE = "Antigravity did not begin a response within the pre-response time limit. Check your connection and try again later.";
|
|
21179
|
+
var PreResponseTimeoutError = class extends Error {
|
|
21180
|
+
code = 412;
|
|
21181
|
+
status = "FAILED_PRECONDITION";
|
|
21182
|
+
reason = "PRE_RESPONSE_TIMEOUT";
|
|
21183
|
+
constructor() {
|
|
21184
|
+
super(PRE_RESPONSE_TIMEOUT_MESSAGE);
|
|
21185
|
+
this.name = "PreResponseTimeoutError";
|
|
21186
|
+
}
|
|
21187
|
+
};
|
|
21188
|
+
function preResponseTimeoutResponse() {
|
|
21189
|
+
return new Response(JSON.stringify({
|
|
21190
|
+
error: {
|
|
21191
|
+
code: 412,
|
|
21192
|
+
status: "FAILED_PRECONDITION",
|
|
21193
|
+
message: PRE_RESPONSE_TIMEOUT_MESSAGE
|
|
21194
|
+
}
|
|
21195
|
+
}), { status: 412, headers: { "Content-Type": "application/json" } });
|
|
21196
|
+
}
|
|
21197
|
+
var clock = {
|
|
21198
|
+
now: () => performance.now(),
|
|
21199
|
+
schedule(callback, delayMs) {
|
|
21200
|
+
const timer = setTimeout(callback, delayMs);
|
|
21201
|
+
timer.unref?.();
|
|
21202
|
+
return () => clearTimeout(timer);
|
|
21203
|
+
}
|
|
21204
|
+
};
|
|
21205
|
+
var PreResponseDeadline = class {
|
|
21206
|
+
caller;
|
|
21207
|
+
time;
|
|
21208
|
+
signal;
|
|
21209
|
+
controller = new AbortController();
|
|
21210
|
+
expiresAt;
|
|
21211
|
+
active = true;
|
|
21212
|
+
cancelTimer;
|
|
21213
|
+
detachCaller;
|
|
21214
|
+
detachSignals = [];
|
|
21215
|
+
constructor(caller, time = clock) {
|
|
21216
|
+
this.caller = caller;
|
|
21217
|
+
this.time = time;
|
|
21218
|
+
this.expiresAt = time.now() + PRE_RESPONSE_DEADLINE_MS;
|
|
21219
|
+
this.signal = this.controller.signal;
|
|
21220
|
+
const abort = () => {
|
|
21221
|
+
this.cancelTimer?.();
|
|
21222
|
+
this.controller.abort(caller?.reason);
|
|
21223
|
+
};
|
|
21224
|
+
this.detachCaller = () => caller?.removeEventListener("abort", abort);
|
|
21225
|
+
if (caller?.aborted)
|
|
21226
|
+
abort();
|
|
21227
|
+
else
|
|
21228
|
+
caller?.addEventListener("abort", abort, { once: true });
|
|
21229
|
+
this.arm();
|
|
21230
|
+
}
|
|
21231
|
+
remainingMs() {
|
|
21232
|
+
return Math.max(0, this.expiresAt - this.time.now());
|
|
21233
|
+
}
|
|
21234
|
+
follow(signal) {
|
|
21235
|
+
if (!signal || signal === this.signal)
|
|
21236
|
+
return;
|
|
21237
|
+
const abort = () => this.controller.abort(signal.reason);
|
|
21238
|
+
if (signal.aborted)
|
|
21239
|
+
abort();
|
|
21240
|
+
else
|
|
21241
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
21242
|
+
this.detachSignals.push(() => signal.removeEventListener("abort", abort));
|
|
21243
|
+
this.check();
|
|
21244
|
+
}
|
|
21245
|
+
arm() {
|
|
21246
|
+
if (this.signal.aborted)
|
|
21247
|
+
return;
|
|
21248
|
+
this.cancelTimer = this.time.schedule(() => {
|
|
21249
|
+
if (this.remainingMs() > 0)
|
|
21250
|
+
this.arm();
|
|
21251
|
+
else
|
|
21252
|
+
this.expire();
|
|
21253
|
+
}, this.remainingMs());
|
|
21254
|
+
}
|
|
21255
|
+
expire() {
|
|
21256
|
+
this.cancelTimer?.();
|
|
21257
|
+
this.controller.abort(new PreResponseTimeoutError());
|
|
21258
|
+
}
|
|
21259
|
+
check() {
|
|
21260
|
+
this.caller?.throwIfAborted();
|
|
21261
|
+
if (this.active && this.remainingMs() <= 0 && !this.signal.aborted)
|
|
21262
|
+
this.expire();
|
|
21263
|
+
this.signal.throwIfAborted();
|
|
21264
|
+
}
|
|
21265
|
+
acceptHeaders() {
|
|
21266
|
+
this.check();
|
|
21267
|
+
this.acceptTerminalResponse();
|
|
21268
|
+
}
|
|
21269
|
+
acceptTerminalResponse() {
|
|
21270
|
+
this.active = false;
|
|
21271
|
+
this.cancelTimer?.();
|
|
21272
|
+
this.cancelTimer = void 0;
|
|
21273
|
+
}
|
|
21274
|
+
resume() {
|
|
21275
|
+
this.active = true;
|
|
21276
|
+
this.check();
|
|
21277
|
+
this.arm();
|
|
21278
|
+
}
|
|
21279
|
+
/** Cancel a response that arrives after its sender lost the abort race. */
|
|
21280
|
+
open(work) {
|
|
21281
|
+
return this.wait(() => {
|
|
21282
|
+
const pending = work();
|
|
21283
|
+
void pending.then((response) => {
|
|
21284
|
+
if (this.signal.aborted)
|
|
21285
|
+
void response.body?.cancel().catch(() => {
|
|
21286
|
+
});
|
|
21287
|
+
}, () => {
|
|
21288
|
+
});
|
|
21289
|
+
return pending;
|
|
21290
|
+
});
|
|
21291
|
+
}
|
|
21292
|
+
/** Interrupt even prerequisites that cannot themselves accept an AbortSignal. */
|
|
21293
|
+
async wait(work) {
|
|
21294
|
+
this.check();
|
|
21295
|
+
let abort = () => {
|
|
21296
|
+
};
|
|
21297
|
+
const cancelled = new Promise((_, reject) => {
|
|
21298
|
+
abort = () => reject(this.caller?.aborted ? this.caller.reason : this.signal.reason);
|
|
21299
|
+
this.signal.addEventListener("abort", abort, { once: true });
|
|
21300
|
+
});
|
|
21301
|
+
try {
|
|
21302
|
+
const result = await Promise.race([
|
|
21303
|
+
Promise.resolve().then(() => {
|
|
21304
|
+
this.check();
|
|
21305
|
+
return work();
|
|
21306
|
+
}),
|
|
21307
|
+
cancelled
|
|
21308
|
+
]);
|
|
21309
|
+
this.check();
|
|
21310
|
+
return result;
|
|
21311
|
+
} finally {
|
|
21312
|
+
this.signal.removeEventListener("abort", abort);
|
|
21313
|
+
}
|
|
21314
|
+
}
|
|
21315
|
+
dispose() {
|
|
21316
|
+
this.cancelTimer?.();
|
|
21317
|
+
this.cancelTimer = void 0;
|
|
21318
|
+
this.detachCaller();
|
|
21319
|
+
for (const detach of this.detachSignals)
|
|
21320
|
+
detach();
|
|
21321
|
+
this.detachSignals.length = 0;
|
|
21322
|
+
}
|
|
21323
|
+
};
|
|
21324
|
+
|
|
20886
21325
|
// ../core/dist/project.js
|
|
20887
21326
|
var log3 = createLogger("project");
|
|
20888
21327
|
var PROJECT_CONTEXT_CACHE_TTL_MS = 30 * 60 * 1e3;
|
|
@@ -22612,6 +23051,17 @@ function getAntigravityVaultEnrollmentName(host) {
|
|
|
22612
23051
|
}
|
|
22613
23052
|
}
|
|
22614
23053
|
|
|
23054
|
+
// ../core/dist/vault-grant-reach.js
|
|
23055
|
+
function emptyVaultRosterCause(reach) {
|
|
23056
|
+
if (reach === void 0)
|
|
23057
|
+
return "unknown";
|
|
23058
|
+
if (reach.grants === 0)
|
|
23059
|
+
return "no-grant";
|
|
23060
|
+
return "grant-reaches-nothing";
|
|
23061
|
+
}
|
|
23062
|
+
var VAULT_RECLASSIFY_COMMAND = "ck auth reclassify --from-registry";
|
|
23063
|
+
var VAULT_STATUS_COMMAND = "ck auth status";
|
|
23064
|
+
|
|
22615
23065
|
// ../core/dist/vault-provider-state.js
|
|
22616
23066
|
import { readFile as readFile7 } from "node:fs/promises";
|
|
22617
23067
|
var VAULT_PROVIDER_STATE_SCHEMA_VERSION = 1;
|
|
@@ -23145,6 +23595,8 @@ function createAntigravityVaultAccountSource(options) {
|
|
|
23145
23595
|
assertOpen();
|
|
23146
23596
|
await consumer.accept(ref.routeId);
|
|
23147
23597
|
},
|
|
23598
|
+
grantReach: () => closed ? void 0 : consumer.grantReach(),
|
|
23599
|
+
emptyRosterCause: () => closed || consumer.snapshot()?.rows.length !== 0 ? "unknown" : emptyVaultRosterCause(consumer.grantReach()),
|
|
23148
23600
|
close: () => {
|
|
23149
23601
|
if (closed)
|
|
23150
23602
|
return;
|
|
@@ -23252,7 +23704,7 @@ async function initAntigravityVersion() {
|
|
|
23252
23704
|
}
|
|
23253
23705
|
|
|
23254
23706
|
// src/cli.ts
|
|
23255
|
-
import { execFile
|
|
23707
|
+
import { execFile } from "node:child_process";
|
|
23256
23708
|
import { realpathSync as realpathSync2 } from "node:fs";
|
|
23257
23709
|
import { resolve as resolve12 } from "node:path";
|
|
23258
23710
|
import { createInterface } from "node:readline/promises";
|
|
@@ -24052,9 +24504,7 @@ function writeConsoleLog2(level, ...args) {
|
|
|
24052
24504
|
}
|
|
24053
24505
|
}
|
|
24054
24506
|
function redactSensitive(value) {
|
|
24055
|
-
|
|
24056
|
-
if (value.length <= 8) return "****";
|
|
24057
|
-
return `${value.slice(0, 4)}****${value.slice(-4)}`;
|
|
24507
|
+
return maskSensitiveIdentifier(value);
|
|
24058
24508
|
}
|
|
24059
24509
|
var SENSITIVE_FIELD_PATTERN = /token|refresh|access|project|fingerprint|deviceId|sessionId|sessionToken|secret|password|apiKey|clientSecret/i;
|
|
24060
24510
|
function redactSensitiveFields(value) {
|
|
@@ -27545,7 +27995,10 @@ function isLostMarkerRaceError2(error) {
|
|
|
27545
27995
|
const code2 = error?.code;
|
|
27546
27996
|
return code2 === "ENOENT" || !windowsPrivateFiles2 && (code2 === "EINVAL" || code2 === "ENOTDIR");
|
|
27547
27997
|
}
|
|
27548
|
-
|
|
27998
|
+
function acquireRefreshFileLock2(options) {
|
|
27999
|
+
return acquireRefreshFileLockWithClock2({ ...options, now: Date.now });
|
|
28000
|
+
}
|
|
28001
|
+
async function acquireRefreshFileLockWithClock2(options) {
|
|
27549
28002
|
const lockPath = lockPathFor2(options.path, options.name);
|
|
27550
28003
|
const legacyOwnerPath = join10(lockPath, "owner.json");
|
|
27551
28004
|
const ownerId = randomUUID15();
|
|
@@ -28479,6 +28932,31 @@ async function readClaustrumEnrollmentStatus2(paths, proposedName) {
|
|
|
28479
28932
|
}
|
|
28480
28933
|
return statusFromState2(state);
|
|
28481
28934
|
}
|
|
28935
|
+
async function enrollmentAuthority3(paths, proposedName) {
|
|
28936
|
+
let status;
|
|
28937
|
+
try {
|
|
28938
|
+
status = await readClaustrumEnrollmentStatus2(paths, proposedName);
|
|
28939
|
+
} catch (error) {
|
|
28940
|
+
if (!(error instanceof ClaustrumConsumerError2) || error.kind !== "invalid-state" && error.kind !== "invalid-token") {
|
|
28941
|
+
return "unreadable";
|
|
28942
|
+
}
|
|
28943
|
+
try {
|
|
28944
|
+
const stateValue = await readBoundedJson2(paths.statePath);
|
|
28945
|
+
if (stateValue === void 0)
|
|
28946
|
+
return "unreadable";
|
|
28947
|
+
const state = decodeEnrollmentState2(stateValue);
|
|
28948
|
+
return state.phase === "approved" && state.proposedName === proposedName ? "vault" : "unreadable";
|
|
28949
|
+
} catch {
|
|
28950
|
+
return "unreadable";
|
|
28951
|
+
}
|
|
28952
|
+
}
|
|
28953
|
+
if ("proposedName" in status && status.proposedName !== proposedName)
|
|
28954
|
+
return "unreadable";
|
|
28955
|
+
if (status.state === "approved" || status.state === "blocked" && status.code === "missing_token") {
|
|
28956
|
+
return "vault";
|
|
28957
|
+
}
|
|
28958
|
+
return "local";
|
|
28959
|
+
}
|
|
28482
28960
|
function statusFromState2(state) {
|
|
28483
28961
|
if (state.phase === "pending") {
|
|
28484
28962
|
return {
|
|
@@ -28719,30 +29197,126 @@ async function resetClaustrumEnrollmentState2(paths, proposedName) {
|
|
|
28719
29197
|
}
|
|
28720
29198
|
|
|
28721
29199
|
// src/common-auth-embedded/setup/command-runner.js
|
|
28722
|
-
import {
|
|
29200
|
+
import { spawn } from "node:child_process";
|
|
29201
|
+
var STDERR_TAIL_MAX_BYTES = 4 * 1024;
|
|
29202
|
+
var STDOUT_MAX_BYTES = 1024 * 1024;
|
|
29203
|
+
var ByteTail = class {
|
|
29204
|
+
buffer = Buffer.alloc(STDERR_TAIL_MAX_BYTES);
|
|
29205
|
+
start = 0;
|
|
29206
|
+
length = 0;
|
|
29207
|
+
truncated = false;
|
|
29208
|
+
get didTruncate() {
|
|
29209
|
+
return this.truncated;
|
|
29210
|
+
}
|
|
29211
|
+
push(chunk) {
|
|
29212
|
+
if (chunk.length >= STDERR_TAIL_MAX_BYTES) {
|
|
29213
|
+
if (chunk.length > STDERR_TAIL_MAX_BYTES || this.length > 0)
|
|
29214
|
+
this.truncated = true;
|
|
29215
|
+
chunk.copy(this.buffer, 0, chunk.length - STDERR_TAIL_MAX_BYTES);
|
|
29216
|
+
this.start = 0;
|
|
29217
|
+
this.length = STDERR_TAIL_MAX_BYTES;
|
|
29218
|
+
return;
|
|
29219
|
+
}
|
|
29220
|
+
const overflow = Math.max(0, this.length + chunk.length - STDERR_TAIL_MAX_BYTES);
|
|
29221
|
+
if (overflow > 0)
|
|
29222
|
+
this.truncated = true;
|
|
29223
|
+
this.start = (this.start + overflow) % STDERR_TAIL_MAX_BYTES;
|
|
29224
|
+
this.length -= overflow;
|
|
29225
|
+
const writeAt = (this.start + this.length) % STDERR_TAIL_MAX_BYTES;
|
|
29226
|
+
const firstLength = Math.min(chunk.length, STDERR_TAIL_MAX_BYTES - writeAt);
|
|
29227
|
+
chunk.copy(this.buffer, writeAt, 0, firstLength);
|
|
29228
|
+
if (firstLength < chunk.length)
|
|
29229
|
+
chunk.copy(this.buffer, 0, firstLength);
|
|
29230
|
+
this.length += chunk.length;
|
|
29231
|
+
}
|
|
29232
|
+
toString() {
|
|
29233
|
+
const bytes = Buffer.alloc(this.length);
|
|
29234
|
+
const firstLength = Math.min(this.length, STDERR_TAIL_MAX_BYTES - this.start);
|
|
29235
|
+
this.buffer.copy(bytes, 0, this.start, this.start + firstLength);
|
|
29236
|
+
if (firstLength < this.length)
|
|
29237
|
+
this.buffer.copy(bytes, firstLength, 0, this.length - firstLength);
|
|
29238
|
+
let start = 0;
|
|
29239
|
+
while (start < bytes.length) {
|
|
29240
|
+
const byte = bytes[start];
|
|
29241
|
+
if (byte === void 0 || (byte & 192) !== 128)
|
|
29242
|
+
break;
|
|
29243
|
+
start++;
|
|
29244
|
+
}
|
|
29245
|
+
return bytes.subarray(start).toString("utf8");
|
|
29246
|
+
}
|
|
29247
|
+
};
|
|
28723
29248
|
var defaultCommandRunner = {
|
|
28724
29249
|
run(file, args, options = {}) {
|
|
28725
29250
|
return new Promise((resolve18) => {
|
|
28726
29251
|
const started = performance.now();
|
|
28727
29252
|
const timeoutMs = options.timeoutMs ?? 15e3;
|
|
28728
|
-
|
|
28729
|
-
|
|
28730
|
-
|
|
28731
|
-
|
|
28732
|
-
|
|
28733
|
-
|
|
28734
|
-
|
|
28735
|
-
|
|
29253
|
+
const stderr = new ByteTail();
|
|
29254
|
+
const stdout = [];
|
|
29255
|
+
let stdoutLength = 0;
|
|
29256
|
+
let outputExceeded = false;
|
|
29257
|
+
let spawnError = false;
|
|
29258
|
+
let timedOut = false;
|
|
29259
|
+
let child;
|
|
29260
|
+
try {
|
|
29261
|
+
child = spawn(file, [...args], {
|
|
29262
|
+
env: options.env ?? process.env,
|
|
29263
|
+
windowsHide: true,
|
|
29264
|
+
windowsVerbatimArguments: options.windowsVerbatimArguments,
|
|
29265
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
29266
|
+
});
|
|
29267
|
+
} catch {
|
|
28736
29268
|
resolve18({
|
|
28737
|
-
exitCode:
|
|
28738
|
-
stdout:
|
|
28739
|
-
stderr:
|
|
28740
|
-
|
|
28741
|
-
|
|
28742
|
-
timedOut:
|
|
28743
|
-
durationMs
|
|
29269
|
+
exitCode: 1,
|
|
29270
|
+
stdout: "",
|
|
29271
|
+
stderr: "",
|
|
29272
|
+
spawnError: true,
|
|
29273
|
+
signal: null,
|
|
29274
|
+
timedOut: false,
|
|
29275
|
+
durationMs: performance.now() - started
|
|
28744
29276
|
});
|
|
29277
|
+
return;
|
|
29278
|
+
}
|
|
29279
|
+
const timer = timeoutMs > 0 ? setTimeout(() => {
|
|
29280
|
+
timedOut = true;
|
|
29281
|
+
child.kill("SIGTERM");
|
|
29282
|
+
}, timeoutMs) : void 0;
|
|
29283
|
+
child.stdout?.on("data", (chunk) => {
|
|
29284
|
+
const remaining = STDOUT_MAX_BYTES - stdoutLength;
|
|
29285
|
+
const length = Math.min(remaining, chunk.length);
|
|
29286
|
+
if (length > 0) {
|
|
29287
|
+
stdout.push(chunk.subarray(0, length));
|
|
29288
|
+
stdoutLength += length;
|
|
29289
|
+
}
|
|
29290
|
+
if (chunk.length > remaining) {
|
|
29291
|
+
outputExceeded = true;
|
|
29292
|
+
child.kill("SIGTERM");
|
|
29293
|
+
}
|
|
29294
|
+
});
|
|
29295
|
+
child.stderr?.on("data", (chunk) => stderr.push(chunk));
|
|
29296
|
+
let settled = false;
|
|
29297
|
+
const settle = (code2, signal) => {
|
|
29298
|
+
if (settled)
|
|
29299
|
+
return;
|
|
29300
|
+
settled = true;
|
|
29301
|
+
if (timer)
|
|
29302
|
+
clearTimeout(timer);
|
|
29303
|
+
resolve18({
|
|
29304
|
+
exitCode: spawnError ? 1 : outputExceeded ? 1 : code2 ?? 1,
|
|
29305
|
+
stdout: Buffer.concat(stdout, stdoutLength).toString("utf8"),
|
|
29306
|
+
stderr: stderr.toString(),
|
|
29307
|
+
stderrTruncated: stderr.didTruncate,
|
|
29308
|
+
...spawnError ? { spawnError: true } : {},
|
|
29309
|
+
signal: signal ?? null,
|
|
29310
|
+
timedOut,
|
|
29311
|
+
durationMs: performance.now() - started
|
|
29312
|
+
});
|
|
29313
|
+
};
|
|
29314
|
+
child.once("error", () => {
|
|
29315
|
+
spawnError = true;
|
|
29316
|
+
if (child.pid === void 0)
|
|
29317
|
+
settle(null, null);
|
|
28745
29318
|
});
|
|
29319
|
+
child.once("close", (code2, signal) => settle(code2, signal));
|
|
28746
29320
|
});
|
|
28747
29321
|
}
|
|
28748
29322
|
};
|
|
@@ -28759,6 +29333,56 @@ function runResolvedCommand(runner, platform, file, args, env3, timeoutMs = 15e3
|
|
|
28759
29333
|
return runner.run(file, args, { env: env3, timeoutMs });
|
|
28760
29334
|
}
|
|
28761
29335
|
|
|
29336
|
+
// src/common-auth-embedded/setup/command-error.js
|
|
29337
|
+
var PI_INSTALL_ERROR_MESSAGE = "Pi install failed; run pi install after checking your npm connection.";
|
|
29338
|
+
function utf8Tail(value) {
|
|
29339
|
+
const bytes = Buffer.from(value, "utf8");
|
|
29340
|
+
if (bytes.length <= STDERR_TAIL_MAX_BYTES)
|
|
29341
|
+
return value;
|
|
29342
|
+
let start = bytes.length - STDERR_TAIL_MAX_BYTES;
|
|
29343
|
+
while (start < bytes.length) {
|
|
29344
|
+
const byte = bytes[start];
|
|
29345
|
+
if (byte === void 0 || (byte & 192) !== 128)
|
|
29346
|
+
break;
|
|
29347
|
+
start++;
|
|
29348
|
+
}
|
|
29349
|
+
return bytes.subarray(start).toString("utf8");
|
|
29350
|
+
}
|
|
29351
|
+
function dropPartialLine(tail) {
|
|
29352
|
+
const newline = tail.indexOf("\n");
|
|
29353
|
+
return newline < 0 ? "" : tail.slice(newline + 1);
|
|
29354
|
+
}
|
|
29355
|
+
var SetupCommandError = class extends Error {
|
|
29356
|
+
step = "pi-install";
|
|
29357
|
+
exitCode;
|
|
29358
|
+
signal;
|
|
29359
|
+
stderrTail;
|
|
29360
|
+
constructor(details) {
|
|
29361
|
+
super(PI_INSTALL_ERROR_MESSAGE);
|
|
29362
|
+
this.name = "SetupCommandError";
|
|
29363
|
+
this.exitCode = details.exitCode;
|
|
29364
|
+
this.signal = details.signal;
|
|
29365
|
+
const tail = details.stderrTruncated ? dropPartialLine(details.stderrTail) : details.stderrTail;
|
|
29366
|
+
const redacted = redact2(tail);
|
|
29367
|
+
this.stderrTail = utf8Tail(typeof redacted === "string" ? redacted : "");
|
|
29368
|
+
}
|
|
29369
|
+
};
|
|
29370
|
+
var HOST_LABELS = { opencode: "OpenCode", pi: "Pi" };
|
|
29371
|
+
var OUTCOME_TEXT = {
|
|
29372
|
+
enrolled: "connected to the vault",
|
|
29373
|
+
"not-enrolled": "not connected",
|
|
29374
|
+
unknown: "unknown, check with ck auth status"
|
|
29375
|
+
};
|
|
29376
|
+
function setupEnrollmentLine({ host, outcome }) {
|
|
29377
|
+
return `${HOST_LABELS[host]}: ${OUTCOME_TEXT[outcome]}`;
|
|
29378
|
+
}
|
|
29379
|
+
var recordedEnrollment = /* @__PURE__ */ new WeakMap();
|
|
29380
|
+
function recordSetupEnrollment(failure2, enrollment) {
|
|
29381
|
+
if (typeof failure2 !== "object" && typeof failure2 !== "function" || !failure2)
|
|
29382
|
+
return;
|
|
29383
|
+
recordedEnrollment.set(failure2, Object.freeze(enrollment.map((entry) => Object.freeze({ ...entry }))));
|
|
29384
|
+
}
|
|
29385
|
+
|
|
28762
29386
|
// src/common-auth-embedded/setup/detect.js
|
|
28763
29387
|
import { accessSync, constants as constants3, existsSync as existsSync5, readFileSync as readFileSync4, realpathSync, statSync as statSync5 } from "node:fs";
|
|
28764
29388
|
import { mkdtemp, rm as rm6 } from "node:fs/promises";
|
|
@@ -29232,6 +29856,9 @@ async function assertHostsStopped(fence, env3) {
|
|
|
29232
29856
|
}
|
|
29233
29857
|
|
|
29234
29858
|
// src/common-auth-embedded/setup/enroll.js
|
|
29859
|
+
var ENROLLMENT_INCOMPLETE_MESSAGE = "Claustrum enrollment did not complete. Inspect and approve with ck, then rerun setup.";
|
|
29860
|
+
var HostNotEnrolledError = class extends Error {
|
|
29861
|
+
};
|
|
29235
29862
|
async function connectSetupHost(plugin, host, io, terminal, fence) {
|
|
29236
29863
|
const { name, paths: input2 } = plugin.vault.hosts[host];
|
|
29237
29864
|
const paths = hostEnrollmentPaths2(input2);
|
|
@@ -29240,7 +29867,7 @@ async function connectSetupHost(plugin, host, io, terminal, fence) {
|
|
|
29240
29867
|
connectionFile: plugin.vault.connectionFile,
|
|
29241
29868
|
handshakeTimeoutMs: 2e3
|
|
29242
29869
|
}).catch(() => {
|
|
29243
|
-
throw new
|
|
29870
|
+
throw new HostNotEnrolledError("Claustrum connection failed; start ck and rerun setup.");
|
|
29244
29871
|
});
|
|
29245
29872
|
try {
|
|
29246
29873
|
const manager = new ClaustrumEnrollmentManager2({
|
|
@@ -29270,10 +29897,10 @@ async function connectSetupHost(plugin, host, io, terminal, fence) {
|
|
|
29270
29897
|
return;
|
|
29271
29898
|
}
|
|
29272
29899
|
if (status.state !== "pending" && status.state !== "busy")
|
|
29273
|
-
throw new
|
|
29900
|
+
throw new HostNotEnrolledError("Claustrum enrollment refused; inspect its status with ck before rerunning setup.");
|
|
29274
29901
|
if (status.state === "pending" && status.requestId && status.requestId !== printedRequest) {
|
|
29275
29902
|
if (!/^[a-zA-Z0-9_-]+$/.test(status.requestId))
|
|
29276
|
-
throw new
|
|
29903
|
+
throw new HostNotEnrolledError("Invalid enrollment request id.");
|
|
29277
29904
|
printedRequest = status.requestId;
|
|
29278
29905
|
printLine2(terminal, "Waiting for approval. In another terminal, run:");
|
|
29279
29906
|
printLine2(terminal, ` ck auth enroll approve --request-id ${status.requestId} --name ${name}`);
|
|
@@ -29281,11 +29908,13 @@ async function connectSetupHost(plugin, host, io, terminal, fence) {
|
|
|
29281
29908
|
}
|
|
29282
29909
|
await (io.wait ?? delay)(1e3);
|
|
29283
29910
|
}
|
|
29284
|
-
throw new
|
|
29911
|
+
throw new HostNotEnrolledError("Claustrum approval is still pending; approve with ck and rerun setup.");
|
|
29285
29912
|
} catch (error) {
|
|
29286
29913
|
if (error instanceof ProcessFenceViolationError || error instanceof ProcessInspectionError)
|
|
29287
29914
|
throw error;
|
|
29288
|
-
|
|
29915
|
+
if (error instanceof HostNotEnrolledError)
|
|
29916
|
+
throw new HostNotEnrolledError(ENROLLMENT_INCOMPLETE_MESSAGE);
|
|
29917
|
+
throw new Error(ENROLLMENT_INCOMPLETE_MESSAGE);
|
|
29289
29918
|
} finally {
|
|
29290
29919
|
client.close();
|
|
29291
29920
|
}
|
|
@@ -29477,8 +30106,13 @@ async function registerOpenCode(writes, beforeWrite) {
|
|
|
29477
30106
|
async function registerPi(plugin, executable, io = {}) {
|
|
29478
30107
|
const { platform, env: env3 } = setupPaths(io);
|
|
29479
30108
|
const result = await runResolvedCommand(io.runner ?? defaultCommandRunner, platform, executable, ["install", `npm:${plugin.packages.pi}@${plugin.version}`], env3);
|
|
29480
|
-
if (result.exitCode !== 0)
|
|
29481
|
-
throw new
|
|
30109
|
+
if (result.exitCode !== 0 || result.timedOut)
|
|
30110
|
+
throw new SetupCommandError({
|
|
30111
|
+
exitCode: result.spawnError ? null : result.exitCode,
|
|
30112
|
+
signal: result.signal ?? null,
|
|
30113
|
+
stderrTail: result.stderr,
|
|
30114
|
+
stderrTruncated: result.stderrTruncated ?? false
|
|
30115
|
+
});
|
|
29482
30116
|
}
|
|
29483
30117
|
|
|
29484
30118
|
// src/common-auth-embedded/setup/command.js
|
|
@@ -29526,6 +30160,22 @@ function validatePlugin(plugin) {
|
|
|
29526
30160
|
throw new Error("Setup requires lowercase vault names containing only letters, digits and dashes.");
|
|
29527
30161
|
}
|
|
29528
30162
|
}
|
|
30163
|
+
async function enrollmentReport(plugin, hosts, recorded) {
|
|
30164
|
+
const report = [];
|
|
30165
|
+
for (const host of hosts) {
|
|
30166
|
+
let outcome = recorded.get(host) ?? "not-enrolled";
|
|
30167
|
+
if (outcome === "unknown") {
|
|
30168
|
+
const { name, paths } = plugin.vault.hosts[host];
|
|
30169
|
+
const authority = await enrollmentAuthority3(hostEnrollmentPaths2(paths), name).catch(() => "unreadable");
|
|
30170
|
+
if (authority === "vault")
|
|
30171
|
+
outcome = "enrolled";
|
|
30172
|
+
else if (authority === "local")
|
|
30173
|
+
outcome = "not-enrolled";
|
|
30174
|
+
}
|
|
30175
|
+
report.push({ host, outcome });
|
|
30176
|
+
}
|
|
30177
|
+
return report;
|
|
30178
|
+
}
|
|
29529
30179
|
async function runSetup(plugin, argv = [], io = {}) {
|
|
29530
30180
|
const options = flags(argv);
|
|
29531
30181
|
validatePlugin(plugin);
|
|
@@ -29635,23 +30285,45 @@ ${write.content}`);
|
|
|
29635
30285
|
hosts: Object.freeze([...hosts]),
|
|
29636
30286
|
piAgentDir: detection.pi.directory
|
|
29637
30287
|
};
|
|
29638
|
-
|
|
29639
|
-
|
|
29640
|
-
|
|
29641
|
-
|
|
29642
|
-
|
|
29643
|
-
await
|
|
29644
|
-
|
|
29645
|
-
|
|
29646
|
-
|
|
29647
|
-
|
|
29648
|
-
|
|
29649
|
-
|
|
29650
|
-
|
|
29651
|
-
|
|
29652
|
-
|
|
29653
|
-
|
|
29654
|
-
|
|
30288
|
+
const enrollment = /* @__PURE__ */ new Map();
|
|
30289
|
+
try {
|
|
30290
|
+
for (const host of hosts) {
|
|
30291
|
+
await stopped();
|
|
30292
|
+
await plugin.beforeSignIn?.(host, context);
|
|
30293
|
+
await stopped();
|
|
30294
|
+
if (useVault) {
|
|
30295
|
+
enrollment.set(host, "unknown");
|
|
30296
|
+
try {
|
|
30297
|
+
await connectSetupHost(plugin, host, io, terminal, stopped);
|
|
30298
|
+
} catch (error) {
|
|
30299
|
+
if (error instanceof HostNotEnrolledError)
|
|
30300
|
+
enrollment.set(host, "not-enrolled");
|
|
30301
|
+
throw error;
|
|
30302
|
+
}
|
|
30303
|
+
enrollment.set(host, "enrolled");
|
|
30304
|
+
} else
|
|
30305
|
+
await plugin.signInLocal(host, context);
|
|
30306
|
+
await stopped();
|
|
30307
|
+
await plugin.beforeRegister?.(host, mode, context);
|
|
30308
|
+
await stopped();
|
|
30309
|
+
if (host === "opencode")
|
|
30310
|
+
await registerOpenCode(writes, stopped);
|
|
30311
|
+
else
|
|
30312
|
+
await registerPi(plugin, detection.pi.executable, io);
|
|
30313
|
+
await stopped();
|
|
30314
|
+
await plugin.migrate(host, context);
|
|
30315
|
+
}
|
|
30316
|
+
} catch (error) {
|
|
30317
|
+
if (enrollment.size === 0)
|
|
30318
|
+
throw error;
|
|
30319
|
+
try {
|
|
30320
|
+
const report = await enrollmentReport(plugin, hosts, enrollment);
|
|
30321
|
+
recordSetupEnrollment(error, report);
|
|
30322
|
+
for (const entry of report)
|
|
30323
|
+
printLine2(terminal, setupEnrollmentLine(entry));
|
|
30324
|
+
} catch {
|
|
30325
|
+
}
|
|
30326
|
+
throw error;
|
|
29655
30327
|
}
|
|
29656
30328
|
}
|
|
29657
30329
|
printLine2(terminal, `${options.dryRun ? "Planned" : "Configured"} ${plugin.displayName} for ${hosts.join(", ")} (${mode}).`);
|
|
@@ -29714,6 +30386,398 @@ function createV1VaultActivationMethod(input2) {
|
|
|
29714
30386
|
// src/plugin/vault-custody.ts
|
|
29715
30387
|
import { chmod as chmod4, mkdir as mkdir14, readFile as readFile12 } from "node:fs/promises";
|
|
29716
30388
|
import { dirname as dirname19, join as join15 } from "node:path";
|
|
30389
|
+
|
|
30390
|
+
// src/plugin/shared/vault-request-credentials.ts
|
|
30391
|
+
function vaultAccountRows(routes) {
|
|
30392
|
+
return routes.map((route, index) => ({
|
|
30393
|
+
index,
|
|
30394
|
+
enabled: true,
|
|
30395
|
+
lastUsed: 0,
|
|
30396
|
+
rateLimitResetTimes: {},
|
|
30397
|
+
touchedForQuota: {},
|
|
30398
|
+
route,
|
|
30399
|
+
...route.email !== void 0 ? { email: route.email } : {}
|
|
30400
|
+
}));
|
|
30401
|
+
}
|
|
30402
|
+
function vaultAccountRowKey(row) {
|
|
30403
|
+
return JSON.stringify([
|
|
30404
|
+
row.route.routeId,
|
|
30405
|
+
row.route.credentialId,
|
|
30406
|
+
row.route.accountIdentity
|
|
30407
|
+
]);
|
|
30408
|
+
}
|
|
30409
|
+
function refreshVaultAccountRow(prior, fresh) {
|
|
30410
|
+
prior.route = fresh.route;
|
|
30411
|
+
if (fresh.email === void 0) delete prior.email;
|
|
30412
|
+
else prior.email = fresh.email;
|
|
30413
|
+
}
|
|
30414
|
+
var VaultSendGrant = class {
|
|
30415
|
+
credentialId;
|
|
30416
|
+
accountIdentity;
|
|
30417
|
+
recordVersion;
|
|
30418
|
+
projectId;
|
|
30419
|
+
report401;
|
|
30420
|
+
constructor(admission, report) {
|
|
30421
|
+
Object.defineProperty(this, "accessToken", {
|
|
30422
|
+
value: admission.accessToken,
|
|
30423
|
+
enumerable: false
|
|
30424
|
+
});
|
|
30425
|
+
this.credentialId = admission.credentialId;
|
|
30426
|
+
this.accountIdentity = admission.accountIdentity;
|
|
30427
|
+
this.recordVersion = admission.recordVersion;
|
|
30428
|
+
this.projectId = admission.projectId;
|
|
30429
|
+
this.report401 = report;
|
|
30430
|
+
}
|
|
30431
|
+
};
|
|
30432
|
+
function createVaultRequestCredentials(source, onAdmitted) {
|
|
30433
|
+
return {
|
|
30434
|
+
domain: "vault",
|
|
30435
|
+
async admit({ account, signal }) {
|
|
30436
|
+
const admission = await source.admit(account.route, signal);
|
|
30437
|
+
if (onAdmitted)
|
|
30438
|
+
onAdmitted.admitted(account, onAdmitted.source.attribution(admission));
|
|
30439
|
+
return new VaultSendGrant(
|
|
30440
|
+
admission,
|
|
30441
|
+
(status) => source.reportServedStatus(admission, status)
|
|
30442
|
+
);
|
|
30443
|
+
}
|
|
30444
|
+
};
|
|
30445
|
+
}
|
|
30446
|
+
function present2(value) {
|
|
30447
|
+
return value === null ? void 0 : value;
|
|
30448
|
+
}
|
|
30449
|
+
function storedResets(resets) {
|
|
30450
|
+
const stored = {};
|
|
30451
|
+
for (const [key, at] of Object.entries(resets))
|
|
30452
|
+
if (typeof at === "number") stored[key] = at;
|
|
30453
|
+
return stored;
|
|
30454
|
+
}
|
|
30455
|
+
function cachedQuotaOf(quota) {
|
|
30456
|
+
const groups = quota.cachedQuota;
|
|
30457
|
+
if (groups == null) return void 0;
|
|
30458
|
+
const out = {};
|
|
30459
|
+
for (const name of ["gemini", "non-gemini"]) {
|
|
30460
|
+
const group = groups[name];
|
|
30461
|
+
if (group === void 0) continue;
|
|
30462
|
+
out[name] = {
|
|
30463
|
+
modelCount: group.modelCount,
|
|
30464
|
+
...group.remainingFraction != null ? { remainingFraction: group.remainingFraction } : {},
|
|
30465
|
+
...group.resetTime != null ? { resetTime: group.resetTime } : {},
|
|
30466
|
+
...group.windows != null ? {
|
|
30467
|
+
windows: group.windows.map((window) => ({
|
|
30468
|
+
window: window.window,
|
|
30469
|
+
remainingFraction: window.remainingFraction,
|
|
30470
|
+
resetTime: window.resetTime
|
|
30471
|
+
}))
|
|
30472
|
+
} : {}
|
|
30473
|
+
};
|
|
30474
|
+
}
|
|
30475
|
+
return out;
|
|
30476
|
+
}
|
|
30477
|
+
function durableSelectionOf(row) {
|
|
30478
|
+
return {
|
|
30479
|
+
lastUsed: row.lastUsed,
|
|
30480
|
+
...row.lastSwitchReason !== void 0 ? { lastSwitchReason: row.lastSwitchReason } : {},
|
|
30481
|
+
rateLimitResetTimes: storedResets(row.rateLimitResetTimes),
|
|
30482
|
+
...row.coolingDownUntil !== void 0 ? { coolingDownUntil: row.coolingDownUntil } : {},
|
|
30483
|
+
...row.cooldownReason !== void 0 ? { cooldownReason: row.cooldownReason } : {},
|
|
30484
|
+
...row.fingerprint !== void 0 ? { fingerprint: structuredClone(row.fingerprint) } : {},
|
|
30485
|
+
...row.fingerprintHistory !== void 0 ? { fingerprintHistory: structuredClone(row.fingerprintHistory) } : {},
|
|
30486
|
+
...row.verificationRequired !== void 0 ? { verificationRequired: row.verificationRequired } : {},
|
|
30487
|
+
...row.verificationRequiredAt !== void 0 ? { verificationRequiredAt: row.verificationRequiredAt } : {},
|
|
30488
|
+
...row.verificationRequiredReason !== void 0 ? { verificationRequiredReason: row.verificationRequiredReason } : {},
|
|
30489
|
+
...row.verificationUrl !== void 0 ? { verificationUrl: row.verificationUrl } : {},
|
|
30490
|
+
...row.accountIneligible !== void 0 ? { accountIneligible: row.accountIneligible } : {},
|
|
30491
|
+
...row.accountIneligibleAt !== void 0 ? { accountIneligibleAt: row.accountIneligibleAt } : {},
|
|
30492
|
+
...row.accountIneligibleReason !== void 0 ? { accountIneligibleReason: row.accountIneligibleReason } : {},
|
|
30493
|
+
...row.eligibilityStateUpdatedAt !== void 0 ? { eligibilityStateUpdatedAt: row.eligibilityStateUpdatedAt } : {},
|
|
30494
|
+
...row.dailyRequestCounts !== void 0 ? { dailyRequestCounts: { ...row.dailyRequestCounts } } : {}
|
|
30495
|
+
};
|
|
30496
|
+
}
|
|
30497
|
+
function applyDurableSelection(row, metadata) {
|
|
30498
|
+
row.lastUsed = metadata.lastUsed;
|
|
30499
|
+
const reason = present2(metadata.lastSwitchReason);
|
|
30500
|
+
if (reason !== void 0) row.lastSwitchReason = reason;
|
|
30501
|
+
const resets = present2(metadata.rateLimitResetTimes);
|
|
30502
|
+
if (resets !== void 0) {
|
|
30503
|
+
const copy = {};
|
|
30504
|
+
for (const [key, at] of Object.entries(resets))
|
|
30505
|
+
if (typeof at === "number") copy[key] = at;
|
|
30506
|
+
row.rateLimitResetTimes = copy;
|
|
30507
|
+
}
|
|
30508
|
+
const until = present2(metadata.coolingDownUntil);
|
|
30509
|
+
const cooldownReason = present2(metadata.cooldownReason);
|
|
30510
|
+
if (until !== void 0 && cooldownReason !== void 0) {
|
|
30511
|
+
row.coolingDownUntil = until;
|
|
30512
|
+
row.cooldownReason = cooldownReason;
|
|
30513
|
+
}
|
|
30514
|
+
const fingerprint = present2(metadata.fingerprint);
|
|
30515
|
+
if (fingerprint !== void 0) row.fingerprint = structuredClone(fingerprint);
|
|
30516
|
+
const history = present2(metadata.fingerprintHistory);
|
|
30517
|
+
if (history !== void 0) row.fingerprintHistory = structuredClone(history);
|
|
30518
|
+
const verification = present2(metadata.verificationRequired);
|
|
30519
|
+
if (verification !== void 0) row.verificationRequired = verification;
|
|
30520
|
+
const verificationAt = present2(metadata.verificationRequiredAt);
|
|
30521
|
+
if (verificationAt !== void 0) row.verificationRequiredAt = verificationAt;
|
|
30522
|
+
const verificationReason = present2(metadata.verificationRequiredReason);
|
|
30523
|
+
if (verificationReason !== void 0)
|
|
30524
|
+
row.verificationRequiredReason = verificationReason;
|
|
30525
|
+
const verificationUrl = present2(metadata.verificationUrl);
|
|
30526
|
+
if (verificationUrl !== void 0) row.verificationUrl = verificationUrl;
|
|
30527
|
+
const ineligible = present2(metadata.accountIneligible);
|
|
30528
|
+
if (ineligible !== void 0) row.accountIneligible = ineligible;
|
|
30529
|
+
const ineligibleAt = present2(metadata.accountIneligibleAt);
|
|
30530
|
+
if (ineligibleAt !== void 0) row.accountIneligibleAt = ineligibleAt;
|
|
30531
|
+
const ineligibleReason = present2(metadata.accountIneligibleReason);
|
|
30532
|
+
if (ineligibleReason !== void 0)
|
|
30533
|
+
row.accountIneligibleReason = ineligibleReason;
|
|
30534
|
+
const eligibilityAt = present2(metadata.eligibilityStateUpdatedAt);
|
|
30535
|
+
if (eligibilityAt !== void 0) row.eligibilityStateUpdatedAt = eligibilityAt;
|
|
30536
|
+
const counts = present2(metadata.dailyRequestCounts);
|
|
30537
|
+
if (counts !== void 0) row.dailyRequestCounts = { ...counts };
|
|
30538
|
+
}
|
|
30539
|
+
function stateBelongsTo(state, row) {
|
|
30540
|
+
return state.observed.routeId === row.route.routeId && state.observed.credentialId === row.route.credentialId;
|
|
30541
|
+
}
|
|
30542
|
+
function createVaultSelectionState(options) {
|
|
30543
|
+
const now = options.now ?? (() => Date.now());
|
|
30544
|
+
const attributions = /* @__PURE__ */ new WeakMap();
|
|
30545
|
+
const changed = /* @__PURE__ */ new Set();
|
|
30546
|
+
let writing = Promise.resolve();
|
|
30547
|
+
const mark = (row) => {
|
|
30548
|
+
changed.add(row);
|
|
30549
|
+
};
|
|
30550
|
+
const report = (error) => {
|
|
30551
|
+
try {
|
|
30552
|
+
options.onError?.(error);
|
|
30553
|
+
} catch {
|
|
30554
|
+
}
|
|
30555
|
+
};
|
|
30556
|
+
const writeRow = async (row) => {
|
|
30557
|
+
const attribution = attributions.get(row);
|
|
30558
|
+
if (attribution === void 0) return;
|
|
30559
|
+
changed.delete(row);
|
|
30560
|
+
const selection = durableSelectionOf(row);
|
|
30561
|
+
try {
|
|
30562
|
+
await options.source.commitState(attribution, (current) => ({
|
|
30563
|
+
metadata: {
|
|
30564
|
+
...current?.metadata ?? { addedAt: now() },
|
|
30565
|
+
...selection
|
|
30566
|
+
},
|
|
30567
|
+
...current?.quota !== void 0 ? { quota: current.quota } : {},
|
|
30568
|
+
...current?.extensions !== void 0 ? { extensions: current.extensions } : {}
|
|
30569
|
+
}));
|
|
30570
|
+
} catch (error) {
|
|
30571
|
+
report(error);
|
|
30572
|
+
}
|
|
30573
|
+
};
|
|
30574
|
+
const flush = () => {
|
|
30575
|
+
writing = writing.then(async () => {
|
|
30576
|
+
for (const row of [...changed]) await writeRow(row);
|
|
30577
|
+
});
|
|
30578
|
+
return writing;
|
|
30579
|
+
};
|
|
30580
|
+
return {
|
|
30581
|
+
sink: {
|
|
30582
|
+
rateLimit: mark,
|
|
30583
|
+
cooldown: mark,
|
|
30584
|
+
switched: mark,
|
|
30585
|
+
lastUsed: mark,
|
|
30586
|
+
usage: mark,
|
|
30587
|
+
accessVerdict: mark,
|
|
30588
|
+
fingerprint: mark,
|
|
30589
|
+
requestSave: () => {
|
|
30590
|
+
void flush();
|
|
30591
|
+
}
|
|
30592
|
+
},
|
|
30593
|
+
admitted(row, attribution) {
|
|
30594
|
+
attributions.set(row, attribution);
|
|
30595
|
+
},
|
|
30596
|
+
async hydrate(rows) {
|
|
30597
|
+
const file = await options.readState();
|
|
30598
|
+
for (const row of rows) {
|
|
30599
|
+
const identity = row.route.accountIdentity;
|
|
30600
|
+
if (!Object.hasOwn(file.accounts, identity)) continue;
|
|
30601
|
+
const state = file.accounts[identity];
|
|
30602
|
+
if (state === void 0 || !stateBelongsTo(state, row)) continue;
|
|
30603
|
+
if (state.metadata !== void 0)
|
|
30604
|
+
applyDurableSelection(row, state.metadata);
|
|
30605
|
+
if (state.quota !== void 0) {
|
|
30606
|
+
const cached = cachedQuotaOf(state.quota);
|
|
30607
|
+
if (cached !== void 0) row.cachedQuota = cached;
|
|
30608
|
+
const updatedAt = present2(state.quota.cachedQuotaUpdatedAt);
|
|
30609
|
+
if (updatedAt !== void 0) row.cachedQuotaUpdatedAt = updatedAt;
|
|
30610
|
+
}
|
|
30611
|
+
}
|
|
30612
|
+
},
|
|
30613
|
+
flush,
|
|
30614
|
+
recordQuota(attribution, quota, signal) {
|
|
30615
|
+
return options.source.commitState(
|
|
30616
|
+
attribution,
|
|
30617
|
+
(current) => ({
|
|
30618
|
+
...current?.metadata !== void 0 ? { metadata: current.metadata } : {},
|
|
30619
|
+
quota,
|
|
30620
|
+
...current?.extensions !== void 0 ? { extensions: current.extensions } : {}
|
|
30621
|
+
}),
|
|
30622
|
+
signal
|
|
30623
|
+
);
|
|
30624
|
+
}
|
|
30625
|
+
};
|
|
30626
|
+
}
|
|
30627
|
+
function createVaultAccountPool(options) {
|
|
30628
|
+
const { source, durable } = options;
|
|
30629
|
+
const state = durable ? createVaultSelectionState({
|
|
30630
|
+
source: durable.source,
|
|
30631
|
+
readState: durable.readState,
|
|
30632
|
+
...options.now ? { now: options.now } : {},
|
|
30633
|
+
...durable.onError ? { onError: durable.onError } : {}
|
|
30634
|
+
}) : void 0;
|
|
30635
|
+
const selector = new AccountSelector({
|
|
30636
|
+
...options.now ? { now: options.now } : {},
|
|
30637
|
+
...state ? { sink: state.sink } : {}
|
|
30638
|
+
});
|
|
30639
|
+
const credentials = createVaultRequestCredentials(
|
|
30640
|
+
source,
|
|
30641
|
+
state && durable ? {
|
|
30642
|
+
source: durable.source,
|
|
30643
|
+
admitted: (row, attribution) => state.admitted(row, attribution)
|
|
30644
|
+
} : void 0
|
|
30645
|
+
);
|
|
30646
|
+
const refusal3 = options.emptyRosterRefusal;
|
|
30647
|
+
if (refusal3)
|
|
30648
|
+
credentials.emptyRosterRefusal = () => refusal3(source.emptyRosterCause?.() ?? "unknown");
|
|
30649
|
+
const rowsFromSource = async () => {
|
|
30650
|
+
const rows = vaultAccountRows(source.routes());
|
|
30651
|
+
if (state) {
|
|
30652
|
+
const kept = new Set(selector.rows.map(vaultAccountRowKey));
|
|
30653
|
+
const added = rows.filter((row) => !kept.has(vaultAccountRowKey(row)));
|
|
30654
|
+
if (added.length > 0) await state.hydrate(added);
|
|
30655
|
+
}
|
|
30656
|
+
return rows;
|
|
30657
|
+
};
|
|
30658
|
+
const replace = async () => {
|
|
30659
|
+
selector.replaceAccounts(await rowsFromSource(), {
|
|
30660
|
+
keyOf: vaultAccountRowKey,
|
|
30661
|
+
refresh: refreshVaultAccountRow
|
|
30662
|
+
});
|
|
30663
|
+
};
|
|
30664
|
+
let firstRead = null;
|
|
30665
|
+
const readOnce = () => {
|
|
30666
|
+
firstRead ??= (async () => {
|
|
30667
|
+
await source.refresh();
|
|
30668
|
+
selector.resetAccounts(await rowsFromSource());
|
|
30669
|
+
})().catch((error) => {
|
|
30670
|
+
firstRead = null;
|
|
30671
|
+
throw error;
|
|
30672
|
+
});
|
|
30673
|
+
return firstRead;
|
|
30674
|
+
};
|
|
30675
|
+
const waitForFirstRoster = async () => {
|
|
30676
|
+
let timer;
|
|
30677
|
+
try {
|
|
30678
|
+
await Promise.race([
|
|
30679
|
+
readOnce(),
|
|
30680
|
+
new Promise((_, reject) => {
|
|
30681
|
+
timer = setTimeout(
|
|
30682
|
+
() => reject(
|
|
30683
|
+
new Error(
|
|
30684
|
+
"The vault roster is not available yet. Check vault access and try the request again."
|
|
30685
|
+
)
|
|
30686
|
+
),
|
|
30687
|
+
2e3
|
|
30688
|
+
);
|
|
30689
|
+
timer.unref?.();
|
|
30690
|
+
})
|
|
30691
|
+
]);
|
|
30692
|
+
} finally {
|
|
30693
|
+
clearTimeout(timer);
|
|
30694
|
+
}
|
|
30695
|
+
};
|
|
30696
|
+
return {
|
|
30697
|
+
selector,
|
|
30698
|
+
credentials,
|
|
30699
|
+
state,
|
|
30700
|
+
async sync() {
|
|
30701
|
+
const pending = firstRead;
|
|
30702
|
+
await waitForFirstRoster();
|
|
30703
|
+
if (pending !== null) await replace();
|
|
30704
|
+
},
|
|
30705
|
+
async refresh() {
|
|
30706
|
+
await waitForFirstRoster();
|
|
30707
|
+
await source.refresh();
|
|
30708
|
+
await replace();
|
|
30709
|
+
},
|
|
30710
|
+
flush: async () => {
|
|
30711
|
+
await state?.flush();
|
|
30712
|
+
}
|
|
30713
|
+
};
|
|
30714
|
+
}
|
|
30715
|
+
function vaultQuotaState(quota, at) {
|
|
30716
|
+
const cachedQuota = {};
|
|
30717
|
+
for (const [name, group] of Object.entries(quota.groups)) {
|
|
30718
|
+
if (group === void 0) continue;
|
|
30719
|
+
cachedQuota[name] = {
|
|
30720
|
+
modelCount: group.modelCount,
|
|
30721
|
+
...group.remainingFraction !== void 0 ? { remainingFraction: group.remainingFraction } : {},
|
|
30722
|
+
...group.resetTime !== void 0 ? { resetTime: group.resetTime } : {},
|
|
30723
|
+
...group.windows !== void 0 ? { windows: group.windows.map((window) => ({ ...window })) } : {}
|
|
30724
|
+
};
|
|
30725
|
+
}
|
|
30726
|
+
return { schemaVersion: 1, cachedQuota, cachedQuotaUpdatedAt: at };
|
|
30727
|
+
}
|
|
30728
|
+
async function checkVaultQuota(input2) {
|
|
30729
|
+
const state = input2.pool.state;
|
|
30730
|
+
const rows = [...input2.pool.selector.rows];
|
|
30731
|
+
const now = input2.now ?? (() => Date.now());
|
|
30732
|
+
let checked = 0;
|
|
30733
|
+
if (state === void 0) input2.onOutcome?.("state-invalid");
|
|
30734
|
+
for (const row of rows) {
|
|
30735
|
+
if (input2.signal.aborted || state === void 0) break;
|
|
30736
|
+
try {
|
|
30737
|
+
input2.onStage?.("fetch");
|
|
30738
|
+
const answer = await input2.fetchReading(row.route, input2.signal);
|
|
30739
|
+
input2.signal.throwIfAborted();
|
|
30740
|
+
const attribution = answer.quotaAttribution;
|
|
30741
|
+
if (answer.quota.error !== void 0) {
|
|
30742
|
+
input2.onOutcome?.("fetch-failed");
|
|
30743
|
+
continue;
|
|
30744
|
+
}
|
|
30745
|
+
if (attribution === void 0) {
|
|
30746
|
+
input2.onOutcome?.("unattributed");
|
|
30747
|
+
continue;
|
|
30748
|
+
}
|
|
30749
|
+
const reading = vaultQuotaState(answer.quota, now());
|
|
30750
|
+
input2.onStage?.("commit");
|
|
30751
|
+
input2.signal.throwIfAborted();
|
|
30752
|
+
const result = await state.recordQuota(attribution, reading, input2.signal);
|
|
30753
|
+
if (result.status !== "written") {
|
|
30754
|
+
input2.onOutcome?.(
|
|
30755
|
+
result.status === "uncertain" ? "write-uncertain" : "commit-unchanged",
|
|
30756
|
+
result.status === "uncertain" ? result.error : void 0
|
|
30757
|
+
);
|
|
30758
|
+
continue;
|
|
30759
|
+
}
|
|
30760
|
+
checked += 1;
|
|
30761
|
+
input2.onOutcome?.("recorded");
|
|
30762
|
+
const live = input2.pool.selector.rows.find(
|
|
30763
|
+
(candidate) => candidate.route.routeId === attribution.routeId && candidate.route.credentialId === attribution.credentialId && candidate.route.accountIdentity === attribution.accountIdentity
|
|
30764
|
+
);
|
|
30765
|
+
if (live !== void 0) {
|
|
30766
|
+
const cached = cachedQuotaOf(reading);
|
|
30767
|
+
if (cached !== void 0) live.cachedQuota = cached;
|
|
30768
|
+
live.cachedQuotaUpdatedAt = reading.cachedQuotaUpdatedAt ?? void 0;
|
|
30769
|
+
}
|
|
30770
|
+
} catch (error) {
|
|
30771
|
+
try {
|
|
30772
|
+
input2.onError?.(error);
|
|
30773
|
+
} catch {
|
|
30774
|
+
}
|
|
30775
|
+
}
|
|
30776
|
+
}
|
|
30777
|
+
return { checked, notChecked: rows.length - checked };
|
|
30778
|
+
}
|
|
30779
|
+
|
|
30780
|
+
// src/plugin/vault-custody.ts
|
|
29717
30781
|
var OPENCODE_VAULT_PROVIDER = "google";
|
|
29718
30782
|
var OPENCODE_VAULT_HOST = "opencode";
|
|
29719
30783
|
var OPENCODE_VAULT_ENROLLMENT_NAME = getAntigravityVaultEnrollmentName(OPENCODE_VAULT_HOST);
|
|
@@ -29857,7 +30921,7 @@ function createOpenCodeVaultCustody(options) {
|
|
|
29857
30921
|
const roster = await (await loadClaustrum()).readVaultRoster(
|
|
29858
30922
|
paths.rosterFile
|
|
29859
30923
|
);
|
|
29860
|
-
return roster?.rows.length === 0 ? noVaultAccountsGuidance() : [];
|
|
30924
|
+
return roster?.rows.length === 0 ? noVaultAccountsGuidance(source?.grantReach()) : [];
|
|
29861
30925
|
} catch {
|
|
29862
30926
|
return [];
|
|
29863
30927
|
}
|
|
@@ -30100,11 +31164,37 @@ function pendingExistsGuidance() {
|
|
|
30100
31164
|
"Or the vault operator clears it now: find its ID with ck auth enroll list, run ck auth enroll deny --request-id <id>, then request vault access again here."
|
|
30101
31165
|
];
|
|
30102
31166
|
}
|
|
30103
|
-
function noVaultAccountsGuidance() {
|
|
30104
|
-
return
|
|
30105
|
-
|
|
30106
|
-
|
|
30107
|
-
|
|
31167
|
+
function noVaultAccountsGuidance(reach) {
|
|
31168
|
+
return emptyRosterGuidance(emptyVaultRosterCause(reach));
|
|
31169
|
+
}
|
|
31170
|
+
function emptyRosterGuidance(cause) {
|
|
31171
|
+
switch (cause) {
|
|
31172
|
+
case "no-grant":
|
|
31173
|
+
return [
|
|
31174
|
+
`Vault access is approved. The vault has not granted ${OPENCODE_VAULT_ENROLLMENT_NAME} read access.`,
|
|
31175
|
+
`The vault operator grants it with: ${OPENCODE_VAULT_GRANT_COMMAND}`
|
|
31176
|
+
];
|
|
31177
|
+
case "grant-reaches-nothing":
|
|
31178
|
+
return [
|
|
31179
|
+
`Vault access is approved. ${OPENCODE_VAULT_ENROLLMENT_NAME} has read access, but it reaches no Antigravity login in the vault.`,
|
|
31180
|
+
`The vault operator updates the vault's logins with: ${VAULT_RECLASSIFY_COMMAND}`,
|
|
31181
|
+
`Then they check them with: ${VAULT_STATUS_COMMAND}`
|
|
31182
|
+
];
|
|
31183
|
+
case "unknown":
|
|
31184
|
+
return [
|
|
31185
|
+
`Vault access is approved, but the vault serves ${OPENCODE_VAULT_ENROLLMENT_NAME} no Antigravity accounts.`,
|
|
31186
|
+
`The vault operator grants read access with: ${OPENCODE_VAULT_GRANT_COMMAND}`
|
|
31187
|
+
];
|
|
31188
|
+
}
|
|
31189
|
+
}
|
|
31190
|
+
function openCodeEmptyVaultRosterRefusal(cause) {
|
|
31191
|
+
return cause === "unknown" ? void 0 : emptyRosterGuidance(cause).join("\n");
|
|
31192
|
+
}
|
|
31193
|
+
function createOpenCodeVaultAccountPool(options) {
|
|
31194
|
+
return createVaultAccountPool({
|
|
31195
|
+
...options,
|
|
31196
|
+
emptyRosterRefusal: openCodeEmptyVaultRosterRefusal
|
|
31197
|
+
});
|
|
30108
31198
|
}
|
|
30109
31199
|
function enrollmentGuidance(status) {
|
|
30110
31200
|
if (status.state === "pending")
|
|
@@ -30758,7 +31848,7 @@ async function runCli(argv, deps) {
|
|
|
30758
31848
|
return 1;
|
|
30759
31849
|
}
|
|
30760
31850
|
}
|
|
30761
|
-
var execFileAsync = promisify(
|
|
31851
|
+
var execFileAsync = promisify(execFile);
|
|
30762
31852
|
async function openBrowserDefault(url) {
|
|
30763
31853
|
if (process.platform === "win32") {
|
|
30764
31854
|
await execFileAsync("cmd", ["/c", "start", "", url]);
|
|
@@ -30876,7 +31966,7 @@ async function persistCliStoreLogin(repository, result, replaceAll) {
|
|
|
30876
31966
|
"Login returned no usable refresh token; no account was saved."
|
|
30877
31967
|
);
|
|
30878
31968
|
}
|
|
30879
|
-
function
|
|
31969
|
+
function present3(value) {
|
|
30880
31970
|
return value === null ? void 0 : value;
|
|
30881
31971
|
}
|
|
30882
31972
|
function cliAccountOf(row) {
|
|
@@ -30890,9 +31980,9 @@ function cliAccountOf(row) {
|
|
|
30890
31980
|
...typeof group.resetTime === "string" ? { resetTime: group.resetTime } : {}
|
|
30891
31981
|
};
|
|
30892
31982
|
}
|
|
30893
|
-
const email =
|
|
30894
|
-
const projectId =
|
|
30895
|
-
const managedProjectId =
|
|
31983
|
+
const email = present3(metadata?.email);
|
|
31984
|
+
const projectId = present3(metadata?.projectId);
|
|
31985
|
+
const managedProjectId = present3(metadata?.managedProjectId);
|
|
30896
31986
|
return {
|
|
30897
31987
|
refreshToken: row.credential?.refreshToken ?? "",
|
|
30898
31988
|
addedAt: metadata?.addedAt ?? row.storeAddedAt ?? 0,
|
|
@@ -31933,14 +33023,14 @@ function parsePending(value) {
|
|
|
31933
33023
|
}
|
|
31934
33024
|
|
|
31935
33025
|
// src/plugin/account-blocks.ts
|
|
31936
|
-
function
|
|
33026
|
+
function present4(value) {
|
|
31937
33027
|
return value === null ? void 0 : value;
|
|
31938
33028
|
}
|
|
31939
33029
|
function accessBlockOf(fields) {
|
|
31940
33030
|
if (fields === void 0) return { kind: "none" };
|
|
31941
33031
|
if (fields.accountIneligible === true) {
|
|
31942
|
-
const reason =
|
|
31943
|
-
const at =
|
|
33032
|
+
const reason = present4(fields.accountIneligibleReason);
|
|
33033
|
+
const at = present4(fields.accountIneligibleAt);
|
|
31944
33034
|
return {
|
|
31945
33035
|
kind: "ineligible",
|
|
31946
33036
|
...reason !== void 0 ? { reason } : {},
|
|
@@ -31948,9 +33038,9 @@ function accessBlockOf(fields) {
|
|
|
31948
33038
|
};
|
|
31949
33039
|
}
|
|
31950
33040
|
if (fields.verificationRequired === true) {
|
|
31951
|
-
const reason =
|
|
31952
|
-
const verificationUrl =
|
|
31953
|
-
const at =
|
|
33041
|
+
const reason = present4(fields.verificationRequiredReason);
|
|
33042
|
+
const verificationUrl = present4(fields.verificationUrl);
|
|
33043
|
+
const at = present4(fields.verificationRequiredAt);
|
|
31954
33044
|
return {
|
|
31955
33045
|
kind: "verification-required",
|
|
31956
33046
|
...reason !== void 0 ? { reason } : {},
|
|
@@ -36249,7 +37339,8 @@ var AntigravityConfigSchema = z.object({
|
|
|
36249
37339
|
// Rate Limiting
|
|
36250
37340
|
// =========================================================================
|
|
36251
37341
|
/**
|
|
36252
|
-
*
|
|
37342
|
+
* Cumulative wait budget in seconds while no account is eligible, shared by
|
|
37343
|
+
* rate-limit and soft-quota waits. Selecting an eligible account resets it.
|
|
36253
37344
|
* If the minimum wait time across all accounts exceeds this threshold,
|
|
36254
37345
|
* the plugin fails fast with an error instead of hanging.
|
|
36255
37346
|
*
|
|
@@ -37406,9 +38497,7 @@ function hashText2(value) {
|
|
|
37406
38497
|
return createHash14("sha256").update(value).digest("hex");
|
|
37407
38498
|
}
|
|
37408
38499
|
function maskIdentifier(value) {
|
|
37409
|
-
|
|
37410
|
-
if (value.length <= 8) return "****";
|
|
37411
|
-
return `${value.slice(0, 4)}****${value.slice(-4)}`;
|
|
38500
|
+
return maskSensitiveIdentifier(value) || void 0;
|
|
37412
38501
|
}
|
|
37413
38502
|
function redactProjectId(value) {
|
|
37414
38503
|
return maskIdentifier(value);
|
|
@@ -40526,7 +41615,6 @@ function prepareAntigravityRequestIn(wire, input2, init, accessToken, projectId,
|
|
|
40526
41615
|
let resolvedProjectId = projectId?.trim() || "";
|
|
40527
41616
|
let toolDebugMissing = 0;
|
|
40528
41617
|
const toolDebugSummaries = [];
|
|
40529
|
-
let toolDebugPayload;
|
|
40530
41618
|
let sessionId;
|
|
40531
41619
|
let needsSignedThinkingWarmup = false;
|
|
40532
41620
|
let thinkingRecoveryMessage;
|
|
@@ -40954,11 +42042,6 @@ function prepareAntigravityRequestIn(wire, input2, init, accessToken, projectId,
|
|
|
40954
42042
|
toolDebugMissing = geminiResult.toolDebugMissing;
|
|
40955
42043
|
toolDebugSummaries.push(...geminiResult.toolDebugSummaries);
|
|
40956
42044
|
}
|
|
40957
|
-
try {
|
|
40958
|
-
toolDebugPayload = JSON.stringify(requestPayload.tools);
|
|
40959
|
-
} catch {
|
|
40960
|
-
toolDebugPayload = void 0;
|
|
40961
|
-
}
|
|
40962
42045
|
const enableToolHardening = options?.claudeToolHardening ?? true;
|
|
40963
42046
|
if (enableToolHardening && isClaude && Array.isArray(requestPayload.tools) && requestPayload.tools.length > 0) {
|
|
40964
42047
|
requestPayload.tools = injectParameterSignatures(
|
|
@@ -41196,7 +42279,6 @@ function prepareAntigravityRequestIn(wire, input2, init, accessToken, projectId,
|
|
|
41196
42279
|
sessionId,
|
|
41197
42280
|
toolDebugMissing,
|
|
41198
42281
|
toolDebugSummary: toolDebugSummaries.slice(0, 20).join(" | "),
|
|
41199
|
-
toolDebugPayload,
|
|
41200
42282
|
needsSignedThinkingWarmup,
|
|
41201
42283
|
headerStyle: "antigravity",
|
|
41202
42284
|
thinkingRecoveryMessage
|
|
@@ -41264,7 +42346,7 @@ function buildThinkingWarmupBody(bodyText, isClaudeThinking) {
|
|
|
41264
42346
|
}
|
|
41265
42347
|
return safeStringify(parsed);
|
|
41266
42348
|
}
|
|
41267
|
-
async function transformAntigravityResponseIn(wire, response, streaming, debugContext, requestedModel, projectId, endpoint, effectiveModel, sessionId, toolDebugMissing, toolDebugSummary,
|
|
42349
|
+
async function transformAntigravityResponseIn(wire, response, streaming, debugContext, requestedModel, projectId, endpoint, effectiveModel, sessionId, toolDebugMissing, toolDebugSummary, debugLines, dumpContext) {
|
|
41268
42350
|
const contentType = response.headers.get("content-type") ?? "";
|
|
41269
42351
|
const isJsonResponse = contentType.includes("application/json");
|
|
41270
42352
|
const isEventStreamResponse = contentType.includes("text/event-stream");
|
|
@@ -41337,20 +42419,23 @@ async function transformAntigravityResponseIn(wire, response, streaming, debugCo
|
|
|
41337
42419
|
errorBody = { error: { message: text2 } };
|
|
41338
42420
|
}
|
|
41339
42421
|
if (errorBody?.error) {
|
|
41340
|
-
const
|
|
42422
|
+
const upstreamErrorMessage = typeof errorBody.error.message === "string" && errorBody.error.message.length > 0 ? errorBody.error.message : "Unknown error";
|
|
42423
|
+
const rawErrorMessage = redactProjectIdText(upstreamErrorMessage, [
|
|
42424
|
+
projectId ?? ""
|
|
42425
|
+
]);
|
|
41341
42426
|
const errorType = detectErrorType(rawErrorMessage);
|
|
42427
|
+
const safeProjectId = maskSensitiveIdentifier(projectId) || "Unknown";
|
|
41342
42428
|
const debugInfo = `
|
|
41343
42429
|
|
|
41344
42430
|
[Debug Info]
|
|
41345
42431
|
Requested Model: ${requestedModel || "Unknown"}
|
|
41346
42432
|
Effective Model: ${effectiveModel || "Unknown"}
|
|
41347
|
-
Project: ${
|
|
42433
|
+
Project: ${safeProjectId}
|
|
41348
42434
|
Endpoint: ${endpoint || "Unknown"}
|
|
41349
42435
|
Status: ${response.status}
|
|
41350
42436
|
Request ID: ${headers.get("x-request-id") || "N/A"}${toolDebugMissing !== void 0 ? `
|
|
41351
42437
|
Tool Debug Missing: ${toolDebugMissing}` : ""}${toolDebugSummary ? `
|
|
41352
|
-
Tool Debug Summary: ${toolDebugSummary}` : ""}
|
|
41353
|
-
Tool Debug Payload: ${toolDebugPayload}` : ""}`;
|
|
42438
|
+
Tool Debug Summary: ${toolDebugSummary}` : ""}`;
|
|
41354
42439
|
const injectedDebug = debugText ? `
|
|
41355
42440
|
|
|
41356
42441
|
${debugText}` : "";
|
|
@@ -42241,393 +43326,6 @@ function vaultQuotaErrorKind(error) {
|
|
|
42241
43326
|
return vaultQuotaErrorReason(error, "fetch-failed") === "fetch-failed" ? "unknown" : vaultQuotaErrorReason(error, "fetch-failed");
|
|
42242
43327
|
}
|
|
42243
43328
|
|
|
42244
|
-
// src/plugin/shared/vault-request-credentials.ts
|
|
42245
|
-
function vaultAccountRows(routes) {
|
|
42246
|
-
return routes.map((route, index) => ({
|
|
42247
|
-
index,
|
|
42248
|
-
enabled: true,
|
|
42249
|
-
lastUsed: 0,
|
|
42250
|
-
rateLimitResetTimes: {},
|
|
42251
|
-
touchedForQuota: {},
|
|
42252
|
-
route,
|
|
42253
|
-
...route.email !== void 0 ? { email: route.email } : {}
|
|
42254
|
-
}));
|
|
42255
|
-
}
|
|
42256
|
-
function vaultAccountRowKey(row) {
|
|
42257
|
-
return JSON.stringify([
|
|
42258
|
-
row.route.routeId,
|
|
42259
|
-
row.route.credentialId,
|
|
42260
|
-
row.route.accountIdentity
|
|
42261
|
-
]);
|
|
42262
|
-
}
|
|
42263
|
-
function refreshVaultAccountRow(prior, fresh) {
|
|
42264
|
-
prior.route = fresh.route;
|
|
42265
|
-
if (fresh.email === void 0) delete prior.email;
|
|
42266
|
-
else prior.email = fresh.email;
|
|
42267
|
-
}
|
|
42268
|
-
var VaultSendGrant = class {
|
|
42269
|
-
credentialId;
|
|
42270
|
-
accountIdentity;
|
|
42271
|
-
recordVersion;
|
|
42272
|
-
projectId;
|
|
42273
|
-
report401;
|
|
42274
|
-
constructor(admission, report) {
|
|
42275
|
-
Object.defineProperty(this, "accessToken", {
|
|
42276
|
-
value: admission.accessToken,
|
|
42277
|
-
enumerable: false
|
|
42278
|
-
});
|
|
42279
|
-
this.credentialId = admission.credentialId;
|
|
42280
|
-
this.accountIdentity = admission.accountIdentity;
|
|
42281
|
-
this.recordVersion = admission.recordVersion;
|
|
42282
|
-
this.projectId = admission.projectId;
|
|
42283
|
-
this.report401 = report;
|
|
42284
|
-
}
|
|
42285
|
-
};
|
|
42286
|
-
function createVaultRequestCredentials(source, onAdmitted) {
|
|
42287
|
-
return {
|
|
42288
|
-
domain: "vault",
|
|
42289
|
-
async admit({ account, signal }) {
|
|
42290
|
-
const admission = await source.admit(account.route, signal);
|
|
42291
|
-
if (onAdmitted)
|
|
42292
|
-
onAdmitted.admitted(account, onAdmitted.source.attribution(admission));
|
|
42293
|
-
return new VaultSendGrant(
|
|
42294
|
-
admission,
|
|
42295
|
-
(status) => source.reportServedStatus(admission, status)
|
|
42296
|
-
);
|
|
42297
|
-
}
|
|
42298
|
-
};
|
|
42299
|
-
}
|
|
42300
|
-
function present4(value) {
|
|
42301
|
-
return value === null ? void 0 : value;
|
|
42302
|
-
}
|
|
42303
|
-
function storedResets(resets) {
|
|
42304
|
-
const stored = {};
|
|
42305
|
-
for (const [key, at] of Object.entries(resets))
|
|
42306
|
-
if (typeof at === "number") stored[key] = at;
|
|
42307
|
-
return stored;
|
|
42308
|
-
}
|
|
42309
|
-
function cachedQuotaOf(quota) {
|
|
42310
|
-
const groups = quota.cachedQuota;
|
|
42311
|
-
if (groups == null) return void 0;
|
|
42312
|
-
const out = {};
|
|
42313
|
-
for (const name of ["gemini", "non-gemini"]) {
|
|
42314
|
-
const group = groups[name];
|
|
42315
|
-
if (group === void 0) continue;
|
|
42316
|
-
out[name] = {
|
|
42317
|
-
modelCount: group.modelCount,
|
|
42318
|
-
...group.remainingFraction != null ? { remainingFraction: group.remainingFraction } : {},
|
|
42319
|
-
...group.resetTime != null ? { resetTime: group.resetTime } : {},
|
|
42320
|
-
...group.windows != null ? {
|
|
42321
|
-
windows: group.windows.map((window) => ({
|
|
42322
|
-
window: window.window,
|
|
42323
|
-
remainingFraction: window.remainingFraction,
|
|
42324
|
-
resetTime: window.resetTime
|
|
42325
|
-
}))
|
|
42326
|
-
} : {}
|
|
42327
|
-
};
|
|
42328
|
-
}
|
|
42329
|
-
return out;
|
|
42330
|
-
}
|
|
42331
|
-
function durableSelectionOf(row) {
|
|
42332
|
-
return {
|
|
42333
|
-
lastUsed: row.lastUsed,
|
|
42334
|
-
...row.lastSwitchReason !== void 0 ? { lastSwitchReason: row.lastSwitchReason } : {},
|
|
42335
|
-
rateLimitResetTimes: storedResets(row.rateLimitResetTimes),
|
|
42336
|
-
...row.coolingDownUntil !== void 0 ? { coolingDownUntil: row.coolingDownUntil } : {},
|
|
42337
|
-
...row.cooldownReason !== void 0 ? { cooldownReason: row.cooldownReason } : {},
|
|
42338
|
-
...row.fingerprint !== void 0 ? { fingerprint: structuredClone(row.fingerprint) } : {},
|
|
42339
|
-
...row.fingerprintHistory !== void 0 ? { fingerprintHistory: structuredClone(row.fingerprintHistory) } : {},
|
|
42340
|
-
...row.verificationRequired !== void 0 ? { verificationRequired: row.verificationRequired } : {},
|
|
42341
|
-
...row.verificationRequiredAt !== void 0 ? { verificationRequiredAt: row.verificationRequiredAt } : {},
|
|
42342
|
-
...row.verificationRequiredReason !== void 0 ? { verificationRequiredReason: row.verificationRequiredReason } : {},
|
|
42343
|
-
...row.verificationUrl !== void 0 ? { verificationUrl: row.verificationUrl } : {},
|
|
42344
|
-
...row.accountIneligible !== void 0 ? { accountIneligible: row.accountIneligible } : {},
|
|
42345
|
-
...row.accountIneligibleAt !== void 0 ? { accountIneligibleAt: row.accountIneligibleAt } : {},
|
|
42346
|
-
...row.accountIneligibleReason !== void 0 ? { accountIneligibleReason: row.accountIneligibleReason } : {},
|
|
42347
|
-
...row.eligibilityStateUpdatedAt !== void 0 ? { eligibilityStateUpdatedAt: row.eligibilityStateUpdatedAt } : {},
|
|
42348
|
-
...row.dailyRequestCounts !== void 0 ? { dailyRequestCounts: { ...row.dailyRequestCounts } } : {}
|
|
42349
|
-
};
|
|
42350
|
-
}
|
|
42351
|
-
function applyDurableSelection(row, metadata) {
|
|
42352
|
-
row.lastUsed = metadata.lastUsed;
|
|
42353
|
-
const reason = present4(metadata.lastSwitchReason);
|
|
42354
|
-
if (reason !== void 0) row.lastSwitchReason = reason;
|
|
42355
|
-
const resets = present4(metadata.rateLimitResetTimes);
|
|
42356
|
-
if (resets !== void 0) {
|
|
42357
|
-
const copy = {};
|
|
42358
|
-
for (const [key, at] of Object.entries(resets))
|
|
42359
|
-
if (typeof at === "number") copy[key] = at;
|
|
42360
|
-
row.rateLimitResetTimes = copy;
|
|
42361
|
-
}
|
|
42362
|
-
const until = present4(metadata.coolingDownUntil);
|
|
42363
|
-
const cooldownReason = present4(metadata.cooldownReason);
|
|
42364
|
-
if (until !== void 0 && cooldownReason !== void 0) {
|
|
42365
|
-
row.coolingDownUntil = until;
|
|
42366
|
-
row.cooldownReason = cooldownReason;
|
|
42367
|
-
}
|
|
42368
|
-
const fingerprint = present4(metadata.fingerprint);
|
|
42369
|
-
if (fingerprint !== void 0) row.fingerprint = structuredClone(fingerprint);
|
|
42370
|
-
const history = present4(metadata.fingerprintHistory);
|
|
42371
|
-
if (history !== void 0) row.fingerprintHistory = structuredClone(history);
|
|
42372
|
-
const verification = present4(metadata.verificationRequired);
|
|
42373
|
-
if (verification !== void 0) row.verificationRequired = verification;
|
|
42374
|
-
const verificationAt = present4(metadata.verificationRequiredAt);
|
|
42375
|
-
if (verificationAt !== void 0) row.verificationRequiredAt = verificationAt;
|
|
42376
|
-
const verificationReason = present4(metadata.verificationRequiredReason);
|
|
42377
|
-
if (verificationReason !== void 0)
|
|
42378
|
-
row.verificationRequiredReason = verificationReason;
|
|
42379
|
-
const verificationUrl = present4(metadata.verificationUrl);
|
|
42380
|
-
if (verificationUrl !== void 0) row.verificationUrl = verificationUrl;
|
|
42381
|
-
const ineligible = present4(metadata.accountIneligible);
|
|
42382
|
-
if (ineligible !== void 0) row.accountIneligible = ineligible;
|
|
42383
|
-
const ineligibleAt = present4(metadata.accountIneligibleAt);
|
|
42384
|
-
if (ineligibleAt !== void 0) row.accountIneligibleAt = ineligibleAt;
|
|
42385
|
-
const ineligibleReason = present4(metadata.accountIneligibleReason);
|
|
42386
|
-
if (ineligibleReason !== void 0)
|
|
42387
|
-
row.accountIneligibleReason = ineligibleReason;
|
|
42388
|
-
const eligibilityAt = present4(metadata.eligibilityStateUpdatedAt);
|
|
42389
|
-
if (eligibilityAt !== void 0) row.eligibilityStateUpdatedAt = eligibilityAt;
|
|
42390
|
-
const counts = present4(metadata.dailyRequestCounts);
|
|
42391
|
-
if (counts !== void 0) row.dailyRequestCounts = { ...counts };
|
|
42392
|
-
}
|
|
42393
|
-
function stateBelongsTo(state, row) {
|
|
42394
|
-
return state.observed.routeId === row.route.routeId && state.observed.credentialId === row.route.credentialId;
|
|
42395
|
-
}
|
|
42396
|
-
function createVaultSelectionState(options) {
|
|
42397
|
-
const now = options.now ?? (() => Date.now());
|
|
42398
|
-
const attributions = /* @__PURE__ */ new WeakMap();
|
|
42399
|
-
const changed = /* @__PURE__ */ new Set();
|
|
42400
|
-
let writing = Promise.resolve();
|
|
42401
|
-
const mark = (row) => {
|
|
42402
|
-
changed.add(row);
|
|
42403
|
-
};
|
|
42404
|
-
const report = (error) => {
|
|
42405
|
-
try {
|
|
42406
|
-
options.onError?.(error);
|
|
42407
|
-
} catch {
|
|
42408
|
-
}
|
|
42409
|
-
};
|
|
42410
|
-
const writeRow = async (row) => {
|
|
42411
|
-
const attribution = attributions.get(row);
|
|
42412
|
-
if (attribution === void 0) return;
|
|
42413
|
-
changed.delete(row);
|
|
42414
|
-
const selection = durableSelectionOf(row);
|
|
42415
|
-
try {
|
|
42416
|
-
await options.source.commitState(attribution, (current) => ({
|
|
42417
|
-
metadata: {
|
|
42418
|
-
...current?.metadata ?? { addedAt: now() },
|
|
42419
|
-
...selection
|
|
42420
|
-
},
|
|
42421
|
-
...current?.quota !== void 0 ? { quota: current.quota } : {},
|
|
42422
|
-
...current?.extensions !== void 0 ? { extensions: current.extensions } : {}
|
|
42423
|
-
}));
|
|
42424
|
-
} catch (error) {
|
|
42425
|
-
report(error);
|
|
42426
|
-
}
|
|
42427
|
-
};
|
|
42428
|
-
const flush = () => {
|
|
42429
|
-
writing = writing.then(async () => {
|
|
42430
|
-
for (const row of [...changed]) await writeRow(row);
|
|
42431
|
-
});
|
|
42432
|
-
return writing;
|
|
42433
|
-
};
|
|
42434
|
-
return {
|
|
42435
|
-
sink: {
|
|
42436
|
-
rateLimit: mark,
|
|
42437
|
-
cooldown: mark,
|
|
42438
|
-
switched: mark,
|
|
42439
|
-
lastUsed: mark,
|
|
42440
|
-
usage: mark,
|
|
42441
|
-
accessVerdict: mark,
|
|
42442
|
-
fingerprint: mark,
|
|
42443
|
-
requestSave: () => {
|
|
42444
|
-
void flush();
|
|
42445
|
-
}
|
|
42446
|
-
},
|
|
42447
|
-
admitted(row, attribution) {
|
|
42448
|
-
attributions.set(row, attribution);
|
|
42449
|
-
},
|
|
42450
|
-
async hydrate(rows) {
|
|
42451
|
-
const file = await options.readState();
|
|
42452
|
-
for (const row of rows) {
|
|
42453
|
-
const identity = row.route.accountIdentity;
|
|
42454
|
-
if (!Object.hasOwn(file.accounts, identity)) continue;
|
|
42455
|
-
const state = file.accounts[identity];
|
|
42456
|
-
if (state === void 0 || !stateBelongsTo(state, row)) continue;
|
|
42457
|
-
if (state.metadata !== void 0)
|
|
42458
|
-
applyDurableSelection(row, state.metadata);
|
|
42459
|
-
if (state.quota !== void 0) {
|
|
42460
|
-
const cached = cachedQuotaOf(state.quota);
|
|
42461
|
-
if (cached !== void 0) row.cachedQuota = cached;
|
|
42462
|
-
const updatedAt = present4(state.quota.cachedQuotaUpdatedAt);
|
|
42463
|
-
if (updatedAt !== void 0) row.cachedQuotaUpdatedAt = updatedAt;
|
|
42464
|
-
}
|
|
42465
|
-
}
|
|
42466
|
-
},
|
|
42467
|
-
flush,
|
|
42468
|
-
recordQuota(attribution, quota, signal) {
|
|
42469
|
-
return options.source.commitState(
|
|
42470
|
-
attribution,
|
|
42471
|
-
(current) => ({
|
|
42472
|
-
...current?.metadata !== void 0 ? { metadata: current.metadata } : {},
|
|
42473
|
-
quota,
|
|
42474
|
-
...current?.extensions !== void 0 ? { extensions: current.extensions } : {}
|
|
42475
|
-
}),
|
|
42476
|
-
signal
|
|
42477
|
-
);
|
|
42478
|
-
}
|
|
42479
|
-
};
|
|
42480
|
-
}
|
|
42481
|
-
function createVaultAccountPool(options) {
|
|
42482
|
-
const { source, durable } = options;
|
|
42483
|
-
const state = durable ? createVaultSelectionState({
|
|
42484
|
-
source: durable.source,
|
|
42485
|
-
readState: durable.readState,
|
|
42486
|
-
...options.now ? { now: options.now } : {},
|
|
42487
|
-
...durable.onError ? { onError: durable.onError } : {}
|
|
42488
|
-
}) : void 0;
|
|
42489
|
-
const selector = new AccountSelector({
|
|
42490
|
-
...options.now ? { now: options.now } : {},
|
|
42491
|
-
...state ? { sink: state.sink } : {}
|
|
42492
|
-
});
|
|
42493
|
-
const credentials = createVaultRequestCredentials(
|
|
42494
|
-
source,
|
|
42495
|
-
state && durable ? {
|
|
42496
|
-
source: durable.source,
|
|
42497
|
-
admitted: (row, attribution) => state.admitted(row, attribution)
|
|
42498
|
-
} : void 0
|
|
42499
|
-
);
|
|
42500
|
-
const rowsFromSource = async () => {
|
|
42501
|
-
const rows = vaultAccountRows(source.routes());
|
|
42502
|
-
if (state) {
|
|
42503
|
-
const kept = new Set(selector.rows.map(vaultAccountRowKey));
|
|
42504
|
-
const added = rows.filter((row) => !kept.has(vaultAccountRowKey(row)));
|
|
42505
|
-
if (added.length > 0) await state.hydrate(added);
|
|
42506
|
-
}
|
|
42507
|
-
return rows;
|
|
42508
|
-
};
|
|
42509
|
-
const replace = async () => {
|
|
42510
|
-
selector.replaceAccounts(await rowsFromSource(), {
|
|
42511
|
-
keyOf: vaultAccountRowKey,
|
|
42512
|
-
refresh: refreshVaultAccountRow
|
|
42513
|
-
});
|
|
42514
|
-
};
|
|
42515
|
-
let firstRead = null;
|
|
42516
|
-
const readOnce = () => {
|
|
42517
|
-
firstRead ??= (async () => {
|
|
42518
|
-
await source.refresh();
|
|
42519
|
-
selector.resetAccounts(await rowsFromSource());
|
|
42520
|
-
})().catch((error) => {
|
|
42521
|
-
firstRead = null;
|
|
42522
|
-
throw error;
|
|
42523
|
-
});
|
|
42524
|
-
return firstRead;
|
|
42525
|
-
};
|
|
42526
|
-
const waitForFirstRoster = async () => {
|
|
42527
|
-
let timer;
|
|
42528
|
-
try {
|
|
42529
|
-
await Promise.race([
|
|
42530
|
-
readOnce(),
|
|
42531
|
-
new Promise((_, reject) => {
|
|
42532
|
-
timer = setTimeout(
|
|
42533
|
-
() => reject(
|
|
42534
|
-
new Error(
|
|
42535
|
-
"The vault roster is not available yet. Check vault access and try the request again."
|
|
42536
|
-
)
|
|
42537
|
-
),
|
|
42538
|
-
2e3
|
|
42539
|
-
);
|
|
42540
|
-
timer.unref?.();
|
|
42541
|
-
})
|
|
42542
|
-
]);
|
|
42543
|
-
} finally {
|
|
42544
|
-
clearTimeout(timer);
|
|
42545
|
-
}
|
|
42546
|
-
};
|
|
42547
|
-
return {
|
|
42548
|
-
selector,
|
|
42549
|
-
credentials,
|
|
42550
|
-
state,
|
|
42551
|
-
async sync() {
|
|
42552
|
-
const pending = firstRead;
|
|
42553
|
-
await waitForFirstRoster();
|
|
42554
|
-
if (pending !== null) await replace();
|
|
42555
|
-
},
|
|
42556
|
-
async refresh() {
|
|
42557
|
-
await waitForFirstRoster();
|
|
42558
|
-
await source.refresh();
|
|
42559
|
-
await replace();
|
|
42560
|
-
},
|
|
42561
|
-
flush: async () => {
|
|
42562
|
-
await state?.flush();
|
|
42563
|
-
}
|
|
42564
|
-
};
|
|
42565
|
-
}
|
|
42566
|
-
function vaultQuotaState(quota, at) {
|
|
42567
|
-
const cachedQuota = {};
|
|
42568
|
-
for (const [name, group] of Object.entries(quota.groups)) {
|
|
42569
|
-
if (group === void 0) continue;
|
|
42570
|
-
cachedQuota[name] = {
|
|
42571
|
-
modelCount: group.modelCount,
|
|
42572
|
-
...group.remainingFraction !== void 0 ? { remainingFraction: group.remainingFraction } : {},
|
|
42573
|
-
...group.resetTime !== void 0 ? { resetTime: group.resetTime } : {},
|
|
42574
|
-
...group.windows !== void 0 ? { windows: group.windows.map((window) => ({ ...window })) } : {}
|
|
42575
|
-
};
|
|
42576
|
-
}
|
|
42577
|
-
return { schemaVersion: 1, cachedQuota, cachedQuotaUpdatedAt: at };
|
|
42578
|
-
}
|
|
42579
|
-
async function checkVaultQuota(input2) {
|
|
42580
|
-
const state = input2.pool.state;
|
|
42581
|
-
const rows = [...input2.pool.selector.rows];
|
|
42582
|
-
const now = input2.now ?? (() => Date.now());
|
|
42583
|
-
let checked = 0;
|
|
42584
|
-
if (state === void 0) input2.onOutcome?.("state-invalid");
|
|
42585
|
-
for (const row of rows) {
|
|
42586
|
-
if (input2.signal.aborted || state === void 0) break;
|
|
42587
|
-
try {
|
|
42588
|
-
input2.onStage?.("fetch");
|
|
42589
|
-
const answer = await input2.fetchReading(row.route, input2.signal);
|
|
42590
|
-
input2.signal.throwIfAborted();
|
|
42591
|
-
const attribution = answer.quotaAttribution;
|
|
42592
|
-
if (answer.quota.error !== void 0) {
|
|
42593
|
-
input2.onOutcome?.("fetch-failed");
|
|
42594
|
-
continue;
|
|
42595
|
-
}
|
|
42596
|
-
if (attribution === void 0) {
|
|
42597
|
-
input2.onOutcome?.("unattributed");
|
|
42598
|
-
continue;
|
|
42599
|
-
}
|
|
42600
|
-
const reading = vaultQuotaState(answer.quota, now());
|
|
42601
|
-
input2.onStage?.("commit");
|
|
42602
|
-
input2.signal.throwIfAborted();
|
|
42603
|
-
const result = await state.recordQuota(attribution, reading, input2.signal);
|
|
42604
|
-
if (result.status !== "written") {
|
|
42605
|
-
input2.onOutcome?.(
|
|
42606
|
-
result.status === "uncertain" ? "write-uncertain" : "commit-unchanged",
|
|
42607
|
-
result.status === "uncertain" ? result.error : void 0
|
|
42608
|
-
);
|
|
42609
|
-
continue;
|
|
42610
|
-
}
|
|
42611
|
-
checked += 1;
|
|
42612
|
-
input2.onOutcome?.("recorded");
|
|
42613
|
-
const live = input2.pool.selector.rows.find(
|
|
42614
|
-
(candidate) => candidate.route.routeId === attribution.routeId && candidate.route.credentialId === attribution.credentialId && candidate.route.accountIdentity === attribution.accountIdentity
|
|
42615
|
-
);
|
|
42616
|
-
if (live !== void 0) {
|
|
42617
|
-
const cached = cachedQuotaOf(reading);
|
|
42618
|
-
if (cached !== void 0) live.cachedQuota = cached;
|
|
42619
|
-
live.cachedQuotaUpdatedAt = reading.cachedQuotaUpdatedAt ?? void 0;
|
|
42620
|
-
}
|
|
42621
|
-
} catch (error) {
|
|
42622
|
-
try {
|
|
42623
|
-
input2.onError?.(error);
|
|
42624
|
-
} catch {
|
|
42625
|
-
}
|
|
42626
|
-
}
|
|
42627
|
-
}
|
|
42628
|
-
return { checked, notChecked: rows.length - checked };
|
|
42629
|
-
}
|
|
42630
|
-
|
|
42631
43329
|
// src/plugin/vault-quota-refresh.ts
|
|
42632
43330
|
async function checkAndPublishVaultQuota(input2, publishSidebar) {
|
|
42633
43331
|
const report = await checkVaultQuota(input2);
|
|
@@ -43618,7 +44316,7 @@ function resolvePluginDependencies(overrides = {}) {
|
|
|
43618
44316
|
authorize: overrides.oauth?.authorize ?? authorizeAntigravity,
|
|
43619
44317
|
exchange: overrides.oauth?.exchange ?? exchangeAntigravity
|
|
43620
44318
|
};
|
|
43621
|
-
const
|
|
44319
|
+
const clock2 = {
|
|
43622
44320
|
now: overrides.clock?.now ?? (() => Date.now()),
|
|
43623
44321
|
random: overrides.clock?.random ?? Math.random,
|
|
43624
44322
|
sleep: overrides.clock?.sleep ?? defaultSleep
|
|
@@ -43628,7 +44326,7 @@ function resolvePluginDependencies(overrides = {}) {
|
|
|
43628
44326
|
agyTransport,
|
|
43629
44327
|
filesystemRoots: roots,
|
|
43630
44328
|
oauth,
|
|
43631
|
-
clock
|
|
44329
|
+
clock: clock2
|
|
43632
44330
|
};
|
|
43633
44331
|
}
|
|
43634
44332
|
async function defaultSleep(ms, signal) {
|
|
@@ -44583,12 +45281,11 @@ function createRequestExecutor(deps) {
|
|
|
44583
45281
|
log16.debug("routing-report-failed", { sessionId, error: String(error) });
|
|
44584
45282
|
}
|
|
44585
45283
|
};
|
|
44586
|
-
async function execute(input2, init, options
|
|
45284
|
+
async function execute(input2, init, options, selectedCredentials, selectedProjectIds, deadline, waitPolicy) {
|
|
44587
45285
|
const assertAdmission = async () => {
|
|
44588
|
-
|
|
44589
|
-
await deps.assertAdmission?.();
|
|
44590
|
-
init?.signal?.throwIfAborted();
|
|
45286
|
+
await deadline.wait(() => deps.assertAdmission?.());
|
|
44591
45287
|
};
|
|
45288
|
+
const logResponseBody2 = (...args) => deadline.wait(() => debug.logResponseBody(...args));
|
|
44592
45289
|
await assertAdmission();
|
|
44593
45290
|
if (typeof input2 !== "string") {
|
|
44594
45291
|
if (input2 instanceof Request) {
|
|
@@ -44599,7 +45296,7 @@ function createRequestExecutor(deps) {
|
|
|
44599
45296
|
headers.set(k, v);
|
|
44600
45297
|
});
|
|
44601
45298
|
}
|
|
44602
|
-
const bodyBuffer = req.body ? await req.clone().arrayBuffer() : void 0;
|
|
45299
|
+
const bodyBuffer = req.body ? await deadline.wait(() => req.clone().arrayBuffer()) : void 0;
|
|
44603
45300
|
init = {
|
|
44604
45301
|
method: init?.method ?? req.method,
|
|
44605
45302
|
headers,
|
|
@@ -44651,7 +45348,10 @@ function createRequestExecutor(deps) {
|
|
|
44651
45348
|
thinkingBudget: registered.thinkingConfig?.thinkingBudget
|
|
44652
45349
|
};
|
|
44653
45350
|
}
|
|
44654
|
-
const
|
|
45351
|
+
const sender = options.transport ?? defaultTransport2;
|
|
45352
|
+
const transport = (url, sendInit, sendOptions) => deadline.open(
|
|
45353
|
+
() => sender(url, sendInit, { ...sendOptions, signal: deadline.signal })
|
|
45354
|
+
);
|
|
44655
45355
|
const requestSessionIdentity = options.session ?? extractOpenCodeSessionIdentity(init?.headers);
|
|
44656
45356
|
const agyRequestScope = agySessionRegistry.beginRequest(
|
|
44657
45357
|
agyMetadataIdentity(requestSessionIdentity, kind)
|
|
@@ -44666,7 +45366,7 @@ function createRequestExecutor(deps) {
|
|
|
44666
45366
|
const urlString2 = typeof input2 === "string" ? input2 : toUrlString(input2);
|
|
44667
45367
|
const modelFromUrl = extractModelFromUrl(urlString2) ?? "unknown";
|
|
44668
45368
|
return createNoAccountResponse(
|
|
44669
|
-
credentials.domain === "vault" ? VAULT_ACCOUNT_REMEDY : "No Antigravity accounts configured. Run `opencode auth login`.",
|
|
45369
|
+
credentials.domain === "vault" ? credentials.emptyRosterRefusal?.() ?? VAULT_ACCOUNT_REMEDY : "No Antigravity accounts configured. Run `opencode auth login`.",
|
|
44670
45370
|
modelFromUrl
|
|
44671
45371
|
);
|
|
44672
45372
|
}
|
|
@@ -44676,7 +45376,13 @@ function createRequestExecutor(deps) {
|
|
|
44676
45376
|
const debugLines = [];
|
|
44677
45377
|
const pushDebug = (line) => {
|
|
44678
45378
|
if (!debug.isDebugEnabled()) return;
|
|
44679
|
-
debugLines.push(
|
|
45379
|
+
debugLines.push(
|
|
45380
|
+
redactCredentialText(
|
|
45381
|
+
line,
|
|
45382
|
+
[...selectedCredentials],
|
|
45383
|
+
[...selectedProjectIds]
|
|
45384
|
+
)
|
|
45385
|
+
);
|
|
44680
45386
|
};
|
|
44681
45387
|
pushDebug(`request=${urlString}`);
|
|
44682
45388
|
if (requestSessionIdentity.sessionId) {
|
|
@@ -44695,6 +45401,7 @@ function createRequestExecutor(deps) {
|
|
|
44695
45401
|
let lastError = null;
|
|
44696
45402
|
const abortSignal = init?.signal ?? void 0;
|
|
44697
45403
|
const checkAborted = () => {
|
|
45404
|
+
deadline.check();
|
|
44698
45405
|
if (abortSignal?.aborted) {
|
|
44699
45406
|
throw abortSignal.reason instanceof Error ? abortSignal.reason : new Error("Aborted");
|
|
44700
45407
|
}
|
|
@@ -44724,8 +45431,9 @@ function createRequestExecutor(deps) {
|
|
|
44724
45431
|
}
|
|
44725
45432
|
}
|
|
44726
45433
|
try {
|
|
44727
|
-
await notify?.(message, variant2);
|
|
45434
|
+
await deadline.wait(() => notify?.(message, variant2));
|
|
44728
45435
|
} catch {
|
|
45436
|
+
checkAborted();
|
|
44729
45437
|
}
|
|
44730
45438
|
};
|
|
44731
45439
|
let accountSwitchCount = 0;
|
|
@@ -44733,6 +45441,8 @@ function createRequestExecutor(deps) {
|
|
|
44733
45441
|
let previousAccountIndex = -1;
|
|
44734
45442
|
let needsCacheWarmup = false;
|
|
44735
45443
|
let localRecaptureUsed = false;
|
|
45444
|
+
const maxWaitMs = (config.max_rate_limit_wait_seconds ?? 300) * 1e3;
|
|
45445
|
+
let allAccountsBlockedAt;
|
|
44736
45446
|
while (true) {
|
|
44737
45447
|
await assertAdmission();
|
|
44738
45448
|
checkAborted();
|
|
@@ -44813,6 +45523,10 @@ function createRequestExecutor(deps) {
|
|
|
44813
45523
|
account = null;
|
|
44814
45524
|
}
|
|
44815
45525
|
if (!account) {
|
|
45526
|
+
allAccountsBlockedAt ??= Date.now();
|
|
45527
|
+
const blockedSince = allAccountsBlockedAt;
|
|
45528
|
+
const remainingWaitMs = () => maxWaitMs > 0 ? Math.max(0, maxWaitMs - (Date.now() - blockedSince)) : Number.POSITIVE_INFINITY;
|
|
45529
|
+
const quotaWins = remainingWaitMs() <= deadline.remainingMs();
|
|
44816
45530
|
if (accountManager.areAllAccountsOverSoftQuota(
|
|
44817
45531
|
family,
|
|
44818
45532
|
config.soft_quota_threshold_percent,
|
|
@@ -44826,8 +45540,12 @@ function createRequestExecutor(deps) {
|
|
|
44826
45540
|
softQuotaCacheTtlMs,
|
|
44827
45541
|
model
|
|
44828
45542
|
);
|
|
44829
|
-
|
|
44830
|
-
|
|
45543
|
+
waitPolicy.refusal = quotaWins ? () => createNativeGoogleErrorResponse({
|
|
45544
|
+
status: 412,
|
|
45545
|
+
reason: "soft_quota",
|
|
45546
|
+
resetAfterMs: softQuotaWaitMs
|
|
45547
|
+
}) : void 0;
|
|
45548
|
+
if (softQuotaWaitMs === null || remainingWaitMs() <= 0 || maxWaitMs > 0 && softQuotaWaitMs > maxWaitMs) {
|
|
44831
45549
|
const waitTimeFormatted = softQuotaWaitMs ? formatWaitTime(softQuotaWaitMs) : "unknown";
|
|
44832
45550
|
await showToast(
|
|
44833
45551
|
`All accounts over ${threshold}% quota threshold. Resets in ${waitTimeFormatted}.`,
|
|
@@ -44849,11 +45567,16 @@ function createRequestExecutor(deps) {
|
|
|
44849
45567
|
);
|
|
44850
45568
|
retryState.markSoftQuotaToastShown();
|
|
44851
45569
|
}
|
|
44852
|
-
await sleep4(softQuotaWaitMs, abortSignal);
|
|
45570
|
+
await sleep4(Math.min(softQuotaWaitMs, remainingWaitMs()), abortSignal);
|
|
44853
45571
|
continue;
|
|
44854
45572
|
}
|
|
44855
45573
|
const minWaitMs = accountManager.getMinWaitTimeForFamily(family, model);
|
|
44856
45574
|
const waitMs = minWaitMs || 6e4;
|
|
45575
|
+
waitPolicy.refusal = quotaWins ? () => createNativeGoogleErrorResponse({
|
|
45576
|
+
status: 412,
|
|
45577
|
+
reason: "pool_unavailable",
|
|
45578
|
+
resetAfterMs: minWaitMs > 0 ? minWaitMs : void 0
|
|
45579
|
+
}) : void 0;
|
|
44857
45580
|
pushDebug(
|
|
44858
45581
|
`all-rate-limited family=${family} accounts=${accountCount} waitMs=${waitMs}`
|
|
44859
45582
|
);
|
|
@@ -44868,8 +45591,7 @@ function createRequestExecutor(deps) {
|
|
|
44868
45591
|
accountManager.getAccountsSnapshot()
|
|
44869
45592
|
);
|
|
44870
45593
|
}
|
|
44871
|
-
|
|
44872
|
-
if (maxWaitMs > 0 && waitMs > maxWaitMs) {
|
|
45594
|
+
if (remainingWaitMs() <= 0 || maxWaitMs > 0 && waitMs > maxWaitMs) {
|
|
44873
45595
|
const waitTimeFormatted = formatWaitTime(waitMs);
|
|
44874
45596
|
await showToast(
|
|
44875
45597
|
`Rate limited for ${waitTimeFormatted}. Try again later or add another account.`,
|
|
@@ -44891,9 +45613,11 @@ function createRequestExecutor(deps) {
|
|
|
44891
45613
|
);
|
|
44892
45614
|
retryState.markRateLimitToastShown();
|
|
44893
45615
|
}
|
|
44894
|
-
await sleep4(waitMs, abortSignal);
|
|
45616
|
+
await sleep4(Math.min(waitMs, remainingWaitMs()), abortSignal);
|
|
44895
45617
|
continue;
|
|
44896
45618
|
}
|
|
45619
|
+
allAccountsBlockedAt = void 0;
|
|
45620
|
+
waitPolicy.refusal = void 0;
|
|
44897
45621
|
retryState.resetAllAccountsBlockedToasts();
|
|
44898
45622
|
pushDebug(
|
|
44899
45623
|
`selected idx=${account.index} email=${account.email ?? ""} family=${family} accounts=${accountCount} strategy=${config.account_selection_strategy}`
|
|
@@ -44932,9 +45656,22 @@ function createRequestExecutor(deps) {
|
|
|
44932
45656
|
throw new Error("Local credentials were not resolved");
|
|
44933
45657
|
await assertAdmission();
|
|
44934
45658
|
if (auth.access) selectedCredentials.add(auth.access);
|
|
44935
|
-
const
|
|
44936
|
-
|
|
45659
|
+
const packedProject = parseRefreshParts(auth.refresh);
|
|
45660
|
+
for (const projectId of [
|
|
45661
|
+
packedProject.projectId,
|
|
45662
|
+
packedProject.managedProjectId
|
|
45663
|
+
]) {
|
|
45664
|
+
if (projectId) selectedProjectIds.add(projectId);
|
|
45665
|
+
}
|
|
45666
|
+
const context = await deadline.wait(() => credentials.ensureProject(auth)).catch((error) => {
|
|
45667
|
+
throw redactCredentialError(
|
|
45668
|
+
error,
|
|
45669
|
+
[...selectedCredentials],
|
|
45670
|
+
[...selectedProjectIds]
|
|
45671
|
+
);
|
|
44937
45672
|
});
|
|
45673
|
+
if (context.effectiveProjectId)
|
|
45674
|
+
selectedProjectIds.add(context.effectiveProjectId);
|
|
44938
45675
|
await assertAdmission();
|
|
44939
45676
|
const projectAuth = {
|
|
44940
45677
|
...context.auth,
|
|
@@ -44944,8 +45681,9 @@ function createRequestExecutor(deps) {
|
|
|
44944
45681
|
if (persistProject && projectAuth.refresh !== auth.refresh) {
|
|
44945
45682
|
credentials.updateFromAuth(account, projectAuth);
|
|
44946
45683
|
try {
|
|
44947
|
-
await credentials.saveToDisk();
|
|
45684
|
+
await deadline.wait(() => credentials.saveToDisk());
|
|
44948
45685
|
} catch (error) {
|
|
45686
|
+
checkAborted();
|
|
44949
45687
|
log16.error("Failed to persist project context", {
|
|
44950
45688
|
error: String(error)
|
|
44951
45689
|
});
|
|
@@ -44964,7 +45702,9 @@ function createRequestExecutor(deps) {
|
|
|
44964
45702
|
if (accessTokenExpired(authRecord)) {
|
|
44965
45703
|
try {
|
|
44966
45704
|
await assertAdmission();
|
|
44967
|
-
const refreshed = await
|
|
45705
|
+
const refreshed = await deadline.wait(
|
|
45706
|
+
() => credentials.refresh(account)
|
|
45707
|
+
);
|
|
44968
45708
|
if (!refreshed) {
|
|
44969
45709
|
const { failures, shouldCooldown, cooldownMs } = retryState.trackAccountFailure(account.index);
|
|
44970
45710
|
trackers.health.recordFailure(account.index);
|
|
@@ -44998,13 +45738,15 @@ function createRequestExecutor(deps) {
|
|
|
44998
45738
|
authRecord = refreshed;
|
|
44999
45739
|
grantCheck = captureFor(authRecord);
|
|
45000
45740
|
try {
|
|
45001
|
-
await credentials.saveToDisk();
|
|
45741
|
+
await deadline.wait(() => credentials.saveToDisk());
|
|
45002
45742
|
} catch (error) {
|
|
45743
|
+
checkAborted();
|
|
45003
45744
|
log16.error("Failed to persist refreshed auth", {
|
|
45004
45745
|
error: String(error)
|
|
45005
45746
|
});
|
|
45006
45747
|
}
|
|
45007
45748
|
} catch (error) {
|
|
45749
|
+
checkAborted();
|
|
45008
45750
|
if (credentials.isInvalidGrant(error)) {
|
|
45009
45751
|
const removed = credentials.removeAccount(account);
|
|
45010
45752
|
if (removed) {
|
|
@@ -45012,8 +45754,9 @@ function createRequestExecutor(deps) {
|
|
|
45012
45754
|
"Removed revoked account from pool - reauthenticate via `opencode auth login`"
|
|
45013
45755
|
);
|
|
45014
45756
|
try {
|
|
45015
|
-
await credentials.saveToDiskReplace();
|
|
45757
|
+
await deadline.wait(() => credentials.saveToDiskReplace());
|
|
45016
45758
|
} catch (persistError) {
|
|
45759
|
+
checkAborted();
|
|
45017
45760
|
log16.error("Failed to persist revoked account removal", {
|
|
45018
45761
|
error: String(persistError)
|
|
45019
45762
|
});
|
|
@@ -45021,8 +45764,9 @@ function createRequestExecutor(deps) {
|
|
|
45021
45764
|
}
|
|
45022
45765
|
if (accountManager.getAccountCount() === 0) {
|
|
45023
45766
|
try {
|
|
45024
|
-
await credentials.clearStoredAuth();
|
|
45767
|
+
await deadline.wait(() => credentials.clearStoredAuth());
|
|
45025
45768
|
} catch (storeError) {
|
|
45769
|
+
checkAborted();
|
|
45026
45770
|
log16.error(
|
|
45027
45771
|
"Failed to clear stored Antigravity OAuth credentials",
|
|
45028
45772
|
{
|
|
@@ -45070,6 +45814,7 @@ function createRequestExecutor(deps) {
|
|
|
45070
45814
|
localGrant = await prepareLocalGrant(authRecord, grantCheck);
|
|
45071
45815
|
retryState.resetAccountFailureState(account.index);
|
|
45072
45816
|
} catch (error) {
|
|
45817
|
+
checkAborted();
|
|
45073
45818
|
const { failures, shouldCooldown, cooldownMs } = retryState.trackAccountFailure(account.index);
|
|
45074
45819
|
trackers.health.recordFailure(account.index);
|
|
45075
45820
|
lastError = error instanceof Error ? error : new Error(String(error));
|
|
@@ -45091,10 +45836,12 @@ function createRequestExecutor(deps) {
|
|
|
45091
45836
|
const credentialForAuxiliarySend = async (sendInit, preparedProjectId) => {
|
|
45092
45837
|
await assertAdmission();
|
|
45093
45838
|
if (credentials.domain === "vault") {
|
|
45094
|
-
const admission = await
|
|
45095
|
-
|
|
45096
|
-
|
|
45097
|
-
|
|
45839
|
+
const admission = await deadline.wait(
|
|
45840
|
+
() => credentials.admit({
|
|
45841
|
+
account: selected,
|
|
45842
|
+
signal: abortSignal
|
|
45843
|
+
})
|
|
45844
|
+
);
|
|
45098
45845
|
selectedCredentials.add(admission.accessToken);
|
|
45099
45846
|
if (admission.projectId !== preparedProjectId) {
|
|
45100
45847
|
throw new Error(
|
|
@@ -45110,7 +45857,7 @@ function createRequestExecutor(deps) {
|
|
|
45110
45857
|
"Local credentials were not resolved for the selected account"
|
|
45111
45858
|
);
|
|
45112
45859
|
}
|
|
45113
|
-
await localGrant.captured.check();
|
|
45860
|
+
await deadline.wait(() => localGrant.captured.check());
|
|
45114
45861
|
await assertAdmission();
|
|
45115
45862
|
return { init: sendInit };
|
|
45116
45863
|
};
|
|
@@ -45152,21 +45899,25 @@ function createRequestExecutor(deps) {
|
|
|
45152
45899
|
onDebug: pushDebug
|
|
45153
45900
|
});
|
|
45154
45901
|
reportVault401(warmupSend.admission, warmupResponse.status);
|
|
45155
|
-
const transformed = await
|
|
45156
|
-
|
|
45157
|
-
|
|
45158
|
-
|
|
45159
|
-
|
|
45160
|
-
|
|
45161
|
-
|
|
45162
|
-
|
|
45163
|
-
|
|
45902
|
+
const transformed = await deadline.wait(
|
|
45903
|
+
() => wire.transformResponse(
|
|
45904
|
+
warmupResponse,
|
|
45905
|
+
true,
|
|
45906
|
+
warmupDebugContext,
|
|
45907
|
+
prepared.requestedModel,
|
|
45908
|
+
projectId,
|
|
45909
|
+
warmupUrl,
|
|
45910
|
+
prepared.effectiveModel,
|
|
45911
|
+
prepared.sessionId
|
|
45912
|
+
)
|
|
45164
45913
|
);
|
|
45165
|
-
await transformed.text();
|
|
45914
|
+
await deadline.wait(() => transformed.text());
|
|
45166
45915
|
warmupState.markSuccess(prepared.sessionId);
|
|
45167
45916
|
pushDebug("thinking-warmup: done");
|
|
45168
45917
|
} catch (error) {
|
|
45169
45918
|
warmupState.clearWarmupAttempt(prepared.sessionId);
|
|
45919
|
+
if (error instanceof PreResponseTimeoutError) throw error;
|
|
45920
|
+
checkAborted();
|
|
45170
45921
|
if (isLocalGrantError(error)) throw error;
|
|
45171
45922
|
pushDebug(
|
|
45172
45923
|
`thinking-warmup: failed ${error instanceof Error ? error.message : String(error)}`
|
|
@@ -45195,14 +45946,16 @@ function createRequestExecutor(deps) {
|
|
|
45195
45946
|
reportVault401(probeSend.admission, probeResponse.status);
|
|
45196
45947
|
if (probeResponse.body) {
|
|
45197
45948
|
const reader = probeResponse.body.getReader();
|
|
45198
|
-
await reader.read();
|
|
45199
|
-
await reader.cancel();
|
|
45949
|
+
await deadline.wait(() => reader.read());
|
|
45950
|
+
await deadline.wait(() => reader.cancel());
|
|
45200
45951
|
}
|
|
45201
45952
|
const status = probeResponse.status;
|
|
45202
45953
|
if (status >= 400) {
|
|
45203
45954
|
let errorSnippet = "";
|
|
45204
45955
|
try {
|
|
45205
|
-
const errText = await
|
|
45956
|
+
const errText = await deadline.wait(
|
|
45957
|
+
() => probeResponse.text().catch(() => "")
|
|
45958
|
+
);
|
|
45206
45959
|
errorSnippet = errText.slice(0, 200);
|
|
45207
45960
|
} catch {
|
|
45208
45961
|
}
|
|
@@ -45215,6 +45968,8 @@ function createRequestExecutor(deps) {
|
|
|
45215
45968
|
);
|
|
45216
45969
|
}
|
|
45217
45970
|
} catch (error) {
|
|
45971
|
+
if (error instanceof PreResponseTimeoutError) throw error;
|
|
45972
|
+
checkAborted();
|
|
45218
45973
|
if (isLocalGrantError(error)) {
|
|
45219
45974
|
needsCacheWarmup = true;
|
|
45220
45975
|
throw error;
|
|
@@ -45255,10 +46010,12 @@ function createRequestExecutor(deps) {
|
|
|
45255
46010
|
let sendAccessToken;
|
|
45256
46011
|
let sendProjectId;
|
|
45257
46012
|
if (credentials.domain === "vault") {
|
|
45258
|
-
sendAdmission = rotatedAdmission ?? await
|
|
45259
|
-
|
|
45260
|
-
|
|
45261
|
-
|
|
46013
|
+
sendAdmission = rotatedAdmission ?? await deadline.wait(
|
|
46014
|
+
() => credentials.admit({
|
|
46015
|
+
account,
|
|
46016
|
+
signal: abortSignal
|
|
46017
|
+
})
|
|
46018
|
+
);
|
|
45262
46019
|
rotatedAdmission = void 0;
|
|
45263
46020
|
sendAccessToken = sendAdmission.accessToken;
|
|
45264
46021
|
sendProjectId = sendAdmission.projectId;
|
|
@@ -45270,6 +46027,7 @@ function createRequestExecutor(deps) {
|
|
|
45270
46027
|
"Local credentials were not resolved for the selected account"
|
|
45271
46028
|
);
|
|
45272
46029
|
}
|
|
46030
|
+
if (sendProjectId) selectedProjectIds.add(sendProjectId);
|
|
45273
46031
|
selectedCredentials.add(sendAccessToken);
|
|
45274
46032
|
const prepared = prepareAgyWireRequest(wire, {
|
|
45275
46033
|
input: input2,
|
|
@@ -45323,7 +46081,6 @@ function createRequestExecutor(deps) {
|
|
|
45323
46081
|
sessionId: prepared.sessionId,
|
|
45324
46082
|
toolDebugMissing: prepared.toolDebugMissing,
|
|
45325
46083
|
toolDebugSummary: prepared.toolDebugSummary,
|
|
45326
|
-
toolDebugPayload: prepared.toolDebugPayload,
|
|
45327
46084
|
dumpContext
|
|
45328
46085
|
});
|
|
45329
46086
|
await runThinkingWarmup(prepared, sendProjectId);
|
|
@@ -45346,7 +46103,7 @@ function createRequestExecutor(deps) {
|
|
|
45346
46103
|
"Local credentials were not resolved for the selected account"
|
|
45347
46104
|
);
|
|
45348
46105
|
}
|
|
45349
|
-
await localGrant.captured.check();
|
|
46106
|
+
await deadline.wait(() => localGrant.captured.check());
|
|
45350
46107
|
await assertAdmission();
|
|
45351
46108
|
}
|
|
45352
46109
|
pushDebug(
|
|
@@ -45358,6 +46115,7 @@ function createRequestExecutor(deps) {
|
|
|
45358
46115
|
prepared.init,
|
|
45359
46116
|
{ signal: abortSignal, onDebug: pushDebug }
|
|
45360
46117
|
);
|
|
46118
|
+
if (response.ok) deadline.acceptHeaders();
|
|
45361
46119
|
apiRequestCount++;
|
|
45362
46120
|
accountManager.recordRequest(account.index, family);
|
|
45363
46121
|
const requestCounts = accountManager.getDailyRequestCounts(
|
|
@@ -45374,17 +46132,22 @@ function createRequestExecutor(deps) {
|
|
|
45374
46132
|
noteGeminiDumpResponse(dumpContext, response);
|
|
45375
46133
|
if (credentials.domain === "vault" && sendAdmission && response.status === 401) {
|
|
45376
46134
|
try {
|
|
45377
|
-
await
|
|
46135
|
+
await deadline.wait(
|
|
46136
|
+
() => sendAdmission.report401(response.status)
|
|
46137
|
+
);
|
|
45378
46138
|
} catch (error) {
|
|
46139
|
+
checkAborted();
|
|
45379
46140
|
log16.debug("send-admission-401-report-failed", {
|
|
45380
46141
|
error: String(error)
|
|
45381
46142
|
});
|
|
45382
46143
|
}
|
|
45383
46144
|
if (!vault401Retried) {
|
|
45384
|
-
const next = await
|
|
45385
|
-
|
|
45386
|
-
|
|
45387
|
-
|
|
46145
|
+
const next = await deadline.wait(
|
|
46146
|
+
() => credentials.admit({
|
|
46147
|
+
account,
|
|
46148
|
+
signal: abortSignal
|
|
46149
|
+
})
|
|
46150
|
+
);
|
|
45388
46151
|
if (next.credentialId === sendAdmission.credentialId && next.accountIdentity === sendAdmission.accountIdentity && next.recordVersion > sendAdmission.recordVersion) {
|
|
45389
46152
|
vault401Retried = true;
|
|
45390
46153
|
rotatedAdmission = next;
|
|
@@ -45422,13 +46185,16 @@ function createRequestExecutor(deps) {
|
|
|
45422
46185
|
);
|
|
45423
46186
|
const bodyInfo = await (async () => {
|
|
45424
46187
|
try {
|
|
45425
|
-
const text2 = await
|
|
46188
|
+
const text2 = await deadline.wait(
|
|
46189
|
+
() => response.clone().text()
|
|
46190
|
+
);
|
|
45426
46191
|
try {
|
|
45427
46192
|
return JSON.parse(text2);
|
|
45428
46193
|
} catch {
|
|
45429
46194
|
return null;
|
|
45430
46195
|
}
|
|
45431
46196
|
} catch {
|
|
46197
|
+
checkAborted();
|
|
45432
46198
|
return null;
|
|
45433
46199
|
}
|
|
45434
46200
|
})();
|
|
@@ -45512,7 +46278,7 @@ function createRequestExecutor(deps) {
|
|
|
45512
46278
|
effectiveDelayMs,
|
|
45513
46279
|
reasonInfo
|
|
45514
46280
|
);
|
|
45515
|
-
await
|
|
46281
|
+
await logResponseBody2(debugContext, response, 429);
|
|
45516
46282
|
trackers.health.recordRateLimit(account.index);
|
|
45517
46283
|
const _accountLabel = account.email || `Account ${account.index + 1}`;
|
|
45518
46284
|
if (backoff.attempt === 1 && rateLimitReason !== "QUOTA_EXHAUSTED") {
|
|
@@ -45595,7 +46361,9 @@ function createRequestExecutor(deps) {
|
|
|
45595
46361
|
retryState.resetRateLimitState(account.index, quotaKey);
|
|
45596
46362
|
retryState.resetAccountFailureState(account.index);
|
|
45597
46363
|
if (response.status === 403) {
|
|
45598
|
-
const errorBodyText = await
|
|
46364
|
+
const errorBodyText = await deadline.wait(
|
|
46365
|
+
() => response.clone().text().catch(() => "")
|
|
46366
|
+
);
|
|
45599
46367
|
const extracted = classifyAccessError(errorBodyText);
|
|
45600
46368
|
if (extracted.accountIneligible) {
|
|
45601
46369
|
const ineligibleReason = extracted.message ?? "Google marked this account as ineligible for Antigravity.";
|
|
@@ -45657,11 +46425,7 @@ function createRequestExecutor(deps) {
|
|
|
45657
46425
|
}
|
|
45658
46426
|
const shouldRetryEndpoint = response.status === 403 || response.status === 404 || response.status >= 500;
|
|
45659
46427
|
if (shouldRetryEndpoint && i < ANTIGRAVITY_ENDPOINT_FALLBACKS.length - 1) {
|
|
45660
|
-
await
|
|
45661
|
-
debugContext,
|
|
45662
|
-
response,
|
|
45663
|
-
response.status
|
|
45664
|
-
);
|
|
46428
|
+
await logResponseBody2(debugContext, response, response.status);
|
|
45665
46429
|
lastFailure = createFailureContext(response);
|
|
45666
46430
|
continue;
|
|
45667
46431
|
}
|
|
@@ -45718,21 +46482,13 @@ function createRequestExecutor(deps) {
|
|
|
45718
46482
|
note: response.ok ? "Success" : `Error ${response.status}`
|
|
45719
46483
|
});
|
|
45720
46484
|
if (response.ok && !prepared.streaming) {
|
|
45721
|
-
await
|
|
45722
|
-
debugContext,
|
|
45723
|
-
response,
|
|
45724
|
-
response.status
|
|
45725
|
-
);
|
|
46485
|
+
await logResponseBody2(debugContext, response, response.status);
|
|
45726
46486
|
}
|
|
45727
46487
|
if (!response.ok) {
|
|
45728
|
-
await
|
|
45729
|
-
debugContext,
|
|
45730
|
-
response,
|
|
45731
|
-
response.status
|
|
45732
|
-
);
|
|
46488
|
+
await logResponseBody2(debugContext, response, response.status);
|
|
45733
46489
|
if (response.status === 400) {
|
|
45734
46490
|
const cloned = response.clone();
|
|
45735
|
-
const bodyText = await cloned.text();
|
|
46491
|
+
const bodyText = await deadline.wait(() => cloned.text());
|
|
45736
46492
|
if (bodyText.includes("Prompt is too long") || bodyText.includes("prompt_too_long")) {
|
|
45737
46493
|
await showToast(
|
|
45738
46494
|
"Context too long - use /compact to reduce size",
|
|
@@ -45747,7 +46503,7 @@ function createRequestExecutor(deps) {
|
|
|
45747
46503
|
const maxAttempts = config.empty_response_max_attempts ?? 4;
|
|
45748
46504
|
const retryDelayMs = config.empty_response_retry_delay_ms ?? 2e3;
|
|
45749
46505
|
const clonedForCheck = response.clone();
|
|
45750
|
-
const bodyText = await clonedForCheck.text();
|
|
46506
|
+
const bodyText = await deadline.wait(() => clonedForCheck.text());
|
|
45751
46507
|
if (isEmptyResponseBody(bodyText)) {
|
|
45752
46508
|
const emptyAttemptKey = `${prepared.sessionId ?? "none"}:${prepared.effectiveModel ?? "unknown"}`;
|
|
45753
46509
|
const currentAttempts = retryState.recordEmptyResponseAttempt(emptyAttemptKey);
|
|
@@ -45755,6 +46511,7 @@ function createRequestExecutor(deps) {
|
|
|
45755
46511
|
`empty-response: attempt ${currentAttempts}/${maxAttempts}`
|
|
45756
46512
|
);
|
|
45757
46513
|
if (currentAttempts < maxAttempts) {
|
|
46514
|
+
deadline.resume();
|
|
45758
46515
|
await showToast(
|
|
45759
46516
|
`Empty response received. Retrying (${currentAttempts}/${maxAttempts})...`,
|
|
45760
46517
|
"warning"
|
|
@@ -45771,20 +46528,21 @@ function createRequestExecutor(deps) {
|
|
|
45771
46528
|
const _emptyAttemptKeyClean = `${prepared.sessionId ?? "none"}:${prepared.effectiveModel ?? "unknown"}`;
|
|
45772
46529
|
retryState.clearEmptyResponseAttempts();
|
|
45773
46530
|
}
|
|
45774
|
-
const transformedResponse = await
|
|
45775
|
-
|
|
45776
|
-
|
|
45777
|
-
|
|
45778
|
-
|
|
45779
|
-
|
|
45780
|
-
|
|
45781
|
-
|
|
45782
|
-
|
|
45783
|
-
|
|
45784
|
-
|
|
45785
|
-
|
|
45786
|
-
|
|
45787
|
-
|
|
46531
|
+
const transformedResponse = await deadline.wait(
|
|
46532
|
+
() => wire.transformResponse(
|
|
46533
|
+
response,
|
|
46534
|
+
prepared.streaming,
|
|
46535
|
+
debugContext,
|
|
46536
|
+
prepared.requestedModel,
|
|
46537
|
+
prepared.projectId,
|
|
46538
|
+
prepared.endpoint,
|
|
46539
|
+
prepared.effectiveModel,
|
|
46540
|
+
prepared.sessionId,
|
|
46541
|
+
prepared.toolDebugMissing,
|
|
46542
|
+
prepared.toolDebugSummary,
|
|
46543
|
+
debugLines,
|
|
46544
|
+
dumpContext
|
|
46545
|
+
)
|
|
45788
46546
|
);
|
|
45789
46547
|
const contextError = transformedResponse.headers.get(
|
|
45790
46548
|
"x-antigravity-context-error"
|
|
@@ -45842,6 +46600,8 @@ function createRequestExecutor(deps) {
|
|
|
45842
46600
|
}
|
|
45843
46601
|
return transformedResponse;
|
|
45844
46602
|
} catch (error) {
|
|
46603
|
+
if (error instanceof PreResponseTimeoutError) throw error;
|
|
46604
|
+
checkAborted();
|
|
45845
46605
|
if (tokenConsumed && (!isLocalGrantError(error) || !physicalAttemptStarted)) {
|
|
45846
46606
|
trackers.token.refund(account.index);
|
|
45847
46607
|
tokenConsumed = false;
|
|
@@ -45850,7 +46610,8 @@ function createRequestExecutor(deps) {
|
|
|
45850
46610
|
if (error instanceof LocalGrantSupersededError && !localRecaptureUsed) {
|
|
45851
46611
|
localRecaptureUsed = true;
|
|
45852
46612
|
try {
|
|
45853
|
-
|
|
46613
|
+
const originalGrant = localGrant.captured;
|
|
46614
|
+
await deadline.wait(() => originalGrant.resolveCurrent());
|
|
45854
46615
|
const auth = credentials.toAuthDetails(account);
|
|
45855
46616
|
if (!auth.access || accessTokenExpired(auth))
|
|
45856
46617
|
return createNativeGoogleErrorResponse({
|
|
@@ -45875,6 +46636,7 @@ function createRequestExecutor(deps) {
|
|
|
45875
46636
|
}
|
|
45876
46637
|
if (error instanceof Error && error.message === "THINKING_RECOVERY_NEEDED") {
|
|
45877
46638
|
if (!forceThinkingRecovery) {
|
|
46639
|
+
deadline.resume();
|
|
45878
46640
|
pushDebug(
|
|
45879
46641
|
"thinking-recovery: API error detected, retrying with forced recovery"
|
|
45880
46642
|
);
|
|
@@ -45943,7 +46705,6 @@ function createRequestExecutor(deps) {
|
|
|
45943
46705
|
lastFailure.sessionId,
|
|
45944
46706
|
lastFailure.toolDebugMissing,
|
|
45945
46707
|
lastFailure.toolDebugSummary,
|
|
45946
|
-
lastFailure.toolDebugPayload,
|
|
45947
46708
|
debugLines,
|
|
45948
46709
|
lastFailure.dumpContext
|
|
45949
46710
|
);
|
|
@@ -45966,7 +46727,6 @@ function createRequestExecutor(deps) {
|
|
|
45966
46727
|
lastFailure.sessionId,
|
|
45967
46728
|
lastFailure.toolDebugMissing,
|
|
45968
46729
|
lastFailure.toolDebugSummary,
|
|
45969
|
-
lastFailure.toolDebugPayload,
|
|
45970
46730
|
debugLines,
|
|
45971
46731
|
lastFailure.dumpContext
|
|
45972
46732
|
);
|
|
@@ -45990,7 +46750,6 @@ function createRequestExecutor(deps) {
|
|
|
45990
46750
|
lastFailure.sessionId,
|
|
45991
46751
|
lastFailure.toolDebugMissing,
|
|
45992
46752
|
lastFailure.toolDebugSummary,
|
|
45993
|
-
lastFailure.toolDebugPayload,
|
|
45994
46753
|
debugLines,
|
|
45995
46754
|
lastFailure.dumpContext
|
|
45996
46755
|
);
|
|
@@ -46034,20 +46793,42 @@ function createRequestExecutor(deps) {
|
|
|
46034
46793
|
const cancellation = createRequestCancellation(
|
|
46035
46794
|
requestedSignal ? [requestedSignal, shutdown.signal] : [shutdown.signal]
|
|
46036
46795
|
);
|
|
46796
|
+
const deadline = new PreResponseDeadline(
|
|
46797
|
+
cancellation.signal,
|
|
46798
|
+
deps.preResponseClock
|
|
46799
|
+
);
|
|
46800
|
+
log16.debug("pre-response-start", { limitMs: PRE_RESPONSE_DEADLINE_MS });
|
|
46801
|
+
const waitPolicy = {};
|
|
46037
46802
|
const selectedCredentials = /* @__PURE__ */ new Set();
|
|
46038
|
-
const
|
|
46039
|
-
|
|
46040
|
-
|
|
46041
|
-
|
|
46042
|
-
|
|
46043
|
-
|
|
46803
|
+
const selectedProjectIds = /* @__PURE__ */ new Set();
|
|
46804
|
+
const pending = deadline.wait(
|
|
46805
|
+
() => execute(
|
|
46806
|
+
input2,
|
|
46807
|
+
{ ...init, signal: deadline.signal },
|
|
46808
|
+
requestOptions ?? {},
|
|
46809
|
+
selectedCredentials,
|
|
46810
|
+
selectedProjectIds,
|
|
46811
|
+
deadline,
|
|
46812
|
+
waitPolicy
|
|
46813
|
+
)
|
|
46814
|
+
).catch((error) => {
|
|
46815
|
+
cancellation.signal.throwIfAborted();
|
|
46816
|
+
if (error instanceof PreResponseTimeoutError) {
|
|
46817
|
+
log16.debug("pre-response-timeout", { reason: error.reason });
|
|
46818
|
+
return waitPolicy.refusal?.() ?? preResponseTimeoutResponse();
|
|
46819
|
+
}
|
|
46820
|
+
throw error;
|
|
46821
|
+
}).then(
|
|
46044
46822
|
async (response) => {
|
|
46823
|
+
deadline.acceptTerminalResponse();
|
|
46045
46824
|
if (bufferedOverflow.has(response)) {
|
|
46825
|
+
deadline.dispose();
|
|
46046
46826
|
cancellation.release();
|
|
46047
46827
|
return redactCredentialResponse(
|
|
46048
46828
|
response,
|
|
46049
46829
|
[...selectedCredentials],
|
|
46050
|
-
bufferedOverflow.get(response)
|
|
46830
|
+
bufferedOverflow.get(response),
|
|
46831
|
+
[...selectedProjectIds]
|
|
46051
46832
|
);
|
|
46052
46833
|
}
|
|
46053
46834
|
const retained = await retainResponseLifetime(
|
|
@@ -46056,18 +46837,31 @@ function createRequestExecutor(deps) {
|
|
|
46056
46837
|
);
|
|
46057
46838
|
inFlight.add(retained.settled);
|
|
46058
46839
|
void retained.settled.then(() => inFlight.delete(retained.settled));
|
|
46840
|
+
void retained.settled.then(() => deadline.dispose());
|
|
46059
46841
|
return redactCredentialResponse(
|
|
46060
46842
|
preserveResponseMetadata2(retained.response, response),
|
|
46061
|
-
[...selectedCredentials]
|
|
46843
|
+
[...selectedCredentials],
|
|
46844
|
+
void 0,
|
|
46845
|
+
[...selectedProjectIds]
|
|
46062
46846
|
);
|
|
46063
46847
|
},
|
|
46064
46848
|
(error) => {
|
|
46849
|
+
deadline.dispose();
|
|
46065
46850
|
cancellation.release();
|
|
46066
|
-
throw redactCredentialError(
|
|
46851
|
+
throw redactCredentialError(
|
|
46852
|
+
error,
|
|
46853
|
+
[...selectedCredentials],
|
|
46854
|
+
[...selectedProjectIds]
|
|
46855
|
+
);
|
|
46067
46856
|
}
|
|
46068
46857
|
).catch((error) => {
|
|
46858
|
+
deadline.dispose();
|
|
46069
46859
|
cancellation.release();
|
|
46070
|
-
throw redactCredentialError(
|
|
46860
|
+
throw redactCredentialError(
|
|
46861
|
+
error,
|
|
46862
|
+
[...selectedCredentials],
|
|
46863
|
+
[...selectedProjectIds]
|
|
46864
|
+
);
|
|
46071
46865
|
});
|
|
46072
46866
|
inFlight.add(pending);
|
|
46073
46867
|
void pending.then(
|
|
@@ -46976,7 +47770,7 @@ var createAntigravityPlugin = (providerId, options = {}) => async (input2) => {
|
|
|
46976
47770
|
if (vaultPool && vaultPool.source === source) return vaultPool;
|
|
46977
47771
|
vaultPool = {
|
|
46978
47772
|
source,
|
|
46979
|
-
pool:
|
|
47773
|
+
pool: createOpenCodeVaultAccountPool({
|
|
46980
47774
|
source,
|
|
46981
47775
|
durable: { source, readState: () => vaultCustody.readState() }
|
|
46982
47776
|
})
|