@capybara-hq/kernel 0.1.0-rc.4 → 0.1.0-rc.6

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 (534) hide show
  1. package/bootstrap.json +61 -5
  2. package/dist/admin/admin.controller.d.ts +51 -14
  3. package/dist/admin/admin.controller.js +60 -19
  4. package/dist/admin/extensions.controller.d.ts +16 -2
  5. package/dist/admin/extensions.controller.js +26 -6
  6. package/dist/admin/setup-lock.d.ts +1 -1
  7. package/dist/admin/setup-lock.js +1 -1
  8. package/dist/admin/setup.controller.d.ts +1 -1
  9. package/dist/admin/setup.controller.js +1 -1
  10. package/dist/admin/setup.service.d.ts +4 -4
  11. package/dist/admin/setup.service.js +8 -8
  12. package/dist/agents/agent-lookup.d.ts +16 -0
  13. package/dist/agents/agent-lookup.js +11 -0
  14. package/dist/agents/agents.controller.d.ts +76 -1
  15. package/dist/agents/agents.controller.js +90 -11
  16. package/dist/agents/agents.module.d.ts +4 -1
  17. package/dist/agents/agents.module.js +32 -6
  18. package/dist/agents/agents.service.d.ts +54 -23
  19. package/dist/agents/agents.service.js +180 -76
  20. package/dist/agents/definition.d.ts +49 -0
  21. package/dist/agents/definition.js +45 -0
  22. package/dist/agents/from-template.d.ts +106 -0
  23. package/dist/agents/from-template.js +649 -0
  24. package/dist/agents/from-template.service.d.ts +60 -0
  25. package/dist/agents/from-template.service.js +161 -0
  26. package/dist/agents/models.controller.d.ts +34 -5
  27. package/dist/agents/models.controller.js +50 -6
  28. package/dist/agents/org-templates.d.ts +176 -0
  29. package/dist/agents/org-templates.js +827 -0
  30. package/dist/agents/pending-connector-requests.d.ts +77 -0
  31. package/dist/agents/pending-connector-requests.js +215 -0
  32. package/dist/agents/pending-connectors.controller.d.ts +39 -0
  33. package/dist/agents/pending-connectors.controller.js +91 -0
  34. package/dist/agents/pending-connectors.service.d.ts +62 -0
  35. package/dist/agents/pending-connectors.service.js +282 -0
  36. package/dist/agents/readiness.controller.d.ts +5 -5
  37. package/dist/agents/readiness.controller.js +6 -6
  38. package/dist/agents/templates.controller.d.ts +86 -5
  39. package/dist/agents/templates.controller.js +171 -7
  40. package/dist/agents/templates.d.ts +127 -23
  41. package/dist/agents/templates.js +475 -52
  42. package/dist/background/background.module.js +8 -1
  43. package/dist/background/finish.d.ts +3 -2
  44. package/dist/background/launch-lock.d.ts +4 -3
  45. package/dist/background/launch-lock.js +4 -3
  46. package/dist/background/poll.job.d.ts +9 -6
  47. package/dist/background/poll.job.js +30 -22
  48. package/dist/background/session.d.ts +13 -2
  49. package/dist/background/session.js +13 -0
  50. package/dist/background/stop.d.ts +12 -6
  51. package/dist/background/stop.js +57 -39
  52. package/dist/background/store.d.ts +18 -6
  53. package/dist/background/store.js +12 -6
  54. package/dist/background/tasks.service.d.ts +15 -5
  55. package/dist/background/tasks.service.js +42 -17
  56. package/dist/background/wake-rules.d.ts +27 -18
  57. package/dist/background/wake-rules.js +52 -22
  58. package/dist/background/wake.d.ts +13 -11
  59. package/dist/background/wake.js +20 -14
  60. package/dist/catalog/admin-catalog.controller.d.ts +129 -30
  61. package/dist/catalog/admin-catalog.controller.js +213 -42
  62. package/dist/catalog/catalog-content.d.ts +58 -32
  63. package/dist/catalog/catalog-content.js +34 -8
  64. package/dist/catalog/catalog-import.module.d.ts +7 -0
  65. package/dist/catalog/catalog-import.module.js +60 -0
  66. package/dist/catalog/catalog-items.d.ts +111 -7
  67. package/dist/catalog/catalog-items.js +279 -13
  68. package/dist/catalog/catalog-scope.service.d.ts +260 -0
  69. package/dist/catalog/catalog-scope.service.js +1116 -0
  70. package/dist/catalog/catalog.module.d.ts +7 -9
  71. package/dist/catalog/catalog.module.js +41 -31
  72. package/dist/catalog/catalog.service.d.ts +101 -29
  73. package/dist/catalog/catalog.service.js +104 -106
  74. package/dist/catalog/cli.d.ts +11 -1
  75. package/dist/catalog/cli.js +26 -1
  76. package/dist/catalog/component-promotion.d.ts +96 -0
  77. package/dist/catalog/component-promotion.js +395 -0
  78. package/dist/catalog/component-scope.controller.d.ts +152 -0
  79. package/dist/catalog/component-scope.controller.js +287 -0
  80. package/dist/catalog/component-scope.service.d.ts +303 -0
  81. package/dist/catalog/component-scope.service.js +936 -0
  82. package/dist/catalog/component-state.d.ts +174 -0
  83. package/dist/catalog/component-state.js +437 -0
  84. package/dist/catalog/job-ids.d.ts +30 -0
  85. package/dist/catalog/job-ids.js +25 -0
  86. package/dist/catalog/marketplace-fetch.d.ts +1 -1
  87. package/dist/catalog/marketplaces.controller.d.ts +22 -5
  88. package/dist/catalog/marketplaces.controller.js +56 -7
  89. package/dist/catalog/marketplaces.service.d.ts +54 -14
  90. package/dist/catalog/marketplaces.service.js +71 -22
  91. package/dist/catalog/org-catalog.controller.d.ts +125 -34
  92. package/dist/catalog/org-catalog.controller.js +181 -65
  93. package/dist/catalog/org-catalog.service.d.ts +65 -33
  94. package/dist/catalog/org-catalog.service.js +324 -157
  95. package/dist/catalog/org-extension-switch.d.ts +41 -0
  96. package/dist/catalog/org-extension-switch.js +115 -0
  97. package/dist/catalog/org-extension.controller.d.ts +119 -0
  98. package/dist/catalog/org-extension.controller.js +266 -0
  99. package/dist/catalog/org-plugin-uploads.controller.d.ts +98 -0
  100. package/dist/catalog/org-plugin-uploads.controller.js +213 -0
  101. package/dist/catalog/org-plugin-uploads.d.ts +63 -0
  102. package/dist/catalog/org-plugin-uploads.js +116 -0
  103. package/dist/catalog/owned-items.d.ts +184 -0
  104. package/dist/catalog/owned-items.js +789 -0
  105. package/dist/catalog/owned-plugin-cleanup.d.ts +56 -0
  106. package/dist/catalog/owned-plugin-cleanup.js +194 -0
  107. package/dist/catalog/ownership.d.ts +172 -0
  108. package/dist/catalog/ownership.js +326 -0
  109. package/dist/catalog/platform-components.d.ts +221 -0
  110. package/dist/catalog/platform-components.js +761 -0
  111. package/dist/catalog/platform-migration.d.ts +115 -0
  112. package/dist/catalog/platform-migration.js +582 -0
  113. package/dist/catalog/plugin-import.d.ts +178 -34
  114. package/dist/catalog/plugin-import.js +622 -82
  115. package/dist/catalog/plugin-install.d.ts +185 -41
  116. package/dist/catalog/plugin-install.js +758 -126
  117. package/dist/catalog/plugin-upgrade.d.ts +260 -225
  118. package/dist/catalog/plugin-upgrade.js +1147 -1136
  119. package/dist/catalog/request-rules.d.ts +65 -0
  120. package/dist/catalog/request-rules.js +217 -0
  121. package/dist/catalog/requests.service.d.ts +193 -118
  122. package/dist/catalog/requests.service.js +526 -343
  123. package/dist/catalog/reserved-names.d.ts +8 -0
  124. package/dist/catalog/reserved-names.js +42 -0
  125. package/dist/catalog/scope-orgs.d.ts +21 -0
  126. package/dist/catalog/scope-orgs.js +67 -0
  127. package/dist/catalog/scope-state.d.ts +35 -0
  128. package/dist/catalog/scope-state.js +87 -0
  129. package/dist/catalog/scope-sync-workers.d.ts +7 -0
  130. package/dist/catalog/scope-sync-workers.js +29 -0
  131. package/dist/catalog/scope-sync.d.ts +176 -0
  132. package/dist/catalog/scope-sync.js +576 -0
  133. package/dist/catalog/scope.d.ts +42 -0
  134. package/dist/catalog/scope.js +42 -0
  135. package/dist/catalog/unshare.d.ts +22 -0
  136. package/dist/catalog/unshare.js +118 -0
  137. package/dist/channels/actions.js +1 -0
  138. package/dist/channels/cards.js +20 -2
  139. package/dist/channels/channels.module.js +2 -0
  140. package/dist/channels/inbound.d.ts +9 -1
  141. package/dist/channels/inbound.js +67 -5
  142. package/dist/channels/phrases.d.ts +35 -0
  143. package/dist/channels/phrases.js +29 -0
  144. package/dist/config/docs.js +3 -1
  145. package/dist/config/schema.d.ts +10 -2
  146. package/dist/config/schema.js +70 -22
  147. package/dist/conversations/access.d.ts +6 -4
  148. package/dist/conversations/access.js +27 -5
  149. package/dist/conversations/agent-tree.d.ts +46 -0
  150. package/dist/conversations/agent-tree.js +92 -0
  151. package/dist/conversations/conversations.controller.d.ts +43 -18
  152. package/dist/conversations/conversations.controller.js +79 -38
  153. package/dist/conversations/conversations.module.d.ts +1 -1
  154. package/dist/conversations/conversations.module.js +7 -7
  155. package/dist/conversations/conversations.service.d.ts +73 -15
  156. package/dist/conversations/conversations.service.js +115 -35
  157. package/dist/conversations/environment-status.d.ts +24 -0
  158. package/dist/conversations/environment-status.js +71 -0
  159. package/dist/conversations/event-log.d.ts +20 -5
  160. package/dist/conversations/event-log.js +60 -0
  161. package/dist/conversations/events.d.ts +84 -2
  162. package/dist/conversations/events.js +91 -17
  163. package/dist/conversations/queue.service.d.ts +1 -1
  164. package/dist/conversations/queue.service.js +5 -0
  165. package/dist/conversations/titles.d.ts +5 -3
  166. package/dist/conversations/titles.js +21 -8
  167. package/dist/conversations/tree.d.ts +17 -0
  168. package/dist/conversations/tree.js +42 -0
  169. package/dist/ctx/create-ctx.d.ts +20 -1
  170. package/dist/ctx/create-ctx.js +38 -7
  171. package/dist/db/kernel-schema.d.ts +386 -18
  172. package/dist/environments/access.d.ts +41 -0
  173. package/dist/environments/access.js +77 -0
  174. package/dist/environments/conversation-environments.d.ts +61 -0
  175. package/dist/environments/conversation-environments.js +170 -0
  176. package/dist/environments/dto.d.ts +25 -0
  177. package/dist/environments/dto.js +12 -0
  178. package/dist/environments/environments.controller.d.ts +33 -0
  179. package/dist/environments/environments.controller.js +110 -0
  180. package/dist/environments/environments.module.d.ts +8 -0
  181. package/dist/environments/environments.module.js +27 -0
  182. package/dist/environments/environments.service.d.ts +153 -0
  183. package/dist/environments/environments.service.js +541 -0
  184. package/dist/environments/legacy-cleanup.job.d.ts +34 -0
  185. package/dist/environments/legacy-cleanup.job.js +141 -0
  186. package/dist/errors.d.ts +85 -2
  187. package/dist/errors.js +85 -2
  188. package/dist/evals/reconstruct.d.ts +18 -9
  189. package/dist/evals/reconstruct.js +26 -7
  190. package/dist/evals/run-replay.d.ts +4 -2
  191. package/dist/evals/run-replay.js +20 -6
  192. package/dist/evals/runs.service.d.ts +2 -1
  193. package/dist/evals/runs.service.js +13 -12
  194. package/dist/evals/step-replay.d.ts +4 -6
  195. package/dist/evals/step-replay.js +4 -3
  196. package/dist/evals/trajectory.service.d.ts +8 -3
  197. package/dist/evals/trajectory.service.js +26 -14
  198. package/dist/evals/worker.d.ts +5 -5
  199. package/dist/evals/worker.js +9 -3
  200. package/dist/extensions/admin-ops.d.ts +36 -10
  201. package/dist/extensions/admin-ops.js +65 -42
  202. package/dist/extensions/admin-view.d.ts +37 -10
  203. package/dist/extensions/admin-view.js +103 -20
  204. package/dist/extensions/bootstrap.d.ts +17 -4
  205. package/dist/extensions/bootstrap.js +70 -9
  206. package/dist/extensions/cli.d.ts +12 -0
  207. package/dist/extensions/cli.js +11 -2
  208. package/dist/extensions/config-hash.d.ts +10 -0
  209. package/dist/extensions/config-hash.js +38 -0
  210. package/dist/extensions/deployment-config.d.ts +28 -5
  211. package/dist/extensions/deployment-config.js +48 -7
  212. package/dist/extensions/effective-config.d.ts +127 -0
  213. package/dist/extensions/effective-config.js +368 -0
  214. package/dist/extensions/extensions.module.js +11 -11
  215. package/dist/extensions/hooks.d.ts +37 -4
  216. package/dist/extensions/hooks.js +82 -16
  217. package/dist/extensions/host.d.ts +24 -10
  218. package/dist/extensions/host.js +49 -54
  219. package/dist/extensions/installs.d.ts +20 -8
  220. package/dist/extensions/installs.js +37 -15
  221. package/dist/extensions/org-config.d.ts +75 -6
  222. package/dist/extensions/org-config.js +184 -32
  223. package/dist/extensions/org-levels.d.ts +37 -0
  224. package/dist/extensions/org-levels.js +71 -0
  225. package/dist/extensions/org-overrides.d.ts +151 -0
  226. package/dist/extensions/org-overrides.js +524 -0
  227. package/dist/extensions/permission-view.d.ts +16 -4
  228. package/dist/extensions/permission-view.js +4 -4
  229. package/dist/extensions/plugin-items.d.ts +21 -0
  230. package/dist/extensions/plugin-items.js +42 -0
  231. package/dist/extensions/point-defaults.d.ts +12 -5
  232. package/dist/extensions/point-defaults.js +37 -9
  233. package/dist/extensions/resolve.d.ts +5 -1
  234. package/dist/extensions/resolve.js +15 -2
  235. package/dist/extensions/state.module.d.ts +9 -0
  236. package/dist/extensions/state.module.js +38 -0
  237. package/dist/files/previewers.d.ts +8 -1
  238. package/dist/files/previewers.js +35 -6
  239. package/dist/http/api.module.js +25 -3
  240. package/dist/http/app.d.ts +11 -2
  241. package/dist/http/app.js +31 -5
  242. package/dist/http/plugin-dispatch.d.ts +4 -1
  243. package/dist/http/plugin-dispatch.js +14 -2
  244. package/dist/identity/accounts.d.ts +29 -29
  245. package/dist/identity/accounts.js +47 -47
  246. package/dist/identity/audit.d.ts +2 -1
  247. package/dist/identity/auth.guard.d.ts +13 -5
  248. package/dist/identity/auth.guard.js +26 -9
  249. package/dist/identity/identity.module.d.ts +1 -1
  250. package/dist/identity/identity.module.js +4 -4
  251. package/dist/identity/me.controller.js +1 -1
  252. package/dist/identity/principal.d.ts +3 -3
  253. package/dist/identity/principal.js +3 -3
  254. package/dist/identity/settings.d.ts +22 -11
  255. package/dist/identity/settings.js +53 -18
  256. package/dist/identity/{enterprise-admin.d.ts → super-admin.d.ts} +5 -5
  257. package/dist/identity/{enterprise-admin.js → super-admin.js} +24 -24
  258. package/dist/inbox/inbox.module.d.ts +4 -1
  259. package/dist/inbox/inbox.module.js +7 -3
  260. package/dist/inbox/inbox.service.d.ts +62 -3
  261. package/dist/inbox/inbox.service.js +74 -4
  262. package/dist/inbox/org-notices.d.ts +63 -0
  263. package/dist/inbox/org-notices.js +91 -0
  264. package/dist/inbox/platform-inbox.controller.d.ts +23 -0
  265. package/dist/inbox/platform-inbox.controller.js +58 -0
  266. package/dist/inbox/platform-inbox.service.d.ts +151 -0
  267. package/dist/inbox/platform-inbox.service.js +263 -0
  268. package/dist/inbox/platform-notices.d.ts +19 -0
  269. package/dist/inbox/platform-notices.js +9 -0
  270. package/dist/index.d.ts +1 -1
  271. package/dist/index.js +1 -1
  272. package/dist/infra/cli/kernel-cli.module.js +9 -1
  273. package/dist/infra/config/kernel-config.service.js +24 -1
  274. package/dist/infra/database/xact-lock.d.ts +1 -1
  275. package/dist/infra/database/xact-lock.js +1 -1
  276. package/dist/infra/events/kernel-events.d.ts +19 -2
  277. package/dist/infra/queue/add-job-once.d.ts +14 -0
  278. package/dist/infra/queue/add-job-once.js +16 -0
  279. package/dist/kernel.module.js +6 -0
  280. package/dist/lifecycle/kernel-lifecycle.d.ts +1 -1
  281. package/dist/lifecycle/kernel-lifecycle.js +4 -4
  282. package/dist/models/embeddings.d.ts +82 -0
  283. package/dist/models/embeddings.js +326 -0
  284. package/dist/models/enablement.controller.d.ts +40 -0
  285. package/dist/models/enablement.controller.js +74 -0
  286. package/dist/models/enablement.d.ts +99 -0
  287. package/dist/models/enablement.js +263 -0
  288. package/dist/models/models.module.d.ts +5 -1
  289. package/dist/models/models.module.js +16 -4
  290. package/dist/models/prices.d.ts +5 -5
  291. package/dist/models/prices.js +4 -4
  292. package/dist/models/purposes.controller.d.ts +6 -4
  293. package/dist/models/purposes.controller.js +13 -7
  294. package/dist/models/purposes.d.ts +37 -12
  295. package/dist/models/purposes.js +63 -17
  296. package/dist/orgs/directory-sync.d.ts +14 -5
  297. package/dist/orgs/directory-sync.js +41 -17
  298. package/dist/orgs/offboarding.d.ts +9 -7
  299. package/dist/orgs/offboarding.js +28 -17
  300. package/dist/orgs/org-lock.d.ts +5 -0
  301. package/dist/orgs/org-lock.js +13 -0
  302. package/dist/orgs/org.guard.d.ts +10 -0
  303. package/dist/orgs/org.guard.js +43 -32
  304. package/dist/orgs/orgs.module.js +3 -0
  305. package/dist/orgs/orgs.service.d.ts +20 -7
  306. package/dist/orgs/orgs.service.js +32 -12
  307. package/dist/orgs/roles.d.ts +1 -1
  308. package/dist/orgs/roles.js +5 -1
  309. package/dist/orgs/settings.controller.d.ts +1 -1
  310. package/dist/orgs/settings.service.d.ts +15 -3
  311. package/dist/orgs/settings.service.js +6 -2
  312. package/dist/overrides.d.ts +3 -0
  313. package/dist/overrides.js +2 -0
  314. package/dist/platform/actor.d.ts +48 -0
  315. package/dist/platform/actor.js +100 -0
  316. package/dist/platform/agent-docs.d.ts +18 -0
  317. package/dist/platform/agent-docs.js +59 -0
  318. package/dist/platform/availability.d.ts +14 -0
  319. package/dist/platform/availability.js +43 -0
  320. package/dist/platform/errors.d.ts +11 -0
  321. package/dist/platform/errors.js +26 -0
  322. package/dist/platform/exclusions.d.ts +12 -0
  323. package/dist/platform/exclusions.js +1405 -0
  324. package/dist/platform/method.d.ts +6 -0
  325. package/dist/platform/method.js +15 -0
  326. package/dist/platform/operation.d.ts +92 -0
  327. package/dist/platform/operation.js +35 -0
  328. package/dist/platform/ops/agent-templates.ops.d.ts +14 -0
  329. package/dist/platform/ops/agent-templates.ops.js +92 -0
  330. package/dist/platform/ops/agents.ops.d.ts +19 -0
  331. package/dist/platform/ops/agents.ops.js +294 -0
  332. package/dist/platform/ops/connectors.ops.d.ts +15 -0
  333. package/dist/platform/ops/connectors.ops.js +126 -0
  334. package/dist/platform/ops/errors.d.ts +11 -0
  335. package/dist/platform/ops/errors.js +22 -0
  336. package/dist/platform/ops/extensions.ops.d.ts +19 -0
  337. package/dist/platform/ops/extensions.ops.js +116 -0
  338. package/dist/platform/ops/marketplaces.ops.d.ts +16 -0
  339. package/dist/platform/ops/marketplaces.ops.js +157 -0
  340. package/dist/platform/ops/paging.d.ts +14 -0
  341. package/dist/platform/ops/paging.js +20 -0
  342. package/dist/platform/ops/platform.ops.d.ts +23 -0
  343. package/dist/platform/ops/platform.ops.js +158 -0
  344. package/dist/platform/ops/plugins.ops.d.ts +33 -0
  345. package/dist/platform/ops/plugins.ops.js +377 -0
  346. package/dist/platform/ops/requests.ops.d.ts +14 -0
  347. package/dist/platform/ops/requests.ops.js +153 -0
  348. package/dist/platform/ops/role.d.ts +4 -0
  349. package/dist/platform/ops/role.js +10 -0
  350. package/dist/platform/ops/skills.ops.d.ts +13 -0
  351. package/dist/platform/ops/skills.ops.js +98 -0
  352. package/dist/platform/ops/summary.d.ts +10 -0
  353. package/dist/platform/ops/summary.js +18 -0
  354. package/dist/platform/platform-ops.module.d.ts +7 -0
  355. package/dist/platform/platform-ops.module.js +55 -0
  356. package/dist/platform/platform.module.d.ts +8 -0
  357. package/dist/platform/platform.module.js +25 -0
  358. package/dist/platform/redact-orgs.d.ts +7 -0
  359. package/dist/platform/redact-orgs.js +52 -0
  360. package/dist/platform/registry.d.ts +30 -0
  361. package/dist/platform/registry.js +111 -0
  362. package/dist/roles/worker-role.d.ts +6 -4
  363. package/dist/roles/worker-role.js +14 -7
  364. package/dist/roles/worker.module.d.ts +1 -1
  365. package/dist/roles/worker.module.js +9 -1
  366. package/dist/runtime/context/build.d.ts +6 -4
  367. package/dist/runtime/context/build.js +26 -7
  368. package/dist/runtime/context/claude-tools.d.ts +2 -1
  369. package/dist/runtime/context/claude-tools.js +5 -4
  370. package/dist/runtime/context/compaction.js +9 -0
  371. package/dist/runtime/context/reminders.d.ts +2 -0
  372. package/dist/runtime/context/reminders.js +2 -0
  373. package/dist/runtime/context/skills.js +9 -2
  374. package/dist/runtime/context/tool-changes.d.ts +27 -0
  375. package/dist/runtime/context/tool-changes.js +60 -0
  376. package/dist/runtime/hook-calls.d.ts +8 -1
  377. package/dist/runtime/hook-calls.js +40 -7
  378. package/dist/runtime/langgraph-loop.d.ts +3 -1
  379. package/dist/runtime/langgraph-loop.js +35 -17
  380. package/dist/runtime/loop.d.ts +32 -4
  381. package/dist/runtime/maintenance.d.ts +7 -4
  382. package/dist/runtime/maintenance.js +23 -8
  383. package/dist/runtime/model-call.d.ts +38 -11
  384. package/dist/runtime/model-call.js +97 -24
  385. package/dist/runtime/providers.d.ts +146 -32
  386. package/dist/runtime/providers.js +321 -67
  387. package/dist/runtime/run-control.d.ts +11 -1
  388. package/dist/runtime/run-control.js +12 -0
  389. package/dist/runtime/run-drafts.d.ts +85 -0
  390. package/dist/runtime/run-drafts.js +230 -0
  391. package/dist/runtime/run-jobs.d.ts +3 -5
  392. package/dist/runtime/run-jobs.js +3 -7
  393. package/dist/runtime/run-queue.d.ts +37 -3
  394. package/dist/runtime/run-queue.js +188 -11
  395. package/dist/runtime/run-worker.d.ts +12 -6
  396. package/dist/runtime/run-worker.js +58 -35
  397. package/dist/runtime/runtime.module.js +3 -0
  398. package/dist/runtime/step-log.d.ts +9 -4
  399. package/dist/runtime/step-log.js +8 -5
  400. package/dist/runtime/stream.controller.d.ts +23 -1
  401. package/dist/runtime/stream.controller.js +60 -3
  402. package/dist/runtime/stream.d.ts +4 -1
  403. package/dist/runtime/stream.js +27 -3
  404. package/dist/runtime/subagents/child.d.ts +55 -7
  405. package/dist/runtime/subagents/child.js +105 -7
  406. package/dist/runtime/subagents/definition.d.ts +12 -3
  407. package/dist/runtime/subagents/definition.js +46 -32
  408. package/dist/runtime/subagents/deliveries.d.ts +71 -0
  409. package/dist/runtime/subagents/deliveries.js +228 -0
  410. package/dist/runtime/subagents/dispatch.d.ts +115 -26
  411. package/dist/runtime/subagents/dispatch.js +212 -141
  412. package/dist/runtime/subagents/limits.d.ts +24 -5
  413. package/dist/runtime/subagents/limits.js +40 -6
  414. package/dist/runtime/subagents/messages.d.ts +95 -0
  415. package/dist/runtime/subagents/messages.js +328 -0
  416. package/dist/runtime/subagents/preamble.d.ts +4 -4
  417. package/dist/runtime/subagents/preamble.js +9 -7
  418. package/dist/runtime/subagents/progress.d.ts +8 -6
  419. package/dist/runtime/subagents/progress.js +11 -6
  420. package/dist/runtime/subagents/render.d.ts +30 -0
  421. package/dist/runtime/subagents/render.js +53 -0
  422. package/dist/runtime/subagents/roster.d.ts +24 -7
  423. package/dist/runtime/subagents/roster.js +47 -11
  424. package/dist/runtime/subagents/skill-fork.d.ts +3 -2
  425. package/dist/runtime/subagents/skill-fork.js +8 -4
  426. package/dist/runtime/subagents/status.d.ts +14 -0
  427. package/dist/runtime/subagents/status.js +23 -0
  428. package/dist/runtime/subagents/subagents.service.d.ts +7 -4
  429. package/dist/runtime/subagents/subagents.service.js +11 -6
  430. package/dist/runtime/usage-report-jobs.d.ts +88 -0
  431. package/dist/runtime/usage-report-jobs.js +158 -0
  432. package/dist/runtime/usage-report.d.ts +33 -38
  433. package/dist/runtime/usage-report.js +169 -96
  434. package/dist/runtime/waits.d.ts +140 -37
  435. package/dist/runtime/waits.js +394 -106
  436. package/dist/sandbox/jobs.d.ts +40 -13
  437. package/dist/sandbox/jobs.js +57 -20
  438. package/dist/sandbox/leases.d.ts +37 -54
  439. package/dist/sandbox/leases.js +71 -115
  440. package/dist/sandbox/providers.d.ts +2 -2
  441. package/dist/sandbox/providers.js +1 -1
  442. package/dist/sandbox/sandbox.module.d.ts +3 -2
  443. package/dist/sandbox/sandbox.module.js +4 -3
  444. package/dist/sandbox/sandbox.service.d.ts +229 -134
  445. package/dist/sandbox/sandbox.service.js +630 -409
  446. package/dist/skills/catalog.d.ts +3 -2
  447. package/dist/skills/catalog.js +21 -43
  448. package/dist/skills/changes.controller.d.ts +7 -0
  449. package/dist/skills/changes.controller.js +19 -1
  450. package/dist/skills/invoke.js +8 -3
  451. package/dist/skills/package.d.ts +20 -1
  452. package/dist/skills/package.js +28 -1
  453. package/dist/skills/skills.controller.d.ts +39 -4
  454. package/dist/skills/skills.controller.js +88 -10
  455. package/dist/skills/skills.module.js +10 -1
  456. package/dist/skills/skills.service.d.ts +106 -26
  457. package/dist/skills/skills.service.js +421 -75
  458. package/dist/skills/usable.d.ts +81 -0
  459. package/dist/skills/usable.js +379 -0
  460. package/dist/tools/approvals.service.d.ts +20 -2
  461. package/dist/tools/approvals.service.js +23 -4
  462. package/dist/tools/builtin-names.d.ts +21 -5
  463. package/dist/tools/builtin-names.js +30 -5
  464. package/dist/tools/builtins/agent.d.ts +23 -21
  465. package/dist/tools/builtins/agent.js +62 -55
  466. package/dist/tools/builtins/builtin-tools.d.ts +6 -2
  467. package/dist/tools/builtins/builtin-tools.js +37 -12
  468. package/dist/tools/builtins/handback.d.ts +28 -0
  469. package/dist/tools/builtins/handback.js +53 -0
  470. package/dist/tools/builtins/platform.d.ts +34 -0
  471. package/dist/tools/builtins/platform.js +362 -0
  472. package/dist/tools/builtins/sandbox/bash.js +13 -3
  473. package/dist/tools/builtins/sandbox/common.d.ts +43 -24
  474. package/dist/tools/builtins/sandbox/common.js +80 -45
  475. package/dist/tools/builtins/sandbox/edit.js +2 -2
  476. package/dist/tools/builtins/sandbox/glob.js +2 -2
  477. package/dist/tools/builtins/sandbox/grep.js +2 -4
  478. package/dist/tools/builtins/sandbox/index.d.ts +1 -1
  479. package/dist/tools/builtins/sandbox/index.js +1 -1
  480. package/dist/tools/builtins/sandbox/read.js +1 -1
  481. package/dist/tools/builtins/sandbox/task-output.d.ts +14 -3
  482. package/dist/tools/builtins/sandbox/task-output.js +30 -5
  483. package/dist/tools/builtins/sandbox/task-stop.js +2 -1
  484. package/dist/tools/builtins/sandbox/write.js +2 -2
  485. package/dist/tools/builtins/send-message.d.ts +56 -0
  486. package/dist/tools/builtins/send-message.js +100 -0
  487. package/dist/tools/builtins/skill-load.d.ts +22 -14
  488. package/dist/tools/builtins/skill-load.js +86 -57
  489. package/dist/tools/builtins/skill-write.js +1 -1
  490. package/dist/tools/builtins/web/extract.js +5 -1
  491. package/dist/tools/builtins/web/fetch.js +1 -0
  492. package/dist/tools/builtins/web/search.js +1 -0
  493. package/dist/tools/connectors.controller.d.ts +10 -0
  494. package/dist/tools/connectors.controller.js +12 -0
  495. package/dist/tools/connectors.service.d.ts +46 -5
  496. package/dist/tools/connectors.service.js +94 -15
  497. package/dist/tools/extension-tools.controller.d.ts +14 -0
  498. package/dist/tools/extension-tools.controller.js +37 -0
  499. package/dist/tools/info.d.ts +42 -1
  500. package/dist/tools/info.js +64 -1
  501. package/dist/tools/org-tool-switches.d.ts +74 -0
  502. package/dist/tools/org-tool-switches.js +184 -0
  503. package/dist/tools/pipeline.d.ts +46 -40
  504. package/dist/tools/pipeline.js +193 -364
  505. package/dist/tools/policy.d.ts +1 -1
  506. package/dist/tools/policy.js +36 -16
  507. package/dist/tools/registry.d.ts +98 -5
  508. package/dist/tools/registry.js +87 -9
  509. package/dist/tools/tools.module.js +12 -2
  510. package/dist/ui/views.d.ts +2 -1
  511. package/dist/ui/views.js +17 -3
  512. package/package.json +3 -3
  513. package/src/migrations/0074_subagent_tree.sql +50 -0
  514. package/src/migrations/0075_plugin_scope.sql +61 -0
  515. package/src/migrations/0076_skills_created_by_nullable.sql +6 -0
  516. package/src/migrations/0077_scope_requests.sql +52 -0
  517. package/src/migrations/0078_scope_grant_switches.sql +18 -0
  518. package/src/migrations/0079_scope_live_install_switches.sql +19 -0
  519. package/src/migrations/0080_rename_enterprise_admin.sql +18 -0
  520. package/src/migrations/0081_platform_components.sql +129 -0
  521. package/src/migrations/0082_platform_migration.sql +33 -0
  522. package/src/migrations/0083_plugin_scope_sync_failures.sql +15 -0
  523. package/src/migrations/0084_org_owned_items.sql +85 -0
  524. package/src/migrations/0085_agent_templates_phase4.sql +45 -0
  525. package/src/migrations/0086_org_layering.sql +30 -0
  526. package/src/migrations/0087_approval_summary.sql +6 -0
  527. package/src/migrations/0088_environments.sql +80 -0
  528. package/src/migrations/0089_model_kinds_usage.sql +38 -0
  529. package/dist/catalog/upgrade-targets.d.ts +0 -56
  530. package/dist/catalog/upgrade-targets.js +0 -90
  531. package/dist/conversations/sandbox-status.d.ts +0 -24
  532. package/dist/conversations/sandbox-status.js +0 -52
  533. package/dist/extensions/org-config.controller.d.ts +0 -32
  534. package/dist/extensions/org-config.controller.js +0 -70
