@jini-ai/plugins 0.7.2 → 0.7.3-next.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.
Files changed (81) hide show
  1. package/README.md +1 -1
  2. package/dist/core/manifest-keys.d.ts +8 -0
  3. package/dist/core/manifest-keys.js +16 -0
  4. package/dist/glue/attachment-points/content-lifecycle.d.ts +6 -7
  5. package/dist/glue/attachment-points/content-lifecycle.js +1 -1
  6. package/dist/glue/capability-gate.d.ts +2 -2
  7. package/dist/glue/manifest.js +2 -12
  8. package/dist/host/activation.d.ts +4 -5
  9. package/dist/host/admin-response.d.ts +2 -3
  10. package/dist/host/attach-loaded-plugin.d.ts +4 -4
  11. package/dist/host/attach-loaded-plugin.js +2 -2
  12. package/dist/host/browser-providers.d.ts +1 -1
  13. package/dist/host/capability-sdk.d.ts +8 -7
  14. package/dist/host/capability-sdk.js +39 -31
  15. package/dist/host/capability-tools.d.ts +4 -3
  16. package/dist/host/capability-tools.js +250 -238
  17. package/dist/host/contributions.d.ts +7 -66
  18. package/dist/host/contributions.js +64 -51
  19. package/dist/host/declarative-content-types.d.ts +6 -6
  20. package/dist/host/declarative-content-types.js +141 -135
  21. package/dist/host/declarative-enable.js +1 -1
  22. package/dist/host/discovery-types.d.ts +3 -3
  23. package/dist/host/hook-registry.d.ts +9 -9
  24. package/dist/host/hook-registry.js +86 -76
  25. package/dist/host/index.d.ts +1 -2
  26. package/dist/host/index.js +1 -1
  27. package/dist/host/manifest-types.d.ts +6 -59
  28. package/dist/host/manifest.d.ts +6 -5
  29. package/dist/host/manifest.js +5 -41
  30. package/dist/host/node/discovery.d.ts +1 -1
  31. package/dist/host/node/discovery.js +5 -6
  32. package/dist/host/node/index.d.ts +3 -0
  33. package/dist/host/node/index.js +2 -0
  34. package/dist/host/node/install.js +4 -4
  35. package/dist/host/node/integrity-command.d.ts +8 -0
  36. package/dist/host/node/integrity-command.js +26 -0
  37. package/dist/host/node/invocation-binding.d.ts +1 -1
  38. package/dist/host/node/invocation-binding.js +1 -1
  39. package/dist/host/node/loader.d.ts +3 -2
  40. package/dist/host/node/loader.js +12 -12
  41. package/dist/host/node/module-snapshot.d.ts +20 -0
  42. package/dist/host/node/module-snapshot.js +31 -0
  43. package/dist/host/node/open-flags.d.ts +4 -1
  44. package/dist/host/node/open-flags.js +1 -1
  45. package/dist/host/node/package-files.js +1 -1
  46. package/dist/host/node/provider-artifact.d.ts +1 -2
  47. package/dist/host/node/runtime-contracts.d.ts +238 -0
  48. package/dist/host/node/runtime-contracts.js +2 -0
  49. package/dist/host/node/runtime-core.d.ts +1 -243
  50. package/dist/host/node/runtime-core.js +18 -114
  51. package/dist/host/node/runtime-load-target.d.ts +44 -0
  52. package/dist/host/node/runtime-load-target.js +45 -0
  53. package/dist/host/node/runtime-package-location.d.ts +45 -0
  54. package/dist/host/node/runtime-package-location.js +57 -0
  55. package/dist/host/node/source-drafts.d.ts +4 -2
  56. package/dist/host/node/source-drafts.js +107 -39
  57. package/dist/host/ports.d.ts +2 -38
  58. package/dist/host/provider-contributions.d.ts +2 -14
  59. package/dist/host/provider-contributions.js +1 -1
  60. package/dist/host/provider-host.d.ts +4 -19
  61. package/dist/host/provider-host.js +83 -71
  62. package/dist/host/provider-revision-watch.d.ts +36 -0
  63. package/dist/host/provider-revision-watch.js +52 -0
  64. package/dist/host/provider-setting-required.d.ts +1 -7
  65. package/dist/host/provider-setting-required.js +1 -18
  66. package/dist/host/provider-settings-migrations.d.ts +1 -1
  67. package/dist/host/repo.memory.d.ts +1 -1
  68. package/dist/host/repo.memory.js +1 -1
  69. package/dist/host/sql/repo.d.ts +4 -3
  70. package/dist/host/sql/repo.rows.js +2 -2
  71. package/dist/host/tool-contributions.d.ts +2 -1
  72. package/dist/host/tool-contributions.js +1 -0
  73. package/dist/host/tools/install.js +1 -0
  74. package/dist/host/tools/management.js +97 -83
  75. package/dist/host/uninstall.d.ts +1 -1
  76. package/dist/host/worker/import-seam.d.ts +2 -2
  77. package/dist/host/worker/protocol.d.ts +2 -2
  78. package/dist/host/worker/run-call.d.ts +2 -1
  79. package/dist/host/worker/run-call.js +2 -2
  80. package/dist/host/worker/start.js +1 -1
  81. package/package.json +7 -17
