@jini-ai/plugins 0.6.22 → 0.7.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 +54 -0
- package/dist/host/admin-response.d.ts +93 -0
- package/dist/host/admin-response.js +32 -0
- package/dist/host/capability-tools.d.ts +369 -0
- package/dist/host/capability-tools.js +306 -0
- package/dist/host/declarative-content-types.d.ts +245 -0
- package/dist/host/declarative-content-types.js +270 -0
- package/dist/host/index.d.ts +3 -0
- package/dist/host/index.js +3 -0
- package/dist/host/manifest.d.ts +1 -4
- package/dist/host/manifest.js +2 -5
- package/dist/host/node/archive-policy.d.ts +57 -0
- package/dist/host/node/archive-policy.js +115 -0
- package/dist/host/node/index.d.ts +3 -0
- package/dist/host/node/index.js +3 -0
- package/dist/host/node/install.d.ts +1 -4
- package/dist/host/node/install.js +2 -8
- package/dist/host/node/invocation-binding.d.ts +45 -0
- package/dist/host/node/invocation-binding.js +69 -0
- package/dist/host/node/runtime-core.d.ts +273 -0
- package/dist/host/node/runtime-core.js +613 -0
- package/dist/host/node/source-drafts.d.ts +1 -5
- package/dist/host/node/source-drafts.js +2 -8
- package/dist/host/plugin-claims.d.ts +2 -1
- package/dist/host/plugin-claims.js +1 -1
- package/dist/host/plugin-format.d.ts +4 -0
- package/dist/host/plugin-format.js +4 -0
- package/dist/host/plugin-tool-errors.d.ts +11 -0
- package/dist/host/plugin-tool-errors.js +19 -0
- package/dist/host/tools/contract.d.ts +397 -0
- package/dist/host/tools/contract.js +7 -0
- package/dist/host/tools/index.d.ts +7 -0
- package/dist/host/tools/index.js +6 -0
- package/dist/host/tools/install.d.ts +12 -0
- package/dist/host/tools/install.js +71 -0
- package/dist/host/tools/management.d.ts +51 -0
- package/dist/host/tools/management.js +607 -0
- package/dist/host/tools/source.d.ts +14 -0
- package/dist/host/tools/source.js +95 -0
- package/dist/host/worker/index.d.ts +1 -0
- package/dist/host/worker/index.js +1 -0
- package/dist/host/worker/start.d.ts +44 -0
- package/dist/host/worker/start.js +31 -0
- package/package.json +16 -9
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
import { PluginInvalidError } from "./activation.js";
|
|
2
|
+
/** ADR-024 §5 bound: how many content types one plugin may declare.
|
|
3
|
+
* @agent-note Plugin-domain bound, not a host option; a longer list is refused whole at parse. */
|
|
4
|
+
export const MAX_DECLARED_CONTENT_TYPES = 20;
|
|
5
|
+
/** ADR-024 §5 bound: how many fields one declared content type may carry.
|
|
6
|
+
* @agent-note Plugin-domain bound, not a host option. */
|
|
7
|
+
export const MAX_DECLARED_FIELDS = 50;
|
|
8
|
+
/** Core's own per-type queryable-field cap (`QUERYABLE_FIELD_CAP` in `@jini-ai/cms`'s
|
|
9
|
+
* `registerContentType`, not exported). Checked here so a declaration core would refuse is
|
|
10
|
+
* `invalid` at discovery, instead of failing at enable after the plugin's code attached.
|
|
11
|
+
* @agent-note A host whose own write path allows fewer queryable fields still refuses at
|
|
12
|
+
* `register`; that refusal surfaces as an enable failure, never as a lost race. */
|
|
13
|
+
export const MAX_DECLARED_QUERYABLE_FIELDS = 20;
|
|
14
|
+
const MAX_LABEL_LENGTH = 100;
|
|
15
|
+
const DECL_KEYS = new Set(["key", "label", "fields"]);
|
|
16
|
+
const FIELD_KEYS = new Set(["name", "kind", "required", "queryable"]);
|
|
17
|
+
function declError(message) {
|
|
18
|
+
return { code: "CONTENT_TYPE_DECL_INVALID", file: null, message };
|
|
19
|
+
}
|
|
20
|
+
function isRecord(value) {
|
|
21
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
22
|
+
}
|
|
23
|
+
function unknownKeyErrors(raw, allowed, where) {
|
|
24
|
+
return Object.keys(raw)
|
|
25
|
+
.filter((key) => !allowed.has(key))
|
|
26
|
+
.map((key) => declError(`${where} has an unknown key '${key}'`));
|
|
27
|
+
}
|
|
28
|
+
function optionalFlag(raw, flag, where, errors) {
|
|
29
|
+
const value = raw[flag];
|
|
30
|
+
if (value === undefined)
|
|
31
|
+
return false;
|
|
32
|
+
if (typeof value === "boolean")
|
|
33
|
+
return value;
|
|
34
|
+
errors.push(declError(`${where} '${flag}' must be a boolean`));
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
function duplicateNames(names) {
|
|
38
|
+
const seen = new Set();
|
|
39
|
+
const duplicates = new Set();
|
|
40
|
+
for (const name of names) {
|
|
41
|
+
if (seen.has(name))
|
|
42
|
+
duplicates.add(name);
|
|
43
|
+
seen.add(name);
|
|
44
|
+
}
|
|
45
|
+
return [...duplicates];
|
|
46
|
+
}
|
|
47
|
+
function labelValid(label) {
|
|
48
|
+
return typeof label === "string" && label.trim().length > 0 && label.length <= MAX_LABEL_LENGTH;
|
|
49
|
+
}
|
|
50
|
+
/** The manifest arrays only executable code can use — a Tier-1 plugin has none to use them with. */
|
|
51
|
+
const CODE_SURFACES = ["capabilities", "hooks", "fields"];
|
|
52
|
+
/** Why `existing` cannot serve as `decl`'s type, one reason per disagreeing field. */
|
|
53
|
+
function incompatibilities(decl, existing) {
|
|
54
|
+
const reasons = [];
|
|
55
|
+
for (const field of decl.fields) {
|
|
56
|
+
const held = existing.fields.find((candidate) => candidate.name === field.name);
|
|
57
|
+
if (!held) {
|
|
58
|
+
reasons.push(`content type '${decl.key}' already exists without field '${field.name}'`);
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
if (held.kind !== field.kind)
|
|
62
|
+
reasons.push(`content type '${decl.key}' already exists with field '${field.name}' as '${held.kind}', not '${field.kind}'`);
|
|
63
|
+
}
|
|
64
|
+
return reasons;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Decides, without writing anything, what enabling would do to each declared type. A conflict on
|
|
68
|
+
* ANY type refuses the whole plan, so an enable never leaves half a plugin's types behind.
|
|
69
|
+
*
|
|
70
|
+
* @complexity O(t) port reads plus O(t · f²) field comparison, all manifest-bounded.
|
|
71
|
+
*/
|
|
72
|
+
async function planDeclaredContentTypes(required, _optional = {}) {
|
|
73
|
+
const { ports, workspaceId, decls } = required;
|
|
74
|
+
const items = [];
|
|
75
|
+
const conflicts = [];
|
|
76
|
+
for (const decl of decls) {
|
|
77
|
+
const existing = await ports.findByKey({ workspaceId, key: decl.key });
|
|
78
|
+
if (!existing)
|
|
79
|
+
items.push({ decl, outcome: "create" });
|
|
80
|
+
else if (existing.status === "tombstone")
|
|
81
|
+
items.push({ decl, outcome: "skip-tombstoned" });
|
|
82
|
+
else {
|
|
83
|
+
const reasons = incompatibilities(decl, existing);
|
|
84
|
+
if (reasons.length === 0)
|
|
85
|
+
items.push({ decl, outcome: "keep" });
|
|
86
|
+
conflicts.push(...reasons);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return conflicts.length > 0 ? { items: [], conflicts } : { items, conflicts };
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* What losing a concurrent create race means: the planning-time compatibility check never saw the
|
|
93
|
+
* winning type, so it is re-read and judged the same way `planDeclaredContentTypes` would have —
|
|
94
|
+
* compatible ⇒ kept, tombstoned ⇒ skipped, anything else refuses the enable.
|
|
95
|
+
*
|
|
96
|
+
* @throws {PluginInvalidError} the winner disagrees with the declaration.
|
|
97
|
+
* @throws the original `lost` error when the winner cannot be read back.
|
|
98
|
+
* @complexity One port read plus O(f²) field comparison.
|
|
99
|
+
*/
|
|
100
|
+
async function judgeLostRace(required) {
|
|
101
|
+
const { ports, workspaceId, pluginId, decl, lost } = required;
|
|
102
|
+
const winner = await ports.findByKey({ workspaceId, key: decl.key });
|
|
103
|
+
if (!winner)
|
|
104
|
+
throw lost;
|
|
105
|
+
if (winner.status === "tombstone")
|
|
106
|
+
return "skip-tombstoned";
|
|
107
|
+
const reasons = incompatibilities(decl, winner);
|
|
108
|
+
if (reasons.length > 0)
|
|
109
|
+
throw new PluginInvalidError(`plugin '${pluginId}' cannot be turned on: ${reasons.join("; ")}`);
|
|
110
|
+
return "keep";
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Binds the declaration grammar, tier rule, planner and provisioner to one host's content-type
|
|
114
|
+
* vocabulary and reserved keys.
|
|
115
|
+
*
|
|
116
|
+
* @agent-note Second-host rules: call once at composition and share the result (see
|
|
117
|
+
* {@link DeclarativeContentTypes}). Creation does no I/O and calls none of the `cms` members.
|
|
118
|
+
* The host keeps the manifest file name, the write path, authorization, storage envelope and
|
|
119
|
+
* reserved keys; this factory keeps only plugin-domain bounds, grammar and outcomes.
|
|
120
|
+
*
|
|
121
|
+
* @example createDeclarativeContentTypes({ cms: hostContentTypeVocabulary, reservedKeys: ["page"] }, {})
|
|
122
|
+
*/
|
|
123
|
+
export function createDeclarativeContentTypes(requiredArgs, _optionalArgs = {}) {
|
|
124
|
+
// The local names keep the transported bodies below byte-identical to their origin.
|
|
125
|
+
const { fieldKinds: CONTENT_TYPE_FIELD_KINDS, isFieldKind: isContentTypeFieldKind, isIndexable: isIndexableFieldKind, validateIdentifier: validateIdentifierGrammar, identifierGrammar: IDENTIFIER_GRAMMAR_TEXT, isAlreadyExists, } = requiredArgs.cms;
|
|
126
|
+
const RESERVED_KEYS = new Set(requiredArgs.reservedKeys);
|
|
127
|
+
/** The name/kind half of one field — returns the validated pair, or `undefined` after recording why. */
|
|
128
|
+
function fieldIdentity(raw, typeKey, errors) {
|
|
129
|
+
const name = raw.name;
|
|
130
|
+
if (typeof name !== "string" || !validateIdentifierGrammar({ value: name })) {
|
|
131
|
+
errors.push(declError(`content type '${typeKey}' field name '${String(name)}' must match ${IDENTIFIER_GRAMMAR_TEXT}`));
|
|
132
|
+
return undefined;
|
|
133
|
+
}
|
|
134
|
+
const kind = raw.kind;
|
|
135
|
+
if (!isContentTypeFieldKind({ value: kind })) {
|
|
136
|
+
errors.push(declError(`content type '${typeKey}' field '${name}' has kind '${String(kind)}'; allowed: ${CONTENT_TYPE_FIELD_KINDS.join("|")}`));
|
|
137
|
+
return undefined;
|
|
138
|
+
}
|
|
139
|
+
return { name, kind: kind };
|
|
140
|
+
}
|
|
141
|
+
/** One `fields[]` entry. Collects every problem it finds; returns the field only when it has none. */
|
|
142
|
+
function parseField(raw, index, typeKey) {
|
|
143
|
+
if (!isRecord(raw))
|
|
144
|
+
return { errors: [declError(`content type '${typeKey}' field ${index} must be an object`)] };
|
|
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 };
|
|
156
|
+
}
|
|
157
|
+
function parseFields(raw, typeKey) {
|
|
158
|
+
if (!Array.isArray(raw) || raw.length === 0 || raw.length > MAX_DECLARED_FIELDS) {
|
|
159
|
+
return { fields: [], errors: [declError(`content type '${typeKey}' must declare 1-${MAX_DECLARED_FIELDS} fields`)] };
|
|
160
|
+
}
|
|
161
|
+
const parsed = raw.map((field, index) => parseField(field, index, typeKey));
|
|
162
|
+
const fields = parsed.flatMap((result) => (result.field ? [result.field] : []));
|
|
163
|
+
const errors = parsed.flatMap((result) => result.errors);
|
|
164
|
+
for (const name of duplicateNames(fields.map((field) => field.name))) {
|
|
165
|
+
errors.push(declError(`content type '${typeKey}' declares field '${name}' more than once`));
|
|
166
|
+
}
|
|
167
|
+
const queryableCount = fields.filter((field) => field.queryable).length;
|
|
168
|
+
if (queryableCount > MAX_DECLARED_QUERYABLE_FIELDS) {
|
|
169
|
+
errors.push(declError(`content type '${typeKey}' declares ${queryableCount} queryable fields; at most ${MAX_DECLARED_QUERYABLE_FIELDS} are allowed`));
|
|
170
|
+
}
|
|
171
|
+
return { fields, errors };
|
|
172
|
+
}
|
|
173
|
+
function keyErrors(key, index) {
|
|
174
|
+
if (typeof key !== "string")
|
|
175
|
+
return [declError(`contentTypes[${index}].key must be a string`)];
|
|
176
|
+
if (!validateIdentifierGrammar({ value: key }))
|
|
177
|
+
return [declError(`content type key '${key}' must match ${IDENTIFIER_GRAMMAR_TEXT}`)];
|
|
178
|
+
if (RESERVED_KEYS.has(key))
|
|
179
|
+
return [declError(`content type key '${key}' is reserved by core`)];
|
|
180
|
+
return [];
|
|
181
|
+
}
|
|
182
|
+
/** One `contentTypes[]` entry. */
|
|
183
|
+
function parseDecl(raw, index) {
|
|
184
|
+
if (!isRecord(raw))
|
|
185
|
+
return { errors: [declError(`contentTypes[${index}] must be an object`)] };
|
|
186
|
+
const errors = [...unknownKeyErrors(raw, DECL_KEYS, `contentTypes[${index}]`), ...keyErrors(raw.key, index)];
|
|
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 };
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Parses a manifest's raw `contentTypes` value. Collect-all, never throws (same contract as
|
|
198
|
+
* `validateManifest`). `undefined`/`null` declare nothing.
|
|
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 };
|
|
218
|
+
}
|
|
219
|
+
/** See {@link DeclarativeContentTypes.validateManifest}. */
|
|
220
|
+
function validateDeclarativeManifest(required, _optional = {}) {
|
|
221
|
+
const { manifest } = required;
|
|
222
|
+
const parsed = parseDeclaredContentTypes({ value: manifest.contentTypes });
|
|
223
|
+
if (manifest.tier !== "tier-1")
|
|
224
|
+
return parsed;
|
|
225
|
+
const surfaceErrors = CODE_SURFACES.filter((surface) => {
|
|
226
|
+
const declared = manifest[surface];
|
|
227
|
+
return Array.isArray(declared) && declared.length > 0;
|
|
228
|
+
}).map((surface) => ({
|
|
229
|
+
code: "TIER1_DECLARES_CODE_SURFACE",
|
|
230
|
+
file: null,
|
|
231
|
+
message: `a declarative (tier-1) plugin cannot declare '${surface}' — only code can use them`,
|
|
232
|
+
}));
|
|
233
|
+
return { decls: parsed.decls, errors: [...surfaceErrors, ...parsed.errors] };
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Carries out a conflict-free plan. Each create is recorded as `plugin:<id>` so the content-type
|
|
237
|
+
* revision log says which plugin made the type; losing a concurrent create race is judged against
|
|
238
|
+
* the winning type ({@link judgeLostRace}) — kept only when it matches the declaration. Any other
|
|
239
|
+
* failure is rethrown as-is.
|
|
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 };
|
|
252
|
+
}
|
|
253
|
+
/** Registers one planned type as `plugin:<id>`; a lost create race takes the judged winner's outcome. */
|
|
254
|
+
async function createDeclared(required) {
|
|
255
|
+
const { ports, workspaceId, pluginId, decl } = required;
|
|
256
|
+
const result = await ports.register({ workspaceId, key: decl.key, label: decl.label, fields: [...decl.fields], actorId: `plugin:${pluginId}` });
|
|
257
|
+
if (result.ok)
|
|
258
|
+
return "created";
|
|
259
|
+
if (!isAlreadyExists({ error: result.error }))
|
|
260
|
+
throw result.error;
|
|
261
|
+
return judgeLostRace({ ports, workspaceId, pluginId, decl, lost: result.error });
|
|
262
|
+
}
|
|
263
|
+
return {
|
|
264
|
+
validateManifest: validateDeclarativeManifest,
|
|
265
|
+
parse: parseDeclaredContentTypes,
|
|
266
|
+
plan: planDeclaredContentTypes,
|
|
267
|
+
apply: applyDeclaredContentTypes,
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
//# sourceMappingURL=declarative-content-types.js.map
|
package/dist/host/index.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ export * from './plugin-claims.js';
|
|
|
10
10
|
export * from './claim-conflicts.js';
|
|
11
11
|
export * from './activation.js';
|
|
12
12
|
export * from './declarative-enable.js';
|
|
13
|
+
export * from './declarative-content-types.js';
|
|
13
14
|
export * from './capability-sdk.js';
|
|
14
15
|
export * from './quarantine.js';
|
|
15
16
|
export * from './repo.memory.js';
|
|
@@ -17,6 +18,7 @@ export * from './uninstall.js';
|
|
|
17
18
|
export * from './source-policy.js';
|
|
18
19
|
export * from './contributions.js';
|
|
19
20
|
export * from './tool-contributions.js';
|
|
21
|
+
export * from './capability-tools.js';
|
|
20
22
|
export * from './browser-providers.js';
|
|
21
23
|
export * from './bundled-initialization.js';
|
|
22
24
|
export { PLUGIN_PROVIDER_CAPABILITY } from './provider-contributions.js';
|
|
@@ -25,4 +27,5 @@ export * from './provider-host.js';
|
|
|
25
27
|
export * from './provider-setting-required.js';
|
|
26
28
|
export * from './provider-settings-migrations.js';
|
|
27
29
|
export type { ProviderConfigSource, ProviderKeyUsage, ProviderPluginConfig, ProviderSettingsView, ProviderWriteResult } from './provider-config-source.js';
|
|
30
|
+
export * from './admin-response.js';
|
|
28
31
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/host/index.js
CHANGED
|
@@ -10,6 +10,7 @@ export * from './plugin-claims.js';
|
|
|
10
10
|
export * from './claim-conflicts.js';
|
|
11
11
|
export * from './activation.js';
|
|
12
12
|
export * from './declarative-enable.js';
|
|
13
|
+
export * from './declarative-content-types.js';
|
|
13
14
|
export * from './capability-sdk.js';
|
|
14
15
|
export * from './quarantine.js';
|
|
15
16
|
export * from './repo.memory.js';
|
|
@@ -17,10 +18,12 @@ export * from './uninstall.js';
|
|
|
17
18
|
export * from './source-policy.js';
|
|
18
19
|
export * from './contributions.js';
|
|
19
20
|
export * from './tool-contributions.js';
|
|
21
|
+
export * from './capability-tools.js';
|
|
20
22
|
export * from './browser-providers.js';
|
|
21
23
|
export * from './bundled-initialization.js';
|
|
22
24
|
export { PLUGIN_PROVIDER_CAPABILITY } from './provider-contributions.js';
|
|
23
25
|
export * from './provider-host.js';
|
|
24
26
|
export * from './provider-setting-required.js';
|
|
25
27
|
export * from './provider-settings-migrations.js';
|
|
28
|
+
export * from './admin-response.js';
|
|
26
29
|
//# sourceMappingURL=index.js.map
|
package/dist/host/manifest.d.ts
CHANGED
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
*/
|
|
27
27
|
import type { PluginValidationError } from './manifest-types.js';
|
|
28
28
|
export type { PluginTier, PluginCapability, PluginManifestFieldDecl, PluginManifest, PluginContributions, PluginProviderDeclaration, PluginProviderSettingsMigration, PluginProviderSettingField, PluginProviderSettingOption, PluginValidationError } from './manifest-types.js';
|
|
29
|
+
export { CORE_OWNER_ID } from "./plugin-format.js";
|
|
29
30
|
import type { HookPoints, ManifestHostPorts } from "./ports.js";
|
|
30
31
|
export interface ValidateManifestRequired<H extends HookPoints = HookPoints> extends ManifestHostPorts<H> {
|
|
31
32
|
/** An already-parsed `jini.plugin.json` value (unparseable JSON is `discovery.ts`'s concern —
|
|
@@ -49,10 +50,6 @@ export interface ValidateManifestResult {
|
|
|
49
50
|
export declare function validatePluginIdFormat(required: {
|
|
50
51
|
id: string;
|
|
51
52
|
}, _optional?: Record<string, never>): readonly PluginValidationError[];
|
|
52
|
-
/** The owner id the claim system gives the host core (`plugin-claims.ts` re-exports it). Conflict
|
|
53
|
-
* detection never compares an owner with itself, so a plugin with this id would never conflict with
|
|
54
|
-
* core's reserved routes, tools or permissions — it is refused as an id instead. */
|
|
55
|
-
export declare const CORE_OWNER_ID = "core";
|
|
56
53
|
/** The `contributes` lists `validateContributes` accepts, including structured providers. */
|
|
57
54
|
export declare const CONTRIBUTION_KEYS: readonly ["routes", "tools", "tables", "settings", "widgets", "permissions", "providers"];
|
|
58
55
|
/**
|
package/dist/host/manifest.js
CHANGED
|
@@ -25,7 +25,8 @@
|
|
|
25
25
|
* `errors[]` — it never throws. Verified against `__tests__/unit/manifest.unit.test.ts`.
|
|
26
26
|
*/
|
|
27
27
|
import * as semver from "semver";
|
|
28
|
-
import { PLUGIN_MANIFEST_FILENAME } from "./plugin-format.js";
|
|
28
|
+
import { CORE_OWNER_ID, PLUGIN_MANIFEST_FILENAME } from "./plugin-format.js";
|
|
29
|
+
export { CORE_OWNER_ID } from "./plugin-format.js";
|
|
29
30
|
import { validatePluginProviderDeclarations } from './provider-contributions.js';
|
|
30
31
|
import { validateBrowserProviders } from "./browser-providers.js";
|
|
31
32
|
import { readPluginIdentity, validatePluginIdentity } from "@jini-ai/core/plugin-directory";
|
|
@@ -95,10 +96,6 @@ function validateIdFormat(id) {
|
|
|
95
96
|
export function validatePluginIdFormat(required, _optional = {}) {
|
|
96
97
|
return validateIdFormat(required.id);
|
|
97
98
|
}
|
|
98
|
-
/** The owner id the claim system gives the host core (`plugin-claims.ts` re-exports it). Conflict
|
|
99
|
-
* detection never compares an owner with itself, so a plugin with this id would never conflict with
|
|
100
|
-
* core's reserved routes, tools or permissions — it is refused as an id instead. */
|
|
101
|
-
export const CORE_OWNER_ID = "core";
|
|
102
99
|
/** id identity: reserved id + folder match + built-in shadowing (BR-02 step 3, DUP-01). */
|
|
103
100
|
function validateIdIdentity(id, folderName, builtInIds, coreOwnerName) {
|
|
104
101
|
const errors = [];
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/** Largest archive accepted for upload, in bytes (32 MiB). */
|
|
2
|
+
export declare const MAX_PLUGIN_ARCHIVE_BYTES: number;
|
|
3
|
+
/**
|
|
4
|
+
* One entry as the host's archive reader yields it.
|
|
5
|
+
*
|
|
6
|
+
* @agent-note The host's reader classifies each entry. Only `file` and `directory` are accepted;
|
|
7
|
+
* any other kind is refused as a link. A reader that cannot classify special platform entries
|
|
8
|
+
* (device, fifo, link mode bits) must refuse or classify them itself before yielding.
|
|
9
|
+
*/
|
|
10
|
+
export type PluginArchiveEntry = {
|
|
11
|
+
readonly kind: "file";
|
|
12
|
+
readonly entryPath: string;
|
|
13
|
+
/** The archive format's own claimed size. Never trusted alone: streamed bytes are counted too. */
|
|
14
|
+
readonly declaredSize?: number | undefined;
|
|
15
|
+
/** @agent-note Opened at most once per entry, after the path and declared size pass. */
|
|
16
|
+
readonly openReadStream: (required: Record<string, never>) => AsyncIterable<Uint8Array>;
|
|
17
|
+
} | {
|
|
18
|
+
readonly kind: "directory";
|
|
19
|
+
readonly entryPath: string;
|
|
20
|
+
} | {
|
|
21
|
+
readonly kind: "symlink" | "hardlink" | "device" | "fifo";
|
|
22
|
+
readonly entryPath: string;
|
|
23
|
+
readonly linkTarget?: string | undefined;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Host-supplied archive reader.
|
|
27
|
+
*
|
|
28
|
+
* @agent-note Fulfilled by the host (for example a ZIP library adapter). `entries` is called exactly
|
|
29
|
+
* once per {@link readPluginArchive} call, with the archive bytes the host passed; entries are
|
|
30
|
+
* consumed in yielded order. Errors it throws that are not `PluginInstallError` become
|
|
31
|
+
* `PLUGIN_ARCHIVE_INVALID`; a `PluginInstallError` it throws passes through unchanged.
|
|
32
|
+
*/
|
|
33
|
+
export interface PluginArchiveReaderPort {
|
|
34
|
+
entries(required: {
|
|
35
|
+
readonly archive: Uint8Array;
|
|
36
|
+
}): AsyncIterable<PluginArchiveEntry>;
|
|
37
|
+
}
|
|
38
|
+
/** Required inputs of {@link readPluginArchive}. */
|
|
39
|
+
export interface ReadPluginArchiveRequired {
|
|
40
|
+
/** The uploaded archive bytes; read once, through `reader`. */
|
|
41
|
+
readonly archive: Uint8Array;
|
|
42
|
+
/** @agent-note Required; there is no built-in reader. The host owns the ZIP library choice. */
|
|
43
|
+
readonly reader: PluginArchiveReaderPort;
|
|
44
|
+
}
|
|
45
|
+
/** Optional inputs of {@link readPluginArchive} (none today). */
|
|
46
|
+
export type ReadPluginArchiveOptional = Record<string, never>;
|
|
47
|
+
/**
|
|
48
|
+
* Reads a plugin archive through the host's reader under the bounded policy, returning the
|
|
49
|
+
* accepted files keyed by package-relative POSIX path.
|
|
50
|
+
*
|
|
51
|
+
* @agent-note Per call: one state, one `reader.entries` iteration, no disk writes, no shared state.
|
|
52
|
+
* Every refusal is a `PluginInstallError` with code `PLUGIN_PACKAGE_TOO_LARGE`,
|
|
53
|
+
* `PLUGIN_PACKAGE_UNSAFE` or `PLUGIN_ARCHIVE_INVALID` (any other reader failure). The upload limit
|
|
54
|
+
* is checked before the reader is called. The host publishes the returned files, if at all.
|
|
55
|
+
*/
|
|
56
|
+
export declare function readPluginArchive(required: ReadPluginArchiveRequired, _optional?: ReadPluginArchiveOptional): Promise<Map<string, Buffer>>;
|
|
57
|
+
//# sourceMappingURL=archive-policy.d.ts.map
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Bounded plugin ZIP policy. Parsing/streaming is the host-supplied archive reader, never a
|
|
3
|
+
* custom ZIP parser here. Keep unreviewed bytes off disk; the normal installer alone may publish a
|
|
4
|
+
* verified package.
|
|
5
|
+
*
|
|
6
|
+
* Every accepted file is held in memory; nothing is written. Limits: 32 MiB upload, 4096 entries
|
|
7
|
+
* and distinct path prefixes, 16 MiB per file, 64 MiB expanded — the expanded counts use the bytes
|
|
8
|
+
* actually streamed, never only the archive's declared sizes.
|
|
9
|
+
*/
|
|
10
|
+
import { PluginInstallError } from "./install.js";
|
|
11
|
+
/** Largest archive accepted for upload, in bytes (32 MiB). */
|
|
12
|
+
export const MAX_PLUGIN_ARCHIVE_BYTES = 32 * 1024 * 1024;
|
|
13
|
+
const MAX_ENTRIES = 4096;
|
|
14
|
+
const MAX_FILE_BYTES = 16 * 1024 * 1024;
|
|
15
|
+
const MAX_EXPANDED_BYTES = 64 * 1024 * 1024;
|
|
16
|
+
const SIZE_LIMIT_MESSAGE = "ZIP exceeds the file or expanded size limit.";
|
|
17
|
+
function fail(code, message) { throw new PluginInstallError(code, message); }
|
|
18
|
+
/** Refuses empty, NUL, absolute, drive-lettered, dot/dot-dot, empty-segment and colon paths. */
|
|
19
|
+
function assertInsidePackage(required) {
|
|
20
|
+
const { key, segments } = required;
|
|
21
|
+
const unsafeKey = !key || key.includes("\0") || key.startsWith("/") || /^[a-zA-Z]:/.test(key);
|
|
22
|
+
if (unsafeKey || segments.some((s) => !s || s === "." || s === ".." || s.includes(":")))
|
|
23
|
+
fail("PLUGIN_PACKAGE_UNSAFE", "ZIP paths must stay inside the package.");
|
|
24
|
+
}
|
|
25
|
+
/** Records one path prefix's spelling; refuses a second spelling of it and caps distinct prefixes. */
|
|
26
|
+
function claimSpelling(required) {
|
|
27
|
+
const { spellings, prefix } = required;
|
|
28
|
+
const lower = prefix.toLowerCase();
|
|
29
|
+
if (spellings.has(lower) && spellings.get(lower) !== prefix)
|
|
30
|
+
fail("PLUGIN_PACKAGE_UNSAFE", "ZIP has case-aliased paths.");
|
|
31
|
+
spellings.set(lower, prefix);
|
|
32
|
+
if (spellings.size > MAX_ENTRIES)
|
|
33
|
+
fail("PLUGIN_PACKAGE_TOO_LARGE", "ZIP has too many files and directories.");
|
|
34
|
+
}
|
|
35
|
+
/** Claims `key` for this entry: no duplicates, aliases, paths through a file, or files over a subtree. */
|
|
36
|
+
function claimPath(required) {
|
|
37
|
+
const { state, kind, key, segments } = required;
|
|
38
|
+
if (state.paths.has(key))
|
|
39
|
+
fail("PLUGIN_PACKAGE_UNSAFE", "ZIP has duplicate paths.");
|
|
40
|
+
for (let i = 1; i <= segments.length; i++) {
|
|
41
|
+
const prefix = segments.slice(0, i).join("/");
|
|
42
|
+
claimSpelling({ spellings: state.spellings, prefix });
|
|
43
|
+
// At i === segments.length the prefix is `key` itself, already refused above if present.
|
|
44
|
+
if (state.paths.get(prefix) === "file")
|
|
45
|
+
fail("PLUGIN_PACKAGE_UNSAFE", "ZIP path crosses a file.");
|
|
46
|
+
}
|
|
47
|
+
if (kind === "file" && [...state.paths.keys()].some((p) => p.startsWith(key + "/")))
|
|
48
|
+
fail("PLUGIN_PACKAGE_UNSAFE", "ZIP file replaces a directory.");
|
|
49
|
+
state.paths.set(key, kind);
|
|
50
|
+
}
|
|
51
|
+
/** Refuses a declared size that is not a sane integer, exceeds the file cap, or would exceed the total. */
|
|
52
|
+
function assertDeclaredSize(required) {
|
|
53
|
+
const { declaredSize, total } = required;
|
|
54
|
+
if (declaredSize === undefined)
|
|
55
|
+
return;
|
|
56
|
+
if (!Number.isSafeInteger(declaredSize) || declaredSize < 0 || declaredSize > MAX_FILE_BYTES || total + declaredSize > MAX_EXPANDED_BYTES)
|
|
57
|
+
fail("PLUGIN_PACKAGE_TOO_LARGE", SIZE_LIMIT_MESSAGE);
|
|
58
|
+
}
|
|
59
|
+
/** Streams one file into memory, counting real bytes against the file and expanded caps. */
|
|
60
|
+
async function readFileBytes(required) {
|
|
61
|
+
const { state, entry } = required;
|
|
62
|
+
const chunks = [];
|
|
63
|
+
let length = 0;
|
|
64
|
+
for await (const chunk of entry.openReadStream({})) {
|
|
65
|
+
length += chunk.byteLength;
|
|
66
|
+
state.total += chunk.byteLength;
|
|
67
|
+
if (length > MAX_FILE_BYTES || state.total > MAX_EXPANDED_BYTES)
|
|
68
|
+
fail("PLUGIN_PACKAGE_TOO_LARGE", SIZE_LIMIT_MESSAGE);
|
|
69
|
+
chunks.push(Buffer.from(chunk));
|
|
70
|
+
}
|
|
71
|
+
return Buffer.concat(chunks, length);
|
|
72
|
+
}
|
|
73
|
+
/** Applies the whole policy to one entry, in order, and keeps a file's bytes when it passes. */
|
|
74
|
+
async function acceptEntry(required) {
|
|
75
|
+
const { state, entry } = required;
|
|
76
|
+
state.entries += 1;
|
|
77
|
+
if (state.entries > MAX_ENTRIES)
|
|
78
|
+
fail("PLUGIN_PACKAGE_TOO_LARGE", "ZIP has too many entries.");
|
|
79
|
+
if (entry.kind !== "file" && entry.kind !== "directory")
|
|
80
|
+
fail("PLUGIN_PACKAGE_UNSAFE", "ZIP links are not allowed.");
|
|
81
|
+
const name = entry.entryPath.replaceAll("\\", "/");
|
|
82
|
+
const key = entry.kind === "directory" ? name.replace(/\/$/, "") : name;
|
|
83
|
+
const segments = key.split("/");
|
|
84
|
+
assertInsidePackage({ key, segments });
|
|
85
|
+
claimPath({ state, kind: entry.kind, key, segments });
|
|
86
|
+
if (entry.kind === "directory")
|
|
87
|
+
return;
|
|
88
|
+
assertDeclaredSize({ declaredSize: entry.declaredSize, total: state.total });
|
|
89
|
+
state.files.set(key, await readFileBytes({ state, entry }));
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Reads a plugin archive through the host's reader under the bounded policy, returning the
|
|
93
|
+
* accepted files keyed by package-relative POSIX path.
|
|
94
|
+
*
|
|
95
|
+
* @agent-note Per call: one state, one `reader.entries` iteration, no disk writes, no shared state.
|
|
96
|
+
* Every refusal is a `PluginInstallError` with code `PLUGIN_PACKAGE_TOO_LARGE`,
|
|
97
|
+
* `PLUGIN_PACKAGE_UNSAFE` or `PLUGIN_ARCHIVE_INVALID` (any other reader failure). The upload limit
|
|
98
|
+
* is checked before the reader is called. The host publishes the returned files, if at all.
|
|
99
|
+
*/
|
|
100
|
+
export async function readPluginArchive(required, _optional = {}) {
|
|
101
|
+
if (required.archive.byteLength > MAX_PLUGIN_ARCHIVE_BYTES)
|
|
102
|
+
fail("PLUGIN_PACKAGE_TOO_LARGE", "ZIP exceeds the 32 MiB upload limit.");
|
|
103
|
+
const state = { files: new Map(), paths: new Map(), spellings: new Map(), entries: 0, total: 0 };
|
|
104
|
+
try {
|
|
105
|
+
for await (const entry of required.reader.entries({ archive: required.archive }))
|
|
106
|
+
await acceptEntry({ state, entry });
|
|
107
|
+
return state.files;
|
|
108
|
+
}
|
|
109
|
+
catch (error) {
|
|
110
|
+
if (error instanceof PluginInstallError)
|
|
111
|
+
throw error;
|
|
112
|
+
return fail("PLUGIN_ARCHIVE_INVALID", "ZIP could not be read safely.");
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
//# sourceMappingURL=archive-policy.js.map
|
|
@@ -7,4 +7,7 @@ export * from './module-snapshot.js';
|
|
|
7
7
|
export * from './source-drafts.js';
|
|
8
8
|
export * from './browser-provider-assets.js';
|
|
9
9
|
export * from './provider-artifact.js';
|
|
10
|
+
export * from './invocation-binding.js';
|
|
11
|
+
export * from './archive-policy.js';
|
|
12
|
+
export * from './runtime-core.js';
|
|
10
13
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/host/node/index.js
CHANGED
|
@@ -7,4 +7,7 @@ export * from './module-snapshot.js';
|
|
|
7
7
|
export * from './source-drafts.js';
|
|
8
8
|
export * from './browser-provider-assets.js';
|
|
9
9
|
export * from './provider-artifact.js';
|
|
10
|
+
export * from './invocation-binding.js';
|
|
11
|
+
export * from './archive-policy.js';
|
|
12
|
+
export * from './runtime-core.js';
|
|
10
13
|
//# sourceMappingURL=index.js.map
|
|
@@ -2,10 +2,7 @@ import { type PluginManifest, type PluginTier } from "../manifest.js";
|
|
|
2
2
|
import type { ArchiveReaderPort, ManifestHostPorts, PluginTierPolicy } from "../ports.js";
|
|
3
3
|
import type { PluginActivationRepoPort } from "../activation.js";
|
|
4
4
|
import type { PluginConflict } from "../plugin-claims.js";
|
|
5
|
-
export
|
|
6
|
-
readonly code: string;
|
|
7
|
-
constructor(code: string, message: string);
|
|
8
|
-
}
|
|
5
|
+
export { PluginInstallError } from '../plugin-tool-errors.js';
|
|
9
6
|
export interface PluginInstallPreview {
|
|
10
7
|
readonly warnings?: readonly string[];
|
|
11
8
|
readonly publisherId?: string;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { PluginInstallError } from '../plugin-tool-errors.js';
|
|
1
2
|
import { readPluginIdentity, assertPluginIdentityAvailable } from "@jini-ai/core/plugin-directory";
|
|
2
3
|
/** Local-install environment consent is host-owned; archiveReader owns zip-slip/decompression
|
|
3
4
|
* checks and tierPolicy.checkInstall owns publisher admission. */
|
|
@@ -12,14 +13,7 @@ import { createHash } from "node:crypto";
|
|
|
12
13
|
import * as semver from "semver";
|
|
13
14
|
import { validateManifest, validatePluginIdFormat } from "../manifest.js";
|
|
14
15
|
import { PLUGIN_MANIFEST_FILENAME as MANIFEST, PLUGIN_MANIFEST_FILENAMES, canonicalizePluginManifest } from "../plugin-format.js";
|
|
15
|
-
export
|
|
16
|
-
code;
|
|
17
|
-
constructor(code, message) {
|
|
18
|
-
super(message);
|
|
19
|
-
this.code = code;
|
|
20
|
-
this.name = "PluginInstallError";
|
|
21
|
-
}
|
|
22
|
-
}
|
|
16
|
+
export { PluginInstallError } from '../plugin-tool-errors.js';
|
|
23
17
|
const MAX_ENTRIES = 4096;
|
|
24
18
|
const MAX_FILE_BYTES = 16 * 1024 * 1024;
|
|
25
19
|
const MAX_TOTAL_BYTES = 64 * 1024 * 1024;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { BeforeSaveFilter } from "../ports.js";
|
|
2
|
+
import type { CapabilityScopedSdkCoreDeps } from "../capability-sdk.js";
|
|
3
|
+
/**
|
|
4
|
+
* @agent-note Second-host rule: `beforeSaveHook` is YOUR SDK's beforeSave hook id (the same string
|
|
5
|
+
* as `PluginSdkBinding.beforeSaveHook`); the plugin package never chooses it. `declaredHooks` is the
|
|
6
|
+
* already-validated manifest `hooks` list for this one load. Build one binding per plugin load
|
|
7
|
+
* (per worker call on Tier 2) — never share one across loads.
|
|
8
|
+
*/
|
|
9
|
+
export interface CreatePluginInvocationBindingRequired {
|
|
10
|
+
readonly pluginId: string;
|
|
11
|
+
/** The manifest's declared `hooks` — `addFilter` refuses any hook not listed here. */
|
|
12
|
+
readonly declaredHooks: readonly string[];
|
|
13
|
+
/** The host SDK's beforeSave hook id; the only hook `addFilter` accepts here. */
|
|
14
|
+
readonly beforeSaveHook: string;
|
|
15
|
+
}
|
|
16
|
+
export type CreatePluginInvocationBindingOptional = Record<string, never>;
|
|
17
|
+
/**
|
|
18
|
+
* @agent-note Second-host rule: hand `coreDeps` to `loadPlugin()`/`buildCapabilityScopedSdk()` for
|
|
19
|
+
* the SAME load, then read `capturedFilter()` only after `setup()` resolved. The wrapped filter
|
|
20
|
+
* runs the plugin filter inside this load's one AsyncLocalStorage; the host adapts its own rich
|
|
21
|
+
* SDK entry/patch types onto this plain envelope and keeps every host payload field (the entry
|
|
22
|
+
* object is passed through untouched).
|
|
23
|
+
*/
|
|
24
|
+
export interface PluginInvocationBinding {
|
|
25
|
+
/** Hand to `buildCapabilityScopedSdk()` (via `loadPlugin()`'s `coreDeps`). */
|
|
26
|
+
readonly coreDeps: CapabilityScopedSdkCoreDeps;
|
|
27
|
+
/** The beforeSave filter `setup()` attached, wrapped so `content.read`/`content.extend` work
|
|
28
|
+
* while it runs; `null` until (or unless) setup attaches one. */
|
|
29
|
+
capturedFilter(): BeforeSaveFilter | null;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Builds one plugin load's SDK backing plus the slot its `setup()` fills with a beforeSave filter.
|
|
33
|
+
*
|
|
34
|
+
* @agent-note Invariants a second host relies on: ONE AsyncLocalStorage per load; `content.read`
|
|
35
|
+
* and `content.extend` work only inside the running filter (outside it they throw a named error);
|
|
36
|
+
* exactly one filter, and only for the declared `beforeSaveHook`; extend writes merge UNDER the
|
|
37
|
+
* filter's returned keys (returned keys win); a non-object return passes through untouched.
|
|
38
|
+
* Nothing here writes or persists — the host's hook registry owns save, preview and quarantine.
|
|
39
|
+
* @throws Nothing at build time. The returned handles throw when used outside a running filter,
|
|
40
|
+
* when an undeclared hook is attached, or when a second beforeSave filter is attached.
|
|
41
|
+
* @complexity O(1) per call; a wrapped filter adds O(extend-write count) to merge writes.
|
|
42
|
+
* @example createPluginInvocationBinding({ pluginId, declaredHooks: manifest.hooks, beforeSaveHook: binding.beforeSaveHook }, {})
|
|
43
|
+
*/
|
|
44
|
+
export declare function createPluginInvocationBinding(required: CreatePluginInvocationBindingRequired, _optional?: CreatePluginInvocationBindingOptional): PluginInvocationBinding;
|
|
45
|
+
//# sourceMappingURL=invocation-binding.d.ts.map
|