@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
@@ -2,11 +2,13 @@ import type { LocalizedName, Logger } from "@capybara-hq/plugin-sdk";
2
2
  import type { z } from "zod";
3
3
  import { ExtensionDisplayNames } from "../extensions/display-name.js";
4
4
  import { PluginIcons } from "../extensions/plugin-icons.js";
5
- import { type Account, AccountsService } from "../identity/accounts.js";
5
+ import { type AccountView } from "../identity/account-avatar.js";
6
+ import { AccountsService } from "../identity/accounts.js";
6
7
  import { type Principal } from "../identity/principal.js";
7
8
  import { SessionService } from "../identity/sessions.js";
8
9
  import { type DeploymentSettingsView, SettingsService } from "../identity/settings.js";
9
10
  import { KernelConfigService } from "../infra/config/kernel-config.service.js";
11
+ import { KernelDb } from "../infra/database/kernel-db.js";
10
12
  import { type ModelDisabledPatch, type ModelProviderParams } from "../models/enablement.controller.js";
11
13
  import { type ModelDisableResult, ModelEnablement } from "../models/enablement.js";
12
14
  import { type ModelPrice, type ModelPricePut, PricesService } from "../models/prices.js";
@@ -34,21 +36,24 @@ export declare class AdminController {
34
36
  private readonly config;
35
37
  private readonly icons;
36
38
  private readonly members;
37
- constructor(accounts: AccountsService, sessions: SessionService, log: Logger, orgs: OrgsService, settings: SettingsService, prices: PricesService, purposes: ModelPurposesService, registry: ProviderRegistry, displayNames: ExtensionDisplayNames, enablement: ModelEnablement, config: KernelConfigService, icons: PluginIcons, members: MembersService);
39
+ private readonly db;
40
+ constructor(accounts: AccountsService, sessions: SessionService, log: Logger, orgs: OrgsService, settings: SettingsService, prices: PricesService, purposes: ModelPurposesService, registry: ProviderRegistry, displayNames: ExtensionDisplayNames, enablement: ModelEnablement, config: KernelConfigService, icons: PluginIcons, members: MembersService, db: KernelDb);
41
+ /** One account with its avatar URL and source. */
42
+ private view;
38
43
  /**
39
44
  * 全部账号,按 id 升序分页:`next` 为下一页的游标(作为 `after` 传回),没有更多时为 null。
40
45
  * 多取一条判断是否还有下一页。
41
46
  */
42
47
  listAccounts(q: z.infer<typeof AccountListQuery>): Promise<{
43
- accounts: Account[];
48
+ accounts: AccountView[];
44
49
  next: string | null;
45
50
  }>;
46
51
  createAccount(principal: Principal, body: z.infer<typeof CreateAccountBody>): Promise<{
47
- account: Account;
52
+ account: AccountView;
48
53
  }>;
49
54
  /** 改显示名 / 状态 / 超级管理员;停用时同时吊销该账号的全部会话与个人令牌。 */
50
55
  updateAccount(principal: Principal, { accountId }: z.infer<typeof AccountParams>, body: z.infer<typeof UpdateAccountBody>): Promise<{
51
- account: Account;
56
+ account: AccountView;
52
57
  }>;
53
58
  /**
54
59
  * 全部组织的元数据与成员数(不含成员明细), with the deployment's defaults of the limits an org
@@ -11,11 +11,13 @@ import { Controller, Get, HttpCode, Inject, Patch, Post, Put } from "@nestjs/com
11
11
  import { ApiError } from "../errors.js";
12
12
  import { ExtensionDisplayNames } from "../extensions/display-name.js";
13
13
  import { PluginIcons } from "../extensions/plugin-icons.js";
14
+ import { withAvatarUrl, withAvatarUrls } from "../identity/account-avatar.js";
14
15
  import { AccountsService } from "../identity/accounts.js";
15
16
  import { CurrentPrincipal, patTokenId, requireUser, SuperAdmin, } from "../identity/principal.js";
16
17
  import { SessionService } from "../identity/sessions.js";
17
18
  import { SettingsService } from "../identity/settings.js";
18
19
  import { KernelConfigService } from "../infra/config/kernel-config.service.js";
20
+ import { KernelDb } from "../infra/database/kernel-db.js";
19
21
  import { KERNEL_LOGGER } from "../infra/tokens.js";
20
22
  import { createZodDto } from "../infra/validation/create-zod-dto.js";
21
23
  import { ZBody, ZParam, ZQuery } from "../infra/validation/zod-params.js";
@@ -63,7 +65,8 @@ let AdminController = class AdminController {
63
65
  config;
64
66
  icons;
65
67
  members;
66
- constructor(accounts, sessions, log, orgs, settings, prices, purposes, registry, displayNames, enablement, config, icons, members) {
68
+ db;
69
+ constructor(accounts, sessions, log, orgs, settings, prices, purposes, registry, displayNames, enablement, config, icons, members, db) {
67
70
  this.accounts = accounts;
68
71
  this.sessions = sessions;
69
72
  this.log = log;
@@ -77,6 +80,11 @@ let AdminController = class AdminController {
77
80
  this.config = config;
78
81
  this.icons = icons;
79
82
  this.members = members;
83
+ this.db = db;
84
+ }
85
+ /** One account with its avatar URL and source. */
86
+ async view(account) {
87
+ return withAvatarUrl(this.db.db, account);
80
88
  }
81
89
  /**
82
90
  * 全部账号,按 id 升序分页:`next` 为下一页的游标(作为 `after` 传回),没有更多时为 null。
@@ -87,9 +95,9 @@ let AdminController = class AdminController {
87
95
  limit: q.limit + 1,
88
96
  ...(q.after !== undefined && { after: q.after }),
89
97
  });
90
- const accounts = rows.slice(0, q.limit);
91
- const next = rows.length > q.limit ? (accounts.at(-1)?.id ?? null) : null;
92
- return { accounts, next };
98
+ const page = rows.slice(0, q.limit);
99
+ const next = rows.length > q.limit ? (page.at(-1)?.id ?? null) : null;
100
+ return { accounts: await withAvatarUrls(this.db.db, page), next };
93
101
  }
94
102
  async createAccount(principal, body) {
95
103
  const actor = requireUser(principal);
@@ -100,7 +108,7 @@ let AdminController = class AdminController {
100
108
  ...(body.email !== undefined && { email: body.email }),
101
109
  ...(body.superAdmin !== undefined && { superAdmin: body.superAdmin }),
102
110
  }, actor.account.id, patTokenId(actor));
103
- return { account };
111
+ return { account: await this.view(account) };
104
112
  }
105
113
  /** 改显示名 / 状态 / 超级管理员;停用时同时吊销该账号的全部会话与个人令牌。 */
106
114
  async updateAccount(principal, { accountId }, body) {
@@ -122,7 +130,7 @@ let AdminController = class AdminController {
122
130
  err,
123
131
  });
124
132
  }
