agent-loft 0.2.122 → 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/src/core/tasks.ts CHANGED
@@ -70,7 +70,7 @@ export type Task = {
70
70
  updatedAt: number;
71
71
  /** 谁建的:用户在页面上建的,还是 agent 在对话里建的 */
72
72
  createdBy: "user" | "agent";
73
- /** 创建时明确交办的 bot,独立运行的任务也能追溯来源。 */
73
+ /** 旧版私人会话创建的任务,生成专用对话时沿用其可见范围。 */
74
74
  assistantKey?: string;
75
75
  nextRunAt?: number;
76
76
  /** 最近的在前 */
@@ -136,11 +136,6 @@ export function listTasks(owner: string): Task[] {
136
136
  .sort((a, b) => b.createdAt - a.createdAt);
137
137
  }
138
138
 
139
- /** 调用方先按 owner 取任务,再按交办来源或投递会话找到相关事项。 */
140
- export function taskBelongsToAssistant(task: Task, key: string): boolean {
141
- return task.assistantKey === key || task.target.key === key;
142
- }
143
-
144
139
  /** 只认主人:别人的任务一律当不存在 */
145
140
  export function getTask(owner: string, id: string): Task | undefined {
146
141
  return load().find((t) => t.id === id && t.owner === owner);
@@ -240,7 +235,7 @@ function cleanTarget(v: unknown, prev?: TaskTarget): TaskTarget {
240
235
  return prev?.kind === "dedicated" ? prev : { kind: "dedicated" };
241
236
  }
242
237
 
243
- export function createTask(owner: string, input: TaskInput, by: "user" | "agent", now = Date.now(), assistantKey?: string): Task {
238
+ export function createTask(owner: string, input: TaskInput, by: "user" | "agent", now = Date.now()): Task {
244
239
  if (listTasks(owner).length >= TASKS_PER_USER) throw new Error(`每人最多 ${TASKS_PER_USER} 个定时任务,先删掉几个不用的`);
245
240
  const prompt = cleanPrompt(input.prompt);
246
241
  const schedule = normalizeSchedule(input.schedule, now);
@@ -266,7 +261,6 @@ export function createTask(owner: string, input: TaskInput, by: "user" | "agent"
266
261
  createdAt: now,
267
262
  updatedAt: now,
268
263
  createdBy: by,
269
- ...(assistantKey ? { assistantKey } : {}),
270
264
  runs: [],
271
265
  };
272
266
  task.nextRunAt = task.enabled ? nextRun(schedule, now) : undefined;
@@ -4,7 +4,7 @@ import path from "node:path";
4
4
  import { dataDir, readJson, writeJsonAtomic } from "../home.js";
5
5
 
6
6
  export type SidebarNavItem = { id: string; visible: boolean };
7
- const NAV_IDS = ["search", "tasks", "assistants", "library", "remote", "settings"];
7
+ const NAV_IDS = ["search", "tasks", "library", "remote", "settings"];
8
8
  type Prefs = { dirOrder?: string[]; sidebarNav?: SidebarNavItem[]; expertOrder?: string[] };
9
9
 
10
10
  const prefsPath = path.join(dataDir, "ui-prefs.json");
package/src/main.ts CHANGED
@@ -20,7 +20,6 @@ import { buildHistoryIndex } from "./core/chat-history.js";
20
20
  import { migrateAllMemoryItems, migrateMemoryDefault } from "./core/memory.js";
21
21
  import { listUsers } from "./core/users.js";
22
22
  import { startScheduler, stopScheduler } from "./core/scheduled.js";
23
- import { startBotEvents, stopBotEvents } from "./bot-event-runner.js";
24
23
  import { startTaskRunner, stopTaskRunner } from "./core/task-runner.js";
25
24
  import { startTasksBridge, stopTasksBridge } from "./core/tasks-bridge.js";
26
25
 
@@ -102,7 +101,6 @@ async function main(): Promise<void> {
102
101
  // 定时任务:agent 用的工具通道先开,再开始按点运行(停机期间错过的补跑)
103
102
  startTasksBridge();
104
103
  startTaskRunner();
105
- startBotEvents();
106
104
  // 先查一遍 agent 装没装、登没登录,网页打开时新对话里就只列出能用的
107
105
  void agentHealth().catch(() => {});
108
106
  // 读一次 Claude 的命令表:成员会话的技能白名单要带上 Claude Code 自带的那些(见 claude/session.ts 的 claudeBuiltins)
@@ -122,7 +120,6 @@ async function main(): Promise<void> {
122
120
  console.log(`[退出] 收到 ${signal},正在收尾…`);
123
121
  const force = setTimeout(() => process.exit(0), 8000);
124
122
  force.unref();
125
- stopBotEvents();
126
123
  stopScheduler();
127
124
  stopFeishu();
128
125
  stopWeixin();
@@ -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/css/tasks.css CHANGED
@@ -544,11 +544,3 @@ button.task-run:hover {
544
544
  text-overflow: ellipsis;
545
545
  white-space: nowrap;
546
546
  }
547
-
548
- .assistant-list, .assistant-card { display: grid; gap: 12px; }
549
- .assistant-card { border: 1px solid var(--border); border-radius: 12px; padding: 12px; }
550
- .assistant-row, .assistant-task { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
551
- .assistant-list .grow { flex: 1 1 8em; min-width: 0; overflow-wrap: anywhere; }
552
- .assistant-row select { flex: 1; min-width: 0; }
553
- .assistant-list small { display: block; color: var(--muted); overflow-wrap: anywhere; }
554
- .assistant-task { padding-top: 8px; border-top: 1px solid var(--border); }
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,
@@ -285,9 +285,6 @@ function onWsMessage(msg) {
285
285
  case "ix":
286
286
  upsertInteraction(msg.interaction);
287
287
  return;
288
- case "bot-events":
289
- document.dispatchEvent(new Event("aim:bot-events"));
290
- break;
291
288
  case "tasks":
292
289
  // 自己的定时任务变了:定时任务页开着的话会去重新拉(views/tasks.js)
293
290
  document.dispatchEvent(new Event("aim:tasks"));
@@ -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,17 +93,11 @@ window.addEventListener("keydown", (e) => {
100
93
 
101
94
  // 多服务器(lib/shell.js):外壳让打开某条对话(点了这台的通知)、点了「管理服务器…」、切到别的服务器
102
95
  document.addEventListener("aim:shell-open", (e) => {
103
- openNoticeTarget(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());
107
100
 
108
- function openNoticeTarget(key) {
109
- if (key?.startsWith("bot-events/")) {
110
- import("./bot-events.js").then((m) => m.openBotEvents({ watch: key.slice("bot-events/".length) })).catch((err) => toast(err.message));
111
- } else if (key && key !== S.current) void openConversation(key);
112
- }
113
-
114
101
  /**
115
102
  * 通知点开的地址:别的服务器的带着 srv=那台的 id(服务端 push.ts 的 relay),交给外壳切过去。
116
103
  * 返回 true 表示已经交出去了
@@ -171,9 +158,11 @@ export async function boot() {
171
158
  if (desktopQuota) desktop.onQuota(applyDesktopQuota);
172
159
  else void loadQuota();
173
160
  if (srv && srv !== HOME) routeToServer(srv, decodeURIComponent(landing.hash.slice(1)));
174
- const fromHash = decodeURIComponent(location.hash.slice(1));
161
+ const restoreSettings = location.hash === "#settings";
162
+ const fromHash = decodeURIComponent(contentHash().slice(1));
175
163
  // 地址里带了会话就打开它;否则打开最近活跃的 Web 对话,没有才进新对话页
176
164
  const latest = latestConversation("web");
165
+ if (restoreSettings) void openSettings();
177
166
  if (fromHash === "tasks") openTasksView();
178
167
  else if (fromHash === "library") openLibraryView();
179
168
  else if (fromHash === "new") newDraft({ inheritLatest: true });
@@ -188,21 +177,15 @@ export async function boot() {
188
177
  else newDraft();
189
178
  preloadCommands();
190
179
  // 以前的技能页地址:技能现在在设置里
191
- if (fromHash.startsWith("bot-events/")) openNoticeTarget(fromHash);
192
180
  if (fromHash === "skills") openSettings("技能");
193
181
  // 点了桌面端的系统通知 / 菜单栏里的待处理项:跳到对应会话
194
182
  desktop?.onOpen((key) => {
195
183
  // 不要求在 S.convs 里:侧栏分页,那条可能还没拉到;openConversation 会去服务端拿
196
- openNoticeTarget(key);
184
+ showConversation(key);
197
185
  });
198
186
  // 页面的「更多」菜单在桌面端顶栏的「更多」里:点了哪项
199
187
  if (desktopMenu) desktop.onMenu(runDesktopMenu);
200
- // 桌面端「更多」里点了这台服务器的设置;已经开着就不再叠一层
201
- if (desktopSettings) {
202
- desktop.onOpenSettings(() => {
203
- if (!document.querySelector(".overlay .settings")) void openSettings();
204
- });
205
- }
188
+ if (desktopSettings) desktop.onOpenSettings(() => void openSettings());
206
189
  // 被嵌在别的服务器的页面里时,通知、角标都归外壳管
207
190
  if ("serviceWorker" in navigator && !framed) {
208
191
  navigator.serviceWorker.register("/sw.js").then(() => clearAppNotifications()).catch(() => {});
@@ -218,7 +201,7 @@ export async function boot() {
218
201
  // 这台自己的通知:外壳正显示着别的服务器的话切回来
219
202
  switchServer(HOME);
220
203
  const key = decodeURIComponent(url.hash.slice(1));
221
- openNoticeTarget(key);
204
+ showConversation(key);
222
205
  });
223
206
  }
224
207
  shellBooted();
@@ -226,6 +209,7 @@ export async function boot() {
226
209
  }
227
210
 
228
211
  function renderLayout() {
212
+ ui.settings = null;
229
213
  ui.convList = h("div", { class: "conv-list" });
230
214
  // 双击重命名。第一下单击会打开会话、侧栏整体重绘,元素已经换了,浏览器自己的 dblclick
231
215
  // 不一定触发;所以按 data-key 自己判断「同一条、两次按下间隔很短」
@@ -281,9 +265,9 @@ function renderLayout() {
281
265
  h(
282
266
  "div",
283
267
  { class: "side-top" },
284
- 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"), "新建"),
285
269
  ),
286
- createSidebarNav({ assistants: () => import("./assistants.js").then((m) => m.openAssistants()).catch((err) => toast(err.message)), 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 }),
287
271
  ui.convList,
288
272
  // 底部只有额度:没有额度可显示(关了查询、还没查到)时整块藏起来,连分隔线一起
289
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();