@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,87 +0,0 @@
|
|
|
1
|
-
import { isRichSegment, richSegmentKind } from './base.js';
|
|
2
|
-
import { richSegmentRegistry } from './registry.js';
|
|
3
|
-
import { RICH_SEGMENT_MODE } from './types.js';
|
|
4
|
-
import { CONTENT_CHAIN_STAGE } from '@zhin.js/logger';
|
|
5
|
-
function asArray(content) {
|
|
6
|
-
return Array.isArray(content) ? content : [content];
|
|
7
|
-
}
|
|
8
|
-
function packSegments(out) {
|
|
9
|
-
if (out.length === 0)
|
|
10
|
-
return { type: 'text', data: { text: '' } };
|
|
11
|
-
if (out.length === 1)
|
|
12
|
-
return out[0];
|
|
13
|
-
return out;
|
|
14
|
-
}
|
|
15
|
-
function appendRendered(out, rendered) {
|
|
16
|
-
if (Array.isArray(rendered)) {
|
|
17
|
-
out.push(...rendered);
|
|
18
|
-
return;
|
|
19
|
-
}
|
|
20
|
-
out.push(rendered);
|
|
21
|
-
}
|
|
22
|
-
function primarySegmentType(rendered) {
|
|
23
|
-
if (typeof rendered === 'string')
|
|
24
|
-
return 'text';
|
|
25
|
-
if (Array.isArray(rendered)) {
|
|
26
|
-
const first = rendered[0];
|
|
27
|
-
if (typeof first === 'string')
|
|
28
|
-
return 'text';
|
|
29
|
-
const t = first?.type;
|
|
30
|
-
return typeof t === 'string' ? t : 'unknown';
|
|
31
|
-
}
|
|
32
|
-
const t = rendered.type;
|
|
33
|
-
return typeof t === 'string' ? t : 'unknown';
|
|
34
|
-
}
|
|
35
|
-
function detectRichSegmentFallback(mode, renderedType) {
|
|
36
|
-
if (mode === RICH_SEGMENT_MODE.IMAGE && renderedType !== 'image')
|
|
37
|
-
return true;
|
|
38
|
-
if (mode === RICH_SEGMENT_MODE.AUDIO && renderedType !== 'audio')
|
|
39
|
-
return true;
|
|
40
|
-
if (mode === RICH_SEGMENT_MODE.FILE && renderedType !== 'file')
|
|
41
|
-
return true;
|
|
42
|
-
return false;
|
|
43
|
-
}
|
|
44
|
-
export function hasRichSegment(content) {
|
|
45
|
-
if (content == null)
|
|
46
|
-
return false;
|
|
47
|
-
return asArray(content).some((item) => {
|
|
48
|
-
if (typeof item === 'string')
|
|
49
|
-
return false;
|
|
50
|
-
return richSegmentKind(item) != null || isRichSegment(item);
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
/** 按 Adapter 出站策略在 renderSendMessage 首步统一渲染富媒体段 */
|
|
54
|
-
export async function resolveRichSegments(content, policy, ctx) {
|
|
55
|
-
if (!hasRichSegment(content)) {
|
|
56
|
-
return content;
|
|
57
|
-
}
|
|
58
|
-
const items = asArray(content);
|
|
59
|
-
const out = [];
|
|
60
|
-
for (const item of items) {
|
|
61
|
-
if (typeof item === 'string') {
|
|
62
|
-
out.push(item);
|
|
63
|
-
continue;
|
|
64
|
-
}
|
|
65
|
-
const kind = isRichSegment(item) ? item.segmentType : richSegmentKind(item);
|
|
66
|
-
if (!kind || !richSegmentRegistry.has(kind)) {
|
|
67
|
-
out.push(item);
|
|
68
|
-
continue;
|
|
69
|
-
}
|
|
70
|
-
const rich = isRichSegment(item)
|
|
71
|
-
? item
|
|
72
|
-
: richSegmentRegistry.wrap(kind, item.data ?? {});
|
|
73
|
-
const mode = richSegmentRegistry.resolveMode(policy, kind);
|
|
74
|
-
const rendered = await rich.render(mode, ctx);
|
|
75
|
-
const renderedType = primarySegmentType(rendered);
|
|
76
|
-
const fallback = detectRichSegmentFallback(mode, renderedType);
|
|
77
|
-
ctx?.logContentChain?.({
|
|
78
|
-
stage: CONTENT_CHAIN_STAGE.RICH_SEGMENT,
|
|
79
|
-
kind,
|
|
80
|
-
mode,
|
|
81
|
-
fallback,
|
|
82
|
-
result: renderedType,
|
|
83
|
-
});
|
|
84
|
-
appendRendered(out, rendered);
|
|
85
|
-
}
|
|
86
|
-
return packSegments(out);
|
|
87
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { RichSegment } from './base.js';
|
|
2
|
-
import { type RichSegmentRenderContext, type RichSegmentRenderResult } from './types.js';
|
|
3
|
-
export interface TtsSegmentData {
|
|
4
|
-
text: string;
|
|
5
|
-
voice?: string;
|
|
6
|
-
provider?: string;
|
|
7
|
-
}
|
|
8
|
-
export declare class TtsSegment extends RichSegment<TtsSegmentData> {
|
|
9
|
-
readonly segmentType: "tts";
|
|
10
|
-
readonly type: "tts";
|
|
11
|
-
render(mode: string, ctx?: RichSegmentRenderContext): Promise<RichSegmentRenderResult>;
|
|
12
|
-
}
|
|
13
|
-
export declare function wrapTtsSegment(data: Record<string, unknown>): TtsSegment;
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { segment } from '../../utils.js';
|
|
2
|
-
import { RichSegment } from './base.js';
|
|
3
|
-
import { RICH_SEGMENT_MODE } from './types.js';
|
|
4
|
-
async function resolveSpeechPipeline(ctx) {
|
|
5
|
-
if (!ctx?.resolveCapability)
|
|
6
|
-
return undefined;
|
|
7
|
-
return ctx.resolveCapability('speech');
|
|
8
|
-
}
|
|
9
|
-
export class TtsSegment extends RichSegment {
|
|
10
|
-
segmentType = 'tts';
|
|
11
|
-
type = 'tts';
|
|
12
|
-
async render(mode, ctx) {
|
|
13
|
-
if (mode === RICH_SEGMENT_MODE.ORIGIN) {
|
|
14
|
-
return this.toJSON();
|
|
15
|
-
}
|
|
16
|
-
const text = typeof this.data.text === 'string' ? this.data.text : '';
|
|
17
|
-
if (mode === RICH_SEGMENT_MODE.TEXT) {
|
|
18
|
-
return segment.text(text);
|
|
19
|
-
}
|
|
20
|
-
if (mode === RICH_SEGMENT_MODE.AUDIO) {
|
|
21
|
-
if (!text.trim()) {
|
|
22
|
-
return segment.text('');
|
|
23
|
-
}
|
|
24
|
-
const pipeline = await resolveSpeechPipeline(ctx);
|
|
25
|
-
if (!pipeline) {
|
|
26
|
-
return this.render(RICH_SEGMENT_MODE.TEXT, ctx);
|
|
27
|
-
}
|
|
28
|
-
try {
|
|
29
|
-
const result = await pipeline.synthesize({
|
|
30
|
-
text,
|
|
31
|
-
voice: typeof this.data.voice === 'string' ? this.data.voice : undefined,
|
|
32
|
-
provider: typeof this.data.provider === 'string' ? this.data.provider : undefined,
|
|
33
|
-
});
|
|
34
|
-
const base64 = result.data.toString('base64');
|
|
35
|
-
const mime = result.format === 'wav' ? 'audio/wav' : 'audio/mpeg';
|
|
36
|
-
return segment('audio', { url: `data:${mime};base64,${base64}`, format: result.format });
|
|
37
|
-
}
|
|
38
|
-
catch {
|
|
39
|
-
return this.render(RICH_SEGMENT_MODE.TEXT, ctx);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
return this.render(RICH_SEGMENT_MODE.TEXT, ctx);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
export function wrapTtsSegment(data) {
|
|
46
|
-
return new TtsSegment({
|
|
47
|
-
text: String(data.text ?? ''),
|
|
48
|
-
voice: typeof data.voice === 'string' ? data.voice : undefined,
|
|
49
|
-
provider: typeof data.provider === 'string' ? data.provider : undefined,
|
|
50
|
-
});
|
|
51
|
-
}
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import type { MessageElement } from '../../types.js';
|
|
2
|
-
import type { ContentChainLogFields } from '@zhin.js/logger';
|
|
3
|
-
/** 内置 kind 常量(外部可增删,registry 为 SSOT) */
|
|
4
|
-
export declare const BUILTIN_RICH_SEGMENT_KINDS: {
|
|
5
|
-
readonly QRCODE: "qrcode";
|
|
6
|
-
readonly HTML: "html";
|
|
7
|
-
readonly MARKDOWN: "markdown";
|
|
8
|
-
readonly TTS: "tts";
|
|
9
|
-
};
|
|
10
|
-
export type BuiltinRichSegmentKind = (typeof BUILTIN_RICH_SEGMENT_KINDS)[keyof typeof BUILTIN_RICH_SEGMENT_KINDS];
|
|
11
|
-
/** 通用 mode 名;各 kind 在 registry 中声明支持的子集 */
|
|
12
|
-
export declare const RICH_SEGMENT_MODE: {
|
|
13
|
-
readonly ORIGIN: "origin";
|
|
14
|
-
readonly TEXT: "text";
|
|
15
|
-
readonly IMAGE: "image";
|
|
16
|
-
readonly FILE: "file";
|
|
17
|
-
readonly URL: "url";
|
|
18
|
-
readonly AUDIO: "audio";
|
|
19
|
-
readonly VIDEO: "video";
|
|
20
|
-
};
|
|
21
|
-
export type RichSegmentMode = (typeof RICH_SEGMENT_MODE)[keyof typeof RICH_SEGMENT_MODE] | string;
|
|
22
|
-
/** 任意已注册 kind → 渲染 mode */
|
|
23
|
-
export type OutboundRichSegmentPolicy = Record<string, string>;
|
|
24
|
-
/** html-renderer 可选包契约 */
|
|
25
|
-
export interface HtmlRendererForRichSegment {
|
|
26
|
-
render(html: string, options?: {
|
|
27
|
-
width?: number;
|
|
28
|
-
format?: 'png';
|
|
29
|
-
backgroundColor?: string;
|
|
30
|
-
}): Promise<{
|
|
31
|
-
format: string;
|
|
32
|
-
data: Buffer | string;
|
|
33
|
-
}>;
|
|
34
|
-
}
|
|
35
|
-
/** speech 可选包契约(@zhin.js/speech) */
|
|
36
|
-
export interface SpeechPipelineForRichSegment {
|
|
37
|
-
transcribe(input: {
|
|
38
|
-
data: Buffer;
|
|
39
|
-
mimeType?: string;
|
|
40
|
-
}): Promise<string>;
|
|
41
|
-
synthesize(input: {
|
|
42
|
-
text: string;
|
|
43
|
-
voice?: string;
|
|
44
|
-
format?: 'mp3' | 'wav';
|
|
45
|
-
speed?: number;
|
|
46
|
-
provider?: string;
|
|
47
|
-
}): Promise<{
|
|
48
|
-
data: Buffer;
|
|
49
|
-
format: 'mp3' | 'wav';
|
|
50
|
-
}>;
|
|
51
|
-
}
|
|
52
|
-
/** 未来 media-pipeline / ffmpeg 等 optional 包可复用同一 id */
|
|
53
|
-
export type RichSegmentCapabilityId = 'html-renderer' | 'speech' | 'media-pipeline' | string;
|
|
54
|
-
export interface RichSegmentRenderContext {
|
|
55
|
-
/** 按 id 懒加载能力(core 或 optional 包 register loader) */
|
|
56
|
-
resolveCapability: <T>(id: RichSegmentCapabilityId) => Promise<T | undefined>;
|
|
57
|
-
/** 可选:rich_segment stage 结构化日志 */
|
|
58
|
-
logContentChain?: (fields: ContentChainLogFields) => void;
|
|
59
|
-
warn?: (message: string) => void;
|
|
60
|
-
}
|
|
61
|
-
export type RichSegmentRenderResult = MessageElement | MessageElement[];
|
|
62
|
-
export interface RichSegmentLike {
|
|
63
|
-
readonly segmentType: string;
|
|
64
|
-
render(mode: string, ctx?: RichSegmentRenderContext): Promise<RichSegmentRenderResult>;
|
|
65
|
-
}
|
|
66
|
-
export interface RichSegmentKindDefinition {
|
|
67
|
-
kind: string;
|
|
68
|
-
/** policy 未指定时使用的 mode */
|
|
69
|
-
defaultMode: string;
|
|
70
|
-
/** 该 kind 支持的 mode 列表(policy 非法值会回退 defaultMode) */
|
|
71
|
-
modes: readonly string[];
|
|
72
|
-
wrap: (data: Record<string, unknown>) => RichSegmentLike;
|
|
73
|
-
}
|
|
74
|
-
export interface RichSegmentCapabilityLoaderOptions {
|
|
75
|
-
warn?: (message: string) => void;
|
|
76
|
-
getConfig?: () => Record<string, unknown> | undefined;
|
|
77
|
-
logContentChain?: RichSegmentRenderContext['logContentChain'];
|
|
78
|
-
}
|
|
79
|
-
export type RichSegmentCapabilityLoader = (options: RichSegmentCapabilityLoaderOptions) => Promise<unknown>;
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/** 内置 kind 常量(外部可增删,registry 为 SSOT) */
|
|
2
|
-
export const BUILTIN_RICH_SEGMENT_KINDS = {
|
|
3
|
-
QRCODE: 'qrcode',
|
|
4
|
-
HTML: 'html',
|
|
5
|
-
MARKDOWN: 'markdown',
|
|
6
|
-
TTS: 'tts',
|
|
7
|
-
};
|
|
8
|
-
/** 通用 mode 名;各 kind 在 registry 中声明支持的子集 */
|
|
9
|
-
export const RICH_SEGMENT_MODE = {
|
|
10
|
-
ORIGIN: 'origin',
|
|
11
|
-
TEXT: 'text',
|
|
12
|
-
IMAGE: 'image',
|
|
13
|
-
FILE: 'file',
|
|
14
|
-
URL: 'url',
|
|
15
|
-
AUDIO: 'audio',
|
|
16
|
-
VIDEO: 'video',
|
|
17
|
-
};
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/** Node / Deno 共用的进程身份与 stdin 绑定(供 ProcessAdapter 使用) */
|
|
2
|
-
export declare function runtimePid(): string;
|
|
3
|
-
export declare function runtimeUser(): string;
|
|
4
|
-
/** 显式允许在非 TTY 场景绑定 stdin(如 `deno task dev --watch` 子进程) */
|
|
5
|
-
export declare function shouldBindProcessStdin(): boolean;
|
|
6
|
-
/** 是否适合绑定交互式 stdin(Deploy / 管道场景为 false) */
|
|
7
|
-
export declare function isInteractiveStdin(): boolean;
|
|
8
|
-
export declare function isDenoDeploy(): boolean;
|
|
9
|
-
export declare function bindStdin(onChunk: (chunk: string) => void): () => void;
|
package/lib/built/runtime-io.js
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
/** Node / Deno 共用的进程身份与 stdin 绑定(供 ProcessAdapter 使用) */
|
|
2
|
-
export function runtimePid() {
|
|
3
|
-
if (typeof Deno !== "undefined")
|
|
4
|
-
return String(Deno.pid);
|
|
5
|
-
return String(process.pid);
|
|
6
|
-
}
|
|
7
|
-
export function runtimeUser() {
|
|
8
|
-
if (typeof Deno !== "undefined") {
|
|
9
|
-
return Deno.env.get("USER") ?? Deno.env.get("USERNAME") ?? "deno";
|
|
10
|
-
}
|
|
11
|
-
return process.env.USER ?? "user";
|
|
12
|
-
}
|
|
13
|
-
/** 显式允许在非 TTY 场景绑定 stdin(如 `deno task dev --watch` 子进程) */
|
|
14
|
-
export function shouldBindProcessStdin() {
|
|
15
|
-
if (isDenoDeploy())
|
|
16
|
-
return false;
|
|
17
|
-
const force = envFlag("ZHIN_BIND_STDIN");
|
|
18
|
-
if (force === "0" || force === "false")
|
|
19
|
-
return false;
|
|
20
|
-
if (force === "1" || force === "true")
|
|
21
|
-
return true;
|
|
22
|
-
return isInteractiveStdin();
|
|
23
|
-
}
|
|
24
|
-
function envFlag(key) {
|
|
25
|
-
if (typeof Deno !== "undefined") {
|
|
26
|
-
return Deno.env.get(key)?.trim().toLowerCase();
|
|
27
|
-
}
|
|
28
|
-
return process.env[key]?.trim().toLowerCase();
|
|
29
|
-
}
|
|
30
|
-
/** 是否适合绑定交互式 stdin(Deploy / 管道场景为 false) */
|
|
31
|
-
export function isInteractiveStdin() {
|
|
32
|
-
if (typeof Deno !== "undefined") {
|
|
33
|
-
try {
|
|
34
|
-
return Deno.stdin.isTerminal();
|
|
35
|
-
}
|
|
36
|
-
catch {
|
|
37
|
-
return false;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
return Boolean(process.stdin.isTTY);
|
|
41
|
-
}
|
|
42
|
-
export function isDenoDeploy() {
|
|
43
|
-
return typeof Deno !== "undefined" &&
|
|
44
|
-
Deno.env.get("DENO_DEPLOYMENT_ID") != null;
|
|
45
|
-
}
|
|
46
|
-
export function bindStdin(onChunk) {
|
|
47
|
-
if (typeof Deno !== "undefined") {
|
|
48
|
-
const ac = new AbortController();
|
|
49
|
-
const decoder = new TextDecoder();
|
|
50
|
-
void (async () => {
|
|
51
|
-
try {
|
|
52
|
-
for await (const bytes of Deno.stdin.readable) {
|
|
53
|
-
if (ac.signal.aborted)
|
|
54
|
-
break;
|
|
55
|
-
onChunk(decoder.decode(bytes));
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
catch {
|
|
59
|
-
/* aborted or stream closed */
|
|
60
|
-
}
|
|
61
|
-
})();
|
|
62
|
-
return () => ac.abort();
|
|
63
|
-
}
|
|
64
|
-
const handler = (data) => onChunk(data.toString());
|
|
65
|
-
process.stdin.on("data", handler);
|
|
66
|
-
return () => process.stdin.removeListener("data", handler);
|
|
67
|
-
}
|
package/lib/built/schedule.d.ts
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ScheduleFeature — 管理插件注册的内存定时任务
|
|
3
|
-
*/
|
|
4
|
-
import { Feature, FeatureJSON, type ScheduleKind, type HolidayInput, type ScatterInput } from '@zhin.js/kernel';
|
|
5
|
-
export interface ScheduleDescriptor {
|
|
6
|
-
kind: ScheduleKind | 'every' | 'at';
|
|
7
|
-
/** 6 段 cron(solar/lunar/workday/freeDay/holiday) */
|
|
8
|
-
cron?: string;
|
|
9
|
-
everyMs?: number;
|
|
10
|
-
atMs?: number;
|
|
11
|
-
scatterInput?: ScatterInput;
|
|
12
|
-
holidayInput?: HolidayInput;
|
|
13
|
-
tz?: string;
|
|
14
|
-
}
|
|
15
|
-
export interface ScheduleHandle {
|
|
16
|
-
id: string;
|
|
17
|
-
descriptor: ScheduleDescriptor;
|
|
18
|
-
dispose: () => void;
|
|
19
|
-
}
|
|
20
|
-
export interface ScheduleContextExtensions {
|
|
21
|
-
addSchedule(descriptor: ScheduleDescriptor, callback: () => void | Promise<void>, id?: string): () => void;
|
|
22
|
-
}
|
|
23
|
-
declare module '../plugin.js' {
|
|
24
|
-
namespace Plugin {
|
|
25
|
-
interface Extensions extends ScheduleContextExtensions {
|
|
26
|
-
}
|
|
27
|
-
interface Contexts {
|
|
28
|
-
schedule: ScheduleFeature;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
export declare class ScheduleFeature extends Feature<ScheduleHandle> {
|
|
33
|
-
readonly name: "schedule";
|
|
34
|
-
readonly icon = "Clock";
|
|
35
|
-
readonly desc = "\u65E5\u5386\u8C03\u5EA6";
|
|
36
|
-
readonly byName: Map<string, ScheduleHandle>;
|
|
37
|
-
add(handle: ScheduleHandle, pluginName: string): () => void;
|
|
38
|
-
remove(handle: ScheduleHandle): boolean;
|
|
39
|
-
get(id: string): ScheduleHandle | undefined;
|
|
40
|
-
stopAll(): void;
|
|
41
|
-
getStatus(): Array<{
|
|
42
|
-
id: string;
|
|
43
|
-
kind: string;
|
|
44
|
-
expression?: string;
|
|
45
|
-
running: boolean;
|
|
46
|
-
nextExecution: Date | null;
|
|
47
|
-
plugin: string;
|
|
48
|
-
}>;
|
|
49
|
-
dispose(): void;
|
|
50
|
-
toJSON(pluginName?: string): FeatureJSON;
|
|
51
|
-
get extensions(): {
|
|
52
|
-
addSchedule(descriptor: ScheduleDescriptor, callback: () => void | Promise<void>, id?: string): () => void;
|
|
53
|
-
};
|
|
54
|
-
}
|
package/lib/built/schedule.js
DELETED
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ScheduleFeature — 管理插件注册的内存定时任务
|
|
3
|
-
*/
|
|
4
|
-
import { Feature, ScheduleEngine, getScheduleEngine, setScheduleEngine } from '@zhin.js/kernel';
|
|
5
|
-
function ensureEngine() {
|
|
6
|
-
let engine = getScheduleEngine();
|
|
7
|
-
if (!engine) {
|
|
8
|
-
engine = new ScheduleEngine();
|
|
9
|
-
setScheduleEngine(engine);
|
|
10
|
-
}
|
|
11
|
-
return engine;
|
|
12
|
-
}
|
|
13
|
-
export class ScheduleFeature extends Feature {
|
|
14
|
-
name = 'schedule';
|
|
15
|
-
icon = 'Clock';
|
|
16
|
-
desc = '日历调度';
|
|
17
|
-
byName = new Map();
|
|
18
|
-
add(handle, pluginName) {
|
|
19
|
-
this.byName.set(handle.id, handle);
|
|
20
|
-
return super.add(handle, pluginName);
|
|
21
|
-
}
|
|
22
|
-
remove(handle) {
|
|
23
|
-
if (!this.byName.has(handle.id) && !this.items.includes(handle)) {
|
|
24
|
-
return false;
|
|
25
|
-
}
|
|
26
|
-
this.byName.delete(handle.id);
|
|
27
|
-
const removed = super.remove(handle);
|
|
28
|
-
if (removed) {
|
|
29
|
-
handle.dispose();
|
|
30
|
-
}
|
|
31
|
-
return removed;
|
|
32
|
-
}
|
|
33
|
-
get(id) {
|
|
34
|
-
return this.byName.get(id);
|
|
35
|
-
}
|
|
36
|
-
stopAll() {
|
|
37
|
-
for (const handle of this.items) {
|
|
38
|
-
handle.dispose();
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
getStatus() {
|
|
42
|
-
const engine = getScheduleEngine();
|
|
43
|
-
const engineStatus = engine?.getStatus() ?? [];
|
|
44
|
-
const byId = new Map(engineStatus.map((s) => [s.id, s]));
|
|
45
|
-
return this.items.map((handle) => {
|
|
46
|
-
let pluginName = 'unknown';
|
|
47
|
-
for (const [name, items] of this.pluginItems) {
|
|
48
|
-
if (items.includes(handle)) {
|
|
49
|
-
pluginName = name;
|
|
50
|
-
break;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
const st = byId.get(handle.id);
|
|
54
|
-
return {
|
|
55
|
-
id: handle.id,
|
|
56
|
-
kind: handle.descriptor.kind,
|
|
57
|
-
expression: handle.descriptor.cron,
|
|
58
|
-
running: st?.running ?? true,
|
|
59
|
-
nextExecution: st?.nextExecution ?? null,
|
|
60
|
-
plugin: pluginName,
|
|
61
|
-
};
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
dispose() {
|
|
65
|
-
this.stopAll();
|
|
66
|
-
}
|
|
67
|
-
toJSON(pluginName) {
|
|
68
|
-
const list = pluginName ? this.getByPlugin(pluginName) : this.items;
|
|
69
|
-
return {
|
|
70
|
-
name: this.name,
|
|
71
|
-
icon: this.icon,
|
|
72
|
-
desc: this.desc,
|
|
73
|
-
count: list.length,
|
|
74
|
-
items: list.map((h) => ({
|
|
75
|
-
id: h.id,
|
|
76
|
-
kind: h.descriptor.kind,
|
|
77
|
-
cron: h.descriptor.cron,
|
|
78
|
-
})),
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
get extensions() {
|
|
82
|
-
const feature = this;
|
|
83
|
-
return {
|
|
84
|
-
addSchedule(descriptor, callback, id) {
|
|
85
|
-
const plugin = this;
|
|
86
|
-
const jobId = id ?? `sched_${Math.random().toString(36).slice(2, 10)}`;
|
|
87
|
-
const engine = ensureEngine();
|
|
88
|
-
const disposeEngine = engine.register(jobId, descriptor.kind, async () => {
|
|
89
|
-
await callback();
|
|
90
|
-
}, {
|
|
91
|
-
cron: descriptor.cron,
|
|
92
|
-
everyMs: descriptor.everyMs,
|
|
93
|
-
atMs: descriptor.atMs,
|
|
94
|
-
scatterInput: descriptor.scatterInput,
|
|
95
|
-
holidayInput: descriptor.holidayInput,
|
|
96
|
-
tz: descriptor.tz,
|
|
97
|
-
});
|
|
98
|
-
const handle = {
|
|
99
|
-
id: jobId,
|
|
100
|
-
descriptor,
|
|
101
|
-
dispose: () => {
|
|
102
|
-
disposeEngine();
|
|
103
|
-
},
|
|
104
|
-
};
|
|
105
|
-
const dispose = feature.add(handle, plugin.name);
|
|
106
|
-
plugin.recordFeatureContribution(feature.name, jobId);
|
|
107
|
-
plugin.onDispose(dispose);
|
|
108
|
-
return dispose;
|
|
109
|
-
},
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { Schema } from '@zhin.js/schema';
|
|
2
|
-
import { Adapter } from '../adapter.js';
|
|
3
|
-
import type { EndpointConfigRecord, EndpointManager, ProvisionContext } from './endpoint-manager.js';
|
|
4
|
-
export declare class SchemaEndpointManager implements EndpointManager {
|
|
5
|
-
private readonly adapter;
|
|
6
|
-
private readonly schema;
|
|
7
|
-
constructor(adapter: Adapter, schema: Schema);
|
|
8
|
-
supportsProvision(): boolean;
|
|
9
|
-
listEndpoints(): EndpointConfigRecord[];
|
|
10
|
-
addEndpoint(ctx: ProvisionContext): Promise<EndpointConfigRecord>;
|
|
11
|
-
editEndpoint(name: string, ctx: ProvisionContext): Promise<EndpointConfigRecord>;
|
|
12
|
-
removeEndpoint(name: string): Promise<boolean>;
|
|
13
|
-
startEndpoint(name: string, ctx: ProvisionContext): Promise<void>;
|
|
14
|
-
stopEndpoint(name: string): Promise<boolean>;
|
|
15
|
-
}
|
|
16
|
-
export declare function resolveEndpointManager(adapter: Adapter): EndpointManager | null;
|
|
17
|
-
export declare function adapterSupportsProvision(adapter: Adapter): boolean;
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { SchemaInteraction } from '../schema-interaction.js';
|
|
2
|
-
function readConfigEndpoints(root, context) {
|
|
3
|
-
const configService = root.inject('config');
|
|
4
|
-
const raw = configService?.getRaw(configService.primaryFile);
|
|
5
|
-
return (raw?.endpoints ?? []).filter((e) => e.context === context);
|
|
6
|
-
}
|
|
7
|
-
export class SchemaEndpointManager {
|
|
8
|
-
adapter;
|
|
9
|
-
schema;
|
|
10
|
-
constructor(adapter, schema) {
|
|
11
|
-
this.adapter = adapter;
|
|
12
|
-
this.schema = schema;
|
|
13
|
-
}
|
|
14
|
-
supportsProvision() {
|
|
15
|
-
return true;
|
|
16
|
-
}
|
|
17
|
-
listEndpoints() {
|
|
18
|
-
return readConfigEndpoints(this.adapter.plugin.root, String(this.adapter.name));
|
|
19
|
-
}
|
|
20
|
-
async addEndpoint(ctx) {
|
|
21
|
-
const interaction = new SchemaInteraction(this.adapter.plugin, ctx.message);
|
|
22
|
-
await ctx.onStatusUpdate(`请按提示填写 ${String(this.adapter.name)} endpoint 配置:`);
|
|
23
|
-
const name = await interaction.text('Endpoint id(zhin.config endpoints[].id):');
|
|
24
|
-
const fields = await interaction.getValueWithSchema(this.schema);
|
|
25
|
-
return {
|
|
26
|
-
context: String(this.adapter.name),
|
|
27
|
-
id: name.trim(),
|
|
28
|
-
...fields,
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
async editEndpoint(name, ctx) {
|
|
32
|
-
const existing = this.listEndpoints().find((e) => e.id === name);
|
|
33
|
-
if (!existing) {
|
|
34
|
-
throw new Error(`配置中不存在 ${String(this.adapter.name)}/${name}`);
|
|
35
|
-
}
|
|
36
|
-
await ctx.onStatusUpdate(`编辑 ${String(this.adapter.name)}/${name},留空字段将保留原值。`);
|
|
37
|
-
const interaction = new SchemaInteraction(this.adapter.plugin, ctx.message);
|
|
38
|
-
const fields = await interaction.getValueWithSchema(this.schema);
|
|
39
|
-
return {
|
|
40
|
-
...existing,
|
|
41
|
-
...fields,
|
|
42
|
-
context: String(this.adapter.name),
|
|
43
|
-
id: name,
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
async removeEndpoint(name) {
|
|
47
|
-
return this.listEndpoints().some((e) => e.id === name);
|
|
48
|
-
}
|
|
49
|
-
async startEndpoint(name, ctx) {
|
|
50
|
-
const rec = this.listEndpoints().find((e) => e.id === name);
|
|
51
|
-
if (!rec)
|
|
52
|
-
throw new Error(`配置中不存在 ${String(this.adapter.name)}/${name}`);
|
|
53
|
-
await ctx.onStatusUpdate(`正在连接 ${String(this.adapter.name)}/${name}…`);
|
|
54
|
-
}
|
|
55
|
-
async stopEndpoint(name) {
|
|
56
|
-
return this.adapter.endpoints.has(name);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
export function resolveEndpointManager(adapter) {
|
|
60
|
-
const custom = adapter.getEndpointManager?.();
|
|
61
|
-
if (custom)
|
|
62
|
-
return custom;
|
|
63
|
-
const schema = adapter.getEndpointConfigSchema?.() ??
|
|
64
|
-
adapter.constructor.endpointConfigSchema;
|
|
65
|
-
if (schema) {
|
|
66
|
-
return new SchemaEndpointManager(adapter, schema);
|
|
67
|
-
}
|
|
68
|
-
return null;
|
|
69
|
-
}
|
|
70
|
-
export function adapterSupportsProvision(adapter) {
|
|
71
|
-
const manager = resolveEndpointManager(adapter);
|
|
72
|
-
return manager?.supportsProvision() ?? false;
|
|
73
|
-
}
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* SchemaFeature — 插件配置 Schema 注册表
|
|
3
|
-
*
|
|
4
|
-
* 插件通过 declareConfig(key, schema) 声明配置项及其 Schema,
|
|
5
|
-
* SchemaFeature 全局收集后供 Web 控制台渲染配置编辑表单。
|
|
6
|
-
*
|
|
7
|
-
* 与 ConfigFeature 协作:
|
|
8
|
-
* - declareConfig 内部调用 addConfig(key, defaults) 写入默认值
|
|
9
|
-
* - Schema.toJSON() 传给前端驱动 PluginConfigForm
|
|
10
|
-
* - reloadable 标记决定保存后是否自动重载插件
|
|
11
|
-
*/
|
|
12
|
-
import { Schema } from '@zhin.js/schema';
|
|
13
|
-
import { Feature, FeatureJSON } from '@zhin.js/kernel';
|
|
14
|
-
export interface SchemaRecord {
|
|
15
|
-
/** 配置 key(对应 zhin.config.yml 中的顶级字段) */
|
|
16
|
-
key: string;
|
|
17
|
-
/** Schema 实例 */
|
|
18
|
-
schema: Schema;
|
|
19
|
-
/** 保存后是否支持热重载(http/database 等底层服务应为 false) */
|
|
20
|
-
reloadable: boolean;
|
|
21
|
-
}
|
|
22
|
-
export interface SchemaContextExtensions {
|
|
23
|
-
/**
|
|
24
|
-
* 声明插件配置 Schema
|
|
25
|
-
* @param key 配置 key,如 "rss"
|
|
26
|
-
* @param schema Schema.object({...}) 定义
|
|
27
|
-
* @param options.reloadable 保存后是否自动重载,默认 true
|
|
28
|
-
* @returns 当前配置值(已合并默认值)
|
|
29
|
-
*/
|
|
30
|
-
declareConfig<T extends Record<string, any>>(key: string, schema: Schema<T>, options?: {
|
|
31
|
-
reloadable?: boolean;
|
|
32
|
-
}): Required<T>;
|
|
33
|
-
}
|
|
34
|
-
declare module '../plugin.js' {
|
|
35
|
-
namespace Plugin {
|
|
36
|
-
interface Extensions extends SchemaContextExtensions {
|
|
37
|
-
}
|
|
38
|
-
interface Contexts {
|
|
39
|
-
schema: SchemaFeature;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
export declare class SchemaFeature extends Feature<SchemaRecord> {
|
|
44
|
-
readonly name: "schema";
|
|
45
|
-
readonly icon = "FileCode";
|
|
46
|
-
readonly desc = "\u914D\u7F6E\u6A21\u578B";
|
|
47
|
-
/**
|
|
48
|
-
* 按配置 key 查找 Schema
|
|
49
|
-
*/
|
|
50
|
-
getByKey(key: string): SchemaRecord | null;
|
|
51
|
-
/**
|
|
52
|
-
* 获取指定插件名注册的 Schema
|
|
53
|
-
*/
|
|
54
|
-
getByPluginName(pluginName: string): SchemaRecord | null;
|
|
55
|
-
/**
|
|
56
|
-
* 获取某个 key 的 Schema 实例(WebSocket handler 使用)
|
|
57
|
-
*/
|
|
58
|
-
get(keyOrPlugin: string): Schema | null;
|
|
59
|
-
/**
|
|
60
|
-
* 判断某个 key 对应的插件是否支持热重载
|
|
61
|
-
*/
|
|
62
|
-
isReloadable(keyOrPlugin: string): boolean;
|
|
63
|
-
/**
|
|
64
|
-
* 通过 pluginName 获取对应的 config key
|
|
65
|
-
*/
|
|
66
|
-
resolveConfigKey(pluginName: string): string | null;
|
|
67
|
-
/**
|
|
68
|
-
* 返回 pluginName → configKey 的映射
|
|
69
|
-
*/
|
|
70
|
-
getPluginKeyMap(): Map<string, string>;
|
|
71
|
-
toJSON(pluginName?: string): FeatureJSON;
|
|
72
|
-
get extensions(): {
|
|
73
|
-
declareConfig<T extends Record<string, any>>(key: string, schema: Schema<T>, options?: {
|
|
74
|
-
reloadable?: boolean;
|
|
75
|
-
}): Required<T>;
|
|
76
|
-
};
|
|
77
|
-
}
|