@wendongfly/myhi 1.3.218 → 1.3.220

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.html CHANGED
@@ -16,6 +16,7 @@
16
16
  <link rel="apple-touch-icon" href="/icon.png">
17
17
  <title>myhi</title>
18
18
  <script src="/lib/machine.js"></script>
19
+ <script src="/lib/icons.js"></script>
19
20
  <script src="/lib/prefs.js"></script>
20
21
  <script src="/lib/attn.js"></script>
21
22
  <script src="/sio-client/socket.io.min.js"></script>
@@ -87,6 +88,9 @@
87
88
  #mig-ov { position: fixed; inset: 0; z-index: 40; background: rgba(0,0,0,0.55); display: flex; align-items: flex-end; justify-content: center; }
88
89
  #mig-box { background: var(--surface); color: var(--text); width: 100%; max-width: 560px; max-height: 90vh; overflow-y: auto; border-radius: 16px 16px 0 0; padding: 1rem 1.1rem max(1rem, env(safe-area-inset-bottom)); font-size: 0.85rem; line-height: 1.6; }
89
90
  @media (min-width: 700px) { #mig-ov { align-items: center; } #mig-box { border-radius: 16px; } }
91
+ .mig-proj { display: flex; align-items: flex-start; gap: 0.5rem; padding: 0.35rem 0; border-top: 1px dashed var(--border); }
92
+ .mig-proj:first-of-type { border-top: none; }
93
+ .mig-proj input[type=text] { width: 100%; margin-top: 0.2rem; }
90
94
  #mig-box h3 { font-size: 1.02rem; margin: 0 0 0.5rem; display: flex; justify-content: space-between; align-items: center; }
91
95
  #mig-box h3 button { background: none; border: none; color: var(--muted); font-size: 1.1rem; cursor: pointer; }
92
96
  #mig-box .mig-intro { color: var(--muted); margin-bottom: 0.7rem; }
@@ -185,6 +189,19 @@
185
189
  .set-lbl small { display: inline; margin-left: 0.4rem; }
186
190
  .set-seg { flex: 1; }
187
191
  }
192
+ /* 模型选择:自己的下拉(原生 datalist 会按当前值过滤,选过一次再点只剩这一项;手机上也不好用) */
193
+ .mp-wrap { flex: 1; min-width: 0; display: flex; position: relative; }
194
+ .mp-wrap .set-inp { padding-right: 1.8rem; }
195
+ .mp-caret { position: absolute; right: 2px; top: 50%; transform: translateY(-50%); border: none; background: none; color: var(--muted); font-size: 0.75rem; padding: 0.3rem 0.45rem; cursor: pointer; }
196
+ #mp-pop { display: none; position: fixed; z-index: 60; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 8px 28px rgba(0,0,0,0.35); overflow-y: auto; padding: 0.25rem; }
197
+ #mp-pop.open { display: block; }
198
+ #mp-pop .mp-o { padding: 0.4rem 0.55rem; border-radius: 7px; cursor: pointer; }
199
+ #mp-pop .mp-o b { display: block; font-size: 0.82rem; font-weight: 500; color: var(--text); word-break: break-all; }
200
+ #mp-pop .mp-o small { display: block; font-size: 0.7rem; color: var(--muted); margin-top: 1px; }
201
+ #mp-pop .mp-o.act { background: var(--surface2); }
202
+ #mp-pop .mp-o.cur b { color: var(--purple); font-weight: 600; }
203
+ #mp-pop .mp-o.cur b::after { content: ' ✓'; }
204
+ #mp-pop .mp-empty { padding: 0.5rem; font-size: 0.75rem; color: var(--muted); }
188
205
  .set-inp { flex: 1; min-width: 0; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; color: var(--text); font-size: 0.8rem; padding: 0.4rem 0.55rem; outline: none; }
189
206
  .set-inp:focus { border-color: var(--accent); }
190
207
  .set-inp:disabled { opacity: 0.6; }
