@cortexkit/opencode-antigravity-auth 3.0.7 → 3.0.8
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 +1001 -63
- package/dist/cli.js.map +4 -4
- package/dist/cli.meta.json +112 -30
- package/dist/index.js +1270 -219
- package/dist/index.js.map +4 -4
- package/dist/index.meta.json +154 -48
- package/dist/server.js +1190 -120
- package/dist/server.js.map +4 -4
- package/dist/server.meta.json +1 -1
- package/dist/src/common-auth-embedded/claustrum/availability.d.ts +89 -0
- package/dist/src/common-auth-embedded/claustrum/availability.js +106 -0
- package/dist/src/common-auth-embedded/claustrum/consumer.d.ts +31 -1
- package/dist/src/common-auth-embedded/claustrum/consumer.js +114 -5
- package/dist/src/common-auth-embedded/claustrum/custody.d.ts +106 -14
- package/dist/src/common-auth-embedded/claustrum/custody.js +294 -16
- package/dist/src/common-auth-embedded/claustrum/errors.d.ts +1 -0
- package/dist/src/common-auth-embedded/claustrum/index.d.ts +5 -3
- package/dist/src/common-auth-embedded/claustrum/index.js +4 -1
- package/dist/src/common-auth-embedded/claustrum/insula.d.ts +48 -0
- package/dist/src/common-auth-embedded/claustrum/insula.js +286 -21
- package/dist/src/common-auth-embedded/claustrum/watch.d.ts +141 -0
- package/dist/src/common-auth-embedded/claustrum/watch.js +254 -0
- package/dist/src/common-auth-embedded/fs/private-files.js +10 -2
- package/dist/src/common-auth-embedded/quota/format.d.ts +3 -0
- package/dist/src/common-auth-embedded/quota/format.js +69 -1
- package/dist/src/common-auth-embedded/quota/index.d.ts +1 -1
- package/dist/src/common-auth-embedded/quota/projection.d.ts +16 -0
- package/dist/src/common-auth-embedded/source-output.json +81 -49
- package/dist/src/ga/server/index.d.ts +2 -0
- package/dist/src/ga/server/index.d.ts.map +1 -1
- package/dist/src/ga/server/index.js +14 -1
- package/dist/src/ga/server/index.js.map +1 -1
- package/dist/src/plugin/auth-loader.d.ts +2 -1
- package/dist/src/plugin/auth-loader.d.ts.map +1 -1
- package/dist/src/plugin/auth-loader.js +5 -4
- package/dist/src/plugin/auth-loader.js.map +1 -1
- package/dist/src/plugin/fetch-interceptor.d.ts +2 -1
- package/dist/src/plugin/fetch-interceptor.d.ts.map +1 -1
- package/dist/src/plugin/fetch-interceptor.js +8 -6
- package/dist/src/plugin/fetch-interceptor.js.map +1 -1
- package/dist/src/plugin/ga-location-services.d.ts.map +1 -1
- package/dist/src/plugin/ga-location-services.js +3 -0
- package/dist/src/plugin/ga-location-services.js.map +1 -1
- package/dist/src/plugin/shared/after-handoff.d.ts +14 -0
- package/dist/src/plugin/shared/after-handoff.d.ts.map +1 -0
- package/dist/src/plugin/shared/after-handoff.js +89 -0
- package/dist/src/plugin/shared/after-handoff.js.map +1 -0
- package/dist/src/plugin/shared/request-services.d.ts +8 -2
- package/dist/src/plugin/shared/request-services.d.ts.map +1 -1
- package/dist/src/plugin/shared/request-services.js +57 -36
- package/dist/src/plugin/shared/request-services.js.map +1 -1
- package/dist/src/plugin/shared/vault-request-credentials.d.ts +2 -2
- package/dist/src/plugin/shared/vault-request-credentials.d.ts.map +1 -1
- package/dist/src/plugin/shared/vault-request-credentials.js +14 -1
- 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 +3 -0
- package/dist/src/plugin/vault-custody.js.map +1 -1
- package/dist/src/tui.d.ts.map +1 -1
- package/dist/src/tui.js +82 -66
- package/dist/src/tui.js.map +1 -1
- package/dist/tui-build-map.json +27 -27
- package/dist/tui-ga-build-map.json +5 -5
- package/dist/types/src/common-auth-embedded/claustrum/availability.d.ts +89 -0
- package/dist/types/src/common-auth-embedded/claustrum/consumer.d.ts +31 -1
- package/dist/types/src/common-auth-embedded/claustrum/custody.d.ts +106 -14
- package/dist/types/src/common-auth-embedded/claustrum/errors.d.ts +1 -0
- package/dist/types/src/common-auth-embedded/claustrum/index.d.ts +5 -3
- package/dist/types/src/common-auth-embedded/claustrum/insula.d.ts +48 -0
- package/dist/types/src/common-auth-embedded/claustrum/watch.d.ts +141 -0
- package/dist/types/src/common-auth-embedded/quota/format.d.ts +3 -0
- package/dist/types/src/common-auth-embedded/quota/index.d.ts +1 -1
- package/dist/types/src/common-auth-embedded/quota/projection.d.ts +16 -0
- package/dist/types/src/ga/server/index.d.ts +2 -0
- package/dist/types/src/ga/server/index.d.ts.map +1 -1
- package/dist/types/src/plugin/auth-loader.d.ts +2 -1
- package/dist/types/src/plugin/auth-loader.d.ts.map +1 -1
- package/dist/types/src/plugin/fetch-interceptor.d.ts +2 -1
- package/dist/types/src/plugin/fetch-interceptor.d.ts.map +1 -1
- package/dist/types/src/plugin/ga-location-services.d.ts.map +1 -1
- package/dist/types/src/plugin/shared/after-handoff.d.ts +14 -0
- package/dist/types/src/plugin/shared/after-handoff.d.ts.map +1 -0
- package/dist/types/src/plugin/shared/request-services.d.ts +8 -2
- package/dist/types/src/plugin/shared/request-services.d.ts.map +1 -1
- package/dist/types/src/plugin/shared/vault-request-credentials.d.ts +2 -2
- 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/package.json +4 -4
- package/src/common-auth-embedded/claustrum/availability.d.ts +89 -0
- package/src/common-auth-embedded/claustrum/availability.js +106 -0
- package/src/common-auth-embedded/claustrum/consumer.d.ts +31 -1
- package/src/common-auth-embedded/claustrum/consumer.js +114 -5
- package/src/common-auth-embedded/claustrum/custody.d.ts +106 -14
- package/src/common-auth-embedded/claustrum/custody.js +294 -16
- package/src/common-auth-embedded/claustrum/errors.d.ts +1 -0
- package/src/common-auth-embedded/claustrum/index.d.ts +5 -3
- package/src/common-auth-embedded/claustrum/index.js +4 -1
- package/src/common-auth-embedded/claustrum/insula.d.ts +48 -0
- package/src/common-auth-embedded/claustrum/insula.js +286 -21
- package/src/common-auth-embedded/claustrum/watch.d.ts +141 -0
- package/src/common-auth-embedded/claustrum/watch.js +254 -0
- package/src/common-auth-embedded/fs/private-files.js +10 -2
- package/src/common-auth-embedded/quota/format.d.ts +3 -0
- package/src/common-auth-embedded/quota/format.js +69 -1
- package/src/common-auth-embedded/quota/index.d.ts +1 -1
- package/src/common-auth-embedded/quota/projection.d.ts +16 -0
- package/src/common-auth-embedded/source-output.json +81 -49
- package/src/tui-compiled/common-auth-embedded/fs/private-files.js +10 -2
- package/src/tui-compiled/common-auth-embedded/quota/format.js +69 -1
- package/src/tui-compiled/tui.js +123 -97
- package/src/tui-ga-compiled/shared/aef2402f8fc342f0-format.js +69 -1
- package/src/tui-ga-raw/shared/aef2402f8fc342f0-format.js +69 -1
- package/src/tui-raw/common-auth-embedded/fs/private-files.js +10 -2
- package/src/tui-raw/common-auth-embedded/quota/format.js +69 -1
- package/src/tui-raw/tui.tsx +126 -107
- package/src/tui.tsx +126 -107
|
@@ -184,19 +184,25 @@ export async function replaceWindowsFile(from, to, options = {}) {
|
|
|
184
184
|
to = resolve(to);
|
|
185
185
|
const now = options.now ?? (() => performance.now());
|
|
186
186
|
const start = now();
|
|
187
|
-
const
|
|
187
|
+
const leaseDeadline = options.deadline ?? Infinity;
|
|
188
|
+
let retryDeadline;
|
|
188
189
|
const delays = [0, 10, 20, 40, 80, 100];
|
|
189
190
|
let original;
|
|
190
191
|
let attempts = 0;
|
|
191
192
|
for (const delay of delays) {
|
|
193
|
+
const deadline = Math.min(retryDeadline ?? Infinity, leaseDeadline);
|
|
192
194
|
if (now() >= deadline)
|
|
193
195
|
break;
|
|
194
196
|
if (delay)
|
|
195
197
|
await (options.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms))))(Math.min(delay, Math.max(0, deadline - now())));
|
|
196
198
|
if (now() >= deadline)
|
|
197
199
|
break;
|
|
200
|
+
const fenceStart = now();
|
|
198
201
|
await options.beforeRename?.();
|
|
199
|
-
|
|
202
|
+
// Ownership checks fence every attempt but do not spend the sharing-retry budget.
|
|
203
|
+
if (retryDeadline !== undefined)
|
|
204
|
+
retryDeadline += now() - fenceStart;
|
|
205
|
+
if (now() >= leaseDeadline)
|
|
200
206
|
break;
|
|
201
207
|
attempts++;
|
|
202
208
|
try {
|
|
@@ -212,6 +218,8 @@ export async function replaceWindowsFile(from, to, options = {}) {
|
|
|
212
218
|
!detail.reason;
|
|
213
219
|
if (!candidate)
|
|
214
220
|
break;
|
|
221
|
+
// Start the retry window only once a rename has actually failed.
|
|
222
|
+
retryDeadline ??= now() + 500;
|
|
215
223
|
}
|
|
216
224
|
}
|
|
217
225
|
const error = new PrivateFileError(to, 'rename', original ??
|
|
@@ -122,6 +122,9 @@ function scopedWindowParts(quota, options) {
|
|
|
122
122
|
const remainingPercent = clampPercent(limit.remainingPercent ?? 0);
|
|
123
123
|
return {
|
|
124
124
|
scope: limit.scope,
|
|
125
|
+
...(limit.windowMinutes === undefined
|
|
126
|
+
? {}
|
|
127
|
+
: { windowMinutes: limit.windowMinutes }),
|
|
125
128
|
part: {
|
|
126
129
|
kind: 'window',
|
|
127
130
|
name: quotaWindowName(limit),
|
|
@@ -212,6 +215,66 @@ function scopeAbbreviations(scopes) {
|
|
|
212
215
|
}
|
|
213
216
|
return new Map(scopes.map((scope) => [scope, short(scopeDisplayName(scope))]));
|
|
214
217
|
}
|
|
218
|
+
/** The most groups a grouped narrow line shows. */
|
|
219
|
+
const NARROW_GROUP_LIMIT = 2;
|
|
220
|
+
/**
|
|
221
|
+
* The names the groups read under in the narrow line, one per listed group:
|
|
222
|
+
* each label's short name, derived exactly as a model window's is (`Gemini`
|
|
223
|
+
* → `Ge`, `Other models` → `Ot`, colliding names extended until they
|
|
224
|
+
* differ), computed over every listed group so a group keeps its name
|
|
225
|
+
* whichever groups show. A blank label falls back to the group's scope.
|
|
226
|
+
*/
|
|
227
|
+
function groupShortNames(groups) {
|
|
228
|
+
const labels = groups.map((group) => group.label.trim() || group.scope);
|
|
229
|
+
const short = scopeAbbreviations(labels);
|
|
230
|
+
return labels.map((label) => short.get(label) ?? label);
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* The narrow line of a reading whose windows belong to named groups and that
|
|
234
|
+
* has no account-wide window: for each group, its tightest window as
|
|
235
|
+
* `Ge 7d 62%`, with ` left` once at the end. The tightest window is the
|
|
236
|
+
* one with least left, compared before rounding; on a tie the first in
|
|
237
|
+
* display order (the shorter window) wins. At most two groups show: the two
|
|
238
|
+
* with least left, earlier-listed first on a tie, and always in the order
|
|
239
|
+
* the reading lists them, so the line does not reorder as the figures move.
|
|
240
|
+
* A group with no reported window is skipped. Windows outside the listed
|
|
241
|
+
* groups and the credit budget are left out. Undefined when the rule does
|
|
242
|
+
* not apply, so the caller uses the ordinary narrow rule.
|
|
243
|
+
*/
|
|
244
|
+
function groupedNarrowPieces(groups, windows) {
|
|
245
|
+
if (!groups || groups.length === 0)
|
|
246
|
+
return undefined;
|
|
247
|
+
const reported = windows.filter(({ part }) => part.kind === 'window');
|
|
248
|
+
if (reported.some(({ scope }) => scope === ALL_SCOPE))
|
|
249
|
+
return undefined;
|
|
250
|
+
const candidates = groups.flatMap((group, listed) => {
|
|
251
|
+
const inGroup = reported.filter(({ scope }) => scope === group.scope);
|
|
252
|
+
// `windows` is already in display order, and strictly lower wins, so on
|
|
253
|
+
// a tie the shorter window keeps the place.
|
|
254
|
+
const groupTightest = inGroup.reduce((least, window) => least === undefined ||
|
|
255
|
+
(window.part.remainingPercent ?? 0) < (least.part.remainingPercent ?? 0)
|
|
256
|
+
? window
|
|
257
|
+
: least, undefined);
|
|
258
|
+
return groupTightest ? [{ group, listed, window: groupTightest }] : [];
|
|
259
|
+
});
|
|
260
|
+
if (candidates.length === 0)
|
|
261
|
+
return undefined;
|
|
262
|
+
const names = groupShortNames(groups);
|
|
263
|
+
const left = (candidate) => candidate.window.part.remainingPercent ?? 0;
|
|
264
|
+
const shown = [...candidates]
|
|
265
|
+
.sort((a, b) => left(a) - left(b) || a.listed - b.listed)
|
|
266
|
+
.slice(0, NARROW_GROUP_LIMIT)
|
|
267
|
+
.sort((a, b) => a.listed - b.listed);
|
|
268
|
+
return shown.map((candidate, index) => {
|
|
269
|
+
const { windowMinutes } = candidate.window;
|
|
270
|
+
const piece = [
|
|
271
|
+
names[candidate.listed] ?? candidate.group.scope,
|
|
272
|
+
...(windowMinutes === undefined ? [] : [lengthName(windowMinutes)]),
|
|
273
|
+
`${wholePercent(left(candidate))}%`,
|
|
274
|
+
].join(' ');
|
|
275
|
+
return index === shown.length - 1 ? `${piece} left` : piece;
|
|
276
|
+
});
|
|
277
|
+
}
|
|
215
278
|
/**
|
|
216
279
|
* The narrow form's pieces: every account-wide window as `5h 92%`, then at
|
|
217
280
|
* most one more item, with ` left` added once to the last piece. That item is
|
|
@@ -224,10 +287,15 @@ function scopeAbbreviations(scopes) {
|
|
|
224
287
|
* be chosen; when nothing at all is shown it keeps its compact wording
|
|
225
288
|
* (`credits available`). No age is added; `isQuotaStale` says whether the
|
|
226
289
|
* reading is stale. A window whose reset arrived after the reading keeps its
|
|
227
|
-
* figure, as in the other forms.
|
|
290
|
+
* figure, as in the other forms. A reading that lists named groups and has no
|
|
291
|
+
* account-wide window reads one item per group instead (see
|
|
292
|
+
* `groupedNarrowPieces`).
|
|
228
293
|
*/
|
|
229
294
|
function narrowTextParts(quota, options) {
|
|
230
295
|
const { windows } = scopedWindowParts(quota, options);
|
|
296
|
+
const grouped = groupedNarrowPieces(quota?.groups, windows);
|
|
297
|
+
if (grouped)
|
|
298
|
+
return grouped;
|
|
231
299
|
const general = windows.filter(({ part, scope }) => part.kind === 'window' && scope === ALL_SCOPE);
|
|
232
300
|
const scoped = windows.filter(({ part, scope }) => part.kind === 'window' && scope !== ALL_SCOPE);
|
|
233
301
|
const abbreviations = scopeAbbreviations(scoped.map(({ scope }) => scope));
|
package/src/tui-compiled/tui.js
CHANGED
|
@@ -52,13 +52,13 @@ import { readFileSync } from "node:fs";
|
|
|
52
52
|
import { dirname, join } from "node:path";
|
|
53
53
|
import { fileURLToPath } from "node:url";
|
|
54
54
|
import { createSlot } from "opentui:runtime-module:%40opentui%2Fsolid";
|
|
55
|
-
import { createSignal, For, onCleanup, onMount, Show } from "opentui:runtime-module:solid-js";
|
|
56
|
-
import {
|
|
55
|
+
import { createMemo, createSignal, For, onCleanup, onMount, Show } from "opentui:runtime-module:solid-js";
|
|
56
|
+
import { formatQuota, isQuotaStale } from "./common-auth-embedded/quota/index.js";
|
|
57
57
|
import { getRpcDir } from "./rpc/rpc-dir.js";
|
|
58
58
|
import { readSidebarState } from "./sidebar-state.js";
|
|
59
59
|
import { createTuiFileLogger } from "./tui/file-logger.js";
|
|
60
60
|
import { createV1MenuTransport, dispatchV1Notification } from "./tui/host-v1.js";
|
|
61
|
-
import { ASSUMED_CONTENT_WIDTH, accountWindows, fitLabel,
|
|
61
|
+
import { ASSUMED_CONTENT_WIDTH, accountWindows, fitLabel, GROUP_NAMES, QUOTA_ORDER, QuotaAccountBlock, quotaTone } from "./tui/quota-layout.js";
|
|
62
62
|
import { routeLineFits } from "./tui/route-layout.js";
|
|
63
63
|
import { computeEffectiveOrder, DEFAULT_PREFS, DEFAULT_SLOT_ORDER, PLUGIN_KEY, queueTuiPreferenceUpdate, readTuiPreferencesFile, resolveAntigravityAuthPrefs, watchTuiPreferences } from "./tui-preferences.js";
|
|
64
64
|
const ID = 'cortexkit.antigravity-auth';
|
|
@@ -106,11 +106,6 @@ let rpcInFlight = false;
|
|
|
106
106
|
const GLOBAL_NOTIFICATION_CURSOR = '__global__';
|
|
107
107
|
const MAX_NOTIFICATION_CURSORS = 256;
|
|
108
108
|
|
|
109
|
-
// The collapsed row has room for one word before the window name.
|
|
110
|
-
const COLLAPSED_GROUP_NAMES = {
|
|
111
|
-
gemini: 'Gemini',
|
|
112
|
-
'non-gemini': 'Other'
|
|
113
|
-
};
|
|
114
109
|
// --- Theme tokens ----------------------------------------------------------
|
|
115
110
|
//
|
|
116
111
|
// The sidebar pulls its colors from the live host theme (`api.theme.current`
|
|
@@ -390,8 +385,8 @@ function StatRow(props) {
|
|
|
390
385
|
}
|
|
391
386
|
|
|
392
387
|
// Fleet CollapsedRow: muted label left, caller-supplied value right. The
|
|
393
|
-
// collapsed view renders one for
|
|
394
|
-
// sides to the measured width, so neither side may wrap.
|
|
388
|
+
// collapsed view renders one row for every visible account. The caller sizes
|
|
389
|
+
// both sides to the measured width, so neither side may wrap.
|
|
395
390
|
function CollapsedRow(props) {
|
|
396
391
|
return (() => {
|
|
397
392
|
var _el$8 = _$createElement("box"),
|
|
@@ -460,32 +455,47 @@ function AccountBlock(props) {
|
|
|
460
455
|
}
|
|
461
456
|
});
|
|
462
457
|
}
|
|
463
|
-
|
|
464
|
-
//
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
458
|
+
|
|
459
|
+
// Sidebar snapshots store quota values as percentages and epoch-millisecond
|
|
460
|
+
// reset times. Adapt those values to the shared projection so common-auth, not
|
|
461
|
+
// the renderer, decides how the narrow line reads.
|
|
462
|
+
function sidebarQuotaProjection(account, now) {
|
|
463
|
+
const limits = [];
|
|
464
|
+
for (const {
|
|
465
|
+
key,
|
|
466
|
+
reading
|
|
467
|
+
} of accountWindows(account, now)) {
|
|
468
|
+
const {
|
|
469
|
+
checkedAt,
|
|
470
|
+
remainingPercent,
|
|
471
|
+
resetAt,
|
|
472
|
+
window
|
|
473
|
+
} = reading;
|
|
474
|
+
if (typeof checkedAt !== 'number' || !Number.isFinite(checkedAt) || checkedAt < 0 || !Number.isFinite(remainingPercent)) continue;
|
|
475
|
+
const resetsAt = typeof resetAt === 'number' && Number.isFinite(resetAt) && Math.abs(resetAt) <= 8.64e15 ? new Date(resetAt).toISOString() : undefined;
|
|
476
|
+
limits.push({
|
|
477
|
+
scope: key,
|
|
478
|
+
label: GROUP_NAMES[key],
|
|
479
|
+
kind: 'reading',
|
|
480
|
+
checkedAt,
|
|
481
|
+
remainingPercent: Math.max(0, Math.min(100, remainingPercent)),
|
|
482
|
+
...(window ? {
|
|
483
|
+
windowMinutes: window === 'weekly' ? 7 * 24 * 60 : 5 * 60
|
|
484
|
+
} : {}),
|
|
485
|
+
...(resetsAt ? {
|
|
486
|
+
resetsAt
|
|
487
|
+
} : {})
|
|
488
|
+
});
|
|
484
489
|
}
|
|
490
|
+
if (limits.length === 0) return undefined;
|
|
485
491
|
return {
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
492
|
+
scope: 'all',
|
|
493
|
+
limits,
|
|
494
|
+
checkedAt: Math.min(...limits.map(limit => limit.checkedAt)),
|
|
495
|
+
groups: QUOTA_ORDER.map(scope => ({
|
|
496
|
+
scope,
|
|
497
|
+
label: GROUP_NAMES[scope]
|
|
498
|
+
}))
|
|
489
499
|
};
|
|
490
500
|
}
|
|
491
501
|
function formatWait(ms) {
|
|
@@ -668,70 +678,86 @@ export function SidebarPanel(props) {
|
|
|
668
678
|
return _$memo(() => !!collapsed())() && hasData();
|
|
669
679
|
},
|
|
670
680
|
get children() {
|
|
671
|
-
return (
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
const tone = () => {
|
|
684
|
-
const remaining = quota().remaining;
|
|
685
|
-
return remaining == null ? 'muted' : quotaTone(100 - remaining, prefs().appearance);
|
|
686
|
-
};
|
|
687
|
-
// Label, one space, the figure and the two-cell dot. The
|
|
688
|
-
// group prefix goes first when narrow; then the label is cut.
|
|
689
|
-
const figure = () => {
|
|
690
|
-
const {
|
|
691
|
-
prefix,
|
|
692
|
-
text
|
|
693
|
-
} = quota();
|
|
694
|
-
const full = `${prefix}${text}`;
|
|
695
|
-
return selected().label.length + 1 + full.length + 2 <= contentWidth() ? full : text;
|
|
696
|
-
};
|
|
697
|
-
const label = () => fitLabel(selected().label, contentWidth() - 1 - figure().length - 2);
|
|
698
|
-
return _$createComponent(CollapsedRow, {
|
|
699
|
-
theme: theme,
|
|
700
|
-
get label() {
|
|
701
|
-
return label();
|
|
702
|
-
},
|
|
703
|
-
get children() {
|
|
704
|
-
var _el$18 = _$createElement("box"),
|
|
705
|
-
_el$19 = _$createElement("text"),
|
|
706
|
-
_el$20 = _$createElement("b"),
|
|
707
|
-
_el$21 = _$createElement("text");
|
|
708
|
-
_$insertNode(_el$18, _el$19);
|
|
709
|
-
_$insertNode(_el$18, _el$21);
|
|
710
|
-
_$setProp(_el$18, "flexDirection", 'row');
|
|
711
|
-
_$setProp(_el$18, "flexShrink", 0);
|
|
712
|
-
_$insertNode(_el$19, _el$20);
|
|
713
|
-
_$setProp(_el$19, "flexShrink", 0);
|
|
714
|
-
_$setProp(_el$19, "wrapMode", 'none');
|
|
715
|
-
_$insert(_el$20, figure);
|
|
716
|
-
_$setProp(_el$21, "flexShrink", 0);
|
|
717
|
-
_$setProp(_el$21, "wrapMode", 'none');
|
|
718
|
-
_$insert(_el$21, () => unavailable() ? ' ⊘' : ' ●');
|
|
719
|
-
_$effect(_p$ => {
|
|
720
|
-
var _v$8 = toneColor(theme(), tone()),
|
|
721
|
-
_v$9 = toneColor(theme(), unavailable() ? 'err' : tone());
|
|
722
|
-
_v$8 !== _p$.e && (_p$.e = _$setProp(_el$19, "fg", _v$8, _p$.e));
|
|
723
|
-
_v$9 !== _p$.t && (_p$.t = _$setProp(_el$21, "fg", _v$9, _p$.t));
|
|
724
|
-
return _p$;
|
|
725
|
-
}, {
|
|
726
|
-
e: undefined,
|
|
727
|
-
t: undefined
|
|
728
|
-
});
|
|
729
|
-
return _el$18;
|
|
730
|
-
}
|
|
681
|
+
return _$createComponent(For, {
|
|
682
|
+
get each() {
|
|
683
|
+
return visibleAccounts();
|
|
684
|
+
},
|
|
685
|
+
children: account => {
|
|
686
|
+
const unavailable = () => !account.enabled || account.cooldownUntil != null && account.cooldownUntil > now();
|
|
687
|
+
const line = createMemo(() => {
|
|
688
|
+
const currentTime = now();
|
|
689
|
+
const projection = sidebarQuotaProjection(account, currentTime);
|
|
690
|
+
const text = formatQuota(projection, {
|
|
691
|
+
now: currentTime,
|
|
692
|
+
form: 'narrow'
|
|
731
693
|
});
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
694
|
+
const remaining = projection?.limits.length ? Math.min(...projection.limits.map(limit => limit.remainingPercent ?? 100)) : undefined;
|
|
695
|
+
const tone = remaining === undefined ? 'muted' : quotaTone(100 - remaining, prefs().appearance);
|
|
696
|
+
const stale = isQuotaStale(projection, {
|
|
697
|
+
now: currentTime
|
|
698
|
+
});
|
|
699
|
+
const dot = unavailable() ? ' ⊘' : ' ●';
|
|
700
|
+
const width = contentWidth();
|
|
701
|
+
// Keep a complete shared line or omit it; a partial quota can
|
|
702
|
+
// make an account look as if it has less remaining.
|
|
703
|
+
const showQuota = text.length <= width;
|
|
704
|
+
const showDot = dot.length <= width && (!showQuota || text.length + dot.length <= width);
|
|
705
|
+
const rightWidth = (showQuota ? text.length : 0) + (showDot ? dot.length : 0);
|
|
706
|
+
const labelWidth = Math.max(0, width - rightWidth - 1);
|
|
707
|
+
return {
|
|
708
|
+
dot,
|
|
709
|
+
label: fitLabel(account.label, labelWidth),
|
|
710
|
+
showDot,
|
|
711
|
+
showQuota,
|
|
712
|
+
stale,
|
|
713
|
+
text,
|
|
714
|
+
tone
|
|
715
|
+
};
|
|
716
|
+
});
|
|
717
|
+
const quotaColor = () => line().stale ? theme().textMuted : toneColor(theme(), line().tone);
|
|
718
|
+
const dotColor = () => line().stale ? theme().textMuted : toneColor(theme(), unavailable() ? 'err' : line().tone);
|
|
719
|
+
return _$createComponent(CollapsedRow, {
|
|
720
|
+
theme: theme,
|
|
721
|
+
get label() {
|
|
722
|
+
return line().label;
|
|
723
|
+
},
|
|
724
|
+
get children() {
|
|
725
|
+
var _el$18 = _$createElement("box");
|
|
726
|
+
_$setProp(_el$18, "flexDirection", 'row');
|
|
727
|
+
_$setProp(_el$18, "flexShrink", 0);
|
|
728
|
+
_$insert(_el$18, _$createComponent(Show, {
|
|
729
|
+
get when() {
|
|
730
|
+
return line().showQuota;
|
|
731
|
+
},
|
|
732
|
+
get children() {
|
|
733
|
+
var _el$19 = _$createElement("text"),
|
|
734
|
+
_el$20 = _$createElement("b");
|
|
735
|
+
_$insertNode(_el$19, _el$20);
|
|
736
|
+
_$setProp(_el$19, "flexShrink", 0);
|
|
737
|
+
_$setProp(_el$19, "wrapMode", 'none');
|
|
738
|
+
_$insert(_el$20, () => line().text);
|
|
739
|
+
_$effect(_$p => _$setProp(_el$19, "fg", quotaColor(), _$p));
|
|
740
|
+
return _el$19;
|
|
741
|
+
}
|
|
742
|
+
}), null);
|
|
743
|
+
_$insert(_el$18, _$createComponent(Show, {
|
|
744
|
+
get when() {
|
|
745
|
+
return line().showDot;
|
|
746
|
+
},
|
|
747
|
+
get children() {
|
|
748
|
+
var _el$21 = _$createElement("text");
|
|
749
|
+
_$setProp(_el$21, "flexShrink", 0);
|
|
750
|
+
_$setProp(_el$21, "wrapMode", 'none');
|
|
751
|
+
_$insert(_el$21, () => line().dot);
|
|
752
|
+
_$effect(_$p => _$setProp(_el$21, "fg", dotColor(), _$p));
|
|
753
|
+
return _el$21;
|
|
754
|
+
}
|
|
755
|
+
}), null);
|
|
756
|
+
return _el$18;
|
|
757
|
+
}
|
|
758
|
+
});
|
|
759
|
+
}
|
|
760
|
+
});
|
|
735
761
|
}
|
|
736
762
|
}), null);
|
|
737
763
|
_$insert(_el$0, _$createComponent(Show, {
|
|
@@ -122,6 +122,9 @@ function scopedWindowParts(quota, options) {
|
|
|
122
122
|
const remainingPercent = clampPercent(limit.remainingPercent ?? 0);
|
|
123
123
|
return {
|
|
124
124
|
scope: limit.scope,
|
|
125
|
+
...(limit.windowMinutes === undefined
|
|
126
|
+
? {}
|
|
127
|
+
: { windowMinutes: limit.windowMinutes }),
|
|
125
128
|
part: {
|
|
126
129
|
kind: 'window',
|
|
127
130
|
name: quotaWindowName(limit),
|
|
@@ -212,6 +215,66 @@ function scopeAbbreviations(scopes) {
|
|
|
212
215
|
}
|
|
213
216
|
return new Map(scopes.map((scope) => [scope, short(scopeDisplayName(scope))]));
|
|
214
217
|
}
|
|
218
|
+
/** The most groups a grouped narrow line shows. */
|
|
219
|
+
const NARROW_GROUP_LIMIT = 2;
|
|
220
|
+
/**
|
|
221
|
+
* The names the groups read under in the narrow line, one per listed group:
|
|
222
|
+
* each label's short name, derived exactly as a model window's is (`Gemini`
|
|
223
|
+
* → `Ge`, `Other models` → `Ot`, colliding names extended until they
|
|
224
|
+
* differ), computed over every listed group so a group keeps its name
|
|
225
|
+
* whichever groups show. A blank label falls back to the group's scope.
|
|
226
|
+
*/
|
|
227
|
+
function groupShortNames(groups) {
|
|
228
|
+
const labels = groups.map((group) => group.label.trim() || group.scope);
|
|
229
|
+
const short = scopeAbbreviations(labels);
|
|
230
|
+
return labels.map((label) => short.get(label) ?? label);
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* The narrow line of a reading whose windows belong to named groups and that
|
|
234
|
+
* has no account-wide window: for each group, its tightest window as
|
|
235
|
+
* `Ge 7d 62%`, with ` left` once at the end. The tightest window is the
|
|
236
|
+
* one with least left, compared before rounding; on a tie the first in
|
|
237
|
+
* display order (the shorter window) wins. At most two groups show: the two
|
|
238
|
+
* with least left, earlier-listed first on a tie, and always in the order
|
|
239
|
+
* the reading lists them, so the line does not reorder as the figures move.
|
|
240
|
+
* A group with no reported window is skipped. Windows outside the listed
|
|
241
|
+
* groups and the credit budget are left out. Undefined when the rule does
|
|
242
|
+
* not apply, so the caller uses the ordinary narrow rule.
|
|
243
|
+
*/
|
|
244
|
+
function groupedNarrowPieces(groups, windows) {
|
|
245
|
+
if (!groups || groups.length === 0)
|
|
246
|
+
return undefined;
|
|
247
|
+
const reported = windows.filter(({ part }) => part.kind === 'window');
|
|
248
|
+
if (reported.some(({ scope }) => scope === ALL_SCOPE))
|
|
249
|
+
return undefined;
|
|
250
|
+
const candidates = groups.flatMap((group, listed) => {
|
|
251
|
+
const inGroup = reported.filter(({ scope }) => scope === group.scope);
|
|
252
|
+
// `windows` is already in display order, and strictly lower wins, so on
|
|
253
|
+
// a tie the shorter window keeps the place.
|
|
254
|
+
const groupTightest = inGroup.reduce((least, window) => least === undefined ||
|
|
255
|
+
(window.part.remainingPercent ?? 0) < (least.part.remainingPercent ?? 0)
|
|
256
|
+
? window
|
|
257
|
+
: least, undefined);
|
|
258
|
+
return groupTightest ? [{ group, listed, window: groupTightest }] : [];
|
|
259
|
+
});
|
|
260
|
+
if (candidates.length === 0)
|
|
261
|
+
return undefined;
|
|
262
|
+
const names = groupShortNames(groups);
|
|
263
|
+
const left = (candidate) => candidate.window.part.remainingPercent ?? 0;
|
|
264
|
+
const shown = [...candidates]
|
|
265
|
+
.sort((a, b) => left(a) - left(b) || a.listed - b.listed)
|
|
266
|
+
.slice(0, NARROW_GROUP_LIMIT)
|
|
267
|
+
.sort((a, b) => a.listed - b.listed);
|
|
268
|
+
return shown.map((candidate, index) => {
|
|
269
|
+
const { windowMinutes } = candidate.window;
|
|
270
|
+
const piece = [
|
|
271
|
+
names[candidate.listed] ?? candidate.group.scope,
|
|
272
|
+
...(windowMinutes === undefined ? [] : [lengthName(windowMinutes)]),
|
|
273
|
+
`${wholePercent(left(candidate))}%`,
|
|
274
|
+
].join(' ');
|
|
275
|
+
return index === shown.length - 1 ? `${piece} left` : piece;
|
|
276
|
+
});
|
|
277
|
+
}
|
|
215
278
|
/**
|
|
216
279
|
* The narrow form's pieces: every account-wide window as `5h 92%`, then at
|
|
217
280
|
* most one more item, with ` left` added once to the last piece. That item is
|
|
@@ -224,10 +287,15 @@ function scopeAbbreviations(scopes) {
|
|
|
224
287
|
* be chosen; when nothing at all is shown it keeps its compact wording
|
|
225
288
|
* (`credits available`). No age is added; `isQuotaStale` says whether the
|
|
226
289
|
* reading is stale. A window whose reset arrived after the reading keeps its
|
|
227
|
-
* figure, as in the other forms.
|
|
290
|
+
* figure, as in the other forms. A reading that lists named groups and has no
|
|
291
|
+
* account-wide window reads one item per group instead (see
|
|
292
|
+
* `groupedNarrowPieces`).
|
|
228
293
|
*/
|
|
229
294
|
function narrowTextParts(quota, options) {
|
|
230
295
|
const { windows } = scopedWindowParts(quota, options);
|
|
296
|
+
const grouped = groupedNarrowPieces(quota?.groups, windows);
|
|
297
|
+
if (grouped)
|
|
298
|
+
return grouped;
|
|
231
299
|
const general = windows.filter(({ part, scope }) => part.kind === 'window' && scope === ALL_SCOPE);
|
|
232
300
|
const scoped = windows.filter(({ part, scope }) => part.kind === 'window' && scope !== ALL_SCOPE);
|
|
233
301
|
const abbreviations = scopeAbbreviations(scoped.map(({ scope }) => scope));
|
|
@@ -122,6 +122,9 @@ function scopedWindowParts(quota, options) {
|
|
|
122
122
|
const remainingPercent = clampPercent(limit.remainingPercent ?? 0);
|
|
123
123
|
return {
|
|
124
124
|
scope: limit.scope,
|
|
125
|
+
...(limit.windowMinutes === undefined
|
|
126
|
+
? {}
|
|
127
|
+
: { windowMinutes: limit.windowMinutes }),
|
|
125
128
|
part: {
|
|
126
129
|
kind: 'window',
|
|
127
130
|
name: quotaWindowName(limit),
|
|
@@ -212,6 +215,66 @@ function scopeAbbreviations(scopes) {
|
|
|
212
215
|
}
|
|
213
216
|
return new Map(scopes.map((scope) => [scope, short(scopeDisplayName(scope))]));
|
|
214
217
|
}
|
|
218
|
+
/** The most groups a grouped narrow line shows. */
|
|
219
|
+
const NARROW_GROUP_LIMIT = 2;
|
|
220
|
+
/**
|
|
221
|
+
* The names the groups read under in the narrow line, one per listed group:
|
|
222
|
+
* each label's short name, derived exactly as a model window's is (`Gemini`
|
|
223
|
+
* → `Ge`, `Other models` → `Ot`, colliding names extended until they
|
|
224
|
+
* differ), computed over every listed group so a group keeps its name
|
|
225
|
+
* whichever groups show. A blank label falls back to the group's scope.
|
|
226
|
+
*/
|
|
227
|
+
function groupShortNames(groups) {
|
|
228
|
+
const labels = groups.map((group) => group.label.trim() || group.scope);
|
|
229
|
+
const short = scopeAbbreviations(labels);
|
|
230
|
+
return labels.map((label) => short.get(label) ?? label);
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* The narrow line of a reading whose windows belong to named groups and that
|
|
234
|
+
* has no account-wide window: for each group, its tightest window as
|
|
235
|
+
* `Ge 7d 62%`, with ` left` once at the end. The tightest window is the
|
|
236
|
+
* one with least left, compared before rounding; on a tie the first in
|
|
237
|
+
* display order (the shorter window) wins. At most two groups show: the two
|
|
238
|
+
* with least left, earlier-listed first on a tie, and always in the order
|
|
239
|
+
* the reading lists them, so the line does not reorder as the figures move.
|
|
240
|
+
* A group with no reported window is skipped. Windows outside the listed
|
|
241
|
+
* groups and the credit budget are left out. Undefined when the rule does
|
|
242
|
+
* not apply, so the caller uses the ordinary narrow rule.
|
|
243
|
+
*/
|
|
244
|
+
function groupedNarrowPieces(groups, windows) {
|
|
245
|
+
if (!groups || groups.length === 0)
|
|
246
|
+
return undefined;
|
|
247
|
+
const reported = windows.filter(({ part }) => part.kind === 'window');
|
|
248
|
+
if (reported.some(({ scope }) => scope === ALL_SCOPE))
|
|
249
|
+
return undefined;
|
|
250
|
+
const candidates = groups.flatMap((group, listed) => {
|
|
251
|
+
const inGroup = reported.filter(({ scope }) => scope === group.scope);
|
|
252
|
+
// `windows` is already in display order, and strictly lower wins, so on
|
|
253
|
+
// a tie the shorter window keeps the place.
|
|
254
|
+
const groupTightest = inGroup.reduce((least, window) => least === undefined ||
|
|
255
|
+
(window.part.remainingPercent ?? 0) < (least.part.remainingPercent ?? 0)
|
|
256
|
+
? window
|
|
257
|
+
: least, undefined);
|
|
258
|
+
return groupTightest ? [{ group, listed, window: groupTightest }] : [];
|
|
259
|
+
});
|
|
260
|
+
if (candidates.length === 0)
|
|
261
|
+
return undefined;
|
|
262
|
+
const names = groupShortNames(groups);
|
|
263
|
+
const left = (candidate) => candidate.window.part.remainingPercent ?? 0;
|
|
264
|
+
const shown = [...candidates]
|
|
265
|
+
.sort((a, b) => left(a) - left(b) || a.listed - b.listed)
|
|
266
|
+
.slice(0, NARROW_GROUP_LIMIT)
|
|
267
|
+
.sort((a, b) => a.listed - b.listed);
|
|
268
|
+
return shown.map((candidate, index) => {
|
|
269
|
+
const { windowMinutes } = candidate.window;
|
|
270
|
+
const piece = [
|
|
271
|
+
names[candidate.listed] ?? candidate.group.scope,
|
|
272
|
+
...(windowMinutes === undefined ? [] : [lengthName(windowMinutes)]),
|
|
273
|
+
`${wholePercent(left(candidate))}%`,
|
|
274
|
+
].join(' ');
|
|
275
|
+
return index === shown.length - 1 ? `${piece} left` : piece;
|
|
276
|
+
});
|
|
277
|
+
}
|
|
215
278
|
/**
|
|
216
279
|
* The narrow form's pieces: every account-wide window as `5h 92%`, then at
|
|
217
280
|
* most one more item, with ` left` added once to the last piece. That item is
|
|
@@ -224,10 +287,15 @@ function scopeAbbreviations(scopes) {
|
|
|
224
287
|
* be chosen; when nothing at all is shown it keeps its compact wording
|
|
225
288
|
* (`credits available`). No age is added; `isQuotaStale` says whether the
|
|
226
289
|
* reading is stale. A window whose reset arrived after the reading keeps its
|
|
227
|
-
* figure, as in the other forms.
|
|
290
|
+
* figure, as in the other forms. A reading that lists named groups and has no
|
|
291
|
+
* account-wide window reads one item per group instead (see
|
|
292
|
+
* `groupedNarrowPieces`).
|
|
228
293
|
*/
|
|
229
294
|
function narrowTextParts(quota, options) {
|
|
230
295
|
const { windows } = scopedWindowParts(quota, options);
|
|
296
|
+
const grouped = groupedNarrowPieces(quota?.groups, windows);
|
|
297
|
+
if (grouped)
|
|
298
|
+
return grouped;
|
|
231
299
|
const general = windows.filter(({ part, scope }) => part.kind === 'window' && scope === ALL_SCOPE);
|
|
232
300
|
const scoped = windows.filter(({ part, scope }) => part.kind === 'window' && scope !== ALL_SCOPE);
|
|
233
301
|
const abbreviations = scopeAbbreviations(scoped.map(({ scope }) => scope));
|
|
@@ -184,19 +184,25 @@ export async function replaceWindowsFile(from, to, options = {}) {
|
|
|
184
184
|
to = resolve(to);
|
|
185
185
|
const now = options.now ?? (() => performance.now());
|
|
186
186
|
const start = now();
|
|
187
|
-
const
|
|
187
|
+
const leaseDeadline = options.deadline ?? Infinity;
|
|
188
|
+
let retryDeadline;
|
|
188
189
|
const delays = [0, 10, 20, 40, 80, 100];
|
|
189
190
|
let original;
|
|
190
191
|
let attempts = 0;
|
|
191
192
|
for (const delay of delays) {
|
|
193
|
+
const deadline = Math.min(retryDeadline ?? Infinity, leaseDeadline);
|
|
192
194
|
if (now() >= deadline)
|
|
193
195
|
break;
|
|
194
196
|
if (delay)
|
|
195
197
|
await (options.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms))))(Math.min(delay, Math.max(0, deadline - now())));
|
|
196
198
|
if (now() >= deadline)
|
|
197
199
|
break;
|
|
200
|
+
const fenceStart = now();
|
|
198
201
|
await options.beforeRename?.();
|
|
199
|
-
|
|
202
|
+
// Ownership checks fence every attempt but do not spend the sharing-retry budget.
|
|
203
|
+
if (retryDeadline !== undefined)
|
|
204
|
+
retryDeadline += now() - fenceStart;
|
|
205
|
+
if (now() >= leaseDeadline)
|
|
200
206
|
break;
|
|
201
207
|
attempts++;
|
|
202
208
|
try {
|
|
@@ -212,6 +218,8 @@ export async function replaceWindowsFile(from, to, options = {}) {
|
|
|
212
218
|
!detail.reason;
|
|
213
219
|
if (!candidate)
|
|
214
220
|
break;
|
|
221
|
+
// Start the retry window only once a rename has actually failed.
|
|
222
|
+
retryDeadline ??= now() + 500;
|
|
215
223
|
}
|
|
216
224
|
}
|
|
217
225
|
const error = new PrivateFileError(to, 'rename', original ??
|