agent-loft 0.2.79 → 0.2.81

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
@@ -96,7 +96,7 @@ Logo 就是这个意思:一大两小几颗星(多个 agent)站在同一张
96
96
  - 桌面:走 VNC 协议,网页里用 noVNC 显示,鼠标、键盘、剪贴板都能用,进来时不自动连、点「连接桌面」才连,工具栏上选画质:流畅 / 标准(默认)/ 高清由服务端把画面缩小到长边 1280 / 1920 / 2560、只把变了的地方压成 JPEG 发过来(macOS 屏幕共享只给无损的 ZRLE,5K 屏一整屏 30MB,原样转发隔着公网几秒一帧),原画是原样转发、只适合局域网;远程那边接了几块屏时可以只看其中一块(按系统里的显示器名称选,服务端只截那块再缩,比几块屏拼在一起缩小清楚得多;macOS 的各块屏位置要从屏幕共享发来的画面里学,第一次连上要几秒,原画下不能选);可以缩放到窗口或按原始大小看、全屏(手机上也能,iPhone 上是铺满页面)、「只看不控制」、发送 Ctrl+Alt+Del 之类的组合键。手机上有两种手势(右上角切换,「?」看说明):**触控板模式**(默认)屏幕上有个指针,单指滑动移动、轻点单击、双指轻点右键、长按后拖动是按住左键拖、双指滑动滚动;**触摸模式**点哪就点哪。两种模式都能双指捏合在本地放大画面(放大后小按钮也点得准,右下角「还原」),画面下面一排 Esc / Tab / Ctrl / Alt / Win / 方向键,Ctrl、Alt、Win 点一下会粘住,带给下一个按键或点击;键盘按钮弹出软键盘打字,中文输入法也能用。Linux 上 agent-loft 在有人连时用 x11vnc 共享当前的桌面(Xorg 会话;只听 127.0.0.1、随机端口、每次随机密码,需要 `sudo apt install x11vnc`),没人连着 30 分钟后停掉;macOS 上在 设置 → 远程控制 里改用「已有的 VNC 服务」,接系统自带的屏幕共享:填 VNC 密码,或者屏幕共享没开 VNC 密码时填 Mac 的用户名和登录密码(苹果认证,由服务端登录)。
