@capybara-hq/kernel 0.1.0-rc.66 → 0.1.0-rc.67

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 (139) hide show
  1. package/bootstrap.json +0 -8
  2. package/dist/admin/admin.schemas.d.ts +3 -0
  3. package/dist/agents/admin-agents.d.ts +2 -2
  4. package/dist/agents/admin-agents.js +2 -1
  5. package/dist/agents/agent-lookup.js +2 -1
  6. package/dist/agents/agent-profile.service.d.ts +5 -2
  7. package/dist/agents/agent-profile.service.js +13 -2
  8. package/dist/agents/agents.controller.d.ts +4 -3
  9. package/dist/agents/agents.controller.js +7 -3
  10. package/dist/agents/agents.module.js +3 -0
  11. package/dist/agents/agents.schemas.d.ts +6 -6
  12. package/dist/agents/agents.service.d.ts +23 -2
  13. package/dist/agents/agents.service.js +61 -6
  14. package/dist/agents/avatar-view.d.ts +8 -0
  15. package/dist/agents/avatar-view.js +12 -0
  16. package/dist/agents/profile.d.ts +38 -13
  17. package/dist/agents/profile.js +31 -20
  18. package/dist/background/poll.job.d.ts +1 -1
  19. package/dist/background/poll.job.js +8 -6
  20. package/dist/background/tasks.service.js +1 -1
  21. package/dist/catalog/marketplaces.service.d.ts +1 -1
  22. package/dist/channels/inbound.d.ts +2 -3
  23. package/dist/channels/inbound.js +2 -3
  24. package/dist/channels/phrases.d.ts +3 -3
  25. package/dist/channels/phrases.js +3 -3
  26. package/dist/config/schema.d.ts +1 -0
  27. package/dist/config/schema.js +14 -1
  28. package/dist/conversations/conversations.service.d.ts +4 -3
  29. package/dist/conversations/conversations.service.js +4 -2
  30. package/dist/ctx/create-ctx.js +5 -2
  31. package/dist/ctx/device-provider-check.d.ts +7 -0
  32. package/dist/ctx/device-provider-check.js +21 -0
  33. package/dist/db/kernel-schema.d.ts +7 -0
  34. package/dist/devices/access.d.ts +16 -46
  35. package/dist/devices/access.js +26 -62
  36. package/dist/devices/access.module.js +2 -2
  37. package/dist/devices/conversation-devices.d.ts +38 -18
  38. package/dist/devices/conversation-devices.js +69 -51
  39. package/dist/devices/default-provider-setting.d.ts +45 -0
  40. package/dist/devices/default-provider-setting.js +59 -0
  41. package/dist/devices/device-projects.service.js +7 -2
  42. package/dist/devices/device-provider-selection.d.ts +37 -0
  43. package/dist/devices/device-provider-selection.js +86 -0
  44. package/dist/devices/device-provider-selection.module.d.ts +3 -0
  45. package/dist/devices/device-provider-selection.module.js +22 -0
  46. package/dist/devices/devices.controller.d.ts +8 -5
  47. package/dist/devices/devices.controller.js +7 -4
  48. package/dist/devices/devices.module.js +3 -1
  49. package/dist/devices/devices.schemas.js +2 -2
  50. package/dist/devices/devices.service.d.ts +72 -83
  51. package/dist/devices/devices.service.js +139 -248
  52. package/dist/devices/dto.d.ts +9 -0
  53. package/dist/devices/dto.js +15 -2
  54. package/dist/devices/label.d.ts +3 -5
  55. package/dist/devices/label.js +3 -14
  56. package/dist/devices/legacy-cleanup.job.d.ts +2 -2
  57. package/dist/devices/legacy-cleanup.job.js +6 -6
  58. package/dist/errors.d.ts +15 -1
  59. package/dist/errors.js +15 -1
  60. package/dist/extensions/guide-places.d.ts +2 -1
  61. package/dist/extensions/guide-places.js +8 -2
  62. package/dist/extensions/locks.d.ts +1 -1
  63. package/dist/extensions/locks.js +1 -1
  64. package/dist/extensions/org-config.d.ts +20 -4
  65. package/dist/extensions/org-config.js +23 -6
  66. package/dist/extensions/permission-view.d.ts +2 -2
  67. package/dist/extensions/permission-view.js +2 -2
  68. package/dist/extensions/plugin-guides.d.ts +1 -1
  69. package/dist/extensions/plugin-guides.js +11 -3
  70. package/dist/extensions/point-defaults.d.ts +14 -0
  71. package/dist/extensions/point-defaults.js +70 -47
  72. package/dist/extensions/resolve.js +7 -2
  73. package/dist/identity/settings.d.ts +8 -0
  74. package/dist/identity/settings.js +24 -1
  75. package/dist/infra/config/kernel-config.service.js +2 -0
  76. package/dist/lifecycle/kernel-lifecycle.js +7 -6
  77. package/dist/local-devices/device-routes.d.ts +1 -1
  78. package/dist/local-devices/device-routes.js +1 -1
  79. package/dist/local-devices/local-device-provider.d.ts +14 -11
  80. package/dist/local-devices/local-device-provider.js +14 -0
  81. package/dist/local-devices/local-devices.module.d.ts +4 -4
  82. package/dist/local-devices/local-devices.module.js +5 -3
  83. package/dist/local-devices/owner-report.js +2 -1
  84. package/dist/local-devices/targets.d.ts +2 -0
  85. package/dist/local-devices/targets.js +10 -0
  86. package/dist/orgs/settings.service.d.ts +26 -1
  87. package/dist/orgs/settings.service.js +44 -3
  88. package/dist/platform/ops/admin.ops.js +8 -3
  89. package/dist/platform/ops/agents.ops.d.ts +6 -1
  90. package/dist/platform/ops/agents.ops.js +38 -11
  91. package/dist/platform/ops/devices.ops.js +25 -20
  92. package/dist/platform/ops/orgs.ops.js +1 -0
  93. package/dist/platform/ops/themes.ops.js +1 -1
  94. package/dist/runtime/plugin-context.service.js +1 -12
  95. package/dist/sandbox/cloud-permission-snapshot.d.ts +2 -2
  96. package/dist/sandbox/cloud-permission-snapshot.js +3 -3
  97. package/dist/sandbox/device-reports.d.ts +50 -0
  98. package/dist/sandbox/device-reports.js +157 -0
  99. package/dist/sandbox/held-operations.d.ts +8 -8
  100. package/dist/sandbox/leases.d.ts +1 -1
  101. package/dist/sandbox/leases.js +1 -1
  102. package/dist/sandbox/operation-authority.d.ts +5 -2
  103. package/dist/sandbox/operation-authority.js +12 -11
  104. package/dist/sandbox/operation-reconcile.job.d.ts +2 -2
  105. package/dist/sandbox/operation-reconcile.job.js +5 -5
  106. package/dist/sandbox/permission-availability.d.ts +2 -2
  107. package/dist/sandbox/permission-call-types.d.ts +5 -0
  108. package/dist/sandbox/permission-facts.d.ts +2 -2
  109. package/dist/sandbox/permission-facts.js +5 -5
  110. package/dist/sandbox/providers.d.ts +23 -24
  111. package/dist/sandbox/providers.js +38 -46
  112. package/dist/sandbox/providers.module.js +3 -3
  113. package/dist/sandbox/sandbox.module.d.ts +1 -1
  114. package/dist/sandbox/sandbox.module.js +7 -2
  115. package/dist/sandbox/sandbox.service.d.ts +95 -68
  116. package/dist/sandbox/sandbox.service.js +212 -208
  117. package/dist/setup/setup-guides.service.d.ts +4 -1
  118. package/dist/setup/setup-guides.service.js +6 -1
  119. package/dist/themes/avatar-preset-key.d.ts +6 -0
  120. package/dist/themes/avatar-preset-key.js +9 -0
  121. package/dist/themes/theme-state.d.ts +29 -1
  122. package/dist/themes/theme-state.js +40 -1
  123. package/dist/themes/themes.service.d.ts +28 -1
  124. package/dist/themes/themes.service.js +36 -2
  125. package/dist/tools/builtins/image/generate.d.ts +3 -0
  126. package/dist/tools/builtins/image/generate.js +21 -11
  127. package/dist/tools/builtins/image/index.d.ts +1 -1
  128. package/dist/tools/builtins/image/index.js +1 -1
  129. package/dist/tools/builtins/sandbox/common.d.ts +36 -12
  130. package/dist/tools/builtins/sandbox/common.js +62 -18
  131. package/dist/tools/builtins/sandbox/read.d.ts +5 -2
  132. package/dist/tools/builtins/sandbox/read.js +9 -6
  133. package/dist/tools/builtins/sandbox/task-output.d.ts +2 -2
  134. package/dist/tools/builtins/sandbox/task-output.js +6 -5
  135. package/dist/tools/builtins/skill-load.js +13 -4
  136. package/dist/until-aborted.d.ts +5 -0
  137. package/dist/until-aborted.js +16 -0
  138. package/package.json +4 -4
  139. package/src/migrations/0176_device_report.sql +6 -0
