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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (362) hide show
  1. package/bootstrap.json +27 -3
  2. package/dist/admin/admin.controller.d.ts +21 -74
  3. package/dist/admin/admin.controller.js +50 -50
  4. package/dist/admin/admin.schemas.d.ts +57 -0
  5. package/dist/admin/admin.schemas.js +50 -0
  6. package/dist/admin/extensions.controller.d.ts +10 -0
  7. package/dist/admin/extensions.controller.js +18 -0
  8. package/dist/admin/extensions.schemas.d.ts +7 -0
  9. package/dist/admin/extensions.schemas.js +10 -0
  10. package/dist/admin/limit-defaults.d.ts +20 -0
  11. package/dist/admin/limit-defaults.js +10 -0
  12. package/dist/agents/agent-profile.service.d.ts +7 -5
  13. package/dist/agents/agent-profile.service.js +14 -9
  14. package/dist/agents/agents.controller.d.ts +7 -287
  15. package/dist/agents/agents.controller.js +7 -67
  16. package/dist/agents/agents.schemas.d.ts +389 -0
  17. package/dist/agents/agents.schemas.js +126 -0
  18. package/dist/agents/agents.service.d.ts +16 -6
  19. package/dist/agents/agents.service.js +75 -19
  20. package/dist/agents/definition.d.ts +47 -19
  21. package/dist/agents/definition.js +119 -38
  22. package/dist/agents/from-template.d.ts +2 -2
  23. package/dist/agents/from-template.js +76 -45
  24. package/dist/agents/from-template.service.d.ts +12 -0
  25. package/dist/agents/from-template.service.js +23 -6
  26. package/dist/agents/models.controller.d.ts +33 -5
  27. package/dist/agents/models.controller.js +50 -6
  28. package/dist/agents/org-templates.d.ts +13 -3
  29. package/dist/agents/org-templates.js +69 -28
  30. package/dist/agents/pending-connector-requests.d.ts +2 -0
  31. package/dist/agents/pending-connector-requests.js +1 -1
  32. package/dist/agents/pending-connectors.controller.d.ts +1 -1
  33. package/dist/agents/pending-connectors.controller.js +2 -2
  34. package/dist/agents/pending-connectors.service.d.ts +2 -2
  35. package/dist/agents/pending-connectors.service.js +19 -19
  36. package/dist/agents/profile.d.ts +18 -0
  37. package/dist/agents/profile.js +5 -1
  38. package/dist/agents/readiness.controller.d.ts +5 -5
  39. package/dist/agents/readiness.controller.js +6 -6
  40. package/dist/agents/templates.controller.d.ts +8 -17
  41. package/dist/agents/templates.controller.js +13 -31
  42. package/dist/agents/templates.schemas.d.ts +20 -0
  43. package/dist/agents/templates.schemas.js +45 -0
  44. package/dist/background/background.controller.js +3 -2
  45. package/dist/background/background.schemas.d.ts +10 -0
  46. package/dist/background/background.schemas.js +16 -0
  47. package/dist/background/tasks.service.d.ts +1 -1
  48. package/dist/background/tasks.service.js +7 -2
  49. package/dist/catalog/admin-catalog.controller.d.ts +4 -57
  50. package/dist/catalog/admin-catalog.controller.js +8 -45
  51. package/dist/catalog/admin-catalog.schemas.d.ts +72 -0
  52. package/dist/catalog/admin-catalog.schemas.js +92 -0
  53. package/dist/catalog/catalog-content.d.ts +12 -2
  54. package/dist/catalog/catalog-scope.service.js +8 -2
  55. package/dist/catalog/catalog.service.d.ts +2 -0
  56. package/dist/catalog/catalog.service.js +3 -0
  57. package/dist/catalog/component-scope.controller.d.ts +3 -65
  58. package/dist/catalog/component-scope.controller.js +3 -56
  59. package/dist/catalog/component-scope.schemas.d.ts +114 -0
  60. package/dist/catalog/component-scope.schemas.js +97 -0
  61. package/dist/catalog/component-scope.service.d.ts +28 -4
  62. package/dist/catalog/component-scope.service.js +55 -3
  63. package/dist/catalog/component-state.d.ts +9 -2
  64. package/dist/catalog/component-state.js +22 -13
  65. package/dist/catalog/marketplaces.controller.d.ts +5 -35
  66. package/dist/catalog/marketplaces.controller.js +6 -34
  67. package/dist/catalog/marketplaces.schemas.d.ts +48 -0
  68. package/dist/catalog/marketplaces.schemas.js +53 -0
  69. package/dist/catalog/marketplaces.service.d.ts +15 -1
  70. package/dist/catalog/marketplaces.service.js +22 -1
  71. package/dist/catalog/org-catalog.controller.d.ts +6 -62
  72. package/dist/catalog/org-catalog.controller.js +12 -66
  73. package/dist/catalog/org-catalog.schemas.d.ts +79 -0
  74. package/dist/catalog/org-catalog.schemas.js +82 -0
  75. package/dist/catalog/org-catalog.service.d.ts +9 -2
  76. package/dist/catalog/org-catalog.service.js +38 -5
  77. package/dist/catalog/org-extension.controller.d.ts +1 -12
  78. package/dist/catalog/org-extension.controller.js +1 -10
  79. package/dist/catalog/org-extension.schemas.d.ts +15 -0
  80. package/dist/catalog/org-extension.schemas.js +22 -0
  81. package/dist/catalog/org-plugin-uploads.controller.d.ts +2 -19
  82. package/dist/catalog/org-plugin-uploads.controller.js +15 -28
  83. package/dist/catalog/org-plugin-uploads.schemas.d.ts +20 -0
  84. package/dist/catalog/org-plugin-uploads.schemas.js +32 -0
  85. package/dist/catalog/owned-items.d.ts +6 -2
  86. package/dist/catalog/owned-items.js +16 -4
  87. package/dist/catalog/platform-components.d.ts +2 -0
  88. package/dist/catalog/platform-components.js +2 -0
  89. package/dist/catalog/plugin-import.js +1 -0
  90. package/dist/catalog/plugin-install.js +1 -1
  91. package/dist/catalog/requests.service.d.ts +2 -1
  92. package/dist/catalog/requests.service.js +6 -2
  93. package/dist/channels/channels.schemas.d.ts +33 -0
  94. package/dist/channels/channels.schemas.js +34 -0
  95. package/dist/channels/connections.controller.d.ts +2 -29
  96. package/dist/channels/connections.controller.js +1 -23
  97. package/dist/channels/connections.service.d.ts +8 -2
  98. package/dist/channels/connections.service.js +23 -5
  99. package/dist/channels/inbound.js +4 -0
  100. package/dist/config/schema.d.ts +4 -0
  101. package/dist/config/schema.js +24 -0
  102. package/dist/conversations/conversations.controller.d.ts +16 -37
  103. package/dist/conversations/conversations.controller.js +16 -56
  104. package/dist/conversations/conversations.schemas.d.ts +52 -0
  105. package/dist/conversations/conversations.schemas.js +79 -0
  106. package/dist/conversations/conversations.service.d.ts +13 -4
  107. package/dist/conversations/conversations.service.js +32 -26
  108. package/dist/conversations/events.d.ts +80 -6
  109. package/dist/conversations/events.js +60 -5
  110. package/dist/conversations/message-context.d.ts +28 -0
  111. package/dist/conversations/message-context.js +56 -0
  112. package/dist/conversations/queue.d.ts +2 -1
  113. package/dist/conversations/queue.js +11 -2
  114. package/dist/ctx/create-ctx.d.ts +15 -1
  115. package/dist/ctx/create-ctx.js +23 -2
  116. package/dist/db/kernel-schema.d.ts +44 -0
  117. package/dist/environments/environments.schemas.d.ts +3 -0
  118. package/dist/environments/environments.schemas.js +14 -0
  119. package/dist/environments/environments.service.d.ts +16 -4
  120. package/dist/environments/environments.service.js +58 -13
  121. package/dist/errors.d.ts +6 -0
  122. package/dist/errors.js +6 -0
  123. package/dist/evals/evals.schemas.d.ts +110 -0
  124. package/dist/evals/evals.schemas.js +107 -0
  125. package/dist/evals/reconstruct.js +18 -11
  126. package/dist/evals/recorded-tools.d.ts +2 -1
  127. package/dist/evals/recorded-tools.js +11 -3
  128. package/dist/evals/run-replay.d.ts +8 -1
  129. package/dist/evals/run-replay.js +17 -2
  130. package/dist/evals/runs.controller.d.ts +2 -57
  131. package/dist/evals/runs.controller.js +1 -42
  132. package/dist/evals/runs.service.d.ts +8 -7
  133. package/dist/evals/runs.service.js +45 -30
  134. package/dist/evals/sets.controller.d.ts +2 -28
  135. package/dist/evals/sets.controller.js +1 -31
  136. package/dist/evals/sets.service.d.ts +7 -7
  137. package/dist/evals/sets.service.js +23 -17
  138. package/dist/evals/snapshot.d.ts +3 -2
  139. package/dist/evals/snapshot.js +17 -4
  140. package/dist/evals/step-replay.d.ts +2 -1
  141. package/dist/evals/step-replay.js +3 -2
  142. package/dist/extensions/admin-ops.d.ts +5 -3
  143. package/dist/extensions/admin-ops.js +17 -12
  144. package/dist/extensions/config-hash.d.ts +10 -0
  145. package/dist/extensions/config-hash.js +38 -0
  146. package/dist/extensions/deployment-config.d.ts +16 -1
  147. package/dist/extensions/deployment-config.js +83 -0
  148. package/dist/extensions/extensions.module.js +9 -12
  149. package/dist/extensions/host.d.ts +39 -12
  150. package/dist/extensions/host.js +129 -51
  151. package/dist/extensions/installs.d.ts +5 -0
  152. package/dist/extensions/installs.js +12 -0
  153. package/dist/extensions/org-config.d.ts +17 -2
  154. package/dist/extensions/org-config.js +23 -4
  155. package/dist/extensions/point-defaults.controller.d.ts +2 -8
  156. package/dist/extensions/point-defaults.controller.js +1 -3
  157. package/dist/extensions/point-defaults.d.ts +3 -1
  158. package/dist/extensions/point-defaults.js +4 -2
  159. package/dist/extensions/point-defaults.schemas.d.ts +9 -0
  160. package/dist/extensions/point-defaults.schemas.js +14 -0
  161. package/dist/extensions/state.module.d.ts +9 -0
  162. package/dist/extensions/state.module.js +38 -0
  163. package/dist/extensions/unavailable.d.ts +49 -0
  164. package/dist/extensions/unavailable.js +113 -0
  165. package/dist/files/previewers.controller.js +2 -3
  166. package/dist/files/previewers.d.ts +1 -1
  167. package/dist/files/previewers.js +4 -4
  168. package/dist/files/previewers.schemas.d.ts +10 -0
  169. package/dist/files/previewers.schemas.js +9 -0
  170. package/dist/http/api.module.js +4 -0
  171. package/dist/http/plugin-dispatch.d.ts +4 -1
  172. package/dist/http/plugin-dispatch.js +14 -2
  173. package/dist/identity/accounts.d.ts +43 -4
  174. package/dist/identity/accounts.js +74 -6
  175. package/dist/identity/auth.guard.js +10 -1
  176. package/dist/identity/cookies.d.ts +6 -0
  177. package/dist/identity/cookies.js +14 -0
  178. package/dist/identity/identity.module.js +3 -0
  179. package/dist/identity/initial-passwords.controller.d.ts +22 -0
  180. package/dist/identity/initial-passwords.controller.js +49 -0
  181. package/dist/identity/initial-passwords.d.ts +61 -0
  182. package/dist/identity/initial-passwords.job.d.ts +16 -0
  183. package/dist/identity/initial-passwords.job.js +46 -0
  184. package/dist/identity/initial-passwords.js +159 -0
  185. package/dist/identity/me.controller.d.ts +14 -0
  186. package/dist/identity/me.controller.js +39 -1
  187. package/dist/identity/principal.d.ts +8 -0
  188. package/dist/identity/principal.js +8 -0
  189. package/dist/identity/settings.d.ts +3 -1
  190. package/dist/identity/settings.js +6 -4
  191. package/dist/inbox/inbox.schemas.d.ts +8 -0
  192. package/dist/inbox/inbox.schemas.js +11 -0
  193. package/dist/inbox/platform-inbox.controller.d.ts +1 -1
  194. package/dist/inbox/platform-inbox.controller.js +2 -2
  195. package/dist/index.d.ts +4 -0
  196. package/dist/index.js +6 -0
  197. package/dist/infra/config/kernel-config.service.js +3 -0
  198. package/dist/infra/events/kernel-events.d.ts +8 -0
  199. package/dist/lifecycle/kernel-lifecycle.js +4 -0
  200. package/dist/models/embeddings.d.ts +82 -0
  201. package/dist/models/embeddings.js +326 -0
  202. package/dist/models/enablement.controller.d.ts +40 -0
  203. package/dist/models/enablement.controller.js +74 -0
  204. package/dist/models/enablement.d.ts +101 -0
  205. package/dist/models/enablement.js +264 -0
  206. package/dist/models/models.module.d.ts +5 -1
  207. package/dist/models/models.module.js +16 -4
  208. package/dist/models/org-models.schemas.d.ts +8 -0
  209. package/dist/models/org-models.schemas.js +22 -0
  210. package/dist/models/prices.d.ts +3 -1
  211. package/dist/models/prices.js +7 -5
  212. package/dist/models/purposes.d.ts +30 -6
  213. package/dist/models/purposes.js +68 -17
  214. package/dist/orgs/orgs.controller.d.ts +2 -5
  215. package/dist/orgs/orgs.controller.js +3 -6
  216. package/dist/orgs/orgs.schemas.d.ts +8 -0
  217. package/dist/orgs/orgs.schemas.js +16 -0
  218. package/dist/orgs/orgs.service.d.ts +3 -1
  219. package/dist/orgs/orgs.service.js +6 -4
  220. package/dist/orgs/settings.service.d.ts +9 -1
  221. package/dist/orgs/settings.service.js +20 -5
  222. package/dist/overrides.d.ts +4 -0
  223. package/dist/overrides.js +2 -0
  224. package/dist/platform/errors.d.ts +21 -4
  225. package/dist/platform/errors.js +45 -6
  226. package/dist/platform/exclusions.d.ts +2 -3
  227. package/dist/platform/exclusions.js +68 -831
  228. package/dist/platform/method.js +1 -1
  229. package/dist/platform/operation.d.ts +82 -5
  230. package/dist/platform/operation.js +62 -7
  231. package/dist/platform/ops/accounts.ops.d.ts +32 -0
  232. package/dist/platform/ops/accounts.ops.js +291 -0
  233. package/dist/platform/ops/admin.ops.d.ts +36 -0
  234. package/dist/platform/ops/admin.ops.js +389 -0
  235. package/dist/platform/ops/agent-skills.ops.d.ts +24 -0
  236. package/dist/platform/ops/agent-skills.ops.js +226 -0
  237. package/dist/platform/ops/agent-templates.ops.d.ts +4 -1
  238. package/dist/platform/ops/agent-templates.ops.js +194 -14
  239. package/dist/platform/ops/agents.ops.d.ts +19 -1
  240. package/dist/platform/ops/agents.ops.js +481 -58
  241. package/dist/platform/ops/approvals.ops.d.ts +30 -0
  242. package/dist/platform/ops/approvals.ops.js +116 -0
  243. package/dist/platform/ops/background.ops.d.ts +14 -0
  244. package/dist/platform/ops/background.ops.js +134 -0
  245. package/dist/platform/ops/catalog-admin.ops.d.ts +74 -0
  246. package/dist/platform/ops/catalog-admin.ops.js +587 -0
  247. package/dist/platform/ops/channels.ops.d.ts +16 -0
  248. package/dist/platform/ops/channels.ops.js +195 -0
  249. package/dist/platform/ops/components.ops.d.ts +46 -0
  250. package/dist/platform/ops/components.ops.js +853 -0
  251. package/dist/platform/ops/connectors.ops.d.ts +4 -2
  252. package/dist/platform/ops/connectors.ops.js +68 -6
  253. package/dist/platform/ops/conversations.ops.d.ts +30 -0
  254. package/dist/platform/ops/conversations.ops.js +470 -0
  255. package/dist/platform/ops/environments.ops.d.ts +26 -0
  256. package/dist/platform/ops/environments.ops.js +289 -0
  257. package/dist/platform/ops/errors.d.ts +10 -5
  258. package/dist/platform/ops/errors.js +19 -11
  259. package/dist/platform/ops/evals.ops.d.ts +28 -0
  260. package/dist/platform/ops/evals.ops.js +783 -0
  261. package/dist/platform/ops/extensions-admin.ops.d.ts +25 -0
  262. package/dist/platform/ops/extensions-admin.ops.js +344 -0
  263. package/dist/platform/ops/extensions.ops.d.ts +7 -1
  264. package/dist/platform/ops/extensions.ops.js +248 -17
  265. package/dist/platform/ops/inbox.ops.d.ts +25 -0
  266. package/dist/platform/ops/inbox.ops.js +378 -0
  267. package/dist/platform/ops/marketplaces.ops.d.ts +7 -1
  268. package/dist/platform/ops/marketplaces.ops.js +326 -17
  269. package/dist/platform/ops/models.ops.d.ts +25 -0
  270. package/dist/platform/ops/models.ops.js +232 -0
  271. package/dist/platform/ops/org-plugins.ops.d.ts +29 -0
  272. package/dist/platform/ops/org-plugins.ops.js +329 -0
  273. package/dist/platform/ops/org-settings.ops.d.ts +16 -0
  274. package/dist/platform/ops/org-settings.ops.js +102 -0
  275. package/dist/platform/ops/orgs.ops.d.ts +28 -0
  276. package/dist/platform/ops/orgs.ops.js +295 -0
  277. package/dist/platform/ops/other-orgs.d.ts +20 -0
  278. package/dist/platform/ops/other-orgs.js +72 -0
  279. package/dist/platform/ops/platform.ops.d.ts +4 -4
  280. package/dist/platform/ops/platform.ops.js +23 -24
  281. package/dist/platform/ops/plugins.ops.d.ts +10 -8
  282. package/dist/platform/ops/plugins.ops.js +176 -77
  283. package/dist/platform/ops/previewers.ops.d.ts +14 -0
  284. package/dist/platform/ops/previewers.ops.js +109 -0
  285. package/dist/platform/ops/requests.ops.js +57 -19
  286. package/dist/platform/ops/skills.ops.d.ts +5 -1
  287. package/dist/platform/ops/skills.ops.js +129 -11
  288. package/dist/platform/ops/unavailable.d.ts +23 -0
  289. package/dist/platform/ops/unavailable.js +111 -0
  290. package/dist/platform/parity.d.ts +33 -0
  291. package/dist/platform/parity.js +272 -0
  292. package/dist/platform/platform-ops.module.d.ts +32 -0
  293. package/dist/platform/platform-ops.module.js +78 -11
  294. package/dist/platform/route-schemas.d.ts +18 -0
  295. package/dist/platform/route-schemas.js +60 -0
  296. package/dist/roles/worker.module.js +2 -0
  297. package/dist/runtime/context/build.d.ts +2 -0
  298. package/dist/runtime/context/build.js +28 -2
  299. package/dist/runtime/context/compaction.js +10 -1
  300. package/dist/runtime/context/run-context.d.ts +65 -0
  301. package/dist/runtime/context/run-context.js +215 -0
  302. package/dist/runtime/hook-calls.d.ts +8 -1
  303. package/dist/runtime/hook-calls.js +40 -9
  304. package/dist/runtime/model-call.d.ts +8 -3
  305. package/dist/runtime/model-call.js +30 -6
  306. package/dist/runtime/providers.d.ts +146 -32
  307. package/dist/runtime/providers.js +328 -67
  308. package/dist/runtime/run-context.service.d.ts +65 -0
  309. package/dist/runtime/run-context.service.js +220 -0
  310. package/dist/runtime/run-worker.d.ts +6 -1
  311. package/dist/runtime/run-worker.js +35 -10
  312. package/dist/runtime/runtime.module.js +2 -0
  313. package/dist/runtime/subagents/definition.d.ts +15 -15
  314. package/dist/runtime/subagents/definition.js +49 -118
  315. package/dist/runtime/usage-report-jobs.d.ts +88 -0
  316. package/dist/runtime/usage-report-jobs.js +158 -0
  317. package/dist/runtime/usage-report.d.ts +33 -38
  318. package/dist/runtime/usage-report.js +152 -84
  319. package/dist/skills/changes.controller.js +2 -1
  320. package/dist/skills/changes.service.d.ts +1 -1
  321. package/dist/skills/changes.service.js +4 -4
  322. package/dist/skills/invocable.controller.d.ts +1 -1
  323. package/dist/skills/invocable.controller.js +2 -2
  324. package/dist/skills/invoke.d.ts +2 -2
  325. package/dist/skills/invoke.js +8 -1
  326. package/dist/skills/skills.controller.d.ts +4 -13
  327. package/dist/skills/skills.controller.js +8 -24
  328. package/dist/skills/skills.schemas.d.ts +48 -0
  329. package/dist/skills/skills.schemas.js +61 -0
  330. package/dist/skills/skills.service.d.ts +11 -1
  331. package/dist/skills/skills.service.js +37 -14
  332. package/dist/time-zone.d.ts +5 -0
  333. package/dist/time-zone.js +19 -0
  334. package/dist/tools/approvals.controller.js +2 -3
  335. package/dist/tools/approvals.schemas.d.ts +21 -0
  336. package/dist/tools/approvals.schemas.js +15 -0
  337. package/dist/tools/builtin-names.d.ts +10 -8
  338. package/dist/tools/builtin-names.js +16 -11
  339. package/dist/tools/builtins/builtin-tools.d.ts +3 -1
  340. package/dist/tools/builtins/builtin-tools.js +15 -3
  341. package/dist/tools/builtins/current-time.d.ts +26 -0
  342. package/dist/tools/builtins/current-time.js +99 -0
  343. package/dist/tools/builtins/platform.d.ts +19 -2
  344. package/dist/tools/builtins/platform.js +105 -16
  345. package/dist/tools/connectors.controller.d.ts +1 -2
  346. package/dist/tools/connectors.controller.js +1 -4
  347. package/dist/tools/connectors.schemas.d.ts +12 -0
  348. package/dist/tools/connectors.schemas.js +19 -0
  349. package/dist/tools/connectors.service.d.ts +5 -2
  350. package/dist/tools/connectors.service.js +7 -5
  351. package/dist/tools/org-tool-switches.d.ts +16 -2
  352. package/dist/tools/org-tool-switches.js +26 -9
  353. package/dist/tools/pipeline.js +9 -1
  354. package/dist/tools/registry.d.ts +48 -51
  355. package/dist/tools/registry.js +222 -233
  356. package/package.json +3 -3
  357. package/src/migrations/0089_model_kinds_usage.sql +38 -0
  358. package/src/migrations/0090_initial_passwords.sql +27 -0
  359. package/src/migrations/0091_account_time_zone.sql +4 -0
  360. package/src/migrations/0092_tools_default_on.sql +27 -0
  361. package/dist/platform/redact-orgs.d.ts +0 -7
  362. package/dist/platform/redact-orgs.js +0 -52
