@zhin.js/core 1.5.15 → 1.6.0
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 +78 -195
- package/lib/ai-completion-contract.d.ts +135 -0
- package/lib/ai-completion-contract.js +69 -0
- package/lib/built/ai-access.d.ts +2 -21
- package/lib/built/ai-access.js +1 -46
- package/lib/built/ai-outbound/index.d.ts +0 -2
- package/lib/built/ai-outbound/index.js +0 -2
- package/lib/built/ai-outbound/prompt.d.ts +2 -0
- package/lib/built/ai-outbound/prompt.js +2 -0
- package/lib/built/ai-outbound/types.d.ts +1 -10
- package/lib/built/ai-trigger.d.ts +39 -78
- package/lib/built/ai-trigger.js +3 -254
- package/lib/built/common-adapter-tools.d.ts +21 -6
- package/lib/built/common-adapter-tools.js +28 -17
- package/lib/built/generic-segment-mapper.js +4 -1
- package/lib/built/html-segment-fallback.d.ts +6 -7
- package/lib/built/html-segment-fallback.js +1 -16
- package/lib/built/html-to-text.d.ts +0 -3
- package/lib/built/html-to-text.js +131 -40
- package/lib/built/interaction-messages.d.ts +1 -0
- package/lib/built/interaction-messages.js +30 -0
- package/lib/built/interactive-segments/action.d.ts +3 -4
- package/lib/built/interactive-segments/action.js +2 -5
- package/lib/built/interactive-segments/index.d.ts +0 -2
- package/lib/built/interactive-segments/index.js +0 -2
- package/lib/built/interactive-segments/keyboard-segment.d.ts +0 -1
- package/lib/built/interactive-segments/keyboard-segment.js +0 -1
- package/lib/built/interactive-segments/onebot-keyboard.d.ts +0 -1
- package/lib/built/interactive-segments/onebot-keyboard.js +0 -2
- package/lib/built/interactive-segments/resolve.d.ts +2 -3
- package/lib/built/interactive-segments/resolve.js +21 -14
- package/lib/built/interactive-segments/types.d.ts +2 -7
- package/lib/built/interactive-segments/types.js +22 -2
- package/lib/built/login-assist.d.ts +13 -11
- package/lib/built/login-assist.js +32 -26
- package/lib/built/message-enrich.d.ts +24 -27
- package/lib/built/message-enrich.js +53 -49
- package/lib/built/outbound-content-arrays.d.ts +4 -0
- package/lib/built/outbound-content-arrays.js +32 -0
- package/lib/built/outbound-media-trust.d.ts +46 -0
- package/lib/built/outbound-media-trust.js +245 -0
- package/lib/built/outbound-media-utils.d.ts +5 -3
- package/lib/built/outbound-media-utils.js +5 -3
- package/lib/built/readable-link.d.ts +4 -0
- package/lib/built/readable-link.js +32 -0
- package/lib/built/rich-segments/markdown-to-text.d.ts +1 -2
- package/lib/built/rich-segments/markdown-to-text.js +141 -17
- package/lib/built/roles.d.ts +141 -12
- package/lib/built/roles.js +253 -52
- package/lib/built/segment-contract/assert.js +8 -2
- package/lib/built/segment-contract/delivery.js +1 -0
- package/lib/built/segment-contract/index.d.ts +3 -3
- package/lib/built/segment-contract/index.js +2 -2
- package/lib/built/segment-contract/json-schema.d.ts +39 -5
- package/lib/built/segment-contract/json-schema.js +207 -24
- package/lib/built/segment-contract/preview.js +8 -1
- package/lib/built/segment-contract/text.js +1 -1
- package/lib/built/segment-contract/types.d.ts +2 -2
- package/lib/built/segment-contract/validate.d.ts +1553 -224
- package/lib/built/segment-contract/validate.js +39 -3
- package/lib/built/tool-access.d.ts +5 -0
- package/lib/built/tool-access.js +17 -0
- package/lib/built/user-interaction.d.ts +5 -4
- package/lib/built/user-interaction.js +64 -52
- package/lib/errors.d.ts +1 -18
- package/lib/errors.js +1 -26
- package/lib/feature/command-public-api.d.ts +5 -0
- package/lib/feature/command-public-api.js +5 -0
- package/lib/feature/command.d.ts +2 -0
- package/lib/feature/command.js +1 -0
- package/lib/feature/component.d.ts +1 -0
- package/lib/feature/component.js +1 -0
- package/lib/feature/handler.d.ts +13 -7
- package/lib/feature/handler.js +2 -1
- package/lib/feature/middleware-public-api.d.ts +6 -0
- package/lib/feature/middleware-public-api.js +6 -0
- package/lib/feature/middleware.d.ts +22 -2
- package/lib/feature/middleware.js +7 -2
- package/lib/im-scene.d.ts +4 -3
- package/lib/im-scene.js +9 -9
- package/lib/im-session-id.d.ts +20 -12
- package/lib/im-session-id.js +8 -8
- package/lib/index.d.ts +19 -48
- package/lib/index.js +14 -41
- package/lib/jsx/intrinsic-elements.d.ts +83 -0
- package/lib/jsx/message-renderer.d.ts +13 -0
- package/lib/jsx/message-renderer.js +128 -0
- package/lib/jsx/message-tags.d.ts +133 -0
- package/lib/jsx/message-tags.js +50 -0
- package/lib/jsx-dev-runtime.d.ts +2 -2
- package/lib/jsx-dev-runtime.js +1 -2
- package/lib/jsx-runtime.d.ts +2 -12
- package/lib/jsx-runtime.js +1 -10
- package/lib/jsx.d.ts +6 -30
- package/lib/jsx.js +3 -93
- package/lib/message.d.ts +0 -40
- package/lib/message.js +1 -27
- package/lib/models/system-log.d.ts +0 -2
- package/lib/models/system-log.js +1 -8
- package/lib/models/user.d.ts +0 -2
- package/lib/models/user.js +1 -7
- package/lib/notice.d.ts +38 -33
- package/lib/notice.js +23 -7
- package/lib/plugin-runtime/im/command-feedback.d.ts +59 -0
- package/lib/plugin-runtime/im/command-feedback.js +148 -0
- package/lib/plugin-runtime/im/contracts.d.ts +217 -32
- package/lib/plugin-runtime/im/contracts.js +141 -23
- package/lib/plugin-runtime/im/conversation-runtime.d.ts +42 -0
- package/lib/plugin-runtime/im/conversation-runtime.js +451 -0
- package/lib/plugin-runtime/im/endpoint-runtime.d.ts +89 -0
- package/lib/plugin-runtime/im/endpoint-runtime.js +381 -0
- package/lib/plugin-runtime/im/feature-gate.d.ts +21 -0
- package/lib/plugin-runtime/im/feature-gate.js +88 -0
- package/lib/plugin-runtime/im/host/component-host-installer.d.ts +2 -0
- package/lib/plugin-runtime/im/host/component-host-installer.js +14 -0
- package/lib/plugin-runtime/im/host/conversation-migration.d.ts +5 -0
- package/lib/plugin-runtime/im/host/conversation-migration.js +75 -0
- package/lib/plugin-runtime/im/host/database-config.d.ts +10 -0
- package/lib/plugin-runtime/im/host/database-config.js +114 -0
- package/lib/plugin-runtime/im/host/database-host-installer.d.ts +29 -0
- package/lib/plugin-runtime/im/host/database-host-installer.js +442 -0
- package/lib/plugin-runtime/im/host/database-state.d.ts +9 -0
- package/lib/plugin-runtime/im/host/database-state.js +91 -0
- package/lib/plugin-runtime/im/host/index.d.ts +8 -0
- package/lib/plugin-runtime/im/host/index.js +8 -0
- package/lib/plugin-runtime/im/host/locale-host-installer.d.ts +3 -0
- package/lib/plugin-runtime/im/host/locale-host-installer.js +60 -0
- package/lib/plugin-runtime/im/host/outbound-host-installer.d.ts +8 -0
- package/lib/plugin-runtime/im/host/outbound-host-installer.js +153 -0
- package/lib/plugin-runtime/im/host/sender-enrichment.d.ts +34 -0
- package/lib/plugin-runtime/im/host/sender-enrichment.js +82 -0
- package/lib/plugin-runtime/im/im-runtime.d.ts +40 -111
- package/lib/plugin-runtime/im/im-runtime.js +234 -1059
- package/lib/plugin-runtime/im/inbound-dedup.d.ts +84 -0
- package/lib/plugin-runtime/im/inbound-dedup.js +322 -0
- package/lib/plugin-runtime/im/inbound-origin.d.ts +150 -0
- package/lib/plugin-runtime/im/inbound-origin.js +183 -0
- package/lib/plugin-runtime/im/inbound-runtime.d.ts +59 -0
- package/lib/plugin-runtime/im/inbound-runtime.js +478 -0
- package/lib/plugin-runtime/im/inbound-spine.d.ts +196 -0
- package/lib/plugin-runtime/im/inbound-spine.js +335 -0
- package/lib/plugin-runtime/im/index.d.ts +15 -4
- package/lib/plugin-runtime/im/index.js +11 -4
- package/lib/plugin-runtime/im/interaction-runtime.d.ts +50 -0
- package/lib/plugin-runtime/im/interaction-runtime.js +390 -0
- package/lib/plugin-runtime/im/interactive-router.d.ts +81 -0
- package/lib/plugin-runtime/im/interactive-router.js +382 -0
- package/lib/plugin-runtime/im/message-diagnostics.d.ts +70 -0
- package/lib/plugin-runtime/im/message-diagnostics.js +182 -0
- package/lib/plugin-runtime/im/message-dispatcher.d.ts +18 -4
- package/lib/plugin-runtime/im/message-dispatcher.js +138 -20
- package/lib/plugin-runtime/im/message-events.d.ts +85 -0
- package/lib/plugin-runtime/im/message-events.js +113 -0
- package/lib/plugin-runtime/im/outbound-delivery-runtime.d.ts +39 -0
- package/lib/plugin-runtime/im/outbound-delivery-runtime.js +450 -0
- package/lib/plugin-runtime/im/outbound-renderer.d.ts +52 -3
- package/lib/plugin-runtime/im/outbound-renderer.js +188 -8
- package/lib/plugin-runtime/im/outbound-segments.d.ts +29 -5
- package/lib/plugin-runtime/im/outbound-segments.js +130 -36
- package/lib/plugin-runtime/im/progressive-reply.d.ts +58 -0
- package/lib/plugin-runtime/im/progressive-reply.js +501 -0
- package/lib/plugin-runtime/im/public-api.d.ts +1 -1
- package/lib/request.d.ts +27 -36
- package/lib/request.js +14 -6
- package/lib/side-event/base.d.ts +64 -44
- package/lib/side-event/base.js +72 -19
- package/lib/side-event/index.d.ts +1 -1
- package/lib/side-event/index.js +1 -1
- package/lib/side-event/normalize.d.ts +7 -38
- package/lib/side-event/normalize.js +4 -109
- package/lib/side-event/scene-events.d.ts +40 -0
- package/lib/side-event/scene-events.js +147 -0
- package/lib/side-event/types.d.ts +4 -13
- package/lib/side-event/types.js +1 -55
- package/lib/system-event.d.ts +17 -12
- package/lib/system-event.js +8 -6
- package/lib/types.d.ts +23 -167
- package/lib/utils.d.ts +50 -33
- package/lib/utils.js +12 -185
- package/lib/venue/contracts.d.ts +21 -0
- package/lib/venue/contracts.js +3 -0
- package/lib/venue/floor-controller.d.ts +11 -0
- package/lib/venue/floor-controller.js +63 -0
- package/lib/venue/index.d.ts +13 -0
- package/lib/venue/index.js +11 -0
- package/lib/venue/membership-port.d.ts +23 -0
- package/lib/venue/membership-port.js +141 -0
- package/lib/venue/projector.d.ts +38 -0
- package/lib/venue/projector.js +45 -0
- package/lib/venue/registry.d.ts +16 -0
- package/lib/venue/registry.js +63 -0
- package/lib/venue/router.d.ts +19 -0
- package/lib/venue/router.js +101 -0
- package/lib/venue/send-limiter.d.ts +17 -0
- package/lib/venue/send-limiter.js +73 -0
- package/lib/venue/validator.d.ts +6 -0
- package/lib/venue/validator.js +160 -0
- package/package.json +24 -50
- package/lib/adapter.d.ts +0 -145
- package/lib/adapter.js +0 -377
- package/lib/built/adapter-process.d.ts +0 -58
- package/lib/built/adapter-process.js +0 -128
- package/lib/built/agent-preset.d.ts +0 -64
- package/lib/built/agent-preset.js +0 -79
- package/lib/built/ai-outbound/adapter-access.d.ts +0 -3
- package/lib/built/ai-outbound/adapter-access.js +0 -9
- package/lib/built/ai-outbound/extensions/qq-message.d.ts +0 -3
- package/lib/built/ai-outbound/extensions/qq-message.js +0 -23
- package/lib/built/authorization.d.ts +0 -10
- package/lib/built/authorization.js +0 -76
- package/lib/built/command.d.ts +0 -72
- package/lib/built/command.js +0 -105
- package/lib/built/component.d.ts +0 -67
- package/lib/built/component.js +0 -97
- package/lib/built/config.d.ts +0 -98
- package/lib/built/config.js +0 -372
- package/lib/built/connect-endpoint-instance.d.ts +0 -17
- package/lib/built/connect-endpoint-instance.js +0 -42
- package/lib/built/database.d.ts +0 -68
- package/lib/built/database.js +0 -106
- package/lib/built/dispatcher.d.ts +0 -141
- package/lib/built/dispatcher.js +0 -383
- package/lib/built/endpoint-commands.d.ts +0 -3
- package/lib/built/endpoint-commands.js +0 -99
- package/lib/built/endpoint-lifecycle-service.d.ts +0 -28
- package/lib/built/endpoint-lifecycle-service.js +0 -242
- package/lib/built/endpoint-lifecycle.d.ts +0 -27
- package/lib/built/endpoint-lifecycle.js +0 -36
- package/lib/built/endpoint-manager.d.ts +0 -34
- package/lib/built/html-renderer-loader.d.ts +0 -13
- package/lib/built/html-renderer-loader.js +0 -33
- package/lib/built/inbound-pipeline.d.ts +0 -37
- package/lib/built/inbound-pipeline.js +0 -63
- package/lib/built/inbound-runner.d.ts +0 -22
- package/lib/built/inbound-runner.js +0 -34
- package/lib/built/interactive-segment-contract.d.ts +0 -6
- package/lib/built/interactive-segment-contract.js +0 -9
- package/lib/built/interactive-segments/fallback-store.d.ts +0 -29
- package/lib/built/interactive-segments/fallback-store.js +0 -63
- package/lib/built/interactive-segments/handlers.d.ts +0 -16
- package/lib/built/interactive-segments/handlers.js +0 -74
- package/lib/built/introspection-format.d.ts +0 -10
- package/lib/built/introspection-format.js +0 -28
- package/lib/built/management-command-guard.d.ts +0 -15
- package/lib/built/management-command-guard.js +0 -25
- package/lib/built/message-filter.d.ts +0 -176
- package/lib/built/message-filter.js +0 -239
- package/lib/built/optional-peer-import.d.ts +0 -3
- package/lib/built/optional-peer-import.js +0 -33
- package/lib/built/outbound-media-contract.d.ts +0 -22
- package/lib/built/outbound-media-contract.js +0 -10
- package/lib/built/permission.d.ts +0 -51
- package/lib/built/permission.js +0 -99
- package/lib/built/permit-check.d.ts +0 -7
- package/lib/built/permit-check.js +0 -35
- package/lib/built/permit-parse.d.ts +0 -16
- package/lib/built/permit-parse.js +0 -32
- package/lib/built/platform-permit.d.ts +0 -20
- package/lib/built/platform-permit.js +0 -91
- package/lib/built/queue-im-field-contract.d.ts +0 -32
- package/lib/built/queue-im-field-contract.js +0 -67
- package/lib/built/rich-segments/adapter-policies.d.ts +0 -9
- package/lib/built/rich-segments/adapter-policies.js +0 -27
- package/lib/built/rich-segments/base.d.ts +0 -11
- package/lib/built/rich-segments/base.js +0 -24
- package/lib/built/rich-segments/builtins.d.ts +0 -4
- package/lib/built/rich-segments/builtins.js +0 -40
- package/lib/built/rich-segments/capabilities.d.ts +0 -6
- package/lib/built/rich-segments/capabilities.js +0 -38
- package/lib/built/rich-segments/html-segment.d.ts +0 -15
- package/lib/built/rich-segments/html-segment.js +0 -62
- package/lib/built/rich-segments/index.d.ts +0 -13
- package/lib/built/rich-segments/index.js +0 -13
- package/lib/built/rich-segments/markdown-segment.d.ts +0 -14
- package/lib/built/rich-segments/markdown-segment.js +0 -58
- package/lib/built/rich-segments/qrcode-segment.d.ts +0 -18
- package/lib/built/rich-segments/qrcode-segment.js +0 -73
- package/lib/built/rich-segments/registry.d.ts +0 -16
- package/lib/built/rich-segments/registry.js +0 -52
- package/lib/built/rich-segments/resolve.d.ts +0 -5
- package/lib/built/rich-segments/resolve.js +0 -87
- package/lib/built/rich-segments/tts-segment.d.ts +0 -13
- package/lib/built/rich-segments/tts-segment.js +0 -51
- package/lib/built/rich-segments/types.d.ts +0 -79
- package/lib/built/rich-segments/types.js +0 -17
- package/lib/built/runtime-io.d.ts +0 -9
- package/lib/built/runtime-io.js +0 -67
- package/lib/built/schedule.d.ts +0 -54
- package/lib/built/schedule.js +0 -112
- package/lib/built/schema-endpoint-manager.d.ts +0 -17
- package/lib/built/schema-endpoint-manager.js +0 -73
- package/lib/built/schema-feature.d.ts +0 -77
- package/lib/built/schema-feature.js +0 -130
- package/lib/built/skill.d.ts +0 -120
- package/lib/built/skill.js +0 -151
- package/lib/built/speech-loader.d.ts +0 -14
- package/lib/built/speech-loader.js +0 -32
- package/lib/built/tool.d.ts +0 -151
- package/lib/built/tool.js +0 -388
- package/lib/command.d.ts +0 -50
- package/lib/command.js +0 -106
- package/lib/component.d.ts +0 -26
- package/lib/component.js +0 -583
- package/lib/endpoint-capabilities.d.ts +0 -46
- package/lib/endpoint-capabilities.js +0 -55
- package/lib/endpoint.d.ts +0 -19
- package/lib/endpoint.js +0 -3
- package/lib/host-plugin-registry.d.ts +0 -8
- package/lib/host-plugin-registry.js +0 -12
- package/lib/plugin-context.d.ts +0 -27
- package/lib/plugin-context.js +0 -64
- package/lib/plugin-runtime/im/interactive.d.ts +0 -26
- package/lib/plugin-runtime/im/interactive.js +0 -46
- package/lib/plugin-runtime/im/login-assist-host.d.ts +0 -6
- package/lib/plugin-runtime/im/login-assist-host.js +0 -6
- package/lib/plugin-runtime/im/message-bus.d.ts +0 -38
- package/lib/plugin-runtime/im/message-bus.js +0 -40
- package/lib/plugin-runtime/im/service-tokens.d.ts +0 -18
- package/lib/plugin-runtime/im/service-tokens.js +0 -13
- package/lib/plugin.d.ts +0 -268
- package/lib/plugin.js +0 -583
- package/lib/schema-interaction.d.ts +0 -117
- package/lib/schema-interaction.js +0 -247
- package/lib/side-event/dispatch.d.ts +0 -15
- package/lib/side-event/dispatch.js +0 -140
- package/lib/tool-zod.d.ts +0 -43
- package/lib/tool-zod.js +0 -184
- /package/lib/{built/endpoint-manager.js → jsx/intrinsic-elements.js} +0 -0
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Inbound runner — one ordered entry for IM message.receive processing.
|
|
3
|
-
*/
|
|
4
|
-
function getDispatcher(plugin) {
|
|
5
|
-
const dispatcher = plugin?.inject('dispatcher');
|
|
6
|
-
if (dispatcher && typeof dispatcher.dispatch === 'function') {
|
|
7
|
-
return dispatcher;
|
|
8
|
-
}
|
|
9
|
-
return undefined;
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* Ordered IM inbound pipeline:
|
|
13
|
-
* root plugin middleware (命令、Prompt / ask_user 等一次性监听) → 作为终端调用
|
|
14
|
-
* MessageDispatcher(护栏 / 路由 / AI)→ 根插件 `message.receive` 生命周期 → adapter observers。
|
|
15
|
-
*
|
|
16
|
-
* 适配器可能挂在子插件上,故中间件始终走 `plugin.root`,与 `addMiddleware` 注册在根插件上的
|
|
17
|
-
* Agent / 业务逻辑一致。
|
|
18
|
-
*/
|
|
19
|
-
export async function runInboundMessage(options) {
|
|
20
|
-
const { plugin, message, emitAdapterObservers } = options;
|
|
21
|
-
const dispatcher = getDispatcher(plugin);
|
|
22
|
-
const root = plugin?.root;
|
|
23
|
-
if (dispatcher && root) {
|
|
24
|
-
await root.middleware(message, async () => {
|
|
25
|
-
await dispatcher.dispatch(message);
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
else if (dispatcher) {
|
|
29
|
-
await dispatcher.dispatch(message);
|
|
30
|
-
}
|
|
31
|
-
plugin?.dispatch('message.receive', message);
|
|
32
|
-
emitAdapterObservers();
|
|
33
|
-
return { dispatched: !!dispatcher };
|
|
34
|
-
}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type { InteractivePolicy } from './interactive-segments/types.js';
|
|
2
|
-
/** 契约测试:adapter 须声明 interactivePolicy */
|
|
3
|
-
export declare function assertAdapterDeclaresInteractivePolicy(adapterClass: {
|
|
4
|
-
interactivePolicy?: InteractivePolicy;
|
|
5
|
-
}): void;
|
|
6
|
-
export type { InteractivePolicy };
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/** 契约测试:adapter 须声明 interactivePolicy */
|
|
2
|
-
export function assertAdapterDeclaresInteractivePolicy(adapterClass) {
|
|
3
|
-
if (!adapterClass.interactivePolicy) {
|
|
4
|
-
throw new Error('Adapter must declare static interactivePolicy');
|
|
5
|
-
}
|
|
6
|
-
if (adapterClass.interactivePolicy !== 'native' && adapterClass.interactivePolicy !== 'text') {
|
|
7
|
-
throw new Error('interactivePolicy must be "native" or "text"');
|
|
8
|
-
}
|
|
9
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* keyboard 文本降级 fallback map 的中央存储。
|
|
3
|
-
*
|
|
4
|
-
* 出站:端点 interactive 策略为 'text' 时,框架把 keyboard 段降级为编号文本,
|
|
5
|
-
* 同时把「数字 → payload」映射按频道写入本存储(后写覆盖先写,等价
|
|
6
|
-
* game-kit lastMenus 的“最近一张键盘”语义)。
|
|
7
|
-
* 入站:框架中间件 / dispatcher 钩子用本存储把用户回复的裸数字解析回
|
|
8
|
-
* payload,再按 prefix 最长匹配路由给注册的 interactive handler。
|
|
9
|
-
*
|
|
10
|
-
* 模块级共享实例与 handlers.ts 的 handler 注册表同例:状态按频道键控、
|
|
11
|
-
* TTL 有界(对齐 game-hub 菜单上下文的 1h),无裸悬挂业务对象。
|
|
12
|
-
*/
|
|
13
|
-
export declare const KEYBOARD_FALLBACK_TTL_MS: number;
|
|
14
|
-
export declare class KeyboardFallbackStore {
|
|
15
|
-
#private;
|
|
16
|
-
private readonly defaultTtlMs;
|
|
17
|
-
constructor(defaultTtlMs?: number);
|
|
18
|
-
/** 记录频道最近一次 keyboard 降级的数字→payload 映射(空 map 忽略)。 */
|
|
19
|
-
remember(channelKey: string, map: Record<string, string>, ttlMs?: number): void;
|
|
20
|
-
/** 频道当前有效的 fallback map(过期即删并返回 undefined)。 */
|
|
21
|
-
mapFor(channelKey: string): Record<string, string> | undefined;
|
|
22
|
-
/** 裸数字 / fallback 键 → payload(无映射或过期返回 undefined)。 */
|
|
23
|
-
resolve(channelKey: string, raw: string): string | undefined;
|
|
24
|
-
clear(): void;
|
|
25
|
-
}
|
|
26
|
-
/** 中央共享实例:出站降级写入、入站回跳读取。 */
|
|
27
|
-
export declare const keyboardFallbackStore: KeyboardFallbackStore;
|
|
28
|
-
/** 测试专用:清空中央 fallback 存储。 */
|
|
29
|
-
export declare function resetKeyboardFallbackStoreForTests(): void;
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { resolveTextFallbackPayload } from './action.js';
|
|
2
|
-
/**
|
|
3
|
-
* keyboard 文本降级 fallback map 的中央存储。
|
|
4
|
-
*
|
|
5
|
-
* 出站:端点 interactive 策略为 'text' 时,框架把 keyboard 段降级为编号文本,
|
|
6
|
-
* 同时把「数字 → payload」映射按频道写入本存储(后写覆盖先写,等价
|
|
7
|
-
* game-kit lastMenus 的“最近一张键盘”语义)。
|
|
8
|
-
* 入站:框架中间件 / dispatcher 钩子用本存储把用户回复的裸数字解析回
|
|
9
|
-
* payload,再按 prefix 最长匹配路由给注册的 interactive handler。
|
|
10
|
-
*
|
|
11
|
-
* 模块级共享实例与 handlers.ts 的 handler 注册表同例:状态按频道键控、
|
|
12
|
-
* TTL 有界(对齐 game-hub 菜单上下文的 1h),无裸悬挂业务对象。
|
|
13
|
-
*/
|
|
14
|
-
export const KEYBOARD_FALLBACK_TTL_MS = 60 * 60 * 1000;
|
|
15
|
-
export class KeyboardFallbackStore {
|
|
16
|
-
defaultTtlMs;
|
|
17
|
-
#entries = new Map();
|
|
18
|
-
constructor(defaultTtlMs = KEYBOARD_FALLBACK_TTL_MS) {
|
|
19
|
-
this.defaultTtlMs = defaultTtlMs;
|
|
20
|
-
}
|
|
21
|
-
/** 记录频道最近一次 keyboard 降级的数字→payload 映射(空 map 忽略)。 */
|
|
22
|
-
remember(channelKey, map, ttlMs = this.defaultTtlMs) {
|
|
23
|
-
if (Object.keys(map).length === 0)
|
|
24
|
-
return;
|
|
25
|
-
this.#prune();
|
|
26
|
-
this.#entries.set(channelKey, {
|
|
27
|
-
map: Object.freeze({ ...map }),
|
|
28
|
-
expiresAt: Date.now() + ttlMs,
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
/** 频道当前有效的 fallback map(过期即删并返回 undefined)。 */
|
|
32
|
-
mapFor(channelKey) {
|
|
33
|
-
const entry = this.#entries.get(channelKey);
|
|
34
|
-
if (!entry)
|
|
35
|
-
return undefined;
|
|
36
|
-
if (entry.expiresAt < Date.now()) {
|
|
37
|
-
this.#entries.delete(channelKey);
|
|
38
|
-
return undefined;
|
|
39
|
-
}
|
|
40
|
-
return entry.map;
|
|
41
|
-
}
|
|
42
|
-
/** 裸数字 / fallback 键 → payload(无映射或过期返回 undefined)。 */
|
|
43
|
-
resolve(channelKey, raw) {
|
|
44
|
-
const map = this.mapFor(channelKey);
|
|
45
|
-
return map ? resolveTextFallbackPayload(raw, map) : undefined;
|
|
46
|
-
}
|
|
47
|
-
clear() {
|
|
48
|
-
this.#entries.clear();
|
|
49
|
-
}
|
|
50
|
-
#prune() {
|
|
51
|
-
const now = Date.now();
|
|
52
|
-
for (const [key, entry] of this.#entries) {
|
|
53
|
-
if (entry.expiresAt < now)
|
|
54
|
-
this.#entries.delete(key);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
/** 中央共享实例:出站降级写入、入站回跳读取。 */
|
|
59
|
-
export const keyboardFallbackStore = new KeyboardFallbackStore();
|
|
60
|
-
/** 测试专用:清空中央 fallback 存储。 */
|
|
61
|
-
export function resetKeyboardFallbackStoreForTests() {
|
|
62
|
-
keyboardFallbackStore.clear();
|
|
63
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { Message } from '../../message.js';
|
|
2
|
-
import type { MessageMiddleware } from '../../types.js';
|
|
3
|
-
import type { InteractiveHandler, RegisteredInteractiveHandler } from './types.js';
|
|
4
|
-
/** 旧轨频道键:与出站降级(Adapter.renderSendMessage)及 game-kit channelKey 一致。 */
|
|
5
|
-
export declare function interactiveChannelKey(message: Message<any>): string;
|
|
6
|
-
/**
|
|
7
|
-
* 文本回跳解析:中央 fallback map(裸数字)→ payload;
|
|
8
|
-
* 或 QQ 指令预填等直出 `prefix:session:id` payload。
|
|
9
|
-
*/
|
|
10
|
-
export declare function resolveInboundTextPayload(message: Message<any>): string | undefined;
|
|
11
|
-
export declare function registerInteractiveHandler(prefix: string, handler: InteractiveHandler): () => void;
|
|
12
|
-
export declare function getInteractiveHandlers(): readonly RegisteredInteractiveHandler[];
|
|
13
|
-
export declare function resetInteractiveHandlersForTests(): void;
|
|
14
|
-
/** 在根插件上安装一次性 action 路由中间件(幂等) */
|
|
15
|
-
export declare function ensureInteractiveMiddleware(addMiddleware: (mw: MessageMiddleware) => () => void): void;
|
|
16
|
-
export declare function dispatchInteractiveAction(message: Message<any>): Promise<boolean>;
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import { getActionFromMessage, resolvePayloadFromText } from './action.js';
|
|
2
|
-
import { keyboardFallbackStore } from './fallback-store.js';
|
|
3
|
-
const handlers = [];
|
|
4
|
-
let middlewareInstalled = false;
|
|
5
|
-
function findHandler(payload) {
|
|
6
|
-
let match;
|
|
7
|
-
for (const entry of handlers) {
|
|
8
|
-
if (payload.startsWith(entry.prefix)) {
|
|
9
|
-
if (!match || entry.prefix.length > match.prefix.length) {
|
|
10
|
-
match = entry;
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
return match?.handler;
|
|
15
|
-
}
|
|
16
|
-
/** 旧轨频道键:与出站降级(Adapter.renderSendMessage)及 game-kit channelKey 一致。 */
|
|
17
|
-
export function interactiveChannelKey(message) {
|
|
18
|
-
return `${String(message.$adapter)}-${message.$endpoint}-${message.$channel.type}:${message.$channel.id}`;
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* 文本回跳解析:中央 fallback map(裸数字)→ payload;
|
|
22
|
-
* 或 QQ 指令预填等直出 `prefix:session:id` payload。
|
|
23
|
-
*/
|
|
24
|
-
export function resolveInboundTextPayload(message) {
|
|
25
|
-
const raw = message.$raw?.trim() ?? '';
|
|
26
|
-
if (!raw)
|
|
27
|
-
return undefined;
|
|
28
|
-
return resolvePayloadFromText(raw, keyboardFallbackStore.mapFor(interactiveChannelKey(message)));
|
|
29
|
-
}
|
|
30
|
-
export function registerInteractiveHandler(prefix, handler) {
|
|
31
|
-
const entry = { prefix, handler };
|
|
32
|
-
handlers.push(entry);
|
|
33
|
-
const dispose = () => {
|
|
34
|
-
const idx = handlers.indexOf(entry);
|
|
35
|
-
if (idx >= 0)
|
|
36
|
-
handlers.splice(idx, 1);
|
|
37
|
-
};
|
|
38
|
-
return dispose;
|
|
39
|
-
}
|
|
40
|
-
export function getInteractiveHandlers() {
|
|
41
|
-
return handlers;
|
|
42
|
-
}
|
|
43
|
-
export function resetInteractiveHandlersForTests() {
|
|
44
|
-
handlers.length = 0;
|
|
45
|
-
middlewareInstalled = false;
|
|
46
|
-
}
|
|
47
|
-
/** 在根插件上安装一次性 action 路由中间件(幂等) */
|
|
48
|
-
export function ensureInteractiveMiddleware(addMiddleware) {
|
|
49
|
-
if (middlewareInstalled)
|
|
50
|
-
return;
|
|
51
|
-
middlewareInstalled = true;
|
|
52
|
-
addMiddleware(async (message, next) => {
|
|
53
|
-
const payload = getActionFromMessage(message)?.payload
|
|
54
|
-
?? resolveInboundTextPayload(message);
|
|
55
|
-
if (!payload)
|
|
56
|
-
return next();
|
|
57
|
-
const handler = findHandler(payload);
|
|
58
|
-
if (!handler)
|
|
59
|
-
return next();
|
|
60
|
-
const handled = await handler(message);
|
|
61
|
-
if (handled)
|
|
62
|
-
return;
|
|
63
|
-
return next();
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
export async function dispatchInteractiveAction(message) {
|
|
67
|
-
const action = getActionFromMessage(message);
|
|
68
|
-
if (!action)
|
|
69
|
-
return false;
|
|
70
|
-
const handler = findHandler(action.payload);
|
|
71
|
-
if (!handler)
|
|
72
|
-
return false;
|
|
73
|
-
return !!(await handler(message));
|
|
74
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* IM 内省指令格式化(/cmd、/endpoints 等)
|
|
3
|
-
*/
|
|
4
|
-
export interface EndpointRow {
|
|
5
|
-
adapter: string;
|
|
6
|
-
name: string;
|
|
7
|
-
online: boolean;
|
|
8
|
-
}
|
|
9
|
-
export declare function formatEndpointsList(endpoints: EndpointRow[]): string;
|
|
10
|
-
export declare function endpointHelpText(): string;
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* IM 内省指令格式化(/cmd、/endpoints 等)
|
|
3
|
-
*/
|
|
4
|
-
export function formatEndpointsList(endpoints) {
|
|
5
|
-
if (endpoints.length === 0)
|
|
6
|
-
return '🤖 暂无 Endpoint 实例';
|
|
7
|
-
const lines = ['🤖 Endpoint 列表 (' + endpoints.length + ')', ''];
|
|
8
|
-
for (const b of [...endpoints].sort((a, c) => a.adapter.localeCompare(c.adapter) || a.name.localeCompare(c.name))) {
|
|
9
|
-
const mark = b.online ? '● online' : '○ offline';
|
|
10
|
-
lines.push(` ${mark} ${b.adapter}/${b.name}`);
|
|
11
|
-
}
|
|
12
|
-
return lines.join('\n');
|
|
13
|
-
}
|
|
14
|
-
export function endpointHelpText() {
|
|
15
|
-
return [
|
|
16
|
-
'Endpoint 运行时管理:',
|
|
17
|
-
'',
|
|
18
|
-
' /endpoint add [adapter] — 添加 endpoint(adapter 交互或 schema 向导)',
|
|
19
|
-
' /endpoint remove <adapter> <name>',
|
|
20
|
-
' /endpoint edit <adapter> <name>',
|
|
21
|
-
' /endpoint start <adapter> <name>',
|
|
22
|
-
' /endpoint stop <adapter> <name>',
|
|
23
|
-
' /endpoint cancel — 取消进行中的添加/绑定',
|
|
24
|
-
' /endpoint sync — 将内存 endpoint 写回 zhin.config',
|
|
25
|
-
' /endpoint help',
|
|
26
|
-
' /endpoints — 查看运行时在线状态',
|
|
27
|
-
].join('\n');
|
|
28
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* IM 运维 / Endpoint 管理斜杠命令:仅 master 或 trusted 可执行。
|
|
3
|
-
*/
|
|
4
|
-
import { resolveSenderRoles, type AITriggerConfig } from './ai-trigger.js';
|
|
5
|
-
import type { Message } from '../message.js';
|
|
6
|
-
import type { Plugin } from '../plugin.js';
|
|
7
|
-
export declare const MANAGEMENT_COMMAND_DENIED = "\u26A0\uFE0F \u8BE5\u547D\u4EE4\u4EC5 Endpoint Owner\uFF08master\uFF09\u6216 trusted \u64CD\u4F5C\u5458\u53EF\u7528\u3002";
|
|
8
|
-
/** 运维 / 内省 / Endpoint 管理命令:仅 master 或 trusted 可执行与展示 */
|
|
9
|
-
export declare const MANAGEMENT_OPERATOR_PERMIT: "role(master,trusted)";
|
|
10
|
-
/** Endpoint Owner 私聊专用命令(如 /approve) */
|
|
11
|
-
export declare const OWNER_OPERATOR_PERMIT: "role(master)";
|
|
12
|
-
export declare const OWNER_PRIVATE_PERMITS: readonly ["role(master)", "private(*)"];
|
|
13
|
-
export declare function resolveManagementCommandRoles(message: Message, root: Plugin, triggerConfig?: AITriggerConfig): ReturnType<typeof resolveSenderRoles>['roles'];
|
|
14
|
-
/** 通过返回 null;拒绝返回用户可见提示文案 */
|
|
15
|
-
export declare function rejectUnlessManagementOperator(message: Message, root: Plugin, triggerConfig?: AITriggerConfig): string | null;
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* IM 运维 / Endpoint 管理斜杠命令:仅 master 或 trusted 可执行。
|
|
3
|
-
*/
|
|
4
|
-
import { mergeAITriggerConfig, resolveSenderRoles, } from './ai-trigger.js';
|
|
5
|
-
import { hasSenderRole } from './roles.js';
|
|
6
|
-
export const MANAGEMENT_COMMAND_DENIED = '⚠️ 该命令仅 Endpoint Owner(master)或 trusted 操作员可用。';
|
|
7
|
-
/** 运维 / 内省 / Endpoint 管理命令:仅 master 或 trusted 可执行与展示 */
|
|
8
|
-
export const MANAGEMENT_OPERATOR_PERMIT = 'role(master,trusted)';
|
|
9
|
-
/** Endpoint Owner 私聊专用命令(如 /approve) */
|
|
10
|
-
export const OWNER_OPERATOR_PERMIT = 'role(master)';
|
|
11
|
-
export const OWNER_PRIVATE_PERMITS = [OWNER_OPERATOR_PERMIT, 'private(*)'];
|
|
12
|
-
export function resolveManagementCommandRoles(message, root, triggerConfig) {
|
|
13
|
-
const cfg = mergeAITriggerConfig(triggerConfig ?? {});
|
|
14
|
-
const adapterInstance = root.inject(message.$adapter);
|
|
15
|
-
const endpointConfig = adapterInstance?.endpoints?.get(message.$endpoint)?.$config;
|
|
16
|
-
return resolveSenderRoles(message, cfg, endpointConfig).roles;
|
|
17
|
-
}
|
|
18
|
-
/** 通过返回 null;拒绝返回用户可见提示文案 */
|
|
19
|
-
export function rejectUnlessManagementOperator(message, root, triggerConfig) {
|
|
20
|
-
const roles = resolveManagementCommandRoles(message, root, triggerConfig);
|
|
21
|
-
if (hasSenderRole(roles, 'trusted')) {
|
|
22
|
-
return null;
|
|
23
|
-
}
|
|
24
|
-
return MANAGEMENT_COMMAND_DENIED;
|
|
25
|
-
}
|
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* MessageFilterFeature — 消息过滤引擎
|
|
3
|
-
*
|
|
4
|
-
* 设计理念:
|
|
5
|
-
* 将过滤规则视为 Feature Item,与命令 (CommandFeature)、权限 (PermissionFeature) 同构,
|
|
6
|
-
* 遵循框架的 add/remove/extensions/toJSON 范式,支持插件级 CRUD 和生命周期自动回收。
|
|
7
|
-
*
|
|
8
|
-
* 核心特性:
|
|
9
|
-
* - 基于优先级的规则引擎(first-match-wins,类似防火墙规则)
|
|
10
|
-
* - 多维匹配:scope / adapter / endpoint / channel / sender
|
|
11
|
-
* - 支持精确匹配、通配符 `*`、正则 `/pattern/`
|
|
12
|
-
* - 通过 Dispatcher Guardrail 集成,在消息调度第一阶段拦截
|
|
13
|
-
* - 插件通过 `addFilterRule()` 动态注册规则,卸载时自动清理
|
|
14
|
-
*/
|
|
15
|
-
import { Feature, FeatureJSON } from '@zhin.js/kernel';
|
|
16
|
-
import type { Message, MessageType } from '../message.js';
|
|
17
|
-
/** 过滤动作 */
|
|
18
|
-
export type FilterAction = 'allow' | 'deny';
|
|
19
|
-
/** 匹配模式:精确字符串 / 正则表达式 */
|
|
20
|
-
export type FilterPattern = string | RegExp;
|
|
21
|
-
/** 消息作用域 */
|
|
22
|
-
export type FilterScope = MessageType;
|
|
23
|
-
/**
|
|
24
|
-
* 过滤规则
|
|
25
|
-
*
|
|
26
|
-
* 每条规则描述一组匹配条件和对应的动作。
|
|
27
|
-
* 所有条件之间为 AND 关系(必须全部满足),每个条件内部的多个值为 OR 关系(满足任一即可)。
|
|
28
|
-
* 未设置的条件视为匹配所有。
|
|
29
|
-
*
|
|
30
|
-
* @example
|
|
31
|
-
* // 拒绝特定群的消息
|
|
32
|
-
* { name: 'block-spam', action: 'deny', scopes: ['group'], channels: ['123456'] }
|
|
33
|
-
*
|
|
34
|
-
* // 放行 VIP 用户(高优先级)
|
|
35
|
-
* { name: 'allow-vip', action: 'allow', priority: 100, senders: ['admin001'] }
|
|
36
|
-
*
|
|
37
|
-
* // 正则匹配:拒绝所有 test- 开头的频道
|
|
38
|
-
* { name: 'block-test', action: 'deny', scopes: ['channel'], channels: [/^test-/] }
|
|
39
|
-
*/
|
|
40
|
-
export interface FilterRule {
|
|
41
|
-
/** 规则名称(唯一标识) */
|
|
42
|
-
name: string;
|
|
43
|
-
/** 规则描述 */
|
|
44
|
-
description?: string;
|
|
45
|
-
/** 过滤动作:allow 放行 / deny 拦截 */
|
|
46
|
-
action: FilterAction;
|
|
47
|
-
/** 优先级,数值越大越先匹配(默认 0) */
|
|
48
|
-
priority?: number;
|
|
49
|
-
/** 是否启用(默认 true) */
|
|
50
|
-
enabled?: boolean;
|
|
51
|
-
/** 匹配的消息作用域,未设置则匹配所有 */
|
|
52
|
-
scopes?: FilterScope[];
|
|
53
|
-
/** 匹配的适配器名称 */
|
|
54
|
-
adapters?: FilterPattern[];
|
|
55
|
-
/** 匹配的 Endpoint 名称 */
|
|
56
|
-
endpoints?: FilterPattern[];
|
|
57
|
-
/** 匹配的频道/群/会话 ID */
|
|
58
|
-
channels?: FilterPattern[];
|
|
59
|
-
/** 匹配的发送者 ID */
|
|
60
|
-
senders?: FilterPattern[];
|
|
61
|
-
}
|
|
62
|
-
/** 过滤检测结果 */
|
|
63
|
-
export interface FilterResult {
|
|
64
|
-
/** 是否允许处理 */
|
|
65
|
-
allowed: boolean;
|
|
66
|
-
/** 匹配到的规则名称(null 表示无规则匹配,走默认策略) */
|
|
67
|
-
matchedRule: string | null;
|
|
68
|
-
/** 结果原因 */
|
|
69
|
-
reason: string;
|
|
70
|
-
}
|
|
71
|
-
/** 配置文件中的规则(pattern 均为 string,正则用 /pattern/ 表示) */
|
|
72
|
-
export interface FilterRuleConfig {
|
|
73
|
-
name: string;
|
|
74
|
-
description?: string;
|
|
75
|
-
action: FilterAction;
|
|
76
|
-
priority?: number;
|
|
77
|
-
enabled?: boolean;
|
|
78
|
-
scopes?: FilterScope[];
|
|
79
|
-
adapters?: string[];
|
|
80
|
-
endpoints?: string[];
|
|
81
|
-
channels?: string[];
|
|
82
|
-
senders?: string[];
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* 消息过滤配置
|
|
86
|
-
*
|
|
87
|
-
* ```yaml
|
|
88
|
-
* message_filter:
|
|
89
|
-
* default_policy: allow
|
|
90
|
-
* rules:
|
|
91
|
-
* - name: block-spam
|
|
92
|
-
* action: deny
|
|
93
|
-
* scopes: [group]
|
|
94
|
-
* channels: ['123456']
|
|
95
|
-
* - name: vip-pass
|
|
96
|
-
* action: allow
|
|
97
|
-
* priority: 100
|
|
98
|
-
* senders: ['admin001']
|
|
99
|
-
* ```
|
|
100
|
-
*/
|
|
101
|
-
export interface MessageFilterConfig {
|
|
102
|
-
/** 默认策略:无规则匹配时的行为(默认 'allow') */
|
|
103
|
-
default_policy?: FilterAction;
|
|
104
|
-
/** 规则列表 */
|
|
105
|
-
rules?: FilterRuleConfig[];
|
|
106
|
-
}
|
|
107
|
-
export interface MessageFilterContextExtensions {
|
|
108
|
-
/** 添加过滤规则,返回 dispose 函数 */
|
|
109
|
-
addFilterRule(rule: FilterRule): () => void;
|
|
110
|
-
/** 检测消息是否应被处理 */
|
|
111
|
-
testFilter(message: Message<any>): FilterResult;
|
|
112
|
-
/** 设置默认过滤策略 */
|
|
113
|
-
setDefaultFilterPolicy(policy: FilterAction): void;
|
|
114
|
-
}
|
|
115
|
-
declare module '../plugin.js' {
|
|
116
|
-
namespace Plugin {
|
|
117
|
-
interface Extensions extends MessageFilterContextExtensions {
|
|
118
|
-
}
|
|
119
|
-
interface Contexts {
|
|
120
|
-
'message-filter': MessageFilterFeature;
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
export declare namespace FilterRules {
|
|
125
|
-
/** 创建拒绝规则 */
|
|
126
|
-
function deny(name: string, conditions: Omit<FilterRule, 'name' | 'action'>): FilterRule;
|
|
127
|
-
/** 创建放行规则 */
|
|
128
|
-
function allow(name: string, conditions: Omit<FilterRule, 'name' | 'action'>): FilterRule;
|
|
129
|
-
/**
|
|
130
|
-
* 创建黑名单规则组
|
|
131
|
-
* @returns 一条 deny 规则
|
|
132
|
-
*/
|
|
133
|
-
function blacklist(scope: FilterScope, ids: string[], name?: string): FilterRule;
|
|
134
|
-
/**
|
|
135
|
-
* 创建白名单规则组
|
|
136
|
-
* @returns [allow 规则, deny-catch-all 规则]
|
|
137
|
-
*/
|
|
138
|
-
function whitelist(scope: FilterScope, ids: string[], name?: string): [FilterRule, FilterRule];
|
|
139
|
-
}
|
|
140
|
-
export declare class MessageFilterFeature extends Feature<FilterRule> {
|
|
141
|
-
#private;
|
|
142
|
-
readonly name: "message-filter";
|
|
143
|
-
readonly icon = "Filter";
|
|
144
|
-
readonly desc = "\u6D88\u606F\u8FC7\u6EE4";
|
|
145
|
-
/** 按规则名称索引 */
|
|
146
|
-
readonly byName: Map<string, FilterRule>;
|
|
147
|
-
constructor(config?: MessageFilterConfig);
|
|
148
|
-
/** 默认策略 */
|
|
149
|
-
get defaultPolicy(): FilterAction;
|
|
150
|
-
set defaultPolicy(policy: FilterAction);
|
|
151
|
-
/** 获取按优先级排序的启用规则列表(带缓存) */
|
|
152
|
-
get sortedRules(): FilterRule[];
|
|
153
|
-
/** 按名称查询规则 */
|
|
154
|
-
getRule(name: string): FilterRule | undefined;
|
|
155
|
-
/**
|
|
156
|
-
* 检测消息是否应该被处理
|
|
157
|
-
*
|
|
158
|
-
* 遍历按优先级排序的规则列表,返回第一个匹配的规则结果。
|
|
159
|
-
* 若无规则匹配,按默认策略决定。
|
|
160
|
-
*/
|
|
161
|
-
test(message: Message<any>): FilterResult;
|
|
162
|
-
/** 添加规则,维护 byName 索引 */
|
|
163
|
-
add(rule: FilterRule, pluginName: string): () => void;
|
|
164
|
-
/** 移除规则,清理 byName 索引 */
|
|
165
|
-
remove(rule: FilterRule, pluginName?: string): boolean;
|
|
166
|
-
/** 清理所有规则注册(热重载时由 Plugin.stop() 调用) */
|
|
167
|
-
dispose(): void;
|
|
168
|
-
/** 序列化为 JSON(供 Web 控制台展示) */
|
|
169
|
-
toJSON(pluginName?: string): FeatureJSON;
|
|
170
|
-
/** 插件扩展方法 */
|
|
171
|
-
get extensions(): {
|
|
172
|
-
addFilterRule(rule: FilterRule): () => void;
|
|
173
|
-
testFilter(message: Message<any>): FilterResult;
|
|
174
|
-
setDefaultFilterPolicy(policy: FilterAction): void;
|
|
175
|
-
};
|
|
176
|
-
}
|