@@ -216,7 +233,12 @@
216
233
  body.ws .hd-actions > :not(#conn-dot) { display: none !important; }
217
234
  body.ws #ws-collapse { display: block; }
218
235
  body.ws #view-controls { position: static; background: var(--surface); padding-top: 0 !important; }
219
- body.ws #view-controls > div:first-child { flex-direction: column-reverse; align-items: stretch; }
236
+ body.ws #view-controls > #search-row { flex-direction: column-reverse; align-items: stretch; }
237
+ #main-nav { display: flex; gap: 3px; padding: 3px; background: var(--bg); border: 1px solid var(--border); border-radius: 10px; }
238
+ #main-nav button { flex: 1; display: flex; align-items: center; justify-content: center; gap: 0.15rem; background: none; border: none; border-radius: 7px; color: var(--text2); font-size: 0.8rem; padding: 0.42rem 0.2rem; cursor: pointer; white-space: nowrap; }
239
+ #main-nav button:hover { color: var(--text); }
240
+ #main-nav button.on { background: var(--accent); color: #fff; font-weight: 600; }
241
+ body.ws #main-nav { background: var(--surface); }
220
242
  body.ws #new-btn { display: block !important; width: 100%; padding: 0.55rem; }
221
243
  body.ws #search-count { display: none; }
222
244
  body.ws #sess-search { flex: none; width: 100%; }
@@ -238,12 +260,15 @@
238
260
  #ws-set { position: relative; background: none; border: none; color: var(--text2); font-size: 1.05rem; width: 34px; height: 34px; border-radius: 8px; cursor: pointer; }
239
261
  #ws-set:hover, #ws-set.on { background: var(--bg); color: var(--text); }
240
262
  #ws-set.has-dot::after, #ws-menu-dot.on { content: ''; position: absolute; top: 6px; right: 6px; width: 7px; height: 7px; border-radius: 50%; background: var(--red); }
241
- #ws-menu { display: none; position: fixed; z-index: 45; min-width: 12rem; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,0.4); padding: 0.3rem; }
263
+ #ws-menu { display: none; position: fixed; z-index: 45; min-width: 14rem; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,0.4); padding: 0.3rem; }
242
264
  #ws-menu.open { display: block; }
243
- #ws-menu button { position: relative; display: flex; align-items: baseline; gap: 0.5rem; width: 100%; text-align: left; background: none; border: none; color: var(--text); font-size: 0.84rem; padding: 0.5rem 0.6rem; border-radius: 7px; cursor: pointer; }
265
+ #ws-menu button { position: relative; display: flex; align-items: center; gap: 0.55rem; width: 100%; text-align: left; background: none; border: none; color: var(--text); font-size: 0.84rem; padding: 0.5rem 0.6rem; border-radius: 7px; cursor: pointer; }
244
266
  #ws-menu button:hover { background: var(--bg); }
245
267
  #ws-menu button small { margin-left: auto; font-size: 0.68rem; color: var(--muted); }
246
268
  #ws-menu button.danger { color: var(--red); }
269
+ #ws-menu .wi { width: 16px; height: 16px; flex-shrink: 0; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; color: var(--muted); }
270
+ #ws-menu button:hover .wi { color: var(--text); }
271
+ #ws-menu button.danger .wi { color: inherit; }
247
272
  #ws-menu hr { border: none; border-top: 1px solid var(--border); margin: 0.3rem 0.2rem; }
248
273
  #ws-menu-dot.on { position: static; display: inline-block; margin-left: 0.3rem; }
249
274
  #ws-collapse { background: none; border: none; color: var(--muted); font-size: 1rem; cursor: pointer; padding: 0.2rem 0.4rem; border-radius: 6px; }
@@ -264,6 +289,7 @@
264
289
  cursor: pointer; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
265
290
  #ws-rail .rb:hover { background: var(--bg); color: var(--text); }
266
291
  #ws-rail .rb.new { background: var(--accent); color: #fff; font-size: 1.3rem; }
292
+ #ws-rail .rb.on { background: var(--bg); color: var(--accent); }
267
293
  #ws-rail .rb.has-dot::after { content: ''; position: absolute; top: 5px; right: 5px; width: 7px; height: 7px; border-radius: 50%; background: var(--red); }
268
294
  #ws-rail .rail-sep { width: 28px; border-top: 1px solid var(--border); margin: 0.2rem 0; flex-shrink: 0; }
269
295
  #ws-rail .rail-list { flex: 1; min-height: 0; overflow-y: auto; scrollbar-width: none; display: flex; flex-direction: column; align-items: center; gap: 0.35rem; padding: 0.1rem 0; }
@@ -778,8 +804,14 @@
778
804
  <div id="ai-banner" class="ai-banner" style="display:none"></div>
779
805
 
780
806
  <div id="view-controls" style="display:flex;flex-direction:column;gap:0.5rem;padding:0.75rem 0.75rem 0">
807
+ <!-- 一级导航:任务(AI 对话任务)/ 出图 / 语音处理。电脑在右侧打开,手机进对应页面 -->
808
+ <div id="main-nav">
809
+ <button data-nav="tasks" class="on" onclick="mainNav('tasks')">💬 任务</button>
810
+ <button data-nav="studio" onclick="mainNav('studio')">🖼 出图</button>
811
+ <button data-nav="voice" onclick="mainNav('voice')">🎤 语音处理</button>
812
+ </div>
781
813
  <!-- 会话搜索:任务多了光看标题认不出,连首条消息/目录/标签一起搜 -->
782
- <div style="display:flex;align-items:center;gap:0.4rem">
814
+ <div id="search-row" style="display:flex;align-items:center;gap:0.4rem">
783
815
  <input id="sess-search" type="search" placeholder="搜任务:标题 / 首条需求 / 目录 / 标签"
784
816
  autocomplete="off" spellcheck="false"
785
817
  style="flex:1;background:var(--bg,var(--bg));border:1px solid var(--border,var(--border));border-radius:8px;color:var(--text,var(--text));font-size:0.8rem;padding:0.4rem 0.7rem;outline:none">
@@ -807,7 +839,7 @@
807
839
  </div>
808
840
  <!-- 工作台任务栏底部:平时只留一行「用户 + ⚙」,其余功能收进 ⚙ 菜单(功能再多也不占地方) -->
809
841
  <div id="ws-foot">
810
- <span id="ws-user">👤 本机</span>
842
+ <span id="ws-user" data-ico>👤 本机</span>
811
843
  <button id="ws-set" onclick="toggleWsMenu(event)" title="设置与更多">⚙</button>
812
844
  </div>
813
845
  </div>
@@ -822,6 +854,8 @@
822
854
  <div id="ws-rail">
823
855
  <button class="rb" onclick="wsSetCollapsed(false)" data-tip="展开任务栏">☰</button>
824
856
  <button class="rb new" onclick="openSheet()" data-tip="新建任务">+</button>
857
+ <button class="rb" data-nav="studio" onclick="mainNav('studio')" data-tip="出图">🖼</button>
858
+ <button class="rb" data-nav="voice" onclick="mainNav('voice')" data-tip="语音处理">🎤</button>
825
859
  <div class="rail-sep"></div>
826
860
  <div class="rail-list" id="rail-list"></div>
827
861
  <div class="rail-sep"></div>
@@ -830,16 +864,18 @@
830
864
  <div id="ws-tip"></div>
831
865
  <!-- ⚙ 菜单(工作台底部 / 窄栏的 ⚙ 打开) -->
832
866
  <div id="ws-menu">
833
- <button onclick="wsMenuGo(openSettings)">⚙ 设置<span id="ws-menu-dot"></span></button>
834
- <button onclick="wsMenuGo(() => location.href = '/grid')">▦ 分屏<small>多任务并排</small></button>
835
- <button onclick="wsMenuGo(openNoteSheet)">📥 随手记<small>先记进草稿箱</small></button>
836
- <button onclick="wsMenuGo(openDoctor)">🩺 会话体检</button>
837
- <button onclick="wsMenuGo(showUsage)">📊 用量</button>
838
- <button onclick="wsMenuGo(openHelpSheet)">❓ 帮助</button>
867
+ <!-- 图标统一:单色线条 SVG,跟随文字颜色(以前 ⚙ ▦ 是字符、其它是彩色 emoji,风格不一) -->
868
+ <button onclick="wsMenuGo(openSettings)"><svg class="wi" viewBox="0 0 24 24" aria-hidden="true"><circle cx="12" cy="12" r="3"/><path d="M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 1 1-2.83 2.83l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 1 1-4 0v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 1 1-2.83-2.83l.06-.06A1.65 1.65 0 0 0 4.68 15a1.65 1.65 0 0 0-1.51-1H3a2 2 0 1 1 0-4h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 1 1 2.83-2.83l.06.06A1.65 1.65 0 0 0 9 4.68a1.65 1.65 0 0 0 1-1.51V3a2 2 0 1 1 4 0v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 1 1 2.83 2.83l-.06.06A1.65 1.65 0 0 0 19.4 9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 1 1 0 4h-.09a1.65 1.65 0 0 0-1.51 1z"/></svg>设置<span id="ws-menu-dot"></span></button>
869
+ <button onclick="wsMenuGo(() => location.href = '/grid')"><svg class="wi" viewBox="0 0 24 24" aria-hidden="true"><rect x="3" y="3" width="7" height="7" rx="1"/><rect x="14" y="3" width="7" height="7" rx="1"/><rect x="3" y="14" width="7" height="7" rx="1"/><rect x="14" y="14" width="7" height="7" rx="1"/></svg>分屏<small>多任务并排</small></button>
870
+ <button onclick="wsMenuGo(openNoteSheet)"><svg class="wi" viewBox="0 0 24 24" aria-hidden="true"><polyline points="22 12 16 12 14 15 10 15 8 12 2 12"/><path d="M5.45 5.11L2 12v6a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-6l-3.45-6.89A2 2 0 0 0 16.76 4H7.24a2 2 0 0 0-1.79 1.11z"/></svg>随手记<small>先记进草稿箱</small></button>
871
+ <button onclick="wsMenuGo(openDoctor)"><svg class="wi" viewBox="0 0 24 24" aria-hidden="true"><polyline points="22 12 18 12 15 21 9 3 6 12 2 12"/></svg>会话体检</button>
872
+ <button onclick="wsMenuGo(showUsage)"><svg class="wi" viewBox="0 0 24 24" aria-hidden="true"><line x1="18" y1="20" x2="18" y2="10"/><line x1="12" y1="20" x2="12" y2="4"/><line x1="6" y1="20" x2="6" y2="14"/></svg>用量</button>
873
+ <button onclick="wsMenuGo(openMigrateAll)"><svg class="wi" viewBox="0 0 24 24" aria-hidden="true"><path d="M21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16z"/><polyline points="3.27 6.96 12 12.01 20.73 6.96"/><line x1="12" y1="22.08" x2="12" y2="12"/></svg>打包全部任务<small>换电脑一次带走</small></button>
874
+ <button onclick="wsMenuGo(openHelpSheet)"><svg class="wi" viewBox="0 0 24 24" aria-hidden="true"><circle cx="12" cy="12" r="10"/><path d="M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3"/><line x1="12" y1="17" x2="12.01" y2="17"/></svg>帮助</button>
839
875
  <div id="ws-menu-acct">
840
876
  <hr>
841
- <button id="ws-menu-pw" onclick="wsMenuGo(openPasswdSheet)" style="display:none">🔑 修改密码</button>
842
- <button class="danger" onclick="wsMenuGo(doLogout)">↩ 退出登录</button>
877
+ <button id="ws-menu-pw" onclick="wsMenuGo(openPasswdSheet)" style="display:none"><svg class="wi" viewBox="0 0 24 24" aria-hidden="true"><circle cx="7.5" cy="15.5" r="5.5"/><path d="M11.4 11.6 21 2"/><path d="m16 7 3 3"/><path d="m18.5 4.5 2 2"/></svg>修改密码</button>
878
+ <button class="danger" onclick="wsMenuGo(doLogout)"><svg class="wi" viewBox="0 0 24 24" aria-hidden="true"><path d="M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4"/><polyline points="16 17 21 12 16 7"/><line x1="21" y1="12" x2="9" y2="12"/></svg>退出登录</button>
843
879
  </div>
844
880
  </div>
845
881
 
@@ -954,6 +990,7 @@
954
990
  <div class="set-card">
955
991
  <button class="set-link" onclick="closeSettings();openDoctor()">🩺 会话体检 <small>查中毒 / 过大的会话,一键重开</small></button>
956
992
  <button class="set-link" onclick="closeSettings();showUsage()">📊 用量 <small>费用 / token 统计</small></button>
993
+ <button class="set-link" onclick="closeSettings();openMigrateAll()">📦 打包全部任务 <small>换电脑时一次带走所有项目,到新 myhi 一次导入</small></button>
957
994
  </div>
958
995
 
959
996
  <!-- 大模型网关(仅管理员;单用户模式的主人就是管理员,不用再去 /admin)-->
@@ -981,8 +1018,6 @@
981
1018
  <div class="set-item" style="justify-content:flex-end"><button class="set-btn" id="set-models-save" onclick="saveSceneModels()">保存</button></div>
982
1019
  </div>
983
1020
  <div id="set-models-status" class="set-status"></div>
984
- <datalist id="set-models-dl-tools"></datalist><datalist id="set-models-dl-vision"></datalist>
985
- <datalist id="set-models-dl-all"></datalist>
986
1021
  </div>
987
1022
 
988
1023
  <div id="set-svc">
@@ -1453,7 +1488,8 @@
1453
1488
  _homeVer = await r.json();
1454
1489
  const sub = document.getElementById('set-ver-sub'), btn = document.getElementById('set-up-btn');
1455
1490
  if (!sub) return;
1456
- sub.textContent = `当前 v${_homeVer.current}` + (_homeVer.updateAvailable ? ` · 有新版 v${_homeVer.latest}` : ' · 已是最新');
1491
+ sub.textContent = `当前 v${_homeVer.current}${_homeVer.build?.commit ? '(' + _homeVer.build.commit + ')' : ''}` + (_homeVer.updateAvailable ? ` · 有新版 v${_homeVer.latest}` : ' · 已是最新');
1492
+ if (_homeVer.build?.stale) { sub.textContent += `。⚠ 程序文件其实是 v${_homeVer.build.version} 的(发布时没重新构建),新功能不会生效,请发布方重新构建后发布`; sub.style.color = 'var(--red)'; }
1457
1493
  btn.style.display = _homeVer.updateAvailable ? '' : 'none';
1458
1494
  btn.textContent = '升级到 v' + _homeVer.latest;
1459
1495
  document.getElementById('settings-btn').classList.toggle('has-dot', !!_homeVer.updateAvailable);
@@ -1520,6 +1556,8 @@
1520
1556
  ask: '「问一问」和解释,建议选便宜快速的;留空 = sonnet',
1521
1557
  voice: '语音转成书面文字,建议选便宜的;留空 = 同问一问',
1522
1558
  vision: '配了就用:聊天框发的图片先用它转成文字再交给主模型(多花几秒,聊天里可点开核对);主模型看不了图时一定要配,如本地的 m1-vision。留空 = 图片直接发给主模型。提示用户:截图标注尽量配文字,红框 / 箭头的指向看图模型常认错',
1559
+ minutes: '整理会议纪要用的模型(逐字稿长,选上下文大、中文好的);留空 = 跟主任务一样',
1560
+ image: '「出图」页默认用的出图模型(如 glm-image、cogview-4、image-01);留空 = 网关上的第一个出图模型',
1523
1561
  visionPro: '可选:重要截图(复杂标注的 bug 单、设计稿评审)发送时点「🔍 高精度」改用它,如网关上的 Claude 等云端多模态模型;留空 = 不显示这个开关',
1524
1562
  };
