agent-loft 0.2.66 → 0.2.67

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
@@ -52,7 +52,7 @@ Logo 就是这个意思:一大两小几颗星(多个 agent)站在同一张
52
52
  - 输入框里的小圆环显示上下文窗口占用;模型按钮显示实际的模型和思考程度(如「Opus 5.5 high」)。
53
53
  - 滚动和 ChatGPT 一样:发出的问题顶到最上面、下面留白,回复长到屏幕底部才跟着往下滚;回复过程中自己滚动了就不再自动滚,下次发消息再恢复。
54
54
  - 定时发送:右上角「更多」→「定时发送」,默认排在 5 小时额度重置后 5 分钟(弹窗里提示 5 小时 / 7 天额度的重置时间),由服务端到点发出,关掉页面也会发。适合额度用完、要等刷新才能接着干活的时候。
55
- - 侧栏直接显示各个文件夹,Web 会话按工作目录归类(目录可以拖动排序,右键可置顶;排好的顺序跟着账号走、各设备一致,新消息不会打乱),飞书机器人各占一行(右键看历史会话);项目名、有分叉的会话后面有个小三角,点一下折叠 / 展开(折叠后显示「N 个嵌套会话」);分叉出来的会话缩进挂在原会话下面,用一条细线连着;标题放不下时尾巴淡出;会话标题由 agent 自动生成,双击重命名;鼠标移到会话上,行尾显示对应的专家图标;定时任务的时钟图标始终放在最右侧。
55
+ - 侧栏直接显示各个文件夹,Web 会话按工作目录归类(目录可以拖动排序,右键可置顶;排好的顺序跟着账号走、各设备一致,新消息不会打乱),飞书会话按机器人分组,也能展开 / 折叠并记住状态(右键仍可看历史会话)。机器人行右侧平时显示飞书图标,鼠标悬停时切成加号;点击加号在 Web 开新对话,沿用最近飞书会话的专家和工作目录。项目名、机器人名和有分叉的会话后面有个小三角,点一下折叠 / 展开(分叉折叠后显示「N 个嵌套会话」);分叉出来的会话缩进挂在原会话下面,用一条细线连着;标题放不下时尾巴淡出;Web 和飞书会话都先用首条消息命名,再同步 agent 自动生成的标题,旧飞书会话会从历史记录补名,双击可手动重命名;鼠标移到会话上,行尾显示对应的专家图标;定时任务的时钟图标始终放在最右侧。
56
56
  - **搜索**:侧栏「搜索」弹窗,搜全部会话的标题、目录名和聊天内容(不开记忆也能搜),可以按专家筛;电脑和手机上弹窗都固定高度,结果在内部滚动,手机上从底部展开;↑↓ 选、回车打开。
57
57
  - **侧栏菜单**:项目上方的「更多」支持点击或鼠标悬停展开,设置入口也在这里。「编辑侧边栏」可勾选直接显示的菜单、拖动调整顺序,未勾选的收进「更多」;配置跟着账号走,电脑和手机共用。
58
58
  - 会话页顶部标题前是专家的头像,鼠标停上去或点一下,看专家的说明、模型、能力和当前工作目录。
@@ -61,7 +61,7 @@ Logo 就是这个意思:一大两小几颗星(多个 agent)站在同一张
61
61
  - 用户消息的复制按钮后有「回退到此处」图标:把这条消息及附件放回输入框,并删除它及之后的聊天内容,重新发送时从之前的上下文继续。
62
62
  - 太长的消息先收起,点「展开显示」看全文;对话里有至少 3 条用户消息时,右侧显示快速定位尺,电脑上鼠标移入查看消息开头、点击跳转;手机上手动滚动时显示短轨道,按住拖动可预览问题和位置,松手跳转,停止操作约 1.6 秒后隐藏。
63
63
  - 回复底部的 token 数自动按大小显示为 K、M 等单位。