97
97
  - 终端:新终端开在当前对话的工作目录里,可以开多个标签;`Ctrl+Shift+C` / `Ctrl+Shift+V` 复制粘贴。`` Ctrl+` `` 在对话下面拉出终端面板(高度可拖动),面板和远程控制里的是同一批终端。关掉页面、手机切到后台、断线都不结束 shell,重新打开时接着用、补上错过的输出,别的设备上也能接上;没有页面连着超过 30 分钟(设置里可改)才结束,点标签上的 × 立即结束。依赖可选的原生模块 `node-pty`:Linux 上安装时要现场编译(需要 `make`、`g++`、`python3`),没装好时终端用不了,其他功能照常。手机上单指上下滑翻看历史(在 less、vim 里是翻页),长按选中文字、接着拖动扩大选区,再点「复制」;终端下面多一排 Esc / Tab / Ctrl / Alt / 方向键 / Home / End / PgUp / PgDn / 粘贴。iOS 上软键盘弹出来时这排键会垫到键盘上面。
98
98
  - 管理员能用;成员要管理员在 设置 → 用户 里单独「开通远程控制」。终端、桌面在 设置 → 远程控制 里各有总开关。
99
- - **微信 ClawBot**:设置 → 账号 → 微信 →「扫码连接微信」,用手机微信扫码并确认(要求微信 8.0.70 以上,「设置 → 插件」里有 ClawBot;这个功能腾讯还在逐步放量)。每个人连自己的微信,这条对话归扫码的人,用他的记忆和工具,只认扫码的这个微信号;服务端主动连向腾讯,不需要公网地址。微信里发文字或语音(要微信能转成文字),不发过程,只显示「正在输入」,结束后发结果;授权和提问是一条文字,回复数字处理(`1` 允许一次、`0` 拒绝,含义固定),网页上也能处理。`/new`、`/stop`、`/model`、`/expert` 等命令都能用。
99
+ - **微信 ClawBot**:设置 → 账号 → 微信 →「扫码连接微信」,用手机微信扫码并确认(要求微信 8.0.70 以上,「设置 → 插件」里有 ClawBot;这个功能腾讯还在逐步放量)。每个人连自己的微信,这条对话归扫码的人,用他的记忆和工具,只认扫码的这个微信号;服务端主动连向腾讯,不需要公网地址。微信里发文字或语音(要微信能转成文字),不发过程,只显示「正在输入」,结束后发结果;授权和提问是一条文字,回复数字处理(`1` 允许一次、`0` 拒绝,含义固定),网页上也能处理。`/new`、`/stop`、`/model`、`/expert` 等命令都能用。连接后可在同一设置页的「微信使用的专家」中选择专家并点击「切换专家」,也能在首次发微信消息前选好;切换会开启新会话,和微信里的 `/expert` 共用同一份选择。
100
100
 
101
101
  微信的限制(官方没公布具体数字,以下来自社区实测,agent-loft 按此处理):每条入站消息之后约能发 10 条,所以长回复每次发 3 段,回「继续」接着发,额度用完时在网页上说明;约 24 小时没在微信里说话后微信会拒绝发送,定时任务的结果可能发不过去,这时改走网页提示和系统推送。接口受理了但没给 `message_id` 时手机可能没收到(微信可能在静默限制账号),设置页和对话里会提示。Web 上说的话回复留在 Web,不花微信的额度。暂不支持群聊和收发图片、文件。
102
102
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-loft",
3
- "version": "0.2.79",
3
+ "version": "0.2.81",
4
4
  "type": "module",
5
5
  "description": "多个 agent 的工作台:把本机 Claude Code / Codex 放到一处统一管理,用飞书和 Web 页面随时驱动——会话、审批、模型切换都共用",
6
6
  "keywords": [
@@ -193,7 +193,7 @@ export class ClaudeDriver implements AgentDriver {
193
193
  };
194
194
  /** 问了、还没对上回答的:tool_use id → 那条 question */
195
195
  const asked = new Map<string, HistoryMessage>();
196
- /** 任务清单:哪条回复里改过,就在那条上挂一份改完的(页面取最后一份显示进度) */
196
+ /** 任务清单:哪条回复里改过,就在那条上挂一份改完的(页面只恢复最后一轮的进度) */
197
197
  const todos = new TodoTracker();
198
198
  for (const msg of raw) {
199
199
  if (msg.parent_tool_use_id) continue;
@@ -42,7 +42,7 @@ import {
42
42
  type CurateSettings,
43
43
  } from "../../core/memory.js";
44
44
  import { createLinkCode, listLinks, unlink, unlinkUser } from "../../core/feishu-links.js";
45
- import { getWeixinAccount, removeWeixinAccount } from "../../core/weixin-accounts.js";
45
+ import { getWeixinAccount, removeWeixinAccount, weixinKey } from "../../core/weixin-accounts.js";
46
46
  import { purgeUserData } from "../../core/personal.js";
47
47
  import { countRecords, purgeHistory, readMeta, searchHistory, writeMeta } from "../../core/chat-history.js";
48
48
  import { curateNow, pendingCount } from "../../core/memory-curator.js";
@@ -52,6 +52,7 @@ import { agentAvailability, agentHealth, invalidateHealth } from "../../agents/h
52
52
  import { installCodex, upgrade, useInstalledCodex, versionInfo } from "../../core/upgrade.js";
53
53
  import { feishuBots } from "../feishu/index.js";
54
54
  import { weixinStatus } from "../weixin/index.js";
55
+ import { ensureWeixinConversation, weixinExpertChoices } from "../weixin/conversation.js";
55
56
  import { cancelWeixinLogin, startWeixinLogin, submitWeixinVerifyCode, weixinLoginStatus } from "../weixin/login.js";
56
57
  import { fromThisMachine, isLoopbackHost, lanAddresses, listening, rebind } from "./listen.js";
57
58
  import { beginRegistration, initRegistration, pollRegistration, qrSvg } from "../feishu/register.js";
@@ -538,12 +539,16 @@ function feishuLinksOf(userId: string) {
538
539
  function weixinAccountView(userId: string) {
539
540
  const account = getWeixinAccount(userId);
540
541
  if (!account) return { linked: false };
542
+ const { choices } = weixinExpertChoices(userId);
543
+ const conv = getConversation(weixinKey(userId));
541
544
  return {
542
545
  linked: true,
543
546
  wechatShort: maskOpenId(account.ilinkUserId),
544
547
  boundAt: account.boundAt,
545
548
  lastInboundAt: account.lastInboundAt,
546
549
  status: weixinStatus(userId) ?? { state: "stopped", since: account.boundAt },
550
+ expert: conv ? (conv.expert ?? conv.agent) : (choices[0]?.id ?? null),
551
+ experts: choices.map(({ id, label }) => ({ id, label })),
547
552
  };
548
553
  }
549
554
 
@@ -1425,6 +1430,19 @@ export async function handleApi(req: IncomingMessage, res: ServerResponse, url:
1425
1430
  sendJson(res, 200, weixinAccountView(user.id));
1426
1431
  return;
1427
1432
  }
1433
+ if (p === "/api/account/weixin" && method === "PATCH") {
1434
+ if (!getWeixinAccount(user.id)) throw new HttpError(409, "请先扫码连接微信");
1435
+ const body = await readJsonBody<{ expert?: unknown }>(req);
1436
+ const { choices } = weixinExpertChoices(user.id);
1437
+ if (typeof body.expert !== "string" || !choices.some((e) => e.id === body.expert)) throw new HttpError(400, "请选择一个可用的专家");
1438
+ const allowed = await ensureWeixinConversation(user.id);
1439
+ if (!allowed) throw new HttpError(409, "你现在没有可用的专家");
1440
+ const message = await hub.setExpert(weixinKey(user.id), body.expert, allowed);
1441
+ const conv = getConversation(weixinKey(user.id));
1442
+ if ((conv?.expert ?? conv?.agent) !== body.expert) throw new HttpError(409, message);
1443
+ sendJson(res, 200, { ...weixinAccountView(user.id), message });
1444
+ return;
1445
+ }
1428
1446
  if (p === "/api/account/weixin" && method === "DELETE") {
1429
1447
  removeWeixinAccount(user.id);
1430
1448
  sendJson(res, 200, weixinAccountView(user.id));
@@ -28,6 +28,7 @@ import {
28
28
  toWeixinText,
29
29
  } from "./format.js";
30
30
  import { weixinEvents } from "./events.js";
31
+ import { ensureWeixinConversation } from "./conversation.js";
31
32
 
32
33
  /** 每条入站消息之后能发的条数(社区实测,官方没有公布) */
33
34
  export const SEND_LIMIT = 10;
@@ -234,29 +235,6 @@ export class WeixinBot {
234
235
  });
235
236
  }
236
237
 
237
- /** 专家:新会话选第一个能用的,手上的专家不能用了就换掉 */
238
- private async ensureConversation(user: User): Promise<string[] | undefined> {
239
- const allowed = hub.enabledAgents().map((d) => d.id);
240
- const choices = hub.expertChoices(user.id, allowed);
241
- if (choices.length === 0) return undefined;
242
- const first = choices[0]!;
243
- const existed = getConversation(this.key);
244
- if (!existed) {
245
- hub.ensure({
246
- key: this.key,
247
- channel: "weixin",
248
- channelId: user.id,
249
- defaultAgent: first.engine,
250
- expert: first.id,
251
- owner: user.id,
252
- title: "微信",
253
- });
254
- } else if (!choices.some((e) => e.id === (existed.expert ?? existed.agent))) {
255
- await hub.setExpert(this.key, first.id, allowed);
256
- }
257
- return allowed;
258
- }
259
-
260
238
  private async handleInbound(msg: WeixinMessage): Promise<void> {
261
239
  const user = this.user;
262
240
  if (!user) return;
@@ -267,7 +245,7 @@ export class WeixinBot {
267
245
  }
268
246
  if (!text) return;
269
247
 
270
- const allowed = await this.ensureConversation(user);
248
+ const allowed = await ensureWeixinConversation(user.id);
271
249
  if (!allowed) {
272
250
  this.say("你现在没有可用的专家。所选专家可能已取消共享、删除,或引擎已停用。");
273
251
  return;
@@ -0,0 +1,32 @@
1
+ // 设置页和微信入站共用同一条会话、同一份专家选择。
2
+ import { hub } from "../../core/hub.js";
3
+ import { getConversation } from "../../core/store.js";
4
+ import { weixinKey } from "../../core/weixin-accounts.js";
5
+
6
+ export function weixinExpertChoices(userId: string) {
7
+ const allowed = hub.enabledAgents().map((d) => d.id);
8
+ return { allowed, choices: hub.expertChoices(userId, allowed) };
9
+ }
10
+
11
+ /** 新会话选第一个可用专家;原专家不可用时换掉。 */
12
+ export async function ensureWeixinConversation(userId: string): Promise<string[] | undefined> {
13
+ const { allowed, choices } = weixinExpertChoices(userId);
14
+ const first = choices[0];
15
+ if (!first) return undefined;
16
+ const key = weixinKey(userId);
17
+ const existed = getConversation(key);
18
+ if (!existed) {
19
+ hub.ensure({
20
+ key,
21
+ channel: "weixin",
22
+ channelId: userId,
23
+ defaultAgent: first.engine,
24
+ expert: first.id,
25
+ owner: userId,
26
+ title: "微信",
27
+ });
28
+ } else if (!choices.some((e) => e.id === (existed.expert ?? existed.agent))) {
29
+ await hub.setExpert(key, first.id, allowed);
30
+ }
31
+ return allowed;
32
+ }
@@ -256,7 +256,7 @@ button.conv-group:hover {
256
256
  display: grid;
257
257
  }
258
258
 
259
- /* 飞书分组的同一位置:平时显示飞书,悬停或键盘聚焦时显示新建加号。 */
259
+ /* IM 分组常驻渠道图标,桌面悬停或键盘聚焦时显示新建加号。 */
260
260
  .bot-row .conv-item.proj {
261
261
  padding-right: 36px;
262
262
  }
@@ -280,14 +280,16 @@ button.conv-group:hover {
280
280
  visibility: hidden;
281
281
  }
282
282
 
283
- .bot-row:hover .bot-new .feishu-mark,
284
- .bot-row:focus-within .bot-new .feishu-mark {
285
- visibility: hidden;
286
- }
283
+ @media (hover: hover) and (pointer: fine) {
284
+ .bot-row:hover .bot-new .feishu-mark,
285
+ .bot-row:focus-within .bot-new .feishu-mark {
286
+ visibility: hidden;
287
+ }
287
288
 
288
- .bot-row:hover .bot-new .bot-plus,
289
- .bot-row:focus-within .bot-new .bot-plus {
290
- visibility: visible;
289
+ .bot-row:hover .bot-new .bot-plus,
290
+ .bot-row:focus-within .bot-new .bot-plus {
291
+ visibility: visible;
292
+ }
291
293
  }
292
294
 
293
295
  /* 鼠标挪到右边的加号上时,整行的 hover 底色还留着 */
@@ -301,14 +303,6 @@ button.conv-group:hover {
301
303
  .proj-new {
302
304
  display: grid;
303
305
  }
304
-
305
- .bot-new .bot-plus {
306
- visibility: visible;
307
- }
308
-
309
- .bot-new .feishu-mark {
310
- visibility: hidden;
311
- }
312
306
  }
313
307
 
314
308
  .conv-item {
@@ -411,12 +405,6 @@ button.conv-group:hover {
411
405
  color: var(--fg-soft);
412
406
  }
413
407
 
414
- /* 有状态点时由状态点推到右侧,专家图标紧随其后 */
415
- .conv-item > .dot + .expert-mark,
416
- .conv-item > .conv-spin + .expert-mark {
417
- margin-left: 0;
418
- }
419
-
420
408
  .conv-item .task-mark,
421
409
  .conv-item .feishu-mark {
422
410
  flex-shrink: 0;
@@ -432,10 +420,9 @@ button.conv-group:hover {
432
420
  height: 14px;
433
421
  }
434
422
 
435
- .conv-item > .dot ~ .task-mark,
436
- .conv-item > .conv-spin ~ .task-mark,
437
- .conv-item > .dot ~ .feishu-mark,
438
- .conv-item > .conv-spin ~ .feishu-mark {
423
+ /* 尾部图标共用右侧空间,状态始终排在最后。 */
424
+ .conv-item > .task-mark ~ .dot,
425
+ .conv-item > .task-mark ~ .conv-spin {
439
426
  margin-left: 0;
440
427
  }
441
428
 
@@ -457,6 +444,11 @@ button.conv-group:hover {
457
444
  display: inline-grid;
458
445
  }
459
446
 
447
+ .conv-item:hover > .expert-mark ~ .dot,
448
+ .conv-item:hover > .expert-mark ~ .conv-spin {
449
+ margin-left: 0;
450
+ }
451
+
460
452
  .conv-item:hover .task-mark,
461
453
  .conv-item:hover .expert-mark ~ .feishu-mark {
462
454
  display: none;
@@ -66,6 +66,27 @@ export function weixinLinkSection() {
66
66
  ].join(" · ");
67
67
  rows.push(h("div", { class: "list-item" }, h("div", { class: "grow" }, h("div", { class: "t" }, state), h("div", { class: "s" }, facts)), rm));
68
68
  if (DELIVERY_TEXT[data.status.delivery]) rows.push(h("div", { class: "error-text" }, DELIVERY_TEXT[data.status.delivery]));
69
+ const choices = data.experts;
70
+ const currentAvailable = choices.some((e) => e.id === data.expert);
71
+ const expert = h("select", { disabled: !choices.length, "aria-label": "微信专家", style: { flex: "1", minWidth: "0" } },
72
+ !currentAvailable ? h("option", { value: "", selected: true, disabled: true }, choices.length ? "当前专家已不可用,请重新选择" : "没有可用的专家") : null,
73
+ choices.map((e) => h("option", { value: e.id, selected: e.id === data.expert }, e.label)));
74
+ const change = h("button", { class: "btn", disabled: true }, "切换专家");
75
+ expert.onchange = () => { change.disabled = !expert.value || expert.value === data.expert; };
76
+ change.onclick = async () => {
77
+ change.disabled = true;
78
+ expert.disabled = true;
79
+ try {
80
+ const result = await api("/api/account/weixin", { method: "PATCH", body: { expert: expert.value } });
81
+ toast(result.message);
82
+ await load();
83
+ } catch (err) {
84
+ toast(err.message);
85
+ expert.disabled = !choices.length;
86
+ change.disabled = !expert.value || expert.value === data.expert;
87
+ }
88
+ };
89
+ rows.push(field("微信使用的专家", h("div", { class: "row" }, expert, change), "切换会结束当前会话并开启新会话,之后的微信消息使用所选专家。也可以在微信里发 /expert 切换。"));
69
90
  }
70
91
  fill(
71
92
  box,
@@ -214,13 +214,17 @@ export async function openConversation(key) {
214
214
  // 历史一次性加进来,最后再统一排版,免得每加一条就强制排版一次
215
215
  bulk = true;
216
216
  try {
217
+ let todos = null;
217
218
  for (const m of data.messages) {
219
+ // 面板只属于最后一轮;提问卡切开的多段回复仍算同一轮。
220
+ if (m.role === "user") todos = null;
221
+ else if (m.todos) todos = m.todos;
218
222
  if (m.role === "user") addItem({ type: "user", text: m.text, files: m.attachments ?? [], origin: null, anchor: m.anchor });
219
223
  else if (m.role === "question") addItem({ type: "ix", id: m.question.id, ix: historyQuestion(key, m) });
220
224
  else addItem({ type: "ai", steps: m.steps ?? [], committed: m.text, partial: "", done: true, footer: m.footer, at: m.ts, anchor: m.anchor, segment: m.segment });
221
225
  }
222
- // 任务清单:最后改过的那一份(进行中这一轮又改了的话,下面重放 todos 事件时换成新的)
223
- setTodos(data.messages.findLast((m) => m.todos)?.todos ?? null);
226
+ // 进行中这一轮的清单由下面重放 todos 事件恢复。
227
+ setTodos(todos);
224
228
  S.seq.set(key, 0);
225
229
  // 进行中这一轮弹过的卡(含已处理的):重放到 ix 事件时放回原位
226
230
  replayCards = new Map((data.interactions ?? []).map((ix) => [ix.id, ix]));
@@ -799,7 +803,10 @@ export function applyEvent(env) {
799
803
  S.items = S.items.filter((i) => i !== S.turnAi);
800
804
  S.turnAi = null;
801
805
  }
802
- if (!queued && (!S.turnAi || S.turnAi.done)) turnStartAt = env.ts;
806
+ if (!queued && (!S.turnAi || S.turnAi.done)) {
807
+ setTodos(null);
808
+ turnStartAt = env.ts;
809
+ }
803
810
  const it = addItem({ type: "user", text: ev.text, files: ev.files ?? ev.attachments, origin: ev.origin, id: ev.id, queued });
804
811
  // 这个页面刚发的:普通消息顶到最上面,排队消息等轮到它时再定位。
805
812
  if (S.pinNext && ev.origin?.channel === "web") {
@@ -834,11 +841,16 @@ export function applyEvent(env) {
834
841
  }
835
842
  // 轮到它了(上一轮刚出结果):挂上「思考中」占位,用时从现在算。被当成提问的回答时那一轮还在跑,不用挂
836
843
  if (ev.state === "started" && (!S.turnAi || S.turnAi.done)) {
844
+ setTodos(null);
837
845
  turnStartAt = env.ts;
838
846
  currentAi(env.ts);
839
847
  }
840
848
  return;
841
849
  }
850
+ case "turn_start":
851
+ // 包括没有新用户消息、由后台任务触发的轮次。
852
+ setTodos(null);
853
+ return;
842
854
  case "step": {
843
855
  const ai = currentAi(env.ts);
844
856
  ai.steps.push(ev.text);
@@ -539,9 +539,9 @@ export function renderSidebar() {
539
539
  orphan ? h("span", { class: "brand-icon lead fork-mark", html: ICON.fork }) : null,
540
540
  h("span", { class: "title" }, convTitle(c)),
541
541
  fold ? caret(fold.folded, fold.toggle) : null,
542
- status(fold?.folded ? fold.keys : [c.key]),
543
542
  convExpertMark(c),
544
543
  c.taskId ? h("span", { class: "brand-icon task-mark", title: "定时任务的对话", html: ICON.clock }) : null,
544
+ status(fold?.folded ? fold.keys : [c.key]),
545
545
  );
546
546
 
547
547
  // 飞书和项目共用排序,展开后的会话跟随所属分组。
@@ -10,7 +10,7 @@ let open = localStorage.getItem("aim.todosOpen") !== "0";
10
10
  /** 当前这份清单点过 ×:清单再变才重新出来 */
11
11
  let dismissed = false;
12
12
 
13
- /** 换了一份清单(null = 清空:换会话、开新对话) */
13
+ /** 换了一份清单(null = 清空:换会话、开始新一轮) */
14
14
  export function setTodos(list) {
15
15
  S.todos = list?.length ? list : null;
16
16
  dismissed = false;