@zhin.js/core 1.5.16 → 1.7.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 +330 -25
- package/lib/built/login-assist.js +1156 -75
- package/lib/built/login-captcha.d.ts +62 -0
- package/lib/built/login-captcha.js +107 -0
- 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 +20 -48
- package/lib/index.js +15 -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 +112 -0
- package/lib/plugin-runtime/im/endpoint-runtime.js +434 -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 +152 -0
- package/lib/plugin-runtime/im/host/database-console-schema.d.ts +79 -0
- package/lib/plugin-runtime/im/host/database-console-schema.js +477 -0
- package/lib/plugin-runtime/im/host/database-console-sql.d.ts +66 -0
- package/lib/plugin-runtime/im/host/database-console-sql.js +459 -0
- package/lib/plugin-runtime/im/host/database-host-installer.d.ts +60 -0
- package/lib/plugin-runtime/im/host/database-host-installer.js +1166 -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 +235 -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
package/lib/im-session-id.d.ts
CHANGED
|
@@ -10,25 +10,33 @@ export declare function resolveIMSessionId(input: ResolveIMSessionIdInput): stri
|
|
|
10
10
|
export declare function resolveIMSessionIdFromScene(scene: IMSceneRef): string;
|
|
11
11
|
export declare function resolveIMSceneIdForSession(kind: IMSceneKind, sceneId?: string, senderId?: string): string;
|
|
12
12
|
export declare function resolveIMSessionIdFromMessage(message: {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
clientAdapter?: string;
|
|
14
|
+
endpointId?: string;
|
|
15
|
+
conversation?: {
|
|
16
|
+
endpoint: {
|
|
17
|
+
adapter: string;
|
|
18
|
+
id: string;
|
|
19
|
+
};
|
|
20
|
+
kind: IMSceneKind;
|
|
21
|
+
id: string;
|
|
18
22
|
};
|
|
19
|
-
|
|
23
|
+
sender?: {
|
|
20
24
|
id?: string;
|
|
21
25
|
};
|
|
22
26
|
}): string;
|
|
23
27
|
/** Canonical scene fields for transcript / session persistence (ADR 0028 SSOT). */
|
|
24
28
|
export declare function resolveSceneFieldsFromMessage(message: {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
29
|
+
clientAdapter?: string;
|
|
30
|
+
endpointId?: string;
|
|
31
|
+
conversation?: {
|
|
32
|
+
endpoint: {
|
|
33
|
+
adapter: string;
|
|
34
|
+
id: string;
|
|
35
|
+
};
|
|
36
|
+
kind: IMSceneKind;
|
|
37
|
+
id: string;
|
|
30
38
|
};
|
|
31
|
-
|
|
39
|
+
sender?: {
|
|
32
40
|
id?: string;
|
|
33
41
|
};
|
|
34
42
|
}): {
|
package/lib/im-session-id.js
CHANGED
|
@@ -18,12 +18,12 @@ export function resolveIMSessionIdFromMessage(message) {
|
|
|
18
18
|
const scene = sceneRefFromMessage(message);
|
|
19
19
|
if (scene)
|
|
20
20
|
return resolveIMSceneSessionId(scene);
|
|
21
|
-
const kind = (message
|
|
21
|
+
const kind = (message.conversation?.kind || 'private');
|
|
22
22
|
return resolveIMSessionId({
|
|
23
|
-
platform: String(message
|
|
24
|
-
endpointKey: String(message
|
|
23
|
+
platform: String(message.clientAdapter || message.conversation?.endpoint.adapter || ''),
|
|
24
|
+
endpointKey: String(message.endpointId || message.conversation?.endpoint.id || ''),
|
|
25
25
|
kind,
|
|
26
|
-
sceneId: resolveIMSceneIdForSession(kind, message
|
|
26
|
+
sceneId: resolveIMSceneIdForSession(kind, message.conversation?.id, message.sender?.id),
|
|
27
27
|
});
|
|
28
28
|
}
|
|
29
29
|
/** Canonical scene fields for transcript / session persistence (ADR 0028 SSOT). */
|
|
@@ -37,11 +37,11 @@ export function resolveSceneFieldsFromMessage(message) {
|
|
|
37
37
|
sceneType: scene.kind,
|
|
38
38
|
};
|
|
39
39
|
}
|
|
40
|
-
const sceneType = (message
|
|
40
|
+
const sceneType = (message.conversation?.kind || 'private');
|
|
41
41
|
return {
|
|
42
|
-
platform: String(message
|
|
43
|
-
endpointKey: String(message
|
|
42
|
+
platform: String(message.clientAdapter || message.conversation?.endpoint.adapter || ''),
|
|
43
|
+
endpointKey: String(message.endpointId || message.conversation?.endpoint.id || ''),
|
|
44
44
|
sceneType,
|
|
45
|
-
sceneId: resolveIMSceneIdForSession(sceneType, message
|
|
45
|
+
sceneId: resolveIMSceneIdForSession(sceneType, message.conversation?.id, message.sender?.id),
|
|
46
46
|
};
|
|
47
47
|
}
|
package/lib/index.d.ts
CHANGED
|
@@ -2,82 +2,54 @@
|
|
|
2
2
|
* Canonical IM messages, Endpoints, rendering, and plugin-facing core types.
|
|
3
3
|
* @module @zhin.js/core
|
|
4
4
|
*/
|
|
5
|
-
export
|
|
6
|
-
export
|
|
7
|
-
export
|
|
8
|
-
export
|
|
9
|
-
export
|
|
10
|
-
export * from './adapter.js';
|
|
11
|
-
export * from './message.js';
|
|
5
|
+
export { defineComponent, type ComponentDefinition, type ComponentContext } from '@zhin.js/component';
|
|
6
|
+
export { component, type ComponentCall, raw, type RawContent, untrustedContent, isUntrustedContent, type UntrustedContent } from './plugin-runtime/im/contracts.js';
|
|
7
|
+
export { checkUntrustedMediaRef, DEFAULT_UNTRUSTED_INLINE_MEDIA_BYTES, isPlatformFileToken, isTrustedMediaRef, trustedMediaRef, type OutboundMediaRefusal, type OutboundMediaTrust, type UntrustedMediaDecision, } from './built/outbound-media-trust.js';
|
|
8
|
+
export type { MessageChannel, MessageType } from './message.js';
|
|
9
|
+
export { Message, type MessageBase } from './plugin-runtime/im/contracts.js';
|
|
12
10
|
export * from './im-scene.js';
|
|
13
11
|
export * from './notice.js';
|
|
14
12
|
export * from './request.js';
|
|
15
13
|
export * from './system-event.js';
|
|
16
14
|
export * from './side-event/index.js';
|
|
17
|
-
export * from '
|
|
18
|
-
export type * from '@zhin.js/interaction';
|
|
15
|
+
export type * from '@zhin.js/im-contract/interaction';
|
|
19
16
|
export * from './types.js';
|
|
20
17
|
export * from './utils.js';
|
|
21
18
|
export * from './errors.js';
|
|
22
|
-
export * from './
|
|
23
|
-
export * from './built/command.js';
|
|
24
|
-
export * from './built/schedule.js';
|
|
25
|
-
export type { ScheduleDescriptor, ScheduleHandle, ScheduleContextExtensions } from './built/schedule.js';
|
|
19
|
+
export * from './ai-completion-contract.js';
|
|
26
20
|
export * from './models/system-log.js';
|
|
27
21
|
export * from './models/user.js';
|
|
28
|
-
export * from './built/permit-parse.js';
|
|
29
|
-
export * from './built/permit-check.js';
|
|
30
|
-
export * from './built/platform-permit.js';
|
|
31
|
-
export * from './built/authorization.js';
|
|
32
22
|
export * from './built/message-enrich.js';
|
|
33
23
|
export type { AgentTurnMessage, SyntheticMessageInput } from './built/message-enrich.js';
|
|
34
|
-
export * from './built/
|
|
35
|
-
export * from './built/database.js';
|
|
36
|
-
export * from './built/message-filter.js';
|
|
37
|
-
export * from './built/tool.js';
|
|
38
|
-
export * from './built/skill.js';
|
|
39
|
-
export * from './built/agent-preset.js';
|
|
24
|
+
export * from './built/tool-access.js';
|
|
40
25
|
export * from './built/common-adapter-tools.js';
|
|
41
26
|
export * from './built/roles.js';
|
|
42
27
|
export * from './im-session-id.js';
|
|
43
28
|
export * from './built/ai-trigger.js';
|
|
44
29
|
export * from './built/ai-access.js';
|
|
45
|
-
export * from './built/dispatcher.js';
|
|
46
|
-
export * from './built/schema-feature.js';
|
|
47
30
|
export * from './built/login-assist.js';
|
|
31
|
+
export * from './built/login-captcha.js';
|
|
48
32
|
export * from './built/generated-qrcode.js';
|
|
49
|
-
export
|
|
33
|
+
export { markdownToPlainText } from './built/rich-segments/markdown-to-text.js';
|
|
50
34
|
export * from './built/interactive-segments/index.js';
|
|
51
35
|
export * from './built/user-interaction.js';
|
|
52
36
|
export * from './built/ai-outbound/index.js';
|
|
53
|
-
export { loadHtmlRenderer, seedHtmlRenderer, HTML_RENDERER_PACKAGE } from './built/html-renderer-loader.js';
|
|
54
|
-
export { loadSpeechPipeline, seedSpeechPipeline, SPEECH_PACKAGE } from './built/speech-loader.js';
|
|
55
37
|
export * from './built/outbound-media-utils.js';
|
|
56
|
-
export * from './built/outbound-media-contract.js';
|
|
57
|
-
export * from './built/interactive-segment-contract.js';
|
|
58
38
|
export * from './built/segment-contract/index.js';
|
|
59
39
|
export type { SegmentMediaRef } from './built/segment-contract/media.js';
|
|
60
40
|
export * from './built/generic-segment-mapper.js';
|
|
61
|
-
export * from './built/adapter-process.js';
|
|
62
|
-
export * from './built/component.js';
|
|
63
|
-
export * from './built/inbound-runner.js';
|
|
64
|
-
export type { RunInboundMessageOptions, InboundRunResult } from './built/inbound-runner.js';
|
|
65
|
-
export * from './built/connect-endpoint-instance.js';
|
|
66
|
-
export type { ConnectEndpointInstanceOptions } from './built/connect-endpoint-instance.js';
|
|
67
|
-
export * from './built/endpoint-lifecycle.js';
|
|
68
|
-
export type { EndpointLifecycleKind, EndpointLifecyclePayload } from './built/endpoint-lifecycle.js';
|
|
69
|
-
export * from './built/endpoint-manager.js';
|
|
70
|
-
export type { EndpointConfigRecord, EndpointManager, ProvisionContext } from './built/endpoint-manager.js';
|
|
71
|
-
export * from './built/endpoint-lifecycle-service.js';
|
|
72
|
-
export * from './built/schema-endpoint-manager.js';
|
|
73
|
-
export * from './built/endpoint-commands.js';
|
|
74
|
-
export * from './built/introspection-format.js';
|
|
75
|
-
export * from './built/management-command-guard.js';
|
|
76
41
|
export * from './built/html-to-text.js';
|
|
77
42
|
export * from './built/html-segment-fallback.js';
|
|
78
43
|
export * from '@zhin.js/database';
|
|
79
44
|
export * from '@zhin.js/logger';
|
|
80
45
|
export { Schema } from '@zhin.js/schema';
|
|
81
|
-
export
|
|
82
|
-
export {
|
|
83
|
-
export type {
|
|
46
|
+
export { ScheduleEngine } from '@zhin.js/kernel';
|
|
47
|
+
export type { ScheduleFireCallback, MemoryScheduleRegistration, ScheduleEngineOptions, JobContext, ResolvedJob, ScheduleKind, } from '@zhin.js/kernel';
|
|
48
|
+
export type { ConversationRef, DeliveryReceipt } from '@zhin.js/im-contract';
|
|
49
|
+
export { conversationRefKey } from '@zhin.js/im-contract';
|
|
50
|
+
export { readOperationSession } from '@zhin.js/feature-kit';
|
|
51
|
+
export type { CapabilityContext, OperationClientPort, OperationSession, OperationScene, OperationSender, OperationMessage, OperationMessageRef } from '@zhin.js/feature-kit';
|
|
52
|
+
/** ADR 0044: adapter capability types, re-exported so the agent layer reads them through core. */
|
|
53
|
+
export type { TurnCapabilities, AdapterCapabilityProfile, CapabilityFacts } from '@zhin.js/adapter';
|
|
54
|
+
export { adapterFeatureId, isAdapterIndex } from '@zhin.js/adapter';
|
|
55
|
+
export * from './venue/index.js';
|
package/lib/index.js
CHANGED
|
@@ -2,76 +2,50 @@
|
|
|
2
2
|
* Canonical IM messages, Endpoints, rendering, and plugin-facing core types.
|
|
3
3
|
* @module @zhin.js/core
|
|
4
4
|
*/
|
|
5
|
-
|
|
6
|
-
export
|
|
7
|
-
export
|
|
8
|
-
export
|
|
9
|
-
export * from './command.js';
|
|
10
|
-
export * from './component.js';
|
|
11
|
-
export * from './adapter.js';
|
|
12
|
-
export * from './message.js';
|
|
5
|
+
export { defineComponent } from '@zhin.js/component';
|
|
6
|
+
export { component, raw, untrustedContent, isUntrustedContent } from './plugin-runtime/im/contracts.js';
|
|
7
|
+
export { checkUntrustedMediaRef, DEFAULT_UNTRUSTED_INLINE_MEDIA_BYTES, isPlatformFileToken, isTrustedMediaRef, trustedMediaRef, } from './built/outbound-media-trust.js';
|
|
8
|
+
export { Message } from './plugin-runtime/im/contracts.js';
|
|
13
9
|
export * from './im-scene.js';
|
|
14
10
|
export * from './notice.js';
|
|
15
11
|
export * from './request.js';
|
|
16
12
|
export * from './system-event.js';
|
|
17
13
|
export * from './side-event/index.js';
|
|
18
|
-
export * from './schema-interaction.js';
|
|
19
14
|
export * from './types.js';
|
|
20
15
|
export * from './utils.js';
|
|
21
16
|
export * from './errors.js';
|
|
17
|
+
// Tool-free AI completion contract for plugins; provided by @zhin.js/agent when AI is configured (#877)
|
|
18
|
+
export * from './ai-completion-contract.js';
|
|
22
19
|
// ── Built 模块 ──────────────────────────────────────────────────────
|
|
23
|
-
export * from './built/config.js';
|
|
24
|
-
export * from './built/command.js';
|
|
25
|
-
export * from './built/schedule.js';
|
|
26
20
|
// Models
|
|
27
21
|
export * from './models/system-log.js';
|
|
28
22
|
export * from './models/user.js';
|
|
29
|
-
export * from './built/permit-parse.js';
|
|
30
|
-
export * from './built/permit-check.js';
|
|
31
|
-
export * from './built/platform-permit.js';
|
|
32
|
-
export * from './built/authorization.js';
|
|
33
23
|
export * from './built/message-enrich.js';
|
|
34
|
-
export * from './built/
|
|
35
|
-
export * from './built/database.js';
|
|
36
|
-
export * from './built/message-filter.js';
|
|
37
|
-
export * from './built/tool.js';
|
|
38
|
-
export * from './built/skill.js';
|
|
39
|
-
export * from './built/agent-preset.js';
|
|
24
|
+
export * from './built/tool-access.js';
|
|
40
25
|
export * from './built/common-adapter-tools.js';
|
|
41
26
|
export * from './built/roles.js';
|
|
42
27
|
export * from './im-session-id.js';
|
|
43
28
|
export * from './built/ai-trigger.js';
|
|
44
29
|
export * from './built/ai-access.js';
|
|
45
|
-
export * from './built/dispatcher.js';
|
|
46
|
-
export * from './built/schema-feature.js';
|
|
47
30
|
export * from './built/login-assist.js';
|
|
31
|
+
export * from './built/login-captcha.js';
|
|
48
32
|
export * from './built/generated-qrcode.js';
|
|
49
|
-
export
|
|
33
|
+
export { markdownToPlainText } from './built/rich-segments/markdown-to-text.js';
|
|
50
34
|
export * from './built/interactive-segments/index.js';
|
|
51
35
|
export * from './built/user-interaction.js';
|
|
52
36
|
export * from './built/ai-outbound/index.js';
|
|
53
|
-
export { loadHtmlRenderer, seedHtmlRenderer, HTML_RENDERER_PACKAGE } from './built/html-renderer-loader.js';
|
|
54
|
-
export { loadSpeechPipeline, seedSpeechPipeline, SPEECH_PACKAGE } from './built/speech-loader.js';
|
|
55
37
|
export * from './built/outbound-media-utils.js';
|
|
56
|
-
export * from './built/outbound-media-contract.js';
|
|
57
|
-
export * from './built/interactive-segment-contract.js';
|
|
58
38
|
export * from './built/segment-contract/index.js';
|
|
59
39
|
export * from './built/generic-segment-mapper.js';
|
|
60
|
-
export * from './built/adapter-process.js';
|
|
61
|
-
export * from './built/component.js';
|
|
62
|
-
export * from './built/inbound-runner.js';
|
|
63
|
-
export * from './built/connect-endpoint-instance.js';
|
|
64
|
-
export * from './built/endpoint-lifecycle.js';
|
|
65
|
-
export * from './built/endpoint-manager.js';
|
|
66
|
-
export * from './built/endpoint-lifecycle-service.js';
|
|
67
|
-
export * from './built/schema-endpoint-manager.js';
|
|
68
|
-
export * from './built/endpoint-commands.js';
|
|
69
|
-
export * from './built/introspection-format.js';
|
|
70
|
-
export * from './built/management-command-guard.js';
|
|
71
40
|
export * from './built/html-to-text.js';
|
|
72
41
|
export * from './built/html-segment-fallback.js';
|
|
73
42
|
// ── 外部库 re-export ──────────────────────────────────────────────────
|
|
74
43
|
export * from '@zhin.js/database';
|
|
75
44
|
export * from '@zhin.js/logger';
|
|
76
45
|
export { Schema } from '@zhin.js/schema';
|
|
77
|
-
export {
|
|
46
|
+
export { ScheduleEngine } from '@zhin.js/kernel';
|
|
47
|
+
export { conversationRefKey } from '@zhin.js/im-contract';
|
|
48
|
+
export { readOperationSession } from '@zhin.js/feature-kit';
|
|
49
|
+
export { adapterFeatureId, isAdapterIndex } from '@zhin.js/adapter';
|
|
50
|
+
// ── Venue 模块 (ADR 0048 H4) ──────────────────────────────────────────
|
|
51
|
+
export * from './venue/index.js';
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import type { JSX as BaseJSX, JSXAttributes, HtmlProps } from '@zhin.js/jsx';
|
|
2
|
+
import type { MediaRef, ForwardSegment, ShareSegment } from '@zhin.js/im-contract';
|
|
3
|
+
import type { ButtonProps, ImageProps, MentionProps, FaceProps, TextProps, MarkdownProps } from './message-tags.js';
|
|
4
|
+
import type { AudioSegment, VideoSegment, FileSegment } from '../built/segment-contract/types.js';
|
|
5
|
+
import type { KeyboardSegmentData, ActionSegmentData } from '../built/interactive-segments/types.js';
|
|
6
|
+
type MediaProps = {
|
|
7
|
+
readonly media: MediaRef;
|
|
8
|
+
readonly duration?: number;
|
|
9
|
+
readonly alt?: string;
|
|
10
|
+
readonly name?: string;
|
|
11
|
+
};
|
|
12
|
+
type HtmlInputProps = Omit<HtmlProps, 'children'> & ({
|
|
13
|
+
readonly html: string;
|
|
14
|
+
readonly children?: never;
|
|
15
|
+
} | {
|
|
16
|
+
readonly children?: HtmlProps['children'];
|
|
17
|
+
readonly html?: never;
|
|
18
|
+
});
|
|
19
|
+
/** Lowercase tags mirror Segment.type and its data fields, with typed creation helpers. */
|
|
20
|
+
export interface MessageTagProps {
|
|
21
|
+
text: TextProps;
|
|
22
|
+
image: ImageProps | {
|
|
23
|
+
readonly media: MediaRef;
|
|
24
|
+
readonly alt?: string;
|
|
25
|
+
};
|
|
26
|
+
mention: MentionProps;
|
|
27
|
+
face: FaceProps;
|
|
28
|
+
audio: AudioSegment['data'];
|
|
29
|
+
video: VideoSegment['data'];
|
|
30
|
+
file: FileSegment['data'];
|
|
31
|
+
record: MediaProps;
|
|
32
|
+
voice: MediaProps;
|
|
33
|
+
reply: {
|
|
34
|
+
readonly message_id: string;
|
|
35
|
+
};
|
|
36
|
+
forward: ForwardSegment['data'];
|
|
37
|
+
share: ShareSegment['data'];
|
|
38
|
+
dice: {
|
|
39
|
+
readonly result?: number;
|
|
40
|
+
};
|
|
41
|
+
rps: {
|
|
42
|
+
readonly result?: number;
|
|
43
|
+
};
|
|
44
|
+
card: Readonly<Record<string, unknown>> & {
|
|
45
|
+
readonly children?: never;
|
|
46
|
+
};
|
|
47
|
+
button: ButtonProps;
|
|
48
|
+
keyboard: KeyboardSegmentData;
|
|
49
|
+
action: ActionSegmentData;
|
|
50
|
+
html: HtmlInputProps;
|
|
51
|
+
markdown: MarkdownProps;
|
|
52
|
+
link: {
|
|
53
|
+
readonly url: string;
|
|
54
|
+
readonly text?: string;
|
|
55
|
+
};
|
|
56
|
+
qrcode: {
|
|
57
|
+
readonly text: string;
|
|
58
|
+
readonly width?: number;
|
|
59
|
+
readonly margin?: number;
|
|
60
|
+
readonly errorCorrectionLevel?: 'L' | 'M' | 'Q' | 'H';
|
|
61
|
+
readonly small?: boolean;
|
|
62
|
+
};
|
|
63
|
+
tts: {
|
|
64
|
+
readonly text: string;
|
|
65
|
+
readonly voice?: string;
|
|
66
|
+
readonly provider?: string;
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
/** Compiler namespace shared by both production and development runtime entrypoints. */
|
|
70
|
+
export declare namespace JSX {
|
|
71
|
+
type Element = BaseJSX.Element;
|
|
72
|
+
type ElementType = BaseJSX.ElementType;
|
|
73
|
+
interface ElementChildrenAttribute {
|
|
74
|
+
children: {};
|
|
75
|
+
}
|
|
76
|
+
interface IntrinsicAttributes {
|
|
77
|
+
key?: string | number;
|
|
78
|
+
}
|
|
79
|
+
interface IntrinsicElements extends MessageTagProps {
|
|
80
|
+
[name: string]: JSXAttributes | MessageTagProps[keyof MessageTagProps];
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type JSXRenderable, type JSXProps } from '@zhin.js/jsx';
|
|
2
|
+
import type { Segment } from '@zhin.js/im-contract';
|
|
3
|
+
import { type ButtonProps } from './message-tags.js';
|
|
4
|
+
/** Native and namespaced extension tags do not use ComponentIndex. */
|
|
5
|
+
export declare function isNativeMessageTag(type: string): boolean;
|
|
6
|
+
export interface MessageRenderOptions {
|
|
7
|
+
readonly maxDepth?: number;
|
|
8
|
+
readonly signal?: AbortSignal;
|
|
9
|
+
readonly bindButton?: (props: ButtonProps) => Segment;
|
|
10
|
+
readonly renderComponent?: (name: string, props: JSXProps) => Promise<JSXRenderable>;
|
|
11
|
+
}
|
|
12
|
+
/** Default JSX lays out ordered message segments. Only Html changes to HTML semantics. */
|
|
13
|
+
export declare function renderToSegments(node: JSXRenderable, options?: MessageRenderOptions): Promise<readonly Segment[]>;
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { Fragment, Html, isJsxElement, renderToHtml } from '@zhin.js/jsx';
|
|
2
|
+
import { segment } from '../utils.js';
|
|
3
|
+
import { isSegmentContent } from '../plugin-runtime/im/contracts.js';
|
|
4
|
+
import { Image } from './message-tags.js';
|
|
5
|
+
import { isKeyboardSegment } from '../built/interactive-segments/types.js';
|
|
6
|
+
const MESSAGE_TAGS = new Set([
|
|
7
|
+
'text', 'mention', 'image', 'audio', 'video', 'file', 'reply', 'forward', 'face',
|
|
8
|
+
'dice', 'rps', 'share', 'card', 'action', 'html', 'keyboard', 'link', 'markdown',
|
|
9
|
+
'qrcode', 'record', 'tts', 'voice',
|
|
10
|
+
]);
|
|
11
|
+
/** Native and namespaced extension tags do not use ComponentIndex. */
|
|
12
|
+
export function isNativeMessageTag(type) {
|
|
13
|
+
return type === 'button' || MESSAGE_TAGS.has(type) || /^[a-z][a-z0-9-]*(?::[a-z][a-z0-9-]*)+$/.test(type);
|
|
14
|
+
}
|
|
15
|
+
/** Default JSX lays out ordered message segments. Only Html changes to HTML semantics. */
|
|
16
|
+
export async function renderToSegments(node, options = {}) {
|
|
17
|
+
const maxDepth = options.maxDepth ?? 100;
|
|
18
|
+
if (!Number.isSafeInteger(maxDepth) || maxDepth < 1)
|
|
19
|
+
throw new RangeError('JSX maxDepth must be a positive integer');
|
|
20
|
+
const ancestors = new WeakSet();
|
|
21
|
+
const output = [];
|
|
22
|
+
let lastButtonIndex = -1;
|
|
23
|
+
const render = async (value, depth) => {
|
|
24
|
+
options.signal?.throwIfAborted();
|
|
25
|
+
if (depth > maxDepth)
|
|
26
|
+
throw new RangeError(`JSX exceeds maximum render depth ${maxDepth}`);
|
|
27
|
+
if (value == null || typeof value === 'boolean')
|
|
28
|
+
return;
|
|
29
|
+
if (typeof value === 'string' || typeof value === 'number') {
|
|
30
|
+
if (value !== '')
|
|
31
|
+
output.push(segment.text(String(value)));
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
if (typeof value !== 'object')
|
|
35
|
+
throw new TypeError('Unsupported JSX child');
|
|
36
|
+
if (ancestors.has(value))
|
|
37
|
+
throw new TypeError('Circular JSX tree');
|
|
38
|
+
ancestors.add(value);
|
|
39
|
+
try {
|
|
40
|
+
if (Array.isArray(value)) {
|
|
41
|
+
for (const child of value)
|
|
42
|
+
await render(child, depth + 1);
|
|
43
|
+
}
|
|
44
|
+
else if ('then' in value && typeof value.then === 'function') {
|
|
45
|
+
const then = value.then;
|
|
46
|
+
const resolved = await new Promise((resolve, reject) => {
|
|
47
|
+
then.call(value, (child) => resolve({ node: child }), reject);
|
|
48
|
+
});
|
|
49
|
+
await render(resolved.node, depth + 1);
|
|
50
|
+
}
|
|
51
|
+
else if (isJsxElement(value)) {
|
|
52
|
+
const { type, props } = value;
|
|
53
|
+
if (type === Fragment)
|
|
54
|
+
await render(props.children, depth + 1);
|
|
55
|
+
else if (type === Html || type === 'html') {
|
|
56
|
+
if (props.html !== undefined && props.children !== undefined)
|
|
57
|
+
throw new TypeError('Html accepts html or children, not both');
|
|
58
|
+
if (props.html !== undefined && typeof props.html !== 'string')
|
|
59
|
+
throw new TypeError('Html html must be a string');
|
|
60
|
+
const html = typeof props.html === 'string' ? props.html
|
|
61
|
+
: await renderToHtml(props.children, { maxDepth: Math.max(1, maxDepth - depth) });
|
|
62
|
+
const { width, backgroundColor, fileName, text } = props;
|
|
63
|
+
if (html || text)
|
|
64
|
+
output.push(segment.html({ html,
|
|
65
|
+
...(width === undefined ? {} : { width }),
|
|
66
|
+
...(backgroundColor === undefined ? {} : { backgroundColor }),
|
|
67
|
+
...(fileName === undefined ? {} : { fileName }),
|
|
68
|
+
...(text === undefined ? {} : { text }),
|
|
69
|
+
}));
|
|
70
|
+
}
|
|
71
|
+
else if (typeof type === 'function')
|
|
72
|
+
await render(type(props), depth + 1);
|
|
73
|
+
else if (type === 'image' && 'src' in props)
|
|
74
|
+
await render(Image(props), depth + 1);
|
|
75
|
+
else if (type === 'button') {
|
|
76
|
+
if (!options.bindButton)
|
|
77
|
+
throw new TypeError('Button requires an active IM runtime');
|
|
78
|
+
const button = options.bindButton(props);
|
|
79
|
+
const previous = output[lastButtonIndex];
|
|
80
|
+
if (lastButtonIndex === output.length - 1 && isKeyboardSegment(previous) && isKeyboardSegment(button)) {
|
|
81
|
+
output[lastButtonIndex] = { type: 'keyboard', data: { rows: [[...previous.data.rows.flat(), ...button.data.rows.flat()]] } };
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
output.push(button);
|
|
85
|
+
lastButtonIndex = output.length - 1;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
else if (typeof type === 'string' && isNativeMessageTag(type)) {
|
|
89
|
+
const { children, ...data } = props;
|
|
90
|
+
if ((type === 'text' || type === 'markdown') && children !== undefined) {
|
|
91
|
+
const field = type === 'text' ? 'text' : 'content';
|
|
92
|
+
if (data[field] !== undefined)
|
|
93
|
+
throw new TypeError(`${type} accepts ${field} or children, not both`);
|
|
94
|
+
const start = output.length;
|
|
95
|
+
await render(children, depth + 1);
|
|
96
|
+
const parts = output.splice(start);
|
|
97
|
+
if (!parts.every((part) => part.type === 'text' && 'text' in part.data && typeof part.data.text === 'string')) {
|
|
98
|
+
throw new TypeError(`${type} children must produce text segments`);
|
|
99
|
+
}
|
|
100
|
+
const text = parts.map(part => part.data.text).join('');
|
|
101
|
+
if (text)
|
|
102
|
+
output.push(segment(type, { ...data, [field]: text }));
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
if (children !== undefined)
|
|
106
|
+
throw new TypeError(`Message tag ${type} stores content in its data props, not children`);
|
|
107
|
+
output.push(segment(type, data));
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
else if (typeof type === 'string' && options.renderComponent) {
|
|
111
|
+
await render(await options.renderComponent(type, props), depth + 1);
|
|
112
|
+
}
|
|
113
|
+
else
|
|
114
|
+
throw new TypeError(`Unknown message tag ${String(type)}; register a component or wrap HTML in <html>`);
|
|
115
|
+
}
|
|
116
|
+
else if (isSegmentContent(value))
|
|
117
|
+
output.push(value);
|
|
118
|
+
else
|
|
119
|
+
throw new TypeError('Unsupported JSX child: expected a JSX element or Segment');
|
|
120
|
+
}
|
|
121
|
+
finally {
|
|
122
|
+
ancestors.delete(value);
|
|
123
|
+
}
|
|
124
|
+
options.signal?.throwIfAborted();
|
|
125
|
+
};
|
|
126
|
+
await render(node, 0);
|
|
127
|
+
return output;
|
|
128
|
+
}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { type JSXElement, type JSXRenderable } from '@zhin.js/jsx';
|
|
2
|
+
import type { MediaRef, Segment } from '@zhin.js/im-contract';
|
|
3
|
+
import type { Message, SendContent } from '../plugin-runtime/im/contracts.js';
|
|
4
|
+
import type { ActionSegmentData, ButtonData, KeyboardSegmentData } from '../built/interactive-segments/types.js';
|
|
5
|
+
export type TextProps = {
|
|
6
|
+
readonly text: string;
|
|
7
|
+
readonly children?: never;
|
|
8
|
+
} | {
|
|
9
|
+
readonly children: JSXRenderable;
|
|
10
|
+
readonly text?: never;
|
|
11
|
+
};
|
|
12
|
+
export declare function Text(props: TextProps): JSXElement;
|
|
13
|
+
export interface ImageProps {
|
|
14
|
+
readonly src: string | MediaRef;
|
|
15
|
+
readonly alt?: string;
|
|
16
|
+
}
|
|
17
|
+
/** URLs and local paths are convenient sources; opaque platform IDs use MediaRef. */
|
|
18
|
+
export declare function Image({ src, alt }: ImageProps): JSXElement;
|
|
19
|
+
export interface MentionProps {
|
|
20
|
+
readonly target: string;
|
|
21
|
+
readonly name?: string;
|
|
22
|
+
}
|
|
23
|
+
export declare function Mention(props: MentionProps): JSXElement;
|
|
24
|
+
export interface FaceProps {
|
|
25
|
+
readonly id: string | number;
|
|
26
|
+
readonly name?: string;
|
|
27
|
+
}
|
|
28
|
+
export declare function Face(props: FaceProps): JSXElement;
|
|
29
|
+
export type MarkdownProps = ({
|
|
30
|
+
readonly content: string;
|
|
31
|
+
readonly children?: never;
|
|
32
|
+
} | {
|
|
33
|
+
readonly children: JSXRenderable;
|
|
34
|
+
readonly content?: never;
|
|
35
|
+
}) & {
|
|
36
|
+
readonly width?: number;
|
|
37
|
+
readonly backgroundColor?: string;
|
|
38
|
+
readonly fileName?: string;
|
|
39
|
+
};
|
|
40
|
+
export declare function Markdown(props: MarkdownProps): JSXElement;
|
|
41
|
+
/** Platform-native payload; no HTML serialization or cross-platform card schema. */
|
|
42
|
+
export interface CardProps {
|
|
43
|
+
readonly data: Readonly<Record<string, unknown>>;
|
|
44
|
+
}
|
|
45
|
+
export declare function Card({ data }: CardProps): Segment;
|
|
46
|
+
export type ButtonClickResult = SendContent | number | boolean | null | void;
|
|
47
|
+
export type ButtonClickHandler = (message: Message) => ButtonClickResult | Promise<ButtonClickResult>;
|
|
48
|
+
export type ButtonProps = Omit<ButtonData, 'id' | 'label' | 'payload'> & {
|
|
49
|
+
readonly id?: string;
|
|
50
|
+
/**
|
|
51
|
+
* `onClick` buttons only (ADR 0056 §5): built-in permit expressions the *clicker* must satisfy
|
|
52
|
+
* (zhin role, platform standing, `bot:*`), checked by the same evaluator as commands and Agent
|
|
53
|
+
* tools. Unmet = the callback does not run and the clicker gets the reason. Never sent to the platform.
|
|
54
|
+
*/
|
|
55
|
+
readonly permit?: readonly string[];
|
|
56
|
+
} & ({
|
|
57
|
+
readonly label: string;
|
|
58
|
+
readonly children?: never;
|
|
59
|
+
} | {
|
|
60
|
+
readonly children: string;
|
|
61
|
+
readonly label?: never;
|
|
62
|
+
}) & ({
|
|
63
|
+
readonly onClick: ButtonClickHandler;
|
|
64
|
+
readonly payload?: never;
|
|
65
|
+
} | {
|
|
66
|
+
readonly payload: string;
|
|
67
|
+
readonly onClick?: never;
|
|
68
|
+
});
|
|
69
|
+
/** Event handlers are bound by the active IM operation, never serialized onto the wire. */
|
|
70
|
+
export declare function Button(props: ButtonProps): JSXElement;
|
|
71
|
+
export declare const Audio: (props: {
|
|
72
|
+
media: MediaRef;
|
|
73
|
+
duration?: number;
|
|
74
|
+
}) => JSXElement;
|
|
75
|
+
export declare const Video: (props: {
|
|
76
|
+
media: MediaRef;
|
|
77
|
+
duration?: number;
|
|
78
|
+
alt?: string;
|
|
79
|
+
}) => JSXElement;
|
|
80
|
+
export declare const File: (props: {
|
|
81
|
+
media: MediaRef;
|
|
82
|
+
name?: string;
|
|
83
|
+
}) => JSXElement;
|
|
84
|
+
export declare const Reply: (props: {
|
|
85
|
+
readonly message_id: string;
|
|
86
|
+
}) => JSXElement;
|
|
87
|
+
export declare const Forward: (props: Readonly<{
|
|
88
|
+
forward_id: string;
|
|
89
|
+
title?: string;
|
|
90
|
+
entries?: readonly import("@zhin.js/im-contract").ForwardEntry[];
|
|
91
|
+
}>) => JSXElement;
|
|
92
|
+
export declare const Share: (props: Readonly<{
|
|
93
|
+
url: string;
|
|
94
|
+
title: string;
|
|
95
|
+
description?: string;
|
|
96
|
+
image?: string;
|
|
97
|
+
audio?: string;
|
|
98
|
+
content?: string;
|
|
99
|
+
artist?: string;
|
|
100
|
+
duration?: number;
|
|
101
|
+
platform?: string;
|
|
102
|
+
config?: Readonly<{
|
|
103
|
+
appid: number;
|
|
104
|
+
package?: string;
|
|
105
|
+
sign?: string;
|
|
106
|
+
icon?: string;
|
|
107
|
+
version?: string;
|
|
108
|
+
}>;
|
|
109
|
+
}>) => JSXElement;
|
|
110
|
+
export declare const Dice: (props: {
|
|
111
|
+
readonly result?: number;
|
|
112
|
+
}) => JSXElement;
|
|
113
|
+
export declare const Rps: (props: {
|
|
114
|
+
readonly result?: number;
|
|
115
|
+
}) => JSXElement;
|
|
116
|
+
export declare const Keyboard: (props: KeyboardSegmentData) => JSXElement;
|
|
117
|
+
export declare const Action: (props: ActionSegmentData) => JSXElement;
|
|
118
|
+
export declare const Link: (props: {
|
|
119
|
+
readonly url: string;
|
|
120
|
+
readonly text?: string;
|
|
121
|
+
}) => JSXElement;
|
|
122
|
+
export declare const Qrcode: (props: {
|
|
123
|
+
readonly text: string;
|
|
124
|
+
readonly width?: number;
|
|
125
|
+
readonly margin?: number;
|
|
126
|
+
readonly errorCorrectionLevel?: "L" | "M" | "Q" | "H";
|
|
127
|
+
readonly small?: boolean;
|
|
128
|
+
}) => JSXElement;
|
|
129
|
+
export declare const Tts: (props: {
|
|
130
|
+
readonly text: string;
|
|
131
|
+
readonly voice?: string;
|
|
132
|
+
readonly provider?: string;
|
|
133
|
+
}) => JSXElement;
|