package/bootstrap.json CHANGED
@@ -86,14 +86,6 @@
86
86
  "integrity": "sha512-c0DFvKKQrO3qDkwAEBoBbFhDDfktucjWCIPyh+wRWGAbrXLwz69zX8C0f6MHI0YmlM68EW+NxVM3f1w8bDHOQg==",
87
87
  "required": false
88
88
  },
89
- {
90
- "name": "sandbox-docker",
91
- "source": "npm",
92
- "npm": "@capybara-hq/plugin-sandbox-docker",
93
- "version": "0.1.0-rc.21",
94
- "integrity": "sha512-os0kmtDtTPUyBEJUNQdxfuYCwet6X7lZrIq6Dyo2hXLCV0ZkPPfONY8ctRh6+qzD52PjHC1YWKAZQesYW5I6ww==",
95
- "required": false
96
- },
97
89
  {
98
90
  "name": "todo",
99
91
  "source": "npm",
@@ -74,6 +74,9 @@ export declare const DeploymentSettingsBody: z.ZodObject<{
74
74
  open: "open";
75
75
  }>>>;
76
76
  }, z.core.$strict>>;
77
+ devicesDefaultProvider: z.ZodOptional<z.ZodObject<{
78
+ provider: z.ZodNullable<z.ZodString>;
79
+ }, z.core.$strict>>;
77
80
  attribution: z.ZodOptional<z.ZodObject<{
78
81
  commit: z.ZodOptional<z.ZodNullable<z.ZodString>>;
79
82
  pr: z.ZodOptional<z.ZodNullable<z.ZodString>>;
@@ -1,7 +1,7 @@
1
1
  import { KernelDb } from "../infra/database/kernel-db.js";
2
2
  import { AgentLookup, type AgentVisibility } from "./agent-lookup.js";
3
3
  import { type AgentDefinition } from "./definition.js";
4
- import type { AgentAvatar } from "./profile.js";
4
+ import type { AgentAvatarView } from "./profile.js";
5
5
  /** One row of the super admin's cross-org agent list (admin agents spec §3.2). */
6
6
  export interface AdminAgentRow {
7
7
  id: string;
@@ -9,7 +9,7 @@ export interface AdminAgentRow {
9
9
  orgName: string;
10
10
  /** The current version's name. */
11
11
  name: string;
12
- avatar: AgentAvatar;
12
+ avatar: AgentAvatarView;
13
13
  ownerAccountId: string;
14
14
  ownerName: string;
15
15
  ownerAvatarUrl: string | null;
@@ -15,6 +15,7 @@ import { avatarColumns, personAvatarUrl } from "../identity/account-avatar.js";
15
15
  import { KernelDb } from "../infra/database/kernel-db.js";
16
16
  import { agentSkills, builtinSkillIds, builtinSkillPlugins, linkedCopyIds, skillIdsOf, usableSkillVersions, } from "../skills/usable.js";
17
17
  import { AgentLookup } from "./agent-lookup.js";
18
+ import { avatarView } from "./avatar-view.js";
18
19
  import { skillDisabled, } from "./definition.js";
19
20
  const notFound = () => new ApiError("agent.not_found", "Agent not found");
20
21
  /**
@@ -216,7 +217,7 @@ function toRow(r, skillsOff) {
216
217
  orgId: r.org_id,
217
218
  orgName: r.org_name,
218
219
  name: r.name,
219
- avatar: (r.profile_avatar ?? null),
220
+ avatar: avatarView((r.profile_avatar ?? null)),
220
221
  ownerAccountId: r.owner_account_id,
221
222
  ownerName: r.owner_name,
222
223
  ownerAvatarUrl: personAvatarUrl(r, "owner", r.owner_account_id),
@@ -11,6 +11,7 @@ import { Inject, Injectable, Module } from "@nestjs/common";
11
11
  import { sql } from "kysely";
12
12
  import { ApiError } from "../errors.js";
13
13
  import { KernelDb } from "../infra/database/kernel-db.js";
14
+ import { avatarView } from "./avatar-view.js";
14
15
  import { normalizeStoredDefinition } from "./definition.js";
15
16
  export const AGENT_VISIBILITIES = ["private", "org", "members"];
16
17
  const notFound = () => new ApiError("agent.not_found", "Agent not found");
@@ -181,7 +182,7 @@ let AgentLookup = class AgentLookup {
181
182
  currentVersion: r.current_version,
182
183
  definition: normalizeStoredDefinition(r.definition),
183
184
  profile: {
184
- avatar: r.profile_avatar,
185
+ avatar: avatarView(r.profile_avatar),
185
186
  description: r.profile_description,
186
187
  quickActions: r.profile_quick_actions,
187
188
  updatedAt: r.profile_updated_at.toISOString(),
@@ -16,7 +16,7 @@ export declare class AgentProfileService {
16
16
  private readonly agents;
17
17
  private readonly attachments;
18
18
  readonly txHost: TransactionHost;
19
- constructor(db: KernelDb, lookup: AgentLookup, agents: Pick<AgentsService, "lockForWrite">, attachments: Pick<AttachmentsService, "prepareAgentAvatar" | "consumeAgentAvatar">, txHost: TransactionHost);
19
+ constructor(db: KernelDb, lookup: AgentLookup, agents: Pick<AgentsService, "lockForWrite" | "resolveAvatarInput">, attachments: Pick<AttachmentsService, "prepareAgentAvatar" | "consumeAgentAvatar">, txHost: TransactionHost);
20
20
  /**
21
21
  * Applies `patch` (only the given fields) when `expectedUpdatedAt` is still the profile's
22
22
  * `updatedAt`, else 409 `agent.profile_conflict` (never a silent overwrite). Audit
@@ -24,7 +24,10 @@ export declare class AgentProfileService {
24
24
  * token, `agent` for a write through the `Platform` tool (`auditDetail` given), else `web`.
25
25
  * An `upload` avatar must be the actor's own upload that no other agent uses (else 404
26
26
  * `attachment.not_found`): it is finalized first (outside the transaction, it reads the object
27
- * store; 503 `storage.unavailable` without one) and bound to the agent inside it.
27
+ * store; 503 `storage.unavailable` without one) and bound to the agent inside it. A `preset`
28
+ * avatar is resolved before the transaction (`AgentsService.resolveAvatarInput`): a built-in id
29
+ * as given, a theme preset key of the org's effective default theme pinned, any other key 400
30
+ * `agent.avatar_unavailable`.
28
31
  */
29
32
  update(orgId: string, agentId: string, actorAccountId: string, patch: ProfilePatch, expectedUpdatedAt: string, actorTokenId?: string, auditDetail?: Record<string, unknown>): Promise<AgentProfile>;
30
33
  private updateIn;
@@ -43,13 +43,24 @@ let AgentProfileService = class AgentProfileService {
43
43
  * token, `agent` for a write through the `Platform` tool (`auditDetail` given), else `web`.
44
44
  * An `upload` avatar must be the actor's own upload that no other agent uses (else 404
45
45
  * `attachment.not_found`): it is finalized first (outside the transaction, it reads the object
46
- * store; 503 `storage.unavailable` without one) and bound to the agent inside it.
46
+ * store; 503 `storage.unavailable` without one) and bound to the agent inside it. A `preset`
47
+ * avatar is resolved before the transaction (`AgentsService.resolveAvatarInput`): a built-in id
48
+ * as given, a theme preset key of the org's effective default theme pinned, any other key 400
49
+ * `agent.avatar_unavailable`.
47
50
  */
48
51
  async update(orgId, agentId, actorAccountId, patch, expectedUpdatedAt, actorTokenId, auditDetail) {
52
+ // reads before the transaction: a theme key resolves against this org's presets only
53
+ const avatar = patch.avatar == null
54
+ ? patch.avatar
55
+ : await this.agents.resolveAvatarInput(orgId, patch.avatar);
49
56
  if (patch.avatar?.kind === "upload") {
50
57
  await this.attachments.prepareAgentAvatar(orgId, actorAccountId, patch.avatar.uploadId, agentId);
51
58
  }
52
- return this.updateIn(orgId, agentId, actorAccountId, patch, expectedUpdatedAt, actorTokenId, auditDetail);
59
+ const stored = {
60
+ ...(avatar !== undefined && { avatar }),
61
+ ...(patch.quickActions !== undefined && { quickActions: patch.quickActions }),
62
+ };
63
+ return this.updateIn(orgId, agentId, actorAccountId, stored, expectedUpdatedAt, actorTokenId, auditDetail);
53
64
  }
54
65
  async updateIn(orgId, agentId, actorAccountId, patch, expectedUpdatedAt, actorTokenId, auditDetail) {
55
66
  const t = this.db.db;
@@ -64,9 +64,10 @@ export declare class AgentsController {
64
64
  */
65
65
  createAvatarUpload(principal: Principal, org: OrgContext, agentId: string, body: z.infer<typeof AvatarUploadBody>): Promise<CreatedAttachment>;
66
66
  /**
67
- * The avatar image: 302 to a short-lived presigned URL for an upload avatar, or to the stored
68
- * URL of an external avatar when it is https; 404 for presets, no avatar, or an agent the
69
- * reader cannot see.
67
+ * The avatar image: 302 to a short-lived presigned URL for an upload avatar, to the pinned theme
68
+ * asset URL of a theme avatar (same origin, immutable), or to the stored URL of an external
69
+ * avatar when it is https; 404 for built-in presets, no avatar, or an agent the reader cannot
70
+ * see.
70
71
  */
71
72
  avatar(principal: Principal, org: OrgContext, agentId: string, reply: FastifyReply): Promise<void>;
72
73
  remove(principal: Principal, org: OrgContext, agentId: string): Promise<void>;
@@ -126,9 +126,10 @@ let AgentsController = class AgentsController {
126
126
  return this.attachments.create(org.orgId, p.account.id, body, "agent-avatar");
127
127
  }
128
128
  /**
129
- * The avatar image: 302 to a short-lived presigned URL for an upload avatar, or to the stored
130
- * URL of an external avatar when it is https; 404 for presets, no avatar, or an agent the
131
- * reader cannot see.
129
+ * The avatar image: 302 to a short-lived presigned URL for an upload avatar, to the pinned theme
130
+ * asset URL of a theme avatar (same origin, immutable), or to the stored URL of an external
131
+ * avatar when it is https; 404 for built-in presets, no avatar, or an agent the reader cannot
132
+ * see.
132
133
  */
133
134
  async avatar(principal, org, agentId, reply) {
134
135
  const view = await this.agents.get(org.orgId, agentId, viewerOf(principal));
@@ -137,6 +138,9 @@ let AgentsController = class AgentsController {
137
138
  if (avatar?.kind === "upload") {
138
139
  location = await this.attachments.agentAvatarUrl(org.orgId, agentId, avatar.uploadId);
139
140
  }
141
+ else if (avatar?.kind === "theme") {
142
+ location = avatar.url;
143
+ }
140
144
  else if (avatar?.kind === "external") {
141
145
  try {
142
146
  if (new URL(avatar.url).protocol === "https:")
@@ -13,6 +13,7 @@ import { ModelsModule } from "../models/models.module.js";
13
13
  import { OrgLockModule } from "../orgs/org-lock.js";
14
14
  import { ProvidersModule } from "../runtime/providers.js";
15
15
  import { SkillsModule } from "../skills/skills.module.js";
16
+ import { ThemesModule } from "../themes/themes.module.js";
16
17
  import { ToolsModule } from "../tools/tools.module.js";
17
18
  import { AdminAgents } from "./admin-agents.js";
18
19
  import { AgentLookupModule } from "./agent-lookup.js";
@@ -52,6 +53,8 @@ AgentsModule = __decorate([
52
53
  ModelsModule,
53
54
  // the agent delete records `agent.deleted` deliveries
54
55
  LifecycleHooksModule,
56
+ // the avatar presets of the org's default theme: avatar inputs and the random default
57
+ ThemesModule,
55
58
  ],
56
59
  providers: [
57
60
  AgentsService,
@@ -210,7 +210,7 @@ export declare const AgentCreateBody: z.ZodObject<{
210
210
  profile: z.ZodOptional<z.ZodObject<{
211
211
  avatar: z.ZodOptional<z.ZodNullable<z.ZodDiscriminatedUnion<[z.ZodObject<{
212
212
  kind: z.ZodLiteral<"preset">;
213
- id: z.ZodEnum<{
213
+ id: z.ZodUnion<readonly [z.ZodEnum<{
214
214
  "black-bear": "black-bear";
215
215
  capybara: "capybara";
216
216
  elephant: "elephant";
@@ -221,7 +221,7 @@ export declare const AgentCreateBody: z.ZodObject<{
221
221
  rabbit: "rabbit";
222
222
  turtle: "turtle";
223
223
  whale: "whale";
224
- }>;
224
+ }>, z.ZodString]>;
225
225
  }, z.core.$strict>, z.ZodObject<{
226
226
  kind: z.ZodLiteral<"upload">;
227
227
  uploadId: z.ZodString;
@@ -370,7 +370,7 @@ export declare const AgentUpdateBody: z.ZodObject<{
370
370
  export declare const AgentProfileBody: z.ZodObject<{
371
371
  avatar: z.ZodOptional<z.ZodNullable<z.ZodDiscriminatedUnion<[z.ZodObject<{
372
372
  kind: z.ZodLiteral<"preset">;
373
- id: z.ZodEnum<{
373
+ id: z.ZodUnion<readonly [z.ZodEnum<{
374
374
  "black-bear": "black-bear";
375
375
  capybara: "capybara";
376
376
  elephant: "elephant";
@@ -381,7 +381,7 @@ export declare const AgentProfileBody: z.ZodObject<{
381
381
  rabbit: "rabbit";
382
382
  turtle: "turtle";
383
383
  whale: "whale";
384
- }>;
384
+ }>, z.ZodString]>;
385
385
  }, z.core.$strict>, z.ZodObject<{
386
386
  kind: z.ZodLiteral<"upload">;
387
387
  uploadId: z.ZodString;
@@ -420,7 +420,7 @@ export declare const AgentFromTemplateBody: z.ZodObject<{
420
420
  }, z.core.$strict>>;
421
421
  avatar: z.ZodOptional<z.ZodObject<{
422
422
  kind: z.ZodLiteral<"preset">;
423
- id: z.ZodEnum<{
423
+ id: z.ZodUnion<readonly [z.ZodEnum<{
424
424
  "black-bear": "black-bear";
425
425
  capybara: "capybara";
426
426
  elephant: "elephant";
@@ -431,7 +431,7 @@ export declare const AgentFromTemplateBody: z.ZodObject<{
431
431
  rabbit: "rabbit";
432
432
  turtle: "turtle";
433
433
  whale: "whale";
434
- }>;
434
+ }>, z.ZodString]>;
435
435
  }, z.core.$strict>>;
436
436
  previewHash: z.ZodString;
437
437
  }, z.core.$strict>;
@@ -8,12 +8,13 @@ import { OrgLock } from "../orgs/org-lock.js";
8
8
  import { type OrgRole } from "../orgs/roles.js";
9
9
  import { ProviderRegistry } from "../runtime/providers.js";
10
10
  import { SkillChangesService } from "../skills/changes.service.js";
11
+ import { ThemesService } from "../themes/themes.service.js";
11
12
  import { ToolRegistry } from "../tools/registry.js";
12
13
  import { AgentLookup, type AgentView, type AgentVisibility } from "./agent-lookup.js";
13
14
  import { type AgentDefinition, type PendingConnector } from "./definition.js";
14
15
  import { type AgentDefinitionInput } from "./instruction-files.js";
15
16
  import { PendingConnectorRequests } from "./pending-connector-requests.js";
16
- import { type ProfileInput } from "./profile.js";
17
+ import { type AgentAvatar, type AvatarInput, type ProfileInput } from "./profile.js";
17
18
  export { AGENT_VISIBILITIES, type AgentView, type AgentVisibility, isAgentVisibleTo, visibleTo, } from "./agent-lookup.js";
18
19
  export { paramIssues, SUBAGENT_ROSTER_MAX } from "./definition.js";
19
20
  export interface AgentVersion {
@@ -95,6 +96,8 @@ export declare class AgentsService {
95
96
  private readonly setupRequests;
96
97
  /** Records `agent.deleted` for the subscribing plugins in the delete's transaction. */
97
98
  private readonly lifecycle;
99
+ /** The avatar presets of the org's effective default theme (theme brand coverage spec §4). */
100
+ private readonly themes;
98
101
  constructor(db: KernelDb, lookup: AgentLookup, tools: Pick<ToolRegistry, "checkDisabled">,
99
102
  /**
100
103
  * Cancels the agent's pending skill requests: all of them when it is deleted, share requests
@@ -110,7 +113,25 @@ export declare class AgentsService {
110
113
  /** Settles the agent's connector setup request when its pending connectors change (P4-7). */
111
114
  setupRequests: Pick<PendingConnectorRequests, "settleIn" | "retargetIn">,
112
115
  /** Records `agent.deleted` for the subscribing plugins in the delete's transaction. */
113
- lifecycle: Pick<LifecycleHooks, "recordIn">);
116
+ lifecycle: Pick<LifecycleHooks, "recordIn">,
117
+ /** The avatar presets of the org's effective default theme (theme brand coverage spec §4). */
118
+ themes: Pick<ThemesService, "avatarPresets">);
119
+ /**
120
+ * The stored value of an avatar input (theme brand coverage spec §4): a built-in preset id is
121
+ * always accepted, also while the theme hides it (hidden only means "not offered"); a theme
122
+ * preset key only while it is a preset of `orgId`'s effective default theme, stored pinned to
123
+ * that theme version; else 400 `agent.avatar_unavailable`. The key is looked up among the writing
124
+ * org's presets only, never across themes, so no org can pick another org's theme preset. An
125
+ * upload passes through (its own checks bind it). A read: call it before the write's
126
+ * transaction.
127
+ */
128
+ resolveAvatarInput(orgId: string, input: AvatarInput): Promise<NonNullable<AgentAvatar>>;
129
+ /**
130
+ * The avatar of an agent created without one (theme brand coverage spec §4): uniform over the
131
+ * built-ins the org's effective default theme does not hide plus that theme's presets (pinned);
132
+ * null (no avatar: the initial) when none is visible. A read, before the create's transaction.
133
+ */
134
+ randomAvatar(orgId: string): Promise<AgentAvatar>;
114
135
  /**
115
136
  * Checks the turned-off tools and the policies (tools default-on spec §2): `disabledTools` must
116
137
  * name existing builtins, extensions and connectors (`ToolRegistry.checkDisabled`); `toolPolicies`
@@ -7,7 +7,7 @@ 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 { randomUUID } from "node:crypto";
10
+ import { randomInt, randomUUID } from "node:crypto";
11
11
  import { parseToolKey } from "@capybara-hq/plugin-sdk";
12
12
  import { Inject, Injectable } from "@nestjs/common";
13
13
  import { sql } from "kysely";
@@ -26,12 +26,13 @@ import { ProviderRegistry } from "../runtime/providers.js";
26
26
  import { SkillChangesService } from "../skills/changes.service.js";
27
27
  import { assertDisabledSkills } from "../skills/skills.service.js";
28
28
  import { agentSkills } from "../skills/usable.js";
29
+ import { ThemesService } from "../themes/themes.service.js";
29
30
  import { ToolRegistry } from "../tools/registry.js";
30
31
  import { AgentLookup, isAgentVisibleTo, visibleTo, } from "./agent-lookup.js";
31
32
  import { canonicalDisabledSkills, canonicalDisabledTools, normalizeStoredDefinition, paramIssues, SUBAGENT_NAME_RE, SUBAGENT_ROSTER_MAX, } from "./definition.js";
32
33
  import { deriveInstructions } from "./instruction-files.js";
33
34
  import { PendingConnectorRequests } from "./pending-connector-requests.js";
34
- import { randomPreset } from "./profile.js";
35
+ import { isBuiltinPresetId, PRESET_IDS, } from "./profile.js";
35
36
  import { loadTemplates, templateTypeOf } from "./templates.js";
36
37
  export { AGENT_VISIBILITIES, isAgentVisibleTo, visibleTo, } from "./agent-lookup.js";
37
38
  export { paramIssues, SUBAGENT_ROSTER_MAX } from "./definition.js";
@@ -51,6 +52,14 @@ export function assertProfileWritable(profile) {
51
52
  }
52
53
  }
53
54
  const notFound = () => new ApiError("agent.not_found", "Agent not found");
55
+ /** The stored value of a theme preset the org offers: pinned to its theme version. */
56
+ const pinnedThemeAvatar = (p) => ({
57
+ kind: "theme",
58
+ themeId: p.themeId,
59
+ version: p.version,
60
+ preset: p.preset,
61
+ file: p.file,
62
+ });
54
63
  /** A per-operation policy key of the `Platform` tool (Platform tool spec §6.2). */
55
64
  const PLATFORM_POLICY_KEY = /^Platform:[a-z][a-z-]*\.[a-z][a-z-]*$/;
56
65
  /**
@@ -278,6 +287,7 @@ let AgentsService = class AgentsService {
278
287
  evalBudget;
279
288
  setupRequests;
280
289
  lifecycle;
290
+ themes;
281
291
  constructor(db, lookup, tools,
282
292
  /**
283
293
  * Cancels the agent's pending skill requests: all of them when it is deleted, share requests
@@ -293,7 +303,9 @@ let AgentsService = class AgentsService {
293
303
  /** Settles the agent's connector setup request when its pending connectors change (P4-7). */
294
304
  setupRequests,
295
305
  /** Records `agent.deleted` for the subscribing plugins in the delete's transaction. */
296
- lifecycle) {
306
+ lifecycle,
307
+ /** The avatar presets of the org's effective default theme (theme brand coverage spec §4). */
308
+ themes) {
297
309
  this.db = db;
298
310
  this.lookup = lookup;
299
311
  this.tools = tools;
@@ -304,6 +316,43 @@ let AgentsService = class AgentsService {
304
316
  this.evalBudget = evalBudget;
305
317
  this.setupRequests = setupRequests;
306
318
  this.lifecycle = lifecycle;
319
+ this.themes = themes;
320
+ }
321
+ /**
322
+ * The stored value of an avatar input (theme brand coverage spec §4): a built-in preset id is
323
+ * always accepted, also while the theme hides it (hidden only means "not offered"); a theme
324
+ * preset key only while it is a preset of `orgId`'s effective default theme, stored pinned to
325
+ * that theme version; else 400 `agent.avatar_unavailable`. The key is looked up among the writing
326
+ * org's presets only, never across themes, so no org can pick another org's theme preset. An
327
+ * upload passes through (its own checks bind it). A read: call it before the write's
328
+ * transaction.
329
+ */
330
+ async resolveAvatarInput(orgId, input) {
331
+ if (input.kind === "upload")
332
+ return { kind: "upload", uploadId: input.uploadId };
333
+ if (isBuiltinPresetId(input.id))
334
+ return { kind: "preset", id: input.id };
335
+ const p = (await this.themes.avatarPresets(orgId)).presets.find((x) => x.key === input.id);
336
+ if (p === undefined) {
337
+ throw new ApiError("agent.avatar_unavailable", `Avatar preset ${input.id} is not offered in this organization; choose one of the presets the picker shows`);
338
+ }
339
+ return pinnedThemeAvatar(p);
340
+ }
341
+ /**
342
+ * The avatar of an agent created without one (theme brand coverage spec §4): uniform over the
343
+ * built-ins the org's effective default theme does not hide plus that theme's presets (pinned);
344
+ * null (no avatar: the initial) when none is visible. A read, before the create's transaction.
345
+ */
346
+ async randomAvatar(orgId) {
347
+ const { hidden, presets } = await this.themes.avatarPresets(orgId);
348
+ const pool = [
349
+ ...PRESET_IDS.filter((id) => !hidden.includes(id)).map((id) => ({
350
+ kind: "preset",
351
+ id,
352
+ })),
353
+ ...presets.map(pinnedThemeAvatar),
354
+ ];
355
+ return pool.length === 0 ? null : (pool[randomInt(pool.length)] ?? null);
307
356
  }
308
357
  /**
309
358
  * Checks the turned-off tools and the policies (tools default-on spec §2): `disabledTools` must
@@ -440,7 +489,12 @@ let AgentsService = class AgentsService {
440
489
  throw new ApiError("validation_failed", "memberIds requires visibility 'members'");
441
490
  }
442
491
  assertProfileWritable(input.profile);
443
- const { agent, role } = await this.createIn(orgId, actorAccountId, input, toolKeys, template, actorTokenId, auditDetail);
492
+ // reads before the transaction: a theme key resolves against this org's presets only
493
+ const avatarInput = input.profile?.avatar;
494
+ const avatar = avatarInput == null
495
+ ? await this.randomAvatar(orgId)
496
+ : await this.resolveAvatarInput(orgId, avatarInput);
497
+ const { agent, role } = await this.createIn(orgId, actorAccountId, { ...input, avatar }, toolKeys, template, actorTokenId, auditDetail);
444
498
  return { agent, warnings, role };
445
499
  }
446
500
  async createIn(orgId, actorAccountId, input, toolKeys, template, actorTokenId, auditDetail) {
@@ -474,7 +528,7 @@ let AgentsService = class AgentsService {
474
528
  owner_account_id: actorAccountId,
475
529
  visibility: input.visibility,
476
530
  current_version: 1,
477
- profile_avatar: JSON.stringify(input.profile?.avatar ?? { kind: "preset", id: randomPreset() }),
531
+ profile_avatar: input.avatar === null ? null : JSON.stringify(input.avatar),
478
532
  profile_description: input.definition.description ?? "",
479
533
  profile_quick_actions: JSON.stringify(input.profile?.quickActions ?? []),
480
534
  ...(template !== null && {
@@ -905,6 +959,7 @@ AgentsService = __decorate([
905
959
  __param(6, Inject(TransactionHost)),
906
960
  __param(7, Inject(EvalBudget)),
907
961
  __param(8, Inject(PendingConnectorRequests)),
908
- __param(9, Inject(LifecycleHooks))
962
+ __param(9, Inject(LifecycleHooks)),
963
+ __param(10, Inject(ThemesService))
909
964
  ], AgentsService);
910
965
  export { AgentsService };
@@ -0,0 +1,8 @@
1
+ import type { AgentAvatar, AgentAvatarView } from "./profile.js";
2
+ /**
3
+ * An agent's stored avatar as the agent API returns it (theme brand coverage spec §4): a `theme`
4
+ * avatar gains `url`, the immutable asset URL of the theme version it is pinned to (served after
5
+ * the theme updates or leaves the org); every other kind as stored. The one mapping for every view
6
+ * that returns an agent avatar (agent lookup, admin agents, conversation groups).
7
+ */
8
+ export declare function avatarView(stored: AgentAvatar): AgentAvatarView;
@@ -0,0 +1,12 @@
1
+ import { themeUrl } from "../themes/theme-state.js";
2
+ /**
3
+ * An agent's stored avatar as the agent API returns it (theme brand coverage spec §4): a `theme`
4
+ * avatar gains `url`, the immutable asset URL of the theme version it is pinned to (served after
5
+ * the theme updates or leaves the org); every other kind as stored. The one mapping for every view
6
+ * that returns an agent avatar (agent lookup, admin agents, conversation groups).
7
+ */
8
+ export function avatarView(stored) {
9
+ if (stored?.kind !== "theme")
10
+ return stored;
11
+ return { ...stored, url: themeUrl(stored.themeId, stored.version, stored.file) };
12
+ }
@@ -1,15 +1,16 @@
1
+ import { type BuiltinAvatarPresetId } from "@capybara-hq/plugin-sdk";
1
2
  import { z } from "zod";
2
3
  /** The ten built-in pixel-animal avatars (drawn by `@capybara-hq/design`). */
3
4
  export declare const PRESET_IDS: readonly ["capybara", "black-bear", "panda", "elephant", "fox", "owl", "penguin", "rabbit", "turtle", "whale"];
4
- export type PresetId = (typeof PRESET_IDS)[number];
5
+ export type PresetId = BuiltinAvatarPresetId;
6
+ /** Whether `id` is a built-in preset id (else, in an avatar input, a theme preset key). */
7
+ export declare const isBuiltinPresetId: (id: string) => id is PresetId;
5
8
  export declare const PROFILE_LIMITS: {
6
9
  readonly description: 500;
7
10
  readonly quickActions: 9;
8
11
  readonly title: 40;
9
12
  readonly body: 20000;
10
13
  };
11
- /** A random preset id: the avatar of an agent created without one. */
12
- export declare function randomPreset(): PresetId;
13
14
  export declare const AgentAvatarSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
14
15
  kind: z.ZodLiteral<"preset">;
15
16
  id: z.ZodEnum<{
@@ -27,12 +28,31 @@ export declare const AgentAvatarSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
27
28
  }, z.core.$strict>, z.ZodObject<{
28
29
  kind: z.ZodLiteral<"upload">;
29
30
  uploadId: z.ZodString;
31
+ }, z.core.$strict>, z.ZodObject<{
32
+ kind: z.ZodLiteral<"theme">;
33
+ themeId: z.ZodString;
34
+ version: z.ZodString;
35
+ preset: z.ZodString;
36
+ file: z.ZodString;
30
37
  }, z.core.$strict>, z.ZodObject<{
31
38
  kind: z.ZodLiteral<"external">;
32
39
  url: z.ZodURL;
33
40
  }, z.core.$strict>], "kind">;
34
- /** `null` only for agents created before profiles existed. */
41
+ /**
42
+ * A stored avatar; `null`: no avatar (agents created before profiles existed, or a random default
43
+ * with no preset visible).
44
+ */
35
45
  export type AgentAvatar = z.infer<typeof AgentAvatarSchema> | null;
46
+ /** A theme preset as stored: pinned to the theme version it was chosen from. */
47
+ export type ThemeAvatar = Extract<z.infer<typeof AgentAvatarSchema>, {
48
+ kind: "theme";
49
+ }>;
50
+ /** An avatar as the agent API returns it: a `theme` one carries its immutable asset URL. */
51
+ export type AgentAvatarView = Exclude<z.infer<typeof AgentAvatarSchema>, {
52
+ kind: "theme";
53
+ }> | (ThemeAvatar & {
54
+ url: string;
55
+ }) | null;
36
56
  export declare const QuickActionSchema: z.ZodObject<{
37
57
  title: z.ZodString;
38
58
  body: z.ZodString;
@@ -43,11 +63,14 @@ export declare const QuickActionsSchema: z.ZodArray<z.ZodObject<{
43
63
  title: z.ZodString;
44
64
  body: z.ZodString;
45
65
  }, z.core.$strict>>;
46
- /** What a client may write (`external` is migrated data only). */
47
- /** A preset avatar: the only kind the `Platform` tool sets (an upload is the web's). */
66
+ /**
67
+ * A preset avatar: the only kind the `Platform` tool sets (an upload is the web's). `id` is a
68
+ * built-in preset id or a theme preset key ({@link THEME_PRESET_KEY_RE}; the org's theme listing
69
+ * returns the keys it offers).
70
+ */
48
71
  export declare const PresetAvatarSchema: z.ZodObject<{
49
72
  kind: z.ZodLiteral<"preset">;
50
- id: z.ZodEnum<{
73
+ id: z.ZodUnion<readonly [z.ZodEnum<{
51
74
  "black-bear": "black-bear";
52
75
  capybara: "capybara";
53
76
  elephant: "elephant";
@@ -58,11 +81,12 @@ export declare const PresetAvatarSchema: z.ZodObject<{
58
81
  rabbit: "rabbit";
59
82
  turtle: "turtle";
60
83
  whale: "whale";
61
- }>;
84
+ }>, z.ZodString]>;
62
85
  }, z.core.$strict>;
86
+ /** What a client may write (`external` is migrated data only, `theme` the kernel's). */
63
87
  export declare const AvatarInputSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
64
88
  kind: z.ZodLiteral<"preset">;
65
- id: z.ZodEnum<{
89
+ id: z.ZodUnion<readonly [z.ZodEnum<{
66
90
  "black-bear": "black-bear";
67
91
  capybara: "capybara";
68
92
  elephant: "elephant";
@@ -73,7 +97,7 @@ export declare const AvatarInputSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
73
97
  rabbit: "rabbit";
74
98
  turtle: "turtle";
75
99
  whale: "whale";
76
- }>;
100
+ }>, z.ZodString]>;
77
101
  }, z.core.$strict>, z.ZodObject<{
78
102
  kind: z.ZodLiteral<"upload">;
79
103
  uploadId: z.ZodString;
@@ -81,7 +105,7 @@ export declare const AvatarInputSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
81
105
  export declare const ProfileInputSchema: z.ZodObject<{
82
106
  avatar: z.ZodOptional<z.ZodNullable<z.ZodDiscriminatedUnion<[z.ZodObject<{
83
107
  kind: z.ZodLiteral<"preset">;
84
- id: z.ZodEnum<{
108
+ id: z.ZodUnion<readonly [z.ZodEnum<{
85
109
  "black-bear": "black-bear";
86
110
  capybara: "capybara";
87
111
  elephant: "elephant";
@@ -92,7 +116,7 @@ export declare const ProfileInputSchema: z.ZodObject<{
92
116
  rabbit: "rabbit";
93
117
  turtle: "turtle";
94
118
  whale: "whale";
95
- }>;
119
+ }>, z.ZodString]>;
96
120
  }, z.core.$strict>, z.ZodObject<{
97
121
  kind: z.ZodLiteral<"upload">;
98
122
  uploadId: z.ZodString;
@@ -106,8 +130,9 @@ export declare const ProfileInputSchema: z.ZodObject<{
106
130
  export type ProfileInput = z.infer<typeof ProfileInputSchema>;
107
131
  /** What `PATCH …/profile` writes: the description is saved with the definition (run context §3.5). */
108
132
  export type ProfilePatch = Omit<ProfileInput, "description">;
133
+ export type AvatarInput = z.infer<typeof AvatarInputSchema>;
109
134
  export interface AgentProfile {
110
- avatar: AgentAvatar;
135
+ avatar: AgentAvatarView;
111
136
  description: string;
112
137
  quickActions: QuickAction[];
113
138
  updatedAt: string;
@@ -1,31 +1,30 @@
1
- import { randomInt } from "node:crypto";
1
+ import { BUILTIN_AVATAR_PRESET_IDS, THEME_AVATAR_ID_RE, } from "@capybara-hq/plugin-sdk";
2
2
  import { z } from "zod";
3
+ import { THEME_PRESET_KEY_RE } from "../themes/avatar-preset-key.js";
3
4
  /** The ten built-in pixel-animal avatars (drawn by `@capybara-hq/design`). */
4
- export const PRESET_IDS = [
5
- "capybara",
6
- "black-bear",
7
- "panda",
8
- "elephant",
9
- "fox",
10
- "owl",
11
- "penguin",
12
- "rabbit",
13
- "turtle",
14
- "whale",
15
- ];
5
+ export const PRESET_IDS = BUILTIN_AVATAR_PRESET_IDS;
6
+ /** Whether `id` is a built-in preset id (else, in an avatar input, a theme preset key). */
7
+ export const isBuiltinPresetId = (id) => PRESET_IDS.includes(id);
16
8
  export const PROFILE_LIMITS = {
17
9
  description: 500,
18
10
  quickActions: 9,
19
11
  title: 40,
20
12
  body: 20_000,
21
13
  };
22
- /** A random preset id: the avatar of an agent created without one. */
23
- export function randomPreset() {
24
- return PRESET_IDS[randomInt(PRESET_IDS.length)];
25
- }
26
14
  export const AgentAvatarSchema = z.discriminatedUnion("kind", [
27
15
  z.object({ kind: z.literal("preset"), id: z.enum(PRESET_IDS) }).strict(),
28
16
  z.object({ kind: z.literal("upload"), uploadId: z.string().min(1).max(200) }).strict(),
17
+ // a theme preset pinned to the theme version it was chosen from (theme brand coverage spec §4);
18
+ // only produced by the kernel from a preset key, never accepted from a client
19
+ z
20
+ .object({
21
+ kind: z.literal("theme"),
22
+ themeId: z.string().min(1).max(200),
23
+ version: z.string().min(1).max(64),
24
+ preset: z.string().regex(THEME_AVATAR_ID_RE),
25
+ file: z.string().min(1).max(512),
26
+ })
27
+ .strict(),
29
28
  // only produced by the migration of `definition.avatarUrl`; never accepted from a client
30
29
  z.object({ kind: z.literal("external"), url: z.url() }).strict(),
31
30
  ]);
@@ -37,11 +36,23 @@ export const QuickActionSchema = z
37
36
  .strict();
38
37
  export const DescriptionSchema = z.string().max(PROFILE_LIMITS.description);
39
38
  export const QuickActionsSchema = z.array(QuickActionSchema).max(PROFILE_LIMITS.quickActions);
40
- /** What a client may write (`external` is migrated data only). */
41
- /** A preset avatar: the only kind the `Platform` tool sets (an upload is the web's). */
39
+ /**
40
+ * A preset avatar: the only kind the `Platform` tool sets (an upload is the web's). `id` is a
41
+ * built-in preset id or a theme preset key ({@link THEME_PRESET_KEY_RE}; the org's theme listing
42
+ * returns the keys it offers).
43
+ */
42
44
  export const PresetAvatarSchema = z
43
- .object({ kind: z.literal("preset"), id: z.enum(PRESET_IDS) })
45
+ .object({
46
+ kind: z.literal("preset"),
47
+ id: z.union([
48
+ z.enum(PRESET_IDS),
49
+ z.string().regex(THEME_PRESET_KEY_RE, {
50
+ message: "id must be a built-in preset id or a theme preset key <plugin>/<theme>/<preset> from the org's theme listing (avatars.presets[].key)",
51
+ }),
52
+ ]),
53
+ })
44
54
  .strict();
55
+ /** What a client may write (`external` is migrated data only, `theme` the kernel's). */
45
56
  export const AvatarInputSchema = z.discriminatedUnion("kind", [
46
57
  PresetAvatarSchema,
47
58
  z.object({ kind: z.literal("upload"), uploadId: z.string().min(1).max(200) }).strict(),