@jini-ai/agent-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 (233) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/README.md +22 -4
  3. package/calendly/README.md +29 -0
  4. package/calendly/mcp.json +1 -1
  5. package/cloudflare/lib/assets.mjs +1 -1
  6. package/cloudflare/lib/cms-forms.mjs +1 -1
  7. package/core/persistent-state.d.ts +4 -1
  8. package/core/persistent-state.js +55 -21
  9. package/dist/admin-surfaces/callback-field-inbox.d.ts +1 -6
  10. package/dist/admin-surfaces/connections/connections.d.ts +2 -6
  11. package/dist/admin-surfaces/connections/index.d.ts +3 -2
  12. package/dist/admin-surfaces/index.d.ts +3 -1
  13. package/dist/connect/access-token-tool.d.ts +1 -1
  14. package/dist/connect/access-token-tool.js +1 -1
  15. package/dist/connect/catalog.d.ts +26 -0
  16. package/dist/connect/catalog.js +42 -0
  17. package/dist/connect/connect-tool.d.ts +2 -294
  18. package/dist/connect/connect-tool.js +2 -53
  19. package/dist/connect/contracts.d.ts +257 -0
  20. package/dist/connect/contracts.js +2 -0
  21. package/dist/connect/credential-cards.d.ts +2 -0
  22. package/dist/connect/credential-cards.js +7 -4
  23. package/dist/connect/grant-signed-in-defaults.js +1 -1
  24. package/dist/connect/host-deps.d.ts +32 -0
  25. package/dist/connect/host-deps.js +35 -0
  26. package/dist/connect/import-access-token.js +1 -1
  27. package/dist/connect/index.d.ts +7 -2
  28. package/dist/connect/index.js +5 -2
  29. package/dist/connect/installed-plugin.d.ts +28 -0
  30. package/dist/connect/installed-plugin.js +19 -0
  31. package/dist/connect/new-site-agent-plugin-tokens.d.ts +88 -0
  32. package/dist/connect/new-site-agent-plugin-tokens.js +107 -0
  33. package/dist/connect/plugin-host/index.d.ts +2 -2
  34. package/dist/connect/plugin-host/index.js +19 -10
  35. package/dist/connect/token-sign-in.d.ts +1 -14
  36. package/dist/connect/token-sign-in.js +4 -23
  37. package/dist/core/export-props.d.ts +10 -0
  38. package/dist/core/export-props.js +31 -0
  39. package/dist/core/folder-zip-error.d.ts +5 -0
  40. package/dist/core/folder-zip-error.js +8 -0
  41. package/dist/core/host-incompatible-error.d.ts +8 -0
  42. package/dist/core/host-incompatible-error.js +9 -0
  43. package/dist/core/identity-namespace.d.ts +27 -16
  44. package/dist/core/identity-namespace.js +25 -22
  45. package/dist/core/plugin-display-name.d.ts +7 -0
  46. package/dist/core/plugin-display-name.js +11 -0
  47. package/dist/core/provider-plugin-link.d.ts +7 -0
  48. package/dist/core/provider-plugin-link.js +5 -0
  49. package/dist/{connect → core}/token-map.d.ts +11 -1
  50. package/dist/{connect → core}/token-map.js +15 -0
  51. package/dist/core/token-sign-in-list.d.ts +18 -0
  52. package/dist/core/token-sign-in-list.js +23 -0
  53. package/dist/core/update-error.d.ts +8 -0
  54. package/dist/core/update-error.js +9 -0
  55. package/dist/{lifecycle → core}/update-plan.d.ts +1 -1
  56. package/dist/ffmpeg-transcode/adapter.d.ts +74 -0
  57. package/dist/ffmpeg-transcode/adapter.js +155 -0
  58. package/dist/folder-zip-node.d.ts +2 -1
  59. package/dist/folder-zip-node.js +6 -5
  60. package/dist/folder-zip.d.ts +0 -4
  61. package/dist/folder-zip.js +1 -7
  62. package/dist/index.d.ts +3 -1
  63. package/dist/lifecycle/activation.d.ts +39 -3
  64. package/dist/lifecycle/activation.js +467 -418
  65. package/dist/lifecycle/automatic-use-offer.d.ts +62 -0
  66. package/dist/lifecycle/automatic-use-offer.js +52 -0
  67. package/dist/lifecycle/automatic-use.d.ts +33 -1
  68. package/dist/lifecycle/automatic-use.js +157 -38
  69. package/dist/lifecycle/bundled-source-archive.d.ts +1 -1
  70. package/dist/lifecycle/capability-projection.d.ts +0 -1
  71. package/dist/lifecycle/capability-projection.js +92 -23
  72. package/dist/lifecycle/compatibility-metadata.d.ts +1 -0
  73. package/dist/lifecycle/compatibility-metadata.js +6 -1
  74. package/dist/lifecycle/compatibility.d.ts +1 -8
  75. package/dist/lifecycle/compatibility.js +1 -8
  76. package/dist/lifecycle/credential-card-metadata.d.ts +2 -2
  77. package/dist/lifecycle/exports.d.ts +2 -45
  78. package/dist/lifecycle/exports.js +1 -30
  79. package/dist/lifecycle/host-tools/identity.d.ts +5 -4
  80. package/dist/lifecycle/host-tools/identity.js +5 -5
  81. package/dist/lifecycle/host-tools/ports.d.ts +10 -1
  82. package/dist/lifecycle/host-tools/search-tool.d.ts +4 -2
  83. package/dist/lifecycle/host-tools/search-tool.js +19 -8
  84. package/dist/lifecycle/host-tools/skill-tool.js +1 -1
  85. package/dist/lifecycle/index.d.ts +20 -17
  86. package/dist/lifecycle/index.js +5 -4
  87. package/dist/lifecycle/install-from-url.d.ts +1 -2
  88. package/dist/lifecycle/install.d.ts +4 -34
  89. package/dist/lifecycle/install.js +3 -3
  90. package/dist/lifecycle/installed-package-index.d.ts +1 -1
  91. package/dist/lifecycle/installed-package-index.js +4 -4
  92. package/dist/lifecycle/layout.d.ts +21 -25
  93. package/dist/lifecycle/layout.js +79 -0
  94. package/dist/lifecycle/manifest.d.ts +10 -7
  95. package/dist/lifecycle/manifest.js +20 -15
  96. package/dist/lifecycle/mcp-provisioning.d.ts +1 -1
  97. package/dist/lifecycle/metadata.d.ts +6 -3
  98. package/dist/lifecycle/metadata.js +2 -1
  99. package/dist/lifecycle/package-paths.js +59 -56
  100. package/dist/lifecycle/persistent-state.d.ts +10 -1
  101. package/dist/lifecycle/persistent-state.js +4 -2
  102. package/dist/lifecycle/ports.d.ts +18 -6
  103. package/dist/lifecycle/resolve-agent-plugin-refs.d.ts +2 -14
  104. package/dist/lifecycle/retire-bundled.d.ts +1 -1
  105. package/dist/lifecycle/search-projection.d.ts +3 -1
  106. package/dist/lifecycle/search-projection.js +7 -3
  107. package/dist/lifecycle/search.d.ts +1 -0
  108. package/dist/lifecycle/seed-bundled.d.ts +86 -1
  109. package/dist/lifecycle/seed-bundled.js +48 -84
  110. package/dist/lifecycle/set-enabled.d.ts +1 -13
  111. package/dist/lifecycle/set-enabled.js +11 -7
  112. package/dist/lifecycle/trusted-plugin-files.d.ts +1 -1
  113. package/dist/lifecycle/trusted-plugin-files.js +33 -30
  114. package/dist/lifecycle/types.d.ts +13 -34
  115. package/dist/lifecycle/uninstall.d.ts +1 -33
  116. package/dist/lifecycle/update-store.d.ts +0 -7
  117. package/dist/lifecycle/update-store.js +1 -8
  118. package/dist/lifecycle/update.d.ts +1 -1
  119. package/dist/lifecycle/update.js +60 -10
  120. package/dist/lifecycle/yauzl-archive-reader.d.ts +7 -2
  121. package/dist/lifecycle/yauzl-archive-reader.js +11 -6
  122. package/dist/manifest.d.ts +4 -8
  123. package/dist/react/AgentPluginDetailsModal.d.ts +187 -0
  124. package/dist/react/AgentPluginDetailsModal.js +29 -0
  125. package/dist/react/agent-plugin-install-port.d.ts +24 -0
  126. package/dist/react/agent-plugin-install-port.js +15 -0
  127. package/dist/react/installed-skills-composer-source.d.ts +60 -0
  128. package/dist/react/installed-skills-composer-source.js +111 -0
  129. package/dist/react/use-agent-plugins.hooks.d.ts +211 -0
  130. package/dist/react/use-agent-plugins.hooks.js +128 -0
  131. package/dist/site/activation-effects.d.ts +17 -0
  132. package/dist/site/activation-effects.js +31 -0
  133. package/dist/site/admin-surfaces/capabilities.d.ts +29 -0
  134. package/dist/site/admin-surfaces/capabilities.js +30 -0
  135. package/dist/site/admin-surfaces/delivery-bindings.d.ts +81 -0
  136. package/dist/site/admin-surfaces/delivery-bindings.js +161 -0
  137. package/dist/site/admin-surfaces/forms.d.ts +28 -0
  138. package/dist/site/admin-surfaces/forms.js +29 -0
  139. package/dist/site/admin-surfaces/handlers.d.ts +61 -0
  140. package/dist/site/admin-surfaces/handlers.js +35 -0
  141. package/dist/site/admin-surfaces/public-config.d.ts +12 -0
  142. package/dist/site/admin-surfaces/public-config.js +28 -0
  143. package/dist/site/analytics-provider-registry.d.ts +87 -0
  144. package/dist/site/analytics-provider-registry.js +87 -0
  145. package/dist/site/archive-reader-abi.d.ts +35 -0
  146. package/dist/site/archive-reader-abi.js +25 -0
  147. package/dist/site/auth-schemes.d.ts +110 -0
  148. package/dist/site/auth-schemes.js +119 -0
  149. package/dist/site/automatic-agent-plugins.d.ts +200 -0
  150. package/dist/site/automatic-agent-plugins.js +277 -0
  151. package/dist/site/bundled-contribution-sources.d.ts +24 -0
  152. package/dist/site/bundled-contribution-sources.js +17 -0
  153. package/dist/site/bundled-id-upgrade.d.ts +115 -0
  154. package/dist/site/bundled-id-upgrade.js +169 -0
  155. package/dist/site/customize-tool.d.ts +39 -0
  156. package/dist/site/customize-tool.js +31 -0
  157. package/dist/site/deploy-split-activation.d.ts +28 -0
  158. package/dist/site/deploy-split-activation.js +21 -0
  159. package/dist/site/exports/diagnostics.d.ts +37 -0
  160. package/dist/site/exports/diagnostics.js +55 -0
  161. package/dist/site/exports/runtime.d.ts +54 -0
  162. package/dist/site/exports/runtime.js +196 -0
  163. package/dist/site/exports/source.d.ts +42 -0
  164. package/dist/site/exports/source.js +58 -0
  165. package/dist/site/host-plugin-guidance.d.ts +137 -0
  166. package/dist/site/host-plugin-guidance.js +223 -0
  167. package/dist/site/host-signals.d.ts +78 -0
  168. package/dist/site/host-signals.js +83 -0
  169. package/dist/site/install-tool.d.ts +69 -0
  170. package/dist/site/install-tool.js +192 -0
  171. package/dist/site/install-upload.d.ts +175 -0
  172. package/dist/site/install-upload.js +324 -0
  173. package/dist/site/memory-i18n.d.ts +5 -0
  174. package/dist/site/memory-i18n.js +176 -0
  175. package/dist/site/memory.d.ts +80 -0
  176. package/dist/site/memory.js +83 -0
  177. package/dist/site/plugin-memory.d.ts +80 -0
  178. package/dist/site/plugin-memory.js +86 -0
  179. package/dist/site/provider-plugin-link.d.ts +112 -0
  180. package/dist/site/provider-plugin-link.js +100 -0
  181. package/dist/site/retired-plugin-tool-aliases.d.ts +40 -0
  182. package/dist/site/retired-plugin-tool-aliases.js +41 -0
  183. package/dist/site/service-ports.d.ts +108 -0
  184. package/dist/site/service-ports.js +2 -0
  185. package/dist/site/set-enabled.d.ts +80 -0
  186. package/dist/site/set-enabled.js +42 -0
  187. package/dist/site/soon-lock.d.ts +83 -0
  188. package/dist/site/soon-lock.js +78 -0
  189. package/dist/site/supersession.d.ts +61 -0
  190. package/dist/site/supersession.js +122 -0
  191. package/dist/site/uninstall-tool.d.ts +136 -0
  192. package/dist/site/uninstall-tool.js +203 -0
  193. package/dist/site/update-effects.d.ts +47 -0
  194. package/dist/site/update-effects.js +49 -0
  195. package/ffmpeg-transcode/plugin.json +16 -0
  196. package/github/source-control/backup-push.mjs +66 -46
  197. package/github/source-control/commit-site.mjs +124 -67
  198. package/github/source-control/write-files.mjs +86 -53
  199. package/github-pages/targets/github-pages.mjs +294 -233
  200. package/google-workspace/form-destinations/mapping.mjs +15 -7
  201. package/google-workspace/form-destinations/sheets.mjs +4 -2
  202. package/google-workspace/plugin.json +1 -0
  203. package/kuinetic/CHANGELOG.md +4 -0
  204. package/kuinetic/plugin.json +4 -1
  205. package/kuinetic/skills/kuinetic/SKILL.md +1 -2
  206. package/package.json +297 -20
  207. package/persistent-state.d.ts +4 -1
  208. package/resend/adapters/resend.mjs +5 -2
  209. package/resend/plugin.json +1 -1
  210. package/s3-compatible/jini-deploy-targets.json +1 -1
  211. package/s3-compatible/object-stores/s3-compatible.mjs +27 -4
  212. package/s3-compatible/targets/s3-compatible.mjs +3 -3
  213. package/site-import/plugin.json +3 -3
  214. package/site-import/skills/site-import/SKILL.md +62 -54
  215. package/site-import/skills/site-import/references/content-mapping.md +26 -20
  216. package/slide-design/plugin.json +1 -1
  217. package/slide-design/skills/slide-design/SKILL.md +8 -2
  218. package/ui-ux-design/CHANGELOG.md +6 -0
  219. package/ui-ux-design/plugin.json +1 -1
  220. package/ui-ux-design/skills/gstack-design/SKILL.md +6 -6
  221. package/ui-ux-design/skills/ui-ux-design/SKILL.md +3 -2
  222. package/ui-ux-design/skills/ui-ux-design/references/chrome-mobile-test-matrix.md +14 -12
  223. package/ui-ux-design/skills/ui-ux-design/references/ui-loop.md +16 -17
  224. package/vercel/NOTES.md +2 -1
  225. package/vercel/object-stores/vercel-blob.mjs +3 -4
  226. package/vercel/targets/vercel.mjs +425 -351
  227. package/core/commerce-server.d.ts +0 -2
  228. package/core/commerce-server.mjs +0 -2
  229. package/dist/admin-surfaces/connections/ports.d.ts +0 -110
  230. package/dist/admin-surfaces/connections/ports.js +0 -2
  231. /package/dist/{lifecycle → core}/install-errors.d.ts +0 -0
  232. /package/dist/{lifecycle → core}/install-errors.js +0 -0
  233. /package/dist/{lifecycle → core}/update-plan.js +0 -0
