zcode-pro 1.11.0 → 1.12.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.
@@ -50,10 +50,11 @@ const continueTextFor = (value) => {
50
50
  const DEFAULTS = {
51
51
  enabled: true,
52
52
  continueText: '',
53
- maxRetries: 8,
54
- cooldownBaseSec: 10,
55
- cooldownFactor: 2,
56
- cooldownMaxSec: 60,
53
+ maxRetries: 10,
54
+ continueDelaySec: 120,
55
+ // 连续失败时继续延迟每次乘以这个倍数(1.3 → 2 分钟、2.6 分钟、3.4 分钟…);
56
+ // 1 = 不递增。连续次数按 30 分钟窗口统计,隔久了重新从基础延迟算
57
+ continueDelayFactor: 1.3,
57
58
  stuckAfterMin: 30,
58
59
  failedAfterMin: 3,
59
60
  truncationContinueText: '',
@@ -142,16 +143,12 @@ function trailingBanner() {
142
143
  }
143
144
 
144
145
  // 自动继续时间戳(页面存活期内):30 分钟窗口计总数(防故障反复时无限继续),
145
- // 2 分钟窗口计密集程度(只对密集失败退避,单次失败不等待)
146
+ // 也是继续延迟递增的计数依据
146
147
  let continueTimes = [];
147
148
  function pruneTimes() {
148
149
  const cutoff = Date.now() - 30 * 60 * 1000;
149
150
  continueTimes = continueTimes.filter((t) => t >= cutoff);
150
151
  }
151
- function recentWithin(ms) {
152
- const cutoff = Date.now() - ms;
153
- return continueTimes.filter((t) => t >= cutoff).length;
154
- }
155
152
 
156
153
  function sleep(ms) {
157
154
  return new Promise((resolve) => setTimeout(resolve, ms));
@@ -205,12 +202,13 @@ async function clickSend() {
205
202
  return false;
206
203
  }
207
204
 
208
- // 单次失败不等待(任务等着接上,只留 3 秒界面稳定时间);2 分钟内已继续过
209
- // 则视为密集失败,按 2 倍递增退避
205
+ // 继续前先等 continueDelaySec(默认 2 分钟,让临时故障自己过去);30 分钟窗口内
206
+ // 第 n 次连续失败等待 基础延迟 × 倍数^(n-1)(倍数 1 = 不递增)
210
207
  function delayFor(dense, cfg) {
211
- if (dense <= 1) return 3000;
212
- const secs = Math.min(cfg.cooldownBaseSec * Math.pow(cfg.cooldownFactor || 2, dense - 2), cfg.cooldownMaxSec);
213
- return Math.round(secs * 1000);
208
+ const base = Math.max(0, cfg.continueDelaySec ?? DEFAULTS.continueDelaySec);
209
+ const factor = Math.max(1, cfg.continueDelayFactor ?? DEFAULTS.continueDelayFactor);
210
+ const times = Math.max(1, dense);
211
+ return Math.round(base * Math.pow(factor, times - 1) * 1000);
214
212
  }
215
213
 
216
214
  // 回合正常结束但收尾内容坏了(原插件 Stop 钩子角色的 DOM 版):最后一行是长回复且
@@ -280,7 +278,7 @@ async function tick() {
280
278
  return;
281
279
  }
282
280
  el.dataset.zcodeproAc = 'pending';
283
- await sleep(delayFor(recentWithin(2 * 60 * 1000), cfg));
281
+ await sleep(delayFor(continueTimes.length + 1, cfg));
284
282
  // 等待期间状态可能变化(用户手动继续、切走会话、目标行消失),重新校验后再发
285
283
  if (!el.isConnected || document.querySelector(STOP_SEL)) {
286
284
  el.dataset.zcodeproAc = 'skip';
@@ -461,6 +459,10 @@ function showNextStuckCard() {
461
459
  const more = stuckQueue.length > 1;
462
460
  const card = document.createElement('div');
463
461
  card.style.cssText = 'position:fixed;right:16px;bottom:16px;z-index:2147483000;max-width:360px;padding:12px;border-radius:12px;border:1px solid var(--color-border, #666);background:var(--color-surface, #222);color:var(--color-foreground, #eee);font-size:13px;line-height:1.5;box-shadow:0 4px 24px rgba(0,0,0,.4)';
462
+ // 与 showCornerCard 共用同一组标记:其他功能(headroom 提示等)据此判断右下角
463
+ // 是否已被占用,避免两张卡片叠在同一角落互相覆盖
464
+ card.className = 'zcodepro-corner-card';
465
+ card.setAttribute('data-zcodepro-corner', 'br');
464
466
  const title = document.createElement('div');
465
467
  title.style.cssText = 'font-weight:600;margin-bottom:4px';
466
468
  title.textContent = (task.failedMsg
@@ -1,33 +1,57 @@
1
1
  // headroom 供应商登记提示:headroom 插件在会话启动时对账「ZCode 供应商配置 ↔ 本地
2
- // 压缩路由登记表」,把结果写进数据根的 hr-reconcile-notice.json。这里轮询 helper
3
- // 拿最新一条,按 at 时间戳去重(存 sessionStorage),只在首次见到时弹右下角卡片。
2
+ // 压缩路由登记表」,把结果写进数据根的 hr-reconcile-notice.json。这里轮询 helper 拿
3
+ // 最新一条,弹右下角卡片。
4
4
  //
5
5
  // 为什么轮询而不是直接收推送:helper 的鉴权 token 每次启动随机生成、不落盘、不进
6
6
  // 环境变量,外部进程(headroom 钩子)拿不到,没法直接调 helper 接口;写文件 + 页面
7
7
  // 轮询是仓库里既有的做法(auto-continue 同款)。
8
8
  //
9
+ // 频率约定:一次应用启动最多弹一次。启动时刻记在 localStorage,8 小时内算同一次
10
+ // 启动(页面刷新、注入重载都不重弹),超过就当作新的一次。
11
+ // 对账文件由 headroom 钩子在“会话第一轮”写入,可能晚于页面注入,所以仍需轮询等着;
12
+ // 但弹出后不再重复,避免每开一个新会话就被同一条待办打扰。
13
+ //
9
14
  // 开关:features.hrNotice(默认开)。
10
15
  import { getConfig, rpc } from '../core.js';
11
16
  import { closeCornerCard, showCornerCard } from '../ui.js';
12
17
 
13
18
  const POLL_MS = 15_000;
19
+ // 本次启动是否已经弹过。用 localStorage 存时间戳而不是 sessionStorage 布尔值:
20
+ // 应用可能长期不关,只靠“页面会话”会把同一天里的多次启动合并成一次;
21
+ // 反过来页面刷新(注入重载)不该重弹,所以按时间窗判定,8 小时内算同一次启动
22
+ const LAUNCH_KEY = 'zcodeproHrNoticeShownAt';
23
+ const LAUNCH_WINDOW_MS = 8 * 60 * 60 * 1000;
24
+ // 同一份对账结果只弹一次(跨页面刷新),防止注入重载后重复
14
25
  const SEEN_KEY = 'zcodeproHrNoticeSeen';
15
- // 与 headroom 侧 hr-notice.mjs 的 MAX_AGE_MS 一致:过期结果不再弹。
16
- // 没有这道限制的话,关掉应用重开后 sessionStorage 清空,几天前的 notice 仍会弹出来。
17
- const MAX_AGE_MS = 10 * 60 * 1000;
26
+ // 过期结果不再弹:
27
+ // - 带「已自动修复」的结果是刚发生的事件,10 分钟后就不该再报(可能是几天前的)
28
+ // - 只有「需要处理」的结果代表仍未解决的问题,放宽到 24 小时:
29
+ // 启动时若没有会话恢复(对账文件没被重写)也不至于把待办漏掉
30
+ const MAX_AGE_FIXED_MS = 10 * 60 * 1000;
31
+ const MAX_AGE_PENDING_MS = 24 * 60 * 60 * 1000;
18
32
 
19
- function seenAt() {
33
+ function readStore(kind, key) {
20
34
  try {
21
- return String(sessionStorage.getItem(SEEN_KEY) || '');
35
+ return String((kind === 'local' ? localStorage : sessionStorage).getItem(key) || '');
22
36
  } catch {
23
37
  return '';
24
38
  }
25
39
  }
26
40
 
27
- function markSeen(at) {
41
+ function writeStore(kind, key, value) {
28
42
  try {
29
- sessionStorage.setItem(SEEN_KEY, String(at || ''));
30
- } catch { /* 隐私模式等写不进去:本轮会重复弹,可接受 */ }
43
+ (kind === 'local' ? localStorage : sessionStorage).setItem(key, String(value ?? ''));
44
+ } catch { /* 隐私模式等写不进去:本轮可能重复弹,可接受 */ }
45
+ }
46
+
47
+ // 8 小时内已经弹过就算本次启动已处理
48
+ function alreadyShownThisLaunch() {
49
+ const raw = readStore('local', LAUNCH_KEY);
50
+ if (!raw) return false;
51
+ const at = Number(raw);
52
+ if (!Number.isFinite(at) || at <= 0) return false;
53
+ const age = Date.now() - at;
54
+ return age >= 0 && age < LAUNCH_WINDOW_MS;
31
55
  }
32
56
 
33
57
  // 把对账结果拼成卡片文案;没有问题返回 null
@@ -38,7 +62,11 @@ function cardOf(notice) {
38
62
 
39
63
  const parts = [];
40
64
  if (fixed.length) {
41
- const items = fixed.map((x) => (x.action === 'key' ? `${x.name}:更新密钥` : `${x.name}:补登记`));
65
+ // action 是插件对账给出的动作:key = 更新密钥,rename = 登记里的名称跟着 ZCode 里的
66
+ // 改名更新,removed = 供应商在 ZCode 里被删、登记跟着删。以前除了 key 以外都写成
67
+ // “补登记”,删除登记、同步名称也显示成补登记
68
+ const ACTION_LABEL = { key: '更新密钥', rename: '已同步名称', removed: '已删除登记' };
69
+ const items = fixed.map((x) => `${x.name}:${ACTION_LABEL[x.action] || '补登记'}`);
42
70
  parts.push(`已自动同步供应商登记:${items.join(';')}`);
43
71
  }
44
72
  if (pending.length) {
@@ -53,36 +81,58 @@ function cardOf(notice) {
53
81
  }
54
82
 
55
83
  let shownAt = null;
84
+ let shownThisLaunch = false;
85
+
86
+ // 右下角是否已经有卡片(自动继续、代理链迁移等)。showCornerCard 会先移除同位置的
87
+ // 旧卡片,两个提示叠着会互相覆盖,所以有别的卡片时就跳过本轮,等它关掉后再弹
88
+ function brOccupied() {
89
+ return !!document.querySelector('.zcodepro-corner-card[data-zcodepro-corner="br"]');
90
+ }
56
91
 
57
92
  async function tick() {
93
+ if (shownThisLaunch || alreadyShownThisLaunch()) return;
58
94
  const cfg = await getConfig();
59
95
  if ((cfg.features || {}).hrNotice === false) return;
60
96
  const res = await rpc('/headroom/reconcile-notice');
61
97
  if (!res || res.ok === false) return;
62
98
  const notice = res.notice;
63
99
  if (!notice || !notice.at) return;
64
- // 过期结果不弹(与 headroom 侧 hr-notice.mjs 同一个 10 分钟窗口)
65
100
  const at = Date.parse(notice.at);
66
- if (!Number.isFinite(at) || Date.now() - at > MAX_AGE_MS) return;
67
- // 同一份结果只处理一次:本进程内 + 跨刷新(sessionStorage)
68
- if (notice.at === shownAt || notice.at === seenAt()) return;
101
+ if (!Number.isFinite(at)) return;
102
+ // 全部都是“已自动修复”才按短窗口丢弃;只要还有待办就按长窗口
103
+ const pendingList = Array.isArray(notice.pending) ? notice.pending : [];
104
+ const age = Date.now() - at;
105
+ if (age > (pendingList.length ? MAX_AGE_PENDING_MS : MAX_AGE_FIXED_MS)) return;
106
+ // 同一份结果只处理一次:本进程内 + 跨刷新
107
+ if (notice.at === shownAt || notice.at === readStore(SEEN_KEY)) return;
69
108
  const card = cardOf(notice);
70
109
  if (!card) return;
110
+ if (brOccupied()) return; // 让用户先处理已在的卡片,本卡留到下轮
71
111
  shownAt = notice.at;
72
- markSeen(notice.at);
73
- // 用左下角:右下角是自动继续卡的位置,两者同时出现时用不同角落避免互相遮挡
74
- showCornerCard({ position: 'bl', ...card, actions: [{ label: '知道了', primary: true, onClick: () => closeCornerCard('bl') }] });
112
+ shownThisLaunch = true;
113
+ writeStore('local', LAUNCH_KEY, String(Date.now()));
114
+ writeStore('session', SEEN_KEY, notice.at);
115
+ showCornerCard({
116
+ position: 'br',
117
+ ...card,
118
+ actions: [{ label: '知道了', primary: true, onClick: () => closeCornerCard('br') }],
119
+ });
75
120
  }
76
121
 
77
122
  export function startHrNotice() {
123
+ // 本次启动已经弹过就不再轮询:省掉每 15 秒一次的无用请求
124
+ if (shownThisLaunch || alreadyShownThisLaunch()) return;
78
125
  const run = () => {
79
- // 首轮立即跑,之后按周期:晚开会话/刷新后不用等 15 秒
126
+ // 首轮立即跑,之后按周期:对账文件可能比页面注入晚写出来
80
127
  tick().catch(() => { /* 单次失败不影响后续 */ });
81
128
  };
82
129
  run();
83
130
  setInterval(() => {
131
+ if (shownThisLaunch) return; // 已弹过,停掉后续轮询
84
132
  if (document.hidden) return; // 后台标签页不轮询,回到前台由 visibilitychange 补一轮
85
133
  run();
86
134
  }, POLL_MS);
87
- document.addEventListener('visibilitychange', () => { if (!document.hidden) run(); });
135
+ document.addEventListener('visibilitychange', () => {
136
+ if (!document.hidden && !shownThisLaunch) run();
137
+ });
88
138
  }
@@ -0,0 +1,215 @@
1
+ // 右下角提示卡片(helper 那边发生的事)。helper 写提示文件,页面轮询 helper 读取、
2
+ // 按写入时间去重、只在首次见到时弹卡片。做法与 hr-notice 一致:helper 的 token
3
+ // 不落盘,外部进程调不了接口,写文件 + 轮询是仓库里既有的做法。
4
+ // 四种提示,由同一个接口一起返回,页面不用为每种各轮询一次:
5
+ // proxy-chain-notice.json
6
+ // auto-unchecked:有供应商因为地址变了(在 ZCode 里手动改的,或从别的设备同步来的)
7
+ // 自动退出了代理链。卡片上可以直接跳到代理链页
8
+ // (没有 kind): 旧的一次性迁移说明(供应商代理改成按代理链展示)
9
+ // proxy-health-notice.json
10
+ // health: 每 30 秒的巡检发现问题(转发器不在监听、走链的 headroom 实例不在
11
+ // 监听)。helper 发现时已经自动处理,卡片说明发现了什么、做了什么
12
+ // title-gen-notice.json
13
+ // title-gen: 新会话自动起名失败(供应商或模型不支持),会话名还是 ZCode 默认的
14
+ // tool-name-notice.json
15
+ // tool-name: 工具名合规检查有文件写不了(ZCode 自带插件在 root 目录下)
16
+ // 右下角同一时间只放一张卡片:按上面的顺序弹第一个没弹过的,其余等下一轮、右下角
17
+ // 空出来再弹。开关:features.proxyChainNotice(默认开)。
18
+ import { getConfig, isCjkLocale, rpc, t } from '../core.js';
19
+ import { openSettingsDialog } from './settings-dialog.js';
20
+ import { closeCornerCard, showCornerCard } from '../ui.js';
21
+
22
+ const POLL_MS = 10_000;
23
+ const MAX_AGE_MS = 10 * 60 * 1000;
24
+
25
+ function storeGet(key) {
26
+ try { return String(sessionStorage.getItem(key) || ''); } catch { return ''; }
27
+ }
28
+ function storeSet(key, at) {
29
+ try { sessionStorage.setItem(key, String(at || '')); } catch { /* 隐私模式写不进去:本轮会重复弹,可接受 */ }
30
+ }
31
+ // 写入时间在 10 分钟内才弹:页面刚打开时不补弹旧提示
32
+ function fresh(atStr) {
33
+ const at = Date.parse(atStr);
34
+ return Number.isFinite(at) && Date.now() - at <= MAX_AGE_MS;
35
+ }
36
+ function cornerBusy() {
37
+ return !!document.querySelector('.zcodepro-corner-card[data-zcodepro-corner="br"]');
38
+ }
39
+ // 端口列表的分隔符:中文用顿号,其他语言用逗号
40
+ const listSep = () => (isCjkLocale() ? '、' : ', ');
41
+
42
+ function showAutoUnchecked(notice, L) {
43
+ const items = (Array.isArray(notice.items) ? notice.items : [])
44
+ .filter((it) => it && typeof it === 'object');
45
+ const lines = items.map((it) => L.noticeAutoUncheckedItem
46
+ .replace('{name}', String(it.name || it.id || ''))
47
+ .replace('{url}', String(it.url || ''))
48
+ .replace('{chain}', String(it.chain || '')));
49
+ showCornerCard({
50
+ position: 'br',
51
+ kind: 'info',
52
+ title: L.noticeAutoUncheckedTitle,
53
+ desc: [L.noticeAutoUncheckedDesc, ...lines, L.noticeAutoUncheckedHow].join('\n\n'),
54
+ actions: [{
55
+ label: L.noticeGoChain,
56
+ primary: true,
57
+ onClick: () => { closeCornerCard('br'); openSettingsDialog('proxy', 'vendor'); },
58
+ }],
59
+ });
60
+ }
61
+
62
+ function showMigration(notice) {
63
+ const cleared = Array.isArray(notice.cleared) ? notice.cleared : [];
64
+ const rebuilt = Array.isArray(notice.rebuilt) ? notice.rebuilt : [];
65
+ const parts = ['供应商代理已改为按代理链展示,原有配置已重置。'];
66
+ if (rebuilt.length) parts.push(`已重建:${rebuilt.join('、')}`);
67
+ if (cleared.length) parts.push(`已还原为直连或 headroom:${cleared.join('、')}`);
68
+ parts.push('请到 设置 → 代理 → 供应商代理 重新配置。');
69
+ showCornerCard({
70
+ position: 'br',
71
+ kind: 'warning',
72
+ title: '供应商代理配置已重置',
73
+ desc: parts.join('\n\n'),
74
+ actions: [{ label: '知道了', primary: true, onClick: () => closeCornerCard('br') }],
75
+ });
76
+ }
77
+
78
+ function showChainNotice(notice, L) {
79
+ if (notice.kind === 'auto-unchecked') showAutoUnchecked(notice, L);
80
+ else showMigration(notice);
81
+ }
82
+
83
+ // 巡检提示:每条说明一个发现(端口、做了什么、有没有处理成功)。
84
+ // 全是 headroom 实例的问题,按钮就去 Headroom 页;有转发器的问题就去代理链页
85
+ function showHealth(health, L) {
86
+ const items = (Array.isArray(health.items) ? health.items : [])
87
+ .filter((it) => it && typeof it === 'object');
88
+ if (!items.length) return;
89
+ const ports = (list) => (Array.isArray(list) ? list : []).map(String).join(listSep());
90
+ const lines = items.map((it) => {
91
+ if (it.type === 'router' || it.type === 'headroom') {
92
+ const tpl = it.type === 'router' ? L.noticeHealthRouter : L.noticeHealthInstance;
93
+ return tpl.replace('{ports}', ports(it.ports))
94
+ + (it.failed ? L.noticeHealthInstanceFailed.replace('{error}', String(it.error || '')) : '');
95
+ }
96
+ return L.noticeHealthForwarder.replace('{ports}', ports(it.ports))
97
+ + (it.stillDown ? L.noticeHealthForwarderDown : '');
98
+ });
99
+ const hasHeadroom = items.some((it) => it.type === 'headroom' || it.type === 'router');
100
+ const parts = [L.noticeHealthDesc, ...lines];
101
+ if (hasHeadroom) parts.push(L.noticeHealthHint);
102
+ const toHeadroom = hasHeadroom && items.every((it) => it.type === 'headroom' || it.type === 'router');
103
+ showCornerCard({
104
+ position: 'br',
105
+ kind: 'warning',
106
+ title: L.noticeHealthTitle,
107
+ desc: parts.join('\n\n'),
108
+ actions: [{
109
+ label: toHeadroom ? L.noticeHealthGoHeadroom : L.noticeGoChain,
110
+ primary: true,
111
+ onClick: () => {
112
+ closeCornerCard('br');
113
+ if (toHeadroom) openSettingsDialog('headroom');
114
+ else openSettingsDialog('proxy', 'vendor');
115
+ },
116
+ }],
117
+ });
118
+ }
119
+
120
+ // 任务名生成失败:哪家供应商、哪个模型、服务端返回的原因。跟随会话起名时供应商一栏
121
+ // 写成“会话用的供应商”
122
+ function showTitleGen(notice, L) {
123
+ const provider = String(notice.providerName || '') || L.noticeTitleGenSession;
124
+ const item = L.noticeTitleGenItem
125
+ .replace('{provider}', provider)
126
+ .replace('{model}', String(notice.model || '—'))
127
+ .replace('{error}', String(notice.error || ''));
128
+ showCornerCard({
129
+ position: 'br',
130
+ kind: 'error',
131
+ title: L.noticeTitleGenTitle,
132
+ desc: [L.noticeTitleGenDesc, item, L.noticeTitleGenHow].join('\n\n'),
133
+ actions: [{
134
+ label: L.noticeTitleGenGo,
135
+ primary: true,
136
+ onClick: () => { closeCornerCard('br'); openSettingsDialog('agents', 'titleGen'); },
137
+ }],
138
+ });
139
+ }
140
+
141
+ // 工具名检查有文件改不了:列出文件、想改成什么、为什么写不进去
142
+ function showToolName(notice, L) {
143
+ const items = (Array.isArray(notice.items) ? notice.items : [])
144
+ .filter((it) => it && typeof it === 'object');
145
+ if (!items.length) return;
146
+ // 报错原文里混着临时文件名(.mcp.json.502418.…tmp),界面上压缩成短语;
147
+ // 认不出的错保留原文、截到 120 字符。原始报错在提示文件里留着
148
+ const errText = (raw) => {
149
+ const s = String(raw || '');
150
+ if (/EACCES|EPERM/i.test(s)) return L.noticeToolNameNoPerm;
151
+ return s.length > 120 ? s.slice(0, 120) + '…' : s;
152
+ };
153
+ const lines = items.map((it) => {
154
+ const renames = (Array.isArray(it.renames) ? it.renames : [])
155
+ .map((x) => `${String((x && x.from) || '')} → ${String((x && x.to) || '')}`).join(listSep());
156
+ return L.noticeToolNameItem
157
+ .replace('{file}', String(it.file || ''))
158
+ .replace('{changes}', renames)
159
+ .replace('{error}', errText(it.error));
160
+ });
161
+ // 说明 + 可复制的命令 + 后续行为。条目之间不空行(路径长,空行会把卡片撑很高)
162
+ const cmd = String(notice.command || '').trim();
163
+ const parts = [L.noticeToolNameDesc, lines.join('\n')];
164
+ if (cmd) parts.push(L.noticeToolNameFix, cmd, L.noticeToolNameAfter);
165
+ else parts.push(L.noticeToolNameFixNoCmd);
166
+ showCornerCard({
167
+ position: 'br',
168
+ kind: 'warning',
169
+ title: L.noticeToolNameTitle,
170
+ desc: parts.join('\n\n'),
171
+ actions: [{
172
+ label: L.noticeToolNameGo,
173
+ primary: true,
174
+ onClick: () => { closeCornerCard('br'); openSettingsDialog('agents', 'zcode'); },
175
+ }],
176
+ });
177
+ }
178
+
179
+ // 顺序即优先级:链的提示最先,然后是巡检、任务名、工具名
180
+ const KINDS = [
181
+ { field: 'notice', seenKey: 'zcodeproProxyChainNoticeSeen', show: showChainNotice },
182
+ { field: 'health', seenKey: 'zcodeproProxyHealthNoticeSeen', show: showHealth },
183
+ { field: 'titleGen', seenKey: 'zcodeproTitleGenNoticeSeen', show: showTitleGen },
184
+ { field: 'toolName', seenKey: 'zcodeproToolNameNoticeSeen', show: showToolName },
185
+ ];
186
+ const shownBy = {};
187
+
188
+ async function tick() {
189
+ const cfg = await getConfig();
190
+ if ((cfg.features || {}).proxyChainNotice === false) return;
191
+ const res = await rpc('/provider-proxies/migration-notice');
192
+ if (!res || res.ok === false) return;
193
+ for (const kind of KINDS) {
194
+ const n = res[kind.field];
195
+ if (!n || !n.at || !fresh(n.at)) continue;
196
+ if (n.at === shownBy[kind.field] || n.at === storeGet(kind.seenKey)) continue;
197
+ // 右下角已被别的卡片占着就先不弹:showCornerCard 会替换同位置的旧卡片,
198
+ // 叠上去等于把用户正在看的提示顶掉。不算“已弹过”,等对方关掉后下轮再来
199
+ if (cornerBusy()) return;
200
+ shownBy[kind.field] = n.at;
201
+ storeSet(kind.seenKey, n.at);
202
+ kind.show(n, t());
203
+ return;
204
+ }
205
+ }
206
+
207
+ export function startProxyChainNotice() {
208
+ const run = () => { tick().catch(() => { /* 单次失败不影响后续 */ }); };
209
+ run();
210
+ setInterval(() => {
211
+ if (document.hidden) return;
212
+ run();
213
+ }, POLL_MS);
214
+ document.addEventListener('visibilitychange', () => { if (!document.hidden) run(); });
215
+ }