@jini-ai/plugins 0.6.19 → 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 +51 -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/source-policy.d.ts +2 -2
- package/dist/host/source-policy.js +3 -3
- 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,306 @@
|
|
|
1
|
+
import { buildDomainRegistrations, indexCatalogById, isRecord, redactSecrets, requireInputRecord, requireString, ToolInputError, requireToolPermission, adaptLegacyAuthorize } from "@jini-ai/core";
|
|
2
|
+
import { readPluginIdentity } from "@jini-ai/core/plugin-directory";
|
|
3
|
+
import { attachPluginContributionTools } from "./tool-contributions.js";
|
|
4
|
+
import { capabilityToolIdFor } from "./plugin-claims.js";
|
|
5
|
+
/** `plugin_capability_<pluginId>` — see this file's header, "Tool id scheme". The derivation lives in
|
|
6
|
+
* `Jini/packages/plugins/src/host/plugin-claims.ts` (2026-10-04) so the conflict detector claims exactly the id registered here. */
|
|
7
|
+
/** The ONE definition of "this plugin's capability tool may exist / may run": this workspace's activation
|
|
8
|
+
* row says `enabled: true`. Absent, disabled, quarantined (saved `enabled: false`) and uninstalled (every
|
|
9
|
+
* row deleted) all answer false. Shared by the boot filter and the per-call gate — see this file's header,
|
|
10
|
+
* "Revocation". @complexity one activation-row read. */
|
|
11
|
+
async function isPluginEnabledInWorkspace(repo, workspaceId, pluginId) {
|
|
12
|
+
const activation = await repo.getActivation({ workspaceId, pluginId });
|
|
13
|
+
return activation?.enabled === true;
|
|
14
|
+
}
|
|
15
|
+
/** Whether this plugin's tool computes a fresh result instead of reading the stored one — see this
|
|
16
|
+
* file's header, "Fresh results for Tier-2 plugins". */
|
|
17
|
+
function runsFreshFor(manifest, beforeSaveHook) {
|
|
18
|
+
return manifest.tier === "tier-2" && manifest.hooks.includes(beforeSaveHook);
|
|
19
|
+
}
|
|
20
|
+
/** This module's own risk classification — every capability tool is a pure read of an already-saved
|
|
21
|
+
* post's already-computed `ext` bag: no domain call, no write path. Mirrors
|
|
22
|
+
* `agent-plugins/tool-registrations.ts`'s identical `"none"` classification for the same reason.
|
|
23
|
+
* @agent-note Host-independent: every source is classified `"none"`. */
|
|
24
|
+
export function pluginCapabilityToolDerivedRisk(required, _optional = {}) {
|
|
25
|
+
return new Map(required.sources.map((source) => [source.id, "none"]));
|
|
26
|
+
}
|
|
27
|
+
/** Reads one plugin's stored field bag off an already-loaded post, defensively — `post.ext` is
|
|
28
|
+
* typed as a generic `JsonObject` (see `post.ts`'s own field doc), so this narrows with `isRecord`
|
|
29
|
+
* at each level rather than casting, and treats any unexpected shape the same as "not yet written"
|
|
30
|
+
* (`undefined`, then `null` + note) rather than throwing on data this handler does not own the shape of. */
|
|
31
|
+
function readStoredFieldBag(source, post) {
|
|
32
|
+
const extension = { value: post.ext };
|
|
33
|
+
const candidate = { value: isRecord(extension) ? extension.value[source.pluginId] : undefined };
|
|
34
|
+
return isRecord(candidate) ? candidate.value : undefined;
|
|
35
|
+
}
|
|
36
|
+
/** A string field holding a JSON object or array comes back parsed (see this file's header, "Fresh
|
|
37
|
+
* results for Tier-2 plugins"); every other value, including a string that only looks like JSON,
|
|
38
|
+
* is returned exactly as written. @complexity O(value length). */
|
|
39
|
+
function decodeFieldValue(value) {
|
|
40
|
+
if (typeof value !== "string" || !/^\s*[[{]/.test(value))
|
|
41
|
+
return value;
|
|
42
|
+
try {
|
|
43
|
+
return JSON.parse(value);
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
return value;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Binds the capability-tool registrar to one host vocabulary.
|
|
51
|
+
* @agent-note Second-host rules: supply every required input; nothing has a default. The returned
|
|
52
|
+
* members hold no state between calls; per-workspace state lives in the `deps` object the caller
|
|
53
|
+
* passes (held by reference). Calls to the host ports happen in this order per tool call: activation
|
|
54
|
+
* read (policy), inner policy, approval policy, permission check, post read, optional preview.
|
|
55
|
+
* @param required Host vocabulary and ports, see {@link PluginCapabilityToolsRequired}.
|
|
56
|
+
* @param _optional Reserved; pass `{}`.
|
|
57
|
+
*/
|
|
58
|
+
export function createPluginCapabilityTools(required, _optional = {}) {
|
|
59
|
+
const { identityNamespace, beforeSaveHook, text, catalog, access, executableAccess, approvalFamily, toPreviewDraft } = required;
|
|
60
|
+
/** Fallback for a field whose manifest declares no `description` (see this file's header,
|
|
61
|
+
* "description text IS the fix") — weaker (a noun-phrase, not an action), but still a usable,
|
|
62
|
+
* non-empty tool description rather than no tool at all. */
|
|
63
|
+
function genericFieldDescription(pluginName, field) {
|
|
64
|
+
return text.genericFieldDescription({ pluginName, path: field.path, type: field.type });
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Resolves one valid manifest's declared fields into tool-ready sources — `expectedPrefix` mirrors
|
|
68
|
+
* `manifest.ts`'s own `validateFields` derivation exactly, so a field this function accepts is
|
|
69
|
+
* guaranteed already-validated namespacing, never a fresh assumption this file invents.
|
|
70
|
+
*
|
|
71
|
+
* @complexity O(fields.length) — one manifest's own declared array.
|
|
72
|
+
*/
|
|
73
|
+
function buildFieldSources(manifest) {
|
|
74
|
+
const expectedPrefix = `ext.${manifest.id}.`;
|
|
75
|
+
return manifest.fields
|
|
76
|
+
.filter((field) => field.path.startsWith(expectedPrefix) && field.path.length > expectedPrefix.length)
|
|
77
|
+
.map((field) => ({
|
|
78
|
+
path: field.path,
|
|
79
|
+
fieldKey: field.path.slice(expectedPrefix.length),
|
|
80
|
+
type: field.type,
|
|
81
|
+
description: field.description ?? genericFieldDescription(manifest.name, field),
|
|
82
|
+
}));
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Builds this plugin tool's model-facing description — an operator SEARCH TARGET, not a card blurb
|
|
86
|
+
* (mirrors `agent-plugins/tool-registrations.ts`'s `buildPluginToolDescription` doc on the same
|
|
87
|
+
* point). Leads with an imperative action clause, folds in every field's own description text (the
|
|
88
|
+
* actual indexed vocabulary a real query needs to match), and states the `postId` precondition and
|
|
89
|
+
* the "no data yet" outcome up front so a model reading only this description already knows how to
|
|
90
|
+
* call it and what an empty result means.
|
|
91
|
+
*/
|
|
92
|
+
function buildCapabilityToolDescription(manifest, fields) {
|
|
93
|
+
const identity = readPluginIdentity({ manifest: manifest, name: manifest.id, namespace: identityNamespace });
|
|
94
|
+
const fieldText = fields.map((field) => field.description).join(" ") + text.discovery({ terms: [identity.id, ...identity.keywords, ...identity.provides].join(" ") });
|
|
95
|
+
if (runsFreshFor(manifest, beforeSaveHook)) {
|
|
96
|
+
return text.freshDescription({ pluginName: manifest.name, fieldText });
|
|
97
|
+
}
|
|
98
|
+
return text.storedDescription({ pluginName: manifest.name, fieldText });
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Loads every ENABLED, valid plugin-runtime plugin that declares at least one field, resolved into
|
|
102
|
+
* one tool-ready source per plugin. See this file's header, "Activation gate", for why "enabled"
|
|
103
|
+
* here means `activation.enabled === true` — the opposite default from Agent Plugins.
|
|
104
|
+
*
|
|
105
|
+
* @complexity O(p) plugin-discovery calls times one `pluginActivationRepo.getActivation` each,
|
|
106
|
+
* dominated by `discoverPlugins()`'s own I/O (unchanged, not re-read per plugin).
|
|
107
|
+
*/
|
|
108
|
+
async function loadEnabledPluginCapabilityToolSources(deps) {
|
|
109
|
+
const discovery = await deps.discoverPlugins();
|
|
110
|
+
const sources = [];
|
|
111
|
+
for (const record of discovery) {
|
|
112
|
+
// No fields means nothing this plugin's tool could ever return. Disabled (or never activated)
|
|
113
|
+
// plugins stay out too — see this file's header. Preserve that short-circuit order.
|
|
114
|
+
if (record.status !== "valid" || !record.manifest || record.manifest.fields.length === 0 ||
|
|
115
|
+
!(await isPluginEnabledInWorkspace(deps.pluginActivationRepo, deps.workspaceId, record.id)))
|
|
116
|
+
continue;
|
|
117
|
+
const fields = buildFieldSources(record.manifest);
|
|
118
|
+
if (fields.length > 0)
|
|
119
|
+
sources.push({
|
|
120
|
+
id: capabilityToolIdFor({ pluginId: record.id }),
|
|
121
|
+
pluginId: record.id,
|
|
122
|
+
pluginName: record.manifest.name,
|
|
123
|
+
description: buildCapabilityToolDescription(record.manifest, fields),
|
|
124
|
+
fields,
|
|
125
|
+
runsFresh: runsFreshFor(record.manifest, beforeSaveHook),
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
return sources;
|
|
129
|
+
}
|
|
130
|
+
function buildCapabilityInputSchema() {
|
|
131
|
+
return {
|
|
132
|
+
type: "object",
|
|
133
|
+
additionalProperties: false,
|
|
134
|
+
required: ["postId"],
|
|
135
|
+
properties: {
|
|
136
|
+
postId: {
|
|
137
|
+
type: "string",
|
|
138
|
+
minLength: 1,
|
|
139
|
+
description: text.postIdDescription,
|
|
140
|
+
},
|
|
141
|
+
},
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
/** Projects one plugin's field bag — stored, or fresh from the preview port (`computedNow`) — onto
|
|
145
|
+
* its declared fields, adding the "not computed yet" note when none of them has a value. */
|
|
146
|
+
function buildCapabilityToolResult(source, post, bag) {
|
|
147
|
+
const pluginBag = bag.values;
|
|
148
|
+
const fields = {};
|
|
149
|
+
let anyComputed = false;
|
|
150
|
+
for (const field of source.fields) {
|
|
151
|
+
const value = pluginBag ? pluginBag[field.fieldKey] : undefined;
|
|
152
|
+
fields[field.fieldKey] = value === undefined ? null : decodeFieldValue(value);
|
|
153
|
+
if (value !== undefined)
|
|
154
|
+
anyComputed = true;
|
|
155
|
+
}
|
|
156
|
+
return {
|
|
157
|
+
postId: post.id,
|
|
158
|
+
pluginId: source.pluginId,
|
|
159
|
+
computedNow: bag.computedNow,
|
|
160
|
+
fields,
|
|
161
|
+
...(anyComputed
|
|
162
|
+
? {}
|
|
163
|
+
: {
|
|
164
|
+
note: text.noDataNote({ pluginName: source.pluginName }),
|
|
165
|
+
}),
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
/** The field bag one call answers with: a fresh preview for a {@link PluginCapabilityToolSource.runsFresh}
|
|
169
|
+
* source when the port is injected and this process has the plugin attached, otherwise the stored one.
|
|
170
|
+
* The draft is the post exactly as stored — the same fields `post.ts` hands the filter on an update.
|
|
171
|
+
* @throws {ToolInputError} the fresh run failed; the cause stays on the error, the model sees fixed text.
|
|
172
|
+
* @complexity one post-draft preview (a worker round trip for tier-2) or none. */
|
|
173
|
+
async function resolveFieldBag(source, post, deps) {
|
|
174
|
+
const preview = source.runsFresh ? deps.previewPluginBeforeSave : undefined;
|
|
175
|
+
const fresh = preview
|
|
176
|
+
? await preview(source.pluginId, toPreviewDraft({ post })).catch((error) => {
|
|
177
|
+
throw new ToolInputError({
|
|
178
|
+
message: text.previewFailed({ pluginName: source.pluginName, postId: post.id }),
|
|
179
|
+
}, { cause: error });
|
|
180
|
+
})
|
|
181
|
+
: null;
|
|
182
|
+
return fresh ? { values: fresh, computedNow: true } : { values: readStoredFieldBag(source, post), computedNow: false };
|
|
183
|
+
}
|
|
184
|
+
/** One source's catalog entry. The host's `access.permission` — the same object the handler checks. */
|
|
185
|
+
function capabilityCatalogEntry(source) {
|
|
186
|
+
return {
|
|
187
|
+
name: source.id,
|
|
188
|
+
description: source.description,
|
|
189
|
+
sideEffects: "none",
|
|
190
|
+
authorization: { permission: access.permission },
|
|
191
|
+
inputSchema: buildCapabilityInputSchema(),
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
/** One source's handler. @complexity one permission check, one post read, and at most one fresh preview. */
|
|
195
|
+
function capabilityToolHandler(source, deps) {
|
|
196
|
+
return async (ctx) => {
|
|
197
|
+
const input = requireInputRecord({ input: ctx.input });
|
|
198
|
+
const postId = requireString({ input: input, key: "postId" });
|
|
199
|
+
await requireToolPermission({ authorize: adaptLegacyAuthorize({ authorize: deps.authorize }), workspaceId: deps.workspaceId, principalId: ctx.principal.id, permission: access.permission }, { entityType: access.entityType, entityId: postId });
|
|
200
|
+
const post = await deps.postRead.readRequired({ workspaceId: deps.workspaceId, id: postId });
|
|
201
|
+
return buildCapabilityToolResult(source, post, await resolveFieldBag(source, post, deps));
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
/** Whether `pluginId` may run right now. A read that throws DENIES and is logged, rather than surfacing as a
|
|
205
|
+
* failed execution whose cause the daemon redacts. @complexity one activation-row read. */
|
|
206
|
+
async function isCapabilityCallableNow(deps, pluginId) {
|
|
207
|
+
try {
|
|
208
|
+
return await isPluginEnabledInWorkspace(deps.pluginActivationRepo, deps.workspaceId, pluginId);
|
|
209
|
+
}
|
|
210
|
+
catch (error) {
|
|
211
|
+
console.warn(text.activationReadDenied({ pluginId, detail: redactSecrets({ input: error instanceof Error ? error.message : String(error) }, { redactPii: false }) }));
|
|
212
|
+
return false;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Wraps one registration's policy so the plugin's CURRENT activation is re-read before its handler can be
|
|
217
|
+
* reached, then defers to the policy `buildDomainRegistrations` attached — the same shape and reason as
|
|
218
|
+
* `agent-plugins/tool-registrations.ts`'s `withToolGate` (a future kit policy must not be silently dropped).
|
|
219
|
+
* @complexity O(1) plus one activation-row read per call.
|
|
220
|
+
*/
|
|
221
|
+
function withActivationGate(registration, deps, pluginId) {
|
|
222
|
+
const inner = registration.policy;
|
|
223
|
+
return {
|
|
224
|
+
...registration,
|
|
225
|
+
policy: {
|
|
226
|
+
async authorize(authCtx) {
|
|
227
|
+
if (!(await isCapabilityCallableNow(deps, pluginId)))
|
|
228
|
+
return "deny";
|
|
229
|
+
return inner.authorize(authCtx);
|
|
230
|
+
},
|
|
231
|
+
},
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Turns already-resolved plugin capability sources into real `ToolRegistration`s — pure and
|
|
236
|
+
* synchronous, unlike {@link loadEnabledPluginCapabilityToolSources}, so this half is unit-tested
|
|
237
|
+
* without touching activation/discovery I/O. Uses the same `buildDomainRegistrations` gate every
|
|
238
|
+
* other domain's `tool-registrations.ts` uses (catalog/risk cross-check, `inputSchema` presence,
|
|
239
|
+
* drift tripwire) — not a parallel mechanism.
|
|
240
|
+
*
|
|
241
|
+
* Permission: the host's `access.permission`, the same permission its own post read tool requires —
|
|
242
|
+
* this tool reads a post's already-persisted data, nothing a plugin-specific permission would
|
|
243
|
+
* meaningfully narrow further (mirrors that tool's own inline `requireToolPermission` call exactly,
|
|
244
|
+
* including the `entityType`/`entityId` pair so a per-post authorization rule can still apply).
|
|
245
|
+
*
|
|
246
|
+
* Every registration carries the per-call activation gate (`withActivationGate`) — see this file's
|
|
247
|
+
* header, "Revocation". Built one source at a time so the owning plugin id is in scope for every
|
|
248
|
+
* registration the kit returns: there is no id-to-plugin lookup that could miss and leave a tool
|
|
249
|
+
* ungated. The build stays synchronous and touches no I/O; the gate reads only when a call is
|
|
250
|
+
* authorized.
|
|
251
|
+
*/
|
|
252
|
+
function buildPluginCapabilityToolRegistrations({ sources, deps, applyApprovalPolicy }, _optionalArgs = {}) {
|
|
253
|
+
return sources.flatMap((source) => buildDomainRegistrations({ metadata: catalog.metadata,
|
|
254
|
+
domain: catalog.domain,
|
|
255
|
+
catalogModule: catalog.catalogModule,
|
|
256
|
+
catalog: indexCatalogById({ catalog: [capabilityCatalogEntry(source)] }),
|
|
257
|
+
handlers: { [source.id]: capabilityToolHandler(source, deps) },
|
|
258
|
+
derivedRisk: pluginCapabilityToolDerivedRisk({ sources: [source] }),
|
|
259
|
+
}).map((registration) => applyApprovalPolicy({ registration: withActivationGate(registration, deps, source.pluginId), family: approvalFamily })));
|
|
260
|
+
}
|
|
261
|
+
/** Product authorization and approval inputs for Jini's executable registration owner. */
|
|
262
|
+
function executablePluginToolPorts({ deps, contributions }) {
|
|
263
|
+
// The caller passes the bound registry it just checked, so there is no unbound case to refuse here.
|
|
264
|
+
return {
|
|
265
|
+
contributions,
|
|
266
|
+
isEnabled: async ({ pluginId }) => (await deps.pluginActivationRepo.getActivation({ workspaceId: deps.workspaceId, pluginId }))?.enabled === true,
|
|
267
|
+
resolveAuth: async ({ pluginId, principalId }) => {
|
|
268
|
+
await requireToolPermission({ authorize: adaptLegacyAuthorize({ authorize: deps.authorize }), workspaceId: deps.workspaceId, principalId, permission: executableAccess.permission }, { entityType: executableAccess.entityType, entityId: pluginId });
|
|
269
|
+
return { access: 'admin', principalId, workspaceId: deps.workspaceId };
|
|
270
|
+
},
|
|
271
|
+
// In-process arbitrary code can leave this site. Its prose cannot self-classify it as read-only.
|
|
272
|
+
// The assistant decides when to invoke it; only permanent-delete tools require confirmation.
|
|
273
|
+
metadata: executableAccess.metadata,
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Composition-root entry point: loads every enabled, field-declaring plugin for one workspace and
|
|
278
|
+
* registers each as a real tool directly on `registry` — the same `registry.register(registration)`
|
|
279
|
+
* call `agent-daemon-server.ts`'s own loops make for every other contributor's output, just awaited
|
|
280
|
+
* first (mirrors `registerInstalledAgentPluginTools`'s identical shape and rationale).
|
|
281
|
+
*
|
|
282
|
+
* @throws Whatever `registry.register()` itself throws on an id collision (`@jini-ai/core`'s
|
|
283
|
+
* `createToolRegistry()` throws synchronously — see this file's header) — deliberately not caught
|
|
284
|
+
* here; the caller's own fail-open `try/catch` (matching `registerInstalledAgentPluginTools`'s and
|
|
285
|
+
* `registerInstalledSkillTools`'s call sites in `agent-daemon-server.ts`) is where that is handled,
|
|
286
|
+
* so all three optional registrars degrade identically on failure.
|
|
287
|
+
*
|
|
288
|
+
* Registers with the per-call activation gate, so a tool this puts into the daemon's registry is
|
|
289
|
+
* refused the moment its plugin is disabled, quarantined or uninstalled.
|
|
290
|
+
*/
|
|
291
|
+
async function registerEnabledPluginCapabilityTools({ registry, deps, applyApprovalPolicy }, _optionalArgs = {}) {
|
|
292
|
+
const sources = await loadEnabledPluginCapabilityToolSources(deps);
|
|
293
|
+
for (const registration of buildPluginCapabilityToolRegistrations({ sources, deps, applyApprovalPolicy })) {
|
|
294
|
+
registry.register(registration);
|
|
295
|
+
}
|
|
296
|
+
if (deps.pluginContributions && (deps.executablePluginToolRegistry || (registry.has && registry.list))) {
|
|
297
|
+
attachPluginContributionTools({ ...executablePluginToolPorts({ deps, contributions: deps.pluginContributions }), registry: deps.executablePluginToolRegistry ?? registry });
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
return {
|
|
301
|
+
loadSources: (deps) => loadEnabledPluginCapabilityToolSources(deps),
|
|
302
|
+
buildRegistrations: (args) => buildPluginCapabilityToolRegistrations(args),
|
|
303
|
+
registerEnabled: (args) => registerEnabledPluginCapabilityTools(args),
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
//# sourceMappingURL=capability-tools.js.map
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file A plugin's manifest-declared content types (the plugin manifest → `contentTypes`) — parse,
|
|
3
|
+
* plan against what the site already has, and apply through the host's ONE content-type write path
|
|
4
|
+
* (behind {@link DeclaredContentTypeWritePorts}). AW-7 Tier 1, 2026-10-04.
|
|
5
|
+
*
|
|
6
|
+
* Why this exists: ADR-024 §1 defines Tier-1 as a manifest-only plugin whose first contribution is
|
|
7
|
+
* "content types & fields", but `manifest.ts` only ever parsed-and-stored `contentTypes` (state.spec
|
|
8
|
+
* §2: "UNUSED in v1"). This module is the missing half: a bounded, closed declaration grammar
|
|
9
|
+
* (ADR-024 §5 — Tier-1 is only safe while its surface is non-Turing-complete and bounded) and an
|
|
10
|
+
* idempotent provisioner that runs at enable time.
|
|
11
|
+
*
|
|
12
|
+
* Rules the provisioner keeps (and why):
|
|
13
|
+
* - **Create if missing, never overwrite.** An existing type that already holds every declared field
|
|
14
|
+
* with the same kind is KEPT (the owner may have added fields of their own through Collections —
|
|
15
|
+
* that is their data model now). An existing type that disagrees is a CONFLICT and the enable is
|
|
16
|
+
* refused before anything is written, rather than silently reshaping someone's content.
|
|
17
|
+
* - **A tombstoned type is skipped.** The owner deleted it on purpose; tombstone is terminal and the
|
|
18
|
+
* key can never be reused (content-types INV-06), so re-enabling the plugin does not resurrect it.
|
|
19
|
+
* - **Retain on disable/uninstall** (ADR-023/ADR-024 retain-by-default): nothing here ever removes a
|
|
20
|
+
* type. The entries are the owner's content, not the plugin's.
|
|
21
|
+
*
|
|
22
|
+
* Pure parsing; the plan/apply halves do I/O only through the injected ports.
|
|
23
|
+
*
|
|
24
|
+
* Ownership split (EXTRACT-S6 L1a): the bounds, grammar, tier rule, plan and apply are plugin-domain
|
|
25
|
+
* and live here. The content-type vocabulary (field kinds, both kind checks, identifier grammar and
|
|
26
|
+
* the already-exists classifier) comes from the host through {@link DeclaredContentTypeCms}, and the
|
|
27
|
+
* reserved keys are a required host input — see {@link createDeclarativeContentTypes}. Where a type
|
|
28
|
+
* is stored (its entry envelope) is the host's `register` decision; nothing here names one.
|
|
29
|
+
*/
|
|
30
|
+
import type { ContentTypeFieldDef, ContentTypeFieldKind, ContentTypeRecord } from "@jini-ai/core/contracts/content-types";
|
|
31
|
+
import type { PluginValidationError } from "./manifest-types.js";
|
|
32
|
+
import type { DeclaredContentType, DeclaredContentTypePlan } from "./ports.js";
|
|
33
|
+
/** ADR-024 §5 bound: how many content types one plugin may declare.
|
|
34
|
+
* @agent-note Plugin-domain bound, not a host option; a longer list is refused whole at parse. */
|
|
35
|
+
export declare const MAX_DECLARED_CONTENT_TYPES = 20;
|
|
36
|
+
/** ADR-024 §5 bound: how many fields one declared content type may carry.
|
|
37
|
+
* @agent-note Plugin-domain bound, not a host option. */
|
|
38
|
+
export declare const MAX_DECLARED_FIELDS = 50;
|
|
39
|
+
/** Core's own per-type queryable-field cap (`QUERYABLE_FIELD_CAP` in `@jini-ai/cms`'s
|
|
40
|
+
* `registerContentType`, not exported). Checked here so a declaration core would refuse is
|
|
41
|
+
* `invalid` at discovery, instead of failing at enable after the plugin's code attached.
|
|
42
|
+
* @agent-note A host whose own write path allows fewer queryable fields still refuses at
|
|
43
|
+
* `register`; that refusal surfaces as an enable failure, never as a lost race. */
|
|
44
|
+
export declare const MAX_DECLARED_QUERYABLE_FIELDS = 20;
|
|
45
|
+
/**
|
|
46
|
+
* The content-type vocabulary the declaration grammar is checked against. Supplied by the host from
|
|
47
|
+
* its own content-type implementation; this package never imports one.
|
|
48
|
+
*
|
|
49
|
+
* @agent-note Second-host rules: every member is called detached (no `this`), synchronously and
|
|
50
|
+
* without side effects, during `parse`/`validateManifest` (discovery) and `apply` (enable). One
|
|
51
|
+
* object is captured per {@link createDeclarativeContentTypes} call and reused for every plugin and
|
|
52
|
+
* call; it must describe the SAME rules the host's `register` enforces, or a declaration valid here
|
|
53
|
+
* fails later at enable.
|
|
54
|
+
*/
|
|
55
|
+
export interface DeclaredContentTypeCms {
|
|
56
|
+
/** @agent-note The host's closed field-kind list. Printed verbatim, in this order, in the
|
|
57
|
+
* unknown-kind diagnostic. Every listed kind must pass `isFieldKind`. */
|
|
58
|
+
readonly fieldKinds: readonly ContentTypeFieldKind[];
|
|
59
|
+
/** @agent-note True exactly for the kinds in `fieldKinds`. Pure; receives any manifest value. */
|
|
60
|
+
readonly isFieldKind: (required: {
|
|
61
|
+
value: unknown;
|
|
62
|
+
}) => boolean;
|
|
63
|
+
/** @agent-note True for kinds the host can index; a `queryable` field of any other kind is
|
|
64
|
+
* refused at parse. Pure; called only with a value that already passed `isFieldKind`. */
|
|
65
|
+
readonly isIndexable: (required: {
|
|
66
|
+
value: unknown;
|
|
67
|
+
}) => boolean;
|
|
68
|
+
/** @agent-note The host's identifier grammar, used for type keys and field names. Pure. */
|
|
69
|
+
readonly validateIdentifier: (required: {
|
|
70
|
+
value: string;
|
|
71
|
+
}) => boolean;
|
|
72
|
+
/** @agent-note Human-readable form of `validateIdentifier` (e.g. a regex source). Printed verbatim
|
|
73
|
+
* in diagnostics, so a host that must keep saved/compared diagnostic text supplies its exact
|
|
74
|
+
* bytes. */
|
|
75
|
+
readonly identifierGrammar: string;
|
|
76
|
+
/**
|
|
77
|
+
* Classifies the error `register` returned: `true` ONLY for the host's own "this key already
|
|
78
|
+
* exists" rejection (a lost concurrent create). The winner is then re-read and judged.
|
|
79
|
+
* @agent-note Must not throw. Any error it does not recognize is rethrown unchanged by `apply`
|
|
80
|
+
* with its identity intact, so return `false` for infrastructure failures, validation refusals
|
|
81
|
+
* and unknown values. Matching by message text is not identity; prefer the host's error class.
|
|
82
|
+
*/
|
|
83
|
+
readonly isAlreadyExists: (required: {
|
|
84
|
+
error: Error;
|
|
85
|
+
}) => boolean;
|
|
86
|
+
}
|
|
87
|
+
/** One validated content-type declaration, already in core's `ContentTypeFieldDef` shape.
|
|
88
|
+
* @agent-note Concrete form of the opaque {@link DeclaredContentType} that `ports.ts` carries;
|
|
89
|
+
* produced only by `parse`, never constructed by a host. */
|
|
90
|
+
export interface DeclaredContentTypeDefinition extends DeclaredContentType {
|
|
91
|
+
readonly key: string;
|
|
92
|
+
readonly label: string;
|
|
93
|
+
readonly fields: readonly ContentTypeFieldDef[];
|
|
94
|
+
}
|
|
95
|
+
/** @agent-note `decls` holds only fully valid declarations; `errors` is collect-all, in order. A
|
|
96
|
+
* host lists a plugin with any error as invalid rather than enabling a subset. */
|
|
97
|
+
export interface ParseDeclaredContentTypesResult {
|
|
98
|
+
readonly decls: readonly DeclaredContentTypeDefinition[];
|
|
99
|
+
readonly errors: readonly PluginValidationError[];
|
|
100
|
+
}
|
|
101
|
+
/** The manifest keys the declarative rules read. Values are `unknown` so `validateManifest` can pass
|
|
102
|
+
* its raw, not-yet-validated object, and a parsed `PluginManifest` fits too.
|
|
103
|
+
* @agent-note Read only; never mutated or retained. */
|
|
104
|
+
export interface DeclarativeManifestView {
|
|
105
|
+
readonly tier?: unknown;
|
|
106
|
+
readonly contentTypes?: unknown;
|
|
107
|
+
readonly capabilities?: unknown;
|
|
108
|
+
readonly hooks?: unknown;
|
|
109
|
+
readonly fields?: unknown;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* The two content-type operations the provisioner needs. `register` is the host's content-type
|
|
113
|
+
* write path bound by the composition root; it returns a `Result` rather than throwing for an
|
|
114
|
+
* expected rejection.
|
|
115
|
+
*
|
|
116
|
+
* @agent-note Second-host rules: `findByKey` reads the type stored under `key` in `workspaceId`
|
|
117
|
+
* (the enabling workspace) and resolves `null` when there is none; a tombstoned type is returned
|
|
118
|
+
* with `status: "tombstone"`, never hidden. `register` performs ONE host write per call, in plan
|
|
119
|
+
* order, and resolves `{ ok: false, error }` for an expected rejection (including a lost create
|
|
120
|
+
* race) instead of throwing. `actorId` arrives as `plugin:<id>`; the host records it as the
|
|
121
|
+
* revision author. The host owns authorization (enable already required the plugin-manage
|
|
122
|
+
* permission and consent), the storage envelope/owner the type is registered under (nothing here
|
|
123
|
+
* passes one — register where the host's readers look), revisions and outbox. Both members must hit
|
|
124
|
+
* the same store so the post-race re-read sees the winner. No cleanup is ever requested: types are
|
|
125
|
+
* retained on disable/uninstall.
|
|
126
|
+
*/
|
|
127
|
+
export interface DeclaredContentTypeWritePorts {
|
|
128
|
+
/** @agent-note Read in the enabling workspace; `null` when absent, tombstones returned as such. */
|
|
129
|
+
findByKey(params: {
|
|
130
|
+
workspaceId: string;
|
|
131
|
+
key: string;
|
|
132
|
+
}): Promise<ContentTypeRecord | null>;
|
|
133
|
+
/** @agent-note One host write; `{ ok: false, error }` for an expected rejection, never a throw. */
|
|
134
|
+
register(input: {
|
|
135
|
+
workspaceId: string;
|
|
136
|
+
key: string;
|
|
137
|
+
label: string;
|
|
138
|
+
fields: ContentTypeFieldDef[];
|
|
139
|
+
actorId: string;
|
|
140
|
+
}): Promise<{
|
|
141
|
+
ok: true;
|
|
142
|
+
} | {
|
|
143
|
+
ok: false;
|
|
144
|
+
error: Error;
|
|
145
|
+
}>;
|
|
146
|
+
}
|
|
147
|
+
/** @agent-note `create` is the only outcome that writes; `keep`/`skip-tombstoned` never touch the type. */
|
|
148
|
+
export type DeclaredContentTypeOutcome = "create" | "keep" | "skip-tombstoned";
|
|
149
|
+
/** @agent-note Concrete form of the opaque {@link DeclaredContentTypePlan}; produced only by `plan`
|
|
150
|
+
* and passed unchanged to `apply` of the SAME instance. */
|
|
151
|
+
export interface DeclaredContentTypeDefinitionPlan extends DeclaredContentTypePlan {
|
|
152
|
+
readonly items: ReadonlyArray<{
|
|
153
|
+
readonly decl: DeclaredContentTypeDefinition;
|
|
154
|
+
readonly outcome: DeclaredContentTypeOutcome;
|
|
155
|
+
}>;
|
|
156
|
+
/** Human-readable reasons the plugin cannot be turned on. Non-empty ⇒ `items` is empty. */
|
|
157
|
+
readonly conflicts: readonly string[];
|
|
158
|
+
}
|
|
159
|
+
/** @agent-note Keys per outcome, in plan order; a lost-race key lands in `kept` or `skipped`. */
|
|
160
|
+
export interface ApplyDeclaredContentTypesResult {
|
|
161
|
+
readonly created: readonly string[];
|
|
162
|
+
readonly kept: readonly string[];
|
|
163
|
+
readonly skipped: readonly string[];
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* One host's bound declaration rules. Its members have the shapes of
|
|
167
|
+
* `DeclarativeContentTypesPort` (`ports.ts`), so the object can be passed as that port directly.
|
|
168
|
+
*
|
|
169
|
+
* @agent-note Second-host rules: use ONE instance for discovery (`validateManifest`), install and
|
|
170
|
+
* enable (`parse`/`plan`/`apply`) so all three judge declarations with the same reserved keys and
|
|
171
|
+
* vocabulary. `plan` and `apply` must receive the same `DeclaredContentTypeWritePorts` (same store)
|
|
172
|
+
* within one enable, and `apply` only a plan `plan` produced with no conflicts. Nothing is cached
|
|
173
|
+
* between calls; instances are safe to share across workspaces and concurrent enables.
|
|
174
|
+
*/
|
|
175
|
+
export interface DeclarativeContentTypes {
|
|
176
|
+
/**
|
|
177
|
+
* The declarative half of a manifest's validation: its `contentTypes`, plus — for a `tier-1`
|
|
178
|
+
* plugin — the rule that it declares no code surface. Hooks, capability grants and `ext` fields
|
|
179
|
+
* all exist to be used by plugin code, and a Tier-1 plugin is never imported (ADR-024 §1: "zero
|
|
180
|
+
* executable code"), so declaring one is either a mistake or an attempt to look like something it
|
|
181
|
+
* is not. `validateManifest()` calls this, so discovery lists a bad declaration as `invalid`
|
|
182
|
+
* instead of it failing only at enable. A surface that is not an array is left to
|
|
183
|
+
* `validateManifest`'s own malformed check (reported once, not twice).
|
|
184
|
+
* @agent-note Collect-all, never throws; code-surface errors come before declaration errors.
|
|
185
|
+
*/
|
|
186
|
+
validateManifest(required: {
|
|
187
|
+
manifest: DeclarativeManifestView;
|
|
188
|
+
}, optional?: Record<string, never>): ParseDeclaredContentTypesResult;
|
|
189
|
+
/**
|
|
190
|
+
* Parses a manifest's raw `contentTypes` value. Collect-all, never throws (same contract as
|
|
191
|
+
* `validateManifest`). `undefined`/`null` declare nothing.
|
|
192
|
+
* @agent-note Errors keep declaration order, field errors inside their type, duplicates last.
|
|
193
|
+
*/
|
|
194
|
+
parse(required: {
|
|
195
|
+
value: unknown;
|
|
196
|
+
}, optional?: Record<string, never>): ParseDeclaredContentTypesResult;
|
|
197
|
+
/** @agent-note Read-only: one `findByKey` per declaration, in order; writes nothing, even when
|
|
198
|
+
* every type is new. A conflict on any type empties `items`. */
|
|
199
|
+
plan(required: {
|
|
200
|
+
ports: Pick<DeclaredContentTypeWritePorts, "findByKey">;
|
|
201
|
+
workspaceId: string;
|
|
202
|
+
decls: readonly DeclaredContentTypeDefinition[];
|
|
203
|
+
}, optional?: Record<string, never>): Promise<DeclaredContentTypeDefinitionPlan>;
|
|
204
|
+
/**
|
|
205
|
+
* Carries out a conflict-free plan. Each create is recorded as `plugin:<id>` so the content-type
|
|
206
|
+
* revision log says which plugin made the type; losing a concurrent create race is judged against
|
|
207
|
+
* the winning type — kept only when it matches the declaration. Any other failure is rethrown
|
|
208
|
+
* as-is.
|
|
209
|
+
* @agent-note Sequential, in plan order; never removes or overwrites a type. A lost race is
|
|
210
|
+
* recognized ONLY through `DeclaredContentTypeCms.isAlreadyExists`; an incompatible winner throws
|
|
211
|
+
* this package's canonical `PluginInvalidError`; an unrecognized error is rethrown with its
|
|
212
|
+
* identity. Types created before a failure stay (retain-by-default).
|
|
213
|
+
*/
|
|
214
|
+
apply(required: {
|
|
215
|
+
ports: DeclaredContentTypeWritePorts;
|
|
216
|
+
workspaceId: string;
|
|
217
|
+
pluginId: string;
|
|
218
|
+
plan: DeclaredContentTypeDefinitionPlan;
|
|
219
|
+
}, optional?: Record<string, never>): Promise<ApplyDeclaredContentTypesResult>;
|
|
220
|
+
}
|
|
221
|
+
/** @agent-note Both members are required host inputs; there is no built-in vocabulary or key list. */
|
|
222
|
+
export interface CreateDeclarativeContentTypesRequired {
|
|
223
|
+
/** @agent-note The host's content-type vocabulary; see {@link DeclaredContentTypeCms}. */
|
|
224
|
+
readonly cms: DeclaredContentTypeCms;
|
|
225
|
+
/**
|
|
226
|
+
* Keys no plugin may declare: the host's own permanently reserved and system content types.
|
|
227
|
+
* @agent-note Required, no default. Copied into a new `Set` once, when the instance is created:
|
|
228
|
+
* later changes to the passed collection have no effect, and separate instances keep separate
|
|
229
|
+
* sets. A declared key in the set is refused at parse as "reserved by core".
|
|
230
|
+
*/
|
|
231
|
+
readonly reservedKeys: Iterable<string>;
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Binds the declaration grammar, tier rule, planner and provisioner to one host's content-type
|
|
235
|
+
* vocabulary and reserved keys.
|
|
236
|
+
*
|
|
237
|
+
* @agent-note Second-host rules: call once at composition and share the result (see
|
|
238
|
+
* {@link DeclarativeContentTypes}). Creation does no I/O and calls none of the `cms` members.
|
|
239
|
+
* The host keeps the manifest file name, the write path, authorization, storage envelope and
|
|
240
|
+
* reserved keys; this factory keeps only plugin-domain bounds, grammar and outcomes.
|
|
241
|
+
*
|
|
242
|
+
* @example createDeclarativeContentTypes({ cms: hostContentTypeVocabulary, reservedKeys: ["page"] }, {})
|
|
243
|
+
*/
|
|
244
|
+
export declare function createDeclarativeContentTypes(requiredArgs: CreateDeclarativeContentTypesRequired, _optionalArgs?: Record<string, never>): DeclarativeContentTypes;
|
|
245
|
+
//# sourceMappingURL=declarative-content-types.d.ts.map
|