@capybara-hq/kernel 0.1.0-rc.6 → 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 (331) hide show
  1. package/bootstrap.json +27 -3
  2. package/dist/admin/admin.controller.d.ts +8 -72
  3. package/dist/admin/admin.controller.js +21 -46
  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 +13 -5
  19. package/dist/agents/agents.service.js +67 -13
  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 +20 -3
  26. package/dist/agents/models.controller.d.ts +1 -2
  27. package/dist/agents/models.controller.js +1 -1
  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/templates.controller.d.ts +8 -17
  39. package/dist/agents/templates.controller.js +13 -31
  40. package/dist/agents/templates.schemas.d.ts +20 -0
  41. package/dist/agents/templates.schemas.js +45 -0
  42. package/dist/background/background.controller.js +3 -2
  43. package/dist/background/background.schemas.d.ts +10 -0
  44. package/dist/background/background.schemas.js +16 -0
  45. package/dist/background/tasks.service.d.ts +1 -1
  46. package/dist/background/tasks.service.js +7 -2
  47. package/dist/catalog/admin-catalog.controller.d.ts +4 -57
  48. package/dist/catalog/admin-catalog.controller.js +8 -45
  49. package/dist/catalog/admin-catalog.schemas.d.ts +72 -0
  50. package/dist/catalog/admin-catalog.schemas.js +92 -0
  51. package/dist/catalog/catalog-content.d.ts +12 -2
  52. package/dist/catalog/catalog-scope.service.js +8 -2
  53. package/dist/catalog/catalog.service.d.ts +2 -0
  54. package/dist/catalog/catalog.service.js +3 -0
  55. package/dist/catalog/component-scope.controller.d.ts +3 -65
  56. package/dist/catalog/component-scope.controller.js +3 -56
  57. package/dist/catalog/component-scope.schemas.d.ts +114 -0
  58. package/dist/catalog/component-scope.schemas.js +97 -0
  59. package/dist/catalog/component-scope.service.d.ts +28 -4
  60. package/dist/catalog/component-scope.service.js +55 -3
  61. package/dist/catalog/component-state.d.ts +9 -2
  62. package/dist/catalog/component-state.js +22 -13
  63. package/dist/catalog/marketplaces.controller.d.ts +5 -35
  64. package/dist/catalog/marketplaces.controller.js +6 -34
  65. package/dist/catalog/marketplaces.schemas.d.ts +48 -0
  66. package/dist/catalog/marketplaces.schemas.js +53 -0
  67. package/dist/catalog/marketplaces.service.d.ts +15 -1
  68. package/dist/catalog/marketplaces.service.js +22 -1
  69. package/dist/catalog/org-catalog.controller.d.ts +6 -62
  70. package/dist/catalog/org-catalog.controller.js +12 -66
  71. package/dist/catalog/org-catalog.schemas.d.ts +79 -0
  72. package/dist/catalog/org-catalog.schemas.js +82 -0
  73. package/dist/catalog/org-catalog.service.d.ts +9 -2
  74. package/dist/catalog/org-catalog.service.js +38 -5
  75. package/dist/catalog/org-extension.controller.d.ts +1 -12
  76. package/dist/catalog/org-extension.controller.js +1 -10
  77. package/dist/catalog/org-extension.schemas.d.ts +15 -0
  78. package/dist/catalog/org-extension.schemas.js +22 -0
  79. package/dist/catalog/org-plugin-uploads.controller.d.ts +2 -19
  80. package/dist/catalog/org-plugin-uploads.controller.js +15 -28
  81. package/dist/catalog/org-plugin-uploads.schemas.d.ts +20 -0
  82. package/dist/catalog/org-plugin-uploads.schemas.js +32 -0
  83. package/dist/catalog/owned-items.d.ts +6 -2
  84. package/dist/catalog/owned-items.js +16 -4
  85. package/dist/catalog/platform-components.d.ts +2 -0
  86. package/dist/catalog/platform-components.js +2 -0
  87. package/dist/catalog/plugin-import.js +1 -0
  88. package/dist/catalog/plugin-install.js +1 -1
  89. package/dist/catalog/requests.service.d.ts +2 -1
  90. package/dist/catalog/requests.service.js +6 -2
  91. package/dist/channels/channels.schemas.d.ts +33 -0
  92. package/dist/channels/channels.schemas.js +34 -0
  93. package/dist/channels/connections.controller.d.ts +2 -29
  94. package/dist/channels/connections.controller.js +1 -23
  95. package/dist/channels/connections.service.d.ts +8 -2
  96. package/dist/channels/connections.service.js +23 -5
  97. package/dist/channels/inbound.js +4 -0
  98. package/dist/conversations/conversations.controller.d.ts +16 -37
  99. package/dist/conversations/conversations.controller.js +16 -56
  100. package/dist/conversations/conversations.schemas.d.ts +52 -0
  101. package/dist/conversations/conversations.schemas.js +79 -0
  102. package/dist/conversations/conversations.service.d.ts +9 -1
  103. package/dist/conversations/conversations.service.js +23 -18
  104. package/dist/conversations/events.d.ts +80 -6
  105. package/dist/conversations/events.js +60 -5
  106. package/dist/conversations/message-context.d.ts +28 -0
  107. package/dist/conversations/message-context.js +56 -0
  108. package/dist/conversations/queue.d.ts +2 -1
  109. package/dist/conversations/queue.js +11 -2
  110. package/dist/db/kernel-schema.d.ts +20 -0
  111. package/dist/environments/environments.schemas.d.ts +3 -0
  112. package/dist/environments/environments.schemas.js +14 -0
  113. package/dist/environments/environments.service.d.ts +16 -4
  114. package/dist/environments/environments.service.js +58 -13
  115. package/dist/errors.d.ts +3 -0
  116. package/dist/errors.js +3 -0
  117. package/dist/evals/evals.schemas.d.ts +110 -0
  118. package/dist/evals/evals.schemas.js +107 -0
  119. package/dist/evals/reconstruct.js +18 -11
  120. package/dist/evals/recorded-tools.d.ts +2 -1
  121. package/dist/evals/recorded-tools.js +11 -3
  122. package/dist/evals/run-replay.d.ts +8 -1
  123. package/dist/evals/run-replay.js +13 -0
  124. package/dist/evals/runs.controller.d.ts +2 -57
  125. package/dist/evals/runs.controller.js +1 -42
  126. package/dist/evals/runs.service.d.ts +6 -6
  127. package/dist/evals/runs.service.js +32 -18
  128. package/dist/evals/sets.controller.d.ts +2 -28
  129. package/dist/evals/sets.controller.js +1 -31
  130. package/dist/evals/sets.service.d.ts +7 -7
  131. package/dist/evals/sets.service.js +23 -17
  132. package/dist/evals/snapshot.d.ts +3 -2
  133. package/dist/evals/snapshot.js +17 -4
  134. package/dist/extensions/admin-ops.d.ts +5 -3
  135. package/dist/extensions/admin-ops.js +17 -12
  136. package/dist/extensions/deployment-config.d.ts +16 -1
  137. package/dist/extensions/deployment-config.js +83 -0
  138. package/dist/extensions/extensions.module.js +3 -0
  139. package/dist/extensions/host.d.ts +33 -2
  140. package/dist/extensions/host.js +107 -1
  141. package/dist/extensions/installs.d.ts +5 -0
  142. package/dist/extensions/installs.js +12 -0
  143. package/dist/extensions/org-config.d.ts +17 -2
  144. package/dist/extensions/org-config.js +23 -4
  145. package/dist/extensions/point-defaults.controller.d.ts +2 -8
  146. package/dist/extensions/point-defaults.controller.js +1 -3
  147. package/dist/extensions/point-defaults.d.ts +3 -1
  148. package/dist/extensions/point-defaults.js +4 -2
  149. package/dist/extensions/point-defaults.schemas.d.ts +9 -0
  150. package/dist/extensions/point-defaults.schemas.js +14 -0
  151. package/dist/extensions/unavailable.d.ts +49 -0
  152. package/dist/extensions/unavailable.js +113 -0
  153. package/dist/files/previewers.controller.js +2 -3
  154. package/dist/files/previewers.d.ts +1 -1
  155. package/dist/files/previewers.js +4 -4
  156. package/dist/files/previewers.schemas.d.ts +10 -0
  157. package/dist/files/previewers.schemas.js +9 -0
  158. package/dist/http/api.module.js +2 -0
  159. package/dist/identity/accounts.d.ts +43 -4
  160. package/dist/identity/accounts.js +74 -6
  161. package/dist/identity/auth.guard.js +10 -1
  162. package/dist/identity/cookies.d.ts +6 -0
  163. package/dist/identity/cookies.js +14 -0
  164. package/dist/identity/identity.module.js +3 -0
  165. package/dist/identity/initial-passwords.controller.d.ts +22 -0
  166. package/dist/identity/initial-passwords.controller.js +49 -0
  167. package/dist/identity/initial-passwords.d.ts +61 -0
  168. package/dist/identity/initial-passwords.job.d.ts +16 -0
  169. package/dist/identity/initial-passwords.job.js +46 -0
  170. package/dist/identity/initial-passwords.js +159 -0
  171. package/dist/identity/me.controller.d.ts +14 -0
  172. package/dist/identity/me.controller.js +39 -1
  173. package/dist/identity/principal.d.ts +8 -0
  174. package/dist/identity/principal.js +8 -0
  175. package/dist/identity/settings.d.ts +3 -1
  176. package/dist/identity/settings.js +6 -4
  177. package/dist/inbox/inbox.schemas.d.ts +8 -0
  178. package/dist/inbox/inbox.schemas.js +11 -0
  179. package/dist/inbox/platform-inbox.controller.d.ts +1 -1
  180. package/dist/inbox/platform-inbox.controller.js +2 -2
  181. package/dist/index.d.ts +4 -0
  182. package/dist/index.js +6 -0
  183. package/dist/lifecycle/kernel-lifecycle.js +4 -0
  184. package/dist/models/enablement.d.ts +2 -0
  185. package/dist/models/enablement.js +1 -0
  186. package/dist/models/org-models.schemas.d.ts +8 -0
  187. package/dist/models/org-models.schemas.js +22 -0
  188. package/dist/models/prices.d.ts +3 -1
  189. package/dist/models/prices.js +7 -5
  190. package/dist/models/purposes.d.ts +12 -2
  191. package/dist/models/purposes.js +22 -8
  192. package/dist/orgs/orgs.controller.d.ts +2 -5
  193. package/dist/orgs/orgs.controller.js +3 -6
  194. package/dist/orgs/orgs.schemas.d.ts +8 -0
  195. package/dist/orgs/orgs.schemas.js +16 -0
  196. package/dist/orgs/orgs.service.d.ts +3 -1
  197. package/dist/orgs/orgs.service.js +6 -4
  198. package/dist/orgs/settings.service.d.ts +9 -1
  199. package/dist/orgs/settings.service.js +20 -5
  200. package/dist/overrides.d.ts +4 -0
  201. package/dist/overrides.js +2 -0
  202. package/dist/platform/errors.d.ts +21 -4
  203. package/dist/platform/errors.js +45 -6
  204. package/dist/platform/exclusions.d.ts +2 -3
  205. package/dist/platform/exclusions.js +68 -849
  206. package/dist/platform/method.js +1 -1
  207. package/dist/platform/operation.d.ts +82 -5
  208. package/dist/platform/operation.js +62 -7
  209. package/dist/platform/ops/accounts.ops.d.ts +32 -0
  210. package/dist/platform/ops/accounts.ops.js +291 -0
  211. package/dist/platform/ops/admin.ops.d.ts +36 -0
  212. package/dist/platform/ops/admin.ops.js +389 -0
  213. package/dist/platform/ops/agent-skills.ops.d.ts +24 -0
  214. package/dist/platform/ops/agent-skills.ops.js +226 -0
  215. package/dist/platform/ops/agent-templates.ops.d.ts +4 -1
  216. package/dist/platform/ops/agent-templates.ops.js +194 -14
  217. package/dist/platform/ops/agents.ops.d.ts +19 -1
  218. package/dist/platform/ops/agents.ops.js +481 -58
  219. package/dist/platform/ops/approvals.ops.d.ts +30 -0
  220. package/dist/platform/ops/approvals.ops.js +116 -0
  221. package/dist/platform/ops/background.ops.d.ts +14 -0
  222. package/dist/platform/ops/background.ops.js +134 -0
  223. package/dist/platform/ops/catalog-admin.ops.d.ts +74 -0
  224. package/dist/platform/ops/catalog-admin.ops.js +587 -0
  225. package/dist/platform/ops/channels.ops.d.ts +16 -0
  226. package/dist/platform/ops/channels.ops.js +195 -0
  227. package/dist/platform/ops/components.ops.d.ts +46 -0
  228. package/dist/platform/ops/components.ops.js +853 -0
  229. package/dist/platform/ops/connectors.ops.d.ts +4 -2
  230. package/dist/platform/ops/connectors.ops.js +68 -6
  231. package/dist/platform/ops/conversations.ops.d.ts +30 -0
  232. package/dist/platform/ops/conversations.ops.js +470 -0
  233. package/dist/platform/ops/environments.ops.d.ts +26 -0
  234. package/dist/platform/ops/environments.ops.js +289 -0
  235. package/dist/platform/ops/errors.d.ts +10 -5
  236. package/dist/platform/ops/errors.js +19 -11
  237. package/dist/platform/ops/evals.ops.d.ts +28 -0
  238. package/dist/platform/ops/evals.ops.js +783 -0
  239. package/dist/platform/ops/extensions-admin.ops.d.ts +25 -0
  240. package/dist/platform/ops/extensions-admin.ops.js +344 -0
  241. package/dist/platform/ops/extensions.ops.d.ts +7 -1
  242. package/dist/platform/ops/extensions.ops.js +248 -17
  243. package/dist/platform/ops/inbox.ops.d.ts +25 -0
  244. package/dist/platform/ops/inbox.ops.js +378 -0
  245. package/dist/platform/ops/marketplaces.ops.d.ts +7 -1
  246. package/dist/platform/ops/marketplaces.ops.js +326 -17
  247. package/dist/platform/ops/models.ops.d.ts +25 -0
  248. package/dist/platform/ops/models.ops.js +232 -0
  249. package/dist/platform/ops/org-plugins.ops.d.ts +29 -0
  250. package/dist/platform/ops/org-plugins.ops.js +329 -0
  251. package/dist/platform/ops/org-settings.ops.d.ts +16 -0
  252. package/dist/platform/ops/org-settings.ops.js +102 -0
  253. package/dist/platform/ops/orgs.ops.d.ts +28 -0
  254. package/dist/platform/ops/orgs.ops.js +295 -0
  255. package/dist/platform/ops/other-orgs.d.ts +20 -0
  256. package/dist/platform/ops/other-orgs.js +72 -0
  257. package/dist/platform/ops/platform.ops.d.ts +4 -4
  258. package/dist/platform/ops/platform.ops.js +23 -24
  259. package/dist/platform/ops/plugins.ops.d.ts +10 -8
  260. package/dist/platform/ops/plugins.ops.js +176 -77
  261. package/dist/platform/ops/previewers.ops.d.ts +14 -0
  262. package/dist/platform/ops/previewers.ops.js +109 -0
  263. package/dist/platform/ops/requests.ops.js +57 -19
  264. package/dist/platform/ops/skills.ops.d.ts +5 -1
  265. package/dist/platform/ops/skills.ops.js +129 -11
  266. package/dist/platform/ops/unavailable.d.ts +23 -0
  267. package/dist/platform/ops/unavailable.js +111 -0
  268. package/dist/platform/parity.d.ts +33 -0
  269. package/dist/platform/parity.js +272 -0
  270. package/dist/platform/platform-ops.module.d.ts +32 -0
  271. package/dist/platform/platform-ops.module.js +78 -11
  272. package/dist/platform/route-schemas.d.ts +18 -0
  273. package/dist/platform/route-schemas.js +60 -0
  274. package/dist/roles/worker.module.js +2 -0
  275. package/dist/runtime/context/build.d.ts +2 -0
  276. package/dist/runtime/context/build.js +28 -2
  277. package/dist/runtime/context/compaction.js +10 -1
  278. package/dist/runtime/context/run-context.d.ts +65 -0
  279. package/dist/runtime/context/run-context.js +215 -0
  280. package/dist/runtime/model-call.js +2 -1
  281. package/dist/runtime/providers.js +8 -1
  282. package/dist/runtime/run-context.service.d.ts +65 -0
  283. package/dist/runtime/run-context.service.js +220 -0
  284. package/dist/runtime/run-worker.d.ts +5 -0
  285. package/dist/runtime/run-worker.js +31 -6
  286. package/dist/runtime/runtime.module.js +2 -0
  287. package/dist/runtime/subagents/definition.d.ts +15 -15
  288. package/dist/runtime/subagents/definition.js +46 -115
  289. package/dist/skills/changes.controller.js +2 -1
  290. package/dist/skills/changes.service.d.ts +1 -1
  291. package/dist/skills/changes.service.js +4 -4
  292. package/dist/skills/invocable.controller.d.ts +1 -1
  293. package/dist/skills/invocable.controller.js +2 -2
  294. package/dist/skills/invoke.d.ts +2 -2
  295. package/dist/skills/invoke.js +8 -1
  296. package/dist/skills/skills.controller.d.ts +4 -13
  297. package/dist/skills/skills.controller.js +8 -24
  298. package/dist/skills/skills.schemas.d.ts +48 -0
  299. package/dist/skills/skills.schemas.js +61 -0
  300. package/dist/skills/skills.service.d.ts +11 -1
  301. package/dist/skills/skills.service.js +37 -14
  302. package/dist/time-zone.d.ts +5 -0
  303. package/dist/time-zone.js +19 -0
  304. package/dist/tools/approvals.controller.js +2 -3
  305. package/dist/tools/approvals.schemas.d.ts +21 -0
  306. package/dist/tools/approvals.schemas.js +15 -0
  307. package/dist/tools/builtin-names.d.ts +10 -8
  308. package/dist/tools/builtin-names.js +16 -11
  309. package/dist/tools/builtins/builtin-tools.d.ts +3 -1
  310. package/dist/tools/builtins/builtin-tools.js +15 -3
  311. package/dist/tools/builtins/current-time.d.ts +26 -0
  312. package/dist/tools/builtins/current-time.js +99 -0
  313. package/dist/tools/builtins/platform.d.ts +19 -2
  314. package/dist/tools/builtins/platform.js +105 -16
  315. package/dist/tools/connectors.controller.d.ts +1 -2
  316. package/dist/tools/connectors.controller.js +1 -4
  317. package/dist/tools/connectors.schemas.d.ts +12 -0
  318. package/dist/tools/connectors.schemas.js +19 -0
  319. package/dist/tools/connectors.service.d.ts +5 -2
  320. package/dist/tools/connectors.service.js +7 -5
  321. package/dist/tools/org-tool-switches.d.ts +16 -2
  322. package/dist/tools/org-tool-switches.js +26 -9
  323. package/dist/tools/pipeline.js +3 -1
  324. package/dist/tools/registry.d.ts +48 -51
  325. package/dist/tools/registry.js +222 -233
  326. package/package.json +3 -3
  327. package/src/migrations/0090_initial_passwords.sql +27 -0
  328. package/src/migrations/0091_account_time_zone.sql +4 -0
  329. package/src/migrations/0092_tools_default_on.sql +27 -0
  330. package/dist/platform/redact-orgs.d.ts +0 -7
  331. package/dist/platform/redact-orgs.js +0 -52
