@capybara-hq/kernel 0.1.0-rc.59 → 0.1.0-rc.60

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/dist/admin/admin.controller.d.ts +10 -5
  2. package/dist/admin/admin.controller.js +16 -7
  3. package/dist/admin/admin.schemas.js +2 -1
  4. package/dist/admin/audit-log.service.d.ts +1 -0
  5. package/dist/admin/audit-log.service.js +4 -1
  6. package/dist/admin/extensions.schemas.js +2 -0
  7. package/dist/agents/admin-agents.d.ts +1 -0
  8. package/dist/agents/admin-agents.js +4 -1
  9. package/dist/agents/agents.controller.d.ts +1 -10
  10. package/dist/agents/agents.controller.js +2 -14
  11. package/dist/agents/agents.schemas.d.ts +10 -0
  12. package/dist/agents/agents.schemas.js +19 -0
  13. package/dist/background/tasks.service.d.ts +5 -0
  14. package/dist/background/tasks.service.js +10 -3
  15. package/dist/catalog/admin-catalog.schemas.js +2 -0
  16. package/dist/catalog/component-scope.schemas.js +2 -0
  17. package/dist/catalog/marketplaces.service.d.ts +1 -1
  18. package/dist/catalog/org-plugin-uploads.schemas.js +2 -0
  19. package/dist/catalog/requests.service.d.ts +2 -0
  20. package/dist/catalog/requests.service.js +4 -1
  21. package/dist/channels/cards.d.ts +9 -0
  22. package/dist/channels/cards.js +32 -1
  23. package/dist/channels/phrases.d.ts +5 -0
  24. package/dist/channels/phrases.js +5 -0
  25. package/dist/conversations/attachments.service.d.ts +34 -0
  26. package/dist/conversations/attachments.service.js +124 -21
  27. package/dist/conversations/conversations.controller.d.ts +5 -1
  28. package/dist/conversations/conversations.controller.js +11 -5
  29. package/dist/conversations/conversations.service.d.ts +5 -0
  30. package/dist/conversations/conversations.service.js +10 -0
  31. package/dist/conversations/event-people.d.ts +12 -0
  32. package/dist/conversations/event-people.js +28 -0
  33. package/dist/db/kernel-schema.d.ts +18 -0
  34. package/dist/devices/devices.service.d.ts +3 -2
  35. package/dist/devices/devices.service.js +17 -2
  36. package/dist/errors.d.ts +1 -0
  37. package/dist/errors.js +1 -0
  38. package/dist/evals/trajectory.service.d.ts +3 -0
  39. package/dist/evals/trajectory.service.js +2 -0
  40. package/dist/extensions/installs.d.ts +3 -0
  41. package/dist/extensions/installs.js +1 -0
  42. package/dist/http/api.module.js +2 -0
  43. package/dist/http/meta.controller.d.ts +1 -0
  44. package/dist/http/meta.controller.js +6 -1
  45. package/dist/identity/account-avatar.controller.d.ts +30 -0
  46. package/dist/identity/account-avatar.controller.js +117 -0
  47. package/dist/identity/account-avatar.d.ts +67 -0
  48. package/dist/identity/account-avatar.js +136 -0
  49. package/dist/identity/account-avatars.service.d.ts +77 -0
  50. package/dist/identity/account-avatars.service.js +321 -0
  51. package/dist/identity/accounts.d.ts +26 -0
  52. package/dist/identity/accounts.js +70 -2
  53. package/dist/identity/app-auth.controller.d.ts +2 -1
  54. package/dist/identity/app-auth.controller.js +2 -1
  55. package/dist/identity/app-auth.d.ts +24 -7
  56. package/dist/identity/app-auth.js +19 -9
  57. package/dist/identity/app-auth.schemas.d.ts +16 -3
  58. package/dist/identity/app-auth.schemas.js +5 -2
  59. package/dist/identity/external.js +7 -1
  60. package/dist/identity/identity.module.d.ts +2 -1
  61. package/dist/identity/identity.module.js +7 -1
  62. package/dist/identity/me.controller.d.ts +29 -5
  63. package/dist/identity/me.controller.js +57 -6
  64. package/dist/identity/me.schemas.d.ts +36 -0
  65. package/dist/identity/me.schemas.js +30 -0
  66. package/dist/identity/principal.d.ts +2 -2
  67. package/dist/identity/principal.js +2 -2
  68. package/dist/local-devices/local-device-gateway.d.ts +2 -0
  69. package/dist/local-devices/local-device-gateway.js +8 -1
  70. package/dist/local-devices/relay.d.ts +10 -9
  71. package/dist/local-devices/relay.js +32 -9
  72. package/dist/local-devices/targets.d.ts +12 -0
  73. package/dist/local-devices/targets.js +18 -2
  74. package/dist/orgs/members.service.d.ts +3 -1
  75. package/dist/orgs/members.service.js +9 -2
  76. package/dist/platform/exclusions.js +33 -57
  77. package/dist/platform/file-ref.d.ts +87 -0
  78. package/dist/platform/file-ref.js +164 -0
  79. package/dist/platform/operation.d.ts +26 -0
  80. package/dist/platform/ops/agent-skills.ops.d.ts +2 -0
  81. package/dist/platform/ops/agent-skills.ops.js +156 -4
  82. package/dist/platform/ops/agents.ops.d.ts +3 -1
  83. package/dist/platform/ops/agents.ops.js +75 -17
  84. package/dist/platform/ops/approvals.ops.js +5 -0
  85. package/dist/platform/ops/catalog-admin.ops.d.ts +9 -1
  86. package/dist/platform/ops/catalog-admin.ops.js +86 -3
  87. package/dist/platform/ops/components.ops.d.ts +3 -1
  88. package/dist/platform/ops/components.ops.js +61 -2
  89. package/dist/platform/ops/connectors.ops.js +15 -1
  90. package/dist/platform/ops/devices.ops.js +6 -1
  91. package/dist/platform/ops/extensions-admin.ops.d.ts +6 -4
  92. package/dist/platform/ops/extensions-admin.ops.js +109 -6
  93. package/dist/platform/ops/inbox.ops.js +10 -0
  94. package/dist/platform/ops/list-handoff.d.ts +10 -0
  95. package/dist/platform/ops/list-handoff.js +11 -0
  96. package/dist/platform/ops/marketplaces.ops.js +2 -1
  97. package/dist/platform/ops/org-plugins.ops.d.ts +12 -3
  98. package/dist/platform/ops/org-plugins.ops.js +97 -6
  99. package/dist/platform/ops/requests.ops.js +9 -0
  100. package/dist/platform/ops/skills.ops.d.ts +5 -1
  101. package/dist/platform/ops/skills.ops.js +98 -4
  102. package/dist/platform/ops/summary.d.ts +5 -0
  103. package/dist/platform/ops/summary.js +10 -0
  104. package/dist/platform/parity.d.ts +6 -4
  105. package/dist/platform/parity.js +94 -68
  106. package/dist/roles/worker.module.js +5 -0
  107. package/dist/sandbox/request-not-sent.d.ts +13 -0
  108. package/dist/sandbox/request-not-sent.js +18 -0
  109. package/dist/schedules/scheduled-tasks.service.d.ts +10 -6
  110. package/dist/schedules/scheduled-tasks.service.js +13 -16
  111. package/dist/shares/shares.service.d.ts +1 -0
  112. package/dist/shares/shares.service.js +9 -3
  113. package/dist/skills/changes.service.d.ts +1 -0
  114. package/dist/skills/changes.service.js +4 -7
  115. package/dist/skills/skills.controller.d.ts +3 -7
  116. package/dist/skills/skills.controller.js +3 -16
  117. package/dist/skills/skills.schemas.d.ts +5 -0
  118. package/dist/skills/skills.schemas.js +17 -0
  119. package/dist/skills/skills.service.d.ts +3 -1
  120. package/dist/skills/skills.service.js +13 -4
  121. package/dist/tools/admin-connectors.d.ts +1 -0
  122. package/dist/tools/admin-connectors.js +4 -1
  123. package/dist/tools/approvals.service.d.ts +16 -2
  124. package/dist/tools/approvals.service.js +13 -0
  125. package/dist/tools/builtins/builtin-tools.d.ts +3 -0
  126. package/dist/tools/builtins/builtin-tools.js +29 -9
  127. package/dist/tools/builtins/platform.d.ts +23 -0
  128. package/dist/tools/builtins/platform.js +95 -6
  129. package/dist/tools/builtins/sandbox/common.d.ts +5 -0
  130. package/dist/tools/builtins/sandbox/common.js +11 -0
  131. package/dist/tools/builtins/skill-load.js +4 -4
  132. package/dist/tools/pipeline.js +10 -3
  133. package/dist/tools/questions.controller.js +2 -2
  134. package/dist/tools/questions.service.d.ts +7 -1
  135. package/dist/tools/questions.service.js +9 -2
  136. package/dist/tools/registry.d.ts +6 -0
  137. package/dist/tools/tools.module.js +3 -0
  138. package/package.json +3 -3
  139. package/src/migrations/0171_account_avatar.sql +26 -0