@@ -7,38 +7,102 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
7
7
  var __param = (this && this.__param) || function (paramIndex, decorator) {
8
8
  return function (target, key) { decorator(target, key, paramIndex); }
9
9
  };
10
+ import { createHash } from "node:crypto";
10
11
  import { assertValidDeclarations, EFFORT_VALUES, parseExtensionPoint, } from "@capybara-hq/plugin-sdk";
11
12
  import { Inject, Injectable, Module, Optional } from "@nestjs/common";
12
13
  import { ApiError } from "../errors.js";
13
- import { ExtensionRegistry, ExtensionRegistryModule } from "../extensions/registry.js";
14
+ import { deploymentConfigHash } from "../extensions/config-hash.js";
15
+ import { EffectiveConfigs } from "../extensions/effective-config.js";
16
+ import { missingOverridable } from "../extensions/org-levels.js";
17
+ import { ExtensionRegistry } from "../extensions/registry.js";
18
+ import { ExtensionStateModule } from "../extensions/state.module.js";
14
19
  import { CacheService } from "../infra/cache/cache.service.js";
15
20
  import { Cacheable } from "../infra/cache/cacheable.decorator.js";
21
+ import { KernelConfigService } from "../infra/config/kernel-config.service.js";
16
22
  import { KERNEL_LOGGER, REDIS } from "../infra/tokens.js";