125
- return { account };
133
+ return { account: await this.view(account) };
126
134
  }
127
135
  /**
128
136
  * 全部组织的元数据与成员数(不含成员明细), with the deployment's defaults of the limits an org
@@ -285,6 +293,7 @@ AdminController = __decorate([
285
293
  __param(9, Inject(ModelEnablement)),
286
294
  __param(10, Inject(KernelConfigService)),
287
295
  __param(11, Inject(PluginIcons)),
288
- __param(12, Inject(MembersService))
296
+ __param(12, Inject(MembersService)),
297
+ __param(13, Inject(KernelDb))
289
298
  ], AdminController);
290
299
  export { AdminController };
@@ -18,7 +18,8 @@ export const CreateAccountBody = z.object({
18
18
  });
19
19
  export const AccountParams = z.object({ accountId: z.string().min(1).max(100) });
20
20
  export const UpdateAccountBody = z.object({
21
- displayName: z.string().trim().min(1).max(100).optional(),
21
+ /** A body sanity bound; a changed name must have at most 64 code points (the service checks). */
22
+ displayName: z.string().trim().min(1).max(1000).optional(),
22
23
  status: z.enum(["active", "disabled"]).optional(),
23
24
  isSuperAdmin: z.boolean().optional(),
24
25
  });
@@ -12,6 +12,7 @@ export interface AuditEvent {
12
12
  id: string;
13
13
  name: string | null;
14
14
  email: string | null;
15
+ avatarUrl: string | null;
15
16
  } | null;
16
17
  /** Done with a personal access token. */
17
18
  viaToken: boolean;
@@ -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 { sql } from "kysely";
12
+ import { avatarColumns, personAvatarUrl } from "../identity/account-avatar.js";
12
13
  import { KernelDb } from "../infra/database/kernel-db.js";
13
14
  /** `prefix` as a LIKE pattern matching the strings that start with it. */
14
15
  const likePrefix = (prefix) => `${prefix.replace(/[\\%_]/g, "\\$&")}%`;