@@ -132,6 +132,19 @@ export declare const ToolViewSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
132
132
  }, z.core.$strip>>;
133
133
  }, z.core.$strip>], "kind">;
134
134
  export type ToolView = z.infer<typeof ToolViewSchema>;
135
+ /**
136
+ * How a sub-agent's run ended (`subagent_finished`, a `subagent_delivery` finish). `timed_out`:
137
+ * stopped by the parent's sub-agents wait timeout (`run_aborted.detail`).
138
+ */
139
+ export declare const SubagentFinishStatusSchema: z.ZodEnum<{
140
+ aborted: "aborted";
141
+ budget: "budget";
142
+ completed: "completed";
143
+ failed: "failed";
144
+ max_duration: "max_duration";
145
+ max_steps: "max_steps";
146
+ timed_out: "timed_out";
147
+ }>;
135
148
  /**
136
149
  * 会话事件(`type` + `payload`)的判别联合。事件日志只追加,写入前用它校验 payload;
137
150
  * 读出时按写入时的形状原样返回。
@@ -223,6 +236,10 @@ export declare const ConversationEventSchema: z.ZodDiscriminatedUnion<[z.ZodObje
223
236
  parentConversationId: z.ZodString;
224
237
  parentRunId: z.ZodString;
225
238
  callId: z.ZodString;
239
+ kind: z.ZodOptional<z.ZodEnum<{
240
+ message: "message";
241
+ task: "task";
242
+ }>>;
226
243
  narrowed: z.ZodOptional<z.ZodObject<{
227
244
  tools: z.ZodArray<z.ZodPreprocess<z.ZodDiscriminatedUnion<[z.ZodObject<{
228
245
  kind: z.ZodLiteral<"builtin">;
@@ -275,6 +292,7 @@ export declare const ConversationEventSchema: z.ZodDiscriminatedUnion<[z.ZodObje
275
292
  trigger: z.ZodOptional<z.ZodEnum<{
276
293
  background_task: "background_task";
277
294
  message: "message";
295
+ subagent: "subagent";
278
296
  }>>;
279
297
  triggerSeq: z.ZodOptional<z.ZodNumber>;
280
298
  }, z.core.$strip>;
@@ -421,6 +439,13 @@ export declare const ConversationEventSchema: z.ZodDiscriminatedUnion<[z.ZodObje
421
439
  step: z.ZodNumber;
422
440
  text: z.ZodString;
423
441
  }, z.core.$strip>;
442
+ }, z.core.$strip>, z.ZodObject<{
443
+ type: z.ZodLiteral<"tools_changed">;
444
+ payload: z.ZodObject<{
445
+ step: z.ZodNumber;
446
+ added: z.ZodArray<z.ZodString>;
447
+ removed: z.ZodArray<z.ZodString>;
448
+ }, z.core.$strip>;
424
449
  }, z.core.$strip>, z.ZodObject<{
425
450
  type: z.ZodLiteral<"tool_call_started">;
426
451
  payload: z.ZodObject<{
@@ -663,6 +688,7 @@ export declare const ConversationEventSchema: z.ZodDiscriminatedUnion<[z.ZodObje
663
688
  id: z.ZodOptional<z.ZodString>;
664
689
  version: z.ZodOptional<z.ZodNumber>;
665
690
  plugin: z.ZodOptional<z.ZodString>;
691
+ platformTemplateId: z.ZodOptional<z.ZodString>;
666
692
  invokedSkill: z.ZodOptional<z.ZodObject<{
667
693
  id: z.ZodString;
668
694
  version: z.ZodNumber;
@@ -747,6 +773,28 @@ export declare const ConversationEventSchema: z.ZodDiscriminatedUnion<[z.ZodObje
747
773
  }, z.core.$strict>>>;
748
774
  dispatchable: z.ZodOptional<z.ZodBoolean>;
749
775
  }, z.core.$strict>>;
776
+ pendingConnectors: z.ZodOptional<z.ZodArray<z.ZodObject<{
777
+ key: z.ZodString;
778
+ label: z.ZodString;
779
+ source: z.ZodUnion<readonly [z.ZodObject<{
780
+ template: z.ZodString;
781
+ }, z.core.$strict>, z.ZodObject<{
782
+ needs: z.ZodObject<{
783
+ protocol: z.ZodEnum<{
784
+ mcp: "mcp";
785
+ openapi: "openapi";
786
+ }>;
787
+ endpoint: z.ZodString;
788
+ tools: z.ZodArray<z.ZodString>;
789
+ label: z.ZodString;
790
+ }, z.core.$strict>;
791
+ }, z.core.$strict>]>;
792
+ tools: z.ZodOptional<z.ZodArray<z.ZodString>>;
793
+ policies: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodEnum<{
794
+ ask: "ask";
795
+ deny: "deny";
796
+ }>>>;
797
+ }, z.core.$strict>>>;
750
798
  }, z.core.$strip>;
751
799
  preamble: z.ZodString;
752
800
  maxSteps: z.ZodNumber;
@@ -781,6 +829,7 @@ export declare const ConversationEventSchema: z.ZodDiscriminatedUnion<[z.ZodObje
781
829
  }>>>;
782
830
  subagentId: z.ZodString;
783
831
  childRunId: z.ZodString;
832
+ path: z.ZodArray<z.ZodString>;
784
833
  kind: z.ZodEnum<{
785
834
  approval: "approval";
786
835
  connect: "connect";
@@ -816,6 +865,35 @@ export declare const ConversationEventSchema: z.ZodDiscriminatedUnion<[z.ZodObje
816
865
  cacheWriteTokens: z.ZodNumber;
817
866
  }, z.core.$strip>;
818
867
  }, z.core.$strip>;
868
+ }, z.core.$strip>, z.ZodObject<{
869
+ type: z.ZodLiteral<"subagent_delivery">;
870
+ payload: z.ZodObject<{
871
+ subagentId: z.ZodString;
872
+ childRunId: z.ZodString;
873
+ description: z.ZodString;
874
+ kind: z.ZodEnum<{
875
+ finished: "finished";
876
+ note: "note";
877
+ report: "report";
878
+ }>;
879
+ text: z.ZodString;
880
+ status: z.ZodOptional<z.ZodEnum<{
881
+ aborted: "aborted";
882
+ budget: "budget";
883
+ completed: "completed";
884
+ failed: "failed";
885
+ max_duration: "max_duration";
886
+ max_steps: "max_steps";
887
+ timed_out: "timed_out";
888
+ }>>;
889
+ handedBack: z.ZodOptional<z.ZodBoolean>;
890
+ errorCode: z.ZodOptional<z.ZodString>;
891
+ abortedBy: z.ZodOptional<z.ZodEnum<{
892
+ parent: "parent";
893
+ user: "user";
894
+ }>>;
895
+ triggerAccountId: z.ZodString;
896
+ }, z.core.$strip>;
819
897
  }, z.core.$strip>, z.ZodObject<{
820
898
  type: z.ZodLiteral<"skill_fork_result">;
821
899
  payload: z.ZodObject<{
@@ -845,6 +923,7 @@ export declare const ConversationEventSchema: z.ZodDiscriminatedUnion<[z.ZodObje
845
923
  stoppedBy: z.ZodOptional<z.ZodEnum<{
846
924
  deletion: "deletion";
847
925
  person: "person";
926
+ subagent_end: "subagent_end";
848
927
  }>>;
849
928
  }, z.core.$strip>;
850
929
  }, z.core.$strip>, z.ZodObject<{
@@ -907,9 +986,12 @@ export type ConversationEvent = ConversationEventBody & {
907
986
  runId: string | null;
908
987
  createdAt: Date;
909
988
  };
910
- /** An event a run absorbs at a step boundary: a person's message or a finished background task. */
989
+ /**
990
+ * An event a run absorbs at a step boundary: a person's message, a finished background task or a
991
+ * sub-agent's delivery.
992
+ */
911
993
  export type AbsorbableEvent = Extract<ConversationEvent, {
912
- type: "user_message" | "background_task_finished";
994
+ type: "user_message" | "background_task_finished" | "subagent_delivery";
913
995
  }>;
