@nocobase/app-plugin-agents 0.1.0-beta.8 → 1.0.0-beta.15

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 (835) hide show
  1. package/CHANGELOG.md +304 -0
  2. package/README.md +94 -51
  3. package/dist/client/api/client.d.ts +25 -19
  4. package/dist/client/api/client.d.ts.map +1 -1
  5. package/dist/client/api/client.js +23 -24
  6. package/dist/client/api/client.js.map +1 -1
  7. package/dist/client/api/keys.d.ts +4 -1
  8. package/dist/client/api/keys.d.ts.map +1 -1
  9. package/dist/client/api/keys.js +4 -1
  10. package/dist/client/api/keys.js.map +1 -1
  11. package/dist/client/api/runners.d.ts +8 -4
  12. package/dist/client/api/runners.d.ts.map +1 -1
  13. package/dist/client/api/runners.js +9 -0
  14. package/dist/client/api/runners.js.map +1 -1
  15. package/dist/client/chat/ai-form.d.ts +13 -0
  16. package/dist/client/chat/ai-form.d.ts.map +1 -0
  17. package/dist/client/chat/ai-form.js +57 -0
  18. package/dist/client/chat/ai-form.js.map +1 -0
  19. package/dist/client/chat/api.d.ts +16 -14
  20. package/dist/client/chat/api.d.ts.map +1 -1
  21. package/dist/client/chat/api.js +85 -18
  22. package/dist/client/chat/api.js.map +1 -1
  23. package/dist/client/chat/client-id.d.ts +3 -0
  24. package/dist/client/chat/client-id.d.ts.map +1 -0
  25. package/dist/client/chat/client-id.js +17 -0
  26. package/dist/client/chat/client-id.js.map +1 -0
  27. package/dist/client/chat/consultation-identity.d.ts +7 -0
  28. package/dist/client/chat/consultation-identity.d.ts.map +1 -0
  29. package/dist/client/chat/consultation-identity.js +39 -0
  30. package/dist/client/chat/consultation-identity.js.map +1 -0
  31. package/dist/client/chat/context-model.d.ts +21 -3
  32. package/dist/client/chat/context-model.d.ts.map +1 -1
  33. package/dist/client/chat/context-model.js +33 -4
  34. package/dist/client/chat/context-model.js.map +1 -1
  35. package/dist/client/chat/controller.d.ts +83 -0
  36. package/dist/client/chat/controller.d.ts.map +1 -0
  37. package/dist/client/chat/controller.js +767 -0
  38. package/dist/client/chat/controller.js.map +1 -0
  39. package/dist/client/chat/extensions.d.ts +8 -3
  40. package/dist/client/chat/extensions.d.ts.map +1 -1
  41. package/dist/client/chat/extensions.js.map +1 -1
  42. package/dist/client/chat/feedback.d.ts +18 -0
  43. package/dist/client/chat/feedback.d.ts.map +1 -0
  44. package/dist/client/chat/feedback.js +38 -0
  45. package/dist/client/chat/feedback.js.map +1 -0
  46. package/dist/client/chat/form-registry.d.ts +95 -0
  47. package/dist/client/chat/form-registry.d.ts.map +1 -0
  48. package/dist/client/chat/form-registry.js +384 -0
  49. package/dist/client/chat/form-registry.js.map +1 -0
  50. package/dist/client/chat/keys.d.ts +1 -0
  51. package/dist/client/chat/keys.d.ts.map +1 -1
  52. package/dist/client/chat/keys.js +3 -1
  53. package/dist/client/chat/keys.js.map +1 -1
  54. package/dist/client/chat/message-model.d.ts +38 -44
  55. package/dist/client/chat/message-model.d.ts.map +1 -1
  56. package/dist/client/chat/message-model.js +138 -56
  57. package/dist/client/chat/message-model.js.map +1 -1
  58. package/dist/client/chat/provider.d.ts +12 -2
  59. package/dist/client/chat/provider.d.ts.map +1 -1
  60. package/dist/client/chat/provider.js +130 -4
  61. package/dist/client/chat/provider.js.map +1 -1
  62. package/dist/client/chat/submissions.d.ts +67 -0
  63. package/dist/client/chat/submissions.d.ts.map +1 -0
  64. package/dist/client/chat/submissions.js +241 -0
  65. package/dist/client/chat/submissions.js.map +1 -0
  66. package/dist/client/chat/tool-renderer.d.ts +39 -0
  67. package/dist/client/chat/tool-renderer.d.ts.map +1 -0
  68. package/dist/client/chat/tool-renderer.js +27 -0
  69. package/dist/client/chat/tool-renderer.js.map +1 -0
  70. package/dist/client/chat/use-chat-scroll.d.ts +4 -0
  71. package/dist/client/chat/use-chat-scroll.d.ts.map +1 -0
  72. package/dist/client/chat/use-chat-scroll.js +73 -0
  73. package/dist/client/chat/use-chat-scroll.js.map +1 -0
  74. package/dist/client/chat/use-chat.d.ts +13 -24
  75. package/dist/client/chat/use-chat.d.ts.map +1 -1
  76. package/dist/client/chat/use-chat.js +250 -235
  77. package/dist/client/chat/use-chat.js.map +1 -1
  78. package/dist/client/chat.d.ts +20 -8
  79. package/dist/client/chat.d.ts.map +1 -1
  80. package/dist/client/chat.js +16 -4
  81. package/dist/client/chat.js.map +1 -1
  82. package/dist/client/components/agent-picker.d.ts +6 -23
  83. package/dist/client/components/agent-picker.d.ts.map +1 -1
  84. package/dist/client/components/agent-picker.js +20 -39
  85. package/dist/client/components/agent-picker.js.map +1 -1
  86. package/dist/client/components/quota-status.d.ts +16 -0
  87. package/dist/client/components/quota-status.d.ts.map +1 -0
  88. package/dist/client/components/quota-status.js +39 -0
  89. package/dist/client/components/quota-status.js.map +1 -0
  90. package/dist/client/components/runners-refresh.d.ts.map +1 -1
  91. package/dist/client/components/runners-refresh.js +1 -0
  92. package/dist/client/components/runners-refresh.js.map +1 -1
  93. package/dist/client/components/variables/variable-dialogs.d.ts.map +1 -1
  94. package/dist/client/components/variables/variable-dialogs.js +7 -7
  95. package/dist/client/components/variables/variable-dialogs.js.map +1 -1
  96. package/dist/client/config.d.ts +2 -0
  97. package/dist/client/config.d.ts.map +1 -1
  98. package/dist/client/config.js +2 -0
  99. package/dist/client/config.js.map +1 -1
  100. package/dist/client/hooks/use-agent-picker-labels.d.ts.map +1 -1
  101. package/dist/client/hooks/use-agent-picker-labels.js +4 -12
  102. package/dist/client/hooks/use-agent-picker-labels.js.map +1 -1
  103. package/dist/client/hooks/use-quota-expiry.d.ts +7 -0
  104. package/dist/client/hooks/use-quota-expiry.d.ts.map +1 -0
  105. package/dist/client/hooks/use-quota-expiry.js +92 -0
  106. package/dist/client/hooks/use-quota-expiry.js.map +1 -0
  107. package/dist/client/hooks/use-realtime-topic.d.ts +1 -4
  108. package/dist/client/hooks/use-realtime-topic.d.ts.map +1 -1
  109. package/dist/client/hooks/use-realtime-topic.js +7 -11
  110. package/dist/client/hooks/use-realtime-topic.js.map +1 -1
  111. package/dist/client/kit.d.ts +14 -12
  112. package/dist/client/kit.d.ts.map +1 -1
  113. package/dist/client/kit.js +37 -14
  114. package/dist/client/kit.js.map +1 -1
  115. package/dist/client/lib/agents.d.ts +5 -18
  116. package/dist/client/lib/agents.d.ts.map +1 -1
  117. package/dist/client/lib/agents.js +18 -55
  118. package/dist/client/lib/agents.js.map +1 -1
  119. package/dist/client/lib/format.d.ts +3 -1
  120. package/dist/client/lib/format.d.ts.map +1 -1
  121. package/dist/client/lib/format.js +25 -0
  122. package/dist/client/lib/format.js.map +1 -1
  123. package/dist/client/lib/skill-settings-context.d.ts +9 -0
  124. package/dist/client/lib/skill-settings-context.d.ts.map +1 -0
  125. package/dist/client/lib/skill-settings-context.js +4 -0
  126. package/dist/client/lib/skill-settings-context.js.map +1 -0
  127. package/dist/client/lib/skill-settings.d.ts +12 -0
  128. package/dist/client/lib/skill-settings.d.ts.map +1 -0
  129. package/dist/client/lib/skill-settings.js +37 -0
  130. package/dist/client/lib/skill-settings.js.map +1 -0
  131. package/dist/client/locales/chat.en-US.d.ts +8 -27
  132. package/dist/client/locales/chat.en-US.d.ts.map +1 -1
  133. package/dist/client/locales/chat.en-US.js +12 -30
  134. package/dist/client/locales/chat.en-US.js.map +1 -1
  135. package/dist/client/locales/chat.zh-CN.d.ts.map +1 -1
  136. package/dist/client/locales/chat.zh-CN.js +9 -27
  137. package/dist/client/locales/chat.zh-CN.js.map +1 -1
  138. package/dist/client/locales/en-US.d.ts +87 -217
  139. package/dist/client/locales/en-US.d.ts.map +1 -1
  140. package/dist/client/locales/en-US.js +92 -218
  141. package/dist/client/locales/en-US.js.map +1 -1
  142. package/dist/client/locales/runWait.en-US.d.ts +7 -0
  143. package/dist/client/locales/runWait.en-US.d.ts.map +1 -1
  144. package/dist/client/locales/runWait.en-US.js +10 -3
  145. package/dist/client/locales/runWait.en-US.js.map +1 -1
  146. package/dist/client/locales/runWait.zh-CN.d.ts +1 -1
  147. package/dist/client/locales/runWait.zh-CN.d.ts.map +1 -1
  148. package/dist/client/locales/runWait.zh-CN.js +11 -4
  149. package/dist/client/locales/runWait.zh-CN.js.map +1 -1
  150. package/dist/client/locales/runtimes.en-US.d.ts +83 -0
  151. package/dist/client/locales/runtimes.en-US.d.ts.map +1 -1
  152. package/dist/client/locales/runtimes.en-US.js +84 -1
  153. package/dist/client/locales/runtimes.en-US.js.map +1 -1
  154. package/dist/client/locales/runtimes.zh-CN.d.ts.map +1 -1
  155. package/dist/client/locales/runtimes.zh-CN.js +83 -0
  156. package/dist/client/locales/runtimes.zh-CN.js.map +1 -1
  157. package/dist/client/locales/skills.en-US.d.ts +7 -0
  158. package/dist/client/locales/skills.en-US.d.ts.map +1 -1
  159. package/dist/client/locales/skills.en-US.js +8 -1
  160. package/dist/client/locales/skills.en-US.js.map +1 -1
  161. package/dist/client/locales/skills.zh-CN.d.ts.map +1 -1
  162. package/dist/client/locales/skills.zh-CN.js +8 -1
  163. package/dist/client/locales/skills.zh-CN.js.map +1 -1
  164. package/dist/client/locales/zh-CN.d.ts.map +1 -1
  165. package/dist/client/locales/zh-CN.js +94 -220
  166. package/dist/client/locales/zh-CN.js.map +1 -1
  167. package/dist/client/online/services.d.ts.map +1 -1
  168. package/dist/client/online/services.js +5 -6
  169. package/dist/client/online/services.js.map +1 -1
  170. package/dist/client/pages/agents/agent-dialog.d.ts +9 -0
  171. package/dist/client/pages/agents/agent-dialog.d.ts.map +1 -0
  172. package/dist/client/pages/agents/agent-dialog.js +106 -0
  173. package/dist/client/pages/agents/agent-dialog.js.map +1 -0
  174. package/dist/client/pages/agents/agent-state.d.ts +11 -0
  175. package/dist/client/pages/agents/agent-state.d.ts.map +1 -0
  176. package/dist/client/pages/agents/agent-state.js +28 -0
  177. package/dist/client/pages/agents/agent-state.js.map +1 -0
  178. package/dist/client/pages/agents/index.d.ts +1 -1
  179. package/dist/client/pages/agents/index.d.ts.map +1 -1
  180. package/dist/client/pages/agents/index.js +7 -101
  181. package/dist/client/pages/agents/index.js.map +1 -1
  182. package/dist/client/pages/agents/runner-agents.d.ts +3 -0
  183. package/dist/client/pages/agents/runner-agents.d.ts.map +1 -0
  184. package/dist/client/pages/agents/runner-agents.js +185 -0
  185. package/dist/client/pages/agents/runner-agents.js.map +1 -0
  186. package/dist/client/pages/runtimes/connect.js.map +1 -1
  187. package/dist/client/pages/runtimes/index.d.ts.map +1 -1
  188. package/dist/client/pages/runtimes/index.js +1 -1
  189. package/dist/client/pages/runtimes/index.js.map +1 -1
  190. package/dist/client/pages/runtimes/quota-targets.d.ts +4 -0
  191. package/dist/client/pages/runtimes/quota-targets.d.ts.map +1 -0
  192. package/dist/client/pages/runtimes/quota-targets.js +18 -0
  193. package/dist/client/pages/runtimes/quota-targets.js.map +1 -0
  194. package/dist/client/pages/runtimes/quota.d.ts +17 -0
  195. package/dist/client/pages/runtimes/quota.d.ts.map +1 -0
  196. package/dist/client/pages/runtimes/quota.js +50 -0
  197. package/dist/client/pages/runtimes/quota.js.map +1 -0
  198. package/dist/client/pages/runtimes/runner-cells.d.ts +11 -4
  199. package/dist/client/pages/runtimes/runner-cells.d.ts.map +1 -1
  200. package/dist/client/pages/runtimes/runner-cells.js +6 -3
  201. package/dist/client/pages/runtimes/runner-cells.js.map +1 -1
  202. package/dist/client/pages/runtimes/runner-overview.d.ts +9 -0
  203. package/dist/client/pages/runtimes/runner-overview.d.ts.map +1 -0
  204. package/dist/client/pages/runtimes/runner-overview.js +109 -0
  205. package/dist/client/pages/runtimes/runner-overview.js.map +1 -0
  206. package/dist/client/pages/runtimes/runner-runs.d.ts +5 -0
  207. package/dist/client/pages/runtimes/runner-runs.d.ts.map +1 -0
  208. package/dist/client/pages/runtimes/runner-runs.js +35 -0
  209. package/dist/client/pages/runtimes/runner-runs.js.map +1 -0
  210. package/dist/client/pages/runtimes/runner-sheet.d.ts +2 -3
  211. package/dist/client/pages/runtimes/runner-sheet.d.ts.map +1 -1
  212. package/dist/client/pages/runtimes/runner-sheet.js +43 -171
  213. package/dist/client/pages/runtimes/runner-sheet.js.map +1 -1
  214. package/dist/client/pages/runtimes/runner-tools.d.ts +17 -0
  215. package/dist/client/pages/runtimes/runner-tools.d.ts.map +1 -0
  216. package/dist/client/pages/runtimes/runner-tools.js +75 -0
  217. package/dist/client/pages/runtimes/runner-tools.js.map +1 -0
  218. package/dist/client/pages/runtimes/runner-workspaces.d.ts +6 -0
  219. package/dist/client/pages/runtimes/runner-workspaces.d.ts.map +1 -0
  220. package/dist/client/pages/runtimes/runner-workspaces.js +37 -0
  221. package/dist/client/pages/runtimes/runner-workspaces.js.map +1 -0
  222. package/dist/client/pages/runtimes/tool-slots-fields.js +1 -1
  223. package/dist/client/pages/runtimes/tool-slots-fields.js.map +1 -1
  224. package/dist/client/pages/runtimes/workspace-diagnostics.d.ts +6 -4
  225. package/dist/client/pages/runtimes/workspace-diagnostics.d.ts.map +1 -1
  226. package/dist/client/pages/runtimes/workspace-diagnostics.js +67 -33
  227. package/dist/client/pages/runtimes/workspace-diagnostics.js.map +1 -1
  228. package/dist/client/pages/skills/detail/index.d.ts.map +1 -1
  229. package/dist/client/pages/skills/detail/index.js +11 -15
  230. package/dist/client/pages/skills/detail/index.js.map +1 -1
  231. package/dist/client/pages/skills/index.d.ts.map +1 -1
  232. package/dist/client/pages/skills/index.js +2 -2
  233. package/dist/client/pages/skills/index.js.map +1 -1
  234. package/dist/client/pages/usage/index.js +2 -2
  235. package/dist/client/pages/usage/index.js.map +1 -1
  236. package/dist/client/profile/default-agent.d.ts.map +1 -1
  237. package/dist/client/profile/default-agent.js +2 -4
  238. package/dist/client/profile/default-agent.js.map +1 -1
  239. package/dist/client/routes.d.ts +1 -1
  240. package/dist/client/routes.d.ts.map +1 -1
  241. package/dist/client/routes.js +1 -13
  242. package/dist/client/routes.js.map +1 -1
  243. package/dist/client/runs/format-wait.d.ts.map +1 -1
  244. package/dist/client/runs/format-wait.js +15 -1
  245. package/dist/client/runs/format-wait.js.map +1 -1
  246. package/dist/client/runs/subject-runs.d.ts +5 -0
  247. package/dist/client/runs/subject-runs.d.ts.map +1 -1
  248. package/dist/client/runs/subject-runs.js +24 -9
  249. package/dist/client/runs/subject-runs.js.map +1 -1
  250. package/dist/client/runs/use-run-events.d.ts +1 -1
  251. package/dist/client/runs/use-run-events.d.ts.map +1 -1
  252. package/dist/client/runs/use-run-events.js +5 -2
  253. package/dist/client/runs/use-run-events.js.map +1 -1
  254. package/dist/client/runs.d.ts +1 -1
  255. package/dist/client/runs.d.ts.map +1 -1
  256. package/dist/client/runs.js +1 -1
  257. package/dist/client/runs.js.map +1 -1
  258. package/dist/database/migrations/.manifest.json +42 -2
  259. package/dist/database/migrations/202610020003_ag_create_runs.d.ts.map +1 -1
  260. package/dist/database/migrations/202610020003_ag_create_runs.js +0 -1
  261. package/dist/database/migrations/202610020003_ag_create_runs.js.map +1 -1
  262. package/dist/database/migrations/202610120001_ag_index_run_retries.d.ts +4 -0
  263. package/dist/database/migrations/202610120001_ag_index_run_retries.d.ts.map +1 -0
  264. package/dist/database/migrations/202610120001_ag_index_run_retries.js +17 -0
  265. package/dist/database/migrations/202610120001_ag_index_run_retries.js.map +1 -0
  266. package/dist/database/migrations/202610120002_ag_add_queue_entered_at.d.ts +4 -0
  267. package/dist/database/migrations/202610120002_ag_add_queue_entered_at.d.ts.map +1 -0
  268. package/dist/database/migrations/202610120002_ag_add_queue_entered_at.js +50 -0
  269. package/dist/database/migrations/202610120002_ag_add_queue_entered_at.js.map +1 -0
  270. package/dist/database/migrations/202610170001_ag_runner_quota.d.ts +4 -0
  271. package/dist/database/migrations/202610170001_ag_runner_quota.d.ts.map +1 -0
  272. package/dist/database/migrations/202610170001_ag_runner_quota.js +19 -0
  273. package/dist/database/migrations/202610170001_ag_runner_quota.js.map +1 -0
  274. package/dist/database/migrations/202610240020_ag_runner_agents.d.ts +4 -0
  275. package/dist/database/migrations/202610240020_ag_runner_agents.d.ts.map +1 -0
  276. package/dist/database/migrations/202610240020_ag_runner_agents.js +115 -0
  277. package/dist/database/migrations/202610240020_ag_runner_agents.js.map +1 -0
  278. package/dist/database/migrations/202610240040_ag_discovery_preferences.d.ts +4 -0
  279. package/dist/database/migrations/202610240040_ag_discovery_preferences.d.ts.map +1 -0
  280. package/dist/database/migrations/202610240040_ag_discovery_preferences.js +18 -0
  281. package/dist/database/migrations/202610240040_ag_discovery_preferences.js.map +1 -0
  282. package/dist/database/migrations/202610250001_ag_comment_runner_consent.d.ts +4 -0
  283. package/dist/database/migrations/202610250001_ag_comment_runner_consent.d.ts.map +1 -0
  284. package/dist/database/migrations/202610250001_ag_comment_runner_consent.js +41 -0
  285. package/dist/database/migrations/202610250001_ag_comment_runner_consent.js.map +1 -0
  286. package/dist/database/migrations/202610260001_ag_drop_directory_index.d.ts +4 -0
  287. package/dist/database/migrations/202610260001_ag_drop_directory_index.d.ts.map +1 -0
  288. package/dist/database/migrations/202610260001_ag_drop_directory_index.js +24 -0
  289. package/dist/database/migrations/202610260001_ag_drop_directory_index.js.map +1 -0
  290. package/dist/database/migrations/202610260001_ag_run_revision.d.ts +4 -0
  291. package/dist/database/migrations/202610260001_ag_run_revision.d.ts.map +1 -0
  292. package/dist/database/migrations/202610260001_ag_run_revision.js +19 -0
  293. package/dist/database/migrations/202610260001_ag_run_revision.js.map +1 -0
  294. package/dist/database/migrations/202610270001_ag_online_agent.d.ts +4 -0
  295. package/dist/database/migrations/202610270001_ag_online_agent.d.ts.map +1 -0
  296. package/dist/database/migrations/202610270001_ag_online_agent.js +43 -0
  297. package/dist/database/migrations/202610270001_ag_online_agent.js.map +1 -0
  298. package/dist/database/migrations/202610270002_ag_chat_list_visibility.d.ts +4 -0
  299. package/dist/database/migrations/202610270002_ag_chat_list_visibility.d.ts.map +1 -0
  300. package/dist/database/migrations/202610270002_ag_chat_list_visibility.js +17 -0
  301. package/dist/database/migrations/202610270002_ag_chat_list_visibility.js.map +1 -0
  302. package/dist/package.json +34 -12
  303. package/dist/server/cli/run-credential.js +1 -1
  304. package/dist/server/cli/surface.d.ts.map +1 -1
  305. package/dist/server/cli/surface.js +4 -1
  306. package/dist/server/cli/surface.js.map +1 -1
  307. package/dist/server/composition.d.ts +36 -35
  308. package/dist/server/composition.d.ts.map +1 -1
  309. package/dist/server/composition.js +99 -66
  310. package/dist/server/composition.js.map +1 -1
  311. package/dist/server/core/agents/agent.service.d.ts +51 -43
  312. package/dist/server/core/agents/agent.service.d.ts.map +1 -1
  313. package/dist/server/core/agents/agent.service.js +347 -321
  314. package/dist/server/core/agents/agent.service.js.map +1 -1
  315. package/dist/server/core/agents/agent.store.d.ts +26 -12
  316. package/dist/server/core/agents/agent.store.d.ts.map +1 -1
  317. package/dist/server/core/agents/agent.store.js +74 -66
  318. package/dist/server/core/agents/agent.store.js.map +1 -1
  319. package/dist/server/core/agents/agent.views.d.ts +29 -0
  320. package/dist/server/core/agents/agent.views.d.ts.map +1 -0
  321. package/dist/server/core/agents/agent.views.js +88 -0
  322. package/dist/server/core/agents/agent.views.js.map +1 -0
  323. package/dist/server/core/agents/discovery.d.ts +12 -0
  324. package/dist/server/core/agents/discovery.d.ts.map +1 -0
  325. package/dist/server/core/agents/discovery.js +39 -0
  326. package/dist/server/core/agents/discovery.js.map +1 -0
  327. package/dist/server/core/agents/index.d.ts +3 -2
  328. package/dist/server/core/agents/index.d.ts.map +1 -1
  329. package/dist/server/core/agents/index.js +3 -2
  330. package/dist/server/core/agents/index.js.map +1 -1
  331. package/dist/server/core/brief/brief.js +3 -3
  332. package/dist/server/core/brief/brief.js.map +1 -1
  333. package/dist/server/core/callers/index.d.ts +10 -1
  334. package/dist/server/core/callers/index.d.ts.map +1 -1
  335. package/dist/server/core/callers/index.js +15 -0
  336. package/dist/server/core/callers/index.js.map +1 -1
  337. package/dist/server/core/conversations/attachments.d.ts.map +1 -1
  338. package/dist/server/core/conversations/attachments.js +6 -1
  339. package/dist/server/core/conversations/attachments.js.map +1 -1
  340. package/dist/server/core/conversations/availability.d.ts +6 -11
  341. package/dist/server/core/conversations/availability.d.ts.map +1 -1
  342. package/dist/server/core/conversations/availability.js +11 -15
  343. package/dist/server/core/conversations/availability.js.map +1 -1
  344. package/dist/server/core/conversations/chat-settings.d.ts +2 -2
  345. package/dist/server/core/conversations/chat-settings.d.ts.map +1 -1
  346. package/dist/server/core/conversations/chat-settings.js +17 -22
  347. package/dist/server/core/conversations/chat-settings.js.map +1 -1
  348. package/dist/server/core/conversations/conversation.service.d.ts +13 -8
  349. package/dist/server/core/conversations/conversation.service.d.ts.map +1 -1
  350. package/dist/server/core/conversations/conversation.service.js +397 -383
  351. package/dist/server/core/conversations/conversation.service.js.map +1 -1
  352. package/dist/server/core/conversations/conversation.store.d.ts +3 -0
  353. package/dist/server/core/conversations/conversation.store.d.ts.map +1 -1
  354. package/dist/server/core/conversations/conversation.store.js +2 -1
  355. package/dist/server/core/conversations/conversation.store.js.map +1 -1
  356. package/dist/server/core/conversations/page-context.d.ts +8 -2
  357. package/dist/server/core/conversations/page-context.d.ts.map +1 -1
  358. package/dist/server/core/conversations/page-context.js +61 -2
  359. package/dist/server/core/conversations/page-context.js.map +1 -1
  360. package/dist/server/core/conversations/ports.d.ts +18 -20
  361. package/dist/server/core/conversations/ports.d.ts.map +1 -1
  362. package/dist/server/core/reports/model-usage.d.ts.map +1 -1
  363. package/dist/server/core/reports/model-usage.js +42 -44
  364. package/dist/server/core/reports/model-usage.js.map +1 -1
  365. package/dist/server/core/reports/prices.d.ts.map +1 -1
  366. package/dist/server/core/reports/prices.js +29 -5
  367. package/dist/server/core/reports/prices.js.map +1 -1
  368. package/dist/server/core/reports/report.service.d.ts +4 -2
  369. package/dist/server/core/reports/report.service.d.ts.map +1 -1
  370. package/dist/server/core/reports/report.service.js +148 -66
  371. package/dist/server/core/reports/report.service.js.map +1 -1
  372. package/dist/server/core/runs/access.d.ts +5 -0
  373. package/dist/server/core/runs/access.d.ts.map +1 -0
  374. package/dist/server/core/runs/access.js +10 -0
  375. package/dist/server/core/runs/access.js.map +1 -0
  376. package/dist/server/core/runs/availability.d.ts +18 -6
  377. package/dist/server/core/runs/availability.d.ts.map +1 -1
  378. package/dist/server/core/runs/availability.js +40 -34
  379. package/dist/server/core/runs/availability.js.map +1 -1
  380. package/dist/server/core/runs/claim.d.ts +30 -106
  381. package/dist/server/core/runs/claim.d.ts.map +1 -1
  382. package/dist/server/core/runs/claim.js +630 -323
  383. package/dist/server/core/runs/claim.js.map +1 -1
  384. package/dist/server/core/runs/comment-consent.d.ts +24 -0
  385. package/dist/server/core/runs/comment-consent.d.ts.map +1 -0
  386. package/dist/server/core/runs/comment-consent.js +116 -0
  387. package/dist/server/core/runs/comment-consent.js.map +1 -0
  388. package/dist/server/core/runs/eligibility.d.ts +13 -1
  389. package/dist/server/core/runs/eligibility.d.ts.map +1 -1
  390. package/dist/server/core/runs/eligibility.js +41 -10
  391. package/dist/server/core/runs/eligibility.js.map +1 -1
  392. package/dist/server/core/runs/execution-view.d.ts +8 -0
  393. package/dist/server/core/runs/execution-view.d.ts.map +1 -1
  394. package/dist/server/core/runs/execution-view.js +9 -0
  395. package/dist/server/core/runs/execution-view.js.map +1 -1
  396. package/dist/server/core/runs/execution.d.ts +1 -1
  397. package/dist/server/core/runs/execution.d.ts.map +1 -1
  398. package/dist/server/core/runs/execution.js +8 -2
  399. package/dist/server/core/runs/execution.js.map +1 -1
  400. package/dist/server/core/runs/identity.d.ts +9 -0
  401. package/dist/server/core/runs/identity.d.ts.map +1 -0
  402. package/dist/server/core/runs/identity.js +75 -0
  403. package/dist/server/core/runs/identity.js.map +1 -0
  404. package/dist/server/core/runs/index.d.ts +6 -6
  405. package/dist/server/core/runs/index.d.ts.map +1 -1
  406. package/dist/server/core/runs/index.js +6 -6
  407. package/dist/server/core/runs/index.js.map +1 -1
  408. package/dist/server/core/runs/input-gate.d.ts +1 -1
  409. package/dist/server/core/runs/input-gate.d.ts.map +1 -1
  410. package/dist/server/core/runs/input-gate.js +4 -2
  411. package/dist/server/core/runs/input-gate.js.map +1 -1
  412. package/dist/server/core/runs/lifecycle.d.ts +16 -18
  413. package/dist/server/core/runs/lifecycle.d.ts.map +1 -1
  414. package/dist/server/core/runs/lifecycle.js +146 -60
  415. package/dist/server/core/runs/lifecycle.js.map +1 -1
  416. package/dist/server/core/runs/policy.d.ts +9 -2
  417. package/dist/server/core/runs/policy.d.ts.map +1 -1
  418. package/dist/server/core/runs/policy.js +17 -8
  419. package/dist/server/core/runs/policy.js.map +1 -1
  420. package/dist/server/core/runs/ports.d.ts +41 -31
  421. package/dist/server/core/runs/ports.d.ts.map +1 -1
  422. package/dist/server/core/runs/ports.js +2 -13
  423. package/dist/server/core/runs/ports.js.map +1 -1
  424. package/dist/server/core/runs/preview.d.ts.map +1 -1
  425. package/dist/server/core/runs/preview.js +1 -3
  426. package/dist/server/core/runs/preview.js.map +1 -1
  427. package/dist/server/core/runs/run-data-purge.d.ts +15 -0
  428. package/dist/server/core/runs/run-data-purge.d.ts.map +1 -0
  429. package/dist/server/core/runs/run-data-purge.js +82 -0
  430. package/dist/server/core/runs/run-data-purge.js.map +1 -0
  431. package/dist/server/core/runs/run-requests.d.ts +25 -0
  432. package/dist/server/core/runs/run-requests.d.ts.map +1 -1
  433. package/dist/server/core/runs/run-requests.js +131 -64
  434. package/dist/server/core/runs/run-requests.js.map +1 -1
  435. package/dist/server/core/runs/run.service.d.ts +39 -3
  436. package/dist/server/core/runs/run.service.d.ts.map +1 -1
  437. package/dist/server/core/runs/run.service.js +729 -102
  438. package/dist/server/core/runs/run.service.js.map +1 -1
  439. package/dist/server/core/runs/run.store.d.ts +11 -0
  440. package/dist/server/core/runs/run.store.d.ts.map +1 -1
  441. package/dist/server/core/runs/run.store.js +39 -11
  442. package/dist/server/core/runs/run.store.js.map +1 -1
  443. package/dist/server/core/runs/runner-view.d.ts +12 -2
  444. package/dist/server/core/runs/runner-view.d.ts.map +1 -1
  445. package/dist/server/core/runs/runner-view.js +55 -13
  446. package/dist/server/core/runs/runner-view.js.map +1 -1
  447. package/dist/server/core/runs/selection.d.ts +13 -0
  448. package/dist/server/core/runs/selection.d.ts.map +1 -0
  449. package/dist/server/core/runs/selection.js +21 -0
  450. package/dist/server/core/runs/selection.js.map +1 -0
  451. package/dist/server/core/runs/sweeper.d.ts +1 -0
  452. package/dist/server/core/runs/sweeper.d.ts.map +1 -1
  453. package/dist/server/core/runs/sweeper.js +66 -17
  454. package/dist/server/core/runs/sweeper.js.map +1 -1
  455. package/dist/server/core/runs/transitions.d.ts +6 -2
  456. package/dist/server/core/runs/transitions.d.ts.map +1 -1
  457. package/dist/server/core/runs/transitions.js +73 -19
  458. package/dist/server/core/runs/transitions.js.map +1 -1
  459. package/dist/server/core/runs/workload.d.ts +17 -5
  460. package/dist/server/core/runs/workload.d.ts.map +1 -1
  461. package/dist/server/core/runs/workload.js +203 -68
  462. package/dist/server/core/runs/workload.js.map +1 -1
  463. package/dist/server/core/skills/skill.service.d.ts +6 -2
  464. package/dist/server/core/skills/skill.service.d.ts.map +1 -1
  465. package/dist/server/core/skills/skill.service.js +87 -66
  466. package/dist/server/core/skills/skill.service.js.map +1 -1
  467. package/dist/server/core/skills/skill.store.d.ts +14 -0
  468. package/dist/server/core/skills/skill.store.d.ts.map +1 -1
  469. package/dist/server/core/skills/skill.store.js +30 -0
  470. package/dist/server/core/skills/skill.store.js.map +1 -1
  471. package/dist/server/core/transaction-read.d.ts +4 -0
  472. package/dist/server/core/transaction-read.d.ts.map +1 -0
  473. package/dist/server/core/transaction-read.js +30 -0
  474. package/dist/server/core/transaction-read.js.map +1 -0
  475. package/dist/server/core/variables/index.d.ts +1 -1
  476. package/dist/server/core/variables/index.d.ts.map +1 -1
  477. package/dist/server/core/variables/index.js.map +1 -1
  478. package/dist/server/core/variables/variable.service.d.ts +18 -0
  479. package/dist/server/core/variables/variable.service.d.ts.map +1 -1
  480. package/dist/server/core/variables/variable.service.js +95 -20
  481. package/dist/server/core/variables/variable.service.js.map +1 -1
  482. package/dist/server/index.d.ts +4 -0
  483. package/dist/server/index.d.ts.map +1 -1
  484. package/dist/server/index.js +3 -0
  485. package/dist/server/index.js.map +1 -1
  486. package/dist/server/jobs/job.service.d.ts +1 -1
  487. package/dist/server/jobs/job.service.d.ts.map +1 -1
  488. package/dist/server/jobs/job.service.js +8 -2
  489. package/dist/server/jobs/job.service.js.map +1 -1
  490. package/dist/server/kernel/events.d.ts +12 -3
  491. package/dist/server/kernel/events.d.ts.map +1 -1
  492. package/dist/server/kernel/events.js.map +1 -1
  493. package/dist/server/kernel/scopes.d.ts +6 -0
  494. package/dist/server/kernel/scopes.d.ts.map +1 -1
  495. package/dist/server/kernel/scopes.js +3 -1
  496. package/dist/server/kernel/scopes.js.map +1 -1
  497. package/dist/server/online/agent/configuration.d.ts +26 -0
  498. package/dist/server/online/agent/configuration.d.ts.map +1 -0
  499. package/dist/server/online/agent/configuration.js +261 -0
  500. package/dist/server/online/agent/configuration.js.map +1 -0
  501. package/dist/server/online/agent/contracts.d.ts +87 -0
  502. package/dist/server/online/agent/contracts.d.ts.map +1 -0
  503. package/dist/server/online/agent/contracts.js +2 -0
  504. package/dist/server/online/agent/contracts.js.map +1 -0
  505. package/dist/server/online/agent/errors.d.ts +11 -0
  506. package/dist/server/online/agent/errors.d.ts.map +1 -0
  507. package/dist/server/online/agent/errors.js +21 -0
  508. package/dist/server/online/agent/errors.js.map +1 -0
  509. package/dist/server/online/agent/index.d.ts +11 -0
  510. package/dist/server/online/agent/index.d.ts.map +1 -0
  511. package/dist/server/online/agent/index.js +9 -0
  512. package/dist/server/online/agent/index.js.map +1 -0
  513. package/dist/server/online/agent/messages/json.d.ts +5 -0
  514. package/dist/server/online/agent/messages/json.d.ts.map +1 -0
  515. package/dist/server/online/agent/messages/json.js +88 -0
  516. package/dist/server/online/agent/messages/json.js.map +1 -0
  517. package/dist/server/online/agent/messages/projection.d.ts +20 -0
  518. package/dist/server/online/agent/messages/projection.d.ts.map +1 -0
  519. package/dist/server/online/agent/messages/projection.js +495 -0
  520. package/dist/server/online/agent/messages/projection.js.map +1 -0
  521. package/dist/server/online/agent/messages/validation.d.ts +7 -0
  522. package/dist/server/online/agent/messages/validation.d.ts.map +1 -0
  523. package/dist/server/online/agent/messages/validation.js +159 -0
  524. package/dist/server/online/agent/messages/validation.js.map +1 -0
  525. package/dist/server/online/agent/native/backend.d.ts +60 -0
  526. package/dist/server/online/agent/native/backend.d.ts.map +1 -0
  527. package/dist/server/online/agent/native/backend.js +411 -0
  528. package/dist/server/online/agent/native/backend.js.map +1 -0
  529. package/dist/server/online/agent/native/execution.d.ts +41 -0
  530. package/dist/server/online/agent/native/execution.d.ts.map +1 -0
  531. package/dist/server/online/agent/native/execution.js +430 -0
  532. package/dist/server/online/agent/native/execution.js.map +1 -0
  533. package/dist/server/online/agent/native/session.d.ts +40 -0
  534. package/dist/server/online/agent/native/session.d.ts.map +1 -0
  535. package/dist/server/online/agent/native/session.js +104 -0
  536. package/dist/server/online/agent/native/session.js.map +1 -0
  537. package/dist/server/online/agent/native/types.d.ts +32 -0
  538. package/dist/server/online/agent/native/types.d.ts.map +1 -0
  539. package/dist/server/online/agent/native/types.js +2 -0
  540. package/dist/server/online/agent/native/types.js.map +1 -0
  541. package/dist/server/online/agent/persistence/manager.d.ts +16 -0
  542. package/dist/server/online/agent/persistence/manager.d.ts.map +1 -0
  543. package/dist/server/online/agent/persistence/manager.js +209 -0
  544. package/dist/server/online/agent/persistence/manager.js.map +1 -0
  545. package/dist/server/online/agent/persistence/state.d.ts +11 -0
  546. package/dist/server/online/agent/persistence/state.d.ts.map +1 -0
  547. package/dist/server/online/agent/persistence/state.js +45 -0
  548. package/dist/server/online/agent/persistence/state.js.map +1 -0
  549. package/dist/server/online/agent/persistence/store.d.ts +58 -0
  550. package/dist/server/online/agent/persistence/store.d.ts.map +1 -0
  551. package/dist/server/online/agent/persistence/store.js +634 -0
  552. package/dist/server/online/agent/persistence/store.js.map +1 -0
  553. package/dist/server/online/agent/persistence/types.d.ts +44 -0
  554. package/dist/server/online/agent/persistence/types.d.ts.map +1 -0
  555. package/dist/server/online/agent/persistence/types.js +2 -0
  556. package/dist/server/online/agent/persistence/types.js.map +1 -0
  557. package/dist/server/online/agent/runner/backend.d.ts +57 -0
  558. package/dist/server/online/agent/runner/backend.d.ts.map +1 -0
  559. package/dist/server/online/agent/runner/backend.js +501 -0
  560. package/dist/server/online/agent/runner/backend.js.map +1 -0
  561. package/dist/server/online/agent/runner/projection.d.ts +10 -0
  562. package/dist/server/online/agent/runner/projection.d.ts.map +1 -0
  563. package/dist/server/online/agent/runner/projection.js +171 -0
  564. package/dist/server/online/agent/runner/projection.js.map +1 -0
  565. package/dist/server/online/agent/runner/types.d.ts +44 -0
  566. package/dist/server/online/agent/runner/types.d.ts.map +1 -0
  567. package/dist/server/online/agent/runner/types.js +2 -0
  568. package/dist/server/online/agent/runner/types.js.map +1 -0
  569. package/dist/server/online/agent/service.d.ts +47 -0
  570. package/dist/server/online/agent/service.d.ts.map +1 -0
  571. package/dist/server/online/agent/service.js +111 -0
  572. package/dist/server/online/agent/service.js.map +1 -0
  573. package/dist/server/online/agent/transport/streams.d.ts +54 -0
  574. package/dist/server/online/agent/transport/streams.d.ts.map +1 -0
  575. package/dist/server/online/agent/transport/streams.js +440 -0
  576. package/dist/server/online/agent/transport/streams.js.map +1 -0
  577. package/dist/server/online/agent/types.d.ts +155 -0
  578. package/dist/server/online/agent/types.d.ts.map +1 -0
  579. package/dist/server/online/agent/types.js +2 -0
  580. package/dist/server/online/agent/types.js.map +1 -0
  581. package/dist/server/online/index.d.ts +0 -5
  582. package/dist/server/online/index.d.ts.map +1 -1
  583. package/dist/server/online/index.js +0 -5
  584. package/dist/server/online/index.js.map +1 -1
  585. package/dist/server/online/providers.d.ts.map +1 -1
  586. package/dist/server/online/providers.js +26 -2
  587. package/dist/server/online/providers.js.map +1 -1
  588. package/dist/server/online/routes.d.ts.map +1 -1
  589. package/dist/server/online/routes.js +6 -35
  590. package/dist/server/online/routes.js.map +1 -1
  591. package/dist/server/online/services.d.ts.map +1 -1
  592. package/dist/server/online/services.js +101 -24
  593. package/dist/server/online/services.js.map +1 -1
  594. package/dist/server/providers/agents.d.ts +18 -25
  595. package/dist/server/providers/agents.d.ts.map +1 -1
  596. package/dist/server/providers/agents.js +79 -100
  597. package/dist/server/providers/agents.js.map +1 -1
  598. package/dist/server/providers/runners.d.ts +3 -1
  599. package/dist/server/providers/runners.d.ts.map +1 -1
  600. package/dist/server/providers/runners.js +38 -9
  601. package/dist/server/providers/runners.js.map +1 -1
  602. package/dist/server/routes/admin.d.ts +4 -0
  603. package/dist/server/routes/admin.d.ts.map +1 -1
  604. package/dist/server/routes/admin.js +139 -212
  605. package/dist/server/routes/admin.js.map +1 -1
  606. package/dist/server/routes/chat.d.ts.map +1 -1
  607. package/dist/server/routes/chat.js +313 -164
  608. package/dist/server/routes/chat.js.map +1 -1
  609. package/dist/server/routes/index.d.ts.map +1 -1
  610. package/dist/server/routes/index.js +8 -0
  611. package/dist/server/routes/index.js.map +1 -1
  612. package/dist/server/routes/roster.d.ts.map +1 -1
  613. package/dist/server/routes/roster.js +6 -22
  614. package/dist/server/routes/roster.js.map +1 -1
  615. package/dist/server/routes/run-requests.js +3 -3
  616. package/dist/server/routes/run-requests.js.map +1 -1
  617. package/dist/server/routes/runners/admin.d.ts.map +1 -1
  618. package/dist/server/routes/runners/admin.js +219 -25
  619. package/dist/server/routes/runners/admin.js.map +1 -1
  620. package/dist/server/routes/runners/install.d.ts.map +1 -1
  621. package/dist/server/routes/runners/install.js +7 -2
  622. package/dist/server/routes/runners/install.js.map +1 -1
  623. package/dist/server/routes/runners/runner.d.ts.map +1 -1
  624. package/dist/server/routes/runners/runner.js +2 -0
  625. package/dist/server/routes/runners/runner.js.map +1 -1
  626. package/dist/server/routes/schemas.d.ts +18 -10
  627. package/dist/server/routes/schemas.d.ts.map +1 -1
  628. package/dist/server/routes/schemas.js +498 -153
  629. package/dist/server/routes/schemas.js.map +1 -1
  630. package/dist/server/runners/runner.service.d.ts +47 -4
  631. package/dist/server/runners/runner.service.d.ts.map +1 -1
  632. package/dist/server/runners/runner.service.js +423 -79
  633. package/dist/server/runners/runner.service.js.map +1 -1
  634. package/dist/server/runners/runner.store.d.ts +8 -3
  635. package/dist/server/runners/runner.store.d.ts.map +1 -1
  636. package/dist/server/runners/runner.store.js +63 -6
  637. package/dist/server/runners/runner.store.js.map +1 -1
  638. package/dist/server/runners/slots.d.ts +5 -2
  639. package/dist/server/runners/slots.d.ts.map +1 -1
  640. package/dist/server/runners/slots.js +3 -4
  641. package/dist/server/runners/slots.js.map +1 -1
  642. package/dist/server/runners/workspaces.d.ts.map +1 -1
  643. package/dist/server/runners/workspaces.js +18 -2
  644. package/dist/server/runners/workspaces.js.map +1 -1
  645. package/dist/server/testing.d.ts +0 -2
  646. package/dist/server/testing.d.ts.map +1 -1
  647. package/dist/server/testing.js +1 -4
  648. package/dist/server/testing.js.map +1 -1
  649. package/dist/server/tokens.d.ts +8 -7
  650. package/dist/server/tokens.d.ts.map +1 -1
  651. package/dist/server/tokens.js +4 -2
  652. package/dist/server/tokens.js.map +1 -1
  653. package/dist/shared/access.d.ts +2 -6
  654. package/dist/shared/access.d.ts.map +1 -1
  655. package/dist/shared/access.js +2 -6
  656. package/dist/shared/access.js.map +1 -1
  657. package/dist/shared/agents.d.ts +131 -169
  658. package/dist/shared/agents.d.ts.map +1 -1
  659. package/dist/shared/agents.js +36 -102
  660. package/dist/shared/agents.js.map +1 -1
  661. package/dist/shared/conversations.d.ts +93 -170
  662. package/dist/shared/conversations.d.ts.map +1 -1
  663. package/dist/shared/conversations.js +8 -30
  664. package/dist/shared/conversations.js.map +1 -1
  665. package/dist/shared/model-catalog.d.ts +53 -0
  666. package/dist/shared/model-catalog.d.ts.map +1 -0
  667. package/dist/shared/model-catalog.js +182 -0
  668. package/dist/shared/model-catalog.js.map +1 -0
  669. package/dist/shared/online-agent.d.ts +3 -0
  670. package/dist/shared/online-agent.d.ts.map +1 -0
  671. package/dist/shared/online-agent.js +3 -0
  672. package/dist/shared/online-agent.js.map +1 -0
  673. package/dist/shared/page-ui-context.d.ts +26 -0
  674. package/dist/shared/page-ui-context.d.ts.map +1 -0
  675. package/dist/shared/page-ui-context.js +129 -0
  676. package/dist/shared/page-ui-context.js.map +1 -0
  677. package/dist/shared/quota.d.ts +15 -0
  678. package/dist/shared/quota.d.ts.map +1 -0
  679. package/dist/shared/quota.js +2 -0
  680. package/dist/shared/quota.js.map +1 -0
  681. package/dist/shared/runners.d.ts +132 -14
  682. package/dist/shared/runners.d.ts.map +1 -1
  683. package/dist/shared/runners.js +171 -11
  684. package/dist/shared/runners.js.map +1 -1
  685. package/dist/shared/runs.d.ts +59 -1
  686. package/dist/shared/runs.d.ts.map +1 -1
  687. package/dist/shared/runs.js +28 -0
  688. package/dist/shared/runs.js.map +1 -1
  689. package/dist/shared/skills.d.ts +11 -5
  690. package/dist/shared/skills.d.ts.map +1 -1
  691. package/dist/shared/skills.js +7 -2
  692. package/dist/shared/skills.js.map +1 -1
  693. package/dist/shared/ui-message.d.ts +80 -0
  694. package/dist/shared/ui-message.d.ts.map +1 -0
  695. package/dist/shared/ui-message.js +153 -0
  696. package/dist/shared/ui-message.js.map +1 -0
  697. package/dist/shared/variables.js +1 -1
  698. package/dist/shared/variables.js.map +1 -1
  699. package/docs/ai-forms.md +346 -0
  700. package/docs/execution-history.md +19 -0
  701. package/docs/mysql-installation-upgrade.md +7 -0
  702. package/docs/runner-agents.md +27 -0
  703. package/docs/ui-message-clients.md +80 -0
  704. package/docs/ui-messages.md +209 -0
  705. package/docs/workspace-cleanup.md +13 -0
  706. package/package.json +39 -25
  707. package/skills/nocobase-app-plugin-agents/SKILL.md +16 -13
  708. package/skills/nocobase-app-plugin-agents/references/agents.md +30 -0
  709. package/skills/nocobase-app-plugin-agents/references/extension-points.md +21 -21
  710. package/skills/nocobase-app-plugin-agents/references/model-services.md +17 -0
  711. package/skills/nocobase-app-plugin-agents/references/online-agent.md +216 -0
  712. package/skills/nocobase-app-plugin-agents/references/runners.md +12 -0
  713. package/skills/nocobase-app-plugin-agents/references/setup-and-config.md +6 -7
  714. package/skills/nocobase-app-plugin-agents/references/variables-skills-usage.md +6 -4
  715. package/skills/nocobase-app-plugin-agents/references/verification-and-troubleshooting.md +29 -32
  716. package/dist/client/chat/settings-section.d.ts +0 -5
  717. package/dist/client/chat/settings-section.d.ts.map +0 -1
  718. package/dist/client/chat/settings-section.js +0 -86
  719. package/dist/client/chat/settings-section.js.map +0 -1
  720. package/dist/client/components/agent-fields.d.ts +0 -45
  721. package/dist/client/components/agent-fields.d.ts.map +0 -1
  722. package/dist/client/components/agent-fields.js +0 -83
  723. package/dist/client/components/agent-fields.js.map +0 -1
  724. package/dist/client/components/agent-type.d.ts +0 -32
  725. package/dist/client/components/agent-type.d.ts.map +0 -1
  726. package/dist/client/components/agent-type.js +0 -80
  727. package/dist/client/components/agent-type.js.map +0 -1
  728. package/dist/client/components/model-entries.d.ts +0 -44
  729. package/dist/client/components/model-entries.d.ts.map +0 -1
  730. package/dist/client/components/model-entries.js +0 -104
  731. package/dist/client/components/model-entries.js.map +0 -1
  732. package/dist/client/hooks/use-agent-save.d.ts +0 -9
  733. package/dist/client/hooks/use-agent-save.d.ts.map +0 -1
  734. package/dist/client/hooks/use-agent-save.js +0 -40
  735. package/dist/client/hooks/use-agent-save.js.map +0 -1
  736. package/dist/client/hooks/use-model-catalog.d.ts +0 -9
  737. package/dist/client/hooks/use-model-catalog.d.ts.map +0 -1
  738. package/dist/client/hooks/use-model-catalog.js +0 -27
  739. package/dist/client/hooks/use-model-catalog.js.map +0 -1
  740. package/dist/client/lib/model-suggestions.d.ts +0 -28
  741. package/dist/client/lib/model-suggestions.d.ts.map +0 -1
  742. package/dist/client/lib/model-suggestions.js +0 -44
  743. package/dist/client/lib/model-suggestions.js.map +0 -1
  744. package/dist/client/lib/tool-policy.d.ts +0 -3
  745. package/dist/client/lib/tool-policy.d.ts.map +0 -1
  746. package/dist/client/lib/tool-policy.js +0 -5
  747. package/dist/client/lib/tool-policy.js.map +0 -1
  748. package/dist/client/online/default-model.d.ts +0 -5
  749. package/dist/client/online/default-model.d.ts.map +0 -1
  750. package/dist/client/online/default-model.js +0 -65
  751. package/dist/client/online/default-model.js.map +0 -1
  752. package/dist/client/pages/agents/agent-model.d.ts +0 -69
  753. package/dist/client/pages/agents/agent-model.d.ts.map +0 -1
  754. package/dist/client/pages/agents/agent-model.js +0 -153
  755. package/dist/client/pages/agents/agent-model.js.map +0 -1
  756. package/dist/client/pages/agents/detail/brief-preview.d.ts +0 -7
  757. package/dist/client/pages/agents/detail/brief-preview.d.ts.map +0 -1
  758. package/dist/client/pages/agents/detail/brief-preview.js +0 -43
  759. package/dist/client/pages/agents/detail/brief-preview.js.map +0 -1
  760. package/dist/client/pages/agents/detail/history.d.ts +0 -11
  761. package/dist/client/pages/agents/detail/history.d.ts.map +0 -1
  762. package/dist/client/pages/agents/detail/history.js +0 -149
  763. package/dist/client/pages/agents/detail/history.js.map +0 -1
  764. package/dist/client/pages/agents/detail/index.d.ts +0 -3
  765. package/dist/client/pages/agents/detail/index.d.ts.map +0 -1
  766. package/dist/client/pages/agents/detail/index.js +0 -241
  767. package/dist/client/pages/agents/detail/index.js.map +0 -1
  768. package/dist/client/pages/agents/detail/sections.d.ts +0 -21
  769. package/dist/client/pages/agents/detail/sections.d.ts.map +0 -1
  770. package/dist/client/pages/agents/detail/sections.js +0 -280
  771. package/dist/client/pages/agents/detail/sections.js.map +0 -1
  772. package/dist/client/pages/agents/detail/tab-draft.d.ts +0 -43
  773. package/dist/client/pages/agents/detail/tab-draft.d.ts.map +0 -1
  774. package/dist/client/pages/agents/detail/tab-draft.js +0 -115
  775. package/dist/client/pages/agents/detail/tab-draft.js.map +0 -1
  776. package/dist/client/pages/agents/detail/unsaved-bar.d.ts +0 -13
  777. package/dist/client/pages/agents/detail/unsaved-bar.d.ts.map +0 -1
  778. package/dist/client/pages/agents/detail/unsaved-bar.js +0 -21
  779. package/dist/client/pages/agents/detail/unsaved-bar.js.map +0 -1
  780. package/dist/client/pages/agents/new.d.ts +0 -3
  781. package/dist/client/pages/agents/new.d.ts.map +0 -1
  782. package/dist/client/pages/agents/new.js +0 -149
  783. package/dist/client/pages/agents/new.js.map +0 -1
  784. package/dist/client/pages/agents/preset-picker.d.ts +0 -8
  785. package/dist/client/pages/agents/preset-picker.d.ts.map +0 -1
  786. package/dist/client/pages/agents/preset-picker.js +0 -41
  787. package/dist/client/pages/agents/preset-picker.js.map +0 -1
  788. package/dist/server/core/consultations/consultation.service.d.ts +0 -59
  789. package/dist/server/core/consultations/consultation.service.d.ts.map +0 -1
  790. package/dist/server/core/consultations/consultation.service.js +0 -198
  791. package/dist/server/core/consultations/consultation.service.js.map +0 -1
  792. package/dist/server/core/consultations/index.d.ts +0 -3
  793. package/dist/server/core/consultations/index.d.ts.map +0 -1
  794. package/dist/server/core/consultations/index.js +0 -3
  795. package/dist/server/core/consultations/index.js.map +0 -1
  796. package/dist/server/core/consultations/prompt.d.ts +0 -41
  797. package/dist/server/core/consultations/prompt.d.ts.map +0 -1
  798. package/dist/server/core/consultations/prompt.js +0 -64
  799. package/dist/server/core/consultations/prompt.js.map +0 -1
  800. package/dist/server/core/presets/index.d.ts +0 -19
  801. package/dist/server/core/presets/index.d.ts.map +0 -1
  802. package/dist/server/core/presets/index.js +0 -28
  803. package/dist/server/core/presets/index.js.map +0 -1
  804. package/dist/server/online/cli-command.d.ts +0 -20
  805. package/dist/server/online/cli-command.d.ts.map +0 -1
  806. package/dist/server/online/cli-command.js +0 -345
  807. package/dist/server/online/cli-command.js.map +0 -1
  808. package/dist/server/online/consult-tool.d.ts +0 -54
  809. package/dist/server/online/consult-tool.d.ts.map +0 -1
  810. package/dist/server/online/consult-tool.js +0 -177
  811. package/dist/server/online/consult-tool.js.map +0 -1
  812. package/dist/server/online/executor.d.ts +0 -83
  813. package/dist/server/online/executor.d.ts.map +0 -1
  814. package/dist/server/online/executor.js +0 -714
  815. package/dist/server/online/executor.js.map +0 -1
  816. package/dist/server/online/sandbox.d.ts +0 -32
  817. package/dist/server/online/sandbox.d.ts.map +0 -1
  818. package/dist/server/online/sandbox.js +0 -246
  819. package/dist/server/online/sandbox.js.map +0 -1
  820. package/dist/server/online/scripted.d.ts +0 -12
  821. package/dist/server/online/scripted.d.ts.map +0 -1
  822. package/dist/server/online/scripted.js +0 -176
  823. package/dist/server/online/scripted.js.map +0 -1
  824. package/dist/server/online/tools.d.ts +0 -17
  825. package/dist/server/online/tools.d.ts.map +0 -1
  826. package/dist/server/online/tools.js +0 -31
  827. package/dist/server/online/tools.js.map +0 -1
  828. package/dist/server/vendor/THIRD_PARTY_LICENSES.txt +0 -782
  829. package/dist/server/vendor/just-bash.d.ts +0 -83
  830. package/dist/server/vendor/just-bash.js +0 -2102
  831. package/dist/shared/presets.d.ts +0 -30
  832. package/dist/shared/presets.d.ts.map +0 -1
  833. package/dist/shared/presets.js +0 -2
  834. package/dist/shared/presets.js.map +0 -1
  835. package/skills/nocobase-app-plugin-agents/references/online-agents.md +0 -31
