@jini-ai/plugins 0.7.3-next.1 → 0.7.3-next.3

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 (104) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/README.md +53 -0
  3. package/dist/host/activation-polling.d.ts +67 -0
  4. package/dist/host/activation-polling.js +113 -0
  5. package/dist/host/activation.d.ts +2 -30
  6. package/dist/host/capability-tools.d.ts +1 -0
  7. package/dist/host/capability-tools.js +4 -4
  8. package/dist/host/contributions.d.ts +2 -9
  9. package/dist/host/hook-refusals.d.ts +49 -0
  10. package/dist/host/hook-refusals.js +65 -0
  11. package/dist/host/index.d.ts +3 -1
  12. package/dist/host/index.js +1 -0
  13. package/dist/host/manifest.js +2 -2
  14. package/dist/host/node/browser-provider-assets.d.ts +2 -1
  15. package/dist/host/node/browser-provider-assets.js +2 -2
  16. package/dist/host/node/discovery.js +5 -5
  17. package/dist/host/node/install.d.ts +6 -1
  18. package/dist/host/node/install.js +22 -20
  19. package/dist/host/node/integrity-command.d.ts +2 -1
  20. package/dist/host/node/integrity-command.js +3 -3
  21. package/dist/host/node/loader.d.ts +3 -2
  22. package/dist/host/node/loader.js +6 -6
  23. package/dist/host/node/module-snapshot.d.ts +4 -3
  24. package/dist/host/node/module-snapshot.js +5 -5
  25. package/dist/host/node/package-files.d.ts +2 -1
  26. package/dist/host/node/package-files.js +6 -6
  27. package/dist/host/node/runtime-activation.d.ts +35 -0
  28. package/dist/host/node/runtime-activation.js +188 -0
  29. package/dist/host/node/runtime-boot.d.ts +16 -0
  30. package/dist/host/node/runtime-boot.js +153 -0
  31. package/dist/host/node/runtime-conflicts.d.ts +38 -0
  32. package/dist/host/node/runtime-conflicts.js +42 -0
  33. package/dist/host/node/runtime-contracts.d.ts +5 -3
  34. package/dist/host/node/runtime-core.js +65 -465
  35. package/dist/host/node/runtime-load-target.d.ts +14 -0
  36. package/dist/host/node/runtime-load-target.js +15 -0
  37. package/dist/host/node/runtime-reload.d.ts +12 -0
  38. package/dist/host/node/runtime-reload.js +107 -0
  39. package/dist/host/node/runtime-state.d.ts +52 -0
  40. package/dist/host/node/runtime-state.js +50 -0
  41. package/dist/host/node/source-drafts.d.ts +1 -1
  42. package/dist/host/node/source-drafts.js +17 -15
  43. package/dist/host/plugin-claims.d.ts +2 -9
  44. package/dist/host/plugin-format.d.ts +5 -5
  45. package/dist/host/plugin-format.js +9 -10
  46. package/dist/host/ports.d.ts +4 -28
  47. package/dist/host/tools/install.js +1 -1
  48. package/dist/host/uninstall.d.ts +2 -2
  49. package/dist/host/worker/import-policy.d.ts +49 -0
  50. package/dist/host/worker/import-policy.js +86 -0
  51. package/dist/host/worker/import-seam.js +21 -2
  52. package/dist/host/worker/index.d.ts +1 -0
  53. package/dist/host/worker/index.js +1 -0
  54. package/dist/host/worker/protocol.d.ts +4 -0
  55. package/dist/host/worker/run-call.js +2 -1
  56. package/dist/host/worker/start.d.ts +18 -1
  57. package/dist/host/worker/start.js +27 -6
  58. package/dist/react/PluginProviderSettingsDialog.d.ts +144 -0
  59. package/dist/react/PluginProviderSettingsDialog.js +54 -0
  60. package/dist/react/plugin-install-port.d.ts +29 -0
  61. package/dist/react/plugin-install-port.js +15 -0
  62. package/dist/runtime/agent-tools.d.ts +174 -0
  63. package/dist/runtime/agent-tools.js +121 -0
  64. package/dist/runtime/built-ins/word-count/count-words.d.ts +21 -0
  65. package/dist/runtime/built-ins/word-count/count-words.js +48 -0
  66. package/dist/runtime/built-ins/word-count/plugin.d.ts +6 -0
  67. package/dist/runtime/built-ins/word-count/plugin.js +12 -0
  68. package/dist/runtime/capability-card.d.ts +22 -0
  69. package/dist/runtime/capability-card.js +30 -0
  70. package/dist/runtime/enable-confirmation-ui.d.ts +28 -0
  71. package/dist/runtime/enable-confirmation-ui.js +54 -0
  72. package/dist/runtime/install-consent.d.ts +12 -0
  73. package/dist/runtime/install-consent.js +27 -0
  74. package/dist/runtime/install-source.d.ts +26 -0
  75. package/dist/runtime/install-source.js +61 -0
  76. package/dist/runtime/install-tool-catalog.d.ts +9 -0
  77. package/dist/runtime/install-tool-catalog.js +25 -0
  78. package/dist/runtime/lower-tool-access.d.ts +17 -0
  79. package/dist/runtime/lower-tool-access.js +14 -0
  80. package/dist/runtime/plugin-export.d.ts +13 -0
  81. package/dist/runtime/plugin-export.js +14 -0
  82. package/dist/runtime/plugin-host-copy.d.ts +17 -0
  83. package/dist/runtime/plugin-host-copy.js +7 -0
  84. package/dist/runtime/plugin-tool-ids.d.ts +18 -0
  85. package/dist/runtime/plugin-tool-ids.js +4 -0
  86. package/dist/runtime/plugin-tool-messages.d.ts +97 -0
  87. package/dist/runtime/plugin-tool-messages.js +90 -0
  88. package/dist/runtime/sdk-resolver.d.ts +60 -0
  89. package/dist/runtime/sdk-resolver.js +97 -0
  90. package/dist/runtime/service-ports.d.ts +43 -0
  91. package/dist/runtime/service-ports.js +3 -0
  92. package/dist/runtime/source-tool-catalog.d.ts +7 -0
  93. package/dist/runtime/source-tool-catalog.js +33 -0
  94. package/dist/runtime/uninstall-confirmation-ui.d.ts +31 -0
  95. package/dist/runtime/uninstall-confirmation-ui.js +38 -0
  96. package/dist/runtime/widget-partials.d.ts +22 -0
  97. package/dist/runtime/widget-partials.js +13 -0
  98. package/dist/site/lipay/manifest.d.ts +10 -0
  99. package/dist/site/lipay/manifest.js +96 -0
  100. package/dist/site/store/manifest.d.ts +10 -0
  101. package/dist/site/store/manifest.js +37 -0
  102. package/package.json +158 -8
  103. package/dist/host/provider-config-source.d.ts +0 -47
  104. package/dist/host/provider-config-source.js +0 -2
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @jini-ai/plugins
2
2
 
