@capybara-hq/kernel 0.1.0-rc.5 → 0.1.0-rc.7

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 (362) hide show
  1. package/bootstrap.json +27 -3
  2. package/dist/admin/admin.controller.d.ts +21 -74
  3. package/dist/admin/admin.controller.js +50 -50
  4. package/dist/admin/admin.schemas.d.ts +57 -0
  5. package/dist/admin/admin.schemas.js +50 -0
  6. package/dist/admin/extensions.controller.d.ts +10 -0
  7. package/dist/admin/extensions.controller.js +18 -0
  8. package/dist/admin/extensions.schemas.d.ts +7 -0
  9. package/dist/admin/extensions.schemas.js +10 -0
  10. package/dist/admin/limit-defaults.d.ts +20 -0
  11. package/dist/admin/limit-defaults.js +10 -0
  12. package/dist/agents/agent-profile.service.d.ts +7 -5
  13. package/dist/agents/agent-profile.service.js +14 -9
  14. package/dist/agents/agents.controller.d.ts +7 -287
  15. package/dist/agents/agents.controller.js +7 -67
  16. package/dist/agents/agents.schemas.d.ts +389 -0
  17. package/dist/agents/agents.schemas.js +126 -0
  18. package/dist/agents/agents.service.d.ts +16 -6
  19. package/dist/agents/agents.service.js +75 -19
  20. package/dist/agents/definition.d.ts +47 -19
  21. package/dist/agents/definition.js +119 -38
  22. package/dist/agents/from-template.d.ts +2 -2
  23. package/dist/agents/from-template.js +76 -45
  24. package/dist/agents/from-template.service.d.ts +12 -0
  25. package/dist/agents/from-template.service.js +23 -6
  26. package/dist/agents/models.controller.d.ts +33 -5
  27. package/dist/agents/models.controller.js +50 -6
  28. package/dist/agents/org-templates.d.ts +13 -3
  29. package/dist/agents/org-templates.js +69 -28
  30. package/dist/agents/pending-connector-requests.d.ts +2 -0
  31. package/dist/agents/pending-connector-requests.js +1 -1
  32. package/dist/agents/pending-connectors.controller.d.ts +1 -1
  33. package/dist/agents/pending-connectors.controller.js +2 -2
  34. package/dist/agents/pending-connectors.service.d.ts +2 -2
  35. package/dist/agents/pending-connectors.service.js +19 -19
  36. package/dist/agents/profile.d.ts +18 -0
  37. package/dist/agents/profile.js +5 -1
  38. package/dist/agents/readiness.controller.d.ts +5 -5
  39. package/dist/agents/readiness.controller.js +6 -6
  40. package/dist/agents/templates.controller.d.ts +8 -17
  41. package/dist/agents/templates.controller.js +13 -31
  42. package/dist/agents/templates.schemas.d.ts +20 -0
  43. package/dist/agents/templates.schemas.js +45 -0
  44. package/dist/background/background.controller.js +3 -2
  45. package/dist/background/background.schemas.d.ts +10 -0
  46. package/dist/background/background.schemas.js +16 -0
  47. package/dist/background/tasks.service.d.ts +1 -1
  48. package/dist/background/tasks.service.js +7 -2
  49. package/dist/catalog/admin-catalog.controller.d.ts +4 -57
  50. package/dist/catalog/admin-catalog.controller.js +8 -45
  51. package/dist/catalog/admin-catalog.schemas.d.ts +72 -0
  52. package/dist/catalog/admin-catalog.schemas.js +92 -0
  53. package/dist/catalog/catalog-content.d.ts +12 -2
  54. package/dist/catalog/catalog-scope.service.js +8 -2
  55. package/dist/catalog/catalog.service.d.ts +2 -0
  56. package/dist/catalog/catalog.service.js +3 -0
  57. package/dist/catalog/component-scope.controller.d.ts +3 -65
  58. package/dist/catalog/component-scope.controller.js +3 -56
  59. package/dist/catalog/component-scope.schemas.d.ts +114 -0
  60. package/dist/catalog/component-scope.schemas.js +97 -0
  61. package/dist/catalog/component-scope.service.d.ts +28 -4
  62. package/dist/catalog/component-scope.service.js +55 -3
  63. package/dist/catalog/component-state.d.ts +9 -2
  64. package/dist/catalog/component-state.js +22 -13
  65. package/dist/catalog/marketplaces.controller.d.ts +5 -35
  66. package/dist/catalog/marketplaces.controller.js +6 -34
  67. package/dist/catalog/marketplaces.schemas.d.ts +48 -0
  68. package/dist/catalog/marketplaces.schemas.js +53 -0
  69. package/dist/catalog/marketplaces.service.d.ts +15 -1
  70. package/dist/catalog/marketplaces.service.js +22 -1
  71. package/dist/catalog/org-catalog.controller.d.ts +6 -62
  72. package/dist/catalog/org-catalog.controller.js +12 -66
  73. package/dist/catalog/org-catalog.schemas.d.ts +79 -0
  74. package/dist/catalog/org-catalog.schemas.js +82 -0
  75. package/dist/catalog/org-catalog.service.d.ts +9 -2
  76. package/dist/catalog/org-catalog.service.js +38 -5
  77. package/dist/catalog/org-extension.controller.d.ts +1 -12
  78. package/dist/catalog/org-extension.controller.js +1 -10
  79. package/dist/catalog/org-extension.schemas.d.ts +15 -0
  80. package/dist/catalog/org-extension.schemas.js +22 -0
  81. package/dist/catalog/org-plugin-uploads.controller.d.ts +2 -19
  82. package/dist/catalog/org-plugin-uploads.controller.js +15 -28
  83. package/dist/catalog/org-plugin-uploads.schemas.d.ts +20 -0
  84. package/dist/catalog/org-plugin-uploads.schemas.js +32 -0
  85. package/dist/catalog/owned-items.d.ts +6 -2
  86. package/dist/catalog/owned-items.js +16 -4
  87. package/dist/catalog/platform-components.d.ts +2 -0
  88. package/dist/catalog/platform-components.js +2 -0
  89. package/dist/catalog/plugin-import.js +1 -0
  90. package/dist/catalog/plugin-install.js +1 -1
  91. package/dist/catalog/requests.service.d.ts +2 -1
  92. package/dist/catalog/requests.service.js +6 -2
  93. package/dist/channels/channels.schemas.d.ts +33 -0
  94. package/dist/channels/channels.schemas.js +34 -0
  95. package/dist/channels/connections.controller.d.ts +2 -29
  96. package/dist/channels/connections.controller.js +1 -23
  97. package/dist/channels/connections.service.d.ts +8 -2
  98. package/dist/channels/connections.service.js +23 -5
  99. package/dist/channels/inbound.js +4 -0
  100. package/dist/config/schema.d.ts +4 -0
  101. package/dist/config/schema.js +24 -0
  102. package/dist/conversations/conversations.controller.d.ts +16 -37
  103. package/dist/conversations/conversations.controller.js +16 -56
  104. package/dist/conversations/conversations.schemas.d.ts +52 -0
  105. package/dist/conversations/conversations.schemas.js +79 -0
  106. package/dist/conversations/conversations.service.d.ts +13 -4
  107. package/dist/conversations/conversations.service.js +32 -26
  108. package/dist/conversations/events.d.ts +80 -6
  109. package/dist/conversations/events.js +60 -5
  110. package/dist/conversations/message-context.d.ts +28 -0
  111. package/dist/conversations/message-context.js +56 -0
  112. package/dist/conversations/queue.d.ts +2 -1
  113. package/dist/conversations/queue.js +11 -2
  114. package/dist/ctx/create-ctx.d.ts +15 -1
  115. package/dist/ctx/create-ctx.js +23 -2
  116. package/dist/db/kernel-schema.d.ts +44 -0
  117. package/dist/environments/environments.schemas.d.ts +3 -0
  118. package/dist/environments/environments.schemas.js +14 -0
  119. package/dist/environments/environments.service.d.ts +16 -4
  120. package/dist/environments/environments.service.js +58 -13
  121. package/dist/errors.d.ts +6 -0
  122. package/dist/errors.js +6 -0
  123. package/dist/evals/evals.schemas.d.ts +110 -0
  124. package/dist/evals/evals.schemas.js +107 -0
  125. package/dist/evals/reconstruct.js +18 -11
  126. package/dist/evals/recorded-tools.d.ts +2 -1
  127. package/dist/evals/recorded-tools.js +11 -3
  128. package/dist/evals/run-replay.d.ts +8 -1
  129. package/dist/evals/run-replay.js +17 -2
  130. package/dist/evals/runs.controller.d.ts +2 -57
  131. package/dist/evals/runs.controller.js +1 -42
  132. package/dist/evals/runs.service.d.ts +8 -7
  133. package/dist/evals/runs.service.js +45 -30
  134. package/dist/evals/sets.controller.d.ts +2 -28
  135. package/dist/evals/sets.controller.js +1 -31
  136. package/dist/evals/sets.service.d.ts +7 -7
  137. package/dist/evals/sets.service.js +23 -17
  138. package/dist/evals/snapshot.d.ts +3 -2
  139. package/dist/evals/snapshot.js +17 -4
  140. package/dist/evals/step-replay.d.ts +2 -1
  141. package/dist/evals/step-replay.js +3 -2
  142. package/dist/extensions/admin-ops.d.ts +5 -3
  143. package/dist/extensions/admin-ops.js +17 -12
  144. package/dist/extensions/config-hash.d.ts +10 -0
  145. package/dist/extensions/config-hash.js +38 -0
  146. package/dist/extensions/deployment-config.d.ts +16 -1
  147. package/dist/extensions/deployment-config.js +83 -0
  148. package/dist/extensions/extensions.module.js +9 -12
  149. package/dist/extensions/host.d.ts +39 -12
  150. package/dist/extensions/host.js +129 -51
  151. package/dist/extensions/installs.d.ts +5 -0
  152. package/dist/extensions/installs.js +12 -0
  153. package/dist/extensions/org-config.d.ts +17 -2
  154. package/dist/extensions/org-config.js +23 -4
  155. package/dist/extensions/point-defaults.controller.d.ts +2 -8
  156. package/dist/extensions/point-defaults.controller.js +1 -3
  157. package/dist/extensions/point-defaults.d.ts +3 -1
  158. package/dist/extensions/point-defaults.js +4 -2
  159. package/dist/extensions/point-defaults.schemas.d.ts +9 -0
  160. package/dist/extensions/point-defaults.schemas.js +14 -0
  161. package/dist/extensions/state.module.d.ts +9 -0
  162. package/dist/extensions/state.module.js +38 -0
  163. package/dist/extensions/unavailable.d.ts +49 -0
  164. package/dist/extensions/unavailable.js +113 -0
  165. package/dist/files/previewers.controller.js +2 -3
  166. package/dist/files/previewers.d.ts +1 -1
  167. package/dist/files/previewers.js +4 -4
  168. package/dist/files/previewers.schemas.d.ts +10 -0
  169. package/dist/files/previewers.schemas.js +9 -0
  170. package/dist/http/api.module.js +4 -0
  171. package/dist/http/plugin-dispatch.d.ts +4 -1
  172. package/dist/http/plugin-dispatch.js +14 -2
  173. package/dist/identity/accounts.d.ts +43 -4
  174. package/dist/identity/accounts.js +74 -6
  175. package/dist/identity/auth.guard.js +10 -1
  176. package/dist/identity/cookies.d.ts +6 -0
  177. package/dist/identity/cookies.js +14 -0
  178. package/dist/identity/identity.module.js +3 -0
  179. package/dist/identity/initial-passwords.controller.d.ts +22 -0
  180. package/dist/identity/initial-passwords.controller.js +49 -0
  181. package/dist/identity/initial-passwords.d.ts +61 -0
  182. package/dist/identity/initial-passwords.job.d.ts +16 -0
  183. package/dist/identity/initial-passwords.job.js +46 -0
  184. package/dist/identity/initial-passwords.js +159 -0
  185. package/dist/identity/me.controller.d.ts +14 -0
  186. package/dist/identity/me.controller.js +39 -1
  187. package/dist/identity/principal.d.ts +8 -0
  188. package/dist/identity/principal.js +8 -0
  189. package/dist/identity/settings.d.ts +3 -1
  190. package/dist/identity/settings.js +6 -4
  191. package/dist/inbox/inbox.schemas.d.ts +8 -0
  192. package/dist/inbox/inbox.schemas.js +11 -0
  193. package/dist/inbox/platform-inbox.controller.d.ts +1 -1
  194. package/dist/inbox/platform-inbox.controller.js +2 -2
  195. package/dist/index.d.ts +4 -0
  196. package/dist/index.js +6 -0
  197. package/dist/infra/config/kernel-config.service.js +3 -0
  198. package/dist/infra/events/kernel-events.d.ts +8 -0
  199. package/dist/lifecycle/kernel-lifecycle.js +4 -0
  200. package/dist/models/embeddings.d.ts +82 -0
  201. package/dist/models/embeddings.js +326 -0
  202. package/dist/models/enablement.controller.d.ts +40 -0
  203. package/dist/models/enablement.controller.js +74 -0
  204. package/dist/models/enablement.d.ts +101 -0
  205. package/dist/models/enablement.js +264 -0
  206. package/dist/models/models.module.d.ts +5 -1
  207. package/dist/models/models.module.js +16 -4
  208. package/dist/models/org-models.schemas.d.ts +8 -0
  209. package/dist/models/org-models.schemas.js +22 -0
  210. package/dist/models/prices.d.ts +3 -1
  211. package/dist/models/prices.js +7 -5
  212. package/dist/models/purposes.d.ts +30 -6
  213. package/dist/models/purposes.js +68 -17
  214. package/dist/orgs/orgs.controller.d.ts +2 -5
  215. package/dist/orgs/orgs.controller.js +3 -6
  216. package/dist/orgs/orgs.schemas.d.ts +8 -0
  217. package/dist/orgs/orgs.schemas.js +16 -0
  218. package/dist/orgs/orgs.service.d.ts +3 -1
  219. package/dist/orgs/orgs.service.js +6 -4
  220. package/dist/orgs/settings.service.d.ts +9 -1
  221. package/dist/orgs/settings.service.js +20 -5
  222. package/dist/overrides.d.ts +4 -0
  223. package/dist/overrides.js +2 -0
  224. package/dist/platform/errors.d.ts +21 -4
  225. package/dist/platform/errors.js +45 -6
  226. package/dist/platform/exclusions.d.ts +2 -3
  227. package/dist/platform/exclusions.js +68 -831
  228. package/dist/platform/method.js +1 -1
  229. package/dist/platform/operation.d.ts +82 -5
  230. package/dist/platform/operation.js +62 -7
  231. package/dist/platform/ops/accounts.ops.d.ts +32 -0
  232. package/dist/platform/ops/accounts.ops.js +291 -0
  233. package/dist/platform/ops/admin.ops.d.ts +36 -0
  234. package/dist/platform/ops/admin.ops.js +389 -0
  235. package/dist/platform/ops/agent-skills.ops.d.ts +24 -0
  236. package/dist/platform/ops/agent-skills.ops.js +226 -0
  237. package/dist/platform/ops/agent-templates.ops.d.ts +4 -1
  238. package/dist/platform/ops/agent-templates.ops.js +194 -14
  239. package/dist/platform/ops/agents.ops.d.ts +19 -1
  240. package/dist/platform/ops/agents.ops.js +481 -58
  241. package/dist/platform/ops/approvals.ops.d.ts +30 -0
  242. package/dist/platform/ops/approvals.ops.js +116 -0
  243. package/dist/platform/ops/background.ops.d.ts +14 -0
  244. package/dist/platform/ops/background.ops.js +134 -0
  245. package/dist/platform/ops/catalog-admin.ops.d.ts +74 -0
  246. package/dist/platform/ops/catalog-admin.ops.js +587 -0
  247. package/dist/platform/ops/channels.ops.d.ts +16 -0
  248. package/dist/platform/ops/channels.ops.js +195 -0
  249. package/dist/platform/ops/components.ops.d.ts +46 -0
  250. package/dist/platform/ops/components.ops.js +853 -0
  251. package/dist/platform/ops/connectors.ops.d.ts +4 -2
  252. package/dist/platform/ops/connectors.ops.js +68 -6
  253. package/dist/platform/ops/conversations.ops.d.ts +30 -0
  254. package/dist/platform/ops/conversations.ops.js +470 -0
  255. package/dist/platform/ops/environments.ops.d.ts +26 -0
  256. package/dist/platform/ops/environments.ops.js +289 -0
  257. package/dist/platform/ops/errors.d.ts +10 -5
  258. package/dist/platform/ops/errors.js +19 -11
  259. package/dist/platform/ops/evals.ops.d.ts +28 -0
  260. package/dist/platform/ops/evals.ops.js +783 -0
  261. package/dist/platform/ops/extensions-admin.ops.d.ts +25 -0
  262. package/dist/platform/ops/extensions-admin.ops.js +344 -0
  263. package/dist/platform/ops/extensions.ops.d.ts +7 -1
  264. package/dist/platform/ops/extensions.ops.js +248 -17
  265. package/dist/platform/ops/inbox.ops.d.ts +25 -0
  266. package/dist/platform/ops/inbox.ops.js +378 -0
  267. package/dist/platform/ops/marketplaces.ops.d.ts +7 -1
  268. package/dist/platform/ops/marketplaces.ops.js +326 -17
  269. package/dist/platform/ops/models.ops.d.ts +25 -0
  270. package/dist/platform/ops/models.ops.js +232 -0
  271. package/dist/platform/ops/org-plugins.ops.d.ts +29 -0
  272. package/dist/platform/ops/org-plugins.ops.js +329 -0
  273. package/dist/platform/ops/org-settings.ops.d.ts +16 -0
  274. package/dist/platform/ops/org-settings.ops.js +102 -0
  275. package/dist/platform/ops/orgs.ops.d.ts +28 -0
  276. package/dist/platform/ops/orgs.ops.js +295 -0
  277. package/dist/platform/ops/other-orgs.d.ts +20 -0
  278. package/dist/platform/ops/other-orgs.js +72 -0
  279. package/dist/platform/ops/platform.ops.d.ts +4 -4
  280. package/dist/platform/ops/platform.ops.js +23 -24
  281. package/dist/platform/ops/plugins.ops.d.ts +10 -8
  282. package/dist/platform/ops/plugins.ops.js +176 -77
  283. package/dist/platform/ops/previewers.ops.d.ts +14 -0
  284. package/dist/platform/ops/previewers.ops.js +109 -0
  285. package/dist/platform/ops/requests.ops.js +57 -19
  286. package/dist/platform/ops/skills.ops.d.ts +5 -1
  287. package/dist/platform/ops/skills.ops.js +129 -11
  288. package/dist/platform/ops/unavailable.d.ts +23 -0
  289. package/dist/platform/ops/unavailable.js +111 -0
  290. package/dist/platform/parity.d.ts +33 -0
  291. package/dist/platform/parity.js +272 -0
  292. package/dist/platform/platform-ops.module.d.ts +32 -0
  293. package/dist/platform/platform-ops.module.js +78 -11
  294. package/dist/platform/route-schemas.d.ts +18 -0
  295. package/dist/platform/route-schemas.js +60 -0
  296. package/dist/roles/worker.module.js +2 -0
  297. package/dist/runtime/context/build.d.ts +2 -0
  298. package/dist/runtime/context/build.js +28 -2
  299. package/dist/runtime/context/compaction.js +10 -1
  300. package/dist/runtime/context/run-context.d.ts +65 -0
  301. package/dist/runtime/context/run-context.js +215 -0
  302. package/dist/runtime/hook-calls.d.ts +8 -1
  303. package/dist/runtime/hook-calls.js +40 -9
  304. package/dist/runtime/model-call.d.ts +8 -3
  305. package/dist/runtime/model-call.js +30 -6
  306. package/dist/runtime/providers.d.ts +146 -32
  307. package/dist/runtime/providers.js +328 -67
  308. package/dist/runtime/run-context.service.d.ts +65 -0
  309. package/dist/runtime/run-context.service.js +220 -0
  310. package/dist/runtime/run-worker.d.ts +6 -1
  311. package/dist/runtime/run-worker.js +35 -10
  312. package/dist/runtime/runtime.module.js +2 -0
  313. package/dist/runtime/subagents/definition.d.ts +15 -15
  314. package/dist/runtime/subagents/definition.js +49 -118
  315. package/dist/runtime/usage-report-jobs.d.ts +88 -0
  316. package/dist/runtime/usage-report-jobs.js +158 -0
  317. package/dist/runtime/usage-report.d.ts +33 -38
  318. package/dist/runtime/usage-report.js +152 -84
  319. package/dist/skills/changes.controller.js +2 -1
  320. package/dist/skills/changes.service.d.ts +1 -1
  321. package/dist/skills/changes.service.js +4 -4
  322. package/dist/skills/invocable.controller.d.ts +1 -1
  323. package/dist/skills/invocable.controller.js +2 -2
  324. package/dist/skills/invoke.d.ts +2 -2
  325. package/dist/skills/invoke.js +8 -1
  326. package/dist/skills/skills.controller.d.ts +4 -13
  327. package/dist/skills/skills.controller.js +8 -24
  328. package/dist/skills/skills.schemas.d.ts +48 -0
  329. package/dist/skills/skills.schemas.js +61 -0
  330. package/dist/skills/skills.service.d.ts +11 -1
  331. package/dist/skills/skills.service.js +37 -14
  332. package/dist/time-zone.d.ts +5 -0
  333. package/dist/time-zone.js +19 -0
  334. package/dist/tools/approvals.controller.js +2 -3
  335. package/dist/tools/approvals.schemas.d.ts +21 -0
  336. package/dist/tools/approvals.schemas.js +15 -0
  337. package/dist/tools/builtin-names.d.ts +10 -8
  338. package/dist/tools/builtin-names.js +16 -11
  339. package/dist/tools/builtins/builtin-tools.d.ts +3 -1
  340. package/dist/tools/builtins/builtin-tools.js +15 -3
  341. package/dist/tools/builtins/current-time.d.ts +26 -0
  342. package/dist/tools/builtins/current-time.js +99 -0
  343. package/dist/tools/builtins/platform.d.ts +19 -2
  344. package/dist/tools/builtins/platform.js +105 -16
  345. package/dist/tools/connectors.controller.d.ts +1 -2
  346. package/dist/tools/connectors.controller.js +1 -4
  347. package/dist/tools/connectors.schemas.d.ts +12 -0
  348. package/dist/tools/connectors.schemas.js +19 -0
  349. package/dist/tools/connectors.service.d.ts +5 -2
  350. package/dist/tools/connectors.service.js +7 -5
  351. package/dist/tools/org-tool-switches.d.ts +16 -2
  352. package/dist/tools/org-tool-switches.js +26 -9
  353. package/dist/tools/pipeline.js +9 -1
  354. package/dist/tools/registry.d.ts +48 -51
  355. package/dist/tools/registry.js +222 -233
  356. package/package.json +3 -3
  357. package/src/migrations/0089_model_kinds_usage.sql +38 -0
  358. package/src/migrations/0090_initial_passwords.sql +27 -0
  359. package/src/migrations/0091_account_time_zone.sql +4 -0
  360. package/src/migrations/0092_tools_default_on.sql +27 -0
  361. package/dist/platform/redact-orgs.d.ts +0 -7
  362. package/dist/platform/redact-orgs.js +0 -52
