@jini-ai/plugins 0.7.3-next.2 → 0.7.4

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 (102) hide show
  1. package/CHANGELOG.md +7 -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/contributions.d.ts +2 -9
  7. package/dist/host/contributions.js +1 -1
  8. package/dist/host/hook-refusals.d.ts +49 -0
  9. package/dist/host/hook-refusals.js +65 -0
  10. package/dist/host/index.d.ts +3 -1
  11. package/dist/host/index.js +1 -0
  12. package/dist/host/node/browser-provider-assets.d.ts +2 -1
  13. package/dist/host/node/browser-provider-assets.js +2 -2
  14. package/dist/host/node/discovery.js +4 -4
  15. package/dist/host/node/install.d.ts +6 -1
  16. package/dist/host/node/install.js +20 -18
  17. package/dist/host/node/integrity-command.d.ts +2 -1
  18. package/dist/host/node/integrity-command.js +3 -3
  19. package/dist/host/node/loader.d.ts +3 -2
  20. package/dist/host/node/loader.js +6 -6
  21. package/dist/host/node/module-snapshot.d.ts +4 -3
  22. package/dist/host/node/module-snapshot.js +5 -5
  23. package/dist/host/node/package-files.d.ts +2 -1
  24. package/dist/host/node/package-files.js +6 -6
  25. package/dist/host/node/runtime-activation.d.ts +35 -0
  26. package/dist/host/node/runtime-activation.js +188 -0
  27. package/dist/host/node/runtime-boot.d.ts +16 -0
  28. package/dist/host/node/runtime-boot.js +153 -0
  29. package/dist/host/node/runtime-conflicts.d.ts +38 -0
  30. package/dist/host/node/runtime-conflicts.js +42 -0
  31. package/dist/host/node/runtime-contracts.d.ts +4 -3
  32. package/dist/host/node/runtime-core.js +65 -465
  33. package/dist/host/node/runtime-load-target.d.ts +14 -0
  34. package/dist/host/node/runtime-load-target.js +15 -0
  35. package/dist/host/node/runtime-reload.d.ts +12 -0
  36. package/dist/host/node/runtime-reload.js +107 -0
  37. package/dist/host/node/runtime-state.d.ts +52 -0
  38. package/dist/host/node/runtime-state.js +50 -0
  39. package/dist/host/node/source-drafts.d.ts +1 -1
  40. package/dist/host/node/source-drafts.js +17 -15
  41. package/dist/host/plugin-claims.d.ts +2 -9
  42. package/dist/host/plugin-format.d.ts +5 -5
  43. package/dist/host/plugin-format.js +9 -10
  44. package/dist/host/ports.d.ts +3 -28
  45. package/dist/host/tools/install.js +1 -1
  46. package/dist/host/uninstall.d.ts +2 -2
  47. package/dist/host/worker/import-policy.d.ts +49 -0
  48. package/dist/host/worker/import-policy.js +86 -0
  49. package/dist/host/worker/import-seam.js +21 -2
  50. package/dist/host/worker/index.d.ts +1 -0
  51. package/dist/host/worker/index.js +1 -0
  52. package/dist/host/worker/protocol.d.ts +4 -0
  53. package/dist/host/worker/run-call.js +2 -1
  54. package/dist/host/worker/start.d.ts +18 -1
  55. package/dist/host/worker/start.js +27 -6
  56. package/dist/react/PluginProviderSettingsDialog.d.ts +144 -0
  57. package/dist/react/PluginProviderSettingsDialog.js +54 -0
  58. package/dist/react/plugin-install-port.d.ts +29 -0
  59. package/dist/react/plugin-install-port.js +15 -0
  60. package/dist/runtime/agent-tools.d.ts +174 -0
  61. package/dist/runtime/agent-tools.js +121 -0
  62. package/dist/runtime/built-ins/word-count/count-words.d.ts +21 -0
  63. package/dist/runtime/built-ins/word-count/count-words.js +48 -0
  64. package/dist/runtime/built-ins/word-count/plugin.d.ts +6 -0
  65. package/dist/runtime/built-ins/word-count/plugin.js +12 -0
  66. package/dist/runtime/capability-card.d.ts +22 -0
  67. package/dist/runtime/capability-card.js +30 -0
  68. package/dist/runtime/enable-confirmation-ui.d.ts +28 -0
  69. package/dist/runtime/enable-confirmation-ui.js +54 -0
  70. package/dist/runtime/install-consent.d.ts +12 -0
  71. package/dist/runtime/install-consent.js +27 -0
  72. package/dist/runtime/install-source.d.ts +26 -0
  73. package/dist/runtime/install-source.js +61 -0
  74. package/dist/runtime/install-tool-catalog.d.ts +9 -0
  75. package/dist/runtime/install-tool-catalog.js +25 -0
  76. package/dist/runtime/lower-tool-access.d.ts +17 -0
  77. package/dist/runtime/lower-tool-access.js +14 -0
  78. package/dist/runtime/plugin-export.d.ts +13 -0
  79. package/dist/runtime/plugin-export.js +14 -0
  80. package/dist/runtime/plugin-host-copy.d.ts +17 -0
  81. package/dist/runtime/plugin-host-copy.js +7 -0
  82. package/dist/runtime/plugin-tool-ids.d.ts +18 -0
  83. package/dist/runtime/plugin-tool-ids.js +4 -0
  84. package/dist/runtime/plugin-tool-messages.d.ts +97 -0
  85. package/dist/runtime/plugin-tool-messages.js +90 -0
  86. package/dist/runtime/sdk-resolver.d.ts +60 -0
  87. package/dist/runtime/sdk-resolver.js +97 -0
  88. package/dist/runtime/service-ports.d.ts +43 -0
  89. package/dist/runtime/service-ports.js +3 -0
  90. package/dist/runtime/source-tool-catalog.d.ts +7 -0
  91. package/dist/runtime/source-tool-catalog.js +33 -0
  92. package/dist/runtime/uninstall-confirmation-ui.d.ts +31 -0
  93. package/dist/runtime/uninstall-confirmation-ui.js +38 -0
  94. package/dist/runtime/widget-partials.d.ts +22 -0
  95. package/dist/runtime/widget-partials.js +13 -0
  96. package/dist/site/lipay/manifest.d.ts +10 -0
  97. package/dist/site/lipay/manifest.js +96 -0
  98. package/dist/site/store/manifest.d.ts +10 -0
  99. package/dist/site/store/manifest.js +37 -0
  100. package/package.json +158 -8
  101. package/dist/host/provider-config-source.d.ts +0 -47
  102. package/dist/host/provider-config-source.js +0 -2
