@zhin.js/core 1.1.35 → 1.1.37

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 (189) hide show
  1. package/README.md +79 -193
  2. package/lib/built/ai-outbound/index.d.ts +0 -1
  3. package/lib/built/ai-outbound/index.js +0 -1
  4. package/lib/built/ai-outbound/types.d.ts +0 -9
  5. package/lib/built/ai-trigger.d.ts +0 -5
  6. package/lib/built/ai-trigger.js +1 -27
  7. package/lib/built/common-adapter-tools.d.ts +0 -2
  8. package/lib/built/common-adapter-tools.js +0 -4
  9. package/lib/built/html-segment-fallback.d.ts +2 -5
  10. package/lib/built/html-segment-fallback.js +0 -15
  11. package/lib/built/interactive-segments/index.d.ts +0 -2
  12. package/lib/built/interactive-segments/index.js +0 -2
  13. package/lib/built/interactive-segments/keyboard-segment.d.ts +0 -1
  14. package/lib/built/interactive-segments/keyboard-segment.js +0 -1
  15. package/lib/built/interactive-segments/onebot-keyboard.d.ts +0 -1
  16. package/lib/built/interactive-segments/onebot-keyboard.js +0 -2
  17. package/lib/built/interactive-segments/resolve.d.ts +0 -1
  18. package/lib/built/interactive-segments/resolve.js +0 -1
  19. package/lib/built/interactive-segments/types.d.ts +0 -5
  20. package/lib/built/login-assist.d.ts +1 -8
  21. package/lib/built/message-enrich.d.ts +2 -8
  22. package/lib/built/message-enrich.js +3 -11
  23. package/lib/built/segment-contract/validate.d.ts +2 -2
  24. package/lib/built/segment-contract/validate.js +1 -3
  25. package/lib/built/tool-access.d.ts +5 -0
  26. package/lib/built/tool-access.js +17 -0
  27. package/lib/built/user-interaction.js +0 -4
  28. package/lib/feature/handler.d.ts +1 -5
  29. package/lib/index.d.ts +4 -45
  30. package/lib/index.js +3 -39
  31. package/lib/message.d.ts +1 -2
  32. package/lib/models/system-log.d.ts +0 -2
  33. package/lib/models/system-log.js +1 -8
  34. package/lib/models/user.d.ts +0 -2
  35. package/lib/models/user.js +1 -7
  36. package/lib/notice.d.ts +1 -2
  37. package/lib/plugin-runtime/im/conversation-runtime.d.ts +19 -0
  38. package/lib/plugin-runtime/im/conversation-runtime.js +312 -0
  39. package/lib/plugin-runtime/im/endpoint-runtime.d.ts +79 -0
  40. package/lib/plugin-runtime/im/endpoint-runtime.js +162 -0
  41. package/lib/plugin-runtime/im/im-runtime.d.ts +13 -106
  42. package/lib/plugin-runtime/im/im-runtime.js +58 -1061
  43. package/lib/plugin-runtime/im/inbound-runtime.d.ts +31 -0
  44. package/lib/plugin-runtime/im/inbound-runtime.js +252 -0
  45. package/lib/plugin-runtime/im/index.d.ts +4 -2
  46. package/lib/plugin-runtime/im/index.js +2 -2
  47. package/lib/plugin-runtime/im/ingress-route.d.ts +10 -0
  48. package/lib/plugin-runtime/im/ingress-route.js +10 -0
  49. package/lib/plugin-runtime/im/interaction-runtime.d.ts +23 -0
  50. package/lib/plugin-runtime/im/interaction-runtime.js +181 -0
  51. package/lib/plugin-runtime/im/interactive-router.d.ts +17 -0
  52. package/lib/plugin-runtime/im/interactive-router.js +98 -0
  53. package/lib/plugin-runtime/im/message-bus.d.ts +3 -3
  54. package/lib/plugin-runtime/im/message-bus.js +3 -3
  55. package/lib/plugin-runtime/im/message-events.d.ts +26 -0
  56. package/lib/plugin-runtime/im/message-events.js +61 -0
  57. package/lib/plugin-runtime/im/outbound-delivery-runtime.d.ts +19 -0
  58. package/lib/plugin-runtime/im/outbound-delivery-runtime.js +165 -0
  59. package/lib/plugin-runtime/im/outbound-segments.d.ts +2 -3
  60. package/lib/plugin-runtime/im/outbound-segments.js +3 -4
  61. package/lib/plugin-runtime/im/runtime-middleware.d.ts +3 -0
  62. package/lib/plugin-runtime/im/runtime-middleware.js +13 -0
  63. package/lib/request.d.ts +1 -2
  64. package/lib/side-event/base.d.ts +1 -2
  65. package/lib/side-event/normalize.d.ts +1 -5
  66. package/lib/side-event/normalize.js +1 -11
  67. package/lib/system-event.d.ts +1 -2
  68. package/lib/types.d.ts +9 -116
  69. package/lib/utils.d.ts +51 -24
  70. package/lib/utils.js +11 -23
  71. package/package.json +18 -28
  72. package/lib/adapter.d.ts +0 -145
  73. package/lib/adapter.js +0 -377
  74. package/lib/built/adapter-process.d.ts +0 -58
  75. package/lib/built/adapter-process.js +0 -128
  76. package/lib/built/agent-preset.d.ts +0 -64
  77. package/lib/built/agent-preset.js +0 -79
  78. package/lib/built/ai-outbound/adapter-access.d.ts +0 -3
  79. package/lib/built/ai-outbound/adapter-access.js +0 -9
  80. package/lib/built/authorization.d.ts +0 -10
  81. package/lib/built/authorization.js +0 -76
  82. package/lib/built/command.d.ts +0 -72
  83. package/lib/built/command.js +0 -105
  84. package/lib/built/component.d.ts +0 -67
  85. package/lib/built/component.js +0 -97
  86. package/lib/built/config.d.ts +0 -98
  87. package/lib/built/config.js +0 -372
  88. package/lib/built/connect-endpoint-instance.d.ts +0 -17
  89. package/lib/built/connect-endpoint-instance.js +0 -42
  90. package/lib/built/database.d.ts +0 -68
  91. package/lib/built/database.js +0 -106
  92. package/lib/built/dispatcher.d.ts +0 -141
  93. package/lib/built/dispatcher.js +0 -383
  94. package/lib/built/endpoint-commands.d.ts +0 -3
  95. package/lib/built/endpoint-commands.js +0 -99
  96. package/lib/built/endpoint-lifecycle-service.d.ts +0 -28
  97. package/lib/built/endpoint-lifecycle-service.js +0 -242
  98. package/lib/built/endpoint-lifecycle.d.ts +0 -27
  99. package/lib/built/endpoint-lifecycle.js +0 -36
  100. package/lib/built/endpoint-manager.d.ts +0 -34
  101. package/lib/built/endpoint-manager.js +0 -1
  102. package/lib/built/html-renderer-loader.d.ts +0 -13
  103. package/lib/built/html-renderer-loader.js +0 -33
  104. package/lib/built/inbound-pipeline.d.ts +0 -37
  105. package/lib/built/inbound-pipeline.js +0 -63
  106. package/lib/built/inbound-runner.d.ts +0 -22
  107. package/lib/built/inbound-runner.js +0 -34
  108. package/lib/built/interactive-segment-contract.d.ts +0 -6
  109. package/lib/built/interactive-segment-contract.js +0 -9
  110. package/lib/built/interactive-segments/fallback-store.d.ts +0 -29
  111. package/lib/built/interactive-segments/fallback-store.js +0 -63
  112. package/lib/built/interactive-segments/handlers.d.ts +0 -16
  113. package/lib/built/interactive-segments/handlers.js +0 -74
  114. package/lib/built/introspection-format.d.ts +0 -10
  115. package/lib/built/introspection-format.js +0 -28
  116. package/lib/built/management-command-guard.d.ts +0 -15
  117. package/lib/built/management-command-guard.js +0 -25
  118. package/lib/built/message-filter.d.ts +0 -176
  119. package/lib/built/message-filter.js +0 -239
  120. package/lib/built/optional-peer-import.d.ts +0 -3
  121. package/lib/built/optional-peer-import.js +0 -33
  122. package/lib/built/outbound-media-contract.d.ts +0 -22
  123. package/lib/built/outbound-media-contract.js +0 -10
  124. package/lib/built/permission.d.ts +0 -51
  125. package/lib/built/permission.js +0 -99
  126. package/lib/built/permit-check.d.ts +0 -7
  127. package/lib/built/permit-check.js +0 -35
  128. package/lib/built/permit-parse.d.ts +0 -16
  129. package/lib/built/permit-parse.js +0 -32
  130. package/lib/built/platform-permit.d.ts +0 -20
  131. package/lib/built/platform-permit.js +0 -91
  132. package/lib/built/rich-segments/adapter-policies.d.ts +0 -9
  133. package/lib/built/rich-segments/adapter-policies.js +0 -27
  134. package/lib/built/rich-segments/base.d.ts +0 -11
  135. package/lib/built/rich-segments/base.js +0 -24
  136. package/lib/built/rich-segments/builtins.d.ts +0 -4
  137. package/lib/built/rich-segments/builtins.js +0 -40
  138. package/lib/built/rich-segments/capabilities.d.ts +0 -6
  139. package/lib/built/rich-segments/capabilities.js +0 -38
  140. package/lib/built/rich-segments/html-segment.d.ts +0 -15
  141. package/lib/built/rich-segments/html-segment.js +0 -62
  142. package/lib/built/rich-segments/index.d.ts +0 -13
  143. package/lib/built/rich-segments/index.js +0 -13
  144. package/lib/built/rich-segments/markdown-segment.d.ts +0 -14
  145. package/lib/built/rich-segments/markdown-segment.js +0 -58
  146. package/lib/built/rich-segments/qrcode-segment.d.ts +0 -18
  147. package/lib/built/rich-segments/qrcode-segment.js +0 -73
  148. package/lib/built/rich-segments/registry.d.ts +0 -16
  149. package/lib/built/rich-segments/registry.js +0 -52
  150. package/lib/built/rich-segments/resolve.d.ts +0 -5
  151. package/lib/built/rich-segments/resolve.js +0 -87
  152. package/lib/built/rich-segments/tts-segment.d.ts +0 -13
  153. package/lib/built/rich-segments/tts-segment.js +0 -51
  154. package/lib/built/rich-segments/types.d.ts +0 -79
  155. package/lib/built/rich-segments/types.js +0 -17
  156. package/lib/built/runtime-io.d.ts +0 -9
  157. package/lib/built/runtime-io.js +0 -67
  158. package/lib/built/schedule.d.ts +0 -54
  159. package/lib/built/schedule.js +0 -112
  160. package/lib/built/schema-endpoint-manager.d.ts +0 -17
  161. package/lib/built/schema-endpoint-manager.js +0 -73
  162. package/lib/built/schema-feature.d.ts +0 -77
  163. package/lib/built/schema-feature.js +0 -130
  164. package/lib/built/skill.d.ts +0 -120
  165. package/lib/built/skill.js +0 -151
  166. package/lib/built/speech-loader.d.ts +0 -14
  167. package/lib/built/speech-loader.js +0 -32
  168. package/lib/built/tool.d.ts +0 -151
  169. package/lib/built/tool.js +0 -388
  170. package/lib/command.d.ts +0 -50
  171. package/lib/command.js +0 -106
  172. package/lib/endpoint-capabilities.d.ts +0 -46
  173. package/lib/endpoint-capabilities.js +0 -55
  174. package/lib/endpoint.d.ts +0 -19
  175. package/lib/endpoint.js +0 -3
  176. package/lib/host-plugin-registry.d.ts +0 -8
  177. package/lib/host-plugin-registry.js +0 -12
  178. package/lib/plugin-context.d.ts +0 -27
  179. package/lib/plugin-context.js +0 -64
  180. package/lib/plugin-runtime/im/interactive.d.ts +0 -26
  181. package/lib/plugin-runtime/im/interactive.js +0 -46
  182. package/lib/plugin-runtime/im/service-tokens.d.ts +0 -18
  183. package/lib/plugin-runtime/im/service-tokens.js +0 -13
  184. package/lib/plugin.d.ts +0 -268
  185. package/lib/plugin.js +0 -583
  186. package/lib/schema-interaction.d.ts +0 -117
  187. package/lib/schema-interaction.js +0 -247
  188. package/lib/tool-zod.d.ts +0 -43
  189. package/lib/tool-zod.js +0 -184
