@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
@@ -40,6 +40,7 @@ export interface ShareView {
40
40
  createdBy: {
41
41
  id: string;
42
42
  displayName: string;
43
+ avatarUrl: string | null;
43
44
  };
44
45
  createdAt: string;
45
46
  expiresAt: string | null;
@@ -14,6 +14,7 @@ import { ConversationAccess } from "../conversations/access.js";
14
14
  import { attachmentContentMatches } from "../conversations/attachments.service.js";
15
15
  import { ConversationFiles } from "../conversations/files.js";
16
16
  import { ApiError } from "../errors.js";
17
+ import { avatarColumns, personAvatarUrl } from "../identity/account-avatar.js";
17
18
  import { audit } from "../identity/audit.js";
18
19
  import { KernelConfigService } from "../infra/config/kernel-config.service.js";
19
20
  import { KernelDb } from "../infra/database/kernel-db.js";
@@ -397,7 +398,7 @@ let SharesService = class SharesService {
397
398
  let q = this.db
398
399
  .selectFrom("file_shares")
399
400
  .innerJoin("accounts as creator", "creator.id", "file_shares.created_by")
400
- .select([
401
+ .select((eb) => [
401
402
  "file_shares.id",
402
403
  "file_shares.code",
403
404
  "file_shares.audience",
@@ -410,13 +411,14 @@ let SharesService = class SharesService {
410
411
  "file_shares.generation",
411
412
  "file_shares.created_by",
412
413
  "creator.display_name",
414
+ ...avatarColumns(eb, "creator", "creator"),
413
415
  "file_shares.created_at",
414
416
  "file_shares.expires_at",
415
417
  "file_shares.last_opened_at",
416
418
  "file_shares.revoked_at",
417
419
  "file_shares.revoke_reason",
418
420
  sql `file_shares.expires_at IS NOT NULL AND file_shares.expires_at <= now()`.as("expired"),
419
- (eb) => creatorStillHasAccess(eb).as("creator_ok"),
421
+ creatorStillHasAccess(eb).as("creator_ok"),
420
422
  // a later delivery of the same source path in the conversation (refresh offered)
421
423
  sql `file_shares.source_path IS NOT NULL AND EXISTS (
422
424
  SELECT 1 FROM capybara.conversation_events later
@@ -471,7 +473,11 @@ let SharesService = class SharesService {
471
473
  contentType: r.content_type,
472
474
  size: Number(r.size),
473
475
  generation: r.generation,
474
- createdBy: { id: r.created_by, displayName: r.display_name },
476
+ createdBy: {
477
+ id: r.created_by,
478
+ displayName: r.display_name,
479
+ avatarUrl: personAvatarUrl(r, "creator", r.created_by),
480
+ },
475
481
  createdAt: r.created_at.toISOString(),
476
482
  expiresAt: iso(r.expires_at),
477
483
  lastOpenedAt: iso(r.last_opened_at),
@@ -35,6 +35,7 @@ export interface SkillChangeView {
35
35
  requestedBy: string;
36
36
  /** The requester's display name (empty when the account no longer exists). */
37
37
  requestedByName: string;
38
+ requestedByAvatarUrl: string | null;
38
39
  /** The proposing conversation (null for a share request and a proposal made on the web). */
39
40
  requestedInConversation: string | null;
40
41
  /** The proposing conversation's web path (no locale prefix), or null. */
@@ -11,6 +11,7 @@ import { Inject, Injectable } from "@nestjs/common";
11
11
  import { sql } from "kysely";
12
12
  import { EventLog } from "../conversations/event-log.js";
13
13
  import { ApiError } from "../errors.js";
14
+ import { loadPeople } from "../identity/account-avatar.js";
14
15
  import { audit } from "../identity/audit.js";
15
16
  import { assertCustomAllowed } from "../identity/settings.js";
16
17
  import { KernelDb } from "../infra/database/kernel-db.js";
@@ -435,12 +436,7 @@ let SkillChangesService = class SkillChangesService {
435
436
  .select(["agents.id", "agent_versions.definition"])
436
437
  .where("agents.id", "in", agentIds)
437
438
  .execute();
438
- const requesters = await this.db
439
- .selectFrom("accounts")
440
- .select(["id", "display_name"])
441
- .where("id", "in", [...new Set(rows.map((r) => r.requested_by_account))])
442
- .execute();
443
- const requesterNames = new Map(requesters.map((a) => [a.id, a.display_name]));
439
+ const requesters = await loadPeople(this.db.db, rows.map((r) => r.requested_by_account));
444
440
  const names = new Map(agents.map((a) => {
445
441
  const n = a.definition?.name;
446
442
  return [a.id, typeof n === "string" ? n : ""];
@@ -457,7 +453,8 @@ let SkillChangesService = class SkillChangesService {
457
453
  files: r.proposed_version.manifest.files.map((f) => ({ path: f.path, size: f.size })),
458
454
  status: r.status,
459
455
  requestedBy: r.requested_by_account,
460
- requestedByName: requesterNames.get(r.requested_by_account) ?? "",
456
+ requestedByName: requesters.get(r.requested_by_account)?.name ?? "",
457
+ requestedByAvatarUrl: requesters.get(r.requested_by_account)?.avatarUrl ?? null,
461
458
  requestedInConversation: r.requested_in_conversation,
462
459
  conversationPath: r.requested_in_conversation === null ? null : `/chat/${r.requested_in_conversation}`,
463
460
  decidedBy: r.decided_by,
@@ -1,14 +1,10 @@
1
- import { z } from "zod";
1
+ import type { z } from "zod";
2
2
  import { OwnedItems, type OwnedSkillDeletePreview } from "../catalog/owned-items.js";
3
- import { type CreatedAttachment } from "../conversations/attachments.service.js";
3
+ import type { CreatedAttachment } from "../conversations/attachments.service.js";
4
4
  import { type Principal } from "../identity/principal.js";
5
5
  import { type OrgContext } from "../orgs/org.guard.js";
6
- import { SkillCreateBody, SkillIdParams } from "./skills.schemas.js";
6
+ import { SkillCreateBody, SkillIdParams, SkillUploadBody as UploadBody } from "./skills.schemas.js";
7
7
  import { type SkillDetail, type SkillSummary, SkillsService, type UploadedSkill } from "./skills.service.js";
8
- declare const UploadBody: z.ZodObject<{
9
- name: z.ZodString;
10
- size: z.ZodNumber;
11
- }, z.core.$strict>;
12
8
  declare const ShareableBody: z.ZodObject<{
13
9
  shareable: z.ZodBoolean;
14
10
  }, z.core.$strict>;
@@ -7,28 +7,15 @@ 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 { hasControlChars, MEDIA_NAME_MAX_CHARS } from "@capybara-hq/plugin-sdk";
11
10
  import { Controller, Delete, Get, HttpCode, Inject, Param, Post, Put } from "@nestjs/common";
12
- import { z } from "zod";
13
11
  import { OwnedItems } from "../catalog/owned-items.js";
14
- import { SKILL_PACKAGE_UPLOAD_MAX_BYTES, } from "../conversations/attachments.service.js";
15
12
  import { CurrentPrincipal, patTokenId, requireUser, } from "../identity/principal.js";
16
13
  import { createZodDto } from "../infra/validation/create-zod-dto.js";
17
14
  import { ZBody, ZParam } from "../infra/validation/zod-params.js";
18
15
  import { CurrentOrg, OrgAction } from "../orgs/org.guard.js";
19
- import { SkillCreateBody, SkillIdParams, SkillShareableSchema } from "./skills.schemas.js";
16
+ import { SkillCreateBody, SkillIdParams, SkillShareableSchema, SkillUploadBody as UploadBody, } from "./skills.schemas.js";
20
17
  import { SkillsService, } from "./skills.service.js";
21
- const UploadBody = z
22
- .object({
23
- name: z
24
- .string()
25
- .min(1)
26
- .max(MEDIA_NAME_MAX_CHARS)
27
- .refine((s) => !hasControlChars(s), "name must not contain control characters"),
28
- size: z.number().int().min(1).max(SKILL_PACKAGE_UPLOAD_MAX_BYTES),
29
- })
30
- .strict();
31
- class SkillUploadBody extends createZodDto(UploadBody, "SkillUploadBody") {
18
+ class SkillUploadBodyDto extends createZodDto(UploadBody, "SkillUploadBody") {
32
19
  }
33
20
  class SkillCreateBodyDto extends createZodDto(SkillCreateBody, "SkillCreateBody") {
34
21
  }
@@ -115,7 +102,7 @@ __decorate([
115
102
  OrgAction("skills.manage"),
116
103
  __param(0, CurrentPrincipal()),
117
104
  __param(1, CurrentOrg()),
118
- __param(2, ZBody(SkillUploadBody))
105
+ __param(2, ZBody(SkillUploadBodyDto))
119
106
  ], SkillsController.prototype, "createUpload", null);
120
107
  __decorate([
121
108
  Post(),
@@ -1,5 +1,10 @@
1
1
  import { z } from "zod";
2
2
  import type { RouteSchemas } from "../platform/route-schemas.js";
3
+ /** `POST /skills/uploads`: registers a skill package upload (a presigned form). */
4
+ export declare const SkillUploadBody: z.ZodObject<{
5
+ name: z.ZodString;
6
+ size: z.ZodNumber;
7
+ }, z.core.$strict>;
3
8
  /** `POST /skills`: an uploaded skill package (`POST /skills/uploads` gives the id); no text form. */
4
9
  export declare const SkillCreateBody: z.ZodObject<{
5
10
  uploadId: z.ZodString;
@@ -1,6 +1,17 @@
1
1
  import { hasControlChars, MEDIA_NAME_MAX_CHARS } from "@capybara-hq/plugin-sdk";
2
2
  import { z } from "zod";
3
3
  import { SKILL_PACKAGE_UPLOAD_MAX_BYTES } from "../conversations/attachments.service.js";
4
+ /** `POST /skills/uploads`: registers a skill package upload (a presigned form). */
5
+ export const SkillUploadBody = z
6
+ .object({
7
+ name: z
8
+ .string()
9
+ .min(1)
10
+ .max(MEDIA_NAME_MAX_CHARS)
11
+ .refine((s) => !hasControlChars(s), "name must not contain control characters"),
12
+ size: z.number().int().min(1).max(SKILL_PACKAGE_UPLOAD_MAX_BYTES),
13
+ })
14
+ .strict();
4
15
  /** `POST /skills`: an uploaded skill package (`POST /skills/uploads` gives the id); no text form. */
5
16
  export const SkillCreateBody = z
6
17
  .object({ uploadId: z.string().min(1).max(100), shareable: z.boolean().optional() })
@@ -37,6 +48,11 @@ export const InvocableSkillsQuerySchema = z
37
48
  export const SKILL_ROUTES = [
38
49
  { route: "GET /api/v1/orgs/:orgId/skill-changes/:id", params: SkillChangePathParams },
39
50
  { route: "GET /api/v1/orgs/:orgId/agents/:agentId/skills", params: AgentSkillsListParams },
51
+ {
52
+ route: "POST /api/v1/orgs/:orgId/agents/:agentId/skills/uploads",
53
+ params: AgentSkillsListParams,
54
+ body: AgentSkillUploadBody,
55
+ },
40
56
  {
41
57
  route: "POST /api/v1/orgs/:orgId/agents/:agentId/skills",
42
58
  params: AgentSkillsListParams,
@@ -57,6 +73,7 @@ export const SKILL_ROUTES = [
57
73
  },
58
74
  { route: "GET /api/v1/orgs/:orgId/skills" },
59
75
  { route: "GET /api/v1/orgs/:orgId/skills/:id", params: SkillPathParams },
76
+ { route: "POST /api/v1/orgs/:orgId/skills/uploads", body: SkillUploadBody },
60
77
  { route: "POST /api/v1/orgs/:orgId/skills", body: SkillCreateBody },
61
78
  {
62
79
  route: "PUT /api/v1/orgs/:orgId/skills/:id/shareable",
@@ -175,7 +175,9 @@ export declare class SkillsService {
175
175
  * 第 3 步之前中断不会留下可见的版本;已写的文件由清理任务在上传过期后删除(未被任何版本引用时)。
176
176
  * 同一上传已经产生过版本(上次提交了、响应丢了而重试)→ 直接返回那个版本(同组织、同一发起人)。
177
177
  */
178
- upload(orgId: string, actorAccountId: string, uploadId: string, actorTokenId?: string, shareable?: boolean): Promise<UploadedSkill>;
178
+ upload(orgId: string, actorAccountId: string, uploadId: string, actorTokenId?: string, shareable?: boolean,
179
+ /** Merged into the audit detail (a write made through the Platform tool: `via`, …). */
180
+ auditDetail?: Record<string, unknown>): Promise<UploadedSkill>;
179
181
  /**
180
182
  * The transaction of {@link upload}: under the org row lock (re-checking `skills.manage`), the
181
183
  * custom-skill policy is re-checked and the upload consumed (of concurrent requests for the same
@@ -398,7 +398,9 @@ let SkillsService = class SkillsService {
398
398
  * 第 3 步之前中断不会留下可见的版本;已写的文件由清理任务在上传过期后删除(未被任何版本引用时)。
399
399
  * 同一上传已经产生过版本(上次提交了、响应丢了而重试)→ 直接返回那个版本(同组织、同一发起人)。
400
400
  */
401
- async upload(orgId, actorAccountId, uploadId, actorTokenId, shareable) {
401
+ async upload(orgId, actorAccountId, uploadId, actorTokenId, shareable,
402
+ /** Merged into the audit detail (a write made through the Platform tool: `via`, …). */
403
+ auditDetail) {
402
404
  this.storage.assertAvailable();
403
405
  const prefix = skillFilesPrefix(uploadId);
404
406
  // 重试(上次已提交、响应丢了):同一上传已产生的版本直接返回,不再要求上传仍可用
@@ -426,7 +428,7 @@ let SkillsService = class SkillsService {
426
428
  // upload is refused and the owner sees the version in the library (accepted, review M6)
427
429
  const owner = await this.putVersionFiles(orgId, pkg, prefix, false);
428
430
  try {
429
- return await this.createUploadedVersionIn(orgId, actorAccountId, uploadId, pkg, prefix, actorTokenId, shareable, owner);
431
+ return await this.createUploadedVersionIn(orgId, actorAccountId, uploadId, pkg, prefix, actorTokenId, shareable, owner, auditDetail);
430
432
  }
431
433
  catch (e) {
432
434
  if (owner !== undefined)
@@ -440,7 +442,7 @@ let SkillsService = class SkillsService {
440
442
  * upload only one succeeds), then the version is written in the same transaction
441
443
  * ({@link createVersionIn} joins it).
442
444
  */
443
- async createUploadedVersionIn(orgId, actorAccountId, uploadId, pkg, prefix, actorTokenId, shareable, owner) {
445
+ async createUploadedVersionIn(orgId, actorAccountId, uploadId, pkg, prefix, actorTokenId, shareable, owner, auditDetail) {
444
446
  await this.orgLock.lockAndAuthorize(orgId, actorAccountId, "skills.manage");
445
447
  await assertCustomAllowed(this.db.db, "customSkills");
446
448
  await this.attachments.consumeSkillPackage(orgId, actorAccountId, uploadId);
@@ -449,6 +451,7 @@ let SkillsService = class SkillsService {
449
451
  ...(actorTokenId !== undefined && { actorTokenId }),
450
452
  ...(shareable !== undefined && { shareable }),
451
453
  ...(owner !== undefined && { owner }),
454
+ ...(auditDetail !== undefined && { auditDetail }),
452
455
  });
453
456
  }
454
457
  /**
@@ -547,7 +550,13 @@ let SkillsService = class SkillsService {
547
550
  orgId,
548
551
  action: "skill.version_created",
549
552
  target: existing.id,
550
- detail: { name: pkg.name, version, files: manifest.files.length, platformId: promoted },
553
+ detail: {
554
+ name: pkg.name,
555
+ version,
556
+ files: manifest.files.length,
557
+ platformId: promoted,
558
+ ...opts.auditDetail,
559
+ },
551
560
  });
552
561
  await notifySharedUpdate(this.db.db, { kind: "skill", id: promoted }, { name: pkg.name, from: String(version - 1), to: String(version) });
553
562
  return {
@@ -19,6 +19,7 @@ export interface AdminConnectorRow {
19
19
  toolsSyncedAt: Date | null;
20
20
  createdBy: string;
21
21
  createdByName: string;
22
+ createdByAvatarUrl: string | null;
22
23
  createdAt: Date;
23
24
  updatedAt: Date;
24
25
  }
@@ -10,6 +10,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
10
10
  import { Inject, Injectable } from "@nestjs/common";
11
11
  import { sql } from "kysely";
12
12
  import { ApiError } from "../errors.js";
13
+ import { avatarColumns, personAvatarUrl } from "../identity/account-avatar.js";
13
14
  import { KernelDb } from "../infra/database/kernel-db.js";
14
15
  import { endpointView } from "./endpoint.js";
15
16
  const notFound = () => new ApiError("connector.not_found", "Connector not found");
@@ -32,7 +33,7 @@ let AdminConnectors = class AdminConnectors {
32
33
  .innerJoin("orgs as o", "o.id", "c.org_id")
33
34
  .innerJoin("accounts as a", "a.id", "c.created_by")
34
35
  .leftJoin("platform_connector_templates as pt", "pt.id", "c.platform_template_id")
35
- .select([
36
+ .select((eb) => [
36
37
  "c.id",
37
38
  "c.org_id",
38
39
  "o.name as org_name",
@@ -46,6 +47,7 @@ let AdminConnectors = class AdminConnectors {
46
47
  "c.tools_synced_at",
47
48
  "c.created_by",
48
49
  "a.display_name as created_by_name",
50
+ ...avatarColumns(eb, "a", "creator"),
49
51
  "c.created_at",
50
52
  "c.updated_at",
51
53
  sql `(SELECT count(*)::int FROM capybara.connector_tools t
@@ -129,6 +131,7 @@ function toRow(r) {
129
131
  toolsSyncedAt: r.tools_synced_at,
130
132
  createdBy: r.created_by,
131
133
  createdByName: r.created_by_name,
134
+ createdByAvatarUrl: personAvatarUrl(r, "creator", r.created_by),
132
135
  createdAt: r.created_at,
133
136
  updatedAt: r.updated_at,
134
137
  };
@@ -2,12 +2,14 @@ import { type LocalizedName, type ToolDisplay } from "@capybara-hq/plugin-sdk";
2
2
  import { EventLog } from "../conversations/event-log.js";
3
3
  import { type ReviewRecord, type ToolView } from "../conversations/events.js";
4
4
  import { ConversationLeakCheck } from "../conversations/leak-check.js";
5
+ import { type PersonRef } from "../identity/account-avatar.js";
5
6
  import { KernelConfigService } from "../infra/config/kernel-config.service.js";
6
7
  import { KernelDb } from "../infra/database/kernel-db.js";
7
8
  import { TransactionHost } from "../infra/database/transaction-host.js";
8
9
  import { KernelEvents } from "../infra/events/kernel-events.js";
9
10
  import { LockService } from "../infra/lock/lock.service.js";
10
11
  import { type OrgRole } from "../orgs/roles.js";
12
+ import type { FileCardDetail } from "../platform/file-ref.js";
11
13
  import { type PersonFieldSpec } from "../platform/person-fields.js";
12
14
  import { SealedInputs } from "../platform/sealed-inputs.js";
13
15
  import { RunResume } from "../runtime/run-jobs.js";
@@ -163,6 +165,11 @@ export interface ApprovalRecord {
163
165
  zh: string;
164
166
  en: string;
165
167
  };
168
+ /**
169
+ * A tool ask whose call takes a file in place of an upload (platform web parity spec §5): its
170
+ * name, size, sha256, type and an image's thumbnail. Absent otherwise.
171
+ */
172
+ file?: FileCardDetail;
166
173
  /**
167
174
  * The person fields whose entered value was refused as leaked (§4.5; paths only): a call that
168
175
  * then ends without running tells the agent to have them rotated.
@@ -249,6 +256,8 @@ export interface ApprovalView extends ApprovalPublicRecord {
249
256
  parentConversationId?: string;
250
257
  /** 发起本次运行的人。 */
251
258
  initiatorAccountId: string;
259
+ /** The person who decided (next to `decidedBy`); null while pending or when the account is gone. */
260
+ decidedByPerson: PersonRef | null;
252
261
  }
253
262
  /** 新建审批(Task 9 的 loop 在策略为 `ask` 时调用)。 */
254
263
  export interface ApprovalRequestInput {
@@ -276,8 +285,11 @@ export interface ApprovalRequestInput {
276
285
  };
277
286
  /** The scopes the decider may choose; unset: derived (see {@link ApprovalRecord.scopes}). */
278
287
  scopes?: ApprovalScope[];
279
- /** A tool ask's person fields and their target (stored in `detail`; specs only, no values). */
280
- detail?: ToolAskDetail;
288
+ /**
289
+ * A tool ask's person fields and their target (specs only, no values) and the file it takes
290
+ * (stored in `detail`).
291
+ */
292
+ detail?: Omit<ToolAskDetail, "personFields" | "target"> & Partial<Pick<ToolAskDetail, "personFields" | "target">>;
281
293
  }
282
294
  /** A tool ask's `detail`: the person fields the card asks for and the target they belong to. */
283
295
  export interface ToolAskDetail {
@@ -288,6 +300,8 @@ export interface ToolAskDetail {
288
300
  };
289
301
  /** The paths whose entered value the decision refused as leaked (written by the decision). */
290
302
  leakedFields?: string[];
303
+ /** The file the call takes in place of an upload (its sha256 is what the approval binds). */
304
+ file?: FileCardDetail;
291
305
  }
292
306
  export interface DecisionInput {
293
307
  decision: "approve" | "deny";
@@ -18,6 +18,7 @@ import { ConversationLeakCheck } from "../conversations/leak-check.js";
18
18
  import { conversationSourceOf } from "../conversations/source.js";
19
19
  import { ApiError } from "../errors.js";
20
20
  import { clipText } from "../extensions/hooks.js";
21
+ import { loadPeople } from "../identity/account-avatar.js";
21
22
  import { audit } from "../identity/audit.js";
22
23
  import { sha256Hex } from "../identity/hash.js";
23
24
  import { KernelConfigService } from "../infra/config/kernel-config.service.js";
@@ -72,6 +73,15 @@ export function publicRecord(r) {
72
73
  git: strip(r.git),
73
74
  };
74
75
  }
76
+ /** A tool ask's file from its stored `detail` (none: the call takes no file). */
77
+ function fileOf(detail) {
78
+ if (typeof detail !== "object" || detail === null)
79
+ return null;
80
+ const f = detail.file;
81
+ if (typeof f !== "object" || f === null)
82
+ return null;
83
+ return { file: f };
84
+ }
75
85
  /** A tool ask's person fields from its stored `detail` (none: an ordinary tool ask). */
76
86
  function personFieldsOf(detail) {
77
87
  if (typeof detail !== "object" || detail === null)
@@ -131,6 +141,7 @@ function toRecord(r) {
131
141
  git: r.kind === "git" ? (r.detail ?? null) : null,
132
142
  command: r.kind === "command" ? (r.detail ?? null) : null,
133
143
  ...(r.kind === "tool" && personFieldsOf(r.detail)),
144
+ ...(r.kind === "tool" && fileOf(r.detail)),
134
145
  toolKey: r.tool_key,
135
146
  specHash: r.spec_hash,
136
147
  connectorId: r.connector_id,
@@ -1854,6 +1865,7 @@ let ApprovalsService = class ApprovalsService {
1854
1865
  roots.set(p, await rootConversationOf(db.db, p));
1855
1866
  }
1856
1867
  const names = await this.agentNames([...new Set(ctxRows.map((r) => r.agent_id))]);
1868
+ const people = await loadPeople(db.db, recs.flatMap((r) => (r.decidedBy === null ? [] : [r.decidedBy])));
1857
1869
  const connectorIds = [
1858
1870
  ...new Set(recs.flatMap((r) => (r.connectorId === null ? [] : [r.connectorId]))),
1859
1871
  ];
@@ -1884,6 +1896,7 @@ let ApprovalsService = class ApprovalsService {
1884
1896
  return [
1885
1897
  {
1886
1898
  ...publicRecord(r),
1899
+ decidedByPerson: r.decidedBy === null ? null : (people.get(r.decidedBy) ?? null),
1887
1900
  toolName: prefix !== undefined && r.toolKey.startsWith(prefix)
1888
1901
  ? r.toolKey.slice(prefix.length)
1889
1902
  : r.toolKey,
@@ -12,6 +12,7 @@ import { ModelImages } from "../../models/images.js";
12
12
  import { ModelPurposesService } from "../../models/purposes.js";
13
13
  import { PlatformActor } from "../../platform/actor.js";
14
14
  import { AgentDocs } from "../../platform/agent-docs.js";
15
+ import { FileRefs } from "../../platform/file-ref.js";
15
16
  import { PlatformOperations } from "../../platform/registry.js";
16
17
  import { SealedInputs } from "../../platform/sealed-inputs.js";
17
18
  import type { HookRunner } from "../../runtime/hook-calls.js";
@@ -41,6 +42,8 @@ export declare class BuiltinTools {
41
42
  } | undefined, stepLog: StepLog, log: Logger, background: BackgroundTaskStore, finisher: BackgroundTaskFinisher, stopper: BackgroundTaskStopper, platformOps: PlatformOperations, platformActor: PlatformActor, agentDocs: AgentDocs,
42
43
  /** The person's sealed approval card values a Platform write with person fields reads. */
43
44
  sealedInputs: SealedInputs,
45
+ /** A Platform write's file reference: a conversation file (spec §5). */
46
+ fileRefs: FileRefs,
44
47
  /** The schedule tools read tasks and grants; their writes go through the task service. */
45
48
  scheduleStore: ScheduledTaskStore,
46
49
  /** `ScheduleUpdate`'s write: its field change and grant changes in one transaction. */
@@ -27,6 +27,7 @@ import { ModelPurposesService } from "../../models/purposes.js";
27
27
  import { readOrgSettings } from "../../orgs/settings.service.js";
28
28
  import { PlatformActor } from "../../platform/actor.js";
29
29
  import { AgentDocs } from "../../platform/agent-docs.js";
30
+ import { FileRefs } from "../../platform/file-ref.js";
30
31
  import { PlatformOperations } from "../../platform/registry.js";
31
32
  import { SealedInputs } from "../../platform/sealed-inputs.js";
32
33
  import { ProviderListError, ProviderRegistry } from "../../runtime/providers.js";
@@ -64,6 +65,8 @@ let BuiltinTools = class BuiltinTools {
64
65
  purposes, host, stepLog, log, background, finisher, stopper, platformOps, platformActor, agentDocs,
65
66
  /** The person's sealed approval card values a Platform write with person fields reads. */
66
67
  sealedInputs,
68
+ /** A Platform write's file reference: a conversation file (spec §5). */
69
+ fileRefs,
67
70
  /** The schedule tools read tasks and grants; their writes go through the task service. */
68
71
  scheduleStore,
69
72
  /** `ScheduleUpdate`'s write: its field change and grant changes in one transaction. */
@@ -186,6 +189,22 @@ let BuiltinTools = class BuiltinTools {
186
189
  return null;
187
190
  return fields.map((f) => String(f.path));
188
191
  },
192
+ files: fileRefs,
193
+ approvalFileSha256: async (approvalId, call) => {
194
+ // only this call's own approved approval in this org (anything else: none, fails closed)
195
+ const row = await db.db
196
+ .selectFrom("approvals")
197
+ .select(["kind", "detail"])
198
+ .where("id", "=", approvalId)
199
+ .where("org_id", "=", call.orgId)
200
+ .where("run_id", "=", call.runId)
201
+ .where("call_id", "=", call.callId)
202
+ .where("status", "=", "approved")
203
+ .executeTakeFirst();
204
+ const sha = row?.detail?.file
205
+ ?.sha256;
206
+ return row?.kind === "tool" && typeof sha === "string" ? sha : null;
207
+ },
189
208
  }),
190
209
  // the clock in the run context's time zone (the run context carries only the date)
191
210
  currentTimeTool({
@@ -232,16 +251,17 @@ BuiltinTools = __decorate([
232
251
  __param(18, Inject(PlatformActor)),
233
252
  __param(19, Inject(AgentDocs)),
234
253
  __param(20, Inject(SealedInputs)),
235
- __param(21, Inject(ScheduledTaskStore)),
236
- __param(22, Inject(ScheduleUpdates)),
237
- __param(23, Inject(ScheduleToolsPort)),
238
- __param(24, Inject(ModelImages)),
239
- __param(25, Inject(ProviderRegistry)),
240
- __param(26, Inject(ManagedDeviceContextRecorder)),
241
- __param(27, Optional()),
242
- __param(27, Inject(RUN_CONTEXT_CLOCK)),
254
+ __param(21, Inject(FileRefs)),
255
+ __param(22, Inject(ScheduledTaskStore)),
256
+ __param(23, Inject(ScheduleUpdates)),
257
+ __param(24, Inject(ScheduleToolsPort)),
258
+ __param(25, Inject(ModelImages)),
259
+ __param(26, Inject(ProviderRegistry)),
260
+ __param(27, Inject(ManagedDeviceContextRecorder)),
243
261
  __param(28, Optional()),
244
- __param(28, Inject(PERMISSION_CONTEXT_ACTIVATION))
262
+ __param(28, Inject(RUN_CONTEXT_CLOCK)),
263
+ __param(29, Optional()),
264
+ __param(29, Inject(PERMISSION_CONTEXT_ACTIVATION))
245
265
  ], BuiltinTools);
246
266
  export { BuiltinTools };
247
267
  /**
@@ -2,6 +2,7 @@ import type { KernelLogger } from "../../log.js";
2
2
  import type { OrgSettings } from "../../orgs/settings.service.js";
3
3
  import type { ActorFacts } from "../../platform/actor.js";
4
4
  import type { AgentDocTopic } from "../../platform/agent-docs.js";
5
+ import { type FileRefs } from "../../platform/file-ref.js";
5
6
  import { type PlatformOperation } from "../../platform/operation.js";
6
7
  import type { PlatformOperations } from "../../platform/registry.js";
7
8
  import { type SealedInputs } from "../../platform/sealed-inputs.js";
@@ -24,6 +25,10 @@ import type { BuiltinTool, CallPolicyContext } from "../registry.js";
24
25
  * card through {@link CallPolicy.personFields} (never remembered). The approved call reads the
25
26
  * person's sealed values through `personInputs` and its result names each entered path, never a
26
27
  * value.
28
+ * - A write that takes a file in place of an upload (spec §5: `op.fileRef`) resolves it at the
29
+ * policy step: a file over the limit or of another type is denied before the card; the card
30
+ * shows it (`CallPolicy.file`, never remembered) and the approval binds its sha256. Right before
31
+ * `op.run` the file is read again, and bytes with another sha256 are refused.
27
32
  * - Results are JSON text; a list an operation returns is capped at {@link LIST_MAX} entries.
28
33
  */
29
34
  /** The most entries of a list in one result (operations that page return `next`). */
@@ -56,6 +61,18 @@ export interface PlatformToolDeps {
56
61
  runId: string;
57
62
  callId: string;
58
63
  }): Promise<string[] | null>;
64
+ /** Resolves a write's file reference (`op.fileRef`); absent: no write takes a file. */
65
+ files?: Pick<FileRefs, "resolve">;
66
+ /**
67
+ * The sha256 of the file an approval's card showed (its stored `detail.file`), or null when it
68
+ * has none or is not this call's approved approval in the org: what an approved call's file is
69
+ * bound to.
70
+ */
71
+ approvalFileSha256?(approvalId: string, call: {
72
+ orgId: string;
73
+ runId: string;
74
+ callId: string;
75
+ }): Promise<string | null>;
59
76
  }
60
77
  /**
61
78
  * An operation's input keys as `browse` and `search` show them, so a call needs no guess:
@@ -64,6 +81,12 @@ export interface PlatformToolDeps {
64
81
  * it. Types, bounds and an example stay in `describe`.
65
82
  */
66
83
  export declare function paramsLine(op: PlatformOperation): string;
84
+ /**
85
+ * An operation's result without people's avatars (account profile spec §3, §5.4: a person's
86
+ * avatar is never model-visible). Drops every avatar key whose value is a person avatar URL or
87
+ * null (a person shape without an image); an agent's own avatar URL stays. Names stay.
88
+ */
89
+ export declare function withoutPersonAvatars(value: unknown): unknown;
67
90
  /** Model-visible: the person's values expired before the approved call ran (spec §4.3). */
68
91
  export declare const PERSON_INPUTS_EXPIRED_TEXT = "The values the person entered expired before they were applied; call the operation again.";
69
92
  export declare function platformTool(deps: PlatformToolDeps): BuiltinTool;