@@ -1,4 +1,4 @@
1
- import { buildDomainRegistrations, indexCatalogById, isRecord, redactSecrets, requireInputRecord, requireString, ToolInputError, requireToolPermission, adaptLegacyAuthorize } from "@jini-ai/core";
1
+ import { buildDomainRegistrations, indexCatalogById, isRecord, describeErrorForLog, requireInputRecord, requireString, ToolInputError, requireToolPermission, adaptLegacyAuthorize } from "@jini-ai/core";
2
2
  import { readPluginIdentity } from "@jini-ai/core/plugin-directory";
3
3
  import { attachPluginContributionTools } from "./tool-contributions.js";
4
4
  import { capabilityToolIdFor } from "./plugin-claims.js";
@@ -56,251 +56,263 @@ function decodeFieldValue(value) {
56
56
  * @param _optional Reserved; pass `{}`.
57
57
  */
58
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 });
59
+ const { identityNamespace, legacyIdentityNamespace, beforeSaveHook, text, catalog, access, executableAccess, approvalFamily, toPreviewDraft } = required;
60
+ const host = { identityNamespace, legacyIdentityNamespace, beforeSaveHook, text, catalog, access, executableAccess, approvalFamily, toPreviewDraft };
61
+ return {
62
+ loadSources: (deps) => loadEnabledPluginCapabilityToolSources(host, deps),
63
+ buildRegistrations: (args) => buildPluginCapabilityToolRegistrations(host, args),
64
+ registerEnabled: (args) => registerEnabledPluginCapabilityTools(host, args),
65
+ };
66
+ }
67
+ /** Fallback for a field whose manifest declares no `description` (see this file's header,
68
+ * "description text IS the fix") — weaker (a noun-phrase, not an action), but still a usable,
69
+ * non-empty tool description rather than no tool at all. */
70
+ function genericFieldDescription(host, pluginName, field) {
71
+ const { text } = host;
72
+ return text.genericFieldDescription({ pluginName, path: field.path, type: field.type });
73
+ }
74
+ /**
75
+ * Resolves one valid manifest's declared fields into tool-ready sources — `expectedPrefix` mirrors
76
+ * `manifest.ts`'s own `validateFields` derivation exactly, so a field this function accepts is
77
+ * guaranteed already-validated namespacing, never a fresh assumption this file invents.
78
+ *
79
+ * @complexity O(fields.length) — one manifest's own declared array.
80
+ */
81
+ function buildFieldSources(host, manifest) {
82
+ const expectedPrefix = `ext.${manifest.id}.`;
83
+ return manifest.fields
84
+ .filter((field) => field.path.startsWith(expectedPrefix) && field.path.length > expectedPrefix.length)
85
+ .map((field) => ({
86
+ path: field.path,
87
+ fieldKey: field.path.slice(expectedPrefix.length),
88
+ type: field.type,
89
+ description: field.description ?? genericFieldDescription(host, manifest.name, field),
90
+ }));
91
+ }
92
+ /**
93
+ * Builds this plugin tool's model-facing description — an operator SEARCH TARGET, not a card blurb
94
+ * (mirrors `agent-plugins/tool-registrations.ts`'s `buildPluginToolDescription` doc on the same
95
+ * point). Leads with an imperative action clause, folds in every field's own description text (the
96
+ * actual indexed vocabulary a real query needs to match), and states the `postId` precondition and
97
+ * the "no data yet" outcome up front so a model reading only this description already knows how to
98
+ * call it and what an empty result means.
99
+ */
100
+ function buildCapabilityToolDescription(host, manifest, fields) {
101
+ const { identityNamespace, legacyIdentityNamespace, beforeSaveHook, text } = host;
102
+ const identity = readPluginIdentity({ manifest: manifest, name: manifest.id, namespace: identityNamespace, legacyNamespace: legacyIdentityNamespace });
103
+ const fieldText = fields.map((field) => field.description).join(" ") + text.discovery({ terms: [identity.id, ...identity.keywords, ...identity.provides].join(" ") });
104
+ if (runsFreshFor(manifest, beforeSaveHook)) {
105
+ return text.freshDescription({ pluginName: manifest.name, fieldText });
99
106
  }
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;
107
+ return text.storedDescription({ pluginName: manifest.name, fieldText });
108
+ }
109
+ /**
110
+ * Loads every ENABLED, valid plugin-runtime plugin that declares at least one field, resolved into
111
+ * one tool-ready source per plugin. See this file's header, "Activation gate", for why "enabled"
112
+ * here means `activation.enabled === true` — the opposite default from Agent Plugins.
113
+ *
114
+ * @complexity O(p) plugin-discovery calls times one `pluginActivationRepo.getActivation` each,
115
+ * dominated by `discoverPlugins()`'s own I/O (unchanged, not re-read per plugin).
116
+ */
117
+ async function loadEnabledPluginCapabilityToolSources(host, deps) {
118
+ const { beforeSaveHook } = host;
119
+ const discovery = await deps.discoverPlugins();
120
+ const sources = [];
121
+ for (const record of discovery) {
122
+ // No fields means nothing this plugin's tool could ever return. Disabled (or never activated)
123
+ // plugins stay out too — see this file's header. Preserve that short-circuit order.
124
+ if (record.status !== "valid" || !record.manifest || record.manifest.fields.length === 0 ||
125
+ !(await isPluginEnabledInWorkspace(deps.pluginActivationRepo, deps.workspaceId, record.id)))
126
+ continue;
127
+ const fields = buildFieldSources(host, record.manifest);
128
+ if (fields.length > 0)
129
+ sources.push({
130
+ id: capabilityToolIdFor({ pluginId: record.id }),
131
+ pluginId: record.id,
132
+ pluginName: record.manifest.name,
133
+ description: buildCapabilityToolDescription(host, record.manifest, fields),
134
+ fields,
135
+ runsFresh: runsFreshFor(record.manifest, beforeSaveHook),
136
+ });
129
137
  }
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
- },
138
+ return sources;
139
+ }
140
+ function buildCapabilityInputSchema(host) {
141
+ const { text } = host;
142
+ return {
143
+ type: "object",
144
+ additionalProperties: false,
145
+ required: ["postId"],
146
+ properties: {
147
+ postId: {
148
+ type: "string",
149
+ minLength: 1,
150
+ description: text.postIdDescription,
141
151
  },
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
- }
152
+ },
153
+ };
154
+ }
155
+ /** Projects one plugin's field bag — stored, or fresh from the preview port (`computedNow`) — onto
156
+ * its declared fields, adding the "not computed yet" note when none of them has a value. */
157
+ function buildCapabilityToolResult(host, { source, post, bag }) {
158
+ const { text } = host;
159
+ const pluginBag = bag.values;
160
+ const fields = {};
161
+ let anyComputed = false;
162
+ for (const field of source.fields) {
163
+ const value = pluginBag ? pluginBag[field.fieldKey] : undefined;
164
+ fields[field.fieldKey] = value === undefined ? null : decodeFieldValue(value);
165
+ if (value !== undefined)
166
+ anyComputed = true;
214
167
  }
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
- };
168
+ return {
169
+ postId: post.id,
170
+ pluginId: source.pluginId,
171
+ computedNow: bag.computedNow,
172
+ fields,
173
+ ...(anyComputed
174
+ ? {}
175
+ : {
176
+ note: text.noDataNote({ pluginName: source.pluginName }),
177
+ }),
178
+ };
179
+ }
180
+ /** The field bag one call answers with: a fresh preview for a {@link PluginCapabilityToolSource.runsFresh}
181
+ * source when the port is injected and this process has the plugin attached, otherwise the stored one.
182
+ * The draft is the post exactly as stored — the same fields `post.ts` hands the filter on an update.
183
+ * @throws {ToolInputError} the fresh run failed; the cause stays on the error, the model sees fixed text.
184
+ * @complexity one post-draft preview (a worker round trip for tier-2) or none. */
185
+ async function resolveFieldBag(host, { source, post, deps }) {
186
+ const { text, toPreviewDraft } = host;
187
+ const preview = source.runsFresh ? deps.previewPluginBeforeSave : undefined;
188
+ const fresh = preview
189
+ ? await preview(source.pluginId, toPreviewDraft({ post })).catch((error) => {
190
+ throw new ToolInputError({
191
+ message: text.previewFailed({ pluginName: source.pluginName, postId: post.id }),
192
+ }, { cause: error });
193
+ })
194
+ : null;
195
+ return fresh ? { values: fresh, computedNow: true } : { values: readStoredFieldBag(source, post), computedNow: false };
196
+ }
197
+ /** One source's catalog entry. The host's `access.permission` — the same object the handler checks. */
198
+ function capabilityCatalogEntry(host, source) {
199
+ const { access } = host;
200
+ return {
201
+ name: source.id,
202
+ description: source.description,
203
+ sideEffects: "none",
204
+ authorization: { permission: access.permission },
205
+ inputSchema: buildCapabilityInputSchema(host),
206
+ };
207
+ }
208
+ /** One source's handler. @complexity one permission check, one post read, and at most one fresh preview. */
209
+ function capabilityToolHandler(host, source, deps) {
210
+ const { access } = host;
211
+ return async (ctx) => {
212
+ const input = requireInputRecord({ input: ctx.input });
213
+ const postId = requireString({ input: input, key: "postId" });
214
+ await requireToolPermission({ authorize: adaptLegacyAuthorize({ authorize: deps.authorize }), workspaceId: deps.workspaceId, principalId: ctx.principal.id, permission: access.permission }, { entityType: access.entityType, entityId: postId });
215
+ const post = await deps.postRead.readRequired({ workspaceId: deps.workspaceId, id: postId });
216
+ return buildCapabilityToolResult(host, { source, post, bag: await resolveFieldBag(host, { source, post, deps }) });
217
+ };
218
+ }
219
+ /** Whether `pluginId` may run right now. A read that throws DENIES and is logged, rather than surfacing as a
220
+ * failed execution whose cause the daemon redacts. @complexity one activation-row read. */
221
+ async function isCapabilityCallableNow(host, deps, pluginId) {
222
+ const { text } = host;
223
+ try {
224
+ return await isPluginEnabledInWorkspace(deps.pluginActivationRepo, deps.workspaceId, pluginId);
233
225
  }
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 })));
226
+ catch (error) {
227
+ console.warn(text.activationReadDenied({ pluginId, detail: describeErrorForLog({ err: error }) }));
228
+ return false;
260
229
  }
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 };
230
+ }
231
+ /**
232
+ * Wraps one registration's policy so the plugin's CURRENT activation is re-read before its handler can be
233
+ * reached, then defers to the policy `buildDomainRegistrations` attached — the same shape and reason as
234
+ * `agent-plugins/tool-registrations.ts`'s `withToolGate` (a future kit policy must not be silently dropped).
235
+ * @complexity O(1) plus one activation-row read per call.
236
+ */
237
+ function withActivationGate(host, registration, { deps, pluginId }) {
238
+ const inner = registration.policy;
239
+ return {
240
+ ...registration,
241
+ policy: {
242
+ async authorize(authCtx) {
243
+ if (!(await isCapabilityCallableNow(host, deps, pluginId)))
244
+ return "deny";
245
+ return inner.authorize(authCtx);
270
246
  },
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
- }
247
+ },
248
+ };
249
+ }
250
+ /**
251
+ * Turns already-resolved plugin capability sources into real `ToolRegistration`s — pure and
252
+ * synchronous, unlike {@link loadEnabledPluginCapabilityToolSources}, so this half is unit-tested
253
+ * without touching activation/discovery I/O. Uses the same `buildDomainRegistrations` gate every
254
+ * other domain's `tool-registrations.ts` uses (catalog/risk cross-check, `inputSchema` presence,
255
+ * drift tripwire) — not a parallel mechanism.
256
+ *
257
+ * Permission: the host's `access.permission`, the same permission its own post read tool requires —
258
+ * this tool reads a post's already-persisted data, nothing a plugin-specific permission would
259
+ * meaningfully narrow further (mirrors that tool's own inline `requireToolPermission` call exactly,
260
+ * including the `entityType`/`entityId` pair so a per-post authorization rule can still apply).
261
+ *
262
+ * Every registration carries the per-call activation gate (`withActivationGate`) — see this file's
263
+ * header, "Revocation". Built one source at a time so the owning plugin id is in scope for every
264
+ * registration the kit returns: there is no id-to-plugin lookup that could miss and leave a tool
265
+ * ungated. The build stays synchronous and touches no I/O; the gate reads only when a call is
266
+ * authorized.
267
+ */
268
+ function buildPluginCapabilityToolRegistrations(host, { sources, deps, applyApprovalPolicy }, _optionalArgs = {}) {
269
+ const { catalog, approvalFamily } = host;
270
+ return sources.flatMap((source) => buildDomainRegistrations({ metadata: catalog.metadata,
271
+ domain: catalog.domain,
272
+ catalogModule: catalog.catalogModule,
273
+ catalog: indexCatalogById({ catalog: [capabilityCatalogEntry(host, source)] }),
274
+ handlers: { [source.id]: capabilityToolHandler(host, source, deps) },
275
+ derivedRisk: pluginCapabilityToolDerivedRisk({ sources: [source] }),
276
+ }).map((registration) => applyApprovalPolicy({ registration: withActivationGate(host, registration, { deps, pluginId: source.pluginId }), family: approvalFamily })));
277
+ }
278
+ /** Product authorization and approval inputs for Jini's executable registration owner. */
279
+ function executablePluginToolPorts(host, { deps, contributions }) {
280
+ const { executableAccess } = host;
281
+ // The caller passes the bound registry it just checked, so there is no unbound case to refuse here.
300
282
  return {
301
- loadSources: (deps) => loadEnabledPluginCapabilityToolSources(deps),
302
- buildRegistrations: (args) => buildPluginCapabilityToolRegistrations(args),
303
- registerEnabled: (args) => registerEnabledPluginCapabilityTools(args),
283
+ contributions,
284
+ isEnabled: async ({ pluginId }) => (await deps.pluginActivationRepo.getActivation({ workspaceId: deps.workspaceId, pluginId }))?.enabled === true,
285
+ resolveAuth: async ({ pluginId, principalId }) => {
286
+ await requireToolPermission({ authorize: adaptLegacyAuthorize({ authorize: deps.authorize }), workspaceId: deps.workspaceId, principalId, permission: executableAccess.permission }, { entityType: executableAccess.entityType, entityId: pluginId });
287
+ return { access: 'admin', principalId, workspaceId: deps.workspaceId };
288
+ },
289
+ // In-process arbitrary code can leave this site. Its prose cannot self-classify it as read-only.
290
+ // The assistant decides when to invoke it; only permanent-delete tools require confirmation.
291
+ metadata: executableAccess.metadata,
304
292
  };
305
293
  }