@@ -1,3 +1,5 @@
1
+ import path from "node:path";
2
+ import { fileURLToPath } from "node:url";
1
3
  function invalidReply() {
2
4
  return new Error("invalid tier-2 worker reply");
3
5
  }
@@ -11,10 +13,13 @@ export function createTier2ImportSeam(required, optional = {}) {
11
13
  const { manifest, runCall, pluginSdkBinding } = required;
12
14
  const HOOK_CONTENT_ENTRY_BEFORE_SAVE = pluginSdkBinding.beforeSaveHook;
13
15
  const definePlugin = (definition) => pluginSdkBinding.definePlugin(definition);
14
- return async ({ modulePath: entryPath }) => {
16
+ return async ({ plugin: registered, modulePath: entryPath }) => {
17
+ const workerEntry = optional.resolveWorkerEntry ? await optional.resolveWorkerEntry({ entryPath }) : entryPath;
18
+ const packageRoot = workerPackageRoot({ registeredRoot: registered.packageRoot, entryPath, workerEntry });
15
19
  const plugin = {
16
20
  pluginId: manifest.id,
17
- entryPath: optional.resolveWorkerEntry ? await optional.resolveWorkerEntry({ entryPath }) : entryPath,
21
+ entryPath: workerEntry,
22
+ ...(packageRoot === undefined ? {} : { packageRoot }),
18
23
  // Same cast `loadPlugin()` makes: validateManifest() has already checked every token.
19
24
  capabilities: manifest.capabilities,
20
25
  hooks: manifest.hooks,
@@ -49,4 +54,18 @@ export function createTier2ImportSeam(required, optional = {}) {
49
54
  };
50
55
  };
51
56
  }
57
+ /** The registered package root, carried over to the file the worker imports: the same root when the
58
+ * worker imports the registered entry, else the snapshot root that holds the entry at the same relative
59
+ * path. `undefined` when the worker entry does not mirror that layout (the worker then fails closed).
60
+ * @complexity O(path length). */
61
+ function workerPackageRoot({ registeredRoot, entryPath, workerEntry }, _optional = {}) {
62
+ if (workerEntry === entryPath)
63
+ return registeredRoot;
64
+ const relative = path.relative(registeredRoot, entryPath);
65
+ if (relative === "" || relative.startsWith("..") || path.isAbsolute(relative))
66
+ return undefined;
67
+ const workerFile = workerEntry.startsWith("file:") ? fileURLToPath(workerEntry) : workerEntry;
68
+ const suffix = `${path.sep}${relative}`;
69
+ return workerFile.endsWith(suffix) ? workerFile.slice(0, -suffix.length) : undefined;
70
+ }
52
71
  //# sourceMappingURL=import-seam.js.map
@@ -1,4 +1,5 @@
1
1
  /** Worker ABI and injected executable materialization. */
2
+ export * from './import-policy.js';
2
3
  export * from './import-seam.js';
3
4
  export * from './protocol.js';
4
5
  export * from './run-call.js';
@@ -1,4 +1,5 @@
1
1
  /** Worker ABI and injected executable materialization. */
2
+ export * from './import-policy.js';
2
3
  export * from './import-seam.js';
3
4
  export * from './protocol.js';
4
5
  export * from './run-call.js';
@@ -17,6 +17,10 @@ export interface Tier2PluginRef {
17
17
  /** Absolute file path or `file:` URL of the code the worker imports (a site plugin's integrity-
18
18
  * checked module snapshot, a built-in's own file). */
19
19
  readonly entryPath: string;
20
+ /** Canonical package root from the host's registration, mapped onto the worker entry (a site
21
+ * snapshot's root, or a built-in's declared sourceDir). Required for the worker to apply an import
22
+ * policy; without it a policy-carrying worker refuses the import. Absent from older hosts. */
23
+ readonly packageRoot?: string;
20
24
  readonly capabilities: readonly PluginCapability[];
21
25
  readonly hooks: readonly string[];
22
26
  }
@@ -50,7 +50,8 @@ export async function runTier2Call(required, _optional = {}) {
50
50
  const { pluginId, entryPath, capabilities, hooks } = request.plugin;
51
51
  let moduleValue;
52
52
  try {
53
- const packageRoot = path.dirname(path.dirname(entryPath.startsWith("file:") ? fileURLToPath(entryPath) : entryPath));
53
+ // The registered root when the host sent one; older hosts get the historical `<package>/server/<entry>` guess.
54
+ const packageRoot = request.plugin.packageRoot ?? path.dirname(path.dirname(entryPath.startsWith("file:") ? fileURLToPath(entryPath) : entryPath));
54
55
  const imported = await importModule({ plugin: { pluginId, packageRoot }, modulePath: entryPath });
55
56
  if (typeof imported === "string")
56
57
  return failed("import", imported);
@@ -1,3 +1,13 @@
1
+ /**
2
+ * @file `startTier2Worker()` — the per-call wiring of ONE Tier-2 plugin call inside a
3
+ * `worker_threads` worker. The host spawns its own worker entry file by path in a
4
+ * fresh, heap-limited worker per call, and terminates it after the first reply or the timeout; that
5
+ * entry calls this function with its own message port, request and product binding.
6
+ *
7
+ * The call logic is `run-call.ts`'s pure `runTier2Call()`; this file only wires the worker's own
8
+ * message port and import mechanism to it. Importing this module starts nothing.
9
+ */
10
+ import { registerTier2ImportPolicy, type Tier2ImportPolicy } from "./import-policy.js";
1
11
  import { type RunTier2CallRequired } from "./run-call.js";
2
12
  /**
3
13
  * Required inputs of {@link startTier2Worker}.
@@ -27,8 +37,15 @@ export interface StartTier2WorkerRequired {
27
37
  /** Optional inputs of {@link startTier2Worker}. */
28
38
  export interface StartTier2WorkerOptional {
29
39
  /** Test seam. Omitted ⇒ register the SDK resolver in this worker, then `realImport`.
30
- * @agent-note When supplied, `registerSdkResolver` and `realImport` are never called. */
40
+ * @agent-note When supplied, `registerSdkResolver`, the import policy and `realImport` are never called. */
31
41
  readonly importModule?: (entryPath: string) => Promise<unknown>;
42
+ /** @agent-note The host's SDK specifiers and trust decisions. When supplied, registered for THIS
43
+ * worker's entry and the request's `plugin.packageRoot` on the real-import path, before the SDK
44
+ * resolver; SDK-only unless the host trusts the entry. A request without `packageRoot` then fails
45
+ * at the import stage. Omitted ⇒ no policy (the pre-policy behaviour existing hosts rely on). */
46
+ readonly importPolicy?: Tier2ImportPolicy;
47
+ /** Test seam over {@link registerTier2ImportPolicy}. */
48
+ readonly registerImportPolicy?: typeof registerTier2ImportPolicy;
32
49
  }
33
50
  /**
34
51
  * Runs the posted request and posts its reply.
@@ -1,3 +1,13 @@
1
+ /**
2
+ * @file `startTier2Worker()` — the per-call wiring of ONE Tier-2 plugin call inside a
3
+ * `worker_threads` worker. The host spawns its own worker entry file by path in a
4
+ * fresh, heap-limited worker per call, and terminates it after the first reply or the timeout; that
5
+ * entry calls this function with its own message port, request and product binding.
6
+ *
7
+ * The call logic is `run-call.ts`'s pure `runTier2Call()`; this file only wires the worker's own
8
+ * message port and import mechanism to it. Importing this module starts nothing.
9
+ */
10
+ import { registerTier2ImportPolicy } from "./import-policy.js";
1
11
  import { runTier2Call } from "./run-call.js";
2
12
  /**
3
13
  * Runs the posted request and posts its reply.
@@ -13,19 +23,30 @@ export async function startTier2Worker(required, optional = {}) {
13
23
  const port = required.parentPort;
14
24
  if (!port)
15
25
  throw new Error("the tier-2 plugin worker must run inside a worker_threads Worker");
16
- let importModule = optional.importModule;
17
- if (!importModule) {
26
+ const request = required.workerData;
27
+ const registerImportPolicy = optional.registerImportPolicy ?? registerTier2ImportPolicy;
28
+ const importEntry = optional.importModule ?? (async (entryPath) => {
29
+ // On the import path, so `runTier2Call`'s import-stage handling turns a malformed or unreadable
30
+ // entry into a structured reply. The policy is computed before anything is registered.
31
+ if (optional.importPolicy)
32
+ registerImportPolicy({ entryPath, packageRoot: registeredPackageRoot(request), policy: optional.importPolicy });
18
33
  // Per worker: main-thread `module.register()` hooks do not reach a worker spawned
19
34
  // with `execArgv: []` (measured, Node v24.2.0), so without this a site plugin's
20
35
  // SDK imports (including the legacy alias) fail, or resolve to a copy planted next to the plugin. Registered
21
36
  // before the plugin's first import.
22
37
  required.registerSdkResolver();
23
- importModule = required.realImport;
24
- }
25
- const importEntry = importModule;
26
- port.postMessage(await runTier2Call({ ...required.binding, request: required.workerData, importModule: async ({ modulePath }) => {
38
+ return required.realImport(entryPath);
39
+ });
40
+ port.postMessage(await runTier2Call({ ...required.binding, request, importModule: async ({ modulePath }) => {
27
41
  const imported = await importEntry(modulePath);
28
42
  return { exported: typeof imported === "object" && imported !== null ? imported.default : undefined };
29
43
  } }));
30
44
  }
45
+ function registeredPackageRoot(request, _optional = {}) {
46
+ const packageRoot = request.plugin.packageRoot;
47
+ // Fail closed: guessing the package from the entry's location is what let a built-in's whole folder count as one package.
48
+ if (!packageRoot)
49
+ throw new Error(`plugin '${request.plugin.pluginId}' has no registered package root, so its import policy cannot be applied`);
50
+ return packageRoot;
51
+ }
31
52
  //# sourceMappingURL=start.js.map
@@ -0,0 +1,144 @@
1
+ import { type AgentHandleProps } from "@jini-ai/core/agent-handles";
2
+ import type { AdminPluginDto } from "@jini-ai/core/contracts/site/cms-plugins";
3
+ import { type Translate } from '@jini-ai/core/text';
4
+ import { type ComponentType, type ReactNode } from "react";
5
+ /**
6
+ * @file A provider plugin's secure settings card (2026-10-26): Plugins → Installed (or Downloaded) →
7
+ * the plugin's Settings button. Every field comes from the plugin's manifest; secret fields are
8
+ * password inputs that never show a saved value ("Saved — leave blank to keep"). Saved values are
9
+ * sealed on the server (the project store visible to attached sites, or this site's vault) and
10
+ * apply now.
11
+ *
12
+ * 2026-10-25 redesign (owner: "looks awful"): the admin's native domain dialog (`PostUrlDialog`'s
13
+ * Jini `Dialog` + `.jini-dialog-body`/`.jini-dialog-footer`) with the `.field` primitives — label
14
+ * above a full-width control, hint below — instead of bare inline labels. Titled "<Name> settings";
15
+ * a successful Save hands off to `onSaved` (the screen closes the card and shows a toast), so the
16
+ * outcome is never a small line inside a card the owner is about to dismiss.
17
+ */
18
+ /** A kit action port (structural: the host injects its kit's Button/Dialog). */
19
+ type KitAction = (required: Record<string, never>, optional?: Record<string, never>) => void;
20
+ /** The Button props this dialog uses; the host's kit Button must accept at least these. */
21
+ export interface ProviderSettingsButtonProps {
22
+ readonly children?: ReactNode;
23
+ readonly onPress?: KitAction;
24
+ readonly disabled?: boolean;
25
+ readonly pending?: boolean;
26
+ readonly variant?: "primary" | "secondary";
27
+ readonly type?: "submit";
28
+ readonly className?: string;
29
+ readonly attrs?: AgentHandleProps;
30
+ }
31
+ /** The Dialog props this dialog uses. */
32
+ export interface ProviderSettingsDialogFrameProps {
33
+ readonly open: boolean;
34
+ readonly title: string;
35
+ readonly children?: ReactNode;
36
+ readonly onClose: KitAction;
37
+ readonly pending?: boolean;
38
+ readonly className?: string;
39
+ }
40
+ /** One manifest-declared provider setting, as the settings endpoint describes it. */
41
+ export interface ProviderSettingFieldShape {
42
+ name: string;
43
+ label: string;
44
+ hint?: string;
45
+ default?: string;
46
+ options?: {
47
+ value: string;
48
+ label: string;
49
+ }[];
50
+ allowCustom?: true;
51
+ secret: boolean;
52
+ required: boolean;
53
+ requiredUnless?: {
54
+ readonly field: string;
55
+ readonly equals: string;
56
+ readonly orPresent?: string;
57
+ readonly headerNames?: readonly string[];
58
+ };
59
+ requiredWhen?: {
60
+ readonly field: string;
61
+ readonly in: readonly string[];
62
+ };
63
+ saved: boolean;
64
+ value?: string;
65
+ }
66
+ /** The provider-settings card (`GET|PUT .../plugins/:pluginId/provider-settings`). */
67
+ export interface ProviderSettingsCard {
68
+ pluginId: string;
69
+ store: "project" | "site";
70
+ appliesAt: "now" | "restart" | "failed";
71
+ message?: string;
72
+ keyId?: string;
73
+ usedByThisSite: boolean;
74
+ usedBy: string[];
75
+ projectAvailable?: boolean;
76
+ legacyCredential?: true;
77
+ unreadable?: true;
78
+ fields: ProviderSettingFieldShape[];
79
+ }
80
+ /** What the injected settings hook returns. */
81
+ export interface ProviderSettingsController {
82
+ card: ProviderSettingsCard | null;
83
+ values: Readonly<Record<string, string>>;
84
+ setValue: (required: {
85
+ name: string;
86
+ value: string;
87
+ }, optional?: Record<string, never>) => void;
88
+ save: () => Promise<boolean>;
89
+ useSavedKey: () => Promise<boolean>;
90
+ saving: boolean;
91
+ error: string | null;
92
+ t: Translate;
93
+ }
94
+ /** The injected field view's props. */
95
+ export interface ProviderSettingFieldViewProps {
96
+ readonly field: ProviderSettingFieldShape;
97
+ readonly id: string;
98
+ readonly value: string;
99
+ readonly onChange: (value: string) => void;
100
+ readonly handle: string;
101
+ readonly pluginName: string;
102
+ readonly t: (key: string) => string;
103
+ }
104
+ /** The injected rule deciding whether a field is required given what is entered and saved. */
105
+ export type ProviderSettingRequiredHere = (required: {
106
+ field: ProviderSettingFieldShape;
107
+ fields: readonly ProviderSettingFieldShape[];
108
+ entered: Readonly<Record<string, string | undefined>>;
109
+ values: Readonly<Record<string, string>>;
110
+ }, optional?: Record<string, never>) => boolean;
111
+ export interface PluginProviderSettingsDialogProps {
112
+ readonly kit: {
113
+ Button: ComponentType<ProviderSettingsButtonProps>;
114
+ Dialog: ComponentType<ProviderSettingsDialogFrameProps>;
115
+ ProviderSettingField: ComponentType<ProviderSettingFieldViewProps>;
116
+ };
117
+ readonly providerSettingRequiredHere: ProviderSettingRequiredHere;
118
+ readonly legacyCredentialKey: string;
119
+ readonly useProviderSettingsFocusHook: (required: {
120
+ card: ProviderSettingsCard | null;
121
+ fieldId: string;
122
+ }) => void;
123
+ readonly plugin: Pick<AdminPluginDto, "id" | "name">;
124
+ readonly agentHandleBase: string;
125
+ readonly onClose: () => void;
126
+ /** After the server accepted the values; the screen closes the card and confirms with a notice. */
127
+ readonly onSaved: () => void;
128
+ /** Injectable seam for tests. Defaults to the real {@link useWiredPluginProviderSettings}. */
129
+ readonly useSettings: (required: {
130
+ pluginId: string;
131
+ }) => ProviderSettingsController;
132
+ }
133
+ export declare function useProviderSettingsFocus({ card, fieldId, document }: {
134
+ card: ProviderSettingsCard | null;
135
+ fieldId: string;
136
+ document: {
137
+ getElementById(id: string): {
138
+ focus(): void;
139
+ } | null;
140
+ };
141
+ }, _options?: {}): void;
142
+ export declare function PluginProviderSettingsDialog({ plugin, agentHandleBase, onClose, onSaved, useSettings, useProviderSettingsFocusHook, kit, providerSettingRequiredHere, legacyCredentialKey }: PluginProviderSettingsDialogProps, _optional?: Record<string, never>): import("react").JSX.Element;
143
+ export {};
144
+ //# sourceMappingURL=PluginProviderSettingsDialog.d.ts.map
@@ -0,0 +1,54 @@
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { agentHandle } from "@jini-ai/core/agent-handles";
3
+ import { interpolate } from '@jini-ai/core/text';
4
+ import { useEffect, useId } from "react";
5
+ /** Field names are manifest keys (`apiKey`); agent handles allow only lowercase words joined by hyphens. */
6
+ function handleWords({ name }, _options = {}) {
7
+ return name.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "");
8
+ }
9
+ /** The card's re-entry notices (a key saved the retired way, or saved keys this machine can't open). */
10
+ function ReentryNotices({ card, t, legacyCredentialKey }) {
11
+ return (_jsxs(_Fragment, { children: [card?.unreadable ? _jsx("p", { className: "provider-settings-notice", role: "note", children: t("Saved keys for this plugin can't be read on this machine. Enter them again here and save.") }) : null, card?.legacyCredential ? _jsx("p", { className: "provider-settings-notice", role: "note", children: t(legacyCredentialKey) }) : null] }));
12
+ }
13
+ /** Cancel and Save; disabled with a spinner while saving. */
14
+ function SettingsFooter({ shown, saving, pluginName, agentHandleBase, onClose, t, Button }) {
15
+ return (_jsxs("div", { className: "jini-dialog-footer", children: [_jsx(Button, { variant: "secondary", className: "btn-secondary", disabled: saving, onPress: () => onClose(), attrs: agentHandle({ handle: `${agentHandleBase}-settings-close` }, { role: "button", label: `Close ${pluginName} settings` }), children: t("Cancel") }), _jsx(Button, { type: "submit", variant: "primary", className: "provider-settings-save", disabled: !shown, pending: saving, attrs: agentHandle({ handle: `${agentHandleBase}-settings-save` }, { role: "button", label: `Save ${pluginName} settings` }), children: saving ? _jsxs(_Fragment, { children: [_jsx("span", { className: "provider-settings-spinner", "aria-hidden": "true" }), t("Saving…")] }) : t("Save") })] }));
16
+ }
17
+ /** What an empty input stands for: a saved secret counts as present, else the declared default. */
18
+ function unenteredFieldValue(field) {
19
+ if (field.secret && field.saved)
20
+ return "saved";
21
+ return field.default ?? "";
22
+ }
23
+ function SettingsSubtitle({ card, t }) {
24
+ if (!card)
25
+ return null;
26
+ return _jsx("p", { className: "provider-settings-subtitle", children: settingsSubtitleText({ card, t }) });
27
+ }
28
+ function settingsSubtitleText({ card, t }, _options = {}) {
29
+ if (card.store !== "project")
30
+ return t(card.projectAvailable ? "Saved for this site only" : "Saved for this site");
31
+ if (card.usedBy.length)
32
+ return interpolate({ template: t("Used by {sites}"), vars: { sites: card.usedBy.join(", ") } });
33
+ return t("Saved to your project — not used by any site yet");
34
+ }
35
+ export function useProviderSettingsFocus({ card, fieldId, document }, _options = {}) {
36
+ // The native dialog focuses on open, before the card has loaded; once it has, start in its first field.
37
+ const firstField = card?.fields[0]?.name;
38
+ useEffect(() => { if (firstField)
39
+ document.getElementById(`${fieldId}-${firstField}`)?.focus(); }, [fieldId, firstField]);
40
+ }
41
+ export function PluginProviderSettingsDialog({ plugin, agentHandleBase, onClose, onSaved, useSettings, useProviderSettingsFocusHook, kit, providerSettingRequiredHere, legacyCredentialKey }, _optional = {}) {
42
+ const { Button, Dialog, ProviderSettingField } = kit;
43
+ const { card, values, setValue, save, useSavedKey: selectSavedKey, saving, error, t } = useSettings({ pluginId: plugin.id });
44
+ const fieldId = useId();
45
+ const fields = card?.fields ?? [];
46
+ // Presence only: a saved alternate secret satisfies the same manifest rule as an entered value.
47
+ const effectiveValues = Object.fromEntries(fields.map(field => [field.name,
48
+ values[field.name]?.trim() || unenteredFieldValue(field)]));
49
+ useProviderSettingsFocusHook({ card, fieldId });
50
+ return (_jsxs(Dialog, { open: true, title: interpolate({ template: t("{name} settings"), vars: { name: plugin.name } }), pending: saving, onClose: () => onClose(), className: "settings-dialog jini-domain-dialog provider-settings-dialog", children: [_jsx(SettingsSubtitle, { card: card, t: t }), _jsxs("form", { onSubmit: (event) => { event.preventDefault(); void save().then((accepted) => { if (accepted)
51
+ onSaved(); }); }, noValidate: true, children: [_jsxs("div", { className: "jini-dialog-body", children: [_jsx(ReentryNotices, { card: card, t: t, legacyCredentialKey: legacyCredentialKey }), card?.store === "project" && card.keyId && !card.usedByThisSite ? _jsx(Button, { variant: "secondary", disabled: saving, onPress: () => { void selectSavedKey().then(accepted => { if (accepted)
52
+ onSaved(); }); }, children: t("Use the saved key for this site") }) : null, fields.map((field) => (_jsx(ProviderSettingField, { field: { ...field, required: providerSettingRequiredHere({ field, fields, entered: values, values: effectiveValues }) }, id: `${fieldId}-${field.name}`, value: values[field.name] ?? "", onChange: (value) => setValue({ name: field.name, value }), handle: `${agentHandleBase}-setting-${handleWords({ name: field.name })}`, pluginName: plugin.name, t: t }, field.name)))] }), error ? _jsx("p", { className: "save-error", role: "alert", children: error }) : null, _jsx(SettingsFooter, { shown: card !== null, saving: saving, pluginName: plugin.name, agentHandleBase: agentHandleBase, onClose: onClose, t: t, Button: Button })] })] }));
53
+ }
54
+ //# sourceMappingURL=PluginProviderSettingsDialog.js.map
@@ -0,0 +1,29 @@
1
+ interface PluginInstallSource {
2
+ source: {
3
+ kind: "folder";
4
+ path: string;
5
+ } | {
6
+ kind: "zip";
7
+ file: File;
8
+ };
9
+ replace?: boolean;
10
+ }
11
+ export declare function createPluginInstallPort<Preview>({ request, workspaceId }: {
12
+ request: <T>(required: {
13
+ path: string;
14
+ method: string;
15
+ body: unknown;
16
+ }) => Promise<T>;
17
+ workspaceId: string;
18
+ }, _optional?: Record<string, never>): {
19
+ preview: (body: PluginInstallSource, _optional?: {}) => Promise<{
20
+ plugin: Preview;
21
+ }>;
22
+ install: (body: PluginInstallSource & {
23
+ expectedDigest: string;
24
+ }, _optional?: {}) => Promise<{
25
+ plugin: Preview;
26
+ }>;
27
+ };
28
+ export {};
29
+ //# sourceMappingURL=plugin-install-port.d.ts.map
@@ -0,0 +1,15 @@
1
+ export function createPluginInstallPort({ request, workspaceId }, _optional = {}) {
2
+ function installRequest({ input, preview }, _optional = {}) {
3
+ const endpoint = `/workspaces/${workspaceId}/plugins/install`;
4
+ if (input.source.kind === "folder")
5
+ return request({ path: endpoint + (preview ? "/preview" : ""), method: "POST", body: input });
6
+ const query = new URLSearchParams({ replace: String(input.replace === true), ...(input.expectedDigest ? { expectedDigest: input.expectedDigest } : {}) });
7
+ return request({ path: `${endpoint}/zip${preview ? "/preview" : ""}?${query}`, method: "POST", body: input.source.file.slice(0, input.source.file.size, "application/zip") });
8
+ }
9
+ /** Reuse the authenticated request seam, including session expiry and the normal API prefix. */
10
+ return {
11
+ preview: (body, _optional = {}) => installRequest({ input: body, preview: true }),
12
+ install: (body, _optional = {}) => installRequest({ input: body, preview: false }),
13
+ };
14
+ }
15
+ //# sourceMappingURL=plugin-install-port.js.map
@@ -0,0 +1,174 @@
1
+ import type { AgentToolDefinition as SharedAgentToolDefinition } from "@jini-ai/core";
2
+ import type { PluginHostCopy } from "./plugin-host-copy.js";
3
+ /**
4
+ * @file SPEC-005 (ADR-005-ARCH) — the Plugins domain's agent-tool catalog, instantiating SPEC-016
5
+ * REQ-22's naming/callability convention (the same shape `forms/agent-tools.ts`,
6
+ * `Jini packages/user-management/src/server/agent-tools.ts`, `Jini packages/cms/src/content-types/agent-tools.ts`, `features/database/
7
+ * agent-tools.ts`, and `features/recovery/agent-tools.ts` already use).
8
+ *
9
+ * Purpose:
10
+ * A static, in-process catalog describing every agent-callable tool this domain exposes and the
11
+ * permission each one carries. Every entry maps 1:1 onto a real, already-shipped admin surface:
12
+ * `content_read.plugin` mirrors the host's admin plugins list route (`PLUGINS_LIST`) and `plugins_set_enabled`
13
+ * mirrors the host's admin plugins set-enabled route (`PLUGIN_SET_ENABLED`) exactly — same permissions,
14
+ * same underlying `Jini/packages/plugins/src/host/activation.ts` functions.
15
+ *
16
+ * Deliberate absences (the point of a catalog, not an oversight):
17
+ * - There is no install/upload tool. `features/plugin-runtime` has no admin ROUTE for either
18
+ * operation at all — `discoverPlugins()` reads whatever is already present on disk (install dir +
19
+ * built-ins), and nothing in this codebase's admin HTTP surface adds a plugin's files. A tool
20
+ * cannot be written against an operation the domain has no route for.
21
+ * CORRECTED 2026-09-07 (`ADS-memory/reports/2026-09-07-assistant-tool-coverage-audit.md`): this
22
+ * bullet used to also claim "There is no ... uninstall tool. features/plugin-runtime has no admin
23
+ * ROUTE for [it] at all" — that was true when originally written, and became false on 2026-08-20
24
+ * (Milestone 2) when `DELETE /api/admin/v1/workspaces/:workspaceId/plugins/:pluginId`
25
+ * (`routes/admin/plugins/uninstall.ts`, calling `uninstallPlugin()`) shipped, without this comment
26
+ * being updated for it — a confidently wrong claim the audit confirmed is exactly what stopped
27
+ * `plugins_uninstall` from being built. `plugins_uninstall` (below) closes that gap; install/upload
28
+ * remain genuinely absent at every layer, unlike uninstall.
29
+ * CORRECTED 2026-10-05: install is no longer absent. The admin folder/ZIP install routes
30
+ * (`routes/plugins/install.ts`, plugin-install-plan M1a) shipped, and `plugins_install` wraps the
31
+ * same installer. It lives in its own module and domain (`install-tool.ts`), not this catalog —
32
+ * see the "install stays separate" reasoning below.
33
+ * - `plugins_uninstall` mirrors the route it wires (`Jini/packages/plugins/src/host/uninstall.ts`) exactly: same
34
+ * `admin.plugins.enable` permission (no new grant introduced), same two hard preconditions
35
+ * (`uninstallPlugin()`'s own — the plugin must be a site-installed, non-built-in record, and must
36
+ * be disabled in every workspace first), same files-first-then-activation-rows ordering. NOT
37
+ * wrapped in a confirmation dialog the way `content_post_delete`/`deployment_execute_static_publish`
38
+ * are: this route itself is deliberately NOT wrapped in the change-set/revert gateway either
39
+ * (`Jini/packages/plugins/src/host/uninstall.ts`'s own header — "there is no meaningful 'restore the prior state' for deleted
40
+ * bytes"). The description below states the irreversibility in plain language instead.
41
+ * CORRECTED 2026-09-09: this bullet used to justify that with "there is no existing
42
+ * human-confirmation transport this tool could reuse without inventing one" — already false when
43
+ * written (ADR-055 Decision 2's held-open exchange had been serving `content_post_delete` since
44
+ * 2026-08-04), and now visibly so: `plugins_set_enabled` below reuses exactly that transport for
45
+ * its own enable path (the host's enable-confirmation UI module). Whether `plugins_uninstall` should too is
46
+ * a live question this file no longer answers with a false premise; it was simply not part of the
47
+ * pass that gated enabling.
48
+ * RESOLVED 2026-09-16: `plugins_uninstall` now DOES raise a confirmation dialog and parks on the
49
+ * human's answer, reusing the exact SAME held-open exchange `plugins_set_enabled`'s enable path
50
+ * already reuses (`uninstall-confirmation-ui.ts`, ADR-055 Decision 2) — closing the "whether
51
+ * plugins_uninstall should too" question the paragraph above left open. Two sentences above are now
52
+ * stale as a result: "NOT wrapped in a confirmation dialog ... are" and "The description below
53
+ * states the irreversibility in plain language instead" — the description below states BOTH the
54
+ * irreversibility and the confirmation requirement now. Only the change-set/revert-gateway claim in
55
+ * that same passage is still accurate: deleting bytes still has no meaningful inverse to capture,
56
+ * so `executeCommand` is still not used here. Confirmation and revertability are orthogonal
57
+ * concerns; only the first one changed.
58
+ * RESOLVED 2026-09-24 (S4): `plugins_uninstall` is now ALSO one tool covering BOTH plugin
59
+ * families, the same merge `plugins_set_enabled` got below, selected by a REQUIRED `family`
60
+ * argument — the sentence above ("mirrors the route it wires exactly") described only the
61
+ * 'site-runtime' branch, which is unchanged; the 'agent-plugin' branch runs
62
+ * `features/agent-plugins/uninstall-tool.ts`'s `runAgentPluginUninstall`, the same logic the
63
+ * deleted standalone `agent_plugins_uninstall` tool used to run under its own id. Risk is now
64
+ * `deletes-durable-state` for the whole tool, not `mutates-durable-state` — the worse of the two
65
+ * families' blast radii (site plugins go to the Trash; Agent Plugins do not), because
66
+ * `pluginsDerivedRisk` is keyed per tool id, not per family.
67
+ * - `plugins_set_enabled` is ONE tool covering BOTH plugin families (2026-09-09) — the site-plugin package
68
+ * site/runtime family this module belongs to, AND `features/agent-plugins/`'s separate Agent Plugin
69
+ * family, selected by a REQUIRED `family` argument. Two tools would have been the smaller diff and
70
+ * the worse answer: the operator asking "turn on the Higgsfield plugin" does not know which of
71
+ * the host's two plugin systems that word means, and a model choosing between two near-identically
72
+ * named enable tools is the exact confusion this catalog exists to prevent. What is deliberately
73
+ * NOT folded in is install: `DERIVED_RISK_BY_TOOL_ID` is keyed per tool id, so merging a reversible
74
+ * flag flip with an operation that runs third-party code would force one risk band onto two very
75
+ * different blast radii. (Uninstall WAS folded in per-family, above — its two families share one
76
+ * blast radius class, "deletes bytes", even though only one of them has a Trash behind it.)
77
+ * - Enabling, in either family, raises a real human confirmation and PARKS on the answer
78
+ * (the host's enable-confirmation UI module, ADR-055 Decision 2's held-open exchange). Disabling does not.
79
+ * See that file's header for why the asymmetry is the point rather than an omission.
80
+ * - `plugins_set_enabled` is included, but is NOT the low-risk "flip a flag" operation its own name
81
+ * suggests: enabling a plugin whose manifest declares a `dataModule` invokes ADR-023's
82
+ * core-mediated DDL engine (`@jini-ai/db/data-modules`) against the LIVE database —
83
+ * snapshot-protected and single-transaction, but genuinely schema-affecting, not a pure metadata
84
+ * toggle. The tool's own description says so; see this file's header and
85
+ * `@jini-ai/db/data-modules`'s own header for the full "never-brick" doctrine this rides
86
+ * on. Still included per this dispatch's brief (comparatively low-risk and REVERSIBLE — disabling
87
+ * undoes the activation-state flip; a plugin's own DDL is additive/idempotent per ADR-023 §2,
88
+ * never a drop on disable) — unlike `database_execute_migrate_forward`/`backup_execute_restore`,
89
+ * which this dispatch's sibling catalogs exclude outright.
90
+ *
91
+ * How it relates to the project:
92
+ * `assistant/tool-registrations.ts` maps these entries into `@jini-ai/core` `ToolRegistration`s; the
93
+ * ADR-014 tool filter consumes the catalog to decide which names a session may see. Actual
94
+ * enforcement is the SAME gate the human admin routes use: `content_read.plugin`'s inline `authorize()`
95
+ * call and `plugins_set_enabled`'s `executeCommand`-wrapped permission check (ADR-021 §2) — this
96
+ * module declares shape only and performs no I/O.
97
+ *
98
+ * Architectural role:
99
+ * `features/plugin-runtime` domain declaration. Imports nothing from elsewhere in this package —
100
+ * every entry's input shape is primitive (a string id, a string family, a boolean flag), so there is
101
+ * no shared type to import without inventing a dependency this file does not otherwise need. In
102
+ * particular the `family` enum is restated here rather than imported from
103
+ * `set-enabled-confirmation-ui.ts`'s `PluginFamily`: this module is the CONTRACT the model reads, and
104
+ * a contract that could silently follow a UI module's rename is not a contract. The two are pinned
105
+ * together by test instead (`tool-registrations.plugins-set-enabled-families.test.ts`).
106
+ */
107
+ export type AgentToolSideEffect = "none" | "mutates-durable-state" | "deletes-durable-state" | "mints-token";
108
+ /**
109
+ * JSON Schema for this tool's `input`, published to the model via `ToolDescriptor.inputSchema`
110
+ * (`assistant/tool-registrations.ts`, which refuses to wire any tool lacking one). Required, not
111
+ * optional — both entries in this catalog are wired, so there is no unwired entry whose input
112
+ * shape is undesigned (mirrors `Jini packages/user-management/src/server/agent-tools.ts`'s reasoning for the same choice).
113
+ */
114
+ export type AgentToolDefinition = SharedAgentToolDefinition & {
115
+ sideEffects: AgentToolSideEffect;
116
+ inputSchema: Readonly<Record<string, unknown>>;
117
+ };
118
+ /**
119
+ * The Plugins domain's fixed agent-tool catalog — the three operations `routes/admin/plugins/`
120
+ * exposes (list, set-enabled, uninstall — see this file's header for install/upload's absence).
121
+ *
122
+ * Ordered read-tool-first, matching the house convention (`Jini packages/user-management/src/server/agent-tools.ts`'s own
123
+ * rationale): a model cannot enable/disable/uninstall a plugin it does not know the id of, and
124
+ * `content_read.plugin` is the only way to learn one.
125
+ */
126
+ export declare function createPluginAgentToolCatalog({ copy }: {
127
+ copy: PluginHostCopy;
128
+ }, _optional?: {}): AgentToolDefinition[];
129
+ /**
130
+ * @file The dialog `plugins_set_enabled` raises before it turns a plugin ON, for either plugin
131
+ * family.
132
+ *
133
+ * ---------------------------------------------------------------------------
134
+ * Why enabling is confirmed at all, when it is "just a flag"
135
+ * ---------------------------------------------------------------------------
136
+ * Enabling changes what the ASSISTANT can do next, which makes it a privilege escalation the model
137
+ * would otherwise be granting itself:
138
+ *
139
+ * - An Agent Plugin's `SKILL.md` is injected into a run's prompt (`resolve-agent-plugin-refs.ts`),
140
+ * and its `agent_plugin_<id>` tool is registered for the model to call
141
+ * (`agent-plugins/tool-registrations.ts`). A disabled plugin gets neither; enabling grants both.
142
+ * - A site-plugin package runtime plugin's enable hook can run ADR-023 schema DDL against the LIVE
143
+ * database (the host's plugin-runtime composition `onPluginEnabled`), and its
144
+ * capability tools become registrable (`capability-tool-registrations.ts`).
145
+ *
146
+ * `plugin-runtime/agent-tools.ts`'s own catalog header left this question open in so many words —
147
+ * "whether that is sufficient, or this needs the stronger actor-class/confirmation gating ... is
148
+ * flagged as open in the audit and not decided here". This answers it: enabling, in either family,
149
+ * asks a human first. DISABLING does not, and that asymmetry is deliberate rather than an
150
+ * oversight — disabling only ever REMOVES capability, so there is no escalation to consent to, and
151
+ * a confirmation dialog in front of the off switch is a dialog people learn to click through.
152
+ *
153
+ * ---------------------------------------------------------------------------
154
+ * The mechanism is the held-open exchange, not a token
155
+ * ---------------------------------------------------------------------------
156
+ * Same shape as the host's core human-confirm contract (ADR-055 Decision 2), for the same
157
+ * reasons — see that file's header for the full chain. The model's one call PARKS; the only way to
158
+ * resolve it is a browser POST to `mcp-ui-tool-calls-route.ts`, a channel the model cannot reach.
159
+ * The `exchangeId` interpolated below is a correlation handle, not a secret, and still belongs in
160
+ * this surface and nowhere else: a copy in the tool's `modelText` or an error message would
161
+ * misleadingly suggest a second, independent path back to the parked call, and there is none.
162
+ *
163
+ * `plugins_set_enabled` must therefore also be on `assistant/mcp-ui-tool-calls.ts`'s
164
+ * `MCP_UI_REDEEMABLE_TOOL_IDS` — without it the human's click is refused at the endpoint and the
165
+ * call parks until it expires. That is asserted, not assumed
166
+ * (`tool-registrations.plugins-set-enabled-families.test.ts`).
167
+ */
168
+ /** Which plugin system a `plugins_set_enabled` call is about. Explicit, never inferred — the two
169
+ * systems share the word "plugin" and nothing else, and guessing between them has already produced
170
+ * real work in the wrong directory. The catalog owns this contract; approval presentation consumes it. */
171
+ export type PluginFamily = 'site-runtime' | 'agent-plugin';
172
+ /** The tool id the common access card asks the Host to call back. Single source of truth for both halves. */
173
+ export declare const PLUGINS_SET_ENABLED_TOOL_ID = "plugins_set_enabled";
174
+ //# sourceMappingURL=agent-tools.d.ts.map