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

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 (309) hide show
  1. package/bootstrap.json +5 -5
  2. package/dist/admin/admin.module.d.ts +3 -3
  3. package/dist/admin/admin.module.js +6 -6
  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/outbox-dead.controller.d.ts +4 -6
  11. package/dist/admin/outbox-dead.controller.js +9 -6
  12. package/dist/admin/outbox-dead.schemas.d.ts +16 -0
  13. package/dist/admin/outbox-dead.schemas.js +25 -1
  14. package/dist/admin/outbox-dead.service.d.ts +16 -7
  15. package/dist/admin/outbox-dead.service.js +34 -10
  16. package/dist/admin/overview.service.d.ts +3 -3
  17. package/dist/admin/overview.service.js +0 -1
  18. package/dist/agents/agent-lookup.js +2 -10
  19. package/dist/agents/agents.service.js +9 -20
  20. package/dist/agents/definition.d.ts +3 -51
  21. package/dist/agents/definition.js +4 -254
  22. package/dist/agents/org-templates.js +2 -6
  23. package/dist/agents/readiness.controller.d.ts +4 -12
  24. package/dist/agents/readiness.controller.js +4 -12
  25. package/dist/agents/readiness.service.d.ts +23 -11
  26. package/dist/agents/readiness.service.js +31 -14
  27. package/dist/agents/templates.d.ts +0 -6
  28. package/dist/agents/templates.js +8 -34
  29. package/dist/background/store.d.ts +2 -0
  30. package/dist/background/store.js +3 -1
  31. package/dist/background/wake-rules.js +2 -1
  32. package/dist/catalog/admin-catalog.controller.d.ts +1 -2
  33. package/dist/catalog/admin-catalog.controller.js +1 -2
  34. package/dist/catalog/appearance.service.js +1 -3
  35. package/dist/catalog/catalog-content.d.ts +1 -1
  36. package/dist/catalog/catalog-content.js +1 -4
  37. package/dist/catalog/catalog-items.js +3 -3
  38. package/dist/catalog/catalog-scope.service.d.ts +10 -28
  39. package/dist/catalog/catalog-scope.service.js +22 -73
  40. package/dist/catalog/cli.d.ts +0 -11
  41. package/dist/catalog/cli.js +0 -20
  42. package/dist/catalog/component-scope.service.js +0 -2
  43. package/dist/catalog/component-state.js +2 -2
  44. package/dist/catalog/install-status.d.ts +6 -0
  45. package/dist/catalog/install-status.js +6 -0
  46. package/dist/catalog/job-ids.d.ts +0 -4
  47. package/dist/catalog/job-ids.js +0 -4
  48. package/dist/catalog/marketplaces.service.d.ts +1 -1
  49. package/dist/catalog/org-catalog.service.d.ts +2 -0
  50. package/dist/catalog/org-catalog.service.js +8 -3
  51. package/dist/catalog/org-extension-switch.d.ts +7 -2
  52. package/dist/catalog/org-extension-switch.js +56 -9
  53. package/dist/catalog/org-plugin-uploads.d.ts +6 -15
  54. package/dist/catalog/org-plugin-uploads.js +9 -27
  55. package/dist/catalog/owned-items.js +1 -3
  56. package/dist/catalog/platform-import-update.js +1 -1
  57. package/dist/catalog/plugin-import.d.ts +15 -13
  58. package/dist/catalog/plugin-import.js +21 -30
  59. package/dist/catalog/plugin-install.d.ts +3 -43
  60. package/dist/catalog/plugin-install.js +8 -150
  61. package/dist/catalog/plugin-package.d.ts +5 -10
  62. package/dist/catalog/plugin-package.js +12 -33
  63. package/dist/catalog/plugin-upgrade.js +5 -4
  64. package/dist/catalog/scope-jobs.d.ts +34 -34
  65. package/dist/catalog/scope-jobs.js +50 -37
  66. package/dist/catalog/scope-orgs.d.ts +1 -1
  67. package/dist/catalog/scope-orgs.js +1 -2
  68. package/dist/catalog/scope-sync-workers.d.ts +4 -3
  69. package/dist/catalog/scope-sync-workers.js +18 -6
  70. package/dist/catalog/scope-sync.d.ts +56 -59
  71. package/dist/catalog/scope-sync.js +96 -166
  72. package/dist/catalog/unshare.d.ts +3 -4
  73. package/dist/catalog/unshare.js +5 -8
  74. package/dist/channels/job-ids.d.ts +2 -6
  75. package/dist/channels/job-ids.js +2 -6
  76. package/dist/channels/outbound.d.ts +1 -1
  77. package/dist/channels/outbound.js +1 -1
  78. package/dist/channels/supervisor.d.ts +2 -3
  79. package/dist/channels/supervisor.js +2 -3
  80. package/dist/client/client-access.service.js +1 -1
  81. package/dist/config/env.js +19 -1
  82. package/dist/config/load.d.ts +0 -6
  83. package/dist/config/load.js +8 -27
  84. package/dist/config/schema.d.ts +53 -47
  85. package/dist/config/schema.js +190 -40
  86. package/dist/conversations/attachments.service.d.ts +10 -3
  87. package/dist/conversations/attachments.service.js +49 -16
  88. package/dist/conversations/conversations.controller.d.ts +0 -39
  89. package/dist/conversations/conversations.controller.js +0 -39
  90. package/dist/conversations/events.d.ts +71 -46
  91. package/dist/conversations/events.js +124 -112
  92. package/dist/conversations/media-types.d.ts +25 -0
  93. package/dist/conversations/media-types.js +38 -0
  94. package/dist/conversations/queue.d.ts +3 -1
  95. package/dist/conversations/queue.service.js +9 -2
  96. package/dist/conversations/titles.js +6 -0
  97. package/dist/ctx/create-ctx.js +1 -2
  98. package/dist/ctx/secrets.d.ts +24 -7
  99. package/dist/ctx/secrets.js +97 -30
  100. package/dist/db/kernel-schema.d.ts +17 -6
  101. package/dist/errors.d.ts +5 -2
  102. package/dist/errors.js +5 -2
  103. package/dist/evals/reconstruct.d.ts +4 -17
  104. package/dist/evals/reconstruct.js +13 -53
  105. package/dist/evals/recorded-tools.d.ts +0 -27
  106. package/dist/evals/recorded-tools.js +2 -92
  107. package/dist/evals/run-replay.d.ts +1 -6
  108. package/dist/evals/run-replay.js +10 -17
  109. package/dist/evals/sets.service.d.ts +17 -5
  110. package/dist/evals/sets.service.js +33 -12
  111. package/dist/evals/snapshot.d.ts +1 -2
  112. package/dist/evals/snapshot.js +4 -17
  113. package/dist/extensions/admin-ops.d.ts +6 -1
  114. package/dist/extensions/admin-ops.js +17 -4
  115. package/dist/extensions/admin-view.d.ts +7 -4
  116. package/dist/extensions/admin-view.js +27 -21
  117. package/dist/extensions/bootstrap.js +0 -1
  118. package/dist/extensions/cli.js +0 -1
  119. package/dist/extensions/host.d.ts +2 -3
  120. package/dist/extensions/host.js +1 -5
  121. package/dist/extensions/installs.d.ts +1 -3
  122. package/dist/extensions/instance.d.ts +0 -2
  123. package/dist/extensions/instance.js +0 -3
  124. package/dist/extensions/org-config.d.ts +4 -4
  125. package/dist/extensions/org-config.js +13 -22
  126. package/dist/extensions/package.d.ts +6 -6
  127. package/dist/extensions/package.js +3 -7
  128. package/dist/extensions/permission-view.d.ts +2 -4
  129. package/dist/extensions/plugin-items.d.ts +21 -1
  130. package/dist/extensions/plugin-items.js +28 -0
  131. package/dist/extensions/sync.js +5 -10
  132. package/dist/extensions/unavailable.js +0 -1
  133. package/dist/http/api.module.js +2 -1
  134. package/dist/identity/audit.d.ts +0 -12
  135. package/dist/identity/audit.js +0 -27
  136. package/dist/identity/auth.controller.js +5 -9
  137. package/dist/identity/cookies.d.ts +4 -9
  138. package/dist/identity/cookies.js +8 -32
  139. package/dist/identity/initial-passwords.d.ts +1 -1
  140. package/dist/identity/initial-passwords.js +1 -2
  141. package/dist/identity/sessions.d.ts +0 -6
  142. package/dist/identity/sessions.js +0 -18
  143. package/dist/inbox/platform-inbox.service.d.ts +33 -1
  144. package/dist/inbox/platform-inbox.service.js +56 -6
  145. package/dist/index.d.ts +4 -2
  146. package/dist/index.js +4 -2
  147. package/dist/infra/cli/master-key-rewrap.d.ts +15 -0
  148. package/dist/infra/cli/master-key-rewrap.js +24 -0
  149. package/dist/infra/config/kernel-config.service.js +0 -17
  150. package/dist/infra/health/health.controller.js +8 -0
  151. package/dist/infra/health/process-fault.d.ts +16 -0
  152. package/dist/infra/health/process-fault.js +49 -0
  153. package/dist/infra/lifecycle/process-guards.d.ts +8 -2
  154. package/dist/infra/lifecycle/process-guards.js +12 -3
  155. package/dist/infra/lifecycle/shutdown-signals.d.ts +10 -1
  156. package/dist/infra/lifecycle/shutdown-signals.js +28 -13
  157. package/dist/infra/outbox/outbox.service.d.ts +12 -9
  158. package/dist/infra/outbox/outbox.service.js +22 -26
  159. package/dist/infra/outbox/registry.d.ts +15 -7
  160. package/dist/infra/outbox/registry.js +39 -23
  161. package/dist/lifecycle/kernel-lifecycle.js +1 -7
  162. package/dist/models/enablement.d.ts +5 -6
  163. package/dist/models/enablement.js +7 -14
  164. package/dist/orgs/orgs.module.d.ts +2 -2
  165. package/dist/orgs/orgs.module.js +2 -2
  166. package/dist/orgs/settings.controller.d.ts +3 -2
  167. package/dist/orgs/settings.service.d.ts +59 -14
  168. package/dist/orgs/settings.service.js +102 -20
  169. package/dist/overrides.d.ts +3 -7
  170. package/dist/overrides.js +2 -4
  171. package/dist/packages/tgz.d.ts +0 -2
  172. package/dist/packages/tgz.js +0 -2
  173. package/dist/platform/exclusions.js +0 -5
  174. package/dist/platform/operation.js +1 -1
  175. package/dist/platform/ops/admin.ops.d.ts +2 -2
  176. package/dist/platform/ops/admin.ops.js +9 -6
  177. package/dist/platform/ops/agents.ops.js +1 -1
  178. package/dist/platform/ops/connectors.ops.js +46 -1
  179. package/dist/platform/ops/evals.ops.js +1 -64
  180. package/dist/platform/ops/extensions-admin.ops.js +1 -1
  181. package/dist/platform/ops/inbox.ops.js +16 -3
  182. package/dist/platform/ops/org-plugins.ops.js +1 -1
  183. package/dist/platform/ops/orgs.ops.d.ts +5 -3
  184. package/dist/platform/ops/orgs.ops.js +19 -4
  185. package/dist/platform/ops/outbox.ops.js +5 -5
  186. package/dist/roles/worker-role.d.ts +2 -3
  187. package/dist/roles/worker-role.js +3 -13
  188. package/dist/runtime/context/build.d.ts +56 -18
  189. package/dist/runtime/context/build.js +143 -50
  190. package/dist/runtime/context/compaction.d.ts +1 -3
  191. package/dist/runtime/context/compaction.js +42 -8
  192. package/dist/runtime/context/run-context.js +1 -2
  193. package/dist/runtime/context/skills.d.ts +27 -56
  194. package/dist/runtime/context/skills.js +42 -114
  195. package/dist/runtime/context/tool-changes.d.ts +3 -3
  196. package/dist/runtime/context/tool-changes.js +6 -16
  197. package/dist/runtime/hook-calls.d.ts +6 -6
  198. package/dist/runtime/hook-calls.js +7 -7
  199. package/dist/runtime/langgraph-loop.js +1 -0
  200. package/dist/runtime/maintenance.d.ts +3 -11
  201. package/dist/runtime/maintenance.js +5 -20
  202. package/dist/runtime/model-call.d.ts +5 -0
  203. package/dist/runtime/model-call.js +48 -36
  204. package/dist/runtime/providers.d.ts +33 -35
  205. package/dist/runtime/providers.js +64 -109
  206. package/dist/runtime/run-context.service.js +7 -22
  207. package/dist/runtime/run-deletion.d.ts +6 -0
  208. package/dist/runtime/run-deletion.js +39 -16
  209. package/dist/runtime/run-execution.js +4 -3
  210. package/dist/runtime/run-finish.js +2 -1
  211. package/dist/runtime/run-liveness.d.ts +11 -0
  212. package/dist/runtime/run-liveness.js +19 -0
  213. package/dist/runtime/run-orphan-check.job.js +2 -1
  214. package/dist/runtime/run-queue.js +8 -16
  215. package/dist/runtime/run-worker.d.ts +2 -2
  216. package/dist/runtime/run-worker.js +8 -6
  217. package/dist/runtime/subagents/definition.d.ts +16 -20
  218. package/dist/runtime/subagents/definition.js +27 -27
  219. package/dist/runtime/subagents/dispatch.d.ts +6 -2
  220. package/dist/runtime/subagents/dispatch.js +17 -3
  221. package/dist/runtime/subagents/org-agents.js +1 -2
  222. package/dist/runtime/subagents/preamble.d.ts +3 -2
  223. package/dist/runtime/subagents/preamble.js +3 -2
  224. package/dist/runtime/subagents/render.d.ts +1 -2
  225. package/dist/runtime/subagents/render.js +1 -2
  226. package/dist/runtime/subagents/skill-fork.d.ts +2 -4
  227. package/dist/runtime/subagents/template-skills.d.ts +47 -0
  228. package/dist/runtime/subagents/template-skills.js +76 -0
  229. package/dist/schedules/effective-settings.d.ts +9 -3
  230. package/dist/schedules/effective-settings.js +5 -4
  231. package/dist/schedules/fire.js +11 -0
  232. package/dist/schedules/scheduled-tasks.service.js +5 -0
  233. package/dist/schedules/unattended.d.ts +2 -0
  234. package/dist/schedules/unattended.js +6 -1
  235. package/dist/skills/agent-skills.service.js +1 -2
  236. package/dist/skills/catalog.d.ts +1 -3
  237. package/dist/skills/catalog.js +1 -3
  238. package/dist/skills/conversation-catalog.d.ts +1 -2
  239. package/dist/skills/conversation-catalog.js +1 -2
  240. package/dist/skills/usable.js +2 -3
  241. package/dist/storage/storage.service.js +9 -1
  242. package/dist/tools/approvals.service.js +2 -4
  243. package/dist/tools/builtin-names.d.ts +2 -9
  244. package/dist/tools/builtin-names.js +4 -13
  245. package/dist/tools/builtins/sandbox/bash.js +3 -3
  246. package/dist/tools/builtins/sandbox/common.d.ts +7 -13
  247. package/dist/tools/builtins/sandbox/common.js +8 -115
  248. package/dist/tools/builtins/sandbox/fetch-attachment.d.ts +10 -0
  249. package/dist/tools/builtins/sandbox/fetch-attachment.js +119 -0
  250. package/dist/tools/builtins/sandbox/glob.js +1 -3
  251. package/dist/tools/builtins/sandbox/grep.js +3 -5
  252. package/dist/tools/builtins/sandbox/index.d.ts +8 -5
  253. package/dist/tools/builtins/sandbox/index.js +10 -5
  254. package/dist/tools/builtins/sandbox/read.js +3 -2
  255. package/dist/tools/builtins/tool-search.d.ts +4 -7
  256. package/dist/tools/builtins/tool-search.js +6 -10
  257. package/dist/tools/connector-account-policies.d.ts +30 -3
  258. package/dist/tools/connector-account-policies.js +54 -7
  259. package/dist/tools/connectors.controller.d.ts +24 -11
  260. package/dist/tools/connectors.controller.js +35 -6
  261. package/dist/tools/connectors.schemas.d.ts +14 -1
  262. package/dist/tools/connectors.schemas.js +14 -2
  263. package/dist/tools/connectors.service.d.ts +22 -0
  264. package/dist/tools/connectors.service.js +56 -0
  265. package/dist/tools/drift.d.ts +1 -1
  266. package/dist/tools/drift.js +1 -1
  267. package/dist/tools/git-push-policy.d.ts +4 -1
  268. package/dist/tools/git-push-policy.js +3 -1
  269. package/dist/tools/info.d.ts +1 -7
  270. package/dist/tools/info.js +5 -18
  271. package/dist/tools/job-ids.d.ts +0 -4
  272. package/dist/tools/job-ids.js +1 -6
  273. package/dist/tools/pipeline.d.ts +4 -10
  274. package/dist/tools/pipeline.js +16 -62
  275. package/dist/tools/policy.d.ts +6 -2
  276. package/dist/tools/policy.js +14 -12
  277. package/dist/tools/registry.js +1 -5
  278. package/dist/ui/views.d.ts +5 -5
  279. package/dist/ui/views.js +10 -16
  280. package/package.json +3 -3
  281. package/src/migrations/0137_audit_org_idx.sql +5 -0
  282. package/src/migrations/0138_plugin_install_status_no_upgrading.sql +18 -0
  283. package/src/migrations/0139_retire_legacy_forms.sql +183 -0
  284. package/src/migrations/0140_retire_history_forms.sql +148 -0
  285. package/src/migrations/0141_install_ledger_promoted_rows.sql +36 -0
  286. package/src/migrations/0142_backfill_event_fields.sql +74 -0
  287. package/src/migrations/0143_backfill_model_call_fields.sql +105 -0
  288. package/src/migrations/0144_retire_frozen_definition_keys.sql +163 -0
  289. package/dist/admin/platform-audit.service.d.ts +0 -41
  290. package/dist/conversations/job-ids.d.ts +0 -6
  291. package/dist/conversations/job-ids.js +0 -6
  292. package/dist/extensions/job-ids.d.ts +0 -6
  293. package/dist/extensions/job-ids.js +0 -6
  294. package/dist/infra/queue/retired-schedulers.d.ts +0 -7
  295. package/dist/infra/queue/retired-schedulers.js +0 -9
  296. package/dist/orgs/job-ids.d.ts +0 -8
  297. package/dist/orgs/job-ids.js +0 -8
  298. package/dist/runtime/context/legacy-text.d.ts +0 -22
  299. package/dist/runtime/context/legacy-text.js +0 -37
  300. package/dist/runtime/job-ids.d.ts +0 -10
  301. package/dist/runtime/job-ids.js +0 -10
  302. package/dist/runtime/retired-schedulers.d.ts +0 -7
  303. package/dist/runtime/retired-schedulers.js +0 -31
  304. package/dist/storage/job-ids.d.ts +0 -6
  305. package/dist/storage/job-ids.js +0 -6
  306. package/dist/tools/legacy-data.d.ts +0 -34
  307. package/dist/tools/legacy-data.js +0 -76
  308. package/dist/tools/legacy-keys.d.ts +0 -51
  309. package/dist/tools/legacy-keys.js +0 -114
