@capybara-hq/kernel 0.1.0-rc.36 → 0.1.0-rc.38

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 (351) hide show
  1. package/bootstrap.json +5 -5
  2. package/dist/admin/admin.module.d.ts +3 -2
  3. package/dist/admin/admin.module.js +9 -5
  4. package/dist/admin/audit-log.service.d.ts +51 -0
  5. package/dist/admin/{platform-audit.service.js → audit-log.service.js} +20 -12
  6. package/dist/admin/audit.controller.d.ts +18 -6
  7. package/dist/admin/audit.controller.js +36 -6
  8. package/dist/admin/audit.schemas.d.ts +9 -1
  9. package/dist/admin/audit.schemas.js +22 -2
  10. package/dist/admin/org-network.controller.d.ts +30 -0
  11. package/dist/admin/org-network.controller.js +77 -0
  12. package/dist/admin/org-network.schemas.d.ts +16 -0
  13. package/dist/admin/org-network.schemas.js +27 -0
  14. package/dist/admin/org-network.service.d.ts +41 -0
  15. package/dist/admin/org-network.service.js +101 -0
  16. package/dist/admin/outbox-dead.controller.d.ts +4 -6
  17. package/dist/admin/outbox-dead.controller.js +9 -6
  18. package/dist/admin/outbox-dead.schemas.d.ts +16 -0
  19. package/dist/admin/outbox-dead.schemas.js +25 -1
  20. package/dist/admin/outbox-dead.service.d.ts +16 -7
  21. package/dist/admin/outbox-dead.service.js +34 -10
  22. package/dist/admin/overview.service.d.ts +3 -3
  23. package/dist/admin/overview.service.js +0 -1
  24. package/dist/agents/agent-lookup.js +2 -10
  25. package/dist/agents/agents.service.js +9 -20
  26. package/dist/agents/definition.d.ts +3 -51
  27. package/dist/agents/definition.js +4 -254
  28. package/dist/agents/org-templates.js +2 -6
  29. package/dist/agents/readiness.controller.d.ts +4 -12
  30. package/dist/agents/readiness.controller.js +4 -12
  31. package/dist/agents/readiness.service.d.ts +23 -11
  32. package/dist/agents/readiness.service.js +31 -14
  33. package/dist/agents/templates.d.ts +0 -6
  34. package/dist/agents/templates.js +8 -34
  35. package/dist/background/store.d.ts +2 -0
  36. package/dist/background/store.js +3 -1
  37. package/dist/background/wake-rules.js +2 -1
  38. package/dist/catalog/admin-catalog.controller.d.ts +1 -2
  39. package/dist/catalog/admin-catalog.controller.js +1 -2
  40. package/dist/catalog/appearance.service.js +1 -3
  41. package/dist/catalog/catalog-content.d.ts +1 -1
  42. package/dist/catalog/catalog-content.js +1 -4
  43. package/dist/catalog/catalog-items.js +3 -3
  44. package/dist/catalog/catalog-scope.service.d.ts +10 -28
  45. package/dist/catalog/catalog-scope.service.js +22 -73
  46. package/dist/catalog/cli.d.ts +0 -11
  47. package/dist/catalog/cli.js +0 -20
  48. package/dist/catalog/component-scope.service.js +0 -2
  49. package/dist/catalog/component-state.js +2 -2
  50. package/dist/catalog/install-status.d.ts +6 -0
  51. package/dist/catalog/install-status.js +6 -0
  52. package/dist/catalog/job-ids.d.ts +0 -4
  53. package/dist/catalog/job-ids.js +0 -4
  54. package/dist/catalog/marketplaces.service.d.ts +1 -1
  55. package/dist/catalog/org-catalog.service.d.ts +2 -0
  56. package/dist/catalog/org-catalog.service.js +8 -3
  57. package/dist/catalog/org-extension-switch.d.ts +7 -2
  58. package/dist/catalog/org-extension-switch.js +56 -9
  59. package/dist/catalog/org-plugin-uploads.d.ts +6 -15
  60. package/dist/catalog/org-plugin-uploads.js +9 -27
  61. package/dist/catalog/owned-items.js +1 -3
  62. package/dist/catalog/platform-import-update.js +1 -1
  63. package/dist/catalog/plugin-import.d.ts +15 -13
  64. package/dist/catalog/plugin-import.js +21 -30
  65. package/dist/catalog/plugin-install.d.ts +3 -43
  66. package/dist/catalog/plugin-install.js +8 -150
  67. package/dist/catalog/plugin-package.d.ts +5 -10
  68. package/dist/catalog/plugin-package.js +12 -33
  69. package/dist/catalog/plugin-upgrade.js +5 -4
  70. package/dist/catalog/scope-jobs.d.ts +34 -34
  71. package/dist/catalog/scope-jobs.js +50 -37
  72. package/dist/catalog/scope-orgs.d.ts +1 -1
  73. package/dist/catalog/scope-orgs.js +1 -2
  74. package/dist/catalog/scope-sync-workers.d.ts +4 -3
  75. package/dist/catalog/scope-sync-workers.js +18 -6
  76. package/dist/catalog/scope-sync.d.ts +56 -59
  77. package/dist/catalog/scope-sync.js +96 -166
  78. package/dist/catalog/unshare.d.ts +3 -4
  79. package/dist/catalog/unshare.js +5 -8
  80. package/dist/channels/job-ids.d.ts +2 -6
  81. package/dist/channels/job-ids.js +2 -6
  82. package/dist/channels/outbound.d.ts +1 -1
  83. package/dist/channels/outbound.js +1 -1
  84. package/dist/channels/supervisor.d.ts +2 -3
  85. package/dist/channels/supervisor.js +2 -3
  86. package/dist/client/client-access.service.js +1 -1
  87. package/dist/config/env.js +19 -1
  88. package/dist/config/load.d.ts +0 -6
  89. package/dist/config/load.js +8 -27
  90. package/dist/config/schema.d.ts +54 -47
  91. package/dist/config/schema.js +198 -42
  92. package/dist/conversations/attachments.service.d.ts +10 -3
  93. package/dist/conversations/attachments.service.js +49 -16
  94. package/dist/conversations/conversations.controller.d.ts +0 -39
  95. package/dist/conversations/conversations.controller.js +0 -39
  96. package/dist/conversations/event-log.js +4 -1
  97. package/dist/conversations/events.d.ts +71 -46
  98. package/dist/conversations/events.js +124 -112
  99. package/dist/conversations/media-types.d.ts +25 -0
  100. package/dist/conversations/media-types.js +38 -0
  101. package/dist/conversations/queue.d.ts +3 -1
  102. package/dist/conversations/queue.service.js +9 -2
  103. package/dist/conversations/titles.js +6 -0
  104. package/dist/ctx/create-ctx.d.ts +8 -1
  105. package/dist/ctx/create-ctx.js +13 -3
  106. package/dist/ctx/net.d.ts +50 -0
  107. package/dist/ctx/net.js +67 -0
  108. package/dist/ctx/secrets.d.ts +24 -7
  109. package/dist/ctx/secrets.js +97 -30
  110. package/dist/db/kernel-schema.d.ts +27 -6
  111. package/dist/devices/devices.service.js +2 -1
  112. package/dist/errors.d.ts +10 -2
  113. package/dist/errors.js +10 -2
  114. package/dist/evals/reconstruct.d.ts +4 -17
  115. package/dist/evals/reconstruct.js +13 -53
  116. package/dist/evals/recorded-tools.d.ts +0 -27
  117. package/dist/evals/recorded-tools.js +2 -92
  118. package/dist/evals/run-replay.d.ts +1 -6
  119. package/dist/evals/run-replay.js +10 -17
  120. package/dist/evals/sets.service.d.ts +17 -5
  121. package/dist/evals/sets.service.js +33 -12
  122. package/dist/evals/snapshot.d.ts +1 -2
  123. package/dist/evals/snapshot.js +4 -17
  124. package/dist/extensions/admin-ops.d.ts +6 -1
  125. package/dist/extensions/admin-ops.js +17 -4
  126. package/dist/extensions/admin-view.d.ts +7 -4
  127. package/dist/extensions/admin-view.js +27 -21
  128. package/dist/extensions/bootstrap.js +0 -1
  129. package/dist/extensions/cli.js +0 -1
  130. package/dist/extensions/extensions.module.js +3 -0
  131. package/dist/extensions/host.d.ts +9 -4
  132. package/dist/extensions/host.js +14 -8
  133. package/dist/extensions/installs.d.ts +1 -3
  134. package/dist/extensions/instance.d.ts +0 -2
  135. package/dist/extensions/instance.js +0 -3
  136. package/dist/extensions/org-config.d.ts +4 -4
  137. package/dist/extensions/org-config.js +13 -22
  138. package/dist/extensions/package.d.ts +6 -6
  139. package/dist/extensions/package.js +3 -7
  140. package/dist/extensions/permission-view.d.ts +2 -4
  141. package/dist/extensions/plugin-items.d.ts +21 -1
  142. package/dist/extensions/plugin-items.js +28 -0
  143. package/dist/extensions/sync.js +5 -10
  144. package/dist/extensions/unavailable.js +0 -1
  145. package/dist/http/api.module.js +4 -1
  146. package/dist/identity/audit.d.ts +0 -12
  147. package/dist/identity/audit.js +0 -27
  148. package/dist/identity/auth.controller.js +5 -9
  149. package/dist/identity/cookies.d.ts +4 -9
  150. package/dist/identity/cookies.js +8 -32
  151. package/dist/identity/initial-passwords.d.ts +1 -1
  152. package/dist/identity/initial-passwords.js +1 -2
  153. package/dist/identity/sessions.d.ts +0 -6
  154. package/dist/identity/sessions.js +0 -18
  155. package/dist/inbox/platform-inbox.service.d.ts +33 -1
  156. package/dist/inbox/platform-inbox.service.js +56 -6
  157. package/dist/index.d.ts +4 -2
  158. package/dist/index.js +4 -2
  159. package/dist/infra/cli/master-key-rewrap.d.ts +15 -0
  160. package/dist/infra/cli/master-key-rewrap.js +24 -0
  161. package/dist/infra/config/kernel-config.service.js +0 -17
  162. package/dist/infra/database/transaction-host.d.ts +32 -1
  163. package/dist/infra/database/transaction-host.js +30 -4
  164. package/dist/infra/database/xact-lock.d.ts +16 -0
  165. package/dist/infra/database/xact-lock.js +28 -1
  166. package/dist/infra/health/health.controller.js +8 -0
  167. package/dist/infra/health/process-fault.d.ts +16 -0
  168. package/dist/infra/health/process-fault.js +49 -0
  169. package/dist/infra/lifecycle/process-guards.d.ts +8 -2
  170. package/dist/infra/lifecycle/process-guards.js +12 -3
  171. package/dist/infra/lifecycle/shutdown-signals.d.ts +10 -1
  172. package/dist/infra/lifecycle/shutdown-signals.js +28 -13
  173. package/dist/infra/outbox/outbox.service.d.ts +12 -9
  174. package/dist/infra/outbox/outbox.service.js +22 -26
  175. package/dist/infra/outbox/registry.d.ts +15 -7
  176. package/dist/infra/outbox/registry.js +39 -23
  177. package/dist/lifecycle/kernel-lifecycle.js +1 -7
  178. package/dist/models/enablement.d.ts +5 -6
  179. package/dist/models/enablement.js +7 -14
  180. package/dist/net/public-address.d.ts +21 -1
  181. package/dist/net/public-address.js +56 -10
  182. package/dist/net/safe-fetch.d.ts +4 -1
  183. package/dist/net/safe-fetch.js +15 -4
  184. package/dist/orgs/directory-sync.js +2 -0
  185. package/dist/orgs/members.service.js +5 -0
  186. package/dist/orgs/network-allowances.service.d.ts +79 -0
  187. package/dist/orgs/network-allowances.service.js +371 -0
  188. package/dist/orgs/offboarding.d.ts +3 -1
  189. package/dist/orgs/offboarding.js +9 -2
  190. package/dist/orgs/org-lock.d.ts +28 -2
  191. package/dist/orgs/org-lock.js +59 -4
  192. package/dist/orgs/orgs.controller.d.ts +11 -2
  193. package/dist/orgs/orgs.controller.js +19 -3
  194. package/dist/orgs/orgs.module.d.ts +3 -2
  195. package/dist/orgs/orgs.module.js +6 -2
  196. package/dist/orgs/orgs.schemas.d.ts +12 -0
  197. package/dist/orgs/orgs.schemas.js +5 -0
  198. package/dist/orgs/orgs.service.js +6 -1
  199. package/dist/orgs/settings.controller.d.ts +3 -2
  200. package/dist/orgs/settings.service.d.ts +59 -14
  201. package/dist/orgs/settings.service.js +102 -20
  202. package/dist/overrides.d.ts +7 -7
  203. package/dist/overrides.js +4 -4
  204. package/dist/packages/tgz.d.ts +0 -2
  205. package/dist/packages/tgz.js +0 -2
  206. package/dist/platform/exclusions.js +0 -5
  207. package/dist/platform/operation.js +1 -1
  208. package/dist/platform/ops/admin.ops.d.ts +2 -2
  209. package/dist/platform/ops/admin.ops.js +9 -6
  210. package/dist/platform/ops/agents.ops.js +1 -1
  211. package/dist/platform/ops/connectors.ops.js +46 -1
  212. package/dist/platform/ops/evals.ops.js +1 -64
  213. package/dist/platform/ops/extensions-admin.ops.js +1 -1
  214. package/dist/platform/ops/inbox.ops.js +16 -3
  215. package/dist/platform/ops/org-plugins.ops.js +1 -1
  216. package/dist/platform/ops/orgs.ops.d.ts +11 -3
  217. package/dist/platform/ops/orgs.ops.js +139 -5
  218. package/dist/platform/ops/outbox.ops.js +5 -5
  219. package/dist/platform/route-schemas.js +3 -0
  220. package/dist/roles/worker-role.d.ts +2 -3
  221. package/dist/roles/worker-role.js +3 -13
  222. package/dist/runtime/checkpointer.d.ts +3 -0
  223. package/dist/runtime/checkpointer.js +7 -4
  224. package/dist/runtime/context/build.d.ts +56 -18
  225. package/dist/runtime/context/build.js +143 -50
  226. package/dist/runtime/context/compaction.d.ts +1 -3
  227. package/dist/runtime/context/compaction.js +42 -8
  228. package/dist/runtime/context/run-context.js +1 -2
  229. package/dist/runtime/context/skills.d.ts +27 -56
  230. package/dist/runtime/context/skills.js +42 -114
  231. package/dist/runtime/context/tool-changes.d.ts +3 -3
  232. package/dist/runtime/context/tool-changes.js +6 -16
  233. package/dist/runtime/hook-calls.d.ts +6 -6
  234. package/dist/runtime/hook-calls.js +7 -7
  235. package/dist/runtime/langgraph-loop.js +9 -3
  236. package/dist/runtime/maintenance.d.ts +3 -11
  237. package/dist/runtime/maintenance.js +5 -20
  238. package/dist/runtime/model-call.d.ts +5 -0
  239. package/dist/runtime/model-call.js +48 -36
  240. package/dist/runtime/providers.d.ts +33 -35
  241. package/dist/runtime/providers.js +64 -109
  242. package/dist/runtime/run-context.service.js +7 -22
  243. package/dist/runtime/run-deletion.d.ts +6 -0
  244. package/dist/runtime/run-deletion.js +39 -16
  245. package/dist/runtime/run-execution.d.ts +56 -3
  246. package/dist/runtime/run-execution.js +81 -11
  247. package/dist/runtime/run-finish.js +2 -1
  248. package/dist/runtime/run-liveness.d.ts +11 -0
  249. package/dist/runtime/run-liveness.js +19 -0
  250. package/dist/runtime/run-orphan-check.job.js +2 -1
  251. package/dist/runtime/run-queue.js +8 -16
  252. package/dist/runtime/run-worker.d.ts +2 -2
  253. package/dist/runtime/run-worker.js +8 -6
  254. package/dist/runtime/step-log.d.ts +5 -0
  255. package/dist/runtime/step-log.js +9 -4
  256. package/dist/runtime/subagents/definition.d.ts +16 -20
  257. package/dist/runtime/subagents/definition.js +27 -27
  258. package/dist/runtime/subagents/dispatch.d.ts +6 -2
  259. package/dist/runtime/subagents/dispatch.js +17 -3
  260. package/dist/runtime/subagents/org-agents.js +1 -2
  261. package/dist/runtime/subagents/preamble.d.ts +3 -2
  262. package/dist/runtime/subagents/preamble.js +3 -2
  263. package/dist/runtime/subagents/render.d.ts +1 -2
  264. package/dist/runtime/subagents/render.js +1 -2
  265. package/dist/runtime/subagents/skill-fork.d.ts +2 -4
  266. package/dist/runtime/subagents/template-skills.d.ts +47 -0
  267. package/dist/runtime/subagents/template-skills.js +76 -0
  268. package/dist/runtime/waits.js +3 -1
  269. package/dist/schedules/effective-settings.d.ts +9 -3
  270. package/dist/schedules/effective-settings.js +5 -4
  271. package/dist/schedules/fire.js +11 -0
  272. package/dist/schedules/scheduled-tasks.service.js +5 -0
  273. package/dist/schedules/unattended.d.ts +2 -0
  274. package/dist/schedules/unattended.js +6 -1
  275. package/dist/skills/agent-skills.service.js +1 -2
  276. package/dist/skills/catalog.d.ts +1 -3
  277. package/dist/skills/catalog.js +1 -3
  278. package/dist/skills/conversation-catalog.d.ts +1 -2
  279. package/dist/skills/conversation-catalog.js +1 -2
  280. package/dist/skills/usable.js +2 -3
  281. package/dist/storage/storage.service.js +9 -1
  282. package/dist/tools/approvals.service.js +2 -4
  283. package/dist/tools/builtin-names.d.ts +2 -9
  284. package/dist/tools/builtin-names.js +4 -13
  285. package/dist/tools/builtins/sandbox/bash.js +3 -3
  286. package/dist/tools/builtins/sandbox/common.d.ts +7 -13
  287. package/dist/tools/builtins/sandbox/common.js +8 -115
  288. package/dist/tools/builtins/sandbox/fetch-attachment.d.ts +10 -0
  289. package/dist/tools/builtins/sandbox/fetch-attachment.js +119 -0
  290. package/dist/tools/builtins/sandbox/glob.js +1 -3
  291. package/dist/tools/builtins/sandbox/grep.js +3 -5
  292. package/dist/tools/builtins/sandbox/index.d.ts +8 -5
  293. package/dist/tools/builtins/sandbox/index.js +10 -5
  294. package/dist/tools/builtins/sandbox/read.js +3 -2
  295. package/dist/tools/builtins/tool-search.d.ts +4 -7
  296. package/dist/tools/builtins/tool-search.js +6 -10
  297. package/dist/tools/connector-account-policies.d.ts +30 -3
  298. package/dist/tools/connector-account-policies.js +54 -7
  299. package/dist/tools/connector-content.js +1 -0
  300. package/dist/tools/connectors.controller.d.ts +24 -11
  301. package/dist/tools/connectors.controller.js +35 -6
  302. package/dist/tools/connectors.schemas.d.ts +14 -1
  303. package/dist/tools/connectors.schemas.js +14 -2
  304. package/dist/tools/connectors.service.d.ts +22 -0
  305. package/dist/tools/connectors.service.js +65 -6
  306. package/dist/tools/drift.d.ts +6 -2
  307. package/dist/tools/drift.js +10 -5
  308. package/dist/tools/git-push-policy.d.ts +4 -1
  309. package/dist/tools/git-push-policy.js +3 -1
  310. package/dist/tools/info.d.ts +1 -7
  311. package/dist/tools/info.js +5 -18
  312. package/dist/tools/job-ids.d.ts +0 -4
  313. package/dist/tools/job-ids.js +1 -6
  314. package/dist/tools/pipeline.d.ts +4 -10
  315. package/dist/tools/pipeline.js +17 -62
  316. package/dist/tools/policy.d.ts +6 -2
  317. package/dist/tools/policy.js +14 -12
  318. package/dist/tools/registry.js +1 -5
  319. package/dist/ui/views.d.ts +5 -5
  320. package/dist/ui/views.js +10 -16
  321. package/package.json +3 -3
  322. package/src/migrations/0137_audit_org_idx.sql +5 -0
  323. package/src/migrations/0138_plugin_install_status_no_upgrading.sql +18 -0
  324. package/src/migrations/0139_retire_legacy_forms.sql +183 -0
  325. package/src/migrations/0140_retire_history_forms.sql +148 -0
  326. package/src/migrations/0141_install_ledger_promoted_rows.sql +36 -0
  327. package/src/migrations/0142_backfill_event_fields.sql +74 -0
  328. package/src/migrations/0143_backfill_model_call_fields.sql +105 -0
  329. package/src/migrations/0144_retire_frozen_definition_keys.sql +163 -0
  330. package/src/migrations/0145_org_network_allowances.sql +12 -0
  331. package/dist/admin/platform-audit.service.d.ts +0 -41
  332. package/dist/conversations/job-ids.d.ts +0 -6
  333. package/dist/conversations/job-ids.js +0 -6
  334. package/dist/extensions/job-ids.d.ts +0 -6
  335. package/dist/extensions/job-ids.js +0 -6
  336. package/dist/infra/queue/retired-schedulers.d.ts +0 -7
  337. package/dist/infra/queue/retired-schedulers.js +0 -9
  338. package/dist/orgs/job-ids.d.ts +0 -8
  339. package/dist/orgs/job-ids.js +0 -8
  340. package/dist/runtime/context/legacy-text.d.ts +0 -22
  341. package/dist/runtime/context/legacy-text.js +0 -37
  342. package/dist/runtime/job-ids.d.ts +0 -10
  343. package/dist/runtime/job-ids.js +0 -10
  344. package/dist/runtime/retired-schedulers.d.ts +0 -7
  345. package/dist/runtime/retired-schedulers.js +0 -31
  346. package/dist/storage/job-ids.d.ts +0 -6
  347. package/dist/storage/job-ids.js +0 -6
  348. package/dist/tools/legacy-data.d.ts +0 -34
  349. package/dist/tools/legacy-data.js +0 -76
  350. package/dist/tools/legacy-keys.d.ts +0 -51
  351. package/dist/tools/legacy-keys.js +0 -114