@@ -27,7 +28,7 @@ let AuditLogService = class AuditLogService {
27
28
  let query = this.kdb.db
28
29
  .selectFrom("audit_events as a")
29
30
  .leftJoin("accounts as ac", "ac.id", "a.actor_account_id")
30
- .select([
31
+ .select((eb) => [
31
32
  "a.id",
32
33
  "a.at",
33
34
  "a.actor_account_id",
@@ -36,6 +37,7 @@ let AuditLogService = class AuditLogService {
36
37
  "a.target",
37
38
  "ac.display_name",
38
39
  "ac.email",
40
+ ...avatarColumns(eb, "ac", "actor"),
39
41
  // only the one flag the log shows, never the whole detail (spec §9)
40
42
  sql `a.detail->>'via'`.as("via"),
41
43
  ]);
@@ -61,6 +63,7 @@ let AuditLogService = class AuditLogService {
61
63
  id: r.actor_account_id,
62
64
  name: r.display_name ?? null,
63
65
  email: r.email ?? null,
66
+ avatarUrl: personAvatarUrl(r, "actor", r.actor_account_id),
64
67
  },
65
68
  viaToken: r.actor_token_id !== null,
66
69
  viaAgent: r.via === "agent",
@@ -32,6 +32,8 @@ export const AdminExtensionConfigBody = z.object({
32
32
  secretEntries: z.array(AdminExtensionSecretEntry).max(200).optional(),
33
33
  });
34
34
  export const ADMIN_EXTENSION_ROUTES = [
35
+ // the extension package is the raw body (no schema)
36
+ { route: "POST /api/v1/admin/extensions/packages/file" },
35
37
  { route: "GET /api/v1/admin/extensions" },
36
38
  { route: "GET /api/v1/admin/extensions/:name", params: AdminExtensionNamePathParams },
37
39
  { route: "POST /api/v1/admin/extensions/:name/enable", params: AdminExtensionNamePathParams },
@@ -12,6 +12,7 @@ export interface AdminAgentRow {
12
12
  avatar: AgentAvatar;
13
13
  ownerAccountId: string;
14
14
  ownerName: string;
15
+ ownerAvatarUrl: string | null;
15
16
  needsReassignment: boolean;
16
17
  visibility: AgentVisibility;
17
18
  createdFrom: {
@@ -11,6 +11,7 @@ import { Inject, Injectable } from "@nestjs/common";
11
11
  import { sql } from "kysely";
12
12
  import { escapeLike } from "../conversations/conversations.service.js";
13
13
  import { ApiError } from "../errors.js";
14
+ import { avatarColumns, personAvatarUrl } from "../identity/account-avatar.js";
14
15
  import { KernelDb } from "../infra/database/kernel-db.js";
15
16
  import { agentSkills, builtinSkillIds, builtinSkillPlugins, linkedCopyIds, skillIdsOf, usableSkillVersions, } from "../skills/usable.js";
16
17
  import { AgentLookup } from "./agent-lookup.js";
@@ -183,7 +184,7 @@ let AdminAgents = class AdminAgents {
183
184
  .innerJoin("agent_versions", (j) => j
184
185
  .onRef("agent_versions.agent_id", "=", "agents.id")
185
186
  .onRef("agent_versions.version", "=", "agents.current_version"))
186
- .select([
187
+ .select((eb) => [
187
188
  "agents.id",
188
189
  "agents.org_id",
189
190
  "orgs.name as org_name",
@@ -192,6 +193,7 @@ let AdminAgents = class AdminAgents {
192
193
  "agents.profile_avatar",
193
194
  "agents.owner_account_id",
194
195
  "accounts.display_name as owner_name",
196
+ ...avatarColumns(eb, "accounts", "owner"),
195
197
  "agents.needs_reassignment",
196
198
  "agents.visibility",
197
199
  "agents.created_from_template_id",
@@ -217,6 +219,7 @@ function toRow(r, skillsOff) {
217
219
  avatar: (r.profile_avatar ?? null),
218
220
  ownerAccountId: r.owner_account_id,
219
221
  ownerName: r.owner_name,
222
+ ownerAvatarUrl: personAvatarUrl(r, "owner", r.owner_account_id),
220
223
  needsReassignment: r.needs_reassignment,
221
224
  visibility: r.visibility,
222
225
  createdFrom: r.created_from_template_id === null
@@ -4,22 +4,13 @@ import { AttachmentsService, type CreatedAttachment } from "../conversations/att
4
4
  import { type Principal } from "../identity/principal.js";
5
5
  import { type OrgContext } from "../orgs/org.guard.js";
6
6
  import { AgentProfileService } from "./agent-profile.service.js";
7
- import { AgentCreateBody, AgentFromTemplateBody, AgentFromTemplatePreviewBody, AgentProfileBody, AgentUpdateBody } from "./agents.schemas.js";
7
+ import { AgentCreateBody, AgentFromTemplateBody, AgentFromTemplatePreviewBody, AgentProfileBody, AgentUpdateBody, AgentAvatarUploadBody as AvatarUploadBody } from "./agents.schemas.js";
8
8
  import { AgentsService, type AgentVersionSummary, type AgentView, type AgentWarning } from "./agents.service.js";
9
9
  import { AgentsFromTemplate, type TemplatePreview } from "./from-template.service.js";
10
10
  import type { AgentProfile } from "./profile.js";
11
11
  declare const OwnerBody: z.ZodObject<{
12
12
  accountId: z.ZodString;
13
13
  }, z.core.$strict>;
14
- declare const AvatarUploadBody: z.ZodObject<{
15
- name: z.ZodString;
16
- contentType: z.ZodEnum<{
17
- "image/jpeg": "image/jpeg";
18
- "image/png": "image/png";
19
- "image/webp": "image/webp";
20
- }>;
21
- size: z.ZodNumber;
22
- }, z.core.$strict>;
23
14
  /**
24
15
  * Agent 定义(`/api/v1/orgs/:orgId/agents`)。读用 `agents.use`(访客与服务令牌可用),
25
16
  * 写用 `agents.create`(member 以上、HUMAN_ONLY),修改 / 删除的负责人或管理员判定在服务的组织行锁内完成。
@@ -7,31 +7,19 @@ 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, Patch, Post, Res } from "@nestjs/common";
12
11
  import { z } from "zod";
13
- import { AGENT_AVATAR_CONTENT_TYPES, AGENT_AVATAR_DOWNLOAD_TTL_SECONDS, AGENT_AVATAR_MAX_BYTES, AttachmentsService, } from "../conversations/attachments.service.js";
12
+ import { AGENT_AVATAR_DOWNLOAD_TTL_SECONDS, AttachmentsService, } from "../conversations/attachments.service.js";
14
13
  import { ApiError } from "../errors.js";
15
14
  import { CurrentPrincipal, patTokenId, requireUser, } from "../identity/principal.js";
16
15
  import { createZodDto } from "../infra/validation/create-zod-dto.js";
17
16
  import { ZBody } from "../infra/validation/zod-params.js";
18
17
  import { CurrentOrg, OrgAction } from "../orgs/org.guard.js";
19
18
  import { AgentProfileService } from "./agent-profile.service.js";
20
- import { AgentCreateBody, AgentFromTemplateBody, AgentFromTemplatePreviewBody, AgentProfileBody, AgentUpdateBody, } from "./agents.schemas.js";
19
+ import { AgentCreateBody, AgentFromTemplateBody, AgentFromTemplatePreviewBody, AgentProfileBody, AgentUpdateBody, AgentAvatarUploadBody as AvatarUploadBody, } from "./agents.schemas.js";
21
20
  import { AgentsService, } from "./agents.service.js";
22
21
  import { AgentsFromTemplate } from "./from-template.service.js";
23
22
  const OwnerBody = z.object({ accountId: z.string().min(1).max(100) }).strict();
24
- const AvatarUploadBody = z
25
- .object({
26
- name: z
27
- .string()
28
- .min(1)
29
- .max(MEDIA_NAME_MAX_CHARS)
30
- .refine((s) => !hasControlChars(s), "name must not contain control characters"),
31
- contentType: z.enum(AGENT_AVATAR_CONTENT_TYPES),
32
- size: z.number().int().min(1).max(AGENT_AVATAR_MAX_BYTES),
33
- })
34
- .strict();
35
23
  /** 服务令牌没有账号:以 null 作为 viewer,只看到 visibility='org' 的 agent。 */
36
24
  const viewerOf = (p) => (p.kind === "user" ? p.account.id : null);
37
25
  class AgentCreateBodyDto extends createZodDto(AgentCreateBody, "AgentCreateBody") {
@@ -392,6 +392,16 @@ export declare const AgentProfileBody: z.ZodObject<{
392
392
  }, z.core.$strict>>>;
393
393
  expectedUpdatedAt: z.ZodString;
394
394
  }, z.core.$strict>;
395
+ /** `POST …/avatar/uploads`: registers an avatar image upload (a presigned form). */
396
+ export declare const AgentAvatarUploadBody: z.ZodObject<{
397
+ name: z.ZodString;
398
+ contentType: z.ZodEnum<{
399
+ "image/jpeg": "image/jpeg";
400
+ "image/png": "image/png";
401
+ "image/webp": "image/webp";
402
+ }>;
403
+ size: z.ZodNumber;
404
+ }, z.core.$strict>;
395
405
  export declare const AgentFromTemplatePreviewBody: z.ZodObject<{
396
406
  templateId: z.ZodString;
397
407
  }, z.core.$strict>;
@@ -1,4 +1,6 @@
1
+ import { hasControlChars, MEDIA_NAME_MAX_CHARS } from "@capybara-hq/plugin-sdk";
1
2
  import { z } from "zod";
3
+ import { AGENT_AVATAR_CONTENT_TYPES, AGENT_AVATAR_MAX_BYTES, } from "../conversations/attachments.service.js";
2
4
  import { AGENT_VISIBILITIES } from "./agents.service.js";
3
5
  import { AgentDefinitionSchema, ModelRef } from "./definition.js";
4
6
  import { PresetAvatarSchema, ProfileInputSchema } from "./profile.js";
@@ -60,6 +62,18 @@ export const AgentProfileBody = ProfileInputSchema.omit({ description: true })
60
62
  expectedUpdatedAt: z.string().min(1).max(40),
61
63
  })
62
64
  .strict();
65
+ /** `POST …/avatar/uploads`: registers an avatar image upload (a presigned form). */
66
+ export const AgentAvatarUploadBody = z
67
+ .object({
68
+ name: z
69
+ .string()
70
+ .min(1)
71
+ .max(MEDIA_NAME_MAX_CHARS)
72
+ .refine((s) => !hasControlChars(s), "name must not contain control characters"),
73
+ contentType: z.enum(AGENT_AVATAR_CONTENT_TYPES),
74
+ size: z.number().int().min(1).max(AGENT_AVATAR_MAX_BYTES),
75
+ })
76
+ .strict();
63
77
  const TemplateId = z.string().min(1).max(100);
64
78
  export const AgentFromTemplatePreviewBody = z.object({ templateId: TemplateId }).strict();
65
79
  export const AgentFromTemplateBody = z
@@ -102,6 +116,11 @@ export const AGENT_ROUTES = [
102
116
  params: AgentPathParams,
103
117
  body: AgentProfileBody,
104
118
  },
119
+ {
120
+ route: "POST /api/v1/orgs/:orgId/agents/:agentId/avatar/uploads",
121
+ params: AgentPathParams,
122
+ body: AgentAvatarUploadBody,
123
+ },
105
124
  {
106
125
  route: "POST /api/v1/orgs/:orgId/agents/from-template/preview",
107
126
  body: AgentFromTemplatePreviewBody,
@@ -1,6 +1,7 @@
1
1
  import { ConversationAccess } from "../conversations/access.js";
2
2
  import { EventLog } from "../conversations/event-log.js";
3
3
  import { ConversationDevices } from "../devices/conversation-devices.js";
4
+ import { type PersonRef } from "../identity/account-avatar.js";
4
5
  import { KernelDb } from "../infra/database/kernel-db.js";
5
6
  import { SandboxService } from "../sandbox/sandbox.service.js";
6
7
  import { BackgroundTaskStopper } from "./stop.js";
@@ -14,6 +15,8 @@ export interface BackgroundTaskView {
14
15
  conversationId: string;
15
16
  /** The child conversation of a sub-agent's task; null for the conversation's own task. */
16
17
  subagentId: string | null;
18
+ /** The person whose run started it (next to the run's trigger); null when the account is gone. */
19
+ trigger: PersonRef | null;
17
20
  description: string;
18
21
  command: string;
19
22
  status: BackgroundTaskStatus;
@@ -70,6 +73,8 @@ export declare class BackgroundTasks {
70
73
  * in the root's sandbox, agent map spec §6); `conversation.not_found` when not visible.
71
74
  */
72
75
  private scope;
76
+ /** The views of the tasks, their trigger people read in one query. */
77
+ private views;
73
78
  private view;
74
79
  private owned;
75
80
  /** The tasks of the conversation and its sub-agents, newest first. */
@@ -14,6 +14,7 @@ import { EventLog } from "../conversations/event-log.js";
14
14
  import { conversationTree } from "../conversations/tree.js";
15
15
  import { ConversationDevices } from "../devices/conversation-devices.js";
16
16
  import { ApiError } from "../errors.js";
17
+ import { loadPeople } from "../identity/account-avatar.js";
17
18
  import { audit } from "../identity/audit.js";
18
19
  import { KernelDb } from "../infra/database/kernel-db.js";
19
20
  import { rootConversationOf } from "../runtime/subagents/child.js";
@@ -67,11 +68,17 @@ let BackgroundTasks = class BackgroundTasks {
67
68
  // the conversation is the org's (isAccessible), and so is every sub-agent conversation below it
68
69
  return (await conversationTree(this.db.db, conversationId)).map((c) => c.id);
69
70
  }
70
- view(task, conversationId) {
71
+ /** The views of the tasks, their trigger people read in one query. */
72
+ async views(tasks, conversationId) {
73
+ const people = await loadPeople(this.db.db, tasks.map((t) => t.triggerAccountId));
74
+ return tasks.map((t) => this.view(t, conversationId, people.get(t.triggerAccountId) ?? null));
75
+ }
76
+ view(task, conversationId, trigger) {
71
77
  return {
72
78
  id: task.id,
73
79
  conversationId,
74
80
  subagentId: task.conversationId === conversationId ? null : task.conversationId,
81
+ trigger,
75
82
  description: task.description,
76
83
  command: task.command,
77
84
  status: task.status,
@@ -96,7 +103,7 @@ let BackgroundTasks = class BackgroundTasks {
96
103
  /** The tasks of the conversation and its sub-agents, newest first. */
97
104
  async list(orgId, conversationId, accountId) {
98
105
  const ids = await this.scope(orgId, conversationId, accountId);
99
- return (await this.store.listFor(ids)).map((t) => this.view(t, conversationId));
106
+ return this.views(await this.store.listFor(ids), conversationId);
100
107
  }
101
108
  /**
102
109
  * A person's stop. Returns the row after the stop: `running` with `stopping` true when another
@@ -121,7 +128,7 @@ let BackgroundTasks = class BackgroundTasks {
121
128
  ...auditDetail,
122
129
  },
123
130
  });
124
- return this.view(after, conversationId);
131
+ return (await this.views([after], conversationId))[0];
125
132
  }
126
133
  /**
127
134
  * Whether the task's device may still be used by its conversation's owner (the access
@@ -64,6 +64,8 @@ export const AdminCatalogGuideQuery = z
64
64
  .object({ locale: z.enum(["en", "zh"]).optional() })
65
65
  .strict();
66
66
  export const ADMIN_CATALOG_ROUTES = [
67
+ // the plugin package is the raw body (no schema)
68
+ { route: "POST /api/v1/admin/catalog/import/file" },
67
69
  { route: "GET /api/v1/admin/catalog/items", query: CatalogItemsQuery },
68
70
  { route: "GET /api/v1/admin/catalog/items/:id", params: CatalogIdPathParams },
69
71
  {
@@ -84,6 +84,8 @@ export const COMPONENT_SCOPE_ROUTES = [
84
84
  params: ComponentParams,
85
85
  body: ComponentShownSchema,
86
86
  },
87
+ // the skill package is the raw body (no schema)
88
+ { route: "POST /api/v1/admin/components/skill/:id/versions", params: ComponentIdSchema },
87
89
  {
88
90
  route: "POST /api/v1/admin/components/agent_template/:id/versions",
89
91
  params: ComponentIdSchema,
@@ -188,7 +188,7 @@ export declare function headsToResolve(entries: readonly MarketplaceEntry[], imp
188
188
  /** The host versions (an entry's `minKernel` is judged against them). */
189
189
  export declare const HOST_VERSIONS: {
190
190
  readonly kernel: string;
191
- readonly sdk: "0.1.0-rc.43";
191
+ readonly sdk: "0.1.0-rc.44";
192
192
  };
193
193
  /** Whether this deployment satisfies the entry's `minKernel`. */
194
194
  export declare const entryCompatible: (e: Pick<MarketplaceEntry, "minKernel">) => boolean;
@@ -11,6 +11,8 @@ export const OrgUploadConfirmBody = z
11
11
  export const OrgOwnedShareableBody = z.object({ shareable: z.boolean() }).strict();
12
12
  export const OrgOwnedDeleteBody = z.object({ previewHash: z.string().min(1).max(128) }).strict();
13
13
  export const ORG_PLUGIN_UPLOAD_ROUTES = [
14
+ // the plugin package is the raw body (no schema)
15
+ { route: "POST /api/v1/orgs/:orgId/catalog/uploads/file" },
14
16
  { route: "GET /api/v1/orgs/:orgId/catalog/uploads/:stagingId", params: OrgUploadStagingParams },
15
17
  {
16
18
  route: "PUT /api/v1/orgs/:orgId/owned-plugins/:id/shareable",
@@ -108,6 +108,8 @@ export interface CatalogRequestView {
108
108
  requestedBy: string | null;
109
109
  /** 申请人的显示名(账号已删除为 null)。 */
110
110
  requestedByName: string | null;
111
+ /** The requester's avatar URL (null: none, or the account is gone). */
112
+ requestedByAvatarUrl: string | null;
111
113
  decidedBy: string | null;
112
114
  decidedAt: string | null;
113
115
  /** The prepared import of an approved `import` request that is not confirmed yet. */
@@ -11,6 +11,7 @@ import { randomUUID } from "node:crypto";
11
11
  import { Inject, Injectable } from "@nestjs/common";
12
12
  import { sql } from "kysely";
13
13
  import { ApiError } from "../errors.js";
14
+ import { avatarColumns, personAvatarUrl } from "../identity/account-avatar.js";
14
15
  import { audit } from "../identity/audit.js";
15
16
  import { readOrgMarketplaceBrowse } from "../identity/settings.js";
16
17
  import { SuperAdminLock } from "../identity/super-admin.js";
@@ -818,7 +819,7 @@ let CatalogRequestsService = class CatalogRequestsService {
818
819
  // a connector_setup request's agent and its current version (name, pending connectors)
819
820
  .leftJoin("agents as ag", "ag.id", "r.agent_id")
820
821
  .leftJoin("agent_versions as av", (j) => j.onRef("av.agent_id", "=", "ag.id").onRef("av.version", "=", "ag.current_version"))
821
- .select([
822
+ .select((eb) => [
822
823
  "r.agent_id",
823
824
  "r.pending_keys",
824
825
  "ag.deleted_at as agent_deleted_at",
@@ -838,6 +839,7 @@ let CatalogRequestsService = class CatalogRequestsService {
838
839
  "r.reason",
839
840
  "r.requested_by",
840
841
  "a.display_name as requested_by_name",
842
+ ...avatarColumns(eb, "a", "requester"),
841
843
  "r.decided_by",
842
844
  "r.decided_at",
843
845
  "r.staging_id",
@@ -953,6 +955,7 @@ function toView(r, templateNames) {
953
955
  reason: r.reason,
954
956
  requestedBy: r.requested_by,
955
957
  requestedByName: r.requested_by_name,
958
+ requestedByAvatarUrl: r.requested_by === null ? null : personAvatarUrl(r, "requester", r.requested_by),
956
959
  decidedBy: r.decided_by,
957
960
  decidedAt: r.decided_at?.toISOString() ?? null,
958
961
  stagingId: r.status === "pending" ? r.staging_id : null,
@@ -1,5 +1,6 @@
1
1
  import { type ChannelCard, type FormAnswer, type InputForm, type OutboundMessage } from "@capybara-hq/plugin-sdk";
2
2
  import type { KernelSchemaDb } from "../db/kernel-schema.js";
3
+ import type { FileCardDetail } from "../platform/file-ref.js";
3
4
  import type { PermissionEscalation } from "../sandbox/permission-call-types.js";
4
5
  import type { ApprovalsService, ApprovalView, CommandAskDetail, GitAskView, NetworkAskView } from "../tools/approvals.service.js";
5
6
  import { type ToolInfo } from "../tools/info.js";
@@ -32,6 +33,14 @@ export declare function keyArgument(input: unknown, keyArgs: readonly string[]):
32
33
  * behind the card's web link.
33
34
  */
34
35
  export declare function callSummary(v: Pick<ApprovalView, "summary" | "input">, display: Pick<ToolInfo, "title" | "keyArgs"> | undefined, locale: ChannelLocale, redact?: (s: string) => string): string;
36
+ /** A byte count as people read it (`1.5 KB`). */
37
+ export declare function humanSize(bytes: number): string;
38
+ /**
39
+ * The approval card's line about the file a call takes in place of an upload (platform web parity
40
+ * spec §5): name, size and the first 12 hex of the sha256, as text (IM shows no thumbnail). The
41
+ * name is a person's file name: one line, no backticks, redacted, cut.
42
+ */
43
+ export declare function fileLine(f: Pick<FileCardDetail, "name" | "size" | "sha256">, locale: ChannelLocale, redact?: (s: string) => string): string;
35
44
  /** 去掉末尾斜杠的 `http.publicUrl`;未配置返回 undefined。 */
36
45
  export declare function webBase(publicUrl: string | undefined): string | undefined;
37
46
  /** 会话的网页链接(与审批详情的 `conversationPath` 一致:`/chat/<id>`,不含语言前缀)。 */
@@ -131,6 +131,31 @@ export function callSummary(v, display, locale, redact = (s) => s) {
131
131
  }
132
132
  return cut(redact(line), CARD_SUMMARY_MAX);
133
133
  }
134
+ /** A byte count as people read it (`1.5 KB`). */
135
+ export function humanSize(bytes) {
136
+ if (bytes < 1024)
137
+ return `${bytes} B`;
138
+ const units = ["KB", "MB", "GB"];
139
+ let v = bytes / 1024;
140
+ let i = 0;
141
+ while (v >= 1024 && i < units.length - 1) {
142
+ v /= 1024;
143
+ i += 1;
144
+ }
145
+ return `${v >= 10 ? Math.round(v) : Math.round(v * 10) / 10} ${units[i]}`;
146
+ }
147
+ /**
148
+ * The approval card's line about the file a call takes in place of an upload (platform web parity
149
+ * spec §5): name, size and the first 12 hex of the sha256, as text (IM shows no thumbnail). The
150
+ * name is a person's file name: one line, no backticks, redacted, cut.
151
+ */
152
+ export function fileLine(f, locale, redact = (s) => s) {
153
+ const name = cut(redact(f.name.replace(/[\r\n`]+/g, " ").trim()), 80);
154
+ return phrase("approvalFile", locale)
155
+ .replace("{name}", name)
156
+ .replace("{size}", humanSize(f.size))
157
+ .replace("{sha}", f.sha256.slice(0, 12));
158
+ }
134
159
  /** 去掉末尾斜杠的 `http.publicUrl`;未配置返回 undefined。 */
135
160
  export function webBase(publicUrl) {
136
161
  return publicUrl ? publicUrl.replace(/\/+$/, "") : undefined;
@@ -323,7 +348,13 @@ export async function approvalCard(d, approvalId, base, locale, redact) {
323
348
  agentName: v.agent.name || "Agent",
324
349
  // the field keeps its contract name; it carries the call line (a network ask's hosts and
325
350
  // command, a command ask's reason and command), never the raw input
326
- inputPreview: special?.inputPreview ?? callSummary(v, display, locale, redact),
351
+ inputPreview: special?.inputPreview ??
352
+ [
353
+ callSummary(v, display, locale, redact),
354
+ ...(v.file !== undefined ? [fileLine(v.file, locale, redact)] : []),
355
+ ]
356
+ .filter((l) => l !== "")
357
+ .join("\n"),
327
358
  // the scopes the approval allows (the kernel stores them for per-call policies); a network,
328
359
  // git or command ask offers only those it labels (an older network ask may still list
329
360
  // `always`, which the decision refuses)
@@ -177,6 +177,11 @@ export declare const CHANNEL_PHRASES: {
177
177
  readonly zh: "启动一个后台进程,它在沙箱外持续运行,直到自行退出或被停止。";
178
178
  readonly en: "Starts a background process that keeps running outside the sandbox until it exits or is stopped.";
179
179
  };
180
+ /** An approval card's line about the file the call takes (`{name}`, `{size}`, `{sha}`: 12 hex). */
181
+ readonly approvalFile: {
182
+ readonly zh: "文件:{name}({size},sha256 {sha})";
183
+ readonly en: "File: {name} ({size}, sha256 {sha})";
184
+ };
180
185
  /** An escalation card's working directory line (`{dir}`). */
181
186
  readonly escalationCwd: {
182
187
  readonly zh: "运行目录:{dir}";
@@ -154,6 +154,11 @@ export const CHANNEL_PHRASES = {
154
154
  zh: "启动一个后台进程,它在沙箱外持续运行,直到自行退出或被停止。",
155
155
  en: "Starts a background process that keeps running outside the sandbox until it exits or is stopped.",
156
156
  },
157
+ /** An approval card's line about the file the call takes (`{name}`, `{size}`, `{sha}`: 12 hex). */
158
+ approvalFile: {
159
+ zh: "文件:{name}({size},sha256 {sha})",
160
+ en: "File: {name} ({size}, sha256 {sha})",
161
+ },
157
162
  /** An escalation card's working directory line (`{dir}`). */
158
163
  escalationCwd: { zh: "运行目录:{dir}", en: "Runs in: {dir}" },
159
164
  /** An escalation card's justification line (`{text}`: the agent's words, quoted). */
@@ -165,6 +165,40 @@ export declare class AttachmentsService {
165
165
  contentType: string;
166
166
  size: number;
167
167
  }, purpose?: AttachmentPurpose): Promise<CreatedAttachment>;
168
+ /**
169
+ * The checks of registering an upload of `purpose` (type, size, the account's unfinished uploads
170
+ * of that purpose) and its expiry. `countStored`: uploads already stored but not yet used (ready,
171
+ * still expiring, bound to no agent) count as unfinished too ({@link createFromBytes}'s rows do
172
+ * not stay pending).
173
+ */
174
+ private admit;
175
+ /**
176
+ * Stores bytes the kernel already holds as an upload of `purpose`, as if a person had uploaded
177
+ * and finalized them (platform web parity spec §5: a `Platform` write takes a file in place of
178
+ * an upload), then the route's next step takes its id (the profile save, `POST /skills`). The
179
+ * checks, expiry and caps of {@link create} apply; no presigned URL is made. Intent first: the
180
+ * `pending` row is committed before the put (a failed put leaves it to expire and be cleaned
181
+ * up), then one update makes it `ready` with the stored size and etag. The type is not sniffed
182
+ * here: callers pass bytes they checked (the Platform tool sniffs a file reference).
183
+ */
184
+ createFromBytes(orgId: string, accountId: string, purpose: "agent-avatar" | "skill-package", file: {
185
+ name: string;
186
+ contentType: string;
187
+ bytes: Uint8Array;
188
+ }): Promise<{
189
+ id: string;
190
+ }>;
191
+ /**
192
+ * Gives up an upload {@link createFromBytes} stored when the write meant to take it failed: a
193
+ * `ready` upload of the account no agent uses becomes `deleting`, expiring now, so it no longer
194
+ * counts toward the cap and the cleanup job deletes it with its object. One already taken (a
195
+ * consumed skill package, an avatar bound to an agent) is left alone.
196
+ */
197
+ discardUpload(orgId: string, accountId: string, id: string): Promise<void>;
198
+ /** The last step of {@link createFromBytes}: the stored object's size and etag, `ready`. */
199
+ private markStored;
200
+ /** The `pending` row of {@link createFromBytes}, committed on its own before the put. */
201
+ private insertUploadIntent;
168
202
  /**
169
203
  * 上传完成后核对并标记为 `ready`(只有上传者能做;已 ready 时直接返回):
170
204
  * - 对象还不存在 → `attachment.not_ready`;