@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
@@ -30,41 +30,43 @@
30
30
  * Portable by design: the database layer offers no `FOR UPDATE SKIP LOCKED` or advisory locks, and the guarded update
31
31
  * plus the agent-row write give the same guarantees on every dialect (SQLite serializes writers anyway).
32
32
  *
33
- * Runners take only runner agents' runs. Online agents' runs are taken by the application itself (`claimServer`, for the
34
- * server executor of each instance), through the same guarded update, so two instances never take the same run: the
35
- * holder is the instance (`server:<instance>`), there is no per-agent or per-holder limit, and the payload is a brief,
36
- * the run's token and its skills (read in the run's sandbox, `online/sandbox.ts`), without directories, variables or
37
- * mounts.
33
+ * Polls are the hot path: every runner walks the same candidates, so a write per candidate is a write per candidate per
34
+ * runner per poll. Everything that rules a candidate out is read outside any transaction — identity, `fits()`, slots,
35
+ * concurrency and comment consent — and a transaction opens only for the run about to be claimed. The agent row is
36
+ * the only row a claim locks with a self-update, and only in that final transaction after `fits()` (or when a stale
37
+ * identity has to be repaired first, which current work never needs). PostgreSQL runs at READ COMMITTED, where each
38
+ * statement sees the latest committed rows, so no transaction needs no-op writes to refresh a snapshot; comment
39
+ * consent needs no chain lock, because confirmation is final and rejection or Run as me end the chain's queued runs,
40
+ * which the guarded update sees. A new write or lock here needs a measured reason (`tests/claim-concurrency.test.ts`
41
+ * counts them, and the lock waits on PostgreSQL).
42
+
38
43
  */
39
- import { ANNOUNCED_FAILURES, policyAllowsAgent, policyAllowsRepo, policyAllowsSubject, TIMINGS, } from '@nocobase/agent-protocol';
40
- import { runsTool, toolLimit } from '../../../shared/runners.js';
44
+ import { GLOBAL_SKILL_TARGET } from '../../../shared/skills.js';
45
+ import { ANNOUNCED_FAILURES, isProtocolSupported, policyAllowsAgent, policyAllowsRepo, policyAllowsSubject, TIMINGS, } from '@nocobase/agent-protocol';
46
+ import { runnerLowOnDisk, runsEntry, toolLimit, supportsWorkspaceKey, } from '../../../shared/runners.js';
47
+ import { queueStart } from './selection.js';
41
48
  import { createHash } from 'node:crypto';
42
- import { onlineEntriesOrDefault, runnerEntries, sameEntry, } from '../../../shared/agents.js';
43
49
  import { later } from '../../kernel/clock.js';
44
50
  import { notFound } from '../../kernel/errors.js';
45
51
  import { runSecretsKey } from '../../kernel/redaction.js';
46
- import { cleanList, covers } from '../../kernel/values.js';
47
- import { findAgent, lockAgentForClaim } from '../agents/index.js';
48
- import { consultSection, } from '../consultations/index.js';
49
- import { joinBrief, onlineSkillsSection, renderBrief, } from '../brief/index.js';
52
+ import { cleanList, covers, jsonObject } from '../../kernel/values.js';
53
+ import { findAgent, findAgents, lockAgentForClaim } from '../agents/index.js';
54
+ import { joinBrief, renderBrief } from '../brief/index.js';
50
55
  import { cliPackageFor } from './cli-package.js';
51
56
  import { executionHistory } from './execution.js';
52
57
  import { describeVariables, variableRefs, } from '../variables/index.js';
53
58
  import { mountsFor, prepareExtensions, repoAccessFor, sessionKeyOf, withSections, } from './extensions.js';
54
- import { dialectOf, } from './ports.js';
55
59
  import { MAX_CLAIM_FAILURES, toolPolicyFor } from './policy.js';
56
60
  import { mintRunToken } from './run-tokens.js';
57
- import { runsHeldByTool } from './runner-view.js';
58
- import { ACTIVE, countActive, eventsRepo, findRunRecord, markDelivered, pendingInputs, runsOfKey, runsRepo, sessionsRepo, toInput, toRun, } from './run.store.js';
61
+ import { ACTIVE, countActive, eventsRepo, findRunRecord, markDelivered, pendingInputs, runsOfKey, runsRepo, inputsRepo, sessionsRepo, toInput, toExecutions, toRun, } from './run.store.js';
59
62
  import { dropInputs } from './input-gate.js';
60
63
  import { finishRun } from './transitions.js';
64
+ import { queuedIdentityCurrent, refreshQueuedIdentity } from './identity.js';
65
+ import { currentCommentOwner, commentConsent, commentFromOwner, withdrawCommentRequests, } from './comment-consent.js';
66
+ import { insertRunRequest, runRequestsRepo } from './run-requests.js';
61
67
  import { consumeReset, saveBrief } from './workspace.store.js';
62
68
  /** Queued runs looked at per claim, oldest first by priority. */
63
69
  const CANDIDATES = 50;
