@zhin.js/core 1.1.38 → 1.1.40

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.
Files changed (52) hide show
  1. package/lib/built/ai-access.d.ts +2 -2
  2. package/lib/built/ai-access.js +4 -4
  3. package/lib/built/ai-outbound/types.d.ts +1 -1
  4. package/lib/built/ai-trigger.d.ts +1 -1
  5. package/lib/built/ai-trigger.js +17 -10
  6. package/lib/built/interactive-segments/action.d.ts +3 -3
  7. package/lib/built/interactive-segments/action.js +1 -1
  8. package/lib/built/message-enrich.d.ts +19 -22
  9. package/lib/built/message-enrich.js +47 -42
  10. package/lib/built/tool-access.d.ts +2 -2
  11. package/lib/built/tool-access.js +2 -2
  12. package/lib/im-scene.d.ts +4 -3
  13. package/lib/im-scene.js +9 -9
  14. package/lib/im-session-id.d.ts +20 -12
  15. package/lib/im-session-id.js +8 -8
  16. package/lib/index.d.ts +2 -1
  17. package/lib/index.js +1 -1
  18. package/lib/message.d.ts +1 -29
  19. package/lib/message.js +1 -27
  20. package/lib/notice.d.ts +34 -32
  21. package/lib/notice.js +21 -7
  22. package/lib/plugin-runtime/im/contracts.d.ts +23 -1
  23. package/lib/plugin-runtime/im/contracts.js +4 -1
  24. package/lib/plugin-runtime/im/conversation-runtime.js +22 -31
  25. package/lib/plugin-runtime/im/endpoint-runtime.d.ts +6 -1
  26. package/lib/plugin-runtime/im/endpoint-runtime.js +27 -5
  27. package/lib/plugin-runtime/im/inbound-runtime.d.ts +2 -2
  28. package/lib/plugin-runtime/im/inbound-runtime.js +58 -29
  29. package/lib/plugin-runtime/im/index.d.ts +3 -0
  30. package/lib/plugin-runtime/im/index.js +3 -0
  31. package/lib/plugin-runtime/im/message-dispatcher.js +28 -4
  32. package/lib/plugin-runtime/im/outbound-delivery-runtime.d.ts +1 -1
  33. package/lib/plugin-runtime/im/outbound-delivery-runtime.js +54 -12
  34. package/lib/plugin-runtime/im/outbound-renderer.js +1 -1
  35. package/lib/plugin-runtime/im/outbound-segments.d.ts +2 -0
  36. package/lib/plugin-runtime/im/outbound-segments.js +8 -0
  37. package/lib/plugin-runtime/im/public-api.d.ts +1 -1
  38. package/lib/plugin-runtime/im/runtime-middleware.js +1 -1
  39. package/lib/request.d.ts +27 -35
  40. package/lib/request.js +14 -6
  41. package/lib/side-event/base.d.ts +64 -43
  42. package/lib/side-event/base.js +66 -19
  43. package/lib/side-event/dispatch.js +40 -38
  44. package/lib/side-event/normalize.d.ts +9 -8
  45. package/lib/side-event/normalize.js +9 -8
  46. package/lib/side-event/types.d.ts +3 -6
  47. package/lib/side-event/types.js +0 -5
  48. package/lib/system-event.d.ts +17 -11
  49. package/lib/system-event.js +8 -6
  50. package/lib/types.d.ts +3 -2
  51. package/lib/utils.d.ts +1 -1
  52. package/package.json +10 -10
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * AI Access Gate — 控制 LLM 回复路径是否对当前会话开放(平台 AIGC 合规等)
3
3
  */
4
- import type { Message } from '../message.js';
4
+ import type { Message } from '../plugin-runtime/im/contracts.js';
5
5
  export type AIAccessMode = 'open' | 'closed' | 'whitelist';
6
6
  /** Endpoint 或全局 ai.access 配置块 */
