agent-loft 0.2.80 → 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.80",
3
+ "version": "0.2.81",
4
4
  "type": "module",
5
5
  "description": "多个 agent 的工作台:把本机 Claude Code / Codex 放到一处统一管理,用飞书和 Web 页面随时驱动——会话、审批、模型切换都共用",
6
6
  "keywords": [
@@ -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
+ }
@@ -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,