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

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 (126) hide show
  1. package/dist/admin/extensions.controller.d.ts +2 -10
  2. package/dist/admin/extensions.controller.js +2 -24
  3. package/dist/admin/extensions.schemas.d.ts +21 -0
  4. package/dist/admin/extensions.schemas.js +37 -0
  5. package/dist/catalog/marketplaces.service.d.ts +1 -1
  6. package/dist/catalog/org-catalog.controller.d.ts +0 -5
  7. package/dist/catalog/org-catalog.controller.js +3 -17
  8. package/dist/catalog/org-catalog.schemas.d.ts +43 -0
  9. package/dist/catalog/org-catalog.schemas.js +43 -2
  10. package/dist/catalog/org-extension-switch.d.ts +3 -1
  11. package/dist/catalog/org-extension-switch.js +12 -5
  12. package/dist/catalog/org-extension.controller.d.ts +2 -21
  13. package/dist/catalog/org-extension.controller.js +1 -38
  14. package/dist/catalog/org-extension.schemas.d.ts +31 -0
  15. package/dist/catalog/org-extension.schemas.js +65 -0
  16. package/dist/catalog/plugin-install.d.ts +2 -0
  17. package/dist/catalog/plugin-install.js +3 -3
  18. package/dist/channels/actions.js +2 -0
  19. package/dist/channels/cards.d.ts +8 -0
  20. package/dist/channels/cards.js +18 -0
  21. package/dist/channels/channels.schemas.d.ts +3 -0
  22. package/dist/channels/channels.schemas.js +8 -0
  23. package/dist/channels/connections.service.d.ts +17 -2
  24. package/dist/channels/connections.service.js +30 -5
  25. package/dist/channels/outbound.js +25 -1
  26. package/dist/channels/phrases.d.ts +10 -0
  27. package/dist/channels/phrases.js +10 -0
  28. package/dist/conversations/conversations.module.js +4 -0
  29. package/dist/conversations/events.d.ts +35 -0
  30. package/dist/conversations/events.js +29 -0
  31. package/dist/conversations/leak-check.d.ts +26 -0
  32. package/dist/conversations/leak-check.js +69 -0
  33. package/dist/ctx/secrets.d.ts +13 -1
  34. package/dist/ctx/secrets.js +19 -1
  35. package/dist/db/kernel-schema.d.ts +34 -0
  36. package/dist/devices/working-root.d.ts +2 -3
  37. package/dist/errors.d.ts +19 -0
  38. package/dist/errors.js +19 -0
  39. package/dist/extensions/deployment-config.d.ts +6 -2
  40. package/dist/extensions/deployment-config.js +35 -23
  41. package/dist/extensions/org-config.d.ts +2 -0
  42. package/dist/extensions/org-config.js +1 -0
  43. package/dist/extensions/org-overrides.d.ts +2 -0
  44. package/dist/extensions/org-overrides.js +3 -2
  45. package/dist/http/api.module.js +6 -0
  46. package/dist/identity/initial-passwords.job.d.ts +3 -2
  47. package/dist/identity/initial-passwords.job.js +11 -5
  48. package/dist/orgs/invitations.controller.d.ts +3 -11
  49. package/dist/orgs/invitations.controller.js +9 -10
  50. package/dist/orgs/invitations.service.d.ts +12 -2
  51. package/dist/orgs/invitations.service.js +14 -7
  52. package/dist/orgs/members.service.d.ts +12 -2
  53. package/dist/orgs/members.service.js +10 -8
  54. package/dist/orgs/orgs.controller.d.ts +4 -12
  55. package/dist/orgs/orgs.controller.js +10 -10
  56. package/dist/orgs/orgs.schemas.d.ts +26 -0
  57. package/dist/orgs/orgs.schemas.js +22 -0
  58. package/dist/platform/connector-person-fields.d.ts +67 -0
  59. package/dist/platform/connector-person-fields.js +129 -0
  60. package/dist/platform/exclusions.js +6 -141
  61. package/dist/platform/method.js +1 -0
  62. package/dist/platform/operation.d.ts +61 -2
  63. package/dist/platform/operation.js +4 -4
  64. package/dist/platform/ops/accounts.ops.js +1 -0
  65. package/dist/platform/ops/channels.ops.d.ts +10 -3
  66. package/dist/platform/ops/channels.ops.js +223 -5
  67. package/dist/platform/ops/connectors.ops.d.ts +22 -4
  68. package/dist/platform/ops/connectors.ops.js +664 -13
  69. package/dist/platform/ops/extensions-admin.ops.d.ts +15 -2
  70. package/dist/platform/ops/extensions-admin.ops.js +153 -5
  71. package/dist/platform/ops/extensions.ops.d.ts +19 -5
  72. package/dist/platform/ops/extensions.ops.js +285 -10
  73. package/dist/platform/ops/org-plugins.ops.d.ts +15 -2
  74. package/dist/platform/ops/org-plugins.ops.js +323 -4
  75. package/dist/platform/ops/orgs.ops.d.ts +40 -3
  76. package/dist/platform/ops/orgs.ops.js +293 -12
  77. package/dist/platform/ops/person-inputs.d.ts +65 -0
  78. package/dist/platform/ops/person-inputs.js +129 -0
  79. package/dist/platform/ops/plugins.ops.d.ts +3 -1
  80. package/dist/platform/ops/plugins.ops.js +33 -20
  81. package/dist/platform/parity.d.ts +7 -2
  82. package/dist/platform/parity.js +75 -13
  83. package/dist/platform/person-fields.d.ts +119 -0
  84. package/dist/platform/person-fields.js +403 -0
  85. package/dist/platform/platform.module.d.ts +4 -3
  86. package/dist/platform/platform.module.js +8 -5
  87. package/dist/platform/route-schemas.js +2 -0
  88. package/dist/platform/sealed-inputs.d.ts +44 -0
  89. package/dist/platform/sealed-inputs.js +116 -0
  90. package/dist/platform/sealed-reveals.controller.d.ts +20 -0
  91. package/dist/platform/sealed-reveals.controller.js +48 -0
  92. package/dist/platform/sealed-reveals.d.ts +52 -0
  93. package/dist/platform/sealed-reveals.js +153 -0
  94. package/dist/runtime/project/knowledge.js +24 -19
  95. package/dist/runtime/waits.js +8 -2
  96. package/dist/sandbox/permission-facts.d.ts +5 -1
  97. package/dist/sandbox/permission-facts.js +8 -2
  98. package/dist/setup/setup-guides.service.d.ts +5 -0
  99. package/dist/setup/setup-guides.service.js +2 -1
  100. package/dist/tools/approvals.controller.d.ts +1 -0
  101. package/dist/tools/approvals.controller.js +19 -0
  102. package/dist/tools/approvals.service.d.ts +50 -1
  103. package/dist/tools/approvals.service.js +118 -10
  104. package/dist/tools/builtins/builtin-tools.d.ts +3 -0
  105. package/dist/tools/builtins/builtin-tools.js +31 -9
  106. package/dist/tools/builtins/platform.d.ts +20 -0
  107. package/dist/tools/builtins/platform.js +214 -15
  108. package/dist/tools/connectors.controller.d.ts +6 -7
  109. package/dist/tools/connectors.controller.js +4 -44
  110. package/dist/tools/connectors.schemas.d.ts +170 -1
  111. package/dist/tools/connectors.schemas.js +82 -3
  112. package/dist/tools/connectors.service.d.ts +16 -6
  113. package/dist/tools/connectors.service.js +39 -24
  114. package/dist/tools/oauth/oauth.controller.d.ts +3 -6
  115. package/dist/tools/oauth/oauth.controller.js +3 -12
  116. package/dist/tools/oauth/oauth.schemas.d.ts +14 -0
  117. package/dist/tools/oauth/oauth.schemas.js +27 -0
  118. package/dist/tools/pipeline.d.ts +31 -2
  119. package/dist/tools/pipeline.js +89 -17
  120. package/dist/tools/policy.d.ts +4 -0
  121. package/dist/tools/policy.js +8 -0
  122. package/dist/tools/registry.d.ts +29 -0
  123. package/dist/tools/tools.module.js +3 -0
  124. package/package.json +3 -3
  125. package/src/migrations/0169_platform_sealed_inputs.sql +23 -0
  126. package/src/migrations/0170_platform_sealed_reveals.sql +27 -0