23
+ import { ModelEnablement, ModelEnablementModule, modelKey } from "../models/enablement.js";
17
24
  /** 供应商模型列表在 Redis 中的缓存时长(秒)。 */
18
25
  const MODELS_TTL_SECONDS = 600;
19
- /** 单个供应商 `listModels()` 的时限(毫秒):一个卡住的供应商不拖住整个列表与解析。 */
20
- export const LIST_MODELS_TIMEOUT_MS = 10_000;
21
- /** Optional provider: the `listModels()` time limit (ms) instead of {@link LIST_MODELS_TIMEOUT_MS} (tests). */
26
+ /**
27
+ * Optional provider: the `listModels()` time limit (ms) instead of the config's
28
+ * `models.listTimeoutMs` (tests).
29
+ */
22
30
  export const LIST_MODELS_TIMEOUT = Symbol("LIST_MODELS_TIMEOUT");
23
31
  /**
24
32
  * 列表视图(后台模型页、组织模型页)里列模型失败的供应商在这么多秒内直接标 error、不再请求(Redis,多副本共享)。
25
33
  * 只用于列表;`resolve`(运行时)照常每次请求,失败由降级梯子重试。
26
34
  */
27
35
  export const LIST_FAILURE_TTL_SECONDS = 15;
36
+ /**
37
+ * How long the "model dropped from the list" warn is not repeated for the same (provider, model,
38
+ * config digest): the list is re-read every {@link MODELS_TTL_SECONDS}, the warn is not.
39
+ */
40
+ const DROPPED_WARN_TTL_SECONDS = 24 * 3600;
41
+ /**
42
+ * The shape of a cached model list. 2: every entry carries its normalised `kind` (model platform
43
+ * providers); a format-1 entry has none, and a kernel reading it found no chat model at all.
44
+ */
45
+ const MODELS_CACHE_FORMAT = 2;
28
46
  /**
29
47
  * The model list's cache key (`@Cacheable` stores it as `cache:<key>`). It carries the provider's
30
48
  * contract major: after a plugin moves from `@1` to `@2` it never reads the list written through
31
49
  * the `@1` adapter (both are `@2`-shaped, the shape cannot tell them apart). It also carries the
32
- * plugin version and the deployment config digest: after an upgrade (the parameter declarations may
33
- * have changed) or a deployment config change (models added or removed) every replica validates
34
- * the new declarations at once instead of waiting for the old entry's TTL. The digest is only a
35
- * hash, never config text (no secret in the key). Old keys expire by TTL. Entries without a
36
- * version / digest (test doubles) use `-`.
50
+ * plugin version and the digest of the effective config the list was read with (see
51
+ * {@link ProviderRegistry}): after an upgrade (the parameter declarations may have changed) or a
52
+ * config change (models added or removed) every replica validates the new list at once instead of
53
+ * waiting for the old entry's TTL. The digest is only a hash, never config text (no secret in the
54
+ * key). Old keys expire by TTL. Entries without a version / digest (test doubles) use `-`.
55
+ * `f<n>` is the shape of the cached entry ({@link MODELS_CACHE_FORMAT}): a kernel that changes what
56
+ * it caches bumps it, so during a rolling upgrade it never reads a list an older kernel wrote.
37
57
  */