@@ -9,16 +9,17 @@
9
9
  */
10
10
  import { ProtocolError, TERMINAL_RUN_STATUSES, } from '@nocobase/agent-protocol';
11
11
  import { conflict, forbidden, invalid, notFound, precondition, } from '../../kernel/errors.js';
12
- import { asJson, cleanList, jsonObject } from '../../kernel/values.js';
12
+ import { asJson, cleanList, jsonObject, stringArray, } from '../../kernel/values.js';
13
13
  import { findAgent, lockAgentForClaim } from '../agents/index.js';
14
+ import { agentNamesOf } from '../agents/agent.store.js';
14
15
  import { createRunRequestService, insertRunRequest, } from './run-requests.js';
15
16
  import { authenticateRunToken } from './run-tokens.js';
16
- import { ACTIVE, eventsRepo, findRunRecord, inputsOnSince, inputsRepo, isActive, isTerminal, lastSummary, openRunsOn, pendingInputs, reposRepo, runsOfKey, runsRepo, toInput, toInputView, toRepo, toRun, usageRepo, } from './run.store.js';
17
- import { dialectOf, takesType } from './ports.js';
18
- import { readWorkload } from './workload.js';
17
+ import { ACTIVE, eventsRepo, findRunRecord, inputsOnSince, inputsRepo, isActive, isTerminal, lastSummary, openRunsOn, openRunsOnEach, pendingInputs, reposRepo, runsOfKey, runsRepo, toInput, toInputView, toRepo, toRun, usageRepo, } from './run.store.js';
18
+ import { readQueueWait, readWorkload, } from './workload.js';
19
19
  import { finishRun } from './transitions.js';
