dsh-cyber-im-avatar 0.8.0 → 0.9.0
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 +50 -28
- package/lib/app.js +97 -9
- package/lib/client.js +849 -375
- package/lib/im.js +418 -33
- package/lib/index.js +63 -4
- package/lib/media.js +182 -0
- package/lib/poller.js +218 -49
- package/lib/profiles.js +4 -9
- package/lib/skill-install.js +49 -4
- package/lib/state.js +91 -18
- package/lib/turns.js +414 -77
- package/package.json +1 -1
- package/skill/SKILL.md +172 -148
- package/skill/references/dingtalk.md +32 -5
- package/skill/references/feishu.md +15 -0
- package/skill/references/troubleshooting.md +30 -1
- package/skill/references/wecom.md +4 -1
- package/skill/scripts/bootstrap.py +121 -1
- package/skill/scripts/doctor.py +3 -1
- package/skill/scripts/listen_core.py +33 -7
- package/web/panel.js +849 -375
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# dsh-cyber-im-avatar · IM 分身壳
|
|
2
2
|
|
|
3
3
|
把仓库根目录那套 skill(`SKILL.md` + `scripts/`)做成 DeepSeek Harness 里的常驻壳:
|
|
4
|
-
|
|
4
|
+
侧边栏一个席位,点开是收件箱、每日关注、分身实例、服务对象档案与手动发送。
|
|
5
5
|
|
|
6
6
|
**分工(spec 0004):插件只当壳,skill 是唯一的脑子。**
|
|
7
7
|
|
|
@@ -49,7 +49,9 @@ dsh plugin --profile web add ~/cyber-im-avatar/dsh-plugin
|
|
|
49
49
|
https://raw.githubusercontent.com/buger-gif/cyber-im-avatar/main/dsh-plugin/market/index.json
|
|
50
50
|
```
|
|
51
51
|
|
|
52
|
-
前置:`lark-cli` / `wecom-cli`
|
|
52
|
+
前置:`lark-cli` / `wecom-cli` 已安装并登录;要用钉钉再装 `dws`(`npm i -g dingtalk-workspace-cli`)。
|
|
53
|
+
钉钉默认不启用:在面板「体检」页点钉钉卡片的「启用」,或加入一个钉钉会话值守,才会开始轮询。
|
|
54
|
+
**skill 不用单独装**:插件首次启动会把
|
|
53
55
|
`cyber-im-avatar` 装到 `~/.agents/skills/cyber-im-avatar/`(npm 包自带副本;本地
|
|
54
56
|
link 安装读仓库根目录)。已经手装过同一份的不会被覆盖,只打一行提示。
|
|
55
57
|
|
|
@@ -66,11 +68,24 @@ link 安装读仓库根目录)。已经手装过同一份的不会被覆盖,
|
|
|
66
68
|
## 命中 → 唤醒 → 同会话续跑
|
|
67
69
|
|
|
68
70
|
值守会话来了新消息(私聊消息 / 群 @我),插件在宿主里拿**绑定的 DSH 会话**跑一轮
|
|
69
|
-
live turn
|
|
71
|
+
live turn。每次唤醒的载荷都**只追加本次新消息**:
|
|
70
72
|
|
|
71
|
-
1.
|
|
72
|
-
|
|
73
|
-
|
|
73
|
+
1. 新会话首轮首行 `/cyber-im-avatar` —— DSH 的 user invocation,直接把 skill 正文注入
|
|
74
|
+
这一步(闭环、平台差异、铁律、故障自愈都在 skill 里,prompt 不再抄);同一轮另带
|
|
75
|
+
平台/对象、chat_id、运行形态、画像文件路径与本次新消息;
|
|
76
|
+
2. 已有会话的后续唤醒**只发本次新消息行**,不再重复平台、chat_id、运行形态、画像路径
|
|
77
|
+
或媒体说明——这些已经在同一 session 的历史里。
|
|
78
|
+
|
|
79
|
+
插件不注入画像正文、不解析 agent 回复、不代写画像;agent 按首轮载荷里的路径自己读、自己改。
|
|
80
|
+
换会话或重置会话会重新带 `/cyber-im-avatar` 入口。进程被杀后 `state.json` 的
|
|
81
|
+
`prompt_session` 与 `recent` 还在,下一轮继续追加 pending/新消息,不重建完整载荷。
|
|
82
|
+
|
|
83
|
+
**富媒体在唤醒时取回**:只对本批待回消息下载,不动历史。图片用 DSH
|
|
84
|
+
`attachments.admitPromptContent()` 变成 image block,模型直接可见;文件/语音/视频
|
|
85
|
+
落 `~/.im-standin/media/` 并在 prompt 给本地路径;sticker 只标 `[表情]`。卡片、合并
|
|
86
|
+
转发、位置、名片、系统消息等未适配类型,以及下载失败的消息,才在 prompt 标“可用 CLI 取”。
|
|
87
|
+
单批最多 4 张图 / 合计 10MB、单条 20 秒;模型不支持图片或附件服务缺失时降级为
|
|
88
|
+
文本 + 本地路径,不阻断 turn。
|
|
74
89
|
|
|
75
90
|
agent 在这一轮里自己用 `lark-cli` 拉上下文、去绑定工作区核实事实(只读)、
|
|
76
91
|
起草并发送或等你在会话里确认——**它有多少工具就用多少,插件不封顶**。
|
|
@@ -87,7 +102,7 @@ agent 在这一轮里自己用 `lark-cli` 拉上下文、去绑定工作区核
|
|
|
87
102
|
- **并发安全**:就是宿主里的同一个 agent,DSH UI 打开它不再抢 `session.lock`;
|
|
88
103
|
另一个 DSH 宿主持有写锁时才报 `session_locked_other_host`。
|
|
89
104
|
- **失败重喊**:turn 失败/超时后,积压还在就下一轮再喊;不自动连环重试。
|
|
90
|
-
-
|
|
105
|
+
- **重开会话**:实例卡片或会话详情点「重开会话」→ 打断在飞 turn、解绑当前会话;
|
|
91
106
|
下次命中开新会话。旧会话保留在侧边栏,只是不再续聊。**这是唯一的换会话入口。**
|
|
92
107
|
|
|
93
108
|
单轮上限默认 600 秒(`dsh.timeout`);有打断机制后,超时只剩防呆。
|
|
@@ -115,7 +130,7 @@ agent 在这一轮里自己用 `lark-cli` 拉上下文、去绑定工作区核
|
|
|
115
130
|
| 建 | 首个命中时 `create({workspaceId|cwd})`,DSH 自动把它归属到工作区 |
|
|
116
131
|
| 续 | 永久复用;历史与工具调用都落在同一个 `session-…` 里 |
|
|
117
132
|
| 断 | 新消息到达时 `agent.cancel` 在飞 turn,同 session 重起 |
|
|
118
|
-
| 换 |
|
|
133
|
+
| 换 | 只有用户点「重开会话」才换;旧会话留在侧边栏 |
|
|
119
134
|
|
|
120
135
|
实例卡片显示绑定会话、累计轮数、最近一次 turn 是否成功。累计轮数超过 50 只提示
|
|
121
136
|
「可新建」,不自动清理——上下文越长每轮 token 越贵,怎么做由你决定。
|
|
@@ -129,11 +144,14 @@ agent 在这一轮里自己用 `lark-cli` 拉上下文、去绑定工作区核
|
|
|
129
144
|
|
|
130
145
|
| 路径 | 什么时候发生 | 拉什么 |
|
|
131
146
|
| --- | --- | --- |
|
|
132
|
-
|
|
|
133
|
-
|
|
|
134
|
-
|
|
|
147
|
+
| 值守(快车道) | 默认每 **60 秒**(`poll.fast_sec`,0 = 关) | 值守中的私聊,以及你逐个勾了「定时检测 @我」的群 |
|
|
148
|
+
| 发现(慢车道) | 默认每 **10 分钟**(可调,**下限 10 分钟**,上限 240) | `whoami` + 刷会话列表(发现新会话),再补拉一轮候选 |
|
|
149
|
+
| 按需 | 点开某个会话时 | 在线拉 30 条;**群聊平时完全不进快车道**,只有勾了才进 |
|
|
150
|
+
| 手动 | 顶部「同步」、会话里的「拉一次」、「设置 → 立即拉一轮」 | 不受间隔约束;同一会话 20 秒冷却,连点不会重复打接口 |
|
|
135
151
|
|
|
136
152
|
面板通知每 **60 秒**刷新一次(角标 / 收件箱 / 处理中状态),和拉取节奏是两件事。
|
|
153
|
+
刷新不会吞掉正在输入的内容:搜索、企微手动加入、详情发送框与设置页数字框都有内存草稿;
|
|
154
|
+
接口失败时保留上一份数据并给「重试」,屏蔽 / 清理待回 / 运行中移出会先确认。
|
|
137
155
|
|
|
138
156
|
为什么要给群单独一套规则:群消息量远大于私聊,绝大多数与你无关。真做群值守时,
|
|
139
157
|
在那个群卡片上勾「定时检测 @我」,它才按上面的间隔轮询;不勾就只在点开时拉一次。
|
|
@@ -175,19 +193,20 @@ agent 在这一轮里自己用 `lark-cli` 拉上下文、去绑定工作区核
|
|
|
175
193
|
| 值守配置 | 保留;取消屏蔽后照常恢复(不补历史) |
|
|
176
194
|
|
|
177
195
|
入口:收件箱每行右侧的小铃铛、会话详情头部的「屏蔽」、分身页卡片上的「屏蔽」;
|
|
178
|
-
|
|
196
|
+
要放回来就去「设置 → 值守范围 → 已屏蔽的会话」。
|
|
179
197
|
|
|
180
198
|
## 用
|
|
181
199
|
|
|
182
|
-
点侧边栏「IM
|
|
200
|
+
点侧边栏「IM 值守」(带未读红点徽章),面板停靠在右侧栏,六个页签:
|
|
183
201
|
|
|
184
202
|
| 页签 | 内容 |
|
|
185
203
|
| --- | --- |
|
|
186
|
-
| 收件箱 | 待回 / 未读 / @我 / 私聊 /
|
|
187
|
-
|
|
|
204
|
+
| 收件箱 | 待回 / 未读 / @我 / 私聊 / 全部;**按会话聚合**,点一行进详情 |
|
|
205
|
+
| 关注 | agent 写的每日摘要 `~/.im-standin/digest/YYYY-MM-DD.md` 原文;可切日期,超一天没更新会提示 |
|
|
206
|
+
| 分身 | 值守中的实例:工作区、DSH 会话、轮数、处理中状态、**去会话**、重开会话、屏蔽;上面是搜人/搜群与手动加入 |
|
|
188
207
|
| 服务对象 | 每个对象一份画像文件:直接读、直接改;agent 起草前只读这一份,不展示历史消息 |
|
|
189
208
|
| 体检 | 轮询节奏与范围、授权状态、DSH 运行时、skill 路径、最近错误 |
|
|
190
|
-
| 设置 |
|
|
209
|
+
| 设置 | 值守节奏(值守秒数 + 发现分钟 + 私聊取前 N 个 + 立即拉一轮)、值守范围 |
|
|
191
210
|
|
|
192
211
|
**去会话**:实例卡与会话详情头部的「去会话」直接调 DSH 客户端的
|
|
193
212
|
`uiWorkspace.openSession(sessionId)`(侧边栏点会话用的同一条路),把主界面切到
|
|
@@ -196,7 +215,7 @@ agent 在这一轮里自己用 `lark-cli` 拉上下文、去绑定工作区核
|
|
|
196
215
|
老版本 DSH 没有这个服务时,退回复制会话 id,不假装跳成功。
|
|
197
216
|
|
|
198
217
|
会话详情里:画像摘要 → 消息气泡 → **手动输入发送** / 忽略。头部可换工作区、
|
|
199
|
-
|
|
218
|
+
开关值守、重开会话、拉一次、屏蔽;有待回且 agent 空闲时多一个 **现在处理**,
|
|
200
219
|
不用等下一条新消息就能让它处理积压(只取最新 10 条)。agent 回复会由下一轮
|
|
201
220
|
拉取以「我」的消息出现,不需要面板再起草。
|
|
202
221
|
|
|
@@ -254,24 +273,27 @@ DSH 把主题解析结果写在 `body[data-ds-dark-theme]` 上(固定深色主
|
|
|
254
273
|
|
|
255
274
|
## 服务对象画像
|
|
256
275
|
|
|
257
|
-
`lib/profiles.js` 为每个对象维护一份
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
在 0.8.x 已迁入画像文件;0.8.0 的迁移脚本保留 `profiles/` 原样不动。
|
|
276
|
+
`lib/profiles.js` 为每个对象维护一份 `~/.im-standin/profiles/<platform>/<chat_id>.md`,
|
|
277
|
+
面板与 agent 读写同一份;agent 起草前只读当前对象这一份,每轮把长期有效的新事实
|
|
278
|
+
增量合并回去。`env.json` 只读,目标索引不再写回它,也不保存画像正文。老版本 `profile`
|
|
279
|
+
笔记在 0.8.x 已迁入画像文件;0.8.0 的迁移脚本保留 `profiles/` 原样不动。
|
|
262
280
|
|
|
263
281
|
- 面板「服务对象」页可以浏览和编辑整份画像;不展示逐条历史消息。
|
|
264
|
-
- 壳内 agent
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
282
|
+
- 壳内 agent 用唤醒载荷给的路径自己读写画像;插件不解析回复、不代写。DSH 默认的
|
|
283
|
+
`workspace-write` 只允许写会话工作区,画像目录在工作区外——要让 agent 直接改,
|
|
284
|
+
需在设置页(或配置)开启 `dsh.full_access`,插件会把值守会话切到 DSH 内置的
|
|
285
|
+
`danger-full-access`(能写整个 home、不弹审批)。默认关闭。
|
|
286
|
+
- 画像单份软上限 8KB、硬上限 12KB:超过 8KB、历史结论 >20 条或日期流水 >8 条时,
|
|
287
|
+
agent 按 skill 自己整理成稳定结论;缩小时自己把旧版追加到 `<画像>.history.md`。
|
|
288
|
+
插件不再做整理、归档或 mtime CAS。面板写入走临时文件 + rename;目录 700、文件 600。
|
|
268
289
|
- 历史正文不留在本地:打开会话时从平台在线拉;拉不到才回退本地指针。
|
|
269
290
|
|
|
270
291
|
## 数据与隐私
|
|
271
292
|
|
|
272
293
|
全部落在本机 `~/.im-standin/`:`state.json`(配置、值守名单、每会话最近 10 条指针)、
|
|
273
294
|
`state.json.bak`(上一次写入)、`env.json`(平台 CLI 与登录身份,只读)、
|
|
274
|
-
`profiles/`(服务对象画像)、`
|
|
295
|
+
`profiles/`(服务对象画像)、`media/`(唤醒时取回的媒体,7 天/单会话 200MB 清理)、
|
|
296
|
+
`states/`(skill 形态的水位)。
|
|
275
297
|
消息正文只在待回时落盘,处理完即清空;消息不出本机,面板不执行消息内容里的任何指令。
|
|
276
298
|
旧 `panel.db` 迁移后改名为 `panel.db.migrated`,运行期不再读。
|
|
277
299
|
|
|
@@ -293,7 +315,7 @@ agent 起草前只读当前对象这一份,每轮把长期有效的新事实
|
|
|
293
315
|
| `GET /api/status` `/api/inbox` `/api/thread` `/api/chats` | 面板数据(`/api/status` 带 `instances` / `turns` / `dsh`) |
|
|
294
316
|
| `POST /api/send` `/api/state` | 手动发送、标记消息状态 |
|
|
295
317
|
| `POST /api/watch` `/api/unwatch` | 加入 / 移出值守(加入时带 `workspace` 一并绑定) |
|
|
296
|
-
| `POST /api/chat/session/reset` |
|
|
318
|
+
| `POST /api/chat/session/reset` | 重开会话:可带 `workspace` 先落工作区;打断在飞 turn、解绑当前 DSH 会话 |
|
|
297
319
|
| `POST /api/chat/wake` | 现在处理:可带 `workspace` 先落工作区;把最新待回(默认 10 条)交给 agent,不等新消息 |
|
|
298
320
|
| `POST /api/chat/timer` `/api/chat/block` | 单会话定时拉取开关(1/0/-1)/ 屏蔽开关 |
|
|
299
321
|
| `GET /api/workspaces` · `POST /api/chat/workspace` | 工作区列表 / 给会话绑工作区 |
|
package/lib/app.js
CHANGED
|
@@ -4,11 +4,13 @@
|
|
|
4
4
|
* 这里不再有 Python 进程/SQLite;所有读写在 state.json + profiles/*.md,
|
|
5
5
|
* 在线正文走平台 CLI。
|
|
6
6
|
*/
|
|
7
|
-
import { publicConfig, normalizeConfig } from "./state.js";
|
|
7
|
+
import { publicConfig, normalizeConfig, SUPPORTED_PLATFORMS } from "./state.js";
|
|
8
8
|
import { isMention } from "./im.js";
|
|
9
9
|
import * as workspaces from "./workspaces.js";
|
|
10
10
|
import * as sessions from "./sessions.js";
|
|
11
11
|
import { excerpt } from "./profiles.js";
|
|
12
|
+
import fs from "node:fs";
|
|
13
|
+
import path from "node:path";
|
|
12
14
|
|
|
13
15
|
export const ROUTES = {
|
|
14
16
|
"/api/health": "health",
|
|
@@ -34,10 +36,12 @@ export const ROUTES = {
|
|
|
34
36
|
"/api/chat/workspace": "chatWorkspace",
|
|
35
37
|
"/api/chat/session": "chatSession",
|
|
36
38
|
"/api/logs": "logs",
|
|
39
|
+
"/api/digest": "digest",
|
|
37
40
|
};
|
|
38
41
|
|
|
39
42
|
export const POST_ROUTES = {
|
|
40
43
|
"/api/config": "setConfig",
|
|
44
|
+
"/api/platforms": "setPlatform",
|
|
41
45
|
"/api/targets/profile": "targetProfile",
|
|
42
46
|
"/api/chat/session/reset": "chatSessionReset",
|
|
43
47
|
"/api/chat/wake": "chatWake",
|
|
@@ -132,6 +136,14 @@ export class App {
|
|
|
132
136
|
return this.state.getChat(platform, chatId);
|
|
133
137
|
}
|
|
134
138
|
|
|
139
|
+
supported(platform) {
|
|
140
|
+
return SUPPORTED_PLATFORMS.includes(String(platform || ""));
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
unsupported(platform) {
|
|
144
|
+
return { ok: false, reason: `插件壳不支持 ${platform || "该平台"}(独立 skill 形态可用)` };
|
|
145
|
+
}
|
|
146
|
+
|
|
135
147
|
async applyWorkspace(platform, chatId, raw) {
|
|
136
148
|
const value = String(raw || "").trim();
|
|
137
149
|
let ws = "";
|
|
@@ -205,17 +217,20 @@ export class App {
|
|
|
205
217
|
if (!platform || !chatId) return { error: "platform 和 chat_id 必填" };
|
|
206
218
|
const chat = this.state.getChat(platform, chatId) || {};
|
|
207
219
|
const blocked = !!chat.blocked;
|
|
220
|
+
const canFetch = !blocked && this.supported(platform);
|
|
208
221
|
let polled = null;
|
|
209
222
|
let items = [];
|
|
210
223
|
let online = false;
|
|
211
224
|
let onlineDone = false;
|
|
212
225
|
let offline = false;
|
|
213
|
-
let error = ""
|
|
226
|
+
let error = this.supported(platform) ? "" : `插件壳不支持 ${platform}(独立 skill 形态可用)`;
|
|
227
|
+
let skipped = "";
|
|
214
228
|
|
|
215
|
-
if (fetch &&
|
|
229
|
+
if (fetch && canFetch) {
|
|
216
230
|
try {
|
|
231
|
+
// 点开只读:补拉/分类,但绝不在这里起 turn;显式唤醒走 POST /api/chat/wake。
|
|
217
232
|
polled = await this.poller.pollChat(platform, chatId, {
|
|
218
|
-
name: chat.name, kind: chat.kind, limit,
|
|
233
|
+
name: chat.name, kind: chat.kind, limit, wake: false,
|
|
219
234
|
});
|
|
220
235
|
if (polled.fetched) {
|
|
221
236
|
online = true;
|
|
@@ -223,6 +238,8 @@ export class App {
|
|
|
223
238
|
items = polled.items || [];
|
|
224
239
|
} else if (polled.error) {
|
|
225
240
|
error = polled.error;
|
|
241
|
+
} else if (polled.skipped) {
|
|
242
|
+
skipped = polled.skipped;
|
|
226
243
|
}
|
|
227
244
|
} catch (e) {
|
|
228
245
|
polled = { ok: false, error: `${e?.name || "Error"}: ${e?.message || e}` };
|
|
@@ -230,7 +247,8 @@ export class App {
|
|
|
230
247
|
}
|
|
231
248
|
}
|
|
232
249
|
|
|
233
|
-
|
|
250
|
+
// 冷却中直接用本地指针:不再回退 fetchThread 打第二次 CLI。
|
|
251
|
+
if (!onlineDone && canFetch && !skipped) {
|
|
234
252
|
const r = await this.poller.fetchThread(platform, chatId, limit);
|
|
235
253
|
if (r.ok) {
|
|
236
254
|
items = r.items || [];
|
|
@@ -244,7 +262,7 @@ export class App {
|
|
|
244
262
|
|
|
245
263
|
if (!onlineDone) {
|
|
246
264
|
items = this.state.threadLocal(platform, chatId, limit).map((m) => this.decorateItem(m));
|
|
247
|
-
if (!error) error = blocked ? "已屏蔽:不同步新消息" : "在线拉取没有返回消息";
|
|
265
|
+
if (!error) error = blocked ? "已屏蔽:不同步新消息" : (skipped || "在线拉取没有返回消息");
|
|
248
266
|
} else {
|
|
249
267
|
const local = new Map();
|
|
250
268
|
for (const m of (this.state.getChat(platform, chatId)?.recent || [])) local.set(m.msg_id, m);
|
|
@@ -255,6 +273,9 @@ export class App {
|
|
|
255
273
|
...m,
|
|
256
274
|
kind: row.kind || m.kind || "",
|
|
257
275
|
state: row.state || "",
|
|
276
|
+
msg_type: row.msg_type || m.msg_type || "",
|
|
277
|
+
app_link: row.app_link || m.app_link || "",
|
|
278
|
+
media_paths: row.media_paths || [],
|
|
258
279
|
is_self: !!m.is_self || (!!self && m.sender_id === self),
|
|
259
280
|
};
|
|
260
281
|
});
|
|
@@ -291,6 +312,7 @@ export class App {
|
|
|
291
312
|
const text = String(pick(q, body, "text") || "").trim();
|
|
292
313
|
const replyTo = pick(q, body, "msg_id") || "";
|
|
293
314
|
if (!platform || !chatId || !text) return { ok: false, reason: "bad_request" };
|
|
315
|
+
if (!this.supported(platform)) return this.unsupported(platform);
|
|
294
316
|
try {
|
|
295
317
|
const r = await this.im.adapter(platform).sendText(chatId, text);
|
|
296
318
|
if (!r.ok) return { ok: false, reason: r.error || "send failed" };
|
|
@@ -317,6 +339,7 @@ export class App {
|
|
|
317
339
|
const platform = pick(q, body, "platform");
|
|
318
340
|
const chatId = pick(q, body, "chat_id");
|
|
319
341
|
if (!platform || !chatId) return { ok: false, reason: "bad_request" };
|
|
342
|
+
if (!this.supported(platform)) return this.unsupported(platform);
|
|
320
343
|
const name = pick(q, body, "name");
|
|
321
344
|
const kind = pick(q, body, "kind");
|
|
322
345
|
const workspace = pick(q, body, "workspace");
|
|
@@ -334,6 +357,14 @@ export class App {
|
|
|
334
357
|
const watching = rawWatching === undefined || rawWatching === "" ? true : boolValue(rawWatching, true);
|
|
335
358
|
chat.watching = watching;
|
|
336
359
|
chat.target = true;
|
|
360
|
+
// 加入值守即视为启用该平台:钉钉默认不开,避免没装 dws 的用户每轮白跑一次 whoami。
|
|
361
|
+
if (watching) {
|
|
362
|
+
const enabled = this.state.data.config.platforms || [];
|
|
363
|
+
if (!enabled.includes(platform)) {
|
|
364
|
+
this.state.data.config.platforms =
|
|
365
|
+
SUPPORTED_PLATFORMS.filter((p) => p === platform || enabled.includes(p));
|
|
366
|
+
}
|
|
367
|
+
}
|
|
337
368
|
if (!watching) this.turns.cancel(platform, chatId, "unwatch");
|
|
338
369
|
try { this.profiles.ensure(platform, chatId, chat.name); } catch { /* profile is best effort */ }
|
|
339
370
|
this.state.save();
|
|
@@ -366,6 +397,7 @@ export class App {
|
|
|
366
397
|
const platform = pick(q, body, "platform");
|
|
367
398
|
const term = String(pick(q, body, "q") || "").trim();
|
|
368
399
|
if (!platform || !term) return { ok: false, reason: "bad_request" };
|
|
400
|
+
if (!this.supported(platform)) return this.unsupported(platform);
|
|
369
401
|
try {
|
|
370
402
|
const r = await this.im.adapter(platform).search(term);
|
|
371
403
|
return { ok: r.ok, items: r.items, error: r.ok ? "" : r.error };
|
|
@@ -378,6 +410,7 @@ export class App {
|
|
|
378
410
|
const platform = pick(q, body, "platform");
|
|
379
411
|
const term = String(pick(q, body, "q") || "").trim();
|
|
380
412
|
if (!platform || !term) return { ok: false, reason: "bad_request" };
|
|
413
|
+
if (!this.supported(platform)) return this.unsupported(platform);
|
|
381
414
|
try {
|
|
382
415
|
const r = await this.im.adapter(platform).searchChats(term);
|
|
383
416
|
return { ok: r.ok, items: r.items, error: r.ok ? "" : r.error };
|
|
@@ -433,13 +466,14 @@ export class App {
|
|
|
433
466
|
const platform = body.platform || q1(q, "platform");
|
|
434
467
|
const chatId = body.chat_id || q1(q, "chat_id");
|
|
435
468
|
if (platform && chatId) {
|
|
469
|
+
if (!this.supported(platform)) return this.unsupported(platform);
|
|
436
470
|
const res = await this.poller.pollChat(platform, chatId, {
|
|
437
|
-
name: body.name, kind: body.kind,
|
|
471
|
+
name: body.name, kind: body.kind,
|
|
438
472
|
});
|
|
439
473
|
return { ok: !!res.fetched || !res.error, single: true, ...res };
|
|
440
474
|
}
|
|
441
475
|
if (this.poller.cycleLock) return { ok: false, busy: true, reason: "上一轮还没跑完" };
|
|
442
|
-
void this.poller.cycle({
|
|
476
|
+
void this.poller.cycle({ note: "manual" }).catch((e) => {
|
|
443
477
|
this.poller.logError(null, null, "manual cycle: " + (e?.message || e));
|
|
444
478
|
});
|
|
445
479
|
return { ok: true, started: true };
|
|
@@ -466,10 +500,31 @@ export class App {
|
|
|
466
500
|
merged[k] = { ...(this.state.data.config[k] || {}), ...body[k] };
|
|
467
501
|
}
|
|
468
502
|
}
|
|
503
|
+
const ignored = Array.isArray(body?.platforms)
|
|
504
|
+
? body.platforms.filter((p) => !SUPPORTED_PLATFORMS.includes(String(p)))
|
|
505
|
+
: [];
|
|
469
506
|
this.state.data.config = normalizeConfig(merged);
|
|
470
507
|
this.state.save();
|
|
471
508
|
this.poller.reload();
|
|
472
|
-
|
|
509
|
+
const out = publicConfig(this.state.data.config, this.hostReady());
|
|
510
|
+
if (ignored.length) {
|
|
511
|
+
out.ignored_platforms = ignored;
|
|
512
|
+
out.notice = `插件壳不支持 ${ignored.join(" / ")}(独立 skill 形态可用),已忽略`;
|
|
513
|
+
}
|
|
514
|
+
return out;
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
async setPlatform(q, body = {}) {
|
|
518
|
+
const platform = String(pick(q, body, "platform") || "");
|
|
519
|
+
if (!platform) return { ok: false, reason: "bad_request" };
|
|
520
|
+
if (!this.supported(platform)) return this.unsupported(platform);
|
|
521
|
+
const enabled = boolValue(pick(q, body, "enabled"), false);
|
|
522
|
+
const cur = new Set(this.state.data.config.platforms || []);
|
|
523
|
+
if (enabled) cur.add(platform); else cur.delete(platform);
|
|
524
|
+
this.state.data.config.platforms = SUPPORTED_PLATFORMS.filter((p) => cur.has(p));
|
|
525
|
+
this.state.save();
|
|
526
|
+
this.poller.reload();
|
|
527
|
+
return { ok: true, platforms: this.state.data.config.platforms };
|
|
473
528
|
}
|
|
474
529
|
|
|
475
530
|
async workspaces() {
|
|
@@ -574,6 +629,7 @@ export class App {
|
|
|
574
629
|
const platform = body.platform;
|
|
575
630
|
const chatId = body.chat_id;
|
|
576
631
|
if (!platform || !chatId) return { ok: false, reason: "bad_request" };
|
|
632
|
+
if (!this.supported(platform)) return this.unsupported(platform);
|
|
577
633
|
if (body.workspace) {
|
|
578
634
|
const applied = await this.applyWorkspace(platform, chatId, body.workspace);
|
|
579
635
|
if (!applied.ok) return applied;
|
|
@@ -588,6 +644,7 @@ export class App {
|
|
|
588
644
|
const nonSelf = chat.recent.some((m) => m.kind !== "out");
|
|
589
645
|
if (!nonSelf) return { ok: false, reason: "empty", pending: 0 };
|
|
590
646
|
const pending = this.state.pendingCount(chat);
|
|
647
|
+
if (!pending) return { ok: false, reason: "no_pending", pending: 0 };
|
|
591
648
|
const r = await this.turns.wake(chat, {});
|
|
592
649
|
if (!r.ok) return { ok: false, reason: r.reason, pending };
|
|
593
650
|
return { ok: true, pending, state: "running", turn_id: r.turn_id };
|
|
@@ -605,4 +662,35 @@ export class App {
|
|
|
605
662
|
turns: this.turns.snapshot(),
|
|
606
663
|
};
|
|
607
664
|
}
|
|
665
|
+
|
|
666
|
+
/**
|
|
667
|
+
* 每日关注摘要:只读 agent 写的那份文件,不创建、不解析、不统计。
|
|
668
|
+
* 目录与文件名都是确定性约定,插件这边唯一要防的是路径穿越。
|
|
669
|
+
*/
|
|
670
|
+
async digest(q) {
|
|
671
|
+
const now = new Date();
|
|
672
|
+
const today = `${now.getFullYear()}-${String(now.getMonth() + 1).padStart(2, "0")}-` +
|
|
673
|
+
String(now.getDate()).padStart(2, "0");
|
|
674
|
+
const date = String(q1(q, "date", "") || today);
|
|
675
|
+
if (!/^\d{4}-\d{2}-\d{2}$/.test(date)) return { ok: false, reason: "bad_date" };
|
|
676
|
+
const [y, mo, da] = date.split("-").map(Number);
|
|
677
|
+
const probe = new Date(y, mo - 1, da);
|
|
678
|
+
if (probe.getFullYear() !== y || probe.getMonth() !== mo - 1 || probe.getDate() !== da) {
|
|
679
|
+
return { ok: false, reason: "bad_date" };
|
|
680
|
+
}
|
|
681
|
+
const dir = path.resolve(this.state.dir, "digest");
|
|
682
|
+
const file = path.resolve(dir, `${date}.md`);
|
|
683
|
+
if (!file.startsWith(dir + path.sep)) return { ok: false, reason: "bad_date" };
|
|
684
|
+
let text = "";
|
|
685
|
+
let mtime = 0;
|
|
686
|
+
try {
|
|
687
|
+
const st = fs.statSync(file);
|
|
688
|
+
if (st.isFile()) {
|
|
689
|
+
mtime = Math.floor(st.mtimeMs / 1000);
|
|
690
|
+
text = fs.readFileSync(file, "utf8");
|
|
691
|
+
if (text.length > 256 * 1024) text = text.slice(0, 256 * 1024) + "\n\n(过长,已截断)";
|
|
692
|
+
}
|
|
693
|
+
} catch { /* 文件不存在就是空态,不建目录、不写盘 */ }
|
|
694
|
+
return { ok: true, date, exists: !!mtime, text, mtime };
|
|
695
|
+
}
|
|
608
696
|
}
|