@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
package/lib/notice.d.ts
CHANGED
|
@@ -1,81 +1,37 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type {
|
|
1
|
+
import type { NoticeKind } from './side-event/types.js';
|
|
2
|
+
import type { SideEventBase } from './side-event/base.js';
|
|
3
|
+
export type { NoticeKind, ComposedNoticeName } from './side-event/types.js';
|
|
4
|
+
export type { SideEventBase } from './side-event/base.js';
|
|
5
|
+
export { composeSideEventName, formatSideEventName, matchesSideEventName, parseSideEventName, sideEventSendChannel, } from './side-event/base.js';
|
|
3
6
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* 常见 IM 通知事件分类:
|
|
7
|
-
* - group_member_increase: 群成员增加(入群)
|
|
8
|
-
* - group_member_decrease: 群成员减少(退群/被踢)
|
|
9
|
-
* - group_admin_change: 群管理员变动
|
|
10
|
-
* - group_ban: 群禁言
|
|
11
|
-
* - group_recall: 群消息撤回
|
|
12
|
-
* - friend_recall: 好友消息撤回
|
|
13
|
-
* - friend_add: 新增好友
|
|
14
|
-
* - group_poke: 群戳一戳
|
|
15
|
-
* - friend_poke: 好友戳一戳
|
|
16
|
-
* - group_transfer: 群转让
|
|
17
|
-
*
|
|
18
|
-
* 适配器可自行扩展更多子类型
|
|
19
|
-
*/
|
|
20
|
-
export type NoticeType = 'group_member_increase' | 'group_member_decrease' | 'group_admin_change' | 'group_ban' | 'group_recall' | 'friend_recall' | 'friend_add' | 'group_poke' | 'friend_poke' | 'group_transfer' | (string & {});
|
|
21
|
-
/**
|
|
22
|
-
* 通知频道信息
|
|
23
|
-
*/
|
|
24
|
-
export interface NoticeChannel {
|
|
25
|
-
id: string;
|
|
26
|
-
type: 'group' | 'private' | 'channel';
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* 通知基础结构
|
|
30
|
-
*
|
|
31
|
-
* 与 MessageBase 同构设计,所有通知共享以下字段。
|
|
32
|
-
* 适配器通过 `Notice.from(raw, base)` 合并平台原始数据和标准字段。
|
|
7
|
+
* 通知基础结构 — 继承 SideEventBase。
|
|
33
8
|
*
|
|
34
9
|
* @example
|
|
35
10
|
* ```typescript
|
|
36
|
-
* // 适配器中格式化通知
|
|
37
11
|
* const notice = Notice.from(rawEvent, {
|
|
38
12
|
* $id: rawEvent.id,
|
|
39
13
|
* $adapter: 'icqq',
|
|
40
|
-
* $
|
|
41
|
-
* $type: '
|
|
42
|
-
* $
|
|
43
|
-
* $
|
|
44
|
-
* $
|
|
14
|
+
* $endpoint: endpointKey,
|
|
15
|
+
* $type: 'notice',
|
|
16
|
+
* $scene_id: groupId,
|
|
17
|
+
* $scene_type: 'group',
|
|
18
|
+
* $sub_type: 'member_decrease',
|
|
19
|
+
* $actor: { id: operatorId, name: '管理员' },
|
|
45
20
|
* $target: { id: userId, name: '被踢者' },
|
|
46
21
|
* $timestamp: Date.now(),
|
|
47
22
|
* });
|
|
23
|
+
* // formatSideEventName(notice) === 'notice.group.member_decrease'
|
|
48
24
|
* this.adapter.emit('notice.receive', notice);
|
|
49
25
|
* ```
|
|
50
26
|
*/
|
|
51
|
-
export interface NoticeBase {
|
|
52
|
-
|
|
53
|
-
$
|
|
54
|
-
/** 适配器名称 */
|
|
55
|
-
$adapter: keyof Adapters;
|
|
56
|
-
/** Bot 名称 */
|
|
57
|
-
$bot: string;
|
|
58
|
-
/** 通知类型 */
|
|
59
|
-
$type: NoticeType;
|
|
60
|
-
/** 通知子类型(如 leave/kick、set/unset) */
|
|
61
|
-
$subType?: string;
|
|
62
|
-
/** 通知发生的频道/群/会话 */
|
|
63
|
-
$channel: NoticeChannel;
|
|
64
|
-
/** 操作者信息(如管理员) */
|
|
65
|
-
$operator?: MessageSender;
|
|
66
|
-
/** 被操作目标信息(如被踢的成员) */
|
|
67
|
-
$target?: MessageSender;
|
|
68
|
-
/** 通知时间戳 */
|
|
69
|
-
$timestamp: number;
|
|
27
|
+
export interface NoticeBase extends SideEventBase {
|
|
28
|
+
$adapter: string;
|
|
29
|
+
$type: NoticeKind;
|
|
70
30
|
}
|
|
71
31
|
/**
|
|
72
32
|
* 完整通知类型,支持平台原始数据扩展
|
|
73
33
|
*/
|
|
74
34
|
export type Notice<T extends object = {}> = NoticeBase & T;
|
|
75
35
|
export declare namespace Notice {
|
|
76
|
-
/**
|
|
77
|
-
* 工具方法:合并自定义字段与基础通知结构
|
|
78
|
-
*/
|
|
79
36
|
function from<T extends object>(input: T, format: NoticeBase): Notice<T>;
|
|
80
37
|
}
|
|
81
|
-
//# sourceMappingURL=notice.d.ts.map
|
package/lib/notice.js
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
|
+
export { composeSideEventName, formatSideEventName, matchesSideEventName, parseSideEventName, sideEventSendChannel, } from './side-event/base.js';
|
|
1
2
|
export var Notice;
|
|
2
3
|
(function (Notice) {
|
|
3
|
-
/**
|
|
4
|
-
* 工具方法:合并自定义字段与基础通知结构
|
|
5
|
-
*/
|
|
6
4
|
function from(input, format) {
|
|
7
5
|
return Object.assign(input, format);
|
|
8
6
|
}
|
|
9
7
|
Notice.from = from;
|
|
10
8
|
})(Notice || (Notice = {}));
|
|
11
|
-
//# sourceMappingURL=notice.js.map
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import type { PluginId } from '@zhin.js/plugin-runtime';
|
|
2
|
+
import type { ConversationRef, DeliveryReceipt, MessageRef } from '@zhin.js/im-contract';
|
|
3
|
+
import type { MediaRef, Segment } from '../../built/segment-contract/types.js';
|
|
4
|
+
export type { MediaRef, Segment };
|
|
5
|
+
declare const componentCallBrand: "zhin.component-call/1";
|
|
6
|
+
declare const rawContentBrand: "zhin.raw-content/1";
|
|
7
|
+
export interface ComponentCall<TProps = unknown> {
|
|
8
|
+
readonly $content: typeof componentCallBrand;
|
|
9
|
+
readonly name: string;
|
|
10
|
+
readonly props: TProps;
|
|
11
|
+
}
|
|
12
|
+
export interface RawContent<TPayload = unknown> {
|
|
13
|
+
readonly $content: typeof rawContentBrand;
|
|
14
|
+
readonly payload: TPayload;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* 出站内容:纯文本 / canonical Segment(一等公民,媒体与富文本的统一表达)/
|
|
18
|
+
* ComponentCall / RawContent,可任意嵌套数组。
|
|
19
|
+
*/
|
|
20
|
+
export type SendContent = string | Segment | ComponentCall | RawContent | readonly SendContent[];
|
|
21
|
+
export declare function component<TProps>(name: string, props: TProps): ComponentCall<TProps>;
|
|
22
|
+
export declare function raw<TPayload>(payload: TPayload): RawContent<TPayload>;
|
|
23
|
+
export declare function isComponentCall(value: SendContent): value is ComponentCall;
|
|
24
|
+
export declare function isRawContent(value: SendContent): value is RawContent;
|
|
25
|
+
/** canonical Segment 一等公民判定(与 ComponentCall/RawContent 的 $content brand 互斥)。 */
|
|
26
|
+
export declare function isSegmentContent(value: unknown): value is Segment;
|
|
27
|
+
export interface MessageSenderRef {
|
|
28
|
+
readonly id: string;
|
|
29
|
+
readonly name?: string;
|
|
30
|
+
readonly roles?: readonly string[];
|
|
31
|
+
}
|
|
32
|
+
export interface IncomingMessage {
|
|
33
|
+
readonly conversation: ConversationRef;
|
|
34
|
+
readonly message?: MessageRef;
|
|
35
|
+
readonly content: string;
|
|
36
|
+
readonly segments?: readonly Segment[];
|
|
37
|
+
readonly sender?: MessageSenderRef;
|
|
38
|
+
/** Endpoint 实例名(如 ICQQ uin、sandbox bot name),区别于 conversation.endpoint.id(CapabilityId)。 */
|
|
39
|
+
readonly endpointId?: string;
|
|
40
|
+
/** 消息是否 @了机器人。 */
|
|
41
|
+
readonly mentioned?: boolean;
|
|
42
|
+
/** 引用/回复的原始消息。 */
|
|
43
|
+
readonly replyTo?: {
|
|
44
|
+
readonly id: string;
|
|
45
|
+
};
|
|
46
|
+
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* 入站消息上下文快照 — 由 reply 闭包捕获,沿出站链路传递到模板编译。
|
|
50
|
+
* 定时任务 / 跨通道发送时整个 incoming 为 undefined。
|
|
51
|
+
*/
|
|
52
|
+
export interface IncomingContext {
|
|
53
|
+
readonly sender?: MessageSenderRef;
|
|
54
|
+
/** 收到的消息纯文本内容。 */
|
|
55
|
+
readonly content: string;
|
|
56
|
+
/** 结构化消息段(图片、@、引用等)。 */
|
|
57
|
+
readonly segments?: readonly Segment[];
|
|
58
|
+
/** 平台原生消息 ID。 */
|
|
59
|
+
readonly messageId?: string;
|
|
60
|
+
/** 消息到达时间戳(ms)。 */
|
|
61
|
+
readonly timestamp: number;
|
|
62
|
+
/** Endpoint 实例名(如 ICQQ uin、sandbox bot name)。 */
|
|
63
|
+
readonly endpointId?: string;
|
|
64
|
+
/** 消息是否 @了机器人。 */
|
|
65
|
+
readonly mentioned?: boolean;
|
|
66
|
+
}
|
|
67
|
+
export interface SendRequest {
|
|
68
|
+
readonly conversation: ConversationRef;
|
|
69
|
+
readonly requester: PluginId;
|
|
70
|
+
readonly content: SendContent;
|
|
71
|
+
/** Incoming message context (absent for scheduled / cross-channel sends). */
|
|
72
|
+
readonly incoming?: IncomingContext;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Host 侧未锚定 endpoint 的会话地址(Console RPC / OutboundHost 入参);
|
|
76
|
+
* ImRuntime 解析 adapter/endpointKey 后锚定为完整 ConversationRef。
|
|
77
|
+
*/
|
|
78
|
+
export type ConversationAddress = Omit<ConversationRef, 'endpoint'>;
|
|
79
|
+
export interface OutboundEnvelope {
|
|
80
|
+
readonly conversation: ConversationRef;
|
|
81
|
+
readonly requester: PluginId;
|
|
82
|
+
readonly generation: number;
|
|
83
|
+
readonly payload: unknown;
|
|
84
|
+
/** Native platform Client for the Endpoint selected by `conversation`. */
|
|
85
|
+
readonly $client: unknown;
|
|
86
|
+
/** Literal adapter name used to validate adapter-bound middleware. */
|
|
87
|
+
readonly clientAdapter?: string;
|
|
88
|
+
replace(payload: unknown): void;
|
|
89
|
+
}
|
|
90
|
+
/** @public Stable IM gateway contract resolved through `outboundMessageToken`. */
|
|
91
|
+
export interface OutboundMessageService {
|
|
92
|
+
send(request: SendRequest): Promise<DeliveryReceipt>;
|
|
93
|
+
/**
|
|
94
|
+
* 注册 interactive action 回跳 handler(prefix 最长匹配;返回注销函数)。
|
|
95
|
+
* 平台 callback 的 action 段、'text' 端点的数字回跳与指令预填直出
|
|
96
|
+
* payload 都会路由到这里。
|
|
97
|
+
*/
|
|
98
|
+
registerInteractiveHandler(prefix: string, handler: (message: Message) => Promise<boolean> | boolean): () => void;
|
|
99
|
+
}
|
|
100
|
+
export interface MessageDispatchResult {
|
|
101
|
+
readonly matched: boolean;
|
|
102
|
+
readonly command?: string;
|
|
103
|
+
readonly owner?: PluginId;
|
|
104
|
+
readonly value?: unknown;
|
|
105
|
+
}
|
|
106
|
+
export declare class Message {
|
|
107
|
+
#private;
|
|
108
|
+
readonly conversation: ConversationRef;
|
|
109
|
+
readonly content: string;
|
|
110
|
+
readonly generation: number;
|
|
111
|
+
readonly sender?: MessageSenderRef | undefined;
|
|
112
|
+
readonly metadata: Readonly<Record<string, unknown>>;
|
|
113
|
+
/**
|
|
114
|
+
* 结构化段视图(与 `content` 纯文本视图同源,见 IncomingMessage.segments)。
|
|
115
|
+
* Command dispatcher 优先使用此字段,以支持 mention、image 等结构化参数。
|
|
116
|
+
*/
|
|
117
|
+
readonly segments?: readonly Segment[] | undefined;
|
|
118
|
+
/** 结构化入站消息身份(平台原生 message id 经 MessageRef 传递)。 */
|
|
119
|
+
readonly message?: MessageRef | undefined;
|
|
120
|
+
readonly endpointId?: string | undefined;
|
|
121
|
+
readonly mentioned?: boolean | undefined;
|
|
122
|
+
readonly replyTo?: {
|
|
123
|
+
readonly id: string;
|
|
124
|
+
} | undefined;
|
|
125
|
+
readonly clientAdapter?: string | undefined;
|
|
126
|
+
/** @internal Constructed only by the generation-owned IM Runtime. */
|
|
127
|
+
constructor(conversation: ConversationRef, content: string, generation: number, reply: (content: SendContent, requester?: PluginId, targetConversation?: ConversationAddress) => Promise<DeliveryReceipt>, sender?: MessageSenderRef | undefined, metadata?: Readonly<Record<string, unknown>>,
|
|
128
|
+
/**
|
|
129
|
+
* 结构化段视图(与 `content` 纯文本视图同源,见 IncomingMessage.segments)。
|
|
130
|
+
* Command dispatcher 优先使用此字段,以支持 mention、image 等结构化参数。
|
|
131
|
+
*/
|
|
132
|
+
segments?: readonly Segment[] | undefined,
|
|
133
|
+
/** 结构化入站消息身份(平台原生 message id 经 MessageRef 传递)。 */
|
|
134
|
+
message?: MessageRef | undefined, endpointId?: string | undefined, mentioned?: boolean | undefined, replyTo?: {
|
|
135
|
+
readonly id: string;
|
|
136
|
+
} | undefined, client?: () => unknown, clientAdapter?: string | undefined);
|
|
137
|
+
/** 平台原生消息 id(`message` 未提供时为 undefined)。 */
|
|
138
|
+
get id(): string | undefined;
|
|
139
|
+
readonly $reply: (content: SendContent) => Promise<DeliveryReceipt>;
|
|
140
|
+
/**
|
|
141
|
+
* Platform-native Client that received this message. The getter is
|
|
142
|
+
* generation-scoped; retaining the returned Client after dispatch is invalid.
|
|
143
|
+
*/
|
|
144
|
+
get $client(): unknown;
|
|
145
|
+
readonly $replyFrom: (requester: PluginId, content: SendContent) => Promise<DeliveryReceipt>;
|
|
146
|
+
/**
|
|
147
|
+
* 向同 Endpoint 的另一个通道发送消息(通用)。
|
|
148
|
+
*
|
|
149
|
+
* ```ts
|
|
150
|
+
* await message.$sendTo({ kind: 'channel', id: 'ch-1', parent: { kind: 'channel', id: 'guild-1' } }, '频道通知');
|
|
151
|
+
* ```
|
|
152
|
+
*/
|
|
153
|
+
readonly $sendTo: (conversation: ConversationAddress, content: SendContent) => Promise<DeliveryReceipt>;
|
|
154
|
+
/**
|
|
155
|
+
* 私信当前消息的发送者(同 Endpoint)。
|
|
156
|
+
*
|
|
157
|
+
* @param content 消息内容
|
|
158
|
+
* @param from 会话上下文:
|
|
159
|
+
* - `true` — 用当前群/频道作为 parent(要求当前不在私聊中)
|
|
160
|
+
* - `{ kind, id }` — 显式指定 parent(群或子频道)
|
|
161
|
+
* - 省略 — 直接私信
|
|
162
|
+
*
|
|
163
|
+
* ```ts
|
|
164
|
+
* await message.$replyToPrivate('直接私信');
|
|
165
|
+
* await message.$replyToPrivate('群临时私信', true);
|
|
166
|
+
* await message.$replyToPrivate('频道私信', { kind: 'channel', id: '子频道ID' });
|
|
167
|
+
* ```
|
|
168
|
+
*/
|
|
169
|
+
readonly $replyToPrivate: (content: SendContent, from?: boolean | {
|
|
170
|
+
readonly kind: 'group' | 'channel';
|
|
171
|
+
readonly id: string;
|
|
172
|
+
}) => Promise<DeliveryReceipt>;
|
|
173
|
+
/**
|
|
174
|
+
* 向指定群发送消息(同 Endpoint)。
|
|
175
|
+
*
|
|
176
|
+
* ```ts
|
|
177
|
+
* await message.$replyToGroup('67890', '群通知');
|
|
178
|
+
* ```
|
|
179
|
+
*/
|
|
180
|
+
readonly $replyToGroup: (groupId: string, content: SendContent) => Promise<DeliveryReceipt>;
|
|
181
|
+
/**
|
|
182
|
+
* 向指定频道/子频道发送消息(同 Endpoint)。
|
|
183
|
+
*
|
|
184
|
+
* ```ts
|
|
185
|
+
* await message.$replyToChannel('channel-1', 'guild-1', '频道通知');
|
|
186
|
+
* await message.$replyToChannel('channel-1', 'guild-1', '话题回复', 'thread-1');
|
|
187
|
+
* ```
|
|
188
|
+
*/
|
|
189
|
+
readonly $replyToChannel: (channelId: string, guildId: string, content: SendContent, threadId?: string) => Promise<DeliveryReceipt>;
|
|
190
|
+
}
|
|
191
|
+
export declare function createOutboundEnvelope(request: Omit<OutboundEnvelope, 'payload' | '$client' | 'replace'>, initialPayload: unknown, resolveClient?: () => unknown): OutboundEnvelope;
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
const componentCallBrand = 'zhin.component-call/1';
|
|
2
|
+
const rawContentBrand = 'zhin.raw-content/1';
|
|
3
|
+
export function component(name, props) {
|
|
4
|
+
if (!name.trim())
|
|
5
|
+
throw new TypeError('Component name cannot be empty');
|
|
6
|
+
return Object.freeze({ $content: componentCallBrand, name, props });
|
|
7
|
+
}
|
|
8
|
+
export function raw(payload) {
|
|
9
|
+
return Object.freeze({ $content: rawContentBrand, payload });
|
|
10
|
+
}
|
|
11
|
+
export function isComponentCall(value) {
|
|
12
|
+
return !Array.isArray(value)
|
|
13
|
+
&& typeof value === 'object'
|
|
14
|
+
&& value !== null
|
|
15
|
+
&& '$content' in value
|
|
16
|
+
&& value.$content === componentCallBrand;
|
|
17
|
+
}
|
|
18
|
+
export function isRawContent(value) {
|
|
19
|
+
return !Array.isArray(value)
|
|
20
|
+
&& typeof value === 'object'
|
|
21
|
+
&& value !== null
|
|
22
|
+
&& '$content' in value
|
|
23
|
+
&& value.$content === rawContentBrand;
|
|
24
|
+
}
|
|
25
|
+
/** canonical Segment 一等公民判定(与 ComponentCall/RawContent 的 $content brand 互斥)。 */
|
|
26
|
+
export function isSegmentContent(value) {
|
|
27
|
+
return !Array.isArray(value)
|
|
28
|
+
&& typeof value === 'object'
|
|
29
|
+
&& value !== null
|
|
30
|
+
&& !('$content' in value)
|
|
31
|
+
&& typeof value.type === 'string'
|
|
32
|
+
&& typeof value.data === 'object'
|
|
33
|
+
&& value.data !== null;
|
|
34
|
+
}
|
|
35
|
+
export class Message {
|
|
36
|
+
conversation;
|
|
37
|
+
content;
|
|
38
|
+
generation;
|
|
39
|
+
sender;
|
|
40
|
+
metadata;
|
|
41
|
+
segments;
|
|
42
|
+
message;
|
|
43
|
+
endpointId;
|
|
44
|
+
mentioned;
|
|
45
|
+
replyTo;
|
|
46
|
+
clientAdapter;
|
|
47
|
+
#resolveClient;
|
|
48
|
+
/** @internal Constructed only by the generation-owned IM Runtime. */
|
|
49
|
+
constructor(conversation, content, generation, reply, sender, metadata = Object.freeze({}),
|
|
50
|
+
/**
|
|
51
|
+
* 结构化段视图(与 `content` 纯文本视图同源,见 IncomingMessage.segments)。
|
|
52
|
+
* Command dispatcher 优先使用此字段,以支持 mention、image 等结构化参数。
|
|
53
|
+
*/
|
|
54
|
+
segments,
|
|
55
|
+
/** 结构化入站消息身份(平台原生 message id 经 MessageRef 传递)。 */
|
|
56
|
+
message, endpointId, mentioned, replyTo, client = () => {
|
|
57
|
+
throw new Error('Message has no Endpoint Client context');
|
|
58
|
+
}, clientAdapter) {
|
|
59
|
+
this.conversation = conversation;
|
|
60
|
+
this.content = content;
|
|
61
|
+
this.generation = generation;
|
|
62
|
+
this.sender = sender;
|
|
63
|
+
this.metadata = metadata;
|
|
64
|
+
this.segments = segments;
|
|
65
|
+
this.message = message;
|
|
66
|
+
this.endpointId = endpointId;
|
|
67
|
+
this.mentioned = mentioned;
|
|
68
|
+
this.replyTo = replyTo;
|
|
69
|
+
this.clientAdapter = clientAdapter;
|
|
70
|
+
this.#resolveClient = client;
|
|
71
|
+
this.$reply = (content) => reply(content);
|
|
72
|
+
this.$replyFrom = (requester, content) => reply(content, requester);
|
|
73
|
+
this.$sendTo = (target, content) => reply(content, undefined, target);
|
|
74
|
+
this.$replyToPrivate = (content, from) => {
|
|
75
|
+
if (!sender)
|
|
76
|
+
throw new Error('Cannot $replyToPrivate: message has no sender');
|
|
77
|
+
let parent;
|
|
78
|
+
if (from === true) {
|
|
79
|
+
if (conversation.kind !== 'group' && conversation.kind !== 'channel') {
|
|
80
|
+
throw new Error('Cannot $replyToPrivate with from=true: current conversation must be a group or channel');
|
|
81
|
+
}
|
|
82
|
+
parent = { kind: conversation.kind, id: conversation.id };
|
|
83
|
+
}
|
|
84
|
+
else if (from != null && typeof from === 'object') {
|
|
85
|
+
parent = from;
|
|
86
|
+
}
|
|
87
|
+
return reply(content, undefined, {
|
|
88
|
+
kind: 'private',
|
|
89
|
+
id: sender.id,
|
|
90
|
+
...(parent ? { parent } : {}),
|
|
91
|
+
});
|
|
92
|
+
};
|
|
93
|
+
this.$replyToGroup = (groupId, content) => {
|
|
94
|
+
return reply(content, undefined, { kind: 'group', id: groupId });
|
|
95
|
+
};
|
|
96
|
+
this.$replyToChannel = (channelId, guildId, content, threadId) => {
|
|
97
|
+
return reply(content, undefined, {
|
|
98
|
+
kind: 'channel',
|
|
99
|
+
id: channelId,
|
|
100
|
+
parent: { kind: 'channel', id: guildId },
|
|
101
|
+
...(threadId ? { threadId } : {}),
|
|
102
|
+
});
|
|
103
|
+
};
|
|
104
|
+
Object.freeze(this);
|
|
105
|
+
}
|
|
106
|
+
/** 平台原生消息 id(`message` 未提供时为 undefined)。 */
|
|
107
|
+
get id() {
|
|
108
|
+
return this.message?.id;
|
|
109
|
+
}
|
|
110
|
+
$reply;
|
|
111
|
+
/**
|
|
112
|
+
* Platform-native Client that received this message. The getter is
|
|
113
|
+
* generation-scoped; retaining the returned Client after dispatch is invalid.
|
|
114
|
+
*/
|
|
115
|
+
get $client() {
|
|
116
|
+
return this.#resolveClient();
|
|
117
|
+
}
|
|
118
|
+
$replyFrom;
|
|
119
|
+
/**
|
|
120
|
+
* 向同 Endpoint 的另一个通道发送消息(通用)。
|
|
121
|
+
*
|
|
122
|
+
* ```ts
|
|
123
|
+
* await message.$sendTo({ kind: 'channel', id: 'ch-1', parent: { kind: 'channel', id: 'guild-1' } }, '频道通知');
|
|
124
|
+
* ```
|
|
125
|
+
*/
|
|
126
|
+
$sendTo;
|
|
127
|
+
/**
|
|
128
|
+
* 私信当前消息的发送者(同 Endpoint)。
|
|
129
|
+
*
|
|
130
|
+
* @param content 消息内容
|
|
131
|
+
* @param from 会话上下文:
|
|
132
|
+
* - `true` — 用当前群/频道作为 parent(要求当前不在私聊中)
|
|
133
|
+
* - `{ kind, id }` — 显式指定 parent(群或子频道)
|
|
134
|
+
* - 省略 — 直接私信
|
|
135
|
+
*
|
|
136
|
+
* ```ts
|
|
137
|
+
* await message.$replyToPrivate('直接私信');
|
|
138
|
+
* await message.$replyToPrivate('群临时私信', true);
|
|
139
|
+
* await message.$replyToPrivate('频道私信', { kind: 'channel', id: '子频道ID' });
|
|
140
|
+
* ```
|
|
141
|
+
*/
|
|
142
|
+
$replyToPrivate;
|
|
143
|
+
/**
|
|
144
|
+
* 向指定群发送消息(同 Endpoint)。
|
|
145
|
+
*
|
|
146
|
+
* ```ts
|
|
147
|
+
* await message.$replyToGroup('67890', '群通知');
|
|
148
|
+
* ```
|
|
149
|
+
*/
|
|
150
|
+
$replyToGroup;
|
|
151
|
+
/**
|
|
152
|
+
* 向指定频道/子频道发送消息(同 Endpoint)。
|
|
153
|
+
*
|
|
154
|
+
* ```ts
|
|
155
|
+
* await message.$replyToChannel('channel-1', 'guild-1', '频道通知');
|
|
156
|
+
* await message.$replyToChannel('channel-1', 'guild-1', '话题回复', 'thread-1');
|
|
157
|
+
* ```
|
|
158
|
+
*/
|
|
159
|
+
$replyToChannel;
|
|
160
|
+
}
|
|
161
|
+
export function createOutboundEnvelope(request, initialPayload, resolveClient = () => undefined) {
|
|
162
|
+
let payload = initialPayload;
|
|
163
|
+
return Object.freeze({
|
|
164
|
+
...request,
|
|
165
|
+
get payload() { return payload; },
|
|
166
|
+
get $client() { return resolveClient(); },
|
|
167
|
+
replace(next) { payload = next; },
|
|
168
|
+
});
|
|
169
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type ConversationContextBlock, type ConversationEventReader, type ConversationEventStore, type ConversationReference, type ConversationResolution, type ConversationRef, type DeliveryReceipt } from '@zhin.js/im-contract';
|
|
2
|
+
import type { Notice } from '../../notice.js';
|
|
3
|
+
import type { IncomingMessage, MessageSenderRef, SendRequest } from './contracts.js';
|
|
4
|
+
/** Owns one ImRuntime's conversation fact store, projections, and consumer cursors. */
|
|
5
|
+
export declare class ConversationRuntime {
|
|
6
|
+
#private;
|
|
7
|
+
constructor(events?: ConversationEventStore);
|
|
8
|
+
get reader(): ConversationEventReader;
|
|
9
|
+
replaceStore(events: ConversationEventStore): void;
|
|
10
|
+
resolveLocal(reference: ConversationReference): Promise<ConversationResolution | undefined>;
|
|
11
|
+
readContext(conversation: ConversationRef, consumer: string, throughSequence: number, limit?: number, excludeMessageId?: string): Promise<Readonly<{
|
|
12
|
+
blocks: readonly ConversationContextBlock[];
|
|
13
|
+
cursor: number;
|
|
14
|
+
}>>;
|
|
15
|
+
commitContext(conversation: ConversationRef, consumer: string, cursor: number): Promise<void>;
|
|
16
|
+
recordIncoming(input: IncomingMessage, sender: MessageSenderRef | undefined): Promise<number | undefined>;
|
|
17
|
+
recordOutbound(request: SendRequest, receipt: DeliveryReceipt): Promise<void>;
|
|
18
|
+
recordNotice(notice: Notice): Promise<void>;
|
|
19
|
+
}
|