@@ -1,6 +1,8 @@
1
1
  import type { z } from "zod";
2
+ import type { ToolView } from "../conversations/events.js";
2
3
  import type { OrgAction } from "../orgs/roles.js";
3
4
  import type { ErrorRole } from "./errors.js";
5
+ import type { PersonFieldTarget } from "./person-fields.js";
4
6
  /**
5
7
  * How an operation is confirmed (spec §6.2): `read` runs; `personal` asks each time and may be
6
8
  * remembered; `org` / `platform` ask each time and are never remembered.
@@ -33,6 +35,24 @@ export interface OperationContext {
33
35
  * then with `roleFor` in ./ops/unavailable.ts.
34
36
  */
35
37
  errorRole?: ErrorRole;
38
+ /**
39
+ * The values the person typed on the approval card for this call's secret fields (platform web
40
+ * parity spec §4.3): present only when the approved call asked for person fields. `paths` are the
41
+ * asked fields; `apply` consumes the sealed values once and runs `fn` with them in the same
42
+ * transaction (a throw puts them back), so the handler passes them to the route's service method
43
+ * inside `fn`. The values never go into the result: the tool appends a line per entered path.
44
+ * `apply` throws when the values expired; the tool returns the "expired" text then.
45
+ */
46
+ personInputs?: {
47
+ paths: readonly string[];
48
+ apply<T>(fn: (values: Readonly<Record<string, string>>) => Promise<T>): Promise<T>;
49
+ };
50
+ /**
51
+ * At confirmation time, for an operation with `personFields`: the paths the planned card asks
52
+ * the person for (`askPerson` plus the required secrets without a stored value), so `summary`
53
+ * names every field the card shows. Absent elsewhere.
54
+ */
55
+ personAsk?: readonly string[];
36
56
  }
