@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.
- package/dist/admin/extensions.controller.d.ts +2 -10
- package/dist/admin/extensions.controller.js +2 -24
- package/dist/admin/extensions.schemas.d.ts +21 -0
- package/dist/admin/extensions.schemas.js +37 -0
- package/dist/catalog/marketplaces.service.d.ts +1 -1
- package/dist/catalog/org-catalog.controller.d.ts +0 -5
- package/dist/catalog/org-catalog.controller.js +3 -17
- package/dist/catalog/org-catalog.schemas.d.ts +43 -0
- package/dist/catalog/org-catalog.schemas.js +43 -2
- package/dist/catalog/org-extension-switch.d.ts +3 -1
- package/dist/catalog/org-extension-switch.js +12 -5
- package/dist/catalog/org-extension.controller.d.ts +2 -21
- package/dist/catalog/org-extension.controller.js +1 -38
- package/dist/catalog/org-extension.schemas.d.ts +31 -0
- package/dist/catalog/org-extension.schemas.js +65 -0
- package/dist/catalog/plugin-install.d.ts +2 -0
- package/dist/catalog/plugin-install.js +3 -3
- package/dist/channels/actions.js +2 -0
- package/dist/channels/cards.d.ts +8 -0
- package/dist/channels/cards.js +18 -0
- package/dist/channels/channels.schemas.d.ts +3 -0
- package/dist/channels/channels.schemas.js +8 -0
- package/dist/channels/connections.service.d.ts +17 -2
- package/dist/channels/connections.service.js +30 -5
- package/dist/channels/outbound.js +25 -1
- package/dist/channels/phrases.d.ts +10 -0
- package/dist/channels/phrases.js +10 -0
- package/dist/conversations/conversations.module.js +4 -0
- package/dist/conversations/events.d.ts +35 -0
- package/dist/conversations/events.js +29 -0
- package/dist/conversations/leak-check.d.ts +26 -0
- package/dist/conversations/leak-check.js +69 -0
- package/dist/ctx/secrets.d.ts +13 -1
- package/dist/ctx/secrets.js +19 -1
- package/dist/db/kernel-schema.d.ts +34 -0
- package/dist/devices/working-root.d.ts +2 -3
- package/dist/errors.d.ts +19 -0
- package/dist/errors.js +19 -0
- package/dist/extensions/deployment-config.d.ts +6 -2
- package/dist/extensions/deployment-config.js +35 -23
- package/dist/extensions/org-config.d.ts +2 -0
- package/dist/extensions/org-config.js +1 -0
- package/dist/extensions/org-overrides.d.ts +2 -0
- package/dist/extensions/org-overrides.js +3 -2
- package/dist/http/api.module.js +6 -0
- package/dist/identity/initial-passwords.job.d.ts +3 -2
- package/dist/identity/initial-passwords.job.js +11 -5
- package/dist/orgs/invitations.controller.d.ts +3 -11
- package/dist/orgs/invitations.controller.js +9 -10
- package/dist/orgs/invitations.service.d.ts +12 -2
- package/dist/orgs/invitations.service.js +14 -7
- package/dist/orgs/members.service.d.ts +12 -2
- package/dist/orgs/members.service.js +10 -8
- package/dist/orgs/orgs.controller.d.ts +4 -12
- package/dist/orgs/orgs.controller.js +10 -10
- package/dist/orgs/orgs.schemas.d.ts +26 -0
- package/dist/orgs/orgs.schemas.js +22 -0
- package/dist/platform/connector-person-fields.d.ts +67 -0
- package/dist/platform/connector-person-fields.js +129 -0
- package/dist/platform/exclusions.js +6 -141
- package/dist/platform/method.js +1 -0
- package/dist/platform/operation.d.ts +61 -2
- package/dist/platform/operation.js +4 -4
- package/dist/platform/ops/accounts.ops.js +1 -0
- package/dist/platform/ops/channels.ops.d.ts +10 -3
- package/dist/platform/ops/channels.ops.js +223 -5
- package/dist/platform/ops/connectors.ops.d.ts +22 -4
- package/dist/platform/ops/connectors.ops.js +664 -13
- package/dist/platform/ops/extensions-admin.ops.d.ts +15 -2
- package/dist/platform/ops/extensions-admin.ops.js +153 -5
- package/dist/platform/ops/extensions.ops.d.ts +19 -5
- package/dist/platform/ops/extensions.ops.js +285 -10
- package/dist/platform/ops/org-plugins.ops.d.ts +15 -2
- package/dist/platform/ops/org-plugins.ops.js +323 -4
- package/dist/platform/ops/orgs.ops.d.ts +40 -3
- package/dist/platform/ops/orgs.ops.js +293 -12
- package/dist/platform/ops/person-inputs.d.ts +65 -0
- package/dist/platform/ops/person-inputs.js +129 -0
- package/dist/platform/ops/plugins.ops.d.ts +3 -1
- package/dist/platform/ops/plugins.ops.js +33 -20
- package/dist/platform/parity.d.ts +7 -2
- package/dist/platform/parity.js +75 -13
- package/dist/platform/person-fields.d.ts +119 -0
- package/dist/platform/person-fields.js +403 -0
- package/dist/platform/platform.module.d.ts +4 -3
- package/dist/platform/platform.module.js +8 -5
- package/dist/platform/route-schemas.js +2 -0
- package/dist/platform/sealed-inputs.d.ts +44 -0
- package/dist/platform/sealed-inputs.js +116 -0
- package/dist/platform/sealed-reveals.controller.d.ts +20 -0
- package/dist/platform/sealed-reveals.controller.js +48 -0
- package/dist/platform/sealed-reveals.d.ts +52 -0
- package/dist/platform/sealed-reveals.js +153 -0
- package/dist/runtime/project/knowledge.js +24 -19
- package/dist/runtime/waits.js +8 -2
- package/dist/sandbox/permission-facts.d.ts +5 -1
- package/dist/sandbox/permission-facts.js +8 -2
- package/dist/setup/setup-guides.service.d.ts +5 -0
- package/dist/setup/setup-guides.service.js +2 -1
- package/dist/tools/approvals.controller.d.ts +1 -0
- package/dist/tools/approvals.controller.js +19 -0
- package/dist/tools/approvals.service.d.ts +50 -1
- package/dist/tools/approvals.service.js +118 -10
- package/dist/tools/builtins/builtin-tools.d.ts +3 -0
- package/dist/tools/builtins/builtin-tools.js +31 -9
- package/dist/tools/builtins/platform.d.ts +20 -0
- package/dist/tools/builtins/platform.js +214 -15
- package/dist/tools/connectors.controller.d.ts +6 -7
- package/dist/tools/connectors.controller.js +4 -44
- package/dist/tools/connectors.schemas.d.ts +170 -1
- package/dist/tools/connectors.schemas.js +82 -3
- package/dist/tools/connectors.service.d.ts +16 -6
- package/dist/tools/connectors.service.js +39 -24
- package/dist/tools/oauth/oauth.controller.d.ts +3 -6
- package/dist/tools/oauth/oauth.controller.js +3 -12
- package/dist/tools/oauth/oauth.schemas.d.ts +14 -0
- package/dist/tools/oauth/oauth.schemas.js +27 -0
- package/dist/tools/pipeline.d.ts +31 -2
- package/dist/tools/pipeline.js +89 -17
- package/dist/tools/policy.d.ts +4 -0
- package/dist/tools/policy.js +8 -0
- package/dist/tools/registry.d.ts +29 -0
- package/dist/tools/tools.module.js +3 -0
- package/package.json +3 -3
- package/src/migrations/0169_platform_sealed_inputs.sql +23 -0
- package/src/migrations/0170_platform_sealed_reveals.sql +27 -0
|
@@ -10,15 +10,89 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
10
10
|
import { Inject, Injectable } from "@nestjs/common";
|
|
11
11
|
import { z } from "zod";
|
|
12
12
|
import { ComponentScopeService } from "../../catalog/component-scope.service.js";
|
|
13
|
-
import {
|
|
13
|
+
import { connectorTemplateState } from "../../catalog/component-state.js";
|
|
14
|
+
import { CatalogConnectorInput, ConnectorTemplatePathParams, OrgTemplateConnectorSchema, } from "../../catalog/org-catalog.schemas.js";
|
|
15
|
+
import { PluginInstaller } from "../../catalog/plugin-install.js";
|
|
16
|
+
import { ApiError } from "../../errors.js";
|
|
17
|
+
import { KernelDb } from "../../infra/database/kernel-db.js";
|
|
18
|
+
import { ConnectorCreateSchema, ConnectorGuideAckSchema, ConnectorPathParams, ConnectorPreviewSchema, ConnectorUpdateSchema, GitPushPolicyBody, } from "../../tools/connectors.schemas.js";
|
|
14
19
|
import { ConnectorsService, } from "../../tools/connectors.service.js";
|
|
15
20
|
import { publicEndpoint } from "../../tools/endpoint.js";
|
|
21
|
+
import { clientProblem, connectorCredential, connectorPersonFields, headersWebOnly, } from "../connector-person-fields.js";
|
|
16
22
|
import { defineOperation } from "../operation.js";
|
|
23
|
+
import { personFieldParams } from "../person-fields.js";
|
|
17
24
|
import { PlatformOperations } from "../registry.js";
|
|
18
25
|
import { precheckBy, viaAgent } from "./errors.js";
|
|
19
26
|
import { Cursor, pageOf, startOf } from "./paging.js";
|
|
27
|
+
import { withPersonInputs } from "./person-inputs.js";
|
|
28
|
+
import { roleOf } from "./role.js";
|
|
20
29
|
import { named, orElse } from "./summary.js";
|
|
21
30
|
const PAGE = 50;
|
|
31
|
+
/** The result text of `connectors.connect` (platform web parity spec §4.4); model-visible English. */
|
|
32
|
+
export const CONNECT_SHOWN_TEXT = "The person was shown a Connect button; check connectors.get for the connection state.";
|
|
33
|
+
const ConnectorId = ConnectorPathParams.shape.connectorId.max(100);
|
|
34
|
+
const EXAMPLE_ID = "5d2e8f1a-0b3c-4d5e-8f9a-1b2c3d4e5f60";
|
|
35
|
+
/** The OAuth client id of a connector (the client secret is a person field, ruling R3). */
|
|
36
|
+
const ClientParam = z
|
|
37
|
+
.object({ clientId: z.string().min(1).max(500) })
|
|
38
|
+
.strict()
|
|
39
|
+
.describe("The OAuth client registered at the authorization server (oauth_client, or oauth_code with client manual): its id; the person enters the client secret on the confirmation card.");
|
|
40
|
+
/** `connectors.create`: the create body without the credential, the client id and askPerson. */
|
|
41
|
+
const CreateInput = ConnectorCreateSchema.omit({ credential: true })
|
|
42
|
+
.extend({ client: ClientParam.optional(), askPerson: personFieldParams.askPerson })
|
|
43
|
+
.strict();
|
|
44
|
+
/** `connectors.update`: the PATCH body without per-tool policies (ruling R4). */
|
|
45
|
+
const UpdateInput = z
|
|
46
|
+
.object({ connectorId: ConnectorId })
|
|
47
|
+
.extend(ConnectorUpdateSchema.omit({ tools: true, allowUnannotated: true }).shape)
|
|
48
|
+
.strict();
|
|
49
|
+
/** `connectors.add-from-template`: the route's name and its `config` flattened, no secrets. */
|
|
50
|
+
const FromTemplateInput = z
|
|
51
|
+
.object({
|
|
52
|
+
templateId: ConnectorTemplatePathParams.shape.templateId.max(100),
|
|
53
|
+
name: OrgTemplateConnectorSchema.shape.name,
|
|
54
|
+
slug: CatalogConnectorInput.shape.slug,
|
|
55
|
+
endpoint: CatalogConnectorInput.shape.endpoint,
|
|
56
|
+
client: ClientParam.optional(),
|
|
57
|
+
askPerson: personFieldParams.askPerson,
|
|
58
|
+
})
|
|
59
|
+
.strict();
|
|
60
|
+
/** The card's word for what the person enters: the OAuth client, or whose credential it is. */
|
|
61
|
+
const ownershipOf = (auth) => {
|
|
62
|
+
if (auth.type === "oauth_client" || auth.type === "oauth_code") {
|
|
63
|
+
return { zh: "OAuth 客户端", en: "OAuth client" };
|
|
64
|
+
}
|
|
65
|
+
return auth.type !== "none" && auth.ownership === "personal"
|
|
66
|
+
? { zh: "个人凭据", en: "personal" }
|
|
67
|
+
: { zh: "组织凭据", en: "org" };
|
|
68
|
+
};
|
|
69
|
+
/** The card target of a connector's credential ("Connector GitHub (org)"). */
|
|
70
|
+
const connectorTarget = (name, auth) => {
|
|
71
|
+
const o = ownershipOf(auth);
|
|
72
|
+
return { zh: `连接器「${named(name)}」(${o.zh})`, en: `Connector ${named(name)} (${o.en})` };
|
|
73
|
+
};
|
|
74
|
+
/** The person fields named on a card summary: the plan's (`personAsk`), else none. */
|
|
75
|
+
const entersText = (ctx) => {
|
|
76
|
+
const ask = ctx.personAsk ?? [];
|
|
77
|
+
return ask.length === 0
|
|
78
|
+
? { zh: "", en: "" }
|
|
79
|
+
: { zh: `;由本人填写 ${ask.join("、")}`, en: `; the person enters ${ask.join(", ")}` };
|
|
80
|
+
};
|
|
81
|
+
/** The refusal of a credential the card cannot ask for (custom headers; ruling R1's code). */
|
|
82
|
+
const webOnly = (message) => message === null ? { ok: true } : { ok: false, code: "platform.secret_record_web_only", message };
|
|
83
|
+
/** A preview as the tool returns it: compact tool rows, no input schemas. */
|
|
84
|
+
const previewOf = (p) => ({
|
|
85
|
+
tools: p.tools?.map((t) => ({
|
|
86
|
+
name: t.name,
|
|
87
|
+
key: t.key,
|
|
88
|
+
description: t.description,
|
|
89
|
+
defaultPolicy: t.defaultPolicy,
|
|
90
|
+
issue: t.issue,
|
|
91
|
+
})) ?? null,
|
|
92
|
+
issues: p.issues,
|
|
93
|
+
authHints: p.authHints,
|
|
94
|
+
operations: p.operations?.length ?? 0,
|
|
95
|
+
});
|
|
22
96
|
/** `connectors.set-git-push-policy`: the route's path param and body. */
|
|
23
97
|
const SetGitPushPolicyInput = z
|
|
24
98
|
.object({ connectorId: ConnectorPathParams.shape.connectorId.max(100) })
|
|
@@ -60,18 +134,77 @@ const detail = (c) => ({
|
|
|
60
134
|
})),
|
|
61
135
|
});
|
|
62
136
|
/**
|
|
63
|
-
* Connector operations of the `Platform` tool (spec §7): reads,
|
|
64
|
-
*
|
|
65
|
-
*
|
|
137
|
+
* Connector operations of the `Platform` tool (spec §7; platform web parity spec §7.2): reads,
|
|
138
|
+
* the kinds and a preview, creating a connector (custom or from a platform template), editing it,
|
|
139
|
+
* credentials, the setup guide acknowledgement, deleting and refreshing. Credentials are person
|
|
140
|
+
* fields (ruling R3): the model names them in `askPerson`, the person types them on the
|
|
141
|
+
* confirmation card, and the write gets them only through `personInputs`. Per-tool policies stay
|
|
142
|
+
* on the web (ruling R4: the agent's own permissions).
|
|
66
143
|
*/
|
|
67
144
|
let ConnectorsOperations = class ConnectorsOperations {
|
|
68
145
|
registry;
|
|
69
146
|
connectors;
|
|
70
147
|
components;
|
|
71
|
-
|
|
148
|
+
installer;
|
|
149
|
+
kdb;
|
|
150
|
+
constructor(registry, connectors, components, installer, kdb) {
|
|
72
151
|
this.registry = registry;
|
|
73
152
|
this.connectors = connectors;
|
|
74
153
|
this.components = components;
|
|
154
|
+
this.installer = installer;
|
|
155
|
+
this.kdb = kdb;
|
|
156
|
+
}
|
|
157
|
+
/** The actor's org role (the guide routes take it), `forbidden` when not a member. */
|
|
158
|
+
async org(ctx) {
|
|
159
|
+
const role = await roleOf(this.kdb.db, ctx.orgId, ctx.actorAccountId);
|
|
160
|
+
if (role === null)
|
|
161
|
+
throw new ApiError("forbidden", "Insufficient organization role");
|
|
162
|
+
return { orgId: ctx.orgId, role };
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* The setup guide of a connector made from a template, as `connectors.guide-ack` takes it (the
|
|
166
|
+
* current guide's version and hash, and the drift since it was set up), or null without one.
|
|
167
|
+
*/
|
|
168
|
+
async guideOf(ctx, c) {
|
|
169
|
+
if (c.platformTemplateId === null)
|
|
170
|
+
return null;
|
|
171
|
+
const org = await this.org(ctx);
|
|
172
|
+
const [states, current] = await Promise.all([
|
|
173
|
+
this.connectors.guideStates(org, [c.id]),
|
|
174
|
+
this.connectors.currentGuide(org, c.id).catch((e) => {
|
|
175
|
+
if (e instanceof ApiError && e.code === "catalog.guide_not_found")
|
|
176
|
+
return null;
|
|
177
|
+
throw e;
|
|
178
|
+
}),
|
|
179
|
+
]);
|
|
180
|
+
if (current === null)
|
|
181
|
+
return null;
|
|
182
|
+
return {
|
|
183
|
+
guideId: current.guideId,
|
|
184
|
+
version: current.version,
|
|
185
|
+
hash: current.hash,
|
|
186
|
+
drift: states.get(c.id)?.guideDrift ?? null,
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
/** A platform connector template on in the org: its card name and auth method. */
|
|
190
|
+
async template(orgId, templateId) {
|
|
191
|
+
// a platform template id is a uuid (the route's service checks the same before reading)
|
|
192
|
+
const uuid = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(templateId);
|
|
193
|
+
const state = uuid ? await connectorTemplateState(this.kdb.db, orgId, templateId) : "absent";
|
|
194
|
+
if (state === "absent") {
|
|
195
|
+
throw new ApiError("component.not_found", "The connector template does not exist or is not available in this organization");
|
|
196
|
+
}
|
|
197
|
+
const row = await this.kdb.db
|
|
198
|
+
.selectFrom("platform_connector_templates")
|
|
199
|
+
.select("file")
|
|
200
|
+
.where("id", "=", templateId)
|
|
201
|
+
.executeTakeFirstOrThrow();
|
|
202
|
+
const file = row.file;
|
|
203
|
+
return {
|
|
204
|
+
name: file.displayName?.en ?? templateId,
|
|
205
|
+
zh: file.displayName?.zh ?? templateId,
|
|
206
|
+
auth: file.template.auth,
|
|
207
|
+
};
|
|
75
208
|
}
|
|
76
209
|
connectorName(ctx, connectorId) {
|
|
77
210
|
return orElse(async () => named((await this.connectors.get(ctx.orgId, connectorId, ctx.actorAccountId)).name), connectorId);
|
|
@@ -91,7 +224,7 @@ let ConnectorsOperations = class ConnectorsOperations {
|
|
|
91
224
|
}),
|
|
92
225
|
defineOperation({
|
|
93
226
|
id: "connectors.get",
|
|
94
|
-
description: "Read one connector: its tools with their state and default policy,
|
|
227
|
+
description: "Read one connector: its tools with their state and default policy, whether your credential for it is connected, and for one made from a template its setup guide (version, hash for connectors.guide-ack, and whether the guide changed since it was set up). Credentials are never returned: the person enters them on the confirmation card of connectors.set-org-credential or connectors.set-my-credential.",
|
|
95
228
|
input: z.object({ connectorId: ConnectorPathParams.shape.connectorId.max(100) }).strict(),
|
|
96
229
|
example: { connectorId: "5d2e8f1a-0b3c-4d5e-8f9a-1b2c3d4e5f60" },
|
|
97
230
|
authz: { orgAction: "connectors.use" },
|
|
@@ -100,13 +233,14 @@ let ConnectorsOperations = class ConnectorsOperations {
|
|
|
100
233
|
errors: [
|
|
101
234
|
{ code: "connector.not_found", next: "Check the connector id with connectors.list." },
|
|
102
235
|
],
|
|
103
|
-
run: async (input, ctx) =>
|
|
104
|
-
|
|
105
|
-
|
|
236
|
+
run: async (input, ctx) => {
|
|
237
|
+
const c = await this.connectors.get(ctx.orgId, input.connectorId, ctx.actorAccountId);
|
|
238
|
+
return { connector: { ...detail(c), setupGuide: await this.guideOf(ctx, c) } };
|
|
239
|
+
},
|
|
106
240
|
}),
|
|
107
241
|
defineOperation({
|
|
108
242
|
id: "connectors.templates",
|
|
109
|
-
description: "List the platform connector templates offered to this org, with whether each is on here: the templates
|
|
243
|
+
description: "List the platform connector templates offered to this org, with whether each is on here: the templates connectors.add-from-template creates connectors from. Pages by 50: pass the returned next as params.cursor.",
|
|
110
244
|
input: z.object({ cursor: Cursor.optional() }).strict(),
|
|
111
245
|
example: {},
|
|
112
246
|
authz: { orgAction: "catalog.read" },
|
|
@@ -135,7 +269,7 @@ let ConnectorsOperations = class ConnectorsOperations {
|
|
|
135
269
|
}),
|
|
136
270
|
defineOperation({
|
|
137
271
|
id: "connectors.delete",
|
|
138
|
-
description: "Delete a connector of the org (org admins): its credentials are deleted too and agents that use it lose its tools.
|
|
272
|
+
description: "Delete a connector of the org (org admins): its credentials are deleted too and agents that use it lose its tools.",
|
|
139
273
|
input: z.object({ connectorId: ConnectorPathParams.shape.connectorId.max(100) }).strict(),
|
|
140
274
|
example: { connectorId: "5d2e8f1a-0b3c-4d5e-8f9a-1b2c3d4e5f60" },
|
|
141
275
|
authz: { orgAction: "connectors.manage" },
|
|
@@ -169,7 +303,7 @@ let ConnectorsOperations = class ConnectorsOperations {
|
|
|
169
303
|
{ code: "connector.not_found", next: "Check the connector id with connectors.list." },
|
|
170
304
|
{
|
|
171
305
|
code: "credential.missing",
|
|
172
|
-
next: "Your credential for this connector is missing:
|
|
306
|
+
next: "Your credential for this connector is missing: set it with connectors.set-my-credential (the person enters it on the card; for an OAuth connector call connectors.connect, which shows the person a Connect button), then refresh again.",
|
|
173
307
|
},
|
|
174
308
|
],
|
|
175
309
|
precheck: (i, ctx) => precheckBy(() => this.connectors.get(ctx.orgId, i.connectorId, ctx.actorAccountId)),
|
|
@@ -223,6 +357,521 @@ let ConnectorsOperations = class ConnectorsOperations {
|
|
|
223
357
|
})),
|
|
224
358
|
}),
|
|
225
359
|
}),
|
|
360
|
+
defineOperation({
|
|
361
|
+
id: "connectors.kinds",
|
|
362
|
+
description: "List the connector kinds this org can create connectors of (org admins), each with the plugin providing it: the connector values connectors.create and connectors.preview take. Empty when no connector extension is on in the org.",
|
|
363
|
+
input: z.object({}).strict(),
|
|
364
|
+
example: {},
|
|
365
|
+
authz: { orgAction: "connectors.manage" },
|
|
366
|
+
mirrors: ["GET /api/v1/orgs/:orgId/connectors/kinds"],
|
|
367
|
+
confirm: "read",
|
|
368
|
+
run: async (_input, ctx) => ({ kinds: await this.connectors.kinds(ctx.orgId) }),
|
|
369
|
+
}),
|
|
370
|
+
defineOperation({
|
|
371
|
+
id: "connectors.preview",
|
|
372
|
+
description: "Preview a custom connector before creating it (org admins): reads the endpoint's description (auth hints, operations) and, when it needs no credential (auth none or omitted), lists its tools with their default policy and issues. Writes nothing. No credential is passed here, so tools behind a credential come back as null (unknown until the connector is created). Calls the endpoint's server.",
|
|
373
|
+
input: ConnectorPreviewSchema.omit({ credential: true }).strict(),
|
|
374
|
+
example: { connector: "mcp", endpoint: { url: "https://mcp.example.com/mcp" } },
|
|
375
|
+
authz: { orgAction: "connectors.manage" },
|
|
376
|
+
mirrors: ["POST /api/v1/orgs/:orgId/connectors/preview"],
|
|
377
|
+
omits: ["credential"],
|
|
378
|
+
withoutSecrets: "a read never asks the person: without the credential, tools behind it stay unknown until connectors.create",
|
|
379
|
+
confirm: "read",
|
|
380
|
+
errors: [
|
|
381
|
+
{
|
|
382
|
+
code: "connector.kind_unavailable",
|
|
383
|
+
next: "No enabled extension provides this connector kind here; list the kinds with connectors.kinds.",
|
|
384
|
+
},
|
|
385
|
+
{
|
|
386
|
+
code: "catalog.custom_disabled",
|
|
387
|
+
next: "The platform does not allow custom connectors; create one from a template (connectors.templates, connectors.add-from-template).",
|
|
388
|
+
},
|
|
389
|
+
{
|
|
390
|
+
code: "connector.connect_failed",
|
|
391
|
+
next: "The connector's server could not be reached or refused the credential or OAuth client (the error says which); check the endpoint with connectors.preview, then call again so the person enters the credential anew.",
|
|
392
|
+
},
|
|
393
|
+
{
|
|
394
|
+
code: "validation_failed",
|
|
395
|
+
next: "The error's details name the fields; correct the params (or have the person enter the credential again) and call again.",
|
|
396
|
+
},
|
|
397
|
+
],
|
|
398
|
+
run: async (input, ctx) => previewOf(await this.connectors.preview(ctx.orgId, input)),
|
|
399
|
+
}),
|
|
400
|
+
defineOperation({
|
|
401
|
+
id: "connectors.create",
|
|
402
|
+
description: "Create a custom connector (org admins): name, connector kind (connectors.kinds), endpoint and auth method; it connects, lists the tools and stores them for review. The credential is never a param: the person enters it on the confirmation card (bearer and api_key: credential.token; basic: credential.username and credential.password; oauth_client, or oauth_code with client manual: client.clientSecret, with the client id in client). Required credential fields are asked even when not listed in askPerson. Custom header credentials are entered on the web. Preview first with connectors.preview.",
|
|
403
|
+
input: CreateInput,
|
|
404
|
+
example: {
|
|
405
|
+
name: "Docs",
|
|
406
|
+
connector: "mcp",
|
|
407
|
+
endpoint: { url: "https://mcp.example.com/mcp" },
|
|
408
|
+
auth: { type: "bearer", ownership: "org" },
|
|
409
|
+
askPerson: ["credential.token"],
|
|
410
|
+
},
|
|
411
|
+
authz: { orgAction: "connectors.manage" },
|
|
412
|
+
mirrors: ["POST /api/v1/orgs/:orgId/connectors"],
|
|
413
|
+
omits: ["credential"],
|
|
414
|
+
extras: ["client", "askPerson"],
|
|
415
|
+
confirm: "org",
|
|
416
|
+
errors: [
|
|
417
|
+
{
|
|
418
|
+
code: "connector.slug_taken",
|
|
419
|
+
next: "Another connector of the org has this slug; pass another slug.",
|
|
420
|
+
},
|
|
421
|
+
{
|
|
422
|
+
code: "connector.kind_unavailable",
|
|
423
|
+
next: "No enabled extension provides this connector kind here; list the kinds with connectors.kinds.",
|
|
424
|
+
},
|
|
425
|
+
{
|
|
426
|
+
code: "catalog.custom_disabled",
|
|
427
|
+
next: "The platform does not allow custom connectors; create one from a template (connectors.templates, connectors.add-from-template).",
|
|
428
|
+
},
|
|
429
|
+
{
|
|
430
|
+
code: "connector.connect_failed",
|
|
431
|
+
next: "The connector's server could not be reached or refused the credential or OAuth client (the error says which); check the endpoint with connectors.preview, then call again so the person enters the credential anew.",
|
|
432
|
+
},
|
|
433
|
+
{
|
|
434
|
+
code: "validation_failed",
|
|
435
|
+
next: "The error's details name the fields; correct the params (or have the person enter the credential again) and call again.",
|
|
436
|
+
},
|
|
437
|
+
{
|
|
438
|
+
code: "platform.secret_record_web_only",
|
|
439
|
+
next: "Tell the person to enter the credential on the connector's web page (Connectors).",
|
|
440
|
+
},
|
|
441
|
+
],
|
|
442
|
+
precheck: async (i) => {
|
|
443
|
+
const auth = i.auth;
|
|
444
|
+
const client = clientProblem(auth, i.client, "This connector");
|
|
445
|
+
if (client !== null)
|
|
446
|
+
return { ok: false, code: "validation_failed", message: client };
|
|
447
|
+
return webOnly(headersWebOnly(auth, "This connector"));
|
|
448
|
+
},
|
|
449
|
+
personFields: async (i) => ({
|
|
450
|
+
target: connectorTarget(i.name, i.auth),
|
|
451
|
+
fields: connectorPersonFields(i.auth, new Set()),
|
|
452
|
+
}),
|
|
453
|
+
summary: (i, ctx) => {
|
|
454
|
+
const e = entersText(ctx);
|
|
455
|
+
return {
|
|
456
|
+
zh: `创建连接器「${named(i.name)}」(${named(i.connector)},认证 ${i.auth.type})${e.zh}`,
|
|
457
|
+
en: `Create connector "${named(i.name)}" (${named(i.connector)}, auth ${i.auth.type})${e.en}`,
|
|
458
|
+
};
|
|
459
|
+
},
|
|
460
|
+
run: async (input, ctx) => {
|
|
461
|
+
const { askPerson: _ask, client, ...body } = input;
|
|
462
|
+
const auth = body.auth;
|
|
463
|
+
const r = await withPersonInputs("connectors.create", ctx, (entered, auditDetail) => {
|
|
464
|
+
const credential = connectorCredential(auth, entered, client?.clientId);
|
|
465
|
+
return this.connectors.create(ctx.orgId, ctx.actorAccountId, { ...body, auth, ...(credential !== undefined && { credential }) }, undefined, auditDetail);
|
|
466
|
+
});
|
|
467
|
+
return { connector: detail(r.connector), issues: r.issues };
|
|
468
|
+
},
|
|
469
|
+
}),
|
|
470
|
+
defineOperation({
|
|
471
|
+
id: "connectors.update",
|
|
472
|
+
description: "Edit a connector (org admins): rename it, switch it off or on (status), or use an org-credential connector that declares git hosts for git in sandboxes (useForGit; pushes are then the bot's). Its endpoint and credential are not edited here (credentials: connectors.set-org-credential); per-tool state and default policies stay on the connector's web page.",
|
|
473
|
+
input: UpdateInput,
|
|
474
|
+
example: { connectorId: EXAMPLE_ID, name: "Docs (staging)" },
|
|
475
|
+
authz: { orgAction: "connectors.manage" },
|
|
476
|
+
mirrors: ["PATCH /api/v1/orgs/:orgId/connectors/:connectorId"],
|
|
477
|
+
// per-tool policies decide what agents may call without asking (ruling R4)
|
|
478
|
+
omits: ["tools", "allowUnannotated"],
|
|
479
|
+
confirm: "org",
|
|
480
|
+
errors: [
|
|
481
|
+
{ code: "connector.not_found", next: "Check the connector id with connectors.list." },
|
|
482
|
+
{
|
|
483
|
+
code: "validation_failed",
|
|
484
|
+
next: "The error's details name the fields; correct the params (or have the person enter the credential again) and call again.",
|
|
485
|
+
},
|
|
486
|
+
],
|
|
487
|
+
precheck: (i, ctx) => precheckBy(() => this.connectors.get(ctx.orgId, i.connectorId, ctx.actorAccountId)),
|
|
488
|
+
summary: async (i, ctx) => {
|
|
489
|
+
const n = await this.connectorName(ctx, i.connectorId);
|
|
490
|
+
const zh = [];
|
|
491
|
+
const en = [];
|
|
492
|
+
if (i.name !== undefined) {
|
|
493
|
+
zh.push(`改名为「${named(i.name)}」`);
|
|
494
|
+
en.push(`rename it to "${named(i.name)}"`);
|
|
495
|
+
}
|
|
496
|
+
if (i.status !== undefined) {
|
|
497
|
+
zh.push(i.status === "active" ? "启用" : "停用");
|
|
498
|
+
en.push(i.status === "active" ? "switch it on" : "switch it off");
|
|
499
|
+
}
|
|
500
|
+
if (i.useForGit !== undefined) {
|
|
501
|
+
zh.push(i.useForGit ? "用于沙箱中的 git" : "不再用于沙箱中的 git");
|
|
502
|
+
en.push(i.useForGit ? "use it for git in sandboxes" : "stop using it for git");
|
|
503
|
+
}
|
|
504
|
+
return {
|
|
505
|
+
zh: `修改连接器「${n}」:${zh.join(",") || "不改动"}`,
|
|
506
|
+
en: `Edit connector "${n}": ${en.join(", ") || "no change"}`,
|
|
507
|
+
};
|
|
508
|
+
},
|
|
509
|
+
run: async (input, ctx) => {
|
|
510
|
+
const { connectorId, ...patch } = input;
|
|
511
|
+
return {
|
|
512
|
+
connector: detail(await this.connectors.update(ctx.orgId, connectorId, ctx.actorAccountId, patch, undefined, viaAgent("connectors.update", ctx))),
|
|
513
|
+
};
|
|
514
|
+
},
|
|
515
|
+
}),
|
|
516
|
+
defineOperation({
|
|
517
|
+
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.",
|
|
519
|
+
input: z
|
|
520
|
+
.object({
|
|
521
|
+
connectorId: ConnectorId,
|
|
522
|
+
client: ClientParam.optional(),
|
|
523
|
+
askPerson: personFieldParams.askPerson,
|
|
524
|
+
})
|
|
525
|
+
.strict(),
|
|
526
|
+
example: { connectorId: EXAMPLE_ID, askPerson: ["credential.token"] },
|
|
527
|
+
authz: { orgAction: "connectors.manage" },
|
|
528
|
+
mirrors: ["PUT /api/v1/orgs/:orgId/connectors/:connectorId/credentials/org"],
|
|
529
|
+
extras: ["client", "askPerson"],
|
|
530
|
+
confirm: "org",
|
|
531
|
+
errors: [
|
|
532
|
+
{ code: "connector.not_found", next: "Check the connector id with connectors.list." },
|
|
533
|
+
{
|
|
534
|
+
code: "connector.connect_failed",
|
|
535
|
+
next: "The connector's server could not be reached or refused the credential or OAuth client (the error says which); check the endpoint with connectors.preview, then call again so the person enters the credential anew.",
|
|
536
|
+
},
|
|
537
|
+
{
|
|
538
|
+
code: "validation_failed",
|
|
539
|
+
next: "The error's details name the fields; correct the params (or have the person enter the credential again) and call again.",
|
|
540
|
+
},
|
|
541
|
+
{
|
|
542
|
+
code: "platform.secret_record_web_only",
|
|
543
|
+
next: "Tell the person to enter the credential on the connector's web page (Connectors).",
|
|
544
|
+
},
|
|
545
|
+
],
|
|
546
|
+
precheck: async (i, ctx) => {
|
|
547
|
+
const c = await this.connectors.get(ctx.orgId, i.connectorId, ctx.actorAccountId);
|
|
548
|
+
const refuse = (message) => ({
|
|
549
|
+
ok: false,
|
|
550
|
+
code: "validation_failed",
|
|
551
|
+
message,
|
|
552
|
+
});
|
|
553
|
+
const a = c.auth;
|
|
554
|
+
if (a.type === "none")
|
|
555
|
+
return refuse("This connector uses no credential");
|
|
556
|
+
if (a.type === "oauth_code" && a.client !== "manual") {
|
|
557
|
+
return refuse("The OAuth client of this connector was registered automatically and cannot be replaced");
|
|
558
|
+
}
|
|
559
|
+
const client = clientProblem(a, i.client, `Connector ${named(c.name)}`);
|
|
560
|
+
if (client !== null)
|
|
561
|
+
return refuse(client);
|
|
562
|
+
if (a.type !== "oauth_code" && a.type !== "oauth_client" && a.ownership === "personal") {
|
|
563
|
+
return refuse("This connector uses each member's own credential, not an org one; each person sets theirs with connectors.set-my-credential");
|
|
564
|
+
}
|
|
565
|
+
return webOnly(headersWebOnly(a, `Connector ${named(c.name)}`));
|
|
566
|
+
},
|
|
567
|
+
personFields: async (i, ctx) => {
|
|
568
|
+
const c = await this.connectors.get(ctx.orgId, i.connectorId, ctx.actorAccountId);
|
|
569
|
+
return {
|
|
570
|
+
target: connectorTarget(c.name, c.auth),
|
|
571
|
+
fields: connectorPersonFields(c.auth, new Set()),
|
|
572
|
+
};
|
|
573
|
+
},
|
|
574
|
+
summary: async (i, ctx) => {
|
|
575
|
+
const n = await this.connectorName(ctx, i.connectorId);
|
|
576
|
+
const e = entersText(ctx);
|
|
577
|
+
return {
|
|
578
|
+
zh: `替换连接器「${n}」的组织凭据${e.zh}`,
|
|
579
|
+
en: `Replace the org credential of connector "${n}"${e.en}`,
|
|
580
|
+
};
|
|
581
|
+
},
|
|
582
|
+
run: async (input, ctx) => {
|
|
583
|
+
const c = await this.connectors.get(ctx.orgId, input.connectorId, ctx.actorAccountId);
|
|
584
|
+
await withPersonInputs("connectors.set-org-credential", ctx, (entered, auditDetail) => this.connectors.setCredential(ctx.orgId, input.connectorId, ctx.actorAccountId, "org", connectorCredential(c.auth, entered, input.client?.clientId), undefined, auditDetail));
|
|
585
|
+
return {
|
|
586
|
+
connector: detail(await this.connectors.get(ctx.orgId, input.connectorId, ctx.actorAccountId)),
|
|
587
|
+
};
|
|
588
|
+
},
|
|
589
|
+
}),
|
|
590
|
+
defineOperation({
|
|
591
|
+
id: "connectors.set-my-credential",
|
|
592
|
+
description: "Set your own credential for a connector that uses each member's own credential: you enter it on the confirmation card (bearer and api_key: credential.token; basic: credential.username and credential.password). An OAuth connector is connected with connectors.connect instead (it shows the person a Connect button). Every field of the credential is asked.",
|
|
593
|
+
input: z
|
|
594
|
+
.object({ connectorId: ConnectorId, askPerson: personFieldParams.askPerson })
|
|
595
|
+
.strict(),
|
|
596
|
+
example: { connectorId: EXAMPLE_ID, askPerson: ["credential.token"] },
|
|
597
|
+
authz: { orgAction: "connectors.use" },
|
|
598
|
+
mirrors: ["PUT /api/v1/orgs/:orgId/connectors/:connectorId/credentials/me"],
|
|
599
|
+
extras: ["askPerson"],
|
|
600
|
+
confirm: "personal",
|
|
601
|
+
rememberable: false,
|
|
602
|
+
errors: [
|
|
603
|
+
{ code: "connector.not_found", next: "Check the connector id with connectors.list." },
|
|
604
|
+
{
|
|
605
|
+
code: "validation_failed",
|
|
606
|
+
next: "The error's details name the fields; correct the params (or have the person enter the credential again) and call again.",
|
|
607
|
+
},
|
|
608
|
+
{
|
|
609
|
+
code: "platform.secret_record_web_only",
|
|
610
|
+
next: "Tell the person to enter the credential on the connector's web page (Connectors).",
|
|
611
|
+
},
|
|
612
|
+
],
|
|
613
|
+
precheck: async (i, ctx) => {
|
|
614
|
+
const c = await this.connectors.get(ctx.orgId, i.connectorId, ctx.actorAccountId);
|
|
615
|
+
if (c.auth.type === "none" || c.auth.ownership === "org") {
|
|
616
|
+
return {
|
|
617
|
+
ok: false,
|
|
618
|
+
code: "validation_failed",
|
|
619
|
+
message: c.auth.type === "none"
|
|
620
|
+
? "This connector uses no credential"
|
|
621
|
+
: "This connector uses one org credential, not each member's own; an org admin sets it with connectors.set-org-credential",
|
|
622
|
+
};
|
|
623
|
+
}
|
|
624
|
+
if (c.auth.type === "oauth_code") {
|
|
625
|
+
return {
|
|
626
|
+
ok: false,
|
|
627
|
+
code: "validation_failed",
|
|
628
|
+
message: "This connector connects each person's account through OAuth: call connectors.connect, which shows the person a Connect button",
|
|
629
|
+
};
|
|
630
|
+
}
|
|
631
|
+
return webOnly(headersWebOnly(c.auth, `Connector ${named(c.name)}`));
|
|
632
|
+
},
|
|
633
|
+
personFields: async (i, ctx) => {
|
|
634
|
+
const c = await this.connectors.get(ctx.orgId, i.connectorId, ctx.actorAccountId);
|
|
635
|
+
return {
|
|
636
|
+
target: connectorTarget(c.name, c.auth),
|
|
637
|
+
fields: connectorPersonFields(c.auth, new Set()),
|
|
638
|
+
};
|
|
639
|
+
},
|
|
640
|
+
summary: async (i, ctx) => {
|
|
641
|
+
const n = await this.connectorName(ctx, i.connectorId);
|
|
642
|
+
const e = entersText(ctx);
|
|
643
|
+
return {
|
|
644
|
+
zh: `设置你在连接器「${n}」上的个人凭据${e.zh}`,
|
|
645
|
+
en: `Set your own credential for connector "${n}"${e.en}`,
|
|
646
|
+
};
|
|
647
|
+
},
|
|
648
|
+
run: async (input, ctx) => {
|
|
649
|
+
const c = await this.connectors.get(ctx.orgId, input.connectorId, ctx.actorAccountId);
|
|
650
|
+
await withPersonInputs("connectors.set-my-credential", ctx, (entered, auditDetail) => this.connectors.setCredential(ctx.orgId, input.connectorId, ctx.actorAccountId, "personal", connectorCredential(c.auth, entered, undefined), undefined, auditDetail));
|
|
651
|
+
return {
|
|
652
|
+
connector: detail(await this.connectors.get(ctx.orgId, input.connectorId, ctx.actorAccountId)),
|
|
653
|
+
};
|
|
654
|
+
},
|
|
655
|
+
}),
|
|
656
|
+
defineOperation({
|
|
657
|
+
id: "connectors.connect",
|
|
658
|
+
description: "Connect your own account to an OAuth connector (oauth_code, each member's own account): shows the person a Connect button in the conversation; the authorization runs in their browser, never through the tool. Starts nothing by itself and returns the connector's current connection state; call connectors.get afterwards to see whether the person connected.",
|
|
659
|
+
input: z.object({ connectorId: ConnectorId }).strict(),
|
|
660
|
+
example: { connectorId: EXAMPLE_ID },
|
|
661
|
+
authz: { orgAction: "connectors.use" },
|
|
662
|
+
mirrors: ["POST /api/v1/orgs/:orgId/connectors/:connectorId/connect"],
|
|
663
|
+
// the web card starts the flow from the person's session and returns to the conversation
|
|
664
|
+
omits: ["returnTo"],
|
|
665
|
+
confirm: "read",
|
|
666
|
+
errors: [
|
|
667
|
+
{ code: "connector.not_found", next: "Check the connector id with connectors.list." },
|
|
668
|
+
{
|
|
669
|
+
code: "validation_failed",
|
|
670
|
+
next: "Only an active OAuth authorization-code connector is connected this way: a token connector takes connectors.set-my-credential, a disabled one needs an org admin to enable it.",
|
|
671
|
+
},
|
|
672
|
+
],
|
|
673
|
+
// nothing is written: the route's start (state, PKCE, the browser binding cookie) stays
|
|
674
|
+
// in the person's browser, through the web card
|
|
675
|
+
run: async (input, ctx) => {
|
|
676
|
+
const c = await this.connectors.get(ctx.orgId, input.connectorId, ctx.actorAccountId);
|
|
677
|
+
// the checks the route's start makes, so no Connect button is shown for nothing (a read
|
|
678
|
+
// runs without a card, so these are the run's own refusals rather than a precheck)
|
|
679
|
+
if (c.auth.type !== "oauth_code") {
|
|
680
|
+
throw new ApiError("validation_failed", "Request validation failed", [
|
|
681
|
+
{
|
|
682
|
+
path: "auth",
|
|
683
|
+
message: "Only OAuth authorization-code connectors are connected this way",
|
|
684
|
+
},
|
|
685
|
+
]);
|
|
686
|
+
}
|
|
687
|
+
if (c.status !== "active") {
|
|
688
|
+
throw new ApiError("validation_failed", "Request validation failed", [
|
|
689
|
+
{
|
|
690
|
+
path: "status",
|
|
691
|
+
message: "The connector is disabled; ask an administrator to enable it",
|
|
692
|
+
},
|
|
693
|
+
]);
|
|
694
|
+
}
|
|
695
|
+
return {
|
|
696
|
+
connector: { ...summary(c), credential: c.credential },
|
|
697
|
+
next: CONNECT_SHOWN_TEXT,
|
|
698
|
+
};
|
|
699
|
+
},
|
|
700
|
+
handoff: (input, result) => {
|
|
701
|
+
const name = result?.connector?.name;
|
|
702
|
+
const n = typeof name === "string" ? named(name) : input.connectorId;
|
|
703
|
+
return {
|
|
704
|
+
kind: "handoff",
|
|
705
|
+
title: { zh: `连接「${n}」`, en: `Connect ${n}` },
|
|
706
|
+
target: { type: "connect", connectorId: input.connectorId },
|
|
707
|
+
};
|
|
708
|
+
},
|
|
709
|
+
}),
|
|
710
|
+
defineOperation({
|
|
711
|
+
id: "connectors.clear-my-credential",
|
|
712
|
+
description: "Delete your own stored credential for a connector that uses each member's own credential (the org's credential is untouched). Agents then cannot use the connector as you until you set it again.",
|
|
713
|
+
input: z.object({ connectorId: ConnectorId }).strict(),
|
|
714
|
+
example: { connectorId: EXAMPLE_ID },
|
|
715
|
+
authz: { orgAction: "connectors.use" },
|
|
716
|
+
mirrors: ["DELETE /api/v1/orgs/:orgId/connectors/:connectorId/credentials/me"],
|
|
717
|
+
confirm: "personal",
|
|
718
|
+
// destructive: agents lose the connector as this person
|
|
719
|
+
rememberable: false,
|
|
720
|
+
errors: [
|
|
721
|
+
{ code: "connector.not_found", next: "Check the connector id with connectors.list." },
|
|
722
|
+
],
|
|
723
|
+
precheck: (i, ctx) => precheckBy(() => this.connectors.get(ctx.orgId, i.connectorId, ctx.actorAccountId)),
|
|
724
|
+
summary: async (i, ctx) => {
|
|
725
|
+
const n = await this.connectorName(ctx, i.connectorId);
|
|
726
|
+
return {
|
|
727
|
+
zh: `删除你在连接器「${n}」上的个人凭据`,
|
|
728
|
+
en: `Delete your own credential for connector "${n}"`,
|
|
729
|
+
};
|
|
730
|
+
},
|
|
731
|
+
run: async (input, ctx) => {
|
|
732
|
+
await this.connectors.clearMyCredential(ctx.orgId, input.connectorId, ctx.actorAccountId, undefined, viaAgent("connectors.clear-my-credential", ctx));
|
|
733
|
+
return { id: input.connectorId, credentialCleared: true };
|
|
734
|
+
},
|
|
735
|
+
}),
|
|
736
|
+
defineOperation({
|
|
737
|
+
id: "connectors.add-from-template",
|
|
738
|
+
description: "Create one more connector from a platform connector template that is on in the org (org admins; connectors.templates lists them): an optional name and slug (defaults: the first free ones), the endpoint fields the template lets the org edit, and for an OAuth template the client id in client. The credential is never a param: the person enters it on the confirmation card (credential.token; credential.username and credential.password; client.clientSecret). Required credential fields are asked even when not listed in askPerson.",
|
|
739
|
+
input: FromTemplateInput,
|
|
740
|
+
example: {
|
|
741
|
+
templateId: "3f1c2a9e-5b7d-4e21-9c0a-1d2e3f4a5b6c",
|
|
742
|
+
name: "GitHub (ops)",
|
|
743
|
+
askPerson: ["credential.token"],
|
|
744
|
+
},
|
|
745
|
+
authz: { orgAction: "connectors.manage" },
|
|
746
|
+
mirrors: ["POST /api/v1/orgs/:orgId/connector-templates/:templateId/connectors"],
|
|
747
|
+
// the route's config is flattened into slug, endpoint and client; its secrets are person fields
|
|
748
|
+
omits: ["config"],
|
|
749
|
+
extras: ["slug", "endpoint", "client", "askPerson"],
|
|
750
|
+
confirm: "org",
|
|
751
|
+
errors: [
|
|
752
|
+
{
|
|
753
|
+
code: "component.not_found",
|
|
754
|
+
next: "The template is not available in this org; list the templates with connectors.templates.",
|
|
755
|
+
},
|
|
756
|
+
{
|
|
757
|
+
code: "component.off",
|
|
758
|
+
next: "The template (or its plugin) is off in this org; switch it on first (plugins.set-enabled for its plugin, or components.set-enabled for the template).",
|
|
759
|
+
},
|
|
760
|
+
{
|
|
761
|
+
code: "connector.slug_taken",
|
|
762
|
+
next: "Another connector of the org has this slug; pass another slug or leave it out.",
|
|
763
|
+
},
|
|
764
|
+
{
|
|
765
|
+
code: "connector.connect_failed",
|
|
766
|
+
next: "The connector's server could not be reached or refused the credential or OAuth client (the error says which); check the endpoint with connectors.preview, then call again so the person enters the credential anew.",
|
|
767
|
+
},
|
|
768
|
+
{
|
|
769
|
+
code: "validation_failed",
|
|
770
|
+
next: "The error's details name the fields; correct the params (or have the person enter the credential again) and call again.",
|
|
771
|
+
},
|
|
772
|
+
{
|
|
773
|
+
code: "platform.secret_record_web_only",
|
|
774
|
+
next: "Tell the person to enter the credential on the connector's web page (Connectors).",
|
|
775
|
+
},
|
|
776
|
+
],
|
|
777
|
+
precheck: async (i, ctx) => {
|
|
778
|
+
const t = await this.template(ctx.orgId, i.templateId);
|
|
779
|
+
const where = `Connector template ${named(t.name)}`;
|
|
780
|
+
const client = clientProblem(t.auth, i.client, where);
|
|
781
|
+
if (client !== null)
|
|
782
|
+
return { ok: false, code: "validation_failed", message: client };
|
|
783
|
+
return webOnly(headersWebOnly(t.auth, where));
|
|
784
|
+
},
|
|
785
|
+
personFields: async (i, ctx) => {
|
|
786
|
+
const t = await this.template(ctx.orgId, i.templateId);
|
|
787
|
+
return {
|
|
788
|
+
// the template's own name: the model's name for the new connector is in the summary
|
|
789
|
+
target: connectorTarget(t.name, t.auth),
|
|
790
|
+
fields: connectorPersonFields(t.auth, new Set()),
|
|
791
|
+
};
|
|
792
|
+
},
|
|
793
|
+
summary: async (i, ctx) => {
|
|
794
|
+
const t = await this.template(ctx.orgId, i.templateId);
|
|
795
|
+
const e = entersText(ctx);
|
|
796
|
+
const name = i.name === undefined ? "" : `「${named(i.name)}」`;
|
|
797
|
+
return {
|
|
798
|
+
zh: `从连接器模板「${named(t.zh)}」新建连接器${name}${e.zh}`,
|
|
799
|
+
en: `Create a connector${i.name === undefined ? "" : ` "${named(i.name)}"`} from the connector template "${named(t.name)}"${e.en}`,
|
|
800
|
+
};
|
|
801
|
+
},
|
|
802
|
+
run: async (input, ctx) => {
|
|
803
|
+
const t = await this.template(ctx.orgId, input.templateId);
|
|
804
|
+
const r = await withPersonInputs("connectors.add-from-template", ctx, (entered, auditDetail) => {
|
|
805
|
+
const value = connectorCredential(t.auth, entered, input.client?.clientId);
|
|
806
|
+
const oauth = t.auth.type === "oauth_client" || t.auth.type === "oauth_code";
|
|
807
|
+
return this.installer.addTemplateConnector(ctx.orgId, ctx.actorAccountId, input.templateId, {
|
|
808
|
+
...(input.name !== undefined && { name: input.name }),
|
|
809
|
+
config: {
|
|
810
|
+
...(input.slug !== undefined && { slug: input.slug }),
|
|
811
|
+
...(input.endpoint !== undefined && { endpoint: input.endpoint }),
|
|
812
|
+
...(value !== undefined &&
|
|
813
|
+
(oauth
|
|
814
|
+
? { client: value }
|
|
815
|
+
: { credential: value })),
|
|
816
|
+
},
|
|
817
|
+
}, { auditDetail });
|
|
818
|
+
});
|
|
819
|
+
return { connector: detail(r.connector), issues: r.issues };
|
|
820
|
+
},
|
|
821
|
+
}),
|
|
822
|
+
defineOperation({
|
|
823
|
+
id: "connectors.guide-ack",
|
|
824
|
+
description: "Record that the person updated the app on the third-party platform after a connector template's setup guide changed (org admins): pass the guide hash connectors.get shows under setupGuide. The card states exactly that, and the person confirms it; a guide that changed again since is refused.",
|
|
825
|
+
input: z.object({ connectorId: ConnectorId, ...ConnectorGuideAckSchema.shape }).strict(),
|
|
826
|
+
example: {
|
|
827
|
+
connectorId: EXAMPLE_ID,
|
|
828
|
+
hash: "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
|
|
829
|
+
},
|
|
830
|
+
authz: { orgAction: "connectors.manage" },
|
|
831
|
+
mirrors: ["POST /api/v1/orgs/:orgId/connectors/:connectorId/guide-ack"],
|
|
832
|
+
confirm: "personal",
|
|
833
|
+
// a person's attestation: confirmed each time, never remembered
|
|
834
|
+
rememberable: false,
|
|
835
|
+
errors: [
|
|
836
|
+
{
|
|
837
|
+
code: "connector.not_found",
|
|
838
|
+
next: "Check the connector id with connectors.list.",
|
|
839
|
+
},
|
|
840
|
+
{
|
|
841
|
+
code: "catalog.guide_not_found",
|
|
842
|
+
next: "The connector has no setup guide from a template; there is nothing to acknowledge.",
|
|
843
|
+
},
|
|
844
|
+
{
|
|
845
|
+
code: "connector.guide_changed",
|
|
846
|
+
next: "The setup guide changed again: read it with setup.read, walk the person through it, then call again with the hash connectors.get shows now.",
|
|
847
|
+
},
|
|
848
|
+
],
|
|
849
|
+
precheck: async (i, ctx) => {
|
|
850
|
+
let hash = "";
|
|
851
|
+
const r = await precheckBy(async () => {
|
|
852
|
+
hash = (await this.connectors.currentGuide(await this.org(ctx), i.connectorId)).hash;
|
|
853
|
+
});
|
|
854
|
+
if (!r.ok)
|
|
855
|
+
return r;
|
|
856
|
+
return hash === i.hash
|
|
857
|
+
? { ok: true }
|
|
858
|
+
: {
|
|
859
|
+
ok: false,
|
|
860
|
+
code: "connector.guide_changed",
|
|
861
|
+
message: "The connector template's setup guide changed since it was shown",
|
|
862
|
+
};
|
|
863
|
+
},
|
|
864
|
+
summary: async (i, ctx) => {
|
|
865
|
+
const n = await this.connectorName(ctx, i.connectorId);
|
|
866
|
+
return {
|
|
867
|
+
zh: `我已按连接器「${n}」更新后的设置指南,在第三方平台上更新了应用`,
|
|
868
|
+
en: `I updated the app on the third-party platform after the setup guide of connector "${n}" changed`,
|
|
869
|
+
};
|
|
870
|
+
},
|
|
871
|
+
run: async (input, ctx) => ({
|
|
872
|
+
connector: detail(await this.connectors.ackGuide(await this.org(ctx), input.connectorId, input.hash, ctx.actorAccountId, undefined, viaAgent("connectors.guide-ack", ctx))),
|
|
873
|
+
}),
|
|
874
|
+
}),
|
|
226
875
|
]);
|
|
227
876
|
}
|
|
228
877
|
};
|
|
@@ -230,6 +879,8 @@ ConnectorsOperations = __decorate([
|
|
|
230
879
|
Injectable(),
|
|
231
880
|
__param(0, Inject(PlatformOperations)),
|
|
232
881
|
__param(1, Inject(ConnectorsService)),
|
|
233
|
-
__param(2, Inject(ComponentScopeService))
|
|
882
|
+
__param(2, Inject(ComponentScopeService)),
|
|
883
|
+
__param(3, Inject(PluginInstaller)),
|
|
884
|
+
__param(4, Inject(KernelDb))
|
|
234
885
|
], ConnectorsOperations);
|
|
235
886
|
export { ConnectorsOperations };
|