@@ -10,44 +10,82 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
10
10
  import { ToolError } from "@capybara-hq/plugin-sdk";
11
11
  import { Inject, Injectable } from "@nestjs/common";
12
12
  import { z } from "zod";
13
+ import { AgentProfileService } from "../../agents/agent-profile.service.js";
14
+ import { AgentCreateBody, AgentCreateDefinition, AgentFromTemplateBody, AgentFromTemplatePreviewBody, AgentPathParams, AgentProfileBody, AgentUpdateBody, PendingConnectorBindBody, PendingConnectorParams, } from "../../agents/agents.schemas.js";
13
15
  import { AgentsService } from "../../agents/agents.service.js";
14
- import { AgentDefinitionSchema, DEFAULT_AGENT_TOOLS, SubagentsSchema, } from "../../agents/definition.js";
16
+ import { AgentDefinitionSchema } from "../../agents/definition.js";
15
17
  import { AgentsFromTemplate } from "../../agents/from-template.service.js";
16
18
  import { OrgAgentTemplates } from "../../agents/org-templates.js";
17
- import { defineOperation } from "../operation.js";
19
+ import { PendingConnectorsService } from "../../agents/pending-connectors.service.js";
20
+ import { PresetAvatarSchema } from "../../agents/profile.js";
21
+ import { CatalogRequestsService } from "../../catalog/requests.service.js";
22
+ import { KernelDb } from "../../infra/database/kernel-db.js";
23
+ import { roleAtLeast } from "../../orgs/roles.js";
24
+ import { ProviderRegistry } from "../../runtime/providers.js";
25
+ import { rootConversationOf } from "../../runtime/subagents/child.js";
26
+ import { ConnectorsService } from "../../tools/connectors.service.js";
27
+ import { defineOperation, } from "../operation.js";
18
28
  import { PlatformOperations } from "../registry.js";
