@capybara-hq/kernel 0.1.0-rc.43 → 0.1.0-rc.45
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 +11 -11
- package/dist/catalog/scope-sync.d.ts +3 -2
- package/dist/catalog/scope-sync.js +3 -2
- package/dist/client/client-access.service.js +4 -4
- package/dist/ctx/create-ctx.d.ts +1 -1
- package/dist/extensions/enabled.d.ts +24 -4
- package/dist/extensions/enabled.js +47 -10
- package/dist/extensions/host.d.ts +3 -2
- package/dist/extensions/host.js +3 -2
- package/dist/extensions/org-config.d.ts +5 -2
- package/dist/extensions/org-config.js +32 -22
- package/dist/models/enablement.d.ts +1 -1
- package/dist/models/enablement.js +1 -1
- package/dist/runtime/providers.d.ts +1 -1
- package/dist/runtime/providers.js +1 -1
- package/dist/tools/registry.d.ts +2 -2
- package/dist/tools/registry.js +2 -2
- package/package.json +3 -3
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": "d83e667fb99d3251dc148ee2583ad8b4722b711f"
|
|
7
7
|
},
|
|
8
8
|
"plugins": [
|
|
9
9
|
{
|
|
@@ -34,8 +34,8 @@
|
|
|
34
34
|
"name": "openai",
|
|
35
35
|
"source": "npm",
|
|
36
36
|
"npm": "@capybara-hq/plugin-openai",
|
|
37
|
-
"version": "0.1.0-rc.
|
|
38
|
-
"integrity": "sha512-
|
|
37
|
+
"version": "0.1.0-rc.11",
|
|
38
|
+
"integrity": "sha512-vFV/CgyPyRdE2OJ2JO+esoDeJ2jP+6jMqIautSOHyCMvpWkrg3UGnUH1iBN1z1Dy0cp293ddwo2CZAmlS6FI7w==",
|
|
39
39
|
"required": false
|
|
40
40
|
},
|
|
41
41
|
{
|
|
@@ -50,16 +50,16 @@
|
|
|
50
50
|
"name": "bailian",
|
|
51
51
|
"source": "npm",
|
|
52
52
|
"npm": "@capybara-hq/plugin-bailian",
|
|
53
|
-
"version": "0.1.0-rc.
|
|
54
|
-
"integrity": "sha512-
|
|
53
|
+
"version": "0.1.0-rc.10",
|
|
54
|
+
"integrity": "sha512-yXDrvaJh3DtGg/hHpYFSJkoRxQdJCJQM6Y+mNLL1Cff53FraGYAZZi7ZIc1FnK9jFEp6nfHgnsuCJcvRmvpqqg==",
|
|
55
55
|
"required": false
|
|
56
56
|
},
|
|
57
57
|
{
|
|
58
58
|
"name": "ark",
|
|
59
59
|
"source": "npm",
|
|
60
60
|
"npm": "@capybara-hq/plugin-ark",
|
|
61
|
-
"version": "0.1.0-rc.
|
|
62
|
-
"integrity": "sha512-
|
|
61
|
+
"version": "0.1.0-rc.10",
|
|
62
|
+
"integrity": "sha512-8SRYcBBb/wROJX8ByBisL/SKNg7z4RvWFq8X7L+944QBzSed4YHwNATLRDTL4pW1l6VIC2rr+0DeSBCjmsF4Qw==",
|
|
63
63
|
"required": false
|
|
64
64
|
},
|
|
65
65
|
{
|
|
@@ -90,8 +90,8 @@
|
|
|
90
90
|
"name": "sandbox-docker",
|
|
91
91
|
"source": "npm",
|
|
92
92
|
"npm": "@capybara-hq/plugin-sandbox-docker",
|
|
93
|
-
"version": "0.1.0-rc.
|
|
94
|
-
"integrity": "sha512-
|
|
93
|
+
"version": "0.1.0-rc.19",
|
|
94
|
+
"integrity": "sha512-kzxoniwY4XgsjlfZTx6RAIao1P6876hED9fGnl8Z8USH7RE51t/3HbwUE5ljfhf7+pp0uB8M0eUjogVm8Jf3EA==",
|
|
95
95
|
"required": false
|
|
96
96
|
},
|
|
97
97
|
{
|
|
@@ -115,8 +115,8 @@
|
|
|
115
115
|
"name": "file-preview",
|
|
116
116
|
"source": "npm",
|
|
117
117
|
"npm": "@capybara-hq/plugin-file-preview",
|
|
118
|
-
"version": "0.1.0-rc.
|
|
119
|
-
"integrity": "sha512-
|
|
118
|
+
"version": "0.1.0-rc.2",
|
|
119
|
+
"integrity": "sha512-pEV/P8ahHt2wU3xudhUmJKX6sKfJCG+q+MNo0T+AiySl31TyPl7bsg9el5Romtg3iFbFlOh7DameL5YgAAzVnw==",
|
|
120
120
|
"required": false,
|
|
121
121
|
"builtin": true
|
|
122
122
|
}
|
|
@@ -22,8 +22,9 @@ import { type ScopeJob } from "./scope-jobs.js";
|
|
|
22
22
|
* `via: "scope"` install or uninstall, so a person's switch committed meanwhile wins.
|
|
23
23
|
* The sync writes no switch row: those record people's choices, and `wantedOn` honours them for
|
|
24
24
|
* every scope (an org that switched an `all` item off stays off, also across a scope change away
|
|
25
|
-
* and back, layering spec §4). Builtin items are left alone
|
|
26
|
-
* extension
|
|
25
|
+
* and back, layering spec §4). Builtin items are left alone: they are on everywhere without an org
|
|
26
|
+
* install, and their extension is enabled in every org by `enabled.ts` (required or not). A
|
|
27
|
+
* failed install, uninstall or dependency install is logged, audited
|
|
27
28
|
* `plugin.scope_sync_failed`, kept as the pair's open failure (`plugin_scope_sync_failures`, the
|
|
28
29
|
* super admin's inbox, until a later sync of the pair does not fail) and not retried until the next
|
|
29
30
|
* sync of the item. An error outside those steps (a read, the failure write itself) ends the attempt
|
|
@@ -40,8 +40,9 @@ import { ScopeNoLongerWanted, ScopeStillWanted } from "./scope-state.js";
|
|
|
40
40
|
* `via: "scope"` install or uninstall, so a person's switch committed meanwhile wins.
|
|
41
41
|
* The sync writes no switch row: those record people's choices, and `wantedOn` honours them for
|
|
42
42
|
* every scope (an org that switched an `all` item off stays off, also across a scope change away
|
|
43
|
-
* and back, layering spec §4). Builtin items are left alone
|
|
44
|
-
* extension
|
|
43
|
+
* and back, layering spec §4). Builtin items are left alone: they are on everywhere without an org
|
|
44
|
+
* install, and their extension is enabled in every org by `enabled.ts` (required or not). A
|
|
45
|
+
* failed install, uninstall or dependency install is logged, audited
|
|
45
46
|
* `plugin.scope_sync_failed`, kept as the pair's open failure (`plugin_scope_sync_failures`, the
|
|
46
47
|
* super admin's inbox, until a later sync of the pair does not fail) and not retried until the next
|
|
47
48
|
* sync of the item. An error outside those steps (a read, the failure write itself) ends the attempt
|
|
@@ -11,7 +11,7 @@ import { CLIENT_API_VERSION, EXTENSION_NAME_RE, resolveUiSlots, validateUiContri
|
|
|
11
11
|
import { Inject, Injectable } from "@nestjs/common";
|
|
12
12
|
import { sql } from "kysely";
|
|
13
13
|
import { ApiError } from "../errors.js";
|
|
14
|
-
import { enabledExtensionsQuery } from "../extensions/enabled.js";
|
|
14
|
+
import { alwaysOnExtensionsQuery, enabledExtensionsQuery } from "../extensions/enabled.js";
|
|
15
15
|
import { STALE_RECONCILE_PERIODS } from "../extensions/lifecycle-topics.js";
|
|
16
16
|
import { CLIENT_EXTENSIONS_SETTING, parseClientExtensions, readClientExtensions, } from "../identity/settings.js";
|
|
17
17
|
import { KernelConfigService } from "../infra/config/kernel-config.service.js";
|
|
@@ -191,8 +191,8 @@ let ClientAccess = class ClientAccess {
|
|
|
191
191
|
.select("value")
|
|
192
192
|
.where("key", "=", CLIENT_EXTENSIONS_SETTING)
|
|
193
193
|
.as("kill"),
|
|
194
|
-
// enabled.ts's two sources, per account:
|
|
195
|
-
// otherwise the org's own switch row
|
|
194
|
+
// enabled.ts's two sources, per account: an always-on extension (required, or its plugin
|
|
195
|
+
// is builtin) is on in every org, otherwise the org's own switch row
|
|
196
196
|
eb
|
|
197
197
|
.exists(eb
|
|
198
198
|
.selectFrom("memberships as m")
|
|
@@ -201,7 +201,7 @@ let ClientAccess = class ClientAccess {
|
|
|
201
201
|
.where("m.account_id", "=", accountId)
|
|
202
202
|
.where("o.deleted_at", "is", null)
|
|
203
203
|
.where((w) => w.or([
|
|
204
|
-
w("i.
|
|
204
|
+
w("i.name", "in", alwaysOnExtensionsQuery(db)),
|
|
205
205
|
w.exists(w
|
|
206
206
|
.selectFrom("extension_org_configs as c")
|
|
207
207
|
.select(sql `1`.as("one"))
|
package/dist/ctx/create-ctx.d.ts
CHANGED
|
@@ -94,7 +94,7 @@ export interface ExtensionPointAccess {
|
|
|
94
94
|
plugin: string;
|
|
95
95
|
impl: unknown;
|
|
96
96
|
}[];
|
|
97
|
-
/** Names of the extensions enabled in the organization (`extension_org_configs.enabled` plus
|
|
97
|
+
/** Names of the extensions enabled in the organization (`extension_org_configs.enabled` plus always-on extensions, `enabled.ts`); queried every time, not cached. */
|
|
98
98
|
enabledPlugins(orgId: string): Promise<Set<string>>;
|
|
99
99
|
/**
|
|
100
100
|
* Whether the extension's effective config is valid in the organization (layering spec A §6):
|
|
@@ -3,11 +3,26 @@ import type { KernelSchemaDb } from "../db/kernel-schema.js";
|
|
|
3
3
|
* Which extensions an organization has enabled. Two sources, and every reader goes through these
|
|
4
4
|
* helpers so none of them misses one:
|
|
5
5
|
* - `extension_org_configs.enabled` (the org's own switch);
|
|
6
|
-
* - every
|
|
7
|
-
*
|
|
6
|
+
* - every always-on extension ({@link alwaysOnExtensionsQuery}): enabled in every org, existing and
|
|
7
|
+
* future, without an org config row, whatever such a row says. That is a required bootstrap
|
|
8
|
+
* plugin (`extension_installs.required`, package ecosystem spec §7) and an extension shipped in a
|
|
9
|
+
* builtin platform plugin (a live `catalog_items` row with `builtin`, recorded on its install or in
|
|
10
|
+
* `extension_catalog_sources`; a `builtin: true` bootstrap entry is builtin without being
|
|
11
|
+
* required). A builtin plugin is on in every org and its org switch is locked (`wantedOn`,
|
|
12
|
+
* `itemLocked`), so its extension must be on too: the scope sync leaves builtin items alone.
|
|
8
13
|
* Neither checks that the extension is loaded on this replica or enabled on the deployment; callers
|
|
9
|
-
* that need that check it themselves, as before.
|
|
14
|
+
* that need that check it themselves, as before. Plain SQL read on every call (no cache), so every
|
|
15
|
+
* replica sees a change at once. `db` may be a transaction.
|
|
10
16
|
*/
|
|
17
|
+
/**
|
|
18
|
+
* The names of the always-on extensions (a subquery with one column, `plugin`): required bootstrap
|
|
19
|
+
* plugins and the extensions of live builtin platform plugins (see the file header).
|
|
20
|
+
*/
|
|
21
|
+
export declare function alwaysOnExtensionsQuery(db: KernelSchemaDb): import("kysely").SelectQueryBuilder<import("../db/kernel-schema.js").KernelDatabase & {
|
|
22
|
+
ri: import("../db/kernel-schema.js").ExtensionInstallsTable;
|
|
23
|
+
}, "ri", {
|
|
24
|
+
plugin: string;
|
|
25
|
+
}>;
|
|
11
26
|
/** The names of the extensions enabled in `orgId` (a subquery with one column, `plugin`). */
|
|
12
27
|
export declare function enabledExtensionsQuery(db: KernelSchemaDb, orgId: string): import("kysely").SelectQueryBuilder<import("../db/kernel-schema.js").KernelDatabase & {
|
|
13
28
|
eoc: import("../db/kernel-schema.js").ExtensionOrgConfigsTable;
|
|
@@ -27,5 +42,10 @@ export declare function enabledExtensionsByOrg(db: KernelSchemaDb): import("kyse
|
|
|
27
42
|
}>;
|
|
28
43
|
/** Whether `plugin` is enabled in `orgId` (see the file header). */
|
|
29
44
|
export declare function isExtensionEnabled(db: KernelSchemaDb, orgId: string, plugin: string): Promise<boolean>;
|
|
30
|
-
/**
|
|
45
|
+
/**
|
|
46
|
+
* The names of the required bootstrap plugins (installed with `required`): the ones that refuse
|
|
47
|
+
* `extension.required`. Whether an extension is on in every org is {@link alwaysOnExtensions}.
|
|
48
|
+
*/
|
|
31
49
|
export declare function requiredExtensions(db: KernelSchemaDb): Promise<Set<string>>;
|
|
50
|
+
/** The names of the always-on extensions ({@link alwaysOnExtensionsQuery}). */
|
|
51
|
+
export declare function alwaysOnExtensions(db: KernelSchemaDb): Promise<Set<string>>;
|
|
@@ -3,11 +3,43 @@ import { sql } from "kysely";
|
|
|
3
3
|
* Which extensions an organization has enabled. Two sources, and every reader goes through these
|
|
4
4
|
* helpers so none of them misses one:
|
|
5
5
|
* - `extension_org_configs.enabled` (the org's own switch);
|
|
6
|
-
* - every
|
|
7
|
-
*
|
|
6
|
+
* - every always-on extension ({@link alwaysOnExtensionsQuery}): enabled in every org, existing and
|
|
7
|
+
* future, without an org config row, whatever such a row says. That is a required bootstrap
|
|
8
|
+
* plugin (`extension_installs.required`, package ecosystem spec §7) and an extension shipped in a
|
|
9
|
+
* builtin platform plugin (a live `catalog_items` row with `builtin`, recorded on its install or in
|
|
10
|
+
* `extension_catalog_sources`; a `builtin: true` bootstrap entry is builtin without being
|
|
11
|
+
* required). A builtin plugin is on in every org and its org switch is locked (`wantedOn`,
|
|
12
|
+
* `itemLocked`), so its extension must be on too: the scope sync leaves builtin items alone.
|
|
8
13
|
* Neither checks that the extension is loaded on this replica or enabled on the deployment; callers
|
|
9
|
-
* that need that check it themselves, as before.
|
|
14
|
+
* that need that check it themselves, as before. Plain SQL read on every call (no cache), so every
|
|
15
|
+
* replica sees a change at once. `db` may be a transaction.
|
|
10
16
|
*/
|
|
17
|
+
/**
|
|
18
|
+
* The names of the always-on extensions (a subquery with one column, `plugin`): required bootstrap
|
|
19
|
+
* plugins and the extensions of live builtin platform plugins (see the file header).
|
|
20
|
+
*/
|
|
21
|
+
export function alwaysOnExtensionsQuery(db) {
|
|
22
|
+
return db
|
|
23
|
+
.selectFrom("extension_installs as ri")
|
|
24
|
+
.select("ri.name as plugin")
|
|
25
|
+
.where("ri.required", "=", true)
|
|
26
|
+
.union(db
|
|
27
|
+
.selectFrom("extension_installs as ei")
|
|
28
|
+
.innerJoin("catalog_items as ci", "ci.id", "ei.catalog_item_id")
|
|
29
|
+
.select("ei.name as plugin")
|
|
30
|
+
.where("ci.builtin", "=", true)
|
|
31
|
+
.where("ci.disabled", "=", false)
|
|
32
|
+
.where("ci.deleted_at", "is", null)
|
|
33
|
+
.where("ci.owner_org_id", "is", null))
|
|
34
|
+
.union(db
|
|
35
|
+
.selectFrom("extension_catalog_sources as cs")
|
|
36
|
+
.innerJoin("catalog_items as si", "si.id", "cs.item_id")
|
|
37
|
+
.select("cs.plugin as plugin")
|
|
38
|
+
.where("si.builtin", "=", true)
|
|
39
|
+
.where("si.disabled", "=", false)
|
|
40
|
+
.where("si.deleted_at", "is", null)
|
|
41
|
+
.where("si.owner_org_id", "is", null));
|
|
42
|
+
}
|
|
11
43
|
/** The names of the extensions enabled in `orgId` (a subquery with one column, `plugin`). */
|
|
12
44
|
export function enabledExtensionsQuery(db, orgId) {
|
|
13
45
|
return db
|
|
@@ -15,10 +47,7 @@ export function enabledExtensionsQuery(db, orgId) {
|
|
|
15
47
|
.select("eoc.plugin as plugin")
|
|
16
48
|
.where("eoc.org_id", "=", orgId)
|
|
17
49
|
.where("eoc.enabled", "=", true)
|
|
18
|
-
.union(db
|
|
19
|
-
.selectFrom("extension_installs as ri")
|
|
20
|
-
.select("ri.name as plugin")
|
|
21
|
-
.where("ri.required", "=", true));
|
|
50
|
+
.union(db.selectFrom(alwaysOnExtensionsQuery(db).as("ao")).select("ao.plugin as plugin"));
|
|
22
51
|
}
|
|
23
52
|
/**
|
|
24
53
|
* Every (org, extension) pair that is enabled, for queries that join it (columns `org_id`,
|
|
@@ -32,8 +61,8 @@ export function enabledExtensionsByOrg(db) {
|
|
|
32
61
|
.where("eoc.enabled", "=", true)
|
|
33
62
|
.union(db
|
|
34
63
|
.selectFrom("orgs as ro")
|
|
35
|
-
.innerJoin(
|
|
36
|
-
.select(["ro.id as org_id", "
|
|
64
|
+
.innerJoin(alwaysOnExtensionsQuery(db).as("ao"), (j) => j.onTrue())
|
|
65
|
+
.select(["ro.id as org_id", "ao.plugin as plugin"]));
|
|
37
66
|
}
|
|
38
67
|
/** Whether `plugin` is enabled in `orgId` (see the file header). */
|
|
39
68
|
export async function isExtensionEnabled(db, orgId, plugin) {
|
|
@@ -44,7 +73,10 @@ export async function isExtensionEnabled(db, orgId, plugin) {
|
|
|
44
73
|
.executeTakeFirst();
|
|
45
74
|
return row !== undefined;
|
|
46
75
|
}
|
|
47
|
-
/**
|
|
76
|
+
/**
|
|
77
|
+
* The names of the required bootstrap plugins (installed with `required`): the ones that refuse
|
|
78
|
+
* `extension.required`. Whether an extension is on in every org is {@link alwaysOnExtensions}.
|
|
79
|
+
*/
|
|
48
80
|
export async function requiredExtensions(db) {
|
|
49
81
|
const rows = await db
|
|
50
82
|
.selectFrom("extension_installs")
|
|
@@ -53,3 +85,8 @@ export async function requiredExtensions(db) {
|
|
|
53
85
|
.execute();
|
|
54
86
|
return new Set(rows.map((r) => r.name));
|
|
55
87
|
}
|
|
88
|
+
/** The names of the always-on extensions ({@link alwaysOnExtensionsQuery}). */
|
|
89
|
+
export async function alwaysOnExtensions(db) {
|
|
90
|
+
const rows = await alwaysOnExtensionsQuery(db).execute();
|
|
91
|
+
return new Set(rows.map((r) => r.plugin));
|
|
92
|
+
}
|
|
@@ -493,8 +493,9 @@ export declare class ExtensionHost {
|
|
|
493
493
|
/** 配置声明的插件名 → 来源(安装包不能与它们重名)。 */
|
|
494
494
|
declared(): Map<string, ExtensionSource>;
|
|
495
495
|
/**
|
|
496
|
-
* Extensions enabled in the org: `extension_org_configs.enabled` plus every
|
|
497
|
-
*
|
|
496
|
+
* Extensions enabled in the org: `extension_org_configs.enabled` plus every always-on extension
|
|
497
|
+
* (required bootstrap plugins, builtin plugins' extensions; see `enabled.ts`); queried every
|
|
498
|
+
* time, not cached.
|
|
498
499
|
* Cost (M-4): hooks call this on every run, so one PG query per model attempt and per tool call.
|
|
499
500
|
* Acceptable for now; if a cache is ever added, give it a short TTL so an org disabling a plugin
|
|
500
501
|
* takes effect quickly.
|
package/dist/extensions/host.js
CHANGED
|
@@ -1671,8 +1671,9 @@ let ExtensionHost = class ExtensionHost {
|
|
|
1671
1671
|
return this.registry.declared();
|
|
1672
1672
|
}
|
|
1673
1673
|
/**
|
|
1674
|
-
* Extensions enabled in the org: `extension_org_configs.enabled` plus every
|
|
1675
|
-
*
|
|
1674
|
+
* Extensions enabled in the org: `extension_org_configs.enabled` plus every always-on extension
|
|
1675
|
+
* (required bootstrap plugins, builtin plugins' extensions; see `enabled.ts`); queried every
|
|
1676
|
+
* time, not cached.
|
|
1676
1677
|
* Cost (M-4): hooks call this on every run, so one PG query per model attempt and per tool call.
|
|
1677
1678
|
* Acceptable for now; if a cache is ever added, give it a short TTL so an org disabling a plugin
|
|
1678
1679
|
* takes effect quickly.
|
|
@@ -48,7 +48,9 @@ export interface OrgExtensionView {
|
|
|
48
48
|
reason?: ExtensionUnavailableReason;
|
|
49
49
|
/**
|
|
50
50
|
* A required bootstrap plugin: enabled in every org (`enabled` is always true) and cannot be
|
|
51
|
-
* disabled here (`extension.required`); its org config, when it has one, can still be set.
|
|
51
|
+
* disabled here (`extension.required`); its org config, when it has one, can still be set. An
|
|
52
|
+
* extension of a builtin plugin is enabled in every org as well (`enabled.ts`) without being
|
|
53
|
+
* required: it is locked by its plugin (`switchable` false, `plugin.scope_locked`).
|
|
52
54
|
*/
|
|
53
55
|
required: boolean;
|
|
54
56
|
/** The catalog plugin the extension ships in and its scope (builtin counts as `all`); null without one. */
|
|
@@ -217,7 +219,8 @@ export declare class OrgExtensionConfigs {
|
|
|
217
219
|
private assertSwitchRules;
|
|
218
220
|
/**
|
|
219
221
|
* 读取并解密某插件在该组织下的完整配置(供运行时按组织构造插件实例)。
|
|
220
|
-
*
|
|
222
|
+
* An always-on extension (a required bootstrap plugin, or its plugin is builtin: `enabled.ts`) is
|
|
223
|
+
* enabled without a row (its stored config, or `{}`, is validated).
|
|
221
224
|
* 无记录 → undefined;插件无 `config.org` 或已停用(`enabled=false`,不校验、不读密钥)时 `config` 为 null。
|
|
222
225
|
* 配置行与密钥在同一个 `REPEATABLE READ` 只读事务里读取。
|
|
223
226
|
* A stored config that no longer matches the schema (e.g. after a plugin upgrade) throws
|
|
@@ -24,7 +24,7 @@ import { OrgLock } from "../orgs/org-lock.js";
|
|
|
24
24
|
import { toIssues } from "./config-issues.js";
|
|
25
25
|
import { configMessages, safeConfigFormSchema } from "./config-json-schema.js";
|
|
26
26
|
import { EffectiveConfigs } from "./effective-config.js";
|
|
27
|
-
import { enabledExtensionsQuery, requiredExtensions } from "./enabled.js";
|
|
27
|
+
import { alwaysOnExtensions, enabledExtensionsQuery, requiredExtensions } from "./enabled.js";
|
|
28
28
|
import { ExtensionHost } from "./host.js";
|
|
29
29
|
import { ExtensionInstalls } from "./installs.js";
|
|
30
30
|
import { fieldLevels } from "./org-levels.js";
|
|
@@ -216,8 +216,10 @@ let OrgExtensionConfigs = class OrgExtensionConfigs {
|
|
|
216
216
|
.execute();
|
|
217
217
|
await this.afterConfigRowRead?.();
|
|
218
218
|
const setKeys = await this.setSecretKeys(t, orgId);
|
|
219
|
-
// Required bootstrap plugins are listed enabled (no org
|
|
219
|
+
// Required bootstrap plugins and builtin plugins' extensions are listed enabled (no org
|
|
220
|
+
// config row needed, spec §7; enabled.ts)
|
|
220
221
|
const required = await requiredExtensions(t);
|
|
222
|
+
const on = await alwaysOnExtensions(t);
|
|
221
223
|
const loaded = this.host.manifests();
|
|
222
224
|
const items = await pluginItemsOf(t, [
|
|
223
225
|
...loaded.map((m) => m.name),
|
|
@@ -228,13 +230,13 @@ let OrgExtensionConfigs = class OrgExtensionConfigs {
|
|
|
228
230
|
const listed = await scopeListedFor(t, orgId);
|
|
229
231
|
const seen = (name) => offeredToOrg({
|
|
230
232
|
required: required.has(name),
|
|
231
|
-
enabled: rows.find((r) => r.plugin === name)?.enabled ?? false,
|
|
233
|
+
enabled: on.has(name) || (rows.find((r) => r.plugin === name)?.enabled ?? false),
|
|
232
234
|
items: items.get(name),
|
|
233
235
|
listed,
|
|
234
236
|
});
|
|
235
237
|
const views = loaded
|
|
236
238
|
.filter((m) => seen(m.name))
|
|
237
|
-
.map((m) => this.view(m, rows.find((r) => r.plugin === m.name), setKeys, required.has(m.name), items.get(m.name)));
|
|
239
|
+
.map((m) => this.view(m, rows.find((r) => r.plugin === m.name), setKeys, required.has(m.name), items.get(m.name), on.has(m.name)));
|
|
238
240
|
const names = new Set(loaded.map((m) => m.name));
|
|
239
241
|
const unavailable = installed
|
|
240
242
|
.filter((i) => !names.has(i.name) && seen(i.name))
|
|
@@ -242,7 +244,7 @@ let OrgExtensionConfigs = class OrgExtensionConfigs {
|
|
|
242
244
|
.map((i) => ({
|
|
243
245
|
plugin: i.name,
|
|
244
246
|
version: i.version,
|
|
245
|
-
enabled:
|
|
247
|
+
enabled: on.has(i.name) || (rows.find((r) => r.plugin === i.name)?.enabled ?? false),
|
|
246
248
|
configurable: false,
|
|
247
249
|
config: null,
|
|
248
250
|
secrets: [],
|
|
@@ -312,18 +314,22 @@ let OrgExtensionConfigs = class OrgExtensionConfigs {
|
|
|
312
314
|
.where("org_id", "=", orgId)
|
|
313
315
|
.executeTakeFirst();
|
|
314
316
|
const required = (await requiredExtensions(t)).has(plugin);
|
|
317
|
+
// Always on (required, or its plugin is builtin): enabled in every org (enabled.ts)
|
|
318
|
+
const on = required || (await alwaysOnExtensions(t)).has(plugin);
|
|
315
319
|
const item = (await pluginItemsOf(t, [plugin])).get(plugin);
|
|
316
320
|
if (required && input.enabled === false)
|
|
317
321
|
throw requiredError(plugin);
|
|
318
|
-
if (
|
|
322
|
+
if (on && input.enabled === false)
|
|
323
|
+
throw scopeLockedError();
|
|
324
|
+
if (opts.ifDisabled && (row?.enabled === true || on)) {
|
|
319
325
|
opts.ifDisabled.skipped = true;
|
|
320
|
-
return this.view(manifest, row, await this.setSecretKeys(t, orgId), required, item);
|
|
326
|
+
return this.view(manifest, row, await this.setSecretKeys(t, orgId), required, item, on);
|
|
321
327
|
}
|
|
322
|
-
//
|
|
323
|
-
const enabled =
|
|
328
|
+
// An always-on extension is enabled whatever the row said (it may predate `required` / builtin)
|
|
329
|
+
const enabled = on || (input.enabled ?? row?.enabled ?? false);
|
|
324
330
|
// validateOnly: the rules for (newly) enabling and disabling belong to the write that follows
|
|
325
331
|
if (!opts.validateOnly) {
|
|
326
|
-
await this.assertSwitchRules(t, orgId, manifest, input, row,
|
|
332
|
+
await this.assertSwitchRules(t, orgId, manifest, input, row, on, opts);
|
|
327
333
|
}
|
|
328
334
|
let plain = row?.config ?? null;
|
|
329
335
|
let changed = [];
|
|
@@ -376,7 +382,7 @@ let OrgExtensionConfigs = class OrgExtensionConfigs {
|
|
|
376
382
|
}
|
|
377
383
|
// Also without an org config schema: nothing is written
|
|
378
384
|
if (opts.validateOnly) {
|
|
379
|
-
return this.view(manifest, row, await this.setSecretKeys(t, orgId), required, item);
|
|
385
|
+
return this.view(manifest, row, await this.setSecretKeys(t, orgId), required, item, on);
|
|
380
386
|
}
|
|
381
387
|
// 当前 schema 中已不存在的密钥路径:同一事务内清掉遗留的密文行
|
|
382
388
|
const live = new Set((schema ? secretPaths(schema) : []).map((p) => secretKey(plugin, p)));
|
|
@@ -421,7 +427,7 @@ let OrgExtensionConfigs = class OrgExtensionConfigs {
|
|
|
421
427
|
.where("plugin", "=", plugin)
|
|
422
428
|
.where("org_id", "=", orgId)
|
|
423
429
|
.executeTakeFirst();
|
|
424
|
-
const view = this.view(manifest, saved, await this.setSecretKeys(t, orgId), required, item);
|
|
430
|
+
const view = this.view(manifest, saved, await this.setSecretKeys(t, orgId), required, item, on);
|
|
425
431
|
// Only once the root transaction committed (an outer caller's too): a rolled-back write
|
|
426
432
|
// registers no secrets and disconnects nothing
|
|
427
433
|
afterCommit(async () => {
|
|
@@ -435,9 +441,9 @@ let OrgExtensionConfigs = class OrgExtensionConfigs {
|
|
|
435
441
|
* re-checks the item policy and grants (C22; one already enabled is unaffected), enabling needs
|
|
436
442
|
* the dependencies enabled, disabling (without `force`) no enabled dependents.
|
|
437
443
|
*/
|
|
438
|
-
async assertSwitchRules(t, orgId, manifest, input, row,
|
|
444
|
+
async assertSwitchRules(t, orgId, manifest, input, row, alwaysOn, opts) {
|
|
439
445
|
const plugin = manifest.name;
|
|
440
|
-
if (input.enabled === true && row?.enabled !== true && !
|
|
446
|
+
if (input.enabled === true && row?.enabled !== true && !alwaysOn) {
|
|
441
447
|
// 插件自己的条目 disabled 是总开关,任何途径都不能新启用(裁决 M-5)
|
|
442
448
|
const killed = await disabledPluginItems(t, [plugin]);
|
|
443
449
|
if (killed.length > 0)
|
|
@@ -457,7 +463,8 @@ let OrgExtensionConfigs = class OrgExtensionConfigs {
|
|
|
457
463
|
}
|
|
458
464
|
/**
|
|
459
465
|
* 读取并解密某插件在该组织下的完整配置(供运行时按组织构造插件实例)。
|
|
460
|
-
*
|
|
466
|
+
* An always-on extension (a required bootstrap plugin, or its plugin is builtin: `enabled.ts`) is
|
|
467
|
+
* enabled without a row (its stored config, or `{}`, is validated).
|
|
461
468
|
* 无记录 → undefined;插件无 `config.org` 或已停用(`enabled=false`,不校验、不读密钥)时 `config` 为 null。
|
|
462
469
|
* 配置行与密钥在同一个 `REPEATABLE READ` 只读事务里读取。
|
|
463
470
|
* A stored config that no longer matches the schema (e.g. after a plugin upgrade) throws
|
|
@@ -483,10 +490,10 @@ let OrgExtensionConfigs = class OrgExtensionConfigs {
|
|
|
483
490
|
.where("org_id", "=", orgId)
|
|
484
491
|
.executeTakeFirst();
|
|
485
492
|
await this.afterConfigRowRead?.();
|
|
486
|
-
const
|
|
487
|
-
if (!row && !
|
|
493
|
+
const on = (await alwaysOnExtensions(t)).has(plugin);
|
|
494
|
+
if (!row && !on)
|
|
488
495
|
return undefined;
|
|
489
|
-
const enabled =
|
|
496
|
+
const enabled = on || row?.enabled === true;
|
|
490
497
|
const schema = manifest.config?.org;
|
|
491
498
|
// 已停用的插件不会被实例化:不校验(可能是升级前存下的旧配置),也不解密密钥
|
|
492
499
|
if (!schema || !enabled)
|
|
@@ -544,8 +551,8 @@ let OrgExtensionConfigs = class OrgExtensionConfigs {
|
|
|
544
551
|
*/
|
|
545
552
|
async disableIn(orgId, plugin, actorAccountId, reason) {
|
|
546
553
|
const t = this.db;
|
|
547
|
-
//
|
|
548
|
-
if ((await
|
|
554
|
+
// An always-on extension (required, or its plugin is builtin) stays enabled in every org
|
|
555
|
+
if ((await alwaysOnExtensions(t)).has(plugin))
|
|
549
556
|
return false;
|
|
550
557
|
const r = await t
|
|
551
558
|
.updateTable("extension_org_configs")
|
|
@@ -635,7 +642,9 @@ let OrgExtensionConfigs = class OrgExtensionConfigs {
|
|
|
635
642
|
throw new ApiError("extension.not_found", `Extension ${plugin} is not installed`);
|
|
636
643
|
return set;
|
|
637
644
|
}
|
|
638
|
-
view(m, row, setKeys, required, items
|
|
645
|
+
view(m, row, setKeys, required, items,
|
|
646
|
+
/** Always on in every org (enabled.ts): required, or its plugin is builtin. */
|
|
647
|
+
alwaysOn) {
|
|
639
648
|
const schema = m.config?.org;
|
|
640
649
|
const paths = schema ? secretPaths(schema) : [];
|
|
641
650
|
let config = null;
|
|
@@ -647,7 +656,7 @@ let OrgExtensionConfigs = class OrgExtensionConfigs {
|
|
|
647
656
|
return {
|
|
648
657
|
plugin: m.name,
|
|
649
658
|
version: m.version,
|
|
650
|
-
enabled:
|
|
659
|
+
enabled: alwaysOn || (row?.enabled ?? false),
|
|
651
660
|
configurable: schema !== undefined,
|
|
652
661
|
config,
|
|
653
662
|
secrets: paths.map((p) => ({ path: p, set: setKeys.has(secretKey(m.name, p)) })),
|
|
@@ -753,4 +762,5 @@ function orgConfigIncomplete(schema, plain, secretSet) {
|
|
|
753
762
|
const secrets = secretPaths(schema).filter(secretSet);
|
|
754
763
|
return toIssues(r.error).some((i) => !secrets.some((p) => i.path === p || i.path.startsWith(`${p}.`)));
|
|
755
764
|
}
|
|
765
|
+
const scopeLockedError = () => new ApiError("plugin.scope_locked", "This plugin is built in: it is on for every organization and cannot be switched off here");
|
|
756
766
|
const requiredError = (plugin) => new ApiError("extension.required", `Extension ${plugin} is required by this deployment (a bootstrap plugin): it is enabled in every organization and cannot be disabled`);
|
|
@@ -65,7 +65,7 @@ export declare class ModelEnablement {
|
|
|
65
65
|
private rowsOf;
|
|
66
66
|
/**
|
|
67
67
|
* The extensions enabled in `orgId` ({@link enabledExtensionsQuery}: the org's own switch on, or
|
|
68
|
-
* a required bootstrap plugin): a model provider is on in an org only then, like every other
|
|
68
|
+
* always on: a required bootstrap plugin or a builtin plugin's extension): a model provider is on in an org only then, like every other
|
|
69
69
|
* extension. Read from PG on every call (one small query; the switch has its own writers, nothing
|
|
70
70
|
* to evict).
|
|
71
71
|
*/
|
|
@@ -75,7 +75,7 @@ let ModelEnablement = class ModelEnablement {
|
|
|
75
75
|
}
|
|
76
76
|
/**
|
|
77
77
|
* The extensions enabled in `orgId` ({@link enabledExtensionsQuery}: the org's own switch on, or
|
|
78
|
-
* a required bootstrap plugin): a model provider is on in an org only then, like every other
|
|
78
|
+
* always on: a required bootstrap plugin or a builtin plugin's extension): a model provider is on in an org only then, like every other
|
|
79
79
|
* extension. Read from PG on every call (one small query; the switch has its own writers, nothing
|
|
80
80
|
* to evict).
|
|
81
81
|
*/
|
|
@@ -101,7 +101,7 @@ export declare class ProviderListError extends ApiError {
|
|
|
101
101
|
* Org-bound (spec B §5.5, A §6): every list and call is made for an org with the provider's
|
|
102
102
|
* effective config there (`EffectiveConfigs.get`), passed as `{ orgId, config }`. A provider is on
|
|
103
103
|
* in an org only when the org enabled it, like every other extension (`enabledExtensionsQuery`: the
|
|
104
|
-
* org's switch on, or
|
|
104
|
+
* org's switch on, or always on: required or builtin); one not enabled there, or whose effective
|
|
105
105
|
* config is not valid there, offers no models there. The admin view (no org) lists with the
|
|
106
106
|
* platform config.
|
|
107
107
|
*
|
|
@@ -128,7 +128,7 @@ export class ProviderListError extends ApiError {
|
|
|
128
128
|
* Org-bound (spec B §5.5, A §6): every list and call is made for an org with the provider's
|
|
129
129
|
* effective config there (`EffectiveConfigs.get`), passed as `{ orgId, config }`. A provider is on
|
|
130
130
|
* in an org only when the org enabled it, like every other extension (`enabledExtensionsQuery`: the
|
|
131
|
-
* org's switch on, or
|
|
131
|
+
* org's switch on, or always on: required or builtin); one not enabled there, or whose effective
|
|
132
132
|
* config is not valid there, offers no models there. The admin view (no org) lists with the
|
|
133
133
|
* platform config.
|
|
134
134
|
*
|
package/dist/tools/registry.d.ts
CHANGED
|
@@ -266,8 +266,8 @@ export interface AgentTools {
|
|
|
266
266
|
* - builtins: every {@link AGENT_BUILTIN_NAMES} entry registered here that can run (`unavailable`
|
|
267
267
|
* says why not), `TaskOutput` / `TaskStop` / `TaskList` with `Bash`, `Agent` while its roster is not empty;
|
|
268
268
|
* - extension tools: every tool registered by an extension loaded on this replica and enabled in
|
|
269
|
-
* the org (`extension_org_configs.enabled`; required bootstrap plugins
|
|
270
|
-
* `enabled.ts`), whose effective config for the org is valid (layering spec A §6) and that the
|
|
269
|
+
* the org (`extension_org_configs.enabled`; required bootstrap plugins and builtin plugins'
|
|
270
|
+
* extensions are enabled in every org, `enabled.ts`), whose effective config for the org is valid (layering spec A §6) and that the
|
|
271
271
|
* org did not switch off (§7: the org's switch wins);
|
|
272
272
|
* - connector tools: every enabled tool of every live, active connector of the org whose
|
|
273
273
|
* connector extension is installed, with a valid key.
|
package/dist/tools/registry.js
CHANGED
|
@@ -95,8 +95,8 @@ const builtinTool = (b, spec) => ({
|
|
|
95
95
|
* - builtins: every {@link AGENT_BUILTIN_NAMES} entry registered here that can run (`unavailable`
|
|
96
96
|
* says why not), `TaskOutput` / `TaskStop` / `TaskList` with `Bash`, `Agent` while its roster is not empty;
|
|
97
97
|
* - extension tools: every tool registered by an extension loaded on this replica and enabled in
|
|
98
|
-
* the org (`extension_org_configs.enabled`; required bootstrap plugins
|
|
99
|
-
* `enabled.ts`), whose effective config for the org is valid (layering spec A §6) and that the
|
|
98
|
+
* the org (`extension_org_configs.enabled`; required bootstrap plugins and builtin plugins'
|
|
99
|
+
* extensions are enabled in every org, `enabled.ts`), whose effective config for the org is valid (layering spec A §6) and that the
|
|
100
100
|
* org did not switch off (§7: the org's switch wins);
|
|
101
101
|
* - connector tools: every enabled tool of every live, active connector of the org whose
|
|
102
102
|
* connector extension is installed, with a valid key.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capybara-hq/kernel",
|
|
3
|
-
"version": "0.1.0-rc.
|
|
3
|
+
"version": "0.1.0-rc.45",
|
|
4
4
|
"description": "Capybara kernel: config, database, plugin host and HTTP API of the Capybara agent platform",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -74,8 +74,8 @@
|
|
|
74
74
|
"@types/ws": "^8.18.2",
|
|
75
75
|
"@types/yauzl": "3.4.0",
|
|
76
76
|
"ws": "^8.22.0",
|
|
77
|
-
"@capybara-hq/
|
|
78
|
-
"@capybara-hq/
|
|
77
|
+
"@capybara-hq/device": "0.1.0-rc.14",
|
|
78
|
+
"@capybara-hq/testing": "0.1.0-rc.26"
|
|
79
79
|
},
|
|
80
80
|
"scripts": {
|
|
81
81
|
"build": "tsc -b"
|