@@ -0,0 +1,169 @@
1
+ /**
2
+ * @file Bundled plugin publisher-ID upgrade: a host maintenance step with verified bundled replacements.
3
+ *
4
+ * A bundled package set can move to a new publisher id while its local name (the activation key) does
5
+ * not change. The install admission then sees a different publisher in the same slot and refuses the
6
+ * canonical package (`PLUGIN_ID_CONFLICT`). Without this step every existing site keeps its
7
+ * pre-rename copy forever and logs one seed failure per plugin per boot. The host injects the rename
8
+ * map (`renamed`: local id -> pre-rename and canonical publisher-qualified ids) and the held-reason
9
+ * wording for a copy its own build did not install.
10
+ *
11
+ * The step runs just before seeding. For each renamed local id it moves the installed pre-rename
12
+ * revisions out of the live package root, but only when the ledgered revision is PROVABLY the one the host's
13
+ * build shipped:
14
+ * 1. its manifest declares exactly the pre-rename id, not some other publisher;
15
+ * 2. its digest is the one the bundled-digest ledger recorded, i.e. the host build's own seed put it
16
+ * there (an upload or a different build's copy is not in the ledger);
17
+ * 3. re-packing its files reproduces that digest, so nobody edited it after install;
18
+ * 4. this build's bundled source really ships the canonical id, so seeding has a replacement.
19
+ * Historical revisions with the same pre-rename id move aside without being trusted as content.
20
+ * An unverified current revision is left exactly where it is and reported in plain words.
21
+ *
22
+ * Only the package bytes move. Activation is keyed by the short name and the plugin's `data/` and
23
+ * `memory/` folders sit beside `package/`, so the owner's switch, settings, data and memory stay.
24
+ * The moved copy is kept under `<workspace>/.bundled-id-upgrade/<id>/<digest>` (dot-prefixed, so the
25
+ * package index never reads it as a plugin) and is put back when the replacement does not seed.
26
+ */
27
+ import path from "node:path";
28
+ /** Folder (inside the workspace root) holding moved pre-rename revisions. */
29
+ export const BUNDLED_ID_UPGRADE_BACKUP_DIRNAME = ".bundled-id-upgrade";
30
+ /**
31
+ * Moves pre-rename bundled revisions aside after verifying the ledgered current revision.
32
+ * @param required.renamed - The host's rename map (it owns which ids moved).
33
+ * @returns One outcome per renamed plugin that still has a pre-rename revision installed; empty
34
+ * (after one directory listing) once a site is upgraded.
35
+ * @throws Nothing for a single plugin: its fault becomes a `held` outcome. Listing faults propagate
36
+ * to the caller, which treats the whole step as optional.
37
+ * @complexity O(r) revisions listed; O(f) file reads to re-pack each ledgered current revision.
38
+ */
39
+ export async function upgradeRenamedBundledPlugins(required, _optional = {}) {
40
+ const { renamed } = required;
41
+ const installed = await required.port.listInstalledPlugins({ workspaceRoot: required.workspaceRoot });
42
+ const blocked = [...renamed].filter(([pluginId, ids]) => blockersOf({ installed, pluginId, to: ids.to }).length > 0);
43
+ if (blocked.length === 0)
44
+ return [];
45
+ const ledger = await required.port.readBundledAgentPluginDigests({ workspaceRoot: required.workspaceRoot });
46
+ const outcomes = [];
47
+ for (const [pluginId, ids] of blocked) {
48
+ const outcome = await upgradeOne({ workspaceRoot: required.workspaceRoot, port: required.port, ledgerMismatchReason: required.ledgerMismatchReason, ledger, pluginId, ids, blockers: blockersOf({ installed, pluginId, to: ids.to }) })
49
+ .catch(() => ({ status: "held", pluginId, to: ids.to, reason: "its installed copy could not be checked" }));
50
+ if (outcome !== undefined)
51
+ outcomes.push(outcome);
52
+ }
53
+ return outcomes;
54
+ }
55
+ /** Same-slot revisions that would make Jini refuse the canonical id. */
56
+ function blockersOf({ installed, pluginId, to }) {
57
+ return installed.filter(revision => revision.pluginId === pluginId && revision.id !== to);
58
+ }
59
+ /** Verifies every blocker's publisher and the ledgered current revision's bytes, then moves them all, or none. `undefined`: this build does
60
+ * not ship the canonical package, so seeding will not try it and nothing needs to move. */
61
+ async function upgradeOne(input) {
62
+ const { port, pluginId, ids } = input;
63
+ if (await bundledSourceId({ port, pluginId }) !== ids.to)
64
+ return undefined;
65
+ for (const revision of input.blockers) {
66
+ const reason = await unverifiedReason({ port, ledger: input.ledger, revision, from: ids.from });
67
+ if (reason !== undefined)
68
+ return { status: "held", pluginId, to: ids.to, reason };
69
+ }
70
+ if (!input.blockers.some(revision => revision.archiveDigest === input.ledger.get(pluginId)))
71
+ return { status: "held", pluginId, to: ids.to, reason: input.ledgerMismatchReason };
72
+ const moved = [];
73
+ for (const revision of input.blockers) {
74
+ const savedAt = path.join(input.workspaceRoot, BUNDLED_ID_UPGRADE_BACKUP_DIRNAME, pluginId, revision.archiveDigest);
75
+ await moveFrozenTree({ filesystem: port.filesystem, from: revision.packageRoot, to: savedAt });
76
+ moved.push({ packageRoot: revision.packageRoot, savedAt });
77
+ }
78
+ return { status: "upgraded", pluginId, to: ids.to, moved };
79
+ }
80
+ /** The qualified id this build's bundled source declares for one local id, if any. */
81
+ async function bundledSourceId({ port, pluginId }) {
82
+ let manifest;
83
+ try {
84
+ manifest = JSON.parse(await port.readBundledSourceManifest({ pluginId }));
85
+ }
86
+ catch {
87
+ return undefined;
88
+ }
89
+ const id = manifest.extensions?.jini?.id;
90
+ return typeof id === "string" ? id : undefined;
91
+ }
92
+ /** Why an installed revision's publisher or the ledgered current revision's bytes prevent the upgrade. */
93
+ async function unverifiedReason({ port, ledger, revision, from }) {
94
+ if (revision.id !== from)
95
+ return `its installed copy is published as '${revision.id ?? "an unnamed publisher"}', not '${from}'`;
96
+ if (ledger.get(revision.pluginId) !== revision.archiveDigest)
97
+ return undefined;
98
+ const repacked = await port.packAgentPluginDirectory({ sourceDir: revision.packageRoot });
99
+ if (repacked.sha256 !== revision.archiveDigest)
100
+ return "its installed files were changed after install";
101
+ return undefined;
102
+ }
103
+ /** Puts back the revisions of every upgrade whose canonical package did not seed, so the site keeps
104
+ * the copy it had rather than no copy at all. `restored` is reported only once every put-back rename
105
+ * succeeded. A failed put-back leaves the saved copy where it is and reports `held`: the site is not
106
+ * repaired yet, and saying `restored` would hide a missing package.
107
+ * @complexity O(m) renames for m moved revisions. */
108
+ export async function restoreUnseededUpgrades(required, _optional = {}) {
109
+ const result = [];
110
+ for (const outcome of required.outcomes) {
111
+ if (outcome.status !== "upgraded" || required.seededIds.has(outcome.pluginId)) {
112
+ result.push(outcome);
113
+ continue;
114
+ }
115
+ let allPutBack = true;
116
+ for (const revision of outcome.moved) {
117
+ // One failed put-back must not stop the others; each kept saved copy stays for the next start.
118
+ await moveFrozenTree({ filesystem: required.filesystem, from: revision.savedAt, to: revision.packageRoot }).catch(() => { allPutBack = false; });
119
+ }
120
+ result.push(allPutBack ? { ...outcome, status: "restored" } : { status: "held", pluginId: outcome.pluginId, to: outcome.to, reason: RESTORE_PENDING_REASON });
121
+ }
122
+ return result;
123
+ }
124
+ const RESTORE_PENDING_REASON = "its earlier copy could not be put back yet; the saved copy is kept for the next start";
125
+ /**
126
+ * One lock ordering for the publisher-ID move, the seed and the put-back: the workspace migration
127
+ * lock is taken first and held across all three, so no migration or second boot can run between a
128
+ * move and its seed or restore. The seed receives the held `ownership` (its nested layout migration
129
+ * runs under it, never reacquiring) and the held ids (they never reach install). Per-plugin locks
130
+ * are only taken inside, under this one.
131
+ * @throws What the injected lock or seed throws; the lock is released either way, and moved copies
132
+ * are put back first when the seed itself throws.
133
+ * @complexity As {@link upgradeRenamedBundledPlugins} plus one seed and O(m) put-back renames.
134
+ */
135
+ export async function seedWithBundledIdUpgrade(required, _optional = {}) {
136
+ const { withWorkspaceLock, seed, ...upgradeInput } = required;
137
+ return withWorkspaceLock({ workspaceRoot: required.workspaceRoot, run: async ({ ownership }) => {
138
+ // Optional step: a listing fault moves nothing, and seeding then reports each conflict itself.
139
+ const upgrades = await upgradeRenamedBundledPlugins(upgradeInput).catch(() => []);
140
+ const heldPluginIds = new Map(upgrades.flatMap(outcome => outcome.status === "held" ? [[outcome.pluginId, outcome.reason]] : []));
141
+ const restore = (seededIds) => restoreUnseededUpgrades({ outcomes: upgrades, seededIds, filesystem: required.port.filesystem });
142
+ let seeded;
143
+ try {
144
+ seeded = await seed({ ownership, heldPluginIds });
145
+ }
146
+ catch (error) {
147
+ await restore(new Set());
148
+ throw error;
149
+ }
150
+ const seededIds = new Set(seeded.outcomes.flatMap(outcome => outcome.status === "seeded" ? [outcome.pluginId] : []));
151
+ return { seeded, idUpgrades: upgrades.length === 0 ? [] : await restore(seededIds) };
152
+ } });
153
+ }
154
+ /** Renames a frozen (0o555) package tree: a directory move needs write permission on the directory
155
+ * itself, so it is opened for the move and its original mode put back afterwards. */
156
+ async function moveFrozenTree({ filesystem, from, to }) {
157
+ const mode = (await filesystem.stat(from)).mode & 0o777;
158
+ await filesystem.mkdir(path.dirname(to), { recursive: true, mode: 0o700 });
159
+ await filesystem.chmod(from, mode | 0o700);
160
+ try {
161
+ await filesystem.rename(from, to);
162
+ }
163
+ catch (error) {
164
+ await filesystem.chmod(from, mode).catch(() => undefined);
165
+ throw error;
166
+ }
167
+ await filesystem.chmod(to, mode).catch(() => undefined);
168
+ }
169
+ //# sourceMappingURL=bundled-id-upgrade.js.map
@@ -0,0 +1,39 @@
1
+ import type { AgentPluginIdentityReadOptions } from "../core/identity-namespace.js";
2
+ /** Chat customization reuses Jini's package fork and the admin upload preview/install owner. */
3
+ import { type ToolExecutionContext } from "@jini-ai/core";
4
+ import type { AgentPluginLayout } from "@jini-ai/core/contracts/headless/plugin-host";
5
+ /** The install tool's deps this fork reads: the site layout and the bound workspace. */
6
+ export interface CustomizeAgentPluginDeps {
7
+ readonly agentPluginLayout: Pick<AgentPluginLayout, "forWorkspace">;
8
+ readonly workspaceId: string;
9
+ }
10
+ /** The lifecycle owner's calls this fork uses; the host passes its bound lifecycle functions. */
11
+ export interface CustomizeAgentPluginLifecycle<P extends {
12
+ readonly pluginId: string;
13
+ readonly packageRoot: string;
14
+ }, B> {
15
+ readonly listInstalledPlugins: (required: {
16
+ readonly workspaceRoot: string;
17
+ }) => Promise<readonly P[]>;
18
+ readonly readBundledAgentPluginDigests: (required: {
19
+ readonly workspaceRoot: string;
20
+ }) => Promise<B>;
21
+ readonly preferBundledAgentPluginDigests: (installed: readonly P[], bundled: B) => readonly P[];
22
+ readonly maxAgentPluginInstallArchiveBytes: () => number;
23
+ }
24
+ /**
25
+ * Prepare a fork after the install tool's authorization; publication stays with that tool's owner.
26
+ * @param required Host deps, the actual assistant tool context and the host's lifecycle calls.
27
+ * @returns ZIP bytes for the existing install flow. Never writes an installed package.
28
+ * @throws {ToolInputError} Unknown/ambiguous source or invalid edit.
29
+ * @complexity O(p + e log e + b) for p installed packages, e files and bounded bytes b; no network.
30
+ */
31
+ export declare function prepareCustomizedAgentPluginArchive<P extends {
32
+ readonly pluginId: string;
33
+ readonly packageRoot: string;
34
+ }, B>({ deps, ctx, lifecycle }: {
35
+ deps: CustomizeAgentPluginDeps;
36
+ ctx: ToolExecutionContext;
37
+ lifecycle: CustomizeAgentPluginLifecycle<P, B>;
38
+ }, options?: Pick<AgentPluginIdentityReadOptions, "legacyIdentity">): Promise<Uint8Array>;
39
+ //# sourceMappingURL=customize-tool.d.ts.map
@@ -0,0 +1,31 @@
1
+ /** Chat customization reuses Jini's package fork and the admin upload preview/install owner. */
2
+ import { requireInputRecord, requireString, ToolInputError } from "@jini-ai/core";
3
+ import { FolderZipError } from "../core/folder-zip-error.js";
4
+ import { zipCustomizedAgentPluginFolder } from "@jini-ai/agent-plugins/folder-zip/node";
5
+ /**
6
+ * Prepare a fork after the install tool's authorization; publication stays with that tool's owner.
7
+ * @param required Host deps, the actual assistant tool context and the host's lifecycle calls.
8
+ * @returns ZIP bytes for the existing install flow. Never writes an installed package.
9
+ * @throws {ToolInputError} Unknown/ambiguous source or invalid edit.
10
+ * @complexity O(p + e log e + b) for p installed packages, e files and bounded bytes b; no network.
11
+ */
12
+ export async function prepareCustomizedAgentPluginArchive({ deps, ctx, lifecycle }, options = {}) {
13
+ const input = requireInputRecord({ input: ctx.input });
14
+ const pluginId = requireString({ input, key: "pluginId" });
15
+ const workspaceRoot = deps.agentPluginLayout.forWorkspace({ workspaceId: deps.workspaceId }).root;
16
+ const installed = lifecycle.preferBundledAgentPluginDigests(await lifecycle.listInstalledPlugins({ workspaceRoot }), await lifecycle.readBundledAgentPluginDigests({ workspaceRoot }));
17
+ const sources = installed.filter(plugin => plugin.pluginId === pluginId);
18
+ const source = sources[0];
19
+ if (sources.length !== 1 || source === undefined)
20
+ throw new ToolInputError({ message: `Source '${pluginId}' must identify exactly one installed Agent Plugin.` });
21
+ try {
22
+ return await zipCustomizedAgentPluginFolder({ path: source.packageRoot, maxBytes: lifecycle.maxAgentPluginInstallArchiveBytes(), name: requireString({ input, key: "newId" }), identityNamespace: "jini",
23
+ edit: { path: requireString({ input, key: "path" }), oldString: requireString({ input, key: "oldString" }), newString: requireString({ input, key: "newString" }, { allowEmpty: true }) } }, options);
24
+ }
25
+ catch (error) {
26
+ if (error instanceof FolderZipError)
27
+ throw new ToolInputError({ message: error.message });
28
+ throw error;
29
+ }
30
+ }
31
+ //# sourceMappingURL=customize-tool.js.map
@@ -0,0 +1,28 @@
1
+ import type { AgentPluginActivations, AgentPluginActivationVerdict, SetAgentPluginActivationRequired, SetAgentPluginActivationOptional } from "../lifecycle/index.js";
2
+ /** @file Preserve explicit activation decisions across a plugin rename (a predecessor plugin was retired in
3
+ * favour of its successor plugin; the host injects both ids). */
4
+ /** The activation calls this step makes, from the boot's lifecycle owner. */
5
+ export interface DeploySplitActivationPort {
6
+ readonly assertAgentPluginActivationsWritable: (input: {
7
+ readonly workspaceRoot: string;
8
+ }) => Promise<void>;
9
+ readonly resolveAgentPluginActivation: (input: {
10
+ readonly workspaceRoot: string;
11
+ readonly pluginId: string;
12
+ }) => Promise<AgentPluginActivationVerdict>;
13
+ readonly readAgentPluginActivations: (input: {
14
+ readonly workspaceRoot: string;
15
+ }) => Promise<AgentPluginActivations>;
16
+ readonly setAgentPluginActivation: (required: SetAgentPluginActivationRequired, optional?: SetAgentPluginActivationOptional) => Promise<unknown>;
17
+ }
18
+ /** Rename precedes split seeding: an existing predecessor-plugin decision wins over old inheritance.
19
+ * Explicit successor decisions win, even when they disagree. Corrupt records fail closed.
20
+ * @complexity O(1), two strict verdicts and at most one activation write. */
21
+ export declare function carryPluginRenameActivation(required: {
22
+ readonly workspaceRoot: string;
23
+ readonly activations: DeploySplitActivationPort;
24
+ readonly fromPluginId: string;
25
+ readonly toPluginId: string;
26
+ readonly actor: string;
27
+ }, _optional?: Record<string, never>): Promise<void>;
28
+ //# sourceMappingURL=deploy-split-activation.d.ts.map
@@ -0,0 +1,21 @@
1
+ /** Rename precedes split seeding: an existing predecessor-plugin decision wins over old inheritance.
2
+ * Explicit successor decisions win, even when they disagree. Corrupt records fail closed.
3
+ * @complexity O(1), two strict verdicts and at most one activation write. */
4
+ export async function carryPluginRenameActivation(required, _optional = {}) {
5
+ const { workspaceRoot, activations, fromPluginId, toPluginId, actor } = required;
6
+ await activations.assertAgentPluginActivationsWritable({ workspaceRoot });
7
+ for (const pluginId of [fromPluginId, toPluginId]) {
8
+ const verdict = await activations.resolveAgentPluginActivation({ workspaceRoot, pluginId });
9
+ if (verdict.verdict === "undetermined")
10
+ throw new Error(`Cannot carry ${pluginId} activation: ${verdict.reason}`);
11
+ }
12
+ const { plugins } = await activations.readAgentPluginActivations({ workspaceRoot });
13
+ const previous = plugins[fromPluginId];
14
+ const successor = plugins[toPluginId];
15
+ if (successor !== undefined && successor.updatedBy !== "system:seed")
16
+ return;
17
+ if (previous === undefined || previous.updatedBy === "system:seed")
18
+ return;
19
+ await activations.setAgentPluginActivation({ workspaceRoot, pluginId: toPluginId, enabled: previous.enabled, actor }, { origin: "bundled" });
20
+ }
21
+ //# sourceMappingURL=deploy-split-activation.js.map
@@ -0,0 +1,37 @@
1
+ /** Editor diagnostics; CMS deliberately exposes only public fallback. */
2
+ import { ToolInputError } from "@jini-ai/core";
3
+ import type { PluginExportPackage } from "./source.js";
4
+ import type { AgentPluginExport } from "@jini-ai/core/contracts/site/agent-plugins-manifest";
5
+ import type { PluginEmbedDiagnostic } from "@jini-ai/core/contracts/site/page-html-store";
6
+ export interface SelectedPluginExport {
7
+ readonly owner: PluginExportPackage;
8
+ readonly component: string;
9
+ readonly definition: AgentPluginExport;
10
+ }
11
+ export type PluginExportSelection = {
12
+ readonly selected: SelectedPluginExport;
13
+ } | {
14
+ readonly diagnostic: PluginEmbedDiagnostic;
15
+ };
16
+ /** A typed, safe input error works in both assistant tools and the authenticated HTML route. */
17
+ export declare class PluginEmbedValidationError extends ToolInputError {
18
+ readonly code = "PLUGIN_EMBED_INVALID_PROPS";
19
+ constructor(required: {
20
+ message: string;
21
+ }, _options?: {});
22
+ }
23
+ /** Canonical names and declared aliases share one ambiguity rule; never guess a rename.
24
+ * Disabled trusted packages still reserve their canonical identity. O(p + a) catalog and aliases.
25
+ */
26
+ export declare function selectPluginExport(required: {
27
+ packages: readonly PluginExportPackage[];
28
+ config: Readonly<Record<string, unknown>>;
29
+ }, _options?: {}): PluginExportSelection;
30
+ /** Schema ownership stays in Jini; version messages stay in the authenticated host. O(props).
31
+ * No prop values, file paths or underlying I/O errors appear in these messages.
32
+ */
33
+ export declare function checkPluginExportConfig(required: {
34
+ selected: SelectedPluginExport;
35
+ config: Readonly<Record<string, unknown>>;
36
+ }, _options?: {}): PluginEmbedDiagnostic | undefined;
37
+ //# sourceMappingURL=diagnostics.d.ts.map
@@ -0,0 +1,55 @@
1
+ /** Editor diagnostics; CMS deliberately exposes only public fallback. */
2
+ import { ToolInputError } from "@jini-ai/core";
3
+ import { validateAgentPluginExportProps } from "../../core/export-props.js";
4
+ /** A typed, safe input error works in both assistant tools and the authenticated HTML route. */
5
+ export class PluginEmbedValidationError extends ToolInputError {
6
+ code = "PLUGIN_EMBED_INVALID_PROPS";
7
+ constructor(required, _options = {}) {
8
+ super({ message: required.message });
9
+ this.name = "PluginEmbedValidationError";
10
+ }
11
+ }
12
+ /** Canonical names and declared aliases share one ambiguity rule; never guess a rename.
13
+ * Disabled trusted packages still reserve their canonical identity. O(p + a) catalog and aliases.
14
+ */
15
+ export function selectPluginExport(required, _options = {}) {
16
+ const { packages, config } = required;
17
+ const owners = packages.filter(item => item.id === config.plugin || item.renamedFrom?.includes(config.plugin));
18
+ const owner = owners[0];
19
+ if (owners.length !== 1 || owner === undefined)
20
+ return { diagnostic: { code: "PLUGIN_UNAVAILABLE", message: owners.length > 1 ? "Plugin identity is ambiguous; visitors see your fallback." : "Plugin is unknown or unavailable; visitors see your fallback." } };
21
+ if (!owner.enabled)
22
+ return { diagnostic: { code: "PLUGIN_DISABLED", message: "Plugin is off; visitors see your fallback." } };
23
+ const entries = Object.entries(owner.exports).filter(([name, entry]) => name === config.component || entry.aliases?.includes(config.component));
24
+ const entry = entries[0];
25
+ if (entries.length !== 1 || entry === undefined)
26
+ return { diagnostic: { code: "COMPONENT_UNAVAILABLE", message: "Plugin component is unknown or ambiguous; visitors see your fallback." } };
27
+ const [component, definition] = entry;
28
+ return { selected: { owner, component, definition } };
29
+ }
30
+ /** Schema ownership stays in Jini; version messages stay in the authenticated host. O(props).
31
+ * No prop values, file paths or underlying I/O errors appear in these messages.
32
+ */
33
+ export function checkPluginExportConfig(required, _options = {}) {
34
+ const { definition } = required.selected;
35
+ // Version first: a retired or newer embed was written against another contract's props, so the
36
+ // current schema cannot judge them; it gets the savable version warning, not a blocking props error.
37
+ const versionDiagnostic = checkVersion({ definition, version: required.config.version === undefined ? 1 : required.config.version });
38
+ if (versionDiagnostic)
39
+ return versionDiagnostic;
40
+ const propsReason = validateAgentPluginExportProps({ definition, props: required.config.props === undefined ? {} : required.config.props });
41
+ if (propsReason)
42
+ return { code: "PLUGIN_EMBED_INVALID_PROPS", message: `Plugin component props are invalid: ${propsReason}. Nothing was written.` };
43
+ return undefined;
44
+ }
45
+ /** Version compatibility is independent of props validity. No side effects. O(1). */
46
+ function checkVersion({ definition, version }, _options = {}) {
47
+ if (typeof version !== "number" || !Number.isSafeInteger(version) || version < 1)
48
+ return { code: "PLUGIN_VERSION_INVALID", message: "Plugin contract version must be a positive integer; visitors see your fallback." };
49
+ if (version > definition.version)
50
+ return { code: "PLUGIN_VERSION_NEWER", message: `Page needs plugin v${version}; visitors see your fallback.` };
51
+ if (version < (definition.minVersion ?? 1))
52
+ return { code: "PLUGIN_VERSION_RETIRED", message: `Contract v${version} retired; visitors see your fallback.` };
53
+ return undefined;
54
+ }
55
+ //# sourceMappingURL=diagnostics.js.map
@@ -0,0 +1,54 @@
1
+ import type { PluginExportsPort } from "@jini-ai/core/contracts/site/widgets-html";
2
+ import type { PluginExportCatalogPort } from '@jini-ai/core/contracts/headless/plugin-export-catalog';
3
+ import type { LoginProvider } from "@jini-ai/core/contracts/site/user-management-server";
4
+ import type { PluginEmbedDiagnostic } from "@jini-ai/core/contracts/site/page-html-store";
5
+ import { type PluginExportSource } from "./source.js";
6
+ import type { DeclaredPageHosts } from "@jini-ai/core/contracts/server/security-headers";
7
+ export interface PluginExportRenderSession extends PluginExportsPort {
8
+ headHtml(required: Record<string, never>, options?: Record<string, never>): string;
9
+ /** External hosts of the exports this page actually shows, for its content-security policy. */
10
+ declaredHosts(required: Record<string, never>, options?: Record<string, never>): DeclaredPageHosts;
11
+ }
12
+ export interface PluginExportRuntime extends PluginExportCatalogPort {
13
+ forRender(required: {
14
+ mode: "live" | "static";
15
+ }, options?: Record<string, never>): PluginExportRenderSession;
16
+ validateHtml(required: {
17
+ workspaceId: string;
18
+ html: string;
19
+ }, options?: Record<string, never>): Promise<readonly PluginEmbedDiagnostic[]>;
20
+ /** Hosts of every enabled export: a static host's header file covers the whole site at once. */
21
+ declaredHosts(required: {
22
+ workspaceId: string;
23
+ }, options?: Record<string, never>): Promise<DeclaredPageHosts>;
24
+ }
25
+ interface RuntimeDeps {
26
+ readonly workspaceId: string;
27
+ readonly source: PluginExportSource;
28
+ readonly filesPrefix: string;
29
+ readonly memberLoginStart: (input: {
30
+ workspaceId: string;
31
+ providerId: string;
32
+ }) => string;
33
+ readonly markersOfType: (input: {
34
+ html: string;
35
+ type: string;
36
+ }) => readonly {
37
+ config: Readonly<Record<string, unknown>>;
38
+ }[];
39
+ readonly embedMarkerSnippetFromConfig: (input: {
40
+ config: Readonly<Record<string, unknown>>;
41
+ }) => string;
42
+ readonly listProviders: (input: {
43
+ workspaceId: string;
44
+ }) => Promise<readonly LoginProvider[]>;
45
+ /** True when the site turned its consent banner off, so declared resources load directly. */
46
+ readonly embedConsentOff?: () => boolean;
47
+ }
48
+ /** Bind to one site. Request-local memoization shares catalog/readiness across occurrences; a new
49
+ * request observes plugin toggles. Static full/link-only exports use the same template.
50
+ * @complexity O(1) construction; work is deferred to the bounded CMS occurrence pass.
51
+ */
52
+ export declare function createPluginExportRuntime(required: RuntimeDeps, _options?: {}): PluginExportRuntime;
53
+ export {};
54
+ //# sourceMappingURL=runtime.d.ts.map
@@ -0,0 +1,196 @@
1
+ /** Admission and member-login host data for the HTML plugin-export port. */
2
+ import { escapeHtml } from "@jini-ai/core/text";
3
+ import { checkPluginExportConfig, selectPluginExport, PluginEmbedValidationError } from "./diagnostics.js";
4
+ import { pluginExportFileUrl } from "./source.js";
5
+ const newHostSets = () => ({ script: new Set(), frame: new Set(), connect: new Set() });
6
+ const hostLists = (sets) => ({ script: [...sets.script], frame: [...sets.frame], connect: [...sets.connect] });
7
+ function addHosts(required, _options = {}) {
8
+ const declared = required.definition.externalHosts ?? {};
9
+ for (const kind of ["script", "frame", "connect"])
10
+ for (const origin of declared[kind] ?? [])
11
+ required.sets[kind].add(origin);
12
+ }
13
+ /** Each host link must belong to this plugin's ready provider, not merely share a provider id.
14
+ * @complexity O(l*p) declared links and ready providers; provider admission is loaded once per session.
15
+ */
16
+ async function publicHost(required, _options = {}) {
17
+ const { owner, component, definition } = required.selected;
18
+ const host = {};
19
+ const links = Object.entries(definition.hostLinks ?? {});
20
+ const providers = links.length ? await required.providers : [];
21
+ for (const [slot, capability] of links) {
22
+ if (!capability.startsWith("member-login:"))
23
+ return undefined;
24
+ const providerId = capability.slice("member-login:".length);
25
+ if (!providers.some(provider => provider.id === providerId && provider.pluginId === owner.plugin.pluginId))
26
+ return undefined;
27
+ host[slot] = required.deps.memberLoginStart({ workspaceId: required.deps.workspaceId, providerId });
28
+ }
29
+ host.assets = Object.fromEntries(Object.entries(definition.assets ?? {}).map(([name, filename]) => [name,
30
+ pluginExportFileUrl({ prefix: required.deps.filesPrefix, pluginId: owner.plugin.pluginId, component, filename })]));
31
+ return host;
32
+ }
33
+ /** Link only declared, admitted resources. A static fallback still ships its themeable CSS/artwork.
34
+ * @complexity O(a) assets; Map keys deduplicate across repeated occurrences without global state.
35
+ */
36
+ function collectHead(required, _options = {}) {
37
+ const { owner, component, definition } = required.selected;
38
+ const urlFor = ({ filename }, _optional = {}) => escapeHtml({ text: pluginExportFileUrl({ prefix: required.deps.filesPrefix, pluginId: owner.plugin.pluginId, component, filename }) });
39
+ if (definition.styles)
40
+ required.head.set(`${owner.id}:${definition.styles}`, `<link rel="stylesheet" href="${urlFor({ filename: definition.styles })}">`);
41
+ if (required.mode !== "static")
42
+ return;
43
+ for (const filename of Object.values(definition.assets ?? {})) {
44
+ const url = urlFor({ filename });
45
+ required.head.set(url, `<link rel="preload" as="image" href="${url}">`);
46
+ }
47
+ }
48
+ /** Queue declared scripts in manifest order. A consent-gated one stays inert until the consent client
49
+ * activates it; a static copy runs scripts only for a `full` export.
50
+ * @complexity O(s) scripts; Map keys deduplicate across repeated occurrences.
51
+ */
52
+ function collectScripts(required, _options = {}) {
53
+ const { owner, component, definition } = required.selected;
54
+ if (required.mode === "static" && definition.staticExport !== "full")
55
+ return;
56
+ const held = definition.consent !== "necessary" && !required.consentOff;
57
+ for (const script of definition.scripts ?? []) {
58
+ const url = escapeHtml({ text: script.startsWith("https://") ? script : pluginExportFileUrl({ prefix: required.deps.filesPrefix, pluginId: owner.plugin.pluginId, component, filename: script }) });
59
+ required.head.set(`script:${url}`, held
60
+ ? `<script type="text/plain" data-consent-category="${definition.consent}" data-src="${url}"></script>`
61
+ : `<script src="${url}" defer></script>`);
62
+ }
63
+ }
64
+ /** Resolve one occurrence; CMS alone fills/validates HTML and stamps its preserved wrapper.
65
+ * @complexity O(p + e + props) catalog selection and schema check, plus one contained template read.
66
+ */
67
+ async function resolveExport(required, _options = {}) {
68
+ const selection = selectPluginExport({ packages: await required.packages, config: required.config });
69
+ if (!("selected" in selection))
70
+ return undefined;
71
+ const { selected } = selection;
72
+ if (checkPluginExportConfig({ selected, config: required.config }))
73
+ return undefined;
74
+ collectHead({ selected, mode: required.mode, head: required.head, deps: required.deps });
75
+ if (required.mode === "static" && selected.definition.staticExport === "fallback-only")
76
+ return undefined;
77
+ const host = await publicHost({ selected, deps: required.deps, providers: required.providers });
78
+ if (!host)
79
+ return undefined;
80
+ const consentOff = required.deps.embedConsentOff?.() === true;
81
+ collectScripts({ selected, mode: required.mode, head: required.head, consentOff, deps: required.deps });
82
+ addHosts({ sets: required.hosts, definition: selected.definition });
83
+ return exportTemplate({ selected, config: required.config, deps: required.deps, host, consentOff });
84
+ }
85
+ /** The CMS-side template for one resolved occurrence: its contract fields, template file and props.
86
+ * @complexity O(1) plus one contained template read.
87
+ */
88
+ async function exportTemplate(required, _options = {}) {
89
+ const { selected, consentOff, host } = required;
90
+ return { plugin: selected.owner.id, component: selected.component, version: selected.definition.version,
91
+ ...(selected.definition.minVersion === undefined ? {} : { minVersion: selected.definition.minVersion }), consent: selected.definition.consent, consentOff,
92
+ frameHosts: selected.definition.externalHosts?.frame ?? [], scriptData: (selected.definition.scripts?.length ?? 0) > 0,
93
+ template: await required.deps.source.readFile({ plugin: selected.owner.plugin, filename: selected.definition.template }),
94
+ props: (required.config.props === undefined ? {} : required.config.props), host };
95
+ }
96
+ /** Validate known enabled contracts before the single HTML writer mutates anything. Unknown,
97
+ * disabled and unsupported contracts remain savable with safe editor warnings. O(markers + schemas).
98
+ */
99
+ async function validateHtml(required, _options = {}) {
100
+ if (required.input.workspaceId !== required.deps.workspaceId)
101
+ throw new PluginEmbedValidationError({ message: "Plugin embed workspace does not match this site." });
102
+ const markers = required.deps.markersOfType({ html: required.input.html, type: "plugin" });
103
+ if (!markers.length)
104
+ return [];
105
+ const packages = await required.deps.source.list({ workspaceId: required.input.workspaceId }).catch(() => []);
106
+ const providers = required.deps.listProviders({ workspaceId: required.input.workspaceId }).catch(() => []);
107
+ const warnings = [];
108
+ for (const marker of markers) {
109
+ const diagnostic = await editorDiagnostic({ packages, config: marker.config, deps: required.deps, providers });
110
+ if (diagnostic?.code === "PLUGIN_EMBED_INVALID_PROPS")
111
+ throw new PluginEmbedValidationError({ message: diagnostic.message });
112
+ if (diagnostic)
113
+ warnings.push(diagnostic);
114
+ }
115
+ return warnings;
116
+ }
117
+ /** The same safe refusal reasons drive editor warnings; provider readiness never opens secrets. */
118
+ async function editorDiagnostic(required, _options = {}) {
119
+ const selection = selectPluginExport(required);
120
+ if ("diagnostic" in selection)
121
+ return selection.diagnostic;
122
+ const diagnostic = checkPluginExportConfig({ selected: selection.selected, config: required.config });
123
+ if (diagnostic)
124
+ return diagnostic;
125
+ const host = await publicHost({ selected: selection.selected, deps: required.deps, providers: required.providers });
126
+ return host ? undefined : { code: "PLUGIN_HOST_UNAVAILABLE", message: "Plugin sign-in is not configured or unavailable; visitors see your fallback." };
127
+ }
128
+ /** Catalog rows expose contracts and snippets, never templates, secrets or local file paths.
129
+ * O(exports * providers), no extra file reads per row beyond the shared catalog load.
130
+ */
131
+ async function catalogRows(required, _options = {}) {
132
+ const rows = new Map();
133
+ const providers = required.deps.listProviders({ workspaceId: required.deps.workspaceId }).catch(() => []);
134
+ for (const owner of required.packages) {
135
+ const exports = [];
136
+ for (const [component, definition] of Object.entries(owner.exports)) {
137
+ const config = { type: "plugin", plugin: owner.id, component, version: definition.version, props: {} };
138
+ const selection = selectPluginExport({ packages: required.packages, config });
139
+ const selected = { owner, component, definition };
140
+ const availability = await catalogAvailability({ selection, selected, config, providers, deps: required.deps });
141
+ exports.push({ plugin: owner.id, ...(owner.displayName ? { displayName: owner.displayName } : {}), component, version: definition.version, minVersion: definition.minVersion ?? 1, props: definition.props,
142
+ consent: definition.consent, availability, snippet: availability === "ready" ? required.deps.embedMarkerSnippetFromConfig({ config }) : null });
143
+ }
144
+ rows.set(owner.plugin.pluginId, exports);
145
+ }
146
+ return rows;
147
+ }
148
+ /** Distinguish props that the author must fill from host readiness; fixed public diagnostics. */
149
+ async function catalogAvailability(required, _options = {}) {
150
+ if ("diagnostic" in required.selection)
151
+ return required.selection.diagnostic.code;
152
+ if (!await publicHost(required))
153
+ return "host-unavailable";
154
+ return checkPluginExportConfig({ selected: required.selected, config: required.config }) ? "props-required" : "ready";
155
+ }
156
+ /** Bind to one site. Request-local memoization shares catalog/readiness across occurrences; a new
157
+ * request observes plugin toggles. Static full/link-only exports use the same template.
158
+ * @complexity O(1) construction; work is deferred to the bounded CMS occurrence pass.
159
+ */
160
+ export function createPluginExportRuntime(required, _options = {}) {
161
+ return {
162
+ forRender: ({ mode }, _options = {}) => {
163
+ let packages;
164
+ let providers;
165
+ const head = new Map();
166
+ const hosts = newHostSets();
167
+ return {
168
+ resolve: async ({ config, workspaceId }, _options = {}) => {
169
+ if (workspaceId !== required.workspaceId)
170
+ return undefined;
171
+ packages ??= required.source.list({ workspaceId });
172
+ // Readiness failures are a public fallback, never an unhandled rejected lazy promise.
173
+ providers ??= required.listProviders({ workspaceId }).catch(() => []);
174
+ return resolveExport({ config, deps: required, packages, providers, mode, head, hosts });
175
+ },
176
+ headHtml: (_input, _options = {}) => [...head.values()].join("\n"),
177
+ declaredHosts: (_input, _options = {}) => hostLists(hosts),
178
+ };
179
+ },
180
+ validateHtml: (input, _options = {}) => validateHtml({ input, deps: required }),
181
+ declaredHosts: async ({ workspaceId }, _options = {}) => {
182
+ const sets = newHostSets();
183
+ if (workspaceId !== required.workspaceId)
184
+ return hostLists(sets);
185
+ for (const owner of await required.source.list({ workspaceId })) {
186
+ if (owner.enabled)
187
+ for (const definition of Object.values(owner.exports))
188
+ addHosts({ sets, definition });
189
+ }
190
+ return hostLists(sets);
191
+ },
192
+ catalog: async ({ workspaceId }, _options = {}) => workspaceId === required.workspaceId
193
+ ? catalogRows({ packages: await required.source.list({ workspaceId }), deps: required }) : new Map(),
194
+ };
195
+ }
196
+ //# sourceMappingURL=runtime.js.map