@jini-ai/plugins 0.6.22 → 0.7.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 +47 -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,95 @@
|
|
|
1
|
+
import { adaptLegacyAuthorize, requireToolPermission, buildDomainRegistrations, indexCatalogById, requireInputRecord, requireString, ToolInputError } from '@jini-ai/core';
|
|
2
|
+
import { PluginInstallError, PluginSourceError } from '../plugin-tool-errors.js';
|
|
3
|
+
const MUTATES_DURABLE_STATE = 'mutates-durable-state';
|
|
4
|
+
/** Reads one required string field, naming it when the caller sent something else. */
|
|
5
|
+
function stringField(required) {
|
|
6
|
+
const value = required.input[required.key];
|
|
7
|
+
if (typeof value !== 'string')
|
|
8
|
+
throw new ToolInputError({ message: `${required.key} must be a string.` });
|
|
9
|
+
return value;
|
|
10
|
+
}
|
|
11
|
+
/** One port call per non-confirming source tool; fields are read in argument order. */
|
|
12
|
+
function sourceOperations(toolIds) {
|
|
13
|
+
return {
|
|
14
|
+
[toolIds.create]: ({ port, pluginId, input }) => port.create({ id: pluginId, name: stringField({ input, key: 'name' }), description: stringField({ input, key: 'description' }) }, {}),
|
|
15
|
+
[toolIds.open]: ({ port, pluginId }) => port.open({ id: pluginId }, {}),
|
|
16
|
+
[toolIds.list]: ({ port, pluginId }) => port.list({ id: pluginId }, {}),
|
|
17
|
+
[toolIds.read]: ({ port, pluginId, input }) => port.read({ id: pluginId, path: stringField({ input, key: 'path' }) }, {}),
|
|
18
|
+
[toolIds.write]: ({ port, pluginId, input }) => port.write({ id: pluginId, path: stringField({ input, key: 'path' }), content: stringField({ input, key: 'content' }) }, {}),
|
|
19
|
+
[toolIds.edit]: ({ port, pluginId, input }) => {
|
|
20
|
+
if (input.replaceAll !== undefined && typeof input.replaceAll !== 'boolean')
|
|
21
|
+
throw new ToolInputError({ message: 'replaceAll must be a boolean.' });
|
|
22
|
+
return port.edit({ id: pluginId, path: stringField({ input, key: 'path' }), oldString: stringField({ input, key: 'oldString' }), newString: stringField({ input, key: 'newString' }), ...(input.replaceAll === undefined ? {} : { replaceAll: input.replaceAll }) }, {});
|
|
23
|
+
},
|
|
24
|
+
[toolIds.seal]: ({ port, pluginId }) => port.seal({ id: pluginId }, {}),
|
|
25
|
+
[toolIds.rollback]: ({ port, pluginId }) => port.rollback({ id: pluginId }, {}),
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
/** Bind authenticated chat operations to the existing source owner and shared approval transport.
|
|
29
|
+
* @param required Narrow site deps and human exchange transport.
|
|
30
|
+
* @param _optional Reserved registration options.
|
|
31
|
+
* @returns Complete registrations; typed source/install refusals become actionable input errors.
|
|
32
|
+
*/
|
|
33
|
+
export function buildPluginSourceRegistrations(deps, _optional = {}) {
|
|
34
|
+
const operations = sourceOperations(deps.toolIds);
|
|
35
|
+
async function authorize(ctx, permission) {
|
|
36
|
+
await requireToolPermission({ authorize: adaptLegacyAuthorize({ authorize: deps.authorize }), workspaceId: deps.workspaceId, principalId: ctx.principal.id, permission }, { entityType: deps.entityType });
|
|
37
|
+
}
|
|
38
|
+
function source() {
|
|
39
|
+
if (!deps.pluginSource)
|
|
40
|
+
throw new ToolInputError({ message: 'Site plugin source authoring is unavailable: this site has no plugin directory.' });
|
|
41
|
+
return deps.pluginSource;
|
|
42
|
+
}
|
|
43
|
+
async function relay(run) {
|
|
44
|
+
try {
|
|
45
|
+
return await run();
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
if (error instanceof PluginSourceError || error instanceof PluginInstallError)
|
|
49
|
+
throw new ToolInputError({ message: `${error.code}: ${error.message}` });
|
|
50
|
+
throw error;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
const handlers = {};
|
|
54
|
+
for (const tool of deps.registration.catalog) {
|
|
55
|
+
const operation = operations[tool.name];
|
|
56
|
+
// Source deletion has no direct operation: its approval handler is bound below.
|
|
57
|
+
if (!operation)
|
|
58
|
+
continue;
|
|
59
|
+
handlers[tool.name] = async (ctx) => {
|
|
60
|
+
await authorize(ctx, tool.authorization.permission);
|
|
61
|
+
const input = requireInputRecord({ input: ctx.input });
|
|
62
|
+
const pluginId = requireString({ input, key: 'id' });
|
|
63
|
+
// The port is resolved before any field is read, so a missing owner is reported first.
|
|
64
|
+
return relay(async () => operation({ port: source(), pluginId, input }));
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
// Only permanent source-file deletion asks. The approved file text is pinned across the wait;
|
|
68
|
+
// neither the model's input nor a later draft edit can stand in for human approval.
|
|
69
|
+
handlers[deps.toolIds.delete] = deps.approvals.handler({
|
|
70
|
+
prepare: async ({ ctx }) => {
|
|
71
|
+
await authorize(ctx, deps.enablePermission);
|
|
72
|
+
const input = requireInputRecord({ input: ctx.input });
|
|
73
|
+
const target = { id: requireString({ input, key: 'id' }), path: requireString({ input, key: 'path' }) };
|
|
74
|
+
const prior = await relay(() => source().read(target, {}));
|
|
75
|
+
return { target, prior };
|
|
76
|
+
},
|
|
77
|
+
describe: ({ prepared }) => deps.describeDelete({ target: prepared.target }),
|
|
78
|
+
run: async ({ ctx, prepared }) => {
|
|
79
|
+
await authorize(ctx, deps.enablePermission);
|
|
80
|
+
return relay(() => source().delete(prepared.target, { expectedDigest: prepared.prior.digest }));
|
|
81
|
+
},
|
|
82
|
+
}, { flag: 'deleted' });
|
|
83
|
+
return buildDomainRegistrations({ ...deps.registration, catalog: indexCatalogById({ catalog: deps.registration.catalog }), derivedRisk: pluginSourceDerivedRiskFor({ toolIds: deps.toolIds }), handlers });
|
|
84
|
+
}
|
|
85
|
+
/** Independently derived from calls to the source port: reads are read-only, delete unlinks,
|
|
86
|
+
* and create/open/write/edit/seal/rollback durably publish bytes. */
|
|
87
|
+
export function pluginSourceDerivedRiskFor({ toolIds }, _optional = {}) {
|
|
88
|
+
return new Map([
|
|
89
|
+
[toolIds.create, MUTATES_DURABLE_STATE], [toolIds.open, MUTATES_DURABLE_STATE],
|
|
90
|
+
[toolIds.list, 'none'], [toolIds.read, 'none'], [toolIds.write, MUTATES_DURABLE_STATE],
|
|
91
|
+
[toolIds.edit, MUTATES_DURABLE_STATE], [toolIds.delete, 'deletes-durable-state'],
|
|
92
|
+
[toolIds.seal, MUTATES_DURABLE_STATE], [toolIds.rollback, MUTATES_DURABLE_STATE],
|
|
93
|
+
]);
|
|
94
|
+
}
|
|
95
|
+
//# sourceMappingURL=source.js.map
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { type RunTier2CallRequired } from "./run-call.js";
|
|
2
|
+
/**
|
|
3
|
+
* Required inputs of {@link startTier2Worker}.
|
|
4
|
+
*
|
|
5
|
+
* @agent-note The worker entry is the host's own file: it reads `workerData`/`parentPort` from
|
|
6
|
+
* `node:worker_threads`, supplies its product binding and SDK resolver, and decides when to call
|
|
7
|
+
* this (normally only when not on the main thread). Jini never auto-starts a worker.
|
|
8
|
+
*/
|
|
9
|
+
export interface StartTier2WorkerRequired {
|
|
10
|
+
/** The `Tier2Request` the host posted as `workerData` (built by the server from a validated manifest). */
|
|
11
|
+
readonly workerData: unknown;
|
|
12
|
+
/** @agent-note `null` (not inside a worker) throws before any registration or import. */
|
|
13
|
+
readonly parentPort: {
|
|
14
|
+
postMessage(message: unknown): void;
|
|
15
|
+
} | null;
|
|
16
|
+
/** @agent-note The host's plugin SDK binding and invocation-deps factory, shared by every call
|
|
17
|
+
* in this worker; the same binding the host's main thread uses. */
|
|
18
|
+
readonly binding: Omit<RunTier2CallRequired, "request" | "importModule">;
|
|
19
|
+
/** @agent-note Registers the host's SDK module resolver in THIS worker. Called once, before the
|
|
20
|
+
* first real import of plugin code, and only when no `importModule` test seam is supplied.
|
|
21
|
+
* Main-thread resolver hooks do not reach a worker spawned with empty `execArgv`. */
|
|
22
|
+
readonly registerSdkResolver: () => void;
|
|
23
|
+
/** @agent-note The host's real `import()` of a plugin entry, defined in the host's own worker
|
|
24
|
+
* entry module so the host's loader (for example a dev transpiler's CJS interop) applies to it. */
|
|
25
|
+
readonly realImport: (entryPath: string) => Promise<unknown>;
|
|
26
|
+
}
|
|
27
|
+
/** Optional inputs of {@link startTier2Worker}. */
|
|
28
|
+
export interface StartTier2WorkerOptional {
|
|
29
|
+
/** Test seam. Omitted ⇒ register the SDK resolver in this worker, then `realImport`.
|
|
30
|
+
* @agent-note When supplied, `registerSdkResolver` and `realImport` are never called. */
|
|
31
|
+
readonly importModule?: (entryPath: string) => Promise<unknown>;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Runs the posted request and posts its reply.
|
|
35
|
+
*
|
|
36
|
+
* @agent-note One call per worker: posts exactly one reply, then the host terminates the worker.
|
|
37
|
+
* A plugin-side failure becomes a structured failed reply, never a rejection; a rejection here
|
|
38
|
+
* (no parent port, or a reply that cannot be posted) becomes the worker's `error` event on the host.
|
|
39
|
+
* The module's `default` export is what the plugin contributes; a non-object module yields none.
|
|
40
|
+
* @throws When there is no parent port (not inside a worker).
|
|
41
|
+
* @complexity O(1) own work plus the plugin's import/setup/filter cost.
|
|
42
|
+
*/
|
|
43
|
+
export declare function startTier2Worker(required: StartTier2WorkerRequired, optional?: StartTier2WorkerOptional): Promise<void>;
|
|
44
|
+
//# sourceMappingURL=start.d.ts.map
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { runTier2Call } from "./run-call.js";
|
|
2
|
+
/**
|
|
3
|
+
* Runs the posted request and posts its reply.
|
|
4
|
+
*
|
|
5
|
+
* @agent-note One call per worker: posts exactly one reply, then the host terminates the worker.
|
|
6
|
+
* A plugin-side failure becomes a structured failed reply, never a rejection; a rejection here
|
|
7
|
+
* (no parent port, or a reply that cannot be posted) becomes the worker's `error` event on the host.
|
|
8
|
+
* The module's `default` export is what the plugin contributes; a non-object module yields none.
|
|
9
|
+
* @throws When there is no parent port (not inside a worker).
|
|
10
|
+
* @complexity O(1) own work plus the plugin's import/setup/filter cost.
|
|
11
|
+
*/
|
|
12
|
+
export async function startTier2Worker(required, optional = {}) {
|
|
13
|
+
const port = required.parentPort;
|
|
14
|
+
if (!port)
|
|
15
|
+
throw new Error("the tier-2 plugin worker must run inside a worker_threads Worker");
|
|
16
|
+
let importModule = optional.importModule;
|
|
17
|
+
if (!importModule) {
|
|
18
|
+
// CIC U-002, per worker: main-thread `module.register()` hooks do not reach a worker spawned
|
|
19
|
+
// with `execArgv: []` (measured, Node v24.2.0), so without this a site plugin's
|
|
20
|
+
// SDK imports (including the legacy alias) fail, or resolve to a copy planted next to the plugin. Registered
|
|
21
|
+
// before the plugin's first import.
|
|
22
|
+
required.registerSdkResolver();
|
|
23
|
+
importModule = required.realImport;
|
|
24
|
+
}
|
|
25
|
+
const importEntry = importModule;
|
|
26
|
+
port.postMessage(await runTier2Call({ ...required.binding, request: required.workerData, importModule: async ({ modulePath }) => {
|
|
27
|
+
const imported = await importEntry(modulePath);
|
|
28
|
+
return { exported: typeof imported === "object" && imported !== null ? imported.default : undefined };
|
|
29
|
+
} }));
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=start.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jini-ai/plugins",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.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": {
|
|
@@ -17,7 +17,8 @@
|
|
|
17
17
|
"./host": "universal",
|
|
18
18
|
"./host/node": "node",
|
|
19
19
|
"./host/worker": "node",
|
|
20
|
-
"./host/sql": "node"
|
|
20
|
+
"./host/sql": "node",
|
|
21
|
+
"./host/tools": "node"
|
|
21
22
|
},
|
|
22
23
|
"isolation": {
|
|
23
24
|
"forbidden": {
|
|
@@ -60,6 +61,11 @@
|
|
|
60
61
|
"types": "./dist/host/sql/index.d.ts",
|
|
61
62
|
"import": "./dist/host/sql/index.js",
|
|
62
63
|
"default": "./dist/host/sql/index.js"
|
|
64
|
+
},
|
|
65
|
+
"./host/tools": {
|
|
66
|
+
"types": "./dist/host/tools/index.d.ts",
|
|
67
|
+
"import": "./dist/host/tools/index.js",
|
|
68
|
+
"default": "./dist/host/tools/index.js"
|
|
63
69
|
}
|
|
64
70
|
},
|
|
65
71
|
"files": [
|
|
@@ -71,28 +77,29 @@
|
|
|
71
77
|
"!dist/**/*.test.d.ts",
|
|
72
78
|
"!dist/**/*.test.js.map",
|
|
73
79
|
"!dist/**/*.test.d.ts.map",
|
|
74
|
-
"!dist/**/__tests__/**"
|
|
80
|
+
"!dist/**/__tests__/**",
|
|
81
|
+
"!dist/**/*.map"
|
|
75
82
|
],
|
|
76
83
|
"publishConfig": {
|
|
77
84
|
"access": "public",
|
|
78
85
|
"registry": "https://registry.npmjs.org"
|
|
79
86
|
},
|
|
80
87
|
"dependencies": {
|
|
81
|
-
"@jini-ai/core": "^0.
|
|
88
|
+
"@jini-ai/core": "^0.7.0"
|
|
82
89
|
},
|
|
83
90
|
"peerDependencies": {
|
|
84
|
-
"@jini-ai/platform": "^0.
|
|
91
|
+
"@jini-ai/platform": "^0.7.0",
|
|
85
92
|
"semver": "^7.6.2",
|
|
86
93
|
"kysely": "^0.29.6",
|
|
87
|
-
"@jini-ai/db": "^0.
|
|
94
|
+
"@jini-ai/db": "^0.7.0"
|
|
88
95
|
},
|
|
89
96
|
"devDependencies": {
|
|
90
97
|
"semver": "^7.6.2",
|
|
91
98
|
"@types/semver": "^7.5.8",
|
|
92
99
|
"kysely": "^0.29.6",
|
|
93
|
-
"@jini-ai/
|
|
94
|
-
"@jini-ai/
|
|
95
|
-
"@jini-ai/db": "0.
|
|
100
|
+
"@jini-ai/core": "^0.7.0",
|
|
101
|
+
"@jini-ai/platform": "^0.7.0",
|
|
102
|
+
"@jini-ai/db": "0.7.0"
|
|
96
103
|
},
|
|
97
104
|
"peerDependenciesMeta": {
|
|
98
105
|
"@jini-ai/platform": {
|