@@ -0,0 +1,101 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
8
+ return function (target, key) { decorator(target, key, paramIndex); }
9
+ };
10
+ import { Inject, Injectable } from "@nestjs/common";
11
+ import { ApiError } from "../errors.js";
12
+ import { SuperAdminLock } from "../identity/super-admin.js";
13
+ import { TransactionHost } from "../infra/database/transaction-host.js";
14
+ import { Transactional } from "../infra/database/transactional.decorator.js";
15
+ import { allowanceEntryProblem, OrgNetworkAllowances, } from "../orgs/network-allowances.service.js";
16
+ import { OrgsService } from "../orgs/orgs.service.js";
17
+ /**
18
+ * The super admin's side of the org network allowances (plugin safe fetch spec): the admin routes
19
+ * and their Platform operations call it. Writes take the super admin lock and re-check the actor
20
+ * in the same transaction as the store's write (`OrgNetworkAllowances` joins it).
21
+ *
22
+ * Only a person widens: an add is refused for an API token or the Platform tool (`onlyNarrows`)
23
+ * with `org.network_allowance_widen_not_allowed`; listing and removing stay open to both.
24
+ */
25
+ let OrgNetworkAdmin = class OrgNetworkAdmin {
26
+ allowances;
27
+ orgs;
28
+ adminLock;
29
+ txHost;
30
+ constructor(allowances, orgs, adminLock, txHost) {
31
+ this.allowances = allowances;
32
+ this.orgs = orgs;
33
+ this.adminLock = adminLock;
34
+ this.txHost = txHost;
35
+ }
36
+ /** The org's entries, oldest first; a missing or deleted org is `org.not_found`. */
37
+ async list(orgId) {
38
+ await this.assertOrg(orgId);
39
+ return this.allowances.list(orgId);
40
+ }
41
+ /**
42
+ * The read-only preconditions of {@link add}, throwing its own refusals: `onlyNarrows` →
43
+ * `org.network_allowance_widen_not_allowed`, a missing org → `org.not_found`, an invalid entry →
44
+ * `org.network_allowance_invalid` (the cap is checked by the write only).
45
+ */
46
+ async checkAdd(orgId, entry, onlyNarrows) {
47
+ assertWidenAllowed(onlyNarrows);
48
+ await this.assertOrg(orgId);
49
+ const problem = allowanceEntryProblem(entry);
50
+ if (problem !== null) {
51
+ throw new ApiError("org.network_allowance_invalid", `${entry.trim()}: ${problem}`);
52
+ }
53
+ }
54
+ /**
55
+ * Adds an entry (audited `org.network_allowance_added`); an entry already listed is returned.
56
+ * `onlyNarrows` (an API token, the Platform tool) refuses it: only a person widens. The actor's
57
+ * token id and `auditDetail` go into the audit event.
58
+ */
59
+ async add(orgId, entry, actor, onlyNarrows, auditDetail = {}) {
60
+ assertWidenAllowed(onlyNarrows);
61
+ await this.adminLock.lockAndAuthorize(actor.accountId);
62
+ return this.allowances.add(orgId, entry, actor, auditDetail);
63
+ }
64
+ /**
65
+ * Removes the org's entry `id` (audited `org.network_allowance_removed`); a missing or deleted
66
+ * org is `org.not_found`, an id the org does not list `org.network_allowance_not_found`. The
67
+ * actor's token id and `auditDetail` go into the audit event.
68
+ */
69
+ async remove(orgId, id, actor, auditDetail = {}) {
70
+ await this.adminLock.lockAndAuthorize(actor.accountId);
71
+ await this.assertOrg(orgId);
72
+ if (!(await this.allowances.remove(orgId, id, actor, auditDetail))) {
73
+ throw new ApiError("org.network_allowance_not_found", "The organization has no such internal endpoint allowance");
74
+ }
75
+ }
76
+ async assertOrg(orgId) {
77
+ if ((await this.orgs.get(orgId)) === undefined) {
78
+ throw new ApiError("org.not_found", "Organization not found");
79
+ }
80
+ }
81
+ };
82
+ __decorate([
83
+ Transactional()
84
+ ], OrgNetworkAdmin.prototype, "add", null);
85
+ __decorate([
86
+ Transactional()
87
+ ], OrgNetworkAdmin.prototype, "remove", null);
88
+ OrgNetworkAdmin = __decorate([
89
+ Injectable(),
90
+ __param(0, Inject(OrgNetworkAllowances)),
91
+ __param(1, Inject(OrgsService)),
92
+ __param(2, Inject(SuperAdminLock)),
93
+ __param(3, Inject(TransactionHost))
94
+ ], OrgNetworkAdmin);
95
+ export { OrgNetworkAdmin };
96
+ /** Only a person in a web session widens what an org's extension requests may reach. */
97
+ function assertWidenAllowed(onlyNarrows) {
98
+ if (onlyNarrows) {
99
+ throw new ApiError("org.network_allowance_widen_not_allowed", "Allowing an internal endpoint needs a super admin in the admin console on the web, not an API token or the Platform tool.");
100
+ }
101
+ }
@@ -1,7 +1,7 @@
1
1
  import type { z } from "zod";
