@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
@@ -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 {};
@@ -1,8 +1,6 @@
1
1
  import { validateParams } from "@capybara-hq/plugin-sdk";
2
2
  import { z } from "zod";
3
3
  import { AgentAttributionSchema } from "../attribution/platform-attribution.js";
4
- import { isRemovedBuiltinKey } from "../tools/builtin-names.js";
5
- import { isLegacyBuiltinKey, isLegacyPrefixedKey, legacyToolKey, } from "../tools/legacy-keys.js";
6
4
  import { InstructionFilesSchema } from "./instruction-files.js";
7
5
  /** 模型引用:供应商插件名 + 模型 id。 */
8
6
  export const ModelRef = z.object({ provider: z.string(), model: z.string() });
@@ -313,261 +311,13 @@ export const AgentDefinitionSchema = z.object({
313
311
  });
314
312
  const isRecord = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
315
313
  /**
316
- * The connector slugs and extension names `definition` names: connector refs (through
317
- * `scope.connectorSlugById`) and plugin refs of a frozen definition's `tools` or of
318
- * `disabledTools`, and current-format keys of a template's `tools`; `inherited` (the parent
319
- * agent's, for an inline template) is added.
314
+ * A definition read from the database or from a log (not parsed by zod): `disabledTools` and
315
+ * `disabledSkills` default to empty lists (nothing turned off). Other fields are kept.
320
316
  */