914
996
  /**
915
997
  * Whether `e` is absorbed like an interjection (spec 2026-11-05-background-bash-design §2.4): the
@@ -144,6 +144,19 @@ const ModelUsageShape = {
144
144
  cacheReadTokens: count,
145
145
  cacheWriteTokens: count,
146
146
  };
147
+ /**
148
+ * How a sub-agent's run ended (`subagent_finished`, a `subagent_delivery` finish). `timed_out`:
149
+ * stopped by the parent's sub-agents wait timeout (`run_aborted.detail`).
150
+ */
151
+ export const SubagentFinishStatusSchema = z.enum([
152
+ "completed",
153
+ "max_steps",
154
+ "max_duration",
155
+ "budget",
156
+ "aborted",
157
+ "timed_out",
158
+ "failed",
159
+ ]);
147
160
  /** 双语或纯文本(plugin-sdk `InputForm` 的文案字段)。 */
148
161
  const FormTextSchema = z.union([z.string(), z.object({ zh: z.string(), en: z.string() })]);
149
162
  /** 交互表单(plugin-sdk 的 `InputForm`;字段 schema 已由 `validateInputForm` 校验过,这里只记形状)。 */
@@ -213,6 +226,11 @@ export const ConversationEventSchema = z.discriminatedUnion("type", [
213
226
  parentConversationId: z.string(),
214
227
  parentRunId: z.string(),
215
228
  callId: z.string(),
229
+ /**
230
+ * `message`: sent by the parent agent with `SendMessage` (agent map spec §5.1); absent or
231
+ * `task`: the task of a dispatch or follow-up.
232
+ */
233
+ kind: z.enum(["task", "message"]).optional(),
216
234
  /**
217
235
  * A follow-up (`resume`, final review I1): the frozen tools and org skills intersected
218
236
  * with the current version (`narrowFollowUp`); the child's run uses these instead of
@@ -252,10 +270,14 @@ export const ConversationEventSchema = z.discriminatedUnion("type", [
252
270
  /**
253
271
  * What started the run (display only): absent or `message` = a person's message (or a
254
272
  * sub-agent's task), `background_task` = a finished background task woke the conversation
255
- * (spec 2026-11-05-background-bash-design §3).
273
+ * (spec 2026-11-05-background-bash-design §3), `subagent` = a sub-agent's delivery woke it
274
+ * (agent map spec §5.3).
275
+ */
276
+ trigger: z.enum(["message", "background_task", "subagent"]).optional(),
277
+ /**
278
+ * A wake run's boundary: the seq of the finish or delivery that woke it (full-run replay
279
+ * seeds from it).
256
280
  */
257
- trigger: z.enum(["message", "background_task"]).optional(),
258
- /** A wake run's boundary: the seq of the finish that woke it (full-run replay seeds from it). */
259
281
  triggerSeq: seqNo.optional(),
260
282
  })),