38
- const modelsKey = (p) => `capk:models:${p.plugin}:v${p.major}:${p.version ?? "-"}:${p.configHash ?? "-"}`;
58
+ const modelsKey = (p, hash) => `capk:models:${p.plugin}:v${p.major}:f${MODELS_CACHE_FORMAT}:${p.version ?? "-"}:${hash ?? "-"}`;
39
59
  /** 列表视图的失败标记({@link LIST_FAILURE_TTL_SECONDS}),与模型列表同样按版本与配置摘要区分。 */
40
- const listFailedKey = (p) => `capk:models-failed:${p.plugin}:v${p.major}:${p.version ?? "-"}:${p.configHash ?? "-"}`;
60
+ const listFailedKey = (p, hash) => `capk:models-failed:${p.plugin}:v${p.major}:${p.version ?? "-"}:${hash ?? "-"}`;
61
+ const droppedKey = (plugin, hash, model) => `capk:models-dropped:${plugin}:${hash ?? "-"}:${model}`;
62
+ /**
63
+ * The digest of an org's own copy of the config. `deploymentConfigHash` masks secrets, and a copy
64
+ * usually differs from the platform only by its key, so the org id goes into the digest: a copy
65
+ * never shares the platform's list (or another org's), whose key may see other models.
66
+ */
67
+ const copyHash = (orgId, schema, config) => createHash("sha256")
68
+ .update(`${orgId}\0${deploymentConfigHash(schema, config)}`)
69
+ .digest("hex")
70
+ .slice(0, 16);
41
71
  const CAPABILITY = "model-provider";