@@ -29,7 +29,9 @@ import { ProviderListError, ProviderRegistry } from "../runtime/providers.js";
29
29
  * - 用途 = 内核用途 {@link KERNEL_PURPOSES}(目前只有评委 `eval`),或已加载插件 `permissions.models` 声明的;
30
30
  * - 映射 = 部署默认(`org_id` 为 null,超级管理员设)+ 组织覆盖(组织管理员设,`org.models.manage`);
31
31
  * 生效的映射先取组织覆盖、再取部署默认,都没有 → `model.unconfigured`;
32
- * - 目标模型按部署范围解析(与运行时一致),参数按目标模型自己的声明严格校验;不做模型白名单;
32
+ * - a target's kind must equal the purpose's kind; an org's override must be enabled in the org on
33
+ * save (a deployment default: not disabled on the platform), and an effective target disabled in
34
+ * the org (by either layer) counts as unconfigured there (spec B §5.3);参数按目标模型自己的声明严格校验;
33
35
  * - 每次都查 PG,不在进程内缓存(多副本下改映射立即生效)。`ctx.models` 仍预留,插件暂不能调用。
34
36
  */
35
37
  /**
@@ -189,11 +191,17 @@ let ModelPurposesService = class ModelPurposesService {
189
191
  async list(orgId) {
190
192
  return this.views(this.declared(), orgId);
191
193
  }
192
- /** 校验目标:模型可解析(部署范围)、参数按它的声明严格通过。 */
193
- async check(target) {
194
+ /**
195
+ * 校验目标:模型可解析且启用(an org's override for the org, a deployment default in the
196
+ * platform view)、its kind is the purpose's `kind`、参数按它的声明严格通过。
197
+ */
198
+ async check(orgId, target, kind) {
194
199
  let info;
195
200
  try {
196
- ({ info } = await this.providers.resolve(target.model));
201
+ info =
202
+ orgId === null
203
+ ? await this.providers.platformInfo(target.model, { kind: "callable" })
204
+ : (await this.providers.resolve(orgId, target.model, { kind: "callable" })).info;
197
205
  }
198
206
  catch (e) {
199
207
  if (e instanceof ProviderListError)
@@ -203,20 +211,38 @@ let ModelPurposesService = class ModelPurposesService {
203
211
  }
204
212
  throw e;
205
213
  }
214
+ if (info.kind !== kind) {
215
+ throw invalid([
216
+ {
217
+ path: "target.model",
218
+ message: `this purpose needs ${kind === "embedding" ? "an" : "a"} ${kind} model, not ${info.kind}`,
219
+ },
220
+ ]);
221
+ }
206
222
  const issues = paramIssues("target.params", info.parameters, target.params);
207
223
  if (issues.length > 0)
208
224
  throw invalid(issues);
209
225
  }
210
- async set(orgId, purpose, target, actor, actorTokenId) {
226
+ async set(orgId, purpose, target, actor, actorTokenId, auditDetail) {
211
227
  const decl = this.find(purpose);
212
228
  if (target)
213
- await this.check(target);
214
- await this.write(orgId, purpose, target, actor, actorTokenId);
229
+ await this.check(orgId, target, decl.kind);
230
+ await this.write(orgId, purpose, target, actor, actorTokenId, auditDetail);
215
231
  const [view] = await this.views([decl], orgId ?? undefined);
216
232
  return view;
217
233
  }
234
+ /**
235
+ * The checks {@link set} runs before writing, nothing written: an unknown purpose, and a target
236
+ * model the scope cannot use, of another kind, or with invalid params (the Platform tool's
237
+ * precheck, so a known failure never reaches the confirmation card).
238
+ */
239
+ async validate(orgId, purpose, target) {
240
+ const decl = this.find(purpose);
241
+ if (target)
242
+ await this.check(orgId, target, decl.kind);
243
+ }
218
244
  /** The mapping write of {@link set}, under the super admin or org lock. */
219
- async write(orgId, purpose, target, actor, actorTokenId) {
245
+ async write(orgId, purpose, target, actor, actorTokenId, auditDetail) {
220
246
  if (orgId === null)
221
247
  await this.adminLock.lockAndAuthorize(actor);
222
248
  else
@@ -249,23 +275,48 @@ let ModelPurposesService = class ModelPurposesService {
249
275
  ...(orgId !== null && { orgId }),
250
276
  action: "model.purpose_mapped",
251
277
  target: purpose,
252
- detail: { scope: orgId === null ? "deployment" : "org", target },
278
+ detail: { scope: orgId === null ? "deployment" : "org", target, ...auditDetail },
253
279
  });
254
280
  }
255
281
  /** 设置(或 `null` 清除)部署默认;只有超级管理员(事务内复核)。 */
256
- setDefault(purpose, target, actor, actorTokenId) {
257
- return this.set(null, purpose, target, actor, actorTokenId);
282
+ setDefault(purpose, target, actor, actorTokenId,
283
+ /** Merged into the audit detail (a write made through the Platform tool). */
284
+ auditDetail) {
285
+ return this.set(null, purpose, target, actor, actorTokenId, auditDetail);
258
286
  }
259
287
  /** 设置(或 `null` 清除)组织覆盖;事务内锁组织并复核 `org.models.manage`。 */
260
- setOrg(orgId, purpose, target, actor, actorTokenId) {
261
- return this.set(orgId, purpose, target, actor, actorTokenId);
288
+ setOrg(orgId, purpose, target, actor, actorTokenId,
289
+ /** Merged into the audit detail (a write made through the Platform tool). */
290
+ auditDetail) {
291
+ return this.set(orgId, purpose, target, actor, actorTokenId, auditDetail);
262
292
  }
263
- /** 生效的映射:组织覆盖,否则部署默认;都没有 → `model.unconfigured`;用途未声明 → `model.purpose_unknown`。 */
293
+ /**
294
+ * 生效的映射:组织覆盖,否则部署默认;都没有 → `model.unconfigured`;用途未声明 → `model.purpose_unknown`。
295
+ * An effective target the org cannot use counts as unconfigured there (spec B §5.3): checked in
296
+ * the registry's org view, so a model the platform or the org disabled, a provider off or needing
297
+ * configuration in the org, a model gone from the org's list or of another kind than the purpose
298
+ * all give `model.unconfigured`. A provider whose list fails (`ProviderListError`) keeps the
299
+ * mapping: the call that follows resolves the model again and fails there, retryably, so paths
300
+ * that only read the mapping (sub-agent tiers, eval start, `ctx.models.describe`) do not fail on
301
+ * a transient list error.
302
+ */
264
303
  async resolve(orgId, purpose) {
265
- const [view] = await this.views([this.find(purpose)], orgId);
304
+ const decl = this.find(purpose);
305
+ const [view] = await this.views([decl], orgId);
266
306
  if (!view?.effective) {
267
307
  throw new ApiError("model.unconfigured", `No model is configured for the "${purpose}" purpose`);
268
308
  }
309
+ try {
310
+ await this.providers.resolve(orgId, view.effective.model, { kind: decl.kind });
311
+ }
312
+ catch (e) {
313
+ if (e instanceof ProviderListError)
314
+ return view.effective;
315
+ if (e instanceof ApiError && e.code === "agent.model_unavailable") {
316
+ throw new ApiError("model.unconfigured", `The model configured for the "${purpose}" purpose is not available in this organization`);
317
+ }
318
+ throw e;
319
+ }
269
320
  return view.effective;
270
321
  }
271
322
  /** The target a {@link chat} call on `purpose` uses: the mapping, else `fallback` when unmapped. */
@@ -286,7 +337,7 @@ let ModelPurposesService = class ModelPurposesService {
286
337
  */
287
338
  async chatLimits(orgId, purpose, opts = {}) {
288
339
  const target = await this.chatTarget(orgId, purpose, opts.fallback);
289
- const { info } = await this.providers.resolve(target.model);
340
+ const { info } = await this.providers.resolve(orgId, target.model);
290
341
  return { contextWindow: info.contextWindow, maxOutputTokens: info.maxOutputTokens };
291
342
  }
292
343
  /**
@@ -301,7 +352,7 @@ let ModelPurposesService = class ModelPurposesService {
301
352
  */
302
353
  async chat(orgId, purpose, req, signal, opts = {}) {
303
354
  const target = await this.chatTarget(orgId, purpose, opts.fallback);
304
- const { provider, info } = await this.providers.resolve(target.model);
355
+ const { provider, info } = await this.providers.resolve(orgId, target.model);
305
356
  const request = {
306
357
  ...req,
307
358
  model: info.id,
@@ -3,16 +3,13 @@ import { type ApiTokenRecord, ApiTokenService } from "../identity/api-tokens.js"
3
3
  import { type Principal } from "../identity/principal.js";
4
4
  import { type Member, MembersService } from "./members.service.js";
5
5
  import { type OrgContext } from "./org.guard.js";
6
+ import { OrgUpdateBody } from "./orgs.schemas.js";
6
7
  import { type Org, OrgsService } from "./orgs.service.js";
7
8
  import { type OrgRole } from "./roles.js";
8
9
  declare const CreateSchema: z.ZodObject<{
9
10
  name: z.ZodString;
10
11
  slug: z.ZodOptional<z.ZodString>;
11
12
  }, z.core.$strip>;
12
- declare const UpdateSchema: z.ZodObject<{
13
- name: z.ZodOptional<z.ZodString>;
14
- slug: z.ZodOptional<z.ZodString>;
15
- }, z.core.$strip>;
16
13
  declare const TransferSchema: z.ZodObject<{
17
14
  toAccountId: z.ZodString;
18
15
  }, z.core.$strip>;
@@ -52,7 +49,7 @@ export declare class OrgsController {
52
49
  org: Org;
53
50
  role: OrgRole;
54
51
  }>;
55
- update(principal: Principal, org: OrgContext, body: z.infer<typeof UpdateSchema>): Promise<{
52
+ update(principal: Principal, org: OrgContext, body: z.infer<typeof OrgUpdateBody>): Promise<{
56
53
  org: Org;
57
54
  }>;
58
55
  remove(principal: Principal, org: OrgContext): Promise<void>;
@@ -16,6 +16,7 @@ import { createZodDto } from "../infra/validation/create-zod-dto.js";
16
16
  import { ZBody } from "../infra/validation/zod-params.js";
17
17
  import { MembersService } from "./members.service.js";
18
18
  import { CurrentOrg, OrgAction } from "./org.guard.js";
19
+ import { OrgUpdateBody } from "./orgs.schemas.js";
19
20
  import { OrgsService } from "./orgs.service.js";
20
21
  import { ORG_ROLES } from "./roles.js";
21
22
  const CreateSchema = z.object({
@@ -24,11 +25,7 @@ const CreateSchema = z.object({
24
25
  });
25
26
  class OrgCreateBody extends createZodDto(CreateSchema, "OrgCreateBody") {
26
27
  }
27
- const UpdateSchema = z.object({
28
- name: z.string().min(1).max(100).optional(),
29
- slug: z.string().min(1).max(40).optional(),
30
- });
31
- class OrgUpdateBody extends createZodDto(UpdateSchema, "OrgUpdateBody") {
28
+ class OrgUpdateBodyDto extends createZodDto(OrgUpdateBody, "OrgUpdateBody") {
32
29
  }
33
30
  const TransferSchema = z.object({ toAccountId: z.string().min(1) });
34
31
  class OrgTransferBody extends createZodDto(TransferSchema, "OrgTransferBody") {
@@ -127,7 +124,7 @@ __decorate([
127
124
  OrgAction("org.update"),
128
125
  __param(0, CurrentPrincipal()),
129
126
  __param(1, CurrentOrg()),
130
- __param(2, ZBody(OrgUpdateBody))
127
+ __param(2, ZBody(OrgUpdateBodyDto))
131
128
  ], OrgsController.prototype, "update", null);
132
129
  __decorate([
133
130
  Delete(":orgId"),
@@ -0,0 +1,8 @@
1
+ import { z } from "zod";
2
+ import type { RouteSchemas } from "../platform/route-schemas.js";
3
+ export declare const OrgUpdateBody: z.ZodObject<{
4
+ name: z.ZodOptional<z.ZodString>;
5
+ slug: z.ZodOptional<z.ZodString>;
6
+ }, z.core.$strip>;
7
+ export declare const ORG_ROUTES: readonly RouteSchemas[];
8
+ export declare const ORG_SETTINGS_ROUTES: readonly RouteSchemas[];
@@ -0,0 +1,16 @@
1
+ import { z } from "zod";
2
+ import { OrgSettingsPatchSchema } from "./settings.service.js";
3
+ export const OrgUpdateBody = z.object({
4
+ name: z.string().min(1).max(100).optional(),
5
+ slug: z.string().min(1).max(40).optional(),
6
+ });
7
+ export const ORG_ROUTES = [
8
+ { route: "GET /api/v1/orgs" },
9
+ { route: "GET /api/v1/orgs/:orgId" },
10
+ { route: "PATCH /api/v1/orgs/:orgId", body: OrgUpdateBody },
11
+ { route: "GET /api/v1/orgs/:orgId/members" },
12
+ ];
13
+ export const ORG_SETTINGS_ROUTES = [
14
+ { route: "GET /api/v1/orgs/:orgId/settings" },
15
+ { route: "PATCH /api/v1/orgs/:orgId/settings", body: OrgSettingsPatchSchema },
16
+ ];
@@ -69,7 +69,9 @@ export declare class OrgsService {
69
69
  update(orgId: string, patch: {
70
70
  name?: string | undefined;
71
71
  slug?: string | undefined;
72
- }, actor: Account, actorTokenId?: string): Promise<Org>;
72
+ }, actor: Account, actorTokenId?: string,
73
+ /** Merged into the audit detail (the Platform tool's `via: "agent"`). */
74
+ auditDetail?: Record<string, unknown>): Promise<Org>;
73
75
  private updateIn;
74
76
  /**
75
77
  * Soft delete (needs owner, decided live under the org lock): in the same transaction revokes
@@ -178,7 +178,9 @@ let OrgsService = class OrgsService {
178
178
  return row && toOrg(row);
179
179
  }
180
180
  /** Renames / re-slugs (needs admin, decided live under the org lock). */
181
- async update(orgId, patch, actor, actorTokenId) {
181
+ async update(orgId, patch, actor, actorTokenId,
182
+ /** Merged into the audit detail (the Platform tool's `via: "agent"`). */
183
+ auditDetail) {
182
184
  const values = {};
183
185
  if (patch.name !== undefined)
184
186
  values.name = checkName(patch.name);
@@ -186,9 +188,9 @@ let OrgsService = class OrgsService {
186
188
  checkSlug(patch.slug);
187
189
  values.slug = patch.slug;
188
190
  }
189
- return slugGuard(this.updateIn(orgId, values, actor, actorTokenId));
191
+ return slugGuard(this.updateIn(orgId, values, actor, actorTokenId, auditDetail));
190
192
  }
191
- async updateIn(orgId, values, actor, actorTokenId) {
193
+ async updateIn(orgId, values, actor, actorTokenId, auditDetail) {
192
194
  const { org: before } = await this.orgLock.lockAndAuthorize(orgId, actor.id, "org.update");
193
195
  if (Object.keys(values).length === 0) {
194
196
  const row = await this.db
@@ -210,7 +212,7 @@ let OrgsService = class OrgsService {
210
212
  orgId,
211
213
  action: "org.updated",
212
214
  target: orgId,
213
- detail: { before, after: values },
215
+ detail: { before, after: values, ...auditDetail },
214
216
  });
215
217
  return toOrg(row);
216
218
  }
@@ -17,6 +17,8 @@ import { OrgLock } from "./org-lock.js";
17
17
  * 见 {@link effectiveSandboxEgress}。存量值非法时按 `none` 读(宁可断网,不悄悄放宽到部署默认)。
18
18
  * - `platformTool`: the `Platform` builtin for the whole org (Platform tool spec §3): `on`,
19
19
  * `read-only` (writes listed as unavailable) or `off` (default `on`).
20
+ * - `timeZone`: the org's default time zone (IANA; absent = UTC) for senders without one of their
21
+ * own (run context spec §3.3); an invalid stored value reads as absent.
20
22
  */
21
23
  /** 组织沙箱出站白名单的主机数上限。 */
22
24
  export declare const ORG_SANDBOX_ALLOW_HOSTS_MAX = 200;
@@ -58,6 +60,7 @@ export declare const OrgSettingsSchema: z.ZodObject<{
58
60
  allowHosts: z.ZodOptional<z.ZodArray<z.ZodString>>;
59
61
  }, z.core.$strict>>>;
60
62
  wakeOnBackgroundTask: z.ZodCatch<z.ZodOptional<z.ZodBoolean>>;
63
+ timeZone: z.ZodCatch<z.ZodOptional<z.ZodString>>;
61
64
  }, z.core.$strip>;
62
65
  export type OrgSettings = z.infer<typeof OrgSettingsSchema>;
63
66
  /** PATCH 体:只改给出的字段;未知字段 → 400。 */
@@ -87,6 +90,7 @@ export declare const OrgSettingsPatchSchema: z.ZodObject<{
87
90
  }>;
88
91
  allowHosts: z.ZodOptional<z.ZodArray<z.ZodString>>;
89
92
  }, z.core.$strict>>>;
93
+ timeZone: z.ZodOptional<z.ZodNullable<z.ZodString>>;
90
94
  }, z.core.$strict>;
91
95
  export type OrgSettingsPatch = z.infer<typeof OrgSettingsPatchSchema>;
92
96
  /** 部署的沙箱出站(`sandbox.limits.egress` + `allowHosts`)。 */
@@ -138,6 +142,10 @@ export declare class OrgSettingsService {
138
142
  /** 组织实际生效的沙箱 cpu / 内存(只读;由超级管理员在部署设置里覆盖)。 */
139
143
  sandboxLimits(orgId: string): Promise<OrgSandboxLimits>;
140
144
  get(orgId: string): Promise<OrgSettings>;
141
- update(orgId: string, patch: OrgSettingsPatch, actorAccountId: string, actorTokenId?: string): Promise<OrgSettings>;
145
+ /** The refusals of {@link update} that need no read of the org (the Platform tool's precheck). */
146
+ check(patch: OrgSettingsPatch): void;
147
+ update(orgId: string, patch: OrgSettingsPatch, actorAccountId: string, actorTokenId?: string,
148
+ /** Merged into the audit detail (the Platform tool's `via: "agent"`). */
149
+ auditDetail?: Record<string, unknown>): Promise<OrgSettings>;
142
150
  private updateIn;
143
151
  }
@@ -17,6 +17,7 @@ import { KernelConfigService } from "../infra/config/kernel-config.service.js";
17
17
  import { KernelDb } from "../infra/database/kernel-db.js";
18
18
  import { TransactionHost } from "../infra/database/transaction-host.js";
19
19
  import { Transactional } from "../infra/database/transactional.decorator.js";
20
+ import { IanaTimeZone } from "../time-zone.js";
20
21
  import { OrgLock } from "./org-lock.js";
21
22
  /**
22
23
  * 组织设置(`capybara.orgs.settings` jsonb)。读取宽松:缺失或非法的字段按默认值,未知键保留不动
@@ -30,6 +31,8 @@ import { OrgLock } from "./org-lock.js";
30
31
  * 见 {@link effectiveSandboxEgress}。存量值非法时按 `none` 读(宁可断网,不悄悄放宽到部署默认)。
31
32
  * - `platformTool`: the `Platform` builtin for the whole org (Platform tool spec §3): `on`,
32
33
  * `read-only` (writes listed as unavailable) or `off` (default `on`).
34
+ * - `timeZone`: the org's default time zone (IANA; absent = UTC) for senders without one of their
35
+ * own (run context spec §3.3); an invalid stored value reads as absent.
33
36
  */
34
37
  /** 组织沙箱出站白名单的主机数上限。 */
35
38
  export const ORG_SANDBOX_ALLOW_HOSTS_MAX = 200;
@@ -64,6 +67,8 @@ export const OrgSettingsSchema = z.object({
64
67
  sandboxEgress: SandboxEgressSettingSchema.optional().catch({ mode: "none" }),
65
68
  /** Overrides `runtime.wakeOnBackgroundTask`; absent follows the deployment. */
66
69
  wakeOnBackgroundTask: z.boolean().optional().catch(undefined),
70
+ /** The org's default time zone (run context spec §3.3); absent = UTC. */
71
+ timeZone: IanaTimeZone.optional().catch(undefined),
67
72
  });
68
73
  /** PATCH 体:只改给出的字段;未知字段 → 400。 */
69
74
  export const OrgSettingsPatchSchema = z
@@ -76,6 +81,8 @@ export const OrgSettingsPatchSchema = z
76
81
  wakeOnBackgroundTask: z.boolean().nullable().optional(),
77
82
  /** null 清除(恢复跟随部署默认)。 */
78
83
  sandboxEgress: SandboxEgressSettingSchema.nullable().optional(),
84
+ /** The org's default time zone (IANA); null clears it (UTC). */
85
+ timeZone: IanaTimeZone.nullable().optional(),
79
86
  })
80
87
  .strict();
81
88
  /**
@@ -164,14 +171,20 @@ let OrgSettingsService = class OrgSettingsService {
164
171
  throw new ApiError("org.not_found", "Organization not found");
165
172
  return parseOrgSettings(row.settings);
166
173
  }
167
- async update(orgId, patch, actorAccountId, actorTokenId) {
174
+ /** The refusals of {@link update} that need no read of the org (the Platform tool's precheck). */
175
+ check(patch) {
168
176
  if (patch.sandboxEgress?.mode === "allowlist" &&
169
177
  this.deployment().sandboxEgress.mode === "none") {
170
178
  throw new ApiError("org.sandbox_egress_not_allowed", "This deployment disables sandbox network access (sandbox.limits.egress is none); an organization can only set sandboxEgress to none");
171
179
  }
172
- return this.updateIn(orgId, patch, actorAccountId, actorTokenId);
173
180
  }
174
- async updateIn(orgId, patch, actorAccountId, actorTokenId) {
181
+ async update(orgId, patch, actorAccountId, actorTokenId,
182
+ /** Merged into the audit detail (the Platform tool's `via: "agent"`). */
183
+ auditDetail) {
184
+ this.check(patch);
185
+ return this.updateIn(orgId, patch, actorAccountId, actorTokenId, auditDetail);
186
+ }
187
+ async updateIn(orgId, patch, actorAccountId, actorTokenId, auditDetail) {
175
188
  await this.orgLock.lockAndAuthorize(orgId, actorAccountId, "org.update");
176
189
  const row = await this.db
177
190
  .selectFrom("orgs")
@@ -189,10 +202,12 @@ let OrgSettingsService = class OrgSettingsService {
189
202
  delete after.sandboxEgress;
190
203
  if (after.wakeOnBackgroundTask === undefined)
191
204
  delete after.wakeOnBackgroundTask;
205
+ if (after.timeZone === undefined)
206
+ delete after.timeZone;
192
207
  if (sameSettings(before, after))
193
208
  return before;
194
209
  // 与存量合并:保留本版本不认识的键(清除的 sandboxEgress 不留在存量里)
195
- const { sandboxEgress: _old, wakeOnBackgroundTask: _oldWake, ...rest } = stored;
210
+ const { sandboxEgress: _old, wakeOnBackgroundTask: _oldWake, timeZone: _oldZone, ...rest } = stored;
196
211
  await this.db
197
212
  .updateTable("orgs")
198
213
  .set({ settings: JSON.stringify({ ...rest, ...after }) })
@@ -204,7 +219,7 @@ let OrgSettingsService = class OrgSettingsService {
204
219
  orgId,
205
220
  action: "org.settings_updated",
206
221
  target: orgId,
207
- detail: { before, after },
222
+ detail: { before, after, ...auditDetail },
208
223
  });
209
224
  return after;
210
225
  }
@@ -6,6 +6,7 @@ import { EVAL_REPLAY_HOOKS } from "./evals/worker.js";
6
6
  import { BOOTSTRAP_LOCK_TTL } from "./extensions/bootstrap.js";
7
7
  import { FILE_PREVIEW_TIMEOUT } from "./files/previewers.js";
8
8
  import { LIST_MODELS_TIMEOUT } from "./runtime/providers.js";
9
+ import { RUN_CONTEXT_CLOCK } from "./runtime/run-context.service.js";
9
10
  import { AGENT_LOOP_FACTORY, type AgentLoopFactory } from "./runtime/run-steps.js";
10
11
  import { RUN_HOOKS, type RunHooks } from "./runtime/run-worker.js";
11
12
  import { SUBAGENT_MESSAGES_HOOKS, type SubagentMessagesHooks } from "./runtime/subagents/messages.js";
@@ -25,6 +26,8 @@ import { EMBED_TOKEN_CLOCK } from "./ui/embed-token.js";
25
26
  * - `BOOTSTRAP_LOCK_TTL`, `FILE_PREVIEW_TIMEOUT`, `LIST_MODELS_TIMEOUT`, `USAGE_REPORT_RETRY`,
26
27
  * `SANDBOX_LEASE_TIMINGS`, `CHANNEL_WEBHOOK_TIMINGS`: shorter timings;
27
28
  * - `EMBED_TOKEN_CLOCK`: the clock embed tokens are issued and checked with;
29
+ * - `RUN_CONTEXT_CLOCK`: the clock run start reads the run context's date from, and the
30
+ * `CurrentTime` builtin the time;
28
31
  * - `APP_INTERCEPTOR`: one more global interceptor (a probe of the matched routes).
29
32
  */
30
33
  interface KernelSeams {
@@ -40,6 +43,7 @@ interface KernelSeams {
40
43
  [SANDBOX_LEASE_TIMINGS]: Partial<SandboxLeaseTimings>;
41
44
  [CHANNEL_WEBHOOK_TIMINGS]: Partial<ChannelWebhookTimings>;
42
45
  [EMBED_TOKEN_CLOCK]: () => number;
46
+ [RUN_CONTEXT_CLOCK]: () => number;
43
47
  [APP_INTERCEPTOR]: NestInterceptor;
44
48
  }
45
49
  /**
package/dist/overrides.js CHANGED
@@ -4,6 +4,7 @@ import { EVAL_REPLAY_HOOKS } from "./evals/worker.js";
4
4
  import { BOOTSTRAP_LOCK_TTL } from "./extensions/bootstrap.js";
5
5
  import { FILE_PREVIEW_TIMEOUT } from "./files/previewers.js";
6
6
  import { LIST_MODELS_TIMEOUT } from "./runtime/providers.js";
7
+ import { RUN_CONTEXT_CLOCK } from "./runtime/run-context.service.js";
7
8
  import { AGENT_LOOP_FACTORY } from "./runtime/run-steps.js";
8
9
  import { RUN_HOOKS } from "./runtime/run-worker.js";
9
10
  import { SUBAGENT_MESSAGES_HOOKS, } from "./runtime/subagents/messages.js";
@@ -24,6 +25,7 @@ const SEAM_TOKENS = [
24
25
  SANDBOX_LEASE_TIMINGS,
25
26
  CHANNEL_WEBHOOK_TIMINGS,
26
27
  EMBED_TOKEN_CLOCK,
28
+ RUN_CONTEXT_CLOCK,
27
29
  APP_INTERCEPTOR,
28
30
  ];
29
31
  const allSeamsListed = true;
@@ -1,11 +1,28 @@
1
1
  import { ToolError } from "@capybara-hq/plugin-sdk";
2
+ import type { ActorFacts } from "./actor.js";
3
+ import type { OperationError, OperationErrorNext } from "./operation.js";
2
4
  /** What the model is told to do after an operation refused its input (Platform tool spec §5.2). */
3
5
  export declare const OPERATION_ERROR_NEXT = "Check the input with describe and call again, or ask the person.";
6
+ /** The role an error's next step is written for (spec §14.5 item 7). */
7
+ export type ErrorRole = "superAdmin" | "orgAdmin" | "member";
8
+ /** The actor's role for next steps: the super admin first, then an org admin (admin or owner). */
9
+ export declare function errorRoleOf(facts: Pick<ActorFacts, "role" | "isSuperAdmin">): ErrorRole;
10
+ /** The next step an operation declares for `code`, for this role; undefined when it has none. */
11
+ export declare function nextStepFor(errors: readonly OperationError[] | undefined, code: string, role: ErrorRole): string | undefined;
12
+ /** One next step resolved for this role (the fallbacks of {@link nextStepFor}). */
13
+ export declare function resolveNext(next: OperationErrorNext | undefined, role: ErrorRole): string | undefined;
14
+ /** `errors[]` as `describe` shows them to this actor: each `next` resolved for the role. */
15
+ export declare function errorsFor(errors: readonly OperationError[], role: ErrorRole): {
16
+ code: string;
17
+ next: string;
18
+ }[];
4
19
  /**
5
20
  * An error an operation threw, as the `Platform` tool's error for the model (spec §5.2: errors say
6
21
  * what to do next). A `ToolError` passes as is; an `ApiError` (what the same HTTP route would
7
- * answer) keeps its code, message and details, then says what to do next. Anything else is a
8
- * kernel fault, not the model's: it is rethrown, so the pipeline logs it and reports the generic
9
- * failure.
22
+ * answer) keeps its code, message and details, then gives the next step: `nextOf(code)` (the
23
+ * operation's entry for the actor's role), else the generic one. Anything else is a kernel fault,
24
+ * not the model's: it is rethrown, so the pipeline logs it and reports the generic failure.
10
25
  */
11
- export declare function toToolError(e: unknown): ToolError;
26
+ export declare function toToolError(e: unknown, nextOf?: (code: string) => string | undefined): ToolError;
27
+ /** A text ending with a full stop (`.` added unless it ends with `.`, `!` or `?`). */
28
+ export declare const sentence: (s: string) => string;
@@ -4,23 +4,62 @@ import { ApiError } from "../errors.js";
4
4
  const DETAILS_MAX = 1000;
5
5
  /** What the model is told to do after an operation refused its input (Platform tool spec §5.2). */
6
6
  export const OPERATION_ERROR_NEXT = "Check the input with describe and call again, or ask the person.";
7
+ /** The actor's role for next steps: the super admin first, then an org admin (admin or owner). */
8
+ export function errorRoleOf(facts) {
9
+ if (facts.isSuperAdmin)
10
+ return "superAdmin";
11
+ return facts.role === "admin" || facts.role === "owner" ? "orgAdmin" : "member";
12
+ }
13
+ /**
14
+ * Which keyed texts a role may get, in order. The super admin's text (the admin console path) goes
15
+ * to the super admin only; an org admin falls back to the member's step and a member to the org
16
+ * admin's (both name steps inside the org).
17
+ */
18
+ const FALLBACK = {
19
+ superAdmin: ["superAdmin", "orgAdmin", "member"],
20
+ orgAdmin: ["orgAdmin", "member"],
21
+ member: ["member", "orgAdmin"],
22
+ };
23
+ /** The next step an operation declares for `code`, for this role; undefined when it has none. */
24
+ export function nextStepFor(errors, code, role) {
25
+ return resolveNext(errors?.find((e) => e.code === code)?.next, role);
26
+ }
27
+ /** One next step resolved for this role (the fallbacks of {@link nextStepFor}). */
28
+ export function resolveNext(next, role) {
29
+ if (next === undefined || typeof next === "string")
30
+ return next;
31
+ for (const r of FALLBACK[role]) {
32
+ const text = next[r];
33
+ if (text !== undefined)
34
+ return text;
35
+ }
36
+ return undefined;
37
+ }
38
+ /** `errors[]` as `describe` shows them to this actor: each `next` resolved for the role. */
39
+ export function errorsFor(errors, role) {
40
+ return errors.flatMap((e) => {
41
+ const next = nextStepFor(errors, e.code, role);
42
+ return next === undefined ? [] : [{ code: e.code, next }];
43
+ });
44
+ }
7
45
  /**
8
46
  * An error an operation threw, as the `Platform` tool's error for the model (spec §5.2: errors say
9
47
  * what to do next). A `ToolError` passes as is; an `ApiError` (what the same HTTP route would
10
- * answer) keeps its code, message and details, then says what to do next. Anything else is a
11
- * kernel fault, not the model's: it is rethrown, so the pipeline logs it and reports the generic
12
- * failure.
48
+ * answer) keeps its code, message and details, then gives the next step: `nextOf(code)` (the
49
+ * operation's entry for the actor's role), else the generic one. Anything else is a kernel fault,
50
+ * not the model's: it is rethrown, so the pipeline logs it and reports the generic failure.
13
51
  */
14
- export function toToolError(e) {
52
+ export function toToolError(e, nextOf) {
15
53
  if (e instanceof ToolError)
16
54
  return e;
17
55
  if (e instanceof ApiError) {
18
56
  const details = e.details !== undefined && e.details.length > 0
19
57
  ? ` Details: ${clip(JSON.stringify(e.details))}`
20
58
  : "";
21
- const message = e.message.trim().replace(/[.!]?$/, ".");
22
- return new ToolError(`${e.code}: ${message}${details} ${OPERATION_ERROR_NEXT}`);
59
+ return new ToolError(`${e.code}: ${sentence(e.message)}${details} ${nextOf?.(e.code) ?? OPERATION_ERROR_NEXT}`);
23
60
  }
24
61
  throw e;
25
62
  }
63
+ /** A text ending with a full stop (`.` added unless it ends with `.`, `!` or `?`). */
64
+ export const sentence = (s) => s.trim().replace(/[.!?]?$/, (m) => m || ".");
26
65
  const clip = (s) => (s.length > DETAILS_MAX ? `${s.slice(0, DETAILS_MAX)}…` : s);
@@ -1,12 +1,11 @@
1
- export type ExclusionCategory = "human-only" | "secret" | "transport" | "internal" | "later";
1
+ export type ExclusionCategory = "human-only" | "secret" | "transport" | "internal";
2
2
  /**
3
3
  * Kernel HTTP routes the `Platform` tool does not mirror, each with a reason (spec §9);
4
4
  * `check:platform-ops` fails a route that is neither mirrored by an operation nor listed here.
5
- * `later` needs an `issue` URL.
5
+ * Every exclusion is for good: there is no "later" (rule `platform-op-later`).
6
6
  */
7
7
  export declare const PLATFORM_EXCLUSIONS: readonly {
8
8
  route: string;
9
9
  category: ExclusionCategory;
10
10
  reason: string;
11
- issue?: string;
12
11
  }[];