@jini-ai/plugins 0.4.1 → 0.5.0
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 +4 -0
- package/dist/host/browser-providers.d.ts +35 -0
- package/dist/host/browser-providers.js +44 -0
- package/dist/host/bundled-initialization.d.ts +23 -0
- package/dist/host/bundled-initialization.js +32 -0
- package/dist/host/index.d.ts +2 -0
- package/dist/host/index.js +2 -0
- package/dist/host/manifest.d.ts +3 -0
- package/dist/host/manifest.js +3 -1
- package/dist/host/node/browser-provider-assets.d.ts +22 -0
- package/dist/host/node/browser-provider-assets.js +50 -0
- package/dist/host/node/index.d.ts +1 -0
- package/dist/host/node/index.js +1 -0
- package/dist/host/node/loader.d.ts +6 -1
- package/dist/host/node/loader.js +13 -2
- package/dist/host/node/module-snapshot.d.ts +7 -0
- package/dist/host/node/module-snapshot.js +18 -11
- package/dist/host/node/source-drafts.d.ts +6 -0
- package/dist/host/node/source-drafts.js +27 -1
- package/dist/host/ports.d.ts +8 -0
- package/dist/host/source-policy.d.ts +20 -0
- package/dist/host/source-policy.js +30 -1
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
# @jini-ai/plugins
|
|
2
2
|
|
|
3
|
+
## 0.5.0 — 2026-10-13
|
|
4
|
+
|
|
5
|
+
- Admit reviewed digest-pinned compiled-in chart browser providers only, retain immutable asset bytes, and initialize bundled site plugins only when activation rows are absent.
|
|
6
|
+
|
|
3
7
|
## 0.4.0 — 2026-10-02
|
|
4
8
|
|
|
5
9
|
### BREAKING
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/** Bundled chart declarations only. ADR-025 trust comes from composition, never the manifest. */
|
|
2
|
+
import type { PluginValidationError } from './manifest.js';
|
|
3
|
+
export interface BrowserProviderDeclaration {
|
|
4
|
+
readonly id: string;
|
|
5
|
+
readonly kind: 'chart';
|
|
6
|
+
readonly contractVersion: 1;
|
|
7
|
+
readonly kinds: readonly string[];
|
|
8
|
+
readonly javascript: string;
|
|
9
|
+
readonly stylesheet?: string;
|
|
10
|
+
}
|
|
11
|
+
export interface BrowserProviderAsset {
|
|
12
|
+
readonly path: string;
|
|
13
|
+
readonly digest: string;
|
|
14
|
+
readonly contentType: 'text/javascript' | 'text/css';
|
|
15
|
+
/** A fresh copy of retained verified bytes, never a filesystem read. */
|
|
16
|
+
readBytes(input: Record<string, never>, options?: Record<string, never>): Uint8Array;
|
|
17
|
+
}
|
|
18
|
+
export interface AdmittedBrowserProvider {
|
|
19
|
+
readonly pluginId: string;
|
|
20
|
+
readonly version: string;
|
|
21
|
+
readonly declaration: BrowserProviderDeclaration;
|
|
22
|
+
readonly assets: readonly BrowserProviderAsset[];
|
|
23
|
+
}
|
|
24
|
+
/** Portable package-relative paths. Refuse dot segments, URL syntax and alternate separators. */
|
|
25
|
+
export declare function isPluginRelativePath({ path }: {
|
|
26
|
+
path: string;
|
|
27
|
+
}, _options?: Record<string, never>): boolean;
|
|
28
|
+
/** Collect static declaration errors; admission additionally requires compiled-in host pins.
|
|
29
|
+
* @example validateBrowserProviders({ browserProviders, integrity })
|
|
30
|
+
*/
|
|
31
|
+
export declare function validateBrowserProviders({ browserProviders, integrity }: {
|
|
32
|
+
browserProviders: unknown;
|
|
33
|
+
integrity: Readonly<Record<string, unknown>>;
|
|
34
|
+
}, _options?: Record<string, never>): readonly PluginValidationError[];
|
|
35
|
+
//# sourceMappingURL=browser-providers.d.ts.map
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/** Portable package-relative paths. Refuse dot segments, URL syntax and alternate separators. */
|
|
2
|
+
export function isPluginRelativePath({ path }, _options = {}) {
|
|
3
|
+
return path.length > 0 && !/[\\:\u0000-\u001f]/.test(path) && path.split('/').every((segment) => segment.length > 0 && segment !== '.' && segment !== '..');
|
|
4
|
+
}
|
|
5
|
+
/** Collect static declaration errors; admission additionally requires compiled-in host pins.
|
|
6
|
+
* @example validateBrowserProviders({ browserProviders, integrity })
|
|
7
|
+
*/
|
|
8
|
+
export function validateBrowserProviders({ browserProviders, integrity }, _options = {}) {
|
|
9
|
+
if (browserProviders === undefined)
|
|
10
|
+
return [];
|
|
11
|
+
const errors = [];
|
|
12
|
+
const invalid = (message) => { errors.push({ code: 'BROWSER_PROVIDER_INVALID', file: null, message }); };
|
|
13
|
+
if (!Array.isArray(browserProviders)) {
|
|
14
|
+
invalid('browserProviders must be a list.');
|
|
15
|
+
return errors;
|
|
16
|
+
}
|
|
17
|
+
const ids = new Set();
|
|
18
|
+
for (const value of browserProviders) {
|
|
19
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value)) {
|
|
20
|
+
invalid('Browser provider must be an object.');
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
const provider = value;
|
|
24
|
+
if (Object.keys(provider).some((key) => !['id', 'kind', 'contractVersion', 'kinds', 'javascript', 'stylesheet'].includes(key)))
|
|
25
|
+
invalid('Unknown browser provider field.');
|
|
26
|
+
if (typeof provider.id !== 'string' || !/^[a-z0-9][a-z0-9.-]*$/.test(provider.id) || ids.has(provider.id))
|
|
27
|
+
invalid('Browser provider id must be unique and non-empty.');
|
|
28
|
+
if (typeof provider.id === 'string')
|
|
29
|
+
ids.add(provider.id);
|
|
30
|
+
if (provider.kind !== 'chart' || provider.contractVersion !== 1)
|
|
31
|
+
invalid('Only chart contractVersion 1 is supported.');
|
|
32
|
+
if (!Array.isArray(provider.kinds) || provider.kinds.length === 0 || provider.kinds.some((kind) => typeof kind !== 'string' || kind.trim() === '') || new Set(provider.kinds).size !== provider.kinds.length)
|
|
33
|
+
invalid('Chart kinds must be unique non-empty strings.');
|
|
34
|
+
for (const [key, suffix] of [['javascript', /\.(?:m?js)$/], ['stylesheet', /\.css$/]]) {
|
|
35
|
+
const file = provider[key];
|
|
36
|
+
if (key === 'stylesheet' && file === undefined)
|
|
37
|
+
continue;
|
|
38
|
+
if (typeof file !== 'string' || !isPluginRelativePath({ path: file }) || !file.startsWith('client/') || !suffix.test(file) || !/^sha256-[0-9a-f]{64}$/.test(String(integrity[file])))
|
|
39
|
+
invalid(`Browser provider ${key} must name a digest-covered client asset.`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return errors;
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=browser-providers.js.map
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/** Site-plugin defaults use the existing activation lifecycle, not the agent-plugin seed store. */
|
|
2
|
+
import { type SetPluginEnabledDeps } from './activation.js';
|
|
3
|
+
export interface BundledInitializationResult {
|
|
4
|
+
readonly enabled: readonly string[];
|
|
5
|
+
readonly skipped: readonly string[];
|
|
6
|
+
readonly failed: readonly {
|
|
7
|
+
pluginId: string;
|
|
8
|
+
error: unknown;
|
|
9
|
+
}[];
|
|
10
|
+
}
|
|
11
|
+
/** Enable approved bundled ids only when NO row exists. Disabled, enabled and quarantined rows
|
|
12
|
+
* remain authoritative. Boot failures are reported individually; activation owns compensation.
|
|
13
|
+
* Composition must serialize this boot initializer with workspace activation changes.
|
|
14
|
+
* @example initializeBundledPlugins({ deps, input: { workspaceId, pluginIds: ['charts-recharts'] } })
|
|
15
|
+
*/
|
|
16
|
+
export declare function initializeBundledPlugins({ deps, input }: {
|
|
17
|
+
deps: SetPluginEnabledDeps;
|
|
18
|
+
input: {
|
|
19
|
+
workspaceId: string;
|
|
20
|
+
pluginIds: readonly string[];
|
|
21
|
+
};
|
|
22
|
+
}, _options?: Record<string, never>): Promise<BundledInitializationResult>;
|
|
23
|
+
//# sourceMappingURL=bundled-initialization.d.ts.map
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/** Site-plugin defaults use the existing activation lifecycle, not the agent-plugin seed store. */
|
|
2
|
+
import { setPluginEnabled } from './activation.js';
|
|
3
|
+
/** Enable approved bundled ids only when NO row exists. Disabled, enabled and quarantined rows
|
|
4
|
+
* remain authoritative. Boot failures are reported individually; activation owns compensation.
|
|
5
|
+
* Composition must serialize this boot initializer with workspace activation changes.
|
|
6
|
+
* @example initializeBundledPlugins({ deps, input: { workspaceId, pluginIds: ['charts-recharts'] } })
|
|
7
|
+
*/
|
|
8
|
+
export async function initializeBundledPlugins({ deps, input }, _options = {}) {
|
|
9
|
+
const enabled = [];
|
|
10
|
+
const skipped = [];
|
|
11
|
+
const failed = [];
|
|
12
|
+
for (const pluginId of new Set(input.pluginIds)) {
|
|
13
|
+
try {
|
|
14
|
+
if (await deps.repo.getActivation({ workspaceId: input.workspaceId, pluginId })) {
|
|
15
|
+
skipped.push(pluginId);
|
|
16
|
+
continue;
|
|
17
|
+
}
|
|
18
|
+
const bundled = deps.discovery.find((record) => record.id === pluginId && record.source === 'built-in');
|
|
19
|
+
if (!bundled) {
|
|
20
|
+
skipped.push(pluginId);
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
await setPluginEnabled({ deps, input: { workspaceId: input.workspaceId, pluginId, enabled: true } });
|
|
24
|
+
enabled.push(pluginId);
|
|
25
|
+
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
failed.push({ pluginId, error });
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return { enabled, skipped, failed };
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=bundled-initialization.js.map
|
package/dist/host/index.d.ts
CHANGED
|
@@ -16,4 +16,6 @@ export * from './uninstall.js';
|
|
|
16
16
|
export * from './source-policy.js';
|
|
17
17
|
export * from './contributions.js';
|
|
18
18
|
export * from './tool-contributions.js';
|
|
19
|
+
export * from './browser-providers.js';
|
|
20
|
+
export * from './bundled-initialization.js';
|
|
19
21
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/host/index.js
CHANGED
|
@@ -16,4 +16,6 @@ export * from './uninstall.js';
|
|
|
16
16
|
export * from './source-policy.js';
|
|
17
17
|
export * from './contributions.js';
|
|
18
18
|
export * from './tool-contributions.js';
|
|
19
|
+
export * from './browser-providers.js';
|
|
20
|
+
export * from './bundled-initialization.js';
|
|
19
21
|
//# 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 BrowserProviderDeclaration } from "./browser-providers.js";
|
|
27
28
|
import { type PluginIdentityExtension } from "@jini-ai/core/plugin-directory";
|
|
28
29
|
import type { HookPoints, ManifestHostPorts } from "./ports.js";
|
|
29
30
|
/** ADR-024 §1 trust-tier vocabulary (1.1.1 REQ-01 fix). Literal encoding reused verbatim from the
|
|
@@ -73,6 +74,8 @@ export interface PluginManifest {
|
|
|
73
74
|
readonly integrity: Readonly<Record<string, string>>;
|
|
74
75
|
/** Parsed-and-stored, UNUSED in v1 (forward-compat, no behavior — state.spec.md §2). */
|
|
75
76
|
readonly adminSurfaces?: readonly unknown[] | null;
|
|
77
|
+
/** Reviewed bundled chart assets only; host admission supplies trust outside this manifest. */
|
|
78
|
+
readonly browserProviders?: readonly BrowserProviderDeclaration[];
|
|
76
79
|
/** Content types the plugin declares (AW-7 Tier 1, 2026-10-04) — no longer unused: validated by
|
|
77
80
|
* `declarative-content-types.ts`, claimed by key (`plugin-claims.ts`), created at enable. */
|
|
78
81
|
readonly contentTypes?: readonly unknown[] | null;
|
package/dist/host/manifest.js
CHANGED
|
@@ -25,6 +25,7 @@
|
|
|
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 { validateBrowserProviders } from "./browser-providers.js";
|
|
28
29
|
import { readPluginIdentity, validatePluginIdentity } from "@jini-ai/core/plugin-directory";
|
|
29
30
|
/**
|
|
30
31
|
* Validates one already-parsed manifest against BR-02 steps (2)-(6), collecting every applicable
|
|
@@ -51,7 +52,7 @@ const REQUIRED_KEYS = [
|
|
|
51
52
|
"integrity",
|
|
52
53
|
];
|
|
53
54
|
/** REQ-01's "parsed-and-stored but unused in v1" forward-compat keys — allowed, never validated. */
|
|
54
|
-
const OPTIONAL_KEYS = ["adminSurfaces", "contentTypes", "provenance", "dependencies", "contributes", "keywords", "extensions"];
|
|
55
|
+
const OPTIONAL_KEYS = ["adminSurfaces", "contentTypes", "provenance", "dependencies", "contributes", "keywords", "extensions", "browserProviders"];
|
|
55
56
|
const ALLOWED_KEYS = new Set([...REQUIRED_KEYS, ...OPTIONAL_KEYS]);
|
|
56
57
|
const VALID_TIERS = new Set(["tier-1", "tier-2", "tier-3"]);
|
|
57
58
|
const VALID_FIELD_TYPES = new Set(["string", "integer", "number", "boolean"]);
|
|
@@ -406,6 +407,7 @@ export function validateManifest(required, _optional = {}) {
|
|
|
406
407
|
...validateHooks(raw, required.pluginSdkBinding.hookIds),
|
|
407
408
|
...validateFields(raw, id),
|
|
408
409
|
...validateContributes(raw, id),
|
|
410
|
+
...validateBrowserProviders({ browserProviders: raw.browserProviders, integrity: typeof raw.integrity === "object" && raw.integrity !== null ? raw.integrity : {} }),
|
|
409
411
|
// AW-7 Tier 1: `contentTypes` grammar and the tier-1 "no code surface" rule.
|
|
410
412
|
...required.declarativeContentTypes.validateManifest({ manifest: raw }).errors,
|
|
411
413
|
];
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type AdmittedBrowserProvider } from '../browser-providers.js';
|
|
2
|
+
import type { PluginManifest } from '../manifest.js';
|
|
3
|
+
import type { PluginDiscoveryRecord } from '../discovery-types.js';
|
|
4
|
+
import type { BundledBrowserProviderApproval } from '../ports.js';
|
|
5
|
+
export type BrowserProviderAdmissionResult = {
|
|
6
|
+
readonly admitted: true;
|
|
7
|
+
readonly providers: readonly AdmittedBrowserProvider[];
|
|
8
|
+
} | {
|
|
9
|
+
readonly admitted: false;
|
|
10
|
+
readonly reason: 'BROWSER_PROVIDER_FORBIDDEN' | 'BROWSER_PROVIDER_INVALID' | 'INTEGRITY_FAILED';
|
|
11
|
+
};
|
|
12
|
+
/** After SDK/integrity checks, admit ONLY reviewed compiled-in chart providers. Use the existing
|
|
13
|
+
* bounded snapshot and integrity owner on retained bytes, then serve those bytes rather than paths.
|
|
14
|
+
* @example admitBrowserProviderAssets({ record, manifest, pluginRoot, approvals: compiledInPins })
|
|
15
|
+
*/
|
|
16
|
+
export declare function admitBrowserProviderAssets({ record, manifest, pluginRoot, approvals }: {
|
|
17
|
+
record: PluginDiscoveryRecord;
|
|
18
|
+
manifest: PluginManifest;
|
|
19
|
+
pluginRoot: string;
|
|
20
|
+
approvals: readonly BundledBrowserProviderApproval[];
|
|
21
|
+
}, _options?: Record<string, never>): Promise<BrowserProviderAdmissionResult>;
|
|
22
|
+
//# sourceMappingURL=browser-provider-assets.d.ts.map
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/** Retained byte admission extends the ordered loader; no second activation or trust store. */
|
|
2
|
+
import { snapshotSitePluginPackage } from './install.js';
|
|
3
|
+
import { verifyPluginSnapshotIntegrity } from './module-snapshot.js';
|
|
4
|
+
import { validateBrowserProviders } from '../browser-providers.js';
|
|
5
|
+
/** Compare review-owned declarations with what the discovered manifest requests. Array order is
|
|
6
|
+
* significant (capability preference); object key order is not. No self-declared trust field exists.
|
|
7
|
+
*/
|
|
8
|
+
function matchesDeclaration(manifest, approval) {
|
|
9
|
+
const requested = manifest.browserProviders ?? [];
|
|
10
|
+
return requested.length === approval.browserProviders.length && requested.every((provider, index) => {
|
|
11
|
+
const pinned = approval.browserProviders[index];
|
|
12
|
+
return provider.id === pinned.id && provider.kind === pinned.kind && provider.contractVersion === pinned.contractVersion
|
|
13
|
+
&& provider.javascript === pinned.javascript && provider.stylesheet === pinned.stylesheet
|
|
14
|
+
&& JSON.stringify(provider.kinds) === JSON.stringify(pinned.kinds);
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
/** A closure retains its own copy; neither the returned metadata nor a caller's bytes can mutate it. */
|
|
18
|
+
function retainedAsset(path, bytes, digest, contentType) {
|
|
19
|
+
const retained = Uint8Array.from(bytes);
|
|
20
|
+
return Object.freeze({ path, digest, contentType, readBytes: (_input, _options = {}) => retained.slice() });
|
|
21
|
+
}
|
|
22
|
+
/** After SDK/integrity checks, admit ONLY reviewed compiled-in chart providers. Use the existing
|
|
23
|
+
* bounded snapshot and integrity owner on retained bytes, then serve those bytes rather than paths.
|
|
24
|
+
* @example admitBrowserProviderAssets({ record, manifest, pluginRoot, approvals: compiledInPins })
|
|
25
|
+
*/
|
|
26
|
+
export async function admitBrowserProviderAssets({ record, manifest, pluginRoot, approvals }, _options = {}) {
|
|
27
|
+
if (validateBrowserProviders({ browserProviders: manifest.browserProviders, integrity: manifest.integrity }).length)
|
|
28
|
+
return { admitted: false, reason: 'BROWSER_PROVIDER_INVALID' };
|
|
29
|
+
const approval = approvals.find((approval) => approval.pluginId === record.id && approval.version === manifest.version);
|
|
30
|
+
if (record.source !== 'built-in' || !approval || !matchesDeclaration(manifest, approval))
|
|
31
|
+
return { admitted: false, reason: 'BROWSER_PROVIDER_FORBIDDEN' };
|
|
32
|
+
// The manifest may not replace the reviewed digests, even with a self-consistent tampered map.
|
|
33
|
+
if (Object.keys(manifest.integrity).length !== Object.keys(approval.integrity).length || Object.entries(approval.integrity).some(([file, digest]) => manifest.integrity[file] !== digest))
|
|
34
|
+
return { admitted: false, reason: 'INTEGRITY_FAILED' };
|
|
35
|
+
try {
|
|
36
|
+
const files = await snapshotSitePluginPackage({ sourceDir: pluginRoot });
|
|
37
|
+
verifyPluginSnapshotIntegrity({ files, integrity: approval.integrity });
|
|
38
|
+
const providers = (manifest.browserProviders ?? []).map((declaration) => {
|
|
39
|
+
const paths = [declaration.javascript, ...(declaration.stylesheet ? [declaration.stylesheet] : [])];
|
|
40
|
+
const assets = paths.map((file) => retainedAsset(file, files.get(file), approval.integrity[file], file.endsWith('.css') ? 'text/css' : 'text/javascript'));
|
|
41
|
+
return Object.freeze({ pluginId: record.id, version: manifest.version,
|
|
42
|
+
declaration: Object.freeze({ ...declaration, kinds: Object.freeze([...declaration.kinds]) }), assets: Object.freeze(assets) });
|
|
43
|
+
});
|
|
44
|
+
return { admitted: true, providers: Object.freeze(providers) };
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
return { admitted: false, reason: 'INTEGRITY_FAILED' };
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=browser-provider-assets.js.map
|
package/dist/host/node/index.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { type AdmittedBrowserProvider } from "../browser-providers.js";
|
|
2
|
+
import type { BundledBrowserProviderApproval } from "../ports.js";
|
|
1
3
|
import { type CapabilityScopedSdkCoreDeps } from "../capability-sdk.js";
|
|
2
4
|
import type { PluginDiscoveryRecord } from "../discovery-types.js";
|
|
3
5
|
import type { PluginManifest } from "../manifest.js";
|
|
@@ -20,9 +22,11 @@ export interface LoadPluginRequired<H extends HookPoints = HookPoints> {
|
|
|
20
22
|
* module and therefore owns building the capability-scoped SDK passed to its `setup()` call;
|
|
21
23
|
* the root owns what each granted handle actually delegates to. */
|
|
22
24
|
readonly coreDeps: CapabilityScopedSdkCoreDeps;
|
|
25
|
+
/** Compiled-in review records; absent means all browser providers are refused. */
|
|
26
|
+
readonly browserProviderApprovals?: readonly BundledBrowserProviderApproval[];
|
|
23
27
|
}
|
|
24
28
|
export type LoadPluginOptional = Record<string, never>;
|
|
25
|
-
export type PluginLoadFailureReason = "INTEGRITY_FAILED" | "SDK_RANGE_UNSATISFIED" | "CODE_ENTRY_MISSING" | "PLUGIN_EXPORT_INVALID" | "PLUGIN_SETUP_FAILED";
|
|
29
|
+
export type PluginLoadFailureReason = "INTEGRITY_FAILED" | "SDK_RANGE_UNSATISFIED" | "CODE_ENTRY_MISSING" | "PLUGIN_EXPORT_INVALID" | "PLUGIN_SETUP_FAILED" | "BROWSER_PROVIDER_FORBIDDEN" | "BROWSER_PROVIDER_INVALID";
|
|
26
30
|
export type PluginEnableFailureReason = PluginLoadFailureReason | "PLUGIN_HOOK_NOT_ATTACHED" | "PLUGIN_HOOK_ATTACH_FAILED";
|
|
27
31
|
/** Raised by the composition root after converting `loadPlugin()`'s expected early-return result
|
|
28
32
|
* into the enable path's error channel. HTTP maps this to `PLUGIN_LOAD_FAILED`; agent tools receive
|
|
@@ -36,6 +40,7 @@ export declare class PluginLoadError extends Error {
|
|
|
36
40
|
}
|
|
37
41
|
export type LoadPluginResult = {
|
|
38
42
|
readonly loaded: true;
|
|
43
|
+
readonly browserProviders?: readonly AdmittedBrowserProvider[];
|
|
39
44
|
} | {
|
|
40
45
|
readonly loaded: false;
|
|
41
46
|
readonly reason: PluginLoadFailureReason;
|
package/dist/host/node/loader.js
CHANGED
|
@@ -19,6 +19,8 @@
|
|
|
19
19
|
*/
|
|
20
20
|
import { PluginSnapshotIntegrityError } from "./module-snapshot.js";
|
|
21
21
|
import path from "node:path";
|
|
22
|
+
import { admitBrowserProviderAssets } from "./browser-provider-assets.js";
|
|
23
|
+
import { isPluginRelativePath } from "../browser-providers.js";
|
|
22
24
|
import * as semver from "semver";
|
|
23
25
|
import { buildCapabilityScopedSdk } from "../capability-sdk.js";
|
|
24
26
|
export { attachLoadedPlugin } from "../attach-loaded-plugin.js";
|
|
@@ -81,6 +83,8 @@ export async function loadPlugin(required, _optional = {}) {
|
|
|
81
83
|
return { loaded: false, reason: "INTEGRITY_FAILED" };
|
|
82
84
|
}
|
|
83
85
|
for (const [relativeFilePath, expectedHash] of Object.entries(manifest.integrity)) {
|
|
86
|
+
if (!isPluginRelativePath({ path: relativeFilePath }))
|
|
87
|
+
return { loaded: false, reason: "INTEGRITY_FAILED" };
|
|
84
88
|
let actualHash;
|
|
85
89
|
try {
|
|
86
90
|
actualHash = await computeFileHash(path.join(pluginRoot, relativeFilePath));
|
|
@@ -96,10 +100,17 @@ export async function loadPlugin(required, _optional = {}) {
|
|
|
96
100
|
if (!semver.satisfies(runtimeSdkVersion, manifest.sdkRange)) {
|
|
97
101
|
return { loaded: false, reason: "SDK_RANGE_UNSATISFIED" };
|
|
98
102
|
}
|
|
103
|
+
let browserProviders;
|
|
104
|
+
if (manifest.browserProviders?.length) {
|
|
105
|
+
const admission = await admitBrowserProviderAssets({ record, manifest, pluginRoot, approvals: required.browserProviderApprovals ?? [] });
|
|
106
|
+
if (!admission.admitted)
|
|
107
|
+
return { loaded: false, reason: admission.reason };
|
|
108
|
+
browserProviders = admission.providers;
|
|
109
|
+
}
|
|
99
110
|
// Declarative plugins never reach an executable importer. A worker port is mandatory for tier-2,
|
|
100
111
|
// and tier-3 must be admitted explicitly by the host (CMS-JINI-MODULAR-DESIGN Rev 3 §5).
|
|
101
112
|
if (manifest.tier === "tier-1")
|
|
102
|
-
return { loaded: true };
|
|
113
|
+
return { loaded: true, ...(browserProviders ? { browserProviders } : {}) };
|
|
103
114
|
if ((manifest.tier === "tier-2" && tierPolicy.execution !== "worker") || !tierPolicy.allowLoad({ record, manifest })) {
|
|
104
115
|
return { loaded: false, reason: "CODE_ENTRY_MISSING" };
|
|
105
116
|
}
|
|
@@ -141,6 +152,6 @@ export async function loadPlugin(required, _optional = {}) {
|
|
|
141
152
|
// the caller's `coreDeps`; only after this successful return does the root call the shared
|
|
142
153
|
// `attachLoadedPlugin()` path below. That split prevents a late setup failure from leaving a
|
|
143
154
|
// partially-attached filter behind.
|
|
144
|
-
return { loaded: true };
|
|
155
|
+
return { loaded: true, ...(browserProviders ? { browserProviders } : {}) };
|
|
145
156
|
}
|
|
146
157
|
//# sourceMappingURL=loader.js.map
|
|
@@ -22,4 +22,11 @@ export declare function snapshotPluginModuleGraph(required: {
|
|
|
22
22
|
}, { writeSnapshotFile }?: {
|
|
23
23
|
writeSnapshotFile?: typeof writeFile;
|
|
24
24
|
}): Promise<string>;
|
|
25
|
+
/** The package integrity owner, shared by executable snapshots and retained browser assets.
|
|
26
|
+
* @throws {PluginSnapshotIntegrityError} A retained file differs from a reviewed digest or is missing.
|
|
27
|
+
*/
|
|
28
|
+
export declare function verifyPluginSnapshotIntegrity(required: {
|
|
29
|
+
files: ReadonlyMap<string, Uint8Array>;
|
|
30
|
+
integrity: Readonly<Record<string, string>>;
|
|
31
|
+
}, _options?: Record<string, never>): void;
|
|
25
32
|
//# sourceMappingURL=module-snapshot.d.ts.map
|
|
@@ -20,17 +20,7 @@ export class PluginSnapshotIntegrityError extends Error {
|
|
|
20
20
|
*/
|
|
21
21
|
export async function snapshotPluginModuleGraph(required, { writeSnapshotFile = writeFile } = {}) {
|
|
22
22
|
const files = await snapshotSitePluginPackage({ sourceDir: required.pluginRoot });
|
|
23
|
-
|
|
24
|
-
if (key === "tovu.plugin.json")
|
|
25
|
-
continue;
|
|
26
|
-
const digest = `sha256-${createHash("sha256").update(bytes).digest("hex")}`;
|
|
27
|
-
if (required.manifest.integrity[key] !== digest)
|
|
28
|
-
throw new PluginSnapshotIntegrityError("Package changed before loading.");
|
|
29
|
-
}
|
|
30
|
-
for (const key of Object.keys(required.manifest.integrity)) {
|
|
31
|
-
if (!files.has(key))
|
|
32
|
-
throw new PluginSnapshotIntegrityError("Package file disappeared before loading.");
|
|
33
|
-
}
|
|
23
|
+
verifyPluginSnapshotIntegrity({ files, integrity: required.manifest.integrity });
|
|
34
24
|
const cacheRoot = path.dirname(path.dirname(required.pluginRoot)) + "-runtime";
|
|
35
25
|
await mkdir(cacheRoot, { recursive: true, mode: 0o700 });
|
|
36
26
|
const info = await lstat(cacheRoot);
|
|
@@ -50,4 +40,21 @@ export async function snapshotPluginModuleGraph(required, { writeSnapshotFile =
|
|
|
50
40
|
throw error;
|
|
51
41
|
}
|
|
52
42
|
}
|
|
43
|
+
/** The package integrity owner, shared by executable snapshots and retained browser assets.
|
|
44
|
+
* @throws {PluginSnapshotIntegrityError} A retained file differs from a reviewed digest or is missing.
|
|
45
|
+
*/
|
|
46
|
+
export function verifyPluginSnapshotIntegrity(required, _options = {}) {
|
|
47
|
+
const { files, integrity } = required;
|
|
48
|
+
for (const [key, bytes] of files) {
|
|
49
|
+
if (key === "tovu.plugin.json")
|
|
50
|
+
continue;
|
|
51
|
+
const digest = `sha256-${createHash("sha256").update(bytes).digest("hex")}`;
|
|
52
|
+
if (integrity[key] !== digest)
|
|
53
|
+
throw new PluginSnapshotIntegrityError("Package changed before loading.");
|
|
54
|
+
}
|
|
55
|
+
for (const key of Object.keys(integrity)) {
|
|
56
|
+
if (!files.has(key))
|
|
57
|
+
throw new PluginSnapshotIntegrityError("Package file disappeared before loading.");
|
|
58
|
+
}
|
|
59
|
+
}
|
|
53
60
|
//# sourceMappingURL=module-snapshot.js.map
|
|
@@ -70,6 +70,12 @@ export interface PluginSourcePort {
|
|
|
70
70
|
isSealedHere(required: Id & {
|
|
71
71
|
version: string;
|
|
72
72
|
}, optional?: Options): Promise<boolean>;
|
|
73
|
+
/** The capability set (`pluginCapabilitySet`) the owner last approved for this id, if any. */
|
|
74
|
+
readApproval(required: Id, optional?: Options): Promise<readonly string[] | undefined>;
|
|
75
|
+
/** Host-only: called after the owner confirmed an enable. Never exposed as a model tool. */
|
|
76
|
+
recordApproval(required: Id & {
|
|
77
|
+
capabilities: readonly string[];
|
|
78
|
+
}, optional?: Options): Promise<void>;
|
|
73
79
|
}
|
|
74
80
|
export interface PluginSourceDeps extends ManifestHostPorts {
|
|
75
81
|
readonly installDir: string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/** Site-scoped source authoring. Drafts never enter discovery; publication belongs to the
|
|
2
2
|
* existing installer. Node filesystem effects live here, host SDK/policy/reload stay ports. */
|
|
3
|
-
import { lstat, mkdir, mkdtemp, readdir, rename, rm, writeFile, unlink } from 'node:fs/promises';
|
|
3
|
+
import { lstat, mkdir, mkdtemp, readdir, readFile, rename, rm, writeFile, unlink } from 'node:fs/promises';
|
|
4
4
|
import path from 'node:path';
|
|
5
5
|
import { tmpdir } from 'node:os';
|
|
6
6
|
import * as semver from 'semver';
|
|
@@ -86,6 +86,9 @@ export function createPluginSourceService(required, optional = {}) {
|
|
|
86
86
|
const drafts = path.join(root, '.drafts');
|
|
87
87
|
const draft = (id) => path.join(drafts, id);
|
|
88
88
|
const marker = (id, version) => path.join(drafts, '.sealed', id, version, 'digest.json');
|
|
89
|
+
// Beside the per-version provenance markers, so version pruning never removes it and no draft
|
|
90
|
+
// path (ids cannot start with '.') can write it. Per site: one approval covers every workspace.
|
|
91
|
+
const approval = (id) => path.join(drafts, '.sealed', id, 'approved.json');
|
|
89
92
|
/** Cross-process source lock serializes edits with seal snapshots. Installer keeps its own
|
|
90
93
|
* publication lock. Platform records pid/time and reclaims only dead owners; age alone must
|
|
91
94
|
* never steal a long seal from a live process. Token-owned release preserves a replacement. */
|
|
@@ -318,6 +321,29 @@ export function createPluginSourceService(required, optional = {}) {
|
|
|
318
321
|
const digest = JSON.parse(markers.get(path.basename(provenance)).toString('utf8')).digest;
|
|
319
322
|
return digest === digestSitePluginSnapshot({ files: await snapshot(path.join(root, id, version)) });
|
|
320
323
|
},
|
|
324
|
+
// Lock-free like isSealedHere: rename-published, and enabling during a seal must not fail BUSY.
|
|
325
|
+
readApproval: async ({ id }, _options = {}) => {
|
|
326
|
+
safeId(id);
|
|
327
|
+
if (!await exists(root))
|
|
328
|
+
return undefined;
|
|
329
|
+
await confined(root, approval(id));
|
|
330
|
+
if (!await exists(approval(id)))
|
|
331
|
+
return undefined;
|
|
332
|
+
// A damaged record means "not approved": the owner is simply asked again.
|
|
333
|
+
let parsed;
|
|
334
|
+
try {
|
|
335
|
+
parsed = JSON.parse(await readFile(approval(id), 'utf8')).capabilities;
|
|
336
|
+
}
|
|
337
|
+
catch {
|
|
338
|
+
return undefined;
|
|
339
|
+
}
|
|
340
|
+
return Array.isArray(parsed) && parsed.every(entry => typeof entry === 'string') ? parsed : undefined;
|
|
341
|
+
},
|
|
342
|
+
recordApproval: async ({ id, capabilities }, _options = {}) => {
|
|
343
|
+
safeId(id);
|
|
344
|
+
await mkdir(root, { recursive: true });
|
|
345
|
+
await writeAtomic(root, approval(id), jsonBytes({ capabilities: [...capabilities] }));
|
|
346
|
+
},
|
|
321
347
|
};
|
|
322
348
|
}
|
|
323
349
|
//# sourceMappingURL=source-drafts.js.map
|
package/dist/host/ports.d.ts
CHANGED
|
@@ -205,4 +205,12 @@ export type RemoveEntity = (required: {
|
|
|
205
205
|
code: string;
|
|
206
206
|
count: number;
|
|
207
207
|
}>;
|
|
208
|
+
/** Review-owned pins supplied by a compiled-in composition source. Never construct these from an
|
|
209
|
+
* installed/custom/marketplace manifest; declaring a tier or provider cannot grant browser trust. */
|
|
210
|
+
export interface BundledBrowserProviderApproval {
|
|
211
|
+
readonly pluginId: string;
|
|
212
|
+
readonly version: string;
|
|
213
|
+
readonly browserProviders: readonly import('./browser-providers.js').BrowserProviderDeclaration[];
|
|
214
|
+
readonly integrity: Readonly<Record<string, string>>;
|
|
215
|
+
}
|
|
208
216
|
//# sourceMappingURL=ports.d.ts.map
|
|
@@ -1,11 +1,17 @@
|
|
|
1
|
+
import type { PluginManifest } from "./manifest.js";
|
|
1
2
|
/** Host-injected deployment policy. Environment interpretation belongs to composition adapters. */
|
|
2
3
|
export interface PluginSourcePolicyPort {
|
|
3
4
|
localInstallEnabled(required?: Record<string, never>, optional?: Record<string, never>): boolean;
|
|
5
|
+
/** `added` is what this version declares beyond the owner's last approval (see `addedPluginCapabilities`). */
|
|
4
6
|
confirmEnable(required: {
|
|
5
7
|
sealedHere: boolean;
|
|
8
|
+
added: readonly string[];
|
|
6
9
|
}, optional?: Record<string, never>): boolean;
|
|
7
10
|
}
|
|
8
11
|
/** Local authoring runs directly; hosted sideloading retains the host's explicit opt-in.
|
|
12
|
+
* Enabling asks the owner unless the package was sealed on this site AND adds nothing beyond the
|
|
13
|
+
* owner's last approval. Tier-3 code runs in-process with full server authority, so "sealed here"
|
|
14
|
+
* (possibly by the assistant itself) is never consent on its own (owner, 2026-10-12).
|
|
9
15
|
* @param required Deployment facts supplied by the host.
|
|
10
16
|
* @param _optional Reserved factory options.
|
|
11
17
|
* @returns The shared install/enable policy, with no environment reads.
|
|
@@ -15,4 +21,18 @@ export declare function createPluginSourcePolicy(required: {
|
|
|
15
21
|
hosted: boolean;
|
|
16
22
|
localInstallOptIn: boolean;
|
|
17
23
|
}, _optional?: {}): PluginSourcePolicyPort;
|
|
24
|
+
/** Everything a manifest lets the plugin reach, as stable `kind:name` entries. Code may change
|
|
25
|
+
* freely between versions without re-asking; only a new entry here is a widening. The tier is an
|
|
26
|
+
* entry so a tier-1 package that becomes tier-3 (code execution) counts as widened.
|
|
27
|
+
* @complexity O(n log n) in the number of declared entries.
|
|
28
|
+
*/
|
|
29
|
+
export declare function pluginCapabilitySet({ manifest }: {
|
|
30
|
+
manifest: Pick<PluginManifest, "tier" | "capabilities" | "hooks" | "fields" | "contentTypes" | "contributes">;
|
|
31
|
+
}, _optional?: {}): readonly string[];
|
|
32
|
+
/** Entries of `next` absent from `approved`; with no approval on record, all of `next`.
|
|
33
|
+
* @complexity O(n + m). */
|
|
34
|
+
export declare function addedPluginCapabilities({ approved, next }: {
|
|
35
|
+
approved: readonly string[] | undefined;
|
|
36
|
+
next: readonly string[];
|
|
37
|
+
}, _optional?: {}): readonly string[];
|
|
18
38
|
//# sourceMappingURL=source-policy.d.ts.map
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
/** Local authoring runs directly; hosted sideloading retains the host's explicit opt-in.
|
|
2
|
+
* Enabling asks the owner unless the package was sealed on this site AND adds nothing beyond the
|
|
3
|
+
* owner's last approval. Tier-3 code runs in-process with full server authority, so "sealed here"
|
|
4
|
+
* (possibly by the assistant itself) is never consent on its own (owner, 2026-10-12).
|
|
2
5
|
* @param required Deployment facts supplied by the host.
|
|
3
6
|
* @param _optional Reserved factory options.
|
|
4
7
|
* @returns The shared install/enable policy, with no environment reads.
|
|
@@ -7,7 +10,33 @@
|
|
|
7
10
|
export function createPluginSourcePolicy(required, _optional = {}) {
|
|
8
11
|
return {
|
|
9
12
|
localInstallEnabled: (_required = {}, _optional = {}) => !required.hosted || required.localInstallOptIn,
|
|
10
|
-
confirmEnable: ({ sealedHere }, _optional = {}) => !sealedHere,
|
|
13
|
+
confirmEnable: ({ sealedHere, added }, _optional = {}) => !sealedHere || added.length > 0,
|
|
11
14
|
};
|
|
12
15
|
}
|
|
16
|
+
/** Everything a manifest lets the plugin reach, as stable `kind:name` entries. Code may change
|
|
17
|
+
* freely between versions without re-asking; only a new entry here is a widening. The tier is an
|
|
18
|
+
* entry so a tier-1 package that becomes tier-3 (code execution) counts as widened.
|
|
19
|
+
* @complexity O(n log n) in the number of declared entries.
|
|
20
|
+
*/
|
|
21
|
+
export function pluginCapabilitySet({ manifest }, _optional = {}) {
|
|
22
|
+
const contributes = manifest.contributes ?? {};
|
|
23
|
+
const contentTypeName = (entry) => typeof entry?.key === "string" ? entry.key : JSON.stringify(entry);
|
|
24
|
+
return [...new Set([
|
|
25
|
+
`tier:${manifest.tier}`,
|
|
26
|
+
...manifest.capabilities.map(name => `capability:${name}`),
|
|
27
|
+
...manifest.hooks.map(name => `hook:${name}`),
|
|
28
|
+
...manifest.fields.map(field => `field:${field.path}`),
|
|
29
|
+
...(manifest.contentTypes ?? []).map(entry => `content-type:${contentTypeName(entry)}`),
|
|
30
|
+
...["routes", "tools", "tables", "settings", "widgets", "permissions"]
|
|
31
|
+
.flatMap(kind => (contributes[kind] ?? []).map(name => `${kind.slice(0, -1)}:${name}`)),
|
|
32
|
+
])].sort();
|
|
33
|
+
}
|
|
34
|
+
/** Entries of `next` absent from `approved`; with no approval on record, all of `next`.
|
|
35
|
+
* @complexity O(n + m). */
|
|
36
|
+
export function addedPluginCapabilities({ approved, next }, _optional = {}) {
|
|
37
|
+
if (approved === undefined)
|
|
38
|
+
return next;
|
|
39
|
+
const known = new Set(approved);
|
|
40
|
+
return next.filter(entry => !known.has(entry));
|
|
41
|
+
}
|
|
13
42
|
//# sourceMappingURL=source-policy.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jini-ai/plugins",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Host-independent extension glue and site-plugin runtime with injected SDK, trust, archive and storage ports.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -72,7 +72,7 @@
|
|
|
72
72
|
"registry": "https://registry.npmjs.org"
|
|
73
73
|
},
|
|
74
74
|
"dependencies": {
|
|
75
|
-
"@jini-ai/core": "^0.4.
|
|
75
|
+
"@jini-ai/core": "^0.4.4"
|
|
76
76
|
},
|
|
77
77
|
"peerDependencies": {
|
|
78
78
|
"@jini-ai/platform": "^0.5.3",
|
|
@@ -98,9 +98,9 @@
|
|
|
98
98
|
"semver": "^7.6.2",
|
|
99
99
|
"@types/semver": "^7.5.8",
|
|
100
100
|
"kysely": "^0.29.6",
|
|
101
|
-
"@jini-ai/core": "^0.4.
|
|
102
|
-
"@jini-ai/platform": "^0.5.
|
|
103
|
-
"@jini-ai/db": "0.3.
|
|
101
|
+
"@jini-ai/core": "^0.4.4",
|
|
102
|
+
"@jini-ai/platform": "^0.5.6",
|
|
103
|
+
"@jini-ai/db": "0.3.4"
|
|
104
104
|
},
|
|
105
105
|
"scripts": {
|
|
106
106
|
"build": "tsc -p tsconfig.json",
|