@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
package/lib/plugin.js
CHANGED
|
@@ -6,15 +6,18 @@
|
|
|
6
6
|
* - 生命周期事件类型安全(Plugin.Lifecycle)
|
|
7
7
|
* - 中间件系统、适配器管理、useContext 等
|
|
8
8
|
*/
|
|
9
|
-
import { AsyncLocalStorage } from "node:async_hooks";
|
|
10
9
|
import * as fs from "node:fs";
|
|
11
10
|
import * as path from "node:path";
|
|
12
|
-
import {
|
|
11
|
+
import { pathToFileURL } from "node:url";
|
|
13
12
|
import { formatCompact } from "@zhin.js/logger";
|
|
14
13
|
import { compose, remove, resolveEntry } from "./utils.js";
|
|
14
|
+
import { ensureInteractiveMiddleware, registerInteractiveHandler as registerInteractiveHandlerCore, } from "./built/interactive-segments/handlers.js";
|
|
15
15
|
import { Adapter } from "./adapter.js";
|
|
16
|
-
import { Feature } from
|
|
17
|
-
import {
|
|
16
|
+
import { Feature, PluginBase, resolvePluginResolveDir as _resolvePluginResolveDir, pluginCreateRequire as _pluginCreateRequire, getFileHash, watchFile, registerExtension, unregisterExtensions, installExtensionProxy } from '@zhin.js/kernel';
|
|
17
|
+
import { storage } from "./plugin-context.js";
|
|
18
|
+
export { getPlugin, markPluginRuntimeActive, isPluginRuntimeActive, resetPluginRuntimeFlag } from "./plugin-context.js";
|
|
19
|
+
export { storage, getCurrentFile } from "./plugin-context.js";
|
|
20
|
+
export { setHostRootPlugin, getHostRootPlugin } from "./host-plugin-registry.js";
|
|
18
21
|
const contextsKey = Symbol("contexts");
|
|
19
22
|
function resolvePluginResolveDir(parent) {
|
|
20
23
|
return _resolvePluginResolveDir(parent);
|
|
@@ -23,68 +26,13 @@ const loadedModules = new Map();
|
|
|
23
26
|
function pluginCreateRequire() {
|
|
24
27
|
return _pluginCreateRequire();
|
|
25
28
|
}
|
|
26
|
-
// ============================================================================
|
|
27
|
-
// AsyncLocalStorage 上下文
|
|
28
|
-
// ============================================================================
|
|
29
|
-
export const storage = new AsyncLocalStorage();
|
|
30
29
|
/**
|
|
31
|
-
*
|
|
32
|
-
|
|
33
|
-
function getCurrentFile(metaUrl = import.meta.url) {
|
|
34
|
-
if (typeof metaUrl !== "string" || metaUrl.length === 0) {
|
|
35
|
-
return path.join(process.cwd(), "__zhin_edge_bootstrap__.mjs");
|
|
36
|
-
}
|
|
37
|
-
const previousPrepareStackTrace = Error.prepareStackTrace;
|
|
38
|
-
Error.prepareStackTrace = function (_, stack) {
|
|
39
|
-
return stack;
|
|
40
|
-
};
|
|
41
|
-
const stack = new Error().stack;
|
|
42
|
-
Error.prepareStackTrace = previousPrepareStackTrace;
|
|
43
|
-
const stackFiles = Array.from(new Set(stack.map((site) => site.getFileName())));
|
|
44
|
-
const idx = stackFiles.findIndex((f) => f === fileURLToPath(metaUrl) || f === metaUrl);
|
|
45
|
-
const result = stackFiles[idx + 1];
|
|
46
|
-
if (!result) {
|
|
47
|
-
return path.join(process.cwd(), "__zhin_edge_bootstrap__.mjs");
|
|
48
|
-
}
|
|
49
|
-
try {
|
|
50
|
-
return fileURLToPath(result);
|
|
51
|
-
}
|
|
52
|
-
catch {
|
|
53
|
-
return result;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* usePlugin - 获取或创建当前插件实例
|
|
58
|
-
* 类似 React Hooks 的设计,根据调用文件自动创建插件树
|
|
59
|
-
* 同一上下文中同一文件多次调用返回同一实例
|
|
30
|
+
* @deprecated **已删除**。请使用 `definePlugin` + 约定目录(`zhin runtime start`)。
|
|
31
|
+
* @throws 总是抛出——仅保留签名供编译期过渡。
|
|
60
32
|
*/
|
|
61
33
|
export function usePlugin() {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
const current = storage.getStore();
|
|
65
|
-
if (current && current.filePath.replace(/\?t=\d+$/, '') === callerFile.replace(/\?t=\d+$/, '')) {
|
|
66
|
-
return current;
|
|
67
|
-
}
|
|
68
|
-
const parentPlugin = current;
|
|
69
|
-
const newPlugin = new Plugin(callerFile, parentPlugin);
|
|
70
|
-
try {
|
|
71
|
-
storage.enterWith(newPlugin);
|
|
72
|
-
}
|
|
73
|
-
catch {
|
|
74
|
-
// Cloudflare Workers 等环境未实现 enterWith;调用方须用 storage.run()
|
|
75
|
-
}
|
|
76
|
-
return newPlugin;
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* getPlugin - 获取当前 AsyncLocalStorage 中的插件实例
|
|
80
|
-
* 用于 extensions 等场景,不创建新插件
|
|
81
|
-
*/
|
|
82
|
-
export function getPlugin() {
|
|
83
|
-
const plugin = storage.getStore();
|
|
84
|
-
if (!plugin) {
|
|
85
|
-
throw new Error('getPlugin() must be called within a plugin context');
|
|
86
|
-
}
|
|
87
|
-
return plugin;
|
|
34
|
+
throw new Error('usePlugin() has been removed. Use `definePlugin` + convention directories instead. '
|
|
35
|
+
+ 'See docs/contributing/public-api-surface.md');
|
|
88
36
|
}
|
|
89
37
|
/**
|
|
90
38
|
* Plugin 类 - IM 特化插件,继承 PluginBase
|
|
@@ -106,33 +54,14 @@ export class Plugin extends PluginBase {
|
|
|
106
54
|
get root() {
|
|
107
55
|
return super.root;
|
|
108
56
|
}
|
|
109
|
-
//
|
|
110
|
-
#messageMiddleware = async (
|
|
111
|
-
|
|
112
|
-
if (!commandService)
|
|
113
|
-
return await next();
|
|
114
|
-
const result = await commandService.handle(message, this);
|
|
115
|
-
if (result === undefined || result === null)
|
|
116
|
-
return await next();
|
|
117
|
-
const adapter = this.inject(message.$adapter);
|
|
118
|
-
if (!adapter || !(adapter instanceof Adapter))
|
|
119
|
-
return await next();
|
|
120
|
-
await message.$reply(result);
|
|
57
|
+
// 默认中间件:将入站消息交给 compose 链末端的 MessageDispatcher(命令/AI 路由在 dispatcher 内完成)
|
|
58
|
+
#messageMiddleware = async (_message, next) => {
|
|
59
|
+
await next();
|
|
121
60
|
};
|
|
122
61
|
#middlewares = [this.#messageMiddleware];
|
|
123
|
-
// Feature 贡献追踪
|
|
124
|
-
#featureContributions = new Map();
|
|
125
|
-
// 统一的清理函数集合
|
|
126
|
-
#disposables = new Set();
|
|
127
62
|
get middleware() {
|
|
128
63
|
return compose(this.#middlewares);
|
|
129
64
|
}
|
|
130
|
-
recordFeatureContribution(featureName, itemName) {
|
|
131
|
-
if (!this.#featureContributions.has(featureName)) {
|
|
132
|
-
this.#featureContributions.set(featureName, new Set());
|
|
133
|
-
}
|
|
134
|
-
this.#featureContributions.get(featureName).add(itemName);
|
|
135
|
-
}
|
|
136
65
|
/**
|
|
137
66
|
* 构造函数
|
|
138
67
|
*/
|
|
@@ -152,11 +81,17 @@ export class Plugin extends PluginBase {
|
|
|
152
81
|
*/
|
|
153
82
|
addMiddleware(middleware, name) {
|
|
154
83
|
this.#middlewares.push(middleware);
|
|
155
|
-
const dispose = () =>
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
84
|
+
const dispose = () => remove(this.#middlewares, middleware);
|
|
85
|
+
this.onDispose(dispose);
|
|
86
|
+
return dispose;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* 注册交互式 action 回调处理器(自动安装根中间件,优先于 Dispatcher)
|
|
90
|
+
*/
|
|
91
|
+
registerInteractiveHandler(prefix, handler) {
|
|
92
|
+
ensureInteractiveMiddleware((mw) => this.root.addMiddleware(mw));
|
|
93
|
+
const dispose = registerInteractiveHandlerCore(prefix, handler);
|
|
94
|
+
this.onDispose(dispose);
|
|
160
95
|
return dispose;
|
|
161
96
|
}
|
|
162
97
|
/**
|
|
@@ -165,15 +100,20 @@ export class Plugin extends PluginBase {
|
|
|
165
100
|
get name() {
|
|
166
101
|
if (this.#cachedName)
|
|
167
102
|
return this.#cachedName;
|
|
168
|
-
|
|
103
|
+
let name = path
|
|
169
104
|
.relative(process.cwd(), this.filePath)
|
|
170
105
|
.replace(/\?t=\d+$/, "")
|
|
171
106
|
.replace(/\\/g, "/")
|
|
172
107
|
.replace(/\/index\.(js|ts)x?$/, "")
|
|
173
|
-
.replace(/\/(lib|src|dist)$/, "")
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
.
|
|
108
|
+
.replace(/\/(lib|src|dist)$/, "");
|
|
109
|
+
const nodeModulesIndex = name.indexOf("node_modules/");
|
|
110
|
+
if (nodeModulesIndex !== -1)
|
|
111
|
+
name = name.slice(nodeModulesIndex + "node_modules/".length);
|
|
112
|
+
const slash = name.lastIndexOf("/");
|
|
113
|
+
if (slash !== -1)
|
|
114
|
+
name = name.slice(slash + 1);
|
|
115
|
+
name = name.replace(/\.(js|ts)x?$/, "");
|
|
116
|
+
this.#cachedName = name;
|
|
177
117
|
return this.#cachedName;
|
|
178
118
|
}
|
|
179
119
|
/**
|
|
@@ -248,10 +188,9 @@ export class Plugin extends PluginBase {
|
|
|
248
188
|
sideEffect.finished = false;
|
|
249
189
|
};
|
|
250
190
|
this.on('context.dispose', disposeFn);
|
|
251
|
-
// 确保 dispose 时清理监听器(只注册一次)
|
|
252
191
|
const cleanupOnDispose = () => {
|
|
253
192
|
this.off('context.dispose', disposeFn);
|
|
254
|
-
dispose(this.inject(
|
|
193
|
+
dispose(this.inject(contexts[0]));
|
|
255
194
|
};
|
|
256
195
|
this.once('dispose', cleanupOnDispose);
|
|
257
196
|
};
|
|
@@ -268,7 +207,8 @@ export class Plugin extends PluginBase {
|
|
|
268
207
|
contextReadyCallback();
|
|
269
208
|
}
|
|
270
209
|
inject(name) {
|
|
271
|
-
const
|
|
210
|
+
const resolved = name === 'cron' ? 'schedule' : name;
|
|
211
|
+
const context = this.root.contexts.get(resolved);
|
|
272
212
|
return context?.value;
|
|
273
213
|
}
|
|
274
214
|
injectAdapter(name) {
|
|
@@ -293,44 +233,41 @@ export class Plugin extends PluginBase {
|
|
|
293
233
|
// ============================================================================
|
|
294
234
|
/**
|
|
295
235
|
* 启动插件
|
|
236
|
+
* 覆盖 PluginBase.start() 以支持 Context 挂载失败回滚
|
|
296
237
|
*/
|
|
297
238
|
async start(t) {
|
|
298
239
|
if (this.started)
|
|
299
240
|
return;
|
|
300
|
-
//
|
|
241
|
+
// 先挂载所有 Context(带回滚),再标记 started
|
|
242
|
+
await this.mountAllContexts();
|
|
243
|
+
this.started = true;
|
|
244
|
+
await this.broadcast("mounted");
|
|
245
|
+
for (const child of this.children) {
|
|
246
|
+
await child.start(t);
|
|
247
|
+
}
|
|
248
|
+
if (t) {
|
|
249
|
+
this.logger.debug(formatCompact({ name: this.name, reload_ms: Date.now() - t }));
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* 覆盖 mountAllContexts:支持部分失败回滚
|
|
254
|
+
*/
|
|
255
|
+
async mountAllContexts() {
|
|
301
256
|
const mountedContexts = [];
|
|
302
257
|
for (const [name, context] of this.$contexts) {
|
|
303
258
|
try {
|
|
304
|
-
|
|
305
|
-
const result = await context.mounted(this);
|
|
306
|
-
// 仅在没有预设 value 时才用 mounted 返回值赋值
|
|
307
|
-
if (!context.value) {
|
|
308
|
-
context.value = result;
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
// 注册扩展方法到共享 registry
|
|
312
|
-
if (context.extensions) {
|
|
313
|
-
installExtensionProxy(Plugin.prototype);
|
|
314
|
-
for (const [extName, fn] of Object.entries(context.extensions)) {
|
|
315
|
-
if (typeof fn === 'function') {
|
|
316
|
-
registerExtension(extName, fn);
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
}
|
|
259
|
+
await this.mountContext(context);
|
|
320
260
|
mountedContexts.push({ name, context });
|
|
321
261
|
}
|
|
322
262
|
catch (e) {
|
|
323
|
-
// 回滚已挂载的 Context(逆序 dispose)
|
|
324
263
|
this.logger.warn(`Context "${name}" mount failed: ${e}, rolling back ${mountedContexts.length} mounted contexts`);
|
|
325
264
|
for (let i = mountedContexts.length - 1; i >= 0; i--) {
|
|
326
265
|
const { name: mName, context: mCtx } = mountedContexts[i];
|
|
327
266
|
try {
|
|
328
|
-
if (mCtx.extensions)
|
|
267
|
+
if (mCtx.extensions)
|
|
329
268
|
unregisterExtensions(Object.keys(mCtx.extensions));
|
|
330
|
-
|
|
331
|
-
if (typeof mCtx.dispose === 'function') {
|
|
269
|
+
if (typeof mCtx.dispose === 'function')
|
|
332
270
|
await mCtx.dispose(mCtx.value);
|
|
333
|
-
}
|
|
334
271
|
}
|
|
335
272
|
catch (disposeErr) {
|
|
336
273
|
this.logger.warn(`Rollback dispose for "${mName}" failed: ${disposeErr}`);
|
|
@@ -339,22 +276,9 @@ export class Plugin extends PluginBase {
|
|
|
339
276
|
throw e;
|
|
340
277
|
}
|
|
341
278
|
}
|
|
342
|
-
// 所有 Context 成功挂载后,才标记为已启动
|
|
343
|
-
this.started = true;
|
|
344
279
|
for (const { name } of mountedContexts) {
|
|
345
280
|
this.dispatch('context.mounted', name);
|
|
346
281
|
}
|
|
347
|
-
await this.broadcast("mounted");
|
|
348
|
-
// 先启动子插件,再打印当前插件启动日志
|
|
349
|
-
for (const child of this.children) {
|
|
350
|
-
await child.start(t);
|
|
351
|
-
}
|
|
352
|
-
if (t) {
|
|
353
|
-
this.logger.debug(formatCompact({
|
|
354
|
-
name: this.name,
|
|
355
|
-
reload_ms: Date.now() - t,
|
|
356
|
-
}));
|
|
357
|
-
}
|
|
358
282
|
}
|
|
359
283
|
/**
|
|
360
284
|
* 获取插件提供的功能
|
|
@@ -363,11 +287,11 @@ export class Plugin extends PluginBase {
|
|
|
363
287
|
get features() {
|
|
364
288
|
const commandService = this.inject('command');
|
|
365
289
|
const componentService = this.inject('component');
|
|
366
|
-
const
|
|
290
|
+
const scheduleService = this.inject('schedule');
|
|
367
291
|
return {
|
|
368
292
|
commands: commandService ? commandService.items.map(c => c.pattern) : [],
|
|
369
293
|
components: componentService ? componentService.getAllNames() : [],
|
|
370
|
-
|
|
294
|
+
schedules: scheduleService ? scheduleService.items.map(s => s.id) : [],
|
|
371
295
|
middlewares: this.#middlewares.map((m, i) => m.name || `middleware_${i}`),
|
|
372
296
|
};
|
|
373
297
|
}
|
|
@@ -382,8 +306,8 @@ export class Plugin extends PluginBase {
|
|
|
382
306
|
result.push({ name: 'command', count: f.commands.length });
|
|
383
307
|
if (f.components.length > 0)
|
|
384
308
|
result.push({ name: 'component', count: f.components.length });
|
|
385
|
-
if (f.
|
|
386
|
-
result.push({ name: '
|
|
309
|
+
if (f.schedules.length > 0)
|
|
310
|
+
result.push({ name: 'schedule', count: f.schedules.length });
|
|
387
311
|
// #middlewares includes the default command middleware, only count user-added ones
|
|
388
312
|
const userMiddlewareCount = this.#middlewares.length - 1; // subtract default #messageMiddleware
|
|
389
313
|
if (userMiddlewareCount > 0)
|
|
@@ -401,63 +325,16 @@ export class Plugin extends PluginBase {
|
|
|
401
325
|
}
|
|
402
326
|
/**
|
|
403
327
|
* 停止插件
|
|
328
|
+
* 委托 PluginBase.stop() 处理通用清理,仅补充 IM 特化逻辑
|
|
404
329
|
*/
|
|
405
330
|
async stop() {
|
|
406
331
|
if (!this.started)
|
|
407
332
|
return;
|
|
408
333
|
this.logger.debug(`Stopping plugin "${this.name}"`);
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
await child.stop();
|
|
413
|
-
}
|
|
414
|
-
this.children = [];
|
|
415
|
-
// 停止服务
|
|
416
|
-
for (const [name, context] of this.$contexts) {
|
|
417
|
-
remove(Plugin[contextsKey], name);
|
|
418
|
-
// 从共享 registry 注销扩展方法(引用计数,不影响其他提供者)
|
|
419
|
-
if (context.extensions) {
|
|
420
|
-
unregisterExtensions(Object.keys(context.extensions));
|
|
421
|
-
}
|
|
422
|
-
if (typeof context.dispose === "function") {
|
|
423
|
-
await context.dispose(context.value);
|
|
424
|
-
}
|
|
425
|
-
}
|
|
426
|
-
// 清理 contexts Map
|
|
427
|
-
this.$contexts.clear();
|
|
428
|
-
// 清空缓存的名称
|
|
429
|
-
this.#cachedName = undefined;
|
|
430
|
-
// 触发 dispose 事件
|
|
431
|
-
this.emit("dispose");
|
|
432
|
-
// 执行所有清理函数
|
|
433
|
-
for (const dispose of this.#disposables) {
|
|
434
|
-
try {
|
|
435
|
-
await dispose();
|
|
436
|
-
}
|
|
437
|
-
catch (e) {
|
|
438
|
-
this.logger.warn(`Dispose callback failed: ${e}`);
|
|
439
|
-
}
|
|
440
|
-
}
|
|
441
|
-
this.#disposables.clear();
|
|
442
|
-
// 清空 middlewares 数组(保留默认的消息中间件)
|
|
334
|
+
// 通用清理(子插件、contexts、disposables、loadedModules 等)
|
|
335
|
+
await super.stop();
|
|
336
|
+
// IM 特化:重置中间件(保留默认消息中间件)
|
|
443
337
|
this.#middlewares.length = 1;
|
|
444
|
-
// 清理 feature 贡献记录
|
|
445
|
-
this.#featureContributions.clear();
|
|
446
|
-
if (this.parent) {
|
|
447
|
-
remove(this.parent?.children, this);
|
|
448
|
-
}
|
|
449
|
-
// 从全局 loadedModules Map 中移除,防止内存泄漏
|
|
450
|
-
if (this.filePath) {
|
|
451
|
-
try {
|
|
452
|
-
const realPath = fs.realpathSync(this.filePath);
|
|
453
|
-
loadedModules.delete(realPath);
|
|
454
|
-
}
|
|
455
|
-
catch {
|
|
456
|
-
// 文件可能已不存在,忽略错误
|
|
457
|
-
}
|
|
458
|
-
}
|
|
459
|
-
this.removeAllListeners();
|
|
460
|
-
this.logger.debug(`Plugin "${this.name}" stopped`);
|
|
461
338
|
}
|
|
462
339
|
// ============================================================================
|
|
463
340
|
// 生命周期钩子
|
|
@@ -465,12 +342,7 @@ export class Plugin extends PluginBase {
|
|
|
465
342
|
onMounted(callback) {
|
|
466
343
|
this.on("mounted", callback);
|
|
467
344
|
}
|
|
468
|
-
onDispose
|
|
469
|
-
this.#disposables.add(callback);
|
|
470
|
-
return () => {
|
|
471
|
-
this.#disposables.delete(callback);
|
|
472
|
-
};
|
|
473
|
-
}
|
|
345
|
+
// onDispose 继承自 PluginBase
|
|
474
346
|
// ============================================================================
|
|
475
347
|
// 事件广播
|
|
476
348
|
// ============================================================================
|
|
@@ -584,30 +456,42 @@ export class Plugin extends PluginBase {
|
|
|
584
456
|
*/
|
|
585
457
|
async reload(plugin = this) {
|
|
586
458
|
const p = plugin;
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
return
|
|
592
|
-
|
|
593
|
-
const entry = p.filePath;
|
|
594
|
-
const parent = p.parent;
|
|
595
|
-
await p.stop();
|
|
596
|
-
let fresh;
|
|
459
|
+
// A burst of file events for one logical save (or an overlapping edit
|
|
460
|
+
// while a reload is still in flight) must not start a second concurrent
|
|
461
|
+
// stop()+import() cycle for the same plugin.
|
|
462
|
+
if (p._reloading)
|
|
463
|
+
return;
|
|
464
|
+
p._reloading = true;
|
|
597
465
|
try {
|
|
598
|
-
|
|
466
|
+
this.logger.info(formatCompact({ name: p.name, reload: true }));
|
|
467
|
+
const now = Date.now();
|
|
468
|
+
if (!p.parent) {
|
|
469
|
+
// 根插件重载 = 退出进程(由 CLI 重启)
|
|
470
|
+
process.exit(51);
|
|
471
|
+
return;
|
|
472
|
+
}
|
|
473
|
+
const entry = p.filePath;
|
|
474
|
+
const parent = p.parent;
|
|
475
|
+
await p.stop();
|
|
476
|
+
let fresh;
|
|
477
|
+
try {
|
|
478
|
+
fresh = await parent.import(entry, now);
|
|
479
|
+
}
|
|
480
|
+
catch (err) {
|
|
481
|
+
this.logger.error(formatCompact({
|
|
482
|
+
name: p.name,
|
|
483
|
+
reload: false,
|
|
484
|
+
error: err instanceof Error ? err.message : String(err),
|
|
485
|
+
hint: 'full_restart',
|
|
486
|
+
}));
|
|
487
|
+
throw err;
|
|
488
|
+
}
|
|
489
|
+
await fresh.broadcast('mounted');
|
|
490
|
+
this.logger.debug(formatCompact({ name: fresh.name, reload_ms: Date.now() - now }));
|
|
599
491
|
}
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
name: p.name,
|
|
603
|
-
reload: false,
|
|
604
|
-
error: err instanceof Error ? err.message : String(err),
|
|
605
|
-
hint: 'full_restart',
|
|
606
|
-
}));
|
|
607
|
-
throw err;
|
|
492
|
+
finally {
|
|
493
|
+
p._reloading = false;
|
|
608
494
|
}
|
|
609
|
-
await fresh.broadcast('mounted');
|
|
610
|
-
this.logger.debug(formatCompact({ name: fresh.name, reload_ms: Date.now() - now }));
|
|
611
495
|
}
|
|
612
496
|
/**
|
|
613
497
|
* 监听文件变化(Plugin 类型窄化版本)
|
|
@@ -615,14 +499,22 @@ export class Plugin extends PluginBase {
|
|
|
615
499
|
watch(callback, recursive = false) {
|
|
616
500
|
if (!this.filePath || this.filePath.includes("node_modules"))
|
|
617
501
|
return;
|
|
618
|
-
const unwatch = watchFile(this.filePath, () => {
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
502
|
+
const unwatch = watchFile(this.filePath, (() => {
|
|
503
|
+
let debounceTimer = null;
|
|
504
|
+
return () => {
|
|
505
|
+
if (debounceTimer)
|
|
506
|
+
clearTimeout(debounceTimer);
|
|
507
|
+
debounceTimer = setTimeout(() => {
|
|
508
|
+
debounceTimer = null;
|
|
509
|
+
const newHash = getFileHash(this.filePath);
|
|
510
|
+
if (newHash === this.fileHash)
|
|
511
|
+
return;
|
|
512
|
+
this.logger.debug(`Plugin "${this.name}" file changed, reloading...`);
|
|
513
|
+
callback(this);
|
|
514
|
+
this.fileHash = newHash;
|
|
515
|
+
}, 300);
|
|
516
|
+
};
|
|
517
|
+
})());
|
|
626
518
|
this.on("dispose", unwatch);
|
|
627
519
|
if (recursive) {
|
|
628
520
|
for (const child of this.children) {
|
|
@@ -676,6 +568,10 @@ export class Plugin extends PluginBase {
|
|
|
676
568
|
plugin.fileHash = getFileHash(entryFile);
|
|
677
569
|
// 先记录,防止循环依赖时重复加载
|
|
678
570
|
loadedModules.set(realPath, plugin);
|
|
571
|
+
// 注意:?t= cache-busting 会导致 Node ESM 模块缓存累积旧条目。
|
|
572
|
+
// 这是 Node.js ESM 的已知限制——没有公开 API 可以逐出 ESM 模块缓存。
|
|
573
|
+
// 在生产环境中插件只加载一次,不会触发此问题;
|
|
574
|
+
// 开发环境中热重载会累积,但仅影响开发进程,重启即释放。
|
|
679
575
|
await storage.run(plugin, async () => {
|
|
680
576
|
await import(`${pathToFileURL(entryFile).href}?t=${Date.now()}`);
|
|
681
577
|
});
|
|
@@ -685,4 +581,3 @@ export class Plugin extends PluginBase {
|
|
|
685
581
|
export function defineContext(options) {
|
|
686
582
|
return options;
|
|
687
583
|
}
|
|
688
|
-
//# sourceMappingURL=plugin.js.map
|
package/lib/request.d.ts
CHANGED
|
@@ -1,85 +1,41 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type {
|
|
1
|
+
import type { MaybePromise } from './types.js';
|
|
2
|
+
import type { Adapters } from './adapter.js';
|
|
3
|
+
import type { RequestKind } from './side-event/types.js';
|
|
4
|
+
import type { SideEventBase } from './side-event/base.js';
|
|
5
|
+
export type { RequestKind, ComposedRequestName } from './side-event/types.js';
|
|
3
6
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* 常见 IM 请求事件分类:
|
|
7
|
-
* - friend_add: 好友添加请求
|
|
8
|
-
* - group_add: 主动申请入群
|
|
9
|
-
* - group_invite: 邀请入群请求
|
|
10
|
-
*
|
|
11
|
-
* 适配器可自行扩展更多子类型
|
|
12
|
-
*/
|
|
13
|
-
export type RequestType = 'friend_add' | 'group_add' | 'group_invite' | (string & {});
|
|
14
|
-
/**
|
|
15
|
-
* 请求频道信息
|
|
16
|
-
*/
|
|
17
|
-
export interface RequestChannel {
|
|
18
|
-
id: string;
|
|
19
|
-
type: 'group' | 'private' | 'channel';
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* 请求基础结构
|
|
23
|
-
*
|
|
24
|
-
* 与 MessageBase / NoticeBase 同构设计。
|
|
25
|
-
* 核心区别:Request 提供 `$approve()` 和 `$reject()` 方法,用于快速处理请求。
|
|
7
|
+
* 请求基础结构 — 继承 SideEventBase,附加审批方法。
|
|
26
8
|
*
|
|
27
9
|
* @example
|
|
28
10
|
* ```typescript
|
|
29
|
-
* // 适配器中格式化请求
|
|
30
11
|
* const request = Request.from(rawEvent, {
|
|
31
12
|
* $id: rawEvent.flag,
|
|
32
13
|
* $adapter: 'icqq',
|
|
33
|
-
* $
|
|
34
|
-
* $type: '
|
|
35
|
-
* $
|
|
36
|
-
* $
|
|
14
|
+
* $endpoint: endpointKey,
|
|
15
|
+
* $type: 'request',
|
|
16
|
+
* $scene_id: groupId,
|
|
17
|
+
* $scene_type: 'group',
|
|
18
|
+
* $sub_type: 'invite',
|
|
19
|
+
* $actor: { id: userId, name: '邀请者' },
|
|
37
20
|
* $comment: '请求加群消息',
|
|
38
21
|
* $timestamp: Date.now(),
|
|
39
22
|
* $approve: async (remark?) => { await api.approve(flag, remark); },
|
|
40
23
|
* $reject: async (reason?) => { await api.reject(flag, reason); },
|
|
41
24
|
* });
|
|
25
|
+
* // formatSideEventName(request) === 'request.group.invite'
|
|
42
26
|
* this.adapter.emit('request.receive', request);
|
|
43
27
|
* ```
|
|
44
28
|
*/
|
|
45
|
-
export interface RequestBase {
|
|
46
|
-
/** 请求唯一 ID / flag(平台提供的请求标识,用于后续处理) */
|
|
47
|
-
$id: string;
|
|
48
|
-
/** 适配器名称 */
|
|
29
|
+
export interface RequestBase extends SideEventBase {
|
|
49
30
|
$adapter: keyof Adapters;
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
$type: RequestType;
|
|
54
|
-
/** 请求子类型 */
|
|
55
|
-
$subType?: string;
|
|
56
|
-
/** 请求发生的频道/群/会话 */
|
|
57
|
-
$channel: RequestChannel;
|
|
58
|
-
/** 请求发送者 */
|
|
59
|
-
$sender: MessageSender;
|
|
60
|
-
/** 请求附言/验证消息 */
|
|
31
|
+
$type: RequestKind;
|
|
32
|
+
/** 主参与者(必填) */
|
|
33
|
+
$actor: NonNullable<SideEventBase['$actor']>;
|
|
61
34
|
$comment?: string;
|
|
62
|
-
/** 请求时间戳 */
|
|
63
|
-
$timestamp: number;
|
|
64
|
-
/**
|
|
65
|
-
* 同意请求
|
|
66
|
-
* @param remark 备注信息(如好友备注)
|
|
67
|
-
*/
|
|
68
35
|
$approve(remark?: string): MaybePromise<void>;
|
|
69
|
-
/**
|
|
70
|
-
* 拒绝请求
|
|
71
|
-
* @param reason 拒绝原因
|
|
72
|
-
*/
|
|
73
36
|
$reject(reason?: string): MaybePromise<void>;
|
|
74
37
|
}
|
|
75
|
-
/**
|
|
76
|
-
* 完整请求类型,支持平台原始数据扩展
|
|
77
|
-
*/
|
|
78
38
|
export type Request<T extends object = {}> = RequestBase & T;
|
|
79
39
|
export declare namespace Request {
|
|
80
|
-
/**
|
|
81
|
-
* 工具方法:合并自定义字段与基础请求结构
|
|
82
|
-
*/
|
|
83
40
|
function from<T extends object>(input: T, format: RequestBase): Request<T>;
|
|
84
41
|
}
|
|
85
|
-
//# sourceMappingURL=request.d.ts.map
|
package/lib/request.js
CHANGED
|
@@ -5,10 +5,10 @@ import { Schema } from '@zhin.js/schema';
|
|
|
5
5
|
/**
|
|
6
6
|
* Prompt类:用于实现机器人与用户的交互式提问与输入收集。
|
|
7
7
|
* 支持文本、数字、确认、列表、选项、Schema等多种输入类型,自动处理超时、默认值、格式化等。
|
|
8
|
-
* 典型用法:await new
|
|
8
|
+
* 典型用法:await new SchemaInteraction(plugin, event).text('请输入内容')
|
|
9
9
|
* @template P 适配器类型
|
|
10
10
|
*/
|
|
11
|
-
export declare class
|
|
11
|
+
export declare class SchemaInteraction<P extends RegisteredAdapter> {
|
|
12
12
|
private plugin;
|
|
13
13
|
private event;
|
|
14
14
|
/**
|
|
@@ -25,7 +25,7 @@ export declare class Prompt<P extends RegisteredAdapter> {
|
|
|
25
25
|
* 通用提问方法,支持自定义格式化、超时、默认值等
|
|
26
26
|
* @param config 提问配置
|
|
27
27
|
*/
|
|
28
|
-
private
|
|
28
|
+
private collect;
|
|
29
29
|
/**
|
|
30
30
|
* 注册一次性消息中间件,等待用户输入或超时
|
|
31
31
|
* @param callback 输入回调
|
|
@@ -52,7 +52,7 @@ export declare class Prompt<P extends RegisteredAdapter> {
|
|
|
52
52
|
/**
|
|
53
53
|
* 列表输入,支持多值分隔
|
|
54
54
|
*/
|
|
55
|
-
list<T extends
|
|
55
|
+
list<T extends SchemaInteraction.SingleType = 'text'>(tips: string, config?: SchemaInteraction.ListConfig<T>, timeoutText?: string): Promise<SchemaInteraction.Result<T>[]>;
|
|
56
56
|
/**
|
|
57
57
|
* 返回常量值(用于Schema)
|
|
58
58
|
*/
|
|
@@ -60,7 +60,7 @@ export declare class Prompt<P extends RegisteredAdapter> {
|
|
|
60
60
|
/**
|
|
61
61
|
* 选项选择,支持单选/多选
|
|
62
62
|
*/
|
|
63
|
-
pick<T extends
|
|
63
|
+
pick<T extends SchemaInteraction.SingleType, M extends boolean = false>(tips: string, config: SchemaInteraction.PickConfig<T, M>, timeoutText?: string): Promise<SchemaInteraction.PickResult<T, M>>;
|
|
64
64
|
/**
|
|
65
65
|
* 基于Schema的选项选择
|
|
66
66
|
*/
|
|
@@ -79,7 +79,7 @@ export declare class Prompt<P extends RegisteredAdapter> {
|
|
|
79
79
|
/**
|
|
80
80
|
* Prompt命名空间:类型辅助定义
|
|
81
81
|
*/
|
|
82
|
-
export declare namespace
|
|
82
|
+
export declare namespace SchemaInteraction {
|
|
83
83
|
interface SingleMap {
|
|
84
84
|
text: string;
|
|
85
85
|
number: number;
|
|
@@ -115,4 +115,3 @@ export declare namespace Prompt {
|
|
|
115
115
|
};
|
|
116
116
|
export {};
|
|
117
117
|
}
|
|
118
|
-
//# sourceMappingURL=prompt.d.ts.map
|