agent-loft 0.2.123 → 0.2.124

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-loft",
3
- "version": "0.2.123",
3
+ "version": "0.2.124",
4
4
  "type": "module",
5
5
  "description": "多个 agent 的工作台:把本机 Claude Code / Codex 放到一处统一管理,用飞书和 Web 页面随时驱动——会话、审批、模型切换都共用",
6
6
  "keywords": [
@@ -1,5 +1,35 @@
1
1
  /* ---------- 设置 ---------- */
2
2
 
3
+ .layout:has(> .settings-view) > :is(.main, .ws-panel) {
4
+ display: none;
5
+ }
6
+
7
+ .settings-view {
8
+ display: flex;
9
+ flex: 1;
10
+ min-width: 0;
11
+ flex-direction: column;
12
+ padding-bottom: env(safe-area-inset-bottom);
13
+ }
14
+
15
+ .settings-header {
16
+ display: flex;
17
+ align-items: center;
18
+ gap: 12px;
19
+ padding: calc(8px + env(safe-area-inset-top)) 16px 8px;
20
+ border-bottom: 1px solid var(--border);
21
+ }
22
+
23
+ .settings-header h1 {
24
+ margin: 0;
25
+ font-size: 18px;
26
+ }
27
+
28
+ .settings-body > .settings-page {
29
+ max-width: 1100px;
30
+ margin-inline: auto;
31
+ }
32
+
3
33
  /* 设置和从设置打开的弹层共用黑白主题,覆盖原生控件的系统强调色。 */
4
34
  .settings,
5
35
  body:has(.settings) > :is(.overlay, .menu) {
package/web/lib/ws.js CHANGED
@@ -109,7 +109,7 @@ export const WS = {
109
109
  const visible = document.visibilityState === "visible" && document.hasFocus() && Date.now() - lastInput < IDLE_MS && shownHere();
110
110
  // 在定时任务、远程控制页上:没在看哪条对话(远程控制页不清 S.current,回来时对话还在)
111
111
  this.raw({
112
- t: "presence", visible, key: S.view ? "" : (S.current ?? ""),
112
+ t: "presence", visible, key: S.view || ui.settings ? "" : (S.current ?? ""),
113
113
  // 前台免打扰按设备判断,不受正在看哪条会话、是否空闲的影响。
114
114
  foreground: document.visibilityState === "visible",
115
115
  pushEndpoint: framed ? (SH.push?.subscription.endpoint ?? null) : this.pushEndpoint,
@@ -1,6 +1,6 @@
1
1
  import { fill, h, toast } from "../lib/dom.js";
2
2
  import { api } from "../lib/api.js";
3
- import { desktop } from "../state.js";
3
+ import { contentHash, desktop } from "../state.js";
4
4
  import { field, saveButton, saveConfig } from "./common.js";
5
5
 
6
6
  /** 设置 → 对话:所有会话共用的规矩——在哪个目录、多久算新会话、授权卡等多久、Claude 的「总是允许」 */
@@ -217,6 +217,7 @@ export function networkSection(cfg) {
217
217
  // 旧端口已经不再接新连接:带着当前会话跳到新端口
218
218
  const url = new URL(location.href);
219
219
  url.port = String(p);
220
+ url.hash = contentHash();
220
221
  toast(`已改为端口 ${p},正在跳转…`);
221
222
  // 桌面端里由它改掉存着的服务器地址再重新打开(直接跳过去会被当成外部链接)
222
223
  if (typeof desktop?.serverMoved === "function") desktop.serverMoved(url.origin);
@@ -1,18 +1,10 @@
1
- import { fill, h } from "../lib/dom.js";
1
+ import { fill, h, icon } from "../lib/dom.js";
2
2
  import { api } from "../lib/api.js";
3
- import { isAdmin } from "../state.js";
4
- import { confirmDialog, modal } from "../lib/overlay.js";
5
- import { conversationTab, remoteTab } from "./general.js";
6
- import { commandsTab } from "./commands.js";
7
- import { agentsTab } from "./agents.js";
8
- import { feishuTab } from "./feishu.js";
9
- import { accountTab } from "./security.js";
10
- import { memoryTab } from "./memory.js";
11
- import { skillsTab } from "./skills.js";
12
- import { expertsTab, mcpTab } from "./experts.js";
13
- import { usageTab } from "./usage.js";
14
- import { serversTab } from "./servers.js";
15
- import { systemTab, usersTab } from "./users.js";
3
+ import { contentHash, isAdmin, ui } from "../state.js";
4
+ import { closeMenu, confirmDialog } from "../lib/overlay.js";
5
+ import { closeSide, renderSidebar } from "../views/sidebar.js";
6
+ import { syncDesktopMenu } from "../views/topbar.js";
7
+ import { WS } from "../lib/ws.js";
16
8
  import { hasDirty, markDirty } from "./common.js";
17
9
 
18
10
  // ---------- 设置 ----------
@@ -26,59 +18,66 @@ const RENAMED = { 通用: "对话", 授权: "对话", 飞书机器人: "飞书",
26
18
  /** 成员没有 Agent 页了:以前记住的 / 外面传进来的「Agent」打开专家页 */
27
19
  const MEMBER_RENAMED = { Agent: "专家" };
28
20
 
29
- function groupsFor(cfg) {
30
- const mine = {
31
- name: "我的",
32
- tabs: [
33
- ["账号", (p) => accountTab(p)],
34
- ["记忆", (p) => memoryTab(p)],
35
- ["专家", (p) => expertsTab(p)],
36
- ["技能", (p) => skillsTab(p)],
37
- ["MCP", (p) => mcpTab(p)],
38
- ["用量", (p) => usageTab(p)],
39
- ],
40
- };
41
- // 成员的内置 Agent 默认设置在「专家」里(内置卡片上的「设置」),这里没有 Agent 页
42
- if (!cfg) return [mine, { name: "系统", tabs: [["系统", (p) => systemTab(null, p)]] }];
43
- return [
44
- mine,
45
- {
46
- name: "Agent",
47
- tabs: [
48
- ["Agent", (p) => agentsTab(cfg, p)],
49
- ["对话", (p) => conversationTab(cfg, p)],
50
- ["命令", (p) => commandsTab(cfg, p)],
51
- ],
52
- },
53
- {
54
- name: "连接",
55
- tabs: [
56
- ["飞书", (p) => feishuTab(cfg, p)],
57
- ["远程控制", (p) => remoteTab(cfg, p)],
58
- ["服务器", (p) => serversTab(cfg, p)],
59
- ],
60
- },
61
- {
62
- name: "管理",
63
- tabs: [
64
- ["用户", (p) => usersTab(p)],
65
- ["系统", (p) => systemTab(cfg, p)],
66
- ],
67
- },
68
- ];
21
+ function warnBeforeUnload(event) {
22
+ if (!ui.settings?.isDirty()) return;
23
+ event.preventDefault();
24
+ event.returnValue = true;
69
25
  }
70
26
 
71
27
  /** tab:直接打开哪一页(标签名,如「技能」),不给就是上次看的那页 */
72
28
  export async function openSettings(tab) {
73
- const nav = h("div", { class: "settings-nav" });
74
- const panel = h("div", { class: "settings-body" });
29
+ closeSide();
30
+ closeMenu();
31
+ if (ui.settings) {
32
+ return tab && ui.settings.selectTab(tab);
33
+ }
34
+ const nav = h("nav", { class: "settings-nav", "aria-label": "设置分类" });
35
+ const panel = h("div", { class: "settings-body" }, h("span", { class: "spinner", role: "status", "aria-label": "加载设置" }));
75
36
  let page = null;
76
- const leaveOk = async () =>
77
- !page ||
78
- !hasDirty(page) ||
79
- confirmDialog({ title: "有修改还没保存", message: "现在离开,这一页刚才改的内容不会保存。", confirmText: "不保存", danger: true });
80
- // 设置弹窗高度固定,切标签页时不跟着内容一伸一缩
81
- modal({ title: "设置", wide: true, tall: true, body: h("div", { class: "settings" }, nav, panel), beforeClose: leaveOk });
37
+ const isDirty = () => page?.isConnected && hasDirty(page);
38
+ let confirming = false;
39
+ const leaveOk = async () => {
40
+ if (!isDirty()) return true;
41
+ if (confirming) return false;
42
+ confirming = true;
43
+ try {
44
+ return await confirmDialog({ title: "有修改还没保存", message: "现在离开,这一页刚才改的内容不会保存。", confirmText: "不保存", danger: true });
45
+ } finally {
46
+ confirming = false;
47
+ }
48
+ };
49
+ const previousHash = contentHash();
50
+ const previousFocus = document.activeElement;
51
+ const scrollTop = ui.messages?.scrollTop;
52
+ const close = async () => {
53
+ if (!(await leaveOk()) || ui.settings !== settings) return false;
54
+ window.removeEventListener("beforeunload", warnBeforeUnload);
55
+ pane.remove();
56
+ ui.settings = null;
57
+ const returnHash = contentHash();
58
+ const { settingsReturnHash, ...state } = history.state ?? {};
59
+ history.replaceState(state, "", location.pathname + location.search + returnHash);
60
+ syncDesktopMenu();
61
+ renderSidebar();
62
+ WS.presence();
63
+ if (ui.messages && previousHash === returnHash) ui.messages.scrollTop = scrollTop;
64
+ if (previousFocus?.isConnected) previousFocus.focus({ preventScroll: true });
65
+ return true;
66
+ };
67
+ const back = h("button", { class: "btn", onclick: close }, icon("back"), "返回");
68
+ const pane = h("main", { class: "settings-view", "aria-label": "设置" },
69
+ h("header", { class: "settings-header" }, back, h("h1", {}, "设置")),
70
+ h("div", { class: "settings" }, nav, panel),
71
+ );
72
+ const settings = { close, isDirty, selectTab: (name) => { tab = name; } };
73
+ ui.settings = settings;
74
+ window.addEventListener("beforeunload", warnBeforeUnload);
75
+ ui.layout.append(pane);
76
+ history.replaceState({ ...history.state, settingsReturnHash: previousHash }, "", "#settings");
77
+ syncDesktopMenu();
78
+ renderSidebar();
79
+ WS.presence();
80
+ back.focus({ preventScroll: true });
82
81
 
83
82
  // 带 data-form 的表单里改了东西:标成没保存(common.js 的 saveButton)
84
83
  const onEdit = (e) => {
@@ -89,34 +88,35 @@ export async function openSettings(tab) {
89
88
  panel.addEventListener("input", onEdit);
90
89
  panel.addEventListener("change", onEdit);
91
90
 
92
- let cfg = null;
93
- if (isAdmin()) {
94
- try {
95
- cfg = await api("/api/config");
96
- } catch (err) {
97
- panel.append(h("div", { class: "error-text" }, err.message));
98
- return;
99
- }
91
+ let cfg, groups;
92
+ try {
93
+ const [module, config] = await Promise.all([import("./tabs.js"), isAdmin() ? api("/api/config") : null]);
94
+ if (!pane.isConnected) return;
95
+ cfg = config;
96
+ groups = module.groupsFor(cfg);
97
+ } catch (err) {
98
+ fill(panel, h("div", { class: "error-text" }, err.message));
99
+ return;
100
100
  }
101
- const groups = groupsFor(cfg);
102
101
  const tabs = groups.flatMap((g) => g.tabs);
103
102
  const buttons = [];
104
103
  let current = -1;
105
104
 
106
105
  const select = async (i) => {
107
- if (i === current || !(await leaveOk())) return;
106
+ if (i === current || !(await leaveOk()) || !pane.isConnected) return;
108
107
  current = i;
109
108
  buttons.forEach((b, j) => b.classList.toggle("on", i === j));
110
109
  buttons[i].scrollIntoView({ block: "nearest", inline: "nearest" });
111
110
  localStorage.setItem(LAST_TAB, tabs[i][0]);
112
111
  // 每页一个新容器:慢的页还在等接口时切走了,它回来后写进的是已经不在页面上的旧容器,不会串到新页里
113
- page = h("div", { class: "settings-page" });
112
+ const content = h("div", { class: "settings-page" });
113
+ page = content;
114
114
  fill(panel, page);
115
115
  panel.scrollTop = 0;
116
116
  try {
117
- await tabs[i][1](page);
117
+ await tabs[i][1](content);
118
118
  } catch (err) {
119
- if (page.isConnected) fill(page, h("div", { class: "error-text" }, err.message));
119
+ if (content.isConnected) fill(content, h("div", { class: "error-text" }, err.message));
120
120
  }
121
121
  };
122
122
 
@@ -130,7 +130,9 @@ export async function openSettings(tab) {
130
130
  nav.append(b);
131
131
  }
132
132
  }
133
- const requested = tab || localStorage.getItem(LAST_TAB);
134
- const want = (cfg ? undefined : MEMBER_RENAMED[requested]) ?? RENAMED[requested] ?? requested;
135
- void select(Math.max(0, tabs.findIndex(([name]) => name === want)));
133
+ settings.selectTab = (requested) => {
134
+ const want = (cfg ? undefined : MEMBER_RENAMED[requested]) ?? RENAMED[requested] ?? requested;
135
+ return select(Math.max(0, tabs.findIndex(([name]) => name === want)));
136
+ };
137
+ await settings.selectTab(tab || localStorage.getItem(LAST_TAB));
136
138
  }
@@ -0,0 +1,53 @@
1
+ import { conversationTab, remoteTab } from "./general.js";
2
+ import { commandsTab } from "./commands.js";
3
+ import { agentsTab } from "./agents.js";
4
+ import { feishuTab } from "./feishu.js";
5
+ import { accountTab } from "./security.js";
6
+ import { memoryTab } from "./memory.js";
7
+ import { skillsTab } from "./skills.js";
8
+ import { expertsTab, mcpTab } from "./experts.js";
9
+ import { usageTab } from "./usage.js";
10
+ import { serversTab } from "./servers.js";
11
+ import { systemTab, usersTab } from "./users.js";
12
+
13
+ export function groupsFor(cfg) {
14
+ const mine = {
15
+ name: "我的",
16
+ tabs: [
17
+ ["账号", (p) => accountTab(p)],
18
+ ["记忆", (p) => memoryTab(p)],
19
+ ["专家", (p) => expertsTab(p)],
20
+ ["技能", (p) => skillsTab(p)],
21
+ ["MCP", (p) => mcpTab(p)],
22
+ ["用量", (p) => usageTab(p)],
23
+ ],
24
+ };
25
+ // 成员的内置 Agent 默认设置在「专家」里(内置卡片上的「设置」),这里没有 Agent 页
26
+ if (!cfg) return [mine, { name: "系统", tabs: [["系统", (p) => systemTab(null, p)]] }];
27
+ return [
28
+ mine,
29
+ {
30
+ name: "Agent",
31
+ tabs: [
32
+ ["Agent", (p) => agentsTab(cfg, p)],
33
+ ["对话", (p) => conversationTab(cfg, p)],
34
+ ["命令", (p) => commandsTab(cfg, p)],
35
+ ],
36
+ },
37
+ {
38
+ name: "连接",
39
+ tabs: [
40
+ ["飞书", (p) => feishuTab(cfg, p)],
41
+ ["远程控制", (p) => remoteTab(cfg, p)],
42
+ ["服务器", (p) => serversTab(cfg, p)],
43
+ ],
44
+ },
45
+ {
46
+ name: "管理",
47
+ tabs: [
48
+ ["用户", (p) => usersTab(p)],
49
+ ["系统", (p) => systemTab(cfg, p)],
50
+ ],
51
+ },
52
+ ];
53
+ }
package/web/state.js CHANGED
@@ -53,6 +53,19 @@ export function remoteTabs() {
53
53
 
54
54
  export const ui = {};
55
55
 
56
+ /** 设置页保留底下的会话或工具页,刷新和后台重连都用同一条返回地址。 */
57
+ export function contentHash() {
58
+ return location.hash === "#settings" ? (history.state?.settingsReturnHash ?? "") : location.hash;
59
+ }
60
+
61
+ export function setContentHash(hash) {
62
+ if (ui.settings) {
63
+ history.replaceState({ ...history.state, settingsReturnHash: hash }, "", "#settings");
64
+ } else {
65
+ history.replaceState(history.state, "", hash || location.pathname + location.search);
66
+ }
67
+ }
68
+
56
69
  /**
57
70
  * 运行在 macOS 桌面端(agent-loft-desktop)里时,由它的 preload 注入。
58
71
  * 桌面端收不到 Web Push,系统通知、Dock 角标、菜单栏的待处理数都交给它。
@@ -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, framed, remoteTabs, S, ui } from "../state.js";
3
+ import { contentHash, desktop, desktopMenu, desktopQuota, desktopSettings, framed, remoteTabs, S, ui } from "../state.js";
4
4
  import { clearAppNotifications, WS } from "../lib/ws.js";
5
5
  import { showAuth } from "./auth.js";
6
6
  import {
@@ -32,29 +32,22 @@ import { clearCommandCache, preloadCommands } from "./slash.js";
32
32
  import { releaseForeignPushSub } from "../lib/push.js";
33
33
  import { createSidebarNav } from "./sidebar-nav.js";
34
34
  import { bindSidebarGestures } from "./sidebar-gestures.js";
35
+ import { openSettings } from "../settings/index.js";
35
36
  import "../lib/keyboard.js";
36
37
 
38
+ export { openSettings };
39
+
37
40
  // ---------- 主界面 ----------
38
41
 
39
- /**
40
- * 设置页的代码占前端的三分之一,平时用不到:第一次打开设置时才加载。
41
- * 加载期间弹窗还没出来,连点 / 桌面端重复触发都会再开一层,所以加载中的再调用直接忽略。
42
- */
43
- let settingsLoading = false;
44
- /** tab:直接打开哪一页,如「技能」 */
45
- export function openSettings(tab) {
46
- if (settingsLoading) return;
47
- settingsLoading = true;
48
- import("../settings/index.js").then(
49
- (m) => {
50
- settingsLoading = false;
51
- return m.openSettings(tab);
52
- },
53
- (err) => {
54
- settingsLoading = false;
55
- toast(`设置加载失败,刷新页面再试:${err.message}`);
56
- },
57
- );
42
+ async function navigate(action) {
43
+ if (ui.settings && !(await ui.settings.close())) return;
44
+ return action();
45
+ }
46
+
47
+ function showConversation(key) {
48
+ if (key) void navigate(() => {
49
+ if (key !== S.current || S.view) return openConversation(key);
50
+ });
58
51
  }
59
52
 
60
53
  /**
@@ -92,7 +85,7 @@ document.addEventListener("aim:remote", async () => {
92
85
  });
93
86
 
94
87
  window.addEventListener("keydown", (e) => {
95
- if (e.ctrlKey && !e.shiftKey && !e.altKey && !e.metaKey && e.code === "Backquote" && S.remote?.terminal?.allowed) {
88
+ if (e.ctrlKey && !e.shiftKey && !e.altKey && !e.metaKey && !ui.settings && e.code === "Backquote" && S.remote?.terminal?.allowed) {
96
89
  e.preventDefault();
97
90
  toggleTerminalDock();
98
91
  }
@@ -100,7 +93,7 @@ window.addEventListener("keydown", (e) => {
100
93
 
101
94
  // 多服务器(lib/shell.js):外壳让打开某条对话(点了这台的通知)、点了「管理服务器…」、切到别的服务器
102
95
  document.addEventListener("aim:shell-open", (e) => {
103
- if (e.detail && e.detail !== S.current) void openConversation(e.detail);
96
+ showConversation(e.detail);
104
97
  });
105
98
  document.addEventListener("aim:open-settings", (e) => openSettings(e.detail));
106
99
  document.addEventListener("aim:server-leave", () => closeSide());
@@ -165,9 +158,11 @@ export async function boot() {
165
158
  if (desktopQuota) desktop.onQuota(applyDesktopQuota);
166
159
  else void loadQuota();
167
160
  if (srv && srv !== HOME) routeToServer(srv, decodeURIComponent(landing.hash.slice(1)));
168
- const fromHash = decodeURIComponent(location.hash.slice(1));
161
+ const restoreSettings = location.hash === "#settings";
162
+ const fromHash = decodeURIComponent(contentHash().slice(1));
169
163
  // 地址里带了会话就打开它;否则打开最近活跃的 Web 对话,没有才进新对话页
170
164
  const latest = latestConversation("web");
165
+ if (restoreSettings) void openSettings();
171
166
  if (fromHash === "tasks") openTasksView();
172
167
  else if (fromHash === "library") openLibraryView();
173
168
  else if (fromHash === "new") newDraft({ inheritLatest: true });
@@ -186,16 +181,11 @@ export async function boot() {
186
181
  // 点了桌面端的系统通知 / 菜单栏里的待处理项:跳到对应会话
187
182
  desktop?.onOpen((key) => {
188
183
  // 不要求在 S.convs 里:侧栏分页,那条可能还没拉到;openConversation 会去服务端拿
189
- if (key && key !== S.current) void openConversation(key);
184
+ showConversation(key);
190
185
  });
191
186
  // 页面的「更多」菜单在桌面端顶栏的「更多」里:点了哪项
192
187
  if (desktopMenu) desktop.onMenu(runDesktopMenu);
193
- // 桌面端「更多」里点了这台服务器的设置;已经开着就不再叠一层
194
- if (desktopSettings) {
195
- desktop.onOpenSettings(() => {
196
- if (!document.querySelector(".overlay .settings")) void openSettings();
197
- });
198
- }
188
+ if (desktopSettings) desktop.onOpenSettings(() => void openSettings());
199
189
  // 被嵌在别的服务器的页面里时,通知、角标都归外壳管
200
190
  if ("serviceWorker" in navigator && !framed) {
201
191
  navigator.serviceWorker.register("/sw.js").then(() => clearAppNotifications()).catch(() => {});
@@ -211,7 +201,7 @@ export async function boot() {
211
201
  // 这台自己的通知:外壳正显示着别的服务器的话切回来
212
202
  switchServer(HOME);
213
203
  const key = decodeURIComponent(url.hash.slice(1));
214
- if (key && key !== S.current) void openConversation(key);
204
+ showConversation(key);
215
205
  });
216
206
  }
217
207
  shellBooted();
@@ -219,6 +209,7 @@ export async function boot() {
219
209
  }
220
210
 
221
211
  function renderLayout() {
212
+ ui.settings = null;
222
213
  ui.convList = h("div", { class: "conv-list" });
223
214
  // 双击重命名。第一下单击会打开会话、侧栏整体重绘,元素已经换了,浏览器自己的 dblclick
224
215
  // 不一定触发;所以按 data-key 自己判断「同一条、两次按下间隔很短」
@@ -274,9 +265,9 @@ function renderLayout() {
274
265
  h(
275
266
  "div",
276
267
  { class: "side-top" },
277
- h("button", { class: "btn new-chat", onclick: () => (newDraft({ inheritLatest: true }), closeSide()) }, icon("plus"), "新建"),
268
+ h("button", { class: "btn new-chat", onclick: () => navigate(() => (newDraft({ inheritLatest: true }), closeSide())) }, icon("plus"), "新建"),
278
269
  ),
279
- createSidebarNav({ search: openSearch, tasks: openTasksView, library: openLibraryView, remote: openRemoteView, settings: openSettings }),
270
+ createSidebarNav({ search: () => navigate(openSearch), tasks: () => navigate(openTasksView), library: () => navigate(openLibraryView), remote: () => navigate(openRemoteView), settings: openSettings }),
280
271
  ui.convList,
281
272
  // 底部只有额度:没有额度可显示(关了查询、还没查到)时整块藏起来,连分隔线一起
282
273
  (ui.sideBottom = h(
@@ -2,7 +2,7 @@ import { fill, h, icon, starsLoader, toast } from "../lib/dom.js";
2
2
  import { api } from "../lib/api.js";
3
3
  import { relTime } from "../lib/time.js";
4
4
  import { confirmDialog, modal, showMenu } from "../lib/overlay.js";
5
- import { S, ui } from "../state.js";
5
+ import { S, setContentHash, ui } from "../state.js";
6
6
  import { WS } from "../lib/ws.js";
7
7
  import { closeSide, renderSidebar } from "./sidebar.js";
8
8
  import { renderTopbar } from "./topbar.js";
@@ -234,7 +234,7 @@ export function openLibrary() {
234
234
  S.view = "library";
235
235
  S.items = [];
236
236
  S.turnAi = null;
237
- history.replaceState(history.state, "", "#library");
237
+ setContentHash("#library");
238
238
  WS.presence();
239
239
  ui.spacer.style.height = "0px";
240
240
  ui.follow = false;
@@ -2,7 +2,7 @@ import { fill, h, icon, isTouch, starsLoader, toast } from "../lib/dom.js";
2
2
  import { api } from "../lib/api.js";
3
3
  import { clockTime, liveDuration, serverNow, setServerTime, tidyFooter } from "../lib/time.js";
4
4
  import { copyText, patchMarkdown, renderMarkdown } from "../lib/markdown.js";
5
- import { S, ui } from "../state.js";
5
+ import { S, setContentHash, ui } from "../state.js";
6
6
  import { WS } from "../lib/ws.js";
7
7
  import { agentLabel, convTitle, renderSidebar } from "./sidebar.js";
8
8
  import { baseName, renderContext, renderTopbar, updateCtxVisibility, usableAgents } from "./topbar.js";
@@ -93,7 +93,7 @@ export function newDraft({ inheritLatest = false } = {}) {
93
93
  setTodos(null);
94
94
  setBusy(false);
95
95
  renderScheduled();
96
- history.replaceState(history.state, "", "#new");
96
+ setContentHash("#new");
97
97
  WS.presence();
98
98
  renderTopbar();
99
99
  renderEmpty();
@@ -175,7 +175,7 @@ export async function openConversation(key) {
175
175
  setTodos(null);
176
176
  renderChips();
177
177
  renderScheduled();
178
- history.replaceState(history.state, "", `#${encodeURIComponent(key)}`);
178
+ setContentHash(`#${encodeURIComponent(key)}`);
179
179
  WS.presence();
180
180
  renderTopbar();
181
181
  renderSidebar();
@@ -1,5 +1,5 @@
1
1
  import { fill, h, icon, toast } from "../lib/dom.js";
2
- import { remoteTabs, S, ui } from "../state.js";
2
+ import { remoteTabs, S, setContentHash, ui } from "../state.js";
3
3
  import { WS } from "../lib/ws.js";
4
4
  import { closeSide, renderSidebar } from "./sidebar.js";
5
5
  import { renderTopbar } from "./topbar.js";
@@ -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(history.state, "", `#remote/${tab}`);
76
+ setContentHash(`#remote/${tab}`);
77
77
  renderSwitch();
78
78
  ui.remoteDesk.hidden = tab !== "desktop";
79
79
  ui.remoteTerm.hidden = tab !== "terminal";
@@ -98,7 +98,7 @@ export function leaveRemote() {
98
98
  R.before = null;
99
99
  if (before === "tasks") return openTasksView();
100
100
  if (before === "library") return openLibraryView();
101
- history.replaceState(history.state, "", S.current ? `#${encodeURIComponent(S.current)}` : location.pathname);
101
+ setContentHash(S.current ? `#${encodeURIComponent(S.current)}` : "");
102
102
  // 对话区藏着的时候滚动位置没了:放回原处
103
103
  ui.messages.scrollTop = R.scroll ?? ui.messages.scrollTop;
104
104
  renderTopbar();
@@ -28,7 +28,7 @@ function configuredItems() {
28
28
  }
29
29
 
30
30
  const available = (item) => item.id !== "remote" || remoteTabs().length > 0;
31
- const isActive = (item) => ["tasks", "library", "remote"].includes(item.id) && S.view === item.id;
31
+ const isActive = (item) => (ui.settings ? "settings" : S.view) === item.id;
32
32
  const remoteLive = () => S.remoteLive.desktop || S.remoteLive.terminals > 0;
33
33
 
34
34
  function navButton(item, inMenu = false) {
@@ -1,6 +1,6 @@
1
1
  import { fill, h, icon, ICON, toast } from "../lib/dom.js";
2
2
  import { api } from "../lib/api.js";
3
- import { desktop, S, ui } from "../state.js";
3
+ import { contentHash, desktop, S, ui } from "../state.js";
4
4
  import { baseName } from "./topbar.js";
5
5
  import { newDraft, openConversation } from "./messages.js";
6
6
  import { convExpert, expertIcon, setDraftExpert } from "./experts.js";
@@ -442,7 +442,7 @@ function weixinState(id) {
442
442
  export function bootstrapQuery() {
443
443
  const q = new URLSearchParams({ recent: String(pages.recent.show), open: JSON.stringify(sideState.open.map((d) => [d, dirState(d).show])) });
444
444
  // 正开着的会话;刚打开页面时是地址里带的那条(可能在后面几页)
445
- const current = S.current ?? decodeURIComponent(location.hash.slice(1));
445
+ const current = S.current ?? decodeURIComponent(contentHash().slice(1));
446
446
  if (current) q.set("current", current);
447
447
  return `?${q}`;
448
448
  }
@@ -558,7 +558,8 @@ export function renderSidebar() {
558
558
  : keys.some((k) => S.convs.get(k)?.busy)
559
559
  ? h("span", { class: "conv-spin", title: "进行中" })
560
560
  : null;
561
- const open = (key) => {
561
+ const open = async (key) => {
562
+ if (ui.settings && !(await ui.settings.close())) return;
562
563
  closeSide();
563
564
  if (key !== S.current) void openConversation(key);
564
565
  // 在远程控制页上点进来之前那条对话:对话没动过,退出远程控制就露出来了
@@ -570,7 +571,7 @@ export function renderSidebar() {
570
571
  h(
571
572
  "button",
572
573
  {
573
- class: `conv-item${cls}${c.key === S.current && !S.view ? " active" : ""}`,
574
+ class: `conv-item${cls}${c.key === S.current && !S.view && !ui.settings ? " active" : ""}`,
574
575
  "data-key": c.key,
575
576
  title: `${convTitle(c)}${forkNote(c)}\n${detail}\n双击重命名,右键更多操作`,
576
577
  onclick: () => open(c.key),
@@ -745,6 +746,7 @@ export function renderSidebar() {
745
746
  title: `在 ${baseName(dir)} 中开新对话`,
746
747
  onclick: async (e) => {
747
748
  const button = e.currentTarget;
749
+ if (ui.settings && !(await ui.settings.close())) return;
748
750
  button.disabled = true;
749
751
  try {
750
752
  let latest = convs[0];
@@ -2,7 +2,7 @@ import { fill, h, icon, starsLoader, toast } from "../lib/dom.js";
2
2
  import { api } from "../lib/api.js";
3
3
  import { clockTime } from "../lib/time.js";
4
4
  import { confirmDialog, modal, showMenu } from "../lib/overlay.js";
5
- import { isAdmin, S, ui } from "../state.js";
5
+ import { isAdmin, S, setContentHash, ui } from "../state.js";
6
6
  import { WS } from "../lib/ws.js";
7
7
  import { agentLabel, closeSide, renderSidebar } from "./sidebar.js";
8
8
  import { baseName, renderTopbar } from "./topbar.js";
@@ -97,7 +97,7 @@ export async function openTasks() {
97
97
  S.view = "tasks";
98
98
  S.items = [];
99
99
  S.turnAi = null;
100
- history.replaceState(history.state, "", "#tasks");
100
+ setContentHash("#tasks");
101
101
  WS.presence();
102
102
  ui.spacer.style.height = "0px";
103
103
  // 对话页的「贴底跟随」在这里不要:内容一变它就会滚到最底下
@@ -250,9 +250,9 @@ let desktopActions = new Map();
250
250
  let desktopMenuSig = "";
251
251
 
252
252
  /** 会话操作菜单变了就报给桌面端。 */
253
- function syncDesktopMenu() {
253
+ export function syncDesktopMenu() {
254
254
  if (!desktopMenu) return;
255
- const items = topMenuItems();
255
+ const items = ui.settings ? [] : topMenuItems();
256
256
  desktopActions = new Map(items.filter((it) => it !== "sep").map((it) => [it.id, it.onclick]));
257
257
  const menu = {
258
258
  items: items.map((it) => (it === "sep" ? { type: "separator" } : { id: it.id, label: it.detail && !it.detail.hidden ? `${it.label} ${it.detail.textContent}` : it.label, ...(it.checked !== undefined ? { checked: it.checked } : {}) })),
@@ -521,7 +521,14 @@ function handoffItem(c) {
521
521
  icon: "handoff",
522
522
  disabled: !c.canHandoff,
523
523
  disabledReason: "这条对话还没有可以交接的内容",
524
- children: targets.map((e) => ({ label: e.name, leading: expertIcon(e), onclick: () => handoffConversation(e, c.key) })),
524
+ children: targets.map((e) => ({
525
+ label: e.name,
526
+ leading: expertIcon(e),
527
+ onclick: async () => {
528
+ if (ui.settings && !(await ui.settings.close())) return;
529
+ await handoffConversation(e, c.key);
530
+ },
531
+ })),
525
532
  },
526
533
  ];
527
534
  }
@@ -545,6 +552,7 @@ function convMenuItems(key) {
545
552
  label: "分叉",
546
553
  icon: "fork",
547
554
  onclick: async () => {
555
+ if (ui.settings && !(await ui.settings.close())) return;
548
556
  if (c.canFork) return forkConversation(undefined, key);
549
557
  // 不支持另开一条的:只能在原对话里分叉,先切过去
550
558
  if (key !== S.current) await openConversation(key);