@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
@@ -1,6 +1,7 @@
1
1
  import { type OnModuleInit } from "@nestjs/common";
2
2
  import { ComponentScopeService } from "../../catalog/component-scope.service.js";
3
3
  import { PlatformComponents } from "../../catalog/platform-components.js";
4
+ import { KernelConfigService } from "../../infra/config/kernel-config.service.js";
4
5
  import { KernelDb } from "../../infra/database/kernel-db.js";
5
6
  import { PlatformOperations } from "../registry.js";
6
7
  /**
@@ -17,7 +18,8 @@ export declare class ComponentsOperations implements OnModuleInit {
17
18
  private readonly components;
18
19
  private readonly platformComponents;
19
20
  private readonly kdb;
20
- constructor(registry: PlatformOperations, components: ComponentScopeService, platformComponents: PlatformComponents, kdb: KernelDb);
21
+ private readonly config;
22
+ constructor(registry: PlatformOperations, components: ComponentScopeService, platformComponents: PlatformComponents, kdb: KernelDb, config: KernelConfigService);
21
23
  /** A component as a write returns it, with its orgs named (see {@link brief}). */
22
24
  private withOrgNames;
23
25
  /** Refuses a super-admin operation on a component another org owns (spec section 6.1). */
@@ -14,7 +14,9 @@ import { ComponentDisabledSchema, ComponentParams, ComponentScopeFields, Compone
14
14
  import { ComponentScopeService, } from "../../catalog/component-scope.service.js";
15
15
  import { PlatformComponents } from "../../catalog/platform-components.js";
16
16
  import { ApiError } from "../../errors.js";
17
+ import { KernelConfigService } from "../../infra/config/kernel-config.service.js";
17
18
  import { KernelDb } from "../../infra/database/kernel-db.js";
19
+ import { FileRefSchema } from "../file-ref.js";
18
20
  import { defineOperation } from "../operation.js";
19
21
  import { PlatformOperations } from "../registry.js";
20
22
  import { precheckBy, viaAgent } from "./errors.js";
@@ -130,11 +132,13 @@ let ComponentsOperations = class ComponentsOperations {
130
132
  components;
131
133
  platformComponents;
132
134
  kdb;
133
- constructor(registry, components, platformComponents, kdb) {
135
+ config;
136
+ constructor(registry, components, platformComponents, kdb, config) {
134
137
  this.registry = registry;
135
138
  this.components = components;
136
139
  this.platformComponents = platformComponents;
137
140
  this.kdb = kdb;
141
+ this.config = config;
138
142
  }
139
143
  /** A component as a write returns it, with its orgs named (see {@link brief}). */
140
144
  async withOrgNames(c) {
@@ -784,6 +788,60 @@ let ComponentsOperations = class ComponentsOperations {
784
788
  };
785
789
  },
786
790
  }),
791
+ defineOperation({
792
+ id: "plugins.update-skill",
793
+ description: "Publish a new version of a platform skill on its own (super admin): a skill package (zip) of this conversation, e.g. one you built in the sandbox and delivered with Deliver, passed as file: { fileId }. The package must keep the skill's name and is checked like an org skill upload; it serves in orgs at once and stays with its plugin. Takes the skill id from plugins.components with kind skill.",
794
+ input: z.object({ skillId: Id, file: FileRefSchema }).strict(),
795
+ example: { skillId: EXAMPLE_ID, file: { fileId: "0b9f2c4e-1d3a-4c55-9e0a-7a2f6d1c8b11" } },
796
+ authz: { superAdmin: true },
797
+ mirrors: ["POST /api/v1/admin/components/skill/:id/versions"],
798
+ renames: { skillId: "id" },
799
+ // the route's raw body
800
+ extras: ["file"],
801
+ confirm: "platform",
802
+ errors: [
803
+ {
804
+ code: "component.not_found",
805
+ next: "Check the skill id with plugins.components (kind skill).",
806
+ },
807
+ {
808
+ code: "validation_failed",
809
+ next: "The package must keep the skill's name: fix the name in SKILL.md, rebuild the zip and retry.",
810
+ },
811
+ {
812
+ code: "skill.invalid_package",
813
+ next: "Fix the package as the message says (SKILL.md at the zip's root with name and description frontmatter, allowed paths and sizes), rebuild the zip, deliver it and retry.",
814
+ },
815
+ {
816
+ code: "component.version_stale",
817
+ next: "The skill changed while this version was stored; call again.",
818
+ },
819
+ ],
820
+ precheck: (i, ctx) => precheckBy(() => this.assertNotOtherOrgs("skill", i.skillId, ctx.orgId)),
821
+ fileRef: (i) => ({
822
+ ref: i.file,
823
+ // the route takes the raw bytes whatever their type; the package reader checks them
824
+ limits: { maxBytes: this.config.get().packages.maxBytes },
825
+ }),
826
+ summary: async (i, ctx) => {
827
+ const n = await this.adminName("skill", i.skillId);
828
+ const f = named(ctx.file?.name ?? "?");
829
+ return {
830
+ zh: `用技能包「${f}」发布平台技能「${n}」的新版本`,
831
+ en: `Publish a new version of platform skill "${n}" from the package "${f}"`,
832
+ };
833
+ },
834
+ run: async (i, ctx) => {
835
+ const f = ctx.file;
836
+ if (f === undefined)
837
+ throw new Error("plugins.update-skill: the file is missing");
838
+ await this.assertNotOtherOrgs("skill", i.skillId, ctx.orgId);
839
+ return this.platformComponents.uploadSkillVersion({
840
+ accountId: ctx.actorAccountId,
841
+ auditDetail: viaAgent("plugins.update-skill", ctx),
842
+ }, i.skillId, f.bytes);
843
+ },
844
+ }),
787
845
  defineOperation({
788
846
  id: "plugins.update-agent-template",
789
847
  description: "Publish a new version of a platform agent template on its own (super admin): content is the template markdown file, which must keep the template's name. It serves in orgs at once. Takes the template id from plugins.components with kind agent_template.",
@@ -849,6 +907,7 @@ ComponentsOperations = __decorate([
849
907
  __param(0, Inject(PlatformOperations)),
850
908
  __param(1, Inject(ComponentScopeService)),
851
909
  __param(2, Inject(PlatformComponents)),
852
- __param(3, Inject(KernelDb))
910
+ __param(3, Inject(KernelDb)),
911
+ __param(4, Inject(KernelConfigService))
853
912
  ], ComponentsOperations);
854
913
  export { ComponentsOperations };
@@ -318,6 +318,20 @@ let ConnectorsOperations = class ConnectorsOperations {
318
318
  const r = await this.connectors.refresh(ctx.orgId, input.connectorId, ctx.actorAccountId, undefined, { auditDetail: viaAgent("connectors.refresh", ctx) });
319
319
  return { connector: detail(r.connector), issues: r.issues, changes: r.changes };
320
320
  },
321
+ handoff: (input, result) => {
322
+ const c = result
323
+ ?.changes;
324
+ if ((c?.added?.length ?? 0) + (c?.changed?.length ?? 0) === 0)
325
+ return null;
326
+ return {
327
+ kind: "handoff",
328
+ title: {
329
+ zh: "审阅连接器新增或变更的工具",
330
+ en: "Review the connector's new or changed tools",
331
+ },
332
+ target: { type: "link", url: `/connectors/${encodeURIComponent(input.connectorId)}` },
333
+ };
334
+ },
321
335
  }),
322
336
  defineOperation({
323
337
  id: "connectors.set-git-push-policy",
@@ -515,7 +529,7 @@ let ConnectorsOperations = class ConnectorsOperations {
515
529
  }),
516
530
  defineOperation({
517
531
  id: "connectors.set-org-credential",
518
- description: "Replace the org's credential of an org-credential connector (org admins): the person enters it on the confirmation card (bearer and api_key: credential.token; basic: credential.username and credential.password). For an OAuth connector it replaces the OAuth client: pass its id in client, the person enters client.clientSecret. Every field of the credential is asked. Custom header credentials are entered on the web.",
532
+ description: "Replace the org's credential of an org-credential connector (org admins): the person enters it on the confirmation card (bearer and api_key: credential.token; basic: credential.username and credential.password). For an OAuth connector it replaces the OAuth client: pass its id in client, the person enters client.clientSecret. Every field of the credential is asked. Custom header credentials are entered by a person in the connector's settings in the web app.",
519
533
  input: z
520
534
  .object({
521
535
  connectorId: ConnectorId,
@@ -156,7 +156,12 @@ let DevicesOperations = class DevicesOperations {
156
156
  ],
157
157
  run: async (input, ctx) => {
158
158
  const e = await this.devices.get(ctx.orgId, ctx.actorAccountId, input.deviceId);
159
- return { device: { ...e, name: labelOf(e), ...stateOf(e) } };
159
+ // the model sees who changed a setting by name only, never their avatar (spec §3)
160
+ const sandbox = {
161
+ ...e.sandbox,
162
+ recent: e.sandbox.recent.map((c) => ({ ...c, by: c.by?.name ?? null })),
163
+ };
164
+ return { device: { ...e, name: labelOf(e), ...stateOf(e), sandbox } };
160
165
  },
161
166
  }),
162
167
  defineOperation({
@@ -3,6 +3,7 @@ import { CatalogService } from "../../catalog/catalog.service.js";
3
3
  import { ExtensionAdminOps } from "../../extensions/admin-ops.js";
4
4
  import { ExtensionAdmin } from "../../extensions/admin-view.js";
5
5
  import { type DeploymentConfigView, ExtensionDeploymentConfigService } from "../../extensions/deployment-config.js";
6
+ import { ExtensionInstalls } from "../../extensions/installs.js";
6
7
  import { KernelConfigService } from "../../infra/config/kernel-config.service.js";
7
8
  import { KernelDb } from "../../infra/database/kernel-db.js";
8
9
  import { type PersonFieldTarget } from "../person-fields.js";
@@ -18,9 +19,9 @@ import { PlatformOperations } from "../registry.js";
18
19
  export declare function deploymentPersonFields(v: DeploymentConfigView, named?: readonly string[], values?: Readonly<Record<string, unknown>>): PersonFieldTarget;
19
20
  /**
20
21
  * The super admin's extension operations of the `Platform` tool (spec §14.2 "admin console",
21
- * §14.5 item 1): the deployment's extensions (list, read), enable, disable and uninstall. Installing
22
- * a package (upload, npm) and approving permissions stay on the web: a person reviews the
23
- * permissions there. The deployment config is read (secrets as set or not) and written here, its
22
+ * §14.5 item 1): the deployment's extensions (list, read), enable, disable and uninstall, and
23
+ * storing an uploaded package (its review). Installing a package and approving permissions stay on
24
+ * the web: a person reviews the permissions there. The deployment config is read (secrets as set or not) and written here, its
24
25
  * secrets entered by the person on the confirmation card (platform web parity spec §4).
25
26
  */
26
27
  export declare class ExtensionsAdminOperations implements OnModuleInit {
@@ -31,7 +32,8 @@ export declare class ExtensionsAdminOperations implements OnModuleInit {
31
32
  private readonly kdb;
32
33
  private readonly catalog;
33
34
  private readonly deploymentConfigs;
34
- constructor(registry: PlatformOperations, admin: ExtensionAdmin, ops: ExtensionAdminOps, config: KernelConfigService, kdb: KernelDb, catalog: CatalogService, deploymentConfigs: ExtensionDeploymentConfigService);
35
+ private readonly installs;
36
+ constructor(registry: PlatformOperations, admin: ExtensionAdmin, ops: ExtensionAdminOps, config: KernelConfigService, kdb: KernelDb, catalog: CatalogService, deploymentConfigs: ExtensionDeploymentConfigService, installs: ExtensionInstalls);
35
37
  /** The view of `name` for a precheck, or the refusal (unknown, startup-declared). */
36
38
  private viewFor;
37
39
  onModuleInit(): void;
@@ -15,10 +15,12 @@ import { ApiError } from "../../errors.js";
15
15
  import { ExtensionAdminOps } from "../../extensions/admin-ops.js";
16
16
  import { ExtensionAdmin } from "../../extensions/admin-view.js";
17
17
  import { ExtensionDeploymentConfigService, } from "../../extensions/deployment-config.js";
18
+ import { ExtensionInstalls } from "../../extensions/installs.js";
18
19
  import { SINGLE_PROVIDER_ENABLED, SINGLE_PROVIDER_REQUIRED, singleProviderMessage, } from "../../extensions/single-provider.js";
19
20
  import { unavailableReason } from "../../extensions/unavailable.js";
20
21
  import { KernelConfigService } from "../../infra/config/kernel-config.service.js";
21
22
  import { KernelDb } from "../../infra/database/kernel-db.js";
23
+ import { FileRefSchema } from "../file-ref.js";
22
24
  import { defineOperation } from "../operation.js";
23
25
  import { pathsTouched, personFieldParams, secretFieldsOf, } from "../person-fields.js";
24
26
  import { PlatformOperations } from "../registry.js";
@@ -26,7 +28,7 @@ import { precheckBy, viaAgent } from "./errors.js";
26
28
  import { assertExtensionNotOtherOrgs, OTHER_ORG, otherOrgExtensions } from "./other-orgs.js";
27
29
  import { Cursor, pageOf, startOf } from "./paging.js";
28
30
  import { configChanges, flatValues, withPersonInputs } from "./person-inputs.js";
29
- import { localized } from "./summary.js";
31
+ import { localized, named } from "./summary.js";
30
32
  import { unavailableFields } from "./unavailable.js";
31
33
  /** An extension's name (`:name` of the admin routes), bounded like the org routes' `:extension`. */
32
34
  const Name = AdminExtensionNamePathParams.shape.name.max(64);
@@ -127,9 +129,9 @@ const pendingPlugin = (i) => ({
127
129
  });
128
130
  /**
129
131
  * The super admin's extension operations of the `Platform` tool (spec §14.2 "admin console",
130
- * §14.5 item 1): the deployment's extensions (list, read), enable, disable and uninstall. Installing
131
- * a package (upload, npm) and approving permissions stay on the web: a person reviews the
132
- * permissions there. The deployment config is read (secrets as set or not) and written here, its
132
+ * §14.5 item 1): the deployment's extensions (list, read), enable, disable and uninstall, and
133
+ * storing an uploaded package (its review). Installing a package and approving permissions stay on
134
+ * the web: a person reviews the permissions there. The deployment config is read (secrets as set or not) and written here, its
133
135
  * secrets entered by the person on the confirmation card (platform web parity spec §4).
134
136
  */
135
137
  let ExtensionsAdminOperations = class ExtensionsAdminOperations {
@@ -140,7 +142,8 @@ let ExtensionsAdminOperations = class ExtensionsAdminOperations {
140
142
  kdb;
141
143
  catalog;
142
144
  deploymentConfigs;
143
- constructor(registry, admin, ops, config, kdb, catalog, deploymentConfigs) {
145
+ installs;
146
+ constructor(registry, admin, ops, config, kdb, catalog, deploymentConfigs, installs) {
144
147
  this.registry = registry;
145
148
  this.admin = admin;
146
149
  this.ops = ops;
@@ -148,6 +151,7 @@ let ExtensionsAdminOperations = class ExtensionsAdminOperations {
148
151
  this.kdb = kdb;
149
152
  this.catalog = catalog;
150
153
  this.deploymentConfigs = deploymentConfigs;
154
+ this.installs = installs;
151
155
  }
152
156
  /** The view of `name` for a precheck, or the refusal (unknown, startup-declared). */
153
157
  async viewFor(name, orgId) {
@@ -214,6 +218,91 @@ let ExtensionsAdminOperations = class ExtensionsAdminOperations {
214
218
  otherOrgExtensions: waiting.length - exts.length,
215
219
  };
216
220
  },
221
+ handoff: (_i, result) => {
222
+ const r = result;
223
+ const rows = r?.items;
224
+ if (rows === undefined || rows.length === 0)
225
+ return null;
226
+ // the one extension's page only when the whole waiting set is that extension
227
+ const onlyExtension = r?.total === 1 && rows.length === 1 && rows[0]?.kind === "extension";
228
+ const id = rows[0]?.id;
229
+ return {
230
+ kind: "handoff",
231
+ title: {
232
+ zh: "审阅待确认的权限",
233
+ en: "Review the permissions waiting for confirmation",
234
+ },
235
+ target: {
236
+ type: "link",
237
+ url: onlyExtension && typeof id === "string"
238
+ ? `/admin/extensions/${encodeURIComponent(id)}`
239
+ : "/admin/plugins/pending",
240
+ },
241
+ };
242
+ },
243
+ }),
244
+ defineOperation({
245
+ id: "extensions.upload-package",
246
+ description: "Store an extension package in the deployment's package store (super admin): a .tgz extension package of this conversation, e.g. one you packed in the sandbox and delivered with Deliver, passed as file: { fileId }; at most the deployment's package limit. Returns its review: name, version, sha256, the permissions it asks for and those added or removed against the approved ones, migration warnings. Nothing is installed or run. No web page shows a stored package: the person installs the stored package with the super admin API (`POST /api/v1/admin/extensions/:name/install` with `{ sha256 }` from the review), or with the capybara CLI (`capybara extensions install <file.tgz>`, which shows the permission review and asks them to confirm) after downloading the .tgz from this conversation.",
247
+ input: z.object({ file: FileRefSchema }).strict(),
248
+ example: { file: { fileId: "0b9f2c4e-1d3a-4c55-9e0a-7a2f6d1c8b11" } },
249
+ authz: { superAdmin: true },
250
+ mirrors: ["POST /api/v1/admin/extensions/packages/file"],
251
+ // the route's raw body
252
+ extras: ["file"],
253
+ confirm: "platform",
254
+ errors: [
255
+ {
256
+ code: "extension.package_invalid",
257
+ next: "The package is not a valid extension package (the details list each problem); fix it, pack and deliver it again.",
258
+ },
259
+ {
260
+ code: "extension.package_too_large",
261
+ next: "The package is over the deployment's package limit; make it smaller.",
262
+ },
263
+ {
264
+ code: "extension.config_declared",
265
+ next: "An extension of this name is declared in the startup config; tell the person, who removes it there first.",
266
+ },
267
+ {
268
+ code: "extension.name_conflict",
269
+ next: "An extension of this name is installed from another npm package; check the package name.",
270
+ },
271
+ ],
272
+ fileRef: (i) => ({
273
+ ref: i.file,
274
+ // the route takes the raw bytes whatever their type (a delivered .tgz is
275
+ // application/octet-stream); the package reader checks them
276
+ limits: { maxBytes: this.config.get().packages.maxBytes },
277
+ }),
278
+ summary: (_i, ctx) => {
279
+ const f = named(ctx.file?.name ?? "?");
280
+ return {
281
+ zh: `把扩展包「${f}」存入平台的包存储(尚未安装)`,
282
+ en: `Store the extension package "${f}" in the platform's package store (nothing is installed yet)`,
283
+ };
284
+ },
285
+ run: async (_input, ctx) => {
286
+ const f = ctx.file;
287
+ if (f === undefined)
288
+ throw new Error("extensions.upload-package: the file is missing");
289
+ const r = await this.installs.ingestFile(ctx.actorAccountId, f.bytes, {
290
+ auditDetail: viaAgent("extensions.upload-package", ctx),
291
+ });
292
+ return {
293
+ review: {
294
+ name: r.name,
295
+ version: r.version,
296
+ sha256: r.sha256,
297
+ permissions: r.permissions,
298
+ addedPermissions: r.added,
299
+ removedPermissions: r.removed,
300
+ warnings: r.warnings,
301
+ },
302
+ next: `Nothing is installed yet; the web has no page for a stored package. Tell the person to install it with the super admin API: POST /api/v1/admin/extensions/${r.name}/install with { "sha256": "${r.sha256}" }; or with \`capybara extensions install <file.tgz>\` (it shows the permission review and asks for confirmation) after downloading the .tgz from this conversation.`,
303
+ };
304
+ },
305
+ noHandoff: "No web page shows a stored package; the person installs it and confirms its permissions with the super admin API or the capybara CLI.",
217
306
  }),
218
307
  defineOperation({
219
308
  id: "extensions.platform-get",
@@ -293,6 +382,19 @@ let ExtensionsAdminOperations = class ExtensionsAdminOperations {
293
382
  next: "Replicas load it in the background; check its state with extensions.platform-get.",
294
383
  };
295
384
  },
385
+ handoff: (input, result) => {
386
+ const state = result?.extension?.state;
387
+ if (state !== "pending_approval")
388
+ return null;
389
+ return {
390
+ kind: "handoff",
391
+ title: {
392
+ zh: "审阅并确认扩展的权限",
393
+ en: "Review and confirm the extension's permissions",
394
+ },
395
+ target: { type: "link", url: `/admin/extensions/${encodeURIComponent(input.name)}` },
396
+ };
397
+ },
296
398
  }),
297
399
  defineOperation({
298
400
  id: "extensions.platform-disable",
@@ -515,6 +617,7 @@ ExtensionsAdminOperations = __decorate([
515
617
  __param(3, Inject(KernelConfigService)),
516
618
  __param(4, Inject(KernelDb)),
517
619
  __param(5, Inject(CatalogService)),
518
- __param(6, Inject(ExtensionDeploymentConfigService))
620
+ __param(6, Inject(ExtensionDeploymentConfigService)),
621
+ __param(7, Inject(ExtensionInstalls))
519
622
  ], ExtensionsAdminOperations);
520
623
  export { ExtensionsAdminOperations };
@@ -17,6 +17,7 @@ import { roleAtLeast } from "../../orgs/roles.js";
17
17
  import { defineOperation } from "../operation.js";
18
18
  import { PlatformOperations } from "../registry.js";
19
19
  import { approvalRow } from "./approvals.ops.js";
20
+ import { listCard } from "./list-handoff.js";
20
21
  import { Cursor, pageOf, startOf } from "./paging.js";
21
22
  import { named, orElse } from "./summary.js";
22
23
  const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
@@ -283,6 +284,10 @@ let InboxOperations = class InboxOperations {
283
284
  truncated: view.truncated,
284
285
  };
285
286
  },
287
+ handoff: (_i, result) => listCard(result, "/inbox", {
288
+ zh: "打开收件箱处理待办",
289
+ en: "Open the inbox to decide what waits",
290
+ }),
286
291
  }),
287
292
  defineOperation({
288
293
  id: "inbox.dismiss-notice",
@@ -314,6 +319,7 @@ let InboxOperations = class InboxOperations {
314
319
  await this.inbox.dismissNotice(ctx.orgId, ctx.actorAccountId, input.id);
315
320
  return { dismissed: input.id };
316
321
  },
322
+ noHandoff: "A dismissal: nothing waits for the person afterwards, the sentence only says where approvals are decided.",
317
323
  }),
318
324
  defineOperation({
319
325
  id: "inbox.platform-list",
@@ -355,6 +361,10 @@ let InboxOperations = class InboxOperations {
355
361
  otherOrgItems: view.items.length - shown.length,
356
362
  };
357
363
  },
364
+ handoff: (_i, result) => listCard(result, "/admin/inbox", {
365
+ zh: "打开平台收件箱处理待办",
366
+ en: "Open the platform inbox to decide what waits",
367
+ }),
358
368
  }),
359
369
  defineOperation({
360
370
  id: "inbox.platform-dismiss-notice",
@@ -0,0 +1,10 @@
1
+ import type { HandoffView } from "../operation.js";
2
+ /**
3
+ * The link card of a list that holds what a person decides on the web (platform web parity spec
4
+ * §6): the page where it is decided, shown when the list is not empty. `result` is a `pageOf`
5
+ * page; an empty one gets no card.
6
+ */
7
+ export declare const listCard: (result: unknown, url: string, title: {
8
+ zh: string;
9
+ en: string;
10
+ }) => HandoffView | null;
@@ -0,0 +1,11 @@
1
+ /**
2
+ * The link card of a list that holds what a person decides on the web (platform web parity spec
3
+ * §6): the page where it is decided, shown when the list is not empty. `result` is a `pageOf`
4
+ * page; an empty one gets no card.
5
+ */
6
+ export const listCard = (result, url, title) => {
7
+ const items = result?.items;
8
+ if (!Array.isArray(items) || items.length === 0)
9
+ return null;
10
+ return { kind: "handoff", title, target: { type: "link", url } };
11
+ };
@@ -18,7 +18,7 @@ import { readOrgMarketplaceBrowse } from "../../identity/settings.js";
18
18
  import { KernelDb } from "../../infra/database/kernel-db.js";
19
19
  import { defineOperation } from "../operation.js";
20
20
  import { PlatformOperations } from "../registry.js";
21
- import { CONFIRM_ON_WEB, reviewBrief, reviewUrl } from "./catalog-admin.ops.js";
21
+ import { CONFIRM_ON_WEB, importHandoff, reviewBrief, reviewUrl } from "./catalog-admin.ops.js";
22
22
  import { viaAgent } from "./errors.js";
23
23
  import { Cursor, pageOf, startOf } from "./paging.js";
24
24
  const PAGE = 50;
@@ -452,6 +452,7 @@ let MarketplacesOperations = class MarketplacesOperations {
452
452
  next: CONFIRM_ON_WEB,
453
453
  };
454
454
  },
455
+ handoff: (_i, result) => importHandoff(result),
455
456
  }),
456
457
  ]);
457
458
  }
@@ -6,14 +6,22 @@ import { OrgPluginUploads } from "../../catalog/org-plugin-uploads.js";
6
6
  import { OwnedItems } from "../../catalog/owned-items.js";
7
7
  import { PluginInstaller } from "../../catalog/plugin-install.js";
8
8
  import { OrgExtensionConfigs } from "../../extensions/org-config.js";
9
+ import { KernelConfigService } from "../../infra/config/kernel-config.service.js";
9
10
  import { KernelDb } from "../../infra/database/kernel-db.js";
10
11
  import { ThemesService } from "../../themes/themes.service.js";
12
+ import { type HandoffView } from "../operation.js";
11
13
  import { PlatformOperations } from "../registry.js";
14
+ /**
15
+ * The link card to the org's Plugins page with a staged upload (`plugins.upload`,
16
+ * `plugins.upload-review`); without the plugin's name the title names none.
17
+ */
18
+ export declare const uploadHandoff: (result: unknown) => HandoffView | null;
12
19
  /**
13
20
  * The org's own plugin operations of the `Platform` tool (spec §14.2): the org's plugin installs
14
21
  * (list, uninstall; installing with inputs and creating missing connectors, their secrets entered
15
- * by the person on the card, platform web parity spec §7.2), its staged uploads (read; uploading is a byte transport and confirming is done
16
- * by a person on the web), and the plugins it owns (share, delete after a preview, withdraw a
22
+ * by the person on the card, platform web parity spec §7.2), its staged uploads (staging a package
23
+ * of the conversation, reading one; confirming is done by a person on the web), and the plugins it
24
+ * owns (share, delete after a preview, withdraw a
17
25
  * pending upload). Org admins; the services re-check the role under the org lock.
18
26
  */
19
27
  export declare class OrgPluginsOperations implements OnModuleInit {
@@ -27,7 +35,8 @@ export declare class OrgPluginsOperations implements OnModuleInit {
27
35
  private readonly appearance;
28
36
  private readonly themes;
29
37
  private readonly extensions;
30
- constructor(registry: PlatformOperations, installer: PluginInstaller, orgCatalog: OrgCatalogService, uploads: OrgPluginUploads, owned: OwnedItems, scope: CatalogScopeService, kdb: KernelDb, appearance: AppearanceService, themes: ThemesService, extensions: OrgExtensionConfigs);
38
+ private readonly config;
39
+ constructor(registry: PlatformOperations, installer: PluginInstaller, orgCatalog: OrgCatalogService, uploads: OrgPluginUploads, owned: OwnedItems, scope: CatalogScopeService, kdb: KernelDb, appearance: AppearanceService, themes: ThemesService, extensions: OrgExtensionConfigs, config: KernelConfigService);
31
40
  /**
32
41
  * What installing a plugin asks the person for (platform web parity spec §7.2): the connector
33
42
  * templates whose connector the install creates (on in the org, none kept from an earlier
@@ -20,10 +20,12 @@ import { OwnedItems } from "../../catalog/owned-items.js";
20
20
  import { PluginInstaller } from "../../catalog/plugin-install.js";
21
21
  import { ApiError } from "../../errors.js";
22
22
  import { OrgExtensionConfigs } from "../../extensions/org-config.js";
23
+ import { KernelConfigService } from "../../infra/config/kernel-config.service.js";
23
24
  import { KernelDb } from "../../infra/database/kernel-db.js";
24
25
  import { ThemesService } from "../../themes/themes.service.js";
25
26
  import { clientProblem, headersWebOnly, templateConnectorInput, templatePersonFields, } from "../connector-person-fields.js";
26
- import { defineOperation } from "../operation.js";
27
+ import { FileRefSchema } from "../file-ref.js";
28
+ import { defineOperation, } from "../operation.js";
27
29
  import { PersonFieldsRefused, personFieldParams, planPersonFields, secretFieldsOf, } from "../person-fields.js";
28
30
  import { PlatformOperations } from "../registry.js";
29
31
  import { appearanceSummary, reviewBrief } from "./catalog-admin.ops.js";
@@ -127,11 +129,29 @@ const installRow = (i) => ({
127
129
  version: i.version,
128
130
  components: i.components.length,
129
131
  });
132
+ /**
133
+ * The link card to the org's Plugins page with a staged upload (`plugins.upload`,
134
+ * `plugins.upload-review`); without the plugin's name the title names none.
135
+ */
136
+ export const uploadHandoff = (result) => {
137
+ const r = result;
138
+ if (typeof r?.stagingId !== "string")
139
+ return null;
140
+ const name = typeof r.review?.name === "string" ? named(r.review.name) : null;
141
+ return {
142
+ kind: "handoff",
143
+ title: name === null
144
+ ? { zh: "确认插件的上传", en: "Confirm the plugin upload" }
145
+ : { zh: `确认插件 ${name} 的上传`, en: `Confirm the upload of plugin ${name}` },
146
+ target: { type: "link", url: `/plugins?staging=${encodeURIComponent(r.stagingId)}` },
147
+ };
148
+ };
130
149
  /**
131
150
  * The org's own plugin operations of the `Platform` tool (spec §14.2): the org's plugin installs
132
151
  * (list, uninstall; installing with inputs and creating missing connectors, their secrets entered
133
- * by the person on the card, platform web parity spec §7.2), its staged uploads (read; uploading is a byte transport and confirming is done
134
- * by a person on the web), and the plugins it owns (share, delete after a preview, withdraw a
152
+ * by the person on the card, platform web parity spec §7.2), its staged uploads (staging a package
153
+ * of the conversation, reading one; confirming is done by a person on the web), and the plugins it
154
+ * owns (share, delete after a preview, withdraw a
135
155
  * pending upload). Org admins; the services re-check the role under the org lock.
136
156
  */
137
157
  let OrgPluginsOperations = class OrgPluginsOperations {
@@ -145,7 +165,8 @@ let OrgPluginsOperations = class OrgPluginsOperations {
145
165
  appearance;
146
166
  themes;
147
167
  extensions;
148
- constructor(registry, installer, orgCatalog, uploads, owned, scope, kdb, appearance, themes, extensions) {
168
+ config;
169
+ constructor(registry, installer, orgCatalog, uploads, owned, scope, kdb, appearance, themes, extensions, config) {
149
170
  this.registry = registry;
150
171
  this.installer = installer;
151
172
  this.orgCatalog = orgCatalog;
@@ -156,6 +177,7 @@ let OrgPluginsOperations = class OrgPluginsOperations {
156
177
  this.appearance = appearance;
157
178
  this.themes = themes;
158
179
  this.extensions = extensions;
180
+ this.config = config;
159
181
  }
160
182
  /**
161
183
  * What installing a plugin asks the person for (platform web parity spec §7.2): the connector
@@ -286,9 +308,76 @@ let OrgPluginsOperations = class OrgPluginsOperations {
286
308
  },
287
309
  run: async (input, ctx) => this.orgCatalog.uninstall(ctx.orgId, ctx.actorAccountId, input.installId, undefined, viaAgent("plugins.uninstall", ctx)),
288
310
  }),
311
+ defineOperation({
312
+ id: "plugins.upload",
313
+ description: "Stage a plugin package as this org's own upload (org admins): a .tgz plugin package of this conversation, e.g. one you packed in the sandbox and delivered with Deliver, passed as file: { fileId }; at most the deployment's package limit. Checks the whole plugin and stages it for 24 hours; returns what it brings and, for a new version of the org's own plugin, the update it applies. Nothing is added until the person confirms the upload on the web (Plugins page); a plugin with an extension then waits for the super admin.",
314
+ input: z.object({ file: FileRefSchema }).strict(),
315
+ example: { file: { fileId: EXAMPLE_ID } },
316
+ authz: { orgAction: "catalog.upload" },
317
+ mirrors: ["POST /api/v1/orgs/:orgId/catalog/uploads/file"],
318
+ // the route's raw body
319
+ extras: ["file"],
320
+ confirm: "org",
321
+ errors: [
322
+ {
323
+ code: "catalog.invalid_manifest",
324
+ next: "The package is not a valid plugin (the details list each problem); fix it, pack and deliver it again.",
325
+ },
326
+ {
327
+ code: "catalog.custom_disabled",
328
+ next: "This deployment does not allow the org's own skills, agent templates or connector templates that the plugin brings; tell the person.",
329
+ },
330
+ {
331
+ code: "plugin.name_taken",
332
+ next: "Another owner has a live plugin of this name; rename the plugin in its manifest, pack it and retry.",
333
+ },
334
+ {
335
+ code: "plugin.dependency_unavailable",
336
+ next: "The plugin depends on plugins this org cannot use (the details list them); install those first, or remove the dependency.",
337
+ },
338
+ {
339
+ code: "catalog.version_exists",
340
+ next: "This version was uploaded already; raise the version in the manifest, pack it and retry.",
341
+ },
342
+ ],
343
+ fileRef: (i) => ({
344
+ ref: i.file,
345
+ // the route takes the raw bytes whatever their type (a delivered .tgz is
346
+ // application/octet-stream); the package reader checks them
347
+ limits: { maxBytes: this.config.get().packages.maxBytes },
348
+ }),
349
+ summary: (_i, ctx) => {
350
+ const f = named(ctx.file?.name ?? "?");
351
+ return {
352
+ zh: `暂存插件包「${f}」作为本组织的上传(确认在网页上进行)`,
353
+ en: `Stage the plugin package "${f}" as this org's upload (confirmed on the web)`,
354
+ };
355
+ },
356
+ run: async (_input, ctx) => {
357
+ const f = ctx.file;
358
+ if (f === undefined)
359
+ throw new Error("plugins.upload: the file is missing");
360
+ const r = await this.uploads.prepare(ctx.actorAccountId, ctx.orgId, f.bytes, {
361
+ auditDetail: viaAgent("plugins.upload", ctx),
362
+ });
363
+ return {
364
+ stagingId: r.stagingId,
365
+ review: reviewBrief(r.review),
366
+ update: r.update === null
367
+ ? null
368
+ : {
369
+ from: r.update.from,
370
+ to: r.update.to,
371
+ components: r.update.components.filter((c) => c.change !== "same").length,
372
+ },
373
+ next: "Nothing is added yet: the person confirms the upload on the web (Plugins page).",
374
+ };
375
+ },
376
+ handoff: (_i, result) => uploadHandoff(result),
377
+ }),
289
378
  defineOperation({
290
379
  id: "plugins.upload-review",
291
- description: "Read one of this org's staged plugin uploads (org admins): what the plugin brings, and for a new version of the org's own plugin the update it applies. Uploading the package and confirming it are done by a person on the web (Plugins page).",
380
+ description: "Read one of this org's staged plugin uploads (org admins): what the plugin brings, and for a new version of the org's own plugin the update it applies. plugins.upload stages one; confirming it is done by a person on the web (Plugins page).",
292
381
  input: z.object({ stagingId: OrgUploadStagingParams.shape.stagingId }).strict(),
293
382
  example: { stagingId: EXAMPLE_ID },
294
383
  authz: { orgAction: "catalog.upload" },
@@ -315,6 +404,7 @@ let OrgPluginsOperations = class OrgPluginsOperations {
315
404
  next: "The person confirms the upload on the web (Plugins page).",
316
405
  };
317
406
  },
407
+ handoff: (_i, result) => uploadHandoff(result),
318
408
  }),
319
409
  defineOperation({
320
410
  id: "plugins.set-shareable",
@@ -702,6 +792,7 @@ OrgPluginsOperations = __decorate([
702
792
  __param(6, Inject(KernelDb)),
703
793
  __param(7, Inject(AppearanceService)),
704
794
  __param(8, Inject(ThemesService)),
705
- __param(9, Inject(OrgExtensionConfigs))
795
+ __param(9, Inject(OrgExtensionConfigs)),
796
+ __param(10, Inject(KernelConfigService))
706
797
  ], OrgPluginsOperations);
707
798
  export { OrgPluginsOperations };