37
57
  /**
38
58
  * The next step after an error: one text, or one per role where the step differs (spec §14.5
@@ -57,8 +77,9 @@ export interface OperationError {
57
77
  * Some codes exist only in the tool, never answered by a route: `marketplace.already_added` (the
58
78
  * `marketplaces.add` duplicate check is tool policy; the web accepts a duplicate source),
59
79
  * `plugin.needs_input` (input only a person enters on the web), `agent.visibility_web_only`,
60
- * `catalog.org_owned` (`plugins.set-shown` leaves an org's own plugin to that org), and
61
- * `account.self` / `account.no_change` (disabling your own account, a status that is set already).
80
+ * `catalog.org_owned` (`plugins.set-shown` leaves an org's own plugin to that org),
81
+ * `account.self` / `account.no_change` (disabling your own account, a status that is set already),
82
+ * and `platform.secret_record_web_only` (a secret record the card cannot ask for; ruling R1).
62
83
  */
63
84
  export type PrecheckResult = {
64
85
  ok: true;
@@ -68,6 +89,16 @@ export type PrecheckResult = {
68
89
  message: string;
69
90
  next?: OperationErrorNext;
70
91
  };
92
+ /**
93
+ * A link card the conversation pops up after an operation (platform web parity spec §4.4, §6): the
94
+ * write's decision stays with a person on a web page (an import review, an OAuth connect), and the
95
+ * card names what waits for them with one button. `link` opens a relative web path (the tool also
96
+ * puts it in the result text as `reviewUrl`); `connect` starts a connector's OAuth flow from the
97
+ * person's web session. Display only (`tool_result.view`): never model-visible.
98
+ */
99
+ export type HandoffView = Extract<ToolView, {
100
+ kind: "handoff";
101
+ }>;
71
102
  /** How long a precheck may take before the tool skips it (spec §14.2 item 2). */
72
103
  export declare const PRECHECK_TIMEOUT_MS = 2000;
73
104
  /** One operation of the `Platform` tool (spec §7), defined next to its domain. */
@@ -112,6 +143,13 @@ export interface PlatformOperation<I = unknown> {
112
143
  * such as deleting a conversation). Static; absent: remembered only for the class `personal`.
113
144
  */
114
145
  rememberable?: false;
146
+ /**
147
+ * `true`: the write's result is shown once, on the web, to the person who approves the call (an
148
+ * invitation link, a generated initial password), so only the person the run works for may
149
+ * confirm it: the call always asks them (never a grant, an `allow`, a role escalation) and is
150
+ * refused in an unattended run (`CallPolicy.personOnly`, like person fields, ruling R6).
151
+ */
152
+ revealsToApprover?: true;
115
153
  /**
116
154
  * The class of one call when it depends on the target (read at confirmation time): e.g.
117
155
  * `agents.update` is `personal` only on a private agent the actor owns and `org` otherwise, so a
@@ -133,6 +171,21 @@ export interface PlatformOperation<I = unknown> {
133
171
  * errors speak.
134
172
  */
135
173
  precheck?(input: I, ctx: OperationContext): Promise<PrecheckResult>;
174
+ /**
175
+ * The secret fields of the write's target (platform web parity spec §4.1): read at confirmation
176
+ * time, after availability, and planned against the input's `values`, `askPerson` and
177
+ * `clearSecrets` (`planPersonFields`). Only for writes whose input carries
178
+ * `personFieldParams`; a secret in `values` is refused before the card, and the asked fields
179
+ * make the call always ask the person, once, on the web. Absent: the write has no person fields.
180
+ */
181
+ personFields?(input: I, ctx: OperationContext): Promise<PersonFieldTarget>;
182
+ /**
183
+ * Why the operation takes none of its mirrored route's secret fields (`secret()` meta, left in
184
+ * `omits`) and asks the person for none, e.g. a preview without the credential, or a switch that
185
+ * refuses a plugin needing input (`plugins.install` takes it). Rule `platform-op-secret-param`
186
+ * otherwise requires {@link personFields}.
187
+ */
188
+ withoutSecrets?: string;
136
189
  /**
137
190
  * The bilingual card summary of a write, rendered from the input and kernel reads (names of
138
191
  * the targets, preview counts), never from model text; required unless `confirm` is `read`.
@@ -147,6 +200,12 @@ export interface PlatformOperation<I = unknown> {
147
200
  en: string;
148
201
  }>;
149
202
  run(input: I, ctx: OperationContext): Promise<unknown>;
203
+ /**
204
+ * The link card to pop up after a successful `run` (platform web parity spec §6), built from the
205
+ * input and the result, never from model text; null: none for this result. A throw leaves the
206
+ * card out (the result stands).
207
+ */
208
+ handoff?(input: I, result: unknown, ctx: OperationContext): HandoffView | null;
150
209
  }
