@nocobase/app-plugin-agents 0.1.0-beta.9 → 1.0.0-beta.16

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 (914) hide show
  1. package/CHANGELOG.md +315 -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/de-DE.d.ts +5 -0
  139. package/dist/client/locales/de-DE.d.ts.map +1 -0
  140. package/dist/client/locales/de-DE.js +1219 -0
  141. package/dist/client/locales/de-DE.js.map +1 -0
  142. package/dist/client/locales/en-US.d.ts +95 -217
  143. package/dist/client/locales/en-US.d.ts.map +1 -1
  144. package/dist/client/locales/en-US.js +100 -218
  145. package/dist/client/locales/en-US.js.map +1 -1
  146. package/dist/client/locales/es-ES.d.ts +5 -0
  147. package/dist/client/locales/es-ES.d.ts.map +1 -0
  148. package/dist/client/locales/es-ES.js +1228 -0
  149. package/dist/client/locales/es-ES.js.map +1 -0
  150. package/dist/client/locales/fr-FR.d.ts +5 -0
  151. package/dist/client/locales/fr-FR.d.ts.map +1 -0
  152. package/dist/client/locales/fr-FR.js +1229 -0
  153. package/dist/client/locales/fr-FR.js.map +1 -0
  154. package/dist/client/locales/id-ID.d.ts +5 -0
  155. package/dist/client/locales/id-ID.d.ts.map +1 -0
  156. package/dist/client/locales/id-ID.js +1219 -0
  157. package/dist/client/locales/id-ID.js.map +1 -0
  158. package/dist/client/locales/index.d.ts.map +1 -1
  159. package/dist/client/locales/index.js +8 -0
  160. package/dist/client/locales/index.js.map +1 -1
  161. package/dist/client/locales/ja-JP.d.ts +5 -0
  162. package/dist/client/locales/ja-JP.d.ts.map +1 -0
  163. package/dist/client/locales/ja-JP.js +1219 -0
  164. package/dist/client/locales/ja-JP.js.map +1 -0
  165. package/dist/client/locales/pt-BR.d.ts +5 -0
  166. package/dist/client/locales/pt-BR.d.ts.map +1 -0
  167. package/dist/client/locales/pt-BR.js +1229 -0
  168. package/dist/client/locales/pt-BR.js.map +1 -0
  169. package/dist/client/locales/runWait.en-US.d.ts +7 -0
  170. package/dist/client/locales/runWait.en-US.d.ts.map +1 -1
  171. package/dist/client/locales/runWait.en-US.js +10 -3
  172. package/dist/client/locales/runWait.en-US.js.map +1 -1
  173. package/dist/client/locales/runWait.zh-CN.d.ts +1 -1
  174. package/dist/client/locales/runWait.zh-CN.d.ts.map +1 -1
  175. package/dist/client/locales/runWait.zh-CN.js +11 -4
  176. package/dist/client/locales/runWait.zh-CN.js.map +1 -1
  177. package/dist/client/locales/runtimes.en-US.d.ts +83 -0
  178. package/dist/client/locales/runtimes.en-US.d.ts.map +1 -1
  179. package/dist/client/locales/runtimes.en-US.js +84 -1
  180. package/dist/client/locales/runtimes.en-US.js.map +1 -1
  181. package/dist/client/locales/runtimes.zh-CN.d.ts.map +1 -1
  182. package/dist/client/locales/runtimes.zh-CN.js +83 -0
  183. package/dist/client/locales/runtimes.zh-CN.js.map +1 -1
  184. package/dist/client/locales/skills.en-US.d.ts +7 -0
  185. package/dist/client/locales/skills.en-US.d.ts.map +1 -1
  186. package/dist/client/locales/skills.en-US.js +8 -1
  187. package/dist/client/locales/skills.en-US.js.map +1 -1
  188. package/dist/client/locales/skills.zh-CN.d.ts.map +1 -1
  189. package/dist/client/locales/skills.zh-CN.js +8 -1
  190. package/dist/client/locales/skills.zh-CN.js.map +1 -1
  191. package/dist/client/locales/vi-VN.d.ts +5 -0
  192. package/dist/client/locales/vi-VN.d.ts.map +1 -0
  193. package/dist/client/locales/vi-VN.js +1219 -0
  194. package/dist/client/locales/vi-VN.js.map +1 -0
  195. package/dist/client/locales/zh-CN.d.ts.map +1 -1
  196. package/dist/client/locales/zh-CN.js +102 -220
  197. package/dist/client/locales/zh-CN.js.map +1 -1
  198. package/dist/client/locales/zh-TW.d.ts +5 -0
  199. package/dist/client/locales/zh-TW.d.ts.map +1 -0
  200. package/dist/client/locales/zh-TW.js +1219 -0
  201. package/dist/client/locales/zh-TW.js.map +1 -0
  202. package/dist/client/model-suggestion.d.ts +6 -0
  203. package/dist/client/model-suggestion.d.ts.map +1 -0
  204. package/dist/client/model-suggestion.js +25 -0
  205. package/dist/client/model-suggestion.js.map +1 -0
  206. package/dist/client/online/services.d.ts.map +1 -1
  207. package/dist/client/online/services.js +5 -6
  208. package/dist/client/online/services.js.map +1 -1
  209. package/dist/client/pages/agents/agent-dialog.d.ts +9 -0
  210. package/dist/client/pages/agents/agent-dialog.d.ts.map +1 -0
  211. package/dist/client/pages/agents/agent-dialog.js +99 -0
  212. package/dist/client/pages/agents/agent-dialog.js.map +1 -0
  213. package/dist/client/pages/agents/agent-state.d.ts +11 -0
  214. package/dist/client/pages/agents/agent-state.d.ts.map +1 -0
  215. package/dist/client/pages/agents/agent-state.js +28 -0
  216. package/dist/client/pages/agents/agent-state.js.map +1 -0
  217. package/dist/client/pages/agents/index.d.ts +1 -1
  218. package/dist/client/pages/agents/index.d.ts.map +1 -1
  219. package/dist/client/pages/agents/index.js +7 -101
  220. package/dist/client/pages/agents/index.js.map +1 -1
  221. package/dist/client/pages/agents/runner-agents.d.ts +3 -0
  222. package/dist/client/pages/agents/runner-agents.d.ts.map +1 -0
  223. package/dist/client/pages/agents/runner-agents.js +185 -0
  224. package/dist/client/pages/agents/runner-agents.js.map +1 -0
  225. package/dist/client/pages/runtimes/connect.js.map +1 -1
  226. package/dist/client/pages/runtimes/index.d.ts.map +1 -1
  227. package/dist/client/pages/runtimes/index.js +1 -1
  228. package/dist/client/pages/runtimes/index.js.map +1 -1
  229. package/dist/client/pages/runtimes/quota-targets.d.ts +4 -0
  230. package/dist/client/pages/runtimes/quota-targets.d.ts.map +1 -0
  231. package/dist/client/pages/runtimes/quota-targets.js +18 -0
  232. package/dist/client/pages/runtimes/quota-targets.js.map +1 -0
  233. package/dist/client/pages/runtimes/quota.d.ts +17 -0
  234. package/dist/client/pages/runtimes/quota.d.ts.map +1 -0
  235. package/dist/client/pages/runtimes/quota.js +50 -0
  236. package/dist/client/pages/runtimes/quota.js.map +1 -0
  237. package/dist/client/pages/runtimes/runner-cells.d.ts +11 -4
  238. package/dist/client/pages/runtimes/runner-cells.d.ts.map +1 -1
  239. package/dist/client/pages/runtimes/runner-cells.js +6 -3
  240. package/dist/client/pages/runtimes/runner-cells.js.map +1 -1
  241. package/dist/client/pages/runtimes/runner-overview.d.ts +9 -0
  242. package/dist/client/pages/runtimes/runner-overview.d.ts.map +1 -0
  243. package/dist/client/pages/runtimes/runner-overview.js +109 -0
  244. package/dist/client/pages/runtimes/runner-overview.js.map +1 -0
  245. package/dist/client/pages/runtimes/runner-runs.d.ts +5 -0
  246. package/dist/client/pages/runtimes/runner-runs.d.ts.map +1 -0
  247. package/dist/client/pages/runtimes/runner-runs.js +35 -0
  248. package/dist/client/pages/runtimes/runner-runs.js.map +1 -0
  249. package/dist/client/pages/runtimes/runner-sheet.d.ts +2 -3
  250. package/dist/client/pages/runtimes/runner-sheet.d.ts.map +1 -1
  251. package/dist/client/pages/runtimes/runner-sheet.js +43 -171
  252. package/dist/client/pages/runtimes/runner-sheet.js.map +1 -1
  253. package/dist/client/pages/runtimes/runner-tools.d.ts +17 -0
  254. package/dist/client/pages/runtimes/runner-tools.d.ts.map +1 -0
  255. package/dist/client/pages/runtimes/runner-tools.js +75 -0
  256. package/dist/client/pages/runtimes/runner-tools.js.map +1 -0
  257. package/dist/client/pages/runtimes/runner-workspaces.d.ts +6 -0
  258. package/dist/client/pages/runtimes/runner-workspaces.d.ts.map +1 -0
  259. package/dist/client/pages/runtimes/runner-workspaces.js +37 -0
  260. package/dist/client/pages/runtimes/runner-workspaces.js.map +1 -0
  261. package/dist/client/pages/runtimes/tool-slots-fields.js +1 -1
  262. package/dist/client/pages/runtimes/tool-slots-fields.js.map +1 -1
  263. package/dist/client/pages/runtimes/workspace-diagnostics.d.ts +6 -4
  264. package/dist/client/pages/runtimes/workspace-diagnostics.d.ts.map +1 -1
  265. package/dist/client/pages/runtimes/workspace-diagnostics.js +67 -33
  266. package/dist/client/pages/runtimes/workspace-diagnostics.js.map +1 -1
  267. package/dist/client/pages/skills/detail/index.d.ts.map +1 -1
  268. package/dist/client/pages/skills/detail/index.js +11 -15
  269. package/dist/client/pages/skills/detail/index.js.map +1 -1
  270. package/dist/client/pages/skills/index.d.ts.map +1 -1
  271. package/dist/client/pages/skills/index.js +2 -2
  272. package/dist/client/pages/skills/index.js.map +1 -1
  273. package/dist/client/pages/usage/date-range-picker.d.ts.map +1 -1
  274. package/dist/client/pages/usage/date-range-picker.js +14 -2
  275. package/dist/client/pages/usage/date-range-picker.js.map +1 -1
  276. package/dist/client/pages/usage/index.js +2 -2
  277. package/dist/client/pages/usage/index.js.map +1 -1
  278. package/dist/client/profile/default-agent.d.ts.map +1 -1
  279. package/dist/client/profile/default-agent.js +2 -4
  280. package/dist/client/profile/default-agent.js.map +1 -1
  281. package/dist/client/routes.d.ts +1 -1
  282. package/dist/client/routes.d.ts.map +1 -1
  283. package/dist/client/routes.js +1 -13
  284. package/dist/client/routes.js.map +1 -1
  285. package/dist/client/runs/format-wait.d.ts.map +1 -1
  286. package/dist/client/runs/format-wait.js +15 -1
  287. package/dist/client/runs/format-wait.js.map +1 -1
  288. package/dist/client/runs/subject-runs.d.ts +5 -0
  289. package/dist/client/runs/subject-runs.d.ts.map +1 -1
  290. package/dist/client/runs/subject-runs.js +24 -9
  291. package/dist/client/runs/subject-runs.js.map +1 -1
  292. package/dist/client/runs/use-run-events.d.ts +1 -1
  293. package/dist/client/runs/use-run-events.d.ts.map +1 -1
  294. package/dist/client/runs/use-run-events.js +5 -2
  295. package/dist/client/runs/use-run-events.js.map +1 -1
  296. package/dist/client/runs.d.ts +1 -1
  297. package/dist/client/runs.d.ts.map +1 -1
  298. package/dist/client/runs.js +1 -1
  299. package/dist/client/runs.js.map +1 -1
  300. package/dist/database/migrations/.manifest.json +38 -2
  301. package/dist/database/migrations/202610020003_ag_create_runs.d.ts.map +1 -1
  302. package/dist/database/migrations/202610020003_ag_create_runs.js +0 -1
  303. package/dist/database/migrations/202610020003_ag_create_runs.js.map +1 -1
  304. package/dist/database/migrations/202610120002_ag_add_queue_entered_at.d.ts +4 -0
  305. package/dist/database/migrations/202610120002_ag_add_queue_entered_at.d.ts.map +1 -0
  306. package/dist/database/migrations/202610120002_ag_add_queue_entered_at.js +50 -0
  307. package/dist/database/migrations/202610120002_ag_add_queue_entered_at.js.map +1 -0
  308. package/dist/database/migrations/202610170001_ag_runner_quota.d.ts +4 -0
  309. package/dist/database/migrations/202610170001_ag_runner_quota.d.ts.map +1 -0
  310. package/dist/database/migrations/202610170001_ag_runner_quota.js +19 -0
  311. package/dist/database/migrations/202610170001_ag_runner_quota.js.map +1 -0
  312. package/dist/database/migrations/202610240020_ag_runner_agents.d.ts +4 -0
  313. package/dist/database/migrations/202610240020_ag_runner_agents.d.ts.map +1 -0
  314. package/dist/database/migrations/202610240020_ag_runner_agents.js +115 -0
  315. package/dist/database/migrations/202610240020_ag_runner_agents.js.map +1 -0
  316. package/dist/database/migrations/202610240040_ag_discovery_preferences.d.ts +4 -0
  317. package/dist/database/migrations/202610240040_ag_discovery_preferences.d.ts.map +1 -0
  318. package/dist/database/migrations/202610240040_ag_discovery_preferences.js +18 -0
  319. package/dist/database/migrations/202610240040_ag_discovery_preferences.js.map +1 -0
  320. package/dist/database/migrations/202610250001_ag_comment_runner_consent.d.ts +4 -0
  321. package/dist/database/migrations/202610250001_ag_comment_runner_consent.d.ts.map +1 -0
  322. package/dist/database/migrations/202610250001_ag_comment_runner_consent.js +41 -0
  323. package/dist/database/migrations/202610250001_ag_comment_runner_consent.js.map +1 -0
  324. package/dist/database/migrations/202610260001_ag_drop_directory_index.d.ts +4 -0
  325. package/dist/database/migrations/202610260001_ag_drop_directory_index.d.ts.map +1 -0
  326. package/dist/database/migrations/202610260001_ag_drop_directory_index.js +24 -0
  327. package/dist/database/migrations/202610260001_ag_drop_directory_index.js.map +1 -0
  328. package/dist/database/migrations/202610260001_ag_run_revision.d.ts +4 -0
  329. package/dist/database/migrations/202610260001_ag_run_revision.d.ts.map +1 -0
  330. package/dist/database/migrations/202610260001_ag_run_revision.js +19 -0
  331. package/dist/database/migrations/202610260001_ag_run_revision.js.map +1 -0
  332. package/dist/database/migrations/202610270001_ag_online_agent.d.ts +4 -0
  333. package/dist/database/migrations/202610270001_ag_online_agent.d.ts.map +1 -0
  334. package/dist/database/migrations/202610270001_ag_online_agent.js +43 -0
  335. package/dist/database/migrations/202610270001_ag_online_agent.js.map +1 -0
  336. package/dist/database/migrations/202610270002_ag_chat_list_visibility.d.ts +4 -0
  337. package/dist/database/migrations/202610270002_ag_chat_list_visibility.d.ts.map +1 -0
  338. package/dist/database/migrations/202610270002_ag_chat_list_visibility.js +17 -0
  339. package/dist/database/migrations/202610270002_ag_chat_list_visibility.js.map +1 -0
  340. package/dist/package.json +34 -12
  341. package/dist/server/cli/run-credential.js +1 -1
  342. package/dist/server/cli/surface.d.ts.map +1 -1
  343. package/dist/server/cli/surface.js +4 -1
  344. package/dist/server/cli/surface.js.map +1 -1
  345. package/dist/server/composition.d.ts +36 -35
  346. package/dist/server/composition.d.ts.map +1 -1
  347. package/dist/server/composition.js +99 -66
  348. package/dist/server/composition.js.map +1 -1
  349. package/dist/server/core/agents/agent.service.d.ts +51 -43
  350. package/dist/server/core/agents/agent.service.d.ts.map +1 -1
  351. package/dist/server/core/agents/agent.service.js +347 -321
  352. package/dist/server/core/agents/agent.service.js.map +1 -1
  353. package/dist/server/core/agents/agent.store.d.ts +26 -12
  354. package/dist/server/core/agents/agent.store.d.ts.map +1 -1
  355. package/dist/server/core/agents/agent.store.js +74 -66
  356. package/dist/server/core/agents/agent.store.js.map +1 -1
  357. package/dist/server/core/agents/agent.views.d.ts +29 -0
  358. package/dist/server/core/agents/agent.views.d.ts.map +1 -0
  359. package/dist/server/core/agents/agent.views.js +88 -0
  360. package/dist/server/core/agents/agent.views.js.map +1 -0
  361. package/dist/server/core/agents/discovery.d.ts +12 -0
  362. package/dist/server/core/agents/discovery.d.ts.map +1 -0
  363. package/dist/server/core/agents/discovery.js +39 -0
  364. package/dist/server/core/agents/discovery.js.map +1 -0
  365. package/dist/server/core/agents/index.d.ts +3 -2
  366. package/dist/server/core/agents/index.d.ts.map +1 -1
  367. package/dist/server/core/agents/index.js +3 -2
  368. package/dist/server/core/agents/index.js.map +1 -1
  369. package/dist/server/core/brief/brief.js +3 -3
  370. package/dist/server/core/brief/brief.js.map +1 -1
  371. package/dist/server/core/callers/index.d.ts +10 -1
  372. package/dist/server/core/callers/index.d.ts.map +1 -1
  373. package/dist/server/core/callers/index.js +15 -0
  374. package/dist/server/core/callers/index.js.map +1 -1
  375. package/dist/server/core/conversations/attachments.d.ts.map +1 -1
  376. package/dist/server/core/conversations/attachments.js +6 -1
  377. package/dist/server/core/conversations/attachments.js.map +1 -1
  378. package/dist/server/core/conversations/availability.d.ts +6 -11
  379. package/dist/server/core/conversations/availability.d.ts.map +1 -1
  380. package/dist/server/core/conversations/availability.js +11 -15
  381. package/dist/server/core/conversations/availability.js.map +1 -1
  382. package/dist/server/core/conversations/chat-settings.d.ts +2 -2
  383. package/dist/server/core/conversations/chat-settings.d.ts.map +1 -1
  384. package/dist/server/core/conversations/chat-settings.js +17 -22
  385. package/dist/server/core/conversations/chat-settings.js.map +1 -1
  386. package/dist/server/core/conversations/conversation.service.d.ts +13 -8
  387. package/dist/server/core/conversations/conversation.service.d.ts.map +1 -1
  388. package/dist/server/core/conversations/conversation.service.js +397 -383
  389. package/dist/server/core/conversations/conversation.service.js.map +1 -1
  390. package/dist/server/core/conversations/conversation.store.d.ts +3 -0
  391. package/dist/server/core/conversations/conversation.store.d.ts.map +1 -1
  392. package/dist/server/core/conversations/conversation.store.js +2 -1
  393. package/dist/server/core/conversations/conversation.store.js.map +1 -1
  394. package/dist/server/core/conversations/page-context.d.ts +8 -2
  395. package/dist/server/core/conversations/page-context.d.ts.map +1 -1
  396. package/dist/server/core/conversations/page-context.js +61 -2
  397. package/dist/server/core/conversations/page-context.js.map +1 -1
  398. package/dist/server/core/conversations/ports.d.ts +18 -20
  399. package/dist/server/core/conversations/ports.d.ts.map +1 -1
  400. package/dist/server/core/reports/model-usage.d.ts.map +1 -1
  401. package/dist/server/core/reports/model-usage.js +42 -44
  402. package/dist/server/core/reports/model-usage.js.map +1 -1
  403. package/dist/server/core/reports/prices.d.ts.map +1 -1
  404. package/dist/server/core/reports/prices.js +29 -5
  405. package/dist/server/core/reports/prices.js.map +1 -1
  406. package/dist/server/core/reports/report.service.d.ts +4 -2
  407. package/dist/server/core/reports/report.service.d.ts.map +1 -1
  408. package/dist/server/core/reports/report.service.js +148 -66
  409. package/dist/server/core/reports/report.service.js.map +1 -1
  410. package/dist/server/core/runs/access.d.ts +5 -0
  411. package/dist/server/core/runs/access.d.ts.map +1 -0
  412. package/dist/server/core/runs/access.js +10 -0
  413. package/dist/server/core/runs/access.js.map +1 -0
  414. package/dist/server/core/runs/availability.d.ts +18 -6
  415. package/dist/server/core/runs/availability.d.ts.map +1 -1
  416. package/dist/server/core/runs/availability.js +40 -34
  417. package/dist/server/core/runs/availability.js.map +1 -1
  418. package/dist/server/core/runs/claim.d.ts +30 -106
  419. package/dist/server/core/runs/claim.d.ts.map +1 -1
  420. package/dist/server/core/runs/claim.js +630 -323
  421. package/dist/server/core/runs/claim.js.map +1 -1
  422. package/dist/server/core/runs/comment-consent.d.ts +24 -0
  423. package/dist/server/core/runs/comment-consent.d.ts.map +1 -0
  424. package/dist/server/core/runs/comment-consent.js +116 -0
  425. package/dist/server/core/runs/comment-consent.js.map +1 -0
  426. package/dist/server/core/runs/eligibility.d.ts +13 -1
  427. package/dist/server/core/runs/eligibility.d.ts.map +1 -1
  428. package/dist/server/core/runs/eligibility.js +41 -10
  429. package/dist/server/core/runs/eligibility.js.map +1 -1
  430. package/dist/server/core/runs/execution-view.d.ts +8 -0
  431. package/dist/server/core/runs/execution-view.d.ts.map +1 -1
  432. package/dist/server/core/runs/execution-view.js +9 -0
  433. package/dist/server/core/runs/execution-view.js.map +1 -1
  434. package/dist/server/core/runs/execution.d.ts +1 -1
  435. package/dist/server/core/runs/execution.d.ts.map +1 -1
  436. package/dist/server/core/runs/execution.js +8 -2
  437. package/dist/server/core/runs/execution.js.map +1 -1
  438. package/dist/server/core/runs/identity.d.ts +9 -0
  439. package/dist/server/core/runs/identity.d.ts.map +1 -0
  440. package/dist/server/core/runs/identity.js +75 -0
  441. package/dist/server/core/runs/identity.js.map +1 -0
  442. package/dist/server/core/runs/index.d.ts +6 -6
  443. package/dist/server/core/runs/index.d.ts.map +1 -1
  444. package/dist/server/core/runs/index.js +6 -6
  445. package/dist/server/core/runs/index.js.map +1 -1
  446. package/dist/server/core/runs/input-gate.d.ts +1 -1
  447. package/dist/server/core/runs/input-gate.d.ts.map +1 -1
  448. package/dist/server/core/runs/input-gate.js +4 -2
  449. package/dist/server/core/runs/input-gate.js.map +1 -1
  450. package/dist/server/core/runs/lifecycle.d.ts +16 -18
  451. package/dist/server/core/runs/lifecycle.d.ts.map +1 -1
  452. package/dist/server/core/runs/lifecycle.js +150 -62
  453. package/dist/server/core/runs/lifecycle.js.map +1 -1
  454. package/dist/server/core/runs/policy.d.ts +9 -2
  455. package/dist/server/core/runs/policy.d.ts.map +1 -1
  456. package/dist/server/core/runs/policy.js +17 -8
  457. package/dist/server/core/runs/policy.js.map +1 -1
  458. package/dist/server/core/runs/ports.d.ts +41 -31
  459. package/dist/server/core/runs/ports.d.ts.map +1 -1
  460. package/dist/server/core/runs/ports.js +2 -13
  461. package/dist/server/core/runs/ports.js.map +1 -1
  462. package/dist/server/core/runs/preview.d.ts.map +1 -1
  463. package/dist/server/core/runs/preview.js +1 -3
  464. package/dist/server/core/runs/preview.js.map +1 -1
  465. package/dist/server/core/runs/run-data-purge.d.ts +15 -0
  466. package/dist/server/core/runs/run-data-purge.d.ts.map +1 -0
  467. package/dist/server/core/runs/run-data-purge.js +82 -0
  468. package/dist/server/core/runs/run-data-purge.js.map +1 -0
  469. package/dist/server/core/runs/run-requests.d.ts +25 -0
  470. package/dist/server/core/runs/run-requests.d.ts.map +1 -1
  471. package/dist/server/core/runs/run-requests.js +131 -64
  472. package/dist/server/core/runs/run-requests.js.map +1 -1
  473. package/dist/server/core/runs/run.service.d.ts +31 -2
  474. package/dist/server/core/runs/run.service.d.ts.map +1 -1
  475. package/dist/server/core/runs/run.service.js +638 -74
  476. package/dist/server/core/runs/run.service.js.map +1 -1
  477. package/dist/server/core/runs/run.store.d.ts +11 -0
  478. package/dist/server/core/runs/run.store.d.ts.map +1 -1
  479. package/dist/server/core/runs/run.store.js +39 -11
  480. package/dist/server/core/runs/run.store.js.map +1 -1
  481. package/dist/server/core/runs/runner-view.d.ts +12 -2
  482. package/dist/server/core/runs/runner-view.d.ts.map +1 -1
  483. package/dist/server/core/runs/runner-view.js +55 -13
  484. package/dist/server/core/runs/runner-view.js.map +1 -1
  485. package/dist/server/core/runs/selection.d.ts +13 -0
  486. package/dist/server/core/runs/selection.d.ts.map +1 -0
  487. package/dist/server/core/runs/selection.js +21 -0
  488. package/dist/server/core/runs/selection.js.map +1 -0
  489. package/dist/server/core/runs/sweeper.d.ts +1 -0
  490. package/dist/server/core/runs/sweeper.d.ts.map +1 -1
  491. package/dist/server/core/runs/sweeper.js +66 -17
  492. package/dist/server/core/runs/sweeper.js.map +1 -1
  493. package/dist/server/core/runs/transitions.d.ts +6 -2
  494. package/dist/server/core/runs/transitions.d.ts.map +1 -1
  495. package/dist/server/core/runs/transitions.js +73 -19
  496. package/dist/server/core/runs/transitions.js.map +1 -1
  497. package/dist/server/core/runs/workload.d.ts +17 -5
  498. package/dist/server/core/runs/workload.d.ts.map +1 -1
  499. package/dist/server/core/runs/workload.js +203 -68
  500. package/dist/server/core/runs/workload.js.map +1 -1
  501. package/dist/server/core/skills/skill.service.d.ts +6 -2
  502. package/dist/server/core/skills/skill.service.d.ts.map +1 -1
  503. package/dist/server/core/skills/skill.service.js +87 -66
  504. package/dist/server/core/skills/skill.service.js.map +1 -1
  505. package/dist/server/core/skills/skill.store.d.ts +14 -0
  506. package/dist/server/core/skills/skill.store.d.ts.map +1 -1
  507. package/dist/server/core/skills/skill.store.js +30 -0
  508. package/dist/server/core/skills/skill.store.js.map +1 -1
  509. package/dist/server/core/transaction-read.d.ts +4 -0
  510. package/dist/server/core/transaction-read.d.ts.map +1 -0
  511. package/dist/server/core/transaction-read.js +30 -0
  512. package/dist/server/core/transaction-read.js.map +1 -0
  513. package/dist/server/core/variables/index.d.ts +1 -1
  514. package/dist/server/core/variables/index.d.ts.map +1 -1
  515. package/dist/server/core/variables/index.js.map +1 -1
  516. package/dist/server/core/variables/variable.service.d.ts +18 -0
  517. package/dist/server/core/variables/variable.service.d.ts.map +1 -1
  518. package/dist/server/core/variables/variable.service.js +95 -20
  519. package/dist/server/core/variables/variable.service.js.map +1 -1
  520. package/dist/server/index.d.ts +4 -0
  521. package/dist/server/index.d.ts.map +1 -1
  522. package/dist/server/index.js +3 -0
  523. package/dist/server/index.js.map +1 -1
  524. package/dist/server/jobs/job.service.d.ts +1 -1
  525. package/dist/server/jobs/job.service.d.ts.map +1 -1
  526. package/dist/server/jobs/job.service.js +8 -2
  527. package/dist/server/jobs/job.service.js.map +1 -1
  528. package/dist/server/kernel/events.d.ts +7 -3
  529. package/dist/server/kernel/events.d.ts.map +1 -1
  530. package/dist/server/kernel/events.js.map +1 -1
  531. package/dist/server/kernel/scopes.d.ts +6 -0
  532. package/dist/server/kernel/scopes.d.ts.map +1 -1
  533. package/dist/server/kernel/scopes.js +3 -1
  534. package/dist/server/kernel/scopes.js.map +1 -1
  535. package/dist/server/locales/de-DE.d.ts +5 -0
  536. package/dist/server/locales/de-DE.d.ts.map +1 -0
  537. package/dist/server/locales/de-DE.js +54 -0
  538. package/dist/server/locales/de-DE.js.map +1 -0
  539. package/dist/server/locales/es-ES.d.ts +5 -0
  540. package/dist/server/locales/es-ES.d.ts.map +1 -0
  541. package/dist/server/locales/es-ES.js +54 -0
  542. package/dist/server/locales/es-ES.js.map +1 -0
  543. package/dist/server/locales/fr-FR.d.ts +5 -0
  544. package/dist/server/locales/fr-FR.d.ts.map +1 -0
  545. package/dist/server/locales/fr-FR.js +54 -0
  546. package/dist/server/locales/fr-FR.js.map +1 -0
  547. package/dist/server/locales/id-ID.d.ts +5 -0
  548. package/dist/server/locales/id-ID.d.ts.map +1 -0
  549. package/dist/server/locales/id-ID.js +54 -0
  550. package/dist/server/locales/id-ID.js.map +1 -0
  551. package/dist/server/locales/index.d.ts.map +1 -1
  552. package/dist/server/locales/index.js +8 -0
  553. package/dist/server/locales/index.js.map +1 -1
  554. package/dist/server/locales/ja-JP.d.ts +5 -0
  555. package/dist/server/locales/ja-JP.d.ts.map +1 -0
  556. package/dist/server/locales/ja-JP.js +54 -0
  557. package/dist/server/locales/ja-JP.js.map +1 -0
  558. package/dist/server/locales/pt-BR.d.ts +5 -0
  559. package/dist/server/locales/pt-BR.d.ts.map +1 -0
  560. package/dist/server/locales/pt-BR.js +54 -0
  561. package/dist/server/locales/pt-BR.js.map +1 -0
  562. package/dist/server/locales/vi-VN.d.ts +5 -0
  563. package/dist/server/locales/vi-VN.d.ts.map +1 -0
  564. package/dist/server/locales/vi-VN.js +54 -0
  565. package/dist/server/locales/vi-VN.js.map +1 -0
  566. package/dist/server/locales/zh-TW.d.ts +5 -0
  567. package/dist/server/locales/zh-TW.d.ts.map +1 -0
  568. package/dist/server/locales/zh-TW.js +54 -0
  569. package/dist/server/locales/zh-TW.js.map +1 -0
  570. package/dist/server/online/agent/configuration.d.ts +26 -0
  571. package/dist/server/online/agent/configuration.d.ts.map +1 -0
  572. package/dist/server/online/agent/configuration.js +261 -0
  573. package/dist/server/online/agent/configuration.js.map +1 -0
  574. package/dist/server/online/agent/contracts.d.ts +87 -0
  575. package/dist/server/online/agent/contracts.d.ts.map +1 -0
  576. package/dist/server/online/agent/contracts.js +2 -0
  577. package/dist/server/online/agent/contracts.js.map +1 -0
  578. package/dist/server/online/agent/errors.d.ts +11 -0
  579. package/dist/server/online/agent/errors.d.ts.map +1 -0
  580. package/dist/server/online/agent/errors.js +21 -0
  581. package/dist/server/online/agent/errors.js.map +1 -0
  582. package/dist/server/online/agent/index.d.ts +11 -0
  583. package/dist/server/online/agent/index.d.ts.map +1 -0
  584. package/dist/server/online/agent/index.js +9 -0
  585. package/dist/server/online/agent/index.js.map +1 -0
  586. package/dist/server/online/agent/messages/json.d.ts +5 -0
  587. package/dist/server/online/agent/messages/json.d.ts.map +1 -0
  588. package/dist/server/online/agent/messages/json.js +88 -0
  589. package/dist/server/online/agent/messages/json.js.map +1 -0
  590. package/dist/server/online/agent/messages/projection.d.ts +20 -0
  591. package/dist/server/online/agent/messages/projection.d.ts.map +1 -0
  592. package/dist/server/online/agent/messages/projection.js +495 -0
  593. package/dist/server/online/agent/messages/projection.js.map +1 -0
  594. package/dist/server/online/agent/messages/validation.d.ts +7 -0
  595. package/dist/server/online/agent/messages/validation.d.ts.map +1 -0
  596. package/dist/server/online/agent/messages/validation.js +159 -0
  597. package/dist/server/online/agent/messages/validation.js.map +1 -0
  598. package/dist/server/online/agent/native/backend.d.ts +60 -0
  599. package/dist/server/online/agent/native/backend.d.ts.map +1 -0
  600. package/dist/server/online/agent/native/backend.js +411 -0
  601. package/dist/server/online/agent/native/backend.js.map +1 -0
  602. package/dist/server/online/agent/native/execution.d.ts +41 -0
  603. package/dist/server/online/agent/native/execution.d.ts.map +1 -0
  604. package/dist/server/online/agent/native/execution.js +430 -0
  605. package/dist/server/online/agent/native/execution.js.map +1 -0
  606. package/dist/server/online/agent/native/session.d.ts +40 -0
  607. package/dist/server/online/agent/native/session.d.ts.map +1 -0
  608. package/dist/server/online/agent/native/session.js +104 -0
  609. package/dist/server/online/agent/native/session.js.map +1 -0
  610. package/dist/server/online/agent/native/types.d.ts +32 -0
  611. package/dist/server/online/agent/native/types.d.ts.map +1 -0
  612. package/dist/server/online/agent/native/types.js +2 -0
  613. package/dist/server/online/agent/native/types.js.map +1 -0
  614. package/dist/server/online/agent/persistence/manager.d.ts +16 -0
  615. package/dist/server/online/agent/persistence/manager.d.ts.map +1 -0
  616. package/dist/server/online/agent/persistence/manager.js +209 -0
  617. package/dist/server/online/agent/persistence/manager.js.map +1 -0
  618. package/dist/server/online/agent/persistence/state.d.ts +11 -0
  619. package/dist/server/online/agent/persistence/state.d.ts.map +1 -0
  620. package/dist/server/online/agent/persistence/state.js +45 -0
  621. package/dist/server/online/agent/persistence/state.js.map +1 -0
  622. package/dist/server/online/agent/persistence/store.d.ts +58 -0
  623. package/dist/server/online/agent/persistence/store.d.ts.map +1 -0
  624. package/dist/server/online/agent/persistence/store.js +634 -0
  625. package/dist/server/online/agent/persistence/store.js.map +1 -0
  626. package/dist/server/online/agent/persistence/types.d.ts +44 -0
  627. package/dist/server/online/agent/persistence/types.d.ts.map +1 -0
  628. package/dist/server/online/agent/persistence/types.js +2 -0
  629. package/dist/server/online/agent/persistence/types.js.map +1 -0
  630. package/dist/server/online/agent/runner/backend.d.ts +57 -0
  631. package/dist/server/online/agent/runner/backend.d.ts.map +1 -0
  632. package/dist/server/online/agent/runner/backend.js +501 -0
  633. package/dist/server/online/agent/runner/backend.js.map +1 -0
  634. package/dist/server/online/agent/runner/projection.d.ts +10 -0
  635. package/dist/server/online/agent/runner/projection.d.ts.map +1 -0
  636. package/dist/server/online/agent/runner/projection.js +171 -0
  637. package/dist/server/online/agent/runner/projection.js.map +1 -0
  638. package/dist/server/online/agent/runner/types.d.ts +44 -0
  639. package/dist/server/online/agent/runner/types.d.ts.map +1 -0
  640. package/dist/server/online/agent/runner/types.js +2 -0
  641. package/dist/server/online/agent/runner/types.js.map +1 -0
  642. package/dist/server/online/agent/service.d.ts +47 -0
  643. package/dist/server/online/agent/service.d.ts.map +1 -0
  644. package/dist/server/online/agent/service.js +111 -0
  645. package/dist/server/online/agent/service.js.map +1 -0
  646. package/dist/server/online/agent/transport/streams.d.ts +54 -0
  647. package/dist/server/online/agent/transport/streams.d.ts.map +1 -0
  648. package/dist/server/online/agent/transport/streams.js +440 -0
  649. package/dist/server/online/agent/transport/streams.js.map +1 -0
  650. package/dist/server/online/agent/types.d.ts +155 -0
  651. package/dist/server/online/agent/types.d.ts.map +1 -0
  652. package/dist/server/online/agent/types.js +2 -0
  653. package/dist/server/online/agent/types.js.map +1 -0
  654. package/dist/server/online/index.d.ts +0 -5
  655. package/dist/server/online/index.d.ts.map +1 -1
  656. package/dist/server/online/index.js +0 -5
  657. package/dist/server/online/index.js.map +1 -1
  658. package/dist/server/online/providers.d.ts.map +1 -1
  659. package/dist/server/online/providers.js +26 -2
  660. package/dist/server/online/providers.js.map +1 -1
  661. package/dist/server/online/routes.d.ts.map +1 -1
  662. package/dist/server/online/routes.js +6 -35
  663. package/dist/server/online/routes.js.map +1 -1
  664. package/dist/server/online/services.d.ts.map +1 -1
  665. package/dist/server/online/services.js +101 -24
  666. package/dist/server/online/services.js.map +1 -1
  667. package/dist/server/providers/agents.d.ts +18 -25
  668. package/dist/server/providers/agents.d.ts.map +1 -1
  669. package/dist/server/providers/agents.js +72 -101
  670. package/dist/server/providers/agents.js.map +1 -1
  671. package/dist/server/providers/authorization.d.ts +1 -1
  672. package/dist/server/providers/authorization.d.ts.map +1 -1
  673. package/dist/server/providers/authorization.js +3 -2
  674. package/dist/server/providers/authorization.js.map +1 -1
  675. package/dist/server/providers/runners.d.ts +3 -1
  676. package/dist/server/providers/runners.d.ts.map +1 -1
  677. package/dist/server/providers/runners.js +38 -9
  678. package/dist/server/providers/runners.js.map +1 -1
  679. package/dist/server/routes/admin.d.ts +4 -0
  680. package/dist/server/routes/admin.d.ts.map +1 -1
  681. package/dist/server/routes/admin.js +131 -209
  682. package/dist/server/routes/admin.js.map +1 -1
  683. package/dist/server/routes/chat.d.ts.map +1 -1
  684. package/dist/server/routes/chat.js +313 -164
  685. package/dist/server/routes/chat.js.map +1 -1
  686. package/dist/server/routes/index.d.ts.map +1 -1
  687. package/dist/server/routes/index.js +8 -0
  688. package/dist/server/routes/index.js.map +1 -1
  689. package/dist/server/routes/roster.d.ts.map +1 -1
  690. package/dist/server/routes/roster.js +6 -22
  691. package/dist/server/routes/roster.js.map +1 -1
  692. package/dist/server/routes/run-requests.js +3 -3
  693. package/dist/server/routes/run-requests.js.map +1 -1
  694. package/dist/server/routes/runners/admin.d.ts.map +1 -1
  695. package/dist/server/routes/runners/admin.js +219 -25
  696. package/dist/server/routes/runners/admin.js.map +1 -1
  697. package/dist/server/routes/runners/install.d.ts.map +1 -1
  698. package/dist/server/routes/runners/install.js +7 -2
  699. package/dist/server/routes/runners/install.js.map +1 -1
  700. package/dist/server/routes/runners/runner.d.ts.map +1 -1
  701. package/dist/server/routes/runners/runner.js +2 -0
  702. package/dist/server/routes/runners/runner.js.map +1 -1
  703. package/dist/server/routes/schemas.d.ts +18 -10
  704. package/dist/server/routes/schemas.d.ts.map +1 -1
  705. package/dist/server/routes/schemas.js +497 -153
  706. package/dist/server/routes/schemas.js.map +1 -1
  707. package/dist/server/runners/runner.service.d.ts +47 -4
  708. package/dist/server/runners/runner.service.d.ts.map +1 -1
  709. package/dist/server/runners/runner.service.js +423 -79
  710. package/dist/server/runners/runner.service.js.map +1 -1
  711. package/dist/server/runners/runner.store.d.ts +8 -3
  712. package/dist/server/runners/runner.store.d.ts.map +1 -1
  713. package/dist/server/runners/runner.store.js +63 -6
  714. package/dist/server/runners/runner.store.js.map +1 -1
  715. package/dist/server/runners/slots.d.ts +5 -2
  716. package/dist/server/runners/slots.d.ts.map +1 -1
  717. package/dist/server/runners/slots.js +3 -4
  718. package/dist/server/runners/slots.js.map +1 -1
  719. package/dist/server/runners/workspaces.d.ts.map +1 -1
  720. package/dist/server/runners/workspaces.js +18 -2
  721. package/dist/server/runners/workspaces.js.map +1 -1
  722. package/dist/server/testing.d.ts +0 -2
  723. package/dist/server/testing.d.ts.map +1 -1
  724. package/dist/server/testing.js +1 -4
  725. package/dist/server/testing.js.map +1 -1
  726. package/dist/server/tokens.d.ts +8 -7
  727. package/dist/server/tokens.d.ts.map +1 -1
  728. package/dist/server/tokens.js +4 -2
  729. package/dist/server/tokens.js.map +1 -1
  730. package/dist/shared/access.d.ts +3 -7
  731. package/dist/shared/access.d.ts.map +1 -1
  732. package/dist/shared/access.js +3 -7
  733. package/dist/shared/access.js.map +1 -1
  734. package/dist/shared/agents.d.ts +131 -169
  735. package/dist/shared/agents.d.ts.map +1 -1
  736. package/dist/shared/agents.js +36 -102
  737. package/dist/shared/agents.js.map +1 -1
  738. package/dist/shared/conversations.d.ts +93 -170
  739. package/dist/shared/conversations.d.ts.map +1 -1
  740. package/dist/shared/conversations.js +8 -30
  741. package/dist/shared/conversations.js.map +1 -1
  742. package/dist/shared/locales/access.en-US.js +3 -3
  743. package/dist/shared/locales/access.zh-CN.js +4 -4
  744. package/dist/shared/model-catalog.d.ts +53 -0
  745. package/dist/shared/model-catalog.d.ts.map +1 -0
  746. package/dist/shared/model-catalog.js +182 -0
  747. package/dist/shared/model-catalog.js.map +1 -0
  748. package/dist/shared/online-agent.d.ts +3 -0
  749. package/dist/shared/online-agent.d.ts.map +1 -0
  750. package/dist/shared/online-agent.js +3 -0
  751. package/dist/shared/online-agent.js.map +1 -0
  752. package/dist/shared/page-ui-context.d.ts +26 -0
  753. package/dist/shared/page-ui-context.d.ts.map +1 -0
  754. package/dist/shared/page-ui-context.js +129 -0
  755. package/dist/shared/page-ui-context.js.map +1 -0
  756. package/dist/shared/quota.d.ts +15 -0
  757. package/dist/shared/quota.d.ts.map +1 -0
  758. package/dist/shared/quota.js +2 -0
  759. package/dist/shared/quota.js.map +1 -0
  760. package/dist/shared/runners.d.ts +132 -14
  761. package/dist/shared/runners.d.ts.map +1 -1
  762. package/dist/shared/runners.js +171 -11
  763. package/dist/shared/runners.js.map +1 -1
  764. package/dist/shared/runs.d.ts +57 -1
  765. package/dist/shared/runs.d.ts.map +1 -1
  766. package/dist/shared/runs.js +28 -0
  767. package/dist/shared/runs.js.map +1 -1
  768. package/dist/shared/skills.d.ts +11 -5
  769. package/dist/shared/skills.d.ts.map +1 -1
  770. package/dist/shared/skills.js +7 -2
  771. package/dist/shared/skills.js.map +1 -1
  772. package/dist/shared/ui-message.d.ts +80 -0
  773. package/dist/shared/ui-message.d.ts.map +1 -0
  774. package/dist/shared/ui-message.js +153 -0
  775. package/dist/shared/ui-message.js.map +1 -0
  776. package/dist/shared/variables.js +1 -1
  777. package/dist/shared/variables.js.map +1 -1
  778. package/docs/ai-forms.md +346 -0
  779. package/docs/execution-history.md +19 -0
  780. package/docs/mysql-installation-upgrade.md +7 -0
  781. package/docs/runner-agents.md +27 -0
  782. package/docs/ui-message-clients.md +80 -0
  783. package/docs/ui-messages.md +209 -0
  784. package/docs/workspace-cleanup.md +13 -0
  785. package/package.json +40 -26
  786. package/skills/nocobase-app-plugin-agents/SKILL.md +16 -13
  787. package/skills/nocobase-app-plugin-agents/references/agents.md +30 -0
  788. package/skills/nocobase-app-plugin-agents/references/extension-points.md +21 -21
  789. package/skills/nocobase-app-plugin-agents/references/model-services.md +17 -0
  790. package/skills/nocobase-app-plugin-agents/references/online-agent.md +216 -0
  791. package/skills/nocobase-app-plugin-agents/references/runners.md +12 -0
  792. package/skills/nocobase-app-plugin-agents/references/setup-and-config.md +6 -7
  793. package/skills/nocobase-app-plugin-agents/references/variables-skills-usage.md +6 -4
  794. package/skills/nocobase-app-plugin-agents/references/verification-and-troubleshooting.md +29 -32
  795. package/dist/client/chat/settings-section.d.ts +0 -5
  796. package/dist/client/chat/settings-section.d.ts.map +0 -1
  797. package/dist/client/chat/settings-section.js +0 -86
  798. package/dist/client/chat/settings-section.js.map +0 -1
  799. package/dist/client/components/agent-fields.d.ts +0 -45
  800. package/dist/client/components/agent-fields.d.ts.map +0 -1
  801. package/dist/client/components/agent-fields.js +0 -83
  802. package/dist/client/components/agent-fields.js.map +0 -1
  803. package/dist/client/components/agent-type.d.ts +0 -32
  804. package/dist/client/components/agent-type.d.ts.map +0 -1
  805. package/dist/client/components/agent-type.js +0 -80
  806. package/dist/client/components/agent-type.js.map +0 -1
  807. package/dist/client/components/model-entries.d.ts +0 -44
  808. package/dist/client/components/model-entries.d.ts.map +0 -1
  809. package/dist/client/components/model-entries.js +0 -104
  810. package/dist/client/components/model-entries.js.map +0 -1
  811. package/dist/client/hooks/use-agent-save.d.ts +0 -9
  812. package/dist/client/hooks/use-agent-save.d.ts.map +0 -1
  813. package/dist/client/hooks/use-agent-save.js +0 -40
  814. package/dist/client/hooks/use-agent-save.js.map +0 -1
  815. package/dist/client/hooks/use-model-catalog.d.ts +0 -9
  816. package/dist/client/hooks/use-model-catalog.d.ts.map +0 -1
  817. package/dist/client/hooks/use-model-catalog.js +0 -27
  818. package/dist/client/hooks/use-model-catalog.js.map +0 -1
  819. package/dist/client/lib/model-suggestions.d.ts +0 -28
  820. package/dist/client/lib/model-suggestions.d.ts.map +0 -1
  821. package/dist/client/lib/model-suggestions.js +0 -44
  822. package/dist/client/lib/model-suggestions.js.map +0 -1
  823. package/dist/client/lib/tool-policy.d.ts +0 -3
  824. package/dist/client/lib/tool-policy.d.ts.map +0 -1
  825. package/dist/client/lib/tool-policy.js +0 -5
  826. package/dist/client/lib/tool-policy.js.map +0 -1
  827. package/dist/client/online/default-model.d.ts +0 -5
  828. package/dist/client/online/default-model.d.ts.map +0 -1
  829. package/dist/client/online/default-model.js +0 -65
  830. package/dist/client/online/default-model.js.map +0 -1
  831. package/dist/client/pages/agents/agent-model.d.ts +0 -69
  832. package/dist/client/pages/agents/agent-model.d.ts.map +0 -1
  833. package/dist/client/pages/agents/agent-model.js +0 -153
  834. package/dist/client/pages/agents/agent-model.js.map +0 -1
  835. package/dist/client/pages/agents/detail/brief-preview.d.ts +0 -7
  836. package/dist/client/pages/agents/detail/brief-preview.d.ts.map +0 -1
  837. package/dist/client/pages/agents/detail/brief-preview.js +0 -43
  838. package/dist/client/pages/agents/detail/brief-preview.js.map +0 -1
  839. package/dist/client/pages/agents/detail/history.d.ts +0 -11
  840. package/dist/client/pages/agents/detail/history.d.ts.map +0 -1
  841. package/dist/client/pages/agents/detail/history.js +0 -149
  842. package/dist/client/pages/agents/detail/history.js.map +0 -1
  843. package/dist/client/pages/agents/detail/index.d.ts +0 -3
  844. package/dist/client/pages/agents/detail/index.d.ts.map +0 -1
  845. package/dist/client/pages/agents/detail/index.js +0 -241
  846. package/dist/client/pages/agents/detail/index.js.map +0 -1
  847. package/dist/client/pages/agents/detail/sections.d.ts +0 -21
  848. package/dist/client/pages/agents/detail/sections.d.ts.map +0 -1
  849. package/dist/client/pages/agents/detail/sections.js +0 -280
  850. package/dist/client/pages/agents/detail/sections.js.map +0 -1
  851. package/dist/client/pages/agents/detail/tab-draft.d.ts +0 -43
  852. package/dist/client/pages/agents/detail/tab-draft.d.ts.map +0 -1
  853. package/dist/client/pages/agents/detail/tab-draft.js +0 -115
  854. package/dist/client/pages/agents/detail/tab-draft.js.map +0 -1
  855. package/dist/client/pages/agents/detail/unsaved-bar.d.ts +0 -13
  856. package/dist/client/pages/agents/detail/unsaved-bar.d.ts.map +0 -1
  857. package/dist/client/pages/agents/detail/unsaved-bar.js +0 -21
  858. package/dist/client/pages/agents/detail/unsaved-bar.js.map +0 -1
  859. package/dist/client/pages/agents/new.d.ts +0 -3
  860. package/dist/client/pages/agents/new.d.ts.map +0 -1
  861. package/dist/client/pages/agents/new.js +0 -149
  862. package/dist/client/pages/agents/new.js.map +0 -1
  863. package/dist/client/pages/agents/preset-picker.d.ts +0 -8
  864. package/dist/client/pages/agents/preset-picker.d.ts.map +0 -1
  865. package/dist/client/pages/agents/preset-picker.js +0 -41
  866. package/dist/client/pages/agents/preset-picker.js.map +0 -1
  867. package/dist/server/core/consultations/consultation.service.d.ts +0 -59
  868. package/dist/server/core/consultations/consultation.service.d.ts.map +0 -1
  869. package/dist/server/core/consultations/consultation.service.js +0 -198
  870. package/dist/server/core/consultations/consultation.service.js.map +0 -1
  871. package/dist/server/core/consultations/index.d.ts +0 -3
  872. package/dist/server/core/consultations/index.d.ts.map +0 -1
  873. package/dist/server/core/consultations/index.js +0 -3
  874. package/dist/server/core/consultations/index.js.map +0 -1
  875. package/dist/server/core/consultations/prompt.d.ts +0 -41
  876. package/dist/server/core/consultations/prompt.d.ts.map +0 -1
  877. package/dist/server/core/consultations/prompt.js +0 -64
  878. package/dist/server/core/consultations/prompt.js.map +0 -1
  879. package/dist/server/core/presets/index.d.ts +0 -19
  880. package/dist/server/core/presets/index.d.ts.map +0 -1
  881. package/dist/server/core/presets/index.js +0 -28
  882. package/dist/server/core/presets/index.js.map +0 -1
  883. package/dist/server/online/cli-command.d.ts +0 -20
  884. package/dist/server/online/cli-command.d.ts.map +0 -1
  885. package/dist/server/online/cli-command.js +0 -345
  886. package/dist/server/online/cli-command.js.map +0 -1
  887. package/dist/server/online/consult-tool.d.ts +0 -54
  888. package/dist/server/online/consult-tool.d.ts.map +0 -1
  889. package/dist/server/online/consult-tool.js +0 -177
  890. package/dist/server/online/consult-tool.js.map +0 -1
  891. package/dist/server/online/executor.d.ts +0 -83
  892. package/dist/server/online/executor.d.ts.map +0 -1
  893. package/dist/server/online/executor.js +0 -714
  894. package/dist/server/online/executor.js.map +0 -1
  895. package/dist/server/online/sandbox.d.ts +0 -32
  896. package/dist/server/online/sandbox.d.ts.map +0 -1
  897. package/dist/server/online/sandbox.js +0 -246
  898. package/dist/server/online/sandbox.js.map +0 -1
  899. package/dist/server/online/scripted.d.ts +0 -12
  900. package/dist/server/online/scripted.d.ts.map +0 -1
  901. package/dist/server/online/scripted.js +0 -176
  902. package/dist/server/online/scripted.js.map +0 -1
  903. package/dist/server/online/tools.d.ts +0 -17
  904. package/dist/server/online/tools.d.ts.map +0 -1
  905. package/dist/server/online/tools.js +0 -31
  906. package/dist/server/online/tools.js.map +0 -1
  907. package/dist/server/vendor/THIRD_PARTY_LICENSES.txt +0 -782
  908. package/dist/server/vendor/just-bash.d.ts +0 -83
  909. package/dist/server/vendor/just-bash.js +0 -2102
  910. package/dist/shared/presets.d.ts +0 -30
  911. package/dist/shared/presets.d.ts.map +0 -1
  912. package/dist/shared/presets.js +0 -2
  913. package/dist/shared/presets.js.map +0 -1
  914. 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) => {
@@ -485,30 +910,115 @@ export function createRunService(deps) {
485
910
  throw precondition('RUN_ALREADY_RETRIED', 'This run has already been retried.', {
486
911
  runId: retried.id,
487
912
  });
488
- const agent = await requireInvocable(unit, run.agentId, byUserId);
489
- const open = await runsOfKey(unit.conn, run, ['queued', ...ACTIVE], byUserId);
490
- if (open.length > 0)
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)
491
955
  throw precondition('AGENT_BUSY', 'The agent is already working on this.', {
492
- runId: open[0].id,
956
+ runId: sameChain[0].id,
493
957
  });
494
958
  const newId = await createRun(unit, agent, {
495
959
  subject: { kind: run.subjectKind, id: run.subjectId },
496
960
  threadScope: run.threadScope,
497
- actorUserId: byUserId,
498
- requestedByUserId: byUserId,
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,
499
972
  confirmedByUserId: null,
500
- ownerUserId: run.ownerUserId,
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,
501
980
  priority: Number(run.priority),
502
981
  requires: toRun(run).requires,
503
982
  retryOfRunId: run.id,
504
983
  freshSession: run.freshSession,
505
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
+ }
506
1009
  for (const input of await pendingInputs(unit.conn, run.id))
507
1010
  await insertInput(unit, newId, {
508
1011
  type: input.type,
509
1012
  actor: toInput(input).actor,
510
1013
  text: input.text,
511
- ...(input.payload === null ? {} : { payload: input.payload }),
1014
+ ...(input.payload === null
1015
+ ? {}
1016
+ : {
1017
+ payload: {
1018
+ ...jsonObject(input.payload),
1019
+ ...(renewComment ? { commentRootRunId: newId } : {}),
1020
+ },
1021
+ }),
512
1022
  });
513
1023
  await insertInput(unit, newId, {
514
1024
  type: 'retry',
@@ -531,6 +1041,8 @@ export function createRunService(deps) {
531
1041
  retryOfRunId: run.id,
532
1042
  previousStatus: run.status,
533
1043
  });
1044
+ if (run.commentRootRunId)
1045
+ await deps.reconcileCommentConsent?.(unit, newId);
534
1046
  return toRun(await require(unit.conn, newId));
535
1047
  });
536
1048
  },