1525
1563
  // ── 大模型网关 ────────────────────────────────────────────
@@ -1546,10 +1584,79 @@
1546
1584
  const baseUrl = document.getElementById('set-gw-url').value.trim(), apiKey = document.getElementById('set-gw-key').value.trim();
1547
1585
  if (baseUrl && !/^https?:\/\//i.test(baseUrl)) { setStatus('set-gw-status', '网关地址要以 http:// 或 https:// 开头'); return; }
1548
1586
  let r; try { r = await (await fetch('/api/gateway', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ baseUrl, apiKey, syncClaude: document.getElementById('set-gw-sync').checked }) })).json(); } catch (e) { r = { error: e.message }; }
1549
- setStatus('set-gw-status', r.ok ? '已保存:新建的任务走新网关;正在跑的任务下次重启 AI 后生效' + (r.synced ? `。已同步到 ${r.synced},终端里新开的 claude 生效` : '') : '保存失败:' + (r.error || ''));
1587
+ setStatus('set-gw-status', r.ok ? '已保存:新建的任务走新网关;已开着的任务从下一条消息起生效(对话保留)' + (r.synced ? `。已同步到 ${r.synced},终端里新开的 claude 生效` : '') : '保存失败:' + (r.error || ''));
1550
1588
  if (r.ok) { await loadGatewayCfg(); fetch('/api/models?refresh=1').catch(() => {}).finally(loadSceneModels); }
