@zhin.js/core 1.1.33 → 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 +140 -61
- package/lib/adapter.d.ts +72 -23
- package/lib/adapter.js +222 -58
- 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 +9 -0
- package/lib/built/html-segment-fallback.js +49 -0
- package/lib/built/html-to-text.d.ts +4 -1
- package/lib/built/html-to-text.js +47 -16
- 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 +67 -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 -21
- package/lib/index.js +53 -28
- 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 -85
- package/lib/types.js +0 -1
- package/lib/utils.d.ts +68 -1
- package/lib/utils.js +73 -11
- 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-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/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 -33
- package/lib/built/prepend-quote-context.d.ts.map +0 -1
- package/lib/built/prepend-quote-context.js +0 -129
- 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
package/lib/built/ai-trigger.js
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* 4. 关键词触发 - 非群/频道场景下匹配关键词时触发
|
|
10
10
|
*/
|
|
11
11
|
import { segment } from "../utils.js";
|
|
12
|
-
import {
|
|
12
|
+
import { readMentionSegmentTarget } from './segment-contract/mention.js';
|
|
13
13
|
import { normalizeSenderRoles, } from './roles.js';
|
|
14
14
|
// ============================================================================
|
|
15
15
|
// 默认配置
|
|
@@ -26,50 +26,44 @@ export const DEFAULT_AI_TRIGGER_CONFIG = {
|
|
|
26
26
|
errorTemplate: '❌ AI 处理失败: {error}',
|
|
27
27
|
masters: [],
|
|
28
28
|
trusted: [],
|
|
29
|
-
resolveQuotedMessages: true,
|
|
30
29
|
};
|
|
31
30
|
// ============================================================================
|
|
32
31
|
// 工具函数
|
|
33
32
|
// ============================================================================
|
|
34
|
-
function normalizeAtIds(
|
|
35
|
-
const ids =
|
|
33
|
+
function normalizeAtIds(endpointAtIds) {
|
|
34
|
+
const ids = endpointAtIds?.length ? endpointAtIds : [];
|
|
36
35
|
return [...new Set(ids.map((id) => String(id)).filter(Boolean))];
|
|
37
36
|
}
|
|
38
37
|
function segmentAtUserId(seg) {
|
|
39
|
-
|
|
40
|
-
if (!data || typeof data !== 'object')
|
|
41
|
-
return '';
|
|
42
|
-
const record = data;
|
|
43
|
-
const raw = record.user_id ?? record.qq ?? record.id;
|
|
44
|
-
return raw == null ? '' : String(raw);
|
|
38
|
+
return readMentionSegmentTarget(seg);
|
|
45
39
|
}
|
|
46
|
-
function
|
|
40
|
+
function isAtSegmentForEndpoint(seg, endpointKeys) {
|
|
47
41
|
if (seg.type !== 'at' && seg.type !== 'mention')
|
|
48
42
|
return false;
|
|
49
43
|
const uid = segmentAtUserId(seg);
|
|
50
|
-
return uid !== '' &&
|
|
44
|
+
return uid !== '' && endpointKeys.includes(uid);
|
|
51
45
|
}
|
|
52
|
-
function
|
|
53
|
-
for (const id of
|
|
46
|
+
function textMentionsEndpoint(text, endpointKeys) {
|
|
47
|
+
for (const id of endpointKeys) {
|
|
54
48
|
const re = new RegExp(`@${id.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}(?:\\s|$|[\\u200b\\uFEFF])`);
|
|
55
49
|
if (re.test(text))
|
|
56
50
|
return true;
|
|
57
51
|
}
|
|
58
52
|
return false;
|
|
59
53
|
}
|
|
60
|
-
function
|
|
54
|
+
function stripTextAtEndpoint(text, endpointKeys) {
|
|
61
55
|
let result = text;
|
|
62
|
-
for (const id of
|
|
56
|
+
for (const id of endpointKeys) {
|
|
63
57
|
const re = new RegExp(`@${id.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}(?:\\s|[\\u200b\\uFEFF])?`, 'g');
|
|
64
58
|
result = result.replace(re, '');
|
|
65
59
|
}
|
|
66
60
|
return result;
|
|
67
61
|
}
|
|
68
62
|
/**
|
|
69
|
-
* 收集用于 @ 匹配的
|
|
63
|
+
* 收集用于 @ 匹配的 Endpoint 标识符
|
|
70
64
|
*/
|
|
71
|
-
export function
|
|
72
|
-
const ids = new Set([String(message.$
|
|
65
|
+
export function collectEndpointAtIds(message, extraIds) {
|
|
66
|
+
const ids = new Set([String(message.$endpoint)]);
|
|
73
67
|
for (const id of extraIds ?? []) {
|
|
74
68
|
if (id)
|
|
75
69
|
ids.add(String(id));
|
|
@@ -77,15 +71,15 @@ export function collectBotAtIds(message, extraIds) {
|
|
|
77
71
|
return [...ids];
|
|
78
72
|
}
|
|
79
73
|
/**
|
|
80
|
-
* 检查消息是否 @
|
|
74
|
+
* 检查消息是否 @ 了 Endpoint
|
|
81
75
|
*/
|
|
82
|
-
export function
|
|
83
|
-
const
|
|
84
|
-
if (message.$content.some((seg) =>
|
|
76
|
+
export function isAtEndpoint(message, endpointAtIds) {
|
|
77
|
+
const endpointKeys = normalizeAtIds(endpointAtIds?.length ? endpointAtIds : collectEndpointAtIds(message));
|
|
78
|
+
if (message.$content.some((seg) => isAtSegmentForEndpoint(seg, endpointKeys))) {
|
|
85
79
|
return true;
|
|
86
80
|
}
|
|
87
81
|
for (const seg of message.$content) {
|
|
88
|
-
if (seg.type === 'text' && seg.data?.text &&
|
|
82
|
+
if (seg.type === 'text' && seg.data?.text && textMentionsEndpoint(seg.data.text, endpointKeys)) {
|
|
89
83
|
return true;
|
|
90
84
|
}
|
|
91
85
|
}
|
|
@@ -98,6 +92,22 @@ export function isAtBot(message, botAtIds) {
|
|
|
98
92
|
export function extractTextContent(message) {
|
|
99
93
|
return segment.toString(message.$content);
|
|
100
94
|
}
|
|
95
|
+
/**
|
|
96
|
+
* 为群/频道消息构建发送者前缀(与 sender-extra.ts buildSenderPrefix 格式对齐)
|
|
97
|
+
* 私聊消息返回 null
|
|
98
|
+
*/
|
|
99
|
+
export function buildSenderPrefixForMessage(message, roles) {
|
|
100
|
+
const scope = message.$channel?.type || 'private';
|
|
101
|
+
if (scope !== 'group' && scope !== 'channel')
|
|
102
|
+
return null;
|
|
103
|
+
const rawId = String(message.$sender?.id ?? 'unknown');
|
|
104
|
+
const id = rawId.trim().replace(/[\]\s]+/g, '_').slice(0, 64) || 'unknown';
|
|
105
|
+
const rawName = message.$sender?.name;
|
|
106
|
+
const name = (rawName?.trim() || 'unknown').replace(/[\]\s]+/g, '_').slice(0, 64);
|
|
107
|
+
const nonUserRoles = roles.filter((r) => r !== 'user');
|
|
108
|
+
const roleStr = nonUserRoles.join(',') || 'user';
|
|
109
|
+
return `[sender:id=${id} name=${name} roles=${roleStr}]`;
|
|
110
|
+
}
|
|
101
111
|
/**
|
|
102
112
|
* 解析 AI 回复中的富媒体内容
|
|
103
113
|
* 将字符串中的 XML-like 标签解析为 MessageElement
|
|
@@ -118,23 +128,23 @@ export function parseRichMediaContent(content) {
|
|
|
118
128
|
}
|
|
119
129
|
}
|
|
120
130
|
/**
|
|
121
|
-
* 移除 @
|
|
131
|
+
* 移除 @ Endpoint 的部分
|
|
122
132
|
*/
|
|
123
|
-
export function
|
|
124
|
-
const
|
|
133
|
+
export function removeAtEndpoint(message, endpointAtIds) {
|
|
134
|
+
const endpointKeys = normalizeAtIds(endpointAtIds?.length ? endpointAtIds : collectEndpointAtIds(message));
|
|
125
135
|
return message.$content
|
|
126
|
-
.filter((seg) => !
|
|
136
|
+
.filter((seg) => !isAtSegmentForEndpoint(seg, endpointKeys))
|
|
127
137
|
.map((seg) => {
|
|
128
138
|
if (seg.type !== 'text' || !seg.data?.text)
|
|
129
139
|
return seg;
|
|
130
|
-
const stripped =
|
|
140
|
+
const stripped = stripTextAtEndpoint(seg.data.text, endpointKeys).trim();
|
|
131
141
|
if (!stripped)
|
|
132
142
|
return null;
|
|
133
143
|
return { ...seg, data: { ...seg.data, text: stripped } };
|
|
134
144
|
})
|
|
135
145
|
.filter((seg) => seg != null);
|
|
136
146
|
}
|
|
137
|
-
function
|
|
147
|
+
function normalizeEndpointIdList(input) {
|
|
138
148
|
if (Array.isArray(input))
|
|
139
149
|
return input.map((v) => String(v)).filter(Boolean);
|
|
140
150
|
if (typeof input === 'string') {
|
|
@@ -142,15 +152,15 @@ function normalizeBotIdList(input) {
|
|
|
142
152
|
}
|
|
143
153
|
return [];
|
|
144
154
|
}
|
|
145
|
-
function
|
|
146
|
-
if (!
|
|
155
|
+
function collectEndpointTrustedIds(endpointConfig) {
|
|
156
|
+
if (!endpointConfig)
|
|
147
157
|
return [];
|
|
148
|
-
return
|
|
158
|
+
return normalizeEndpointIdList(endpointConfig.trusted);
|
|
149
159
|
}
|
|
150
160
|
/**
|
|
151
|
-
* 解析发送者角色集合(IM 群角色 + trigger +
|
|
161
|
+
* 解析发送者角色集合(IM 群角色 + trigger + endpoints[].$config)
|
|
152
162
|
*/
|
|
153
|
-
export function resolveSenderRoles(message, config,
|
|
163
|
+
export function resolveSenderRoles(message, config, endpointConfig) {
|
|
154
164
|
const scope = message.$channel?.type || 'private';
|
|
155
165
|
// process 适配器(stdin/本机 CLI):操作者即宿主用户,恒为 master
|
|
156
166
|
if (message.$adapter === 'process') {
|
|
@@ -160,60 +170,45 @@ export function resolveSenderRoles(message, config, botConfig) {
|
|
|
160
170
|
};
|
|
161
171
|
}
|
|
162
172
|
const senderId = String(message.$sender.id);
|
|
163
|
-
const senderPermissions = message.$sender.permissions || [];
|
|
164
173
|
const roles = [];
|
|
165
174
|
const masters = config.masters || [];
|
|
166
175
|
const globalTrusted = config.trusted || [];
|
|
167
|
-
const cfg =
|
|
168
|
-
const
|
|
169
|
-
const
|
|
170
|
-
if (masters.includes(senderId) || (
|
|
176
|
+
const cfg = endpointConfig;
|
|
177
|
+
const endpointMaster = cfg?.master != null ? String(cfg.master) : undefined;
|
|
178
|
+
const endpointTrustedIds = collectEndpointTrustedIds(cfg);
|
|
179
|
+
if (masters.includes(senderId) || (endpointMaster != null && senderId === endpointMaster)) {
|
|
171
180
|
roles.push('master');
|
|
172
181
|
}
|
|
173
|
-
else if (globalTrusted.includes(senderId) ||
|
|
182
|
+
else if (globalTrusted.includes(senderId) || endpointTrustedIds.includes(senderId)) {
|
|
174
183
|
roles.push('trusted');
|
|
175
184
|
}
|
|
176
|
-
const isGroupOwner = senderPermissions.includes('owner')
|
|
177
|
-
|| senderPermissions.includes('group_owner')
|
|
178
|
-
|| message.$sender?.role === 'owner';
|
|
179
|
-
const isGroupAdmin = isGroupOwner
|
|
180
|
-
|| senderPermissions.includes('admin')
|
|
181
|
-
|| senderPermissions.includes('group_admin')
|
|
182
|
-
|| message.$sender?.role === 'admin';
|
|
183
|
-
if (isGroupOwner)
|
|
184
|
-
roles.push('group_owner');
|
|
185
|
-
else if (isGroupAdmin)
|
|
186
|
-
roles.push('group_admin');
|
|
187
185
|
return {
|
|
188
186
|
scope,
|
|
189
187
|
roles: normalizeSenderRoles(roles),
|
|
190
188
|
};
|
|
191
189
|
}
|
|
192
|
-
/** 从 IM 消息生成 sessionId(platform:botId:type:sceneId) */
|
|
193
|
-
export function resolveIMSessionIdFromMessage(message) {
|
|
194
|
-
const scope = (message.$channel?.type || 'private');
|
|
195
|
-
const sceneId = scope === 'private'
|
|
196
|
-
? String(message.$sender.id)
|
|
197
|
-
: String(message.$channel?.id || message.$sender.id);
|
|
198
|
-
return resolveIMSessionId({
|
|
199
|
-
platform: message.$adapter,
|
|
200
|
-
botId: message.$bot,
|
|
201
|
-
scope,
|
|
202
|
-
sceneId,
|
|
203
|
-
});
|
|
204
|
-
}
|
|
205
190
|
/**
|
|
206
191
|
* 检查消息是否应该触发 AI
|
|
207
192
|
*/
|
|
208
193
|
export function shouldTriggerAI(message, config, options) {
|
|
209
194
|
const fullConfig = { ...DEFAULT_AI_TRIGGER_CONFIG, ...config };
|
|
210
|
-
const
|
|
195
|
+
const endpointAtIds = collectEndpointAtIds(message, options?.endpointAtIds);
|
|
211
196
|
if (!fullConfig.enabled) {
|
|
212
197
|
return { triggered: false, content: '' };
|
|
213
198
|
}
|
|
214
199
|
const text = extractTextContent(message);
|
|
215
200
|
const scope = message.$channel?.type || 'private';
|
|
216
201
|
const isSharedSession = scope === 'group' || scope === 'channel';
|
|
202
|
+
/** 对群/频道触发结果附加发送者前缀(与 DB 历史的 buildSenderPrefix 格式对齐) */
|
|
203
|
+
const withSenderPrefix = (content) => {
|
|
204
|
+
if (!isSharedSession)
|
|
205
|
+
return content;
|
|
206
|
+
const { roles } = resolveSenderRoles(message, config);
|
|
207
|
+
const prefix = buildSenderPrefixForMessage(message, roles);
|
|
208
|
+
if (!prefix)
|
|
209
|
+
return content;
|
|
210
|
+
return content ? `${prefix} ${content}` : prefix;
|
|
211
|
+
};
|
|
217
212
|
// 检查忽略前缀
|
|
218
213
|
for (const prefix of fullConfig.ignorePrefixes) {
|
|
219
214
|
if (text.startsWith(prefix)) {
|
|
@@ -229,11 +224,12 @@ export function shouldTriggerAI(message, config, options) {
|
|
|
229
224
|
}
|
|
230
225
|
}
|
|
231
226
|
// 2. 检查 @ 触发(群/频道主路径;仅 @ 无正文时也触发,由 Agent 处理空输入)
|
|
232
|
-
if (fullConfig.respondToAt &&
|
|
233
|
-
const content =
|
|
227
|
+
if (fullConfig.respondToAt && isAtEndpoint(message, endpointAtIds)) {
|
|
228
|
+
const content = removeAtEndpoint(message, endpointAtIds);
|
|
229
|
+
const body = content.length ? segment.toString(content).trim() : '';
|
|
234
230
|
return {
|
|
235
231
|
triggered: true,
|
|
236
|
-
content:
|
|
232
|
+
content: withSenderPrefix(body),
|
|
237
233
|
};
|
|
238
234
|
}
|
|
239
235
|
// 3. 检查私聊触发
|
|
@@ -259,4 +255,3 @@ export function shouldTriggerAI(message, config, options) {
|
|
|
259
255
|
export function mergeAITriggerConfig(config) {
|
|
260
256
|
return { ...DEFAULT_AI_TRIGGER_CONFIG, ...config };
|
|
261
257
|
}
|
|
262
|
-
//# sourceMappingURL=ai-trigger.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 授权重算 — ConfigFeature + Message 为单一真相源($sender.isMaster/isTrusted 为 enrich 快照)
|
|
3
|
+
*/
|
|
4
|
+
import type { Plugin } from '../plugin.js';
|
|
5
|
+
import type { Message } from '../message.js';
|
|
6
|
+
import { type SenderRolesResult } from './ai-trigger.js';
|
|
7
|
+
/**
|
|
8
|
+
* 从 ConfigFeature + Message 重算发送者角色(含群角色与 master/trusted)
|
|
9
|
+
*/
|
|
10
|
+
export declare function resolveSubjectRoles(plugin: Plugin, message: Message<any>): SenderRolesResult;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { mergeAITriggerConfig, resolveSenderRoles, } from './ai-trigger.js';
|
|
2
|
+
import { formatCompact, getLogger } from '@zhin.js/logger';
|
|
3
|
+
const logger = getLogger('Authorization');
|
|
4
|
+
function findEndpointEntryFromConfig(config, adapter, endpointKey) {
|
|
5
|
+
// 1) top-level endpoints[] (legacy / flat format)
|
|
6
|
+
const topLevel = config.endpoints;
|
|
7
|
+
if (Array.isArray(topLevel)) {
|
|
8
|
+
const found = topLevel.find((b) => b.context === adapter && String(b.id) === endpointKey);
|
|
9
|
+
if (found)
|
|
10
|
+
return found;
|
|
11
|
+
}
|
|
12
|
+
// 2) plugins.<adapter> — adapter-level master/trusted + nested endpoints[]
|
|
13
|
+
const adapterConfig = config.plugins?.[adapter];
|
|
14
|
+
if (!adapterConfig)
|
|
15
|
+
return undefined;
|
|
16
|
+
const nested = adapterConfig.endpoints;
|
|
17
|
+
const entry = Array.isArray(nested)
|
|
18
|
+
? nested.find((b) => String(b.id) === endpointKey)
|
|
19
|
+
: undefined;
|
|
20
|
+
// Merge adapter-level master/trusted onto the matched endpoint entry
|
|
21
|
+
// so that resolveSenderRoles sees them in one place
|
|
22
|
+
const merged = {
|
|
23
|
+
context: adapter,
|
|
24
|
+
...(entry ?? { id: endpointKey }),
|
|
25
|
+
};
|
|
26
|
+
if (adapterConfig.master != null && merged.master == null) {
|
|
27
|
+
merged.master = adapterConfig.master;
|
|
28
|
+
}
|
|
29
|
+
if (adapterConfig.trusted != null && merged.trusted == null) {
|
|
30
|
+
merged.trusted = adapterConfig.trusted;
|
|
31
|
+
}
|
|
32
|
+
return merged;
|
|
33
|
+
}
|
|
34
|
+
function readTriggerConfig(plugin) {
|
|
35
|
+
const root = plugin.root ?? plugin;
|
|
36
|
+
try {
|
|
37
|
+
const ai = root.inject('ai');
|
|
38
|
+
if (ai?.getTriggerConfig)
|
|
39
|
+
return ai.getTriggerConfig();
|
|
40
|
+
}
|
|
41
|
+
catch (e) {
|
|
42
|
+
logger.debug(formatCompact({ auth: 'trigger_config_fallback', reason: 'ai_not_ready' }));
|
|
43
|
+
}
|
|
44
|
+
try {
|
|
45
|
+
const configSvc = root.inject('config');
|
|
46
|
+
const primary = configSvc?.getPrimary?.();
|
|
47
|
+
return primary?.ai?.trigger ?? {};
|
|
48
|
+
}
|
|
49
|
+
catch (e) {
|
|
50
|
+
logger.debug(formatCompact({ auth: 'trigger_config_read_error' }));
|
|
51
|
+
return {};
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
function readEndpointConfig(plugin, message) {
|
|
55
|
+
const root = plugin.root ?? plugin;
|
|
56
|
+
try {
|
|
57
|
+
const configSvc = root.inject('config');
|
|
58
|
+
const primary = configSvc?.getPrimary?.();
|
|
59
|
+
if (!primary)
|
|
60
|
+
return undefined;
|
|
61
|
+
const entry = findEndpointEntryFromConfig(primary, String(message.$adapter), String(message.$endpoint));
|
|
62
|
+
return entry;
|
|
63
|
+
}
|
|
64
|
+
catch (e) {
|
|
65
|
+
logger.debug(formatCompact({ auth: 'endpoint_config_read_error' }));
|
|
66
|
+
return undefined;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* 从 ConfigFeature + Message 重算发送者角色(含群角色与 master/trusted)
|
|
71
|
+
*/
|
|
72
|
+
export function resolveSubjectRoles(plugin, message) {
|
|
73
|
+
const triggerConfig = mergeAITriggerConfig(readTriggerConfig(plugin));
|
|
74
|
+
const endpointConfig = readEndpointConfig(plugin, message);
|
|
75
|
+
return resolveSenderRoles(message, triggerConfig, endpointConfig);
|
|
76
|
+
}
|
package/lib/built/command.d.ts
CHANGED
|
@@ -5,15 +5,17 @@
|
|
|
5
5
|
import { Feature, FeatureJSON } from "@zhin.js/kernel";
|
|
6
6
|
/** 命令 pattern 的首个词(用于前缀排序) */
|
|
7
7
|
export declare function commandLeadingToken(pattern: string): string;
|
|
8
|
+
/** 命令匹配优先级:首词越长越优先;同首词则完整 pattern 越长越优先 */
|
|
9
|
+
export declare function compareCommandPatterns(a: string, b: string): number;
|
|
8
10
|
import { MessageCommand } from "../command.js";
|
|
9
11
|
import { Message } from "../message.js";
|
|
10
|
-
import { Plugin } from "../plugin.js";
|
|
11
12
|
import type { RegisteredAdapter, AdapterMessage } from "../types.js";
|
|
13
|
+
import type { PermissionHost } from '@zhin.js/permission';
|
|
12
14
|
/**
|
|
13
15
|
* CommandContext 扩展方法类型
|
|
14
16
|
*/
|
|
15
17
|
export interface CommandContextExtensions {
|
|
16
|
-
/**
|
|
18
|
+
/** @deprecated 使用 `defineCommand` + `commands/`;勿在新代码调用。 */
|
|
17
19
|
addCommand<T extends RegisteredAdapter>(command: MessageCommand<T>): () => void;
|
|
18
20
|
}
|
|
19
21
|
declare module "../plugin.js" {
|
|
@@ -26,7 +28,10 @@ declare module "../plugin.js" {
|
|
|
26
28
|
}
|
|
27
29
|
}
|
|
28
30
|
/**
|
|
29
|
-
* 命令服务 Feature
|
|
31
|
+
* 命令服务 Feature(经典 MessageCommand 注册表)。
|
|
32
|
+
*
|
|
33
|
+
* @deprecated 新命令走 `@zhin.js/command` 的 `defineCommand` + 约定目录发现。
|
|
34
|
+
* 本 Feature 仍服务 Agent / game-kit / legacy Plugin.addCommand。
|
|
30
35
|
*/
|
|
31
36
|
export declare class CommandFeature extends Feature<MessageCommand<RegisteredAdapter>> {
|
|
32
37
|
readonly name: "command";
|
|
@@ -49,7 +54,7 @@ export declare class CommandFeature extends Feature<MessageCommand<RegisteredAda
|
|
|
49
54
|
/**
|
|
50
55
|
* 处理消息,依次尝试匹配命令(较长前缀优先,避免 `teach` 抢 `teach-list`)
|
|
51
56
|
*/
|
|
52
|
-
handle(message: Message<AdapterMessage<RegisteredAdapter>>,
|
|
57
|
+
handle(message: Message<AdapterMessage<RegisteredAdapter>>, host: PermissionHost | null): Promise<any>;
|
|
53
58
|
/**
|
|
54
59
|
* 生命周期: 销毁时清理所有命令
|
|
55
60
|
*/
|
|
@@ -65,4 +70,3 @@ export declare class CommandFeature extends Feature<MessageCommand<RegisteredAda
|
|
|
65
70
|
addCommand<T extends RegisteredAdapter>(command: MessageCommand<T>): () => void;
|
|
66
71
|
};
|
|
67
72
|
}
|
|
68
|
-
//# sourceMappingURL=command.d.ts.map
|
package/lib/built/command.js
CHANGED
|
@@ -7,9 +7,23 @@ import { Feature } from "@zhin.js/kernel";
|
|
|
7
7
|
export function commandLeadingToken(pattern) {
|
|
8
8
|
return pattern.split(/\s/)[0] ?? "";
|
|
9
9
|
}
|
|
10
|
-
|
|
10
|
+
/** 命令匹配优先级:首词越长越优先;同首词则完整 pattern 越长越优先 */
|
|
11
|
+
export function compareCommandPatterns(a, b) {
|
|
12
|
+
const leadDiff = commandLeadingToken(b).length - commandLeadingToken(a).length;
|
|
13
|
+
if (leadDiff !== 0)
|
|
14
|
+
return leadDiff;
|
|
15
|
+
const lenDiff = b.length - a.length;
|
|
16
|
+
if (lenDiff !== 0)
|
|
17
|
+
return lenDiff;
|
|
18
|
+
const tokA = a.trim().split(/\s+/).length;
|
|
19
|
+
const tokB = b.trim().split(/\s+/).length;
|
|
20
|
+
return tokB - tokA;
|
|
21
|
+
}
|
|
11
22
|
/**
|
|
12
|
-
* 命令服务 Feature
|
|
23
|
+
* 命令服务 Feature(经典 MessageCommand 注册表)。
|
|
24
|
+
*
|
|
25
|
+
* @deprecated 新命令走 `@zhin.js/command` 的 `defineCommand` + 约定目录发现。
|
|
26
|
+
* 本 Feature 仍服务 Agent / game-kit / legacy Plugin.addCommand。
|
|
13
27
|
*/
|
|
14
28
|
export class CommandFeature extends Feature {
|
|
15
29
|
name = 'command';
|
|
@@ -40,10 +54,10 @@ export class CommandFeature extends Feature {
|
|
|
40
54
|
/**
|
|
41
55
|
* 处理消息,依次尝试匹配命令(较长前缀优先,避免 `teach` 抢 `teach-list`)
|
|
42
56
|
*/
|
|
43
|
-
async handle(message,
|
|
44
|
-
const commands = [...this.items].sort((a, b) =>
|
|
57
|
+
async handle(message, host) {
|
|
58
|
+
const commands = [...this.items].sort((a, b) => compareCommandPatterns(a.pattern, b.pattern));
|
|
45
59
|
for (const command of commands) {
|
|
46
|
-
const result = await command.handle(message,
|
|
60
|
+
const result = await command.handle(message, host);
|
|
47
61
|
if (result)
|
|
48
62
|
return result;
|
|
49
63
|
}
|
|
@@ -80,7 +94,7 @@ export class CommandFeature extends Feature {
|
|
|
80
94
|
const feature = this;
|
|
81
95
|
return {
|
|
82
96
|
addCommand(command) {
|
|
83
|
-
const plugin =
|
|
97
|
+
const plugin = this;
|
|
84
98
|
const dispose = feature.add(command, plugin.name);
|
|
85
99
|
plugin.recordFeatureContribution(feature.name, command.pattern);
|
|
86
100
|
plugin.onDispose(dispose);
|
|
@@ -89,4 +103,3 @@ export class CommandFeature extends Feature {
|
|
|
89
103
|
};
|
|
90
104
|
}
|
|
91
105
|
}
|
|
92
|
-
//# sourceMappingURL=command.js.map
|
|
@@ -1,40 +1,40 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Scene Management — 方法规范与 Tool 工厂
|
|
3
3
|
*
|
|
4
4
|
* 设计理念:
|
|
5
|
-
* 各 IM
|
|
5
|
+
* 各 IM 平台在适配器内自行实现场景治理方法(removeMember、muteMember 等),
|
|
6
6
|
* 并自行注册 Tool;平台说明使用包内 `skills/<adapter>/SKILL.md`。
|
|
7
7
|
*
|
|
8
8
|
* 使用方式(在各适配器 start 或注册方法中):
|
|
9
9
|
*
|
|
10
|
-
* import {
|
|
11
|
-
* const tools =
|
|
10
|
+
* import { createSceneManagementTools, SCENE_MANAGEMENT_SKILL_KEYWORDS, SCENE_MANAGEMENT_SKILL_TAGS } from 'zhin.js';
|
|
11
|
+
* const tools = createSceneManagementTools(this, this.name);
|
|
12
12
|
* tools.forEach(t => this.addTool(t));
|
|
13
13
|
* // 另:包内 skills/<name>/SKILL.md 供 Agent 发现
|
|
14
14
|
*/
|
|
15
|
-
import type { Tool
|
|
15
|
+
import type { Tool } from '../types.js';
|
|
16
16
|
/**
|
|
17
|
-
*
|
|
17
|
+
* 场景治理能力接口。
|
|
18
18
|
* Adapter 基类通过此接口声明方法签名,子类选择性覆写。
|
|
19
19
|
*/
|
|
20
|
-
export interface
|
|
21
|
-
|
|
22
|
-
muteMember?(
|
|
23
|
-
setMemberNickname?(
|
|
24
|
-
|
|
25
|
-
listMembers?(
|
|
26
|
-
banMember?(
|
|
27
|
-
unbanMember?(
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
20
|
+
export interface ISceneManagement {
|
|
21
|
+
removeMember?(endpointKey: string, sceneId: string, userId: string): Promise<any>;
|
|
22
|
+
muteMember?(endpointKey: string, sceneId: string, userId: string, duration?: number): Promise<any>;
|
|
23
|
+
setMemberNickname?(endpointKey: string, sceneId: string, userId: string, nickname: string): Promise<any>;
|
|
24
|
+
setModerator?(endpointKey: string, sceneId: string, userId: string, enable?: boolean): Promise<any>;
|
|
25
|
+
listMembers?(endpointKey: string, sceneId: string): Promise<any>;
|
|
26
|
+
banMember?(endpointKey: string, sceneId: string, userId: string, reason?: string): Promise<any>;
|
|
27
|
+
unbanMember?(endpointKey: string, sceneId: string, userId: string): Promise<any>;
|
|
28
|
+
renameScene?(endpointKey: string, sceneId: string, name: string): Promise<any>;
|
|
29
|
+
setSceneMuted?(endpointKey: string, sceneId: string, enable?: boolean): Promise<any>;
|
|
30
|
+
getSceneInfo?(endpointKey: string, sceneId: string): Promise<any>;
|
|
31
31
|
}
|
|
32
|
-
export interface
|
|
33
|
-
method: keyof
|
|
32
|
+
export interface SceneManagementMethodSpec {
|
|
33
|
+
method: keyof ISceneManagement;
|
|
34
34
|
toolSuffix: string;
|
|
35
35
|
description: string;
|
|
36
36
|
keywords: string[];
|
|
37
|
-
|
|
37
|
+
permit?: string;
|
|
38
38
|
extraParams: Record<string, {
|
|
39
39
|
type: string;
|
|
40
40
|
description: string;
|
|
@@ -43,13 +43,19 @@ export interface GroupMethodSpec {
|
|
|
43
43
|
extraRequired?: string[];
|
|
44
44
|
preExecutable?: boolean;
|
|
45
45
|
}
|
|
46
|
-
export declare const
|
|
47
|
-
export declare const
|
|
48
|
-
export declare const
|
|
49
|
-
export interface
|
|
50
|
-
(spec:
|
|
46
|
+
export declare const SCENE_MANAGEMENT_METHOD_SPECS: SceneManagementMethodSpec[];
|
|
47
|
+
export declare const SCENE_MANAGEMENT_SKILL_TAGS: string[];
|
|
48
|
+
export declare const SCENE_MANAGEMENT_SKILL_KEYWORDS: string[];
|
|
49
|
+
export interface SceneManagementToolFactory<T> {
|
|
50
|
+
(spec: SceneManagementMethodSpec, prefix: string, execute: (args: Record<string, any>) => Promise<any>): T;
|
|
51
51
|
}
|
|
52
|
-
export declare function
|
|
53
|
-
export
|
|
54
|
-
|
|
55
|
-
|
|
52
|
+
export declare function defaultScenePermitResolver(adapterPrefix: string): (logicalPerm: string) => string;
|
|
53
|
+
export interface CreateSceneManagementToolsOptions {
|
|
54
|
+
/** 将 SCENE_MANAGEMENT_METHOD_SPECS 逻辑 perm(scene_admin/scene_owner)映射为 platform(...) 字符串 */
|
|
55
|
+
permitResolver?: (logicalPerm: string) => string | undefined;
|
|
56
|
+
/** 是否注册默认 QQ 系 scene checker(默认 true) */
|
|
57
|
+
registerChecker?: boolean;
|
|
58
|
+
}
|
|
59
|
+
export declare function createSceneManagementTools(adapter: ISceneManagement, prefix: string, options?: CreateSceneManagementToolsOptions): Tool[];
|
|
60
|
+
export declare function createSceneManagementToolsRaw<T>(adapter: ISceneManagement, prefix: string, factory: SceneManagementToolFactory<T>): T[];
|
|
61
|
+
export declare function buildSceneMethodArgs(method: keyof ISceneManagement, endpointKey: string, sceneId: string, rest: Record<string, any>): any[];
|