2
2
  import { type Principal } from "../identity/principal.js";
3
- import { OutboxDeadParams } from "./outbox-dead.schemas.js";
4
- import { type OutboxDeadRow, OutboxDeadService, type OutboxRetryOutcome } from "./outbox-dead.service.js";
3
+ import { OutboxDeadListQuery, OutboxDeadParams } from "./outbox-dead.schemas.js";
4
+ import { type OutboxDeadPage, OutboxDeadService, type OutboxRetryOutcome } from "./outbox-dead.service.js";
5
5
  /**
6
6
  * Dead outbox rows (`/api/v1/admin/outbox/dead*`, transactional outbox spec §3.4): background work
7
7
  * the kernel could not queue after its last attempt. Super admins only; service tokens 403. Retry
@@ -10,10 +10,8 @@ import { type OutboxDeadRow, OutboxDeadService, type OutboxRetryOutcome } from "
10
10
  export declare class OutboxDeadController {
11
11
  private readonly dead;
12
12
  constructor(dead: OutboxDeadService);
13
- /** The dead rows, oldest first (at most 200). */
14
- list(): Promise<{
15
- items: OutboxDeadRow[];
16
- }>;
13
+ /** A page of dead rows, oldest first; `next` is the `after` of the next page, null at the end. */
14
+ list(q: z.infer<typeof OutboxDeadListQuery>): Promise<OutboxDeadPage>;
17
15
  /** Makes the row due again, or discards it when the same job is owed already (`already_owed`). */