261
283
  ev("model_call", z.object({
@@ -358,6 +380,13 @@ export const ConversationEventSchema = z.discriminatedUnion("type", [
358
380
  callId: z.string().optional(),
359
381
  })),
360
382
  ev("reminder", z.object({ step: count, text: z.string() })),
383
+ /**
384
+ * The step's resolved tool set differs from the one the conversation's previous model request
385
+ * offered (`toolSetChange`): tool names as the model sees them, sorted. Written before that
386
+ * step's request, never before a conversation's first one. **Model-visible**: rendered at its
387
+ * position as a system message (`toolsChangedText`); dropped once a summary covers it.
388
+ */
389
+ ev("tools_changed", z.object({ step: count, added: z.array(z.string()), removed: z.array(z.string()) })),
361
390
  /** 工具调用开始执行之前写入(续跑时「有开始无结果」的调用记为结果未知,不再执行)。 */
362
391
  ev("tool_call_started", z.object({ step: count, callId: z.string(), toolKey: z.string(), specHash: z.string() })),
363
392
  /**
@@ -553,6 +582,12 @@ export const ConversationEventSchema = z.discriminatedUnion("type", [
553
582
  id: z.string().optional(),
554
583
  version: z.number().int().positive().optional(),
555
584
  plugin: z.string().optional(),
585
+ /**
586
+ * Plugin scope phase 2: the platform template whose content a `plugin` child ran (a
587
+ * platform template, or an org copy linked to one, recorded under the copy's `id`). Absent
588
+ * = the org's own template (and in every older event). Eval metadata, not model-visible.
589
+ */
590
+ platformTemplateId: z.string().optional(),
556
591
  /**
557
592
  * Phase D: the child runs a forked skill a person invoked (display and eval metadata, not
558
593
  * model-visible).
@@ -589,10 +624,16 @@ export const ConversationEventSchema = z.discriminatedUnion("type", [
589
624
  */
590
625
  invokedSeq: seqNo.optional(),
591
626
  })),