321
- function ownRefs(definition, scope, inherited) {
322
- const connectors = new Set(inherited?.connectors);
323
- const extensions = new Set(inherited?.extensions);
324
- const tools = [
325
- ...(Array.isArray(definition.tools) ? definition.tools : []),
326
- ...(Array.isArray(definition.disabledTools) ? definition.disabledTools : []),
327
- ];
328
- for (const r of tools) {
329
- if (typeof r === "string") {
330
- const m = /^(mcp|plugin)__([^_].*?)__./.exec(r);
331
- if (m)
332
- (m[1] === "mcp" ? connectors : extensions).add(m[2]);
333
- }
334
- else if (isRecord(r) && r.kind === "connector" && typeof r.connectorId === "string") {
335
- const slug = scope.connectorSlugById?.get(r.connectorId);
336
- if (slug !== undefined)
337
- connectors.add(slug);
338
- }
339
- else if (isRecord(r) && r.kind === "plugin" && typeof r.plugin === "string") {
340
- extensions.add(r.plugin);
341
- }
342
- }
343
- return { connectors, extensions };
344
- }
345
- /**
346
- * The current key(s) of a stored key. A builtin and an unambiguous `<x>__<tool>` map to one key
347
- * ({@link legacyToolKey}). When `x` is both a connector slug and an extension name, the
348
- * definition's own refs decide (only connector `x` -> `mcp__…`, only extension `x` ->
349
- * `plugin__…`); when they name both or neither, both candidates are returned and the caller
350
- * decides (a policy keeps a deny / ask on both: it must never be lost). Anything else: as is.
351
- */
352
- function currentKeys(key, scope, own) {
353
- const one = legacyToolKey(key, scope);
354
- if (one !== null)
355
- return [one];
356
- if (scope === undefined || !isLegacyPrefixedKey(key))
357
- return [key];
358
- const head = key.slice(0, key.indexOf("__"));
359
- if (!scope.connectorSlugs.has(head) || !scope.extensionNames.has(head))
360
- return [key];
361
- const c = own?.connectors.has(head) === true;
362
- const e = own?.extensions.has(head) === true;
363
- if (c && !e)
364
- return [`mcp__${key}`];
365
- if (e && !c)
366
- return [`plugin__${key}`];
367
- return [`mcp__${key}`, `plugin__${key}`];
368
- }
369
- /**
370
- * A list of tool keys (a template's `tools` / `disallowedTools`) in current keys, deduplicated.
371
- * A still-ambiguous key becomes both candidates in a deny list (`widen`), and stays as is (inert,
372
- * so narrower) in an allowlist.
373
- */
374
- function keyList(v, scope, own, widen) {
375
- if (!Array.isArray(v))
376
- return v;
377
- let changed = false;
378
- const out = [];
379
- for (const x of v) {
380
- let next = [x];
381
- if (typeof x === "string") {
382
- const keys = currentKeys(x, scope, own);
383
- next = keys.length > 1 && !widen ? [x] : keys;
384
- }
385
- if (next.length !== 1 || next[0] !== x)
386
- changed = true;
387
- for (const n of next) {
388
- if (typeof n === "string" && out.includes(n)) {
389
- changed = true;
390
- continue;
391
- }
392
- out.push(n);
393
- }
394
- }
395
- return changed ? out : v;
396
- }
397
- /**
398
- * `toolPolicies` in current keys; keys that become one keep the stricter policy, and a
399
- * still-ambiguous key keeps its `ask` / `deny` on both candidates (anything else is dropped).
400
- */
401
- function policyKeys(v, scope, own) {
402
- if (!isRecord(v))
403
- return v;
404
- const mapped = Object.entries(v).map(([k, p]) => [k, p, currentKeys(k, scope, own)]);
405
- if (mapped.every(([k, , keys]) => keys.length === 1 && keys[0] === k))
406
- return v;
407
- const rank = (p) => (p === "deny" ? 2 : p === "ask" ? 1 : 0);
408
- const out = {};
409
- for (const [, p, keys] of mapped) {
410
- if (keys.length > 1 && rank(p) === 0)
411
- continue;
412
- for (const next of keys) {
413
- if (!Object.hasOwn(out, next) || rank(p) > rank(out[next]))
414
- out[next] = p;
415
- }
416
- }
417
- return out;
418
- }
419
- /**
420
- * A definition's `tools`: a template's allowlist of keys, or the refs of a definition frozen into
421
- * history before tools were on by default (builtin refs by their current names).
422
- */
423
- function toolRefs(v, scope, own) {
424
- if (!Array.isArray(v))
425
- return v;
426
- // template-shaped (`tools: string[]`): an allowlist
427
- if (v.some((x) => typeof x === "string"))
428
- return keyList(v, scope, own, false);
429
- if (!v.some((r) => isRecord(r) &&
430
- r.kind === "builtin" &&
431
- typeof r.name === "string" &&
432
- isLegacyBuiltinKey(r.name))) {
433
- return v;
434
- }
435
- return v.map((r) => isRecord(r) && r.kind === "builtin" && typeof r.name === "string"
436
- ? { ...r, name: legacyToolKey(r.name) ?? r.name }
437
- : r);
438
- }
439
- /**
440
- * Release-candidate tool keys in a stored definition, read as current keys (tool naming spec
441
- * §8.3), the way {@link normalizeToolRef} reads the app -> connector rename: builtin refs in
442
- * `tools`, the keys of `toolPolicies`, and the `tools` / `disallowedTools` / `toolPolicies` of a
443
- * template, the agent's inline sub-agent templates included. Works on an agent definition and on
444
- * an agent template alike. Old builtin names map without `scope`; an rc `<x>__<tool>` key maps
445
- * only with one (the org's connector slugs and their ids, the deployment's extension names). When
446
- * `x` is both a slug and an extension name, the definition's own tool refs decide; when they
447
- * cannot, a policy or a deny list keeps the restriction on both candidate keys (a deny is never
448
- * lost) and an allowlist keeps the old key (inert). An unknown key stays as it is. Keys in the
449
- * current format are never touched. Returns the same object when nothing changes. Saving never
450
- * goes through this: a new definition with an old key is refused (`AgentsService`).
451
- */
452
- export function normalizeToolKeys(definition, scope, inherited) {
453
- if (!isRecord(definition))
454
- return definition;
455
- const own = scope === undefined ? undefined : ownRefs(definition, scope, inherited);
456
- const next = { ...definition };
457
- let changed = false;
458
- const put = (field, value) => {
459
- if (value === definition[field])
460
- return;
461
- next[field] = value;
462
- changed = true;
463
- };
464
- if ("tools" in definition)
465
- put("tools", toolRefs(definition.tools, scope, own));
466
- if ("disallowedTools" in definition) {
467
- put("disallowedTools", keyList(definition.disallowedTools, scope, own, true));
468
- }
469
- if ("toolPolicies" in definition) {
470
- put("toolPolicies", policyKeys(definition.toolPolicies, scope, own));
471
- }
472
- const sub = definition.subagents;
473
- if (isRecord(sub) && Array.isArray(sub.inline)) {
474
- const inline = sub.inline.map((t) => normalizeToolKeys(t, scope, own));
475
- if (inline.some((t, i) => t !== sub.inline[i])) {
476
- put("subagents", { ...sub, inline });
477
- }
478
- }
479
- return changed ? next : definition;
480
- }
481
- /**
482
- * `definition` without the `toolPolicies` keys (its own and its inline sub-agents') of builtins
483
- * that no longer exist ({@link isRemovedBuiltinKey}): applied to a definition being saved, so a
484
- * key left over from a removed builtin never blocks the save. Returns the same object when
485
- * nothing is dropped.
486
- */
487
- export function withoutRemovedBuiltinPolicies(definition) {
488
- const strip = (p) => {
489
- if (p === undefined || !Object.keys(p).some(isRemovedBuiltinKey))
490
- return p;
491
- return Object.fromEntries(Object.entries(p).filter(([k]) => !isRemovedBuiltinKey(k)));
492
- };
493
- let next = definition;
494
- const policies = strip(definition.toolPolicies);
495
- if (policies !== definition.toolPolicies)
496
- next = { ...next, toolPolicies: policies };
497
- const inline = definition.subagents?.inline;
498
- if (inline !== undefined) {
499
- const stripped = inline.map((t) => {
500
- const p = strip(t.toolPolicies);
501
- return p === t.toolPolicies ? t : { ...t, toolPolicies: p };
502
- });
503
- if (stripped.some((t, i) => t !== inline[i])) {
504
- next = { ...next, subagents: { ...definition.subagents, inline: stripped } };
505
- }
506
- }
507
- return next;
508
- }
509
- /**
510
- * Does a stored definition or template hold an rc `<x>__<tool>` key, which only a
511
- * {@link LegacyScope} can map? (Callers load the scope only then.)
512
- */
513
- export function needsLegacyScope(definition) {
514
- if (!isRecord(definition))
515
- return false;
516
- const lists = [definition.tools, definition.disallowedTools];
517
- for (const l of lists) {
518
- if (Array.isArray(l) && l.some((x) => typeof x === "string" && isLegacyPrefixedKey(x))) {
519
- return true;
520
- }
521
- }
522
- if (isRecord(definition.toolPolicies)) {
523
- if (Object.keys(definition.toolPolicies).some(isLegacyPrefixedKey))
524
- return true;
525
- }
526
- const sub = definition.subagents;
527
- return isRecord(sub) && Array.isArray(sub.inline) && sub.inline.some(needsLegacyScope);
528
- }
529
- /**
530
- * A tool ref of a definition frozen into history (logs, eval case snapshots) before tools were on
531
- * by default (tools default-on spec §2): `{ kind: "app", appId }` (before D17) reads as a
532
- * connector ref. Other values are returned as they are.
533
- */
534
- function normalizeToolRef(v) {
535
- if (!isRecord(v) || v.kind !== "app")
536
- return v;
537
- const { kind: _kind, appId, ...rest } = v;
538
- return { kind: "connector", connectorId: appId, ...rest };
539
- }
540
- /**
541
- * A definition read from the database or from history (not parsed by zod): rc tool keys read as
542
- * current keys ({@link normalizeToolKeys}: builtins always, `<x>__<tool>` keys with `scope`), and
543
- * a definition from before tools were on by default (an enabled `tools` list, history only: the
544
- * migration rewrote stored versions) reads as nothing turned off, which is what the migration
545
- * writes (tools default-on spec §2, §3). Likewise a definition from before skills were on by
546
- * default (`skills.orgSkills` / `skills.pinned`) reads as no skill turned off (skills default-on
547
- * spec §4; migration 0116 rewrote stored versions). Other fields are kept; without old forms the
548
- * same object is returned.
549
- */
550
- export function normalizeStoredDefinition(def, scope) {
317
+ export function normalizeStoredDefinition(def) {
551
318
  let d = def;
552
- const tools = d.tools;
553
- if (Array.isArray(tools) && tools.some((t) => isRecord(t) && t.kind === "app")) {
554
- d = { ...d, tools: tools.map(normalizeToolRef) };
555
- }
556
- d = normalizeToolKeys(d, scope);
557
- if ("tools" in d) {
558
- const { tools: _enabled, ...rest } = d;
559
- d = { ...rest, disabledTools: Array.isArray(d.disabledTools) ? d.disabledTools : [] };
560
- }
561
- else if (!Array.isArray(d.disabledTools)) {
319
+ if (!Array.isArray(d.disabledTools))
562
320
  d = { ...d, disabledTools: [] };
563
- }
564
- // before skills were on by default (skills default-on spec §4, §5): selected and pinned skills
565
- // read as nothing turned off, which is what migration 0116 writes
566
- if (isRecord(d.skills) && ("orgSkills" in d.skills || "pinned" in d.skills)) {
567
- const { orgSkills: _o, pinned: _p, ...keep } = d.skills;
568
- const { skills: _s, ...rest } = d;
569
- d = Object.keys(keep).length > 0 ? { ...rest, skills: keep } : rest;
570
- }
571
321
  if (!Array.isArray(d.disabledSkills))
572
322
  d = { ...d, disabledSkills: [] };
573
323
  // an attribution mode other than inherit / custom / off (stored data is not re-validated) reads
@@ -23,12 +23,11 @@ import { TransactionHost } from "../infra/database/transaction-host.js";
23
23
  import { Transactional } from "../infra/database/transactional.decorator.js";
24
24
  import { OrgLock } from "../orgs/org-lock.js";
25
25
  import { builtinSkillIds, builtinSkillPlugins, linkedCopyIds, skillIdsOf, skillVersionsById, usableSkillVersions, } from "../skills/usable.js";
26
- import { isRemovedBuiltinKey } from "../tools/builtin-names.js";
27
26
  import { canonicalJson } from "../tools/canonical-json.js";
28
27
  import { ToolRegistry } from "../tools/registry.js";
29
28
  import { AgentLookup } from "./agent-lookup.js";
30
29
  import { canonicalDisabledSkills, } from "./definition.js";
31
- import { loadTemplates, putTemplateVersionIn, readOwnTemplate, storedTemplate, templateTypeOf, templateViewOf, usableTemplates, } from "./templates.js";
30
+ import { loadTemplates, putTemplateVersionIn, readOwnTemplate, templateTypeOf, templateViewOf, usableTemplates, } from "./templates.js";
32
31
  /**
33
32
  * Roster names no template may take (ruling T4-R15): `general-purpose`, always the roster's first
34
33
  * entry. Claude Code's other built-in types (`Explore`, `Plan`) are capitalized, which the
@@ -268,9 +267,6 @@ extensionTools = []) {
268
267
  // is not carried into it
269
268
  if (v === "allow")
270
269
  continue;
271
- // a removed builtin's policy left in a stored definition is not carried
272
- if (isRemovedBuiltinKey(k))
273
- continue;
274
270
  const parsed = parseToolKey(k);
275
271
  if (parsed !== null && parsed.kind !== "connector" && TOOL_KEY_RE.test(k)) {
276
272
  toolPolicies[k] = v;
@@ -862,7 +858,7 @@ let OrgAgentTemplates = class OrgAgentTemplates {
862
858
  name: own.name,
863
859
  plugin: null,
864
860
  version: row.current_version,
865
- template: storedTemplate(row.definition),
861
+ template: row.definition,
866
862
  sourceFormat: row.source_format,
867
863
  catalogItemId: null,
868
864
  catalogVersion: null,
@@ -3,18 +3,10 @@ import { type OrgContext } from "../orgs/org.guard.js";
3
3
  import { type OrgReadiness, ReadinessService } from "./readiness.service.js";
4
4
  /**
5
5
  * Whether the org can run (`/api/v1/orgs/:orgId/readiness`, web-order spec §3.8): the web app
6
- * decides between the shell and the setup layout with it. `modelProvider` is `ready` when a
7
- * model-provider extension is loaded (enabled and configured), from extension state only, never
8
- * a vendor call; `orgCanAddModel` says whether an org admin can make one usable from the org's
9
- * 扩展 page (switch on a provider the platform offers, or fill its org config) or only the super
10
- * admin can; `agents` is the number of agents the caller can see (the agent list's visibility).
11
- * Humans and service tokens (`org.read`).
12
- *
13
- * `modelProvider` counts the deployment's providers whose effective config is valid in this org
14
- * (spec B §5.5: a provider the platform installed without a key needs each org's own). It is read
15
- * from this replica's provider registry, which follows the per-replica extension reconcile: right
16
- * after a provider is enabled, a replica that has not reconciled yet may still answer `none` for
17
- * a moment.
6
+ * decides between the shell and the setup layout with it ({@link OrgReadiness}: `ready`,
7
+ * `org_fixable` with the providers an org admin can switch on or configure, or `none`; and the
8
+ * agents the caller can see). Computed by {@link ReadinessService}, from extension state only,
9
+ * never a vendor call. Humans and service tokens (`org.read`).
18
10
  */
19
11
  export declare class ReadinessController {
20
12
  private readonly readiness;
@@ -15,18 +15,10 @@ import { ReadinessService } from "./readiness.service.js";
15
15
  const viewerOf = (p) => (p.kind === "user" ? p.account.id : null);
16
16
  /**
17
17
  * Whether the org can run (`/api/v1/orgs/:orgId/readiness`, web-order spec §3.8): the web app
18
- * decides between the shell and the setup layout with it. `modelProvider` is `ready` when a
19
- * model-provider extension is loaded (enabled and configured), from extension state only, never
20
- * a vendor call; `orgCanAddModel` says whether an org admin can make one usable from the org's
21
- * 扩展 page (switch on a provider the platform offers, or fill its org config) or only the super
22
- * admin can; `agents` is the number of agents the caller can see (the agent list's visibility).
23
- * Humans and service tokens (`org.read`).
24
- *
25
- * `modelProvider` counts the deployment's providers whose effective config is valid in this org
26
- * (spec B §5.5: a provider the platform installed without a key needs each org's own). It is read
27
- * from this replica's provider registry, which follows the per-replica extension reconcile: right
28
- * after a provider is enabled, a replica that has not reconciled yet may still answer `none` for
29
- * a moment.
18
+ * decides between the shell and the setup layout with it ({@link OrgReadiness}: `ready`,
19
+ * `org_fixable` with the providers an org admin can switch on or configure, or `none`; and the
20
+ * agents the caller can see). Computed by {@link ReadinessService}, from extension state only,
21
+ * never a vendor call. Humans and service tokens (`org.read`).
30
22
  */
31
23
  let ReadinessController = class ReadinessController {
32
24
  readiness;
@@ -1,24 +1,36 @@
1
1
  import { OrgExtensionConfigs } from "../extensions/org-config.js";
2
2
  import { ProviderRegistry } from "../runtime/providers.js";
3
3
  import { AgentsService } from "./agents.service.js";
4
+ /**
5
+ * A model provider an org admin can make usable on `/settings/models`, and what it waits for:
6
+ * `not_enabled`, the org has not switched it on (it may also need the org's config then);
7
+ * `needs_config`, it is on but waits for the org's own config (an org-level field, or an
8
+ * overridable platform field the platform left empty).
9
+ */
10
+ export interface OrgFixableProvider {
11
+ provider: string;
12
+ reason: "not_enabled" | "needs_config";
13
+ }
4
14
  /** What `GET /orgs/:orgId/readiness` and the `agents.readiness` operation answer. */
5
15
  export interface OrgReadiness {
6
- /** `ready` when a model provider is usable in the org (extension state only, no vendor call). */
7
- modelProvider: "ready" | "none";
8
16
  /**
9
- * Whether an org admin can make a model provider usable from the org's 扩展 page: a provider
10
- * loaded on the deployment that is off in this org (and the org may switch it), or on but
11
- * waiting for the org's own config. False when only the super admin can help (no provider is
12
- * loaded on the deployment). Meaningful while `modelProvider` is `none`.
17
+ * `ready`: a model provider is usable in the org (extension state only, never a vendor call);
18
+ * `org_fixable`: none is, but an org admin can make one usable (`orgFixableProviders`); `none`:
19
+ * only the super admin can help (no provider loaded on the deployment that the org may use).
13
20
  */
14
- orgCanAddModel: boolean;
21
+ modelProvider: "ready" | "org_fixable" | "none";
22
+ /** With `org_fixable`, the providers an org admin can fix here (empty otherwise). */
23
+ orgFixableProviders: OrgFixableProvider[];
15
24
  /** The agents the caller can see (the agent list's visibility). */
16
25
  agents: number;
17
26
  }
18
27
  /**
19
- * Whether the org can run (web-order spec §3.8): the web app decides between the shell and the
20
- * setup layout with it, and the setup checklist sends the viewer to the org's 扩展 page or to the
21
- * admin console by `orgCanAddModel`.
28
+ * Whether the org can run (web-order spec §3.8), the one place it is computed (the readiness
29
+ * route and the `agents.readiness` operation): the web app decides between the shell and the setup
30
+ * layout with it, and the setup checklist sends the org's admins to `/settings/models` while the
31
+ * model step is `org_fixable`. `ready` reads this replica's provider registry (a replica that has
32
+ * not reconciled a just-enabled provider answers otherwise for a moment); the fixable providers
33
+ * come from the org's extension list.
22
34
  */
23
35
  export declare class ReadinessService {
24
36
  private readonly registry;
@@ -26,5 +38,5 @@ export declare class ReadinessService {
26
38
  private readonly agents;
27
39
  constructor(registry: ProviderRegistry, configs: OrgExtensionConfigs, agents: AgentsService);
28
40
  get(orgId: string, viewer: string | null): Promise<OrgReadiness>;
29
- private orgCanAddModel;
41
+ private orgFixable;
30
42
  }