64
- - 侧栏按页加载:每个项目目录先显示 5 条,点「展开显示」每次再拉 10 条。
64
+ - 侧栏按页加载:每个项目目录和飞书机器人分组先显示 5 条,点「展开显示」每次再拉 10 条。
65
65
  - 侧栏底部显示 Claude / Codex 的订阅额度(5 小时 / 7 天窗口,以及多久后重置);关了额度查询就整块不显示。
66
66
  - 右上角「更多」最下面显示当前会话累计消耗的 token 分布(输入 / 缓存写入 / 缓存读取 / 输出,Claude 还有按 API 价格估算的费用)。设置也在「更多」里。
67
67
  - 设置 → 用量:按日 / 月 / 年(默认按月)统计 token 和金额,有每天(每月)的柱状图,按 agent、模型、用户(管理员才有)分开看;成员只看到自己的。管理员还可查看服务端本机直接使用的 Claude Code、Codex 桌面端和 CLI 用量,和 Agent Loft 的用量分开显示、避免重复计算。金额都是按 API 价格算的参考值:Agent Loft 的 Claude 用它自己报的费用,Codex 和直接用的 Claude Code 按模型单价 × token 估算(OpenAI 单价来自 LiteLLM 公开价格表,内置快照、联网时每天更新)。Agent Loft 的账从 0.2.34 开始记录;本机直接使用的用量可回溯已有会话记录。
@@ -70,7 +70,7 @@ Logo 就是这个意思:一大两小几颗星(多个 agent)站在同一张
70
70
  - **系统通知**:Web 会话回复完成、出错、需要授权或提问时推送到手机 / 电脑(设置 → 通知 → 「在此设备开启通知」,可以发测试通知)。飞书会话由飞书提醒,正在前台看着的会话不推。需要 HTTPS 访问,iPhone 需 iOS 16.4+ 且从主屏幕图标打开。
71
71
  - **跨渠道同步**:飞书里的会话在 Web 上也能打开接着聊。同一个授权请求同时出现在飞书卡片和网页上,哪边先点算哪边,另一边自动变成「已处理」。
72
72
  - **授权**:允许一次 / 本会话全部允许 / 总是允许(按钮上写明放行范围)/ 拒绝。`/autoedit on` 让 Claude Code 在这条会话里改工作目录内的文件不再询问(Bash 仍询问)。超时一律按拒绝处理。
73
- - **设置都在网页上**,按用途分组:**我的**(账号和密码、飞书绑定、登录设备、通知、记忆、技能、用量,每个人都有);**Agent**(运行环境、各 agent 的默认模型和思考程度、可选模型、Codex 沙箱、额度查询;工作目录、会话闲置过期、授权卡超时和 Claude 的「总是允许」名单;「/」命令);**连接**(飞书机器人、配对批准、指令面板同步;远程控制;服务器);**管理**(用户、所有人的登录设备;服务端版本和升级、重启、局域网访问和端口)。改了没保存就切页或关掉设置会先提醒。
73
+ - **设置都在网页上**,按用途分组:**我的**(账号和密码、飞书绑定、登录设备、通知、记忆、技能、用量,每个人都有);**Agent**(运行环境、各 agent 的默认模型和思考程度、可选模型、Codex 沙箱、额度查询;工作目录、会话闲置过期、授权卡超时和 Claude 的「总是允许」名单;「/」命令);**连接**(飞书机器人、配对批准、指令面板同步;远程控制;服务器);**管理**(用户、所有人的登录设备;服务端版本和升级、重启、局域网访问和端口)。设置、新建 / 编辑专家、重命名等编辑弹窗不会因点击外部或按 Esc 关闭;通过关闭、取消或保存 / 完成按钮退出。改了没保存就切页或关掉设置会先提醒。
74
74
  - **多用户**(信任型):管理员在 设置 → 用户 里给别人建账号。每个人只看得到自己的对话、授权和通知,设置只有管理员能改,见下面「安全」。
