@jini-ai/plugins 0.4.0 → 0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,42 @@
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).
5
+ * @param required Deployment facts supplied by the host.
6
+ * @param _optional Reserved factory options.
7
+ * @returns The shared install/enable policy, with no environment reads.
8
+ * @example createPluginSourcePolicy({ hosted: false, localInstallOptIn: false }, {})
9
+ */
10
+ export function createPluginSourcePolicy(required, _optional = {}) {
11
+ return {
12
+ localInstallEnabled: (_required = {}, _optional = {}) => !required.hosted || required.localInstallOptIn,
13
+ confirmEnable: ({ sealedHere, added }, _optional = {}) => !sealedHere || added.length > 0,
14
+ };
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
+ }
42
+ //# sourceMappingURL=source-policy.js.map
@@ -0,0 +1,26 @@
1
+ /** Projects executable plugins onto the host's existing ToolRegistry. Metadata/auth are host
2
+ * ports; no separate catalog, executor, permission vocabulary, or approval engine is created. */
3
+ import { type ToolRegistry, type ToolRegistration, type ToolMetadata } from '@jini-ai/core';
4
+ import { type PluginContributionRegistry, type PluginAuthContext } from './contributions.js';
5
+ export interface PluginToolContributionPorts {
6
+ readonly contributions: PluginContributionRegistry;
7
+ readonly isEnabled: (required: {
8
+ pluginId: string;
9
+ }, optional?: Record<string, never>) => Promise<boolean>;
10
+ readonly resolveAuth: (required: {
11
+ pluginId: string;
12
+ principalId: string;
13
+ }, optional?: Record<string, never>) => Promise<PluginAuthContext | null>;
14
+ readonly metadata: ToolMetadata;
15
+ }
16
+ /** Generation + durable activation are checked before authorization and after confirmation.
17
+ * Arbitrary tier-3 handlers cannot establish read-only safety; the host supplies approval policy. */
18
+ export declare function buildPluginContributionToolRegistrations(required: PluginToolContributionPorts, _optional?: Record<string, never>): ToolRegistration[];
19
+ /** Host lifecycle attaches one revocable scope to its existing registry. Disposal removes only
20
+ * this scope's tools and subscription. A failed replacement leaves the previous generation. */
21
+ export declare function attachPluginContributionTools(required: PluginToolContributionPorts & {
22
+ registry: ToolRegistry;
23
+ }, _optional?: Record<string, never>): {
24
+ dispose(_required: Record<string, never>, _optional?: Record<string, never>): void;
25
+ };
26
+ //# sourceMappingURL=tool-contributions.d.ts.map
@@ -0,0 +1,42 @@
1
+ /** Projects executable plugins onto the host's existing ToolRegistry. Metadata/auth are host
2
+ * ports; no separate catalog, executor, permission vocabulary, or approval engine is created. */
3
+ import { createToolRegistrationScope, requireInputRecord, ToolInputError } from '@jini-ai/core';
4
+ import { pluginToolIdFor } from './contributions.js';
5
+ /** Generation + durable activation are checked before authorization and after confirmation.
6
+ * Arbitrary tier-3 handlers cannot establish read-only safety; the host supplies approval policy. */
7
+ export function buildPluginContributionToolRegistrations(required, _optional = {}) {
8
+ const { contributions } = required;
9
+ return contributions.list({}).flatMap(snapshot => snapshot.tools.map(tool => {
10
+ const active = async () => await required.isEnabled({ pluginId: snapshot.pluginId }) && contributions.list({}).includes(snapshot);
11
+ return {
12
+ descriptor: {
13
+ id: pluginToolIdFor({ pluginId: snapshot.pluginId, name: tool.name }), description: tool.description,
14
+ inputSchema: tool.inputSchema, readOnly: false, requiresConfirmation: required.metadata.approval?.confirmation !== 'direct',
15
+ timeoutMs: 30000, maxOutputBytes: 65536, metadata: required.metadata,
16
+ },
17
+ policy: { authorize: async (ctx) => {
18
+ if (!await active())
19
+ return 'deny';
20
+ const auth = await required.resolveAuth({ pluginId: snapshot.pluginId, principalId: ctx.principal.id });
21
+ return auth && await active() ? 'allow' : 'deny';
22
+ } },
23
+ handler: async (ctx) => {
24
+ const auth = await required.resolveAuth({ pluginId: snapshot.pluginId, principalId: ctx.principal.id });
25
+ if (!auth || !await active())
26
+ throw new ToolInputError({ message: 'Plugin tool is disabled or was reloaded.' });
27
+ const input = requireInputRecord({ input: ctx.input });
28
+ return tool.handler({ pluginId: snapshot.pluginId, sdk: snapshot.sdk, auth, input, signal: ctx.signal }, {});
29
+ },
30
+ };
31
+ }));
32
+ }
33
+ /** Host lifecycle attaches one revocable scope to its existing registry. Disposal removes only
34
+ * this scope's tools and subscription. A failed replacement leaves the previous generation. */
35
+ export function attachPluginContributionTools(required, _optional = {}) {
36
+ const scope = createToolRegistrationScope({ registry: required.registry });
37
+ const refresh = () => scope.replace({ registrations: buildPluginContributionToolRegistrations(required) });
38
+ refresh();
39
+ const unsubscribe = required.contributions.subscribe({ onChanged: refresh });
40
+ return { dispose(_required, _optional = {}) { unsubscribe(); scope.replace({ registrations: [] }); } };
41
+ }
42
+ //# sourceMappingURL=tool-contributions.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jini-ai/plugins",
3
- "version": "0.4.0",
3
+ "version": "0.4.2",
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,14 +72,18 @@
72
72
  "registry": "https://registry.npmjs.org"
73
73
  },
74
74
  "dependencies": {
75
- "@jini-ai/core": "^0.4.2"
75
+ "@jini-ai/core": "^0.4.3"
76
76
  },
77
77
  "peerDependencies": {
78
+ "@jini-ai/platform": "^0.5.3",
78
79
  "semver": "^7.6.2",
79
80
  "kysely": "^0.29.6",
80
- "@jini-ai/db": "^0.3.0"
81
+ "@jini-ai/db": "^0.3.2"
81
82
  },
82
83
  "peerDependenciesMeta": {
84
+ "@jini-ai/platform": {
85
+ "optional": true
86
+ },
83
87
  "semver": {
84
88
  "optional": true
85
89
  },
@@ -94,8 +98,9 @@
94
98
  "semver": "^7.6.2",
95
99
  "@types/semver": "^7.5.8",
96
100
  "kysely": "^0.29.6",
97
- "@jini-ai/db": "0.3.1",
98
- "@jini-ai/core": "^0.4.2"
101
+ "@jini-ai/core": "^0.4.3",
102
+ "@jini-ai/platform": "^0.5.3",
103
+ "@jini-ai/db": "0.3.2"
99
104
  },
100
105
  "scripts": {
101
106
  "build": "tsc -p tsconfig.json",