@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,24 +1,25 @@
|
|
|
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
|
-
|
|
15
|
+
import { registerDefaultScenePlatformPermitChecker } from './platform-permit.js';
|
|
16
|
+
export const SCENE_MANAGEMENT_METHOD_SPECS = [
|
|
16
17
|
{
|
|
17
|
-
method: '
|
|
18
|
-
toolSuffix: '
|
|
19
|
-
description: '
|
|
18
|
+
method: 'removeMember',
|
|
19
|
+
toolSuffix: 'remove_member',
|
|
20
|
+
description: '将成员移出当前 IM 场景。适用于严重违规、广告号等需要移除的场景。如果只需要用户名而没有 user_id,请先调用 list_members 查询',
|
|
20
21
|
keywords: ['踢', 'kick', '移除', '踢出'],
|
|
21
|
-
|
|
22
|
+
permit: 'scene_admin',
|
|
22
23
|
extraParams: {
|
|
23
24
|
user_id: { type: 'string', description: '目标用户 ID(如果只有昵称,先用 list_members 查询获取)' },
|
|
24
25
|
},
|
|
@@ -29,7 +30,7 @@ export const GROUP_METHOD_SPECS = [
|
|
|
29
30
|
toolSuffix: 'mute_member',
|
|
30
31
|
description: '禁言或解除禁言群成员。适用于违规发言、刷屏、骚扰他人等需要临时限制发言的场景。duration 单位为秒,传 0 表示解除禁言。默认禁言 10 分钟(600秒)。如果只有昵称而没有 user_id,请先调用 list_members 查询',
|
|
31
32
|
keywords: ['禁言', 'mute', '静音', '解除禁言', '解禁', '闭嘴'],
|
|
32
|
-
|
|
33
|
+
permit: 'scene_admin',
|
|
33
34
|
extraParams: {
|
|
34
35
|
user_id: { type: 'string', description: '目标用户 ID(如果只有昵称,先用 list_members 查询获取)' },
|
|
35
36
|
duration: { type: 'number', description: '禁言时长(秒),0=解除禁言,默认600(10分钟)。常用值:60=1分钟, 600=10分钟, 3600=1小时, 86400=1天', default: 600 },
|
|
@@ -41,7 +42,7 @@ export const GROUP_METHOD_SPECS = [
|
|
|
41
42
|
toolSuffix: 'set_nickname',
|
|
42
43
|
description: '设置群成员的群昵称/名片。仅修改群内显示名称,不影响用户的全局昵称。如果只有昵称而没有 user_id,请先调用 list_members 查询',
|
|
43
44
|
keywords: ['昵称', '名片', 'nickname', 'card', '改名片'],
|
|
44
|
-
|
|
45
|
+
permit: 'scene_admin',
|
|
45
46
|
extraParams: {
|
|
46
47
|
user_id: { type: 'string', description: '目标用户 ID(如果只有昵称,先用 list_members 查询获取)' },
|
|
47
48
|
nickname: { type: 'string', description: '新的群昵称/名片' },
|
|
@@ -49,11 +50,11 @@ export const GROUP_METHOD_SPECS = [
|
|
|
49
50
|
extraRequired: ['user_id', 'nickname'],
|
|
50
51
|
},
|
|
51
52
|
{
|
|
52
|
-
method: '
|
|
53
|
-
toolSuffix: '
|
|
54
|
-
description: '
|
|
53
|
+
method: 'setModerator',
|
|
54
|
+
toolSuffix: 'set_moderator',
|
|
55
|
+
description: '设置或取消场景管理员。注意:此操作通常需要场景所有者权限。enable=true 为设置管理员,enable=false 为取消管理员。如果只有昵称而没有 user_id,请先调用 list_members 查询',
|
|
55
56
|
keywords: ['管理员', 'admin', '设置管理', '取消管理', '提升管理', '撤销管理'],
|
|
56
|
-
|
|
57
|
+
permit: 'scene_owner',
|
|
57
58
|
extraParams: {
|
|
58
59
|
user_id: { type: 'string', description: '目标用户 ID(如果只有昵称,先用 list_members 查询获取)' },
|
|
59
60
|
enable: { type: 'boolean', description: 'true=设置为管理员,false=取消管理员身份', default: true },
|
|
@@ -73,7 +74,7 @@ export const GROUP_METHOD_SPECS = [
|
|
|
73
74
|
toolSuffix: 'ban_member',
|
|
74
75
|
description: '永久封禁成员(拉入黑名单)。与踢人(kick)不同,封禁后该成员无法再加入群聊。适用于恶意用户、严重违规等需要永久禁止的场景。如果只有昵称而没有 user_id,请先调用 list_members 查询',
|
|
75
76
|
keywords: ['封禁', 'ban', '拉黑', '黑名单'],
|
|
76
|
-
|
|
77
|
+
permit: 'scene_admin',
|
|
77
78
|
extraParams: {
|
|
78
79
|
user_id: { type: 'string', description: '目标用户 ID(如果只有昵称,先用 list_members 查询获取)' },
|
|
79
80
|
reason: { type: 'string', description: '封禁原因(将记录在封禁日志中)' },
|
|
@@ -85,37 +86,37 @@ export const GROUP_METHOD_SPECS = [
|
|
|
85
86
|
toolSuffix: 'unban_member',
|
|
86
87
|
description: '解除封禁,将成员从黑名单中移除。解除后该成员可以重新加入群聊。如果只有昵称而没有 user_id,请先调用 list_members 查询',
|
|
87
88
|
keywords: ['解封', 'unban', '解除封禁', '移出黑名单'],
|
|
88
|
-
|
|
89
|
+
permit: 'scene_admin',
|
|
89
90
|
extraParams: {
|
|
90
91
|
user_id: { type: 'string', description: '目标用户 ID(如果只有昵称,先用 list_members 查询获取)' },
|
|
91
92
|
},
|
|
92
93
|
extraRequired: ['user_id'],
|
|
93
94
|
},
|
|
94
95
|
{
|
|
95
|
-
method: '
|
|
96
|
-
toolSuffix: '
|
|
97
|
-
description: '
|
|
96
|
+
method: 'renameScene',
|
|
97
|
+
toolSuffix: 'rename_scene',
|
|
98
|
+
description: '修改 IM 场景名称。修改后所有成员立即可见新名称',
|
|
98
99
|
keywords: ['群名', '改名', 'group name', '修改群名'],
|
|
99
|
-
|
|
100
|
+
permit: 'scene_admin',
|
|
100
101
|
extraParams: {
|
|
101
102
|
name: { type: 'string', description: '新群名称' },
|
|
102
103
|
},
|
|
103
104
|
extraRequired: ['name'],
|
|
104
105
|
},
|
|
105
106
|
{
|
|
106
|
-
method: '
|
|
107
|
-
toolSuffix: '
|
|
108
|
-
description: '
|
|
107
|
+
method: 'setSceneMuted',
|
|
108
|
+
toolSuffix: 'set_scene_muted',
|
|
109
|
+
description: '开启或关闭场景全员禁言。开启后除管理员外所有成员都无法发言。适用于紧急维护、重要通知、聊天秩序混乱等场景。enable=true 开启,enable=false 解除',
|
|
109
110
|
keywords: ['全员禁言', 'mute all', '全体禁言', '全体解禁'],
|
|
110
|
-
|
|
111
|
+
permit: 'scene_admin',
|
|
111
112
|
extraParams: {
|
|
112
113
|
enable: { type: 'boolean', description: 'true=开启全员禁言,false=解除全员禁言', default: true },
|
|
113
114
|
},
|
|
114
115
|
},
|
|
115
116
|
{
|
|
116
|
-
method: '
|
|
117
|
-
toolSuffix: '
|
|
118
|
-
description: '
|
|
117
|
+
method: 'getSceneInfo',
|
|
118
|
+
toolSuffix: 'get_scene_info',
|
|
119
|
+
description: '获取 IM 场景基本信息,包括名称、所有者、成员数量、创建时间等。用于了解场景概况',
|
|
119
120
|
keywords: ['群信息', 'group info', '群资料', '群详情'],
|
|
120
121
|
extraParams: {},
|
|
121
122
|
preExecutable: true,
|
|
@@ -124,42 +125,58 @@ export const GROUP_METHOD_SPECS = [
|
|
|
124
125
|
// ============================================================================
|
|
125
126
|
// Skill 常量(群管相关 SKILL.md 与文档可复用 keywords/tags)
|
|
126
127
|
// ============================================================================
|
|
127
|
-
export const
|
|
128
|
-
export const
|
|
129
|
-
'群管理', '踢人', '禁言', '封禁', '管理员', '群名',
|
|
128
|
+
export const SCENE_MANAGEMENT_SKILL_TAGS = ['scene', 'management', 'im', 'admin'];
|
|
129
|
+
export const SCENE_MANAGEMENT_SKILL_KEYWORDS = [
|
|
130
|
+
'场景治理', '群管理', '踢人', '禁言', '封禁', '管理员', '群名',
|
|
130
131
|
'成员', 'kick', 'mute', 'ban', 'admin', 'members',
|
|
131
132
|
];
|
|
132
|
-
export function
|
|
133
|
-
return
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
133
|
+
export function defaultScenePermitResolver(adapterPrefix) {
|
|
134
|
+
return (logicalPerm) => `platform(${adapterPrefix},${logicalPerm})`;
|
|
135
|
+
}
|
|
136
|
+
function resolveSpecPermit(specPerm, prefix, permitResolver) {
|
|
137
|
+
if (!specPerm)
|
|
138
|
+
return undefined;
|
|
139
|
+
const resolved = permitResolver(specPerm);
|
|
140
|
+
return resolved ? [resolved] : undefined;
|
|
141
|
+
}
|
|
142
|
+
export function createSceneManagementTools(adapter, prefix, options = {}) {
|
|
143
|
+
const permitResolver = options.permitResolver ?? defaultScenePermitResolver(prefix);
|
|
144
|
+
if (options.registerChecker !== false) {
|
|
145
|
+
registerDefaultScenePlatformPermitChecker(prefix);
|
|
146
|
+
}
|
|
147
|
+
return createSceneManagementToolsRaw(adapter, prefix, (spec, prefix, execute) => {
|
|
148
|
+
const specPermissions = resolveSpecPermit(spec.permit, prefix, permitResolver);
|
|
149
|
+
return {
|
|
150
|
+
name: `${prefix}_${spec.toolSuffix}`,
|
|
151
|
+
description: `${spec.description} (${prefix})`,
|
|
152
|
+
parameters: {
|
|
153
|
+
type: 'object',
|
|
154
|
+
properties: {
|
|
155
|
+
endpoint_id: { type: 'string', description: 'Endpoint ID', contextKey: 'endpointKey' },
|
|
156
|
+
scene_id: { type: 'string', description: 'IM 场景 ID', contextKey: 'sceneId' },
|
|
157
|
+
...Object.fromEntries(Object.entries(spec.extraParams)),
|
|
158
|
+
},
|
|
159
|
+
required: ['endpoint_id', 'scene_id', ...(spec.extraRequired ?? [])],
|
|
142
160
|
},
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
}));
|
|
161
|
+
execute,
|
|
162
|
+
tags: ['scene', 'management', prefix],
|
|
163
|
+
keywords: spec.keywords,
|
|
164
|
+
...(specPermissions ? { permissions: specPermissions } : {}),
|
|
165
|
+
scopes: ['group', 'channel'],
|
|
166
|
+
preExecutable: spec.preExecutable,
|
|
167
|
+
};
|
|
168
|
+
});
|
|
152
169
|
}
|
|
153
|
-
export function
|
|
170
|
+
export function createSceneManagementToolsRaw(adapter, prefix, factory) {
|
|
154
171
|
const tools = [];
|
|
155
|
-
for (const spec of
|
|
172
|
+
for (const spec of SCENE_MANAGEMENT_METHOD_SPECS) {
|
|
156
173
|
const fn = adapter[spec.method];
|
|
157
174
|
if (typeof fn !== 'function')
|
|
158
175
|
continue;
|
|
159
176
|
const boundFn = fn.bind(adapter);
|
|
160
177
|
const execute = async (args) => {
|
|
161
|
-
const {
|
|
162
|
-
const methodArgs =
|
|
178
|
+
const { endpoint_id, scene_id, ...rest } = args;
|
|
179
|
+
const methodArgs = buildSceneMethodArgs(spec.method, endpoint_id, scene_id, rest);
|
|
163
180
|
return boundFn.apply(adapter, methodArgs);
|
|
164
181
|
};
|
|
165
182
|
tools.push(factory(spec, prefix, execute));
|
|
@@ -169,19 +186,18 @@ export function createGroupManagementToolsRaw(adapter, prefix, factory) {
|
|
|
169
186
|
// ============================================================================
|
|
170
187
|
// 参数映射(method → 有序参数列表)
|
|
171
188
|
// ============================================================================
|
|
172
|
-
export function
|
|
189
|
+
export function buildSceneMethodArgs(method, endpointKey, sceneId, rest) {
|
|
173
190
|
switch (method) {
|
|
174
|
-
case '
|
|
175
|
-
case 'muteMember': return [
|
|
176
|
-
case 'setMemberNickname': return [
|
|
177
|
-
case '
|
|
178
|
-
case 'listMembers': return [
|
|
179
|
-
case 'banMember': return [
|
|
180
|
-
case 'unbanMember': return [
|
|
181
|
-
case '
|
|
182
|
-
case '
|
|
183
|
-
case '
|
|
184
|
-
default: return [
|
|
191
|
+
case 'removeMember': return [endpointKey, sceneId, rest.user_id];
|
|
192
|
+
case 'muteMember': return [endpointKey, sceneId, rest.user_id, rest.duration ?? 600];
|
|
193
|
+
case 'setMemberNickname': return [endpointKey, sceneId, rest.user_id, rest.nickname];
|
|
194
|
+
case 'setModerator': return [endpointKey, sceneId, rest.user_id, rest.enable ?? true];
|
|
195
|
+
case 'listMembers': return [endpointKey, sceneId];
|
|
196
|
+
case 'banMember': return [endpointKey, sceneId, rest.user_id, rest.reason];
|
|
197
|
+
case 'unbanMember': return [endpointKey, sceneId, rest.user_id];
|
|
198
|
+
case 'renameScene': return [endpointKey, sceneId, rest.name];
|
|
199
|
+
case 'setSceneMuted': return [endpointKey, sceneId, rest.enable ?? true];
|
|
200
|
+
case 'getSceneInfo': return [endpointKey, sceneId];
|
|
201
|
+
default: return [endpointKey, sceneId, ...Object.values(rest)];
|
|
185
202
|
}
|
|
186
203
|
}
|
|
187
|
-
//# sourceMappingURL=common-adapter-tools.js.map
|
package/lib/built/component.d.ts
CHANGED
|
@@ -2,9 +2,8 @@
|
|
|
2
2
|
* ComponentFeature
|
|
3
3
|
* 管理所有插件注册的组件,继承自 Feature 抽象类
|
|
4
4
|
*/
|
|
5
|
-
import { Feature, FeatureJSON } from
|
|
5
|
+
import { Feature, FeatureJSON, type PluginLike } from '@zhin.js/kernel';
|
|
6
6
|
import { Component } from "../component.js";
|
|
7
|
-
import type { PluginLike } from '@zhin.js/kernel';
|
|
8
7
|
/**
|
|
9
8
|
* ComponentContext 扩展方法类型
|
|
10
9
|
*/
|
|
@@ -66,4 +65,3 @@ export declare class ComponentFeature extends Feature<Component<any>> {
|
|
|
66
65
|
addComponent<T extends Component<any>>(component: T): () => void;
|
|
67
66
|
};
|
|
68
67
|
}
|
|
69
|
-
//# sourceMappingURL=component.d.ts.map
|
package/lib/built/component.js
CHANGED
|
@@ -2,9 +2,8 @@
|
|
|
2
2
|
* ComponentFeature
|
|
3
3
|
* 管理所有插件注册的组件,继承自 Feature 抽象类
|
|
4
4
|
*/
|
|
5
|
-
import { Feature } from
|
|
5
|
+
import { Feature } from '@zhin.js/kernel';
|
|
6
6
|
import { renderComponents } from "../component.js";
|
|
7
|
-
import { getPlugin } from "../plugin.js";
|
|
8
7
|
/**
|
|
9
8
|
* 组件服务 Feature
|
|
10
9
|
*/
|
|
@@ -87,7 +86,7 @@ export class ComponentFeature extends Feature {
|
|
|
87
86
|
const feature = this;
|
|
88
87
|
return {
|
|
89
88
|
addComponent(component) {
|
|
90
|
-
const plugin =
|
|
89
|
+
const plugin = this;
|
|
91
90
|
const dispose = feature.add(component, plugin.name);
|
|
92
91
|
plugin.recordFeatureContribution(feature.name, component.name);
|
|
93
92
|
plugin.onDispose(dispose);
|
|
@@ -96,4 +95,3 @@ export class ComponentFeature extends Feature {
|
|
|
96
95
|
};
|
|
97
96
|
}
|
|
98
97
|
}
|
|
99
|
-
//# sourceMappingURL=component.js.map
|
package/lib/built/config.d.ts
CHANGED
|
@@ -10,6 +10,8 @@ export declare class ConfigLoader<T extends object> {
|
|
|
10
10
|
get data(): T;
|
|
11
11
|
get raw(): T;
|
|
12
12
|
get extension(): string;
|
|
13
|
+
/** `load()` / `patchKey()` 使用的绝对路径 */
|
|
14
|
+
get resolvedPath(): string;
|
|
13
15
|
constructor(filename: string, initial: T, schema?: Schema<T> | undefined);
|
|
14
16
|
resolvePath(baseDir?: string): string;
|
|
15
17
|
load(baseDir?: string): void;
|
|
@@ -20,6 +22,8 @@ export declare class ConfigLoader<T extends object> {
|
|
|
20
22
|
*/
|
|
21
23
|
patchKey(key: string, value: any): void;
|
|
22
24
|
}
|
|
25
|
+
/** 解析 endpoint 配置中的 `${ENV}` 引用(运行时 add 后热连接用) */
|
|
26
|
+
export declare function resolveEndpointConfigEnv(config: Record<string, unknown>): Record<string, unknown>;
|
|
23
27
|
export declare function mergeConfigDefaults<T>(defaults: T, overrides: unknown): T;
|
|
24
28
|
export declare namespace ConfigLoader {
|
|
25
29
|
const supportedExtensions: string[];
|
|
@@ -92,8 +96,3 @@ export declare class ConfigFeature extends Feature<ConfigRecord> {
|
|
|
92
96
|
addConfig(key: string, defaultValue: any): () => void;
|
|
93
97
|
};
|
|
94
98
|
}
|
|
95
|
-
/**
|
|
96
|
-
* @deprecated Use ConfigFeature instead
|
|
97
|
-
*/
|
|
98
|
-
export declare const ConfigService: typeof ConfigFeature;
|
|
99
|
-
//# sourceMappingURL=config.d.ts.map
|
package/lib/built/config.js
CHANGED
|
@@ -8,7 +8,6 @@ import fs from "node:fs";
|
|
|
8
8
|
import { stringify as stringifyYaml, parse as parseYaml, parseDocument } from "yaml";
|
|
9
9
|
import { parse as parseToml, stringify as stringifyToml } from "smol-toml";
|
|
10
10
|
import { Feature } from "@zhin.js/kernel";
|
|
11
|
-
import { getPlugin } from "../plugin.js";
|
|
12
11
|
/** Deno / Node 统一的工作目录(`Deno.chdir` 后应与 `process.cwd()` 一致) */
|
|
13
12
|
export function runtimeCwd() {
|
|
14
13
|
const g = globalThis;
|
|
@@ -37,6 +36,10 @@ export class ConfigLoader {
|
|
|
37
36
|
get extension() {
|
|
38
37
|
return path.extname(this.filename).toLowerCase();
|
|
39
38
|
}
|
|
39
|
+
/** `load()` / `patchKey()` 使用的绝对路径 */
|
|
40
|
+
get resolvedPath() {
|
|
41
|
+
return this.#resolvedPath || this.resolvePath();
|
|
42
|
+
}
|
|
40
43
|
constructor(filename, initial, schema) {
|
|
41
44
|
this.filename = filename;
|
|
42
45
|
this.initial = initial;
|
|
@@ -96,8 +99,10 @@ export class ConfigLoader {
|
|
|
96
99
|
? this.filename
|
|
97
100
|
: path.resolve(baseDir, this.filename);
|
|
98
101
|
}
|
|
99
|
-
load(baseDir
|
|
100
|
-
const fullPath =
|
|
102
|
+
load(baseDir) {
|
|
103
|
+
const fullPath = baseDir !== undefined
|
|
104
|
+
? this.resolvePath(baseDir)
|
|
105
|
+
: (this.#resolvedPath || this.resolvePath());
|
|
101
106
|
this.#resolvedPath = fullPath;
|
|
102
107
|
if (!fs.existsSync(fullPath)) {
|
|
103
108
|
try {
|
|
@@ -197,6 +202,23 @@ function isPlainObject(value) {
|
|
|
197
202
|
&& !Array.isArray(value)
|
|
198
203
|
&& Object.getPrototypeOf(value) === Object.prototype;
|
|
199
204
|
}
|
|
205
|
+
/** 解析 endpoint 配置中的 `${ENV}` 引用(运行时 add 后热连接用) */
|
|
206
|
+
export function resolveEndpointConfigEnv(config) {
|
|
207
|
+
const out = { ...config };
|
|
208
|
+
for (const [key, value] of Object.entries(out)) {
|
|
209
|
+
if (typeof value !== 'string')
|
|
210
|
+
continue;
|
|
211
|
+
const match = value.match(/^\$\{([^}]+)\}$/);
|
|
212
|
+
if (!match)
|
|
213
|
+
continue;
|
|
214
|
+
const envKey = match[1];
|
|
215
|
+
const resolved = envLookup(envKey);
|
|
216
|
+
if (resolved != null && resolved !== '') {
|
|
217
|
+
out[key] = resolved;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
return out;
|
|
221
|
+
}
|
|
200
222
|
export function mergeConfigDefaults(defaults, overrides) {
|
|
201
223
|
if (Array.isArray(defaults)) {
|
|
202
224
|
return (Array.isArray(overrides) ? overrides : defaults);
|
|
@@ -327,7 +349,7 @@ export class ConfigFeature extends Feature {
|
|
|
327
349
|
const feature = this;
|
|
328
350
|
return {
|
|
329
351
|
addConfig(key, defaultValue) {
|
|
330
|
-
const plugin =
|
|
352
|
+
const plugin = this;
|
|
331
353
|
// 尝试写入主配置文件(如果 key 不存在)
|
|
332
354
|
if (feature.#primaryConfigFile) {
|
|
333
355
|
const config = feature.configs.get(feature.#primaryConfigFile);
|
|
@@ -348,8 +370,3 @@ export class ConfigFeature extends Feature {
|
|
|
348
370
|
};
|
|
349
371
|
}
|
|
350
372
|
}
|
|
351
|
-
/**
|
|
352
|
-
* @deprecated Use ConfigFeature instead
|
|
353
|
-
*/
|
|
354
|
-
export const ConfigService = ConfigFeature;
|
|
355
|
-
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Adapter } from '../adapter.js';
|
|
2
|
+
import type { Endpoint } from '../endpoint.js';
|
|
3
|
+
import type { Plugin } from '../plugin.js';
|
|
4
|
+
import { type EndpointCapabilitiesConfig } from '../endpoint-capabilities.js';
|
|
5
|
+
export interface ConnectEndpointInstanceOptions {
|
|
6
|
+
plugin: Plugin;
|
|
7
|
+
adapter: Adapter;
|
|
8
|
+
config: EndpointCapabilitiesConfig & Record<string, unknown>;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* 按 Endpoint capabilities 连接或注册单个实例(connectEndpoints 与 Adapter.start 共用)。
|
|
12
|
+
*/
|
|
13
|
+
export declare function connectEndpointInstance(options: ConnectEndpointInstanceOptions): Promise<Endpoint>;
|
|
14
|
+
/**
|
|
15
|
+
* 按 Endpoint capabilities 断开单个实例。
|
|
16
|
+
*/
|
|
17
|
+
export declare function disconnectEndpointInstance(plugin: Plugin, adapter: Adapter, endpoint: Endpoint): Promise<void>;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { assertInbound, getAdapterCapabilities, hasInbound, registerEndpointCapabilities, resolveEndpointCapabilities, } from '../endpoint-capabilities.js';
|
|
2
|
+
import { emitEndpointLifecycle } from './endpoint-lifecycle.js';
|
|
3
|
+
import { resolveEndpointConfigEnv } from './config.js';
|
|
4
|
+
/**
|
|
5
|
+
* 按 Endpoint capabilities 连接或注册单个实例(connectEndpoints 与 Adapter.start 共用)。
|
|
6
|
+
*/
|
|
7
|
+
export async function connectEndpointInstance(options) {
|
|
8
|
+
const { plugin, adapter, config } = options;
|
|
9
|
+
const adapterCaps = getAdapterCapabilities(adapter);
|
|
10
|
+
const caps = resolveEndpointCapabilities(adapterCaps, config.capabilities);
|
|
11
|
+
const resolvedConfig = resolveEndpointConfigEnv(config);
|
|
12
|
+
const endpoint = adapter.createEndpoint(resolvedConfig);
|
|
13
|
+
registerEndpointCapabilities(endpoint, caps);
|
|
14
|
+
if (caps.includes('inbound')) {
|
|
15
|
+
assertInbound(endpoint);
|
|
16
|
+
try {
|
|
17
|
+
await endpoint.$connect();
|
|
18
|
+
await emitEndpointLifecycle(plugin, adapter, endpoint, 'connect');
|
|
19
|
+
}
|
|
20
|
+
catch (error) {
|
|
21
|
+
await emitEndpointLifecycle(plugin, adapter, endpoint, 'error', {
|
|
22
|
+
error: error instanceof Error ? error.message : String(error),
|
|
23
|
+
phase: 'connect',
|
|
24
|
+
});
|
|
25
|
+
throw error;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
endpoint.$connected = true;
|
|
30
|
+
}
|
|
31
|
+
return endpoint;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* 按 Endpoint capabilities 断开单个实例。
|
|
35
|
+
*/
|
|
36
|
+
export async function disconnectEndpointInstance(plugin, adapter, endpoint) {
|
|
37
|
+
if (!hasInbound(endpoint))
|
|
38
|
+
return;
|
|
39
|
+
assertInbound(endpoint);
|
|
40
|
+
await endpoint.$disconnect();
|
|
41
|
+
await emitEndpointLifecycle(plugin, adapter, endpoint, 'disconnect');
|
|
42
|
+
}
|
package/lib/built/database.d.ts
CHANGED
|
@@ -4,8 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { Definition, Database } from "@zhin.js/database";
|
|
6
6
|
import { DatabaseConfig, Models } from "../types.js";
|
|
7
|
-
import { Feature, FeatureJSON } from
|
|
8
|
-
import type { PluginLike } from '@zhin.js/kernel';
|
|
7
|
+
import { Feature, FeatureJSON, type PluginLike } from '@zhin.js/kernel';
|
|
9
8
|
/**
|
|
10
9
|
* 模型定义记录
|
|
11
10
|
*/
|
|
@@ -23,6 +22,9 @@ declare module "../plugin.js" {
|
|
|
23
22
|
}
|
|
24
23
|
}
|
|
25
24
|
}
|
|
25
|
+
type DatabaseAfterStartHook = (db: Database<any, Models, any>) => void | Promise<void>;
|
|
26
|
+
/** 在 `db.start()` 完成之后、`context.mounted` 发出之前执行(用于 schema 迁移) */
|
|
27
|
+
export declare function onDatabaseAfterStart(hook: DatabaseAfterStartHook): void;
|
|
26
28
|
export declare class DatabaseFeature extends Feature<ModelRecord> {
|
|
27
29
|
readonly name: "database";
|
|
28
30
|
readonly icon = "Database";
|
|
@@ -63,4 +65,4 @@ export declare class DatabaseFeature extends Feature<ModelRecord> {
|
|
|
63
65
|
defineModel<K extends keyof Models>(name: K, definition: Definition<Models[K]>): void;
|
|
64
66
|
};
|
|
65
67
|
}
|
|
66
|
-
|
|
68
|
+
export {};
|
package/lib/built/database.js
CHANGED
|
@@ -4,10 +4,14 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { Registry } from "@zhin.js/database";
|
|
6
6
|
import { formatCompact } from '@zhin.js/logger';
|
|
7
|
-
import { Feature } from
|
|
8
|
-
import { getPlugin } from "../plugin.js";
|
|
7
|
+
import { Feature } from '@zhin.js/kernel';
|
|
9
8
|
import { SystemLogDefinition } from "../models/system-log.js";
|
|
10
9
|
import { UserDefinition } from "../models/user.js";
|
|
10
|
+
const databaseAfterStartHooks = [];
|
|
11
|
+
/** 在 `db.start()` 完成之后、`context.mounted` 发出之前执行(用于 schema 迁移) */
|
|
12
|
+
export function onDatabaseAfterStart(hook) {
|
|
13
|
+
databaseAfterStartHooks.push(hook);
|
|
14
|
+
}
|
|
11
15
|
export class DatabaseFeature extends Feature {
|
|
12
16
|
name = 'database';
|
|
13
17
|
icon = 'Database';
|
|
@@ -59,6 +63,9 @@ export class DatabaseFeature extends Feature {
|
|
|
59
63
|
async mounted(plugin) {
|
|
60
64
|
plugin.logger.debug(formatCompact({ ready: true }));
|
|
61
65
|
await this.db.start();
|
|
66
|
+
for (const hook of databaseAfterStartHooks) {
|
|
67
|
+
await hook(this.db);
|
|
68
|
+
}
|
|
62
69
|
}
|
|
63
70
|
/**
|
|
64
71
|
* 生命周期: 停止数据库
|
|
@@ -88,7 +95,7 @@ export class DatabaseFeature extends Feature {
|
|
|
88
95
|
const feature = this;
|
|
89
96
|
return {
|
|
90
97
|
defineModel(name, definition) {
|
|
91
|
-
const plugin =
|
|
98
|
+
const plugin = this;
|
|
92
99
|
const record = { name: name, definition };
|
|
93
100
|
const dispose = feature.add(record, plugin.name);
|
|
94
101
|
plugin.recordFeatureContribution(feature.name, name);
|
|
@@ -97,4 +104,3 @@ export class DatabaseFeature extends Feature {
|
|
|
97
104
|
};
|
|
98
105
|
}
|
|
99
106
|
}
|
|
100
|
-
//# sourceMappingURL=database.js.map
|
|
@@ -27,12 +27,10 @@
|
|
|
27
27
|
* 默认路由为 exclusive(命令与 AI 互斥);需双轨时请显式 dualRoute.mode: 'dual'。
|
|
28
28
|
*/
|
|
29
29
|
import { Message } from '../message.js';
|
|
30
|
-
import
|
|
31
|
-
import type
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
source: OutboundReplySource;
|
|
35
|
-
} | undefined;
|
|
30
|
+
import { type Context } from '../plugin.js';
|
|
31
|
+
import { type PermissionHost } from '@zhin.js/permission';
|
|
32
|
+
import type { MessageMiddleware, RegisteredAdapter, MaybePromise, SendContent, OutboundReplySource, OutboundPolishMiddleware, OutboundReplyStore } from '../types.js';
|
|
33
|
+
export declare function getOutboundReplyStore(): OutboundReplyStore | undefined;
|
|
36
34
|
/**
|
|
37
35
|
* 路由判定结果(互斥模式 legacy)
|
|
38
36
|
*/
|
|
@@ -82,7 +80,7 @@ export type AITriggerMatcher = (message: Message<any>) => {
|
|
|
82
80
|
*/
|
|
83
81
|
export type GroupPassiveContextHandler = (message: Message<any>) => MaybePromise<void>;
|
|
84
82
|
export type GuardrailMiddleware = MessageMiddleware<RegisteredAdapter>;
|
|
85
|
-
/**
|
|
83
|
+
/** Backward-compatible name for the command or AI outbound reply source. */
|
|
86
84
|
export type ReplySource = OutboundReplySource;
|
|
87
85
|
/** replyWithPolish 可选参数 */
|
|
88
86
|
export interface ReplyWithPolishOptions {
|
|
@@ -91,6 +89,7 @@ export interface ReplyWithPolishOptions {
|
|
|
91
89
|
}
|
|
92
90
|
export interface CreateMessageDispatcherOptions {
|
|
93
91
|
dualRoute?: Partial<DualRouteConfig>;
|
|
92
|
+
permissionHost?: PermissionHost | null;
|
|
94
93
|
}
|
|
95
94
|
export interface MessageDispatcherService {
|
|
96
95
|
dispatch(message: Message<any>): Promise<void>;
|
|
@@ -110,6 +109,10 @@ export interface MessageDispatcherService {
|
|
|
110
109
|
* 在 `before.sendMessage` 管道内调用 `message.$reply`(与 Adapter#sendMessage 同一出站链)
|
|
111
110
|
*/
|
|
112
111
|
replyWithPolish(message: Message<any>, source: ReplySource, content: SendContent, options?: ReplyWithPolishOptions): Promise<unknown>;
|
|
112
|
+
/** Proactive 出站:在 ALS 内执行 send,触发 outbound polish / before.sendMessage */
|
|
113
|
+
runWithOutboundPolish<T>(store: Pick<OutboundReplyStore, 'message' | 'trigger' | 'proactiveSource'> & {
|
|
114
|
+
source?: OutboundReplySource;
|
|
115
|
+
}, fn: () => Promise<T>): Promise<T>;
|
|
113
116
|
/**
|
|
114
117
|
* 是否匹配为指令路径(与 dispatch 内判定一致)
|
|
115
118
|
*/
|
|
@@ -136,4 +139,3 @@ declare module '../plugin.js' {
|
|
|
136
139
|
}
|
|
137
140
|
}
|
|
138
141
|
export declare function createMessageDispatcher(options?: CreateMessageDispatcherOptions): Context<'dispatcher', DispatcherContextExtensions>;
|
|
139
|
-
//# sourceMappingURL=dispatcher.d.ts.map
|