@capybara-hq/kernel 0.1.0-rc.142 → 0.1.0-rc.144
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/admin-agents.controller.d.ts +3 -5
- package/dist/admin/admin-agents.controller.js +1 -1
- package/dist/admin/admin-connectors.controller.d.ts +3 -5
- package/dist/admin/admin-connectors.controller.js +1 -1
- package/dist/admin/admin-items.schemas.d.ts +6 -6
- package/dist/admin/admin-items.schemas.js +5 -9
- package/dist/admin/admin.controller.d.ts +18 -12
- package/dist/admin/admin.controller.js +29 -15
- package/dist/admin/admin.schemas.d.ts +12 -3
- package/dist/admin/admin.schemas.js +17 -6
- package/dist/agents/admin-agents.d.ts +10 -8
- package/dist/agents/admin-agents.js +13 -9
- package/dist/agents/agents.module.js +3 -0
- package/dist/agents/agents.service.js +1 -1
- package/dist/agents/org-templates.d.ts +3 -1
- package/dist/agents/org-templates.js +7 -3
- package/dist/agents/pending-connector-requests.d.ts +10 -4
- package/dist/agents/pending-connector-requests.js +29 -7
- package/dist/automations/automations.controller.d.ts +9 -5
- package/dist/automations/automations.controller.js +21 -4
- package/dist/automations/automations.schemas.d.ts +19 -0
- package/dist/automations/automations.schemas.js +9 -0
- package/dist/automations/automations.service.d.ts +25 -8
- package/dist/automations/automations.service.js +40 -34
- package/dist/automations/events/acceptance.d.ts +6 -1
- package/dist/automations/events/acceptance.js +30 -11
- package/dist/automations/store.d.ts +17 -0
- package/dist/automations/store.js +35 -0
- package/dist/catalog/admin-catalog.controller.d.ts +64 -2
- package/dist/catalog/admin-catalog.controller.js +17 -0
- package/dist/catalog/catalog-import.module.js +3 -0
- package/dist/catalog/catalog-scope.service.d.ts +3 -1
- package/dist/catalog/catalog-scope.service.js +11 -7
- package/dist/catalog/catalog.module.js +3 -0
- package/dist/catalog/catalog.service.d.ts +3 -1
- package/dist/catalog/catalog.service.js +8 -4
- package/dist/catalog/cli.js +2 -2
- package/dist/catalog/component-promotion.d.ts +3 -1
- package/dist/catalog/component-promotion.js +7 -3
- package/dist/catalog/component-scope.service.d.ts +3 -1
- package/dist/catalog/component-scope.service.js +7 -3
- package/dist/catalog/enable-requests.d.ts +10 -8
- package/dist/catalog/enable-requests.js +40 -21
- package/dist/catalog/marketplaces.service.d.ts +1 -1
- package/dist/catalog/owned-items.d.ts +3 -1
- package/dist/catalog/owned-items.js +13 -9
- package/dist/catalog/platform-components.d.ts +6 -1
- package/dist/catalog/platform-components.js +9 -3
- package/dist/catalog/plugin-connectors.d.ts +8 -4
- package/dist/catalog/plugin-connectors.js +12 -6
- package/dist/catalog/plugin-import.d.ts +3 -1
- package/dist/catalog/plugin-import.js +14 -5
- package/dist/catalog/plugin-install.d.ts +3 -1
- package/dist/catalog/plugin-install.js +8 -4
- package/dist/catalog/plugin-package.js +2 -1
- package/dist/catalog/plugin-upgrade.d.ts +3 -1
- package/dist/catalog/plugin-upgrade.js +8 -4
- package/dist/catalog/request-hints.d.ts +19 -0
- package/dist/catalog/request-hints.js +34 -0
- package/dist/catalog/request-rules.d.ts +9 -5
- package/dist/catalog/request-rules.js +16 -9
- package/dist/catalog/requests.service.d.ts +3 -1
- package/dist/catalog/requests.service.js +28 -9
- package/dist/catalog/scope-orgs.d.ts +2 -1
- package/dist/catalog/scope-orgs.js +2 -2
- package/dist/catalog/scope-sync.d.ts +3 -1
- package/dist/catalog/scope-sync.js +12 -2
- package/dist/catalog/scope-writer.d.ts +6 -3
- package/dist/catalog/scope-writer.js +28 -10
- package/dist/catalog/unshare.d.ts +3 -2
- package/dist/catalog/unshare.js +4 -4
- package/dist/client/client-access.service.js +29 -1
- package/dist/config/schema.d.ts +12 -0
- package/dist/config/schema.js +56 -0
- package/dist/ctx/create-ctx.d.ts +2 -19
- package/dist/ctx/create-ctx.js +3 -93
- package/dist/ctx/durable-relay.d.ts +2 -5
- package/dist/ctx/durable-relay.js +56 -29
- package/dist/db/extension-handoff-schema.js +5 -0
- package/dist/db/kernel-schema.d.ts +74 -0
- package/dist/db/migrator.js +36 -0
- package/dist/erasure/account-batches.js +2 -0
- package/dist/erasure/account-residual.js +1 -0
- package/dist/erasure/org-catalog.js +8 -3
- package/dist/erasure/org-rules.js +1 -0
- package/dist/evals/evals.schemas.d.ts +15 -5
- package/dist/evals/evals.schemas.js +17 -10
- package/dist/evals/runs.controller.d.ts +4 -12
- package/dist/evals/runs.controller.js +14 -11
- package/dist/evals/runs.service.d.ts +29 -25
- package/dist/evals/runs.service.js +73 -61
- package/dist/evals/trajectory.controller.d.ts +10 -6
- package/dist/evals/trajectory.controller.js +11 -4
- package/dist/evals/trajectory.service.d.ts +17 -9
- package/dist/evals/trajectory.service.js +52 -35
- package/dist/extensions/admin-ops.d.ts +6 -1
- package/dist/extensions/admin-ops.js +21 -7
- package/dist/extensions/blobs.d.ts +2 -0
- package/dist/extensions/blobs.js +11 -0
- package/dist/extensions/deployment-config.d.ts +6 -1
- package/dist/extensions/deployment-config.js +13 -2
- package/dist/extensions/enabled.d.ts +5 -0
- package/dist/extensions/extensions.module.js +3 -0
- package/dist/extensions/grant-epoch.d.ts +108 -0
- package/dist/extensions/grant-epoch.js +214 -0
- package/dist/extensions/host.d.ts +29 -9
- package/dist/extensions/host.js +148 -42
- package/dist/extensions/instance.d.ts +3 -3
- package/dist/extensions/instance.js +1 -1
- package/dist/extensions/isolated/authorization.d.ts +54 -2
- package/dist/extensions/isolated/authorization.js +148 -35
- package/dist/extensions/isolated/child-session.js +0 -1
- package/dist/extensions/isolated/revision.js +1 -1
- package/dist/extensions/org-config.d.ts +3 -1
- package/dist/extensions/org-config.js +13 -4
- package/dist/extensions/org-overrides.d.ts +6 -1
- package/dist/extensions/org-overrides.js +13 -2
- package/dist/extensions/package-digest.job.d.ts +34 -0
- package/dist/extensions/package-digest.job.js +121 -0
- package/dist/extensions/package.js +10 -6
- package/dist/extensions/permission-set.d.ts +14 -78
- package/dist/extensions/permission-set.js +17 -143
- package/dist/extensions/permission-view.d.ts +13 -1
- package/dist/extensions/permission-view.js +20 -0
- package/dist/extensions/registry.js +4 -1
- package/dist/extensions/resolve.d.ts +7 -8
- package/dist/extensions/resolve.js +7 -8
- package/dist/extensions/revision-approvals.d.ts +167 -0
- package/dist/extensions/revision-approvals.js +353 -0
- package/dist/extensions/revision-grants.d.ts +197 -0
- package/dist/extensions/revision-grants.js +584 -0
- package/dist/extensions/state.module.js +12 -1
- package/dist/identity/accounts.d.ts +10 -4
- package/dist/identity/accounts.js +18 -5
- package/dist/inbox/inbox-items.service.d.ts +6 -1
- package/dist/inbox/inbox-items.service.js +29 -10
- package/dist/inbox/inbox.module.js +3 -0
- package/dist/inbox/inbox.service.d.ts +3 -1
- package/dist/inbox/inbox.service.js +9 -2
- package/dist/inbox/org-notices.d.ts +4 -3
- package/dist/inbox/org-notices.js +9 -6
- package/dist/inbox/platform-inbox.service.d.ts +3 -1
- package/dist/inbox/platform-inbox.service.js +11 -3
- package/dist/inbox/platform-notices.d.ts +3 -2
- package/dist/inbox/platform-notices.js +10 -4
- package/dist/infra/config/kernel-config.service.js +4 -1
- package/dist/infra/database/extension-effect-key-lock.js +7 -0
- package/dist/infra/paging/paged-read.d.ts +34 -4
- package/dist/infra/paging/paged-read.js +38 -1
- package/dist/invalidation/audiences.d.ts +32 -0
- package/dist/invalidation/audiences.js +43 -0
- package/dist/invalidation/hints.d.ts +6 -0
- package/dist/invalidation/hints.js +7 -1
- package/dist/invalidation/invalidation-hints.d.ts +12 -1
- package/dist/invalidation/invalidation-hints.js +46 -5
- package/dist/invalidation/invalidation-hints.module.d.ts +2 -0
- package/dist/invalidation/invalidation-hints.module.js +4 -1
- package/dist/invalidation/me-stream.d.ts +1 -11
- package/dist/invalidation/me-stream.js +12 -41
- package/dist/invalidation/org-intent-bridge.d.ts +18 -0
- package/dist/invalidation/org-intent-bridge.js +46 -0
- package/dist/models/enablement.d.ts +3 -1
- package/dist/models/enablement.js +25 -5
- package/dist/orgs/invitations.controller.d.ts +4 -7
- package/dist/orgs/invitations.controller.js +8 -5
- package/dist/orgs/invitations.service.d.ts +17 -3
- package/dist/orgs/invitations.service.js +35 -13
- package/dist/orgs/members.service.d.ts +35 -0
- package/dist/orgs/members.service.js +52 -3
- package/dist/orgs/offboarding.d.ts +3 -1
- package/dist/orgs/offboarding.js +7 -3
- package/dist/orgs/orgs.controller.d.ts +11 -4
- package/dist/orgs/orgs.controller.js +25 -5
- package/dist/orgs/orgs.module.js +3 -0
- package/dist/orgs/orgs.schemas.d.ts +14 -0
- package/dist/orgs/orgs.schemas.js +19 -2
- package/dist/orgs/orgs.service.d.ts +24 -2
- package/dist/orgs/orgs.service.js +47 -4
- package/dist/orgs/security-settings.service.d.ts +14 -6
- package/dist/orgs/security-settings.service.js +18 -13
- package/dist/orgs/settings.controller.d.ts +7 -4
- package/dist/platform/exclusions.js +15 -0
- package/dist/platform/ops/accounts.ops.js +7 -16
- package/dist/platform/ops/admin-items.ops.js +7 -7
- package/dist/platform/ops/automations.ops.js +6 -4
- package/dist/platform/ops/evals.ops.js +30 -15
- package/dist/platform/ops/org-settings.ops.js +2 -2
- package/dist/platform/ops/orgs.ops.js +44 -27
- package/dist/push/delivery.d.ts +3 -1
- package/dist/push/delivery.js +7 -3
- package/dist/push/push-processor.js +8 -1
- package/dist/roles/worker.module.js +3 -0
- package/dist/runtime/step-log.d.ts +1 -1
- package/dist/runtime/step-log.js +5 -4
- package/dist/runtime/stream-limit.d.ts +13 -0
- package/dist/runtime/stream-limit.js +40 -0
- package/dist/runtime/stream.controller.d.ts +2 -0
- package/dist/runtime/stream.controller.js +2 -0
- package/dist/runtime/stream.d.ts +1 -0
- package/dist/runtime/stream.js +15 -6
- package/dist/sandbox/permission-authority.module.js +6 -1
- package/dist/sandbox/permission-transitions.d.ts +3 -1
- package/dist/sandbox/permission-transitions.js +17 -2
- package/dist/setup/kernel-checks.d.ts +3 -3
- package/dist/setup/kernel-checks.js +4 -4
- package/dist/setup/setup-check-registry.d.ts +16 -5
- package/dist/setup/setup-check-registry.js +11 -3
- package/dist/setup/setup-checks.service.d.ts +1 -2
- package/dist/setup/setup-checks.service.js +7 -6
- package/dist/skills/agent-skills.service.d.ts +6 -1
- package/dist/skills/agent-skills.service.js +12 -3
- package/dist/skills/changes.service.d.ts +6 -1
- package/dist/skills/changes.service.js +11 -3
- package/dist/skills/conversation-catalog.d.ts +3 -0
- package/dist/skills/conversation-catalog.js +2 -0
- package/dist/skills/skills.module.js +3 -0
- package/dist/skills/skills.service.d.ts +3 -1
- package/dist/skills/skills.service.js +8 -4
- package/dist/tools/admin-connectors.d.ts +10 -8
- package/dist/tools/admin-connectors.js +12 -10
- package/dist/tools/approvals.service.d.ts +12 -1
- package/dist/tools/approvals.service.js +36 -9
- package/dist/tools/builtins/automations.d.ts +1 -1
- package/dist/tools/builtins/automations.js +1 -1
- package/dist/tools/connectors.service.d.ts +3 -1
- package/dist/tools/connectors.service.js +29 -7
- package/dist/tools/tools.module.js +3 -0
- package/dist/ui/admin-ui.controller.d.ts +3 -1
- package/dist/ui/admin-ui.controller.js +3 -1
- package/dist/ui/ui-stream.d.ts +2 -0
- package/dist/ui/ui-stream.js +20 -6
- package/dist/ui/views.controller.d.ts +4 -2
- package/dist/ui/views.controller.js +4 -2
- package/package.json +3 -3
- package/src/migrations/0234_extension_grant_epoch.sql +141 -0
- package/src/migrations/0235_extension_revision_grants.sql +166 -0
- package/src/migrations/0236_paged_table_idx.sql +33 -0
- package/src/migrations/0237_extension_handoff_health.sql +18 -0
|
@@ -20,6 +20,8 @@ import { Transactional } from "../infra/database/transactional.decorator.js";
|
|
|
20
20
|
import { XactLock } from "../infra/database/xact-lock.js";
|
|
21
21
|
import { KernelEvents } from "../infra/events/kernel-events.js";
|
|
22
22
|
import { OutboxService } from "../infra/outbox/outbox.service.js";
|
|
23
|
+
import { publishCapabilities, publishPlatformCapabilities, } from "../invalidation/audiences.js";
|
|
24
|
+
import { InvalidationHints } from "../invalidation/invalidation-hints.js";
|
|
23
25
|
import { EFFECT_CANDIDATES_LOCK, oweEffectWork } from "./effect-work.js";
|
|
24
26
|
import { cancelEnableRequestsOfBundle, reconcileEnableRequestsOf, settleEnableRequests, } from "./enable-requests.js";
|
|
25
27
|
export const COMPONENT_SCOPE_TABLE = {
|
|
@@ -49,11 +51,12 @@ export async function writeComponentSwitch(db, subject, orgId, enabled, actor) {
|
|
|
49
51
|
/**
|
|
50
52
|
* Apply a typed scope change in the caller's transaction and under its target lock. Every scope
|
|
51
53
|
* write re-checks the pending enable requests of the subject in every org
|
|
52
|
-
* ({@link reconcileEnableRequestsOf}), so no caller can narrow a scope and leave a stale request
|
|
54
|
+
* ({@link reconcileEnableRequestsOf}), so no caller can narrow a scope and leave a stale request;
|
|
55
|
+
* `hints` publishes the requests it settles.
|
|
53
56
|
*/
|
|
54
|
-
export async function writeScope(db, change) {
|
|
57
|
+
export async function writeScope(db, hints, change) {
|
|
55
58
|
await writeScopeRows(db, change);
|
|
56
|
-
await reconcileEnableRequestsOf(db, { kind: change.kind, id: change.id }, null);
|
|
59
|
+
await reconcileEnableRequestsOf(db, hints, { kind: change.kind, id: change.id }, null);
|
|
57
60
|
}
|
|
58
61
|
async function writeScopeRows(db, change) {
|
|
59
62
|
const { kind, id, scope, orgs } = change;
|
|
@@ -114,7 +117,8 @@ let ScopeWriter = class ScopeWriter {
|
|
|
114
117
|
adminLock;
|
|
115
118
|
txHost;
|
|
116
119
|
events;
|
|
117
|
-
|
|
120
|
+
hints;
|
|
121
|
+
constructor(kdb, installLock, xactLock, outbox, adminLock, txHost, events, hints) {
|
|
118
122
|
this.kdb = kdb;
|
|
119
123
|
this.installLock = installLock;
|
|
120
124
|
this.xactLock = xactLock;
|
|
@@ -122,6 +126,7 @@ let ScopeWriter = class ScopeWriter {
|
|
|
122
126
|
this.adminLock = adminLock;
|
|
123
127
|
this.txHost = txHost;
|
|
124
128
|
this.events = events;
|
|
129
|
+
this.hints = hints;
|
|
125
130
|
}
|
|
126
131
|
async platformChange(actor, confirmation, prepare) {
|
|
127
132
|
await this.xactLock.lock(EFFECT_CANDIDATES_LOCK);
|
|
@@ -145,13 +150,17 @@ let ScopeWriter = class ScopeWriter {
|
|
|
145
150
|
.execute()).map((row) => row.org_id)
|
|
146
151
|
: [];
|
|
147
152
|
// (writeScope re-checks the pending enable requests of the subject)
|
|
148
|
-
await writeScope(db, change);
|
|
153
|
+
await writeScope(db, this.hints, change);
|
|
149
154
|
if (change.kind === "connector_template") {
|
|
150
155
|
await this.oweConnectorTemplate(change.id, { previousOrgs });
|
|
151
156
|
}
|
|
152
157
|
if (change.kind === "plugin" || change.kind === "connector_template") {
|
|
153
158
|
this.refreshIsolatedOrgIntent();
|
|
154
159
|
}
|
|
160
|
+
// a skill or agent template owes no effect pairs (no affected-org set): `platform-caps`
|
|
161
|
+
if (change.kind === "skill" || change.kind === "agent_template") {
|
|
162
|
+
publishPlatformCapabilities(this.hints);
|
|
163
|
+
}
|
|
155
164
|
}
|
|
156
165
|
/** Persist deployment enablement after platform confirmation. */
|
|
157
166
|
async setDisabled(subject, disabled) {
|
|
@@ -163,10 +172,13 @@ let ScopeWriter = class ScopeWriter {
|
|
|
163
172
|
.execute();
|
|
164
173
|
if (subject.kind === "connector_template")
|
|
165
174
|
await this.oweConnectorTemplate(subject.id, {});
|
|
166
|
-
await reconcileEnableRequestsOf(this.kdb.db, subject, null);
|
|
175
|
+
await reconcileEnableRequestsOf(this.kdb.db, this.hints, subject, null);
|
|
167
176
|
if ((subject.kind === "plugin" && disabled) || subject.kind === "connector_template") {
|
|
168
177
|
this.refreshIsolatedOrgIntent();
|
|
169
178
|
}
|
|
179
|
+
if (subject.kind === "skill" || subject.kind === "agent_template") {
|
|
180
|
+
publishPlatformCapabilities(this.hints);
|
|
181
|
+
}
|
|
170
182
|
}
|
|
171
183
|
/**
|
|
172
184
|
* Store local intent under the caller's transaction and org lock. The org's pending enable
|
|
@@ -209,10 +221,10 @@ let ScopeWriter = class ScopeWriter {
|
|
|
209
221
|
}
|
|
210
222
|
await oweEffectWork(this.outbox, db, { itemIds: [subject.id], orgId, previousOrgs: [orgId] });
|
|
211
223
|
if (enabled) {
|
|
212
|
-
await settleEnableRequests(db, orgId, { kind: "plugin", id: subject.id }, actor, opts);
|
|
224
|
+
await settleEnableRequests(db, this.hints, orgId, { kind: "plugin", id: subject.id }, actor, opts);
|
|
213
225
|
}
|
|
214
226
|
else
|
|
215
|
-
await cancelEnableRequestsOfBundle(db, orgId, subject.id, actor);
|
|
227
|
+
await cancelEnableRequestsOfBundle(db, this.hints, orgId, subject.id, actor);
|
|
216
228
|
}
|
|
217
229
|
else {
|
|
218
230
|
await writeComponentSwitch(db, { kind: subject.kind, id: subject.id }, orgId, enabled, actor);
|
|
@@ -220,12 +232,17 @@ let ScopeWriter = class ScopeWriter {
|
|
|
220
232
|
await this.oweConnectorTemplate(subject.id, { orgId, previousOrgs: [orgId] });
|
|
221
233
|
}
|
|
222
234
|
if (enabled && subject.kind !== "theme") {
|
|
223
|
-
await settleEnableRequests(db, orgId, { kind: subject.kind, id: subject.id }, actor, opts);
|
|
235
|
+
await settleEnableRequests(db, this.hints, orgId, { kind: subject.kind, id: subject.id }, actor, opts);
|
|
224
236
|
}
|
|
225
237
|
}
|
|
226
238
|
if ((subject.kind === "plugin" && !enabled) || subject.kind === "connector_template") {
|
|
239
|
+
// (its `catalog.org-intent-changed` publishes the org's `capabilities` hint too)
|
|
227
240
|
this.refreshIsolatedOrgIntent(orgId);
|
|
228
241
|
}
|
|
242
|
+
else {
|
|
243
|
+
// the org's committed intent changed: its members' pickers refetch
|
|
244
|
+
publishCapabilities(this.hints, [orgId]);
|
|
245
|
+
}
|
|
229
246
|
}
|
|
230
247
|
async oweConnectorTemplate(id, scope) {
|
|
231
248
|
const db = this.kdb.db;
|
|
@@ -263,6 +280,7 @@ ScopeWriter = __decorate([
|
|
|
263
280
|
__param(3, Inject(OutboxService)),
|
|
264
281
|
__param(4, Inject(SuperAdminLock)),
|
|
265
282
|
__param(5, Inject(TransactionHost)),
|
|
266
|
-
__param(6, Inject(KernelEvents))
|
|
283
|
+
__param(6, Inject(KernelEvents)),
|
|
284
|
+
__param(7, Inject(InvalidationHints))
|
|
267
285
|
], ScopeWriter);
|
|
268
286
|
export { ScopeWriter };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { KernelSchemaDb } from "../db/kernel-schema.js";
|
|
2
|
+
import type { HintPublisher } from "../invalidation/audiences.js";
|
|
2
3
|
import { type ComponentRow } from "./component-state.js";
|
|
3
4
|
import type { PluginScope } from "./scope.js";
|
|
4
5
|
/**
|
|
@@ -7,7 +8,7 @@ import type { PluginScope } from "./scope.js";
|
|
|
7
8
|
* `catalog.scope_changed`; returns whether the scope changed (the caller enqueues the item's
|
|
8
9
|
* scope sync after the commit).
|
|
9
10
|
*/
|
|
10
|
-
export declare function narrowItemOnUnshare(db: KernelSchemaDb, actor: string | null, item: {
|
|
11
|
+
export declare function narrowItemOnUnshare(db: KernelSchemaDb, hints: HintPublisher, actor: string | null, item: {
|
|
11
12
|
id: string;
|
|
12
13
|
name: string;
|
|
13
14
|
scope: PluginScope;
|
|
@@ -18,4 +19,4 @@ export declare function narrowItemOnUnshare(db: KernelSchemaDb, actor: string |
|
|
|
18
19
|
* to `named` = owner + the live orgs where it is on now ({@link componentOn}). A component that
|
|
19
20
|
* follows its plugin is narrowed with the plugin. Audits `component.scope_changed`.
|
|
20
21
|
*/
|
|
21
|
-
export declare function narrowComponentOnUnshare(db: KernelSchemaDb, actor: string | null, c: ComponentRow): Promise<boolean>;
|
|
22
|
+
export declare function narrowComponentOnUnshare(db: KernelSchemaDb, hints: HintPublisher, actor: string | null, c: ComponentRow): Promise<boolean>;
|
package/dist/catalog/unshare.js
CHANGED
|
@@ -12,7 +12,7 @@ async function liveOrgIds(db) {
|
|
|
12
12
|
* `catalog.scope_changed`; returns whether the scope changed (the caller enqueues the item's
|
|
13
13
|
* scope sync after the commit).
|
|
14
14
|
*/
|
|
15
|
-
export async function narrowItemOnUnshare(db, actor, item) {
|
|
15
|
+
export async function narrowItemOnUnshare(db, hints, actor, item) {
|
|
16
16
|
const ownerOrgId = item.owner_org_id;
|
|
17
17
|
if (ownerOrgId === null || item.scope === "named")
|
|
18
18
|
return false;
|
|
@@ -37,7 +37,7 @@ export async function narrowItemOnUnshare(db, actor, item) {
|
|
|
37
37
|
...[...installs, ...switches].map((r) => r.org_id).filter((o) => live.has(o)),
|
|
38
38
|
]),
|
|
39
39
|
].sort();
|
|
40
|
-
await writeScope(db, { kind: "plugin", id: item.id, scope: "named", orgs: kept });
|
|
40
|
+
await writeScope(db, hints, { kind: "plugin", id: item.id, scope: "named", orgs: kept });
|
|
41
41
|
return kept;
|
|
42
42
|
});
|
|
43
43
|
await audit(db, {
|
|
@@ -58,7 +58,7 @@ export async function narrowItemOnUnshare(db, actor, item) {
|
|
|
58
58
|
* to `named` = owner + the live orgs where it is on now ({@link componentOn}). A component that
|
|
59
59
|
* follows its plugin is narrowed with the plugin. Audits `component.scope_changed`.
|
|
60
60
|
*/
|
|
61
|
-
export async function narrowComponentOnUnshare(db, actor, c) {
|
|
61
|
+
export async function narrowComponentOnUnshare(db, hints, actor, c) {
|
|
62
62
|
const ownerOrgId = c.ownerOrgId;
|
|
63
63
|
if (ownerOrgId === null || c.scopeMode !== "own" || c.scope === "named")
|
|
64
64
|
return false;
|
|
@@ -67,7 +67,7 @@ export async function narrowComponentOnUnshare(db, actor, c) {
|
|
|
67
67
|
const st = await loadScopeState(db, c.kind, [c]);
|
|
68
68
|
const on = (await liveOrgIds(db)).filter((o) => componentOn(c, pluginFactsOf(st, c.itemId, o), listedIn(st, c.id, o), switchOf(st, c.id, o)));
|
|
69
69
|
const kept = [...new Set([ownerOrgId, ...on])].sort();
|
|
70
|
-
await writeScope(db, {
|
|
70
|
+
await writeScope(db, hints, {
|
|
71
71
|
kind: c.kind,
|
|
72
72
|
id: c.id,
|
|
73
73
|
scopeMode: "own",
|
|
@@ -135,6 +135,34 @@ let ClientAccess = class ClientAccess {
|
|
|
135
135
|
*/
|
|
136
136
|
served(db) {
|
|
137
137
|
const staleSeconds = STALE_RECONCILE_PERIODS * this.config.get().extensionHost.reconcileIntervalSeconds;
|
|
138
|
+
const declaredComponents = sql `p.section -> 'manifest' -> 'permissions' -> 'ui' -> 'components'`;
|
|
139
|
+
const approvedComponents = sql `coalesce(s.permissions -> 'permissions' -> 'ui' -> 'components', '[]'::jsonb)`;
|
|
140
|
+
// The package retains authored declarations. The snapshot approves the component IDs.
|
|
141
|
+
const componentApproval = sql `
|
|
142
|
+
not exists (
|
|
143
|
+
select 1 from jsonb_array_elements(
|
|
144
|
+
case
|
|
145
|
+
when ${declaredComponents} is null then '[]'::jsonb
|
|
146
|
+
when jsonb_typeof(${declaredComponents}) = 'array' then ${declaredComponents}
|
|
147
|
+
else '[null]'::jsonb
|
|
148
|
+
end
|
|
149
|
+
) as declared(entry)
|
|
150
|
+
where not coalesce(
|
|
151
|
+
${approvedComponents} @> case
|
|
152
|
+
when jsonb_typeof(declared.entry) = 'string'
|
|
153
|
+
then jsonb_build_array(declared.entry)
|
|
154
|
+
when jsonb_typeof(declared.entry -> 'value') = 'string'
|
|
155
|
+
and not (declared.entry ? 'covers')
|
|
156
|
+
then jsonb_build_array(declared.entry -> 'value')
|
|
157
|
+
when jsonb_typeof(declared.entry -> 'covers') = 'array'
|
|
158
|
+
and not (declared.entry ? 'value')
|
|
159
|
+
and declared.entry -> 'covers' <> '[]'::jsonb
|
|
160
|
+
then declared.entry -> 'covers'
|
|
161
|
+
end,
|
|
162
|
+
false
|
|
163
|
+
)
|
|
164
|
+
)
|
|
165
|
+
`;
|
|
138
166
|
return db
|
|
139
167
|
.selectFrom("extension_installs as i")
|
|
140
168
|
.innerJoin("extension_client_builds as b", "b.plugin", "i.name")
|
|
@@ -142,7 +170,7 @@ let ClientAccess = class ClientAccess {
|
|
|
142
170
|
.innerJoin("extension_permission_snapshots as s", "s.plugin", "i.name")
|
|
143
171
|
.where("i.desired_state", "=", "enabled")
|
|
144
172
|
.where(sql `s.permissions -> 'permissions' -> 'client' = 'true'::jsonb`)
|
|
145
|
-
.where(
|
|
173
|
+
.where(componentApproval)
|
|
146
174
|
.where((eb) => eb.exists(eb
|
|
147
175
|
.selectFrom("extension_replica_status as r")
|
|
148
176
|
.select(sql `1`.as("one"))
|
package/dist/config/schema.d.ts
CHANGED
|
@@ -10,6 +10,11 @@ export interface FieldMeta {
|
|
|
10
10
|
* 构造给 Zod 4 `.meta()` 使用的字段元信息。
|
|
11
11
|
* 用法:`z.string().meta(meta({ secret: true, description: "..." }))`。
|
|
12
12
|
*/
|
|
13
|
+
/** Defaults of `extensionHost.capacity`, also used where a hand-built config leaves it out. */
|
|
14
|
+
export declare const EXTENSION_CAPACITY_DEFAULTS: {
|
|
15
|
+
readonly grantEpochMaxAgeMs: 3000;
|
|
16
|
+
readonly grantCacheEntries: 10000;
|
|
17
|
+
};
|
|
13
18
|
export declare function meta(opts: FieldMeta): FieldMeta;
|
|
14
19
|
/** `sandbox.limits.maxCommandSeconds` 的默认值。 */
|
|
15
20
|
export declare const DEFAULT_MAX_COMMAND_SECONDS = 7200;
|
|
@@ -102,6 +107,10 @@ export declare const KernelConfigSchema: z.ZodObject<{
|
|
|
102
107
|
socketDir: z.ZodString;
|
|
103
108
|
postgresSocket: z.ZodString;
|
|
104
109
|
}, z.core.$strict>>;
|
|
110
|
+
capacity: z.ZodPrefault<z.ZodObject<{
|
|
111
|
+
grantEpochMaxAgeMs: z.ZodDefault<z.ZodNumber>;
|
|
112
|
+
grantCacheEntries: z.ZodDefault<z.ZodNumber>;
|
|
113
|
+
}, z.core.$strict>>;
|
|
105
114
|
drainSeconds: z.ZodDefault<z.ZodNumber>;
|
|
106
115
|
disposeTimeoutSeconds: z.ZodDefault<z.ZodNumber>;
|
|
107
116
|
reloadSetupTimeoutSeconds: z.ZodDefault<z.ZodNumber>;
|
|
@@ -176,6 +185,9 @@ export declare const KernelConfigSchema: z.ZodObject<{
|
|
|
176
185
|
sseHeartbeatMs: z.ZodDefault<z.ZodNumber>;
|
|
177
186
|
sseRecheckMs: z.ZodDefault<z.ZodNumber>;
|
|
178
187
|
meStreamMaxPerAccount: z.ZodDefault<z.ZodNumber>;
|
|
188
|
+
orgUiStreamMaxPerAccount: z.ZodDefault<z.ZodNumber>;
|
|
189
|
+
platformUiStreamMaxPerAccount: z.ZodDefault<z.ZodNumber>;
|
|
190
|
+
conversationStreamMaxPerAccount: z.ZodDefault<z.ZodNumber>;
|
|
179
191
|
}, z.core.$strict>>;
|
|
180
192
|
tools: z.ZodDefault<z.ZodObject<{
|
|
181
193
|
timeoutMs: z.ZodDefault<z.ZodNumber>;
|
package/dist/config/schema.js
CHANGED
|
@@ -9,6 +9,11 @@ import { privateHostEntryProblem } from "../net/public-address.js";
|
|
|
9
9
|
* 构造给 Zod 4 `.meta()` 使用的字段元信息。
|
|
10
10
|
* 用法:`z.string().meta(meta({ secret: true, description: "..." }))`。
|
|
11
11
|
*/
|
|
12
|
+
/** Defaults of `extensionHost.capacity`, also used where a hand-built config leaves it out. */
|
|
13
|
+
export const EXTENSION_CAPACITY_DEFAULTS = {
|
|
14
|
+
grantEpochMaxAgeMs: 3000,
|
|
15
|
+
grantCacheEntries: 10_000,
|
|
16
|
+
};
|
|
12
17
|
export function meta(opts) {
|
|
13
18
|
return { ...opts };
|
|
14
19
|
}
|
|
@@ -506,6 +511,27 @@ export const KernelConfigSchema = z.strictObject({
|
|
|
506
511
|
})),
|
|
507
512
|
})
|
|
508
513
|
.optional(),
|
|
514
|
+
capacity: z
|
|
515
|
+
.strictObject({
|
|
516
|
+
grantEpochMaxAgeMs: z
|
|
517
|
+
.number()
|
|
518
|
+
.int()
|
|
519
|
+
.min(1500)
|
|
520
|
+
.max(3500)
|
|
521
|
+
.default(EXTENSION_CAPACITY_DEFAULTS.grantEpochMaxAgeMs)
|
|
522
|
+
.meta(meta({
|
|
523
|
+
description: "Milliseconds a replica trusts its cached isolated extension grants after its last successful read of the grant epoch (read every second); when the epoch is older, new isolated calls wait for a fresh read and are refused if it fails. Kept below the 4 s fence deadline, which leaves 1 s of slack under the 5 s revocation bound",
|
|
524
|
+
})),
|
|
525
|
+
grantCacheEntries: z
|
|
526
|
+
.number()
|
|
527
|
+
.int()
|
|
528
|
+
.positive()
|
|
529
|
+
.default(EXTENSION_CAPACITY_DEFAULTS.grantCacheEntries)
|
|
530
|
+
.meta(meta({
|
|
531
|
+
description: "Maximum isolated extension grants (one per running extension instance and org) each replica caches; the least recently used idle grant is evicted first, and a call is refused when every cached grant is in use",
|
|
532
|
+
})),
|
|
533
|
+
})
|
|
534
|
+
.prefault({}),
|
|
509
535
|
drainSeconds: z
|
|
510
536
|
.number()
|
|
511
537
|
.int()
|
|
@@ -993,6 +1019,33 @@ export const KernelConfigSchema = z.strictObject({
|
|
|
993
1019
|
hot: true,
|
|
994
1020
|
description: "Maximum concurrent account invalidation streams (GET /api/v1/orgs/:orgId/me/stream) per account on one replica; a new stream over the limit closes that account's oldest stream on the replica",
|
|
995
1021
|
})),
|
|
1022
|
+
orgUiStreamMaxPerAccount: z
|
|
1023
|
+
.number()
|
|
1024
|
+
.int()
|
|
1025
|
+
.positive()
|
|
1026
|
+
.default(8)
|
|
1027
|
+
.meta(meta({
|
|
1028
|
+
hot: true,
|
|
1029
|
+
description: "Maximum concurrent org UI streams per account on one replica; a new stream over the limit closes that account's oldest stream of the same family on the replica",
|
|
1030
|
+
})),
|
|
1031
|
+
platformUiStreamMaxPerAccount: z
|
|
1032
|
+
.number()
|
|
1033
|
+
.int()
|
|
1034
|
+
.positive()
|
|
1035
|
+
.default(8)
|
|
1036
|
+
.meta(meta({
|
|
1037
|
+
hot: true,
|
|
1038
|
+
description: "Maximum concurrent platform UI streams per account on one replica; a new stream over the limit closes that account's oldest stream of the same family on the replica",
|
|
1039
|
+
})),
|
|
1040
|
+
conversationStreamMaxPerAccount: z
|
|
1041
|
+
.number()
|
|
1042
|
+
.int()
|
|
1043
|
+
.positive()
|
|
1044
|
+
.default(16)
|
|
1045
|
+
.meta(meta({
|
|
1046
|
+
hot: true,
|
|
1047
|
+
description: "Maximum concurrent conversation streams per account on one replica; a new stream over the limit closes that account's oldest stream of the same family on the replica",
|
|
1048
|
+
})),
|
|
996
1049
|
})
|
|
997
1050
|
.default({
|
|
998
1051
|
maxSteps: 0,
|
|
@@ -1008,6 +1061,9 @@ export const KernelConfigSchema = z.strictObject({
|
|
|
1008
1061
|
sseHeartbeatMs: 15000,
|
|
1009
1062
|
sseRecheckMs: 60000,
|
|
1010
1063
|
meStreamMaxPerAccount: 8,
|
|
1064
|
+
orgUiStreamMaxPerAccount: 8,
|
|
1065
|
+
platformUiStreamMaxPerAccount: 8,
|
|
1066
|
+
conversationStreamMaxPerAccount: 16,
|
|
1011
1067
|
}),
|
|
1012
1068
|
tools: z
|
|
1013
1069
|
.strictObject({
|
package/dist/ctx/create-ctx.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type EmbedClaims, type ExtensionContext, type ExtensionManifest, type ExtensionPointRef, type HttpAccess, type Logger, type RouteCaller, resolveUiSlots, type SetupCheckArgs, type SetupGuidePlace, type ToolHandler, type ToolSpec, type ToolWatcher, type TriggerEvent } from "@capybara-hq/plugin-sdk";
|
|
1
|
+
import { type EmbedClaims, type ExtensionContext, type ExtensionManifest, type ExtensionPointRef, type HttpAccess, type Logger, type ObjectStore, type RouteCaller, resolveUiSlots, type SetupCheckArgs, type SetupGuidePlace, type ToolHandler, type ToolSpec, type ToolWatcher, type TriggerEvent } from "@capybara-hq/plugin-sdk";
|
|
2
2
|
import type { Redis } from "ioredis";
|
|
3
3
|
import type { Kysely } from "kysely";
|
|
4
4
|
import type { TriggerEventsService } from "../automations/events/trigger-events.service.js";
|
|
@@ -170,21 +170,6 @@ export type RegisteredSetupCheck = Readonly<{
|
|
|
170
170
|
place: SetupGuidePlace;
|
|
171
171
|
run: (args: SetupCheckArgs) => Promise<unknown>;
|
|
172
172
|
}>;
|
|
173
|
-
/** 插件经 `ctx.extensionPoints` 取用其他插件能力时,内核注入的访问接口。 */
|
|
174
|
-
export interface ExtensionPointAccess {
|
|
175
|
-
/** 已加载(setup 完成)的提供方,按加载顺序;按完整引用(含主版本)精确匹配。 */
|
|
176
|
-
providers(ref: ExtensionPointRef): {
|
|
177
|
-
plugin: string;
|
|
178
|
-
impl: unknown;
|
|
179
|
-
}[];
|
|
180
|
-
/** Names of the extensions enabled in the organization (the org intent projection, `enabled.ts`); queried every time, not cached. */
|
|
181
|
-
enabledPlugins(orgId: string): Promise<Set<string>>;
|
|
182
|
-
/**
|
|
183
|
-
* Whether the extension's effective config is valid in the organization (layering spec A §6):
|
|
184
|
-
* a provider that is not is excluded from point resolution for that org.
|
|
185
|
-
*/
|
|
186
|
-
configOk(orgId: string, plugin: string): Promise<boolean>;
|
|
187
|
-
}
|
|
188
173
|
/**
|
|
189
174
|
* Queries the names of the extensions enabled in the organization (org config rows plus the
|
|
190
175
|
* required bootstrap plugins, see `extensions/enabled.ts`), not cached.
|
|
@@ -280,15 +265,13 @@ export declare class LiveConfig {
|
|
|
280
265
|
* replicas; `ui.verifyEmbedToken` checks an embed token the kernel signed: `claims.plugin` must be
|
|
281
266
|
* this extension, the extension still enabled in that org and the caller still an active member of
|
|
282
267
|
* the org (org not deleted); returns the current role;
|
|
283
|
-
* - `extensionPoints` only gives extension points declared in `requires` / `optional` that are not
|
|
284
|
-
* brokered (through `extensionPointAccess`).
|
|
285
268
|
* - `hooks.on` only during setup, only mount points declared in `permissions.hooks` and available
|
|
286
269
|
* (`HOOKS_AVAILABLE`), `policy` only on `POLICY_HOOKS` declared in `permissions.policyHooks`; kept on the ctx (`registeredHooks`, read by
|
|
287
270
|
* the host's `HookRegistry` from active instances only) and recorded in the ledger.
|
|
288
271
|
* An undeclared access throws `ExtensionPermissionError` and audits `extension.permission_denied`
|
|
289
272
|
* (once per extension and item).
|
|
290
273
|
*/
|
|
291
|
-
export declare function createExtensionContext(deps: KernelDeps, manifest: ExtensionManifest, deploymentConfig: unknown,
|
|
274
|
+
export declare function createExtensionContext(deps: KernelDeps, manifest: ExtensionManifest, deploymentConfig: unknown, objectStore?: () => ObjectStore | undefined,
|
|
292
275
|
/** The package this instance was loaded from (null: not from an install record). */
|
|
293
276
|
identity?: {
|
|
294
277
|
sha256: string | null;
|
package/dist/ctx/create-ctx.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CONVERSATION_TARGET_EXTENSION_POINT, CtxReadError, DEVICE_PROVIDER_EXTENSION_POINT, DeviceAccessError,
|
|
1
|
+
import { CONVERSATION_TARGET_EXTENSION_POINT, CtxReadError, DEVICE_PROVIDER_EXTENSION_POINT, DeviceAccessError, ExtensionPermissionError, FILE_PREVIEW_EXTENSION_POINT, InboxError, resolveUiSlots, SETUP_CHECK_ID_RE, SETUP_GUIDE_PLACES, TriggerError, validateFilePreviewProvider, validateToolSpec, } from "@capybara-hq/plugin-sdk";
|
|
2
2
|
import { conversationTopic } from "../conversations/event-log.js";
|
|
3
3
|
import { checkExternalText } from "../conversations/external/external-calls.js";
|
|
4
4
|
import { pluginSchemaName } from "../db/extension-db.js";
|
|
@@ -150,12 +150,6 @@ async function recordDenial(deps, plugin, item) {
|
|
|
150
150
|
deps.log.warn("plugin permission denial audit failed", { plugin, item, err: e });
|
|
151
151
|
}
|
|
152
152
|
}
|
|
153
|
-
/** 未注入能力访问时(单独构造 ctx 的测试等):没有任何提供方,组织启用照常查库。 */
|
|
154
|
-
const noProviders = (deps) => ({
|
|
155
|
-
providers: () => [],
|
|
156
|
-
enabledPlugins: (orgId) => queryEnabledPlugins(deps.db, orgId),
|
|
157
|
-
configOk: async () => true,
|
|
158
|
-
});
|
|
159
153
|
/**
|
|
160
154
|
* An extension instance's deployment config (validated): `ctx.config` is a getter that reads it.
|
|
161
155
|
* When a hot field changes the host replaces `value` (C10) and the extension's next read of
|
|
@@ -195,15 +189,13 @@ export class LiveConfig {
|
|
|
195
189
|
* replicas; `ui.verifyEmbedToken` checks an embed token the kernel signed: `claims.plugin` must be
|
|
196
190
|
* this extension, the extension still enabled in that org and the caller still an active member of
|
|
197
191
|
* the org (org not deleted); returns the current role;
|
|
198
|
-
* - `extensionPoints` only gives extension points declared in `requires` / `optional` that are not
|
|
199
|
-
* brokered (through `extensionPointAccess`).
|
|
200
192
|
* - `hooks.on` only during setup, only mount points declared in `permissions.hooks` and available
|
|
201
193
|
* (`HOOKS_AVAILABLE`), `policy` only on `POLICY_HOOKS` declared in `permissions.policyHooks`; kept on the ctx (`registeredHooks`, read by
|
|
202
194
|
* the host's `HookRegistry` from active instances only) and recorded in the ledger.
|
|
203
195
|
* An undeclared access throws `ExtensionPermissionError` and audits `extension.permission_denied`
|
|
204
196
|
* (once per extension and item).
|
|
205
197
|
*/
|
|
206
|
-
export function createExtensionContext(deps, manifest, deploymentConfig,
|
|
198
|
+
export function createExtensionContext(deps, manifest, deploymentConfig, objectStore = () => undefined,
|
|
207
199
|
/** The package this instance was loaded from (null: not from an install record). */
|
|
208
200
|
identity = { sha256: null }) {
|
|
209
201
|
const name = manifest.name;
|
|
@@ -243,7 +235,7 @@ identity = { sha256: null }) {
|
|
|
243
235
|
// (宿主不会加载这样的插件,见 approvals.ts;单独构造 ctx 的测试会走到这里)
|
|
244
236
|
const storageApi = perms.storage
|
|
245
237
|
? new PrefixedStorage({
|
|
246
|
-
provider:
|
|
238
|
+
provider: objectStore,
|
|
247
239
|
plugins: async () => [name],
|
|
248
240
|
}).forPlugin(name)
|
|
249
241
|
: undefined;
|
|
@@ -667,10 +659,6 @@ identity = { sha256: null }) {
|
|
|
667
659
|
const declaredHooks = new Set(perms.hooks ?? []);
|
|
668
660
|
const declaredPolicyHooks = new Set(perms.policyHooks ?? []);
|
|
669
661
|
const registeredHooks = [];
|
|
670
|
-
const declaredPoints = new Set([
|
|
671
|
-
...(manifest.requires ?? []),
|
|
672
|
-
...(manifest.optional ?? []),
|
|
673
|
-
]);
|
|
674
662
|
const uiReg = new PluginUiRegistration(manifest, deny);
|
|
675
663
|
const declaredSetupChecks = new Set(perms.setupChecks ?? []);
|
|
676
664
|
const setupChecks = new Map();
|
|
@@ -722,83 +710,6 @@ identity = { sha256: null }) {
|
|
|
722
710
|
};
|
|
723
711
|
/** Ids of the extension's `platform.page` contributions (their invalidate takes no orgId). */
|
|
724
712
|
const platformUi = new Set([...uiSlots].filter(([, s]) => s.id === "platform.page").map(([id]) => id));
|
|
725
|
-
/** 校验能力可取用(非 brokered、已在清单声明),返回其登记信息。 */
|
|
726
|
-
const checkExtensionPoint = (ref) => {
|
|
727
|
-
const capName = parseExtensionPoint(ref).name;
|
|
728
|
-
const info = Object.hasOwn(EXTENSION_POINTS, capName) ? EXTENSION_POINTS[capName] : undefined;
|
|
729
|
-
if (info?.brokered) {
|
|
730
|
-
throw new Error(`plugin ${name}: extension point ${ref} is brokered and can only be used through the platform API`);
|
|
731
|
-
}
|
|
732
|
-
if (!info || !declaredPoints.has(ref))
|
|
733
|
-
return deny(`requires/optional ${ref}`);
|
|
734
|
-
return info;
|
|
735
|
-
};
|
|
736
|
-
/** 部署级视角选出提供方:指定 provider 时按名找;单选能力取唯一提供方;多选能力必须指定。 */
|
|
737
|
-
const pick = (ref, provider) => {
|
|
738
|
-
const info = checkExtensionPoint(ref);
|
|
739
|
-
const providers = extensionPointAccess.providers(ref);
|
|
740
|
-
if (provider !== undefined) {
|
|
741
|
-
const chosen = providers.find((p) => p.plugin === provider);
|
|
742
|
-
if (!chosen) {
|
|
743
|
-
throw new ExtensionPointUnavailableError(`extension point ${ref} is not provided by plugin ${provider}`);
|
|
744
|
-
}
|
|
745
|
-
return { info, chosen };
|
|
746
|
-
}
|
|
747
|
-
if (info.cardinality === "multi") {
|
|
748
|
-
// 多选能力即使只有一个提供者也要显式指定,避免新增提供者后行为悄悄变化
|
|
749
|
-
throw new Error(`plugin ${name}: extension point ${ref} is multi-provider; specify a provider name (available: ${providers.map((p) => p.plugin).join(", ") || "none"})`);
|
|
750
|
-
}
|
|
751
|
-
const chosen = providers[0];
|
|
752
|
-
if (!chosen)
|
|
753
|
-
throw new ExtensionPointUnavailableError(`extension point ${ref} has no provider`);
|
|
754
|
-
return { info, chosen };
|
|
755
|
-
};
|
|
756
|
-
/**
|
|
757
|
-
* The org's view of the providers: an orgScoped point keeps only those the org enabled (queried
|
|
758
|
-
* every time, not cached), and every point drops those whose effective config is not valid in
|
|
759
|
-
* the org (layering spec A §6: a call on behalf of an org never reaches such a provider).
|
|
760
|
-
*/
|
|
761
|
-
const forOrg = async (orgScoped, orgId, entries) => {
|
|
762
|
-
if (orgId === "" || entries.length === 0)
|
|
763
|
-
return [];
|
|
764
|
-
return withOrgScope(orgId, async () => {
|
|
765
|
-
let out = entries;
|
|
766
|
-
if (orgScoped) {
|
|
767
|
-
const enabled = await extensionPointAccess.enabledPlugins(orgId);
|
|
768
|
-
out = out.filter((e) => enabled.has(e.plugin));
|
|
769
|
-
}
|
|
770
|
-
const ok = await Promise.all(out.map((e) => extensionPointAccess.configOk(orgId, e.plugin)));
|
|
771
|
-
return out.filter((_, i) => ok[i]);
|
|
772
|
-
});
|
|
773
|
-
};
|
|
774
|
-
const listAll = (ref) => {
|
|
775
|
-
const info = checkExtensionPoint(ref);
|
|
776
|
-
return { info, entries: extensionPointAccess.providers(ref).map((p) => ({ ...p })) };
|
|
777
|
-
};
|
|
778
|
-
// 不传 orgId:同步返回;传 orgId:返回 Promise,所有错误都以 reject 交出
|
|
779
|
-
const extensionPoints = {
|
|
780
|
-
get(ref, provider, opts) {
|
|
781
|
-
const orgId = opts?.orgId;
|
|
782
|
-
if (orgId === undefined)
|
|
783
|
-
return pick(ref, provider).chosen.impl;
|
|
784
|
-
return (async () => {
|
|
785
|
-
const { info, chosen } = pick(ref, provider);
|
|
786
|
-
if ((await forOrg(info.orgScoped, orgId, [chosen])).length === 0) {
|
|
787
|
-
throw new ExtensionPointUnavailableError(`extension point ${ref} provider ${chosen.plugin} is not available in organization ${orgId} (not enabled there, or its configuration is not valid there)`);
|
|
788
|
-
}
|
|
789
|
-
return chosen.impl;
|
|
790
|
-
})();
|
|
791
|
-
},
|
|
792
|
-
list(ref, opts) {
|
|
793
|
-
const orgId = opts?.orgId;
|
|
794
|
-
if (orgId === undefined)
|
|
795
|
-
return listAll(ref).entries;
|
|
796
|
-
return (async () => {
|
|
797
|
-
const { info, entries } = listAll(ref);
|
|
798
|
-
return forOrg(info.orgScoped, orgId, entries);
|
|
799
|
-
})();
|
|
800
|
-
},
|
|
801
|
-
};
|
|
802
713
|
const ctx = {
|
|
803
714
|
kv: createKv(deps.redis, name),
|
|
804
715
|
lock: {
|
|
@@ -817,7 +728,6 @@ identity = { sha256: null }) {
|
|
|
817
728
|
};
|
|
818
729
|
},
|
|
819
730
|
},
|
|
820
|
-
extensionPoints,
|
|
821
731
|
// the kernel's guarded client for person-supplied URLs, no permission needed; without the
|
|
822
732
|
// services (a ctx built alone in a test) it refuses rather than reaching the network unguarded
|
|
823
733
|
net: deps.net
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import { type ExtensionDbIdentity } from "../db/extension-db.js";
|
|
2
|
-
import { ExtensionRegistry } from "../extensions/registry.js";
|
|
3
|
-
import { ReplicaStatusStore } from "../extensions/sources.js";
|
|
4
2
|
import { KernelConfigService } from "../infra/config/kernel-config.service.js";
|
|
5
3
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
6
4
|
import { LockService } from "../infra/lock/lock.service.js";
|
|
@@ -13,16 +11,15 @@ export declare class ExtensionEffectRelay {
|
|
|
13
11
|
private readonly effects;
|
|
14
12
|
private readonly keys;
|
|
15
13
|
private readonly identity;
|
|
16
|
-
private readonly registry;
|
|
17
|
-
private readonly status;
|
|
18
14
|
private readonly db;
|
|
19
15
|
readonly config: KernelConfigService;
|
|
20
16
|
readonly lockService: LockService;
|
|
21
17
|
readonly log: KernelLogger;
|
|
22
|
-
constructor(dispatcher: OutboxDispatcher, effects: ExtensionEffects, keys: ExtensionEffectKeys, identity: ExtensionDbIdentity,
|
|
18
|
+
constructor(dispatcher: OutboxDispatcher, effects: ExtensionEffects, keys: ExtensionEffectKeys, identity: ExtensionDbIdentity, db: KernelDb, config: KernelConfigService, lockService: LockService, log: KernelLogger);
|
|
23
19
|
relay(signal?: AbortSignal): Promise<void>;
|
|
24
20
|
retireKeys(): Promise<void>;
|
|
25
21
|
relayOnce(signal?: AbortSignal): Promise<void>;
|
|
22
|
+
private handoffHealth;
|
|
26
23
|
private redrive;
|
|
27
24
|
private ingest;
|
|
28
25
|
private cleanup;
|