@zhin.js/core 1.1.34 → 1.1.35
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 +121 -65
- package/lib/adapter.d.ts +72 -23
- package/lib/adapter.js +222 -62
- package/lib/built/adapter-process.d.ts +20 -5
- package/lib/built/adapter-process.js +54 -7
- package/lib/built/agent-preset.d.ts +1 -2
- package/lib/built/agent-preset.js +1 -2
- package/lib/built/ai-access.d.ts +36 -0
- package/lib/built/ai-access.js +46 -0
- package/lib/built/ai-outbound/adapter-access.d.ts +3 -0
- package/lib/built/ai-outbound/adapter-access.js +9 -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 +9 -0
- package/lib/built/ai-outbound/index.js +9 -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 +58 -0
- package/lib/built/ai-outbound/types.js +5 -0
- package/lib/built/ai-trigger.d.ts +17 -17
- package/lib/built/ai-trigger.js +65 -70
- package/lib/built/authorization.d.ts +10 -0
- package/lib/built/authorization.js +76 -0
- package/lib/built/command.d.ts +9 -5
- package/lib/built/command.js +20 -7
- package/lib/built/common-adapter-tools.d.ts +35 -29
- package/lib/built/common-adapter-tools.js +83 -67
- package/lib/built/component.d.ts +1 -3
- package/lib/built/component.js +2 -4
- package/lib/built/config.d.ts +4 -5
- package/lib/built/config.js +26 -9
- package/lib/built/connect-endpoint-instance.d.ts +17 -0
- package/lib/built/connect-endpoint-instance.js +42 -0
- package/lib/built/database.d.ts +5 -3
- package/lib/built/database.js +10 -4
- package/lib/built/dispatcher.d.ts +10 -8
- package/lib/built/dispatcher.js +31 -9
- package/lib/built/endpoint-commands.d.ts +3 -0
- package/lib/built/endpoint-commands.js +99 -0
- package/lib/built/endpoint-lifecycle-service.d.ts +28 -0
- package/lib/built/endpoint-lifecycle-service.js +242 -0
- package/lib/built/endpoint-lifecycle.d.ts +27 -0
- package/lib/built/endpoint-lifecycle.js +36 -0
- package/lib/built/endpoint-manager.d.ts +34 -0
- package/lib/built/endpoint-manager.js +1 -0
- 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-renderer-loader.d.ts +13 -0
- package/lib/built/html-renderer-loader.js +33 -0
- package/lib/built/html-segment-fallback.d.ts +2 -2
- package/lib/built/html-segment-fallback.js +0 -1
- package/lib/built/html-to-text.d.ts +0 -1
- package/lib/built/html-to-text.js +15 -15
- package/lib/built/inbound-pipeline.d.ts +37 -0
- package/lib/built/inbound-pipeline.js +63 -0
- package/lib/built/inbound-runner.d.ts +0 -1
- package/lib/built/inbound-runner.js +0 -3
- package/lib/built/interactive-segment-contract.d.ts +6 -0
- package/lib/built/interactive-segment-contract.js +9 -0
- 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/fallback-store.d.ts +29 -0
- package/lib/built/interactive-segments/fallback-store.js +63 -0
- package/lib/built/interactive-segments/handlers.d.ts +16 -0
- package/lib/built/interactive-segments/handlers.js +74 -0
- package/lib/built/interactive-segments/index.d.ts +8 -0
- package/lib/built/interactive-segments/index.js +8 -0
- package/lib/built/interactive-segments/keyboard-segment.d.ts +11 -0
- package/lib/built/interactive-segments/keyboard-segment.js +12 -0
- package/lib/built/interactive-segments/onebot-keyboard.d.ts +7 -0
- package/lib/built/interactive-segments/onebot-keyboard.js +51 -0
- package/lib/built/interactive-segments/resolve.d.ts +15 -0
- package/lib/built/interactive-segments/resolve.js +110 -0
- package/lib/built/interactive-segments/types.d.ts +50 -0
- package/lib/built/interactive-segments/types.js +9 -0
- package/lib/built/introspection-format.d.ts +10 -0
- package/lib/built/introspection-format.js +28 -0
- package/lib/built/login-assist.d.ts +43 -9
- package/lib/built/login-assist.js +113 -11
- package/lib/built/management-command-guard.d.ts +15 -0
- package/lib/built/management-command-guard.js +25 -0
- package/lib/built/message-enrich.d.ts +38 -0
- package/lib/built/message-enrich.js +75 -0
- package/lib/built/message-filter.d.ts +4 -5
- package/lib/built/message-filter.js +5 -7
- package/lib/built/optional-peer-import.d.ts +3 -0
- package/lib/built/optional-peer-import.js +33 -0
- package/lib/built/outbound-media-contract.d.ts +22 -0
- package/lib/built/outbound-media-contract.js +10 -0
- package/lib/built/outbound-media-utils.d.ts +9 -0
- package/lib/built/outbound-media-utils.js +62 -0
- package/lib/built/permission.d.ts +3 -7
- package/lib/built/permission.js +39 -52
- package/lib/built/permit-check.d.ts +7 -0
- package/lib/built/permit-check.js +35 -0
- package/lib/built/permit-parse.d.ts +16 -0
- package/lib/built/permit-parse.js +32 -0
- package/lib/built/platform-permit.d.ts +20 -0
- package/lib/built/platform-permit.js +91 -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/adapter-policies.d.ts +9 -0
- package/lib/built/rich-segments/adapter-policies.js +27 -0
- package/lib/built/rich-segments/base.d.ts +11 -0
- package/lib/built/rich-segments/base.js +24 -0
- package/lib/built/rich-segments/builtins.d.ts +4 -0
- package/lib/built/rich-segments/builtins.js +40 -0
- package/lib/built/rich-segments/capabilities.d.ts +6 -0
- package/lib/built/rich-segments/capabilities.js +38 -0
- package/lib/built/rich-segments/html-segment.d.ts +15 -0
- package/lib/built/rich-segments/html-segment.js +62 -0
- package/lib/built/rich-segments/index.d.ts +13 -0
- package/lib/built/rich-segments/index.js +13 -0
- package/lib/built/rich-segments/markdown-segment.d.ts +14 -0
- package/lib/built/rich-segments/markdown-segment.js +58 -0
- 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/rich-segments/qrcode-segment.d.ts +18 -0
- package/lib/built/rich-segments/qrcode-segment.js +73 -0
- package/lib/built/rich-segments/registry.d.ts +16 -0
- package/lib/built/rich-segments/registry.js +52 -0
- package/lib/built/rich-segments/resolve.d.ts +5 -0
- package/lib/built/rich-segments/resolve.js +87 -0
- package/lib/built/rich-segments/tts-segment.d.ts +13 -0
- package/lib/built/rich-segments/tts-segment.js +51 -0
- package/lib/built/rich-segments/types.d.ts +79 -0
- package/lib/built/rich-segments/types.js +17 -0
- package/lib/built/roles.d.ts +4 -5
- package/lib/built/roles.js +4 -5
- package/lib/built/runtime-io.d.ts +0 -1
- package/lib/built/runtime-io.js +0 -1
- package/lib/built/schedule.d.ts +54 -0
- package/lib/built/schedule.js +112 -0
- package/lib/built/schema-endpoint-manager.d.ts +17 -0
- package/lib/built/schema-endpoint-manager.js +73 -0
- package/lib/built/schema-feature.d.ts +0 -1
- package/lib/built/schema-feature.js +1 -3
- 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 +174 -0
- package/lib/built/skill.d.ts +0 -1
- package/lib/built/skill.js +0 -1
- package/lib/built/speech-loader.d.ts +14 -0
- package/lib/built/speech-loader.js +32 -0
- package/lib/built/tool.d.ts +14 -13
- package/lib/built/tool.js +30 -25
- package/lib/built/user-interaction.d.ts +30 -0
- package/lib/built/user-interaction.js +248 -0
- package/lib/command.d.ts +19 -11
- package/lib/command.js +42 -11
- package/lib/component.d.ts +0 -1
- package/lib/component.js +30 -14
- package/lib/endpoint-capabilities.d.ts +46 -0
- package/lib/endpoint-capabilities.js +55 -0
- package/lib/endpoint.d.ts +19 -0
- package/lib/endpoint.js +3 -0
- 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 +52 -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/host-plugin-registry.d.ts +8 -0
- package/lib/host-plugin-registry.js +12 -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 +59 -25
- package/lib/index.js +53 -31
- 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 +16 -10
- package/lib/message.js +16 -13
- package/lib/models/system-log.d.ts +0 -1
- package/lib/models/system-log.js +0 -1
- package/lib/models/user.d.ts +0 -1
- package/lib/models/user.js +0 -1
- package/lib/notice.d.ts +16 -59
- package/lib/notice.js +1 -4
- package/lib/plugin-context.d.ts +27 -0
- package/lib/plugin-context.js +64 -0
- package/lib/plugin-runtime/im/contracts.d.ts +191 -0
- package/lib/plugin-runtime/im/contracts.js +169 -0
- package/lib/plugin-runtime/im/im-runtime.d.ts +177 -0
- package/lib/plugin-runtime/im/im-runtime.js +1204 -0
- package/lib/plugin-runtime/im/index.d.ts +9 -0
- package/lib/plugin-runtime/im/index.js +9 -0
- package/lib/plugin-runtime/im/interactive.d.ts +26 -0
- package/lib/plugin-runtime/im/interactive.js +46 -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/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 +72 -0
- package/lib/plugin-runtime/im/outbound-segments.js +220 -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/service-tokens.d.ts +18 -0
- package/lib/plugin-runtime/im/service-tokens.js +13 -0
- package/lib/plugin.d.ts +34 -24
- package/lib/plugin.js +119 -224
- package/lib/request.d.ts +17 -61
- package/lib/request.js +0 -4
- package/lib/{prompt.d.ts → schema-interaction.d.ts} +6 -7
- package/lib/{prompt.js → schema-interaction.js} +20 -17
- package/lib/side-event/base.d.ts +52 -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 +42 -0
- package/lib/side-event/normalize.js +121 -0
- package/lib/side-event/types.d.ts +23 -0
- package/lib/side-event/types.js +55 -0
- package/lib/system-event.d.ts +15 -0
- package/lib/system-event.js +7 -0
- package/lib/tool-zod.d.ts +18 -3
- package/lib/tool-zod.js +140 -54
- package/lib/types.d.ts +44 -95
- package/lib/types.js +0 -1
- package/lib/utils.d.ts +61 -13
- package/lib/utils.js +66 -25
- package/package.json +98 -10
- package/lib/adapter.d.ts.map +0 -1
- 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.map +0 -1
- package/lib/built/adapter-process.js.map +0 -1
- package/lib/built/agent-preset.d.ts.map +0 -1
- 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.map +0 -1
- 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.map +0 -1
- package/lib/built/component.js.map +0 -1
- package/lib/built/config.d.ts.map +0 -1
- 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.map +0 -1
- package/lib/built/database.js.map +0 -1
- package/lib/built/dispatcher.d.ts.map +0 -1
- 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.map +0 -1
- 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.map +0 -1
- package/lib/built/message-filter.js.map +0 -1
- package/lib/built/permission.d.ts.map +0 -1
- 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.map +0 -1
- package/lib/built/runtime-io.js.map +0 -1
- package/lib/built/schema-feature.d.ts.map +0 -1
- package/lib/built/schema-feature.js.map +0 -1
- package/lib/built/skill.d.ts.map +0 -1
- package/lib/built/skill.js.map +0 -1
- package/lib/built/tool.d.ts.map +0 -1
- package/lib/built/tool.js.map +0 -1
- package/lib/command.d.ts.map +0 -1
- 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.map +0 -1
- package/lib/plugin.js.map +0 -1
- package/lib/prompt.d.ts.map +0 -1
- 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.map +0 -1
- 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,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Prompt类:用于实现机器人与用户的交互式提问与输入收集。
|
|
3
3
|
* 支持文本、数字、确认、列表、选项、Schema等多种输入类型,自动处理超时、默认值、格式化等。
|
|
4
|
-
* 典型用法:await new
|
|
4
|
+
* 典型用法:await new SchemaInteraction(plugin, event).text('请输入内容')
|
|
5
5
|
* @template P 适配器类型
|
|
6
6
|
*/
|
|
7
|
-
export class
|
|
7
|
+
export class SchemaInteraction {
|
|
8
8
|
plugin;
|
|
9
9
|
event;
|
|
10
10
|
/**
|
|
@@ -20,18 +20,22 @@ export class Prompt {
|
|
|
20
20
|
* 获取当前会话唯一标识(适配器-机器人-频道-用户)
|
|
21
21
|
*/
|
|
22
22
|
getChannelAddress(event) {
|
|
23
|
-
return `${event.$adapter}-${event.$
|
|
23
|
+
return `${event.$adapter}-${event.$endpoint}-${event.$channel.type}:${event.$channel.id}-${event.$sender.id}`;
|
|
24
24
|
}
|
|
25
25
|
/**
|
|
26
26
|
* 通用提问方法,支持自定义格式化、超时、默认值等
|
|
27
27
|
* @param config 提问配置
|
|
28
28
|
*/
|
|
29
|
-
|
|
29
|
+
collect(config) {
|
|
30
30
|
return new Promise(async (resolve, reject) => {
|
|
31
|
+
if (!this.event.$reply) {
|
|
32
|
+
reject(new Error('SchemaInteraction requires outbound capability on the current endpoint'));
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
31
35
|
const id = await this.event.$reply(config.tips);
|
|
32
36
|
this.middleware(input => {
|
|
33
37
|
if (input instanceof Error) {
|
|
34
|
-
this.event.$reply(input.message);
|
|
38
|
+
void this.event.$reply?.(input.message);
|
|
35
39
|
if (config.defaultValue)
|
|
36
40
|
resolve(config.defaultValue);
|
|
37
41
|
else
|
|
@@ -39,7 +43,7 @@ export class Prompt {
|
|
|
39
43
|
return;
|
|
40
44
|
}
|
|
41
45
|
const adapter = this.plugin.inject(this.event.$adapter);
|
|
42
|
-
adapter.emit('call.recallMessage', this.event.$
|
|
46
|
+
adapter.emit('call.recallMessage', this.event.$endpoint, id);
|
|
43
47
|
resolve(config.format(input));
|
|
44
48
|
}, config.timeout, config.timeoutText);
|
|
45
49
|
});
|
|
@@ -58,7 +62,7 @@ export class Prompt {
|
|
|
58
62
|
dispose();
|
|
59
63
|
clearTimeout(timer);
|
|
60
64
|
};
|
|
61
|
-
const dispose = this.plugin.addMiddleware(middleware);
|
|
65
|
+
const dispose = this.plugin.root.addMiddleware(middleware);
|
|
62
66
|
const timer = setTimeout(() => {
|
|
63
67
|
dispose();
|
|
64
68
|
callback(new Error(timeoutText));
|
|
@@ -68,7 +72,7 @@ export class Prompt {
|
|
|
68
72
|
* 文本输入
|
|
69
73
|
*/
|
|
70
74
|
async text(tips, timeout, defaultValue = '', timeoutText) {
|
|
71
|
-
return this.
|
|
75
|
+
return this.collect({
|
|
72
76
|
tips,
|
|
73
77
|
defaultValue,
|
|
74
78
|
timeoutText,
|
|
@@ -80,7 +84,7 @@ export class Prompt {
|
|
|
80
84
|
* 任意输入
|
|
81
85
|
*/
|
|
82
86
|
async any(tips, timeout, defaultValue = '', timeoutText) {
|
|
83
|
-
return this.
|
|
87
|
+
return this.collect({
|
|
84
88
|
tips,
|
|
85
89
|
defaultValue,
|
|
86
90
|
timeoutText,
|
|
@@ -92,7 +96,7 @@ export class Prompt {
|
|
|
92
96
|
* 数字输入
|
|
93
97
|
*/
|
|
94
98
|
async number(tips, timeout, defaultValue = 0, timeoutText) {
|
|
95
|
-
return this.
|
|
99
|
+
return this.collect({
|
|
96
100
|
tips,
|
|
97
101
|
defaultValue,
|
|
98
102
|
timeoutText,
|
|
@@ -104,7 +108,7 @@ export class Prompt {
|
|
|
104
108
|
* 确认输入(如 yes/no)
|
|
105
109
|
*/
|
|
106
110
|
async confirm(tips, condition = 'yes', timeout, defaultValue = false, timeoutText) {
|
|
107
|
-
return this.
|
|
111
|
+
return this.collect({
|
|
108
112
|
tips: `${tips}\n输入“${condition}”以确认`,
|
|
109
113
|
defaultValue,
|
|
110
114
|
timeout,
|
|
@@ -117,7 +121,7 @@ export class Prompt {
|
|
|
117
121
|
*/
|
|
118
122
|
async list(tips, config = { type: 'text' }, timeoutText) {
|
|
119
123
|
const separator = config.separator || ',';
|
|
120
|
-
return this.
|
|
124
|
+
return this.collect({
|
|
121
125
|
tips: `${tips}\n值之间使用“${separator}”分隔`,
|
|
122
126
|
defaultValue: config.defaultValue || [],
|
|
123
127
|
timeout: config.timeout,
|
|
@@ -150,7 +154,7 @@ export class Prompt {
|
|
|
150
154
|
const separator = config.separator || ',';
|
|
151
155
|
if (config.multiple)
|
|
152
156
|
moreTextArr.push(`多选请用“${separator}”分隔`);
|
|
153
|
-
return this.
|
|
157
|
+
return this.collect({
|
|
154
158
|
tips: `${tips}\n${moreTextArr.join('\n')}`,
|
|
155
159
|
defaultValue: config.defaultValue,
|
|
156
160
|
timeout: config.timeout,
|
|
@@ -209,18 +213,18 @@ export class Prompt {
|
|
|
209
213
|
return (await this.confirm(schema.meta.description || schema.meta.key || 'Confirm'));
|
|
210
214
|
case 'object':
|
|
211
215
|
if (schema.meta.description)
|
|
212
|
-
await this.event.$reply(schema.meta.description);
|
|
216
|
+
await this.event.$reply?.(schema.meta.description);
|
|
213
217
|
if (!schema.options.object)
|
|
214
218
|
throw new Error('Object schema missing object definition');
|
|
215
219
|
return (await this.getValueWithSchemas(schema.options.object));
|
|
216
220
|
case 'date':
|
|
217
|
-
return await this.
|
|
221
|
+
return await this.collect({
|
|
218
222
|
tips: schema.meta.description || schema.meta.key || 'Enter a date',
|
|
219
223
|
defaultValue: schema.meta.default || new Date(),
|
|
220
224
|
format: (input) => new Date(input),
|
|
221
225
|
});
|
|
222
226
|
case 'regexp':
|
|
223
|
-
return await this.
|
|
227
|
+
return await this.collect({
|
|
224
228
|
tips: schema.meta.description || schema.meta.key || 'Enter a regex pattern',
|
|
225
229
|
defaultValue: schema.meta.default || '',
|
|
226
230
|
format: (input) => new RegExp(input),
|
|
@@ -241,4 +245,3 @@ export class Prompt {
|
|
|
241
245
|
}
|
|
242
246
|
}
|
|
243
247
|
}
|
|
244
|
-
//# sourceMappingURL=prompt.js.map
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { Adapters } from '../adapter.js';
|
|
2
|
+
import type { MessageSender } from '../types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Side Event 共享基础结构(Notice 与 Request 共用)。
|
|
5
|
+
* 字段统一为 `$foo_bar` 命名。
|
|
6
|
+
*
|
|
7
|
+
* 完整事件名:`${$type}.${$scene_type}.${$sub_type}`(见 `formatSideEventName`)。
|
|
8
|
+
*/
|
|
9
|
+
export interface SideEventBase {
|
|
10
|
+
/** 平台侧去重键 / flag(非 DB 行 id) */
|
|
11
|
+
$id: string;
|
|
12
|
+
$adapter: keyof Adapters;
|
|
13
|
+
$endpoint: string;
|
|
14
|
+
/** 命名空间:`notice` 或 `request` */
|
|
15
|
+
$type: string;
|
|
16
|
+
/** 平台场景 ID(群号、用户号、频道 ID 等) */
|
|
17
|
+
$scene_id: string;
|
|
18
|
+
/** 场景域(如 group、friend、channel、endpoint) */
|
|
19
|
+
$scene_type?: string;
|
|
20
|
+
/** 动作子类型(如 member_increase、add、poke) */
|
|
21
|
+
$sub_type?: string;
|
|
22
|
+
/** 主参与者(原 Notice.$operator / Request.$sender) */
|
|
23
|
+
$actor?: MessageSender;
|
|
24
|
+
/** 被操作对象 */
|
|
25
|
+
$target?: MessageSender;
|
|
26
|
+
/** 毫秒时间戳 */
|
|
27
|
+
$timestamp: number;
|
|
28
|
+
/** Canonical relation fields populated by the Adapter boundary. */
|
|
29
|
+
$message_id?: string;
|
|
30
|
+
$reaction?: string;
|
|
31
|
+
$operation?: 'added' | 'removed';
|
|
32
|
+
$duration_seconds?: number;
|
|
33
|
+
$role?: string;
|
|
34
|
+
$enabled?: boolean;
|
|
35
|
+
}
|
|
36
|
+
/** 组合 Side Event 完整类型名 */
|
|
37
|
+
export declare function composeSideEventName(type: string, sceneType: string | undefined, subType: string | undefined): string;
|
|
38
|
+
/** 从 Side Event 字段生成完整类型名 */
|
|
39
|
+
export declare function formatSideEventName(event: Pick<SideEventBase, '$type' | '$scene_type' | '$sub_type'>): string;
|
|
40
|
+
/** 判断 Side Event 是否匹配完整类型名(如 `notice.group.member_increase`) */
|
|
41
|
+
export declare function matchesSideEventName(event: Pick<SideEventBase, '$type' | '$scene_type' | '$sub_type'>, fullName: string): boolean;
|
|
42
|
+
/** 解析完整类型名为三段 */
|
|
43
|
+
export declare function parseSideEventName(fullName: string): {
|
|
44
|
+
type: string;
|
|
45
|
+
scene_type?: string;
|
|
46
|
+
sub_type?: string;
|
|
47
|
+
};
|
|
48
|
+
/** 将 Side Event 场景映射为 IM 发送通道(group-suite 等消费者用) */
|
|
49
|
+
export declare function sideEventSendChannel(event: Pick<SideEventBase, '$scene_type' | '$scene_id'>): {
|
|
50
|
+
id: string;
|
|
51
|
+
type: 'group' | 'private' | 'channel';
|
|
52
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/** 组合 Side Event 完整类型名 */
|
|
2
|
+
export function composeSideEventName(type, sceneType, subType) {
|
|
3
|
+
return [type, sceneType, subType].filter((p) => !!p).join('.');
|
|
4
|
+
}
|
|
5
|
+
/** 从 Side Event 字段生成完整类型名 */
|
|
6
|
+
export function formatSideEventName(event) {
|
|
7
|
+
return composeSideEventName(event.$type, event.$scene_type, event.$sub_type);
|
|
8
|
+
}
|
|
9
|
+
/** 判断 Side Event 是否匹配完整类型名(如 `notice.group.member_increase`) */
|
|
10
|
+
export function matchesSideEventName(event, fullName) {
|
|
11
|
+
return formatSideEventName(event) === fullName;
|
|
12
|
+
}
|
|
13
|
+
/** 解析完整类型名为三段 */
|
|
14
|
+
export function parseSideEventName(fullName) {
|
|
15
|
+
const parts = fullName.split('.');
|
|
16
|
+
return {
|
|
17
|
+
type: parts[0] ?? '',
|
|
18
|
+
scene_type: parts[1],
|
|
19
|
+
sub_type: parts.slice(2).join('.') || undefined,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
/** 将 Side Event 场景映射为 IM 发送通道(group-suite 等消费者用) */
|
|
23
|
+
export function sideEventSendChannel(event) {
|
|
24
|
+
const domain = event.$scene_type ?? 'private';
|
|
25
|
+
if (domain === 'group')
|
|
26
|
+
return { id: event.$scene_id, type: 'group' };
|
|
27
|
+
if (domain === 'channel')
|
|
28
|
+
return { id: event.$scene_id, type: 'channel' };
|
|
29
|
+
return { id: event.$scene_id, type: 'private' };
|
|
30
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { EndpointEventEmitter } from '@zhin.js/adapter';
|
|
2
|
+
import { type OneBotLikeRawEvent, type SideEventPlatform } from './normalize.js';
|
|
3
|
+
export interface OneBotLikeSideEventInput {
|
|
4
|
+
readonly adapter: string;
|
|
5
|
+
readonly endpointKey: string;
|
|
6
|
+
readonly platform?: SideEventPlatform;
|
|
7
|
+
readonly raw: OneBotLikeRawEvent;
|
|
8
|
+
readonly approve?: (flag: string, remark?: string) => void | Promise<void>;
|
|
9
|
+
readonly reject?: (flag: string, reason?: string) => void | Promise<void>;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Normalize OneBot / icqq-style notice|request|meta payloads and feed Endpoint.emit().
|
|
13
|
+
* Returns which kind was dispatched, or null when the payload is not a side event.
|
|
14
|
+
*/
|
|
15
|
+
export declare function receiveOneBotLikeSideEvent(emit: EndpointEventEmitter, input: OneBotLikeSideEventInput): Promise<'notice' | 'request' | 'system' | null>;
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { buildNotice, buildRequest, buildSystem, mapNoticeParts, mapRequestParts, resolveSideEventDedupeKey, senderFromId, } from './normalize.js';
|
|
2
|
+
/**
|
|
3
|
+
* Normalize OneBot / icqq-style notice|request|meta payloads and feed Endpoint.emit().
|
|
4
|
+
* Returns which kind was dispatched, or null when the payload is not a side event.
|
|
5
|
+
*/
|
|
6
|
+
export async function receiveOneBotLikeSideEvent(emit, input) {
|
|
7
|
+
const raw = input.raw;
|
|
8
|
+
const platform = input.platform ?? 'onebot';
|
|
9
|
+
const postType = String(raw.post_type ?? raw.type ?? '');
|
|
10
|
+
if (postType === 'notice' || postType.startsWith('notice.')) {
|
|
11
|
+
const noticeType = String(raw.notice_type ?? (postType.replace(/^notice\.?/, '') || 'unknown'));
|
|
12
|
+
const parts = mapNoticeParts(platform, noticeType, {
|
|
13
|
+
sub_type: raw.sub_type != null ? String(raw.sub_type) : undefined,
|
|
14
|
+
is_group: raw.group_id != null,
|
|
15
|
+
});
|
|
16
|
+
const id = resolveSideEventDedupeKey(raw, 'notice');
|
|
17
|
+
const memberEvent = ['member_increase', 'member_decrease', 'ban', 'admin_change'].includes(parts.sub_type);
|
|
18
|
+
const actorId = raw.operator_id
|
|
19
|
+
?? (!memberEvent ? raw.user_id : undefined);
|
|
20
|
+
const targetId = memberEvent
|
|
21
|
+
? raw.user_id
|
|
22
|
+
: parts.sub_type === 'poke'
|
|
23
|
+
? raw.target_id ?? raw.self_id
|
|
24
|
+
: raw.user_id != null && String(raw.user_id) !== String(raw.operator_id ?? '')
|
|
25
|
+
? raw.user_id
|
|
26
|
+
: undefined;
|
|
27
|
+
const notice = buildNotice(raw, {
|
|
28
|
+
$id: id,
|
|
29
|
+
$adapter: input.adapter,
|
|
30
|
+
$endpoint: input.endpointKey,
|
|
31
|
+
$type: 'notice',
|
|
32
|
+
$scene_id: String(raw.group_id ?? raw.user_id ?? input.endpointKey),
|
|
33
|
+
$scene_type: parts.scene_type,
|
|
34
|
+
$sub_type: parts.sub_type,
|
|
35
|
+
$actor: senderFromId(actorId),
|
|
36
|
+
$target: senderFromId(targetId),
|
|
37
|
+
$timestamp: toMillis(raw.time),
|
|
38
|
+
...(raw.message_id != null ? { $message_id: String(raw.message_id) } : {}),
|
|
39
|
+
...(raw.emoji_id != null || raw.code != null
|
|
40
|
+
? { $reaction: String(raw.emoji_id ?? raw.code) }
|
|
41
|
+
: {}),
|
|
42
|
+
...(parts.sub_type === 'emoji_reaction'
|
|
43
|
+
? { $operation: /delete|remove/i.test(String(raw.sub_type ?? noticeType)) ? 'removed' : 'added' }
|
|
44
|
+
: {}),
|
|
45
|
+
...(raw.duration != null ? { $duration_seconds: Math.max(0, Number(raw.duration) || 0) } : {}),
|
|
46
|
+
...(parts.sub_type === 'admin_change'
|
|
47
|
+
? { $role: 'admin', $enabled: String(raw.sub_type ?? '') === 'set' }
|
|
48
|
+
: {}),
|
|
49
|
+
});
|
|
50
|
+
await emit('notice.receive', notice);
|
|
51
|
+
return 'notice';
|
|
52
|
+
}
|
|
53
|
+
if (postType === 'request' || postType.startsWith('request.')) {
|
|
54
|
+
const requestType = String(raw.request_type ?? (postType.replace(/^request\.?/, '') || 'friend'));
|
|
55
|
+
const parts = mapRequestParts(platform, requestType, raw.sub_type != null ? String(raw.sub_type) : undefined);
|
|
56
|
+
const flag = raw.flag != null ? String(raw.flag) : '';
|
|
57
|
+
const id = flag || resolveSideEventDedupeKey(raw, 'request');
|
|
58
|
+
const actor = senderFromId(raw.user_id);
|
|
59
|
+
if (!actor)
|
|
60
|
+
return null;
|
|
61
|
+
const approve = input.approve;
|
|
62
|
+
const reject = input.reject;
|
|
63
|
+
let active = true;
|
|
64
|
+
const actions = new Set();
|
|
65
|
+
const requireActiveAction = () => {
|
|
66
|
+
if (!active)
|
|
67
|
+
throw new Error('Request action port expired with its generation operation');
|
|
68
|
+
};
|
|
69
|
+
const runAction = (action) => {
|
|
70
|
+
requireActiveAction();
|
|
71
|
+
const operation = Promise.resolve().then(action);
|
|
72
|
+
actions.add(operation);
|
|
73
|
+
void operation.then(() => actions.delete(operation), () => actions.delete(operation));
|
|
74
|
+
return operation;
|
|
75
|
+
};
|
|
76
|
+
const request = buildRequest(raw, {
|
|
77
|
+
$id: id,
|
|
78
|
+
$adapter: input.adapter,
|
|
79
|
+
$endpoint: input.endpointKey,
|
|
80
|
+
$type: 'request',
|
|
81
|
+
$scene_id: String(raw.group_id ?? raw.user_id ?? input.endpointKey),
|
|
82
|
+
$scene_type: parts.scene_type,
|
|
83
|
+
$sub_type: parts.sub_type,
|
|
84
|
+
$actor: actor,
|
|
85
|
+
$comment: raw.comment != null ? String(raw.comment) : undefined,
|
|
86
|
+
$timestamp: toMillis(raw.time),
|
|
87
|
+
async $approve(remark) {
|
|
88
|
+
if (!approve || !flag)
|
|
89
|
+
throw new Error('Request approve is not available');
|
|
90
|
+
await runAction(() => approve(flag, remark));
|
|
91
|
+
},
|
|
92
|
+
async $reject(reason) {
|
|
93
|
+
if (!reject || !flag)
|
|
94
|
+
throw new Error('Request reject is not available');
|
|
95
|
+
await runAction(() => reject(flag, reason));
|
|
96
|
+
},
|
|
97
|
+
});
|
|
98
|
+
try {
|
|
99
|
+
await emit('request.receive', request);
|
|
100
|
+
}
|
|
101
|
+
finally {
|
|
102
|
+
active = false;
|
|
103
|
+
await Promise.allSettled([...actions]);
|
|
104
|
+
}
|
|
105
|
+
return 'request';
|
|
106
|
+
}
|
|
107
|
+
if (postType === 'meta_event'
|
|
108
|
+
|| postType === 'meta'
|
|
109
|
+
|| postType.startsWith('meta.')
|
|
110
|
+
|| postType.startsWith('system.')) {
|
|
111
|
+
const metaType = String(raw.meta_event_type
|
|
112
|
+
?? raw.detail_type
|
|
113
|
+
?? (postType.replace(/^(meta_event|meta|system)\.?/, '') || 'unknown'));
|
|
114
|
+
const subType = raw.sub_type != null ? String(raw.sub_type) : undefined;
|
|
115
|
+
const sceneType = postType.startsWith('system.')
|
|
116
|
+
? (postType.split('.')[1] ?? 'system')
|
|
117
|
+
: metaType === 'lifecycle' || metaType === 'heartbeat'
|
|
118
|
+
? metaType
|
|
119
|
+
: 'meta';
|
|
120
|
+
const system = buildSystem(raw, {
|
|
121
|
+
$id: `system:${toMillis(raw.time)}_${metaType}_${subType ?? ''}`,
|
|
122
|
+
$adapter: input.adapter,
|
|
123
|
+
$endpoint: input.endpointKey,
|
|
124
|
+
$type: 'system',
|
|
125
|
+
$scene_id: String(raw.self_id ?? input.endpointKey),
|
|
126
|
+
$scene_type: sceneType,
|
|
127
|
+
$sub_type: subType ?? metaType,
|
|
128
|
+
$timestamp: toMillis(raw.time),
|
|
129
|
+
});
|
|
130
|
+
await emit('system.receive', system);
|
|
131
|
+
return 'system';
|
|
132
|
+
}
|
|
133
|
+
return null;
|
|
134
|
+
}
|
|
135
|
+
function toMillis(time) {
|
|
136
|
+
const seconds = Number(time);
|
|
137
|
+
return Number.isFinite(seconds) && seconds > 0
|
|
138
|
+
? (seconds < 1e12 ? seconds * 1000 : seconds)
|
|
139
|
+
: Date.now();
|
|
140
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Notice, type NoticeBase } from '../notice.js';
|
|
2
|
+
import { Request, type RequestBase } from '../request.js';
|
|
3
|
+
import { SystemEvent, type SystemEventBase } from '../system-event.js';
|
|
4
|
+
import { type ComposedNoticeName, type ComposedRequestName, type SideEventParts } from './types.js';
|
|
5
|
+
export type SideEventPlatform = 'onebot' | 'icqq' | 'napcat' | 'kook' | (string & {});
|
|
6
|
+
export interface OneBotLikeRawEvent {
|
|
7
|
+
notice_type?: string;
|
|
8
|
+
request_type?: string;
|
|
9
|
+
sub_type?: string;
|
|
10
|
+
group_id?: number | string;
|
|
11
|
+
user_id?: number | string;
|
|
12
|
+
operator_id?: number | string;
|
|
13
|
+
flag?: string;
|
|
14
|
+
time?: number;
|
|
15
|
+
self_id?: number | string;
|
|
16
|
+
[key: string]: unknown;
|
|
17
|
+
}
|
|
18
|
+
/** 去重用:notice / request 无稳定 id 时组合键 */
|
|
19
|
+
export declare function resolveSideEventDedupeKey(data: OneBotLikeRawEvent, kind: 'notice' | 'request'): string;
|
|
20
|
+
/**
|
|
21
|
+
* 将平台原始 notice_type 映射为标准 `$scene_type` + `$sub_type`。
|
|
22
|
+
*/
|
|
23
|
+
export declare function mapNoticeParts(platform: SideEventPlatform, raw: string, options?: {
|
|
24
|
+
sub_type?: string;
|
|
25
|
+
is_group?: boolean;
|
|
26
|
+
notify_handler?: (subType: string | undefined, isGroup: boolean) => SideEventParts;
|
|
27
|
+
}): SideEventParts;
|
|
28
|
+
/**
|
|
29
|
+
* 将平台原始 request_type 映射为标准 `$scene_type` + `$sub_type`。
|
|
30
|
+
*/
|
|
31
|
+
export declare function mapRequestParts(_platform: SideEventPlatform, raw: string, subType?: string): SideEventParts;
|
|
32
|
+
/** 组合完整 Notice 类型名(兼容旧 API) */
|
|
33
|
+
export declare function mapNoticeType(platform: SideEventPlatform, raw: string, options?: Parameters<typeof mapNoticeParts>[2]): ComposedNoticeName;
|
|
34
|
+
/** 组合完整 Request 类型名(兼容旧 API) */
|
|
35
|
+
export declare function mapRequestType(platform: SideEventPlatform, raw: string, subType?: string): ComposedRequestName;
|
|
36
|
+
export declare function senderFromId(id: unknown, name?: string): {
|
|
37
|
+
id: string;
|
|
38
|
+
name: string;
|
|
39
|
+
} | undefined;
|
|
40
|
+
export declare function buildNotice<T extends object>(input: T, format: NoticeBase): Notice<T>;
|
|
41
|
+
export declare function buildRequest<T extends object>(input: T, format: RequestBase): Request<T>;
|
|
42
|
+
export declare function buildSystem<T extends object>(input: T, format: SystemEventBase): SystemEvent<T>;
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { Notice } from '../notice.js';
|
|
2
|
+
import { Request } from '../request.js';
|
|
3
|
+
import { SystemEvent } from '../system-event.js';
|
|
4
|
+
import { composeSideEventName, parseSideEventName, } from './base.js';
|
|
5
|
+
import { KOOK_NOTICE_PARTS_MAP, ONEBOT_NOTICE_PARTS_MAP, SLACK_NOTICE_PARTS_MAP } from './types.js';
|
|
6
|
+
/** 去重用:notice / request 无稳定 id 时组合键 */
|
|
7
|
+
export function resolveSideEventDedupeKey(data, kind) {
|
|
8
|
+
if (data.flag != null && String(data.flag) !== '') {
|
|
9
|
+
return `${kind}:${data.flag}`;
|
|
10
|
+
}
|
|
11
|
+
const time = data.time ?? 0;
|
|
12
|
+
const type = data.notice_type ?? data.request_type ?? kind;
|
|
13
|
+
const scope = data.group_id ?? data.user_id ?? '';
|
|
14
|
+
const sub = data.sub_type ?? '';
|
|
15
|
+
return `${kind}:${time}_${type}_${scope}_${sub}`;
|
|
16
|
+
}
|
|
17
|
+
function resolveNotifyNoticeParts(subType, isGroup) {
|
|
18
|
+
if (subType === 'poke') {
|
|
19
|
+
return isGroup
|
|
20
|
+
? { scene_type: 'group', sub_type: 'poke' }
|
|
21
|
+
: { scene_type: 'friend', sub_type: 'poke' };
|
|
22
|
+
}
|
|
23
|
+
if (subType === 'input_status')
|
|
24
|
+
return { scene_type: 'notify', sub_type: 'input_status' };
|
|
25
|
+
if (subType === 'title')
|
|
26
|
+
return { scene_type: 'notify', sub_type: 'title_change' };
|
|
27
|
+
if (subType === 'profile_like')
|
|
28
|
+
return { scene_type: 'notify', sub_type: 'profile_like' };
|
|
29
|
+
return { scene_type: 'notify', sub_type: subType ?? 'unknown' };
|
|
30
|
+
}
|
|
31
|
+
function resolveEssenceNoticeParts(subType) {
|
|
32
|
+
return subType === 'add'
|
|
33
|
+
? { scene_type: 'group', sub_type: 'essence_add' }
|
|
34
|
+
: { scene_type: 'group', sub_type: 'essence_delete' };
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* 将平台原始 notice_type 映射为标准 `$scene_type` + `$sub_type`。
|
|
38
|
+
*/
|
|
39
|
+
export function mapNoticeParts(platform, raw, options) {
|
|
40
|
+
const subType = options?.sub_type;
|
|
41
|
+
const isGroup = options?.is_group ?? false;
|
|
42
|
+
if (platform === 'kook') {
|
|
43
|
+
return KOOK_NOTICE_PARTS_MAP[raw] ?? { scene_type: 'kook', sub_type: raw };
|
|
44
|
+
}
|
|
45
|
+
if (platform === 'slack') {
|
|
46
|
+
return SLACK_NOTICE_PARTS_MAP[raw] ?? { scene_type: 'slack', sub_type: raw };
|
|
47
|
+
}
|
|
48
|
+
if (raw === 'notify') {
|
|
49
|
+
const handler = options?.notify_handler ?? resolveNotifyNoticeParts;
|
|
50
|
+
return handler(subType, isGroup);
|
|
51
|
+
}
|
|
52
|
+
if (raw === 'essence') {
|
|
53
|
+
return resolveEssenceNoticeParts(subType);
|
|
54
|
+
}
|
|
55
|
+
if (ONEBOT_NOTICE_PARTS_MAP[raw]) {
|
|
56
|
+
return ONEBOT_NOTICE_PARTS_MAP[raw];
|
|
57
|
+
}
|
|
58
|
+
if (raw.startsWith('notice.')) {
|
|
59
|
+
const parsed = parseSideEventName(raw);
|
|
60
|
+
if (parsed.scene_type && parsed.sub_type) {
|
|
61
|
+
return { scene_type: parsed.scene_type, sub_type: parsed.sub_type };
|
|
62
|
+
}
|
|
63
|
+
const suffix = raw.slice('notice.'.length).replace(/\./g, '_');
|
|
64
|
+
if (ONEBOT_NOTICE_PARTS_MAP[suffix])
|
|
65
|
+
return ONEBOT_NOTICE_PARTS_MAP[suffix];
|
|
66
|
+
return { scene_type: parsed.scene_type ?? 'unknown', sub_type: parsed.sub_type ?? suffix };
|
|
67
|
+
}
|
|
68
|
+
if (platform === 'icqq' || platform === 'onebot' || platform === 'napcat') {
|
|
69
|
+
const dotted = raw.replace(/_/g, '.');
|
|
70
|
+
const parsed = parseSideEventName(`notice.${dotted}`);
|
|
71
|
+
return {
|
|
72
|
+
scene_type: parsed.scene_type ?? dotted.split('.')[0] ?? 'unknown',
|
|
73
|
+
sub_type: parsed.sub_type ?? (dotted.split('.').slice(1).join('.') || raw),
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
return { scene_type: platform, sub_type: raw };
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* 将平台原始 request_type 映射为标准 `$scene_type` + `$sub_type`。
|
|
80
|
+
*/
|
|
81
|
+
export function mapRequestParts(_platform, raw, subType) {
|
|
82
|
+
if (raw === 'friend' || raw.startsWith('friend')) {
|
|
83
|
+
return { scene_type: 'friend', sub_type: 'add' };
|
|
84
|
+
}
|
|
85
|
+
if (raw === 'group' || raw.startsWith('group')) {
|
|
86
|
+
return { scene_type: 'group', sub_type: subType === 'invite' ? 'invite' : 'add' };
|
|
87
|
+
}
|
|
88
|
+
if (raw.startsWith('request.')) {
|
|
89
|
+
const parsed = parseSideEventName(raw);
|
|
90
|
+
return {
|
|
91
|
+
scene_type: parsed.scene_type ?? 'unknown',
|
|
92
|
+
sub_type: parsed.sub_type ?? 'unknown',
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
return { scene_type: raw, sub_type: subType ?? 'unknown' };
|
|
96
|
+
}
|
|
97
|
+
/** 组合完整 Notice 类型名(兼容旧 API) */
|
|
98
|
+
export function mapNoticeType(platform, raw, options) {
|
|
99
|
+
const parts = mapNoticeParts(platform, raw, options);
|
|
100
|
+
return composeSideEventName('notice', parts.scene_type, parts.sub_type);
|
|
101
|
+
}
|
|
102
|
+
/** 组合完整 Request 类型名(兼容旧 API) */
|
|
103
|
+
export function mapRequestType(platform, raw, subType) {
|
|
104
|
+
const parts = mapRequestParts(platform, raw, subType);
|
|
105
|
+
return composeSideEventName('request', parts.scene_type, parts.sub_type);
|
|
106
|
+
}
|
|
107
|
+
export function senderFromId(id, name) {
|
|
108
|
+
if (id == null || id === '')
|
|
109
|
+
return undefined;
|
|
110
|
+
const s = String(id);
|
|
111
|
+
return { id: s, name: name ?? s };
|
|
112
|
+
}
|
|
113
|
+
export function buildNotice(input, format) {
|
|
114
|
+
return Notice.from(input, format);
|
|
115
|
+
}
|
|
116
|
+
export function buildRequest(input, format) {
|
|
117
|
+
return Request.from(input, format);
|
|
118
|
+
}
|
|
119
|
+
export function buildSystem(input, format) {
|
|
120
|
+
return SystemEvent.from(input, format);
|
|
121
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Side Event 标准类型。
|
|
3
|
+
* 运行时 `$type` 仅存命名空间(`notice` / `request` / `system`);
|
|
4
|
+
* 完整名由 `${$type}.${$scene_type}.${$sub_type}` 组合。
|
|
5
|
+
*/
|
|
6
|
+
export type SideEventKind = 'notice' | 'request' | 'system';
|
|
7
|
+
export type NoticeKind = 'notice';
|
|
8
|
+
export type RequestKind = 'request';
|
|
9
|
+
export type SystemKind = 'system';
|
|
10
|
+
/** 完整组合名(测试 / 文档 / 消费者匹配用) */
|
|
11
|
+
export type ComposedNoticeName = 'notice.group.member_increase' | 'notice.group.member_decrease' | 'notice.group.admin_change' | 'notice.group.ban' | 'notice.group.recall' | 'notice.group.poke' | 'notice.group.transfer' | 'notice.group.upload' | 'notice.group.emoji_reaction' | 'notice.group.card_change' | 'notice.group.essence_add' | 'notice.group.essence_delete' | 'notice.friend.recall' | 'notice.friend.increase' | 'notice.friend.poke' | 'notice.endpoint.lifecycle' | (string & {});
|
|
12
|
+
export type ComposedRequestName = 'request.friend.add' | 'request.group.add' | 'request.group.invite' | (string & {});
|
|
13
|
+
export type ComposedSystemName = 'system.login.qrcode' | 'system.login.slider' | 'system.login.device' | 'system.login.error' | 'system.login.auth' | 'system.offline' | 'system.offline.network' | 'system.offline.kickoff' | 'system.online' | (string & {});
|
|
14
|
+
export interface SideEventParts {
|
|
15
|
+
scene_type: string;
|
|
16
|
+
sub_type: string;
|
|
17
|
+
}
|
|
18
|
+
/** OneBot / icqq 等平台 notice_type 原始值 → 标准 scene_type + sub_type */
|
|
19
|
+
export declare const ONEBOT_NOTICE_PARTS_MAP: Record<string, SideEventParts>;
|
|
20
|
+
/** KOOK extra.type 原始值 → 标准 scene_type + sub_type */
|
|
21
|
+
export declare const KOOK_NOTICE_PARTS_MAP: Record<string, SideEventParts>;
|
|
22
|
+
/** Slack event type 原始值 → 标准 scene_type + sub_type */
|
|
23
|
+
export declare const SLACK_NOTICE_PARTS_MAP: Record<string, SideEventParts>;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Side Event 标准类型。
|
|
3
|
+
* 运行时 `$type` 仅存命名空间(`notice` / `request` / `system`);
|
|
4
|
+
* 完整名由 `${$type}.${$scene_type}.${$sub_type}` 组合。
|
|
5
|
+
*/
|
|
6
|
+
/** OneBot / icqq 等平台 notice_type 原始值 → 标准 scene_type + sub_type */
|
|
7
|
+
export const ONEBOT_NOTICE_PARTS_MAP = {
|
|
8
|
+
group_increase: { scene_type: 'group', sub_type: 'member_increase' },
|
|
9
|
+
group_decrease: { scene_type: 'group', sub_type: 'member_decrease' },
|
|
10
|
+
group_admin: { scene_type: 'group', sub_type: 'admin_change' },
|
|
11
|
+
group_ban: { scene_type: 'group', sub_type: 'ban' },
|
|
12
|
+
group_recall: { scene_type: 'group', sub_type: 'recall' },
|
|
13
|
+
friend_recall: { scene_type: 'friend', sub_type: 'recall' },
|
|
14
|
+
friend_add: { scene_type: 'friend', sub_type: 'increase' },
|
|
15
|
+
group_upload: { scene_type: 'group', sub_type: 'upload' },
|
|
16
|
+
group_transfer: { scene_type: 'group', sub_type: 'transfer' },
|
|
17
|
+
group_card: { scene_type: 'group', sub_type: 'card_change' },
|
|
18
|
+
group_msg_emoji_like: { scene_type: 'group', sub_type: 'emoji_reaction' },
|
|
19
|
+
'group.increase': { scene_type: 'group', sub_type: 'member_increase' },
|
|
20
|
+
'group.decrease': { scene_type: 'group', sub_type: 'member_decrease' },
|
|
21
|
+
'group.admin': { scene_type: 'group', sub_type: 'admin_change' },
|
|
22
|
+
'group.ban': { scene_type: 'group', sub_type: 'ban' },
|
|
23
|
+
'group.recall': { scene_type: 'group', sub_type: 'recall' },
|
|
24
|
+
'friend.increase': { scene_type: 'friend', sub_type: 'increase' },
|
|
25
|
+
'friend.decrease': { scene_type: 'friend', sub_type: 'recall' },
|
|
26
|
+
'friend.recall': { scene_type: 'friend', sub_type: 'recall' },
|
|
27
|
+
};
|
|
28
|
+
/** KOOK extra.type 原始值 → 标准 scene_type + sub_type */
|
|
29
|
+
export const KOOK_NOTICE_PARTS_MAP = {
|
|
30
|
+
joined_guild: { scene_type: 'group', sub_type: 'member_increase' },
|
|
31
|
+
exited_guild: { scene_type: 'group', sub_type: 'member_decrease' },
|
|
32
|
+
deleted_message: { scene_type: 'group', sub_type: 'recall' },
|
|
33
|
+
deleted_private_message: { scene_type: 'friend', sub_type: 'recall' },
|
|
34
|
+
added_reaction: { scene_type: 'group', sub_type: 'emoji_reaction' },
|
|
35
|
+
deleted_reaction: { scene_type: 'group', sub_type: 'emoji_reaction' },
|
|
36
|
+
private_added_reaction: { scene_type: 'group', sub_type: 'emoji_reaction' },
|
|
37
|
+
private_deleted_reaction: { scene_type: 'group', sub_type: 'emoji_reaction' },
|
|
38
|
+
};
|
|
39
|
+
/** Slack event type 原始值 → 标准 scene_type + sub_type */
|
|
40
|
+
export const SLACK_NOTICE_PARTS_MAP = {
|
|
41
|
+
member_joined_channel: { scene_type: 'group', sub_type: 'member_increase' },
|
|
42
|
+
member_left_channel: { scene_type: 'group', sub_type: 'member_decrease' },
|
|
43
|
+
reaction_added: { scene_type: 'group', sub_type: 'emoji_reaction' },
|
|
44
|
+
reaction_removed: { scene_type: 'group', sub_type: 'emoji_reaction' },
|
|
45
|
+
message_deleted: { scene_type: 'group', sub_type: 'recall' },
|
|
46
|
+
channel_archive: { scene_type: 'slack', sub_type: 'channel_archive' },
|
|
47
|
+
channel_unarchive: { scene_type: 'slack', sub_type: 'channel_unarchive' },
|
|
48
|
+
channel_rename: { scene_type: 'slack', sub_type: 'channel_rename' },
|
|
49
|
+
channel_created: { scene_type: 'slack', sub_type: 'channel_created' },
|
|
50
|
+
channel_deleted: { scene_type: 'slack', sub_type: 'channel_deleted' },
|
|
51
|
+
pin_added: { scene_type: 'slack', sub_type: 'pin_added' },
|
|
52
|
+
pin_removed: { scene_type: 'slack', sub_type: 'pin_removed' },
|
|
53
|
+
app_home_opened: { scene_type: 'slack', sub_type: 'app_home_opened' },
|
|
54
|
+
team_join: { scene_type: 'friend', sub_type: 'increase' },
|
|
55
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Adapters } from './adapter.js';
|
|
2
|
+
import type { SideEventBase } from './side-event/base.js';
|
|
3
|
+
/**
|
|
4
|
+
* 系统/登录侧事件(扫码、滑块、掉线等)。
|
|
5
|
+
* `$scene_type`:`login` / `offline` / `online` 等;
|
|
6
|
+
* `$sub_type`:`qrcode` / `slider` / `device` / `kickoff` / `network` 等。
|
|
7
|
+
*/
|
|
8
|
+
export interface SystemEventBase extends SideEventBase {
|
|
9
|
+
$adapter: keyof Adapters;
|
|
10
|
+
$type: 'system';
|
|
11
|
+
}
|
|
12
|
+
export type SystemEvent<T extends object = {}> = SystemEventBase & T;
|
|
13
|
+
export declare namespace SystemEvent {
|
|
14
|
+
function from<T extends object>(input: T, format: SystemEventBase): SystemEvent<T>;
|
|
15
|
+
}
|