agent-loft 0.2.63 → 0.2.64

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/README.md CHANGED
@@ -54,6 +54,7 @@ Logo 就是这个意思:一大两小几颗星(多个 agent)站在同一张
54
54
  - 定时发送:右上角「更多」→「定时发送」,默认排在 5 小时额度重置后 5 分钟(弹窗里提示 5 小时 / 7 天额度的重置时间),由服务端到点发出,关掉页面也会发。适合额度用完、要等刷新才能接着干活的时候。
55
55
  - 侧栏直接显示各个文件夹,Web 会话按工作目录归类(目录可以拖动排序,右键可置顶;排好的顺序跟着账号走、各设备一致,新消息不会打乱),飞书机器人各占一行(右键看历史会话);项目名、有分叉的会话后面有个小三角,点一下折叠 / 展开(折叠后显示「N 个嵌套会话」);分叉出来的会话缩进挂在原会话下面,用一条细线连着;标题放不下时尾巴淡出;会话标题由 agent 自动生成,双击重命名;鼠标移到会话上,行尾显示对应的专家图标;定时任务的时钟图标始终放在最右侧。
56
56
  - **搜索**:侧栏「搜索」弹窗,搜全部会话的标题、目录名和聊天内容(不开记忆也能搜),可以按专家筛;电脑和手机上弹窗都固定高度,结果在内部滚动,手机上从底部展开;↑↓ 选、回车打开。
57
+ - **侧栏菜单**:项目上方的「更多」支持点击或鼠标悬停展开,设置入口也在这里。「编辑侧边栏」可勾选直接显示的菜单、拖动调整顺序,未勾选的收进「更多」;配置跟着账号走,电脑和手机共用。
57
58
  - 会话页顶部标题前是专家的头像,鼠标停上去或点一下,看专家的说明、模型、能力和当前工作目录。
58
59
  - 附件可以直接拖到聊天区任意位置上传。
59
60
  - 回复过程中接着发的消息排队,标着「排队中」,隐藏底部的复制和回退按钮,上一条回复完自动接着处理;点「撤销并编辑」图标把排队消息放回输入框;点「打断并发送」停掉正在进行的回复、马上处理这条;点停止则连排着的一起取消(标「没有发出」)。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-loft",
3
- "version": "0.2.63",
3
+ "version": "0.2.64",
4
4
  "type": "module",
5
5
  "description": "多个 agent 的工作台:把本机 Claude Code / Codex 放到一处统一管理,用飞书和 Web 页面随时驱动——会话、审批、模型切换都共用",
