@zhin.js/adapter-icqq 1.0.71 → 1.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 +1216 -52
- package/PERMITS.md +24 -0
- package/README.md +123 -429
- package/adapters/icqq/index.js +31 -0
- package/adapters/icqq/index.ts +42 -0
- package/agents/icqq/agent.json +20 -0
- package/agents/icqq/boundaries.md +3 -0
- package/agents/icqq/conventions.md +3 -0
- package/agents/icqq/skills/icqq-directory/SKILL.md +20 -0
- package/agents/icqq/skills/icqq-directory/tools/friend_list/index.js +19 -0
- package/agents/icqq/skills/icqq-directory/tools/friend_list/index.ts +19 -0
- package/agents/icqq/skills/icqq-directory/tools/group_list/index.js +20 -0
- package/agents/icqq/skills/icqq-directory/tools/group_list/index.ts +20 -0
- package/agents/icqq/skills/icqq-directory/tools/group_member_info/index.js +26 -0
- package/agents/icqq/skills/icqq-directory/tools/group_member_info/index.ts +28 -0
- package/agents/icqq/skills/icqq-directory/tools/user_info/index.js +15 -0
- package/agents/icqq/skills/icqq-directory/tools/user_info/index.ts +14 -0
- package/agents/icqq/skills/icqq-group-admin/SKILL.md +25 -0
- package/agents/icqq/skills/icqq-group-admin/tools/announce/index.js +18 -0
- package/agents/icqq/skills/icqq-group-admin/tools/announce/index.ts +17 -0
- package/agents/icqq/skills/icqq-group-admin/tools/essence/index.js +24 -0
- package/agents/icqq/skills/icqq-group-admin/tools/essence/index.ts +22 -0
- package/agents/icqq/skills/icqq-group-admin/tools/group_invite/index.js +23 -0
- package/agents/icqq/skills/icqq-group-admin/tools/group_invite/index.ts +20 -0
- package/agents/icqq/skills/icqq-group-admin/tools/group_kick/index.js +27 -0
- package/agents/icqq/skills/icqq-group-admin/tools/group_kick/index.ts +23 -0
- package/agents/icqq/skills/icqq-group-admin/tools/set_anonymous/index.js +23 -0
- package/agents/icqq/skills/icqq-group-admin/tools/set_anonymous/index.ts +21 -0
- package/agents/icqq/skills/icqq-group-admin/tools/set_mute/index.js +25 -0
- package/agents/icqq/skills/icqq-group-admin/tools/set_mute/index.ts +22 -0
- package/agents/icqq/skills/icqq-group-admin/tools/set_title/index.js +26 -0
- package/agents/icqq/skills/icqq-group-admin/tools/set_title/index.ts +23 -0
- package/agents/icqq/skills/icqq-group-state/SKILL.md +17 -0
- package/agents/icqq/skills/icqq-group-state/tools/group_files/index.js +24 -0
- package/agents/icqq/skills/icqq-group-state/tools/group_files/index.ts +22 -0
- package/agents/icqq/skills/icqq-group-state/tools/list_muted/index.js +18 -0
- package/agents/icqq/skills/icqq-group-state/tools/list_muted/index.ts +17 -0
- package/agents/icqq/skills/icqq-interaction/SKILL.md +19 -0
- package/agents/icqq/skills/icqq-interaction/tools/group_sign/index.js +20 -0
- package/agents/icqq/skills/icqq-interaction/tools/group_sign/index.ts +18 -0
- package/agents/icqq/skills/icqq-interaction/tools/poke/index.js +17 -0
- package/agents/icqq/skills/icqq-interaction/tools/poke/index.ts +16 -0
- package/agents/icqq/skills/icqq-interaction/tools/send_user_like/index.js +26 -0
- package/agents/icqq/skills/icqq-interaction/tools/send_user_like/index.ts +22 -0
- package/agents/icqq/system.md +3 -0
- package/commands/icqq/endpoint/add/[[id]]/index.js +3 -0
- package/commands/icqq/endpoint/add/[[id]]/index.ts +3 -0
- package/commands/icqq/endpoint/definition.js +31 -0
- package/commands/icqq/endpoint/definition.ts +32 -0
- package/commands/icqq/endpoint/list/index.js +3 -0
- package/commands/icqq/endpoint/list/index.ts +3 -0
- package/commands/icqq/endpoint/remove/[id]/index.js +3 -0
- package/commands/icqq/endpoint/remove/[id]/index.ts +3 -0
- package/lib/client.d.ts +19 -0
- package/lib/client.js +3 -0
- package/lib/content-resolver.d.ts +10 -0
- package/lib/content-resolver.js +98 -0
- package/lib/cq-message.d.ts +14 -0
- package/lib/cq-message.js +106 -0
- package/lib/endpoint.d.ts +30 -0
- package/lib/endpoint.js +1003 -0
- package/lib/forward-msg.d.ts +6 -0
- package/lib/forward-msg.js +107 -0
- package/lib/icqq-guild.d.ts +57 -0
- package/lib/icqq-guild.js +109 -0
- package/lib/icqq-inbound.d.ts +165 -0
- package/lib/icqq-inbound.js +651 -0
- package/lib/icqq-inbox.d.ts +25 -0
- package/lib/icqq-inbox.js +129 -0
- package/lib/icqq-login-assist.d.ts +27 -0
- package/lib/icqq-login-assist.js +109 -0
- package/lib/icqq-runtime-state.d.ts +1 -0
- package/lib/icqq-runtime-state.js +6 -0
- package/lib/index.d.ts +5 -18
- package/lib/index.js +5 -124
- package/lib/outbound-media.d.ts +14 -0
- package/lib/outbound-media.js +76 -0
- package/lib/protocol.d.ts +258 -0
- package/lib/protocol.js +422 -0
- package/lib/types.d.ts +33 -13
- package/lib/types.js +0 -1
- package/package.json +86 -32
- package/plugin.js +19 -0
- package/prompt-sections/platform/index.js +16 -0
- package/prompt-sections/platform/index.ts +16 -0
- package/schema.json +168 -0
- package/src/client.ts +29 -0
- package/src/content-resolver.ts +131 -0
- package/src/cq-message.ts +113 -0
- package/src/endpoint.ts +1084 -0
- package/src/forward-msg.ts +112 -0
- package/src/icqq-guild.ts +154 -0
- package/src/icqq-inbound.ts +814 -0
- package/src/icqq-inbox.ts +147 -0
- package/src/icqq-login-assist.ts +132 -0
- package/src/icqq-runtime-state.ts +7 -0
- package/src/index.ts +30 -149
- package/src/outbound-media.ts +103 -0
- package/src/protocol.ts +551 -0
- package/src/types.ts +35 -13
- package/LICENSE +0 -21
- package/client/ICQQManagement.tsx +0 -139
- package/client/LoginAssistPanel.tsx +0 -293
- package/client/index.tsx +0 -11
- package/client/tsconfig.json +0 -7
- package/client/utils/api.ts +0 -20
- package/dist/index.js +0 -1
- package/lib/adapter.d.ts +0 -34
- package/lib/adapter.d.ts.map +0 -1
- package/lib/adapter.js +0 -396
- package/lib/adapter.js.map +0 -1
- package/lib/bot.d.ts +0 -46
- package/lib/bot.d.ts.map +0 -1
- package/lib/bot.js +0 -457
- package/lib/bot.js.map +0 -1
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/types.d.ts.map +0 -1
- package/lib/types.js.map +0 -1
- package/skills/icqq/SKILL.md +0 -22
- package/src/adapter.ts +0 -448
- package/src/bot.ts +0 -521
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/** ICQQ 历史文本视图 → canonical MessageSegment。出站只使用原生 Sendable。 */
|
|
2
|
+
import { isMediaRef, type MediaRef } from '@zhin.js/im-contract';
|
|
3
|
+
import type { MessageSegment } from "zhin.js";
|
|
4
|
+
|
|
5
|
+
const MAX_CQ_PARSE_LEN = 256_000;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* CQ 媒体参数 / 入站元素媒体值 → canonical MediaRef:
|
|
9
|
+
* `base64://` → base64;http(s) → url;本机路径 → path;其余视为平台不透明引用(file)。
|
|
10
|
+
*/
|
|
11
|
+
export function icqqMediaRefFromString(value: string): MediaRef {
|
|
12
|
+
if (value.startsWith("base64://")) {
|
|
13
|
+
return { kind: "base64", value: value.slice("base64://".length) };
|
|
14
|
+
}
|
|
15
|
+
if (value.startsWith("http://") || value.startsWith("https://")) {
|
|
16
|
+
return { kind: "url", value };
|
|
17
|
+
}
|
|
18
|
+
if (value.startsWith("/") || /^[a-zA-Z]:[\\/]/.test(value)) {
|
|
19
|
+
return { kind: "path", value };
|
|
20
|
+
}
|
|
21
|
+
return { kind: "file", value };
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* canonical MediaRef(`data.media`,唯一媒体来源)→ ICQQ native
|
|
26
|
+
* element 的 file 参数。base64 使用 ICQQ 原生支持的 `base64://` 前缀。
|
|
27
|
+
*/
|
|
28
|
+
export function resolveIcqqMediaFile(
|
|
29
|
+
data: Record<string, unknown> | undefined,
|
|
30
|
+
): string | undefined {
|
|
31
|
+
const media = data?.media;
|
|
32
|
+
if (!isMediaRef(media)) return undefined;
|
|
33
|
+
if (media.kind === "base64") {
|
|
34
|
+
return media.value.startsWith("base64://") ? media.value : `base64://${media.value}`;
|
|
35
|
+
}
|
|
36
|
+
return media.value;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function pushCqSegment(segments: MessageSegment[], type: string, arg: string): void {
|
|
40
|
+
switch (type) {
|
|
41
|
+
case "face":
|
|
42
|
+
segments.push({ type: "face", data: { id: Number(arg) } });
|
|
43
|
+
break;
|
|
44
|
+
case "image":
|
|
45
|
+
segments.push({ type: "image", data: { media: icqqMediaRefFromString(arg) } });
|
|
46
|
+
break;
|
|
47
|
+
case "at":
|
|
48
|
+
if (arg === "all") {
|
|
49
|
+
segments.push({ type: "at", data: { qq: "all" } });
|
|
50
|
+
} else {
|
|
51
|
+
segments.push({ type: "at", data: { qq: arg } });
|
|
52
|
+
}
|
|
53
|
+
break;
|
|
54
|
+
case "dice":
|
|
55
|
+
segments.push({ type: "dice", data: {} });
|
|
56
|
+
break;
|
|
57
|
+
case "rps":
|
|
58
|
+
segments.push({ type: "rps", data: {} });
|
|
59
|
+
break;
|
|
60
|
+
case "record":
|
|
61
|
+
case "audio":
|
|
62
|
+
segments.push({ type: "audio", data: { media: icqqMediaRefFromString(arg) } });
|
|
63
|
+
break;
|
|
64
|
+
case "video":
|
|
65
|
+
segments.push({ type: "video", data: { media: icqqMediaRefFromString(arg) } });
|
|
66
|
+
break;
|
|
67
|
+
case "reply":
|
|
68
|
+
segments.push({ type: "reply", data: { message_id: arg } });
|
|
69
|
+
break;
|
|
70
|
+
case "json":
|
|
71
|
+
segments.push({ type: "json", data: { text: arg } });
|
|
72
|
+
break;
|
|
73
|
+
default:
|
|
74
|
+
segments.push({ type, data: { text: `[${type}:${arg}]` } });
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function parseCqMessage(raw: string): MessageSegment[] {
|
|
80
|
+
const text = raw.length > MAX_CQ_PARSE_LEN ? raw.slice(0, MAX_CQ_PARSE_LEN) : raw;
|
|
81
|
+
const segments: MessageSegment[] = [];
|
|
82
|
+
let i = 0;
|
|
83
|
+
|
|
84
|
+
while (i < text.length) {
|
|
85
|
+
if (text[i] !== "[") {
|
|
86
|
+
const next = text.indexOf("[", i);
|
|
87
|
+
const chunk = next === -1 ? text.slice(i) : text.slice(i, next);
|
|
88
|
+
if (chunk) segments.push({ type: "text", data: { text: chunk } });
|
|
89
|
+
if (next === -1) break;
|
|
90
|
+
i = next;
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const close = text.indexOf("]", i + 1);
|
|
95
|
+
if (close === -1) {
|
|
96
|
+
segments.push({ type: "text", data: { text: text.slice(i) } });
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const inner = text.slice(i + 1, close);
|
|
101
|
+
const colon = inner.indexOf(":");
|
|
102
|
+
const type = (colon === -1 ? inner : inner.slice(0, colon)).trim().toLowerCase();
|
|
103
|
+
const arg = colon === -1 ? "" : inner.slice(colon + 1);
|
|
104
|
+
if (/^[a-z_]+$/.test(type)) {
|
|
105
|
+
pushCqSegment(segments, type, arg);
|
|
106
|
+
} else {
|
|
107
|
+
segments.push({ type: "text", data: { text: text.slice(i, close + 1) } });
|
|
108
|
+
}
|
|
109
|
+
i = close + 1;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return segments.length ? segments : [{ type: "text", data: { text: raw } }];
|
|
113
|
+
}
|