@@ -1,36 +1,16 @@
1
- import { Scope, generationAdmissionBinder, type GenerationAdmissionGate, type PluginId, type RuntimeSnapshot, type SnapshotLease, type SnapshotReader } from '@zhin.js/plugin-runtime';
1
+ import { Scope, generationAdmissionBinder, type GenerationAdmissionGate, type RuntimeSnapshot, type SnapshotLease, type SnapshotReader } from '@zhin.js/plugin-runtime';
2
+ import { PermissionHost } from '@zhin.js/permission';
2
3
  import { MessageBus } from './message-bus.js';
3
- import { type AdapterOperation, type EndpointManagement, type EndpointManagementCapability, type AdapterEndpointPhase, type EndpointContentResolveContext, type EndpointEvent, type EndpointEventGateway } from '@zhin.js/adapter';
4
- import { type ConversationEventStore, type ConversationContextBlock, type ConversationReference, type ConversationResolution, type ConversationRef, type DeliveryReceipt, type EndpointCapabilities, type MessageRef } from '@zhin.js/im-contract';
5
- import { Message, type ConversationAddress, type IncomingMessage, type OutboundMessageService, type MessageSenderRef, type SendRequest } from './contracts.js';
4
+ import { type EndpointContentResolveContext, type EndpointEventGateway } from '@zhin.js/adapter';
5
+ import { type ConversationEventStore, type ConversationEventReader, type ConversationContextBlock, type ConversationReference, type ConversationResolution, type ConversationRef, type DeliveryReceipt } from '@zhin.js/im-contract';
6
+ import { Message, type IncomingMessage, type OutboundMessageService, type MessageSenderRef, type SendRequest } from './contracts.js';
6
7
  import { LoginAssist } from '../../built/login-assist.js';