6
6
  "keywords": [
@@ -30,7 +30,7 @@ import {
30
30
  import type { AttachmentInfo, SavedAttachment } from "../../core/types.js";
31
31
  import { dailyUsage } from "../../core/usage.js";
32
32
  import { localUsage } from "../../core/local-usage.js";
33
- import { appendDirOrder, getDirOrder, setDirOrder } from "../../core/ui-prefs.js";
33
+ import { appendDirOrder, getDirOrder, getSidebarNav, setDirOrder, setSidebarNav } from "../../core/ui-prefs.js";
34
34
  import {
35
35
  addMemoryItem,
36
36
  clearMemory,
@@ -693,6 +693,7 @@ export async function handleApi(req: IncomingMessage, res: ServerResponse, url:
693
693
  },
694
694
  // 「项目」目录的顺序(拖拽排的),跟着账号走;null = 还没存过
695
695
  dirOrder: getDirOrder(user.id) ?? null,
696
+ sidebarNav: getSidebarNav(user.id),
696
697
  pending,
697
698
  user: publicMe(user),
698
699
  remote: remoteStatus(user),
@@ -711,6 +712,13 @@ export async function handleApi(req: IncomingMessage, res: ServerResponse, url:
711
712
  return;
712
713
  }
713
714
 
715
+ if (p === "/api/ui/sidebar-nav" && method === "PUT") {
716
+ const body = await readJsonBody<{ items?: unknown }>(req);
717
+ if (!Array.isArray(body.items)) throw new HttpError(400, "菜单配置必须是列表");
718
+ sendJson(res, 200, { items: setSidebarNav(user.id, body.items) });
719
+ return;
720
+ }
721
+
714
722
  // ----- 系统通知(Web Push) -----
715
723
  if (p === "/api/push" && method === "GET") {
716
724
  sendJson(res, 200, { publicKey: vapidPublicKey(), subscriptions: listSubscriptions(pushOwnedBy(user.id)) });
@@ -1,9 +1,11 @@
1
1
  // 每个用户的界面偏好,跟着账号走(换手机、换浏览器、桌面端都一样)。
2
- // 现在只有侧栏「项目」目录的顺序:用户拖过的顺序是固定的,新消息不会把目录顶到前面。
2
+ // 侧栏菜单的显示、顺序,以及「项目」目录的顺序。
3
3
  import path from "node:path";
4
4
  import { dataDir, readJson, writeJsonAtomic } from "../home.js";
5
5
 
6
- type Prefs = { dirOrder?: string[] };
6
+ export type SidebarNavItem = { id: string; visible: boolean };
7
+ const NAV_IDS = ["search", "tasks", "library", "remote", "settings"];
8
+ type Prefs = { dirOrder?: string[]; sidebarNav?: SidebarNavItem[] };
7
9
 
8
10
  const prefsPath = path.join(dataDir, "ui-prefs.json");
9
11
  let cache: Record<string, Prefs> | null = null;
@@ -53,6 +55,31 @@ export function appendDirOrder(userId: string, dirs: unknown): string[] {
53
55
  return dirOrder;
54
56
  }
55
57
 
58
+ /** 新菜单接在最后;未配置过的菜单沿用默认显示方式(设置默认收进「更多」)。 */
59
+ function cleanSidebarNav(value: unknown): SidebarNavItem[] {
60
+ const items: SidebarNavItem[] = [];
61
+ const seen = new Set<string>();
62
+ for (const item of Array.isArray(value) ? value : []) {
63
+ if (!item || typeof item !== "object" || !NAV_IDS.includes(item.id) || seen.has(item.id)) continue;
64
+ seen.add(item.id);
65
+ items.push({ id: item.id, visible: typeof item.visible === "boolean" ? item.visible : item.id !== "settings" });
66
+ }
67
+ for (const id of NAV_IDS) if (!seen.has(id)) items.push({ id, visible: id !== "settings" });
68
+ return items;
69
+ }
70
+
71
+ export function getSidebarNav(userId: string): SidebarNavItem[] {
72
+ return cleanSidebarNav(load()[userId]?.sidebarNav);
73
+ }
74
+
75
+ export function setSidebarNav(userId: string, value: unknown): SidebarNavItem[] {
76
+ const all = load();
77
+ const sidebarNav = cleanSidebarNav(value);
78
+ all[userId] = { ...all[userId], sidebarNav };
79
+ save();
80
+ return sidebarNav;
81
+ }
82
+
56
83
  export function deleteUiPrefs(userId: string): void {
57
84
  const all = load();
58
85
  if (!(userId in all)) return;
@@ -163,11 +163,12 @@ button.conv-group:hover {
163
163
 
164
164
  .proj-row {
165
165
  position: relative;
166
- margin-top: 2px;
166
+ margin-bottom: 4px;
167
167
  }
168
168
 
169
169
  .conv-item.proj {
170
170
  color: var(--fg-soft);
171
+ margin-bottom: 0;
171
172
  }
172
173
 
173
174
  .conv-item.proj:hover {
@@ -277,6 +278,7 @@ button.conv-group:hover {
277
278
  border-radius: 8px;
278
279
  font-size: 14px;
279
280
  position: relative;
281
+ margin-bottom: 4px;
280
282
  }
281
283
 
282
284
  .conv-item:hover {
@@ -372,7 +374,8 @@ button.conv-group:hover {
372
374
  margin-left: 0;
373
375
  }
374
376
 
375
- .conv-item .task-mark {
377
+ .conv-item .task-mark,
378
+ .conv-item .feishu-mark {
376
379
  flex-shrink: 0;
377
380
  width: 14px;
378
381
  height: 14px;
@@ -380,13 +383,16 @@ button.conv-group:hover {
380
383
  color: var(--fg-faint);
381
384
  }
382
385
 
383
- .conv-item .task-mark svg {
386
+ .conv-item .task-mark svg,
387
+ .conv-item .feishu-mark svg {
384
388
  width: 14px;
385
389
  height: 14px;
386
390
  }
387
391
 
388
392
  .conv-item > .dot ~ .task-mark,
389
- .conv-item > .conv-spin ~ .task-mark {
393
+ .conv-item > .conv-spin ~ .task-mark,
394
+ .conv-item > .dot ~ .feishu-mark,
395
+ .conv-item > .conv-spin ~ .feishu-mark {
390
396
  margin-left: 0;
391
397
  }
392
398
 
@@ -408,7 +414,8 @@ button.conv-group:hover {
408
414
  display: inline-grid;
409
415
  }
410
416
 
411
- .conv-item:hover .task-mark {
417
+ .conv-item:hover .task-mark,
418
+ .conv-item:hover .expert-mark ~ .feishu-mark {
412
419
  display: none;
413
420
  }
414
421
  }
@@ -657,7 +664,151 @@ button.conv-group:hover {
657
664
  color: var(--fg);
658
665
  }
659
666
 
660
- /* 「搜索」和下面的「定时任务」挨着,间距和「新聊天」到它一样 */
661
- .side-nav.search-nav {
667
+ /* 项目列表上方的菜单;「新建」固定,其余可配置显示和顺序。 */
668
+ .sidebar-nav {
669
+ padding: 4px 10px 8px;
670
+ flex-shrink: 0;
671
+ }
672
+
673
+ .sidebar-nav .side-nav {
674
+ width: 100%;
675
+ margin: 0 0 4px;
676
+ text-align: left;
677
+ }
678
+
679
+ .sidebar-nav .side-nav:last-child {
662
680
  margin-bottom: 0;
663
681
  }
682
+
683
+ .sidebar-nav .grow,
684
+ .sidebar-edit-row .grow {
685
+ flex: 1;
686
+ min-width: 0;
687
+ }
688
+
689
+ .side-more[aria-expanded="true"] {
690
+ background: var(--bg-hover);
691
+ }
692
+
693
+ .popover.side-more-menu {
694
+ min-width: 200px;
695
+ max-width: calc(100vw - 16px);
696
+ max-height: calc(100dvh - 16px);
697
+ overflow-y: auto;
698
+ }
699
+
700
+ .side-more-menu .pop-item {
701
+ display: flex;
702
+ align-items: center;
703
+ gap: 10px;
704
+ }
705
+
706
+ .side-more-menu .pop-item > span:first-child {
707
+ display: inline-grid;
708
+ flex-shrink: 0;
709
+ }
710
+
711
+ .side-more-menu .pop-item svg {
712
+ width: 16px;
713
+ height: 16px;
714
+ }
715
+
716
+ .side-more-menu .pop-item.active {
717
+ background: var(--bg-hover);
718
+ }
719
+
720
+ .side-more-menu .live-dot {
721
+ display: none;
722
+ width: 7px;
723
+ height: 7px;
724
+ margin-left: auto;
725
+ border-radius: 50%;
726
+ background: var(--ok);
727
+ }
728
+
729
+ .side-more-menu .live .live-dot {
730
+ display: block;
731
+ }
732
+
733
+ .modal.sidebar-editor {
734
+ max-width: 440px;
735
+ }
736
+
737
+ .sidebar-edit-hint {
738
+ margin: 0;
739
+ color: var(--fg-soft);
740
+ font-size: 13px;
741
+ line-height: 1.6;
742
+ }
743
+
744
+ .sidebar-edit-list {
745
+ display: flex;
746
+ flex-direction: column;
747
+ gap: 4px;
748
+ }
749
+
750
+ .sidebar-edit-row {
751
+ display: flex;
752
+ align-items: center;
753
+ border-radius: 8px;
754
+ min-height: 44px;
755
+ padding: 0 4px 0 10px;
756
+ }
757
+
758
+ .sidebar-edit-row:hover,
759
+ .sidebar-edit-row.dragging {
760
+ background: var(--bg-hover);
761
+ }
762
+
763
+ .sidebar-edit-row.dragging {
764
+ opacity: 0.6;
765
+ }
766
+
767
+ .sidebar-edit-row label {
768
+ display: flex;
769
+ align-items: center;
770
+ flex: 1;
771
+ gap: 12px;
772
+ min-height: 44px;
773
+ cursor: pointer;
774
+ font-size: 14px;
775
+ }
776
+
777
+ .sidebar-edit-row input {
778
+ width: 17px;
779
+ height: 17px;
780
+ flex-shrink: 0;
781
+ margin: 0;
782
+ accent-color: var(--accent);
783
+ }
784
+
785
+ .sidebar-edit-row svg {
786
+ width: 17px;
787
+ height: 17px;
788
+ color: var(--fg-soft);
789
+ }
790
+
791
+ .sidebar-edit-grip {
792
+ display: grid;
793
+ place-items: center;
794
+ width: 36px;
795
+ height: 40px;
796
+ flex-shrink: 0;
797
+ border-radius: 6px;
798
+ font-size: 18px;
799
+ letter-spacing: -3px;
800
+ color: var(--fg-faint);
801
+ cursor: grab;
802
+ touch-action: none;
803
+ user-select: none;
804
+ }
805
+
806
+ .sidebar-edit-grip:hover,
807
+ .sidebar-edit-grip:focus-visible {
808
+ color: var(--fg);
809
+ background: var(--bg-soft);
810
+ }
811
+
812
+ .sidebar-edit-grip:active {
813
+ cursor: grabbing;
814
+ }
@@ -46,6 +46,7 @@ function onOutsideMenu(e) {
46
46
  }
47
47
 
48
48
  export function closeMenu() {
49
+ ui.menu?.onMenuClose?.();
49
50
  ui.menu?.remove();
50
51
  ui.menu = null;
51
52
  document.removeEventListener("pointerdown", onOutsideMenu);
@@ -83,7 +84,12 @@ export function showPopover(anchor, { place = "above", align = "right" } = {}) {
83
84
  pop.dataset.align = align;
84
85
  document.body.append(pop);
85
86
  ui.menu = pop;
86
- setTimeout(() => document.addEventListener("pointerdown", onOutsideMenu), 0);
87
+ setTimeout(() => {
88
+ if (ui.menu !== pop) return;
89
+ document.addEventListener("pointerdown", onOutsideMenu);
90
+ document.addEventListener("keydown", onMenuKey);
91
+ addEventListener("blur", closeMenu);
92
+ }, 0);
87
93
  return pop;
88
94
  }
89
95
 
package/web/state.js CHANGED
@@ -5,6 +5,8 @@ export const S = {
5
5
  bots: [],
6
6
  convs: new Map(),
7
7
  pending: new Map(),
8
+ /** 侧栏菜单的显示和顺序,随账号保存;null 使用默认配置。 */
9
+ sidebarNav: null,
8
10
  current: null,
9
11
  /** 新对话的引擎(claude / codex),跟着选的专家走 */
10
12
  draftAgent: localStorage.getItem("aim.agent") || null,
@@ -30,6 +30,7 @@ import { createNav } from "./msg-nav.js";
30
30
  import { renameConv } from "./conv-actions.js";
31
31
  import { clearCommandCache, preloadCommands } from "./slash.js";
32
32
  import { releaseForeignPushSub } from "../lib/push.js";
33
+ import { createSidebarNav } from "./sidebar-nav.js";
33
34
 
34
35
  // ---------- 主界面 ----------
35
36
 
@@ -276,20 +277,7 @@ function renderLayout() {
276
277
  { class: "side-top" },
277
278
  h("button", { class: "btn new-chat", onclick: () => (newDraft(), closeSide()) }, icon("plus"), "新建"),
278
279
  ),
279
- // 搜索:弹窗里搜标题和聊天内容,可以按专家筛
280
- h("button", { class: "btn new-chat side-nav search-nav", onclick: () => openSearch() }, icon("search"), "搜索"),
281
- // 「最近」上面的入口,像 ChatGPT 的 Tasks。当前在任务页时高亮(renderSidebar 里切换)
282
- (ui.tasksNav = h("button", { class: "btn new-chat side-nav", onclick: () => openTasksView() }, icon("clock"), "定时任务")),
283
- // 资料库:发过的附件、agent 生成的文件
284
- (ui.libraryNav = h("button", { class: "btn new-chat side-nav", onclick: () => openLibraryView() }, icon("library"), "资料库")),
285
- // 远程控制:这台机器的桌面和终端。后台连着时右边亮个小绿点(renderSidebar 里切换)
286
- (ui.remoteNav = h(
287
- "button",
288
- { class: "btn new-chat side-nav", hidden: !remoteTabs().length, onclick: () => openRemoteView() },
289
- icon("monitor"),
290
- "远程控制",
291
- h("span", { class: "live-dot", title: "在后台连着" }),
292
- )),
280
+ createSidebarNav({ search: openSearch, tasks: openTasksView, library: openLibraryView, remote: openRemoteView, settings: openSettings }),
293
281
  ui.convList,
294
282
  // 底部只有额度:没有额度可显示(关了查询、还没查到)时整块藏起来,连分隔线一起
295
283
  (ui.sideBottom = h(
@@ -0,0 +1,299 @@
1
+ import { fill, h, icon, toast } from "../lib/dom.js";
2
+ import { api } from "../lib/api.js";
3
+ import { closeMenu, modal, showPopover } from "../lib/overlay.js";
4
+ import { remoteTabs, S, ui } from "../state.js";
5
+
6
+ const ITEMS = [
7
+ { id: "search", label: "搜索", icon: "search" },
8
+ { id: "tasks", label: "定时任务", icon: "clock" },
9
+ { id: "library", label: "资料库", icon: "library" },
10
+ { id: "remote", label: "远程控制", icon: "monitor" },
11
+ { id: "settings", label: "设置", icon: "gear" },
12
+ ];
13
+ let actions = {};
14
+ let navSignature = "";
15
+ let hoverTimer = 0;
16
+ let pinned = false;
17
+
18
+ function configuredItems() {
19
+ const seen = new Set();
20
+ const items = [];
21
+ for (const saved of S.sidebarNav ?? []) {
22
+ const item = ITEMS.find((it) => it.id === saved.id);
23
+ if (!item || seen.has(item.id)) continue;
24
+ seen.add(item.id);
25
+ items.push({ ...item, visible: saved.visible !== false });
26
+ }
27
+ return [...items, ...ITEMS.filter((it) => !seen.has(it.id)).map((it) => ({ ...it, visible: it.id !== "settings" }))];
28
+ }
29
+
30
+ const available = (item) => item.id !== "remote" || remoteTabs().length > 0;
31
+ const isActive = (item) => ["tasks", "library", "remote"].includes(item.id) && S.view === item.id;
32
+ const remoteLive = () => S.remoteLive.desktop || S.remoteLive.terminals > 0;
33
+
34
+ function navButton(item, inMenu = false) {
35
+ return h(
36
+ "button",
37
+ {
38
+ class: inMenu ? "pop-item side-nav-item" : `btn new-chat side-nav${item.id === "search" ? " search-nav" : ""}`,
39
+ "data-nav": item.id,
40
+ role: inMenu ? "menuitem" : null,
41
+ onclick: () => {
42
+ closeMenu();
43
+ actions[item.id]?.();
44
+ },
45
+ },
46
+ icon(item.icon),
47
+ h("span", { class: "grow" }, item.label),
48
+ item.id === "remote" ? h("span", { class: "live-dot", title: "在后台连着" }) : null,
49
+ );
50
+ }
51
+
52
+ export function createSidebarNav(handlers) {
53
+ actions = handlers;
54
+ navSignature = "";
55
+ ui.sidebarNav = h("nav", { class: "sidebar-nav", "aria-label": "侧边栏菜单" });
56
+ syncSidebarNav();
57
+ return ui.sidebarNav;
58
+ }
59
+
60
+ /** 会话重绘时只更新选中和连接状态,配置或权限变化时才重建入口。 */
61
+ export function syncSidebarNav() {
62
+ if (!ui.sidebarNav) return;
63
+ const items = configuredItems();
64
+ const signature = JSON.stringify([items, remoteTabs().length > 0]);
65
+ if (signature !== navSignature) {
66
+ if (ui.menu?.dataset.for === "sidebar-more") closeMenu();
67
+ clearTimeout(hoverTimer);
68
+ navSignature = signature;
69
+ const direct = items.filter((it) => it.visible && available(it)).map((it) => {
70
+ const button = navButton(it);
71
+ ui[`${it.id}Nav`] = button;
72
+ return button;
73
+ });
74
+ const more = h(
75
+ "button",
76
+ {
77
+ class: "btn new-chat side-nav side-more",
78
+ id: "sidebar-more",
79
+ "aria-haspopup": "menu",
80
+ "aria-expanded": "false",
81
+ onclick: () => {
82
+ clearTimeout(hoverTimer);
83
+ if (ui.menu?.anchor === more) {
84
+ if (!pinned) pinned = true;
85
+ else closeMenu();
86
+ } else openMore(more, true);
87
+ },
88
+ onpointerenter: (e) => {
89
+ if (e.pointerType !== "mouse") return;
90
+ clearTimeout(hoverTimer);
91
+ if (ui.menu?.anchor !== more) hoverTimer = setTimeout(() => openMore(more, false), 200);
92
+ },
93
+ onpointerleave: (e) => e.pointerType === "mouse" && scheduleClose(),
94
+ onkeydown: (e) => {
95
+ if (e.key !== "ArrowDown") return;
96
+ e.preventDefault();
97
+ openMore(more, true);
98
+ ui.menu?.querySelector("button")?.focus();
99
+ },
100
+ },
101
+ icon("more"),
102
+ h("span", { class: "grow" }, "更多"),
103
+ h("span", { class: "live-dot", title: "远程控制在后台连着" }),
104
+ );
105
+ ui.sideMore = more;
106
+ fill(ui.sidebarNav, ...direct, more);
107
+ }
108
+ for (const container of [ui.sidebarNav, ui.menu?.dataset.for === "sidebar-more" ? ui.menu : null]) {
109
+ for (const button of container?.querySelectorAll("[data-nav]") ?? []) {
110
+ button.classList.toggle("active", isActive({ id: button.dataset.nav }));
111
+ button.classList.toggle("live", button.dataset.nav === "remote" && remoteLive());
112
+ }
113
+ }
114
+ const folded = items.filter((it) => !it.visible && available(it));
115
+ ui.sideMore.classList.toggle("active", folded.some(isActive));
116
+ ui.sideMore.classList.toggle("live", folded.some((it) => it.id === "remote") && remoteLive());
117
+ }
118
+
119
+ function scheduleClose() {
120
+ clearTimeout(hoverTimer);
121
+ hoverTimer = setTimeout(() => {
122
+ if (!pinned && ui.menu?.dataset.for === "sidebar-more") closeMenu();
123
+ }, 200);
124
+ }
125
+
126
+ function openMore(anchor, pin) {
127
+ if (!anchor.isConnected) return;
128
+ clearTimeout(hoverTimer);
129
+ const pop = showPopover(anchor);
130
+ pop.classList.add("side-more-menu");
131
+ pop.dataset.for = "sidebar-more";
132
+ pop.setAttribute("role", "menu");
133
+ pop.setAttribute("aria-label", "更多菜单");
134
+ pinned = pin;
135
+ anchor.setAttribute("aria-expanded", "true");
136
+ pop.onMenuClose = () => {
137
+ clearTimeout(hoverTimer);
138
+ anchor.setAttribute("aria-expanded", "false");
139
+ };
140
+ pop.onpointerenter = () => clearTimeout(hoverTimer);
141
+ pop.onpointerleave = (e) => e.pointerType === "mouse" && scheduleClose();
142
+ pop.onkeydown = (e) => {
143
+ const buttons = [...pop.querySelectorAll("button")];
144
+ const i = buttons.indexOf(document.activeElement);
145
+ if (e.key === "Escape") {
146
+ e.preventDefault();
147
+ e.stopPropagation();
148
+ closeMenu();
149
+ anchor.focus();
150
+ } else if (["ArrowDown", "ArrowUp", "Home", "End"].includes(e.key)) {
151
+ e.preventDefault();
152
+ const next = e.key === "Home" ? 0 : e.key === "End" ? buttons.length - 1 : (i + (e.key === "ArrowDown" ? 1 : -1) + buttons.length) % buttons.length;
153
+ buttons[next]?.focus();
154
+ }
155
+ };
156
+ const folded = configuredItems().filter((it) => !it.visible && available(it));
157
+ fill(
158
+ pop,
159
+ ...folded.map((it) => navButton(it, true)),
160
+ folded.length ? h("div", { class: "sep" }) : null,
161
+ h("button", { class: "pop-item", role: "menuitem", onclick: () => (closeMenu(), editSidebar()) }, icon("edit"), "编辑侧边栏"),
162
+ );
163
+ syncSidebarNav();
164
+ const r = anchor.getBoundingClientRect();
165
+ const width = pop.offsetWidth;
166
+ const side = innerWidth > 768 && r.right + width + 16 <= innerWidth;
167
+ pop.style.left = `${Math.max(8, Math.min(side ? r.right + 8 : r.left, innerWidth - width - 8))}px`;
168
+ pop.style.top = `${Math.max(8, Math.min(side ? r.top : r.bottom + 6, innerHeight - pop.offsetHeight - 8))}px`;
169
+ }
170
+
171
+ function editSidebar() {
172
+ const draft = configuredItems();
173
+ const list = h("div", { class: "sidebar-edit-list", role: "list", "aria-label": "菜单显示与顺序" });
174
+ const rows = new Map();
175
+ let saving = false;
176
+ const move = (id, to) => {
177
+ const from = draft.findIndex((it) => it.id === id);
178
+ if (from === to || to < 0 || to >= draft.length) return;
179
+ draft.splice(to, 0, ...draft.splice(from, 1));
180
+ for (const it of draft) list.append(rows.get(it.id));
181
+ };
182
+ for (const item of draft) {
183
+ const checkbox = h("input", {
184
+ type: "checkbox",
185
+ checked: item.visible,
186
+ onchange: () => (item.visible = checkbox.checked),
187
+ });
188
+ let drag = null;
189
+ const endDrag = () => {
190
+ drag = null;
191
+ row.classList.remove("dragging");
192
+ if (handle.hasPointerCapture(dragPointer)) handle.releasePointerCapture(dragPointer);
193
+ };
194
+ let dragPointer = 0;
195
+ const handle = h("button", {
196
+ class: "sidebar-edit-grip",
197
+ type: "button",
198
+ title: "拖动排序,也可用上下方向键调整",
199
+ "aria-label": `调整${item.label}顺序`,
200
+ onpointerdown: (e) => {
201
+ if (e.button !== 0 || saving) return;
202
+ e.preventDefault();
203
+ drag = { y: e.clientY };
204
+ dragPointer = e.pointerId;
205
+ handle.setPointerCapture(e.pointerId);
206
+ },
207
+ onpointermove: (e) => {
208
+ if (!drag || Math.abs(e.clientY - drag.y) < 4) return;
209
+ row.classList.add("dragging");
210
+ const to = draft.filter((it) => it.id !== item.id).filter((it) => {
211
+ const r = rows.get(it.id).getBoundingClientRect();
212
+ return e.clientY > r.top + r.height / 2;
213
+ }).length;
214
+ move(item.id, to);
215
+ handle.setPointerCapture(e.pointerId);
216
+ },
217
+ onpointerup: endDrag,
218
+ onpointercancel: endDrag,
219
+ onkeydown: (e) => {
220
+ if (saving || !["ArrowUp", "ArrowDown"].includes(e.key)) return;
221
+ e.preventDefault();
222
+ move(item.id, draft.indexOf(item) + (e.key === "ArrowUp" ? -1 : 1));
223
+ handle.focus();
224
+ },
225
+ }, "⋮⋮");
226
+ const row = h(
227
+ "div", { class: "sidebar-edit-row", role: "listitem", "data-nav": item.id },
228
+ h("label", {}, checkbox, icon(item.icon), h("span", { class: "grow" }, item.label)),
229
+ handle,
230
+ );
231
+ rows.set(item.id, row);
232
+ list.append(row);
233
+ }
234
+ const body = h("div", { class: "modal-body" }, h("p", { class: "sidebar-edit-hint" }, "勾选的菜单直接显示,未勾选的收进「更多」。拖动右侧手柄调整顺序。"), list);
235
+ const close = () => {
236
+ if (saving) return;
237
+ document.removeEventListener("keydown", onKey, true);
238
+ dismiss();
239
+ ui.sideMore?.focus();
240
+ };
241
+ const onKey = (e) => {
242
+ if (e.key === "Tab") {
243
+ const focusable = [...dialog.querySelectorAll("button:not(:disabled), input:not(:disabled)")];
244
+ const edge = e.shiftKey ? focusable[0] : focusable.at(-1);
245
+ if (document.activeElement === edge) {
246
+ e.preventDefault();
247
+ (e.shiftKey ? focusable.at(-1) : focusable[0])?.focus();
248
+ }
249
+ return;
250
+ }
251
+ if (e.key !== "Escape") return;
252
+ e.preventDefault();
253
+ e.stopPropagation();
254
+ close();
255
+ };
256
+ const done = h("button", {
257
+ class: "btn primary",
258
+ onclick: async () => {
259
+ if (saving) return;
260
+ saving = true;
261
+ done.disabled = true;
262
+ done.textContent = "保存中…";
263
+ list.inert = true;
264
+ try {
265
+ const items = draft.map(({ id, visible }) => ({ id, visible }));
266
+ const result = await api("/api/ui/sidebar-nav", { method: "PUT", body: { items } });
267
+ S.sidebarNav = result.items;
268
+ syncSidebarNav();
269
+ saving = false;
270
+ close();
271
+ } catch (err) {
272
+ toast(`侧边栏保存失败:${err.message}`);
273
+ } finally {
274
+ saving = false;
275
+ done.disabled = false;
276
+ done.textContent = "完成";
277
+ list.inert = false;
278
+ }
279
+ },
280
+ }, "完成");
281
+ const dismiss = modal({
282
+ title: "编辑侧边栏",
283
+ className: "sidebar-editor",
284
+ body,
285
+ foot: h("div", { class: "modal-foot" }, h("button", { class: "btn ghost", onclick: close }, "取消"), done),
286
+ beforeClose: () => {
287
+ if (saving) return false;
288
+ close();
289
+ return false;
290
+ },
291
+ });
292
+ const dialog = body.closest(".modal");
293
+ dialog.setAttribute("role", "dialog");
294
+ dialog.setAttribute("aria-modal", "true");
295
+ dialog.setAttribute("aria-label", "编辑侧边栏");
296
+ dialog.querySelector(".modal-head .icon-btn").setAttribute("aria-label", "关闭");
297
+ document.addEventListener("keydown", onKey, true);
298
+ list.querySelector("input")?.focus();
299
+ }
@@ -1,11 +1,12 @@
1
1
  import { fill, h, icon, ICON, toast } from "../lib/dom.js";
2
2
  import { api } from "../lib/api.js";
3
- import { desktop, remoteTabs, S, ui } from "../state.js";
3
+ import { desktop, S, ui } from "../state.js";
4
4
  import { baseName } from "./topbar.js";
5
5
  import { newDraft, openConversation } from "./messages.js";
6
- import { convExpert, expertIcon } from "./experts.js";
6
+ import { convExpert, expertIcon, setDraftExpert } from "./experts.js";
7
7
  import { leaveRemote } from "./remote.js";
8
8
  import { reportShellState } from "../lib/shell.js";
9
+ import { syncSidebarNav } from "./sidebar-nav.js";
9
10
 
10
11
  // ---------- 侧栏标题跑马灯:名字被省略时,hover 来回滚动显示全名 ----------
11
12
 
@@ -351,6 +352,7 @@ export function bootstrapQuery() {
351
352
  }
352
353
 
353
354
  export function applyBootstrap(data) {
355
+ S.sidebarNav = data.sidebarNav ?? null;
354
356
  S.convs = new Map(data.conversations.map((c) => [c.key, c]));
355
357
  pages.full = !data.sidebar;
356
358
  pages.recent.next = data.sidebar?.recent.next ?? null;
@@ -442,13 +444,7 @@ export function renderSidebar() {
442
444
  return;
443
445
  }
444
446
  sidebarStale = false;
445
- ui.tasksNav?.classList.toggle("active", S.view === "tasks");
446
- ui.libraryNav?.classList.toggle("active", S.view === "library");
447
- if (ui.remoteNav) {
448
- ui.remoteNav.hidden = !remoteTabs().length;
449
- ui.remoteNav.classList.toggle("active", S.view === "remote");
450
- ui.remoteNav.classList.toggle("live", S.remoteLive.desktop || S.remoteLive.terminals > 0);
451
- }
447
+ syncSidebarNav();
452
448
  const askKeys = new Set([...S.pending.values()].filter((i) => !i.settled).map((i) => i.convKey));
453
449
  const visible = [...S.convs.values()].filter((c) => !c.hidden).sort((a, b) => b.activeAt - a.activeAt);
454
450
  const cur = S.current ? S.convs.get(S.current) : null;
@@ -500,10 +496,10 @@ export function renderSidebar() {
500
496
  title: latest ? `飞书 · ${bot.name}\n${agentLabel(latest.agent)} · ${latest.cwd}` : `飞书 · ${bot.name}\n还没有会话`,
501
497
  onclick: () => (latest ? open(latest.key) : toast("这个机器人还没有会话,先在飞书里给它发条消息")),
502
498
  },
503
- h("span", { class: "brand-icon lead", title: "飞书", html: ICON.feishu }),
504
499
  h("span", { class: "title" }, bot.name),
505
500
  status(convs.map((c) => c.key)),
506
501
  convExpertMark(latest),
502
+ h("span", { class: "brand-icon feishu-mark", title: "飞书", html: ICON.feishu }),
507
503
  ),
508
504
  });
509
505
  }
@@ -596,11 +592,30 @@ export function renderSidebar() {
596
592
  {
597
593
  class: "proj-new",
598
594
  title: `在 ${baseName(dir)} 中开新对话`,
599
- onclick: () => {
600
- S.draftCwd = dir === S.workspaceRoot ? null : dir;
601
- S.draftCwdPicked = true;
602
- newDraft();
603
- closeSide();
595
+ onclick: async (e) => {
596
+ const button = e.currentTarget;
597
+ button.disabled = true;
598
+ try {
599
+ let latest = convs[0];
600
+ // 收起的项目可能只加载了旧会话,先补齐最近一棵树,再按会话活跃时间选。
601
+ if (!pages.full && (!latest || latest.activeAt < (pages.dirAt.get(dir) ?? 0))) {
602
+ const q = new URLSearchParams({ scope: "dir", dir, limit: "1" });
603
+ const data = await api(`/api/conversations/page?${q}`);
604
+ for (const c of data.conversations) S.convs.set(c.key, c);
605
+ latest = [...S.convs.values()]
606
+ .filter((c) => !c.hidden && c.channel === "web" && c.cwd === dir)
607
+ .sort((a, b) => b.activeAt - a.activeAt)[0];
608
+ }
609
+ S.draftCwd = dir === S.workspaceRoot ? null : dir;
610
+ S.draftCwdPicked = true;
611
+ if (latest) setDraftExpert(latest.expert?.id ?? latest.agent);
612
+ newDraft();
613
+ closeSide();
614
+ } catch (err) {
615
+ toast(`新对话创建失败:${err.message}`);
616
+ } finally {
617
+ button.disabled = false;
618
+ }
604
619
  },
605
620
  },
606
621
  icon("plus"),
@@ -1,12 +1,11 @@
1
1
  import { fill, h, icon, ICON, toast } from "../lib/dom.js";
2
2
  import { api } from "../lib/api.js";
3
3
  import { relTime } from "../lib/time.js";
4
- import { desktop, desktopMenu, desktopSettings, S, ui } from "../state.js";
4
+ import { desktop, desktopMenu, S, ui } from "../state.js";
5
5
  import { agentLabel, convTitle, openSide } from "./sidebar.js";
6
6
  import { convExpert, expertChoices, expertIcon, findExpert } from "./experts.js";
7
7
  import { closeMenu, modal, placePopover, showMenu, showPopover } from "../lib/overlay.js";
8
8
  import { openConversation } from "./messages.js";
9
- import { openSettings } from "./layout.js";
10
9
  import { openSchedule } from "./schedule.js";
11
10
  import { changeCwd, deleteConv, doAction, forkConversation, openModelPicker, renameConv, switchAgent } from "./conv-actions.js";
12
11
 
@@ -142,19 +141,12 @@ function openExpertCard(anchor, key, pinned) {
142
141
  placePopover(pop, anchor);
143
142
  }
144
143
 
145
- /**
146
- * 右上角「更多」里的项。对话页(含新对话)有定时发送;设置哪个页面都有,
147
- * 桌面端自己的「更多」里已经有每台服务器的设置时不放
148
- */
144
+ /** 右上角「更多」只放当前对话的操作;设置在侧边栏的「更多」里。 */
149
145
  function topMenuItems() {
150
146
  const items = [];
151
147
  if (!S.view) {
152
148
  items.push({ id: "schedule", label: "定时发送", icon: "clock", onclick: () => openSchedule() });
153
149
  }
154
- if (!desktopSettings) {
155
- if (items.length) items.push("sep");
156
- items.push({ id: "settings", label: "设置", icon: "gear", onclick: () => openSettings() });
157
- }
158
150
  return items;
159
151
  }
160
152