7
7
  export interface AIAccessScopeConfig {
@@ -33,4 +33,4 @@ export declare function resolveAIAccessConfig(global: AIAccessConfig | undefined
33
33
  * 判定当前消息是否允许进入 AI Handler(LLM 回复路径)。
34
34
  * 不影响命令、游戏等其它 Dispatcher 分支。
35
35
  */
36
- export declare function checkAIAccess(message: Message<any>, globalConfig: AIAccessConfig | undefined, endpointScope?: AIAccessScopeConfig): AIAccessResult;
36
+ export declare function checkAIAccess(message: Message, globalConfig: AIAccessConfig | undefined, endpointScope?: AIAccessScopeConfig): AIAccessResult;
@@ -11,19 +11,19 @@ export function resolveAIAccessConfig(global, endpointScope) {
11
11
  };
12
12
  }
13
13
  function isWhitelisted(message, config) {
14
- const userId = String(message.$sender?.id ?? '');
14
+ const userId = String(message.sender?.id ?? '');
15
15
  if (userId && config.users.includes(userId))
16
16
  return true;
17
- const scope = message.$channel?.type;
17
+ const scope = message.conversation.kind;
18
18
  if (scope === 'group' || scope === 'channel') {
19
- const channelId = String(message.$channel?.id ?? '');
19
+ const channelId = String(message.conversation.id ?? '');
20
20
  if (channelId && config.groups.includes(channelId))
21
21
  return true;
22
22
  }
23
23
  return false;
24
24
  }
25
25
  function denyResult(message, config, reason) {
26
- const scope = message.$channel?.type;
26
+ const scope = message.conversation.kind;
27
27
  const replyMessage = scope === 'private' ? config.denyMessage : undefined;
28
28
  return { allowed: false, reason, replyMessage };
29
29
  }
@@ -1,4 +1,4 @@
1
- import type { Message } from '../../message.js';
1
+ import type { Message } from '../../plugin-runtime/im/contracts.js';
2
2
  import type { MessageElement } from '../../types.js';
3
3
  import type { InteractivePolicy } from '../interactive-segments/types.js';
4
4
  import type { Segment } from '../segment-contract/types.js';
@@ -8,7 +8,7 @@
8
8
  * 3. 私聊直接对话 - 私聊时直接对话
9
9
  * 4. 关键词触发 - 非群/频道场景下匹配关键词时触发
10
10
  */
11
- import { Message } from "../message.js";
11
+ import type { Message } from "../plugin-runtime/im/contracts.js";
12
12
  import type { MessageElement, ToolScope } from "../types.js";
13
13
  import { type SenderRole } from './roles.js';
14
14
  /**
@@ -34,6 +34,11 @@ function normalizeAtIds(endpointAtIds) {
34
34
  const ids = endpointAtIds?.length ? endpointAtIds : [];
35
35
  return [...new Set(ids.map((id) => String(id)).filter(Boolean))];
36
36
  }
37
+ function messageElements(message) {
38
+ if (message.segments?.length)
39
+ return [...message.segments];
40
+ return message.content ? [{ type: 'text', data: { text: message.content } }] : [];
41
+ }
37
42
  function segmentAtUserId(seg) {
38
43
  return readMentionSegmentTarget(seg);
39
44
  }
@@ -63,7 +68,9 @@ function stripTextAtEndpoint(text, endpointKeys) {
63
68
  * 收集用于 @ 匹配的 Endpoint 标识符
64
69
  */
65
70
  export function collectEndpointAtIds(message, extraIds) {
66
- const ids = new Set([String(message.$endpoint)]);
71
+ const ids = new Set([
72
+ String(message.endpointId ?? message.conversation.endpoint.id),
73
+ ]);
67
74
  for (const id of extraIds ?? []) {
68
75
  if (id)
69
76
  ids.add(String(id));
@@ -75,10 +82,10 @@ export function collectEndpointAtIds(message, extraIds) {
75
82
  */
76
83
  export function isAtEndpoint(message, endpointAtIds) {
77
84
  const endpointKeys = normalizeAtIds(endpointAtIds?.length ? endpointAtIds : collectEndpointAtIds(message));
78
- if (message.$content.some((seg) => isAtSegmentForEndpoint(seg, endpointKeys))) {
85
+ if (messageElements(message).some((seg) => isAtSegmentForEndpoint(seg, endpointKeys))) {
79
86
  return true;
80
87
  }
81
- for (const seg of message.$content) {
88
+ for (const seg of messageElements(message)) {
82
89
  if (seg.type === 'text' && seg.data?.text && textMentionsEndpoint(seg.data.text, endpointKeys)) {
83
90
  return true;
84
91
  }
@@ -90,7 +97,7 @@ export function isAtEndpoint(message, endpointAtIds) {
90
97
  * 使用 segment.toString 将 MessageElement 转为 XML 格式
91
98
  */
92
99
  export function extractTextContent(message) {
93
- return segment.toString(message.$content);
100
+ return message.segments?.length ? segment.toString(messageElements(message)) : message.content;
94
101
  }
95
102
  /**
96
103
  * 解析 AI 回复中的富媒体内容
@@ -116,7 +123,7 @@ export function parseRichMediaContent(content) {
116
123
  */
117
124
  export function removeAtEndpoint(message, endpointAtIds) {
118
125
  const endpointKeys = normalizeAtIds(endpointAtIds?.length ? endpointAtIds : collectEndpointAtIds(message));
119
- return message.$content
126
+ return messageElements(message)
120
127
  .filter((seg) => !isAtSegmentForEndpoint(seg, endpointKeys))
121
128
  .map((seg) => {
122
129
  if (seg.type !== 'text' || !seg.data?.text)
@@ -145,15 +152,15 @@ function collectEndpointTrustedIds(endpointConfig) {
145
152
  * 解析发送者角色集合(IM 群角色 + trigger + endpoints[].$config)
146
153
  */
147
154
  export function resolveSenderRoles(message, config, endpointConfig) {
148
- const scope = message.$channel?.type || 'private';
155
+ const scope = message.conversation.kind;
149
156
  // process 适配器(stdin/本机 CLI):操作者即宿主用户,恒为 master
150
- if (message.$adapter === 'process') {
157
+ if ((message.clientAdapter ?? message.conversation.endpoint.adapter) === 'process') {
151
158
  return {
152
159
  scope,
153
160
  roles: normalizeSenderRoles(['master']),
154
161
  };
155
162
  }
156
- const senderId = String(message.$sender.id);
163
+ const senderId = String(message.sender?.id ?? '');
157
164
  const roles = [];
158
165
  const masters = config.masters || [];
159
166
  const globalTrusted = config.trusted || [];
@@ -181,7 +188,7 @@ export function shouldTriggerAI(message, config, options) {
181
188
  return { triggered: false, content: '' };
182
189
  }
183
190
  const text = extractTextContent(message);
184
- const scope = message.$channel?.type || 'private';
191
+ const scope = message.conversation.kind;
185
192
  const isSharedSession = scope === 'group' || scope === 'channel';
186
193
  // 检查忽略前缀
187
194
  for (const prefix of fullConfig.ignorePrefixes) {
@@ -207,7 +214,7 @@ export function shouldTriggerAI(message, config, options) {
207
214
  };
208
215
  }
209
216
  // 3. 检查私聊触发
210
- if (fullConfig.respondToPrivate && message.$channel?.type === 'private') {
217
+ if (fullConfig.respondToPrivate && message.conversation.kind === 'private') {
211
218
  if (text.trim()) {
212
219
  return { triggered: true, content: text.trim() };
213
220
  }
@@ -1,10 +1,10 @@
1
- import type { Message } from '../../message.js';
1
+ import type { Message } from '../../plugin-runtime/im/contracts.js';
2
2
  import type { MessageElement } from '../../types.js';
3
3
  import { type ActionSegmentData } from './types.js';
4
4
  export declare function actionSegment(data: ActionSegmentData): MessageElement;
5
- export declare function getActionFromMessage(message: Message<any>): ActionSegmentData | undefined;
5
+ export declare function getActionFromMessage(message: Message): ActionSegmentData | undefined;
6
6
  /** 入站互动 action(按钮点击等),不应计入用户发言/消息统计 */
7
- export declare function isActionMessage(message: Message<any>): boolean;
7
+ export declare function isActionMessage(message: Message): boolean;
8
8
  /** 去掉 @bot、XML at 段、首尾空白(QQ 指令预填文本归一化) */
9
9
  export declare function stripInteractiveCommandText(raw: string): string;
10
10
  /** 从文本降级输入解析 payload(需在 active session 的 fallback.map 中查找) */
@@ -3,7 +3,7 @@ export function actionSegment(data) {
3
3
  return { type: ACTION_SEGMENT_TYPE, data };
4
4
  }
5
5
  export function getActionFromMessage(message) {
6
- for (const item of message.$content ?? []) {
6
+ for (const item of message.segments ?? []) {
7
7
  if (typeof item === 'string')
8
8
  continue;
9
9
  if (isActionSegment(item))
@@ -1,32 +1,29 @@
1
1
  /**
2
- * Message enrich — 入站鉴权快照与合成通讯上下文
2
+ * Message enrich — inbound authorization snapshots and synthetic communication context.
3
3
  */
4
- import { Message, type MessageChannel } from '../message.js';
5
- import type { SendContent } from '../types.js';
4
+ import type { ConversationRef, DeliveryReceipt } from '@zhin.js/im-contract';
5
+ import type { Message, MessageSenderRef, Segment, SendContent } from '../plugin-runtime/im/contracts.js';
6
6
  import type { SenderRole } from './roles.js';
7
- /** Agent turn 可挂载在 Message 扩展字段上的元数据 */
7
+ /** Agent turns may attach host-owned metadata to the canonical runtime message. */
8
8
  export type AgentTurnMessage = Message<{
9
9
  extra?: Record<string, unknown>;
10
10
  }>;
11
- export declare function senderRolesFromMessage(message: Message<any>): readonly SenderRole[];
11
+ export declare function senderRolesFromMessage(message: Message): readonly SenderRole[];
12
12
  export interface SyntheticMessageInput {
13
- adapter: string;
14
- endpoint: string;
15
- sender: {
16
- id: string;
17
- name?: string;
18
- role?: string;
19
- isMaster?: boolean;
20
- isTrusted?: boolean;
21
- };
22
- channel: MessageChannel;
23
- id?: string;
24
- reply?: (content: SendContent, quote?: boolean | string) => Promise<string>;
13
+ conversation: ConversationRef;
14
+ sender?: MessageSenderRef;
15
+ content?: string;
16
+ segments?: readonly Segment[];
17
+ messageId?: string;
18
+ generation?: number;
19
+ endpointId?: string;
20
+ clientAdapter?: string;
21
+ reply?: (content: SendContent) => Promise<DeliveryReceipt>;
25
22
  extra?: Record<string, unknown>;
26
23
  }
27
- /** cron / subagent / mission 等无真实入站时构造最小 Message */
24
+ /** Construct a canonical Message for cron, subagent, and mission turns without live ingress. */
28
25
  export declare function createSyntheticMessage(input: SyntheticMessageInput): AgentTurnMessage;
29
- /** hook context 中的 commMessage 字段(AIHookEvent.context) */
30
- export declare function commMessageFromHookContext(context: Record<string, unknown>): Message<any> | undefined;
31
- /** 兼容 tool parameters 上的 contextKey(endpointKey / sceneId / scope 等) */
32
- export declare function resolveContextKey(message: Message<any>, key: string): unknown;
26
+ /** Read a canonical communication message from an AI hook context. */
27
+ export declare function commMessageFromHookContext(context: Record<string, unknown>): Message | undefined;
28
+ /** Resolve tool context injection keys from the canonical Message contract. */
29
+ export declare function resolveContextKey(message: Message, key: string): unknown;
@@ -1,67 +1,72 @@
1
- /**
2
- * Message enrich — 入站鉴权快照与合成通讯上下文
3
- */
4
- import { Message } from '../message.js';
5
- function frameworkRolesFromSenderFlags(sender) {
6
- if (sender.isMaster)
7
- return ['master'];
8
- if (sender.isTrusted)
9
- return ['trusted'];
10
- return ['user'];
11
- }
1
+ import { segmentsToPlainText } from './segment-contract/text.js';
12
2
  export function senderRolesFromMessage(message) {
13
- const sender = message.$sender;
14
- if (sender.isMaster !== undefined || sender.isTrusted !== undefined) {
15
- return frameworkRolesFromSenderFlags(sender);
16
- }
17
- return ['user'];
3
+ const roles = message.sender?.roles?.filter((role) => role === 'master' || role === 'trusted' || role === 'user');
4
+ return roles?.length ? roles : ['user'];
18
5
  }
19
- /** cron / subagent / mission 等无真实入站时构造最小 Message */
6
+ /** Construct a canonical Message for cron, subagent, and mission turns without live ingress. */
20
7
  export function createSyntheticMessage(input) {
21
- const id = input.id ?? `synthetic:${Date.now()}`;
22
- const reply = input.reply ?? (async () => id);
23
- return Message.from({ extra: input.extra }, {
24
- $id: id,
25
- $adapter: input.adapter,
26
- $endpoint: input.endpoint,
27
- $content: [],
28
- $sender: { ...input.sender },
8
+ const messageId = input.messageId ?? `synthetic:${Date.now()}`;
9
+ const unsupportedReply = async () => Object.freeze({
10
+ status: 'unsupported',
11
+ failure: Object.freeze({
12
+ code: 'synthetic_reply_unavailable',
13
+ message: 'Synthetic Message has no outbound delivery port',
14
+ retryable: false,
15
+ }),
16
+ });
17
+ const reply = input.reply ?? unsupportedReply;
18
+ const segments = input.segments ? Object.freeze([...input.segments]) : undefined;
19
+ const content = segments ? segmentsToPlainText(segments) : (input.content ?? '');
20
+ return Object.freeze({
21
+ conversation: input.conversation,
22
+ content,
23
+ generation: input.generation ?? 0,
24
+ metadata: Object.freeze({}),
25
+ segments,
26
+ sender: input.sender,
27
+ message: Object.freeze({ conversation: input.conversation, id: messageId }),
28
+ endpointId: input.endpointId,
29
+ clientAdapter: input.clientAdapter,
30
+ id: messageId,
31
+ extra: input.extra,
32
+ get $client() {
33
+ throw new Error('Synthetic Message has no Endpoint Client context');
34
+ },
29
35
  $reply: reply,
30
- $recall: async () => { },
31
- $channel: input.channel,
32
- $timestamp: Date.now(),
33
- $raw: '',
36
+ $replyFrom: () => unsupportedReply(),
37
+ $sendTo: () => unsupportedReply(),
38
+ $replyToPrivate: () => unsupportedReply(),
39
+ $replyToGroup: () => unsupportedReply(),
40
+ $replyToChannel: () => unsupportedReply(),
34
41
  });
35
42
  }
36
- /** hook context 中的 commMessage 字段(AIHookEvent.context) */
43
+ /** Read a canonical communication message from an AI hook context. */
37
44
  export function commMessageFromHookContext(context) {
38
45
  const raw = context.commMessage;
39
- if (raw && typeof raw === 'object' && '$sender' in raw) {
46
+ if (raw && typeof raw === 'object' && 'conversation' in raw && 'content' in raw) {
40
47
  return raw;
41
48
  }
42
49
  return undefined;
43
50
  }
44
- /** 兼容 tool parameters 上的 contextKey(endpointKey / sceneId / scope 等) */
51
+ /** Resolve tool context injection keys from the canonical Message contract. */
45
52
  export function resolveContextKey(message, key) {
46
53
  switch (key) {
47
54
  case 'platform':
48
- return message.$adapter;
55
+ return message.clientAdapter ?? message.conversation.endpoint.adapter;
49
56
  case 'endpointKey':
50
- return message.$endpoint;
57
+ return message.endpointId ?? message.conversation.endpoint.id;
51
58
  case 'messageId':
52
- return message.$id;
59
+ return message.id;
53
60
  case 'sceneId':
54
- return message.$channel?.id ?? message.$sender.id;
61
+ return message.conversation.id ?? message.sender?.id;
55
62
  case 'senderId':
56
- return message.$sender.id;
63
+ return message.sender?.id;
57
64
  case 'scope':
58
- return message.$channel?.type ?? 'private';
65
+ return message.conversation.kind;
59
66
  default: {
60
- if (key in message) {
67
+ if (key in message)
61
68
  return message[key];
62
- }
63
- const extra = message.extra;
64
- return extra?.[key];
69
+ return message.extra?.[key];
65
70
  }
66
71
  }
67
72
  }
@@ -1,5 +1,5 @@
1
1
  import { type PermissionHost } from '@zhin.js/permission';
2
- import type { Message } from '../message.js';
2
+ import type { Message } from '../plugin-runtime/im/contracts.js';
3
3
  import type { Tool } from '../types.js';
4
4
  /** Checks whether a Tool is visible to the current IM message context. */
5
- export declare function canAccessTool(tool: Tool, message?: Message<any>, host?: PermissionHost | null): Promise<boolean>;
5
+ export declare function canAccessTool(tool: Tool, message?: Message, host?: PermissionHost | null): Promise<boolean>;
@@ -3,8 +3,8 @@ import { toPermissionSubject } from '@zhin.js/permission';
3
3
  export async function canAccessTool(tool, message, host) {
4
4
  if (!message)
5
5
  return !tool.platforms?.length && !tool.scopes?.length && !tool.permissions?.length;
6
- const adapter = String(message.$adapter);
7
- const scope = (message.$channel?.type || 'private');
6
+ const adapter = String(message.clientAdapter ?? message.conversation.endpoint.adapter);
7
+ const scope = message.conversation.kind;
8
8
  if (tool.platforms?.length && !tool.platforms.includes(adapter))
9
9
  return false;
10
10
  if (tool.scopes?.length && !tool.scopes.includes(scope))
package/lib/im-scene.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- import type { Message, MessageType } from './message.js';
1
+ import type { MessageType } from './message.js';
2
+ import type { Message } from './plugin-runtime/im/contracts.js';
2
3
  import type { SendContent, SendOptions } from './types.js';
3
4
  export type IMSceneKind = MessageType;
4
5
  /** Parent scene kind (distinct from sub-channel MessageType.channel). */
@@ -23,7 +24,7 @@ export interface IMDeliveryTarget {
23
24
  }
24
25
  /** Normalize legacy parent.type channel → guild. */
25
26
  export declare function normalizeIMSceneParentKind(value: unknown): IMSceneParentKind | undefined;
26
- export declare function sceneRefFromMessage(message: Partial<Message<any>>): IMSceneRef | undefined;
27
+ export declare function sceneRefFromMessage(message: Partial<Message>): IMSceneRef | undefined;
27
28
  export declare function sceneRefToSendOptions(target: IMDeliveryTarget, content: SendContent): SendOptions;
28
29
  export declare function resolveIMSceneSessionId(scene: IMSceneRef): string;
29
- export declare function messageToIMDeliveryTarget(message: Partial<Message<any>>): IMDeliveryTarget | undefined;
30
+ export declare function messageToIMDeliveryTarget(message: Partial<Message>): IMDeliveryTarget | undefined;
package/lib/im-scene.js CHANGED
@@ -11,25 +11,25 @@ export function normalizeIMSceneParentKind(value) {
11
11
  return undefined;
12
12
  }
13
13
  export function sceneRefFromMessage(message) {
14
- const platform = nonEmptyString(message.$adapter);
15
- const endpointKey = nonEmptyString(message.$endpoint);
16
- const kind = message.$channel?.type;
14
+ const platform = nonEmptyString(message.clientAdapter ?? message.conversation?.endpoint.adapter);
15
+ const endpointKey = nonEmptyString(message.endpointId ?? message.conversation?.endpoint.id);
16
+ const kind = message.conversation?.kind;
17
17
  if (!platform || !endpointKey || !kind)
18
18
  return undefined;
19
- const senderId = nonEmptyString(message.$sender?.id);
20
- const channelId = nonEmptyString(message.$channel?.id);
19
+ const senderId = nonEmptyString(message.sender?.id);
20
+ const channelId = nonEmptyString(message.conversation?.id);
21
21
  const sceneId = kind === 'private'
22
22
  ? senderId ?? channelId
23
23
  : channelId ?? senderId;
24
24
  if (!sceneId)
25
25
  return undefined;
26
- const parentKind = message.$channel?.parent
27
- ? normalizeIMSceneParentKind(message.$channel.parent.type)
26
+ const parentKind = message.conversation?.parent
27
+ ? normalizeIMSceneParentKind(message.conversation.parent.kind)
28
28
  : undefined;
29
- const parent = parentKind && message.$channel?.parent
29
+ const parent = parentKind && message.conversation?.parent
30
30
  ? {
31
31
  kind: parentKind,
32
- sceneId: String(message.$channel.parent.id),
32
+ sceneId: String(message.conversation.parent.id),
33
33
  }
34
34
  : undefined;
35
35
  return {
@@ -10,25 +10,33 @@ export declare function resolveIMSessionId(input: ResolveIMSessionIdInput): stri
10
10
  export declare function resolveIMSessionIdFromScene(scene: IMSceneRef): string;
11
11
  export declare function resolveIMSceneIdForSession(kind: IMSceneKind, sceneId?: string, senderId?: string): string;
12
12
  export declare function resolveIMSessionIdFromMessage(message: {
13
- $adapter?: string;
14
- $endpoint?: string;
15
- $channel?: {
16
- type?: IMSceneKind;
17
- id?: string;
13
+ clientAdapter?: string;
14
+ endpointId?: string;
15
+ conversation?: {
16
+ endpoint: {
17
+ adapter: string;
18
+ id: string;
19
+ };
20
+ kind: IMSceneKind;
21
+ id: string;
18
22
  };
19
- $sender?: {
23
+ sender?: {
20
24
  id?: string;
21
25
  };
22
26
  }): string;
23
27
  /** Canonical scene fields for transcript / session persistence (ADR 0028 SSOT). */
24
28
  export declare function resolveSceneFieldsFromMessage(message: {
25
- $adapter?: string;
26
- $endpoint?: string;
27
- $channel?: {
28
- type?: IMSceneKind;
29
- id?: string;
29
+ clientAdapter?: string;
30
+ endpointId?: string;
31
+ conversation?: {
32
+ endpoint: {
33
+ adapter: string;
34
+ id: string;
35
+ };
36
+ kind: IMSceneKind;
37
+ id: string;
30
38
  };
31
- $sender?: {
39
+ sender?: {
32
40
  id?: string;
33
41
  };
34
42
  }): {
@@ -18,12 +18,12 @@ export function resolveIMSessionIdFromMessage(message) {
18
18
  const scene = sceneRefFromMessage(message);
19
19
  if (scene)
20
20
  return resolveIMSceneSessionId(scene);
21
- const kind = (message.$channel?.type || 'private');
21
+ const kind = (message.conversation?.kind || 'private');
22
22
  return resolveIMSessionId({
23
- platform: String(message.$adapter || ''),
24
- endpointKey: String(message.$endpoint || ''),
23
+ platform: String(message.clientAdapter || message.conversation?.endpoint.adapter || ''),
24
+ endpointKey: String(message.endpointId || message.conversation?.endpoint.id || ''),
25
25
  kind,
26
- sceneId: resolveIMSceneIdForSession(kind, message.$channel?.id, message.$sender?.id),
26
+ sceneId: resolveIMSceneIdForSession(kind, message.conversation?.id, message.sender?.id),
27
27
  });
28
28
  }
29
29
  /** Canonical scene fields for transcript / session persistence (ADR 0028 SSOT). */
@@ -37,11 +37,11 @@ export function resolveSceneFieldsFromMessage(message) {
37
37
  sceneType: scene.kind,
38
38
  };
39
39
  }
40
- const sceneType = (message.$channel?.type || 'private');
40
+ const sceneType = (message.conversation?.kind || 'private');
41
41
  return {
42
- platform: String(message.$adapter || ''),
43
- endpointKey: String(message.$endpoint || ''),
42
+ platform: String(message.clientAdapter || message.conversation?.endpoint.adapter || ''),
43
+ endpointKey: String(message.endpointId || message.conversation?.endpoint.id || ''),
44
44
  sceneType,
45
- sceneId: resolveIMSceneIdForSession(sceneType, message.$channel?.id, message.$sender?.id),
45
+ sceneId: resolveIMSceneIdForSession(sceneType, message.conversation?.id, message.sender?.id),
46
46
  };
47
47
  }
package/lib/index.d.ts CHANGED
@@ -3,7 +3,8 @@
3
3
  * @module @zhin.js/core
4
4
  */
5
5
  export * from './component.js';
6
- export * from './message.js';
6
+ export type { MessageChannel, MessageComponent, MessageType } from './message.js';
7
+ export { Message, type MessageBase } from './plugin-runtime/im/contracts.js';
7
8
  export * from './im-scene.js';
8
9
  export * from './notice.js';
9
10
  export * from './request.js';
package/lib/index.js CHANGED
@@ -3,7 +3,7 @@
3
3
  * @module @zhin.js/core
4
4
  */
5
5
  export * from './component.js';
6
- export * from './message.js';
6
+ export { Message } from './plugin-runtime/im/contracts.js';
7
7
  export * from './im-scene.js';
8
8
  export * from './notice.js';
9
9
  export * from './request.js';
package/lib/message.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { MessageElement, MessageSender, SendContent } from "./types.js";
1
+ import type { SendContent } from "./types.js";
2
2
  import { Component } from "./component.js";
3
3
  /**
4
4
  * 消息组件类型:用于自定义消息结构
@@ -29,31 +29,3 @@ export interface MessageChannel {
29
29
  * 消息类型枚举
30
30
  */
31
31
  export type MessageType = 'group' | 'private' | 'channel';
32
- /**
33
- * 消息基础结构
34
- */
35
- export interface MessageBase {
36
- $id: string;
37
- $adapter: string;
38
- $endpoint: string;
39
- $content: MessageElement[];
40
- $sender: MessageSender;
41
- $reply?(content: SendContent, quote?: boolean | string): Promise<string>;
42
- $recall?(): Promise<void>;
43
- $channel: MessageChannel;
44
- $timestamp: number;
45
- $raw: string;
46
- }
47
- /**
48
- * 完整消息类型,支持扩展
49
- */
50
- export type Message<T extends object = {}> = MessageBase & T;
51
- /** @internal Legacy static helpers; not part of Agent resource authoring. */
52
- export declare namespace Message {
53
- /**
54
- * 工具方法:合并自定义字段与基础消息结构
55
- */
56
- function from<T extends object>(input: T, format: MessageBase): Message<T>;
57
- function actionPayload(message: Message<any>): string | undefined;
58
- function isAction(message: Message<any>): boolean;
59
- }
package/lib/message.js CHANGED
@@ -1,27 +1 @@
1
- import { isActionMessage as isActionMessageImpl } from "./built/interactive-segments/action.js";
2
- /** @internal Legacy static helpers; not part of Agent resource authoring. */
3
- export var Message;
4
- (function (Message) {
5
- /**
6
- * 工具方法:合并自定义字段与基础消息结构
7
- */
8
- function from(input, format) {
9
- return Object.assign({}, input, format);
10
- }
11
- Message.from = from;
12
- function actionPayload(message) {
13
- for (const item of message.$content ?? []) {
14
- if (typeof item === 'string')
15
- continue;
16
- if (item.type === 'action' && item.data?.payload) {
17
- return String(item.data.payload);
18
- }
19
- }
20
- return undefined;
21
- }
22
- Message.actionPayload = actionPayload;
23
- function isAction(message) {
24
- return isActionMessageImpl(message);
25
- }
26
- Message.isAction = isAction;
27
- })(Message || (Message = {}));
1
+ export {};