3
+ ## 0.7.2
4
+
5
+ ### Patch Changes
6
+
7
+ - @jini-ai/core@0.7.2
8
+
3
9
  ## 0.7.1
4
10
 
5
11
  ### Patch Changes
package/README.md CHANGED
@@ -56,6 +56,54 @@ Historical note — 2026-08-18: [DR-005 portable package boundaries](../../docs/
56
56
  kept the host format reserved until a real consumer justified its implementation. The 2026-10-07
57
57
  p6 extraction implements that format under the approved CMS/Jini modular design Rev 3.
58
58
 
59
+ ## Wiring
60
+
61
+ `./runtime/*` holds host-neutral pieces lifted from a host's plugin runtime. They need nothing
62
+ injected: `./runtime/plugin-export`'s `readDefinedPlugin({ moduleValue }, {})` is pure and returns
63
+ the module's `definePlugin()` default export (`DefinedPlugin` from `@jini-ai/core/contracts/plugin-sdk`)
64
+ or `null`. A host binds it as its `PluginSdkBinding.readDefinedPlugin`:
65
+
66
+ ```ts
67
+ import type { PluginSdkBinding } from '@jini-ai/plugins/host';
68
+ import { readDefinedPlugin } from '@jini-ai/plugins/runtime/plugin-export';
69
+
70
+ const pluginSdkBinding: PluginSdkBinding = {
71
+ ...hostSdkAbi, // hook ids, semantics, runtimeSdkVersion, buildSdk, definePlugin
72
+ readDefinedPlugin: ({ moduleValue }) => readDefinedPlugin({ moduleValue }, {}),
73
+ };
74
+ ```
75
+
76
+ `./runtime/*` must never import a host SDK package, node built-ins, or another `@jini-ai/*`
77
+ implementation; types come from `@jini-ai/core` contracts. Boundaries: [DR-005](../../docs/decisions/DR-005-portable-package-boundaries.md).
78
+
79
+ Model-facing plugin text takes the host's product copy (`PluginHostCopy` from
80
+ `./runtime/plugin-host-copy`: `productName`, `sitePluginFormat`, `localInstallEnv`,
81
+ `pluginListToolName` — the host's plugin list tool). The host binds
82
+ it once, in its own composition module, and passes the results to its tool bindings:
83
+
84
+ - `./runtime/agent-tools` — `createPluginAgentToolCatalog({ copy })` (plus `PluginFamily`,
85
+ `PLUGINS_SET_ENABLED_TOOL_ID`, `AgentToolDefinition`).
86
+ - `./runtime/source-tool-catalog` — `createPluginSourceAgentToolCatalog({ copy })`.
87
+ - `./runtime/install-tool-catalog` — `createInstallToolCatalog({ copy, installSourceSchema })`; the
88
+ host also injects its install-source JSON Schema. `PLUGINS_INSTALL_TOOL_ID` is a plain constant.
89
+ - `./runtime/plugin-tool-messages` — `createPluginToolMessages({ copy })` /
90
+ `createPluginInstallMessages({ copy })` return the `messages` objects the `./host/tools`
91
+ registrations take, with the same call shapes as before.
92
+ - `./runtime/capability-card` — `createCapabilityCard({ pluginsAdminHref, pluginListToolName })`; the host says where its
93
+ Plugins admin screen lives and which tool lists plugins.
94
+
95
+ `./site/lipay/manifest` and `./site/store/manifest` are the bundled first-party data-module
96
+ declarations (`LIPAY_MANIFEST`, `STORE_MANIFEST`). Nothing is injected; the host lists them in its
97
+ first-party data-module set. Their provenance publisher is `"jini-core"` — persisted in
98
+ `_plugin_identity`, so changing it is a migration (see CHANGELOG).
99
+
100
+ `./runtime/enable-confirmation-ui` (`describeEnableApproval`, `EnableConfirmationSubject`) and
101
+ `./runtime/uninstall-confirmation-ui` (`describeUninstallApproval`, `PLUGINS_UNINSTALL_TOOL_ID`) are
102
+ pure: they return a `HumanConfirmSpec` (`@jini-ai/core/contracts/site/human-confirm`) and inject
103
+ nothing. The host renders and redeems that spec through its own approval transport; it passes both
104
+ builders as the `descriptions: { enable, uninstall }` field of `PluginManagementToolsRequired`
105
+ (`./host/tools`) when it binds the plugin management tools.
106
+
59
107
  ## Design decisions
60
108
 
61
109
  - [Attachment vocabulary and failure containment are separate decisions](docs/decisions/DR-001-category-specific-glue-containment.md).
@@ -66,3 +114,8 @@ Server provider plugins extend this same host with `contributes.providers` and a
66
114
  resources on contribution detach/replacement or shutdown. See [API.md](API.md#server-provider-contributions).
67
115
  Self-contained artifacts are distributed by `@jini-ai/provider-plugins`; there are no domain or
68
116
  vendor imports in this host extension.
117
+
118
+ ## Wiring
119
+
120
+ - `@jini-ai/plugins/host/hook-refusals`: the host wraps each save domain's handler map with `withPluginHookRefusals` (or maps one rejection with `toModelFacingPluginHookError`) and uses `pluginHookRefusalText` for its HTTP envelope; nothing to inject.
121
+ - `@jini-ai/plugins/host` activation polling: the serving host calls `startPluginActivationPolling({ workspaceId, pluginActivationRepo, onPluginEnabled, onPluginDisabled, pluginLoadedVersion?, pluginRuntimeReady }, { intervalMs })` once and calls `stop()` on shutdown; it injects its activation repo and its registry attach/detach callbacks.
@@ -0,0 +1,67 @@
1
+ /** @file Server-owned durable plugin-activation reconciliation (moved from the host composition
2
+ * root). The host passes its activation repo, workspace and attach/detach callbacks. */
3
+ import type { PluginActivationRepoPort } from "@jini-ai/core/contracts/site/plugins-host";
4
+ import type { Logger } from "@jini-ai/core/primitives";
5
+ /** Server-owned hook activation polling. The registry is process-local, while durable row
6
+ * revisions can be changed by another server/client. Polling reuses those revisions instead
7
+ * of claiming outbox events on a bus whose subscribers belong to another process.
8
+ *
9
+ * P0b's original failure was two composePluginRuntime registries: an admin enable/disable updated
10
+ * only its own registry, while the daemon kept its boot snapshot. Boot readiness fixed initial
11
+ * staleness, not later changes. Polling durable activation row versions was chosen because sharing
12
+ * content.db did not share either bus or hook registry; an enqueue-only daemon could not consume
13
+ * an outbox notification safely. ADR-070 removes that daemon registry, while the serving process
14
+ * retains this reconciliation against changes from another process. Never remove the server's
15
+ * poll merely because the daemon no longer has one. */
16
+ /** The narrow slice `startPluginActivationPolling` needs — never the whole `RouteDeps`, so a
17
+ * caller (or a test) can pass a hand-built fake without satisfying the full interface. */
18
+ export interface PluginActivationPollDeps {
19
+ readonly pluginLoadedVersion?: (required: {
20
+ id: string;
21
+ }, optional?: Record<string, never>) => string | undefined;
22
+ readonly workspaceId: string;
23
+ readonly pluginActivationRepo: Pick<PluginActivationRepoPort, "listAll">;
24
+ readonly onPluginEnabled: (pluginId: string) => Promise<void>;
25
+ readonly onPluginDisabled: (pluginId: string) => void;
26
+ /** The host's log channel; an attach or poll failure goes in its error bag, never as line text. */
27
+ readonly logger: Logger;
28
+ }
29
+ /** A plugin whose last attach failed: what was logged, and how many passes to wait before retrying.
30
+ * The 2026-11-13 charts-recharts INTEGRITY_FAILED logged the same line every 5 s poll (5,895 lines
31
+ * in a day) and re-hashed its whole payload each time. Now the first occurrence of each distinct
32
+ * failure is still logged (never silent), retries back off 1, 3, 7… passes (capped near 10 min at
33
+ * the 5 s default), and a changed activation row version retries at once. */
34
+ export interface PluginAttachFailure {
35
+ message: string;
36
+ version: string;
37
+ failures: number;
38
+ skipPasses: number;
39
+ }
40
+ /**
41
+ * One reconciliation pass: attaches any plugin durably `enabled` for `workspaceId` that isn't
42
+ * already in `attachedIds` (mutated in place — the caller keeps this Set across ticks so an
43
+ * already-attached plugin is never redundantly reloaded, which would needlessly re-run its
44
+ * `setup()` and reset its quarantine failure count), and detaches any plugin `attachedIds` still
45
+ * has that is no longer durably enabled. A single plugin's `onPluginEnabled` failure (its package
46
+ * removed from disk, a tamper, …) is logged and skipped — it can never block reconciling the rest.
47
+ */
48
+ export declare function reconcilePluginActivationsOnce({ deps, attachedIds, failures }: {
49
+ deps: PluginActivationPollDeps;
50
+ attachedIds: Set<string>;
51
+ failures?: Map<string, PluginAttachFailure>;
52
+ }, _optional?: {}): Promise<void>;
53
+ /**
54
+ * Starts this process's periodic reconciliation against the durable activation table (P0b).
55
+ * Seeds `attachedIds` from the SAME rows `pluginRuntimeReady`'s boot attach already used, so the
56
+ * first tick reconciles only what changed since boot rather than redundantly re-attaching
57
+ * everything. Returns a `stop()` the caller invokes on shutdown; the timer is `unref()`'d so it
58
+ * never holds the process open on its own.
59
+ */
60
+ export declare function startPluginActivationPolling(deps: PluginActivationPollDeps & {
61
+ readonly pluginRuntimeReady: Promise<void>;
62
+ }, options?: {
63
+ intervalMs?: number;
64
+ }): {
65
+ stop: () => void;
66
+ };
67
+ //# sourceMappingURL=activation-polling.d.ts.map
@@ -0,0 +1,113 @@
1
+ const MAX_SKIP_PASSES = 120;
2
+ /**
3
+ * One reconciliation pass: attaches any plugin durably `enabled` for `workspaceId` that isn't
4
+ * already in `attachedIds` (mutated in place — the caller keeps this Set across ticks so an
5
+ * already-attached plugin is never redundantly reloaded, which would needlessly re-run its
6
+ * `setup()` and reset its quarantine failure count), and detaches any plugin `attachedIds` still
7
+ * has that is no longer durably enabled. A single plugin's `onPluginEnabled` failure (its package
8
+ * removed from disk, a tamper, …) is logged and skipped — it can never block reconciling the rest.
9
+ */
10
+ export async function reconcilePluginActivationsOnce({ deps, attachedIds, failures = new Map() }, _optional = {}) {
11
+ const records = await deps.pluginActivationRepo.listAll();
12
+ const enabledVersions = new Map(records.filter(record => record.workspaceId === deps.workspaceId && record.enabled).map(record => [record.pluginId, record.version]));
13
+ for (const [pluginId, activeVersion] of enabledVersions) {
14
+ const loadedVersion = deps.pluginLoadedVersion?.({ id: pluginId }, {});
15
+ const current = attachedIds.has(pluginId) && (!deps.pluginLoadedVersion || loadedVersion === activeVersion);
16
+ if (current || shouldWaitBeforeRetry(failures.get(pluginId), activeVersion))
17
+ continue;
18
+ await attachActivatedPlugin({ deps, attachedIds, failures, pluginId, version: activeVersion });
19
+ }
20
+ removeDisabledActivations({ deps, enabledVersions, attachedIds, failures });
21
+ }
22
+ function removeDisabledActivations({ deps, enabledVersions, attachedIds, failures }, _optional = {}) {
23
+ for (const pluginId of failures.keys())
24
+ if (!enabledVersions.has(pluginId))
25
+ failures.delete(pluginId);
26
+ for (const pluginId of attachedIds) {
27
+ if (enabledVersions.has(pluginId))
28
+ continue;
29
+ deps.onPluginDisabled(pluginId);
30
+ attachedIds.delete(pluginId);
31
+ }
32
+ }
33
+ /** Counts down a failed plugin's backoff; a new activation version (re-enable, reinstall) retries now. */
34
+ function shouldWaitBeforeRetry(failure, activeVersion) {
35
+ if (!failure || failure.version !== activeVersion || failure.skipPasses === 0)
36
+ return false;
37
+ failure.skipPasses -= 1;
38
+ return true;
39
+ }
40
+ /** An attach failure is local to this plugin; later attachments and detachments still run. */
41
+ async function attachActivatedPlugin(required, _optional = {}) {
42
+ const { deps, attachedIds, failures, pluginId, version } = required;
43
+ try {
44
+ await deps.onPluginEnabled(pluginId);
45
+ attachedIds.add(pluginId);
46
+ if (failures.delete(pluginId))
47
+ deps.logger.info({ message: `[plugin-runtime] plugin '${pluginId}' is attached again after earlier failures` });
48
+ }
49
+ catch (error) {
50
+ recordAttachFailure({ failures, pluginId, version, logger: deps.logger, error });
51
+ }
52
+ }
53
+ /** Logs a failure only when it differs from the last one logged for this plugin, then backs off. */
54
+ function recordAttachFailure(required) {
55
+ const { failures, pluginId, version, logger, error } = required;
56
+ // The text only identifies a repeat of the same failure; it is compared, never logged.
57
+ const message = error instanceof Error ? error.message : String(error);
58
+ const previous = failures.get(pluginId);
59
+ if (previous?.message !== message) {
60
+ logger.warn({ message: `[plugin-runtime] plugin activation poll failed to attach '${pluginId}'` }, { error });
61
+ }
62
+ const count = previous?.message === message && previous.version === version ? previous.failures + 1 : 1;
63
+ failures.set(pluginId, { message, version, failures: count, skipPasses: Math.min(2 ** count - 1, MAX_SKIP_PASSES) });
64
+ }
65
+ /**
66
+ * Starts this process's periodic reconciliation against the durable activation table (P0b).
67
+ * Seeds `attachedIds` from the SAME rows `pluginRuntimeReady`'s boot attach already used, so the
68
+ * first tick reconciles only what changed since boot rather than redundantly re-attaching
69
+ * everything. Returns a `stop()` the caller invokes on shutdown; the timer is `unref()`'d so it
70
+ * never holds the process open on its own.
71
+ */
72
+ export function startPluginActivationPolling(deps, options = {}) {
73
+ const intervalMs = options.intervalMs ?? 5000;
74
+ const attachedIds = new Set();
75
+ const failures = new Map();
76
+ let stopped = false;
77
+ // A pass can already be awaiting readiness or a durable read when stop() clears the timer.
78
+ // Check again at each registry boundary so that settling that pass cannot change hooks.
79
+ const pollingDeps = {
80
+ ...deps,
81
+ onPluginEnabled: async (pluginId) => { if (!stopped)
82
+ await deps.onPluginEnabled(pluginId); },
83
+ onPluginDisabled: (pluginId) => { if (!stopped)
84
+ deps.onPluginDisabled(pluginId); },
85
+ };
86
+ const seeded = deps.pluginRuntimeReady.then(async () => {
87
+ const records = await deps.pluginActivationRepo.listAll();
88
+ for (const record of records) {
89
+ if (record.workspaceId === deps.workspaceId && record.enabled)
90
+ attachedIds.add(record.pluginId);
91
+ }
92
+ });
93
+ // Mark the rejection handled now: the first tick attaches its `.catch` only after `intervalMs`,
94
+ // and every tick still logs the failure through its own chain below.
95
+ seeded.catch(() => undefined);
96
+ const timer = setInterval(() => {
97
+ if (stopped)
98
+ return;
99
+ void seeded
100
+ .then(() => stopped ? undefined : reconcilePluginActivationsOnce({ deps: pollingDeps, attachedIds, failures }))
101
+ .catch((error) => {
102
+ deps.logger.warn({ message: "[plugin-runtime] plugin activation poll failed" }, { error });
103
+ });
104
+ }, intervalMs);
105
+ timer.unref?.();
106
+ return {
107
+ stop: () => {
108
+ stopped = true;
109
+ clearInterval(timer);
110
+ },
111
+ };
112
+ }
113
+ //# sourceMappingURL=activation-polling.js.map
@@ -25,36 +25,8 @@
25
25
  */
26
26
  import type { Clock as ClockPort, UUID } from "@jini-ai/core/primitives";
27
27
  import type { PluginDiscoveryRecord } from "./discovery-types.js";
28
- /** `plugin_activations` row (durable, behind the gateway) — state.spec.md §2. */
29
- export interface PluginActivationRecord {
30
- readonly pluginId: string;
31
- readonly workspaceId: UUID;
32
- /** The active (enabled) installed version — the "active pointer". */
33
- readonly version: string;
34
- readonly enabled: boolean;
35
- readonly updatedAt: string;
36
- /** Present only while automatic quarantine is active. A normal enable/disable save omits these
37
- * fields, which clears the durable marker and makes re-enable the operator recovery action. */
38
- readonly quarantinedAt?: string;
39
- readonly quarantineReason?: string;
40
- readonly quarantineFailureCount?: number;
41
- }
42
- /** Persistence contract — shaped identically to `PresentationSettingsRepoPort` (rule-of-two, two
43
- * adapters from day one: `repo.memory.ts` / `repo.sqlite.ts`). */
44
- export interface PluginActivationRepoPort {
45
- getActivation(required: {
46
- workspaceId: UUID;
47
- pluginId: string;
48
- }, optional?: Record<string, never>): Promise<PluginActivationRecord | null>;
49
- save(record: PluginActivationRecord, optional?: Record<string, never>): Promise<void>;
50
- deleteActivation(required: {
51
- workspaceId: UUID;
52
- pluginId: string;
53
- }, optional?: Record<string, never>): Promise<void>;
54
- /** Every row across every workspace — used by discovery's `enabled` projection and by any
55
- * future migration, mirrors `PresentationSettingsRepoPort.listAll`. */
56
- listAll(required?: Record<string, never>, optional?: Record<string, never>): Promise<PluginActivationRecord[]>;
57
- }
28
+ import type { PluginActivationRecord, PluginActivationRepoPort } from "@jini-ai/core/contracts/site/plugins-host";
29
+ export type { PluginActivationRecord, PluginActivationRepoPort } from "@jini-ai/core/contracts/site/plugins-host";
58
30
  export declare class PluginNotFoundError extends Error {
59
31
  }
60
32
  export declare class PluginInvalidError extends Error {
@@ -289,6 +289,7 @@ export interface PluginCapabilitySourceDeps {
289
289
  export interface PluginCapabilityToolsRequired<TPost extends PluginCapabilityPost, TDraft, TFamily extends string> {
290
290
  /** @agent-note Namespace passed to `readPluginIdentity` for the discovery terms. */
291
291
  readonly identityNamespace: string;
292
+ readonly legacyIdentityNamespace?: string | undefined;
292
293
  /** The host SDK's before-save hook id (the same id its `PluginSdkBinding.hookIds` admits and its
293
294
  * invocation binding receives as `beforeSaveHook`).
294
295
  * @agent-note Second-host rule: required, no default. A tier-2 plugin whose manifest `hooks`
@@ -56,8 +56,8 @@ 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
- const host = { identityNamespace, beforeSaveHook, text, catalog, access, executableAccess, approvalFamily, toPreviewDraft };
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
61
  return {
62
62
  loadSources: (deps) => loadEnabledPluginCapabilityToolSources(host, deps),
63
63
  buildRegistrations: (args) => buildPluginCapabilityToolRegistrations(host, args),
@@ -98,8 +98,8 @@ function buildFieldSources(host, manifest) {
98
98
  * call it and what an empty result means.
99
99
  */
100
100
  function buildCapabilityToolDescription(host, manifest, fields) {
101
- const { identityNamespace, beforeSaveHook, text } = host;
102
- const identity = readPluginIdentity({ manifest: manifest, name: manifest.id, namespace: identityNamespace });
101
+ const { identityNamespace, legacyIdentityNamespace, beforeSaveHook, text } = host;
102
+ const identity = readPluginIdentity({ manifest: manifest, name: manifest.id, namespace: identityNamespace, legacyNamespace: legacyIdentityNamespace });
103
103
  const fieldText = fields.map((field) => field.description).join(" ") + text.discovery({ terms: [identity.id, ...identity.keywords, ...identity.provides].join(" ") });
104
104
  if (runsFreshFor(manifest, beforeSaveHook)) {
105
105
  return text.freshDescription({ pluginName: manifest.name, fieldText });
@@ -1,15 +1,8 @@
1
- import { type PluginProviderContribution } from '@jini-ai/core/contracts/plugin-sdk';
2
1
  import type { PluginManifest } from './manifest-types.js';
2
+ import type { PluginContributionsSnapshot } from "@jini-ai/core/contracts/site/plugins-host";
3
3
  import type { PluginRouteContribution, PluginSdk, PluginToolContribution, PluginWidgetContribution } from '@jini-ai/core/contracts/plugin-sdk';
4
4
  export declare const PLUGIN_CONTRIBUTION_CAPABILITIES: readonly ["http.route.register", "tools.register", "render.contribute", "providers.register"];
5
- export interface PluginContributionsSnapshot {
6
- readonly pluginId: string;
7
- readonly sdk: PluginSdk;
8
- readonly providers?: readonly PluginProviderContribution[];
9
- readonly routes: readonly PluginRouteContribution[];
10
- readonly tools: readonly PluginToolContribution[];
11
- readonly widgets: readonly PluginWidgetContribution[];
12
- }
5
+ export type { PluginContributionsSnapshot } from "@jini-ai/core/contracts/site/plugins-host";
13
6
  /** The name used by both the claims gate and the assistant's real registry. */
14
7
  export declare function pluginToolIdFor(required: {
15
8
  pluginId: string;
@@ -0,0 +1,49 @@
1
+ /**
2
+ * @file Model-facing refusal for a plugin save-hook failure.
3
+ *
4
+ * Why it is shared: a content feature must recognize a plugin save-hook refusal to tell the model
5
+ * about it, but it cannot import the plugin runtime that already imports it. Both sides depend on
6
+ * this module instead, and it uses the host's one `PluginHookFailedError` class identity.
7
+ */
8
+ import { type ToolHandler } from "@jini-ai/core";
9
+ import { PluginHookFailedError } from "./errors.js";
10
+ /**
11
+ * The public text for a save-hook refusal — what an agent tool and every HTTP route return instead
12
+ * of the error's own message.
13
+ *
14
+ * The text is FIXED apart from the plugin id (and, for a partly applied run, the refused item's
15
+ * ref): a `PluginHookFailedError`'s own text quotes the plugin's thrown error (or a
16
+ * quarantine-persistence error), which can carry a path, a SQL error or a secret — the same reason `ModelFacingErrorRule.message` exists.
17
+ *
18
+ * @complexity O(1).
19
+ */
20
+ export declare function pluginHookRefusalText({ err }: {
21
+ err: PluginHookFailedError;
22
+ }, _optional?: {}): string;
23
+ /**
24
+ * Re-classifies a plugin save-hook refusal into a `ToolInputError` the model can act on; anything
25
+ * else is returned unchanged (and stays redacted by the transport). The message is
26
+ * {@link pluginHookRefusalText}; a `ModelFacingErrorRule` cannot interpolate the plugin id, which is
27
+ * why this is a function rather than a rule.
28
+ *
29
+ * @param required.err - Any rejection a tool handler threw.
30
+ * @returns The value to re-throw.
31
+ * @complexity O(1).
32
+ */
33
+ export declare function toModelFacingPluginHookError({ err }: {
34
+ err: unknown;
35
+ }, _optional?: {}): unknown;
36
+ /**
37
+ * Wraps every handler in a map with {@link toModelFacingPluginHookError} — the whole map at once,
38
+ * so no save handler can be the one that forgot (see `withModelFacingErrors`). Transparent on the
39
+ * success path. A host whose wrap port is `(handlers) => handlers` binds it as
40
+ * `(handlers) => withPluginHookRefusals({ handlers })`.
41
+ *
42
+ * @param required.handlers - A domain's handler map, keyed by tool id.
43
+ * @returns A new map with the same keys; the input is not mutated.
44
+ * @complexity O(h) at build time; O(1) per failed call.
45
+ */
46
+ export declare function withPluginHookRefusals({ handlers }: {
47
+ handlers: Record<string, ToolHandler>;
48
+ }, _optional?: {}): Record<string, ToolHandler>;
49
+ //# sourceMappingURL=hook-refusals.d.ts.map
@@ -0,0 +1,65 @@
1
+ /**
2
+ * @file Model-facing refusal for a plugin save-hook failure.
3
+ *
4
+ * Why it is shared: a content feature must recognize a plugin save-hook refusal to tell the model
5
+ * about it, but it cannot import the plugin runtime that already imports it. Both sides depend on
6
+ * this module instead, and it uses the host's one `PluginHookFailedError` class identity.
7
+ */
8
+ import { ToolInputError } from "@jini-ai/core";
9
+ import { PluginHookFailedError } from "./errors.js";
10
+ /**
11
+ * The public text for a save-hook refusal — what an agent tool and every HTTP route return instead
12
+ * of the error's own message.
13
+ *
14
+ * The text is FIXED apart from the plugin id (and, for a partly applied run, the refused item's
15
+ * ref): a `PluginHookFailedError`'s own text quotes the plugin's thrown error (or a
16
+ * quarantine-persistence error), which can carry a path, a SQL error or a secret — the same reason `ModelFacingErrorRule.message` exists.
17
+ *
18
+ * @complexity O(1).
19
+ */
20
+ export function pluginHookRefusalText({ err }, _optional = {}) {
21
+ // A refused item of a partly applied run must not claim "nothing was saved": the items before it
22
+ // landed. The item ref is a stable id, never body content.
23
+ return err.refusedItemRef === null
24
+ ? `a site plugin (${err.pluginId}) refused this save; the content was not saved`
25
+ : `a site plugin (${err.pluginId}) refused item ${err.refusedItemRef}; items applied before it stay saved, so check the import history before retrying`;
26
+ }
27
+ /**
28
+ * Re-classifies a plugin save-hook refusal into a `ToolInputError` the model can act on; anything
29
+ * else is returned unchanged (and stays redacted by the transport). The message is
30
+ * {@link pluginHookRefusalText}; a `ModelFacingErrorRule` cannot interpolate the plugin id, which is
31
+ * why this is a function rather than a rule.
32
+ *
33
+ * @param required.err - Any rejection a tool handler threw.
34
+ * @returns The value to re-throw.
35
+ * @complexity O(1).
36
+ */
37
+ export function toModelFacingPluginHookError({ err }, _optional = {}) {
38
+ if (!(err instanceof PluginHookFailedError))
39
+ return err;
40
+ return new ToolInputError({ message: `PLUGIN_HOOK_FAILED: ${pluginHookRefusalText({ err })}` });
41
+ }
42
+ /**
43
+ * Wraps every handler in a map with {@link toModelFacingPluginHookError} — the whole map at once,
44
+ * so no save handler can be the one that forgot (see `withModelFacingErrors`). Transparent on the
45
+ * success path. A host whose wrap port is `(handlers) => handlers` binds it as
46
+ * `(handlers) => withPluginHookRefusals({ handlers })`.
47
+ *
48
+ * @param required.handlers - A domain's handler map, keyed by tool id.
49
+ * @returns A new map with the same keys; the input is not mutated.
50
+ * @complexity O(h) at build time; O(1) per failed call.
51
+ */
52
+ export function withPluginHookRefusals({ handlers }, _optional = {}) {
53
+ return Object.fromEntries(Object.entries(handlers).map(([toolId, handler]) => [
54
+ toolId,
55
+ async (...args) => {
56
+ try {
57
+ return await handler(...args);
58
+ }
59
+ catch (err) {
60
+ throw toModelFacingPluginHookError({ err });
61
+ }
62
+ },
63
+ ]));
64
+ }
65
+ //# sourceMappingURL=hook-refusals.js.map
@@ -9,6 +9,7 @@ export * from './attach-loaded-plugin.js';
9
9
  export * from './plugin-claims.js';
10
10
  export * from './claim-conflicts.js';
11
11
  export * from './activation.js';
12
+ export * from './activation-polling.js';
12
13
  export * from './declarative-enable.js';
13
14
  export * from './declarative-content-types.js';
14
15
  export * from './capability-sdk.js';
@@ -25,6 +26,7 @@ export * from './provider-host.js';
25
26
  export * from './provider-revision-watch.js';
26
27
  export * from './provider-setting-required.js';
27
28
  export * from './provider-settings-migrations.js';
28
- export type { ProviderConfigSource, ProviderKeyUsage, ProviderPluginConfig, ProviderSettingsView, ProviderWriteResult } from './provider-config-source.js';
29
+ export type { ProviderConfigSource, ProviderPluginConfig, ProviderSettingsView } from '@jini-ai/core/contracts/site/composition-provider-config-source';
30
+ export type { ProviderKeyUsage, ProviderWriteResult } from '@jini-ai/core/contracts/site/plugins-host';
29
31
  export * from './admin-response.js';
30
32
  //# sourceMappingURL=index.d.ts.map
@@ -9,6 +9,7 @@ export * from './attach-loaded-plugin.js';
9
9
  export * from './plugin-claims.js';
10
10
  export * from './claim-conflicts.js';
11
11
  export * from './activation.js';
12
+ export * from './activation-polling.js';
12
13
  export * from './declarative-enable.js';
13
14
  export * from './declarative-content-types.js';
14
15
  export * from './capability-sdk.js';
@@ -374,7 +374,7 @@ export function validateManifest(required, _optional = {}) {
374
374
  const { errors: idErrors, id } = validateId(raw, folderName, builtInIds, required.coreOwnerName);
375
375
  const errors = [
376
376
  ...validateKeys(raw),
377
- ...validatePluginIdentity({ manifest: raw, namespace: required.identityNamespace }).errors.map(message => ({ code: "PLUGIN_IDENTITY_INVALID", file: null, message })),
377
+ ...validatePluginIdentity({ manifest: raw, namespace: required.identityNamespace, legacyNamespace: required.legacyIdentityNamespace }).errors.map(message => ({ code: "PLUGIN_IDENTITY_INVALID", file: null, message })),
378
378
  ...idErrors,
379
379
  ...validateIdentityFields(raw),
380
380
  ...validateEngine(raw),
@@ -388,7 +388,7 @@ export function validateManifest(required, _optional = {}) {
388
388
  ...required.declarativeContentTypes.validateManifest({ manifest: raw }).errors,
389
389
  ];
390
390
  const warnings = errors.length === 0
391
- ? readPluginIdentity({ manifest: raw, name: id, namespace: required.identityNamespace }).warnings
391
+ ? readPluginIdentity({ manifest: raw, name: id, namespace: required.identityNamespace, legacyNamespace: required.legacyIdentityNamespace }).warnings
392
392
  : [];
393
393
  return { errors, warnings };
394
394
  }
@@ -1,3 +1,4 @@
1
+ import type { PluginManifestReadOptions } from "../plugin-format.js";
1
2
  import { type AdmittedBrowserProvider } from '../browser-providers.js';
2
3
  import type { PluginManifest } from '../manifest.js';
3
4
  import type { PluginDiscoveryRecord } from '../discovery-types.js';
@@ -18,5 +19,5 @@ export declare function admitBrowserProviderAssets({ record, manifest, pluginRoo
18
19
  manifest: PluginManifest;
19
20
  pluginRoot: string;
20
21
  approvals: readonly BundledBrowserProviderApproval[];
21
- }, _options?: Record<string, never>): Promise<BrowserProviderAdmissionResult>;
22
+ }, options?: PluginManifestReadOptions): Promise<BrowserProviderAdmissionResult>;
22
23
  //# sourceMappingURL=browser-provider-assets.d.ts.map
@@ -24,7 +24,7 @@ function retainedAsset(path, bytes, digest, contentType) {
24
24
  * bounded snapshot and integrity owner on retained bytes, then serve those bytes rather than paths.
25
25
  * @example admitBrowserProviderAssets({ record, manifest, pluginRoot, approvals: compiledInPins })
26
26
  */
27
- export async function admitBrowserProviderAssets({ record, manifest, pluginRoot, approvals }, _options = {}) {
27
+ export async function admitBrowserProviderAssets({ record, manifest, pluginRoot, approvals }, options = {}) {
28
28
  if (validateBrowserProviders({ browserProviders: manifest.browserProviders, integrity: manifest.integrity }).length)
29
29
  return { admitted: false, reason: 'BROWSER_PROVIDER_INVALID' };
30
30
  const approval = approvals.find((approval) => approval.pluginId === record.id && approval.version === manifest.version);
@@ -35,7 +35,7 @@ export async function admitBrowserProviderAssets({ record, manifest, pluginRoot,
35
35
  return { admitted: false, reason: 'INTEGRITY_FAILED' };
36
36
  try {
37
37
  const files = await snapshotSitePluginPackage({ sourceDir: pluginRoot });
38
- verifyPluginSnapshotIntegrity({ files, integrity: approval.integrity });
38
+ verifyPluginSnapshotIntegrity({ files, integrity: approval.integrity }, options);
39
39
  const providers = (manifest.browserProviders ?? []).map((declaration) => {
40
40
  const paths = [declaration.javascript, ...(declaration.stylesheet ? [declaration.stylesheet] : [])];
41
41
  const assets = paths.map((file) => retainedAsset(file, files.get(file), approval.integrity[file], file.endsWith('.css') ? 'text/css' : 'text/javascript'));
@@ -27,7 +27,7 @@ import { constants } from "node:fs";
27
27
  import { open, readdir } from "node:fs/promises";
28
28
  import path from "node:path";
29
29
  import { readAtMost, readNoFollowFlags } from "./open-flags.js";
30
- import { PLUGIN_MANIFEST_FILENAME, PLUGIN_MANIFEST_FILENAMES } from "../plugin-format.js";
30
+ import { PLUGIN_MANIFEST_FILENAME, pluginManifestFilenames } from "../plugin-format.js";
31
31
  import * as semver from "semver";
32
32
  import { validateManifest } from "../manifest.js";
33
33
  export class PluginDiscoveryVersionError extends Error {
@@ -181,8 +181,8 @@ async function readOpenManifest(handle) {
181
181
  /** The first manifest present (current name, then the legacy alias); `missing` when neither exists.
182
182
  * A present manifest that is not a small regular file is `unreadable`: that plugin is invalid, and
183
183
  * discovery (which boot runs) never hangs on a FIFO, follows a link or buffers a huge file. */
184
- async function readSiteManifest(versionDir) {
185
- for (const filename of PLUGIN_MANIFEST_FILENAMES) { // legacy alias
184
+ async function readSiteManifest(versionDir, optional = {}) {
185
+ for (const filename of pluginManifestFilenames({}, optional)) { // legacy alias
186
186
  const handle = await openManifest(path.join(versionDir, filename));
187
187
  if (handle === null)
188
188
  continue;
@@ -221,7 +221,7 @@ async function discoverOneSiteCandidate({ installDir, idFolderName, builtInIds,
221
221
  const versionFolderName = requestedVersion ?? await pickLatestVersionFolder(idFolderPath);
222
222
  if (versionFolderName === null)
223
223
  return null;
224
- const read = await readSiteManifest(path.join(idFolderPath, versionFolderName));
224
+ const read = await readSiteManifest(path.join(idFolderPath, versionFolderName), host);
225
225
  const { manifestValue } = read;
226
226
  const errors = manifestReadErrors({ read, idFolderName, builtInIds, host });
227
227
  const manifestVersion = readStringField(manifestValue, "version");
@@ -289,7 +289,7 @@ export async function discoverPlugins(required, optional = {}) {
289
289
  return records.map(record => {
290
290
  if (record.status !== "valid" || !record.manifest)
291
291
  return record;
292
- const identity = readPluginIdentity({ manifest: record.manifest, name: record.id, namespace: required.identityNamespace });
292
+ const identity = readPluginIdentity({ manifest: record.manifest, name: record.id, namespace: required.identityNamespace, legacyNamespace: required.legacyIdentityNamespace });
293
293
  if (!qualifiedIds.has(identity.id)) {
294
294
  qualifiedIds.add(identity.id);
295
295
  return { ...record, warnings: identity.warnings };
@@ -2,6 +2,7 @@ import { type PluginManifest, type PluginTier } from "../manifest.js";
2
2
  import type { ArchiveReaderPort, ManifestHostPorts, PluginTierPolicy } from "../ports.js";
3
3
  import type { PluginActivationRepoPort } from "../activation.js";
4
4
  import type { PluginConflict } from "../plugin-claims.js";
5
+ import { type PluginManifestReadOptions } from "../plugin-format.js";
5
6
  export { PluginInstallError } from '../plugin-tool-errors.js';
6
7
  export interface PluginInstallPreview {
7
8
  readonly warnings?: readonly string[];
@@ -37,6 +38,8 @@ export interface PluginInstallDeps extends ManifestHostPorts {
37
38
  /** Internal authoring path only: append immutable versions while retaining rollback bytes.
38
39
  * Same-version replacement still refuses enabled plugins. Ordinary installs keep their policy. */
39
40
  readonly versionAppend?: boolean;
41
+ /** See {@link PluginInstallOptions.signal}. */
42
+ readonly signal?: AbortSignal;
40
43
  readonly warn?: (message: string) => void;
41
44
  readonly archiveReader: ArchiveReaderPort;
42
45
  readonly tierPolicy: PluginTierPolicy;
@@ -65,6 +68,8 @@ export interface PluginInstallerPort {
65
68
  /** Not a model input: the source authoring service opts into immutable version publication. */
66
69
  export interface PluginInstallOptions {
67
70
  readonly versionAppend?: boolean;
71
+ /** The caller's cancellation, checked before anything is staged and again before publication. */
72
+ readonly signal?: AbortSignal;
68
73
  }
69
74
  export interface PluginSnapshotLimits {
70
75
  readonly maxEntries?: number;
@@ -103,7 +108,7 @@ export declare function digestSitePluginSnapshot(required: {
103
108
  }, _optional?: {}): string;
104
109
  export declare function computePluginIntegrity(required: {
105
110
  sourceDir: string;
106
- }, _optional?: Record<string, never>): Promise<Record<string, string>>;
111
+ }, optional?: PluginManifestReadOptions): Promise<Record<string, string>>;
107
112
  export declare function previewSitePluginInstall(required: PluginInstallInput & {
108
113
  deps: PluginInstallDeps;
109
114
  }, _optional?: Record<string, never>): Promise<PluginInstallPreview>;