19
- import { asToolError, viaAgent } from "./errors.js";
29
+ import { precheckBy, viaAgent } from "./errors.js";
30
+ import { roleOf } from "./role.js";
20
31
  import { named, orElse } from "./summary.js";
21
- const Id = z.string().min(1).max(100);
32
+ const AgentId = AgentPathParams.shape.agentId.max(100);
33
+ /** The request's definition (create form): the operations tighten its fields, never redeclare them. */
34
+ const Def = AgentCreateDefinition.shape;
35
+ /** Every string the model sends is bounded (the route's tool refs and model strings are not). */
22
36
  const Short = z.string().min(1).max(200);
23
- const Model = z.object({ provider: Short, model: Short }).strict();
24
- const ToolRef = z.union([
25
- z.object({ kind: z.literal("builtin"), name: Short }).strict(),
26
- z.object({ kind: z.literal("plugin"), plugin: Short, name: Short }).strict(),
27
- z
28
- .object({
29
- kind: z.literal("connector"),
30
- connectorId: Short,
31
- tools: z.union([z.literal("all"), z.array(Short).min(1).max(200)]),
32
- })
33
- .strict(),
34
- ]);
35
- const ToolPolicies = z.record(Short, z.enum(["ask", "deny"]));
36
- const Skills = z
37
- .object({
38
- orgSkills: z.array(Id).max(100),
39
- pinned: z.array(Id).max(100).optional(),
40
- })
37
+ const Model = Def.model.extend({ provider: Short, model: Short }).strict();
38
+ const RouteSkills = Def.skills.unwrap();
39
+ /** `writePolicy` stays the web's; `orgSkills` is required here (the route defaults it to []). */
40
+ const Skills = RouteSkills.pick({ pinned: true })
41
+ .extend({ orgSkills: RouteSkills.shape.orgSkills.unwrap() })
41
42
  .strict();
