@zhin.js/core 1.5.16 → 1.7.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.
Files changed (334) hide show
  1. package/README.md +78 -195
  2. package/lib/ai-completion-contract.d.ts +135 -0
  3. package/lib/ai-completion-contract.js +69 -0
  4. package/lib/built/ai-access.d.ts +2 -21
  5. package/lib/built/ai-access.js +1 -46
  6. package/lib/built/ai-outbound/index.d.ts +0 -2
  7. package/lib/built/ai-outbound/index.js +0 -2
  8. package/lib/built/ai-outbound/prompt.d.ts +2 -0
  9. package/lib/built/ai-outbound/prompt.js +2 -0
  10. package/lib/built/ai-outbound/types.d.ts +1 -10
  11. package/lib/built/ai-trigger.d.ts +39 -78
  12. package/lib/built/ai-trigger.js +3 -254
  13. package/lib/built/common-adapter-tools.d.ts +21 -6
  14. package/lib/built/common-adapter-tools.js +28 -17
  15. package/lib/built/generic-segment-mapper.js +4 -1
  16. package/lib/built/html-segment-fallback.d.ts +6 -7
  17. package/lib/built/html-segment-fallback.js +1 -16
  18. package/lib/built/html-to-text.d.ts +0 -3
  19. package/lib/built/html-to-text.js +131 -40
  20. package/lib/built/interaction-messages.d.ts +1 -0
  21. package/lib/built/interaction-messages.js +30 -0
  22. package/lib/built/interactive-segments/action.d.ts +3 -4
  23. package/lib/built/interactive-segments/action.js +2 -5
  24. package/lib/built/interactive-segments/index.d.ts +0 -2
  25. package/lib/built/interactive-segments/index.js +0 -2
  26. package/lib/built/interactive-segments/keyboard-segment.d.ts +0 -1
  27. package/lib/built/interactive-segments/keyboard-segment.js +0 -1
  28. package/lib/built/interactive-segments/onebot-keyboard.d.ts +0 -1
  29. package/lib/built/interactive-segments/onebot-keyboard.js +0 -2
  30. package/lib/built/interactive-segments/resolve.d.ts +2 -3
  31. package/lib/built/interactive-segments/resolve.js +21 -14
  32. package/lib/built/interactive-segments/types.d.ts +2 -7
  33. package/lib/built/interactive-segments/types.js +22 -2
  34. package/lib/built/login-assist.d.ts +330 -25
  35. package/lib/built/login-assist.js +1156 -75
  36. package/lib/built/login-captcha.d.ts +62 -0
  37. package/lib/built/login-captcha.js +107 -0
  38. package/lib/built/message-enrich.d.ts +24 -27
  39. package/lib/built/message-enrich.js +53 -49
  40. package/lib/built/outbound-content-arrays.d.ts +4 -0
  41. package/lib/built/outbound-content-arrays.js +32 -0
  42. package/lib/built/outbound-media-trust.d.ts +46 -0
  43. package/lib/built/outbound-media-trust.js +245 -0
  44. package/lib/built/outbound-media-utils.d.ts +5 -3
  45. package/lib/built/outbound-media-utils.js +5 -3
  46. package/lib/built/readable-link.d.ts +4 -0
  47. package/lib/built/readable-link.js +32 -0
  48. package/lib/built/rich-segments/markdown-to-text.d.ts +1 -2
  49. package/lib/built/rich-segments/markdown-to-text.js +141 -17
  50. package/lib/built/roles.d.ts +141 -12
  51. package/lib/built/roles.js +253 -52
  52. package/lib/built/segment-contract/assert.js +8 -2
  53. package/lib/built/segment-contract/delivery.js +1 -0
  54. package/lib/built/segment-contract/index.d.ts +3 -3
  55. package/lib/built/segment-contract/index.js +2 -2
  56. package/lib/built/segment-contract/json-schema.d.ts +39 -5
  57. package/lib/built/segment-contract/json-schema.js +207 -24
  58. package/lib/built/segment-contract/preview.js +8 -1
  59. package/lib/built/segment-contract/text.js +1 -1
  60. package/lib/built/segment-contract/types.d.ts +2 -2
  61. package/lib/built/segment-contract/validate.d.ts +1553 -224
  62. package/lib/built/segment-contract/validate.js +39 -3
  63. package/lib/built/tool-access.d.ts +5 -0
  64. package/lib/built/tool-access.js +17 -0
  65. package/lib/built/user-interaction.d.ts +5 -4
  66. package/lib/built/user-interaction.js +64 -52
  67. package/lib/errors.d.ts +1 -18
  68. package/lib/errors.js +1 -26
  69. package/lib/feature/command-public-api.d.ts +5 -0
  70. package/lib/feature/command-public-api.js +5 -0
  71. package/lib/feature/command.d.ts +2 -0
  72. package/lib/feature/command.js +1 -0
  73. package/lib/feature/component.d.ts +1 -0
  74. package/lib/feature/component.js +1 -0
  75. package/lib/feature/handler.d.ts +13 -7
  76. package/lib/feature/handler.js +2 -1
  77. package/lib/feature/middleware-public-api.d.ts +6 -0
  78. package/lib/feature/middleware-public-api.js +6 -0
  79. package/lib/feature/middleware.d.ts +22 -2
  80. package/lib/feature/middleware.js +7 -2
  81. package/lib/im-scene.d.ts +4 -3
  82. package/lib/im-scene.js +9 -9
  83. package/lib/im-session-id.d.ts +20 -12
  84. package/lib/im-session-id.js +8 -8
  85. package/lib/index.d.ts +20 -48
  86. package/lib/index.js +15 -41
  87. package/lib/jsx/intrinsic-elements.d.ts +83 -0
  88. package/lib/jsx/message-renderer.d.ts +13 -0
  89. package/lib/jsx/message-renderer.js +128 -0
  90. package/lib/jsx/message-tags.d.ts +133 -0
  91. package/lib/jsx/message-tags.js +50 -0
  92. package/lib/jsx-dev-runtime.d.ts +2 -2
  93. package/lib/jsx-dev-runtime.js +1 -2
  94. package/lib/jsx-runtime.d.ts +2 -12
  95. package/lib/jsx-runtime.js +1 -10
  96. package/lib/jsx.d.ts +6 -30
  97. package/lib/jsx.js +3 -93
  98. package/lib/message.d.ts +0 -40
  99. package/lib/message.js +1 -27
  100. package/lib/models/system-log.d.ts +0 -2
  101. package/lib/models/system-log.js +1 -8
  102. package/lib/models/user.d.ts +0 -2
  103. package/lib/models/user.js +1 -7
  104. package/lib/notice.d.ts +38 -33
  105. package/lib/notice.js +23 -7
  106. package/lib/plugin-runtime/im/command-feedback.d.ts +59 -0
  107. package/lib/plugin-runtime/im/command-feedback.js +148 -0
  108. package/lib/plugin-runtime/im/contracts.d.ts +217 -32
  109. package/lib/plugin-runtime/im/contracts.js +141 -23
  110. package/lib/plugin-runtime/im/conversation-runtime.d.ts +42 -0
  111. package/lib/plugin-runtime/im/conversation-runtime.js +451 -0
  112. package/lib/plugin-runtime/im/endpoint-runtime.d.ts +112 -0
  113. package/lib/plugin-runtime/im/endpoint-runtime.js +434 -0
  114. package/lib/plugin-runtime/im/feature-gate.d.ts +21 -0
  115. package/lib/plugin-runtime/im/feature-gate.js +88 -0
  116. package/lib/plugin-runtime/im/host/component-host-installer.d.ts +2 -0
  117. package/lib/plugin-runtime/im/host/component-host-installer.js +14 -0
  118. package/lib/plugin-runtime/im/host/conversation-migration.d.ts +5 -0
  119. package/lib/plugin-runtime/im/host/conversation-migration.js +75 -0
  120. package/lib/plugin-runtime/im/host/database-config.d.ts +10 -0
  121. package/lib/plugin-runtime/im/host/database-config.js +152 -0
  122. package/lib/plugin-runtime/im/host/database-console-schema.d.ts +79 -0
  123. package/lib/plugin-runtime/im/host/database-console-schema.js +477 -0
  124. package/lib/plugin-runtime/im/host/database-console-sql.d.ts +66 -0
  125. package/lib/plugin-runtime/im/host/database-console-sql.js +459 -0
  126. package/lib/plugin-runtime/im/host/database-host-installer.d.ts +60 -0
  127. package/lib/plugin-runtime/im/host/database-host-installer.js +1166 -0
  128. package/lib/plugin-runtime/im/host/database-state.d.ts +9 -0
  129. package/lib/plugin-runtime/im/host/database-state.js +91 -0
  130. package/lib/plugin-runtime/im/host/index.d.ts +8 -0
  131. package/lib/plugin-runtime/im/host/index.js +8 -0
  132. package/lib/plugin-runtime/im/host/locale-host-installer.d.ts +3 -0
  133. package/lib/plugin-runtime/im/host/locale-host-installer.js +60 -0
  134. package/lib/plugin-runtime/im/host/outbound-host-installer.d.ts +8 -0
  135. package/lib/plugin-runtime/im/host/outbound-host-installer.js +153 -0
  136. package/lib/plugin-runtime/im/host/sender-enrichment.d.ts +34 -0
  137. package/lib/plugin-runtime/im/host/sender-enrichment.js +82 -0
  138. package/lib/plugin-runtime/im/im-runtime.d.ts +40 -111
  139. package/lib/plugin-runtime/im/im-runtime.js +235 -1059
  140. package/lib/plugin-runtime/im/inbound-dedup.d.ts +84 -0
  141. package/lib/plugin-runtime/im/inbound-dedup.js +322 -0
  142. package/lib/plugin-runtime/im/inbound-origin.d.ts +150 -0
  143. package/lib/plugin-runtime/im/inbound-origin.js +183 -0
  144. package/lib/plugin-runtime/im/inbound-runtime.d.ts +59 -0
  145. package/lib/plugin-runtime/im/inbound-runtime.js +478 -0
  146. package/lib/plugin-runtime/im/inbound-spine.d.ts +196 -0
  147. package/lib/plugin-runtime/im/inbound-spine.js +335 -0
  148. package/lib/plugin-runtime/im/index.d.ts +15 -4
  149. package/lib/plugin-runtime/im/index.js +11 -4
  150. package/lib/plugin-runtime/im/interaction-runtime.d.ts +50 -0
  151. package/lib/plugin-runtime/im/interaction-runtime.js +390 -0
  152. package/lib/plugin-runtime/im/interactive-router.d.ts +81 -0
  153. package/lib/plugin-runtime/im/interactive-router.js +382 -0
  154. package/lib/plugin-runtime/im/message-diagnostics.d.ts +70 -0
  155. package/lib/plugin-runtime/im/message-diagnostics.js +182 -0
  156. package/lib/plugin-runtime/im/message-dispatcher.d.ts +18 -4
  157. package/lib/plugin-runtime/im/message-dispatcher.js +138 -20
  158. package/lib/plugin-runtime/im/message-events.d.ts +85 -0
  159. package/lib/plugin-runtime/im/message-events.js +113 -0
  160. package/lib/plugin-runtime/im/outbound-delivery-runtime.d.ts +39 -0
  161. package/lib/plugin-runtime/im/outbound-delivery-runtime.js +450 -0
  162. package/lib/plugin-runtime/im/outbound-renderer.d.ts +52 -3
  163. package/lib/plugin-runtime/im/outbound-renderer.js +188 -8
  164. package/lib/plugin-runtime/im/outbound-segments.d.ts +29 -5
  165. package/lib/plugin-runtime/im/outbound-segments.js +130 -36
  166. package/lib/plugin-runtime/im/progressive-reply.d.ts +58 -0
  167. package/lib/plugin-runtime/im/progressive-reply.js +501 -0
  168. package/lib/plugin-runtime/im/public-api.d.ts +1 -1
  169. package/lib/request.d.ts +27 -36
  170. package/lib/request.js +14 -6
  171. package/lib/side-event/base.d.ts +64 -44
  172. package/lib/side-event/base.js +72 -19
  173. package/lib/side-event/index.d.ts +1 -1
  174. package/lib/side-event/index.js +1 -1
  175. package/lib/side-event/normalize.d.ts +7 -38
  176. package/lib/side-event/normalize.js +4 -109
  177. package/lib/side-event/scene-events.d.ts +40 -0
  178. package/lib/side-event/scene-events.js +147 -0
  179. package/lib/side-event/types.d.ts +4 -13
  180. package/lib/side-event/types.js +1 -55
  181. package/lib/system-event.d.ts +17 -12
  182. package/lib/system-event.js +8 -6
  183. package/lib/types.d.ts +23 -167
  184. package/lib/utils.d.ts +50 -33
  185. package/lib/utils.js +12 -185
  186. package/lib/venue/contracts.d.ts +21 -0
  187. package/lib/venue/contracts.js +3 -0
  188. package/lib/venue/floor-controller.d.ts +11 -0
  189. package/lib/venue/floor-controller.js +63 -0
  190. package/lib/venue/index.d.ts +13 -0
  191. package/lib/venue/index.js +11 -0
  192. package/lib/venue/membership-port.d.ts +23 -0
  193. package/lib/venue/membership-port.js +141 -0
  194. package/lib/venue/projector.d.ts +38 -0
  195. package/lib/venue/projector.js +45 -0
  196. package/lib/venue/registry.d.ts +16 -0
  197. package/lib/venue/registry.js +63 -0
  198. package/lib/venue/router.d.ts +19 -0
  199. package/lib/venue/router.js +101 -0
  200. package/lib/venue/send-limiter.d.ts +17 -0
  201. package/lib/venue/send-limiter.js +73 -0
  202. package/lib/venue/validator.d.ts +6 -0
  203. package/lib/venue/validator.js +160 -0
  204. package/package.json +24 -50
  205. package/lib/adapter.d.ts +0 -145
  206. package/lib/adapter.js +0 -377
  207. package/lib/built/adapter-process.d.ts +0 -58
  208. package/lib/built/adapter-process.js +0 -128
  209. package/lib/built/agent-preset.d.ts +0 -64
  210. package/lib/built/agent-preset.js +0 -79
  211. package/lib/built/ai-outbound/adapter-access.d.ts +0 -3
  212. package/lib/built/ai-outbound/adapter-access.js +0 -9
  213. package/lib/built/ai-outbound/extensions/qq-message.d.ts +0 -3
  214. package/lib/built/ai-outbound/extensions/qq-message.js +0 -23
  215. package/lib/built/authorization.d.ts +0 -10
  216. package/lib/built/authorization.js +0 -76
  217. package/lib/built/command.d.ts +0 -72
  218. package/lib/built/command.js +0 -105
  219. package/lib/built/component.d.ts +0 -67
  220. package/lib/built/component.js +0 -97
  221. package/lib/built/config.d.ts +0 -98
  222. package/lib/built/config.js +0 -372
  223. package/lib/built/connect-endpoint-instance.d.ts +0 -17
  224. package/lib/built/connect-endpoint-instance.js +0 -42
  225. package/lib/built/database.d.ts +0 -68
  226. package/lib/built/database.js +0 -106
  227. package/lib/built/dispatcher.d.ts +0 -141
  228. package/lib/built/dispatcher.js +0 -383
  229. package/lib/built/endpoint-commands.d.ts +0 -3
  230. package/lib/built/endpoint-commands.js +0 -99
  231. package/lib/built/endpoint-lifecycle-service.d.ts +0 -28
  232. package/lib/built/endpoint-lifecycle-service.js +0 -242
  233. package/lib/built/endpoint-lifecycle.d.ts +0 -27
  234. package/lib/built/endpoint-lifecycle.js +0 -36
  235. package/lib/built/endpoint-manager.d.ts +0 -34
  236. package/lib/built/html-renderer-loader.d.ts +0 -13
  237. package/lib/built/html-renderer-loader.js +0 -33
  238. package/lib/built/inbound-pipeline.d.ts +0 -37
  239. package/lib/built/inbound-pipeline.js +0 -63
  240. package/lib/built/inbound-runner.d.ts +0 -22
  241. package/lib/built/inbound-runner.js +0 -34
  242. package/lib/built/interactive-segment-contract.d.ts +0 -6
  243. package/lib/built/interactive-segment-contract.js +0 -9
  244. package/lib/built/interactive-segments/fallback-store.d.ts +0 -29
  245. package/lib/built/interactive-segments/fallback-store.js +0 -63
  246. package/lib/built/interactive-segments/handlers.d.ts +0 -16
  247. package/lib/built/interactive-segments/handlers.js +0 -74
  248. package/lib/built/introspection-format.d.ts +0 -10
  249. package/lib/built/introspection-format.js +0 -28
  250. package/lib/built/management-command-guard.d.ts +0 -15
  251. package/lib/built/management-command-guard.js +0 -25
  252. package/lib/built/message-filter.d.ts +0 -176
  253. package/lib/built/message-filter.js +0 -239
  254. package/lib/built/optional-peer-import.d.ts +0 -3
  255. package/lib/built/optional-peer-import.js +0 -33
  256. package/lib/built/outbound-media-contract.d.ts +0 -22
  257. package/lib/built/outbound-media-contract.js +0 -10
  258. package/lib/built/permission.d.ts +0 -51
  259. package/lib/built/permission.js +0 -99
  260. package/lib/built/permit-check.d.ts +0 -7
  261. package/lib/built/permit-check.js +0 -35
  262. package/lib/built/permit-parse.d.ts +0 -16
  263. package/lib/built/permit-parse.js +0 -32
  264. package/lib/built/platform-permit.d.ts +0 -20
  265. package/lib/built/platform-permit.js +0 -91
  266. package/lib/built/queue-im-field-contract.d.ts +0 -32
  267. package/lib/built/queue-im-field-contract.js +0 -67
  268. package/lib/built/rich-segments/adapter-policies.d.ts +0 -9
  269. package/lib/built/rich-segments/adapter-policies.js +0 -27
  270. package/lib/built/rich-segments/base.d.ts +0 -11
  271. package/lib/built/rich-segments/base.js +0 -24
  272. package/lib/built/rich-segments/builtins.d.ts +0 -4
  273. package/lib/built/rich-segments/builtins.js +0 -40
  274. package/lib/built/rich-segments/capabilities.d.ts +0 -6
  275. package/lib/built/rich-segments/capabilities.js +0 -38
  276. package/lib/built/rich-segments/html-segment.d.ts +0 -15
  277. package/lib/built/rich-segments/html-segment.js +0 -62
  278. package/lib/built/rich-segments/index.d.ts +0 -13
  279. package/lib/built/rich-segments/index.js +0 -13
  280. package/lib/built/rich-segments/markdown-segment.d.ts +0 -14
  281. package/lib/built/rich-segments/markdown-segment.js +0 -58
  282. package/lib/built/rich-segments/qrcode-segment.d.ts +0 -18
  283. package/lib/built/rich-segments/qrcode-segment.js +0 -73
  284. package/lib/built/rich-segments/registry.d.ts +0 -16
  285. package/lib/built/rich-segments/registry.js +0 -52
  286. package/lib/built/rich-segments/resolve.d.ts +0 -5
  287. package/lib/built/rich-segments/resolve.js +0 -87
  288. package/lib/built/rich-segments/tts-segment.d.ts +0 -13
  289. package/lib/built/rich-segments/tts-segment.js +0 -51
  290. package/lib/built/rich-segments/types.d.ts +0 -79
  291. package/lib/built/rich-segments/types.js +0 -17
  292. package/lib/built/runtime-io.d.ts +0 -9
  293. package/lib/built/runtime-io.js +0 -67
  294. package/lib/built/schedule.d.ts +0 -54
  295. package/lib/built/schedule.js +0 -112
  296. package/lib/built/schema-endpoint-manager.d.ts +0 -17
  297. package/lib/built/schema-endpoint-manager.js +0 -73
  298. package/lib/built/schema-feature.d.ts +0 -77
  299. package/lib/built/schema-feature.js +0 -130
  300. package/lib/built/skill.d.ts +0 -120
  301. package/lib/built/skill.js +0 -151
  302. package/lib/built/speech-loader.d.ts +0 -14
  303. package/lib/built/speech-loader.js +0 -32
  304. package/lib/built/tool.d.ts +0 -151
  305. package/lib/built/tool.js +0 -388
  306. package/lib/command.d.ts +0 -50
  307. package/lib/command.js +0 -106
  308. package/lib/component.d.ts +0 -26
  309. package/lib/component.js +0 -583
  310. package/lib/endpoint-capabilities.d.ts +0 -46
  311. package/lib/endpoint-capabilities.js +0 -55
  312. package/lib/endpoint.d.ts +0 -19
  313. package/lib/endpoint.js +0 -3
  314. package/lib/host-plugin-registry.d.ts +0 -8
  315. package/lib/host-plugin-registry.js +0 -12
  316. package/lib/plugin-context.d.ts +0 -27
  317. package/lib/plugin-context.js +0 -64
  318. package/lib/plugin-runtime/im/interactive.d.ts +0 -26
  319. package/lib/plugin-runtime/im/interactive.js +0 -46
  320. package/lib/plugin-runtime/im/login-assist-host.d.ts +0 -6
  321. package/lib/plugin-runtime/im/login-assist-host.js +0 -6
  322. package/lib/plugin-runtime/im/message-bus.d.ts +0 -38
  323. package/lib/plugin-runtime/im/message-bus.js +0 -40
  324. package/lib/plugin-runtime/im/service-tokens.d.ts +0 -18
  325. package/lib/plugin-runtime/im/service-tokens.js +0 -13
  326. package/lib/plugin.d.ts +0 -268
  327. package/lib/plugin.js +0 -583
  328. package/lib/schema-interaction.d.ts +0 -117
  329. package/lib/schema-interaction.js +0 -247
  330. package/lib/side-event/dispatch.d.ts +0 -15
  331. package/lib/side-event/dispatch.js +0 -140
  332. package/lib/tool-zod.d.ts +0 -43
  333. package/lib/tool-zod.js +0 -184
  334. /package/lib/{built/endpoint-manager.js → jsx/intrinsic-elements.js} +0 -0
