@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
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Schema } from '@zhin.js/schema';
|
|
2
|
+
export { isMediaRef } from '@zhin.js/im-contract';
|
|
2
3
|
const platformSchema = Schema.dict(Schema.any());
|
|
3
4
|
const mediaKindSchema = Schema.union([
|
|
4
5
|
Schema.const('url'),
|
|
@@ -95,6 +96,29 @@ export const rpsSegmentSchema = Schema.object({
|
|
|
95
96
|
data: Schema.object({ result: Schema.number() }).required(),
|
|
96
97
|
platform: platformSchema,
|
|
97
98
|
});
|
|
99
|
+
const shareConfigSchema = Schema.object({
|
|
100
|
+
appid: Schema.number().required(),
|
|
101
|
+
package: Schema.string(),
|
|
102
|
+
sign: Schema.string(),
|
|
103
|
+
icon: Schema.string(),
|
|
104
|
+
version: Schema.string(),
|
|
105
|
+
});
|
|
106
|
+
export const shareSegmentSchema = Schema.object({
|
|
107
|
+
type: Schema.const('share'),
|
|
108
|
+
data: Schema.object({
|
|
109
|
+
url: Schema.string().required(),
|
|
110
|
+
title: Schema.string().required(),
|
|
111
|
+
description: Schema.string(),
|
|
112
|
+
image: Schema.string(),
|
|
113
|
+
audio: Schema.string(),
|
|
114
|
+
content: Schema.string(),
|
|
115
|
+
artist: Schema.string(),
|
|
116
|
+
duration: Schema.number(),
|
|
117
|
+
platform: Schema.string(),
|
|
118
|
+
config: shareConfigSchema,
|
|
119
|
+
}).required(),
|
|
120
|
+
platform: platformSchema,
|
|
121
|
+
});
|
|
98
122
|
export const canonicalSegmentSchema = Schema.discriminatedUnion('type', {
|
|
99
123
|
text: {
|
|
100
124
|
data: Schema.object({ text: Schema.string().required() }).required(),
|
|
@@ -163,11 +187,23 @@ export const canonicalSegmentSchema = Schema.discriminatedUnion('type', {
|
|
|
163
187
|
data: Schema.object({ result: Schema.number() }).required(),
|
|
164
188
|
platform: platformSchema,
|
|
165
189
|
},
|
|
190
|
+
share: {
|
|
191
|
+
data: Schema.object({
|
|
192
|
+
url: Schema.string().required(),
|
|
193
|
+
title: Schema.string().required(),
|
|
194
|
+
description: Schema.string(),
|
|
195
|
+
image: Schema.string(),
|
|
196
|
+
audio: Schema.string(),
|
|
197
|
+
content: Schema.string(),
|
|
198
|
+
artist: Schema.string(),
|
|
199
|
+
duration: Schema.number(),
|
|
200
|
+
platform: Schema.string(),
|
|
201
|
+
config: shareConfigSchema,
|
|
202
|
+
}).required(),
|
|
203
|
+
platform: platformSchema,
|
|
204
|
+
},
|
|
166
205
|
});
|
|
167
206
|
export const segmentArraySchema = Schema.list(canonicalSegmentSchema);
|
|
168
|
-
export function isMediaRef(value) {
|
|
169
|
-
return mediaRefSchema.safeParse(value).success;
|
|
170
|
-
}
|
|
171
207
|
/** 严格 canonical 段校验(@zhin.js/schema validate-only) */
|
|
172
208
|
export function isStrictCanonicalSegment(value) {
|
|
173
209
|
return canonicalSegmentSchema.safeParse(value).success;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type PermissionHost } from '@zhin.js/permission';
|
|
2
|
+
import type { Message } from '../plugin-runtime/im/contracts.js';
|
|
3
|
+
import type { Tool } from '../types.js';
|
|
4
|
+
/** Checks whether a Tool is visible to the current IM message context. */
|
|
5
|
+
export declare function canAccessTool(tool: Tool, message?: Message, host?: PermissionHost | null): Promise<boolean>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { toPermissionSubject } from '@zhin.js/permission';
|
|
2
|
+
/** Checks whether a Tool is visible to the current IM message context. */
|
|
3
|
+
export async function canAccessTool(tool, message, host) {
|
|
4
|
+
if (!message)
|
|
5
|
+
return !tool.platforms?.length && !tool.scopes?.length && !tool.permissions?.length;
|
|
6
|
+
const adapter = String(message.clientAdapter ?? message.conversation.endpoint.adapter);
|
|
7
|
+
const scope = message.conversation.kind;
|
|
8
|
+
if (tool.platforms?.length && !tool.platforms.includes(adapter))
|
|
9
|
+
return false;
|
|
10
|
+
if (tool.scopes?.length && !tool.scopes.includes(scope))
|
|
11
|
+
return false;
|
|
12
|
+
if (!tool.permissions?.length)
|
|
13
|
+
return true;
|
|
14
|
+
if (!host)
|
|
15
|
+
return false;
|
|
16
|
+
return host.checkAll(tool.permissions, toPermissionSubject(message), { source: message });
|
|
17
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Locale } from '@zhin.js/plugin-runtime';
|
|
2
|
+
import type { UserInteractionContent, UserInteractionRequest } from '@zhin.js/im-contract';
|
|
2
3
|
import type { SendContent } from '../plugin-runtime/im/contracts.js';
|
|
3
4
|
import type { ButtonStyle } from './interactive-segments/types.js';
|
|
4
5
|
export interface UserInteractionAction {
|
|
@@ -23,8 +24,8 @@ export type UserInteractionParseResult = Readonly<{
|
|
|
23
24
|
/** Fail early for interaction definitions that could never produce an unambiguous answer. */
|
|
24
25
|
export declare function assertUserInteractionRequest(request: UserInteractionRequest): void;
|
|
25
26
|
/** Project semantic content into canonical Markdown + keyboard segments. */
|
|
26
|
-
export declare function renderUserInteraction(view: UserInteractionView): SendContent;
|
|
27
|
+
export declare function renderUserInteraction(view: UserInteractionView, actionPayload?: (value: string, index: number) => string, locale?: Locale): SendContent;
|
|
27
28
|
/** Derive presentation and controls from one discriminated request. */
|
|
28
|
-
export declare function projectUserInteraction(request: UserInteractionRequest, progress?: UserInteractionProgress): UserInteractionView;
|
|
29
|
+
export declare function projectUserInteraction(request: UserInteractionRequest, progress?: UserInteractionProgress, locale?: Locale): UserInteractionView;
|
|
29
30
|
/** Parse and validate one user reply without transport knowledge. */
|
|
30
|
-
export declare function parseUserInteractionAnswer(request: UserInteractionRequest, rawInput: string): UserInteractionParseResult;
|
|
31
|
+
export declare function parseUserInteractionAnswer(request: UserInteractionRequest, rawInput: string, locale?: Locale, action?: boolean): UserInteractionParseResult;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { interactionMessages as t } from './interaction-messages.js';
|
|
1
2
|
/** Fail early for interaction definitions that could never produce an unambiguous answer. */
|
|
2
3
|
export function assertUserInteractionRequest(request) {
|
|
3
4
|
if (!request.title.trim())
|
|
@@ -14,14 +15,10 @@ export function assertUserInteractionRequest(request) {
|
|
|
14
15
|
if (request.type === 'select' || request.type === 'multiselect') {
|
|
15
16
|
if (request.options.length === 0)
|
|
16
17
|
throw new TypeError('User interaction options must not be empty');
|
|
17
|
-
const labels = new Set();
|
|
18
18
|
for (const option of request.options) {
|
|
19
19
|
const label = option.label.trim().toLocaleLowerCase();
|
|
20
20
|
if (!label)
|
|
21
21
|
throw new TypeError('User interaction option label must not be empty');
|
|
22
|
-
if (labels.has(label))
|
|
23
|
-
throw new TypeError(`Duplicate user interaction option label: ${option.label}`);
|
|
24
|
-
labels.add(label);
|
|
25
22
|
}
|
|
26
23
|
}
|
|
27
24
|
if (request.type === 'multiselect') {
|
|
@@ -40,23 +37,24 @@ export function assertUserInteractionRequest(request) {
|
|
|
40
37
|
}
|
|
41
38
|
}
|
|
42
39
|
/** Project semantic content into canonical Markdown + keyboard segments. */
|
|
43
|
-
export function renderUserInteraction(view) {
|
|
40
|
+
export function renderUserInteraction(view, actionPayload = (value) => value, locale = 'zh-CN') {
|
|
44
41
|
const markdown = [
|
|
45
42
|
`### ${view.title}`,
|
|
46
43
|
view.description?.trim(),
|
|
47
44
|
view.tip?.trim() ? quoteTip(view.tip.trim()) : undefined,
|
|
48
45
|
].filter((part) => !!part).join('\n\n');
|
|
49
46
|
const actions = view.actions ?? [];
|
|
50
|
-
|
|
47
|
+
const hasInlineOptionList = actions.length > 0
|
|
48
|
+
&& actions.every((action, index) => view.description?.includes(`${index + 1}. ${action.label}`));
|
|
49
|
+
if (actions.length === 0 || hasInlineOptionList) {
|
|
51
50
|
return [{ type: 'markdown', data: { content: markdown } }];
|
|
52
51
|
}
|
|
53
52
|
const buttons = actions.map((action, index) => ({
|
|
54
53
|
id: `interaction-${index + 1}`,
|
|
55
54
|
label: action.label,
|
|
56
|
-
payload: action.value,
|
|
55
|
+
payload: actionPayload(action.value, index),
|
|
57
56
|
...(action.style ? { style: action.style } : {}),
|
|
58
|
-
mode: '
|
|
59
|
-
command: { enter: true, reply: false },
|
|
57
|
+
mode: 'callback',
|
|
60
58
|
}));
|
|
61
59
|
return [
|
|
62
60
|
{ type: 'markdown', data: { content: markdown } },
|
|
@@ -65,23 +63,23 @@ export function renderUserInteraction(view) {
|
|
|
65
63
|
data: {
|
|
66
64
|
rows: chunk(buttons, 5),
|
|
67
65
|
fallback: {
|
|
68
|
-
hint: '
|
|
69
|
-
map: Object.fromEntries(
|
|
66
|
+
hint: t(locale, 'fallback'),
|
|
67
|
+
map: Object.fromEntries(buttons.map((button, index) => [String(index + 1), button.payload])),
|
|
70
68
|
},
|
|
71
69
|
},
|
|
72
70
|
},
|
|
73
71
|
];
|
|
74
72
|
}
|
|
75
73
|
/** Derive presentation and controls from one discriminated request. */
|
|
76
|
-
export function projectUserInteraction(request, progress) {
|
|
77
|
-
const instruction = instructionFor(request);
|
|
74
|
+
export function projectUserInteraction(request, progress, locale = 'zh-CN') {
|
|
75
|
+
const instruction = instructionFor(request, locale);
|
|
78
76
|
const optionList = request.type === 'select' || request.type === 'multiselect'
|
|
79
77
|
? renderOptions(request.options)
|
|
80
78
|
: undefined;
|
|
81
79
|
const optionsHaveDescriptions = request.type === 'select' || request.type === 'multiselect'
|
|
82
80
|
? request.options.some((option) => !!option.description)
|
|
83
81
|
: false;
|
|
84
|
-
const actions = actionsFor(request);
|
|
82
|
+
const actions = actionsFor(request, locale);
|
|
85
83
|
const stepDescription = [
|
|
86
84
|
progress ? `**${progress.index}/${progress.total} · ${request.title}**` : undefined,
|
|
87
85
|
request.description,
|
|
@@ -97,58 +95,62 @@ export function projectUserInteraction(request, progress) {
|
|
|
97
95
|
});
|
|
98
96
|
}
|
|
99
97
|
/** Parse and validate one user reply without transport knowledge. */
|
|
100
|
-
export function parseUserInteractionAnswer(request, rawInput) {
|
|
98
|
+
export function parseUserInteractionAnswer(request, rawInput, locale = 'zh-CN', action = false) {
|
|
101
99
|
const raw = rawInput.trim();
|
|
102
100
|
switch (request.type) {
|
|
103
101
|
case 'text': {
|
|
104
102
|
if (raw.length < (request.minLength ?? 0))
|
|
105
|
-
return invalid(
|
|
103
|
+
return invalid(t(locale, 'minLength', { count: request.minLength }));
|
|
106
104
|
if (request.maxLength !== undefined && raw.length > request.maxLength) {
|
|
107
|
-
return invalid(
|
|
105
|
+
return invalid(t(locale, 'maxLength', { count: request.maxLength }));
|
|
108
106
|
}
|
|
109
107
|
if (request.pattern) {
|
|
110
108
|
request.pattern.lastIndex = 0;
|
|
111
109
|
if (!request.pattern.test(raw))
|
|
112
|
-
return invalid('
|
|
110
|
+
return invalid(t(locale, 'pattern'));
|
|
113
111
|
}
|
|
114
112
|
return valid(raw);
|
|
115
113
|
}
|
|
116
114
|
case 'number': {
|
|
117
115
|
const value = Number(raw);
|
|
118
116
|
if (!raw || !Number.isFinite(value))
|
|
119
|
-
return invalid('
|
|
117
|
+
return invalid(t(locale, 'number'));
|
|
120
118
|
if (request.integer && !Number.isInteger(value))
|
|
121
|
-
return invalid('
|
|
119
|
+
return invalid(t(locale, 'integer'));
|
|
122
120
|
if (request.min !== undefined && value < request.min)
|
|
123
|
-
return invalid(
|
|
121
|
+
return invalid(t(locale, 'min', { count: request.min }));
|
|
124
122
|
if (request.max !== undefined && value > request.max)
|
|
125
|
-
return invalid(
|
|
123
|
+
return invalid(t(locale, 'max', { count: request.max }));
|
|
126
124
|
return valid(value);
|
|
127
125
|
}
|
|
128
126
|
case 'confirm': {
|
|
129
|
-
const normalized = raw.
|
|
127
|
+
const normalized = raw.toLowerCase();
|
|
128
|
+
if (action && normalized === 'yes')
|
|
129
|
+
return valid(true);
|
|
130
|
+
if (action && normalized === 'no')
|
|
131
|
+
return valid(false);
|
|
130
132
|
const confirmLabel = request.confirmLabel?.trim().toLocaleLowerCase();
|
|
131
133
|
const cancelLabel = request.cancelLabel?.trim().toLocaleLowerCase();
|
|
132
|
-
if (CONFIRM_VALUES.has(normalized) || (confirmLabel && normalized === confirmLabel))
|
|
134
|
+
if (CONFIRM_VALUES[locale].has(normalized) || (confirmLabel && normalized === confirmLabel))
|
|
133
135
|
return valid(true);
|
|
134
|
-
if (CANCEL_VALUES.has(normalized) || (cancelLabel && normalized === cancelLabel))
|
|
136
|
+
if (CANCEL_VALUES[locale].has(normalized) || (cancelLabel && normalized === cancelLabel))
|
|
135
137
|
return valid(false);
|
|
136
|
-
return invalid('
|
|
138
|
+
return invalid(t(locale, 'confirmOrCancel'));
|
|
137
139
|
}
|
|
138
140
|
case 'select': {
|
|
139
141
|
const option = resolveOption(request.options, raw);
|
|
140
|
-
return option ? valid(option.value) : invalid('
|
|
142
|
+
return option ? valid(option.value) : invalid(t(locale, 'select'));
|
|
141
143
|
}
|
|
142
144
|
case 'multiselect': {
|
|
143
145
|
const separator = request.separator ?? ',';
|
|
144
146
|
const tokens = raw.split(separator).map((token) => token.trim()).filter(Boolean);
|
|
145
147
|
const selected = uniqueOptions(tokens.map((token) => resolveOption(request.options, token)));
|
|
146
148
|
if (selected.length !== tokens.length)
|
|
147
|
-
return invalid('
|
|
149
|
+
return invalid(t(locale, 'invalidSelection'));
|
|
148
150
|
if (selected.length < (request.minSelections ?? 0))
|
|
149
|
-
return invalid(
|
|
151
|
+
return invalid(t(locale, 'minSelections', { count: request.minSelections }));
|
|
150
152
|
if (request.maxSelections !== undefined && selected.length > request.maxSelections) {
|
|
151
|
-
return invalid(
|
|
153
|
+
return invalid(t(locale, 'maxSelections', { count: request.maxSelections }));
|
|
152
154
|
}
|
|
153
155
|
return valid(Object.freeze(selected.map((option) => option.value)));
|
|
154
156
|
}
|
|
@@ -156,28 +158,28 @@ export function parseUserInteractionAnswer(request, rawInput) {
|
|
|
156
158
|
const separator = request.separator ?? ',';
|
|
157
159
|
const tokens = raw.split(separator).map((token) => token.trim()).filter(Boolean);
|
|
158
160
|
if (tokens.length < (request.minItems ?? 0))
|
|
159
|
-
return invalid(
|
|
161
|
+
return invalid(t(locale, 'minItems', { count: request.minItems }));
|
|
160
162
|
if (request.maxItems !== undefined && tokens.length > request.maxItems)
|
|
161
|
-
return invalid(
|
|
163
|
+
return invalid(t(locale, 'maxItems', { count: request.maxItems }));
|
|
162
164
|
if (request.valueType === 'number') {
|
|
163
165
|
const values = tokens.map(Number);
|
|
164
|
-
return values.every(Number.isFinite) ? valid(Object.freeze(values)) : invalid('
|
|
166
|
+
return values.every(Number.isFinite) ? valid(Object.freeze(values)) : invalid(t(locale, 'invalidNumbers'));
|
|
165
167
|
}
|
|
166
168
|
if (request.valueType === 'boolean') {
|
|
167
|
-
const values = tokens.map(parseBoolean);
|
|
169
|
+
const values = tokens.map(value => parseBoolean(value, locale));
|
|
168
170
|
return values.every((value) => value !== undefined)
|
|
169
171
|
? valid(Object.freeze(values))
|
|
170
|
-
: invalid(
|
|
172
|
+
: invalid(t(locale, 'invalidBooleans'));
|
|
171
173
|
}
|
|
172
174
|
return valid(Object.freeze(tokens));
|
|
173
175
|
}
|
|
174
176
|
}
|
|
175
177
|
}
|
|
176
|
-
function actionsFor(request) {
|
|
178
|
+
function actionsFor(request, locale) {
|
|
177
179
|
if (request.type === 'confirm') {
|
|
178
180
|
return [
|
|
179
|
-
{ label: request.confirmLabel ?? '
|
|
180
|
-
{ label: request.cancelLabel ?? '
|
|
181
|
+
{ label: request.confirmLabel ?? t(locale, 'confirm'), value: 'yes', style: 'primary' },
|
|
182
|
+
{ label: request.cancelLabel ?? t(locale, 'cancel'), value: 'no', style: 'danger' },
|
|
181
183
|
];
|
|
182
184
|
}
|
|
183
185
|
if (request.type === 'select' && request.options.length <= 10) {
|
|
@@ -185,24 +187,30 @@ function actionsFor(request) {
|
|
|
185
187
|
}
|
|
186
188
|
return undefined;
|
|
187
189
|
}
|
|
188
|
-
function instructionFor(request) {
|
|
190
|
+
function instructionFor(request, locale) {
|
|
189
191
|
switch (request.type) {
|
|
190
|
-
case 'confirm': return '
|
|
191
|
-
case 'select': return '
|
|
192
|
-
case 'multiselect': return
|
|
193
|
-
case 'list': return
|
|
192
|
+
case 'confirm': return t(locale, 'confirmation');
|
|
193
|
+
case 'select': return t(locale, 'selection');
|
|
194
|
+
case 'multiselect': return t(locale, 'multiple', { separator: request.separator ?? ',' });
|
|
195
|
+
case 'list': return t(locale, 'list', { separator: request.separator ?? ',' });
|
|
194
196
|
default: return undefined;
|
|
195
197
|
}
|
|
196
198
|
}
|
|
197
199
|
function renderOptions(options) {
|
|
198
|
-
return options.map((option, index) =>
|
|
200
|
+
return options.map((option, index) => {
|
|
201
|
+
const aliases = option.aliases?.length ? `(${option.aliases.join(' / ')})` : '';
|
|
202
|
+
const description = option.description ? ` — ${option.description}` : '';
|
|
203
|
+
return `${index + 1}. ${option.label}${aliases}${description}`;
|
|
204
|
+
}).join('\n');
|
|
199
205
|
}
|
|
200
206
|
function resolveOption(options, raw) {
|
|
201
207
|
const index = Number(raw);
|
|
202
208
|
if (Number.isInteger(index) && index >= 1 && index <= options.length)
|
|
203
209
|
return options[index - 1];
|
|
204
|
-
const normalized = raw.toLocaleLowerCase();
|
|
205
|
-
|
|
210
|
+
const normalized = raw.trim().toLocaleLowerCase();
|
|
211
|
+
const matches = (candidate) => candidate.trim().toLocaleLowerCase() === normalized;
|
|
212
|
+
return options.find((option) => matches(option.label))
|
|
213
|
+
?? options.find((option) => option.aliases?.some(matches));
|
|
206
214
|
}
|
|
207
215
|
function uniqueOptions(options) {
|
|
208
216
|
const result = [];
|
|
@@ -211,11 +219,15 @@ function uniqueOptions(options) {
|
|
|
211
219
|
result.push(option);
|
|
212
220
|
return result;
|
|
213
221
|
}
|
|
214
|
-
function parseBoolean(raw) {
|
|
215
|
-
const normalized = raw.
|
|
216
|
-
if (
|
|
222
|
+
function parseBoolean(raw, locale) {
|
|
223
|
+
const normalized = raw.toLowerCase();
|
|
224
|
+
if (normalized === 'true')
|
|
225
|
+
return true;
|
|
226
|
+
if (normalized === 'false')
|
|
227
|
+
return false;
|
|
228
|
+
if (CONFIRM_VALUES[locale].has(normalized))
|
|
217
229
|
return true;
|
|
218
|
-
if (CANCEL_VALUES.has(normalized))
|
|
230
|
+
if (CANCEL_VALUES[locale].has(normalized))
|
|
219
231
|
return false;
|
|
220
232
|
return undefined;
|
|
221
233
|
}
|
|
@@ -238,8 +250,8 @@ function validBounds(minimum, maximum) {
|
|
|
238
250
|
&& (maximum === undefined || Number.isFinite(maximum))
|
|
239
251
|
&& (minimum === undefined || maximum === undefined || minimum <= maximum);
|
|
240
252
|
}
|
|
241
|
-
const CONFIRM_VALUES = new Set(['1', '
|
|
242
|
-
const CANCEL_VALUES = new Set(['2', '
|
|
253
|
+
const CONFIRM_VALUES = { 'zh-CN': new Set(['1', '是', '确认', '同意']), en: new Set(['1', 'y', 'yes', 'true', 'confirm', 'agree']) };
|
|
254
|
+
const CANCEL_VALUES = { 'zh-CN': new Set(['2', '否', '取消', '拒绝']), en: new Set(['2', 'n', 'no', 'false', 'cancel', 'reject']) };
|
|
243
255
|
function chunk(items, size) {
|
|
244
256
|
const rows = [];
|
|
245
257
|
for (let index = 0; index < items.length; index += size)
|
package/lib/errors.d.ts
CHANGED
|
@@ -1,21 +1,4 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Re-export generic errors from @zhin.js/kernel
|
|
3
3
|
*/
|
|
4
|
-
export { ZhinError
|
|
5
|
-
import { ZhinError } from '@zhin.js/kernel';
|
|
6
|
-
/**
|
|
7
|
-
* 适配器相关错误
|
|
8
|
-
*/
|
|
9
|
-
export declare class AdapterError extends ZhinError {
|
|
10
|
-
readonly adapterName: string;
|
|
11
|
-
readonly endpointKey?: string;
|
|
12
|
-
constructor(message: string, adapterName: string, endpointKey?: string, context?: Record<string, any>);
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* 消息处理错误
|
|
16
|
-
*/
|
|
17
|
-
export declare class MessageError extends ZhinError {
|
|
18
|
-
readonly messageId?: string;
|
|
19
|
-
readonly channelId?: string;
|
|
20
|
-
constructor(message: string, messageId?: string, channelId?: string, context?: Record<string, any>);
|
|
21
|
-
}
|
|
4
|
+
export { ZhinError } from '@zhin.js/kernel';
|
package/lib/errors.js
CHANGED
|
@@ -1,29 +1,4 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Re-export generic errors from @zhin.js/kernel
|
|
3
3
|
*/
|
|
4
|
-
export { ZhinError
|
|
5
|
-
import { ZhinError } from '@zhin.js/kernel';
|
|
6
|
-
/**
|
|
7
|
-
* 适配器相关错误
|
|
8
|
-
*/
|
|
9
|
-
export class AdapterError extends ZhinError {
|
|
10
|
-
adapterName;
|
|
11
|
-
endpointKey;
|
|
12
|
-
constructor(message, adapterName, endpointKey, context) {
|
|
13
|
-
super(message, 'ADAPTER_ERROR', { ...context, adapterName, endpointKey });
|
|
14
|
-
this.adapterName = adapterName;
|
|
15
|
-
this.endpointKey = endpointKey;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* 消息处理错误
|
|
20
|
-
*/
|
|
21
|
-
export class MessageError extends ZhinError {
|
|
22
|
-
messageId;
|
|
23
|
-
channelId;
|
|
24
|
-
constructor(message, messageId, channelId, context) {
|
|
25
|
-
super(message, 'MESSAGE_ERROR', { ...context, messageId, channelId });
|
|
26
|
-
this.messageId = messageId;
|
|
27
|
-
this.channelId = channelId;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
4
|
+
export { ZhinError } from '@zhin.js/kernel';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Command authoring and Root-selected IM presentation contracts.
|
|
3
|
+
* @module zhin.js/command
|
|
4
|
+
*/
|
|
5
|
+
export { defineCommand, commandFeedbackToken, commandMenuPresentationToken, type CommandContext, type CommandConversation, type CommandDefiner, type CommandDefinition, type CommandMessage, type CommandParameterDefinition, type CommandParamSchema, type CommandScene, type CommandSegment, type CommandSender, type CommandSession, type CommandDynamicValue, type CommandParameterType, type CommandParameterValue, type CommandExecutionPolicy, type CommandExecutionLimit, type CommandParams, type CommandOptions, type CommandOptionSchema, type InferCommandParams, type InferCommandOptions, type CommandFeedback, type CommandFeedbackContext, type CommandFeedbackRenderer, type CommandMenuPresentationInput, type CommandMenuPresenter, type CommandMenuPage, type CommandMenuNavigation, type CommandMenuEntry, type CommandMenuAppearance, type CommandValidationIssue, } from './command.js';
|
package/lib/feature/command.d.ts
CHANGED
|
@@ -1,2 +1,4 @@
|
|
|
1
1
|
/** Authoring API for Command Feature — implementation in `@zhin.js/command`. */
|
|
2
2
|
export * from '@zhin.js/command';
|
|
3
|
+
export { commandFeedbackToken, commandMenuPresentationToken } from '../plugin-runtime/im/command-feedback.js';
|
|
4
|
+
export type { CommandFeedback, CommandFeedbackContext, CommandFeedbackRenderer, CommandMenuPresentationInput, CommandMenuPresenter } from '../plugin-runtime/im/command-feedback.js';
|
package/lib/feature/command.js
CHANGED
package/lib/feature/component.js
CHANGED
package/lib/feature/handler.d.ts
CHANGED
|
@@ -1,17 +1,13 @@
|
|
|
1
1
|
/** Authoring API for Handler Feature — implementation in `@zhin.js/handler`. */
|
|
2
2
|
export { parseHandlerDefinition, HandlerIndex, isHandlerIndex, handlerFeatureId, handlerFeature, handlerEventFromLocalName, resolveHandlerEvent, type HandlerEventMap, type HandlerDefinition, type HandlerDescriptor, type HandlerContext, type HandlerDispatchOptions, } from '@zhin.js/handler';
|
|
3
3
|
import { type HandlerContext, type HandlerDefinition, type HandlerEventMap } from '@zhin.js/handler';
|
|
4
|
-
import type { Plugin } from '../plugin.js';
|
|
5
4
|
import type { Message } from '../plugin-runtime/im/contracts.js';
|
|
6
5
|
import type { Notice } from '../notice.js';
|
|
7
6
|
import type { Request } from '../request.js';
|
|
8
7
|
import type { SystemEvent } from '../system-event.js';
|
|
9
8
|
import type { AdapterClient, AdapterEvents, EndpointEvent, EndpointIdentity, PlatformEvent, RegisteredAdapterName } from '@zhin.js/adapter';
|
|
10
|
-
type KnownKeys<T> = {
|
|
11
|
-
[K in keyof T as string extends K ? never : number extends K ? never : K]: T[K];
|
|
12
|
-
};
|
|
13
9
|
declare module '@zhin.js/handler' {
|
|
14
|
-
interface HandlerEventMap
|
|
10
|
+
interface HandlerEventMap {
|
|
15
11
|
'message.receive': [event: EndpointEvent<Message>];
|
|
16
12
|
'notice.receive': [event: EndpointEvent<Notice>];
|
|
17
13
|
'request.receive': [event: EndpointEvent<Request>];
|
|
@@ -30,7 +26,7 @@ export interface ClientHandlerEvent<TAdapter extends RegisteredAdapterName, TNam
|
|
|
30
26
|
export interface ClientHandlerOptions<TAdapter extends RegisteredAdapterName, TName extends NativeEventName<TAdapter>> {
|
|
31
27
|
readonly adapter: TAdapter;
|
|
32
28
|
readonly event: TName;
|
|
33
|
-
handle(this: HandlerContext, event: ClientHandlerEvent<TAdapter, TName>): void | Promise<void>;
|
|
29
|
+
handle(this: HandlerContext<unknown, TAdapter>, event: ClientHandlerEvent<TAdapter, TName>): void | Promise<void>;
|
|
34
30
|
}
|
|
35
31
|
export interface ClientHandlerWildcardEvent<TAdapter extends RegisteredAdapterName> {
|
|
36
32
|
readonly name: string;
|
|
@@ -41,8 +37,18 @@ export interface ClientHandlerWildcardEvent<TAdapter extends RegisteredAdapterNa
|
|
|
41
37
|
export interface ClientHandlerWildcardOptions<TAdapter extends RegisteredAdapterName> {
|
|
42
38
|
readonly adapter: TAdapter;
|
|
43
39
|
readonly event: '*';
|
|
44
|
-
handle(this: HandlerContext, event: ClientHandlerWildcardEvent<TAdapter>): void | Promise<void>;
|
|
40
|
+
handle(this: HandlerContext<unknown, TAdapter>, event: ClientHandlerWildcardEvent<TAdapter>): void | Promise<void>;
|
|
45
41
|
}
|
|
42
|
+
type CanonicalHandlerEvent = 'message.receive' | 'notice.receive' | 'request.receive' | 'system.receive' | 'platform.receive';
|
|
43
|
+
type BoundCanonicalHandler<K extends CanonicalHandlerEvent> = {
|
|
44
|
+
[A in RegisteredAdapterName]: {
|
|
45
|
+
readonly adapter: A;
|
|
46
|
+
readonly event: K;
|
|
47
|
+
handle(this: HandlerContext<unknown, A>, ...args: HandlerEventMap[K]): void | Promise<void>;
|
|
48
|
+
};
|
|
49
|
+
}[RegisteredAdapterName];
|
|
50
|
+
/** Canonical messages share the captured operation Session; native callbacks retain their original payload. */
|
|
51
|
+
export declare function defineHandler<K extends CanonicalHandlerEvent>(options: BoundCanonicalHandler<K>): Readonly<HandlerDefinition<K>>;
|
|
46
52
|
export declare function defineHandler<TAdapter extends RegisteredAdapterName, TName extends NativeEventName<TAdapter>>(options: ClientHandlerOptions<TAdapter, TName>): Readonly<HandlerDefinition<'platform.receive'>>;
|
|
47
53
|
/** Handle every native event from one Client without pretending unknown payloads are typed. */
|
|
48
54
|
export declare function defineHandler<TAdapter extends RegisteredAdapterName>(options: ClientHandlerWildcardOptions<TAdapter>): Readonly<HandlerDefinition<'platform.receive'>>;
|
package/lib/feature/handler.js
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
export { parseHandlerDefinition, HandlerIndex, isHandlerIndex, handlerFeatureId, handlerFeature, handlerEventFromLocalName, resolveHandlerEvent, } from '@zhin.js/handler';
|
|
3
3
|
import { defineHandler as defineHandlerFeature, } from '@zhin.js/handler';
|
|
4
4
|
export function defineHandler(options) {
|
|
5
|
-
if (!('adapter' in options) || typeof options.adapter !== 'string'
|
|
5
|
+
if (!('adapter' in options) || typeof options.adapter !== 'string'
|
|
6
|
+
|| ['message.receive', 'notice.receive', 'request.receive', 'system.receive', 'platform.receive'].includes(options.event ?? '')) {
|
|
6
7
|
return defineHandlerFeature(options);
|
|
7
8
|
}
|
|
8
9
|
const adapter = options.adapter;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Incoming Message and outbound envelope middleware authoring contracts.
|
|
3
|
+
* @module zhin.js/middleware
|
|
4
|
+
*/
|
|
5
|
+
export { defineMiddleware, type MiddlewareContext, type MiddlewareContinuation, type MiddlewareDefinition, type MiddlewareDefinitionBase, type MiddlewareNext, type MiddlewarePhase, type MiddlewareTarget, type OutboundMiddlewareNext, } from './middleware.js';
|
|
6
|
+
export { outboundPresentationToken, type OutboundPresentation, type OutboundPresentationContext, type OutboundPresentationMode, type OutboundPresentationPreferences, } from './middleware.js';
|
|
@@ -1,2 +1,22 @@
|
|
|
1
|
-
/**
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* IM authoring defaults; the underlying Feature remains transport independent.
|
|
3
|
+
* @module zhin.js/middleware
|
|
4
|
+
*/
|
|
5
|
+
export type { MiddlewareContinuation, MiddlewareDefinitionBase, MiddlewareNext, MiddlewarePhase, MiddlewareTarget, OutboundMiddlewareNext, } from '@zhin.js/middleware';
|
|
6
|
+
import { type MiddlewareAuthoringDefinition, type MiddlewareContext as FeatureMiddlewareContext, type MiddlewareDefinition as FeatureMiddlewareDefinition } from '@zhin.js/middleware';
|
|
7
|
+
import type { Message, OutboundEnvelope } from '../plugin-runtime/im/contracts.js';
|
|
8
|
+
export type MiddlewareContext<TInput = Message, TConfig = unknown, TAdapter extends string | undefined = undefined> = FeatureMiddlewareContext<TInput, TConfig, TAdapter>;
|
|
9
|
+
export type MiddlewareDefinition<TInput = Message, TConfig = unknown, TAdapter extends string | undefined = string | undefined> = FeatureMiddlewareDefinition<TInput, TConfig, TAdapter>;
|
|
10
|
+
/** Incoming IM middleware receives Message; outbound middleware receives its envelope. */
|
|
11
|
+
export declare function defineMiddleware<TInput = OutboundEnvelope, TConfig = unknown>(definition: Extract<MiddlewareAuthoringDefinition<TInput, TConfig>, {
|
|
12
|
+
readonly target: 'outbound';
|
|
13
|
+
}>): Readonly<Extract<FeatureMiddlewareDefinition<TInput, TConfig>, {
|
|
14
|
+
readonly target: 'outbound';
|
|
15
|
+
}>>;
|
|
16
|
+
export declare function defineMiddleware<TInput = Message, TConfig = unknown>(definition: Extract<MiddlewareAuthoringDefinition<TInput, TConfig>, {
|
|
17
|
+
readonly target?: 'inbound';
|
|
18
|
+
}>): Readonly<Extract<FeatureMiddlewareDefinition<TInput, TConfig>, {
|
|
19
|
+
readonly target: 'inbound';
|
|
20
|
+
}>>;
|
|
21
|
+
export { outboundPresentationToken } from '../plugin-runtime/im/outbound-renderer.js';
|
|
22
|
+
export type { OutboundPresentation, OutboundPresentationContext, OutboundPresentationMode, OutboundPresentationPreferences, } from '../plugin-runtime/im/outbound-renderer.js';
|
|
@@ -1,2 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
1
|
+
import { defineMiddleware as defineFeatureMiddleware, } from '@zhin.js/middleware';
|
|
2
|
+
export function defineMiddleware(definition) {
|
|
3
|
+
// Both overloads deliberately delegate the same validation and feature brand.
|
|
4
|
+
const define = defineFeatureMiddleware;
|
|
5
|
+
return define(definition);
|
|
6
|
+
}
|
|
7
|
+
export { outboundPresentationToken } from '../plugin-runtime/im/outbound-renderer.js';
|
package/lib/im-scene.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { MessageType } from './message.js';
|
|
2
|
+
import type { Message } from './plugin-runtime/im/contracts.js';
|
|
2
3
|
import type { SendContent, SendOptions } from './types.js';
|
|
3
4
|
export type IMSceneKind = MessageType;
|
|
4
5
|
/** Parent scene kind (distinct from sub-channel MessageType.channel). */
|
|
@@ -23,7 +24,7 @@ export interface IMDeliveryTarget {
|
|
|
23
24
|
}
|
|
24
25
|
/** Normalize legacy parent.type channel → guild. */
|
|
25
26
|
export declare function normalizeIMSceneParentKind(value: unknown): IMSceneParentKind | undefined;
|
|
26
|
-
export declare function sceneRefFromMessage(message: Partial<Message
|
|
27
|
+
export declare function sceneRefFromMessage(message: Partial<Message>): IMSceneRef | undefined;
|
|
27
28
|
export declare function sceneRefToSendOptions(target: IMDeliveryTarget, content: SendContent): SendOptions;
|
|
28
29
|
export declare function resolveIMSceneSessionId(scene: IMSceneRef): string;
|
|
29
|
-
export declare function messageToIMDeliveryTarget(message: Partial<Message
|
|
30
|
+
export declare function messageToIMDeliveryTarget(message: Partial<Message>): IMDeliveryTarget | undefined;
|
package/lib/im-scene.js
CHANGED
|
@@ -11,25 +11,25 @@ export function normalizeIMSceneParentKind(value) {
|
|
|
11
11
|
return undefined;
|
|
12
12
|
}
|
|
13
13
|
export function sceneRefFromMessage(message) {
|
|
14
|
-
const platform = nonEmptyString(message
|
|
15
|
-
const endpointKey = nonEmptyString(message
|
|
16
|
-
const kind = message
|
|
14
|
+
const platform = nonEmptyString(message.clientAdapter ?? message.conversation?.endpoint.adapter);
|
|
15
|
+
const endpointKey = nonEmptyString(message.endpointId ?? message.conversation?.endpoint.id);
|
|
16
|
+
const kind = message.conversation?.kind;
|
|
17
17
|
if (!platform || !endpointKey || !kind)
|
|
18
18
|
return undefined;
|
|
19
|
-
const senderId = nonEmptyString(message
|
|
20
|
-
const channelId = nonEmptyString(message
|
|
19
|
+
const senderId = nonEmptyString(message.sender?.id);
|
|
20
|
+
const channelId = nonEmptyString(message.conversation?.id);
|
|
21
21
|
const sceneId = kind === 'private'
|
|
22
22
|
? senderId ?? channelId
|
|
23
23
|
: channelId ?? senderId;
|
|
24
24
|
if (!sceneId)
|
|
25
25
|
return undefined;
|
|
26
|
-
const parentKind = message
|
|
27
|
-
? normalizeIMSceneParentKind(message
|
|
26
|
+
const parentKind = message.conversation?.parent
|
|
27
|
+
? normalizeIMSceneParentKind(message.conversation.parent.kind)
|
|
28
28
|
: undefined;
|
|
29
|
-
const parent = parentKind && message
|
|
29
|
+
const parent = parentKind && message.conversation?.parent
|
|
30
30
|
? {
|
|
31
31
|
kind: parentKind,
|
|
32
|
-
sceneId: String(message
|
|
32
|
+
sceneId: String(message.conversation.parent.id),
|
|
33
33
|
}
|
|
34
34
|
: undefined;
|
|
35
35
|
return {
|