1551
1589
  };
1552
1590
 
1591
+ // ── 模型下拉:点开总是列出全部候选(当前值高亮),打字才过滤;也可以手填 ─────────
1592
+ let _mpLists = { tools: [], all: [], vision: [] };
1593
+ let _mpInp = null, _mpAct = -1, _mpItems = [];
1594
+ function mpRender(filter) {
1595
+ const pop = document.getElementById('mp-pop');
1596
+ const all = _mpLists[_mpInp.dataset.mp] || [];
1597
+ const q = (filter || '').trim().toLowerCase();
1598
+ const list = q ? all.filter(o => (o.id + ' ' + o.meta).toLowerCase().includes(q)) : all;
1599
+ _mpItems = [{ id: '', meta: '留空:用这个场景的默认' }, ...list];
1600
+ const cur = _mpInp.value.trim();
1601
+ _mpAct = Math.max(0, _mpItems.findIndex(o => o.id === cur));
1602
+ pop.innerHTML = _mpItems.map((o, i) => `<div class="mp-o${o.id === cur ? ' cur' : ''}${i === _mpAct ? ' act' : ''}" data-i="${i}"><b>${o.id ? esc(o.id) : '默认'}</b>${o.meta ? `<small>${esc(o.meta)}</small>` : ''}</div>`).join('')
1603
+ + (q && !list.length ? `<div class="mp-empty">网关列表里没有「${esc(q)}」,保存时按手填的名字用</div>` : '');
1604
+ pop.querySelector('.mp-o.act')?.scrollIntoView({ block: 'nearest' });
1605
+ }
1606
+ function mpPlace() {
1607
+ const pop = document.getElementById('mp-pop'), r = _mpInp.getBoundingClientRect();
1608
+ const w = Math.max(r.width, 260), below = innerHeight - r.bottom - 12, above = r.top - 12;
1609
+ const h = Math.min(360, Math.max(below, above));
1610
+ pop.style.width = w + 'px'; pop.style.maxHeight = h + 'px';
1611
+ pop.style.left = Math.min(innerWidth - w - 8, Math.max(8, r.right - w)) + 'px';
1612
+ pop.style.top = (below >= Math.min(220, above) ? r.bottom + 4 : Math.max(8, r.top - 4 - Math.min(h, pop.scrollHeight))) + 'px';
1613
+ }
1614
+ function mpOpen(inp, showAll) {
1615
+ _mpInp = inp;
1616
+ mpRender(showAll ? '' : inp.value);
1617
+ document.getElementById('mp-pop').classList.add('open');
1618
+ mpPlace();
1619
+ }
1620
+ function mpClose() { document.getElementById('mp-pop').classList.remove('open'); _mpInp = null; }
1621
+ function mpPick(i) {
1622
+ const o = _mpItems[i]; if (!o || !_mpInp) return;
1623
+ const inp = _mpInp;
1624
+ inp.value = o.id;
1625
+ inp.dispatchEvent(new Event('input', { bubbles: true })); // 触发「保存」出现 + 不适合提示
1626
+ mpClose();
1627
+ }
1628
+ function mpInit() {
1629
+ const pop = document.createElement('div'); pop.id = 'mp-pop'; document.body.appendChild(pop);
1630
+ pop.addEventListener('mousedown', (e) => e.preventDefault()); // 不让输入框失焦
1631
+ pop.addEventListener('click', (e) => { const el = e.target.closest('.mp-o'); if (el) mpPick(+el.dataset.i); });
1632
+ const rows = document.getElementById('set-models-rows');
1633
+ rows.addEventListener('focusin', (e) => { if (e.target.dataset?.mp) mpOpen(e.target, true); });
1634
+ rows.addEventListener('input', (e) => { if (e.target.dataset?.mp && e.isTrusted) { if (_mpInp !== e.target) mpOpen(e.target, false); else { mpRender(e.target.value); mpPlace(); } } });
1635
+ rows.addEventListener('focusout', (e) => { if (e.target.dataset?.mp) setTimeout(() => { if (_mpInp === e.target && document.activeElement !== e.target) mpClose(); }, 120); });
1636
+ rows.addEventListener('mousedown', (e) => {
1637
+ const c = e.target.closest('[data-mp-caret]'); if (!c) return;
1638
+ e.preventDefault();
1639
+ const inp = c.parentElement.querySelector('input');
1640
+ if (_mpInp === inp) { mpClose(); return; }
1641
+ inp.focus(); mpOpen(inp, true);
1642
+ });
1643
+ rows.addEventListener('keydown', (e) => {
1644
+ if (!e.target.dataset?.mp) return;
1645
+ if (!_mpInp) { if (e.key === 'ArrowDown') { mpOpen(e.target, true); e.preventDefault(); } return; }
1646
+ const n = _mpItems.length;
1647
+ if (e.key === 'ArrowDown' || e.key === 'ArrowUp') {
1648
+ e.preventDefault(); _mpAct = (_mpAct + (e.key === 'ArrowDown' ? 1 : n - 1)) % n;
1649
+ pop.querySelectorAll('.mp-o').forEach((el, i) => el.classList.toggle('act', i === _mpAct));
1650
+ pop.querySelector('.mp-o.act')?.scrollIntoView({ block: 'nearest' });
1651
+ } else if (e.key === 'Enter') { e.preventDefault(); mpPick(_mpAct); }
1652
+ else if (e.key === 'Escape') { e.stopPropagation(); mpClose(); }
1653
+ });
1654
+ // 设置面板滚动 / 窗口变化时跟着输入框走
1655
+ document.getElementById('set-sheet')?.addEventListener('scroll', () => { if (_mpInp) mpPlace(); }, true);
1656
+ addEventListener('resize', () => { if (_mpInp) mpPlace(); });
1657
+ }
1658
+ if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', mpInit); else mpInit();
1659
+
1553
1660
  async function loadSceneModels() {
1554
1661
  let d; try { d = await (await fetch('/api/models')).json(); } catch { return; }
1555
1662
  if (!d.ok) return;
@@ -1568,14 +1675,20 @@
1568
1675
  const opt = (m) => `<option value="${esc(m.id)}">${esc([m.name !== m.id ? m.name : '', m.kind === 'alias' && m.target ? '→ ' + m.target : '', (m.tags || []).includes('cheap') ? '便宜' : '', m.multiplier != null ? m.multiplier + 'x' : '', (m.caps || []).includes('vision') ? '能看图' : ''].filter(Boolean).join(' · '))}</option>`;
1569
1676
  const aliases = ''; // 模型只从网关目录选(不再列 Claude 别名)
1570
1677
  const cheapFirst = [...ms].sort((a, b) => ((b.tags || []).includes('cheap') - (a.tags || []).includes('cheap')));
1571
- document.getElementById('set-models-dl-tools').innerHTML = ms.filter(m => !m.fit?.main).map(opt).join('') + aliases;
1572
- document.getElementById('set-models-dl-all').innerHTML = cheapFirst.map(opt).join('') + aliases;
1573
- document.getElementById('set-models-dl-vision').innerHTML = cheapFirst.filter(m => (m.caps || []).includes('vision')).map(opt).join('') + aliases;
1678
+ const meta = (m) => [m.name !== m.id ? m.name : '', m.kind === 'alias' && m.target ? '→ ' + m.target : '', (m.tags || []).includes('cheap') ? '便宜' : '', m.multiplier != null ? m.multiplier + 'x' : '', (m.caps || []).includes('vision') ? '能看图' : ''].filter(Boolean).join(' · ');
1679
+ const item = (m) => ({ id: m.id, meta: meta(m) });
1680
+ _mpLists = {
1681
+ tools: ms.filter(m => !m.fit?.main).map(item),
1682
+ all: cheapFirst.map(item),
1683
+ vision: cheapFirst.filter(m => (m.caps || []).includes('vision')).map(item),
1684
+ // 出图模型:网关标了 image_generation,或名字像出图模型(旧网关没标能力时)
1685
+ image: ms.filter(m => (m.caps || []).includes('image_generation') || m.image || (/(^|[-_/.])(image|cogview|seedream|wanx|flux|jimeng)/i.test(m.id) && !/vision|[-_]vl\b|ocr/i.test(m.id))).map(item),
1686
+ };
1574
1687
  const TOOL_SCENES = { main: 1, plan: 1, subagent: 1, vision: 1, visionPro: 1 };
1575
- const DL = (k) => k === 'vision' || k === 'visionPro' ? 'set-models-dl-vision' : TOOL_SCENES[k] ? 'set-models-dl-tools' : 'set-models-dl-all';
1688
+ const DL = (k) => k === 'image' ? 'image' : k === 'vision' || k === 'visionPro' ? 'vision' : TOOL_SCENES[k] ? 'tools' : 'all';
1576
1689
  document.getElementById('set-models-rows').innerHTML = Object.entries(d.sceneLabels || {}).map(([k, label]) =>
1577
1690
  `<div class="set-item inp"><div class="set-lbl">${esc(label)}<small>${esc(SCENE_HINT[k] || '')}</small></div>
1578
- <div class="set-ctl"><input class="set-inp" data-scene="${esc(k)}" list="${DL(k)}" value="${esc(d.scenes?.[k] || '')}" placeholder="默认" autocomplete="off" spellcheck="false"></div>
1691
+ <div class="set-ctl"><div class="mp-wrap"><input class="set-inp" data-scene="${esc(k)}" data-mp="${DL(k)}" value="${esc(d.scenes?.[k] || '')}" placeholder="默认" autocomplete="off" spellcheck="false"><button type="button" class="mp-caret" tabindex="-1" data-mp-caret aria-label="选择模型">▾</button></div></div>
1579
1692
  <div class="set-warn" data-warn="${esc(k)}" style="display:none;font-size:0.72rem;color:var(--yellow,#d29922)"></div></div>`).join('');
1580
1693
  // 填了不适合这个场景的模型(不支持工具等)→ 输入框下提示原因(不硬拦:网关元数据可能没填全)
1581
1694
  const byId = Object.fromEntries(ms.map(m => [m.id, m]));
@@ -1598,7 +1711,7 @@
1598
1711
  document.querySelectorAll('#set-models-rows [data-scene]').forEach(i => { body[i.dataset.scene] = i.value.trim(); });
1599
1712
  let r; try { r = await (await fetch('/api/model-scenes', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body) })).json(); } catch (e) { r = { ok: false, error: e.message }; }