151
210
  /** Identity helper that types an operation's handler and summary from its input schema. */
152
211
  export declare function defineOperation<I>(op: PlatformOperation<I>): PlatformOperation<I>;
@@ -25,7 +25,7 @@ export const PLATFORM_DOMAINS = [
25
25
  },
26
26
  {
27
27
  id: "plugins",
28
- description: "Plugins in the org and on the platform: list, read, enable, disable, update, scope, import, the org's own uploads.",
28
+ description: "Plugins in the org and on the platform: list, read, install with inputs, enable, disable, update, scope, import, the org's own uploads.",
29
29
  },
30
30
  {
31
31
  id: "marketplaces",
@@ -37,11 +37,11 @@ export const PLATFORM_DOMAINS = [
37
37
  },
38
38
  {
39
39
  id: "connectors",
40
- description: "Connectors and connector templates: list and read, refresh tools, delete.",
40
+ description: "Connectors and connector templates: list, read, preview, create (custom or from a template), edit, credentials (the person enters them on the card), OAuth connect (a Connect button for the person), guide acknowledgement, refresh tools, delete.",
41
41
  },
42
42
  {
43
43
  id: "extensions",
44
- description: "Extensions in the org (state, tool switches, extension point defaults, file previewers) and, for the super admin, on the platform (state, pending permission confirmations, enable, disable, uninstall).",
44
+ description: "Extensions in the org (state, tool switches, extension point defaults, file previewers, the org config and the org's copy of platform config) and, for the super admin, on the platform (state, deployment config, pending permission confirmations, enable, disable, uninstall). Secrets are entered by the person on the confirmation card.",
45
45
  },
46
46
  {
47
47
  id: "conversations",
@@ -49,7 +49,7 @@ export const PLATFORM_DOMAINS = [
49
49
  },
50
50
  {
51
51
  id: "orgs",
52
- description: "This org (read, rename, members, its audit log) and, for the super admin, every org and its limits.",
52
+ description: "This org (read, rename, members and invitations, its audit log) and, for the super admin, every org and its limits.",
53
53
  },
54
54
  {
55
55
  id: "accounts",
@@ -190,6 +190,7 @@ let AccountsOperations = class AccountsOperations {
190
190
  // the password is generated by the kernel; the super-admin flag is a role change (human-only)
191
191
  omits: ["password", "superAdmin"],
192
192
  confirm: "platform",
193
+ revealsToApprover: true,
193
194
  errors: [
194
195
  {
195
196
  code: "account.login_taken",
@@ -1,16 +1,23 @@
1
1
  import { type OnModuleInit } from "@nestjs/common";
2
2
  import { ChannelConnections } from "../../channels/connections.service.js";
3
+ import { PluginGuides } from "../../extensions/plugin-guides.js";
4
+ import { KernelDb } from "../../infra/database/kernel-db.js";
3
5
  import { PlatformOperations } from "../registry.js";
4
6
  /**
5
7
  * Channel connection operations of the `Platform` tool (spec §14): read a connection and change
6
8
  * its binding (which agent answers, what happens to unbound people, on / off, inbound mode),
7
- * or remove it. Creating a connection and changing its credentials or config stay on the web:
8
- * they carry app secrets a person types (spec §6.4).
9
+ * or remove it. Creating a connection takes the channel's secrets as person fields (the person types
10
+ * them on the confirmation card; platform web parity spec §4, §7.2); changing the credentials or
11
+ * the config of a connection stays on the web.
9
12
  */
10
13
  export declare class ChannelsOperations implements OnModuleInit {
11
14
  private readonly registry;
12
15
  private readonly channels;
13
- constructor(registry: PlatformOperations, channels: ChannelConnections);
16
+ private readonly guides;
17
+ private readonly kdb;
18
+ constructor(registry: PlatformOperations, channels: ChannelConnections, guides: PluginGuides, kdb: KernelDb);
19
+ /** The actor's org role (the guide reads and the ack take it), `forbidden` when not a member. */
20
+ private org;
14
21
  private nameOf;
15
22
  onModuleInit(): void;
16
23
  }
@@ -9,12 +9,18 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
9
9
  };
10
10
  import { Inject, Injectable } from "@nestjs/common";
11
11
  import { z } from "zod";
12
- import { ChannelPatchSchema, ChannelPathParams } from "../../channels/channels.schemas.js";
12
+ import { ChannelCreateSchema, ChannelGuideAckSchema, ChannelPatchSchema, ChannelPathParams, ChannelSchemaParams, } from "../../channels/channels.schemas.js";
13
13
  import { ChannelConnections, } from "../../channels/connections.service.js";
14
+ import { ApiError } from "../../errors.js";
15
+ import { PluginGuides } from "../../extensions/plugin-guides.js";
16
+ import { KernelDb } from "../../infra/database/kernel-db.js";
14
17
  import { defineOperation } from "../operation.js";
18
+ import { personFieldParams, secretFieldsOf } from "../person-fields.js";
15
19
  import { PlatformOperations } from "../registry.js";
16
20
  import { precheckBy, viaAgent } from "./errors.js";
17
21
  import { Cursor, pageOf, startOf } from "./paging.js";
22
+ import { nestedConfig, withPersonInputs } from "./person-inputs.js";
23
+ import { roleOf } from "./role.js";
18
24
  import { named, orElse } from "./summary.js";
19
25
  const PAGE = 50;
20
26
  /**
@@ -41,15 +47,27 @@ const detail = (c) => ({
41
47
  /**
42
48
  * Channel connection operations of the `Platform` tool (spec §14): read a connection and change
43
49
  * its binding (which agent answers, what happens to unbound people, on / off, inbound mode),
44
- * or remove it. Creating a connection and changing its credentials or config stay on the web:
45
- * they carry app secrets a person types (spec §6.4).
50
+ * or remove it. Creating a connection takes the channel's secrets as person fields (the person types
51
+ * them on the confirmation card; platform web parity spec §4, §7.2); changing the credentials or
52
+ * the config of a connection stays on the web.
46
53
  */
47
54
  let ChannelsOperations = class ChannelsOperations {
48
55
  registry;
49
56
  channels;
50
- constructor(registry, channels) {
57
+ guides;
58
+ kdb;
59
+ constructor(registry, channels, guides, kdb) {
51
60
  this.registry = registry;
52
61
  this.channels = channels;
62
+ this.guides = guides;
63
+ this.kdb = kdb;
64
+ }
65
+ /** The actor's org role (the guide reads and the ack take it), `forbidden` when not a member. */
66
+ async org(ctx) {
67
+ const role = await roleOf(this.kdb.db, ctx.orgId, ctx.actorAccountId);
68
+ if (role === null)
69
+ throw new ApiError("forbidden", "Insufficient organization role");
70
+ return { orgId: ctx.orgId, role };
53
71
  }
54
72
  async nameOf(orgId, id) {
55
73
  return orElse(async () => named((await this.channels.get(orgId, id)).name), id);
@@ -93,6 +111,204 @@ let ChannelsOperations = class ChannelsOperations {
93
111
  channel: detail(await this.channels.get(ctx.orgId, input.connectionId)),
94
112
  }),
95
113
  }),
114
+ defineOperation({
115
+ id: "channels.schema",
116
+ description: "Read the connection form of a channel plugin (org admins): schema is the JSON Schema of the connection config (secret fields carry x-secret; no values), guide names the plugin's setup guide for the org (null when it has none), inbound says whether webhook inbound is supported and available. Read it before channels.create to know the fields.",
117
+ input: ChannelSchemaParams.strict(),
118
+ example: { plugin: "lark" },
119
+ authz: { orgAction: "channels.manage" },
120
+ mirrors: ["GET /api/v1/orgs/:orgId/channels/schema/:plugin"],
121
+ confirm: "read",
122
+ errors: [
123
+ {
124
+ code: "extension.not_found",
125
+ next: "The extension does not provide a channel; pick one that is installed (extensions.list).",
126
+ },
127
+ ],
128
+ run: async (input, ctx) => {
129
+ const schema = this.channels.jsonSchema(input.plugin);
130
+ const inbound = this.channels.inboundInfo(input.plugin);
131
+ const g = (await this.guides.channelGuides([input.plugin], await this.org(ctx))).get(input.plugin);
132
+ return {
133
+ plugin: input.plugin,
134
+ schema,
135
+ guide: g ? { itemId: g.itemId, guideId: g.guideId } : null,
136
+ inbound,
137
+ };
138
+ },
139
+ }),
140
+ defineOperation({
141
+ id: "channels.create",
142
+ description: "Create a channel connection (IM bot) in the org (org admins): plugin, name, the agent that answers (agentId) and values, the non-secret connection config (read the fields with channels.schema). Secret fields (app secrets, tokens) are never in values: list them in askPerson and the person types them on the confirmation card (on the web); required secrets are asked even when not listed. The plugin verifies the credentials before anything is saved. Turn on webhook inbound with inboundMode webhook (only where supported); a setup guide, if any, is in channels.schema.",
143
+ input: z
144
+ .object({
145
+ plugin: ChannelCreateSchema.shape.plugin,
146
+ name: ChannelCreateSchema.shape.name,
147
+ agentId: ChannelCreateSchema.shape.agentId,
148
+ values: ChannelCreateSchema.shape.config,
149
+ unboundPolicy: ChannelCreateSchema.shape.unboundPolicy,
150
+ inboundMode: ChannelCreateSchema.shape.inboundMode,
151
+ askPerson: personFieldParams.askPerson,
152
+ })
153
+ .strict(),
154
+ example: {
155
+ plugin: "lark",
156
+ name: "Lark bot",
157
+ agentId: "00000000-0000-4000-8000-000000000000",
158
+ values: { appId: "cli_a1b2c3" },
159
+ askPerson: ["appSecret"],
160
+ },
161
+ authz: { orgAction: "channels.manage" },
162
+ mirrors: ["POST /api/v1/orgs/:orgId/channels"],
163
+ renames: { values: "config" },
164
+ extras: ["askPerson"],
165
+ confirm: "org",
166
+ errors: [
167
+ {
168
+ code: "extension.not_found",
169
+ next: "The extension does not provide a channel; pick one that is installed (extensions.list).",
170
+ },
171
+ {
172
+ code: "extension.not_enabled",
173
+ next: "Switch the extension on in the org first (plugins.set-enabled).",
174
+ },
175
+ {
176
+ code: "extension.config_invalid",
177
+ next: "Read the form with channels.schema and correct values (the error's details name the fields); fields required in webhook mode come from inboundMode, secret ones are asked with askPerson.",
178
+ },
179
+ {
180
+ code: "channel.verify_failed",
181
+ next: "The plugin could not verify the credentials; the person re-enters them on a new call (check the non-secret values and the app on the IM platform).",
182
+ },
183
+ {
184
+ code: "agent.not_found",
185
+ next: "Pick the agent with agents.list and pass its id as agentId.",
186
+ },
187
+ {
188
+ code: "channel.webhook_unavailable",
189
+ next: "The plugin or the deployment cannot receive webhooks; keep inboundMode long_connection, or ask the super admin to set channels.webhookBaseUrl.",
190
+ },
191
+ ],
192
+ precheck: (i, ctx) => precheckBy(() => this.channels.checkCreate(ctx.orgId, {
193
+ plugin: i.plugin,
194
+ agentId: i.agentId,
195
+ inboundMode: i.inboundMode,
196
+ })),
197
+ personFields: async (i) => {
198
+ const found = secretFieldsOf(this.channels.jsonSchema(i.plugin), new Set());
199
+ // a secret the chosen inbound mode requires is asked even when not listed
200
+ const modal = new Set(this.channels.modeRequiredFields(i.plugin, i.inboundMode ?? "long_connection"));
201
+ found.fields = found.fields.map((f) => modal.has(f.path) ? { ...f, required: true } : f);
202
+ return {
203
+ target: {
204
+ zh: `渠道连接「${named(i.name)}」(${named(i.plugin)})`,
205
+ en: `Channel connection "${named(i.name)}" (${named(i.plugin)})`,
206
+ },
207
+ ...found,
208
+ };
209
+ },
210
+ summary: (i, ctx) => {
211
+ const ask = ctx.personAsk ?? i.askPerson;
212
+ const keys = Object.keys(i.values).map(named);
213
+ const zh = [
214
+ `用插件 ${named(i.plugin)} 创建渠道连接「${named(i.name)}」,由智能体 ${named(i.agentId)} 应答`,
215
+ keys.length > 0 && `设置 ${keys.join("、")}`,
216
+ ask.length > 0 && `由本人填写 ${ask.map(named).join("、")}`,
217
+ i.inboundMode === "webhook" && "入站方式:webhook",
218
+ ].filter((p) => typeof p === "string");
219
+ const en = [
220
+ `Create channel connection "${named(i.name)}" with plugin ${named(i.plugin)}, answered by agent ${named(i.agentId)}`,
221
+ keys.length > 0 && `sets ${keys.join(", ")}`,
222
+ ask.length > 0 && `the person enters ${ask.map(named).join(", ")}`,
223
+ i.inboundMode === "webhook" && "inbound mode: webhook",
224
+ ].filter((p) => typeof p === "string");
225
+ return { zh: zh.join(";"), en: en.join("; ") };
226
+ },
227
+ run: async (input, ctx) => {
228
+ const r = await withPersonInputs("channels.create", ctx, (entered, detail) => this.channels.create(ctx.orgId, {
229
+ plugin: input.plugin,
230
+ name: input.name,
231
+ agentId: input.agentId,
232
+ config: nestedConfig(input.values, entered, []),
233
+ unboundPolicy: input.unboundPolicy,
234
+ inboundMode: input.inboundMode,
235
+ }, ctx.actorAccountId, undefined, detail));
236
+ const webhook = input.inboundMode === "webhook";
237
+ return {
238
+ channel: detail(r),
239
+ ...(webhook && {
240
+ note: r.webhookUrl !== null
241
+ ? `Register the callback URL ${r.webhookUrl} in the IM platform's app settings (channels.get shows it again).`
242
+ : "The callback URL is not available yet: the super admin has to set channels.webhookBaseUrl; the channels page on the web then shows it.",
243
+ }),
244
+ };
245
+ },
246
+ }),
247
+ defineOperation({
248
+ id: "channels.guide-ack",
249
+ description: "Record that the person updated the app on the IM platform to the plugin's current setup guide (org admins). The card states what the person confirms. hash is the guide's hash from setup.read for this connection (audience admin, the connection's inbound mode); a stale hash is refused before the card.",
250
+ input: ChannelPathParams.extend(ChannelGuideAckSchema.shape).strict(),
251
+ example: {
252
+ connectionId: "00000000-0000-4000-8000-000000000000",
253
+ hash: "0".repeat(64),
254
+ },
255
+ authz: { orgAction: "channels.manage" },
256
+ mirrors: ["POST /api/v1/orgs/:orgId/channels/:connectionId/guide-ack"],
257
+ confirm: "personal",
258
+ // A human attestation: a remembered grant would let the agent confirm unseen guides.
259
+ rememberable: false,
260
+ errors: [
261
+ {
262
+ code: "channel.not_found",
263
+ next: "Look the connection up with channels.list and pass its id.",
264
+ },
265
+ {
266
+ code: "channel.guide_changed",
267
+ next: "The plugin's setup guide changed since the hash was taken: read it again with setup.read (connectionId, audience admin, the connection's inbound mode), walk the person through it, then call again with the hash it returns.",
268
+ },
269
+ {
270
+ code: "catalog.guide_not_found",
271
+ next: "The plugin has no setup guide the org can see; there is nothing to acknowledge.",
272
+ },
273
+ ],
274
+ precheck: async (i, ctx) => {
275
+ let current;
276
+ const r = await precheckBy(async () => {
277
+ current = await this.channels.get(ctx.orgId, i.connectionId);
278
+ });
279
+ if (!r.ok || current === undefined)
280
+ return r;
281
+ // the service's own comparison, read before the card: a stale hash is never confirmed
282
+ const ack = await this.guides.currentAck(current.plugin, "channel-connection", {
283
+ mode: current.inboundMode,
284
+ org: await this.org(ctx),
285
+ });
286
+ if (ack === null) {
287
+ return {
288
+ ok: false,
289
+ code: "catalog.guide_not_found",
290
+ message: "The plugin has no channel setup guide",
291
+ };
292
+ }
293
+ return ack.hash === i.hash
294
+ ? { ok: true }
295
+ : {
296
+ ok: false,
297
+ code: "channel.guide_changed",
298
+ message: "The plugin's setup guide changed since it was shown",
299
+ };
300
+ },
301
+ summary: async (i, ctx) => {
302
+ const name = await this.nameOf(ctx.orgId, i.connectionId);
303
+ return {
304
+ zh: `确认已按最新的设置指南更新第三方平台上渠道连接「${name}」对应的应用`,
305
+ en: `Confirm that the app of channel connection "${name}" was updated on the IM platform to the current setup guide`,
306
+ };
307
+ },
308
+ run: async (input, ctx) => ({
309
+ channel: detail(await this.channels.ackGuide(await this.org(ctx), input.connectionId, input.hash, ctx.actorAccountId, undefined, viaAgent("channels.guide-ack", ctx))),
310
+ }),
311
+ }),
96
312
  defineOperation({
97
313
  id: "channels.update",
98
314
  description: "Change a channel connection's binding (org admins): its name, the agent that answers (agentId), what happens to people not yet bound to an account (unboundPolicy: bind or anonymous), active or disabled, and the inbound mode. Give only what changes. Credentials and config are changed on the web.",
@@ -190,6 +406,8 @@ let ChannelsOperations = class ChannelsOperations {
190
406
  ChannelsOperations = __decorate([
191
407
  Injectable(),
192
408
  __param(0, Inject(PlatformOperations)),
193
- __param(1, Inject(ChannelConnections))
409
+ __param(1, Inject(ChannelConnections)),
410
+ __param(2, Inject(PluginGuides)),
411
+ __param(3, Inject(KernelDb))
194
412
  ], ChannelsOperations);
195
413
  export { ChannelsOperations };
@@ -1,17 +1,35 @@
1
1
  import { type OnModuleInit } from "@nestjs/common";
2
2
  import { ComponentScopeService } from "../../catalog/component-scope.service.js";
3
+ import { PluginInstaller } from "../../catalog/plugin-install.js";
4
+ import { KernelDb } from "../../infra/database/kernel-db.js";
3
5
  import { ConnectorsService } from "../../tools/connectors.service.js";
4
6
  import { PlatformOperations } from "../registry.js";
7
+ /** The result text of `connectors.connect` (platform web parity spec §4.4); model-visible English. */
8
+ export declare const CONNECT_SHOWN_TEXT = "The person was shown a Connect button; check connectors.get for the connection state.";
5
9
  /**
6
- * Connector operations of the `Platform` tool (spec §7): reads, deleting a connector and
7
- * refreshing its tool list (org admins). Creating a connector, editing its endpoint or entering a
8
- * credential stays on the web (a person types credentials, spec §6.4).
10
+ * Connector operations of the `Platform` tool (spec §7; platform web parity spec §7.2): reads,
11
+ * the kinds and a preview, creating a connector (custom or from a platform template), editing it,
12
+ * credentials, the setup guide acknowledgement, deleting and refreshing. Credentials are person
13
+ * fields (ruling R3): the model names them in `askPerson`, the person types them on the
14
+ * confirmation card, and the write gets them only through `personInputs`. Per-tool policies stay
15
+ * on the web (ruling R4: the agent's own permissions).
9
16
  */
10
17
  export declare class ConnectorsOperations implements OnModuleInit {
11
18
  private readonly registry;
12
19
  private readonly connectors;
13
20
  private readonly components;
14
- constructor(registry: PlatformOperations, connectors: ConnectorsService, components: ComponentScopeService);
21
+ private readonly installer;
22
+ private readonly kdb;
23
+ constructor(registry: PlatformOperations, connectors: ConnectorsService, components: ComponentScopeService, installer: PluginInstaller, kdb: KernelDb);
24
+ /** The actor's org role (the guide routes take it), `forbidden` when not a member. */
25
+ private org;
26
+ /**
27
+ * The setup guide of a connector made from a template, as `connectors.guide-ack` takes it (the
28
+ * current guide's version and hash, and the drift since it was set up), or null without one.
29
+ */
30
+ private guideOf;
31
+ /** A platform connector template on in the org: its card name and auth method. */
32
+ private template;
15
33
  private connectorName;
16
34
  onModuleInit(): void;
17
35
  }