@zhin.js/core 1.1.34 → 1.1.37
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 +84 -142
- package/lib/built/ai-access.d.ts +36 -0
- package/lib/built/ai-access.js +46 -0
- package/lib/built/ai-outbound/extensions/onebot-keyboard.d.ts +2 -0
- package/lib/built/ai-outbound/extensions/onebot-keyboard.js +67 -0
- package/lib/built/ai-outbound/extensions/qq-message.d.ts +3 -0
- package/lib/built/ai-outbound/extensions/qq-message.js +23 -0
- package/lib/built/ai-outbound/index.d.ts +8 -0
- package/lib/built/ai-outbound/index.js +8 -0
- package/lib/built/ai-outbound/parse.d.ts +13 -0
- package/lib/built/ai-outbound/parse.js +104 -0
- package/lib/built/ai-outbound/plain-mention-rewrite.d.ts +6 -0
- package/lib/built/ai-outbound/plain-mention-rewrite.js +37 -0
- package/lib/built/ai-outbound/prompt.d.ts +11 -0
- package/lib/built/ai-outbound/prompt.js +44 -0
- package/lib/built/ai-outbound/resolve.d.ts +4 -0
- package/lib/built/ai-outbound/resolve.js +64 -0
- package/lib/built/ai-outbound/structured-detect.d.ts +3 -0
- package/lib/built/ai-outbound/structured-detect.js +6 -0
- package/lib/built/ai-outbound/types.d.ts +49 -0
- package/lib/built/ai-outbound/types.js +5 -0
- package/lib/built/ai-trigger.d.ts +12 -17
- package/lib/built/ai-trigger.js +39 -70
- package/lib/built/common-adapter-tools.d.ts +33 -29
- package/lib/built/common-adapter-tools.js +79 -67
- package/lib/built/generated-qrcode.d.ts +24 -0
- package/lib/built/generated-qrcode.js +45 -0
- package/lib/built/generic-segment-mapper.d.ts +4 -0
- package/lib/built/generic-segment-mapper.js +190 -0
- package/lib/built/html-segment-fallback.d.ts +2 -5
- package/lib/built/html-segment-fallback.js +0 -16
- package/lib/built/html-to-text.d.ts +0 -1
- package/lib/built/html-to-text.js +15 -15
- package/lib/built/interactive-segments/action.d.ts +17 -0
- package/lib/built/interactive-segments/action.js +69 -0
- package/lib/built/interactive-segments/button-spec.d.ts +10 -0
- package/lib/built/interactive-segments/button-spec.js +21 -0
- package/lib/built/interactive-segments/index.d.ts +6 -0
- package/lib/built/interactive-segments/index.js +6 -0
- package/lib/built/interactive-segments/keyboard-segment.d.ts +10 -0
- package/lib/built/interactive-segments/keyboard-segment.js +11 -0
- package/lib/built/interactive-segments/onebot-keyboard.d.ts +6 -0
- package/lib/built/interactive-segments/onebot-keyboard.js +49 -0
- package/lib/built/interactive-segments/resolve.d.ts +14 -0
- package/lib/built/interactive-segments/resolve.js +109 -0
- package/lib/built/interactive-segments/types.d.ts +45 -0
- package/lib/built/interactive-segments/types.js +9 -0
- package/lib/built/login-assist.d.ts +43 -16
- package/lib/built/login-assist.js +113 -11
- package/lib/built/message-enrich.d.ts +32 -0
- package/lib/built/message-enrich.js +67 -0
- package/lib/built/outbound-media-utils.d.ts +9 -0
- package/lib/built/outbound-media-utils.js +62 -0
- package/lib/built/queue-im-field-contract.d.ts +7 -2
- package/lib/built/queue-im-field-contract.js +13 -4
- package/lib/built/rich-segments/markdown-to-text.d.ts +3 -0
- package/lib/built/rich-segments/markdown-to-text.js +27 -0
- package/lib/built/roles.d.ts +4 -5
- package/lib/built/roles.js +4 -5
- package/lib/built/segment-contract/assert.d.ts +7 -0
- package/lib/built/segment-contract/assert.js +39 -0
- package/lib/built/segment-contract/delivery.d.ts +5 -0
- package/lib/built/segment-contract/delivery.js +40 -0
- package/lib/built/segment-contract/image.d.ts +5 -0
- package/lib/built/segment-contract/image.js +10 -0
- package/lib/built/segment-contract/index.d.ts +10 -0
- package/lib/built/segment-contract/index.js +9 -0
- package/lib/built/segment-contract/json-schema.d.ts +28 -0
- package/lib/built/segment-contract/json-schema.js +128 -0
- package/lib/built/segment-contract/media.d.ts +12 -0
- package/lib/built/segment-contract/media.js +22 -0
- package/lib/built/segment-contract/mention.d.ts +10 -0
- package/lib/built/segment-contract/mention.js +26 -0
- package/lib/built/segment-contract/preview.d.ts +3 -0
- package/lib/built/segment-contract/preview.js +159 -0
- package/lib/built/segment-contract/text.d.ts +7 -0
- package/lib/built/segment-contract/text.js +34 -0
- package/lib/built/segment-contract/types.d.ts +58 -0
- package/lib/built/segment-contract/types.js +1 -0
- package/lib/built/segment-contract/validate.d.ts +229 -0
- package/lib/built/segment-contract/validate.js +172 -0
- package/lib/built/tool-access.d.ts +5 -0
- package/lib/built/tool-access.js +17 -0
- package/lib/built/user-interaction.d.ts +30 -0
- package/lib/built/user-interaction.js +244 -0
- package/lib/component.d.ts +0 -1
- package/lib/component.js +30 -14
- package/lib/errors.d.ts +2 -3
- package/lib/errors.js +4 -5
- package/lib/feature/adapter.d.ts +2 -0
- package/lib/feature/adapter.js +2 -0
- package/lib/feature/command.d.ts +2 -0
- package/lib/feature/command.js +2 -0
- package/lib/feature/component.d.ts +2 -0
- package/lib/feature/component.js +2 -0
- package/lib/feature/handler.d.ts +48 -0
- package/lib/feature/handler.js +26 -0
- package/lib/feature/middleware.d.ts +2 -0
- package/lib/feature/middleware.js +2 -0
- package/lib/im-scene.d.ts +29 -0
- package/lib/im-scene.js +75 -0
- package/lib/im-session-id.d.ts +39 -0
- package/lib/im-session-id.js +47 -0
- package/lib/index.d.ts +29 -36
- package/lib/index.js +27 -41
- package/lib/jsx-dev-runtime.d.ts +0 -1
- package/lib/jsx-dev-runtime.js +0 -1
- package/lib/jsx-runtime.d.ts +1 -1
- package/lib/jsx-runtime.js +0 -1
- package/lib/jsx.d.ts +19 -22
- package/lib/jsx.js +0 -1
- package/lib/message.d.ts +17 -12
- package/lib/message.js +16 -13
- package/lib/models/system-log.d.ts +0 -3
- package/lib/models/system-log.js +1 -9
- package/lib/models/user.d.ts +0 -3
- package/lib/models/user.js +1 -8
- package/lib/notice.d.ts +16 -60
- package/lib/notice.js +1 -4
- package/lib/plugin-runtime/im/contracts.d.ts +191 -0
- package/lib/plugin-runtime/im/contracts.js +169 -0
- package/lib/plugin-runtime/im/conversation-runtime.d.ts +19 -0
- package/lib/plugin-runtime/im/conversation-runtime.js +312 -0
- package/lib/plugin-runtime/im/endpoint-runtime.d.ts +79 -0
- package/lib/plugin-runtime/im/endpoint-runtime.js +162 -0
- package/lib/plugin-runtime/im/im-runtime.d.ts +84 -0
- package/lib/plugin-runtime/im/im-runtime.js +201 -0
- package/lib/plugin-runtime/im/inbound-runtime.d.ts +31 -0
- package/lib/plugin-runtime/im/inbound-runtime.js +252 -0
- package/lib/plugin-runtime/im/index.d.ts +11 -0
- package/lib/plugin-runtime/im/index.js +9 -0
- package/lib/plugin-runtime/im/ingress-route.d.ts +10 -0
- package/lib/plugin-runtime/im/ingress-route.js +10 -0
- package/lib/plugin-runtime/im/interaction-runtime.d.ts +23 -0
- package/lib/plugin-runtime/im/interaction-runtime.js +181 -0
- package/lib/plugin-runtime/im/interactive-router.d.ts +17 -0
- package/lib/plugin-runtime/im/interactive-router.js +98 -0
- package/lib/plugin-runtime/im/login-assist-host.d.ts +6 -0
- package/lib/plugin-runtime/im/login-assist-host.js +6 -0
- package/lib/plugin-runtime/im/message-bus.d.ts +38 -0
- package/lib/plugin-runtime/im/message-bus.js +40 -0
- package/lib/plugin-runtime/im/message-dispatcher.d.ts +18 -0
- package/lib/plugin-runtime/im/message-dispatcher.js +107 -0
- package/lib/plugin-runtime/im/message-events.d.ts +26 -0
- package/lib/plugin-runtime/im/message-events.js +61 -0
- package/lib/plugin-runtime/im/outbound-delivery-runtime.d.ts +19 -0
- package/lib/plugin-runtime/im/outbound-delivery-runtime.js +165 -0
- package/lib/plugin-runtime/im/outbound-renderer.d.ts +7 -0
- package/lib/plugin-runtime/im/outbound-renderer.js +70 -0
- package/lib/plugin-runtime/im/outbound-segments.d.ts +71 -0
- package/lib/plugin-runtime/im/outbound-segments.js +219 -0
- package/lib/plugin-runtime/im/public-api.d.ts +6 -0
- package/lib/plugin-runtime/im/public-api.js +6 -0
- package/lib/plugin-runtime/im/runtime-middleware.d.ts +3 -0
- package/lib/plugin-runtime/im/runtime-middleware.js +13 -0
- package/lib/request.d.ts +17 -62
- package/lib/request.js +0 -4
- package/lib/side-event/base.d.ts +51 -0
- package/lib/side-event/base.js +30 -0
- package/lib/side-event/dispatch.d.ts +15 -0
- package/lib/side-event/dispatch.js +140 -0
- package/lib/side-event/index.d.ts +4 -0
- package/lib/side-event/index.js +4 -0
- package/lib/side-event/normalize.d.ts +38 -0
- package/lib/side-event/normalize.js +111 -0
- package/lib/side-event/types.d.ts +23 -0
- package/lib/side-event/types.js +55 -0
- package/lib/system-event.d.ts +14 -0
- package/lib/system-event.js +7 -0
- package/lib/types.d.ts +35 -193
- package/lib/types.js +0 -1
- package/lib/utils.d.ts +81 -6
- package/lib/utils.js +54 -25
- package/package.json +94 -16
- package/lib/adapter.d.ts +0 -96
- package/lib/adapter.d.ts.map +0 -1
- package/lib/adapter.js +0 -217
- package/lib/adapter.js.map +0 -1
- package/lib/agent-prompt.d.ts +0 -37
- package/lib/agent-prompt.d.ts.map +0 -1
- package/lib/agent-prompt.js +0 -2
- package/lib/agent-prompt.js.map +0 -1
- package/lib/bot.d.ts +0 -38
- package/lib/bot.d.ts.map +0 -1
- package/lib/bot.js +0 -2
- package/lib/bot.js.map +0 -1
- package/lib/built/adapter-process.d.ts +0 -43
- package/lib/built/adapter-process.d.ts.map +0 -1
- package/lib/built/adapter-process.js +0 -81
- package/lib/built/adapter-process.js.map +0 -1
- package/lib/built/agent-preset.d.ts +0 -65
- package/lib/built/agent-preset.d.ts.map +0 -1
- package/lib/built/agent-preset.js +0 -80
- package/lib/built/agent-preset.js.map +0 -1
- package/lib/built/ai-trigger.d.ts.map +0 -1
- package/lib/built/ai-trigger.js.map +0 -1
- package/lib/built/command.d.ts +0 -68
- package/lib/built/command.d.ts.map +0 -1
- package/lib/built/command.js +0 -92
- package/lib/built/command.js.map +0 -1
- package/lib/built/common-adapter-tools.d.ts.map +0 -1
- package/lib/built/common-adapter-tools.js.map +0 -1
- package/lib/built/component.d.ts +0 -69
- package/lib/built/component.d.ts.map +0 -1
- package/lib/built/component.js +0 -99
- package/lib/built/component.js.map +0 -1
- package/lib/built/config.d.ts +0 -99
- package/lib/built/config.d.ts.map +0 -1
- package/lib/built/config.js +0 -355
- package/lib/built/config.js.map +0 -1
- package/lib/built/cron.d.ts +0 -75
- package/lib/built/cron.d.ts.map +0 -1
- package/lib/built/cron.js +0 -122
- package/lib/built/cron.js.map +0 -1
- package/lib/built/database.d.ts +0 -66
- package/lib/built/database.d.ts.map +0 -1
- package/lib/built/database.js +0 -100
- package/lib/built/database.js.map +0 -1
- package/lib/built/dispatcher.d.ts +0 -139
- package/lib/built/dispatcher.d.ts.map +0 -1
- package/lib/built/dispatcher.js +0 -361
- package/lib/built/dispatcher.js.map +0 -1
- package/lib/built/html-segment-fallback.d.ts.map +0 -1
- package/lib/built/html-segment-fallback.js.map +0 -1
- package/lib/built/html-to-text.d.ts.map +0 -1
- package/lib/built/html-to-text.js.map +0 -1
- package/lib/built/inbound-runner.d.ts +0 -23
- package/lib/built/inbound-runner.d.ts.map +0 -1
- package/lib/built/inbound-runner.js +0 -37
- package/lib/built/inbound-runner.js.map +0 -1
- package/lib/built/login-assist.d.ts.map +0 -1
- package/lib/built/login-assist.js.map +0 -1
- package/lib/built/mcp-mesh-registrar.d.ts +0 -9
- package/lib/built/mcp-mesh-registrar.d.ts.map +0 -1
- package/lib/built/mcp-mesh-registrar.js +0 -17
- package/lib/built/mcp-mesh-registrar.js.map +0 -1
- package/lib/built/message-filter.d.ts +0 -177
- package/lib/built/message-filter.d.ts.map +0 -1
- package/lib/built/message-filter.js +0 -241
- package/lib/built/message-filter.js.map +0 -1
- package/lib/built/permission.d.ts +0 -55
- package/lib/built/permission.d.ts.map +0 -1
- package/lib/built/permission.js +0 -112
- package/lib/built/permission.js.map +0 -1
- package/lib/built/prepend-quote-context.d.ts +0 -35
- package/lib/built/prepend-quote-context.d.ts.map +0 -1
- package/lib/built/prepend-quote-context.js +0 -131
- package/lib/built/prepend-quote-context.js.map +0 -1
- package/lib/built/queue-im-field-contract.d.ts.map +0 -1
- package/lib/built/queue-im-field-contract.js.map +0 -1
- package/lib/built/roles.d.ts.map +0 -1
- package/lib/built/roles.js.map +0 -1
- package/lib/built/runtime-io.d.ts +0 -10
- package/lib/built/runtime-io.d.ts.map +0 -1
- package/lib/built/runtime-io.js +0 -68
- package/lib/built/runtime-io.js.map +0 -1
- package/lib/built/schema-feature.d.ts +0 -78
- package/lib/built/schema-feature.d.ts.map +0 -1
- package/lib/built/schema-feature.js +0 -132
- package/lib/built/schema-feature.js.map +0 -1
- package/lib/built/skill.d.ts +0 -121
- package/lib/built/skill.d.ts.map +0 -1
- package/lib/built/skill.js +0 -152
- package/lib/built/skill.js.map +0 -1
- package/lib/built/tool.d.ts +0 -150
- package/lib/built/tool.d.ts.map +0 -1
- package/lib/built/tool.js +0 -383
- package/lib/built/tool.js.map +0 -1
- package/lib/command.d.ts +0 -42
- package/lib/command.d.ts.map +0 -1
- package/lib/command.js +0 -75
- package/lib/command.js.map +0 -1
- package/lib/component.d.ts.map +0 -1
- package/lib/component.js.map +0 -1
- package/lib/errors.d.ts.map +0 -1
- package/lib/errors.js.map +0 -1
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/jsx-dev-runtime.d.ts.map +0 -1
- package/lib/jsx-dev-runtime.js.map +0 -1
- package/lib/jsx-runtime.d.ts.map +0 -1
- package/lib/jsx-runtime.js.map +0 -1
- package/lib/jsx.d.ts.map +0 -1
- package/lib/jsx.js.map +0 -1
- package/lib/message-quote.d.ts +0 -11
- package/lib/message-quote.d.ts.map +0 -1
- package/lib/message-quote.js +0 -91
- package/lib/message-quote.js.map +0 -1
- package/lib/message.d.ts.map +0 -1
- package/lib/message.js.map +0 -1
- package/lib/models/system-log.d.ts.map +0 -1
- package/lib/models/system-log.js.map +0 -1
- package/lib/models/user.d.ts.map +0 -1
- package/lib/models/user.js.map +0 -1
- package/lib/notice.d.ts.map +0 -1
- package/lib/notice.js.map +0 -1
- package/lib/plugin.d.ts +0 -258
- package/lib/plugin.d.ts.map +0 -1
- package/lib/plugin.js +0 -688
- package/lib/plugin.js.map +0 -1
- package/lib/prompt.d.ts +0 -118
- package/lib/prompt.d.ts.map +0 -1
- package/lib/prompt.js +0 -244
- package/lib/prompt.js.map +0 -1
- package/lib/request.d.ts.map +0 -1
- package/lib/request.js.map +0 -1
- package/lib/scheduler/scheduler.d.ts +0 -49
- package/lib/scheduler/scheduler.d.ts.map +0 -1
- package/lib/scheduler/scheduler.js +0 -352
- package/lib/scheduler/scheduler.js.map +0 -1
- package/lib/scheduler/types.d.ts +0 -71
- package/lib/scheduler/types.d.ts.map +0 -1
- package/lib/scheduler/types.js +0 -8
- package/lib/scheduler/types.js.map +0 -1
- package/lib/tool-zod.d.ts +0 -28
- package/lib/tool-zod.d.ts.map +0 -1
- package/lib/tool-zod.js +0 -98
- package/lib/tool-zod.js.map +0 -1
- package/lib/types-generator.d.ts +0 -6
- package/lib/types-generator.d.ts.map +0 -1
- package/lib/types-generator.js +0 -72
- package/lib/types-generator.js.map +0 -1
- package/lib/types.d.ts.map +0 -1
- package/lib/types.js.map +0 -1
- package/lib/utils.d.ts.map +0 -1
- package/lib/utils.js.map +0 -1
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Scene Management — 方法规范与 Tool 工厂
|
|
3
3
|
*
|
|
4
4
|
* 设计理念:
|
|
5
|
-
* 各 IM
|
|
5
|
+
* 各 IM 平台在适配器内自行实现场景治理方法(removeMember、muteMember 等),
|
|
6
6
|
* 并自行注册 Tool;平台说明使用包内 `skills/<adapter>/SKILL.md`。
|
|
7
7
|
*
|
|
8
8
|
* 使用方式(在各适配器 start 或注册方法中):
|
|
9
9
|
*
|
|
10
|
-
* import {
|
|
11
|
-
* const tools =
|
|
10
|
+
* import { createSceneManagementTools, SCENE_MANAGEMENT_SKILL_KEYWORDS, SCENE_MANAGEMENT_SKILL_TAGS } from 'zhin.js';
|
|
11
|
+
* const tools = createSceneManagementTools(this, this.name);
|
|
12
12
|
* tools.forEach(t => this.addTool(t));
|
|
13
13
|
* // 另:包内 skills/<name>/SKILL.md 供 Agent 发现
|
|
14
14
|
*/
|
|
15
|
-
export const
|
|
15
|
+
export const SCENE_MANAGEMENT_METHOD_SPECS = [
|
|
16
16
|
{
|
|
17
|
-
method: '
|
|
18
|
-
toolSuffix: '
|
|
19
|
-
description: '
|
|
17
|
+
method: 'removeMember',
|
|
18
|
+
toolSuffix: 'remove_member',
|
|
19
|
+
description: '将成员移出当前 IM 场景。适用于严重违规、广告号等需要移除的场景。如果只需要用户名而没有 user_id,请先调用 list_members 查询',
|
|
20
20
|
keywords: ['踢', 'kick', '移除', '踢出'],
|
|
21
|
-
|
|
21
|
+
permit: 'scene_admin',
|
|
22
22
|
extraParams: {
|
|
23
23
|
user_id: { type: 'string', description: '目标用户 ID(如果只有昵称,先用 list_members 查询获取)' },
|
|
24
24
|
},
|
|
@@ -29,7 +29,7 @@ export const GROUP_METHOD_SPECS = [
|
|
|
29
29
|
toolSuffix: 'mute_member',
|
|
30
30
|
description: '禁言或解除禁言群成员。适用于违规发言、刷屏、骚扰他人等需要临时限制发言的场景。duration 单位为秒,传 0 表示解除禁言。默认禁言 10 分钟(600秒)。如果只有昵称而没有 user_id,请先调用 list_members 查询',
|
|
31
31
|
keywords: ['禁言', 'mute', '静音', '解除禁言', '解禁', '闭嘴'],
|
|
32
|
-
|
|
32
|
+
permit: 'scene_admin',
|
|
33
33
|
extraParams: {
|
|
34
34
|
user_id: { type: 'string', description: '目标用户 ID(如果只有昵称,先用 list_members 查询获取)' },
|
|
35
35
|
duration: { type: 'number', description: '禁言时长(秒),0=解除禁言,默认600(10分钟)。常用值:60=1分钟, 600=10分钟, 3600=1小时, 86400=1天', default: 600 },
|
|
@@ -41,7 +41,7 @@ export const GROUP_METHOD_SPECS = [
|
|
|
41
41
|
toolSuffix: 'set_nickname',
|
|
42
42
|
description: '设置群成员的群昵称/名片。仅修改群内显示名称,不影响用户的全局昵称。如果只有昵称而没有 user_id,请先调用 list_members 查询',
|
|
43
43
|
keywords: ['昵称', '名片', 'nickname', 'card', '改名片'],
|
|
44
|
-
|
|
44
|
+
permit: 'scene_admin',
|
|
45
45
|
extraParams: {
|
|
46
46
|
user_id: { type: 'string', description: '目标用户 ID(如果只有昵称,先用 list_members 查询获取)' },
|
|
47
47
|
nickname: { type: 'string', description: '新的群昵称/名片' },
|
|
@@ -49,11 +49,11 @@ export const GROUP_METHOD_SPECS = [
|
|
|
49
49
|
extraRequired: ['user_id', 'nickname'],
|
|
50
50
|
},
|
|
51
51
|
{
|
|
52
|
-
method: '
|
|
53
|
-
toolSuffix: '
|
|
54
|
-
description: '
|
|
52
|
+
method: 'setModerator',
|
|
53
|
+
toolSuffix: 'set_moderator',
|
|
54
|
+
description: '设置或取消场景管理员。注意:此操作通常需要场景所有者权限。enable=true 为设置管理员,enable=false 为取消管理员。如果只有昵称而没有 user_id,请先调用 list_members 查询',
|
|
55
55
|
keywords: ['管理员', 'admin', '设置管理', '取消管理', '提升管理', '撤销管理'],
|
|
56
|
-
|
|
56
|
+
permit: 'scene_owner',
|
|
57
57
|
extraParams: {
|
|
58
58
|
user_id: { type: 'string', description: '目标用户 ID(如果只有昵称,先用 list_members 查询获取)' },
|
|
59
59
|
enable: { type: 'boolean', description: 'true=设置为管理员,false=取消管理员身份', default: true },
|
|
@@ -73,7 +73,7 @@ export const GROUP_METHOD_SPECS = [
|
|
|
73
73
|
toolSuffix: 'ban_member',
|
|
74
74
|
description: '永久封禁成员(拉入黑名单)。与踢人(kick)不同,封禁后该成员无法再加入群聊。适用于恶意用户、严重违规等需要永久禁止的场景。如果只有昵称而没有 user_id,请先调用 list_members 查询',
|
|
75
75
|
keywords: ['封禁', 'ban', '拉黑', '黑名单'],
|
|
76
|
-
|
|
76
|
+
permit: 'scene_admin',
|
|
77
77
|
extraParams: {
|
|
78
78
|
user_id: { type: 'string', description: '目标用户 ID(如果只有昵称,先用 list_members 查询获取)' },
|
|
79
79
|
reason: { type: 'string', description: '封禁原因(将记录在封禁日志中)' },
|
|
@@ -85,37 +85,37 @@ export const GROUP_METHOD_SPECS = [
|
|
|
85
85
|
toolSuffix: 'unban_member',
|
|
86
86
|
description: '解除封禁,将成员从黑名单中移除。解除后该成员可以重新加入群聊。如果只有昵称而没有 user_id,请先调用 list_members 查询',
|
|
87
87
|
keywords: ['解封', 'unban', '解除封禁', '移出黑名单'],
|
|
88
|
-
|
|
88
|
+
permit: 'scene_admin',
|
|
89
89
|
extraParams: {
|
|
90
90
|
user_id: { type: 'string', description: '目标用户 ID(如果只有昵称,先用 list_members 查询获取)' },
|
|
91
91
|
},
|
|
92
92
|
extraRequired: ['user_id'],
|
|
93
93
|
},
|
|
94
94
|
{
|
|
95
|
-
method: '
|
|
96
|
-
toolSuffix: '
|
|
97
|
-
description: '
|
|
95
|
+
method: 'renameScene',
|
|
96
|
+
toolSuffix: 'rename_scene',
|
|
97
|
+
description: '修改 IM 场景名称。修改后所有成员立即可见新名称',
|
|
98
98
|
keywords: ['群名', '改名', 'group name', '修改群名'],
|
|
99
|
-
|
|
99
|
+
permit: 'scene_admin',
|
|
100
100
|
extraParams: {
|
|
101
101
|
name: { type: 'string', description: '新群名称' },
|
|
102
102
|
},
|
|
103
103
|
extraRequired: ['name'],
|
|
104
104
|
},
|
|
105
105
|
{
|
|
106
|
-
method: '
|
|
107
|
-
toolSuffix: '
|
|
108
|
-
description: '
|
|
106
|
+
method: 'setSceneMuted',
|
|
107
|
+
toolSuffix: 'set_scene_muted',
|
|
108
|
+
description: '开启或关闭场景全员禁言。开启后除管理员外所有成员都无法发言。适用于紧急维护、重要通知、聊天秩序混乱等场景。enable=true 开启,enable=false 解除',
|
|
109
109
|
keywords: ['全员禁言', 'mute all', '全体禁言', '全体解禁'],
|
|
110
|
-
|
|
110
|
+
permit: 'scene_admin',
|
|
111
111
|
extraParams: {
|
|
112
112
|
enable: { type: 'boolean', description: 'true=开启全员禁言,false=解除全员禁言', default: true },
|
|
113
113
|
},
|
|
114
114
|
},
|
|
115
115
|
{
|
|
116
|
-
method: '
|
|
117
|
-
toolSuffix: '
|
|
118
|
-
description: '
|
|
116
|
+
method: 'getSceneInfo',
|
|
117
|
+
toolSuffix: 'get_scene_info',
|
|
118
|
+
description: '获取 IM 场景基本信息,包括名称、所有者、成员数量、创建时间等。用于了解场景概况',
|
|
119
119
|
keywords: ['群信息', 'group info', '群资料', '群详情'],
|
|
120
120
|
extraParams: {},
|
|
121
121
|
preExecutable: true,
|
|
@@ -124,42 +124,55 @@ export const GROUP_METHOD_SPECS = [
|
|
|
124
124
|
// ============================================================================
|
|
125
125
|
// Skill 常量(群管相关 SKILL.md 与文档可复用 keywords/tags)
|
|
126
126
|
// ============================================================================
|
|
127
|
-
export const
|
|
128
|
-
export const
|
|
129
|
-
'群管理', '踢人', '禁言', '封禁', '管理员', '群名',
|
|
127
|
+
export const SCENE_MANAGEMENT_SKILL_TAGS = ['scene', 'management', 'im', 'admin'];
|
|
128
|
+
export const SCENE_MANAGEMENT_SKILL_KEYWORDS = [
|
|
129
|
+
'场景治理', '群管理', '踢人', '禁言', '封禁', '管理员', '群名',
|
|
130
130
|
'成员', 'kick', 'mute', 'ban', 'admin', 'members',
|
|
131
131
|
];
|
|
132
|
-
export function
|
|
133
|
-
return
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
132
|
+
export function defaultScenePermitResolver(adapterPrefix) {
|
|
133
|
+
return (logicalPerm) => `platform(${adapterPrefix},${logicalPerm})`;
|
|
134
|
+
}
|
|
135
|
+
function resolveSpecPermit(specPerm, prefix, permitResolver) {
|
|
136
|
+
if (!specPerm)
|
|
137
|
+
return undefined;
|
|
138
|
+
const resolved = permitResolver(specPerm);
|
|
139
|
+
return resolved ? [resolved] : undefined;
|
|
140
|
+
}
|
|
141
|
+
export function createSceneManagementTools(adapter, prefix, options = {}) {
|
|
142
|
+
const permitResolver = options.permitResolver ?? defaultScenePermitResolver(prefix);
|
|
143
|
+
return createSceneManagementToolsRaw(adapter, prefix, (spec, prefix, execute) => {
|
|
144
|
+
const specPermissions = resolveSpecPermit(spec.permit, prefix, permitResolver);
|
|
145
|
+
return {
|
|
146
|
+
name: `${prefix}_${spec.toolSuffix}`,
|
|
147
|
+
description: `${spec.description} (${prefix})`,
|
|
148
|
+
parameters: {
|
|
149
|
+
type: 'object',
|
|
150
|
+
properties: {
|
|
151
|
+
endpoint_id: { type: 'string', description: 'Endpoint ID', contextKey: 'endpointKey' },
|
|
152
|
+
scene_id: { type: 'string', description: 'IM 场景 ID', contextKey: 'sceneId' },
|
|
153
|
+
...Object.fromEntries(Object.entries(spec.extraParams)),
|
|
154
|
+
},
|
|
155
|
+
required: ['endpoint_id', 'scene_id', ...(spec.extraRequired ?? [])],
|
|
142
156
|
},
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
}));
|
|
157
|
+
execute,
|
|
158
|
+
tags: ['scene', 'management', prefix],
|
|
159
|
+
keywords: spec.keywords,
|
|
160
|
+
...(specPermissions ? { permissions: specPermissions } : {}),
|
|
161
|
+
scopes: ['group', 'channel'],
|
|
162
|
+
preExecutable: spec.preExecutable,
|
|
163
|
+
};
|
|
164
|
+
});
|
|
152
165
|
}
|
|
153
|
-
export function
|
|
166
|
+
export function createSceneManagementToolsRaw(adapter, prefix, factory) {
|
|
154
167
|
const tools = [];
|
|
155
|
-
for (const spec of
|
|
168
|
+
for (const spec of SCENE_MANAGEMENT_METHOD_SPECS) {
|
|
156
169
|
const fn = adapter[spec.method];
|
|
157
170
|
if (typeof fn !== 'function')
|
|
158
171
|
continue;
|
|
159
172
|
const boundFn = fn.bind(adapter);
|
|
160
173
|
const execute = async (args) => {
|
|
161
|
-
const {
|
|
162
|
-
const methodArgs =
|
|
174
|
+
const { endpoint_id, scene_id, ...rest } = args;
|
|
175
|
+
const methodArgs = buildSceneMethodArgs(spec.method, endpoint_id, scene_id, rest);
|
|
163
176
|
return boundFn.apply(adapter, methodArgs);
|
|
164
177
|
};
|
|
165
178
|
tools.push(factory(spec, prefix, execute));
|
|
@@ -169,19 +182,18 @@ export function createGroupManagementToolsRaw(adapter, prefix, factory) {
|
|
|
169
182
|
// ============================================================================
|
|
170
183
|
// 参数映射(method → 有序参数列表)
|
|
171
184
|
// ============================================================================
|
|
172
|
-
export function
|
|
185
|
+
export function buildSceneMethodArgs(method, endpointKey, sceneId, rest) {
|
|
173
186
|
switch (method) {
|
|
174
|
-
case '
|
|
175
|
-
case 'muteMember': return [
|
|
176
|
-
case 'setMemberNickname': return [
|
|
177
|
-
case '
|
|
178
|
-
case 'listMembers': return [
|
|
179
|
-
case 'banMember': return [
|
|
180
|
-
case 'unbanMember': return [
|
|
181
|
-
case '
|
|
182
|
-
case '
|
|
183
|
-
case '
|
|
184
|
-
default: return [
|
|
187
|
+
case 'removeMember': return [endpointKey, sceneId, rest.user_id];
|
|
188
|
+
case 'muteMember': return [endpointKey, sceneId, rest.user_id, rest.duration ?? 600];
|
|
189
|
+
case 'setMemberNickname': return [endpointKey, sceneId, rest.user_id, rest.nickname];
|
|
190
|
+
case 'setModerator': return [endpointKey, sceneId, rest.user_id, rest.enable ?? true];
|
|
191
|
+
case 'listMembers': return [endpointKey, sceneId];
|
|
192
|
+
case 'banMember': return [endpointKey, sceneId, rest.user_id, rest.reason];
|
|
193
|
+
case 'unbanMember': return [endpointKey, sceneId, rest.user_id];
|
|
194
|
+
case 'renameScene': return [endpointKey, sceneId, rest.name];
|
|
195
|
+
case 'setSceneMuted': return [endpointKey, sceneId, rest.enable ?? true];
|
|
196
|
+
case 'getSceneInfo': return [endpointKey, sceneId];
|
|
197
|
+
default: return [endpointKey, sceneId, ...Object.values(rest)];
|
|
185
198
|
}
|
|
186
199
|
}
|
|
187
|
-
//# sourceMappingURL=common-adapter-tools.js.map
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export interface GenerateQrCodeOptions {
|
|
2
|
+
width?: number;
|
|
3
|
+
margin?: number;
|
|
4
|
+
errorCorrectionLevel?: 'L' | 'M' | 'Q' | 'H';
|
|
5
|
+
}
|
|
6
|
+
export interface PrintQrCodeTerminalOptions {
|
|
7
|
+
small?: boolean;
|
|
8
|
+
}
|
|
9
|
+
/** 二维码实例:一次 generate,多种输出 */
|
|
10
|
+
export declare class GeneratedQrCode {
|
|
11
|
+
#private;
|
|
12
|
+
private constructor();
|
|
13
|
+
static generate(text: string, options?: GenerateQrCodeOptions): Promise<GeneratedQrCode>;
|
|
14
|
+
/** data URL,含 `data:image/png;base64,...` 前缀 */
|
|
15
|
+
toDataUrl(): string;
|
|
16
|
+
/**
|
|
17
|
+
* encoding === 'base64' → 纯 base64 载荷(无 data: 前缀)
|
|
18
|
+
*/
|
|
19
|
+
toString(encoding: 'base64'): string;
|
|
20
|
+
/** 输出 ASCII 二维码到 process.stdout */
|
|
21
|
+
printToTerminal(options?: PrintQrCodeTerminalOptions): Promise<void>;
|
|
22
|
+
}
|
|
23
|
+
/** 便捷别名 */
|
|
24
|
+
export declare const generateQrCode: typeof GeneratedQrCode.generate;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import QRCode from 'qrcode';
|
|
2
|
+
/** 二维码实例:一次 generate,多种输出 */
|
|
3
|
+
export class GeneratedQrCode {
|
|
4
|
+
#text;
|
|
5
|
+
#dataUrl;
|
|
6
|
+
constructor(text, dataUrl) {
|
|
7
|
+
this.#text = text;
|
|
8
|
+
this.#dataUrl = dataUrl;
|
|
9
|
+
}
|
|
10
|
+
static async generate(text, options = {}) {
|
|
11
|
+
const dataUrl = await QRCode.toDataURL(text, {
|
|
12
|
+
width: options.width ?? 280,
|
|
13
|
+
margin: options.margin ?? 2,
|
|
14
|
+
errorCorrectionLevel: options.errorCorrectionLevel ?? 'M',
|
|
15
|
+
});
|
|
16
|
+
return new GeneratedQrCode(text, dataUrl);
|
|
17
|
+
}
|
|
18
|
+
/** data URL,含 `data:image/png;base64,...` 前缀 */
|
|
19
|
+
toDataUrl() {
|
|
20
|
+
return this.#dataUrl;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* encoding === 'base64' → 纯 base64 载荷(无 data: 前缀)
|
|
24
|
+
*/
|
|
25
|
+
toString(encoding) {
|
|
26
|
+
if (encoding !== 'base64') {
|
|
27
|
+
throw new Error(`GeneratedQrCode.toString: unsupported encoding "${encoding}"`);
|
|
28
|
+
}
|
|
29
|
+
const prefix = 'data:image/png;base64,';
|
|
30
|
+
if (!this.#dataUrl.startsWith(prefix)) {
|
|
31
|
+
throw new Error('GeneratedQrCode.toString: unexpected data URL format');
|
|
32
|
+
}
|
|
33
|
+
return this.#dataUrl.slice(prefix.length);
|
|
34
|
+
}
|
|
35
|
+
/** 输出 ASCII 二维码到 process.stdout */
|
|
36
|
+
async printToTerminal(options = {}) {
|
|
37
|
+
const terminalText = await QRCode.toString(this.#text, {
|
|
38
|
+
type: 'terminal',
|
|
39
|
+
small: options.small ?? true,
|
|
40
|
+
});
|
|
41
|
+
process.stdout.write(`${terminalText}\n`);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/** 便捷别名 */
|
|
45
|
+
export const generateQrCode = GeneratedQrCode.generate.bind(GeneratedQrCode);
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { MessageElement } from '../types.js';
|
|
2
|
+
import type { Segment } from './segment-contract/types.js';
|
|
3
|
+
/** wire 段数组 → canonical Segment[](包括所有媒体的 `data.media` 归一)。 */
|
|
4
|
+
export declare function toCanonicalSegments(content: readonly MessageElement[] | readonly unknown[]): Segment[];
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import { isMediaRef, readMentionTarget, } from './segment-contract/index.js';
|
|
2
|
+
function isRecord(value) {
|
|
3
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
4
|
+
}
|
|
5
|
+
function readPlatform(seg) {
|
|
6
|
+
const platform = seg.platform;
|
|
7
|
+
return platform && typeof platform === 'object' ? platform : undefined;
|
|
8
|
+
}
|
|
9
|
+
function normalizeMention(seg) {
|
|
10
|
+
const data = seg.data;
|
|
11
|
+
const target = readMentionTarget(data);
|
|
12
|
+
const name = typeof data.name === 'string' && data.name ? data.name : undefined;
|
|
13
|
+
const platform = readPlatform(seg);
|
|
14
|
+
return {
|
|
15
|
+
type: 'mention',
|
|
16
|
+
data: name ? { target, name } : { target },
|
|
17
|
+
...(platform ? { platform } : {}),
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
const MEDIA_SEGMENT_TYPES = new Set(['image', 'audio', 'video', 'file']);
|
|
21
|
+
function nonEmptyString(value) {
|
|
22
|
+
return typeof value === 'string' && value.trim() ? value : undefined;
|
|
23
|
+
}
|
|
24
|
+
function legacyMediaRef(data) {
|
|
25
|
+
if (isMediaRef(data.media))
|
|
26
|
+
return data.media;
|
|
27
|
+
const url = nonEmptyString(data.url) ?? nonEmptyString(data.href) ?? nonEmptyString(data.src);
|
|
28
|
+
const path = nonEmptyString(data.path) ?? nonEmptyString(data.file_path);
|
|
29
|
+
const base64 = nonEmptyString(data.base64);
|
|
30
|
+
const file = nonEmptyString(data.file) ?? nonEmptyString(data.file_id);
|
|
31
|
+
const value = url ?? path ?? base64 ?? file;
|
|
32
|
+
if (!value)
|
|
33
|
+
return undefined;
|
|
34
|
+
const kind = url ? 'url'
|
|
35
|
+
: path ? 'path'
|
|
36
|
+
: base64 ? 'base64'
|
|
37
|
+
: /^(?:[a-z][a-z0-9+.-]*:)?\/\//iu.test(value) ? 'url'
|
|
38
|
+
: /^(?:\.{1,2}\/|\/|~\/)/u.test(value) ? 'path'
|
|
39
|
+
: 'file';
|
|
40
|
+
const mimeType = nonEmptyString(data.mime_type) ?? nonEmptyString(data.mimeType);
|
|
41
|
+
// Legacy top-level fileName names the rendered file segment. Keep source
|
|
42
|
+
// metadata reserved for an explicit media object instead of duplicating it.
|
|
43
|
+
const fileName = nonEmptyString(data.media_file_name);
|
|
44
|
+
const size = typeof data.size === 'number' && Number.isFinite(data.size) ? data.size : undefined;
|
|
45
|
+
return {
|
|
46
|
+
kind,
|
|
47
|
+
value,
|
|
48
|
+
...(mimeType ? { mime_type: mimeType } : {}),
|
|
49
|
+
...(fileName ? { file_name: fileName } : {}),
|
|
50
|
+
...(size === undefined ? {} : { size }),
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* The sole ingress compatibility boundary for media. Adapters may emit their
|
|
55
|
+
* native `url`/`path`/`file` fields, but every consumer receives `data.media`.
|
|
56
|
+
*/
|
|
57
|
+
function normalizeMedia(seg) {
|
|
58
|
+
const data = seg.data;
|
|
59
|
+
const platform = readPlatform(seg);
|
|
60
|
+
const media = legacyMediaRef(data);
|
|
61
|
+
if (!media)
|
|
62
|
+
return seg;
|
|
63
|
+
const attributes = seg.type === 'image'
|
|
64
|
+
? { ...(typeof data.alt === 'string' ? { alt: data.alt } : {}) }
|
|
65
|
+
: seg.type === 'audio'
|
|
66
|
+
? { ...(typeof data.duration === 'number' ? { duration: data.duration } : {}) }
|
|
67
|
+
: seg.type === 'video'
|
|
68
|
+
? {
|
|
69
|
+
...(typeof data.duration === 'number' ? { duration: data.duration } : {}),
|
|
70
|
+
...(typeof data.alt === 'string' ? { alt: data.alt } : {}),
|
|
71
|
+
}
|
|
72
|
+
: {
|
|
73
|
+
...(nonEmptyString(data.name) ?? nonEmptyString(data.file_name) ?? nonEmptyString(data.fileName)
|
|
74
|
+
? { name: nonEmptyString(data.name) ?? nonEmptyString(data.file_name) ?? nonEmptyString(data.fileName) }
|
|
75
|
+
: {}),
|
|
76
|
+
};
|
|
77
|
+
return {
|
|
78
|
+
type: seg.type,
|
|
79
|
+
data: { media, ...attributes },
|
|
80
|
+
...(platform ? { platform } : {}),
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
function normalizeReply(seg) {
|
|
84
|
+
const data = seg.data;
|
|
85
|
+
const messageId = String(data.message_id ?? data.id ?? '').trim();
|
|
86
|
+
if (!messageId)
|
|
87
|
+
return seg;
|
|
88
|
+
return { type: 'reply', data: { message_id: messageId } };
|
|
89
|
+
}
|
|
90
|
+
function normalizeLink(seg) {
|
|
91
|
+
const data = seg.data;
|
|
92
|
+
const url = String(data.url ?? data.href ?? '').trim();
|
|
93
|
+
if (!url)
|
|
94
|
+
return seg;
|
|
95
|
+
const text = typeof data.text === 'string' && data.text ? data.text : undefined;
|
|
96
|
+
const platform = readPlatform(seg);
|
|
97
|
+
return {
|
|
98
|
+
type: 'link',
|
|
99
|
+
data: text ? { url, text } : { url },
|
|
100
|
+
...(platform ? { platform } : {}),
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
function normalizeForward(seg) {
|
|
104
|
+
const data = seg.data;
|
|
105
|
+
const forwardId = String(data.forward_id ?? data.id ?? data.resid ?? '').trim();
|
|
106
|
+
if (!forwardId)
|
|
107
|
+
return seg;
|
|
108
|
+
const title = typeof data.title === 'string' ? data.title : undefined;
|
|
109
|
+
const messages = Array.isArray(data.messages) ? data.messages : undefined;
|
|
110
|
+
const platform = { ...(readPlatform(seg) ?? {}) };
|
|
111
|
+
if (data.resid != null)
|
|
112
|
+
platform.resid = String(data.resid);
|
|
113
|
+
return {
|
|
114
|
+
type: 'forward',
|
|
115
|
+
data: {
|
|
116
|
+
forward_id: forwardId,
|
|
117
|
+
...(title ? { title } : {}),
|
|
118
|
+
...(messages ? { messages: messages } : {}),
|
|
119
|
+
},
|
|
120
|
+
...(Object.keys(platform).length ? { platform } : {}),
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
function isPlatformSticker(seg) {
|
|
124
|
+
if (seg.type !== 'sticker')
|
|
125
|
+
return false;
|
|
126
|
+
const data = seg.data;
|
|
127
|
+
return data.package_id != null
|
|
128
|
+
|| data.sticker_id != null
|
|
129
|
+
|| data.packageId != null
|
|
130
|
+
|| data.stickerId != null;
|
|
131
|
+
}
|
|
132
|
+
function normalizeFace(seg) {
|
|
133
|
+
if (isPlatformSticker(seg))
|
|
134
|
+
return seg;
|
|
135
|
+
const data = seg.data;
|
|
136
|
+
const rawId = data.id ?? data.face_id;
|
|
137
|
+
const name = typeof data.name === 'string'
|
|
138
|
+
? data.name
|
|
139
|
+
: typeof data.text === 'string'
|
|
140
|
+
? data.text
|
|
141
|
+
: undefined;
|
|
142
|
+
const platform = readPlatform(seg);
|
|
143
|
+
return {
|
|
144
|
+
type: 'face',
|
|
145
|
+
data: {
|
|
146
|
+
...(rawId != null ? { id: rawId } : {}),
|
|
147
|
+
...(name ? { name } : {}),
|
|
148
|
+
},
|
|
149
|
+
...(platform ? { platform } : {}),
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
function normalizeMarkdown(seg) {
|
|
153
|
+
const data = seg.data;
|
|
154
|
+
const content = typeof data.content === 'string'
|
|
155
|
+
? data.content
|
|
156
|
+
: typeof data.text === 'string'
|
|
157
|
+
? data.text
|
|
158
|
+
: '';
|
|
159
|
+
return { type: 'markdown', data: { content } };
|
|
160
|
+
}
|
|
161
|
+
function normalizeSegment(seg) {
|
|
162
|
+
if (seg.type === 'at' || seg.type === 'mention')
|
|
163
|
+
return normalizeMention(seg);
|
|
164
|
+
if (MEDIA_SEGMENT_TYPES.has(seg.type))
|
|
165
|
+
return normalizeMedia(seg);
|
|
166
|
+
if (seg.type === 'reply')
|
|
167
|
+
return normalizeReply(seg);
|
|
168
|
+
if (seg.type === 'forward')
|
|
169
|
+
return normalizeForward(seg);
|
|
170
|
+
if (seg.type === 'sticker' && isPlatformSticker(seg))
|
|
171
|
+
return seg;
|
|
172
|
+
if (seg.type === 'face' || seg.type === 'sticker' || seg.type === 'emoji')
|
|
173
|
+
return normalizeFace(seg);
|
|
174
|
+
if (seg.type === 'link')
|
|
175
|
+
return normalizeLink(seg);
|
|
176
|
+
if (seg.type === 'markdown')
|
|
177
|
+
return normalizeMarkdown(seg);
|
|
178
|
+
return seg;
|
|
179
|
+
}
|
|
180
|
+
function asMessageSegments(content) {
|
|
181
|
+
return content.map((item) => {
|
|
182
|
+
if (typeof item === 'string')
|
|
183
|
+
return { type: 'text', data: { text: item } };
|
|
184
|
+
return item;
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
/** wire 段数组 → canonical Segment[](包括所有媒体的 `data.media` 归一)。 */
|
|
188
|
+
export function toCanonicalSegments(content) {
|
|
189
|
+
return asMessageSegments(content).map((seg) => normalizeSegment(seg));
|
|
190
|
+
}
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Convert unresolved `html` segments to portable text content.
|
|
3
|
+
* Canonical outbound rendering owns when this fallback is applied.
|
|
3
4
|
*/
|
|
4
|
-
import type { Plugin } from '../plugin.js';
|
|
5
5
|
import type { SendContent } from '../types.js';
|
|
6
6
|
export declare function coerceHtmlSegmentsToText(content: SendContent): SendContent;
|
|
7
|
-
/** 注册链尾 before.sendMessage:将未转换的 html 段降级为 text */
|
|
8
|
-
export declare function registerHtmlSegmentFallback(plugin: Plugin): () => void;
|
|
9
|
-
//# sourceMappingURL=html-segment-fallback.d.ts.map
|
|
@@ -32,19 +32,3 @@ export function coerceHtmlSegmentsToText(content) {
|
|
|
32
32
|
return out[0];
|
|
33
33
|
return out;
|
|
34
34
|
}
|
|
35
|
-
/** 注册链尾 before.sendMessage:将未转换的 html 段降级为 text */
|
|
36
|
-
export function registerHtmlSegmentFallback(plugin) {
|
|
37
|
-
const handler = (options) => {
|
|
38
|
-
const content = options.content;
|
|
39
|
-
if (content == null)
|
|
40
|
-
return options;
|
|
41
|
-
const items = asArray(content);
|
|
42
|
-
if (!items.some((item) => typeof item !== 'string' && item?.type === 'html')) {
|
|
43
|
-
return options;
|
|
44
|
-
}
|
|
45
|
-
return { ...options, content: coerceHtmlSegmentsToText(content) };
|
|
46
|
-
};
|
|
47
|
-
plugin.root.on('before.sendMessage', handler);
|
|
48
|
-
return () => plugin.root.off('before.sendMessage', handler);
|
|
49
|
-
}
|
|
50
|
-
//# sourceMappingURL=html-segment-fallback.js.map
|
|
@@ -14,4 +14,3 @@ export declare function htmlToPlainTextWithBlockBreaks(html: string, options?: H
|
|
|
14
14
|
* HTML 卡片出站回退:块级换行 + 语义标题轻量 markdown 前缀。
|
|
15
15
|
*/
|
|
16
16
|
export declare function htmlToFallbackText(html: string, options?: HtmlToPlainTextOptions): string;
|
|
17
|
-
//# sourceMappingURL=html-to-text.d.ts.map
|
|
@@ -79,20 +79,21 @@ function stripRemainingTags(html) {
|
|
|
79
79
|
return out;
|
|
80
80
|
}
|
|
81
81
|
function decodeCommonEntities(text) {
|
|
82
|
-
return text
|
|
83
|
-
.
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
82
|
+
return text.replace(/&(#x[0-9a-fA-F]+|#\d+|nbsp|amp|lt|gt|quot|apos);/gi, (entity) => {
|
|
83
|
+
const key = entity.slice(1, -1).toLowerCase();
|
|
84
|
+
if (key === 'nbsp')
|
|
85
|
+
return ' ';
|
|
86
|
+
if (key === 'amp')
|
|
87
|
+
return '&';
|
|
88
|
+
if (key === 'lt')
|
|
89
|
+
return '<';
|
|
90
|
+
if (key === 'gt')
|
|
91
|
+
return '>';
|
|
92
|
+
if (key === 'quot')
|
|
93
|
+
return '"';
|
|
94
|
+
if (key === 'apos')
|
|
95
|
+
return "'";
|
|
96
|
+
const n = key.startsWith('#x') ? parseInt(key.slice(2), 16) : Number(key.slice(1));
|
|
96
97
|
return Number.isFinite(n) && n >= 0 && n <= 0x10ffff ? String.fromCodePoint(n) : '';
|
|
97
98
|
});
|
|
98
99
|
}
|
|
@@ -163,4 +164,3 @@ export function htmlToFallbackText(html, options) {
|
|
|
163
164
|
.replace(/\n{3,}/g, '\n\n')
|
|
164
165
|
.trim();
|
|
165
166
|
}
|
|
166
|
-
//# sourceMappingURL=html-to-text.js.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Message } from '../../message.js';
|
|
2
|
+
import type { MessageElement } from '../../types.js';
|
|
3
|
+
import { type ActionSegmentData } from './types.js';
|
|
4
|
+
export declare function actionSegment(data: ActionSegmentData): MessageElement;
|
|
5
|
+
export declare function getActionFromMessage(message: Message<any>): ActionSegmentData | undefined;
|
|
6
|
+
/** 入站互动 action(按钮点击等),不应计入用户发言/消息统计 */
|
|
7
|
+
export declare function isActionMessage(message: Message<any>): boolean;
|
|
8
|
+
/** 去掉 @bot、XML at 段、首尾空白(QQ 指令预填文本归一化) */
|
|
9
|
+
export declare function stripInteractiveCommandText(raw: string): string;
|
|
10
|
+
/** 从文本降级输入解析 payload(需在 active session 的 fallback.map 中查找) */
|
|
11
|
+
export declare function resolveTextFallbackPayload(raw: string, map: Record<string, string>): string | undefined;
|
|
12
|
+
/**
|
|
13
|
+
* 从用户文本入站解析 interactive payload:
|
|
14
|
+
* 归一化 → 直接匹配 prefix:session:id → fallback 数字映射
|
|
15
|
+
*/
|
|
16
|
+
export declare function resolvePayloadFromText(raw: string, map?: Record<string, string>): string | undefined;
|
|
17
|
+
export declare function formatActionAsRaw(data: ActionSegmentData): string;
|