@capybara-hq/kernel 0.1.0-rc.140 → 0.1.0-rc.141
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/agents/models.controller.d.ts +9 -2
- package/dist/agents/models.controller.js +35 -4
- package/dist/catalog/catalog-scope.service.js +3 -0
- package/dist/catalog/catalog.module.js +8 -0
- package/dist/catalog/catalog.service.d.ts +2 -2
- package/dist/catalog/catalog.service.js +3 -3
- package/dist/catalog/component-scope.controller.d.ts +2 -1
- package/dist/catalog/component-scope.controller.js +5 -2
- package/dist/catalog/component-scope.service.d.ts +16 -0
- package/dist/catalog/component-scope.service.js +21 -1
- package/dist/catalog/enable-decision.d.ts +34 -0
- package/dist/catalog/enable-decision.js +17 -0
- package/dist/catalog/enable-requests.d.ts +186 -0
- package/dist/catalog/enable-requests.js +767 -0
- package/dist/catalog/enable-targets.d.ts +63 -0
- package/dist/catalog/enable-targets.js +94 -0
- package/dist/catalog/org-catalog.controller.d.ts +11 -3
- package/dist/catalog/org-catalog.controller.js +28 -5
- package/dist/catalog/org-catalog.schemas.d.ts +38 -0
- package/dist/catalog/org-catalog.schemas.js +31 -0
- package/dist/catalog/org-catalog.service.js +1 -1
- package/dist/catalog/org-extension.controller.d.ts +1 -1
- package/dist/catalog/owned-items.js +6 -1
- package/dist/catalog/plugin-install.js +7 -2
- package/dist/catalog/plugin-upgrade.js +3 -0
- package/dist/catalog/request-rules.d.ts +7 -5
- package/dist/catalog/request-rules.js +53 -14
- package/dist/catalog/requests.service.d.ts +137 -4
- package/dist/catalog/requests.service.js +574 -28
- package/dist/catalog/scope-writer.d.ts +20 -3
- package/dist/catalog/scope-writer.js +32 -3
- package/dist/ctx/bus.js +3 -2
- package/dist/db/kernel-schema.d.ts +3 -2
- package/dist/errors.d.ts +7 -0
- package/dist/errors.js +7 -0
- package/dist/extensions/admin-ops.js +2 -0
- package/dist/extensions/admin-view.js +2 -1
- package/dist/extensions/host.js +1 -1
- package/dist/extensions/org-config.d.ts +8 -0
- package/dist/extensions/org-config.js +20 -5
- package/dist/extensions/permission-view.d.ts +7 -0
- package/dist/extensions/plugin-guides.d.ts +1 -1
- package/dist/extensions/plugin-guides.js +1 -1
- package/dist/extensions/plugin-items.d.ts +8 -0
- package/dist/extensions/plugin-items.js +8 -0
- package/dist/infra/queue/run-job.js +3 -1
- package/dist/models/enablement.d.ts +12 -0
- package/dist/models/enablement.js +32 -0
- package/dist/platform/ops/admin.ops.js +2 -2
- package/dist/platform/ops/catalog-admin.ops.js +1 -1
- package/dist/platform/ops/extensions-admin.ops.js +17 -9
- package/dist/platform/ops/extensions.ops.js +6 -3
- package/dist/platform/ops/org-plugins.ops.js +1 -1
- package/dist/platform/ops/plugins.ops.js +1 -1
- package/dist/platform/ops/requests.ops.js +55 -1
- package/dist/platform/ops/unavailable.js +2 -2
- package/dist/tools/builtins/sandbox/common.d.ts +3 -3
- package/dist/tools/builtins/sandbox/common.js +3 -3
- package/dist/tools/connectors.controller.d.ts +8 -1
- package/dist/tools/connectors.controller.js +14 -1
- package/dist/tools/connectors.service.d.ts +7 -0
- package/dist/tools/connectors.service.js +30 -0
- package/package.json +1 -1
- package/src/migrations/0233_enable_request_targets.sql +64 -0
|
@@ -35,7 +35,7 @@ const Force = OrgExtensionPut.shape.force;
|
|
|
35
35
|
/** The next step of an extension that needs its org config. */
|
|
36
36
|
const NEEDS_ORG_CONFIG = {
|
|
37
37
|
orgAdmin: "Read what is missing with extensions.org-config, then fill in the org's own copy of the overridable fields with extensions.save-org-config; the person enters secrets in a secure input request.",
|
|
38
|
-
member: "Ask an org admin to fill in its org config
|
|
38
|
+
member: "Ask an org admin to fill in its org config in Plugins.",
|
|
39
39
|
};
|
|
40
40
|
/** What `extensions.set-enabled` adds when the extension is on but its org config is not valid. */
|
|
41
41
|
const CONFIG_NEEDED = `The extension is on, but has no valid config for this org yet and gets no calls until it does: ${NEEDS_ORG_CONFIG.orgAdmin} If only platform-only fields are missing, the super admin must set them.`;
|
|
@@ -67,7 +67,7 @@ export function copyPersonFields(v) {
|
|
|
67
67
|
const notOurs = found.fields.filter((f) => !overridable.has(top(f.path))).map((f) => f.path);
|
|
68
68
|
return withUnaddressed({ fields, recordOnly: [...found.recordOnly, ...notOurs] }, secrets.map((f) => f.path));
|
|
69
69
|
}
|
|
70
|
-
/** An extension's state in the org, as the
|
|
70
|
+
/** An extension's state in the org, as the Plugins surface's Extension tab shows it. */
|
|
71
71
|
function stateOf(v) {
|
|
72
72
|
if (!v.available)
|
|
73
73
|
return "unavailable";
|
|
@@ -139,7 +139,7 @@ let ExtensionsOperations = class ExtensionsOperations {
|
|
|
139
139
|
this.registry.register([
|
|
140
140
|
defineOperation({
|
|
141
141
|
id: "extensions.list",
|
|
142
|
-
description: "List this org's extensions, as
|
|
142
|
+
description: "List this org's extensions, as the org admin's Plugins surface does (an extension whose plugin is not installed in the org is left out until plugins.set-enabled installs it), one compact row each: the state here (on, off, needs_config: its config for this org is not valid, unavailable: it cannot run on the platform), why an unavailable one cannot be used (reason) and your next step (next), whether it is available on the platform, the extension points it provides and the plugin that brings it (catalogItemId), plus canonicalItemId (the one plugin whose page manages it, null when it is declared in the startup configuration or several plugins ship it) and sourceItemIds (every plugin of the org's that ships it). State only: an org admin reads the config with extensions.org-config and sets the org's copy with extensions.save-org-config. Pages by 50: pass the returned next as params.cursor.",
|
|
143
143
|
input: z.object({ cursor: Cursor.optional() }).strict(),
|
|
144
144
|
example: {},
|
|
145
145
|
authz: { orgAction: "org.extensions.read" },
|
|
@@ -166,6 +166,9 @@ let ExtensionsOperations = class ExtensionsOperations {
|
|
|
166
166
|
available: v.available,
|
|
167
167
|
provides: providesOf(v),
|
|
168
168
|
catalogItemId: v.catalogItem?.itemId ?? null,
|
|
169
|
+
// the plugin whose page manages it (its one source), and every source plugin
|
|
170
|
+
canonicalItemId: v.canonicalItemId,
|
|
171
|
+
sourceItemIds: v.sourceItemIds,
|
|
169
172
|
};
|
|
170
173
|
}), startOf(input.cursor), 50);
|
|
171
174
|
},
|
|
@@ -378,7 +378,7 @@ let OrgPluginsOperations = class OrgPluginsOperations {
|
|
|
378
378
|
}),
|
|
379
379
|
defineOperation({
|
|
380
380
|
id: "plugins.apply-appearance",
|
|
381
|
-
description: "Apply a plugin's suggested appearance in this org (org admins; the
|
|
381
|
+
description: "Apply a plugin's suggested appearance in this org (org admins; the \"Apply this plugin's appearance\" action on the plugin's Extension tab in Plugins), for a plugin whose extension is on here: in one step, its theme becomes the org's default theme (whether members may pick their own stays as it is) and each component it suggests replaces the built-in block of its slot (shell.brand, conversation.empty, conversation.composer.frame) in the org's arrangement. The card shows exactly what changes; a theme that is not on in the org refuses the whole call, a component that is not available is skipped.",
|
|
382
382
|
input: z.object({ extension: OrgExtensionParams.shape.extension }).strict(),
|
|
383
383
|
example: { extension: "theme-cyberpunk" },
|
|
384
384
|
authz: { orgAction: "org.update" },
|
|
@@ -248,7 +248,7 @@ let PluginsOperations = class PluginsOperations {
|
|
|
248
248
|
{
|
|
249
249
|
code: "catalog.not_deployed",
|
|
250
250
|
next: {
|
|
251
|
-
superAdmin: "Open the
|
|
251
|
+
superAdmin: "Open the plugin's Extension tab in the admin console's Plugins to see why its extension is not running (deployment config, permission approval, disabled, or failed to load); fix it, then call again.",
|
|
252
252
|
orgAdmin: "Only the super admin can make the plugin's extension run; plugins.get shows the reason. There is no request operation for this (requests.create covers enabling and access only), so tell the super admin directly.",
|
|
253
253
|
member: "Ask an org admin: the super admin must set up the plugin's extension on the platform first.",
|
|
254
254
|
},
|
|
@@ -9,7 +9,7 @@ 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 { CatalogItemPathParams, CatalogMarketplaceRequestBody, CatalogRequestBody, CatalogRequestsListQuery, } from "../../catalog/org-catalog.schemas.js";
|
|
12
|
+
import { CatalogItemPathParams, CatalogMarketplaceRequestBody, CatalogRequestBody, CatalogRequestsListQuery, EnableRequestBody, } from "../../catalog/org-catalog.schemas.js";
|
|
13
13
|
import { CatalogRequestsService } from "../../catalog/requests.service.js";
|
|
14
14
|
import { defineOperation } from "../operation.js";
|
|
15
15
|
import { PlatformOperations } from "../registry.js";
|
|
@@ -25,6 +25,7 @@ const view = (r) => ({
|
|
|
25
25
|
entry: r.entry,
|
|
26
26
|
agent: r.agent,
|
|
27
27
|
network: r.network,
|
|
28
|
+
enable: r.enable,
|
|
28
29
|
note: r.note,
|
|
29
30
|
reason: r.reason,
|
|
30
31
|
decidedAt: r.decidedAt,
|
|
@@ -118,6 +119,59 @@ let RequestsOperations = class RequestsOperations {
|
|
|
118
119
|
request: view(await this.requests.requestItem(ctx.orgId, ctx.actorAccountId, input.itemId, { kind: input.kind, ...(input.note !== undefined && { note: input.note }) }, { auditDetail: viaAgent("requests.create", ctx) })),
|
|
119
120
|
}),
|
|
120
121
|
}),
|
|
122
|
+
defineOperation({
|
|
123
|
+
id: "plugins.request-enable",
|
|
124
|
+
description: 'Ask the org admins to turn on what a capability needs in this org (members and up): pass the subject the person pointed at (kind plugin with the catalog item id, extension with its name, skill / agent_template / connector_template with the component id, connector with its id, or model with the id ["<provider>","<model>"]) and an optional note. The platform finds the switch to turn on (the plugin, the extension, the component, the model or the connector) and files one request for it; when the org has a pending request for that switch already, that one is returned.',
|
|
125
|
+
input: EnableRequestBody,
|
|
126
|
+
example: {
|
|
127
|
+
subject: { kind: "model", id: '["model-fake","fake-large"]' },
|
|
128
|
+
note: "For the weekly report.",
|
|
129
|
+
},
|
|
130
|
+
authz: { orgAction: "catalog.request" },
|
|
131
|
+
mirrors: ["POST /api/v1/orgs/:orgId/catalog-requests/enable"],
|
|
132
|
+
confirm: "personal",
|
|
133
|
+
errors: [
|
|
134
|
+
{
|
|
135
|
+
code: "catalog.request_invalid",
|
|
136
|
+
next: "It is already on, built in, or not offered to this org; nothing an org admin can turn on. Tell the person what you found.",
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
code: "catalog.item_disabled",
|
|
140
|
+
next: "The super admin disabled it on the platform; only the super admin can change that.",
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
code: "catalog.item_not_found",
|
|
144
|
+
next: "This org does not see that plugin. Check the id with plugins.list.",
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
code: "extension.not_found",
|
|
148
|
+
next: "This org does not see that extension. Check the name with extensions.list.",
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
code: "connector.not_found",
|
|
152
|
+
next: "No such connector in this org. Check the id with connectors.list.",
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
code: "component.not_found",
|
|
156
|
+
next: "This org does not see that component. Check the id with the component lists.",
|
|
157
|
+
},
|
|
158
|
+
{
|
|
159
|
+
code: "model.not_found",
|
|
160
|
+
next: 'This org does not see that model. Use ["<provider>","<model>"] as models.list names them.',
|
|
161
|
+
},
|
|
162
|
+
],
|
|
163
|
+
summary: (i) => ({
|
|
164
|
+
zh: `申请在本组织启用 ${i.subject.kind} ${i.subject.id}`,
|
|
165
|
+
en: `Ask the org admins to turn on ${i.subject.kind} ${i.subject.id}`,
|
|
166
|
+
}),
|
|
167
|
+
run: async (input, ctx) => {
|
|
168
|
+
const { request, created } = await this.requests.requestEnable(ctx.orgId, ctx.actorAccountId, {
|
|
169
|
+
subject: input.subject,
|
|
170
|
+
...(input.note !== undefined && { note: input.note }),
|
|
171
|
+
}, { auditDetail: viaAgent("plugins.request-enable", ctx) });
|
|
172
|
+
return { request: view(request), created };
|
|
173
|
+
},
|
|
174
|
+
}),
|
|
121
175
|
defineOperation({
|
|
122
176
|
id: "requests.create-import",
|
|
123
177
|
description: "Ask the super admin to import a plugin from a marketplace into the platform catalog (org admins, when the platform lets orgs browse): the marketplaceId, name and version from marketplaces.entries, and an optional note.",
|
|
@@ -23,7 +23,7 @@ const TELL_SUPER_ADMIN = "There is no request operation for this (requests.creat
|
|
|
23
23
|
const memberNext = (name) => `Ask an org admin: the super admin must set up ${name} on the platform before anyone in the org can use it.`;
|
|
24
24
|
/** The next step for an unavailable plugin or extension, keyed by role. */
|
|
25
25
|
export function unavailableNext(reason, name) {
|
|
26
|
-
const adminPath = `Open the admin console
|
|
26
|
+
const adminPath = `Open the Extension tab of ${name} in the admin console's Plugins (/admin/plugins/extensions/${encodeURIComponent(name)} opens it)`;
|
|
27
27
|
switch (reason) {
|
|
28
28
|
case "loading":
|
|
29
29
|
case "pending_migration":
|
|
@@ -72,7 +72,7 @@ export function unavailableNext(reason, name) {
|
|
|
72
72
|
};
|
|
73
73
|
case "not_deployed":
|
|
74
74
|
return {
|
|
75
|
-
superAdmin: `Install the extension of ${name}:
|
|
75
|
+
superAdmin: `Install the extension of ${name}: import or update its plugin in the admin console under Plugins, then switch it on again.`,
|
|
76
76
|
orgAdmin: `Only the super admin can install the extension of ${name}. ${TELL_SUPER_ADMIN}`,
|
|
77
77
|
member: memberNext(name),
|
|
78
78
|
};
|
|
@@ -136,9 +136,9 @@ export declare const ENV_FILES_LOST_TEXT = "This device's files are gone. Ask th
|
|
|
136
136
|
* A provider call that never connected (refused, unknown host, unreachable network): the request
|
|
137
137
|
* did not reach the provider, so the call did nothing in the sandbox.
|
|
138
138
|
*/
|
|
139
|
-
export declare const SANDBOX_UNREACHABLE_TEXT = "The sandbox provider can't be reached (the connection failed), so this call did nothing in the sandbox; retrying won't help until a super admin checks the sandbox extension's configuration (Admin console \u2192
|
|
139
|
+
export declare const SANDBOX_UNREACHABLE_TEXT = "The sandbox provider can't be reached (the connection failed), so this call did nothing in the sandbox; retrying won't help until a super admin checks the sandbox extension's configuration (Admin console \u2192 Plugins \u2192 its Extension tab). Continue without the sandbox, or ask the person to have a super admin check it.";
|
|
140
140
|
/** A provider connection that broke during the call: the provider may have acted before it broke. */
|
|
141
|
-
export declare const SANDBOX_CONNECTION_DROPPED_TEXT = "The connection to the sandbox provider broke during this call, so it may or may not have taken effect; check the sandbox state before retrying. If it fails again, continue without the sandbox and ask the person to have a super admin check the sandbox extension's configuration (Admin console \u2192
|
|
141
|
+
export declare const SANDBOX_CONNECTION_DROPPED_TEXT = "The connection to the sandbox provider broke during this call, so it may or may not have taken effect; check the sandbox state before retrying. If it fails again, continue without the sandbox and ask the person to have a super admin check the sandbox extension's configuration (Admin console \u2192 Plugins \u2192 its Extension tab).";
|
|
142
142
|
/** A dial-in device whose machine is not connected (`device.offline`, the SDK's offline error). */
|
|
143
143
|
export declare const DEVICE_OFFLINE_TEXT = "The machine serving this device is offline. Ask the person to connect it again, or to start a new conversation on another device.";
|
|
144
144
|
/**
|
|
@@ -147,7 +147,7 @@ export declare const DEVICE_OFFLINE_TEXT = "The machine serving this device is o
|
|
|
147
147
|
*/
|
|
148
148
|
export declare const SANDBOX_OPEN_NETWORK_REFUSED_TEXT = "The cloud sandbox provider refused to give this device the open public network, so nothing ran in the sandbox and retrying won't help. Ask the person to switch this device to sandbox mode and have an org admin switch the organization's cloud network to an allowlist, or have a super admin use a sandbox provider that offers the open network. Continue without the sandbox meanwhile.";
|
|
149
149
|
/** A cloud provider failed to create the device's sandbox otherwise (`sandbox.create_failed`). */
|
|
150
|
-
export declare const SANDBOX_CREATE_FAILED_TEXT = "The cloud sandbox provider could not create this device's sandbox, so nothing ran in it. Retry once; if it fails again, continue without the sandbox and ask the person to have a super admin check the sandbox extension's settings (Admin console \u2192
|
|
150
|
+
export declare const SANDBOX_CREATE_FAILED_TEXT = "The cloud sandbox provider could not create this device's sandbox, so nothing ran in it. Retry once; if it fails again, continue without the sandbox and ask the person to have a super admin check the sandbox extension's settings (Admin console \u2192 Plugins \u2192 its Extension tab).";
|
|
151
151
|
export { ATTACHMENTS_ROOT, attachmentsDir, attachmentsRoot };
|
|
152
152
|
/** 附件文件名的上限(UTF-8 字节,常见文件系统单个文件名上限 255 字节,留出 `-N` 后缀的余量)。 */
|
|
153
153
|
export declare const ATTACHMENT_NAME_MAX_BYTES = 200;
|
|
@@ -60,9 +60,9 @@ export const ENV_FILES_LOST_TEXT = "This device's files are gone. Ask the user t
|
|
|
60
60
|
* A provider call that never connected (refused, unknown host, unreachable network): the request
|
|
61
61
|
* did not reach the provider, so the call did nothing in the sandbox.
|
|
62
62
|
*/
|
|
63
|
-
export const SANDBOX_UNREACHABLE_TEXT = "The sandbox provider can't be reached (the connection failed), so this call did nothing in the sandbox; retrying won't help until a super admin checks the sandbox extension's configuration (Admin console →
|
|
63
|
+
export const SANDBOX_UNREACHABLE_TEXT = "The sandbox provider can't be reached (the connection failed), so this call did nothing in the sandbox; retrying won't help until a super admin checks the sandbox extension's configuration (Admin console → Plugins → its Extension tab). Continue without the sandbox, or ask the person to have a super admin check it.";
|
|
64
64
|
/** A provider connection that broke during the call: the provider may have acted before it broke. */
|
|
65
|
-
export const SANDBOX_CONNECTION_DROPPED_TEXT = "The connection to the sandbox provider broke during this call, so it may or may not have taken effect; check the sandbox state before retrying. If it fails again, continue without the sandbox and ask the person to have a super admin check the sandbox extension's configuration (Admin console →
|
|
65
|
+
export const SANDBOX_CONNECTION_DROPPED_TEXT = "The connection to the sandbox provider broke during this call, so it may or may not have taken effect; check the sandbox state before retrying. If it fails again, continue without the sandbox and ask the person to have a super admin check the sandbox extension's configuration (Admin console → Plugins → its Extension tab).";
|
|
66
66
|
/** A dial-in device whose machine is not connected (`device.offline`, the SDK's offline error). */
|
|
67
67
|
export const DEVICE_OFFLINE_TEXT = "The machine serving this device is offline. Ask the person to connect it again, or to start a new conversation on another device.";
|
|
68
68
|
const DEVICE_OUTDATED_TEXT = "The machine serving this device runs an outdated device program. Ask the person to update it on that machine and connect it again.";
|
|
@@ -74,7 +74,7 @@ const deviceProtocolText = (detail) => `The machine serving this device sent an
|
|
|
74
74
|
*/
|
|
75
75
|
export const SANDBOX_OPEN_NETWORK_REFUSED_TEXT = "The cloud sandbox provider refused to give this device the open public network, so nothing ran in the sandbox and retrying won't help. Ask the person to switch this device to sandbox mode and have an org admin switch the organization's cloud network to an allowlist, or have a super admin use a sandbox provider that offers the open network. Continue without the sandbox meanwhile.";
|
|
76
76
|
/** A cloud provider failed to create the device's sandbox otherwise (`sandbox.create_failed`). */
|
|
77
|
-
export const SANDBOX_CREATE_FAILED_TEXT = "The cloud sandbox provider could not create this device's sandbox, so nothing ran in it. Retry once; if it fails again, continue without the sandbox and ask the person to have a super admin check the sandbox extension's settings (Admin console →
|
|
77
|
+
export const SANDBOX_CREATE_FAILED_TEXT = "The cloud sandbox provider could not create this device's sandbox, so nothing ran in it. Retry once; if it fails again, continue without the sandbox and ask the person to have a super admin check the sandbox extension's settings (Admin console → Plugins → its Extension tab).";
|
|
78
78
|
const LOCK_LOST_TEXT = "The sandbox operation was interrupted because the sandbox lock was lost; check the sandbox state and retry.";
|
|
79
79
|
export { ATTACHMENTS_ROOT, attachmentsDir, attachmentsRoot };
|
|
80
80
|
/** 附件文件名的上限(UTF-8 字节,常见文件系统单个文件名上限 255 字节,留出 `-N` 后缀的余量)。 */
|
|
@@ -11,6 +11,7 @@ export interface ConnectorTemplateDescription {
|
|
|
11
11
|
/** The template's Chinese text; null: `templateDescription` serves both languages. */
|
|
12
12
|
templateDescriptionZh: string | null;
|
|
13
13
|
}
|
|
14
|
+
import type { RequestableFields } from "../catalog/enable-requests.js";
|
|
14
15
|
import type { ConnectionGuideState } from "../extensions/plugin-guides.js";
|
|
15
16
|
import { PluginIcons } from "../extensions/plugin-icons.js";
|
|
16
17
|
import { type Principal } from "../identity/principal.js";
|
|
@@ -228,8 +229,14 @@ export declare class ConnectorsController {
|
|
|
228
229
|
* `connector.not_found`; no icon the reader may see -> 404 `catalog.icon_not_found`.
|
|
229
230
|
*/
|
|
230
231
|
icon(org: OrgContext, connectorId: string, reply: FastifyReply): Promise<void>;
|
|
232
|
+
/**
|
|
233
|
+
* The org's connectors. A disabled one whose owning switch the reader may ask an org admin to
|
|
234
|
+
* turn on (the connector itself, or its plugin while a plugin switch-off disabled it) carries
|
|
235
|
+
* `requestable: true` and the org's pending request (`pendingRequestId`): the connector
|
|
236
|
+
* picker's "Ask to turn on" (org-usable spec). Only active connectors are selectable.
|
|
237
|
+
*/
|
|
231
238
|
list(org: OrgContext): Promise<{
|
|
232
|
-
connectors: ConnectorPage<ConnectorSummary>[];
|
|
239
|
+
connectors: (ConnectorPage<ConnectorSummary> & Partial<RequestableFields>)[];
|
|
233
240
|
}>;
|
|
234
241
|
/** Adds the icon and the setup guide fields to connector views (one lookup each for all). */
|
|
235
242
|
private withGuides;
|
|
@@ -114,9 +114,22 @@ let ConnectorsController = class ConnectorsController {
|
|
|
114
114
|
const ref = await this.connectors.iconRef(org.orgId, connectorId);
|
|
115
115
|
await sendCatalogIcon(reply, await this.icons.readConnectorIcon(ref, orgIconScope(org)));
|
|
116
116
|
}
|
|
117
|
+
/**
|
|
118
|
+
* The org's connectors. A disabled one whose owning switch the reader may ask an org admin to
|
|
119
|
+
* turn on (the connector itself, or its plugin while a plugin switch-off disabled it) carries
|
|
120
|
+
* `requestable: true` and the org's pending request (`pendingRequestId`): the connector
|
|
121
|
+
* picker's "Ask to turn on" (org-usable spec). Only active connectors are selectable.
|
|
122
|
+
*/
|
|
117
123
|
async list(org) {
|
|
118
124
|
const list = (await this.connectors.list(org.orgId)).map((a) => forViewer(org, a));
|
|
119
|
-
|
|
125
|
+
const fields = await this.connectors.requestable(org.orgId, org.role, list.flatMap((c) => (c.status === "disabled" ? [c.id] : [])));
|
|
126
|
+
const pages = await this.withGuides(org, list);
|
|
127
|
+
return {
|
|
128
|
+
connectors: pages.map((c) => {
|
|
129
|
+
const f = fields.get(c.id);
|
|
130
|
+
return f === undefined ? c : { ...c, ...f };
|
|
131
|
+
}),
|
|
132
|
+
};
|
|
120
133
|
}
|
|
121
134
|
/** Adds the icon and the setup guide fields to connector views (one lookup each for all). */
|
|
122
135
|
async withGuides(org, views) {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type AuthHint, type ConnectorOperation, type GitSource, type ToolAnnotations } from "@capybara-hq/plugin-sdk";
|
|
2
|
+
import { type RequestableFields } from "../catalog/enable-requests.js";
|
|
2
3
|
import { type ConnectionGuideState, type GuideAck, PluginGuides } from "../extensions/plugin-guides.js";
|
|
3
4
|
import type { WriteActor } from "../identity/write-actor.js";
|
|
4
5
|
import { KernelConfigService } from "../infra/config/kernel-config.service.js";
|
|
@@ -445,6 +446,12 @@ export declare class ConnectorsService {
|
|
|
445
446
|
private ackIn;
|
|
446
447
|
/** The org's connectors that are not deleted (by creation time). */
|
|
447
448
|
list(orgId: string): Promise<ConnectorSummary[]>;
|
|
449
|
+
/**
|
|
450
|
+
* The picker projection of disabled connectors `ids` for a reader of `role` (org-usable spec
|
|
451
|
+
* "Members and guests"): the ones whose owning switch the reader may ask an org admin to turn on,
|
|
452
|
+
* with `requestable: true` and the org's pending request, by connector id.
|
|
453
|
+
*/
|
|
454
|
+
requestable(orgId: string, role: OrgRole, ids: readonly string[]): Promise<Map<string, RequestableFields>>;
|
|
448
455
|
/**
|
|
449
456
|
* Where a live connector of the org takes its icon from: its platform template and its plugin
|
|
450
457
|
* (catalog item). Unknown -> `connector.not_found`.
|
|
@@ -13,6 +13,8 @@ import { Inject, Injectable } from "@nestjs/common";
|
|
|
13
13
|
import { sql } from "kysely";
|
|
14
14
|
import { z } from "zod";
|
|
15
15
|
import { connectorTemplateState } from "../catalog/component-state.js";
|
|
16
|
+
import { cancelEnableRequestsOfConnector, requestableSubjects, settleEnableRequests, } from "../catalog/enable-requests.js";
|
|
17
|
+
import { targetKey } from "../catalog/enable-targets.js";
|
|
16
18
|
import { pluginSwitchOff } from "../catalog/plugin-connectors.js";
|
|
17
19
|
import { assertItemInstallable } from "../catalog/request-rules.js";
|
|
18
20
|
import { productName } from "../config/product-name.js";
|
|
@@ -1103,6 +1105,21 @@ let ConnectorsService = class ConnectorsService {
|
|
|
1103
1105
|
const setups = await connectorSetups(this.credentials, orgId, rows.map((r) => ({ id: r.id, auth: r.auth })));
|
|
1104
1106
|
return rows.map((r) => this.summary(r, setups.get(r.id) ?? "needs_config"));
|
|
1105
1107
|
}
|
|
1108
|
+
/**
|
|
1109
|
+
* The picker projection of disabled connectors `ids` for a reader of `role` (org-usable spec
|
|
1110
|
+
* "Members and guests"): the ones whose owning switch the reader may ask an org admin to turn on,
|
|
1111
|
+
* with `requestable: true` and the org's pending request, by connector id.
|
|
1112
|
+
*/
|
|
1113
|
+
async requestable(orgId, role, ids) {
|
|
1114
|
+
const fields = await requestableSubjects(this.db, orgId, role, ids.map((id) => ({ kind: "connector", id })));
|
|
1115
|
+
const out = new Map();
|
|
1116
|
+
for (const id of ids) {
|
|
1117
|
+
const f = fields.get(targetKey({ kind: "connector", id }));
|
|
1118
|
+
if (f !== undefined)
|
|
1119
|
+
out.set(id, f);
|
|
1120
|
+
}
|
|
1121
|
+
return out;
|
|
1122
|
+
}
|
|
1106
1123
|
/**
|
|
1107
1124
|
* Where a live connector of the org takes its icon from: its platform template and its plugin
|
|
1108
1125
|
* (catalog item). Unknown -> `connector.not_found`.
|
|
@@ -1223,6 +1240,12 @@ let ConnectorsService = class ConnectorsService {
|
|
|
1223
1240
|
.where("org_id", "=", orgId)
|
|
1224
1241
|
.execute();
|
|
1225
1242
|
}
|
|
1243
|
+
// switched back on: the org's pending enable requests for the connector are settled
|
|
1244
|
+
if (patch.status === "active" && app.status === "disabled") {
|
|
1245
|
+
await settleEnableRequests(t, orgId, { kind: "connector", id: connectorId }, actorAccountId, {
|
|
1246
|
+
...(actorTokenId !== undefined && { actorTokenId }),
|
|
1247
|
+
});
|
|
1248
|
+
}
|
|
1226
1249
|
for (const [name, change] of toolChanges) {
|
|
1227
1250
|
if (change.status === undefined)
|
|
1228
1251
|
continue;
|
|
@@ -1390,6 +1413,8 @@ let ConnectorsService = class ConnectorsService {
|
|
|
1390
1413
|
.where("org_id", "=", orgId)
|
|
1391
1414
|
.where("deleted_at", "is", null)
|
|
1392
1415
|
.execute();
|
|
1416
|
+
// its plugin is its owning switch now: a pending request for the connector is stale
|
|
1417
|
+
await cancelEnableRequestsOfConnector(this.db, orgId, connectorId, null, "target_changed");
|
|
1393
1418
|
}
|
|
1394
1419
|
/** Owe a listing before changing the row's status and legacy last-update timestamp. */
|
|
1395
1420
|
async oweStaleEndpointList(orgId, app) {
|
|
@@ -1439,6 +1464,7 @@ let ConnectorsService = class ConnectorsService {
|
|
|
1439
1464
|
.where("id", "=", connectorId)
|
|
1440
1465
|
.where("org_id", "=", orgId)
|
|
1441
1466
|
.execute();
|
|
1467
|
+
await settleEnableRequests(this.db, orgId, { kind: "connector", id: connectorId }, null);
|
|
1442
1468
|
return true;
|
|
1443
1469
|
}
|
|
1444
1470
|
/**
|
|
@@ -1463,6 +1489,9 @@ let ConnectorsService = class ConnectorsService {
|
|
|
1463
1489
|
.where("id", "=", connectorId)
|
|
1464
1490
|
.where("org_id", "=", orgId)
|
|
1465
1491
|
.execute();
|
|
1492
|
+
if (status === "active" && app.status === "disabled") {
|
|
1493
|
+
await settleEnableRequests(t, orgId, { kind: "connector", id: connectorId }, actor.accountId, { ...(actor.tokenId !== undefined && { actorTokenId: actor.tokenId }) });
|
|
1494
|
+
}
|
|
1466
1495
|
await audit(t, {
|
|
1467
1496
|
actorAccountId: actor.accountId,
|
|
1468
1497
|
...(actor.tokenId !== undefined && { actorTokenId: actor.tokenId }),
|
|
@@ -1507,6 +1536,7 @@ let ConnectorsService = class ConnectorsService {
|
|
|
1507
1536
|
.where("id", "=", connectorId)
|
|
1508
1537
|
.where("org_id", "=", orgId)
|
|
1509
1538
|
.execute();
|
|
1539
|
+
await cancelEnableRequestsOfConnector(t, orgId, connectorId, actorAccountId, "connector_removed");
|
|
1510
1540
|
await this.credentials.clearConnector(orgId, connectorId);
|
|
1511
1541
|
// 授权绑定连接器 id(软删除不触发外键级联):一并删掉,不留给任何后来的连接器
|
|
1512
1542
|
await t
|
package/package.json
CHANGED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
-- Point-of-use enable requests (org-usable spec 2026-12-02, `catalog_requests` row): an `enable`
|
|
2
|
+
-- request names the switch it asks the org admins to turn on in `detail.target` (`{ kind, id }`,
|
|
3
|
+
-- kinds plugin, extension, skill, agent_template, connector_template, connector and model; a model
|
|
4
|
+
-- id is the JSON tuple `["<provider>","<model>"]`), plus the picker subject it was resolved from
|
|
5
|
+
-- in `detail.subject`. Only a plugin target carries `item_id`. One pending enable request per
|
|
6
|
+
-- (org, target); the other kinds keep their pending (org, kind, item) uniqueness.
|
|
7
|
+
--
|
|
8
|
+
-- Runs as the kernel owner (the migrator's session has no `capybara.rls = enforce`, so the
|
|
9
|
+
-- `org_scope` policy admits every row); the runtime role keeps its grants on the table and the
|
|
10
|
+
-- existing policy; no table is added. catalog_requests is small (requests people file by hand):
|
|
11
|
+
-- re-adding the check constraint takes an ACCESS EXCLUSIVE lock and scans the table, and the
|
|
12
|
+
-- plain CREATE INDEX statements hold a SHARE lock while they build; at this size each lasts a
|
|
13
|
+
-- moment, so no maintenance window is needed. The lock wait is bounded so a busy table fails the
|
|
14
|
+
-- migration instead of queueing writers behind it.
|
|
15
|
+
SET LOCAL lock_timeout = '5s';
|
|
16
|
+
|
|
17
|
+
-- Legacy enable rows (a member asking for a plugin) target that plugin. Idempotent: only rows
|
|
18
|
+
-- without a target are touched.
|
|
19
|
+
UPDATE catalog_requests
|
|
20
|
+
SET detail = coalesce(detail, '{}'::jsonb)
|
|
21
|
+
|| jsonb_build_object('target', jsonb_build_object('kind', 'plugin', 'id', item_id::text))
|
|
22
|
+
WHERE kind = 'enable'
|
|
23
|
+
AND item_id IS NOT NULL
|
|
24
|
+
AND (detail IS NULL OR jsonb_typeof(detail -> 'target') IS DISTINCT FROM 'object');
|
|
25
|
+
|
|
26
|
+
-- capybara:allow-destructive the check is added back in the next statement with the enable branch; every row satisfies it after the backfill above
|
|
27
|
+
ALTER TABLE catalog_requests DROP CONSTRAINT IF EXISTS catalog_requests_target_check;
|
|
28
|
+
ALTER TABLE catalog_requests ADD CONSTRAINT catalog_requests_target_check
|
|
29
|
+
CHECK (
|
|
30
|
+
kind = 'import' AND entry_name IS NOT NULL
|
|
31
|
+
OR kind = 'connector_setup' AND agent_id IS NOT NULL
|
|
32
|
+
AND item_id IS NULL AND entry_name IS NULL
|
|
33
|
+
OR kind = 'network_allowlist' AND detail IS NOT NULL
|
|
34
|
+
AND item_id IS NULL AND agent_id IS NULL AND entry_name IS NULL
|
|
35
|
+
OR kind = 'enable' AND detail IS NOT NULL
|
|
36
|
+
AND jsonb_typeof(detail -> 'target') = 'object'
|
|
37
|
+
AND detail -> 'target' ->> 'kind' IN ('plugin', 'extension', 'skill', 'agent_template',
|
|
38
|
+
'connector_template', 'connector', 'model')
|
|
39
|
+
AND coalesce(detail -> 'target' ->> 'id', '') <> ''
|
|
40
|
+
AND (detail -> 'target' ->> 'kind' <> 'plugin' OR item_id::text = detail -> 'target' ->> 'id')
|
|
41
|
+
AND agent_id IS NULL AND entry_name IS NULL
|
|
42
|
+
OR kind NOT IN ('import', 'connector_setup', 'network_allowlist', 'enable')
|
|
43
|
+
AND item_id IS NOT NULL
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
-- Pending item uniqueness for the kinds other than enable (access), under a new name, before the
|
|
47
|
+
-- old index (which also covered enable) goes.
|
|
48
|
+
CREATE UNIQUE INDEX IF NOT EXISTS catalog_requests_pending_item_kind_uq
|
|
49
|
+
ON catalog_requests (org_id, kind, item_id)
|
|
50
|
+
WHERE status = 'pending' AND item_id IS NOT NULL AND kind <> 'enable';
|
|
51
|
+
|
|
52
|
+
-- One pending enable request per (org, target). It also serves the lookups by target.
|
|
53
|
+
CREATE UNIQUE INDEX IF NOT EXISTS catalog_requests_pending_enable_uq
|
|
54
|
+
ON catalog_requests (org_id, (detail -> 'target' ->> 'kind'), (detail -> 'target' ->> 'id'))
|
|
55
|
+
WHERE status = 'pending' AND kind = 'enable';
|
|
56
|
+
|
|
57
|
+
-- capybara:allow-destructive replaced by catalog_requests_pending_item_kind_uq and catalog_requests_pending_enable_uq above, created in this transaction
|
|
58
|
+
DROP INDEX IF EXISTS catalog_requests_pending_item_uq;
|
|
59
|
+
|
|
60
|
+
-- The requester's inbox notices: decided requests, now including enable requests a switch change
|
|
61
|
+
-- cancelled (`cancelReason: target_changed`); the 0077 index covers approved and rejected only.
|
|
62
|
+
CREATE INDEX IF NOT EXISTS catalog_requests_requester_decided_idx
|
|
63
|
+
ON catalog_requests (org_id, requested_by)
|
|
64
|
+
WHERE status IN ('approved', 'rejected', 'cancelled');
|