agent-loft 0.2.65 → 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.
@@ -20,6 +20,8 @@ const PERMS = [
20
20
  { id: "exec", label: "跑命令", hint: "执行命令,等于能改任何文件;需要授权时会弹卡" },
21
21
  ];
22
22
  const FILE_LEVELS = ["read", "edit", "exec"];
23
+ let refreshExpertsPage = () => {};
24
+ document.addEventListener("aim:experts", () => refreshExpertsPage());
23
25
 
24
26
  export async function expertsTab(panel) {
25
27
  const box = h("div", { class: "experts-page" }, h("span", { class: "spinner" }));
@@ -35,6 +37,7 @@ export async function expertsTab(panel) {
35
37
  if (!box.isConnected) return;
36
38
  render(box, data, load);
37
39
  };
40
+ refreshExpertsPage = () => { if (box.isConnected) void load(); };
38
41
  await load();
39
42
  }
40
43
 
@@ -48,7 +51,7 @@ function render(box, data, reload) {
48
51
  h(
49
52
  "p",
50
53
  { class: "skill-note" },
51
- "专家是一份配置:用哪个引擎、什么提示词、能做什么(联网 / 读文件 / 改文件 / 跑命令)、带哪些技能和 MCP、能把活派给哪些子智能体。新建对话、定时任务时选一个专家,对话从头到尾都是它。内置的 Claude Code、Codex 在「设置 → Agent」里选择默认技能和 MCP。",
54
+ "专家决定引擎、提示词和能力。共享给所有账号后,设定由创建者维护,每个人的记忆、技能和 MCP 仍各自独立;点「我的工具」选择自己要用的工具。内置的 Claude Code、Codex 在「设置 → Agent」里选择默认技能和 MCP。",
52
55
  ),
53
56
  h("div", { class: "skill-head-btns" }, add),
54
57
  ),
@@ -70,14 +73,15 @@ function render(box, data, reload) {
70
73
  }
71
74
 
