@zhin.js/core 1.1.34 → 1.1.37
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 +84 -142
- package/lib/built/ai-access.d.ts +36 -0
- package/lib/built/ai-access.js +46 -0
- package/lib/built/ai-outbound/extensions/onebot-keyboard.d.ts +2 -0
- package/lib/built/ai-outbound/extensions/onebot-keyboard.js +67 -0
- package/lib/built/ai-outbound/extensions/qq-message.d.ts +3 -0
- package/lib/built/ai-outbound/extensions/qq-message.js +23 -0
- package/lib/built/ai-outbound/index.d.ts +8 -0
- package/lib/built/ai-outbound/index.js +8 -0
- package/lib/built/ai-outbound/parse.d.ts +13 -0
- package/lib/built/ai-outbound/parse.js +104 -0
- package/lib/built/ai-outbound/plain-mention-rewrite.d.ts +6 -0
- package/lib/built/ai-outbound/plain-mention-rewrite.js +37 -0
- package/lib/built/ai-outbound/prompt.d.ts +11 -0
- package/lib/built/ai-outbound/prompt.js +44 -0
- package/lib/built/ai-outbound/resolve.d.ts +4 -0
- package/lib/built/ai-outbound/resolve.js +64 -0
- package/lib/built/ai-outbound/structured-detect.d.ts +3 -0
- package/lib/built/ai-outbound/structured-detect.js +6 -0
- package/lib/built/ai-outbound/types.d.ts +49 -0
- package/lib/built/ai-outbound/types.js +5 -0
- package/lib/built/ai-trigger.d.ts +12 -17
- package/lib/built/ai-trigger.js +39 -70
- package/lib/built/common-adapter-tools.d.ts +33 -29
- package/lib/built/common-adapter-tools.js +79 -67
- package/lib/built/generated-qrcode.d.ts +24 -0
- package/lib/built/generated-qrcode.js +45 -0
- package/lib/built/generic-segment-mapper.d.ts +4 -0
- package/lib/built/generic-segment-mapper.js +190 -0
- package/lib/built/html-segment-fallback.d.ts +2 -5
- package/lib/built/html-segment-fallback.js +0 -16
- package/lib/built/html-to-text.d.ts +0 -1
- package/lib/built/html-to-text.js +15 -15
- package/lib/built/interactive-segments/action.d.ts +17 -0
- package/lib/built/interactive-segments/action.js +69 -0
- package/lib/built/interactive-segments/button-spec.d.ts +10 -0
- package/lib/built/interactive-segments/button-spec.js +21 -0
- package/lib/built/interactive-segments/index.d.ts +6 -0
- package/lib/built/interactive-segments/index.js +6 -0
- package/lib/built/interactive-segments/keyboard-segment.d.ts +10 -0
- package/lib/built/interactive-segments/keyboard-segment.js +11 -0
- package/lib/built/interactive-segments/onebot-keyboard.d.ts +6 -0
- package/lib/built/interactive-segments/onebot-keyboard.js +49 -0
- package/lib/built/interactive-segments/resolve.d.ts +14 -0
- package/lib/built/interactive-segments/resolve.js +109 -0
- package/lib/built/interactive-segments/types.d.ts +45 -0
- package/lib/built/interactive-segments/types.js +9 -0
- package/lib/built/login-assist.d.ts +43 -16
- package/lib/built/login-assist.js +113 -11
- package/lib/built/message-enrich.d.ts +32 -0
- package/lib/built/message-enrich.js +67 -0
- package/lib/built/outbound-media-utils.d.ts +9 -0
- package/lib/built/outbound-media-utils.js +62 -0
- package/lib/built/queue-im-field-contract.d.ts +7 -2
- package/lib/built/queue-im-field-contract.js +13 -4
- package/lib/built/rich-segments/markdown-to-text.d.ts +3 -0
- package/lib/built/rich-segments/markdown-to-text.js +27 -0
- package/lib/built/roles.d.ts +4 -5
- package/lib/built/roles.js +4 -5
- package/lib/built/segment-contract/assert.d.ts +7 -0
- package/lib/built/segment-contract/assert.js +39 -0
- package/lib/built/segment-contract/delivery.d.ts +5 -0
- package/lib/built/segment-contract/delivery.js +40 -0
- package/lib/built/segment-contract/image.d.ts +5 -0
- package/lib/built/segment-contract/image.js +10 -0
- package/lib/built/segment-contract/index.d.ts +10 -0
- package/lib/built/segment-contract/index.js +9 -0
- package/lib/built/segment-contract/json-schema.d.ts +28 -0
- package/lib/built/segment-contract/json-schema.js +128 -0
- package/lib/built/segment-contract/media.d.ts +12 -0
- package/lib/built/segment-contract/media.js +22 -0
- package/lib/built/segment-contract/mention.d.ts +10 -0
- package/lib/built/segment-contract/mention.js +26 -0
- package/lib/built/segment-contract/preview.d.ts +3 -0
- package/lib/built/segment-contract/preview.js +159 -0
- package/lib/built/segment-contract/text.d.ts +7 -0
- package/lib/built/segment-contract/text.js +34 -0
- package/lib/built/segment-contract/types.d.ts +58 -0
- package/lib/built/segment-contract/types.js +1 -0
- package/lib/built/segment-contract/validate.d.ts +229 -0
- package/lib/built/segment-contract/validate.js +172 -0
- package/lib/built/tool-access.d.ts +5 -0
- package/lib/built/tool-access.js +17 -0
- package/lib/built/user-interaction.d.ts +30 -0
- package/lib/built/user-interaction.js +244 -0
- package/lib/component.d.ts +0 -1
- package/lib/component.js +30 -14
- package/lib/errors.d.ts +2 -3
- package/lib/errors.js +4 -5
- package/lib/feature/adapter.d.ts +2 -0
- package/lib/feature/adapter.js +2 -0
- package/lib/feature/command.d.ts +2 -0
- package/lib/feature/command.js +2 -0
- package/lib/feature/component.d.ts +2 -0
- package/lib/feature/component.js +2 -0
- package/lib/feature/handler.d.ts +48 -0
- package/lib/feature/handler.js +26 -0
- package/lib/feature/middleware.d.ts +2 -0
- package/lib/feature/middleware.js +2 -0
- package/lib/im-scene.d.ts +29 -0
- package/lib/im-scene.js +75 -0
- package/lib/im-session-id.d.ts +39 -0
- package/lib/im-session-id.js +47 -0
- package/lib/index.d.ts +29 -36
- package/lib/index.js +27 -41
- package/lib/jsx-dev-runtime.d.ts +0 -1
- package/lib/jsx-dev-runtime.js +0 -1
- package/lib/jsx-runtime.d.ts +1 -1
- package/lib/jsx-runtime.js +0 -1
- package/lib/jsx.d.ts +19 -22
- package/lib/jsx.js +0 -1
- package/lib/message.d.ts +17 -12
- package/lib/message.js +16 -13
- package/lib/models/system-log.d.ts +0 -3
- package/lib/models/system-log.js +1 -9
- package/lib/models/user.d.ts +0 -3
- package/lib/models/user.js +1 -8
- package/lib/notice.d.ts +16 -60
- package/lib/notice.js +1 -4
- package/lib/plugin-runtime/im/contracts.d.ts +191 -0
- package/lib/plugin-runtime/im/contracts.js +169 -0
- package/lib/plugin-runtime/im/conversation-runtime.d.ts +19 -0
- package/lib/plugin-runtime/im/conversation-runtime.js +312 -0
- package/lib/plugin-runtime/im/endpoint-runtime.d.ts +79 -0
- package/lib/plugin-runtime/im/endpoint-runtime.js +162 -0
- package/lib/plugin-runtime/im/im-runtime.d.ts +84 -0
- package/lib/plugin-runtime/im/im-runtime.js +201 -0
- package/lib/plugin-runtime/im/inbound-runtime.d.ts +31 -0
- package/lib/plugin-runtime/im/inbound-runtime.js +252 -0
- package/lib/plugin-runtime/im/index.d.ts +11 -0
- package/lib/plugin-runtime/im/index.js +9 -0
- package/lib/plugin-runtime/im/ingress-route.d.ts +10 -0
- package/lib/plugin-runtime/im/ingress-route.js +10 -0
- package/lib/plugin-runtime/im/interaction-runtime.d.ts +23 -0
- package/lib/plugin-runtime/im/interaction-runtime.js +181 -0
- package/lib/plugin-runtime/im/interactive-router.d.ts +17 -0
- package/lib/plugin-runtime/im/interactive-router.js +98 -0
- package/lib/plugin-runtime/im/login-assist-host.d.ts +6 -0
- package/lib/plugin-runtime/im/login-assist-host.js +6 -0
- package/lib/plugin-runtime/im/message-bus.d.ts +38 -0
- package/lib/plugin-runtime/im/message-bus.js +40 -0
- package/lib/plugin-runtime/im/message-dispatcher.d.ts +18 -0
- package/lib/plugin-runtime/im/message-dispatcher.js +107 -0
- package/lib/plugin-runtime/im/message-events.d.ts +26 -0
- package/lib/plugin-runtime/im/message-events.js +61 -0
- package/lib/plugin-runtime/im/outbound-delivery-runtime.d.ts +19 -0
- package/lib/plugin-runtime/im/outbound-delivery-runtime.js +165 -0
- package/lib/plugin-runtime/im/outbound-renderer.d.ts +7 -0
- package/lib/plugin-runtime/im/outbound-renderer.js +70 -0
- package/lib/plugin-runtime/im/outbound-segments.d.ts +71 -0
- package/lib/plugin-runtime/im/outbound-segments.js +219 -0
- package/lib/plugin-runtime/im/public-api.d.ts +6 -0
- package/lib/plugin-runtime/im/public-api.js +6 -0
- package/lib/plugin-runtime/im/runtime-middleware.d.ts +3 -0
- package/lib/plugin-runtime/im/runtime-middleware.js +13 -0
- package/lib/request.d.ts +17 -62
- package/lib/request.js +0 -4
- package/lib/side-event/base.d.ts +51 -0
- package/lib/side-event/base.js +30 -0
- package/lib/side-event/dispatch.d.ts +15 -0
- package/lib/side-event/dispatch.js +140 -0
- package/lib/side-event/index.d.ts +4 -0
- package/lib/side-event/index.js +4 -0
- package/lib/side-event/normalize.d.ts +38 -0
- package/lib/side-event/normalize.js +111 -0
- package/lib/side-event/types.d.ts +23 -0
- package/lib/side-event/types.js +55 -0
- package/lib/system-event.d.ts +14 -0
- package/lib/system-event.js +7 -0
- package/lib/types.d.ts +35 -193
- package/lib/types.js +0 -1
- package/lib/utils.d.ts +81 -6
- package/lib/utils.js +54 -25
- package/package.json +94 -16
- package/lib/adapter.d.ts +0 -96
- package/lib/adapter.d.ts.map +0 -1
- package/lib/adapter.js +0 -217
- package/lib/adapter.js.map +0 -1
- package/lib/agent-prompt.d.ts +0 -37
- package/lib/agent-prompt.d.ts.map +0 -1
- package/lib/agent-prompt.js +0 -2
- package/lib/agent-prompt.js.map +0 -1
- package/lib/bot.d.ts +0 -38
- package/lib/bot.d.ts.map +0 -1
- package/lib/bot.js +0 -2
- package/lib/bot.js.map +0 -1
- package/lib/built/adapter-process.d.ts +0 -43
- package/lib/built/adapter-process.d.ts.map +0 -1
- package/lib/built/adapter-process.js +0 -81
- package/lib/built/adapter-process.js.map +0 -1
- package/lib/built/agent-preset.d.ts +0 -65
- package/lib/built/agent-preset.d.ts.map +0 -1
- package/lib/built/agent-preset.js +0 -80
- package/lib/built/agent-preset.js.map +0 -1
- package/lib/built/ai-trigger.d.ts.map +0 -1
- package/lib/built/ai-trigger.js.map +0 -1
- package/lib/built/command.d.ts +0 -68
- package/lib/built/command.d.ts.map +0 -1
- package/lib/built/command.js +0 -92
- package/lib/built/command.js.map +0 -1
- package/lib/built/common-adapter-tools.d.ts.map +0 -1
- package/lib/built/common-adapter-tools.js.map +0 -1
- package/lib/built/component.d.ts +0 -69
- package/lib/built/component.d.ts.map +0 -1
- package/lib/built/component.js +0 -99
- package/lib/built/component.js.map +0 -1
- package/lib/built/config.d.ts +0 -99
- package/lib/built/config.d.ts.map +0 -1
- package/lib/built/config.js +0 -355
- package/lib/built/config.js.map +0 -1
- package/lib/built/cron.d.ts +0 -75
- package/lib/built/cron.d.ts.map +0 -1
- package/lib/built/cron.js +0 -122
- package/lib/built/cron.js.map +0 -1
- package/lib/built/database.d.ts +0 -66
- package/lib/built/database.d.ts.map +0 -1
- package/lib/built/database.js +0 -100
- package/lib/built/database.js.map +0 -1
- package/lib/built/dispatcher.d.ts +0 -139
- package/lib/built/dispatcher.d.ts.map +0 -1
- package/lib/built/dispatcher.js +0 -361
- package/lib/built/dispatcher.js.map +0 -1
- package/lib/built/html-segment-fallback.d.ts.map +0 -1
- package/lib/built/html-segment-fallback.js.map +0 -1
- package/lib/built/html-to-text.d.ts.map +0 -1
- package/lib/built/html-to-text.js.map +0 -1
- package/lib/built/inbound-runner.d.ts +0 -23
- package/lib/built/inbound-runner.d.ts.map +0 -1
- package/lib/built/inbound-runner.js +0 -37
- package/lib/built/inbound-runner.js.map +0 -1
- package/lib/built/login-assist.d.ts.map +0 -1
- package/lib/built/login-assist.js.map +0 -1
- package/lib/built/mcp-mesh-registrar.d.ts +0 -9
- package/lib/built/mcp-mesh-registrar.d.ts.map +0 -1
- package/lib/built/mcp-mesh-registrar.js +0 -17
- package/lib/built/mcp-mesh-registrar.js.map +0 -1
- package/lib/built/message-filter.d.ts +0 -177
- package/lib/built/message-filter.d.ts.map +0 -1
- package/lib/built/message-filter.js +0 -241
- package/lib/built/message-filter.js.map +0 -1
- package/lib/built/permission.d.ts +0 -55
- package/lib/built/permission.d.ts.map +0 -1
- package/lib/built/permission.js +0 -112
- package/lib/built/permission.js.map +0 -1
- package/lib/built/prepend-quote-context.d.ts +0 -35
- package/lib/built/prepend-quote-context.d.ts.map +0 -1
- package/lib/built/prepend-quote-context.js +0 -131
- package/lib/built/prepend-quote-context.js.map +0 -1
- package/lib/built/queue-im-field-contract.d.ts.map +0 -1
- package/lib/built/queue-im-field-contract.js.map +0 -1
- package/lib/built/roles.d.ts.map +0 -1
- package/lib/built/roles.js.map +0 -1
- package/lib/built/runtime-io.d.ts +0 -10
- package/lib/built/runtime-io.d.ts.map +0 -1
- package/lib/built/runtime-io.js +0 -68
- package/lib/built/runtime-io.js.map +0 -1
- package/lib/built/schema-feature.d.ts +0 -78
- package/lib/built/schema-feature.d.ts.map +0 -1
- package/lib/built/schema-feature.js +0 -132
- package/lib/built/schema-feature.js.map +0 -1
- package/lib/built/skill.d.ts +0 -121
- package/lib/built/skill.d.ts.map +0 -1
- package/lib/built/skill.js +0 -152
- package/lib/built/skill.js.map +0 -1
- package/lib/built/tool.d.ts +0 -150
- package/lib/built/tool.d.ts.map +0 -1
- package/lib/built/tool.js +0 -383
- package/lib/built/tool.js.map +0 -1
- package/lib/command.d.ts +0 -42
- package/lib/command.d.ts.map +0 -1
- package/lib/command.js +0 -75
- package/lib/command.js.map +0 -1
- package/lib/component.d.ts.map +0 -1
- package/lib/component.js.map +0 -1
- package/lib/errors.d.ts.map +0 -1
- package/lib/errors.js.map +0 -1
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/jsx-dev-runtime.d.ts.map +0 -1
- package/lib/jsx-dev-runtime.js.map +0 -1
- package/lib/jsx-runtime.d.ts.map +0 -1
- package/lib/jsx-runtime.js.map +0 -1
- package/lib/jsx.d.ts.map +0 -1
- package/lib/jsx.js.map +0 -1
- package/lib/message-quote.d.ts +0 -11
- package/lib/message-quote.d.ts.map +0 -1
- package/lib/message-quote.js +0 -91
- package/lib/message-quote.js.map +0 -1
- package/lib/message.d.ts.map +0 -1
- package/lib/message.js.map +0 -1
- package/lib/models/system-log.d.ts.map +0 -1
- package/lib/models/system-log.js.map +0 -1
- package/lib/models/user.d.ts.map +0 -1
- package/lib/models/user.js.map +0 -1
- package/lib/notice.d.ts.map +0 -1
- package/lib/notice.js.map +0 -1
- package/lib/plugin.d.ts +0 -258
- package/lib/plugin.d.ts.map +0 -1
- package/lib/plugin.js +0 -688
- package/lib/plugin.js.map +0 -1
- package/lib/prompt.d.ts +0 -118
- package/lib/prompt.d.ts.map +0 -1
- package/lib/prompt.js +0 -244
- package/lib/prompt.js.map +0 -1
- package/lib/request.d.ts.map +0 -1
- package/lib/request.js.map +0 -1
- package/lib/scheduler/scheduler.d.ts +0 -49
- package/lib/scheduler/scheduler.d.ts.map +0 -1
- package/lib/scheduler/scheduler.js +0 -352
- package/lib/scheduler/scheduler.js.map +0 -1
- package/lib/scheduler/types.d.ts +0 -71
- package/lib/scheduler/types.d.ts.map +0 -1
- package/lib/scheduler/types.js +0 -8
- package/lib/scheduler/types.js.map +0 -1
- package/lib/tool-zod.d.ts +0 -28
- package/lib/tool-zod.d.ts.map +0 -1
- package/lib/tool-zod.js +0 -98
- package/lib/tool-zod.js.map +0 -1
- package/lib/types-generator.d.ts +0 -6
- package/lib/types-generator.d.ts.map +0 -1
- package/lib/types-generator.js +0 -72
- package/lib/types-generator.js.map +0 -1
- package/lib/types.d.ts.map +0 -1
- package/lib/types.js.map +0 -1
- package/lib/utils.d.ts.map +0 -1
- package/lib/utils.js.map +0 -1
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { Schema } from '@zhin.js/schema';
|
|
2
|
+
export { isMediaRef } from '@zhin.js/im-contract';
|
|
3
|
+
const platformSchema = Schema.dict(Schema.any());
|
|
4
|
+
const mediaKindSchema = Schema.union([
|
|
5
|
+
Schema.const('url'),
|
|
6
|
+
Schema.const('path'),
|
|
7
|
+
Schema.const('base64'),
|
|
8
|
+
Schema.const('file'),
|
|
9
|
+
]);
|
|
10
|
+
export const mediaRefSchema = Schema.object({
|
|
11
|
+
kind: mediaKindSchema.required(),
|
|
12
|
+
value: Schema.string().required(),
|
|
13
|
+
mime_type: Schema.string(),
|
|
14
|
+
file_name: Schema.string(),
|
|
15
|
+
size: Schema.number(),
|
|
16
|
+
});
|
|
17
|
+
export const textSegmentSchema = Schema.object({
|
|
18
|
+
type: Schema.const('text'),
|
|
19
|
+
data: Schema.object({ text: Schema.string().required() }).required(),
|
|
20
|
+
platform: platformSchema,
|
|
21
|
+
});
|
|
22
|
+
export const mentionSegmentSchema = Schema.object({
|
|
23
|
+
type: Schema.const('mention'),
|
|
24
|
+
data: Schema.object({
|
|
25
|
+
target: Schema.string().required(),
|
|
26
|
+
name: Schema.string(),
|
|
27
|
+
}).required(),
|
|
28
|
+
platform: platformSchema,
|
|
29
|
+
});
|
|
30
|
+
export const imageSegmentSchema = Schema.object({
|
|
31
|
+
type: Schema.const('image'),
|
|
32
|
+
data: Schema.object({
|
|
33
|
+
media: mediaRefSchema.required(),
|
|
34
|
+
alt: Schema.string(),
|
|
35
|
+
}).required(),
|
|
36
|
+
platform: platformSchema,
|
|
37
|
+
});
|
|
38
|
+
export const audioSegmentSchema = Schema.object({
|
|
39
|
+
type: Schema.const('audio'),
|
|
40
|
+
data: Schema.object({
|
|
41
|
+
media: mediaRefSchema.required(),
|
|
42
|
+
duration: Schema.number(),
|
|
43
|
+
}).required(),
|
|
44
|
+
platform: platformSchema,
|
|
45
|
+
});
|
|
46
|
+
export const videoSegmentSchema = Schema.object({
|
|
47
|
+
type: Schema.const('video'),
|
|
48
|
+
data: Schema.object({
|
|
49
|
+
media: mediaRefSchema.required(),
|
|
50
|
+
duration: Schema.number(),
|
|
51
|
+
alt: Schema.string(),
|
|
52
|
+
}).required(),
|
|
53
|
+
platform: platformSchema,
|
|
54
|
+
});
|
|
55
|
+
export const fileSegmentSchema = Schema.object({
|
|
56
|
+
type: Schema.const('file'),
|
|
57
|
+
data: Schema.object({
|
|
58
|
+
media: mediaRefSchema.required(),
|
|
59
|
+
name: Schema.string(),
|
|
60
|
+
}).required(),
|
|
61
|
+
platform: platformSchema,
|
|
62
|
+
});
|
|
63
|
+
export const replySegmentSchema = Schema.object({
|
|
64
|
+
type: Schema.const('reply'),
|
|
65
|
+
data: Schema.object({ message_id: Schema.string().required() }).required(),
|
|
66
|
+
platform: platformSchema,
|
|
67
|
+
});
|
|
68
|
+
export const forwardSegmentSchema = Schema.object({
|
|
69
|
+
type: Schema.const('forward'),
|
|
70
|
+
data: Schema.object({
|
|
71
|
+
forward_id: Schema.string().required(),
|
|
72
|
+
title: Schema.string(),
|
|
73
|
+
messages: Schema.list(Schema.list(Schema.any())),
|
|
74
|
+
}).required(),
|
|
75
|
+
platform: platformSchema,
|
|
76
|
+
});
|
|
77
|
+
const stringOrNumberSchema = Schema.union([
|
|
78
|
+
Schema.string(),
|
|
79
|
+
Schema.number(),
|
|
80
|
+
]);
|
|
81
|
+
export const faceSegmentSchema = Schema.object({
|
|
82
|
+
type: Schema.const('face'),
|
|
83
|
+
data: Schema.object({
|
|
84
|
+
id: stringOrNumberSchema.required(),
|
|
85
|
+
name: Schema.string(),
|
|
86
|
+
}).required(),
|
|
87
|
+
platform: platformSchema,
|
|
88
|
+
});
|
|
89
|
+
export const diceSegmentSchema = Schema.object({
|
|
90
|
+
type: Schema.const('dice'),
|
|
91
|
+
data: Schema.object({ result: Schema.number() }).required(),
|
|
92
|
+
platform: platformSchema,
|
|
93
|
+
});
|
|
94
|
+
export const rpsSegmentSchema = Schema.object({
|
|
95
|
+
type: Schema.const('rps'),
|
|
96
|
+
data: Schema.object({ result: Schema.number() }).required(),
|
|
97
|
+
platform: platformSchema,
|
|
98
|
+
});
|
|
99
|
+
export const canonicalSegmentSchema = Schema.discriminatedUnion('type', {
|
|
100
|
+
text: {
|
|
101
|
+
data: Schema.object({ text: Schema.string().required() }).required(),
|
|
102
|
+
platform: platformSchema,
|
|
103
|
+
},
|
|
104
|
+
mention: {
|
|
105
|
+
data: Schema.object({
|
|
106
|
+
target: Schema.string().required(),
|
|
107
|
+
name: Schema.string(),
|
|
108
|
+
}).required(),
|
|
109
|
+
platform: platformSchema,
|
|
110
|
+
},
|
|
111
|
+
image: {
|
|
112
|
+
data: Schema.object({
|
|
113
|
+
media: mediaRefSchema.required(),
|
|
114
|
+
alt: Schema.string(),
|
|
115
|
+
}).required(),
|
|
116
|
+
platform: platformSchema,
|
|
117
|
+
},
|
|
118
|
+
audio: {
|
|
119
|
+
data: Schema.object({
|
|
120
|
+
media: mediaRefSchema.required(),
|
|
121
|
+
duration: Schema.number(),
|
|
122
|
+
}).required(),
|
|
123
|
+
platform: platformSchema,
|
|
124
|
+
},
|
|
125
|
+
video: {
|
|
126
|
+
data: Schema.object({
|
|
127
|
+
media: mediaRefSchema.required(),
|
|
128
|
+
duration: Schema.number(),
|
|
129
|
+
alt: Schema.string(),
|
|
130
|
+
}).required(),
|
|
131
|
+
platform: platformSchema,
|
|
132
|
+
},
|
|
133
|
+
file: {
|
|
134
|
+
data: Schema.object({
|
|
135
|
+
media: mediaRefSchema.required(),
|
|
136
|
+
name: Schema.string(),
|
|
137
|
+
}).required(),
|
|
138
|
+
platform: platformSchema,
|
|
139
|
+
},
|
|
140
|
+
reply: {
|
|
141
|
+
data: Schema.object({ message_id: Schema.string().required() }).required(),
|
|
142
|
+
platform: platformSchema,
|
|
143
|
+
},
|
|
144
|
+
forward: {
|
|
145
|
+
data: Schema.object({
|
|
146
|
+
forward_id: Schema.string().required(),
|
|
147
|
+
title: Schema.string(),
|
|
148
|
+
messages: Schema.list(Schema.list(Schema.any())),
|
|
149
|
+
}).required(),
|
|
150
|
+
platform: platformSchema,
|
|
151
|
+
},
|
|
152
|
+
face: {
|
|
153
|
+
data: Schema.object({
|
|
154
|
+
id: stringOrNumberSchema.required(),
|
|
155
|
+
name: Schema.string(),
|
|
156
|
+
}).required(),
|
|
157
|
+
platform: platformSchema,
|
|
158
|
+
},
|
|
159
|
+
dice: {
|
|
160
|
+
data: Schema.object({ result: Schema.number() }).required(),
|
|
161
|
+
platform: platformSchema,
|
|
162
|
+
},
|
|
163
|
+
rps: {
|
|
164
|
+
data: Schema.object({ result: Schema.number() }).required(),
|
|
165
|
+
platform: platformSchema,
|
|
166
|
+
},
|
|
167
|
+
});
|
|
168
|
+
export const segmentArraySchema = Schema.list(canonicalSegmentSchema);
|
|
169
|
+
/** 严格 canonical 段校验(@zhin.js/schema validate-only) */
|
|
170
|
+
export function isStrictCanonicalSegment(value) {
|
|
171
|
+
return canonicalSegmentSchema.safeParse(value).success;
|
|
172
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type PermissionHost } from '@zhin.js/permission';
|
|
2
|
+
import type { Message } from '../message.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<any>, 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.$adapter);
|
|
7
|
+
const scope = (message.$channel?.type || 'private');
|
|
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));
|
|
17
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { UserInteractionContent, UserInteractionRequest } from '@zhin.js/interaction';
|
|
2
|
+
import type { SendContent } from '../plugin-runtime/im/contracts.js';
|
|
3
|
+
import type { ButtonStyle } from './interactive-segments/types.js';
|
|
4
|
+
export interface UserInteractionAction {
|
|
5
|
+
readonly label: string;
|
|
6
|
+
readonly value: string;
|
|
7
|
+
readonly style?: ButtonStyle;
|
|
8
|
+
}
|
|
9
|
+
export interface UserInteractionView extends UserInteractionContent {
|
|
10
|
+
readonly actions?: readonly UserInteractionAction[];
|
|
11
|
+
}
|
|
12
|
+
export interface UserInteractionProgress extends UserInteractionContent {
|
|
13
|
+
readonly index: number;
|
|
14
|
+
readonly total: number;
|
|
15
|
+
}
|
|
16
|
+
export type UserInteractionParseResult = Readonly<{
|
|
17
|
+
ok: true;
|
|
18
|
+
value: unknown;
|
|
19
|
+
}> | Readonly<{
|
|
20
|
+
ok: false;
|
|
21
|
+
message: string;
|
|
22
|
+
}>;
|
|
23
|
+
/** Fail early for interaction definitions that could never produce an unambiguous answer. */
|
|
24
|
+
export declare function assertUserInteractionRequest(request: UserInteractionRequest): void;
|
|
25
|
+
/** Project semantic content into canonical Markdown + keyboard segments. */
|
|
26
|
+
export declare function renderUserInteraction(view: UserInteractionView): SendContent;
|
|
27
|
+
/** Derive presentation and controls from one discriminated request. */
|
|
28
|
+
export declare function projectUserInteraction(request: UserInteractionRequest, progress?: UserInteractionProgress): UserInteractionView;
|
|
29
|
+
/** Parse and validate one user reply without transport knowledge. */
|
|
30
|
+
export declare function parseUserInteractionAnswer(request: UserInteractionRequest, rawInput: string): UserInteractionParseResult;
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
/** Fail early for interaction definitions that could never produce an unambiguous answer. */
|
|
2
|
+
export function assertUserInteractionRequest(request) {
|
|
3
|
+
if (!request.title.trim())
|
|
4
|
+
throw new TypeError('User interaction title must not be empty');
|
|
5
|
+
if (request.timeout !== undefined && (!Number.isFinite(request.timeout) || request.timeout <= 0)) {
|
|
6
|
+
throw new RangeError('User interaction timeout must be a positive finite number');
|
|
7
|
+
}
|
|
8
|
+
if (request.type === 'text' && !validRange(request.minLength, request.maxLength)) {
|
|
9
|
+
throw new RangeError('User interaction text length range is invalid');
|
|
10
|
+
}
|
|
11
|
+
if (request.type === 'number' && !validBounds(request.min, request.max)) {
|
|
12
|
+
throw new RangeError('User interaction number range is invalid');
|
|
13
|
+
}
|
|
14
|
+
if (request.type === 'select' || request.type === 'multiselect') {
|
|
15
|
+
if (request.options.length === 0)
|
|
16
|
+
throw new TypeError('User interaction options must not be empty');
|
|
17
|
+
for (const option of request.options) {
|
|
18
|
+
const label = option.label.trim().toLocaleLowerCase();
|
|
19
|
+
if (!label)
|
|
20
|
+
throw new TypeError('User interaction option label must not be empty');
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
if (request.type === 'multiselect') {
|
|
24
|
+
if (request.separator === '')
|
|
25
|
+
throw new TypeError('User interaction separator must not be empty');
|
|
26
|
+
if (!validRange(request.minSelections, request.maxSelections)) {
|
|
27
|
+
throw new RangeError('User interaction selection range is invalid');
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
if (request.type === 'list') {
|
|
31
|
+
if (request.separator === '')
|
|
32
|
+
throw new TypeError('User interaction separator must not be empty');
|
|
33
|
+
if (!validRange(request.minItems, request.maxItems)) {
|
|
34
|
+
throw new RangeError('User interaction list length range is invalid');
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/** Project semantic content into canonical Markdown + keyboard segments. */
|
|
39
|
+
export function renderUserInteraction(view) {
|
|
40
|
+
const markdown = [
|
|
41
|
+
`### ${view.title}`,
|
|
42
|
+
view.description?.trim(),
|
|
43
|
+
view.tip?.trim() ? quoteTip(view.tip.trim()) : undefined,
|
|
44
|
+
].filter((part) => !!part).join('\n\n');
|
|
45
|
+
const actions = view.actions ?? [];
|
|
46
|
+
if (actions.length === 0) {
|
|
47
|
+
return [{ type: 'markdown', data: { content: markdown } }];
|
|
48
|
+
}
|
|
49
|
+
const buttons = actions.map((action, index) => ({
|
|
50
|
+
id: `interaction-${index + 1}`,
|
|
51
|
+
label: action.label,
|
|
52
|
+
payload: action.value,
|
|
53
|
+
...(action.style ? { style: action.style } : {}),
|
|
54
|
+
mode: 'command',
|
|
55
|
+
command: { enter: true, reply: false },
|
|
56
|
+
}));
|
|
57
|
+
return [
|
|
58
|
+
{ type: 'markdown', data: { content: markdown } },
|
|
59
|
+
{
|
|
60
|
+
type: 'keyboard',
|
|
61
|
+
data: {
|
|
62
|
+
rows: chunk(buttons, 5),
|
|
63
|
+
fallback: {
|
|
64
|
+
hint: '也可以直接回复对应内容。',
|
|
65
|
+
map: Object.fromEntries(actions.map((action, index) => [String(index + 1), action.value])),
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
];
|
|
70
|
+
}
|
|
71
|
+
/** Derive presentation and controls from one discriminated request. */
|
|
72
|
+
export function projectUserInteraction(request, progress) {
|
|
73
|
+
const instruction = instructionFor(request);
|
|
74
|
+
const optionList = request.type === 'select' || request.type === 'multiselect'
|
|
75
|
+
? renderOptions(request.options)
|
|
76
|
+
: undefined;
|
|
77
|
+
const optionsHaveDescriptions = request.type === 'select' || request.type === 'multiselect'
|
|
78
|
+
? request.options.some((option) => !!option.description)
|
|
79
|
+
: false;
|
|
80
|
+
const actions = actionsFor(request);
|
|
81
|
+
const stepDescription = [
|
|
82
|
+
progress ? `**${progress.index}/${progress.total} · ${request.title}**` : undefined,
|
|
83
|
+
request.description,
|
|
84
|
+
optionList && (!actions || optionsHaveDescriptions) ? optionList : undefined,
|
|
85
|
+
].filter((part) => !!part).join('\n\n');
|
|
86
|
+
return Object.freeze({
|
|
87
|
+
title: progress?.title ?? request.title,
|
|
88
|
+
description: progress
|
|
89
|
+
? [progress.description, stepDescription].filter(Boolean).join('\n\n')
|
|
90
|
+
: stepDescription || undefined,
|
|
91
|
+
tip: [request.tip, instruction, progress?.tip].filter(Boolean).join('\n'),
|
|
92
|
+
...(actions ? { actions: Object.freeze(actions) } : {}),
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
/** Parse and validate one user reply without transport knowledge. */
|
|
96
|
+
export function parseUserInteractionAnswer(request, rawInput) {
|
|
97
|
+
const raw = rawInput.trim();
|
|
98
|
+
switch (request.type) {
|
|
99
|
+
case 'text': {
|
|
100
|
+
if (raw.length < (request.minLength ?? 0))
|
|
101
|
+
return invalid(`请至少输入 ${request.minLength} 个字符`);
|
|
102
|
+
if (request.maxLength !== undefined && raw.length > request.maxLength) {
|
|
103
|
+
return invalid(`请不要超过 ${request.maxLength} 个字符`);
|
|
104
|
+
}
|
|
105
|
+
if (request.pattern) {
|
|
106
|
+
request.pattern.lastIndex = 0;
|
|
107
|
+
if (!request.pattern.test(raw))
|
|
108
|
+
return invalid('输入格式不正确');
|
|
109
|
+
}
|
|
110
|
+
return valid(raw);
|
|
111
|
+
}
|
|
112
|
+
case 'number': {
|
|
113
|
+
const value = Number(raw);
|
|
114
|
+
if (!raw || !Number.isFinite(value))
|
|
115
|
+
return invalid('请输入有效数字');
|
|
116
|
+
if (request.integer && !Number.isInteger(value))
|
|
117
|
+
return invalid('请输入整数');
|
|
118
|
+
if (request.min !== undefined && value < request.min)
|
|
119
|
+
return invalid(`请输入不小于 ${request.min} 的数字`);
|
|
120
|
+
if (request.max !== undefined && value > request.max)
|
|
121
|
+
return invalid(`请输入不大于 ${request.max} 的数字`);
|
|
122
|
+
return valid(value);
|
|
123
|
+
}
|
|
124
|
+
case 'confirm': {
|
|
125
|
+
const normalized = raw.toLocaleLowerCase();
|
|
126
|
+
const confirmLabel = request.confirmLabel?.trim().toLocaleLowerCase();
|
|
127
|
+
const cancelLabel = request.cancelLabel?.trim().toLocaleLowerCase();
|
|
128
|
+
if (CONFIRM_VALUES.has(normalized) || (confirmLabel && normalized === confirmLabel))
|
|
129
|
+
return valid(true);
|
|
130
|
+
if (CANCEL_VALUES.has(normalized) || (cancelLabel && normalized === cancelLabel))
|
|
131
|
+
return valid(false);
|
|
132
|
+
return invalid('请选择确认或取消');
|
|
133
|
+
}
|
|
134
|
+
case 'select': {
|
|
135
|
+
const option = resolveOption(request.options, raw);
|
|
136
|
+
return option ? valid(option.value) : invalid('请选择一个有效选项');
|
|
137
|
+
}
|
|
138
|
+
case 'multiselect': {
|
|
139
|
+
const separator = request.separator ?? ',';
|
|
140
|
+
const tokens = raw.split(separator).map((token) => token.trim()).filter(Boolean);
|
|
141
|
+
const selected = uniqueOptions(tokens.map((token) => resolveOption(request.options, token)));
|
|
142
|
+
if (selected.length !== tokens.length)
|
|
143
|
+
return invalid('多选中包含无效选项');
|
|
144
|
+
if (selected.length < (request.minSelections ?? 0))
|
|
145
|
+
return invalid(`请至少选择 ${request.minSelections} 项`);
|
|
146
|
+
if (request.maxSelections !== undefined && selected.length > request.maxSelections) {
|
|
147
|
+
return invalid(`请最多选择 ${request.maxSelections} 项`);
|
|
148
|
+
}
|
|
149
|
+
return valid(Object.freeze(selected.map((option) => option.value)));
|
|
150
|
+
}
|
|
151
|
+
case 'list': {
|
|
152
|
+
const separator = request.separator ?? ',';
|
|
153
|
+
const tokens = raw.split(separator).map((token) => token.trim()).filter(Boolean);
|
|
154
|
+
if (tokens.length < (request.minItems ?? 0))
|
|
155
|
+
return invalid(`请至少输入 ${request.minItems} 项`);
|
|
156
|
+
if (request.maxItems !== undefined && tokens.length > request.maxItems)
|
|
157
|
+
return invalid(`请最多输入 ${request.maxItems} 项`);
|
|
158
|
+
if (request.valueType === 'number') {
|
|
159
|
+
const values = tokens.map(Number);
|
|
160
|
+
return values.every(Number.isFinite) ? valid(Object.freeze(values)) : invalid('列表中包含无效数字');
|
|
161
|
+
}
|
|
162
|
+
if (request.valueType === 'boolean') {
|
|
163
|
+
const values = tokens.map(parseBoolean);
|
|
164
|
+
return values.every((value) => value !== undefined)
|
|
165
|
+
? valid(Object.freeze(values))
|
|
166
|
+
: invalid('布尔列表只接受 true/false、yes/no 或 是/否');
|
|
167
|
+
}
|
|
168
|
+
return valid(Object.freeze(tokens));
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
function actionsFor(request) {
|
|
173
|
+
if (request.type === 'confirm') {
|
|
174
|
+
return [
|
|
175
|
+
{ label: request.confirmLabel ?? '确认', value: 'yes', style: 'primary' },
|
|
176
|
+
{ label: request.cancelLabel ?? '取消', value: 'no', style: 'danger' },
|
|
177
|
+
];
|
|
178
|
+
}
|
|
179
|
+
if (request.type === 'select' && request.options.length <= 10) {
|
|
180
|
+
return request.options.map((option, index) => ({ label: option.label, value: String(index + 1), style: 'secondary' }));
|
|
181
|
+
}
|
|
182
|
+
return undefined;
|
|
183
|
+
}
|
|
184
|
+
function instructionFor(request) {
|
|
185
|
+
switch (request.type) {
|
|
186
|
+
case 'confirm': return '请选择确认或取消。';
|
|
187
|
+
case 'select': return '可以点击按钮,或回复序号/选项名称。';
|
|
188
|
+
case 'multiselect': return `回复序号或选项名称,多项用“${request.separator ?? ','}”分隔。`;
|
|
189
|
+
case 'list': return `多项用“${request.separator ?? ','}”分隔。`;
|
|
190
|
+
default: return undefined;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
function renderOptions(options) {
|
|
194
|
+
return options.map((option, index) => `${index + 1}. ${option.label}${option.description ? ` — ${option.description}` : ''}`).join('\n');
|
|
195
|
+
}
|
|
196
|
+
function resolveOption(options, raw) {
|
|
197
|
+
const index = Number(raw);
|
|
198
|
+
if (Number.isInteger(index) && index >= 1 && index <= options.length)
|
|
199
|
+
return options[index - 1];
|
|
200
|
+
const normalized = raw.toLocaleLowerCase();
|
|
201
|
+
return options.find((option) => option.label.trim().toLocaleLowerCase() === normalized);
|
|
202
|
+
}
|
|
203
|
+
function uniqueOptions(options) {
|
|
204
|
+
const result = [];
|
|
205
|
+
for (const option of options)
|
|
206
|
+
if (option && !result.includes(option))
|
|
207
|
+
result.push(option);
|
|
208
|
+
return result;
|
|
209
|
+
}
|
|
210
|
+
function parseBoolean(raw) {
|
|
211
|
+
const normalized = raw.toLocaleLowerCase();
|
|
212
|
+
if (CONFIRM_VALUES.has(normalized))
|
|
213
|
+
return true;
|
|
214
|
+
if (CANCEL_VALUES.has(normalized))
|
|
215
|
+
return false;
|
|
216
|
+
return undefined;
|
|
217
|
+
}
|
|
218
|
+
function quoteTip(tip) {
|
|
219
|
+
return tip.split('\n').map((line) => `> 💡 ${line}`).join('\n');
|
|
220
|
+
}
|
|
221
|
+
function valid(value) {
|
|
222
|
+
return Object.freeze({ ok: true, value });
|
|
223
|
+
}
|
|
224
|
+
function invalid(message) {
|
|
225
|
+
return Object.freeze({ ok: false, message });
|
|
226
|
+
}
|
|
227
|
+
function validRange(minimum, maximum) {
|
|
228
|
+
return (minimum === undefined || (Number.isFinite(minimum) && minimum >= 0))
|
|
229
|
+
&& (maximum === undefined || (Number.isFinite(maximum) && maximum >= 0))
|
|
230
|
+
&& (minimum === undefined || maximum === undefined || minimum <= maximum);
|
|
231
|
+
}
|
|
232
|
+
function validBounds(minimum, maximum) {
|
|
233
|
+
return (minimum === undefined || Number.isFinite(minimum))
|
|
234
|
+
&& (maximum === undefined || Number.isFinite(maximum))
|
|
235
|
+
&& (minimum === undefined || maximum === undefined || minimum <= maximum);
|
|
236
|
+
}
|
|
237
|
+
const CONFIRM_VALUES = new Set(['1', 'y', 'yes', 'true', '是', '确认', '同意']);
|
|
238
|
+
const CANCEL_VALUES = new Set(['2', 'n', 'no', 'false', '否', '取消', '拒绝']);
|
|
239
|
+
function chunk(items, size) {
|
|
240
|
+
const rows = [];
|
|
241
|
+
for (let index = 0; index < items.length; index += size)
|
|
242
|
+
rows.push(items.slice(index, index + size));
|
|
243
|
+
return rows;
|
|
244
|
+
}
|
package/lib/component.d.ts
CHANGED
package/lib/component.js
CHANGED
|
@@ -176,24 +176,41 @@ function parseAttributeValue(str, startIndex, context) {
|
|
|
176
176
|
function evaluateQuotedExpression(quotedValue, context) {
|
|
177
177
|
if (!context)
|
|
178
178
|
return quotedValue;
|
|
179
|
-
|
|
180
|
-
let
|
|
181
|
-
const
|
|
182
|
-
|
|
183
|
-
while ((match = expressionRegex.exec(quotedValue)) !== null) {
|
|
184
|
-
const expr = match[1];
|
|
179
|
+
let result = '';
|
|
180
|
+
let cursor = 0;
|
|
181
|
+
for (const match of readBraceExpressions(quotedValue)) {
|
|
182
|
+
result += quotedValue.slice(cursor, match.start);
|
|
185
183
|
try {
|
|
186
|
-
const value = context.getValue(expr);
|
|
187
|
-
if (value !== undefined && value !== expr) {
|
|
184
|
+
const value = context.getValue(match.expr);
|
|
185
|
+
if (value !== undefined && value !== match.expr) {
|
|
188
186
|
const stringValue = typeof value === 'string' ? value : JSON.stringify(value);
|
|
189
|
-
result
|
|
187
|
+
result += stringValue;
|
|
188
|
+
}
|
|
189
|
+
else {
|
|
190
|
+
result += quotedValue.slice(match.start, match.end);
|
|
190
191
|
}
|
|
191
192
|
}
|
|
192
193
|
catch (error) {
|
|
193
|
-
|
|
194
|
+
result += quotedValue.slice(match.start, match.end);
|
|
194
195
|
}
|
|
196
|
+
cursor = match.end;
|
|
195
197
|
}
|
|
196
|
-
return result;
|
|
198
|
+
return result + quotedValue.slice(cursor);
|
|
199
|
+
}
|
|
200
|
+
function readBraceExpressions(value) {
|
|
201
|
+
const matches = [];
|
|
202
|
+
let cursor = 0;
|
|
203
|
+
while (cursor < value.length) {
|
|
204
|
+
const start = value.indexOf('{', cursor);
|
|
205
|
+
if (start < 0)
|
|
206
|
+
break;
|
|
207
|
+
const end = value.indexOf('}', start + 1);
|
|
208
|
+
if (end < 0)
|
|
209
|
+
break;
|
|
210
|
+
matches.push({ start, end: end + 1, expr: value.slice(start + 1, end) });
|
|
211
|
+
cursor = end + 1;
|
|
212
|
+
}
|
|
213
|
+
return matches;
|
|
197
214
|
}
|
|
198
215
|
/**
|
|
199
216
|
* 解析表达式值
|
|
@@ -546,7 +563,7 @@ export async function renderComponents(componentMap, options, customContext) {
|
|
|
546
563
|
}
|
|
547
564
|
// 内置组件
|
|
548
565
|
export const Fragment = defineComponent(async (props, context) => {
|
|
549
|
-
|
|
566
|
+
const children = props.children || '';
|
|
550
567
|
if (Array.isArray(children)) {
|
|
551
568
|
return children.join('');
|
|
552
569
|
}
|
|
@@ -562,6 +579,5 @@ export const Fragment = defineComponent(async (props, context) => {
|
|
|
562
579
|
return String(children);
|
|
563
580
|
}, 'Fragment');
|
|
564
581
|
export const Fetch = defineComponent(async ({ url }) => {
|
|
565
|
-
return await fetch(url).then((r) => r.text());
|
|
582
|
+
return await fetch(url, { signal: AbortSignal.timeout(30_000) }).then((r) => r.text());
|
|
566
583
|
}, 'fetch');
|
|
567
|
-
//# sourceMappingURL=component.js.map
|
package/lib/errors.d.ts
CHANGED
|
@@ -8,8 +8,8 @@ import { ZhinError } from '@zhin.js/kernel';
|
|
|
8
8
|
*/
|
|
9
9
|
export declare class AdapterError extends ZhinError {
|
|
10
10
|
readonly adapterName: string;
|
|
11
|
-
readonly
|
|
12
|
-
constructor(message: string, adapterName: string,
|
|
11
|
+
readonly endpointKey?: string;
|
|
12
|
+
constructor(message: string, adapterName: string, endpointKey?: string, context?: Record<string, any>);
|
|
13
13
|
}
|
|
14
14
|
/**
|
|
15
15
|
* 消息处理错误
|
|
@@ -19,4 +19,3 @@ export declare class MessageError extends ZhinError {
|
|
|
19
19
|
readonly channelId?: string;
|
|
20
20
|
constructor(message: string, messageId?: string, channelId?: string, context?: Record<string, any>);
|
|
21
21
|
}
|
|
22
|
-
//# sourceMappingURL=errors.d.ts.map
|
package/lib/errors.js
CHANGED
|
@@ -8,11 +8,11 @@ import { ZhinError } from '@zhin.js/kernel';
|
|
|
8
8
|
*/
|
|
9
9
|
export class AdapterError extends ZhinError {
|
|
10
10
|
adapterName;
|
|
11
|
-
|
|
12
|
-
constructor(message, adapterName,
|
|
13
|
-
super(message, 'ADAPTER_ERROR', { ...context, adapterName,
|
|
11
|
+
endpointKey;
|
|
12
|
+
constructor(message, adapterName, endpointKey, context) {
|
|
13
|
+
super(message, 'ADAPTER_ERROR', { ...context, adapterName, endpointKey });
|
|
14
14
|
this.adapterName = adapterName;
|
|
15
|
-
this.
|
|
15
|
+
this.endpointKey = endpointKey;
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
18
|
/**
|
|
@@ -27,4 +27,3 @@ export class MessageError extends ZhinError {
|
|
|
27
27
|
this.channelId = channelId;
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
|
-
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/** Authoring API for Handler Feature — implementation in `@zhin.js/handler`. */
|
|
2
|
+
export { parseHandlerDefinition, HandlerIndex, isHandlerIndex, handlerFeatureId, handlerFeature, handlerEventFromLocalName, resolveHandlerEvent, type HandlerEventMap, type HandlerDefinition, type HandlerDescriptor, type HandlerContext, type HandlerDispatchOptions, } from '@zhin.js/handler';
|
|
3
|
+
import { type HandlerContext, type HandlerDefinition, type HandlerEventMap } from '@zhin.js/handler';
|
|
4
|
+
import type { Message } from '../plugin-runtime/im/contracts.js';
|
|
5
|
+
import type { Notice } from '../notice.js';
|
|
6
|
+
import type { Request } from '../request.js';
|
|
7
|
+
import type { SystemEvent } from '../system-event.js';
|
|
8
|
+
import type { AdapterClient, AdapterEvents, EndpointEvent, EndpointIdentity, PlatformEvent, RegisteredAdapterName } from '@zhin.js/adapter';
|
|
9
|
+
declare module '@zhin.js/handler' {
|
|
10
|
+
interface HandlerEventMap {
|
|
11
|
+
'message.receive': [event: EndpointEvent<Message>];
|
|
12
|
+
'notice.receive': [event: EndpointEvent<Notice>];
|
|
13
|
+
'request.receive': [event: EndpointEvent<Request>];
|
|
14
|
+
'system.receive': [event: EndpointEvent<SystemEvent>];
|
|
15
|
+
'platform.receive': [event: EndpointEvent<PlatformEvent>];
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
type NativeEventName<TAdapter extends RegisteredAdapterName> = Extract<keyof AdapterEvents<TAdapter>, string>;
|
|
19
|
+
/** Fully inferred native platform event exposed to plugin handlers. */
|
|
20
|
+
export interface ClientHandlerEvent<TAdapter extends RegisteredAdapterName, TName extends NativeEventName<TAdapter> = NativeEventName<TAdapter>> {
|
|
21
|
+
readonly name: TName;
|
|
22
|
+
readonly event: AdapterEvents<TAdapter>[TName];
|
|
23
|
+
readonly endpoint: EndpointIdentity;
|
|
24
|
+
readonly client: AdapterClient<TAdapter>;
|
|
25
|
+
}
|
|
26
|
+
export interface ClientHandlerOptions<TAdapter extends RegisteredAdapterName, TName extends NativeEventName<TAdapter>> {
|
|
27
|
+
readonly adapter: TAdapter;
|
|
28
|
+
readonly event: TName;
|
|
29
|
+
handle(this: HandlerContext, event: ClientHandlerEvent<TAdapter, TName>): void | Promise<void>;
|
|
30
|
+
}
|
|
31
|
+
export interface ClientHandlerWildcardEvent<TAdapter extends RegisteredAdapterName> {
|
|
32
|
+
readonly name: string;
|
|
33
|
+
readonly event: unknown;
|
|
34
|
+
readonly endpoint: EndpointIdentity;
|
|
35
|
+
readonly client: AdapterClient<TAdapter>;
|
|
36
|
+
}
|
|
37
|
+
export interface ClientHandlerWildcardOptions<TAdapter extends RegisteredAdapterName> {
|
|
38
|
+
readonly adapter: TAdapter;
|
|
39
|
+
readonly event: '*';
|
|
40
|
+
handle(this: HandlerContext, event: ClientHandlerWildcardEvent<TAdapter>): void | Promise<void>;
|
|
41
|
+
}
|
|
42
|
+
export declare function defineHandler<TAdapter extends RegisteredAdapterName, TName extends NativeEventName<TAdapter>>(options: ClientHandlerOptions<TAdapter, TName>): Readonly<HandlerDefinition<'platform.receive'>>;
|
|
43
|
+
/** Handle every native event from one Client without pretending unknown payloads are typed. */
|
|
44
|
+
export declare function defineHandler<TAdapter extends RegisteredAdapterName>(options: ClientHandlerWildcardOptions<TAdapter>): Readonly<HandlerDefinition<'platform.receive'>>;
|
|
45
|
+
export declare function defineHandler<K extends keyof HandlerEventMap & string>(options: {
|
|
46
|
+
readonly event: K;
|
|
47
|
+
handle(this: HandlerContext, ...args: HandlerEventMap[K] extends unknown[] ? HandlerEventMap[K] : unknown[]): void | Promise<void>;
|
|
48
|
+
}): Readonly<HandlerDefinition<K>>;
|