7
8
  import type { UserInteraction } from '@zhin.js/interaction';
8
- import { OutboundRenderer } from './outbound-renderer.js';
9
- import { type RuntimeInteractiveHandler } from './interactive.js';
9
+ import type { OutboundRenderer } from './outbound-renderer.js';
10
+ import { EndpointRuntime } from './endpoint-runtime.js';
11
+ import { type RuntimeMessageEventSource } from './message-events.js';
10
12
  /** @public Stable inbound and outbound IM gateway token for Adapter integrations. */
11
13
  export declare const outboundMessageToken: import("@zhin.js/plugin-runtime").Token<OutboundMessageService>;
12
- /** Generation-owned ingress hooks before ordinary dispatch and after it misses. */
13
- export interface IngressRoute {
14
- preRoute?(message: Message, lease: SnapshotLease, requester: PluginId, conversationSequence: number | undefined): Promise<boolean>;
15
- /** A live pre-route handoff that must run before handlers and commands. */
16
- shouldRouteBeforeDispatch?(message: Message): boolean;
17
- route(message: Message, lease: SnapshotLease, requester: PluginId, conversationSequence: number | undefined): Promise<boolean>;
18
- }
19
- export declare const ingressRouteToken: import("@zhin.js/plugin-runtime").Token<IngressRoute>;
20
- /** Console 实时消息事件(SSE 推送源;content 仅为截断预览,不含完整原始段)。 */
21
- export interface RuntimeMessageEvent {
22
- readonly direction: 'inbound' | 'outbound';
23
- readonly conversation: ConversationRef;
24
- /** inbound:发送者。 */
25
- readonly sender?: MessageSenderRef;
26
- /** outbound:发起方插件。 */
27
- readonly requester?: PluginId;
28
- /** 预览文本,截断至 200 字。 */
29
- readonly contentPreview: string;
30
- readonly messageId?: string;
31
- readonly timestamp: number;
32
- }
33
- export declare const messagePreviewLimit = 200;
34
14
  export interface ImRuntimeOptions {
35
15
  /**
36
16
  * 全局静态命令前缀(如 `'/'`)。缺省时按适配器实例 config 的
@@ -51,10 +31,12 @@ export interface ImRuntimeOptions {
51
31
  }
52
32
  export declare class ImRuntime implements OutboundMessageService {
53
33
  #private;
54
- conversationEvents: ConversationEventStore;
34
+ readonly messageEvents: RuntimeMessageEventSource;
35
+ readonly endpoints: EndpointRuntime;
55
36
  constructor(options?: ImRuntimeOptions);
56
37
  /** Process composition replaces the bootstrap memory store after required DB activation. */
57
38
  replaceConversationEventStore(store: ConversationEventStore): void;
39
+ get conversationEventReader(): ConversationEventReader;
58
40
  /** Pins all nested IM operations to the snapshot current at operation ingress. */
59
41
  runWithSnapshotView<T>(operation: () => Promise<T>): Promise<T>;
60
42
  resolveConversationReference(lease: SnapshotLease, reference: ConversationReference, context: EndpointContentResolveContext): Promise<ConversationResolution>;
@@ -64,7 +46,7 @@ export declare class ImRuntime implements OutboundMessageService {
64
46
  }>>;
65
47
  commitConversationContext(conversation: ConversationRef, consumer: string, cursor: number): Promise<void>;
66
48
  attach(snapshots: SnapshotReader): void;
67
- readonly permissionHost: import("@zhin.js/permission").PermissionHost;
49
+ readonly permissionHost: PermissionHost;
68
50
  readonly messageBus: MessageBus;
69
51
  readonly loginAssist: LoginAssist;
70
52
  install(resources: Scope): void;
@@ -77,7 +59,7 @@ export declare class ImRuntime implements OutboundMessageService {
77
59
  * 注册 interactive action 回跳 handler(prefix 最长匹配;返回注销函数)。
78
60
  * 在 Command dispatch 之前路由:action 段 / 数字回跳 / 指令预填 payload。
79
61
  */
80
- registerInteractiveHandler(prefix: string, handler: RuntimeInteractiveHandler): () => void;
62
+ registerInteractiveHandler(prefix: string, handler: (message: Message) => Promise<boolean> | boolean): () => void;
81
63
  /**
82
64
  * User interaction bound to this conversation.
83
65
  * `bind.subjectId` waits for that user (e.g. master) instead of the message sender.
@@ -85,32 +67,9 @@ export declare class ImRuntime implements OutboundMessageService {
85
67
  createInteraction(message: Message, bind?: {
86
68
  readonly subjectId: string;
87
69
  }): UserInteraction | undefined;
88
- /**
89
- * 订阅消息事件(入站 dispatch 完成后 / 出站发送成功后回调)。
90
- * 返回注销函数。listener 抛错不会阻断消息链路。
91
- */
92
- onMessage(listener: (event: RuntimeMessageEvent) => void): () => void;
93
70
  send(request: SendRequest): Promise<DeliveryReceipt>;
94
71
  /** Sends through the exact generation lease that admitted the current operation. */
95
72
  sendWithSnapshotLease(lease: SnapshotLease, request: SendRequest): Promise<DeliveryReceipt>;
96
- receiveEndpointEvent(event: EndpointEvent, admission?: GenerationAdmissionGate): Promise<unknown>;
97
- /** Console `endpoint.list` — empty until Adapter Feature projection is ready. */
98
- listEndpoints(): readonly {
99
- readonly id: string;
100
- readonly name: string;
101
- readonly adapter: string;
102
- readonly owner: string;
103
- readonly connected: boolean;
104
- readonly status: 'online' | 'offline';
105
- readonly phase: AdapterEndpointPhase;
106
- readonly operations: readonly AdapterOperation[];
107
- readonly managementCapabilities: readonly EndpointManagementCapability[];
108
- }[];
109
- /** Exact operation capabilities for one concrete live Endpoint. */
110
- endpointCapabilities(input: {
111
- readonly adapter: string;
112
- readonly endpointKey: string;
113
- }): EndpointCapabilities | undefined;
114
73
  /**
115
74
  * Console `GET /api/stats` 同源计数:非 root 插件节点 + AdapterIndex endpoints。
116
75
  * 供命令 / 状态卡等在 Plugin Runtime 下读取(legacy `root.adapters` / `root.children` 已不存在)。
@@ -122,56 +81,4 @@ export declare class ImRuntime implements OutboundMessageService {
122
81
  readonly online: number;
123
82
  };
124
83
  }>;
125
- getEndpoint(adapter: string, endpointKey: string): {
126
- readonly name: string;
127
- readonly adapter: string;
128
- readonly connected: boolean;
129
- readonly status: 'online' | 'offline';
130
- readonly phase: AdapterEndpointPhase;
131
- readonly operations: readonly AdapterOperation[];
132
- readonly managementCapabilities: readonly EndpointManagementCapability[];
133
- } | null;
134
- sendEndpointMessage(input: {
135
- readonly adapter: string;
136
- readonly endpointKey: string;
137
- readonly conversation: ConversationAddress;
138
- readonly content: unknown;
139
- }): Promise<{
140
- messageId: string;
141
- }>;
142
- /** Activity-feedback: add a message reaction when the live Endpoint supports it. */
143
- addEndpointReaction(input: {
144
- readonly adapter: string;
145
- readonly endpointKey: string;
146
- readonly message: MessageRef;
147
- readonly emoji: string;
148
- readonly sceneType?: string;
149
- readonly channelId?: string;
150
- }): Promise<string | null>;
151
- removeEndpointReaction(input: {
152
- readonly adapter: string;
153
- readonly endpointKey: string;
154
- readonly message: MessageRef;
155
- readonly reactionId: string;
156
- }): Promise<void>;
157
- /** Activity-feedback autoRemove: recall a previously sent status message. */
158
- recallEndpointMessage(input: {
159
- readonly adapter: string;
160
- readonly endpointKey: string;
161
- readonly message: MessageRef;
162
- }): Promise<void>;
163
- editEndpointMessage(input: {
164
- readonly adapter: string;
165
- readonly endpointKey: string;
166
- readonly message: MessageRef;
167
- readonly content: unknown;
168
- }): Promise<string | null>;
169
- setEndpointTyping(input: {
170
- readonly adapter: string;
171
- readonly endpointKey: string;
172
- readonly conversation: ConversationRef;
173
- readonly active?: boolean;
174
- }): Promise<void>;
175
- /** Run one management operation while the Endpoint generation stays leased. */
176
- withEndpointManagement<T>(adapter: string, endpointKey: string, run: (management: EndpointManagement) => T | Promise<T>): Promise<T | null>;
177
84
  }