@@ -26,13 +26,18 @@ import { IanaTimeZone } from "../time-zone.js";
26
26
  import { mergeArrangement, OrgUiArrangementPatchSchema, UiArrangementSchema, } from "../ui/arrangement.js";
27
27
  import { OrgLock, OrgLockModule } from "./org-lock.js";
28
28
  /**
29
- * 组织设置(`capybara.orgs.settings` jsonb)。读取宽松:缺失或非法的字段按默认值,未知键保留不动
30
- * (更新时与存量合并),新版本加字段不需要迁移。
31
- * - `toolSearch`:工具超过阈值时是否改用目录 + `ToolSearch`(D11,默认 on)。
32
- * - `locale`:组织默认语言(`zh` / `en`,默认 en),机器人在 IM 里说的固定话术按它选择。
33
- * - `sandboxToolPolicy`:沙箱工具的默认策略(M5 T8,默认 allow)。为 `ask` 时除只读的
34
- * `Read` / `Glob` / `Grep` 外都需要审批(执行时实时读取)。
35
- * - `wakeOnBackgroundTask`:组织对 `runtime.wakeOnBackgroundTask` 的覆盖(缺省跟随部署),见 {@link effectiveWakeOnBackgroundTask}。
29
+ * Org settings (`capybara.orgs.settings` jsonb). Read leniently: a missing or invalid field reads
30
+ * as its default and unknown keys are kept (merged with the stored value on update), so a new
31
+ * field needs no migration.
32
+ * - `toolSearch`: whether to switch to a catalog + `ToolSearch` once the tools pass the threshold
33
+ * (D11, default on).
34
+ * - `locale`: the org's default language (`zh` / `en`, default en); the bot's fixed phrases in IM
35
+ * follow it.
36
+ * - `sandboxToolPolicy`: the default policy of the sandbox tools (M5 T8, default allow). With
37
+ * `ask`, every tool but the read-only `Read` / `Glob` / `Grep` needs approval (read live at
38
+ * execution). An invalid stored value reads as `ask` (narrower, never wider) and is logged.
39
+ * - `wakeOnBackgroundTask`: the org's override of `runtime.wakeOnBackgroundTask` (absent follows
40
+ * the deployment), see {@link effectiveWakeOnBackgroundTask}.
36
41
  * - `autoMode`: whether devices of the org may run in auto mode (auto mode spec §4.3); absent
37
42
  * follows the platform's `devices.autoMode`, and an invalid stored value reads as `off`
38
43
  * (narrower, never wider). Setting `allowed` while the platform is `off` is refused.
@@ -118,7 +123,9 @@ const posInt = (max, def) => z.number().int().min(1).max(max).default(def).catch
118
123
  const isForbiddenToolEntry = (v) => typeof v === "string" && v.length >= 1 && v.length <= 200;
119
124
  /**
120
125
  * Org settings of scheduled tasks (spec §9); every field reads leniently (invalid = default,
121
- * except `forbiddenTools`, which keeps its valid entries).
126
+ * except `forbiddenTools`, which keeps its valid entries). A stored `forbiddenTools` that is not a
127
+ * list (or a group that is not an object) reads as `[]` here, for display; enforcement checks
128
+ * {@link invalidStoredForbiddenTools} and fails unattended runs instead (never wider).
122
129
  */