294
+ /**
295
+ * Composition-root entry point: loads every enabled, field-declaring plugin for one workspace and
296
+ * registers each as a real tool directly on `registry` — the same `registry.register(registration)`
297
+ * call `agent-daemon-server.ts`'s own loops make for every other contributor's output, just awaited
298
+ * first (mirrors `registerInstalledAgentPluginTools`'s identical shape and rationale).
299
+ *
300
+ * @throws Whatever `registry.register()` itself throws on an id collision (`@jini-ai/core`'s
301
+ * `createToolRegistry()` throws synchronously — see this file's header) — deliberately not caught
302
+ * here; the caller's own fail-open `try/catch` (matching `registerInstalledAgentPluginTools`'s and
303
+ * `registerInstalledSkillTools`'s call sites in `agent-daemon-server.ts`) is where that is handled,
304
+ * so all three optional registrars degrade identically on failure.
305
+ *
306
+ * Registers with the per-call activation gate, so a tool this puts into the daemon's registry is
307
+ * refused the moment its plugin is disabled, quarantined or uninstalled.
308
+ */
309
+ async function registerEnabledPluginCapabilityTools(host, { registry, deps, applyApprovalPolicy }, _optionalArgs = {}) {
310
+ const sources = await loadEnabledPluginCapabilityToolSources(host, deps);
311
+ for (const registration of buildPluginCapabilityToolRegistrations(host, { sources, deps, applyApprovalPolicy })) {
312
+ registry.register(registration);
313
+ }
314
+ if (deps.pluginContributions && (deps.executablePluginToolRegistry || (registry.has && registry.list))) {
315
+ attachPluginContributionTools({ ...executablePluginToolPorts(host, { deps, contributions: deps.pluginContributions }), registry: deps.executablePluginToolRegistry ?? registry });
316
+ }
317
+ }
306
318
  //# sourceMappingURL=capability-tools.js.map
