@zhin.js/core 1.5.6 → 1.5.7
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.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Scope, type PluginId, type SnapshotLease, type SnapshotStore } from '@zhin.js/plugin-runtime';
|
|
1
|
+
import { Scope, type PluginId, type RuntimeSnapshot, type SnapshotLease, type SnapshotStore } from '@zhin.js/plugin-runtime';
|
|
2
2
|
import { MessageBus } from './message-bus.js';
|
|
3
3
|
import { type EndpointManagement, type EndpointManagementCapability } from '@zhin.js/adapter';
|
|
4
4
|
import { type ConversationRef, type DeliveryReceipt, type MessageRef } from '@zhin.js/im-contract';
|
|
@@ -34,6 +34,13 @@ export interface ImRuntimeOptions {
|
|
|
34
34
|
readonly renderer?: OutboundRenderer;
|
|
35
35
|
/** Process-root ingress claim (pending interaction, authentication challenge, etc.). */
|
|
36
36
|
readonly inboundClaim?: (message: Message) => boolean | Promise<boolean>;
|
|
37
|
+
/**
|
|
38
|
+
* 入站 sender 增强:在构造 Message 前,将框架级角色(master / trusted)
|
|
39
|
+
* 合并到 sender.roles,使整个下游链路(命令分发、agent ingress 等)都能读到完整角色。
|
|
40
|
+
*
|
|
41
|
+
* 返回增强后的 sender(可原样返回)。缺省时 sender 保留适配器给出的平台角色。
|
|
42
|
+
*/
|
|
43
|
+
readonly enrichSender?: (sender: MessageSenderRef | undefined, conversation: IncomingMessage['conversation'], snapshot: RuntimeSnapshot) => MessageSenderRef | undefined;
|
|
37
44
|
}
|
|
38
45
|
export declare class ImRuntime implements MessageGateway {
|
|
39
46
|
#private;
|
|
@@ -23,12 +23,14 @@ export class ImRuntime {
|
|
|
23
23
|
#interactiveHandlers = [];
|
|
24
24
|
#snapshots;
|
|
25
25
|
#inboundClaim;
|
|
26
|
+
#enrichSender;
|
|
26
27
|
constructor(options = {}) {
|
|
27
28
|
this.#dispatcher = new MessageDispatcher(options.commandPrefix === undefined
|
|
28
29
|
? defaultCommandPrefixResolver
|
|
29
30
|
: () => options.commandPrefix ?? '');
|
|
30
31
|
this.#renderer = options.renderer ?? new OutboundRenderer();
|
|
31
32
|
this.#inboundClaim = options.inboundClaim;
|
|
33
|
+
this.#enrichSender = options.enrichSender;
|
|
32
34
|
}
|
|
33
35
|
attach(snapshots) {
|
|
34
36
|
if (this.#snapshots && this.#snapshots !== snapshots) {
|
|
@@ -87,6 +89,9 @@ export class ImRuntime {
|
|
|
87
89
|
sender: `${input.sender?.name || 'undefined'}(${input.sender?.id || 'undefined'})`,
|
|
88
90
|
preview: truncatePreview(input.content),
|
|
89
91
|
}));
|
|
92
|
+
const enrichedSender = this.#enrichSender
|
|
93
|
+
? this.#enrichSender(input.sender, conversation, lease.value)
|
|
94
|
+
: input.sender;
|
|
90
95
|
const message = new Message(conversation, input.content, lease.value.generation, (content, replyRequester = requester, targetConversation) => {
|
|
91
96
|
if (!active)
|
|
92
97
|
throw new Error('Message reply scope has ended');
|
|
@@ -98,7 +103,7 @@ export class ImRuntime {
|
|
|
98
103
|
requester: replyRequester,
|
|
99
104
|
content,
|
|
100
105
|
incoming: {
|
|
101
|
-
sender:
|
|
106
|
+
sender: enrichedSender,
|
|
102
107
|
content: input.content,
|
|
103
108
|
segments: input.segments,
|
|
104
109
|
messageId: input.message?.id,
|
|
@@ -107,7 +112,7 @@ export class ImRuntime {
|
|
|
107
112
|
mentioned: input.mentioned,
|
|
108
113
|
},
|
|
109
114
|
}, lease.value);
|
|
110
|
-
},
|
|
115
|
+
}, enrichedSender, Object.freeze({ ...input.metadata }), input.segments ? Object.freeze([...input.segments]) : undefined, input.message, input.endpointId, input.mentioned, input.replyTo);
|
|
111
116
|
let result = Object.freeze({ matched: false });
|
|
112
117
|
const claimed = await this.#inboundClaim?.(message) === true;
|
|
113
118
|
if (claimed) {
|