72
75
  function expertCard(data, e, reload) {
76
+ const editable = e.editable !== false;
77
+ const open = () => editable ? openEditor(data, e, reload) : viewSharedExpert(e);
73
78
  const access = data.access.find((a) => a.id === e.access)?.label ?? e.access;
74
79
  const more = h("button", { class: "icon-btn", title: "更多" }, icon("more"));
75
80
  more.onclick = () =>
76
81
  showMenu(more, [
77
- { label: "编辑…", onclick: () => openEditor(data, e, reload) },
78
- { label: "复制一份…", onclick: () => openEditor(data, null, reload, { ...e, name: `${e.name} 副本` }) },
79
- "sep",
80
- { label: "删除", danger: true, onclick: () => removeExpert(e, reload) },
82
+ { label: editable ? "编辑…" : "查看设定…", onclick: open },
83
+ { label: "复制一份…", onclick: () => openEditor(data, null, reload, { ...e, shared: false, subagents: editable ? e.subagents : [], name: `${e.name} 副本` }) },
84
+ ...(editable ? ["sep", { label: "删除", danger: true, onclick: () => removeExpert(e, reload) }] : []),
81
85
  ]);
82
86
  const extras = [
83
87
  e.skills.length ? `${e.skills.length} 个技能` : null,
@@ -91,7 +95,9 @@ function expertCard(data, e, reload) {
91
95
  h(
92
96
  "div",
93
97
  { class: "task-top" },
94
- h("button", { class: "task-title skill-name", title: "编辑", onclick: () => openEditor(data, e, reload) }, expertIcon(e, "expert-card-icon"), e.name),
98
+ h("button", { class: "task-title skill-name", title: editable ? "编辑" : "查看设定", onclick: open }, expertIcon(e, "expert-card-icon"), e.name),
99
+ e.shared ? h("span", { class: "badge" }, editable ? "已共享" : "共享") : null,
100
+ e.shared ? h("button", { class: "btn", onclick: () => openTools(data, e, reload) }, "我的工具") : null,
95
101
  more,
96
102
  ),
97
103
  h("div", { class: "task-meta" }, h("span", {}, ENGINE_LABEL[e.engine]), h("span", {}, access), e.model ? h("span", {}, e.model) : null, extras.map((x) => h("span", {}, x))),
@@ -99,6 +105,40 @@ function expertCard(data, e, reload) {
99
105
  );
100
106
  }
101
107
 
108
+ function viewSharedExpert(e) {
109
+ const prompt = h("textarea", { rows: 12, readonly: true, "aria-label": "提示词" });
110
+ prompt.value = e.prompt;
111
+ modal({ title: e.name, wide: true, body: h("div", { class: "modal-body" },
112
+ h("p", { class: "muted" }, "这是共享专家,设定由创建者维护。你的记忆和工具独立,工具可在「我的工具」里配置。"),
113
+ field("说明", h("p", {}, e.description || "暂无说明")),
114
+ field("引擎", h("p", {}, ENGINE_LABEL[e.engine])),
115
+ field("提示词", prompt),
116
+ ) });
117
+ }
118
+
119
+ function openTools(data, e, reload) {
120
+ const skills = checkList(data.skills.map((s) => ({ id: s.id, label: s.name, hint: s.description })), e.skills, "还没有启用的技能(设置 → 技能)");
121
+ const machine = (data.machineMcp?.[e.engine] ?? []).map((name) => ({ id: `${data.machinePrefix}${name}`, label: `${name}(本机)` }));
122
+ const mcp = checkList([...data.mcp.map((s) => ({ id: s.id, label: s.name, hint: s.description })), ...machine], e.mcp, "还没有 MCP(设置 → MCP)");
123
+ const save = h("button", { class: "btn primary" }, "保存我的工具");
124
+ const close = modal({ title: `${e.name} · 我的工具`, body: h("div", { class: "modal-body" },
125
+ h("p", { class: "muted" }, "只影响你使用这个专家时加载的工具,网页和绑定账号后的飞书私聊共用。未选择时不加载技能或 MCP;记忆使用你自己的设置。子智能体的工具需在对应专家中单独配置。"),
126
+ field("我的技能", skills.el), field("我的 MCP", mcp.el),
127
+ ), foot: h("div", { class: "modal-foot" }, save) });
128
+ save.onclick = async () => {
129
+ save.disabled = true;
130
+ try {
131
+ await api(`/api/experts/${e.id}/tools`, { method: "PUT", body: { skills: skills.value(), mcp: mcp.value() } });
132
+ close();
133
+ toast("已保存,你的对话下一条消息起使用新的工具");
134
+ void reload();
135
+ } catch (err) {
136
+ save.disabled = false;
137
+ toast(err.message);
138
+ }
139
+ };
140
+ }
141
+
102
142
  async function removeExpert(e, reload) {
103
143
  const sure = await confirmDialog({
104
144
  title: `删除专家「${e.name}」?`,
@@ -170,6 +210,7 @@ function openEditor(data, e, reload, preset) {
170
210
  },
171
211
  });
172
212
  const memory = h("input", { type: "checkbox", checked: src.memory !== false });
213
+ const shared = h("input", { type: "checkbox", checked: src.shared === true });
173
214
  const welcome = h("input", { value: src.welcome ?? "", maxlength: "500", placeholder: "新对话页上的那句话,比如:想了解哪只股票?" });
174
215
  const quick = h("textarea", { rows: 4, placeholder: "一行一个,新对话页上点一下就填进输入框。可以写成「标题|提示词」,提示词里的 ___ 是要用户填的空" });
175
216
  quick.value = (src.quickPrompts ?? []).map((q) => (q.title && q.title !== q.prompt.slice(0, 20) ? `${q.title}|${q.prompt}` : q.prompt)).join("\n");
@@ -196,7 +237,7 @@ function openEditor(data, e, reload, preset) {
196
237
  const keepSubs = subs.value();
197
238
  // 子智能体只有 Claude:自己的 Claude 专家,不能是自己
198
239
  subs = checkList(
199
- data.experts.filter((x) => x.engine === "claude" && x.id !== e?.id).map((x) => ({ id: x.id, label: !x.avatar && x.icon ? `${x.icon} ${x.name}` : x.name, hint: x.description })),
240
+ data.experts.filter((x) => x.editable !== false && x.engine === "claude" && x.id !== e?.id).map((x) => ({ id: x.id, label: !x.avatar && x.icon ? `${x.icon} ${x.name}` : x.name, hint: x.description })),
200
241
  keepSubs,
201
242
  "还没有别的 Claude 专家可以当子智能体",
202
243
  );
@@ -218,15 +259,16 @@ function openEditor(data, e, reload, preset) {
218
259
  { class: "modal-body task-form expert-form" },
219
260
  h("div", { class: "row-fields avatar-row" }, field("头像", avatar.el), field("名字", name)),
220
261
  field("说明", desc),
262
+ field("共享", h("label", { class: "check-item" }, shared, h("span", {}, "共享给所有账号")), "其他账号可在网页、飞书私聊和定时任务中使用;只有你能修改设定。取消共享后,其他人的旧对话保留但不能继续调用。子智能体也需要先共享。"),
221
263
  h("div", { class: "row-fields" }, field("引擎", engine, e ? "建好后不能换" : null), field("模型", models.model), field("思考程度", models.effort)),
222
264
  field("提示词", prompt, "agent-loft 会在后面自动补上:这个专家能做什么、不能做什么,今天的日期,记忆"),
223
265
  baseField,
224
266
  field("权限", perms.el, "改文件包含读文件,跑命令包含改文件。什么都不勾就是只能聊天"),
225
267
  cwdField,
226
- field("技能", skills.el, "只给选中的技能;没选就不挂技能(省 token)"),
227
- field("MCP", mcpBox, "选中的 MCP 的工具直接可用(MCP 设了「调用前询问」的会弹授权)"),
268
+ field("我的技能", skills.el, "只影响你的工具选择;共享后其他账号单独选择自己的技能"),
269
+ field("我的 MCP", mcpBox, "只使用你的 MCP;共享后不会把你的 MCP 或凭据交给其他账号"),
228
270
  subField,
229
- field("记忆", h("label", { class: "check-item" }, memory, h("span", {}, "带上我的个人记忆(设置 → 记忆)"))),
271
+ field("记忆", h("label", { class: "check-item" }, memory, h("span", {}, "使用聊天者自己的个人记忆(需在设置 → 记忆开启)"))),
230
272
  field("欢迎语", welcome),
231
273
  field("快捷提问", quick),
232
274
  );
@@ -246,6 +288,7 @@ function openEditor(data, e, reload, preset) {
246
288
  });
247
289
  const payload = {
248
290
  name: name.value,
291
+ shared: shared.checked,
249
292
  ...avatar.payload(),
250
293
  description: desc.value,
251
294
  engine: engine.value,
@@ -9,7 +9,17 @@ import { field, markDirty, saveButton, saveConfig } from "./common.js";
9
9
  * 设置 → 飞书:机器人、谁能用(配对请求、已配对的人)、指令面板同步,都是飞书这一侧的事,放在一页。
10
10
  * 每个机器人一张表单各自保存;存了一个,其它机器人没保存的改动原样留着(表单按机器人缓存,不重建)。
11
11
  */
12
- export function feishuTab(cfg, page) {
12
+ export async function feishuTab(cfg, page) {
13
+ let shared;
14
+ try {
15
+ shared = (await api("/api/experts/brief")).experts.filter((e) => e.shared);
16
+ } catch (err) {
17
+ page.append(h("div", { class: "error-text" }, `无法加载共享专家:${err.message}`));
18
+ return;
19
+ }
20
+ const choices = [...S.agents.map((a) => ({ id: a.id, label: a.label, engine: a.id })), ...shared.map((e) => ({ id: e.id, label: `${e.name}(共享)`, engine: e.engine }))];
21
+ // 复选框各有自己的 label,外层使用分组,避免把第一项关联到整组说明。
22
+ const expertField = (content, hint) => h("div", { class: "field", role: "group", "aria-label": "可用专家" }, h("span", {}, "可用专家"), content, h("small", {}, hint));
13
23
  /** 已经存进配置的机器人(以服务端为准) + 手动添加、还没保存的 */
14
24
  let saved = structuredClone(cfg.feishu.bots);
15
25
  let drafts = [];
@@ -42,7 +52,7 @@ export function feishuTab(cfg, page) {
42
52
  "div",
43
53
  { class: "section" },
44
54
  h("h4", {}, "飞书机器人"),
45
- h("div", { class: "muted" }, "一个机器人可以对应一个 agent,也可以在会话里用 /agent 切换。扫码创建会自动建好飞书应用;Lark 国际版请用「手动添加」,填开发者后台里的 App ID 和 App Secret。"),
55
+ h("div", { class: "muted" }, "勾选这个机器人可用的内置或共享专家,并选择默认专家。共享专家在每个人绑定账号后的私聊中使用各自的记忆和工具。扫码创建会自动建好飞书应用;Lark 国际版请用「手动添加」。"),
46
56
  h(
47
57
  "div",
48
58
  { class: "row" },
@@ -79,11 +89,21 @@ export function feishuTab(cfg, page) {
79
89
  const allow = h("textarea", { rows: 2, placeholder: "ou_xxx,一行一个" });
80
90
  allow.value = b.allowFrom.join("\n");
81
91
  const enabled = h("input", { type: "checkbox", checked: b.enabled });
82
- const agentChecks = S.agents.map((a) => {
83
- const box = h("input", { type: "checkbox", checked: b.agents.includes(a.id), value: a.id });
84
- return { id: a.id, box, el: h("label", { class: "check" }, box, a.label) };
92
+ const selected = b.experts ?? b.agents;
93
+ const missing = selected.filter((id) => !choices.some((e) => e.id === id)).map((id) => ({ id, label: `${id}(已删除或未共享,请取消勾选)` }));
94
+ const expertChecks = [...choices, ...missing].map((e) => {
95
+ const box = h("input", { type: "checkbox", checked: selected.includes(e.id), value: e.id });
96
+ return { id: e.id, box, el: h("label", { class: "check" }, box, e.label) };
85
97
  });
86
- const def = h("select", {}, S.agents.map((a) => h("option", { value: a.id, selected: a.id === b.defaultAgent }, a.label)));
98
+ const def = h("select", { "aria-label": "默认专家" });
99
+ const syncDefault = () => {
100
+ const preferred = def.value || b.defaultExpert || b.defaultAgent;
101
+ const enabled = choices.filter((e) => expertChecks.some((c) => c.id === e.id && c.box.checked));
102
+ fill(def, enabled.map((e) => h("option", { value: e.id }, e.label)));
103
+ if (enabled.some((e) => e.id === preferred)) def.value = preferred;
104
+ };
105
+ for (const c of expertChecks) c.box.addEventListener("change", syncDefault);
106
+ syncDefault();
87
107
  const status = h("span", { class: "status-tag" }, b.enabled ? "…" : "未启用");
88
108
  if (!isDraft) statusTags.set(b.id, status);
89
109
  const collect = () => {
@@ -96,14 +116,16 @@ export function feishuTab(cfg, page) {
96
116
  domain: domain.value,
97
117
  allowFrom: allow.value.split(/[\s,]+/).filter(Boolean),
98
118
  enabled: enabled.checked,
99
- agents: agentChecks.filter((c) => c.box.checked).map((c) => c.id),
100
- defaultAgent: def.value,
119
+ experts: expertChecks.filter((c) => c.box.checked).map((c) => c.id),
120
+ defaultExpert: def.value,
121
+ agents: [...new Set(choices.filter((e) => expertChecks.some((c) => c.id === e.id && c.box.checked)).map((e) => e.engine))],
122
+ defaultAgent: choices.find((e) => e.id === def.value)?.engine ?? b.defaultAgent,
101
123
  };
102
124
  };
103
125
  const save = async () => {
104
126
  const v = collect();
105
- if (!v.agents.length) {
106
- toast("至少勾选一个 agent");
127
+ if (!v.experts.length) {
128
+ toast("至少勾选一个专家");
107
129
  return false;
108
130
  }
109
131
  // 只存这一个:其它机器人按服务端现在的样子原样带上,别的草稿不跟着存
@@ -125,8 +147,8 @@ export function feishuTab(cfg, page) {
125
147
  field("名称", name),
126
148
  h("div", { class: "row" }, h("div", { style: { flex: 1 } }, field("App ID", appId)), h("div", { style: { flex: 1 } }, field("App Secret", secret))),
127
149
  field("域名", domain),
128
- field("可用的 Agent", h("div", { class: "row" }, agentChecks.map((c) => c.el)), "勾一个 = 一个机器人对应一个 agent;勾多个可在会话里用 /agent 切换"),
129
- field("默认 Agent", def),
150
+ expertField(h("div", { class: "row" }, expertChecks.map((c) => c.el)), "只勾一个共享专家即可专用;无需再勾选底层 Agent。勾多个可用 /expert 切换。保存后按这里的名单限制可选专家"),
151
+ field("默认专家", def, "新聊天和绑定账号后使用;已有聊天在当前专家仍可用时继续使用原专家"),
130
152
  field("Owner 白名单(open_id)", allow, "陌生人发消息会拿到配对码,在下面「配对请求」里批准即可,不必手填"),
131
153
  h(
132
154
  "div",
@@ -174,22 +196,24 @@ export function feishuTab(cfg, page) {
174
196
 
175
197
  const registerBot = async () => {
176
198
  const nameInput = h("input", { value: "Agent 助手" });
177
- const checks = S.agents.filter((a) => a.enabled).map((a) => ({ id: a.id, box: h("input", { type: "checkbox", checked: true }), label: a.label }));
199
+ const checks = choices.map((e) => ({ id: e.id, box: h("input", { type: "checkbox", checked: false }), label: e.label }));
178
200
  const body = h(
179
201
  "div",
180
202
  { class: "modal-body" },
181
203
  h("div", { class: "muted" }, "用飞书扫码,会自动创建一个飞书应用(机器人),并把扫码的你设为 owner。"),
182
204
  field("机器人名称", nameInput),
183
- field("可用的 Agent", h("div", { class: "row" }, checks.map((c) => h("label", { class: "check" }, c.box, c.label)))),
205
+ expertField(h("div", { class: "row" }, checks.map((c) => h("label", { class: "check" }, c.box, c.label))), "可直接选择共享专家;选多个时默认使用第一个,创建后可以再调整默认专家"),
184
206
  );
185
207
  const go = h("button", { class: "btn primary" }, "生成二维码");
186
208
  const closeReg = modal({ title: "扫码创建飞书机器人", body, foot: h("div", { class: "modal-foot" }, go) });
187
209
  go.onclick = async () => {
210
+ const selected = checks.filter((c) => c.box.checked).map((c) => c.id);
211
+ if (!selected.length) return toast("至少勾选一个专家");
188
212
  go.disabled = true;
189
213
  try {
190
214
  const reg = await api("/api/feishu/register", {
191
215
  method: "POST",
192
- body: { name: nameInput.value, agents: checks.filter((c) => c.box.checked).map((c) => c.id) },
216
+ body: { name: nameInput.value, experts: selected, defaultExpert: selected[0] },
193
217
  });
194
218
  const state = h("div", { class: "muted", style: { textAlign: "center" } }, "等待扫码确认…");
195
219
  fill(
@@ -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" },
@@ -14,7 +14,7 @@ function usableEngines() {
14
14
  return (usable.length ? usable : enabled).map((a) => a.id);
15
15
  }
16
16
 
17
- /** 能选的专家:内置的在前,再是自己的(引擎能用的) */
17
+ /** 能选的专家:内置的在前,再是自己的和共享的(引擎能用的) */
18
18
  export function expertChoices() {
19
19
  const engines = usableEngines();
20
20
  return [
@@ -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" }));