dsh-dot-life 0.17.0 → 0.17.3
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/docs/DESIGN.md +6 -0
- package/docs/SETTINGS.md +1 -0
- package/docs/memory.md +2 -0
- package/docs/qq.md +3 -1
- package/package.json +1 -1
- package/src/dot/core.js +57 -6
- package/src/memory/memory.js +11 -9
- package/src/prompts/memory.handoff.txt +1 -1
- package/src/prompts/qq.channel.owner.txt +1 -1
- package/src/prompts/qq.channel.txt +1 -1
- package/src/qq/qq.js +144 -18
package/docs/DESIGN.md
CHANGED
|
@@ -227,3 +227,9 @@ Kevin:"感觉现在很难给他长任务。他很容易直接结束然后就
|
|
|
227
227
|
- **规则**:`dot.rules` 加一条:他连着发几条时等他说完、按最后一条的意思回、不逐条回;回到一半他又说话,先看。
|
|
228
228
|
- **记忆只记发出去的**:`qq_send` 不再在 `tool/call` 时按参数记,而是等同一 `callId` 的 `tool/result`:出错或被拦(`isError`)→ 不记;否则记 `meta.said` / `meta.imagesSent`(`qq_send` 的 `output.presentationMeta`,落在持久的 `tool/result` 上:打断后没发的、丢掉的英文行、上传失败的图都不在里面)。没有 meta 的旧结果按 `sent N` 取前 N 行。时间用调用的时刻,按时间插回 `lines`(handoff 尾巴、recall 都读它),重放会话日志(`transcriptFromEvents`)走同一个 `qqSentText`。
|
|
229
229
|
|
|
230
|
+
## v0.17.2(2026-11-04):图——她发的记成能发的样子,别人发的她看得见
|
|
231
|
+
|
|
232
|
+
两件事,0.17.1 的标记过滤(`markerOf`)只是兜底,这里修根上的原因。
|
|
233
|
+
|
|
234
|
+
- **记下的就是能发的**:交接尾巴里她的旧话写着 `… [图片×1]`(记录用的写法),新一段她照着打了一条 `[图片]`,dot 把对话里的回复原样转给他。现在 `qq_send` 的结果(`presentationMeta`)带上真正发出去的图的 ref(`images`,QQ 拒收的不在里面),记忆把它们写成 `[表情包 sticker:<id>]` / `[图 phone:screen]` / `[图 phone:latest]` / `[图 <网址>]`——照着打出来就是那张图(`markerOf` 认得,`sendGate` 也把它当 `images` 审)。只有数量的旧结果取调用里的前 N 张。交接尾巴的说明(`memory.handoff` 的 `tail`)跟着改;`qq.channel.owner` 说清两条路:直接写的回复会原样发给他,图和表情包只能用 `images`。
|
|
235
|
+
- **别人发的图她看得见**:以前进她会话的只有 `[图片 <网址>]` / `[表情包 sticker:<id>]` 这几个字。dsh 的用户消息本来就能带图(dsh-llm 的 `ImageBlock { type: 'image', attachment }`,`attachment` 是附件仓库 `ctx.attachments`——`@deepseek-ai/dsh-attachment` 的 `AttachmentStore`,cordis 服务名 `attachments`——`saveImages` 返回的 `ImageAttachmentRef`;mobile-mcp 截图走的也是这条:dsh-mcp-client 用 `ctx.get('attachments').saveImages` 存 MCP 结果里的图)。dot/qq 在会叫醒她的消息上取图、存进仓库,`m.images: [{ ref, text }]`;dot/core 把他的话和通知的叫醒文本拆成内容数组,图紧跟在它的文字后面(`withImages`)。文字部分拼起来和原来一字不差,所以记忆(只取 text 部分)、recall 索引都不变,也不会记下附件 id。模型不收图时 dsh 的请求组装自己换成文字占位(`projectImagesForTextModel`)。
|
package/docs/SETTINGS.md
CHANGED
|
@@ -142,6 +142,7 @@ setx DSH_DOT_COMPUTER off
|
|
|
142
142
|
| `scoreThreshold` | `7` | `score` 模式的插话门槛(0–10) |
|
|
143
143
|
| `sendPolicy` | `"reply"` | `reply` / `always` / `off` |
|
|
144
144
|
| `replyWindowMinutes` | `30` | `reply` 模式下多久内算"对方找过她" |
|
|
145
|
+
| `imageSeeMax` | `4` | 别人发来的图和表情包,每条消息最多给她看几张;0 只给文字 |
|
|
145
146
|
| `typingMsPerChar` | `60` | 分条发送的打字停顿,0 一次发完 |
|
|
146
147
|
| `tidy` | `true` | 去掉句号、引号、破折号等书面符号 |
|
|
147
148
|
| `dropLatinLeaks` | `true` | 不发整条都是英文的气泡(思考漏出来),短英文照发 |
|
package/docs/memory.md
CHANGED
|
@@ -26,6 +26,8 @@
|
|
|
26
26
|
|
|
27
27
|
`~/dot/memory/transcript.jsonl` 只记她对话里真实发生的:你说的话、她真正用 `qq_send` 发出去的话(发给谁;按工具结果记,记在调用的时刻:被拦下的一句不记,发到一半被他打断的只记发出去的几条,图片没发成的只记文字)、手机通知、跑腿留下的结论、定时任务。幕间写的虚构剧本不进这里,所以虚构的事不会变成「记忆」。`recall` 工具在这里、碎片和人物卡里找原话。叫醒她的消息开头带时间戳(`[11-04 04:51] …`、`[11-04 04:52 手机通知] …`,见 prompts.md),记进来时去掉——每行本来就有自己的时间,不记两遍。她对话里「现在」那行(`dot:now`)的「距上一条消息」也从这里算:上一条你说的或她说的话。
|
|
28
28
|
|
|
29
|
+
记录里的图(0.17.2):她发出去的图记成它的 ref,写法本身就能再发——`[表情包 sticker:<id>]`、`[图 phone:screen]`、`[图 phone:latest]`、`[图 <网址>]`(`face:<n>`、手机/电脑路径同理),一行里跟在文字后面:`那家店我去过 / 下次带你去 [图 phone:latest]`。0.17.0 的结果只有张数,就取那次调用 `images` 里的前几张;以前的 `[图片×N]` 不再写。别人发给她的图照旧是消息里的文字:`[图片 <网址>]`、`[表情包 sticker:<id>]`。她看得到那些图(见 qq.md),但记录只取消息的文字部分,图本身(附件 id、字节)从不进 transcript、碎片、recall 索引。交接尾巴和 recall 读的就是这些行;`memory.handoff` 的尾巴说明告诉她方括号里的是什么。
|
|
30
|
+
|
|
29
31
|
## 整理
|
|
30
32
|
|
|
31
33
|
每天 `dailyAt`(23:30)固定一次:把这一天新的记录整理掉,并让她写日记。
|
package/docs/qq.md
CHANGED
|
@@ -49,7 +49,8 @@ QQ 的电脑登录码**不接受相册导入,只认摄像头**。她手机的
|
|
|
49
49
|
| 她回 | `qq_send(to: "owner" \| "user:<号>" \| "group:<号>", text, images)`,**text 每一行一条**(`<sep/>` 也行),条与条之间按字数停一下(`typingMsPerChar`,默认 60 ms/字,最多 2.5 s)。dot 转发她在对话里的回答时同样按行拆。**审批**(`sendPolicy: reply`):发给你永远不问;回最近 30 分钟内给她发过消息的人或群(文字、网图)不问;发给没找过她的人、沉默的群,或者发她手机/电脑上的文件(`phone:*`、`/sdcard/…`、电脑路径)——先弹审批 |
|
|
50
50
|
| 她发图 | `images` 里每一项直接作为**图片**发出(不是链接):网址(NapCat 下载)、`phone:screen`(手机此刻截图)、`phone:latest`(手机里最新的照片/截图/下载)、`/sdcard/…`(手机上的文件)、电脑上的绝对路径;≤10 MB。**先文字后图**,但所有图在发第一条之前就先准备好(读手机、查网址、取表情包):哪张准备不了,整次调用报错,一条都没发出去。图已准备好、QQ 上传时才失败的,如果前面的文字已经发出去了,不报错:返回 `failed: [{ image, error }]`,她看到的是「文字已发出;图片 X 没发成:…」,这样她不会把文字再发一遍(审计里的 `sent` 也记着 `failed`)。`phone:screen` 截到一张纯白或纯黑的图(亮屏中、切换动画中)时,隔 400 ms 再截一次 |
|
|
51
51
|
| 图片网址规则 | 只接受公网 `http`/`https`、端口 80/443、不带账号密码;回环、私网、链路本地(含 169.254.169.254)、组播、`localhost`/`*.local`/`*.internal`/单段主机名一律拒绝并报错(NapCat 在 VM 里下载,防止她让它访问 VM 内部服务)。公网域名解析到内网(DNS rebinding)这里拦不住 |
|
|
52
|
-
| 别人发图给她 |
|
|
52
|
+
| 别人发图给她 | **她直接看得到**:你(或任何一条会叫醒她的消息)发来的图和表情包,dot/qq 取到字节(图片走 QQ 给的网址,经同一套公网 URL 检查;表情包用 `stickers.js` 里已下载的那份,不再下第二次),存进 dsh 的附件仓库(`ctx.attachments.saveImages`),作为 `{ type: 'image', attachment }` 跟在消息里那张图的文字后面,按消息里的顺序。文字不变:`[表情包 sticker:<id>]`、`[图片 <网址>]`(网址留着,她想存成表情包就 `qq_sticker_keep`)。每条消息最多 `imageSeeMax`(4)张,每张不超过附件仓库的 `imageLimits.maxImageBytes`(没有就 4 MB),只收 PNG / JPEG / GIF / WebP;一次叫醒合起来也按 `imageSeeMax` 和 `maxImagesPerMessage` / `maxMessageImageBytes` 截断。有图的消息要等取图,后面来的消息排在它后面,顺序不乱。没有附件仓库、取不到、存不进:就是以前的纯文字,日志 warn 一次。模型不收图时,dsh 自己把图换成一行文字占位 |
|
|
53
|
+
| 她的话怎么发出去 | 两条路:`qq_send`;或者她在对话里直接写回复,dot 原样转给你(只发文字)。图和表情包只能走 `qq_send` 的 `images`——提示词(`qq.channel.owner`)这么说。写在文字里的标记(一整条气泡就是 `[表情包 sticker:<id>]`、`[图 <ref>]`、`[图片 <网址>]`)会被当成那张图发出去,`[图片]` 这种空标记丢掉(0.17.1 的兜底,仍在);`[图 /sdcard/…]` 这类本地文件和写在 `images` 里一样要审批 |
|
|
53
54
|
| 表情包 | 别人发的表情包(QQ 标 `sub_type: 1`;QQ 自带的大表情 mface 的 summary 是 `[?]`、`[doge]` 这种短方括号,也算)进文本是 `[表情包 sticker:<id>]`,同时下载到 `~/.dsh/stickers/`,列表在 `~/.dsh/dsh-qq-stickers.json`(最多 300 张,先进先出);她自己也能存:手机 App 里长按保存图片后 `qq_sticker_keep(image: "phone:latest", note: "无语")`(或手机路径、网图)。发:`images: ["sticker:<id>"]`(以 base64 发出,标 sticker),`face:<编号>` 发 QQ 小黄脸;提示词里列最近 12 张;这两种不走审批。**手机上**:存下的每一张都同步到手机相册的 `dot-stickers`(`/sdcard/Pictures/dot-stickers/<id>.<ext>`;存了、新下载了、被挤掉了、手机开机时各同步一次,名字 + 大小一样的不重推),所以手机上任何 App 都能从相册选图发;手机 QQ 的「收藏」表情栏不会自己有它们——她得在 QQ 里长按 → 添加到表情,提示词(`qq.stickers` / `qq.channel.no-stickers` 说在哪,`phone.stickers` 说各 App 怎么加)只教不催。`/qq stickers` 看 `stickers: N saved · phone: N/M synced`,`/qq stickers sync` 立刻推一次。`phone:latest` 只看各相册目录下的文件本身(`ls -td`),dot-stickers 这个子目录不会被当成「刚存的图」。**冷启动**:她的表情包少于 5 张时,幕间知道这件事,可以写一个 `collect` 的 playIntent——去某个 App 逛逛顺手攒几张(见 interlude.md 的「玩」) |
|
|
54
55
|
| dot 的提醒、幕间的主动联系 | 连上后优先走她的 QQ(发给 `owner`),dsh-im 的官方机器人退为后备 |
|
|
55
56
|
| 手机上 QQ 的通知 | 连上后自动忽略(否则同一条叫两次);手机 QQ 照常可以看空间、看群、发图 |
|
|
@@ -122,6 +123,7 @@ QQ 的电脑登录码**不接受相册导入,只认摄像头**。她手机的
|
|
|
122
123
|
| `dropLatinLeaks` | `true` | 跟着 `tidy` 生效:一条 ≥ 30 字、80% 以上是英文字母/标点/空格(网址不算)的气泡,是她的思考漏进了回复(比如 `hmm, actually don't over-explain. Let's just be brief…`),不发,日志里 warn 一行(前 60 字);`ok`、`lol`、`GG` 这种短英文照发。全被拦下又没有图时,调用报错让她重写 |
|
|
123
124
|
| `sendPolicy` | `reply` | `qq_send` 审批:`reply`(见上表)/ `always`(除了你,发谁都问)/ `off`(不问) |
|
|
124
125
|
| `replyWindowMinutes` | `30` | `reply` 策略里"最近给她发过消息"的时间窗 |
|
|
126
|
+
| `imageSeeMax` | `4` | 叫醒她的消息里,每条最多让她看几张图 / 表情包;0 = 只给文字 |
|
|
125
127
|
| `githubProxy` / `DSH_DOT_GITHUB_PROXY` | 无 | 安装脚本下载 GitHub 资源的镜像前缀 |
|
|
126
128
|
| `autoStart` | `true` | 电脑就绪后自动启动 |
|
|
127
129
|
| `DSH_DOT_QQ=off` | | 不加载;电脑关了它也不加载 |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-dot-life",
|
|
3
|
-
"version": "0.17.
|
|
3
|
+
"version": "0.17.3",
|
|
4
4
|
"description": "dot — a character who lives on her own phone, for DeepSeek Harness (dsh): an Android phone the plugin installs and runs, her own QQ, memory and a diary from real events, a life between conversations (幕间, after HDS-Interlude), an optional microVM computer with approval gates. One plugin, six components.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "AGPL-3.0-only",
|
package/src/dot/core.js
CHANGED
|
@@ -49,6 +49,27 @@ const firstAt = (items, now) => { const t = Date.parse(items?.[0]?.at ?? ''); re
|
|
|
49
49
|
* `whileBusy` (steered into the turn she is in the middle of) adds one line saying so.
|
|
50
50
|
*/
|
|
51
51
|
export const ownerWords = (items, now = Date.now(), { whileBusy = false } = {}) => prompt('dot.owner-words', { stamp: stamp(firstAt(items, now), now), text: items.map((n) => n.text).join('\n'), busy: whileBusy ? prompt('dot.owner-words.busy') : '' });
|
|
52
|
+
/**
|
|
53
|
+
* A wake text with the pictures in it: the text cut right after each picture's words (`[表情包 sticker:<id>]`,
|
|
54
|
+
* `[图片]`), one `{ type: 'image', attachment }` there, in message order. The text parts joined are the text
|
|
55
|
+
* exactly, so what memory records (text parts only) does not change. A picture whose words are not in
|
|
56
|
+
* the text, or past `max` / `maxBytes` for the whole message, is left out (its words stay).
|
|
57
|
+
* @param images - `[{ ref: ImageAttachmentRef, text }]` from dsh-dot/qq.
|
|
58
|
+
*/
|
|
59
|
+
export function withImages(text, images = [], { max = Infinity, maxBytes = Infinity } = {}) {
|
|
60
|
+
const content = [];
|
|
61
|
+
let from = 0, n = 0, bytes = 0;
|
|
62
|
+
for (const im of images ?? []) {
|
|
63
|
+
if (!im?.ref || !im.text || n >= max || bytes + (Number(im.ref.bytes) || 0) > maxBytes) continue;
|
|
64
|
+
const i = text.indexOf(im.text, from);
|
|
65
|
+
if (i < 0) continue;
|
|
66
|
+
const end = i + im.text.length;
|
|
67
|
+
content.push({ type: 'text', text: text.slice(from, end) }, { type: 'image', attachment: im.ref });
|
|
68
|
+
from = end; n++; bytes += Number(im.ref.bytes) || 0;
|
|
69
|
+
}
|
|
70
|
+
if (from < text.length || !content.length) content.push({ type: 'text', text: text.slice(from) });
|
|
71
|
+
return content;
|
|
72
|
+
}
|
|
52
73
|
/** The model-facing reason a qq_send to him is held back: he said something she has not read yet. */
|
|
53
74
|
export const ownerInterruptText = () => prompt('dot.owner-interrupt');
|
|
54
75
|
/** Is this qq_send `to` him? "owner", or his number (bare or user:/private:). */
|
|
@@ -86,7 +107,8 @@ export function groupNotifications(items) {
|
|
|
86
107
|
const id = n.key || `${n.pkg}|${title}`;
|
|
87
108
|
const g = groups.get(id) ?? { pkg: n.pkg, title, texts: [] };
|
|
88
109
|
const text = String(n.text ?? '').trim();
|
|
89
|
-
|
|
110
|
+
// The same words twice in a row are one line, unless they carry a picture (two [图片] are two pictures).
|
|
111
|
+
if (text && (g.texts.at(-1) !== text || n.images?.length)) g.texts.push(text);
|
|
90
112
|
groups.set(id, g);
|
|
91
113
|
}
|
|
92
114
|
return [...groups.values()];
|
|
@@ -502,7 +524,7 @@ export function apply(ctx, config = {}) {
|
|
|
502
524
|
if (!items.length) return;
|
|
503
525
|
// The people in these messages, as she remembers them (dsh-dot/memory).
|
|
504
526
|
const cards = ctx.get('dotMemory')?.cardsFor?.(items) ?? '';
|
|
505
|
-
found.agent.followup(createUserMessage({ content:
|
|
527
|
+
found.agent.followup(createUserMessage({ content: contentFor(wakeText(items, { whileBusy, cards }), items), source: PHONE_NOTIFICATION_SOURCE }));
|
|
506
528
|
bump('woke', 1);
|
|
507
529
|
audit('notification-woke', { session: id, count: items.length, pkgs: [...new Set(items.map((n) => n.pkg))], whileBusy, sinceSeenMs: Date.now() - Date.parse(items[0].at), sincePostedMs: items[0].postedAt ? Date.now() - items[0].postedAt : undefined });
|
|
508
530
|
}).catch((err) => { logger.warn(`wake for notification failed: ${err.message}`); audit('notification-dropped', { pkgs, why: err.message }); });
|
|
@@ -512,11 +534,39 @@ export function apply(ctx, config = {}) {
|
|
|
512
534
|
* steered into it, so she reads them at her next step instead of after the turn (an agent without
|
|
513
535
|
* `steer` gets the followup).
|
|
514
536
|
*/
|
|
537
|
+
let agentShapeLogged = false;
|
|
515
538
|
const toOwnerAgent = (agent, id, items) => {
|
|
516
|
-
const
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
539
|
+
const busy = turns.has(id);
|
|
540
|
+
// The host's agent handle may not expose `steer`: `send(message, 'next-step', true)` is the same
|
|
541
|
+
// boundary in dsh-agent's inbox API; failing both, the followup (after the turn, as before).
|
|
542
|
+
const via = busy && typeof agent.steer === 'function' ? 'steer' : busy && typeof agent.send === 'function' ? 'send' : 'followup';
|
|
543
|
+
if (!agentShapeLogged) {
|
|
544
|
+
agentShapeLogged = true;
|
|
545
|
+
const methods = [...new Set([...Object.keys(agent), ...Object.getOwnPropertyNames(Object.getPrototypeOf(agent) ?? {})])].filter((k) => typeof agent[k] === 'function');
|
|
546
|
+
logger.info(`her agent handle offers: ${methods.join(', ')} (busy now: ${busy}, open turns: ${[...turns.keys()].map((k) => k.slice(0, 16)).join(' ') || 'none'})`);
|
|
547
|
+
}
|
|
548
|
+
const message = createUserMessage({ content: contentFor(ownerWords(items, Date.now(), { whileBusy: via !== 'followup' }), items), source: ownerSource() });
|
|
549
|
+
try {
|
|
550
|
+
if (via === 'steer') agent.steer(message); else if (via === 'send') agent.send(message, 'next-step', true); else agent.followup(message);
|
|
551
|
+
} catch (err) { logger.warn(`${via} failed (${err.message}); followup instead`); agent.followup(message); }
|
|
552
|
+
audit('owner-message', { session: id, count: items.length, whileBusy: busy, via }); bump('owner', items.length);
|
|
553
|
+
};
|
|
554
|
+
// The pictures in what wakes her (dsh-dot/qq saved them in the attachment store): image blocks in the
|
|
555
|
+
// message, capped per message by qq's imageSeeMax and the store's imageLimits. Without a store: text only.
|
|
556
|
+
let warnedImages = false;
|
|
557
|
+
const contentFor = (text, items) => {
|
|
558
|
+
const images = items.flatMap((n) => n.images ?? []);
|
|
559
|
+
if (!images.length) return [{ type: 'text', text }];
|
|
560
|
+
const store = ctx.get('attachments');
|
|
561
|
+
if (!store) {
|
|
562
|
+
if (!warnedImages) { warnedImages = true; logger.warn('pictures arrived but no attachment store (ctx.attachments) is mounted: she reads them as text'); }
|
|
563
|
+
return [{ type: 'text', text }];
|
|
564
|
+
}
|
|
565
|
+
const limits = store.imageLimits ?? {};
|
|
566
|
+
const content = withImages(text, images, { max: Math.min(ctx.get('dshQq')?.imageSeeMax ?? 4, limits.maxImagesPerMessage || Infinity), maxBytes: limits.maxMessageImageBytes || Infinity });
|
|
567
|
+
const seen = content.filter((p) => p.type === 'image').length;
|
|
568
|
+
if (seen) audit('images-in-message', { count: seen, of: images.length });
|
|
569
|
+
return content;
|
|
520
570
|
};
|
|
521
571
|
let frozen = 0; let frozenQueue = []; // while her conversation is being handed over (dsh-dot/memory)
|
|
522
572
|
const send = (id, items) => {
|
|
@@ -607,6 +657,7 @@ export function apply(ctx, config = {}) {
|
|
|
607
657
|
// QQ messages (NapCat in the computer) take the same road as phone notifications: batch, hold while busy, group.
|
|
608
658
|
ctx.inject(['dshQq'], (c) => c.effect(() => c.dshQq.onMessage?.((m) => wake({
|
|
609
659
|
key: `qq:${m.kind}:${m.groupId || m.userId}`, pkg: 'qq', title: m.kind === 'group' ? `群 ${m.groupId} · ${m.who}` : `${m.who}(${m.userId})`, text: m.text, at: m.at, postedAt: Date.parse(m.at), fromOwner: Boolean(m.fromOwner),
|
|
660
|
+
...(m.images?.length ? { images: m.images } : {}),
|
|
610
661
|
handles: [`qq:${m.userId}`], platform: 'qq', name: m.who, kind: m.kind,
|
|
611
662
|
})) ?? (() => {}), 'dsh-dot: qq messages'));
|
|
612
663
|
ctx.inject(['dshQq'], (c) => c.effect(() => c.dshQq.onTyping?.(ownerTypingNow) ?? (() => {}), 'dsh-dot: qq typing'));
|
package/src/memory/memory.js
CHANGED
|
@@ -186,27 +186,29 @@ export function applyExtraction(memory, out, { limits = DEFAULT_LIMITS, now = Da
|
|
|
186
186
|
/** His words as he typed them: without the line dot adds when they were steered into a running turn. */
|
|
187
187
|
export const ownerSaid = (text) => { const busy = `\n${prompt('dot.owner-words.busy')}`; return text.endsWith(busy) ? text.slice(0, -busy.length) : text; };
|
|
188
188
|
|
|
189
|
+
/** An image she sent, as her transcript writes it — the ref itself, so the line can be sent again as it reads: `[表情包 sticker:<id>]`, else `[图 <ref>]` (phone:screen, phone:latest, a URL, face:<n>, a path). */
|
|
190
|
+
export const sentImage = (ref) => { const r = String(ref ?? '').trim(); return /^sticker:/i.test(r) ? `[表情包 ${r}]` : `[图 ${r}]`; };
|
|
189
191
|
/**
|
|
190
192
|
* What one qq_send really put on QQ, as a transcript line's text ('' = nothing went out), from its
|
|
191
193
|
* `tool/result`: denied or failed → nothing; otherwise the bubbles qq_send reports as sent
|
|
192
|
-
* (`meta.said`, `meta.
|
|
193
|
-
* are not in them)
|
|
194
|
-
* `
|
|
194
|
+
* (`meta.said`, `meta.images` — an interrupted send, a dropped leak line and an image QQ refused
|
|
195
|
+
* are not in them), the images as their refs (sentImage). A result without `meta.images` (0.17.0's
|
|
196
|
+
* `imagesSent` count, an older version, a nested call): the first that many of the call's images; a
|
|
197
|
+
* result with no meta at all: the first `sent N` lines of the call's text, then images.
|
|
195
198
|
*/
|
|
196
199
|
export function qqSentText(args, result) {
|
|
197
200
|
if (!result || result.isError || result.message?.isError) return '';
|
|
198
201
|
const meta = result.meta && typeof result.meta === 'object' ? result.meta : null;
|
|
202
|
+
const asked = [].concat(args?.images ?? []).filter(Boolean).map(String);
|
|
199
203
|
let said, images;
|
|
200
|
-
if (Array.isArray(meta?.said)) { said = meta.said.map(String); images = Number(meta.imagesSent) || 0; }
|
|
204
|
+
if (Array.isArray(meta?.said)) { said = meta.said.map(String); images = Array.isArray(meta.images) ? meta.images.map(String) : asked.slice(0, Number(meta.imagesSent) || 0); }
|
|
201
205
|
else {
|
|
202
206
|
const parts = String(args?.text ?? '').split(/<sep\s*\/>|\n/i).map((x) => x.trim()).filter(Boolean);
|
|
203
|
-
const refs = [].concat(args?.images ?? []).filter(Boolean).length;
|
|
204
207
|
const m = /^sent (\d+) message/.exec(contentText(result.message?.content ?? result.content));
|
|
205
|
-
const n = m ? Number(m[1]) : parts.length +
|
|
206
|
-
said = parts.slice(0, n); images =
|
|
208
|
+
const n = m ? Number(m[1]) : parts.length + asked.length;
|
|
209
|
+
said = parts.slice(0, n); images = asked.slice(0, Math.max(0, n - parts.length));
|
|
207
210
|
}
|
|
208
|
-
|
|
209
|
-
return `${text}${images ? `${text ? ' ' : ''}[图片×${images}]` : ''}`;
|
|
211
|
+
return [said.join(' / '), ...images.map(sentImage)].filter(Boolean).join(' ');
|
|
210
212
|
}
|
|
211
213
|
const parseArgs = (s) => { try { return JSON.parse(s ?? '{}') ?? {}; } catch { return {}; } };
|
|
212
214
|
/** Lines kept in time order: a qq_send is recorded at its result, with the time of its call. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
QQ {owner} 是你的人:他私聊你的话会原样出现在对话里,就是他本人对你说的,回他用 qq_send(to: "owner"
|
|
1
|
+
QQ {owner} 是你的人:他私聊你的话会原样出现在对话里,就是他本人对你说的,回他用 qq_send(to: "owner")。你直接写的回复也会原样发给他(dot 代发);带图、带表情包必须用 qq_send 的 images,写在文字里发不出去。
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
你的 QQ({qq})在你电脑上也登着。{owner}其他人发来的消息会以「[QQ] 谁:内容」叫醒你,回复用 qq_send(立刻送达,to 用 user:<QQ号> 或 owner)。{score}要给人看图就用 qq_send 的 images 直接发图片——网上的图给网址,手机屏幕给 "phone:screen",手机里刚存的给 "phone:latest"
|
|
1
|
+
你的 QQ({qq})在你电脑上也登着。{owner}其他人发来的消息会以「[QQ] 谁:内容」叫醒你,回复用 qq_send(立刻送达,to 用 user:<QQ号> 或 owner)。{score}要给人看图就用 qq_send 的 images 直接发图片——网上的图给网址,手机屏幕给 "phone:screen",手机里刚存的给 "phone:latest"——别发链接让人自己点。别人发的图和表情包你直接就能看到(消息里带着图);想保存就 qq_sticker_keep。手机上的 QQ 照常可以看空间、看群。
|
|
2
2
|
聊天的样子:一句话一行,每行就是一条消息,短的几条比一大段好;想用表情就在 images 里发:{stickers};{faces}。可以只发一个表情不说话。
|
package/src/qq/qq.js
CHANGED
|
@@ -60,6 +60,10 @@ export const defaults = {
|
|
|
60
60
|
// could carry anything). 'always' asks for everything but the owner; 'off' never asks.
|
|
61
61
|
sendPolicy: 'reply',
|
|
62
62
|
replyWindowMinutes: 30,
|
|
63
|
+
// Pictures and stickers people send her (the owner and anyone whose message wakes her) go into the
|
|
64
|
+
// message as images she sees: at most this many per message, each within the attachment store's
|
|
65
|
+
// imageLimits (else 4 MB). 0 = text only ("[图片 <url>]", "[表情包 sticker:<id>]").
|
|
66
|
+
imageSeeMax: 4,
|
|
63
67
|
reconnectMs: 5000,
|
|
64
68
|
requestTimeoutMs: 15000,
|
|
65
69
|
};
|
|
@@ -229,7 +233,8 @@ export function sendGate({ to, text = '', images = [] }, { owner, policy = 'repl
|
|
|
229
233
|
const target = parseTarget(to, owner);
|
|
230
234
|
if (!target) return null; // qq.send rejects it with a clear error
|
|
231
235
|
if (owner && target.user_id === Number(owner)) return null;
|
|
232
|
-
|
|
236
|
+
// `[图 /sdcard/…]` typed as a bubble is sent as that image (qq.send), so it is judged as one here.
|
|
237
|
+
const local = [...[].concat(images ?? []), ...typedImages(text)].filter((r) => r && !/^(https?:\/\/|sticker:|face:)/i.test(String(r)));
|
|
233
238
|
const who = target.group_id ? `group:${target.group_id}` : `user:${target.user_id}`;
|
|
234
239
|
if (local.length) return `dsh-dot/qq: sending ${local.length} file(s) from her devices to ${who} (${local.map((r) => String(r).slice(0, 40)).join(', ')})`;
|
|
235
240
|
if (policy === 'always') return `dsh-dot/qq: message to ${who}: ${String(text).slice(0, 80)}`;
|
|
@@ -253,6 +258,42 @@ export function tidyVoice(text) {
|
|
|
253
258
|
}).join('\n').replace(/\n{3,}/g, '\n\n').trim();
|
|
254
259
|
}
|
|
255
260
|
|
|
261
|
+
/**
|
|
262
|
+
* A whole bubble that is transcript notation: `[图片]`, `[图片×3]`, `[表情包 sticker:<id>]`, `[表情 …]`,
|
|
263
|
+
* or what her transcript records for an image she sent — `[图 <ref>]` (phone:screen, phone:latest, a
|
|
264
|
+
* URL, face:<n>, a path) — and `[图片 <url>]`, a picture someone sent her. `image` is the ref it stands for ('' = a bare picture marker, nothing to send).
|
|
265
|
+
*/
|
|
266
|
+
export function markerOf(line) {
|
|
267
|
+
const s = String(line ?? '').trim();
|
|
268
|
+
const sent = /^\[图片?\s+([^\s\]]+)\]$/.exec(s);
|
|
269
|
+
if (sent) return imageSource(sent[1]) ? { image: sent[1] } : null;
|
|
270
|
+
const m = /^\[(图片|表情包?|image)(?:\s*[×x]\s*\d+)?(?:\s+sticker:([a-f0-9]{6,12}))?\]$/i.exec(s);
|
|
271
|
+
return m ? { image: m[2] ? `sticker:${m[2]}` : '' } : null;
|
|
272
|
+
}
|
|
273
|
+
/** Image refs typed as whole-bubble markers in a qq_send text (see markerOf), in order. */
|
|
274
|
+
export const typedImages = (text) => String(text ?? '').split(/<sep\s*\/>|\n/i).map(markerOf).filter((m) => m?.image).map((m) => m.image);
|
|
275
|
+
/** The ref of an image that went out, as she wrote it, normalised: `sticker:<id>`, `face:<n>`, a URL, phone:…, a path. */
|
|
276
|
+
export function sentRef(ref) {
|
|
277
|
+
const src = imageSource(ref);
|
|
278
|
+
if (!src) return String(ref ?? '').trim();
|
|
279
|
+
if (src.kind === 'sticker' || src.kind === 'face') return `${src.kind}:${src.ref}`;
|
|
280
|
+
if (src.kind === 'phone-screen') return 'phone:screen';
|
|
281
|
+
if (src.kind === 'phone-latest') return 'phone:latest';
|
|
282
|
+
return src.kind === 'phone' && !/^\/(sdcard|storage)\//.test(src.ref) ? `phone:${src.ref}` : src.ref;
|
|
283
|
+
}
|
|
284
|
+
/** An image ref as her transcript writes it — itself sendable (markerOf reads it back): `[表情包 sticker:<id>]`, else `[图 <ref>]`. */
|
|
285
|
+
export const imageMarker = (ref) => (/^sticker:/.test(String(ref)) ? `[表情包 ${ref}]` : `[图 ${ref}]`);
|
|
286
|
+
|
|
287
|
+
/** The media type of image bytes, from their first bytes ('' = not PNG, JPEG, GIF or WebP). */
|
|
288
|
+
export function imageType(buf) {
|
|
289
|
+
const b = Buffer.isBuffer(buf) ? buf : Buffer.from(buf ?? []);
|
|
290
|
+
if (b.length >= 8 && b[0] === 0x89 && b.toString('latin1', 1, 4) === 'PNG') return 'image/png';
|
|
291
|
+
if (b.length >= 3 && b[0] === 0xff && b[1] === 0xd8 && b[2] === 0xff) return 'image/jpeg';
|
|
292
|
+
if (b.length >= 6 && b.toString('latin1', 0, 4) === 'GIF8') return 'image/gif';
|
|
293
|
+
if (b.length >= 12 && b.toString('latin1', 0, 4) === 'RIFF' && b.toString('latin1', 8, 12) === 'WEBP') return 'image/webp';
|
|
294
|
+
return '';
|
|
295
|
+
}
|
|
296
|
+
|
|
256
297
|
/**
|
|
257
298
|
* A bubble that is English prose, not chat: 30+ characters (URLs aside) of which ≥ 80% are ASCII
|
|
258
299
|
* letters, punctuation or spaces. That is the model thinking aloud ("hmm, actually don't over-explain…").
|
|
@@ -881,7 +922,16 @@ export function apply(ctx, config = {}, deps = {}) {
|
|
|
881
922
|
if (String(ev.user_id) === selfId) return;
|
|
882
923
|
const isGroup = ev.message_type === 'group';
|
|
883
924
|
const who = ev.sender?.card || ev.sender?.nickname || String(ev.user_id);
|
|
884
|
-
|
|
925
|
+
// Every picture in it, in order, with the words that stand for it in `text` — what she may get to see (seeImages).
|
|
926
|
+
const seen = [];
|
|
927
|
+
const segs = Array.isArray(ev.message) ? ev.message.map((s) => {
|
|
928
|
+
if (s?.type !== 'image') return s;
|
|
929
|
+
if (!isSticker(s.data)) { if (s.data?.url) seen.push({ url: s.data.url, text: segmentsToText([s]) }); return s; }
|
|
930
|
+
const k = keepSticker(s.data, who);
|
|
931
|
+
if (k.id) seen.push({ sticker: k.id, text: k.seg.data.text, fetching: k.fetching });
|
|
932
|
+
return k.seg;
|
|
933
|
+
}) : ev.message;
|
|
934
|
+
const text = segmentsToText(segs, selfId);
|
|
885
935
|
if (!text) return;
|
|
886
936
|
const wanted = isGroup ? groupWanted(ev, cfg.groupPolicy, selfId) : true;
|
|
887
937
|
if (isGroup) {
|
|
@@ -895,24 +945,92 @@ export function apply(ctx, config = {}, deps = {}) {
|
|
|
895
945
|
if (fromOwner) lastOwnerAt = Date.now();
|
|
896
946
|
recent.set(isGroup ? `group:${msg.groupId}` : `user:${msg.userId}`, Date.now());
|
|
897
947
|
if (recent.size > 500) recent.delete(recent.keys().next().value);
|
|
898
|
-
if (wanted === 'score') { void scoreAndDeliver(msg); return; }
|
|
899
|
-
deliver(msg);
|
|
948
|
+
if (wanted === 'score') { void scoreAndDeliver(msg, seen); return; }
|
|
949
|
+
deliver(msg, seen);
|
|
900
950
|
}
|
|
901
951
|
/** A sticker someone sent: into her collection (downloaded once, in the background) and named in the text she reads. */
|
|
902
952
|
function keepSticker(d, who) {
|
|
903
953
|
const got = urlRefusal(d.url) ? null : stickers.note({ file: d.file, url: d.url, from: who });
|
|
904
|
-
if (!got) return { type: 'text', data: { text: '[表情包]' } };
|
|
905
|
-
|
|
906
|
-
|
|
954
|
+
if (!got) return { seg: { type: 'text', data: { text: '[表情包]' } } };
|
|
955
|
+
// `fetching`: the one download, which seeing it (seeImages) waits for instead of fetching again.
|
|
956
|
+
const fetching = got.isNew ? stickers.fetch(got.id).then((ok) => { if (ok) audit({ kind: 'sticker-kept', id: got.id, from: who }); return ok; }, (err) => { logger.debug(`sticker ${got.id}: ${err.message}`); return false; }) : undefined;
|
|
957
|
+
return { seg: { type: 'text', data: { text: `[表情包 sticker:${got.id}]` } }, id: got.id, fetching };
|
|
958
|
+
}
|
|
959
|
+
// ---- what she sees: pictures and stickers in a message that wakes her, as images in that message ----
|
|
960
|
+
const warned = new Set();
|
|
961
|
+
const warnOnce = (key, m) => { if (warned.has(key)) return; warned.add(key); logger.warn(m); };
|
|
962
|
+
const SEE_MAX_BYTES = 4 * 1024 * 1024;
|
|
963
|
+
const SEE_TYPES = ['image/png', 'image/jpeg', 'image/webp', 'image/gif'];
|
|
964
|
+
/** The bytes of one picture in a message: a sticker from her collection (downloaded once), else its QQ URL. */
|
|
965
|
+
async function seenBytes(item, cap) {
|
|
966
|
+
let buf;
|
|
967
|
+
if (item.sticker) {
|
|
968
|
+
if (!(await (item.fetching ?? stickers.fetch(item.sticker).catch(() => false)))) throw new Error(`sticker ${item.sticker} not downloaded`);
|
|
969
|
+
buf = stickers.read(item.sticker);
|
|
970
|
+
if (!buf) throw new Error(`sticker ${item.sticker} not in her collection`);
|
|
971
|
+
} else {
|
|
972
|
+
const why = urlRefusal(item.url);
|
|
973
|
+
if (why) throw new Error(`image URL refused: ${why}`);
|
|
974
|
+
const res = await (deps.fetch ?? globalThis.fetch)(publicHttpUrl(item.url), { signal: AbortSignal.timeout(15_000) });
|
|
975
|
+
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
|
976
|
+
if (Number(res.headers?.get?.('content-length') ?? 0) > cap) throw new Error(`image over ${cap} bytes`);
|
|
977
|
+
buf = Buffer.from(await res.arrayBuffer());
|
|
978
|
+
}
|
|
979
|
+
if (!buf.length || buf.length > cap) throw new Error(`image is ${buf.length} bytes (1 – ${cap})`);
|
|
980
|
+
return buf;
|
|
981
|
+
}
|
|
982
|
+
/**
|
|
983
|
+
* The message with `images: [{ ref, text }]`: each picture she can see, saved in dsh's attachment store
|
|
984
|
+
* (`ctx.attachments`), with the words that stand for it in the message text (`[表情包 sticker:<id>]`,
|
|
985
|
+
* `[图片 <url>]` — the URL stays, for qq_sticker_keep). The text itself is unchanged. At most
|
|
986
|
+
* imageSeeMax, each within the store's imageLimits. No store, nothing fetchable, or every save
|
|
987
|
+
* refused: the message as it was (text only).
|
|
988
|
+
*/
|
|
989
|
+
async function seeImages(msg, seen) {
|
|
990
|
+
if (!seen.length || !(cfg.imageSeeMax > 0)) return msg;
|
|
991
|
+
const store = ctx.get?.('attachments');
|
|
992
|
+
if (typeof store?.saveImages !== 'function') { warnOnce('no-store', 'no attachment store (ctx.attachments): pictures and stickers reach her as text only'); return msg; }
|
|
993
|
+
const limits = store.imageLimits ?? {};
|
|
994
|
+
const max = Math.min(cfg.imageSeeMax, limits.maxImagesPerMessage || Infinity);
|
|
995
|
+
const cap = limits.maxImageBytes || SEE_MAX_BYTES;
|
|
996
|
+
const types = limits.mediaTypes ?? SEE_TYPES;
|
|
997
|
+
const got = [];
|
|
998
|
+
for (const item of seen) {
|
|
999
|
+
if (got.length >= max) break;
|
|
1000
|
+
try {
|
|
1001
|
+
const data = await seenBytes(item, cap);
|
|
1002
|
+
const mediaType = imageType(data);
|
|
1003
|
+
if (!types.includes(mediaType)) throw new Error(`not an image she can see (${mediaType || 'unknown type'})`);
|
|
1004
|
+
got.push({ item, input: { data: new Uint8Array(data), mediaType, name: item.sticker ? `sticker-${item.sticker}` : 'qq-image' } });
|
|
1005
|
+
} catch (err) { logger.debug(`picture not seen: ${err.message}`); }
|
|
1006
|
+
}
|
|
1007
|
+
if (!got.length) return msg;
|
|
1008
|
+
const refs = new Map();
|
|
1009
|
+
try { (await store.saveImages(got.map((g) => g.input))).forEach((ref, i) => refs.set(got[i].item, ref)); } catch (err) {
|
|
1010
|
+
// The batch is all or nothing: one bad picture must not hide the others.
|
|
1011
|
+
for (const g of got) { try { refs.set(g.item, (await store.saveImages([g.input]))[0]); } catch (e) { logger.warn(`picture not saved for her to see: ${e.message}`); } }
|
|
1012
|
+
if (!refs.size) warnOnce(`save:${err.message}`, `attachment store refused the pictures (${err.message}): text only`);
|
|
1013
|
+
}
|
|
1014
|
+
if (!refs.size) return msg;
|
|
1015
|
+
const images = seen.filter((item) => refs.has(item)).map((item) => ({ ref: refs.get(item), text: item.text }));
|
|
1016
|
+
audit({ kind: 'images-seen', from: msg.userId, count: images.length });
|
|
1017
|
+
return { ...msg, images };
|
|
1018
|
+
}
|
|
1019
|
+
// Messages reach her in the order they came: one with pictures waits for them, and those after it wait too.
|
|
1020
|
+
let delivering = Promise.resolve(), queued = 0;
|
|
1021
|
+
function deliver(msg, seen = []) {
|
|
1022
|
+
if (!seen.length && !queued) { emit(msg); return; }
|
|
1023
|
+
queued++;
|
|
1024
|
+
delivering = delivering.then(() => seeImages(msg, seen)).catch((err) => { logger.warn(`pictures not seen: ${err.message}`); return msg; }).then((m) => emit(m)).finally(() => { queued--; });
|
|
907
1025
|
}
|
|
908
|
-
function
|
|
909
|
-
audit({ kind: 'message', ...msg, text: msg.text.slice(0, 200) });
|
|
1026
|
+
function emit(msg) {
|
|
1027
|
+
audit({ kind: 'message', ...msg, text: msg.text.slice(0, 200), ...(msg.images ? { images: msg.images.length } : {}) });
|
|
910
1028
|
for (const fn of listeners) { try { fn(msg); } catch (err) { logger.warn(`qq listener: ${err.message}`); } }
|
|
911
1029
|
}
|
|
912
1030
|
/** groupPolicy 'score': one short model call decides whether this group message wakes her. */
|
|
913
1031
|
const groupLines = new Map();
|
|
914
1032
|
const scoreBudget = new Map(); // group → [timestamps of calls in the last minute]
|
|
915
|
-
async function scoreAndDeliver(msg) {
|
|
1033
|
+
async function scoreAndDeliver(msg, seen = []) {
|
|
916
1034
|
const llm = ctx.get?.('llm');
|
|
917
1035
|
const sel = (() => { try { return ctx.get?.('agentDefaultModel')?.currentSelection?.(); } catch { return null; } })();
|
|
918
1036
|
if (!llm?.stream) return;
|
|
@@ -933,7 +1051,7 @@ export function apply(ctx, config = {}, deps = {}) {
|
|
|
933
1051
|
} catch (err) { logger.debug(`group score failed: ${err.message}`); return; }
|
|
934
1052
|
const score = parseScore(text);
|
|
935
1053
|
audit({ kind: 'group-score', group: msg.groupId, from: msg.userId, score, raw: text.slice(0, 40), text: msg.text.slice(0, 80) });
|
|
936
|
-
if (score >= cfg.scoreThreshold) deliver({ ...msg, score });
|
|
1054
|
+
if (score >= cfg.scoreThreshold) deliver({ ...msg, score }, seen);
|
|
937
1055
|
}
|
|
938
1056
|
function call(action, params) {
|
|
939
1057
|
return new Promise((resolve, reject) => {
|
|
@@ -997,6 +1115,8 @@ export function apply(ctx, config = {}, deps = {}) {
|
|
|
997
1115
|
return got;
|
|
998
1116
|
};
|
|
999
1117
|
qq.stickerCount = () => stickers.count();
|
|
1118
|
+
/** At most this many pictures per message she is woken with (dot caps a whole wake the same). */
|
|
1119
|
+
qq.imageSeeMax = cfg.imageSeeMax;
|
|
1000
1120
|
qq.stickerSync = stickerSync;
|
|
1001
1121
|
/**
|
|
1002
1122
|
* Send to "user:123" | "group:456" | "owner" | a number: text (one bubble per line or <sep/>, paced) and/or images, in that order.
|
|
@@ -1004,7 +1124,7 @@ export function apply(ctx, config = {}, deps = {}) {
|
|
|
1004
1124
|
* QQ then refuses an image after something was already delivered, the call does not throw (she would
|
|
1005
1125
|
* resend the text): it returns `failed: [{ image, error }]` next to what was sent.
|
|
1006
1126
|
* To him: if he says something while the bubbles are going out, the rest is not sent — `{ sent,
|
|
1007
|
-
* interrupted: true, unsent: [lines…] }` (images not yet sent are listed as `[
|
|
1127
|
+
* interrupted: true, unsent: [lines…] }` (images not yet sent are listed as `[图 <ref>]` / `[表情包 sticker:<id>]`).
|
|
1008
1128
|
*/
|
|
1009
1129
|
qq.send = async (to, text = '', images = []) => {
|
|
1010
1130
|
const target = parseTarget(to, qq.owner);
|
|
@@ -1012,12 +1132,17 @@ export function apply(ctx, config = {}, deps = {}) {
|
|
|
1012
1132
|
const action = target.group_id ? 'send_group_msg' : 'send_private_msg';
|
|
1013
1133
|
let parts = String(text ?? '').split(/<sep\s*\/>|\n/i).map((t) => (cfg.tidy ? tidyVoice(t) : t.trim())).filter(Boolean);
|
|
1014
1134
|
let dropped = 0;
|
|
1135
|
+
// Transcript notation typed as words ("[图片]", "[图片×2]", "[表情包 sticker:ab12]", "[图 phone:latest]"):
|
|
1136
|
+
// not chat. A marker that names an image becomes that image; a bare picture marker is dropped.
|
|
1137
|
+
const markers = parts.map(markerOf).filter(Boolean);
|
|
1138
|
+
if (markers.length) { parts = parts.filter((p) => !markerOf(p)); images = [...[].concat(images ?? []), ...markers.map((m) => m.image).filter(Boolean)]; }
|
|
1015
1139
|
if (cfg.tidy && cfg.dropLatinLeaks !== false) {
|
|
1016
1140
|
parts = parts.filter((p) => { if (!latinLeak(p)) return true; dropped++; logger.warn(`dropped an English-prose bubble (reasoning leak?): ${p.slice(0, 60)}`); return false; });
|
|
1017
1141
|
}
|
|
1018
1142
|
const refs = [].concat(images ?? []).filter(Boolean);
|
|
1019
1143
|
const segments = [];
|
|
1020
1144
|
for (const ref of refs) segments.push(await imageSegment(ref));
|
|
1145
|
+
if (!parts.length && !segments.length && markers.length) return { sent: 0, messageIds: [], said: [], imagesSent: 0, images: [], note: '只有 [图片] 这种记录标记,没有要发的内容;发图用 images' };
|
|
1021
1146
|
if (!parts.length && !segments.length) throw new Error(dropped ? `nothing to send: ${dropped} line(s) were English prose, not chat, and were dropped — write what you mean to say to them` : 'nothing to send (text and images both empty)');
|
|
1022
1147
|
const ids = [], failed = [];
|
|
1023
1148
|
const started = Date.now();
|
|
@@ -1026,16 +1151,17 @@ export function apply(ctx, config = {}, deps = {}) {
|
|
|
1026
1151
|
for (const [i, part] of parts.entries()) {
|
|
1027
1152
|
if (i && cfg.typingMsPerChar > 0) await new Promise((r) => setTimeout(r, Math.min(2500, part.length * cfg.typingMsPerChar)));
|
|
1028
1153
|
// He spoke while she was typing these out: stop, she reads him first.
|
|
1029
|
-
if (i && toOwner && qq.ownerSaidSince(started)) { unsent = [...parts.slice(i), ...refs.map((r) =>
|
|
1154
|
+
if (i && toOwner && qq.ownerSaidSince(started)) { unsent = [...parts.slice(i), ...refs.map((r) => imageMarker(sentRef(r).slice(0, 80)))]; break; }
|
|
1030
1155
|
ids.push((await call(action, { ...target, message: [{ type: 'text', data: { text: part } }] }))?.message_id);
|
|
1031
1156
|
}
|
|
1032
1157
|
if (unsent) {
|
|
1033
1158
|
qq.sentToOwnerAt = Date.now();
|
|
1034
1159
|
audit({ kind: 'sent', to: target, text: parts.slice(0, ids.length).join(' / ').slice(0, 200), interrupted: true, unsent: unsent.length });
|
|
1035
|
-
return { sent: ids.length, messageIds: ids, interrupted: true, unsent, said: parts.slice(0, ids.length), imagesSent: 0 };
|
|
1160
|
+
return { sent: ids.length, messageIds: ids, interrupted: true, unsent, said: parts.slice(0, ids.length), imagesSent: 0, images: [] };
|
|
1036
1161
|
}
|
|
1162
|
+
const went = []; // the refs of the images that went out, in order (her transcript records them)
|
|
1037
1163
|
for (const [i, seg] of segments.entries()) {
|
|
1038
|
-
try { ids.push((await call(action, { ...target, message: [seg] }))?.message_id); } catch (err) {
|
|
1164
|
+
try { ids.push((await call(action, { ...target, message: [seg] }))?.message_id); went.push(sentRef(refs[i])); } catch (err) {
|
|
1039
1165
|
if (!ids.length) throw err; // nothing delivered yet: an ordinary failure
|
|
1040
1166
|
failed.push({ image: String(refs[i]).slice(0, 80), error: err.message });
|
|
1041
1167
|
}
|
|
@@ -1043,7 +1169,7 @@ export function apply(ctx, config = {}, deps = {}) {
|
|
|
1043
1169
|
const n = ids.length;
|
|
1044
1170
|
if (qq.owner && target.user_id === Number(qq.owner)) qq.sentToOwnerAt = Date.now();
|
|
1045
1171
|
audit({ kind: 'sent', to: target, text: parts.join(' / ').slice(0, 200), images: refs.map((r) => (String(r).startsWith('http') ? r : String(r).slice(0, 80))), ...(failed.length ? { failed } : {}), ...(dropped ? { dropped } : {}) });
|
|
1046
|
-
return { sent: n, messageIds: ids, said: parts, imagesSent:
|
|
1172
|
+
return { sent: n, messageIds: ids, said: parts, imagesSent: went.length, images: went, ...(failed.length ? { failed, textSent: parts.length } : {}), ...(dropped ? { dropped } : {}) };
|
|
1047
1173
|
};
|
|
1048
1174
|
/** Her friend list: [{ uid, nickname, remark }] (OneBot get_friend_list). */
|
|
1049
1175
|
qq.friends = async () => ((await call('get_friend_list', {})) ?? []).map((f) => ({ uid: String(f.user_id ?? ''), nickname: String(f.nickname ?? ''), remark: String(f.remark ?? '') })).filter((f) => f.uid);
|
|
@@ -1098,10 +1224,10 @@ export function apply(ctx, config = {}, deps = {}) {
|
|
|
1098
1224
|
description: '用你的 QQ(电脑端在线)发消息:文字和/或图片。to: "user:<QQ号>"、"group:<群号>" 或 "owner"(和你说话的人)。text 里每一行是单独一条消息,像人打字那样一句一句发。images 是要发的图片,每张直接作为图片发出去(不是链接):"sticker:<id>"(你存的表情包,id 见收到的 [表情包 sticker:…]);"face:<编号>"(QQ 小黄脸);图片网址;"phone:screen"(你手机此刻的屏幕截图);"phone:latest"(你手机里最新的照片/截图/下载);手机上的路径 "/sdcard/...";或你电脑上的绝对路径。只在你确实想回或想说时用。',
|
|
1099
1225
|
parameters: { type: 'object', properties: { to: { type: 'string' }, text: { type: 'string' }, images: { type: 'array', items: { type: 'string' } } }, required: ['to'], additionalProperties: false },
|
|
1100
1226
|
// presentationMeta lands on the durable tool/result: what really went out, for her memory's transcript.
|
|
1101
|
-
output: { schema: { type: 'object', properties: { sent: { type: 'number' } }, required: ['sent'], additionalProperties: true }, render: (_a, v) => [{ type: 'text', text: sendReport(v) }], presentationMeta: (_a, v) => ({ sent: v?.sent ?? 0, said: v?.said ?? [], imagesSent: v?.imagesSent ?? 0, ...(v?.interrupted ? { interrupted: true } : {}) }) },
|
|
1227
|
+
output: { schema: { type: 'object', properties: { sent: { type: 'number' } }, required: ['sent'], additionalProperties: true }, render: (_a, v) => [{ type: 'text', text: sendReport(v) }], presentationMeta: (_a, v) => ({ sent: v?.sent ?? 0, said: v?.said ?? [], imagesSent: v?.imagesSent ?? 0, images: v?.images ?? [], ...(v?.interrupted ? { interrupted: true } : {}) }) },
|
|
1102
1228
|
async execute(args) {
|
|
1103
1229
|
const r = await qq.send(args.to, args.text ?? '', args.images ?? []);
|
|
1104
|
-
const out = { sent: r.sent, said: r.said ?? [], imagesSent: r.imagesSent ?? 0, ...(r.failed ? { failed: r.failed, textSent: r.textSent } : {}), ...(r.dropped ? { dropped: r.dropped } : {}), ...(r.interrupted ? { interrupted: true, unsent: r.unsent } : {}) };
|
|
1230
|
+
const out = { sent: r.sent, said: r.said ?? [], imagesSent: r.imagesSent ?? 0, images: r.images ?? [], ...(r.failed ? { failed: r.failed, textSent: r.textSent } : {}), ...(r.dropped ? { dropped: r.dropped } : {}), ...(r.interrupted ? { interrupted: true, unsent: r.unsent } : {}) };
|
|
1105
1231
|
return r.failed || r.dropped || r.interrupted ? { ...out, note: sendReport(out).split('\n').slice(1).join('\n') } : out;
|
|
1106
1232
|
},
|
|
1107
1233
|
}), 'dsh-dot/qq: qq_send tool');
|