@zhin.js/core 1.5.16 → 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,5 +1,32 @@
|
|
|
1
|
+
import { commandFeatureId, isCommandIndex } from '@zhin.js/command';
|
|
2
|
+
import { createRootPrivateToken, resolveLocale } from '@zhin.js/plugin-runtime';
|
|
3
|
+
import { operationInputBinding, operationInputSignal, operationInputResources, operationSession } from '@zhin.js/feature-kit';
|
|
4
|
+
/** Internal send binding retained by one inbound operation; never a wire/config field. */
|
|
5
|
+
export const operationEndpoint = Symbol('zhin.im.operation-endpoint');
|
|
6
|
+
/** Core-only trusted operation binding; never read from message metadata. */
|
|
7
|
+
export const interactionOperationScope = Symbol('InteractionOperationScope');
|
|
8
|
+
export const imOperationResourcesToken = createRootPrivateToken('zhin.im.operation-resources', 'Host resources for one authorized IM capability operation');
|
|
1
9
|
const componentCallBrand = 'zhin.component-call/1';
|
|
2
10
|
const rawContentBrand = 'zhin.raw-content/1';
|
|
11
|
+
const untrustedContentBrand = 'zhin.untrusted-content/1';
|
|
12
|
+
/**
|
|
13
|
+
* Mark content as coming from an untrusted source (ADR 0056 §2): its media may only be http(s) URLs,
|
|
14
|
+
* bounded inline data, platform file tokens, or local paths that `trust.authorizePath` admits (or that
|
|
15
|
+
* trusted code built with {@link trustedMediaRef}). Anything else is replaced by a visible notice and logged.
|
|
16
|
+
*/
|
|
17
|
+
export function untrustedContent(content, trust) {
|
|
18
|
+
if (!trust || typeof trust !== 'object' || typeof trust.source !== 'string' || !trust.source.trim()) {
|
|
19
|
+
throw new TypeError('untrustedContent requires a trust policy with a source label');
|
|
20
|
+
}
|
|
21
|
+
return Object.freeze({ $content: untrustedContentBrand, content, trust: Object.freeze({ ...trust }) });
|
|
22
|
+
}
|
|
23
|
+
export function isUntrustedContent(value) {
|
|
24
|
+
return !Array.isArray(value)
|
|
25
|
+
&& typeof value === 'object'
|
|
26
|
+
&& value !== null
|
|
27
|
+
&& '$content' in value
|
|
28
|
+
&& value.$content === untrustedContentBrand;
|
|
29
|
+
}
|
|
3
30
|
export function component(name, props) {
|
|
4
31
|
if (!name.trim())
|
|
5
32
|
throw new TypeError('Component name cannot be empty');
|
|
@@ -32,7 +59,11 @@ export function isSegmentContent(value) {
|
|
|
32
59
|
&& typeof value.data === 'object'
|
|
33
60
|
&& value.data !== null;
|
|
34
61
|
}
|
|
35
|
-
|
|
62
|
+
/** @internal Generation-scoped implementation of the public Message contract. */
|
|
63
|
+
export class RuntimeMessage {
|
|
64
|
+
locale;
|
|
65
|
+
commandPrefix;
|
|
66
|
+
commandMenu;
|
|
36
67
|
conversation;
|
|
37
68
|
content;
|
|
38
69
|
generation;
|
|
@@ -44,33 +75,35 @@ export class Message {
|
|
|
44
75
|
mentioned;
|
|
45
76
|
replyTo;
|
|
46
77
|
clientAdapter;
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
throw new Error('Message has no Endpoint Client context');
|
|
58
|
-
}, clientAdapter) {
|
|
78
|
+
origin;
|
|
79
|
+
#facts;
|
|
80
|
+
#operation;
|
|
81
|
+
#session;
|
|
82
|
+
/** Core owns these immutable facts; author rebinding shares them and the captured operation. */
|
|
83
|
+
constructor(facts, operation) {
|
|
84
|
+
this.#facts = Object.freeze(facts);
|
|
85
|
+
this.#operation = Object.freeze(operation);
|
|
86
|
+
const { conversation, content, sender, segments, message, endpointId, mentioned, replyTo } = facts;
|
|
87
|
+
const { reply } = operation;
|
|
59
88
|
this.conversation = conversation;
|
|
60
89
|
this.content = content;
|
|
61
|
-
this.generation = generation;
|
|
90
|
+
this.generation = operation.generation;
|
|
62
91
|
this.sender = sender;
|
|
63
|
-
this.metadata = metadata;
|
|
92
|
+
this.metadata = facts.metadata ?? Object.freeze({});
|
|
64
93
|
this.segments = segments;
|
|
65
94
|
this.message = message;
|
|
66
95
|
this.endpointId = endpointId;
|
|
67
96
|
this.mentioned = mentioned;
|
|
68
97
|
this.replyTo = replyTo;
|
|
69
|
-
this.clientAdapter = clientAdapter;
|
|
70
|
-
this
|
|
71
|
-
this
|
|
98
|
+
this.clientAdapter = operation.clientAdapter;
|
|
99
|
+
this.locale = resolveLocale(operation.presentation?.locale);
|
|
100
|
+
this.origin = operation.origin;
|
|
101
|
+
if (operation.snapshot)
|
|
102
|
+
operation.registerOperationView?.(this, operation.requester ?? operation.snapshot.root);
|
|
103
|
+
const requester = operation.requester;
|
|
104
|
+
this.$reply = (content) => requester === undefined ? reply(content) : reply(content, requester);
|
|
72
105
|
this.$replyFrom = (requester, content) => reply(content, requester);
|
|
73
|
-
this.$sendTo = (target, content) => reply(content,
|
|
106
|
+
this.$sendTo = (target, content) => reply(content, requester, target);
|
|
74
107
|
this.$replyToPrivate = (content, from) => {
|
|
75
108
|
if (!sender)
|
|
76
109
|
throw new Error('Cannot $replyToPrivate: message has no sender');
|
|
@@ -84,36 +117,119 @@ export class Message {
|
|
|
84
117
|
else if (from != null && typeof from === 'object') {
|
|
85
118
|
parent = from;
|
|
86
119
|
}
|
|
87
|
-
return reply(content,
|
|
120
|
+
return reply(content, requester, {
|
|
88
121
|
kind: 'private',
|
|
89
122
|
id: sender.id,
|
|
90
123
|
...(parent ? { parent } : {}),
|
|
91
124
|
});
|
|
92
125
|
};
|
|
93
126
|
this.$replyToGroup = (groupId, content) => {
|
|
94
|
-
return reply(content,
|
|
127
|
+
return reply(content, requester, { kind: 'group', id: groupId });
|
|
95
128
|
};
|
|
96
129
|
this.$replyToChannel = (channelId, guildId, content, threadId) => {
|
|
97
|
-
return reply(content,
|
|
130
|
+
return reply(content, requester, {
|
|
98
131
|
kind: 'channel',
|
|
99
132
|
id: channelId,
|
|
100
133
|
parent: { kind: 'channel', id: guildId },
|
|
101
134
|
...(threadId ? { threadId } : {}),
|
|
102
135
|
});
|
|
103
136
|
};
|
|
137
|
+
const commands = operation.presentation?.commands ?? operation.presentation?.resolveCommands?.(this);
|
|
138
|
+
this.commandPrefix = commands?.prefix;
|
|
139
|
+
this.commandMenu = commands?.menu;
|
|
140
|
+
if (operation.session) {
|
|
141
|
+
this.#session = Object.freeze({ ...operation.session,
|
|
142
|
+
reply: (value) => this.$reply(value),
|
|
143
|
+
});
|
|
144
|
+
}
|
|
104
145
|
Object.freeze(this);
|
|
105
146
|
}
|
|
147
|
+
/** The same captured data, with reply authority rebound by operationInputBinding. */
|
|
148
|
+
[operationSession]() {
|
|
149
|
+
this.#operation.assertActive?.();
|
|
150
|
+
return this.#session;
|
|
151
|
+
}
|
|
152
|
+
/** @internal A frozen view whose sends retain the current author's exact operation. */
|
|
153
|
+
[operationInputBinding](owner, snapshot) {
|
|
154
|
+
this.#operation.assertActive?.();
|
|
155
|
+
if (snapshot.generation !== this.generation || (this.#operation.snapshot && snapshot !== this.#operation.snapshot)) {
|
|
156
|
+
throw new Error('Message author binding belongs to another generation operation');
|
|
157
|
+
}
|
|
158
|
+
if (!snapshot.tree.has(owner))
|
|
159
|
+
throw new Error(`Unknown Message author: ${owner}`);
|
|
160
|
+
if (this.#operation.requester === owner && this.#operation.snapshot === snapshot)
|
|
161
|
+
return this;
|
|
162
|
+
return new RuntimeMessage(this.#facts, {
|
|
163
|
+
...this.#operation,
|
|
164
|
+
requester: owner,
|
|
165
|
+
snapshot,
|
|
166
|
+
presentation: {
|
|
167
|
+
locale: this.locale,
|
|
168
|
+
...(this.commandPrefix !== undefined
|
|
169
|
+
? { commands: { prefix: this.commandPrefix, menu: this.commandMenu } }
|
|
170
|
+
: {}),
|
|
171
|
+
},
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
/** @internal Metadata fields cannot replace this actual leased operation factory. */
|
|
175
|
+
[operationInputResources](snapshot) {
|
|
176
|
+
this.#operation.assertActive?.();
|
|
177
|
+
if (snapshot !== this.#operation.snapshot || snapshot.generation !== this.generation) {
|
|
178
|
+
throw new Error('Message resources belong to another generation operation');
|
|
179
|
+
}
|
|
180
|
+
if (!this.#operation.createOperationResources)
|
|
181
|
+
return undefined;
|
|
182
|
+
const signal = this.#operation.signal ?? new AbortController().signal;
|
|
183
|
+
return Object.freeze({ signal, create: (input) => {
|
|
184
|
+
this.#operation.assertActive?.();
|
|
185
|
+
if (!snapshot.tree.has(input.owner))
|
|
186
|
+
throw new Error(`Unknown operation owner: ${input.owner}`);
|
|
187
|
+
const actualSignal = input.signal === signal ? signal : AbortSignal.any([signal, input.signal]);
|
|
188
|
+
return Object.freeze({ signal: actualSignal, resources: this.#operation.createOperationResources?.({
|
|
189
|
+
message: this, owner: input.owner, signal: actualSignal,
|
|
190
|
+
}) });
|
|
191
|
+
} });
|
|
192
|
+
}
|
|
193
|
+
/** @internal Explicit operation cancellation; replacement alone does not end accepted work. */
|
|
194
|
+
[operationInputSignal]() {
|
|
195
|
+
this.#operation.assertActive?.();
|
|
196
|
+
return this.#operation.signal;
|
|
197
|
+
}
|
|
198
|
+
/** @internal The command/handler author's actual leased operation. */
|
|
199
|
+
[interactionOperationScope]() {
|
|
200
|
+
this.#operation.assertActive?.();
|
|
201
|
+
return this.#operation.snapshot ? {
|
|
202
|
+
snapshot: this.#operation.snapshot,
|
|
203
|
+
owner: this.#operation.requester ?? this.#operation.snapshot.root,
|
|
204
|
+
signal: this.#operation.signal,
|
|
205
|
+
...(this.#operation.captureInteraction ? { retain: () => {
|
|
206
|
+
this.#operation.assertActive?.();
|
|
207
|
+
return this.#operation.captureInteraction(this.#operation.requester ?? this.#operation.snapshot.root);
|
|
208
|
+
} } : {}),
|
|
209
|
+
} : undefined;
|
|
210
|
+
}
|
|
106
211
|
/** 平台原生消息 id(`message` 未提供时为 undefined)。 */
|
|
107
212
|
get id() {
|
|
108
213
|
return this.message?.id;
|
|
109
214
|
}
|
|
215
|
+
formatCommand(localPath, owner) {
|
|
216
|
+
this.#operation.assertActive?.();
|
|
217
|
+
if (!this.#operation.snapshot)
|
|
218
|
+
return undefined;
|
|
219
|
+
const commands = this.#operation.snapshot.projections.get(commandFeatureId);
|
|
220
|
+
return isCommandIndex(commands)
|
|
221
|
+
? commands.formatCommand(owner ?? this.#operation.requester ?? this.#operation.snapshot.root, localPath, this.commandPrefix, this.locale)
|
|
222
|
+
: undefined;
|
|
223
|
+
}
|
|
110
224
|
$reply;
|
|
111
225
|
/**
|
|
112
226
|
* Platform-native Client that received this message. The getter is
|
|
113
227
|
* generation-scoped; retaining the returned Client after dispatch is invalid.
|
|
114
228
|
*/
|
|
115
229
|
get $client() {
|
|
116
|
-
|
|
230
|
+
if (!this.#operation.client)
|
|
231
|
+
throw new Error('Message has no Endpoint Client context');
|
|
232
|
+
return this.#operation.client();
|
|
117
233
|
}
|
|
118
234
|
$replyFrom;
|
|
119
235
|
/**
|
|
@@ -158,6 +274,8 @@ export class Message {
|
|
|
158
274
|
*/
|
|
159
275
|
$replyToChannel;
|
|
160
276
|
}
|
|
277
|
+
/** Constructor for canonical runtime Message values. */
|
|
278
|
+
export const Message = RuntimeMessage;
|
|
161
279
|
export function createOutboundEnvelope(request, initialPayload, resolveClient = () => undefined) {
|
|
162
280
|
let payload = initialPayload;
|
|
163
281
|
return Object.freeze({
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { type ConversationContextBlock, type ConversationEventReader, type ConversationEventStore, type ConversationReference, type ConversationResolution, type ConversationRef, type DeliveryReceipt, type MessageRef, type SequencedConversationEvent, type Segment } from '@zhin.js/im-contract';
|
|
2
|
+
import type { Notice } from '../../notice.js';
|
|
3
|
+
import type { Request } from '../../request.js';
|
|
4
|
+
import type { IncomingMessage, MessageSenderRef, SendRequest } from './contracts.js';
|
|
5
|
+
/**
|
|
6
|
+
* Backlog messages older than this are dropped from the next turn's context:
|
|
7
|
+
* a stale command from hours ago is not something the current reply should answer.
|
|
8
|
+
*/
|
|
9
|
+
export declare const CONVERSATION_CONTEXT_MAX_AGE_MS: number;
|
|
10
|
+
/** Owns one ImRuntime's conversation fact store, projections, and consumer cursors. */
|
|
11
|
+
export declare class ConversationRuntime {
|
|
12
|
+
#private;
|
|
13
|
+
constructor(events?: ConversationEventStore);
|
|
14
|
+
get reader(): ConversationEventReader;
|
|
15
|
+
replaceStore(events: ConversationEventStore): void;
|
|
16
|
+
resolveLocal(reference: ConversationReference): Promise<ConversationResolution | undefined>;
|
|
17
|
+
readContext(conversation: ConversationRef, consumer: string, throughSequence: number, limit?: number, excludeMessageId?: string): Promise<Readonly<{
|
|
18
|
+
blocks: readonly ConversationContextBlock[];
|
|
19
|
+
cursor: number;
|
|
20
|
+
}>>;
|
|
21
|
+
/**
|
|
22
|
+
* An answer to an interaction prompt (an approval `y`, a menu choice) was
|
|
23
|
+
* already handled by that prompt; replaying it as background would invite
|
|
24
|
+
* the model to answer it again. Kept in memory and bounded: the context age
|
|
25
|
+
* window makes older answers irrelevant anyway.
|
|
26
|
+
*/
|
|
27
|
+
markInteractionAnswer(message: MessageRef): void;
|
|
28
|
+
commitContext(conversation: ConversationRef, consumer: string, cursor: number): Promise<void>;
|
|
29
|
+
recordIncoming(input: IncomingMessage, sender: MessageSenderRef | undefined): Promise<number | undefined>;
|
|
30
|
+
recordOutbound(request: SendRequest, receipt: DeliveryReceipt, canonicalContent?: readonly Segment[] | 'unavailable'): Promise<number | undefined>;
|
|
31
|
+
/** Records a confirmed replacement body without inventing another physical message. */
|
|
32
|
+
recordOutboundUpdate(request: SendRequest, receipt: DeliveryReceipt, revision: number, canonicalContent?: readonly Segment[] | 'unavailable'): Promise<number | undefined>;
|
|
33
|
+
/** Records a normalized notice; returns the stored event (with its sequence) when newly appended. */
|
|
34
|
+
recordNotice(notice: Notice): Promise<SequencedConversationEvent | undefined>;
|
|
35
|
+
/** Join requests / invitations into a group or channel become `scene.join_requested` (#996). */
|
|
36
|
+
recordRequest(request: Request): Promise<SequencedConversationEvent | undefined>;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Label of the bot's own messages. Outbound messages are recorded without an actor; without
|
|
40
|
+
* them the model cannot tell its own words from the members' or follow the order of the chat.
|
|
41
|
+
*/
|
|
42
|
+
export declare const OWN_MESSAGE_LABEL = "You (this bot)";
|