@capybara-hq/kernel 0.1.0-rc.136 → 0.1.0-rc.137
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/admin/audit-log.service.d.ts +96 -12
- package/dist/admin/audit-log.service.js +508 -44
- package/dist/admin/audit-targets.d.ts +17 -0
- package/dist/admin/audit-targets.js +84 -0
- package/dist/admin/audit.controller.d.ts +12 -9
- package/dist/admin/audit.controller.js +29 -8
- package/dist/admin/audit.schemas.d.ts +20 -4
- package/dist/admin/audit.schemas.js +42 -17
- package/dist/agents/templates.js +3 -10
- package/dist/app.d.ts +3 -1
- package/dist/app.js +1 -0
- package/dist/automations/automations.service.js +4 -5
- package/dist/catalog/catalog-content.d.ts +1 -1
- package/dist/catalog/catalog-content.js +17 -22
- package/dist/catalog/catalog-items.d.ts +5 -10
- package/dist/catalog/catalog-items.js +27 -51
- package/dist/catalog/catalog-scope.service.d.ts +4 -2
- package/dist/catalog/catalog-scope.service.js +105 -141
- package/dist/catalog/catalog.module.js +2 -0
- package/dist/catalog/catalog.service.d.ts +3 -3
- package/dist/catalog/catalog.service.js +33 -8
- package/dist/catalog/cli.js +17 -0
- package/dist/catalog/component-promotion.js +8 -4
- package/dist/catalog/component-scope.service.d.ts +3 -1
- package/dist/catalog/component-scope.service.js +101 -140
- package/dist/catalog/component-state.d.ts +10 -8
- package/dist/catalog/component-state.js +42 -30
- package/dist/catalog/dependency-edges.d.ts +25 -0
- package/dist/catalog/dependency-edges.js +125 -0
- package/dist/catalog/install-status.d.ts +2 -3
- package/dist/catalog/install-status.js +2 -3
- package/dist/catalog/org-catalog.service.d.ts +3 -1
- package/dist/catalog/org-catalog.service.js +33 -94
- package/dist/catalog/org-intent.d.ts +43 -0
- package/dist/catalog/org-intent.js +184 -0
- package/dist/catalog/owned-items.d.ts +1 -1
- package/dist/catalog/owned-items.js +9 -29
- package/dist/catalog/ownership.d.ts +2 -3
- package/dist/catalog/ownership.js +10 -28
- package/dist/catalog/platform-components.d.ts +3 -1
- package/dist/catalog/platform-components.js +9 -1
- package/dist/catalog/plugin-import.js +12 -16
- package/dist/catalog/plugin-install.d.ts +3 -4
- package/dist/catalog/plugin-install.js +25 -49
- package/dist/catalog/plugin-upgrade.d.ts +2 -2
- package/dist/catalog/plugin-upgrade.js +18 -34
- package/dist/catalog/request-rules.js +20 -8
- package/dist/catalog/scope-orgs.js +2 -7
- package/dist/catalog/scope-state.d.ts +6 -6
- package/dist/catalog/scope-state.js +24 -43
- package/dist/catalog/scope-sync.d.ts +0 -2
- package/dist/catalog/scope-sync.js +11 -39
- package/dist/catalog/scope-writer.d.ts +78 -0
- package/dist/catalog/scope-writer.js +181 -0
- package/dist/catalog/unshare.js +8 -41
- package/dist/channels/connections.service.js +6 -6
- package/dist/channels/supervisor.js +3 -7
- package/dist/client/client-access.service.js +2 -12
- package/dist/config/schema.d.ts +6 -0
- package/dist/config/schema.js +29 -1
- package/dist/ctx/create-ctx.d.ts +2 -2
- package/dist/ctx/create-ctx.js +2 -60
- package/dist/ctx/guard-db.d.ts +6 -0
- package/dist/ctx/guard-db.js +55 -0
- package/dist/db/extension-handoff-schema.d.ts +1 -1
- package/dist/db/extension-handoff-schema.js +48 -10
- package/dist/db/extension-schema-transfer.js +5 -2
- package/dist/db/kernel-schema.d.ts +11 -1
- package/dist/device-access/host-services.d.ts +2 -2
- package/dist/device-access/host-services.js +5 -6
- package/dist/erasure/org-catalog.js +2 -2
- package/dist/erasure/org-rules.js +5 -0
- package/dist/extensions/admin-ops.d.ts +9 -5
- package/dist/extensions/admin-ops.js +52 -8
- package/dist/extensions/admin-view.js +1 -4
- package/dist/extensions/bootstrap.js +4 -1
- package/dist/extensions/cli.js +1 -0
- package/dist/extensions/effective-config.js +1 -4
- package/dist/extensions/enabled.d.ts +23 -29
- package/dist/extensions/enabled.js +141 -62
- package/dist/extensions/host.d.ts +64 -45
- package/dist/extensions/host.js +443 -128
- package/dist/extensions/installs.d.ts +9 -0
- package/dist/extensions/installs.js +23 -0
- package/dist/extensions/isolated/admission.d.ts +10 -0
- package/dist/extensions/isolated/admission.js +206 -0
- package/dist/extensions/isolated/authorization.d.ts +37 -0
- package/dist/extensions/isolated/authorization.js +146 -0
- package/dist/extensions/isolated/broker.d.ts +15 -0
- package/dist/extensions/isolated/broker.js +452 -0
- package/dist/extensions/isolated/child-protocol.d.ts +84 -0
- package/dist/extensions/isolated/child-protocol.js +21 -0
- package/dist/extensions/isolated/child-registration.d.ts +22 -0
- package/dist/extensions/isolated/child-registration.js +152 -0
- package/dist/extensions/isolated/child-session.d.ts +6 -0
- package/dist/extensions/isolated/child-session.js +343 -0
- package/dist/extensions/isolated/child-streams.d.ts +4 -0
- package/dist/extensions/isolated/child-streams.js +142 -0
- package/dist/extensions/isolated/child.d.ts +1 -0
- package/dist/extensions/isolated/child.js +10 -0
- package/dist/extensions/isolated/configured-package.d.ts +15 -0
- package/dist/extensions/isolated/configured-package.js +73 -0
- package/dist/extensions/isolated/lanes.d.ts +100 -0
- package/dist/extensions/isolated/lanes.js +699 -0
- package/dist/extensions/isolated/postgres-gate.d.ts +14 -0
- package/dist/extensions/isolated/postgres-gate.js +255 -0
- package/dist/extensions/isolated/revision.d.ts +32 -0
- package/dist/extensions/isolated/revision.js +358 -0
- package/dist/extensions/isolated/rpc-frame.d.ts +50 -0
- package/dist/extensions/isolated/rpc-frame.js +193 -0
- package/dist/extensions/isolated/rpc.d.ts +66 -0
- package/dist/extensions/isolated/rpc.js +314 -0
- package/dist/extensions/isolated/sandbox.d.ts +35 -0
- package/dist/extensions/isolated/sandbox.js +372 -0
- package/dist/extensions/isolated/tier.d.ts +6 -0
- package/dist/extensions/isolated/tier.js +45 -0
- package/dist/extensions/ledger.d.ts +1 -1
- package/dist/extensions/lifecycle-topics.d.ts +1 -0
- package/dist/extensions/lifecycle-topics.js +1 -0
- package/dist/extensions/lifecycle.d.ts +3 -1
- package/dist/extensions/lifecycle.js +32 -5
- package/dist/extensions/locks.d.ts +2 -0
- package/dist/extensions/locks.js +7 -0
- package/dist/extensions/org-config.d.ts +17 -27
- package/dist/extensions/org-config.js +114 -129
- package/dist/extensions/plugin-guides.d.ts +5 -10
- package/dist/extensions/plugin-guides.js +18 -37
- package/dist/extensions/plugin-icons.d.ts +3 -21
- package/dist/extensions/plugin-icons.js +9 -44
- package/dist/extensions/plugin-items.d.ts +10 -30
- package/dist/extensions/plugin-items.js +32 -73
- package/dist/extensions/source-intent.d.ts +14 -0
- package/dist/extensions/source-intent.js +77 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/infra/database/database.module.js +6 -1
- package/dist/infra/database/kernel-db.d.ts +3 -1
- package/dist/infra/database/kernel-db.js +4 -0
- package/dist/infra/paging/paged-read.d.ts +56 -0
- package/dist/infra/paging/paged-read.js +78 -0
- package/dist/kernel.d.ts +3 -2
- package/dist/kernel.js +21 -2
- package/dist/lifecycle/kernel-lifecycle.d.ts +3 -1
- package/dist/lifecycle/kernel-lifecycle.js +22 -12
- package/dist/lifecycle/tokens.d.ts +8 -0
- package/dist/lifecycle/tokens.js +2 -0
- package/dist/orgs/directory-sync.js +1 -4
- package/dist/platform/ops/admin.ops.js +14 -3
- package/dist/platform/ops/orgs.ops.js +13 -3
- package/dist/setup/setup-checks.service.js +3 -2
- package/dist/skills/usable.js +41 -30
- package/dist/themes/theme-state.js +3 -3
- package/dist/tools/registry.d.ts +1 -1
- package/dist/tools/registry.js +1 -1
- package/package.json +2 -2
- package/src/migrations/0228_extension_org_switches.sql +56 -0
- package/src/migrations/0229_catalog_dependency_edges.sql +17 -0
- package/src/migrations/0230_audit_filter_idx.sql +18 -0
|
@@ -1,78 +1,157 @@
|
|
|
1
1
|
import { sql } from "kysely";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
* helpers so none of them misses one:
|
|
5
|
-
* - `extension_org_configs.enabled` (the org's own switch);
|
|
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.
|
|
13
|
-
* Neither checks that the extension is loaded on this replica or enabled on the deployment; callers
|
|
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.
|
|
16
|
-
*/
|
|
2
|
+
import { orgUsable } from "../catalog/org-intent.js";
|
|
3
|
+
import { extensionSourcesQuery } from "./plugin-items.js";
|
|
17
4
|
/**
|
|
18
5
|
* The names of the always-on extensions (a subquery with one column, `plugin`): required bootstrap
|
|
19
6
|
* plugins and the extensions of live builtin platform plugins (see the file header).
|
|
20
7
|
*/
|
|
21
|
-
export function alwaysOnExtensionsQuery(db) {
|
|
22
|
-
|
|
8
|
+
export function alwaysOnExtensionsQuery(db, plugin) {
|
|
9
|
+
const required = db
|
|
23
10
|
.selectFrom("extension_installs as ri")
|
|
24
11
|
.select("ri.name as plugin")
|
|
25
|
-
.where("ri.required", "=", true)
|
|
26
|
-
|
|
27
|
-
.selectFrom(
|
|
28
|
-
.innerJoin("catalog_items as
|
|
29
|
-
.select("
|
|
30
|
-
.where("
|
|
31
|
-
.where("
|
|
32
|
-
.where("
|
|
33
|
-
.where("
|
|
34
|
-
|
|
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));
|
|
12
|
+
.where("ri.required", "=", true);
|
|
13
|
+
const builtin = db
|
|
14
|
+
.selectFrom(extensionSourcesQuery(db, plugin).as("source"))
|
|
15
|
+
.innerJoin("catalog_items as item", "item.id", "source.item_id")
|
|
16
|
+
.select("source.plugin")
|
|
17
|
+
.where("item.builtin", "=", true)
|
|
18
|
+
.where("item.disabled", "=", false)
|
|
19
|
+
.where("item.deleted_at", "is", null)
|
|
20
|
+
.where("item.owner_org_id", "is", null);
|
|
21
|
+
return (plugin === undefined ? required : required.where("ri.name", "=", plugin)).union(builtin);
|
|
42
22
|
}
|
|
43
|
-
/** The
|
|
44
|
-
export function
|
|
23
|
+
/** The stored choice for this extension. An absent choice follows its source or default. */
|
|
24
|
+
export function extensionSwitch(db, orgId, plugin) {
|
|
45
25
|
return db
|
|
46
|
-
.selectFrom("
|
|
47
|
-
.select("
|
|
48
|
-
.where("
|
|
49
|
-
.where("
|
|
50
|
-
.
|
|
26
|
+
.selectFrom("component_org_switches as extension_switch")
|
|
27
|
+
.select("extension_switch.enabled")
|
|
28
|
+
.where("extension_switch.kind", "=", "extension")
|
|
29
|
+
.where("extension_switch.org_id", "=", orgId)
|
|
30
|
+
.where("extension_switch.component_id", "=", plugin);
|
|
51
31
|
}
|
|
52
|
-
/**
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
32
|
+
/** The same intent predicate for point, org-list and membership-correlated reads. */
|
|
33
|
+
export function extensionIntent(db, orgId, plugin, proposedChoice) {
|
|
34
|
+
const org = db
|
|
35
|
+
.selectFrom("orgs")
|
|
36
|
+
.select("id")
|
|
37
|
+
.where("id", "=", orgId)
|
|
38
|
+
.where("deleted_at", "is", null);
|
|
39
|
+
const required = db
|
|
40
|
+
.selectFrom("extension_installs")
|
|
41
|
+
.select("name")
|
|
42
|
+
.where("name", "=", plugin)
|
|
43
|
+
.where("required", "=", true);
|
|
44
|
+
const sources = db
|
|
45
|
+
.selectFrom(extensionSourcesQuery(db, plugin).as("source"))
|
|
46
|
+
.crossJoinLateral((eb) => db
|
|
47
|
+
.selectFrom("catalog_items")
|
|
48
|
+
.select([
|
|
49
|
+
"id",
|
|
50
|
+
"deleted_at",
|
|
51
|
+
"disabled",
|
|
52
|
+
"owner_org_id",
|
|
53
|
+
"shareable",
|
|
54
|
+
"scope",
|
|
55
|
+
"builtin",
|
|
56
|
+
"latest_version",
|
|
57
|
+
])
|
|
58
|
+
.where("id", "=", eb.ref("source.item_id"))
|
|
59
|
+
.limit(1)
|
|
60
|
+
.as("source_item"))
|
|
61
|
+
.leftJoin("catalog_item_scope_orgs as source_org", (join) => join.onRef("source_org.item_id", "=", "source.item_id").on("source_org.org_id", "=", orgId))
|
|
62
|
+
.select((eb) => [
|
|
63
|
+
eb("source_item.deleted_at", "is", null).as("live"),
|
|
64
|
+
eb
|
|
65
|
+
.and([
|
|
66
|
+
eb("source_item.builtin", "=", true),
|
|
67
|
+
eb("source_item.disabled", "=", false),
|
|
68
|
+
eb("source_item.owner_org_id", "is", null),
|
|
69
|
+
])
|
|
70
|
+
.as("builtin"),
|
|
71
|
+
eb
|
|
72
|
+
.and([
|
|
73
|
+
eb("source_item.disabled", "=", false),
|
|
74
|
+
eb.or([
|
|
75
|
+
eb("source_item.owner_org_id", "is", null),
|
|
76
|
+
eb("source_item.owner_org_id", "=", orgId),
|
|
77
|
+
eb.and([
|
|
78
|
+
eb("source_item.shareable", "=", true),
|
|
79
|
+
eb.exists(eb
|
|
80
|
+
.selectFrom("catalog_item_versions as published")
|
|
81
|
+
.select("published.item_id")
|
|
82
|
+
.whereRef("published.item_id", "=", "source_item.id")
|
|
83
|
+
.whereRef("published.version", "=", "source_item.latest_version")
|
|
84
|
+
.where("published.applied_at", "is not", null)),
|
|
85
|
+
]),
|
|
86
|
+
]),
|
|
87
|
+
eb.or([eb("source_item.scope", "!=", "named"), eb("source_org.item_id", "is not", null)]),
|
|
88
|
+
])
|
|
89
|
+
.as("authorized"),
|
|
90
|
+
orgUsable(db, orgId, eb.ref("source.item_id")).as("follows"),
|
|
91
|
+
]);
|
|
92
|
+
const choice = proposedChoice === undefined
|
|
93
|
+
? extensionSwitch(db, orgId, plugin)
|
|
94
|
+
: db.selectNoFrom(sql `${proposedChoice}::boolean`.as("enabled"));
|
|
95
|
+
return sql `
|
|
96
|
+
exists (${org}) AND (
|
|
97
|
+
exists (${required})
|
|
98
|
+
OR (
|
|
99
|
+
SELECT CASE
|
|
100
|
+
WHEN summary.builtin THEN true
|
|
101
|
+
WHEN summary.all_sources = 0 THEN choice.enabled IS TRUE
|
|
102
|
+
WHEN summary.live_sources = 1 THEN summary.follows AND choice.enabled IS NOT FALSE
|
|
103
|
+
WHEN summary.live_sources > 1 THEN summary.authorized AND choice.enabled IS TRUE
|
|
104
|
+
ELSE false
|
|
105
|
+
END
|
|
106
|
+
FROM (
|
|
107
|
+
SELECT count(*) AS all_sources,
|
|
108
|
+
count(*) FILTER (WHERE live) AS live_sources,
|
|
109
|
+
bool_or(builtin) FILTER (WHERE live) AS builtin,
|
|
110
|
+
bool_or(follows) FILTER (WHERE live) AS follows,
|
|
111
|
+
bool_and(authorized) FILTER (WHERE live) AS authorized
|
|
112
|
+
FROM (${sources}) AS source_intent
|
|
113
|
+
) AS summary
|
|
114
|
+
LEFT JOIN (${choice}) AS choice ON true
|
|
115
|
+
)
|
|
116
|
+
)`;
|
|
117
|
+
}
|
|
118
|
+
/** The names enabled in an org, optionally narrowed to one extension in the outer query. */
|
|
119
|
+
export function enabledExtensionsQuery(db, orgId, plugin) {
|
|
120
|
+
if (plugin !== undefined) {
|
|
121
|
+
return db
|
|
122
|
+
.selectNoFrom(sql `${plugin}`.as("plugin"))
|
|
123
|
+
.where(extensionIntent(db, orgId, plugin));
|
|
124
|
+
}
|
|
125
|
+
const installed = db.selectFrom("extension_installs").select("name as plugin");
|
|
126
|
+
const sources = db.selectFrom("extension_catalog_sources").select("plugin");
|
|
127
|
+
const switches = db
|
|
128
|
+
.selectFrom("component_org_switches")
|
|
129
|
+
.select("component_id as plugin")
|
|
130
|
+
.where("kind", "=", "extension")
|
|
131
|
+
.where("org_id", "=", orgId);
|
|
132
|
+
return db
|
|
133
|
+
.selectFrom(installed.union(sources).union(switches).as("candidate"))
|
|
134
|
+
.select("candidate.plugin")
|
|
135
|
+
.where((eb) => extensionIntent(db, orgId, eb.ref("candidate.plugin")));
|
|
136
|
+
}
|
|
137
|
+
/** Test only the requested extension names when a deployment-wide reader needs org pairs. */
|
|
138
|
+
export function enabledExtensionsByOrg(db, plugins) {
|
|
139
|
+
const requested = db
|
|
140
|
+
.selectNoFrom(sql `unnest(${[...new Set(plugins)]}::text[])`.as("plugin"))
|
|
141
|
+
.as("requested");
|
|
59
142
|
return db
|
|
60
|
-
.selectFrom("
|
|
61
|
-
.
|
|
62
|
-
.
|
|
63
|
-
.
|
|
64
|
-
.
|
|
65
|
-
.innerJoin(alwaysOnExtensionsQuery(db).as("ao"), (j) => j.onTrue())
|
|
66
|
-
.select(["ro.id as org_id", "ao.plugin as plugin"]));
|
|
143
|
+
.selectFrom("orgs as enabled_org")
|
|
144
|
+
.crossJoin(requested)
|
|
145
|
+
.select(["enabled_org.id as org_id", "requested.plugin"])
|
|
146
|
+
.where("enabled_org.deleted_at", "is", null)
|
|
147
|
+
.where(({ exists, ref }) => exists(enabledExtensionsQuery(db, ref("enabled_org.id"), ref("requested.plugin"))));
|
|
67
148
|
}
|
|
68
|
-
/** Whether
|
|
149
|
+
/** Whether the extension has committed intent in the org. Execution checks remain at the caller. */
|
|
69
150
|
export async function isExtensionEnabled(db, orgId, plugin) {
|
|
70
|
-
const
|
|
71
|
-
.
|
|
72
|
-
.
|
|
73
|
-
|
|
74
|
-
.executeTakeFirst();
|
|
75
|
-
return row !== undefined;
|
|
151
|
+
const { enabled } = await db
|
|
152
|
+
.selectNoFrom(extensionIntent(db, orgId, plugin).as("enabled"))
|
|
153
|
+
.executeTakeFirstOrThrow();
|
|
154
|
+
return enabled;
|
|
76
155
|
}
|
|
77
156
|
/**
|
|
78
157
|
* The names of the required bootstrap plugins (installed with `required`): the ones that refuse
|
|
@@ -9,6 +9,7 @@ import { EXTERNAL_CONVERSATIONS_BACKEND } from "../conversations/external/token.
|
|
|
9
9
|
import type { BusSubscriber } from "../ctx/bus.js";
|
|
10
10
|
import { type DeviceAccessBackend, type InboxBackend, type PluginReadsBackend, type Route, type TriggersBackend } from "../ctx/create-ctx.js";
|
|
11
11
|
import { ExtensionEffects } from "../ctx/durable-effects.service.js";
|
|
12
|
+
import { ExtensionEffectKeys } from "../ctx/durable-keys.js";
|
|
12
13
|
import { type ExtensionNetSeams } from "../ctx/net.js";
|
|
13
14
|
import type { Keyring } from "../ctx/secrets.js";
|
|
14
15
|
import { type ExtensionDbIdentity } from "../db/extension-db.js";
|
|
@@ -20,6 +21,7 @@ import { INBOX_ITEMS_BACKEND } from "../inbox/token.js";
|
|
|
20
21
|
import { KernelConfigService } from "../infra/config/kernel-config.service.js";
|
|
21
22
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
22
23
|
import { LockService } from "../infra/lock/lock.service.js";
|
|
24
|
+
import { KERNEL_FIXTURE_TRUST, type KernelFixtureTrust } from "../lifecycle/tokens.js";
|
|
23
25
|
import type { KernelLogger } from "../log.js";
|
|
24
26
|
import { ModelEmbeddings } from "../models/embeddings.js";
|
|
25
27
|
import { ModelImages } from "../models/images.js";
|
|
@@ -36,6 +38,8 @@ import { HookRegistry } from "./hooks.js";
|
|
|
36
38
|
import type { InflightTracker } from "./inflight.js";
|
|
37
39
|
import { type DesiredExtension, ExtensionInstalls } from "./installs.js";
|
|
38
40
|
import { type ExtensionInstance } from "./instance.js";
|
|
41
|
+
import { type IsolatedRevocation } from "./isolated/authorization.js";
|
|
42
|
+
import type { ExtensionTier } from "./isolated/tier.js";
|
|
39
43
|
import { type PermissionSet } from "./permission-set.js";
|
|
40
44
|
import { type ExtensionPointEntry, ExtensionRegistry } from "./registry.js";
|
|
41
45
|
import { type ExtensionSource, ReplicaStatusStore } from "./sources.js";
|
|
@@ -60,6 +64,7 @@ export interface LoadedUiContribution {
|
|
|
60
64
|
export type { ExtensionPointEntry } from "./registry.js";
|
|
61
65
|
/** One item of {@link ExtensionHost.inspect}. */
|
|
62
66
|
export interface InspectedExtension {
|
|
67
|
+
isolated?: true;
|
|
63
68
|
/** Always `config`: the startup config `extensions` list. */
|
|
64
69
|
source: "config";
|
|
65
70
|
manifest: ExtensionManifest;
|
|
@@ -84,6 +89,7 @@ export declare function assertSecretsReachable(manifest: ExtensionManifest): voi
|
|
|
84
89
|
* extension must be ready).
|
|
85
90
|
*/
|
|
86
91
|
export interface InstalledExtensionLoader {
|
|
92
|
+
tier?(d: DesiredExtension, verifyBytes: boolean): Promise<ExtensionTier>;
|
|
87
93
|
desired(): Promise<DesiredExtension[]>;
|
|
88
94
|
sync(d: DesiredExtension): Promise<string>;
|
|
89
95
|
/**
|
|
@@ -118,7 +124,7 @@ export interface ExtensionLoadPlan {
|
|
|
118
124
|
/** 安装记录。 */
|
|
119
125
|
installs?: InstalledExtensionLoader;
|
|
120
126
|
}
|
|
121
|
-
/**
|
|
127
|
+
/** Resolves extensions and their configuration, runs migrations and registers capabilities. */
|
|
122
128
|
export declare class ExtensionHost {
|
|
123
129
|
/** The process's extension registry (one provider, shared with other domains). */
|
|
124
130
|
private readonly registry;
|
|
@@ -134,11 +140,27 @@ export declare class ExtensionHost {
|
|
|
134
140
|
private readonly status;
|
|
135
141
|
private readonly config;
|
|
136
142
|
private readonly log;
|
|
143
|
+
private readonly options;
|
|
137
144
|
/**
|
|
138
145
|
* Each hook call's effective config for its organization, and the providers excluded from an
|
|
139
146
|
* org's point resolution (layering spec A §6).
|
|
140
147
|
*/
|
|
141
148
|
private readonly effective;
|
|
149
|
+
/** `ctx.net`: the internal endpoints each org's extension requests may reach (read per call). */
|
|
150
|
+
private readonly allowances;
|
|
151
|
+
/**
|
|
152
|
+
* Finds `DeviceAccessService` (`ctx.deviceAccess`, {@link DEVICE_ACCESS_BACKEND}) at the time
|
|
153
|
+
* of use: its module imports the sandbox, devices and tools modules, which import this one (a
|
|
154
|
+
* module cycle otherwise).
|
|
155
|
+
* Absent (a hand-built host) or not found (the CLI): `ctx.deviceAccess` calls are refused.
|
|
156
|
+
* `TriggerEventsService` (`ctx.triggers`, {@link TRIGGER_EVENTS_BACKEND}) and
|
|
157
|
+
* `InboxItemsService` (`ctx.inbox`, {@link INBOX_ITEMS_BACKEND}) and `PluginReadsService`
|
|
158
|
+
* (`ctx.agents`, `ctx.conversations`, `ctx.people`, {@link PLUGIN_READS_BACKEND}) and
|
|
159
|
+
* `ExternalConversationsService` (`ctx.conversations`' external methods,
|
|
160
|
+
* {@link EXTERNAL_CONVERSATIONS_BACKEND}) and
|
|
161
|
+
* `ServiceEvents` (`ctx.devices.serviceEvent`, {@link SERVICE_EVENTS_BACKEND}) likewise.
|
|
162
|
+
*/
|
|
163
|
+
private readonly modules?;
|
|
142
164
|
private readonly dbIdentity;
|
|
143
165
|
/**
|
|
144
166
|
* Only resolves extensions and runs migrations in dependency order: no deployment config check, no
|
|
@@ -150,12 +172,15 @@ export declare class ExtensionHost {
|
|
|
150
172
|
* kernel migrations to have run (reads `extension_permission_snapshots`). With `autoApprove` all are
|
|
151
173
|
* migrated and no snapshot is written (`load()` writes snapshots).
|
|
152
174
|
*/
|
|
153
|
-
static migrateOnly(specifiers: string[], opts: {
|
|
175
|
+
static migrateOnly(specifiers: string[], opts: KernelFixtureTrust & {
|
|
154
176
|
dbUrl: string;
|
|
155
177
|
extensionIdentity?: ExtensionDbIdentity;
|
|
156
178
|
extensionProvisioning?: KernelConfig["db"];
|
|
157
179
|
resolveFrom?: string;
|
|
158
180
|
connectTimeoutMs?: number;
|
|
181
|
+
migrationTimeoutMs?: number;
|
|
182
|
+
packageCacheDir?: string;
|
|
183
|
+
maxPackageBytes?: number;
|
|
159
184
|
autoApprove?: boolean;
|
|
160
185
|
onPending?: (pending: PendingExtension[]) => void;
|
|
161
186
|
}): Promise<{
|
|
@@ -163,26 +188,29 @@ export declare class ExtensionHost {
|
|
|
163
188
|
schema: string;
|
|
164
189
|
applied: string[];
|
|
165
190
|
}[]>;
|
|
166
|
-
/**
|
|
167
|
-
|
|
168
|
-
* list): imports their modules only (the same modules `load()` imports next, from Node's module
|
|
169
|
-
* cache). The kernel passes them to the bootstrap step before loading, so a bootstrap entry of
|
|
170
|
-
* the same name is kept and gets no install record (config wins, C15).
|
|
171
|
-
*/
|
|
172
|
-
static declaredNames(specifiers: string[], opts?: {
|
|
191
|
+
/** Reads configured package identities for bootstrap without starting extension code. */
|
|
192
|
+
static declaredNames(specifiers: string[], opts?: KernelFixtureTrust & {
|
|
173
193
|
resolveFrom?: string;
|
|
194
|
+
maxPackageBytes?: number;
|
|
174
195
|
}): Promise<Set<string>>;
|
|
175
196
|
/**
|
|
176
197
|
* 只导入、校验并按依赖排序插件,计算各自的权限集合;不迁移、不调用 setup、不连数据库与 Redis
|
|
177
198
|
* (供 `capybara extensions review / approve`)。返回依赖拓扑序。
|
|
178
199
|
*/
|
|
179
|
-
static inspect(specifiers: string[], opts?: {
|
|
200
|
+
static inspect(specifiers: string[], opts?: KernelFixtureTrust & {
|
|
180
201
|
resolveFrom?: string;
|
|
202
|
+
maxPackageBytes?: number;
|
|
181
203
|
}): Promise<InspectedExtension[]>;
|
|
182
204
|
/**
|
|
183
205
|
* M-1: plugin → mount points where deployment state expects `policy` hooks. A per-replica copy of PG
|
|
184
206
|
* deployment state (like the registry), rebuilt on every load / converge, never written elsewhere.
|
|
185
207
|
*/
|
|
208
|
+
private readonly declaredIsolation;
|
|
209
|
+
private readonly quota;
|
|
210
|
+
private readonly isolatedAuthority;
|
|
211
|
+
private readonly isolatedLanes;
|
|
212
|
+
private readonly isolatedGrants;
|
|
213
|
+
private readonly executionTier;
|
|
186
214
|
private policyExpected;
|
|
187
215
|
/**
|
|
188
216
|
* Runs the hooks of this process's active plugin instances (resolved from the registry on every
|
|
@@ -281,7 +309,7 @@ export declare class ExtensionHost {
|
|
|
281
309
|
/** This replica's load status table (`extension_replica_status`): every load result writes a row. */
|
|
282
310
|
status: ReplicaStatusStore, config: KernelConfigService, kdb: KernelDb, redis: Redis, busSubscriber: BusSubscriber, keyring: Keyring, embedTokens: EmbedTokens,
|
|
283
311
|
/** `ctx.ui.verifyEmbedToken`: the live check of a share-scoped token (file sharing spec §7). */
|
|
284
|
-
shares: ShareLiveness, locks: LockService, log: KernelLogger, options: Pick<KernelAppOptions, "resolveFrom">,
|
|
312
|
+
shares: ShareLiveness, locks: LockService, log: KernelLogger, options: Pick<KernelAppOptions, "resolveFrom" | typeof KERNEL_FIXTURE_TRUST>,
|
|
285
313
|
/**
|
|
286
314
|
* Each hook call's effective config for its organization, and the providers excluded from an
|
|
287
315
|
* org's point resolution (layering spec A §6).
|
|
@@ -319,6 +347,9 @@ export declare class ExtensionHost {
|
|
|
319
347
|
get(token: typeof ExtensionEffects, opts: {
|
|
320
348
|
strict: false;
|
|
321
349
|
}): ExtensionEffects;
|
|
350
|
+
get(token: typeof ExtensionEffectKeys, opts: {
|
|
351
|
+
strict: false;
|
|
352
|
+
}): ExtensionEffectKeys;
|
|
322
353
|
get(token: typeof TRIGGER_EVENTS_BACKEND, opts: {
|
|
323
354
|
strict: false;
|
|
324
355
|
}): TriggersBackend;
|
|
@@ -331,7 +362,7 @@ export declare class ExtensionHost {
|
|
|
331
362
|
get(token: typeof EXTERNAL_CONVERSATIONS_BACKEND, opts: {
|
|
332
363
|
strict: false;
|
|
333
364
|
}): ExternalConversationsBackend;
|
|
334
|
-
},
|
|
365
|
+
} | undefined,
|
|
335
366
|
/** Tests only: `ctx.net`'s DNS and dispatcher seams (`EXTENSION_NET_SEAMS`). */
|
|
336
367
|
netSeams?: ExtensionNetSeams, dbIdentity?: ExtensionDbIdentity);
|
|
337
368
|
/** The startup config's `extensionConfig` (file / Nacos merged with env). */
|
|
@@ -413,18 +444,13 @@ export declare class ExtensionHost {
|
|
|
413
444
|
private rawConfigOf;
|
|
414
445
|
/** 把一份已校验部署配置里的密钥值登记到日志打码。 */
|
|
415
446
|
private reportSecrets;
|
|
447
|
+
private tierOf;
|
|
416
448
|
/**
|
|
417
|
-
*
|
|
418
|
-
*
|
|
419
|
-
*
|
|
420
|
-
*
|
|
421
|
-
*
|
|
422
|
-
* 必需能力(此刻没有生效的提供方 → pending / dependency)、导入模块并核对静态清单(`import_failed` /
|
|
423
|
-
* `manifest_mismatch`;闸门放行之前不导入)、部署配置、
|
|
424
|
-
* 持锁迁移(busy → pending / migration)、setup,成功后登记新实例(先加载新、再撤销旧:旧实例在后台排空后撤销);
|
|
425
|
-
* 任何一步失败旧实例保留,记 failed(`migration_failed` / `setup_failed`)。
|
|
426
|
-
* 4. 运行中(非启动):对变了的能力做依赖方连锁(本轮刚加载的除外),此前因依赖卸下的插件随之补回。
|
|
427
|
-
* 返回启用的安装记录在静态清单里声明提供的能力(启动第 4 步据此判断待定还是缺提供方)。
|
|
449
|
+
* Reconciles enabled installs from PostgreSQL at startup and during convergence. It removes
|
|
450
|
+
* withdrawn revisions, verifies the tier, and prepares replacements in dependency order.
|
|
451
|
+
* Permission or dependency waits keep the same-tier serving revision. Import, migration and
|
|
452
|
+
* setup failures report the stage that failed. Successful replacements drain the old instance
|
|
453
|
+
* and changed providers trigger dependency reconciliation.
|
|
428
454
|
*/
|
|
429
455
|
private applyInstalls;
|
|
430
456
|
/**
|
|
@@ -457,7 +483,7 @@ export declare class ExtensionHost {
|
|
|
457
483
|
private logFailure;
|
|
458
484
|
/** 记下(替换同名的)待定插件,供 {@link pending} 列出。 */
|
|
459
485
|
private notePending;
|
|
460
|
-
/**
|
|
486
|
+
/** Removes an extension from the pending list. */
|
|
461
487
|
private dropPending;
|
|
462
488
|
/**
|
|
463
489
|
* 第 4 步:第 2 步挑出来的配置声明插件(`requires` 只能由安装记录满足)。与已加载的插件一起解析依赖:
|
|
@@ -466,6 +492,7 @@ export declare class ExtensionHost {
|
|
|
466
492
|
* 与「配置声明插件依赖待批准的配置声明插件」一致,内核照常启动;
|
|
467
493
|
* - 缺的能力没有任何提供方 → 与此前一样抛错(内核启动失败)。
|
|
468
494
|
*/
|
|
495
|
+
private declaredMigrationDirectory;
|
|
469
496
|
private loadDeferred;
|
|
470
497
|
/**
|
|
471
498
|
* Checks the config UI hints of a loaded module's deployment schema (spec §4.1). Invalid
|
|
@@ -488,10 +515,9 @@ export declare class ExtensionHost {
|
|
|
488
515
|
*/
|
|
489
516
|
private writeStatus;
|
|
490
517
|
/**
|
|
491
|
-
*
|
|
492
|
-
*
|
|
493
|
-
*
|
|
494
|
-
* 返回新登记的实例(没有加载时返回 undefined)。
|
|
518
|
+
* Admit a reviewed revision, resolve deployment config, migrate, and register it. Ineligible
|
|
519
|
+
* config leaves the extension pending. A same-tier replacement keeps the previous instance
|
|
520
|
+
* available until the new instance registers. Tier transitions drain before replacement.
|
|
495
521
|
*/
|
|
496
522
|
private activate;
|
|
497
523
|
/**
|
|
@@ -511,21 +537,14 @@ export declare class ExtensionHost {
|
|
|
511
537
|
* 与 unload / reload 串行。返回本次加载的插件名。
|
|
512
538
|
*/
|
|
513
539
|
activatePending(): Promise<string[]>;
|
|
540
|
+
revokeIsolatedInvocations(scope: IsolatedRevocation): void;
|
|
541
|
+
revalidateIsolatedInvocations(): Promise<void>;
|
|
514
542
|
/**
|
|
515
|
-
*
|
|
516
|
-
*
|
|
517
|
-
* 2. 安装记录按 PG 期望状态收敛(见 {@link applyInstalls}:停用 / 卸载的卸下,换包的先加载新再撤销旧,
|
|
518
|
-
* 失败的每次重试),之后做依赖方连锁;
|
|
519
|
-
* 3. 再试一次第 1 步(安装记录提供的能力可能放行了依赖它的配置声明插件)。
|
|
520
|
-
* 读不到安装记录时只做第 1 步并抛错(调用方记日志,下一个周期再来)。
|
|
543
|
+
* Publish approved policy expectations before doing work that might leave a handler temporarily
|
|
544
|
+
* unavailable. Re-read after activation, which may have persisted new permission approvals.
|
|
521
545
|
*/
|
|
522
546
|
converge(): Promise<void>;
|
|
523
|
-
/**
|
|
524
|
-
* Refreshes {@link policyExpected} from deployment state (M-1):
|
|
525
|
-
* config-declared plugins and enabled installs (`desired`) from their approved permission snapshot.
|
|
526
|
-
* `desired` undefined (install records unreadable) keeps the previous install entries.
|
|
527
|
-
* `shrinkOnly`: only remove entries (a plugin no longer desired or approved), never add new ones.
|
|
528
|
-
*/
|
|
547
|
+
/** Policy expectations follow approval and deployment state for every execution tier. */
|
|
529
548
|
private refreshPolicyExpectations;
|
|
530
549
|
/**
|
|
531
550
|
* Plugins that deployment state expects to run `policy` hooks on the mount point (M-1): enabled and
|
|
@@ -553,7 +572,7 @@ export declare class ExtensionHost {
|
|
|
553
572
|
/** 配置声明的插件名 → 来源(安装包不能与它们重名)。 */
|
|
554
573
|
declared(): Map<string, ExtensionSource>;
|
|
555
574
|
/**
|
|
556
|
-
* Extensions enabled in the org:
|
|
575
|
+
* Extensions enabled in the org: the org intent projection
|
|
557
576
|
* (required bootstrap plugins, builtin plugins' extensions; see `enabled.ts`); queried every
|
|
558
577
|
* time, not cached.
|
|
559
578
|
* Cost (M-4): hooks call this on every run, so one PG query per model attempt and per tool call.
|
|
@@ -564,15 +583,14 @@ export declare class ExtensionHost {
|
|
|
564
583
|
/**
|
|
565
584
|
* The access behind an extension's `ctx.extensionPoints`: only active instances in the registry
|
|
566
585
|
* (dependencies load in topological order, so the depended-on are ready first); org enablement is
|
|
567
|
-
* read from
|
|
586
|
+
* read from PostgreSQL every time, not cached. Resolved live on every call: once a
|
|
568
587
|
* provider is revoked it is no longer returned.
|
|
569
588
|
*/
|
|
570
589
|
private readonly extensionPointAccess;
|
|
571
590
|
private get loadDeps();
|
|
572
591
|
/**
|
|
573
|
-
*
|
|
574
|
-
*
|
|
575
|
-
* 配置声明的插件启动时不设时限(见 {@link load})。
|
|
592
|
+
* Build a new generation. Track its context during setup so shutdown can close it immediately.
|
|
593
|
+
* A reload deadline closes incomplete setup and any late instance that reaches registration.
|
|
576
594
|
*/
|
|
577
595
|
private setup;
|
|
578
596
|
/** Logs once per load what slot resolution left out or flagged (UI slots spec §3.2). */
|
|
@@ -719,6 +737,7 @@ export declare class ExtensionHost {
|
|
|
719
737
|
}): Promise<ExtensionInstance>;
|
|
720
738
|
/** 摘下并撤销一个实例(不做连锁);不在注册表时返回 undefined。 */
|
|
721
739
|
private doUnload;
|
|
740
|
+
private assertCurrentInstall;
|
|
722
741
|
/** 新建实例并原子替换、撤销旧实例(不做连锁)。 */
|
|
723
742
|
private doReload;
|
|
724
743
|
/** 生效实例按依赖拓扑排序(解析不了时退回注册表顺序)。 */
|