75
75
  - **专家**:设置 → 专家。专家是一份配置,新建对话、定时任务时选一个,对话从头到尾都是它(中途不能换;飞书里 `/expert 名字`、`/claude`、`/codex` 换专家会开新会话)。**内置专家**:Claude Code、Codex,保留原装提示词和所有工具,默认技能与 MCP 在「设置 → Agent」中按账号、按引擎分别选择。**自定义专家**由创建者管理,可以勾选「共享给所有账号」。共享后,其他人能在网页、绑定账号后的飞书私聊和定时任务中选择它;只有创建者能修改设定。每个人在该专家的「我的工具」里选择自己的技能和 MCP,使用各自的变量、凭据、记忆和聊天记录;创建者沿用原有工具选择,其他人未配置时不加载技能或 MCP。取消共享后,其他人的历史对话保留,后续消息不能继续调用该专家,相关定时任务在下次运行时暂停。可以配:
76
76
  - 头像(点头像区域的加号上传;未上传时,会话中用引擎的图标)、引擎(Claude / Codex,建好后不能换)、默认模型和思考程度(从模型列表里选);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-loft",
3
- "version": "0.2.66",
3
+ "version": "0.2.67",
4
4
  "type": "module",
5
5
  "description": "多个 agent 的工作台:把本机 Claude Code / Codex 放到一处统一管理,用飞书和 Web 页面随时驱动——会话、审批、模型切换都共用",
