@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
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ScheduleFeature — 管理插件注册的内存定时任务
|
|
3
|
+
*/
|
|
4
|
+
import { Feature, ScheduleEngine, getScheduleEngine, setScheduleEngine, } from '@zhin.js/kernel';
|
|
5
|
+
function ensureEngine() {
|
|
6
|
+
let engine = getScheduleEngine();
|
|
7
|
+
if (!engine) {
|
|
8
|
+
engine = new ScheduleEngine();
|
|
9
|
+
setScheduleEngine(engine);
|
|
10
|
+
}
|
|
11
|
+
return engine;
|
|
12
|
+
}
|
|
13
|
+
export class ScheduleFeature extends Feature {
|
|
14
|
+
name = 'schedule';
|
|
15
|
+
icon = 'Clock';
|
|
16
|
+
desc = '日历调度';
|
|
17
|
+
byName = new Map();
|
|
18
|
+
add(handle, pluginName) {
|
|
19
|
+
this.byName.set(handle.id, handle);
|
|
20
|
+
return super.add(handle, pluginName);
|
|
21
|
+
}
|
|
22
|
+
remove(handle) {
|
|
23
|
+
if (!this.byName.has(handle.id) && !this.items.includes(handle)) {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
this.byName.delete(handle.id);
|
|
27
|
+
const removed = super.remove(handle);
|
|
28
|
+
if (removed) {
|
|
29
|
+
handle.dispose();
|
|
30
|
+
}
|
|
31
|
+
return removed;
|
|
32
|
+
}
|
|
33
|
+
get(id) {
|
|
34
|
+
return this.byName.get(id);
|
|
35
|
+
}
|
|
36
|
+
stopAll() {
|
|
37
|
+
for (const handle of this.items) {
|
|
38
|
+
handle.dispose();
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
getStatus() {
|
|
42
|
+
const engine = getScheduleEngine();
|
|
43
|
+
const engineStatus = engine?.getStatus() ?? [];
|
|
44
|
+
const byId = new Map(engineStatus.map((s) => [s.id, s]));
|
|
45
|
+
return this.items.map((handle) => {
|
|
46
|
+
let pluginName = 'unknown';
|
|
47
|
+
for (const [name, items] of this.pluginItems) {
|
|
48
|
+
if (items.includes(handle)) {
|
|
49
|
+
pluginName = name;
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
const st = byId.get(handle.id);
|
|
54
|
+
return {
|
|
55
|
+
id: handle.id,
|
|
56
|
+
kind: handle.descriptor.kind,
|
|
57
|
+
expression: handle.descriptor.cron,
|
|
58
|
+
running: st?.running ?? true,
|
|
59
|
+
nextExecution: st?.nextExecution ?? null,
|
|
60
|
+
plugin: pluginName,
|
|
61
|
+
};
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
dispose() {
|
|
65
|
+
this.stopAll();
|
|
66
|
+
}
|
|
67
|
+
toJSON(pluginName) {
|
|
68
|
+
const list = pluginName ? this.getByPlugin(pluginName) : this.items;
|
|
69
|
+
return {
|
|
70
|
+
name: this.name,
|
|
71
|
+
icon: this.icon,
|
|
72
|
+
desc: this.desc,
|
|
73
|
+
count: list.length,
|
|
74
|
+
items: list.map((h) => ({
|
|
75
|
+
id: h.id,
|
|
76
|
+
kind: h.descriptor.kind,
|
|
77
|
+
cron: h.descriptor.cron,
|
|
78
|
+
})),
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
get extensions() {
|
|
82
|
+
const feature = this;
|
|
83
|
+
return {
|
|
84
|
+
addSchedule(descriptor, callback, id) {
|
|
85
|
+
const plugin = this;
|
|
86
|
+
const jobId = id ?? `sched_${Math.random().toString(36).slice(2, 10)}`;
|
|
87
|
+
const engine = ensureEngine();
|
|
88
|
+
const disposeEngine = engine.register(jobId, descriptor.kind, async () => {
|
|
89
|
+
await callback();
|
|
90
|
+
}, {
|
|
91
|
+
cron: descriptor.cron,
|
|
92
|
+
everyMs: descriptor.everyMs,
|
|
93
|
+
atMs: descriptor.atMs,
|
|
94
|
+
scatterInput: descriptor.scatterInput,
|
|
95
|
+
holidayInput: descriptor.holidayInput,
|
|
96
|
+
tz: descriptor.tz,
|
|
97
|
+
});
|
|
98
|
+
const handle = {
|
|
99
|
+
id: jobId,
|
|
100
|
+
descriptor,
|
|
101
|
+
dispose: () => {
|
|
102
|
+
disposeEngine();
|
|
103
|
+
},
|
|
104
|
+
};
|
|
105
|
+
const dispose = feature.add(handle, plugin.name);
|
|
106
|
+
plugin.recordFeatureContribution(feature.name, jobId);
|
|
107
|
+
plugin.onDispose(dispose);
|
|
108
|
+
return dispose;
|
|
109
|
+
},
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
}
|
|
@@ -15,4 +15,3 @@ export declare class SchemaEndpointManager implements EndpointManager {
|
|
|
15
15
|
}
|
|
16
16
|
export declare function resolveEndpointManager(adapter: Adapter): EndpointManager | null;
|
|
17
17
|
export declare function adapterSupportsProvision(adapter: Adapter): boolean;
|
|
18
|
-
//# sourceMappingURL=schema-endpoint-manager.d.ts.map
|
|
@@ -9,7 +9,6 @@
|
|
|
9
9
|
* - Schema.toJSON() 传给前端驱动 PluginConfigForm
|
|
10
10
|
* - reloadable 标记决定保存后是否自动重载插件
|
|
11
11
|
*/
|
|
12
|
-
import { getPlugin } from '../plugin.js';
|
|
13
12
|
import { Feature } from '@zhin.js/kernel';
|
|
14
13
|
// ============================================================================
|
|
15
14
|
// SchemaFeature
|
|
@@ -91,7 +90,7 @@ export class SchemaFeature extends Feature {
|
|
|
91
90
|
const feature = this;
|
|
92
91
|
return {
|
|
93
92
|
declareConfig(key, schema, options) {
|
|
94
|
-
const plugin =
|
|
93
|
+
const plugin = this;
|
|
95
94
|
const reloadable = options?.reloadable ?? true;
|
|
96
95
|
// 从 Schema 提取默认值
|
|
97
96
|
const defaults = extractDefaults(schema);
|
|
@@ -129,4 +128,3 @@ function extractDefaults(schema) {
|
|
|
129
128
|
}
|
|
130
129
|
return result;
|
|
131
130
|
}
|
|
132
|
-
//# sourceMappingURL=schema-feature.js.map
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Segment } from './types.js';
|
|
2
|
+
/** 宽松判断:已知 canonical type 走严格校验;未知 type 仅校验顶层形状(adapter 渐进迁移) */
|
|
3
|
+
export declare function isCanonicalSegment(value: unknown): value is Segment;
|
|
4
|
+
export declare function assertCanonicalSegments(segments: unknown): asserts segments is Segment[];
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { isStrictCanonicalSegment } from './validate.js';
|
|
2
|
+
const STRICT_CANONICAL_TYPES = new Set([
|
|
3
|
+
'text', 'mention', 'image', 'reply', 'forward', 'face', 'dice', 'rps',
|
|
4
|
+
]);
|
|
5
|
+
function isPlainObject(value) {
|
|
6
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
7
|
+
}
|
|
8
|
+
/** 宽松判断:已知 canonical type 走严格校验;未知 type 仅校验顶层形状(adapter 渐进迁移) */
|
|
9
|
+
export function isCanonicalSegment(value) {
|
|
10
|
+
if (!isPlainObject(value) || typeof value.type !== 'string')
|
|
11
|
+
return false;
|
|
12
|
+
if (!isPlainObject(value.data))
|
|
13
|
+
return false;
|
|
14
|
+
if (value.platform !== undefined && !isPlainObject(value.platform))
|
|
15
|
+
return false;
|
|
16
|
+
if (!STRICT_CANONICAL_TYPES.has(value.type)) {
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
return isStrictCanonicalSegment(value);
|
|
20
|
+
}
|
|
21
|
+
export function assertCanonicalSegments(segments) {
|
|
22
|
+
if (!Array.isArray(segments)) {
|
|
23
|
+
throw new Error('segments must be an array');
|
|
24
|
+
}
|
|
25
|
+
for (let i = 0; i < segments.length; i++) {
|
|
26
|
+
if (!isCanonicalSegment(segments[i])) {
|
|
27
|
+
throw new Error(`segment[${i}] is not canonical`);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { isCanonicalSegment } from './assert.js';
|
|
2
|
+
/** IM 可见段白名单(thinking / tool_call 等 AI-only 段过滤) */
|
|
3
|
+
const IM_VISIBLE_TYPES = new Set([
|
|
4
|
+
'text',
|
|
5
|
+
'mention',
|
|
6
|
+
'image',
|
|
7
|
+
'video',
|
|
8
|
+
'audio',
|
|
9
|
+
'voice',
|
|
10
|
+
'record',
|
|
11
|
+
'file',
|
|
12
|
+
'face',
|
|
13
|
+
'reply',
|
|
14
|
+
'forward',
|
|
15
|
+
'link',
|
|
16
|
+
'dice',
|
|
17
|
+
'rps',
|
|
18
|
+
'markdown',
|
|
19
|
+
'html',
|
|
20
|
+
'qrcode',
|
|
21
|
+
'tts',
|
|
22
|
+
'keyboard',
|
|
23
|
+
]);
|
|
24
|
+
const AI_ONLY_TYPES = new Set(['thinking', 'tool_call']);
|
|
25
|
+
/**
|
|
26
|
+
* 过滤 agent / AI 出站段,仅保留可经 IM 投递的 canonical 段。
|
|
27
|
+
*/
|
|
28
|
+
export function segmentsForImDelivery(segments) {
|
|
29
|
+
const out = [];
|
|
30
|
+
for (const item of segments) {
|
|
31
|
+
if (!isCanonicalSegment(item))
|
|
32
|
+
continue;
|
|
33
|
+
if (AI_ONLY_TYPES.has(item.type))
|
|
34
|
+
continue;
|
|
35
|
+
if (!IM_VISIBLE_TYPES.has(item.type))
|
|
36
|
+
continue;
|
|
37
|
+
out.push(item);
|
|
38
|
+
}
|
|
39
|
+
return out;
|
|
40
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export type { Segment, SegmentBase, MediaRef, TextSegment, MentionSegment, ImageSegment, ReplySegment, ForwardSegment, FaceSegment, DiceSegment, RpsSegment, } from './types.js';
|
|
2
|
+
export { mediaRefSchema, textSegmentSchema, mentionSegmentSchema, imageSegmentSchema, replySegmentSchema, forwardSegmentSchema, faceSegmentSchema, diceSegmentSchema, rpsSegmentSchema, canonicalSegmentSchema, segmentArraySchema, } from './validate.js';
|
|
3
|
+
export { assertCanonicalSegments, isCanonicalSegment } from './assert.js';
|
|
4
|
+
export { segmentsForImDelivery } from './delivery.js';
|
|
5
|
+
export { isMediaRef, mediaRefFromLegacyData, mediaRefToLegacyFields } from './media.js';
|
|
6
|
+
export { createImageSegment } from './image.js';
|
|
7
|
+
export { formatSegmentPreview } from './preview.js';
|
|
8
|
+
export { readMentionTarget, readMentionName, readMentionSegmentTarget } from './mention.js';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { mediaRefSchema, textSegmentSchema, mentionSegmentSchema, imageSegmentSchema, replySegmentSchema, forwardSegmentSchema, faceSegmentSchema, diceSegmentSchema, rpsSegmentSchema, canonicalSegmentSchema, segmentArraySchema, } from './validate.js';
|
|
2
|
+
export { assertCanonicalSegments, isCanonicalSegment } from './assert.js';
|
|
3
|
+
export { segmentsForImDelivery } from './delivery.js';
|
|
4
|
+
export { isMediaRef, mediaRefFromLegacyData, mediaRefToLegacyFields } from './media.js';
|
|
5
|
+
export { createImageSegment } from './image.js';
|
|
6
|
+
export { formatSegmentPreview } from './preview.js';
|
|
7
|
+
export { readMentionTarget, readMentionName, readMentionSegmentTarget } from './mention.js';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { MediaRef } from './types.js';
|
|
2
|
+
import { isMediaRef } from './validate.js';
|
|
3
|
+
export { isMediaRef };
|
|
4
|
+
export declare function mediaRefFromLegacyData(data: Record<string, unknown>): MediaRef | undefined;
|
|
5
|
+
export declare function mediaRefToLegacyFields(media: MediaRef): {
|
|
6
|
+
url?: string;
|
|
7
|
+
file?: string;
|
|
8
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { isMediaRef } from './validate.js';
|
|
2
|
+
export { isMediaRef };
|
|
3
|
+
export function mediaRefFromLegacyData(data) {
|
|
4
|
+
if (isMediaRef(data.media)) {
|
|
5
|
+
return data.media;
|
|
6
|
+
}
|
|
7
|
+
const mimeType = typeof data.mime_type === 'string' ? data.mime_type : undefined;
|
|
8
|
+
const base64 = typeof data.base64 === 'string' && data.base64.trim()
|
|
9
|
+
? data.base64.trim()
|
|
10
|
+
: typeof data.data === 'string' && data.data.trim() && !String(data.data).startsWith('http')
|
|
11
|
+
? data.data.trim()
|
|
12
|
+
: undefined;
|
|
13
|
+
if (base64) {
|
|
14
|
+
return { kind: 'base64', value: base64, ...(mimeType ? { mime_type: mimeType } : {}) };
|
|
15
|
+
}
|
|
16
|
+
const raw = [data.url, data.file, data.src, data.href]
|
|
17
|
+
.find((v) => typeof v === 'string' && v.trim().length > 0);
|
|
18
|
+
if (!raw)
|
|
19
|
+
return undefined;
|
|
20
|
+
const value = raw.trim();
|
|
21
|
+
if (value.startsWith('base64://')) {
|
|
22
|
+
return { kind: 'base64', value: value.slice('base64://'.length), ...(mimeType ? { mime_type: mimeType } : {}) };
|
|
23
|
+
}
|
|
24
|
+
if (value.startsWith('http://') || value.startsWith('https://')) {
|
|
25
|
+
return { kind: 'url', value, ...(mimeType ? { mime_type: mimeType } : {}) };
|
|
26
|
+
}
|
|
27
|
+
if (value.startsWith('/') || /^[a-zA-Z]:[\\/]/.test(value)) {
|
|
28
|
+
return { kind: 'path', value, ...(mimeType ? { mime_type: mimeType } : {}) };
|
|
29
|
+
}
|
|
30
|
+
return { kind: 'url', value, ...(mimeType ? { mime_type: mimeType } : {}) };
|
|
31
|
+
}
|
|
32
|
+
export function mediaRefToLegacyFields(media) {
|
|
33
|
+
if (media.kind === 'url')
|
|
34
|
+
return { url: media.value, file: media.value };
|
|
35
|
+
if (media.kind === 'path')
|
|
36
|
+
return { file: media.value, url: media.value };
|
|
37
|
+
const encoded = media.value.startsWith('base64://') ? media.value : `base64://${media.value}`;
|
|
38
|
+
return { file: encoded, url: encoded };
|
|
39
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Canonical mention field readers (SSOT).
|
|
3
|
+
*/
|
|
4
|
+
export declare function readMentionTarget(data: Record<string, unknown> | undefined): string;
|
|
5
|
+
export declare function readMentionName(data: Record<string, unknown> | undefined): string | undefined;
|
|
6
|
+
/** Resolve @ target from at / mention segment. */
|
|
7
|
+
export declare function readMentionSegmentTarget(seg: {
|
|
8
|
+
type: unknown;
|
|
9
|
+
data?: unknown;
|
|
10
|
+
}): string;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Canonical mention field readers (SSOT).
|
|
3
|
+
*/
|
|
4
|
+
export function readMentionTarget(data) {
|
|
5
|
+
if (!data)
|
|
6
|
+
return '';
|
|
7
|
+
const raw = data.target ?? data.user_id ?? data.qq ?? data.id;
|
|
8
|
+
if (raw === 'all')
|
|
9
|
+
return 'all';
|
|
10
|
+
return raw != null ? String(raw) : '';
|
|
11
|
+
}
|
|
12
|
+
export function readMentionName(data) {
|
|
13
|
+
if (!data)
|
|
14
|
+
return undefined;
|
|
15
|
+
const name = data.name ?? data.nickname ?? data.username;
|
|
16
|
+
return typeof name === 'string' && name.trim() ? name.trim() : undefined;
|
|
17
|
+
}
|
|
18
|
+
function isRecord(value) {
|
|
19
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
20
|
+
}
|
|
21
|
+
/** Resolve @ target from at / mention segment. */
|
|
22
|
+
export function readMentionSegmentTarget(seg) {
|
|
23
|
+
if (seg.type !== 'at' && seg.type !== 'mention')
|
|
24
|
+
return '';
|
|
25
|
+
return readMentionTarget(isRecord(seg.data) ? seg.data : undefined);
|
|
26
|
+
}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Canonical Segment[] log / debug preview (SSOT).
|
|
3
|
+
* @see docs/architecture/segment-content-model.md
|
|
4
|
+
*/
|
|
5
|
+
import { htmlToFallbackText } from '../html-to-text.js';
|
|
6
|
+
import { readMentionName, readMentionTarget } from './mention.js';
|
|
7
|
+
import { mediaRefFromLegacyData } from './media.js';
|
|
8
|
+
const PREVIEW_MAX = 80;
|
|
9
|
+
function clip(text, max = PREVIEW_MAX) {
|
|
10
|
+
const normalized = text.trim();
|
|
11
|
+
if (normalized.length <= max)
|
|
12
|
+
return normalized;
|
|
13
|
+
return `${normalized.slice(0, max)}…`;
|
|
14
|
+
}
|
|
15
|
+
function previewMedia(data) {
|
|
16
|
+
const media = mediaRefFromLegacyData(data);
|
|
17
|
+
if (!media)
|
|
18
|
+
return undefined;
|
|
19
|
+
if (media.kind === 'base64') {
|
|
20
|
+
const mime = media.mime_type ?? 'data';
|
|
21
|
+
return `base64:${mime}[${media.value.length}]`;
|
|
22
|
+
}
|
|
23
|
+
if (media.kind === 'path') {
|
|
24
|
+
const base = media.value.split(/[/\\]/).pop() ?? media.value;
|
|
25
|
+
return clip(base, 48);
|
|
26
|
+
}
|
|
27
|
+
return clip(media.value, 60);
|
|
28
|
+
}
|
|
29
|
+
function previewMediaSegment(type, data) {
|
|
30
|
+
const media = previewMedia(data);
|
|
31
|
+
const alt = typeof data.alt === 'string'
|
|
32
|
+
? data.alt
|
|
33
|
+
: typeof data.name === 'string'
|
|
34
|
+
? data.name
|
|
35
|
+
: undefined;
|
|
36
|
+
if (media && alt)
|
|
37
|
+
return `[${type}:${media} alt=${clip(alt, 24)}]`;
|
|
38
|
+
if (media)
|
|
39
|
+
return `[${type}:${media}]`;
|
|
40
|
+
return `[${type}]`;
|
|
41
|
+
}
|
|
42
|
+
/** Single canonical segment → compact human-readable preview for logs. */
|
|
43
|
+
export function formatSegmentPreview(item) {
|
|
44
|
+
const { type } = item;
|
|
45
|
+
const data = item.data ?? {};
|
|
46
|
+
switch (type) {
|
|
47
|
+
case 'text':
|
|
48
|
+
return typeof data.text === 'string' ? data.text : '';
|
|
49
|
+
case 'mention': {
|
|
50
|
+
const target = readMentionTarget(data);
|
|
51
|
+
if (target === 'all')
|
|
52
|
+
return '@all';
|
|
53
|
+
const name = readMentionName(data);
|
|
54
|
+
if (name)
|
|
55
|
+
return `@${name}`;
|
|
56
|
+
return `@${target}`;
|
|
57
|
+
}
|
|
58
|
+
case 'at': {
|
|
59
|
+
const target = readMentionTarget(data);
|
|
60
|
+
const name = readMentionName(data);
|
|
61
|
+
if (name)
|
|
62
|
+
return `@${name}`;
|
|
63
|
+
return `@${target}`;
|
|
64
|
+
}
|
|
65
|
+
case 'image':
|
|
66
|
+
case 'video':
|
|
67
|
+
case 'audio':
|
|
68
|
+
case 'voice':
|
|
69
|
+
case 'record':
|
|
70
|
+
case 'file':
|
|
71
|
+
return previewMediaSegment(type, data);
|
|
72
|
+
case 'face': {
|
|
73
|
+
const id = data.id ?? data.face_id;
|
|
74
|
+
const name = typeof data.name === 'string'
|
|
75
|
+
? data.name
|
|
76
|
+
: typeof data.text === 'string'
|
|
77
|
+
? data.text
|
|
78
|
+
: undefined;
|
|
79
|
+
if (id != null && name)
|
|
80
|
+
return `[face:${id} ${name}]`;
|
|
81
|
+
if (id != null)
|
|
82
|
+
return `[face:${id}]`;
|
|
83
|
+
if (name)
|
|
84
|
+
return `{face}(${name})`;
|
|
85
|
+
return '[face]';
|
|
86
|
+
}
|
|
87
|
+
case 'reply': {
|
|
88
|
+
const id = data.message_id ?? data.id;
|
|
89
|
+
return id ? `↩${id}` : '[reply]';
|
|
90
|
+
}
|
|
91
|
+
case 'forward': {
|
|
92
|
+
const id = data.forward_id ?? data.id;
|
|
93
|
+
const title = typeof data.title === 'string' ? data.title : undefined;
|
|
94
|
+
const count = Array.isArray(data.messages) ? data.messages.length : 0;
|
|
95
|
+
let out = `[forward${id ? `:${id}` : ''}`;
|
|
96
|
+
if (title)
|
|
97
|
+
out += ` ${clip(title, 32)}`;
|
|
98
|
+
if (count > 0)
|
|
99
|
+
out += ` ×${count}`;
|
|
100
|
+
return `${out}]`;
|
|
101
|
+
}
|
|
102
|
+
case 'link': {
|
|
103
|
+
const url = typeof data.url === 'string' ? data.url : '';
|
|
104
|
+
const text = typeof data.text === 'string' ? data.text : '';
|
|
105
|
+
if (text && url)
|
|
106
|
+
return clip(`${text} <${url}>`);
|
|
107
|
+
return clip(url || text || '[link]');
|
|
108
|
+
}
|
|
109
|
+
case 'dice':
|
|
110
|
+
return data.result != null ? `{dice}(${data.result})` : '{dice}';
|
|
111
|
+
case 'rps':
|
|
112
|
+
return data.result != null ? `{rps}(${data.result})` : '{rps}';
|
|
113
|
+
case 'html': {
|
|
114
|
+
if (typeof data.text === 'string' && data.text)
|
|
115
|
+
return clip(data.text);
|
|
116
|
+
if (typeof data.html === 'string') {
|
|
117
|
+
const stripped = htmlToFallbackText(data.html);
|
|
118
|
+
return stripped ? clip(`[html] ${stripped}`) : '[html]';
|
|
119
|
+
}
|
|
120
|
+
return '[html]';
|
|
121
|
+
}
|
|
122
|
+
case 'qrcode': {
|
|
123
|
+
const text = typeof data.text === 'string' ? data.text : '';
|
|
124
|
+
return text ? clip(`[qrcode] ${text}`) : '[qrcode]';
|
|
125
|
+
}
|
|
126
|
+
case 'markdown': {
|
|
127
|
+
const text = typeof data.content === 'string'
|
|
128
|
+
? data.content
|
|
129
|
+
: typeof data.text === 'string'
|
|
130
|
+
? data.text
|
|
131
|
+
: '';
|
|
132
|
+
return text ? clip(`[markdown] ${text}`) : '[markdown]';
|
|
133
|
+
}
|
|
134
|
+
case 'tts': {
|
|
135
|
+
const text = typeof data.text === 'string' ? data.text : '';
|
|
136
|
+
return text ? clip(`[tts] ${text}`) : '[tts]';
|
|
137
|
+
}
|
|
138
|
+
case 'keyboard': {
|
|
139
|
+
const rows = Array.isArray(data.rows)
|
|
140
|
+
? data.rows.length
|
|
141
|
+
: Array.isArray(data.buttons)
|
|
142
|
+
? data.buttons.length
|
|
143
|
+
: 0;
|
|
144
|
+
return rows > 0 ? `[keyboard:${rows}]` : '[keyboard]';
|
|
145
|
+
}
|
|
146
|
+
case 'thinking': {
|
|
147
|
+
const text = typeof data.text === 'string' ? data.text : '';
|
|
148
|
+
return text ? clip(`[thinking] ${text}`, 60) : '[thinking]';
|
|
149
|
+
}
|
|
150
|
+
case 'tool_call': {
|
|
151
|
+
const name = typeof data.name === 'string' ? data.name : 'tool';
|
|
152
|
+
return `[tool:${name}]`;
|
|
153
|
+
}
|
|
154
|
+
default:
|
|
155
|
+
if (typeof data.text === 'string' && data.text)
|
|
156
|
+
return `{${type}}(${clip(data.text)})`;
|
|
157
|
+
return `{${type}}`;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Canonical Segment SSOT — IM + AI 共用 JSON 形状(snake_case data)。
|
|
3
|
+
* @see docs/architecture/segment-content-model.md
|
|
4
|
+
*/
|
|
5
|
+
export interface SegmentBase {
|
|
6
|
+
type: string;
|
|
7
|
+
data: Record<string, unknown>;
|
|
8
|
+
platform?: Record<string, unknown>;
|
|
9
|
+
}
|
|
10
|
+
/** 媒体引用占位(完整 schema 随 adapter 迁移补齐) */
|
|
11
|
+
export interface MediaRef {
|
|
12
|
+
kind: 'url' | 'path' | 'base64';
|
|
13
|
+
value: string;
|
|
14
|
+
mime_type?: string;
|
|
15
|
+
}
|
|
16
|
+
export interface TextSegment extends SegmentBase {
|
|
17
|
+
type: 'text';
|
|
18
|
+
data: {
|
|
19
|
+
text: string;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
export interface MentionSegment extends SegmentBase {
|
|
23
|
+
type: 'mention';
|
|
24
|
+
data: {
|
|
25
|
+
target: string;
|
|
26
|
+
name?: string;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
export interface ImageSegment extends SegmentBase {
|
|
30
|
+
type: 'image';
|
|
31
|
+
data: {
|
|
32
|
+
media: MediaRef;
|
|
33
|
+
alt?: string;
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
export interface ReplySegment extends SegmentBase {
|
|
37
|
+
type: 'reply';
|
|
38
|
+
data: {
|
|
39
|
+
message_id: string;
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
export interface ForwardSegment extends SegmentBase {
|
|
43
|
+
type: 'forward';
|
|
44
|
+
data: {
|
|
45
|
+
forward_id: string;
|
|
46
|
+
title?: string;
|
|
47
|
+
messages?: Segment[][];
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
export interface FaceSegment extends SegmentBase {
|
|
51
|
+
type: 'face';
|
|
52
|
+
data: {
|
|
53
|
+
id: string | number;
|
|
54
|
+
name?: string;
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
export interface DiceSegment extends SegmentBase {
|
|
58
|
+
type: 'dice';
|
|
59
|
+
data: {
|
|
60
|
+
result?: number;
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
export interface RpsSegment extends SegmentBase {
|
|
64
|
+
type: 'rps';
|
|
65
|
+
data: {
|
|
66
|
+
result?: number;
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
/** 规范态 segment(严格校验 text / mention / image / reply / forward / face / dice / rps) */
|
|
70
|
+
export type Segment = TextSegment | MentionSegment | ImageSegment | ReplySegment | ForwardSegment | FaceSegment | DiceSegment | RpsSegment | SegmentBase;
|