@jini-ai/plugins 0.0.0-stage → 0.4.1
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/CHANGELOG.md +27 -0
- package/LICENSE +201 -0
- package/README.md +60 -2
- package/dist/glue/attachment-points/content-lifecycle.d.ts +52 -0
- package/dist/glue/attachment-points/content-lifecycle.js +15 -0
- package/dist/glue/attachment-points/events.d.ts +12 -0
- package/dist/glue/attachment-points/events.js +5 -0
- package/dist/glue/attachment-points/tool-registration.d.ts +23 -0
- package/dist/glue/attachment-points/tool-registration.js +43 -0
- package/dist/glue/capability-gate.d.ts +73 -0
- package/dist/glue/capability-gate.js +41 -0
- package/dist/glue/dispatch.d.ts +20 -0
- package/dist/glue/dispatch.js +9 -0
- package/dist/glue/index.d.ts +8 -0
- package/dist/glue/index.js +8 -0
- package/dist/glue/manifest.d.ts +43 -0
- package/dist/glue/manifest.js +106 -0
- package/dist/glue/ports.d.ts +60 -0
- package/dist/glue/ports.js +2 -0
- package/dist/host/activation.d.ts +118 -0
- package/dist/host/activation.js +104 -0
- package/dist/host/attach-loaded-plugin.d.ts +37 -0
- package/dist/host/attach-loaded-plugin.js +19 -0
- package/dist/host/capability-sdk.d.ts +74 -0
- package/dist/host/capability-sdk.js +94 -0
- package/dist/host/claim-conflicts.d.ts +101 -0
- package/dist/host/claim-conflicts.js +139 -0
- package/dist/host/contributions.d.ts +129 -0
- package/dist/host/contributions.js +167 -0
- package/dist/host/declarative-enable.d.ts +43 -0
- package/dist/host/declarative-enable.js +73 -0
- package/dist/host/discovery-types.d.ts +55 -0
- package/dist/host/discovery-types.js +2 -0
- package/dist/host/errors.d.ts +20 -0
- package/dist/host/errors.js +22 -0
- package/dist/host/hook-registry.d.ts +113 -0
- package/dist/host/hook-registry.js +190 -0
- package/dist/host/index.d.ts +19 -0
- package/dist/host/index.js +19 -0
- package/dist/host/manifest.d.ts +159 -0
- package/dist/host/manifest.js +417 -0
- package/dist/host/node/discovery.d.ts +32 -0
- package/dist/host/node/discovery.js +241 -0
- package/dist/host/node/index.d.ts +8 -0
- package/dist/host/node/index.js +8 -0
- package/dist/host/node/install.d.ts +118 -0
- package/dist/host/node/install.js +431 -0
- package/dist/host/node/loader.d.ts +55 -0
- package/dist/host/node/loader.js +146 -0
- package/dist/host/node/module-snapshot.d.ts +25 -0
- package/dist/host/node/module-snapshot.js +53 -0
- package/dist/host/node/package-files.d.ts +52 -0
- package/dist/host/node/package-files.js +214 -0
- package/dist/host/node/source-drafts.d.ts +98 -0
- package/dist/host/node/source-drafts.js +323 -0
- package/dist/host/plugin-claims.d.ts +75 -0
- package/dist/host/plugin-claims.js +182 -0
- package/dist/host/ports.d.ts +208 -0
- package/dist/host/ports.js +2 -0
- package/dist/host/quarantine.d.ts +19 -0
- package/dist/host/quarantine.js +28 -0
- package/dist/host/repo.memory.d.ts +27 -0
- package/dist/host/repo.memory.js +33 -0
- package/dist/host/source-policy.d.ts +18 -0
- package/dist/host/source-policy.js +13 -0
- package/dist/host/sql/index.d.ts +4 -0
- package/dist/host/sql/index.js +4 -0
- package/dist/host/sql/repo.d.ts +38 -0
- package/dist/host/sql/repo.js +50 -0
- package/dist/host/sql/repo.rows.d.ts +28 -0
- package/dist/host/sql/repo.rows.js +28 -0
- package/dist/host/tool-contributions.d.ts +26 -0
- package/dist/host/tool-contributions.js +42 -0
- package/dist/host/uninstall.d.ts +88 -0
- package/dist/host/uninstall.js +112 -0
- package/dist/host/worker/import-seam.d.ts +45 -0
- package/dist/host/worker/import-seam.js +52 -0
- package/dist/host/worker/index.d.ts +5 -0
- package/dist/host/worker/index.js +5 -0
- package/dist/host/worker/protocol.d.ts +62 -0
- package/dist/host/worker/protocol.js +31 -0
- package/dist/host/worker/run-call.d.ts +27 -0
- package/dist/host/worker/run-call.js +76 -0
- package/package.json +107 -3
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file `resolveClaimConflicts()` — product-neutral detection of two extensions claiming the same
|
|
3
|
+
* named thing (a route, a tool name, a table, a setting id, a widget id, a permission id, an
|
|
4
|
+
* exclusive hook).
|
|
5
|
+
*
|
|
6
|
+
* JINI CANDIDATE: nothing in this file knows about Tovu, its manifest, its plugins or its storage —
|
|
7
|
+
* it takes owners and their claims as plain data and returns who keeps what. It belongs in
|
|
8
|
+
* `@jini-ai/plugins` (or `@jini-ai/core`) beside the glue capability gates. Not moved yet because
|
|
9
|
+
* Tovu's deploy build resolves `@jini-ai/*` from the published registry, so a Jini-side copy would be
|
|
10
|
+
* unreachable from production until the owner publishes; moving it is a file move plus one import.
|
|
11
|
+
*
|
|
12
|
+
* ## The rules (also in `ADS-memory/specs/005-plugin-system/conflicts.spec.md`)
|
|
13
|
+
*
|
|
14
|
+
* 1. Owners are processed in PRECEDENCE order — the caller's order, first wins. Core goes first;
|
|
15
|
+
* after that the caller decides (Tovu: earliest-enabled first, so the NEWER plugin is the one
|
|
16
|
+
* refused — the plugin that was already working keeps working).
|
|
17
|
+
* 2. A claim is `exclusive` (only one owner may hold it) or `shared` (any number of owners may hold
|
|
18
|
+
* it together — a filter pipeline hook where every filter runs in a fixed order is the example).
|
|
19
|
+
* An exclusive claim conflicts with ANY other owner's claim on the same slot, shared or not; two
|
|
20
|
+
* shared claims never conflict.
|
|
21
|
+
* 3. A REFUSED owner contributes nothing: if A holds `x`, B is refused for `x`, and C claims B's
|
|
22
|
+
* other key `y`, C is accepted. Refusal is all-or-nothing per owner — half a plugin is not a
|
|
23
|
+
* state anyone can reason about, so an owner with any conflict keeps none of its claims.
|
|
24
|
+
* 4. One owner claiming the same slot twice is not a conflict (a manifest repeating itself is a
|
|
25
|
+
* validation concern, not a collision between two parties).
|
|
26
|
+
* 5. Keys are compared after the kind's normalization (see {@link DEFAULT_CLAIM_KIND_RULES}):
|
|
27
|
+
* identifiers are case-insensitive; a route is `METHOD /path` with parameter names erased
|
|
28
|
+
* (`/a/:id` and `/a/{slug}` are the same route) and `*`/`ANY` meaning every method.
|
|
29
|
+
* 6. A key ending in `*` is a PREFIX claim: it holds every key that starts with what precedes the
|
|
30
|
+
* `*`. Core uses this to reserve whole namespaces (`/api/*`, `admin.*`) without listing every
|
|
31
|
+
* name in them; an exact claim inside a held prefix conflicts, and so does a prefix claim that
|
|
32
|
+
* covers a held exact key or overlaps a held prefix.
|
|
33
|
+
*
|
|
34
|
+
* Pure: no I/O, no clock, no mutation of its input.
|
|
35
|
+
*/
|
|
36
|
+
/** Whether a claim may be held by several owners at once (see rule 2). */
|
|
37
|
+
export type ClaimMode = "exclusive" | "shared";
|
|
38
|
+
/** One named thing an owner says it provides. `kind` is free text so a host can add kinds without
|
|
39
|
+
* touching this module; {@link DEFAULT_CLAIM_KIND_RULES} only supplies normalization for the
|
|
40
|
+
* common ones. */
|
|
41
|
+
export interface ExtensionClaim {
|
|
42
|
+
readonly kind: string;
|
|
43
|
+
readonly key: string;
|
|
44
|
+
readonly mode: ClaimMode;
|
|
45
|
+
}
|
|
46
|
+
/** One party taking part in conflict resolution — core, a plugin, a module. */
|
|
47
|
+
export interface ClaimOwner {
|
|
48
|
+
readonly id: string;
|
|
49
|
+
readonly claims: readonly ExtensionClaim[];
|
|
50
|
+
}
|
|
51
|
+
/** One refused claim: `ownerId` wanted `kind`/`key`, `heldBy` already had it (`heldKey` is the
|
|
52
|
+
* holder's own spelling — it differs from `key` when a prefix or a normalized route matched). */
|
|
53
|
+
export interface ClaimConflict {
|
|
54
|
+
readonly ownerId: string;
|
|
55
|
+
readonly kind: string;
|
|
56
|
+
readonly key: string;
|
|
57
|
+
readonly heldBy: string;
|
|
58
|
+
readonly heldKey: string;
|
|
59
|
+
}
|
|
60
|
+
/** How one kind's keys are compared: `normalize` turns a key into the slot strings it occupies.
|
|
61
|
+
* Most kinds occupy one slot; a route claimed for every method occupies one per method. */
|
|
62
|
+
export interface ClaimKindRule {
|
|
63
|
+
readonly normalize: (key: string) => readonly string[];
|
|
64
|
+
}
|
|
65
|
+
export interface ResolveClaimConflictsRequired {
|
|
66
|
+
/** Every owner, in precedence order — the first owner to claim a slot keeps it. */
|
|
67
|
+
readonly owners: readonly ClaimOwner[];
|
|
68
|
+
}
|
|
69
|
+
export interface ResolveClaimConflictsOptional {
|
|
70
|
+
/** Per-kind normalization; a kind with no rule uses {@link normalizeIdentifier}. Defaults to
|
|
71
|
+
* {@link DEFAULT_CLAIM_KIND_RULES}. */
|
|
72
|
+
readonly rules?: Readonly<Record<string, ClaimKindRule>>;
|
|
73
|
+
}
|
|
74
|
+
export interface ResolveClaimConflictsResult {
|
|
75
|
+
/** Owner ids that keep all their claims, in precedence order. */
|
|
76
|
+
readonly accepted: readonly string[];
|
|
77
|
+
/** Owner id -> every conflict that refused it (at least one per entry). */
|
|
78
|
+
readonly refused: ReadonlyMap<string, readonly ClaimConflict[]>;
|
|
79
|
+
}
|
|
80
|
+
/** Trimmed, lower-cased — tool names, table names, setting/widget/permission ids. SQLite table
|
|
81
|
+
* names are case-insensitive and the rest are human-typed ids where `Foo` and `foo` side by side
|
|
82
|
+
* would only ever be a mistake, so case never distinguishes two claims. */
|
|
83
|
+
export declare function normalizeIdentifier({ key }: {
|
|
84
|
+
key: string;
|
|
85
|
+
}, _optional?: Record<string, never>): readonly string[];
|
|
86
|
+
/** `"GET /a/:id"` -> `["GET /a/:"]`; `"/a"` or `"* /a"` or `"ANY /a"` -> one slot per method. */
|
|
87
|
+
export declare function normalizeRoute({ key }: {
|
|
88
|
+
key: string;
|
|
89
|
+
}, _optional?: Record<string, never>): readonly string[];
|
|
90
|
+
/** The kinds Tovu (and most hosts) need. A host adds or overrides kinds by spreading this. */
|
|
91
|
+
export declare const DEFAULT_CLAIM_KIND_RULES: Readonly<Record<string, ClaimKindRule>>;
|
|
92
|
+
/**
|
|
93
|
+
* Decides, owner by owner in precedence order, who keeps their claims (see this file's header for
|
|
94
|
+
* the six rules).
|
|
95
|
+
*
|
|
96
|
+
* @complexity O(S²) in the total slot count across all owners — a site has tens of plugins with a
|
|
97
|
+
* handful of claims each, so a linear scan of held slots beats an index that prefix claims would
|
|
98
|
+
* make complicated.
|
|
99
|
+
*/
|
|
100
|
+
export declare function resolveClaimConflicts(required: ResolveClaimConflictsRequired, optional?: ResolveClaimConflictsOptional): ResolveClaimConflictsResult;
|
|
101
|
+
//# sourceMappingURL=claim-conflicts.d.ts.map
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file `resolveClaimConflicts()` — product-neutral detection of two extensions claiming the same
|
|
3
|
+
* named thing (a route, a tool name, a table, a setting id, a widget id, a permission id, an
|
|
4
|
+
* exclusive hook).
|
|
5
|
+
*
|
|
6
|
+
* JINI CANDIDATE: nothing in this file knows about Tovu, its manifest, its plugins or its storage —
|
|
7
|
+
* it takes owners and their claims as plain data and returns who keeps what. It belongs in
|
|
8
|
+
* `@jini-ai/plugins` (or `@jini-ai/core`) beside the glue capability gates. Not moved yet because
|
|
9
|
+
* Tovu's deploy build resolves `@jini-ai/*` from the published registry, so a Jini-side copy would be
|
|
10
|
+
* unreachable from production until the owner publishes; moving it is a file move plus one import.
|
|
11
|
+
*
|
|
12
|
+
* ## The rules (also in `ADS-memory/specs/005-plugin-system/conflicts.spec.md`)
|
|
13
|
+
*
|
|
14
|
+
* 1. Owners are processed in PRECEDENCE order — the caller's order, first wins. Core goes first;
|
|
15
|
+
* after that the caller decides (Tovu: earliest-enabled first, so the NEWER plugin is the one
|
|
16
|
+
* refused — the plugin that was already working keeps working).
|
|
17
|
+
* 2. A claim is `exclusive` (only one owner may hold it) or `shared` (any number of owners may hold
|
|
18
|
+
* it together — a filter pipeline hook where every filter runs in a fixed order is the example).
|
|
19
|
+
* An exclusive claim conflicts with ANY other owner's claim on the same slot, shared or not; two
|
|
20
|
+
* shared claims never conflict.
|
|
21
|
+
* 3. A REFUSED owner contributes nothing: if A holds `x`, B is refused for `x`, and C claims B's
|
|
22
|
+
* other key `y`, C is accepted. Refusal is all-or-nothing per owner — half a plugin is not a
|
|
23
|
+
* state anyone can reason about, so an owner with any conflict keeps none of its claims.
|
|
24
|
+
* 4. One owner claiming the same slot twice is not a conflict (a manifest repeating itself is a
|
|
25
|
+
* validation concern, not a collision between two parties).
|
|
26
|
+
* 5. Keys are compared after the kind's normalization (see {@link DEFAULT_CLAIM_KIND_RULES}):
|
|
27
|
+
* identifiers are case-insensitive; a route is `METHOD /path` with parameter names erased
|
|
28
|
+
* (`/a/:id` and `/a/{slug}` are the same route) and `*`/`ANY` meaning every method.
|
|
29
|
+
* 6. A key ending in `*` is a PREFIX claim: it holds every key that starts with what precedes the
|
|
30
|
+
* `*`. Core uses this to reserve whole namespaces (`/api/*`, `admin.*`) without listing every
|
|
31
|
+
* name in them; an exact claim inside a held prefix conflicts, and so does a prefix claim that
|
|
32
|
+
* covers a held exact key or overlaps a held prefix.
|
|
33
|
+
*
|
|
34
|
+
* Pure: no I/O, no clock, no mutation of its input.
|
|
35
|
+
*/
|
|
36
|
+
const HTTP_METHODS = ["GET", "HEAD", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"];
|
|
37
|
+
const PREFIX_MARKER = "*";
|
|
38
|
+
/** Trimmed, lower-cased — tool names, table names, setting/widget/permission ids. SQLite table
|
|
39
|
+
* names are case-insensitive and the rest are human-typed ids where `Foo` and `foo` side by side
|
|
40
|
+
* would only ever be a mistake, so case never distinguishes two claims. */
|
|
41
|
+
export function normalizeIdentifier({ key }, _optional = {}) {
|
|
42
|
+
return [key.trim().toLowerCase()];
|
|
43
|
+
}
|
|
44
|
+
/** One path: lower-cased, slashes collapsed, trailing slash dropped, every parameter segment
|
|
45
|
+
* (`:id`, `{id}`, `[id]`) erased to `:` so two routes that differ only by parameter NAME — which
|
|
46
|
+
* a router cannot tell apart — compare equal. A trailing `*` survives as the prefix marker. */
|
|
47
|
+
function normalizePath(path) {
|
|
48
|
+
const segments = path
|
|
49
|
+
.trim()
|
|
50
|
+
.toLowerCase()
|
|
51
|
+
.split("/")
|
|
52
|
+
.filter((segment) => segment.length > 0)
|
|
53
|
+
.map((segment) => (/^(:.+|\{.+\}|\[.+\])$/.test(segment) ? ":" : segment));
|
|
54
|
+
return `/${segments.join("/")}`;
|
|
55
|
+
}
|
|
56
|
+
/** `"GET /a/:id"` -> `["GET /a/:"]`; `"/a"` or `"* /a"` or `"ANY /a"` -> one slot per method. */
|
|
57
|
+
export function normalizeRoute({ key }, _optional = {}) {
|
|
58
|
+
const trimmed = key.trim();
|
|
59
|
+
const space = trimmed.indexOf(" ");
|
|
60
|
+
const method = space === -1 ? "*" : trimmed.slice(0, space).toUpperCase();
|
|
61
|
+
const path = normalizePath(space === -1 ? trimmed : trimmed.slice(space + 1));
|
|
62
|
+
const methods = method === "*" || method === "ANY" ? HTTP_METHODS : [method];
|
|
63
|
+
return methods.map((each) => `${each} ${path}`);
|
|
64
|
+
}
|
|
65
|
+
/** The kinds Tovu (and most hosts) need. A host adds or overrides kinds by spreading this. */
|
|
66
|
+
export const DEFAULT_CLAIM_KIND_RULES = {
|
|
67
|
+
route: { normalize: (key) => normalizeRoute({ key }) },
|
|
68
|
+
};
|
|
69
|
+
function isPrefix(slot) {
|
|
70
|
+
return slot.endsWith(PREFIX_MARKER);
|
|
71
|
+
}
|
|
72
|
+
/** Whether two normalized slots of the same kind name overlapping things (rule 6). */
|
|
73
|
+
function slotsOverlap(a, b) {
|
|
74
|
+
if (a === b)
|
|
75
|
+
return true;
|
|
76
|
+
const aStem = isPrefix(a) ? a.slice(0, -1) : undefined;
|
|
77
|
+
const bStem = isPrefix(b) ? b.slice(0, -1) : undefined;
|
|
78
|
+
if (aStem !== undefined && b.startsWith(aStem))
|
|
79
|
+
return true;
|
|
80
|
+
if (bStem !== undefined && a.startsWith(bStem))
|
|
81
|
+
return true;
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
function slotsFor(claim, rules) {
|
|
85
|
+
const rule = rules[claim.kind];
|
|
86
|
+
const slots = rule ? rule.normalize(claim.key) : normalizeIdentifier({ key: claim.key });
|
|
87
|
+
return slots.map((slot) => ({ claim, slot }));
|
|
88
|
+
}
|
|
89
|
+
/** The first already-held slot a pending slot collides with, if any (rule 2: shared+shared never
|
|
90
|
+
* collides; anything involving an exclusive claim does). */
|
|
91
|
+
function findHolder(held, ownerId, pending) {
|
|
92
|
+
return held.find((each) => each.ownerId !== ownerId &&
|
|
93
|
+
each.kind === pending.claim.kind &&
|
|
94
|
+
!(each.mode === "shared" && pending.claim.mode === "shared") &&
|
|
95
|
+
slotsOverlap(each.slot, pending.slot));
|
|
96
|
+
}
|
|
97
|
+
/** Every conflict one owner has against what is already held; one entry per distinct claim. */
|
|
98
|
+
function conflictsFor(held, owner, pending) {
|
|
99
|
+
const conflicts = [];
|
|
100
|
+
const reported = new Set();
|
|
101
|
+
for (const each of pending) {
|
|
102
|
+
if (reported.has(each.claim))
|
|
103
|
+
continue;
|
|
104
|
+
const holder = findHolder(held, owner.id, each);
|
|
105
|
+
if (!holder)
|
|
106
|
+
continue;
|
|
107
|
+
reported.add(each.claim);
|
|
108
|
+
conflicts.push({ ownerId: owner.id, kind: each.claim.kind, key: each.claim.key, heldBy: holder.ownerId, heldKey: holder.key });
|
|
109
|
+
}
|
|
110
|
+
return conflicts;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Decides, owner by owner in precedence order, who keeps their claims (see this file's header for
|
|
114
|
+
* the six rules).
|
|
115
|
+
*
|
|
116
|
+
* @complexity O(S²) in the total slot count across all owners — a site has tens of plugins with a
|
|
117
|
+
* handful of claims each, so a linear scan of held slots beats an index that prefix claims would
|
|
118
|
+
* make complicated.
|
|
119
|
+
*/
|
|
120
|
+
export function resolveClaimConflicts(required, optional = {}) {
|
|
121
|
+
const rules = optional.rules ?? DEFAULT_CLAIM_KIND_RULES;
|
|
122
|
+
const held = [];
|
|
123
|
+
const accepted = [];
|
|
124
|
+
const refused = new Map();
|
|
125
|
+
for (const owner of required.owners) {
|
|
126
|
+
const pending = owner.claims.flatMap((claim) => slotsFor(claim, rules));
|
|
127
|
+
const conflicts = conflictsFor(held, owner, pending);
|
|
128
|
+
if (conflicts.length > 0) {
|
|
129
|
+
refused.set(owner.id, conflicts);
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
for (const each of pending) {
|
|
133
|
+
held.push({ ownerId: owner.id, kind: each.claim.kind, key: each.claim.key, slot: each.slot, mode: each.claim.mode });
|
|
134
|
+
}
|
|
135
|
+
accepted.push(owner.id);
|
|
136
|
+
}
|
|
137
|
+
return { accepted, refused };
|
|
138
|
+
}
|
|
139
|
+
//# sourceMappingURL=claim-conflicts.js.map
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import type { PluginManifest } from './manifest.js';
|
|
2
|
+
import type { PluginSdk } from './ports.js';
|
|
3
|
+
export declare const PLUGIN_CONTRIBUTION_CAPABILITIES: readonly ["http.route.register", "tools.register", "render.contribute"];
|
|
4
|
+
export type PluginRouteAccess = 'public' | 'member' | 'admin';
|
|
5
|
+
export interface PluginAuthContext {
|
|
6
|
+
readonly access: PluginRouteAccess;
|
|
7
|
+
readonly principalId?: string;
|
|
8
|
+
readonly workspaceId: string;
|
|
9
|
+
}
|
|
10
|
+
export interface PluginInvocationContext {
|
|
11
|
+
readonly pluginId: string;
|
|
12
|
+
readonly auth: PluginAuthContext;
|
|
13
|
+
readonly sdk: PluginSdk;
|
|
14
|
+
readonly signal?: AbortSignal;
|
|
15
|
+
}
|
|
16
|
+
export interface PluginRouteInput extends PluginInvocationContext {
|
|
17
|
+
readonly body: unknown;
|
|
18
|
+
readonly params: Readonly<Record<string, string>>;
|
|
19
|
+
readonly query: Readonly<Record<string, unknown>>;
|
|
20
|
+
}
|
|
21
|
+
export interface PluginRouteResult {
|
|
22
|
+
readonly status?: number;
|
|
23
|
+
readonly body?: unknown;
|
|
24
|
+
}
|
|
25
|
+
export interface PluginRouteContribution {
|
|
26
|
+
readonly method: string;
|
|
27
|
+
readonly path: string;
|
|
28
|
+
readonly access: PluginRouteAccess;
|
|
29
|
+
readonly handler: (required: PluginRouteInput, optional?: Record<string, never>) => PluginRouteResult | void | Promise<PluginRouteResult | void>;
|
|
30
|
+
}
|
|
31
|
+
export interface PluginToolContribution {
|
|
32
|
+
readonly name: string;
|
|
33
|
+
readonly description: string;
|
|
34
|
+
readonly inputSchema: Readonly<Record<string, unknown>>;
|
|
35
|
+
readonly handler: (required: PluginInvocationContext & {
|
|
36
|
+
readonly input: unknown;
|
|
37
|
+
}, optional?: Record<string, never>) => unknown | Promise<unknown>;
|
|
38
|
+
}
|
|
39
|
+
export interface PluginWidgetContribution {
|
|
40
|
+
readonly name: string;
|
|
41
|
+
/** Public SSR only. Host sanitizes the bounded HTML before partial placement (ADR-025). */
|
|
42
|
+
readonly render: (required: PluginInvocationContext, optional?: Record<string, never>) => string | Promise<string>;
|
|
43
|
+
}
|
|
44
|
+
export type PluginContribution = {
|
|
45
|
+
readonly kind: 'route';
|
|
46
|
+
readonly value: PluginRouteContribution;
|
|
47
|
+
} | {
|
|
48
|
+
readonly kind: 'tool';
|
|
49
|
+
readonly value: PluginToolContribution;
|
|
50
|
+
} | {
|
|
51
|
+
readonly kind: 'widget';
|
|
52
|
+
readonly value: PluginWidgetContribution;
|
|
53
|
+
};
|
|
54
|
+
export interface PluginContributionsSnapshot {
|
|
55
|
+
readonly pluginId: string;
|
|
56
|
+
readonly sdk: PluginSdk;
|
|
57
|
+
readonly routes: readonly PluginRouteContribution[];
|
|
58
|
+
readonly tools: readonly PluginToolContribution[];
|
|
59
|
+
readonly widgets: readonly PluginWidgetContribution[];
|
|
60
|
+
}
|
|
61
|
+
/** The name used by both the claims gate and the assistant's real registry. */
|
|
62
|
+
export declare function pluginToolIdFor(required: {
|
|
63
|
+
pluginId: string;
|
|
64
|
+
name: string;
|
|
65
|
+
}, _optional?: Record<string, never>): string;
|
|
66
|
+
/** Relative route grammar intentionally excludes wildcard/regex routes: a handler cannot widen
|
|
67
|
+
* its declared claim or leave /api/p/<id>. Express owns parameter matching. */
|
|
68
|
+
export declare function validatePluginRoute(required: {
|
|
69
|
+
method: string;
|
|
70
|
+
path: string;
|
|
71
|
+
}, _optional?: Record<string, never>): void;
|
|
72
|
+
/** Bounded registration and detached snapshots; all runtime surfaces require a manifest claim.
|
|
73
|
+
* SDK capability checks remain in buildCapabilityScopedSdk; this owner checks declarations too. */
|
|
74
|
+
export declare function createPluginContributionCapture(required: {
|
|
75
|
+
manifest: PluginManifest;
|
|
76
|
+
}, optional?: {
|
|
77
|
+
maxContributions?: number;
|
|
78
|
+
}): {
|
|
79
|
+
routes: {
|
|
80
|
+
add(value: PluginRouteContribution, _optional?: Record<string, never>): void;
|
|
81
|
+
};
|
|
82
|
+
tools: {
|
|
83
|
+
add(value: PluginToolContribution, _optional?: Record<string, never>): void;
|
|
84
|
+
};
|
|
85
|
+
widgets: {
|
|
86
|
+
add(value: PluginWidgetContribution, _optional?: Record<string, never>): void;
|
|
87
|
+
};
|
|
88
|
+
seal({ sdk }: {
|
|
89
|
+
sdk: PluginSdk;
|
|
90
|
+
}, _optional?: Record<string, never>): PluginContributionsSnapshot;
|
|
91
|
+
};
|
|
92
|
+
export interface PluginContributionRegistry {
|
|
93
|
+
replace(required: {
|
|
94
|
+
contributions: PluginContributionsSnapshot;
|
|
95
|
+
}, optional?: Record<string, never>): void;
|
|
96
|
+
detach(required: {
|
|
97
|
+
pluginId: string;
|
|
98
|
+
}, optional?: Record<string, never>): void;
|
|
99
|
+
list(required: Record<string, never>, optional?: Record<string, never>): readonly PluginContributionsSnapshot[];
|
|
100
|
+
subscribe(required: {
|
|
101
|
+
onChanged: () => void;
|
|
102
|
+
}, optional?: Record<string, never>): () => void;
|
|
103
|
+
}
|
|
104
|
+
/** Reuses core's contribution owner and the existing conflict detector. Replacement and detach
|
|
105
|
+
* rebuild a small plugin collection atomically; readers always see complete generations. */
|
|
106
|
+
export declare function createPluginContributionRegistry(_required: Record<string, never>, _optional?: Record<string, never>): PluginContributionRegistry;
|
|
107
|
+
/** Resolves only named public fragments, isolating failures and bounding the awaited work.
|
|
108
|
+
* Validation is an injected host renderer port; plugins cannot substitute their own validator.
|
|
109
|
+
* TODO: client enhancement JS waits for an ADR-025 owner amendment. */
|
|
110
|
+
export declare function renderPluginWidgetFragments(required: {
|
|
111
|
+
registry: PluginContributionRegistry;
|
|
112
|
+
names: readonly string[];
|
|
113
|
+
workspaceId: string;
|
|
114
|
+
isEnabled: (required: {
|
|
115
|
+
pluginId: string;
|
|
116
|
+
}, optional?: Record<string, never>) => Promise<boolean>;
|
|
117
|
+
validateHtml: (required: {
|
|
118
|
+
html: string;
|
|
119
|
+
}, optional?: Record<string, never>) => string;
|
|
120
|
+
}, optional?: {
|
|
121
|
+
timeoutMs?: number;
|
|
122
|
+
maxNames?: number;
|
|
123
|
+
onError?: (required: {
|
|
124
|
+
pluginId: string;
|
|
125
|
+
widgetName: string;
|
|
126
|
+
error: unknown;
|
|
127
|
+
}, optional?: Record<string, never>) => void;
|
|
128
|
+
}): Promise<Readonly<Record<string, string>>>;
|
|
129
|
+
//# sourceMappingURL=contributions.d.ts.map
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
/** Executable contribution admission on the existing plugin loader, never a second loader.
|
|
2
|
+
* Captures stay private until setup succeeds. A sealed generation cannot register from a timer.
|
|
3
|
+
* Tier-3 currently runs with full in-process authority; TODO: hardened worker at this boundary. */
|
|
4
|
+
import { createContributionRegistry } from '@jini-ai/core/contribution-registry';
|
|
5
|
+
import { normalizeRoute, resolveClaimConflicts } from './claim-conflicts.js';
|
|
6
|
+
export const PLUGIN_CONTRIBUTION_CAPABILITIES = ['http.route.register', 'tools.register', 'render.contribute'];
|
|
7
|
+
/** The name used by both the claims gate and the assistant's real registry. */
|
|
8
|
+
export function pluginToolIdFor(required, _optional = {}) {
|
|
9
|
+
return `p_${required.pluginId.replace(/-/g, '_')}__${required.name}`;
|
|
10
|
+
}
|
|
11
|
+
/** Relative route grammar intentionally excludes wildcard/regex routes: a handler cannot widen
|
|
12
|
+
* its declared claim or leave /api/p/<id>. Express owns parameter matching. */
|
|
13
|
+
export function validatePluginRoute(required, _optional = {}) {
|
|
14
|
+
if (!/^(GET|HEAD|POST|PUT|PATCH|DELETE|OPTIONS)$/.test(required.method))
|
|
15
|
+
throw new Error('unsupported plugin route method');
|
|
16
|
+
if (!/^\/(?:[a-zA-Z0-9_-]+|:[a-zA-Z][a-zA-Z0-9_]*)(?:\/(?:[a-zA-Z0-9_-]+|:[a-zA-Z][a-zA-Z0-9_]*))*\/?$/.test(required.path) && required.path !== '/')
|
|
17
|
+
throw new Error('unsafe plugin route path');
|
|
18
|
+
}
|
|
19
|
+
/** Bounded registration and detached snapshots; all runtime surfaces require a manifest claim.
|
|
20
|
+
* SDK capability checks remain in buildCapabilityScopedSdk; this owner checks declarations too. */
|
|
21
|
+
export function createPluginContributionCapture(required, optional = {}) {
|
|
22
|
+
const { manifest } = required;
|
|
23
|
+
const routes = [], tools = [], widgets = [];
|
|
24
|
+
let sealed = false;
|
|
25
|
+
const limit = optional.maxContributions ?? 128;
|
|
26
|
+
if (!Number.isSafeInteger(limit) || limit < 1)
|
|
27
|
+
throw new RangeError('invalid contribution limit');
|
|
28
|
+
const check = () => {
|
|
29
|
+
if (sealed)
|
|
30
|
+
throw new Error('plugin contribution capture is sealed');
|
|
31
|
+
if (routes.length + tools.length + widgets.length >= limit)
|
|
32
|
+
throw new Error('plugin contribution limit reached');
|
|
33
|
+
// Worker proxy currently transports only beforeSave; accepting these there would lose them.
|
|
34
|
+
if (manifest.tier === 'tier-2')
|
|
35
|
+
throw new Error('worker contributions are not supported yet');
|
|
36
|
+
};
|
|
37
|
+
const named = (name, declarations) => {
|
|
38
|
+
if (!/^[a-z][a-z0-9_-]{0,63}$/.test(name) || !declarations?.includes(name))
|
|
39
|
+
throw new Error(`undeclared plugin contribution '${name}'`);
|
|
40
|
+
};
|
|
41
|
+
const capture = {
|
|
42
|
+
routes: { add(value, _optional = {}) {
|
|
43
|
+
check();
|
|
44
|
+
validatePluginRoute(value);
|
|
45
|
+
if (!['public', 'member', 'admin'].includes(value.access))
|
|
46
|
+
throw new Error('invalid plugin route access');
|
|
47
|
+
if (typeof value.handler !== 'function')
|
|
48
|
+
throw new Error('plugin route handler is required');
|
|
49
|
+
const slot = normalizeRoute({ key: `${value.method} ${value.path}` })[0];
|
|
50
|
+
if (!manifest.contributes?.routes?.some(key => normalizeRoute({ key }).includes(slot)))
|
|
51
|
+
throw new Error(`undeclared plugin route '${slot}'`);
|
|
52
|
+
if (routes.some(route => normalizeRoute({ key: `${route.method} ${route.path}` }).includes(slot)))
|
|
53
|
+
throw new Error('duplicate plugin route');
|
|
54
|
+
routes.push(Object.freeze({ ...value }));
|
|
55
|
+
} },
|
|
56
|
+
tools: { add(value, _optional = {}) {
|
|
57
|
+
check();
|
|
58
|
+
named(value.name, manifest.contributes?.tools);
|
|
59
|
+
if (tools.some(tool => tool.name === value.name))
|
|
60
|
+
throw new Error('duplicate plugin tool');
|
|
61
|
+
if (typeof value.handler !== 'function' || typeof value.description !== 'string' || !value.description.trim() || value.description.length > 8000)
|
|
62
|
+
throw new Error('plugin tool handler and description are required');
|
|
63
|
+
const schema = value.inputSchema;
|
|
64
|
+
if (!schema || typeof schema !== 'object' || Array.isArray(schema) || schema.type !== 'object')
|
|
65
|
+
throw new Error('plugin tool input schema must describe an object');
|
|
66
|
+
// Detach the JSON schema so later plugin mutations cannot alter the assistant contract.
|
|
67
|
+
const json = JSON.stringify(schema);
|
|
68
|
+
if (new TextEncoder().encode(json).byteLength > 65536)
|
|
69
|
+
throw new Error('plugin tool schema is too large');
|
|
70
|
+
tools.push(Object.freeze({ ...value, inputSchema: JSON.parse(json) }));
|
|
71
|
+
} },
|
|
72
|
+
widgets: { add(value, _optional = {}) {
|
|
73
|
+
check();
|
|
74
|
+
named(value.name, manifest.contributes?.widgets);
|
|
75
|
+
if (typeof value.render !== 'function' || widgets.some(widget => widget.name === value.name))
|
|
76
|
+
throw new Error('invalid or duplicate plugin widget');
|
|
77
|
+
widgets.push(Object.freeze({ ...value }));
|
|
78
|
+
} },
|
|
79
|
+
seal({ sdk }, _optional = {}) {
|
|
80
|
+
sealed = true;
|
|
81
|
+
return Object.freeze({ pluginId: manifest.id, sdk, routes: Object.freeze([...routes]), tools: Object.freeze([...tools]), widgets: Object.freeze([...widgets]) });
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
return capture;
|
|
85
|
+
}
|
|
86
|
+
/** Reuses core's contribution owner and the existing conflict detector. Replacement and detach
|
|
87
|
+
* rebuild a small plugin collection atomically; readers always see complete generations. */
|
|
88
|
+
export function createPluginContributionRegistry(_required, _optional = {}) {
|
|
89
|
+
const registry = createContributionRegistry({ keyOf: ({ contribution }) => contribution.pluginId });
|
|
90
|
+
const listeners = new Set();
|
|
91
|
+
const notify = () => { for (const listener of listeners)
|
|
92
|
+
listener(); };
|
|
93
|
+
return {
|
|
94
|
+
subscribe({ onChanged }) { listeners.add(onChanged); return () => { listeners.delete(onChanged); }; },
|
|
95
|
+
replace({ contributions }) {
|
|
96
|
+
const next = [...registry.list({}).filter(row => row.pluginId !== contributions.pluginId), contributions];
|
|
97
|
+
const owners = next.map(row => ({ id: row.pluginId, claims: [
|
|
98
|
+
...row.tools.map(tool => ({ kind: 'tool', key: pluginToolIdFor({ pluginId: row.pluginId, name: tool.name }), mode: 'exclusive' })),
|
|
99
|
+
...row.widgets.map(widget => ({ kind: 'widget', key: widget.name, mode: 'exclusive' })),
|
|
100
|
+
] }));
|
|
101
|
+
if (resolveClaimConflicts({ owners }).refused.size)
|
|
102
|
+
throw new Error('plugin contribution collision');
|
|
103
|
+
const previous = registry.list({});
|
|
104
|
+
registry.register({ contribution: contributions });
|
|
105
|
+
try {
|
|
106
|
+
notify();
|
|
107
|
+
}
|
|
108
|
+
catch (error) {
|
|
109
|
+
registry.clear({});
|
|
110
|
+
for (const contribution of previous)
|
|
111
|
+
registry.register({ contribution });
|
|
112
|
+
notify();
|
|
113
|
+
throw error;
|
|
114
|
+
}
|
|
115
|
+
},
|
|
116
|
+
detach({ pluginId }) {
|
|
117
|
+
const retained = registry.list({}).filter(row => row.pluginId !== pluginId);
|
|
118
|
+
registry.clear({});
|
|
119
|
+
for (const contribution of retained)
|
|
120
|
+
registry.register({ contribution });
|
|
121
|
+
notify();
|
|
122
|
+
},
|
|
123
|
+
list: (input) => registry.list(input),
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
/** Resolves only named public fragments, isolating failures and bounding the awaited work.
|
|
127
|
+
* Validation is an injected host renderer port; plugins cannot substitute their own validator.
|
|
128
|
+
* TODO: client enhancement JS waits for an ADR-025 owner amendment. */
|
|
129
|
+
export async function renderPluginWidgetFragments(required, optional = {}) {
|
|
130
|
+
const names = [...new Set(required.names)];
|
|
131
|
+
if (names.length > (optional.maxNames ?? 32))
|
|
132
|
+
throw new Error('too many plugin widget placements');
|
|
133
|
+
const timeoutMs = optional.timeoutMs ?? 2000;
|
|
134
|
+
if (!Number.isSafeInteger(timeoutMs) || timeoutMs < 1)
|
|
135
|
+
throw new RangeError('invalid widget timeout');
|
|
136
|
+
const fragments = Object.create(null);
|
|
137
|
+
for (const snapshot of required.registry.list({})) {
|
|
138
|
+
const selected = snapshot.widgets.filter(widget => names.includes(widget.name));
|
|
139
|
+
if (!selected.length)
|
|
140
|
+
continue;
|
|
141
|
+
if (!await required.isEnabled({ pluginId: snapshot.pluginId }))
|
|
142
|
+
continue;
|
|
143
|
+
await Promise.all(selected.map(async (widget) => {
|
|
144
|
+
let timer;
|
|
145
|
+
const controller = new AbortController();
|
|
146
|
+
try {
|
|
147
|
+
const html = await Promise.race([
|
|
148
|
+
Promise.resolve().then(() => widget.render({ pluginId: snapshot.pluginId, sdk: snapshot.sdk, auth: { access: 'public', workspaceId: required.workspaceId }, signal: controller.signal }, {})),
|
|
149
|
+
new Promise((_resolve, reject) => { timer = setTimeout(() => { controller.abort(); reject(new Error('widget timeout')); }, timeoutMs); }),
|
|
150
|
+
]);
|
|
151
|
+
if (typeof html !== 'string' || !required.registry.list({}).includes(snapshot) || !await required.isEnabled({ pluginId: snapshot.pluginId }))
|
|
152
|
+
return;
|
|
153
|
+
fragments[widget.name] = required.validateHtml({ html });
|
|
154
|
+
}
|
|
155
|
+
catch (error) {
|
|
156
|
+
(optional.onError ?? ((failure) => console.warn(`[plugins] Plugin '${failure.pluginId}' widget '${failure.widgetName}' failed`, failure.error)))({ pluginId: snapshot.pluginId, widgetName: widget.name, error }, {});
|
|
157
|
+
fragments[widget.name] = '';
|
|
158
|
+
}
|
|
159
|
+
finally {
|
|
160
|
+
if (timer !== undefined)
|
|
161
|
+
clearTimeout(timer);
|
|
162
|
+
}
|
|
163
|
+
}));
|
|
164
|
+
}
|
|
165
|
+
return fragments;
|
|
166
|
+
}
|
|
167
|
+
//# sourceMappingURL=contributions.js.map
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { DeclarativeContentTypesPort, DeclaredContentTypePorts } from "./ports.js";
|
|
2
|
+
import type { PluginManifest } from "./manifest.js";
|
|
3
|
+
export interface EnableDeclaredPluginRequired {
|
|
4
|
+
readonly declarativeContentTypes: DeclarativeContentTypesPort;
|
|
5
|
+
readonly pluginId: string;
|
|
6
|
+
readonly workspaceId: string;
|
|
7
|
+
/** The discovery record's manifest — already through `validateManifest`, declarations included. */
|
|
8
|
+
readonly manifest: PluginManifest;
|
|
9
|
+
/** Loads and attaches the plugin's code (the runtime's own load path). Never called for tier-1. */
|
|
10
|
+
readonly loadCode: () => Promise<void>;
|
|
11
|
+
/** Detaches what `loadCode` attached — called only when a content type fails to create after it. */
|
|
12
|
+
readonly unloadCode: () => void;
|
|
13
|
+
}
|
|
14
|
+
export interface EnableDeclaredPluginOptional {
|
|
15
|
+
/** Where declared content types are created. Omitted (a composition with no content-type store)
|
|
16
|
+
* ⇒ a plugin that declares any is refused rather than enabled without them. */
|
|
17
|
+
readonly contentTypes?: DeclaredContentTypePorts;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Turns one plugin on around its declarations. A plugin that declares no content types is just
|
|
21
|
+
* `loadCode()` (tier-1 with none: nothing at all). Content-type conflicts with what the site
|
|
22
|
+
* already has throw `PluginInvalidError` (the enable route maps it to 422; `setPluginEnabled`
|
|
23
|
+
* restores the prior activation row).
|
|
24
|
+
*
|
|
25
|
+
* @complexity O(t) port reads/writes over the manifest's declared types (bounded, ≤ 20).
|
|
26
|
+
*/
|
|
27
|
+
export declare function enableDeclaredPlugin(required: EnableDeclaredPluginRequired, optional?: EnableDeclaredPluginOptional): Promise<void>;
|
|
28
|
+
/**
|
|
29
|
+
* Binds the host's `registerContentType` for the provisioner. `authorize` always allows, on purpose: the
|
|
30
|
+
* real authorization already happened one layer up — turning a plugin on requires the plugin-manage
|
|
31
|
+
* permission and the owner's consent, and these types are what that consented action declares
|
|
32
|
+
* (the same reasoning as widgets' `PRE_AUTHORIZED`). The write is recorded as `principalKind:
|
|
33
|
+
* "system"` with the plugin as actor, so the revision log says no human typed this schema.
|
|
34
|
+
*/
|
|
35
|
+
/**
|
|
36
|
+
* Ports built on first use. Both composition roots compose the plugin runtime before their
|
|
37
|
+
* content-type repo and outbox exist (top-level composition is synchronous and enable never runs
|
|
38
|
+
* during it), so they hand the runtime this and bind the real ports where those are declared.
|
|
39
|
+
*/
|
|
40
|
+
export declare function deferDeclaredContentTypePorts(required: {
|
|
41
|
+
build: () => DeclaredContentTypePorts;
|
|
42
|
+
}, _optional?: Record<string, never>): DeclaredContentTypePorts;
|
|
43
|
+
//# sourceMappingURL=declarative-enable.d.ts.map
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/** Concrete content-type construction is host-owned. The required declaration port owns its
|
|
2
|
+
* grammar, planning and application; this module owns ordering and deferred binding. */
|
|
3
|
+
/**
|
|
4
|
+
* @file The enable path for a plugin's DECLARED contributions (AW-7 Tier 1): a `tier-1`
|
|
5
|
+
* (manifest-only) plugin is applied from its manifest and never imported, and a code plugin that
|
|
6
|
+
* also declares content types gets them.
|
|
7
|
+
*
|
|
8
|
+
* Runs inside `composePluginRuntime().onPluginEnabled` (`server/runtime/composition/plugin-runtime.ts`),
|
|
9
|
+
* AFTER its conflict gate, so a declared content-type key is checked against every other plugin's
|
|
10
|
+
* claims first (`plugin-claims.ts`, kind `content-type`). Boot re-attach skips tier-1 plugins: their
|
|
11
|
+
* types were stored when they were turned on, and there is no code to load.
|
|
12
|
+
*
|
|
13
|
+
* Order for a code plugin with content types: plan (read-only) → load code → create types. A
|
|
14
|
+
* conflict refuses the enable before the plugin's code is imported, and a failed load leaves no
|
|
15
|
+
* types behind. A type that still fails to create (everything core would refuse is already refused
|
|
16
|
+
* at discovery, so this is an infrastructure failure) unloads the code again, so a refused enable
|
|
17
|
+
* never leaves a hook running. Types created before that failure stay: retain-by-default, and
|
|
18
|
+
* tombstoning them would burn their keys for good (content-types INV-06); a later enable keeps them.
|
|
19
|
+
*/
|
|
20
|
+
import { PluginInvalidError } from "./activation.js";
|
|
21
|
+
/**
|
|
22
|
+
* Turns one plugin on around its declarations. A plugin that declares no content types is just
|
|
23
|
+
* `loadCode()` (tier-1 with none: nothing at all). Content-type conflicts with what the site
|
|
24
|
+
* already has throw `PluginInvalidError` (the enable route maps it to 422; `setPluginEnabled`
|
|
25
|
+
* restores the prior activation row).
|
|
26
|
+
*
|
|
27
|
+
* @complexity O(t) port reads/writes over the manifest's declared types (bounded, ≤ 20).
|
|
28
|
+
*/
|
|
29
|
+
export async function enableDeclaredPlugin(required, optional = {}) {
|
|
30
|
+
const { pluginId, workspaceId, manifest, loadCode } = required;
|
|
31
|
+
// ADR-024 §1: a Tier-1 plugin is zero executable code — the runtime never imports anything for it.
|
|
32
|
+
const load = manifest.tier === "tier-1" ? async () => { } : loadCode;
|
|
33
|
+
const { decls } = required.declarativeContentTypes.parse({ value: manifest.contentTypes });
|
|
34
|
+
if (decls.length === 0)
|
|
35
|
+
return load();
|
|
36
|
+
const ports = optional.contentTypes;
|
|
37
|
+
if (!ports)
|
|
38
|
+
throw new PluginInvalidError(`plugin '${pluginId}' declares content types, but this site cannot create them`);
|
|
39
|
+
const plan = await required.declarativeContentTypes.plan({ ports, workspaceId, decls });
|
|
40
|
+
if (plan.conflicts.length > 0) {
|
|
41
|
+
throw new PluginInvalidError(`plugin '${pluginId}' cannot be turned on: ${plan.conflicts.join("; ")}`);
|
|
42
|
+
}
|
|
43
|
+
await load();
|
|
44
|
+
try {
|
|
45
|
+
await required.declarativeContentTypes.apply({ ports, workspaceId, pluginId, plan });
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
required.unloadCode();
|
|
49
|
+
throw error;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Binds the host's `registerContentType` for the provisioner. `authorize` always allows, on purpose: the
|
|
54
|
+
* real authorization already happened one layer up — turning a plugin on requires the plugin-manage
|
|
55
|
+
* permission and the owner's consent, and these types are what that consented action declares
|
|
56
|
+
* (the same reasoning as widgets' `PRE_AUTHORIZED`). The write is recorded as `principalKind:
|
|
57
|
+
* "system"` with the plugin as actor, so the revision log says no human typed this schema.
|
|
58
|
+
*/
|
|
59
|
+
// createDeclaredContentTypePorts stays at the host composition boundary with the core write service.
|
|
60
|
+
/**
|
|
61
|
+
* Ports built on first use. Both composition roots compose the plugin runtime before their
|
|
62
|
+
* content-type repo and outbox exist (top-level composition is synchronous and enable never runs
|
|
63
|
+
* during it), so they hand the runtime this and bind the real ports where those are declared.
|
|
64
|
+
*/
|
|
65
|
+
export function deferDeclaredContentTypePorts(required, _optional = {}) {
|
|
66
|
+
let ports;
|
|
67
|
+
const resolve = () => (ports ??= required.build());
|
|
68
|
+
return {
|
|
69
|
+
findByKey: (params) => resolve().findByKey(params),
|
|
70
|
+
register: (input) => resolve().register(input),
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=declarative-enable.js.map
|