@jini-ai/plugins 0.4.0 → 0.4.2
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 +2 -0
- package/dist/glue/attachment-points/content-lifecycle.d.ts +47 -5
- package/dist/glue/attachment-points/content-lifecycle.js +10 -0
- package/dist/glue/capability-gate.d.ts +54 -1
- package/dist/glue/capability-gate.js +19 -1
- package/dist/host/capability-sdk.d.ts +2 -2
- package/dist/host/capability-sdk.js +45 -9
- package/dist/host/contributions.d.ts +129 -0
- package/dist/host/contributions.js +167 -0
- package/dist/host/discovery-types.d.ts +6 -3
- package/dist/host/index.d.ts +3 -0
- package/dist/host/index.js +3 -0
- package/dist/host/manifest.d.ts +10 -0
- package/dist/host/manifest.js +12 -2
- package/dist/host/node/discovery.d.ts +9 -2
- package/dist/host/node/discovery.js +30 -6
- package/dist/host/node/index.d.ts +1 -0
- package/dist/host/node/index.js +1 -0
- package/dist/host/node/install.d.ts +49 -4
- package/dist/host/node/install.js +207 -77
- package/dist/host/node/source-drafts.d.ts +104 -0
- package/dist/host/node/source-drafts.js +349 -0
- package/dist/host/plugin-claims.d.ts +0 -38
- package/dist/host/plugin-claims.js +50 -2
- package/dist/host/ports.d.ts +13 -1
- package/dist/host/source-policy.d.ts +38 -0
- package/dist/host/source-policy.js +42 -0
- package/dist/host/tool-contributions.d.ts +26 -0
- package/dist/host/tool-contributions.js +42 -0
- package/package.json +10 -5
package/CHANGELOG.md
CHANGED
|
@@ -9,6 +9,8 @@
|
|
|
9
9
|
|
|
10
10
|
## Unreleased
|
|
11
11
|
|
|
12
|
+
- Share publisher identity validation with core, retain the built-in incumbent on duplicate publisher IDs, and omit broken unrelated installed manifests from admission with warnings while preserving link refusals.
|
|
13
|
+
|
|
12
14
|
- Publish the plugin host runtime at universal `./host` and Node `./host/node`, `./host/worker`,
|
|
13
15
|
`./host/sql`; keep `./glue` unchanged. Require host SDK/catalog, declaration, tier, executable
|
|
14
16
|
import/digest, archive and storage-table ports; preserve package layout, diagnostics and states.
|
|
@@ -1,10 +1,52 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @file `attachGlueContentLifecycle()` — the content-lifecycle attachment point (SPEC-048 REQ-5;
|
|
3
|
+
* ADR-057 Decision 2's `content.entry.beforeSave` adapter row, Decision 2.1).
|
|
4
|
+
*
|
|
5
|
+
* Purpose:
|
|
6
|
+
* The wired adapter for the one category that stays **fail-closed, unchanged** (ADR-057 Decision 4
|
|
7
|
+
* — data-mutation call sites are never fail-isolated). This module owns none of that containment
|
|
8
|
+
* logic itself: it delegates straight to {@link GlueHostPort.attachContentLifecycleFilter}, whose
|
|
9
|
+
* real, host-specific implementation is expected to attach the given filter to a live
|
|
10
|
+
* `hook-registry.ts` instance via `Jini/packages/plugins/src/host/node/loader.ts`'s `attachLoadedPlugin()` — the shared
|
|
11
|
+
* extraction ADR-057 Decision 2.1 introduced, with the `"glue"` source. That composition (a real
|
|
12
|
+
* `HookRegistry` plus `attachLoadedPlugin`) is host-specific wiring and does not belong in this
|
|
13
|
+
* product-neutral module; see `__tests__/integration/content-lifecycle.integration.test.ts` for a
|
|
14
|
+
* worked example proving the two compose correctly end to end.
|
|
15
|
+
*
|
|
16
|
+
* Product-neutral core: depends only on `../ports` (the frozen `GlueHostPort` seam). No import of
|
|
17
|
+
* `plugin-runtime`, `hook-registry.ts`, or anything else host-specific — the fail-closed
|
|
18
|
+
* *mechanism* this category relies on lives entirely behind the port, not in this file.
|
|
19
|
+
*
|
|
20
|
+
* Architectural role:
|
|
21
|
+
* Implementation Outline slice 2 (ADR-057, Implementation Outline). Depends on slice 1's frozen
|
|
22
|
+
* `manifest.ts`/`ports.ts` contracts.
|
|
23
|
+
*/
|
|
24
|
+
import type { GlueContentLifecycleFilter, GlueFieldDecl } from "../ports.js";
|
|
25
|
+
export interface AttachGlueContentLifecycleRequired<Filter = GlueContentLifecycleFilter> {
|
|
3
26
|
readonly moduleId: string;
|
|
4
|
-
|
|
27
|
+
/** The glue module's already-obtained `content.entry.beforeSave` filter — how it was obtained
|
|
28
|
+
* (a `setup()` call gated by this module's own granted `GlueCapability` set) is the loader's
|
|
29
|
+
* concern, not this attachment point's. */
|
|
30
|
+
readonly filter: Filter;
|
|
5
31
|
readonly declaredFields: readonly GlueFieldDecl[];
|
|
6
|
-
readonly hostPort:
|
|
32
|
+
readonly hostPort: {
|
|
33
|
+
attachContentLifecycleFilter(required: {
|
|
34
|
+
moduleId: string;
|
|
35
|
+
filter: Filter;
|
|
36
|
+
declaredFields: readonly GlueFieldDecl[];
|
|
37
|
+
}): void;
|
|
38
|
+
};
|
|
7
39
|
}
|
|
8
40
|
export type AttachGlueContentLifecycleOptional = Record<string, never>;
|
|
9
|
-
|
|
41
|
+
/**
|
|
42
|
+
* Attaches one glue module's content-lifecycle filter via the host port. Pure delegation — this
|
|
43
|
+
* function adds no containment or validation of its own, matching ADR-057 Decision 4's explicit
|
|
44
|
+
* instruction that this category stays fail-closed and unchanged from `hook-registry.ts`'s existing
|
|
45
|
+
* discipline (a throw here is expected to propagate, not be caught).
|
|
46
|
+
*
|
|
47
|
+
* @throws Whatever `hostPort.attachContentLifecycleFilter()` itself throws — never caught here.
|
|
48
|
+
* @complexity O(1) — a single delegated call.
|
|
49
|
+
* @overallScore 100/100
|
|
50
|
+
*/
|
|
51
|
+
export declare function attachGlueContentLifecycle<Filter = GlueContentLifecycleFilter>(required: AttachGlueContentLifecycleRequired<Filter>, _optional?: AttachGlueContentLifecycleOptional): void;
|
|
10
52
|
//# sourceMappingURL=content-lifecycle.d.ts.map
|
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Attaches one glue module's content-lifecycle filter via the host port. Pure delegation — this
|
|
3
|
+
* function adds no containment or validation of its own, matching ADR-057 Decision 4's explicit
|
|
4
|
+
* instruction that this category stays fail-closed and unchanged from `hook-registry.ts`'s existing
|
|
5
|
+
* discipline (a throw here is expected to propagate, not be caught).
|
|
6
|
+
*
|
|
7
|
+
* @throws Whatever `hostPort.attachContentLifecycleFilter()` itself throws — never caught here.
|
|
8
|
+
* @complexity O(1) — a single delegated call.
|
|
9
|
+
* @overallScore 100/100
|
|
10
|
+
*/
|
|
1
11
|
export function attachGlueContentLifecycle(required, _optional = {}) {
|
|
2
12
|
const { moduleId, filter, declaredFields, hostPort } = required;
|
|
3
13
|
hostPort.attachContentLifecycleFilter({ moduleId, filter, declaredFields });
|
|
@@ -1,3 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file `buildGlueCapabilityGate()` — capability-scoped delegate handle for `GlueCapability`
|
|
3
|
+
* (SPEC-048 REQ-1/REQ-4; ADR-057 CIC-1, `ESCALATE_SECURITY`).
|
|
4
|
+
*
|
|
5
|
+
* Purpose:
|
|
6
|
+
* Extends the sibling plugin mechanism's own `gate()` pattern (always-present, granted-delegates,
|
|
7
|
+
* ungranted-throws) to the wider eight-member glue capability vocabulary. **Default-deny**: a
|
|
8
|
+
* capability absent from the granted set is never silently omitted from the returned handle — it
|
|
9
|
+
* is present as a callable stub that synchronously throws a classified `GlueCapabilityDeniedError`
|
|
10
|
+
* naming the missing capability. A bare `TypeError` on an absent property is exactly the wrong
|
|
11
|
+
* implementation this mirrors the sibling mechanism's own CIC in guarding against.
|
|
12
|
+
*
|
|
13
|
+
* **A module cannot grow its own capability set through this gate.** The granted set is a snapshot
|
|
14
|
+
* taken once, at build time, from a caller-supplied list — never read from anything the gated
|
|
15
|
+
* module itself holds a reference to or could write. The returned handle is frozen; there is no
|
|
16
|
+
* setter, no admin surface, and no code path from inside a delegate call back into the granted
|
|
17
|
+
* set. Widening what a module can do requires building a new gate from a re-approved manifest, not
|
|
18
|
+
* calling anything this module exports.
|
|
19
|
+
*
|
|
20
|
+
* Capabilities are exposed by handle only: every granted position is a plain closure the caller
|
|
21
|
+
* supplies (`coreDelegates`), never a raw filesystem, network, or process handle. This module has
|
|
22
|
+
* zero I/O of its own — it is pure wiring between "is this granted" and "which closure runs."
|
|
23
|
+
*
|
|
24
|
+
* Architectural role:
|
|
25
|
+
* Design-frozen contract for the extension-glue-tier work (ADR-057, Implementation Outline slice
|
|
26
|
+
* 1). Depends on `./manifest`'s `GlueCapability` type and `core/`'s shared capability vocabulary
|
|
27
|
+
* — no host-specific dependency.
|
|
28
|
+
*/
|
|
1
29
|
import type { GlueCapability } from './manifest.js';
|
|
2
30
|
export declare class GlueCapabilityDeniedError extends Error {
|
|
3
31
|
readonly moduleId: string;
|
|
@@ -7,14 +35,39 @@ export declare class GlueCapabilityDeniedError extends Error {
|
|
|
7
35
|
capability: GlueCapability;
|
|
8
36
|
}, _optional?: Record<string, never>);
|
|
9
37
|
}
|
|
38
|
+
/** Every capability position resolves to one of these once gated. Untyped args/return —
|
|
39
|
+
* each capability's real signature is owned by whichever attachment-point adapter backs it
|
|
40
|
+
* (later slices), never by this generic gate. */
|
|
10
41
|
export type GlueCapabilityDelegate = (required: Readonly<Record<string, unknown>>, optional?: Readonly<Record<string, unknown>>) => unknown;
|
|
11
42
|
export interface BuildGlueCapabilityGateRequired {
|
|
12
43
|
readonly moduleId: string;
|
|
44
|
+
/** The closed, eight-member vocabulary this gate always exposes a position for, regardless of
|
|
45
|
+
* grant set (CIC-1's "always present" property, made an iterable constant so the gate and its
|
|
46
|
+
* tests share one source of truth for "every position"). */
|
|
13
47
|
readonly vocabulary: readonly GlueCapability[];
|
|
48
|
+
/** The manifest's declared capability set (already validated against the v1 vocabulary by
|
|
49
|
+
* `validateGlueManifest()` — this function trusts its input is well-formed capability strings,
|
|
50
|
+
* same division of labor as the sibling mechanism's own capability-gate). */
|
|
14
51
|
readonly capabilities: readonly GlueCapability[];
|
|
52
|
+
/** The real backing implementation for every granted position, supplied by the caller (a later
|
|
53
|
+
* slice's loader, closing over that specific module load's host-port-backed state). This module
|
|
54
|
+
* never reaches into any host mechanism directly. */
|
|
15
55
|
readonly coreDelegates: Readonly<Record<GlueCapability, GlueCapabilityDelegate>>;
|
|
16
56
|
}
|
|
17
57
|
export type BuildGlueCapabilityGateOptional = Record<string, never>;
|
|
18
|
-
/**
|
|
58
|
+
/**
|
|
59
|
+
* Builds one glue module's capability-scoped delegate handle. Every one of the eight
|
|
60
|
+
* `GlueCapability` positions is always present on the returned object (CIC-1) — granted positions
|
|
61
|
+
* delegate to `coreDelegates`, ungranted positions are stubs that throw `GlueCapabilityDeniedError`
|
|
62
|
+
* when invoked (never at build time — the stub itself is a normal, present function; only calling
|
|
63
|
+
* it throws). The returned object is frozen: no caller, including the gated module itself, can add,
|
|
64
|
+
* remove, or replace a position after the gate is built.
|
|
65
|
+
*
|
|
66
|
+
* @throws Nothing at build time. The returned handle's ungranted-position stubs throw
|
|
67
|
+
* `GlueCapabilityDeniedError` synchronously when invoked.
|
|
68
|
+
* @complexity O(1) — eight capability checks, fixed-size regardless of the caller-supplied
|
|
69
|
+
* `capabilities` array's length.
|
|
70
|
+
* @overallScore 100/100
|
|
71
|
+
*/
|
|
19
72
|
export declare function buildGlueCapabilityGate(required: BuildGlueCapabilityGateRequired, _optional?: BuildGlueCapabilityGateOptional): Readonly<Record<GlueCapability, GlueCapabilityDelegate>>;
|
|
20
73
|
//# sourceMappingURL=capability-gate.d.ts.map
|
|
@@ -8,8 +8,26 @@ export class GlueCapabilityDeniedError extends Error {
|
|
|
8
8
|
this.capability = required.capability;
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
|
-
/**
|
|
11
|
+
/**
|
|
12
|
+
* Builds one glue module's capability-scoped delegate handle. Every one of the eight
|
|
13
|
+
* `GlueCapability` positions is always present on the returned object (CIC-1) — granted positions
|
|
14
|
+
* delegate to `coreDelegates`, ungranted positions are stubs that throw `GlueCapabilityDeniedError`
|
|
15
|
+
* when invoked (never at build time — the stub itself is a normal, present function; only calling
|
|
16
|
+
* it throws). The returned object is frozen: no caller, including the gated module itself, can add,
|
|
17
|
+
* remove, or replace a position after the gate is built.
|
|
18
|
+
*
|
|
19
|
+
* @throws Nothing at build time. The returned handle's ungranted-position stubs throw
|
|
20
|
+
* `GlueCapabilityDeniedError` synchronously when invoked.
|
|
21
|
+
* @complexity O(1) — eight capability checks, fixed-size regardless of the caller-supplied
|
|
22
|
+
* `capabilities` array's length.
|
|
23
|
+
* @overallScore 100/100
|
|
24
|
+
*/
|
|
25
|
+
// The caller supplies the vocabulary; the preserved CIC rationale describes Tovu's eight-slot host.
|
|
26
|
+
// Capability-specific arguments remain owned by the supplied attachment-point delegates.
|
|
12
27
|
export function buildGlueCapabilityGate(required, _optional = {}) {
|
|
28
|
+
// Defensive copy: a caller-side mutation of the `capabilities` array after this call must never
|
|
29
|
+
// change what this already-built gate grants (part of CIC-1's "cannot grow its own capability
|
|
30
|
+
// set" property — the snapshot is taken once, here, and never re-read).
|
|
13
31
|
const granted = new Set(required.capabilities);
|
|
14
32
|
const handle = Object.create(null);
|
|
15
33
|
for (const capability of required.vocabulary) {
|
|
@@ -49,6 +49,7 @@ export interface CapabilityScopedSdkCoreDeps {
|
|
|
49
49
|
writeExtField(field: string, value: string | number | boolean): void;
|
|
50
50
|
/** Backing implementation for the granted `addFilter()` surface. */
|
|
51
51
|
attachFilter(hookName: string, filter: BeforeSaveFilter): void;
|
|
52
|
+
readonly contributions?: Pick<PluginSdk, 'routes' | 'tools' | 'widgets'>;
|
|
52
53
|
}
|
|
53
54
|
export interface BuildCapabilityScopedSdkRequired<H extends HookPoints = HookPoints> {
|
|
54
55
|
readonly pluginSdkBinding: PluginSdkBinding<H>;
|
|
@@ -67,8 +68,7 @@ export type BuildCapabilityScopedSdkOptional = Record<string, never>;
|
|
|
67
68
|
*
|
|
68
69
|
* @throws Nothing at build time. The returned object's ungranted-surface stubs throw
|
|
69
70
|
* `CapabilityDeniedError` synchronously when invoked by the plugin.
|
|
70
|
-
* @complexity O(
|
|
71
|
-
* plugin-declared array length (the vocabulary itself is fixed-size at exactly three).
|
|
71
|
+
* @complexity O(capabilities.length) to build the granted set; every surface check is O(1).
|
|
72
72
|
*/
|
|
73
73
|
export declare function buildCapabilityScopedSdk<H extends HookPoints>(required: BuildCapabilityScopedSdkRequired<H>, _optional?: BuildCapabilityScopedSdkOptional): PluginSdk<H>;
|
|
74
74
|
//# sourceMappingURL=capability-sdk.d.ts.map
|
|
@@ -20,8 +20,7 @@ export class CapabilityDeniedError extends Error {
|
|
|
20
20
|
*
|
|
21
21
|
* @throws Nothing at build time. The returned object's ungranted-surface stubs throw
|
|
22
22
|
* `CapabilityDeniedError` synchronously when invoked by the plugin.
|
|
23
|
-
* @complexity O(
|
|
24
|
-
* plugin-declared array length (the vocabulary itself is fixed-size at exactly three).
|
|
23
|
+
* @complexity O(capabilities.length) to build the granted set; every surface check is O(1).
|
|
25
24
|
*/
|
|
26
25
|
export function buildCapabilityScopedSdk(required, _optional = {}) {
|
|
27
26
|
const { pluginId, capabilities, coreDeps } = required;
|
|
@@ -45,13 +44,50 @@ export function buildCapabilityScopedSdk(required, _optional = {}) {
|
|
|
45
44
|
extend: gate("content.extend", (field, value) => coreDeps.writeExtField(field, value)),
|
|
46
45
|
},
|
|
47
46
|
addFilter: gate("hooks.attach", (hookName, filter) => coreDeps.attachFilter(hookName, filter)),
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
47
|
+
routes: { add: gate("http.route.register", (input, options = {}) => {
|
|
48
|
+
if (!coreDeps.contributions)
|
|
49
|
+
throw new Error('plugin routes are not bound by this host');
|
|
50
|
+
coreDeps.contributions.routes.add(input, options);
|
|
51
|
+
}) },
|
|
52
|
+
tools: { add: gate("tools.register", (input, options = {}) => {
|
|
53
|
+
if (!coreDeps.contributions)
|
|
54
|
+
throw new Error('plugin tools are not bound by this host');
|
|
55
|
+
coreDeps.contributions.tools.add(input, options);
|
|
56
|
+
}) },
|
|
57
|
+
widgets: { add: gate("render.contribute", (input, options = {}) => {
|
|
58
|
+
if (!coreDeps.contributions)
|
|
59
|
+
throw new Error('plugin widgets are not bound by this host');
|
|
60
|
+
coreDeps.contributions.widgets.add(input, options);
|
|
61
|
+
}) },
|
|
62
|
+
// V1 rationale retained: `ActionHookName`/`ContributionHookName` (@tovu/sdk hooks.ts) have no
|
|
63
|
+
// catalog members yet (hooks v2 plan §3.3 Waves 1/2 land in a later slice), so no name
|
|
64
|
+
// type-checks as an argument to either legacy surface. They remain present-but-unreachable,
|
|
65
|
+
// following the same "always present" contract as addFilter, gated on hooks.attach. There
|
|
66
|
+
// is still no action-hook coreDeps backing until a hook is cataloged. Explicit contribution
|
|
67
|
+
// records below now have real route/tool/widget owners and use those owners' capabilities.
|
|
68
|
+
// No action hooks are cataloged. Preserve CIC U-003's callable denial boundary, but remove
|
|
69
|
+
// the silent no-op: a granted unsupported action fails explicitly until a real owner exists.
|
|
70
|
+
addAction: gate("hooks.attach", (..._args) => { throw new Error('no plugin action hooks are cataloged'); }),
|
|
71
|
+
addContribution: (input, options = {}) => {
|
|
72
|
+
// Legacy positional hook calls have no contribution hook in the catalog. Deny first for
|
|
73
|
+
// ungranted hooks, preserving the old SDK's classified security failure.
|
|
74
|
+
if (!input || typeof input !== 'object') {
|
|
75
|
+
gate("hooks.attach", () => { throw new Error('use an explicit route, tool or widget contribution'); })();
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
switch (input.kind) {
|
|
79
|
+
case 'route':
|
|
80
|
+
sdk.routes.add(input.value, options);
|
|
81
|
+
return;
|
|
82
|
+
case 'tool':
|
|
83
|
+
sdk.tools.add(input.value, options);
|
|
84
|
+
return;
|
|
85
|
+
case 'widget':
|
|
86
|
+
sdk.widgets.add(input.value, options);
|
|
87
|
+
return;
|
|
88
|
+
default: throw new Error('unsupported plugin contribution kind');
|
|
89
|
+
}
|
|
90
|
+
},
|
|
55
91
|
};
|
|
56
92
|
return required.pluginSdkBinding.buildSdk({ sdk });
|
|
57
93
|
}
|
|
@@ -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
|
|
@@ -9,6 +9,7 @@ export interface BuiltInPluginSource {
|
|
|
9
9
|
* once activation state is projected onto it by the caller (the HTTP route layer, C-016/C-017 —
|
|
10
10
|
* discovery itself does not know about `plugin_activations`). */
|
|
11
11
|
export interface PluginDiscoveryRecord {
|
|
12
|
+
readonly warnings?: readonly string[];
|
|
12
13
|
readonly id: string;
|
|
13
14
|
readonly name: string;
|
|
14
15
|
readonly version: string;
|
|
@@ -27,9 +28,11 @@ export interface PluginDiscoveryRecord {
|
|
|
27
28
|
readonly errors: readonly PluginValidationError[];
|
|
28
29
|
/**
|
|
29
30
|
* (Milestone 1b, 2026-08-20) The already-parsed, already-`validateManifest()`-checked manifest
|
|
30
|
-
* this record was built from — present
|
|
31
|
-
*
|
|
32
|
-
*
|
|
31
|
+
* this record was built from — present after manifest validation (`undefined` otherwise:
|
|
32
|
+
* an invalid/incompatible candidate's raw JSON may not conform to `PluginManifest`'s shape at
|
|
33
|
+
* all, so this field never claims a validated type for a manifest that failed validation).
|
|
34
|
+
* A later whole-set publisher collision omits the losing manifest and marks its record invalid.
|
|
35
|
+
* The incumbent keeps its reservation; the rejected claim must not reappear in host lookup.
|
|
33
36
|
*
|
|
34
37
|
* Exists so a composition root's enable path (`server/plugin-runtime.ts`'s `onPluginEnabled()`)
|
|
35
38
|
* can hand `loadPlugin()` the SAME manifest object this discovery pass already parsed, instead of
|
package/dist/host/index.d.ts
CHANGED
|
@@ -13,4 +13,7 @@ export * from './capability-sdk.js';
|
|
|
13
13
|
export * from './quarantine.js';
|
|
14
14
|
export * from './repo.memory.js';
|
|
15
15
|
export * from './uninstall.js';
|
|
16
|
+
export * from './source-policy.js';
|
|
17
|
+
export * from './contributions.js';
|
|
18
|
+
export * from './tool-contributions.js';
|
|
16
19
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/host/index.js
CHANGED
|
@@ -13,4 +13,7 @@ export * from './capability-sdk.js';
|
|
|
13
13
|
export * from './quarantine.js';
|
|
14
14
|
export * from './repo.memory.js';
|
|
15
15
|
export * from './uninstall.js';
|
|
16
|
+
export * from './source-policy.js';
|
|
17
|
+
export * from './contributions.js';
|
|
18
|
+
export * from './tool-contributions.js';
|
|
16
19
|
//# sourceMappingURL=index.js.map
|
package/dist/host/manifest.d.ts
CHANGED
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
* engine/tier, capabilities, hooks, fields) rather than stopping at the first, returning them in
|
|
25
25
|
* `errors[]` — it never throws. Verified against `__tests__/unit/manifest.unit.test.ts`.
|
|
26
26
|
*/
|
|
27
|
+
import { type PluginIdentityExtension } from "@jini-ai/core/plugin-directory";
|
|
27
28
|
import type { HookPoints, ManifestHostPorts } from "./ports.js";
|
|
28
29
|
/** ADR-024 §1 trust-tier vocabulary (1.1.1 REQ-01 fix). Literal encoding reused verbatim from the
|
|
29
30
|
* existing, approved SPEC-032/ADR-023 precedent (`DataModuleDecl.pluginTier`). */
|
|
@@ -57,7 +58,10 @@ export interface PluginManifestFieldDecl {
|
|
|
57
58
|
}
|
|
58
59
|
/** `tovu.plugin.json` — the ecosystem compatibility surface (state.spec.md §2, ADR-004). */
|
|
59
60
|
export interface PluginManifest {
|
|
61
|
+
/** Storage/activation key. Publisher identity lives in extensions[identityNamespace].id. */
|
|
60
62
|
readonly id: string;
|
|
63
|
+
readonly keywords?: readonly string[];
|
|
64
|
+
readonly extensions?: Readonly<Record<string, PluginIdentityExtension>>;
|
|
61
65
|
readonly name: string;
|
|
62
66
|
readonly version: string;
|
|
63
67
|
readonly sdkRange: string;
|
|
@@ -124,10 +128,16 @@ export interface ValidateManifestRequired<H extends HookPoints = HookPoints> ext
|
|
|
124
128
|
}
|
|
125
129
|
export type ValidateManifestOptional = Record<string, never>;
|
|
126
130
|
export interface ValidateManifestResult {
|
|
131
|
+
readonly warnings?: readonly string[];
|
|
127
132
|
/** Every applicable error, collected — NOT first-failure (BR-02). Empty when the manifest is
|
|
128
133
|
* statically valid (integrity/`sdkRange` are separate, load-pipeline-time checks, BR-01). */
|
|
129
134
|
readonly errors: readonly PluginValidationError[];
|
|
130
135
|
}
|
|
136
|
+
/** Shared id grammar for source paths and manifests. Identity admission (reserved ids, folder
|
|
137
|
+
* match and built-in shadowing) still belongs to full manifest validation. */
|
|
138
|
+
export declare function validatePluginIdFormat(required: {
|
|
139
|
+
id: string;
|
|
140
|
+
}, _optional?: Record<string, never>): readonly PluginValidationError[];
|
|
131
141
|
/** The owner id the claim system gives Tovu core (`plugin-claims.ts` re-exports it). Conflict
|
|
132
142
|
* detection never compares an owner with itself, so a plugin with this id would never conflict with
|
|
133
143
|
* core's reserved routes, tools or permissions — it is refused as an id instead. */
|