cortico-world-wechat-claw 0.1.1 → 0.1.2
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/CHANGELOG.md +20 -1
- package/package.json +2 -1
- package/src/config.ts +5 -2
- package/src/world.ts +48 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,23 @@
|
|
|
1
|
-
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.1.2
|
|
4
|
+
|
|
5
|
+
安全修复:收件人钉死在绑定本人。
|
|
6
|
+
|
|
7
|
+
- **回复目标不再随入站消息变化**。早先用「最近一条消息的发送者」当收件人,任何人只要能让一条
|
|
8
|
+
消息进入收件流(群成员、服务通知、陌生人),文字和文件就会被发到对方。现在一律发往绑定记录里的
|
|
9
|
+
`userId`,拿不到就明确报错而不是乱发。
|
|
10
|
+
- **只接受绑定本人发来的消息**。发送者不是本人就丢弃并记一条 warn,不再进入上下文、
|
|
11
|
+
也不保存它的 `context_token`。
|
|
12
|
+
- 绑定记录缺少 `ilink_user_id` 时,把扫码后第一条消息的发送者认作本人并写回 `auth.json`,
|
|
13
|
+
认领只发生一次,之后严格比对。
|
|
14
|
+
- **配置页加安全提示**:说明启用后模型能把本机任意文件发到微信(含它自己的登录令牌),
|
|
15
|
+
且发送前不会确认。
|
|
16
|
+
- **主动声明 `unsafe` 标签**:这个能力确实符合该标签的定义,由作者声明而不是等维护者来加。
|
|
17
|
+
|
|
18
|
+
注意:这次没有收紧「能发哪些文件」。`wechat_send_image` / `wechat_send_file` 仍接受任意绝对路径,
|
|
19
|
+
所以 `unsafe`(能把本机任意文件发到微信)依然成立。要撤这个标签,得先收紧到白名单目录,
|
|
20
|
+
再向索引仓提 `[tags]` issue。
|
|
2
21
|
|
|
3
22
|
## 0.1.1
|
|
4
23
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cortico-world-wechat-claw",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "在微信里和桌宠一对一聊天:文字、图片、文件双向收发,语音用微信的转写文本,视频可按需抽帧给模型看。",
|
|
6
6
|
"author": {
|
|
@@ -40,6 +40,7 @@
|
|
|
40
40
|
"webUiClient": "dist/webui.js",
|
|
41
41
|
"tags": [
|
|
42
42
|
"im",
|
|
43
|
+
"unsafe",
|
|
43
44
|
"unofficial-api"
|
|
44
45
|
],
|
|
45
46
|
"locales": {
|
package/src/config.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import type { ConfigGroup } from 'cortico/core/types.ts';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* `config.json` 的 `worlds.wechat-claw` 段。
|
|
@@ -59,7 +59,10 @@ export const WECHAT_CLAW_CONFIG_GROUP: ConfigGroup = {
|
|
|
59
59
|
schema: {
|
|
60
60
|
type: 'object',
|
|
61
61
|
title: '微信 ClawBot',
|
|
62
|
-
description:
|
|
62
|
+
description:
|
|
63
|
+
'微信一对一私聊的接入方式与收件范围。绑定状态在「微信绑定」面板。\n'
|
|
64
|
+
+ '⚠ 安全提示:启用后模型能把本机任意文件发到微信,包括它自己的登录令牌,'
|
|
65
|
+
+ '发送前不会向你确认。只在你信任这个微信账号、并清楚可能被发出去什么时启用。',
|
|
63
66
|
properties: {
|
|
64
67
|
'worlds.wechat-claw.networkMode': {
|
|
65
68
|
type: 'string',
|
package/src/world.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
2
|
* 微信 ClawBot World。
|
|
3
3
|
*
|
|
4
4
|
* 一个 iLink 一对一通道:扫码绑定、长轮询收消息、按类型回复文字/图片/文件。
|
|
@@ -195,7 +195,6 @@ export class WechatClawWorld implements World {
|
|
|
195
195
|
#started = false;
|
|
196
196
|
#startedAt = '';
|
|
197
197
|
#lastError = '';
|
|
198
|
-
#lastUserId = '';
|
|
199
198
|
#lastMessageAt = '';
|
|
200
199
|
#contextCount = 0;
|
|
201
200
|
#networkProblem = '';
|
|
@@ -264,13 +263,21 @@ export class WechatClawWorld implements World {
|
|
|
264
263
|
}
|
|
265
264
|
}
|
|
266
265
|
|
|
267
|
-
/**
|
|
266
|
+
/**
|
|
267
|
+
* 回复目标:**永远是绑定的微信本人**。
|
|
268
|
+
*
|
|
269
|
+
* 不用「最近一条消息的发送者」当目标——那样任何人只要能让一条消息进入收件流
|
|
270
|
+
* (群聊成员、服务通知、陌生人),回复目标就会被改写成对方,文件和文字都会发错人。
|
|
271
|
+
* 这个插件只服务一对一私聊,所以收件人钉死在绑定记录里。
|
|
272
|
+
*/
|
|
268
273
|
#replyTarget(): { to: string; contextToken: string } {
|
|
269
274
|
if (!this.#driver || !this.#auth?.token) {
|
|
270
275
|
throw new Error('微信未连接:先在「微信绑定」面板扫码,并确认本 World 已启用。');
|
|
271
276
|
}
|
|
272
|
-
const to = this.#
|
|
273
|
-
if (!to)
|
|
277
|
+
const to = String(this.#auth.userId ?? '').trim();
|
|
278
|
+
if (!to) {
|
|
279
|
+
throw new Error('绑定记录里没有微信用户 ID,无法确定收件人。请在「微信绑定」面板解绑后重新扫码。');
|
|
280
|
+
}
|
|
274
281
|
return { to, contextToken: '' };
|
|
275
282
|
}
|
|
276
283
|
|
|
@@ -607,7 +614,6 @@ export class WechatClawWorld implements World {
|
|
|
607
614
|
|
|
608
615
|
this.#auth = null;
|
|
609
616
|
this.#contextCount = 0;
|
|
610
|
-
this.#lastUserId = '';
|
|
611
617
|
this.#lastMessageAt = '';
|
|
612
618
|
this.#typingTickets.clear();
|
|
613
619
|
this.#lastError = '';
|
|
@@ -1119,6 +1125,37 @@ export class WechatClawWorld implements World {
|
|
|
1119
1125
|
});
|
|
1120
1126
|
}
|
|
1121
1127
|
|
|
1128
|
+
/**
|
|
1129
|
+
* 判断一条入站消息的发送者是不是绑定的微信本人。
|
|
1130
|
+
*
|
|
1131
|
+
* 正常绑定会带回 `ilink_user_id`,这里严格比对,不匹配就丢。
|
|
1132
|
+
* 极少数情况下服务端没给这个字段,则把**扫码绑定后第一条消息的发送者**认作本人并持久化
|
|
1133
|
+
* (首次信任:刚扫完码,第一个说话的就是操作者)。认领只发生一次,之后一律严格比对。
|
|
1134
|
+
*/
|
|
1135
|
+
#acceptSender(from: string): boolean {
|
|
1136
|
+
const auth = this.#auth;
|
|
1137
|
+
const owner = String(auth?.userId ?? '').trim();
|
|
1138
|
+
|
|
1139
|
+
if (owner) {
|
|
1140
|
+
if (from === owner) return true;
|
|
1141
|
+
this.#host?.log?.warn?.('丢弃非绑定用户发来的微信消息', { from: shortId(from) });
|
|
1142
|
+
return false;
|
|
1143
|
+
}
|
|
1144
|
+
|
|
1145
|
+
// 没有绑定记录,或绑定没带 userId:无法确定本人。
|
|
1146
|
+
if (!auth?.token) {
|
|
1147
|
+
this.#host?.log?.warn?.('未绑定状态下收到微信消息,已丢弃', { from: shortId(from) });
|
|
1148
|
+
return false;
|
|
1149
|
+
}
|
|
1150
|
+
|
|
1151
|
+
auth.userId = from;
|
|
1152
|
+
this.#host?.log?.warn?.('绑定记录缺少微信用户 ID,已把首个发送者认作本人', { userId: shortId(from) });
|
|
1153
|
+
void this.#store.saveAuth(auth).catch((err) => {
|
|
1154
|
+
this.#host?.log?.warn?.('保存微信用户 ID 失败', { error: errorText(err) });
|
|
1155
|
+
});
|
|
1156
|
+
return true;
|
|
1157
|
+
}
|
|
1158
|
+
|
|
1122
1159
|
async #handleInbound(driver: ILinkDriver, message: WeixinMessage): Promise<void> {
|
|
1123
1160
|
if (driver !== this.#driver) return;
|
|
1124
1161
|
// 自己发出去的消息不回到自己这里。
|
|
@@ -1127,6 +1164,11 @@ export class WechatClawWorld implements World {
|
|
|
1127
1164
|
if (!from) return;
|
|
1128
1165
|
if (this.#auth?.accountId && from === this.#auth.accountId) return;
|
|
1129
1166
|
|
|
1167
|
+
// 只接受绑定本人发来的消息。别的人(群成员、服务通知、陌生人)一律丢弃:
|
|
1168
|
+
// 收件人已经钉死在 auth.userId,这里再放行,非本人的内容就会进入上下文,
|
|
1169
|
+
// 并且「回复」的语义会被引到错误的人身上。
|
|
1170
|
+
if (!this.#acceptSender(from)) return;
|
|
1171
|
+
|
|
1130
1172
|
const contextToken = String(message?.context_token ?? '').trim();
|
|
1131
1173
|
if (contextToken) {
|
|
1132
1174
|
try {
|
|
@@ -1137,7 +1179,6 @@ export class WechatClawWorld implements World {
|
|
|
1137
1179
|
}
|
|
1138
1180
|
|
|
1139
1181
|
const atMs = messageTimeMs(message);
|
|
1140
|
-
this.#lastUserId = from;
|
|
1141
1182
|
this.#lastMessageAt = new Date(atMs).toISOString();
|
|
1142
1183
|
|
|
1143
1184
|
const maxBytes = Math.max(1, Number(this.#cfg.maxInboundMediaMb) || 20) * 1024 * 1024;
|