@rudderhq/server 0.7.2 → 0.7.4

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 (512) hide show
  1. package/dist/agent-runtimes/registry.d.ts.map +1 -1
  2. package/dist/agent-runtimes/registry.js +0 -2
  3. package/dist/agent-runtimes/registry.js.map +1 -1
  4. package/dist/app.d.ts.map +1 -1
  5. package/dist/app.js +1 -5
  6. package/dist/app.js.map +1 -1
  7. package/dist/bootstrap/create-http-app.d.ts +1 -2
  8. package/dist/bootstrap/create-http-app.d.ts.map +1 -1
  9. package/dist/bootstrap/create-http-app.js +13 -12
  10. package/dist/bootstrap/create-http-app.js.map +1 -1
  11. package/dist/bootstrap/register-api-routes.d.ts +1 -2
  12. package/dist/bootstrap/register-api-routes.d.ts.map +1 -1
  13. package/dist/bootstrap/register-api-routes.js +22 -4
  14. package/dist/bootstrap/register-api-routes.js.map +1 -1
  15. package/dist/index.js +2 -0
  16. package/dist/index.js.map +1 -1
  17. package/dist/middleware/logger.js +2 -2
  18. package/dist/middleware/logger.js.map +1 -1
  19. package/dist/middleware/logger.test.js +26 -10
  20. package/dist/middleware/logger.test.js.map +1 -1
  21. package/dist/redaction.d.ts +4 -0
  22. package/dist/redaction.d.ts.map +1 -1
  23. package/dist/redaction.js +15 -0
  24. package/dist/redaction.js.map +1 -1
  25. package/dist/routes/agent-issue-creation.d.ts +25 -0
  26. package/dist/routes/agent-issue-creation.d.ts.map +1 -0
  27. package/dist/routes/agent-issue-creation.js +201 -0
  28. package/dist/routes/agent-issue-creation.js.map +1 -0
  29. package/dist/routes/app-builder.d.ts +3 -1
  30. package/dist/routes/app-builder.d.ts.map +1 -1
  31. package/dist/routes/app-builder.js +30 -22
  32. package/dist/routes/app-builder.js.map +1 -1
  33. package/dist/routes/approvals.d.ts.map +1 -1
  34. package/dist/routes/approvals.js +36 -9
  35. package/dist/routes/approvals.js.map +1 -1
  36. package/dist/routes/chats.d.ts.map +1 -1
  37. package/dist/routes/chats.js +23 -4
  38. package/dist/routes/chats.js.map +1 -1
  39. package/dist/routes/chats.preflight.d.ts +2 -1
  40. package/dist/routes/chats.preflight.d.ts.map +1 -1
  41. package/dist/routes/chats.preflight.js +7 -0
  42. package/dist/routes/chats.preflight.js.map +1 -1
  43. package/dist/routes/chats.stream-routes.d.ts.map +1 -1
  44. package/dist/routes/chats.stream-routes.js +14 -3
  45. package/dist/routes/chats.stream-routes.js.map +1 -1
  46. package/dist/routes/chats.stream-support.d.ts.map +1 -1
  47. package/dist/routes/chats.stream-support.js +8 -0
  48. package/dist/routes/chats.stream-support.js.map +1 -1
  49. package/dist/routes/computer.d.ts +30 -0
  50. package/dist/routes/computer.d.ts.map +1 -0
  51. package/dist/routes/computer.js +231 -0
  52. package/dist/routes/computer.js.map +1 -0
  53. package/dist/routes/goals.d.ts.map +1 -1
  54. package/dist/routes/goals.js +176 -27
  55. package/dist/routes/goals.js.map +1 -1
  56. package/dist/routes/health.d.ts.map +1 -1
  57. package/dist/routes/health.js +2 -0
  58. package/dist/routes/health.js.map +1 -1
  59. package/dist/routes/index.d.ts +1 -0
  60. package/dist/routes/index.d.ts.map +1 -1
  61. package/dist/routes/index.js +1 -0
  62. package/dist/routes/index.js.map +1 -1
  63. package/dist/routes/instance-settings.d.ts.map +1 -1
  64. package/dist/routes/instance-settings.js +3 -0
  65. package/dist/routes/instance-settings.js.map +1 -1
  66. package/dist/routes/issues.comments-attachments.d.ts.map +1 -1
  67. package/dist/routes/issues.comments-attachments.js +90 -8
  68. package/dist/routes/issues.comments-attachments.js.map +1 -1
  69. package/dist/routes/issues.d.ts.map +1 -1
  70. package/dist/routes/issues.js +14 -2
  71. package/dist/routes/issues.js.map +1 -1
  72. package/dist/routes/issues.mutations.d.ts.map +1 -1
  73. package/dist/routes/issues.mutations.js +206 -52
  74. package/dist/routes/issues.mutations.js.map +1 -1
  75. package/dist/routes/managed-mcp-runtime.d.ts.map +1 -1
  76. package/dist/routes/managed-mcp-runtime.js +109 -7
  77. package/dist/routes/managed-mcp-runtime.js.map +1 -1
  78. package/dist/routes/organization-skills.d.ts.map +1 -1
  79. package/dist/routes/organization-skills.js +23 -1
  80. package/dist/routes/organization-skills.js.map +1 -1
  81. package/dist/routes/requests.d.ts +3 -0
  82. package/dist/routes/requests.d.ts.map +1 -0
  83. package/dist/routes/requests.js +122 -0
  84. package/dist/routes/requests.js.map +1 -0
  85. package/dist/routes/rudder-plugins.d.ts +4 -0
  86. package/dist/routes/rudder-plugins.d.ts.map +1 -0
  87. package/dist/routes/rudder-plugins.js +203 -0
  88. package/dist/routes/rudder-plugins.js.map +1 -0
  89. package/dist/services/activity-log.d.ts +0 -3
  90. package/dist/services/activity-log.d.ts.map +1 -1
  91. package/dist/services/activity-log.js +19 -42
  92. package/dist/services/activity-log.js.map +1 -1
  93. package/dist/services/activity.d.ts +3 -3
  94. package/dist/services/agent-issue-creation.d.ts +344 -0
  95. package/dist/services/agent-issue-creation.d.ts.map +1 -0
  96. package/dist/services/agent-issue-creation.js +675 -0
  97. package/dist/services/agent-issue-creation.js.map +1 -0
  98. package/dist/services/agent-run-context.d.ts.map +1 -1
  99. package/dist/services/agent-run-context.js +10 -4
  100. package/dist/services/agent-run-context.js.map +1 -1
  101. package/dist/services/agents.d.ts +14 -14
  102. package/dist/services/agents.d.ts.map +1 -1
  103. package/dist/services/agents.js +2 -1
  104. package/dist/services/agents.js.map +1 -1
  105. package/dist/services/app-builder.d.ts.map +1 -1
  106. package/dist/services/app-builder.js +24 -3
  107. package/dist/services/app-builder.js.map +1 -1
  108. package/dist/services/chat-agent-runs.d.ts +1 -0
  109. package/dist/services/chat-agent-runs.d.ts.map +1 -1
  110. package/dist/services/chat-agent-runs.js +1 -0
  111. package/dist/services/chat-agent-runs.js.map +1 -1
  112. package/dist/services/chat-assistant.d.ts.map +1 -1
  113. package/dist/services/chat-assistant.helpers.d.ts +3 -1
  114. package/dist/services/chat-assistant.helpers.d.ts.map +1 -1
  115. package/dist/services/chat-assistant.helpers.js +25 -0
  116. package/dist/services/chat-assistant.helpers.js.map +1 -1
  117. package/dist/services/chat-assistant.js +57 -11
  118. package/dist/services/chat-assistant.js.map +1 -1
  119. package/dist/services/chat-generation-protocol.test.js +2 -2
  120. package/dist/services/chat-generation-protocol.test.js.map +1 -1
  121. package/dist/services/chat-queued-message-materialization.d.ts +1 -1
  122. package/dist/services/chats.create.d.ts +2 -2
  123. package/dist/services/chats.create.d.ts.map +1 -1
  124. package/dist/services/chats.d.ts +15 -15
  125. package/dist/services/chats.d.ts.map +1 -1
  126. package/dist/services/chats.helpers.d.ts +2 -2
  127. package/dist/services/chats.helpers.d.ts.map +1 -1
  128. package/dist/services/chats.helpers.goal-context.test.d.ts +2 -0
  129. package/dist/services/chats.helpers.goal-context.test.d.ts.map +1 -0
  130. package/dist/services/chats.helpers.goal-context.test.js +40 -0
  131. package/dist/services/chats.helpers.goal-context.test.js.map +1 -0
  132. package/dist/services/chats.helpers.js +27 -2
  133. package/dist/services/chats.helpers.js.map +1 -1
  134. package/dist/services/chats.js.map +1 -1
  135. package/dist/services/computer-broker.d.ts +35 -0
  136. package/dist/services/computer-broker.d.ts.map +1 -0
  137. package/dist/services/computer-broker.js +211 -0
  138. package/dist/services/computer-broker.js.map +1 -0
  139. package/dist/services/computer-broker.test.d.ts +2 -0
  140. package/dist/services/computer-broker.test.d.ts.map +1 -0
  141. package/dist/services/computer-broker.test.js +70 -0
  142. package/dist/services/computer-broker.test.js.map +1 -0
  143. package/dist/services/computer-capability.d.ts +13 -0
  144. package/dist/services/computer-capability.d.ts.map +1 -0
  145. package/dist/services/computer-capability.js +11 -0
  146. package/dist/services/computer-capability.js.map +1 -0
  147. package/dist/services/computer-capability.test.d.ts +2 -0
  148. package/dist/services/computer-capability.test.d.ts.map +1 -0
  149. package/dist/services/computer-capability.test.js +27 -0
  150. package/dist/services/computer-capability.test.js.map +1 -0
  151. package/dist/services/finance.d.ts +2 -2
  152. package/dist/services/goals.d.ts +267 -244
  153. package/dist/services/goals.d.ts.map +1 -1
  154. package/dist/services/goals.js +1279 -297
  155. package/dist/services/goals.js.map +1 -1
  156. package/dist/services/index.d.ts +3 -0
  157. package/dist/services/index.d.ts.map +1 -1
  158. package/dist/services/index.js +3 -0
  159. package/dist/services/index.js.map +1 -1
  160. package/dist/services/instance-settings.d.ts.map +1 -1
  161. package/dist/services/instance-settings.js +8 -3
  162. package/dist/services/instance-settings.js.map +1 -1
  163. package/dist/services/integrations/agent-integrations.d.ts +1 -1
  164. package/dist/services/issues.d.ts +86 -1
  165. package/dist/services/issues.d.ts.map +1 -1
  166. package/dist/services/issues.helpers.d.ts +4 -0
  167. package/dist/services/issues.helpers.d.ts.map +1 -1
  168. package/dist/services/issues.helpers.js +28 -6
  169. package/dist/services/issues.helpers.js.map +1 -1
  170. package/dist/services/issues.js +207 -127
  171. package/dist/services/issues.js.map +1 -1
  172. package/dist/services/knowledge-portability/organization-portability.files.d.ts +1 -1
  173. package/dist/services/knowledge-portability/organization-skills.catalog.d.ts +7 -1
  174. package/dist/services/knowledge-portability/organization-skills.catalog.d.ts.map +1 -1
  175. package/dist/services/knowledge-portability/organization-skills.catalog.js +10 -0
  176. package/dist/services/knowledge-portability/organization-skills.catalog.js.map +1 -1
  177. package/dist/services/knowledge-portability/organization-skills.d.ts +3 -1
  178. package/dist/services/knowledge-portability/organization-skills.d.ts.map +1 -1
  179. package/dist/services/knowledge-portability/organization-skills.js +80 -12
  180. package/dist/services/knowledge-portability/organization-skills.js.map +1 -1
  181. package/dist/services/mcp/managed-bindings.d.ts.map +1 -1
  182. package/dist/services/mcp/managed-bindings.js +18 -2
  183. package/dist/services/mcp/managed-bindings.js.map +1 -1
  184. package/dist/services/mcp/managed-client.d.ts +15 -0
  185. package/dist/services/mcp/managed-client.d.ts.map +1 -1
  186. package/dist/services/mcp/managed-client.js +23 -1
  187. package/dist/services/mcp/managed-client.js.map +1 -1
  188. package/dist/services/mcp/managed-client.test.js +73 -9
  189. package/dist/services/mcp/managed-client.test.js.map +1 -1
  190. package/dist/services/messenger.d.ts +3 -3
  191. package/dist/services/messenger.d.ts.map +1 -1
  192. package/dist/services/messenger.js +201 -65
  193. package/dist/services/messenger.js.map +1 -1
  194. package/dist/services/orgs.d.ts.map +1 -1
  195. package/dist/services/orgs.js +3 -1
  196. package/dist/services/orgs.js.map +1 -1
  197. package/dist/services/product-analytics.d.ts +2 -2
  198. package/dist/services/requests.d.ts +919 -0
  199. package/dist/services/requests.d.ts.map +1 -0
  200. package/dist/services/requests.js +532 -0
  201. package/dist/services/requests.js.map +1 -0
  202. package/dist/services/rudder-plugins.d.ts +107 -0
  203. package/dist/services/rudder-plugins.d.ts.map +1 -0
  204. package/dist/services/rudder-plugins.js +1760 -0
  205. package/dist/services/rudder-plugins.js.map +1 -0
  206. package/dist/services/rudder-plugins.test.d.ts +2 -0
  207. package/dist/services/rudder-plugins.test.d.ts.map +1 -0
  208. package/dist/services/rudder-plugins.test.js +191 -0
  209. package/dist/services/rudder-plugins.test.js.map +1 -0
  210. package/dist/services/runtime-kernel/heartbeat.core.d.ts +1 -0
  211. package/dist/services/runtime-kernel/heartbeat.core.d.ts.map +1 -1
  212. package/dist/services/runtime-kernel/heartbeat.core.js +1 -1
  213. package/dist/services/runtime-kernel/heartbeat.core.js.map +1 -1
  214. package/dist/services/runtime-kernel/heartbeat.d.ts +65 -0
  215. package/dist/services/runtime-kernel/heartbeat.d.ts.map +1 -1
  216. package/dist/services/runtime-kernel/heartbeat.execute.d.ts.map +1 -1
  217. package/dist/services/runtime-kernel/heartbeat.execute.js +21 -5
  218. package/dist/services/runtime-kernel/heartbeat.execute.js.map +1 -1
  219. package/dist/services/runtime-kernel/heartbeat.js +320 -108
  220. package/dist/services/runtime-kernel/heartbeat.js.map +1 -1
  221. package/dist/services/runtime-kernel/heartbeat.recovery.d.ts +1 -0
  222. package/dist/services/runtime-kernel/heartbeat.recovery.d.ts.map +1 -1
  223. package/dist/services/runtime-kernel/heartbeat.recovery.js +39 -4
  224. package/dist/services/runtime-kernel/heartbeat.recovery.js.map +1 -1
  225. package/dist/services/runtime-kernel/heartbeat.sessions.js +1 -1
  226. package/dist/services/runtime-kernel/heartbeat.sessions.js.map +1 -1
  227. package/dist/services/runtime-kernel/heartbeat.terminal.d.ts +14 -1
  228. package/dist/services/runtime-kernel/heartbeat.terminal.d.ts.map +1 -1
  229. package/dist/services/runtime-kernel/heartbeat.terminal.js +46 -1
  230. package/dist/services/runtime-kernel/heartbeat.terminal.js.map +1 -1
  231. package/dist/services/runtime-kernel/heartbeat.wakeup.d.ts +1 -0
  232. package/dist/services/runtime-kernel/heartbeat.wakeup.d.ts.map +1 -1
  233. package/dist/services/runtime-kernel/heartbeat.wakeup.js +124 -6
  234. package/dist/services/runtime-kernel/heartbeat.wakeup.js.map +1 -1
  235. package/dist/services/workspace-runtime.services.d.ts +1 -1
  236. package/package.json +18 -18
  237. package/resources/bundled-skills/app-builder/SKILL.md +39 -9
  238. package/resources/bundled-skills/app-builder/assets/scaffold/app/globals.css +109 -16
  239. package/resources/bundled-skills/app-builder/assets/scaffold/components/contacts-workspace.tsx +176 -152
  240. package/resources/bundled-skills/app-builder/assets/scaffold/components/ui/alert.tsx +12 -0
  241. package/resources/bundled-skills/app-builder/assets/scaffold/components/ui/badge.tsx +27 -0
  242. package/resources/bundled-skills/app-builder/assets/scaffold/components/ui/button.tsx +9 -7
  243. package/resources/bundled-skills/app-builder/assets/scaffold/components/ui/card.tsx +15 -3
  244. package/resources/bundled-skills/app-builder/assets/scaffold/components/ui/empty.tsx +18 -0
  245. package/resources/bundled-skills/app-builder/assets/scaffold/components/ui/field.tsx +23 -0
  246. package/resources/bundled-skills/app-builder/assets/scaffold/components/ui/input.tsx +1 -1
  247. package/resources/bundled-skills/app-builder/assets/scaffold/components/ui/label.tsx +1 -1
  248. package/resources/bundled-skills/app-builder/assets/scaffold/components/ui/separator.tsx +6 -0
  249. package/resources/bundled-skills/app-builder/assets/scaffold/components/ui/skeleton.tsx +6 -0
  250. package/resources/bundled-skills/app-builder/assets/scaffold/components/ui/table.tsx +30 -0
  251. package/resources/bundled-skills/app-builder/assets/scaffold/components.json +20 -0
  252. package/resources/bundled-skills/app-builder/assets/scaffold/next-env.d.ts +1 -1
  253. package/resources/bundled-skills/app-builder/assets/scaffold/next.config.ts +19 -0
  254. package/resources/bundled-skills/app-builder/assets/scaffold/package.json +2 -1
  255. package/resources/bundled-skills/app-builder/assets/scaffold/rudder.app.json +1 -1
  256. package/resources/bundled-skills/app-builder/assets/scaffold/rudder.ui.json +13 -0
  257. package/resources/bundled-skills/app-builder/assets/scaffold/scripts/validate-rudder-ui.mjs +50 -0
  258. package/resources/bundled-skills/app-builder/assets/scaffold/tests/e2e/app.spec.ts +35 -1
  259. package/resources/bundled-skills/app-builder/evals/evals.json +2 -1
  260. package/resources/bundled-skills/app-builder/references/design-guidelines.md +19 -2
  261. package/resources/bundled-skills/app-builder/references/rudder-ui-preset.md +73 -0
  262. package/resources/bundled-skills/app-builder/references/scaffold-contract.md +12 -0
  263. package/resources/bundled-skills/app-builder/references/verification.md +6 -0
  264. package/resources/bundled-skills/app-builder/scripts/report-build-status.mjs +83 -0
  265. package/resources/bundled-skills/rudder-docs/SKILL.md +2 -2
  266. package/resources/bundled-skills/rudder-docs/evals/retrieval-authority-evals.json +40 -0
  267. package/resources/bundled-skills/rudder-docs/evals/trigger-evals.json +2 -2
  268. package/resources/bundled-skills/rudder-docs/references/api-reference.md +0 -2
  269. package/resources/bundled-skills/rudder-docs/references/cli-reference.md +7 -2
  270. package/resources/bundled-skills/rudder-docs/references/operating-practices.md +10 -6
  271. package/resources/bundled-skills/rudder-docs/references/plugin-authoring.md +38 -114
  272. package/resources/bundled-skills/rudder-docs/references/source-map.md +2 -0
  273. package/skills/app-builder/SKILL.md +39 -9
  274. package/skills/app-builder/assets/scaffold/app/globals.css +109 -16
  275. package/skills/app-builder/assets/scaffold/components/contacts-workspace.tsx +176 -152
  276. package/skills/app-builder/assets/scaffold/components/ui/alert.tsx +12 -0
  277. package/skills/app-builder/assets/scaffold/components/ui/badge.tsx +27 -0
  278. package/skills/app-builder/assets/scaffold/components/ui/button.tsx +9 -7
  279. package/skills/app-builder/assets/scaffold/components/ui/card.tsx +15 -3
  280. package/skills/app-builder/assets/scaffold/components/ui/empty.tsx +18 -0
  281. package/skills/app-builder/assets/scaffold/components/ui/field.tsx +23 -0
  282. package/skills/app-builder/assets/scaffold/components/ui/input.tsx +1 -1
  283. package/skills/app-builder/assets/scaffold/components/ui/label.tsx +1 -1
  284. package/skills/app-builder/assets/scaffold/components/ui/separator.tsx +6 -0
  285. package/skills/app-builder/assets/scaffold/components/ui/skeleton.tsx +6 -0
  286. package/skills/app-builder/assets/scaffold/components/ui/table.tsx +30 -0
  287. package/skills/app-builder/assets/scaffold/components.json +20 -0
  288. package/skills/app-builder/assets/scaffold/next-env.d.ts +1 -1
  289. package/skills/app-builder/assets/scaffold/next.config.ts +19 -0
  290. package/skills/app-builder/assets/scaffold/package.json +2 -1
  291. package/skills/app-builder/assets/scaffold/rudder.app.json +1 -1
  292. package/skills/app-builder/assets/scaffold/rudder.ui.json +13 -0
  293. package/skills/app-builder/assets/scaffold/scripts/validate-rudder-ui.mjs +50 -0
  294. package/skills/app-builder/assets/scaffold/tests/e2e/app.spec.ts +35 -1
  295. package/skills/app-builder/evals/evals.json +2 -1
  296. package/skills/app-builder/references/design-guidelines.md +19 -2
  297. package/skills/app-builder/references/rudder-ui-preset.md +73 -0
  298. package/skills/app-builder/references/scaffold-contract.md +12 -0
  299. package/skills/app-builder/references/verification.md +6 -0
  300. package/skills/app-builder/scripts/report-build-status.mjs +83 -0
  301. package/skills/rudder-docs/SKILL.md +2 -2
  302. package/skills/rudder-docs/evals/retrieval-authority-evals.json +40 -0
  303. package/skills/rudder-docs/evals/trigger-evals.json +2 -2
  304. package/skills/rudder-docs/references/api-reference.md +0 -2
  305. package/skills/rudder-docs/references/cli-reference.md +7 -2
  306. package/skills/rudder-docs/references/operating-practices.md +10 -6
  307. package/skills/rudder-docs/references/plugin-authoring.md +38 -114
  308. package/skills/rudder-docs/references/source-map.md +2 -0
  309. package/ui-dist/assets/{LibraryLiveSurface-cHCJmmsl.js → LibraryLiveSurface-D4uCo0l0.js} +1 -1
  310. package/ui-dist/assets/{abnfDiagram-VRR7QNED-BORJvkew.js → abnfDiagram-VRR7QNED-FF2qcR6A.js} +1 -1
  311. package/ui-dist/assets/addon-fit-4gL7JXzc.js +1 -0
  312. package/ui-dist/assets/{arc-DPUzhx87.js → arc-D5pLjh6B.js} +1 -1
  313. package/ui-dist/assets/{architectureDiagram-ZJ3FMSHR-Bz_hY8LM.js → architectureDiagram-ZJ3FMSHR-BvqY-HXg.js} +1 -1
  314. package/ui-dist/assets/{blockDiagram-677ZJIJ3-Bq1X3YkP.js → blockDiagram-677ZJIJ3-BU6ZbJ0s.js} +1 -1
  315. package/ui-dist/assets/{c4Diagram-LMCZKHZV-BawEM9Pc.js → c4Diagram-LMCZKHZV-Cl5Gsovj.js} +1 -1
  316. package/ui-dist/assets/channel-HcmprA3I.js +1 -0
  317. package/ui-dist/assets/{chunk-2Q5K7J3B-D0D5ZOaA.js → chunk-2Q5K7J3B-4a2agt_p.js} +1 -1
  318. package/ui-dist/assets/{chunk-32BRIVSS-T90P7lug.js → chunk-32BRIVSS-CF0oOO2T.js} +1 -1
  319. package/ui-dist/assets/{chunk-5VM5RSS4-jcAERTgh.js → chunk-5VM5RSS4-CsSq2zX2.js} +1 -1
  320. package/ui-dist/assets/{chunk-EX3LRPZG-t9-JXwnR.js → chunk-EX3LRPZG-B6riETVZ.js} +1 -1
  321. package/ui-dist/assets/{chunk-JWPE2WC7-hqgD1saC.js → chunk-JWPE2WC7-S-p1xu0r.js} +1 -1
  322. package/ui-dist/assets/{chunk-MOJQB5TN-BsSUoYzd.js → chunk-MOJQB5TN-mVE4v_LV.js} +1 -1
  323. package/ui-dist/assets/{chunk-RYQCIY6F-YcdDh2Zn.js → chunk-RYQCIY6F-CElbgpgs.js} +1 -1
  324. package/ui-dist/assets/{chunk-V7JOEXUC-ChFyH9Su.js → chunk-V7JOEXUC-8XM3povP.js} +1 -1
  325. package/ui-dist/assets/{chunk-VR4S4FIN-BjVK8IyX.js → chunk-VR4S4FIN-LrThp3ht.js} +1 -1
  326. package/ui-dist/assets/{chunk-XXDRQBXY-D-TvO9vT.js → chunk-XXDRQBXY-D38vLb4t.js} +1 -1
  327. package/ui-dist/assets/classDiagram-OUVF2IWQ-Dpe8LaLf.js +1 -0
  328. package/ui-dist/assets/classDiagram-v2-EOCWNBFH-Dpe8LaLf.js +1 -0
  329. package/ui-dist/assets/{cose-bilkent-JH36ORCC-DBwhASJG.js → cose-bilkent-JH36ORCC-CmpZMaDV.js} +1 -1
  330. package/ui-dist/assets/{cynefin-VYW2F7L2-SlCRmwl2.js → cynefin-VYW2F7L2-D3RnbBvI.js} +1 -1
  331. package/ui-dist/assets/{cynefinDiagram-TSTJHNR4-DImV6N_p.js → cynefinDiagram-TSTJHNR4-DZTcUojp.js} +1 -1
  332. package/ui-dist/assets/{dagre-VKFMJZFB-FH4Wv8Zn.js → dagre-VKFMJZFB-6jXSDi0S.js} +1 -1
  333. package/ui-dist/assets/{diagram-FQU43EPY-CrZvQjId.js → diagram-FQU43EPY-DIMm3mfS.js} +1 -1
  334. package/ui-dist/assets/{diagram-G47NLZAW-B7IGl_T3.js → diagram-G47NLZAW-Cyo22v0_.js} +1 -1
  335. package/ui-dist/assets/{diagram-NH7WQ7WH-CB4i7H1a.js → diagram-NH7WQ7WH-CHDV0nSL.js} +1 -1
  336. package/ui-dist/assets/{diagram-OA4YK3LP-DNyWPYY9.js → diagram-OA4YK3LP-Jijx9vQO.js} +1 -1
  337. package/ui-dist/assets/{diagram-WEI45ONY-BAhxbhpi.js → diagram-WEI45ONY-CcL19HLE.js} +1 -1
  338. package/ui-dist/assets/{ebnfDiagram-CCIWWBDH-ClXtQ9qt.js → ebnfDiagram-CCIWWBDH-D94h-RFQ.js} +1 -1
  339. package/ui-dist/assets/{erDiagram-Q63AITRT-DGXiMYfn.js → erDiagram-Q63AITRT-B3ypUGZX.js} +1 -1
  340. package/ui-dist/assets/{flowDiagram-23GEKE2U-CdZ-02zc.js → flowDiagram-23GEKE2U-DjCT6Y1o.js} +1 -1
  341. package/ui-dist/assets/{ganttDiagram-NO4QXBWP-TxhzNpta.js → ganttDiagram-NO4QXBWP-C3QVhTc9.js} +1 -1
  342. package/ui-dist/assets/{gitGraphDiagram-IHSO6WYX-D6Q_w6wR.js → gitGraphDiagram-IHSO6WYX-D0trBzU5.js} +1 -1
  343. package/ui-dist/assets/{graph-CxNmbpl9.js → graph-D1zFmVUP.js} +1 -1
  344. package/ui-dist/assets/{index-Cx6oIZPm.js → index-B0GEsWui.js} +568 -593
  345. package/ui-dist/assets/{index-BA9tMBhO.js → index-B8bxQLfN.js} +1 -1
  346. package/ui-dist/assets/{index-C_nwI4Yj.js → index-BFktZ2tu.js} +1 -1
  347. package/ui-dist/assets/index-BT7dphT4.css +32 -0
  348. package/ui-dist/assets/{index-BoTz5S-X.js → index-Bk_yesiO.js} +1 -1
  349. package/ui-dist/assets/{index-CXnqg1Oq.js → index-BwutQLG1.js} +1 -1
  350. package/ui-dist/assets/{index-AkhgKOxC.js → index-CB4zr_Ku.js} +1 -1
  351. package/ui-dist/assets/{index-Rau2cGm0.js → index-CC89UPa-.js} +1 -1
  352. package/ui-dist/assets/{index-kbWUQ1um.js → index-CFWOO6yn.js} +1 -1
  353. package/ui-dist/assets/{index-DU2LI7f9.js → index-CK8u9b07.js} +1 -1
  354. package/ui-dist/assets/{index-C12QC1Ex.js → index-CRolpP90.js} +1 -1
  355. package/ui-dist/assets/{index-Bxz75ICF.js → index-CiCRRUVV.js} +1 -1
  356. package/ui-dist/assets/{index-Do78GymY.js → index-D8JG-IU9.js} +1 -1
  357. package/ui-dist/assets/{index-CW21qWFm.js → index-DKCiVvJo.js} +1 -1
  358. package/ui-dist/assets/{index-BujwWE3j.js → index-G2yfKEf_.js} +1 -1
  359. package/ui-dist/assets/{index-BQ87dGIq.js → index-or2C22bw.js} +1 -1
  360. package/ui-dist/assets/{infoDiagram-FWYZ7A6U-CnJd4-Jq.js → infoDiagram-FWYZ7A6U-Co0nkcV4.js} +1 -1
  361. package/ui-dist/assets/{ishikawaDiagram-FXEZZL3T-Bq-qc3pD.js → ishikawaDiagram-FXEZZL3T-CkIg1Jdu.js} +1 -1
  362. package/ui-dist/assets/{journeyDiagram-5HDEW3XC-NSmpUGUA.js → journeyDiagram-5HDEW3XC-AYUT6JuJ.js} +1 -1
  363. package/ui-dist/assets/{kanban-definition-HUTT4EX6-D7pgWtfA.js → kanban-definition-HUTT4EX6-C3H2XW08.js} +1 -1
  364. package/ui-dist/assets/{layout-BRuo6LWe.js → layout-sZWyqNOu.js} +1 -1
  365. package/ui-dist/assets/{linear-CkaWI9Nd.js → linear-BLTYou8N.js} +1 -1
  366. package/ui-dist/assets/{map-CgA6tTpZ.js → map-zKBdHkX8.js} +1 -1
  367. package/ui-dist/assets/{mermaid.core-DrXOt-P6.js → mermaid.core-DbjdFip8.js} +4 -4
  368. package/ui-dist/assets/{mindmap-definition-LN4V7U3C-D9ImeWBe.js → mindmap-definition-LN4V7U3C-DcDNQ4GQ.js} +1 -1
  369. package/ui-dist/assets/{pegDiagram-2B236MQR-Cq-zZ_zz.js → pegDiagram-2B236MQR-BGq1PngU.js} +1 -1
  370. package/ui-dist/assets/{pieDiagram-ENE6RG2P-FgNgy726.js → pieDiagram-ENE6RG2P-BfXWRzNb.js} +1 -1
  371. package/ui-dist/assets/{quadrantDiagram-ABIIQ3AL-BxQbmGmi.js → quadrantDiagram-ABIIQ3AL-AYMVAbo1.js} +1 -1
  372. package/ui-dist/assets/{railroadDiagram-RFXS5EU6-CrpbkPH2.js → railroadDiagram-RFXS5EU6-B0PoG0Ih.js} +1 -1
  373. package/ui-dist/assets/{requirementDiagram-TGXJPOKE-DQ-65ZW6.js → requirementDiagram-TGXJPOKE-Cuuu9wfw.js} +1 -1
  374. package/ui-dist/assets/{sankeyDiagram-HTMAVEWB-Bom0lMZm.js → sankeyDiagram-HTMAVEWB-BceAc42f.js} +1 -1
  375. package/ui-dist/assets/{sequenceDiagram-DBY2YBRQ-C1MSDLDj.js → sequenceDiagram-DBY2YBRQ-cqJ71-Rw.js} +1 -1
  376. package/ui-dist/assets/{sizeCapture-X5ZJPWSS-Bn1vxebD.js → sizeCapture-X5ZJPWSS-DQ6MibbA.js} +1 -1
  377. package/ui-dist/assets/{stateDiagram-2N3HPSRC-GRRQpmzI.js → stateDiagram-2N3HPSRC-Bdl-XY7t.js} +1 -1
  378. package/ui-dist/assets/stateDiagram-v2-6OUMAXLB-Cjj7yPIO.js +1 -0
  379. package/ui-dist/assets/{swimlanes-5IMT3BWC-BcOOCZ4q.js → swimlanes-5IMT3BWC-Dpo2HDtE.js} +2 -2
  380. package/ui-dist/assets/swimlanesDiagram-G3AALYLV-CPmIkNCu.js +8 -0
  381. package/ui-dist/assets/{timeline-definition-FHXFAJF6-gi6amswh.js → timeline-definition-FHXFAJF6-BzmJ-xnC.js} +1 -1
  382. package/ui-dist/assets/{vennDiagram-L72KCM5P-B9uqeyQt.js → vennDiagram-L72KCM5P-BF2EI7vn.js} +1 -1
  383. package/ui-dist/assets/{wardleyDiagram-EHGQE667-BnqWAMiE.js → wardleyDiagram-EHGQE667-DM65x1i1.js} +1 -1
  384. package/ui-dist/assets/xterm-DZP7bLZ5.js +9 -0
  385. package/ui-dist/assets/{xychartDiagram-FW5EYKEG-BJXKltIN.js → xychartDiagram-FW5EYKEG-3Q2t9pdU.js} +1 -1
  386. package/ui-dist/index.html +2 -2
  387. package/dist/bootstrap/plugin-host-runtime.d.ts +0 -116
  388. package/dist/bootstrap/plugin-host-runtime.d.ts.map +0 -1
  389. package/dist/bootstrap/plugin-host-runtime.js +0 -179
  390. package/dist/bootstrap/plugin-host-runtime.js.map +0 -1
  391. package/dist/bundled-plugins/plugin-linear/README.md +0 -22
  392. package/dist/bundled-plugins/plugin-linear/dist/manifest.js +0 -183
  393. package/dist/bundled-plugins/plugin-linear/dist/manifest.js.map +0 -7
  394. package/dist/bundled-plugins/plugin-linear/dist/ui/index.js +0 -1285
  395. package/dist/bundled-plugins/plugin-linear/dist/ui/index.js.map +0 -7
  396. package/dist/bundled-plugins/plugin-linear/dist/worker.js +0 -10699
  397. package/dist/bundled-plugins/plugin-linear/dist/worker.js.map +0 -7
  398. package/dist/bundled-plugins/plugin-linear/package.json +0 -42
  399. package/dist/routes/plugin-ui-static.d.ts +0 -70
  400. package/dist/routes/plugin-ui-static.d.ts.map +0 -1
  401. package/dist/routes/plugin-ui-static.js +0 -375
  402. package/dist/routes/plugin-ui-static.js.map +0 -1
  403. package/dist/routes/plugins.d.ts +0 -120
  404. package/dist/routes/plugins.d.ts.map +0 -1
  405. package/dist/routes/plugins.js +0 -1125
  406. package/dist/routes/plugins.js.map +0 -1
  407. package/dist/routes/plugins.operations-routes.d.ts +0 -28
  408. package/dist/routes/plugins.operations-routes.d.ts.map +0 -1
  409. package/dist/routes/plugins.operations-routes.js +0 -720
  410. package/dist/routes/plugins.operations-routes.js.map +0 -1
  411. package/dist/services/plugin-capability-validator.d.ts +0 -108
  412. package/dist/services/plugin-capability-validator.d.ts.map +0 -1
  413. package/dist/services/plugin-capability-validator.js +0 -268
  414. package/dist/services/plugin-capability-validator.js.map +0 -1
  415. package/dist/services/plugin-config-validator.d.ts +0 -26
  416. package/dist/services/plugin-config-validator.d.ts.map +0 -1
  417. package/dist/services/plugin-config-validator.js +0 -41
  418. package/dist/services/plugin-config-validator.js.map +0 -1
  419. package/dist/services/plugin-dev-watcher.d.ts +0 -47
  420. package/dist/services/plugin-dev-watcher.d.ts.map +0 -1
  421. package/dist/services/plugin-dev-watcher.js +0 -275
  422. package/dist/services/plugin-dev-watcher.js.map +0 -1
  423. package/dist/services/plugin-event-bus.d.ts +0 -149
  424. package/dist/services/plugin-event-bus.d.ts.map +0 -1
  425. package/dist/services/plugin-event-bus.js +0 -258
  426. package/dist/services/plugin-event-bus.js.map +0 -1
  427. package/dist/services/plugin-host-service-cleanup.d.ts +0 -14
  428. package/dist/services/plugin-host-service-cleanup.d.ts.map +0 -1
  429. package/dist/services/plugin-host-service-cleanup.js +0 -37
  430. package/dist/services/plugin-host-service-cleanup.js.map +0 -1
  431. package/dist/services/plugin-host-services.d.ts +0 -13
  432. package/dist/services/plugin-host-services.d.ts.map +0 -1
  433. package/dist/services/plugin-host-services.js +0 -933
  434. package/dist/services/plugin-host-services.js.map +0 -1
  435. package/dist/services/plugin-job-coordinator.d.ts +0 -81
  436. package/dist/services/plugin-job-coordinator.d.ts.map +0 -1
  437. package/dist/services/plugin-job-coordinator.js +0 -172
  438. package/dist/services/plugin-job-coordinator.js.map +0 -1
  439. package/dist/services/plugin-job-scheduler.d.ts +0 -163
  440. package/dist/services/plugin-job-scheduler.d.ts.map +0 -1
  441. package/dist/services/plugin-job-scheduler.js +0 -452
  442. package/dist/services/plugin-job-scheduler.js.map +0 -1
  443. package/dist/services/plugin-job-store.d.ts +0 -208
  444. package/dist/services/plugin-job-store.d.ts.map +0 -1
  445. package/dist/services/plugin-job-store.js +0 -350
  446. package/dist/services/plugin-job-store.js.map +0 -1
  447. package/dist/services/plugin-lifecycle.d.ts +0 -240
  448. package/dist/services/plugin-lifecycle.d.ts.map +0 -1
  449. package/dist/services/plugin-lifecycle.js +0 -439
  450. package/dist/services/plugin-lifecycle.js.map +0 -1
  451. package/dist/services/plugin-loader.core.d.ts +0 -40
  452. package/dist/services/plugin-loader.core.d.ts.map +0 -1
  453. package/dist/services/plugin-loader.core.js +0 -879
  454. package/dist/services/plugin-loader.core.js.map +0 -1
  455. package/dist/services/plugin-loader.d.ts +0 -30
  456. package/dist/services/plugin-loader.d.ts.map +0 -1
  457. package/dist/services/plugin-loader.helpers.d.ts +0 -495
  458. package/dist/services/plugin-loader.helpers.d.ts.map +0 -1
  459. package/dist/services/plugin-loader.helpers.js +0 -238
  460. package/dist/services/plugin-loader.helpers.js.map +0 -1
  461. package/dist/services/plugin-loader.js +0 -30
  462. package/dist/services/plugin-loader.js.map +0 -1
  463. package/dist/services/plugin-loader.worker-paths.d.ts +0 -37
  464. package/dist/services/plugin-loader.worker-paths.d.ts.map +0 -1
  465. package/dist/services/plugin-loader.worker-paths.js +0 -62
  466. package/dist/services/plugin-loader.worker-paths.js.map +0 -1
  467. package/dist/services/plugin-log-retention.d.ts +0 -20
  468. package/dist/services/plugin-log-retention.d.ts.map +0 -1
  469. package/dist/services/plugin-log-retention.js +0 -63
  470. package/dist/services/plugin-log-retention.js.map +0 -1
  471. package/dist/services/plugin-manifest-validator.d.ts +0 -90
  472. package/dist/services/plugin-manifest-validator.d.ts.map +0 -1
  473. package/dist/services/plugin-manifest-validator.js +0 -72
  474. package/dist/services/plugin-manifest-validator.js.map +0 -1
  475. package/dist/services/plugin-registry.d.ts +0 -2542
  476. package/dist/services/plugin-registry.d.ts.map +0 -1
  477. package/dist/services/plugin-registry.js +0 -536
  478. package/dist/services/plugin-registry.js.map +0 -1
  479. package/dist/services/plugin-runtime-sandbox.d.ts +0 -40
  480. package/dist/services/plugin-runtime-sandbox.d.ts.map +0 -1
  481. package/dist/services/plugin-runtime-sandbox.js +0 -154
  482. package/dist/services/plugin-runtime-sandbox.js.map +0 -1
  483. package/dist/services/plugin-secrets-handler.d.ts +0 -81
  484. package/dist/services/plugin-secrets-handler.d.ts.map +0 -1
  485. package/dist/services/plugin-secrets-handler.js +0 -275
  486. package/dist/services/plugin-secrets-handler.js.map +0 -1
  487. package/dist/services/plugin-state-store.d.ts +0 -92
  488. package/dist/services/plugin-state-store.d.ts.map +0 -1
  489. package/dist/services/plugin-state-store.js +0 -190
  490. package/dist/services/plugin-state-store.js.map +0 -1
  491. package/dist/services/plugin-stream-bus.d.ts +0 -29
  492. package/dist/services/plugin-stream-bus.d.ts.map +0 -1
  493. package/dist/services/plugin-stream-bus.js +0 -48
  494. package/dist/services/plugin-stream-bus.js.map +0 -1
  495. package/dist/services/plugin-tool-dispatcher.d.ts +0 -180
  496. package/dist/services/plugin-tool-dispatcher.d.ts.map +0 -1
  497. package/dist/services/plugin-tool-dispatcher.js +0 -224
  498. package/dist/services/plugin-tool-dispatcher.js.map +0 -1
  499. package/dist/services/plugin-tool-registry.d.ts +0 -192
  500. package/dist/services/plugin-tool-registry.d.ts.map +0 -1
  501. package/dist/services/plugin-tool-registry.js +0 -224
  502. package/dist/services/plugin-tool-registry.js.map +0 -1
  503. package/dist/services/plugin-worker-manager.d.ts +0 -260
  504. package/dist/services/plugin-worker-manager.d.ts.map +0 -1
  505. package/dist/services/plugin-worker-manager.js +0 -836
  506. package/dist/services/plugin-worker-manager.js.map +0 -1
  507. package/ui-dist/assets/channel-C08AyYJr.js +0 -1
  508. package/ui-dist/assets/classDiagram-OUVF2IWQ-BIXq6fec.js +0 -1
  509. package/ui-dist/assets/classDiagram-v2-EOCWNBFH-BIXq6fec.js +0 -1
  510. package/ui-dist/assets/index-BmXb0yC1.css +0 -1
  511. package/ui-dist/assets/stateDiagram-v2-6OUMAXLB-KvSJhiLM.js +0 -1
  512. package/ui-dist/assets/swimlanesDiagram-G3AALYLV-Cr92NnJ4.js +0 -8