123
130
  export const ScheduledTasksSettingsSchema = z.object({
124
131
  enabled: z.boolean().default(true).catch(true),
@@ -170,7 +177,8 @@ export const GIT_GATEWAY_INVALID = { enabled: false };
170
177
  export const OrgSettingsSchema = z.object({
171
178
  toolSearch: z.enum(["on", "off"]).default("on").catch("on"),
172
179
  locale: z.enum(["zh", "en"]).default("en").catch("en"),
173
- sandboxToolPolicy: z.enum(["allow", "ask"]).default("allow").catch("allow"),
180
+ /** Absent = `allow`; an invalid stored value reads as `ask` (narrower, never wider). */
181
+ sandboxToolPolicy: z.enum(["allow", "ask"]).default("allow").catch("ask"),
174
182
  platformTool: z.enum(["on", "read-only", "off"]).default("on").catch("on"),
175
183
  /** The org's auto-mode switch (auto mode spec §4.3); absent follows the platform. */
176
184
  autoMode: AutoModeSetting.optional().catch("off"),
@@ -194,6 +202,13 @@ export const OrgSettingsSchema = z.object({
194
202
  */
195
203
  compaction: COMPACTION_SETTINGS_PARTIAL.optional().catch(undefined),
196
204
  });
205
+ /** {@link OrgSettingsView} of `settings`, flagged from the stored value `raw`. */
206
+ const viewOf = (settings, raw) => invalidStoredForbiddenTools(raw)
207
+ ? {
208
+ ...settings,
209
+ scheduledTasks: { ...settings.scheduledTasks, forbiddenToolsUnreadable: true },
210
+ }
211
+ : settings;
197
212
  /** PATCH 体:只改给出的字段;未知字段 → 400。 */
198
213
  export const OrgSettingsPatchSchema = z
199
214
  .object({
@@ -259,15 +274,65 @@ const asObject = (v) => v !== null && typeof v === "object" && !Array.isArray(v)
259
274
  export function parseOrgSettings(raw) {
260
275
  return OrgSettingsSchema.parse(asObject(raw));
261
276
  }
262
- /** 读组织设置(每次实时读 PG,多副本下改动立即生效);组织不存在或已删除按默认值。 */
263
- export async function readOrgSettings(db, orgId) {
277
+ /** The org's stored settings jsonb, read live; undefined when the org is missing or deleted. */
278
+ export async function readStoredOrgSettings(db, orgId) {
264
279
  const row = await db
265
280
  .selectFrom("orgs")
266
281
  .select("settings")
267
282
  .where("id", "=", orgId)
268
283
  .where("deleted_at", "is", null)
269
284
  .executeTakeFirst();
270
- return parseOrgSettings(row?.settings);
285
+ return row?.settings;
286
+ }
287
+ /**
288
+ * Reads the org settings (live from PG every time, so a change applies at once across replicas);
289
+ * a missing or deleted org reads as the defaults. With `log`, an
290
+ * unreadable security setting ({@link logUnreadableSecuritySettings}) is logged.
291
+ */
292
+ export async function readOrgSettings(db, orgId,
293
+ /** Per-call paths (the tool policy) log at debug; the settings reads and the fire warn. */
294
+ log) {
295
+ const raw = await readStoredOrgSettings(db, orgId);
296
+ if (log !== undefined) {
297
+ logUnreadableSecuritySettings((msg, f) => log.debug(msg, f), orgId, raw);
298
+ }
299
+ return parseOrgSettings(raw);
300
+ }
301
+ /** Whether a stored settings object holds a `sandboxToolPolicy` this version reads as `ask`. */
302
+ export function invalidStoredSandboxToolPolicy(raw) {
303
+ const v = asObject(raw).sandboxToolPolicy;
304
+ return v !== undefined && !OrgSettingsPatchSchema.shape.sandboxToolPolicy.safeParse(v).success;
305
+ }
306
+ /**
307
+ * Whether the stored scheduled-task `forbiddenTools` cannot be read: the group or the field is
308
+ * present but not an object / a list. Unattended runs of such an org fail
309
+ * ({@link FORBIDDEN_TOOLS_UNREADABLE_ERROR}) rather than run with nothing forbidden. Invalid
310
+ * entries inside a list are dropped instead (the valid ones stay forbidden).
311
+ */
312
+ export function invalidStoredForbiddenTools(raw) {
313
+ const group = asObject(raw).scheduledTasks;
314
+ if (group === undefined)
315
+ return false;
316
+ if (group === null || typeof group !== "object" || Array.isArray(group))
317
+ return true;
318
+ const v = group.forbiddenTools;
319
+ return v !== undefined && !Array.isArray(v);
320
+ }
321
+ /** The refusal of an unattended run of an org whose `forbiddenTools` cannot be read. */
322
+ export const FORBIDDEN_TOOLS_UNREADABLE_ERROR = "The organization's forbidden tool list for scheduled tasks is unreadable, so this scheduled run cannot continue; an org admin must save the list again in the organization's scheduled task settings.";
323
+ /** The refusal of a new task grant while the org's `forbiddenTools` cannot be read. */
324
+ export const FORBIDDEN_TOOLS_UNREADABLE_GRANT_ERROR = "The organization's forbidden tool list for scheduled tasks is unreadable, so no tool can be approved for a task now; an org admin must save the list again in the organization's scheduled task settings.";
325
+ /**
326
+ * Logs (through `log`, at the caller's level) the security settings a stored value reads narrower
327
+ * than written, with the org id.
328
+ */
329
+ export function logUnreadableSecuritySettings(log, orgId, raw) {
330
+ if (invalidStoredSandboxToolPolicy(raw)) {
331
+ log("org settings: stored sandboxToolPolicy is invalid; it reads as ask", { orgId });
332
+ }
333
+ if (invalidStoredForbiddenTools(raw)) {
334
+ log("org settings: stored scheduledTasks.forbiddenTools is unreadable; unattended runs fail until an org admin saves it again", { orgId });
335
+ }
271
336
  }
272
337
  const autoModeNotAllowed = (message) => new ApiError("org.auto_mode_not_allowed", message);
273
338
  /** Whether a stored settings object holds an `autoMode` this version reads as `off`. */
@@ -321,8 +386,9 @@ let OrgSettingsService = class OrgSettingsService {
321
386
  this.config = config;
322
387
  this.log = log;
323
388
  }
324
- /** Parses stored settings, warning when an invalid `autoMode` narrows to `off` or an invalid
325
- * `cloudNetwork` to an empty allowlist. */
389
+ /** Parses stored settings, warning when an invalid `autoMode` narrows to `off`, an invalid
390
+ * `cloudNetwork` to an empty allowlist, or a security setting reads narrower
391
+ * ({@link logUnreadableSecuritySettings}, warn). */
326
392
  parseStored(orgId, raw) {
327
393
  if (invalidStoredAutoMode(raw)) {
328
394
  this.log?.warn("org settings: stored autoMode is invalid; it reads as off", { orgId });
@@ -332,6 +398,9 @@ let OrgSettingsService = class OrgSettingsService {
332
398
  orgId,
333
399
  });
334
400
  }
401
+ const log = this.log;
402
+ if (log !== undefined)
403
+ logUnreadableSecuritySettings((m, f) => log.warn(m, f), orgId, raw);
335
404
  return parseOrgSettings(raw);
336
405
  }
337
406
  /** 部署默认值(设置页展示「跟随部署」时的实际取值)。 */
@@ -384,7 +453,7 @@ let OrgSettingsService = class OrgSettingsService {
384
453
  .executeTakeFirst();
385
454
  if (!row)
386
455
  throw new ApiError("org.not_found", "Organization not found");
387
- return this.parseStored(orgId, row.settings);
456
+ return viewOf(this.parseStored(orgId, row.settings), row.settings);
388
457
  }
389
458
  /**
390
459
  * The refusals of {@link update} that need no read of the org (the Platform tool's precheck):
@@ -518,8 +587,11 @@ let OrgSettingsService = class OrgSettingsService {
518
587
  }
519
588
  if (after.compaction === undefined)
520
589
  delete after.compaction;
521
- if (sameSettings(before, after))
522
- return before;
590
+ // saving an unreadable security setting writes it even when it equals what it read as
591
+ const repairs = (invalidStoredForbiddenTools(stored) && patch.scheduledTasks?.forbiddenTools !== undefined) ||
592
+ (invalidStoredSandboxToolPolicy(stored) && patch.sandboxToolPolicy !== undefined);
593
+ if (!repairs && sameSettings(before, after))
594
+ return viewOf(before, stored);
523
595
  // Lock order: the org row (orgLock above), then the theme's catalog item and its row FOR
524
596
  // SHARE (assertThemeOnIn), then the check, so no scope writer changes what it read first
525
597
  if (patch.theme?.id != null && patch.theme.id !== before.theme?.id) {
@@ -528,9 +600,19 @@ let OrgSettingsService = class OrgSettingsService {
528
600
  // Merge with the stored value: keep the keys this version does not know (a cleared autoMode /
529
601
  // cloudNetwork is not kept)
530
602
  const { autoMode: _oldAutoMode, cloudNetwork: _oldNetwork, wakeOnBackgroundTask: _oldWake, timeZone: _oldZone, theme: _oldTheme, uiArrangement: _oldArrangement, scheduledTasks: _oldScheduled, compaction: _oldCompaction, ...rest } = stored;
603
+ const written = { ...rest, ...after };
604
+ // An unreadable forbiddenTools reads as [] for display only: a write that does not replace the
605
+ // list keeps it unreadable (never healed to "nothing forbidden"); saving the list fixes it
606
+ if (invalidStoredForbiddenTools(stored) && patch.scheduledTasks?.forbiddenTools === undefined) {
607
+ const group = asObject(stored.scheduledTasks);
608
+ written.scheduledTasks = {
609
+ ...after.scheduledTasks,
610
+ forbiddenTools: group.forbiddenTools ?? null,
611
+ };
612
+ }
531
613
  await this.db
532
614
  .updateTable("orgs")
533
- .set({ settings: JSON.stringify({ ...rest, ...after }) })
615
+ .set({ settings: JSON.stringify(written) })
534
616
  .where("id", "=", orgId)
535
617
  .execute();
536
618
  await audit(this.db.db, {
@@ -539,9 +621,9 @@ let OrgSettingsService = class OrgSettingsService {
539
621
  orgId,
540
622
  action: "org.settings_updated",
541
623
  target: orgId,
542
- detail: { before, after, ...auditDetail },
624
+ detail: { before, after, ...(repairs && { repaired: true }), ...auditDetail },
543
625
  });
544
- return after;
626
+ return viewOf(after, written);
545
627
  }
546
628
  };
547
629
  __decorate([
@@ -1,7 +1,7 @@
1
1
  import type { NestInterceptor } from "@nestjs/common";
2
2
  import { APP_INTERCEPTOR } from "@nestjs/core";
3
3
  import { ADMIN_USAGE_TIMINGS, type AdminUsageTimings } from "./admin/usage.service.js";
4
- import { SCOPE_BACKSTOP_DELAY } from "./catalog/scope-jobs.js";
4
+ import { SCOPE_ORG_CHUNK_SIZE } from "./catalog/scope-jobs.js";
5
5
  import { CHANNEL_WEBHOOK_TIMINGS, type ChannelWebhookTimings } from "./channels/webhook.js";
6
6
  import type { EvalReplayHooks } from "./evals/run-replay.js";
7
7
  import { EVAL_REPLAY_HOOKS } from "./evals/worker.js";
@@ -13,7 +13,6 @@ import { GIT_IDENTITY_API_BASE, type GitIdentityApiBase } from "./git/identity.j
13
13
  import { PLUGIN_PUBLIC_WRITE_LIMIT } from "./http/plugin-route-access.js";
14
14
  import { OUTBOX_DISPATCH_FAILS } from "./infra/outbox/outbox.dispatcher.js";
15
15
  import { OUTBOX_FAST_PATH_SETTLED } from "./infra/outbox/outbox.module.js";
16
- import { OUTBOX_STRICT_CONFLICTS } from "./infra/outbox/outbox.service.js";
17
16
  import { PRESENCE_INTERVAL_MS } from "./infra/presence/replica-presence.js";
18
17
  import type { KernelQueueName } from "./infra/queue/queue-names.js";
19
18
  import { DEVICE_POLICY_AFTER_CALL } from "./local-devices/device-policy.service.js";
@@ -46,8 +45,6 @@ import { EMBED_TOKEN_CLOCK } from "./ui/embed-token.js";
46
45
  * `CurrentTime` builtin the time;
47
46
  * - `GIT_IDENTITY_API_BASE`: the API base of a git host for the commit identity (a loopback fake);
48
47
  * - `GIT_UPSTREAM_ORIGIN`: the origin the git gateway relays a git host to (a loopback fake);
49
- * - `OUTBOX_STRICT_CONFLICTS`: a reused outbox job id with different data throws (tests) instead
50
- * of logging an error;
51
48
  * - `OUTBOX_DISPATCH_FAILS`: returns true to make the outbox dispatcher's adds to the given queue
52
49
  * fail (a Redis outage);
53
50
  * - `USAGE_SUBSCRIBERS_CLOCK`: the clock the `usage.report` subscriber cache ages with;
@@ -59,7 +56,7 @@ import { EMBED_TOKEN_CLOCK } from "./ui/embed-token.js";
59
56
  * - `PROJECT_KNOWLEDGE_TIMEOUT`: the run-start read of a bound project's time limit, read at every
60
57
  * read (a test shortens it for one run);
61
58
  * - `PLUGIN_PUBLIC_WRITE_LIMIT`: a lower limit for unsafe methods on `public` extension routes;
62
- * - `SCOPE_BACKSTOP_DELAY`: the delay of a confirmation's scope sync backstop (ruling R24);
59
+ * - `SCOPE_ORG_CHUNK_SIZE`: fewer orgs per plugin scope sync chunk job (several chunks in a test);
63
60
  * - `APP_INTERCEPTOR`: one more global interceptor (a probe of the matched routes).
64
61
  */
65
62
  interface KernelSeams {
@@ -80,12 +77,11 @@ interface KernelSeams {
80
77
  [RUN_CONTEXT_CLOCK]: () => number;
81
78
  [GIT_IDENTITY_API_BASE]: GitIdentityApiBase;
82
79
  [GIT_UPSTREAM_ORIGIN]: GitUpstreamOrigin;
83
- [OUTBOX_STRICT_CONFLICTS]: boolean;
84
80
  [OUTBOX_DISPATCH_FAILS]: (queue: KernelQueueName) => boolean;
85
81
  [USAGE_SUBSCRIBERS_CLOCK]: () => number;
86
82
  [OUTBOX_FAST_PATH_SETTLED]: (pass: Promise<void>) => void;
87
83
  [ENSURE_RUN_FAILS]: () => boolean;
88
- [SCOPE_BACKSTOP_DELAY]: number;
84
+ [SCOPE_ORG_CHUNK_SIZE]: number;
89
85
  [PROJECT_KNOWLEDGE_TIMEOUT]: () => number;
90
86
  [PLUGIN_PUBLIC_WRITE_LIMIT]: number;
91
87
  [DEVICE_POLICY_AFTER_CALL]: (opId: string) => void;
package/dist/overrides.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { APP_INTERCEPTOR } from "@nestjs/core";
2
2
  import { ADMIN_USAGE_TIMINGS } from "./admin/usage.service.js";
3
- import { SCOPE_BACKSTOP_DELAY } from "./catalog/scope-jobs.js";
3
+ import { SCOPE_ORG_CHUNK_SIZE } from "./catalog/scope-jobs.js";
4
4
  import { CHANNEL_WEBHOOK_TIMINGS } from "./channels/webhook.js";
5
5
  import { EVAL_REPLAY_HOOKS } from "./evals/worker.js";
6
6
  import { BOOTSTRAP_LOCK_TTL } from "./extensions/bootstrap.js";
@@ -11,7 +11,6 @@ import { GIT_IDENTITY_API_BASE } from "./git/identity.js";
11
11
  import { PLUGIN_PUBLIC_WRITE_LIMIT } from "./http/plugin-route-access.js";
12
12
  import { OUTBOX_DISPATCH_FAILS } from "./infra/outbox/outbox.dispatcher.js";
13
13
  import { OUTBOX_FAST_PATH_SETTLED } from "./infra/outbox/outbox.module.js";
14
- import { OUTBOX_STRICT_CONFLICTS } from "./infra/outbox/outbox.service.js";
15
14
  import { PRESENCE_INTERVAL_MS } from "./infra/presence/replica-presence.js";
16
15
  import { DEVICE_POLICY_AFTER_CALL } from "./local-devices/device-policy.service.js";
17
16
  import { PROJECT_KNOWLEDGE_TIMEOUT } from "./runtime/project/knowledge.service.js";
@@ -44,11 +43,10 @@ const SEAM_TOKENS = [
44
43
  RUN_CONTEXT_CLOCK,
45
44
  GIT_IDENTITY_API_BASE,
46
45
  GIT_UPSTREAM_ORIGIN,
47
- OUTBOX_STRICT_CONFLICTS,
48
46
  OUTBOX_DISPATCH_FAILS,
49
47
  OUTBOX_FAST_PATH_SETTLED,
50
48
  ENSURE_RUN_FAILS,
51
- SCOPE_BACKSTOP_DELAY,
49
+ SCOPE_ORG_CHUNK_SIZE,
52
50
  PROJECT_KNOWLEDGE_TIMEOUT,
53
51
  PLUGIN_PUBLIC_WRITE_LIMIT,
54
52
  DEVICE_POLICY_AFTER_CALL,
@@ -34,8 +34,6 @@ export declare const PACKAGE_TGZ_LIMITS: {
34
34
  * `syncPackage` links for extensions.
35
35
  */
36
36
  export declare const HOST_ZOD_VERSION: string;
37
- /** The message for a tgz in the pre-0.1.0 format (follows the package's name). */
38
- export declare const LEGACY_FORMAT_MESSAGE = "uses the pre-0.1.0 package format (capybara section / app.yaml); repack it as a plugin with .capybara-plugin/plugin.json (pnpm pack-plugin)";
39
37
  /** `./skills/x` → `skills/x` (manifest paths start with `./`). */
40
38
  export declare const packagePath: (p: string) => string;
41
39
  /** A tgz or `package.json` problem; `issues` lists them (English, shown to the admin). */
@@ -39,8 +39,6 @@ export const PACKAGE_TGZ_LIMITS = {
39
39
  * `syncPackage` links for extensions.
40
40
  */
41
41
  export const HOST_ZOD_VERSION = createRequire(import.meta.url)("zod/package.json").version;
42
- /** The message for a tgz in the pre-0.1.0 format (follows the package's name). */
43
- export const LEGACY_FORMAT_MESSAGE = "uses the pre-0.1.0 package format (capybara section / app.yaml); repack it as a plugin with .capybara-plugin/plugin.json (pnpm pack-plugin)";
44
42
  /** `./skills/x` → `skills/x` (manifest paths start with `./`). */
45
43
  export const packagePath = (p) => p.replace(/^\.\//, "").replace(/\/+$/, "");
46
44
  /** A tgz or `package.json` problem; `issues` lists them (English, shown to the admin). */
@@ -339,11 +339,6 @@ export const PLATFORM_EXCLUSIONS = [
339
339
  category: "internal",
340
340
  reason: "Deprecated message queue the web no longer uses; leftover items drain until the table is dropped",
341
341
  },
342
- {
343
- route: "POST /api/v1/orgs/:orgId/conversations/:id/queue",
344
- category: "internal",
345
- reason: "Deprecated alias of POST messages, which stays with the person",
346
- },
347
342
  {
348
343
  route: "POST /api/v1/orgs/:orgId/conversations/:id/queue/resume",
349
344
  category: "internal",
@@ -49,7 +49,7 @@ export const PLATFORM_DOMAINS = [
49
49
  },
50
50
  {
51
51
  id: "orgs",
52
- description: "This org (read, rename, members) and, for the super admin, every org and its limits.",
52
+ description: "This org (read, rename, members, its audit log) and, for the super admin, every org and its limits.",
53
53
  },
54
54
  {
55
55
  id: "accounts",
@@ -1,7 +1,7 @@
1
1
  import { type OnModuleInit } from "@nestjs/common";
2
+ import { AuditLogService } from "../../admin/audit-log.service.js";
2
3
  import { AdminHealthService } from "../../admin/health.service.js";
3
4
  import { AdminOverviewService } from "../../admin/overview.service.js";
4
- import { PlatformAuditService } from "../../admin/platform-audit.service.js";
5
5
  import { AdminUsageService } from "../../admin/usage.service.js";
6
6
  import { ExtensionDisplayNames } from "../../extensions/display-name.js";
7
7
  import { ExtensionRegistry } from "../../extensions/registry.js";
@@ -32,7 +32,7 @@ export declare class AdminOperations implements OnModuleInit {
32
32
  private readonly overview;
33
33
  private readonly health;
34
34
  private readonly usage;
35
- constructor(registry: PlatformOperations, settings: SettingsService, providers: ProviderRegistry, displayNames: ExtensionDisplayNames, extensionRegistry: ExtensionRegistry, enablement: ModelEnablement, prices: PricesService, purposes: ModelPurposesService, themes: ThemesService, audit: PlatformAuditService, overview: AdminOverviewService, health: AdminHealthService, usage: AdminUsageService);
35
+ constructor(registry: PlatformOperations, settings: SettingsService, providers: ProviderRegistry, displayNames: ExtensionDisplayNames, extensionRegistry: ExtensionRegistry, enablement: ModelEnablement, prices: PricesService, purposes: ModelPurposesService, themes: ThemesService, audit: AuditLogService, overview: AdminOverviewService, health: AdminHealthService, usage: AdminUsageService);
36
36
  private assertProvider;
37
37
  onModuleInit(): void;
38
38
  }
@@ -11,10 +11,10 @@ import { Inject, Injectable } from "@nestjs/common";
11
11
  import { z } from "zod";
12
12
  import { DeploymentSettingsBody, PurposeParams } from "../../admin/admin.schemas.js";
13
13
  import { AuditListQuery } from "../../admin/audit.schemas.js";
14
+ import { AuditLogService } from "../../admin/audit-log.service.js";
14
15
  import { AdminHealthService } from "../../admin/health.service.js";
15
16
  import { UsageQuery } from "../../admin/overview.schemas.js";
16
17
  import { AdminOverviewService } from "../../admin/overview.service.js";
17
- import { PlatformAuditService } from "../../admin/platform-audit.service.js";
18
18
  import { AdminUsageService } from "../../admin/usage.service.js";
19
19
  import { ApiError } from "../../errors.js";
20
20
  import { ExtensionDisplayNames } from "../../extensions/display-name.js";
@@ -154,7 +154,7 @@ let AdminOperations = class AdminOperations {
154
154
  }),
155
155
  defineOperation({
156
156
  id: "admin.attention",
157
- description: "What needs the super admin besides the platform inbox (super admin), one compact row each (kind, id, name, state, reason, next step): extensions (reason config, load_failed, approval, dependency, conflict, converging or legacy_format), platform plugins with a newer marketplace version (reason names both versions) model providers (reason list_failed or no_chat_model) background work the kernel could not queue (kind outbox: how many outbox rows are dead and since when) and run jobs the queue lost (kind queue: Redis lost data; the runs were queued again). Each kind lists at most 20 rows; more counts the rest per kind. unavailable names a kind that could not be read right now (try again later). The platform inbox itself is inbox.platform-list.",
157
+ description: "What needs the super admin besides the platform inbox (super admin), one compact row each (kind, id, name, state, reason, next step): extensions (reason config, load_failed, approval, dependency, conflict, or converging), platform plugins with a newer marketplace version (reason names both versions) model providers (reason list_failed or no_chat_model) background work the kernel could not queue (kind outbox: how many outbox rows are dead and since when) and run jobs the queue lost (kind queue: Redis lost data; the runs were queued again). Each kind lists at most 20 rows; more counts the rest per kind. unavailable names a kind that could not be read right now (try again later). The platform inbox itself is inbox.platform-list.",
158
158
  input: z.object({}).strict(),
159
159
  example: {},
160
160
  authz: { superAdmin: true },
@@ -190,13 +190,16 @@ let AdminOperations = class AdminOperations {
190
190
  }),
191
191
  defineOperation({
192
192
  id: "admin.audit",
193
- description: "The platform-level audit log (super admin), newest first: deployment settings, accounts, marketplaces, catalog imports and scope, extensions, model prices and purposes, setup. Each event has its id, time, actor (id, name, email; null for the kernel itself), viaToken (done with a personal access token), viaAgent (done through the Platform tool), action and target; never the event's details, and never an org's own events. limit is 1 to 100 (default 20); pages by keyset: pass the returned next as params.after (null: no more).",
194
- input: AuditListQuery.strict(),
193
+ description: "The platform-level audit log (super admin), newest first: deployment settings, accounts, marketplaces, catalog imports and scope, extensions, model prices and purposes, setup. Each event has its id, time, actor (id, name, email; null for the kernel itself), viaToken (done with a personal access token), viaAgent (done through the Platform tool), action and target; never the event's details, and never an org's own events (an org's log is orgs.audit, in that org). action filters by an action name or its prefix (e.g. marketplace.). limit is 1 to 100 (default 20); pages by keyset: pass the returned next as params.after (null: no more).",
194
+ // Another org's events are never read through an agent (the conversation's org: orgs.audit).
195
+ // The route's `orgId` query field is left out; parity treats `orgId` as implicit (never an
196
+ // operation field), so it needs no `omits` entry.
197
+ input: AuditListQuery.omit({ orgId: true }).strict(),
195
198
  example: { limit: 20 },
196
199
  authz: { superAdmin: true },
197
200
  mirrors: ["GET /api/v1/admin/audit"],
198
201
  confirm: "read",
199
- run: (input) => this.audit.list(input),
202
+ run: (input) => this.audit.list({ platform: true }, input),
200
203
  }),
201
204
  defineOperation({
202
205
  id: "admin.settings",
@@ -538,7 +541,7 @@ AdminOperations = __decorate([
538
541
  __param(6, Inject(PricesService)),
539
542
  __param(7, Inject(ModelPurposesService)),
540
543
  __param(8, Inject(ThemesService)),
541
- __param(9, Inject(PlatformAuditService)),
544
+ __param(9, Inject(AuditLogService)),
542
545
  __param(10, Inject(AdminOverviewService)),
543
546
  __param(11, Inject(AdminHealthService)),
544
547
  __param(12, Inject(AdminUsageService))
@@ -696,7 +696,7 @@ let AgentsOperations = class AgentsOperations {
696
696
  }),
697
697
  defineOperation({
698
698
  id: "agents.readiness",
699
- description: "Whether the org can run agents: modelProvider is ready when a model provider is available in the org (none otherwise); orgCanAddModel is true when an org admin can make one available on the org's extensions page (switch on a provider the platform offers, or fill its org config), false when only the super admin can; and how many agents you can see.",
699
+ description: "Whether the org can run agents: modelProvider is ready when a model provider is available in the org; org_fixable when an org admin can make one available on Settings > Models (orgFixableProviders names each provider and its reason: not_enabled, switch it on; needs_config, fill the org's config); none when only the super admin can help; and how many agents you can see.",
700
700
  input: z.object({}).strict(),
701
701
  example: {},
702
702
  authz: { orgAction: "org.read" },
@@ -10,7 +10,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
10
10
  import { Inject, Injectable } from "@nestjs/common";
11
11
  import { z } from "zod";
12
12
  import { ComponentScopeService } from "../../catalog/component-scope.service.js";
13
- import { ConnectorPathParams } from "../../tools/connectors.schemas.js";
13
+ import { ConnectorPathParams, GitPushPolicyBody } from "../../tools/connectors.schemas.js";
14
14
  import { ConnectorsService, } from "../../tools/connectors.service.js";
15
15
  import { publicEndpoint } from "../../tools/endpoint.js";
16
16
  import { defineOperation } from "../operation.js";
@@ -19,6 +19,11 @@ import { precheckBy, viaAgent } from "./errors.js";
19
19
  import { Cursor, pageOf, startOf } from "./paging.js";
20
20
  import { named, orElse } from "./summary.js";
21
21
  const PAGE = 50;
22
+ /** `connectors.set-git-push-policy`: the route's path param and body. */
23
+ const SetGitPushPolicyInput = z
24
+ .object({ connectorId: ConnectorPathParams.shape.connectorId.max(100) })
25
+ .extend(GitPushPolicyBody.shape)
26
+ .strict();
22
27
  /**
23
28
  * A connector without anything secret: the auth method and who holds the credential (the org or
24
29
  * each person), never the auth preset's fields or a credential. The endpoint is always the public
@@ -42,6 +47,8 @@ const summary = (c) => ({
42
47
  /** A connector's detail: its tools (name, description, state, default policy) and your credential state. */
43
48
  const detail = (c) => ({
44
49
  ...summary(c),
50
+ // the org's default for git pushes through its credential, when it serves git hosts
51
+ gitPushPolicy: c.git !== null ? c.gitPushPolicy : null,
45
52
  credential: c.credential,
46
53
  tools: c.tools.map((t) => ({
47
54
  name: t.name,
@@ -178,6 +185,44 @@ let ConnectorsOperations = class ConnectorsOperations {
178
185
  return { connector: detail(r.connector), issues: r.issues, changes: r.changes };
179
186
  },
180
187
  }),
188
+ defineOperation({
189
+ id: "connectors.set-git-push-policy",
190
+ description: "Set the org's default for git pushes through a connector's credential in sandboxes (org admins): deny refuses every push, ask asks the person for each repository, allow pushes without asking. Through this tool it may only be tightened (allow to ask or deny, ask to deny); loosening needs a person on the connector's settings page. Only a connector that declares git hosts.",
191
+ input: SetGitPushPolicyInput,
192
+ example: { connectorId: "5d2e8f1a-0b3c-4d5e-8f9a-1b2c3d4e5f60", policy: "deny" },
193
+ authz: { orgAction: "connectors.manage" },
194
+ mirrors: ["PUT /api/v1/orgs/:orgId/connectors/:connectorId/git-push-policy"],
195
+ confirm: "org",
196
+ errors: [
197
+ { code: "connector.not_found", next: "Check the connector id with connectors.list." },
198
+ {
199
+ code: "connector.git_push_widen_not_allowed",
200
+ next: {
201
+ orgAdmin: "Loosen the git push policy yourself on the connector's settings page on the web.",
202
+ member: "Ask an org admin to loosen the git push policy on the connector's settings page on the web.",
203
+ },
204
+ },
205
+ {
206
+ code: "validation_failed",
207
+ next: "The connector declares no git hosts, so it has no git push policy; connectors.get shows gitPushPolicy null for such a connector.",
208
+ },
209
+ ],
210
+ precheck: (i, ctx) => precheckBy(() => this.connectors.checkGitPushPolicy(ctx.orgId, i.connectorId, i.policy, true)),
211
+ summary: async (i, ctx) => {
212
+ const n = await this.connectorName(ctx, i.connectorId);
213
+ const zh = { allow: "允许", ask: "需审批", deny: "禁止" }[i.policy];
214
+ return {
215
+ zh: `把连接器「${n}」的 git 推送默认策略设为「${zh}」`,
216
+ en: `Set the default git push policy of connector "${n}" to ${i.policy}`,
217
+ };
218
+ },
219
+ run: async (input, ctx) => ({
220
+ connector: detail(await this.connectors.setGitPushPolicy(ctx.orgId, input.connectorId, ctx.actorAccountId, input.policy, {
221
+ auditDetail: viaAgent("connectors.set-git-push-policy", ctx),
222
+ onlyNarrows: true,
223
+ })),
224
+ }),
225
+ }),
181
226
  ]);
182
227
  }
183
228
  };
@@ -313,70 +313,7 @@ let EvalsOperations = class EvalsOperations {
313
313
  },
314
314
  ],
315
315
  precheck: async (i, ctx) => {
316
- const found = await this.setCheck(ctx, i.setId);
317
- if (!found.ok)
318
- return found;
319
- const set = await this.sets.get(ctx.orgId, i.setId);
320
- const conv = await this.kdb.db
321
- .selectFrom("conversations")
322
- .select(["agent_id", "kind"])
323
- .where("id", "=", i.conversationId)
324
- .where("org_id", "=", ctx.orgId)
325
- .executeTakeFirst();
326
- if (conv?.kind !== "chat" && conv?.kind !== "subagent") {
327
- return {
328
- ok: false,
329
- code: "conversation.not_found",
330
- message: "Conversation or run not found",
331
- };
332
- }
333
- const sets = await this.kdb.db
334
- .selectFrom("eval_sets")
335
- .select("agent_id")
336
- .where("id", "=", i.setId)
337
- .executeTakeFirstOrThrow();
338
- if (conv.agent_id !== sets.agent_id) {
339
- return {
340
- ok: false,
341
- code: "eval.agent_mismatch",
342
- message: "The run belongs to a different agent",
343
- };
344
- }
345
- if (set.cases.some((c) => c.sourceRunId === i.runId)) {
346
- return {
347
- ok: false,
348
- code: "eval.case_exists",
349
- message: "That run is already a case of the eval set",
350
- };
351
- }
352
- const run = await this.kdb.db
353
- .selectFrom("runs")
354
- .select(["status", "compact"])
355
- .where("id", "=", i.runId)
356
- .where("conversation_id", "=", i.conversationId)
357
- .executeTakeFirst();
358
- if (run === undefined) {
359
- return {
360
- ok: false,
361
- code: "conversation.not_found",
362
- message: "Conversation or run not found",
363
- };
364
- }
365
- if (run.compact) {
366
- return {
367
- ok: false,
368
- code: "eval.compact_not_replayable",
369
- message: "A manual compaction run has no model step to replay",
370
- };
371
- }
372
- if (run.status === "running" || run.status === "queued") {
373
- return {
374
- ok: false,
375
- code: "eval.run_not_finished",
376
- message: "The run has not finished yet",
377
- };
378
- }
379
- return this.roomCheck(ctx, i.setId);
316
+ return precheckBy(() => this.sets.checkAddCase(ctx.orgId, i.setId, i));
380
317
  },
381
318
  summary: async (i, ctx) => {
382
319
  const n = await this.setName(ctx, i.setId);
@@ -132,7 +132,7 @@ let ExtensionsAdminOperations = class ExtensionsAdminOperations {
132
132
  this.registry.register([
133
133
  defineOperation({
134
134
  id: "extensions.platform-list",
135
- description: "List the extensions on the platform (super admin), one compact row each: the deployment status (enabled, disabled, pending_approval, pending_config, pending_migration, converging, failed, dependency, conflict, legacy_format), why one does not run (reason) and your next step (next), its version, how many orgs have it on and whether it is required. Extensions only other orgs' own plugins bring are counted (otherOrgExtensions), never listed. Details come from extensions.platform-get. Pages by 50: pass the returned next as params.cursor.",
135
+ description: "List the extensions on the platform (super admin), one compact row each: the deployment status (enabled, disabled, pending_approval, pending_config, pending_migration, converging, failed, dependency, conflict), why one does not run (reason) and your next step (next), its version, how many orgs have it on and whether it is required. Extensions only other orgs' own plugins bring are counted (otherOrgExtensions), never listed. Details come from extensions.platform-get. Pages by 50: pass the returned next as params.cursor.",
136
136
  input: z.object({ cursor: Cursor.optional() }).strict(),
137
137
  example: {},
138
138
  authz: { superAdmin: true },
@@ -180,6 +180,16 @@ function platformRow(i) {
180
180
  next: "Open the plugin in the admin console to see the error and retry.",
181
181
  };
182
182
  }
183
+ case "extension_disabled": {
184
+ const d = i.disabled;
185
+ return {
186
+ ...base,
187
+ name: d.item.name,
188
+ state: "disabled",
189
+ summary: `Plugin ${d.item.name} is on by its scope, but its extension ${d.extension.name} ${d.extension.version} is disabled on the deployment, so it is installed in no org that lacks it.`,
190
+ next: "Enable the extension in the admin console (or disable another provider of its single-provider extension point first); the enable syncs the plugin's scope.",
191
+ };
192
+ }
183
193
  case "ownership_transferred":
184
194
  return {
185
195
  ...base,
@@ -307,7 +317,7 @@ let InboxOperations = class InboxOperations {
307
317
  }),
308
318
  defineOperation({
309
319
  id: "inbox.platform-list",
310
- description: "List the platform inbox (super admin), newest first, one compact row each (type, what, state, summary, next step): orgs' requests to the platform, plugins waiting for a permission confirmation, this org's uploads waiting for you, failed scope syncs and ownership notices. Only the newest 100 items are read (truncated: more wait); listed is how many of them are shown, otherOrgItems how many are items of plugins other orgs own (only counted). total counts everything waiting on the platform, other orgs' items included, as the admin console does; byType splits total by type (everything waiting, not the listed page). Nothing is decided here: requests and confirmations are done in the admin console. Pages by 50: pass the returned next as params.cursor.",
320
+ description: "List the platform inbox (super admin), newest first, one compact row each (type, what, state, summary, next step): orgs' requests to the platform, plugins waiting for a permission confirmation, this org's uploads waiting for you, failed scope syncs, plugins on by scope whose extension is disabled, and ownership notices. Only the newest 100 items are read (truncated: more wait); listed is how many of them are shown, otherOrgItems how many are items of plugins other orgs own (only counted). total counts everything waiting on the platform, other orgs' items included, as the admin console does; byType splits total by type (everything waiting, not the listed page). Nothing is decided here: requests and confirmations are done in the admin console. Pages by 50: pass the returned next as params.cursor.",
311
321
  input: z.object({ cursor: Cursor.optional() }).strict(),
312
322
  example: {},
313
323
  authz: { superAdmin: true },
@@ -320,7 +330,9 @@ let InboxOperations = class InboxOperations {
320
330
  ? [i.item.id]
321
331
  : i.type === "scope_sync_failed"
322
332
  ? [i.failure.item.id]
323
- : []);
333
+ : i.type === "extension_disabled"
334
+ ? [i.disabled.item.id]
335
+ : []);
324
336
  const owners = await this.owners(itemIds);
325
337
  const theirs = (itemId) => {
326
338
  const o = owners.get(itemId);
@@ -328,7 +340,8 @@ let InboxOperations = class InboxOperations {
328
340
  };
329
341
  const shown = view.items.filter((i) => !(((i.type === "org_upload_pending" || i.type === "permission_confirmation") &&
330
342
  theirs(i.item.id)) ||
331
- (i.type === "scope_sync_failed" && theirs(i.failure.item.id))));
343
+ (i.type === "scope_sync_failed" && theirs(i.failure.item.id)) ||
344
+ (i.type === "extension_disabled" && theirs(i.disabled.item.id))));
332
345
  const page = pageOf(shown.map(platformRow), startOf(input.cursor), 50);
333
346
  // total is the console's count of everything waiting (other orgs' items included): when
334
347
  // the inbox is truncated the items past the newest 100 cannot be told apart, so the
@@ -101,7 +101,7 @@ let OrgPluginsOperations = class OrgPluginsOperations {
101
101
  this.registry.register([
102
102
  defineOperation({
103
103
  id: "plugins.installs",
104
- description: "List the plugin installs of this org (org admins), one compact row each: the plugin, the install state (installing, installed, failed, uninstalling, upgrading), a failure's step and code (reason), the version and how many components it brought. Pages by 50: pass the returned next as params.cursor.",
104
+ description: "List the plugin installs of this org (org admins), one compact row each: the plugin, the install state (installing, installed, failed, uninstalling), a failure's step and code (reason), the version and how many components it brought. Pages by 50: pass the returned next as params.cursor.",
105
105
  input: z.object({ cursor: Cursor.optional() }).strict(),
106
106
  example: {},
107
107
  authz: { orgAction: "org.extensions.manage" },