@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
@@ -0,0 +1,57 @@
1
+ import path from "node:path";
2
+ import { PluginPackagePathError } from "./package-files.js";
3
+ /**
4
+ * A plugin id safe to use as a single filesystem path segment (Milestone 2, 2026-08-20) — the same
5
+ * character class `src/features/agent-plugins/layout.ts`'s `SAFE_PLUGIN_ID_PATTERN` uses,
6
+ * independently declared here rather than imported: that module is a DIFFERENT, unrelated plugin
7
+ * system (agent-plugins.org format; see this file's own `PluginRuntimeSource` doc history and
8
+ * Milestone 1's handoff for why the two are never wired together), and importing from it would
9
+ * create exactly that coupling for a one-line regex. `.` and `-` are allowed mid-string (matching
10
+ * real semver-adjacent plugin ids like `word-count`) but the pattern has no `/`, no `..`, and no
11
+ * leading/trailing separator — it cannot itself produce a path-traversal segment.
12
+ */
13
+ export const SAFE_PLUGIN_ID_SEGMENT = /^[a-z0-9]+(?:[-.][a-z0-9]+)*$/;
14
+ /** Thrown when `pluginId` is not safe to use as a filesystem path segment
15
+ * under `installDir` — either it fails {@link SAFE_PLUGIN_ID_SEGMENT}'s allowlist, or (defense in
16
+ * depth, in case some future caller's id validation elsewhere ever drifts) the resolved absolute
17
+ * path would land outside `installDir` after resolution. Deliberately fails closed on EITHER
18
+ * check independently, not just the one presumed sufficient.
19
+ * @agent-note Error identity: hosts re-export this ONE class (never a copy) so `instanceof` and
20
+ * `name === "PluginUninstallPathError"` hold across the host's routes and tests. */
21
+ export class PluginUninstallPathError extends Error {
22
+ constructor(pluginId) {
23
+ super(`plugin id '${pluginId}' is not a safe filesystem path segment — refusing to remove it`);
24
+ this.name = "PluginUninstallPathError";
25
+ }
26
+ }
27
+ /** A site plugin's version folder name as discovery read it from disk: one segment, no
28
+ * separator, no leading dot. Checked together with {@link SAFE_PLUGIN_ID_SEGMENT} before either is
29
+ * joined into a path. */
30
+ const SAFE_VERSION_SEGMENT = /^[0-9A-Za-z][0-9A-Za-z.+-]*$/;
31
+ /**
32
+ * Where one discovered plugin's files live, for the package-files viewer: a built-in's own
33
+ * `sourceDir`, or a site plugin's `<installDir>/<id>/<version>/` (REQ-02's layout, the same one
34
+ * `siteEntryPath()` joins). The directory is its own container for a built-in; `installDir` is the
35
+ * container for a site plugin, so `readPluginPackageFiles()`'s realpath check keeps a symlinked id
36
+ * or version folder from reaching outside it.
37
+ *
38
+ * @returns `null` when there is no directory to show: a built-in without `sourceDir`, or a site
39
+ * record while `installDir` is unset.
40
+ * @throws {PluginPackagePathError} a site record's id or version is not one safe path segment — a
41
+ * site record's id comes from its own manifest, so it is untrusted text until checked here.
42
+ * @complexity O(sources.length).
43
+ */
44
+ export function resolvePackageLocation(params) {
45
+ const { record, sources, installDir } = params;
46
+ if (record.source === "built-in") {
47
+ const sourceDir = sources.find((candidate) => candidate.manifest.id === record.id)?.sourceDir;
48
+ return sourceDir === undefined ? null : { rootDir: sourceDir, containerDir: sourceDir };
49
+ }
50
+ if (installDir === undefined)
51
+ return null;
52
+ if (!SAFE_PLUGIN_ID_SEGMENT.test(record.id) || !SAFE_VERSION_SEGMENT.test(record.version)) {
53
+ throw new PluginPackagePathError(`plugin '${record.id}' version '${record.version}' is not a safe path segment`);
54
+ }
55
+ return { rootDir: path.join(installDir, record.id, record.version), containerDir: installDir };
56
+ }
57
+ //# sourceMappingURL=runtime-package-location.js.map
@@ -1,4 +1,4 @@
1
- import { type FileLockOptions } from '@jini-ai/platform/fs/file-lock';
1
+ import { type FileLockPort, type FileLockPortOptions } from '@jini-ai/core/contracts/runtime';
2
2
  import type { ManifestHostPorts } from '../ports.js';
