@capybara-hq/kernel 0.1.0-rc.115 → 0.1.0-rc.117
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/bootstrap.json +3 -3
- package/dist/agents/agents.controller.d.ts +13 -1
- package/dist/agents/agents.controller.js +24 -2
- package/dist/catalog/catalog-content.d.ts +11 -0
- package/dist/catalog/catalog-content.js +1 -0
- package/dist/catalog/catalog.service.d.ts +11 -1
- package/dist/catalog/catalog.service.js +36 -2
- package/dist/catalog/marketplaces.service.d.ts +1 -1
- package/dist/catalog/org-catalog.service.d.ts +1 -0
- package/dist/catalog/org-catalog.service.js +44 -2
- package/dist/catalog/platform-components.js +13 -0
- package/dist/catalog/plugin-connectors.d.ts +35 -0
- package/dist/catalog/plugin-connectors.js +81 -0
- package/dist/catalog/schema-path.d.ts +4 -6
- package/dist/catalog/schema-path.js +48 -21
- package/dist/channels/outbound.d.ts +5 -0
- package/dist/channels/outbound.js +6 -1
- package/dist/channels/supervisor.d.ts +5 -1
- package/dist/channels/supervisor.js +20 -1
- package/dist/conversations/conversations.controller.d.ts +46 -14
- package/dist/conversations/conversations.controller.js +82 -47
- package/dist/conversations/conversations.service.d.ts +93 -59
- package/dist/conversations/conversations.service.js +255 -72
- package/dist/conversations/events.d.ts +32 -0
- package/dist/conversations/events.js +47 -3
- package/dist/conversations/inline-tokens.d.ts +87 -0
- package/dist/conversations/inline-tokens.js +154 -0
- package/dist/conversations/permission-profiles.controller.d.ts +14 -7
- package/dist/conversations/permission-profiles.controller.js +1 -5
- package/dist/conversations/prompt-suggestions.js +2 -4
- package/dist/conversations/queue.d.ts +0 -2
- package/dist/conversations/queue.service.js +9 -13
- package/dist/db/kernel-schema.d.ts +2 -0
- package/dist/devices/devices.service.d.ts +8 -0
- package/dist/devices/devices.service.js +16 -0
- package/dist/errors.d.ts +12 -0
- package/dist/errors.js +12 -0
- package/dist/evals/snapshot.js +4 -2
- package/dist/files/library-files.service.d.ts +13 -0
- package/dist/files/library-files.service.js +33 -6
- package/dist/net/safe-fetch.js +1 -1
- package/dist/platform/exclusions.js +11 -1
- package/dist/platform/ops/devices.ops.js +14 -0
- package/dist/runtime/context/build.d.ts +7 -2
- package/dist/runtime/context/build.js +17 -6
- package/dist/runtime/context/compaction.d.ts +3 -3
- package/dist/runtime/context/compaction.js +12 -13
- package/dist/sandbox/review/classifier.js +5 -1
- package/dist/sandbox/sandbox.service.d.ts +13 -0
- package/dist/sandbox/sandbox.service.js +51 -4
- package/dist/tools/builtins/sandbox/common.d.ts +2 -7
- package/dist/tools/builtins/sandbox/common.js +4 -2
- package/dist/tools/connector-content.controller.d.ts +6 -2
- package/dist/tools/connector-content.controller.js +13 -3
- package/dist/tools/connector-content.d.ts +55 -15
- package/dist/tools/connector-content.js +112 -54
- package/dist/tools/connectors.service.d.ts +3 -2
- package/dist/tools/connectors.service.js +6 -20
- package/dist/tools/mentionable-connectors.d.ts +88 -0
- package/dist/tools/mentionable-connectors.js +218 -0
- package/dist/tools/pipeline.d.ts +4 -0
- package/dist/tools/pipeline.js +98 -22
- package/dist/tools/specs.d.ts +13 -4
- package/dist/tools/specs.js +22 -8
- package/dist/tools/tools.module.js +7 -0
- package/dist/ui/admin-ui.controller.d.ts +5 -2
- package/dist/ui/admin-ui.controller.js +14 -1
- package/dist/ui/ui.schemas.d.ts +9 -0
- package/dist/ui/ui.schemas.js +2 -0
- package/dist/ui/views.d.ts +1 -1
- package/dist/ui/views.js +4 -5
- package/package.json +3 -3
- package/src/migrations/0201_tool_specs_text.sql +8 -0
package/bootstrap.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"schemaVersion": 1,
|
|
4
4
|
"marketplace": {
|
|
5
5
|
"url": "https://github.com/capybara-hq/plugins.git",
|
|
6
|
-
"commit": "
|
|
6
|
+
"commit": "994dfd8cff41b1bc6c43149a9b9e98887c362d67"
|
|
7
7
|
},
|
|
8
8
|
"plugins": [
|
|
9
9
|
{
|
|
@@ -124,8 +124,8 @@
|
|
|
124
124
|
"name": "file-preview",
|
|
125
125
|
"source": "npm",
|
|
126
126
|
"npm": "@capybara-hq/plugin-file-preview",
|
|
127
|
-
"version": "0.1.0-rc.
|
|
128
|
-
"integrity": "sha512
|
|
127
|
+
"version": "0.1.0-rc.5",
|
|
128
|
+
"integrity": "sha512-/GSQeVc2AlO3q69pLm4EKFo8Q85nQG3PXbKPdL2UV+PeTBvXgqEL2bWO1upSVhD+SQaq3OTU85GZ097QjzDkrA==",
|
|
129
129
|
"required": false,
|
|
130
130
|
"builtin": true
|
|
131
131
|
}
|
|
@@ -3,6 +3,7 @@ import { z } from "zod";
|
|
|
3
3
|
import { AttachmentsService, type CreatedAttachment } from "../conversations/attachments.service.js";
|
|
4
4
|
import { type Principal } from "../identity/principal.js";
|
|
5
5
|
import { type OrgContext } from "../orgs/org.guard.js";
|
|
6
|
+
import { type MentionableConnector, MentionableConnectorsService } from "../tools/mentionable-connectors.js";
|
|
6
7
|
import { AgentProfileService } from "./agent-profile.service.js";
|
|
7
8
|
import { AgentCreateBody, AgentFromTemplateBody, AgentFromTemplatePreviewBody, AgentProfileBody, AgentUpdateBody, AgentAvatarUploadBody as AvatarUploadBody } from "./agents.schemas.js";
|
|
8
9
|
import { AgentsService, type AgentVersionSummary, type AgentView, type AgentWarning } from "./agents.service.js";
|
|
@@ -20,7 +21,8 @@ export declare class AgentsController {
|
|
|
20
21
|
private readonly profiles;
|
|
21
22
|
private readonly attachments;
|
|
22
23
|
private readonly fromTemplate;
|
|
23
|
-
|
|
24
|
+
private readonly mentionable;
|
|
25
|
+
constructor(agents: AgentsService, profiles: AgentProfileService, attachments: AttachmentsService, fromTemplate: AgentsFromTemplate, mentionable: MentionableConnectorsService);
|
|
24
26
|
/** A response's view with its provenance link (`createdFrom.available`, ruling P4-8). */
|
|
25
27
|
private linked;
|
|
26
28
|
/**
|
|
@@ -49,6 +51,16 @@ export declare class AgentsController {
|
|
|
49
51
|
get(principal: Principal, org: OrgContext, agentId: string): Promise<{
|
|
50
52
|
agent: AgentView;
|
|
51
53
|
}>;
|
|
54
|
+
/**
|
|
55
|
+
* The connectors the web input box's `@` menu offers for this agent (composer inline tokens
|
|
56
|
+
* spec §4): the org's live, active connectors the agent is offered tools of, plus the
|
|
57
|
+
* `needs_config` ones, with the caller's credential state. A person only (a service token ->
|
|
58
|
+
* 403 `forbidden`); an agent the caller cannot see -> 404 `agent.not_found`. Opens no
|
|
59
|
+
* connector session.
|
|
60
|
+
*/
|
|
61
|
+
mentionableConnectors(principal: Principal, org: OrgContext, agentId: string): Promise<{
|
|
62
|
+
connectors: MentionableConnector[];
|
|
63
|
+
}>;
|
|
52
64
|
update(principal: Principal, org: OrgContext, agentId: string, body: z.infer<typeof AgentUpdateBody>): Promise<{
|
|
53
65
|
agent: AgentView;
|
|
54
66
|
warnings: AgentWarning[];
|
|
@@ -15,6 +15,7 @@ import { CurrentPrincipal, patTokenId, requireUser, } from "../identity/principa
|
|
|
15
15
|
import { createZodDto } from "../infra/validation/create-zod-dto.js";
|
|
16
16
|
import { ZBody } from "../infra/validation/zod-params.js";
|
|
17
17
|
import { CurrentOrg, OrgAction } from "../orgs/org.guard.js";
|
|
18
|
+
import { MentionableConnectorsService, } from "../tools/mentionable-connectors.js";
|
|
18
19
|
import { AgentProfileService } from "./agent-profile.service.js";
|
|
19
20
|
import { AgentCreateBody, AgentFromTemplateBody, AgentFromTemplatePreviewBody, AgentProfileBody, AgentUpdateBody, AgentAvatarUploadBody as AvatarUploadBody, } from "./agents.schemas.js";
|
|
20
21
|
import { AgentsService, } from "./agents.service.js";
|
|
@@ -45,11 +46,13 @@ let AgentsController = class AgentsController {
|
|
|
45
46
|
profiles;
|
|
46
47
|
attachments;
|
|
47
48
|
fromTemplate;
|
|
48
|
-
|
|
49
|
+
mentionable;
|
|
50
|
+
constructor(agents, profiles, attachments, fromTemplate, mentionable) {
|
|
49
51
|
this.agents = agents;
|
|
50
52
|
this.profiles = profiles;
|
|
51
53
|
this.attachments = attachments;
|
|
52
54
|
this.fromTemplate = fromTemplate;
|
|
55
|
+
this.mentionable = mentionable;
|
|
53
56
|
}
|
|
54
57
|
/** A response's view with its provenance link (`createdFrom.available`, ruling P4-8). */
|
|
55
58
|
async linked(orgId, view) {
|
|
@@ -101,6 +104,17 @@ let AgentsController = class AgentsController {
|
|
|
101
104
|
agent: await this.linked(org.orgId, await this.agents.get(org.orgId, agentId, viewerOf(principal))),
|
|
102
105
|
};
|
|
103
106
|
}
|
|
107
|
+
/**
|
|
108
|
+
* The connectors the web input box's `@` menu offers for this agent (composer inline tokens
|
|
109
|
+
* spec §4): the org's live, active connectors the agent is offered tools of, plus the
|
|
110
|
+
* `needs_config` ones, with the caller's credential state. A person only (a service token ->
|
|
111
|
+
* 403 `forbidden`); an agent the caller cannot see -> 404 `agent.not_found`. Opens no
|
|
112
|
+
* connector session.
|
|
113
|
+
*/
|
|
114
|
+
async mentionableConnectors(principal, org, agentId) {
|
|
115
|
+
const p = requireUser(principal);
|
|
116
|
+
return this.mentionable.list(org, p.account.id, agentId);
|
|
117
|
+
}
|
|
104
118
|
async update(principal, org, agentId, body) {
|
|
105
119
|
const p = requireUser(principal);
|
|
106
120
|
const r = await this.agents.update(org.orgId, agentId, p.account.id, body, patTokenId(p));
|
|
@@ -205,6 +219,13 @@ __decorate([
|
|
|
205
219
|
__param(1, CurrentOrg()),
|
|
206
220
|
__param(2, Param("agentId"))
|
|
207
221
|
], AgentsController.prototype, "get", null);
|
|
222
|
+
__decorate([
|
|
223
|
+
Get(":agentId/mentionable-connectors"),
|
|
224
|
+
OrgAction("agents.use"),
|
|
225
|
+
__param(0, CurrentPrincipal()),
|
|
226
|
+
__param(1, CurrentOrg()),
|
|
227
|
+
__param(2, Param("agentId"))
|
|
228
|
+
], AgentsController.prototype, "mentionableConnectors", null);
|
|
208
229
|
__decorate([
|
|
209
230
|
Patch(":agentId"),
|
|
210
231
|
OrgAction("agents.create"),
|
|
@@ -266,6 +287,7 @@ AgentsController = __decorate([
|
|
|
266
287
|
__param(0, Inject(AgentsService)),
|
|
267
288
|
__param(1, Inject(AgentProfileService)),
|
|
268
289
|
__param(2, Inject(AttachmentsService)),
|
|
269
|
-
__param(3, Inject(AgentsFromTemplate))
|
|
290
|
+
__param(3, Inject(AgentsFromTemplate)),
|
|
291
|
+
__param(4, Inject(MentionableConnectorsService))
|
|
270
292
|
], AgentsController);
|
|
271
293
|
export { AgentsController };
|
|
@@ -73,6 +73,7 @@ export interface OrgCatalogTemplate {
|
|
|
73
73
|
connector: string;
|
|
74
74
|
endpoint: Record<string, unknown>;
|
|
75
75
|
editableEndpoint: string[];
|
|
76
|
+
editableEndpointTitles?: Record<string, string>;
|
|
76
77
|
auth: Record<string, unknown>;
|
|
77
78
|
ownership: "org" | "personal" | null;
|
|
78
79
|
/**
|
|
@@ -106,6 +107,13 @@ export interface OrgCatalogTemplate {
|
|
|
106
107
|
*/
|
|
107
108
|
icon: string | null;
|
|
108
109
|
}
|
|
110
|
+
/** A connector reference or described need for the org's plugin review. */
|
|
111
|
+
export type OrgCatalogAgentConnectorNeed = {
|
|
112
|
+
template: string;
|
|
113
|
+
} | {
|
|
114
|
+
label: string;
|
|
115
|
+
host?: string;
|
|
116
|
+
};
|
|
109
117
|
/** `GET /orgs/:orgId/catalog/:itemId`: the item and what the install wizard needs (latest version). */
|
|
110
118
|
export interface OrgCatalogDetail {
|
|
111
119
|
item: OrgCatalogItem;
|
|
@@ -127,6 +135,8 @@ export interface OrgCatalogDetail {
|
|
|
127
135
|
skills: string[];
|
|
128
136
|
/** The agent template files (`agents/<name>.md`, sub-agents spec §16). */
|
|
129
137
|
agents: string[];
|
|
138
|
+
/** Display details for agent templates with connector references, keyed by their paths in `agents`. */
|
|
139
|
+
agentConnectorNeeds?: Record<string, OrgCatalogAgentConnectorNeed[]>;
|
|
130
140
|
}
|
|
131
141
|
/**
|
|
132
142
|
* A connector template as an org sees it (the install wizard and the upgrade preview's inputs):
|
|
@@ -137,6 +147,7 @@ export declare function orgTemplateView(id: string, file: ConnectorTemplateFile,
|
|
|
137
147
|
on?: boolean;
|
|
138
148
|
connected?: boolean;
|
|
139
149
|
icon?: string | null;
|
|
150
|
+
editableEndpointTitles?: Record<string, string> | undefined;
|
|
140
151
|
}): OrgCatalogTemplate;
|
|
141
152
|
/** An item's icon (the latest version's plugin icon). */
|
|
142
153
|
export interface CatalogIcon {
|
|
@@ -27,6 +27,7 @@ export function orgTemplateView(id, file, o = {}) {
|
|
|
27
27
|
connector: t.connector,
|
|
28
28
|
endpoint: t.endpoint,
|
|
29
29
|
editableEndpoint: t.editableEndpoint ?? [],
|
|
30
|
+
...(o.editableEndpointTitles && { editableEndpointTitles: o.editableEndpointTitles }),
|
|
30
31
|
auth: t.auth,
|
|
31
32
|
ownership: t.ownership ??
|
|
32
33
|
(typeof t.auth.ownership === "string" ? t.auth.ownership : null),
|
|
@@ -8,6 +8,7 @@ import { KernelConfigService } from "../infra/config/kernel-config.service.js";
|
|
|
8
8
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
9
9
|
import { TransactionHost } from "../infra/database/transaction-host.js";
|
|
10
10
|
import { OutboxService } from "../infra/outbox/outbox.service.js";
|
|
11
|
+
import { OrgLock } from "../orgs/org-lock.js";
|
|
11
12
|
import type { TranslationReport } from "./claude/report.js";
|
|
12
13
|
import { type GitLocation } from "./git-source.js";
|
|
13
14
|
import { MarketplacesService } from "./marketplaces.service.js";
|
|
@@ -258,6 +259,8 @@ export declare class CatalogService {
|
|
|
258
259
|
private readonly installLock;
|
|
259
260
|
/** A removed org-owned plugin's cleanup job, owed by the removal (transactional outbox §8.1). */
|
|
260
261
|
private readonly outbox;
|
|
262
|
+
/** The orgs whose connectors a delete switches off, locked before the item (ruling P3-50). */
|
|
263
|
+
private readonly orgLock;
|
|
261
264
|
readonly txHost: TransactionHost;
|
|
262
265
|
constructor(kdb: KernelDb,
|
|
263
266
|
/** The super admin lock (identity/super-admin.ts): joins the caller's transaction. */
|
|
@@ -271,7 +274,9 @@ export declare class CatalogService {
|
|
|
271
274
|
/** Serializes a claim release with an install of that name still committing (F10). */
|
|
272
275
|
installLock: PluginInstallLock,
|
|
273
276
|
/** A removed org-owned plugin's cleanup job, owed by the removal (transactional outbox §8.1). */
|
|
274
|
-
outbox: Pick<OutboxService, "add">,
|
|
277
|
+
outbox: Pick<OutboxService, "add">,
|
|
278
|
+
/** The orgs whose connectors a delete switches off, locked before the item (ruling P3-50). */
|
|
279
|
+
orgLock: OrgLock, txHost: TransactionHost);
|
|
275
280
|
/** The kernel-schema handle of the current context (the transaction, else the pool). */
|
|
276
281
|
private get db();
|
|
277
282
|
/** Downloads a marketplace archive source, verified against its integrity. */
|
|
@@ -363,6 +368,11 @@ export declare class CatalogService {
|
|
|
363
368
|
*/
|
|
364
369
|
assertRemovable(itemId: string): Promise<void>;
|
|
365
370
|
private writeRemove;
|
|
371
|
+
/**
|
|
372
|
+
* Locks, in sorted order, the live orgs with live connectors made from the item's connector
|
|
373
|
+
* templates (a deleted org is skipped).
|
|
374
|
+
*/
|
|
375
|
+
private lockConnectorOrgs;
|
|
366
376
|
/**
|
|
367
377
|
* A live platform item whose extension (the install of the item's name from its package) is
|
|
368
378
|
* enabled -> 409 `catalog.extension_enabled`. With `lock`, under the per-name install lock an
|
|
@@ -21,6 +21,7 @@ import { KernelDb } from "../infra/database/kernel-db.js";
|
|
|
21
21
|
import { TransactionHost } from "../infra/database/transaction-host.js";
|
|
22
22
|
import { Transactional } from "../infra/database/transactional.decorator.js";
|
|
23
23
|
import { OutboxService } from "../infra/outbox/outbox.service.js";
|
|
24
|
+
import { OrgLock } from "../orgs/org-lock.js";
|
|
24
25
|
import { sameRepository } from "../packages/provenance.js";
|
|
25
26
|
import { assertNotPlatformDefault } from "../themes/theme-usage.js";
|
|
26
27
|
import { countInstalls, inAuthorOrder, itemConfirmations, itemScopeFacts, itemView, marketplaceLatest, versionUsable, } from "./catalog-items.js";
|
|
@@ -29,6 +30,7 @@ import { oweOwnedPluginCleanup } from "./job-ids.js";
|
|
|
29
30
|
import { fetchMarketplaceArchive, marketplaceNetPolicy, marketplaceUrlProblem, } from "./marketplace-fetch.js";
|
|
30
31
|
import { assertEntryNotDeprecated, entryCompatible, entrySourceHost, HOST_VERSIONS, hostAllowed, loadMarketplaceEntry, MarketplacesService, pluginNameFrom, } from "./marketplaces.service.js";
|
|
31
32
|
import { releaseExtensionClaim } from "./ownership.js";
|
|
33
|
+
import { switchOffItemConnectors } from "./plugin-connectors.js";
|
|
32
34
|
import { PluginImport } from "./plugin-import.js";
|
|
33
35
|
import { cancelPendingRequests } from "./request-rules.js";
|
|
34
36
|
import { newestFirst } from "./versions.js";
|
|
@@ -102,6 +104,7 @@ let CatalogService = class CatalogService {
|
|
|
102
104
|
marketplaces;
|
|
103
105
|
installLock;
|
|
104
106
|
outbox;
|
|
107
|
+
orgLock;
|
|
105
108
|
txHost;
|
|
106
109
|
constructor(kdb,
|
|
107
110
|
/** The super admin lock (identity/super-admin.ts): joins the caller's transaction. */
|
|
@@ -115,7 +118,9 @@ let CatalogService = class CatalogService {
|
|
|
115
118
|
/** Serializes a claim release with an install of that name still committing (F10). */
|
|
116
119
|
installLock,
|
|
117
120
|
/** A removed org-owned plugin's cleanup job, owed by the removal (transactional outbox §8.1). */
|
|
118
|
-
outbox,
|
|
121
|
+
outbox,
|
|
122
|
+
/** The orgs whose connectors a delete switches off, locked before the item (ruling P3-50). */
|
|
123
|
+
orgLock, txHost) {
|
|
119
124
|
this.kdb = kdb;
|
|
120
125
|
this.adminLock = adminLock;
|
|
121
126
|
this.config = config;
|
|
@@ -125,6 +130,7 @@ let CatalogService = class CatalogService {
|
|
|
125
130
|
this.marketplaces = marketplaces;
|
|
126
131
|
this.installLock = installLock;
|
|
127
132
|
this.outbox = outbox;
|
|
133
|
+
this.orgLock = orgLock;
|
|
128
134
|
this.txHost = txHost;
|
|
129
135
|
}
|
|
130
136
|
/** The kernel-schema handle of the current context (the transaction, else the pool). */
|
|
@@ -503,6 +509,9 @@ let CatalogService = class CatalogService {
|
|
|
503
509
|
}
|
|
504
510
|
async writeRemove(actor, itemId, opts) {
|
|
505
511
|
await this.adminLock.lockAndAuthorize(actor);
|
|
512
|
+
// The orgs whose connectors the delete switches off, sorted, before the item (the global lock
|
|
513
|
+
// order, ruling P3-50, as the platform plugin update takes them)
|
|
514
|
+
await this.lockConnectorOrgs(itemId);
|
|
506
515
|
// The item row before the install lock the check below takes (the global lock order: the
|
|
507
516
|
// item, then the install lock, ruling P3-50; also the item before its theme rows in removeIn)
|
|
508
517
|
await this.db
|
|
@@ -515,6 +524,24 @@ let CatalogService = class CatalogService {
|
|
|
515
524
|
if ((await this.removeIn(actor, itemId, opts)) === null)
|
|
516
525
|
throw notFound();
|
|
517
526
|
}
|
|
527
|
+
/**
|
|
528
|
+
* Locks, in sorted order, the live orgs with live connectors made from the item's connector
|
|
529
|
+
* templates (a deleted org is skipped).
|
|
530
|
+
*/
|
|
531
|
+
// org-filter: the super admin's delete of a catalog item reaches its template connectors in
|
|
532
|
+
// every org by design; this only collects their orgs to lock them
|
|
533
|
+
async lockConnectorOrgs(itemId) {
|
|
534
|
+
const rows = await this.db
|
|
535
|
+
.selectFrom("connectors as c")
|
|
536
|
+
.innerJoin("platform_connector_templates as t", "t.id", "c.platform_template_id")
|
|
537
|
+
.select("c.org_id")
|
|
538
|
+
.distinct()
|
|
539
|
+
.where("t.catalog_item_id", "=", itemId)
|
|
540
|
+
.where("c.deleted_at", "is", null)
|
|
541
|
+
.execute();
|
|
542
|
+
for (const orgId of rows.map((r) => r.org_id).sort())
|
|
543
|
+
await this.orgLock.tryLock(orgId);
|
|
544
|
+
}
|
|
518
545
|
/**
|
|
519
546
|
* A live platform item whose extension (the install of the item's name from its package) is
|
|
520
547
|
* enabled -> 409 `catalog.extension_enabled`. With `lock`, under the per-name install lock an
|
|
@@ -604,6 +631,12 @@ let CatalogService = class CatalogService {
|
|
|
604
631
|
.where("catalog_item_id", "=", itemId)
|
|
605
632
|
.where("deleted_at", "is", null)
|
|
606
633
|
.execute();
|
|
634
|
+
// Its connectors are switched off with it, as an uninstall switches them off (spec §5 rule 8):
|
|
635
|
+
// endpoint and credentials stay, and an import of the same plugin again relinks them to the
|
|
636
|
+
// new item, whose install switches them back on (`relinkDeletedItemConnectors`). The super
|
|
637
|
+
// admin's delete locked their orgs first; an owner's delete or an org deletion removes an
|
|
638
|
+
// item no other org uses (P3-19), so its connectors are the owner org's, already locked
|
|
639
|
+
await switchOffItemConnectors(t, itemId);
|
|
607
640
|
// Pending requests for a deleted item are pointless: cancel them in the same transaction
|
|
608
641
|
await cancelPendingRequests(t, { itemId }, actor, "item_removed", opts);
|
|
609
642
|
await audit(t, {
|
|
@@ -640,6 +673,7 @@ CatalogService = __decorate([
|
|
|
640
673
|
__param(6, Inject(MarketplacesService)),
|
|
641
674
|
__param(7, Inject(PluginInstallLock)),
|
|
642
675
|
__param(8, Inject(OutboxService)),
|
|
643
|
-
__param(9, Inject(
|
|
676
|
+
__param(9, Inject(OrgLock)),
|
|
677
|
+
__param(10, Inject(TransactionHost))
|
|
644
678
|
], CatalogService);
|
|
645
679
|
export { CatalogService };
|
|
@@ -208,7 +208,7 @@ export declare function headsToResolve(entries: readonly MarketplaceEntry[], imp
|
|
|
208
208
|
/** The host versions (an entry's `minKernel` is judged against them). */
|
|
209
209
|
export declare const HOST_VERSIONS: {
|
|
210
210
|
readonly kernel: string;
|
|
211
|
-
readonly sdk: "0.1.0-rc.
|
|
211
|
+
readonly sdk: "0.1.0-rc.92";
|
|
212
212
|
};
|
|
213
213
|
/** Whether this deployment satisfies the entry's `minKernel`. */
|
|
214
214
|
export declare const entryCompatible: (e: Pick<MarketplaceEntry, "minKernel">) => boolean;
|
|
@@ -66,6 +66,7 @@ export declare class OrgCatalogService {
|
|
|
66
66
|
*/
|
|
67
67
|
/** The account is an admin (or owner) of the org. */
|
|
68
68
|
private isOrgAdmin;
|
|
69
|
+
private endpointTitles;
|
|
69
70
|
detail(orgId: string, accountId: string, itemId: string): Promise<OrgCatalogDetail>;
|
|
70
71
|
/**
|
|
71
72
|
* The item's icon; members don't see disabled items, nobody outside its list sees a hidden
|
|
@@ -22,17 +22,30 @@ import { OrgLock } from "../orgs/org-lock.js";
|
|
|
22
22
|
import { can, roleAtLeast } from "../orgs/roles.js";
|
|
23
23
|
import { packagePath } from "../packages/tgz.js";
|
|
24
24
|
import { StorageService } from "../storage/storage.service.js";
|
|
25
|
-
import { catalogHasIcon, findConnectorIn, orgTemplateView, readCatalogIcon, readCatalogTemplates, templatePluginProblem, } from "./catalog-content.js";
|
|
25
|
+
import { catalogHasIcon, findConnectorIn, orgTemplateView, readCatalogAgentTemplates, readCatalogIcon, readCatalogTemplates, templatePluginProblem, } from "./catalog-content.js";
|
|
26
26
|
import { itemView, ownerOnlyFacts, versionUsable } from "./catalog-items.js";
|
|
27
27
|
import { connectorTemplatesOn } from "./component-state.js";
|
|
28
28
|
import { LIVE_INSTALL_STATUSES } from "./install-status.js";
|
|
29
29
|
import { itemPendingError, ownerOf, ownersOf } from "./ownership.js";
|
|
30
30
|
import { PluginInstaller, uninstallPreviewHash, upsertOrgSwitch, } from "./plugin-install.js";
|
|
31
|
+
import { schemaPathTitle } from "./schema-path.js";
|
|
31
32
|
import { requestable, switchable, visibleTo, wantedOn } from "./scope.js";
|
|
32
33
|
const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
33
34
|
const itemNotFound = () => new ApiError("catalog.item_not_found", "Catalog item not found");
|
|
34
35
|
const notOffered = () => new ApiError("catalog.approval_required", "This plugin is not offered to this organization; an org admin can request access");
|
|
35
36
|
const pluginDisabled = () => new ApiError("plugin.disabled", "This plugin is disabled by the super admin and cannot be switched on");
|
|
37
|
+
function connectorNeedHost(endpoint) {
|
|
38
|
+
const url = URL.parse(endpoint);
|
|
39
|
+
if (!url?.hostname)
|
|
40
|
+
return undefined;
|
|
41
|
+
if (url.port)
|
|
42
|
+
return url.host;
|
|
43
|
+
// Parse the same authority with a different default port so an explicit default stays visible.
|
|
44
|
+
const scheme = url.protocol === "http:" || url.protocol === "ws:" ? "https" : "http";
|
|
45
|
+
const alternate = URL.parse(scheme + endpoint.slice(endpoint.indexOf(":")));
|
|
46
|
+
const port = alternate?.hostname === url.hostname ? alternate.port : undefined;
|
|
47
|
+
return port ? `${url.hostname}:${port}` : url.host;
|
|
48
|
+
}
|
|
36
49
|
/**
|
|
37
50
|
* Organizations see the platform catalog with the plugin scope rules applied (plugin and component
|
|
38
51
|
* management spec §5): a plugin is `all` (on in every org unless an org admin switched it off,
|
|
@@ -258,6 +271,19 @@ let OrgCatalogService = class OrgCatalogService {
|
|
|
258
271
|
.executeTakeFirst();
|
|
259
272
|
return m !== undefined && roleAtLeast(m.role, "admin");
|
|
260
273
|
}
|
|
274
|
+
endpointTitles(template) {
|
|
275
|
+
const paths = template.editableEndpoint;
|
|
276
|
+
if (!paths?.length)
|
|
277
|
+
return undefined;
|
|
278
|
+
const schema = findConnectorIn(this.registry, template.plugin, template.connector)?.endpointSchema;
|
|
279
|
+
if (!schema)
|
|
280
|
+
return undefined;
|
|
281
|
+
const entries = paths.flatMap((path) => {
|
|
282
|
+
const title = schemaPathTitle(schema, path.split("."));
|
|
283
|
+
return title ? [[path, title]] : [];
|
|
284
|
+
});
|
|
285
|
+
return entries.length ? Object.fromEntries(entries) : undefined;
|
|
286
|
+
}
|
|
261
287
|
async detail(orgId, accountId, itemId) {
|
|
262
288
|
if (!UUID_RE.test(itemId))
|
|
263
289
|
throw itemNotFound();
|
|
@@ -273,7 +299,21 @@ let OrgCatalogService = class OrgCatalogService {
|
|
|
273
299
|
if (!v)
|
|
274
300
|
throw itemNotFound();
|
|
275
301
|
const m = v.manifest;
|
|
276
|
-
const templates = await
|
|
302
|
+
const [templates, agentTemplates] = await Promise.all([
|
|
303
|
+
readCatalogTemplates(this.storage, v),
|
|
304
|
+
readCatalogAgentTemplates(this.storage, v),
|
|
305
|
+
]);
|
|
306
|
+
const agentConnectorNeeds = {};
|
|
307
|
+
for (const { path, template } of agentTemplates) {
|
|
308
|
+
if (!template.connectors?.length)
|
|
309
|
+
continue;
|
|
310
|
+
agentConnectorNeeds[path] = template.connectors.map((connector) => {
|
|
311
|
+
if ("template" in connector)
|
|
312
|
+
return { template: connector.template };
|
|
313
|
+
const host = connectorNeedHost(connector.needs.endpoint);
|
|
314
|
+
return { label: connector.needs.label, ...(host && { host }) };
|
|
315
|
+
});
|
|
316
|
+
}
|
|
277
317
|
// Which templates are on in this org now: the install makes connectors of those, a
|
|
278
318
|
// default-off one an admin switched on included
|
|
279
319
|
const on = await connectorTemplatesOn(this.db, orgId, itemId, templates.map((t) => t.id));
|
|
@@ -304,6 +344,7 @@ let OrgCatalogService = class OrgCatalogService {
|
|
|
304
344
|
on: on.has(t.id),
|
|
305
345
|
connected: connected.has(t.id),
|
|
306
346
|
icon: iconOf(t.id),
|
|
347
|
+
editableEndpointTitles: this.endpointTitles(t.file.template),
|
|
307
348
|
})),
|
|
308
349
|
dependencies: [
|
|
309
350
|
...(m.dependencies ?? []).map((d) => ({ name: d.name, range: d.version })),
|
|
@@ -311,6 +352,7 @@ let OrgCatalogService = class OrgCatalogService {
|
|
|
311
352
|
],
|
|
312
353
|
skills: (m.skills ?? []).map((s) => packagePath(s.path)),
|
|
313
354
|
agents: (m.agents ?? []).map((a) => packagePath(a.path)),
|
|
355
|
+
...(Object.keys(agentConnectorNeeds).length > 0 && { agentConnectorNeeds }),
|
|
314
356
|
};
|
|
315
357
|
}
|
|
316
358
|
/**
|
|
@@ -30,6 +30,7 @@ import { readCatalogAgentTemplates, readCatalogFiles, readCatalogTemplates, read
|
|
|
30
30
|
import { putCatalogFiles } from "./catalog-items.js";
|
|
31
31
|
import { CatalogItemLock } from "./locks.js";
|
|
32
32
|
import { assertNotAwaiting } from "./ownership.js";
|
|
33
|
+
import { relinkDeletedItemConnectors } from "./plugin-connectors.js";
|
|
33
34
|
/** The prefix (in `deployment/`) of a platform skill version's files. */
|
|
34
35
|
export const platformSkillPrefix = (id, version) => `platform/skills/${id}/${version}/`;
|
|
35
36
|
/** The prefix (in `deployment/`) of a platform agent template version's file. */
|
|
@@ -750,6 +751,18 @@ let PlatformComponents = class PlatformComponents {
|
|
|
750
751
|
...owned,
|
|
751
752
|
})
|
|
752
753
|
.execute();
|
|
754
|
+
// The plugin imported again after its delete: the connectors the deleted item's template
|
|
755
|
+
// made move to this one, and its installs take them back (spec §5 rule 8). Their orgs are
|
|
756
|
+
// not locked: nothing else writes a deleted plugin's connectors but their org's admins,
|
|
757
|
+
// whose row locks this waits for without holding anything they need
|
|
758
|
+
await relinkDeletedItemConnectors(t, {
|
|
759
|
+
itemId: plan.itemId,
|
|
760
|
+
name: plan.plugin,
|
|
761
|
+
ownerOrgId,
|
|
762
|
+
version: plan.version,
|
|
763
|
+
templateId: c.name,
|
|
764
|
+
newTemplateId: c.id,
|
|
765
|
+
});
|
|
753
766
|
}
|
|
754
767
|
out.connectorTemplates.push({
|
|
755
768
|
kind: "connector_template",
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { KernelSchemaDb } from "../db/kernel-schema.js";
|
|
2
|
+
/**
|
|
3
|
+
* The update that switches a connector off with plugin `itemId`: status `disabled`, and the marker
|
|
4
|
+
* set only on a connector that was active, so switching the plugin back on re-enables exactly what
|
|
5
|
+
* this switched off; one an org admin disabled by hand keeps no marker and stays off. Endpoint and
|
|
6
|
+
* credentials stay.
|
|
7
|
+
*/
|
|
8
|
+
export declare function pluginSwitchOff(itemId: string): {
|
|
9
|
+
status: "disabled";
|
|
10
|
+
disabled_by_plugin_id: import("kysely").RawBuilder<string | null>;
|
|
11
|
+
updated_at: import("kysely").RawBuilder<Date>;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Switches off, in the caller's transaction, every live connector in any org made from one of the
|
|
15
|
+
* item's connector templates ({@link pluginSwitchOff}): the super admin's delete of the item
|
|
16
|
+
* (`CatalogService.removeIn`). The caller holds the orgs' row locks where it can (the global lock
|
|
17
|
+
* order puts them before the item). Returns how many connectors it touched.
|
|
18
|
+
*/
|
|
19
|
+
export declare function switchOffItemConnectors(db: KernelSchemaDb, itemId: string): Promise<number>;
|
|
20
|
+
/**
|
|
21
|
+
* When a plugin is imported again after its delete (a new catalog item of the same name and
|
|
22
|
+
* owner), the live connectors that the deleted items' connector template `templateId` made move to
|
|
23
|
+
* the new item's template `newTemplateId`: their template, item and version links point at the new
|
|
24
|
+
* item, and a marker of a deleted item's switch-off becomes the new item's, so the new item's
|
|
25
|
+
* install takes them back and re-enables them exactly as switching the plugin back on does (one an
|
|
26
|
+
* org admin disabled by hand stays off). In the caller's transaction, under the item lock.
|
|
27
|
+
*/
|
|
28
|
+
export declare function relinkDeletedItemConnectors(db: KernelSchemaDb, to: {
|
|
29
|
+
itemId: string;
|
|
30
|
+
name: string;
|
|
31
|
+
ownerOrgId: string | null;
|
|
32
|
+
version: string;
|
|
33
|
+
templateId: string;
|
|
34
|
+
newTemplateId: string;
|
|
35
|
+
}): Promise<number>;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { sql } from "kysely";
|
|
2
|
+
// The connectors a plugin's connector templates made, switched off and on with the plugin (spec §5
|
|
3
|
+
// rule 8): an org's uninstall or switch-off (`ConnectorsService.disableWithPluginIn`), the super
|
|
4
|
+
// admin's delete of the plugin ({@link switchOffItemConnectors}) and an import of the same plugin
|
|
5
|
+
// again ({@link relinkDeletedItemConnectors}) share one meaning of the marker
|
|
6
|
+
// `connectors.disabled_by_plugin_id`.
|
|
7
|
+
/**
|
|
8
|
+
* The update that switches a connector off with plugin `itemId`: status `disabled`, and the marker
|
|
9
|
+
* set only on a connector that was active, so switching the plugin back on re-enables exactly what
|
|
10
|
+
* this switched off; one an org admin disabled by hand keeps no marker and stays off. Endpoint and
|
|
11
|
+
* credentials stay.
|
|
12
|
+
*/
|
|
13
|
+
export function pluginSwitchOff(itemId) {
|
|
14
|
+
return {
|
|
15
|
+
status: "disabled",
|
|
16
|
+
disabled_by_plugin_id: sql `case when status = 'active' then ${itemId}::uuid else disabled_by_plugin_id end`,
|
|
17
|
+
updated_at: sql `now()`,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Switches off, in the caller's transaction, every live connector in any org made from one of the
|
|
22
|
+
* item's connector templates ({@link pluginSwitchOff}): the super admin's delete of the item
|
|
23
|
+
* (`CatalogService.removeIn`). The caller holds the orgs' row locks where it can (the global lock
|
|
24
|
+
* order puts them before the item). Returns how many connectors it touched.
|
|
25
|
+
*/
|
|
26
|
+
export async function switchOffItemConnectors(db, itemId) {
|
|
27
|
+
// org-filter: the delete of a catalog item switches off its template connectors in every org
|
|
28
|
+
// by design (spec §5 rule 8), keyed by the item's own template ids
|
|
29
|
+
const rows = await db
|
|
30
|
+
.updateTable("connectors")
|
|
31
|
+
.set(pluginSwitchOff(itemId))
|
|
32
|
+
.where("deleted_at", "is", null)
|
|
33
|
+
.where("platform_template_id", "in", (q) => q
|
|
34
|
+
.selectFrom("platform_connector_templates")
|
|
35
|
+
.select("id")
|
|
36
|
+
.where("catalog_item_id", "=", itemId))
|
|
37
|
+
.returning("id")
|
|
38
|
+
.execute();
|
|
39
|
+
return rows.length;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* When a plugin is imported again after its delete (a new catalog item of the same name and
|
|
43
|
+
* owner), the live connectors that the deleted items' connector template `templateId` made move to
|
|
44
|
+
* the new item's template `newTemplateId`: their template, item and version links point at the new
|
|
45
|
+
* item, and a marker of a deleted item's switch-off becomes the new item's, so the new item's
|
|
46
|
+
* install takes them back and re-enables them exactly as switching the plugin back on does (one an
|
|
47
|
+
* org admin disabled by hand stays off). In the caller's transaction, under the item lock.
|
|
48
|
+
*/
|
|
49
|
+
export async function relinkDeletedItemConnectors(db, to) {
|
|
50
|
+
// The deleted items of this plugin (its name, the same owner) and their template `templateId`
|
|
51
|
+
const old = await db
|
|
52
|
+
.selectFrom("platform_connector_templates as t")
|
|
53
|
+
.innerJoin("catalog_items as i", "i.id", "t.catalog_item_id")
|
|
54
|
+
.select(["t.id", "i.id as item_id"])
|
|
55
|
+
.where("t.template_id", "=", to.templateId)
|
|
56
|
+
.where("i.name", "=", to.name)
|
|
57
|
+
.where("i.deleted_at", "is not", null)
|
|
58
|
+
.$call((q) => to.ownerOrgId === null
|
|
59
|
+
? q.where("i.owner_org_id", "is", null)
|
|
60
|
+
: q.where("i.owner_org_id", "=", to.ownerOrgId))
|
|
61
|
+
.execute();
|
|
62
|
+
if (old.length === 0)
|
|
63
|
+
return 0;
|
|
64
|
+
const oldItems = [...new Set(old.map((r) => r.item_id))];
|
|
65
|
+
// org-filter: an import relinks the deleted plugin's template connectors in every org by
|
|
66
|
+
// design, keyed by the deleted items' own template ids
|
|
67
|
+
const rows = await db
|
|
68
|
+
.updateTable("connectors")
|
|
69
|
+
.set({
|
|
70
|
+
platform_template_id: to.newTemplateId,
|
|
71
|
+
catalog_item_id: to.itemId,
|
|
72
|
+
catalog_version: to.version,
|
|
73
|
+
disabled_by_plugin_id: sql `case when disabled_by_plugin_id in (${sql.join(oldItems.map((id) => sql `${id}::uuid`))}) then ${to.itemId}::uuid else disabled_by_plugin_id end`,
|
|
74
|
+
updated_at: sql `now()`,
|
|
75
|
+
})
|
|
76
|
+
.where("deleted_at", "is", null)
|
|
77
|
+
.where("platform_template_id", "in", old.map((r) => r.id))
|
|
78
|
+
.returning("id")
|
|
79
|
+
.execute();
|
|
80
|
+
return rows.length;
|
|
81
|
+
}
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import type { ZodTypeAny } from "zod";
|
|
2
|
-
/**
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
*/
|
|
7
|
-
export declare function schemaHasPath(schema: ZodTypeAny, segs: string[], depth?: number): boolean;
|
|
2
|
+
/** Whether the Zod schema admits the template's editable path. */
|
|
3
|
+
export declare function schemaHasPath(schema: ZodTypeAny, segs: string[]): boolean;
|
|
4
|
+
/** The title shared by the endpoint field's titled alternatives, when available. */
|
|
5
|
+
export declare function schemaPathTitle(schema: ZodTypeAny, segs: string[]): string | undefined;
|