64
- /** Whether a run holder id is an application instance's (an online run's), not a runner's. */
65
- export function isServerHolder(runnerId) {
66
- return runnerId !== null && runnerId.startsWith('server:');
67
- }
68
70
  class AssemblyError extends Error {
69
71
  cause;
70
72
  constructor(message, cause) {
@@ -101,57 +103,50 @@ function toolRoom(tools) {
101
103
  };
102
104
  }
103
105
  /**
104
- * The entry `runner` takes a run of `agent` with: the first whose tool it has enabled, installed and signed in. Null
105
- * when it has none of them, and always for an online agent, which has no tool.
106
+ * The entry `runner` takes a run of `agent` with: the first whose tool it has enabled, installed and signed in, with
107
+ * the entry's model among those it reports (`runsEntry`). Null when it has none of them.
106
108
  */
107
- export function pickEntry(runner, agent) {
108
- return (runnerEntries(agent).find((entry) => runsTool(runner, entry.tool)) ?? null);
109
+ export function pickEntry(runner, agent, now) {
110
+ return (agent.modelEntries.find((entry) => runsEntry(runner, entry, now)) ?? null);
109
111
  }
110
112
  /**
111
113
  * The entry `runner` takes a run of `agent` with when some of its tools are full: the first whose tool it runs and
112
114
  * `open` says has room. Null when none has.
113
115
  */
114
- export function pickOpenEntry(runner, agent, open) {
115
- return (runnerEntries(agent).find((entry) => runsTool(runner, entry.tool) && open(entry.tool)) ?? null);
116
- }
117
- /** Whether `runner` has one of `agent`'s tools enabled, installed and signed in; never for an online agent. */
118
- export function hasTool(runner, agent) {
119
- return pickEntry(runner, agent) !== null;
116
+ export function pickOpenEntry(runner, agent, open, now) {
117
+ return (agent.modelEntries.find((entry) => runsEntry(runner, entry, now) && open(entry.tool)) ?? null);
120
118
  }
121
- /**
122
- * The entry an online run uses: the one its subject asks for while the agent lists it, else the agent's first; for an
123
- * agent that lists none, the system default chat model (`fallback`).
124
- */
125
- export function onlineEntryOf(agent, wanted, fallback = null) {
126
- const entries = onlineEntriesOrDefault(agent, fallback);
127
- return ((wanted && entries.find((entry) => sameEntry(entry, wanted))) ??
128
- entries[0] ??
129
- null);
119
+ /** Whether `runner` has one of `agent`'s tools and models enabled, installed, signed in and reported. */
120
+ export function hasTool(runner, agent, now) {
121
+ return pickEntry(runner, agent, now) !== null;
130
122
  }
131
123
  /**
132
124
  * Whether `runner` may run work of `agent` as `actorUserId` that needs `requires`, before any lock is taken and before
133
- * a payload is known: the agent's tool signed in there, its owner's policy, the agent's named runners, and trust.
125
+ * a payload is known: the agent enabled, its tool and model reported there, its owner's policy, and trust.
134
126
  */
135
- export function fitsActor(runner, agent, actorUserId, requires) {
136
- if (agent.archivedAt || agent.type !== 'runner')
127
+ export function fitsActor(runner, agent, actorUserId, requires, now) {
128
+ if (agent.status !== 'enabled' || runnerLowOnDisk(runner))
129
+ return false;
130
+ if (!isProtocolSupported(runner.protocolVersion) ||
131
+ runner.status === 'upgrade_required' ||
132
+ runner.status === 'revoked')
137
133
  return false;
138
134
  if (!covers(runner.features, requires))
139
135
  return false;
140
- if (!hasTool(runner, agent))
136
+ if (!hasTool(runner, agent, now))
141
137
  return false;
142
138
  if (!policyAllowsAgent(runner.policy, agent))
143
139
  return false;
144
- if (agent.runnerIds.length > 0 && !agent.runnerIds.includes(runner.id))
145
- return false;
146
140
  return runner.trust === 'team' || runner.ownerUserId === actorUserId;
147
141
  }
148
142
  /** Whether `runner` may run `run` of `agent`, before any lock is taken and before its payload is known. */
149
- export function fits(runner, agent, run) {
150
- return fitsActor(runner, agent, run.actorUserId, toRun(run).requires);
143
+ export function fits(runner, agent, run, now) {
144
+ return fitsActor(runner, agent, run.actorUserId, toRun(run).requires, now);
151
145
  }
152
146
  /** The runner features a payload needs. */
153
- export function payloadRequires(dirs, skills, variables) {
147
+ export function payloadRequires(dirs, skills, variables, workspaceKey = false) {
154
148
  return [
149
+ ...(workspaceKey ? ['workspaceKey'] : []),
155
150
  ...(dirs.some((dir) => dir.kind === 'repo') ? ['checkout'] : []),
156
151
  ...(dirs.some((dir) => dir.kind === 'directory')
157
152
  ? ['directories']
@@ -175,11 +170,11 @@ export function variableTargets(agent, assembly) {
175
170
  { scope: 'agent', scopeId: agent.id },
176
171
  ];
177
172
  }
178
- /** Where a run's skills come from, the agent's first so its own win a shared slug. */
179
- export function skillTargets(agent, assembly) {
173
+ /** Team defaults, application scopes and directories, from lowest to highest priority. */
174
+ export function skillTargets(_agent, assembly) {
180
175
  return [
181
- { scope: 'agent', scopeId: agent.id },
182
- ...assembly.scopes,
176
+ GLOBAL_SKILL_TARGET,
177
+ ...assembly.scopes.filter((target) => target.scope !== 'agent' && target.scope !== 'global'),
183
178
  ...assembly.dirs.flatMap((dir) => dir.scopeId ? [{ scope: 'workdir', scopeId: dir.scopeId }] : []),
184
179
  ];
185
180
  }
@@ -198,7 +193,6 @@ function fingerprint(agent, entry, layers, skills) {
198
193
  /** The brief for `assembly`, with the skills a run would get. */
199
194
  export function briefOf(agent, assembly, skills, cli, appName) {
200
195
  const rendered = renderBrief({
201
- dialect: dialectOf(agent),
202
196
  agentName: agent.name,
203
197
  subject: { noun: assembly.subject.noun, key: assembly.subject.key },
204
198
  task: assembly.task,
@@ -252,7 +246,226 @@ async function settleClaimInputs(conn, pending, effective, now) {
252
246
  }
253
247
  export function createClaimService(deps) {
254
248
  const { tx, clock } = deps;
255
- async function assemble({ conn }, run, agent, runner, inputs, leaseExpiresAt, prepared, entry) {
249
+ /** Reuse only identical ordered targets, within this attempt and connection. */
250
+ function claimResources(conn, runId) {
251
+ const cache = new Map();
252
+ return (agent, assembly) => {
253
+ const skills = skillTargets(agent, assembly);
254
+ const variables = variableTargets(agent, assembly);
255
+ const key = JSON.stringify([skills, variables]);
256
+ let result = cache.get(key);
257
+ if (!result) {
258
+ result = (async () => ({
259
+ skills: await deps.skills.forRun(conn, skills, runId),
260
+ variables: await deps.variables.prepareRun(conn, variables),
261
+ }))();
262
+ cache.set(key, result);
263
+ }
264
+ return result;
265
+ };
266
+ }
267
+ /** Database reads only; used by the actual claim and ordered-model diagnostics. */
268
+ async function assemblyCompatibility(conn, run, agent, runner, assembly, resources = claimResources(conn, run.id)) {
269
+ if (!isProtocolSupported(runner.protocolVersion) ||
270
+ (assembly.workspaceKey && !supportsWorkspaceKey(runner)))
271
+ return 'incompatible';
272
+ const { skills, variables } = await resources(agent, assembly);
273
+ const names = variables.names;
274
+ if (!covers(runner.features, [
275
+ ...run.requires,
276
+ ...payloadRequires(payloadDirs(assembly.dirs), skills.length, names.length, Boolean(assembly.workspaceKey)),
277
+ ]))
278
+ return 'incompatible';
279
+ if (!fitsActor(runner, agent, run.actorUserId, run.requires, clock.now().getTime()) ||
280
+ !policyAllowsSubject(runner.policy, assembly.subject.key) ||
281
+ assembly.dirs.some((dir) => (dir.kind === 'repo' && !policyAllowsRepo(runner.policy, dir.url)) ||
282
+ (dir.kind === 'directory' && dir.runnerId !== runner.id)))
283
+ return 'restricted';
284
+ if (runner.trust !== 'team' && variables.teamOnly.length > 0)
285
+ return 'restricted';
286
+ return 'ready';
287
+ }
288
+ async function selectionFacts(conn, run, agent, requirePolicy = true, trust, resources = claimResources(conn, run.id)) {
289
+ const policy = await deps.selectionPolicies?.forRun(conn, run);
290
+ if ((requirePolicy && !policy) || !deps.runners)
291
+ return null;
292
+ const now = clock.now();
293
+ const start = queueStart(run);
294
+ const registered = (await deps.runners.all(conn)).filter((runner) => !trust ||
295
+ (trust === 'team' ? runner.trust === 'team' : runner.trust !== 'team'));
296
+ const binding = deps.subjects.get(run.subject.kind);
297
+ if (!binding)
298
+ throw new Error(`No context provider for ${run.subject.kind}.`);
299
+ const inputs = (await pendingInputs(conn, run.id)).map(toInput);
300
+ const active = await countActive(conn, 'agentId', agent.id);
301
+ const sameWork = (await runsOfKey(conn, {
302
+ agentId: agent.id,
303
+ subjectKind: run.subject.kind,
304
+ subjectId: run.subject.id,
305
+ threadScope: run.threadScope,
306
+ }, ACTIVE)).length > 0;
307
+ const entries = [];
308
+ for (const entry of agent.modelEntries) {
309
+ const single = { ...agent, modelEntries: [entry] };
310
+ const candidates = registered.filter((runner) => runner.status !== 'revoked');
311
+ const connected = candidates.filter((runner) => (runner.status === 'online' ||
312
+ runner.status === 'upgrade_required') &&
313
+ runner.lastSeenAt !== null &&
314
+ new Date(runner.lastSeenAt).getTime() + TIMINGS.offlineAfterMs >
315
+ now.getTime());
316
+ const installed = connected.filter((runner) => runner.tools.some((tool) => tool.kind === entry.tool));
317
+ const usable = installed.filter((runner) => runsEntry(runner, entry, clock.now().getTime()));
318
+ const online = usable.filter((runner) => runner.trust === 'team' || runner.ownerUserId === run.actorUserId);
319
+ const compatible = [];
320
+ const loads = [];
321
+ let unknown = false;
322
+ let incompatible = false;
323
+ let ready = false;
324
+ let directoryBlocked = false;
325
+ for (const runner of online) {
326
+ if (!isProtocolSupported(runner.protocolVersion) ||
327
+ runner.status === 'upgrade_required') {
328
+ incompatible = true;
329
+ loads.push({
330
+ name: runner.name,
331
+ ownerUserId: runner.ownerUserId,
332
+ reason: 'incompatible',
333
+ lastSeenAt: runner.lastSeenAt,
334
+ });
335
+ continue;
336
+ }
337
+ const assembly = await binding.context
338
+ .assemble(conn, {
339
+ run: run,
340
+ agent,
341
+ runner,
342
+ inputs,
343
+ cli: deps.cli.name,
344
+ appName: deps.app.name,
345
+ })
346
+ .catch(() => null);
347
+ if (!assembly) {
348
+ unknown = true;
349
+ loads.push({
350
+ name: runner.name,
351
+ ownerUserId: runner.ownerUserId,
352
+ reason: 'unknown',
353
+ lastSeenAt: runner.lastSeenAt,
354
+ });
355
+ continue;
356
+ }
357
+ const reason = await assemblyCompatibility(conn, run, single, runner, assembly, resources);
358
+ if (reason !== 'ready') {
359
+ incompatible ||= reason === 'incompatible';
360
+ loads.push({
361
+ name: runner.name,
362
+ ownerUserId: runner.ownerUserId,
363
+ reason,
364
+ lastSeenAt: runner.lastSeenAt,
365
+ });
366
+ continue;
367
+ }
368
+ const requiredVariables = (await resources(single, assembly)).variables
369
+ .passthrough;
370
+ if (requiredVariables.length > 0 && runner.variables == null) {
371
+ unknown = true;
372
+ continue;
373
+ }
374
+ if (requiredVariables.some((name) => !runner.variables?.includes(name)))
375
+ continue;
376
+ compatible.push(runner);
377
+ const held = await deps.slotsHeld(conn, runner.id);
378
+ const byTool = held.byTool ?? {};
379
+ const used = held.jobs + held.runs;
380
+ const directory = directoryKeyOf(runner.id, payloadDirs(assembly.dirs));
381
+ const blockedDirectory = directory !== null &&
382
+ (await directoryBusy(conn, runner.id, run.id, directory));
383
+ directoryBlocked ||= blockedDirectory;
384
+ const hasRoom = !runner.draining &&
385
+ (runner.globalFree ?? 1) > 0 &&
386
+ used < runner.slots &&
387
+ (byTool[entry.tool] ?? 0) < toolLimit(runner, entry.tool) &&
388
+ (runner.toolLoad?.[entry.tool]?.free ?? 1) > 0 &&
389
+ !blockedDirectory;
390
+ ready ||= hasRoom && runner.globalFree !== undefined;
391
+ if (hasRoom && runner.globalFree === undefined)
392
+ unknown = true;
393
+ loads.push({
394
+ name: runner.name,
395
+ ownerUserId: runner.ownerUserId,
396
+ reason: hasRoom
397
+ ? runner.globalFree === undefined
398
+ ? 'unknown'
399
+ : 'ready'
400
+ : runner.draining
401
+ ? runner.draining
402
+ : blockedDirectory
403
+ ? 'restricted'
404
+ : 'busy',
405
+ lastSeenAt: runner.lastSeenAt,
406
+ used,
407
+ limit: runner.slots,
408
+ toolUsed: byTool[entry.tool] ?? 0,
409
+ toolLimit: toolLimit(runner, entry.tool),
410
+ reportedFree: runner.toolLoad?.[entry.tool]?.free,
411
+ reportedTotalFree: runner.globalFree,
412
+ });
413
+ }
414
+ let reason = compatible.length
415
+ ? ready
416
+ ? 'ready'
417
+ : 'busy'
418
+ : online.length
419
+ ? incompatible
420
+ ? 'incompatible'
421
+ : 'restricted'
422
+ : usable.length
423
+ ? 'noSharedRunner'
424
+ : installed.length
425
+ ? 'toolUnavailable'
426
+ : connected.length
427
+ ? 'toolNotInstalled'
428
+ : 'offline';
429
+ if (directoryBlocked && !ready)
430
+ reason = 'restricted';
431
+ if (!ready &&
432
+ compatible.length > 0 &&
433
+ loads.every((runner) => runner.reason === 'updatePending' || runner.reason === 'pruning'))
434
+ reason = loads.some((runner) => runner.reason === 'updatePending')
435
+ ? 'updatePending'
436
+ : 'pruning';
437
+ if (unknown &&
438
+ !ready &&
439
+ !loads.some((runner) => runner.reason === 'busy'))
440
+ reason = 'unknown';
441
+ if (compatible.length && sameWork)
442
+ reason = 'sameWorkActive';
443
+ else if (compatible.length && active >= agent.maxConcurrentRuns)
444
+ reason = 'concurrencyFull';
445
+ else if (start > now.getTime())
446
+ reason = 'delayed';
447
+ entries.push({
448
+ tool: entry.tool,
449
+ model: entry.model,
450
+ reason,
451
+ compatibleCount: compatible.length,
452
+ blockers: [
453
+ ...(unknown ? ['unknown'] : []),
454
+ ...new Set(loads
455
+ .map((runner) => runner.reason)
456
+ .filter((reason) => reason !== undefined && reason !== 'ready')),
457
+ ],
458
+ runners: loads,
459
+ });
460
+ }
461
+ return {
462
+ queueEnteredAt: new Date(start).toISOString(),
463
+ fallbackAfterSeconds: policy?.fallbackAfterSeconds ?? 0,
464
+ sampledAt: now.toISOString(),
465
+ entries,
466
+ };
467
+ }
468
+ async function assemble({ conn }, run, agent, runner, inputs, leaseExpiresAt, prepared, entry, resources = claimResources(conn, run.id)) {
256
469
  const binding = deps.subjects.get(run.subjectKind);
257
470
  if (!binding)
258
471
  throw new Error(`No context provider is registered for subjects of kind "${run.subjectKind}".`);
@@ -264,9 +477,11 @@ export function createClaimService(deps) {
264
477
  inputs,
265
478
  cli: deps.cli.name,
266
479
  appName: deps.app.name,
267
- dialect: 'cli',
268
480
  };
269
- const assembly = await binding.context.assemble(conn, claim);
481
+ const assembly = await binding.context.assemble(conn, claim, prepared.get('subject'));
482
+ // workspace.key is required for coordinating runs; old runners must not silently ignore it.
483
+ if ((await assemblyCompatibility(conn, toRun(run), agent, runner, assembly, resources)) === 'incompatible')
484
+ throw new NotForThisRunner();
270
485
  inputs = assembly.inputs ?? inputs;
271
486
  const effectiveClaim = { ...claim, inputs };
272
487
  // Its owner's local policy keeps this runner off the subject, or off one of the repositories: another runner takes
@@ -282,30 +497,29 @@ export function createClaimService(deps) {
282
497
  if (directoryKey !== null &&
283
498
  (await directoryBusy(conn, runner.id, run.id, directoryKey)))
284
499
  throw new NotForThisRunner();
285
- const skills = await deps.skills.forRun(conn, skillTargets(agent, assembly), run.id);
286
- const variables = variableTargets(agent, assembly);
287
- const names = await deps.variables.namesOf(conn, variables);
500
+ const { skills, variables } = await resources(agent, assembly);
501
+ const names = variables.names;
288
502
  const requires = cleanList([
289
503
  ...view.requires,
290
- ...payloadRequires(dirs, skills.length, names.length),
504
+ ...payloadRequires(dirs, skills.length, names.length, Boolean(assembly.workspaceKey)),
291
505
  ]);
292
506
  if (!covers(runner.features, requires))
293
507
  throw new NotForThisRunner();
294
508
  // A variable for team runners only keeps a personal runner off the run.
295
509
  if (names.length > 0 && runner.trust !== 'team') {
296
- const teamOnly = await deps.variables.teamOnly(conn, variables);
510
+ const teamOnly = variables.teamOnly;
297
511
  if (teamOnly.length > 0)
298
512
  throw new TeamRunnersOnly(teamOnly);
299
513
  }
300
514
  const env = names.length > 0
301
- ? await deps.variables.forRun(conn, variables, {
515
+ ? await variables.deliver({
302
516
  runId: run.id,
303
517
  runnerId: runner.id,
304
518
  })
305
519
  : [];
306
520
  // Variables taken from the runner: names only. A runner that does not provide one fails the run while preparing
307
521
  // it, saying how to provide it; runners are not chosen by them.
308
- const passthrough = await deps.variables.passthroughOf(conn, variables);
522
+ const passthrough = variables.passthrough;
309
523
  const nowText = clock.now().toISOString();
310
524
  const clean = await consumeReset(conn, { kind: run.subjectKind, id: run.subjectId }, run.id, nowText);
311
525
  const session = await sessionsRepo(conn).findOne({
@@ -352,6 +566,11 @@ export function createClaimService(deps) {
352
566
  const sessionNote = resume ? assembly.turn.resumed : assembly.turn.fresh;
353
567
  const turn = [
354
568
  brief.turn,
569
+ ...(toExecutions(run.executionHistory).find((execution) => execution.attempt === Number(run.attempt) - 1)?.failureReason === 'runnerUpgrade'
570
+ ? [
571
+ 'The previous attempt was interrupted by a runner upgrade. Continue from the current state.',
572
+ ]
573
+ : []),
355
574
  ...resumeNotes,
356
575
  ...(sessionNote ? [sessionNote] : []),
357
576
  ].join('\n\n');
@@ -395,10 +614,13 @@ export function createClaimService(deps) {
395
614
  },
396
615
  inputs,
397
616
  workspace: {
617
+ sessionScope: run.threadScope,
398
618
  dirs,
399
619
  env,
400
620
  ...(passthrough.length > 0 ? { passthrough } : {}),
401
621
  ...(clean ? { clean: true } : {}),
622
+ ...(assembly.workspaceKey ? { key: assembly.workspaceKey } : {}),
623
+ ...(assembly.readOnly ? { readOnly: true } : {}),
402
624
  ...(git ? { git } : {}),
403
625
  },
404
626
  skills,
@@ -465,18 +687,175 @@ export function createClaimService(deps) {
465
687
  });
466
688
  });
467
689
  }
468
- async function admit(unit, run, agent, runner, inputs) {
469
- const rejection = await deps.subjects
470
- .get(run.subjectKind)
471
- ?.context.admit?.(unit.conn, {
690
+ /** What reconciling a comment run would change, read without writing: most runs need nothing. */
691
+ async function planCommentConsent(conn, runId) {
692
+ const none = { kind: 'none' };
693
+ const run = await findRunRecord(conn, runId);
694
+ if (!run?.commentRootRunId)
695
+ return none;
696
+ const root = await findRunRecord(conn, run.commentRootRunId);
697
+ if (!root)
698
+ return none;
699
+ if (run.status !== 'queued') {
700
+ const pending = await runRequestsRepo(conn).findMany({
701
+ filter: {
702
+ commentRootRunId: root.id,
703
+ commentRunId: run.id,
704
+ purpose: 'personalRunner',
705
+ status: 'pending',
706
+ },
707
+ limit: 1,
708
+ });
709
+ return pending.length > 0 ? { kind: 'withdraw', rootId: root.id } : none;
710
+ }
711
+ if (!(await queuedIdentityCurrent(conn, deps, run)))
712
+ return { kind: 'refresh', run };
713
+ if (!(await currentCommentOwner(conn, deps.subjects, root)))
714
+ return {
715
+ kind: 'cancel',
716
+ run,
717
+ detail: 'The comment belongs to an earlier owner assignment.',
718
+ };
719
+ if (root.commentExecution === 'requester' ||
720
+ run.actorUserId !== root.ownerUserId)
721
+ return none;
722
+ const { decision } = await commentConsent(conn, root);
723
+ if (decision === 'confirmed' || decision === 'pending')
724
+ return none;
725
+ if (await commentFromOwner(conn, root))
726
+ return none;
727
+ if (decision === 'rejected')
728
+ return {
729
+ kind: 'cancel',
730
+ run,
731
+ detail: 'The comment personal runner authorization is no longer valid.',
732
+ };
733
+ const agent = await findAgent(conn, run.agentId);
734
+ if (!agent)
735
+ return none;
736
+ const team = await selectionFacts(conn, toRun(run), agent, false, 'team');
737
+ if (!team ||
738
+ team.entries.some((e) => e.compatibleCount > 0 ||
739
+ e.reason === 'unknown' ||
740
+ e.blockers?.includes('unknown')))
741
+ return none;
742
+ const personal = await selectionFacts(conn, toRun(run), agent, false, 'personal');
743
+ if (!personal?.entries.some((e) => e.compatibleCount > 0))
744
+ return none;
745
+ const sourceInputs = await inputsRepo(conn).findMany({
746
+ filter: { runId: root.id },
747
+ sort: (sort) => [sort.field('createdAt').asc(), sort.field('id').asc()],
748
+ });
749
+ const input = sourceInputs.find((input) => input.type === 'comment' &&
750
+ jsonObject(input.payload).commentSourceSnapshot === true) ?? sourceInputs.find((input) => input.type === 'comment');
751
+ return input ? { kind: 'request', run, root, input } : none;
752
+ }
753
+ /**
754
+ * Brings a comment run's consent up to date. It takes no lock of its own: callers that may create a request hold
755
+ * the run's agent row (enqueue, retry and the sweeper do), which serializes the duplicate check in insertRunRequest
756
+ * with every other enqueue and claim of that agent. Everything else is a guarded update.
757
+ */
758
+ async function reconcileCommentConsent(unit, runId) {
759
+ let plan = await planCommentConsent(unit.conn, runId);
760
+ if (plan.kind === 'refresh') {
761
+ if (!(await refreshQueuedIdentity(unit, deps, plan.run)))
762
+ return;
763
+ plan = await planCommentConsent(unit.conn, runId);
764
+ }
765
+ switch (plan.kind) {
766
+ case 'withdraw':
767
+ await withdrawCommentRequests(unit, plan.rootId, clock.now().toISOString(), runId);
768
+ return;
769
+ case 'cancel':
770
+ await finishRun(unit, deps, plan.run, {
771
+ status: 'cancelled',
772
+ reason: null,
773
+ detail: plan.detail,
774
+ });
775
+ return;
776
+ case 'request': {
777
+ const { run, root, input } = plan;
778
+ await insertRunRequest(unit, deps, {
779
+ purpose: 'personalRunner',
780
+ commentRootRunId: root.id,
781
+ commentRunId: run.id,
782
+ commentOwnerKey: root.commentOwnerKey ?? null,
783
+ agentId: run.agentId,
784
+ subject: toRun(run).subject,
785
+ threadScope: run.threadScope,
786
+ // The plan only asks for runs acting as the chain's owner.
787
+ responsibleUserId: run.actorUserId,
788
+ requestedByUserId: root.requestedByUserId ?? root.actorUserId,
789
+ ownerUserId: run.actorUserId,
790
+ priority: Number(run.priority),
791
+ requires: toRun(run).requires,
792
+ fireAt: run.availableAt,
793
+ maxAttempts: Number(run.maxAttempts),
794
+ input: toInput(input),
795
+ });
796
+ return;
797
+ }
798
+ default:
799
+ return;
800
+ }
801
+ }
802
+ /**
803
+ * Whether this runner may take this candidate under comment consent, read outside any transaction. Immutable facts
804
+ * settle most candidates without a query: no comment chain, work run as the commenter, or work not run as the
805
+ * chain's owner. The rest read the chain's requests once. A decision never needs a lock: confirmation is final,
806
+ * and rejection or Run as me end the chain's queued runs, which the claim's guarded `status = 'queued'` update sees.
807
+ */
808
+ async function commentConsentFor(conn, runner, run) {
809
+ const allowed = { allowed: true, confirmedByUserId: null };
810
+ const refused = { allowed: false, confirmedByUserId: null };
811
+ if (!run.commentRootRunId || run.commentExecution === 'requester')
812
+ return allowed;
813
+ const root = await findRunRecord(conn, run.commentRootRunId);
814
+ if (!root || root.commentRootRunId !== root.id)
815
+ return refused;
816
+ if (root.commentExecution === 'requester' ||
817
+ run.actorUserId !== root.ownerUserId)
818
+ return allowed;
819
+ const { decision, confirmation } = await commentConsent(conn, root);
820
+ if (decision === 'rejected')
821
+ return refused;
822
+ if (decision === 'confirmed')
823
+ return {
824
+ allowed: true,
825
+ confirmedByUserId: confirmation?.settledById ?? null,
826
+ };
827
+ if (runner.trust === 'team')
828
+ return allowed;
829
+ return (await commentFromOwner(conn, root)) ? allowed : refused;
830
+ }
831
+ /** Withdraws the request a team claim made obsolete, writing only when one is pending. */
832
+ async function withdrawIfPending(rootId, runId) {
833
+ try {
834
+ const pending = await runRequestsRepo(tx.read()).findMany({
835
+ filter: {
836
+ commentRootRunId: rootId,
837
+ commentRunId: runId,
838
+ purpose: 'personalRunner',
839
+ status: 'pending',
840
+ },
841
+ limit: 1,
842
+ });
843
+ if (pending.length > 0)
844
+ await tx.run((unit) => withdrawCommentRequests(unit, rootId, clock.now().toISOString(), runId));
845
+ }
846
+ catch (error) {
847
+ deps.onClaimFailure?.(runId, error);
848
+ }
849
+ }
850
+ async function admit(unit, run, agent, runner, inputs, prepared) {
851
+ const rejection = await deps.subjects.get(run.subjectKind)?.context.admit?.(unit.conn, {
472
852
  run: toRun(run),
473
853
  agent,
474
854
  runner,
475
855
  inputs,
476
856
  cli: deps.cli.name,
477
857
  appName: deps.app.name,
478
- dialect: dialectOf(agent),
479
- });
858
+ }, prepared);
480
859
  if (!rejection)
481
860
  return true;
482
861
  await finishRun(unit, deps, run, {
@@ -487,62 +866,144 @@ export function createClaimService(deps) {
487
866
  return false;
488
867
  }
489
868
  async function attempt(runner, agent, candidate, reported) {
490
- // Avoid assembling or asking authorization when a cheap claim rule already rules this work out.
491
869
  const conn = tx.read();
492
- if (!fits(runner, agent, candidate) ||
493
- (await deps.slotsUsed(conn, runner.id)) >= runner.slots ||
494
- (await countActive(conn, 'agentId', agent.id)) >=
495
- agent.maxConcurrentRuns ||
870
+ // Rules that do not depend on who the run acts as come first, and settle the rest of the pass: an agent at its
871
+ // limit is checked once per poll, not once per queued run.
872
+ if ((await countActive(conn, 'agentId', agent.id)) >= agent.maxConcurrentRuns)
873
+ return { kind: 'full', scope: 'agent' };
874
+ // Repair pre-upgrade queued work before even checking personal runner ownership. Reading first keeps a poll over
875
+ // current work free of transactions and row locks; only work whose identity changed is written.
876
+ if (deps.subjects.get(candidate.subjectKind)?.actsAs &&
877
+ !(await queuedIdentityCurrent(conn, deps, candidate))) {
878
+ const current = await tx.run(async (unit) => {
879
+ await lockAgentForClaim(unit.conn, agent.id, clock.now().toISOString());
880
+ const run = await findRunRecord(unit.conn, candidate.id);
881
+ return run?.status === 'queued'
882
+ ? refreshQueuedIdentity(unit, deps, run)
883
+ : null;
884
+ });
885
+ if (!current)
886
+ return { kind: 'skipped' };
887
+ candidate = current;
888
+ }
889
+ // Avoid assembling or asking authorization when a cheap claim rule already rules this work out.
890
+ if (!fits(runner, agent, candidate, clock.now().getTime()) ||
496
891
  (await runsOfKey(conn, candidate, ACTIVE)).length > 0)
497
892
  return { kind: 'skipped' };
893
+ const consent = await commentConsentFor(conn, runner, candidate);
894
+ if (!consent.allowed)
895
+ return { kind: 'skipped' };
498
896
  // Before the transaction: on SQLite it holds the only connection, so the providers read what else they need now.
499
- const prepared = await prepareExtensions(toRun(candidate), deps.sections, deps.mounts, (error) => deps.onClaimFailure?.(candidate.id, error), deps.repoAccess, { onDemand: asksCredentialsOnDemand(runner) });
897
+ const prepared = new Map(await prepareExtensions(toRun(candidate), deps.sections, deps.mounts, (error) => deps.onClaimFailure?.(candidate.id, error), deps.repoAccess, { onDemand: asksCredentialsOnDemand(runner) }));
898
+ const subjectContext = deps.subjects.get(candidate.subjectKind)?.context;
899
+ if (subjectContext?.prepare) {
900
+ try {
901
+ prepared.set('subject', await subjectContext.prepare(toRun(candidate)));
902
+ }
903
+ catch (error) {
904
+ deps.onClaimFailure?.(candidate.id, error);
905
+ }
906
+ }
500
907
  let taken;
908
+ let runnerFull = false;
501
909
  try {
502
910
  taken = await tx.run(async (unit) => {
503
911
  const { conn } = unit;
504
912
  const now = clock.now();
505
913
  const nowText = now.toISOString();
506
914
  await lockAgentForClaim(conn, agent.id, nowText);
915
+ const queuedRun = await findRunRecord(conn, candidate.id);
916
+ if (!queuedRun || queuedRun.status !== 'queued')
917
+ return null;
918
+ const identity = await refreshQueuedIdentity(unit, deps, queuedRun);
919
+ // Providers were prepared for the candidate's identity outside this transaction.
920
+ if (!identity || identity.actorUserId !== candidate.actorUserId)
921
+ return null;
507
922
  if ((await countActive(conn, 'agentId', agent.id)) >=
508
923
  agent.maxConcurrentRuns)
509
924
  return null;
510
925
  // Slots are shared with the jobs the runner holds.
511
- if ((await deps.slotsUsed(conn, runner.id)) >= runner.slots)
926
+ const held = await deps.slotsHeld(conn, runner.id);
927
+ if (held.runs + held.jobs >= runner.slots) {
928
+ runnerFull = true;
929
+ return null;
930
+ }
931
+ // Total and per-tool room come from the same locked snapshot.
932
+ const byTool = held.byTool ?? {};
933
+ const current = identity;
934
+ if (!current ||
935
+ current.status !== 'queued' ||
936
+ (current.availableAt &&
937
+ new Date(current.availableAt).getTime() > now.getTime()))
512
938
  return null;
513
- // The first of the agent's tools with room, by its limit here and by what the runner said it can take.
514
- const byTool = await runsHeldByTool(conn, runner.id);
515
- const entry = pickOpenEntry(runner, agent, (tool) => (byTool[tool] ?? 0) < toolLimit(runner, tool) && reported.has(tool));
939
+ const entry = pickOpenEntry(runner, agent, (tool) => (byTool[tool] ?? 0) < toolLimit(runner, tool) && reported.has(tool), now.getTime());
516
940
  if (!entry)
517
941
  return null;
518
942
  const busy = await runsOfKey(conn, candidate, ACTIVE);
519
943
  if (busy.length > 0)
520
944
  return null;
521
- const leaseExpiresAt = later(now, TIMINGS.leaseMs);
945
+ const leaseExpiresAt = later(now, TIMINGS.startTimeoutMs);
946
+ const dispatchValues = {
947
+ status: 'dispatched',
948
+ failureReason: null,
949
+ failureDetail: null,
950
+ runnerId: runner.id,
951
+ // Brief providers observe this reservation inside the claim transaction.
952
+ // Replace a previous attempt's tool before computing the roster.
953
+ tool: entry.tool,
954
+ leaseExpiresAt,
955
+ dispatchedAt: nowText,
956
+ lastActivityAt: nowText,
957
+ availableAt: null,
958
+ updatedAt: nowText,
959
+ ...(consent.confirmedByUserId
960
+ ? { confirmedByUserId: consent.confirmedByUserId }
961
+ : {}),
962
+ };
522
963
  const claimed = await runsRepo(conn).updateMany({
523
964
  filter: (f) => f.and([
524
965
  f.string('id').eq(candidate.id),
525
966
  f.string('status').eq('queued'),
967
+ f.string('actorUserId').eq(candidate.actorUserId),
526
968
  ]),
527
- values: {
528
- status: 'dispatched',
529
- runnerId: runner.id,
530
- leaseExpiresAt,
531
- dispatchedAt: nowText,
532
- lastActivityAt: nowText,
533
- availableAt: null,
534
- updatedAt: nowText,
535
- },
969
+ values: dispatchValues,
536
970
  });
537
971
  if (claimed.updatedCount !== 1)
538
972
  return null;
539
- const run = (await findRunRecord(conn, candidate.id));
540
- const pending = await pendingInputs(conn, run.id);
973
+ const run = { ...current, ...dispatchValues };
974
+ const pending = (await pendingInputs(conn, run.id)).filter((input) => !run.commentRootRunId ||
975
+ input.type !== 'comment' ||
976
+ jsonObject(input.payload).commentRootRunId === run.commentRootRunId);
541
977
  let assembled;
978
+ let selectionSnapshot;
542
979
  try {
543
- if (!(await admit(unit, run, agent, runner, pending.map(toInput))))
980
+ if (!(await admit(unit, run, agent, runner, pending.map(toInput), prepared.get('subject'))))
544
981
  return null;
545
- assembled = await assemble(unit, run, agent, runner, pending.map(toInput), leaseExpiresAt, prepared, entry);
982
+ // Admission must precede preflight assembly: a missing or obsolete
983
+ // subject is cancelled normally, rather than counted as setup failure.
984
+ const resources = claimResources(conn, run.id);
985
+ const selection = await selectionFacts(conn, toRun(current), agent, true, undefined, resources);
986
+ const elapsed = Math.max(0, (now.getTime() - queueStart(toRun(current))) / 1000);
987
+ const preferredAvailable = (selection?.entries[0]?.compatibleCount ?? 0) > 0 ||
988
+ selection?.entries[0]?.reason === 'unknown' ||
989
+ selection?.entries[0]?.blockers?.includes('unknown') === true;
990
+ const chosenIndex = agent.modelEntries.indexOf(entry);
991
+ if (selection && chosenIndex > 0) {
992
+ // Throw to roll back the provisional dispatch; the original run keeps
993
+ // waiting for its first choice without consuming an attempt or token.
994
+ if (preferredAvailable && elapsed < selection.fallbackAfterSeconds)
995
+ throw new NotForThisRunner();
996
+ selectionSnapshot = {
997
+ reason: preferredAvailable
998
+ ? 'preferredQueued'
999
+ : 'preferredUnavailable',
1000
+ preferredTool: agent.modelEntries[0].tool,
1001
+ preferredModel: agent.modelEntries[0].model,
1002
+ queueEnteredAt: selection.queueEnteredAt,
1003
+ waitedSeconds: elapsed,
1004
+ };
1005
+ }
1006
+ assembled = await assemble(unit, run, agent, runner, pending.map(toInput), leaseExpiresAt, prepared, entry, resources);
546
1007
  }
547
1008
  catch (error) {
548
1009
  if (error instanceof NotForThisRunner)
@@ -558,6 +1019,7 @@ export function createClaimService(deps) {
558
1019
  directoryKey: assembled.directoryKey,
559
1020
  tool: assembled.entry.tool,
560
1021
  executionHistory: executionHistory(run, {
1022
+ ...(selectionSnapshot ? { selection: selectionSnapshot } : {}),
561
1023
  attempt: Number(run.attempt),
562
1024
  runnerId: runner.id,
563
1025
  runnerName: runner.name,
@@ -608,8 +1070,15 @@ export function createClaimService(deps) {
608
1070
  }
609
1071
  if (!taken) {
610
1072
  await discardRepoAccess(candidate, prepared);
611
- return { kind: 'skipped' };
1073
+ return runnerFull
1074
+ ? { kind: 'full', scope: 'runner' }
1075
+ : { kind: 'skipped' };
612
1076
  }
1077
+ // After the claim commits, never inside it: decisions settle the request before touching runs, so a claim that
1078
+ // held its run while waiting for the request could deadlock with them. A request left pending by a crash here is
1079
+ // withdrawn by the next reconciliation, and confirming it finds the run no longer waiting.
1080
+ if (candidate.commentRootRunId && runner.trust === 'team')
1081
+ await withdrawIfPending(candidate.commentRootRunId, candidate.id);
613
1082
  return { kind: 'claimed', payload: taken };
614
1083
  }
615
1084
  async function discardRepoAccess(run, prepared) {
@@ -642,20 +1111,18 @@ export function createClaimService(deps) {
642
1111
  filter: { id: runId },
643
1112
  values: {
644
1113
  claimFailures: failures,
1114
+ failureReason: 'setupFailed',
645
1115
  failureDetail: error.message.slice(0, 10_000),
646
1116
  },
647
1117
  });
648
1118
  });
649
1119
  }
650
- /** Queued runs of agents of `type` that may be claimed now, in claim order. */
651
- async function candidatesOf(type) {
1120
+ /** Queued runs that may be claimed now, in claim order. */
1121
+ async function candidates() {
652
1122
  const now = clock.now();
653
1123
  return runsRepo(tx.read()).findMany({
654
1124
  filter: (f) => f.and([
655
1125
  f.string('status').eq('queued'),
656
- f.string('agentType').eq(type),
657
- // A consultation is taken by the holder of the run that asked it, never from the queue.
658
- f.string('parentRunId').empty(),
659
1126
  f.or([
660
1127
  f.date('availableAt').empty(),
661
1128
  f.date('availableAt').notAfter(now),
@@ -669,180 +1136,38 @@ export function createClaimService(deps) {
669
1136
  limit: CANDIDATES,
670
1137
  });
671
1138
  }
672
- /** Takes an online run for `holder` in one transaction, or skips it when another holder or run got there first. */
673
- async function attemptServer(holder, agent, candidate) {
674
- const prepared = await prepareExtensions(toRun(candidate), deps.sections, undefined, (error) => deps.onClaimFailure?.(candidate.id, error));
675
- return tx.run(async (unit) => {
676
- const { conn } = unit;
677
- const now = clock.now();
678
- const nowText = now.toISOString();
679
- // Serializes claims and enqueues of this agent, so one key never has two runs held.
680
- await lockAgentForClaim(conn, agent.id, nowText);
681
- if ((await runsOfKey(conn, candidate, ACTIVE)).length > 0)
682
- return null;
683
- const leaseExpiresAt = later(now, TIMINGS.leaseMs);
684
- const taken = await runsRepo(conn).updateMany({
685
- filter: (f) => f.and([
686
- f.string('id').eq(candidate.id),
687
- f.string('status').eq('queued'),
688
- ]),
689
- values: {
690
- status: 'dispatched',
691
- runnerId: holder.id,
692
- leaseExpiresAt,
693
- dispatchedAt: nowText,
694
- lastActivityAt: nowText,
695
- availableAt: null,
696
- updatedAt: nowText,
697
- },
698
- });
699
- if (taken.updatedCount !== 1)
700
- return null;
701
- const run = (await findRunRecord(conn, candidate.id));
702
- const pending = await pendingInputs(conn, run.id);
703
- const inputs = pending.map(toInput);
704
- let claimed;
705
- try {
706
- if (!(await admit(unit, run, agent, null, inputs)))
707
- return null;
708
- claimed = await assembleServer(unit, run, agent, holder, inputs, leaseExpiresAt, prepared);
709
- }
710
- catch (error) {
711
- throw new AssemblyError(error instanceof Error ? error.message : String(error), error);
712
- }
713
- await settleClaimInputs(conn, pending, claimed.inputs, nowText);
714
- await runsRepo(conn).updateMany({
715
- filter: { id: run.id },
716
- values: {
717
- tool: null,
718
- executionHistory: executionHistory(run, {
719
- attempt: Number(run.attempt),
720
- runnerId: holder.id,
721
- runnerName: null,
722
- runnerOwnerUserId: null,
723
- runnerOwnerName: null,
724
- runnerTrust: null,
725
- tool: null,
726
- toolVersion: null,
727
- modelService: claimed.model?.modelService ?? null,
728
- model: claimed.model?.model ?? null,
729
- actualModels: [],
730
- effort: claimed.model?.effort ?? null,
731
- dispatchedAt: nowText,
732
- finishedAt: null,
733
- failureReason: null,
734
- }),
735
- modelService: claimed.model?.modelService ?? null,
736
- model: claimed.model?.model ?? null,
737
- effort: claimed.model?.effort ?? null,
738
- },
739
- });
740
- unit.emit({ type: 'run.changed', runId: run.id, status: 'dispatched' });
741
- return {
742
- ...claimed,
743
- run: {
744
- ...claimed.run,
745
- tool: null,
746
- modelService: claimed.model?.modelService ?? null,
747
- model: claimed.model?.model ?? null,
748
- effort: claimed.model?.effort ?? null,
749
- },
750
- };
751
- });
752
- }
753
- async function assembleServer({ conn }, run, agent, holder, inputs, leaseExpiresAt, prepared) {
754
- const binding = deps.subjects.get(run.subjectKind);
755
- if (!binding)
756
- throw new Error(`No context provider is registered for subjects of kind "${run.subjectKind}".`);
757
- const view = toRun(run);
758
- const claim = {
759
- run: view,
760
- agent,
761
- runner: null,
762
- inputs,
763
- cli: deps.cli.name,
764
- appName: deps.app.name,
765
- dialect: 'tools',
766
- };
767
- const assembly = await binding.context.assemble(conn, claim);
768
- inputs = assembly.inputs ?? inputs;
769
- const effectiveClaim = { ...claim, inputs };
770
- if (assembly.dirs.length > 0)
771
- throw new Error('An online agent has no working directory, and this work needs one.');
772
- const skills = await deps.skills.forRun(conn, skillTargets(agent, assembly), run.id);
773
- const own = new Set(skills.map((skill) => skill.slug));
774
- const rendered = briefOf(agent, await withSections(conn, deps.sections, effectiveClaim, assembly, prepared), [], deps.cli.name, deps.app.name);
775
- // The skills an online run reads through its tools, and the agents it may consult, whatever system layer its
776
- // subject gives it.
777
- const consultable = (await deps.consultations?.targets(conn, run, agent)) ?? [];
778
- const depth = run.parentRunId
779
- ? ((await deps.consultations?.chain(conn, run))?.length ?? 1) - 1
780
- : 0;
781
- const section = [
782
- ...onlineSkillsSection([
783
- ...skills,
784
- ...(deps.onlineSkills?.() ?? []).filter((skill) => !own.has(skill.slug)),
785
- ]),
786
- ...(consultable.length > 0 ? ['', ...consultSection(consultable)] : []),
787
- ];
788
- const layers = section.length > 0
789
- ? {
790
- ...rendered.layers,
791
- system: [rendered.layers.system, '', ...section].join('\n'),
792
- }
793
- : rendered.layers;
794
- const brief = { ...rendered, layers, prompt: joinBrief(layers) };
795
- const token = await mintRunToken(conn, deps, run, holder.id);
796
- deps.secrets?.remember(runSecretsKey(run.id), [token.value]);
797
- const last = await eventsRepo(conn).findOne({
798
- filter: { runId: run.id },
799
- sort: (sort) => sort.field('seq').desc(),
800
- });
801
- await saveBrief(conn, () => deps.ids.next(), {
802
- runId: run.id,
803
- attempt: Number(run.attempt),
804
- layers: brief.layers,
805
- turn: brief.turn,
806
- prompt: brief.prompt,
807
- createdAt: clock.now().toISOString(),
808
- });
809
- return {
810
- runId: run.id,
811
- attempt: Number(run.attempt),
812
- agent,
813
- run: view,
814
- model: onlineEntryOf(agent, assembly.model, (await deps.defaultModel?.(conn)) ?? null),
815
- system: brief.prompt,
816
- turn: brief.turn,
817
- inputs,
818
- token: token.value,
819
- skills,
820
- leaseExpiresAt,
821
- firstSeq: (last ? Number(last.seq) : 0) + 1,
822
- consultable,
823
- depth,
824
- };
825
- }
826
1139
  async function claimOne(runner, seen, reported) {
1140
+ if (runner.draining)
1141
+ return null;
827
1142
  const conn = tx.read();
828
- const candidates = await candidatesOf('runner');
829
- const agents = new Map();
830
- for (const candidate of candidates) {
831
- if (seen.has(candidate.id))
1143
+ const queued = await candidates();
1144
+ const agents = await findAgents(conn, queued
1145
+ .filter((candidate) => !seen.has(candidate.id))
1146
+ .map((candidate) => candidate.agentId));
1147
+ const full = new Set();
1148
+ for (const candidate of queued) {
1149
+ if (seen.has(candidate.id) || full.has(candidate.agentId))
832
1150
  continue;
833
1151
  seen.add(candidate.id);
834
- if (!agents.has(candidate.agentId))
835
- agents.set(candidate.agentId, await findAgent(conn, candidate.agentId));
836
1152
  const agent = agents.get(candidate.agentId);
837
- if (!agent || !fits(runner, agent, candidate))
1153
+ if (!agent ||
1154
+ (!deps.subjects.get(candidate.subjectKind)?.actsAs &&
1155
+ !fits(runner, agent, candidate, clock.now().getTime())))
838
1156
  continue;
839
1157
  // None of its tools has room on the runner's side: the runs behind it may still fit.
840
- if (!pickOpenEntry(runner, agent, (tool) => reported.has(tool)))
1158
+ if (!pickOpenEntry(runner, agent, (tool) => reported.has(tool), clock.now().getTime()))
841
1159
  continue;
842
1160
  try {
843
1161
  const result = await attempt(runner, agent, candidate, reported);
844
1162
  if (result.kind === 'claimed')
845
1163
  return result.payload;
1164
+ if (result.kind === 'full') {
1165
+ if (result.scope === 'runner')
1166
+ return null;
1167
+ // Seen candidates are passed over for good in this claim; unvisited ones stay eligible for the next pass.
1168
+ seen.delete(candidate.id);
1169
+ full.add(candidate.agentId);
1170
+ }
846
1171
  }
847
1172
  catch (error) {
848
1173
  // Rolled back: the run stays queued for a runner it fits.
@@ -856,16 +1181,57 @@ export function createClaimService(deps) {
856
1181
  return null;
857
1182
  }
858
1183
  return {
1184
+ reconcileCommentConsent,
1185
+ async reconcileCommentQueue() {
1186
+ const conn = tx.read();
1187
+ const queued = await runsRepo(conn).findMany({
1188
+ filter: (f) => f.and([
1189
+ f.string('status').eq('queued'),
1190
+ f.string('commentRootRunId').notEmpty(),
1191
+ ]),
1192
+ sort: (s) => [s.field('createdAt').asc()],
1193
+ limit: 100,
1194
+ });
1195
+ const pending = await runRequestsRepo(conn).findMany({
1196
+ filter: { purpose: 'personalRunner', status: 'pending' },
1197
+ limit: 100,
1198
+ });
1199
+ for (const id of new Set([
1200
+ ...queued.map((run) => run.id),
1201
+ ...pending
1202
+ .map((request) => request.commentRunId)
1203
+ .filter((id) => Boolean(id)),
1204
+ ])) {
1205
+ // Read first: a sweep over settled chains opens no transaction at all.
1206
+ const plan = await planCommentConsent(conn, id);
1207
+ if (plan.kind === 'none')
1208
+ continue;
1209
+ await tx.run(async (unit) => {
1210
+ if (plan.kind === 'request' || plan.kind === 'refresh')
1211
+ await lockAgentForClaim(unit.conn, plan.run.agentId, clock.now().toISOString());
1212
+ await reconcileCommentConsent(unit, id);
1213
+ });
1214
+ }
1215
+ },
1216
+ diagnose: (conn, run, agent) => selectionFacts(conn, run, agent, false),
1217
+ async selectionWait(runId) {
1218
+ const conn = tx.read();
1219
+ const run = await findRunRecord(conn, runId);
1220
+ if (!run || run.status !== 'queued')
1221
+ return null;
1222
+ const agent = await findAgent(conn, run.agentId);
1223
+ return agent ? selectionFacts(conn, toRun(run), agent, false) : null;
1224
+ },
859
1225
  async claim(runner, free, tools) {
860
- if (runner.status !== 'online')
861
- return [];
862
- if ((await deps.slotsUsed(tx.read(), runner.id)) >= runner.slots)
1226
+ if (runner.status !== 'online' || runnerLowOnDisk(runner))
863
1227
  return [];
864
1228
  const payloads = [];
865
1229
  const seen = new Set();
866
1230
  const limit = Math.min(free, runner.slots);
867
1231
  const reported = toolRoom(tools);
868
1232
  while (payloads.length < limit) {
1233
+ if ((await deps.slotsUsed(tx.read(), runner.id)) >= runner.slots)
1234
+ break;
869
1235
  const payload = await claimOne(runner, seen, reported);
870
1236
  if (!payload)
871
1237
  break;
@@ -874,64 +1240,6 @@ export function createClaimService(deps) {
874
1240
  }
875
1241
  return payloads;
876
1242
  },
877
- async claimServer(holder, limit) {
878
- const claimed = [];
879
- const conn = tx.read();
880
- const agents = new Map();
881
- for (const candidate of await candidatesOf('online')) {
882
- if (claimed.length >= limit)
883
- break;
884
- if (!agents.has(candidate.agentId))
885
- agents.set(candidate.agentId, await findAgent(conn, candidate.agentId));
886
- const agent = agents.get(candidate.agentId);
887
- if (!agent || agent.archivedAt || agent.type !== 'online')
888
- continue;
889
- try {
890
- const taken = await attemptServer(holder, agent, candidate);
891
- if (taken)
892
- claimed.push(taken);
893
- }
894
- catch (error) {
895
- if (!(error instanceof AssemblyError))
896
- throw error;
897
- await recordFailure(candidate.id, error);
898
- }
899
- }
900
- return claimed;
901
- },
902
- async claimChild(holder, runId) {
903
- const conn = tx.read();
904
- const candidate = await findRunRecord(conn, runId);
905
- if (!candidate?.parentRunId || candidate.status !== 'queued')
906
- throw notFound('Run');
907
- const parent = await findRunRecord(conn, candidate.parentRunId);
908
- if (parent?.runnerId !== holder.id)
909
- throw notFound('Run');
910
- const agent = await findAgent(conn, candidate.agentId);
911
- if (!agent || agent.archivedAt || agent.type !== 'online')
912
- throw notFound('Agent');
913
- try {
914
- const taken = await attemptServer(holder, agent, candidate);
915
- if (!taken)
916
- throw notFound('Run');
917
- return taken;
918
- }
919
- catch (error) {
920
- if (!(error instanceof AssemblyError))
921
- throw error;
922
- // One attempt: a consultation that cannot be assembled fails at once.
923
- await tx.run(async (unit) => {
924
- const run = await findRunRecord(unit.conn, runId);
925
- if (run)
926
- await finishRun(unit, deps, run, {
927
- status: 'failed',
928
- reason: 'setupFailed',
929
- detail: error.message,
930
- });
931
- });
932
- throw error;
933
- }
934
- },
935
1243
  async runSkills(runner, runId) {
936
1244
  const conn = tx.read();
937
1245
  const run = await findRunRecord(conn, runId);
@@ -948,8 +1256,7 @@ export function createClaimService(deps) {
948
1256
  inputs: [],
949
1257
  cli: deps.cli.name,
950
1258
  appName: deps.app.name,
951
- dialect: dialectOf(agent),
952
- });
1259
+ }, await binding.context.prepare?.(toRun(run)));
953
1260
  return deps.skills.forRun(conn, skillTargets(agent, assembly), run.id);
954
1261
  },
955
1262
  };