592
- /** Parent log: a sub-agent waits for a person (approval, input or a connection). Not model-visible. */
627
+ /**
628
+ * Root log (agent map spec §7): a sub-agent `subagentId` of the tree, at any depth, waits for a
629
+ * person (approval, input or a connection). Not model-visible. `path`: the child conversation ids
630
+ * from the root's child down to `subagentId` (`[subagentId]` for a child of the root); logged under
631
+ * the root run that last dispatched the root's child on that path.
632
+ */
593
633
  ev("subagent_waiting", z.object({
594
634
  subagentId: z.string(),
595
635
  childRunId: z.string(),
636
+ path: z.array(z.string()).min(1).max(16),
596
637
  kind: z.enum(["approval", "input", "connect"]),
597
638
  approvalId: z.string().optional(),
598
639
  questionId: z.string().optional(),
@@ -606,21 +647,51 @@ export const ConversationEventSchema = z.discriminatedUnion("type", [
606
647
  subagentId: z.string(),
607
648
  childRunId: z.string(),
608
649
  callId: z.string(),
609
- /** `timed_out`: stopped by the parent's sub-agents wait timeout (`run_aborted.detail`). */
610
- status: z.enum([
611
- "completed",
612
- "max_steps",
613
- "max_duration",
614
- "budget",
615
- "aborted",
616
- "timed_out",
617
- "failed",
618
- ]),
650
+ status: SubagentFinishStatusSchema,
619
651
  errorCode: z.string().optional(),
620
652
  toolCalls: count,
621
653
  durationMs: count,
622
654
  usage: z.object(ModelUsageShape),
623
655
  })),
656
+ /**
657
+ * Parent log (agent map spec §4.5, §5.2): a sub-agent `subagentId` (its child conversation id)
658
+ * handed back a report (`SubagentHandback`), sent a note (`SendMessage to: "parent"`) or its run
659
+ * `childRunId` finished. **Model-visible**: absorbed like an interjection and rendered as a system
660
+ * message (`renderSubagentDelivery`). A finish after a handback carries `text: ""` and
661
+ * `handedBack: true` and renders as one status line, except that a run that handed back and
662
+ * `completed` writes no finished delivery at all (acceptance 2026-11-07; older logs have one and
663
+ * keep rendering it); a finish without a handback carries the child's
664
+ * final reply, a failed finish its error message (`errorCode` the code), an aborted one no text
665
+ * (`abortedBy` who stopped it), with `subagent_finished`'s vocabulary. `status` is present exactly
666
+ * on `kind: "finished"`. `triggerAccountId`: the child run's trigger account, the one a wake runs
667
+ * as (§7).
668
+ */
669
+ ev("subagent_delivery", z
670
+ .object({
671
+ subagentId: z.string(),
672
+ childRunId: z.string(),
673
+ description: z.string(),
674
+ kind: z.enum(["report", "note", "finished"]),
675
+ text: z.string().max(200_000),
676
+ /** `kind: "finished"` only (required there). */
677
+ status: SubagentFinishStatusSchema.optional(),
678
+ /** `kind: "finished"` only: a report was handed back before the run finished. */
679
+ handedBack: z.boolean().optional(),
680
+ /** `status: "failed"` only: the child run's error code. */
681
+ errorCode: z.string().optional(),
682
+ /** `status: "aborted"` only: a person stopped it, or the kernel on its parent's behalf. */
683
+ abortedBy: z.enum(["user", "parent"]).optional(),
684
+ triggerAccountId: z.string(),
685
+ })
686
+ .superRefine((p, ctx) => {
687
+ if ((p.kind === "finished") !== (p.status !== undefined)) {
688
+ ctx.addIssue({
689
+ code: "custom",
690
+ path: ["status"],
691
+ message: "status is required on a finished delivery and allowed only there",
692
+ });
693
+ }
694
+ })),
624
695
  /**
625
696
  * Phase D (spec §6.3): the report of the sub-agent that ran a person's fork invocation
626
697
  * (`invokedSeq`), written once (idem `skill_fork_result:<seq>`) before the parent's next model
@@ -654,9 +725,10 @@ export const ConversationEventSchema = z.discriminatedUnion("type", [
654
725
  /**
655
726
  * The finish never wakes a run, but the next run absorbs it like any other (background
656
727
  * Bash §3): `person`, a person stopped the task (the conversation's background section);
657
- * `deletion`, the conversation was being deleted.
728
+ * `deletion`, the conversation was being deleted; `subagent_end`, the sub-agent that owns it
729
+ * ended (a fork's run, or a stopped background sub-agent; agent map spec §5.3).
658
730
  */
659
- stoppedBy: z.enum(["person", "deletion"]).optional(),
731
+ stoppedBy: z.enum(["person", "deletion", "subagent_end"]).optional(),
660
732
  })),
