agent-loft 0.2.44 → 0.2.46

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/web/lib/ws.js CHANGED
@@ -8,6 +8,7 @@ import { renderTopbar } from "../views/topbar.js";
8
8
  import { applyEvent, openConversation } from "../views/messages.js";
9
9
  import { upsertInteraction } from "../views/interaction.js";
10
10
  import { setBusy } from "../views/composer.js";
11
+ import { shownHere } from "./shell.js";
11
12
  import { renderScheduled } from "../views/schedule.js";
12
13
 
13
14
  // ---------- WebSocket ----------
@@ -97,7 +98,8 @@ export const WS = {
97
98
  * 窗口开着人走开了(电脑上停在这条会话、人在用手机),照样推
98
99
  */
99
100
  presence() {
100
- const visible = document.visibilityState === "visible" && document.hasFocus() && Date.now() - lastInput < IDLE_MS;
101
+ // 多服务器:外壳切到了别的服务器、或者这台被嵌着但没在显示,也算没在看
102
+ const visible = document.visibilityState === "visible" && document.hasFocus() && Date.now() - lastInput < IDLE_MS && shownHere();
101
103
  // 在定时任务、远程控制页上:没在看哪条对话(远程控制页不清 S.current,回来时对话还在)
102
104
  this.raw({ t: "presence", visible, key: S.view ? "" : (S.current ?? "") });
103
105
  },
@@ -105,6 +107,10 @@ export const WS = {
105
107
 
106
108
  // 切回窗口本身就算动了一下
107
109
  window.addEventListener("focus", () => (markActive(), WS.presence()));
110
+ document.addEventListener("aim:shell-active", () => {
111
+ if (shownHere()) markActive();
112
+ WS.presence();
113
+ });
108
114
  window.addEventListener("blur", () => WS.presence());
109
115
 
110
116
  // ---------- 有没有人在动页面 ----------
@@ -4,6 +4,7 @@ import { S } from "../state.js";
4
4
  import { renderSidebar } from "../views/sidebar.js";
5
5
  import { loadQuota, scheduleIdleQuota } from "../views/quota.js";
6
6
  import { catalogCache, catalogDefaults, catalogLoaded, renderContext, renderTopbar } from "../views/topbar.js";
7
+ import { applyShellInfo } from "../lib/shell.js";
7
8
 
8
9
  export async function saveConfig(cfg, patch) {
9
10
  try {
@@ -18,6 +19,8 @@ export async function saveConfig(cfg, patch) {
18
19
  S.agents = boot2.agents;
19
20
  S.bots = boot2.bots;
20
21
  S.workspaceRoot = boot2.workspaceRoot;
22
+ // 左上角切换的服务器可能改了
23
+ applyShellInfo(boot2.servers);
21
24
  const quotaOn = boot2.quotaEnabled !== false;
22
25
  if (boot2.quotaRefreshMin !== S.quotaRefreshMin || quotaOn !== S.quotaEnabled) {
23
26
  const turnedOn = quotaOn && !S.quotaEnabled;
@@ -11,6 +11,7 @@ import { accountTab } from "./security.js";
11
11
  import { memoryTab } from "./memory.js";
12
12
  import { skillsTab } from "./skills.js";
13
13
  import { usageTab } from "./usage.js";
14
+ import { serversTab } from "./servers.js";
14
15
  import { systemTab, usersTab } from "./users.js";
15
16
  import { hasDirty, markDirty } from "./common.js";
16
17
 
@@ -50,6 +51,7 @@ function groupsFor(cfg) {
50
51
  tabs: [
51
52
  ["飞书", (p) => feishuTab(cfg, p)],
52
53
  ["远程控制", (p) => remoteTab(cfg, p)],
54
+ ["服务器", (p) => serversTab(cfg, p)],
53
55
  ],
54
56
  },
55
57
  {
@@ -2,6 +2,7 @@ import { fill, h, toast } from "../lib/dom.js";
2
2
  import { api } from "../lib/api.js";
3
3
  import { relTime } from "../lib/time.js";
4
4
  import { currentPushSub, enablePush, pushSupport } from "../lib/push.js";
5
+ import { refreshShellPush } from "../lib/shell.js";
5
6
 
6
7
  export async function notifyTab(panel) {
7
8
  const support = pushSupport();
@@ -25,6 +26,8 @@ export async function notifyTab(panel) {
25
26
  toast(err.message);
26
27
  }
27
28
  btn.disabled = false;
29
+ // 多服务器的外壳:开关通知后,转给各台的订阅跟着变
30
+ void refreshShellPush();
28
31
  await render();
29
32
  };
30
33
  const onBtn = h("button", { class: "btn primary" }, "在此设备开启通知");
@@ -49,9 +52,11 @@ export async function notifyTab(panel) {
49
52
  h("div", { class: "muted" }, "Web 对话里 agent 回复完成、出错、需要授权或向你提问时,推送到开启了通知的设备。正在前台看着那条对话的时候不推。飞书对话由飞书自己提醒。"),
50
53
  support.ok
51
54
  ? h("div", { class: "row" }, here ? offBtn : onBtn, data.subscriptions.length ? testBtn : null)
52
- : h("div", { class: "error-text" }, support.why),
55
+ : support.framed
56
+ ? [h("div", { class: "muted" }, support.why), data.subscriptions.length ? h("div", { class: "row" }, testBtn) : null]
57
+ : h("div", { class: "error-text" }, support.why),
53
58
  // 推送用不了(比如不是 HTTPS):至少让页面开着、切到别的窗口时能弹提醒
54
- !support.ok && "Notification" in window && Notification.permission === "default"
59
+ !support.ok && !support.framed && "Notification" in window && Notification.permission === "default"
55
60
  ? h(
56
61
  "div",
57
62
  { class: "row" },
@@ -12,9 +12,14 @@ export async function accountTab(page) {
12
12
  logout.onclick = async () => {
13
13
  logout.disabled = true;
14
14
  // 退出了就别再收这个账号的通知:换个人在这台设备上登录,不能收到上一个人的
15
- await dropPushSub().catch(() => {});
16
- await api("/api/logout", { method: "POST" });
17
- location.reload();
15
+ try {
16
+ await dropPushSub();
17
+ await api("/api/logout", { method: "POST" });
18
+ location.reload();
19
+ } catch (err) {
20
+ toast(err.message);
21
+ logout.disabled = false;
22
+ }
18
23
  };
19
24
  const old = h("input", { type: "password", autocomplete: "current-password" });
20
25
  const pw = h("input", { type: "password", autocomplete: "new-password" });
@@ -0,0 +1,207 @@
1
+ import { fill, h, icon, toast } from "../lib/dom.js";
2
+ import { canFrame, openForAuth } from "../lib/shell.js";
3
+ import { field, markDirty, saveButton, saveConfig } from "./common.js";
4
+
5
+ // ---------- 设置 → 服务器 ----------
6
+ // 左上角切换到别的 agent-loft(lib/shell.js、服务端 core/servers.ts)。两件事:
7
+ // - 这台能切到哪几台(这台当外壳);
8
+ // - 允许哪些地址把这台嵌进去(这台被别人切过来)。
9
+
10
+ const HINT =
11
+ "在左上角切换到别的 agent-loft,像 Codex 桌面端切换「Codex」和「ChatGPT」那样。别的服务器的页面原样嵌在这里,各自登录、直接连它自己的服务端,这台不中转。" +
12
+ "几台要在同一个主域名下(比如 mac.example.com、nas.example.com),都要用 HTTPS;对方还要允许这台嵌入:加好后点「授权」,在打开的页面里确认。";
13
+
14
+ export function serversTab(cfg, panel) {
15
+ fill(panel, listSection(cfg), embeddersSection(cfg));
16
+ }
17
+
18
+ /** 这台能切到哪几台 */
19
+ function listSection(cfg) {
20
+ const box = h("div", { class: "section", "data-form": "" });
21
+ const selfIcon = h("input", { class: "srv-emoji", value: cfg.servers.selfIcon, placeholder: "🖥️", maxlength: 16 });
22
+ const selfName = h("input", { value: cfg.servers.selfName, placeholder: "空着用主机名" });
23
+ const rows = h("div", { class: "srv-rows" });
24
+ let list = cfg.servers.list.map((s) => ({ ...s }));
25
+
26
+ const render = () => {
27
+ fill(
28
+ rows,
29
+ list.length === 0
30
+ ? h("div", { class: "muted" }, "还没有加别的服务器")
31
+ : list.map((s, i) => {
32
+ let saved = cfg.servers.list.find((x) => x.id === s.id && x.url === s.url);
33
+ const authorize = h("button", {
34
+ class: "btn small",
35
+ disabled: !saved,
36
+ title: saved ? "在新标签页打开那台,允许这台嵌入" : "先保存",
37
+ onclick: () => saved && openForAuth(saved),
38
+ }, "授权");
39
+ const em = h("input", { class: "srv-emoji", value: s.icon, placeholder: "🗄️", maxlength: 16, oninput: () => (s.icon = em.value) });
40
+ const name = h("input", { value: s.name, placeholder: "名称", oninput: () => (s.name = name.value) });
41
+ const url = h("input", {
42
+ value: s.url,
43
+ placeholder: "https://nas.example.com",
44
+ autocapitalize: "off",
45
+ spellcheck: "false",
46
+ oninput: () => {
47
+ s.url = url.value;
48
+ saved = cfg.servers.list.find((x) => x.id === s.id && x.url === s.url);
49
+ authorize.disabled = !saved;
50
+ authorize.title = saved ? "在新标签页打开那台,允许这台嵌入" : "先保存";
51
+ },
52
+ });
53
+ const move = (d) => () => {
54
+ [list[i], list[i + d]] = [list[i + d], list[i]];
55
+ markDirty(box);
56
+ render();
57
+ };
58
+ return h(
59
+ "div",
60
+ { class: "srv-edit" },
61
+ h("div", { class: "srv-edit-fields" }, em, name, url),
62
+ h(
63
+ "div",
64
+ { class: "srv-edit-actions" },
65
+ h("button", { class: "btn small", disabled: i === 0, title: "上移", onclick: move(-1) }, "↑"),
66
+ h("button", { class: "btn small", disabled: i === list.length - 1, title: "下移", onclick: move(1) }, "↓"),
67
+ // 没保存的地址先别去授权:那边确认后会通知这边重新加载,这边得已经有它
68
+ authorize,
69
+ h(
70
+ "button",
71
+ {
72
+ class: "icon-btn",
73
+ title: "移除",
74
+ onclick: () => {
75
+ list.splice(i, 1);
76
+ markDirty(box);
77
+ render();
78
+ },
79
+ },
80
+ icon("trash"),
81
+ ),
82
+ ),
83
+ );
84
+ }),
85
+ );
86
+ };
87
+ render();
88
+
89
+ const add = h(
90
+ "button",
91
+ {
92
+ class: "btn",
93
+ onclick: () => {
94
+ list.push({ id: "", name: "", icon: "", url: "" });
95
+ markDirty(box);
96
+ render();
97
+ rows.querySelectorAll(".srv-edit-fields input:nth-child(3)")[list.length - 1]?.focus();
98
+ },
99
+ },
100
+ icon("plus"),
101
+ "添加服务器",
102
+ );
103
+
104
+ const save = async () => {
105
+ const clean = list.filter((s) => s.url.trim() || s.name.trim());
106
+ if (clean.some((s) => !s.url.trim())) {
107
+ toast("有一台没填地址");
108
+ return false;
109
+ }
110
+ const ok = await saveConfig(cfg, { servers: { selfName: selfName.value, selfIcon: selfIcon.value, list: clean } });
111
+ if (!ok) return false;
112
+ // 新加的地址要刷新页面才嵌得进来(页面的 CSP 是加载时按旧列表出的)
113
+ if (cfg.servers.list.some((s) => !canFrame(s.url))) {
114
+ toast("已保存,刷新页面后生效…");
115
+ setTimeout(() => location.reload(), 900);
116
+ }
117
+ box.replaceWith(listSection(cfg));
118
+ return true;
119
+ };
120
+
121
+ fill(
122
+ box,
123
+ h("h4", {}, "切换服务器"),
124
+ h("div", { class: "muted" }, HINT),
125
+ field("这台", h("div", { class: "srv-edit-fields self" }, selfIcon, selfName), "左上角列表里这台的图标(一个 emoji)和名字"),
126
+ h("div", { class: "field" }, h("span", {}, "其他服务器"), rows),
127
+ h("div", { class: "row" }, add, saveButton(save)),
128
+ );
129
+ return box;
130
+ }
131
+
132
+ /** 允许哪些地址把这台嵌进去 */
133
+ function embeddersSection(cfg) {
134
+ const box = h("div", { class: "section", "data-form": "" });
135
+ let list = [...cfg.servers.embedders];
136
+ const rows = h("div", {});
137
+ const input = h("input", { placeholder: "https://loft.example.com", autocapitalize: "off", spellcheck: "false" });
138
+
139
+ const render = () => {
140
+ fill(
141
+ rows,
142
+ list.length === 0
143
+ ? h("div", { class: "muted" }, "还没有")
144
+ : list.map((origin, i) =>
145
+ h(
146
+ "div",
147
+ { class: "list-item" },
148
+ h("div", { class: "grow" }, h("div", { class: "t" }, origin)),
149
+ h(
150
+ "button",
151
+ {
152
+ class: "btn small",
153
+ onclick: () => {
154
+ list.splice(i, 1);
155
+ markDirty(box);
156
+ render();
157
+ },
158
+ },
159
+ "移除",
160
+ ),
161
+ ),
162
+ ),
163
+ );
164
+ };
165
+ render();
166
+
167
+ const addOne = () => {
168
+ const v = input.value.trim();
169
+ if (!v) return;
170
+ let origin;
171
+ try {
172
+ origin = new URL(/^[a-z]+:\/\//i.test(v) ? v : `https://${v}`).origin;
173
+ } catch {
174
+ toast("地址不对");
175
+ return;
176
+ }
177
+ if (!list.includes(origin)) list.push(origin);
178
+ input.value = "";
179
+ markDirty(box);
180
+ render();
181
+ };
182
+ input.addEventListener("keydown", (e) => {
183
+ if (e.key === "Enter") {
184
+ e.preventDefault();
185
+ addOne();
186
+ }
187
+ });
188
+
189
+ const save = async () => {
190
+ const ok = await saveConfig(cfg, { servers: { embedders: list } });
191
+ if (ok) box.replaceWith(embeddersSection(cfg));
192
+ return ok;
193
+ };
194
+
195
+ fill(
196
+ box,
197
+ h("h4", {}, "允许被嵌入"),
198
+ h(
199
+ "div",
200
+ { class: "muted" },
201
+ `别的 agent-loft 要在左上角切到这台,得先允许它嵌入这台的页面。一般不用手填:在那边加上这台(${location.origin})后点「授权」,在打开的页面里确认就行。切过来时照样要登录这台的账号。`,
202
+ ),
203
+ rows,
204
+ h("div", { class: "row" }, input, h("button", { class: "btn", onclick: addOne }, "添加"), saveButton(save)),
205
+ );
206
+ return box;
207
+ }
package/web/state.js CHANGED
@@ -45,6 +45,8 @@ export const ui = {};
45
45
  * 桌面端收不到 Web Push,系统通知、Dock 角标、菜单栏的待处理数都交给它。
46
46
  */
47
47
  export const desktop = window.agentLoftDesktop ?? null;
48
+ /** 被别的 agent-loft 嵌在 iframe 里(多服务器,见 lib/shell.js)。只有服务端允许了的地址嵌得进来 */
49
+ export const framed = !desktop && window.parent !== window;
48
50
  /** 新版桌面端:额度由它统一查好推过来,页面自己不查(老版本桌面端没有 onQuota,照旧自己查) */
49
51
  export const desktopQuota = typeof desktop?.onQuota === "function";
50
52
  // 桌面端里:顶栏、侧栏顶部可以按住拖动窗口(样式见 css/topbar.css 的 .in-desktop)
package/web/views/auth.js CHANGED
@@ -2,6 +2,7 @@ import { $app, fill, h } from "../lib/dom.js";
2
2
  import { api } from "../lib/api.js";
3
3
  import { WS } from "../lib/ws.js";
4
4
  import { boot } from "./layout.js";
5
+ import { mountSwitcher } from "../lib/shell.js";
5
6
 
6
7
  // ---------- 登录 ----------
7
8
 
@@ -56,6 +57,7 @@ export async function showAuth() {
56
57
  btn,
57
58
  err,
58
59
  );
59
- fill($app, h("div", { class: "auth" }, form));
60
+ // 被嵌在别的服务器的页面里(多服务器):左上角照样能切回去,不然手机上就困在登录页了
61
+ fill($app, h("div", { class: "auth" }, mountSwitcher("auth", h("div", { class: "auth-switch", hidden: true })), form));
60
62
  (me.needsSetup ? token : askName ? name : pw).focus();
61
63
  }
@@ -225,7 +225,7 @@ export async function ensureConversation() {
225
225
  S.current = info.key;
226
226
  S.allowedAgents = S.agents.filter((a) => a.enabled).map((a) => a.id);
227
227
  S.seq.set(info.key, 0);
228
- history.replaceState(null, "", `#${encodeURIComponent(info.key)}`);
228
+ history.replaceState(history.state, "", `#${encodeURIComponent(info.key)}`);
229
229
  WS.presence();
230
230
  fill(ui.msgInner, );
231
231
  WS.subscribe(info.key, 0);
@@ -1,6 +1,6 @@
1
1
  import { $app, fill, h, icon, toast } from "../lib/dom.js";
2
2
  import { api } from "../lib/api.js";
3
- import { desktop, desktopMenu, desktopQuota, desktopSettings, remoteTabs, S, ui } from "../state.js";
3
+ import { desktop, desktopMenu, desktopQuota, desktopSettings, framed, remoteTabs, S, ui } from "../state.js";
4
4
  import { clearAppBadge, WS } from "../lib/ws.js";
5
5
  import { showAuth } from "./auth.js";
6
6
  import {
@@ -20,7 +20,8 @@ import {
20
20
  } from "./sidebar.js";
21
21
  import { applyDesktopQuota, loadQuota, renderQuota } from "./quota.js";
22
22
  import { openBotConversations, openConvContextMenu, runDesktopMenu, usableAgents } from "./topbar.js";
23
- import { showMenu } from "../lib/overlay.js";
23
+ import { confirmDialog, showMenu } from "../lib/overlay.js";
24
+ import { applyShellInfo, handleAllowEmbed, HOME, mountSwitcher, refreshShellPush, routeToServer, shellBooted, switchServer } from "../lib/shell.js";
24
25
  import { bindScrollWatch, newDraft, openConversation, scrollToBottom } from "./messages.js";
25
26
  import { renderComposer } from "./composer.js";
26
27
  import { createNav } from "./msg-nav.js";
@@ -91,6 +92,23 @@ window.addEventListener("keydown", (e) => {
91
92
  }
92
93
  });
93
94
 
95
+ // 多服务器(lib/shell.js):外壳让打开某条对话(点了这台的通知)、点了「管理服务器…」、切到别的服务器
96
+ document.addEventListener("aim:shell-open", (e) => {
97
+ if (e.detail && e.detail !== S.current) void openConversation(e.detail);
98
+ });
99
+ document.addEventListener("aim:open-settings", (e) => openSettings(e.detail));
100
+ document.addEventListener("aim:server-leave", () => closeSide());
101
+
102
+ /**
103
+ * 通知点开的地址:别的服务器的带着 srv=那台的 id(服务端 push.ts 的 relay),交给外壳切过去。
104
+ * 返回 true 表示已经交出去了
105
+ */
106
+ function routeNotice(url) {
107
+ const srv = url.searchParams.get("srv");
108
+ if (!srv || srv === HOME) return false;
109
+ return routeToServer(srv, decodeURIComponent(url.hash.slice(1)));
110
+ }
111
+
94
112
  /** 定时任务页:第一次打开时才加载 */
95
113
  export function openTasksView() {
96
114
  import("./tasks.js").then(
@@ -113,6 +131,14 @@ export async function boot() {
113
131
  S.quotaRefreshMin = data.quotaRefreshMin ?? 10;
114
132
  S.quotaEnabled = data.quotaEnabled !== false;
115
133
  S.remote = data.remote ?? null;
134
+ // 通知优先;刷新保留当前历史记录里的服务器;新打开的本机会话链接显示本机。
135
+ const landing = new URL(location.href);
136
+ const srv = landing.searchParams.get("srv");
137
+ if (srv) {
138
+ landing.searchParams.delete("srv");
139
+ history.replaceState(history.state, "", `${landing.pathname}${landing.search}${srv === HOME ? landing.hash : ""}`);
140
+ }
141
+ applyShellInfo(data.servers, srv || history.state?.loftServer || (location.hash.length > 1 ? HOME : undefined));
116
142
  applyBootstrap(data);
117
143
  S.pending = new Map(data.pending.map((i) => [i.id, i]));
118
144
  const enabled = usableAgents().map((a) => a.id);
@@ -122,6 +148,7 @@ export async function boot() {
122
148
  WS.connect();
123
149
  if (desktopQuota) desktop.onQuota(applyDesktopQuota);
124
150
  else void loadQuota();
151
+ if (srv && srv !== HOME) routeToServer(srv, decodeURIComponent(landing.hash.slice(1)));
125
152
  const fromHash = decodeURIComponent(location.hash.slice(1));
126
153
  // 地址里带了会话就打开它;否则打开「最近」里最近活跃的那个对话,一个都没有才进新对话页
127
154
  const latest = [...S.convs.values()].filter((c) => !c.hidden).sort((a, b) => b.activeAt - a.activeAt)[0];
@@ -150,17 +177,26 @@ export async function boot() {
150
177
  if (!document.querySelector(".overlay .settings")) void openSettings();
151
178
  });
152
179
  }
153
- if ("serviceWorker" in navigator) {
180
+ // 被嵌在别的服务器的页面里时,通知、角标都归外壳管
181
+ if ("serviceWorker" in navigator && !framed) {
154
182
  navigator.serviceWorker.register("/sw.js").catch(() => {});
155
183
  clearAppBadge();
156
- void releaseForeignPushSub().catch(() => {});
184
+ void releaseForeignPushSub()
185
+ .catch(() => {})
186
+ .then(() => refreshShellPush());
157
187
  // 点了系统通知、页面本来就开着:跳到通知对应的会话
158
188
  navigator.serviceWorker.addEventListener("message", (e) => {
159
189
  if (e.data?.type !== "open") return;
160
- const key = decodeURIComponent(new URL(e.data.url, location.origin).hash.slice(1));
190
+ const url = new URL(e.data.url, location.origin);
191
+ if (routeNotice(url)) return;
192
+ // 这台自己的通知:外壳正显示着别的服务器的话切回来
193
+ switchServer(HOME);
194
+ const key = decodeURIComponent(url.hash.slice(1));
161
195
  if (key && key !== S.current) void openConversation(key);
162
196
  });
163
197
  }
198
+ shellBooted();
199
+ void handleAllowEmbed(confirmDialog, toast);
164
200
  }
165
201
 
166
202
  function renderLayout() {
@@ -219,6 +255,8 @@ function renderLayout() {
219
255
  ui.sidebar = h(
220
256
  "aside",
221
257
  { class: "sidebar" },
258
+ // 左上角切换服务器(lib/shell.js),没有别的服务器时藏着
259
+ mountSwitcher("sidebar", h("div", { class: "side-switch", hidden: true })),
222
260
  h(
223
261
  "div",
224
262
  { class: "side-top" },
@@ -37,7 +37,7 @@ export function newDraft() {
37
37
  ui.follow = true;
38
38
  setBusy(false);
39
39
  renderScheduled();
40
- history.replaceState(null, "", location.pathname);
40
+ history.replaceState(history.state, "", location.pathname);
41
41
  WS.presence();
42
42
  renderTopbar();
43
43
  renderEmpty();
@@ -83,7 +83,7 @@ export async function openConversation(key) {
83
83
  ui.follow = true;
84
84
  renderChips();
85
85
  renderScheduled();
86
- history.replaceState(null, "", `#${encodeURIComponent(key)}`);
86
+ history.replaceState(history.state, "", `#${encodeURIComponent(key)}`);
87
87
  WS.presence();
88
88
  renderTopbar();
89
89
  renderSidebar();
@@ -73,7 +73,7 @@ export async function openRemote(tab) {
73
73
  async function select(tab) {
74
74
  R.tab = tab;
75
75
  localStorage.setItem("aim.remoteTab", tab);
76
- history.replaceState(null, "", `#remote/${tab}`);
76
+ history.replaceState(history.state, "", `#remote/${tab}`);
77
77
  renderSwitch();
78
78
  ui.remoteDesk.hidden = tab !== "desktop";
79
79
  ui.remoteTerm.hidden = tab !== "terminal";
@@ -97,7 +97,7 @@ export function leaveRemote() {
97
97
  const before = R.before;
98
98
  R.before = null;
99
99
  if (before === "tasks") return openTasksView();
100
- history.replaceState(null, "", S.current ? `#${encodeURIComponent(S.current)}` : location.pathname);
100
+ history.replaceState(history.state, "", S.current ? `#${encodeURIComponent(S.current)}` : location.pathname);
101
101
  // 对话区藏着的时候滚动位置没了:放回原处
102
102
  ui.messages.scrollTop = R.scroll ?? ui.messages.scrollTop;
103
103
  renderTopbar();
@@ -4,6 +4,7 @@ import { desktop, remoteTabs, S, ui } from "../state.js";
4
4
  import { baseName } from "./topbar.js";
5
5
  import { newDraft, openConversation } from "./messages.js";
6
6
  import { leaveRemote } from "./remote.js";
7
+ import { reportShellState } from "../lib/shell.js";
7
8
 
8
9
  // ---------- 侧栏标题跑马灯:名字被省略时,hover 来回滚动显示全名 ----------
9
10
 
@@ -388,11 +389,12 @@ function moreButton(st, count, limit, load) {
388
389
 
389
390
  /** 待处理的授权 / 提问和正在跑的会话,报给桌面端显示在菜单栏里 */
390
391
  export function reportDesktop() {
391
- if (!desktop) return;
392
- const pending = [...S.pending.values()]
393
- .filter((i) => !i.settled)
394
- .map((i) => ({ id: i.id, key: i.convKey, title: i.spec.title, conv: convTitle(S.convs.get(i.convKey)) }));
392
+ const open = [...S.pending.values()].filter((i) => !i.settled);
395
393
  const busy = [...S.convs.values()].filter((c) => c.busy).length;
394
+ // 多服务器:左上角切换列表里这台的角标
395
+ reportShellState(open.length, busy);
396
+ if (!desktop) return;
397
+ const pending = open.map((i) => ({ id: i.id, key: i.convKey, title: i.spec.title, conv: convTitle(S.convs.get(i.convKey)) }));
396
398
  desktop.setState({ pending, busy });
397
399
  }
398
400
 
@@ -87,7 +87,7 @@ export async function openTasks() {
87
87
  S.view = "tasks";
88
88
  S.items = [];
89
89
  S.turnAi = null;
90
- history.replaceState(null, "", "#tasks");
90
+ history.replaceState(history.state, "", "#tasks");
91
91
  WS.presence();
92
92
  ui.spacer.style.height = "0px";
93
93
  // 对话页的「贴底跟随」在这里不要:内容一变它就会滚到最底下