@zhin.js/core 1.3.1 → 1.3.3
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 +66 -11
- package/lib/adapter.d.ts +41 -3
- package/lib/adapter.js +110 -6
- package/lib/agent-prompt.d.ts +0 -1
- package/lib/agent-prompt.js +0 -1
- package/lib/built/adapter-process.d.ts +11 -2
- package/lib/built/adapter-process.js +43 -2
- package/lib/built/agent-preset.d.ts +0 -1
- package/lib/built/agent-preset.js +0 -1
- package/lib/built/ai-access.d.ts +36 -0
- package/lib/built/ai-access.js +46 -0
- package/lib/built/ai-outbound/adapter-access.d.ts +3 -0
- package/lib/built/ai-outbound/adapter-access.js +9 -0
- package/lib/built/ai-outbound/extensions/onebot-keyboard.d.ts +2 -0
- package/lib/built/ai-outbound/extensions/onebot-keyboard.js +67 -0
- package/lib/built/ai-outbound/extensions/qq-message.d.ts +3 -0
- package/lib/built/ai-outbound/extensions/qq-message.js +23 -0
- package/lib/built/ai-outbound/index.d.ts +9 -0
- package/lib/built/ai-outbound/index.js +9 -0
- package/lib/built/ai-outbound/parse.d.ts +13 -0
- package/lib/built/ai-outbound/parse.js +94 -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 +7 -0
- package/lib/built/ai-outbound/types.d.ts +60 -0
- package/lib/built/ai-outbound/types.js +5 -0
- package/lib/built/ai-trigger.d.ts +5 -1
- package/lib/built/ai-trigger.js +3 -7
- package/lib/built/authorization.d.ts +0 -1
- package/lib/built/authorization.js +0 -1
- package/lib/built/command.d.ts +2 -1
- package/lib/built/command.js +14 -4
- package/lib/built/common-adapter-tools.d.ts +25 -26
- package/lib/built/common-adapter-tools.js +48 -49
- package/lib/built/component.d.ts +0 -1
- package/lib/built/component.js +1 -3
- package/lib/built/config.d.ts +4 -1
- package/lib/built/config.js +26 -5
- package/lib/built/connect-endpoint-instance.d.ts +0 -1
- package/lib/built/connect-endpoint-instance.js +3 -2
- package/lib/built/database.d.ts +0 -1
- package/lib/built/database.js +1 -3
- package/lib/built/dispatcher.d.ts +6 -6
- package/lib/built/dispatcher.js +20 -8
- package/lib/built/endpoint-commands.d.ts +3 -0
- package/lib/built/endpoint-commands.js +99 -0
- package/lib/built/endpoint-lifecycle-service.d.ts +28 -0
- package/lib/built/endpoint-lifecycle-service.js +241 -0
- package/lib/built/endpoint-lifecycle.d.ts +0 -1
- package/lib/built/endpoint-lifecycle.js +0 -1
- package/lib/built/endpoint-manager.d.ts +34 -0
- package/lib/built/endpoint-manager.js +1 -0
- package/lib/built/generated-qrcode.d.ts +24 -0
- package/lib/built/generated-qrcode.js +45 -0
- package/lib/built/generic-segment-mapper.d.ts +6 -0
- package/lib/built/generic-segment-mapper.js +232 -0
- package/lib/built/html-renderer-loader.d.ts +13 -0
- package/lib/built/html-renderer-loader.js +33 -0
- package/lib/built/html-segment-fallback.d.ts +2 -2
- package/lib/built/html-segment-fallback.js +0 -1
- package/lib/built/html-to-text.d.ts +0 -1
- package/lib/built/html-to-text.js +0 -1
- package/lib/built/inbound-pipeline.d.ts +0 -1
- package/lib/built/inbound-pipeline.js +0 -1
- package/lib/built/inbound-runner.d.ts +0 -1
- package/lib/built/inbound-runner.js +0 -1
- package/lib/built/interactive-segment-contract.d.ts +6 -0
- package/lib/built/interactive-segment-contract.js +9 -0
- package/lib/built/interactive-segments/action.d.ts +17 -0
- package/lib/built/interactive-segments/action.js +54 -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/handlers.d.ts +9 -0
- package/lib/built/interactive-segments/handlers.js +58 -0
- package/lib/built/interactive-segments/index.d.ts +7 -0
- package/lib/built/interactive-segments/index.js +7 -0
- package/lib/built/interactive-segments/keyboard-segment.d.ts +12 -0
- package/lib/built/interactive-segments/keyboard-segment.js +13 -0
- package/lib/built/interactive-segments/onebot-keyboard.d.ts +10 -0
- package/lib/built/interactive-segments/onebot-keyboard.js +53 -0
- package/lib/built/interactive-segments/resolve.d.ts +9 -0
- package/lib/built/interactive-segments/resolve.js +84 -0
- package/lib/built/interactive-segments/types.d.ts +62 -0
- package/lib/built/interactive-segments/types.js +13 -0
- package/lib/built/introspection-format.d.ts +10 -0
- package/lib/built/introspection-format.js +28 -0
- package/lib/built/login-assist.d.ts +1 -2
- package/lib/built/login-assist.js +0 -1
- package/lib/built/management-command-guard.d.ts +15 -0
- package/lib/built/management-command-guard.js +25 -0
- package/lib/built/message-enrich.d.ts +0 -1
- package/lib/built/message-enrich.js +0 -1
- package/lib/built/message-filter.d.ts +0 -1
- package/lib/built/message-filter.js +1 -3
- package/lib/built/optional-peer-import.d.ts +3 -0
- package/lib/built/optional-peer-import.js +33 -0
- package/lib/built/outbound-media-contract.d.ts +22 -0
- package/lib/built/outbound-media-contract.js +10 -0
- package/lib/built/outbound-media-utils.d.ts +9 -0
- package/lib/built/outbound-media-utils.js +62 -0
- package/lib/built/permission.d.ts +0 -1
- package/lib/built/permission.js +1 -3
- package/lib/built/permit-check.d.ts +0 -1
- package/lib/built/permit-check.js +0 -1
- package/lib/built/permit-parse.d.ts +0 -1
- package/lib/built/permit-parse.js +0 -1
- package/lib/built/platform-permit.d.ts +5 -6
- package/lib/built/platform-permit.js +11 -12
- package/lib/built/prepend-quote-context.d.ts +0 -1
- package/lib/built/prepend-quote-context.js +0 -1
- package/lib/built/qrcode-segment.d.ts +18 -0
- package/lib/built/qrcode-segment.js +78 -0
- package/lib/built/queue-im-field-contract.d.ts +6 -1
- package/lib/built/queue-im-field-contract.js +10 -1
- package/lib/built/rich-segments/adapter-policies.d.ts +9 -0
- package/lib/built/rich-segments/adapter-policies.js +27 -0
- package/lib/built/rich-segments/base.d.ts +11 -0
- package/lib/built/rich-segments/base.js +24 -0
- package/lib/built/rich-segments/builtins.d.ts +4 -0
- package/lib/built/rich-segments/builtins.js +40 -0
- package/lib/built/rich-segments/capabilities.d.ts +6 -0
- package/lib/built/rich-segments/capabilities.js +39 -0
- package/lib/built/rich-segments/html-segment.d.ts +15 -0
- package/lib/built/rich-segments/html-segment.js +65 -0
- package/lib/built/rich-segments/index.d.ts +13 -0
- package/lib/built/rich-segments/index.js +13 -0
- package/lib/built/rich-segments/markdown-segment.d.ts +14 -0
- package/lib/built/rich-segments/markdown-segment.js +61 -0
- package/lib/built/rich-segments/markdown-to-text.d.ts +3 -0
- package/lib/built/rich-segments/markdown-to-text.js +27 -0
- package/lib/built/rich-segments/qrcode-segment.d.ts +18 -0
- package/lib/built/rich-segments/qrcode-segment.js +73 -0
- package/lib/built/rich-segments/registry.d.ts +16 -0
- package/lib/built/rich-segments/registry.js +52 -0
- package/lib/built/rich-segments/resolve.d.ts +5 -0
- package/lib/built/rich-segments/resolve.js +87 -0
- package/lib/built/rich-segments/tts-segment.d.ts +13 -0
- package/lib/built/rich-segments/tts-segment.js +51 -0
- package/lib/built/rich-segments/types.d.ts +84 -0
- package/lib/built/rich-segments/types.js +17 -0
- package/lib/built/roles.d.ts +0 -1
- package/lib/built/roles.js +0 -1
- package/lib/built/runtime-io.d.ts +0 -1
- package/lib/built/runtime-io.js +0 -1
- package/lib/built/schedule.d.ts +55 -0
- package/lib/built/schedule.js +112 -0
- package/lib/built/schema-endpoint-manager.d.ts +17 -0
- package/lib/built/schema-endpoint-manager.js +73 -0
- package/lib/built/schema-feature.d.ts +0 -1
- package/lib/built/schema-feature.js +1 -3
- package/lib/built/segment-contract/assert.d.ts +4 -0
- package/lib/built/segment-contract/assert.js +30 -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 +8 -0
- package/lib/built/segment-contract/index.js +7 -0
- package/lib/built/segment-contract/media.d.ts +8 -0
- package/lib/built/segment-contract/media.js +39 -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/types.d.ts +70 -0
- package/lib/built/segment-contract/types.js +5 -0
- package/lib/built/segment-contract/validate.d.ts +138 -0
- package/lib/built/segment-contract/validate.js +124 -0
- package/lib/built/skill.d.ts +0 -1
- package/lib/built/skill.js +0 -1
- package/lib/built/speech-loader.d.ts +14 -0
- package/lib/built/speech-loader.js +32 -0
- package/lib/built/tool.d.ts +0 -1
- package/lib/built/tool.js +1 -3
- package/lib/command.d.ts +12 -7
- package/lib/command.js +38 -16
- package/lib/component.d.ts +0 -1
- package/lib/component.js +0 -1
- package/lib/endpoint-capabilities.d.ts +3 -1
- package/lib/endpoint-capabilities.js +0 -1
- package/lib/endpoint.d.ts +0 -1
- package/lib/endpoint.js +0 -1
- package/lib/errors.d.ts +0 -1
- package/lib/errors.js +0 -1
- package/lib/host-plugin-registry.d.ts +0 -1
- package/lib/host-plugin-registry.js +0 -1
- package/lib/im-scene.d.ts +29 -0
- package/lib/im-scene.js +77 -0
- package/lib/im-session-id.d.ts +25 -12
- package/lib/im-session-id.js +35 -17
- package/lib/index.d.ts +25 -5
- package/lib/index.js +22 -4
- package/lib/jsx-dev-runtime.d.ts +0 -1
- package/lib/jsx-dev-runtime.js +0 -1
- package/lib/jsx-runtime.d.ts +0 -1
- package/lib/jsx-runtime.js +0 -1
- package/lib/jsx.d.ts +0 -1
- package/lib/jsx.js +0 -1
- package/lib/message-quote.d.ts +1 -2
- package/lib/message-quote.js +2 -3
- package/lib/message.d.ts +12 -2
- package/lib/message.js +16 -1
- package/lib/models/system-log.d.ts +0 -1
- package/lib/models/system-log.js +0 -1
- package/lib/models/user.d.ts +0 -1
- package/lib/models/user.js +0 -1
- package/lib/notice.d.ts +0 -1
- package/lib/notice.js +0 -1
- package/lib/plugin-context.d.ts +0 -1
- package/lib/plugin-context.js +0 -1
- package/lib/plugin.d.ts +11 -2
- package/lib/plugin.js +22 -23
- package/lib/prompt.d.ts +0 -1
- package/lib/prompt.js +1 -2
- package/lib/request.d.ts +0 -1
- package/lib/request.js +0 -1
- package/lib/tool-zod.d.ts +0 -1
- package/lib/tool-zod.js +0 -1
- package/lib/types-generator.d.ts +0 -1
- package/lib/types-generator.js +0 -1
- package/lib/types.d.ts +30 -11
- package/lib/types.js +0 -1
- package/lib/utils.d.ts +57 -12
- package/lib/utils.js +54 -19
- package/package.json +18 -9
- package/lib/adapter.d.ts.map +0 -1
- package/lib/adapter.js.map +0 -1
- package/lib/agent-prompt.d.ts.map +0 -1
- package/lib/agent-prompt.js.map +0 -1
- package/lib/built/adapter-process.d.ts.map +0 -1
- package/lib/built/adapter-process.js.map +0 -1
- package/lib/built/agent-preset.d.ts.map +0 -1
- package/lib/built/agent-preset.js.map +0 -1
- package/lib/built/ai-trigger.d.ts.map +0 -1
- package/lib/built/ai-trigger.js.map +0 -1
- package/lib/built/authorization.d.ts.map +0 -1
- package/lib/built/authorization.js.map +0 -1
- package/lib/built/command.d.ts.map +0 -1
- package/lib/built/command.js.map +0 -1
- package/lib/built/common-adapter-tools.d.ts.map +0 -1
- package/lib/built/common-adapter-tools.js.map +0 -1
- package/lib/built/component.d.ts.map +0 -1
- package/lib/built/component.js.map +0 -1
- package/lib/built/config.d.ts.map +0 -1
- package/lib/built/config.js.map +0 -1
- package/lib/built/connect-endpoint-instance.d.ts.map +0 -1
- package/lib/built/connect-endpoint-instance.js.map +0 -1
- package/lib/built/cron.d.ts +0 -75
- package/lib/built/cron.d.ts.map +0 -1
- package/lib/built/cron.js +0 -122
- package/lib/built/cron.js.map +0 -1
- package/lib/built/database.d.ts.map +0 -1
- package/lib/built/database.js.map +0 -1
- package/lib/built/dispatcher.d.ts.map +0 -1
- package/lib/built/dispatcher.js.map +0 -1
- package/lib/built/endpoint-lifecycle.d.ts.map +0 -1
- package/lib/built/endpoint-lifecycle.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-pipeline.d.ts.map +0 -1
- package/lib/built/inbound-pipeline.js.map +0 -1
- package/lib/built/inbound-runner.d.ts.map +0 -1
- package/lib/built/inbound-runner.js.map +0 -1
- package/lib/built/login-assist.d.ts.map +0 -1
- package/lib/built/login-assist.js.map +0 -1
- package/lib/built/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-enrich.d.ts.map +0 -1
- package/lib/built/message-enrich.js.map +0 -1
- package/lib/built/message-filter.d.ts.map +0 -1
- package/lib/built/message-filter.js.map +0 -1
- package/lib/built/permission.d.ts.map +0 -1
- package/lib/built/permission.js.map +0 -1
- package/lib/built/permit-check.d.ts.map +0 -1
- package/lib/built/permit-check.js.map +0 -1
- package/lib/built/permit-parse.d.ts.map +0 -1
- package/lib/built/permit-parse.js.map +0 -1
- package/lib/built/platform-permit.d.ts.map +0 -1
- package/lib/built/platform-permit.js.map +0 -1
- package/lib/built/prepend-quote-context.d.ts.map +0 -1
- package/lib/built/prepend-quote-context.js.map +0 -1
- package/lib/built/queue-im-field-contract.d.ts.map +0 -1
- package/lib/built/queue-im-field-contract.js.map +0 -1
- package/lib/built/roles.d.ts.map +0 -1
- package/lib/built/roles.js.map +0 -1
- package/lib/built/runtime-io.d.ts.map +0 -1
- package/lib/built/runtime-io.js.map +0 -1
- package/lib/built/schema-feature.d.ts.map +0 -1
- package/lib/built/schema-feature.js.map +0 -1
- package/lib/built/skill.d.ts.map +0 -1
- package/lib/built/skill.js.map +0 -1
- package/lib/built/tool.d.ts.map +0 -1
- package/lib/built/tool.js.map +0 -1
- package/lib/command.d.ts.map +0 -1
- package/lib/command.js.map +0 -1
- package/lib/component.d.ts.map +0 -1
- package/lib/component.js.map +0 -1
- package/lib/endpoint-capabilities.d.ts.map +0 -1
- package/lib/endpoint-capabilities.js.map +0 -1
- package/lib/endpoint.d.ts.map +0 -1
- package/lib/endpoint.js.map +0 -1
- package/lib/errors.d.ts.map +0 -1
- package/lib/errors.js.map +0 -1
- package/lib/host-plugin-registry.d.ts.map +0 -1
- package/lib/host-plugin-registry.js.map +0 -1
- package/lib/im-session-id.d.ts.map +0 -1
- package/lib/im-session-id.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.map +0 -1
- 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-context.d.ts.map +0 -1
- package/lib/plugin-context.js.map +0 -1
- package/lib/plugin.d.ts.map +0 -1
- package/lib/plugin.js.map +0 -1
- package/lib/prompt.d.ts.map +0 -1
- package/lib/prompt.js.map +0 -1
- package/lib/request.d.ts.map +0 -1
- package/lib/request.js.map +0 -1
- package/lib/scheduler/scheduler.d.ts +0 -49
- package/lib/scheduler/scheduler.d.ts.map +0 -1
- package/lib/scheduler/scheduler.js +0 -352
- package/lib/scheduler/scheduler.js.map +0 -1
- package/lib/scheduler/types.d.ts +0 -71
- package/lib/scheduler/types.d.ts.map +0 -1
- package/lib/scheduler/types.js +0 -8
- package/lib/scheduler/types.js.map +0 -1
- package/lib/tool-zod.d.ts.map +0 -1
- package/lib/tool-zod.js.map +0 -1
- package/lib/types-generator.d.ts.map +0 -1
- 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
package/lib/im-scene.js
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { resolveIMSceneSessionId as resolveIMSceneSessionIdKernel, } from '@zhin.js/kernel';
|
|
2
|
+
function nonEmptyString(value) {
|
|
3
|
+
return typeof value === 'string' && value.trim() ? value.trim() : undefined;
|
|
4
|
+
}
|
|
5
|
+
/** Normalize legacy parent.type channel → guild. */
|
|
6
|
+
export function normalizeIMSceneParentKind(value) {
|
|
7
|
+
if (value === 'group' || value === 'guild')
|
|
8
|
+
return value;
|
|
9
|
+
if (value === 'channel')
|
|
10
|
+
return 'guild';
|
|
11
|
+
return undefined;
|
|
12
|
+
}
|
|
13
|
+
export function sceneRefFromMessage(message) {
|
|
14
|
+
const platform = nonEmptyString(message.$adapter);
|
|
15
|
+
const endpointId = nonEmptyString(message.$endpoint);
|
|
16
|
+
const kind = message.$channel?.type;
|
|
17
|
+
if (!platform || !endpointId || !kind)
|
|
18
|
+
return undefined;
|
|
19
|
+
const senderId = nonEmptyString(message.$sender?.id);
|
|
20
|
+
const channelId = nonEmptyString(message.$channel?.id);
|
|
21
|
+
const sceneId = kind === 'private'
|
|
22
|
+
? senderId ?? channelId
|
|
23
|
+
: channelId ?? senderId;
|
|
24
|
+
if (!sceneId)
|
|
25
|
+
return undefined;
|
|
26
|
+
const parentKind = message.$channel?.parent
|
|
27
|
+
? normalizeIMSceneParentKind(message.$channel.parent.type)
|
|
28
|
+
: undefined;
|
|
29
|
+
const parent = parentKind && message.$channel?.parent
|
|
30
|
+
? {
|
|
31
|
+
kind: parentKind,
|
|
32
|
+
sceneId: String(message.$channel.parent.id),
|
|
33
|
+
}
|
|
34
|
+
: undefined;
|
|
35
|
+
return {
|
|
36
|
+
platform,
|
|
37
|
+
endpointId,
|
|
38
|
+
sceneId,
|
|
39
|
+
kind,
|
|
40
|
+
...(senderId ? { senderId } : {}),
|
|
41
|
+
...(parent ? { parent } : {}),
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
export function sceneRefToSendOptions(target, content) {
|
|
45
|
+
const { scene } = target;
|
|
46
|
+
return {
|
|
47
|
+
context: scene.platform,
|
|
48
|
+
endpoint: scene.endpointId,
|
|
49
|
+
id: scene.sceneId,
|
|
50
|
+
type: scene.kind,
|
|
51
|
+
parent: scene.parent
|
|
52
|
+
? { type: scene.parent.kind, id: scene.parent.sceneId }
|
|
53
|
+
: undefined,
|
|
54
|
+
content,
|
|
55
|
+
...(target.quoteId ? { quoteId: target.quoteId } : {}),
|
|
56
|
+
...(target.threadId ? { threadId: target.threadId } : {}),
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
export function resolveIMSceneSessionId(scene) {
|
|
60
|
+
return resolveIMSceneSessionIdKernel({
|
|
61
|
+
platform: scene.platform,
|
|
62
|
+
endpointId: scene.endpointId,
|
|
63
|
+
sceneId: scene.sceneId,
|
|
64
|
+
kind: scene.kind,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
export function messageToIMDeliveryTarget(message) {
|
|
68
|
+
const scene = sceneRefFromMessage(message);
|
|
69
|
+
if (!scene)
|
|
70
|
+
return undefined;
|
|
71
|
+
const quoteId = nonEmptyString(message.$quote_id);
|
|
72
|
+
return {
|
|
73
|
+
channel: 'im',
|
|
74
|
+
scene,
|
|
75
|
+
...(quoteId ? { quoteId } : {}),
|
|
76
|
+
};
|
|
77
|
+
}
|
package/lib/im-session-id.d.ts
CHANGED
|
@@ -1,26 +1,39 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* IM 会话 ID
|
|
2
|
+
* IM 会话 ID 解析(SSOT 在 @zhin.js/kernel + im-scene)
|
|
3
3
|
*
|
|
4
|
-
* 格式:`platform:endpointId:
|
|
4
|
+
* 格式:`platform:endpointId:kind:sceneId`
|
|
5
5
|
*/
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
endpointId: string;
|
|
10
|
-
scope: IMSessionScope;
|
|
11
|
-
sceneId: string;
|
|
12
|
-
}
|
|
6
|
+
import { type ResolveIMSessionIdInput } from '@zhin.js/kernel';
|
|
7
|
+
import { type IMSceneKind, type IMSceneRef } from './im-scene.js';
|
|
8
|
+
export type { IMSceneKind, ResolveIMSessionIdInput };
|
|
13
9
|
export declare function resolveIMSessionId(input: ResolveIMSessionIdInput): string;
|
|
14
|
-
export declare function
|
|
10
|
+
export declare function resolveIMSessionIdFromScene(scene: IMSceneRef): string;
|
|
11
|
+
export declare function resolveIMSceneIdForSession(kind: IMSceneKind, sceneId?: string, senderId?: string): string;
|
|
15
12
|
export declare function resolveIMSessionIdFromMessage(message: {
|
|
16
13
|
$adapter?: string;
|
|
17
14
|
$endpoint?: string;
|
|
18
15
|
$channel?: {
|
|
19
|
-
type?:
|
|
16
|
+
type?: IMSceneKind;
|
|
20
17
|
id?: string;
|
|
21
18
|
};
|
|
22
19
|
$sender?: {
|
|
23
20
|
id?: string;
|
|
24
21
|
};
|
|
25
22
|
}): string;
|
|
26
|
-
|
|
23
|
+
/** Canonical scene fields for transcript / session persistence (ADR 0028 SSOT). */
|
|
24
|
+
export declare function resolveSceneFieldsFromMessage(message: {
|
|
25
|
+
$adapter?: string;
|
|
26
|
+
$endpoint?: string;
|
|
27
|
+
$channel?: {
|
|
28
|
+
type?: IMSceneKind;
|
|
29
|
+
id?: string;
|
|
30
|
+
};
|
|
31
|
+
$sender?: {
|
|
32
|
+
id?: string;
|
|
33
|
+
};
|
|
34
|
+
}): {
|
|
35
|
+
platform: string;
|
|
36
|
+
endpointId: string;
|
|
37
|
+
sceneId: string;
|
|
38
|
+
sceneType: IMSceneKind;
|
|
39
|
+
};
|
package/lib/im-session-id.js
CHANGED
|
@@ -1,29 +1,47 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* IM 会话 ID
|
|
2
|
+
* IM 会话 ID 解析(SSOT 在 @zhin.js/kernel + im-scene)
|
|
3
3
|
*
|
|
4
|
-
* 格式:`platform:endpointId:
|
|
4
|
+
* 格式:`platform:endpointId:kind:sceneId`
|
|
5
5
|
*/
|
|
6
|
+
import { resolveIMSceneIdForSession as resolveIMSceneIdForSessionKernel, resolveIMSessionId as resolveIMSessionIdKernel, } from '@zhin.js/kernel';
|
|
7
|
+
import { resolveIMSceneSessionId, sceneRefFromMessage, } from './im-scene.js';
|
|
6
8
|
export function resolveIMSessionId(input) {
|
|
7
|
-
|
|
8
|
-
const endpointId = String(input.endpointId || 'default');
|
|
9
|
-
const scope = input.scope || 'private';
|
|
10
|
-
const sceneId = String(input.sceneId || 'unknown');
|
|
11
|
-
return `${platform}:${endpointId}:${scope}:${sceneId}`;
|
|
9
|
+
return resolveIMSessionIdKernel(input);
|
|
12
10
|
}
|
|
13
|
-
export function
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
return
|
|
11
|
+
export function resolveIMSessionIdFromScene(scene) {
|
|
12
|
+
return resolveIMSceneSessionId(scene);
|
|
13
|
+
}
|
|
14
|
+
export function resolveIMSceneIdForSession(kind, sceneId, senderId) {
|
|
15
|
+
return resolveIMSceneIdForSessionKernel(kind, sceneId, senderId);
|
|
18
16
|
}
|
|
19
17
|
export function resolveIMSessionIdFromMessage(message) {
|
|
20
|
-
const
|
|
21
|
-
|
|
18
|
+
const scene = sceneRefFromMessage(message);
|
|
19
|
+
if (scene)
|
|
20
|
+
return resolveIMSceneSessionId(scene);
|
|
21
|
+
const kind = (message.$channel?.type || 'private');
|
|
22
22
|
return resolveIMSessionId({
|
|
23
23
|
platform: String(message.$adapter || ''),
|
|
24
24
|
endpointId: String(message.$endpoint || ''),
|
|
25
|
-
|
|
26
|
-
sceneId,
|
|
25
|
+
kind,
|
|
26
|
+
sceneId: resolveIMSceneIdForSession(kind, message.$channel?.id, message.$sender?.id),
|
|
27
27
|
});
|
|
28
28
|
}
|
|
29
|
-
|
|
29
|
+
/** Canonical scene fields for transcript / session persistence (ADR 0028 SSOT). */
|
|
30
|
+
export function resolveSceneFieldsFromMessage(message) {
|
|
31
|
+
const scene = sceneRefFromMessage(message);
|
|
32
|
+
if (scene) {
|
|
33
|
+
return {
|
|
34
|
+
platform: scene.platform,
|
|
35
|
+
endpointId: scene.endpointId,
|
|
36
|
+
sceneId: scene.sceneId,
|
|
37
|
+
sceneType: scene.kind,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
const sceneType = (message.$channel?.type || 'private');
|
|
41
|
+
return {
|
|
42
|
+
platform: String(message.$adapter || ''),
|
|
43
|
+
endpointId: String(message.$endpoint || ''),
|
|
44
|
+
sceneType,
|
|
45
|
+
sceneId: resolveIMSceneIdForSession(sceneType, message.$channel?.id, message.$sender?.id),
|
|
46
|
+
};
|
|
47
|
+
}
|
package/lib/index.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export * from './command.js';
|
|
|
5
5
|
export * from './component.js';
|
|
6
6
|
export * from './adapter.js';
|
|
7
7
|
export * from './message.js';
|
|
8
|
+
export * from './im-scene.js';
|
|
8
9
|
export * from './notice.js';
|
|
9
10
|
export * from './request.js';
|
|
10
11
|
export * from './prompt.js';
|
|
@@ -14,7 +15,8 @@ export * from './utils.js';
|
|
|
14
15
|
export * from './errors.js';
|
|
15
16
|
export * from './built/config.js';
|
|
16
17
|
export * from './built/command.js';
|
|
17
|
-
export * from './built/
|
|
18
|
+
export * from './built/schedule.js';
|
|
19
|
+
export type { ScheduleDescriptor, ScheduleHandle, ScheduleContextExtensions } from './built/schedule.js';
|
|
18
20
|
export * from './models/system-log.js';
|
|
19
21
|
export * from './models/user.js';
|
|
20
22
|
export * from './built/permission.js';
|
|
@@ -34,9 +36,22 @@ export * from './built/common-adapter-tools.js';
|
|
|
34
36
|
export * from './built/roles.js';
|
|
35
37
|
export * from './im-session-id.js';
|
|
36
38
|
export * from './built/ai-trigger.js';
|
|
39
|
+
export * from './built/ai-access.js';
|
|
37
40
|
export * from './built/dispatcher.js';
|
|
38
41
|
export * from './built/schema-feature.js';
|
|
39
42
|
export * from './built/login-assist.js';
|
|
43
|
+
export * from './built/generated-qrcode.js';
|
|
44
|
+
export * from './built/qrcode-segment.js';
|
|
45
|
+
export * from './built/rich-segments/index.js';
|
|
46
|
+
export * from './built/interactive-segments/index.js';
|
|
47
|
+
export * from './built/ai-outbound/index.js';
|
|
48
|
+
export { loadHtmlRenderer, seedHtmlRenderer, HTML_RENDERER_PACKAGE } from './built/html-renderer-loader.js';
|
|
49
|
+
export { loadSpeechPipeline, seedSpeechPipeline, SPEECH_PACKAGE } from './built/speech-loader.js';
|
|
50
|
+
export * from './built/outbound-media-utils.js';
|
|
51
|
+
export * from './built/outbound-media-contract.js';
|
|
52
|
+
export * from './built/interactive-segment-contract.js';
|
|
53
|
+
export * from './built/segment-contract/index.js';
|
|
54
|
+
export * from './built/generic-segment-mapper.js';
|
|
40
55
|
export * from './built/adapter-process.js';
|
|
41
56
|
export * from './built/component.js';
|
|
42
57
|
export * from './built/inbound-runner.js';
|
|
@@ -45,15 +60,20 @@ export * from './built/connect-endpoint-instance.js';
|
|
|
45
60
|
export type { ConnectEndpointInstanceOptions } from './built/connect-endpoint-instance.js';
|
|
46
61
|
export * from './built/endpoint-lifecycle.js';
|
|
47
62
|
export type { EndpointLifecycleKind, EndpointLifecyclePayload } from './built/endpoint-lifecycle.js';
|
|
63
|
+
export * from './built/endpoint-manager.js';
|
|
64
|
+
export type { EndpointConfigRecord, EndpointManager, ProvisionContext } from './built/endpoint-manager.js';
|
|
65
|
+
export * from './built/endpoint-lifecycle-service.js';
|
|
66
|
+
export * from './built/schema-endpoint-manager.js';
|
|
67
|
+
export * from './built/endpoint-commands.js';
|
|
68
|
+
export * from './built/introspection-format.js';
|
|
69
|
+
export * from './built/management-command-guard.js';
|
|
48
70
|
export * from './built/html-to-text.js';
|
|
49
71
|
export * from './built/html-segment-fallback.js';
|
|
50
|
-
export * from './built/mcp-mesh-registrar.js';
|
|
51
72
|
export * from './built/prepend-quote-context.js';
|
|
52
73
|
export * from './message-quote.js';
|
|
53
74
|
export * from '@zhin.js/database';
|
|
54
75
|
export * from '@zhin.js/logger';
|
|
55
76
|
export { Schema } from '@zhin.js/schema';
|
|
56
77
|
export type { PluginLike } from '@zhin.js/kernel';
|
|
57
|
-
export { Feature,
|
|
58
|
-
export type { FeatureJSON, FeatureListener, Schedule, JobPayload, JobState, ScheduledJob, JobStore, JobCallback, AddJobOptions, IScheduler, SchedulerOptions, } from '@zhin.js/kernel';
|
|
59
|
-
//# sourceMappingURL=index.d.ts.map
|
|
78
|
+
export { Feature, ScheduleEngine, getScheduleEngine, setScheduleEngine, Scheduler, getScheduler, setScheduler, } from '@zhin.js/kernel';
|
|
79
|
+
export type { FeatureJSON, FeatureListener, Schedule, JobPayload, JobState, ScheduledJob, JobStore, JobCallback, AddJobOptions, IScheduler, SchedulerOptions, ScheduleFireCallback, MemoryScheduleRegistration, ScheduleEngineOptions, JobContext, ResolvedJob, ScheduleKind, } from '@zhin.js/kernel';
|
package/lib/index.js
CHANGED
|
@@ -6,6 +6,7 @@ export * from './command.js';
|
|
|
6
6
|
export * from './component.js';
|
|
7
7
|
export * from './adapter.js';
|
|
8
8
|
export * from './message.js';
|
|
9
|
+
export * from './im-scene.js';
|
|
9
10
|
export * from './notice.js';
|
|
10
11
|
export * from './request.js';
|
|
11
12
|
export * from './prompt.js';
|
|
@@ -16,7 +17,7 @@ export * from './errors.js';
|
|
|
16
17
|
// ── Built 模块 ──────────────────────────────────────────────────────
|
|
17
18
|
export * from './built/config.js';
|
|
18
19
|
export * from './built/command.js';
|
|
19
|
-
export * from './built/
|
|
20
|
+
export * from './built/schedule.js';
|
|
20
21
|
// Models
|
|
21
22
|
export * from './models/system-log.js';
|
|
22
23
|
export * from './models/user.js';
|
|
@@ -36,22 +37,39 @@ export * from './built/common-adapter-tools.js';
|
|
|
36
37
|
export * from './built/roles.js';
|
|
37
38
|
export * from './im-session-id.js';
|
|
38
39
|
export * from './built/ai-trigger.js';
|
|
40
|
+
export * from './built/ai-access.js';
|
|
39
41
|
export * from './built/dispatcher.js';
|
|
40
42
|
export * from './built/schema-feature.js';
|
|
41
43
|
export * from './built/login-assist.js';
|
|
44
|
+
export * from './built/generated-qrcode.js';
|
|
45
|
+
export * from './built/qrcode-segment.js';
|
|
46
|
+
export * from './built/rich-segments/index.js';
|
|
47
|
+
export * from './built/interactive-segments/index.js';
|
|
48
|
+
export * from './built/ai-outbound/index.js';
|
|
49
|
+
export { loadHtmlRenderer, seedHtmlRenderer, HTML_RENDERER_PACKAGE } from './built/html-renderer-loader.js';
|
|
50
|
+
export { loadSpeechPipeline, seedSpeechPipeline, SPEECH_PACKAGE } from './built/speech-loader.js';
|
|
51
|
+
export * from './built/outbound-media-utils.js';
|
|
52
|
+
export * from './built/outbound-media-contract.js';
|
|
53
|
+
export * from './built/interactive-segment-contract.js';
|
|
54
|
+
export * from './built/segment-contract/index.js';
|
|
55
|
+
export * from './built/generic-segment-mapper.js';
|
|
42
56
|
export * from './built/adapter-process.js';
|
|
43
57
|
export * from './built/component.js';
|
|
44
58
|
export * from './built/inbound-runner.js';
|
|
45
59
|
export * from './built/connect-endpoint-instance.js';
|
|
46
60
|
export * from './built/endpoint-lifecycle.js';
|
|
61
|
+
export * from './built/endpoint-manager.js';
|
|
62
|
+
export * from './built/endpoint-lifecycle-service.js';
|
|
63
|
+
export * from './built/schema-endpoint-manager.js';
|
|
64
|
+
export * from './built/endpoint-commands.js';
|
|
65
|
+
export * from './built/introspection-format.js';
|
|
66
|
+
export * from './built/management-command-guard.js';
|
|
47
67
|
export * from './built/html-to-text.js';
|
|
48
68
|
export * from './built/html-segment-fallback.js';
|
|
49
|
-
export * from './built/mcp-mesh-registrar.js';
|
|
50
69
|
export * from './built/prepend-quote-context.js';
|
|
51
70
|
export * from './message-quote.js';
|
|
52
71
|
// ── 外部库 re-export ──────────────────────────────────────────────────
|
|
53
72
|
export * from '@zhin.js/database';
|
|
54
73
|
export * from '@zhin.js/logger';
|
|
55
74
|
export { Schema } from '@zhin.js/schema';
|
|
56
|
-
export { Feature,
|
|
57
|
-
//# sourceMappingURL=index.js.map
|
|
75
|
+
export { Feature, ScheduleEngine, getScheduleEngine, setScheduleEngine, Scheduler, getScheduler, setScheduler, } from '@zhin.js/kernel';
|
package/lib/jsx-dev-runtime.d.ts
CHANGED
package/lib/jsx-dev-runtime.js
CHANGED
package/lib/jsx-runtime.d.ts
CHANGED
package/lib/jsx-runtime.js
CHANGED
package/lib/jsx.d.ts
CHANGED
|
@@ -30,4 +30,3 @@ declare global {
|
|
|
30
30
|
export declare function jsx(type: JSXElementType, data: JSXProps): MessageComponent<any>;
|
|
31
31
|
export declare function jsxs(type: JSXElementType, props: JSXProps): MessageElement;
|
|
32
32
|
export declare function renderJSX(element: MessageComponent<any>, context?: ComponentContext): Promise<SendContent>;
|
|
33
|
-
//# sourceMappingURL=jsx.d.ts.map
|
package/lib/jsx.js
CHANGED
package/lib/message-quote.d.ts
CHANGED
|
@@ -6,6 +6,5 @@ export declare function quoteIdFromContent(content: MessageElement[]): string |
|
|
|
6
6
|
export declare function quoteIdFromRaw(raw: unknown): string | undefined;
|
|
7
7
|
/** 无 $quote_id 时从 $content / $raw 回填 */
|
|
8
8
|
export declare function syncQuoteId(message: Message<any>): void;
|
|
9
|
-
/** 将 reply
|
|
9
|
+
/** 将 reply 段与 $quote_id 对齐(canonical 仅保留 message_id) */
|
|
10
10
|
export declare function alignReplySegments(content: MessageElement[], quoteId?: string): void;
|
|
11
|
-
//# sourceMappingURL=message-quote.d.ts.map
|
package/lib/message-quote.js
CHANGED
|
@@ -75,7 +75,7 @@ export function syncQuoteId(message) {
|
|
|
75
75
|
if (id)
|
|
76
76
|
message.$quote_id = id;
|
|
77
77
|
}
|
|
78
|
-
/** 将 reply
|
|
78
|
+
/** 将 reply 段与 $quote_id 对齐(canonical 仅保留 message_id) */
|
|
79
79
|
export function alignReplySegments(content, quoteId) {
|
|
80
80
|
const id = quoteId ?? quoteIdFromContent(content);
|
|
81
81
|
if (!id)
|
|
@@ -84,8 +84,7 @@ export function alignReplySegments(content, quoteId) {
|
|
|
84
84
|
if (seg.type !== 'reply' || !seg.data || typeof seg.data !== 'object')
|
|
85
85
|
continue;
|
|
86
86
|
const data = seg.data;
|
|
87
|
-
data.id = id;
|
|
88
87
|
data.message_id = id;
|
|
88
|
+
delete data.id;
|
|
89
89
|
}
|
|
90
90
|
}
|
|
91
|
-
//# sourceMappingURL=message-quote.js.map
|
package/lib/message.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MessageElement, MessageSender, SendContent } from "./types";
|
|
1
|
+
import { MessageElement, MessageSender, SendContent } from "./types.js";
|
|
2
2
|
import { Component } from "./component.js";
|
|
3
3
|
import { Adapters } from "./adapter.js";
|
|
4
4
|
/**
|
|
@@ -16,6 +16,15 @@ export type MessageComponent<T extends object> = {
|
|
|
16
16
|
export interface MessageChannel {
|
|
17
17
|
id: string;
|
|
18
18
|
type: MessageType;
|
|
19
|
+
/**
|
|
20
|
+
* 私聊/子频道消息的来源场景:
|
|
21
|
+
* - 群临时会话:type=private + parent.group
|
|
22
|
+
* - QQ 子频道:type=channel + parent.guild
|
|
23
|
+
*/
|
|
24
|
+
parent?: {
|
|
25
|
+
type: 'group' | 'channel' | 'guild';
|
|
26
|
+
id: string;
|
|
27
|
+
};
|
|
19
28
|
}
|
|
20
29
|
/**
|
|
21
30
|
* 消息类型枚举
|
|
@@ -50,5 +59,6 @@ export declare namespace Message {
|
|
|
50
59
|
function quoteIdFromContent(content: MessageElement[]): string | undefined;
|
|
51
60
|
function syncQuoteId(message: Message<any>): void;
|
|
52
61
|
function alignReplySegments(content: MessageElement[], quoteId?: string): void;
|
|
62
|
+
function actionPayload(message: Message<any>): string | undefined;
|
|
63
|
+
function isAction(message: Message<any>): boolean;
|
|
53
64
|
}
|
|
54
|
-
//# sourceMappingURL=message.d.ts.map
|
package/lib/message.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { alignReplySegments as alignReplySegmentsImpl, quoteIdFromContent as quoteIdFromContentImpl, syncQuoteId as syncQuoteIdImpl, } from "./message-quote.js";
|
|
2
|
+
import { isActionMessage as isActionMessageImpl } from "./built/interactive-segments/action.js";
|
|
2
3
|
export var Message;
|
|
3
4
|
(function (Message) {
|
|
4
5
|
/**
|
|
@@ -20,5 +21,19 @@ export var Message;
|
|
|
20
21
|
alignReplySegmentsImpl(content, quoteId);
|
|
21
22
|
}
|
|
22
23
|
Message.alignReplySegments = alignReplySegments;
|
|
24
|
+
function actionPayload(message) {
|
|
25
|
+
for (const item of message.$content ?? []) {
|
|
26
|
+
if (typeof item === 'string')
|
|
27
|
+
continue;
|
|
28
|
+
if (item.type === 'action' && item.data?.payload) {
|
|
29
|
+
return String(item.data.payload);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
Message.actionPayload = actionPayload;
|
|
35
|
+
function isAction(message) {
|
|
36
|
+
return isActionMessageImpl(message);
|
|
37
|
+
}
|
|
38
|
+
Message.isAction = isAction;
|
|
23
39
|
})(Message || (Message = {}));
|
|
24
|
-
//# sourceMappingURL=message.js.map
|
package/lib/models/system-log.js
CHANGED
package/lib/models/user.d.ts
CHANGED
package/lib/models/user.js
CHANGED
package/lib/notice.d.ts
CHANGED
package/lib/notice.js
CHANGED
package/lib/plugin-context.d.ts
CHANGED
package/lib/plugin-context.js
CHANGED
package/lib/plugin.d.ts
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
* - 中间件系统、适配器管理、useContext 等
|
|
8
8
|
*/
|
|
9
9
|
import type { PluginManifest } from "./types.js";
|
|
10
|
+
import type { InteractiveHandler } from "./built/interactive-segments/types.js";
|
|
10
11
|
import { MessageMiddleware, RegisteredAdapter, MaybePromise, ArrayItem, SendOptions, MessageSendPayload } from "./types.js";
|
|
11
12
|
import { Adapter, Adapters } from "./adapter.js";
|
|
12
13
|
import { PluginBase, PluginBaseLifecycle } from "@zhin.js/kernel";
|
|
@@ -64,6 +65,10 @@ export declare class Plugin extends PluginBase implements PluginLike {
|
|
|
64
65
|
* 中间件用于处理消息流转
|
|
65
66
|
*/
|
|
66
67
|
addMiddleware<T extends RegisteredAdapter>(middleware: MessageMiddleware<T>, name?: string): () => void;
|
|
68
|
+
/**
|
|
69
|
+
* 注册交互式 action 回调处理器(自动安装根中间件,优先于 Dispatcher)
|
|
70
|
+
*/
|
|
71
|
+
registerInteractiveHandler(prefix: string, handler: InteractiveHandler): () => void;
|
|
67
72
|
/**
|
|
68
73
|
* 插件名称
|
|
69
74
|
*/
|
|
@@ -159,7 +164,7 @@ export declare namespace Plugin {
|
|
|
159
164
|
interface Features {
|
|
160
165
|
commands: string[];
|
|
161
166
|
components: string[];
|
|
162
|
-
|
|
167
|
+
schedules: string[];
|
|
163
168
|
middlewares: string[];
|
|
164
169
|
}
|
|
165
170
|
/**
|
|
@@ -193,6 +198,8 @@ export declare namespace Plugin {
|
|
|
193
198
|
"ai.response": [Plugin.AIEventPayload];
|
|
194
199
|
"ai.typing.start": [Plugin.AIEventPayload];
|
|
195
200
|
"ai.typing.stop": [Plugin.AIEventPayload];
|
|
201
|
+
"ai.activity.queued.start": [Plugin.AIEventPayload];
|
|
202
|
+
"ai.activity.queued.clear": [Plugin.AIEventPayload];
|
|
196
203
|
"ai.subagent.spawn": [Plugin.AIEventPayload];
|
|
197
204
|
"ai.subagent.start": [Plugin.AIEventPayload];
|
|
198
205
|
"ai.subagent.finish": [Plugin.AIEventPayload];
|
|
@@ -204,6 +211,9 @@ export declare namespace Plugin {
|
|
|
204
211
|
"ai.session.new": [Plugin.AIEventPayload];
|
|
205
212
|
"ai.session.compact": [Plugin.AIEventPayload];
|
|
206
213
|
"ai.hook": [Plugin.AIEventPayload];
|
|
214
|
+
"schedule.start": [Plugin.AIEventPayload];
|
|
215
|
+
"schedule.finish": [Plugin.AIEventPayload];
|
|
216
|
+
"schedule.error": [Plugin.AIEventPayload];
|
|
207
217
|
}
|
|
208
218
|
interface AIEventPayload {
|
|
209
219
|
sessionId: string;
|
|
@@ -257,4 +267,3 @@ export declare namespace Plugin {
|
|
|
257
267
|
interface Extensions {
|
|
258
268
|
}
|
|
259
269
|
}
|
|
260
|
-
//# sourceMappingURL=plugin.d.ts.map
|
package/lib/plugin.js
CHANGED
|
@@ -11,6 +11,7 @@ import * as path from "node:path";
|
|
|
11
11
|
import { pathToFileURL } from "node:url";
|
|
12
12
|
import { formatCompact } from "@zhin.js/logger";
|
|
13
13
|
import { compose, remove, resolveEntry } from "./utils.js";
|
|
14
|
+
import { ensureInteractiveMiddleware, registerInteractiveHandler as registerInteractiveHandlerCore, } from "./built/interactive-segments/handlers.js";
|
|
14
15
|
import { Adapter } from "./adapter.js";
|
|
15
16
|
import { Feature } from "@zhin.js/kernel";
|
|
16
17
|
import { PluginBase, resolvePluginResolveDir as _resolvePluginResolveDir, pluginCreateRequire as _pluginCreateRequire, getFileHash, watchFile, registerExtension, unregisterExtensions, installExtensionProxy, } from "@zhin.js/kernel";
|
|
@@ -36,7 +37,9 @@ function pluginCreateRequire() {
|
|
|
36
37
|
* 同一上下文中同一文件多次调用返回同一实例
|
|
37
38
|
*/
|
|
38
39
|
export function usePlugin() {
|
|
39
|
-
|
|
40
|
+
// 必须传入 plugin.ts 的 import.meta.url:getCurrentFile 默认锚定在 plugin-context.ts,
|
|
41
|
+
// 否则会多跳一层 usePlugin 帧,把调用方误判为 plugin.ts(plugin.name === "plugin")。
|
|
42
|
+
const callerFile = getCurrentFile(import.meta.url);
|
|
40
43
|
// 如果当前 store 已是同一文件创建的插件,直接返回
|
|
41
44
|
const current = storage.getStore();
|
|
42
45
|
if (current && current.filePath.replace(/\?t=\d+$/, '') === callerFile.replace(/\?t=\d+$/, '')) {
|
|
@@ -72,22 +75,9 @@ export class Plugin extends PluginBase {
|
|
|
72
75
|
get root() {
|
|
73
76
|
return super.root;
|
|
74
77
|
}
|
|
75
|
-
//
|
|
76
|
-
#messageMiddleware = async (
|
|
77
|
-
|
|
78
|
-
if (!commandService)
|
|
79
|
-
return await next();
|
|
80
|
-
const result = await commandService.handle(message, this);
|
|
81
|
-
if (result === undefined || result === null)
|
|
82
|
-
return await next();
|
|
83
|
-
const adapter = this.inject(message.$adapter);
|
|
84
|
-
if (!adapter || !(adapter instanceof Adapter))
|
|
85
|
-
return await next();
|
|
86
|
-
if (!message.$reply) {
|
|
87
|
-
this.logger.warn(`command result cannot be sent: endpoint ${message.$endpoint} has no outbound capability`);
|
|
88
|
-
return;
|
|
89
|
-
}
|
|
90
|
-
await message.$reply(result);
|
|
78
|
+
// 默认中间件:将入站消息交给 compose 链末端的 MessageDispatcher(命令/AI 路由在 dispatcher 内完成)
|
|
79
|
+
#messageMiddleware = async (_message, next) => {
|
|
80
|
+
await next();
|
|
91
81
|
};
|
|
92
82
|
#middlewares = [this.#messageMiddleware];
|
|
93
83
|
get middleware() {
|
|
@@ -116,6 +106,15 @@ export class Plugin extends PluginBase {
|
|
|
116
106
|
this.onDispose(dispose);
|
|
117
107
|
return dispose;
|
|
118
108
|
}
|
|
109
|
+
/**
|
|
110
|
+
* 注册交互式 action 回调处理器(自动安装根中间件,优先于 Dispatcher)
|
|
111
|
+
*/
|
|
112
|
+
registerInteractiveHandler(prefix, handler) {
|
|
113
|
+
ensureInteractiveMiddleware((mw) => this.root.addMiddleware(mw));
|
|
114
|
+
const dispose = registerInteractiveHandlerCore(prefix, handler);
|
|
115
|
+
this.onDispose(dispose);
|
|
116
|
+
return dispose;
|
|
117
|
+
}
|
|
119
118
|
/**
|
|
120
119
|
* 插件名称
|
|
121
120
|
*/
|
|
@@ -225,7 +224,8 @@ export class Plugin extends PluginBase {
|
|
|
225
224
|
contextReadyCallback();
|
|
226
225
|
}
|
|
227
226
|
inject(name) {
|
|
228
|
-
const
|
|
227
|
+
const resolved = name === 'cron' ? 'schedule' : name;
|
|
228
|
+
const context = this.root.contexts.get(resolved);
|
|
229
229
|
return context?.value;
|
|
230
230
|
}
|
|
231
231
|
injectAdapter(name) {
|
|
@@ -304,11 +304,11 @@ export class Plugin extends PluginBase {
|
|
|
304
304
|
get features() {
|
|
305
305
|
const commandService = this.inject('command');
|
|
306
306
|
const componentService = this.inject('component');
|
|
307
|
-
const
|
|
307
|
+
const scheduleService = this.inject('schedule');
|
|
308
308
|
return {
|
|
309
309
|
commands: commandService ? commandService.items.map(c => c.pattern) : [],
|
|
310
310
|
components: componentService ? componentService.getAllNames() : [],
|
|
311
|
-
|
|
311
|
+
schedules: scheduleService ? scheduleService.items.map(s => s.id) : [],
|
|
312
312
|
middlewares: this.#middlewares.map((m, i) => m.name || `middleware_${i}`),
|
|
313
313
|
};
|
|
314
314
|
}
|
|
@@ -323,8 +323,8 @@ export class Plugin extends PluginBase {
|
|
|
323
323
|
result.push({ name: 'command', count: f.commands.length });
|
|
324
324
|
if (f.components.length > 0)
|
|
325
325
|
result.push({ name: 'component', count: f.components.length });
|
|
326
|
-
if (f.
|
|
327
|
-
result.push({ name: '
|
|
326
|
+
if (f.schedules.length > 0)
|
|
327
|
+
result.push({ name: 'schedule', count: f.schedules.length });
|
|
328
328
|
// #middlewares includes the default command middleware, only count user-added ones
|
|
329
329
|
const userMiddlewareCount = this.#middlewares.length - 1; // subtract default #messageMiddleware
|
|
330
330
|
if (userMiddlewareCount > 0)
|
|
@@ -586,4 +586,3 @@ export class Plugin extends PluginBase {
|
|
|
586
586
|
export function defineContext(options) {
|
|
587
587
|
return options;
|
|
588
588
|
}
|
|
589
|
-
//# sourceMappingURL=plugin.js.map
|
package/lib/prompt.d.ts
CHANGED