72
+ /** The model kinds this kernel knows; another kind (a newer plugin) is listed as `other`. */
73
+ const KNOWN_KINDS = new Set([
74
+ "chat",
75
+ "embedding",
76
+ "rerank",
77
+ "image_generation",
78
+ "video_generation",
79
+ "speech_to_text",
80
+ "text_to_speech",
81
+ ]);
82
+ function bindProvider(impl, call) {
83
+ const bound = {
84
+ stream: (req, opts) => impl.stream(req, { signal: opts.signal, ...call }),
85
+ };
86
+ if (typeof impl.embed === "function") {
87
+ bound.embed = (req, opts) => impl.embed(req, { signal: opts.signal, ...call });
88
+ }
89
+ return bound;
90
+ }
91
+ const positiveInt = (n) => typeof n === "number" && Number.isInteger(n) && n > 0;
92
+ /**
93
+ * Whether an embedding model's info is usable: at least one dimension, every dimension and the
94
+ * limits positive integers, and `defaultDimensions` one of `dimensions`. A model failing this is
95
+ * dropped from the list (every default call on it would fail validation).
96
+ */
97
+ function isValidEmbeddingInfo(e) {
98
+ return (Array.isArray(e.dimensions) &&
99
+ e.dimensions.length > 0 &&
100
+ e.dimensions.every(positiveInt) &&
101
+ positiveInt(e.defaultDimensions) &&
102
+ e.dimensions.includes(e.defaultDimensions) &&
103
+ positiveInt(e.maxInputTokens) &&
104
+ positiveInt(e.maxBatch));
105
+ }
42
106
  /**
43
107
  * 供应商的 `listModels()` 失败(上游不可用等)。仍是 `agent.model_unavailable`,HTTP 调用方照常
44
108
  * 得到该错误码;运行时(`runModelStep`)据此类型把它当作可重试的失败交给降级梯子,
@@ -66,14 +130,16 @@ const V1_EFFORT_KNOB = {
66
130
  /**
67
131
  * 把 `model-provider@1` 实现包成 `@2`:
68
132
  * - `listModels`:`parameters` 由 `capabilities.effort` 推导(为真时只有 effort 旋钮,否则为空);
133
+ * an `@1` model is always a chat model: `kind` and `embedding` are dropped (an `@1` provider has
134
+ * no `embed`); the per-call options are not passed (an `@1` provider reads `ctx.config`);
69
135
  * - `stream`:`params.effort` 映射为 `req.effort`,其余参数丢弃(`@1` 没有对应字段);
70
- * 没有 `params.effort` 时保留请求自带的 `effort`。
136
+ * 没有 `params.effort` 时保留请求自带的 `effort`;only the signal is passed.
71
137
  */