661
733
  ev("compaction_summary", z.object({ coversUpToSeq: seqNo, text: z.string() })),
662
734
  ev("compaction_failed", z.object({ attempt: count, reason: z.string() })),
@@ -684,7 +756,9 @@ export const ConversationEventSchema = z.discriminatedUnion("type", [
684
756
  * loop takes it at its next step boundary, `consumed_seq` moves past it, and request building
685
757
  * places it where the model call that absorbed it was built.
686
758
  */
687
- export const isAbsorbable = (e) => e.type === "user_message" || e.type === "background_task_finished";
759
+ export const isAbsorbable = (e) => e.type === "user_message" ||
760
+ e.type === "background_task_finished" ||
761
+ e.type === "subagent_delivery";
688
762
  /**
689
763
  * What the person typed for a skill invocation (phase D): `/<plugin>:<name> <arguments>` (no
690
764
  * plugin: `/<name>`). Titles and eval case titles use it instead of the rendered skill in
@@ -17,7 +17,7 @@ export declare class ConversationQueue {
17
17
  readonly txHost: TransactionHost;
18
18
  constructor(db: KernelDb, eventLog: Pick<EventLog, "appendIn" | "notify" | "publishChanged" | "findByIdem">, conversations: Pick<ConversationsService, "get" | "writable" | "resolveExtra" | "bindIn" | "checkPick" | "prepareQueuedSkill">,
19
19
  /** Starts the conversation's next run (`ensureRun`). */
20
- runs: Pick<RunControl, "ensureRun">, txHost: TransactionHost);
20
+ runs: Pick<RunControl, "ensureRun" | "wakeHeldTree">, txHost: TransactionHost);
21
21
  list(orgId: string, conversationId: string, accountId: string): Promise<{
22
22
  items: QueueItem[];
23
23
  paused: boolean;
@@ -218,6 +218,8 @@ let ConversationQueue = class ConversationQueue {
218
218
  await this.conversations.writable(orgId, conversationId, accountId);
219
219
  await this.removeIn(conversationId, itemId);
220
220
  await this.eventLog.publishChanged(conversationId, "queue");
221
+ // removing the last item unpauses the queue: the wakes it held for the tree go out
222
+ await this.runs.wakeHeldTree(conversationId);
221
223
  }
222
224
  // its own transaction: the caller notifies and publishes after the commit
223
225
  async removeIn(conversationId, itemId) {
@@ -249,6 +251,7 @@ let ConversationQueue = class ConversationQueue {
249
251
  await this.eventLog.publishChanged(conversationId, "archived");
250
252
  await this.eventLog.publishChanged(conversationId, "queue");
251
253
  await this.runs.ensureRun(conversationId);
254
+ await this.runs.wakeHeldTree(conversationId);
252
255
  return event;
253
256
  }
254
257
  // its own transaction: the caller notifies and publishes after the commit
@@ -293,6 +296,8 @@ let ConversationQueue = class ConversationQueue {
293
296
  .execute();
294
297
  await this.eventLog.publishChanged(conversationId, "queue");
295
298
  await this.runs.ensureRun(conversationId);
299
+ // a paused root holds the wakes of its whole tree (agent map spec §5.3)
300
+ await this.runs.wakeHeldTree(conversationId);
296
301
  }
297
302
  /** A queued item or a sent message for this client id (outside any transaction). */
298
303
  async prior(conversationId, clientMessageId) {
@@ -29,8 +29,10 @@ export declare const titleJobId: (conversationId: string, attempt: number) => st
29
29
  export declare const TITLE_MAX_ATTEMPTS = 3;
30
30
  /** Output cap of the title call. */
31
31
  export declare const TITLE_MAX_OUTPUT_TOKENS = 32;
32
- /** The longest generated title (characters); a rename has the same limit. */
32
+ /** The longest title a person can give by renaming (characters). */
33
33
  export declare const TITLE_MAX_CHARS = 120;
34
+ /** The longest generated title by display width (CJK and emoji count 2: ~24 CJK / 48 Latin). */
35
+ export declare const TITLE_MAX_WIDTH = 48;
34
36
  /** Each side of the excerpt is cut to this many characters. */
35
37
  export declare const TITLE_EXCERPT_CHARS = 1000;
36
38
  /**
@@ -48,8 +50,8 @@ export declare const TITLE_PROMPT: string;
48
50
  export declare function titleExcerpt(firstUser: string, firstReply: string): string;
49
51
  /**
50
52
  * The title from a model reply: the first non-empty line, without control or format characters,
51
- * wrapping quotes or trailing punctuation, at most {@link TITLE_MAX_CHARS} characters; null when
52
- * nothing is left.
53
+ * wrapping quotes or trailing punctuation, at most {@link TITLE_MAX_WIDTH} display width (cut on a
54
+ * character boundary, no ellipsis); null when nothing is left.
53
55
  */
54
56
  export declare function cleanTitle(reply: string): string | null;
55
57
  export interface TitleDeps {
@@ -47,8 +47,10 @@ export const titleJobId = (conversationId, attempt) => `title-${conversationId}-
47
47
  export const TITLE_MAX_ATTEMPTS = 3;
48
48
  /** Output cap of the title call. */
49
49
  export const TITLE_MAX_OUTPUT_TOKENS = 32;
50
- /** The longest generated title (characters); a rename has the same limit. */
50
+ /** The longest title a person can give by renaming (characters). */
51
51
  export const TITLE_MAX_CHARS = 120;
52
+ /** The longest generated title by display width (CJK and emoji count 2: ~24 CJK / 48 Latin). */
53
+ export const TITLE_MAX_WIDTH = 48;
52
54
  /** Each side of the excerpt is cut to this many characters. */
53
55
  export const TITLE_EXCERPT_CHARS = 1000;
54
56
  /**
@@ -63,8 +65,13 @@ const EXCERPT_SCAN_EVENTS = 2000;
63
65
  const PAGE = 500;
64
66
  const JOB = "title";
65
67
  /** The system prompt of the title call (model-facing, English). */
66
- export const TITLE_PROMPT = "Write a title of at most 8 words for this conversation, in the language the user writes in. " +
68
+ export const TITLE_PROMPT = "Write a short topic of what the user asked, not the reply, as a title for this conversation, " +
69
+ "in the language the user writes in. Use a noun phrase of at most 6 words or about 16 CJK " +
70
+ "characters: no sentence, no list. " +
67
71
  "Reply with the title only, no quotes or punctuation at the end.";
72
+ const WIDE_RE = /[\u1100-\u115F\u2E80-\u303E\u3041-\u33FF\u3400-\u4DBF\u4E00-\u9FFF\uA000-\uA4CF\uAC00-\uD7A3\uF900-\uFAFF\uFE30-\uFE6F\uFF00-\uFF60\uFFE0-\uFFE6]|\p{Extended_Pictographic}|[\u{20000}-\u{3FFFD}]/u;
73
+ /** Display width of a character: 2 for CJK, fullwidth forms and emoji, else 1. */
74
+ const widthOf = (ch) => (WIDE_RE.test(ch) ? 2 : 1);
68
75
  const cut = (s) => {
69
76
  const cps = Array.from(s);
70
77
  return cps.length <= TITLE_EXCERPT_CHARS ? s : `${cps.slice(0, TITLE_EXCERPT_CHARS).join("")}…`;
@@ -75,8 +82,8 @@ export function titleExcerpt(firstUser, firstReply) {
75
82
  }
76
83
  /**
77
84
  * The title from a model reply: the first non-empty line, without control or format characters,
78
- * wrapping quotes or trailing punctuation, at most {@link TITLE_MAX_CHARS} characters; null when
79
- * nothing is left.
85
+ * wrapping quotes or trailing punctuation, at most {@link TITLE_MAX_WIDTH} display width (cut on a
86
+ * character boundary, no ellipsis); null when nothing is left.
80
87
  */
81
88
  export function cleanTitle(reply) {
82
89
  const line = reply
@@ -91,10 +98,16 @@ export function cleanTitle(reply) {
91
98
  .replace(/^["'“”‘’「」《》`*]+|["'“”‘’「」《》`*]+$/gu, "")
92
99
  .replace(/[.。!!??,,;;::]+$/u, "")
93
100
  .trim();
94
- // counted in code points, so a cut never splits a surrogate pair
95
- const cps = Array.from(t);
96
- if (cps.length > TITLE_MAX_CHARS)
97
- t = cps.slice(0, TITLE_MAX_CHARS).join("").trimEnd();
101
+ // cut by display width over code points, so a cut never splits a surrogate pair
102
+ let width = 0;
103
+ let out = "";
104
+ for (const ch of t) {
105
+ width += widthOf(ch);
106
+ if (width > TITLE_MAX_WIDTH)
107
+ break;
108
+ out += ch;
109
+ }
110
+ t = out.trimEnd();
98
111
  return t === "" ? null : t;
99
112
  }
100
113
  const textOf = (content) => content.flatMap((b) => (b.type === "text" ? [b.text] : [])).join("");
@@ -0,0 +1,17 @@
1
+ import type { KernelSchemaDb } from "../db/kernel-schema.js";
2
+ /**
3
+ * A conversation and every sub-agent conversation below it (agent map spec §6: its children,
4
+ * grandchildren and so on, through `conversations.parent_conversation_id`), each with its level
5
+ * below `conversationId` (0 for the conversation itself), shallowest first. Deleted conversations
6
+ * are included (a deleted root's tree is still stopped); an unknown id yields nothing.
7
+ */
8
+ export declare function conversationTree(db: KernelSchemaDb, conversationId: string): Promise<{
9
+ id: string;
10
+ level: number;
11
+ }[]>;
12
+ /**
13
+ * The ancestors of a conversation (agent map spec §8: live progress reaches every level above a
14
+ * sub-agent), nearest first: its parent, the parent's parent and so on up to the root, through
15
+ * `conversations.parent_conversation_id`. Empty for a root or an unknown id.
16
+ */
17
+ export declare function conversationAncestors(db: KernelSchemaDb, conversationId: string): Promise<string[]>;
@@ -0,0 +1,42 @@
1
+ import { sql } from "kysely";
2
+ /**
3
+ * How many levels below a conversation the tree reads walk at most: far above
4
+ * `subagents.maxDepth`'s bound of 5, so a corrupt parent chain cannot loop forever.
5
+ */
6
+ const TREE_MAX_LEVELS = 16;
7
+ /**
8
+ * A conversation and every sub-agent conversation below it (agent map spec §6: its children,
9
+ * grandchildren and so on, through `conversations.parent_conversation_id`), each with its level
10
+ * below `conversationId` (0 for the conversation itself), shallowest first. Deleted conversations
11
+ * are included (a deleted root's tree is still stopped); an unknown id yields nothing.
12
+ */
13
+ export async function conversationTree(db, conversationId) {
14
+ const r = await sql `
15
+ WITH RECURSIVE tree(id, level) AS (
16
+ SELECT c.id, 0 FROM capybara.conversations c WHERE c.id = ${conversationId}
17
+ UNION ALL
18
+ SELECT c.id, t.level + 1
19
+ FROM capybara.conversations c JOIN tree t ON c.parent_conversation_id = t.id
20
+ WHERE c.kind = 'subagent' AND t.level < ${TREE_MAX_LEVELS}
21
+ )
22
+ SELECT id, level FROM tree ORDER BY level, id`.execute(db);
23
+ return r.rows;
24
+ }
25
+ /**
26
+ * The ancestors of a conversation (agent map spec §8: live progress reaches every level above a
27
+ * sub-agent), nearest first: its parent, the parent's parent and so on up to the root, through
28
+ * `conversations.parent_conversation_id`. Empty for a root or an unknown id.
29
+ */
30
+ export async function conversationAncestors(db, conversationId) {
31
+ const r = await sql `
32
+ WITH RECURSIVE up(id, parent, level) AS (
33
+ SELECT c.id, c.parent_conversation_id, 0 FROM capybara.conversations c
34
+ WHERE c.id = ${conversationId}
35
+ UNION ALL
36
+ SELECT c.id, c.parent_conversation_id, up.level + 1
37
+ FROM capybara.conversations c JOIN up ON c.id = up.parent
38
+ WHERE up.level < ${TREE_MAX_LEVELS}
39
+ )
40
+ SELECT id FROM up WHERE level > 0 ORDER BY level`.execute(db);
41
+ return r.rows.map((row) => row.id);
42
+ }
@@ -4,6 +4,8 @@ import { Kysely } from "kysely";
4
4
  import { type RegisteredHook } from "../extensions/hooks.js";
5
5
  import { RegistrationLedger } from "../extensions/ledger.js";
6
6
  import type { LockService } from "../infra/lock/lock.service.js";
7
+ import type { ModelEmbeddings } from "../models/embeddings.js";
8
+ import type { HookRunner } from "../runtime/hook-calls.js";
7
9
  import type { EmbedTokens } from "../ui/embed-token.js";
8
10
  import { type UiActionHandler, type UiRender } from "../ui/registry.js";
9
11
  import { type BusSubscriber } from "./bus.js";
@@ -22,6 +24,17 @@ export interface KernelDeps {
22
24
  keyring: Keyring;
23
25
  /** Verifies embed tokens (`ctx.ui` embed requests; the one `EmbedTokens` provider). */
24
26
  embedTokens: Pick<EmbedTokens, "verify">;
27
+ /**
28
+ * The `ctx.models` broker (the one `ModelEmbeddings` provider). Absent (a ctx built alone in a
29
+ * test): `ctx.models` calls reject.
30
+ */
31
+ models?: Pick<ModelEmbeddings, "embed" | "describe">;
32
+ /**
33
+ * The host's hook registry: `ctx.models.embed` fires `model.request` through it (spec B §5.4).
34
+ * A required key, so no builder leaves policy hooks out by omission (fail closed by
35
+ * construction); only a ctx built alone in a test passes `undefined` (no hooks fire).
36
+ */
37
+ hooks: HookRunner | undefined;
25
38
  runWorkers: boolean;
26
39
  /** 内核 logger(`debug` 可选:插件 Logger 没有它,测试可不给)。 */
27
40
  log: Logger & {
@@ -48,6 +61,11 @@ export interface ExtensionPointAccess {
48
61
  }[];
49
62
  /** Names of the extensions enabled in the organization (`extension_org_configs.enabled` plus required bootstrap plugins, `enabled.ts`); queried every time, not cached. */
50
63
  enabledPlugins(orgId: string): Promise<Set<string>>;
64
+ /**
65
+ * Whether the extension's effective config is valid in the organization (layering spec A §6):
66
+ * a provider that is not is excluded from point resolution for that org.
67
+ */
68
+ configOk(orgId: string, plugin: string): Promise<boolean>;
51
69
  }
52
70
  /**
53
71
  * Queries the names of the extensions enabled in the organization (org config rows plus the
@@ -97,7 +115,8 @@ export declare class LiveConfig {
97
115
  * `deploymentConfig` may be a {@link LiveConfig} (shared by the instance, replaceable in place);
98
116
  * otherwise a fixed value is wrapped.
99
117
  * - Granted automatically: `kv`, `lock`, `bus`, `queue`, `log`, `db`, `config`, `provide`;
100
- * - `secrets` only with `permissions.secrets`, `storage` only with `permissions.storage`; `http.route`
118
+ * - `secrets` only with `permissions.secrets`, `storage` only with `permissions.storage`, `models`
119
+ * only with `permissions.models` (and only its `embedding` purposes, through `deps.models`); `http.route`
101
120
  * only the method + path declared in `permissions.http`; `tools.register` only names declared in
102
121
  * `permissions.tools`; `ui.view` / `ui.action` only ids declared in `permissions.ui.views` (during
103
122
  * setup only); `ui.invalidate` sends a refresh over the kernel bus (namespace `kernel`), across
@@ -146,6 +146,7 @@ function guardBuilder(builder, plugin) {
146
146
  const noProviders = (deps) => ({
147
147
  providers: () => [],
148
148
  enabledPlugins: (orgId) => queryEnabledPlugins(deps.db, orgId),
149
+ configOk: async () => true,
149
150
  });
150
151
  /**
151
152
  * 插件实例的部署配置(已校验):`ctx.config` 是读它的 getter。hot 字段改动时宿主替换 `value`(C10),
@@ -163,7 +164,8 @@ export class LiveConfig {
163
164
  * `deploymentConfig` may be a {@link LiveConfig} (shared by the instance, replaceable in place);
164
165
  * otherwise a fixed value is wrapped.
165
166
  * - Granted automatically: `kv`, `lock`, `bus`, `queue`, `log`, `db`, `config`, `provide`;
166
- * - `secrets` only with `permissions.secrets`, `storage` only with `permissions.storage`; `http.route`
167
+ * - `secrets` only with `permissions.secrets`, `storage` only with `permissions.storage`, `models`
168
+ * only with `permissions.models` (and only its `embedding` purposes, through `deps.models`); `http.route`
167
169
  * only the method + path declared in `permissions.http`; `tools.register` only names declared in
168
170
  * `permissions.tools`; `ui.view` / `ui.action` only ids declared in `permissions.ui.views` (during
169
171
  * setup only); `ui.invalidate` sends a refresh over the kernel bus (namespace `kernel`), across
@@ -217,6 +219,24 @@ export function createExtensionContext(deps, manifest, deploymentConfig, extensi
217
219
  plugins: async () => [name],
218
220
  }).forPlugin(name)
219
221
  : undefined;
222
+ // ctx.models: only with permissions.models; the broker accepts only the purposes declared there
223
+ // with kind embedding (spec B §5.4), aborted by this instance's signal
224
+ // a frozen copy: the approved manifest, not an object the extension could change later
225
+ const declaredModels = Object.freeze(structuredClone(perms.models ?? []).map((m) => Object.freeze(m)));
226
+ const modelsApi = declaredModels.length > 0
227
+ ? {
228
+ embed: async (req) => {
229
+ if (!deps.models)
230
+ throw new Error(`plugin ${name}: ctx.models is not available`);
231
+ return deps.models.embed(name, declaredModels, req, lifecycle.signal, deps.hooks);
232
+ },
233
+ describe: async (req) => {
234
+ if (!deps.models)
235
+ throw new Error(`plugin ${name}: ctx.models is not available`);
236
+ return deps.models.describe(name, declaredModels, req);
237
+ },
238
+ }
239
+ : undefined;
220
240
  const declaredRoutes = new Set((perms.http ?? []).map((r) => `${r.method} ${r.path}`));
221
241
  const declaredTools = new Set(perms.tools ?? []);
222
242
  const declaredHooks = new Set(perms.hooks ?? []);
@@ -260,12 +280,21 @@ export function createExtensionContext(deps, manifest, deploymentConfig, extensi
260
280
  throw new ExtensionPointUnavailableError(`extension point ${ref} has no provider`);
261
281
  return { info, chosen };
262
282
  };
263
- /** 组织视角过滤提供方:orgScoped 能力只留该组织已启用的(每次查询,不缓存)。 */
283
+ /**
284
+ * The org's view of the providers: an orgScoped point keeps only those the org enabled (queried
285
+ * every time, not cached), and every point drops those whose effective config is not valid in
286
+ * the org (layering spec A §6: a call on behalf of an org never reaches such a provider).
287
+ */
264
288
  const forOrg = async (orgScoped, orgId, entries) => {
265
- if (!orgScoped || entries.length === 0)
289
+ if (entries.length === 0)
266
290
  return entries;
267
- const enabled = await extensionPointAccess.enabledPlugins(orgId);
268
- return entries.filter((e) => enabled.has(e.plugin));
291
+ let out = entries;
292
+ if (orgScoped) {
293
+ const enabled = await extensionPointAccess.enabledPlugins(orgId);
294
+ out = out.filter((e) => enabled.has(e.plugin));
295
+ }
296
+ const ok = await Promise.all(out.map((e) => extensionPointAccess.configOk(orgId, e.plugin)));
297
+ return out.filter((_, i) => ok[i]);
269
298
  };
270
299
  const listAll = (ref) => {
271
300
  const info = checkExtensionPoint(ref);
@@ -280,7 +309,7 @@ export function createExtensionContext(deps, manifest, deploymentConfig, extensi
280
309
  return (async () => {
281
310
  const { info, chosen } = pick(ref, provider);
282
311
  if ((await forOrg(info.orgScoped, orgId, [chosen])).length === 0) {
283
- throw new ExtensionPointUnavailableError(`extension point ${ref} provider ${chosen.plugin} is not enabled in organization ${orgId}`);
312
+ throw new ExtensionPointUnavailableError(`extension point ${ref} provider ${chosen.plugin} is not available in organization ${orgId} (not enabled there, or its configuration is not valid there)`);
284
313
  }
285
314
  return chosen.impl;
286
315
  })();
@@ -551,7 +580,8 @@ export function createExtensionContext(deps, manifest, deploymentConfig, extensi
551
580
  return closing;
552
581
  },
553
582
  };
554
- // 声明了 secrets / storage 时是普通属性;未声明时是不可枚举的抛错 getter——展开 / 打印 ctx 不会触发越权与审计
583
+ // secrets / storage / models: a plain property when declared; otherwise a non-enumerable getter
584
+ // that throws, so spreading or printing ctx triggers no denial and no audit
555
585
  const gated = (key, api) => {
556
586
  if (api) {
557
587
  Object.assign(ctx, { [key]: api });
@@ -565,6 +595,7 @@ export function createExtensionContext(deps, manifest, deploymentConfig, extensi
565
595
  };
566
596
  gated("secrets", secretsApi);
567
597
  gated("storage", storageApi);
598
+ gated("models", modelsApi);
568
599
  return ctx;
569
600
  }
570
601
  /**