@@ -574,14 +1086,31 @@ export function createRunService(deps) {
574
1086
  filter: { parentRunId: runId },
575
1087
  sort: (sort) => [sort.field('createdAt').asc(), sort.field('id').asc()],
576
1088
  });
577
- const names = new Map();
578
- for (const child of children)
579
- if (!names.has(child.agentId))
580
- 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
+ ]);
581
1093
  return {
582
1094
  ...(await readRuns([run]))[0],
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,
583
1104
  retriedRunId: retried?.id ?? null,
584
- inputs: inputs.map(toInputView),
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
+ }),
585
1114
  repos: repos.map(toRepo),
586
1115
  usage: await usageOf(conn, runId),
587
1116
  children: children.map((child) => ({
@@ -596,6 +1125,33 @@ export function createRunService(deps) {
596
1125
  })),
597
1126
  };
598
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
+ },
599
1155
  async list(filter) {
600
1156
  const records = await runsRepo(tx.read()).findMany({
601
1157
  filter: (f) => f.and([
@@ -672,6 +1228,9 @@ export function createRunService(deps) {
672
1228
  workload(query) {
673
1229
  return readWorkload(tx.read(), clock, deps.runners, query);
674
1230
  },
1231
+ queueWait(runId) {
1232
+ return readQueueWait(tx.read(), clock, deps.runners, runId, deps.diagnose);
1233
+ },
675
1234
  async events(runId, afterSeq, limit, types) {
676
1235
  const conn = tx.read();
677
1236
  await require(conn, runId);
@@ -706,7 +1265,16 @@ export function createRunService(deps) {
706
1265
  lastSeq: events.length > 0 ? events[events.length - 1].seq : afterSeq,
707
1266
  };
708
1267
  },
709
- 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
+ },
710
1278
  async self({ run }) {
711
1279
  const conn = tx.read();
712
1280
  const agent = await findAgent(conn, run.agentId);
@@ -735,14 +1303,10 @@ export function createRunService(deps) {
735
1303
  const conn = tx.read();
736
1304
  const binding = deps.subjects.get(run.subjectKind);
737
1305
  const agent = await findAgent(conn, run.agentId);
738
- // An online run is held by the application itself, not by a registered runner.
739
- const runner = run.runnerId && agent?.type === 'runner'
1306
+ const runner = run.runnerId
740
1307
  ? await deps.runners.find(conn, run.runnerId)
741
1308
  : null;
742
- if (!binding ||
743
- !agent ||
744
- (agent.type === 'runner' && !runner) ||
745
- !isActive(run.status))
1309
+ if (!binding || !agent || !runner || !isActive(run.status))
746
1310
  throw notFound('Run context');
747
1311
  const assembly = await binding.context.assemble(conn, {
748
1312
  run: toRun(run),
@@ -751,11 +1315,11 @@ export function createRunService(deps) {
751
1315
  inputs: (await pendingInputs(conn, run.id)).map(toInput),
752
1316
  cli: deps.cliName,
753
1317
  appName: deps.appName,
754
- dialect: dialectOf(agent),
755
- });
1318
+ }, await binding.context.prepare?.(toRun(run)));
756
1319
  return assembly.data;
757
1320
  },
758
1321
  openOn: openRunsOn,
1322
+ openOnEach: openRunsOnEach,
759
1323
  pendingInputs: async (conn, runId) => (await pendingInputs(conn, runId)).map(toInput),
760
1324
  inputsSince: inputsOnSince,
761
1325
  lastSummary,