@cortexkit/opencode-antigravity-auth 3.0.8 → 3.0.10
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 +584 -189
- package/dist/cli.js.map +4 -4
- package/dist/cli.meta.json +122 -48
- package/dist/index.js +920 -336
- package/dist/index.js.map +4 -4
- package/dist/index.meta.json +141 -64
- package/dist/server.js +954 -368
- package/dist/server.js.map +4 -4
- package/dist/server.meta.json +1 -1
- package/dist/src/common-auth-embedded/auth-menu/login.d.ts +6 -10
- package/dist/src/common-auth-embedded/auth-menu/login.js +14 -11
- package/dist/src/common-auth-embedded/claustrum/consumer.d.ts +8 -2
- package/dist/src/common-auth-embedded/claustrum/consumer.js +64 -21
- package/dist/src/common-auth-embedded/claustrum/index.d.ts +2 -1
- package/dist/src/common-auth-embedded/claustrum/index.js +1 -0
- package/dist/src/common-auth-embedded/claustrum/insula.d.ts +23 -0
- package/dist/src/common-auth-embedded/claustrum/insula.js +64 -2
- package/dist/src/common-auth-embedded/claustrum/quota-writer.d.ts +18 -0
- package/dist/src/common-auth-embedded/claustrum/quota-writer.js +253 -0
- package/dist/src/common-auth-embedded/claustrum/roster.d.ts +18 -2
- package/dist/src/common-auth-embedded/claustrum/roster.js +100 -43
- package/dist/src/common-auth-embedded/fs/with-lock.d.ts +1 -0
- package/dist/src/common-auth-embedded/fs/with-lock.js +2 -0
- package/dist/src/common-auth-embedded/quota/format.d.ts +19 -0
- package/dist/src/common-auth-embedded/quota/format.js +50 -5
- package/dist/src/common-auth-embedded/quota/index.d.ts +3 -3
- package/dist/src/common-auth-embedded/quota/index.js +2 -2
- package/dist/src/common-auth-embedded/quota/map.d.ts +24 -1
- package/dist/src/common-auth-embedded/quota/map.js +31 -6
- package/dist/src/common-auth-embedded/quota/merge.d.ts +6 -1
- package/dist/src/common-auth-embedded/quota/merge.js +17 -3
- package/dist/src/common-auth-embedded/quota/projection.d.ts +3 -1
- package/dist/src/common-auth-embedded/quota/projection.js +3 -1
- package/dist/src/common-auth-embedded/setup/process-fence.d.ts +7 -0
- package/dist/src/common-auth-embedded/setup/process-fence.js +5 -3
- package/dist/src/common-auth-embedded/source-output.json +95 -79
- package/dist/src/plugin/background-vault-quota-refresh.d.ts.map +1 -1
- package/dist/src/plugin/background-vault-quota-refresh.js +8 -1
- package/dist/src/plugin/background-vault-quota-refresh.js.map +1 -1
- package/dist/src/plugin/index.d.ts.map +1 -1
- package/dist/src/plugin/index.js +1 -0
- package/dist/src/plugin/index.js.map +1 -1
- package/dist/src/plugin/quota.d.ts +1 -1
- package/dist/src/plugin/quota.d.ts.map +1 -1
- package/dist/src/plugin/quota.js +17 -5
- package/dist/src/plugin/quota.js.map +1 -1
- package/dist/src/plugin/request-helpers.d.ts +5 -0
- package/dist/src/plugin/request-helpers.d.ts.map +1 -1
- package/dist/src/plugin/request-helpers.js +1 -0
- package/dist/src/plugin/request-helpers.js.map +1 -1
- package/dist/src/plugin/shared/request-services.d.ts.map +1 -1
- package/dist/src/plugin/shared/request-services.js +123 -5
- package/dist/src/plugin/shared/request-services.js.map +1 -1
- package/dist/src/plugin/shared/vault-request-credentials.d.ts +9 -6
- package/dist/src/plugin/shared/vault-request-credentials.d.ts.map +1 -1
- package/dist/src/plugin/shared/vault-request-credentials.js +9 -4
- package/dist/src/plugin/shared/vault-request-credentials.js.map +1 -1
- package/dist/src/plugin/vault-custody.d.ts +2 -0
- package/dist/src/plugin/vault-custody.d.ts.map +1 -1
- package/dist/src/plugin/vault-custody.js +9 -0
- package/dist/src/plugin/vault-custody.js.map +1 -1
- package/dist/src/plugin/vault-insula-quota.d.ts +6 -0
- package/dist/src/plugin/vault-insula-quota.d.ts.map +1 -0
- package/dist/src/plugin/vault-insula-quota.js +50 -0
- package/dist/src/plugin/vault-insula-quota.js.map +1 -0
- package/dist/src/plugin/vault-quota-outcome.d.ts +1 -1
- package/dist/src/plugin/vault-quota-outcome.d.ts.map +1 -1
- package/dist/src/plugin/vault-quota-outcome.js.map +1 -1
- package/dist/tui-build-map.json +21 -21
- package/dist/tui-ga-build-map.json +21 -21
- package/dist/types/src/common-auth-embedded/claustrum/consumer.d.ts +8 -2
- package/dist/types/src/common-auth-embedded/claustrum/index.d.ts +2 -1
- package/dist/types/src/common-auth-embedded/claustrum/insula.d.ts +23 -0
- package/dist/types/src/common-auth-embedded/claustrum/quota-writer.d.ts +18 -0
- package/dist/types/src/common-auth-embedded/claustrum/roster.d.ts +18 -2
- package/dist/types/src/common-auth-embedded/quota/format.d.ts +19 -0
- package/dist/types/src/common-auth-embedded/quota/index.d.ts +3 -3
- package/dist/types/src/common-auth-embedded/quota/map.d.ts +24 -1
- package/dist/types/src/common-auth-embedded/quota/merge.d.ts +6 -1
- package/dist/types/src/common-auth-embedded/quota/projection.d.ts +3 -1
- package/dist/types/src/common-auth-embedded/setup/process-fence.d.ts +7 -0
- package/dist/types/src/plugin/background-vault-quota-refresh.d.ts.map +1 -1
- package/dist/types/src/plugin/config/schema.d.ts +2 -2
- package/dist/types/src/plugin/index.d.ts.map +1 -1
- package/dist/types/src/plugin/quota.d.ts +1 -1
- package/dist/types/src/plugin/quota.d.ts.map +1 -1
- package/dist/types/src/plugin/request-helpers.d.ts +5 -0
- package/dist/types/src/plugin/request-helpers.d.ts.map +1 -1
- package/dist/types/src/plugin/shared/request-services.d.ts.map +1 -1
- package/dist/types/src/plugin/shared/vault-request-credentials.d.ts +9 -6
- package/dist/types/src/plugin/shared/vault-request-credentials.d.ts.map +1 -1
- package/dist/types/src/plugin/vault-custody.d.ts +2 -0
- package/dist/types/src/plugin/vault-custody.d.ts.map +1 -1
- package/dist/types/src/plugin/vault-insula-quota.d.ts +6 -0
- package/dist/types/src/plugin/vault-insula-quota.d.ts.map +1 -0
- package/dist/types/src/plugin/vault-quota-outcome.d.ts +1 -1
- package/dist/types/src/plugin/vault-quota-outcome.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/common-auth-embedded/auth-menu/login.d.ts +6 -10
- package/src/common-auth-embedded/auth-menu/login.js +14 -11
- package/src/common-auth-embedded/claustrum/consumer.d.ts +8 -2
- package/src/common-auth-embedded/claustrum/consumer.js +64 -21
- package/src/common-auth-embedded/claustrum/index.d.ts +2 -1
- package/src/common-auth-embedded/claustrum/index.js +1 -0
- package/src/common-auth-embedded/claustrum/insula.d.ts +23 -0
- package/src/common-auth-embedded/claustrum/insula.js +64 -2
- package/src/common-auth-embedded/claustrum/quota-writer.d.ts +18 -0
- package/src/common-auth-embedded/claustrum/quota-writer.js +253 -0
- package/src/common-auth-embedded/claustrum/roster.d.ts +18 -2
- package/src/common-auth-embedded/claustrum/roster.js +100 -43
- package/src/common-auth-embedded/fs/with-lock.d.ts +1 -0
- package/src/common-auth-embedded/fs/with-lock.js +2 -0
- package/src/common-auth-embedded/quota/format.d.ts +19 -0
- package/src/common-auth-embedded/quota/format.js +50 -5
- package/src/common-auth-embedded/quota/index.d.ts +3 -3
- package/src/common-auth-embedded/quota/index.js +2 -2
- package/src/common-auth-embedded/quota/map.d.ts +24 -1
- package/src/common-auth-embedded/quota/map.js +31 -6
- package/src/common-auth-embedded/quota/merge.d.ts +6 -1
- package/src/common-auth-embedded/quota/merge.js +17 -3
- package/src/common-auth-embedded/quota/projection.d.ts +3 -1
- package/src/common-auth-embedded/quota/projection.js +3 -1
- package/src/common-auth-embedded/setup/process-fence.d.ts +7 -0
- package/src/common-auth-embedded/setup/process-fence.js +5 -3
- package/src/common-auth-embedded/source-output.json +95 -79
- package/src/tui-compiled/common-auth-embedded/quota/format.js +50 -5
- package/src/tui-compiled/common-auth-embedded/quota/index.js +2 -2
- package/src/tui-compiled/common-auth-embedded/quota/map.js +31 -6
- package/src/tui-compiled/common-auth-embedded/quota/merge.js +17 -3
- package/src/tui-compiled/common-auth-embedded/quota/projection.js +3 -1
- package/src/tui-ga-compiled/shared/1ff34afa7c42d196-projection.js +3 -1
- package/src/tui-ga-compiled/shared/77138df80c7ae006-map.js +31 -6
- package/src/tui-ga-compiled/shared/aef2402f8fc342f0-format.js +50 -5
- package/src/tui-ga-compiled/shared/bf17cbee28e58197-index.js +2 -2
- package/src/tui-ga-compiled/shared/ecc214300932dfb6-merge.js +17 -3
- package/src/tui-ga-raw/shared/1ff34afa7c42d196-projection.js +3 -1
- package/src/tui-ga-raw/shared/77138df80c7ae006-map.js +31 -6
- package/src/tui-ga-raw/shared/aef2402f8fc342f0-format.js +50 -5
- package/src/tui-ga-raw/shared/bf17cbee28e58197-index.js +2 -2
- package/src/tui-ga-raw/shared/ecc214300932dfb6-merge.js +17 -3
- package/src/tui-raw/common-auth-embedded/quota/format.js +50 -5
- package/src/tui-raw/common-auth-embedded/quota/index.js +2 -2
- package/src/tui-raw/common-auth-embedded/quota/map.js +31 -6
- package/src/tui-raw/common-auth-embedded/quota/merge.js +17 -3
- package/src/tui-raw/common-auth-embedded/quota/projection.js +3 -1
package/dist/server.js
CHANGED
|
@@ -64,6 +64,12 @@ function isQuotaCounter(value) {
|
|
|
64
64
|
function isQuotaCounters(value) {
|
|
65
65
|
return isRecord2(value) && Object.values(value).every(isQuotaCounter);
|
|
66
66
|
}
|
|
67
|
+
function isBoolean(value) {
|
|
68
|
+
return typeof value === "boolean";
|
|
69
|
+
}
|
|
70
|
+
function isQuotaCredits(value) {
|
|
71
|
+
return isRecord2(value) && typeof value.hasCredits === "boolean" && typeof value.unlimited === "boolean" && optional2(value, "balance", isFiniteNumber) && optional2(value, "overageLimitReached", isBoolean) && isFiniteNumber(value.checkedAt);
|
|
72
|
+
}
|
|
67
73
|
function readQuotaCounters(value) {
|
|
68
74
|
if (!isRecord2(value))
|
|
69
75
|
return void 0;
|
|
@@ -75,11 +81,16 @@ function decodeQuotaMap(value) {
|
|
|
75
81
|
return value;
|
|
76
82
|
if (!isRecord2(value))
|
|
77
83
|
return void 0;
|
|
78
|
-
const { counters: rawCounters, ...rest } = value;
|
|
84
|
+
const { counters: rawCounters, credits: rawCredits, ...rest } = value;
|
|
79
85
|
if (!isQuotaMap(rest))
|
|
80
86
|
return void 0;
|
|
81
87
|
const counters = readQuotaCounters(rawCounters);
|
|
82
|
-
|
|
88
|
+
const credits = isQuotaCredits(rawCredits) ? rawCredits : void 0;
|
|
89
|
+
return {
|
|
90
|
+
...rest,
|
|
91
|
+
...counters === void 0 ? {} : { counters },
|
|
92
|
+
...credits === void 0 ? {} : { credits }
|
|
93
|
+
};
|
|
83
94
|
}
|
|
84
95
|
function isQuotaMap(value) {
|
|
85
96
|
if (!isRecord2(value) || !Array.isArray(value.limits))
|
|
@@ -93,7 +104,7 @@ function isQuotaMap(value) {
|
|
|
93
104
|
return false;
|
|
94
105
|
seen.add(key);
|
|
95
106
|
}
|
|
96
|
-
return optional2(value, "budget", isCreditBudgetEntry) && optional2(value, "counters", isQuotaCounters);
|
|
107
|
+
return optional2(value, "budget", isCreditBudgetEntry) && optional2(value, "counters", isQuotaCounters) && optional2(value, "credits", isQuotaCredits);
|
|
97
108
|
}
|
|
98
109
|
var ALL_SCOPE, DEFAULT_REQUIRED_LABELS;
|
|
99
110
|
var init_map = __esm({
|
|
@@ -156,7 +167,7 @@ function isQuotaObservation(value) {
|
|
|
156
167
|
}
|
|
157
168
|
if (!coverage.every(isObservedPair))
|
|
158
169
|
return false;
|
|
159
|
-
return (value.budget === void 0 || isObservedBudget(value.budget)) && (value.counters === void 0 || isQuotaCounters(value.counters));
|
|
170
|
+
return (value.budget === void 0 || isObservedBudget(value.budget)) && (value.counters === void 0 || isQuotaCounters(value.counters)) && (value.credits === void 0 || isQuotaCredits(value.credits));
|
|
160
171
|
}
|
|
161
172
|
function compareEntries(left, right) {
|
|
162
173
|
if (left.scope !== right.scope)
|
|
@@ -182,6 +193,14 @@ function mergeCounters(stored, observed) {
|
|
|
182
193
|
}
|
|
183
194
|
return counters.size === 0 ? void 0 : Object.fromEntries(counters);
|
|
184
195
|
}
|
|
196
|
+
function mergeCredits(stored, observed) {
|
|
197
|
+
if (observed === void 0)
|
|
198
|
+
return stored;
|
|
199
|
+
if (stored !== void 0 && observed.checkedAt < stored.checkedAt) {
|
|
200
|
+
return stored;
|
|
201
|
+
}
|
|
202
|
+
return { ...observed };
|
|
203
|
+
}
|
|
185
204
|
function mergeQuotaObservation(stored, observation) {
|
|
186
205
|
const decoded = stored === void 0 ? void 0 : decodeQuotaMap(stored);
|
|
187
206
|
if (stored !== void 0 && decoded === void 0) {
|
|
@@ -225,14 +244,16 @@ function mergeQuotaObservation(stored, observation) {
|
|
|
225
244
|
const existing = entries.get(key);
|
|
226
245
|
entries.set(key, existing === void 0 || existing.kind === "absent" ? { scope, label: pair.label, kind: "absent", checkedAt: at } : { scope, label: pair.label, kind: "retired", retiredAt: at });
|
|
227
246
|
}
|
|
228
|
-
const { limits: _limits, budget: _budget, counters: _counters, ...unknownKeys } = base;
|
|
247
|
+
const { limits: _limits, budget: _budget, counters: _counters, credits: _credits, ...unknownKeys } = base;
|
|
229
248
|
const budget = mergeBudget(base.budget, observation.budget, at);
|
|
230
249
|
const counters = mergeCounters(base.counters, observation.counters);
|
|
250
|
+
const credits = mergeCredits(base.credits, observation.credits);
|
|
231
251
|
return {
|
|
232
252
|
...unknownKeys,
|
|
233
253
|
limits: [...entries.values()].sort(compareEntries),
|
|
234
254
|
...budget === void 0 ? {} : { budget },
|
|
235
|
-
...counters === void 0 ? {} : { counters }
|
|
255
|
+
...counters === void 0 ? {} : { counters },
|
|
256
|
+
...credits === void 0 ? {} : { credits }
|
|
236
257
|
};
|
|
237
258
|
}
|
|
238
259
|
var QuotaCodecError;
|
|
@@ -323,16 +344,23 @@ function displayOrder(left, right) {
|
|
|
323
344
|
return left.label < right.label ? -1 : left.label > right.label ? 1 : 0;
|
|
324
345
|
}
|
|
325
346
|
function quotaWindowParts(quota, options) {
|
|
326
|
-
const { windows, age } = scopedWindowParts(quota, options);
|
|
327
|
-
const parts =
|
|
347
|
+
const { windows: windows2, age } = scopedWindowParts(quota, options);
|
|
348
|
+
const parts = windows2.map(({ part }) => part);
|
|
328
349
|
return age === void 0 ? { windows: parts } : { windows: parts, age };
|
|
329
350
|
}
|
|
351
|
+
function withShortNames(windows2) {
|
|
352
|
+
const abbreviations = scopeAbbreviations(windows2.filter(({ part, scope }) => part.kind === "window" && scope !== ALL_SCOPE).map(({ scope }) => scope));
|
|
353
|
+
for (const window of windows2) {
|
|
354
|
+
window.part.short = window.part.kind === "budget" ? "cr" : window.scope === ALL_SCOPE ? window.part.name : abbreviations.get(window.scope) ?? window.scope;
|
|
355
|
+
}
|
|
356
|
+
return windows2;
|
|
357
|
+
}
|
|
330
358
|
function scopedWindowParts(quota, options) {
|
|
331
359
|
if (!quota)
|
|
332
360
|
return { windows: [] };
|
|
333
361
|
const { now } = options;
|
|
334
362
|
const readings = quota.limits.filter((limit) => limit.kind === "reading" && limit.remainingPercent !== void 0).sort(displayOrder);
|
|
335
|
-
const
|
|
363
|
+
const windows2 = readings.map((limit) => {
|
|
336
364
|
const remainingPercent = clampPercent(limit.remainingPercent ?? 0);
|
|
337
365
|
return {
|
|
338
366
|
scope: limit.scope,
|
|
@@ -340,6 +368,7 @@ function scopedWindowParts(quota, options) {
|
|
|
340
368
|
part: {
|
|
341
369
|
kind: "window",
|
|
342
370
|
name: quotaWindowName(limit),
|
|
371
|
+
short: "",
|
|
343
372
|
figure: percentLeft(limit.remainingPercent ?? 0),
|
|
344
373
|
remainingPercent,
|
|
345
374
|
checkedAt: limit.checkedAt,
|
|
@@ -351,12 +380,13 @@ function scopedWindowParts(quota, options) {
|
|
|
351
380
|
if (budget) {
|
|
352
381
|
const remainingPercent = budget.remainingPercent;
|
|
353
382
|
const figure = budget.reached ? "credits spent" : remainingPercent !== void 0 ? `credits ${percentLeft(remainingPercent)}` : "credits available";
|
|
354
|
-
|
|
383
|
+
windows2.push({
|
|
355
384
|
scope: ALL_SCOPE,
|
|
356
385
|
spent: budget.reached,
|
|
357
386
|
part: {
|
|
358
387
|
kind: "budget",
|
|
359
388
|
name: "credits",
|
|
389
|
+
short: "",
|
|
360
390
|
figure,
|
|
361
391
|
...remainingPercent === void 0 ? {} : { remainingPercent: clampPercent(remainingPercent) },
|
|
362
392
|
checkedAt: budget.checkedAt,
|
|
@@ -364,13 +394,14 @@ function scopedWindowParts(quota, options) {
|
|
|
364
394
|
}
|
|
365
395
|
});
|
|
366
396
|
}
|
|
367
|
-
|
|
368
|
-
|
|
397
|
+
withShortNames(windows2);
|
|
398
|
+
if (windows2.length > 0) {
|
|
399
|
+
const age = now - Math.min(...windows2.map(({ part }) => part.checkedAt));
|
|
369
400
|
if (age > (options.staleAfterMs ?? QUOTA_STALE_AFTER_MS)) {
|
|
370
|
-
return { windows, age: `checked ${shortSpan(age)} ago` };
|
|
401
|
+
return { windows: windows2, age: `checked ${shortSpan(age)} ago` };
|
|
371
402
|
}
|
|
372
403
|
}
|
|
373
|
-
return { windows };
|
|
404
|
+
return { windows: windows2 };
|
|
374
405
|
}
|
|
375
406
|
function isQuotaStale(quota, options) {
|
|
376
407
|
return scopedWindowParts(quota, options).age !== void 0;
|
|
@@ -410,10 +441,10 @@ function groupShortNames(groups) {
|
|
|
410
441
|
const short = scopeAbbreviations(labels);
|
|
411
442
|
return labels.map((label) => short.get(label) ?? label);
|
|
412
443
|
}
|
|
413
|
-
function groupedNarrowPieces(groups,
|
|
444
|
+
function groupedNarrowPieces(groups, windows2) {
|
|
414
445
|
if (!groups || groups.length === 0)
|
|
415
446
|
return void 0;
|
|
416
|
-
const reported =
|
|
447
|
+
const reported = windows2.filter(({ part }) => part.kind === "window");
|
|
417
448
|
if (reported.some(({ scope }) => scope === ALL_SCOPE))
|
|
418
449
|
return void 0;
|
|
419
450
|
const candidates = groups.flatMap((group, listed) => {
|
|
@@ -437,21 +468,20 @@ function groupedNarrowPieces(groups, windows) {
|
|
|
437
468
|
});
|
|
438
469
|
}
|
|
439
470
|
function narrowTextParts(quota, options) {
|
|
440
|
-
const { windows } = scopedWindowParts(quota, options);
|
|
441
|
-
const grouped = groupedNarrowPieces(quota?.groups,
|
|
471
|
+
const { windows: windows2 } = scopedWindowParts(quota, options);
|
|
472
|
+
const grouped = groupedNarrowPieces(quota?.groups, windows2);
|
|
442
473
|
if (grouped)
|
|
443
474
|
return grouped;
|
|
444
|
-
const general =
|
|
445
|
-
const scoped =
|
|
446
|
-
const
|
|
447
|
-
const budget = windows.find(({ part }) => part.kind === "budget");
|
|
475
|
+
const general = windows2.filter(({ part, scope }) => part.kind === "window" && scope === ALL_SCOPE);
|
|
476
|
+
const scoped = windows2.filter(({ part, scope }) => part.kind === "window" && scope !== ALL_SCOPE);
|
|
477
|
+
const budget = windows2.find(({ part }) => part.kind === "budget");
|
|
448
478
|
const budgetLeft = budget?.spent ? 0 : budget?.part.remainingPercent;
|
|
449
479
|
const extras = [
|
|
450
|
-
...scoped.map(({
|
|
451
|
-
label:
|
|
480
|
+
...scoped.map(({ part }) => ({
|
|
481
|
+
label: part.short,
|
|
452
482
|
remaining: part.remainingPercent ?? 0
|
|
453
483
|
})),
|
|
454
|
-
...budgetLeft === void 0 ? [] : [{ label:
|
|
484
|
+
...budgetLeft === void 0 || budget === void 0 ? [] : [{ label: budget.part.short, remaining: budgetLeft }]
|
|
455
485
|
];
|
|
456
486
|
const tightest = extras.reduce((best, item) => best === void 0 || item.remaining < best.remaining ? item : best, void 0);
|
|
457
487
|
const pieces = general.map(({ part }) => `${part.name} ${wholePercent(part.remainingPercent ?? 0)}%`);
|
|
@@ -459,7 +489,7 @@ function narrowTextParts(quota, options) {
|
|
|
459
489
|
pieces.push(`${tightest.label} ${wholePercent(tightest.remaining)}%`);
|
|
460
490
|
}
|
|
461
491
|
if (pieces.length === 0)
|
|
462
|
-
return
|
|
492
|
+
return windows2.map(({ part }) => part.figure);
|
|
463
493
|
return pieces.map((piece, index) => index === pieces.length - 1 ? `${piece} left` : piece);
|
|
464
494
|
}
|
|
465
495
|
function quotaTextParts(quota, options) {
|
|
@@ -479,6 +509,16 @@ function formatQuota(quota, options) {
|
|
|
479
509
|
return parts.join(" \xB7 ");
|
|
480
510
|
return quota && quota.limits.length > 0 ? NO_LIMITS_REPORTED : NO_QUOTA_READING;
|
|
481
511
|
}
|
|
512
|
+
function quotaCreditsText(credits) {
|
|
513
|
+
if (credits === void 0)
|
|
514
|
+
return void 0;
|
|
515
|
+
if (credits.unlimited)
|
|
516
|
+
return "Unlimited";
|
|
517
|
+
if (!credits.hasCredits)
|
|
518
|
+
return void 0;
|
|
519
|
+
const { balance } = credits;
|
|
520
|
+
return typeof balance === "number" && Number.isFinite(balance) && balance > 0 ? `${Math.round(balance)} credits` : "Available";
|
|
521
|
+
}
|
|
482
522
|
var QUOTA_STALE_AFTER_MS, NO_QUOTA_READING, NO_LIMITS_REPORTED, NARROW_GROUP_LIMIT;
|
|
483
523
|
var init_format = __esm({
|
|
484
524
|
"../core/dist/common-auth-embedded/quota/format.js"() {
|
|
@@ -560,12 +600,14 @@ function projectQuota(map, scope = ALL_SCOPE) {
|
|
|
560
600
|
const checkedAt = stamped.length > 0 ? Math.min(...stamped.map((limit) => limit.checkedAt)) : void 0;
|
|
561
601
|
const budget = map?.budget?.kind === "reading" ? projectBudget(map.budget) : void 0;
|
|
562
602
|
const counters = readQuotaCounters(map?.counters);
|
|
603
|
+
const credits = isQuotaCredits(map?.credits) ? map.credits : void 0;
|
|
563
604
|
return {
|
|
564
605
|
scope,
|
|
565
606
|
limits,
|
|
566
607
|
...checkedAt === void 0 ? {} : { checkedAt },
|
|
567
608
|
...budget === void 0 ? {} : { budget },
|
|
568
|
-
...counters === void 0 ? {} : { counters }
|
|
609
|
+
...counters === void 0 ? {} : { counters },
|
|
610
|
+
...credits === void 0 ? {} : { credits }
|
|
569
611
|
};
|
|
570
612
|
}
|
|
571
613
|
function budgetExhaustedResetAt(quota, now) {
|
|
@@ -608,12 +650,14 @@ __export(quota_exports, {
|
|
|
608
650
|
emptyQuotaMap: () => emptyQuotaMap,
|
|
609
651
|
formatQuota: () => formatQuota,
|
|
610
652
|
futureResetAt: () => futureResetAt,
|
|
653
|
+
isQuotaCredits: () => isQuotaCredits,
|
|
611
654
|
isQuotaMap: () => isQuotaMap,
|
|
612
655
|
isQuotaObservation: () => isQuotaObservation,
|
|
613
656
|
isQuotaStale: () => isQuotaStale,
|
|
614
657
|
mergeQuotaObservation: () => mergeQuotaObservation,
|
|
615
658
|
projectQuota: () => projectQuota,
|
|
616
659
|
quotaCodec: () => quotaCodec2,
|
|
660
|
+
quotaCreditsText: () => quotaCreditsText,
|
|
617
661
|
quotaTextParts: () => quotaTextParts,
|
|
618
662
|
quotaWindowName: () => quotaWindowName,
|
|
619
663
|
quotaWindowParts: () => quotaWindowParts,
|
|
@@ -1114,8 +1158,8 @@ async function acquireRefreshFileLockWithClock(options) {
|
|
|
1114
1158
|
let releaseConfirmed = false;
|
|
1115
1159
|
let loss;
|
|
1116
1160
|
let resolveLoss;
|
|
1117
|
-
const lostPromise = new Promise((
|
|
1118
|
-
resolveLoss =
|
|
1161
|
+
const lostPromise = new Promise((resolve20) => {
|
|
1162
|
+
resolveLoss = resolve20;
|
|
1119
1163
|
});
|
|
1120
1164
|
function notifyTimerStep(event) {
|
|
1121
1165
|
try {
|
|
@@ -1272,7 +1316,7 @@ async function acquireRefreshFileLockWithClock(options) {
|
|
|
1272
1316
|
}
|
|
1273
1317
|
}
|
|
1274
1318
|
async function backoff() {
|
|
1275
|
-
await new Promise((
|
|
1319
|
+
await new Promise((resolve20) => setTimeout(resolve20, Math.floor(Math.random() * 4)));
|
|
1276
1320
|
}
|
|
1277
1321
|
async function readLockState(notifyReady = true) {
|
|
1278
1322
|
if (notifyReady && options.onStep)
|
|
@@ -1722,6 +1766,7 @@ function lockPathFor(target, name) {
|
|
|
1722
1766
|
async function withLock(target, options, fn) {
|
|
1723
1767
|
const started = performance.now();
|
|
1724
1768
|
for (; ; ) {
|
|
1769
|
+
options.signal?.throwIfAborted();
|
|
1725
1770
|
const lock = await acquireRefreshFileLock({
|
|
1726
1771
|
path: target,
|
|
1727
1772
|
name: options.name,
|
|
@@ -1732,6 +1777,7 @@ async function withLock(target, options, fn) {
|
|
|
1732
1777
|
});
|
|
1733
1778
|
if (lock) {
|
|
1734
1779
|
try {
|
|
1780
|
+
options.signal?.throwIfAborted();
|
|
1735
1781
|
return await fn(lock);
|
|
1736
1782
|
} finally {
|
|
1737
1783
|
await lock.release();
|
|
@@ -1745,7 +1791,7 @@ async function withLock(target, options, fn) {
|
|
|
1745
1791
|
timeoutMs: options.timeoutMs
|
|
1746
1792
|
});
|
|
1747
1793
|
}
|
|
1748
|
-
await new Promise((
|
|
1794
|
+
await new Promise((resolve20) => setTimeout(resolve20, Math.min(25, Math.ceil(remaining))));
|
|
1749
1795
|
}
|
|
1750
1796
|
}
|
|
1751
1797
|
var LockContentionError, LockOwnershipError;
|
|
@@ -1781,13 +1827,13 @@ function assertNotInsideHook(operation) {
|
|
|
1781
1827
|
function runInsideHook(operation, fn) {
|
|
1782
1828
|
return insideHook.run(operation, async () => await fn());
|
|
1783
1829
|
}
|
|
1784
|
-
async function callFailureHook(operation, hook, rowId2, error,
|
|
1830
|
+
async function callFailureHook(operation, hook, rowId2, error, logger3) {
|
|
1785
1831
|
if (!hook)
|
|
1786
1832
|
return;
|
|
1787
1833
|
try {
|
|
1788
1834
|
await runInsideHook(operation, () => hook(rowId2, error));
|
|
1789
1835
|
} catch (hookError) {
|
|
1790
|
-
|
|
1836
|
+
logger3?.warn("store failure hook threw; the original failure stands", {
|
|
1791
1837
|
operation,
|
|
1792
1838
|
rowId: rowId2,
|
|
1793
1839
|
error: hookError instanceof Error ? hookError.message : String(hookError)
|
|
@@ -1864,7 +1910,7 @@ async function acquirePoolLock(spec, defaults, env3) {
|
|
|
1864
1910
|
});
|
|
1865
1911
|
}
|
|
1866
1912
|
const jitter = Math.floor(Math.random() * (options.retryMs + 1));
|
|
1867
|
-
await new Promise((
|
|
1913
|
+
await new Promise((resolve20) => setTimeout(resolve20, Math.min(options.retryMs + jitter, remaining)));
|
|
1868
1914
|
}
|
|
1869
1915
|
}
|
|
1870
1916
|
function definedOnly(spec) {
|
|
@@ -2942,11 +2988,11 @@ var init_mutate = __esm({
|
|
|
2942
2988
|
if (isRecord4(this.state.accounts) && Object.hasOwn(this.state.accounts, id))
|
|
2943
2989
|
delete this.state.accounts[id];
|
|
2944
2990
|
}
|
|
2945
|
-
setStateAccount(id,
|
|
2991
|
+
setStateAccount(id, fields2) {
|
|
2946
2992
|
if (!isRecord4(this.state.accounts))
|
|
2947
2993
|
this.state.accounts = {};
|
|
2948
2994
|
Object.defineProperty(this.state.accounts, id, {
|
|
2949
|
-
value:
|
|
2995
|
+
value: fields2,
|
|
2950
2996
|
enumerable: true,
|
|
2951
2997
|
writable: true,
|
|
2952
2998
|
configurable: true
|
|
@@ -4495,12 +4541,12 @@ var init_pull = __esm({
|
|
|
4495
4541
|
firedAtLoad;
|
|
4496
4542
|
logger;
|
|
4497
4543
|
inflight = /* @__PURE__ */ new Set();
|
|
4498
|
-
constructor(rt, hook, onFailure, firedAtLoad,
|
|
4544
|
+
constructor(rt, hook, onFailure, firedAtLoad, logger3) {
|
|
4499
4545
|
this.rt = rt;
|
|
4500
4546
|
this.hook = hook;
|
|
4501
4547
|
this.onFailure = onFailure;
|
|
4502
4548
|
this.firedAtLoad = firedAtLoad;
|
|
4503
|
-
this.logger =
|
|
4549
|
+
this.logger = logger3;
|
|
4504
4550
|
}
|
|
4505
4551
|
fire(id, reason) {
|
|
4506
4552
|
if (!this.hook)
|
|
@@ -5582,15 +5628,15 @@ function createRedactor(options = {}) {
|
|
|
5582
5628
|
return SECRET_KEY_EXACT.test(key) || normalized.includes("apikey") || normalized.endsWith("secret") || normalized.endsWith("password") || normalized.endsWith("token") && !normalized.endsWith("tokens") || !!options.extraSecretKeys?.(normalized);
|
|
5583
5629
|
}
|
|
5584
5630
|
function errorEntries(error) {
|
|
5585
|
-
const
|
|
5631
|
+
const fields2 = error;
|
|
5586
5632
|
const entries = [
|
|
5587
5633
|
["name", error.name],
|
|
5588
5634
|
["message", error.message],
|
|
5589
5635
|
["stack", error.stack]
|
|
5590
5636
|
];
|
|
5591
5637
|
for (const key of ["code", "status", "cause"])
|
|
5592
|
-
if (
|
|
5593
|
-
entries.push([key,
|
|
5638
|
+
if (fields2[key] !== void 0)
|
|
5639
|
+
entries.push([key, fields2[key]]);
|
|
5594
5640
|
const listed = new Set(entries.map(([key]) => key));
|
|
5595
5641
|
for (const entry of Object.entries(error))
|
|
5596
5642
|
if (!listed.has(entry[0]))
|
|
@@ -5832,7 +5878,7 @@ function createEngine(options) {
|
|
|
5832
5878
|
} catch {
|
|
5833
5879
|
}
|
|
5834
5880
|
}
|
|
5835
|
-
function
|
|
5881
|
+
function schedule2() {
|
|
5836
5882
|
if (!timer)
|
|
5837
5883
|
timer = setTimeout(() => {
|
|
5838
5884
|
timer = void 0;
|
|
@@ -5874,7 +5920,7 @@ function createEngine(options) {
|
|
|
5874
5920
|
void flushed.catch(() => {
|
|
5875
5921
|
});
|
|
5876
5922
|
} else
|
|
5877
|
-
|
|
5923
|
+
schedule2();
|
|
5878
5924
|
} catch {
|
|
5879
5925
|
}
|
|
5880
5926
|
}
|
|
@@ -6745,9 +6791,9 @@ function findAction(sections, request) {
|
|
|
6745
6791
|
return actions?.find((action) => action.id === request.actionId);
|
|
6746
6792
|
}
|
|
6747
6793
|
function createCommandMenu(options) {
|
|
6748
|
-
const
|
|
6794
|
+
const logger3 = options.logger ?? createLogger2("commands");
|
|
6749
6795
|
const redact3 = createTextRedactor(options.redaction);
|
|
6750
|
-
const seam = { logger:
|
|
6796
|
+
const seam = { logger: logger3, redact: redact3 };
|
|
6751
6797
|
const now = options.now ?? Date.now;
|
|
6752
6798
|
const extras = options.extras ?? [];
|
|
6753
6799
|
const replaced = options.replace ?? {};
|
|
@@ -6774,7 +6820,7 @@ function createCommandMenu(options) {
|
|
|
6774
6820
|
content: await section.build(invocation)
|
|
6775
6821
|
};
|
|
6776
6822
|
} catch (error) {
|
|
6777
|
-
|
|
6823
|
+
logger3.warn("command menu section failed to build", {
|
|
6778
6824
|
command: options.command,
|
|
6779
6825
|
section: id,
|
|
6780
6826
|
error: redact3(error instanceof Error ? error.message : String(error))
|
|
@@ -6861,7 +6907,7 @@ function createCommandMenu(options) {
|
|
|
6861
6907
|
};
|
|
6862
6908
|
} catch (error) {
|
|
6863
6909
|
const failure2 = projectFailure(error);
|
|
6864
|
-
|
|
6910
|
+
logger3.warn("command menu action failed", {
|
|
6865
6911
|
command: options.command,
|
|
6866
6912
|
section: request.sectionId,
|
|
6867
6913
|
action: request.actionId,
|
|
@@ -7227,12 +7273,12 @@ var init_doctor = __esm({
|
|
|
7227
7273
|
});
|
|
7228
7274
|
|
|
7229
7275
|
// ../core/dist/common-auth-embedded/auth-menu/login.js
|
|
7230
|
-
import {
|
|
7231
|
-
function openBrowserForMenu(url, platform = process.platform,
|
|
7276
|
+
import { spawn as defaultSpawn } from "node:child_process";
|
|
7277
|
+
function openBrowserForMenu(url, platform = process.platform, spawn2 = defaultSpawn) {
|
|
7232
7278
|
try {
|
|
7233
7279
|
if (platform === "win32") {
|
|
7234
7280
|
const command = `Start-Process '${url.replaceAll("'", "''")}'`;
|
|
7235
|
-
const
|
|
7281
|
+
const child2 = spawn2("powershell.exe", [
|
|
7236
7282
|
"-NoProfile",
|
|
7237
7283
|
"-NonInteractive",
|
|
7238
7284
|
"-WindowStyle",
|
|
@@ -7240,17 +7286,18 @@ function openBrowserForMenu(url, platform = process.platform, execFileSync = def
|
|
|
7240
7286
|
"-EncodedCommand",
|
|
7241
7287
|
Buffer.from(command, "utf16le").toString("base64")
|
|
7242
7288
|
], { stdio: "ignore", windowsHide: true });
|
|
7243
|
-
|
|
7244
|
-
});
|
|
7245
|
-
child.unref();
|
|
7246
|
-
return child.pid !== void 0;
|
|
7247
|
-
} else {
|
|
7248
|
-
execFileSync(platform === "darwin" ? "open" : "xdg-open", [url], {
|
|
7249
|
-
stdio: "ignore",
|
|
7250
|
-
timeout: 3e3
|
|
7289
|
+
child2.on("error", () => {
|
|
7251
7290
|
});
|
|
7291
|
+
child2.unref();
|
|
7292
|
+
return child2.pid !== void 0;
|
|
7252
7293
|
}
|
|
7253
|
-
|
|
7294
|
+
const child = spawn2(platform === "darwin" ? "open" : "xdg-open", [url], {
|
|
7295
|
+
stdio: "ignore"
|
|
7296
|
+
});
|
|
7297
|
+
child.on("error", () => {
|
|
7298
|
+
});
|
|
7299
|
+
child.unref();
|
|
7300
|
+
return child.pid !== void 0;
|
|
7254
7301
|
} catch {
|
|
7255
7302
|
return false;
|
|
7256
7303
|
}
|
|
@@ -7472,7 +7519,7 @@ async function select(terminal, items, options) {
|
|
|
7472
7519
|
writeLine("");
|
|
7473
7520
|
renderedLines = lines;
|
|
7474
7521
|
};
|
|
7475
|
-
return new Promise((
|
|
7522
|
+
return new Promise((resolve20) => {
|
|
7476
7523
|
const wasRaw = stdin.isRaw ?? false;
|
|
7477
7524
|
const cleanup2 = () => {
|
|
7478
7525
|
if (cleaned)
|
|
@@ -7492,7 +7539,7 @@ async function select(terminal, items, options) {
|
|
|
7492
7539
|
};
|
|
7493
7540
|
const finish = (value) => {
|
|
7494
7541
|
cleanup2();
|
|
7495
|
-
|
|
7542
|
+
resolve20(value);
|
|
7496
7543
|
};
|
|
7497
7544
|
const onSignal = () => finish(null);
|
|
7498
7545
|
const onKey = (data) => {
|
|
@@ -7532,7 +7579,7 @@ async function select(terminal, items, options) {
|
|
|
7532
7579
|
stdin.setRawMode(true);
|
|
7533
7580
|
} catch {
|
|
7534
7581
|
cleanup2();
|
|
7535
|
-
|
|
7582
|
+
resolve20(null);
|
|
7536
7583
|
return;
|
|
7537
7584
|
}
|
|
7538
7585
|
stdin.resume();
|
|
@@ -8523,7 +8570,7 @@ function acquireInsulaQuotaSource(transport, tokenPath) {
|
|
|
8523
8570
|
}
|
|
8524
8571
|
};
|
|
8525
8572
|
}
|
|
8526
|
-
var MINUTE, MAX_AGE, sources, attempts, InsulaQuotaSource;
|
|
8573
|
+
var MINUTE, MAX_AGE, COLD_WAIT, sources, attempts, InsulaQuotaSource;
|
|
8527
8574
|
var init_insula = __esm({
|
|
8528
8575
|
"../core/dist/common-auth-embedded/claustrum/insula.js"() {
|
|
8529
8576
|
"use strict";
|
|
@@ -8531,12 +8578,16 @@ var init_insula = __esm({
|
|
|
8531
8578
|
init_watch();
|
|
8532
8579
|
MINUTE = 6e4;
|
|
8533
8580
|
MAX_AGE = 4 * MINUTE;
|
|
8581
|
+
COLD_WAIT = 2 * MINUTE;
|
|
8534
8582
|
sources = /* @__PURE__ */ new Map();
|
|
8535
8583
|
attempts = /* @__PURE__ */ new Map();
|
|
8536
8584
|
InsulaQuotaSource = class {
|
|
8537
8585
|
transport;
|
|
8538
8586
|
key;
|
|
8539
8587
|
#entries = [];
|
|
8588
|
+
#available = false;
|
|
8589
|
+
#completeProviders = /* @__PURE__ */ new Set();
|
|
8590
|
+
#coldSince = /* @__PURE__ */ new Map();
|
|
8540
8591
|
/** Every usage.get, polled or watch-driven, shares this one slot. */
|
|
8541
8592
|
#reads = new CoalescedRead(async () => {
|
|
8542
8593
|
try {
|
|
@@ -8544,8 +8595,14 @@ var init_insula = __esm({
|
|
|
8544
8595
|
if (!record2(reply) || !Array.isArray(reply.result) || reply.error !== void 0)
|
|
8545
8596
|
throw new Error("unavailable insula usage");
|
|
8546
8597
|
this.#entries = reply.result.filter((entry) => record2(entry) && typeof entry.provider === "string");
|
|
8598
|
+
this.#available = this.#entries.length === reply.result.length && (reply.completeProviders === void 0 || Array.isArray(reply.completeProviders) && reply.completeProviders.every((value) => typeof value === "string"));
|
|
8599
|
+
this.#completeProviders = new Set(this.#available && Array.isArray(reply.completeProviders) ? reply.completeProviders : []);
|
|
8600
|
+
for (const provider2 of this.#completeProviders)
|
|
8601
|
+
this.#coldSince.delete(provider2);
|
|
8547
8602
|
} catch {
|
|
8548
8603
|
this.#entries = [];
|
|
8604
|
+
this.#available = false;
|
|
8605
|
+
this.#completeProviders.clear();
|
|
8549
8606
|
}
|
|
8550
8607
|
}, () => {
|
|
8551
8608
|
});
|
|
@@ -8724,6 +8781,37 @@ var init_insula = __esm({
|
|
|
8724
8781
|
}
|
|
8725
8782
|
return void 0;
|
|
8726
8783
|
}
|
|
8784
|
+
/** Cache-only background lookup; current() retains its original miss behavior. */
|
|
8785
|
+
lookup(provider2, accountId, now) {
|
|
8786
|
+
if (!this.#available)
|
|
8787
|
+
return { miss: "unreachable" };
|
|
8788
|
+
const entry = this.#entries.find((value) => value.provider === provider2 && typeof value.account === "string" && value.account.trim() === accountId);
|
|
8789
|
+
const errorClass = (entry ?? this.#entries.find((value) => value.provider === provider2 && value.account === void 0 && value.errorClass !== void 0))?.errorClass;
|
|
8790
|
+
if (errorClass === "upstream_failed")
|
|
8791
|
+
return { miss: "upstream-failed" };
|
|
8792
|
+
if (errorClass === "credential_absent" || errorClass === "credential_unusable" || errorClass === "credential_rejected")
|
|
8793
|
+
return { miss: "credential" };
|
|
8794
|
+
if (errorClass !== void 0)
|
|
8795
|
+
return { miss: "unreachable" };
|
|
8796
|
+
if (entry) {
|
|
8797
|
+
const fetchedAt = typeof entry.fetchedAt === "string" ? Date.parse(entry.fetchedAt) : Number.NaN;
|
|
8798
|
+
if (!record2(entry.usage) || !Number.isFinite(fetchedAt))
|
|
8799
|
+
return { miss: "unreachable" };
|
|
8800
|
+
const reading = {
|
|
8801
|
+
entry,
|
|
8802
|
+
context: {
|
|
8803
|
+
fetchedAt,
|
|
8804
|
+
...typeof entry.source === "string" && { source: entry.source }
|
|
8805
|
+
}
|
|
8806
|
+
};
|
|
8807
|
+
return now >= fetchedAt + MAX_AGE || entry.stale !== void 0 ? { miss: "stale", reading } : { reading };
|
|
8808
|
+
}
|
|
8809
|
+
if (this.#completeProviders.has(provider2))
|
|
8810
|
+
return { miss: "absent" };
|
|
8811
|
+
const since = this.#coldSince.get(provider2) ?? now;
|
|
8812
|
+
this.#coldSince.set(provider2, since);
|
|
8813
|
+
return { miss: now - since >= COLD_WAIT ? "unreachable" : "cold" };
|
|
8814
|
+
}
|
|
8727
8815
|
};
|
|
8728
8816
|
}
|
|
8729
8817
|
});
|
|
@@ -8937,13 +9025,13 @@ async function readBoundedJson(path5) {
|
|
|
8937
9025
|
await descriptor.close();
|
|
8938
9026
|
}
|
|
8939
9027
|
}
|
|
8940
|
-
function accountRecords(text2,
|
|
9028
|
+
function accountRecords(text2, fields2) {
|
|
8941
9029
|
const records = [];
|
|
8942
9030
|
for (const line of text2.split("\n")) {
|
|
8943
9031
|
if (line.trim() === "" || line.startsWith("#"))
|
|
8944
9032
|
continue;
|
|
8945
9033
|
const parts = line.split(":");
|
|
8946
|
-
if (parts.length !==
|
|
9034
|
+
if (parts.length !== fields2 || !/^[^\s:,]+$/.test(parts[0] ?? "") || !/^\d+$/.test(parts[2] ?? "") || !Number.isSafeInteger(Number(parts[2])) || fields2 === 7 && (!/^\d+$/.test(parts[3] ?? "") || !Number.isSafeInteger(Number(parts[3]))) || fields2 === 4 && parts[3] !== "" && !/^[^\s:,]+(?:,[^\s:,]+)*$/.test(parts[3] ?? ""))
|
|
8947
9035
|
return void 0;
|
|
8948
9036
|
records.push(parts);
|
|
8949
9037
|
}
|
|
@@ -9493,9 +9581,9 @@ function scopedRetryReason(served, current) {
|
|
|
9493
9581
|
return "version-unchanged";
|
|
9494
9582
|
return "rotated";
|
|
9495
9583
|
}
|
|
9496
|
-
function decideScopedRetryAfter401(site, served, current,
|
|
9584
|
+
function decideScopedRetryAfter401(site, served, current, logger3 = defaultLogger) {
|
|
9497
9585
|
const retry = isScopedCredentialRotation(served, current);
|
|
9498
|
-
|
|
9586
|
+
logger3.debug("scoped 401 re-authorized", {
|
|
9499
9587
|
site,
|
|
9500
9588
|
credentialId: served.credentialId,
|
|
9501
9589
|
servedVersion: served.recordVersion,
|
|
@@ -10068,6 +10156,7 @@ var init_interlock = __esm({
|
|
|
10068
10156
|
|
|
10069
10157
|
// ../core/dist/common-auth-embedded/claustrum/roster.js
|
|
10070
10158
|
import { createHash as createHash7 } from "node:crypto";
|
|
10159
|
+
import { resolve as resolve6 } from "node:path";
|
|
10071
10160
|
function hash(value) {
|
|
10072
10161
|
return createHash7("sha256").update(value).digest("hex");
|
|
10073
10162
|
}
|
|
@@ -10288,7 +10377,7 @@ async function readVaultRoster(path5) {
|
|
|
10288
10377
|
return decodeRoster(value);
|
|
10289
10378
|
}
|
|
10290
10379
|
async function mutateVaultRoster(path5, change, options = {}) {
|
|
10291
|
-
return withLock(path5, WRITE_LOCK, async (lock) => {
|
|
10380
|
+
return withLock(path5, { ...WRITE_LOCK, signal: options.signal }, async (lock) => {
|
|
10292
10381
|
const current = await readVaultRoster(path5);
|
|
10293
10382
|
const { next, result } = await change(current, {
|
|
10294
10383
|
assertOwned: () => lock.assertOwned()
|
|
@@ -10298,6 +10387,7 @@ async function mutateVaultRoster(path5, change, options = {}) {
|
|
|
10298
10387
|
await writeJsonAtomic2(path5, next, {
|
|
10299
10388
|
beforeRename: async () => {
|
|
10300
10389
|
await options.beforePublish?.();
|
|
10390
|
+
options.signal?.throwIfAborted();
|
|
10301
10391
|
await lock.assertOwned();
|
|
10302
10392
|
}
|
|
10303
10393
|
});
|
|
@@ -10347,43 +10437,51 @@ function receiptFence(row, receipt2) {
|
|
|
10347
10437
|
return "bind";
|
|
10348
10438
|
return "refuse";
|
|
10349
10439
|
}
|
|
10350
|
-
function recordVaultQuota(path5, input2) {
|
|
10351
|
-
|
|
10352
|
-
|
|
10353
|
-
|
|
10354
|
-
|
|
10355
|
-
|
|
10356
|
-
|
|
10357
|
-
const bound = fence === "bind" ? { accountIdentity: input2.accountIdentity, unclaimed: true } : {};
|
|
10358
|
-
return {
|
|
10359
|
-
next: {
|
|
10360
|
-
...current,
|
|
10361
|
-
rows: current.rows.map((entry) => entry === row ? { ...entry, ...bound, quota } : entry)
|
|
10362
|
-
},
|
|
10363
|
-
result: true
|
|
10364
|
-
};
|
|
10440
|
+
async function recordVaultQuota(path5, input2) {
|
|
10441
|
+
const { routeId, observation, ...receipt2 } = input2;
|
|
10442
|
+
return enqueueFencedVaultQuota(path5, {
|
|
10443
|
+
routeId,
|
|
10444
|
+
observation,
|
|
10445
|
+
accountIdentity: receipt2.accountIdentity,
|
|
10446
|
+
receipt: receipt2
|
|
10365
10447
|
});
|
|
10366
10448
|
}
|
|
10449
|
+
async function enqueueFencedVaultQuota(path5, publication2) {
|
|
10450
|
+
if (!isQuotaObservation(publication2.observation))
|
|
10451
|
+
return false;
|
|
10452
|
+
const current = pendingVaultQuota(path5, await readVaultRoster(path5));
|
|
10453
|
+
if (!applyVaultQuota(current, publication2).kept)
|
|
10454
|
+
return false;
|
|
10455
|
+
return enqueueVaultQuota(path5, publication2);
|
|
10456
|
+
}
|
|
10367
10457
|
function recordVaultAccountQuota(path5, input2) {
|
|
10368
|
-
return
|
|
10369
|
-
|
|
10370
|
-
|
|
10371
|
-
|
|
10372
|
-
|
|
10373
|
-
|
|
10374
|
-
|
|
10375
|
-
|
|
10376
|
-
|
|
10377
|
-
|
|
10378
|
-
|
|
10379
|
-
|
|
10380
|
-
|
|
10458
|
+
return enqueueFencedVaultQuota(path5, input2);
|
|
10459
|
+
}
|
|
10460
|
+
function applyVaultQuota(current, input2) {
|
|
10461
|
+
const row = current?.rows.find((entry) => entry.routeId === input2.routeId);
|
|
10462
|
+
const fence = !row ? "refuse" : input2.receipt ? receiptFence(row, input2.receipt) : row.accountIdentity !== void 0 && row.accountIdentity === input2.accountIdentity ? "hold" : "refuse";
|
|
10463
|
+
if (!current || !row || fence === "refuse")
|
|
10464
|
+
return { roster: current, kept: false };
|
|
10465
|
+
const quota = mergeQuotaObservation(row.quota, input2.observation);
|
|
10466
|
+
const bound = fence === "bind" ? { accountIdentity: input2.accountIdentity, unclaimed: true } : {};
|
|
10467
|
+
return {
|
|
10468
|
+
roster: {
|
|
10469
|
+
...current,
|
|
10470
|
+
rows: current.rows.map((entry) => entry === row ? { ...entry, ...bound, quota } : entry)
|
|
10471
|
+
},
|
|
10472
|
+
kept: true
|
|
10473
|
+
};
|
|
10474
|
+
}
|
|
10475
|
+
function forgetPendingVaultDiscovery(path5) {
|
|
10476
|
+
pendingDiscoveries.delete(resolve6(path5));
|
|
10381
10477
|
}
|
|
10382
10478
|
async function refreshVaultRoster(options) {
|
|
10383
10479
|
options.signal?.throwIfAborted();
|
|
10384
10480
|
const active2 = async () => await options.isActive?.() ?? true;
|
|
10385
|
-
if (!await active2())
|
|
10481
|
+
if (!await active2()) {
|
|
10482
|
+
forgetPendingVaultDiscovery(options.path);
|
|
10386
10483
|
return void 0;
|
|
10484
|
+
}
|
|
10387
10485
|
const lease = await acquireRefreshFileLock({
|
|
10388
10486
|
...DISCOVERY_LEASE,
|
|
10389
10487
|
path: options.path,
|
|
@@ -10396,8 +10494,18 @@ async function refreshVaultRoster(options) {
|
|
|
10396
10494
|
throw new ClaustrumConsumerError("roster-busy", "Claustrum account discovery is already in progress");
|
|
10397
10495
|
return persisted;
|
|
10398
10496
|
}
|
|
10497
|
+
const key = resolve6(options.path);
|
|
10498
|
+
let discovered;
|
|
10399
10499
|
try {
|
|
10400
|
-
const
|
|
10500
|
+
const previous = await readVaultRoster(options.path);
|
|
10501
|
+
const pending = pendingDiscoveries.get(key);
|
|
10502
|
+
discovered = pending && (pending.previousView === previous?.view || pending.inventory.view === previous?.view) ? pending : {
|
|
10503
|
+
inventory: await options.custody.discover(options.signal),
|
|
10504
|
+
previousView: previous?.view
|
|
10505
|
+
};
|
|
10506
|
+
pendingDiscoveries.delete(key);
|
|
10507
|
+
const { inventory } = discovered;
|
|
10508
|
+
options.onInventory?.(inventory);
|
|
10401
10509
|
options.signal?.throwIfAborted();
|
|
10402
10510
|
return await mutateVaultRoster(options.path, async (current) => {
|
|
10403
10511
|
if (!await active2())
|
|
@@ -10408,7 +10516,16 @@ async function refreshVaultRoster(options) {
|
|
|
10408
10516
|
const next = projectVaultRoster(current, inventory, projection);
|
|
10409
10517
|
const changed = JSON.stringify(current) !== JSON.stringify(next);
|
|
10410
10518
|
return { ...changed && { next }, result: next };
|
|
10519
|
+
}, {
|
|
10520
|
+
beforePublish: async () => {
|
|
10521
|
+
options.signal?.throwIfAborted();
|
|
10522
|
+
await lease.assertOwned();
|
|
10523
|
+
}
|
|
10411
10524
|
});
|
|
10525
|
+
} catch (error) {
|
|
10526
|
+
if (error instanceof LockContentionError && discovered && !options.signal?.aborted && await active2())
|
|
10527
|
+
pendingDiscoveries.set(key, discovered);
|
|
10528
|
+
throw error;
|
|
10412
10529
|
} finally {
|
|
10413
10530
|
await lease.release();
|
|
10414
10531
|
}
|
|
@@ -10445,7 +10562,7 @@ function resolveVaultPrimary(input2) {
|
|
|
10445
10562
|
...previous && previous.accountIdentity !== identity && { replaced: previous }
|
|
10446
10563
|
};
|
|
10447
10564
|
}
|
|
10448
|
-
var DEFAULT_ROUTE_PREFIX, SKIPPED_REASONS, WRITE_LOCK, DISCOVERY_LEASE;
|
|
10565
|
+
var DEFAULT_ROUTE_PREFIX, SKIPPED_REASONS, WRITE_LOCK, DISCOVERY_LEASE, pendingDiscoveries;
|
|
10449
10566
|
var init_roster = __esm({
|
|
10450
10567
|
"../core/dist/common-auth-embedded/claustrum/roster.js"() {
|
|
10451
10568
|
"use strict";
|
|
@@ -10454,6 +10571,8 @@ var init_roster = __esm({
|
|
|
10454
10571
|
init_quota();
|
|
10455
10572
|
init_errors2();
|
|
10456
10573
|
init_interlock();
|
|
10574
|
+
init_quota_writer();
|
|
10575
|
+
init_quota_writer();
|
|
10457
10576
|
DEFAULT_ROUTE_PREFIX = "vault:";
|
|
10458
10577
|
SKIPPED_REASONS = /* @__PURE__ */ new Set([
|
|
10459
10578
|
"empty credential id",
|
|
@@ -10464,9 +10583,238 @@ var init_roster = __esm({
|
|
|
10464
10583
|
WRITE_LOCK = {
|
|
10465
10584
|
name: "claustrum-roster-write",
|
|
10466
10585
|
ttlMs: 1e4,
|
|
10467
|
-
timeoutMs: 5e3
|
|
10586
|
+
timeoutMs: 5e3,
|
|
10587
|
+
renew: true
|
|
10468
10588
|
};
|
|
10469
10589
|
DISCOVERY_LEASE = { name: "claustrum-roster", ttlMs: 3e4 };
|
|
10590
|
+
pendingDiscoveries = /* @__PURE__ */ new Map();
|
|
10591
|
+
}
|
|
10592
|
+
});
|
|
10593
|
+
|
|
10594
|
+
// ../core/dist/common-auth-embedded/claustrum/quota-writer.js
|
|
10595
|
+
import { resolve as resolve7 } from "node:path";
|
|
10596
|
+
function writerFor(path5) {
|
|
10597
|
+
const key = resolve7(path5);
|
|
10598
|
+
let writer = writers.get(key);
|
|
10599
|
+
if (!writer) {
|
|
10600
|
+
writer = {
|
|
10601
|
+
path: key,
|
|
10602
|
+
pending: /* @__PURE__ */ new Map(),
|
|
10603
|
+
listeners: /* @__PURE__ */ new Set(),
|
|
10604
|
+
wake: /* @__PURE__ */ new Set(),
|
|
10605
|
+
abort: new AbortController(),
|
|
10606
|
+
failures: 0,
|
|
10607
|
+
draining: false,
|
|
10608
|
+
order: 0
|
|
10609
|
+
};
|
|
10610
|
+
writers.set(key, writer);
|
|
10611
|
+
}
|
|
10612
|
+
return writer;
|
|
10613
|
+
}
|
|
10614
|
+
function retainVaultQuotaWriter(path5, listener) {
|
|
10615
|
+
const writer = writerFor(path5);
|
|
10616
|
+
writer.listeners.add(listener);
|
|
10617
|
+
let released;
|
|
10618
|
+
return () => released ??= (() => {
|
|
10619
|
+
writer.listeners.delete(listener);
|
|
10620
|
+
return writer.listeners.size ? Promise.resolve() : drainVaultQuota(path5);
|
|
10621
|
+
})();
|
|
10622
|
+
}
|
|
10623
|
+
function fields(publication2) {
|
|
10624
|
+
const result = /* @__PURE__ */ new Map();
|
|
10625
|
+
const { observation } = publication2;
|
|
10626
|
+
const witness = JSON.stringify([
|
|
10627
|
+
publication2.routeId,
|
|
10628
|
+
publication2.receipt?.credentialId,
|
|
10629
|
+
publication2.receipt?.accountIdentitySource,
|
|
10630
|
+
publication2.receipt?.expectedAccountIdentity
|
|
10631
|
+
]);
|
|
10632
|
+
const add = (key, at, part) => result.set(`${witness}:${key}`, {
|
|
10633
|
+
at,
|
|
10634
|
+
order: 0,
|
|
10635
|
+
publication: { ...publication2, observation: part }
|
|
10636
|
+
});
|
|
10637
|
+
const keyFor = (scope, label) => JSON.stringify([scope ?? "all", label]);
|
|
10638
|
+
const read = /* @__PURE__ */ new Set();
|
|
10639
|
+
for (const reading of observation.readings ?? []) {
|
|
10640
|
+
const key = keyFor(reading.scope, reading.label);
|
|
10641
|
+
read.add(key);
|
|
10642
|
+
add(key, observation.checkedAt, {
|
|
10643
|
+
checkedAt: observation.checkedAt,
|
|
10644
|
+
readings: [{ ...reading }]
|
|
10645
|
+
});
|
|
10646
|
+
}
|
|
10647
|
+
for (const pair of observation.coverage ?? []) {
|
|
10648
|
+
const key = keyFor(pair.scope, pair.label);
|
|
10649
|
+
if (!read.has(key))
|
|
10650
|
+
add(key, observation.checkedAt, {
|
|
10651
|
+
checkedAt: observation.checkedAt,
|
|
10652
|
+
coverage: [{ ...pair }]
|
|
10653
|
+
});
|
|
10654
|
+
}
|
|
10655
|
+
if (observation.budget)
|
|
10656
|
+
add("budget", observation.checkedAt, {
|
|
10657
|
+
checkedAt: observation.checkedAt,
|
|
10658
|
+
budget: { ...observation.budget }
|
|
10659
|
+
});
|
|
10660
|
+
for (const [name, counter] of Object.entries(observation.counters ?? {})) {
|
|
10661
|
+
add(`counter:${name}`, counter.checkedAt, {
|
|
10662
|
+
checkedAt: observation.checkedAt,
|
|
10663
|
+
counters: { [name]: { ...counter } }
|
|
10664
|
+
});
|
|
10665
|
+
}
|
|
10666
|
+
if (observation.credits)
|
|
10667
|
+
add("credits", observation.credits.checkedAt, {
|
|
10668
|
+
checkedAt: observation.checkedAt,
|
|
10669
|
+
credits: { ...observation.credits }
|
|
10670
|
+
});
|
|
10671
|
+
if (!result.size)
|
|
10672
|
+
add("empty", observation.checkedAt, { checkedAt: observation.checkedAt });
|
|
10673
|
+
return result;
|
|
10674
|
+
}
|
|
10675
|
+
function enqueueVaultQuota(path5, publication2) {
|
|
10676
|
+
if (!isQuotaObservation(publication2.observation))
|
|
10677
|
+
return Promise.resolve(false);
|
|
10678
|
+
const writer = writerFor(path5);
|
|
10679
|
+
const account = JSON.stringify([
|
|
10680
|
+
publication2.accountIdentity ?? null,
|
|
10681
|
+
publication2.accountIdentity === void 0 ? publication2.routeId : null
|
|
10682
|
+
]);
|
|
10683
|
+
const pending = writer.pending.get(account) ?? /* @__PURE__ */ new Map();
|
|
10684
|
+
for (const [key, field] of fields(publication2)) {
|
|
10685
|
+
const previous = pending.get(key);
|
|
10686
|
+
if (!previous || field.at >= previous.at) {
|
|
10687
|
+
field.order = ++writer.order;
|
|
10688
|
+
if (field.publication.observation.coverage)
|
|
10689
|
+
field.priorReading = previous?.publication.observation.readings ? previous.publication : previous?.priorReading;
|
|
10690
|
+
pending.set(key, field);
|
|
10691
|
+
}
|
|
10692
|
+
}
|
|
10693
|
+
if (pending.size)
|
|
10694
|
+
writer.pending.set(account, pending);
|
|
10695
|
+
for (const listener of writer.listeners)
|
|
10696
|
+
listener(publication2);
|
|
10697
|
+
schedule(writer, COALESCE_MS);
|
|
10698
|
+
return Promise.resolve(true);
|
|
10699
|
+
}
|
|
10700
|
+
function orderedFields(pending) {
|
|
10701
|
+
return [...pending.values()].flatMap((account) => [...account.values()]).sort((a, b) => a.order - b.order);
|
|
10702
|
+
}
|
|
10703
|
+
function pendingVaultQuota(path5, roster) {
|
|
10704
|
+
const writer = writers.get(resolve7(path5));
|
|
10705
|
+
if (writer) {
|
|
10706
|
+
for (const field of orderedFields(writer.pending)) {
|
|
10707
|
+
if (field.priorReading)
|
|
10708
|
+
roster = applyVaultQuota(roster, field.priorReading).roster;
|
|
10709
|
+
roster = applyVaultQuota(roster, field.publication).roster;
|
|
10710
|
+
}
|
|
10711
|
+
}
|
|
10712
|
+
return roster;
|
|
10713
|
+
}
|
|
10714
|
+
function schedule(writer, delay3) {
|
|
10715
|
+
if (writer.running || writer.timer || !writer.pending.size || writer.abort.signal.aborted)
|
|
10716
|
+
return;
|
|
10717
|
+
writer.timer = setTimeout(() => {
|
|
10718
|
+
writer.timer = void 0;
|
|
10719
|
+
flush(writer);
|
|
10720
|
+
}, delay3);
|
|
10721
|
+
if (!writer.draining)
|
|
10722
|
+
writer.timer.unref?.();
|
|
10723
|
+
}
|
|
10724
|
+
function flush(writer) {
|
|
10725
|
+
if (writer.running || writer.abort.signal.aborted)
|
|
10726
|
+
return;
|
|
10727
|
+
const batch = new Map([...writer.pending].map(([account, pending]) => [
|
|
10728
|
+
account,
|
|
10729
|
+
new Map(pending)
|
|
10730
|
+
]));
|
|
10731
|
+
writer.running = (async () => {
|
|
10732
|
+
try {
|
|
10733
|
+
await mutateVaultRoster(writer.path, (current) => {
|
|
10734
|
+
let next = current;
|
|
10735
|
+
for (const field of orderedFields(batch)) {
|
|
10736
|
+
if (field.priorReading)
|
|
10737
|
+
next = applyVaultQuota(next, field.priorReading).roster;
|
|
10738
|
+
next = applyVaultQuota(next, field.publication).roster;
|
|
10739
|
+
}
|
|
10740
|
+
return { ...next !== current && { next }, result: void 0 };
|
|
10741
|
+
}, { signal: writer.abort.signal });
|
|
10742
|
+
for (const [account, fields2] of batch) {
|
|
10743
|
+
const pending = writer.pending.get(account);
|
|
10744
|
+
for (const [key, field] of fields2) {
|
|
10745
|
+
if (pending?.get(key) === field)
|
|
10746
|
+
pending.delete(key);
|
|
10747
|
+
}
|
|
10748
|
+
if (!pending?.size)
|
|
10749
|
+
writer.pending.delete(account);
|
|
10750
|
+
}
|
|
10751
|
+
writer.failures = 0;
|
|
10752
|
+
} catch (error) {
|
|
10753
|
+
if (!writer.abort.signal.aborted && writer.failures++ === 0) {
|
|
10754
|
+
logger.warn("vault quota publication delayed; retrying", {
|
|
10755
|
+
error: error instanceof Error ? error.message : String(error)
|
|
10756
|
+
});
|
|
10757
|
+
}
|
|
10758
|
+
} finally {
|
|
10759
|
+
writer.running = void 0;
|
|
10760
|
+
for (const wake of writer.wake)
|
|
10761
|
+
wake();
|
|
10762
|
+
const backoff = writer.failures ? Math.min(5e3, 100 * 2 ** Math.min(writer.failures, 6)) * (0.5 + Math.random()) : COALESCE_MS;
|
|
10763
|
+
schedule(writer, backoff);
|
|
10764
|
+
}
|
|
10765
|
+
})();
|
|
10766
|
+
}
|
|
10767
|
+
async function drainVaultQuota(path5, timeoutMs = 1e3) {
|
|
10768
|
+
const key = resolve7(path5);
|
|
10769
|
+
const writer = writers.get(key);
|
|
10770
|
+
if (!writer)
|
|
10771
|
+
return;
|
|
10772
|
+
writer.draining = true;
|
|
10773
|
+
clearTimeout(writer.timer);
|
|
10774
|
+
writer.timer = void 0;
|
|
10775
|
+
let deadline;
|
|
10776
|
+
let wake;
|
|
10777
|
+
const drained = new Promise((done) => {
|
|
10778
|
+
wake = () => {
|
|
10779
|
+
if (!writer.pending.size || writer.abort.signal.aborted)
|
|
10780
|
+
done();
|
|
10781
|
+
};
|
|
10782
|
+
writer.wake.add(wake);
|
|
10783
|
+
wake();
|
|
10784
|
+
});
|
|
10785
|
+
try {
|
|
10786
|
+
if (writer.pending.size)
|
|
10787
|
+
flush(writer);
|
|
10788
|
+
await Promise.race([
|
|
10789
|
+
drained,
|
|
10790
|
+
new Promise((done) => {
|
|
10791
|
+
deadline = setTimeout(done, Math.max(0, timeoutMs));
|
|
10792
|
+
})
|
|
10793
|
+
]);
|
|
10794
|
+
} finally {
|
|
10795
|
+
clearTimeout(deadline);
|
|
10796
|
+
if (wake)
|
|
10797
|
+
writer.wake.delete(wake);
|
|
10798
|
+
writer.draining = false;
|
|
10799
|
+
if (!writer.listeners.size) {
|
|
10800
|
+
writer.abort.abort();
|
|
10801
|
+
clearTimeout(writer.timer);
|
|
10802
|
+
writer.pending.clear();
|
|
10803
|
+
if (writers.get(key) === writer)
|
|
10804
|
+
writers.delete(key);
|
|
10805
|
+
}
|
|
10806
|
+
}
|
|
10807
|
+
}
|
|
10808
|
+
var writers, logger, COALESCE_MS;
|
|
10809
|
+
var init_quota_writer = __esm({
|
|
10810
|
+
"../core/dist/common-auth-embedded/claustrum/quota-writer.js"() {
|
|
10811
|
+
"use strict";
|
|
10812
|
+
init_logger();
|
|
10813
|
+
init_quota();
|
|
10814
|
+
init_roster();
|
|
10815
|
+
writers = /* @__PURE__ */ new Map();
|
|
10816
|
+
logger = createLogger2("claustrum");
|
|
10817
|
+
COALESCE_MS = 100;
|
|
10470
10818
|
}
|
|
10471
10819
|
});
|
|
10472
10820
|
|
|
@@ -10481,6 +10829,7 @@ var init_consumer = __esm({
|
|
|
10481
10829
|
init_enrollment();
|
|
10482
10830
|
init_errors2();
|
|
10483
10831
|
init_insula();
|
|
10832
|
+
init_quota_writer();
|
|
10484
10833
|
init_roster();
|
|
10485
10834
|
init_watch();
|
|
10486
10835
|
ClaustrumConsumer = class {
|
|
@@ -10501,11 +10850,16 @@ var init_consumer = __esm({
|
|
|
10501
10850
|
#insula;
|
|
10502
10851
|
#vaultWatch;
|
|
10503
10852
|
#releaseInsulaWatch;
|
|
10853
|
+
#insulaSkips = /* @__PURE__ */ new Map();
|
|
10504
10854
|
/** When this instance last completed a discovery, by `now`. */
|
|
10505
10855
|
#discoveredAt;
|
|
10856
|
+
#releaseQuotaWriter;
|
|
10506
10857
|
constructor(options) {
|
|
10507
10858
|
this.#options = options;
|
|
10508
10859
|
this.#logger = options.logger ?? createLogger2("claustrum");
|
|
10860
|
+
this.#releaseQuotaWriter = retainVaultQuotaWriter(options.rosterPath, (publication2) => {
|
|
10861
|
+
this.#roster = applyVaultQuota(this.#roster, publication2).roster;
|
|
10862
|
+
});
|
|
10509
10863
|
}
|
|
10510
10864
|
#assertOpen(signal) {
|
|
10511
10865
|
this.#shutdown.signal.throwIfAborted();
|
|
@@ -10519,7 +10873,7 @@ var init_consumer = __esm({
|
|
|
10519
10873
|
this.#shutdown.signal,
|
|
10520
10874
|
...signal ? [signal] : []
|
|
10521
10875
|
]);
|
|
10522
|
-
return new Promise((
|
|
10876
|
+
return new Promise((resolve20, reject) => {
|
|
10523
10877
|
const cleanup2 = () => {
|
|
10524
10878
|
combined.signal.removeEventListener("abort", abort);
|
|
10525
10879
|
combined.dispose();
|
|
@@ -10534,7 +10888,7 @@ var init_consumer = __esm({
|
|
|
10534
10888
|
if (combined.signal.aborted)
|
|
10535
10889
|
reject(combined.signal.reason);
|
|
10536
10890
|
else
|
|
10537
|
-
|
|
10891
|
+
resolve20(value);
|
|
10538
10892
|
}, (error) => {
|
|
10539
10893
|
cleanup2();
|
|
10540
10894
|
reject(error);
|
|
@@ -10634,11 +10988,9 @@ var init_consumer = __esm({
|
|
|
10634
10988
|
let discovered;
|
|
10635
10989
|
const roster = await refreshVaultRoster({
|
|
10636
10990
|
path: this.#options.rosterPath,
|
|
10637
|
-
custody
|
|
10638
|
-
|
|
10639
|
-
|
|
10640
|
-
return discovered;
|
|
10641
|
-
}
|
|
10991
|
+
custody,
|
|
10992
|
+
onInventory: (inventory) => {
|
|
10993
|
+
discovered = inventory;
|
|
10642
10994
|
},
|
|
10643
10995
|
isActive: () => this.#active(),
|
|
10644
10996
|
signal: this.#shutdown.signal,
|
|
@@ -10651,7 +11003,7 @@ var init_consumer = __esm({
|
|
|
10651
11003
|
});
|
|
10652
11004
|
this.#assertOpen();
|
|
10653
11005
|
const changed = roster?.view !== this.#roster?.view;
|
|
10654
|
-
this.#roster = roster;
|
|
11006
|
+
this.#roster = pendingVaultQuota(this.#options.rosterPath, roster);
|
|
10655
11007
|
custody.retain(roster?.rows ?? []);
|
|
10656
11008
|
if (discovered && roster?.view !== void 0)
|
|
10657
11009
|
this.#grantReach = discovered.grantReach ? { view: roster.view, reach: discovered.grantReach } : void 0;
|
|
@@ -10787,13 +11139,48 @@ var init_consumer = __esm({
|
|
|
10787
11139
|
return void 0;
|
|
10788
11140
|
try {
|
|
10789
11141
|
await readClaustrumEnrollmentToken(this.#options.tokenPath);
|
|
10790
|
-
const roster = await readVaultRoster(this.#options.rosterPath);
|
|
11142
|
+
const roster = pendingVaultQuota(this.#options.rosterPath, await readVaultRoster(this.#options.rosterPath));
|
|
10791
11143
|
const row = roster?.rows.find((entry) => entry.routeId === routeId);
|
|
10792
11144
|
return this.#normalizeInsulaQuota(row?.accountIdentity);
|
|
10793
11145
|
} catch {
|
|
10794
11146
|
return void 0;
|
|
10795
11147
|
}
|
|
10796
11148
|
}
|
|
11149
|
+
/** Cache-only background lookup, preserving the reason a route has no reading. */
|
|
11150
|
+
async lookupInsulaQuotaForRoute(routeId) {
|
|
11151
|
+
const options = this.#options.insula;
|
|
11152
|
+
if (!options || this.#shutdown.signal.aborted || !await this.#active())
|
|
11153
|
+
return { miss: "unreachable" };
|
|
11154
|
+
try {
|
|
11155
|
+
await readClaustrumEnrollmentToken(this.#options.tokenPath);
|
|
11156
|
+
const roster = pendingVaultQuota(this.#options.rosterPath, await readVaultRoster(this.#options.rosterPath));
|
|
11157
|
+
const account = roster?.rows.find((row) => row.routeId === routeId)?.accountIdentity;
|
|
11158
|
+
if (!account || !this.#insula)
|
|
11159
|
+
return { miss: "unreachable" };
|
|
11160
|
+
const result = this.#insula.source.lookup(options.provider, account, (this.#options.now ?? Date.now)());
|
|
11161
|
+
const reading = result.reading && options.normalize(result.reading.entry, result.reading.context);
|
|
11162
|
+
if (result.miss)
|
|
11163
|
+
return { miss: result.miss, ...reading !== void 0 && { reading } };
|
|
11164
|
+
return reading === void 0 ? { miss: "unreachable" } : { reading };
|
|
11165
|
+
} catch {
|
|
11166
|
+
return { miss: "unreachable" };
|
|
11167
|
+
}
|
|
11168
|
+
}
|
|
11169
|
+
/** Skip the fallback poll while insula is cold or its upstream fetch failed. */
|
|
11170
|
+
async pollInsulaQuotaForRoute(routeId, fallback) {
|
|
11171
|
+
const result = await this.lookupInsulaQuotaForRoute(routeId);
|
|
11172
|
+
if (result.miss === "cold" || result.miss === "upstream-failed") {
|
|
11173
|
+
if (this.#insulaSkips.get(routeId) !== result.miss) {
|
|
11174
|
+
this.#insulaSkips.set(routeId, result.miss);
|
|
11175
|
+
this.#logger.warn("skipped insula provider poll", {
|
|
11176
|
+
reason: result.miss
|
|
11177
|
+
});
|
|
11178
|
+
}
|
|
11179
|
+
return void 0;
|
|
11180
|
+
}
|
|
11181
|
+
this.#insulaSkips.delete(routeId);
|
|
11182
|
+
return result.miss ? fallback() : result.reading;
|
|
11183
|
+
}
|
|
10797
11184
|
#normalizeInsulaQuota(accountIdentity) {
|
|
10798
11185
|
if (!this.#options.insula || !accountIdentity)
|
|
10799
11186
|
return void 0;
|
|
@@ -10816,7 +11203,7 @@ var init_consumer = __esm({
|
|
|
10816
11203
|
this.#insula = void 0;
|
|
10817
11204
|
throw new ClaustrumConsumerError("not-active", "Claustrum scoped custody is not active");
|
|
10818
11205
|
}
|
|
10819
|
-
const current = await readVaultRoster(this.#options.rosterPath);
|
|
11206
|
+
const current = pendingVaultQuota(this.#options.rosterPath, await readVaultRoster(this.#options.rosterPath));
|
|
10820
11207
|
this.#assertOpen(signal);
|
|
10821
11208
|
const observed = roster.rows.find((row) => row.routeId === routeId);
|
|
10822
11209
|
const configured = current?.rows.find((row) => row.routeId === routeId);
|
|
@@ -10895,13 +11282,13 @@ var init_consumer = __esm({
|
|
|
10895
11282
|
async decline(routeId) {
|
|
10896
11283
|
this.#assertOpen();
|
|
10897
11284
|
await declineVaultRoute(this.#options.rosterPath, routeId);
|
|
10898
|
-
this.#roster = await readVaultRoster(this.#options.rosterPath);
|
|
11285
|
+
this.#roster = pendingVaultQuota(this.#options.rosterPath, await readVaultRoster(this.#options.rosterPath));
|
|
10899
11286
|
this.#custody?.retain(this.#roster?.rows ?? []);
|
|
10900
11287
|
}
|
|
10901
11288
|
async accept(routeId) {
|
|
10902
11289
|
this.#assertOpen();
|
|
10903
11290
|
await acceptVaultRoute(this.#options.rosterPath, routeId);
|
|
10904
|
-
this.#roster = await readVaultRoster(this.#options.rosterPath);
|
|
11291
|
+
this.#roster = pendingVaultQuota(this.#options.rosterPath, await readVaultRoster(this.#options.rosterPath));
|
|
10905
11292
|
}
|
|
10906
11293
|
/**
|
|
10907
11294
|
* Store a quota or profile observation for a vault route. The receipt the
|
|
@@ -10911,7 +11298,7 @@ var init_consumer = __esm({
|
|
|
10911
11298
|
*/
|
|
10912
11299
|
async recordQuota(routeId, observation, attempt) {
|
|
10913
11300
|
this.#assertOpen();
|
|
10914
|
-
|
|
11301
|
+
return recordVaultQuota(this.#options.rosterPath, {
|
|
10915
11302
|
routeId,
|
|
10916
11303
|
observation,
|
|
10917
11304
|
credentialId: attempt.credentialId,
|
|
@@ -10923,27 +11310,21 @@ var init_consumer = __esm({
|
|
|
10923
11310
|
expectedAccountIdentity: attempt.expectedAccountIdentity
|
|
10924
11311
|
}
|
|
10925
11312
|
});
|
|
10926
|
-
if (kept)
|
|
10927
|
-
this.#roster = await readVaultRoster(this.#options.rosterPath);
|
|
10928
|
-
return kept;
|
|
10929
11313
|
}
|
|
10930
11314
|
/**
|
|
10931
11315
|
* Store a background observation that belongs to an account rather than to
|
|
10932
11316
|
* a served credential (an insula reading from `cachedInsulaQuotaForRoute`).
|
|
10933
11317
|
* It lands only while the route is still bound to that known account, so no
|
|
10934
11318
|
* credential fetch is needed and a replaced account's reading is dropped.
|
|
10935
|
-
*
|
|
11319
|
+
* Memory updates immediately; durable publication is detached and coalesced.
|
|
10936
11320
|
*/
|
|
10937
11321
|
async recordAccountQuota(routeId, accountIdentity, observation) {
|
|
10938
11322
|
this.#assertOpen();
|
|
10939
|
-
|
|
11323
|
+
return recordVaultAccountQuota(this.#options.rosterPath, {
|
|
10940
11324
|
routeId,
|
|
10941
11325
|
accountIdentity,
|
|
10942
11326
|
observation
|
|
10943
11327
|
});
|
|
10944
|
-
if (kept)
|
|
10945
|
-
this.#roster = await readVaultRoster(this.#options.rosterPath);
|
|
10946
|
-
return kept;
|
|
10947
11328
|
}
|
|
10948
11329
|
close() {
|
|
10949
11330
|
if (this.#shutdown.signal.aborted)
|
|
@@ -10958,6 +11339,13 @@ var init_consumer = __esm({
|
|
|
10958
11339
|
this.#insula = void 0;
|
|
10959
11340
|
this.#roster = void 0;
|
|
10960
11341
|
this.#grantReach = void 0;
|
|
11342
|
+
void this.#releaseQuotaWriter();
|
|
11343
|
+
forgetPendingVaultDiscovery(this.#options.rosterPath);
|
|
11344
|
+
}
|
|
11345
|
+
/** Close immediately; the last consumer also waits for the writer's bounded drain. */
|
|
11346
|
+
async dispose() {
|
|
11347
|
+
this.close();
|
|
11348
|
+
await this.#releaseQuotaWriter();
|
|
10961
11349
|
}
|
|
10962
11350
|
};
|
|
10963
11351
|
}
|
|
@@ -11000,6 +11388,7 @@ __export(claustrum_exports, {
|
|
|
11000
11388
|
declineAccount: () => declineAccount,
|
|
11001
11389
|
declineVaultRoute: () => declineVaultRoute,
|
|
11002
11390
|
disconnectClaustrumEnrollment: () => disconnectClaustrumEnrollment,
|
|
11391
|
+
drainVaultQuota: () => drainVaultQuota,
|
|
11003
11392
|
enrollmentAuthority: () => enrollmentAuthority,
|
|
11004
11393
|
enrollmentName: () => enrollmentName,
|
|
11005
11394
|
getClaustrumEnrollmentPaths: () => getClaustrumEnrollmentPaths,
|
|
@@ -11038,6 +11427,7 @@ var init_claustrum = __esm({
|
|
|
11038
11427
|
init_host_slot();
|
|
11039
11428
|
init_insula();
|
|
11040
11429
|
init_interlock();
|
|
11430
|
+
init_quota_writer();
|
|
11041
11431
|
init_roster();
|
|
11042
11432
|
init_watch();
|
|
11043
11433
|
}
|
|
@@ -11118,7 +11508,7 @@ async function acquirePiLock(authPath, onCompromised, onRenew) {
|
|
|
11118
11508
|
if (!released && lastUpdate + RENEWAL_STALE < Date.now())
|
|
11119
11509
|
compromise();
|
|
11120
11510
|
}
|
|
11121
|
-
function
|
|
11511
|
+
function schedule2(delay3 = UPDATE) {
|
|
11122
11512
|
if (released)
|
|
11123
11513
|
return;
|
|
11124
11514
|
timer = setTimeout(() => {
|
|
@@ -11132,7 +11522,7 @@ async function acquirePiLock(authPath, onCompromised, onRenew) {
|
|
|
11132
11522
|
if (errorCode(error) === "ENOENT" || lastUpdate + RENEWAL_STALE < Date.now())
|
|
11133
11523
|
compromise();
|
|
11134
11524
|
else
|
|
11135
|
-
|
|
11525
|
+
schedule2(1e3);
|
|
11136
11526
|
}
|
|
11137
11527
|
async function update() {
|
|
11138
11528
|
assertFresh();
|
|
@@ -11165,14 +11555,14 @@ async function acquirePiLock(authPath, onCompromised, onRenew) {
|
|
|
11165
11555
|
mtime = next.getTime();
|
|
11166
11556
|
lastUpdate = Date.now();
|
|
11167
11557
|
active.set(path5, { ...identity, mtime, renewedAt: lastUpdate });
|
|
11168
|
-
|
|
11558
|
+
schedule2();
|
|
11169
11559
|
}
|
|
11170
11560
|
onRenew?.(async () => {
|
|
11171
11561
|
if (timer)
|
|
11172
11562
|
clearTimeout(timer);
|
|
11173
11563
|
await update();
|
|
11174
11564
|
});
|
|
11175
|
-
|
|
11565
|
+
schedule2();
|
|
11176
11566
|
return {
|
|
11177
11567
|
assertFresh,
|
|
11178
11568
|
async release() {
|
|
@@ -11231,7 +11621,7 @@ var init_lock = __esm({
|
|
|
11231
11621
|
import { createHash as createHash8 } from "node:crypto";
|
|
11232
11622
|
import { constants as constants2 } from "node:fs";
|
|
11233
11623
|
import { lstat as lstat3, mkdir as mkdir10, open as open7, unlink as unlink7 } from "node:fs/promises";
|
|
11234
|
-
import { dirname as dirname10, resolve as
|
|
11624
|
+
import { dirname as dirname10, resolve as resolve8 } from "node:path";
|
|
11235
11625
|
import { setTimeout as sleep2 } from "node:timers/promises";
|
|
11236
11626
|
function rootSpans(text2) {
|
|
11237
11627
|
let i = text2.indexOf("{") + 1;
|
|
@@ -11432,8 +11822,8 @@ function createPiSlot(options, onStep, hooks) {
|
|
|
11432
11822
|
if (!provider2 || !options.authPath || !options.stashPath || !placeholderKey || placeholderKey.startsWith("!") || placeholderKey.includes("$") || !Number.isFinite(timeout) || timeout < 0) {
|
|
11433
11823
|
throw new PiSlotError("invalid-options");
|
|
11434
11824
|
}
|
|
11435
|
-
const authPath =
|
|
11436
|
-
const stashPath =
|
|
11825
|
+
const authPath = resolve8(options.authPath);
|
|
11826
|
+
const stashPath = resolve8(options.stashPath);
|
|
11437
11827
|
if (authPath === stashPath || stashPath === `${authPath}.lock`) {
|
|
11438
11828
|
throw new PiSlotError("invalid-options");
|
|
11439
11829
|
}
|
|
@@ -18152,7 +18542,7 @@ async function rmEvictingDir(evictingPath) {
|
|
|
18152
18542
|
});
|
|
18153
18543
|
}
|
|
18154
18544
|
async function sleep(ms) {
|
|
18155
|
-
await new Promise((
|
|
18545
|
+
await new Promise((resolve20) => setTimeout(resolve20, ms));
|
|
18156
18546
|
}
|
|
18157
18547
|
async function acquireFencedFileLock(options) {
|
|
18158
18548
|
const lockPath = `${options.path}.${options.name}.lock`;
|
|
@@ -18268,8 +18658,8 @@ function buildLock(lockPath, evictingPath, ownerId, options, now) {
|
|
|
18268
18658
|
let released = false;
|
|
18269
18659
|
let lost = false;
|
|
18270
18660
|
let lostResolve = null;
|
|
18271
|
-
let lostPromise = new Promise((
|
|
18272
|
-
lostResolve =
|
|
18661
|
+
let lostPromise = new Promise((resolve20) => {
|
|
18662
|
+
lostResolve = resolve20;
|
|
18273
18663
|
});
|
|
18274
18664
|
const markLost = () => {
|
|
18275
18665
|
if (lost)
|
|
@@ -18279,9 +18669,9 @@ function buildLock(lockPath, evictingPath, ownerId, options, now) {
|
|
|
18279
18669
|
clearInterval(renewTimer);
|
|
18280
18670
|
renewTimer = null;
|
|
18281
18671
|
}
|
|
18282
|
-
const
|
|
18672
|
+
const resolve20 = lostResolve;
|
|
18283
18673
|
lostResolve = null;
|
|
18284
|
-
|
|
18674
|
+
resolve20?.();
|
|
18285
18675
|
};
|
|
18286
18676
|
const setupRenew = () => {
|
|
18287
18677
|
if (options.renew === false)
|
|
@@ -18508,7 +18898,7 @@ var AccountStorageUnreadableError = class extends Error {
|
|
|
18508
18898
|
}
|
|
18509
18899
|
};
|
|
18510
18900
|
var RETRY_DELAYS_MS = [100, 200, 400, 800, 1e3];
|
|
18511
|
-
var DEFAULT_SLEEP = (ms) => new Promise((
|
|
18901
|
+
var DEFAULT_SLEEP = (ms) => new Promise((resolve20) => setTimeout(resolve20, ms));
|
|
18512
18902
|
var DEFAULT_BUILD_BACKUP_PATH = (path5, now) => `${path5}.corrupt-${now.toISOString().replace(/[:.]/g, "-")}`;
|
|
18513
18903
|
async function ensureSecurePermissions(path5) {
|
|
18514
18904
|
try {
|
|
@@ -18899,7 +19289,7 @@ async function saveAccountStorageReplace(path5, incoming) {
|
|
|
18899
19289
|
return mutateAccountStorage(path5, () => incoming);
|
|
18900
19290
|
}
|
|
18901
19291
|
async function clearAccountStorage(path5) {
|
|
18902
|
-
const sleep5 = (ms) => new Promise((
|
|
19292
|
+
const sleep5 = (ms) => new Promise((resolve20) => setTimeout(resolve20, ms));
|
|
18903
19293
|
const lock = await acquireWithRetry(path5, sleep5);
|
|
18904
19294
|
try {
|
|
18905
19295
|
await assertLegacyAccountStorageWritable(path5);
|
|
@@ -20090,8 +20480,8 @@ var AccountManager = class _AccountManager {
|
|
|
20090
20480
|
await this.saveInFlight;
|
|
20091
20481
|
return;
|
|
20092
20482
|
}
|
|
20093
|
-
return new Promise((
|
|
20094
|
-
this.savePromiseResolvers.push({ resolve:
|
|
20483
|
+
return new Promise((resolve20, reject) => {
|
|
20484
|
+
this.savePromiseResolvers.push({ resolve: resolve20, reject });
|
|
20095
20485
|
});
|
|
20096
20486
|
}
|
|
20097
20487
|
async dispose() {
|
|
@@ -20134,8 +20524,8 @@ var AccountManager = class _AccountManager {
|
|
|
20134
20524
|
reject(error);
|
|
20135
20525
|
throw error;
|
|
20136
20526
|
}
|
|
20137
|
-
for (const { resolve:
|
|
20138
|
-
|
|
20527
|
+
for (const { resolve: resolve20 } of resolvers)
|
|
20528
|
+
resolve20();
|
|
20139
20529
|
}
|
|
20140
20530
|
async executeSave() {
|
|
20141
20531
|
this.savePending = false;
|
|
@@ -20149,16 +20539,16 @@ var AccountManager = class _AccountManager {
|
|
|
20149
20539
|
}
|
|
20150
20540
|
try {
|
|
20151
20541
|
await this.saveToDisk();
|
|
20152
|
-
for (const { resolve:
|
|
20153
|
-
|
|
20542
|
+
for (const { resolve: resolve20 } of resolvers) {
|
|
20543
|
+
resolve20();
|
|
20154
20544
|
}
|
|
20155
20545
|
} catch (error) {
|
|
20156
20546
|
if (isStorageLockContention(error)) {
|
|
20157
20547
|
this.onDiagnostic?.("Skipped account-state persist due to storage lock contention", {
|
|
20158
20548
|
error: String(error)
|
|
20159
20549
|
});
|
|
20160
|
-
for (const { resolve:
|
|
20161
|
-
|
|
20550
|
+
for (const { resolve: resolve20 } of resolvers) {
|
|
20551
|
+
resolve20();
|
|
20162
20552
|
}
|
|
20163
20553
|
return;
|
|
20164
20554
|
}
|
|
@@ -20635,7 +21025,7 @@ function getHttpsProxy(url) {
|
|
|
20635
21025
|
}
|
|
20636
21026
|
}
|
|
20637
21027
|
function waitForHead(socket, timeoutMs, onTimeout) {
|
|
20638
|
-
return new Promise((
|
|
21028
|
+
return new Promise((resolve20, reject) => {
|
|
20639
21029
|
let buffer = Buffer3.alloc(0);
|
|
20640
21030
|
const timeout = setTimeout(() => {
|
|
20641
21031
|
onTimeout();
|
|
@@ -20658,7 +21048,7 @@ function waitForHead(socket, timeoutMs, onTimeout) {
|
|
|
20658
21048
|
return;
|
|
20659
21049
|
const head = buffer.subarray(0, marker).toString("latin1");
|
|
20660
21050
|
const leftover = buffer.subarray(marker + 4);
|
|
20661
|
-
cleanup2(() =>
|
|
21051
|
+
cleanup2(() => resolve20({ head, leftover }));
|
|
20662
21052
|
};
|
|
20663
21053
|
socket.on("data", onData);
|
|
20664
21054
|
socket.once("error", onError);
|
|
@@ -20672,7 +21062,7 @@ async function connectViaProxy(proxyUrl, targetUrl, timeoutMs, signal, onDebug)
|
|
|
20672
21062
|
port: Number(proxyUrl.port || DEFAULT_PROXY_PORT),
|
|
20673
21063
|
signal: signal ?? void 0
|
|
20674
21064
|
});
|
|
20675
|
-
await new Promise((
|
|
21065
|
+
await new Promise((resolve20, reject) => {
|
|
20676
21066
|
const timeout = setTimeout(() => {
|
|
20677
21067
|
onDebug?.(`agy transport proxy connect timeout after ${timeoutMs}ms`);
|
|
20678
21068
|
proxySocket.destroy();
|
|
@@ -20681,7 +21071,7 @@ async function connectViaProxy(proxyUrl, targetUrl, timeoutMs, signal, onDebug)
|
|
|
20681
21071
|
const cleanup2 = () => clearTimeout(timeout);
|
|
20682
21072
|
proxySocket.once("connect", () => {
|
|
20683
21073
|
cleanup2();
|
|
20684
|
-
|
|
21074
|
+
resolve20();
|
|
20685
21075
|
});
|
|
20686
21076
|
proxySocket.once("error", (error) => {
|
|
20687
21077
|
cleanup2();
|
|
@@ -20706,7 +21096,7 @@ Host: ${targetHost}:${targetPort}\r
|
|
|
20706
21096
|
if (leftover.length > 0) {
|
|
20707
21097
|
proxySocket.unshift(leftover);
|
|
20708
21098
|
}
|
|
20709
|
-
return await new Promise((
|
|
21099
|
+
return await new Promise((resolve20, reject) => {
|
|
20710
21100
|
const tlsOptions = {
|
|
20711
21101
|
socket: proxySocket,
|
|
20712
21102
|
servername: targetHost,
|
|
@@ -20721,7 +21111,7 @@ Host: ${targetHost}:${targetPort}\r
|
|
|
20721
21111
|
const cleanup2 = () => clearTimeout(timeout);
|
|
20722
21112
|
tlsSocket.once("secureConnect", () => {
|
|
20723
21113
|
cleanup2();
|
|
20724
|
-
|
|
21114
|
+
resolve20(tlsSocket);
|
|
20725
21115
|
});
|
|
20726
21116
|
tlsSocket.once("error", (error) => {
|
|
20727
21117
|
cleanup2();
|
|
@@ -20730,7 +21120,7 @@ Host: ${targetHost}:${targetPort}\r
|
|
|
20730
21120
|
});
|
|
20731
21121
|
}
|
|
20732
21122
|
async function connectDirect(targetUrl, timeoutMs, signal, onDebug) {
|
|
20733
|
-
return await new Promise((
|
|
21123
|
+
return await new Promise((resolve20, reject) => {
|
|
20734
21124
|
const tlsOptions = {
|
|
20735
21125
|
host: targetUrl.hostname,
|
|
20736
21126
|
port: Number(targetUrl.port || DEFAULT_HTTPS_PORT),
|
|
@@ -20746,7 +21136,7 @@ async function connectDirect(targetUrl, timeoutMs, signal, onDebug) {
|
|
|
20746
21136
|
const cleanup2 = () => clearTimeout(timeout);
|
|
20747
21137
|
socket.once("secureConnect", () => {
|
|
20748
21138
|
cleanup2();
|
|
20749
|
-
|
|
21139
|
+
resolve20(socket);
|
|
20750
21140
|
});
|
|
20751
21141
|
socket.once("error", (error) => {
|
|
20752
21142
|
cleanup2();
|
|
@@ -21008,6 +21398,7 @@ var ANTIGRAVITY_SCOPES = [
|
|
|
21008
21398
|
var ANTIGRAVITY_REDIRECT_URI = "http://localhost:51121/oauth-callback";
|
|
21009
21399
|
var ANTIGRAVITY_ENDPOINT_DAILY = "https://daily-cloudcode-pa.googleapis.com";
|
|
21010
21400
|
var ANTIGRAVITY_ENDPOINT_PROD = "https://cloudcode-pa.googleapis.com";
|
|
21401
|
+
var ANTIGRAVITY_QUOTA_ENDPOINT = ANTIGRAVITY_ENDPOINT_DAILY;
|
|
21011
21402
|
var ANTIGRAVITY_ENDPOINT_FALLBACKS = [
|
|
21012
21403
|
ANTIGRAVITY_ENDPOINT_DAILY,
|
|
21013
21404
|
ANTIGRAVITY_ENDPOINT_PROD
|
|
@@ -21409,9 +21800,9 @@ function projectAntigravityQuota(quota) {
|
|
|
21409
21800
|
const model = MODEL_LABELS[scope];
|
|
21410
21801
|
if (!model)
|
|
21411
21802
|
continue;
|
|
21412
|
-
const
|
|
21413
|
-
if (
|
|
21414
|
-
for (const window of
|
|
21803
|
+
const windows2 = group.windows ?? [];
|
|
21804
|
+
if (windows2.length) {
|
|
21805
|
+
for (const window of windows2) {
|
|
21415
21806
|
if (!Number.isFinite(window.remainingFraction))
|
|
21416
21807
|
continue;
|
|
21417
21808
|
const duration = window.window === "weekly" ? "7d" : "5h";
|
|
@@ -21948,11 +22339,11 @@ function containsCredential(value, credentials, projectIds, seen = /* @__PURE__
|
|
|
21948
22339
|
function redactCredentialError(error, credentials, projectIds) {
|
|
21949
22340
|
const source = error instanceof Error || error instanceof DOMException ? error : void 0;
|
|
21950
22341
|
const message = redactCredentialText(source?.message ?? String(error), credentials, projectIds);
|
|
21951
|
-
const
|
|
22342
|
+
const fields2 = source ? Reflect.ownKeys(source).map((key) => ({
|
|
21952
22343
|
key,
|
|
21953
22344
|
descriptor: Object.getOwnPropertyDescriptor(source, key)
|
|
21954
22345
|
})) : [];
|
|
21955
|
-
const cause =
|
|
22346
|
+
const cause = fields2.find(({ key }) => key === "cause")?.descriptor;
|
|
21956
22347
|
const secretCause = cause && (!("value" in cause) || containsCredential(cause.value, credentials, projectIds));
|
|
21957
22348
|
try {
|
|
21958
22349
|
if (source) {
|
|
@@ -21962,7 +22353,7 @@ function redactCredentialError(error, credentials, projectIds) {
|
|
|
21962
22353
|
configurable: true,
|
|
21963
22354
|
writable: true
|
|
21964
22355
|
});
|
|
21965
|
-
for (const { key, descriptor } of
|
|
22356
|
+
for (const { key, descriptor } of fields2) {
|
|
21966
22357
|
if (key === "message" || key === "cause" || !("value" in descriptor))
|
|
21967
22358
|
continue;
|
|
21968
22359
|
const value = scrub2(descriptor.value, credentials, projectIds);
|
|
@@ -21977,7 +22368,7 @@ function redactCredentialError(error, credentials, projectIds) {
|
|
|
21977
22368
|
}
|
|
21978
22369
|
const safe = new Error(message);
|
|
21979
22370
|
safe.name = redactCredentialText(source?.name ?? "Error", credentials, projectIds);
|
|
21980
|
-
for (const { key, descriptor } of
|
|
22371
|
+
for (const { key, descriptor } of fields2) {
|
|
21981
22372
|
if (key === "message" || key === "cause" || !("value" in descriptor))
|
|
21982
22373
|
continue;
|
|
21983
22374
|
Object.defineProperty(safe, key, {
|
|
@@ -22288,8 +22679,8 @@ function getDefaultTierId(allowedTiers) {
|
|
|
22288
22679
|
return allowedTiers[0]?.id;
|
|
22289
22680
|
}
|
|
22290
22681
|
function wait(ms) {
|
|
22291
|
-
return new Promise((
|
|
22292
|
-
setTimeout(
|
|
22682
|
+
return new Promise((resolve20) => {
|
|
22683
|
+
setTimeout(resolve20, ms);
|
|
22293
22684
|
});
|
|
22294
22685
|
}
|
|
22295
22686
|
function extractManagedProjectId(payload) {
|
|
@@ -22833,13 +23224,13 @@ function aggregateQuota(models) {
|
|
|
22833
23224
|
perModel.sort((a, b) => a.modelId.localeCompare(b.modelId));
|
|
22834
23225
|
return { groups, perModel, modelCount: totalCount };
|
|
22835
23226
|
}
|
|
22836
|
-
function mostConstrainedWindow(
|
|
22837
|
-
if (
|
|
23227
|
+
function mostConstrainedWindow(windows2) {
|
|
23228
|
+
if (windows2.length === 0)
|
|
22838
23229
|
return void 0;
|
|
22839
|
-
let best =
|
|
22840
|
-
for (let i = 1; i <
|
|
22841
|
-
if (
|
|
22842
|
-
best =
|
|
23230
|
+
let best = windows2[0];
|
|
23231
|
+
for (let i = 1; i < windows2.length; i++) {
|
|
23232
|
+
if (windows2[i].remainingFraction < best.remainingFraction) {
|
|
23233
|
+
best = windows2[i];
|
|
22843
23234
|
}
|
|
22844
23235
|
}
|
|
22845
23236
|
return {
|
|
@@ -22876,21 +23267,21 @@ function aggregateQuotaSummary(response) {
|
|
|
22876
23267
|
const groups = {};
|
|
22877
23268
|
let totalCount = 0;
|
|
22878
23269
|
for (const group of response.groups) {
|
|
22879
|
-
const
|
|
23270
|
+
const windows2 = [];
|
|
22880
23271
|
for (const bucket of group.buckets) {
|
|
22881
23272
|
const pool2 = poolForBucketId(bucket.bucketId);
|
|
22882
23273
|
if (!pool2)
|
|
22883
23274
|
continue;
|
|
22884
|
-
|
|
23275
|
+
windows2.push({
|
|
22885
23276
|
window: bucket.window,
|
|
22886
23277
|
remainingFraction: normalizeRemainingFraction(bucket.remainingFraction),
|
|
22887
23278
|
resetTime: bucket.resetTime
|
|
22888
23279
|
});
|
|
22889
23280
|
}
|
|
22890
|
-
if (
|
|
23281
|
+
if (windows2.length === 0)
|
|
22891
23282
|
continue;
|
|
22892
|
-
|
|
22893
|
-
const constrained = mostConstrainedWindow(
|
|
23283
|
+
windows2.sort((a, b) => windowDurationMs(a.window) - windowDurationMs(b.window));
|
|
23284
|
+
const constrained = mostConstrainedWindow(windows2);
|
|
22894
23285
|
const recognizedBucket = group.buckets.find((bucket) => poolForBucketId(bucket.bucketId));
|
|
22895
23286
|
if (!recognizedBucket)
|
|
22896
23287
|
continue;
|
|
@@ -22902,7 +23293,7 @@ function aggregateQuotaSummary(response) {
|
|
|
22902
23293
|
remainingFraction: constrained.remainingFraction,
|
|
22903
23294
|
resetTime: constrained.resetTime,
|
|
22904
23295
|
modelCount,
|
|
22905
|
-
windows
|
|
23296
|
+
windows: windows2
|
|
22906
23297
|
};
|
|
22907
23298
|
totalCount += modelCount;
|
|
22908
23299
|
}
|
|
@@ -24316,12 +24707,12 @@ async function commitVaultProviderState(input2) {
|
|
|
24316
24707
|
function untilAborted(pending, signal) {
|
|
24317
24708
|
if (!signal)
|
|
24318
24709
|
return pending;
|
|
24319
|
-
return new Promise((
|
|
24710
|
+
return new Promise((resolve20, reject) => {
|
|
24320
24711
|
const abort = () => reject(signal.reason);
|
|
24321
24712
|
signal.addEventListener("abort", abort, { once: true });
|
|
24322
24713
|
if (signal.aborted)
|
|
24323
24714
|
abort();
|
|
24324
|
-
pending.then(
|
|
24715
|
+
pending.then(resolve20, reject).finally(() => signal.removeEventListener("abort", abort));
|
|
24325
24716
|
});
|
|
24326
24717
|
}
|
|
24327
24718
|
var AntigravityVaultSourceError = class extends Error {
|
|
@@ -24408,7 +24799,8 @@ function createAntigravityVaultAccountSource(options) {
|
|
|
24408
24799
|
pollIntervalMs: options.pollIntervalMs
|
|
24409
24800
|
},
|
|
24410
24801
|
...options.now && { now: options.now },
|
|
24411
|
-
...options.logger && { logger: options.logger }
|
|
24802
|
+
...options.logger && { logger: options.logger },
|
|
24803
|
+
...options.insula && { insula: options.insula }
|
|
24412
24804
|
});
|
|
24413
24805
|
const issued = /* @__PURE__ */ new WeakMap();
|
|
24414
24806
|
const isDeclined2 = claustrum.isDeclined.bind(claustrum);
|
|
@@ -24520,6 +24912,37 @@ function createAntigravityVaultAccountSource(options) {
|
|
|
24520
24912
|
recordVersion: admission.recordVersion
|
|
24521
24913
|
});
|
|
24522
24914
|
},
|
|
24915
|
+
pollInsulaQuotaForRoute: async (ref, fallback, signal, onSkip) => {
|
|
24916
|
+
await assertServing(signal);
|
|
24917
|
+
assertCurrentRoute(ref);
|
|
24918
|
+
if (!consumer.pollInsulaQuotaForRoute)
|
|
24919
|
+
return fallback();
|
|
24920
|
+
let usedFallback = false;
|
|
24921
|
+
const reading = await untilAborted(consumer.pollInsulaQuotaForRoute(ref.routeId, () => {
|
|
24922
|
+
usedFallback = true;
|
|
24923
|
+
return fallback();
|
|
24924
|
+
}), signal);
|
|
24925
|
+
if (reading === void 0) {
|
|
24926
|
+
const result = consumer.lookupInsulaQuotaForRoute ? await untilAborted(consumer.lookupInsulaQuotaForRoute(ref.routeId), signal) : void 0;
|
|
24927
|
+
if (result?.miss === "cold" || result?.miss === "upstream-failed")
|
|
24928
|
+
onSkip?.(result.miss);
|
|
24929
|
+
return void 0;
|
|
24930
|
+
}
|
|
24931
|
+
if (usedFallback)
|
|
24932
|
+
return reading;
|
|
24933
|
+
if (reading.accountIdentity !== ref.accountIdentity)
|
|
24934
|
+
throw new AntigravityVaultSourceError("identity-contradicted", "The background quota reading belongs to another vault account");
|
|
24935
|
+
const admission = await admit2(ref, signal);
|
|
24936
|
+
return {
|
|
24937
|
+
...reading,
|
|
24938
|
+
quotaAttribution: {
|
|
24939
|
+
routeId: admission.routeId,
|
|
24940
|
+
credentialId: admission.credentialId,
|
|
24941
|
+
accountIdentity: admission.accountIdentity,
|
|
24942
|
+
recordVersion: admission.recordVersion
|
|
24943
|
+
}
|
|
24944
|
+
};
|
|
24945
|
+
},
|
|
24523
24946
|
commitState: async (attribution, update, signal) => {
|
|
24524
24947
|
assertOpen(signal);
|
|
24525
24948
|
if (!options.state)
|
|
@@ -24765,21 +25188,21 @@ import { randomBytes as randomBytes5 } from "node:crypto";
|
|
|
24765
25188
|
function present2(value) {
|
|
24766
25189
|
return value === null ? void 0 : value;
|
|
24767
25190
|
}
|
|
24768
|
-
function accessBlockOf(
|
|
24769
|
-
if (
|
|
24770
|
-
if (
|
|
24771
|
-
const reason = present2(
|
|
24772
|
-
const at = present2(
|
|
25191
|
+
function accessBlockOf(fields2) {
|
|
25192
|
+
if (fields2 === void 0) return { kind: "none" };
|
|
25193
|
+
if (fields2.accountIneligible === true) {
|
|
25194
|
+
const reason = present2(fields2.accountIneligibleReason);
|
|
25195
|
+
const at = present2(fields2.accountIneligibleAt);
|
|
24773
25196
|
return {
|
|
24774
25197
|
kind: "ineligible",
|
|
24775
25198
|
...reason !== void 0 ? { reason } : {},
|
|
24776
25199
|
...at !== void 0 ? { at } : {}
|
|
24777
25200
|
};
|
|
24778
25201
|
}
|
|
24779
|
-
if (
|
|
24780
|
-
const reason = present2(
|
|
24781
|
-
const verificationUrl = present2(
|
|
24782
|
-
const at = present2(
|
|
25202
|
+
if (fields2.verificationRequired === true) {
|
|
25203
|
+
const reason = present2(fields2.verificationRequiredReason);
|
|
25204
|
+
const verificationUrl = present2(fields2.verificationUrl);
|
|
25205
|
+
const at = present2(fields2.verificationRequiredAt);
|
|
24783
25206
|
return {
|
|
24784
25207
|
kind: "verification-required",
|
|
24785
25208
|
...reason !== void 0 ? { reason } : {},
|
|
@@ -24908,12 +25331,12 @@ function clearLegacyAccessBlocks(account, enableIfBlocked, now) {
|
|
|
24908
25331
|
// src/common-auth-embedded/logger/engine.js
|
|
24909
25332
|
import { appendFileSync as appendFileSync2, chmodSync as chmodSync2, existsSync as existsSync2, renameSync as renameSync2, statSync as statSync3 } from "node:fs";
|
|
24910
25333
|
import { open as open8 } from "node:fs/promises";
|
|
24911
|
-
import { dirname as dirname13, resolve as
|
|
25334
|
+
import { dirname as dirname13, resolve as resolve10 } from "node:path";
|
|
24912
25335
|
|
|
24913
25336
|
// src/common-auth-embedded/fs/private-files.js
|
|
24914
25337
|
import { randomUUID as randomUUID13 } from "node:crypto";
|
|
24915
25338
|
import { lstat as lstat4, readFile as readFile8, rename as rename7, unlink as unlink8 } from "node:fs/promises";
|
|
24916
|
-
import { dirname as dirname12, resolve as
|
|
25339
|
+
import { dirname as dirname12, resolve as resolve9 } from "node:path";
|
|
24917
25340
|
var windowsPrivateFiles2 = process.platform === "win32";
|
|
24918
25341
|
var migrationNotices2 = /* @__PURE__ */ new Set();
|
|
24919
25342
|
function ioCode2(detail) {
|
|
@@ -24964,7 +25387,7 @@ async function privateOperation2(path5, stage, operation) {
|
|
|
24964
25387
|
}
|
|
24965
25388
|
var safeParentOptionsForTest2;
|
|
24966
25389
|
async function verifySafeDirectory2(path5, options) {
|
|
24967
|
-
path5 =
|
|
25390
|
+
path5 = resolve9(path5);
|
|
24968
25391
|
options ??= safeParentOptionsForTest2;
|
|
24969
25392
|
await privateOperation2(path5, "safe-parent", async () => {
|
|
24970
25393
|
const result = await (await loadBackend2()).verifySafeParent(path5, options);
|
|
@@ -24979,7 +25402,7 @@ async function verifySafeDirectory2(path5, options) {
|
|
|
24979
25402
|
});
|
|
24980
25403
|
}
|
|
24981
25404
|
async function verifyPrivate2(path5, kind, migrate = false) {
|
|
24982
|
-
path5 =
|
|
25405
|
+
path5 = resolve9(path5);
|
|
24983
25406
|
if (kind === "directory")
|
|
24984
25407
|
return verifySafeDirectory2(path5);
|
|
24985
25408
|
await privateOperation2(path5, "verify", async () => {
|
|
@@ -25014,7 +25437,7 @@ async function verifyPrivate2(path5, kind, migrate = false) {
|
|
|
25014
25437
|
});
|
|
25015
25438
|
}
|
|
25016
25439
|
async function ensurePrivateDirectory3(path5, _migrate = false, options) {
|
|
25017
|
-
path5 =
|
|
25440
|
+
path5 = resolve9(path5);
|
|
25018
25441
|
await privateOperation2(path5, "directory", async () => {
|
|
25019
25442
|
const api = await loadBackend2();
|
|
25020
25443
|
try {
|
|
@@ -25045,7 +25468,7 @@ async function readPrivateText2(path5, migrate = false) {
|
|
|
25045
25468
|
async function readPrivateBuffer2(path5, migrate = false) {
|
|
25046
25469
|
if (!windowsPrivateFiles2)
|
|
25047
25470
|
return readFile8(path5);
|
|
25048
|
-
path5 =
|
|
25471
|
+
path5 = resolve9(path5);
|
|
25049
25472
|
if (migrate) {
|
|
25050
25473
|
await verifySafeDirectory2(dirname12(path5));
|
|
25051
25474
|
await verifyPrivate2(path5, "file", true);
|
|
@@ -25053,20 +25476,20 @@ async function readPrivateBuffer2(path5, migrate = false) {
|
|
|
25053
25476
|
return privateOperation2(path5, "read", async () => (await loadBackend2()).readOwnerOnly(path5));
|
|
25054
25477
|
}
|
|
25055
25478
|
async function createPrivateBytes2(path5, bytes) {
|
|
25056
|
-
await verifySafeDirectory2(dirname12(
|
|
25479
|
+
await verifySafeDirectory2(dirname12(resolve9(path5)));
|
|
25057
25480
|
await privateOperation2(path5, "create", async () => {
|
|
25058
|
-
await (await loadBackend2()).createPrivateFile(
|
|
25481
|
+
await (await loadBackend2()).createPrivateFile(resolve9(path5), bytes);
|
|
25059
25482
|
});
|
|
25060
25483
|
}
|
|
25061
25484
|
async function createPrivateDirectoryExclusive2(path5) {
|
|
25062
|
-
await verifySafeDirectory2(dirname12(
|
|
25485
|
+
await verifySafeDirectory2(dirname12(resolve9(path5)));
|
|
25063
25486
|
await privateOperation2(path5, "directory-create", async () => {
|
|
25064
|
-
await (await loadBackend2()).createOwnerOnly(
|
|
25487
|
+
await (await loadBackend2()).createOwnerOnly(resolve9(path5), { kind: "dir" });
|
|
25065
25488
|
});
|
|
25066
25489
|
}
|
|
25067
25490
|
async function replaceWindowsFile2(from, to, options = {}) {
|
|
25068
|
-
from =
|
|
25069
|
-
to =
|
|
25491
|
+
from = resolve9(from);
|
|
25492
|
+
to = resolve9(to);
|
|
25070
25493
|
const now = options.now ?? (() => performance.now());
|
|
25071
25494
|
const start = now();
|
|
25072
25495
|
const leaseDeadline = options.deadline ?? Infinity;
|
|
@@ -25109,7 +25532,7 @@ async function replaceWindowsFile2(from, to, options = {}) {
|
|
|
25109
25532
|
throw error;
|
|
25110
25533
|
}
|
|
25111
25534
|
async function writePrivateAtomic2(path5, bytes, options = {}) {
|
|
25112
|
-
path5 =
|
|
25535
|
+
path5 = resolve9(path5);
|
|
25113
25536
|
await ensurePrivateDirectory3(dirname12(path5));
|
|
25114
25537
|
try {
|
|
25115
25538
|
await verifyPrivate2(path5, "file", true);
|
|
@@ -25117,7 +25540,7 @@ async function writePrivateAtomic2(path5, bytes, options = {}) {
|
|
|
25117
25540
|
if (error.code !== "ENOENT")
|
|
25118
25541
|
throw error;
|
|
25119
25542
|
}
|
|
25120
|
-
const stage =
|
|
25543
|
+
const stage = resolve9(options.stagePath ?? `${path5}.${randomUUID13()}.tmp`);
|
|
25121
25544
|
if (dirname12(stage) !== dirname12(path5))
|
|
25122
25545
|
throw new PrivateFileError2(path5, "stage-directory", { code: "EXDEV" });
|
|
25123
25546
|
let created = false;
|
|
@@ -25193,15 +25616,15 @@ function createRedactor2(options = {}) {
|
|
|
25193
25616
|
return SECRET_KEY_EXACT2.test(key) || normalized.includes("apikey") || normalized.endsWith("secret") || normalized.endsWith("password") || normalized.endsWith("token") && !normalized.endsWith("tokens") || !!options.extraSecretKeys?.(normalized);
|
|
25194
25617
|
}
|
|
25195
25618
|
function errorEntries(error) {
|
|
25196
|
-
const
|
|
25619
|
+
const fields2 = error;
|
|
25197
25620
|
const entries = [
|
|
25198
25621
|
["name", error.name],
|
|
25199
25622
|
["message", error.message],
|
|
25200
25623
|
["stack", error.stack]
|
|
25201
25624
|
];
|
|
25202
25625
|
for (const key of ["code", "status", "cause"])
|
|
25203
|
-
if (
|
|
25204
|
-
entries.push([key,
|
|
25626
|
+
if (fields2[key] !== void 0)
|
|
25627
|
+
entries.push([key, fields2[key]]);
|
|
25205
25628
|
const listed = new Set(entries.map(([key]) => key));
|
|
25206
25629
|
for (const entry of Object.entries(error))
|
|
25207
25630
|
if (!listed.has(entry[0]))
|
|
@@ -25302,7 +25725,7 @@ async function openWindowsFile2(sink, file) {
|
|
|
25302
25725
|
return sink.handle;
|
|
25303
25726
|
}
|
|
25304
25727
|
async function flushWindowsFile2(sink, file, text2) {
|
|
25305
|
-
file =
|
|
25728
|
+
file = resolve10(file);
|
|
25306
25729
|
try {
|
|
25307
25730
|
if (sink.file !== file)
|
|
25308
25731
|
await closeWindowsFile2(sink);
|
|
@@ -25439,7 +25862,7 @@ function createEngine2(options) {
|
|
|
25439
25862
|
} catch {
|
|
25440
25863
|
}
|
|
25441
25864
|
}
|
|
25442
|
-
function
|
|
25865
|
+
function schedule2() {
|
|
25443
25866
|
if (!timer)
|
|
25444
25867
|
timer = setTimeout(() => {
|
|
25445
25868
|
timer = void 0;
|
|
@@ -25481,7 +25904,7 @@ function createEngine2(options) {
|
|
|
25481
25904
|
void flushed.catch(() => {
|
|
25482
25905
|
});
|
|
25483
25906
|
} else
|
|
25484
|
-
|
|
25907
|
+
schedule2();
|
|
25485
25908
|
} catch {
|
|
25486
25909
|
}
|
|
25487
25910
|
}
|
|
@@ -25697,7 +26120,7 @@ import {
|
|
|
25697
26120
|
writeFileSync
|
|
25698
26121
|
} from "node:fs";
|
|
25699
26122
|
import { homedir as homedir2 } from "node:os";
|
|
25700
|
-
import { dirname as dirname14, join as join7, resolve as
|
|
26123
|
+
import { dirname as dirname14, join as join7, resolve as resolve11 } from "node:path";
|
|
25701
26124
|
var log5 = createLogger4("storage");
|
|
25702
26125
|
var mutateAccountStorage2 = async (path5, mutate) => {
|
|
25703
26126
|
await assertLegacyPoolInUse(path5);
|
|
@@ -25885,7 +26308,7 @@ var LegacyAccountPoolRetiredError = class extends Error {
|
|
|
25885
26308
|
};
|
|
25886
26309
|
async function assertLegacyPoolInUse(legacyPath) {
|
|
25887
26310
|
try {
|
|
25888
|
-
await assertLegacyAccountStorageWritable(
|
|
26311
|
+
await assertLegacyAccountStorageWritable(resolve11(legacyPath));
|
|
25889
26312
|
} catch (error) {
|
|
25890
26313
|
throw new LegacyAccountPoolRetiredError(legacyPath, { cause: error });
|
|
25891
26314
|
}
|
|
@@ -25905,7 +26328,7 @@ function refusalMessage(admission) {
|
|
|
25905
26328
|
}
|
|
25906
26329
|
async function bindingOf(options) {
|
|
25907
26330
|
const now = options.now ?? (() => Date.now());
|
|
25908
|
-
const legacyPath =
|
|
26331
|
+
const legacyPath = resolve11(options.legacyPath ?? getStoragePath());
|
|
25909
26332
|
return {
|
|
25910
26333
|
legacyPath,
|
|
25911
26334
|
now,
|
|
@@ -25973,7 +26396,7 @@ async function openAccountStore(options) {
|
|
|
25973
26396
|
}
|
|
25974
26397
|
function initializeFreshAccountStoreFor(modules, options = {}) {
|
|
25975
26398
|
return initializeFreshAccountStore(modules, {
|
|
25976
|
-
legacyPath:
|
|
26399
|
+
legacyPath: resolve11(options.legacyPath ?? getStoragePath()),
|
|
25977
26400
|
now: options.now ?? (() => Date.now())
|
|
25978
26401
|
});
|
|
25979
26402
|
}
|
|
@@ -26150,13 +26573,13 @@ function closeDebugStream(state) {
|
|
|
26150
26573
|
state.logWriter = () => {
|
|
26151
26574
|
};
|
|
26152
26575
|
if (state.logFilePath) liveLogFilePaths.delete(state.logFilePath);
|
|
26153
|
-
return new Promise((
|
|
26154
|
-
current.once("close", () =>
|
|
26155
|
-
current.once("error", () =>
|
|
26576
|
+
return new Promise((resolve20) => {
|
|
26577
|
+
current.once("close", () => resolve20());
|
|
26578
|
+
current.once("error", () => resolve20());
|
|
26156
26579
|
try {
|
|
26157
26580
|
current.end();
|
|
26158
26581
|
} catch {
|
|
26159
|
-
|
|
26582
|
+
resolve20();
|
|
26160
26583
|
}
|
|
26161
26584
|
});
|
|
26162
26585
|
}
|
|
@@ -26428,13 +26851,13 @@ function closeDebugLog() {
|
|
|
26428
26851
|
if (!state || !current) return Promise.resolve();
|
|
26429
26852
|
state.logStream = null;
|
|
26430
26853
|
if (state.logFilePath) liveLogFilePaths.delete(state.logFilePath);
|
|
26431
|
-
return new Promise((
|
|
26432
|
-
current.once("close", () =>
|
|
26433
|
-
current.once("error", () =>
|
|
26854
|
+
return new Promise((resolve20) => {
|
|
26855
|
+
current.once("close", () => resolve20());
|
|
26856
|
+
current.once("error", () => resolve20());
|
|
26434
26857
|
try {
|
|
26435
26858
|
current.end();
|
|
26436
26859
|
} catch {
|
|
26437
|
-
|
|
26860
|
+
resolve20();
|
|
26438
26861
|
}
|
|
26439
26862
|
});
|
|
26440
26863
|
}
|
|
@@ -27416,8 +27839,8 @@ var openCodeStore = {
|
|
|
27416
27839
|
clear: async () => {
|
|
27417
27840
|
}
|
|
27418
27841
|
};
|
|
27419
|
-
function defaultDiagnostic(message,
|
|
27420
|
-
debugLogToFile(
|
|
27842
|
+
function defaultDiagnostic(message, fields2) {
|
|
27843
|
+
debugLogToFile(fields2 ? `${message} ${JSON.stringify(fields2)}` : message);
|
|
27421
27844
|
}
|
|
27422
27845
|
var AccountStoreNotReadyError = class extends Error {
|
|
27423
27846
|
read;
|
|
@@ -27516,7 +27939,7 @@ import { z as z4 } from "zod";
|
|
|
27516
27939
|
// src/plugin/config/loader.ts
|
|
27517
27940
|
import { existsSync as existsSync4, readFileSync as readFileSync2, realpathSync } from "node:fs";
|
|
27518
27941
|
import { homedir as homedir4 } from "node:os";
|
|
27519
|
-
import { basename as basename4, dirname as dirname15, join as join9, resolve as
|
|
27942
|
+
import { basename as basename4, dirname as dirname15, join as join9, resolve as resolve12 } from "node:path";
|
|
27520
27943
|
|
|
27521
27944
|
// src/plugin/config/schema.ts
|
|
27522
27945
|
import { z } from "zod";
|
|
@@ -28074,13 +28497,13 @@ function loadConfigWithLogger(directory, log16) {
|
|
|
28074
28497
|
return config;
|
|
28075
28498
|
}
|
|
28076
28499
|
function createLocationConfig(directory, options) {
|
|
28077
|
-
const
|
|
28078
|
-
if (typeof
|
|
28500
|
+
const logger3 = options?.logger;
|
|
28501
|
+
if (typeof logger3?.warn !== "function") {
|
|
28079
28502
|
throw new TypeError(
|
|
28080
28503
|
"createLocationConfig requires a logger with a warn function"
|
|
28081
28504
|
);
|
|
28082
28505
|
}
|
|
28083
|
-
const config = loadConfigWithLogger(directory,
|
|
28506
|
+
const config = loadConfigWithLogger(directory, logger3);
|
|
28084
28507
|
return {
|
|
28085
28508
|
directory,
|
|
28086
28509
|
config,
|
|
@@ -28090,7 +28513,7 @@ function createLocationConfig(directory, options) {
|
|
|
28090
28513
|
};
|
|
28091
28514
|
}
|
|
28092
28515
|
function canonicalizeOwnedPath(path5) {
|
|
28093
|
-
const absolute =
|
|
28516
|
+
const absolute = resolve12(path5);
|
|
28094
28517
|
const missing = [];
|
|
28095
28518
|
let current = absolute;
|
|
28096
28519
|
for (; ; ) {
|
|
@@ -28820,7 +29243,7 @@ function normalizeQuota(input2) {
|
|
|
28820
29243
|
const resetAt = toFiniteNumber(record3.resetAt) ?? void 0;
|
|
28821
29244
|
const checkedAt = toFiniteNumber(record3.checkedAt) ?? void 0;
|
|
28822
29245
|
const windowsRaw = record3.windows;
|
|
28823
|
-
let
|
|
29246
|
+
let windows2;
|
|
28824
29247
|
if (Array.isArray(windowsRaw)) {
|
|
28825
29248
|
const parsed = windowsRaw.filter(isObject).map((w) => {
|
|
28826
29249
|
const win = w.window;
|
|
@@ -28839,14 +29262,14 @@ function normalizeQuota(input2) {
|
|
|
28839
29262
|
...ca !== null && ca >= 0 ? { checkedAt: ca } : {}
|
|
28840
29263
|
};
|
|
28841
29264
|
}).filter((v) => v !== null);
|
|
28842
|
-
if (parsed.length > 0)
|
|
29265
|
+
if (parsed.length > 0) windows2 = parsed;
|
|
28843
29266
|
}
|
|
28844
29267
|
return {
|
|
28845
29268
|
remainingPercent: clampNumber(remaining, 0, 100),
|
|
28846
29269
|
...fraction !== null ? { remainingFraction: clampNumber(fraction, 0, 1) } : {},
|
|
28847
29270
|
resetAt,
|
|
28848
29271
|
...checkedAt !== void 0 ? { checkedAt } : {},
|
|
28849
|
-
windows
|
|
29272
|
+
windows: windows2
|
|
28850
29273
|
};
|
|
28851
29274
|
}
|
|
28852
29275
|
function normalizeRouting(input2) {
|
|
@@ -28966,7 +29389,7 @@ function projectQuotaPoolForSidebar(source, checkedAt) {
|
|
|
28966
29389
|
const parsed = Date.parse(source.resetTime);
|
|
28967
29390
|
if (Number.isFinite(parsed)) resetAt = parsed;
|
|
28968
29391
|
}
|
|
28969
|
-
const
|
|
29392
|
+
const windows2 = source.windows?.length ? source.windows.map((w) => ({
|
|
28970
29393
|
window: w.window,
|
|
28971
29394
|
...readingAt !== void 0 ? { checkedAt: readingAt } : {},
|
|
28972
29395
|
remainingPercent: clampNumber(
|
|
@@ -28984,7 +29407,7 @@ function projectQuotaPoolForSidebar(source, checkedAt) {
|
|
|
28984
29407
|
remainingPercent,
|
|
28985
29408
|
remainingFraction: clampNumber(fraction, 0, 1),
|
|
28986
29409
|
resetAt,
|
|
28987
|
-
windows,
|
|
29410
|
+
windows: windows2,
|
|
28988
29411
|
...readingAt !== void 0 ? { checkedAt: readingAt } : {}
|
|
28989
29412
|
};
|
|
28990
29413
|
}
|
|
@@ -29051,7 +29474,7 @@ function drainSidebarWrites() {
|
|
|
29051
29474
|
return sidebarWriteChain;
|
|
29052
29475
|
}
|
|
29053
29476
|
async function sleep3(ms) {
|
|
29054
|
-
await new Promise((
|
|
29477
|
+
await new Promise((resolve20) => setTimeout(resolve20, ms));
|
|
29055
29478
|
}
|
|
29056
29479
|
async function acquireSidebarLockWithRetry(stateFile) {
|
|
29057
29480
|
const start = Date.now();
|
|
@@ -29229,7 +29652,7 @@ function createLocationQuotaManager(options) {
|
|
|
29229
29652
|
fetchTimeoutMs: options.fetchTimeoutMs
|
|
29230
29653
|
});
|
|
29231
29654
|
const sidebar = options.sidebar;
|
|
29232
|
-
const
|
|
29655
|
+
const logger3 = options.logger;
|
|
29233
29656
|
return withSidebarPushAfterRefresh(
|
|
29234
29657
|
manager,
|
|
29235
29658
|
sidebar ? (account) => pushSidebarQuotaSnapshot(
|
|
@@ -29238,7 +29661,7 @@ function createLocationQuotaManager(options) {
|
|
|
29238
29661
|
sidebar.getActiveIndexByFamily,
|
|
29239
29662
|
{
|
|
29240
29663
|
write: sidebar.write,
|
|
29241
|
-
logger:
|
|
29664
|
+
logger: logger3,
|
|
29242
29665
|
healthScore: sidebar.healthScore ?? null,
|
|
29243
29666
|
now: sidebar.now
|
|
29244
29667
|
}
|
|
@@ -29375,7 +29798,7 @@ async function fetchLegacyModelsFallback(options) {
|
|
|
29375
29798
|
const modelsResponse = await fetchAvailableModels({
|
|
29376
29799
|
accessToken: options.accessToken,
|
|
29377
29800
|
projectId: options.projectId,
|
|
29378
|
-
endpoints:
|
|
29801
|
+
endpoints: [ANTIGRAVITY_QUOTA_ENDPOINT],
|
|
29379
29802
|
userAgent: buildAntigravityHarnessUserAgent(),
|
|
29380
29803
|
timeoutMs: 1e4,
|
|
29381
29804
|
...options.fetchVia ? { fetchVia: options.fetchVia } : {}
|
|
@@ -29404,7 +29827,7 @@ async function fetchQuotaPayloads(options) {
|
|
|
29404
29827
|
accessToken,
|
|
29405
29828
|
managedProjectId,
|
|
29406
29829
|
projectId,
|
|
29407
|
-
endpoints:
|
|
29830
|
+
endpoints: [ANTIGRAVITY_QUOTA_ENDPOINT],
|
|
29408
29831
|
userAgent: buildAntigravityHarnessUserAgent(),
|
|
29409
29832
|
timeoutMs: 1e4,
|
|
29410
29833
|
...fetchVia ? { fetchVia } : {}
|
|
@@ -29521,7 +29944,7 @@ async function fetchVaultAccountQuota(options) {
|
|
|
29521
29944
|
return result;
|
|
29522
29945
|
};
|
|
29523
29946
|
const fetchSummary = async () => {
|
|
29524
|
-
for (const endpoint of
|
|
29947
|
+
for (const endpoint of [ANTIGRAVITY_QUOTA_ENDPOINT]) {
|
|
29525
29948
|
const result = await attempt(
|
|
29526
29949
|
async (grant, fetchVia) => aggregateQuotaSummary(
|
|
29527
29950
|
(await fetchQuotaSummary({
|
|
@@ -29543,7 +29966,7 @@ async function fetchVaultAccountQuota(options) {
|
|
|
29543
29966
|
}
|
|
29544
29967
|
if (result.refused) break;
|
|
29545
29968
|
}
|
|
29546
|
-
for (const endpoint of
|
|
29969
|
+
for (const endpoint of [ANTIGRAVITY_QUOTA_ENDPOINT]) {
|
|
29547
29970
|
for (const withProject of [true, false]) {
|
|
29548
29971
|
const result = await attempt(
|
|
29549
29972
|
(grant, fetchVia) => fetchAvailableModels({
|
|
@@ -29602,14 +30025,14 @@ var LocalQuotaGrantStaleError = class extends Error {
|
|
|
29602
30025
|
name = "LocalQuotaGrantStaleError";
|
|
29603
30026
|
};
|
|
29604
30027
|
function untilQuotaAborted(pending, signal) {
|
|
29605
|
-
return new Promise((
|
|
30028
|
+
return new Promise((resolve20, reject) => {
|
|
29606
30029
|
const abort = () => reject(signal.reason);
|
|
29607
30030
|
if (signal.aborted) abort();
|
|
29608
30031
|
else signal.addEventListener("abort", abort, { once: true });
|
|
29609
30032
|
void pending.then(
|
|
29610
30033
|
(value) => {
|
|
29611
30034
|
signal.removeEventListener("abort", abort);
|
|
29612
|
-
|
|
30035
|
+
resolve20(value);
|
|
29613
30036
|
},
|
|
29614
30037
|
(error) => {
|
|
29615
30038
|
signal.removeEventListener("abort", abort);
|
|
@@ -29686,6 +30109,14 @@ function createAuthorizedFetchAccountQuota(options) {
|
|
|
29686
30109
|
error: `quota check refused (stale grant: ${staleReason})`
|
|
29687
30110
|
};
|
|
29688
30111
|
}
|
|
30112
|
+
if (payloads.quota.error) {
|
|
30113
|
+
return {
|
|
30114
|
+
...base,
|
|
30115
|
+
status: "error",
|
|
30116
|
+
disabled: false,
|
|
30117
|
+
error: payloads.quota.error
|
|
30118
|
+
};
|
|
30119
|
+
}
|
|
29689
30120
|
return {
|
|
29690
30121
|
...base,
|
|
29691
30122
|
status: "ok",
|
|
@@ -29761,6 +30192,7 @@ function makeFetchAccountQuota(client, providerId, fetchVia) {
|
|
|
29761
30192
|
}),
|
|
29762
30193
|
signal
|
|
29763
30194
|
);
|
|
30195
|
+
if (payloads.quota.error) throw new Error(payloads.quota.error);
|
|
29764
30196
|
return {
|
|
29765
30197
|
index,
|
|
29766
30198
|
email: account.email,
|
|
@@ -29816,6 +30248,7 @@ function makeFetchAccountQuota(client, providerId, fetchVia) {
|
|
|
29816
30248
|
logger: log7
|
|
29817
30249
|
});
|
|
29818
30250
|
quotaResult = payloads.quota;
|
|
30251
|
+
if (quotaResult.error) throw new Error(quotaResult.error);
|
|
29819
30252
|
fellBackToLegacy = payloads.fellBackToLegacy;
|
|
29820
30253
|
for (const [family, groupQuota] of Object.entries(quotaResult.groups)) {
|
|
29821
30254
|
const remainingPercent = (groupQuota.remainingFraction ?? 0) * 100;
|
|
@@ -29959,7 +30392,7 @@ function heldAccount(manager, ref) {
|
|
|
29959
30392
|
);
|
|
29960
30393
|
}
|
|
29961
30394
|
function createStoreQuotaService(options) {
|
|
29962
|
-
const { manager, logger:
|
|
30395
|
+
const { manager, logger: logger3 } = options;
|
|
29963
30396
|
const credentials = options.credentials ?? createLocalAccountCredentials(manager, { repository: options.repository });
|
|
29964
30397
|
const authorize = async (account, _signal, purpose = "required") => {
|
|
29965
30398
|
const ref = account.rowRef;
|
|
@@ -30032,11 +30465,11 @@ function createStoreQuotaService(options) {
|
|
|
30032
30465
|
};
|
|
30033
30466
|
const fetchAccountQuota = createAuthorizedFetchAccountQuota({
|
|
30034
30467
|
authorize: (account) => authorize(account),
|
|
30035
|
-
logger:
|
|
30468
|
+
logger: logger3,
|
|
30036
30469
|
transport: options.transport
|
|
30037
30470
|
});
|
|
30038
30471
|
const quotaManager = createLocationQuotaManager({
|
|
30039
|
-
logger:
|
|
30472
|
+
logger: logger3,
|
|
30040
30473
|
fetchAccountQuota,
|
|
30041
30474
|
// Backoff and cache are per credential: a re-authenticated row starts
|
|
30042
30475
|
// fresh instead of inheriting its predecessor's state.
|
|
@@ -30109,7 +30542,7 @@ function createStoreQuotaService(options) {
|
|
|
30109
30542
|
(failure2) => failure2.rowId
|
|
30110
30543
|
);
|
|
30111
30544
|
failedRows = report === void 0 || failedIds.length === 0 || failedIds.some((id) => id === void 0) ? "all" : new Set(failedIds.filter((id) => id !== void 0));
|
|
30112
|
-
|
|
30545
|
+
logger3.debug("quota readings were not all persisted", {
|
|
30113
30546
|
error: error instanceof Error ? error.message : String(error)
|
|
30114
30547
|
});
|
|
30115
30548
|
}
|
|
@@ -33424,6 +33857,7 @@ var NATIVE_GOOGLE_ERROR_MESSAGES = {
|
|
|
33424
33857
|
operator_policy: "Antigravity account pool is unavailable under the operator quota policy. Adjust /antigravity-killswitch or refresh quota.",
|
|
33425
33858
|
soft_quota: "Antigravity account pool is unavailable under the quota protection policy. Add accounts, wait for quota reset, or disable soft quota protection.",
|
|
33426
33859
|
pool_unavailable: "Antigravity account pool has no account available within the configured wait limit. Add accounts with `opencode auth login` or wait for quota reset.",
|
|
33860
|
+
model_unavailable: "The requested Antigravity model is not available to the configured accounts. Choose another model.",
|
|
33427
33861
|
missing_access_token: "Missing access token. Run `opencode auth login` to reauthenticate.",
|
|
33428
33862
|
empty_response: "Antigravity returned an empty response after the internal retry attempts."
|
|
33429
33863
|
};
|
|
@@ -35459,12 +35893,12 @@ async function startOAuthListener({
|
|
|
35459
35893
|
let resolveCallback;
|
|
35460
35894
|
let rejectCallback;
|
|
35461
35895
|
let timeoutHandle;
|
|
35462
|
-
const callbackPromise = new Promise((
|
|
35896
|
+
const callbackPromise = new Promise((resolve20, reject) => {
|
|
35463
35897
|
resolveCallback = (url) => {
|
|
35464
35898
|
if (settled) return;
|
|
35465
35899
|
settled = true;
|
|
35466
35900
|
if (timeoutHandle) clearTimeout(timeoutHandle);
|
|
35467
|
-
|
|
35901
|
+
resolve20(url);
|
|
35468
35902
|
};
|
|
35469
35903
|
rejectCallback = (error) => {
|
|
35470
35904
|
if (settled) return;
|
|
@@ -35623,7 +36057,7 @@ async function startOAuthListener({
|
|
|
35623
36057
|
});
|
|
35624
36058
|
});
|
|
35625
36059
|
const bindAddress = getBindAddress();
|
|
35626
|
-
await new Promise((
|
|
36060
|
+
await new Promise((resolve20, reject) => {
|
|
35627
36061
|
const handleError = (error) => {
|
|
35628
36062
|
server.off("error", handleError);
|
|
35629
36063
|
if (error.code === "EADDRINUSE") {
|
|
@@ -35639,7 +36073,7 @@ async function startOAuthListener({
|
|
|
35639
36073
|
server.once("error", handleError);
|
|
35640
36074
|
server.listen(port, bindAddress, () => {
|
|
35641
36075
|
server.off("error", handleError);
|
|
35642
|
-
|
|
36076
|
+
resolve20();
|
|
35643
36077
|
});
|
|
35644
36078
|
});
|
|
35645
36079
|
server.on("error", (error) => {
|
|
@@ -35647,7 +36081,7 @@ async function startOAuthListener({
|
|
|
35647
36081
|
});
|
|
35648
36082
|
return {
|
|
35649
36083
|
waitForCallback: () => callbackPromise,
|
|
35650
|
-
close: () => new Promise((
|
|
36084
|
+
close: () => new Promise((resolve20, reject) => {
|
|
35651
36085
|
server.close((error) => {
|
|
35652
36086
|
if (error && error.code !== "ERR_SERVER_NOT_RUNNING") {
|
|
35653
36087
|
reject(error);
|
|
@@ -35656,7 +36090,7 @@ async function startOAuthListener({
|
|
|
35656
36090
|
if (!settled) {
|
|
35657
36091
|
rejectCallback(new Error("OAuth listener closed before callback"));
|
|
35658
36092
|
}
|
|
35659
|
-
|
|
36093
|
+
resolve20();
|
|
35660
36094
|
});
|
|
35661
36095
|
})
|
|
35662
36096
|
};
|
|
@@ -35667,7 +36101,7 @@ async function startOAuthListener({
|
|
|
35667
36101
|
}
|
|
35668
36102
|
|
|
35669
36103
|
// src/plugin/session-context.ts
|
|
35670
|
-
import { resolve as
|
|
36104
|
+
import { resolve as resolve13 } from "node:path";
|
|
35671
36105
|
import { pathToFileURL } from "node:url";
|
|
35672
36106
|
var FALLBACK_SESSION_KEY = "__default__";
|
|
35673
36107
|
function extractOpenCodeSessionIdentity(headers) {
|
|
@@ -35681,7 +36115,7 @@ var AgySessionRegistry = class {
|
|
|
35681
36115
|
requestSessions;
|
|
35682
36116
|
parentSessionIds = /* @__PURE__ */ new Map();
|
|
35683
36117
|
constructor(directory, options = {}) {
|
|
35684
|
-
const workspaceUri = directory ? pathToFileURL(
|
|
36118
|
+
const workspaceUri = directory ? pathToFileURL(resolve13(directory)).href : "";
|
|
35685
36119
|
this.requestSessions = new AgyRequestSessionStore(workspaceUri, options);
|
|
35686
36120
|
}
|
|
35687
36121
|
getOrCreate(identity) {
|
|
@@ -36306,10 +36740,10 @@ async function retainResponseLifetime(response, cancellation) {
|
|
|
36306
36740
|
cancellation.release();
|
|
36307
36741
|
throw error;
|
|
36308
36742
|
}
|
|
36309
|
-
let
|
|
36743
|
+
let resolve20 = () => {
|
|
36310
36744
|
};
|
|
36311
36745
|
const settled = new Promise((done) => {
|
|
36312
|
-
|
|
36746
|
+
resolve20 = done;
|
|
36313
36747
|
});
|
|
36314
36748
|
let stopping = false;
|
|
36315
36749
|
let finished = false;
|
|
@@ -36319,7 +36753,7 @@ async function retainResponseLifetime(response, cancellation) {
|
|
|
36319
36753
|
finished = true;
|
|
36320
36754
|
cancellation.signal.removeEventListener("abort", abort);
|
|
36321
36755
|
cancellation.release();
|
|
36322
|
-
|
|
36756
|
+
resolve20();
|
|
36323
36757
|
};
|
|
36324
36758
|
const abort = () => {
|
|
36325
36759
|
if (finished || stopping) return;
|
|
@@ -36388,8 +36822,8 @@ function createAfterHandoff(work, signals, onFailure) {
|
|
|
36388
36822
|
let running = false;
|
|
36389
36823
|
let resolveCompletion = () => {
|
|
36390
36824
|
};
|
|
36391
|
-
const completion = new Promise((
|
|
36392
|
-
resolveCompletion =
|
|
36825
|
+
const completion = new Promise((resolve20) => {
|
|
36826
|
+
resolveCompletion = resolve20;
|
|
36393
36827
|
});
|
|
36394
36828
|
const finish = () => {
|
|
36395
36829
|
if (finished) return;
|
|
@@ -36436,14 +36870,14 @@ function createAfterHandoff(work, signals, onFailure) {
|
|
|
36436
36870
|
};
|
|
36437
36871
|
}
|
|
36438
36872
|
function publishResponse(dispatch) {
|
|
36439
|
-
return new Promise((
|
|
36873
|
+
return new Promise((resolve20, reject) => {
|
|
36440
36874
|
let acknowledge;
|
|
36441
36875
|
void Promise.resolve().then(
|
|
36442
36876
|
() => dispatch((callback) => {
|
|
36443
36877
|
acknowledge = callback;
|
|
36444
36878
|
})
|
|
36445
36879
|
).then((response) => {
|
|
36446
|
-
|
|
36880
|
+
resolve20(response);
|
|
36447
36881
|
acknowledge?.();
|
|
36448
36882
|
}, reject);
|
|
36449
36883
|
});
|
|
@@ -36545,7 +36979,7 @@ function formatWaitTime(ms) {
|
|
|
36545
36979
|
return remainingMinutes > 0 ? `${hours}h ${remainingMinutes}m` : `${hours}h`;
|
|
36546
36980
|
}
|
|
36547
36981
|
function sleep4(ms, signal) {
|
|
36548
|
-
return new Promise((
|
|
36982
|
+
return new Promise((resolve20, reject) => {
|
|
36549
36983
|
if (signal?.aborted) {
|
|
36550
36984
|
reject(
|
|
36551
36985
|
signal.reason instanceof Error ? signal.reason : new Error("Aborted")
|
|
@@ -36554,7 +36988,7 @@ function sleep4(ms, signal) {
|
|
|
36554
36988
|
}
|
|
36555
36989
|
const timeout = setTimeout(() => {
|
|
36556
36990
|
cleanup2();
|
|
36557
|
-
|
|
36991
|
+
resolve20();
|
|
36558
36992
|
}, ms);
|
|
36559
36993
|
const onAbort = () => {
|
|
36560
36994
|
cleanup2();
|
|
@@ -36810,6 +37244,7 @@ function createRequestExecutor(deps) {
|
|
|
36810
37244
|
let localRecaptureUsed = false;
|
|
36811
37245
|
const maxWaitMs = (config.max_rate_limit_wait_seconds ?? 300) * 1e3;
|
|
36812
37246
|
let allAccountsBlockedAt;
|
|
37247
|
+
const modelUnavailableIndexes = /* @__PURE__ */ new Set();
|
|
36813
37248
|
while (true) {
|
|
36814
37249
|
await assertAdmission();
|
|
36815
37250
|
checkAborted();
|
|
@@ -36873,6 +37308,26 @@ function createRequestExecutor(deps) {
|
|
|
36873
37308
|
const killedIndexes = eligibleIndexes === null ? void 0 : new Set(
|
|
36874
37309
|
accountManager.getAccounts().map((entry) => entry.index).filter((index) => !eligibleIndexes.has(index))
|
|
36875
37310
|
);
|
|
37311
|
+
if (modelUnavailableIndexes.size > 0) {
|
|
37312
|
+
const candidates = accountManager.getEnabledAccounts().filter(
|
|
37313
|
+
(entry) => eligibleIndexes === null || eligibleIndexes.has(entry.index)
|
|
37314
|
+
);
|
|
37315
|
+
if (candidates.length > 0 && candidates.every((entry) => modelUnavailableIndexes.has(entry.index))) {
|
|
37316
|
+
pushDebug(
|
|
37317
|
+
`model-unavailable: all ${candidates.length} eligible account(s) skipped`
|
|
37318
|
+
);
|
|
37319
|
+
log16.warn("model-unavailable-all-accounts", {
|
|
37320
|
+
family,
|
|
37321
|
+
model,
|
|
37322
|
+
accounts: candidates.length
|
|
37323
|
+
});
|
|
37324
|
+
return createNativeGoogleErrorResponse({
|
|
37325
|
+
status: 412,
|
|
37326
|
+
reason: "model_unavailable"
|
|
37327
|
+
});
|
|
37328
|
+
}
|
|
37329
|
+
}
|
|
37330
|
+
const excludedIndexes = modelUnavailableIndexes.size === 0 ? killedIndexes : /* @__PURE__ */ new Set([...killedIndexes ?? [], ...modelUnavailableIndexes]);
|
|
36876
37331
|
let account = accountManager.getCurrentOrNextForFamily(
|
|
36877
37332
|
family,
|
|
36878
37333
|
model,
|
|
@@ -36881,7 +37336,7 @@ function createRequestExecutor(deps) {
|
|
|
36881
37336
|
config.soft_quota_threshold_percent,
|
|
36882
37337
|
softQuotaCacheTtlMs,
|
|
36883
37338
|
accountSessionIdentity,
|
|
36884
|
-
|
|
37339
|
+
excludedIndexes
|
|
36885
37340
|
);
|
|
36886
37341
|
if (account && eligibleIndexes !== null && !eligibleIndexes.has(account.index)) {
|
|
36887
37342
|
pushDebug(
|
|
@@ -37348,6 +37803,7 @@ function createRequestExecutor(deps) {
|
|
|
37348
37803
|
};
|
|
37349
37804
|
let apiRequestCount = 0;
|
|
37350
37805
|
let shouldSwitchAccount = false;
|
|
37806
|
+
let skippedForModelUnavailable = false;
|
|
37351
37807
|
if (account.fingerprint) {
|
|
37352
37808
|
pushDebug(
|
|
37353
37809
|
`fingerprint: deviceId=${account.fingerprint.deviceId.slice(0, 8)}...`
|
|
@@ -37727,6 +38183,37 @@ function createRequestExecutor(deps) {
|
|
|
37727
38183
|
shouldSwitchAccount = true;
|
|
37728
38184
|
break;
|
|
37729
38185
|
}
|
|
38186
|
+
if (response.status === 404 && currentEndpoint === ANTIGRAVITY_ENDPOINT_DAILY) {
|
|
38187
|
+
const notFoundBody = await deadline.wait(
|
|
38188
|
+
() => response.clone().text().catch(() => "")
|
|
38189
|
+
);
|
|
38190
|
+
const unavailable = parseModelUnavailableError(notFoundBody);
|
|
38191
|
+
if (unavailable) {
|
|
38192
|
+
if (tokenConsumed) {
|
|
38193
|
+
trackers.token.refund(account.index);
|
|
38194
|
+
tokenConsumed = false;
|
|
38195
|
+
}
|
|
38196
|
+
const reasonCodes = unavailable.reasons.length > 0 ? unavailable.reasons.join(",") : "none";
|
|
38197
|
+
const note = `model-unavailable idx=${account.index} status=${unavailable.status} reasons=${reasonCodes}`;
|
|
38198
|
+
pushDebug(note);
|
|
38199
|
+
debug.logAntigravityDebugResponse(debugContext, response, {
|
|
38200
|
+
note
|
|
38201
|
+
});
|
|
38202
|
+
log16.info("model-unavailable", {
|
|
38203
|
+
accountIndex: account.index,
|
|
38204
|
+
family,
|
|
38205
|
+
model,
|
|
38206
|
+
status: unavailable.status,
|
|
38207
|
+
reasons: unavailable.reasons
|
|
38208
|
+
});
|
|
38209
|
+
void response.body?.cancel().catch(() => {
|
|
38210
|
+
});
|
|
38211
|
+
modelUnavailableIndexes.add(account.index);
|
|
38212
|
+
skippedForModelUnavailable = true;
|
|
38213
|
+
shouldSwitchAccount = true;
|
|
38214
|
+
break;
|
|
38215
|
+
}
|
|
38216
|
+
}
|
|
37730
38217
|
const quotaKey = getQuotaKey(family, model);
|
|
37731
38218
|
retryState.resetRateLimitState(account.index, quotaKey);
|
|
37732
38219
|
retryState.resetAccountFailureState(account.index);
|
|
@@ -37793,7 +38280,7 @@ function createRequestExecutor(deps) {
|
|
|
37793
38280
|
break;
|
|
37794
38281
|
}
|
|
37795
38282
|
}
|
|
37796
|
-
const shouldRetryEndpoint = response.status ===
|
|
38283
|
+
const shouldRetryEndpoint = response.status === 404 || response.status >= 500;
|
|
37797
38284
|
if (shouldRetryEndpoint && i < ANTIGRAVITY_ENDPOINT_FALLBACKS.length - 1) {
|
|
37798
38285
|
await logResponseBody2(debugContext, response, response.status);
|
|
37799
38286
|
lastFailure = createFailureContext(response);
|
|
@@ -38044,6 +38531,9 @@ function createRequestExecutor(deps) {
|
|
|
38044
38531
|
}
|
|
38045
38532
|
}
|
|
38046
38533
|
}
|
|
38534
|
+
if (shouldSwitchAccount && skippedForModelUnavailable) {
|
|
38535
|
+
continue;
|
|
38536
|
+
}
|
|
38047
38537
|
if (shouldSwitchAccount) {
|
|
38048
38538
|
accountSwitchCount++;
|
|
38049
38539
|
if (accountSwitchCount > maxAccountSwitches) {
|
|
@@ -38246,6 +38736,32 @@ function createRequestExecutor(deps) {
|
|
|
38246
38736
|
dispose
|
|
38247
38737
|
};
|
|
38248
38738
|
}
|
|
38739
|
+
var ERROR_REASON_CODE = /^[A-Za-z0-9_.-]{1,128}$/;
|
|
38740
|
+
function parseModelUnavailableError(bodyText) {
|
|
38741
|
+
let body;
|
|
38742
|
+
try {
|
|
38743
|
+
body = JSON.parse(bodyText);
|
|
38744
|
+
} catch {
|
|
38745
|
+
return null;
|
|
38746
|
+
}
|
|
38747
|
+
const envelope = Array.isArray(body) ? body[0] : body;
|
|
38748
|
+
if (!envelope || typeof envelope !== "object") return null;
|
|
38749
|
+
const error = envelope.error;
|
|
38750
|
+
if (!error || typeof error !== "object") return null;
|
|
38751
|
+
if (error.status !== "NOT_FOUND") return null;
|
|
38752
|
+
const details = error.details;
|
|
38753
|
+
const reasons = [];
|
|
38754
|
+
if (Array.isArray(details)) {
|
|
38755
|
+
for (const detail of details) {
|
|
38756
|
+
if (!detail || typeof detail !== "object") continue;
|
|
38757
|
+
const reason = detail.reason;
|
|
38758
|
+
if (typeof reason === "string" && ERROR_REASON_CODE.test(reason)) {
|
|
38759
|
+
reasons.push(reason);
|
|
38760
|
+
}
|
|
38761
|
+
}
|
|
38762
|
+
}
|
|
38763
|
+
return { status: "NOT_FOUND", reasons };
|
|
38764
|
+
}
|
|
38249
38765
|
function extractRateLimitBodyInfo(body) {
|
|
38250
38766
|
if (!body || typeof body !== "object") return { retryDelayMs: null };
|
|
38251
38767
|
const error = body.error;
|
|
@@ -38980,13 +39496,13 @@ async function buildLocationRuntime(options, scope) {
|
|
|
38980
39496
|
);
|
|
38981
39497
|
}
|
|
38982
39498
|
let config;
|
|
38983
|
-
const
|
|
39499
|
+
const logger3 = createLocationLogger({
|
|
38984
39500
|
sink: options.logSink,
|
|
38985
39501
|
sinkEnabled: () => config?.config.debug_tui === true
|
|
38986
39502
|
});
|
|
38987
|
-
const log16 =
|
|
39503
|
+
const log16 = logger3.createLogger("runtime");
|
|
38988
39504
|
config = createLocationConfig(options.directory, {
|
|
38989
|
-
logger:
|
|
39505
|
+
logger: logger3.createLogger("config")
|
|
38990
39506
|
});
|
|
38991
39507
|
const debug = createLocationDebug(config.config);
|
|
38992
39508
|
scope.add({ dispose: () => debug.close() }, "consumer");
|
|
@@ -38997,7 +39513,7 @@ async function buildLocationRuntime(options, scope) {
|
|
|
38997
39513
|
});
|
|
38998
39514
|
scope.add(operatorSettings, "consumer");
|
|
38999
39515
|
const applyOperatorSettings = () => {
|
|
39000
|
-
|
|
39516
|
+
logger3.setLevel(operatorSettings.get().log_level);
|
|
39001
39517
|
};
|
|
39002
39518
|
applyOperatorSettings();
|
|
39003
39519
|
const signatureOptions = {
|
|
@@ -39024,7 +39540,7 @@ async function buildLocationRuntime(options, scope) {
|
|
|
39024
39540
|
}));
|
|
39025
39541
|
};
|
|
39026
39542
|
const quotaManager = createLocationQuotaManager({
|
|
39027
|
-
logger:
|
|
39543
|
+
logger: logger3.createLogger("quota"),
|
|
39028
39544
|
fetchAccountQuota: options.mayRun ? async (account, signal, purpose) => {
|
|
39029
39545
|
if (!await options.mayRun?.()) throw new Error(VAULT_ACCOUNT_REMEDY);
|
|
39030
39546
|
return purpose === "advisory" ? options.fetchAccountQuota(account, signal, purpose) : options.fetchAccountQuota(account, signal);
|
|
@@ -39054,7 +39570,7 @@ async function buildLocationRuntime(options, scope) {
|
|
|
39054
39570
|
...options.random ? { random: options.random } : {},
|
|
39055
39571
|
...options.acquireLock ? { acquireLock: options.acquireLock } : {},
|
|
39056
39572
|
healthScore: options.healthScore ?? null,
|
|
39057
|
-
logger:
|
|
39573
|
+
logger: logger3.createLogger("background-quota")
|
|
39058
39574
|
});
|
|
39059
39575
|
const poller = backgroundQuotaRefresh;
|
|
39060
39576
|
scope.add({ dispose: () => poller.dispose() }, "producer");
|
|
@@ -39086,7 +39602,7 @@ async function buildLocationRuntime(options, scope) {
|
|
|
39086
39602
|
if (!view || !config?.config.proactive_token_refresh) return;
|
|
39087
39603
|
const queue2 = createLocationProactiveRefreshQueue(
|
|
39088
39604
|
{
|
|
39089
|
-
logger:
|
|
39605
|
+
logger: logger3.createLogger("refresh-queue"),
|
|
39090
39606
|
refreshToken: options.refreshToken
|
|
39091
39607
|
},
|
|
39092
39608
|
{
|
|
@@ -39111,7 +39627,7 @@ async function buildLocationRuntime(options, scope) {
|
|
|
39111
39627
|
const runtimeConfig2 = config;
|
|
39112
39628
|
return {
|
|
39113
39629
|
directory: options.directory,
|
|
39114
|
-
logger:
|
|
39630
|
+
logger: logger3,
|
|
39115
39631
|
config: runtimeConfig2,
|
|
39116
39632
|
debug,
|
|
39117
39633
|
dump,
|
|
@@ -39378,7 +39894,7 @@ function createVaultSelectionState(options) {
|
|
|
39378
39894
|
report(error);
|
|
39379
39895
|
}
|
|
39380
39896
|
};
|
|
39381
|
-
const
|
|
39897
|
+
const flush2 = () => {
|
|
39382
39898
|
writing = writing.then(async () => {
|
|
39383
39899
|
for (const row of [...changed]) await writeRow(row);
|
|
39384
39900
|
});
|
|
@@ -39394,7 +39910,7 @@ function createVaultSelectionState(options) {
|
|
|
39394
39910
|
accessVerdict: mark,
|
|
39395
39911
|
fingerprint: mark,
|
|
39396
39912
|
requestSave: () => {
|
|
39397
|
-
void
|
|
39913
|
+
void flush2();
|
|
39398
39914
|
}
|
|
39399
39915
|
},
|
|
39400
39916
|
admitted(row, attribution) {
|
|
@@ -39417,7 +39933,7 @@ function createVaultSelectionState(options) {
|
|
|
39417
39933
|
}
|
|
39418
39934
|
}
|
|
39419
39935
|
},
|
|
39420
|
-
flush,
|
|
39936
|
+
flush: flush2,
|
|
39421
39937
|
recordQuota(attribution, quota, signal) {
|
|
39422
39938
|
return options.source.commitState(
|
|
39423
39939
|
attribution,
|
|
@@ -39544,6 +40060,10 @@ async function checkVaultQuota(input2) {
|
|
|
39544
40060
|
input2.onStage?.("fetch");
|
|
39545
40061
|
const answer = await input2.fetchReading(row.route, input2.signal);
|
|
39546
40062
|
input2.signal.throwIfAborted();
|
|
40063
|
+
if (answer === void 0) {
|
|
40064
|
+
input2.onOutcome?.("fetch-failed");
|
|
40065
|
+
continue;
|
|
40066
|
+
}
|
|
39547
40067
|
const attribution = answer.quotaAttribution;
|
|
39548
40068
|
if (answer.quota.error !== void 0) {
|
|
39549
40069
|
input2.onOutcome?.("fetch-failed");
|
|
@@ -39553,7 +40073,7 @@ async function checkVaultQuota(input2) {
|
|
|
39553
40073
|
input2.onOutcome?.("unattributed");
|
|
39554
40074
|
continue;
|
|
39555
40075
|
}
|
|
39556
|
-
const reading = vaultQuotaState(answer.quota, now());
|
|
40076
|
+
const reading = vaultQuotaState(answer.quota, answer.observedAt ?? now());
|
|
39557
40077
|
input2.onStage?.("commit");
|
|
39558
40078
|
input2.signal.throwIfAborted();
|
|
39559
40079
|
const result = await state.recordQuota(attribution, reading, input2.signal);
|
|
@@ -39587,6 +40107,50 @@ async function checkVaultQuota(input2) {
|
|
|
39587
40107
|
// src/plugin/vault-custody.ts
|
|
39588
40108
|
import { chmod as chmod3, mkdir as mkdir11, readFile as readFile9 } from "node:fs/promises";
|
|
39589
40109
|
import { dirname as dirname18, join as join16 } from "node:path";
|
|
40110
|
+
|
|
40111
|
+
// src/plugin/vault-insula-quota.ts
|
|
40112
|
+
var windows = [
|
|
40113
|
+
["gemini-5h", "gemini", "5h"],
|
|
40114
|
+
["gemini-weekly", "gemini", "weekly"],
|
|
40115
|
+
["3p-5h", "non-gemini", "5h"],
|
|
40116
|
+
["3p-weekly", "non-gemini", "weekly"]
|
|
40117
|
+
];
|
|
40118
|
+
var normalizeVaultInsulaQuota = (entry, context) => {
|
|
40119
|
+
if (entry.source !== "vault") return void 0;
|
|
40120
|
+
if (entry.provider !== "antigravity" || !entry.account?.trim() || !Number.isFinite(context.fetchedAt))
|
|
40121
|
+
return void 0;
|
|
40122
|
+
const groups = {};
|
|
40123
|
+
for (const [id, group, window] of windows) {
|
|
40124
|
+
const reading = entry.usage?.extraRateWindows?.find(
|
|
40125
|
+
(extra) => extra.id === id
|
|
40126
|
+
)?.window;
|
|
40127
|
+
if (!reading || !Number.isFinite(reading.usedPercent) || reading.usedPercent < 0 || reading.usedPercent > 100)
|
|
40128
|
+
continue;
|
|
40129
|
+
const normalized = {
|
|
40130
|
+
window,
|
|
40131
|
+
remainingFraction: 1 - reading.usedPercent / 100,
|
|
40132
|
+
resetTime: reading.resetsAt ?? ""
|
|
40133
|
+
};
|
|
40134
|
+
let summary = groups[group];
|
|
40135
|
+
if (summary === void 0) {
|
|
40136
|
+
summary = { modelCount: 0, windows: [] };
|
|
40137
|
+
groups[group] = summary;
|
|
40138
|
+
}
|
|
40139
|
+
summary.windows?.push(normalized);
|
|
40140
|
+
if (summary.remainingFraction === void 0 || normalized.remainingFraction < summary.remainingFraction) {
|
|
40141
|
+
summary.remainingFraction = normalized.remainingFraction;
|
|
40142
|
+
summary.resetTime = normalized.resetTime;
|
|
40143
|
+
}
|
|
40144
|
+
}
|
|
40145
|
+
if (Object.keys(groups).length === 0) return void 0;
|
|
40146
|
+
return {
|
|
40147
|
+
quota: { groups, modelCount: 0 },
|
|
40148
|
+
accountIdentity: entry.account.trim(),
|
|
40149
|
+
observedAt: context.fetchedAt
|
|
40150
|
+
};
|
|
40151
|
+
};
|
|
40152
|
+
|
|
40153
|
+
// src/plugin/vault-custody.ts
|
|
39590
40154
|
var OPENCODE_VAULT_PROVIDER = "google";
|
|
39591
40155
|
var OPENCODE_VAULT_HOST = "opencode";
|
|
39592
40156
|
var OPENCODE_VAULT_ENROLLMENT_NAME = getAntigravityVaultEnrollmentName(OPENCODE_VAULT_HOST);
|
|
@@ -39694,6 +40258,12 @@ function createOpenCodeVaultCustody(options) {
|
|
|
39694
40258
|
onError: () => options.onRosterChanged?.(),
|
|
39695
40259
|
reporterSource: options.reporterSource,
|
|
39696
40260
|
state: { path: paths.stateFile, fs: await loadCommonAuthFs() },
|
|
40261
|
+
...options.insulaQuota ? {
|
|
40262
|
+
insula: {
|
|
40263
|
+
provider: "antigravity",
|
|
40264
|
+
normalize: normalizeVaultInsulaQuota
|
|
40265
|
+
}
|
|
40266
|
+
} : {},
|
|
39697
40267
|
...options.logger ? { logger: options.logger } : {},
|
|
39698
40268
|
...options.now ? { now: options.now } : {},
|
|
39699
40269
|
...options.pollIntervalMs !== void 0 ? { pollIntervalMs: options.pollIntervalMs } : {}
|
|
@@ -39766,11 +40336,11 @@ function createOpenCodeVaultCustody(options) {
|
|
|
39766
40336
|
].join("\n");
|
|
39767
40337
|
const waitForApproval = async () => {
|
|
39768
40338
|
while (!closed) {
|
|
39769
|
-
await new Promise((
|
|
40339
|
+
await new Promise((resolve20) => {
|
|
39770
40340
|
const done = () => {
|
|
39771
40341
|
clearTimeout(timer);
|
|
39772
40342
|
cancelWait = void 0;
|
|
39773
|
-
|
|
40343
|
+
resolve20();
|
|
39774
40344
|
};
|
|
39775
40345
|
const timer = setTimeout(done, 2e3);
|
|
39776
40346
|
timer.unref?.();
|
|
@@ -40399,7 +40969,7 @@ function createGaReauthorize(input2) {
|
|
|
40399
40969
|
const continuations = /* @__PURE__ */ new Set();
|
|
40400
40970
|
const shutdown = new AbortController();
|
|
40401
40971
|
let disposed = false;
|
|
40402
|
-
const waitForRedirect = (code2) => new Promise((
|
|
40972
|
+
const waitForRedirect = (code2) => new Promise((resolve20, reject) => {
|
|
40403
40973
|
const detach = () => shutdown.signal.removeEventListener("abort", abort);
|
|
40404
40974
|
const abort = () => {
|
|
40405
40975
|
detach();
|
|
@@ -40410,7 +40980,7 @@ function createGaReauthorize(input2) {
|
|
|
40410
40980
|
void code2.then(
|
|
40411
40981
|
(value) => {
|
|
40412
40982
|
detach();
|
|
40413
|
-
|
|
40983
|
+
resolve20(value);
|
|
40414
40984
|
},
|
|
40415
40985
|
(error) => {
|
|
40416
40986
|
detach();
|
|
@@ -40818,8 +41388,8 @@ function gaEngineCollaborators(input2) {
|
|
|
40818
41388
|
async function createGaLocalRequestPipeline(input2) {
|
|
40819
41389
|
const runtime = input2.runtime;
|
|
40820
41390
|
await input2.assertAdmission?.();
|
|
40821
|
-
const
|
|
40822
|
-
const advisory = createAdvisoryRepositoryOwner(input2.repository,
|
|
41391
|
+
const logger3 = runtime.logger.createLogger("request");
|
|
41392
|
+
const advisory = createAdvisoryRepositoryOwner(input2.repository, logger3);
|
|
40823
41393
|
const manager = await loadAccountManagerFromRepository(advisory.repository, {
|
|
40824
41394
|
onWriteError: advisory.owns
|
|
40825
41395
|
});
|
|
@@ -40831,7 +41401,7 @@ async function createGaLocalRequestPipeline(input2) {
|
|
|
40831
41401
|
runtime,
|
|
40832
41402
|
overrides: input2.overrides,
|
|
40833
41403
|
routes: input2.routes,
|
|
40834
|
-
logger:
|
|
41404
|
+
logger: logger3
|
|
40835
41405
|
}),
|
|
40836
41406
|
accounts: manager,
|
|
40837
41407
|
...input2.assertAdmission ? { assertAdmission: input2.assertAdmission } : {},
|
|
@@ -40841,7 +41411,7 @@ async function createGaLocalRequestPipeline(input2) {
|
|
|
40841
41411
|
refreshQuotaAfterSuccess: createLocalQuotaRefresh(
|
|
40842
41412
|
manager,
|
|
40843
41413
|
runtime.quotaManager,
|
|
40844
|
-
|
|
41414
|
+
logger3
|
|
40845
41415
|
)
|
|
40846
41416
|
}),
|
|
40847
41417
|
// The trackers the manager selects with, so recorded outcomes steer
|
|
@@ -40885,13 +41455,13 @@ async function createGaVaultRequestPipeline(input2) {
|
|
|
40885
41455
|
const { pool } = input2;
|
|
40886
41456
|
await input2.assertAdmission?.();
|
|
40887
41457
|
await pool.sync();
|
|
40888
|
-
const
|
|
41458
|
+
const logger3 = input2.runtime.logger.createLogger("request");
|
|
40889
41459
|
const executor = createRequestExecutor({
|
|
40890
41460
|
...gaEngineCollaborators({
|
|
40891
41461
|
runtime: input2.runtime,
|
|
40892
41462
|
overrides: input2.overrides,
|
|
40893
41463
|
routes: input2.routes,
|
|
40894
|
-
logger:
|
|
41464
|
+
logger: logger3
|
|
40895
41465
|
}),
|
|
40896
41466
|
accounts: pool.selector,
|
|
40897
41467
|
...input2.assertAdmission ? { assertAdmission: input2.assertAdmission } : {},
|
|
@@ -42990,11 +43560,11 @@ var OPENCODE2_VAULT_AUTH_LABEL = "Use approved Antigravity vault";
|
|
|
42990
43560
|
var GA_POOL_METHOD_ID = "antigravity-auth-pool-browser";
|
|
42991
43561
|
var LOGIN_FAILED = "The Antigravity pool login could not be completed.";
|
|
42992
43562
|
function abortable(pending, signal) {
|
|
42993
|
-
return new Promise((
|
|
43563
|
+
return new Promise((resolve20, reject) => {
|
|
42994
43564
|
const abort = () => reject(signal.reason);
|
|
42995
43565
|
if (signal.aborted) abort();
|
|
42996
43566
|
else signal.addEventListener("abort", abort, { once: true });
|
|
42997
|
-
void pending.then(
|
|
43567
|
+
void pending.then(resolve20, reject).finally(() => {
|
|
42998
43568
|
signal.removeEventListener("abort", abort);
|
|
42999
43569
|
});
|
|
43000
43570
|
});
|
|
@@ -43362,11 +43932,11 @@ async function startGaLoopbackBridge(options) {
|
|
|
43362
43932
|
}
|
|
43363
43933
|
}
|
|
43364
43934
|
};
|
|
43365
|
-
await new Promise((
|
|
43935
|
+
await new Promise((resolve20, reject) => {
|
|
43366
43936
|
server.once("error", reject);
|
|
43367
43937
|
server.listen(0, BRIDGE_HOST, () => {
|
|
43368
43938
|
server.off("error", reject);
|
|
43369
|
-
|
|
43939
|
+
resolve20();
|
|
43370
43940
|
});
|
|
43371
43941
|
});
|
|
43372
43942
|
server.unref();
|
|
@@ -43470,8 +44040,8 @@ async function startGaLoopbackBridge(options) {
|
|
|
43470
44040
|
disposal = (async () => {
|
|
43471
44041
|
for (const { timer } of queued.values()) clearTimeout(timer);
|
|
43472
44042
|
queued.clear();
|
|
43473
|
-
const closed = new Promise((
|
|
43474
|
-
server.close(() =>
|
|
44043
|
+
const closed = new Promise((resolve20) => {
|
|
44044
|
+
server.close(() => resolve20());
|
|
43475
44045
|
});
|
|
43476
44046
|
for (const controller of running) {
|
|
43477
44047
|
controller.abort(
|
|
@@ -43535,9 +44105,9 @@ async function pipeResponse(upstream, response, onFailure, onHandoff) {
|
|
|
43535
44105
|
return;
|
|
43536
44106
|
}
|
|
43537
44107
|
if (!response.write(value) && !response.destroyed) {
|
|
43538
|
-
await new Promise((
|
|
43539
|
-
response.once("drain",
|
|
43540
|
-
response.once("close",
|
|
44108
|
+
await new Promise((resolve20) => {
|
|
44109
|
+
response.once("drain", resolve20);
|
|
44110
|
+
response.once("close", resolve20);
|
|
43541
44111
|
});
|
|
43542
44112
|
}
|
|
43543
44113
|
if (response.destroyed) {
|
|
@@ -43724,10 +44294,10 @@ function createGaRpcActivation(options) {
|
|
|
43724
44294
|
const { email: _email, quota, ...rest } = account;
|
|
43725
44295
|
const entry = (value) => {
|
|
43726
44296
|
if (value === void 0) return void 0;
|
|
43727
|
-
const { remainingFraction: _fraction, windows, ...
|
|
43728
|
-
return
|
|
43729
|
-
...
|
|
43730
|
-
windows:
|
|
44297
|
+
const { remainingFraction: _fraction, windows: windows2, ...fields2 } = value;
|
|
44298
|
+
return windows2 === void 0 ? fields2 : {
|
|
44299
|
+
...fields2,
|
|
44300
|
+
windows: windows2.map(
|
|
43731
44301
|
({ remainingFraction: _windowFraction, ...window }) => window
|
|
43732
44302
|
)
|
|
43733
44303
|
};
|
|
@@ -44192,12 +44762,12 @@ function createGaAntigravityPlugin(overrides = {}) {
|
|
|
44192
44762
|
|
|
44193
44763
|
// src/plugin/index.ts
|
|
44194
44764
|
import { createHash as createHash20, randomUUID as randomUUID21 } from "node:crypto";
|
|
44195
|
-
import { join as join31, resolve as
|
|
44765
|
+
import { join as join31, resolve as resolve19 } from "node:path";
|
|
44196
44766
|
|
|
44197
44767
|
// src/cli.ts
|
|
44198
44768
|
import { execFile } from "node:child_process";
|
|
44199
44769
|
import { realpathSync as realpathSync3 } from "node:fs";
|
|
44200
|
-
import { resolve as
|
|
44770
|
+
import { resolve as resolve16 } from "node:path";
|
|
44201
44771
|
import { createInterface } from "node:readline/promises";
|
|
44202
44772
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
44203
44773
|
import { promisify } from "node:util";
|
|
@@ -44241,7 +44811,7 @@ async function performOAuthLogin(request, deps) {
|
|
|
44241
44811
|
|
|
44242
44812
|
// src/setup.ts
|
|
44243
44813
|
import { lstat as lstat5, readFile as readFile13 } from "node:fs/promises";
|
|
44244
|
-
import { join as join22, resolve as
|
|
44814
|
+
import { join as join22, resolve as resolve15 } from "node:path";
|
|
44245
44815
|
|
|
44246
44816
|
// src/common-auth-embedded/auth-menu/ansi.js
|
|
44247
44817
|
var ANSI2 = {
|
|
@@ -44409,7 +44979,7 @@ async function select2(terminal, items, options) {
|
|
|
44409
44979
|
writeLine("");
|
|
44410
44980
|
renderedLines = lines;
|
|
44411
44981
|
};
|
|
44412
|
-
return new Promise((
|
|
44982
|
+
return new Promise((resolve20) => {
|
|
44413
44983
|
const wasRaw = stdin.isRaw ?? false;
|
|
44414
44984
|
const cleanup2 = () => {
|
|
44415
44985
|
if (cleaned)
|
|
@@ -44429,7 +44999,7 @@ async function select2(terminal, items, options) {
|
|
|
44429
44999
|
};
|
|
44430
45000
|
const finish = (value) => {
|
|
44431
45001
|
cleanup2();
|
|
44432
|
-
|
|
45002
|
+
resolve20(value);
|
|
44433
45003
|
};
|
|
44434
45004
|
const onSignal = () => finish(null);
|
|
44435
45005
|
const onKey = (data) => {
|
|
@@ -44469,7 +45039,7 @@ async function select2(terminal, items, options) {
|
|
|
44469
45039
|
stdin.setRawMode(true);
|
|
44470
45040
|
} catch {
|
|
44471
45041
|
cleanup2();
|
|
44472
|
-
|
|
45042
|
+
resolve20(null);
|
|
44473
45043
|
return;
|
|
44474
45044
|
}
|
|
44475
45045
|
stdin.resume();
|
|
@@ -44483,7 +45053,7 @@ async function select2(terminal, items, options) {
|
|
|
44483
45053
|
import { createHash as createHash15, randomBytes as randomBytes6, randomUUID as randomUUID17 } from "node:crypto";
|
|
44484
45054
|
import { constants as fsConstants2 } from "node:fs";
|
|
44485
45055
|
import { chmod as chmod4, mkdir as mkdir13, open as open10, readFile as readFile11, realpath as realpath4, rename as rename9, stat as stat7, unlink as unlink9 } from "node:fs/promises";
|
|
44486
|
-
import { basename as basename5, dirname as dirname20, extname as extname2, isAbsolute as isAbsolute3, join as join18, resolve as
|
|
45056
|
+
import { basename as basename5, dirname as dirname20, extname as extname2, isAbsolute as isAbsolute3, join as join18, resolve as resolve14 } from "node:path";
|
|
44487
45057
|
import { ClaustrumCredentialError as ClaustrumCredentialError5, ClaustrumClient as ClaustrumWireClient2, writeEnrollmentTokenFile as writeEnrollmentTokenFile2 } from "@cortexkit/claustrum-client";
|
|
44488
45058
|
|
|
44489
45059
|
// src/common-auth-embedded/fs/lock-constants.js
|
|
@@ -44548,8 +45118,8 @@ async function acquireRefreshFileLockWithClock2(options) {
|
|
|
44548
45118
|
let releaseConfirmed = false;
|
|
44549
45119
|
let loss;
|
|
44550
45120
|
let resolveLoss;
|
|
44551
|
-
const lostPromise = new Promise((
|
|
44552
|
-
resolveLoss =
|
|
45121
|
+
const lostPromise = new Promise((resolve20) => {
|
|
45122
|
+
resolveLoss = resolve20;
|
|
44553
45123
|
});
|
|
44554
45124
|
function notifyTimerStep(event) {
|
|
44555
45125
|
try {
|
|
@@ -44706,7 +45276,7 @@ async function acquireRefreshFileLockWithClock2(options) {
|
|
|
44706
45276
|
}
|
|
44707
45277
|
}
|
|
44708
45278
|
async function backoff() {
|
|
44709
|
-
await new Promise((
|
|
45279
|
+
await new Promise((resolve20) => setTimeout(resolve20, Math.floor(Math.random() * 4)));
|
|
44710
45280
|
}
|
|
44711
45281
|
async function readLockState(notifyReady = true) {
|
|
44712
45282
|
if (notifyReady && options.onStep)
|
|
@@ -45192,7 +45762,7 @@ function hostEnrollmentPaths2(input2) {
|
|
|
45192
45762
|
const override = input2.override?.trim();
|
|
45193
45763
|
if (override && !isAbsolute3(override) && !input2.cwd)
|
|
45194
45764
|
throw new ClaustrumConsumerError2("invalid-state", "A relative Claustrum enrollment override needs a base directory");
|
|
45195
|
-
const tokenPath = override ? isAbsolute3(override) ? override :
|
|
45765
|
+
const tokenPath = override ? isAbsolute3(override) ? override : resolve14(input2.cwd, override) : join18(input2.stateDir, `${input2.host}-enrollment.json`);
|
|
45196
45766
|
return getClaustrumEnrollmentPaths2(tokenPath);
|
|
45197
45767
|
}
|
|
45198
45768
|
function isRecord10(value) {
|
|
@@ -45321,13 +45891,13 @@ async function readBoundedJson2(path5) {
|
|
|
45321
45891
|
await descriptor.close();
|
|
45322
45892
|
}
|
|
45323
45893
|
}
|
|
45324
|
-
function accountRecords2(text2,
|
|
45894
|
+
function accountRecords2(text2, fields2) {
|
|
45325
45895
|
const records = [];
|
|
45326
45896
|
for (const line of text2.split("\n")) {
|
|
45327
45897
|
if (line.trim() === "" || line.startsWith("#"))
|
|
45328
45898
|
continue;
|
|
45329
45899
|
const parts = line.split(":");
|
|
45330
|
-
if (parts.length !==
|
|
45900
|
+
if (parts.length !== fields2 || !/^[^\s:,]+$/.test(parts[0] ?? "") || !/^\d+$/.test(parts[2] ?? "") || !Number.isSafeInteger(Number(parts[2])) || fields2 === 7 && (!/^\d+$/.test(parts[3] ?? "") || !Number.isSafeInteger(Number(parts[3]))) || fields2 === 4 && parts[3] !== "" && !/^[^\s:,]+(?:,[^\s:,]+)*$/.test(parts[3] ?? ""))
|
|
45331
45901
|
return void 0;
|
|
45332
45902
|
records.push(parts);
|
|
45333
45903
|
}
|
|
@@ -45787,7 +46357,7 @@ var ByteTail = class {
|
|
|
45787
46357
|
};
|
|
45788
46358
|
var defaultCommandRunner = {
|
|
45789
46359
|
run(file, args, options = {}) {
|
|
45790
|
-
return new Promise((
|
|
46360
|
+
return new Promise((resolve20) => {
|
|
45791
46361
|
const started = performance.now();
|
|
45792
46362
|
const timeoutMs = options.timeoutMs ?? 15e3;
|
|
45793
46363
|
const stderr = new ByteTail();
|
|
@@ -45805,7 +46375,7 @@ var defaultCommandRunner = {
|
|
|
45805
46375
|
stdio: ["ignore", "pipe", "pipe"]
|
|
45806
46376
|
});
|
|
45807
46377
|
} catch {
|
|
45808
|
-
|
|
46378
|
+
resolve20({
|
|
45809
46379
|
exitCode: 1,
|
|
45810
46380
|
stdout: "",
|
|
45811
46381
|
stderr: "",
|
|
@@ -45840,7 +46410,7 @@ var defaultCommandRunner = {
|
|
|
45840
46410
|
settled = true;
|
|
45841
46411
|
if (timer)
|
|
45842
46412
|
clearTimeout(timer);
|
|
45843
|
-
|
|
46413
|
+
resolve20({
|
|
45844
46414
|
exitCode: spawnError ? 1 : outputExceeded ? 1 : code2 ?? 1,
|
|
45845
46415
|
stdout: Buffer.concat(stdout, stdoutLength).toString("utf8"),
|
|
45846
46416
|
stderr: stderr.toString(),
|
|
@@ -46268,9 +46838,10 @@ Please quit all OpenCode, LiteCode, and Pi processes before running setup.`);
|
|
|
46268
46838
|
}
|
|
46269
46839
|
};
|
|
46270
46840
|
async function listSetupProcesses(runner = defaultCommandRunner, options = {}) {
|
|
46271
|
-
const
|
|
46841
|
+
const windows2 = (options.platform ?? process.platform) === "win32";
|
|
46842
|
+
const selfPid = options.selfPid ?? process.pid;
|
|
46272
46843
|
let inspection = {
|
|
46273
|
-
step:
|
|
46844
|
+
step: windows2 ? "tasklist" : "ps",
|
|
46274
46845
|
exitCode: null,
|
|
46275
46846
|
signal: null,
|
|
46276
46847
|
timedOut: false,
|
|
@@ -46305,7 +46876,7 @@ async function listSetupProcesses(runner = defaultCommandRunner, options = {}) {
|
|
|
46305
46876
|
}
|
|
46306
46877
|
};
|
|
46307
46878
|
try {
|
|
46308
|
-
const result = await inspect(
|
|
46879
|
+
const result = await inspect(windows2 ? "tasklist" : "ps", windows2 ? "tasklist.exe" : "ps", windows2 ? ["/fo", "csv", "/nh"] : ["-eo", "pid,command"]);
|
|
46309
46880
|
if (result.exitCode !== 0)
|
|
46310
46881
|
throw new ProcessInspectionError(inspection);
|
|
46311
46882
|
const processes = [];
|
|
@@ -46315,7 +46886,7 @@ async function listSetupProcesses(runner = defaultCommandRunner, options = {}) {
|
|
|
46315
46886
|
continue;
|
|
46316
46887
|
let pid;
|
|
46317
46888
|
let command;
|
|
46318
|
-
if (
|
|
46889
|
+
if (windows2) {
|
|
46319
46890
|
const match = /^"([^"]+)","(\d+)"(?:,|$)/.exec(trimmed);
|
|
46320
46891
|
if (!match)
|
|
46321
46892
|
throw new ProcessInspectionError(inspection);
|
|
@@ -46337,8 +46908,8 @@ async function listSetupProcesses(runner = defaultCommandRunner, options = {}) {
|
|
|
46337
46908
|
}
|
|
46338
46909
|
if (!processes.length)
|
|
46339
46910
|
throw new ProcessInspectionError(inspection);
|
|
46340
|
-
const runtimes = processes.filter((entry) => entry.pid !==
|
|
46341
|
-
if (
|
|
46911
|
+
const runtimes = processes.filter((entry) => entry.pid !== selfPid && /^(?:node|bun)\.exe$/i.test(entry.command));
|
|
46912
|
+
if (windows2 && runtimes.length && options.inspectRuntimes !== false) {
|
|
46342
46913
|
const details = await inspect("CIM", "powershell.exe", [
|
|
46343
46914
|
"-NoProfile",
|
|
46344
46915
|
"-NonInteractive",
|
|
@@ -46370,7 +46941,8 @@ async function listSetupProcesses(runner = defaultCommandRunner, options = {}) {
|
|
|
46370
46941
|
}
|
|
46371
46942
|
}
|
|
46372
46943
|
function createProcessFence(runner = defaultCommandRunner, options = {}) {
|
|
46373
|
-
const
|
|
46944
|
+
const selfPid = options.selfPid ?? process.pid;
|
|
46945
|
+
const isHost = (entry) => entry.pid !== selfPid && hostName(entry.command) !== null;
|
|
46374
46946
|
return {
|
|
46375
46947
|
async listRunningHosts(env3) {
|
|
46376
46948
|
return (await listSetupProcesses(runner, { ...options, env: env3 })).filter(isHost);
|
|
@@ -46381,10 +46953,10 @@ function createProcessFence(runner = defaultCommandRunner, options = {}) {
|
|
|
46381
46953
|
env: env3,
|
|
46382
46954
|
inspectRuntimes: false
|
|
46383
46955
|
});
|
|
46384
|
-
const
|
|
46956
|
+
const windows2 = (options.platform ?? process.platform) === "win32";
|
|
46385
46957
|
return {
|
|
46386
46958
|
hosts: processes.filter(isHost),
|
|
46387
|
-
uncheckedRuntimes:
|
|
46959
|
+
uncheckedRuntimes: windows2 ? processes.filter((entry) => entry.pid !== selfPid && /^(?:node|bun)\.exe$/i.test(entry.command)).length : 0
|
|
46388
46960
|
};
|
|
46389
46961
|
}
|
|
46390
46962
|
};
|
|
@@ -46495,11 +47067,11 @@ import { mkdir as mkdir14, open as open11, rename as rename10, stat as stat9, un
|
|
|
46495
47067
|
import { basename as basename6, dirname as dirname21, join as join20 } from "node:path";
|
|
46496
47068
|
import { setTimeout as delay2 } from "node:timers/promises";
|
|
46497
47069
|
async function writeHostConfigAtomic(file, content, options = {}) {
|
|
46498
|
-
const
|
|
47070
|
+
const windows2 = (options.platform ?? process.platform) === "win32";
|
|
46499
47071
|
const parent = dirname21(file);
|
|
46500
47072
|
await mkdir14(parent, { recursive: true });
|
|
46501
47073
|
let mode;
|
|
46502
|
-
if (!
|
|
47074
|
+
if (!windows2) {
|
|
46503
47075
|
try {
|
|
46504
47076
|
mode = (await stat9(file)).mode & 4095;
|
|
46505
47077
|
} catch (error) {
|
|
@@ -46530,7 +47102,7 @@ async function writeHostConfigAtomic(file, content, options = {}) {
|
|
|
46530
47102
|
} catch (error) {
|
|
46531
47103
|
const code2 = error.code;
|
|
46532
47104
|
const remaining = 2e3 - (now() - started);
|
|
46533
|
-
if (!
|
|
47105
|
+
if (!windows2 || !["EPERM", "EBUSY", "EACCES"].includes(code2 ?? "") || remaining <= 0 || attempt >= 40)
|
|
46534
47106
|
throw new Error(`Unable to replace host config ${file}. Close editors or other programs using the file, then rerun setup.`);
|
|
46535
47107
|
await (options.wait ?? delay2)(Math.min(remaining, 25 * 2 ** Math.min(attempt, 2)));
|
|
46536
47108
|
}
|
|
@@ -46982,7 +47554,7 @@ async function writeNativeSlot(host, slot, context, expectedAuthority = "local")
|
|
|
46982
47554
|
beforeRename: async () => {
|
|
46983
47555
|
await assertSetupHostsStopped();
|
|
46984
47556
|
const claustrum = await loadCommonAuthClaustrum();
|
|
46985
|
-
const stateDir = host === "opencode" ? openCodeVaultPaths(
|
|
47557
|
+
const stateDir = host === "opencode" ? openCodeVaultPaths(resolve15(getStoragePath())).dir : getPiAntigravityVaultDir();
|
|
46986
47558
|
if (await claustrum.enrollmentAuthority(
|
|
46987
47559
|
claustrum.hostEnrollmentPaths({ stateDir, host }),
|
|
46988
47560
|
`antigravity-auth-${host}`
|
|
@@ -47012,7 +47584,7 @@ async function persistPiSetupLogin(result, context) {
|
|
|
47012
47584
|
}
|
|
47013
47585
|
async function createSetupPlugin(deps, migrateOpenCode, forceLogin = false) {
|
|
47014
47586
|
const claustrum = await loadCommonAuthClaustrum();
|
|
47015
|
-
const opencode = openCodeVaultPaths(
|
|
47587
|
+
const opencode = openCodeVaultPaths(resolve15(getStoragePath()));
|
|
47016
47588
|
const piDir = getPiAntigravityVaultDir();
|
|
47017
47589
|
const hosts = {
|
|
47018
47590
|
opencode: {
|
|
@@ -47031,7 +47603,7 @@ async function createSetupPlugin(deps, migrateOpenCode, forceLogin = false) {
|
|
|
47031
47603
|
const assertLocal = async (host, context) => {
|
|
47032
47604
|
if (host === "opencode")
|
|
47033
47605
|
return assertLocalOpenCodeLogin(
|
|
47034
|
-
|
|
47606
|
+
resolve15(getStoragePath()),
|
|
47035
47607
|
context.opencodeGeneration
|
|
47036
47608
|
);
|
|
47037
47609
|
if (await authority(host) !== "local")
|
|
@@ -47563,7 +48135,7 @@ function createDefaultCliDependencies() {
|
|
|
47563
48135
|
throw new Error(
|
|
47564
48136
|
"Pi setup requires its detected native agent directory."
|
|
47565
48137
|
);
|
|
47566
|
-
const legacyPath =
|
|
48138
|
+
const legacyPath = resolve16(getStoragePath());
|
|
47567
48139
|
const repository = host === "pi" ? void 0 : await prepareCliLoginStore(legacyPath, context?.opencodeGeneration);
|
|
47568
48140
|
try {
|
|
47569
48141
|
return await performOAuthLogin(request, {
|
|
@@ -47723,7 +48295,7 @@ async function readAccountStore(legacyPath) {
|
|
|
47723
48295
|
function createDefaultAccountStoreOperations() {
|
|
47724
48296
|
const offline = { processesStopped: true };
|
|
47725
48297
|
return {
|
|
47726
|
-
legacyPath: () =>
|
|
48298
|
+
legacyPath: () => resolve16(getStoragePath()),
|
|
47727
48299
|
migrate: async (legacyPath) => createAccountMigrationFactory(await loadCommonAuthStoreModules())({
|
|
47728
48300
|
legacyPath,
|
|
47729
48301
|
offline,
|
|
@@ -48224,14 +48796,14 @@ function isTuiConnected(sessionId) {
|
|
|
48224
48796
|
// src/rpc/rpc-dir.ts
|
|
48225
48797
|
import { createHash as createHash16 } from "node:crypto";
|
|
48226
48798
|
import { homedir as homedir12, tmpdir as tmpdir4 } from "node:os";
|
|
48227
|
-
import { isAbsolute as isAbsolute4, join as join26, resolve as
|
|
48799
|
+
import { isAbsolute as isAbsolute4, join as join26, resolve as resolve17 } from "node:path";
|
|
48228
48800
|
var RPC_DIR_ENV = "ANTIGRAVITY_AUTH_RPC_DIR";
|
|
48229
48801
|
function getRpcDir(projectDirectory) {
|
|
48230
48802
|
const override = process.env[RPC_DIR_ENV]?.trim();
|
|
48231
48803
|
if (override) {
|
|
48232
|
-
return isAbsolute4(override) ? override :
|
|
48804
|
+
return isAbsolute4(override) ? override : resolve17(projectDirectory, override);
|
|
48233
48805
|
}
|
|
48234
|
-
const projectHash = createHash16("sha256").update(
|
|
48806
|
+
const projectHash = createHash16("sha256").update(resolve17(projectDirectory)).digest("hex").slice(0, 16);
|
|
48235
48807
|
const stateHome = process.env.XDG_STATE_HOME ?? join26(homedir12(), ".local", "state");
|
|
48236
48808
|
return join26(stateHome, "cortexkit", "antigravity-auth", "rpc", projectHash);
|
|
48237
48809
|
}
|
|
@@ -48244,7 +48816,7 @@ function isSessionId(value) {
|
|
|
48244
48816
|
// src/common-auth-embedded/rpc/port-file.js
|
|
48245
48817
|
import { createHash as createHash17, randomUUID as randomUUID19 } from "node:crypto";
|
|
48246
48818
|
import { chmod as chmod5, mkdir as mkdir15, open as open12, readdir, rename as rename11, rmdir as rmdir2, stat as stat10, unlink as unlink11 } from "node:fs/promises";
|
|
48247
|
-
import { join as join27, resolve as
|
|
48819
|
+
import { join as join27, resolve as resolve18 } from "node:path";
|
|
48248
48820
|
function isProbeablePid(pid) {
|
|
48249
48821
|
return typeof pid === "number" && Number.isSafeInteger(pid) && pid > 0;
|
|
48250
48822
|
}
|
|
@@ -48331,7 +48903,7 @@ async function sweepRpcState(root, activeDir, isManagedDir, log16) {
|
|
|
48331
48903
|
return;
|
|
48332
48904
|
throw error;
|
|
48333
48905
|
}
|
|
48334
|
-
const active2 =
|
|
48906
|
+
const active2 = resolve18(activeDir);
|
|
48335
48907
|
for (const projectDir of projectDirs) {
|
|
48336
48908
|
if (!projectDir.isDirectory() || !isManagedDir(projectDir.name)) {
|
|
48337
48909
|
continue;
|
|
@@ -48375,7 +48947,7 @@ async function sweepRpcState(root, activeDir, isManagedDir, log16) {
|
|
|
48375
48947
|
await unlink11(portFile).catch(() => {
|
|
48376
48948
|
});
|
|
48377
48949
|
}
|
|
48378
|
-
if (
|
|
48950
|
+
if (resolve18(dir) !== active2)
|
|
48379
48951
|
await rmdir2(dir).catch(() => {
|
|
48380
48952
|
});
|
|
48381
48953
|
}
|
|
@@ -48405,7 +48977,7 @@ var BodyTooLargeError = class extends Error {
|
|
|
48405
48977
|
}
|
|
48406
48978
|
};
|
|
48407
48979
|
function readBody(req) {
|
|
48408
|
-
return new Promise((
|
|
48980
|
+
return new Promise((resolve20, reject) => {
|
|
48409
48981
|
const tooLarge = (declaredOversize = false) => {
|
|
48410
48982
|
req.removeAllListeners("data");
|
|
48411
48983
|
req.on("data", () => {
|
|
@@ -48428,7 +49000,7 @@ function readBody(req) {
|
|
|
48428
49000
|
}
|
|
48429
49001
|
chunks.push(chunk);
|
|
48430
49002
|
});
|
|
48431
|
-
req.on("end", () =>
|
|
49003
|
+
req.on("end", () => resolve20(Buffer.concat(chunks).toString("utf8")));
|
|
48432
49004
|
req.on("error", reject);
|
|
48433
49005
|
});
|
|
48434
49006
|
}
|
|
@@ -48596,12 +49168,12 @@ async function startRpcServer(options) {
|
|
|
48596
49168
|
json(500, { error: "internal error" });
|
|
48597
49169
|
}
|
|
48598
49170
|
}
|
|
48599
|
-
const port = await new Promise((
|
|
49171
|
+
const port = await new Promise((resolve20, reject) => {
|
|
48600
49172
|
server.on("error", reject);
|
|
48601
49173
|
server.listen(0, "127.0.0.1", () => {
|
|
48602
49174
|
const addr = server.address();
|
|
48603
49175
|
if (addr && typeof addr === "object")
|
|
48604
|
-
|
|
49176
|
+
resolve20(addr.port);
|
|
48605
49177
|
else
|
|
48606
49178
|
reject(new Error("no port"));
|
|
48607
49179
|
});
|
|
@@ -48624,16 +49196,16 @@ async function startRpcServer(options) {
|
|
|
48624
49196
|
rpcPort: port
|
|
48625
49197
|
});
|
|
48626
49198
|
} catch (error) {
|
|
48627
|
-
await new Promise((
|
|
49199
|
+
await new Promise((resolve20) => server.close(() => resolve20()));
|
|
48628
49200
|
throw error;
|
|
48629
49201
|
}
|
|
48630
49202
|
return {
|
|
48631
49203
|
port,
|
|
48632
49204
|
token,
|
|
48633
49205
|
async stop() {
|
|
48634
|
-
await new Promise((
|
|
49206
|
+
await new Promise((resolve20) => {
|
|
48635
49207
|
server.closeAllConnections?.();
|
|
48636
|
-
server.close(() =>
|
|
49208
|
+
server.close(() => resolve20());
|
|
48637
49209
|
for (const socket of connections)
|
|
48638
49210
|
socket.destroy();
|
|
48639
49211
|
});
|
|
@@ -49217,7 +49789,7 @@ async function select3(items, options) {
|
|
|
49217
49789
|
}
|
|
49218
49790
|
renderedLines = linesWritten;
|
|
49219
49791
|
};
|
|
49220
|
-
return new Promise((
|
|
49792
|
+
return new Promise((resolve20) => {
|
|
49221
49793
|
const wasRaw = stdin.isRaw ?? false;
|
|
49222
49794
|
const cleanup2 = () => {
|
|
49223
49795
|
if (isCleanedUp) return;
|
|
@@ -49238,11 +49810,11 @@ async function select3(items, options) {
|
|
|
49238
49810
|
};
|
|
49239
49811
|
const onSignal = () => {
|
|
49240
49812
|
cleanup2();
|
|
49241
|
-
|
|
49813
|
+
resolve20(null);
|
|
49242
49814
|
};
|
|
49243
49815
|
const finishWithValue = (value) => {
|
|
49244
49816
|
cleanup2();
|
|
49245
|
-
|
|
49817
|
+
resolve20(value);
|
|
49246
49818
|
};
|
|
49247
49819
|
const findNextSelectable = (from, direction) => {
|
|
49248
49820
|
if (items.length === 0) return from;
|
|
@@ -49288,7 +49860,7 @@ async function select3(items, options) {
|
|
|
49288
49860
|
stdin.setRawMode(true);
|
|
49289
49861
|
} catch {
|
|
49290
49862
|
cleanup2();
|
|
49291
|
-
|
|
49863
|
+
resolve20(null);
|
|
49292
49864
|
return;
|
|
49293
49865
|
}
|
|
49294
49866
|
stdin.resume();
|
|
@@ -52118,7 +52690,7 @@ var BackgroundVaultQuotaRefresh = class {
|
|
|
52118
52690
|
fetchReading: async (ref, signal) => {
|
|
52119
52691
|
rowFailure = "fetch-failed";
|
|
52120
52692
|
await this.assertActive(controller);
|
|
52121
|
-
const
|
|
52693
|
+
const fallback = () => fetchVaultAccountQuota({
|
|
52122
52694
|
source,
|
|
52123
52695
|
ref,
|
|
52124
52696
|
signal,
|
|
@@ -52128,7 +52700,10 @@ var BackgroundVaultQuotaRefresh = class {
|
|
|
52128
52700
|
if (kind !== "unknown" || outcome.errorKind === void 0)
|
|
52129
52701
|
outcome.errorKind = kind;
|
|
52130
52702
|
if (refused)
|
|
52131
|
-
rowFailure = vaultQuotaErrorReason(
|
|
52703
|
+
rowFailure = vaultQuotaErrorReason(
|
|
52704
|
+
error,
|
|
52705
|
+
"admission-refused"
|
|
52706
|
+
);
|
|
52132
52707
|
},
|
|
52133
52708
|
transport: async (url, init, extra) => {
|
|
52134
52709
|
await this.assertActive(controller);
|
|
@@ -52151,6 +52726,16 @@ var BackgroundVaultQuotaRefresh = class {
|
|
|
52151
52726
|
}
|
|
52152
52727
|
}
|
|
52153
52728
|
});
|
|
52729
|
+
const reading = source.pollInsulaQuotaForRoute ? await source.pollInsulaQuotaForRoute(
|
|
52730
|
+
ref,
|
|
52731
|
+
fallback,
|
|
52732
|
+
signal,
|
|
52733
|
+
(reason) => {
|
|
52734
|
+
rowFailure = `insula-${reason}`;
|
|
52735
|
+
}
|
|
52736
|
+
) : await fallback();
|
|
52737
|
+
if (reading === void 0 && rowFailure === "fetch-failed")
|
|
52738
|
+
rowFailure = "insula-skipped";
|
|
52154
52739
|
await this.assertActive(controller);
|
|
52155
52740
|
await lock.assertOwned();
|
|
52156
52741
|
return reading;
|
|
@@ -52481,7 +53066,7 @@ function toCommandAccountRow(entry) {
|
|
|
52481
53066
|
const parsed = Date.parse(cachedEntry.resetTime);
|
|
52482
53067
|
if (Number.isFinite(parsed)) resetAt = parsed;
|
|
52483
53068
|
}
|
|
52484
|
-
const
|
|
53069
|
+
const windows2 = cachedEntry.windows?.length ? cachedEntry.windows.map((w) => ({
|
|
52485
53070
|
window: w.window,
|
|
52486
53071
|
remainingPercent: Math.round(w.remainingFraction * 100),
|
|
52487
53072
|
resetAt: typeof w.resetTime === "string" && w.resetTime.length > 0 ? (() => {
|
|
@@ -52494,7 +53079,7 @@ function toCommandAccountRow(entry) {
|
|
|
52494
53079
|
label: QUOTA_GROUP_LABELS[key],
|
|
52495
53080
|
remainingPercent,
|
|
52496
53081
|
resetAt,
|
|
52497
|
-
windows
|
|
53082
|
+
windows: windows2
|
|
52498
53083
|
});
|
|
52499
53084
|
}
|
|
52500
53085
|
const label = `Account ${entry.index + 1}`;
|
|
@@ -52570,10 +53155,10 @@ function resolvePluginDependencies(overrides = {}) {
|
|
|
52570
53155
|
}
|
|
52571
53156
|
async function defaultSleep(ms, signal) {
|
|
52572
53157
|
if (ms <= 0) return;
|
|
52573
|
-
await new Promise((
|
|
53158
|
+
await new Promise((resolve20, reject) => {
|
|
52574
53159
|
const timer = setTimeout(() => {
|
|
52575
53160
|
signal?.removeEventListener("abort", onAbort);
|
|
52576
|
-
|
|
53161
|
+
resolve20();
|
|
52577
53162
|
}, ms);
|
|
52578
53163
|
timer.unref?.();
|
|
52579
53164
|
const onAbort = () => {
|
|
@@ -52595,7 +53180,7 @@ function createEventHandler({
|
|
|
52595
53180
|
sessionRegistry,
|
|
52596
53181
|
sessionRecovery,
|
|
52597
53182
|
updateChecker,
|
|
52598
|
-
logger:
|
|
53183
|
+
logger: logger3
|
|
52599
53184
|
}) {
|
|
52600
53185
|
return async (input2) => {
|
|
52601
53186
|
await updateChecker.event(input2);
|
|
@@ -52607,14 +53192,14 @@ function createEventHandler({
|
|
|
52607
53192
|
sessionRegistry.register(sessionId, parentSessionId);
|
|
52608
53193
|
}
|
|
52609
53194
|
if (parentSessionId) {
|
|
52610
|
-
|
|
53195
|
+
logger3.debug("child-session-detected", {
|
|
52611
53196
|
sessionId,
|
|
52612
53197
|
parentID: parentSessionId
|
|
52613
53198
|
});
|
|
52614
53199
|
} else {
|
|
52615
53200
|
const previousSummary = lifecycle.getAccountManager()?.getSessionSummary();
|
|
52616
53201
|
if (previousSummary && (previousSummary.totalClaude > 0 || previousSummary.totalGemini > 0)) {
|
|
52617
|
-
|
|
53202
|
+
logger3.debug("prev-session-quota-summary", {
|
|
52618
53203
|
durationMinutes: previousSummary.durationMinutes,
|
|
52619
53204
|
totalClaude: previousSummary.totalClaude,
|
|
52620
53205
|
totalGemini: previousSummary.totalGemini,
|
|
@@ -52622,7 +53207,7 @@ function createEventHandler({
|
|
|
52622
53207
|
accountsUsed: previousSummary.accountsUsed
|
|
52623
53208
|
});
|
|
52624
53209
|
}
|
|
52625
|
-
|
|
53210
|
+
logger3.debug("root-session-detected", { sessionId });
|
|
52626
53211
|
}
|
|
52627
53212
|
}
|
|
52628
53213
|
if (input2.event.type === "session.deleted") {
|
|
@@ -52631,7 +53216,7 @@ function createEventHandler({
|
|
|
52631
53216
|
if (sessionId) {
|
|
52632
53217
|
sessionRegistry.delete(sessionId);
|
|
52633
53218
|
lifecycle.getAccountManager()?.deleteSessionState(sessionId);
|
|
52634
|
-
const eventLogger =
|
|
53219
|
+
const eventLogger = logger3;
|
|
52635
53220
|
void removeSidebarActiveRouting(sessionId).catch((error2) => {
|
|
52636
53221
|
eventLogger.debug("sidebar-route-remove-failed", {
|
|
52637
53222
|
sessionId,
|
|
@@ -52667,7 +53252,7 @@ function createEventHandler({
|
|
|
52667
53252
|
});
|
|
52668
53253
|
const successToast = getRecoverySuccessToast();
|
|
52669
53254
|
const isChildSession = sessionRegistry.getParentSessionId(sessionID) !== null;
|
|
52670
|
-
|
|
53255
|
+
logger3.debug("recovery-toast", {
|
|
52671
53256
|
...successToast,
|
|
52672
53257
|
isChildSession,
|
|
52673
53258
|
toastScope: config.toast_scope
|
|
@@ -53271,8 +53856,8 @@ function createPluginLifecycle(options) {
|
|
|
53271
53856
|
};
|
|
53272
53857
|
let failDisposal = () => {
|
|
53273
53858
|
};
|
|
53274
|
-
disposal = new Promise((
|
|
53275
|
-
finishDisposal =
|
|
53859
|
+
disposal = new Promise((resolve20, reject) => {
|
|
53860
|
+
finishDisposal = resolve20;
|
|
53276
53861
|
failDisposal = reject;
|
|
53277
53862
|
});
|
|
53278
53863
|
void (async () => {
|
|
@@ -53336,7 +53921,7 @@ function createSourceSidebarPublisher(options) {
|
|
|
53336
53921
|
}
|
|
53337
53922
|
|
|
53338
53923
|
// src/plugin/index.ts
|
|
53339
|
-
var
|
|
53924
|
+
var logger2 = createLogger4("plugin");
|
|
53340
53925
|
function quotaAccountIdentity4(refreshToken) {
|
|
53341
53926
|
return createHash20("sha256").update(refreshToken).digest("hex").slice(0, 16);
|
|
53342
53927
|
}
|
|
@@ -53405,7 +53990,8 @@ var createAntigravityPlugin = (providerId, options = {}) => async (input2) => {
|
|
|
53405
53990
|
});
|
|
53406
53991
|
let vaultQuotaPoller;
|
|
53407
53992
|
const vaultCustody = createOpenCodeVaultCustody({
|
|
53408
|
-
accountFile:
|
|
53993
|
+
accountFile: resolve19(getStoragePath()),
|
|
53994
|
+
insulaQuota: true,
|
|
53409
53995
|
readHostSlot: async () => {
|
|
53410
53996
|
if (!cachedGetAuth)
|
|
53411
53997
|
throw new Error("OpenCode has not provided its sign-in yet");
|
|
@@ -53528,7 +54114,7 @@ var createAntigravityPlugin = (providerId, options = {}) => async (input2) => {
|
|
|
53528
54114
|
});
|
|
53529
54115
|
function scheduleSidebarPublication() {
|
|
53530
54116
|
void sidebarPublisher.publish().catch(
|
|
53531
|
-
(error) =>
|
|
54117
|
+
(error) => logger2.debug("sidebar-source-publish-failed", {
|
|
53532
54118
|
error: error instanceof Error ? error.name : "unknown"
|
|
53533
54119
|
})
|
|
53534
54120
|
);
|
|
@@ -53558,7 +54144,7 @@ var createAntigravityPlugin = (providerId, options = {}) => async (input2) => {
|
|
|
53558
54144
|
}
|
|
53559
54145
|
);
|
|
53560
54146
|
})().catch(
|
|
53561
|
-
(error) =>
|
|
54147
|
+
(error) => logger2.debug("sidebar-routing-publish-failed", {
|
|
53562
54148
|
error: error instanceof Error ? error.name : "unknown"
|
|
53563
54149
|
})
|
|
53564
54150
|
);
|
|
@@ -53603,8 +54189,8 @@ var createAntigravityPlugin = (providerId, options = {}) => async (input2) => {
|
|
|
53603
54189
|
readProviderState: () => vaultCustody.readState(),
|
|
53604
54190
|
publishSidebar: () => sidebarPublisher.publish(),
|
|
53605
54191
|
transport: vaultQuotaTransport,
|
|
53606
|
-
logger,
|
|
53607
|
-
onOutcome: (level, outcome) => (level === "warn" ? quotaOutcomeLogger :
|
|
54192
|
+
logger: logger2,
|
|
54193
|
+
onOutcome: (level, outcome) => (level === "warn" ? quotaOutcomeLogger : logger2)[level](
|
|
53608
54194
|
"vault-quota-tick",
|
|
53609
54195
|
{ ...outcome }
|
|
53610
54196
|
),
|
|
@@ -53640,7 +54226,7 @@ var createAntigravityPlugin = (providerId, options = {}) => async (input2) => {
|
|
|
53640
54226
|
sessionRegistry,
|
|
53641
54227
|
sessionRecovery,
|
|
53642
54228
|
updateChecker,
|
|
53643
|
-
logger
|
|
54229
|
+
logger: logger2
|
|
53644
54230
|
});
|
|
53645
54231
|
let storeQuota = null;
|
|
53646
54232
|
const currentStoreQuota = async (knownRepository) => {
|
|
@@ -53746,7 +54332,7 @@ var createAntigravityPlugin = (providerId, options = {}) => async (input2) => {
|
|
|
53746
54332
|
source,
|
|
53747
54333
|
ref,
|
|
53748
54334
|
signal: check,
|
|
53749
|
-
logger,
|
|
54335
|
+
logger: logger2,
|
|
53750
54336
|
transport: vaultQuotaTransport
|
|
53751
54337
|
})
|
|
53752
54338
|
},
|
|
@@ -54006,7 +54592,7 @@ var createAntigravityPlugin = (providerId, options = {}) => async (input2) => {
|
|
|
54006
54592
|
if (await readAuthority2() === "local")
|
|
54007
54593
|
await lifecycle.getAccountManager()?.refreshFromRepository();
|
|
54008
54594
|
} catch (error) {
|
|
54009
|
-
|
|
54595
|
+
logger2.warn("menu-routing-refresh-failed", { error: String(error) });
|
|
54010
54596
|
pushNotification(
|
|
54011
54597
|
{
|
|
54012
54598
|
command: ANTIGRAVITY_MENU_COMMAND,
|