@@ -9,6 +9,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
9
9
  };
10
10
  import { Inject, Injectable } from "@nestjs/common";
11
11
  import { ApiError } from "../errors.js";
12
+ import { avatarColumns, personAvatarUrl } from "../identity/account-avatar.js";
12
13
  import { audit } from "../identity/audit.js";
13
14
  import { afterCommit } from "../infra/database/after-commit.js";
14
15
  import { KernelDb } from "../infra/database/kernel-db.js";
@@ -58,20 +59,26 @@ let MembersService = class MembersService {
58
59
  .leftJoin("org_anonymous_accounts", (j) => j
59
60
  .onRef("org_anonymous_accounts.org_id", "=", "memberships.org_id")
60
61
  .onRef("org_anonymous_accounts.account_id", "=", "memberships.account_id"))
61
- .select([
62
+ .select((eb) => [
62
63
  "accounts.id",
63
64
  "accounts.display_name",
64
65
  "accounts.email",
65
66
  "memberships.role",
66
67
  "memberships.created_at",
67
68
  "org_anonymous_accounts.account_id as anonymous_id",
69
+ ...avatarColumns(eb, "accounts", "account"),
68
70
  ])
69
71
  .where("memberships.org_id", "=", orgId)
70
72
  .orderBy("memberships.created_at")
71
73
  .orderBy("accounts.id")
72
74
  .execute();
73
75
  return rows.map((r) => ({
74
- account: { id: r.id, displayName: r.display_name, email: r.email },
76
+ account: {
77
+ id: r.id,
78
+ displayName: r.display_name,
79
+ email: r.email,
80
+ avatarUrl: personAvatarUrl(r, "account", r.id),
81
+ },
75
82
  role: r.role,
76
83
  joinedAt: r.created_at,
77
84
  anonymous: r.anonymous_id !== null,
@@ -39,12 +39,7 @@ export const PLATFORM_EXCLUSIONS = [
39
39
  {
40
40
  route: "POST /api/v1/admin/extensions/:name/install",
41
41
  category: "human-only",
42
- reason: "Points an extension at a package from the package store (a new install or a version change); the package comes from an upload or npm import whose permissions a person reviews, and new permissions wait for that person's approval, so the install stays with the review on the web",
43
- },
44
- {
45
- route: "POST /api/v1/admin/extensions/packages/file",
46
- category: "transport",
47
- reason: "Uploads a package file as multipart bytes",
42
+ reason: "Points an extension at a package from the package store (a new install or a version change); the package comes from an npm import or a stored package whose permissions a person reviews, and new permissions wait for that person's approval, so the install stays with the review the person confirms",
48
43
  },
49
44
  {
50
45
  route: "POST /api/v1/admin/extensions/packages/npm",
@@ -72,7 +67,7 @@ export const PLATFORM_EXCLUSIONS = [
72
67
  {
73
68
  route: "GET /api/v1/setup",
74
69
  category: "internal",
75
- reason: "First-run setup status used by the web app before any login",
70
+ reason: "First-run setup status the web app reads before any login, with no org and no actor yet; no operation gives it, an agent exists only after setup",
76
71
  },
77
72
  {
78
73
  route: "POST /api/v1/setup",
@@ -80,11 +75,6 @@ export const PLATFORM_EXCLUSIONS = [
80
75
  reason: "Creates the first super admin account and password",
81
76
  },
82
77
  // agents
83
- {
84
- route: "POST /api/v1/orgs/:orgId/agents/:agentId/avatar/uploads",
85
- category: "transport",
86
- reason: "Creates a presigned avatar upload",
87
- },
88
78
  {
89
79
  route: "GET /api/v1/orgs/:orgId/agents/:agentId/avatar",
90
80
  category: "transport",
@@ -100,6 +90,12 @@ export const PLATFORM_EXCLUSIONS = [
100
90
  category: "human-only",
101
91
  reason: "Transfers ownership of an org's agent to another person on the platform's behalf, as the org's own transfer route",
102
92
  },
93
+ // accounts
94
+ {
95
+ route: "GET /api/v1/accounts/:accountId/avatar",
96
+ category: "transport",
97
+ reason: "Redirects to the avatar image for <img>; no agent use",
98
+ },
103
99
  // background
104
100
  {
105
101
  route: "GET /api/v1/orgs/:orgId/conversations/:id/background-tasks/:taskId/output",
@@ -107,11 +103,6 @@ export const PLATFORM_EXCLUSIONS = [
107
103
  reason: "Streams raw task output bytes",
108
104
  },
109
105
  // catalog-admin
110
- {
111
- route: "POST /api/v1/admin/catalog/import/file",
112
- category: "transport",
113
- reason: "Uploads a plugin archive as multipart bytes",
114
- },
115
106
  {
116
107
  route: "POST /api/v1/admin/catalog/imports/:stagingId/confirm",
117
108
  category: "human-only",
@@ -130,7 +121,7 @@ export const PLATFORM_EXCLUSIONS = [
130
121
  {
131
122
  route: "GET /api/v1/admin/catalog/:itemId/guides/:guideId",
132
123
  category: "internal",
133
- reason: "The super admin's preview of a plugin's setup guide for the admin console, with no org and no target; agents assist with the org guides an org member sees",
124
+ reason: "The super admin's preview of a plugin's setup guide for the admin console, with no org and no target; no operation gives it, agents assist with the org guides an org member sees (channels.schema, connectors.kinds)",
134
125
  },
135
126
  {
136
127
  route: "POST /api/v1/admin/catalog/items/:id/confirm",
@@ -143,11 +134,6 @@ export const PLATFORM_EXCLUSIONS = [
143
134
  reason: "Rejects a catalog item's reviewed changes, an approval decision",
144
135
  },
145
136
  // components
146
- {
147
- route: "POST /api/v1/admin/components/skill/:id/versions",
148
- category: "transport",
149
- reason: "Uploads a platform skill package as raw bytes",
150
- },
151
137
  // marketplaces
152
138
  {
153
139
  route: "GET /api/v1/admin/marketplaces/:id/icons/:sha256",
@@ -186,32 +172,27 @@ export const PLATFORM_EXCLUSIONS = [
186
172
  reason: "Decides an org's catalog request as super admin",
187
173
  },
188
174
  // org-uploads
189
- {
190
- route: "POST /api/v1/orgs/:orgId/catalog/uploads/file",
191
- category: "transport",
192
- reason: "Uploads a plugin archive as multipart bytes",
193
- },
194
175
  {
195
176
  route: "POST /api/v1/orgs/:orgId/catalog/uploads/:stagingId/confirm",
196
177
  category: "human-only",
197
- reason: "Confirms an upload review, an approval decision",
178
+ reason: "Confirms a staged plugin review (reached by the link card of the staged plugin), a trust decision by the person",
198
179
  },
199
180
  // channels
200
181
  // attachments
201
182
  {
202
183
  route: "GET /api/v1/orgs/:orgId/attachments/limits",
203
184
  category: "internal",
204
- reason: "The composer's pre-upload check on the web; an agent does not upload attachments",
185
+ reason: "The composer's size check for a person's file into a conversation; an agent gets files by file reference, not by attaching",
205
186
  },
206
187
  {
207
188
  route: "POST /api/v1/orgs/:orgId/attachments",
208
- category: "transport",
209
- reason: "Creates a presigned attachment upload",
189
+ category: "internal",
190
+ reason: "Registers a person's file into a conversation from the composer; an agent gets files by file reference (fileId), not through attachments",
210
191
  },
211
192
  {
212
193
  route: "POST /api/v1/orgs/:orgId/attachments/:id/finalize",
213
- category: "transport",
214
- reason: "Finishes a presigned attachment upload",
194
+ category: "internal",
195
+ reason: "Finishes a person's file into a conversation from the composer; an agent gets files by file reference (fileId), not through attachments",
215
196
  },
216
197
  {
217
198
  route: "GET /api/v1/orgs/:orgId/attachments/:id/download",
@@ -429,13 +410,23 @@ export const PLATFORM_EXCLUSIONS = [
429
410
  {
430
411
  route: "GET /api/v1/me",
431
412
  category: "internal",
432
- reason: "Account profile the web app loads for its own session; not an operation an agent needs",
413
+ reason: "Account profile the web app loads for its own session; platform.me gives an agent the same facts",
433
414
  },
434
415
  {
435
416
  route: "PUT /api/v1/me/current-org",
436
417
  category: "human-only",
437
418
  reason: "Switches the web session's current org",
438
419
  },
420
+ {
421
+ route: "PATCH /api/v1/me/profile",
422
+ category: "human-only",
423
+ reason: "Changes the person's own name and avatar",
424
+ },
425
+ {
426
+ route: "POST /api/v1/me/avatar/uploads",
427
+ category: "human-only",
428
+ reason: "The person's own avatar: only the person sets it, an agent never does",
429
+ },
439
430
  {
440
431
  route: "PUT /api/v1/me/password",
441
432
  category: "human-only",
@@ -459,7 +450,7 @@ export const PLATFORM_EXCLUSIONS = [
459
450
  {
460
451
  route: "GET /api/v1/auth/sources",
461
452
  category: "internal",
462
- reason: "Login source list the web sign-in page renders; no agent use",
453
+ reason: "Login source list the web sign-in page renders before a session exists; no operation gives it, a signed-in agent has nothing to choose",
463
454
  },
464
455
  {
465
456
  route: "GET /api/v1/auth/sso/:plugin/start",
@@ -564,21 +555,6 @@ export const PLATFORM_EXCLUSIONS = [
564
555
  category: "human-only",
565
556
  reason: "Decides a proposed skill change",
566
557
  },
567
- {
568
- route: "POST /api/v1/orgs/:orgId/skills/uploads",
569
- category: "transport",
570
- reason: "Uploads a skill archive as multipart bytes",
571
- },
572
- {
573
- route: "POST /api/v1/orgs/:orgId/skills",
574
- category: "transport",
575
- reason: "Creates an org skill from an uploaded archive; uploads are multipart bytes",
576
- },
577
- {
578
- route: "POST /api/v1/orgs/:orgId/agents/:agentId/skills/uploads",
579
- category: "transport",
580
- reason: "Uploads a skill archive as multipart bytes",
581
- },
582
558
  // approvals
583
559
  {
584
560
  route: "POST /api/v1/orgs/:orgId/approvals/:id/decision",
@@ -599,12 +575,12 @@ export const PLATFORM_EXCLUSIONS = [
599
575
  {
600
576
  route: "GET /api/v1/orgs/:orgId/connectors/prompts",
601
577
  category: "internal",
602
- reason: "Feeds the slash menu of the web input box: prompt templates of remote servers, written for a person to fill in and send; an agent has no one to send them to",
578
+ reason: "Feeds the slash menu of the web input box: prompt templates of remote servers, written for a person to fill in and send; no operation gives them, an agent has no one to send them to",
603
579
  },
604
580
  {
605
581
  route: "GET /api/v1/orgs/:orgId/connectors/resources",
606
582
  category: "internal",
607
- reason: "Feeds the @ reference picker of the web input box; an agent reads connector resources through its connector tools",
583
+ reason: "Feeds the @ reference picker of the web input box; no operation gives it, an agent reads connector resources through its connector tools",
608
584
  },
609
585
  {
610
586
  route: "POST /api/v1/orgs/:orgId/connectors/:connectorId/prompts/:name",
@@ -650,7 +626,7 @@ export const PLATFORM_EXCLUSIONS = [
650
626
  {
651
627
  route: "GET /api/v1/orgs/:orgId/ui/contributions",
652
628
  category: "internal",
653
- reason: "Navigation entries of the web shell (panels, pages, embeds); nothing an agent acts on",
629
+ reason: "Navigation entries of the web shell (panels, pages, embeds); ui.slots gives an agent the slots, nothing else here is acted on",
654
630
  },
655
631
  {
656
632
  route: "GET /api/v1/orgs/:orgId/ui/arrangement",
@@ -680,7 +656,7 @@ export const PLATFORM_EXCLUSIONS = [
680
656
  {
681
657
  route: "GET /api/v1/admin/ui/contributions",
682
658
  category: "internal",
683
- reason: "Navigation entries of the admin console (platform pages)",
659
+ reason: "Navigation entries of the admin console (platform pages); ui.slots gives an agent the slots, nothing else here is acted on",
684
660
  },
685
661
  {
686
662
  route: "GET /api/v1/admin/ui/arrangement",
@@ -716,12 +692,12 @@ export const PLATFORM_EXCLUSIONS = [
716
692
  {
717
693
  route: "GET /api/v1/orgs/:orgId/ui/client",
718
694
  category: "internal",
719
- reason: "The web shell's list of client code to load (file URLs and integrity); nothing an agent acts on",
695
+ reason: "The web shell's list of client code to load (file URLs and integrity); no operation gives it, nothing an agent acts on",
720
696
  },
721
697
  {
722
698
  route: "GET /api/v1/admin/ui/client",
723
699
  category: "internal",
724
- reason: "The admin console's list of platform page client code to load; nothing an agent acts on",
700
+ reason: "The admin console's list of platform page client code to load; no operation gives it, nothing an agent acts on",
725
701
  },
726
702
  {
727
703
  route: "POST /api/v1/orgs/:orgId/ui/client/reports",
@@ -0,0 +1,87 @@
1
+ import { z } from "zod";
2
+ import { AttachmentsService } from "../conversations/attachments.service.js";
3
+ import { KernelDb } from "../infra/database/kernel-db.js";
4
+ import { StorageService } from "../storage/storage.service.js";
5
+ /**
6
+ * File references (platform web parity spec §5): a `Platform` write the web does with an upload
7
+ * takes a file the agent already has instead, a conversation file (`fileId`: an attachment, a
8
+ * generated or delivered artifact, a `read` copy). A file on the conversation's device is delivered
9
+ * first (`Deliver`: the device rules, the command review and the activation gate apply) and passed
10
+ * by the delivered file's id, so device files have one reading path. The tool resolves it at the
11
+ * policy step (limits, sha256, a thumbnail for an image: the card's `detail.file`) and again right
12
+ * before the run, which refuses bytes that differ from the ones the person confirmed.
13
+ */
14
+ export type FileRef = {
15
+ fileId: string;
16
+ };
17
+ /** Model-visible: a device path where a file reference is expected. */
18
+ export declare const FILE_REF_PATH_TEXT = "Deliver the file first, then pass its fileId.";
19
+ export declare const FileRefSchema: z.ZodType<FileRef>;
20
+ /** What an operation accepts: the route's byte limit and content types (absent: any type). */
21
+ export interface FileLimits {
22
+ maxBytes: number;
23
+ contentTypes?: readonly string[];
24
+ }
25
+ /** A resolved reference: the bytes and what the card shows of them. */
26
+ export interface ResolvedFile {
27
+ name: string;
28
+ /** Normalized (lower case, no parameters). */
29
+ contentType: string;
30
+ size: number;
31
+ /** Hex sha256 of {@link bytes}. */
32
+ sha256: string;
33
+ bytes: Uint8Array;
34
+ }
35
+ /** What the approval card shows of a referenced file (`detail.file`; never the bytes). */
36
+ export interface FileCardDetail {
37
+ name: string;
38
+ size: number;
39
+ sha256: string;
40
+ contentType: string;
41
+ /** A WebP data URL (ruling R9); absent for a non-image, an undecodable one or one too large. */
42
+ thumbnail?: string;
43
+ }
44
+ /** Where a reference is resolved: the runtime's ids, never input. */
45
+ export interface FileRefContext {
46
+ orgId: string;
47
+ conversationId: string;
48
+ signal: AbortSignal;
49
+ }
50
+ /** Ruling R9: the thumbnail's longest edge, quality and the most the data URL may take. */
51
+ export declare const THUMBNAIL_MAX_EDGE = 160;
52
+ export declare const THUMBNAIL_MAX_CHARS: number;
53
+ /**
54
+ * The most an image may weigh, and the most pixels it may decode to, for a thumbnail: a card is
55
+ * drawn at the policy step of every call, so a large or decompression-bomb image gets none.
56
+ */
57
+ export declare const THUMBNAIL_MAX_INPUT_BYTES: number;
58
+ export declare const THUMBNAIL_MAX_INPUT_PIXELS = 40000000;
59
+ /** Model-visible: the referenced file is over the operation's byte limit. */
60
+ export declare const fileTooLargeText: (size: number, max: number) => string;
61
+ /** Model-visible: the referenced file's type is not one the operation takes. */
62
+ export declare const fileTypeText: (contentType: string, types: readonly string[]) => string;
63
+ /** Model-visible: the bytes at run time differ from the ones the person confirmed. */
64
+ export declare const FILE_CHANGED_TEXT = "The file changed after the person confirmed it; call the operation again.";
65
+ /** The card's view of a resolved file, with a thumbnail for an image (R9). */
66
+ export declare function fileCardDetail(file: ResolvedFile): Promise<FileCardDetail>;
67
+ /**
68
+ * A 160 px (longest edge) WebP q70 data URL of an image, or null: not an image type the kernel
69
+ * decodes, bytes over {@link THUMBNAIL_MAX_INPUT_BYTES} or decoding to more than
70
+ * {@link THUMBNAIL_MAX_INPUT_PIXELS}, bytes that fail to decode, or a data URL over
71
+ * {@link THUMBNAIL_MAX_CHARS} (ruling R9).
72
+ */
73
+ export declare function thumbnailOf(file: Pick<ResolvedFile, "contentType" | "bytes">): Promise<string | null>;
74
+ /**
75
+ * Resolves file references for the `Platform` tool. `fileId` goes through
76
+ * `findConversationFile` (the resolver `Read` uses: the conversation and its root, inside the
77
+ * org).
78
+ * Every refusal is a model-visible `ToolError`.
79
+ */
80
+ export declare class FileRefs {
81
+ private readonly db;
82
+ private readonly attachments;
83
+ private readonly storage;
84
+ constructor(db: KernelDb, attachments: AttachmentsService, storage: StorageService);
85
+ resolve(ref: FileRef, limits: FileLimits, ctx: FileRefContext): Promise<ResolvedFile>;
86
+ private conversationFile;
87
+ }
@@ -0,0 +1,164 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
8
+ return function (target, key) { decorator(target, key, paramIndex); }
9
+ };
10
+ import { createHash } from "node:crypto";
11
+ import { ToolError } from "@capybara-hq/plugin-sdk";
12
+ import { Inject, Injectable } from "@nestjs/common";
13
+ import sharp from "sharp";
14
+ import { z } from "zod";
15
+ import { AttachmentsService, normalizeContentType, sniffMatches, } from "../conversations/attachments.service.js";
16
+ import { KernelDb } from "../infra/database/kernel-db.js";
17
+ import { rootConversationOf } from "../runtime/subagents/child.js";
18
+ import { StorageService } from "../storage/storage.service.js";
19
+ import { findConversationFile } from "../tools/builtins/conversation-files.js";
20
+ /** Model-visible: a device path where a file reference is expected. */
21
+ export const FILE_REF_PATH_TEXT = "Deliver the file first, then pass its fileId.";
22
+ export const FileRefSchema = z.strictObject({
23
+ fileId: z
24
+ .uuid()
25
+ .describe("The id of a file of this conversation: an attachment, a generated image or a delivered file (Deliver a device file first)."),
26
+ }, {
27
+ // a device path is not a file reference: the model delivers the file first
28
+ error: (iss) => iss.code === "unrecognized_keys" && iss.keys.includes("path")
29
+ ? FILE_REF_PATH_TEXT
30
+ : undefined,
31
+ });
32
+ /** Ruling R9: the thumbnail's longest edge, quality and the most the data URL may take. */
33
+ export const THUMBNAIL_MAX_EDGE = 160;
34
+ const THUMBNAIL_QUALITY = 70;
35
+ export const THUMBNAIL_MAX_CHARS = 24 * 1024;
36
+ /**
37
+ * The most an image may weigh, and the most pixels it may decode to, for a thumbnail: a card is
38
+ * drawn at the policy step of every call, so a large or decompression-bomb image gets none.
39
+ */
40
+ export const THUMBNAIL_MAX_INPUT_BYTES = 10 * 1024 * 1024;
41
+ export const THUMBNAIL_MAX_INPUT_PIXELS = 40_000_000;
42
+ /** Image types a thumbnail is made of (an SVG is never rendered by the kernel). */
43
+ const THUMBNAIL_TYPES = new Set(["image/png", "image/jpeg", "image/webp", "image/gif"]);
44
+ /** Model-visible: the referenced file is over the operation's byte limit. */
45
+ export const fileTooLargeText = (size, max) => `The file is ${size} bytes; this operation takes at most ${max}.`;
46
+ /** Model-visible: the referenced file's type is not one the operation takes. */
47
+ export const fileTypeText = (contentType, types) => `The file is ${contentType}; this operation takes ${types.join(", ")}.`;
48
+ /** Model-visible: the bytes at run time differ from the ones the person confirmed. */
49
+ export const FILE_CHANGED_TEXT = "The file changed after the person confirmed it; call the operation again.";
50
+ const notFoundText = (id) => `File ${id} is not a file of this conversation. Pass the id of an attachment, a generated image or a delivered file of this conversation, or Deliver a device file first and pass its fileId.`;
51
+ const sha256Of = (bytes) => createHash("sha256").update(bytes).digest("hex");
52
+ /** The card's view of a resolved file, with a thumbnail for an image (R9). */
53
+ export async function fileCardDetail(file) {
54
+ const thumbnail = await thumbnailOf(file);
55
+ return {
56
+ name: file.name,
57
+ size: file.size,
58
+ sha256: file.sha256,
59
+ contentType: file.contentType,
60
+ ...(thumbnail !== null && { thumbnail }),
61
+ };
62
+ }
63
+ /**
64
+ * A 160 px (longest edge) WebP q70 data URL of an image, or null: not an image type the kernel
65
+ * decodes, bytes over {@link THUMBNAIL_MAX_INPUT_BYTES} or decoding to more than
66
+ * {@link THUMBNAIL_MAX_INPUT_PIXELS}, bytes that fail to decode, or a data URL over
67
+ * {@link THUMBNAIL_MAX_CHARS} (ruling R9).
68
+ */
69
+ export async function thumbnailOf(file) {
70
+ if (!THUMBNAIL_TYPES.has(file.contentType))
71
+ return null;
72
+ if (file.bytes.byteLength > THUMBNAIL_MAX_INPUT_BYTES)
73
+ return null;
74
+ try {
75
+ const out = await sharp(file.bytes, {
76
+ failOn: "error",
77
+ limitInputPixels: THUMBNAIL_MAX_INPUT_PIXELS,
78
+ })
79
+ .autoOrient()
80
+ .resize({
81
+ width: THUMBNAIL_MAX_EDGE,
82
+ height: THUMBNAIL_MAX_EDGE,
83
+ fit: "inside",
84
+ withoutEnlargement: true,
85
+ })
86
+ .webp({ quality: THUMBNAIL_QUALITY })
87
+ .toBuffer();
88
+ const url = `data:image/webp;base64,${out.toString("base64")}`;
89
+ return url.length <= THUMBNAIL_MAX_CHARS ? url : null;
90
+ }
91
+ catch {
92
+ return null;
93
+ }
94
+ }
95
+ /**
96
+ * Resolves file references for the `Platform` tool. `fileId` goes through
97
+ * `findConversationFile` (the resolver `Read` uses: the conversation and its root, inside the
98
+ * org).
99
+ * Every refusal is a model-visible `ToolError`.
100
+ */
101
+ let FileRefs = class FileRefs {
102
+ db;
103
+ attachments;
104
+ storage;
105
+ constructor(db, attachments, storage) {
106
+ this.db = db;
107
+ this.attachments = attachments;
108
+ this.storage = storage;
109
+ }
110
+ async resolve(ref, limits, ctx) {
111
+ const got = await this.conversationFile(ref.fileId, limits, ctx);
112
+ const contentType = normalizeContentType(got.contentType);
113
+ return {
114
+ name: got.name,
115
+ contentType,
116
+ size: got.bytes.byteLength,
117
+ sha256: sha256Of(got.bytes),
118
+ bytes: got.bytes,
119
+ };
120
+ }
121
+ async conversationFile(id, limits, ctx) {
122
+ const db = this.db.db;
123
+ const rootConversationId = await rootConversationOf(db, ctx.conversationId);
124
+ const file = await findConversationFile({ db, attachments: this.attachments, storage: this.storage }, {
125
+ orgId: ctx.orgId,
126
+ conversationId: ctx.conversationId,
127
+ rootConversationId,
128
+ id,
129
+ // one byte past the limit tells a file that grew from one that fits
130
+ maxBytes: limits.maxBytes + 1,
131
+ signal: ctx.signal,
132
+ });
133
+ if (file === null)
134
+ throw new ToolError(notFoundText(id));
135
+ if (file.size > limits.maxBytes) {
136
+ await file.discard();
137
+ throw new ToolError(fileTooLargeText(file.size, limits.maxBytes));
138
+ }
139
+ const types = limits.contentTypes;
140
+ const declared = normalizeContentType(file.contentType);
141
+ if (types !== undefined && !types.includes(declared)) {
142
+ await file.discard();
143
+ throw new ToolError(fileTypeText(declared, types));
144
+ }
145
+ const bytes = await file.open({ maxBytes: limits.maxBytes + 1 });
146
+ if (bytes.byteLength > limits.maxBytes) {
147
+ await file.discard();
148
+ throw new ToolError(fileTooLargeText(bytes.byteLength, limits.maxBytes));
149
+ }
150
+ // the bytes must be what the type says (the upload routes sniff the same way)
151
+ if (types !== undefined && !sniffMatches(declared, bytes.subarray(0, 4096))) {
152
+ await file.discard();
153
+ throw new ToolError(`The file's bytes are not ${declared}; this operation takes ${types.join(", ")}.`);
154
+ }
155
+ return { name: file.name, contentType: file.contentType, bytes };
156
+ }
157
+ };
158
+ FileRefs = __decorate([
159
+ Injectable(),
160
+ __param(0, Inject(KernelDb)),
161
+ __param(1, Inject(AttachmentsService)),
162
+ __param(2, Inject(StorageService))
163
+ ], FileRefs);
164
+ export { FileRefs };
@@ -2,6 +2,7 @@ import type { z } from "zod";
2
2
  import type { ToolView } from "../conversations/events.js";
3
3
  import type { OrgAction } from "../orgs/roles.js";
4
4
  import type { ErrorRole } from "./errors.js";
5
+ import type { FileLimits, FileRef, ResolvedFile } from "./file-ref.js";
5
6
  import type { PersonFieldTarget } from "./person-fields.js";
6
7
  /**
7
8
  * How an operation is confirmed (spec §6.2): `read` runs; `personal` asks each time and may be
@@ -53,6 +54,13 @@ export interface OperationContext {
53
54
  * names every field the card shows. Absent elsewhere.
54
55
  */
55
56
  personAsk?: readonly string[];
57
+ /**
58
+ * The file the call's {@link PlatformOperation.fileRef} names (platform web parity spec §5),
59
+ * resolved and checked against its limits. In `run`: read again right before it, and the same
60
+ * bytes the person confirmed (the tool refuses a different sha256 before `run`). In `summary`:
61
+ * the bytes the card shows. Absent when the operation takes no file for this input.
62
+ */
63
+ file?: ResolvedFile;
56
64
  }
57
65
  /**
58
66
  * The next step after an error: one text, or one per role where the step differs (spec §14.5
@@ -179,6 +187,17 @@ export interface PlatformOperation<I = unknown> {
179
187
  * make the call always ask the person, once, on the web. Absent: the write has no person fields.
180
188
  */
181
189
  personFields?(input: I, ctx: OperationContext): Promise<PersonFieldTarget>;
190
+ /**
191
+ * The file this input takes in place of an upload (platform web parity spec §5), with the
192
+ * mirrored route's byte limit and content types; null: none for this input (another variant).
193
+ * The tool resolves it at the policy step (a file over the limit or of another type is refused
194
+ * before the card; the card shows its name, size, sha256 and an image's thumbnail, and the
195
+ * approval binds the sha256), and again before `run`, which gets it as `ctx.file`.
196
+ */
197
+ fileRef?(input: I): {
198
+ ref: FileRef;
199
+ limits: FileLimits;
200
+ } | null;
182
201
  /**
183
202
  * Why the operation takes none of its mirrored route's secret fields (`secret()` meta, left in
184
203
  * `omits`) and asks the person for none, e.g. a preview without the credential, or a switch that
@@ -186,6 +205,13 @@ export interface PlatformOperation<I = unknown> {
186
205
  * otherwise requires {@link personFields}.
187
206
  */
188
207
  withoutSecrets?: string;
208
+ /**
209
+ * Why the operation sends the person to the web (its description names a place where they
210
+ * confirm, review, approve or decide) yet pops no {@link handoff} card: no web page shows it.
211
+ * Rule `platform-op-handoff` otherwise requires `handoff`; the opt-out is stale once the
212
+ * description stops sending the person there.
213
+ */
214
+ noHandoff?: string;
189
215
  /**
190
216
  * The bilingual card summary of a write, rendered from the input and kernel reads (names of
191
217
  * the targets, preview counts), never from model text; required unless `confirm` is `read`.
@@ -35,6 +35,8 @@ export declare class AgentSkillsOperations implements OnModuleInit {
35
35
  * a sub-agent conversation, then an actor who is not the agent's current owner.
36
36
  */
37
37
  private registerCheck;
38
+ /** The refusals of `agents.upload-skill`: a sub-agent conversation, then an actor not the owner. */
39
+ private uploadCheck;
38
40
  /**
39
41
  * The refusals of sharing read before the card: a sub-agent conversation, an actor who is not
40
42
  * the agent's current owner, a skill that is not one of the agent's own.