72
138
  export function adaptModelProviderV1(impl) {
73
139
  return {
74
140
  async listModels() {
75
141
  const models = await impl.listModels();
76
- return models.map((m) => ({
142
+ return models.map(({ kind: _kind, embedding: _embedding, ...m }) => ({
77
143
  ...m,
78
144
  parameters: m.capabilities.effort ? [structuredClone(V1_EFFORT_KNOB)] : [],
79
145
  }));
@@ -86,43 +152,61 @@ export function adaptModelProviderV1(impl) {
86
152
  if (typeof effort === "string" && EFFORT_VALUES.includes(effort)) {
87
153
  out.effort = effort;
88
154
  }
89
- return impl.stream(out, opts);
155
+ return impl.stream(out, { signal: opts.signal });
90
156
  },
91
157
  };
92
158
  }
93
159
  /**
94
160
  * 模型供应商注册表:供应商即提供 `model-provider` 能力的插件(以插件名为供应商名)。
95
161
  * 同时支持 `model-provider@1`(经 {@link adaptModelProviderV1} 适配)与 `@2`;
96
- * 同一插件两者都提供时用 `@2`。`@2` 的 `listModels()` 结果先过 `assertValidDeclarations`,
97
- * 不合规的供应商不可用(不可重试)。
98
- * Each provider's model list (`@2`-shaped) is cached in Redis (`@Cacheable`, key
162
+ * 同一插件两者都提供时用 `@2`。
163
+ *
164
+ * Org-bound (spec B §5.5, A §6): every list and call is made for an org with the provider's
165
+ * effective config there (`EffectiveConfigs.get`), passed as `{ orgId, config }`; a provider whose
166
+ * effective config is not valid in the org offers no models there, and neither does one the org
167
+ * explicitly turned off (its own extension switch row off, spec A §8; a provider with no switch row
168
+ * stays usable). The admin view (no org) lists with the platform config.
169
+ *
170
+ * Each list is validated per model (spec B §5.1): kinds are normalised (absent = `chat`, unknown =
171
+ * `other`); a chat model failing `assertValidDeclarations`, or an `embedding` model without
172
+ * `embedding` info or from a provider without `embed`, is dropped with a warn, the rest of the
173
+ * provider stays usable. Only `chat` and `embedding` models resolve.
174
+ *
175
+ * Each list (`@2`-shaped) is cached in Redis (`@Cacheable`, key
99
176
  * `cache:capk:models:<provider>:v<major>:<plugin version>:<config digest>`, 600 s), never in
100
- * process memory: every replica shares it.
177
+ * process memory: every replica shares it. The digest is the platform config's for every org that
178
+ * follows the platform (one shared list), and a per-org digest for an org's own copy.
101
179
  */
102
180
  let ProviderRegistry = class ProviderRegistry {
103
181
  host;
182
+ effective;
104
183
  cacheService;
105
184
  kv;
185
+ config;
186
+ enablement;
106
187
  log;
107
- listTimeoutMs;
108
- constructor(host, cacheService, kv, log,
109
- /** The `listModels()` time limit. */
110
- listTimeoutMs = LIST_MODELS_TIMEOUT_MS) {
188
+ listTimeoutOverride;
189
+ constructor(host, effective, cacheService, kv, config, enablement, log,
190
+ /** Overrides `models.listTimeoutMs` (tests). */
191
+ listTimeoutOverride) {
111
192
  this.host = host;
193
+ this.effective = effective;
112
194
  this.cacheService = cacheService;
113
195
  this.kv = kv;
196
+ this.config = config;
197
+ this.enablement = enablement;
114
198
  this.log = log;
115
- this.listTimeoutMs = listTimeoutMs;
199
+ this.listTimeoutOverride = listTimeoutOverride;
116
200
  }
117
201
  /** `listModels()` 加时限(到时按失败处理,供应商的调用留在后台、结果丢弃)。 */
118
- async listModelsWithTimeout(impl) {
119
- const ms = this.listTimeoutMs;
202
+ async listModelsWithTimeout(impl, call) {
203
+ const ms = this.listTimeoutOverride ?? this.config.get().models.listTimeoutMs;
120
204
  let timer;
121
- const call = Promise.resolve().then(() => impl.listModels());
122
- call.catch(() => { });
205
+ const call$ = Promise.resolve().then(() => impl.listModels(call));
206
+ call$.catch(() => { });
123
207
  try {
124
208
  return await Promise.race([
125
- call,
209
+ call$,
126
210
  new Promise((_, reject) => {
127
211
  timer = setTimeout(() => reject(new Error(`listModels timed out after ${ms}ms`)), ms);
128
212
  }),
@@ -134,11 +218,17 @@ let ProviderRegistry = class ProviderRegistry {
134
218
  }
135
219
  /**
136
220
  * Whether at least one model-provider extension is loaded on this replica (enabled, configured,
137
- * set up). Read from the extension host only: never calls a vendor, so a provider whose vendor
138
- * is down still counts (org readiness, web-order spec §3.8).
221
+ * set up) with a valid effective config in `orgId`. Read from extension state and the org's
222
+ * config only: never calls a vendor, so a provider whose vendor is down still counts (org
223
+ * readiness, web-order spec §3.8).
139
224
  */
140
- hasProvider() {
141
- return this.providers().length > 0;
225
+ async hasProvider(orgId) {
226
+ const off = await this.enablement.switchedOff(orgId);
227
+ for (const p of this.providers()) {
228
+ if ((await this.target(p, orgId, off)).ok)
229
+ return true;
230
+ }
231
+ return false;
142
232
  }
143
233
  /** 每个插件取一个实现(`@2` 优先),按插件首次出现的顺序;不支持的主版本记 warn 后忽略。 */
144
234
  providers() {
@@ -170,53 +260,174 @@ let ProviderRegistry = class ProviderRegistry {
170
260
  impl: major === 2 ? impl : adaptModelProviderV1(impl),
171
261
  }));
172
262
  }
173
- models(p) {
174
- return this.validatedModels(modelsKey(p), p);
263
+ /**
264
+ * The call options and list digest of `p` for `orgId`, or for the platform when `orgId` is
265
+ * undefined (the admin view). An org: its effective config (not valid -> `needs_config`); the
266
+ * platform's digest while it follows the platform, a per-org one for its copy. The platform: its
267
+ * own config (a required overridable field left empty -> `org_configured`). `off`: the
268
+ * extensions the org explicitly turned off (`ModelEnablement.switchedOff`) -> `switched_off`.
269
+ */
270
+ async target(p, orgId, off = new Set()) {
271
+ const inst = this.host.current?.(p.plugin);
272
+ const schema = inst?.manifest.config?.deployment;
273
+ if (orgId === undefined) {
274
+ if (schema && missingOverridable(schema, inst?.config).length > 0) {
275
+ return { ok: false, reason: "org_configured" };
276
+ }
277
+ return { ok: true, call: { config: inst?.config }, hash: p.configHash };
278
+ }
279
+ if (off.has(p.plugin))
280
+ return { ok: false, reason: "switched_off" };
281
+ const eff = await this.effective.get(orgId, p.plugin);
282
+ if (!eff.ok)
283
+ return { ok: false, reason: "needs_config" };
284
+ // an `@1` provider ignores the per-call options (it reads `ctx.config`): the org's own copy
285
+ // could not be honoured, its calls would go out with the platform's config
286
+ if (eff.source === "copy" && p.major === 1)
287
+ return { ok: false, reason: "needs_config" };
288
+ return {
289
+ ok: true,
290
+ call: { orgId, config: eff.config },
291
+ hash: eff.source === "platform" ? p.configHash : copyHash(orgId, schema, eff.config),
292
+ };
293
+ }
294
+ models(p, t) {
295
+ return this.validatedModels(modelsKey(p, t.hash), p, t.call, t.hash);
175
296
  }
176
297
  /** The provider's validated model list, cached under `key` (see {@link modelsKey}). */
177
- async validatedModels(_key, p) {
178
- const { plugin: provider, major, impl } = p;
298
+ async validatedModels(_key, p, call, hash) {
299
+ const { plugin: provider, impl } = p;
179
300
  let models;
180
301
  try {
181
- models = await this.listModelsWithTimeout(impl);
302
+ models = await this.listModelsWithTimeout(impl, call);
182
303
  }
183
304
  catch (err) {
184
305
  throw new ProviderListError(provider, err);
185
306
  }
186
- if (major === 2) {
187
- try {
188
- for (const m of models)
307
+ const out = [];
308
+ for (const m of models) {
309
+ const kind = m.kind === undefined ? "chat" : KNOWN_KINDS.has(m.kind) ? m.kind : "other";
310
+ let problem;
311
+ let cause;
312
+ if (kind === "chat") {
313
+ try {
189
314
  assertValidDeclarations(provider, m.parameters);
315
+ }
316
+ catch (err) {
317
+ problem = "invalid parameter declarations";
318
+ cause = err;
319
+ }
190
320
  }
191
- catch (err) {
192
- const e = new ApiError("agent.model_unavailable", `Model provider ${provider} declared invalid model parameters`);
193
- e.cause = err;
194
- throw e;
321
+ else if (kind === "embedding") {
322
+ if (!m.embedding)
323
+ problem = "an embedding model without embedding info";
324
+ else if (!isValidEmbeddingInfo(m.embedding))
325
+ problem = "malformed embedding info";
326
+ else if (typeof impl.embed !== "function") {
327
+ problem = "an embedding model from a provider without embed";
328
+ }
195
329
  }
330
+ if (problem !== undefined) {
331
+ await this.warnDropped(provider, m.id, hash, problem, cause);
332
+ continue;
333
+ }
334
+ out.push({ ...m, kind });
196
335
  }
197
- return models;
336
+ return out;
337
+ }
338
+ /** One warn per (provider, model, config digest) within {@link DROPPED_WARN_TTL_SECONDS}. */
339
+ async warnDropped(provider, model, hash, problem, cause) {
340
+ const key = droppedKey(provider, hash, model);
341
+ if ((await this.kv.get(key)) !== null)
342
+ return;
343
+ await this.kv.set(key, "1", "EX", DROPPED_WARN_TTL_SECONDS);
344
+ this.log?.warn("model dropped from the provider's list", {
345
+ provider,
346
+ model,
347
+ problem,
348
+ ...(cause !== undefined && { err: cause }),
349
+ });
350
+ }
351
+ /**
352
+ * 每个供应商及其模型(按插件加载顺序),for `orgId`:列模型失败或在该组织需要配置的供应商跳过。Only
353
+ * enabled models (neither the platform nor the org disabled them, spec B §5.3), optionally of
354
+ * one `kind`.
355
+ */
356
+ async list(orgId, opts = {}) {
357
+ return (await this.listWithStatus(orgId)).flatMap((p) => p.status === "ok"
358
+ ? [
359
+ {
360
+ provider: p.provider,
361
+ models: opts.kind === undefined ? p.models : p.models.filter((m) => m.kind === opts.kind),
362
+ },
363
+ ]
364
+ : []);
365
+ }
366
+ /**
367
+ * An org's catalog (the org settings page, spec B §5.3): every provider as in
368
+ * {@link listWithStatus} for the org, with every model the platform left on, each carrying
369
+ * `disabled` for the org's own list. Reads the same cached lists (no extra provider call).
370
+ */
371
+ async catalog(orgId) {
372
+ const [statuses, platform, org] = await Promise.all([
373
+ this.statuses(orgId),
374
+ this.enablement.disabled(null),
375
+ this.enablement.disabled(orgId),
376
+ ]);
377
+ return statuses.map((p) => ({
378
+ ...p,
379
+ models: p.models
380
+ .filter((m) => !platform.has(modelKey(p.provider, m.id)))
381
+ .map((m) => ({ ...m, disabled: org.has(modelKey(p.provider, m.id)) })),
382
+ }));
198
383
  }
199
- /** 每个已安装供应商及其模型(按插件加载顺序);列模型失败或声明不合规的供应商跳过并记 warn。 */
200
- async list() {
201
- return (await this.listWithStatus()).flatMap((p) => p.status === "ok" ? [{ provider: p.provider, models: p.models }] : []);
384
+ /**
385
+ * 每个已安装供应商及其状态(按插件加载顺序),for `orgId` (enabled models only), or the platform
386
+ * view when undefined (`/admin/models`: every model, `disabled` from the platform's list only).
387
+ * See {@link statuses} for the statuses.
388
+ */
389
+ async listWithStatus(orgId) {
390
+ const [statuses, platform, org] = await Promise.all([
391
+ this.statuses(orgId),
392
+ this.enablement.disabled(null),
393
+ orgId === undefined ? Promise.resolve(new Set()) : this.enablement.disabled(orgId),
394
+ ]);
395
+ return statuses.map((p) => ({
396
+ ...p,
397
+ models: orgId === undefined
398
+ ? p.models.map((m) => ({ ...m, disabled: platform.has(modelKey(p.provider, m.id)) }))
399
+ : p.models.filter((m) => {
400
+ const key = modelKey(p.provider, m.id);
401
+ return !platform.has(key) && !org.has(key);
402
+ }),
403
+ }));
202
404
  }
203
405
  /**
204
- * 每个已安装供应商及其状态(按插件加载顺序,后台用):列模型失败(含超过 {@link LIST_MODELS_TIMEOUT_MS})或声明
205
- * 不合规的标 `error`、`models` 为空,不影响其他供应商;列模型失败的在 {@link LIST_FAILURE_TTL_SECONDS} 秒内不再请求。`error` 只是内核自己的英文说明(不透出上游错误原文,原文记 warn 日志)。
406
+ * 每个已安装供应商的完整列表与状态,for `orgId` or the platform: 列模型失败(含超过
407
+ * `models.listTimeoutMs`)的标 `error`、`models` 为空,不影响其他供应商;列模型失败的在
408
+ * {@link LIST_FAILURE_TTL_SECONDS} 秒内不再请求。An org where the provider needs configuration gets
409
+ * `error`; the platform view of a provider whose platform config leaves a required overridable
410
+ * field empty gets `org_configured`. `error` 只是内核自己的英文说明(不透出上游错误原文,原文记 warn
411
+ * 日志)。No disabled list applied.
206
412
  */
207
- async listWithStatus() {
413
+ async statuses(orgId) {
208
414
  const providers = this.providers();
415
+ const off = orgId === undefined ? new Set() : await this.enablement.switchedOff(orgId);
209
416
  const settled = await Promise.allSettled(providers.map(async (p) => {
417
+ const t = await this.target(p, orgId, off);
418
+ if (!t.ok)
419
+ return t.reason;
420
+ const failed = listFailedKey(p, t.hash);
210
421
  // 刚失败过的供应商:短时间内直接标 error,不再等它(每个供应商另有时限)
211
- if ((await this.kv.get(listFailedKey(p))) !== null) {
422
+ if ((await this.kv.get(failed)) !== null) {
212
423
  throw new ProviderListError(p.plugin, new Error("listModels failed recently"));
213
424
  }
214
425
  try {
215
- return await this.models(p);
426
+ return await this.models(p, t);
216
427
  }
217
428
  catch (err) {
218
429
  if (err instanceof ProviderListError) {
219
- await this.kv.set(listFailedKey(p), "1", "EX", LIST_FAILURE_TTL_SECONDS);
430
+ await this.kv.set(failed, "1", "EX", LIST_FAILURE_TTL_SECONDS);
220
431
  }
221
432
  throw err;
222
433
  }
@@ -224,6 +435,17 @@ let ProviderRegistry = class ProviderRegistry {
224
435
  return settled.map((r, i) => {
225
436
  const provider = providers[i].plugin;
226
437
  if (r.status === "fulfilled") {
438
+ if (r.value === "org_configured") {
439
+ return { provider, plugin: provider, status: "org_configured", models: [] };
440
+ }
441
+ if (r.value === "needs_config") {
442
+ const error = `Model provider ${provider} needs configuration in this organization`;
443
+ return { provider, plugin: provider, status: "error", error, models: [] };
444
+ }
445
+ if (r.value === "switched_off") {
446
+ const error = `Model provider ${provider} is turned off in this organization`;
447
+ return { provider, plugin: provider, status: "error", error, models: [] };
448
+ }
227
449
  return { provider, plugin: provider, status: "ok", models: r.value };
228
450
  }
229
451
  this.log?.warn("model provider listModels failed; skipped", { provider, err: r.reason });
@@ -234,17 +456,53 @@ let ProviderRegistry = class ProviderRegistry {
234
456
  });
235
457
  }
236
458
  /**
237
- * 解析模型引用,返回 `@2` 形状的供应商实现(`@1` 已适配)与模型信息。
238
- * 供应商未安装、模型不存在或参数声明不合规 → `agent.model_unavailable`;
459
+ * 解析模型引用 for `orgId`,返回绑定到该组织调用选项的供应商与模型信息。
460
+ * 供应商未安装、在该组织需要配置、模型不存在(或被丢弃)、不是 `opts.kind`(default `chat`: a
461
+ * streaming caller never gets an embedding model)或被平台 / 该组织停用 → `agent.model_unavailable`;
239
462
  * 供应商 `listModels()` 失败 → `ProviderListError`(同一错误码,运行时视为可重试)。
240
463
  */
241
- async resolve(ref) {
464
+ async resolve(orgId, ref, opts = {}) {
465
+ const { p, t, info } = await this.lookup(orgId, ref, opts.kind ?? "chat");
466
+ return { provider: bindProvider(p.impl, t.call), info };
467
+ }
468
+ /**
469
+ * The model's info in the platform view (deployment-level settings such as a purpose's
470
+ * deployment default; no call is ever made there), by {@link resolve}'s rules. A provider each
471
+ * org configures itself has no platform list: `agent.model_unavailable`. Only the platform's
472
+ * disabled list applies.
473
+ */
474
+ async platformInfo(ref, opts = {}) {
475
+ return (await this.lookup(undefined, ref, opts.kind ?? "chat")).info;
476
+ }
477
+ async lookup(orgId, ref, kind) {
478
+ const unavailable = () => new ApiError("agent.model_unavailable", `Model ${ref.provider}/${ref.model} is not available`);
242
479
  const p = this.providers().find((x) => x.plugin === ref.provider);
243
- const info = p && (await this.models(p)).find((m) => m.id === ref.model);
244
- if (!p || !info) {
245
- throw new ApiError("agent.model_unavailable", `Model ${ref.provider}/${ref.model} is not available`);
480
+ if (!p)
481
+ throw unavailable();
482
+ const off = orgId === undefined ? new Set() : await this.enablement.switchedOff(orgId);
483
+ const t = await this.target(p, orgId, off);
484
+ if (!t.ok) {
485
+ throw new ApiError("agent.model_unavailable", t.reason === "org_configured"
486
+ ? `Model provider ${ref.provider} is configured by each organization`
487
+ : t.reason === "switched_off"
488
+ ? `Model provider ${ref.provider} is turned off in this organization`
489
+ : `Model provider ${ref.provider} needs configuration in this organization`);
490
+ }
491
+ const info = (await this.models(p, t)).find((m) => m.id === ref.model);
492
+ if (!info || (info.kind !== "chat" && info.kind !== "embedding"))
493
+ throw unavailable();
494
+ if (kind !== "callable" && info.kind !== kind) {
495
+ throw new ApiError("agent.model_unavailable", `Model ${ref.provider}/${ref.model} is not ${kind === "embedding" ? "an" : "a"} ${kind} model`);
496
+ }
497
+ const key = modelKey(ref.provider, ref.model);
498
+ const [platform, org] = await Promise.all([
499
+ this.enablement.disabled(null),
500
+ orgId === undefined ? Promise.resolve(new Set()) : this.enablement.disabled(orgId),
501
+ ]);
502
+ if (platform.has(key) || org.has(key)) {
503
+ throw new ApiError("agent.model_unavailable", `Model ${ref.provider}/${ref.model} is disabled`);
246
504
  }
247
- return { provider: p.impl, info };
505
+ return { p, t, info: info };
248
506
  }
249
507
  };
250
508
  __decorate([
@@ -253,11 +511,14 @@ __decorate([
253
511
  ProviderRegistry = __decorate([
254
512
  Injectable(),
255
513
  __param(0, Inject(ExtensionRegistry)),
256
- __param(1, Inject(CacheService)),
257
- __param(2, Inject(REDIS)),
258
- __param(3, Inject(KERNEL_LOGGER)),
259
- __param(4, Optional()),
260
- __param(4, Inject(LIST_MODELS_TIMEOUT))
514
+ __param(1, Inject(EffectiveConfigs)),
515
+ __param(2, Inject(CacheService)),
516
+ __param(3, Inject(REDIS)),
517
+ __param(4, Inject(KernelConfigService)),
518
+ __param(5, Inject(ModelEnablement)),
519
+ __param(6, Inject(KERNEL_LOGGER)),
520
+ __param(7, Optional()),
521
+ __param(7, Inject(LIST_MODELS_TIMEOUT))
261
522
  ], ProviderRegistry);
262
523
  export { ProviderRegistry };
263
524
  /** The model provider registry (one instance; the models and agents domains read it). */
@@ -265,7 +526,7 @@ let ProvidersModule = class ProvidersModule {
265
526
  };
266
527
  ProvidersModule = __decorate([
267
528
  Module({
268
- imports: [ExtensionRegistryModule],
529
+ imports: [ExtensionStateModule, ModelEnablementModule],
269
530
  providers: [ProviderRegistry],
270
531
  exports: [ProviderRegistry],
271
532
  })
@@ -0,0 +1,65 @@
1
+ import type { AgentDefinition } from "../agents/definition.js";
2
+ import { EventLog } from "../conversations/event-log.js";
3
+ import type { KernelSchemaDb } from "../db/kernel-schema.js";
4
+ import { KernelDb } from "../infra/database/kernel-db.js";
5
+ import { TransactionHost } from "../infra/database/transaction-host.js";
6
+ /**
7
+ * Optional provider: the clock run start reads the date from and the `CurrentTime` builtin reads
8
+ * the time from (default `Date.now`; tests).
9
+ */
10
+ export declare const RUN_CONTEXT_CLOCK: unique symbol;
11
+ /** The idem key of a run's `run_context` (one per run at most). */
12
+ export declare const runContextIdemKey: (runId: string) => string;
13
+ /** What a run start tells {@link RunContextService.record}. */
14
+ export interface RunContextInput {
15
+ orgId: string;
16
+ conversationId: string;
17
+ runId: string;
18
+ /** The run's boundary: its trigger message (or the finish / delivery that woke it). */
19
+ triggerSeq: number;
20
+ /** The run's effective definition (a root run's agent version; a sub-agent's frozen one). */
21
+ agent: AgentDefinition;
22
+ /** A sub-agent run: the parent call that dispatched it and the child's roster name. */
23
+ subagent?: {
24
+ parentConversationId: string;
25
+ parentRunId: string;
26
+ /** The roster name (`subagent_started.agentType`), or the forked skill's name. */
27
+ name: string;
28
+ };
29
+ }
30
+ /**
31
+ * Run start's run context (spec 2026-11-08-run-context-design §5): compares the facts the run
32
+ * would show the model (its agent's name and description, the org's name, today's date, the time
33
+ * zone and language of the person whose message started it; for a sub-agent who dispatched it)
34
+ * with the fold of the conversation's `run_context` events, and appends only what differs (the
35
+ * first time: everything). Lazy: a rename writes nothing anywhere; the next run notices.
36
+ */
37
+ export declare class RunContextService {
38
+ private readonly db;
39
+ private readonly eventLog;
40
+ readonly txHost: TransactionHost;
41
+ private readonly now;
42
+ constructor(db: KernelDb, eventLog: Pick<EventLog, "appendIn" | "notify">, txHost: TransactionHost, now?: () => number);
43
+ private clock;
44
+ /** Records the run's context (see the class) and notifies after the commit. */
45
+ record(input: RunContextInput): Promise<void>;
46
+ /**
47
+ * One transaction under the conversation row lock (as `lockLatestCatalog`): fold, read the
48
+ * current values, append when something differs, with the idem key `run_context:<runId>` (a
49
+ * retried run start finds its event, or finds nothing changed). Returns the seq written.
50
+ */
51
+ private append;
52
+ /** A root run: agent, org, and the date, zone and language of the run's person (§3.4). */
53
+ private rootContext;
54
+ /**
55
+ * A sub-agent run (spec §6): its roster name, who dispatched it (the parent agent's name and
56
+ * the person the parent works for), and the parent's date and zone; no org, no language.
57
+ */
58
+ private childContext;
59
+ }
60
+ /**
61
+ * The time zone a conversation's run context holds now (the latest `run_context` with a
62
+ * `timeZone`, as the fold reads it), else the org default (§3.3), else UTC. The `CurrentTime`
63
+ * builtin's default zone.
64
+ */
65
+ export declare function conversationTimeZone(t: KernelSchemaDb, orgId: string, conversationId: string): Promise<string>;