18
16
  retry(principal: Principal, { id }: z.infer<typeof OutboxDeadParams>): Promise<{
19
17
  outcome: OutboxRetryOutcome;
@@ -11,9 +11,11 @@ import { Controller, Delete, Get, HttpCode, Inject, Post } from "@nestjs/common"
11
11
  import { CurrentPrincipal, SuperAdmin } from "../identity/principal.js";
12
12
  import { writeActorOf } from "../identity/write-actor.js";
13
13
  import { createZodDto } from "../infra/validation/create-zod-dto.js";
14
- import { ZParam } from "../infra/validation/zod-params.js";
15
- import { OutboxDeadParams } from "./outbox-dead.schemas.js";
14
+ import { ZParam, ZQuery } from "../infra/validation/zod-params.js";
15
+ import { OutboxDeadListQuery, OutboxDeadParams } from "./outbox-dead.schemas.js";
16
16
  import { OutboxDeadService, } from "./outbox-dead.service.js";
17
+ class OutboxDeadListQueryDto extends createZodDto(OutboxDeadListQuery, "OutboxDeadListQuery") {
18
+ }
17
19
  class OutboxDeadParamsDto extends createZodDto(OutboxDeadParams, "OutboxDeadParams") {
18
20
  }
19
21
  /**
@@ -26,9 +28,9 @@ let OutboxDeadController = class OutboxDeadController {
26
28
  constructor(dead) {
27
29
  this.dead = dead;
28
30
  }
29
- /** The dead rows, oldest first (at most 200). */
30
- list() {
31
- return this.dead.list();
31
+ /** A page of dead rows, oldest first; `next` is the `after` of the next page, null at the end. */
32
+ list(q) {
33
+ return this.dead.list(q);
32
34
  }
33
35
  /** Makes the row due again, or discards it when the same job is owed already (`already_owed`). */
34
36
  retry(principal, { id }) {
@@ -40,7 +42,8 @@ let OutboxDeadController = class OutboxDeadController {
40
42
  }
41
43
  };
42
44
  __decorate([
43
- Get()
45
+ Get(),
46
+ __param(0, ZQuery(OutboxDeadListQueryDto))
44
47
  ], OutboxDeadController.prototype, "list", null);
45
48
  __decorate([
46
49
  Post(":id/retry"),
@@ -4,5 +4,21 @@ import type { RouteSchemas } from "../platform/route-schemas.js";
4
4
  export declare const OutboxDeadParams: z.ZodObject<{
5
5
  id: z.ZodString;
6
6
  }, z.core.$strip>;
7
+ /** The most dead rows one page of `GET /api/v1/admin/outbox/dead` returns. */
8
+ export declare const OUTBOX_DEAD_LIST_MAX = 200;
9
+ /** A page cursor: the last row's `dead_at` (as PG prints it, microseconds) and id. */
10
+ export interface OutboxDeadCursor {
11
+ deadAt: string;
12
+ id: string;
13
+ }
14
+ /** The opaque `next` / `after` token of a page ending at `c`. */
15
+ export declare const encodeOutboxDeadCursor: (c: OutboxDeadCursor) => string;
16
+ /** The cursor in `token`, or null when it is not one {@link encodeOutboxDeadCursor} made. */
17
+ export declare function decodeOutboxDeadCursor(token: string): OutboxDeadCursor | null;
18
+ /** `GET /api/v1/admin/outbox/dead`: keyset paging by `(dead_at, id)`, oldest first. */
19
+ export declare const OutboxDeadListQuery: z.ZodObject<{
20
+ after: z.ZodOptional<z.ZodString>;
21
+ limit: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
22
+ }, z.core.$strip>;
7
23
  /** The super admin's dead outbox rows (transactional outbox spec §3.4). */
8
24
  export declare const OUTBOX_DEAD_ROUTES: readonly RouteSchemas[];
@@ -10,9 +10,33 @@ export const OutboxDeadParams = z.object({
10
10
  .refine((v) => !/^\d{1,19}$/.test(v) || BigInt(v) <= MAX_BIGINT, "id must be an outbox row id")
11
11
  .describe("The dead row's id, as admin.outbox-list-dead lists it."),
12
12
  });
13
+ /** The most dead rows one page of `GET /api/v1/admin/outbox/dead` returns. */
14
+ export const OUTBOX_DEAD_LIST_MAX = 200;
15
+ const CURSOR_TS = /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}(\.\d{1,6})?[+-]\d{2}(:\d{2})?$/;
16
+ /** The opaque `next` / `after` token of a page ending at `c`. */
17
+ export const encodeOutboxDeadCursor = (c) => Buffer.from(`${c.deadAt}|${c.id}`, "utf8").toString("base64url");
18
+ /** The cursor in `token`, or null when it is not one {@link encodeOutboxDeadCursor} made. */
19
+ export function decodeOutboxDeadCursor(token) {
20
+ const [deadAt, id, ...rest] = Buffer.from(token, "base64url").toString("utf8").split("|");
21
+ if (deadAt === undefined || id === undefined || rest.length > 0)
22
+ return null;
23
+ if (!CURSOR_TS.test(deadAt) || !/^\d{1,19}$/.test(id) || BigInt(id) > MAX_BIGINT)
24
+ return null;
25
+ return { deadAt, id };
26
+ }
27
+ /** `GET /api/v1/admin/outbox/dead`: keyset paging by `(dead_at, id)`, oldest first. */
28
+ export const OutboxDeadListQuery = z.object({
29
+ after: z
30
+ .string()
31
+ .max(200)
32
+ .refine((v) => decodeOutboxDeadCursor(v) !== null, "after must be a cursor from a previous page")
33
+ .optional()
34
+ .describe("The `next` of the previous page; absent: the oldest dead rows."),
35
+ limit: z.coerce.number().int().min(1).max(OUTBOX_DEAD_LIST_MAX).default(OUTBOX_DEAD_LIST_MAX),
36
+ });
13
37
  /** The super admin's dead outbox rows (transactional outbox spec §3.4). */
14
38
  export const OUTBOX_DEAD_ROUTES = [
15
- { route: "GET /api/v1/admin/outbox/dead" },
39
+ { route: "GET /api/v1/admin/outbox/dead", query: OutboxDeadListQuery },
16
40
  { route: "POST /api/v1/admin/outbox/dead/:id/retry", params: OutboxDeadParams },
17
41
  { route: "DELETE /api/v1/admin/outbox/dead/:id", params: OutboxDeadParams },
18
42
  ];
@@ -1,9 +1,8 @@
1
+ import { SuperAdminLock } from "../identity/super-admin.js";
1
2
  import type { WriteActor } from "../identity/write-actor.js";
2
3
  import { KernelDb } from "../infra/database/kernel-db.js";
3
4
  import { TransactionHost } from "../infra/database/transaction-host.js";
4
5
  import { type OutboxFastPath } from "../infra/outbox/outbox.service.js";
5
- /** The most dead rows `GET /api/v1/admin/outbox/dead` returns, oldest first. */
6
- export declare const OUTBOX_DEAD_LIST_MAX = 200;
7
6
  /** A dead outbox row as the super admin sees it (transactional outbox spec §3.4). */
8
7
  export interface OutboxDeadRow {
9
8
  id: string;
@@ -17,6 +16,11 @@ export interface OutboxDeadRow {
17
16
  deadAt: string;
18
17
  createdAt: string;
19
18
  }
19
+ /** A page of dead rows; `next` is the `after` of the next page, null at the end. */
20
+ export interface OutboxDeadPage {
21
+ items: OutboxDeadRow[];
22
+ next: string | null;
23
+ }
20
24
  /** Dead rows in all: how many and since when (the overview's `outbox_dead` attention item). */
21
25
  export interface OutboxDeadSummary {
22
26
  count: number;
@@ -38,11 +42,16 @@ export declare class OutboxDeadService {
38
42
  readonly txHost: TransactionHost;
39
43
  private readonly db;
40
44
  private readonly fastPath;
41
- constructor(txHost: TransactionHost, db: KernelDb, fastPath: OutboxFastPath);
42
- /** The dead rows, oldest first, at most {@link OUTBOX_DEAD_LIST_MAX}. */
43
- list(): Promise<{
44
- items: OutboxDeadRow[];
45
- }>;
45
+ private readonly adminLock;
46
+ constructor(txHost: TransactionHost, db: KernelDb, fastPath: OutboxFastPath, adminLock: SuperAdminLock);
47
+ /**
48
+ * `limit` dead rows (at most {@link OUTBOX_DEAD_LIST_MAX}) after the cursor `after`, oldest
49
+ * first by `(dead_at, id)`; one extra row tells `next`. A malformed cursor is a validation error.
50
+ */
51
+ list(q?: {
52
+ after?: string | undefined;
53
+ limit?: number;
54
+ }): Promise<OutboxDeadPage>;
46
55
  /** How many rows are dead, and the oldest one's `dead_at`. */
47
56
  summary(): Promise<OutboxDeadSummary>;
48
57
  /**
@@ -11,13 +11,13 @@ import { Inject, Injectable } from "@nestjs/common";
11
11
  import { sql } from "kysely";
12
12
  import { ApiError } from "../errors.js";
13
13
  import { audit } from "../identity/audit.js";
14
+ import { SuperAdminLock } from "../identity/super-admin.js";
14
15
  import { afterCommit } from "../infra/database/after-commit.js";
15
16
  import { KernelDb } from "../infra/database/kernel-db.js";
16
17
  import { TransactionHost } from "../infra/database/transaction-host.js";
17
18
  import { Transactional } from "../infra/database/transactional.decorator.js";
18
19
  import { OUTBOX_FAST_PATH } from "../infra/outbox/outbox.service.js";
19
- /** The most dead rows `GET /api/v1/admin/outbox/dead` returns, oldest first. */
20
- export const OUTBOX_DEAD_LIST_MAX = 200;
20
+ import { decodeOutboxDeadCursor, encodeOutboxDeadCursor, OUTBOX_DEAD_LIST_MAX, } from "./outbox-dead.schemas.js";
21
21
  /** The unique index of pending rows (0119): one pending row per (queue, job_id). */
22
22
  const PENDING_UNIQUE = "outbox_job_uniq";
23
23
  const isPendingConflict = (e) => typeof e === "object" &&
@@ -36,14 +36,24 @@ let OutboxDeadService = class OutboxDeadService {
36
36
  txHost;
37
37
  db;
38
38
  fastPath;
39
- constructor(txHost, db, fastPath) {
39
+ adminLock;
40
+ constructor(txHost, db, fastPath, adminLock) {
40
41
  this.txHost = txHost;
41
42
  this.db = db;
42
43
  this.fastPath = fastPath;
44
+ this.adminLock = adminLock;
43
45
  }
44
- /** The dead rows, oldest first, at most {@link OUTBOX_DEAD_LIST_MAX}. */
45
- async list() {
46
- const rows = await this.db.db
46
+ /**
47
+ * `limit` dead rows (at most {@link OUTBOX_DEAD_LIST_MAX}) after the cursor `after`, oldest
48
+ * first by `(dead_at, id)`; one extra row tells `next`. A malformed cursor is a validation error.
49
+ */
50
+ async list(q = {}) {
51
+ const limit = Math.min(q.limit ?? OUTBOX_DEAD_LIST_MAX, OUTBOX_DEAD_LIST_MAX);
52
+ const cursor = q.after === undefined ? null : decodeOutboxDeadCursor(q.after);
53
+ if (q.after !== undefined && cursor === null) {
54
+ throw new ApiError("validation_failed", "after must be a cursor from a previous page");
55
+ }
56
+ let query = this.db.db
47
57
  .selectFrom("outbox")
48
58
  .select([
49
59
  "id",
@@ -55,14 +65,25 @@ let OutboxDeadService = class OutboxDeadService {
55
65
  "last_error",
56
66
  "dead_at",
57
67
  "created_at",
68
+ // PG's own text keeps the microseconds a JS Date would cut
69
+ sql `dead_at::text`.as("dead_at_text"),
58
70
  ])
59
- .where("dead_at", "is not", null)
71
+ .where("dead_at", "is not", null);
72
+ if (cursor !== null) {
73
+ query = query.where(sql `(dead_at, id) > (${cursor.deadAt}::timestamptz, ${cursor.id}::bigint)`);
74
+ }
75
+ const rows = await query
60
76
  .orderBy("dead_at")
61
77
  .orderBy("id")
62
- .limit(OUTBOX_DEAD_LIST_MAX)
78
+ .limit(limit + 1)
63
79
  .execute();
80
+ const page = rows.slice(0, limit);
81
+ const last = page.at(-1);
64
82
  return {
65
- items: rows.map((r) => ({
83
+ next: rows.length > limit && last !== undefined
84
+ ? encodeOutboxDeadCursor({ deadAt: last.dead_at_text, id: String(last.id) })
85
+ : null,
86
+ items: page.map((r) => ({
66
87
  id: String(r.id),
67
88
  queue: r.queue,
68
89
  jobName: r.job_name,
@@ -111,6 +132,7 @@ let OutboxDeadService = class OutboxDeadService {
111
132
  }
112
133
  }
113
134
  async retryOnce(id, actor, detail) {
135
+ await this.adminLock.lockAndAuthorize(actor.accountId);
114
136
  await this.lockRunRetryIn(id);
115
137
  const row = await this.lockDead(id);
116
138
  const owed = await this.db.db
@@ -169,6 +191,7 @@ let OutboxDeadService = class OutboxDeadService {
169
191
  }
170
192
  /** Deletes a dead row: its job is never delivered. `outbox.not_found` (404) when none. */
171
193
  async discard(id, actor, detail = {}) {
194
+ await this.adminLock.lockAndAuthorize(actor.accountId);
172
195
  const row = await this.lockDead(id);
173
196
  await this.db.db.deleteFrom("outbox").where("id", "=", id).execute();
174
197
  await this.audit("outbox.discarded", id, row, actor, detail);
@@ -219,6 +242,7 @@ OutboxDeadService = __decorate([
219
242
  Injectable(),
220
243
  __param(0, Inject(TransactionHost)),
221
244
  __param(1, Inject(KernelDb)),
222
- __param(2, Inject(OUTBOX_FAST_PATH))
245
+ __param(2, Inject(OUTBOX_FAST_PATH)),
246
+ __param(3, Inject(SuperAdminLock))
223
247
  ], OutboxDeadService);
224
248
  export { OutboxDeadService };
@@ -29,10 +29,10 @@ export interface AdminOverviewStats {
29
29
  /**
30
30
  * Why an extension needs a look (spec §5.2), from its status and `configValid`: `config` (missing
31
31
  * or invalid deployment config), `load_failed`, `approval` (permissions wait for confirmation),
32
- * `dependency`, `conflict`, `converging` (replicas disagree, or a migration waits) and
33
- * `legacy_format`. Never the raw replica detail.
32
+ * `dependency`, `conflict` and `converging` (replicas disagree, or a migration waits). Never the
33
+ * raw replica detail.
34
34
  */
35
- export type AttentionExtensionReason = "config" | "load_failed" | "approval" | "dependency" | "conflict" | "converging" | "legacy_format";
35
+ export type AttentionExtensionReason = "config" | "load_failed" | "approval" | "dependency" | "conflict" | "converging";
36
36
  /** What is wrong with a model provider: its model list failed, or it lists no usable chat model. */
37
37
  export type AttentionProviderProblem = "list_failed" | "no_chat_model";
38
38
  /** An attention list a source failed to read (it is then empty, the others intact). */
@@ -33,7 +33,6 @@ export function extensionReason(e) {
33
33
  return "approval";
34
34
  case "dependency":
35
35
  case "conflict":
36
- case "legacy_format":
37
36
  return e.status;
38
37
  case "converging":
39
38
  case "pending_migration":
@@ -11,8 +11,7 @@ import { Inject, Injectable, Module } from "@nestjs/common";
11
11
  import { sql } from "kysely";
12
12
  import { ApiError } from "../errors.js";
13
13
  import { KernelDb } from "../infra/database/kernel-db.js";
14
- import { loadLegacyScope } from "../tools/legacy-data.js";
15
- import { needsLegacyScope, normalizeStoredDefinition } from "./definition.js";
14
+ import { normalizeStoredDefinition } from "./definition.js";
16
15
  export const AGENT_VISIBILITIES = ["private", "org", "members"];
17
16
  const notFound = () => new ApiError("agent.not_found", "Agent not found");
18
17
  /**
@@ -165,13 +164,6 @@ let AgentLookup = class AgentLookup {
165
164
  .orderBy("account_id")
166
165
  .execute();
167
166
  const byId = new Map(rows.map((r) => [r.id, r]));
168
- // rc `<x>__<tool>` keys read with their org's scope, loaded once per org that needs it
169
- const scopes = new Map();
170
- for (const r of rows) {
171
- if (!scopes.has(r.org_id) && needsLegacyScope(r.definition)) {
172
- scopes.set(r.org_id, await loadLegacyScope(this.db.db, r.org_id));
173
- }
174
- }
175
167
  return ids.flatMap((id) => {
176
168
  const r = byId.get(id);
177
169
  if (!r)
@@ -184,7 +176,7 @@ let AgentLookup = class AgentLookup {
184
176
  ownerAccountId: r.owner_account_id,
185
177
  visibility: r.visibility,
186
178
  currentVersion: r.current_version,
187
- definition: normalizeStoredDefinition(r.definition, scopes.get(r.org_id)),
179
+ definition: normalizeStoredDefinition(r.definition),
188
180
  profile: {
189
181
  avatar: r.profile_avatar,
190
182
  description: r.profile_description,
@@ -26,10 +26,9 @@ import { ProviderRegistry } from "../runtime/providers.js";
26
26
  import { SkillChangesService } from "../skills/changes.service.js";
27
27
  import { assertDisabledSkills } from "../skills/skills.service.js";
28
28
  import { agentSkills } from "../skills/usable.js";
29
- import { legacyKeySaveText } from "../tools/legacy-keys.js";
30
29
  import { ToolRegistry } from "../tools/registry.js";
31
30
  import { AgentLookup, isAgentVisibleTo, visibleTo, } from "./agent-lookup.js";
32
- import { canonicalDisabledSkills, canonicalDisabledTools, normalizeStoredDefinition, paramIssues, SUBAGENT_NAME_RE, SUBAGENT_ROSTER_MAX, withoutRemovedBuiltinPolicies, } from "./definition.js";
31
+ import { canonicalDisabledSkills, canonicalDisabledTools, normalizeStoredDefinition, paramIssues, SUBAGENT_NAME_RE, SUBAGENT_ROSTER_MAX, } from "./definition.js";
33
32
  import { deriveInstructions } from "./instruction-files.js";
34
33
  import { PendingConnectorRequests } from "./pending-connector-requests.js";
35
34
  import { randomPreset } from "./profile.js";
@@ -213,11 +212,8 @@ export async function assertSubagents(t, a) {
213
212
  const base = `subagents.inline.${i}`;
214
213
  name(x.name, `${base}.name`);
215
214
  const tool = (key, path) => {
216
- if (a.toolKeys.has(key))
217
- return;
218
- // an rc key names its current key(s) (tool naming spec §8.3)
219
- const renamed = legacyKeySaveText(key, a.toolKeys);
220
- add("tool_not_selected", path, key, renamed ?? undefined);
215
+ if (!a.toolKeys.has(key))
216
+ add("tool_not_selected", path, key);
221
217
  };
222
218
  for (const [j, key] of (x.tools ?? []).entries())
223
219
  tool(key, `${base}.tools.${j}`);
@@ -336,11 +332,9 @@ let AgentsService = class AgentsService {
336
332
  continue;
337
333
  }
338
334
  if (!isToolPolicyKey(key, keys)) {
339
- // an rc key (tool naming spec §8.3): saving writes current keys only, so name them
340
- const renamed = legacyKeySaveText(key, keys);
341
335
  details.push({
342
336
  path: `toolPolicies.${key}`,
343
- message: renamed ?? `"${key}" is not a tool of this agent`,
337
+ message: `"${key}" is not a tool of this agent`,
344
338
  });
345
339
  }
346
340
  }
@@ -431,8 +425,7 @@ let AgentsService = class AgentsService {
431
425
  return this.createChecked(orgId, actorAccountId, request, template, actorTokenId, auditDetail);
432
426
  }
433
427
  async createChecked(orgId, actorAccountId, request, template, actorTokenId, auditDetail) {
434
- // a policy key of a removed builtin (e.g. copied from a template) is dropped, never refused
435
- const given = withoutRemovedBuiltinPolicies(request.definition);
428
+ const given = request.definition;
436
429
  const input = {
437
430
  ...request,
438
431
  givenDisabledSkills: given.disabledSkills ?? [],
@@ -579,15 +572,11 @@ let AgentsService = class AgentsService {
579
572
  * 只有负责人或组织管理员以上可改,在组织行锁内复核。
580
573
  */
581
574
  async update(orgId, agentId, actorAccountId, request, actorTokenId, auditDetail) {
582
- // a policy key of a removed builtin (stored before it went) is dropped, never refused
583
- const patch = request.definition === undefined
584
- ? request
585
- : { ...request, definition: withoutRemovedBuiltinPolicies(request.definition) };
586
- const warnings = patch.definition ? await this.checkModels(orgId, patch.definition) : [];
587
- const toolKeys = patch.definition
588
- ? await this.checkTools(orgId, patch.definition, await this.keptDisabled(orgId, agentId))
575
+ const warnings = request.definition ? await this.checkModels(orgId, request.definition) : [];
576
+ const toolKeys = request.definition
577
+ ? await this.checkTools(orgId, request.definition, await this.keptDisabled(orgId, agentId))
589
578
  : null;
590
- const agent = await this.updateIn(orgId, agentId, actorAccountId, patch, toolKeys, actorTokenId, auditDetail);
579
+ const agent = await this.updateIn(orgId, agentId, actorAccountId, request, toolKeys, actorTokenId, auditDetail);
591
580
  return { agent, warnings };
592
581
  }
593
582
  async updateIn(orgId, agentId, actorAccountId, patch, toolKeys, actorTokenId, auditDetail) {
@@ -1,6 +1,5 @@
1
1
  import { type ModelParameter } from "@capybara-hq/plugin-sdk";
2
2
  import { z } from "zod";
3
- import { type LegacyScope } from "../tools/legacy-keys.js";
4
3
  /** 模型引用:供应商插件名 + 模型 id。 */
5
4
  export declare const ModelRef: z.ZodObject<{
6
5
  provider: z.ZodString;
@@ -314,57 +313,11 @@ export declare const AgentDefinitionSchema: z.ZodObject<{
314
313
  }, z.core.$strict>>;
315
314
  }, z.core.$strip>;
316
315
  export type AgentDefinition = z.infer<typeof AgentDefinitionSchema>;
317
- /** The connectors and extensions a definition's own tool refs name (to read an ambiguous rc key). */
318
- interface OwnRefs {
319
- connectors: ReadonlySet<string>;
320
- extensions: ReadonlySet<string>;
321
- }
322
316
  /**
323
- * Release-candidate tool keys in a stored definition, read as current keys (tool naming spec
324
- * §8.3), the way {@link normalizeToolRef} reads the app -> connector rename: builtin refs in
325
- * `tools`, the keys of `toolPolicies`, and the `tools` / `disallowedTools` / `toolPolicies` of a
326
- * template, the agent's inline sub-agent templates included. Works on an agent definition and on
327
- * an agent template alike. Old builtin names map without `scope`; an rc `<x>__<tool>` key maps
328
- * only with one (the org's connector slugs and their ids, the deployment's extension names). When
329
- * `x` is both a slug and an extension name, the definition's own tool refs decide; when they
330
- * cannot, a policy or a deny list keeps the restriction on both candidate keys (a deny is never
331
- * lost) and an allowlist keeps the old key (inert). An unknown key stays as it is. Keys in the
332
- * current format are never touched. Returns the same object when nothing changes. Saving never
333
- * goes through this: a new definition with an old key is refused (`AgentsService`).
317
+ * A definition read from the database or from a log (not parsed by zod): `disabledTools` and
318
+ * `disabledSkills` default to empty lists (nothing turned off). Other fields are kept.
334
319
  */
335
- export declare function normalizeToolKeys(definition: unknown, scope?: LegacyScope, inherited?: OwnRefs): unknown;
336
- /** The fields {@link withoutRemovedBuiltinPolicies} reads. */
337
- interface AgentDefinitionLike {
338
- toolPolicies?: Record<string, string> | undefined;
339
- subagents?: {
340
- inline?: readonly {
341
- toolPolicies?: Record<string, string> | undefined;
342
- }[] | undefined;
343
- } | undefined;
344
- }
345
- /**
346
- * `definition` without the `toolPolicies` keys (its own and its inline sub-agents') of builtins
347
- * that no longer exist ({@link isRemovedBuiltinKey}): applied to a definition being saved, so a
348
- * key left over from a removed builtin never blocks the save. Returns the same object when
349
- * nothing is dropped.
350
- */
351
- export declare function withoutRemovedBuiltinPolicies<T extends AgentDefinitionLike>(definition: T): T;
352
- /**
353
- * Does a stored definition or template hold an rc `<x>__<tool>` key, which only a
354
- * {@link LegacyScope} can map? (Callers load the scope only then.)
355
- */
356
- export declare function needsLegacyScope(definition: unknown): boolean;
357
- /**
358
- * A definition read from the database or from history (not parsed by zod): rc tool keys read as
359
- * current keys ({@link normalizeToolKeys}: builtins always, `<x>__<tool>` keys with `scope`), and
360
- * a definition from before tools were on by default (an enabled `tools` list, history only: the
361
- * migration rewrote stored versions) reads as nothing turned off, which is what the migration
362
- * writes (tools default-on spec §2, §3). Likewise a definition from before skills were on by
363
- * default (`skills.orgSkills` / `skills.pinned`) reads as no skill turned off (skills default-on
364
- * spec §4; migration 0116 rewrote stored versions). Other fields are kept; without old forms the
365
- * same object is returned.
366
- */
367
- export declare function normalizeStoredDefinition(def: unknown, scope?: LegacyScope): AgentDefinition;
320
+ export declare function normalizeStoredDefinition(def: unknown): AgentDefinition;
368
321
  /** 按模型声明严格校验一组参数,返回 `{ path: "<field>.<key>", message }[]`(评测候选也用它)。 */
369
322
  export declare function paramIssues(field: string, decl: ModelParameter[], params: Record<string, unknown>): {
370
323
  path: string;
@@ -372,4 +325,3 @@ export declare function paramIssues(field: string, decl: ModelParameter[], param
372
325
  }[];
373
326
  /** Roster entries an agent may list (spec §4.3), general-purpose included. */
374
327
  export declare const SUBAGENT_ROSTER_MAX = 20;
375
- export {};