@@ -1,879 +0,0 @@
1
- import { existsSync } from "node:fs";
2
- import { readdir, rm, stat } from "node:fs/promises";
3
- import path from "node:path";
4
- import { logger } from "../middleware/logger.js";
5
- import { pluginCapabilityValidator } from "./plugin-capability-validator.js";
6
- import { compareSemver, DEFAULT_LOCAL_PLUGIN_DIR, DEV_TSX_LOADER_PATH, execFileAsync, getDeclaredPageRoutePaths, getMinimumHostVersion, isPluginPackageName, readPackageJson, resolveManifestPath } from "./plugin-loader.helpers.js";
7
- import { isPathInsideDir, resolveManagedInstallPackageDir, resolveWorkerEntrypoint } from "./plugin-loader.worker-paths.js";
8
- import { pluginManifestValidator } from "./plugin-manifest-validator.js";
9
- import { pluginRegistryService } from "./plugin-registry.js";
10
- export function pluginLoader(db, options = {}, runtimeServices) {
11
- const { localPluginDir = DEFAULT_LOCAL_PLUGIN_DIR, enableLocalFilesystem = true, enableNpmDiscovery = true, } = options;
12
- const registry = pluginRegistryService(db);
13
- const manifestValidator = pluginManifestValidator();
14
- const capabilityValidator = pluginCapabilityValidator();
15
- const log = logger.child({ service: "plugin-loader" });
16
- const hostVersion = runtimeServices?.instanceInfo.hostVersion;
17
- async function assertPageRoutePathsAvailable(manifest) {
18
- const requestedRoutePaths = getDeclaredPageRoutePaths(manifest);
19
- if (requestedRoutePaths.length === 0)
20
- return;
21
- const uniqueRequested = new Set(requestedRoutePaths);
22
- if (uniqueRequested.size !== requestedRoutePaths.length) {
23
- throw new Error(`Plugin ${manifest.id} declares duplicate page routePath values`);
24
- }
25
- const installedPlugins = await registry.listInstalled();
26
- for (const plugin of installedPlugins) {
27
- if (plugin.pluginKey === manifest.id)
28
- continue;
29
- const installedManifest = plugin.manifestJson;
30
- if (!installedManifest)
31
- continue;
32
- const installedRoutePaths = new Set(getDeclaredPageRoutePaths(installedManifest));
33
- const conflictingRoute = requestedRoutePaths.find((routePath) => installedRoutePaths.has(routePath));
34
- if (conflictingRoute) {
35
- throw new Error(`Plugin ${manifest.id} routePath "${conflictingRoute}" conflicts with installed plugin ${plugin.pluginKey}`);
36
- }
37
- }
38
- }
39
- // -------------------------------------------------------------------------
40
- // Internal helpers
41
- // -------------------------------------------------------------------------
42
- /**
43
- * Fetch a plugin from npm or local path, then parse and validate its manifest.
44
- *
45
- * This internal helper encapsulates the core plugin retrieval and validation
46
- * logic used by both install and upgrade operations. It handles:
47
- * 1. Resolving the package from npm or local filesystem.
48
- * 2. Installing the package via npm if necessary.
49
- * 3. Reading and parsing the plugin manifest.
50
- * 4. Validating API version compatibility.
51
- * 5. Validating manifest capabilities.
52
- *
53
- * @param installOptions - Options specifying the package to fetch.
54
- * @returns A `DiscoveredPlugin` object containing the validated manifest.
55
- */
56
- async function fetchAndValidate(installOptions) {
57
- const { packageName, localPath, version, installDir } = installOptions;
58
- if (!packageName && !localPath) {
59
- throw new Error("Either packageName or localPath must be provided");
60
- }
61
- const targetInstallDir = installDir ?? localPluginDir;
62
- // Step 1 & 2: Resolve and install package
63
- let resolvedPackagePath;
64
- let resolvedPackageName;
65
- if (localPath) {
66
- // Local path install — validate the directory exists
67
- const absLocalPath = path.resolve(localPath);
68
- if (!existsSync(absLocalPath)) {
69
- throw new Error(`Local plugin path does not exist: ${absLocalPath}`);
70
- }
71
- resolvedPackagePath = absLocalPath;
72
- const pkgJson = await readPackageJson(absLocalPath);
73
- resolvedPackageName =
74
- typeof pkgJson?.["name"] === "string"
75
- ? pkgJson["name"]
76
- : path.basename(absLocalPath);
77
- log.info({ localPath: absLocalPath, packageName: resolvedPackageName }, "plugin-loader: fetching plugin from local path");
78
- }
79
- else {
80
- // npm install
81
- const spec = version ? `${packageName}@${version}` : packageName;
82
- log.info({ spec, installDir: targetInstallDir }, "plugin-loader: fetching plugin from npm");
83
- try {
84
- // Use execFile (not exec) to avoid shell injection from package name/version.
85
- // --ignore-scripts prevents preinstall/install/postinstall hooks from
86
- // executing arbitrary code on the host before manifest validation.
87
- await execFileAsync("npm", ["install", spec, "--prefix", targetInstallDir, "--save", "--ignore-scripts"], { timeout: 120_000 });
88
- }
89
- catch (err) {
90
- throw new Error(`npm install failed for ${spec}: ${String(err)}`);
91
- }
92
- // Resolve the package path after installation
93
- const nodeModulesPath = path.join(targetInstallDir, "node_modules");
94
- resolvedPackageName = packageName;
95
- // Handle scoped packages
96
- if (resolvedPackageName.startsWith("@")) {
97
- const [scope, name] = resolvedPackageName.split("/");
98
- resolvedPackagePath = path.join(nodeModulesPath, scope, name);
99
- }
100
- else {
101
- resolvedPackagePath = path.join(nodeModulesPath, resolvedPackageName);
102
- }
103
- if (!existsSync(resolvedPackagePath)) {
104
- throw new Error(`Package directory not found after installation: ${resolvedPackagePath}`);
105
- }
106
- }
107
- // Step 3: Read and validate plugin manifest
108
- // Note: this.loadManifest (used via current context)
109
- const pkgJson = await readPackageJson(resolvedPackagePath);
110
- if (!pkgJson)
111
- throw new Error(`Missing package.json at ${resolvedPackagePath}`);
112
- const manifestPath = resolveManifestPath(resolvedPackagePath, pkgJson);
113
- if (!manifestPath || !existsSync(manifestPath)) {
114
- throw new Error(`Package ${resolvedPackageName} at ${resolvedPackagePath} does not appear to be a Rudder plugin (no manifest found).`);
115
- }
116
- const manifest = await loadManifestFromPath(manifestPath);
117
- // Step 4: Reject incompatible plugin API versions
118
- if (!manifestValidator.getSupportedVersions().includes(manifest.apiVersion)) {
119
- throw new Error(`Plugin ${manifest.id} declares apiVersion ${manifest.apiVersion} which is not supported by this host. ` +
120
- `Supported versions: ${manifestValidator.getSupportedVersions().join(", ")}`);
121
- }
122
- // Step 5: Validate manifest capabilities are consistent
123
- const capResult = capabilityValidator.validateManifestCapabilities(manifest);
124
- if (!capResult.allowed) {
125
- throw new Error(`Plugin ${manifest.id} manifest has inconsistent capabilities. ` +
126
- `Missing required capabilities for declared features: ${capResult.missing.join(", ")}`);
127
- }
128
- await assertPageRoutePathsAvailable(manifest);
129
- // Step 6: Reject plugins that require a newer host than the running server
130
- const minimumHostVersion = getMinimumHostVersion(manifest);
131
- if (minimumHostVersion && hostVersion) {
132
- if (compareSemver(hostVersion, minimumHostVersion) < 0) {
133
- throw new Error(`Plugin ${manifest.id} requires host version ${minimumHostVersion} or newer, ` +
134
- `but this server is running ${hostVersion}`);
135
- }
136
- }
137
- // Use the version declared in the manifest.
138
- const resolvedVersion = manifest.version;
139
- return {
140
- packagePath: resolvedPackagePath,
141
- packageName: resolvedPackageName,
142
- version: resolvedVersion,
143
- source: localPath ? "local-filesystem" : "npm",
144
- manifest,
145
- };
146
- }
147
- /**
148
- * Attempt to load and validate a plugin manifest from a resolved path.
149
- * Returns the manifest on success or throws with a descriptive error.
150
- */
151
- async function loadManifestFromPath(manifestPath) {
152
- let raw;
153
- try {
154
- // Dynamic import works for both .js (ESM) and .cjs (CJS) manifests
155
- const mod = await import(manifestPath);
156
- // The manifest may be the default export or the module itself
157
- raw = mod["default"] ?? mod;
158
- }
159
- catch (err) {
160
- throw new Error(`Failed to load manifest module at ${manifestPath}: ${String(err)}`);
161
- }
162
- return manifestValidator.parseOrThrow(raw);
163
- }
164
- /**
165
- * Build a DiscoveredPlugin from a resolved package directory, or null
166
- * if the package is not a Rudder plugin.
167
- */
168
- async function buildDiscoveredPlugin(packagePath, source) {
169
- const pkgJson = await readPackageJson(packagePath);
170
- if (!pkgJson)
171
- return null;
172
- const packageName = typeof pkgJson["name"] === "string" ? pkgJson["name"] : "";
173
- const version = typeof pkgJson["version"] === "string" ? pkgJson["version"] : "0.0.0";
174
- // Determine if this is a plugin package at all
175
- const hasPaperclipPlugin = "rudderPlugin" in pkgJson;
176
- const nameMatchesConvention = isPluginPackageName(packageName);
177
- if (!hasPaperclipPlugin && !nameMatchesConvention) {
178
- return null;
179
- }
180
- const manifestPath = resolveManifestPath(packagePath, pkgJson);
181
- if (!manifestPath || !existsSync(manifestPath)) {
182
- // Found a potential plugin package but no manifest entry point — treat
183
- // as a discovery-only result with no manifest
184
- return {
185
- packagePath,
186
- packageName,
187
- version,
188
- source,
189
- manifest: null,
190
- };
191
- }
192
- try {
193
- const manifest = await loadManifestFromPath(manifestPath);
194
- return {
195
- packagePath,
196
- packageName,
197
- version,
198
- source,
199
- manifest,
200
- };
201
- }
202
- catch (err) {
203
- // Rethrow with context — callers catch and route to the errors array
204
- throw new Error(`Plugin ${packageName}: ${String(err)}`);
205
- }
206
- }
207
- // -------------------------------------------------------------------------
208
- // Public API
209
- // -------------------------------------------------------------------------
210
- return {
211
- // -----------------------------------------------------------------------
212
- // discoverAll
213
- // -----------------------------------------------------------------------
214
- async discoverAll(npmSearchDirs) {
215
- const allDiscovered = [];
216
- const allErrors = [];
217
- const sources = [];
218
- if (enableLocalFilesystem) {
219
- sources.push("local-filesystem");
220
- const fsResult = await this.discoverFromLocalFilesystem();
221
- allDiscovered.push(...fsResult.discovered);
222
- allErrors.push(...fsResult.errors);
223
- }
224
- if (enableNpmDiscovery) {
225
- sources.push("npm");
226
- const npmResult = await this.discoverFromNpm(npmSearchDirs);
227
- // Deduplicate against already-discovered packages (same package path)
228
- const existingPaths = new Set(allDiscovered.map((d) => d.packagePath));
229
- for (const plugin of npmResult.discovered) {
230
- if (!existingPaths.has(plugin.packagePath)) {
231
- allDiscovered.push(plugin);
232
- }
233
- }
234
- allErrors.push(...npmResult.errors);
235
- }
236
- // Future: registry source (options.registryUrl)
237
- if (options.registryUrl) {
238
- sources.push("registry");
239
- log.warn({ registryUrl: options.registryUrl }, "plugin-loader: remote registry discovery is not yet implemented");
240
- }
241
- log.info({
242
- discovered: allDiscovered.length,
243
- errors: allErrors.length,
244
- sources,
245
- }, "plugin-loader: discovery complete");
246
- return { discovered: allDiscovered, errors: allErrors, sources };
247
- },
248
- // -----------------------------------------------------------------------
249
- // discoverFromLocalFilesystem
250
- // -----------------------------------------------------------------------
251
- async discoverFromLocalFilesystem(dir) {
252
- const scanDir = dir ?? localPluginDir;
253
- const discovered = [];
254
- const errors = [];
255
- if (!existsSync(scanDir)) {
256
- log.debug({ dir: scanDir }, "plugin-loader: local plugin directory does not exist, skipping");
257
- return { discovered, errors, sources: ["local-filesystem"] };
258
- }
259
- let entries;
260
- try {
261
- entries = await readdir(scanDir);
262
- }
263
- catch (err) {
264
- log.warn({ dir: scanDir, err }, "plugin-loader: failed to read local plugin directory");
265
- return { discovered, errors, sources: ["local-filesystem"] };
266
- }
267
- for (const entry of entries) {
268
- const entryPath = path.join(scanDir, entry);
269
- // Check if entry is a directory
270
- let entryStat;
271
- try {
272
- entryStat = await stat(entryPath);
273
- }
274
- catch {
275
- continue;
276
- }
277
- if (!entryStat.isDirectory())
278
- continue;
279
- // Handle scoped packages: @scope/plugin-name is a subdirectory
280
- if (entry.startsWith("@")) {
281
- let scopedEntries;
282
- try {
283
- scopedEntries = await readdir(entryPath);
284
- }
285
- catch {
286
- continue;
287
- }
288
- for (const scopedEntry of scopedEntries) {
289
- const scopedPath = path.join(entryPath, scopedEntry);
290
- try {
291
- const scopedStat = await stat(scopedPath);
292
- if (!scopedStat.isDirectory())
293
- continue;
294
- const plugin = await buildDiscoveredPlugin(scopedPath, "local-filesystem");
295
- if (plugin)
296
- discovered.push(plugin);
297
- }
298
- catch (err) {
299
- errors.push({
300
- packagePath: scopedPath,
301
- packageName: `${entry}/${scopedEntry}`,
302
- error: String(err),
303
- });
304
- }
305
- }
306
- continue;
307
- }
308
- try {
309
- const plugin = await buildDiscoveredPlugin(entryPath, "local-filesystem");
310
- if (plugin)
311
- discovered.push(plugin);
312
- }
313
- catch (err) {
314
- const pkgJson = await readPackageJson(entryPath);
315
- const packageName = typeof pkgJson?.["name"] === "string" ? pkgJson["name"] : entry;
316
- errors.push({ packagePath: entryPath, packageName, error: String(err) });
317
- }
318
- }
319
- log.debug({ dir: scanDir, discovered: discovered.length, errors: errors.length }, "plugin-loader: local filesystem scan complete");
320
- return { discovered, errors, sources: ["local-filesystem"] };
321
- },
322
- // -----------------------------------------------------------------------
323
- // discoverFromNpm
324
- // -----------------------------------------------------------------------
325
- async discoverFromNpm(searchDirs) {
326
- const discovered = [];
327
- const errors = [];
328
- // Determine the node_modules directories to search.
329
- // When searchDirs is undefined OR empty, fall back to the conventional
330
- // defaults (cwd/node_modules and localPluginDir/node_modules).
331
- // To search nowhere explicitly, pass a non-empty array of non-existent paths.
332
- const dirsToSearch = searchDirs && searchDirs.length > 0 ? searchDirs : [];
333
- if (dirsToSearch.length === 0) {
334
- // Default: search node_modules relative to the process working directory
335
- // and also the local plugin dir's node_modules
336
- const cwdNodeModules = path.join(process.cwd(), "node_modules");
337
- const localNodeModules = path.join(localPluginDir, "node_modules");
338
- if (existsSync(cwdNodeModules))
339
- dirsToSearch.push(cwdNodeModules);
340
- if (existsSync(localNodeModules))
341
- dirsToSearch.push(localNodeModules);
342
- }
343
- for (const nodeModulesDir of dirsToSearch) {
344
- if (!existsSync(nodeModulesDir))
345
- continue;
346
- let entries;
347
- try {
348
- entries = await readdir(nodeModulesDir);
349
- }
350
- catch {
351
- continue;
352
- }
353
- for (const entry of entries) {
354
- const entryPath = path.join(nodeModulesDir, entry);
355
- // Handle scoped packages (@scope/*)
356
- if (entry.startsWith("@")) {
357
- let scopedEntries;
358
- try {
359
- scopedEntries = await readdir(entryPath);
360
- }
361
- catch {
362
- continue;
363
- }
364
- for (const scopedEntry of scopedEntries) {
365
- const fullName = `${entry}/${scopedEntry}`;
366
- if (!isPluginPackageName(fullName))
367
- continue;
368
- const scopedPath = path.join(entryPath, scopedEntry);
369
- try {
370
- const plugin = await buildDiscoveredPlugin(scopedPath, "npm");
371
- if (plugin)
372
- discovered.push(plugin);
373
- }
374
- catch (err) {
375
- errors.push({
376
- packagePath: scopedPath,
377
- packageName: fullName,
378
- error: String(err),
379
- });
380
- }
381
- }
382
- continue;
383
- }
384
- // Non-scoped packages: check naming convention
385
- if (!isPluginPackageName(entry))
386
- continue;
387
- let entryStat;
388
- try {
389
- entryStat = await stat(entryPath);
390
- }
391
- catch {
392
- continue;
393
- }
394
- if (!entryStat.isDirectory())
395
- continue;
396
- try {
397
- const plugin = await buildDiscoveredPlugin(entryPath, "npm");
398
- if (plugin)
399
- discovered.push(plugin);
400
- }
401
- catch (err) {
402
- const pkgJson = await readPackageJson(entryPath);
403
- const packageName = typeof pkgJson?.["name"] === "string" ? pkgJson["name"] : entry;
404
- errors.push({ packagePath: entryPath, packageName, error: String(err) });
405
- }
406
- }
407
- }
408
- log.debug({ searchDirs: dirsToSearch, discovered: discovered.length, errors: errors.length }, "plugin-loader: npm discovery scan complete");
409
- return { discovered, errors, sources: ["npm"] };
410
- },
411
- // -----------------------------------------------------------------------
412
- // loadManifest
413
- // -----------------------------------------------------------------------
414
- async loadManifest(packagePath) {
415
- const pkgJson = await readPackageJson(packagePath);
416
- if (!pkgJson)
417
- return null;
418
- const hasPaperclipPlugin = "rudderPlugin" in pkgJson;
419
- const packageName = typeof pkgJson["name"] === "string" ? pkgJson["name"] : "";
420
- const nameMatchesConvention = isPluginPackageName(packageName);
421
- if (!hasPaperclipPlugin && !nameMatchesConvention) {
422
- return null;
423
- }
424
- const manifestPath = resolveManifestPath(packagePath, pkgJson);
425
- if (!manifestPath || !existsSync(manifestPath))
426
- return null;
427
- return loadManifestFromPath(manifestPath);
428
- },
429
- // -----------------------------------------------------------------------
430
- // installPlugin
431
- // -----------------------------------------------------------------------
432
- async installPlugin(installOptions) {
433
- const discovered = await fetchAndValidate(installOptions);
434
- // Step 6: Persist install record in Postgres (include packagePath for local installs so the worker can be resolved)
435
- await registry.install({
436
- packageName: discovered.packageName,
437
- packagePath: discovered.source === "local-filesystem" ? discovered.packagePath : undefined,
438
- }, discovered.manifest);
439
- log.info({
440
- pluginId: discovered.manifest.id,
441
- packageName: discovered.packageName,
442
- version: discovered.version,
443
- capabilities: discovered.manifest.capabilities,
444
- }, "plugin-loader: plugin installed successfully");
445
- return discovered;
446
- },
447
- // -----------------------------------------------------------------------
448
- // upgradePlugin
449
- // -----------------------------------------------------------------------
450
- /**
451
- * Upgrade an already-installed plugin to a newer version.
452
- *
453
- * This method:
454
- * 1. Fetches and validates the new plugin package using `fetchAndValidate`.
455
- * 2. Ensures the new manifest ID matches the existing plugin ID for safety.
456
- * 3. Updates the plugin record in the registry with the new version and manifest.
457
- *
458
- * @param pluginId - The UUID of the plugin to upgrade.
459
- * @param upgradeOptions - Options for the upgrade (packageName, localPath, version).
460
- * @returns The old and new manifests, along with the discovery metadata.
461
- * @throws {Error} If the plugin is not found or if the new manifest ID differs.
462
- */
463
- async upgradePlugin(pluginId, upgradeOptions) {
464
- const plugin = (await registry.getById(pluginId));
465
- if (!plugin)
466
- throw new Error(`Plugin not found: ${pluginId}`);
467
- const oldManifest = plugin.manifestJson;
468
- const { packageName = plugin.packageName,
469
- // For local-path installs, fall back to the stored packagePath so
470
- // `upgradePlugin` can re-read the manifest from disk without needing
471
- // the caller to re-supply the path every time.
472
- localPath = plugin.packagePath ?? undefined, version, } = upgradeOptions;
473
- log.info({ pluginId, packageName, version, localPath }, "plugin-loader: upgrading plugin");
474
- // 1. Fetch/Install the new version
475
- const discovered = await fetchAndValidate({
476
- packageName,
477
- localPath,
478
- version,
479
- installDir: localPluginDir,
480
- });
481
- const newManifest = discovered.manifest;
482
- // 2. Validate it's the same plugin ID
483
- if (newManifest.id !== oldManifest.id) {
484
- throw new Error(`Upgrade failed: new manifest ID '${newManifest.id}' does not match existing plugin ID '${oldManifest.id}'`);
485
- }
486
- // 3. Detect capability escalation — new capabilities not in the old manifest
487
- const oldCaps = new Set(oldManifest.capabilities ?? []);
488
- const newCaps = newManifest.capabilities ?? [];
489
- const escalated = newCaps.filter((c) => !oldCaps.has(c));
490
- if (escalated.length > 0) {
491
- log.warn({ pluginId, escalated, oldVersion: oldManifest.version, newVersion: newManifest.version }, "plugin-loader: upgrade introduces new capabilities — requires admin approval");
492
- throw new Error(`Upgrade for "${pluginId}" introduces new capabilities that require approval: ${escalated.join(", ")}. ` +
493
- `The previous version declared [${[...oldCaps].join(", ")}]. ` +
494
- `Please review and approve the capability escalation before upgrading.`);
495
- }
496
- // 4. Update the existing record
497
- await registry.update(pluginId, {
498
- packageName: discovered.packageName,
499
- version: discovered.version,
500
- manifest: newManifest,
501
- });
502
- return {
503
- oldManifest,
504
- newManifest,
505
- discovered,
506
- };
507
- },
508
- // -----------------------------------------------------------------------
509
- // isSupportedApiVersion
510
- // -----------------------------------------------------------------------
511
- isSupportedApiVersion(apiVersion) {
512
- return manifestValidator.getSupportedVersions().includes(apiVersion);
513
- },
514
- // -----------------------------------------------------------------------
515
- // cleanupInstallArtifacts
516
- // -----------------------------------------------------------------------
517
- async cleanupInstallArtifacts(plugin) {
518
- const managedTargets = new Set();
519
- const managedNodeModulesDir = resolveManagedInstallPackageDir(localPluginDir, plugin.packageName);
520
- const directManagedDir = path.join(localPluginDir, plugin.packageName);
521
- managedTargets.add(managedNodeModulesDir);
522
- if (isPathInsideDir(directManagedDir, localPluginDir)) {
523
- managedTargets.add(directManagedDir);
524
- }
525
- if (plugin.packagePath && isPathInsideDir(plugin.packagePath, localPluginDir)) {
526
- managedTargets.add(path.resolve(plugin.packagePath));
527
- }
528
- const packageJsonPath = path.join(localPluginDir, "package.json");
529
- if (existsSync(packageJsonPath)) {
530
- try {
531
- await execFileAsync("npm", ["uninstall", plugin.packageName, "--prefix", localPluginDir, "--ignore-scripts"], { timeout: 120_000 });
532
- }
533
- catch (err) {
534
- log.warn({
535
- pluginId: plugin.id,
536
- pluginKey: plugin.pluginKey,
537
- packageName: plugin.packageName,
538
- err: err instanceof Error ? err.message : String(err),
539
- }, "plugin-loader: npm uninstall failed during cleanup, falling back to direct removal");
540
- }
541
- }
542
- for (const target of managedTargets) {
543
- if (!existsSync(target))
544
- continue;
545
- await rm(target, { recursive: true, force: true });
546
- }
547
- },
548
- // -----------------------------------------------------------------------
549
- // getLocalPluginDir
550
- // -----------------------------------------------------------------------
551
- getLocalPluginDir() {
552
- return localPluginDir;
553
- },
554
- // -----------------------------------------------------------------------
555
- // hasRuntimeServices
556
- // -----------------------------------------------------------------------
557
- hasRuntimeServices() {
558
- return runtimeServices !== undefined;
559
- },
560
- // -----------------------------------------------------------------------
561
- // -----------------------------------------------------------------------
562
- // loadAll
563
- // -----------------------------------------------------------------------
564
- /**
565
- * loadAll — Loads and activates all plugins that are currently in 'ready' status.
566
- *
567
- * This method is typically called during server startup. It fetches all ready
568
- * plugins from the registry and attempts to activate them in parallel using
569
- * Promise.allSettled. Failures in individual plugins do not prevent others from loading.
570
- *
571
- * @returns A promise that resolves with summary statistics of the load operation.
572
- */
573
- async loadAll() {
574
- if (!runtimeServices) {
575
- throw new Error("Cannot loadAll: no PluginRuntimeServices provided. " +
576
- "Pass runtime services as the third argument to pluginLoader().");
577
- }
578
- log.info("plugin-loader: loading all ready plugins");
579
- // Fetch all plugins in ready status, ordered by installOrder
580
- const readyPlugins = (await registry.listByStatus("ready"));
581
- if (readyPlugins.length === 0) {
582
- log.info("plugin-loader: no ready plugins to load");
583
- return { total: 0, succeeded: 0, failed: 0, results: [] };
584
- }
585
- log.info({ count: readyPlugins.length }, "plugin-loader: found ready plugins to load");
586
- // Load plugins in parallel
587
- const results = await Promise.allSettled(readyPlugins.map((plugin) => activatePlugin(plugin)));
588
- const loadResults = results.map((r, i) => {
589
- if (r.status === "fulfilled")
590
- return r.value;
591
- return {
592
- plugin: readyPlugins[i],
593
- success: false,
594
- error: String(r.reason),
595
- registered: { worker: false, eventSubscriptions: 0, jobs: 0, webhooks: 0, tools: 0 },
596
- };
597
- });
598
- const succeeded = loadResults.filter((r) => r.success).length;
599
- const failed = loadResults.filter((r) => !r.success).length;
600
- log.info({
601
- total: readyPlugins.length,
602
- succeeded,
603
- failed,
604
- }, "plugin-loader: loadAll complete");
605
- return {
606
- total: readyPlugins.length,
607
- succeeded,
608
- failed,
609
- results: loadResults,
610
- };
611
- },
612
- // -----------------------------------------------------------------------
613
- // loadSingle
614
- // -----------------------------------------------------------------------
615
- /**
616
- * loadSingle — Loads and activates a single plugin by its ID.
617
- *
618
- * This method retrieves the plugin from the registry, ensures it's in a valid
619
- * state, and then calls activatePlugin to start its worker and register its
620
- * capabilities (tools, jobs, etc.).
621
- *
622
- * @param pluginId - The UUID of the plugin to load.
623
- * @returns A promise that resolves with the result of the activation.
624
- */
625
- async loadSingle(pluginId) {
626
- if (!runtimeServices) {
627
- throw new Error("Cannot loadSingle: no PluginRuntimeServices provided. " +
628
- "Pass runtime services as the third argument to pluginLoader().");
629
- }
630
- const plugin = (await registry.getById(pluginId));
631
- if (!plugin) {
632
- throw new Error(`Plugin not found: ${pluginId}`);
633
- }
634
- // If the plugin is in 'installed' status, transition it to 'ready' first.
635
- // lifecycleManager.load() transitions the status AND activates the plugin
636
- // via activateReadyPlugin() → loadSingle() (recursive call with 'ready'
637
- // status) → activatePlugin(). We must NOT call activatePlugin() again here,
638
- // as that would double-start the worker and duplicate registrations.
639
- if (plugin.status === "installed") {
640
- await runtimeServices.lifecycleManager.load(pluginId);
641
- const updated = (await registry.getById(pluginId));
642
- if (!updated)
643
- throw new Error(`Plugin not found after status update: ${pluginId}`);
644
- return {
645
- plugin: updated,
646
- success: true,
647
- registered: { worker: true, eventSubscriptions: 0, jobs: 0, webhooks: 0, tools: 0 },
648
- };
649
- }
650
- if (plugin.status !== "ready") {
651
- throw new Error(`Cannot load plugin in status '${plugin.status}'. ` +
652
- `Plugin must be in 'installed' or 'ready' status.`);
653
- }
654
- return activatePlugin(plugin);
655
- },
656
- // -----------------------------------------------------------------------
657
- // unloadSingle
658
- // -----------------------------------------------------------------------
659
- async unloadSingle(pluginId, pluginKey) {
660
- if (!runtimeServices) {
661
- throw new Error("Cannot unloadSingle: no PluginRuntimeServices provided.");
662
- }
663
- log.info({ pluginId, pluginKey }, "plugin-loader: unloading single plugin");
664
- const { workerManager, eventBus, jobScheduler, toolDispatcher, } = runtimeServices;
665
- // 1. Unregister from job scheduler (cancels in-flight runs)
666
- try {
667
- await jobScheduler.unregisterPlugin(pluginId);
668
- }
669
- catch (err) {
670
- log.warn({ pluginId, err: err instanceof Error ? err.message : String(err) }, "plugin-loader: failed to unregister from job scheduler (best-effort)");
671
- }
672
- // 2. Clear event subscriptions
673
- eventBus.clearPlugin(pluginKey);
674
- // 3. Unregister agent tools
675
- toolDispatcher.unregisterPluginTools(pluginKey);
676
- // 4. Stop the worker process
677
- try {
678
- if (workerManager.isRunning(pluginId)) {
679
- await workerManager.stopWorker(pluginId);
680
- }
681
- }
682
- catch (err) {
683
- log.warn({ pluginId, err: err instanceof Error ? err.message : String(err) }, "plugin-loader: failed to stop worker during unload (best-effort)");
684
- }
685
- log.info({ pluginId, pluginKey }, "plugin-loader: plugin unloaded successfully");
686
- },
687
- // -----------------------------------------------------------------------
688
- // shutdownAll
689
- // -----------------------------------------------------------------------
690
- async shutdownAll() {
691
- if (!runtimeServices) {
692
- throw new Error("Cannot shutdownAll: no PluginRuntimeServices provided.");
693
- }
694
- log.info("plugin-loader: shutting down all plugins");
695
- const { workerManager, jobScheduler } = runtimeServices;
696
- // 1. Stop the job scheduler tick loop
697
- jobScheduler.stop();
698
- // 2. Stop all worker processes
699
- await workerManager.stopAll();
700
- log.info("plugin-loader: all plugins shut down");
701
- },
702
- };
703
- // -------------------------------------------------------------------------
704
- // Internal: activatePlugin — shared logic for loadAll and loadSingle
705
- // -------------------------------------------------------------------------
706
- /**
707
- * Activate a single plugin: spawn its worker, register event subscriptions,
708
- * sync jobs, register tools.
709
- *
710
- * This is the core orchestration logic shared by `loadAll()` and `loadSingle()`.
711
- * Failures are caught and reported in the result; the plugin is marked as
712
- * `error` in the database when activation fails.
713
- */
714
- async function activatePlugin(plugin) {
715
- const manifest = plugin.manifestJson;
716
- const pluginId = plugin.id;
717
- const pluginKey = plugin.pluginKey;
718
- const registered = {
719
- worker: false,
720
- eventSubscriptions: 0,
721
- jobs: 0,
722
- webhooks: 0,
723
- tools: 0,
724
- };
725
- // Guard: runtime services must exist (callers already checked)
726
- if (!runtimeServices) {
727
- return {
728
- plugin,
729
- success: false,
730
- error: "No runtime services available",
731
- registered,
732
- };
733
- }
734
- const { workerManager, eventBus, jobScheduler, jobStore, toolDispatcher, lifecycleManager, buildHostHandlers, instanceInfo, } = runtimeServices;
735
- try {
736
- log.info({ pluginId, pluginKey, version: plugin.version }, "plugin-loader: activating plugin");
737
- // ------------------------------------------------------------------
738
- // 1. Resolve worker entrypoint
739
- // ------------------------------------------------------------------
740
- const workerEntrypoint = resolveWorkerEntrypoint(plugin, localPluginDir);
741
- // ------------------------------------------------------------------
742
- // 2. Build host handlers for this plugin
743
- // ------------------------------------------------------------------
744
- const hostHandlers = buildHostHandlers(pluginId, manifest);
745
- // ------------------------------------------------------------------
746
- // 3. Retrieve plugin config (if any)
747
- // ------------------------------------------------------------------
748
- let config = {};
749
- try {
750
- const configRow = await registry.getConfig(pluginId);
751
- if (configRow && typeof configRow === "object" && "configJson" in configRow) {
752
- config = configRow.configJson ?? {};
753
- }
754
- }
755
- catch {
756
- // Config may not exist yet — use empty object
757
- log.debug({ pluginId }, "plugin-loader: no config found, using empty config");
758
- }
759
- // ------------------------------------------------------------------
760
- // 4. Spawn worker process
761
- // ------------------------------------------------------------------
762
- const workerOptions = {
763
- entrypointPath: workerEntrypoint,
764
- manifest,
765
- config,
766
- instanceInfo,
767
- apiVersion: manifest.apiVersion,
768
- hostHandlers,
769
- autoRestart: true,
770
- };
771
- // Repo-local plugin installs can resolve workspace TS sources at runtime
772
- // (for example @rudderhq/shared exports). Run those workers through
773
- // the tsx loader so first-party example plugins work in development.
774
- if (plugin.packagePath && existsSync(DEV_TSX_LOADER_PATH)) {
775
- workerOptions.execArgv = ["--import", DEV_TSX_LOADER_PATH];
776
- }
777
- await workerManager.startWorker(pluginId, workerOptions);
778
- registered.worker = true;
779
- log.info({ pluginId, pluginKey }, "plugin-loader: worker started");
780
- // ------------------------------------------------------------------
781
- // 5. Sync job declarations and register with scheduler
782
- // ------------------------------------------------------------------
783
- const jobDeclarations = manifest.jobs ?? [];
784
- if (jobDeclarations.length > 0) {
785
- await jobStore.syncJobDeclarations(pluginId, jobDeclarations);
786
- await jobScheduler.registerPlugin(pluginId);
787
- registered.jobs = jobDeclarations.length;
788
- log.info({ pluginId, pluginKey, jobs: jobDeclarations.length }, "plugin-loader: job declarations synced and plugin registered with scheduler");
789
- }
790
- // ------------------------------------------------------------------
791
- // 6. Register event subscriptions
792
- //
793
- // Note: Event subscriptions are declared at runtime by the plugin
794
- // worker via the SDK's ctx.events.on() calls. The event bus manages
795
- // per-plugin subscription scoping. Here we ensure the event bus has
796
- // a scoped handle ready for this plugin — the actual subscriptions
797
- // are registered by the host handler layer when the worker calls
798
- // events.subscribe via RPC.
799
- //
800
- // The bus.forPlugin() call creates the scoped handle if needed;
801
- // any previous subscriptions for this plugin are preserved if the
802
- // worker is restarting.
803
- // ------------------------------------------------------------------
804
- const _scopedBus = eventBus.forPlugin(pluginKey);
805
- registered.eventSubscriptions = eventBus.subscriptionCount(pluginKey);
806
- log.debug({ pluginId, pluginKey }, "plugin-loader: event bus scoped handle ready");
807
- // ------------------------------------------------------------------
808
- // 7. Register webhook endpoints (manifest-declared)
809
- //
810
- // Webhooks are statically declared in the manifest. The actual
811
- // endpoint routing is handled by the plugin routes module which
812
- // checks the manifest for declared webhooks. No explicit
813
- // registration step is needed here — the manifest is persisted
814
- // in the DB and the route handler reads it at request time.
815
- //
816
- // We track the count for the result reporting.
817
- // ------------------------------------------------------------------
818
- const webhookDeclarations = manifest.webhooks ?? [];
819
- registered.webhooks = webhookDeclarations.length;
820
- if (webhookDeclarations.length > 0) {
821
- log.info({ pluginId, pluginKey, webhooks: webhookDeclarations.length }, "plugin-loader: webhook endpoints declared in manifest");
822
- }
823
- // ------------------------------------------------------------------
824
- // 8. Register agent tools
825
- // ------------------------------------------------------------------
826
- const toolDeclarations = manifest.tools ?? [];
827
- if (toolDeclarations.length > 0) {
828
- toolDispatcher.registerPluginTools(pluginKey, manifest);
829
- registered.tools = toolDeclarations.length;
830
- log.info({ pluginId, pluginKey, tools: toolDeclarations.length }, "plugin-loader: agent tools registered");
831
- }
832
- // ------------------------------------------------------------------
833
- // Done — plugin fully activated
834
- // ------------------------------------------------------------------
835
- log.info({
836
- pluginId,
837
- pluginKey,
838
- version: plugin.version,
839
- registered,
840
- }, "plugin-loader: plugin activated successfully");
841
- return { plugin, success: true, registered };
842
- }
843
- catch (err) {
844
- const errorMessage = err instanceof Error ? err.message : String(err);
845
- log.error({ pluginId, pluginKey, err: errorMessage }, "plugin-loader: failed to activate plugin");
846
- // Mark the plugin as errored in the database so it is not retried
847
- // automatically on next startup without operator intervention.
848
- try {
849
- await lifecycleManager.markError(pluginId, `Activation failed: ${errorMessage}`);
850
- }
851
- catch (markErr) {
852
- log.error({
853
- pluginId,
854
- err: markErr instanceof Error ? markErr.message : String(markErr),
855
- }, "plugin-loader: failed to mark plugin as error after activation failure");
856
- }
857
- return {
858
- plugin,
859
- success: false,
860
- error: errorMessage,
861
- registered,
862
- };
863
- }
864
- }
865
- }
866
- // ---------------------------------------------------------------------------
867
- // Worker entrypoint resolution
868
- // ---------------------------------------------------------------------------
869
- /**
870
- * Resolve the absolute path to a plugin's worker entrypoint from its manifest
871
- * and known install locations.
872
- *
873
- * The manifest `entrypoints.worker` field is relative to the package root.
874
- * We check the local plugin directory (where the package was installed) and
875
- * also the package directory if it was a local-path install.
876
- *
877
- * @see doc/engineering/PLUGIN_RUNTIME_CONTRACT.md — Package Contract
878
- */
879
- //# sourceMappingURL=plugin-loader.core.js.map