42
43
  /** The definition fields an agent can set through the tool; the rest keep the web's defaults. */
43
44
  const Fields = {
44
- instructions: z.string().max(100_000),
45
+ name: Def.name,
46
+ description: Def.description.unwrap(),
47
+ instructions: Def.instructions.unwrap(),
45
48
  model: Model,
46
- tools: z.array(ToolRef).max(200),
47
- toolPolicies: ToolPolicies,
49
+ /**
50
+ * Tools turned off (tools default-on spec §8): an agent has every builtin, every tool of the
51
+ * extensions enabled in the org and every tool of the org's connectors except these.
52
+ */
53
+ disabledTools: Def.disabledTools.unwrap(),
54
+ toolPolicies: z.record(Short, Def.toolPolicies.unwrap().valueType),
48
55
  skills: Skills,
49
- subagents: SubagentsSchema,
56
+ subagents: Def.subagents.unwrap(),
50
57
  };
58
+ /**
59
+ * The profile fields the tool sets: a preset avatar (or none) and the quick actions. An uploaded
60
+ * image is the web's (byte upload); the description moves into the agent definition (run-context
61
+ * spec §3.5), so it is not mirrored here.
62
+ */
63
+ const Profile = AgentProfileBody.shape;
64
+ const PresetAvatar = PresetAvatarSchema;
65
+ /** One change of `agents.update-profile` as the card says it. */
66
+ function profileChanges(i) {
67
+ const zh = [];
68
+ const en = [];
69
+ if (i.avatar === null) {
70
+ zh.push("移除头像");
71
+ en.push("remove the avatar");
72
+ }
73
+ else if (i.avatar !== undefined) {
74
+ zh.push(`头像设为预设「${i.avatar.id}」`);
75
+ en.push(`set the avatar to preset "${i.avatar.id}"`);
76
+ }
77
+ if (i.quickActions !== undefined && i.quickActions.length === 0) {
78
+ zh.push("清空快捷操作");
79
+ en.push("clear the quick actions");
80
+ }
81
+ else if (i.quickActions !== undefined) {
82
+ // a count only: the titles are model text (spec §6.3); the card's parameters list them
83
+ const n = i.quickActions.length;
84
+ zh.push(`快捷操作设为 ${n} 条(替换现有的)`);
85
+ en.push(`set ${n} quick action${n === 1 ? "" : "s"} (replacing the current ones)`);
86
+ }
87
+ return { zh, en };
88
+ }
51
89
  const WEB_ONLY = "Agents created with the Platform tool are private, and no agent's visibility can be changed with it; sharing an agent with the org or with members is done on the agents page of the web app.";