6
6
  "keywords": [
@@ -694,7 +694,7 @@ export async function handleApi(req: IncomingMessage, res: ServerResponse, url:
694
694
  workspaceRoot: config().workspaceRoot,
695
695
  quotaRefreshMin: config().web.quotaRefreshMin,
696
696
  quotaEnabled: config().web.quotaEnabled,
697
- conversations: [...keep.values()],
697
+ conversations: await hub.backfillFeishuTitles([...keep.values()]),
698
698
  sidebar: {
699
699
  recent: { next: recent.next },
700
700
  // 展开着的目录带上翻页游标(没带 next 的目录前端还没拉过)
@@ -813,13 +813,19 @@ export async function handleApi(req: IncomingMessage, res: ServerResponse, url:
813
813
  }
814
814
 
815
815
  // ----- 会话 -----
816
- // 侧栏按页拉:scope=recent(最近)/ dir(某个项目目录)按树分页;bot(某个飞书机器人的全部聊天)平铺
816
+ // 侧栏按页拉:recent / dir / bot 按树分页;bot 不传 limit 时保留历史弹窗的平铺列表。
817
817
  if (p === "/api/conversations/page" && method === "GET") {
818
818
  const all = hub.list(visible).filter((c) => !c.hidden);
819
819
  const scope = url.searchParams.get("scope");
820
820
  if (scope === "bot") {
821
821
  const bot = url.searchParams.get("bot") ?? "";
822
- sendJson(res, 200, { conversations: all.filter((c) => c.channel === "feishu" && c.channelId === bot).slice(0, 200), next: null });
822
+ const list = all.filter((c) => c.channel === "feishu" && c.channelId === bot);
823
+ const before = parseCursor(url.searchParams.get("at"), url.searchParams.get("key"));
824
+ const page = url.searchParams.has("limit")
825
+ ? pageOf(list, before, clampLimit(url.searchParams.get("limit"), 5))
826
+ : { conversations: list.slice(0, 200), next: null };
827
+ page.conversations = await hub.backfillFeishuTitles(page.conversations);
828
+ sendJson(res, 200, page);
823
829
  return;
824
830
  }
825
831
  if (scope !== "recent" && scope !== "dir") throw new HttpError(400, "scope 只能是 recent / dir / bot");
@@ -9,7 +9,7 @@ export type Cursor = { at: number; key: string };
9
9
  export type Page = { conversations: ConversationInfo[]; next: Cursor | null };
10
10
  type Tree = { root: ConversationInfo; convs: ConversationInfo[]; at: number };
11
11
 
12
- /** 最近:飞书以外的会话(飞书按机器人各占一行,另外给) */
12
+ /** 最近:飞书以外的会话(飞书单独按机器人分组) */
13
13
  export const inRecent = (c: ConversationInfo): boolean => c.channel !== "feishu";
14
14
  /** 项目:Web 会话按工作目录分组 */
15
15
  export const inDir = (dir: string) => (c: ConversationInfo): boolean => c.channel === "web" && c.cwd === dir;
package/src/core/hub.ts CHANGED
@@ -632,6 +632,32 @@ class Hub extends EventEmitter<{ event: [EventEnvelope]; task: [TaskTurnEnd] }>
632
632
  .sort((a, b) => b.activeAt - a.activeAt);
633
633
  }
634
634
 
635
+ /** 旧版飞书会话没有自动命名;只为当前要显示的会话从已有记录补首条消息。 */
636
+ async backfillFeishuTitles(list: ConversationInfo[]): Promise<ConversationInfo[]> {
637
+ return Promise.all(list.map(async (info) => {
638
+ const conv = getConversation(info.key);
639
+ if (!conv || conv.channel !== "feishu" || conv.title || conv.titleAuto === false) return info;
640
+ const { agent, cwd } = conv;
641
+ const sessionId = agentBinding(conv).sessionId;
642
+ const driver = this.enabledAgents().find((d) => d.id === agent);
643
+ if (!sessionId || !driver) return info;
644
+ try {
645
+ const messages = await withTimeout(driver.readHistory(sessionId, cwd), "读取会话标题", 3000);
646
+ const first = messages.find((m) => m.role === "user" && m.text.trim());
647
+ const now = getConversation(info.key);
648
+ // 读记录期间用户可能改名、切专家或切目录,不能把旧标题写进新会话。
649
+ if (first && now && !now.title && now.titleAuto !== false && now.agent === agent && now.cwd === cwd && agentBinding(now).sessionId === sessionId) {
650
+ updateConversation(info.key, { title: first.text.trim().replace(/\s+/g, " ").slice(0, 40), titleAuto: true });
651
+ this.emitEvent(info.key, { type: "meta" });
652
+ this.syncTitle(info.key, agent);
653
+ }
654
+ } catch (err) {
655
+ console.warn(`[${agent}] 补齐飞书会话标题失败:`, err instanceof Error ? err.message : err);
656
+ }
657
+ return this.info(info.key) ?? info;
658
+ }));
659
+ }
660
+
635
661
  /** 取活着的 agent 会话,没有就按绑定拉起(默认续用上次的会话)。 */
636
662
  session(key: string, opts: { resumeId?: string; fork?: boolean } = {}): AgentSession {
637
663
  const conv = getConversation(key);
@@ -1016,7 +1042,7 @@ class Hub extends EventEmitter<{ event: [EventEnvelope]; task: [TaskTurnEnd] }>
1016
1042
  // 闲置过期要按这次说话之前的活跃时间判断,所以先记下、后 touch
1017
1043
  const lastActive = conv.activeAt;
1018
1044
  touchConversation(key);
1019
- if (!conv.title && conv.channel === "web" && shown.text.trim()) {
1045
+ if (!conv.title && conv.titleAuto !== false && (conv.channel === "web" || conv.channel === "feishu") && shown.text.trim()) {
1020
1046
  // 先用首条消息占位,第一轮结束后换成 agent 自己生成的短标题(syncTitle)
1021
1047
  updateConversation(key, { title: shown.text.trim().replace(/\s+/g, " ").slice(0, 40), titleAuto: true });
1022
1048
  this.emitEvent(key, { type: "meta" });
@@ -255,6 +255,40 @@ button.conv-group:hover {
255
255
  display: grid;
256
256
  }
257
257
 
258
+ /* 飞书分组的同一位置:平时显示飞书,悬停或键盘聚焦时显示新建加号。 */
259
+ .bot-row .conv-item.proj {
260
+ padding-right: 36px;
261
+ }
262
+
263
+ .bot-new {
264
+ display: grid;
265
+ }
266
+
267
+ .bot-new .feishu-mark,
268
+ .bot-new .bot-plus {
269
+ grid-area: 1 / 1;
270
+ }
271
+
272
+ .bot-new .feishu-mark,
273
+ .bot-new .feishu-mark svg {
274
+ width: 14px;
275
+ height: 14px;
276
+ }
277
+
278
+ .bot-new .bot-plus {
279
+ visibility: hidden;
280
+ }
281
+
282
+ .bot-row:hover .bot-new .feishu-mark,
283
+ .bot-row:focus-within .bot-new .feishu-mark {
284
+ visibility: hidden;
285
+ }
286
+
287
+ .bot-row:hover .bot-new .bot-plus,
288
+ .bot-row:focus-within .bot-new .bot-plus {
289
+ visibility: visible;
290
+ }
291
+
258
292
  /* 鼠标挪到右边的加号上时,整行的 hover 底色还留着 */
259
293
  .proj-row:hover .conv-item.proj {
260
294
  padding-right: 36px;
@@ -266,6 +300,14 @@ button.conv-group:hover {
266
300
  .proj-new {
267
301
  display: grid;
268
302
  }
303
+
304
+ .bot-new .bot-plus {
305
+ visibility: visible;
306
+ }
307
+
308
+ .bot-new .feishu-mark {
309
+ visibility: hidden;
310
+ }
269
311
  }
270
312
 
271
313
  .conv-item {
@@ -54,7 +54,7 @@ export function closeMenu() {
54
54
  removeEventListener("blur", closeMenu);
55
55
  }
56
56
 
57
- /** beforeClose:点 × 或点外面关闭前先问它,返回(或 resolve 成)false 就不关。返回的 close 不问,直接关 */
57
+ /** 弹窗只通过按钮关闭,点击遮罩不关闭。beforeClose:点 × 前先问它,false 就不关。返回的 close 直接关 */
58
58
  export function modal({ title, body, foot, wide, tall, className = "", beforeClose }) {
59
59
  const close = () => overlay.remove();
60
60
  const tryClose = async () => {
@@ -62,11 +62,11 @@ export function modal({ title, body, foot, wide, tall, className = "", beforeClo
62
62
  };
63
63
  const overlay = h(
64
64
  "div",
65
- { class: "overlay", onclick: (e) => e.target === overlay && void tryClose() },
65
+ { class: "overlay" },
66
66
  h(
67
67
  "div",
68
68
  { class: `modal${wide ? " wide" : ""}${tall ? " tall" : ""}${className ? ` ${className}` : ""}` },
69
- h("div", { class: "modal-head" }, h("h3", {}, title), h("button", { class: "icon-btn", onclick: () => void tryClose() }, icon("x"))),
69
+ h("div", { class: "modal-head" }, h("h3", {}, title), h("button", { class: "icon-btn", "aria-label": "关闭", onclick: () => void tryClose() }, icon("x"))),
70
70
  body,
71
71
  foot ?? null,
72
72
  ),
@@ -110,7 +110,7 @@ export function placePopover(pop, anchor) {
110
110
 
111
111
  /**
112
112
  * 确认弹窗(替代浏览器自带的 confirm),样式和重命名弹窗一致。
113
- * 回车确认、Esc / 点外面取消;resolve 成 true / false
113
+ * 回车确认,点击取消按钮取消;resolve 成 true / false
114
114
  */
115
115
  /** altText:给了就多一个按钮,点它返回 "alt"(确定返回 true,取消返回 false) */
116
116
  export function confirmDialog({ title, message, sub, confirmText = "确定", danger = false, altText }) {
@@ -125,10 +125,7 @@ export function confirmDialog({ title, message, sub, confirmText = "确定", dan
125
125
  resolve(v);
126
126
  };
127
127
  const onKey = (e) => {
128
- if (e.key === "Escape") {
129
- e.preventDefault();
130
- done(false);
131
- } else if (e.key === "Enter" && !e.isComposing) {
128
+ if (e.key === "Enter" && !e.isComposing) {
132
129
  e.preventDefault();
133
130
  done(true);
134
131
  }
@@ -137,7 +134,7 @@ export function confirmDialog({ title, message, sub, confirmText = "确定", dan
137
134
  cancel.onclick = () => done(false);
138
135
  const overlay = h(
139
136
  "div",
140
- { class: "overlay dialog-overlay", onclick: (e) => e.target === overlay && done(false) },
137
+ { class: "overlay dialog-overlay" },
141
138
  h(
142
139
  "div",
143
140
  { class: "dialog confirm-dialog" },
@@ -396,7 +396,7 @@ export async function changeCwd(pick) {
396
396
  await load(startRel);
397
397
  }
398
398
 
399
- /** 重命名:小弹窗,回车保存、Esc 取消,打开时全选原名 */
399
+ /** 重命名:小弹窗,回车保存、按钮取消,打开时全选原名 */
400
400
  export function renameConv(key = S.current) {
401
401
  const c = S.convs.get(key);
402
402
  if (!c) return;
@@ -424,10 +424,7 @@ export function renameConv(key = S.current) {
424
424
  }
425
425
  };
426
426
  const onKey = (e) => {
427
- if (e.key === "Escape") {
428
- e.preventDefault();
429
- close();
430
- } else if (e.key === "Enter" && !e.isComposing && document.activeElement === input) {
427
+ if (e.key === "Enter" && !e.isComposing && document.activeElement === input) {
431
428
  e.preventDefault();
432
429
  void submit();
433
430
  }
@@ -436,7 +433,7 @@ export function renameConv(key = S.current) {
436
433
  cancel.onclick = close;
437
434
  const overlay = h(
438
435
  "div",
439
- { class: "overlay dialog-overlay", onclick: (e) => e.target === overlay && close() },
436
+ { class: "overlay dialog-overlay" },
440
437
  h(
441
438
  "div",
442
439
  { class: "dialog" },
@@ -248,10 +248,6 @@ function editSidebar() {
248
248
  }
249
249
  return;
250
250
  }
251
- if (e.key !== "Escape") return;
252
- e.preventDefault();
253
- e.stopPropagation();
254
- close();
255
251
  };
256
252
  const done = h("button", {
257
253
  class: "btn primary",
@@ -240,8 +240,8 @@ function agentShort(id) {
240
240
  return id === "claude" ? "Claude" : id === "codex" ? "Codex" : id;
241
241
  }
242
242
 
243
- /** 侧栏里展开 / 收起的状态:哪些项目目录展开了、哪些分组折叠了、哪些主对话的分叉折叠了、目录的顺序(more 是老版本的,不再用) */
244
- export const sideState = { open: [], more: [], folded: [], forkFolded: [], order: [], ...JSON.parse(localStorage.getItem("aim.side") || "{}") };
243
+ /** 侧栏状态:展开的项目和机器人、折叠的分组和分叉、目录顺序(more 是老版本的,不再用) */
244
+ export const sideState = { open: [], botOpen: [], more: [], folded: [], forkFolded: [], order: [], ...JSON.parse(localStorage.getItem("aim.side") || "{}") };
245
245
 
246
246
  /**
247
247
  * 「项目」目录的顺序固定按 sideState.order,新消息不会把目录顶到前面。
@@ -334,7 +334,7 @@ const MORE_STEP = 10;
334
334
  // next:下一页的游标;null = 没有更多了;undefined = 这个目录还没拉过。
335
335
 
336
336
  /** full:老版本服务端一次给了全部,不用再拉 */
337
- const pages = { recent: { show: RECENT_LIMIT, next: null, loading: false }, dirs: new Map(), dirAt: new Map(), full: false };
337
+ const pages = { recent: { show: RECENT_LIMIT, next: null, loading: false }, dirs: new Map(), bots: new Map(), dirAt: new Map(), full: false };
338
338
 
339
339
  function dirState(dir) {
340
340
  let st = pages.dirs.get(dir);
@@ -342,6 +342,12 @@ function dirState(dir) {
342
342
  return st;
343
343
  }
344
344
 
345
+ function botState(id) {
346
+ let st = pages.bots.get(id);
347
+ if (!st) pages.bots.set(id, (st = { show: PROJECT_LIMIT, next: pages.full ? null : undefined, loading: false }));
348
+ return st;
349
+ }
350
+
345
351
  /** /api/bootstrap 的参数:按现在显示了多少条要(重连后整份换掉时,已经展开的不会缩回去) */
346
352
  export function bootstrapQuery() {
347
353
  const q = new URLSearchParams({ recent: String(pages.recent.show), open: JSON.stringify(sideState.open.map((d) => [d, dirState(d).show])) });
@@ -355,6 +361,11 @@ export function applyBootstrap(data) {
355
361
  S.sidebarNav = data.sidebarNav ?? null;
356
362
  S.convs = new Map(data.conversations.map((c) => [c.key, c]));
357
363
  pages.full = !data.sidebar;
364
+ // bootstrap 只带每个机器人最近的一条;展开的列表需要重新补齐。
365
+ for (const st of pages.bots.values()) {
366
+ st.next = pages.full ? null : undefined;
367
+ st.failed = false;
368
+ }
358
369
  pages.recent.next = data.sidebar?.recent.next ?? null;
359
370
  pages.dirAt = new Map((data.sidebar?.dirs ?? []).map((d) => [d.dir, d.at]));
360
371
  const fetched = new Map((data.sidebar?.dirs ?? []).filter((d) => "next" in d).map((d) => [d.dir, d.next]));
@@ -480,27 +491,70 @@ export function renderSidebar() {
480
491
  );
481
492
 
482
493
  const nodes = [];
483
- // 飞书机器人独立显示在文件夹后面,点击打开它最近活跃的聊天
494
+ // 飞书机器人和项目一样展开会话,独立显示在文件夹后面。
495
+ if (cur?.channel === "feishu" && cur.key !== autoOpenedFor) {
496
+ autoOpenedFor = cur.key;
497
+ if (!sideState.botOpen.includes(cur.channelId)) {
498
+ sideState.botOpen.push(cur.channelId);
499
+ saveSideState();
500
+ }
501
+ }
484
502
  const botRows = [];
485
503
  for (const bot of S.bots) {
486
504
  const convs = visible.filter((c) => c.channel === "feishu" && c.channelId === bot.id);
487
505
  if (bot.enabled === false && convs.length === 0) continue;
488
506
  const latest = convs[0];
489
- botRows.push({
490
- at: latest?.activeAt ?? 0,
491
- el: h(
507
+ const expanded = sideState.botOpen.includes(bot.id);
508
+ const rows = [h(
509
+ "div",
510
+ { class: "proj-row bot-row", "data-bot": bot.id },
511
+ h(
492
512
  "button",
493
513
  {
494
- class: `conv-item${!S.view && cur?.channel === "feishu" && cur.channelId === bot.id ? " active" : ""}`,
495
- "data-bot": bot.id,
496
- title: latest ? `飞书 · ${bot.name}\n${agentLabel(latest.agent)} · ${latest.cwd}` : `飞书 · ${bot.name}\n还没有会话`,
497
- onclick: () => (latest ? open(latest.key) : toast("这个机器人还没有会话,先在飞书里给它发条消息")),
514
+ class: "conv-item proj",
515
+ title: `飞书 · ${bot.name}`,
516
+ "aria-expanded": String(expanded),
517
+ onclick: () => toggleSide("botOpen", bot.id),
498
518
  },
499
519
  h("span", { class: "title" }, bot.name),
500
- status(convs.map((c) => c.key)),
501
- convExpertMark(latest),
502
- h("span", { class: "brand-icon feishu-mark", title: "飞书", html: ICON.feishu }),
520
+ caret(!expanded),
521
+ expanded ? null : status(convs.map((c) => c.key)),
522
+ ),
523
+ h(
524
+ "button",
525
+ {
526
+ class: "proj-new bot-new",
527
+ title: `使用 ${bot.name} 的专家和工作目录开新对话`,
528
+ "aria-label": `使用 ${bot.name} 的专家和工作目录开新对话`,
529
+ onclick: () => {
530
+ S.draftCwd = latest?.cwd && latest.cwd !== S.workspaceRoot ? latest.cwd : null;
531
+ S.draftCwdPicked = true;
532
+ const expert = latest?.expert?.id ?? latest?.agent ?? bot.agents?.[0];
533
+ if (expert) setDraftExpert(expert);
534
+ newDraft();
535
+ closeSide();
536
+ },
537
+ },
538
+ h("span", { class: "brand-icon feishu-mark", html: ICON.feishu, "aria-hidden": "true" }),
539
+ h("span", { class: "bot-plus", "aria-hidden": "true" }, icon("plus")),
503
540
  ),
541
+ )];
542
+ if (expanded) {
543
+ const st = botState(bot.id);
544
+ const load = (limit) => fetchPage(st, { scope: "bot", bot: bot.id, limit: String(limit) });
545
+ if (st.next === undefined && !st.loading && !st.failed) void load(st.show);
546
+ const forest = loadedPrefix(st, forkForest(convs));
547
+ for (const node of forest.slice(0, st.show)) {
548
+ rows.push(renderForkNode(node, (c, orphan, fold) => convRow(c, " sub", `${agentLabel(c.agent)} · ${c.cwd}`, orphan, fold)));
549
+ }
550
+ if (!convs.length && !st.loading && !st.failed) rows.push(h("div", { class: "conv-empty sub" }, "还没有会话"));
551
+ if (st.failed) rows.push(h("button", { class: "conv-more", onclick: () => { void load(st.show); renderSidebar(); } }, "加载失败,点击重试"));
552
+ const btn = moreButton(st, forest.length, PROJECT_LIMIT, load);
553
+ if (btn) rows.push(h("div", { class: "sub-more" }, btn));
554
+ }
555
+ botRows.push({
556
+ at: latest?.activeAt ?? 0,
557
+ rows,
504
558
  });
505
559
  }
506
560
 
@@ -636,7 +690,7 @@ export function renderSidebar() {
636
690
  if (btn) nodes.push(h("div", { class: "sub-more" }, btn));
637
691
  }
638
692
  }
639
- nodes.push(...botRows.sort((a, b) => b.at - a.at).map((r) => r.el));
693
+ nodes.push(...botRows.sort((a, b) => b.at - a.at).flatMap((r) => r.rows));
640
694
  if (!nodes.length) nodes.push(h("div", { class: "conv-empty" }, "还没有会话"));
641
695
  paintList(nodes, askKeys.size);
642
696
  }
@@ -546,7 +546,7 @@ async function continueInFeishu(key) {
546
546
  );
547
547
  }
548
548
 
549
- /** 飞书机器人的历史会话:这个机器人的所有聊天(侧栏只拿了最近的一条,这里去服务端拉全),按活跃时间排,点一下打开 */
549
+ /** 飞书机器人的历史会话:独立于侧栏分页拉取,按活跃时间排,点一下打开 */
550
550
  export async function openBotConversations(botId) {
551
551
  const bot = S.bots.find((b) => b.id === botId);
552
552
  const body = h("div", { class: "modal-body" }, h("span", { class: "spinner" }));