@zhin.js/core 1.5.15 → 1.6.0
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 +78 -195
- package/lib/ai-completion-contract.d.ts +135 -0
- package/lib/ai-completion-contract.js +69 -0
- package/lib/built/ai-access.d.ts +2 -21
- package/lib/built/ai-access.js +1 -46
- package/lib/built/ai-outbound/index.d.ts +0 -2
- package/lib/built/ai-outbound/index.js +0 -2
- package/lib/built/ai-outbound/prompt.d.ts +2 -0
- package/lib/built/ai-outbound/prompt.js +2 -0
- package/lib/built/ai-outbound/types.d.ts +1 -10
- package/lib/built/ai-trigger.d.ts +39 -78
- package/lib/built/ai-trigger.js +3 -254
- package/lib/built/common-adapter-tools.d.ts +21 -6
- package/lib/built/common-adapter-tools.js +28 -17
- package/lib/built/generic-segment-mapper.js +4 -1
- package/lib/built/html-segment-fallback.d.ts +6 -7
- package/lib/built/html-segment-fallback.js +1 -16
- package/lib/built/html-to-text.d.ts +0 -3
- package/lib/built/html-to-text.js +131 -40
- package/lib/built/interaction-messages.d.ts +1 -0
- package/lib/built/interaction-messages.js +30 -0
- package/lib/built/interactive-segments/action.d.ts +3 -4
- package/lib/built/interactive-segments/action.js +2 -5
- package/lib/built/interactive-segments/index.d.ts +0 -2
- package/lib/built/interactive-segments/index.js +0 -2
- package/lib/built/interactive-segments/keyboard-segment.d.ts +0 -1
- package/lib/built/interactive-segments/keyboard-segment.js +0 -1
- package/lib/built/interactive-segments/onebot-keyboard.d.ts +0 -1
- package/lib/built/interactive-segments/onebot-keyboard.js +0 -2
- package/lib/built/interactive-segments/resolve.d.ts +2 -3
- package/lib/built/interactive-segments/resolve.js +21 -14
- package/lib/built/interactive-segments/types.d.ts +2 -7
- package/lib/built/interactive-segments/types.js +22 -2
- package/lib/built/login-assist.d.ts +13 -11
- package/lib/built/login-assist.js +32 -26
- package/lib/built/message-enrich.d.ts +24 -27
- package/lib/built/message-enrich.js +53 -49
- package/lib/built/outbound-content-arrays.d.ts +4 -0
- package/lib/built/outbound-content-arrays.js +32 -0
- package/lib/built/outbound-media-trust.d.ts +46 -0
- package/lib/built/outbound-media-trust.js +245 -0
- package/lib/built/outbound-media-utils.d.ts +5 -3
- package/lib/built/outbound-media-utils.js +5 -3
- package/lib/built/readable-link.d.ts +4 -0
- package/lib/built/readable-link.js +32 -0
- package/lib/built/rich-segments/markdown-to-text.d.ts +1 -2
- package/lib/built/rich-segments/markdown-to-text.js +141 -17
- package/lib/built/roles.d.ts +141 -12
- package/lib/built/roles.js +253 -52
- package/lib/built/segment-contract/assert.js +8 -2
- package/lib/built/segment-contract/delivery.js +1 -0
- package/lib/built/segment-contract/index.d.ts +3 -3
- package/lib/built/segment-contract/index.js +2 -2
- package/lib/built/segment-contract/json-schema.d.ts +39 -5
- package/lib/built/segment-contract/json-schema.js +207 -24
- package/lib/built/segment-contract/preview.js +8 -1
- package/lib/built/segment-contract/text.js +1 -1
- package/lib/built/segment-contract/types.d.ts +2 -2
- package/lib/built/segment-contract/validate.d.ts +1553 -224
- package/lib/built/segment-contract/validate.js +39 -3
- package/lib/built/tool-access.d.ts +5 -0
- package/lib/built/tool-access.js +17 -0
- package/lib/built/user-interaction.d.ts +5 -4
- package/lib/built/user-interaction.js +64 -52
- package/lib/errors.d.ts +1 -18
- package/lib/errors.js +1 -26
- package/lib/feature/command-public-api.d.ts +5 -0
- package/lib/feature/command-public-api.js +5 -0
- package/lib/feature/command.d.ts +2 -0
- package/lib/feature/command.js +1 -0
- package/lib/feature/component.d.ts +1 -0
- package/lib/feature/component.js +1 -0
- package/lib/feature/handler.d.ts +13 -7
- package/lib/feature/handler.js +2 -1
- package/lib/feature/middleware-public-api.d.ts +6 -0
- package/lib/feature/middleware-public-api.js +6 -0
- package/lib/feature/middleware.d.ts +22 -2
- package/lib/feature/middleware.js +7 -2
- package/lib/im-scene.d.ts +4 -3
- package/lib/im-scene.js +9 -9
- package/lib/im-session-id.d.ts +20 -12
- package/lib/im-session-id.js +8 -8
- package/lib/index.d.ts +19 -48
- package/lib/index.js +14 -41
- package/lib/jsx/intrinsic-elements.d.ts +83 -0
- package/lib/jsx/message-renderer.d.ts +13 -0
- package/lib/jsx/message-renderer.js +128 -0
- package/lib/jsx/message-tags.d.ts +133 -0
- package/lib/jsx/message-tags.js +50 -0
- package/lib/jsx-dev-runtime.d.ts +2 -2
- package/lib/jsx-dev-runtime.js +1 -2
- package/lib/jsx-runtime.d.ts +2 -12
- package/lib/jsx-runtime.js +1 -10
- package/lib/jsx.d.ts +6 -30
- package/lib/jsx.js +3 -93
- package/lib/message.d.ts +0 -40
- package/lib/message.js +1 -27
- package/lib/models/system-log.d.ts +0 -2
- package/lib/models/system-log.js +1 -8
- package/lib/models/user.d.ts +0 -2
- package/lib/models/user.js +1 -7
- package/lib/notice.d.ts +38 -33
- package/lib/notice.js +23 -7
- package/lib/plugin-runtime/im/command-feedback.d.ts +59 -0
- package/lib/plugin-runtime/im/command-feedback.js +148 -0
- package/lib/plugin-runtime/im/contracts.d.ts +217 -32
- package/lib/plugin-runtime/im/contracts.js +141 -23
- package/lib/plugin-runtime/im/conversation-runtime.d.ts +42 -0
- package/lib/plugin-runtime/im/conversation-runtime.js +451 -0
- package/lib/plugin-runtime/im/endpoint-runtime.d.ts +89 -0
- package/lib/plugin-runtime/im/endpoint-runtime.js +381 -0
- package/lib/plugin-runtime/im/feature-gate.d.ts +21 -0
- package/lib/plugin-runtime/im/feature-gate.js +88 -0
- package/lib/plugin-runtime/im/host/component-host-installer.d.ts +2 -0
- package/lib/plugin-runtime/im/host/component-host-installer.js +14 -0
- package/lib/plugin-runtime/im/host/conversation-migration.d.ts +5 -0
- package/lib/plugin-runtime/im/host/conversation-migration.js +75 -0
- package/lib/plugin-runtime/im/host/database-config.d.ts +10 -0
- package/lib/plugin-runtime/im/host/database-config.js +114 -0
- package/lib/plugin-runtime/im/host/database-host-installer.d.ts +29 -0
- package/lib/plugin-runtime/im/host/database-host-installer.js +442 -0
- package/lib/plugin-runtime/im/host/database-state.d.ts +9 -0
- package/lib/plugin-runtime/im/host/database-state.js +91 -0
- package/lib/plugin-runtime/im/host/index.d.ts +8 -0
- package/lib/plugin-runtime/im/host/index.js +8 -0
- package/lib/plugin-runtime/im/host/locale-host-installer.d.ts +3 -0
- package/lib/plugin-runtime/im/host/locale-host-installer.js +60 -0
- package/lib/plugin-runtime/im/host/outbound-host-installer.d.ts +8 -0
- package/lib/plugin-runtime/im/host/outbound-host-installer.js +153 -0
- package/lib/plugin-runtime/im/host/sender-enrichment.d.ts +34 -0
- package/lib/plugin-runtime/im/host/sender-enrichment.js +82 -0
- package/lib/plugin-runtime/im/im-runtime.d.ts +40 -111
- package/lib/plugin-runtime/im/im-runtime.js +234 -1059
- package/lib/plugin-runtime/im/inbound-dedup.d.ts +84 -0
- package/lib/plugin-runtime/im/inbound-dedup.js +322 -0
- package/lib/plugin-runtime/im/inbound-origin.d.ts +150 -0
- package/lib/plugin-runtime/im/inbound-origin.js +183 -0
- package/lib/plugin-runtime/im/inbound-runtime.d.ts +59 -0
- package/lib/plugin-runtime/im/inbound-runtime.js +478 -0
- package/lib/plugin-runtime/im/inbound-spine.d.ts +196 -0
- package/lib/plugin-runtime/im/inbound-spine.js +335 -0
- package/lib/plugin-runtime/im/index.d.ts +15 -4
- package/lib/plugin-runtime/im/index.js +11 -4
- package/lib/plugin-runtime/im/interaction-runtime.d.ts +50 -0
- package/lib/plugin-runtime/im/interaction-runtime.js +390 -0
- package/lib/plugin-runtime/im/interactive-router.d.ts +81 -0
- package/lib/plugin-runtime/im/interactive-router.js +382 -0
- package/lib/plugin-runtime/im/message-diagnostics.d.ts +70 -0
- package/lib/plugin-runtime/im/message-diagnostics.js +182 -0
- package/lib/plugin-runtime/im/message-dispatcher.d.ts +18 -4
- package/lib/plugin-runtime/im/message-dispatcher.js +138 -20
- package/lib/plugin-runtime/im/message-events.d.ts +85 -0
- package/lib/plugin-runtime/im/message-events.js +113 -0
- package/lib/plugin-runtime/im/outbound-delivery-runtime.d.ts +39 -0
- package/lib/plugin-runtime/im/outbound-delivery-runtime.js +450 -0
- package/lib/plugin-runtime/im/outbound-renderer.d.ts +52 -3
- package/lib/plugin-runtime/im/outbound-renderer.js +188 -8
- package/lib/plugin-runtime/im/outbound-segments.d.ts +29 -5
- package/lib/plugin-runtime/im/outbound-segments.js +130 -36
- package/lib/plugin-runtime/im/progressive-reply.d.ts +58 -0
- package/lib/plugin-runtime/im/progressive-reply.js +501 -0
- package/lib/plugin-runtime/im/public-api.d.ts +1 -1
- package/lib/request.d.ts +27 -36
- package/lib/request.js +14 -6
- package/lib/side-event/base.d.ts +64 -44
- package/lib/side-event/base.js +72 -19
- package/lib/side-event/index.d.ts +1 -1
- package/lib/side-event/index.js +1 -1
- package/lib/side-event/normalize.d.ts +7 -38
- package/lib/side-event/normalize.js +4 -109
- package/lib/side-event/scene-events.d.ts +40 -0
- package/lib/side-event/scene-events.js +147 -0
- package/lib/side-event/types.d.ts +4 -13
- package/lib/side-event/types.js +1 -55
- package/lib/system-event.d.ts +17 -12
- package/lib/system-event.js +8 -6
- package/lib/types.d.ts +23 -167
- package/lib/utils.d.ts +50 -33
- package/lib/utils.js +12 -185
- package/lib/venue/contracts.d.ts +21 -0
- package/lib/venue/contracts.js +3 -0
- package/lib/venue/floor-controller.d.ts +11 -0
- package/lib/venue/floor-controller.js +63 -0
- package/lib/venue/index.d.ts +13 -0
- package/lib/venue/index.js +11 -0
- package/lib/venue/membership-port.d.ts +23 -0
- package/lib/venue/membership-port.js +141 -0
- package/lib/venue/projector.d.ts +38 -0
- package/lib/venue/projector.js +45 -0
- package/lib/venue/registry.d.ts +16 -0
- package/lib/venue/registry.js +63 -0
- package/lib/venue/router.d.ts +19 -0
- package/lib/venue/router.js +101 -0
- package/lib/venue/send-limiter.d.ts +17 -0
- package/lib/venue/send-limiter.js +73 -0
- package/lib/venue/validator.d.ts +6 -0
- package/lib/venue/validator.js +160 -0
- package/package.json +24 -50
- package/lib/adapter.d.ts +0 -145
- package/lib/adapter.js +0 -377
- package/lib/built/adapter-process.d.ts +0 -58
- package/lib/built/adapter-process.js +0 -128
- package/lib/built/agent-preset.d.ts +0 -64
- package/lib/built/agent-preset.js +0 -79
- package/lib/built/ai-outbound/adapter-access.d.ts +0 -3
- package/lib/built/ai-outbound/adapter-access.js +0 -9
- package/lib/built/ai-outbound/extensions/qq-message.d.ts +0 -3
- package/lib/built/ai-outbound/extensions/qq-message.js +0 -23
- package/lib/built/authorization.d.ts +0 -10
- package/lib/built/authorization.js +0 -76
- package/lib/built/command.d.ts +0 -72
- package/lib/built/command.js +0 -105
- package/lib/built/component.d.ts +0 -67
- package/lib/built/component.js +0 -97
- package/lib/built/config.d.ts +0 -98
- package/lib/built/config.js +0 -372
- package/lib/built/connect-endpoint-instance.d.ts +0 -17
- package/lib/built/connect-endpoint-instance.js +0 -42
- package/lib/built/database.d.ts +0 -68
- package/lib/built/database.js +0 -106
- package/lib/built/dispatcher.d.ts +0 -141
- package/lib/built/dispatcher.js +0 -383
- package/lib/built/endpoint-commands.d.ts +0 -3
- package/lib/built/endpoint-commands.js +0 -99
- package/lib/built/endpoint-lifecycle-service.d.ts +0 -28
- package/lib/built/endpoint-lifecycle-service.js +0 -242
- package/lib/built/endpoint-lifecycle.d.ts +0 -27
- package/lib/built/endpoint-lifecycle.js +0 -36
- package/lib/built/endpoint-manager.d.ts +0 -34
- package/lib/built/html-renderer-loader.d.ts +0 -13
- package/lib/built/html-renderer-loader.js +0 -33
- package/lib/built/inbound-pipeline.d.ts +0 -37
- package/lib/built/inbound-pipeline.js +0 -63
- package/lib/built/inbound-runner.d.ts +0 -22
- package/lib/built/inbound-runner.js +0 -34
- package/lib/built/interactive-segment-contract.d.ts +0 -6
- package/lib/built/interactive-segment-contract.js +0 -9
- package/lib/built/interactive-segments/fallback-store.d.ts +0 -29
- package/lib/built/interactive-segments/fallback-store.js +0 -63
- package/lib/built/interactive-segments/handlers.d.ts +0 -16
- package/lib/built/interactive-segments/handlers.js +0 -74
- package/lib/built/introspection-format.d.ts +0 -10
- package/lib/built/introspection-format.js +0 -28
- package/lib/built/management-command-guard.d.ts +0 -15
- package/lib/built/management-command-guard.js +0 -25
- package/lib/built/message-filter.d.ts +0 -176
- package/lib/built/message-filter.js +0 -239
- package/lib/built/optional-peer-import.d.ts +0 -3
- package/lib/built/optional-peer-import.js +0 -33
- package/lib/built/outbound-media-contract.d.ts +0 -22
- package/lib/built/outbound-media-contract.js +0 -10
- package/lib/built/permission.d.ts +0 -51
- package/lib/built/permission.js +0 -99
- package/lib/built/permit-check.d.ts +0 -7
- package/lib/built/permit-check.js +0 -35
- package/lib/built/permit-parse.d.ts +0 -16
- package/lib/built/permit-parse.js +0 -32
- package/lib/built/platform-permit.d.ts +0 -20
- package/lib/built/platform-permit.js +0 -91
- package/lib/built/queue-im-field-contract.d.ts +0 -32
- package/lib/built/queue-im-field-contract.js +0 -67
- package/lib/built/rich-segments/adapter-policies.d.ts +0 -9
- package/lib/built/rich-segments/adapter-policies.js +0 -27
- package/lib/built/rich-segments/base.d.ts +0 -11
- package/lib/built/rich-segments/base.js +0 -24
- package/lib/built/rich-segments/builtins.d.ts +0 -4
- package/lib/built/rich-segments/builtins.js +0 -40
- package/lib/built/rich-segments/capabilities.d.ts +0 -6
- package/lib/built/rich-segments/capabilities.js +0 -38
- package/lib/built/rich-segments/html-segment.d.ts +0 -15
- package/lib/built/rich-segments/html-segment.js +0 -62
- package/lib/built/rich-segments/index.d.ts +0 -13
- package/lib/built/rich-segments/index.js +0 -13
- package/lib/built/rich-segments/markdown-segment.d.ts +0 -14
- package/lib/built/rich-segments/markdown-segment.js +0 -58
- package/lib/built/rich-segments/qrcode-segment.d.ts +0 -18
- package/lib/built/rich-segments/qrcode-segment.js +0 -73
- package/lib/built/rich-segments/registry.d.ts +0 -16
- package/lib/built/rich-segments/registry.js +0 -52
- package/lib/built/rich-segments/resolve.d.ts +0 -5
- package/lib/built/rich-segments/resolve.js +0 -87
- package/lib/built/rich-segments/tts-segment.d.ts +0 -13
- package/lib/built/rich-segments/tts-segment.js +0 -51
- package/lib/built/rich-segments/types.d.ts +0 -79
- package/lib/built/rich-segments/types.js +0 -17
- package/lib/built/runtime-io.d.ts +0 -9
- package/lib/built/runtime-io.js +0 -67
- package/lib/built/schedule.d.ts +0 -54
- package/lib/built/schedule.js +0 -112
- package/lib/built/schema-endpoint-manager.d.ts +0 -17
- package/lib/built/schema-endpoint-manager.js +0 -73
- package/lib/built/schema-feature.d.ts +0 -77
- package/lib/built/schema-feature.js +0 -130
- package/lib/built/skill.d.ts +0 -120
- package/lib/built/skill.js +0 -151
- package/lib/built/speech-loader.d.ts +0 -14
- package/lib/built/speech-loader.js +0 -32
- package/lib/built/tool.d.ts +0 -151
- package/lib/built/tool.js +0 -388
- package/lib/command.d.ts +0 -50
- package/lib/command.js +0 -106
- package/lib/component.d.ts +0 -26
- package/lib/component.js +0 -583
- package/lib/endpoint-capabilities.d.ts +0 -46
- package/lib/endpoint-capabilities.js +0 -55
- package/lib/endpoint.d.ts +0 -19
- package/lib/endpoint.js +0 -3
- package/lib/host-plugin-registry.d.ts +0 -8
- package/lib/host-plugin-registry.js +0 -12
- package/lib/plugin-context.d.ts +0 -27
- package/lib/plugin-context.js +0 -64
- package/lib/plugin-runtime/im/interactive.d.ts +0 -26
- package/lib/plugin-runtime/im/interactive.js +0 -46
- package/lib/plugin-runtime/im/login-assist-host.d.ts +0 -6
- package/lib/plugin-runtime/im/login-assist-host.js +0 -6
- package/lib/plugin-runtime/im/message-bus.d.ts +0 -38
- package/lib/plugin-runtime/im/message-bus.js +0 -40
- package/lib/plugin-runtime/im/service-tokens.d.ts +0 -18
- package/lib/plugin-runtime/im/service-tokens.js +0 -13
- package/lib/plugin.d.ts +0 -268
- package/lib/plugin.js +0 -583
- package/lib/schema-interaction.d.ts +0 -117
- package/lib/schema-interaction.js +0 -247
- package/lib/side-event/dispatch.d.ts +0 -15
- package/lib/side-event/dispatch.js +0 -140
- package/lib/tool-zod.d.ts +0 -43
- package/lib/tool-zod.js +0 -184
- /package/lib/{built/endpoint-manager.js → jsx/intrinsic-elements.js} +0 -0
|
@@ -44,13 +44,29 @@ function strictBranch(type, data) {
|
|
|
44
44
|
function dataObject(properties, required) {
|
|
45
45
|
return { type: 'object', properties, required: [...required], additionalProperties: false };
|
|
46
46
|
}
|
|
47
|
+
/** Interactive extension guards validate known fields while preserving platform-specific extras. */
|
|
48
|
+
function interactiveDataObject(properties, required) {
|
|
49
|
+
return { type: 'object', properties, required: [...required], additionalProperties: true };
|
|
50
|
+
}
|
|
51
|
+
const buttonJsonSchema = interactiveDataObject({
|
|
52
|
+
id: { type: 'string' },
|
|
53
|
+
label: { type: 'string' },
|
|
54
|
+
payload: { type: 'string' },
|
|
55
|
+
disabled: { type: 'boolean' },
|
|
56
|
+
style: { type: 'string', enum: ['primary', 'danger', 'secondary'] },
|
|
57
|
+
mode: { type: 'string', enum: ['callback', 'command'] },
|
|
58
|
+
command: interactiveDataObject({
|
|
59
|
+
enter: { type: 'boolean' },
|
|
60
|
+
reply: { type: 'boolean' },
|
|
61
|
+
}, []),
|
|
62
|
+
}, ['id', 'label', 'payload']);
|
|
47
63
|
/** 宽松分支:未纳入严格契约的段类型,仅约束顶层形状(与 isCanonicalSegment 宽松路径一致) */
|
|
48
64
|
const looseBranch = {
|
|
49
65
|
type: 'object',
|
|
50
66
|
properties: {
|
|
51
67
|
type: {
|
|
52
68
|
type: 'string',
|
|
53
|
-
enum: ['
|
|
69
|
+
enum: ['voice', 'record', 'link', 'markdown', 'html', 'card'],
|
|
54
70
|
},
|
|
55
71
|
data: { type: 'object' },
|
|
56
72
|
platform: platformJsonSchema,
|
|
@@ -60,11 +76,12 @@ const looseBranch = {
|
|
|
60
76
|
};
|
|
61
77
|
/** 严格段类型集合(SSOT:assert.ts STRICT_CANONICAL_TYPES) */
|
|
62
78
|
export const STRICT_OUTBOUND_SEGMENT_TYPES = [
|
|
63
|
-
'text', 'mention', 'image', '
|
|
79
|
+
'text', 'mention', 'image', 'audio', 'video', 'file', 'reply', 'forward',
|
|
80
|
+
'face', 'dice', 'rps', 'share',
|
|
64
81
|
];
|
|
65
82
|
/**
|
|
66
83
|
* 单条 outbound 消息段的 JSON Schema。
|
|
67
|
-
* 严格段镜像 validate.ts
|
|
84
|
+
* 严格段镜像 validate.ts,交互段镜像 interactive-segments/types.ts;其他扩展段走宽松分支。
|
|
68
85
|
*/
|
|
69
86
|
export const outboundSegmentJsonSchema = {
|
|
70
87
|
description: 'zhin 消息段 {type, data, platform?}',
|
|
@@ -80,8 +97,21 @@ export const outboundSegmentJsonSchema = {
|
|
|
80
97
|
media: mediaRefJsonSchema,
|
|
81
98
|
alt: { type: 'string' },
|
|
82
99
|
}, ['media'])),
|
|
100
|
+
strictBranch('audio', dataObject({
|
|
101
|
+
media: mediaRefJsonSchema,
|
|
102
|
+
duration: { type: 'number' },
|
|
103
|
+
}, ['media'])),
|
|
104
|
+
strictBranch('video', dataObject({
|
|
105
|
+
media: mediaRefJsonSchema,
|
|
106
|
+
duration: { type: 'number' },
|
|
107
|
+
alt: { type: 'string' },
|
|
108
|
+
}, ['media'])),
|
|
109
|
+
strictBranch('file', dataObject({
|
|
110
|
+
media: mediaRefJsonSchema,
|
|
111
|
+
name: { type: 'string' },
|
|
112
|
+
}, ['media'])),
|
|
83
113
|
strictBranch('reply', dataObject({
|
|
84
|
-
message_id: { type: 'string', description: '被引用消息的平台消息 id' },
|
|
114
|
+
message_id: { type: 'string', description: '被引用消息的平台消息 id,或消息头里的 m<n> 别名' },
|
|
85
115
|
}, ['message_id'])),
|
|
86
116
|
strictBranch('forward', dataObject({
|
|
87
117
|
forward_id: { type: 'string' },
|
|
@@ -98,31 +128,184 @@ export const outboundSegmentJsonSchema = {
|
|
|
98
128
|
strictBranch('rps', dataObject({
|
|
99
129
|
result: { type: 'number' },
|
|
100
130
|
}, [])),
|
|
131
|
+
strictBranch('share', dataObject({
|
|
132
|
+
url: { type: 'string', description: '分享跳转地址' },
|
|
133
|
+
title: { type: 'string', description: '分享标题' },
|
|
134
|
+
description: { type: 'string', description: '分享摘要' },
|
|
135
|
+
image: { type: 'string', description: '预览图地址' },
|
|
136
|
+
audio: { type: 'string', description: '音频地址' },
|
|
137
|
+
content: { type: 'string', description: '消息列表中的显示文字' },
|
|
138
|
+
artist: { type: 'string', description: '音乐分享的艺术家' },
|
|
139
|
+
duration: { type: 'number', description: '音频时长(秒)' },
|
|
140
|
+
platform: { type: 'string', description: '歌曲所属音乐平台:qq / netease / kugou / kuwo / migu' },
|
|
141
|
+
config: dataObject({
|
|
142
|
+
appid: { type: 'number' },
|
|
143
|
+
package: { type: 'string' },
|
|
144
|
+
sign: { type: 'string' },
|
|
145
|
+
icon: { type: 'string' },
|
|
146
|
+
version: { type: 'string' },
|
|
147
|
+
}, ['appid']),
|
|
148
|
+
}, ['url', 'title'])),
|
|
149
|
+
strictBranch('keyboard', interactiveDataObject({
|
|
150
|
+
rows: { type: 'array', items: { type: 'array', items: buttonJsonSchema } },
|
|
151
|
+
fallback: interactiveDataObject({
|
|
152
|
+
hint: { type: 'string' },
|
|
153
|
+
map: { type: 'object', additionalProperties: { type: 'string' } },
|
|
154
|
+
}, ['hint', 'map']),
|
|
155
|
+
}, ['rows'])),
|
|
156
|
+
strictBranch('action', interactiveDataObject({
|
|
157
|
+
id: { type: 'string' },
|
|
158
|
+
payload: { type: 'string' },
|
|
159
|
+
sourceMessageId: { type: 'string' },
|
|
160
|
+
}, ['id', 'payload'])),
|
|
101
161
|
looseBranch,
|
|
102
162
|
],
|
|
103
163
|
};
|
|
104
164
|
/**
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
*
|
|
165
|
+
* Provider-facing subset of the canonical contract. Only required fields are
|
|
166
|
+
* exposed: strict structured-output providers require closed objects with all
|
|
167
|
+
* properties required. Optional presentation/platform fields belong to renderers
|
|
168
|
+
* and tools, not to model-generated replies.
|
|
108
169
|
*/
|
|
109
|
-
|
|
110
|
-
type
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
170
|
+
function requiredFieldsOnly(schema) {
|
|
171
|
+
if (schema.type === 'object') {
|
|
172
|
+
const required = (schema.required ?? []);
|
|
173
|
+
const properties = schema.properties;
|
|
174
|
+
return {
|
|
175
|
+
type: 'object',
|
|
176
|
+
properties: Object.fromEntries(required.map(key => [key, requiredFieldsOnly(properties[key])])),
|
|
177
|
+
required,
|
|
178
|
+
additionalProperties: false,
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
if (typeof schema.const === 'string')
|
|
182
|
+
return { type: 'string', ...schema };
|
|
183
|
+
return schema;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Segment types a model may author in a final reply. reply / forward / face are
|
|
187
|
+
* left out: they carry platform ids (message, forward, emoji) the model has no
|
|
188
|
+
* reliable source for.
|
|
189
|
+
*/
|
|
190
|
+
export const AI_OUTBOUND_SEGMENT_TYPES = [
|
|
191
|
+
'text', 'mention', 'image', 'audio', 'video', 'file', 'markdown', 'keyboard', 'share', 'dice', 'rps',
|
|
192
|
+
];
|
|
193
|
+
/** Offered when the adapter declares no `segments.supported` list. */
|
|
194
|
+
export const DEFAULT_AI_OUTBOUND_SEGMENT_TYPES = [
|
|
195
|
+
'text', 'mention', 'image', 'audio', 'video', 'file', 'markdown', 'keyboard',
|
|
196
|
+
];
|
|
197
|
+
// Concrete closed shapes for renderer extensions; the publisher fills in ids,
|
|
198
|
+
// interaction mode and the text fallback for keyboards.
|
|
199
|
+
const aiExtensionBranches = {
|
|
200
|
+
markdown: strictBranch('markdown', dataObject({
|
|
201
|
+
content: { type: 'string', description: 'Markdown source; rendered by the unified outbound pipeline' },
|
|
202
|
+
}, ['content'])),
|
|
203
|
+
keyboard: strictBranch('keyboard', dataObject({
|
|
204
|
+
rows: {
|
|
122
205
|
type: 'array',
|
|
123
|
-
|
|
124
|
-
|
|
206
|
+
description: 'Quick-reply buttons, at most 5 per row; tapping one sends its payload as the user\'s next message',
|
|
207
|
+
items: {
|
|
208
|
+
type: 'array',
|
|
209
|
+
items: dataObject({
|
|
210
|
+
label: { type: 'string', description: 'Button text' },
|
|
211
|
+
payload: { type: 'string', description: 'Message sent when tapped, e.g. a command' },
|
|
212
|
+
}, ['label', 'payload']),
|
|
213
|
+
},
|
|
125
214
|
},
|
|
126
|
-
},
|
|
127
|
-
additionalProperties: false,
|
|
215
|
+
}, ['rows'])),
|
|
128
216
|
};
|
|
217
|
+
/**
|
|
218
|
+
* Promote declared optional string fields to required ones; the model writes ""
|
|
219
|
+
* when it has no value, and the decoder drops those empty fields again.
|
|
220
|
+
*/
|
|
221
|
+
function withModelFields(branch, fields) {
|
|
222
|
+
const branchProperties = branch.properties;
|
|
223
|
+
const data = branchProperties.data;
|
|
224
|
+
const properties = data.properties;
|
|
225
|
+
const extra = fields.filter(field => properties[field]?.type === 'string' && !data.required.includes(field));
|
|
226
|
+
return {
|
|
227
|
+
...branch,
|
|
228
|
+
properties: {
|
|
229
|
+
...branchProperties,
|
|
230
|
+
data: {
|
|
231
|
+
...data,
|
|
232
|
+
properties: Object.fromEntries(Object.entries(properties).map(([key, value]) => [key,
|
|
233
|
+
extra.includes(key) ? { ...value, description: `${value.description ?? key}; "" when unknown` } : value])),
|
|
234
|
+
required: [...data.required, ...extra],
|
|
235
|
+
},
|
|
236
|
+
},
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
/** Merge only branches whose complete constraints match apart from the type tag.
|
|
240
|
+
* Inline enums work across strict output providers without introducing $ref dialects.
|
|
241
|
+
*/
|
|
242
|
+
function mergeEquivalentBranches(branches) {
|
|
243
|
+
const groups = new Map();
|
|
244
|
+
for (const branch of branches) {
|
|
245
|
+
const properties = branch.properties;
|
|
246
|
+
const tag = properties.type;
|
|
247
|
+
const type = tag.const;
|
|
248
|
+
const shape = { ...branch, properties: { ...properties, type: { type: 'string' } } };
|
|
249
|
+
const key = JSON.stringify(shape);
|
|
250
|
+
const group = groups.get(key);
|
|
251
|
+
if (group) {
|
|
252
|
+
if (!group.types.includes(type))
|
|
253
|
+
group.types.push(type);
|
|
254
|
+
}
|
|
255
|
+
else
|
|
256
|
+
groups.set(key, { branch, types: [type] });
|
|
257
|
+
}
|
|
258
|
+
return [...groups.values()].map(({ branch, types }) => types.length === 1 ? branch : {
|
|
259
|
+
...branch,
|
|
260
|
+
properties: { ...branch.properties, type: { type: 'string', enum: types } },
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* The model's final reply: one or more chat messages, sent in order. Each message
|
|
265
|
+
* is an ordered segment array; the model decides how to split, like a person
|
|
266
|
+
* sending a few short messages. No text/mentions shorthand.
|
|
267
|
+
*/
|
|
268
|
+
export function buildAiOutboundJsonSchema(types = DEFAULT_AI_OUTBOUND_SEGMENT_TYPES, extensions = {}, reaction) {
|
|
269
|
+
const branches = outboundSegmentJsonSchema.anyOf.flatMap(branch => {
|
|
270
|
+
const type = branch.properties.type?.const;
|
|
271
|
+
if (type === undefined || type in aiExtensionBranches || !types.includes(type))
|
|
272
|
+
return [];
|
|
273
|
+
const fields = extensions[type]?.fields;
|
|
274
|
+
return [fields?.length ? withModelFields(branch, fields) : branch];
|
|
275
|
+
});
|
|
276
|
+
for (const type of types) {
|
|
277
|
+
const branch = aiExtensionBranches[type];
|
|
278
|
+
if (branch)
|
|
279
|
+
branches.push(branch);
|
|
280
|
+
}
|
|
281
|
+
return {
|
|
282
|
+
type: 'object',
|
|
283
|
+
properties: {
|
|
284
|
+
messages: {
|
|
285
|
+
type: 'array',
|
|
286
|
+
items: {
|
|
287
|
+
type: 'object',
|
|
288
|
+
properties: {
|
|
289
|
+
segments: {
|
|
290
|
+
type: 'array',
|
|
291
|
+
items: { anyOf: mergeEquivalentBranches(branches.map(requiredFieldsOnly)) },
|
|
292
|
+
},
|
|
293
|
+
},
|
|
294
|
+
required: ['segments'],
|
|
295
|
+
additionalProperties: false,
|
|
296
|
+
},
|
|
297
|
+
},
|
|
298
|
+
// Required with "" for none, like extension fields: strict structured outputs reject optional keys.
|
|
299
|
+
...(reaction ? {
|
|
300
|
+
reaction: {
|
|
301
|
+
type: 'string',
|
|
302
|
+
enum: ['', ...reaction.values.map(item => item.value)],
|
|
303
|
+
description: 'Reaction to put on the message being answered; "" for none.',
|
|
304
|
+
},
|
|
305
|
+
} : {}),
|
|
306
|
+
},
|
|
307
|
+
required: reaction ? ['messages', 'reaction'] : ['messages'],
|
|
308
|
+
additionalProperties: false,
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
export const aiOutboundJsonSchema = buildAiOutboundJsonSchema();
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Canonical Segment[] log / debug preview (SSOT).
|
|
3
|
-
* @see docs/
|
|
3
|
+
* @see ./types.ts (canonical Segment contract) and docs/concepts/message-flow.md
|
|
4
4
|
*/
|
|
5
5
|
import { htmlToFallbackText } from '../html-to-text.js';
|
|
6
6
|
import { readMentionName, readMentionTarget } from './mention.js';
|
|
@@ -106,6 +106,13 @@ export function formatSegmentPreview(item) {
|
|
|
106
106
|
return clip(`${text} <${url}>`);
|
|
107
107
|
return clip(url || text || '[link]');
|
|
108
108
|
}
|
|
109
|
+
case 'share': {
|
|
110
|
+
const url = typeof data.url === 'string' ? data.url : '';
|
|
111
|
+
const title = typeof data.title === 'string' ? data.title : '';
|
|
112
|
+
if (title && url)
|
|
113
|
+
return clip(`[share] ${title} <${url}>`);
|
|
114
|
+
return clip(title || url || '[share]');
|
|
115
|
+
}
|
|
109
116
|
case 'dice':
|
|
110
117
|
return data.result != null ? `{dice}(${data.result})` : '{dice}';
|
|
111
118
|
case 'rps':
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Canonical Segment[] → 纯文本视图(SSOT)。
|
|
3
3
|
* 入站双轨:结构化段为唯一内部契约,纯文本视图供命令匹配 / AI 兜底消费。
|
|
4
|
-
* @see docs/
|
|
4
|
+
* @see ./types.ts (canonical Segment contract) and docs/concepts/message-flow.md
|
|
5
5
|
*/
|
|
6
6
|
import { readMentionName, readMentionTarget } from './mention.js';
|
|
7
7
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/** Canonical Segment SSOT lives in @zhin.js/im-contract. */
|
|
2
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';
|
|
3
|
+
export type { ForwardSegment, MediaRef, MentionSegment, ReplySegment, ShareSegment, Segment, SegmentBase, TextSegment, } from '@zhin.js/im-contract';
|
|
4
4
|
/**
|
|
5
5
|
* 媒体引用占位(全框架唯一媒体表达)。
|
|
6
6
|
* kind=file:平台侧不透明文件引用(如 Telegram file_id、Milky resource_id),
|
|
@@ -54,5 +54,5 @@ export interface RpsSegment extends SegmentBase {
|
|
|
54
54
|
result?: number;
|
|
55
55
|
};
|
|
56
56
|
}
|
|
57
|
-
/** 规范态 segment(严格校验 text / mention / image / audio / video / file / reply / forward / face / dice / rps) */
|
|
57
|
+
/** 规范态 segment(严格校验 text / mention / image / audio / video / file / reply / forward / face / dice / rps / share) */
|
|
58
58
|
export type LegacySpecificSegment = ImageSegment | AudioSegment | VideoSegment | FileSegment | FaceSegment | DiceSegment | RpsSegment;
|