@capybara-hq/kernel 0.1.0-rc.115 → 0.1.0-rc.116
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.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/platform-components.js +13 -0
- package/dist/catalog/plugin-connectors.d.ts +35 -0
- package/dist/catalog/plugin-connectors.js +81 -0
- package/dist/channels/supervisor.d.ts +5 -1
- package/dist/channels/supervisor.js +17 -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 +31 -0
- package/dist/conversations/events.js +41 -2
- 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/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 +6 -1
- 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/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.js +43 -6
- package/dist/tools/specs.d.ts +13 -4
- package/dist/tools/specs.js +22 -8
- package/dist/tools/tools.module.js +7 -0
- 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 };
|
|
@@ -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.91";
|
|
212
212
|
};
|
|
213
213
|
/** Whether this deployment satisfies the entry's `minKernel`. */
|
|
214
214
|
export declare const entryCompatible: (e: Pick<MarketplaceEntry, "minKernel">) => boolean;
|
|
@@ -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
|
+
}
|
|
@@ -137,7 +137,11 @@ export declare class ChannelSupervisor {
|
|
|
137
137
|
private handOff;
|
|
138
138
|
/** After-release callback: tells the other replicas a connection of `plugin` is free to claim. */
|
|
139
139
|
private nudge;
|
|
140
|
-
/**
|
|
140
|
+
/**
|
|
141
|
+
* A renewal succeeded: one lease period connected in a row clears the failure count and the
|
|
142
|
+
* connection's `last_error`, so a failure the connection has recovered from does not stay on its
|
|
143
|
+
* page next to "running".
|
|
144
|
+
*/
|
|
141
145
|
private afterRenew;
|
|
142
146
|
/**
|
|
143
147
|
* 可以持有的连接:active、未删除、所属组织未删除、插件在该组织启用(组织停用插件 / 删除组织时持有方据此断开),
|
|
@@ -341,12 +341,28 @@ let ChannelSupervisor = class ChannelSupervisor {
|
|
|
341
341
|
.publish(CHANNEL_HANDOFF_TOPIC, { plugin, replicaId: this.replicaId })
|
|
342
342
|
.catch((err) => this.log.warn("cannot publish channel handoff", { err }));
|
|
343
343
|
}
|
|
344
|
-
/**
|
|
344
|
+
/**
|
|
345
|
+
* A renewal succeeded: one lease period connected in a row clears the failure count and the
|
|
346
|
+
* connection's `last_error`, so a failure the connection has recovered from does not stay on its
|
|
347
|
+
* page next to "running".
|
|
348
|
+
*/
|
|
345
349
|
async afterRenew(id, h, ttl) {
|
|
346
350
|
h.renewedAt = Date.now();
|
|
347
351
|
if (!h.stable && Date.now() - h.startedAt >= ttl) {
|
|
348
352
|
h.stable = true;
|
|
349
353
|
await this.redis.del(channelFailsKey(id)).catch(() => { });
|
|
354
|
+
try {
|
|
355
|
+
// org-filter: id is a connection this gateway supervisor holds the lease of, not caller input
|
|
356
|
+
await this.db
|
|
357
|
+
.updateTable("channel_connections")
|
|
358
|
+
.set({ last_error: null })
|
|
359
|
+
.where("id", "=", id)
|
|
360
|
+
.where("last_error", "is not", null)
|
|
361
|
+
.execute();
|
|
362
|
+
}
|
|
363
|
+
catch (e) {
|
|
364
|
+
this.log.warn("cannot clear channel error", { connectionId: id, err: e });
|
|
365
|
+
}
|
|
350
366
|
}
|
|
351
367
|
}
|
|
352
368
|
/**
|
|
@@ -53,20 +53,45 @@ declare const DownloadQuery: z.ZodObject<{
|
|
|
53
53
|
url: "url";
|
|
54
54
|
}>>;
|
|
55
55
|
}, z.core.$strip>;
|
|
56
|
+
/** One inline token of a message (composer inline tokens spec §3.1); its place is a U+FFFC in `text`. */
|
|
57
|
+
export declare const MessageTokenSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
58
|
+
type: z.ZodLiteral<"connector">;
|
|
59
|
+
connectorId: z.ZodUUID;
|
|
60
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
61
|
+
type: z.ZodLiteral<"resource">;
|
|
62
|
+
connectorId: z.ZodUUID;
|
|
63
|
+
uri: z.ZodString;
|
|
64
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
65
|
+
type: z.ZodLiteral<"file">;
|
|
66
|
+
id: z.ZodUUID;
|
|
67
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
68
|
+
type: z.ZodLiteral<"projectFile">;
|
|
69
|
+
path: z.ZodString;
|
|
70
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
71
|
+
type: z.ZodLiteral<"conversation">;
|
|
72
|
+
id: z.ZodString;
|
|
73
|
+
}, z.core.$strict>], "type">;
|
|
56
74
|
declare const MessageBody: z.ZodObject<{
|
|
57
75
|
text: z.ZodString;
|
|
58
76
|
clientMessageId: z.ZodOptional<z.ZodString>;
|
|
59
|
-
|
|
77
|
+
tokens: z.ZodOptional<z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
78
|
+
type: z.ZodLiteral<"connector">;
|
|
79
|
+
connectorId: z.ZodUUID;
|
|
80
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
81
|
+
type: z.ZodLiteral<"resource">;
|
|
60
82
|
connectorId: z.ZodUUID;
|
|
61
83
|
uri: z.ZodString;
|
|
62
|
-
}, z.core.$strict
|
|
63
|
-
|
|
64
|
-
|
|
84
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
85
|
+
type: z.ZodLiteral<"file">;
|
|
86
|
+
id: z.ZodUUID;
|
|
87
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
88
|
+
type: z.ZodLiteral<"projectFile">;
|
|
65
89
|
path: z.ZodString;
|
|
66
|
-
}, z.core.$strict
|
|
67
|
-
|
|
90
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
91
|
+
type: z.ZodLiteral<"conversation">;
|
|
68
92
|
id: z.ZodString;
|
|
69
|
-
}, z.core.$strict>>>;
|
|
93
|
+
}, z.core.$strict>], "type">>>;
|
|
94
|
+
files: z.ZodOptional<z.ZodArray<z.ZodUUID>>;
|
|
70
95
|
model: z.ZodOptional<z.ZodObject<{
|
|
71
96
|
provider: z.ZodString;
|
|
72
97
|
model: z.ZodString;
|
|
@@ -103,17 +128,24 @@ export declare const CreateBody: z.ZodObject<{
|
|
|
103
128
|
project: z.ZodOptional<z.ZodString & z.ZodType<string, string, z.core.$ZodTypeInternals<string, string>>>;
|
|
104
129
|
message: z.ZodOptional<z.ZodObject<{
|
|
105
130
|
text: z.ZodString;
|
|
106
|
-
|
|
131
|
+
tokens: z.ZodOptional<z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
132
|
+
type: z.ZodLiteral<"connector">;
|
|
133
|
+
connectorId: z.ZodUUID;
|
|
134
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
135
|
+
type: z.ZodLiteral<"resource">;
|
|
107
136
|
connectorId: z.ZodUUID;
|
|
108
137
|
uri: z.ZodString;
|
|
109
|
-
}, z.core.$strict
|
|
110
|
-
|
|
111
|
-
|
|
138
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
139
|
+
type: z.ZodLiteral<"file">;
|
|
140
|
+
id: z.ZodUUID;
|
|
141
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
142
|
+
type: z.ZodLiteral<"projectFile">;
|
|
112
143
|
path: z.ZodString;
|
|
113
|
-
}, z.core.$strict
|
|
114
|
-
|
|
144
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
145
|
+
type: z.ZodLiteral<"conversation">;
|
|
115
146
|
id: z.ZodString;
|
|
116
|
-
}, z.core.$strict>>>;
|
|
147
|
+
}, z.core.$strict>], "type">>>;
|
|
148
|
+
files: z.ZodOptional<z.ZodArray<z.ZodUUID>>;
|
|
117
149
|
model: z.ZodOptional<z.ZodObject<{
|
|
118
150
|
provider: z.ZodString;
|
|
119
151
|
model: z.ZodString;
|