@cortexkit/opencode-openai-auth 1.9.0 → 1.9.2
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/bin.js +2 -2
- package/dist/{index-v0y4hv4r.js → index-5sgqz46z.js} +1 -1
- package/dist/{index-2sb7q9wr.js → index-6j3059fy.js} +1 -1
- package/dist/{index-ececstzk.js → index-6r27fz5a.js} +6 -6
- package/dist/{index-vkg5pw57.js → index-85w1x19b.js} +1 -1
- package/dist/{index-0vvxnhd3.js → index-cb1kwn36.js} +18 -18
- package/dist/{index-e32hgdk4.js → index-hpev556z.js} +1 -1
- package/dist/{index-7bgst9rd.js → index-k1dfzavn.js} +1 -1
- package/dist/index-mtf8pv2w.js +8 -0
- package/dist/{index-yw0wnqjq.js → index-qdy57ej9.js} +1 -1
- package/dist/index.js +1 -1
- package/dist/rpc/port-file.js +1 -1
- package/dist/rpc/protocol.js +1 -1
- package/dist/rpc/rpc-client.js +1 -1
- package/dist/sidebar-state.js +1 -1
- package/dist/tui-preferences.js +1 -1
- package/dist/v2/server.js +1 -1
- package/package.json +2 -2
- package/src/tui-compiled/raw/shared/0332701351b3eeec-format.js +45 -26
- package/src/tui-compiled/raw/shared/4825e03209d6ae3e-with-lock.js +37 -10
- package/src/tui-compiled/raw/shared/549daf371622c304-index.tsx +56 -32
- package/src/tui-compiled/raw/shared/7c97ac0cec074ae7-format.js +30 -17
- package/src/tui-compiled/raw/shared/e8cd4929507508d8-refresh-file-lock.js +2 -2
- package/src/tui-compiled/runtime/shared/0332701351b3eeec-format.js +45 -26
- package/src/tui-compiled/runtime/shared/4825e03209d6ae3e-with-lock.js +37 -10
- package/src/tui-compiled/runtime/shared/549daf371622c304-index.js +165 -148
- package/src/tui-compiled/runtime/shared/7c97ac0cec074ae7-format.js +30 -17
- package/src/tui-compiled/runtime/shared/e8cd4929507508d8-refresh-file-lock.js +2 -2
- package/dist/index-wkn4d21h.js +0 -8
- /package/dist/{index-jenb51ww.js → index-hpb6k6st.js} +0 -0
|
@@ -5,10 +5,10 @@
|
|
|
5
5
|
//
|
|
6
6
|
// The rules: a window is named by its length (`5h`, `7d`), or, for a window
|
|
7
7
|
// that binds only one model family, by the label the plugin stored it under.
|
|
8
|
-
// Every figure is "% left". A window the provider did not
|
|
9
|
-
// record or a retirement tombstone) is left out rather than
|
|
10
|
-
// reported". A reset is a short time from now (`resets 2h`).
|
|
11
|
-
// than fifteen minutes says how old it is (`checked 3h ago`).
|
|
8
|
+
// Every reported window figure is "% left". A window the provider did not
|
|
9
|
+
// report (an absence record or a retirement tombstone) is left out rather than
|
|
10
|
+
// written as "not reported". A reset is a short time from now (`resets 2h`).
|
|
11
|
+
// A reading older than fifteen minutes says how old it is (`checked 3h ago`).
|
|
12
12
|
//
|
|
13
13
|
// Like the rest of this module it reads no clock: `now` is a parameter.
|
|
14
14
|
import { ALL_SCOPE } from "./905bffc0220f43d0-map.js";
|
|
@@ -97,12 +97,14 @@ function displayOrder(left, right) {
|
|
|
97
97
|
return left.label < right.label ? -1 : left.label > right.label ? 1 : 0;
|
|
98
98
|
}
|
|
99
99
|
/**
|
|
100
|
-
* Structured quota wording for layouts that need one row per window.
|
|
101
|
-
*
|
|
102
|
-
*
|
|
100
|
+
* Structured quota wording for layouts that need one row per window.
|
|
101
|
+
* Windows without a dated percentage remain as explicit unknown parts. Limits
|
|
102
|
+
* marked absent (not reported) or retired (no longer tracked) remain omitted.
|
|
103
|
+
* Reported windows, future resets and the optional age keep the shared
|
|
104
|
+
* formatter's wording and order.
|
|
103
105
|
*/
|
|
104
106
|
export function quotaWindowParts(quota, options) {
|
|
105
|
-
const { windows, age } = scopedWindowParts(quota, options);
|
|
107
|
+
const { windows, age } = scopedWindowParts(quota, options, true);
|
|
106
108
|
const parts = windows.map(({ part }) => part);
|
|
107
109
|
return age === undefined ? { windows: parts } : { windows: parts, age };
|
|
108
110
|
}
|
|
@@ -125,34 +127,47 @@ function withShortNames(windows) {
|
|
|
125
127
|
}
|
|
126
128
|
return windows;
|
|
127
129
|
}
|
|
130
|
+
function hasWindowReading(limit) {
|
|
131
|
+
return (Number.isFinite(limit.remainingPercent) && Number.isFinite(limit.checkedAt));
|
|
132
|
+
}
|
|
128
133
|
/**
|
|
129
134
|
* `quotaWindowParts` with each window's scope kept beside it. The narrow form
|
|
130
135
|
* needs the scope to name and pick model-scoped windows; the public parts do
|
|
131
|
-
* not carry
|
|
136
|
+
* not carry the scope.
|
|
132
137
|
*/
|
|
133
|
-
function scopedWindowParts(quota, options) {
|
|
138
|
+
function scopedWindowParts(quota, options, includeUnknown = false) {
|
|
134
139
|
if (!quota)
|
|
135
140
|
return { windows: [] };
|
|
136
141
|
const { now } = options;
|
|
137
142
|
const readings = quota.limits
|
|
138
|
-
.filter((limit) => limit.kind === 'reading' &&
|
|
143
|
+
.filter((limit) => limit.kind === 'reading' && (includeUnknown || hasWindowReading(limit)))
|
|
139
144
|
.sort(displayOrder);
|
|
140
145
|
const windows = readings.map((limit) => {
|
|
141
|
-
const
|
|
142
|
-
|
|
143
|
-
scope: limit.scope,
|
|
144
|
-
...(limit.windowMinutes === undefined
|
|
145
|
-
? {}
|
|
146
|
-
: { windowMinutes: limit.windowMinutes }),
|
|
147
|
-
part: {
|
|
146
|
+
const part = hasWindowReading(limit)
|
|
147
|
+
? {
|
|
148
148
|
kind: 'window',
|
|
149
|
+
reading: 'known',
|
|
149
150
|
name: quotaWindowName(limit),
|
|
150
151
|
short: '',
|
|
151
|
-
figure: percentLeft(limit.remainingPercent
|
|
152
|
-
remainingPercent,
|
|
152
|
+
figure: percentLeft(limit.remainingPercent),
|
|
153
|
+
remainingPercent: clampPercent(limit.remainingPercent),
|
|
153
154
|
checkedAt: limit.checkedAt,
|
|
154
155
|
...resetDetails(limit.resetsAt, limit.checkedAt, now),
|
|
155
|
-
}
|
|
156
|
+
}
|
|
157
|
+
: {
|
|
158
|
+
kind: 'window',
|
|
159
|
+
reading: 'unknown',
|
|
160
|
+
name: quotaWindowName(limit),
|
|
161
|
+
short: '',
|
|
162
|
+
figure: 'no reading',
|
|
163
|
+
resetSinceReading: false,
|
|
164
|
+
};
|
|
165
|
+
return {
|
|
166
|
+
scope: limit.scope,
|
|
167
|
+
...(limit.windowMinutes === undefined
|
|
168
|
+
? {}
|
|
169
|
+
: { windowMinutes: limit.windowMinutes }),
|
|
170
|
+
part,
|
|
156
171
|
};
|
|
157
172
|
});
|
|
158
173
|
const budget = quota.budget;
|
|
@@ -168,6 +183,7 @@ function scopedWindowParts(quota, options) {
|
|
|
168
183
|
spent: budget.reached,
|
|
169
184
|
part: {
|
|
170
185
|
kind: 'budget',
|
|
186
|
+
reading: 'known',
|
|
171
187
|
name: 'credits',
|
|
172
188
|
short: '',
|
|
173
189
|
figure,
|
|
@@ -180,8 +196,11 @@ function scopedWindowParts(quota, options) {
|
|
|
180
196
|
});
|
|
181
197
|
}
|
|
182
198
|
withShortNames(windows);
|
|
183
|
-
|
|
184
|
-
|
|
199
|
+
const readingTimes = windows.flatMap(({ part }) => part.reading === 'known' && part.checkedAt !== undefined
|
|
200
|
+
? [part.checkedAt]
|
|
201
|
+
: []);
|
|
202
|
+
if (readingTimes.length > 0) {
|
|
203
|
+
const age = now - Math.min(...readingTimes);
|
|
185
204
|
if (age > (options.staleAfterMs ?? QUOTA_STALE_AFTER_MS)) {
|
|
186
205
|
return { windows, age: `checked ${shortSpan(age)} ago` };
|
|
187
206
|
}
|
|
@@ -357,13 +376,13 @@ function narrowTextParts(quota, options) {
|
|
|
357
376
|
export function quotaTextParts(quota, options) {
|
|
358
377
|
if (options.form === 'narrow')
|
|
359
378
|
return narrowTextParts(quota, options);
|
|
360
|
-
const
|
|
379
|
+
const { windows, age } = scopedWindowParts(quota, options);
|
|
361
380
|
const full = (options.form ?? 'full') === 'full';
|
|
362
|
-
const text =
|
|
381
|
+
const text = windows.map(({ part }) => {
|
|
363
382
|
const reset = full && part.resetIn ? `, resets ${part.resetIn}` : '';
|
|
364
383
|
return `${part.kind === 'budget' ? '' : `${part.name} `}${part.figure}${reset}`;
|
|
365
384
|
});
|
|
366
|
-
return
|
|
385
|
+
return age === undefined ? text : [...text, age];
|
|
367
386
|
}
|
|
368
387
|
/**
|
|
369
388
|
* A row's quota as one line: `5h 58% left · 7d 90% left` in the compact
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { join, resolve } from "node:path";
|
|
2
|
+
import { PrivateFileError, windowsPrivateFiles } from "./375d9cca2def037d-private-files.js";
|
|
1
3
|
import { acquireRefreshFileLock } from "./e8cd4929507508d8-refresh-file-lock.js";
|
|
2
4
|
export function lockPathFor(target, name) {
|
|
3
5
|
return `${target}.${name}.lock`;
|
|
@@ -18,20 +20,42 @@ export class LockOwnershipError extends Error {
|
|
|
18
20
|
this.details = details;
|
|
19
21
|
}
|
|
20
22
|
}
|
|
23
|
+
function isChangingLockRead(error, target, name) {
|
|
24
|
+
if (!windowsPrivateFiles ||
|
|
25
|
+
!(error instanceof PrivateFileError) ||
|
|
26
|
+
error.reason !== 'io-error' ||
|
|
27
|
+
(error.win32Code !== 32 && error.win32Code !== 303) ||
|
|
28
|
+
(error.stage !== 'read' && error.stage !== 'verify'))
|
|
29
|
+
return false;
|
|
30
|
+
const path = resolve(lockPathFor(target, name));
|
|
31
|
+
return error.path === path || error.path === join(path, 'owner.json');
|
|
32
|
+
}
|
|
21
33
|
export async function withLock(target, options, fn) {
|
|
22
34
|
const started = performance.now();
|
|
23
35
|
for (;;) {
|
|
24
36
|
options.signal?.throwIfAborted();
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
: {}),
|
|
34
|
-
|
|
37
|
+
let lock;
|
|
38
|
+
let changingReadError;
|
|
39
|
+
try {
|
|
40
|
+
lock = await acquireRefreshFileLock({
|
|
41
|
+
path: target,
|
|
42
|
+
name: options.name,
|
|
43
|
+
ttlMs: options.ttlMs,
|
|
44
|
+
renew: options.renew ?? false,
|
|
45
|
+
...(options.onStep ? { onStep: options.onStep } : {}),
|
|
46
|
+
...(options.onRenewalTimer
|
|
47
|
+
? { onRenewalTimer: options.onRenewalTimer }
|
|
48
|
+
: {}),
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
if (!isChangingLockRead(error, target, options.name))
|
|
53
|
+
throw error;
|
|
54
|
+
// Sharing violations (32) and delete-pending opens (303) do not reveal
|
|
55
|
+
// ownership or expiry. Retry exclusive creation, never infer a stale lock.
|
|
56
|
+
lock = null;
|
|
57
|
+
changingReadError = error;
|
|
58
|
+
}
|
|
35
59
|
if (lock) {
|
|
36
60
|
try {
|
|
37
61
|
options.signal?.throwIfAborted();
|
|
@@ -43,6 +67,9 @@ export async function withLock(target, options, fn) {
|
|
|
43
67
|
}
|
|
44
68
|
const remaining = options.timeoutMs - (performance.now() - started);
|
|
45
69
|
if (remaining <= 0) {
|
|
70
|
+
// Keep persistent native IO failures distinguishable from a live holder.
|
|
71
|
+
if (changingReadError)
|
|
72
|
+
throw changingReadError;
|
|
46
73
|
throw new LockContentionError({
|
|
47
74
|
target,
|
|
48
75
|
name: options.name,
|
|
@@ -238,17 +238,20 @@ function QuotaRow(props: {
|
|
|
238
238
|
' '.repeat(Math.max(0, props.labelWidth - displayWidth(props.part.name)))
|
|
239
239
|
const figure = () =>
|
|
240
240
|
` ${props.part.kind === 'budget' && props.part.figure.startsWith(`${props.part.name} `) ? props.part.figure.slice(props.part.name.length + 1) : props.part.figure}`
|
|
241
|
+
const hasReading = () => props.part.reading === 'known'
|
|
241
242
|
const used = () => 100 - (props.part.remainingPercent ?? 100)
|
|
242
243
|
// Size notifications can recompute an unchanged fit after text has been flushed
|
|
243
244
|
// for the frame. Keep equal segments, and update fixed slots in place when the
|
|
244
245
|
// bar changes, rather than replacing text nodes during layout.
|
|
245
246
|
const segments = createMemo(
|
|
246
247
|
() =>
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
248
|
+
hasReading()
|
|
249
|
+
? barSegments(
|
|
250
|
+
used(),
|
|
251
|
+
{ ...context.appearance, barWidth: props.barCells },
|
|
252
|
+
props.pace,
|
|
253
|
+
)
|
|
254
|
+
: [],
|
|
252
255
|
undefined,
|
|
253
256
|
{
|
|
254
257
|
equals: (previous, next) =>
|
|
@@ -286,36 +289,49 @@ function QuotaRow(props: {
|
|
|
286
289
|
</text>
|
|
287
290
|
</Show>
|
|
288
291
|
<Show
|
|
289
|
-
when={
|
|
292
|
+
when={hasReading()}
|
|
290
293
|
fallback={
|
|
291
294
|
<text fg={context.theme.textMuted} wrapMode='none'>
|
|
292
|
-
|
|
295
|
+
no reading
|
|
293
296
|
</text>
|
|
294
297
|
}
|
|
295
298
|
>
|
|
296
|
-
<Show
|
|
297
|
-
{
|
|
298
|
-
|
|
299
|
-
{
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
width={segment().text ? undefined : 0}
|
|
304
|
-
>
|
|
305
|
-
{segment().text}
|
|
306
|
-
</text>
|
|
307
|
-
)}
|
|
308
|
-
</Index>
|
|
309
|
-
</Show>
|
|
310
|
-
<text
|
|
311
|
-
fg={context.theme[usageTone(used(), context.appearance)]}
|
|
312
|
-
wrapMode='none'
|
|
299
|
+
<Show
|
|
300
|
+
when={!props.part.resetSinceReading}
|
|
301
|
+
fallback={
|
|
302
|
+
<text fg={context.theme.textMuted} wrapMode='none'>
|
|
303
|
+
reset since last check
|
|
304
|
+
</text>
|
|
305
|
+
}
|
|
313
306
|
>
|
|
314
|
-
{
|
|
315
|
-
|
|
307
|
+
<Show when={props.barCells > 0}>
|
|
308
|
+
{/* Text nodes clear omitted theme colours; empty slots must not reserve a cell. */}
|
|
309
|
+
<Index each={segments()}>
|
|
310
|
+
{(segment) => (
|
|
311
|
+
<text
|
|
312
|
+
fg={context.theme[segment().tone]}
|
|
313
|
+
wrapMode='none'
|
|
314
|
+
width={segment().text ? undefined : 0}
|
|
315
|
+
>
|
|
316
|
+
{segment().text}
|
|
317
|
+
</text>
|
|
318
|
+
)}
|
|
319
|
+
</Index>
|
|
320
|
+
</Show>
|
|
321
|
+
<text
|
|
322
|
+
fg={context.theme[usageTone(used(), context.appearance)]}
|
|
323
|
+
wrapMode='none'
|
|
324
|
+
>
|
|
325
|
+
{figure()}
|
|
326
|
+
</text>
|
|
327
|
+
</Show>
|
|
316
328
|
</Show>
|
|
317
329
|
</box>
|
|
318
|
-
<Show
|
|
330
|
+
<Show
|
|
331
|
+
when={
|
|
332
|
+
hasReading() && props.showReset && !props.part.resetSinceReading
|
|
333
|
+
}
|
|
334
|
+
>
|
|
319
335
|
<box
|
|
320
336
|
width={props.resetWidth}
|
|
321
337
|
flexShrink={0}
|
|
@@ -331,7 +347,10 @@ function QuotaRow(props: {
|
|
|
331
347
|
</Show>
|
|
332
348
|
</box>
|
|
333
349
|
{/* A changed fitted line needs a fresh text node to draw at its new width. */}
|
|
334
|
-
<Show
|
|
350
|
+
<Show
|
|
351
|
+
when={hasReading() && !props.part.resetSinceReading && paceLine()}
|
|
352
|
+
keyed
|
|
353
|
+
>
|
|
335
354
|
{(line: string) => (
|
|
336
355
|
<box width='100%' flexDirection='row'>
|
|
337
356
|
<Show when={props.labelWidth > 0}>
|
|
@@ -357,8 +376,9 @@ function CollapsedAccountRow(props: { account: AccountView }) {
|
|
|
357
376
|
const [width, setWidth] = createSignal(0)
|
|
358
377
|
let row: { width: number } | undefined
|
|
359
378
|
const hasQuota = () =>
|
|
360
|
-
quotaWindowParts(props.account.quota, { now: context.now }).windows.
|
|
361
|
-
|
|
379
|
+
quotaWindowParts(props.account.quota, { now: context.now }).windows.some(
|
|
380
|
+
(part) => part.reading === 'known',
|
|
381
|
+
)
|
|
362
382
|
const text = () =>
|
|
363
383
|
hasQuota()
|
|
364
384
|
? formatQuota(props.account.quota, { now: context.now, form: 'narrow' })
|
|
@@ -431,14 +451,18 @@ function AccountBlock(props: { account: AccountView; marginTop: number }) {
|
|
|
431
451
|
Math.max(
|
|
432
452
|
0,
|
|
433
453
|
...rows().map(({ part }) =>
|
|
434
|
-
part.
|
|
454
|
+
part.reading === 'unknown' || part.resetSinceReading
|
|
455
|
+
? 0
|
|
456
|
+
: displayWidth(part.resetIn ?? ''),
|
|
435
457
|
),
|
|
436
458
|
)
|
|
437
459
|
const figureWidth = createMemo(() =>
|
|
438
460
|
Math.max(
|
|
439
461
|
10,
|
|
440
462
|
...rows()
|
|
441
|
-
.filter(
|
|
463
|
+
.filter(
|
|
464
|
+
({ part }) => part.reading === 'known' && !part.resetSinceReading,
|
|
465
|
+
)
|
|
442
466
|
.map(({ part }) =>
|
|
443
467
|
displayWidth(
|
|
444
468
|
` ${part.kind === 'budget' && part.figure.startsWith(`${part.name} `) ? part.figure.slice(part.name.length + 1) : part.figure}`,
|
|
@@ -55,7 +55,7 @@ function displayOrder(left, right) {
|
|
|
55
55
|
return left.label < right.label ? -1 : left.label > right.label ? 1 : 0;
|
|
56
56
|
}
|
|
57
57
|
export function quotaWindowParts(quota, options) {
|
|
58
|
-
const { windows, age } = scopedWindowParts(quota, options), parts = windows.map(({ part }) => part);
|
|
58
|
+
const { windows, age } = scopedWindowParts(quota, options, !0), parts = windows.map(({ part }) => part);
|
|
59
59
|
return age === void 0 ? { windows: parts } : { windows: parts, age };
|
|
60
60
|
}
|
|
61
61
|
function withShortNames(windows) {
|
|
@@ -64,23 +64,34 @@ function withShortNames(windows) {
|
|
|
64
64
|
window.part.short = window.part.kind === "budget" ? "cr" : window.scope === ALL_SCOPE ? window.part.name : abbreviations.get(window.scope) ?? window.scope;
|
|
65
65
|
return windows;
|
|
66
66
|
}
|
|
67
|
-
function
|
|
67
|
+
function hasWindowReading(limit) {
|
|
68
|
+
return Number.isFinite(limit.remainingPercent) && Number.isFinite(limit.checkedAt);
|
|
69
|
+
}
|
|
70
|
+
function scopedWindowParts(quota, options, includeUnknown = !1) {
|
|
68
71
|
if (!quota)
|
|
69
72
|
return { windows: [] };
|
|
70
|
-
const { now } = options, windows = quota.limits.filter((limit) => limit.kind === "reading" &&
|
|
71
|
-
const
|
|
73
|
+
const { now } = options, windows = quota.limits.filter((limit) => limit.kind === "reading" && (includeUnknown || hasWindowReading(limit))).sort(displayOrder).map((limit) => {
|
|
74
|
+
const part = hasWindowReading(limit) ? {
|
|
75
|
+
kind: "window",
|
|
76
|
+
reading: "known",
|
|
77
|
+
name: quotaWindowName(limit),
|
|
78
|
+
short: "",
|
|
79
|
+
figure: percentLeft(limit.remainingPercent),
|
|
80
|
+
remainingPercent: clampPercent(limit.remainingPercent),
|
|
81
|
+
checkedAt: limit.checkedAt,
|
|
82
|
+
...resetDetails(limit.resetsAt, limit.checkedAt, now)
|
|
83
|
+
} : {
|
|
84
|
+
kind: "window",
|
|
85
|
+
reading: "unknown",
|
|
86
|
+
name: quotaWindowName(limit),
|
|
87
|
+
short: "",
|
|
88
|
+
figure: "no reading",
|
|
89
|
+
resetSinceReading: !1
|
|
90
|
+
};
|
|
72
91
|
return {
|
|
73
92
|
scope: limit.scope,
|
|
74
93
|
...limit.windowMinutes === void 0 ? {} : { windowMinutes: limit.windowMinutes },
|
|
75
|
-
part
|
|
76
|
-
kind: "window",
|
|
77
|
-
name: quotaWindowName(limit),
|
|
78
|
-
short: "",
|
|
79
|
-
figure: percentLeft(limit.remainingPercent ?? 0),
|
|
80
|
-
remainingPercent,
|
|
81
|
-
checkedAt: limit.checkedAt,
|
|
82
|
-
...resetDetails(limit.resetsAt, limit.checkedAt, now)
|
|
83
|
-
}
|
|
94
|
+
part
|
|
84
95
|
};
|
|
85
96
|
}), budget = quota.budget;
|
|
86
97
|
if (budget) {
|
|
@@ -90,6 +101,7 @@ function scopedWindowParts(quota, options) {
|
|
|
90
101
|
spent: budget.reached,
|
|
91
102
|
part: {
|
|
92
103
|
kind: "budget",
|
|
104
|
+
reading: "known",
|
|
93
105
|
name: "credits",
|
|
94
106
|
short: "",
|
|
95
107
|
figure,
|
|
@@ -100,8 +112,9 @@ function scopedWindowParts(quota, options) {
|
|
|
100
112
|
});
|
|
101
113
|
}
|
|
102
114
|
withShortNames(windows);
|
|
103
|
-
|
|
104
|
-
|
|
115
|
+
const readingTimes = windows.flatMap(({ part }) => part.reading === "known" && part.checkedAt !== void 0 ? [part.checkedAt] : []);
|
|
116
|
+
if (readingTimes.length > 0) {
|
|
117
|
+
const age = now - Math.min(...readingTimes);
|
|
105
118
|
if (age > (options.staleAfterMs ?? QUOTA_STALE_AFTER_MS))
|
|
106
119
|
return { windows, age: `checked ${shortSpan(age)} ago` };
|
|
107
120
|
}
|
|
@@ -184,11 +197,11 @@ function narrowTextParts(quota, options) {
|
|
|
184
197
|
export function quotaTextParts(quota, options) {
|
|
185
198
|
if (options.form === "narrow")
|
|
186
199
|
return narrowTextParts(quota, options);
|
|
187
|
-
const
|
|
200
|
+
const { windows, age } = scopedWindowParts(quota, options), full = (options.form ?? "full") === "full", text = windows.map(({ part }) => {
|
|
188
201
|
const reset = full && part.resetIn ? `, resets ${part.resetIn}` : "";
|
|
189
202
|
return `${part.kind === "budget" ? "" : `${part.name} `}${part.figure}${reset}`;
|
|
190
203
|
});
|
|
191
|
-
return
|
|
204
|
+
return age === void 0 ? text : [...text, age];
|
|
192
205
|
}
|
|
193
206
|
export function formatQuota(quota, options) {
|
|
194
207
|
const parts = quotaTextParts(quota, options);
|
|
@@ -244,8 +244,8 @@ export async function acquireRefreshFileLockWithClock(options) {
|
|
|
244
244
|
}
|
|
245
245
|
catch (readError) {
|
|
246
246
|
// The holder can release after exclusive creation reports a collision.
|
|
247
|
-
// Only absence permits
|
|
248
|
-
//
|
|
247
|
+
// Only absence permits acquisition to continue here. Sharing failures
|
|
248
|
+
// escape to withLock's deadline-bounded retry, never to stale eviction.
|
|
249
249
|
if (readError.code !== 'ENOENT')
|
|
250
250
|
throw readError;
|
|
251
251
|
}
|
|
@@ -5,10 +5,10 @@
|
|
|
5
5
|
//
|
|
6
6
|
// The rules: a window is named by its length (`5h`, `7d`), or, for a window
|
|
7
7
|
// that binds only one model family, by the label the plugin stored it under.
|
|
8
|
-
// Every figure is "% left". A window the provider did not
|
|
9
|
-
// record or a retirement tombstone) is left out rather than
|
|
10
|
-
// reported". A reset is a short time from now (`resets 2h`).
|
|
11
|
-
// than fifteen minutes says how old it is (`checked 3h ago`).
|
|
8
|
+
// Every reported window figure is "% left". A window the provider did not
|
|
9
|
+
// report (an absence record or a retirement tombstone) is left out rather than
|
|
10
|
+
// written as "not reported". A reset is a short time from now (`resets 2h`).
|
|
11
|
+
// A reading older than fifteen minutes says how old it is (`checked 3h ago`).
|
|
12
12
|
//
|
|
13
13
|
// Like the rest of this module it reads no clock: `now` is a parameter.
|
|
14
14
|
import { ALL_SCOPE } from "./905bffc0220f43d0-map.js";
|
|
@@ -97,12 +97,14 @@ function displayOrder(left, right) {
|
|
|
97
97
|
return left.label < right.label ? -1 : left.label > right.label ? 1 : 0;
|
|
98
98
|
}
|
|
99
99
|
/**
|
|
100
|
-
* Structured quota wording for layouts that need one row per window.
|
|
101
|
-
*
|
|
102
|
-
*
|
|
100
|
+
* Structured quota wording for layouts that need one row per window.
|
|
101
|
+
* Windows without a dated percentage remain as explicit unknown parts. Limits
|
|
102
|
+
* marked absent (not reported) or retired (no longer tracked) remain omitted.
|
|
103
|
+
* Reported windows, future resets and the optional age keep the shared
|
|
104
|
+
* formatter's wording and order.
|
|
103
105
|
*/
|
|
104
106
|
export function quotaWindowParts(quota, options) {
|
|
105
|
-
const { windows, age } = scopedWindowParts(quota, options);
|
|
107
|
+
const { windows, age } = scopedWindowParts(quota, options, true);
|
|
106
108
|
const parts = windows.map(({ part }) => part);
|
|
107
109
|
return age === undefined ? { windows: parts } : { windows: parts, age };
|
|
108
110
|
}
|
|
@@ -125,34 +127,47 @@ function withShortNames(windows) {
|
|
|
125
127
|
}
|
|
126
128
|
return windows;
|
|
127
129
|
}
|
|
130
|
+
function hasWindowReading(limit) {
|
|
131
|
+
return (Number.isFinite(limit.remainingPercent) && Number.isFinite(limit.checkedAt));
|
|
132
|
+
}
|
|
128
133
|
/**
|
|
129
134
|
* `quotaWindowParts` with each window's scope kept beside it. The narrow form
|
|
130
135
|
* needs the scope to name and pick model-scoped windows; the public parts do
|
|
131
|
-
* not carry
|
|
136
|
+
* not carry the scope.
|
|
132
137
|
*/
|
|
133
|
-
function scopedWindowParts(quota, options) {
|
|
138
|
+
function scopedWindowParts(quota, options, includeUnknown = false) {
|
|
134
139
|
if (!quota)
|
|
135
140
|
return { windows: [] };
|
|
136
141
|
const { now } = options;
|
|
137
142
|
const readings = quota.limits
|
|
138
|
-
.filter((limit) => limit.kind === 'reading' &&
|
|
143
|
+
.filter((limit) => limit.kind === 'reading' && (includeUnknown || hasWindowReading(limit)))
|
|
139
144
|
.sort(displayOrder);
|
|
140
145
|
const windows = readings.map((limit) => {
|
|
141
|
-
const
|
|
142
|
-
|
|
143
|
-
scope: limit.scope,
|
|
144
|
-
...(limit.windowMinutes === undefined
|
|
145
|
-
? {}
|
|
146
|
-
: { windowMinutes: limit.windowMinutes }),
|
|
147
|
-
part: {
|
|
146
|
+
const part = hasWindowReading(limit)
|
|
147
|
+
? {
|
|
148
148
|
kind: 'window',
|
|
149
|
+
reading: 'known',
|
|
149
150
|
name: quotaWindowName(limit),
|
|
150
151
|
short: '',
|
|
151
|
-
figure: percentLeft(limit.remainingPercent
|
|
152
|
-
remainingPercent,
|
|
152
|
+
figure: percentLeft(limit.remainingPercent),
|
|
153
|
+
remainingPercent: clampPercent(limit.remainingPercent),
|
|
153
154
|
checkedAt: limit.checkedAt,
|
|
154
155
|
...resetDetails(limit.resetsAt, limit.checkedAt, now),
|
|
155
|
-
}
|
|
156
|
+
}
|
|
157
|
+
: {
|
|
158
|
+
kind: 'window',
|
|
159
|
+
reading: 'unknown',
|
|
160
|
+
name: quotaWindowName(limit),
|
|
161
|
+
short: '',
|
|
162
|
+
figure: 'no reading',
|
|
163
|
+
resetSinceReading: false,
|
|
164
|
+
};
|
|
165
|
+
return {
|
|
166
|
+
scope: limit.scope,
|
|
167
|
+
...(limit.windowMinutes === undefined
|
|
168
|
+
? {}
|
|
169
|
+
: { windowMinutes: limit.windowMinutes }),
|
|
170
|
+
part,
|
|
156
171
|
};
|
|
157
172
|
});
|
|
158
173
|
const budget = quota.budget;
|
|
@@ -168,6 +183,7 @@ function scopedWindowParts(quota, options) {
|
|
|
168
183
|
spent: budget.reached,
|
|
169
184
|
part: {
|
|
170
185
|
kind: 'budget',
|
|
186
|
+
reading: 'known',
|
|
171
187
|
name: 'credits',
|
|
172
188
|
short: '',
|
|
173
189
|
figure,
|
|
@@ -180,8 +196,11 @@ function scopedWindowParts(quota, options) {
|
|
|
180
196
|
});
|
|
181
197
|
}
|
|
182
198
|
withShortNames(windows);
|
|
183
|
-
|
|
184
|
-
|
|
199
|
+
const readingTimes = windows.flatMap(({ part }) => part.reading === 'known' && part.checkedAt !== undefined
|
|
200
|
+
? [part.checkedAt]
|
|
201
|
+
: []);
|
|
202
|
+
if (readingTimes.length > 0) {
|
|
203
|
+
const age = now - Math.min(...readingTimes);
|
|
185
204
|
if (age > (options.staleAfterMs ?? QUOTA_STALE_AFTER_MS)) {
|
|
186
205
|
return { windows, age: `checked ${shortSpan(age)} ago` };
|
|
187
206
|
}
|
|
@@ -357,13 +376,13 @@ function narrowTextParts(quota, options) {
|
|
|
357
376
|
export function quotaTextParts(quota, options) {
|
|
358
377
|
if (options.form === 'narrow')
|
|
359
378
|
return narrowTextParts(quota, options);
|
|
360
|
-
const
|
|
379
|
+
const { windows, age } = scopedWindowParts(quota, options);
|
|
361
380
|
const full = (options.form ?? 'full') === 'full';
|
|
362
|
-
const text =
|
|
381
|
+
const text = windows.map(({ part }) => {
|
|
363
382
|
const reset = full && part.resetIn ? `, resets ${part.resetIn}` : '';
|
|
364
383
|
return `${part.kind === 'budget' ? '' : `${part.name} `}${part.figure}${reset}`;
|
|
365
384
|
});
|
|
366
|
-
return
|
|
385
|
+
return age === undefined ? text : [...text, age];
|
|
367
386
|
}
|
|
368
387
|
/**
|
|
369
388
|
* A row's quota as one line: `5h 58% left · 7d 90% left` in the compact
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { join, resolve } from "node:path";
|
|
2
|
+
import { PrivateFileError, windowsPrivateFiles } from "./375d9cca2def037d-private-files.js";
|
|
1
3
|
import { acquireRefreshFileLock } from "./e8cd4929507508d8-refresh-file-lock.js";
|
|
2
4
|
export function lockPathFor(target, name) {
|
|
3
5
|
return `${target}.${name}.lock`;
|
|
@@ -18,20 +20,42 @@ export class LockOwnershipError extends Error {
|
|
|
18
20
|
this.details = details;
|
|
19
21
|
}
|
|
20
22
|
}
|
|
23
|
+
function isChangingLockRead(error, target, name) {
|
|
24
|
+
if (!windowsPrivateFiles ||
|
|
25
|
+
!(error instanceof PrivateFileError) ||
|
|
26
|
+
error.reason !== 'io-error' ||
|
|
27
|
+
(error.win32Code !== 32 && error.win32Code !== 303) ||
|
|
28
|
+
(error.stage !== 'read' && error.stage !== 'verify'))
|
|
29
|
+
return false;
|
|
30
|
+
const path = resolve(lockPathFor(target, name));
|
|
31
|
+
return error.path === path || error.path === join(path, 'owner.json');
|
|
32
|
+
}
|
|
21
33
|
export async function withLock(target, options, fn) {
|
|
22
34
|
const started = performance.now();
|
|
23
35
|
for (;;) {
|
|
24
36
|
options.signal?.throwIfAborted();
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
: {}),
|
|
34
|
-
|
|
37
|
+
let lock;
|
|
38
|
+
let changingReadError;
|
|
39
|
+
try {
|
|
40
|
+
lock = await acquireRefreshFileLock({
|
|
41
|
+
path: target,
|
|
42
|
+
name: options.name,
|
|
43
|
+
ttlMs: options.ttlMs,
|
|
44
|
+
renew: options.renew ?? false,
|
|
45
|
+
...(options.onStep ? { onStep: options.onStep } : {}),
|
|
46
|
+
...(options.onRenewalTimer
|
|
47
|
+
? { onRenewalTimer: options.onRenewalTimer }
|
|
48
|
+
: {}),
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
if (!isChangingLockRead(error, target, options.name))
|
|
53
|
+
throw error;
|
|
54
|
+
// Sharing violations (32) and delete-pending opens (303) do not reveal
|
|
55
|
+
// ownership or expiry. Retry exclusive creation, never infer a stale lock.
|
|
56
|
+
lock = null;
|
|
57
|
+
changingReadError = error;
|
|
58
|
+
}
|
|
35
59
|
if (lock) {
|
|
36
60
|
try {
|
|
37
61
|
options.signal?.throwIfAborted();
|
|
@@ -43,6 +67,9 @@ export async function withLock(target, options, fn) {
|
|
|
43
67
|
}
|
|
44
68
|
const remaining = options.timeoutMs - (performance.now() - started);
|
|
45
69
|
if (remaining <= 0) {
|
|
70
|
+
// Keep persistent native IO failures distinguishable from a live holder.
|
|
71
|
+
if (changingReadError)
|
|
72
|
+
throw changingReadError;
|
|
46
73
|
throw new LockContentionError({
|
|
47
74
|
target,
|
|
48
75
|
name: options.name,
|