sideby 0.43.0 → 0.44.0
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/build.json +1 -1
- package/dist/src/cli/json-schemas.js +7 -0
- package/dist/src/core/file-memo.d.ts +2 -0
- package/dist/src/core/file-memo.js +20 -0
- package/dist/src/core/handoff.d.ts +9 -0
- package/dist/src/core/handoff.js +10 -0
- package/dist/src/core/memo-store.js +32 -8
- package/dist/src/families/quota-watch.d.ts +12 -0
- package/dist/src/families/quota-watch.js +24 -0
- package/dist/src/panel/changes.d.ts +57 -0
- package/dist/src/panel/changes.js +178 -0
- package/dist/src/panel/handler.d.ts +38 -0
- package/dist/src/panel/handler.js +206 -68
- package/dist/src/panel/i18n.d.ts +23 -0
- package/dist/src/panel/i18n.js +46 -0
- package/dist/src/panel/page-logic.d.ts +11 -0
- package/dist/src/panel/page-logic.js +11 -0
- package/dist/src/panel/page-script.js +109 -11
- package/dist/src/panel/page-styles.js +17 -8
- package/dist/src/panel/page.js +3 -1
- package/dist/src/runtime.d.ts +11 -0
- package/dist/src/runtime.js +5 -2
- package/package.json +1 -1
- package/schemas/next.json +25 -0
- package/skills/sideby/SKILL.md +2 -2
- package/skills/sideby/references/handoff.md +2 -0
|
@@ -13,7 +13,7 @@ import { aiTaskPermissions, aliasArgs, aliasRefs, EDITORS, editConfigPanel, edit
|
|
|
13
13
|
import { openDesktopApp, withDesktopApps } from '../core/desktop-app.js';
|
|
14
14
|
import { editSettings, isEditor } from '../core/edit-settings.js';
|
|
15
15
|
import { UserError } from '../core/errors.js';
|
|
16
|
-
import { planHandoff } from '../core/handoff.js';
|
|
16
|
+
import { blocked, planHandoff } from '../core/handoff.js';
|
|
17
17
|
import { applyHandoffEnable, planHandoffEnable } from '../core/handoff-enable.js';
|
|
18
18
|
import { handoffOverview } from '../core/handoff-overview.js';
|
|
19
19
|
import { apiUndecided, handoffRulesView } from '../core/handoff-rules.js';
|
|
@@ -45,11 +45,13 @@ import { listPendingDecisions, markPendingDone, reopenPendingDecisions } from '.
|
|
|
45
45
|
import { readUnattendedConfig } from '../core/unattended-state.js';
|
|
46
46
|
import * as update from '../core/update.js';
|
|
47
47
|
import { buildId, localBuild, packageVersion } from '../core/version.js';
|
|
48
|
+
import { quotaWatchDirs } from '../families/quota-watch.js';
|
|
48
49
|
import { HOOK_FAMILIES } from '../handoff/hook.js';
|
|
49
50
|
import { MENUBAR_AGENT } from '../menubar/agent.js';
|
|
50
51
|
import { hotkeyView, iconView, openMenuBarSettings, readMenubarState, setMenubarHotkey, } from '../menubar/hotkey.js';
|
|
51
52
|
import { MENUBAR_SCRIPT } from '../menubar/script.js';
|
|
52
53
|
import { renderNetworkPage } from '../network/page.js';
|
|
54
|
+
import { createChangeFeed, stateQuotaDir } from './changes.js';
|
|
53
55
|
import { orcaTabs, switchOrcaTab, systemOrca } from './orca.js';
|
|
54
56
|
import { renderPage } from './page.js';
|
|
55
57
|
import { AI_TASK_KINDS } from './page-logic.js';
|
|
@@ -273,14 +275,32 @@ export function handoffByFamily(rt, accounts, now, load) {
|
|
|
273
275
|
}
|
|
274
276
|
/** The plan behind each pick of `handoffByFamily`, spread by Room per Session when `load` is given (ADR-0083). */
|
|
275
277
|
export function handoffPlans(rt, accounts, now, load) {
|
|
278
|
+
return nextPicks(familyPlans(rt, accounts, now, load));
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* The plans that make a Next pick: a pick from Quota data, among two logins or more. Logins, not directories: a Same
|
|
282
|
+
* Login group (spec §3.21) is one Quota, so it alone is no alternative.
|
|
283
|
+
*/
|
|
284
|
+
function nextPicks(all) {
|
|
285
|
+
const out = {};
|
|
286
|
+
for (const [id, { plan, logins }] of Object.entries(all))
|
|
287
|
+
if (logins >= 2 && plan.pick && plan.hasQuota)
|
|
288
|
+
out[id] = plan;
|
|
289
|
+
return out;
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* `sideby next`'s plan for every Family with a Quota source and a signed-in or unknown Subscription Account read
|
|
293
|
+
* already, with how many logins it has: the Next pick takes those with two or more, the "Best to use now" card
|
|
294
|
+
* (spec §3.45) every one.
|
|
295
|
+
*/
|
|
296
|
+
export function familyPlans(rt, accounts, now, load) {
|
|
276
297
|
const out = {};
|
|
277
298
|
for (const [id, f] of rt.families) {
|
|
278
299
|
// An Account still being read has no Quota yet; it is neither a pick nor an alternative until it has.
|
|
279
300
|
const list = accounts.filter((a) => a.family === id && !a.pending);
|
|
280
|
-
// Count logins, not directories: a Same Login group (spec §3.21) is one Quota, so it alone is no alternative.
|
|
281
301
|
const subs = list.filter((a) => a.kind === 'subscription');
|
|
282
302
|
const logins = subs.filter((a, i) => !subs.slice(0, i).some((b) => a.sameLogin?.includes(b.ref))).length;
|
|
283
|
-
if ((!f.readQuota && !f.fetchQuota) || logins <
|
|
303
|
+
if ((!f.readQuota && !f.fetchQuota) || logins < 1)
|
|
284
304
|
continue;
|
|
285
305
|
const plan = planHandoff(id, list.map((a) => ({
|
|
286
306
|
ref: a.ref,
|
|
@@ -300,11 +320,35 @@ export function handoffPlans(rt, accounts, now, load) {
|
|
|
300
320
|
// Counted over every Account, also one still being read, so a Same Login partner's sessions count.
|
|
301
321
|
...(load ? { picks: load.picks, live: load.live } : {}),
|
|
302
322
|
});
|
|
303
|
-
|
|
304
|
-
out[id] = plan;
|
|
323
|
+
out[id] = { plan, logins };
|
|
305
324
|
}
|
|
306
325
|
return out;
|
|
307
326
|
}
|
|
327
|
+
/** The "Best to use now" card's entry of a Family's plan (spec §3.45). */
|
|
328
|
+
export function pickNowOf(plan) {
|
|
329
|
+
const chosen = plan.accounts.find((e) => e.ref === plan.pick);
|
|
330
|
+
if (plan.pick && plan.hasQuota) {
|
|
331
|
+
const reason = plan.reason ?? (plan.tight ? 'tight' : chosen?.state === 'unknown' ? 'unknown' : undefined);
|
|
332
|
+
return {
|
|
333
|
+
pick: plan.pick,
|
|
334
|
+
hasQuota: true,
|
|
335
|
+
...(reason ? { reason } : {}),
|
|
336
|
+
...(chosen?.liveSessions ? { running: chosen.liveSessions } : {}),
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
// No Subscription Account that can start (signed out, or its sign-in expired): signing in comes first.
|
|
340
|
+
const subs = plan.accounts.filter((e) => e.kind === 'subscription');
|
|
341
|
+
if (!subs.some((e) => e.state !== 'logged-out' && !blocked(e)))
|
|
342
|
+
return { pick: null, hasQuota: plan.hasQuota, why: 'signed-out' };
|
|
343
|
+
if (!plan.hasQuota)
|
|
344
|
+
return { pick: null, hasQuota: false, why: 'no-quota' };
|
|
345
|
+
return {
|
|
346
|
+
pick: null,
|
|
347
|
+
hasQuota: true,
|
|
348
|
+
why: 'used-up',
|
|
349
|
+
...(plan.earliestReset ? { earliestReset: plan.earliestReset } : {}),
|
|
350
|
+
};
|
|
351
|
+
}
|
|
308
352
|
class HttpError extends Error {
|
|
309
353
|
status;
|
|
310
354
|
/** Machine-readable reason the page acts on, such as `bad-token`. */
|
|
@@ -471,52 +515,62 @@ function optBool(body, key) {
|
|
|
471
515
|
throw new HttpError(400, `"${key}" must be true or false`);
|
|
472
516
|
return v;
|
|
473
517
|
}
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
const
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
const
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
518
|
+
function settle(p) {
|
|
519
|
+
return p.then((value) => ({ value }), (err) => ({ error: err.message }));
|
|
520
|
+
}
|
|
521
|
+
/**
|
|
522
|
+
* Starts the reads of one Account. `full` is its whole state. Usage parses session logs and can take far longer than
|
|
523
|
+
* the rest on a cold start, so `quick()` gives the state without it (`usagePending`) once the rest is in, or null
|
|
524
|
+
* while it is not.
|
|
525
|
+
*/
|
|
526
|
+
function accountState(rt, account, families) {
|
|
527
|
+
const status = settle(rt.status(account));
|
|
528
|
+
// The kept answer of a Quota check shows now; a stale one is asked again behind it (spec §3.26).
|
|
529
|
+
const quota = settle(rt.quota(account, { fetch: 'background' }));
|
|
530
|
+
const usage = settle(rt.usage(account));
|
|
531
|
+
let restIn = false;
|
|
532
|
+
void Promise.all([status, quota]).then(() => {
|
|
533
|
+
restIn = true;
|
|
534
|
+
});
|
|
535
|
+
const build = async (u) => {
|
|
536
|
+
const [s, q] = await Promise.all([status, quota]);
|
|
537
|
+
const errors = [s.error, q.error, u?.error].filter((e) => e !== undefined);
|
|
538
|
+
const fam = families.find((f) => f.id === account.family);
|
|
539
|
+
const base = s.value ?? {
|
|
540
|
+
...account,
|
|
541
|
+
familyTitle: fam?.title ?? account.family,
|
|
542
|
+
hostInstalled: fam?.installed ?? false,
|
|
543
|
+
login: 'unknown',
|
|
544
|
+
};
|
|
545
|
+
errors.push(...(s.value?.problems ?? []));
|
|
546
|
+
let modelInfo;
|
|
547
|
+
if (rt.families.get(account.family)?.modelChoice) {
|
|
548
|
+
const used = u?.value;
|
|
549
|
+
// Given even when empty: without it `accountModel` would wait for the usage itself.
|
|
550
|
+
const last = used?.status === 'ok'
|
|
551
|
+
? {
|
|
552
|
+
...(used.lastModel ? { model: used.lastModel } : {}),
|
|
553
|
+
...(used.lastEffort ? { effort: used.lastEffort } : {}),
|
|
554
|
+
}
|
|
555
|
+
: {};
|
|
556
|
+
try {
|
|
557
|
+
const { ref: _r, family: _f, ...rest } = await accountModel(rt, account, last);
|
|
558
|
+
modelInfo = rest;
|
|
559
|
+
}
|
|
560
|
+
catch (err) {
|
|
561
|
+
errors.push(err.message);
|
|
505
562
|
}
|
|
506
|
-
: {};
|
|
507
|
-
const info = await guard(accountModel(rt, account, last));
|
|
508
|
-
if (info) {
|
|
509
|
-
const { ref: _r, family: _f, ...rest } = info;
|
|
510
|
-
modelInfo = rest;
|
|
511
563
|
}
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
564
|
+
return {
|
|
565
|
+
...base,
|
|
566
|
+
...(modelInfo ? { modelInfo } : {}),
|
|
567
|
+
...(q.value ? { quota: q.value } : {}),
|
|
568
|
+
...(u?.value ? { usage: u.value } : {}),
|
|
569
|
+
...(u ? {} : { usagePending: true }),
|
|
570
|
+
...(errors.length ? { error: errors.join('; ') } : {}),
|
|
571
|
+
};
|
|
519
572
|
};
|
|
573
|
+
return { full: usage.then(build), quick: () => (restIn ? build(undefined) : null) };
|
|
520
574
|
}
|
|
521
575
|
/** The model an advisor request asks for, and the Account it is limited to (a ref), checked. */
|
|
522
576
|
async function advisorBody(rt, body) {
|
|
@@ -544,10 +598,32 @@ function advisorView(st, home) {
|
|
|
544
598
|
* answer. Mutable for tests only.
|
|
545
599
|
*/
|
|
546
600
|
export const readBudget = { ms: 2000, hungMs: 60_000 };
|
|
601
|
+
/** How long a state waits, once `readBudget` is over, for an Account's state without its usage. */
|
|
602
|
+
const QUICK_MS = 500;
|
|
547
603
|
/** An answer kept longer than this is not used: the next state reads the Account again. */
|
|
548
604
|
const KEPT_MS = 30_000;
|
|
549
|
-
/**
|
|
550
|
-
|
|
605
|
+
/** Forgets every read and every last state: after a change, nothing read before it is shown. */
|
|
606
|
+
function clearReadings(r) {
|
|
607
|
+
r.going.clear();
|
|
608
|
+
r.last.clear();
|
|
609
|
+
}
|
|
610
|
+
/** A read that began longer ago than this goes on after a file change: a cold first read can take a minute. */
|
|
611
|
+
const REREAD_MS = 5000;
|
|
612
|
+
/**
|
|
613
|
+
* After a file Quota lands in changed (spec §3.45): the next state reads again instead of using a read from before
|
|
614
|
+
* the change. The last states stay, for slow rows meanwhile.
|
|
615
|
+
*/
|
|
616
|
+
function dropEarlyReadings(r, now) {
|
|
617
|
+
for (const [ref, reading] of r.going)
|
|
618
|
+
if (reading.done || now - reading.started < REREAD_MS)
|
|
619
|
+
r.going.delete(ref);
|
|
620
|
+
}
|
|
621
|
+
/**
|
|
622
|
+
* The Account's state within `readBudget`. While its reads go on: its last complete state (`refreshing`), or else
|
|
623
|
+
* the state without its usage once the rest is in (`usagePending`), or else a pending placeholder.
|
|
624
|
+
*/
|
|
625
|
+
async function timedAccountState(rt, account, families, readings) {
|
|
626
|
+
const mine = readings.going;
|
|
551
627
|
const fam = families.find((f) => f.id === account.family);
|
|
552
628
|
const placeholder = async (extra) => {
|
|
553
629
|
// Its Same Login is known without the slow reads, so its rows stay grouped meanwhile.
|
|
@@ -561,21 +637,53 @@ async function timedAccountState(rt, account, families, mine) {
|
|
|
561
637
|
...extra,
|
|
562
638
|
};
|
|
563
639
|
};
|
|
640
|
+
const last = () => {
|
|
641
|
+
const st = readings.last.get(account.ref);
|
|
642
|
+
return st ? { ...st, refreshing: true } : null;
|
|
643
|
+
};
|
|
644
|
+
// The state without usage still asks the model reader, which a plugin may make slow: it gets a short wait only.
|
|
645
|
+
const partial = async (r) => {
|
|
646
|
+
const quick = r.quick();
|
|
647
|
+
if (!quick)
|
|
648
|
+
return null;
|
|
649
|
+
let timer;
|
|
650
|
+
const late = new Promise((done) => {
|
|
651
|
+
timer = setTimeout(() => done(null), QUICK_MS);
|
|
652
|
+
});
|
|
653
|
+
try {
|
|
654
|
+
return await Promise.race([quick.catch(() => null), late]);
|
|
655
|
+
}
|
|
656
|
+
finally {
|
|
657
|
+
clearTimeout(timer);
|
|
658
|
+
}
|
|
659
|
+
};
|
|
564
660
|
let r = mine.get(account.ref);
|
|
565
661
|
if (r?.done && Date.now() - r.done.at > KEPT_MS)
|
|
566
662
|
r = undefined;
|
|
567
|
-
// A read still going after `readBudget.hungMs` has hung (a plugin reader, a Host that never answers).
|
|
663
|
+
// A read still going after `readBudget.hungMs` has hung (a plugin reader, a Host that never answers). A first read
|
|
664
|
+
// on a cold start can parse usage for longer than that: while the rest is in, it goes on.
|
|
568
665
|
if (r && !r.done && Date.now() - r.started > readBudget.hungMs) {
|
|
569
|
-
|
|
666
|
+
const early = last() ? null : await partial(r);
|
|
667
|
+
if (early)
|
|
668
|
+
return early;
|
|
669
|
+
// Dropped, so the next state starts a new read; this one shows the last state, or says what happened instead
|
|
670
|
+
// of spinning on.
|
|
570
671
|
mine.delete(account.ref);
|
|
672
|
+
const shown = last();
|
|
673
|
+
if (shown)
|
|
674
|
+
return shown;
|
|
571
675
|
return placeholder({
|
|
572
676
|
error: `reading this account took longer than ${Math.round(readBudget.hungMs / 1000)} s; refresh to try again`,
|
|
573
677
|
});
|
|
574
678
|
}
|
|
575
679
|
if (!r) {
|
|
576
|
-
const
|
|
680
|
+
const read = accountState(rt, account, families);
|
|
681
|
+
const fresh = { promise: read.full, quick: read.quick, started: Date.now() };
|
|
577
682
|
fresh.promise.then((state) => {
|
|
578
683
|
fresh.done = { state, at: Date.now() };
|
|
684
|
+
// Not a read a change has since dropped: its state is from before the change.
|
|
685
|
+
if (mine.get(account.ref) === fresh)
|
|
686
|
+
readings.last.set(account.ref, state);
|
|
579
687
|
}, () => undefined);
|
|
580
688
|
mine.set(account.ref, fresh);
|
|
581
689
|
r = fresh;
|
|
@@ -603,7 +711,7 @@ async function timedAccountState(rt, account, families, mine) {
|
|
|
603
711
|
mine.delete(account.ref);
|
|
604
712
|
return state;
|
|
605
713
|
}
|
|
606
|
-
return placeholder({ pending: true });
|
|
714
|
+
return last() ?? (await partial(reading)) ?? placeholder({ pending: true });
|
|
607
715
|
}
|
|
608
716
|
async function buildState(rt, opts) {
|
|
609
717
|
// Read alongside the Accounts, so waiting for it adds little.
|
|
@@ -623,9 +731,10 @@ async function buildState(rt, opts) {
|
|
|
623
731
|
? await rt.networkStatus().catch(() => undefined)
|
|
624
732
|
: undefined;
|
|
625
733
|
// Reads of Accounts that are gone are dropped.
|
|
626
|
-
for (const
|
|
627
|
-
|
|
628
|
-
|
|
734
|
+
for (const map of [opts.readings.going, opts.readings.last])
|
|
735
|
+
for (const ref of map.keys())
|
|
736
|
+
if (!accounts.some((a) => a.ref === ref))
|
|
737
|
+
map.delete(ref);
|
|
629
738
|
const aliases = aliasesByAccount(aliasRefs(rt.config.aliases), accounts);
|
|
630
739
|
// Asks in flight before the reads start: one that ends while they run may have left a row with the older numbers.
|
|
631
740
|
const askingOf = () => accounts.filter((a) => quotaAsking(rt.paths.stateDir, a.family, a.name)).map((a) => a.ref);
|
|
@@ -660,9 +769,14 @@ async function buildState(rt, opts) {
|
|
|
660
769
|
const ref = key.slice(0, key.indexOf('\0'));
|
|
661
770
|
live.set(ref, (live.get(ref) ?? 0) + 1);
|
|
662
771
|
}
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
772
|
+
// Unknown running sessions leave the Next pick out; the card ranks as if none ran, so it never reads "nothing".
|
|
773
|
+
const load = keys ? { live, picks: await readPickRecords(rt.paths.stateDir, ctx.now) } : undefined;
|
|
774
|
+
const every = familyPlans(rt, list, ctx.now, load);
|
|
775
|
+
const plans = keys ? nextPicks(every) : {};
|
|
776
|
+
// A tool whose quota has only per-model windows (Antigravity CLI) never ranks by quota, so it gets no card.
|
|
777
|
+
const pickNow = Object.fromEntries(Object.entries(every)
|
|
778
|
+
.filter(([f, { plan }]) => plan.hasQuota || !list.some((a) => a.family === f && a.quota?.status === 'ok'))
|
|
779
|
+
.map(([f, { plan }]) => [f, pickNowOf(plan)]));
|
|
666
780
|
const handoff = Object.fromEntries(Object.entries(plans).map(([f, p]) => [f, p.pick]));
|
|
667
781
|
const handoffRunning = Object.fromEntries(Object.entries(plans).flatMap(([f, p]) => {
|
|
668
782
|
const n = p.accounts.find((e) => e.ref === p.pick)?.liveSessions ?? 0;
|
|
@@ -722,6 +836,7 @@ async function buildState(rt, opts) {
|
|
|
722
836
|
...(Object.keys(handoff).length ? { handoff } : {}),
|
|
723
837
|
...(Object.keys(handoffRunning).length ? { handoffRunning } : {}),
|
|
724
838
|
...(Object.keys(handoffReason).length ? { handoffReason } : {}),
|
|
839
|
+
...(Object.keys(pickNow).length ? { pickNow } : {}),
|
|
725
840
|
...(remoteControl.length ? { remoteControl: rcView(remoteControl, ctx.home) } : {}),
|
|
726
841
|
...(advisor.groups.length ? { advisor: advisorView(advisor, ctx.home) } : {}),
|
|
727
842
|
...(appProfiles.length
|
|
@@ -1110,8 +1225,16 @@ export function createPanelHandler(opts) {
|
|
|
1110
1225
|
const openBridge = resolveBridge('open', opts.open);
|
|
1111
1226
|
const token = randomBytes(32).toString('base64url');
|
|
1112
1227
|
const serial = writeQueue();
|
|
1113
|
-
const readings = new Map();
|
|
1228
|
+
const readings = { going: new Map(), last: new Map() };
|
|
1114
1229
|
const getRuntime = typeof opts.runtime === 'function' ? opts.runtime : async () => opts.runtime;
|
|
1230
|
+
// Quota files watched while a page asks (spec §3.45, ADR-0084).
|
|
1231
|
+
const changes = createChangeFeed({
|
|
1232
|
+
dirs: async () => {
|
|
1233
|
+
const rt = await getRuntime();
|
|
1234
|
+
return [stateQuotaDir(rt.paths.stateDir), ...quotaWatchDirs(await rt.accounts())];
|
|
1235
|
+
},
|
|
1236
|
+
onChange: () => dropEarlyReadings(readings, Date.now()),
|
|
1237
|
+
});
|
|
1115
1238
|
const sessionsSource = opts[LIVE_SESSIONS_SOURCE];
|
|
1116
1239
|
const liveSessions = sessionsSource?.list ?? listLiveSessions;
|
|
1117
1240
|
// A change from this page can end a stretch of Unattended Mode: the plugins hear of it now, as after the CLI. The
|
|
@@ -1455,20 +1578,25 @@ export function createPanelHandler(opts) {
|
|
|
1455
1578
|
},
|
|
1456
1579
|
// Pick Commands (spec §3.13, ADR-0035): start the Account with the most room in the Preferred Terminal, add one
|
|
1457
1580
|
// (a name that hides a command on PATH comes back as `confirm` until the page sends confirm: true), remove one.
|
|
1581
|
+
// `family` instead of `name`: the "Best to use now" card (spec §3.45), the Family's Pick Command when it has one,
|
|
1582
|
+
// else the same rules without one.
|
|
1458
1583
|
'/api/pick/start': {
|
|
1459
1584
|
async run(body) {
|
|
1460
|
-
const
|
|
1461
|
-
if (!name)
|
|
1462
|
-
throw new HttpError(400, '"name" is required');
|
|
1585
|
+
const fam = optString(body, 'family');
|
|
1463
1586
|
const rt = await getRuntime();
|
|
1587
|
+
const name = optString(body, 'name') ??
|
|
1588
|
+
(fam ? Object.entries(rt.config.pickCommands ?? {}).find(([, f]) => f === fam)?.[0] : undefined);
|
|
1589
|
+
if (!name && !fam)
|
|
1590
|
+
throw new HttpError(400, '"name" or "family" is required');
|
|
1464
1591
|
// This start counts for the next pick, so its record is written now (ADR-0083).
|
|
1465
1592
|
let rec;
|
|
1466
|
-
const
|
|
1593
|
+
const po = {
|
|
1467
1594
|
record: true,
|
|
1468
1595
|
recorded: (r) => {
|
|
1469
1596
|
rec = r;
|
|
1470
1597
|
},
|
|
1471
|
-
}
|
|
1598
|
+
};
|
|
1599
|
+
const { family, choice } = name ? await rt.pickChoice(name, po) : await rt.familyPick(fam, po);
|
|
1472
1600
|
if (choice.ref === null)
|
|
1473
1601
|
throw new UserError(choice.earliestReset
|
|
1474
1602
|
? `Every signed-in ${family} account has used up its quota; ${choice.earliestReset.ref} is back first.`
|
|
@@ -1484,7 +1612,7 @@ export function createPanelHandler(opts) {
|
|
|
1484
1612
|
await rt.cancelPick(rec);
|
|
1485
1613
|
return {
|
|
1486
1614
|
...r,
|
|
1487
|
-
name,
|
|
1615
|
+
...(name ? { name } : {}),
|
|
1488
1616
|
family,
|
|
1489
1617
|
picked: choice.ref,
|
|
1490
1618
|
reason: choice.reason,
|
|
@@ -2781,6 +2909,16 @@ export function createPanelHandler(opts) {
|
|
|
2781
2909
|
send(res, 200, await loginItemView(rt, sub === '/api/menubar' ? MENUBAR_AGENT : PANEL_AGENT));
|
|
2782
2910
|
return true;
|
|
2783
2911
|
}
|
|
2912
|
+
// Held until a Quota file changes or 25 s pass (spec §3.45, ADR-0084).
|
|
2913
|
+
if (sub === '/api/changes') {
|
|
2914
|
+
const raw = new URL(req.url ?? '/', 'http://x').searchParams.get('since');
|
|
2915
|
+
const since = method === 'GET' && raw !== null && /^\d{1,15}$/.test(raw) ? Number(raw) : null;
|
|
2916
|
+
const gone = new Promise((done) => res.once('close', done));
|
|
2917
|
+
const answer = await changes.wait(since, gone);
|
|
2918
|
+
if (!res.destroyed)
|
|
2919
|
+
send(res, 200, answer);
|
|
2920
|
+
return true;
|
|
2921
|
+
}
|
|
2784
2922
|
if (sub === '/api/state') {
|
|
2785
2923
|
send(res, 200, await buildState(await getRuntime(), {
|
|
2786
2924
|
version,
|
|
@@ -2831,7 +2969,7 @@ export function createPanelHandler(opts) {
|
|
|
2831
2969
|
const result = await (route.queued === false ? route.run(body) : serial(() => route.run(body)));
|
|
2832
2970
|
// A change may concern an Account whose read began before it: the next state reads again.
|
|
2833
2971
|
if (route.writes?.(body) ?? true)
|
|
2834
|
-
readings
|
|
2972
|
+
clearReadings(readings);
|
|
2835
2973
|
send(res, 200, result);
|
|
2836
2974
|
return true;
|
|
2837
2975
|
}
|
package/dist/src/panel/i18n.d.ts
CHANGED
|
@@ -6,6 +6,8 @@ declare const en: {
|
|
|
6
6
|
'top.loading': string;
|
|
7
7
|
'top.refreshing': string;
|
|
8
8
|
'top.updated': string;
|
|
9
|
+
'top.updatedLive': string;
|
|
10
|
+
'top.updatedTitleLive': string;
|
|
9
11
|
'top.updatedTitle': string;
|
|
10
12
|
'top.stale': string;
|
|
11
13
|
'foot.text': string;
|
|
@@ -153,6 +155,27 @@ declare const en: {
|
|
|
153
155
|
'stat.sessions.other': string;
|
|
154
156
|
'stat.nextReset': string;
|
|
155
157
|
'stat.noQuota': string;
|
|
158
|
+
'stat.pickNow': string;
|
|
159
|
+
'stat.pickNowIn': string;
|
|
160
|
+
'stat.pickLeft': string;
|
|
161
|
+
'stat.pickReset': string;
|
|
162
|
+
'stat.pickTight': string;
|
|
163
|
+
'stat.pickNoData': string;
|
|
164
|
+
'stat.pickStart': string;
|
|
165
|
+
'stat.pickStartTip': string;
|
|
166
|
+
'stat.pickCopy': string;
|
|
167
|
+
'stat.pickCopyTip': string;
|
|
168
|
+
'stat.pickOnly': string;
|
|
169
|
+
'stat.pickOthers': string;
|
|
170
|
+
'stat.pickUsedUp': string;
|
|
171
|
+
'stat.pickBack': string;
|
|
172
|
+
'stat.pickWait': string;
|
|
173
|
+
'stat.pickNoQuota': string;
|
|
174
|
+
'stat.pickNoQuotaTip': string;
|
|
175
|
+
'stat.pickSignIn': string;
|
|
176
|
+
'stat.pickNoSource': string;
|
|
177
|
+
'stat.pickNoSourceOne': string;
|
|
178
|
+
'stat.pickReading': string;
|
|
156
179
|
'need.error.one': string;
|
|
157
180
|
'need.error.other': string;
|
|
158
181
|
'need.health-fail.one': string;
|
package/dist/src/panel/i18n.js
CHANGED
|
@@ -8,6 +8,8 @@ const en = {
|
|
|
8
8
|
'top.loading': 'Loading…',
|
|
9
9
|
'top.refreshing': 'Refreshing…',
|
|
10
10
|
'top.updated': 'Read {ago} · refreshes every {s} s',
|
|
11
|
+
'top.updatedLive': 'Read {ago} · updates as quota changes',
|
|
12
|
+
'top.updatedTitleLive': 'Quota, usage and health of each account, last read at {at}. The page reads them again as soon as a quota file changes, and every {s} s.',
|
|
11
13
|
'top.updatedTitle': 'Quota, usage and health of every account, last read at {at}. They are read again every {s} s while this page is open.',
|
|
12
14
|
'top.stale': 'Not refreshed: the panel cannot be reached or the last read failed.',
|
|
13
15
|
'foot.text': 'runs on this machine; nothing leaves it.',
|
|
@@ -155,6 +157,27 @@ const en = {
|
|
|
155
157
|
'stat.sessions.other': '{n} sessions',
|
|
156
158
|
'stat.nextReset': 'Next quota reset',
|
|
157
159
|
'stat.noQuota': 'No quota data',
|
|
160
|
+
'stat.pickNow': 'Best to use now',
|
|
161
|
+
'stat.pickNowIn': 'Best to use now · {title}',
|
|
162
|
+
'stat.pickLeft': '{w} {n}% left',
|
|
163
|
+
'stat.pickReset': '{w} reset',
|
|
164
|
+
'stat.pickTight': 'all past their limit',
|
|
165
|
+
'stat.pickNoData': 'no quota data for it yet',
|
|
166
|
+
'stat.pickStart': 'Start',
|
|
167
|
+
'stat.pickStartTip': 'Click to start it in a terminal.',
|
|
168
|
+
'stat.pickCopy': 'Copy',
|
|
169
|
+
'stat.pickCopyTip': 'Click to copy the command that starts it: sideby next {family}',
|
|
170
|
+
'stat.pickOnly': 'Your only {title} account, and it has quota left.',
|
|
171
|
+
'stat.pickOthers': 'Other tools:{list}',
|
|
172
|
+
'stat.pickUsedUp': 'All used up',
|
|
173
|
+
'stat.pickBack': '{ref} is back {when}',
|
|
174
|
+
'stat.pickWait': 'wait for the next reset',
|
|
175
|
+
'stat.pickNoQuota': 'No quota data yet',
|
|
176
|
+
'stat.pickNoQuotaTip': 'A pick shows here once one of these accounts has quota data: start a session in one, or press Refresh.',
|
|
177
|
+
'stat.pickSignIn': 'Sign in to an account first',
|
|
178
|
+
'stat.pickNoSource': 'No subscription account here shows its quota',
|
|
179
|
+
'stat.pickNoSourceOne': 'No subscription account of this tool shows its quota',
|
|
180
|
+
'stat.pickReading': 'Reading quota…',
|
|
158
181
|
'need.error.one': '{n} unreadable',
|
|
159
182
|
'need.error.other': '{n} unreadable',
|
|
160
183
|
'need.health-fail.one': '{n} with issues',
|
|
@@ -1881,6 +1904,8 @@ const zh = {
|
|
|
1881
1904
|
'top.loading': '加载中…',
|
|
1882
1905
|
'top.refreshing': '刷新中…',
|
|
1883
1906
|
'top.updated': '{ago}读取 · 每 {s} 秒自动刷新',
|
|
1907
|
+
'top.updatedLive': '{ago}读取 · 额度一变就更新',
|
|
1908
|
+
'top.updatedTitleLive': '各账号的额度、用量和健康状态,上次读取于 {at}。额度文件一变就立即重新读取,另外每 {s} 秒读取一次。',
|
|
1884
1909
|
'top.updatedTitle': '各账号的额度、用量和健康状态,上次读取于 {at}。页面打开时每 {s} 秒重新读取一次。',
|
|
1885
1910
|
'top.stale': '没有刷新:连不上面板,或上次读取失败。',
|
|
1886
1911
|
'foot.text': '只在本机运行,数据不会离开这台电脑。',
|
|
@@ -2028,6 +2053,27 @@ const zh = {
|
|
|
2028
2053
|
'stat.sessions.other': '{n} 个会话',
|
|
2029
2054
|
'stat.nextReset': '下一次额度重置',
|
|
2030
2055
|
'stat.noQuota': '暂无额度数据',
|
|
2056
|
+
'stat.pickNow': '现在最该用',
|
|
2057
|
+
'stat.pickNowIn': '现在最该用 · {title}',
|
|
2058
|
+
'stat.pickLeft': '{w}剩 {n}%',
|
|
2059
|
+
'stat.pickReset': '{w}已重置',
|
|
2060
|
+
'stat.pickTight': '都过了提醒线',
|
|
2061
|
+
'stat.pickNoData': '还没有它的额度数据',
|
|
2062
|
+
'stat.pickStart': '启动',
|
|
2063
|
+
'stat.pickStartTip': '点一下在终端里启动它。',
|
|
2064
|
+
'stat.pickCopy': '复制',
|
|
2065
|
+
'stat.pickCopyTip': '点一下复制启动它的命令:sideby next {family}',
|
|
2066
|
+
'stat.pickOnly': '这是你唯一的 {title} 账号,还有额度。',
|
|
2067
|
+
'stat.pickOthers': '其他工具:{list}',
|
|
2068
|
+
'stat.pickUsedUp': '都用完了',
|
|
2069
|
+
'stat.pickBack': '{ref} {when}恢复',
|
|
2070
|
+
'stat.pickWait': '等下一次重置',
|
|
2071
|
+
'stat.pickNoQuota': '还没有额度数据',
|
|
2072
|
+
'stat.pickNoQuotaTip': '这些账号有了额度数据,这里就会推荐一个:在其中一个账号开个会话,或点「刷新」。',
|
|
2073
|
+
'stat.pickSignIn': '先登录一个账号',
|
|
2074
|
+
'stat.pickNoSource': '没有能看到额度的订阅账号',
|
|
2075
|
+
'stat.pickNoSourceOne': '这个工具没有能看到额度的订阅账号',
|
|
2076
|
+
'stat.pickReading': '正在读取额度…',
|
|
2031
2077
|
'need.error.one': '{n} 个读取失败',
|
|
2032
2078
|
'need.error.other': '{n} 个读取失败',
|
|
2033
2079
|
'need.health-fail.one': '{n} 个有问题',
|
|
@@ -259,6 +259,17 @@ export declare function nextReset(accounts: LogicAccount[], now: number): {
|
|
|
259
259
|
name: string;
|
|
260
260
|
family: string;
|
|
261
261
|
} | null;
|
|
262
|
+
/**
|
|
263
|
+
* Which tool the "Best to use now" card shows (spec §3.45): the one the family filter names, else the first in the
|
|
264
|
+
* page's group `order` with a pick, else the first with an entry, so the card says why nothing can be picked. Quota
|
|
265
|
+
* is never compared across tools. `others`: every other tool with an entry, in `order`, for the hover text.
|
|
266
|
+
*/
|
|
267
|
+
export declare function pickNowChoice(pickNow: Record<string, {
|
|
268
|
+
pick: string | null;
|
|
269
|
+
}> | undefined, order: string[], filter: string): {
|
|
270
|
+
family: string;
|
|
271
|
+
others: string[];
|
|
272
|
+
} | null;
|
|
262
273
|
/**
|
|
263
274
|
* A name to offer for a new Account of a Family, given its existing Account names (`main` included or not).
|
|
264
275
|
* Numbered names (`001` … `007`) continue after the highest number with the same width (`008`); otherwise
|
|
@@ -558,6 +558,17 @@ export function nextReset(accounts, now) {
|
|
|
558
558
|
}
|
|
559
559
|
return best;
|
|
560
560
|
}
|
|
561
|
+
/**
|
|
562
|
+
* Which tool the "Best to use now" card shows (spec §3.45): the one the family filter names, else the first in the
|
|
563
|
+
* page's group `order` with a pick, else the first with an entry, so the card says why nothing can be picked. Quota
|
|
564
|
+
* is never compared across tools. `others`: every other tool with an entry, in `order`, for the hover text.
|
|
565
|
+
*/
|
|
566
|
+
export function pickNowChoice(pickNow, order, filter) {
|
|
567
|
+
const has = (f) => Boolean(pickNow && Object.hasOwn(pickNow, f));
|
|
568
|
+
const picks = order.filter((f) => has(f) && pickNow[f].pick);
|
|
569
|
+
const family = filter ? (has(filter) ? filter : null) : (picks[0] ?? order.find(has) ?? null);
|
|
570
|
+
return family ? { family, others: order.filter((f) => f !== family && has(f)) } : null;
|
|
571
|
+
}
|
|
561
572
|
/**
|
|
562
573
|
* A name to offer for a new Account of a Family, given its existing Account names (`main` included or not).
|
|
563
574
|
* Numbered names (`001` … `007`) continue after the highest number with the same width (`008`); otherwise
|