sideby 0.31.2 → 0.32.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/README.md +4 -4
- package/dist/build.json +1 -1
- package/dist/src/cli/commands.d.ts +0 -4
- package/dist/src/cli/commands.js +76 -14
- package/dist/src/cli/format.js +3 -2
- package/dist/src/cli/json-schemas.js +45 -5
- package/dist/src/cli/main.js +19 -159
- package/dist/src/core/ask.js +6 -1
- package/dist/src/core/cli-commands.d.ts +56 -0
- package/dist/src/core/cli-commands.js +842 -0
- package/dist/src/core/handoff-chain.d.ts +9 -3
- package/dist/src/core/handoff-chain.js +3 -2
- package/dist/src/core/handoff-rules.js +5 -5
- package/dist/src/core/handoff-run.js +19 -2
- package/dist/src/core/handoff-select.d.ts +15 -5
- package/dist/src/core/handoff-select.js +34 -22
- package/dist/src/core/handoff.d.ts +36 -3
- package/dist/src/core/handoff.js +57 -18
- package/dist/src/core/pick-commands.d.ts +19 -4
- package/dist/src/core/pick-commands.js +19 -5
- package/dist/src/core/quota-levels.d.ts +67 -4
- package/dist/src/core/quota-levels.js +82 -6
- package/dist/src/core/search-catalog.js +20 -0
- package/dist/src/families/claude/index.js +3 -0
- package/dist/src/families/claude/quota-fetch.d.ts +26 -0
- package/dist/src/families/claude/quota-fetch.js +236 -0
- package/dist/src/handoff/hook.js +5 -0
- package/dist/src/menubar/script.js +8 -3
- package/dist/src/menubar/snapshot.d.ts +9 -5
- package/dist/src/menubar/snapshot.js +37 -24
- package/dist/src/menubar/strings.d.ts +6 -4
- package/dist/src/menubar/strings.js +6 -4
- package/dist/src/panel/handler.js +7 -3
- package/dist/src/panel/i18n.d.ts +15 -0
- package/dist/src/panel/i18n.js +36 -6
- package/dist/src/panel/page-logic.d.ts +32 -8
- package/dist/src/panel/page-logic.js +43 -16
- package/dist/src/panel/page-script.js +129 -17
- package/dist/src/panel/page-styles.js +18 -0
- package/dist/src/panel/page.js +6 -1
- package/dist/src/runtime.d.ts +2 -1
- package/dist/src/runtime.js +10 -4
- package/dist/testing/index.d.ts +5 -0
- package/dist/testing/index.js +2 -0
- package/package.json +2 -2
- package/schemas/commands-list.json +165 -0
- package/schemas/menubar-snapshot.json +3 -3
- package/schemas/next.json +57 -4
- package/skills/sideby/SKILL.md +3 -2
- package/skills/sideby/references/accounts.md +1 -1
- package/skills/sideby/references/ai-tasks.md +2 -2
- package/skills/sideby/references/diagnose.md +1 -1
- package/skills/sideby/references/handoff.md +13 -9
- package/skills/sideby/references/panel.md +11 -1
- package/skills/sideby/references/quota.md +9 -3
|
@@ -31,7 +31,8 @@ export declare const MENUBAR_STRINGS: {
|
|
|
31
31
|
readonly windowTip: '{label}: {p}% used';
|
|
32
32
|
readonly windowResetsTip: '{label}: {p}% used · resets in {time}';
|
|
33
33
|
readonly window: '{label} {p}%';
|
|
34
|
-
readonly resets: 'resets in {time}';
|
|
34
|
+
readonly resets: '{label} resets in {time}';
|
|
35
|
+
readonly resetIn: '{label} · in {time}';
|
|
35
36
|
readonly moreApi: 'API keys ({n})';
|
|
36
37
|
readonly moreSignedOut: '{n} signed out';
|
|
37
38
|
readonly moreMixed: '{n} more';
|
|
@@ -89,7 +90,8 @@ export declare const MENUBAR_STRINGS: {
|
|
|
89
90
|
readonly windowTip: '{label}:已用 {p}%';
|
|
90
91
|
readonly windowResetsTip: '{label}:已用 {p}% · {time}后重置';
|
|
91
92
|
readonly window: '{label} {p}%';
|
|
92
|
-
readonly resets: '{time}后重置';
|
|
93
|
+
readonly resets: '{label} {time}后重置';
|
|
94
|
+
readonly resetIn: '{label} · {time}后';
|
|
93
95
|
readonly moreApi: '{n} 个 API 密钥账号';
|
|
94
96
|
readonly moreSignedOut: '{n} 个未登录账号';
|
|
95
97
|
readonly moreMixed: '另外 {n} 个账号';
|
|
@@ -97,8 +99,8 @@ export declare const MENUBAR_STRINGS: {
|
|
|
97
99
|
readonly sameLoginTip: '与 {names} 同一登录,共用这份额度';
|
|
98
100
|
readonly sep: ' · ';
|
|
99
101
|
readonly minutes: '{m}分';
|
|
100
|
-
readonly hoursMinutes: '{h}小时
|
|
101
|
-
readonly daysHours: '{d}天
|
|
102
|
+
readonly hoursMinutes: '{h}小时{m}分';
|
|
103
|
+
readonly daysHours: '{d}天{h}小时';
|
|
102
104
|
readonly startTip: '在终端里启动 {account}';
|
|
103
105
|
readonly empty: '还没有账号';
|
|
104
106
|
readonly loading: '正在读取额度…';
|
|
@@ -31,7 +31,8 @@ export const MENUBAR_STRINGS = {
|
|
|
31
31
|
windowTip: '{label}: {p}% used',
|
|
32
32
|
windowResetsTip: '{label}: {p}% used · resets in {time}',
|
|
33
33
|
window: '{label} {p}%',
|
|
34
|
-
resets: 'resets in {time}',
|
|
34
|
+
resets: '{label} resets in {time}',
|
|
35
|
+
resetIn: '{label} · in {time}',
|
|
35
36
|
moreApi: 'API keys ({n})',
|
|
36
37
|
moreSignedOut: '{n} signed out',
|
|
37
38
|
moreMixed: '{n} more',
|
|
@@ -89,7 +90,8 @@ export const MENUBAR_STRINGS = {
|
|
|
89
90
|
windowTip: '{label}:已用 {p}%',
|
|
90
91
|
windowResetsTip: '{label}:已用 {p}% · {time}后重置',
|
|
91
92
|
window: '{label} {p}%',
|
|
92
|
-
resets: '{time}后重置',
|
|
93
|
+
resets: '{label} {time}后重置',
|
|
94
|
+
resetIn: '{label} · {time}后',
|
|
93
95
|
moreApi: '{n} 个 API 密钥账号',
|
|
94
96
|
moreSignedOut: '{n} 个未登录账号',
|
|
95
97
|
moreMixed: '另外 {n} 个账号',
|
|
@@ -97,8 +99,8 @@ export const MENUBAR_STRINGS = {
|
|
|
97
99
|
sameLoginTip: '与 {names} 同一登录,共用这份额度',
|
|
98
100
|
sep: ' · ',
|
|
99
101
|
minutes: '{m}分',
|
|
100
|
-
hoursMinutes: '{h}小时
|
|
101
|
-
daysHours: '{d}天
|
|
102
|
+
hoursMinutes: '{h}小时{m}分',
|
|
103
|
+
daysHours: '{d}天{h}小时',
|
|
102
104
|
startTip: '在终端里启动 {account}',
|
|
103
105
|
empty: '还没有账号',
|
|
104
106
|
loading: '正在读取额度…',
|
|
@@ -22,6 +22,7 @@ import { listMessages, sendMessage } from '../core/messages.js';
|
|
|
22
22
|
import { accountModel, setAccountModel } from '../core/model-choice.js';
|
|
23
23
|
import { GUARDED_FAMILIES, setNetwork } from '../core/network.js';
|
|
24
24
|
import { tildify } from '../core/paths.js';
|
|
25
|
+
import { takeoverLimits } from '../core/quota-levels.js';
|
|
25
26
|
import { remoteControlTodo } from '../core/remote-control.js';
|
|
26
27
|
import { openRunBoard, withRuns } from '../core/run-link.js';
|
|
27
28
|
import { SECRET_VAR_NAME, secretVarFor, setSecret } from '../core/secret-file.js';
|
|
@@ -260,7 +261,9 @@ export function handoffByFamily(rt, accounts, now) {
|
|
|
260
261
|
kind: a.kind,
|
|
261
262
|
login: a.login ?? 'unknown',
|
|
262
263
|
quota: a.quota ?? { status: 'unavailable', reason: 'unrecognized' },
|
|
263
|
-
})), now
|
|
264
|
+
})), now,
|
|
265
|
+
// The same plan as `sideby next`: the same Takeover Limits, and past them the least used Account (a Last Resort).
|
|
266
|
+
{ limits: takeoverLimits(rt.handoffSettings().threshold), lastResort: true });
|
|
264
267
|
if (plan.pick && plan.hasQuota)
|
|
265
268
|
out[id] = plan.pick;
|
|
266
269
|
}
|
|
@@ -1272,7 +1275,7 @@ export function createPanelHandler(opts) {
|
|
|
1272
1275
|
const { family, choice } = await rt.pickChoice(name);
|
|
1273
1276
|
if (choice.ref === null)
|
|
1274
1277
|
throw new UserError(choice.earliestReset
|
|
1275
|
-
? `Every ${family} account
|
|
1278
|
+
? `Every signed-in ${family} account has used up its quota; ${choice.earliestReset.ref} is back first.`
|
|
1276
1279
|
: `No ${family} account can be used now; sign one in first.`, { code: 'none-usable' });
|
|
1277
1280
|
// The terminal runs the Pick Command itself, so it picks again as it starts and prints which and why.
|
|
1278
1281
|
const r = opened(await openPickInTerminal(rt, name));
|
|
@@ -1282,7 +1285,8 @@ export function createPanelHandler(opts) {
|
|
|
1282
1285
|
family,
|
|
1283
1286
|
picked: choice.ref,
|
|
1284
1287
|
reason: choice.reason,
|
|
1285
|
-
...('pressure' in choice ? { pressure: choice.pressure } : {}),
|
|
1288
|
+
...('pressure' in choice ? { pressure: choice.pressure, window: choice.window } : {}),
|
|
1289
|
+
...('limit' in choice ? { limit: choice.limit, longLimit: choice.longLimit } : {}),
|
|
1286
1290
|
};
|
|
1287
1291
|
},
|
|
1288
1292
|
},
|
package/dist/src/panel/i18n.d.ts
CHANGED
|
@@ -458,6 +458,7 @@ declare const en: {
|
|
|
458
458
|
'ai.ask.api': string;
|
|
459
459
|
'ai.ask.tool': string;
|
|
460
460
|
'ai.ask.find': string;
|
|
461
|
+
'ai.ask.commands': string;
|
|
461
462
|
'pal.button': string;
|
|
462
463
|
'pal.title': string;
|
|
463
464
|
'pal.placeholder': string;
|
|
@@ -477,6 +478,19 @@ declare const en: {
|
|
|
477
478
|
'pal.readOnly': string;
|
|
478
479
|
'pal.also': string;
|
|
479
480
|
'pal.keys': string;
|
|
481
|
+
'cmds.button': string;
|
|
482
|
+
'cmds.title': string;
|
|
483
|
+
'cmds.intro': string;
|
|
484
|
+
'cmds.placeholder': string;
|
|
485
|
+
'cmds.common': string;
|
|
486
|
+
'cmds.none': string;
|
|
487
|
+
'cmds.feature': string;
|
|
488
|
+
'cmds.example': string;
|
|
489
|
+
'cmds.copy': string;
|
|
490
|
+
'cmds.copied': string;
|
|
491
|
+
'cmds.open': string;
|
|
492
|
+
'cmds.openLabel': string;
|
|
493
|
+
'cmds.foot': string;
|
|
480
494
|
'ask.button': string;
|
|
481
495
|
'ask.title': string;
|
|
482
496
|
'ask.title.fix': string;
|
|
@@ -614,6 +628,7 @@ declare const en: {
|
|
|
614
628
|
'pk.namePh': string;
|
|
615
629
|
'pk.started': string;
|
|
616
630
|
'pk.why.room': string;
|
|
631
|
+
'pk.why.tight': string;
|
|
617
632
|
'pk.why.noData': string;
|
|
618
633
|
'login.opened': string;
|
|
619
634
|
'login.failed': string;
|
package/dist/src/panel/i18n.js
CHANGED
|
@@ -460,6 +460,7 @@ const en = {
|
|
|
460
460
|
'ai.ask.api': 'Add a DeepSeek API account for me.',
|
|
461
461
|
'ai.ask.tool': 'Help sideby support a new tool.',
|
|
462
462
|
'ai.ask.find': 'Where do I change the language of the Panel?',
|
|
463
|
+
'ai.ask.commands': 'Which sideby commands are there for quota?',
|
|
463
464
|
'pal.button': 'Search',
|
|
464
465
|
'pal.title': 'Search sideby',
|
|
465
466
|
'pal.placeholder': 'Find a page, setting or action…',
|
|
@@ -479,6 +480,19 @@ const en = {
|
|
|
479
480
|
'pal.readOnly': 'Not in a read-only Panel',
|
|
480
481
|
'pal.also': 'matches “{w}”',
|
|
481
482
|
'pal.keys': '↑ ↓ to move · Enter to open · Esc to close',
|
|
483
|
+
'cmds.button': 'Commands',
|
|
484
|
+
'cmds.title': 'Commands',
|
|
485
|
+
'cmds.intro': 'Everything the Panel does, you can also type in a terminal. Copy a command and paste it there.',
|
|
486
|
+
'cmds.placeholder': 'Filter commands, in English or Chinese…',
|
|
487
|
+
'cmds.common': 'Common',
|
|
488
|
+
'cmds.none': 'No command matches “{q}”.',
|
|
489
|
+
'cmds.feature': 'Search Panel features for “{q}”',
|
|
490
|
+
'cmds.example': 'Example',
|
|
491
|
+
'cmds.copy': 'Copy {text}',
|
|
492
|
+
'cmds.copied': 'Copied',
|
|
493
|
+
'cmds.open': 'Open in Panel',
|
|
494
|
+
'cmds.openLabel': 'Open {what} in the Panel',
|
|
495
|
+
'cmds.foot': 'Press ? anywhere to open this list · sideby commands in a terminal · Esc to close',
|
|
482
496
|
'ask.button': 'Let AI do it',
|
|
483
497
|
'ask.title': 'Let AI do it',
|
|
484
498
|
'ask.title.fix': 'Let AI fix it',
|
|
@@ -615,7 +629,8 @@ const en = {
|
|
|
615
629
|
'pk.offerNoNameShort': 'Add short command',
|
|
616
630
|
'pk.namePh': 'e.g. cc',
|
|
617
631
|
'pk.started': 'Opened {ref} in {terminal} ({why}).',
|
|
618
|
-
'pk.why.room': '{n}% used, most quota left',
|
|
632
|
+
'pk.why.room': '{w}{n}% used, most quota left',
|
|
633
|
+
'pk.why.tight': 'every account is past its limit ({limit}% of a 5-hour window, {longLimit}% of a weekly one); this one has the most left, {w}{n}% used',
|
|
619
634
|
'pk.why.noData': 'no quota data yet',
|
|
620
635
|
'login.opened': 'Opened {terminal}: sign in to {ref} there.',
|
|
621
636
|
'login.failed': 'Could not open a terminal. Copied: paste it into your terminal and press Return.',
|
|
@@ -871,8 +886,8 @@ const en = {
|
|
|
871
886
|
'hp.rulesNote': 'These rules decide when an account hands over and which account takes over. Each change applies at once and can be undone.',
|
|
872
887
|
'hp.rule.whenAdaptive': 'The AI writes a handoff note at {prepare}% used. Handoff starts at {p}% used until sideby learns how fast this session spends quota, then between {prepare}% and {max}%, earlier if recent turns used a lot.',
|
|
873
888
|
'hp.rule.when': 'The AI writes a handoff note at {prepare}% used. Handoff starts at {p}% used.',
|
|
874
|
-
'hp.rule.windows': 'Every quota window counts (5 hours, weekly, a billing period): the fullest
|
|
875
|
-
'hp.rule.takeover': '
|
|
889
|
+
'hp.rule.windows': 'Every quota window counts (5 hours, weekly, a billing period): the session hands over when its fullest window reaches the level above. No AI has a daily quota.',
|
|
890
|
+
'hp.rule.takeover': 'An account will not take over once a 5-hour window is {limit}% used or a weekly window is {long}% used, so the next account has room to work. A 5-hour window costs only about a fifth of a week, so the weekly line sits higher: at the handoff level ({p}%), the 5-hour line 10 points below it. The account furthest from these lines goes first.',
|
|
876
891
|
'hp.rule.wait': 'If the quota comes back within {w} minutes and the session carries on by itself at that point (Claude Code), it waits instead of switching. Codex and Grok switch right away.',
|
|
877
892
|
'hp.rule.noWait': 'It never waits for quota to come back; it switches right away.',
|
|
878
893
|
'hp.rule.sameOn': 'Other accounts of the same AI can take over first (for example cc001 to cc002). The account with the most quota left goes first.',
|
|
@@ -2035,6 +2050,7 @@ const zh = {
|
|
|
2035
2050
|
'ai.ask.api': '帮我加一个 DeepSeek API 账号。',
|
|
2036
2051
|
'ai.ask.tool': '帮 sideby 支持一个新工具。',
|
|
2037
2052
|
'ai.ask.find': '面板的语言在哪里改?',
|
|
2053
|
+
'ai.ask.commands': 'sideby 有哪些和额度有关的命令?',
|
|
2038
2054
|
'pal.button': '搜索',
|
|
2039
2055
|
'pal.title': '搜索 sideby',
|
|
2040
2056
|
'pal.placeholder': '查找页面、设置或操作…',
|
|
@@ -2054,6 +2070,19 @@ const zh = {
|
|
|
2054
2070
|
'pal.readOnly': '只读面板里不能用',
|
|
2055
2071
|
'pal.also': '匹配“{w}”',
|
|
2056
2072
|
'pal.keys': '↑ ↓ 选择 · Enter 打开 · Esc 关闭',
|
|
2073
|
+
'cmds.button': '命令',
|
|
2074
|
+
'cmds.title': '命令',
|
|
2075
|
+
'cmds.intro': '面板能做的事,在终端里也能敲命令完成。复制一条命令,粘贴到终端里运行。',
|
|
2076
|
+
'cmds.placeholder': '筛选命令,中英文都行…',
|
|
2077
|
+
'cmds.common': '常用',
|
|
2078
|
+
'cmds.none': '没有匹配“{q}”的命令。',
|
|
2079
|
+
'cmds.feature': '在面板功能里搜索“{q}”',
|
|
2080
|
+
'cmds.example': '示例',
|
|
2081
|
+
'cmds.copy': '复制 {text}',
|
|
2082
|
+
'cmds.copied': '已复制',
|
|
2083
|
+
'cmds.open': '在面板中打开',
|
|
2084
|
+
'cmds.openLabel': '在面板中打开{what}',
|
|
2085
|
+
'cmds.foot': '在任意位置按 ? 打开这个列表 · 终端里用 sideby commands · Esc 关闭',
|
|
2057
2086
|
'ask.button': '让 AI 帮我',
|
|
2058
2087
|
'ask.title': '让 AI 帮我',
|
|
2059
2088
|
'ask.title.fix': '让 AI 修复',
|
|
@@ -2190,7 +2219,8 @@ const zh = {
|
|
|
2190
2219
|
'pk.offerNoNameShort': '添加短命令',
|
|
2191
2220
|
'pk.namePh': '例如 cc',
|
|
2192
2221
|
'pk.started': '已在 {terminal} 启动 {ref}({why})。',
|
|
2193
|
-
'pk.why.room': '已用 {n}%,剩余额度最多',
|
|
2222
|
+
'pk.why.room': '{w}已用 {n}%,剩余额度最多',
|
|
2223
|
+
'pk.why.tight': '所有账号都已到上限(5 小时窗口 {limit}%,每周窗口 {longLimit}%);这个剩得最多,{w}已用 {n}%',
|
|
2194
2224
|
'pk.why.noData': '还没有额度数据',
|
|
2195
2225
|
'login.opened': '已打开 {terminal},请在那里登录 {ref}。',
|
|
2196
2226
|
'login.failed': '终端没打开,命令已复制:粘贴到你的终端,按回车。',
|
|
@@ -2446,8 +2476,8 @@ const zh = {
|
|
|
2446
2476
|
'hp.rulesNote': '这些规则决定什么时候接力、交给哪个账号。每项改动立即生效,可以撤销。',
|
|
2447
2477
|
'hp.rule.whenAdaptive': '用量到 {prepare}% 时,AI 会写好接力笔记。sideby 了解本次会话的消耗速度前,会在用量到 {p}% 时接力;之后会在 {prepare}% 到 {max}% 之间接力,最近几轮用得多就更早接力。',
|
|
2448
2478
|
'hp.rule.when': '用量到 {prepare}% 时,AI 会写好接力笔记;用量到 {p}% 时接力。',
|
|
2449
|
-
'hp.rule.windows': '每个额度窗口都算(5
|
|
2450
|
-
'hp.rule.takeover': '
|
|
2479
|
+
'hp.rule.windows': '每个额度窗口都算(5 小时、每周、计费周期):会话用得最多的窗口到上面的用量就接力。目前没有 AI 设日额度。',
|
|
2480
|
+
'hp.rule.takeover': '5 小时窗口用到 {limit}%、或每周窗口用到 {long}% 的账号不会接手,确保下一个账号有足够额度干活。一个 5 小时窗口只占一周额度的五分之一左右,所以每周的线更高:等于接力用量({p}%),5 小时的线比它低 10 个百分点。离这两条线最远的账号先接手。',
|
|
2451
2481
|
'hp.rule.wait': '如果 {w} 分钟内额度就恢复,而且会话到时会自己继续(Claude Code),就原地等,不换号。Codex 和 Grok 直接换号。',
|
|
2452
2482
|
'hp.rule.noWait': '不等额度恢复,直接换号。',
|
|
2453
2483
|
'hp.rule.sameOn': '同一个 AI 的其他账号优先接手(例如 cc001 到 cc002),剩余额度最多的优先。',
|
|
@@ -52,11 +52,27 @@ export interface LogicUsage {
|
|
|
52
52
|
}
|
|
53
53
|
/** A short countdown such as `2h 05m`, `3d 4h` or `12m` (`2小时05分` in Chinese); fixed shape so it does not jump. */
|
|
54
54
|
export declare function formatDuration(ms: number, lang: string): string;
|
|
55
|
-
/**
|
|
55
|
+
/**
|
|
56
|
+
* A Long Window: longer than one day (weekly, a billing period), from `windowMinutes` or else a label such as `7d`.
|
|
57
|
+
* The page's copy of `isLongWindow` in core/quota-levels.ts; a test keeps the two equal.
|
|
58
|
+
*/
|
|
59
|
+
export declare function longWindow(w: {
|
|
60
|
+
label?: string;
|
|
61
|
+
windowMinutes?: number;
|
|
62
|
+
}): boolean;
|
|
63
|
+
/**
|
|
64
|
+
* One Quota window as the page draws it: percent used (0 after a reset passed) and its warning level. `warn` and
|
|
65
|
+
* `fail` are a Short Window's levels; `long`, when given, a Long Window's (spec §3.26: a weekly window warns later).
|
|
66
|
+
*/
|
|
56
67
|
export declare function windowState(w: {
|
|
57
68
|
usedPercent: number;
|
|
58
69
|
resetsAt: string;
|
|
59
|
-
|
|
70
|
+
label?: string;
|
|
71
|
+
windowMinutes?: number;
|
|
72
|
+
}, now: number, warn: number, fail: number, long?: {
|
|
73
|
+
warn: number;
|
|
74
|
+
fail: number;
|
|
75
|
+
}): {
|
|
60
76
|
pct: number;
|
|
61
77
|
passed: boolean;
|
|
62
78
|
level: string;
|
|
@@ -68,7 +84,12 @@ export declare function windowState(w: {
|
|
|
68
84
|
export declare function bindingWindow<W extends {
|
|
69
85
|
usedPercent: number;
|
|
70
86
|
resetsAt: string;
|
|
71
|
-
|
|
87
|
+
label?: string;
|
|
88
|
+
windowMinutes?: number;
|
|
89
|
+
}>(list: W[], now: number, warn: number, fail: number, long?: {
|
|
90
|
+
warn: number;
|
|
91
|
+
fail: number;
|
|
92
|
+
}): W | undefined;
|
|
72
93
|
/**
|
|
73
94
|
* A window whose reset time has passed: the numbers on record are from before the reset and nothing newer came
|
|
74
95
|
* in. `since` is when they were last seen (the Quota's observation time, or the reset itself when that is
|
|
@@ -89,12 +110,15 @@ export declare function quotaPressure(a: LogicAccount, now: number): number;
|
|
|
89
110
|
export declare function attentionReasons(a: LogicAccount, health: {
|
|
90
111
|
fail: number;
|
|
91
112
|
warn: number;
|
|
92
|
-
} | null, now: number, warn: number
|
|
113
|
+
} | null, now: number, warn: number,
|
|
114
|
+
/** A Long Window's warning level (spec §3.26); without it every window uses `warn`. */
|
|
115
|
+
longWarn?: number): string[];
|
|
93
116
|
/**
|
|
94
|
-
* How serious an Account's `quota-high` is: `fail` once
|
|
95
|
-
* else `warn`, so a running-low label takes the same color as the bar it speaks
|
|
117
|
+
* How serious an Account's `quota-high` is: `fail` once a live window reaches its red level (`fail`, or `longFail` for
|
|
118
|
+
* a Long Window: the bar turns red), else `warn`, so a running-low label takes the same color as the bar it speaks
|
|
119
|
+
* about.
|
|
96
120
|
*/
|
|
97
|
-
export declare function quotaHighLevel(a: LogicAccount, now: number, fail: number): 'warn' | 'fail';
|
|
121
|
+
export declare function quotaHighLevel(a: LogicAccount, now: number, fail: number, longFail?: number): 'warn' | 'fail';
|
|
98
122
|
/**
|
|
99
123
|
* The one status badge an account row shows after its name (spec §3.27), most important first: `health-fail`
|
|
100
124
|
* (needs fixing), `quota-high` (running low), the other attention labels (`signed-out`, `not-installed`,
|
|
@@ -112,7 +136,7 @@ export declare function rowBadge(reasons: string[], opts: {
|
|
|
112
136
|
export declare function attentionWhy(a: LogicAccount, health: {
|
|
113
137
|
fail: number;
|
|
114
138
|
warn: number;
|
|
115
|
-
} | null, now: number, warn: number): {
|
|
139
|
+
} | null, now: number, warn: number, longWarn?: number): {
|
|
116
140
|
key: string;
|
|
117
141
|
vars: Record<string, string | number>;
|
|
118
142
|
} | null;
|
|
@@ -18,23 +18,42 @@ export function formatDuration(ms, lang) {
|
|
|
18
18
|
return zh ? `${h}小时${mm}分` : `${h}h ${mm}m`;
|
|
19
19
|
return zh ? `${m}分钟` : `${m}m`;
|
|
20
20
|
}
|
|
21
|
-
/**
|
|
22
|
-
|
|
21
|
+
/**
|
|
22
|
+
* A Long Window: longer than one day (weekly, a billing period), from `windowMinutes` or else a label such as `7d`.
|
|
23
|
+
* The page's copy of `isLongWindow` in core/quota-levels.ts; a test keeps the two equal.
|
|
24
|
+
*/
|
|
25
|
+
export function longWindow(w) {
|
|
26
|
+
let minutes = Number(w.windowMinutes);
|
|
27
|
+
if (!(Number.isFinite(minutes) && minutes > 0)) {
|
|
28
|
+
const m = /^(\d+(?:\.\d+)?)\s*([mhdw])$/i.exec(String(w.label ?? '').trim());
|
|
29
|
+
const units = { m: 1, h: 60, d: 1440, w: 10080 };
|
|
30
|
+
minutes = m ? Number(m[1]) * units[m[2].toLowerCase()] : 0;
|
|
31
|
+
}
|
|
32
|
+
return minutes > 1440;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* One Quota window as the page draws it: percent used (0 after a reset passed) and its warning level. `warn` and
|
|
36
|
+
* `fail` are a Short Window's levels; `long`, when given, a Long Window's (spec §3.26: a weekly window warns later).
|
|
37
|
+
*/
|
|
38
|
+
export function windowState(w, now, warn, fail, long) {
|
|
23
39
|
const reset = Date.parse(w.resetsAt);
|
|
24
40
|
const passed = Number.isFinite(reset) && reset <= now;
|
|
25
41
|
const raw = Math.max(0, Math.min(100, Math.round(Number(w.usedPercent) || 0)));
|
|
26
42
|
const pct = passed ? 0 : raw;
|
|
27
|
-
const
|
|
43
|
+
const lv = long && longWindow(w) ? long : { warn, fail };
|
|
44
|
+
const level = passed ? 'reset' : pct >= lv.fail ? 'fail' : pct >= lv.warn ? 'warn' : 'ok';
|
|
28
45
|
return { pct, passed, level };
|
|
29
46
|
}
|
|
30
47
|
/**
|
|
31
48
|
* The window that binds first among those sharing one column (a model group with a 5-hour and a weekly limit, as
|
|
32
49
|
* Antigravity CLI reports): the most used as the page draws it, the first on a tie. Undefined for none.
|
|
33
50
|
*/
|
|
34
|
-
export function bindingWindow(list, now, warn, fail) {
|
|
51
|
+
export function bindingWindow(list, now, warn, fail, long) {
|
|
52
|
+
// Closest to its own red level: a weekly 87% of 95 binds before a 5-hour 80% of 85.
|
|
53
|
+
const share = (w) => windowState(w, now, warn, fail).pct / (long && longWindow(w) ? long.fail : fail);
|
|
35
54
|
let best;
|
|
36
55
|
for (const w of list)
|
|
37
|
-
if (!best ||
|
|
56
|
+
if (!best || share(w) > share(best))
|
|
38
57
|
best = w;
|
|
39
58
|
return best;
|
|
40
59
|
}
|
|
@@ -71,7 +90,9 @@ export function quotaPressure(a, now) {
|
|
|
71
90
|
* `quota-high` (a live window at or over the warning level), `health-warn`. Empty when all is well. A Quota read from
|
|
72
91
|
* another Account of the same login (`quota.from`, spec §3.21) is that Account's warning, so it counts once per group.
|
|
73
92
|
*/
|
|
74
|
-
export function attentionReasons(a, health, now, warn
|
|
93
|
+
export function attentionReasons(a, health, now, warn,
|
|
94
|
+
/** A Long Window's warning level (spec §3.26); without it every window uses `warn`. */
|
|
95
|
+
longWarn = warn) {
|
|
75
96
|
const out = [];
|
|
76
97
|
if (a.error)
|
|
77
98
|
out.push('error');
|
|
@@ -89,7 +110,7 @@ export function attentionReasons(a, health, now, warn) {
|
|
|
89
110
|
const reset = Date.parse(w.resetsAt);
|
|
90
111
|
if (Number.isFinite(reset) && reset <= now)
|
|
91
112
|
continue;
|
|
92
|
-
if ((Number(w.usedPercent) || 0) >= warn) {
|
|
113
|
+
if ((Number(w.usedPercent) || 0) >= (longWindow(w) ? longWarn : warn)) {
|
|
93
114
|
out.push('quota-high');
|
|
94
115
|
break;
|
|
95
116
|
}
|
|
@@ -99,10 +120,11 @@ export function attentionReasons(a, health, now, warn) {
|
|
|
99
120
|
return out;
|
|
100
121
|
}
|
|
101
122
|
/**
|
|
102
|
-
* How serious an Account's `quota-high` is: `fail` once
|
|
103
|
-
* else `warn`, so a running-low label takes the same color as the bar it speaks
|
|
123
|
+
* How serious an Account's `quota-high` is: `fail` once a live window reaches its red level (`fail`, or `longFail` for
|
|
124
|
+
* a Long Window: the bar turns red), else `warn`, so a running-low label takes the same color as the bar it speaks
|
|
125
|
+
* about.
|
|
104
126
|
*/
|
|
105
|
-
export function quotaHighLevel(a, now, fail) {
|
|
127
|
+
export function quotaHighLevel(a, now, fail, longFail = fail) {
|
|
106
128
|
const q = a.quota;
|
|
107
129
|
if (!q || q.status !== 'ok' || !q.windows || q.from)
|
|
108
130
|
return 'warn';
|
|
@@ -112,7 +134,7 @@ export function quotaHighLevel(a, now, fail) {
|
|
|
112
134
|
const reset = Date.parse(w.resetsAt);
|
|
113
135
|
if (Number.isFinite(reset) && reset <= now)
|
|
114
136
|
continue;
|
|
115
|
-
if ((Number(w.usedPercent) || 0) >= fail)
|
|
137
|
+
if ((Number(w.usedPercent) || 0) >= (longWindow(w) ? longFail : fail))
|
|
116
138
|
return 'fail';
|
|
117
139
|
}
|
|
118
140
|
return 'warn';
|
|
@@ -137,12 +159,13 @@ export function rowBadge(reasons, opts) {
|
|
|
137
159
|
* attention count is: `why.<reason>`; for `quota-high` the fullest live window at or over `warn`, with its label and
|
|
138
160
|
* rounded percentage. Null when all is well.
|
|
139
161
|
*/
|
|
140
|
-
export function attentionWhy(a, health, now, warn) {
|
|
141
|
-
const reason = attentionReasons(a, health, now, warn)[0];
|
|
162
|
+
export function attentionWhy(a, health, now, warn, longWarn = warn) {
|
|
163
|
+
const reason = attentionReasons(a, health, now, warn, longWarn)[0];
|
|
142
164
|
if (!reason)
|
|
143
165
|
return null;
|
|
144
166
|
if (reason !== 'quota-high')
|
|
145
167
|
return { key: `why.${reason}`, vars: {} };
|
|
168
|
+
// The window furthest past its own warning level: a weekly window warns at `longWarn` (spec §3.26).
|
|
146
169
|
let top = null;
|
|
147
170
|
for (const w of a.quota?.windows ?? []) {
|
|
148
171
|
if (w.name)
|
|
@@ -151,10 +174,14 @@ export function attentionWhy(a, health, now, warn) {
|
|
|
151
174
|
if (Number.isFinite(reset) && reset <= now)
|
|
152
175
|
continue;
|
|
153
176
|
const pct = Number(w.usedPercent) || 0;
|
|
154
|
-
|
|
155
|
-
|
|
177
|
+
const at = longWindow(w) ? longWarn : warn;
|
|
178
|
+
if (pct >= at && (!top || pct / at > top.pct / top.at))
|
|
179
|
+
top = { label: w.label, pct, at };
|
|
156
180
|
}
|
|
157
|
-
return {
|
|
181
|
+
return {
|
|
182
|
+
key: 'why.quota-high',
|
|
183
|
+
vars: { label: top?.label ?? '', pct: Math.round(top?.pct ?? 0), warn: top?.at ?? warn },
|
|
184
|
+
};
|
|
158
185
|
}
|
|
159
186
|
/**
|
|
160
187
|
* `items` in Display Order (spec §3.25): those whose key is in `order` first, in that order; the others after, in the
|