@@ -1,128 +0,0 @@
1
- import { formatCompact } from "@zhin.js/logger";
2
- import { Adapter } from "../adapter.js";
3
- import { Message } from "../message.js";
4
- import { segment } from "../utils.js";
5
- import { assertOutbound } from "../endpoint-capabilities.js";
6
- import { getOutboundReplyStore } from "./dispatcher.js";
7
- import { bindStdin, runtimePid, runtimeUser } from "./runtime-io.js";
8
- import { interpretOriginQrcodeForProcess } from "./rich-segments/qrcode-segment.js";
9
- export class ProcessEndpoint {
10
- adapter;
11
- $config;
12
- $id = runtimePid();
13
- get logger() {
14
- return this.adapter.logger;
15
- }
16
- $connected = false;
17
- #unbindStdin = null;
18
- constructor(adapter, $config = { owner: runtimePid() }) {
19
- this.adapter = adapter;
20
- this.$config = $config;
21
- this.$listenInput = this.$listenInput.bind(this);
22
- }
23
- $listenInput(chunk) {
24
- const content = chunk.trim();
25
- if (content) {
26
- this.adapter.emit('message.receive', this.$formatMessage({ content, ts: Date.now() }));
27
- }
28
- }
29
- async connect() {
30
- }
31
- async disconnect() {
32
- }
33
- $formatMessage(event) {
34
- const base = {
35
- $id: `${event.ts}`,
36
- $adapter: 'process',
37
- $endpoint: runtimePid(),
38
- $sender: {
39
- id: runtimeUser(),
40
- name: runtimeUser(),
41
- role: 'master',
42
- },
43
- $channel: {
44
- id: runtimeUser(),
45
- type: 'private',
46
- },
47
- $content: [{ type: 'text', data: { text: event.content } }],
48
- $raw: event.content,
49
- $timestamp: event.ts,
50
- $recall: async () => {
51
- await this.$recallMessage(base.$id);
52
- },
53
- $reply: async (content) => {
54
- return await this.adapter.sendMessage({
55
- context: 'process',
56
- endpoint: base.$endpoint,
57
- content,
58
- id: base.$sender.id,
59
- type: base.$channel.type,
60
- });
61
- },
62
- };
63
- return Message.from(event, base);
64
- }
65
- get control() {
66
- return {
67
- recall: async (message) => this.$recallMessage(message.id),
68
- };
69
- }
70
- async $recallMessage(id) {
71
- }
72
- async $sendMessage(options) {
73
- const content = await interpretOriginQrcodeForProcess(options.content ?? '');
74
- if (content != null) {
75
- const preview = segment.raw(content);
76
- if (preview) {
77
- process.stdout.write(`${preview}\n`);
78
- }
79
- }
80
- return `${Date.now()}`;
81
- }
82
- async $connect() {
83
- this.#unbindStdin = bindStdin((chunk) => this.$listenInput(chunk));
84
- this.$connected = true;
85
- }
86
- async $disconnect() {
87
- this.#unbindStdin?.();
88
- this.#unbindStdin = null;
89
- }
90
- }
91
- export class ProcessAdapter extends Adapter {
92
- static capabilities = ['inbound', 'outbound'];
93
- static outboundRichSegmentPolicy = {
94
- qrcode: 'origin',
95
- html: 'text',
96
- markdown: 'text',
97
- };
98
- constructor(plugin) {
99
- super(plugin, 'process', [{ owner: runtimePid() }]);
100
- }
101
- /**
102
- * process 出站由 $sendMessage 写入 stdout;父类 INFO preview 会与终端输出重复,故仅 debug 元数据。
103
- */
104
- async sendMessage(options) {
105
- options = await this.renderSendMessage(options);
106
- const endpoint = this.endpoints.get(options.endpoint);
107
- if (!endpoint)
108
- throw new Error(`Endpoint ${options.endpoint} not found`);
109
- assertOutbound(endpoint);
110
- this.logger.debug(formatCompact({
111
- send: `${options.type}(${options.id})`,
112
- endpoint: options.endpoint,
113
- }));
114
- const messageId = await endpoint.$sendMessage(options);
115
- const replyStore = getOutboundReplyStore();
116
- this.plugin.root.dispatch('message.send', {
117
- adapter: this.name,
118
- options,
119
- messageId,
120
- replySource: replyStore?.source,
121
- replyMessage: replyStore?.message,
122
- });
123
- return messageId;
124
- }
125
- createEndpoint(config) {
126
- return new ProcessEndpoint(this, config);
127
- }
128
- }
@@ -1,64 +0,0 @@
1
- /**
2
- * AgentPreset — 插件声明的专长 Agent 预设
3
- *
4
- * 核心概念:
5
- * Tool = 单个 AI 可调用的能力(函数)
6
- * Skill = 一组相关 Tool + 发现元数据(SKILL.md)
7
- * Agent = 针对特定领域的 Agent 预设(*.agent.md)
8
- *
9
- * Agent 预设以标准 *.agent.md 文件提供,框架自动扫描发现。
10
- * 主 Agent(ZhinAgent)可根据用户请求自动委派给匹配的专长 Agent。
11
- */
12
- import { Feature, type FeatureJSON } from '@zhin.js/kernel';
13
- import type { Tool } from '../types.js';
14
- /**
15
- * Agent 预设(从 *.agent.md 文件解析或编程式注册)
16
- */
17
- export interface AgentPreset {
18
- /** 预设名称(唯一标识) */
19
- name: string;
20
- /** 描述(AI 用来判断何时委派给此 Agent) */
21
- description: string;
22
- /** 自定义系统提示词(从 agent.md body 提取或显式指定) */
23
- systemPrompt?: string;
24
- /** 关联的工具列表 */
25
- tools?: Tool[];
26
- /** 触发关键词(用户消息匹配时优先考虑此 Agent) */
27
- keywords?: string[];
28
- /** 分类标签 */
29
- tags?: string[];
30
- /** 首选模型名 */
31
- model?: string;
32
- /** 首选 Provider 名 */
33
- provider?: string;
34
- /** 最大工具调用迭代次数 */
35
- maxIterations?: number;
36
- /** 来源插件名(由框架自动填充) */
37
- pluginName?: string;
38
- /** *.agent.md 文件的绝对路径 */
39
- filePath?: string;
40
- }
41
- declare module '../plugin.js' {
42
- namespace Plugin {
43
- interface Contexts {
44
- agentPreset: AgentPresetFeature;
45
- }
46
- }
47
- }
48
- export declare class AgentPresetFeature extends Feature<AgentPreset> {
49
- #private;
50
- readonly name: "agentPreset";
51
- readonly icon = "Endpoint";
52
- readonly desc = "Agent \u9884\u8BBE";
53
- readonly byName: Map<string, AgentPreset>;
54
- add(preset: AgentPreset, pluginName: string): () => void;
55
- remove(preset: AgentPreset, pluginName?: string): boolean;
56
- get(name: string): AgentPreset | undefined;
57
- /** 清理所有预设注册(热重载时由 Plugin.stop() 调用) */
58
- dispose(): void;
59
- getAll(): AgentPreset[];
60
- search(query: string, options?: {
61
- maxResults?: number;
62
- }): AgentPreset[];
63
- toJSON(pluginName?: string): FeatureJSON;
64
- }
@@ -1,79 +0,0 @@
1
- /**
2
- * AgentPreset — 插件声明的专长 Agent 预设
3
- *
4
- * 核心概念:
5
- * Tool = 单个 AI 可调用的能力(函数)
6
- * Skill = 一组相关 Tool + 发现元数据(SKILL.md)
7
- * Agent = 针对特定领域的 Agent 预设(*.agent.md)
8
- *
9
- * Agent 预设以标准 *.agent.md 文件提供,框架自动扫描发现。
10
- * 主 Agent(ZhinAgent)可根据用户请求自动委派给匹配的专长 Agent。
11
- */
12
- import { Feature } from '@zhin.js/kernel';
13
- export class AgentPresetFeature extends Feature {
14
- name = 'agentPreset';
15
- icon = 'Endpoint';
16
- desc = 'Agent 预设';
17
- byName = new Map();
18
- add(preset, pluginName) {
19
- this.byName.set(preset.name, preset);
20
- return super.add(preset, pluginName);
21
- }
22
- remove(preset, pluginName) {
23
- this.byName.delete(preset.name);
24
- return super.remove(preset, pluginName);
25
- }
26
- get(name) {
27
- return this.byName.get(name);
28
- }
29
- /** 清理所有预设注册(热重载时由 Plugin.stop() 调用) */
30
- dispose() {
31
- this.byName.clear();
32
- }
33
- getAll() {
34
- return [...this.items];
35
- }
36
- search(query, options) {
37
- const maxResults = options?.maxResults ?? 5;
38
- const lower = query.toLowerCase();
39
- const scored = this.items
40
- .map(preset => ({ preset, score: this.#scorePreset(preset, lower) }))
41
- .filter(({ score }) => score > 0)
42
- .sort((a, b) => b.score - a.score)
43
- .slice(0, maxResults);
44
- return scored.map(({ preset }) => preset);
45
- }
46
- #scorePreset(preset, query) {
47
- let score = 0;
48
- if (preset.name.toLowerCase().includes(query))
49
- score += 10;
50
- if (preset.description.toLowerCase().includes(query))
51
- score += 5;
52
- for (const kw of preset.keywords || []) {
53
- if (kw.toLowerCase().includes(query) || query.includes(kw.toLowerCase()))
54
- score += 8;
55
- }
56
- for (const tag of preset.tags || []) {
57
- if (tag.toLowerCase().includes(query))
58
- score += 3;
59
- }
60
- return score;
61
- }
62
- toJSON(pluginName) {
63
- const list = pluginName ? this.getByPlugin(pluginName) : this.items;
64
- return {
65
- name: this.name,
66
- icon: this.icon,
67
- desc: this.desc,
68
- count: list.length,
69
- items: list.map(p => ({
70
- name: p.name,
71
- desc: p.description,
72
- keywords: p.keywords,
73
- tags: p.tags,
74
- model: p.model,
75
- provider: p.provider,
76
- })),
77
- };
78
- }
79
- }
@@ -1,3 +0,0 @@
1
- import { type AiOutboundCapabilities, type AiOutboundExtensionDefinition } from './types.js';
2
- export declare function getAdapterAiOutboundCapabilities(adapterInstance: object): AiOutboundCapabilities;
3
- export declare function getAdapterAiOutboundExtensions(adapterInstance: object): readonly AiOutboundExtensionDefinition[];
@@ -1,9 +0,0 @@
1
- import { DEFAULT_AI_OUTBOUND_CAPABILITIES, } from './types.js';
2
- export function getAdapterAiOutboundCapabilities(adapterInstance) {
3
- const ctor = adapterInstance.constructor;
4
- return ctor.aiOutboundCapabilities ?? DEFAULT_AI_OUTBOUND_CAPABILITIES;
5
- }
6
- export function getAdapterAiOutboundExtensions(adapterInstance) {
7
- const ctor = adapterInstance.constructor;
8
- return ctor.aiOutboundExtensions ?? [];
9
- }
@@ -1,3 +0,0 @@
1
- import type { AiOutboundExtensionDefinition } from '../types.js';
2
- export declare const QQ_MARKDOWN_AI_OUTBOUND_EXTENSION: AiOutboundExtensionDefinition;
3
- export declare const QQ_AI_OUTBOUND_EXTENSIONS: readonly AiOutboundExtensionDefinition[];
@@ -1,23 +0,0 @@
1
- const QQ_MARKDOWN_SCHEMA = {
2
- type: 'object',
3
- properties: {
4
- content: { type: 'string' },
5
- },
6
- required: ['content'],
7
- };
8
- export const QQ_MARKDOWN_AI_OUTBOUND_EXTENSION = {
9
- key: 'qq.markdown',
10
- schema: QQ_MARKDOWN_SCHEMA,
11
- examples: ['{"extensions":{"qq.markdown":{"content":"# Title\\nBody"}}}'],
12
- toMessageElements(ext, _ctx) {
13
- if (!ext || typeof ext !== 'object')
14
- return [];
15
- const content = ext.content;
16
- if (typeof content !== 'string' || !content.trim())
17
- return [];
18
- return [{ type: 'markdown', data: { content: content.trim() } }];
19
- },
20
- };
21
- export const QQ_AI_OUTBOUND_EXTENSIONS = [
22
- QQ_MARKDOWN_AI_OUTBOUND_EXTENSION,
23
- ];
@@ -1,10 +0,0 @@
1
- /**
2
- * 授权重算 — ConfigFeature + Message 为单一真相源($sender.isMaster/isTrusted 为 enrich 快照)
3
- */
4
- import type { Plugin } from '../plugin.js';
5
- import type { Message } from '../message.js';
6
- import { type SenderRolesResult } from './ai-trigger.js';
7
- /**
8
- * 从 ConfigFeature + Message 重算发送者角色(含群角色与 master/trusted)
9
- */
10
- export declare function resolveSubjectRoles(plugin: Plugin, message: Message<any>): SenderRolesResult;
@@ -1,76 +0,0 @@
1
- import { mergeAITriggerConfig, resolveSenderRoles, } from './ai-trigger.js';
2
- import { formatCompact, getLogger } from '@zhin.js/logger';
3
- const logger = getLogger('Authorization');
4
- function findEndpointEntryFromConfig(config, adapter, endpointKey) {
5
- // 1) top-level endpoints[] (legacy / flat format)
6
- const topLevel = config.endpoints;
7
- if (Array.isArray(topLevel)) {
8
- const found = topLevel.find((b) => b.context === adapter && String(b.id) === endpointKey);
9
- if (found)
10
- return found;
11
- }
12
- // 2) plugins.<adapter> — adapter-level master/trusted + nested endpoints[]
13
- const adapterConfig = config.plugins?.[adapter];
14
- if (!adapterConfig)
15
- return undefined;
16
- const nested = adapterConfig.endpoints;
17
- const entry = Array.isArray(nested)
18
- ? nested.find((b) => String(b.id) === endpointKey)
19
- : undefined;
20
- // Merge adapter-level master/trusted onto the matched endpoint entry
21
- // so that resolveSenderRoles sees them in one place
22
- const merged = {
23
- context: adapter,
24
- ...(entry ?? { id: endpointKey }),
25
- };
26
- if (adapterConfig.master != null && merged.master == null) {
27
- merged.master = adapterConfig.master;
28
- }
29
- if (adapterConfig.trusted != null && merged.trusted == null) {
30
- merged.trusted = adapterConfig.trusted;
31
- }
32
- return merged;
33
- }
34
- function readTriggerConfig(plugin) {
35
- const root = plugin.root ?? plugin;
36
- try {
37
- const ai = root.inject('ai');
38
- if (ai?.getTriggerConfig)
39
- return ai.getTriggerConfig();
40
- }
41
- catch (e) {
42
- logger.debug(formatCompact({ auth: 'trigger_config_fallback', reason: 'ai_not_ready' }));
43
- }
44
- try {
45
- const configSvc = root.inject('config');
46
- const primary = configSvc?.getPrimary?.();
47
- return primary?.ai?.trigger ?? {};
48
- }
49
- catch (e) {
50
- logger.debug(formatCompact({ auth: 'trigger_config_read_error' }));
51
- return {};
52
- }
53
- }
54
- function readEndpointConfig(plugin, message) {
55
- const root = plugin.root ?? plugin;
56
- try {
57
- const configSvc = root.inject('config');
58
- const primary = configSvc?.getPrimary?.();
59
- if (!primary)
60
- return undefined;
61
- const entry = findEndpointEntryFromConfig(primary, String(message.$adapter), String(message.$endpoint));
62
- return entry;
63
- }
64
- catch (e) {
65
- logger.debug(formatCompact({ auth: 'endpoint_config_read_error' }));
66
- return undefined;
67
- }
68
- }
69
- /**
70
- * 从 ConfigFeature + Message 重算发送者角色(含群角色与 master/trusted)
71
- */
72
- export function resolveSubjectRoles(plugin, message) {
73
- const triggerConfig = mergeAITriggerConfig(readTriggerConfig(plugin));
74
- const endpointConfig = readEndpointConfig(plugin, message);
75
- return resolveSenderRoles(message, triggerConfig, endpointConfig);
76
- }
@@ -1,72 +0,0 @@
1
- /**
2
- * CommandFeature
3
- * 管理所有插件注册的命令,继承自 Feature 抽象类
4
- */
5
- import { Feature, FeatureJSON } from "@zhin.js/kernel";
6
- /** 命令 pattern 的首个词(用于前缀排序) */
7
- export declare function commandLeadingToken(pattern: string): string;
8
- /** 命令匹配优先级:首词越长越优先;同首词则完整 pattern 越长越优先 */
9
- export declare function compareCommandPatterns(a: string, b: string): number;
10
- import { MessageCommand } from "../command.js";
11
- import { Message } from "../message.js";
12
- import type { RegisteredAdapter, AdapterMessage } from "../types.js";
13
- import type { PermissionHost } from '@zhin.js/permission';
14
- /**
15
- * CommandContext 扩展方法类型
16
- */
17
- export interface CommandContextExtensions {
18
- /** @deprecated 使用 `defineCommand` + `commands/`;勿在新代码调用。 */
19
- addCommand<T extends RegisteredAdapter>(command: MessageCommand<T>): () => void;
20
- }
21
- declare module "../plugin.js" {
22
- namespace Plugin {
23
- interface Extensions extends CommandContextExtensions {
24
- }
25
- interface Contexts {
26
- command: CommandFeature;
27
- }
28
- }
29
- }
30
- /**
31
- * 命令服务 Feature(经典 MessageCommand 注册表)。
32
- *
33
- * @deprecated 新命令走 `@zhin.js/command` 的 `defineCommand` + 约定目录发现。
34
- * 本 Feature 仍服务 Agent / game-kit / legacy Plugin.addCommand。
35
- */
36
- export declare class CommandFeature extends Feature<MessageCommand<RegisteredAdapter>> {
37
- readonly name: "command";
38
- readonly icon = "Terminal";
39
- readonly desc = "\u547D\u4EE4";
40
- /** 按 pattern 索引 */
41
- readonly byName: Map<string, MessageCommand<"process">>;
42
- /**
43
- * 添加命令
44
- */
45
- add(command: MessageCommand<RegisteredAdapter>, pluginName: string): () => void;
46
- /**
47
- * 移除命令
48
- */
49
- remove(command: MessageCommand<RegisteredAdapter>): boolean;
50
- /**
51
- * 按 pattern 获取命令
52
- */
53
- get(pattern: string): MessageCommand<RegisteredAdapter> | undefined;
54
- /**
55
- * 处理消息,依次尝试匹配命令(较长前缀优先,避免 `teach` 抢 `teach-list`)
56
- */
57
- handle(message: Message<AdapterMessage<RegisteredAdapter>>, host: PermissionHost | null): Promise<any>;
58
- /**
59
- * 生命周期: 销毁时清理所有命令
60
- */
61
- dispose(): void;
62
- /**
63
- * 序列化为 JSON
64
- */
65
- toJSON(pluginName?: string): FeatureJSON;
66
- /**
67
- * 提供给 Plugin.prototype 的扩展方法
68
- */
69
- get extensions(): {
70
- addCommand<T extends RegisteredAdapter>(command: MessageCommand<T>): () => void;
71
- };
72
- }
@@ -1,105 +0,0 @@
1
- /**
2
- * CommandFeature
3
- * 管理所有插件注册的命令,继承自 Feature 抽象类
4
- */
5
- import { Feature } from "@zhin.js/kernel";
6
- /** 命令 pattern 的首个词(用于前缀排序) */
7
- export function commandLeadingToken(pattern) {
8
- return pattern.split(/\s/)[0] ?? "";
9
- }
10
- /** 命令匹配优先级:首词越长越优先;同首词则完整 pattern 越长越优先 */
11
- export function compareCommandPatterns(a, b) {
12
- const leadDiff = commandLeadingToken(b).length - commandLeadingToken(a).length;
13
- if (leadDiff !== 0)
14
- return leadDiff;
15
- const lenDiff = b.length - a.length;
16
- if (lenDiff !== 0)
17
- return lenDiff;
18
- const tokA = a.trim().split(/\s+/).length;
19
- const tokB = b.trim().split(/\s+/).length;
20
- return tokB - tokA;
21
- }
22
- /**
23
- * 命令服务 Feature(经典 MessageCommand 注册表)。
24
- *
25
- * @deprecated 新命令走 `@zhin.js/command` 的 `defineCommand` + 约定目录发现。
26
- * 本 Feature 仍服务 Agent / game-kit / legacy Plugin.addCommand。
27
- */
28
- export class CommandFeature extends Feature {
29
- name = 'command';
30
- icon = 'Terminal';
31
- desc = '命令';
32
- /** 按 pattern 索引 */
33
- byName = new Map();
34
- /**
35
- * 添加命令
36
- */
37
- add(command, pluginName) {
38
- this.byName.set(command.pattern, command);
39
- return super.add(command, pluginName);
40
- }
41
- /**
42
- * 移除命令
43
- */
44
- remove(command) {
45
- this.byName.delete(command.pattern);
46
- return super.remove(command);
47
- }
48
- /**
49
- * 按 pattern 获取命令
50
- */
51
- get(pattern) {
52
- return this.byName.get(pattern);
53
- }
54
- /**
55
- * 处理消息,依次尝试匹配命令(较长前缀优先,避免 `teach` 抢 `teach-list`)
56
- */
57
- async handle(message, host) {
58
- const commands = [...this.items].sort((a, b) => compareCommandPatterns(a.pattern, b.pattern));
59
- for (const command of commands) {
60
- const result = await command.handle(message, host);
61
- if (result)
62
- return result;
63
- }
64
- return null;
65
- }
66
- /**
67
- * 生命周期: 销毁时清理所有命令
68
- */
69
- dispose() {
70
- this.byName.clear();
71
- }
72
- /**
73
- * 序列化为 JSON
74
- */
75
- toJSON(pluginName) {
76
- const list = pluginName ? this.getByPlugin(pluginName) : this.items;
77
- return {
78
- name: this.name,
79
- icon: this.icon,
80
- desc: this.desc,
81
- count: list.length,
82
- items: list.map(c => ({
83
- name: c.pattern,
84
- desc: c.helpInfo?.desc,
85
- usage: c.helpInfo?.usage,
86
- examples: c.helpInfo?.examples,
87
- })),
88
- };
89
- }
90
- /**
91
- * 提供给 Plugin.prototype 的扩展方法
92
- */
93
- get extensions() {
94
- const feature = this;
95
- return {
96
- addCommand(command) {
97
- const plugin = this;
98
- const dispose = feature.add(command, plugin.name);
99
- plugin.recordFeatureContribution(feature.name, command.pattern);
100
- plugin.onDispose(dispose);
101
- return dispose;
102
- },
103
- };
104
- }
105
- }
@@ -1,67 +0,0 @@
1
- /**
2
- * ComponentFeature
3
- * 管理所有插件注册的组件,继承自 Feature 抽象类
4
- */
5
- import { Feature, FeatureJSON, type PluginLike } from '@zhin.js/kernel';
6
- import { Component } from "../component.js";
7
- /**
8
- * ComponentContext 扩展方法类型
9
- */
10
- export interface ComponentContextExtensions {
11
- /** 添加组件 */
12
- addComponent<T extends Component<any>>(component: T): () => void;
13
- }
14
- declare module "../plugin.js" {
15
- namespace Plugin {
16
- interface Extensions extends ComponentContextExtensions {
17
- }
18
- interface Contexts {
19
- component: ComponentFeature;
20
- }
21
- }
22
- }
23
- /**
24
- * 组件服务 Feature
25
- */
26
- export declare class ComponentFeature extends Feature<Component<any>> {
27
- #private;
28
- readonly name: "component";
29
- readonly icon = "Box";
30
- readonly desc = "\u7EC4\u4EF6";
31
- /** 按名称索引 */
32
- readonly byName: Map<string, Component<any>>;
33
- /**
34
- * 添加组件
35
- */
36
- add(component: Component<any>, pluginName: string): () => void;
37
- /**
38
- * 移除组件
39
- */
40
- remove(component: Component<any>): boolean;
41
- /**
42
- * 获取所有组件名称
43
- */
44
- getAllNames(): string[];
45
- /**
46
- * 按名称获取组件
47
- */
48
- get(name: string): Component<any> | undefined;
49
- /**
50
- * 生命周期: 挂载时注册消息渲染监听器
51
- */
52
- mounted(plugin: PluginLike): void;
53
- /**
54
- * 生命周期: 销毁时移除监听器
55
- */
56
- dispose(): void;
57
- /**
58
- * 序列化为 JSON
59
- */
60
- toJSON(pluginName?: string): FeatureJSON;
61
- /**
62
- * 提供给 Plugin.prototype 的扩展方法
63
- */
64
- get extensions(): {
65
- addComponent<T extends Component<any>>(component: T): () => void;
66
- };
67
- }