dsh-agy-link 0.6.48 → 0.6.50
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/CHANGELOG.md +40 -0
- package/dist/cli-image.mjs +97 -32
- package/dist/client.js +121 -32
- package/dist/index.js +144 -41
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,45 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.6.50 (2026-11-21)
|
|
4
|
+
|
|
5
|
+
### English
|
|
6
|
+
|
|
7
|
+
- **Fix(watchdog): a scheduled wake-up no longer releases the idle-grace exemption on its own status line (fixes #148).** When agy hands work to the background it asks the model for a short status update before it prints the idle line, so the sequence was: tool returns `state === 'RUNNING'` → `text`/`thinking` step → `root agent idle; waiting …`. `text`/`thinking` cleared the subagent exemption and `RUNNING` counted as a completed hand-off, so nothing held the exemption when the idle line finally arrived.
|
|
8
|
+
- A `schedule` step that returns `RUNNING` is now tracked until it reports a terminal state, and that wait holds the exemption independently; a `text`/`thinking` step no longer cancels it (it still restores the normal idle *budget*, which is a different concern).
|
|
9
|
+
- **`run_command` is deliberately excluded.** agy also uses it for daemons (dev servers, watchers) that never report back, and reclaiming those is exactly what #119 exists for — #124's test pins that. A backgrounded *build* is protected by agy's own count instead (`waiting for N background task(s)` with N > 0 disarms the reaper, shipped in v0.6.46/0.6.48), which needs no exemption and cannot resurrect the daemon case.
|
|
10
|
+
- **Fix(mcp-bridge): `/tools` now lists the caller's own tool surface (fixes #150).** The endpoint called `svc.schemas()` with no scope, so every tool registered inside a DSH preset (`present`, `todo_write`, `job_*`, `schedule_*`, `office_*`) was invisible to an allowlisted agy child even though `/call` could invoke it. The session→agent resolution that `/call` already performed is now a shared `resolveSessionAgent()` used by both endpoints, including the bare-sub-agent-key retry with the `session-` prefix.
|
|
11
|
+
|
|
12
|
+
### 中文
|
|
13
|
+
|
|
14
|
+
- **修复(watchdog):定时唤醒不再因为自己的状态提示而解除 idle-grace 豁免(修复 #148)。** agy 把工作交给后台时,要求模型先发一句简短状态更新,然后才打印 idle 行,于是顺序是:工具返回 `state === 'RUNNING'` → `text`/`thinking` 步骤 → `root agent idle; waiting …`。而 `text`/`thinking` 会清掉子代理豁免,`RUNNING` 又被当作「已完成交接」,等 idle 行真正出现时已没有任何东西撑着豁免。
|
|
15
|
+
- 返回 `RUNNING` 的 `schedule` 步骤现在被跟踪到它有终态为止,这个等待**独立**持有豁免;`text`/`thinking` 不再取消它(它仍然负责把空闲**预算**恢复正常,那是另一件事)。
|
|
16
|
+
- **`run_command` 被刻意排除。** agy 也用它启动永不回报的守护进程(dev server、watcher),而回收这类进程正是 #119 存在的理由——#124 的测试锁定着这一点。而后台化的**构建**由 agy 自己的计数保护(`waiting for N background task(s)`,N > 0 时不武装收割器,v0.6.46/0.6.48 已发布),既不需要豁免,也不会把守护进程那一类放回来。
|
|
17
|
+
- **修复(mcp-bridge):`/tools` 现在列出调用者自己的工具面(修复 #150)。** 该端点用无 scope 的 `svc.schemas()`,导致注册在 DSH preset 里的工具(`present`、`todo_write`、`job_*`、`schedule_*`、`office_*`)对已加入白名单的 agy 子进程完全不可见,尽管 `/call` 其实能调用它们。`/call` 原本就有的 session→agent 解析被提取为共用的 `resolveSessionAgent()`,两个端点都用它,包括「裸子会话 key 加 `session-` 前缀重试」的行为。
|
|
18
|
+
|
|
19
|
+
## 0.6.49 (2026-11-20)
|
|
20
|
+
|
|
21
|
+
### English
|
|
22
|
+
|
|
23
|
+
- **Fix(accounts/UI): one source of truth for quota admission, so the console never disagrees with the scheduler.** A Pro account at `0%` on the 5-hour window (e.g. `god`) was rotated out by `isQuotaBenched()` while every client surface still painted it eligible: the dot stayed green, no badge appeared, "Set as in use" was offered, and `/agy pool` printed `Ready`. Clicking it reported success and then silently retreated, because `setActiveAccount()` never consulted eligibility.
|
|
24
|
+
- New `src/common/quota-bench.ts` holds the pure predicates (`is5hQuotaBenched`, `isWeeklyQuotaBenched`, `isQuotaBenched`, `accountHasActiveCooldown`, `accountHasQuotaBench`, `isAccountCriticalAuth`). `domain/accounts/selection.ts` re-exports them, so scheduling and rendering share one implementation instead of two drifting copies.
|
|
25
|
+
- `AccountsPanel` now derives the dot, the `rate-limited` badge, the banner (with its clear action) and the visibility of "Set as in use" from those predicates; a quota-benched account is no longer advertised as usable. `VALIDATION_REQUIRED` / `TOS_VIOLATION` render as `Verification required` / `Suspended (ToS)` with the verification link, taken from `quotaUnavailable` when `authError` carries no URL.
|
|
26
|
+
- `QuotaPanel` marks the 5-hour and weekly rows `· rate-limited` when they are what benched the account. `SessionStatus` includes quota benches in both the active-account and all-accounts-drained checks, so the header dot turns amber too.
|
|
27
|
+
- `setActiveAccount()` validates with `isAccountEligible()`, so a rejected pin returns `false` up front instead of a false success. `/agy pool` reports `Quota-limited (auto-rotated until reset)` instead of `Ready`.
|
|
28
|
+
- **Fix(quota): the "data frozen at" stamp names the oldest frozen window.** `renderQuotaUnavailableNote` used `Math.max` across families, so a partial refresh that only touched `argon` dated the whole row to *now* (14:05) while the failing `google` snapshot was hours old (11:27). It now takes the oldest non-zero `updatedAt`, which is what "the data is stuck at" actually means.
|
|
29
|
+
- **Fix(quota): verification and ToS refusals quarantine the account immediately.** A `403` carrying `VALIDATION_REQUIRED` or `TOS_VIOLATION` recorded `quotaUnavailable` but left `authRequired` unset, so selection kept routing to an account Google had just refused. Both reasons now stamp `authRequired` (with the verification URL) and clear again once a later summary succeeds.
|
|
30
|
+
- Four locales updated (en/es/ptBR/zh). Regression suite added: `test/status-consistency.test.ts` (5 cases covering the benched-card render, the header dot, `setActiveAccount` agreement, the frozen-stamp choice, and the verification heals-on-success path).
|
|
31
|
+
|
|
32
|
+
### 中文
|
|
33
|
+
|
|
34
|
+
- **修复(账号/UI):配额可用性判定收敛为单一真源,控制台不再与调度器打架。** 一个 5 小时额度 `0%` 的 Pro 账号(如 `god`)已被 `isQuotaBenched()` 轮转掉,但所有前端面仍把它画成可用:圆点还是绿的、没有任何标签、「设为当前使用」照常出现、`/agy pool` 也打印 `Ready`。点下去还会提示成功然后悄悄退回,因为 `setActiveAccount()` 从未校验可用性。
|
|
35
|
+
- 新增 `src/common/quota-bench.ts` 承载纯谓词(`is5hQuotaBenched`、`isWeeklyQuotaBenched`、`isQuotaBenched`、`accountHasActiveCooldown`、`accountHasQuotaBench`、`isAccountCriticalAuth`)。`domain/accounts/selection.ts` 复用它并再导出,调度与渲染共用一份实现,而不是两份逐渐分叉的副本。
|
|
36
|
+
- `AccountsPanel` 的圆点、`限流中` 标签、提示条(含清除动作)以及「设为当前使用」的可见性,全部由这些谓词推导;被配额限流的账号不再被宣称为可用。`VALIDATION_REQUIRED` / `TOS_VIOLATION` 显示为 `需安全验证` / `已封禁 (ToS)` 并附验证链接——当 `authError` 里没有 URL 时从 `quotaUnavailable` 取。
|
|
37
|
+
- `QuotaPanel` 在 5 小时或周额度正是限流原因时,于对应行标注 `· 限流中`。`SessionStatus` 把配额限流也纳入「当前账号」与「全部账号耗尽」的判定,顶部圆点同步变琥珀色。
|
|
38
|
+
- `setActiveAccount()` 改用 `isAccountEligible()` 校验,被拒绝的固定会当场返回 `false`,而不是假成功。`/agy pool` 输出 `Quota-limited (auto-rotated until reset)`,不再是 `Ready`。
|
|
39
|
+
- **修复(额度):冻结时间戳改取最早冻结的那个窗口。** `renderQuotaUnavailableNote` 原先取各族的 `Math.max`,于是一次只刷新了 `argon` 的部分刷新会把整行标成「数据停留在」当下(14:05),而真正失败的 `google` 快照已经是几小时前(11:27)。现改取最早的非零 `updatedAt`——这才是「数据卡在什么时候」的本意。
|
|
40
|
+
- **修复(额度):需验证与被封禁会被立即隔离。** 携带 `VALIDATION_REQUIRED` 或 `TOS_VIOLATION` 的 `403` 只记录了 `quotaUnavailable`,却没设 `authRequired`,于是选号仍在往 Google 刚拒绝过的账号上派活。现在这两种原因都会打上 `authRequired`(含验证链接),并在后续 summary 成功时自动解除。
|
|
41
|
+
- 四语言词条同步(en/es/ptBR/zh)。新增回归套件 `test/status-consistency.test.ts`(5 条用例,覆盖限流卡片渲染、顶部圆点、`setActiveAccount` 一致性、冻结时间戳选取,以及验证通过后自动恢复)。
|
|
42
|
+
|
|
3
43
|
## 0.6.48 (2026-11-20)
|
|
4
44
|
|
|
5
45
|
### English
|
package/dist/cli-image.mjs
CHANGED
|
@@ -6887,6 +6887,19 @@ const SUBAGENT_COLLAB_TOOLS = /* @__PURE__ */ new Set([
|
|
|
6887
6887
|
"run_workflow",
|
|
6888
6888
|
"swarm"
|
|
6889
6889
|
]);
|
|
6890
|
+
/**
|
|
6891
|
+
* Tools that hand work to the BACKGROUND and return `state === 'RUNNING'` with a
|
|
6892
|
+
* DETERMINISTIC finish: a scheduled wake-up reports back when its timer fires.
|
|
6893
|
+
* The root agent idles until then, so the reaper stays suspended for the wait
|
|
6894
|
+
* (issue #148).
|
|
6895
|
+
*
|
|
6896
|
+
* `run_command` is deliberately NOT here: agy also uses it for daemons (dev
|
|
6897
|
+
* servers, watchers) that never report back, and reclaiming those is exactly
|
|
6898
|
+
* what #119 exists for. A backgrounded BUILD is protected by agy's own count
|
|
6899
|
+
* instead — `waiting for N background task(s)` with N > 0 keeps the reaper
|
|
6900
|
+
* disarmed (see idle-line.ts).
|
|
6901
|
+
*/
|
|
6902
|
+
const BACKGROUND_WAIT_TOOLS = /* @__PURE__ */ new Set(["schedule"]);
|
|
6890
6903
|
function resolveWatchdogBudgets(cfg) {
|
|
6891
6904
|
const longToolIdleMinutes = cfg.longToolIdleMinutes > 0 ? cfg.longToolIdleMinutes : 0;
|
|
6892
6905
|
let printTimeoutMinutes = Math.max(longToolIdleMinutes > 0 ? longToolIdleMinutes : Math.ceil(cfg.timeoutMs / 6e4), Math.ceil(cfg.timeoutMs / 6e4));
|
|
@@ -6911,6 +6924,36 @@ function isToolStepCompleted(ev) {
|
|
|
6911
6924
|
* build, …) — issue #33 — so the watchdog raises the idle budget; bare
|
|
6912
6925
|
* generation gets a bounded floor so a hung SSE stream can fail and rotate.
|
|
6913
6926
|
*/
|
|
6927
|
+
/**
|
|
6928
|
+
* Tracks backgrounded hand-offs whose completion agy will report later
|
|
6929
|
+
* (`schedule`). They hold the idle-grace exemption on their own: the mapper
|
|
6930
|
+
* treats `RUNNING` as a completed hand-off, so they never appear in
|
|
6931
|
+
* `openToolKeys`, yet the root agent is still waiting on them (issue #148).
|
|
6932
|
+
*/
|
|
6933
|
+
function createBackgroundWaits(onChange) {
|
|
6934
|
+
const keys = /* @__PURE__ */ new Set();
|
|
6935
|
+
return {
|
|
6936
|
+
note(stepKey, name, state, completed) {
|
|
6937
|
+
if (!BACKGROUND_WAIT_TOOLS.has(name)) return;
|
|
6938
|
+
const before = keys.size;
|
|
6939
|
+
if (state === "RUNNING") keys.add(stepKey);
|
|
6940
|
+
else if (completed) keys.delete(stepKey);
|
|
6941
|
+
if (keys.size !== before) onChange();
|
|
6942
|
+
},
|
|
6943
|
+
get active() {
|
|
6944
|
+
return keys.size > 0;
|
|
6945
|
+
},
|
|
6946
|
+
clear() {
|
|
6947
|
+
keys.clear();
|
|
6948
|
+
}
|
|
6949
|
+
};
|
|
6950
|
+
}
|
|
6951
|
+
/** Heartbeat log line: what the turn is waiting on and for how long. */
|
|
6952
|
+
function heartbeatMessage(openCount, oldestAt, sinceOutput, longToolIdleMs) {
|
|
6953
|
+
const mins = Math.max(1, Math.round((Date.now() - (openCount === 0 && sinceOutput > 0 ? sinceOutput : oldestAt)) / 6e4));
|
|
6954
|
+
const budget = Math.round(longToolIdleMs / 6e4) + "m";
|
|
6955
|
+
return openCount > 0 ? "agy tool step still running: " + openCount + " open, oldest " + mins + "m (idle budget " + budget + ") — the turn is waiting on agy" : "agy run still working: no new output for " + mins + "m (idle budget " + budget + ") — the turn is waiting on agy; press Stop to cancel";
|
|
6956
|
+
}
|
|
6914
6957
|
function createToolWatchdog(log, cfg) {
|
|
6915
6958
|
const openToolKeys = /* @__PURE__ */ new Set();
|
|
6916
6959
|
const openToolSince = /* @__PURE__ */ new Map();
|
|
@@ -6922,8 +6965,9 @@ function createToolWatchdog(log, cfg) {
|
|
|
6922
6965
|
const TOOL_HEARTBEAT_MS = 3e5;
|
|
6923
6966
|
let toolHeartbeat = null;
|
|
6924
6967
|
let idleGraceExempt = false;
|
|
6968
|
+
const backgroundWaits = createBackgroundWaits(() => syncIdleGraceExempt());
|
|
6925
6969
|
const syncIdleGraceExempt = () => {
|
|
6926
|
-
const next = awaitingSubagent || openToolKeys.size > 0;
|
|
6970
|
+
const next = awaitingSubagent || openToolKeys.size > 0 || backgroundWaits.active;
|
|
6927
6971
|
if (next === idleGraceExempt) return;
|
|
6928
6972
|
idleGraceExempt = next;
|
|
6929
6973
|
runningProc?.exemptIdleGrace(next);
|
|
@@ -6952,9 +6996,7 @@ function createToolWatchdog(log, cfg) {
|
|
|
6952
6996
|
}
|
|
6953
6997
|
let oldest = Date.now();
|
|
6954
6998
|
for (const startedAt of openToolSince.values()) if (startedAt < oldest) oldest = startedAt;
|
|
6955
|
-
|
|
6956
|
-
const mins = Math.max(1, Math.round((Date.now() - oldest) / 6e4));
|
|
6957
|
-
log?.(openToolKeys.size > 0 ? "agy tool step still running: " + openToolKeys.size + " open, oldest " + mins + "m (idle budget " + Math.round(longToolIdleMs / 6e4) + "m) — the turn is waiting on agy" : "agy run still working: no new output for " + mins + "m (idle budget " + Math.round(longToolIdleMs / 6e4) + "m) — the turn is waiting on agy; press Stop to cancel");
|
|
6999
|
+
log?.(heartbeatMessage(openToolKeys.size, oldest, lastOutputAt, longToolIdleMs));
|
|
6958
7000
|
}, TOOL_HEARTBEAT_MS);
|
|
6959
7001
|
toolHeartbeat.unref?.();
|
|
6960
7002
|
};
|
|
@@ -6975,6 +7017,7 @@ function createToolWatchdog(log, cfg) {
|
|
|
6975
7017
|
if (ev.kind !== "step") return;
|
|
6976
7018
|
if (ev.stepKind === "tool" && ev.tool !== void 0) {
|
|
6977
7019
|
if (SUBAGENT_COLLAB_TOOLS.has(ev.tool.name)) setAwaitingSubagent(!isStepFailedOrCanceled(ev));
|
|
7020
|
+
backgroundWaits.note(ev.stepKey, ev.tool.name, ev.state, isToolStepCompleted(ev));
|
|
6978
7021
|
if (!isToolStepCompleted(ev)) {
|
|
6979
7022
|
if (!openToolKeys.has(ev.stepKey)) {
|
|
6980
7023
|
openToolKeys.add(ev.stepKey);
|
|
@@ -7002,6 +7045,7 @@ function createToolWatchdog(log, cfg) {
|
|
|
7002
7045
|
awaitingSubagent = false;
|
|
7003
7046
|
openToolKeys.clear();
|
|
7004
7047
|
openToolSince.clear();
|
|
7048
|
+
backgroundWaits.clear();
|
|
7005
7049
|
syncIdleGraceExempt();
|
|
7006
7050
|
}
|
|
7007
7051
|
};
|
|
@@ -7579,6 +7623,51 @@ function defaultPoolDir(home) {
|
|
|
7579
7623
|
return join(effectiveHome, ".dsh", "agy-accounts");
|
|
7580
7624
|
}
|
|
7581
7625
|
//#endregion
|
|
7626
|
+
//#region src/common/quota-bench.ts
|
|
7627
|
+
/** Proactive rotation thresholds: bench accounts at or below these remaining fractions until reset. */
|
|
7628
|
+
const LOW_QUOTA_5H = .1;
|
|
7629
|
+
const LOW_QUOTA_WEEKLY = .05;
|
|
7630
|
+
function isWindowBenched(fraction, resetTime, threshold, now) {
|
|
7631
|
+
if (typeof fraction !== "number" || fraction > threshold) return false;
|
|
7632
|
+
if (!resetTime) return true;
|
|
7633
|
+
const resetMs = Date.parse(resetTime);
|
|
7634
|
+
return Number.isNaN(resetMs) || resetMs > now;
|
|
7635
|
+
}
|
|
7636
|
+
/** True when a family's 5-hour quota window is at or below the proactive bench threshold and not yet reset. */
|
|
7637
|
+
function is5hQuotaBenched(quota, clearedAt, now) {
|
|
7638
|
+
if (!quota) return false;
|
|
7639
|
+
if (clearedAt !== void 0 && (quota.updatedAt ?? 0) <= clearedAt) return false;
|
|
7640
|
+
return isWindowBenched(quota.remainingFraction, quota.resetTime, LOW_QUOTA_5H, now);
|
|
7641
|
+
}
|
|
7642
|
+
/** True when a family's weekly quota window is at or below the proactive bench threshold and not yet reset. */
|
|
7643
|
+
function isWeeklyQuotaBenched(quota, clearedAt, now) {
|
|
7644
|
+
if (!quota) return false;
|
|
7645
|
+
if (clearedAt !== void 0 && (quota.updatedAt ?? 0) <= clearedAt) return false;
|
|
7646
|
+
return isWindowBenched(quota.weeklyFraction, quota.weeklyResetTime, LOW_QUOTA_WEEKLY, now);
|
|
7647
|
+
}
|
|
7648
|
+
/**
|
|
7649
|
+
* True when a family's cached quota snapshot benches the account.
|
|
7650
|
+
*
|
|
7651
|
+
* A user-visible `clearCooldown(..., includeQuotaBench = true)` records the
|
|
7652
|
+
* `updatedAt` of the snapshot it overrode; the gate stays off only while the
|
|
7653
|
+
* cached row is no newer than that stamp, so a fresh poll always re-arms it.
|
|
7654
|
+
*/
|
|
7655
|
+
function isQuotaBenched(acc, family, now) {
|
|
7656
|
+
const quota = acc.quotas?.[family] ?? (family === "argon" ? acc.quotas?.google : void 0);
|
|
7657
|
+
if (!quota) return false;
|
|
7658
|
+
const clearedAt = acc.quotaGateClearedAt?.[family];
|
|
7659
|
+
return is5hQuotaBenched(quota, clearedAt, now) || isWeeklyQuotaBenched(quota, clearedAt, now);
|
|
7660
|
+
}
|
|
7661
|
+
/**
|
|
7662
|
+
* True when the account cannot operate due to auth expiration, web verification
|
|
7663
|
+
* (`VALIDATION_REQUIRED`), or ToS suspension (`TOS_VIOLATION`).
|
|
7664
|
+
*/
|
|
7665
|
+
function isAccountCriticalAuth(acc) {
|
|
7666
|
+
if (acc.authRequired === true) return true;
|
|
7667
|
+
const reason = acc.quotaUnavailable?.reason;
|
|
7668
|
+
return reason === "validation_required" || reason === "tos_violation";
|
|
7669
|
+
}
|
|
7670
|
+
//#endregion
|
|
7582
7671
|
//#region src/common/quota-pacing.ts
|
|
7583
7672
|
const FIVE_HOUR_WINDOW_MS = 18e6;
|
|
7584
7673
|
const WEEKLY_WINDOW_MS = 6048e5;
|
|
@@ -7638,32 +7727,8 @@ function computeQuotaPacing(remainingFraction, resetTimeIso, windowMs, now = Dat
|
|
|
7638
7727
|
burnMultiplier
|
|
7639
7728
|
};
|
|
7640
7729
|
}
|
|
7641
|
-
|
|
7642
|
-
|
|
7643
|
-
*
|
|
7644
|
-
* A user-visible `clearCooldown(..., includeQuotaBench = true)` records the
|
|
7645
|
-
* `updatedAt` of the snapshot it overrode; the gate stays off only while the
|
|
7646
|
-
* cached row is no newer than that stamp, so a fresh poll always re-arms it.
|
|
7647
|
-
*/
|
|
7648
|
-
function isQuotaBenched(acc, family, now) {
|
|
7649
|
-
const quota = acc.quotas?.[family] ?? (family === "argon" ? acc.quotas?.google : void 0);
|
|
7650
|
-
if (!quota) return false;
|
|
7651
|
-
const clearedAt = acc.quotaGateClearedAt?.[family];
|
|
7652
|
-
if (clearedAt !== void 0 && (quota.updatedAt ?? 0) <= clearedAt) return false;
|
|
7653
|
-
if (typeof quota.remainingFraction === "number" && quota.remainingFraction <= .1) {
|
|
7654
|
-
if (quota.resetTime) {
|
|
7655
|
-
const resetMs = Date.parse(quota.resetTime);
|
|
7656
|
-
if (Number.isNaN(resetMs) || resetMs > now) return true;
|
|
7657
|
-
} else return true;
|
|
7658
|
-
}
|
|
7659
|
-
if (typeof quota.weeklyFraction === "number" && quota.weeklyFraction <= .05) {
|
|
7660
|
-
if (quota.weeklyResetTime) {
|
|
7661
|
-
const resetMs = Date.parse(quota.weeklyResetTime);
|
|
7662
|
-
if (Number.isNaN(resetMs) || resetMs > now) return true;
|
|
7663
|
-
} else return true;
|
|
7664
|
-
}
|
|
7665
|
-
return false;
|
|
7666
|
-
}
|
|
7730
|
+
//#endregion
|
|
7731
|
+
//#region src/domain/accounts/selection.ts
|
|
7667
7732
|
/**
|
|
7668
7733
|
* Why this account cannot serve `family` right now, or null when it can.
|
|
7669
7734
|
*
|
|
@@ -7673,7 +7738,7 @@ function isQuotaBenched(acc, family, now) {
|
|
|
7673
7738
|
*/
|
|
7674
7739
|
function explainIneligibility(acc, family, now, pool, model) {
|
|
7675
7740
|
if (!acc.enabled) return "disabled";
|
|
7676
|
-
if (acc
|
|
7741
|
+
if (isAccountCriticalAuth(acc)) return "auth";
|
|
7677
7742
|
if (family === "argon" && !accountHasArgon(acc, pool)) return "unsupported";
|
|
7678
7743
|
if (model && pool?.isModelSupported && !pool.isModelSupported(acc, model)) return "model-unsupported";
|
|
7679
7744
|
const cd = acc.cooldowns?.[family];
|
|
@@ -7930,7 +7995,7 @@ var PoolAdmin = class {
|
|
|
7930
7995
|
setActiveAccount(id, family = "google") {
|
|
7931
7996
|
const data = this.deps.getData();
|
|
7932
7997
|
const acc = this.account(id);
|
|
7933
|
-
if (!acc || !acc
|
|
7998
|
+
if (!acc || !isAccountEligible(acc, family, Date.now(), this.deps.pool)) return false;
|
|
7934
7999
|
if (!data.activeAccountIds) data.activeAccountIds = {};
|
|
7935
8000
|
data.activeAccountIds[family] = id;
|
|
7936
8001
|
data.lastActiveAccountId = id;
|
package/dist/client.js
CHANGED
|
@@ -37,12 +37,13 @@ window.__ModuleLoader__.load({
|
|
|
37
37
|
"status.loading": "正在加载 Antigravity 状态...",
|
|
38
38
|
"status.authRequired": "需重新登录",
|
|
39
39
|
"status.cooldown": "冷却中",
|
|
40
|
+
"status.quotaLimited": "限流中",
|
|
40
41
|
"status.tosBanned": "已封禁 (ToS)",
|
|
41
42
|
"status.validationRequired": "需安全验证",
|
|
42
43
|
"account.setActive": "设为当前使用",
|
|
43
44
|
"account.settingActive": "切换中",
|
|
44
45
|
"account.activeSet": "已切换当前使用账号",
|
|
45
|
-
"account.activeSetFailed": "
|
|
46
|
+
"account.activeSetFailed": "该账号当前不可用(冷却、限流或需重新登录)",
|
|
46
47
|
"account.reauth": "重新登录",
|
|
47
48
|
"account.reauthing": "重登中",
|
|
48
49
|
"account.reauthTitle": "原位重新登录此账号(保留别名、代理与优先级)",
|
|
@@ -70,6 +71,7 @@ window.__ModuleLoader__.load({
|
|
|
70
71
|
"account.cooldown": "部分模型限流中,已自动切换账号",
|
|
71
72
|
"account.clearCooldown": "清除冷却",
|
|
72
73
|
"account.localCooldown": " · 本地冷却中",
|
|
74
|
+
"account.quotaLimitedNote": " · 限流中",
|
|
73
75
|
"account.removed": "已移除账号:{alias}",
|
|
74
76
|
"quota.fiveHour": "5 小时额度",
|
|
75
77
|
"quota.weekly": "周额度",
|
|
@@ -269,12 +271,13 @@ window.__ModuleLoader__.load({
|
|
|
269
271
|
"status.loading": "Loading Antigravity status...",
|
|
270
272
|
"status.authRequired": "Sign in again required",
|
|
271
273
|
"status.cooldown": "Cooldown",
|
|
274
|
+
"status.quotaLimited": "Rate limited",
|
|
272
275
|
"status.tosBanned": "Suspended (ToS)",
|
|
273
276
|
"status.validationRequired": "Verification required",
|
|
274
277
|
"account.setActive": "Set as in use",
|
|
275
278
|
"account.settingActive": "Switching...",
|
|
276
279
|
"account.activeSet": "Active account switched",
|
|
277
|
-
"account.activeSetFailed": "Account not currently eligible (cooldown or auth required)",
|
|
280
|
+
"account.activeSetFailed": "Account not currently eligible (cooldown, quota-limited, or auth required)",
|
|
278
281
|
"account.reauth": "Sign in again",
|
|
279
282
|
"account.reauthing": "Signing in...",
|
|
280
283
|
"account.reauthTitle": "Re-authenticate this account in place (keeps alias, proxy and priority)",
|
|
@@ -302,6 +305,7 @@ window.__ModuleLoader__.load({
|
|
|
302
305
|
"account.cooldown": "Some models are rate-limited; the account was switched automatically",
|
|
303
306
|
"account.clearCooldown": "Clear cooldown",
|
|
304
307
|
"account.localCooldown": " · local cooldown active",
|
|
308
|
+
"account.quotaLimitedNote": " · rate-limited",
|
|
305
309
|
"account.removed": "Account removed: {alias}",
|
|
306
310
|
"quota.fiveHour": "5-hour quota",
|
|
307
311
|
"quota.weekly": "Weekly quota",
|
|
@@ -501,12 +505,13 @@ window.__ModuleLoader__.load({
|
|
|
501
505
|
"status.loading": "Carregando o status do Antigravity...",
|
|
502
506
|
"status.authRequired": "É necessário entrar novamente",
|
|
503
507
|
"status.cooldown": "Em espera",
|
|
508
|
+
"status.quotaLimited": "Limitado",
|
|
504
509
|
"status.tosBanned": "Suspensa (ToS)",
|
|
505
510
|
"status.validationRequired": "Verificação necessária",
|
|
506
511
|
"account.setActive": "Definir como em uso",
|
|
507
512
|
"account.settingActive": "Alternando...",
|
|
508
513
|
"account.activeSet": "Conta em uso alterada",
|
|
509
|
-
"account.activeSetFailed": "Conta não elegível no momento (cooldown ou login necessário)",
|
|
514
|
+
"account.activeSetFailed": "Conta não elegível no momento (cooldown, cota limitada ou login necessário)",
|
|
510
515
|
"account.reauth": "Entrar novamente",
|
|
511
516
|
"account.reauthing": "Entrando...",
|
|
512
517
|
"account.reauthTitle": "Reautenticar esta conta no lugar (mantém apelido, proxy e prioridade)",
|
|
@@ -534,6 +539,7 @@ window.__ModuleLoader__.load({
|
|
|
534
539
|
"account.cooldown": "Alguns modelos estão limitados; a conta foi alternada automaticamente",
|
|
535
540
|
"account.clearCooldown": "Limpar espera",
|
|
536
541
|
"account.localCooldown": " · espera local ativa",
|
|
542
|
+
"account.quotaLimitedNote": " · limitado",
|
|
537
543
|
"account.removed": "Conta removida: {alias}",
|
|
538
544
|
"quota.fiveHour": "Cota de 5 horas",
|
|
539
545
|
"quota.weekly": "Cota semanal",
|
|
@@ -733,12 +739,13 @@ window.__ModuleLoader__.load({
|
|
|
733
739
|
"status.loading": "Cargando el estado de Antigravity...",
|
|
734
740
|
"status.authRequired": "Debe iniciar sesión de nuevo",
|
|
735
741
|
"status.cooldown": "En espera",
|
|
742
|
+
"status.quotaLimited": "Limitado",
|
|
736
743
|
"status.tosBanned": "Suspendida (ToS)",
|
|
737
744
|
"status.validationRequired": "Verificación requerida",
|
|
738
745
|
"account.setActive": "Establecer como en uso",
|
|
739
746
|
"account.settingActive": "Cambiando...",
|
|
740
747
|
"account.activeSet": "Cuenta en uso cambiada",
|
|
741
|
-
"account.activeSetFailed": "Cuenta no elegible ahora (enfriamiento o requiere login)",
|
|
748
|
+
"account.activeSetFailed": "Cuenta no elegible ahora (enfriamiento, límite de cuota o requiere login)",
|
|
742
749
|
"account.reauth": "Iniciar sesión de nuevo",
|
|
743
750
|
"account.reauthing": "Iniciando...",
|
|
744
751
|
"account.reauthTitle": "Reautenticar esta cuenta en su sitio (conserva alias, proxy y prioridad)",
|
|
@@ -766,6 +773,7 @@ window.__ModuleLoader__.load({
|
|
|
766
773
|
"account.cooldown": "Algunos modelos tienen límite de uso; la cuenta se cambió automáticamente",
|
|
767
774
|
"account.clearCooldown": "Borrar espera",
|
|
768
775
|
"account.localCooldown": " · espera local activa",
|
|
776
|
+
"account.quotaLimitedNote": " · limitado",
|
|
769
777
|
"account.removed": "Cuenta eliminada: {alias}",
|
|
770
778
|
"quota.fiveHour": "Cuota de 5 horas",
|
|
771
779
|
"quota.weekly": "Cuota semanal",
|
|
@@ -8348,7 +8356,7 @@ body[data-ds-dark-theme] select.agy-select { color-scheme: dark; }
|
|
|
8348
8356
|
openai: "OpenAI",
|
|
8349
8357
|
unknown: "Other"
|
|
8350
8358
|
};
|
|
8351
|
-
const QUOTA_FAMILIES = [
|
|
8359
|
+
const QUOTA_FAMILIES$1 = [
|
|
8352
8360
|
"google",
|
|
8353
8361
|
"argon",
|
|
8354
8362
|
"anthropic",
|
|
@@ -8393,7 +8401,7 @@ body[data-ds-dark-theme] select.agy-select { color-scheme: dark; }
|
|
|
8393
8401
|
}
|
|
8394
8402
|
function collectAccountQuotaModels(acc) {
|
|
8395
8403
|
const out = [];
|
|
8396
|
-
for (const fam of QUOTA_FAMILIES) {
|
|
8404
|
+
for (const fam of QUOTA_FAMILIES$1) {
|
|
8397
8405
|
const models = acc.quotas?.[fam]?.models;
|
|
8398
8406
|
if (!Array.isArray(models)) continue;
|
|
8399
8407
|
for (const model of models) if (model && typeof model.modelId === "string" && model.modelId.trim() !== "") out.push({
|
|
@@ -8512,6 +8520,70 @@ body[data-ds-dark-theme] select.agy-select { color-scheme: dark; }
|
|
|
8512
8520
|
return projectFromQuotaFallback(acc);
|
|
8513
8521
|
}
|
|
8514
8522
|
//#endregion
|
|
8523
|
+
//#region src/common/quota-bench.ts
|
|
8524
|
+
/** Proactive rotation thresholds: bench accounts at or below these remaining fractions until reset. */
|
|
8525
|
+
const LOW_QUOTA_5H = .1;
|
|
8526
|
+
const LOW_QUOTA_WEEKLY = .05;
|
|
8527
|
+
/** Ordered quota families tracked on an account card. */
|
|
8528
|
+
const QUOTA_FAMILIES = [
|
|
8529
|
+
"google",
|
|
8530
|
+
"argon",
|
|
8531
|
+
"anthropic",
|
|
8532
|
+
"openai"
|
|
8533
|
+
];
|
|
8534
|
+
function isWindowBenched(fraction, resetTime, threshold, now) {
|
|
8535
|
+
if (typeof fraction !== "number" || fraction > threshold) return false;
|
|
8536
|
+
if (!resetTime) return true;
|
|
8537
|
+
const resetMs = Date.parse(resetTime);
|
|
8538
|
+
return Number.isNaN(resetMs) || resetMs > now;
|
|
8539
|
+
}
|
|
8540
|
+
/** True when a family's 5-hour quota window is at or below the proactive bench threshold and not yet reset. */
|
|
8541
|
+
function is5hQuotaBenched(quota, clearedAt, now) {
|
|
8542
|
+
if (!quota) return false;
|
|
8543
|
+
if (clearedAt !== void 0 && (quota.updatedAt ?? 0) <= clearedAt) return false;
|
|
8544
|
+
return isWindowBenched(quota.remainingFraction, quota.resetTime, LOW_QUOTA_5H, now);
|
|
8545
|
+
}
|
|
8546
|
+
/** True when a family's weekly quota window is at or below the proactive bench threshold and not yet reset. */
|
|
8547
|
+
function isWeeklyQuotaBenched(quota, clearedAt, now) {
|
|
8548
|
+
if (!quota) return false;
|
|
8549
|
+
if (clearedAt !== void 0 && (quota.updatedAt ?? 0) <= clearedAt) return false;
|
|
8550
|
+
return isWindowBenched(quota.weeklyFraction, quota.weeklyResetTime, LOW_QUOTA_WEEKLY, now);
|
|
8551
|
+
}
|
|
8552
|
+
/**
|
|
8553
|
+
* True when a family's cached quota snapshot benches the account.
|
|
8554
|
+
*
|
|
8555
|
+
* A user-visible `clearCooldown(..., includeQuotaBench = true)` records the
|
|
8556
|
+
* `updatedAt` of the snapshot it overrode; the gate stays off only while the
|
|
8557
|
+
* cached row is no newer than that stamp, so a fresh poll always re-arms it.
|
|
8558
|
+
*/
|
|
8559
|
+
function isQuotaBenched(acc, family, now) {
|
|
8560
|
+
const quota = acc.quotas?.[family] ?? (family === "argon" ? acc.quotas?.google : void 0);
|
|
8561
|
+
if (!quota) return false;
|
|
8562
|
+
const clearedAt = acc.quotaGateClearedAt?.[family];
|
|
8563
|
+
return is5hQuotaBenched(quota, clearedAt, now) || isWeeklyQuotaBenched(quota, clearedAt, now);
|
|
8564
|
+
}
|
|
8565
|
+
/** True when any family on the account has an active local 429 cooldown timer. */
|
|
8566
|
+
function accountHasActiveCooldown(acc, now) {
|
|
8567
|
+
return Object.values(acc.cooldowns ?? {}).some((cd) => Boolean(cd && cd.cooldownUntil > now));
|
|
8568
|
+
}
|
|
8569
|
+
/**
|
|
8570
|
+
* True when any family reported on the account is benched by its quota snapshot.
|
|
8571
|
+
* Skips the synthesized `argon -> google` fallback when the account has no dedicated
|
|
8572
|
+
* `quotas.argon` row, since `google` itself already reflects that shared bucket.
|
|
8573
|
+
*/
|
|
8574
|
+
function accountHasQuotaBench(acc, now) {
|
|
8575
|
+
return QUOTA_FAMILIES.some((fam) => (fam !== "argon" || acc.quotas?.argon !== void 0) && isQuotaBenched(acc, fam, now));
|
|
8576
|
+
}
|
|
8577
|
+
/**
|
|
8578
|
+
* True when the account cannot operate due to auth expiration, web verification
|
|
8579
|
+
* (`VALIDATION_REQUIRED`), or ToS suspension (`TOS_VIOLATION`).
|
|
8580
|
+
*/
|
|
8581
|
+
function isAccountCriticalAuth(acc) {
|
|
8582
|
+
if (acc.authRequired === true) return true;
|
|
8583
|
+
const reason = acc.quotaUnavailable?.reason;
|
|
8584
|
+
return reason === "validation_required" || reason === "tos_violation";
|
|
8585
|
+
}
|
|
8586
|
+
//#endregion
|
|
8515
8587
|
//#region src/common/quota-pacing.ts
|
|
8516
8588
|
/**
|
|
8517
8589
|
* Compare remaining quota fraction against remaining reset window fraction.
|
|
@@ -8734,20 +8806,25 @@ body[data-ds-dark-theme] select.agy-select { color-scheme: dark; }
|
|
|
8734
8806
|
function renderFamilyQuotaBar(t, label, familyKey, acc, isRefreshing = false) {
|
|
8735
8807
|
const info = acc.quotas[familyKey];
|
|
8736
8808
|
const cd = acc.cooldowns[familyKey];
|
|
8737
|
-
const
|
|
8809
|
+
const now = Date.now();
|
|
8810
|
+
const inCooldown = Boolean(cd && cd.cooldownUntil > now);
|
|
8811
|
+
const clearedAt = acc.quotaGateClearedAt?.[familyKey];
|
|
8812
|
+
const benched5h = !inCooldown && is5hQuotaBenched(info, clearedAt, now);
|
|
8813
|
+
const benchedWeekly = !inCooldown && isWeeklyQuotaBenched(info, clearedAt, now);
|
|
8738
8814
|
const has5h = typeof info?.remainingFraction === "number" && Number.isFinite(info.remainingFraction);
|
|
8739
8815
|
const pct5h = has5h ? Math.max(0, Math.min(100, Math.round(info.remainingFraction * 100))) : -1;
|
|
8740
|
-
const
|
|
8816
|
+
const cdNote5h = inCooldown ? t("account.localCooldown") : benched5h ? t("account.quotaLimitedNote") : "";
|
|
8741
8817
|
const w5h = formatQuotaWindow(t, info?.resetTime);
|
|
8742
8818
|
const expiredFull5h = w5h.expired && has5h && pct5h >= 100;
|
|
8743
8819
|
const hasWeekly = typeof info?.weeklyFraction === "number" && Number.isFinite(info.weeklyFraction);
|
|
8744
8820
|
const pctWeekly = hasWeekly ? Math.max(0, Math.min(100, Math.round(info.weeklyFraction * 100))) : -1;
|
|
8821
|
+
const cdNoteWeekly = benchedWeekly ? t("account.quotaLimitedNote") : "";
|
|
8745
8822
|
const wWeekly = formatQuotaWindow(t, info?.weeklyResetTime);
|
|
8746
8823
|
const expiredFullWeekly = wWeekly.expired && hasWeekly && pctWeekly >= 100;
|
|
8747
8824
|
const c5h = getQuotaColors(pct5h);
|
|
8748
8825
|
const cWeekly = getQuotaColors(pctWeekly);
|
|
8749
|
-
const note5h = w5h.resetText ? w5h.resetText +
|
|
8750
|
-
const noteWeekly = wWeekly.resetText ? wWeekly.resetText : expiredFullWeekly ? t("quota.windowReset") : "";
|
|
8826
|
+
const note5h = w5h.resetText ? w5h.resetText + cdNote5h : expiredFull5h ? t("quota.windowReset") + cdNote5h : cdNote5h.replace(/^ · /, "");
|
|
8827
|
+
const noteWeekly = wWeekly.resetText ? wWeekly.resetText + cdNoteWeekly : expiredFullWeekly ? t("quota.windowReset") + cdNoteWeekly : cdNoteWeekly.replace(/^ · /, "");
|
|
8751
8828
|
return h("div", { style: {
|
|
8752
8829
|
margin: "4px 0",
|
|
8753
8830
|
padding: "5px 8px",
|
|
@@ -8785,7 +8862,8 @@ body[data-ds-dark-theme] select.agy-select { color-scheme: dark; }
|
|
|
8785
8862
|
function renderQuotaUnavailableNote(t, acc) {
|
|
8786
8863
|
const state = acc.quotaUnavailable;
|
|
8787
8864
|
if (!state) return null;
|
|
8788
|
-
const
|
|
8865
|
+
const stamps = Object.values(acc.quotas).map((q) => q?.updatedAt ?? 0).filter((ts) => ts > 0);
|
|
8866
|
+
const oldest = stamps.length > 0 ? Math.min(...stamps) : 0;
|
|
8789
8867
|
const reason = t(`quota.unavailable.${state.reason}`);
|
|
8790
8868
|
const isCritical = state.reason === "validation_required" || state.reason === "tos_violation";
|
|
8791
8869
|
const toneText = isCritical ? "var(--agy-quota-low-text)" : "var(--agy-quota-med-text)";
|
|
@@ -8817,10 +8895,10 @@ body[data-ds-dark-theme] select.agy-select { color-scheme: dark; }
|
|
|
8817
8895
|
textDecoration: "underline",
|
|
8818
8896
|
fontWeight: 700
|
|
8819
8897
|
}
|
|
8820
|
-
}, t("quota.verifyNow")) : null,
|
|
8898
|
+
}, t("quota.verifyNow")) : null, oldest > 0 ? h("span", { style: {
|
|
8821
8899
|
fontWeight: 500,
|
|
8822
8900
|
opacity: .85
|
|
8823
|
-
} }, t("quota.unavailableSince", { time: formatSnapshotStamp(
|
|
8901
|
+
} }, t("quota.unavailableSince", { time: formatSnapshotStamp(oldest) })) : null);
|
|
8824
8902
|
}
|
|
8825
8903
|
//#endregion
|
|
8826
8904
|
//#region src/client/sections/AccountsPanel.ts
|
|
@@ -8830,12 +8908,17 @@ body[data-ds-dark-theme] select.agy-select { color-scheme: dark; }
|
|
|
8830
8908
|
const renderQuotaBar = (label, familyKey, acc) => renderFamilyQuotaBar(t, label, familyKey, acc, loadingAction === "refresh:all" || loadingAction === `refresh:${acc.id}` || quotaRefreshing.includes(acc.id));
|
|
8831
8909
|
const authoritativeActiveId = pool?.activeAccountId ?? pool?.lastActiveAccountId ?? pool?.activeAccountIds?.google ?? pool?.primaryAccountId;
|
|
8832
8910
|
const activeAccountId = optimisticActiveId ?? authoritativeActiveId;
|
|
8911
|
+
const now = Date.now();
|
|
8833
8912
|
return accounts.map((acc) => {
|
|
8834
8913
|
const isPrimary = acc.id === pool?.primaryAccountId;
|
|
8835
|
-
const hasCooldown =
|
|
8836
|
-
const
|
|
8914
|
+
const hasCooldown = accountHasActiveCooldown(acc, now);
|
|
8915
|
+
const hasQuotaBench = accountHasQuotaBench(acc, now);
|
|
8916
|
+
const isRateLimited = hasCooldown || hasQuotaBench;
|
|
8917
|
+
const isAuthRequired = isAccountCriticalAuth(acc);
|
|
8918
|
+
const isGoogleCooldown = Boolean(acc.cooldowns?.google && acc.cooldowns.google.cooldownUntil > now);
|
|
8919
|
+
const isGoogleEligible = acc.enabled && !isAuthRequired && !isGoogleCooldown && !isQuotaBenched(acc, "google", now);
|
|
8837
8920
|
const isInUse = Boolean(acc.enabled && !isAuthRequired && activeAccountId !== void 0 && activeAccountId === acc.id);
|
|
8838
|
-
const dotColor = !acc.enabled ? "#64748b" : isAuthRequired ? "#ef4444" :
|
|
8921
|
+
const dotColor = !acc.enabled ? "#64748b" : isAuthRequired ? "#ef4444" : isRateLimited ? "#f59e0b" : "#10b981";
|
|
8839
8922
|
const isEditingProxy = editingProxyId === acc.id;
|
|
8840
8923
|
const isExpanded = expandedModels[acc.id] ?? false;
|
|
8841
8924
|
const accIndex = accounts.indexOf(acc);
|
|
@@ -8861,6 +8944,8 @@ body[data-ds-dark-theme] select.agy-select { color-scheme: dark; }
|
|
|
8861
8944
|
isPrimary,
|
|
8862
8945
|
isAuthRequired,
|
|
8863
8946
|
hasCooldown,
|
|
8947
|
+
hasQuotaBench,
|
|
8948
|
+
isGoogleEligible,
|
|
8864
8949
|
isInUse,
|
|
8865
8950
|
dotColor,
|
|
8866
8951
|
isEditingProxy,
|
|
@@ -8884,7 +8969,7 @@ body[data-ds-dark-theme] select.agy-select { color-scheme: dark; }
|
|
|
8884
8969
|
margin: "4px 0 2px 0"
|
|
8885
8970
|
},
|
|
8886
8971
|
onClick: () => toggleExpand(acc.id)
|
|
8887
|
-
}, uiIcon(isExpanded ? "chevronUp" : "chevronDown", 10), h("span", null, isExpanded ? t("account.collapseOthers") : t("account.expandOthers"))), isExpanded ? h("div", { key: "expanded-details" }, renderQuotaBar("Claude", "anthropic", acc), renderQuotaBar("GPT-OSS", "openai", acc), childModels.length > 0 ? renderChildModels(t, childModels) : null) : null),
|
|
8972
|
+
}, uiIcon(isExpanded ? "chevronUp" : "chevronDown", 10), h("span", null, isExpanded ? t("account.collapseOthers") : t("account.expandOthers"))), isExpanded ? h("div", { key: "expanded-details" }, renderQuotaBar("Claude", "anthropic", acc), renderQuotaBar("GPT-OSS", "openai", acc), childModels.length > 0 ? renderChildModels(t, childModels) : null) : null), isRateLimited ? renderCooldownBanner(t, acc, loadingAction, accountActionBusy, handlers) : null, isEditingProxy ? renderProxyEditor(t, acc, pool, proxyInputs, setProxyInputs, setEditingProxyId, loadingAction, accountActionBusy, handlers) : null);
|
|
8888
8973
|
});
|
|
8889
8974
|
}
|
|
8890
8975
|
function extractActionUrl(text) {
|
|
@@ -8893,11 +8978,12 @@ body[data-ds-dark-theme] select.agy-select { color-scheme: dark; }
|
|
|
8893
8978
|
return m ? m[0] : void 0;
|
|
8894
8979
|
}
|
|
8895
8980
|
function renderStatusBadges(t, acc, ctx) {
|
|
8896
|
-
const { isAuthRequired, hasCooldown, isInUse, pool } = ctx;
|
|
8897
|
-
const
|
|
8898
|
-
const
|
|
8981
|
+
const { isAuthRequired, hasCooldown, hasQuotaBench, isInUse, pool } = ctx;
|
|
8982
|
+
const unavailReason = acc.quotaUnavailable?.reason;
|
|
8983
|
+
const isTos = isAuthRequired && (unavailReason === "tos_violation" || /\bTOS_VIOLATION\b|violation of Terms of Service/i.test(acc.authError ?? ""));
|
|
8984
|
+
const isValidation = isAuthRequired && !isTos && (unavailReason === "validation_required" || /\bVALIDATION_REQUIRED\b/i.test(acc.authError ?? ""));
|
|
8899
8985
|
const authLabel = isTos ? t("status.tosBanned") : isValidation ? t("status.validationRequired") : t("status.authRequired");
|
|
8900
|
-
const actionUrl = isAuthRequired ? extractActionUrl(acc.authError) : void 0;
|
|
8986
|
+
const actionUrl = isAuthRequired ? extractActionUrl(acc.authError) ?? (typeof acc.quotaUnavailable?.actionUrl === "string" && acc.quotaUnavailable.actionUrl.startsWith("https://") ? acc.quotaUnavailable.actionUrl : void 0) : void 0;
|
|
8901
8987
|
return [
|
|
8902
8988
|
acc.email ? h("span", {
|
|
8903
8989
|
style: {
|
|
@@ -8963,7 +9049,7 @@ body[data-ds-dark-theme] select.agy-select { color-scheme: dark; }
|
|
|
8963
9049
|
textDecoration: actionUrl ? "underline" : "none"
|
|
8964
9050
|
}
|
|
8965
9051
|
}, uiIcon("alert", 10, "#ef4444"), authLabel) : null,
|
|
8966
|
-
hasCooldown ? h("span", { style: {
|
|
9052
|
+
hasCooldown || hasQuotaBench ? h("span", { style: {
|
|
8967
9053
|
...S.badgeTag,
|
|
8968
9054
|
background: "rgba(245, 158, 11, 0.15)",
|
|
8969
9055
|
color: "#f59e0b",
|
|
@@ -8974,7 +9060,7 @@ body[data-ds-dark-theme] select.agy-select { color-scheme: dark; }
|
|
|
8974
9060
|
fontWeight: 700,
|
|
8975
9061
|
whiteSpace: "nowrap",
|
|
8976
9062
|
flexShrink: 0
|
|
8977
|
-
} }, uiIcon("alert", 10, "#f59e0b"), t("status.cooldown")) : null,
|
|
9063
|
+
} }, uiIcon("alert", 10, "#f59e0b"), hasCooldown ? t("status.cooldown") : t("status.quotaLimited")) : null,
|
|
8978
9064
|
!acc.enabled ? h("span", {
|
|
8979
9065
|
style: {
|
|
8980
9066
|
...S.badgeTag,
|
|
@@ -9081,7 +9167,7 @@ body[data-ds-dark-theme] select.agy-select { color-scheme: dark; }
|
|
|
9081
9167
|
}, ...badges);
|
|
9082
9168
|
}
|
|
9083
9169
|
function renderCardHeader(t, acc, ctx) {
|
|
9084
|
-
const { isEditingProxy, isInUse, displayAlias, accounts, loadingAction, accountActionBusy, handlers, setEditingProxyId } = ctx;
|
|
9170
|
+
const { isEditingProxy, isAuthRequired, isInUse, isGoogleEligible, displayAlias, accounts, loadingAction, accountActionBusy, handlers, setEditingProxyId } = ctx;
|
|
9085
9171
|
return h("div", {
|
|
9086
9172
|
className: "agy-card-header",
|
|
9087
9173
|
style: {
|
|
@@ -9102,7 +9188,9 @@ body[data-ds-dark-theme] select.agy-select { color-scheme: dark; }
|
|
|
9102
9188
|
}
|
|
9103
9189
|
}, renderHeaderBadges(t, acc, ctx), renderActionButtons(t, acc, {
|
|
9104
9190
|
isEditingProxy,
|
|
9191
|
+
isAuthRequired,
|
|
9105
9192
|
isInUse,
|
|
9193
|
+
isGoogleEligible,
|
|
9106
9194
|
displayAlias,
|
|
9107
9195
|
showRemove: accounts.length > 1,
|
|
9108
9196
|
loadingAction,
|
|
@@ -9112,7 +9200,7 @@ body[data-ds-dark-theme] select.agy-select { color-scheme: dark; }
|
|
|
9112
9200
|
})), renderMetaRow(t, acc, ctx));
|
|
9113
9201
|
}
|
|
9114
9202
|
function renderActionButtons(t, acc, ctx) {
|
|
9115
|
-
const { isEditingProxy, isInUse, displayAlias, showRemove, loadingAction, accountActionBusy, handlers, setEditingProxyId } = ctx;
|
|
9203
|
+
const { isEditingProxy, isAuthRequired, isInUse, isGoogleEligible, displayAlias, showRemove, loadingAction, accountActionBusy, handlers, setEditingProxyId } = ctx;
|
|
9116
9204
|
return h("div", {
|
|
9117
9205
|
className: "agy-card-actions",
|
|
9118
9206
|
style: {
|
|
@@ -9148,7 +9236,7 @@ body[data-ds-dark-theme] select.agy-select { color-scheme: dark; }
|
|
|
9148
9236
|
title: t("account.syncTitle"),
|
|
9149
9237
|
disabled: accountActionBusy(acc, "refresh"),
|
|
9150
9238
|
onClick: () => void handlers.refreshQuota(acc.id)
|
|
9151
|
-
}, ...loadingAction === `refresh:${acc.id}` ? [Spinner(), t("account.syncing")] : [uiIcon("refresh", 10), ` ${t("account.sync")}`]),
|
|
9239
|
+
}, ...loadingAction === `refresh:${acc.id}` ? [Spinner(), t("account.syncing")] : [uiIcon("refresh", 10), ` ${t("account.sync")}`]), isAuthRequired && handlers.beginReauth ? h(Button, {
|
|
9152
9240
|
variant: "primary",
|
|
9153
9241
|
size: "sm",
|
|
9154
9242
|
className: "agy-btn",
|
|
@@ -9161,7 +9249,7 @@ body[data-ds-dark-theme] select.agy-select { color-scheme: dark; }
|
|
|
9161
9249
|
title: t("account.reauthTitle"),
|
|
9162
9250
|
disabled: accountActionBusy(acc, "reauth"),
|
|
9163
9251
|
onClick: () => void handlers.beginReauth(acc)
|
|
9164
|
-
}, ...loadingAction === `reauth:${acc.id}` ? [Spinner(), t("account.reauthing")] : [uiIcon("externalLink", 10, "#ffffff"), ` ${t("account.reauth")}`]) : null, acc.enabled && !
|
|
9252
|
+
}, ...loadingAction === `reauth:${acc.id}` ? [Spinner(), t("account.reauthing")] : [uiIcon("externalLink", 10, "#ffffff"), ` ${t("account.reauth")}`]) : null, acc.enabled && !isAuthRequired ? h(Button, {
|
|
9165
9253
|
variant: "default",
|
|
9166
9254
|
size: "sm",
|
|
9167
9255
|
className: "agy-btn",
|
|
@@ -9175,7 +9263,7 @@ body[data-ds-dark-theme] select.agy-select { color-scheme: dark; }
|
|
|
9175
9263
|
title: t("account.warmupTitle"),
|
|
9176
9264
|
disabled: accountActionBusy(acc, "warmup"),
|
|
9177
9265
|
onClick: () => void handlers.warmupAccount(acc.id)
|
|
9178
|
-
}, ...loadingAction === `warmup:${acc.id}` ? [Spinner(), t("account.warmingUp")] : [uiIcon("flame", 10, "#f97316"), ` ${t("account.warmup")}`]) : null,
|
|
9266
|
+
}, ...loadingAction === `warmup:${acc.id}` ? [Spinner(), t("account.warmingUp")] : [uiIcon("flame", 10, "#f97316"), ` ${t("account.warmup")}`]) : null, isGoogleEligible && !isInUse ? h(Button, {
|
|
9179
9267
|
variant: "default",
|
|
9180
9268
|
size: "sm",
|
|
9181
9269
|
className: "agy-btn",
|
|
@@ -10101,16 +10189,17 @@ body[data-ds-dark-theme] select.agy-select { color-scheme: dark; }
|
|
|
10101
10189
|
const accounts = pool?.accounts ?? [];
|
|
10102
10190
|
const rawActiveId = pool?.activeAccountId ?? pool?.lastActiveAccountId ?? pool?.activeAccountIds?.google ?? pool?.primaryAccountId;
|
|
10103
10191
|
const activeAcc = rawActiveId !== void 0 ? accounts.find((a) => a.id === rawActiveId) : void 0;
|
|
10104
|
-
const
|
|
10105
|
-
const
|
|
10106
|
-
const
|
|
10192
|
+
const now = Date.now();
|
|
10193
|
+
const activeAuthRequired = activeAcc ? isAccountCriticalAuth(activeAcc) : false;
|
|
10194
|
+
const activeHasCooldown = activeAcc ? accountHasActiveCooldown(activeAcc, now) || accountHasQuotaBench(activeAcc, now) : false;
|
|
10195
|
+
const allInCooldown = accounts.length > 0 && accounts.every((a) => !a.enabled || isAccountCriticalAuth(a) || accountHasActiveCooldown(a, now) || accountHasQuotaBench(a, now));
|
|
10107
10196
|
const isAuthed = status?.auth?.phase === "ok" || accounts.length > 0;
|
|
10108
10197
|
const color = status === null ? "#64748b" : status.dormantReason ? "#f59e0b" : allInCooldown ? "#f59e0b" : activeAuthRequired ? "#ef4444" : activeHasCooldown ? "#f59e0b" : isAuthed ? "#10b981" : "#f59e0b";
|
|
10109
10198
|
const legacyDefault = activeAcc && activeAcc.defaultAlias === void 0 && activeAcc.systemHome && activeAcc.alias === "主账号 (系统登录)";
|
|
10110
10199
|
const displayAlias = activeAcc ? activeAcc.defaultAlias || legacyDefault ? activeAcc.systemHome ? t("account.defaultAlias") : t("account.aliasDefault", { number: accounts.indexOf(activeAcc) + 1 }) : activeAcc.alias : "";
|
|
10111
10200
|
const gFrac = activeAcc?.quotas?.google?.remainingFraction;
|
|
10112
10201
|
const activePct = typeof gFrac === "number" && Number.isFinite(gFrac) ? Math.max(0, Math.min(100, Math.round(gFrac * 100))) : null;
|
|
10113
|
-
const activeEligible = activeAcc !== void 0 && activeAcc.enabled && !
|
|
10202
|
+
const activeEligible = activeAcc !== void 0 && activeAcc.enabled && !activeAuthRequired;
|
|
10114
10203
|
const activeDetail = activeAcc !== void 0 && activeEligible ? ` · ${t("status.inUse")}: ${displayAlias}${activeAcc.email ? ` (${activeAcc.email})` : ""}${activePct !== null ? ` · ${activePct}%` : ""}` : "";
|
|
10115
10204
|
const badgeTitle = status === null ? t("header.badgeLoading") : `${t("header.badgeTitle", { count: accounts.length })}${activeDetail}`;
|
|
10116
10205
|
const buttonLabel = status === null ? "AGY" : displayAlias ? `AGY · ${displayAlias}` : `AGY (${accounts.length})`;
|
package/dist/index.js
CHANGED
|
@@ -1411,6 +1411,66 @@ function defaultPoolDir(home) {
|
|
|
1411
1411
|
return join(effectiveHome, ".dsh", "agy-accounts");
|
|
1412
1412
|
}
|
|
1413
1413
|
//#endregion
|
|
1414
|
+
//#region src/common/quota-bench.ts
|
|
1415
|
+
/** Proactive rotation thresholds: bench accounts at or below these remaining fractions until reset. */
|
|
1416
|
+
const LOW_QUOTA_5H = .1;
|
|
1417
|
+
const LOW_QUOTA_WEEKLY = .05;
|
|
1418
|
+
/** Ordered quota families tracked on an account card. */
|
|
1419
|
+
const QUOTA_FAMILIES = [
|
|
1420
|
+
"google",
|
|
1421
|
+
"argon",
|
|
1422
|
+
"anthropic",
|
|
1423
|
+
"openai"
|
|
1424
|
+
];
|
|
1425
|
+
function isWindowBenched(fraction, resetTime, threshold, now) {
|
|
1426
|
+
if (typeof fraction !== "number" || fraction > threshold) return false;
|
|
1427
|
+
if (!resetTime) return true;
|
|
1428
|
+
const resetMs = Date.parse(resetTime);
|
|
1429
|
+
return Number.isNaN(resetMs) || resetMs > now;
|
|
1430
|
+
}
|
|
1431
|
+
/** True when a family's 5-hour quota window is at or below the proactive bench threshold and not yet reset. */
|
|
1432
|
+
function is5hQuotaBenched(quota, clearedAt, now) {
|
|
1433
|
+
if (!quota) return false;
|
|
1434
|
+
if (clearedAt !== void 0 && (quota.updatedAt ?? 0) <= clearedAt) return false;
|
|
1435
|
+
return isWindowBenched(quota.remainingFraction, quota.resetTime, LOW_QUOTA_5H, now);
|
|
1436
|
+
}
|
|
1437
|
+
/** True when a family's weekly quota window is at or below the proactive bench threshold and not yet reset. */
|
|
1438
|
+
function isWeeklyQuotaBenched(quota, clearedAt, now) {
|
|
1439
|
+
if (!quota) return false;
|
|
1440
|
+
if (clearedAt !== void 0 && (quota.updatedAt ?? 0) <= clearedAt) return false;
|
|
1441
|
+
return isWindowBenched(quota.weeklyFraction, quota.weeklyResetTime, LOW_QUOTA_WEEKLY, now);
|
|
1442
|
+
}
|
|
1443
|
+
/**
|
|
1444
|
+
* True when a family's cached quota snapshot benches the account.
|
|
1445
|
+
*
|
|
1446
|
+
* A user-visible `clearCooldown(..., includeQuotaBench = true)` records the
|
|
1447
|
+
* `updatedAt` of the snapshot it overrode; the gate stays off only while the
|
|
1448
|
+
* cached row is no newer than that stamp, so a fresh poll always re-arms it.
|
|
1449
|
+
*/
|
|
1450
|
+
function isQuotaBenched(acc, family, now) {
|
|
1451
|
+
const quota = acc.quotas?.[family] ?? (family === "argon" ? acc.quotas?.google : void 0);
|
|
1452
|
+
if (!quota) return false;
|
|
1453
|
+
const clearedAt = acc.quotaGateClearedAt?.[family];
|
|
1454
|
+
return is5hQuotaBenched(quota, clearedAt, now) || isWeeklyQuotaBenched(quota, clearedAt, now);
|
|
1455
|
+
}
|
|
1456
|
+
/**
|
|
1457
|
+
* True when any family reported on the account is benched by its quota snapshot.
|
|
1458
|
+
* Skips the synthesized `argon -> google` fallback when the account has no dedicated
|
|
1459
|
+
* `quotas.argon` row, since `google` itself already reflects that shared bucket.
|
|
1460
|
+
*/
|
|
1461
|
+
function accountHasQuotaBench(acc, now) {
|
|
1462
|
+
return QUOTA_FAMILIES.some((fam) => (fam !== "argon" || acc.quotas?.argon !== void 0) && isQuotaBenched(acc, fam, now));
|
|
1463
|
+
}
|
|
1464
|
+
/**
|
|
1465
|
+
* True when the account cannot operate due to auth expiration, web verification
|
|
1466
|
+
* (`VALIDATION_REQUIRED`), or ToS suspension (`TOS_VIOLATION`).
|
|
1467
|
+
*/
|
|
1468
|
+
function isAccountCriticalAuth(acc) {
|
|
1469
|
+
if (acc.authRequired === true) return true;
|
|
1470
|
+
const reason = acc.quotaUnavailable?.reason;
|
|
1471
|
+
return reason === "validation_required" || reason === "tos_violation";
|
|
1472
|
+
}
|
|
1473
|
+
//#endregion
|
|
1414
1474
|
//#region src/common/quota-pacing.ts
|
|
1415
1475
|
const FIVE_HOUR_WINDOW_MS = 18e6;
|
|
1416
1476
|
const WEEKLY_WINDOW_MS = 6048e5;
|
|
@@ -1470,32 +1530,8 @@ function computeQuotaPacing(remainingFraction, resetTimeIso, windowMs, now = Dat
|
|
|
1470
1530
|
burnMultiplier
|
|
1471
1531
|
};
|
|
1472
1532
|
}
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
*
|
|
1476
|
-
* A user-visible `clearCooldown(..., includeQuotaBench = true)` records the
|
|
1477
|
-
* `updatedAt` of the snapshot it overrode; the gate stays off only while the
|
|
1478
|
-
* cached row is no newer than that stamp, so a fresh poll always re-arms it.
|
|
1479
|
-
*/
|
|
1480
|
-
function isQuotaBenched(acc, family, now) {
|
|
1481
|
-
const quota = acc.quotas?.[family] ?? (family === "argon" ? acc.quotas?.google : void 0);
|
|
1482
|
-
if (!quota) return false;
|
|
1483
|
-
const clearedAt = acc.quotaGateClearedAt?.[family];
|
|
1484
|
-
if (clearedAt !== void 0 && (quota.updatedAt ?? 0) <= clearedAt) return false;
|
|
1485
|
-
if (typeof quota.remainingFraction === "number" && quota.remainingFraction <= .1) {
|
|
1486
|
-
if (quota.resetTime) {
|
|
1487
|
-
const resetMs = Date.parse(quota.resetTime);
|
|
1488
|
-
if (Number.isNaN(resetMs) || resetMs > now) return true;
|
|
1489
|
-
} else return true;
|
|
1490
|
-
}
|
|
1491
|
-
if (typeof quota.weeklyFraction === "number" && quota.weeklyFraction <= .05) {
|
|
1492
|
-
if (quota.weeklyResetTime) {
|
|
1493
|
-
const resetMs = Date.parse(quota.weeklyResetTime);
|
|
1494
|
-
if (Number.isNaN(resetMs) || resetMs > now) return true;
|
|
1495
|
-
} else return true;
|
|
1496
|
-
}
|
|
1497
|
-
return false;
|
|
1498
|
-
}
|
|
1533
|
+
//#endregion
|
|
1534
|
+
//#region src/domain/accounts/selection.ts
|
|
1499
1535
|
/**
|
|
1500
1536
|
* Why this account cannot serve `family` right now, or null when it can.
|
|
1501
1537
|
*
|
|
@@ -1505,7 +1541,7 @@ function isQuotaBenched(acc, family, now) {
|
|
|
1505
1541
|
*/
|
|
1506
1542
|
function explainIneligibility(acc, family, now, pool, model) {
|
|
1507
1543
|
if (!acc.enabled) return "disabled";
|
|
1508
|
-
if (acc
|
|
1544
|
+
if (isAccountCriticalAuth(acc)) return "auth";
|
|
1509
1545
|
if (family === "argon" && !accountHasArgon(acc, pool)) return "unsupported";
|
|
1510
1546
|
if (model && pool?.isModelSupported && !pool.isModelSupported(acc, model)) return "model-unsupported";
|
|
1511
1547
|
const cd = acc.cooldowns?.[family];
|
|
@@ -1762,7 +1798,7 @@ var PoolAdmin = class {
|
|
|
1762
1798
|
setActiveAccount(id, family = "google") {
|
|
1763
1799
|
const data = this.deps.getData();
|
|
1764
1800
|
const acc = this.account(id);
|
|
1765
|
-
if (!acc || !acc
|
|
1801
|
+
if (!acc || !isAccountEligible(acc, family, Date.now(), this.deps.pool)) return false;
|
|
1766
1802
|
if (!data.activeAccountIds) data.activeAccountIds = {};
|
|
1767
1803
|
data.activeAccountIds[family] = id;
|
|
1768
1804
|
data.lastActiveAccountId = id;
|
|
@@ -34308,6 +34344,19 @@ const SUBAGENT_COLLAB_TOOLS = /* @__PURE__ */ new Set([
|
|
|
34308
34344
|
"run_workflow",
|
|
34309
34345
|
"swarm"
|
|
34310
34346
|
]);
|
|
34347
|
+
/**
|
|
34348
|
+
* Tools that hand work to the BACKGROUND and return `state === 'RUNNING'` with a
|
|
34349
|
+
* DETERMINISTIC finish: a scheduled wake-up reports back when its timer fires.
|
|
34350
|
+
* The root agent idles until then, so the reaper stays suspended for the wait
|
|
34351
|
+
* (issue #148).
|
|
34352
|
+
*
|
|
34353
|
+
* `run_command` is deliberately NOT here: agy also uses it for daemons (dev
|
|
34354
|
+
* servers, watchers) that never report back, and reclaiming those is exactly
|
|
34355
|
+
* what #119 exists for. A backgrounded BUILD is protected by agy's own count
|
|
34356
|
+
* instead — `waiting for N background task(s)` with N > 0 keeps the reaper
|
|
34357
|
+
* disarmed (see idle-line.ts).
|
|
34358
|
+
*/
|
|
34359
|
+
const BACKGROUND_WAIT_TOOLS = /* @__PURE__ */ new Set(["schedule"]);
|
|
34311
34360
|
function resolveWatchdogBudgets(cfg) {
|
|
34312
34361
|
const longToolIdleMinutes = cfg.longToolIdleMinutes > 0 ? cfg.longToolIdleMinutes : 0;
|
|
34313
34362
|
let printTimeoutMinutes = Math.max(longToolIdleMinutes > 0 ? longToolIdleMinutes : Math.ceil(cfg.timeoutMs / 6e4), Math.ceil(cfg.timeoutMs / 6e4));
|
|
@@ -34332,6 +34381,36 @@ function isToolStepCompleted(ev) {
|
|
|
34332
34381
|
* build, …) — issue #33 — so the watchdog raises the idle budget; bare
|
|
34333
34382
|
* generation gets a bounded floor so a hung SSE stream can fail and rotate.
|
|
34334
34383
|
*/
|
|
34384
|
+
/**
|
|
34385
|
+
* Tracks backgrounded hand-offs whose completion agy will report later
|
|
34386
|
+
* (`schedule`). They hold the idle-grace exemption on their own: the mapper
|
|
34387
|
+
* treats `RUNNING` as a completed hand-off, so they never appear in
|
|
34388
|
+
* `openToolKeys`, yet the root agent is still waiting on them (issue #148).
|
|
34389
|
+
*/
|
|
34390
|
+
function createBackgroundWaits(onChange) {
|
|
34391
|
+
const keys = /* @__PURE__ */ new Set();
|
|
34392
|
+
return {
|
|
34393
|
+
note(stepKey, name, state, completed) {
|
|
34394
|
+
if (!BACKGROUND_WAIT_TOOLS.has(name)) return;
|
|
34395
|
+
const before = keys.size;
|
|
34396
|
+
if (state === "RUNNING") keys.add(stepKey);
|
|
34397
|
+
else if (completed) keys.delete(stepKey);
|
|
34398
|
+
if (keys.size !== before) onChange();
|
|
34399
|
+
},
|
|
34400
|
+
get active() {
|
|
34401
|
+
return keys.size > 0;
|
|
34402
|
+
},
|
|
34403
|
+
clear() {
|
|
34404
|
+
keys.clear();
|
|
34405
|
+
}
|
|
34406
|
+
};
|
|
34407
|
+
}
|
|
34408
|
+
/** Heartbeat log line: what the turn is waiting on and for how long. */
|
|
34409
|
+
function heartbeatMessage(openCount, oldestAt, sinceOutput, longToolIdleMs) {
|
|
34410
|
+
const mins = Math.max(1, Math.round((Date.now() - (openCount === 0 && sinceOutput > 0 ? sinceOutput : oldestAt)) / 6e4));
|
|
34411
|
+
const budget = Math.round(longToolIdleMs / 6e4) + "m";
|
|
34412
|
+
return openCount > 0 ? "agy tool step still running: " + openCount + " open, oldest " + mins + "m (idle budget " + budget + ") — the turn is waiting on agy" : "agy run still working: no new output for " + mins + "m (idle budget " + budget + ") — the turn is waiting on agy; press Stop to cancel";
|
|
34413
|
+
}
|
|
34335
34414
|
function createToolWatchdog(log, cfg) {
|
|
34336
34415
|
const openToolKeys = /* @__PURE__ */ new Set();
|
|
34337
34416
|
const openToolSince = /* @__PURE__ */ new Map();
|
|
@@ -34343,8 +34422,9 @@ function createToolWatchdog(log, cfg) {
|
|
|
34343
34422
|
const TOOL_HEARTBEAT_MS = 3e5;
|
|
34344
34423
|
let toolHeartbeat = null;
|
|
34345
34424
|
let idleGraceExempt = false;
|
|
34425
|
+
const backgroundWaits = createBackgroundWaits(() => syncIdleGraceExempt());
|
|
34346
34426
|
const syncIdleGraceExempt = () => {
|
|
34347
|
-
const next = awaitingSubagent || openToolKeys.size > 0;
|
|
34427
|
+
const next = awaitingSubagent || openToolKeys.size > 0 || backgroundWaits.active;
|
|
34348
34428
|
if (next === idleGraceExempt) return;
|
|
34349
34429
|
idleGraceExempt = next;
|
|
34350
34430
|
runningProc?.exemptIdleGrace(next);
|
|
@@ -34373,9 +34453,7 @@ function createToolWatchdog(log, cfg) {
|
|
|
34373
34453
|
}
|
|
34374
34454
|
let oldest = Date.now();
|
|
34375
34455
|
for (const startedAt of openToolSince.values()) if (startedAt < oldest) oldest = startedAt;
|
|
34376
|
-
|
|
34377
|
-
const mins = Math.max(1, Math.round((Date.now() - oldest) / 6e4));
|
|
34378
|
-
log?.(openToolKeys.size > 0 ? "agy tool step still running: " + openToolKeys.size + " open, oldest " + mins + "m (idle budget " + Math.round(longToolIdleMs / 6e4) + "m) — the turn is waiting on agy" : "agy run still working: no new output for " + mins + "m (idle budget " + Math.round(longToolIdleMs / 6e4) + "m) — the turn is waiting on agy; press Stop to cancel");
|
|
34456
|
+
log?.(heartbeatMessage(openToolKeys.size, oldest, lastOutputAt, longToolIdleMs));
|
|
34379
34457
|
}, TOOL_HEARTBEAT_MS);
|
|
34380
34458
|
toolHeartbeat.unref?.();
|
|
34381
34459
|
};
|
|
@@ -34396,6 +34474,7 @@ function createToolWatchdog(log, cfg) {
|
|
|
34396
34474
|
if (ev.kind !== "step") return;
|
|
34397
34475
|
if (ev.stepKind === "tool" && ev.tool !== void 0) {
|
|
34398
34476
|
if (SUBAGENT_COLLAB_TOOLS.has(ev.tool.name)) setAwaitingSubagent(!isStepFailedOrCanceled(ev));
|
|
34477
|
+
backgroundWaits.note(ev.stepKey, ev.tool.name, ev.state, isToolStepCompleted(ev));
|
|
34399
34478
|
if (!isToolStepCompleted(ev)) {
|
|
34400
34479
|
if (!openToolKeys.has(ev.stepKey)) {
|
|
34401
34480
|
openToolKeys.add(ev.stepKey);
|
|
@@ -34423,6 +34502,7 @@ function createToolWatchdog(log, cfg) {
|
|
|
34423
34502
|
awaitingSubagent = false;
|
|
34424
34503
|
openToolKeys.clear();
|
|
34425
34504
|
openToolSince.clear();
|
|
34505
|
+
backgroundWaits.clear();
|
|
34426
34506
|
syncIdleGraceExempt();
|
|
34427
34507
|
}
|
|
34428
34508
|
};
|
|
@@ -36493,15 +36573,17 @@ function renderPool(deps) {
|
|
|
36493
36573
|
const qO = a.quotas.openai?.remainingFraction !== void 0 ? `${Math.round(a.quotas.openai.remainingFraction * 100)}%` : "unknown";
|
|
36494
36574
|
const qA = a.quotas.argon?.weeklyFraction ?? a.quotas.argon?.remainingFraction;
|
|
36495
36575
|
const quotaLine = ` - Quota: Gemini ${qG} | Claude ${qC} | GPT-OSS ${qO}` + (qA !== void 0 ? ` | Argon ${Math.round(qA * 100)}%` : "");
|
|
36576
|
+
const now = Date.now();
|
|
36496
36577
|
const cds = [];
|
|
36497
|
-
for (const [fam, cd] of Object.entries(a.cooldowns)) if (cd && cd.cooldownUntil >
|
|
36498
|
-
const sec = Math.ceil((cd.cooldownUntil -
|
|
36578
|
+
for (const [fam, cd] of Object.entries(a.cooldowns)) if (cd && cd.cooldownUntil > now) {
|
|
36579
|
+
const sec = Math.ceil((cd.cooldownUntil - now) / 1e3);
|
|
36499
36580
|
cds.push(`${fam} cooldown: ${sec}s left (${cd.reason})`);
|
|
36500
36581
|
}
|
|
36501
36582
|
let statusText = " - Status: 🟢 Ready";
|
|
36502
36583
|
if (!a.enabled) statusText = " - Status: ⏸️ Disabled";
|
|
36503
|
-
else if (a
|
|
36584
|
+
else if (isAccountCriticalAuth(a)) statusText = ` - Status: 🔴 Auth required (${a.authError || a.quotaUnavailable?.reason || "sign in again"})`;
|
|
36504
36585
|
else if (cds.length > 0) statusText = ` - ⚠️ ${cds.join("; ")}`;
|
|
36586
|
+
else if (accountHasQuotaBench(a, now)) statusText = " - ⚠️ Quota-limited (auto-rotated until reset)";
|
|
36505
36587
|
lines.push(`${i + 1}. **${a.alias}** (${a.email || "email unknown"}; id: \`${a.id}\`)${isPrimary ? " ⭐ primary" : ""}`, ` - Proxy: ${a.proxyUrl ? redactProxyUrl(a.proxyUrl) : deps.cfg().proxyUrl ? redactProxyUrl(deps.cfg().proxyUrl) : "system default"}`, quotaLine, statusText);
|
|
36506
36588
|
}
|
|
36507
36589
|
return ok$1(lines.join("\n"));
|
|
@@ -36514,7 +36596,7 @@ async function handlePool(deps, ctx) {
|
|
|
36514
36596
|
const pool = deps.pool?.();
|
|
36515
36597
|
if (!pool) return err$1("Account pool not available");
|
|
36516
36598
|
const prev = pool.getActiveAccountId("google");
|
|
36517
|
-
if (!pool.setActiveAccount(arg)) return err$1(`Account ${arg} not found or not eligible (disabled / auth required)`);
|
|
36599
|
+
if (!pool.setActiveAccount(arg)) return err$1(`Account ${arg} not found or not eligible (disabled / cooldown / quota-limited / auth required)`);
|
|
36518
36600
|
if (arg === prev) deps.notifyPicker?.();
|
|
36519
36601
|
return ok$1(`Active account set to **${arg}** — model picker synced.`);
|
|
36520
36602
|
}
|
|
@@ -37267,6 +37349,25 @@ function settledToolResult(result, callId) {
|
|
|
37267
37349
|
* may arrive later (optional service): pass a thunk.
|
|
37268
37350
|
*/
|
|
37269
37351
|
function startMcpBridge(opts) {
|
|
37352
|
+
/**
|
|
37353
|
+
* Resolve the DSH agent that owns the request's `X-DSH-Session`.
|
|
37354
|
+
*
|
|
37355
|
+
* Shared by `/tools` and `/call`: a preset-scoped tool only exists for a
|
|
37356
|
+
* caller scope, so listing without one hides every tool registered inside a
|
|
37357
|
+
* preset (`present`, `todo_write`, `schedule_*`, `office_*`) even when the
|
|
37358
|
+
* allowlist names it (issue #150). DSH session keys come in two forms — a
|
|
37359
|
+
* top-level web session is `session-<uuid>`, a sub-agent/fork session is a
|
|
37360
|
+
* bare `<uuid>` — so the value is tried as given first (a bare sub-agent key
|
|
37361
|
+
* must not be rewritten) and retried once with the `session-` prefix only
|
|
37362
|
+
* when that finds nothing.
|
|
37363
|
+
*/
|
|
37364
|
+
const resolveSessionAgent = async (req) => {
|
|
37365
|
+
const sessionHeader = String(req.headers["x-dsh-session"] ?? "");
|
|
37366
|
+
const resolveSession = async (id) => id === "" ? void 0 : await Promise.resolve(opts.resolveAgent?.(id));
|
|
37367
|
+
const agent = await resolveSession(sessionHeader);
|
|
37368
|
+
if (agent === void 0 && sessionHeader !== "" && !sessionHeader.startsWith("session-")) return await resolveSession("session-" + sessionHeader);
|
|
37369
|
+
return agent;
|
|
37370
|
+
};
|
|
37270
37371
|
const token = randomBytes(24).toString("hex");
|
|
37271
37372
|
let callSeq = 0;
|
|
37272
37373
|
const server = createServer((req, res) => {
|
|
@@ -37285,7 +37386,7 @@ function startMcpBridge(opts) {
|
|
|
37285
37386
|
const allow = opts.allowlist().split(",").map((s) => s.trim()).filter(Boolean);
|
|
37286
37387
|
const allowSet = new Set(allow);
|
|
37287
37388
|
const used = /* @__PURE__ */ new Set();
|
|
37288
|
-
sendJson$1(res, 200, { tools: svc.schemas().filter((t) => allow.length === 0 || allowSet.has(t.name)).filter((t) => !INTERNAL_TOOL_NAMES.has(t.name)).map((t) => {
|
|
37389
|
+
sendJson$1(res, 200, { tools: svc.schemas(await resolveSessionAgent(req)).filter((t) => allow.length === 0 || allowSet.has(t.name)).filter((t) => !INTERNAL_TOOL_NAMES.has(t.name)).map((t) => {
|
|
37289
37390
|
const base = toMcpName(t.name);
|
|
37290
37391
|
let name = base;
|
|
37291
37392
|
for (let i = 2; used.has(name); i++) name = base + "__" + i;
|
|
@@ -37337,10 +37438,7 @@ function startMcpBridge(opts) {
|
|
|
37337
37438
|
return;
|
|
37338
37439
|
}
|
|
37339
37440
|
try {
|
|
37340
|
-
const
|
|
37341
|
-
const resolveSession = async (id) => id === "" ? void 0 : await Promise.resolve(opts.resolveAgent?.(id));
|
|
37342
|
-
let agent = await resolveSession(sessionHeader);
|
|
37343
|
-
if (agent === void 0 && sessionHeader !== "" && !sessionHeader.startsWith("session-")) agent = await resolveSession("session-" + sessionHeader);
|
|
37441
|
+
const agent = await resolveSessionAgent(req);
|
|
37344
37442
|
const controller = new AbortController();
|
|
37345
37443
|
const abortIfOpen = () => {
|
|
37346
37444
|
if (!res.writableEnded) controller.abort();
|
|
@@ -40280,6 +40378,11 @@ async function refreshAccountQuotaPipeline(deps, account, force = false) {
|
|
|
40280
40378
|
...failure?.detail === void 0 ? {} : { detail: failure.detail },
|
|
40281
40379
|
...failure?.actionUrl === void 0 ? {} : { actionUrl: failure.actionUrl }
|
|
40282
40380
|
});
|
|
40381
|
+
if ((reason === "validation_required" || reason === "tos_violation") && !account.authRequired) {
|
|
40382
|
+
const tag = reason === "tos_violation" ? "TOS_VIOLATION" : "VALIDATION_REQUIRED";
|
|
40383
|
+
const suffix = failure?.actionUrl ? ` (${failure.actionUrl})` : "";
|
|
40384
|
+
deps.pool.markAuthRequired(account.id, `${tag}${suffix}`);
|
|
40385
|
+
}
|
|
40283
40386
|
}
|
|
40284
40387
|
}
|
|
40285
40388
|
if (!summary && Object.keys(modelsCatalog).length === 0) return null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-agy-link",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.50",
|
|
4
4
|
"description": "Google Antigravity (agy CLI) models for DeepSeek Harness — stream Gemini/Claude/GPT-OSS subscriptions into DSH with thinking, tool activity, token usage and in-GUI Google OAuth login.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|