1600
1713
  if (r.ok) document.getElementById('set-models-save').classList.remove('dirty');
1601
- setStatus('set-models-status', r.ok ? '已保存。新开的任务和下一次重启的 AI 进程生效;正在跑的任务在下次重启 AI 后生效' : '保存失败:' + (r.error || ''));
1714
+ setStatus('set-models-status', r.ok ? '已保存:新开的任务马上生效;已开着的任务从下一条消息起生效(对话保留)' : '保存失败:' + (r.error || ''));
1602
1715
  };
1603
1716
 
1604
1717
  async function loadRegistry() {
@@ -1811,7 +1924,7 @@
1811
1924
  + (foldable ? ';cursor:pointer' : '');
1812
1925
  return `<div class="group-header"${attrs} style="${style}">
1813
1926
  ${foldable ? `<span style="display:inline-block;width:0.7rem">${off ? '▸' : '▾'}</span>` : ''}
1814
- <span>${esc(label)}</span>
1927
+ <span data-ico>${esc(label)}</span>
1815
1928
  <span style="color:var(--border,var(--border2))">·</span>
1816
1929
  <span style="font-weight:400">${count}</span>
1817
1930
  </div>`;
@@ -2121,7 +2234,7 @@
2121
2234
 
2122
2235
  window.openMigrateImport = function() {
2123
2236
  const box = migSheet(`<h3>📦 从迁移包导入<button data-mig-close>✕</button></h3>
2124
- <div class="mig-intro">把另一台 myhi 导出的任务(<code>.myhipack</code> 文件)导入到这台电脑,导入后会生成一个新任务,项目文件和 AI 对话都在,可以接着做。</div>
2237
+ <div class="mig-intro">把另一台 myhi 导出的任务(<code>.myhipack</code> 文件)导入到这台电脑,导入后会生成新任务,项目文件和 AI 对话都在,可以接着做。<b>「打包全部任务」导出的总包</b>也在这里导入,会一次恢复所有项目。</div>
2125
2238
  <div class="mig-card"><b>还没有迁移包?</b><div class="mig-dim">在原来那台电脑的 myhi 首页,点任务右边的 <b>⋯</b> → <b>📦 迁移到另一台 myhi</b> → 下载迁移包,再用微信 / U 盘 / 网盘传到这台电脑。</div></div>
2126
2239
  <div class="mig-card" id="mig-step1"><b>① 选择迁移包</b><div style="margin-top:0.4rem"><input type="file" id="mig-file" accept="${'.myhipack'},application/gzip"></div>
2127
2240
  <div id="mig-up" style="display:none"><div class="mig-bar"><div></div></div><span class="mig-dim" id="mig-up-t">上传中…</span></div></div>
@@ -2139,7 +2252,7 @@
2139
2252
  let r; try { r = JSON.parse(xhr.responseText); } catch { r = { ok: false, error: '上传失败(' + xhr.status + ')' }; }
2140
2253
  if (!r.ok) { t.innerHTML = '<span class="mig-warn">' + esc(r.error) + '</span>'; return; }
2141
2254
  bar.style.width = '100%'; t.textContent = '已上传,请确认下面的信息';
2142
- showMigrateConfirm(step2, r);
2255
+ if (r.manifest?.myhiBundle) showBundleConfirm(step2, r); else showMigrateConfirm(step2, r);
2143
2256
  };
2144
2257
  xhr.onerror = () => { t.innerHTML = '<span class="mig-warn">上传失败,网络中断了,请重试</span>'; };
2145
2258
  xhr.send(fd);
@@ -2182,6 +2295,92 @@
2182
2295
  };
2183
2296
  }
2184
2297
 
2298
+ // ── 一键打包全部任务(首页设置 › 工具)──────────────────────────────
2299
+ window.openMigrateAll = async function() {
2300
+ const box = migSheet(`<h3>📦 打包全部任务<button data-mig-close>✕</button></h3>
2301
+ <div class="mig-intro">把这台 myhi 上${_isAdmin ? '' : '你的'}<b>所有任务</b>打成<b>一个文件</b>,带到另一台电脑的 myhi <b>一次导入</b>,全部恢复成任务、可以接着聊。同一个项目文件夹下的多个任务,项目文件只打一份。</div>
2302
+ <div class="mig-card" id="mig-what"><span class="mig-dim">正在统计各项目要打包的内容…(项目多时要几秒)</span></div>
2303
+ <div class="mig-card"><b>怎么用(3 步)</b><ol>
2304
+ <li>点下面「下载总迁移包」,得到一个 <code>.myhipack</code> 文件</li>
2305
+ <li>用 U 盘 / 网盘 / 微信,把它传到另一台电脑</li>
2306
+ <li>在那台电脑的 myhi 首页 → <b>+ 新建任务</b> → <b>📦 从迁移包导入</b>,选这个文件,选好放在哪个根目录,一次导入全部</li></ol></div>
2307
+ <div class="mig-dim" style="margin-bottom:0.5rem">🔒 包里是所有项目的原文件(和对话记录),请像保管项目代码一样保管。</div>
2308
+ <button class="mig-btn" id="mig-dl" disabled>⬇ 下载总迁移包</button>
2309
+ <button class="mig-btn2" data-mig-close>取消</button>`);
2310
+ let p;
2311
+ try { p = await (await fetch('/api/migrate-all/preview')).json(); } catch (e) { p = { ok: false, error: e.message }; }
2312
+ const what = box.querySelector('#mig-what');
2313
+ if (!p.ok) { what.innerHTML = '<span class="mig-warn">统计失败:' + esc(p.error || '') + '</span>'; return; }
2314
+ const ps = p.projects || [];
2315
+ if (!ps.length) { what.innerHTML = '<span class="mig-dim">这里还没有任务,没什么可打包的。</span>'; return; }
2316
+ const tasks = ps.reduce((n, x) => n + x.tasks.length, 0);
2317
+ const files = ps.reduce((n, x) => n + x.files, 0), bytes = ps.reduce((n, x) => n + x.bytes, 0);
2318
+ const convN = ps.reduce((n, x) => n + x.tasks.filter(t => t.hasConv).length, 0);
2319
+ const convB = ps.reduce((n, x) => n + x.tasks.reduce((m, t) => m + (t.convBytes || 0), 0), 0);
2320
+ const memN = ps.reduce((n, x) => n + x.memFiles, 0);
2321
+ const secrets = [...new Set(ps.flatMap(x => x.secrets))];
2322
+ const busy = ps.some(x => x.tasks.some(t => t.busy));
2323
+ const skipped = [...new Set(ps.flatMap(x => x.skipped))];
2324
+ what.innerHTML = `<b>包里会有:${ps.length} 个项目、${tasks} 个任务,项目文件 ${files} 个,共 ${fmtSize(bytes)}</b>
2325
+ <div style="max-height:32vh;overflow-y:auto;margin:0.35rem 0">${ps.map(x => `<div class="mig-proj"><span>📁</span><div style="min-width:0"><b>${esc(x.name)}</b> <span class="mig-dim">· ${x.tasks.length} 个任务 · ${x.files} 个文件 · ${fmtSize(x.bytes)}</span>
2326
+ <div class="mig-dim" style="word-break:break-all">${esc(x.cwd)}${x.exists ? '' : ' <span class="mig-warn">(文件夹已不存在,只带对话记录)</span>'}${x.truncated ? ' <span class="mig-warn">(文件太多,只打包前 20 万个)</span>' : ''}</div>
2327
+ <div class="mig-dim">${x.tasks.map(t => esc(t.title || '未命名') + (t.hasConv ? '' : '(无对话记录)')).join('、')}</div></div></div>`).join('')}</div>
2328
+ ${skipped.length ? `<div class="mig-row"><span>⏭</span><div>不打包(可重新生成,到新电脑再装):${skipped.map(d => `<code>${esc(d)}</code>`).join('、')}</div></div>` : ''}
2329
+ <div class="mig-row"><span>💬</span><label style="cursor:pointer"><input type="checkbox" id="mig-conv" ${convN ? 'checked' : 'disabled'}> 带上 AI 对话记录(${convN} 个任务${convN ? ',' + fmtSize(convB) : ''})<br><small>带上后在新电脑上可以<b>接着聊</b>;对话里的路径会自动改成新位置。</small></label></div>
2330
+ <div class="mig-row"><span>🧠</span><label style="cursor:pointer"><input type="checkbox" id="mig-mem" ${memN ? 'checked' : 'disabled'}> 带上项目记忆(${memN} 个文件)</label></div>
2331
+ ${secrets.length ? `<div class="mig-row"><span>🔑</span><div><b>密钥不会带走</b>(${secrets.map(esc).join('、')})<br><small>到新电脑后在各任务会话页「🔑 密钥」里重新录入。</small></div></div>` : ''}
2332
+ ${busy ? '<div class="mig-row mig-warn"><span>⚠️</span><div>有任务的 AI 正在执行,建议等它这一轮结束再打包,否则最后一轮对话可能不完整。</div></div>' : ''}`;
2333
+ const btn = box.querySelector('#mig-dl'); btn.disabled = false;
2334
+ btn.onclick = () => {
2335
+ const conv = box.querySelector('#mig-conv')?.checked ? '1' : '0';
2336
+ const mem = box.querySelector('#mig-mem')?.checked ? '1' : '0';
2337
+ const a = document.createElement('a'); a.href = '/api/migrate-all/export?conv=' + conv + '&mem=' + mem; a.download = '';
2338
+ document.body.appendChild(a); a.click(); a.remove();
2339
+ btn.textContent = '✓ 已开始下载'; btn.disabled = true;
2340
+ btn.insertAdjacentHTML('afterend', '<div class="mig-dim" style="margin-top:0.4rem">项目多、文件大时下载要一会儿(边打包边下载),留意浏览器下载栏。下载完成后按上面第 2、3 步操作。</div>');
2341
+ };
2342
+ };
2343
+ // 总迁移包:选根目录 + 每个项目一个子文件夹(可改名 / 取消勾选),一次导入
2344
+ function showBundleConfirm(el, r) {
2345
+ const m = r.manifest, ps = m.projects || [];
2346
+ let root = taskRoot() || (r.userDir || '');
2347
+ const tasks = ps.reduce((n, x) => n + (x.tasks || []).length, 0);
2348
+ const secrets = [...new Set(ps.flatMap(x => x.secrets || []))];
2349
+ el.innerHTML = `<div class="mig-card"><b>② 确认总迁移包内容</b>
2350
+ <div class="mig-row"><span>📦</span><div><b>${ps.length}</b> 个项目、<b>${tasks}</b> 个任务<br><small>来自「${esc(m.from || '另一台 myhi')}」,${esc(new Date(m.exportedAt).toLocaleString())} 打包</small></div></div>
2351
+ ${secrets.length ? `<div class="mig-row mig-warn"><span>🔑</span><div>导入后需要重新录入的密钥:${secrets.map(esc).join('、')}<br><small>在对应任务会话页「🔑 密钥」里填。</small></div></div>` : ''}
2352
+ </div>
2353
+ <div class="mig-card"><b>③ 放到这台电脑的哪个根目录</b>
2354
+ <div style="margin:0.35rem 0"><input type="text" id="mig-root" value="${esc(root)}" placeholder="例如 D:\\projects 或 /home/me/projects" spellcheck="false"></div>
2355
+ <div class="mig-dim">每个项目放在根目录下的同名子文件夹里(名字可改)。<b>已存在且有文件</b>的文件夹会跳过,不覆盖。</div>
2356
+ <div style="max-height:34vh;overflow-y:auto;margin-top:0.4rem">${ps.map(x => `<div class="mig-proj"><input type="checkbox" data-key="${esc(x.key)}" checked style="margin-top:0.35rem"><div style="flex:1;min-width:0">
2357
+ <div><b>${esc(x.name)}</b> <span class="mig-dim">· ${(x.tasks || []).length} 个任务 · ${x.files} 个文件 · ${fmtSize(x.bytes || 0)}${(x.tasks || []).some(t => t.conv) ? ' · 带对话记录' : ''}</span></div>
2358
+ <input type="text" data-name="${esc(x.key)}" value="${esc(sanitizeTaskName(x.name))}" spellcheck="false" title="放在根目录下的文件夹名">
2359
+ <div class="mig-dim">${(x.tasks || []).map(t => esc(t.title || '未命名')).join('、')}</div></div></div>`).join('')}</div></div>
2360
+ <button class="mig-btn" id="mig-go">导入选中的项目</button><div id="mig-res"></div>`;
2361
+ el.querySelector('#mig-go').onclick = async (ev) => {
2362
+ const btn = ev.target, res = el.querySelector('#mig-res');
2363
+ const rootV = el.querySelector('#mig-root').value.trim();
2364
+ if (!rootV) { res.innerHTML = '<div class="mig-warn">请填写根目录</div>'; return; }
2365
+ const projects = {};
2366
+ el.querySelectorAll('[data-key]').forEach(c => { if (c.checked) projects[c.dataset.key] = el.querySelector(`[data-name="${c.dataset.key}"]`).value.trim(); });
2367
+ if (!Object.keys(projects).length) { res.innerHTML = '<div class="mig-warn">至少勾选一个项目</div>'; return; }
2368
+ btn.disabled = true; btn.textContent = '导入中…(项目多、文件多时要等一会儿)'; res.innerHTML = '';
2369
+ let d;
2370
+ try { d = await (await fetch('/api/migrate/import-all', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ token: r.token, root: rootV, projects }) })).json(); }
2371
+ catch (e) { d = { ok: false, error: e.message }; }
2372
+ const skippedHtml = (d.skipped || []).length ? `<div class="mig-warn" style="margin-top:0.4rem">跳过 ${d.skipped.length} 个:${d.skipped.map(x => esc(x.name) + '(' + esc(x.reason) + ')').join(';')}</div>` : '';
2373
+ if (!d.ok) { btn.disabled = false; btn.textContent = '导入选中的项目'; res.innerHTML = '<div class="mig-warn" style="margin-top:0.4rem">' + esc(d.error) + '</div>' + skippedHtml; return; }
2374
+ btn.textContent = '✓ 导入完成';
2375
+ const mm = d.memory && (d.memory.written || d.memory.kept) ? `项目记忆导入 ${d.memory.written} 个${d.memory.kept ? `(${d.memory.kept} 个这台电脑上已有,保留了这台的)` : ''}。` : '';
2376
+ res.innerHTML = `<div style="margin-top:0.5rem">已导入 <b>${d.projects}</b> 个项目、<b>${d.created.length}</b> 个任务,带对话记录的打开后可以接着聊。${mm}</div>${skippedHtml}
2377
+ ${(d.secrets || []).length ? `<div class="mig-warn">别忘了在对应任务会话页「🔑 密钥」里重新录入:${d.secrets.map(esc).join('、')}</div>` : ''}
2378
+ <div style="max-height:24vh;overflow-y:auto;margin-top:0.3rem">${d.created.map(c => `<div class="mig-dim">✓ ${esc(c.title || '未命名')} → <code>${esc(c.cwd)}</code>${c.conv ? '' : '(新对话)'}</div>`).join('')}</div>
2379
+ <button class="mig-btn" data-mig-close>完成</button>`;
2380
+ try { socket.emit('list'); } catch {}
2381
+ };
2382
+ }
2383
+
2185
2384
  function openSession(id) {
2186
2385
  if (wsOn()) return wsOpen(id);
2187
2386
  window.location.href = `/terminal/${id}`;
@@ -2192,7 +2391,46 @@
2192
2391
  const WS_MQ = matchMedia('(min-width: 1024px)');
2193
2392
  const WS_KEEP = 5;
2194
2393
  function wsOn() { return document.body.classList.contains('ws'); }
2394
+ // ── 一级导航:出图 / 语音处理 在工作台右侧打开(和任务一样留在后台,来回切不重载);手机直接进页面 ──
2395
+ const TOOL_URL = { studio: '/studio', voice: '/minutes' };
2396
+ const TOOL_TITLE = { studio: '出图', voice: '语音处理' };
2397
+ const _toolFrames = new Map();
2398
+ let _tool = null, _lastTask = null;
2399
+ let _toolPending = new URLSearchParams(location.search).get('tool'); // 刷新后回到上次的工具页
2400
+ function setNavActive(k) {
2401
+ document.querySelectorAll('#main-nav [data-nav]').forEach(b => b.classList.toggle('on', b.dataset.nav === k));
2402
+ document.querySelectorAll('#ws-rail [data-nav]').forEach(b => b.classList.toggle('on', b.dataset.nav === k));
2403
+ }
2404
+ function hideTools() { for (const f of _toolFrames.values()) f.style.display = 'none'; _tool = null; setNavActive('tasks'); }
2405
+ window.mainNav = function(k) {
2406
+ if (k === 'tasks') {
2407
+ if (!_tool) return;
2408
+ const back = _lastTask && _allSessions.some(x => x.id === _lastTask) ? _lastTask : null;
2409
+ hideTools();
2410
+ return back ? wsOpen(back) : wsShowWelcome();
2411
+ }
2412
+ if (!TOOL_URL[k]) return;
2413
+ if (!wsOn()) { location.href = TOOL_URL[k]; return; }
2414
+ if (_wsCur) _lastTask = _wsCur;
2415
+ let f = _toolFrames.get(k);
2416
+ if (!f) {
2417
+ f = document.createElement('iframe');
2418
+ f.src = TOOL_URL[k] + '?embed=ws';
2419
+ f.setAttribute('allow', 'microphone; clipboard-read; clipboard-write');
2420
+ document.getElementById('ws-main').appendChild(f);
2421
+ _toolFrames.set(k, f);
2422
+ }
2423
+ for (const fr of _wsFrames.values()) fr.style.display = 'none';
2424
+ for (const [n, fr] of _toolFrames) fr.style.display = n === k ? '' : 'none';
2425
+ document.getElementById('ws-welcome').style.display = 'none';
2426
+ _wsCur = null; _tool = k;
2427
+ history.replaceState(null, '', '/?tool=' + k);
2428
+ document.title = TOOL_TITLE[k] + ' — myhi';
2429
+ setNavActive(k);
2430
+ wsMarkActive();
2431
+ };
2195
2432
  function wsOpen(id) {
2433
+ if (_tool) hideTools();
2196
2434
  _wsCur = id;
2197
2435
  let f = _wsFrames.get(id);
2198
2436
  if (f) _wsFrames.delete(id);
@@ -2213,6 +2451,7 @@
2213
2451
  setTimeout(() => f.contentWindow?.focus(), 50);
2214
2452
  }
2215
2453
  function wsShowWelcome() {
2454
+ if (_tool) hideTools();
2216
2455
  _wsCur = null;
2217
2456
  for (const fr of _wsFrames.values()) fr.style.display = 'none';
2218
2457
  document.getElementById('ws-welcome').style.display = '';
@@ -2248,6 +2487,7 @@
2248
2487
  // 每次列表重绘后:刷新前打开的任务等列表到了再打开;当前任务被删了就回欢迎页、回收它的会话页
2249
2488
  function wsAfterRender() {
2250
2489
  if (!wsOn()) return;
2490
+ if (_toolPending) { const k = _toolPending; _toolPending = null; mainNav(k); }
2251
2491
  if (_wsPending && _allSessions.some(x => x.id === _wsPending)) { const id = _wsPending; _wsPending = null; wsOpen(id); return; }
2252
2492
  for (const [k, fr] of _wsFrames) if (!_allSessions.some(x => x.id === k)) { fr.remove(); _wsFrames.delete(k); if (k === _wsCur) wsShowWelcome(); }
2253
2493
  renderRail();
@@ -2284,6 +2524,7 @@
2284
2524
  const banner = document.getElementById('ai-banner');
2285
2525
  const target = on ? document.getElementById('ws-welcome') : document.getElementById('view-controls');
2286
2526
  if (on) target.appendChild(banner); else target.parentNode.insertBefore(banner, target);
2527
+ if (!on && _tool) { location.href = TOOL_URL[_tool]; return; } // 窗口拉窄:进工具的独立页面
2287
2528
  if (!on && _wsCur) { location.href = '/terminal/' + encodeURIComponent(_wsCur); return; } // 窗口拉窄:直接进当前任务的会话页
2288
2529
  fitHeader();
2289
2530
  }
Binary file