52
90
  const brief = (a) => ({
53
91
  id: a.id,
@@ -64,13 +102,55 @@ const brief = (a) => ({
64
102
  let AgentsOperations = class AgentsOperations {
65
103
  registry;
66
104
  agents;
105
+ profiles;
67
106
  fromTemplate;
68
107
  orgTemplates;
69
- constructor(registry, agents, fromTemplate, orgTemplates) {
108
+ pending;
109
+ requests;
110
+ connectors;
111
+ providers;
112
+ kdb;
113
+ constructor(registry, agents, profiles, fromTemplate, orgTemplates, pending, requests, connectors, providers, kdb) {
70
114
  this.registry = registry;
71
115
  this.agents = agents;
116
+ this.profiles = profiles;
72
117
  this.fromTemplate = fromTemplate;
73
118
  this.orgTemplates = orgTemplates;
119
+ this.pending = pending;
120
+ this.requests = requests;
121
+ this.connectors = connectors;
122
+ this.providers = providers;
123
+ this.kdb = kdb;
124
+ }
125
+ /**
126
+ * The edit rule the service enforces, read before the card: the agent is visible, and the actor
127
+ * owns it or is an org admin. Returns the agent too for the checks that follow.
128
+ */
129
+ async editCheck(agentId, ctx) {
130
+ let agent;
131
+ try {
132
+ agent = await this.agents.get(ctx.orgId, agentId, ctx.actorAccountId);
133
+ }
134
+ catch (e) {
135
+ const r = await precheckBy(() => Promise.reject(e));
136
+ if (!r.ok)
137
+ return r;
138
+ throw e;
139
+ }
140
+ if (agent.ownerAccountId !== ctx.actorAccountId) {
141
+ const role = await roleOf(this.kdb.db, ctx.orgId, ctx.actorAccountId);
142
+ if (role === null || !roleAtLeast(role, "admin")) {
143
+ return {
144
+ ok: false,
145
+ code: "forbidden",
146
+ message: "Only the agent owner or an organization admin can modify it",
147
+ };
148
+ }
149
+ }
150
+ return { ok: true, agent };
151
+ }
152
+ agentName(ctx, agentId) {
153
+ return orElse(async () => named((await this.agents.get(ctx.orgId, agentId, ctx.actorAccountId)).definition.name), agentId);
74
154
  }
75
155
  /**
76
156
  * `agents.update`'s class (spec §13): `personal` (may be remembered) only on a private agent the
@@ -98,33 +178,34 @@ let AgentsOperations = class AgentsOperations {
98
178
  }),
99
179
  defineOperation({
100
180
  id: "agents.get",
101
- description: "Read one agent you can see with its full definition: instructions, model, tools, skills and sub-agents. Takes the agent id from agents.list.",
102
- input: z.object({ agentId: Id }).strict(),
181
+ description: "Read one agent you can see with its full definition (description, instructions, model, the tools it turns off (disabledTools: an agent has every tool the org offers except these), tool policies, skills and sub-agents) and its profile (avatar, description, quick actions). Takes the agent id from agents.list.",
182
+ input: z.object({ agentId: AgentId }).strict(),
103
183
  example: { agentId: "7c1a5b0e-9a53-4c6b-8d64-2f5a1b0c3e77" },
104
184
  authz: { orgAction: "agents.use" },
105
185
  mirrors: ["GET /api/v1/orgs/:orgId/agents/:agentId"],
106
186
  confirm: "read",
107
- run: async (input, ctx) => asToolError(async () => ({
187
+ run: async (input, ctx) => ({
108
188
  agent: await this.agents.get(ctx.orgId, input.agentId, ctx.actorAccountId),
109
- })),
189
+ }),
110
190
  }),
111
191
  defineOperation({
112
192
  id: "agents.create",
113
- description: "Create a new private agent owned by you, with a name, a model and optionally instructions, tools, skills and sub-agents. Without tools it gets the default ones. Agents created with the Platform tool are private; sharing an agent with the org or with members is done on the agents page of the web app.",
193
+ description: 'Create a new private agent owned by you, with a name, a model and optionally instructions, disabledTools, tool policies, skills and sub-agents. An agent has every tool the org offers (all built-in tools, the tools of the extensions on in the org and of the org\'s connectors) unless disabledTools turns it off: { kind: "builtin", name }, { kind: "plugin", plugin, tools: "all" | [names] } or { kind: "connector", connectorId, tools: "all" | [names] }. Agents created with the Platform tool are private; sharing an agent with the org or with members is done on the agents page of the web app.',
114
194
  input: z
115
195
  .object({
116
196
  definition: z
117
197
  .object({
118
- name: z.string().min(1).max(80),
198
+ name: Fields.name,
119
199
  instructions: Fields.instructions.optional(),
120
200
  model: Fields.model,
121
- tools: Fields.tools.optional(),
201
+ disabledTools: Fields.disabledTools.optional(),
122
202
  toolPolicies: Fields.toolPolicies.optional(),
123
203
  skills: Fields.skills.optional(),
124
204
  subagents: Fields.subagents.optional(),
125
205
  })
126
206
  .strict(),
127
- visibility: z.string().max(40).optional(),
207
+ // only "private" passes; any other is refused with where to share it (WEB_ONLY)
208
+ visibility: AgentCreateBody.shape.visibility.optional(),
128
209
  })
129
210
  .strict(),
130
211
  example: {
@@ -136,6 +217,9 @@ let AgentsOperations = class AgentsOperations {
136
217
  },
137
218
  authz: { orgAction: "agents.create" },
138
219
  mirrors: ["POST /api/v1/orgs/:orgId/agents"],
220
+ // sharing and the avatar are set on the web
221
+ omits: ["memberIds", "profile"],
222
+ loosens: { visibility: "optional: the operation creates private agents only" },
139
223
  confirm: "personal",
140
224
  summary: (i) => ({
141
225
  zh: `新建私有智能体「${i.definition.name}」`,
@@ -149,28 +233,29 @@ let AgentsOperations = class AgentsOperations {
149
233
  const parsed = AgentDefinitionSchema.omit({ pendingConnectors: true }).parse({
150
234
  name: d.name,
151
235
  model: d.model,
152
- tools: d.tools ?? structuredClone(DEFAULT_AGENT_TOOLS),
236
+ ...(d.disabledTools !== undefined && { disabledTools: d.disabledTools }),
153
237
  ...(d.toolPolicies !== undefined && { toolPolicies: d.toolPolicies }),
154
238
  ...(d.skills !== undefined && { skills: d.skills }),
155
239
  ...(d.subagents !== undefined && { subagents: d.subagents }),
156
240
  });
157
- return asToolError(() => this.agents.create(ctx.orgId, ctx.actorAccountId, {
241
+ return this.agents.create(ctx.orgId, ctx.actorAccountId, {
158
242
  definition: { ...parsed, instructions: d.instructions },
159
243
  visibility: "private",
160
- }, undefined, viaAgent("agents.create", ctx)));
244
+ }, undefined, viaAgent("agents.create", ctx));
161
245
  },
162
246
  }),
163
247
  defineOperation({
164
248
  id: "agents.update",
165
- description: "Change an agent you may edit: your own, private or shared, and as an org admin any agent of the org. Send the version you read from agents.get and only the fields to change; the others keep their value. A version that is no longer current is refused, so read the agent again first. The visibility cannot be changed here (that is done on the agents page of the web app). A change to your own private agent may be remembered by the person; a change to a shared agent is confirmed every time.",
249
+ description: 'Change an agent you may edit: your own, private or shared, and as an org admin any agent of the org. Send the version you read from agents.get and only the fields to change; the others keep their value. The description (one short paragraph, "" removes it) is saved with the definition; the avatar and quick actions are changed with agents.update-profile. disabledTools replaces the whole list of turned-off tools (send [] to turn every tool on). A version that is no longer current is refused, so read the agent again first. The visibility cannot be changed here (that is done on the agents page of the web app). A change to your own private agent may be remembered by the person; a change to a shared agent is confirmed every time.',
166
250
  input: z
167
251
  .object({
168
- agentId: Id,
169
- version: z.number().int().positive(),
170
- name: z.string().min(1).max(80).optional(),
252
+ agentId: AgentId,
253
+ version: AgentUpdateBody.shape.expectedVersion.unwrap(),
254
+ name: Fields.name.optional(),
255
+ description: Fields.description.optional(),
171
256
  instructions: Fields.instructions.optional(),
172
257
  model: Fields.model.optional(),
173
- tools: Fields.tools.optional(),
258
+ disabledTools: Fields.disabledTools.optional(),
174
259
  toolPolicies: Fields.toolPolicies.optional(),
175
260
  skills: Fields.skills.optional(),
176
261
  subagents: Fields.subagents.optional(),
@@ -183,6 +268,20 @@ let AgentsOperations = class AgentsOperations {
183
268
  },
184
269
  authz: { orgAction: "agents.create" },
185
270
  mirrors: ["PATCH /api/v1/orgs/:orgId/agents/:agentId"],
271
+ // flat: the definition's editable fields at the top, merged into the current definition;
272
+ // `version` is the route's `expectedVersion`, required here; visibility is the web's
273
+ omits: ["visibility", "memberIds"],
274
+ renames: {
275
+ version: "expectedVersion",
276
+ name: "definition.name",
277
+ description: "definition.description",
278
+ instructions: "definition.instructions",
279
+ model: "definition.model",
280
+ disabledTools: "definition.disabledTools",
281
+ toolPolicies: "definition.toolPolicies",
282
+ skills: "definition.skills",
283
+ subagents: "definition.subagents",
284
+ },
186
285
  confirm: "personal",
187
286
  errors: [
188
287
  {
@@ -204,7 +303,7 @@ let AgentsOperations = class AgentsOperations {
204
303
  en: `Update shared agent "${name}" (version ${i.version})`,
205
304
  };
206
305
  },
207
- run: async (input, ctx) => asToolError(async () => {
306
+ run: async (input, ctx) => {
208
307
  const { agentId, version, ...patch } = input;
209
308
  const current = (await this.agents.get(ctx.orgId, agentId, ctx.actorAccountId))
210
309
  .definition;
@@ -215,37 +314,112 @@ let AgentsOperations = class AgentsOperations {
215
314
  ? { ...base, instructionFiles }
216
315
  : base),
217
316
  ...(patch.name !== undefined && { name: patch.name }),
317
+ ...(patch.description !== undefined && { description: patch.description }),
218
318
  ...(patch.instructions !== undefined && { instructions: patch.instructions }),
219
319
  ...(patch.model !== undefined && { model: patch.model }),
220
- ...(patch.tools !== undefined && { tools: patch.tools }),
320
+ ...(patch.disabledTools !== undefined && { disabledTools: patch.disabledTools }),
221
321
  ...(patch.toolPolicies !== undefined && { toolPolicies: patch.toolPolicies }),
222
322
  ...(patch.skills !== undefined && { skills: patch.skills }),
223
323
  ...(patch.subagents !== undefined && { subagents: patch.subagents }),
224
324
  };
225
325
  return this.agents.update(ctx.orgId, agentId, ctx.actorAccountId, { definition, expectedVersion: version }, undefined, viaAgent("agents.update", ctx));
326
+ },
327
+ }),
328
+ defineOperation({
329
+ id: "agents.update-profile",
330
+ description: "Change how an agent you may edit looks to people: its avatar (one of the preset animals, or null for none) and its quick actions (the prompts offered when a conversation starts; the list you send replaces the current one, [] clears it). Send at least one of the two. The current profile is in agents.get. The description is part of the definition: change it with agents.update. A custom avatar image is uploaded on the agents page of the web app. A change to your own private agent may be remembered by the person; a change to a shared agent is confirmed every time.",
331
+ input: z
332
+ .object({
333
+ agentId: AgentId,
334
+ // a preset only: the route's `upload` kind needs a byte upload, which stays on the web
335
+ avatar: PresetAvatar.nullable().optional(),
336
+ quickActions: Profile.quickActions,
337
+ })
338
+ .strict()
339
+ .refine((i) => i.avatar !== undefined || i.quickActions !== undefined, {
340
+ message: "Send avatar, quickActions or both",
226
341
  }),
342
+ example: {
343
+ agentId: "7c1a5b0e-9a53-4c6b-8d64-2f5a1b0c3e77",
344
+ avatar: { kind: "preset", id: "owl" },
345
+ quickActions: [
346
+ { title: "Weekly report", body: "Write this week's report from my notes." },
347
+ ],
348
+ },
349
+ authz: { orgAction: "agents.create" },
350
+ mirrors: ["PATCH /api/v1/orgs/:orgId/agents/:agentId/profile"],
351
+ // `expectedUpdatedAt` is read by the operation itself (the route takes no description: it
352
+ // is saved with the definition, agents.update). The narrower avatar (no `upload` kind)
353
+ // needs no declaration: an input that accepts less than the route passes the parity test.
354
+ omits: ["expectedUpdatedAt"],
355
+ confirm: "personal",
356
+ confirmFor: (i, ctx) => this.updateClass(i.agentId, ctx),
357
+ errors: [
358
+ {
359
+ code: "agent.not_found",
360
+ next: "Check the agent id with agents.list; only agents you can see can be changed.",
361
+ },
362
+ {
363
+ code: "forbidden",
364
+ next: {
365
+ orgAdmin: "Only the agent's owner or an org admin can change its profile.",
366
+ member: "Only the agent's owner or an org admin can change its profile; ask the owner, or an org admin.",
367
+ },
368
+ },
369
+ {
370
+ code: "agent.profile_conflict",
371
+ next: "Someone changed the profile while you were waiting: read it again with agents.get, then call again.",
372
+ },
373
+ ],
374
+ precheck: async (i, ctx) => {
375
+ const { agent: _a, ...check } = await this.editCheck(i.agentId, ctx);
376
+ return check;
377
+ },
378
+ summary: async (i, ctx) => {
379
+ const a = await orElse(() => this.agents.get(ctx.orgId, i.agentId, ctx.actorAccountId), null);
380
+ const n = named(a?.definition.name ?? i.agentId);
381
+ const c = profileChanges(i);
382
+ return a?.visibility === "private"
383
+ ? {
384
+ zh: `修改私有智能体「${n}」的资料:${c.zh.join(";")}`,
385
+ en: `Update the profile of private agent "${n}": ${c.en.join("; ")}`,
386
+ }
387
+ : {
388
+ zh: `修改共享智能体「${n}」的资料:${c.zh.join(";")}`,
389
+ en: `Update the profile of shared agent "${n}": ${c.en.join("; ")}`,
390
+ };
391
+ },
392
+ run: async (input, ctx) => {
393
+ // the profile as of now: the person approved this change, not a guard on an earlier read
394
+ const current = await this.agents.get(ctx.orgId, input.agentId, ctx.actorAccountId);
395
+ const profile = await this.profiles.update(ctx.orgId, input.agentId, ctx.actorAccountId, {
396
+ ...(input.avatar !== undefined && { avatar: input.avatar }),
397
+ ...(input.quickActions !== undefined && { quickActions: input.quickActions }),
398
+ }, current.profile.updatedAt, undefined, viaAgent("agents.update-profile", ctx));
399
+ return { id: input.agentId, profile };
400
+ },
227
401
  }),
228
402
  defineOperation({
229
403
  id: "agents.preview-from-template",
230
404
  description: "Preview creating an agent from an agent template: what carries over, what is pending (connectors the org has not set up) or unavailable, the model that would be used, and a previewHash. agents.create-from-template needs that hash.",
231
- input: z.object({ templateId: Id }).strict(),
405
+ input: AgentFromTemplatePreviewBody,
232
406
  example: { templateId: "5d0c7a52-3a0e-4f0a-bd0a-0f8c3d2a9e10" },
233
407
  authz: { orgAction: "agents.create" },
234
408
  mirrors: ["POST /api/v1/orgs/:orgId/agents/from-template/preview"],
235
409
  confirm: "read",
236
- run: async (input, ctx) => asToolError(() => this.fromTemplate.preview(ctx.orgId, input.templateId)),
410
+ run: async (input, ctx) => this.fromTemplate.preview(ctx.orgId, input.templateId),
237
411
  }),
238
412
  defineOperation({
239
413
  id: "agents.create-from-template",
240
414
  description: "Create a private agent from an agent template, with the previewHash of agents.preview-from-template; a changed template or org makes the hash stale and the preview must be redone. Connectors the template needs that the org lacks become pending entries and a setup request goes to the org admins. Agents created with the Platform tool are private; sharing an agent with the org or with members is done on the agents page of the web app.",
241
- input: z
242
- .object({
243
- templateId: Id,
244
- name: z.string().min(1).max(80),
245
- previewHash: z.string().min(1).max(100),
246
- model: Model.optional(),
247
- visibility: z.string().max(40).optional(),
415
+ input: AgentFromTemplateBody.pick({
416
+ templateId: true,
417
+ name: true,
418
+ previewHash: true,
419
+ visibility: true,
248
420
  })
421
+ // the model with bounded strings (the route's are not)
422
+ .extend({ model: Model.optional() })
249
423
  .strict(),
250
424
  example: {
251
425
  templateId: "5d0c7a52-3a0e-4f0a-bd0a-0f8c3d2a9e10",
@@ -254,13 +428,41 @@ let AgentsOperations = class AgentsOperations {
254
428
  },
255
429
  authz: { orgAction: "agents.create" },
256
430
  mirrors: ["POST /api/v1/orgs/:orgId/agents/from-template"],
431
+ // a members agent and its avatar are set on the web
432
+ omits: ["members", "avatar"],
257
433
  confirm: "personal",
258
434
  errors: [
259
435
  {
260
436
  code: "agent.template_preview_stale",
261
437
  next: "Call agents.preview-from-template again and use its new previewHash.",
262
438
  },
439
+ {
440
+ code: "component.not_found",
441
+ next: "Check the template id with agent-templates.list; this org cannot use that template.",
442
+ },
443
+ {
444
+ code: "agent.model_unavailable",
445
+ next: {
446
+ superAdmin: "No model is set up: configure a model provider in the admin console, then call again.",
447
+ orgAdmin: "No model is available in this deployment; ask the super admin to set one up.",
448
+ member: "No model is available in this deployment; ask an org admin.",
449
+ },
450
+ },
451
+ {
452
+ code: "agent.visibility_web_only",
453
+ next: "Leave visibility out (the agent is private), and share it on the agents page of the web app.",
454
+ },
263
455
  ],
456
+ precheck: async (i, ctx) => {
457
+ if (i.visibility !== undefined && i.visibility !== "private") {
458
+ return { ok: false, code: "agent.visibility_web_only", message: WEB_ONLY };
459
+ }
460
+ return precheckBy(() => this.fromTemplate.check(ctx.orgId, {
461
+ templateId: i.templateId,
462
+ previewHash: i.previewHash,
463
+ ...(i.model !== undefined && { model: i.model }),
464
+ }));
465
+ },
264
466
  summary: async (i, ctx) => {
265
467
  const t = named(await orElse(async () => (await this.orgTemplates.detail(ctx.orgId, i.templateId)).name, i.templateId));
266
468
  return {
@@ -272,15 +474,230 @@ let AgentsOperations = class AgentsOperations {
272
474
  if (input.visibility !== undefined && input.visibility !== "private") {
273
475
  throw new ToolError(WEB_ONLY);
274
476
  }
275
- return asToolError(() => this.fromTemplate.create(ctx.orgId, ctx.actorAccountId, {
477
+ return this.fromTemplate.create(ctx.orgId, ctx.actorAccountId, {
276
478
  templateId: input.templateId,
277
479
  name: input.name,
278
480
  previewHash: input.previewHash,
279
481
  visibility: "private",
280
482
  ...(input.model !== undefined && { model: input.model }),
281
- }, undefined, viaAgent("agents.create-from-template", ctx)));
483
+ }, undefined, viaAgent("agents.create-from-template", ctx));
484
+ },
485
+ }),
486
+ defineOperation({
487
+ id: "agents.delete",
488
+ description: "Delete an agent you may edit: your own, and as an org admin any agent of the org. Its conversations stay readable but it can no longer be used, its eval runs stop and its pending skill changes are cancelled. The person confirms every delete; it is never remembered. The agent you are running as cannot be deleted.",
489
+ input: z.object({ agentId: AgentId }).strict(),
490
+ example: { agentId: "7c1a5b0e-9a53-4c6b-8d64-2f5a1b0c3e77" },
491
+ authz: { orgAction: "agents.create" },
492
+ mirrors: ["DELETE /api/v1/orgs/:orgId/agents/:agentId"],
493
+ confirm: "personal",
494
+ // destructive: asked every time and never remembered, a shared agent as an org write
495
+ rememberable: false,
496
+ confirmFor: (i, ctx) => this.updateClass(i.agentId, ctx),
497
+ errors: [
498
+ {
499
+ code: "agent.not_found",
500
+ next: "Check the agent id with agents.list; you can only delete agents you own, and org admins any agent of the org.",
501
+ },
502
+ {
503
+ code: "forbidden",
504
+ next: {
505
+ orgAdmin: "Only the agent's owner or an org admin can delete it.",
506
+ member: "Only the agent's owner or an org admin can delete it; ask one of them.",
507
+ },
508
+ },
509
+ {
510
+ code: "agent.delete_current",
511
+ next: "This is the agent you are running as: ask the person to delete it on the agents page of the web app, or delete a different agent.",
512
+ },
513
+ ],
514
+ precheck: async (i, ctx) => {
515
+ // the run's agent is the root conversation's: a sub-agent runs under its parent's agent
516
+ const rootId = await rootConversationOf(this.kdb.db, ctx.conversationId);
517
+ const root = await this.kdb.db
518
+ .selectFrom("conversations")
519
+ .select("agent_id")
520
+ .where("id", "=", rootId)
521
+ .executeTakeFirst();
522
+ if (i.agentId === ctx.agentId || i.agentId === root?.agent_id) {
523
+ return {
524
+ ok: false,
525
+ code: "agent.delete_current",
526
+ message: "The agent you are running as cannot be deleted from here.",
527
+ };
528
+ }
529
+ const { agent: _a, ...check } = await this.editCheck(i.agentId, ctx);
530
+ return check;
531
+ },
532
+ summary: async (i, ctx) => {
533
+ const a = await orElse(() => this.agents.get(ctx.orgId, i.agentId, ctx.actorAccountId), null);
534
+ const n = named(a?.definition.name ?? i.agentId);
535
+ return a?.visibility === "private"
536
+ ? { zh: `删除私有智能体「${n}」`, en: `Delete private agent "${n}"` }
537
+ : { zh: `删除共享智能体「${n}」`, en: `Delete shared agent "${n}"` };
538
+ },
539
+ run: async (input, ctx) => {
540
+ await this.agents.softDelete(ctx.orgId, input.agentId, ctx.actorAccountId, undefined, viaAgent("agents.delete", ctx));
541
+ return { id: input.agentId, deleted: true };
282
542
  },
283
543
  }),
544
+ defineOperation({
545
+ id: "agents.versions",
546
+ description: "List the versions of an agent you can see, newest first: the version number, who saved it and when. Read the definition of the current one with agents.get.",
547
+ input: z.object({ agentId: AgentId }).strict(),
548
+ example: { agentId: "7c1a5b0e-9a53-4c6b-8d64-2f5a1b0c3e77" },
549
+ authz: { orgAction: "agents.use" },
550
+ mirrors: ["GET /api/v1/orgs/:orgId/agents/:agentId/versions"],
551
+ confirm: "read",
552
+ errors: [
553
+ {
554
+ code: "agent.not_found",
555
+ next: "Check the agent id with agents.list; only agents you can see can be read.",
556
+ },
557
+ ],
558
+ run: async (input, ctx) => {
559
+ await this.agents.get(ctx.orgId, input.agentId, ctx.actorAccountId);
560
+ return { versions: await this.agents.listVersions(input.agentId) };
561
+ },
562
+ }),
563
+ defineOperation({
564
+ id: "agents.bind-connector",
565
+ description: "Bind one of the org's connectors to a pending connector of an agent (an agent created from a template waits for connectors the org lacked): the agent gets a new version with that connector's tools and the entry is gone. Needs the owner or an org admin; the connector must match the entry's template or protocol and have its tools synced. Read the pending entries from agents.get.",
566
+ input: z
567
+ .object({
568
+ agentId: AgentId,
569
+ key: PendingConnectorParams.shape.key.max(200),
570
+ connectorId: PendingConnectorBindBody.shape.connectorId,
571
+ })
572
+ .strict(),
573
+ example: {
574
+ agentId: "7c1a5b0e-9a53-4c6b-8d64-2f5a1b0c3e77",
575
+ key: "crm",
576
+ connectorId: "5d2e8f1a-0b3c-4d5e-8f9a-1b2c3d4e5f60",
577
+ },
578
+ authz: { orgAction: "agents.create" },
579
+ mirrors: ["POST /api/v1/orgs/:orgId/agents/:agentId/pending-connectors/:key/bind"],
580
+ confirm: "personal",
581
+ confirmFor: (i, ctx) => this.updateClass(i.agentId, ctx),
582
+ errors: [
583
+ {
584
+ code: "agent.pending_connector_not_found",
585
+ next: "The agent has no pending connector with this key; read its pending entries with agents.get.",
586
+ },
587
+ {
588
+ code: "agent.pending_connector_mismatch",
589
+ next: "That connector does not fit the entry (another template or protocol, no tools synced yet, or none of the entry's tools); pick another with connectors.list, or ask an org admin to set one up.",
590
+ },
591
+ { code: "connector.not_found", next: "Check the connector id with connectors.list." },
592
+ {
593
+ code: "agent.not_found",
594
+ next: "Check the agent id with agents.list; only the owner or an org admin can bind.",
595
+ },
596
+ ],
597
+ precheck: async (i, ctx) => {
598
+ const { agent: _a, ...found } = await this.editCheck(i.agentId, ctx);
599
+ if (!found.ok)
600
+ return found;
601
+ return precheckBy(() => this.connectors.get(ctx.orgId, i.connectorId, ctx.actorAccountId));
602
+ },
603
+ summary: async (i, ctx) => {
604
+ const agent = await this.agentName(ctx, i.agentId);
605
+ const c = named(await orElse(async () => (await this.connectors.get(ctx.orgId, i.connectorId, ctx.actorAccountId)).name, i.connectorId));
606
+ return {
607
+ zh: `把连接器「${c}」绑定到智能体「${agent}」的待配置连接器「${named(i.key)}」,智能体将获得新版本`,
608
+ en: `Bind connector "${c}" to pending connector "${named(i.key)}" of agent "${agent}"; the agent gets a new version`,
609
+ };
610
+ },
611
+ run: async (input, ctx) => {
612
+ const r = await this.pending.bind(ctx.orgId, input.agentId, input.key, input.connectorId, ctx.actorAccountId, undefined, viaAgent("agents.bind-connector", ctx));
613
+ return {
614
+ agent: brief(r.agent),
615
+ currentVersion: r.agent.currentVersion,
616
+ dropped: r.dropped,
617
+ };
618
+ },
619
+ }),
620
+ defineOperation({
621
+ id: "agents.request-connector-setup",
622
+ description: "Send the org admins a request to set up the connectors an agent is still waiting for (the owner or an org admin may). If a request is already pending it is returned instead of a second one. This only asks: the admins decide on the web.",
623
+ input: z.object({ agentId: AgentId }).strict(),
624
+ example: { agentId: "7c1a5b0e-9a53-4c6b-8d64-2f5a1b0c3e77" },
625
+ authz: { orgAction: "agents.create" },
626
+ mirrors: ["POST /api/v1/orgs/:orgId/agents/:agentId/pending-connectors/request"],
627
+ confirm: "personal",
628
+ errors: [
629
+ {
630
+ code: "agent.no_pending_connectors",
631
+ next: "The agent waits for no connectors; nothing to request.",
632
+ },
633
+ {
634
+ code: "agent.not_found",
635
+ next: "Check the agent id with agents.list; only the owner or an org admin can request.",
636
+ },
637
+ ],
638
+ precheck: async (i, ctx) => {
639
+ const { agent, ...check } = await this.editCheck(i.agentId, ctx);
640
+ if (!check.ok || agent === undefined)
641
+ return check;
642
+ return (agent.definition.pendingConnectors ?? []).length === 0
643
+ ? {
644
+ ok: false,
645
+ code: "agent.no_pending_connectors",
646
+ message: "The agent has no connectors waiting to be configured",
647
+ }
648
+ : { ok: true };
649
+ },
650
+ summary: async (i, ctx) => {
651
+ const n = await this.agentName(ctx, i.agentId);
652
+ return {
653
+ zh: `请求组织管理员为智能体「${n}」配置所缺的连接器`,
654
+ en: `Ask the org admins to set up the connectors agent "${n}" is waiting for`,
655
+ };
656
+ },
657
+ run: async (input, ctx) => {
658
+ const r = await this.pending.reopen(ctx.orgId, input.agentId, ctx.actorAccountId, undefined, viaAgent("agents.request-connector-setup", ctx));
659
+ return { created: r.created, request: await this.requests.view(r.id) };
660
+ },
661
+ }),
662
+ defineOperation({
663
+ id: "agents.connector-setup-status",
664
+ description: "Read the latest connector setup request of an agent, whatever its status (pending, approved, cancelled), or null when none was sent. Only the agent's owner or an org admin may read it.",
665
+ input: z.object({ agentId: AgentId }).strict(),
666
+ example: { agentId: "7c1a5b0e-9a53-4c6b-8d64-2f5a1b0c3e77" },
667
+ authz: { orgAction: "agents.use" },
668
+ mirrors: ["GET /api/v1/orgs/:orgId/agents/:agentId/pending-connectors/request"],
669
+ confirm: "read",
670
+ errors: [
671
+ {
672
+ code: "agent.not_found",
673
+ next: "Check the agent id with agents.list.",
674
+ },
675
+ {
676
+ code: "forbidden",
677
+ next: {
678
+ orgAdmin: "Only the agent's owner or an org admin can read its setup request.",
679
+ member: "Only the agent's owner or an org admin can read its setup request; ask one of them.",
680
+ },
681
+ },
682
+ ],
683
+ run: async (input, ctx) => {
684
+ const id = await this.pending.latestRequest(ctx.orgId, input.agentId, ctx.actorAccountId);
685
+ return { request: id === null ? null : await this.requests.view(id) };
686
+ },
687
+ }),
688
+ defineOperation({
689
+ id: "agents.readiness",
690
+ description: "Whether the org can run agents: modelProvider is ready when a model provider is available in the org (none otherwise), and how many agents you can see.",
691
+ input: z.object({}).strict(),
692
+ example: {},
693
+ authz: { orgAction: "org.read" },
694
+ mirrors: ["GET /api/v1/orgs/:orgId/readiness"],
695
+ confirm: "read",
696
+ run: async (_input, ctx) => ({
697
+ modelProvider: (await this.providers.hasProvider(ctx.orgId)) ? "ready" : "none",
698
+ agents: (await this.agents.listVisible(ctx.orgId, ctx.actorAccountId)).length,
699
+ }),
700
+ }),
284
701
  ]);
285
702
  }
286
703
  };
@@ -288,7 +705,13 @@ AgentsOperations = __decorate([
288
705
  Injectable(),
289
706
  __param(0, Inject(PlatformOperations)),
290
707
  __param(1, Inject(AgentsService)),
291
- __param(2, Inject(AgentsFromTemplate)),
292
- __param(3, Inject(OrgAgentTemplates))
708
+ __param(2, Inject(AgentProfileService)),
709
+ __param(3, Inject(AgentsFromTemplate)),
710
+ __param(4, Inject(OrgAgentTemplates)),
711
+ __param(5, Inject(PendingConnectorsService)),
712
+ __param(6, Inject(CatalogRequestsService)),
713
+ __param(7, Inject(ConnectorsService)),
714
+ __param(8, Inject(ProviderRegistry)),
715
+ __param(9, Inject(KernelDb))
293
716
  ], AgentsOperations);
294
717
  export { AgentsOperations };