@zhin.js/core 1.3.2 → 1.3.3
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 +7 -7
- package/lib/adapter.d.ts +22 -2
- package/lib/adapter.js +71 -1
- package/lib/agent-prompt.d.ts +0 -1
- package/lib/agent-prompt.js +0 -1
- package/lib/built/adapter-process.d.ts +0 -1
- package/lib/built/adapter-process.js +0 -1
- package/lib/built/agent-preset.d.ts +0 -1
- package/lib/built/agent-preset.js +0 -1
- 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 +94 -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 +7 -0
- package/lib/built/ai-outbound/types.d.ts +60 -0
- package/lib/built/ai-outbound/types.js +5 -0
- package/lib/built/ai-trigger.d.ts +5 -1
- package/lib/built/ai-trigger.js +3 -7
- package/lib/built/authorization.d.ts +0 -1
- package/lib/built/authorization.js +0 -1
- package/lib/built/command.d.ts +0 -1
- package/lib/built/command.js +1 -3
- package/lib/built/common-adapter-tools.d.ts +25 -26
- package/lib/built/common-adapter-tools.js +48 -49
- package/lib/built/component.d.ts +0 -1
- package/lib/built/component.js +1 -3
- package/lib/built/config.d.ts +4 -1
- package/lib/built/config.js +26 -5
- package/lib/built/connect-endpoint-instance.d.ts +0 -1
- package/lib/built/connect-endpoint-instance.js +3 -2
- package/lib/built/database.d.ts +0 -1
- package/lib/built/database.js +1 -3
- package/lib/built/dispatcher.d.ts +6 -6
- package/lib/built/dispatcher.js +20 -8
- package/lib/built/endpoint-commands.d.ts +0 -1
- package/lib/built/endpoint-commands.js +6 -9
- package/lib/built/endpoint-lifecycle-service.d.ts +2 -1
- package/lib/built/endpoint-lifecycle-service.js +25 -3
- package/lib/built/endpoint-lifecycle.d.ts +0 -1
- package/lib/built/endpoint-lifecycle.js +0 -1
- package/lib/built/endpoint-manager.d.ts +0 -1
- package/lib/built/endpoint-manager.js +0 -1
- package/lib/built/generated-qrcode.d.ts +0 -1
- package/lib/built/generated-qrcode.js +0 -1
- package/lib/built/generic-segment-mapper.d.ts +6 -0
- package/lib/built/generic-segment-mapper.js +232 -0
- package/lib/built/html-renderer-loader.d.ts +2 -1
- package/lib/built/html-renderer-loader.js +6 -2
- package/lib/built/html-segment-fallback.d.ts +0 -1
- 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 +0 -1
- package/lib/built/inbound-pipeline.d.ts +0 -1
- package/lib/built/inbound-pipeline.js +0 -1
- package/lib/built/inbound-runner.d.ts +0 -1
- package/lib/built/inbound-runner.js +0 -1
- 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 +54 -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/handlers.d.ts +9 -0
- package/lib/built/interactive-segments/handlers.js +58 -0
- package/lib/built/interactive-segments/index.d.ts +7 -0
- package/lib/built/interactive-segments/index.js +7 -0
- package/lib/built/interactive-segments/keyboard-segment.d.ts +12 -0
- package/lib/built/interactive-segments/keyboard-segment.js +13 -0
- package/lib/built/interactive-segments/onebot-keyboard.d.ts +10 -0
- package/lib/built/interactive-segments/onebot-keyboard.js +53 -0
- package/lib/built/interactive-segments/resolve.d.ts +9 -0
- package/lib/built/interactive-segments/resolve.js +84 -0
- package/lib/built/interactive-segments/types.d.ts +62 -0
- package/lib/built/interactive-segments/types.js +13 -0
- package/lib/built/introspection-format.d.ts +0 -1
- package/lib/built/introspection-format.js +1 -1
- package/lib/built/login-assist.d.ts +0 -1
- package/lib/built/login-assist.js +0 -1
- package/lib/built/management-command-guard.d.ts +5 -1
- package/lib/built/management-command-guard.js +5 -1
- package/lib/built/message-enrich.d.ts +0 -1
- package/lib/built/message-enrich.js +0 -1
- package/lib/built/message-filter.d.ts +0 -1
- package/lib/built/message-filter.js +1 -3
- 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 +0 -1
- package/lib/built/outbound-media-contract.js +0 -1
- package/lib/built/outbound-media-utils.d.ts +0 -1
- package/lib/built/outbound-media-utils.js +0 -1
- package/lib/built/permission.d.ts +0 -1
- package/lib/built/permission.js +1 -3
- package/lib/built/permit-check.d.ts +0 -1
- package/lib/built/permit-check.js +0 -1
- package/lib/built/permit-parse.d.ts +0 -1
- package/lib/built/permit-parse.js +0 -1
- package/lib/built/platform-permit.d.ts +5 -6
- package/lib/built/platform-permit.js +11 -12
- package/lib/built/prepend-quote-context.d.ts +0 -1
- package/lib/built/prepend-quote-context.js +0 -1
- package/lib/built/qrcode-segment.d.ts +0 -1
- package/lib/built/qrcode-segment.js +0 -1
- package/lib/built/queue-im-field-contract.d.ts +6 -1
- package/lib/built/queue-im-field-contract.js +10 -1
- package/lib/built/rich-segments/adapter-policies.d.ts +1 -2
- package/lib/built/rich-segments/adapter-policies.js +0 -1
- package/lib/built/rich-segments/base.d.ts +0 -1
- package/lib/built/rich-segments/base.js +0 -1
- package/lib/built/rich-segments/builtins.d.ts +0 -1
- package/lib/built/rich-segments/builtins.js +0 -1
- package/lib/built/rich-segments/capabilities.d.ts +0 -1
- package/lib/built/rich-segments/capabilities.js +0 -1
- package/lib/built/rich-segments/html-segment.d.ts +1 -2
- package/lib/built/rich-segments/html-segment.js +0 -1
- package/lib/built/rich-segments/index.d.ts +0 -1
- package/lib/built/rich-segments/index.js +0 -1
- package/lib/built/rich-segments/markdown-segment.d.ts +1 -2
- package/lib/built/rich-segments/markdown-segment.js +0 -1
- package/lib/built/rich-segments/markdown-to-text.d.ts +0 -1
- package/lib/built/rich-segments/markdown-to-text.js +0 -1
- package/lib/built/rich-segments/qrcode-segment.d.ts +1 -2
- package/lib/built/rich-segments/qrcode-segment.js +0 -1
- package/lib/built/rich-segments/registry.d.ts +0 -1
- package/lib/built/rich-segments/registry.js +0 -1
- package/lib/built/rich-segments/resolve.d.ts +1 -2
- package/lib/built/rich-segments/resolve.js +0 -1
- package/lib/built/rich-segments/tts-segment.d.ts +1 -2
- package/lib/built/rich-segments/tts-segment.js +0 -1
- package/lib/built/rich-segments/types.d.ts +0 -1
- package/lib/built/rich-segments/types.js +0 -1
- package/lib/built/roles.d.ts +0 -1
- package/lib/built/roles.js +0 -1
- package/lib/built/runtime-io.d.ts +0 -1
- package/lib/built/runtime-io.js +0 -1
- package/lib/built/schedule.d.ts +55 -0
- package/lib/built/schedule.js +112 -0
- package/lib/built/schema-endpoint-manager.d.ts +0 -1
- package/lib/built/schema-endpoint-manager.js +0 -1
- 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 +4 -0
- package/lib/built/segment-contract/assert.js +30 -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 +8 -0
- package/lib/built/segment-contract/index.js +7 -0
- package/lib/built/segment-contract/media.d.ts +8 -0
- package/lib/built/segment-contract/media.js +39 -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/types.d.ts +70 -0
- package/lib/built/segment-contract/types.js +5 -0
- package/lib/built/segment-contract/validate.d.ts +138 -0
- package/lib/built/segment-contract/validate.js +124 -0
- package/lib/built/skill.d.ts +0 -1
- package/lib/built/skill.js +0 -1
- package/lib/built/speech-loader.d.ts +2 -1
- package/lib/built/speech-loader.js +6 -2
- package/lib/built/tool.d.ts +0 -1
- package/lib/built/tool.js +1 -3
- package/lib/command.d.ts +12 -7
- package/lib/command.js +38 -16
- package/lib/component.d.ts +0 -1
- package/lib/component.js +0 -1
- package/lib/endpoint-capabilities.d.ts +3 -1
- package/lib/endpoint-capabilities.js +0 -1
- package/lib/endpoint.d.ts +0 -1
- package/lib/endpoint.js +0 -1
- package/lib/errors.d.ts +0 -1
- package/lib/errors.js +0 -1
- package/lib/host-plugin-registry.d.ts +0 -1
- package/lib/host-plugin-registry.js +0 -1
- package/lib/im-scene.d.ts +29 -0
- package/lib/im-scene.js +77 -0
- package/lib/im-session-id.d.ts +25 -12
- package/lib/im-session-id.js +35 -17
- package/lib/index.d.ts +13 -7
- package/lib/index.js +11 -6
- package/lib/jsx-dev-runtime.d.ts +0 -1
- package/lib/jsx-dev-runtime.js +0 -1
- package/lib/jsx-runtime.d.ts +0 -1
- package/lib/jsx-runtime.js +0 -1
- package/lib/jsx.d.ts +0 -1
- package/lib/jsx.js +0 -1
- package/lib/message-quote.d.ts +1 -2
- package/lib/message-quote.js +2 -3
- package/lib/message.d.ts +7 -5
- package/lib/message.js +16 -1
- 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 +0 -1
- package/lib/notice.js +0 -1
- package/lib/plugin-context.d.ts +0 -1
- package/lib/plugin-context.js +0 -1
- package/lib/plugin.d.ts +11 -2
- package/lib/plugin.js +19 -7
- package/lib/prompt.d.ts +0 -1
- package/lib/prompt.js +0 -1
- package/lib/request.d.ts +0 -1
- package/lib/request.js +0 -1
- package/lib/tool-zod.d.ts +0 -1
- package/lib/tool-zod.js +0 -1
- package/lib/types-generator.d.ts +0 -1
- package/lib/types-generator.js +0 -1
- package/lib/types.d.ts +30 -11
- package/lib/types.js +0 -1
- package/lib/utils.d.ts +36 -1
- package/lib/utils.js +33 -25
- package/package.json +15 -8
- package/lib/adapter.d.ts.map +0 -1
- package/lib/adapter.js.map +0 -1
- package/lib/agent-prompt.d.ts.map +0 -1
- package/lib/agent-prompt.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/authorization.d.ts.map +0 -1
- package/lib/built/authorization.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/connect-endpoint-instance.d.ts.map +0 -1
- package/lib/built/connect-endpoint-instance.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/endpoint-commands.d.ts.map +0 -1
- package/lib/built/endpoint-commands.js.map +0 -1
- package/lib/built/endpoint-lifecycle-service.d.ts.map +0 -1
- package/lib/built/endpoint-lifecycle-service.js.map +0 -1
- package/lib/built/endpoint-lifecycle.d.ts.map +0 -1
- package/lib/built/endpoint-lifecycle.js.map +0 -1
- package/lib/built/endpoint-manager.d.ts.map +0 -1
- package/lib/built/endpoint-manager.js.map +0 -1
- package/lib/built/generated-qrcode.d.ts.map +0 -1
- package/lib/built/generated-qrcode.js.map +0 -1
- package/lib/built/html-renderer-loader.d.ts.map +0 -1
- package/lib/built/html-renderer-loader.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-pipeline.d.ts.map +0 -1
- package/lib/built/inbound-pipeline.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/introspection-format.d.ts.map +0 -1
- package/lib/built/introspection-format.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/management-command-guard.d.ts.map +0 -1
- package/lib/built/management-command-guard.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-enrich.d.ts.map +0 -1
- package/lib/built/message-enrich.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/outbound-media-contract.d.ts.map +0 -1
- package/lib/built/outbound-media-contract.js.map +0 -1
- package/lib/built/outbound-media-utils.d.ts.map +0 -1
- package/lib/built/outbound-media-utils.js.map +0 -1
- package/lib/built/permission.d.ts.map +0 -1
- package/lib/built/permission.js.map +0 -1
- package/lib/built/permit-check.d.ts.map +0 -1
- package/lib/built/permit-check.js.map +0 -1
- package/lib/built/permit-parse.d.ts.map +0 -1
- package/lib/built/permit-parse.js.map +0 -1
- package/lib/built/platform-permit.d.ts.map +0 -1
- package/lib/built/platform-permit.js.map +0 -1
- package/lib/built/prepend-quote-context.d.ts.map +0 -1
- package/lib/built/prepend-quote-context.js.map +0 -1
- package/lib/built/qrcode-segment.d.ts.map +0 -1
- package/lib/built/qrcode-segment.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/rich-segments/adapter-policies.d.ts.map +0 -1
- package/lib/built/rich-segments/adapter-policies.js.map +0 -1
- package/lib/built/rich-segments/base.d.ts.map +0 -1
- package/lib/built/rich-segments/base.js.map +0 -1
- package/lib/built/rich-segments/builtins.d.ts.map +0 -1
- package/lib/built/rich-segments/builtins.js.map +0 -1
- package/lib/built/rich-segments/capabilities.d.ts.map +0 -1
- package/lib/built/rich-segments/capabilities.js.map +0 -1
- package/lib/built/rich-segments/html-segment.d.ts.map +0 -1
- package/lib/built/rich-segments/html-segment.js.map +0 -1
- package/lib/built/rich-segments/index.d.ts.map +0 -1
- package/lib/built/rich-segments/index.js.map +0 -1
- package/lib/built/rich-segments/markdown-segment.d.ts.map +0 -1
- package/lib/built/rich-segments/markdown-segment.js.map +0 -1
- package/lib/built/rich-segments/markdown-to-text.d.ts.map +0 -1
- package/lib/built/rich-segments/markdown-to-text.js.map +0 -1
- package/lib/built/rich-segments/qrcode-segment.d.ts.map +0 -1
- package/lib/built/rich-segments/qrcode-segment.js.map +0 -1
- package/lib/built/rich-segments/registry.d.ts.map +0 -1
- package/lib/built/rich-segments/registry.js.map +0 -1
- package/lib/built/rich-segments/resolve.d.ts.map +0 -1
- package/lib/built/rich-segments/resolve.js.map +0 -1
- package/lib/built/rich-segments/tts-segment.d.ts.map +0 -1
- package/lib/built/rich-segments/tts-segment.js.map +0 -1
- package/lib/built/rich-segments/types.d.ts.map +0 -1
- package/lib/built/rich-segments/types.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-endpoint-manager.d.ts.map +0 -1
- package/lib/built/schema-endpoint-manager.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/speech-loader.d.ts.map +0 -1
- package/lib/built/speech-loader.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/endpoint-capabilities.d.ts.map +0 -1
- package/lib/endpoint-capabilities.js.map +0 -1
- package/lib/endpoint.d.ts.map +0 -1
- package/lib/endpoint.js.map +0 -1
- package/lib/errors.d.ts.map +0 -1
- package/lib/errors.js.map +0 -1
- package/lib/host-plugin-registry.d.ts.map +0 -1
- package/lib/host-plugin-registry.js.map +0 -1
- package/lib/im-session-id.d.ts.map +0 -1
- package/lib/im-session-id.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.map +0 -1
- 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-context.d.ts.map +0 -1
- package/lib/plugin-context.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.map +0 -1
- 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/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[];
|
|
@@ -96,4 +100,3 @@ export declare class ConfigFeature extends Feature<ConfigRecord> {
|
|
|
96
100
|
* @deprecated Use ConfigFeature instead
|
|
97
101
|
*/
|
|
98
102
|
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);
|
|
@@ -352,4 +374,3 @@ export class ConfigFeature extends Feature {
|
|
|
352
374
|
* @deprecated Use ConfigFeature instead
|
|
353
375
|
*/
|
|
354
376
|
export const ConfigService = ConfigFeature;
|
|
355
|
-
//# sourceMappingURL=config.js.map
|
|
@@ -15,4 +15,3 @@ export declare function connectEndpointInstance(options: ConnectEndpointInstance
|
|
|
15
15
|
* 按 Endpoint capabilities 断开单个实例。
|
|
16
16
|
*/
|
|
17
17
|
export declare function disconnectEndpointInstance(plugin: Plugin, adapter: Adapter, endpoint: Endpoint): Promise<void>;
|
|
18
|
-
//# sourceMappingURL=connect-endpoint-instance.d.ts.map
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { assertInbound, getAdapterCapabilities, hasInbound, registerEndpointCapabilities, resolveEndpointCapabilities, } from '../endpoint-capabilities.js';
|
|
2
2
|
import { emitEndpointLifecycle } from './endpoint-lifecycle.js';
|
|
3
|
+
import { resolveEndpointConfigEnv } from './config.js';
|
|
3
4
|
/**
|
|
4
5
|
* 按 Endpoint capabilities 连接或注册单个实例(connectEndpoints 与 Adapter.start 共用)。
|
|
5
6
|
*/
|
|
@@ -7,7 +8,8 @@ export async function connectEndpointInstance(options) {
|
|
|
7
8
|
const { plugin, adapter, config } = options;
|
|
8
9
|
const adapterCaps = getAdapterCapabilities(adapter);
|
|
9
10
|
const caps = resolveEndpointCapabilities(adapterCaps, config.capabilities);
|
|
10
|
-
const
|
|
11
|
+
const resolvedConfig = resolveEndpointConfigEnv(config);
|
|
12
|
+
const endpoint = adapter.createEndpoint(resolvedConfig);
|
|
11
13
|
registerEndpointCapabilities(endpoint, caps);
|
|
12
14
|
if (caps.includes('inbound')) {
|
|
13
15
|
assertInbound(endpoint);
|
|
@@ -38,4 +40,3 @@ export async function disconnectEndpointInstance(plugin, adapter, endpoint) {
|
|
|
38
40
|
await endpoint.$disconnect();
|
|
39
41
|
await emitEndpointLifecycle(plugin, adapter, endpoint, 'disconnect');
|
|
40
42
|
}
|
|
41
|
-
//# sourceMappingURL=connect-endpoint-instance.js.map
|
package/lib/built/database.d.ts
CHANGED
package/lib/built/database.js
CHANGED
|
@@ -5,7 +5,6 @@
|
|
|
5
5
|
import { Registry } from "@zhin.js/database";
|
|
6
6
|
import { formatCompact } from '@zhin.js/logger';
|
|
7
7
|
import { Feature } from "@zhin.js/kernel";
|
|
8
|
-
import { getPlugin } from "../plugin.js";
|
|
9
8
|
import { SystemLogDefinition } from "../models/system-log.js";
|
|
10
9
|
import { UserDefinition } from "../models/user.js";
|
|
11
10
|
const databaseAfterStartHooks = [];
|
|
@@ -96,7 +95,7 @@ export class DatabaseFeature extends Feature {
|
|
|
96
95
|
const feature = this;
|
|
97
96
|
return {
|
|
98
97
|
defineModel(name, definition) {
|
|
99
|
-
const plugin =
|
|
98
|
+
const plugin = this;
|
|
100
99
|
const record = { name: name, definition };
|
|
101
100
|
const dispose = feature.add(record, plugin.name);
|
|
102
101
|
plugin.recordFeatureContribution(feature.name, name);
|
|
@@ -105,4 +104,3 @@ export class DatabaseFeature extends Feature {
|
|
|
105
104
|
};
|
|
106
105
|
}
|
|
107
106
|
}
|
|
108
|
-
//# sourceMappingURL=database.js.map
|
|
@@ -27,12 +27,9 @@
|
|
|
27
27
|
* 默认路由为 exclusive(命令与 AI 互斥);需双轨时请显式 dualRoute.mode: 'dual'。
|
|
28
28
|
*/
|
|
29
29
|
import { Message } from '../message.js';
|
|
30
|
-
import type { MessageMiddleware, RegisteredAdapter, MaybePromise, SendContent, OutboundReplySource, OutboundPolishMiddleware } from '../types.js';
|
|
30
|
+
import type { MessageMiddleware, RegisteredAdapter, MaybePromise, SendContent, OutboundReplySource, OutboundPolishMiddleware, OutboundReplyStore } from '../types.js';
|
|
31
31
|
import type { Context } from '../plugin.js';
|
|
32
|
-
export declare function getOutboundReplyStore():
|
|
33
|
-
message: Message<any>;
|
|
34
|
-
source: OutboundReplySource;
|
|
35
|
-
} | undefined;
|
|
32
|
+
export declare function getOutboundReplyStore(): OutboundReplyStore | undefined;
|
|
36
33
|
/**
|
|
37
34
|
* 路由判定结果(互斥模式 legacy)
|
|
38
35
|
*/
|
|
@@ -110,6 +107,10 @@ export interface MessageDispatcherService {
|
|
|
110
107
|
* 在 `before.sendMessage` 管道内调用 `message.$reply`(与 Adapter#sendMessage 同一出站链)
|
|
111
108
|
*/
|
|
112
109
|
replyWithPolish(message: Message<any>, source: ReplySource, content: SendContent, options?: ReplyWithPolishOptions): Promise<unknown>;
|
|
110
|
+
/** Proactive 出站:在 ALS 内执行 send,触发 outbound polish / before.sendMessage */
|
|
111
|
+
runWithOutboundPolish<T>(store: Pick<OutboundReplyStore, 'message' | 'trigger' | 'proactiveSource'> & {
|
|
112
|
+
source?: OutboundReplySource;
|
|
113
|
+
}, fn: () => Promise<T>): Promise<T>;
|
|
113
114
|
/**
|
|
114
115
|
* 是否匹配为指令路径(与 dispatch 内判定一致)
|
|
115
116
|
*/
|
|
@@ -136,4 +137,3 @@ declare module '../plugin.js' {
|
|
|
136
137
|
}
|
|
137
138
|
}
|
|
138
139
|
export declare function createMessageDispatcher(options?: CreateMessageDispatcherOptions): Context<'dispatcher', DispatcherContextExtensions>;
|
|
139
|
-
//# sourceMappingURL=dispatcher.d.ts.map
|
package/lib/built/dispatcher.js
CHANGED
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
* 默认路由为 exclusive(命令与 AI 互斥);需双轨时请显式 dualRoute.mode: 'dual'。
|
|
28
28
|
*/
|
|
29
29
|
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
30
|
-
import {
|
|
30
|
+
import { isActionMessage } from './interactive-segments/action.js';
|
|
31
31
|
/** Dispatcher 管理的「会话回复」异步上下文,供 `before.sendMessage` 内读取(与 Adapter.renderSendMessage 同链) */
|
|
32
32
|
const outboundReplyAls = new AsyncLocalStorage();
|
|
33
33
|
export function getOutboundReplyStore() {
|
|
@@ -206,10 +206,22 @@ export function createMessageDispatcher(options) {
|
|
|
206
206
|
if (!rootPlugin) {
|
|
207
207
|
return quote ? message.$reply(content, quote) : message.$reply(content);
|
|
208
208
|
}
|
|
209
|
-
return outboundReplyAls.run({
|
|
209
|
+
return outboundReplyAls.run({
|
|
210
|
+
message,
|
|
211
|
+
source,
|
|
212
|
+
trigger: 'inbound',
|
|
213
|
+
}, () => quote ? message.$reply(content, quote) : message.$reply(content));
|
|
214
|
+
}
|
|
215
|
+
async function runWithOutboundPolish(store, fn) {
|
|
216
|
+
return outboundReplyAls.run({
|
|
217
|
+
message: store.message,
|
|
218
|
+
source: store.source ?? 'proactive',
|
|
219
|
+
trigger: store.trigger,
|
|
220
|
+
proactiveSource: store.proactiveSource,
|
|
221
|
+
}, fn);
|
|
210
222
|
}
|
|
211
223
|
async function maybeRecordGroupPassiveContext(message) {
|
|
212
|
-
if (!groupPassiveContextHandler)
|
|
224
|
+
if (!groupPassiveContextHandler || isActionMessage(message))
|
|
213
225
|
return;
|
|
214
226
|
const scope = message.$channel?.type;
|
|
215
227
|
if (scope !== 'group' && scope !== 'channel')
|
|
@@ -336,6 +348,9 @@ export function createMessageDispatcher(options) {
|
|
|
336
348
|
replyWithPolish(message, source, content, options) {
|
|
337
349
|
return replyWithPolishInternal(message, source, content, options);
|
|
338
350
|
},
|
|
351
|
+
runWithOutboundPolish(store, fn) {
|
|
352
|
+
return runWithOutboundPolish(store, fn);
|
|
353
|
+
},
|
|
339
354
|
matchCommand(message) {
|
|
340
355
|
return matchCommandInternal(message);
|
|
341
356
|
},
|
|
@@ -354,18 +369,15 @@ export function createMessageDispatcher(options) {
|
|
|
354
369
|
},
|
|
355
370
|
extensions: {
|
|
356
371
|
addGuardrail(guardrail) {
|
|
357
|
-
const plugin = getPlugin();
|
|
358
372
|
const dispose = service.addGuardrail(guardrail);
|
|
359
|
-
|
|
373
|
+
rootPlugin?.onDispose(dispose);
|
|
360
374
|
return dispose;
|
|
361
375
|
},
|
|
362
376
|
addOutboundPolish(handler) {
|
|
363
|
-
const plugin = getPlugin();
|
|
364
377
|
const dispose = service.addOutboundPolish(handler);
|
|
365
|
-
|
|
378
|
+
rootPlugin?.onDispose(dispose);
|
|
366
379
|
return dispose;
|
|
367
380
|
},
|
|
368
381
|
},
|
|
369
382
|
};
|
|
370
383
|
}
|
|
371
|
-
//# sourceMappingURL=dispatcher.js.map
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { Adapter } from '../adapter.js';
|
|
5
5
|
import { MessageCommand } from '../command.js';
|
|
6
|
-
import {
|
|
6
|
+
import { MANAGEMENT_OPERATOR_PERMIT } from './management-command-guard.js';
|
|
7
7
|
import { createEndpointLifecycleService } from './endpoint-lifecycle-service.js';
|
|
8
8
|
import { endpointHelpText, formatEndpointsList } from './introspection-format.js';
|
|
9
9
|
function collectRuntimeEndpoints(root) {
|
|
@@ -26,17 +26,11 @@ export function registerEndpointManagementCommands(plugin, commandService) {
|
|
|
26
26
|
const root = plugin.root;
|
|
27
27
|
const disposers = [];
|
|
28
28
|
const service = () => createEndpointLifecycleService(root);
|
|
29
|
-
const guard = (message) => {
|
|
30
|
-
const ai = root.inject('ai');
|
|
31
|
-
return rejectUnlessManagementOperator(message, root, ai?.getTriggerConfig?.());
|
|
32
|
-
};
|
|
33
29
|
const register = (pattern, desc, handler) => {
|
|
34
30
|
const cmd = new MessageCommand(pattern)
|
|
35
31
|
.desc(desc)
|
|
32
|
+
.permit(MANAGEMENT_OPERATOR_PERMIT)
|
|
36
33
|
.action(async (message, match) => {
|
|
37
|
-
const denied = guard(message);
|
|
38
|
-
if (denied)
|
|
39
|
-
return denied;
|
|
40
34
|
try {
|
|
41
35
|
return await handler(message, match);
|
|
42
36
|
}
|
|
@@ -93,10 +87,13 @@ export function registerEndpointManagementCommands(plugin, commandService) {
|
|
|
93
87
|
}
|
|
94
88
|
return '已取消 Endpoint 绑定流程。';
|
|
95
89
|
});
|
|
90
|
+
register('/endpoint sync', '将内存中的 endpoint 配置写回 zhin.config', async () => {
|
|
91
|
+
const result = await service().syncToDisk();
|
|
92
|
+
return result.message;
|
|
93
|
+
});
|
|
96
94
|
register('/endpoints', '列出各适配器下的 Endpoint 及在线状态', () => formatEndpointsList(collectRuntimeEndpoints(root)));
|
|
97
95
|
return () => {
|
|
98
96
|
for (const d of disposers)
|
|
99
97
|
d();
|
|
100
98
|
};
|
|
101
99
|
}
|
|
102
|
-
//# sourceMappingURL=endpoint-commands.js.map
|
|
@@ -14,6 +14,8 @@ export declare class EndpointLifecycleService {
|
|
|
14
14
|
resolveManager(adapterKey: string): EndpointManager;
|
|
15
15
|
listProvisionableAdapters(): string[];
|
|
16
16
|
persistEndpoints(endpoints: EndpointConfigRecord[]): Promise<void>;
|
|
17
|
+
/** 将内存中的 endpoints 写回 zhin.config(修复运行时与磁盘不一致) */
|
|
18
|
+
syncToDisk(): Promise<EndpointLifecycleResult>;
|
|
17
19
|
connectConfig(adapter: Adapter, config: EndpointConfigRecord): Promise<Endpoint>;
|
|
18
20
|
disconnectRuntime(adapter: Adapter, name: string): Promise<boolean>;
|
|
19
21
|
add(adapterKey: string, message: Message, initialReply?: string): Promise<EndpointLifecycleResult>;
|
|
@@ -24,4 +26,3 @@ export declare class EndpointLifecycleService {
|
|
|
24
26
|
cancelProvision(): boolean;
|
|
25
27
|
}
|
|
26
28
|
export declare function createEndpointLifecycleService(root: Plugin): EndpointLifecycleService;
|
|
27
|
-
//# sourceMappingURL=endpoint-lifecycle-service.d.ts.map
|
|
@@ -74,7 +74,18 @@ export class EndpointLifecycleService {
|
|
|
74
74
|
const configService = getConfigService(this.root);
|
|
75
75
|
const loader = configService.configs.get(configService.primaryFile);
|
|
76
76
|
loader.patchKey('endpoints', endpoints);
|
|
77
|
-
|
|
77
|
+
}
|
|
78
|
+
/** 将内存中的 endpoints 写回 zhin.config(修复运行时与磁盘不一致) */
|
|
79
|
+
async syncToDisk() {
|
|
80
|
+
const configService = getConfigService(this.root);
|
|
81
|
+
const loader = configService.configs.get(configService.primaryFile);
|
|
82
|
+
const endpoints = readAllEndpoints(this.root);
|
|
83
|
+
await this.persistEndpoints(endpoints);
|
|
84
|
+
const configPath = loader.resolvedPath;
|
|
85
|
+
const names = endpoints.map((e) => `${e.context}/${e.name}`).join(', ') || '(无)';
|
|
86
|
+
return {
|
|
87
|
+
message: `✅ 已将 ${endpoints.length} 个 endpoint 写入 \`${configPath}\`:${names}`,
|
|
88
|
+
};
|
|
78
89
|
}
|
|
79
90
|
async connectConfig(adapter, config) {
|
|
80
91
|
const name = config.name;
|
|
@@ -110,7 +121,19 @@ export class EndpointLifecycleService {
|
|
|
110
121
|
throw new Error('Endpoint 名称不能为空');
|
|
111
122
|
}
|
|
112
123
|
const endpoints = readAllEndpoints(this.root);
|
|
113
|
-
|
|
124
|
+
try {
|
|
125
|
+
assertUniqueName(endpoints, config.context, config.name);
|
|
126
|
+
}
|
|
127
|
+
catch (err) {
|
|
128
|
+
if (err instanceof Error && err.message.includes('已存在')) {
|
|
129
|
+
const online = adapter.endpoints.has(config.name);
|
|
130
|
+
const hint = online
|
|
131
|
+
? '该 Endpoint 已在运行时注册,无需重复扫码;可发 /endpoints 确认。若 zhin.config.yml 未更新,请 /endpoint sync。'
|
|
132
|
+
: '可用 /endpoint start 重试连接,或 /endpoint remove 后重新添加。';
|
|
133
|
+
throw new Error(`${err.message}。${hint}`);
|
|
134
|
+
}
|
|
135
|
+
throw err;
|
|
136
|
+
}
|
|
114
137
|
endpoints.push(config);
|
|
115
138
|
await this.persistEndpoints(endpoints);
|
|
116
139
|
try {
|
|
@@ -216,4 +239,3 @@ export class EndpointLifecycleService {
|
|
|
216
239
|
export function createEndpointLifecycleService(root) {
|
|
217
240
|
return new EndpointLifecycleService(root);
|
|
218
241
|
}
|
|
219
|
-
//# sourceMappingURL=endpoint-lifecycle-service.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { MessageElement, SendContent } from '../types.js';
|
|
2
|
+
import type { Segment } from './segment-contract/types.js';
|
|
3
|
+
/** 通用 IM adapter:legacy wire → canonical Segment[] */
|
|
4
|
+
export declare function toCanonicalSegments(content: readonly MessageElement[] | readonly unknown[]): Segment[];
|
|
5
|
+
/** canonical → wire(mention→at;image MediaRef→legacy 字段) */
|
|
6
|
+
export declare function fromCanonicalSegments(content: SendContent): MessageElement[];
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
import { createImageSegment, isMediaRef, mediaRefFromLegacyData, mediaRefToLegacyFields, readMentionTarget, } from './segment-contract/index.js';
|
|
2
|
+
function isRecord(value) {
|
|
3
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
4
|
+
}
|
|
5
|
+
function readPlatform(seg) {
|
|
6
|
+
const platform = seg.platform;
|
|
7
|
+
return platform && typeof platform === 'object' ? platform : undefined;
|
|
8
|
+
}
|
|
9
|
+
function normalizeMention(seg) {
|
|
10
|
+
const data = seg.data;
|
|
11
|
+
const target = readMentionTarget(data);
|
|
12
|
+
const name = typeof data.name === 'string' && data.name ? data.name : undefined;
|
|
13
|
+
const platform = readPlatform(seg);
|
|
14
|
+
return {
|
|
15
|
+
type: 'mention',
|
|
16
|
+
data: name ? { target, name } : { target },
|
|
17
|
+
...(platform ? { platform } : {}),
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
function normalizeImage(seg) {
|
|
21
|
+
const data = seg.data;
|
|
22
|
+
const platform = readPlatform(seg);
|
|
23
|
+
if (isMediaRef(data.media)) {
|
|
24
|
+
return {
|
|
25
|
+
type: 'image',
|
|
26
|
+
data: {
|
|
27
|
+
media: data.media,
|
|
28
|
+
...(typeof data.alt === 'string' ? { alt: data.alt } : {}),
|
|
29
|
+
},
|
|
30
|
+
...(platform ? { platform } : {}),
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
const media = mediaRefFromLegacyData(data);
|
|
34
|
+
if (media) {
|
|
35
|
+
const mergedPlatform = { ...(platform ?? {}) };
|
|
36
|
+
for (const key of ['url', 'file', 'src', 'file_id']) {
|
|
37
|
+
if (typeof data[key] === 'string' && data[key])
|
|
38
|
+
mergedPlatform[key] = data[key];
|
|
39
|
+
}
|
|
40
|
+
const platformKeys = Object.keys(mergedPlatform);
|
|
41
|
+
const legacyPlatform = platformKeys.length === 0
|
|
42
|
+
? undefined
|
|
43
|
+
: platformKeys.length === 1 && mergedPlatform[platformKeys[0]] === media.value
|
|
44
|
+
? undefined
|
|
45
|
+
: mergedPlatform;
|
|
46
|
+
return createImageSegment(media, {
|
|
47
|
+
alt: typeof data.alt === 'string' ? data.alt : undefined,
|
|
48
|
+
platform: legacyPlatform,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
return seg;
|
|
52
|
+
}
|
|
53
|
+
function normalizeReply(seg) {
|
|
54
|
+
const data = seg.data;
|
|
55
|
+
const messageId = String(data.message_id ?? data.id ?? '').trim();
|
|
56
|
+
if (!messageId)
|
|
57
|
+
return seg;
|
|
58
|
+
return { type: 'reply', data: { message_id: messageId } };
|
|
59
|
+
}
|
|
60
|
+
function normalizeLink(seg) {
|
|
61
|
+
const data = seg.data;
|
|
62
|
+
const url = String(data.url ?? data.href ?? '').trim();
|
|
63
|
+
if (!url)
|
|
64
|
+
return seg;
|
|
65
|
+
const text = typeof data.text === 'string' && data.text ? data.text : undefined;
|
|
66
|
+
const platform = readPlatform(seg);
|
|
67
|
+
return {
|
|
68
|
+
type: 'link',
|
|
69
|
+
data: text ? { url, text } : { url },
|
|
70
|
+
...(platform ? { platform } : {}),
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
function normalizeForward(seg) {
|
|
74
|
+
const data = seg.data;
|
|
75
|
+
const forwardId = String(data.forward_id ?? data.id ?? data.resid ?? '').trim();
|
|
76
|
+
if (!forwardId)
|
|
77
|
+
return seg;
|
|
78
|
+
const title = typeof data.title === 'string' ? data.title : undefined;
|
|
79
|
+
const messages = Array.isArray(data.messages) ? data.messages : undefined;
|
|
80
|
+
const platform = { ...(readPlatform(seg) ?? {}) };
|
|
81
|
+
if (data.resid != null)
|
|
82
|
+
platform.resid = String(data.resid);
|
|
83
|
+
return {
|
|
84
|
+
type: 'forward',
|
|
85
|
+
data: {
|
|
86
|
+
forward_id: forwardId,
|
|
87
|
+
...(title ? { title } : {}),
|
|
88
|
+
...(messages ? { messages: messages } : {}),
|
|
89
|
+
},
|
|
90
|
+
...(Object.keys(platform).length ? { platform } : {}),
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
function isPlatformSticker(seg) {
|
|
94
|
+
if (seg.type !== 'sticker')
|
|
95
|
+
return false;
|
|
96
|
+
const data = seg.data;
|
|
97
|
+
return data.package_id != null
|
|
98
|
+
|| data.sticker_id != null
|
|
99
|
+
|| data.packageId != null
|
|
100
|
+
|| data.stickerId != null;
|
|
101
|
+
}
|
|
102
|
+
function normalizeFace(seg) {
|
|
103
|
+
if (isPlatformSticker(seg))
|
|
104
|
+
return seg;
|
|
105
|
+
const data = seg.data;
|
|
106
|
+
const rawId = data.id ?? data.face_id;
|
|
107
|
+
const name = typeof data.name === 'string'
|
|
108
|
+
? data.name
|
|
109
|
+
: typeof data.text === 'string'
|
|
110
|
+
? data.text
|
|
111
|
+
: undefined;
|
|
112
|
+
const platform = readPlatform(seg);
|
|
113
|
+
return {
|
|
114
|
+
type: 'face',
|
|
115
|
+
data: {
|
|
116
|
+
...(rawId != null ? { id: rawId } : {}),
|
|
117
|
+
...(name ? { name } : {}),
|
|
118
|
+
},
|
|
119
|
+
...(platform ? { platform } : {}),
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
function normalizeMarkdown(seg) {
|
|
123
|
+
const data = seg.data;
|
|
124
|
+
const content = typeof data.content === 'string'
|
|
125
|
+
? data.content
|
|
126
|
+
: typeof data.text === 'string'
|
|
127
|
+
? data.text
|
|
128
|
+
: '';
|
|
129
|
+
return { type: 'markdown', data: { content } };
|
|
130
|
+
}
|
|
131
|
+
function normalizeSegment(seg) {
|
|
132
|
+
if (seg.type === 'at' || seg.type === 'mention')
|
|
133
|
+
return normalizeMention(seg);
|
|
134
|
+
if (seg.type === 'image')
|
|
135
|
+
return normalizeImage(seg);
|
|
136
|
+
if (seg.type === 'reply')
|
|
137
|
+
return normalizeReply(seg);
|
|
138
|
+
if (seg.type === 'forward')
|
|
139
|
+
return normalizeForward(seg);
|
|
140
|
+
if (seg.type === 'sticker' && isPlatformSticker(seg))
|
|
141
|
+
return seg;
|
|
142
|
+
if (seg.type === 'face' || seg.type === 'sticker' || seg.type === 'emoji')
|
|
143
|
+
return normalizeFace(seg);
|
|
144
|
+
if (seg.type === 'link')
|
|
145
|
+
return normalizeLink(seg);
|
|
146
|
+
if (seg.type === 'markdown')
|
|
147
|
+
return normalizeMarkdown(seg);
|
|
148
|
+
return seg;
|
|
149
|
+
}
|
|
150
|
+
function asMessageSegments(content) {
|
|
151
|
+
return content.map((item) => {
|
|
152
|
+
if (typeof item === 'string')
|
|
153
|
+
return { type: 'text', data: { text: item } };
|
|
154
|
+
return item;
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
function asCanonicalSegments(content) {
|
|
158
|
+
if (typeof content === 'string') {
|
|
159
|
+
return [{ type: 'text', data: { text: content } }];
|
|
160
|
+
}
|
|
161
|
+
const items = Array.isArray(content) ? content : [content];
|
|
162
|
+
return items.map((item) => {
|
|
163
|
+
if (typeof item === 'string')
|
|
164
|
+
return { type: 'text', data: { text: item } };
|
|
165
|
+
return item;
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
/** 通用 IM adapter:legacy wire → canonical Segment[] */
|
|
169
|
+
export function toCanonicalSegments(content) {
|
|
170
|
+
return asMessageSegments(content).map((seg) => normalizeSegment(seg));
|
|
171
|
+
}
|
|
172
|
+
function mapCanonicalToWire(seg) {
|
|
173
|
+
if (seg.type === 'image' && isRecord(seg.data) && seg.data.media) {
|
|
174
|
+
const media = seg.data.media;
|
|
175
|
+
const legacy = mediaRefToLegacyFields(media);
|
|
176
|
+
return {
|
|
177
|
+
type: 'image',
|
|
178
|
+
data: {
|
|
179
|
+
...legacy,
|
|
180
|
+
media,
|
|
181
|
+
...(typeof seg.data.alt === 'string' ? { alt: seg.data.alt } : {}),
|
|
182
|
+
},
|
|
183
|
+
...(seg.platform ? { platform: seg.platform } : {}),
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
if (seg.type === 'mention') {
|
|
187
|
+
const data = seg.data;
|
|
188
|
+
return {
|
|
189
|
+
type: 'at',
|
|
190
|
+
data: {
|
|
191
|
+
id: data.target,
|
|
192
|
+
...(data.name ? { name: data.name } : {}),
|
|
193
|
+
},
|
|
194
|
+
...(seg.platform ? { platform: seg.platform } : {}),
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
if (seg.type === 'reply') {
|
|
198
|
+
const messageId = String(seg.data.message_id);
|
|
199
|
+
return {
|
|
200
|
+
type: 'reply',
|
|
201
|
+
data: { id: messageId, message_id: messageId },
|
|
202
|
+
...(seg.platform ? { platform: seg.platform } : {}),
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
if (seg.type === 'forward') {
|
|
206
|
+
const data = seg.data;
|
|
207
|
+
const resid = seg.platform?.resid ?? data.forward_id;
|
|
208
|
+
return {
|
|
209
|
+
type: 'forward',
|
|
210
|
+
data: {
|
|
211
|
+
id: data.forward_id,
|
|
212
|
+
resid,
|
|
213
|
+
...(data.title ? { title: data.title } : {}),
|
|
214
|
+
...(data.messages ? { messages: data.messages } : {}),
|
|
215
|
+
},
|
|
216
|
+
...(seg.platform ? { platform: seg.platform } : {}),
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
if (seg.type === 'link') {
|
|
220
|
+
const data = seg.data;
|
|
221
|
+
return {
|
|
222
|
+
type: 'link',
|
|
223
|
+
data: { url: data.url, ...(data.text ? { text: data.text } : {}) },
|
|
224
|
+
...(seg.platform ? { platform: seg.platform } : {}),
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
return seg;
|
|
228
|
+
}
|
|
229
|
+
/** canonical → wire(mention→at;image MediaRef→legacy 字段) */
|
|
230
|
+
export function fromCanonicalSegments(content) {
|
|
231
|
+
return asCanonicalSegments(content).map((seg) => mapCanonicalToWire(seg));
|
|
232
|
+
}
|
|
@@ -5,8 +5,9 @@ export interface LoadHtmlRendererOptions {
|
|
|
5
5
|
getConfig?: () => Record<string, unknown> | undefined;
|
|
6
6
|
warn?: (message: string) => void;
|
|
7
7
|
}
|
|
8
|
+
/** zhin 启动时已创建 renderer 时注入,避免 core 目录下 peer 解析失败 */
|
|
9
|
+
export declare function seedHtmlRenderer(renderer: HtmlRendererForRichSegment): void;
|
|
8
10
|
/** 动态加载 @zhin.js/html-renderer;未安装时 warn 一次并返回 undefined */
|
|
9
11
|
export declare function loadHtmlRenderer(opts?: LoadHtmlRendererOptions): Promise<HtmlRendererForRichSegment | undefined>;
|
|
10
12
|
/** 测试用:重置加载缓存 */
|
|
11
13
|
export declare function resetHtmlRendererLoaderForTests(): void;
|
|
12
|
-
//# sourceMappingURL=html-renderer-loader.d.ts.map
|
|
@@ -1,14 +1,19 @@
|
|
|
1
|
+
import { importOptionalPeerPackage } from './optional-peer-import.js';
|
|
1
2
|
/** 动态 import 时使用的包名(与 @zhin.js/html-renderer package.json 一致) */
|
|
2
3
|
export const HTML_RENDERER_PACKAGE = '@zhin.js/html-renderer';
|
|
3
4
|
let cached;
|
|
4
5
|
let warned = false;
|
|
6
|
+
/** zhin 启动时已创建 renderer 时注入,避免 core 目录下 peer 解析失败 */
|
|
7
|
+
export function seedHtmlRenderer(renderer) {
|
|
8
|
+
cached = renderer;
|
|
9
|
+
}
|
|
5
10
|
/** 动态加载 @zhin.js/html-renderer;未安装时 warn 一次并返回 undefined */
|
|
6
11
|
export async function loadHtmlRenderer(opts) {
|
|
7
12
|
if (cached !== undefined) {
|
|
8
13
|
return cached ?? undefined;
|
|
9
14
|
}
|
|
10
15
|
try {
|
|
11
|
-
const mod = await
|
|
16
|
+
const mod = await importOptionalPeerPackage(HTML_RENDERER_PACKAGE);
|
|
12
17
|
cached = mod.createHtmlRenderer(opts?.getConfig?.() ?? {});
|
|
13
18
|
return cached;
|
|
14
19
|
}
|
|
@@ -26,4 +31,3 @@ export function resetHtmlRendererLoaderForTests() {
|
|
|
26
31
|
cached = undefined;
|
|
27
32
|
warned = false;
|
|
28
33
|
}
|
|
29
|
-
//# sourceMappingURL=html-renderer-loader.js.map
|