@zhin.js/core 1.1.33 → 1.1.35
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +140 -61
- package/lib/adapter.d.ts +72 -23
- package/lib/adapter.js +222 -58
- package/lib/built/adapter-process.d.ts +20 -5
- package/lib/built/adapter-process.js +54 -7
- package/lib/built/agent-preset.d.ts +1 -2
- package/lib/built/agent-preset.js +1 -2
- package/lib/built/ai-access.d.ts +36 -0
- package/lib/built/ai-access.js +46 -0
- package/lib/built/ai-outbound/adapter-access.d.ts +3 -0
- package/lib/built/ai-outbound/adapter-access.js +9 -0
- package/lib/built/ai-outbound/extensions/onebot-keyboard.d.ts +2 -0
- package/lib/built/ai-outbound/extensions/onebot-keyboard.js +67 -0
- package/lib/built/ai-outbound/extensions/qq-message.d.ts +3 -0
- package/lib/built/ai-outbound/extensions/qq-message.js +23 -0
- package/lib/built/ai-outbound/index.d.ts +9 -0
- package/lib/built/ai-outbound/index.js +9 -0
- package/lib/built/ai-outbound/parse.d.ts +13 -0
- package/lib/built/ai-outbound/parse.js +104 -0
- package/lib/built/ai-outbound/plain-mention-rewrite.d.ts +6 -0
- package/lib/built/ai-outbound/plain-mention-rewrite.js +37 -0
- package/lib/built/ai-outbound/prompt.d.ts +11 -0
- package/lib/built/ai-outbound/prompt.js +44 -0
- package/lib/built/ai-outbound/resolve.d.ts +4 -0
- package/lib/built/ai-outbound/resolve.js +64 -0
- package/lib/built/ai-outbound/structured-detect.d.ts +3 -0
- package/lib/built/ai-outbound/structured-detect.js +6 -0
- package/lib/built/ai-outbound/types.d.ts +58 -0
- package/lib/built/ai-outbound/types.js +5 -0
- package/lib/built/ai-trigger.d.ts +17 -17
- package/lib/built/ai-trigger.js +65 -70
- package/lib/built/authorization.d.ts +10 -0
- package/lib/built/authorization.js +76 -0
- package/lib/built/command.d.ts +9 -5
- package/lib/built/command.js +20 -7
- package/lib/built/common-adapter-tools.d.ts +35 -29
- package/lib/built/common-adapter-tools.js +83 -67
- package/lib/built/component.d.ts +1 -3
- package/lib/built/component.js +2 -4
- package/lib/built/config.d.ts +4 -5
- package/lib/built/config.js +26 -9
- package/lib/built/connect-endpoint-instance.d.ts +17 -0
- package/lib/built/connect-endpoint-instance.js +42 -0
- package/lib/built/database.d.ts +5 -3
- package/lib/built/database.js +10 -4
- package/lib/built/dispatcher.d.ts +10 -8
- package/lib/built/dispatcher.js +31 -9
- package/lib/built/endpoint-commands.d.ts +3 -0
- package/lib/built/endpoint-commands.js +99 -0
- package/lib/built/endpoint-lifecycle-service.d.ts +28 -0
- package/lib/built/endpoint-lifecycle-service.js +242 -0
- package/lib/built/endpoint-lifecycle.d.ts +27 -0
- package/lib/built/endpoint-lifecycle.js +36 -0
- package/lib/built/endpoint-manager.d.ts +34 -0
- package/lib/built/endpoint-manager.js +1 -0
- package/lib/built/generated-qrcode.d.ts +24 -0
- package/lib/built/generated-qrcode.js +45 -0
- package/lib/built/generic-segment-mapper.d.ts +4 -0
- package/lib/built/generic-segment-mapper.js +190 -0
- package/lib/built/html-renderer-loader.d.ts +13 -0
- package/lib/built/html-renderer-loader.js +33 -0
- package/lib/built/html-segment-fallback.d.ts +9 -0
- package/lib/built/html-segment-fallback.js +49 -0
- package/lib/built/html-to-text.d.ts +4 -1
- package/lib/built/html-to-text.js +47 -16
- package/lib/built/inbound-pipeline.d.ts +37 -0
- package/lib/built/inbound-pipeline.js +63 -0
- package/lib/built/inbound-runner.d.ts +0 -1
- package/lib/built/inbound-runner.js +0 -3
- package/lib/built/interactive-segment-contract.d.ts +6 -0
- package/lib/built/interactive-segment-contract.js +9 -0
- package/lib/built/interactive-segments/action.d.ts +17 -0
- package/lib/built/interactive-segments/action.js +69 -0
- package/lib/built/interactive-segments/button-spec.d.ts +10 -0
- package/lib/built/interactive-segments/button-spec.js +21 -0
- package/lib/built/interactive-segments/fallback-store.d.ts +29 -0
- package/lib/built/interactive-segments/fallback-store.js +63 -0
- package/lib/built/interactive-segments/handlers.d.ts +16 -0
- package/lib/built/interactive-segments/handlers.js +74 -0
- package/lib/built/interactive-segments/index.d.ts +8 -0
- package/lib/built/interactive-segments/index.js +8 -0
- package/lib/built/interactive-segments/keyboard-segment.d.ts +11 -0
- package/lib/built/interactive-segments/keyboard-segment.js +12 -0
- package/lib/built/interactive-segments/onebot-keyboard.d.ts +7 -0
- package/lib/built/interactive-segments/onebot-keyboard.js +51 -0
- package/lib/built/interactive-segments/resolve.d.ts +15 -0
- package/lib/built/interactive-segments/resolve.js +110 -0
- package/lib/built/interactive-segments/types.d.ts +50 -0
- package/lib/built/interactive-segments/types.js +9 -0
- package/lib/built/introspection-format.d.ts +10 -0
- package/lib/built/introspection-format.js +28 -0
- package/lib/built/login-assist.d.ts +43 -9
- package/lib/built/login-assist.js +113 -11
- package/lib/built/management-command-guard.d.ts +15 -0
- package/lib/built/management-command-guard.js +25 -0
- package/lib/built/message-enrich.d.ts +38 -0
- package/lib/built/message-enrich.js +75 -0
- package/lib/built/message-filter.d.ts +4 -5
- package/lib/built/message-filter.js +5 -7
- package/lib/built/optional-peer-import.d.ts +3 -0
- package/lib/built/optional-peer-import.js +33 -0
- package/lib/built/outbound-media-contract.d.ts +22 -0
- package/lib/built/outbound-media-contract.js +10 -0
- package/lib/built/outbound-media-utils.d.ts +9 -0
- package/lib/built/outbound-media-utils.js +62 -0
- package/lib/built/permission.d.ts +3 -7
- package/lib/built/permission.js +39 -52
- package/lib/built/permit-check.d.ts +7 -0
- package/lib/built/permit-check.js +35 -0
- package/lib/built/permit-parse.d.ts +16 -0
- package/lib/built/permit-parse.js +32 -0
- package/lib/built/platform-permit.d.ts +20 -0
- package/lib/built/platform-permit.js +91 -0
- package/lib/built/queue-im-field-contract.d.ts +7 -2
- package/lib/built/queue-im-field-contract.js +13 -4
- package/lib/built/rich-segments/adapter-policies.d.ts +9 -0
- package/lib/built/rich-segments/adapter-policies.js +27 -0
- package/lib/built/rich-segments/base.d.ts +11 -0
- package/lib/built/rich-segments/base.js +24 -0
- package/lib/built/rich-segments/builtins.d.ts +4 -0
- package/lib/built/rich-segments/builtins.js +40 -0
- package/lib/built/rich-segments/capabilities.d.ts +6 -0
- package/lib/built/rich-segments/capabilities.js +38 -0
- package/lib/built/rich-segments/html-segment.d.ts +15 -0
- package/lib/built/rich-segments/html-segment.js +62 -0
- package/lib/built/rich-segments/index.d.ts +13 -0
- package/lib/built/rich-segments/index.js +13 -0
- package/lib/built/rich-segments/markdown-segment.d.ts +14 -0
- package/lib/built/rich-segments/markdown-segment.js +58 -0
- package/lib/built/rich-segments/markdown-to-text.d.ts +3 -0
- package/lib/built/rich-segments/markdown-to-text.js +27 -0
- package/lib/built/rich-segments/qrcode-segment.d.ts +18 -0
- package/lib/built/rich-segments/qrcode-segment.js +73 -0
- package/lib/built/rich-segments/registry.d.ts +16 -0
- package/lib/built/rich-segments/registry.js +52 -0
- package/lib/built/rich-segments/resolve.d.ts +5 -0
- package/lib/built/rich-segments/resolve.js +87 -0
- package/lib/built/rich-segments/tts-segment.d.ts +13 -0
- package/lib/built/rich-segments/tts-segment.js +51 -0
- package/lib/built/rich-segments/types.d.ts +79 -0
- package/lib/built/rich-segments/types.js +17 -0
- package/lib/built/roles.d.ts +4 -5
- package/lib/built/roles.js +4 -5
- package/lib/built/runtime-io.d.ts +0 -1
- package/lib/built/runtime-io.js +0 -1
- package/lib/built/schedule.d.ts +54 -0
- package/lib/built/schedule.js +112 -0
- package/lib/built/schema-endpoint-manager.d.ts +17 -0
- package/lib/built/schema-endpoint-manager.js +73 -0
- package/lib/built/schema-feature.d.ts +0 -1
- package/lib/built/schema-feature.js +1 -3
- package/lib/built/segment-contract/assert.d.ts +7 -0
- package/lib/built/segment-contract/assert.js +39 -0
- package/lib/built/segment-contract/delivery.d.ts +5 -0
- package/lib/built/segment-contract/delivery.js +40 -0
- package/lib/built/segment-contract/image.d.ts +5 -0
- package/lib/built/segment-contract/image.js +10 -0
- package/lib/built/segment-contract/index.d.ts +10 -0
- package/lib/built/segment-contract/index.js +9 -0
- package/lib/built/segment-contract/json-schema.d.ts +28 -0
- package/lib/built/segment-contract/json-schema.js +128 -0
- package/lib/built/segment-contract/media.d.ts +12 -0
- package/lib/built/segment-contract/media.js +22 -0
- package/lib/built/segment-contract/mention.d.ts +10 -0
- package/lib/built/segment-contract/mention.js +26 -0
- package/lib/built/segment-contract/preview.d.ts +3 -0
- package/lib/built/segment-contract/preview.js +159 -0
- package/lib/built/segment-contract/text.d.ts +7 -0
- package/lib/built/segment-contract/text.js +34 -0
- package/lib/built/segment-contract/types.d.ts +58 -0
- package/lib/built/segment-contract/types.js +1 -0
- package/lib/built/segment-contract/validate.d.ts +229 -0
- package/lib/built/segment-contract/validate.js +174 -0
- package/lib/built/skill.d.ts +0 -1
- package/lib/built/skill.js +0 -1
- package/lib/built/speech-loader.d.ts +14 -0
- package/lib/built/speech-loader.js +32 -0
- package/lib/built/tool.d.ts +14 -13
- package/lib/built/tool.js +30 -25
- package/lib/built/user-interaction.d.ts +30 -0
- package/lib/built/user-interaction.js +248 -0
- package/lib/command.d.ts +19 -11
- package/lib/command.js +42 -11
- package/lib/component.d.ts +0 -1
- package/lib/component.js +67 -14
- package/lib/endpoint-capabilities.d.ts +46 -0
- package/lib/endpoint-capabilities.js +55 -0
- package/lib/endpoint.d.ts +19 -0
- package/lib/endpoint.js +3 -0
- package/lib/errors.d.ts +2 -3
- package/lib/errors.js +4 -5
- package/lib/feature/adapter.d.ts +2 -0
- package/lib/feature/adapter.js +2 -0
- package/lib/feature/command.d.ts +2 -0
- package/lib/feature/command.js +2 -0
- package/lib/feature/component.d.ts +2 -0
- package/lib/feature/component.js +2 -0
- package/lib/feature/handler.d.ts +52 -0
- package/lib/feature/handler.js +26 -0
- package/lib/feature/middleware.d.ts +2 -0
- package/lib/feature/middleware.js +2 -0
- package/lib/host-plugin-registry.d.ts +8 -0
- package/lib/host-plugin-registry.js +12 -0
- package/lib/im-scene.d.ts +29 -0
- package/lib/im-scene.js +75 -0
- package/lib/im-session-id.d.ts +39 -0
- package/lib/im-session-id.js +47 -0
- package/lib/index.d.ts +59 -21
- package/lib/index.js +53 -28
- package/lib/jsx-dev-runtime.d.ts +0 -1
- package/lib/jsx-dev-runtime.js +0 -1
- package/lib/jsx-runtime.d.ts +1 -1
- package/lib/jsx-runtime.js +0 -1
- package/lib/jsx.d.ts +19 -22
- package/lib/jsx.js +0 -1
- package/lib/message.d.ts +16 -10
- package/lib/message.js +16 -13
- package/lib/models/system-log.d.ts +0 -1
- package/lib/models/system-log.js +0 -1
- package/lib/models/user.d.ts +0 -1
- package/lib/models/user.js +0 -1
- package/lib/notice.d.ts +16 -59
- package/lib/notice.js +1 -4
- package/lib/plugin-context.d.ts +27 -0
- package/lib/plugin-context.js +64 -0
- package/lib/plugin-runtime/im/contracts.d.ts +191 -0
- package/lib/plugin-runtime/im/contracts.js +169 -0
- package/lib/plugin-runtime/im/im-runtime.d.ts +177 -0
- package/lib/plugin-runtime/im/im-runtime.js +1204 -0
- package/lib/plugin-runtime/im/index.d.ts +9 -0
- package/lib/plugin-runtime/im/index.js +9 -0
- package/lib/plugin-runtime/im/interactive.d.ts +26 -0
- package/lib/plugin-runtime/im/interactive.js +46 -0
- package/lib/plugin-runtime/im/login-assist-host.d.ts +6 -0
- package/lib/plugin-runtime/im/login-assist-host.js +6 -0
- package/lib/plugin-runtime/im/message-bus.d.ts +38 -0
- package/lib/plugin-runtime/im/message-bus.js +40 -0
- package/lib/plugin-runtime/im/message-dispatcher.d.ts +18 -0
- package/lib/plugin-runtime/im/message-dispatcher.js +107 -0
- package/lib/plugin-runtime/im/outbound-renderer.d.ts +7 -0
- package/lib/plugin-runtime/im/outbound-renderer.js +70 -0
- package/lib/plugin-runtime/im/outbound-segments.d.ts +72 -0
- package/lib/plugin-runtime/im/outbound-segments.js +220 -0
- package/lib/plugin-runtime/im/public-api.d.ts +6 -0
- package/lib/plugin-runtime/im/public-api.js +6 -0
- package/lib/plugin-runtime/im/service-tokens.d.ts +18 -0
- package/lib/plugin-runtime/im/service-tokens.js +13 -0
- package/lib/plugin.d.ts +34 -24
- package/lib/plugin.js +119 -224
- package/lib/request.d.ts +17 -61
- package/lib/request.js +0 -4
- package/lib/{prompt.d.ts → schema-interaction.d.ts} +6 -7
- package/lib/{prompt.js → schema-interaction.js} +20 -17
- package/lib/side-event/base.d.ts +52 -0
- package/lib/side-event/base.js +30 -0
- package/lib/side-event/dispatch.d.ts +15 -0
- package/lib/side-event/dispatch.js +140 -0
- package/lib/side-event/index.d.ts +4 -0
- package/lib/side-event/index.js +4 -0
- package/lib/side-event/normalize.d.ts +42 -0
- package/lib/side-event/normalize.js +121 -0
- package/lib/side-event/types.d.ts +23 -0
- package/lib/side-event/types.js +55 -0
- package/lib/system-event.d.ts +15 -0
- package/lib/system-event.js +7 -0
- package/lib/tool-zod.d.ts +18 -3
- package/lib/tool-zod.js +140 -54
- package/lib/types.d.ts +44 -85
- package/lib/types.js +0 -1
- package/lib/utils.d.ts +68 -1
- package/lib/utils.js +73 -11
- package/package.json +98 -10
- package/lib/adapter.d.ts.map +0 -1
- package/lib/adapter.js.map +0 -1
- package/lib/agent-prompt.d.ts +0 -37
- package/lib/agent-prompt.d.ts.map +0 -1
- package/lib/agent-prompt.js +0 -2
- package/lib/agent-prompt.js.map +0 -1
- package/lib/bot.d.ts +0 -38
- package/lib/bot.d.ts.map +0 -1
- package/lib/bot.js +0 -2
- package/lib/bot.js.map +0 -1
- package/lib/built/adapter-process.d.ts.map +0 -1
- package/lib/built/adapter-process.js.map +0 -1
- package/lib/built/agent-preset.d.ts.map +0 -1
- package/lib/built/agent-preset.js.map +0 -1
- package/lib/built/ai-trigger.d.ts.map +0 -1
- package/lib/built/ai-trigger.js.map +0 -1
- package/lib/built/command.d.ts.map +0 -1
- package/lib/built/command.js.map +0 -1
- package/lib/built/common-adapter-tools.d.ts.map +0 -1
- package/lib/built/common-adapter-tools.js.map +0 -1
- package/lib/built/component.d.ts.map +0 -1
- package/lib/built/component.js.map +0 -1
- package/lib/built/config.d.ts.map +0 -1
- package/lib/built/config.js.map +0 -1
- package/lib/built/cron.d.ts +0 -75
- package/lib/built/cron.d.ts.map +0 -1
- package/lib/built/cron.js +0 -122
- package/lib/built/cron.js.map +0 -1
- package/lib/built/database.d.ts.map +0 -1
- package/lib/built/database.js.map +0 -1
- package/lib/built/dispatcher.d.ts.map +0 -1
- package/lib/built/dispatcher.js.map +0 -1
- package/lib/built/html-to-text.d.ts.map +0 -1
- package/lib/built/html-to-text.js.map +0 -1
- package/lib/built/inbound-runner.d.ts.map +0 -1
- package/lib/built/inbound-runner.js.map +0 -1
- package/lib/built/login-assist.d.ts.map +0 -1
- package/lib/built/login-assist.js.map +0 -1
- package/lib/built/message-filter.d.ts.map +0 -1
- package/lib/built/message-filter.js.map +0 -1
- package/lib/built/permission.d.ts.map +0 -1
- package/lib/built/permission.js.map +0 -1
- package/lib/built/prepend-quote-context.d.ts +0 -33
- package/lib/built/prepend-quote-context.d.ts.map +0 -1
- package/lib/built/prepend-quote-context.js +0 -129
- package/lib/built/prepend-quote-context.js.map +0 -1
- package/lib/built/queue-im-field-contract.d.ts.map +0 -1
- package/lib/built/queue-im-field-contract.js.map +0 -1
- package/lib/built/roles.d.ts.map +0 -1
- package/lib/built/roles.js.map +0 -1
- package/lib/built/runtime-io.d.ts.map +0 -1
- package/lib/built/runtime-io.js.map +0 -1
- package/lib/built/schema-feature.d.ts.map +0 -1
- package/lib/built/schema-feature.js.map +0 -1
- package/lib/built/skill.d.ts.map +0 -1
- package/lib/built/skill.js.map +0 -1
- package/lib/built/tool.d.ts.map +0 -1
- package/lib/built/tool.js.map +0 -1
- package/lib/command.d.ts.map +0 -1
- package/lib/command.js.map +0 -1
- package/lib/component.d.ts.map +0 -1
- package/lib/component.js.map +0 -1
- package/lib/errors.d.ts.map +0 -1
- package/lib/errors.js.map +0 -1
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/jsx-dev-runtime.d.ts.map +0 -1
- package/lib/jsx-dev-runtime.js.map +0 -1
- package/lib/jsx-runtime.d.ts.map +0 -1
- package/lib/jsx-runtime.js.map +0 -1
- package/lib/jsx.d.ts.map +0 -1
- package/lib/jsx.js.map +0 -1
- package/lib/message-quote.d.ts +0 -11
- package/lib/message-quote.d.ts.map +0 -1
- package/lib/message-quote.js +0 -91
- package/lib/message-quote.js.map +0 -1
- package/lib/message.d.ts.map +0 -1
- package/lib/message.js.map +0 -1
- package/lib/models/system-log.d.ts.map +0 -1
- package/lib/models/system-log.js.map +0 -1
- package/lib/models/user.d.ts.map +0 -1
- package/lib/models/user.js.map +0 -1
- package/lib/notice.d.ts.map +0 -1
- package/lib/notice.js.map +0 -1
- package/lib/plugin.d.ts.map +0 -1
- package/lib/plugin.js.map +0 -1
- package/lib/prompt.d.ts.map +0 -1
- package/lib/prompt.js.map +0 -1
- package/lib/request.d.ts.map +0 -1
- package/lib/request.js.map +0 -1
- package/lib/scheduler/scheduler.d.ts +0 -49
- package/lib/scheduler/scheduler.d.ts.map +0 -1
- package/lib/scheduler/scheduler.js +0 -352
- package/lib/scheduler/scheduler.js.map +0 -1
- package/lib/scheduler/types.d.ts +0 -71
- package/lib/scheduler/types.d.ts.map +0 -1
- package/lib/scheduler/types.js +0 -8
- package/lib/scheduler/types.js.map +0 -1
- package/lib/tool-zod.d.ts.map +0 -1
- package/lib/tool-zod.js.map +0 -1
- package/lib/types-generator.d.ts +0 -6
- package/lib/types-generator.d.ts.map +0 -1
- package/lib/types-generator.js +0 -72
- package/lib/types-generator.js.map +0 -1
- package/lib/types.d.ts.map +0 -1
- package/lib/types.js.map +0 -1
- package/lib/utils.d.ts.map +0 -1
- package/lib/utils.js.map +0 -1
|
@@ -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 { isMediaRef } from './validate.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 = isMediaRef(data.media) ? data.media : undefined;
|
|
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,7 @@
|
|
|
1
|
+
import type { Segment } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* 提取纯文本视图:text 段原文拼接,mention/at 段渲染为 `@name`(无名回退
|
|
4
|
+
* `@target`,`all` → `@all`);其余段类型不产生文本(媒体 / 回复等结构化
|
|
5
|
+
* 信息经 `segments` 轨道消费,不污染命令输入)。
|
|
6
|
+
*/
|
|
7
|
+
export declare function segmentsToPlainText(segments: readonly Segment[]): string;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Canonical Segment[] → 纯文本视图(SSOT)。
|
|
3
|
+
* 入站双轨:结构化段为唯一内部契约,纯文本视图供命令匹配 / AI 兜底消费。
|
|
4
|
+
* @see docs/architecture/segment-content-model.md
|
|
5
|
+
*/
|
|
6
|
+
import { readMentionName, readMentionTarget } from './mention.js';
|
|
7
|
+
/**
|
|
8
|
+
* 提取纯文本视图:text 段原文拼接,mention/at 段渲染为 `@name`(无名回退
|
|
9
|
+
* `@target`,`all` → `@all`);其余段类型不产生文本(媒体 / 回复等结构化
|
|
10
|
+
* 信息经 `segments` 轨道消费,不污染命令输入)。
|
|
11
|
+
*/
|
|
12
|
+
export function segmentsToPlainText(segments) {
|
|
13
|
+
let out = '';
|
|
14
|
+
for (const segment of segments) {
|
|
15
|
+
// Segment 含 SegmentBase 兜底成员,type 窄化不能联动窄化 data,统一按字典读
|
|
16
|
+
const data = segment.data;
|
|
17
|
+
if (segment.type === 'text') {
|
|
18
|
+
if (typeof data.text === 'string')
|
|
19
|
+
out += data.text;
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
if (segment.type === 'mention' || segment.type === 'at') {
|
|
23
|
+
const name = readMentionName(data);
|
|
24
|
+
if (name) {
|
|
25
|
+
out += `@${name}`;
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
const target = readMentionTarget(data);
|
|
29
|
+
if (target)
|
|
30
|
+
out += `@${target}`;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return out;
|
|
34
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/** Canonical Segment SSOT lives in @zhin.js/im-contract. */
|
|
2
|
+
import type { MediaRef, SegmentBase } from '@zhin.js/im-contract';
|
|
3
|
+
export type { ForwardSegment, MediaRef, MentionSegment, ReplySegment, Segment, SegmentBase, TextSegment, } from '@zhin.js/im-contract';
|
|
4
|
+
/**
|
|
5
|
+
* 媒体引用占位(全框架唯一媒体表达)。
|
|
6
|
+
* kind=file:平台侧不透明文件引用(如 Telegram file_id、Milky resource_id),
|
|
7
|
+
* 非 URL/本地路径,消费方需经平台 API 解析。
|
|
8
|
+
*/
|
|
9
|
+
export interface ImageSegment extends SegmentBase {
|
|
10
|
+
type: 'image';
|
|
11
|
+
data: {
|
|
12
|
+
media: MediaRef;
|
|
13
|
+
alt?: string;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
export interface AudioSegment extends SegmentBase {
|
|
17
|
+
type: 'audio';
|
|
18
|
+
data: {
|
|
19
|
+
media: MediaRef;
|
|
20
|
+
duration?: number;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
export interface VideoSegment extends SegmentBase {
|
|
24
|
+
type: 'video';
|
|
25
|
+
data: {
|
|
26
|
+
media: MediaRef;
|
|
27
|
+
duration?: number;
|
|
28
|
+
alt?: string;
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
export interface FileSegment extends SegmentBase {
|
|
32
|
+
type: 'file';
|
|
33
|
+
data: {
|
|
34
|
+
media: MediaRef;
|
|
35
|
+
name?: string;
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
export interface FaceSegment extends SegmentBase {
|
|
39
|
+
type: 'face';
|
|
40
|
+
data: {
|
|
41
|
+
id: string | number;
|
|
42
|
+
name?: string;
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
export interface DiceSegment extends SegmentBase {
|
|
46
|
+
type: 'dice';
|
|
47
|
+
data: {
|
|
48
|
+
result?: number;
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
export interface RpsSegment extends SegmentBase {
|
|
52
|
+
type: 'rps';
|
|
53
|
+
data: {
|
|
54
|
+
result?: number;
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
/** 规范态 segment(严格校验 text / mention / image / audio / video / file / reply / forward / face / dice / rps) */
|
|
58
|
+
export type LegacySpecificSegment = ImageSegment | AudioSegment | VideoSegment | FileSegment | FaceSegment | DiceSegment | RpsSegment;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
import { Schema } from '@zhin.js/schema';
|
|
2
|
+
import type { MediaRef, Segment } from './types.js';
|
|
3
|
+
export declare const mediaRefSchema: Schema<{
|
|
4
|
+
kind?: any;
|
|
5
|
+
value?: string | undefined;
|
|
6
|
+
mime_type?: string | undefined;
|
|
7
|
+
file_name?: string | undefined;
|
|
8
|
+
size?: number | undefined;
|
|
9
|
+
}, {
|
|
10
|
+
kind?: any;
|
|
11
|
+
value?: string | undefined;
|
|
12
|
+
mime_type?: string | undefined;
|
|
13
|
+
file_name?: string | undefined;
|
|
14
|
+
size?: number | undefined;
|
|
15
|
+
}>;
|
|
16
|
+
export declare const textSegmentSchema: Schema<{
|
|
17
|
+
type?: "text" | undefined;
|
|
18
|
+
data?: {
|
|
19
|
+
text?: string | undefined;
|
|
20
|
+
} | undefined;
|
|
21
|
+
platform?: Record<string, any> | undefined;
|
|
22
|
+
}, {
|
|
23
|
+
type?: "text" | undefined;
|
|
24
|
+
data?: {
|
|
25
|
+
text?: string | undefined;
|
|
26
|
+
} | undefined;
|
|
27
|
+
platform?: Record<string, any> | undefined;
|
|
28
|
+
}>;
|
|
29
|
+
export declare const mentionSegmentSchema: Schema<{
|
|
30
|
+
type?: "mention" | undefined;
|
|
31
|
+
data?: {
|
|
32
|
+
target?: string | undefined;
|
|
33
|
+
name?: string | undefined;
|
|
34
|
+
} | undefined;
|
|
35
|
+
platform?: Record<string, any> | undefined;
|
|
36
|
+
}, {
|
|
37
|
+
type?: "mention" | undefined;
|
|
38
|
+
data?: {
|
|
39
|
+
target?: string | undefined;
|
|
40
|
+
name?: string | undefined;
|
|
41
|
+
} | undefined;
|
|
42
|
+
platform?: Record<string, any> | undefined;
|
|
43
|
+
}>;
|
|
44
|
+
export declare const imageSegmentSchema: Schema<{
|
|
45
|
+
type?: "image" | undefined;
|
|
46
|
+
data?: {
|
|
47
|
+
media?: {
|
|
48
|
+
kind?: any;
|
|
49
|
+
value?: string | undefined;
|
|
50
|
+
mime_type?: string | undefined;
|
|
51
|
+
file_name?: string | undefined;
|
|
52
|
+
size?: number | undefined;
|
|
53
|
+
} | undefined;
|
|
54
|
+
alt?: string | undefined;
|
|
55
|
+
} | undefined;
|
|
56
|
+
platform?: Record<string, any> | undefined;
|
|
57
|
+
}, {
|
|
58
|
+
type?: "image" | undefined;
|
|
59
|
+
data?: {
|
|
60
|
+
media?: {
|
|
61
|
+
kind?: any;
|
|
62
|
+
value?: string | undefined;
|
|
63
|
+
mime_type?: string | undefined;
|
|
64
|
+
file_name?: string | undefined;
|
|
65
|
+
size?: number | undefined;
|
|
66
|
+
} | undefined;
|
|
67
|
+
alt?: string | undefined;
|
|
68
|
+
} | undefined;
|
|
69
|
+
platform?: Record<string, any> | undefined;
|
|
70
|
+
}>;
|
|
71
|
+
export declare const audioSegmentSchema: Schema<{
|
|
72
|
+
type?: "audio" | undefined;
|
|
73
|
+
data?: {
|
|
74
|
+
media?: {
|
|
75
|
+
kind?: any;
|
|
76
|
+
value?: string | undefined;
|
|
77
|
+
mime_type?: string | undefined;
|
|
78
|
+
file_name?: string | undefined;
|
|
79
|
+
size?: number | undefined;
|
|
80
|
+
} | undefined;
|
|
81
|
+
duration?: number | undefined;
|
|
82
|
+
} | undefined;
|
|
83
|
+
platform?: Record<string, any> | undefined;
|
|
84
|
+
}, {
|
|
85
|
+
type?: "audio" | undefined;
|
|
86
|
+
data?: {
|
|
87
|
+
media?: {
|
|
88
|
+
kind?: any;
|
|
89
|
+
value?: string | undefined;
|
|
90
|
+
mime_type?: string | undefined;
|
|
91
|
+
file_name?: string | undefined;
|
|
92
|
+
size?: number | undefined;
|
|
93
|
+
} | undefined;
|
|
94
|
+
duration?: number | undefined;
|
|
95
|
+
} | undefined;
|
|
96
|
+
platform?: Record<string, any> | undefined;
|
|
97
|
+
}>;
|
|
98
|
+
export declare const videoSegmentSchema: Schema<{
|
|
99
|
+
type?: "video" | undefined;
|
|
100
|
+
data?: {
|
|
101
|
+
media?: {
|
|
102
|
+
kind?: any;
|
|
103
|
+
value?: string | undefined;
|
|
104
|
+
mime_type?: string | undefined;
|
|
105
|
+
file_name?: string | undefined;
|
|
106
|
+
size?: number | undefined;
|
|
107
|
+
} | undefined;
|
|
108
|
+
duration?: number | undefined;
|
|
109
|
+
alt?: string | undefined;
|
|
110
|
+
} | undefined;
|
|
111
|
+
platform?: Record<string, any> | undefined;
|
|
112
|
+
}, {
|
|
113
|
+
type?: "video" | undefined;
|
|
114
|
+
data?: {
|
|
115
|
+
media?: {
|
|
116
|
+
kind?: any;
|
|
117
|
+
value?: string | undefined;
|
|
118
|
+
mime_type?: string | undefined;
|
|
119
|
+
file_name?: string | undefined;
|
|
120
|
+
size?: number | undefined;
|
|
121
|
+
} | undefined;
|
|
122
|
+
duration?: number | undefined;
|
|
123
|
+
alt?: string | undefined;
|
|
124
|
+
} | undefined;
|
|
125
|
+
platform?: Record<string, any> | undefined;
|
|
126
|
+
}>;
|
|
127
|
+
export declare const fileSegmentSchema: Schema<{
|
|
128
|
+
type?: "file" | undefined;
|
|
129
|
+
data?: {
|
|
130
|
+
media?: {
|
|
131
|
+
kind?: any;
|
|
132
|
+
value?: string | undefined;
|
|
133
|
+
mime_type?: string | undefined;
|
|
134
|
+
file_name?: string | undefined;
|
|
135
|
+
size?: number | undefined;
|
|
136
|
+
} | undefined;
|
|
137
|
+
name?: string | undefined;
|
|
138
|
+
} | undefined;
|
|
139
|
+
platform?: Record<string, any> | undefined;
|
|
140
|
+
}, {
|
|
141
|
+
type?: "file" | undefined;
|
|
142
|
+
data?: {
|
|
143
|
+
media?: {
|
|
144
|
+
kind?: any;
|
|
145
|
+
value?: string | undefined;
|
|
146
|
+
mime_type?: string | undefined;
|
|
147
|
+
file_name?: string | undefined;
|
|
148
|
+
size?: number | undefined;
|
|
149
|
+
} | undefined;
|
|
150
|
+
name?: string | undefined;
|
|
151
|
+
} | undefined;
|
|
152
|
+
platform?: Record<string, any> | undefined;
|
|
153
|
+
}>;
|
|
154
|
+
export declare const replySegmentSchema: Schema<{
|
|
155
|
+
type?: "reply" | undefined;
|
|
156
|
+
data?: {
|
|
157
|
+
message_id?: string | undefined;
|
|
158
|
+
} | undefined;
|
|
159
|
+
platform?: Record<string, any> | undefined;
|
|
160
|
+
}, {
|
|
161
|
+
type?: "reply" | undefined;
|
|
162
|
+
data?: {
|
|
163
|
+
message_id?: string | undefined;
|
|
164
|
+
} | undefined;
|
|
165
|
+
platform?: Record<string, any> | undefined;
|
|
166
|
+
}>;
|
|
167
|
+
export declare const forwardSegmentSchema: Schema<{
|
|
168
|
+
type?: "forward" | undefined;
|
|
169
|
+
data?: {
|
|
170
|
+
forward_id?: string | undefined;
|
|
171
|
+
title?: string | undefined;
|
|
172
|
+
messages?: any[][] | undefined;
|
|
173
|
+
} | undefined;
|
|
174
|
+
platform?: Record<string, any> | undefined;
|
|
175
|
+
}, {
|
|
176
|
+
type?: "forward" | undefined;
|
|
177
|
+
data?: {
|
|
178
|
+
forward_id?: string | undefined;
|
|
179
|
+
title?: string | undefined;
|
|
180
|
+
messages?: any[][] | undefined;
|
|
181
|
+
} | undefined;
|
|
182
|
+
platform?: Record<string, any> | undefined;
|
|
183
|
+
}>;
|
|
184
|
+
export declare const faceSegmentSchema: Schema<{
|
|
185
|
+
type?: "face" | undefined;
|
|
186
|
+
data?: {
|
|
187
|
+
id?: any;
|
|
188
|
+
name?: string | undefined;
|
|
189
|
+
} | undefined;
|
|
190
|
+
platform?: Record<string, any> | undefined;
|
|
191
|
+
}, {
|
|
192
|
+
type?: "face" | undefined;
|
|
193
|
+
data?: {
|
|
194
|
+
id?: any;
|
|
195
|
+
name?: string | undefined;
|
|
196
|
+
} | undefined;
|
|
197
|
+
platform?: Record<string, any> | undefined;
|
|
198
|
+
}>;
|
|
199
|
+
export declare const diceSegmentSchema: Schema<{
|
|
200
|
+
type?: "dice" | undefined;
|
|
201
|
+
data?: {
|
|
202
|
+
result?: number | undefined;
|
|
203
|
+
} | undefined;
|
|
204
|
+
platform?: Record<string, any> | undefined;
|
|
205
|
+
}, {
|
|
206
|
+
type?: "dice" | undefined;
|
|
207
|
+
data?: {
|
|
208
|
+
result?: number | undefined;
|
|
209
|
+
} | undefined;
|
|
210
|
+
platform?: Record<string, any> | undefined;
|
|
211
|
+
}>;
|
|
212
|
+
export declare const rpsSegmentSchema: Schema<{
|
|
213
|
+
type?: "rps" | undefined;
|
|
214
|
+
data?: {
|
|
215
|
+
result?: number | undefined;
|
|
216
|
+
} | undefined;
|
|
217
|
+
platform?: Record<string, any> | undefined;
|
|
218
|
+
}, {
|
|
219
|
+
type?: "rps" | undefined;
|
|
220
|
+
data?: {
|
|
221
|
+
result?: number | undefined;
|
|
222
|
+
} | undefined;
|
|
223
|
+
platform?: Record<string, any> | undefined;
|
|
224
|
+
}>;
|
|
225
|
+
export declare const canonicalSegmentSchema: Schema<any, any>;
|
|
226
|
+
export declare const segmentArraySchema: Schema<any[], any[]>;
|
|
227
|
+
export declare function isMediaRef(value: unknown): value is MediaRef;
|
|
228
|
+
/** 严格 canonical 段校验(@zhin.js/schema validate-only) */
|
|
229
|
+
export declare function isStrictCanonicalSegment(value: unknown): value is Segment;
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { Schema } from '@zhin.js/schema';
|
|
2
|
+
const platformSchema = Schema.dict(Schema.any());
|
|
3
|
+
const mediaKindSchema = Schema.union([
|
|
4
|
+
Schema.const('url'),
|
|
5
|
+
Schema.const('path'),
|
|
6
|
+
Schema.const('base64'),
|
|
7
|
+
Schema.const('file'),
|
|
8
|
+
]);
|
|
9
|
+
export const mediaRefSchema = Schema.object({
|
|
10
|
+
kind: mediaKindSchema.required(),
|
|
11
|
+
value: Schema.string().required(),
|
|
12
|
+
mime_type: Schema.string(),
|
|
13
|
+
file_name: Schema.string(),
|
|
14
|
+
size: Schema.number(),
|
|
15
|
+
});
|
|
16
|
+
export const textSegmentSchema = Schema.object({
|
|
17
|
+
type: Schema.const('text'),
|
|
18
|
+
data: Schema.object({ text: Schema.string().required() }).required(),
|
|
19
|
+
platform: platformSchema,
|
|
20
|
+
});
|
|
21
|
+
export const mentionSegmentSchema = Schema.object({
|
|
22
|
+
type: Schema.const('mention'),
|
|
23
|
+
data: Schema.object({
|
|
24
|
+
target: Schema.string().required(),
|
|
25
|
+
name: Schema.string(),
|
|
26
|
+
}).required(),
|
|
27
|
+
platform: platformSchema,
|
|
28
|
+
});
|
|
29
|
+
export const imageSegmentSchema = Schema.object({
|
|
30
|
+
type: Schema.const('image'),
|
|
31
|
+
data: Schema.object({
|
|
32
|
+
media: mediaRefSchema.required(),
|
|
33
|
+
alt: Schema.string(),
|
|
34
|
+
}).required(),
|
|
35
|
+
platform: platformSchema,
|
|
36
|
+
});
|
|
37
|
+
export const audioSegmentSchema = Schema.object({
|
|
38
|
+
type: Schema.const('audio'),
|
|
39
|
+
data: Schema.object({
|
|
40
|
+
media: mediaRefSchema.required(),
|
|
41
|
+
duration: Schema.number(),
|
|
42
|
+
}).required(),
|
|
43
|
+
platform: platformSchema,
|
|
44
|
+
});
|
|
45
|
+
export const videoSegmentSchema = Schema.object({
|
|
46
|
+
type: Schema.const('video'),
|
|
47
|
+
data: Schema.object({
|
|
48
|
+
media: mediaRefSchema.required(),
|
|
49
|
+
duration: Schema.number(),
|
|
50
|
+
alt: Schema.string(),
|
|
51
|
+
}).required(),
|
|
52
|
+
platform: platformSchema,
|
|
53
|
+
});
|
|
54
|
+
export const fileSegmentSchema = Schema.object({
|
|
55
|
+
type: Schema.const('file'),
|
|
56
|
+
data: Schema.object({
|
|
57
|
+
media: mediaRefSchema.required(),
|
|
58
|
+
name: Schema.string(),
|
|
59
|
+
}).required(),
|
|
60
|
+
platform: platformSchema,
|
|
61
|
+
});
|
|
62
|
+
export const replySegmentSchema = Schema.object({
|
|
63
|
+
type: Schema.const('reply'),
|
|
64
|
+
data: Schema.object({ message_id: Schema.string().required() }).required(),
|
|
65
|
+
platform: platformSchema,
|
|
66
|
+
});
|
|
67
|
+
export const forwardSegmentSchema = Schema.object({
|
|
68
|
+
type: Schema.const('forward'),
|
|
69
|
+
data: Schema.object({
|
|
70
|
+
forward_id: Schema.string().required(),
|
|
71
|
+
title: Schema.string(),
|
|
72
|
+
messages: Schema.list(Schema.list(Schema.any())),
|
|
73
|
+
}).required(),
|
|
74
|
+
platform: platformSchema,
|
|
75
|
+
});
|
|
76
|
+
const stringOrNumberSchema = Schema.union([
|
|
77
|
+
Schema.string(),
|
|
78
|
+
Schema.number(),
|
|
79
|
+
]);
|
|
80
|
+
export const faceSegmentSchema = Schema.object({
|
|
81
|
+
type: Schema.const('face'),
|
|
82
|
+
data: Schema.object({
|
|
83
|
+
id: stringOrNumberSchema.required(),
|
|
84
|
+
name: Schema.string(),
|
|
85
|
+
}).required(),
|
|
86
|
+
platform: platformSchema,
|
|
87
|
+
});
|
|
88
|
+
export const diceSegmentSchema = Schema.object({
|
|
89
|
+
type: Schema.const('dice'),
|
|
90
|
+
data: Schema.object({ result: Schema.number() }).required(),
|
|
91
|
+
platform: platformSchema,
|
|
92
|
+
});
|
|
93
|
+
export const rpsSegmentSchema = Schema.object({
|
|
94
|
+
type: Schema.const('rps'),
|
|
95
|
+
data: Schema.object({ result: Schema.number() }).required(),
|
|
96
|
+
platform: platformSchema,
|
|
97
|
+
});
|
|
98
|
+
export const canonicalSegmentSchema = Schema.discriminatedUnion('type', {
|
|
99
|
+
text: {
|
|
100
|
+
data: Schema.object({ text: Schema.string().required() }).required(),
|
|
101
|
+
platform: platformSchema,
|
|
102
|
+
},
|
|
103
|
+
mention: {
|
|
104
|
+
data: Schema.object({
|
|
105
|
+
target: Schema.string().required(),
|
|
106
|
+
name: Schema.string(),
|
|
107
|
+
}).required(),
|
|
108
|
+
platform: platformSchema,
|
|
109
|
+
},
|
|
110
|
+
image: {
|
|
111
|
+
data: Schema.object({
|
|
112
|
+
media: mediaRefSchema.required(),
|
|
113
|
+
alt: Schema.string(),
|
|
114
|
+
}).required(),
|
|
115
|
+
platform: platformSchema,
|
|
116
|
+
},
|
|
117
|
+
audio: {
|
|
118
|
+
data: Schema.object({
|
|
119
|
+
media: mediaRefSchema.required(),
|
|
120
|
+
duration: Schema.number(),
|
|
121
|
+
}).required(),
|
|
122
|
+
platform: platformSchema,
|
|
123
|
+
},
|
|
124
|
+
video: {
|
|
125
|
+
data: Schema.object({
|
|
126
|
+
media: mediaRefSchema.required(),
|
|
127
|
+
duration: Schema.number(),
|
|
128
|
+
alt: Schema.string(),
|
|
129
|
+
}).required(),
|
|
130
|
+
platform: platformSchema,
|
|
131
|
+
},
|
|
132
|
+
file: {
|
|
133
|
+
data: Schema.object({
|
|
134
|
+
media: mediaRefSchema.required(),
|
|
135
|
+
name: Schema.string(),
|
|
136
|
+
}).required(),
|
|
137
|
+
platform: platformSchema,
|
|
138
|
+
},
|
|
139
|
+
reply: {
|
|
140
|
+
data: Schema.object({ message_id: Schema.string().required() }).required(),
|
|
141
|
+
platform: platformSchema,
|
|
142
|
+
},
|
|
143
|
+
forward: {
|
|
144
|
+
data: Schema.object({
|
|
145
|
+
forward_id: Schema.string().required(),
|
|
146
|
+
title: Schema.string(),
|
|
147
|
+
messages: Schema.list(Schema.list(Schema.any())),
|
|
148
|
+
}).required(),
|
|
149
|
+
platform: platformSchema,
|
|
150
|
+
},
|
|
151
|
+
face: {
|
|
152
|
+
data: Schema.object({
|
|
153
|
+
id: stringOrNumberSchema.required(),
|
|
154
|
+
name: Schema.string(),
|
|
155
|
+
}).required(),
|
|
156
|
+
platform: platformSchema,
|
|
157
|
+
},
|
|
158
|
+
dice: {
|
|
159
|
+
data: Schema.object({ result: Schema.number() }).required(),
|
|
160
|
+
platform: platformSchema,
|
|
161
|
+
},
|
|
162
|
+
rps: {
|
|
163
|
+
data: Schema.object({ result: Schema.number() }).required(),
|
|
164
|
+
platform: platformSchema,
|
|
165
|
+
},
|
|
166
|
+
});
|
|
167
|
+
export const segmentArraySchema = Schema.list(canonicalSegmentSchema);
|
|
168
|
+
export function isMediaRef(value) {
|
|
169
|
+
return mediaRefSchema.safeParse(value).success;
|
|
170
|
+
}
|
|
171
|
+
/** 严格 canonical 段校验(@zhin.js/schema validate-only) */
|
|
172
|
+
export function isStrictCanonicalSegment(value) {
|
|
173
|
+
return canonicalSegmentSchema.safeParse(value).success;
|
|
174
|
+
}
|
package/lib/built/skill.d.ts
CHANGED
package/lib/built/skill.js
CHANGED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { SpeechPipelineForRichSegment } from './rich-segments/types.js';
|
|
2
|
+
/** 动态 import 时使用的包名(与 @zhin.js/speech package.json 一致) */
|
|
3
|
+
export declare const SPEECH_PACKAGE = "@zhin.js/speech";
|
|
4
|
+
export interface LoadSpeechPipelineOptions {
|
|
5
|
+
getConfig?: () => Record<string, unknown> | undefined;
|
|
6
|
+
warn?: (message: string) => void;
|
|
7
|
+
}
|
|
8
|
+
/** zhin 启动时已创建 pipeline 时注入 */
|
|
9
|
+
export declare function seedSpeechPipeline(pipeline: SpeechPipelineForRichSegment): void;
|
|
10
|
+
/** 动态加载 @zhin.js/speech;未安装时 warn 一次并返回 undefined */
|
|
11
|
+
export declare function loadSpeechPipeline(opts?: LoadSpeechPipelineOptions): Promise<SpeechPipelineForRichSegment | undefined>;
|
|
12
|
+
/** 测试用:重置加载缓存 */
|
|
13
|
+
export declare function resetSpeechLoaderForTests(): void;
|
|
14
|
+
export type { SpeechPipelineForRichSegment };
|