3
3
  import type { PluginSourcePolicyPort } from '../source-policy.js';
4
4
  import { type PluginInstallerPort, type PluginInstallPreview } from './install.js';
@@ -79,6 +79,8 @@ export interface PluginSourceDeps extends ManifestHostPorts {
79
79
  readonly builtInIds: readonly string[];
80
80
  readonly installer: PluginInstallerPort;
81
81
  readonly policy: PluginSourcePolicyPort;
82
+ /** The host's cross-process file lock (Node hosts pass `nodeFileLock` of `@jini-ai/node-adapters/fs`). Required: a default would re-import platform. */
83
+ readonly fileLock: FileLockPort;
82
84
  /** Host-specific opt-in instructions; omitted hosts receive a neutral refusal. */
83
85
  readonly localInstallDisabledMessage?: string;
84
86
  /** Host ABI text, avoiding an external site's dependency on npm package resolution. */
@@ -97,6 +99,6 @@ export interface PluginSourceDeps extends ManifestHostPorts {
97
99
  */
98
100
  export declare function createPluginSourceService(required: PluginSourceDeps, optional?: {
99
101
  temporaryDir?: string;
100
- lockPorts?: Pick<FileLockOptions, 'clock' | 'process' | 'hostname'>;
102
+ lockPorts?: Pick<FileLockPortOptions, 'clock' | 'process' | 'hostname'>;
101
103
  }): PluginSourcePort;
102
104
  //# sourceMappingURL=source-drafts.d.ts.map
@@ -5,7 +5,7 @@ import { lstat, mkdir, mkdtemp, readdir, readFile, rename, rm, writeFile, unlink
5
5
  import path from 'node:path';
6
6
  import { tmpdir } from 'node:os';
7
7
  import * as semver from 'semver';
8
- import { withFileLock, FileLockTimeoutError } from '@jini-ai/platform/fs/file-lock';
8
+ import { FileLockTimeoutError } from '@jini-ai/core/contracts/runtime';
9
9
  import { validateManifest, validatePluginIdFormat } from '../manifest.js';
10
10
  import { PLUGIN_MANIFEST_FILENAME as MANIFEST, LEGACY_PLUGIN_MANIFEST_FILENAME, PLUGIN_MANIFEST_FILENAMES, canonicalizePluginManifest } from '../plugin-format.js';
11
11
  import { computePluginIntegrity, digestSitePluginSnapshot, snapshotSitePluginPackage } from './install.js';
@@ -120,14 +120,7 @@ function parseDraftManifest(files) {
120
120
  function nextSealVersion(latest, declaredVersion) {
121
121
  return latest && !semver.gt(declaredVersion, latest) ? new semver.SemVer(latest).inc('patch').version : declaredVersion;
122
122
  }
123
- /** Build the bounded Node draft adapter.
124
- * @param required Site path and injected manifest, installer, policy and reload owners.
125
- * @param optional.temporaryDir External sealing staging root; defaults to the OS temp directory.
126
- * @returns The source tool port. Typed source/install errors describe refusals; filesystem faults reject.
127
- * @example createPluginSourceService({ ...host, installDir, installer, policy, reload, builtInIds: [], scaffoldEntry }, {})
128
- * @complexity O(package bytes) per operation, capped at 8 MiB / 512 entries.
129
- */
130
- export function createPluginSourceService(required, optional = {}) {
123
+ function createDraftContext(required, optional) {
131
124
  const root = path.resolve(required.installDir);
132
125
  const drafts = path.join(root, '.drafts');
133
126
  const draft = (id) => path.join(drafts, id);
@@ -135,10 +128,14 @@ export function createPluginSourceService(required, optional = {}) {
135
128
  // Beside the per-version provenance markers, so version pruning never removes it and no draft
136
129
  // path (ids cannot start with '.') can write it. Per site: one approval covers every workspace.
137
130
  const approval = (id) => path.join(drafts, '.sealed', id, 'approved.json');
131
+ return { required, optional, root, drafts, draft, marker, approval };
132
+ }
133
+ function createDraftLock(ctx) {
134
+ const { required, optional, root } = ctx;
138
135
  /** Cross-process source lock serializes edits with seal snapshots. Installer keeps its own
139
136
  * publication lock. Platform records pid/time and reclaims only dead owners; age alone must
140
137
  * never steal a long seal from a live process. Token-owned release preserves a replacement. */
141
- async function locked(id, action, options = {}) {
138
+ return async function locked(id, action, options = {}) {
142
139
  safeId(id);
143
140
  if (required.builtInIds.some(builtIn => builtIn.toLowerCase() === id))
144
141
  fail('PLUGIN_SHADOWS_BUILT_IN', 'Built-in plugin source cannot be edited.');
@@ -148,15 +145,18 @@ export function createPluginSourceService(required, optional = {}) {
148
145
  if (!options.createRoot && !await exists(root))
149
146
  fail('PLUGIN_SOURCE_DRAFT_MISSING', 'Create or open a plugin draft first.');
150
147
  try {
151
- return await withFileLock({ lockPath: root + '-source-lock', run: action }, { ...optional.lockPorts, timeoutMs: 100, staleMs: Infinity });
148
+ return await required.fileLock.withFileLock({ lockPath: root + '-source-lock', run: action }, { ...optional.lockPorts, timeoutMs: 100, staleMs: Infinity });
152
149
  }
153
150
  catch (error) {
154
151
  if (error instanceof FileLockTimeoutError)
155
152
  fail('PLUGIN_SOURCE_BUSY', 'Another source operation is in progress. Retry after it finishes.');
156
153
  throw error;
157
154
  }
158
- }
159
- async function versions(id) {
155
+ };
156
+ }
157
+ function createDraftVersionReader(ctx) {
158
+ const { root } = ctx;
159
+ return async function versions(id) {
160
160
  const slot = path.join(root, id);
161
161
  await confined(root, slot);
162
162
  if (!await exists(slot))
@@ -165,14 +165,20 @@ export function createPluginSourceService(required, optional = {}) {
165
165
  if (entries.some(version => !semver.valid(version)))
166
166
  fail('PLUGIN_SOURCE_VERSION_INVALID', 'Installed plugin has an unrecognized version folder.');
167
167
  return entries.sort(semver.rcompare);
168
- }
169
- async function snapshot(location) {
168
+ };
169
+ }
170
+ function createDraftSnapshotReader(ctx) {
171
+ const { root } = ctx;
172
+ return async function snapshot(location) {
170
173
  await confined(root, location);
171
174
  if (!await exists(location))
172
175
  fail('PLUGIN_SOURCE_DRAFT_MISSING', 'Open an installed plugin with plugin_source_open or scaffold it with plugin_source_create first.');
173
176
  return snapshotSitePluginPackage({ sourceDir: location }, PLUGIN_SOURCE_LIMITS);
174
- }
175
- async function putDraft(id, files) {
177
+ };
178
+ }
179
+ function createDraftInstaller(ctx) {
180
+ const { root, drafts, draft } = ctx;
181
+ return async function putDraft(id, files) {
176
182
  await confined(root, draft(id));
177
183
  await confined(root, drafts);
178
184
  await mkdir(drafts, { recursive: true });
@@ -188,8 +194,12 @@ export function createPluginSourceService(required, optional = {}) {
188
194
  finally {
189
195
  await rm(staging, { recursive: true, force: true });
190
196
  }
191
- }
192
- async function open(id) {
197
+ };
198
+ }
199
+ function createDraftOpener(ctx, deps) {
200
+ const { root, draft } = ctx;
201
+ const { snapshot, versions, putDraft } = deps;
202
+ return async function open(id) {
193
203
  await confined(root, draft(id));
194
204
  if (await exists(draft(id))) {
195
205
  await snapshot(draft(id));
@@ -201,8 +211,12 @@ export function createPluginSourceService(required, optional = {}) {
201
211
  const files = await snapshot(path.join(root, id, latest));
202
212
  await putDraft(id, files);
203
213
  return { created: true };
204
- }
205
- async function write(id, file, content) {
214
+ };
215
+ }
216
+ function createDraftWriter(ctx, deps) {
217
+ const { root, draft } = ctx;
218
+ const { snapshot } = deps;
219
+ return async function write(id, file, content) {
206
220
  safeFile(file);
207
221
  if (file === LEGACY_PLUGIN_MANIFEST_FILENAME)
208
222
  file = MANIFEST; // legacy alias
@@ -221,8 +235,12 @@ export function createPluginSourceService(required, optional = {}) {
221
235
  if (file === MANIFEST)
222
236
  await rm(path.join(draft(id), LEGACY_PLUGIN_MANIFEST_FILENAME), { force: true }); // legacy alias
223
237
  return { bytesWritten: bytes.length };
224
- }
225
- async function read(id, file) {
238
+ };
239
+ }
240
+ function createDraftReader(ctx, deps) {
241
+ const { draft } = ctx;
242
+ const { snapshot } = deps;
243
+ return async function read(id, file) {
226
244
  safeFile(file);
227
245
  const files = await snapshot(draft(id));
228
246
  if (PLUGIN_MANIFEST_FILENAMES.includes(file))
@@ -231,15 +249,22 @@ export function createPluginSourceService(required, optional = {}) {
231
249
  if (!bytes)
232
250
  fail('PLUGIN_SOURCE_FILE_MISSING', 'The requested file is not in the draft.');
233
251
  return { content: bytes.toString('utf8'), bytes: bytes.length, digest: digestSitePluginSnapshot({ files: new Map([[file, bytes]]) }) };
234
- }
235
- function validate(id, manifest) {
252
+ };
253
+ }
254
+ function createDraftValidator(ctx) {
255
+ const { required } = ctx;
256
+ return function validate(id, manifest) {
236
257
  const errors = validateManifest({ ...required, manifest, folderName: id, builtInIds: required.builtInIds }).errors;
237
258
  if (errors.length)
238
259
  fail('PLUGIN_MANIFEST_INVALID', errors.map(error => error.message).join('; '));
239
- }
260
+ };
261
+ }
262
+ function createDraftPublisher(ctx, deps) {
263
+ const { required, optional, root, marker } = ctx;
264
+ const { validate, versions, reloadAndPrune } = deps;
240
265
  /** Install a sealed, immutable copy outside discovery's tree. No alternate installer or ZIP
241
266
  * encoder is needed; the folder installer refuses sources inside its own destination. */
242
- async function publish(id, files, rollbackFrom) {
267
+ return async function publish(id, files, rollbackFrom) {
243
268
  if (!required.policy.localInstallEnabled({}, {}))
244
269
  fail('PLUGIN_LOCAL_INSTALL_DISABLED', required.localInstallDisabledMessage ?? 'Local plugin install is disabled by the host.');
245
270
  const raw = parseDraftManifest(files);
@@ -263,17 +288,20 @@ export function createPluginSourceService(required, optional = {}) {
263
288
  finally {
264
289
  await rm(staging, { recursive: true, force: true });
265
290
  }
266
- }
267
- /** Writes the draft files, then the manifest with the sealed version and fresh integrity. */
268
- async function stageSealedPackage(staging, files, manifest) {
269
- for (const [file, bytes] of canonicalizePluginManifest({ files })) {
270
- safeFile(file);
271
- await writeAtomic(staging, path.join(staging, file), bytes);
272
- } // legacy alias
273
- const integrity = await computePluginIntegrity({ sourceDir: staging });
274
- await writeAtomic(staging, path.join(staging, MANIFEST), jsonBytes({ ...manifest, integrity }));
275
- }
276
- async function reloadAndPrune(id, plugin, rollback) {
291
+ };
292
+ }
293
+ /** Writes the draft files, then the manifest with the sealed version and fresh integrity. */
294
+ async function stageSealedPackage(staging, files, manifest) {
295
+ for (const [file, bytes] of canonicalizePluginManifest({ files })) {
296
+ safeFile(file);
297
+ await writeAtomic(staging, path.join(staging, file), bytes);
298
+ } // legacy alias
299
+ const integrity = await computePluginIntegrity({ sourceDir: staging });
300
+ await writeAtomic(staging, path.join(staging, MANIFEST), jsonBytes({ ...manifest, integrity }));
301
+ }
302
+ function createDraftReload(ctx) {
303
+ const { required, root, marker } = ctx;
304
+ return async function reloadAndPrune(id, plugin, rollback) {
277
305
  let reloaded = false;
278
306
  try {
279
307
  reloaded = await required.reload({ id }, {});
@@ -288,7 +316,10 @@ export function createPluginSourceService(required, optional = {}) {
288
316
  await rm(path.dirname(marker(id, retired)), { recursive: true, force: true });
289
317
  }
290
318
  return { installed: true, plugin, reloaded, ...rollback };
291
- }
319
+ };
320
+ }
321
+ function draftFileOperations(ctx) {
322
+ const { required, root, draft, locked, versions, snapshot, putDraft, open, write, read, validate } = ctx;
292
323
  return {
293
324
  create: ({ id, name, description }, _options = {}) => locked(id, async () => {
294
325
  if (typeof name !== 'string' || !name.trim() || typeof description !== 'string')
@@ -310,6 +341,11 @@ export function createPluginSourceService(required, optional = {}) {
310
341
  list: ({ id }, _options = {}) => locked(id, async () => ({ files: [...await snapshot(draft(id))].map(([file, bytes]) => ({ path: file, bytes: bytes.length })) })),
311
342
  read: ({ id, path: file }, _options = {}) => locked(id, () => read(id, file)),
312
343
  write: ({ id, path: file, content }, _options = {}) => locked(id, () => write(id, file, content)),
344
+ };
345
+ }
346
+ function draftEditOperations(ctx) {
347
+ const { root, draft, locked, write, read } = ctx;
348
+ return {
313
349
  edit: ({ id, path: file, oldString, newString, replaceAll }, _options = {}) => locked(id, async () => {
314
350
  const validReplaceAll = replaceAll === undefined || typeof replaceAll === 'boolean';
315
351
  if (typeof oldString !== 'string' || !oldString || typeof newString !== 'string' || !validReplaceAll)
@@ -335,6 +371,11 @@ export function createPluginSourceService(required, optional = {}) {
335
371
  await unlink(target);
336
372
  return { deleted: true };
337
373
  }),
374
+ };
375
+ }
376
+ function draftPublicationOperations(ctx) {
377
+ const { required, root, draft, marker, locked, versions, snapshot, publish } = ctx;
378
+ return {
338
379
  seal: ({ id }, _options = {}) => locked(id, async () => publish(id, await snapshot(draft(id)))),
339
380
  rollback: ({ id }, _options = {}) => locked(id, async () => {
340
381
  const previous = (await versions(id))[1];
@@ -359,6 +400,11 @@ export function createPluginSourceService(required, optional = {}) {
359
400
  const digest = JSON.parse(markers.get(path.basename(provenance)).toString('utf8')).digest;
360
401
  return digest === digestSitePluginSnapshot({ files: await snapshot(path.join(root, id, version)) });
361
402
  },
403
+ };
404
+ }
405
+ function draftApprovalOperations(ctx) {
406
+ const { root, approval } = ctx;
407
+ return {
362
408
  // Lock-free like isSealedHere: rename-published, and enabling during a seal must not fail BUSY.
363
409
  readApproval: async ({ id }, _options = {}) => {
364
410
  safeId(id);
@@ -384,4 +430,26 @@ export function createPluginSourceService(required, optional = {}) {
384
430
  },
385
431
  };
386
432
  }
433
+ /** Build the bounded Node draft adapter.
434
+ * @param required Site path and injected manifest, installer, policy and reload owners.
435
+ * @param optional.temporaryDir External sealing staging root; defaults to the OS temp directory.
436
+ * @returns The source tool port. Typed source/install errors describe refusals; filesystem faults reject.
437
+ * @example createPluginSourceService({ ...host, installDir, installer, policy, reload, builtInIds: [], scaffoldEntry }, {})
438
+ * @complexity O(package bytes) per operation, capped at 8 MiB / 512 entries.
439
+ */
440
+ export function createPluginSourceService(required, optional = {}) {
441
+ const ctx = createDraftContext(required, optional);
442
+ const locked = createDraftLock(ctx);
443
+ const versions = createDraftVersionReader(ctx);
444
+ const snapshot = createDraftSnapshotReader(ctx);
445
+ const putDraft = createDraftInstaller(ctx);
446
+ const open = createDraftOpener(ctx, { snapshot, versions, putDraft });
447
+ const write = createDraftWriter(ctx, { snapshot });
448
+ const read = createDraftReader(ctx, { snapshot });
449
+ const validate = createDraftValidator(ctx);
450
+ const reloadAndPrune = createDraftReload(ctx);
451
+ const publish = createDraftPublisher(ctx, { validate, versions, reloadAndPrune });
452
+ const operations = { ...ctx, locked, versions, snapshot, putDraft, open, write, read, validate, publish, reloadAndPrune };
453
+ return { ...draftFileOperations(operations), ...draftEditOperations(operations), ...draftPublicationOperations(operations), ...draftApprovalOperations(operations) };
454
+ }
387
455
  //# sourceMappingURL=source-drafts.js.map
@@ -2,44 +2,7 @@
2
2
  import type { PluginManifest, PluginValidationError } from './manifest-types.js';
3
3
  import type { PluginDiscoveryRecord } from './discovery-types.js';
4
4
  import type { ClaimMode } from './claim-conflicts.js';
5
- /** Plain serializable entry envelope; hosts extend it with their own hook payload fields. */
6
- export interface ContentEntryDraft {
7
- readonly workspaceId: string;
8
- readonly ext: Readonly<Record<string, Readonly<Record<string, unknown>>>>;
9
- }
10
- export interface HookContext {
11
- readonly pluginId: string;
12
- readonly workspaceId: string;
13
- }
14
- export type ExtPatch = Readonly<Record<string, string | number | boolean>>;
15
- /** Positional callbacks are the existing plugin wire ABI, not Jini factory boundaries. */
16
- export type BeforeSaveFilter = (entry: Readonly<ContentEntryDraft>, ctx: HookContext) => ExtPatch | Promise<ExtPatch>;
17
- export type HookPoints = Readonly<Record<string, unknown>>;
18
- export interface PluginSdk<H extends HookPoints = HookPoints> {
19
- readonly providers: import('./provider-contributions.js').PluginProvidersSdk;
20
- readonly plugins?: import("@jini-ai/core/plugin-directory").PluginLookupPort;
21
- readonly content: {
22
- read(): Readonly<ContentEntryDraft>;
23
- extend(field: string, value: string | number | boolean): void;
24
- };
25
- addFilter<K extends keyof H & string>(hookName: K, filter: H[K] extends (...args: never[]) => unknown ? H[K] : BeforeSaveFilter): void;
26
- readonly routes: {
27
- add(required: import('./contributions.js').PluginRouteContribution, optional?: Record<string, never>): void;
28
- };
29
- readonly tools: {
30
- add(required: import('./contributions.js').PluginToolContribution, optional?: Record<string, never>): void;
31
- };
32
- readonly widgets: {
33
- add(required: import('./contributions.js').PluginWidgetContribution, optional?: Record<string, never>): void;
34
- };
35
- addAction(...args: never[]): void;
36
- addContribution(required: import('./contributions.js').PluginContribution, optional?: Record<string, never>): void;
37
- }
38
- export interface DefinedPlugin<H extends HookPoints = HookPoints> {
39
- readonly definition: {
40
- setup(sdk: PluginSdk<H>): void | Promise<void>;
41
- };
42
- }
5
+ import type { DefinedPlugin, HookPoints, PluginSdk } from '@jini-ai/core/contracts/plugin-sdk';
43
6
  /** Required binding to the host-owned SDK. Hook ids and semantics never default to a product catalog.
44
7
  * @example { hookIds: ['beforeSave'], beforeSaveHook: 'beforeSave', hookSemantics: { beforeSave: 'shared' }, ...abi }
45
8
  */
@@ -113,6 +76,7 @@ export interface DeclarativeContentTypesPort {
113
76
  export interface ManifestHostPorts<H extends HookPoints = HookPoints> {
114
77
  /** Host-owned namespace containing publisher id/provides in persisted manifest extensions. */
115
78
  readonly identityNamespace: string;
79
+ readonly legacyIdentityNamespace?: string;
116
80
  readonly pluginSdkBinding: PluginSdkBinding<H>;
117
81
  readonly capabilityVocabulary: readonly string[];
118
82
  readonly declarativeContentTypes: DeclarativeContentTypesPort;
@@ -1,17 +1,5 @@
1
- import type { PluginProviderDeclaration, PluginValidationError } from './manifest-types.js';
2
- export declare const PLUGIN_PROVIDER_CAPABILITY: "providers.register";
3
- export interface PluginProviderResource<T = unknown> {
4
- readonly port: T;
5
- /** Release owned resources only; borrowed effect ports remain host-owned. */
6
- readonly dispose: (required: Record<string, never>, optional?: Record<string, never>) => void | Promise<void>;
7
- }
8
- export type PluginProviderFactory = (required: Readonly<Record<string, unknown>>, optional?: Readonly<Record<string, unknown>>) => PluginProviderResource | Promise<PluginProviderResource>;
9
- export interface PluginProviderContribution extends PluginProviderDeclaration {
10
- readonly factory: PluginProviderFactory;
11
- }
12
- export interface PluginProvidersSdk {
13
- register(required: PluginProviderContribution, optional?: Record<string, never>): void;
14
- }
1
+ import type { PluginValidationError } from './manifest-types.js';
2
+ import { type PluginProviderDeclaration } from '@jini-ai/core/contracts/plugin-sdk';
15
3
  /** Shared grammar for manifest validation and runtime capture, using core's frozen id contract. */
16
4
  export declare function isPluginProviderDeclaration(required: {
17
5
  value: unknown;
@@ -1,6 +1,6 @@
1
1
  /** Server factories are inert registrations. Clients and timers belong to initialized resources. */
2
2
  import { PROVIDER_ID_PATTERN } from '@jini-ai/core/provider-registry';
3
- export const PLUGIN_PROVIDER_CAPABILITY = 'providers.register';
3
+ import { PLUGIN_PROVIDER_CAPABILITY } from '@jini-ai/core/contracts/plugin-sdk';
4
4
  /** Shared grammar for manifest validation and runtime capture, using core's frozen id contract. */
5
5
  export function isPluginProviderDeclaration(required, _optional = {}) {
6
6
  const value = required.value;
@@ -1,7 +1,7 @@
1
1
  /** Resource lifecycle for the existing contribution snapshots. Domain validation stays injected. */
2
2
  import { type ProviderDefinition } from '@jini-ai/core/provider-registry';
3
3
  import type { PluginContributionRegistry } from './contributions.js';
4
- import type { PluginProviderResource } from './provider-contributions.js';
4
+ import type { PluginProviderResource } from '@jini-ai/core/contracts/plugin-sdk';
5
5
  export interface PluginProviderContract {
6
6
  readonly contract: string;
7
7
  /** Supplied by the domain owner; plugins never select or replace this validator. */
@@ -9,6 +9,9 @@ export interface PluginProviderContract {
9
9
  provider: unknown;
10
10
  }, optional?: Record<string, never>) => string | undefined;
11
11
  readonly seed?: readonly ProviderDefinition<unknown>[];
12
+ /** Domain-owned helper values handed to every provider of this contract as the factory's
13
+ * `optional.context`. Providers restate their shape and never import the domain. */
14
+ readonly context?: Readonly<Record<string, unknown>>;
12
15
  }
13
16
  export interface PluginProviderFailure {
14
17
  readonly pluginId: string;
@@ -39,24 +42,6 @@ export declare class PluginProviderError extends Error {
39
42
  message: string;
40
43
  }, _optional?: Record<string, never>);
41
44
  }
42
- /** Explicit plugin-authored startup guidance. Raw SDK errors must never be shown to users. */
43
- export declare class PluginProviderStartupError extends Error {
44
- readonly reason: string;
45
- readonly action: string;
46
- constructor({ reason, action, cause }: {
47
- reason: string;
48
- action: string;
49
- cause?: unknown;
50
- }, _optional?: {});
51
- }
52
- /** Startup guidance from a {@link PluginProviderStartupError}, matched by shape: each provider plugin
53
- * artifact bundles its own copy of this class, so `instanceof` against the host's copy is always false. */
54
- export declare function pluginProviderStartupGuidance({ error }: {
55
- error: unknown;
56
- }, _optional?: {}): {
57
- reason: string;
58
- action: string;
59
- } | undefined;
60
45
  /** Applying saved settings either succeeds, requires a browser/process refresh, or fails to start. */
61
46
  export type PluginProviderApplyResult = 'now' | 'restart' | {
62
47
  appliesAt: 'failed';