@jini-ai/plugins 0.7.2 → 0.7.3-next.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 +0 -6
- package/README.md +1 -1
- package/dist/core/manifest-keys.d.ts +8 -0
- package/dist/core/manifest-keys.js +16 -0
- package/dist/glue/attachment-points/content-lifecycle.d.ts +6 -7
- package/dist/glue/attachment-points/content-lifecycle.js +1 -1
- package/dist/glue/capability-gate.d.ts +2 -2
- package/dist/glue/manifest.js +2 -12
- package/dist/host/activation.d.ts +4 -5
- package/dist/host/admin-response.d.ts +2 -3
- package/dist/host/attach-loaded-plugin.d.ts +4 -4
- package/dist/host/attach-loaded-plugin.js +2 -2
- package/dist/host/browser-providers.d.ts +1 -1
- package/dist/host/capability-sdk.d.ts +8 -7
- package/dist/host/capability-sdk.js +39 -31
- package/dist/host/capability-tools.d.ts +3 -3
- package/dist/host/capability-tools.js +249 -237
- package/dist/host/contributions.d.ts +7 -66
- package/dist/host/contributions.js +64 -51
- package/dist/host/declarative-content-types.d.ts +6 -6
- package/dist/host/declarative-content-types.js +141 -135
- package/dist/host/declarative-enable.js +1 -1
- package/dist/host/discovery-types.d.ts +3 -3
- package/dist/host/hook-registry.d.ts +9 -9
- package/dist/host/hook-registry.js +86 -76
- package/dist/host/index.d.ts +1 -2
- package/dist/host/index.js +1 -1
- package/dist/host/manifest-types.d.ts +6 -59
- package/dist/host/manifest.d.ts +6 -5
- package/dist/host/manifest.js +3 -39
- package/dist/host/node/discovery.d.ts +1 -1
- package/dist/host/node/discovery.js +4 -5
- package/dist/host/node/index.d.ts +3 -0
- package/dist/host/node/index.js +2 -0
- package/dist/host/node/install.js +2 -2
- package/dist/host/node/integrity-command.d.ts +8 -0
- package/dist/host/node/integrity-command.js +26 -0
- package/dist/host/node/invocation-binding.d.ts +1 -1
- package/dist/host/node/invocation-binding.js +1 -1
- package/dist/host/node/loader.d.ts +3 -2
- package/dist/host/node/loader.js +12 -12
- package/dist/host/node/module-snapshot.d.ts +20 -0
- package/dist/host/node/module-snapshot.js +31 -0
- package/dist/host/node/open-flags.d.ts +4 -1
- package/dist/host/node/open-flags.js +1 -1
- package/dist/host/node/package-files.js +1 -1
- package/dist/host/node/provider-artifact.d.ts +1 -2
- package/dist/host/node/runtime-contracts.d.ts +237 -0
- package/dist/host/node/runtime-contracts.js +2 -0
- package/dist/host/node/runtime-core.d.ts +1 -243
- package/dist/host/node/runtime-core.js +18 -114
- package/dist/host/node/runtime-load-target.d.ts +44 -0
- package/dist/host/node/runtime-load-target.js +45 -0
- package/dist/host/node/runtime-package-location.d.ts +45 -0
- package/dist/host/node/runtime-package-location.js +57 -0
- package/dist/host/node/source-drafts.d.ts +4 -2
- package/dist/host/node/source-drafts.js +107 -39
- package/dist/host/ports.d.ts +1 -38
- package/dist/host/provider-contributions.d.ts +2 -14
- package/dist/host/provider-contributions.js +1 -1
- package/dist/host/provider-host.d.ts +4 -19
- package/dist/host/provider-host.js +83 -71
- package/dist/host/provider-revision-watch.d.ts +36 -0
- package/dist/host/provider-revision-watch.js +52 -0
- package/dist/host/provider-setting-required.d.ts +1 -7
- package/dist/host/provider-setting-required.js +1 -18
- package/dist/host/provider-settings-migrations.d.ts +1 -1
- package/dist/host/repo.memory.d.ts +1 -1
- package/dist/host/repo.memory.js +1 -1
- package/dist/host/sql/repo.d.ts +4 -3
- package/dist/host/sql/repo.rows.js +2 -2
- package/dist/host/tool-contributions.d.ts +2 -1
- package/dist/host/tool-contributions.js +1 -0
- package/dist/host/tools/install.js +1 -0
- package/dist/host/tools/management.js +97 -83
- package/dist/host/uninstall.d.ts +1 -1
- package/dist/host/worker/import-seam.d.ts +2 -2
- package/dist/host/worker/protocol.d.ts +2 -2
- package/dist/host/worker/run-call.d.ts +2 -1
- package/dist/host/worker/run-call.js +2 -2
- package/dist/host/worker/start.js +1 -1
- package/package.json +7 -17
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { describeErrorForLog } from '@jini-ai/core';
|
|
2
2
|
/** Executable contribution admission on the existing plugin loader, never a second loader.
|
|
3
3
|
* Captures stay private until setup succeeds. A sealed generation cannot register from a timer.
|
|
4
4
|
* Tier-3 currently runs with full in-process authority; a hardened worker at this boundary is
|
|
5
5
|
* still to come. */
|
|
6
|
-
import {
|
|
6
|
+
import { isPluginProviderDeclaration } from './provider-contributions.js';
|
|
7
|
+
import { PLUGIN_PROVIDER_CAPABILITY, } from '@jini-ai/core/contracts/plugin-sdk';
|
|
7
8
|
import { createContributionRegistry } from '@jini-ai/core/contribution-registry';
|
|
8
9
|
import { normalizeRoute, resolveClaimConflicts } from './claim-conflicts.js';
|
|
9
10
|
export const PLUGIN_CONTRIBUTION_CAPABILITIES = ['http.route.register', 'tools.register', 'render.contribute', PLUGIN_PROVIDER_CAPABILITY];
|
|
@@ -61,60 +62,72 @@ export function createPluginContributionCapture(required, optional = {}) {
|
|
|
61
62
|
if (manifest.tier === 'tier-2')
|
|
62
63
|
throw new Error('worker contributions are not supported yet');
|
|
63
64
|
};
|
|
64
|
-
const named = (name, declarations) => {
|
|
65
|
-
if (!/^[a-z][a-z0-9_-]{0,63}$/.test(name) || !declarations?.includes(name))
|
|
66
|
-
throw new Error(`undeclared plugin contribution '${name}'`);
|
|
67
|
-
};
|
|
68
65
|
return {
|
|
69
|
-
providers: {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
if (!manifest.contributes?.providers?.some(declaration => declaration.contract === value.contract && declaration.id === value.id && declaration.contractVersion === value.contractVersion))
|
|
74
|
-
throw new Error('undeclared plugin provider');
|
|
75
|
-
if (providers.some(provider => provider.contract === value.contract && provider.id === value.id))
|
|
76
|
-
throw new Error('duplicate plugin provider');
|
|
77
|
-
providers.push(Object.freeze({ contract: value.contract, id: value.id, contractVersion: value.contractVersion, factory: value.factory }));
|
|
78
|
-
} },
|
|
79
|
-
routes: { add(value, _optional = {}) {
|
|
80
|
-
check();
|
|
81
|
-
validatePluginRoute(value);
|
|
82
|
-
if (!['public', 'member', 'admin'].includes(value.access))
|
|
83
|
-
throw new Error('invalid plugin route access');
|
|
84
|
-
if (typeof value.handler !== 'function')
|
|
85
|
-
throw new Error('plugin route handler is required');
|
|
86
|
-
const slot = normalizeRoute({ key: `${value.method} ${value.path}` })[0];
|
|
87
|
-
if (!manifest.contributes?.routes?.some(key => normalizeRoute({ key }).includes(slot)))
|
|
88
|
-
throw new Error(`undeclared plugin route '${slot}'`);
|
|
89
|
-
if (routes.some(route => normalizeRoute({ key: `${route.method} ${route.path}` }).includes(slot)))
|
|
90
|
-
throw new Error('duplicate plugin route');
|
|
91
|
-
routes.push(Object.freeze({ ...value }));
|
|
92
|
-
} },
|
|
93
|
-
tools: { add(value, _optional = {}) {
|
|
94
|
-
check();
|
|
95
|
-
named(value.name, manifest.contributes?.tools);
|
|
96
|
-
if (tools.some(tool => tool.name === value.name))
|
|
97
|
-
throw new Error('duplicate plugin tool');
|
|
98
|
-
if (typeof value.handler !== 'function' || typeof value.description !== 'string' || !value.description.trim() || value.description.length > 8000)
|
|
99
|
-
throw new Error('plugin tool handler and description are required');
|
|
100
|
-
const json = serializePluginToolSchema({ schema: value.inputSchema });
|
|
101
|
-
const captured = { ...value };
|
|
102
|
-
const inputSchema = requireObjectSchema({ schema: JSON.parse(json) });
|
|
103
|
-
tools.push(Object.freeze({ ...captured, inputSchema }));
|
|
104
|
-
} },
|
|
105
|
-
widgets: { add(value, _optional = {}) {
|
|
106
|
-
check();
|
|
107
|
-
named(value.name, manifest.contributes?.widgets);
|
|
108
|
-
if (typeof value.render !== 'function' || widgets.some(widget => widget.name === value.name))
|
|
109
|
-
throw new Error('invalid or duplicate plugin widget');
|
|
110
|
-
widgets.push(Object.freeze({ ...value }));
|
|
111
|
-
} },
|
|
66
|
+
providers: capturedProvidersSurface({ manifest, providers }, check),
|
|
67
|
+
routes: capturedRoutesSurface({ manifest, routes }, check),
|
|
68
|
+
tools: capturedToolsSurface({ manifest, tools }, check),
|
|
69
|
+
widgets: capturedWidgetsSurface({ manifest, widgets }, check),
|
|
112
70
|
seal({ sdk }, _optional = {}) {
|
|
113
71
|
sealed = true;
|
|
114
72
|
return Object.freeze({ pluginId: manifest.id, sdk, routes: Object.freeze([...routes]), tools: Object.freeze([...tools]), widgets: Object.freeze([...widgets]), providers: Object.freeze([...providers]) });
|
|
115
73
|
},
|
|
116
74
|
};
|
|
117
75
|
}
|
|
76
|
+
function named(name, declarations) {
|
|
77
|
+
if (!/^[a-z][a-z0-9_-]{0,63}$/.test(name) || !declarations?.includes(name))
|
|
78
|
+
throw new Error(`undeclared plugin contribution '${name}'`);
|
|
79
|
+
}
|
|
80
|
+
function capturedProvidersSurface({ manifest, providers }, check) {
|
|
81
|
+
return { register(value, _optional = {}) {
|
|
82
|
+
check();
|
|
83
|
+
if (manifest.tier !== 'tier-3' || !isPluginProviderDeclaration({ value }) || typeof value.factory !== 'function')
|
|
84
|
+
throw new Error('invalid plugin provider factory');
|
|
85
|
+
if (!manifest.contributes?.providers?.some(declaration => declaration.contract === value.contract && declaration.id === value.id && declaration.contractVersion === value.contractVersion))
|
|
86
|
+
throw new Error('undeclared plugin provider');
|
|
87
|
+
if (providers.some(provider => provider.contract === value.contract && provider.id === value.id))
|
|
88
|
+
throw new Error('duplicate plugin provider');
|
|
89
|
+
providers.push(Object.freeze({ contract: value.contract, id: value.id, contractVersion: value.contractVersion, factory: value.factory }));
|
|
90
|
+
} };
|
|
91
|
+
}
|
|
92
|
+
function capturedRoutesSurface({ manifest, routes }, check) {
|
|
93
|
+
return { add(value, _optional = {}) {
|
|
94
|
+
check();
|
|
95
|
+
validatePluginRoute(value);
|
|
96
|
+
if (!['public', 'member', 'admin'].includes(value.access))
|
|
97
|
+
throw new Error('invalid plugin route access');
|
|
98
|
+
if (typeof value.handler !== 'function')
|
|
99
|
+
throw new Error('plugin route handler is required');
|
|
100
|
+
const slot = normalizeRoute({ key: `${value.method} ${value.path}` })[0];
|
|
101
|
+
if (!manifest.contributes?.routes?.some(key => normalizeRoute({ key }).includes(slot)))
|
|
102
|
+
throw new Error(`undeclared plugin route '${slot}'`);
|
|
103
|
+
if (routes.some(route => normalizeRoute({ key: `${route.method} ${route.path}` }).includes(slot)))
|
|
104
|
+
throw new Error('duplicate plugin route');
|
|
105
|
+
routes.push(Object.freeze({ ...value }));
|
|
106
|
+
} };
|
|
107
|
+
}
|
|
108
|
+
function capturedToolsSurface({ manifest, tools }, check) {
|
|
109
|
+
return { add(value, _optional = {}) {
|
|
110
|
+
check();
|
|
111
|
+
named(value.name, manifest.contributes?.tools);
|
|
112
|
+
if (tools.some(tool => tool.name === value.name))
|
|
113
|
+
throw new Error('duplicate plugin tool');
|
|
114
|
+
if (typeof value.handler !== 'function' || typeof value.description !== 'string' || !value.description.trim() || value.description.length > 8000)
|
|
115
|
+
throw new Error('plugin tool handler and description are required');
|
|
116
|
+
const json = serializePluginToolSchema({ schema: value.inputSchema });
|
|
117
|
+
const captured = { ...value };
|
|
118
|
+
const inputSchema = requireObjectSchema({ schema: JSON.parse(json) });
|
|
119
|
+
tools.push(Object.freeze({ ...captured, inputSchema }));
|
|
120
|
+
} };
|
|
121
|
+
}
|
|
122
|
+
function capturedWidgetsSurface({ manifest, widgets }, check) {
|
|
123
|
+
return { add(value, _optional = {}) {
|
|
124
|
+
check();
|
|
125
|
+
named(value.name, manifest.contributes?.widgets);
|
|
126
|
+
if (typeof value.render !== 'function' || widgets.some(widget => widget.name === value.name))
|
|
127
|
+
throw new Error('invalid or duplicate plugin widget');
|
|
128
|
+
widgets.push(Object.freeze({ ...value }));
|
|
129
|
+
} };
|
|
130
|
+
}
|
|
118
131
|
/** Reuses core's contribution owner and the existing conflict detector. Replacement and detach
|
|
119
132
|
* rebuild a small plugin collection atomically; readers always see complete generations. */
|
|
120
133
|
export function createPluginContributionRegistry(_required, _optional = {}) {
|
|
@@ -159,7 +172,7 @@ export function createPluginContributionRegistry(_required, _optional = {}) {
|
|
|
159
172
|
}
|
|
160
173
|
/** Resolves only named public fragments, isolating failures and bounding the awaited work.
|
|
161
174
|
* Validation is an injected host renderer port; plugins cannot substitute their own validator.
|
|
162
|
-
* Client enhancement JS is still pending: it waits for an
|
|
175
|
+
* Client enhancement JS is still pending: it waits for an owner amendment. */
|
|
163
176
|
export async function renderPluginWidgetFragments(required, optional = {}) {
|
|
164
177
|
const names = [...new Set(required.names)];
|
|
165
178
|
if (names.length > (optional.maxNames ?? 32))
|
|
@@ -185,7 +198,7 @@ export async function renderPluginWidgetFragments(required, optional = {}) {
|
|
|
185
198
|
fragments[widget.name] = required.validateHtml({ html });
|
|
186
199
|
}
|
|
187
200
|
catch (error) {
|
|
188
|
-
(optional.onError ?? (({ pluginId, widgetName, error: failureError }) => console.warn(`[plugins] Plugin '${pluginId}' widget '${widgetName}' failed`,
|
|
201
|
+
(optional.onError ?? (({ pluginId, widgetName, error: failureError }) => console.warn(`[plugins] Plugin '${pluginId}' widget '${widgetName}' failed`, describeErrorForLog({ err: failureError }))))({ pluginId: snapshot.pluginId, widgetName: widget.name, error }, {});
|
|
189
202
|
fragments[widget.name] = '';
|
|
190
203
|
}
|
|
191
204
|
finally {
|
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
* plan against what the site already has, and apply through the host's ONE content-type write path
|
|
4
4
|
* (behind {@link DeclaredContentTypeWritePorts}). AW-7 Tier 1, 2026-10-04.
|
|
5
5
|
*
|
|
6
|
-
* Why this exists:
|
|
6
|
+
* Why this exists: Tier-1 is defined as a manifest-only plugin whose first contribution is
|
|
7
7
|
* "content types & fields", but `manifest.ts` only ever parsed-and-stored `contentTypes` (state.spec
|
|
8
8
|
* §2: "UNUSED in v1"). This module is the missing half: a bounded, closed declaration grammar
|
|
9
|
-
* (
|
|
9
|
+
* (Tier-1 is only safe while its surface is non-Turing-complete and bounded) and an
|
|
10
10
|
* idempotent provisioner that runs at enable time.
|
|
11
11
|
*
|
|
12
12
|
* Rules the provisioner keeps (and why):
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
* refused before anything is written, rather than silently reshaping someone's content.
|
|
17
17
|
* - **A tombstoned type is skipped.** The owner deleted it on purpose; tombstone is terminal and the
|
|
18
18
|
* key can never be reused (content-types INV-06), so re-enabling the plugin does not resurrect it.
|
|
19
|
-
* - **Retain on disable/uninstall** (
|
|
19
|
+
* - **Retain on disable/uninstall** (retain-by-default): nothing here ever removes a
|
|
20
20
|
* type. The entries are the owner's content, not the plugin's.
|
|
21
21
|
*
|
|
22
22
|
* Pure parsing; the plan/apply halves do I/O only through the injected ports.
|
|
@@ -30,10 +30,10 @@
|
|
|
30
30
|
import type { ContentTypeFieldDef, ContentTypeFieldKind, ContentTypeRecord } from "@jini-ai/core/contracts/content-types";
|
|
31
31
|
import type { PluginValidationError } from "./manifest-types.js";
|
|
32
32
|
import type { DeclaredContentType, DeclaredContentTypePlan } from "./ports.js";
|
|
33
|
-
/**
|
|
33
|
+
/** Bound: how many content types one plugin may declare.
|
|
34
34
|
* @agent-note Plugin-domain bound, not a host option; a longer list is refused whole at parse. */
|
|
35
35
|
export declare const MAX_DECLARED_CONTENT_TYPES = 20;
|
|
36
|
-
/**
|
|
36
|
+
/** Bound: how many fields one declared content type may carry.
|
|
37
37
|
* @agent-note Plugin-domain bound, not a host option. */
|
|
38
38
|
export declare const MAX_DECLARED_FIELDS = 50;
|
|
39
39
|
/** Core's own per-type queryable-field cap (`QUERYABLE_FIELD_CAP` in `@jini-ai/cms`'s
|
|
@@ -176,7 +176,7 @@ export interface DeclarativeContentTypes {
|
|
|
176
176
|
/**
|
|
177
177
|
* The declarative half of a manifest's validation: its `contentTypes`, plus — for a `tier-1`
|
|
178
178
|
* plugin — the rule that it declares no code surface. Hooks, capability grants and `ext` fields
|
|
179
|
-
* all exist to be used by plugin code, and a Tier-1 plugin is never imported (
|
|
179
|
+
* all exist to be used by plugin code, and a Tier-1 plugin is never imported ("zero
|
|
180
180
|
* executable code"), so declaring one is either a mistake or an attempt to look like something it
|
|
181
181
|
* is not. `validateManifest()` calls this, so discovery lists a bad declaration as `invalid`
|
|
182
182
|
* instead of it failing only at enable. A surface that is not an array is left to
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { PluginInvalidError } from "./activation.js";
|
|
2
|
-
/**
|
|
2
|
+
/** Bound: how many content types one plugin may declare.
|
|
3
3
|
* @agent-note Plugin-domain bound, not a host option; a longer list is refused whole at parse. */
|
|
4
4
|
export const MAX_DECLARED_CONTENT_TYPES = 20;
|
|
5
|
-
/**
|
|
5
|
+
/** Bound: how many fields one declared content type may carry.
|
|
6
6
|
* @agent-note Plugin-domain bound, not a host option. */
|
|
7
7
|
export const MAX_DECLARED_FIELDS = 50;
|
|
8
8
|
/** Core's own per-type queryable-field cap (`QUERYABLE_FIELD_CAP` in `@jini-ai/cms`'s
|
|
@@ -124,147 +124,153 @@ export function createDeclarativeContentTypes(requiredArgs, _optionalArgs = {})
|
|
|
124
124
|
// The local names keep the transported bodies below byte-identical to their origin.
|
|
125
125
|
const { fieldKinds: CONTENT_TYPE_FIELD_KINDS, isFieldKind: isContentTypeFieldKind, isIndexable: isIndexableFieldKind, validateIdentifier: validateIdentifierGrammar, identifierGrammar: IDENTIFIER_GRAMMAR_TEXT, isAlreadyExists, } = requiredArgs.cms;
|
|
126
126
|
const RESERVED_KEYS = new Set(requiredArgs.reservedKeys);
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
127
|
+
const rules = { CONTENT_TYPE_FIELD_KINDS, isContentTypeFieldKind, isIndexableFieldKind,
|
|
128
|
+
validateIdentifierGrammar, IDENTIFIER_GRAMMAR_TEXT, isAlreadyExists, RESERVED_KEYS };
|
|
129
|
+
return {
|
|
130
|
+
validateManifest: (required, optional) => validateDeclarativeManifest(rules, required, optional),
|
|
131
|
+
parse: (required, optional) => parseDeclaredContentTypes(rules, required, optional),
|
|
132
|
+
plan: planDeclaredContentTypes,
|
|
133
|
+
apply: (required, optional) => applyDeclaredContentTypes(rules, required, optional),
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
/** The name/kind half of one field — returns the validated pair, or `undefined` after recording why. */
|
|
137
|
+
function fieldIdentity(rules, { raw, typeKey, errors }) {
|
|
138
|
+
const { CONTENT_TYPE_FIELD_KINDS, isContentTypeFieldKind, validateIdentifierGrammar, IDENTIFIER_GRAMMAR_TEXT } = rules;
|
|
139
|
+
const name = raw.name;
|
|
140
|
+
if (typeof name !== "string" || !validateIdentifierGrammar({ value: name })) {
|
|
141
|
+
errors.push(declError(`content type '${typeKey}' field name '${String(name)}' must match ${IDENTIFIER_GRAMMAR_TEXT}`));
|
|
142
|
+
return undefined;
|
|
140
143
|
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
const where = `content type '${typeKey}' field '${String(raw.name)}'`;
|
|
146
|
-
const errors = unknownKeyErrors(raw, FIELD_KEYS, where);
|
|
147
|
-
const identity = fieldIdentity(raw, typeKey, errors);
|
|
148
|
-
const required = optionalFlag(raw, "required", where, errors);
|
|
149
|
-
const queryable = optionalFlag(raw, "queryable", where, errors);
|
|
150
|
-
if (identity && queryable && !isIndexableFieldKind({ value: identity.kind })) {
|
|
151
|
-
errors.push(declError(`${where} has storage-only kind '${identity.kind}' and cannot be queryable`));
|
|
152
|
-
}
|
|
153
|
-
if (!identity || errors.length > 0)
|
|
154
|
-
return { errors };
|
|
155
|
-
return { field: { name: identity.name, kind: identity.kind, required, queryable }, errors };
|
|
144
|
+
const kind = raw.kind;
|
|
145
|
+
if (!isContentTypeFieldKind({ value: kind })) {
|
|
146
|
+
errors.push(declError(`content type '${typeKey}' field '${name}' has kind '${String(kind)}'; allowed: ${CONTENT_TYPE_FIELD_KINDS.join("|")}`));
|
|
147
|
+
return undefined;
|
|
156
148
|
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
}
|
|
171
|
-
return { fields, errors };
|
|
149
|
+
return { name, kind: kind };
|
|
150
|
+
}
|
|
151
|
+
/** One `fields[]` entry. Collects every problem it finds; returns the field only when it has none. */
|
|
152
|
+
function parseField(rules, { raw, index, typeKey }) {
|
|
153
|
+
const { isIndexableFieldKind } = rules;
|
|
154
|
+
if (!isRecord(raw))
|
|
155
|
+
return { errors: [declError(`content type '${typeKey}' field ${index} must be an object`)] };
|
|
156
|
+
const where = `content type '${typeKey}' field '${String(raw.name)}'`;
|
|
157
|
+
const errors = unknownKeyErrors(raw, FIELD_KEYS, where);
|
|
158
|
+
const identity = fieldIdentity(rules, { raw, typeKey, errors });
|
|
159
|
+
const required = optionalFlag(raw, "required", where, errors);
|
|
160
|
+
const queryable = optionalFlag(raw, "queryable", where, errors);
|
|
161
|
+
if (identity && queryable && !isIndexableFieldKind({ value: identity.kind })) {
|
|
162
|
+
errors.push(declError(`${where} has storage-only kind '${identity.kind}' and cannot be queryable`));
|
|
172
163
|
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
return [];
|
|
164
|
+
if (!identity || errors.length > 0)
|
|
165
|
+
return { errors };
|
|
166
|
+
return { field: { name: identity.name, kind: identity.kind, required, queryable }, errors };
|
|
167
|
+
}
|
|
168
|
+
function parseFields(rules, raw, typeKey) {
|
|
169
|
+
if (!Array.isArray(raw) || raw.length === 0 || raw.length > MAX_DECLARED_FIELDS) {
|
|
170
|
+
return { fields: [], errors: [declError(`content type '${typeKey}' must declare 1-${MAX_DECLARED_FIELDS} fields`)] };
|
|
181
171
|
}
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
const key = String(raw.key);
|
|
188
|
-
if (!labelValid(raw.label))
|
|
189
|
-
errors.push(declError(`content type '${key}' needs a label of 1-${MAX_LABEL_LENGTH} characters`));
|
|
190
|
-
const fields = parseFields(raw.fields, key);
|
|
191
|
-
errors.push(...fields.errors);
|
|
192
|
-
if (errors.length > 0)
|
|
193
|
-
return { errors };
|
|
194
|
-
return { decl: { key, label: raw.label, fields: fields.fields }, errors };
|
|
172
|
+
const parsed = raw.map((field, index) => parseField(rules, { raw: field, index, typeKey }));
|
|
173
|
+
const fields = parsed.flatMap((result) => (result.field ? [result.field] : []));
|
|
174
|
+
const errors = parsed.flatMap((result) => result.errors);
|
|
175
|
+
for (const name of duplicateNames(fields.map((field) => field.name))) {
|
|
176
|
+
errors.push(declError(`content type '${typeKey}' declares field '${name}' more than once`));
|
|
195
177
|
}
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
*
|
|
200
|
-
* @complexity O(t · f) over declared types and their fields — both bounded by the MAX_* constants.
|
|
201
|
-
*/
|
|
202
|
-
function parseDeclaredContentTypes(required, _optional = {}) {
|
|
203
|
-
const { value } = required;
|
|
204
|
-
if (value === undefined || value === null)
|
|
205
|
-
return { decls: [], errors: [] };
|
|
206
|
-
if (!Array.isArray(value))
|
|
207
|
-
return { decls: [], errors: [declError("'contentTypes' must be an array")] };
|
|
208
|
-
if (value.length > MAX_DECLARED_CONTENT_TYPES) {
|
|
209
|
-
return { decls: [], errors: [declError(`'contentTypes' declares more than ${MAX_DECLARED_CONTENT_TYPES} content types`)] };
|
|
210
|
-
}
|
|
211
|
-
const parsed = value.map((entry, index) => parseDecl(entry, index));
|
|
212
|
-
const decls = parsed.flatMap((result) => (result.decl ? [result.decl] : []));
|
|
213
|
-
const errors = parsed.flatMap((result) => result.errors);
|
|
214
|
-
for (const key of duplicateNames(decls.map((decl) => decl.key))) {
|
|
215
|
-
errors.push(declError(`content type key '${key}' is declared more than once`));
|
|
216
|
-
}
|
|
217
|
-
return { decls, errors };
|
|
178
|
+
const queryableCount = fields.filter((field) => field.queryable).length;
|
|
179
|
+
if (queryableCount > MAX_DECLARED_QUERYABLE_FIELDS) {
|
|
180
|
+
errors.push(declError(`content type '${typeKey}' declares ${queryableCount} queryable fields; at most ${MAX_DECLARED_QUERYABLE_FIELDS} are allowed`));
|
|
218
181
|
}
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
182
|
+
return { fields, errors };
|
|
183
|
+
}
|
|
184
|
+
function keyErrors(rules, key, index) {
|
|
185
|
+
const { validateIdentifierGrammar, IDENTIFIER_GRAMMAR_TEXT, RESERVED_KEYS } = rules;
|
|
186
|
+
if (typeof key !== "string")
|
|
187
|
+
return [declError(`contentTypes[${index}].key must be a string`)];
|
|
188
|
+
if (!validateIdentifierGrammar({ value: key }))
|
|
189
|
+
return [declError(`content type key '${key}' must match ${IDENTIFIER_GRAMMAR_TEXT}`)];
|
|
190
|
+
if (RESERVED_KEYS.has(key))
|
|
191
|
+
return [declError(`content type key '${key}' is reserved by core`)];
|
|
192
|
+
return [];
|
|
193
|
+
}
|
|
194
|
+
/** One `contentTypes[]` entry. */
|
|
195
|
+
function parseDecl(rules, raw, index) {
|
|
196
|
+
if (!isRecord(raw))
|
|
197
|
+
return { errors: [declError(`contentTypes[${index}] must be an object`)] };
|
|
198
|
+
const errors = [...unknownKeyErrors(raw, DECL_KEYS, `contentTypes[${index}]`), ...keyErrors(rules, raw.key, index)];
|
|
199
|
+
const key = String(raw.key);
|
|
200
|
+
if (!labelValid(raw.label))
|
|
201
|
+
errors.push(declError(`content type '${key}' needs a label of 1-${MAX_LABEL_LENGTH} characters`));
|
|
202
|
+
const fields = parseFields(rules, raw.fields, key);
|
|
203
|
+
errors.push(...fields.errors);
|
|
204
|
+
if (errors.length > 0)
|
|
205
|
+
return { errors };
|
|
206
|
+
return { decl: { key, label: raw.label, fields: fields.fields }, errors };
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Parses a manifest's raw `contentTypes` value. Collect-all, never throws (same contract as
|
|
210
|
+
* `validateManifest`). `undefined`/`null` declare nothing.
|
|
211
|
+
*
|
|
212
|
+
* @complexity O(t · f) over declared types and their fields — both bounded by the MAX_* constants.
|
|
213
|
+
*/
|
|
214
|
+
function parseDeclaredContentTypes(rules, required, _optional = {}) {
|
|
215
|
+
const { value } = required;
|
|
216
|
+
if (value === undefined || value === null)
|
|
217
|
+
return { decls: [], errors: [] };
|
|
218
|
+
if (!Array.isArray(value))
|
|
219
|
+
return { decls: [], errors: [declError("'contentTypes' must be an array")] };
|
|
220
|
+
if (value.length > MAX_DECLARED_CONTENT_TYPES) {
|
|
221
|
+
return { decls: [], errors: [declError(`'contentTypes' declares more than ${MAX_DECLARED_CONTENT_TYPES} content types`)] };
|
|
234
222
|
}
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
*/
|
|
241
|
-
async function applyDeclaredContentTypes(required, _optional = {}) {
|
|
242
|
-
const { ports, workspaceId, pluginId, plan } = required;
|
|
243
|
-
const created = [];
|
|
244
|
-
const kept = [];
|
|
245
|
-
const skipped = [];
|
|
246
|
-
const bucket = { created, keep: kept, "skip-tombstoned": skipped };
|
|
247
|
-
for (const { decl, outcome } of plan.items) {
|
|
248
|
-
const applied = outcome === "keep" || outcome === "skip-tombstoned" ? outcome : await createDeclared({ ports, workspaceId, pluginId, decl });
|
|
249
|
-
bucket[applied].push(decl.key);
|
|
250
|
-
}
|
|
251
|
-
return { created, kept, skipped };
|
|
223
|
+
const parsed = value.map((entry, index) => parseDecl(rules, entry, index));
|
|
224
|
+
const decls = parsed.flatMap((result) => (result.decl ? [result.decl] : []));
|
|
225
|
+
const errors = parsed.flatMap((result) => result.errors);
|
|
226
|
+
for (const key of duplicateNames(decls.map((decl) => decl.key))) {
|
|
227
|
+
errors.push(declError(`content type key '${key}' is declared more than once`));
|
|
252
228
|
}
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
229
|
+
return { decls, errors };
|
|
230
|
+
}
|
|
231
|
+
/** See {@link DeclarativeContentTypes.validateManifest}. */
|
|
232
|
+
function validateDeclarativeManifest(rules, required, _optional = {}) {
|
|
233
|
+
const { manifest } = required;
|
|
234
|
+
const parsed = parseDeclaredContentTypes(rules, { value: manifest.contentTypes });
|
|
235
|
+
if (manifest.tier !== "tier-1")
|
|
236
|
+
return parsed;
|
|
237
|
+
const surfaceErrors = CODE_SURFACES.filter((surface) => {
|
|
238
|
+
const declared = manifest[surface];
|
|
239
|
+
return Array.isArray(declared) && declared.length > 0;
|
|
240
|
+
}).map((surface) => ({
|
|
241
|
+
code: "TIER1_DECLARES_CODE_SURFACE",
|
|
242
|
+
file: null,
|
|
243
|
+
message: `a declarative (tier-1) plugin cannot declare '${surface}' — only code can use them`,
|
|
244
|
+
}));
|
|
245
|
+
return { decls: parsed.decls, errors: [...surfaceErrors, ...parsed.errors] };
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Carries out a conflict-free plan. Each create is recorded as `plugin:<id>` so the content-type
|
|
249
|
+
* revision log says which plugin made the type; losing a concurrent create race is judged against
|
|
250
|
+
* the winning type ({@link judgeLostRace}) — kept only when it matches the declaration. Any other
|
|
251
|
+
* failure is rethrown as-is.
|
|
252
|
+
*/
|
|
253
|
+
async function applyDeclaredContentTypes(rules, required, _optional = {}) {
|
|
254
|
+
const { ports, workspaceId, pluginId, plan } = required;
|
|
255
|
+
const created = [];
|
|
256
|
+
const kept = [];
|
|
257
|
+
const skipped = [];
|
|
258
|
+
const bucket = { created, keep: kept, "skip-tombstoned": skipped };
|
|
259
|
+
for (const { decl, outcome } of plan.items) {
|
|
260
|
+
const applied = outcome === "keep" || outcome === "skip-tombstoned" ? outcome : await createDeclared(rules, { ports, workspaceId, pluginId, decl });
|
|
261
|
+
bucket[applied].push(decl.key);
|
|
262
262
|
}
|
|
263
|
-
return {
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
};
|
|
263
|
+
return { created, kept, skipped };
|
|
264
|
+
}
|
|
265
|
+
/** Registers one planned type as `plugin:<id>`; a lost create race takes the judged winner's outcome. */
|
|
266
|
+
async function createDeclared(rules, required) {
|
|
267
|
+
const { isAlreadyExists } = rules;
|
|
268
|
+
const { ports, workspaceId, pluginId, decl } = required;
|
|
269
|
+
const result = await ports.register({ workspaceId, key: decl.key, label: decl.label, fields: [...decl.fields], actorId: `plugin:${pluginId}` });
|
|
270
|
+
if (result.ok)
|
|
271
|
+
return "created";
|
|
272
|
+
if (!isAlreadyExists({ error: result.error }))
|
|
273
|
+
throw result.error;
|
|
274
|
+
return judgeLostRace({ ports, workspaceId, pluginId, decl, lost: result.error });
|
|
269
275
|
}
|
|
270
276
|
//# sourceMappingURL=declarative-content-types.js.map
|
|
@@ -28,7 +28,7 @@ import { PluginInvalidError } from "./activation.js";
|
|
|
28
28
|
*/
|
|
29
29
|
export async function enableDeclaredPlugin(required, optional = {}) {
|
|
30
30
|
const { pluginId, workspaceId, manifest, loadCode } = required;
|
|
31
|
-
//
|
|
31
|
+
// A Tier-1 plugin is zero executable code — the runtime never imports anything for it.
|
|
32
32
|
const load = manifest.tier === "tier-1" ? async () => { } : loadCode;
|
|
33
33
|
const { decls } = required.declarativeContentTypes.parse({ value: manifest.contentTypes });
|
|
34
34
|
if (decls.length === 0) {
|
|
@@ -15,7 +15,7 @@ export interface PluginDiscoveryRecord {
|
|
|
15
15
|
readonly version: string;
|
|
16
16
|
readonly source: "built-in" | "site";
|
|
17
17
|
/** (1.1.2, REQ-10/REQ-18) The plugin's trust tier, projected verbatim from the already-required
|
|
18
|
-
* `PluginManifest.tier`
|
|
18
|
+
* `PluginManifest.tier` — mirrors how `source` already passes through
|
|
19
19
|
* unchanged. Optional on this stub type only so pre-existing fixtures in unrelated test files
|
|
20
20
|
* (`activation.integration.test.ts`, `loader.integration.test.ts`) that construct
|
|
21
21
|
* `PluginDiscoveryRecord` literals for concerns unrelated to REQ-10/`PLUGINS_LIST` are not forced
|
|
@@ -34,12 +34,12 @@ export interface PluginDiscoveryRecord {
|
|
|
34
34
|
* A later whole-set publisher collision omits the losing manifest and marks its record invalid.
|
|
35
35
|
* The incumbent keeps its reservation; the rejected claim must not reappear in host lookup.
|
|
36
36
|
*
|
|
37
|
-
* Exists so a composition root's enable path (`
|
|
37
|
+
* Exists so a composition root's enable path (`packages/plugins/src/host/node/runtime-core.ts`'s `onPluginEnabled()`)
|
|
38
38
|
* can hand `loadPlugin()` the SAME manifest object this discovery pass already parsed, instead of
|
|
39
39
|
* re-reading `jini.plugin.json` a second time. This matters beyond avoiding duplicate I/O: every
|
|
40
40
|
* real caller of `onPluginEnabled` (`activation.ts`'s `setPluginEnabled`, BR-05 step 1) already
|
|
41
41
|
* calls `discoverPlugins()` fresh, in the SAME request, immediately before invoking it (see
|
|
42
|
-
*
|
|
42
|
+
* a host module) — so reusing that record's manifest is not a staleness
|
|
43
43
|
* risk, it is the one-and-only read for this attempt. A second, independent load-time re-read
|
|
44
44
|
* would instead open a narrow TOCTOU window: an attacker who can write to `installDir` between
|
|
45
45
|
* the discovery read and a second load-time read could swap in a self-consistent tampered
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @file `createHookRegistry()` / `runBeforeSave()` — composes enabled plugins' `content.entry.
|
|
3
|
-
* beforeSave` filters, merges `ext`, fail-closed (
|
|
4
|
-
* CIC U-004, no escalation marker).
|
|
3
|
+
* beforeSave` filters, merges `ext`, fail-closed (no escalation marker).
|
|
5
4
|
*
|
|
6
5
|
* Purpose:
|
|
7
6
|
* The concrete adapter for `BeforeSaveHookPort` (`src/features/post/post.ts`'s contract). Keeping
|
|
8
7
|
* this composition logic here — not in `post.ts` — is what keeps `post.ts` plugin-ignorant
|
|
9
8
|
* (Module Map). `activation.ts` calls `.detach()` on disable.
|
|
10
9
|
*
|
|
11
|
-
* **Corrected 2026-08-04
|
|
10
|
+
* **Corrected 2026-08-04:** this comment previously claimed `loader.ts`
|
|
12
11
|
* calls `.attach()` on this registry as each plugin's `setup()` runs. That was false — `loadPlugin()`
|
|
13
12
|
* (`loader.ts`) has never called `.attach()`; steps 4-5 of BR-01 were left unwired, documented but
|
|
14
13
|
* dead, and no other production code called it either (verified: `grep -rn "hookRegistry\.attach"
|
|
@@ -16,10 +15,10 @@
|
|
|
16
15
|
* `loader.ts` exports `attachLoadedPlugin()`, the real (not stub) extraction of that dead logic's
|
|
17
16
|
* attach half, widened to accept a `"glue"` source. Site Glue's content-lifecycle attachment point
|
|
18
17
|
* is `attachLoadedPlugin`'s first production caller; `loadPlugin()` itself still does not call it —
|
|
19
|
-
* a future
|
|
20
|
-
*
|
|
18
|
+
* a future fix for its own activation path is expected to call the same function,
|
|
19
|
+
* rather than re-inventing this wiring a second time.
|
|
21
20
|
*
|
|
22
|
-
* **
|
|
21
|
+
* **Binding, no escalation marker — bounded blast radius via revert:**
|
|
23
22
|
* `runBeforeSave()` must fully resolve (returning the merged patch) or throw before its caller
|
|
24
23
|
* (`post.ts`) constructs the final `PostRecord` passed to `deps.repo.save()`. There is exactly one
|
|
25
24
|
* `repo.save()` call per `createPost`/`updatePost` invocation, and it must never be reached if
|
|
@@ -34,14 +33,15 @@
|
|
|
34
33
|
* earlier filters' already-merged `ext` values on the entry snapshot they receive.
|
|
35
34
|
*
|
|
36
35
|
* Architectural role:
|
|
37
|
-
* TDD-certified implementation
|
|
36
|
+
* TDD-certified implementation. Signature and JSDoc are
|
|
38
37
|
* design-frozen; `runBeforeSave()` orders attached filters, gives each an isolated entry snapshot,
|
|
39
38
|
* validates each declared-field patch, and returns the merged per-plugin `ext` object fail-closed.
|
|
40
39
|
*/
|
|
41
40
|
import type { JsonObject } from "@jini-ai/core/primitives";
|
|
42
|
-
import type {
|
|
41
|
+
import type { PluginSdkBinding } from "./ports.js";
|
|
42
|
+
import type { BeforeSaveFilter, ContentEntryDraft, HookPoints } from "@jini-ai/core/contracts/plugin-sdk";
|
|
43
43
|
import { PluginHookFailedError } from "./errors.js";
|
|
44
|
-
/** Who attached a given filter — extended
|
|
44
|
+
/** Who attached a given filter — extended with `"glue"`, ranked after
|
|
45
45
|
* `"site"` in {@link compareTb01}. Exported so `loader.ts`'s `attachLoadedPlugin()` and any other
|
|
46
46
|
* caller share this one source of truth for the vocabulary rather than re-declaring the union. */
|
|
47
47
|
export type AttachmentSource = "built-in" | "site" | "glue";
|