@jini-ai/plugins 0.5.0 → 0.5.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 +10 -0
- package/dist/glue/capability-gate.js +1 -1
- package/dist/host/browser-providers.d.ts +2 -9
- package/dist/host/browser-providers.js +34 -18
- package/dist/host/capability-sdk.js +1 -1
- package/dist/host/claim-conflicts.d.ts +4 -4
- package/dist/host/claim-conflicts.js +4 -4
- package/dist/host/contributions.d.ts +4 -1
- package/dist/host/contributions.js +19 -8
- package/dist/host/discovery-types.d.ts +2 -2
- package/dist/host/hook-registry.js +7 -5
- package/dist/host/index.d.ts +1 -0
- package/dist/host/index.js +1 -0
- package/dist/host/manifest-types.d.ts +103 -0
- package/dist/host/manifest-types.js +2 -0
- package/dist/host/manifest.d.ts +5 -97
- package/dist/host/manifest.js +33 -24
- package/dist/host/node/discovery.js +27 -22
- package/dist/host/node/install.js +257 -192
- package/dist/host/node/loader.js +85 -67
- package/dist/host/node/module-snapshot.js +3 -2
- package/dist/host/node/open-flags.d.ts +18 -0
- package/dist/host/node/open-flags.js +14 -0
- package/dist/host/node/package-files.js +18 -12
- package/dist/host/node/source-drafts.d.ts +2 -0
- package/dist/host/node/source-drafts.js +93 -59
- package/dist/host/plugin-claims.js +6 -4
- package/dist/host/plugin-format.d.ts +14 -0
- package/dist/host/plugin-format.js +21 -0
- package/dist/host/ports.d.ts +4 -4
- package/dist/host/tool-contributions.js +3 -1
- package/dist/host/worker/protocol.js +8 -6
- package/dist/host/worker/run-call.d.ts +1 -1
- package/dist/host/worker/run-call.js +20 -17
- package/package.json +5 -5
package/dist/host/manifest.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* (SPEC-005 REQ-01, BR-02/BR-03; ADR-024 `tier`, 1.1.1 fix).
|
|
4
4
|
*
|
|
5
5
|
* Purpose:
|
|
6
|
-
* Pure, no-I/O validation of an already-parsed `
|
|
6
|
+
* Pure, no-I/O validation of an already-parsed `jini.plugin.json` object against the v1 required-
|
|
7
7
|
* field set, id/folder match, capability vocabulary, hook vocabulary, and field-declaration rules.
|
|
8
8
|
* Consumed by both `discovery.ts` (list-time, every discovery pass) and `loader.ts` (enable-time
|
|
9
9
|
* re-validation, BR-05) — one validator, two call sites, never diverging (mirrors SPEC-004's theme
|
|
@@ -25,8 +25,10 @@
|
|
|
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
29
|
import { validateBrowserProviders } from "./browser-providers.js";
|
|
29
30
|
import { readPluginIdentity, validatePluginIdentity } from "@jini-ai/core/plugin-directory";
|
|
31
|
+
import { isNonArrayRecord } from "@jini-ai/core/records";
|
|
30
32
|
/**
|
|
31
33
|
* Validates one already-parsed manifest against BR-02 steps (2)-(6), collecting every applicable
|
|
32
34
|
* error rather than stopping at the first (BR-02: "collect ALL statically-determinable errors").
|
|
@@ -92,7 +94,7 @@ function validateIdFormat(id) {
|
|
|
92
94
|
export function validatePluginIdFormat(required, _optional = {}) {
|
|
93
95
|
return validateIdFormat(required.id);
|
|
94
96
|
}
|
|
95
|
-
/** The owner id the claim system gives
|
|
97
|
+
/** The owner id the claim system gives the host core (`plugin-claims.ts` re-exports it). Conflict
|
|
96
98
|
* detection never compares an owner with itself, so a plugin with this id would never conflict with
|
|
97
99
|
* core's reserved routes, tools or permissions — it is refused as an id instead. */
|
|
98
100
|
export const CORE_OWNER_ID = "core";
|
|
@@ -160,13 +162,17 @@ function validateIdentityFields(raw) {
|
|
|
160
162
|
if (raw.version !== undefined && (typeof raw.version !== "string" || !isExactSemver(raw.version))) {
|
|
161
163
|
errors.push(malformed(`version '${String(raw.version)}' must be a semver version (e.g. 1.0.0)`));
|
|
162
164
|
}
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
return
|
|
165
|
+
return [...errors, ...validateIntegrity({ integrity: raw.integrity })];
|
|
166
|
+
}
|
|
167
|
+
function validateIntegrity({ integrity }, _optional = {}) {
|
|
168
|
+
if (integrity === undefined)
|
|
169
|
+
return [];
|
|
170
|
+
const input = { value: integrity };
|
|
171
|
+
if (!isNonArrayRecord(input)) {
|
|
172
|
+
return [malformed("'integrity' must be an object mapping packaged file paths to sha256 hashes")];
|
|
168
173
|
}
|
|
169
|
-
|
|
174
|
+
const errors = [];
|
|
175
|
+
for (const [file, hash] of Object.entries(input.value)) {
|
|
170
176
|
if (file === "" || typeof hash !== "string" || !INTEGRITY_HASH_PATTERN.test(hash)) {
|
|
171
177
|
errors.push(malformed(`integrity entry '${file}' must be 'sha256-' followed by 64 lowercase hex characters`));
|
|
172
178
|
}
|
|
@@ -361,19 +367,22 @@ function validateContributes(raw, id) {
|
|
|
361
367
|
}
|
|
362
368
|
const errors = [];
|
|
363
369
|
for (const [key, list] of Object.entries(raw.contributes)) {
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
370
|
+
errors.push(...validateContributionList({ key, list, id }));
|
|
371
|
+
}
|
|
372
|
+
return errors;
|
|
373
|
+
}
|
|
374
|
+
function validateContributionList({ key, list, id }, _optional = {}) {
|
|
375
|
+
if (!CONTRIBUTION_KEY_SET.has(key)) {
|
|
376
|
+
return [contributesInvalid(`unknown contributes key '${key}' (expected one of ${CONTRIBUTION_KEYS.join(", ")})`)];
|
|
377
|
+
}
|
|
378
|
+
if (!Array.isArray(list) || list.some((entry) => typeof entry !== "string" || entry.trim() === "")) {
|
|
379
|
+
return [contributesInvalid(`contributes.${key} must be a list of non-empty strings`)];
|
|
380
|
+
}
|
|
381
|
+
const errors = [];
|
|
382
|
+
for (const entry of list) {
|
|
383
|
+
const error = validateContribution(key, entry, id);
|
|
384
|
+
if (error)
|
|
385
|
+
errors.push(error);
|
|
377
386
|
}
|
|
378
387
|
return errors;
|
|
379
388
|
}
|
|
@@ -391,14 +400,14 @@ function validateContributes(raw, id) {
|
|
|
391
400
|
export function validateManifest(required, _optional = {}) {
|
|
392
401
|
const { manifest, folderName, builtInIds } = required;
|
|
393
402
|
if (typeof manifest !== "object" || manifest === null || Array.isArray(manifest)) {
|
|
394
|
-
return { errors: [malformed(
|
|
403
|
+
return { errors: [malformed(`${PLUGIN_MANIFEST_FILENAME} must be a JSON object`)] };
|
|
395
404
|
}
|
|
396
405
|
// Treat the input as a read-only bag of unknown values — never assigned back into.
|
|
397
406
|
const raw = manifest;
|
|
398
407
|
const { errors: idErrors, id } = validateId(raw, folderName, builtInIds, required.coreOwnerName);
|
|
399
408
|
const errors = [
|
|
400
409
|
...validateKeys(raw),
|
|
401
|
-
...validatePluginIdentity({ manifest: raw, namespace: required.identityNamespace
|
|
410
|
+
...validatePluginIdentity({ manifest: raw, namespace: required.identityNamespace }).errors.map(message => ({ code: "PLUGIN_IDENTITY_INVALID", file: null, message })),
|
|
402
411
|
...idErrors,
|
|
403
412
|
...validateIdentityFields(raw),
|
|
404
413
|
...validateEngine(raw),
|
|
@@ -412,7 +421,7 @@ export function validateManifest(required, _optional = {}) {
|
|
|
412
421
|
...required.declarativeContentTypes.validateManifest({ manifest: raw }).errors,
|
|
413
422
|
];
|
|
414
423
|
const warnings = errors.length === 0
|
|
415
|
-
? readPluginIdentity({ manifest: raw, name: id, namespace: required.identityNamespace
|
|
424
|
+
? readPluginIdentity({ manifest: raw, name: id, namespace: required.identityNamespace }).warnings
|
|
416
425
|
: [];
|
|
417
426
|
return { errors, warnings };
|
|
418
427
|
}
|
|
@@ -26,6 +26,7 @@ import { readPluginIdentity } from "@jini-ai/core/plugin-directory";
|
|
|
26
26
|
*/
|
|
27
27
|
import { readdir, readFile } from "node:fs/promises";
|
|
28
28
|
import path from "node:path";
|
|
29
|
+
import { PLUGIN_MANIFEST_FILENAME, PLUGIN_MANIFEST_FILENAMES } from "../plugin-format.js";
|
|
29
30
|
import * as semver from "semver";
|
|
30
31
|
import { validateManifest } from "../manifest.js";
|
|
31
32
|
export class PluginDiscoveryVersionError extends Error {
|
|
@@ -60,7 +61,7 @@ function readTierField(value) {
|
|
|
60
61
|
const raw = readStringField(value, "tier");
|
|
61
62
|
return raw !== undefined && VALID_TIERS.has(raw) ? raw : FALLBACK_TIER;
|
|
62
63
|
}
|
|
63
|
-
/** Parses one `
|
|
64
|
+
/** Parses one `jini.plugin.json` file's bytes; unparseable JSON becomes `null` — `validateManifest`
|
|
64
65
|
* already reports a `MANIFEST_MALFORMED` entry for any non-object value (its own top-level guard),
|
|
65
66
|
* so a parse failure and a wrong-shape object are handled through the exact same code path. */
|
|
66
67
|
function parseManifestJson(raw) {
|
|
@@ -133,7 +134,26 @@ async function pickLatestVersionFolder(idFolderPath) {
|
|
|
133
134
|
return 1;
|
|
134
135
|
return b.localeCompare(a);
|
|
135
136
|
});
|
|
136
|
-
return sorted[0]
|
|
137
|
+
return sorted[0];
|
|
138
|
+
}
|
|
139
|
+
/** Activation pins must be exact, path-safe semver; a malformed pin is the caller's fault, not a plugin's. */
|
|
140
|
+
function assertSafeRequestedVersion(requestedVersion) {
|
|
141
|
+
if (requestedVersion !== undefined && (!semver.valid(requestedVersion) || !/^[0-9A-Za-z][0-9A-Za-z.+-]*$/.test(requestedVersion))) {
|
|
142
|
+
throw new PluginDiscoveryVersionError('The requested plugin activation version is not a safe semantic version.');
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
/** The first manifest present (current name, then the legacy alias); `missing` when neither exists. */
|
|
146
|
+
async function readSiteManifest(versionDir) {
|
|
147
|
+
for (const filename of PLUGIN_MANIFEST_FILENAMES) { // legacy alias
|
|
148
|
+
try {
|
|
149
|
+
return { missing: false, manifestValue: parseManifestJson(await readFile(path.join(versionDir, filename), "utf8")) };
|
|
150
|
+
}
|
|
151
|
+
catch (error) {
|
|
152
|
+
if (error?.code !== "ENOENT")
|
|
153
|
+
throw error;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
return { missing: true, manifestValue: null };
|
|
137
157
|
}
|
|
138
158
|
/**
|
|
139
159
|
* The installer refuses a sideloaded tier-2 package (`install.ts`'s `checkTierAndCode`): a package
|
|
@@ -147,28 +167,13 @@ async function pickLatestVersionFolder(idFolderPath) {
|
|
|
147
167
|
async function discoverOneSiteCandidate(installDir, idFolderName, builtInIds, host, options = {}) {
|
|
148
168
|
const idFolderPath = path.join(installDir, idFolderName);
|
|
149
169
|
const requestedVersion = options.versions?.get(idFolderName);
|
|
150
|
-
|
|
151
|
-
throw new PluginDiscoveryVersionError('The requested plugin activation version is not a safe semantic version.');
|
|
152
|
-
}
|
|
170
|
+
assertSafeRequestedVersion(requestedVersion);
|
|
153
171
|
const versionFolderName = requestedVersion ?? await pickLatestVersionFolder(idFolderPath);
|
|
154
172
|
if (versionFolderName === null)
|
|
155
173
|
return null;
|
|
156
|
-
const
|
|
157
|
-
let manifestValue = null;
|
|
158
|
-
let missing = false;
|
|
159
|
-
try {
|
|
160
|
-
manifestValue = parseManifestJson(await readFile(manifestPath, "utf8"));
|
|
161
|
-
}
|
|
162
|
-
catch (error) {
|
|
163
|
-
if (error?.code === "ENOENT") {
|
|
164
|
-
missing = true;
|
|
165
|
-
}
|
|
166
|
-
else {
|
|
167
|
-
throw error;
|
|
168
|
-
}
|
|
169
|
-
}
|
|
174
|
+
const { missing, manifestValue } = await readSiteManifest(path.join(idFolderPath, versionFolderName));
|
|
170
175
|
const errors = missing
|
|
171
|
-
? [{ code: "MANIFEST_MISSING", file:
|
|
176
|
+
? [{ code: "MANIFEST_MISSING", file: PLUGIN_MANIFEST_FILENAME, message: `${PLUGIN_MANIFEST_FILENAME} was not found` }]
|
|
172
177
|
: [...validateManifest({ ...host, manifest: manifestValue, folderName: idFolderName, builtInIds }).errors, ...host.tierPolicy.siteErrors({ manifestValue })];
|
|
173
178
|
const id = readStringField(manifestValue, "id") ?? idFolderName;
|
|
174
179
|
const name = readStringField(manifestValue, "name") ?? idFolderName;
|
|
@@ -185,7 +190,7 @@ function markCaseInsensitiveDuplicates(records) {
|
|
|
185
190
|
countByLowerId.set(key, (countByLowerId.get(key) ?? 0) + 1);
|
|
186
191
|
}
|
|
187
192
|
return records.map((record) => {
|
|
188
|
-
const isDuplicate =
|
|
193
|
+
const isDuplicate = countByLowerId.get(record.id.toLowerCase()) > 1;
|
|
189
194
|
if (!isDuplicate)
|
|
190
195
|
return record;
|
|
191
196
|
const errors = [
|
|
@@ -229,7 +234,7 @@ export async function discoverPlugins(required, optional = {}) {
|
|
|
229
234
|
return records.map(record => {
|
|
230
235
|
if (record.status !== "valid" || !record.manifest)
|
|
231
236
|
return record;
|
|
232
|
-
const identity = readPluginIdentity({ manifest: record.manifest, name: record.id, namespace: required.identityNamespace
|
|
237
|
+
const identity = readPluginIdentity({ manifest: record.manifest, name: record.id, namespace: required.identityNamespace });
|
|
233
238
|
if (!qualifiedIds.has(identity.id)) {
|
|
234
239
|
qualifiedIds.add(identity.id);
|
|
235
240
|
return { ...record, warnings: identity.warnings };
|