20
20
  import { gateInputs, gatePending } from './input-gate.js';
21
21
  import { findBrief, requestReset } from './workspace.store.js';
22
+ import { findCommentRoot, currentCommentOwner, commentConsent, commentFromOwner, } from './comment-consent.js';
22
23
  export const DEFAULT_THREAD = 'main';
23
24
  /**
24
25
  * The run work went into, for a caller that names no responsible (a conversation, a consultation): such work is never
@@ -31,7 +32,9 @@ export function queuedRun(result) {
31
32
  }
32
33
  /** Who a chain of work a run belongs to started with: who confirmed it, else who it was requested by. */
33
34
  function chainSourceOf(run) {
34
- return run.confirmedByUserId ?? run.requestedByUserId ?? run.actorUserId;
35
+ return run.commentRootRunId
36
+ ? (run.requestedByUserId ?? run.actorUserId)
37
+ : (run.confirmedByUserId ?? run.requestedByUserId ?? run.actorUserId);
35
38
  }
36
39
  /** A delay as the moment a run may be claimed, or null for now (and for any moment already past). */
37
40
  function fireAtOf(value, now) {
@@ -42,8 +45,20 @@ function fireAtOf(value, now) {
42
45
  throw invalid('fireAt is not a date.');
43
46
  return at.getTime() > now.getTime() ? at.toISOString() : null;
44
47
  }
48
+ const COMMENT_CANCEL_DETAIL = 'The personal runner request was declined or switched to the commenter.';
45
49
  export function createRunService(deps) {
46
50
  const { tx, ids, clock } = deps;
51
+ /** Ends one unfinished run of a declined chain; a run that moved since it was read rolls the decision back. */
52
+ async function endCommentRun(unit, run, byUserId) {
53
+ const ended = await finishRun(unit, deps, run, {
54
+ status: 'cancelled',
55
+ reason: null,
56
+ detail: COMMENT_CANCEL_DETAIL,
57
+ cancelledById: byUserId,
58
+ });
59
+ if (!ended)
60
+ throw conflict('The comment work changed; read it again.');
61
+ }
47
62
  const require = async (conn, id) => {
48
63
  const run = await findRunRecord(conn, id);
49
64
  if (!run)
@@ -79,22 +94,20 @@ export function createRunService(deps) {
79
94
  const agent = await findAgent(unit.conn, agentId);
80
95
  if (!agent)
81
96
  throw notFound('Agent');
82
- if (agent.archivedAt)
83
- throw precondition('AGENT_ARCHIVED', 'The agent is archived.');
97
+ if (agent.status !== 'enabled')
98
+ throw precondition('AGENT_NOT_ENABLED', 'The agent is not enabled.');
84
99
  if (!deps.agents.mayInvoke(agent, userId))
85
100
  throw forbidden('You may not wake this agent.');
86
101
  return agent;
87
102
  }
88
103
  async function createRun(unit, agent, values) {
89
- if (!takesType(deps.subjects.get(values.subject.kind), agent.type))
90
- throw invalid(`A ${agent.type} agent cannot work on a ${values.subject.kind}.`, { reason: 'AGENT_TYPE_NOT_ALLOWED', agentType: agent.type });
91
104
  const now = clock.now().toISOString();
92
105
  const id = ids.next();
93
106
  await runsRepo(unit.conn).createOne({
94
107
  values: {
95
108
  id,
96
109
  agentId: agent.id,
97
- agentType: agent.type,
110
+ agentType: 'runner',
98
111
  runnerId: null,
99
112
  status: 'queued',
100
113
  priority: values.priority,
@@ -106,6 +119,11 @@ export function createRunService(deps) {
106
119
  subjectKind: values.subject.kind,
107
120
  subjectId: values.subject.id,
108
121
  threadScope: values.threadScope,
122
+ commentRootRunId: values.commentRootRunId === ''
123
+ ? id
124
+ : (values.commentRootRunId ?? null),
125
+ commentExecution: values.commentExecution ?? null,
126
+ commentOwnerKey: values.commentOwnerKey ?? null,
109
127
  actorUserId: values.actorUserId,
110
128
  requestedByUserId: values.requestedByUserId,
111
129
  confirmedByUserId: values.confirmedByUserId,
@@ -113,6 +131,7 @@ export function createRunService(deps) {
113
131
  requires: cleanList([...values.requires]),
114
132
  acceptsInput: false,
115
133
  availableAt: values.availableAt ?? null,
134
+ queueEnteredAt: now,
116
135
  leaseExpiresAt: null,
117
136
  dispatchedAt: null,
118
137
  startedAt: null,
@@ -208,13 +227,93 @@ export function createRunService(deps) {
208
227
  actualModels: models.get(run.id) ?? [],
209
228
  });
210
229
  }
230
+ /** Cross-root appends require both sources to retain the same owner's authorization. */
231
+ async function equivalentCommentAuthority(unit, run, work) {
232
+ if (run.ownerUserId !== work.ownerUserId ||
233
+ (run.commentOwnerKey ?? null) !== (work.commentOwnerKey ?? null) ||
234
+ (run.commentExecution ?? 'owner') !== (work.commentExecution ?? 'owner'))
235
+ return false;
236
+ if ((run.commentRootRunId ?? null) === (work.commentRootRunId ?? null)) {
237
+ if (!run.commentRootRunId)
238
+ return true;
239
+ const root = await findCommentRoot(unit.conn, run.commentRootRunId);
240
+ // Requester execution keeps its own identity; it does not borrow the owner's consent.
241
+ if (root.commentExecution === 'requester')
242
+ return (root.actorUserId === work.actorUserId &&
243
+ (await currentCommentOwner(unit.conn, deps.subjects, root)));
244
+ return await authorizedRoot(root);
245
+ }
246
+ if (work.commentExecution === 'requester' ||
247
+ run.commentExecution === 'requester' ||
248
+ !work.sourceRunId)
249
+ return false;
250
+ const source = await findRunRecord(unit.conn, work.sourceRunId);
251
+ if (!source ||
252
+ source.subjectKind !== run.subjectKind ||
253
+ source.subjectId !== run.subjectId ||
254
+ source.ownerUserId !== run.ownerUserId ||
255
+ source.actorUserId !== run.actorUserId)
256
+ return false;
257
+ const sourceRoot = source.commentRootRunId
258
+ ? await findCommentRoot(unit.conn, source.commentRootRunId)
259
+ : source;
260
+ const targetRoot = run.commentRootRunId
261
+ ? await findCommentRoot(unit.conn, run.commentRootRunId)
262
+ : run;
263
+ return ((await authorizedRoot(sourceRoot)) && (await authorizedRoot(targetRoot)));
264
+ async function authorizedRoot(root) {
265
+ if (!(await currentCommentOwner(unit.conn, deps.subjects, root)))
266
+ return false;
267
+ if (!root.commentRootRunId)
268
+ return chainSourceOf(root) === root.ownerUserId;
269
+ const { decision } = await commentConsent(unit.conn, root);
270
+ if (decision === 'pending' || decision === 'rejected')
271
+ return false;
272
+ return (decision === 'confirmed' || (await commentFromOwner(unit.conn, root)));
273
+ }
274
+ }
211
275
  /**
212
276
  * Queues `work` for `agent`: it joins the run working on its key while that run can still be told, else the run
213
277
  * waiting for it, else starts a new run.
214
278
  */
215
279
  async function queue(unit, agent, work) {
280
+ if (work.commentRootRunId) {
281
+ // A plain read: the root's subject never changes, and the agent lock below serializes the chain's enqueues.
282
+ const root = await findCommentRoot(unit.conn, work.commentRootRunId);
283
+ if (root.subjectKind !== work.subject.kind ||
284
+ root.subjectId !== work.subject.id)
285
+ throw invalid('A comment authorization cannot cross subjects.');
286
+ }
216
287
  // Serializes enqueues and claims for this agent, so a key never gets two waiting runs.
217
288
  await lockAgentForClaim(unit.conn, agent.id, clock.now().toISOString());
289
+ if (work.preferActive) {
290
+ const commentId = jsonObject(work.input.payload).commentId;
291
+ if (typeof commentId === 'string') {
292
+ const prior = await inputsRepo(unit.conn).findOne({
293
+ filter: (f) => f.and([
294
+ f.string('type').eq('comment'),
295
+ f.json('payload').path(['commentId']).eq(commentId),
296
+ f
297
+ .relation('run')
298
+ .some((r) => r.and([
299
+ r.string('agentId').eq(agent.id),
300
+ r.string('subjectKind').eq(work.subject.kind),
301
+ r.string('subjectId').eq(work.subject.id),
302
+ ])),
303
+ ]),
304
+ });
305
+ if (prior) {
306
+ const run = (await findRunRecord(unit.conn, prior.runId));
307
+ return {
308
+ runId: run.id,
309
+ inputId: prior.id,
310
+ outcome: 'appended',
311
+ status: run.status,
312
+ duplicate: true,
313
+ };
314
+ }
315
+ }
316
+ }
218
317
  const key = {
219
318
  agentId: agent.id,
220
319
  subjectKind: work.subject.kind,
@@ -223,24 +322,87 @@ export function createRunService(deps) {
223
322
  };
224
323
  // Only into work done as the same person: merged into another's run, it would borrow their identity, or wait
225
324
  // for a runner that never takes it.
226
- const open = await runsOfKey(unit.conn, key, ['queued', ...ACTIVE], work.actorUserId);
227
- const candidate = open.find((run) => !work.freshSession &&
228
- (run.status === 'dispatched' ||
229
- (run.status === 'running' && Boolean(run.acceptsInput))));
230
- // Joins the working run only when the subject would let the agent act on it now; otherwise it waits in a queued run,
231
- // which the claim admits or cancels.
232
- const working = candidate &&
233
- (await gateInputs(unit.conn, deps, candidate, agent, [
234
- {
325
+ const unfiltered = await runsOfKey(unit.conn, key, ['queued', ...ACTIVE], work.actorUserId);
326
+ const open = unfiltered.filter((run) => (run.commentRootRunId ?? null) === (work.commentRootRunId ?? null) &&
327
+ (run.commentExecution ?? null) === (work.commentExecution ?? null));
328
+ let working;
329
+ for (let candidate of work.preferActive ? unfiltered : open) {
330
+ if (work.freshSession ||
331
+ candidate.cancelRequestedAt ||
332
+ !(candidate.status === 'dispatched' ||
333
+ (candidate.status === 'running' && Boolean(candidate.acceptsInput))))
334
+ continue;
335
+ if (work.preferActive) {
336
+ if (!candidate.runnerId ||
337
+ !['claude', 'codex', 'pi', 'opencode'].includes(candidate.tool ?? ''))
338
+ continue;
339
+ const runner = await deps.runners.find(unit.conn, candidate.runnerId);
340
+ if (!runner?.features.includes('steer'))
341
+ continue;
342
+ }
343
+ for (let attempt = 0; attempt < 4; attempt += 1) {
344
+ if (work.preferActive &&
345
+ !(await equivalentCommentAuthority(unit, candidate, work)))
346
+ break;
347
+ const input = {
235
348
  id: '',
236
349
  at: clock.now().toISOString(),
237
350
  ...work.input,
238
- },
239
- ])).length > 0
240
- ? candidate
241
- : undefined;
351
+ ...(candidate.commentRootRunId
352
+ ? {
353
+ payload: {
354
+ ...jsonObject(work.input.payload),
355
+ commentRootRunId: candidate.commentRootRunId,
356
+ },
357
+ }
358
+ : {}),
359
+ };
360
+ if ((await gateInputs(unit.conn, deps, candidate, agent, [input]))
361
+ .length === 0)
362
+ break;
363
+ const touched = await runsRepo(unit.conn).updateMany({
364
+ filter: (f) => f.and([
365
+ f.string('id').eq(candidate.id),
366
+ f.string('status').eq(candidate.status),
367
+ f.number('revision').eq(candidate.revision),
368
+ f.date('cancelRequestedAt').empty(),
369
+ ]),
370
+ values: { updatedAt: clock.now().toISOString() },
371
+ });
372
+ if (touched.updatedCount === 1) {
373
+ working = candidate;
374
+ break;
375
+ }
376
+ const current = await findRunRecord(unit.conn, candidate.id);
377
+ if (!current ||
378
+ current.cancelRequestedAt ||
379
+ !(current.status === 'dispatched' ||
380
+ (current.status === 'running' && current.acceptsInput)))
381
+ break;
382
+ // A claim/start may change the holder or tool; re-evaluate those on a subsequent dispatch.
383
+ if (current.actorUserId !== work.actorUserId ||
384
+ current.threadScope !== work.threadScope ||
385
+ current.runnerId !== candidate.runnerId ||
386
+ current.tool !== candidate.tool)
387
+ break;
388
+ candidate = current;
389
+ if (attempt === 3)
390
+ throw conflict('The run revision changed during append; retry the dispatch.');
391
+ }
392
+ if (working)
393
+ break;
394
+ }
242
395
  const waiting = open.find((run) => run.status === 'queued');
243
396
  const target = working ?? waiting;
397
+ const commentInput = (rootId) => rootId
398
+ ? {
399
+ ...work.input,
400
+ payload: {
401
+ ...jsonObject(work.input.payload),
402
+ commentRootRunId: rootId,
403
+ },
404
+ }
405
+ : work.input;
244
406
  if (!working && waiting)
245
407
  await hurry(unit, waiting, work.priority, work.fireAt);
246
408
  if (target) {
@@ -249,7 +411,7 @@ export function createRunService(deps) {
249
411
  filter: { id: target.id, status: 'queued' },
250
412
  values: { freshSession: true, updatedAt: clock.now().toISOString() },
251
413
  });
252
- const inputId = await insertInput(unit, target.id, work.input);
414
+ const inputId = await insertInput(unit, target.id, commentInput(target.commentRootRunId));
253
415
  return {
254
416
  runId: target.id,
255
417
  outcome: working ? 'appended' : 'merged',
@@ -258,6 +420,9 @@ export function createRunService(deps) {
258
420
  };
259
421
  }
260
422
  const runId = await createRun(unit, agent, {
423
+ commentRootRunId: work.commentRootRunId,
424
+ commentExecution: work.commentExecution,
425
+ commentOwnerKey: work.commentOwnerKey,
261
426
  freshSession: work.freshSession,
262
427
  subject: work.subject,
263
428
  threadScope: work.threadScope,
@@ -272,16 +437,23 @@ export function createRunService(deps) {
272
437
  ...(work.parentRunId ? { parentRunId: work.parentRunId } : {}),
273
438
  ...(work.maxAttempts ? { maxAttempts: work.maxAttempts } : {}),
274
439
  });
275
- const inputId = await insertInput(unit, runId, work.input);
440
+ const inputId = await insertInput(unit, runId, commentInput(work.commentRootRunId === '' ? runId : work.commentRootRunId));
276
441
  return { runId, outcome: 'created', status: 'queued', inputId };
277
442
  }
278
443
  /** The source of the chain of work a request belongs to (`EnqueueRequest.requestedByUserId`). */
279
444
  async function sourceOf(unit, request) {
445
+ if (request.comment &&
446
+ request.input.actor.kind === 'user' &&
447
+ jsonObject(request.input.payload).byAgent !== true &&
448
+ (request.requestedByUserId ?? request.actorUserId))
449
+ return (request.requestedByUserId ?? request.actorUserId);
280
450
  if (request.causedByRunId) {
281
451
  const cause = await findRunRecord(unit.conn, request.causedByRunId);
282
452
  if (!cause)
283
453
  throw invalid('causedByRunId names no run.');
284
- return chainSourceOf(cause);
454
+ return request.comment
455
+ ? (cause.requestedByUserId ?? cause.actorUserId)
456
+ : chainSourceOf(cause);
285
457
  }
286
458
  const source = request.requestedByUserId ??
287
459
  request.actorUserId ??
@@ -290,10 +462,23 @@ export function createRunService(deps) {
290
462
  throw invalid('Name who woke the agent: actorUserId, requestedByUserId or responsibleUserId.');
291
463
  return source;
292
464
  }
465
+ async function selectedIdentity(unit, request, commentExecution) {
466
+ const identity = await deps.subjects
467
+ .get(request.subject.kind)
468
+ ?.actsAs?.(unit.conn, {
469
+ subjectId: request.subject.id,
470
+ agentId: request.agentId,
471
+ causedByRunId: request.causedByRunId,
472
+ commentExecution,
473
+ actorUserId: request.actorUserId,
474
+ inputs: [request.input],
475
+ });
476
+ if (identity && !identity.actorUserId)
477
+ throw new ProtocolError('FORBIDDEN', 'The subject has no valid execution identity.', { identityReason: identity.reason ?? 'noOwner' });
478
+ return identity;
479
+ }
293
480
  /** Refuses work run as `userId` when no runner they may use can run the agent now: it would only wait. */
294
481
  async function requireRunnerFor(unit, agent, userId, requires) {
295
- if (agent.type !== 'runner')
296
- return;
297
482
  // By the claim's own rules, the agent's variables included; the subject's are the claim's to check.
298
483
  if (!(await deps.eligibility.canClaim(unit.conn, agent, {
299
484
  actorUserId: userId,
@@ -312,26 +497,225 @@ export function createRunService(deps) {
312
497
  mayInvoke: (agent, userId) => deps.agents.mayInvoke(agent, userId),
313
498
  requireInvocable,
314
499
  requireRunnerFor,
315
- direct: (unit, run) => queue(unit, run.agent, {
316
- freshSession: run.freshSession,
317
- subject: run.subject,
318
- threadScope: run.threadScope,
319
- actorUserId: run.actorUserId,
320
- requestedByUserId: run.requestedByUserId,
321
- confirmedByUserId: run.confirmedByUserId,
322
- ownerUserId: run.ownerUserId,
323
- priority: run.priority,
324
- // As it was asked: a moment already past when it is confirmed means now.
325
- fireAt: fireAtOf(run.fireAt ?? undefined, clock.now()),
326
- requires: run.requires,
327
- ...(run.maxAttempts === null ? {} : { maxAttempts: run.maxAttempts }),
328
- input: run.input,
329
- }),
500
+ prepareCommentActor: async (record, byUserId) => {
501
+ const mayRead = deps.subjects.get(record.subjectKind)?.commentActorMayRead;
502
+ if (mayRead && !(await mayRead(record.subjectId, byUserId)))
503
+ throw forbidden('The acting user may no longer read this issue.');
504
+ },
505
+ checkCommentRequest: async (unit, record) => {
506
+ const root = await findCommentRoot(unit.conn, record.commentRootRunId);
507
+ if (!(await currentCommentOwner(unit.conn, deps.subjects, root)) ||
508
+ root.commentExecution !== 'owner' ||
509
+ root.ownerUserId !== record.responsibleUserId ||
510
+ (root.commentOwnerKey ?? null) !== (record.commentOwnerKey ?? null))
511
+ throw precondition('RUN_REQUEST_SETTLED', 'This comment request belongs to an earlier owner assignment.');
512
+ },
513
+ releaseCommentRequest: async (unit, record, byUserId) => {
514
+ const run = await findRunRecord(unit.conn, record.commentRunId);
515
+ if (!run ||
516
+ run.status !== 'queued' ||
517
+ run.commentRootRunId !== record.commentRootRunId)
518
+ throw precondition('RUN_REQUEST_SETTLED', 'The requested work is no longer waiting.');
519
+ const inputs = await pendingInputs(unit.conn, run.id);
520
+ const now = clock.now().toISOString();
521
+ // Guarded on the requested run itself: a claim that took it first wins, and this confirmation rolls back.
522
+ const released = await runsRepo(unit.conn).updateMany({
523
+ filter: { id: run.id, status: 'queued' },
524
+ values: { confirmedByUserId: byUserId, updatedAt: now },
525
+ });
526
+ if (released.updatedCount !== 1)
527
+ throw precondition('RUN_REQUEST_SETTLED', 'The requested work is no longer waiting.');
528
+ await runsRepo(unit.conn).updateMany({
529
+ filter: {
530
+ commentRootRunId: record.commentRootRunId,
531
+ status: 'queued',
532
+ actorUserId: record.responsibleUserId,
533
+ },
534
+ values: { confirmedByUserId: byUserId, updatedAt: now },
535
+ });
536
+ unit.emit({ type: 'run.changed', runId: run.id, status: 'queued' });
537
+ return {
538
+ runId: run.id,
539
+ outcome: 'merged',
540
+ status: 'queued',
541
+ inputId: inputs[0].id,
542
+ };
543
+ },
544
+ cancelCommentRequest: async (unit, record, byUserId) => {
545
+ for (const run of await runsRepo(unit.conn).findMany({
546
+ filter: { commentRootRunId: record.commentRootRunId },
547
+ }))
548
+ if (!isTerminal(run.status))
549
+ await endCommentRun(unit, run, byUserId);
550
+ },
551
+ runCommentAsRequester: async (unit, record, byUserId) => {
552
+ // Queuing the replacements takes their agents' rows, as claims do before they take a run. Taking every agent of
553
+ // the chain first, in one order, keeps this from holding a run a claim waits on while it waits for that claim.
554
+ const agentIds = new Set((await runsRepo(unit.conn).findMany({
555
+ filter: { commentRootRunId: record.commentRootRunId },
556
+ })).map((run) => run.agentId));
557
+ for (const agentId of [...agentIds].sort())
558
+ await lockAgentForClaim(unit.conn, agentId, clock.now().toISOString());
559
+ const chain = await runsRepo(unit.conn).findMany({
560
+ filter: { commentRootRunId: record.commentRootRunId },
561
+ sort: (sort) => [sort.field('createdAt').asc(), sort.field('id').asc()],
562
+ });
563
+ const targets = [];
564
+ for (const old of chain) {
565
+ // Rejection ends the queued chain, but leaves its inputs unhandled. Do not revive independently ended work.
566
+ const declined = record.status === 'rejected' &&
567
+ old.status === 'cancelled' &&
568
+ old.cancelledById === record.responsibleUserId &&
569
+ old.failureDetail === COMMENT_CANCEL_DETAIL;
570
+ if (isTerminal(old.status) && !declined)
571
+ continue;
572
+ const inputs = await pendingInputs(unit.conn, old.id);
573
+ if (inputs.length === 0)
574
+ continue;
575
+ await selectedIdentity(unit, {
576
+ agentId: old.agentId,
577
+ subject: { kind: old.subjectKind, id: old.subjectId },
578
+ input: toInput(inputs[0]),
579
+ actorUserId: byUserId,
580
+ }, 'requester');
581
+ const agent = await requireInvocable(unit, old.agentId, byUserId);
582
+ const requires = stringArray(old.requires);
583
+ await requireRunnerFor(unit, agent, byUserId, requires);
584
+ targets.push({ old, inputs, agent, requires });
585
+ }
586
+ if (!targets.length)
587
+ throw precondition('RUN_REQUEST_SETTLED', 'No comment work is still waiting.');
588
+ // Validate all targets before stopping any of them. Each stop is guarded on the status read, so a run a claim took
589
+ // meanwhile rolls this back rather than being replaced twice; the settled request covers repeat clicks.
590
+ for (const old of chain)
591
+ if (!isTerminal(old.status))
592
+ await endCommentRun(unit, old, byUserId);
593
+ const replacements = new Map();
594
+ let rootId;
595
+ for (const { old, inputs, agent, requires } of targets) {
596
+ const first = inputs[0];
597
+ const next = await queue(unit, agent, {
598
+ commentRootRunId: rootId ?? '',
599
+ commentExecution: 'requester',
600
+ commentOwnerKey: record.commentOwnerKey ?? null,
601
+ freshSession: Boolean(old.freshSession),
602
+ subject: { kind: old.subjectKind, id: old.subjectId },
603
+ threadScope: old.threadScope,
604
+ actorUserId: byUserId,
605
+ requestedByUserId: byUserId,
606
+ confirmedByUserId: null,
607
+ ownerUserId: old.ownerUserId,
608
+ priority: Number(old.priority),
609
+ fireAt: fireAtOf(old.availableAt ?? undefined, clock.now()),
610
+ requires,
611
+ maxAttempts: Number(old.maxAttempts),
612
+ input: toInput(first),
613
+ });
614
+ rootId ??= next.runId;
615
+ replacements.set(old.id, next);
616
+ for (const input of inputs.slice(1))
617
+ await insertInput(unit, next.runId, {
618
+ ...toInput(input),
619
+ payload: { ...jsonObject(input.payload), commentRootRunId: rootId },
620
+ });
621
+ }
622
+ // Remap causal references only for replaced work; completed ancestors remain the original historical runs.
623
+ for (const { old } of targets) {
624
+ const next = replacements.get(old.id);
625
+ if (old.parentRunId)
626
+ await runsRepo(unit.conn).updateMany({
627
+ filter: { id: next.runId },
628
+ values: {
629
+ parentRunId: replacements.get(old.parentRunId)?.runId ?? old.parentRunId,
630
+ },
631
+ });
632
+ for (const input of await pendingInputs(unit.conn, next.runId)) {
633
+ const payload = jsonObject(input.payload);
634
+ const cause = typeof payload.causedByRunId === 'string'
635
+ ? replacements.get(payload.causedByRunId)
636
+ : undefined;
637
+ if (cause)
638
+ await inputsRepo(unit.conn).updateMany({
639
+ filter: { id: input.id },
640
+ values: {
641
+ payload: asJson({ ...payload, causedByRunId: cause.runId }),
642
+ },
643
+ });
644
+ }
645
+ }
646
+ const rootInputs = await pendingInputs(unit.conn, rootId);
647
+ if (!rootInputs.some((input) => input.type === record.inputType &&
648
+ input.text === record.inputText &&
649
+ jsonObject(input.payload).commentId ===
650
+ jsonObject(record.inputPayload).commentId)) {
651
+ const sourceId = await insertInput(unit, rootId, {
652
+ type: record.inputType,
653
+ actor: {
654
+ kind: record.inputActorKind,
655
+ id: record.inputActorId,
656
+ name: record.inputActorName,
657
+ },
658
+ text: record.inputText,
659
+ payload: {
660
+ ...jsonObject(record.inputPayload),
661
+ commentSourceSnapshot: true,
662
+ commentRootRunId: rootId,
663
+ },
664
+ });
665
+ await inputsRepo(unit.conn).updateMany({
666
+ filter: { id: sourceId },
667
+ values: { handledAt: clock.now().toISOString() },
668
+ });
669
+ }
670
+ return (replacements.get(record.commentRunId) ??
671
+ replacements.values().next().value);
672
+ },
673
+ direct: async (unit, run) => {
674
+ const identity = await selectedIdentity(unit, {
675
+ agentId: run.agent.id,
676
+ subject: run.subject,
677
+ input: run.input,
678
+ actorUserId: run.actorUserId,
679
+ });
680
+ const actorUserId = identity?.actorUserId ?? run.actorUserId;
681
+ const agent = await requireInvocable(unit, run.agent.id, actorUserId);
682
+ return queue(unit, agent, {
683
+ freshSession: run.freshSession,
684
+ subject: run.subject,
685
+ threadScope: run.threadScope,
686
+ actorUserId,
687
+ requestedByUserId: run.requestedByUserId,
688
+ confirmedByUserId: run.confirmedByUserId,
689
+ ownerUserId: identity ? actorUserId : run.ownerUserId,
690
+ priority: run.priority,
691
+ fireAt: fireAtOf(run.fireAt ?? undefined, clock.now()),
692
+ requires: run.requires,
693
+ ...(run.maxAttempts === null ? {} : { maxAttempts: run.maxAttempts }),
694
+ input: run.input,
695
+ });
696
+ },
330
697
  });
331
698
  return {
332
699
  enqueue: (request, outer) => tx.run(async (unit) => {
333
700
  const source = await sourceOf(unit, request);
334
- const responsible = request.responsibleUserId ?? null;
701
+ const cause = request.causedByRunId
702
+ ? await findRunRecord(unit.conn, request.causedByRunId)
703
+ : null;
704
+ const inherited = !request.comment &&
705
+ cause?.commentRootRunId &&
706
+ cause.subjectKind === request.subject.kind &&
707
+ cause.subjectId === request.subject.id
708
+ ? cause
709
+ : null;
710
+ const commentRootRunId = request.comment?.rootRunId ??
711
+ inherited?.commentRootRunId ??
712
+ (request.comment ? '' : null);
713
+ const commentExecution = inherited?.commentExecution ?? (request.comment ? 'owner' : null);
714
+ const commentOwnerKey = request.comment?.ownerKey ?? inherited?.commentOwnerKey ?? null;
715
+ const identity = await selectedIdentity(unit, request, commentExecution);
716
+ const responsible = identity
717
+ ? null
718
+ : (request.responsibleUserId ?? null);
335
719
  const threadScope = request.threadScope ?? DEFAULT_THREAD;
336
720
  const foreign = responsible !== null && source !== responsible;
337
721
  if (foreign && (request.execution ?? 'auto') === 'auto') {
@@ -342,8 +726,6 @@ export function createRunService(deps) {
342
726
  const agent = await requireInvocable(unit, request.agentId, source);
343
727
  if (!deps.agents.mayInvoke(agent, responsible))
344
728
  throw forbidden('The person who answers for this may not wake this agent.');
345
- if (!takesType(deps.subjects.get(request.subject.kind), agent.type))
346
- throw invalid(`A ${agent.type} agent cannot work on a ${request.subject.kind}.`, { reason: 'AGENT_TYPE_NOT_ALLOWED', agentType: agent.type });
347
729
  const created = await insertRunRequest(unit, { ids, clock }, {
348
730
  agentId: agent.id,
349
731
  freshSession: request.freshSession,
@@ -368,20 +750,30 @@ export function createRunService(deps) {
368
750
  }
369
751
  // As the responsible when they caused it; as the source when they run it as themselves (`mine`); as whoever
370
752
  // woke the agent when nobody answers for the subject.
371
- const actorUserId = foreign
372
- ? source
373
- : (responsible ?? request.actorUserId ?? source);
753
+ const actorUserId = (commentExecution === 'requester'
754
+ ? inherited?.actorUserId
755
+ : identity?.actorUserId) ??
756
+ (foreign ? source : (responsible ?? request.actorUserId ?? source));
374
757
  const agent = await requireInvocable(unit, request.agentId, actorUserId);
375
758
  if (foreign)
376
759
  await requireRunnerFor(unit, agent, actorUserId, request.requires ?? []);
377
- return queue(unit, agent, {
760
+ const result = await queue(unit, agent, {
761
+ preferActive: request.preferActive,
762
+ sourceRunId: request.causedByRunId,
763
+ commentRootRunId,
764
+ commentExecution,
765
+ commentOwnerKey,
378
766
  freshSession: request.freshSession,
379
767
  subject: request.subject,
380
768
  threadScope,
381
769
  actorUserId,
382
770
  requestedByUserId: source,
383
- confirmedByUserId: null,
384
- ownerUserId: request.ownerUserId ?? null,
771
+ confirmedByUserId: inherited?.confirmedByUserId ?? null,
772
+ ownerUserId: commentExecution === 'requester'
773
+ ? (inherited?.ownerUserId ?? request.ownerUserId ?? null)
774
+ : identity
775
+ ? actorUserId
776
+ : (request.ownerUserId ?? null),
385
777
  priority: request.priority ?? 0,
386
778
  fireAt: fireAtOf(request.fireAt, clock.now()),
387
779
  requires: request.requires ?? [],
@@ -389,12 +781,45 @@ export function createRunService(deps) {
389
781
  ...(request.maxAttempts ? { maxAttempts: request.maxAttempts } : {}),
390
782
  input: request.input,
391
783
  });
784
+ if (commentRootRunId !== null)
785
+ await deps.reconcileCommentConsent?.(unit, result.runId);
786
+ return result;
392
787
  }, outer),
393
788
  requests,
789
+ identityInputs: async (conn, runId) => {
790
+ const run = await findRunRecord(conn, runId);
791
+ if (!run)
792
+ return null;
793
+ const inputs = await inputsRepo(conn).findMany({ filter: { runId } });
794
+ return { run: toRun(run), inputs: inputs.map(toInput) };
795
+ },
394
796
  addInput: (runId, input, outer) => tx.run(async (unit) => {
395
797
  const run = await require(unit.conn, runId);
798
+ if (run.commentRootRunId &&
799
+ input.type === 'comment' &&
800
+ jsonObject(input.payload).commentRootRunId !== run.commentRootRunId)
801
+ throw forbidden('A comment must be queued in its own authorized run chain.');
396
802
  if (isTerminal(run.status))
397
803
  throw new ProtocolError('RUN_NOT_ACTIVE', `The run is ${run.status}.`);
804
+ if (isActive(run.status)) {
805
+ let current = run;
806
+ for (let attempt = 0; attempt < 4; attempt += 1) {
807
+ const updated = await runsRepo(unit.conn).updateMany({
808
+ filter: {
809
+ id: current.id,
810
+ status: current.status,
811
+ revision: current.revision,
812
+ },
813
+ values: { updatedAt: clock.now().toISOString() },
814
+ });
815
+ if (updated.updatedCount === 1)
816
+ return insertInput(unit, current.id, input);
817
+ current = await require(unit.conn, run.id);
818
+ if (!isActive(current.status))
819
+ throw conflict('The run moved on before input was appended.');
820
+ }
821
+ throw conflict('The run revision changed during append; retry the input.');
822
+ }
398
823
  return insertInput(unit, run.id, input);
399
824
  }, outer),
400
825
  cancel: (runId, byUserId, outer) => tx.run(async (unit) => {
@@ -459,47 +884,192 @@ export function createRunService(deps) {
459
884
  }
460
885
  return ended;
461
886
  }, outer),
462
- retry: (runId, byUserId) => tx.run(async (unit) => {
463
- const run = await require(unit.conn, runId);
464
- if (run.status !== 'failed' && run.status !== 'cancelled')
465
- throw precondition('RUN_NOT_RETRYABLE', 'Only a failed or cancelled run can be retried.');
466
- if (run.parentRunId)
467
- throw precondition('RUN_NOT_RETRYABLE', 'A consultation is not retried: the agent that asked asks again.');
468
- const agent = await requireInvocable(unit, run.agentId, byUserId);
469
- await lockAgentForClaim(unit.conn, agent.id, clock.now().toISOString());
470
- const open = await runsOfKey(unit.conn, run, ['queued', ...ACTIVE], byUserId);
471
- if (open.length > 0)
472
- throw precondition('AGENT_BUSY', 'The agent is already working on this.', {
473
- runId: open[0].id,
887
+ retry: async (runId, byUserId, source = 'api') => {
888
+ const target = await require(tx.read(), runId);
889
+ // Resolve collection metadata outside the transaction too. The lock must
890
+ // precede consistent reads so repeatable-read databases see a concurrent
891
+ // retry that committed while this request waited for the lock.
892
+ await findAgent(tx.read(), target.agentId);
893
+ return tx.run(async (unit) => {
894
+ await lockAgentForClaim(unit.conn, target.agentId, clock.now().toISOString());
895
+ const run = await require(unit.conn, runId);
896
+ if (run.status !== 'failed' && run.status !== 'cancelled')
897
+ throw precondition('RUN_NOT_RETRYABLE', 'Only a failed or cancelled run can be retried.');
898
+ if (run.parentRunId)
899
+ throw precondition('RUN_NOT_RETRYABLE', 'A consultation is not retried: the agent that asked asks again.');
900
+ // The agent lock serializes retry and enqueue across server instances. Check
901
+ // the relationship even after the replacement has already ended.
902
+ const retried = await runsRepo(unit.conn).findOne({
903
+ filter: { retryOfRunId: run.id },
904
+ sort: (sort) => [
905
+ sort.field('createdAt').asc(),
906
+ sort.field('id').asc(),
907
+ ],
474
908
  });
475
- const newId = await createRun(unit, agent, {
476
- subject: { kind: run.subjectKind, id: run.subjectId },
477
- threadScope: run.threadScope,
478
- actorUserId: byUserId,
479
- requestedByUserId: byUserId,
480
- confirmedByUserId: null,
481
- ownerUserId: run.ownerUserId,
482
- priority: Number(run.priority),
483
- requires: toRun(run).requires,
484
- retryOfRunId: run.id,
485
- freshSession: run.freshSession,
486
- });
487
- for (const input of await pendingInputs(unit.conn, run.id))
909
+ if (retried)
910
+ throw precondition('RUN_ALREADY_RETRIED', 'This run has already been retried.', {
911
+ runId: retried.id,
912
+ });
913
+ const previousInputs = await inputsRepo(unit.conn).findMany({
914
+ filter: { runId: run.id },
915
+ });
916
+ if (!run.commentRootRunId &&
917
+ deps.subjects.get(run.subjectKind)?.commentOwnerKey &&
918
+ previousInputs.some((input) => input.type === 'comment' &&
919
+ !(input.actorKind === 'user' &&
920
+ input.actorId === run.ownerUserId &&
921
+ jsonObject(input.payload).byAgent !== true)))
922
+ throw precondition('RUN_NOT_RETRYABLE', 'Post the comment again to start a new authorized comment chain.');
923
+ const oldRoot = run.commentRootRunId
924
+ ? await findRunRecord(unit.conn, run.commentRootRunId)
925
+ : null;
926
+ const renewComment = oldRoot
927
+ ? !(await currentCommentOwner(unit.conn, deps.subjects, oldRoot))
928
+ : false;
929
+ const commentExecution = renewComment &&
930
+ run.commentExecution === 'requester' &&
931
+ byUserId !== run.actorUserId
932
+ ? 'owner'
933
+ : run.commentExecution;
934
+ const identity = await deps.subjects
935
+ .get(run.subjectKind)
936
+ ?.actsAs?.(unit.conn, {
937
+ subjectId: run.subjectId,
938
+ agentId: run.agentId,
939
+ inputs: previousInputs.map(toInput),
940
+ causedByRunId: run.retryOfRunId ?? undefined,
941
+ commentExecution,
942
+ actorUserId: run.actorUserId,
943
+ });
944
+ if (identity && !identity.actorUserId)
945
+ throw forbidden(identity.reason ?? 'noOwner');
946
+ const actorUserId = commentExecution === 'requester'
947
+ ? run.actorUserId
948
+ : (identity?.actorUserId ?? byUserId);
949
+ const agent = await requireInvocable(unit, run.agentId, actorUserId);
950
+ const open = await runsOfKey(unit.conn, run, ['queued', ...ACTIVE], actorUserId);
951
+ const sameChain = run.commentRootRunId
952
+ ? open.filter((candidate) => candidate.commentRootRunId === run.commentRootRunId)
953
+ : open;
954
+ if (sameChain.length > 0)
955
+ throw precondition('AGENT_BUSY', 'The agent is already working on this.', {
956
+ runId: sameChain[0].id,
957
+ });
958
+ const newId = await createRun(unit, agent, {
959
+ subject: { kind: run.subjectKind, id: run.subjectId },
960
+ threadScope: run.threadScope,
961
+ actorUserId,
962
+ commentRootRunId: renewComment ? '' : run.commentRootRunId,
963
+ commentExecution,
964
+ commentOwnerKey: renewComment
965
+ ? ((await deps.subjects
966
+ .get(run.subjectKind)
967
+ ?.commentOwnerKey?.(unit.conn, run.subjectId)) ?? null)
968
+ : run.commentOwnerKey,
969
+ requestedByUserId: run.commentRootRunId
970
+ ? (run.requestedByUserId ?? run.actorUserId)
971
+ : byUserId,
972
+ confirmedByUserId: null,
973
+ ownerUserId: run.commentRootRunId
974
+ ? ((await deps.subjects
975
+ .get(run.subjectKind)
976
+ ?.responsibleUserId?.(unit.conn, run.subjectId)) ?? null)
977
+ : identity
978
+ ? actorUserId
979
+ : run.ownerUserId,
980
+ priority: Number(run.priority),
981
+ requires: toRun(run).requires,
982
+ retryOfRunId: run.id,
983
+ freshSession: run.freshSession,
984
+ });
985
+ if (renewComment && oldRoot) {
986
+ const origins = await inputsRepo(unit.conn).findMany({
987
+ filter: { runId: oldRoot.id },
988
+ sort: (s) => [s.field('createdAt').asc(), s.field('id').asc()],
989
+ });
990
+ const origin = origins.find((input) => input.type === 'comment' &&
991
+ jsonObject(input.payload).commentSourceSnapshot === true) ?? origins.find((input) => input.type === 'comment');
992
+ if (origin) {
993
+ const snapshotId = await insertInput(unit, newId, {
994
+ type: 'comment',
995
+ actor: toInput(origin).actor,
996
+ text: origin.text,
997
+ payload: {
998
+ ...jsonObject(origin.payload),
999
+ commentRootRunId: newId,
1000
+ commentSourceSnapshot: true,
1001
+ },
1002
+ });
1003
+ await inputsRepo(unit.conn).updateMany({
1004
+ filter: { id: snapshotId },
1005
+ values: { handledAt: clock.now().toISOString() },
1006
+ });
1007
+ }
1008
+ }
1009
+ for (const input of await pendingInputs(unit.conn, run.id))
1010
+ await insertInput(unit, newId, {
1011
+ type: input.type,
1012
+ actor: toInput(input).actor,
1013
+ text: input.text,
1014
+ ...(input.payload === null
1015
+ ? {}
1016
+ : {
1017
+ payload: {
1018
+ ...jsonObject(input.payload),
1019
+ ...(renewComment ? { commentRootRunId: newId } : {}),
1020
+ },
1021
+ }),
1022
+ });
488
1023
  await insertInput(unit, newId, {
489
- type: input.type,
490
- actor: toInput(input).actor,
491
- text: input.text,
492
- ...(input.payload === null ? {} : { payload: input.payload }),
1024
+ type: 'retry',
1025
+ actor: {
1026
+ kind: 'user',
1027
+ id: byUserId,
1028
+ name: (await deps.people.names(unit.conn, [byUserId])).get(byUserId) ??
1029
+ byUserId,
1030
+ },
1031
+ text: 'Retry the work of the previous run.',
1032
+ payload: {
1033
+ retryOfRunId: run.id,
1034
+ failureReason: run.failureReason,
1035
+ source,
1036
+ },
493
1037
  });
494
- await insertInput(unit, newId, {
495
- type: 'retry',
496
- actor: { kind: 'user', id: byUserId, name: byUserId },
497
- text: 'Retry the work of the previous run.',
498
- payload: { retryOfRunId: run.id, failureReason: run.failureReason },
1038
+ unit.emit({
1039
+ type: 'run.retried',
1040
+ runId: newId,
1041
+ retryOfRunId: run.id,
1042
+ previousStatus: run.status,
1043
+ });
1044
+ if (run.commentRootRunId)
1045
+ await deps.reconcileCommentConsent?.(unit, newId);
1046
+ return toRun(await require(unit.conn, newId));
499
1047
  });
500
- return toRun(await require(unit.conn, newId));
501
- }),
1048
+ },
502
1049
  get: async (runId) => (await readRuns([await require(tx.read(), runId)]))[0],
1050
+ async retryInfo(runId) {
1051
+ const conn = tx.read();
1052
+ const next = await runsRepo(conn).findOne({
1053
+ filter: { retryOfRunId: runId },
1054
+ sort: (sort) => [sort.field('createdAt').asc(), sort.field('id').asc()],
1055
+ });
1056
+ if (!next)
1057
+ return null;
1058
+ const input = await inputsRepo(conn).findOne({
1059
+ filter: { runId: next.id, type: 'retry' },
1060
+ sort: (sort) => [
1061
+ sort.field('createdAt').desc(),
1062
+ sort.field('id').desc(),
1063
+ ],
1064
+ });
1065
+ const source = input?.payload?.source;
1066
+ return {
1067
+ runId: next.id,
1068
+ actorUserId: next.actorUserId,
1069
+ actorName: input ? toInputView(input).actor.name : next.actorUserId,
1070
+ source: typeof source === 'string' ? source : 'unknown',
1071
+ };
1072
+ },
503
1073
  async detail(runId) {
504
1074
  const conn = tx.read();
505
1075
  const run = await require(conn, runId);
@@ -508,17 +1078,39 @@ export function createRunService(deps) {
508
1078
  sort: (sort) => [sort.field('createdAt').asc(), sort.field('id').asc()],
509
1079
  });
510
1080
  const repos = await reposRepo(conn).findMany({ filter: { runId } });
1081
+ const retried = await runsRepo(conn).findOne({
1082
+ filter: { retryOfRunId: runId },
1083
+ sort: (sort) => [sort.field('createdAt').asc(), sort.field('id').asc()],
1084
+ });
511
1085
  const children = await runsRepo(conn).findMany({
512
1086
  filter: { parentRunId: runId },
513
1087
  sort: (sort) => [sort.field('createdAt').asc(), sort.field('id').asc()],
514
1088
  });
515
- const names = new Map();
516
- for (const child of children)
517
- if (!names.has(child.agentId))
518
- names.set(child.agentId, (await findAgent(conn, child.agentId))?.name ?? null);
1089
+ const names = await agentNamesOf(conn, [
1090
+ ...children.map((child) => child.agentId),
1091
+ ...inputs.flatMap((input) => input.actorKind === 'agent' && input.actorId ? [input.actorId] : []),
1092
+ ]);
519
1093
  return {
520
1094
  ...(await readRuns([run]))[0],
521
- inputs: inputs.map(toInputView),
1095
+ actorName: (await deps.people.names(conn, [run.actorUserId])).get(run.actorUserId) ?? run.actorUserId,
1096
+ confirmedByName: run.confirmedByUserId
1097
+ ? ((await deps.people.names(conn, [run.confirmedByUserId])).get(run.confirmedByUserId) ?? run.confirmedByUserId)
1098
+ : undefined,
1099
+ requestedByName: (await deps.people.names(conn, [
1100
+ run.requestedByUserId ?? run.actorUserId,
1101
+ ])).get(run.requestedByUserId ?? run.actorUserId) ??
1102
+ run.requestedByUserId ??
1103
+ run.actorUserId,
1104
+ retriedRunId: retried?.id ?? null,
1105
+ inputs: inputs.map((input) => {
1106
+ const view = toInputView(input);
1107
+ const name = view.actor.kind === 'agent' && view.actor.id
1108
+ ? names.get(view.actor.id)
1109
+ : undefined;
1110
+ return name === undefined
1111
+ ? view
1112
+ : { ...view, actor: { ...view.actor, name } };
1113
+ }),
522
1114
  repos: repos.map(toRepo),
523
1115
  usage: await usageOf(conn, runId),
524
1116
  children: children.map((child) => ({
@@ -533,6 +1125,33 @@ export function createRunService(deps) {
533
1125
  })),
534
1126
  };
535
1127
  },
1128
+ async inputTriggers(runIds) {
1129
+ const result = new Map();
1130
+ if (!runIds.length)
1131
+ return result;
1132
+ const rows = await tx
1133
+ .read()
1134
+ .query.selectFrom('agRunInputs as input')
1135
+ .select(['input.runId', 'input.type', 'input.payload'])
1136
+ .where('input.runId', 'in', [...runIds])
1137
+ .where((eb) => eb('input.id', '=', eb
1138
+ .selectFrom('agRunInputs as first')
1139
+ .select('first.id')
1140
+ .whereRef('first.runId', '=', 'input.runId')
1141
+ .orderBy('first.createdAt', 'asc')
1142
+ .orderBy('first.id', 'asc')
1143
+ .limit(1)))
1144
+ .execute();
1145
+ for (const row of rows) {
1146
+ const inputs = result.get(String(row.runId)) ?? [];
1147
+ inputs.push({
1148
+ type: String(row.type),
1149
+ payload: jsonObject(row.payload),
1150
+ });
1151
+ result.set(String(row.runId), inputs);
1152
+ }
1153
+ return result;
1154
+ },
536
1155
  async list(filter) {
537
1156
  const records = await runsRepo(tx.read()).findMany({
538
1157
  filter: (f) => f.and([
@@ -609,6 +1228,9 @@ export function createRunService(deps) {
609
1228
  workload(query) {
610
1229
  return readWorkload(tx.read(), clock, deps.runners, query);
611
1230
  },
1231
+ queueWait(runId) {
1232
+ return readQueueWait(tx.read(), clock, deps.runners, runId, deps.diagnose);
1233
+ },
612
1234
  async events(runId, afterSeq, limit, types) {
613
1235
  const conn = tx.read();
614
1236
  await require(conn, runId);
@@ -643,7 +1265,16 @@ export function createRunService(deps) {
643
1265
  lastSeq: events.length > 0 ? events[events.length - 1].seq : afterSeq,
644
1266
  };
645
1267
  },
646
- authenticateToken: (value) => authenticateRunToken(tx.read(), clock, value),
1268
+ authenticateToken: async (value) => {
1269
+ const conn = tx.read();
1270
+ const identity = await authenticateRunToken(conn, clock, value);
1271
+ if (identity.run.commentRootRunId) {
1272
+ const root = await findRunRecord(conn, identity.run.commentRootRunId);
1273
+ if (!root || !(await currentCommentOwner(conn, deps.subjects, root)))
1274
+ throw precondition('RUN_TOKEN_INVALID', 'The comment authorization belongs to an earlier owner assignment.');
1275
+ }
1276
+ return identity;
1277
+ },
647
1278
  async self({ run }) {
648
1279
  const conn = tx.read();
649
1280
  const agent = await findAgent(conn, run.agentId);
@@ -672,14 +1303,10 @@ export function createRunService(deps) {
672
1303
  const conn = tx.read();
673
1304
  const binding = deps.subjects.get(run.subjectKind);
674
1305
  const agent = await findAgent(conn, run.agentId);
675
- // An online run is held by the application itself, not by a registered runner.
676
- const runner = run.runnerId && agent?.type === 'runner'
1306
+ const runner = run.runnerId
677
1307
  ? await deps.runners.find(conn, run.runnerId)
678
1308
  : null;
679
- if (!binding ||
680
- !agent ||
681
- (agent.type === 'runner' && !runner) ||
682
- !isActive(run.status))
1309
+ if (!binding || !agent || !runner || !isActive(run.status))
683
1310
  throw notFound('Run context');
684
1311
  const assembly = await binding.context.assemble(conn, {
685
1312
  run: toRun(run),
@@ -688,11 +1315,11 @@ export function createRunService(deps) {
688
1315
  inputs: (await pendingInputs(conn, run.id)).map(toInput),
689
1316
  cli: deps.cliName,
690
1317
  appName: deps.appName,
691
- dialect: dialectOf(agent),
692
- });
1318
+ }, await binding.context.prepare?.(toRun(run)));
693
1319
  return assembly.data;
694
1320
  },
695
1321
  openOn: openRunsOn,
1322
+ openOnEach: openRunsOnEach,
696
1323
  pendingInputs: async (conn, runId) => (await pendingInputs(conn, runId)).map(toInput),
697
1324
  inputsSince: inputsOnSince,
698
1325
  lastSummary,