@@ -1,64 +1,7 @@
1
- /** Executable contribution admission on the existing plugin loader, never a second loader.
2
- * Captures stay private until setup succeeds. A sealed generation cannot register from a timer.
3
- * Tier-3 currently runs with full in-process authority; a hardened worker at this boundary is
4
- * still to come. */
5
- import { type PluginProviderContribution } from './provider-contributions.js';
1
+ import { type PluginProviderContribution } from '@jini-ai/core/contracts/plugin-sdk';
6
2
  import type { PluginManifest } from './manifest-types.js';
7
- import type { PluginSdk } from './ports.js';
3
+ import type { PluginRouteContribution, PluginSdk, PluginToolContribution, PluginWidgetContribution } from '@jini-ai/core/contracts/plugin-sdk';
8
4
  export declare const PLUGIN_CONTRIBUTION_CAPABILITIES: readonly ["http.route.register", "tools.register", "render.contribute", "providers.register"];
9
- export type PluginRouteAccess = 'public' | 'member' | 'admin';
10
- export interface PluginAuthContext {
11
- readonly access: PluginRouteAccess;
12
- readonly principalId?: string;
13
- readonly workspaceId: string;
14
- }
15
- export interface PluginInvocationContext {
16
- readonly pluginId: string;
17
- readonly auth: PluginAuthContext;
18
- readonly sdk: PluginSdk;
19
- readonly signal?: AbortSignal;
20
- }
21
- export interface PluginRouteInput extends PluginInvocationContext {
22
- readonly body: unknown;
23
- readonly params: Readonly<Record<string, string>>;
24
- readonly query: Readonly<Record<string, unknown>>;
25
- }
26
- export interface PluginRouteResult {
27
- readonly status?: number;
28
- readonly body?: unknown;
29
- }
30
- export interface PluginRouteContribution {
31
- readonly method: string;
32
- readonly path: string;
33
- readonly access: PluginRouteAccess;
34
- readonly handler: (required: PluginRouteInput, optional?: Record<string, never>) => PluginRouteResult | void | Promise<PluginRouteResult | void>;
35
- }
36
- /** Declared change class. Only ever tightens host policy: `destructive` forces confirmation. */
37
- export type PluginToolEffect = 'read' | 'write' | 'destructive';
38
- export interface PluginToolContribution {
39
- readonly name: string;
40
- readonly description: string;
41
- readonly inputSchema: Readonly<Record<string, unknown>>;
42
- readonly effect?: PluginToolEffect;
43
- readonly handler: (required: PluginInvocationContext & {
44
- readonly input: unknown;
45
- }, optional?: Record<string, never>) => unknown | Promise<unknown>;
46
- }
47
- export interface PluginWidgetContribution {
48
- readonly name: string;
49
- /** Public SSR only. Host sanitizes the bounded HTML before partial placement (ADR-025). */
50
- readonly render: (required: PluginInvocationContext, optional?: Record<string, never>) => string | Promise<string>;
51
- }
52
- export type PluginContribution = {
53
- readonly kind: 'route';
54
- readonly value: PluginRouteContribution;
55
- } | {
56
- readonly kind: 'tool';
57
- readonly value: PluginToolContribution;
58
- } | {
59
- readonly kind: 'widget';
60
- readonly value: PluginWidgetContribution;
61
- };
62
5
  export interface PluginContributionsSnapshot {
63
6
  readonly pluginId: string;
64
7
  readonly sdk: PluginSdk;
@@ -85,17 +28,15 @@ export declare function createPluginContributionCapture(required: {
85
28
  }, optional?: {
86
29
  maxContributions?: number;
87
30
  }): {
88
- providers: {
89
- register(value: PluginProviderContribution, _optional?: Record<string, never>): void;
90
- };
31
+ providers: import("@jini-ai/core/contracts/plugin-sdk").PluginProvidersSdk;
91
32
  routes: {
92
- add(value: PluginRouteContribution, _optional?: Record<string, never>): void;
33
+ add(required: PluginRouteContribution, optional?: Record<string, never>): void;
93
34
  };
94
35
  tools: {
95
- add(value: PluginToolContribution, _optional?: Record<string, never>): void;
36
+ add(required: PluginToolContribution, optional?: Record<string, never>): void;
96
37
  };
97
38
  widgets: {
98
- add(value: PluginWidgetContribution, _optional?: Record<string, never>): void;
39
+ add(required: PluginWidgetContribution, optional?: Record<string, never>): void;
99
40
  };
100
41
  seal({ sdk }: {
101
42
  sdk: PluginSdk;
@@ -118,7 +59,7 @@ export interface PluginContributionRegistry {
118
59
  export declare function createPluginContributionRegistry(_required: Record<string, never>, _optional?: Record<string, never>): PluginContributionRegistry;
119
60
  /** Resolves only named public fragments, isolating failures and bounding the awaited work.
120
61
  * Validation is an injected host renderer port; plugins cannot substitute their own validator.
121
- * Client enhancement JS is still pending: it waits for an ADR-025 owner amendment. */
62
+ * Client enhancement JS is still pending: it waits for an owner amendment. */
122
63
  export declare function renderPluginWidgetFragments(required: {
123
64
  registry: PluginContributionRegistry;
124
65
  names: readonly string[];