@jini-ai/agent-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 (234) hide show
  1. package/CHANGELOG.md +7 -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/credential-save-tool.js +2 -3
  24. package/dist/connect/grant-signed-in-defaults.js +1 -1
  25. package/dist/connect/host-deps.d.ts +32 -0
  26. package/dist/connect/host-deps.js +35 -0
  27. package/dist/connect/import-access-token.js +1 -1
  28. package/dist/connect/index.d.ts +7 -2
  29. package/dist/connect/index.js +5 -2
  30. package/dist/connect/installed-plugin.d.ts +28 -0
  31. package/dist/connect/installed-plugin.js +19 -0
  32. package/dist/connect/new-site-agent-plugin-tokens.d.ts +88 -0
  33. package/dist/connect/new-site-agent-plugin-tokens.js +107 -0
  34. package/dist/connect/plugin-host/index.d.ts +1 -2
  35. package/dist/connect/plugin-host/index.js +18 -9
  36. package/dist/connect/token-sign-in.d.ts +1 -14
  37. package/dist/connect/token-sign-in.js +4 -23
  38. package/dist/core/export-props.d.ts +10 -0
  39. package/dist/core/export-props.js +31 -0
  40. package/dist/core/folder-zip-error.d.ts +5 -0
  41. package/dist/core/folder-zip-error.js +8 -0
  42. package/dist/core/host-incompatible-error.d.ts +8 -0
  43. package/dist/core/host-incompatible-error.js +9 -0
  44. package/dist/core/identity-namespace.d.ts +27 -16
  45. package/dist/core/identity-namespace.js +25 -22
  46. package/dist/core/plugin-display-name.d.ts +7 -0
  47. package/dist/core/plugin-display-name.js +11 -0
  48. package/dist/core/provider-plugin-link.d.ts +7 -0
  49. package/dist/core/provider-plugin-link.js +5 -0
  50. package/dist/{connect → core}/token-map.d.ts +11 -1
  51. package/dist/{connect → core}/token-map.js +15 -0
  52. package/dist/core/token-sign-in-list.d.ts +18 -0
  53. package/dist/core/token-sign-in-list.js +23 -0
  54. package/dist/core/update-error.d.ts +8 -0
  55. package/dist/core/update-error.js +9 -0
  56. package/dist/{lifecycle → core}/update-plan.d.ts +1 -1
  57. package/dist/ffmpeg-transcode/adapter.d.ts +74 -0
  58. package/dist/ffmpeg-transcode/adapter.js +155 -0
  59. package/dist/folder-zip-node.d.ts +2 -1
  60. package/dist/folder-zip-node.js +6 -5
  61. package/dist/folder-zip.d.ts +0 -4
  62. package/dist/folder-zip.js +1 -7
  63. package/dist/index.d.ts +3 -1
  64. package/dist/lifecycle/activation.d.ts +39 -3
  65. package/dist/lifecycle/activation.js +467 -418
  66. package/dist/lifecycle/automatic-use-offer.d.ts +62 -0
  67. package/dist/lifecycle/automatic-use-offer.js +52 -0
  68. package/dist/lifecycle/automatic-use.d.ts +33 -1
  69. package/dist/lifecycle/automatic-use.js +159 -38
  70. package/dist/lifecycle/bundled-source-archive.d.ts +1 -1
  71. package/dist/lifecycle/capability-projection.d.ts +0 -1
  72. package/dist/lifecycle/capability-projection.js +92 -23
  73. package/dist/lifecycle/compatibility-metadata.d.ts +1 -0
  74. package/dist/lifecycle/compatibility-metadata.js +6 -1
  75. package/dist/lifecycle/compatibility.d.ts +1 -8
  76. package/dist/lifecycle/compatibility.js +1 -8
  77. package/dist/lifecycle/credential-card-metadata.d.ts +2 -2
  78. package/dist/lifecycle/exports.d.ts +2 -45
  79. package/dist/lifecycle/exports.js +1 -30
  80. package/dist/lifecycle/host-tools/identity.d.ts +5 -4
  81. package/dist/lifecycle/host-tools/identity.js +5 -5
  82. package/dist/lifecycle/host-tools/ports.d.ts +10 -1
  83. package/dist/lifecycle/host-tools/search-tool.js +18 -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 +17 -3
  106. package/dist/lifecycle/search-projection.js +8 -8
  107. package/dist/lifecycle/search.d.ts +1 -0
  108. package/dist/lifecycle/search.js +2 -2
  109. package/dist/lifecycle/seed-bundled.d.ts +86 -1
  110. package/dist/lifecycle/seed-bundled.js +48 -84
  111. package/dist/lifecycle/set-enabled.d.ts +1 -13
  112. package/dist/lifecycle/set-enabled.js +11 -7
  113. package/dist/lifecycle/trusted-plugin-files.d.ts +1 -1
  114. package/dist/lifecycle/trusted-plugin-files.js +33 -30
  115. package/dist/lifecycle/types.d.ts +13 -34
  116. package/dist/lifecycle/uninstall.d.ts +1 -33
  117. package/dist/lifecycle/update-store.d.ts +0 -7
  118. package/dist/lifecycle/update-store.js +1 -8
  119. package/dist/lifecycle/update.d.ts +1 -1
  120. package/dist/lifecycle/update.js +60 -10
  121. package/dist/lifecycle/yauzl-archive-reader.d.ts +7 -2
  122. package/dist/lifecycle/yauzl-archive-reader.js +11 -6
  123. package/dist/manifest.d.ts +4 -8
  124. package/dist/react/AgentPluginDetailsModal.d.ts +187 -0
  125. package/dist/react/AgentPluginDetailsModal.js +29 -0
  126. package/dist/react/agent-plugin-install-port.d.ts +24 -0
  127. package/dist/react/agent-plugin-install-port.js +15 -0
  128. package/dist/react/installed-skills-composer-source.d.ts +60 -0
  129. package/dist/react/installed-skills-composer-source.js +111 -0
  130. package/dist/react/use-agent-plugins.hooks.d.ts +211 -0
  131. package/dist/react/use-agent-plugins.hooks.js +128 -0
  132. package/dist/site/activation-effects.d.ts +17 -0
  133. package/dist/site/activation-effects.js +31 -0
  134. package/dist/site/admin-surfaces/capabilities.d.ts +29 -0
  135. package/dist/site/admin-surfaces/capabilities.js +30 -0
  136. package/dist/site/admin-surfaces/delivery-bindings.d.ts +81 -0
  137. package/dist/site/admin-surfaces/delivery-bindings.js +161 -0
  138. package/dist/site/admin-surfaces/forms.d.ts +28 -0
  139. package/dist/site/admin-surfaces/forms.js +29 -0
  140. package/dist/site/admin-surfaces/handlers.d.ts +61 -0
  141. package/dist/site/admin-surfaces/handlers.js +35 -0
  142. package/dist/site/admin-surfaces/public-config.d.ts +12 -0
  143. package/dist/site/admin-surfaces/public-config.js +28 -0
  144. package/dist/site/analytics-provider-registry.d.ts +87 -0
  145. package/dist/site/analytics-provider-registry.js +87 -0
  146. package/dist/site/archive-reader-abi.d.ts +35 -0
  147. package/dist/site/archive-reader-abi.js +25 -0
  148. package/dist/site/auth-schemes.d.ts +110 -0
  149. package/dist/site/auth-schemes.js +119 -0
  150. package/dist/site/automatic-agent-plugins.d.ts +200 -0
  151. package/dist/site/automatic-agent-plugins.js +277 -0
  152. package/dist/site/bundled-contribution-sources.d.ts +24 -0
  153. package/dist/site/bundled-contribution-sources.js +17 -0
  154. package/dist/site/bundled-id-upgrade.d.ts +115 -0
  155. package/dist/site/bundled-id-upgrade.js +169 -0
  156. package/dist/site/customize-tool.d.ts +39 -0
  157. package/dist/site/customize-tool.js +31 -0
  158. package/dist/site/deploy-split-activation.d.ts +28 -0
  159. package/dist/site/deploy-split-activation.js +21 -0
  160. package/dist/site/exports/diagnostics.d.ts +37 -0
  161. package/dist/site/exports/diagnostics.js +55 -0
  162. package/dist/site/exports/runtime.d.ts +54 -0
  163. package/dist/site/exports/runtime.js +196 -0
  164. package/dist/site/exports/source.d.ts +42 -0
  165. package/dist/site/exports/source.js +58 -0
  166. package/dist/site/host-plugin-guidance.d.ts +137 -0
  167. package/dist/site/host-plugin-guidance.js +223 -0
  168. package/dist/site/host-signals.d.ts +78 -0
  169. package/dist/site/host-signals.js +83 -0
  170. package/dist/site/install-tool.d.ts +69 -0
  171. package/dist/site/install-tool.js +192 -0
  172. package/dist/site/install-upload.d.ts +175 -0
  173. package/dist/site/install-upload.js +324 -0
  174. package/dist/site/memory-i18n.d.ts +5 -0
  175. package/dist/site/memory-i18n.js +176 -0
  176. package/dist/site/memory.d.ts +80 -0
  177. package/dist/site/memory.js +83 -0
  178. package/dist/site/plugin-memory.d.ts +80 -0
  179. package/dist/site/plugin-memory.js +86 -0
  180. package/dist/site/provider-plugin-link.d.ts +112 -0
  181. package/dist/site/provider-plugin-link.js +100 -0
  182. package/dist/site/retired-plugin-tool-aliases.d.ts +40 -0
  183. package/dist/site/retired-plugin-tool-aliases.js +41 -0
  184. package/dist/site/service-ports.d.ts +108 -0
  185. package/dist/site/service-ports.js +2 -0
  186. package/dist/site/set-enabled.d.ts +80 -0
  187. package/dist/site/set-enabled.js +42 -0
  188. package/dist/site/soon-lock.d.ts +83 -0
  189. package/dist/site/soon-lock.js +78 -0
  190. package/dist/site/supersession.d.ts +61 -0
  191. package/dist/site/supersession.js +122 -0
  192. package/dist/site/uninstall-tool.d.ts +136 -0
  193. package/dist/site/uninstall-tool.js +203 -0
  194. package/dist/site/update-effects.d.ts +47 -0
  195. package/dist/site/update-effects.js +49 -0
  196. package/ffmpeg-transcode/plugin.json +16 -0
  197. package/github/source-control/backup-push.mjs +66 -46
  198. package/github/source-control/commit-site.mjs +112 -65
  199. package/github/source-control/write-files.mjs +86 -53
  200. package/github-pages/targets/github-pages.mjs +294 -233
  201. package/google-workspace/form-destinations/mapping.mjs +15 -7
  202. package/google-workspace/form-destinations/sheets.mjs +4 -2
  203. package/google-workspace/plugin.json +1 -0
  204. package/kuinetic/CHANGELOG.md +4 -0
  205. package/kuinetic/plugin.json +4 -1
  206. package/kuinetic/skills/kuinetic/SKILL.md +1 -2
  207. package/package.json +295 -18
  208. package/persistent-state.d.ts +4 -1
  209. package/resend/adapters/resend.mjs +5 -2
  210. package/resend/plugin.json +1 -1
  211. package/s3-compatible/jini-deploy-targets.json +1 -1
  212. package/s3-compatible/object-stores/s3-compatible.mjs +27 -4
  213. package/s3-compatible/targets/s3-compatible.mjs +3 -3
  214. package/site-import/plugin.json +3 -3
  215. package/site-import/skills/site-import/SKILL.md +62 -54
  216. package/site-import/skills/site-import/references/content-mapping.md +26 -20
  217. package/slide-design/plugin.json +1 -1
  218. package/slide-design/skills/slide-design/SKILL.md +8 -2
  219. package/ui-ux-design/CHANGELOG.md +6 -0
  220. package/ui-ux-design/plugin.json +1 -1
  221. package/ui-ux-design/skills/gstack-design/SKILL.md +6 -6
  222. package/ui-ux-design/skills/ui-ux-design/SKILL.md +3 -2
  223. package/ui-ux-design/skills/ui-ux-design/references/chrome-mobile-test-matrix.md +14 -12
  224. package/ui-ux-design/skills/ui-ux-design/references/ui-loop.md +16 -17
  225. package/vercel/NOTES.md +2 -1
  226. package/vercel/object-stores/vercel-blob.mjs +3 -4
  227. package/vercel/targets/vercel.mjs +425 -351
  228. package/core/commerce-server.d.ts +0 -2
  229. package/core/commerce-server.mjs +0 -2
  230. package/dist/admin-surfaces/connections/ports.d.ts +0 -110
  231. package/dist/admin-surfaces/connections/ports.js +0 -2
  232. /package/dist/{lifecycle → core}/install-errors.d.ts +0 -0
  233. /package/dist/{lifecycle → core}/install-errors.js +0 -0
  234. /package/dist/{lifecycle → core}/update-plan.js +0 -0
@@ -72,12 +72,59 @@ function isGitHubTimeout({ err }, _options = {}) {
72
72
  return err instanceof Error && (err.name === "TimeoutError" || err.name === "AbortError");
73
73
  }
74
74
 
75
- /**
76
- * The commit operation, bound to one kit.
77
- *
78
- * @param {Kit} kit
75
+ /** @param {Response} response @returns {Promise<{ ok: true, json: Record<string, any> } | { ok: false, message: string }>} */
76
+ async function readJsonBody(response) {
77
+ try {
78
+ const json = await response.json();
79
+ // `null`, an array or a scalar is valid JSON but carries none of the fields callers read:
80
+ // treat it as an empty object so each caller's own missing-field handling applies.
81
+ return { ok: true, json: json !== null && typeof json === "object" && !Array.isArray(json) ? json : {} };
82
+ } catch {
83
+ return { ok: false, message: "GitHub returned a non-JSON response." };
84
+ }
85
+ }
86
+
87
+ /** @param {Response} response @param {string} fallback */
88
+ async function providerErrorMessage(response, fallback) {
89
+ const body = await readJsonBody(response);
90
+ if (body.ok && typeof body.json.message === "string" && body.json.message.trim() !== "") return body.json.message;
91
+ return `${fallback} (${response.status}).`;
92
+ }
93
+
94
+ /** @param {{ kind: "network-unreachable" | "provider-rejected", message: string }} result @returns {StepFailure} */
95
+ function nonResponseFailure(result) {
96
+ return { ok: false, code: result.kind === "network-unreachable" ? "network-unreachable" : PROVIDER_ERROR, message: result.message };
97
+ }
98
+
99
+ /** Prefix payloads once and reserve the local ownership manifest before any provider I/O.
100
+ * @param {{ kit: Kit, input: { folder?: string, previousManagedManifestPath?: string, files: readonly CommitFile[] } }} required
101
+ * @complexity O(file count + path bytes), no effects.
79
102
  */
80
- export function createSiteCommitter(kit, _optional = {}) {
103
+ function prepareCommitScope({ input, kit }, _options = {}) {
104
+ try {
105
+ const folder = kit.repositoryPaths.normalizeFolder({ folder: input.folder });
106
+ const manifestPath = kit.repositoryPaths.prefixPath({ folder, path: MANAGED_MANIFEST_PATH });
107
+ const previousManagedManifestPath = input.previousManagedManifestPath ? kit.repositoryPaths.prefixPath({ folder, path: input.previousManagedManifestPath }) : undefined;
108
+ const files = input.files.map(file => ({ ...file, path: kit.repositoryPaths.prefixPath({ folder, path: file.path }) }));
109
+ if (files.some(file => file.path === manifestPath || file.path === previousManagedManifestPath)) return { ok: false, code: PROVIDER_ERROR, message: "Export cannot overwrite the managed manifest." };
110
+ return { ok: true, folder, manifestPath, previousManagedManifestPath, files };
111
+ } catch {
112
+ return { ok: false, code: PROVIDER_ERROR, message: "Invalid target folder or repository file path." };
113
+ }
114
+ }
115
+
116
+ /** @param {{ input: { branch?: string }, defaultBranch: string }} required */
117
+ function siteCommitBranch({ input, defaultBranch }, _options = {}) {
118
+ return input.branch ?? defaultBranch;
119
+ }
120
+
121
+ /** @param {{ baseTreeSha: string | undefined, treeSha: string }} required */
122
+ function unchangedSiteTree({ baseTreeSha, treeSha }, _options = {}) {
123
+ return baseTreeSha !== undefined && baseTreeSha === treeSha;
124
+ }
125
+
126
+ /** @param {Kit} kit */
127
+ function createSiteCommitTransport(kit) {
81
128
  /**
82
129
  * One request, classified before any status interpretation.
83
130
  * @param {string} url @param {RequestInit} init
@@ -99,27 +146,6 @@ export function createSiteCommitter(kit, _optional = {}) {
99
146
  }
100
147
  }
101
148
 
102
- /** @param {Response} response @returns {Promise<{ ok: true, json: Record<string, any> } | { ok: false, message: string }>} */
103
- async function readJsonBody(response) {
104
- try {
105
- return { ok: true, json: /** @type {Record<string, any>} */ (await response.json()) };
106
- } catch {
107
- return { ok: false, message: "GitHub returned a non-JSON response." };
108
- }
109
- }
110
-
111
- /** @param {Response} response @param {string} fallback */
112
- async function providerErrorMessage(response, fallback) {
113
- const body = await readJsonBody(response);
114
- if (body.ok && typeof body.json.message === "string" && body.json.message.trim() !== "") return body.json.message;
115
- return `${fallback} (${response.status}).`;
116
- }
117
-
118
- /** @param {{ kind: "network-unreachable" | "provider-rejected", message: string }} result @returns {StepFailure} */
119
- function nonResponseFailure(result) {
120
- return { ok: false, code: result.kind === "network-unreachable" ? "network-unreachable" : PROVIDER_ERROR, message: result.message };
121
- }
122
-
123
149
  /** POSTs JSON and reads back `sha`. @param {string} url @param {unknown} body @param {string} what
124
150
  * @returns {Promise<{ ok: true, sha: string } | StepFailure>} */
125
151
  async function postForSha(url, body, what, token) {
@@ -134,6 +160,11 @@ export function createSiteCommitter(kit, _optional = {}) {
134
160
  return { ok: true, sha };
135
161
  }
136
162
 
163
+ return { githubFetch, postForSha };
164
+ }
165
+
166
+ /** @param {ReturnType<typeof createSiteCommitTransport>["githubFetch"]} githubFetch */
167
+ function createCommitRepositoryReads(githubFetch) {
137
168
  /** @param {string} token @param {string} owner @param {string} repo */
138
169
  async function fetchRepo(token, owner, repo) {
139
170
  const result = await githubFetch(`${GITHUB_API}/repos/${enc(owner)}/${enc(repo)}`, { headers: githubHeaders(token) });
@@ -181,6 +212,11 @@ export function createSiteCommitter(kit, _optional = {}) {
181
212
  return { ok: true, treeSha: sha };
182
213
  }
183
214
 
215
+ return { fetchRepo, fetchBranchTip, fetchParentTree };
216
+ }
217
+
218
+ /** @param {{ kit: Kit, githubFetch: ReturnType<typeof createSiteCommitTransport>["githubFetch"] }} required */
219
+ function createManagedManifestReads({ kit, githubFetch }) {
184
220
  async function fetchManagedManifestResponse({ token, owner, repo, branch, scope }) {
185
221
  const result = await githubFetch(`${GITHUB_API}/repos/${enc(owner)}/${enc(repo)}/contents/${encPath(scope.manifestPath)}?ref=${enc(branch)}`, { headers: githubHeaders(token) });
186
222
  if (result.kind === "response" && result.response.status === 404 && scope.previousManagedManifestPath) {
@@ -234,6 +270,29 @@ export function createSiteCommitter(kit, _optional = {}) {
234
270
  return typeof body.json.sha === "string" ? { kind: "found", sha: body.json.sha } : { kind: "unverifiable" };
235
271
  }
236
272
 
273
+ return { fetchManagedManifest, fetchLiveBlobSha };
274
+ }
275
+
276
+ /** @param {Pick<ReturnType<typeof createCommitRepositoryReads>, "fetchParentTree"> & Pick<ReturnType<typeof createManagedManifestReads>, "fetchManagedManifest">} required */
277
+ function createCommitPrerequisiteReader({ fetchParentTree, fetchManagedManifest }) {
278
+ /** A new branch has no parent, no base tree and no manifest. @param {string} token @param {string} owner
279
+ * @param {string} repo @param {string} branch @param {string | undefined} parentSha */
280
+ async function resolveCommitPrerequisites(token, owner, repo, branch, parentSha, scope) {
281
+ if (parentSha === undefined) return /** @type {const} */ ({ ok: true, baseTreeSha: undefined, previousManagedFiles: undefined, parents: [], readRef: branch });
282
+
283
+ const parentTreeResult = await fetchParentTree(token, owner, repo, parentSha);
284
+ if (!parentTreeResult.ok) return parentTreeResult;
285
+ const readRef = scope.previousManagedManifestPath ? parentSha : branch;
286
+ const manifestResult = await fetchManagedManifest(token, owner, repo, readRef, scope);
287
+ if (!manifestResult.ok) return manifestResult;
288
+ return /** @type {const} */ ({ ok: true, baseTreeSha: parentTreeResult.treeSha, previousManagedFiles: manifestResult.files, parents: [parentSha], readRef });
289
+ }
290
+
291
+ return resolveCommitPrerequisites;
292
+ }
293
+
294
+ /** @param {Pick<ReturnType<typeof createSiteCommitTransport>, "postForSha"> & Pick<ReturnType<typeof createManagedManifestReads>, "fetchLiveBlobSha">} required */
295
+ function createManagedTreeEntries({ postForSha, fetchLiveBlobSha }) {
237
296
  /** @param {string} token @param {string} owner @param {string} repo @param {string | Buffer} data */
238
297
  function createBlob(token, owner, repo, data) {
239
298
  return postForSha(`${GITHUB_API}/repos/${enc(owner)}/${enc(repo)}/git/blobs`, { content: Buffer.from(data).toString("base64"), encoding: "base64" }, "blob creation", token);
@@ -288,6 +347,13 @@ export function createSiteCommitter(kit, _optional = {}) {
288
347
  return { deletions, deletedPaths, divergedPaths };
289
348
  }
290
349
 
350
+ return { createBlob, buildFileTreeEntries, resolveDeletionCandidates };
351
+ }
352
+
353
+ /** @param {Pick<ReturnType<typeof createSiteCommitTransport>, "postForSha"> & Pick<ReturnType<typeof createManagedManifestReads>, "fetchLiveBlobSha">} required */
354
+ function createManagedTreeWriter({ postForSha, fetchLiveBlobSha }) {
355
+ const { createBlob, buildFileTreeEntries, resolveDeletionCandidates } = createManagedTreeEntries({ postForSha, fetchLiveBlobSha });
356
+
291
357
  /** @param {string} token @param {string} owner @param {string} repo @param {string} branch
292
358
  * @param {readonly CommitFile[]} files @param {string | undefined} baseTreeSha
293
359
  * @param {readonly PreviouslyManagedFile[] | undefined} previousManagedFiles */
@@ -321,6 +387,11 @@ export function createSiteCommitter(kit, _optional = {}) {
321
387
  return /** @type {const} */ ({ ok: true, sha: treeResult.sha, deletedPaths, divergedPaths });
322
388
  }
323
389
 
390
+ return buildTree;
391
+ }
392
+
393
+ /** @param {ReturnType<typeof createSiteCommitTransport>["githubFetch"]} githubFetch */
394
+ function createSiteRefWriter(githubFetch) {
324
395
  /** @param {string} token @param {string} owner @param {string} repo @param {string} branch
325
396
  * @param {string} sha @param {"create" | "update"} mode */
326
397
  async function writeRef(token, owner, repo, branch, sha, mode) {
@@ -341,45 +412,21 @@ export function createSiteCommitter(kit, _optional = {}) {
341
412
  return { ok: false, code: PROVIDER_ERROR, message: await providerErrorMessage(response, `GitHub branch ${mode} failed`) };
342
413
  }
343
414
 
344
- /** A new branch has no parent, no base tree and no manifest. @param {string} token @param {string} owner
345
- * @param {string} repo @param {string} branch @param {string | undefined} parentSha */
346
- async function resolveCommitPrerequisites(token, owner, repo, branch, parentSha, scope) {
347
- if (parentSha === undefined) return /** @type {const} */ ({ ok: true, baseTreeSha: undefined, previousManagedFiles: undefined, parents: [], readRef: branch });
348
-
349
- const parentTreeResult = await fetchParentTree(token, owner, repo, parentSha);
350
- if (!parentTreeResult.ok) return parentTreeResult;
351
- const readRef = scope.previousManagedManifestPath ? parentSha : branch;
352
- const manifestResult = await fetchManagedManifest(token, owner, repo, readRef, scope);
353
- if (!manifestResult.ok) return manifestResult;
354
- return /** @type {const} */ ({ ok: true, baseTreeSha: parentTreeResult.treeSha, previousManagedFiles: manifestResult.files, parents: [parentSha], readRef });
355
- }
356
-
357
- /** Prefix payloads once and reserve the local ownership manifest before any provider I/O.
358
- * @param {{ input: { folder?: string, previousManagedManifestPath?: string, files: readonly CommitFile[] } }} required
359
- * @complexity O(file count + path bytes), no effects.
360
- */
361
- function prepareCommitScope({ input }, _options = {}) {
362
- try {
363
- const folder = kit.repositoryPaths.normalizeFolder({ folder: input.folder });
364
- const manifestPath = kit.repositoryPaths.prefixPath({ folder, path: MANAGED_MANIFEST_PATH });
365
- const previousManagedManifestPath = input.previousManagedManifestPath ? kit.repositoryPaths.prefixPath({ folder, path: input.previousManagedManifestPath }) : undefined;
366
- const files = input.files.map(file => ({ ...file, path: kit.repositoryPaths.prefixPath({ folder, path: file.path }) }));
367
- if (files.some(file => file.path === manifestPath || file.path === previousManagedManifestPath)) return { ok: false, code: PROVIDER_ERROR, message: "Export cannot overwrite the managed manifest." };
368
- return { ok: true, folder, manifestPath, previousManagedManifestPath, files };
369
- } catch {
370
- return { ok: false, code: PROVIDER_ERROR, message: "Invalid target folder or repository file path." };
371
- }
372
- }
373
-
374
- /** @param {{ input: { branch?: string }, defaultBranch: string }} required */
375
- function siteCommitBranch({ input, defaultBranch }, _options = {}) {
376
- return input.branch ?? defaultBranch;
377
- }
415
+ return writeRef;
416
+ }
378
417
 
379
- /** @param {{ baseTreeSha: string | undefined, treeSha: string }} required */
380
- function unchangedSiteTree({ baseTreeSha, treeSha }, _options = {}) {
381
- return baseTreeSha !== undefined && baseTreeSha === treeSha;
382
- }
418
+ /**
419
+ * The commit operation, bound to one kit.
420
+ *
421
+ * @param {Kit} kit
422
+ */
423
+ export function createSiteCommitter(kit, _optional = {}) {
424
+ const { githubFetch, postForSha } = createSiteCommitTransport(kit);
425
+ const { fetchRepo, fetchBranchTip, fetchParentTree } = createCommitRepositoryReads(githubFetch);
426
+ const { fetchManagedManifest, fetchLiveBlobSha } = createManagedManifestReads({ kit, githubFetch });
427
+ const resolveCommitPrerequisites = createCommitPrerequisiteReader({ fetchParentTree, fetchManagedManifest });
428
+ const buildTree = createManagedTreeWriter({ postForSha, fetchLiveBlobSha });
429
+ const writeRef = createSiteRefWriter(githubFetch);
383
430
 
384
431
  /**
385
432
  * @param {{ token: string, owner: string, repo: string, branch?: string, commitMessage: string, folder?: string, previousManagedManifestPath?: string, files: readonly CommitFile[] }} input
@@ -387,7 +434,7 @@ export function createSiteCommitter(kit, _optional = {}) {
387
434
  */
388
435
  return async function commitSite(input) {
389
436
  const { token, owner, repo, commitMessage } = input;
390
- const scope = prepareCommitScope({ input });
437
+ const scope = prepareCommitScope({ input, kit });
391
438
  if (!scope.ok) return scope;
392
439
  const files = scope.files;
393
440
 
@@ -33,20 +33,20 @@ const GITHUB_WRITE_FILES_TIMEOUT_MS = 30_000;
33
33
  const CONTENTS_API_DIRECTORY_LISTING_CAP = 1000;
34
34
  const GITHUB_UNREACHABLE_MESSAGE = "GitHub could not be reached: the request failed before any response arrived (a network error or timeout).";
35
35
 
36
- /** @param {string} value */
37
- export function enc(value) {
36
+ /** @param {{ value: string }} required */
37
+ export function enc({ value }, _optional = {}) {
38
38
  return encodeURIComponent(value);
39
39
  }
40
40
 
41
41
  /** @param {{ path: string }} required */
42
42
  export function encPath({ path }, _optional = {}) {
43
- return path.split("/").map(enc).join("/");
43
+ return path.split("/").map(value => enc({ value })).join("/");
44
44
  }
45
45
 
46
46
  /** `<baseUrl>/repos/<owner>/<repo>`. @param {Target} target */
47
47
  export function repoPathOf(target, _optional = {}) {
48
48
  const base = target.baseUrl.endsWith("/") ? target.baseUrl.slice(0, -1) : target.baseUrl;
49
- return `${base}/repos/${enc(target.owner)}/${enc(target.repo)}`;
49
+ return `${base}/repos/${enc({ value: target.owner })}/${enc({ value: target.repo })}`;
50
50
  }
51
51
 
52
52
  /** @param {HttpResponse} response */
@@ -145,17 +145,8 @@ export function retryDelayMs({ result, attempt, policy }, _optional = {}) {
145
145
  * `maxWaitMs` caps one wait: GitHub asking for longer (an hourly limit) is reported, not slept on.
146
146
  */
147
147
 
148
- /**
149
- * The credentialed GitHub calls, bound to one kit.
150
- *
151
- * @param {Kit} kit
152
- * @param {{ timeoutMs?: number, retry?: RetryPolicy }} [options] - `timeoutMs` is each request's
153
- * socket-idle budget (the egress policy may cap it lower). `retry` re-sends a request that failed
154
- * transiently ({@link retryDelayMs}); every GitHub Git Data write is safe to repeat (a blob or tree
155
- * is addressed by its content, and a non-force ref update to the same commit is a no-op). Without
156
- * it a request is sent once, as `custom_credential_write_files` always has.
157
- */
158
- export function createGitDataClient(kit, options = {}) {
148
+ /** @param {Kit} kit @param {{ timeoutMs?: number, retry?: RetryPolicy }} options */
149
+ function createGitHubSender(kit, options) {
159
150
  const timeoutMs = options.timeoutMs ?? GITHUB_WRITE_FILES_TIMEOUT_MS;
160
151
  const sleep = kit.sleep ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
161
152
 
@@ -203,6 +194,11 @@ export function createGitDataClient(kit, options = {}) {
203
194
  }
204
195
  }
205
196
 
197
+ return send;
198
+ }
199
+
200
+ /** @param {ReturnType<typeof createGitHubSender>} send */
201
+ function createGitHubJsonOperations(send) {
206
202
  /** @param {{ message: string, logDetail: string }} result @returns {Failure} */
207
203
  function nonResponseFailure(result) {
208
204
  return { ok: false, code: "network-unreachable", message: result.message, logDetail: result.logDetail };
@@ -231,6 +227,23 @@ export function createGitDataClient(kit, options = {}) {
231
227
  return { ok: true, json: parsed.json };
232
228
  }
233
229
 
230
+ return { getJson, postJson, nonResponseFailure };
231
+ }
232
+
233
+ /**
234
+ * The credentialed GitHub calls, bound to one kit.
235
+ *
236
+ * @param {Kit} kit
237
+ * @param {{ timeoutMs?: number, retry?: RetryPolicy }} [options] - `timeoutMs` is each request's
238
+ * socket-idle budget (the egress policy may cap it lower). `retry` re-sends a request that failed
239
+ * transiently ({@link retryDelayMs}); every GitHub Git Data write is safe to repeat (a blob or tree
240
+ * is addressed by its content, and a non-force ref update to the same commit is a no-op). Without
241
+ * it a request is sent once, as `custom_credential_write_files` always has.
242
+ */
243
+ export function createGitDataClient(kit, options = {}) {
244
+ const send = createGitHubSender(kit, options);
245
+ const { getJson, postJson, nonResponseFailure } = createGitHubJsonOperations(send);
246
+
234
247
  /** @param {Target} target @param {string | Uint8Array} content @returns {Promise<{ ok: true, sha: string } | Failure>} */
235
248
  async function createBlob(target, content) {
236
249
  const bytes = typeof content === "string" ? Buffer.from(content, "utf8") : Buffer.from(content.buffer, content.byteOffset, content.byteLength);
@@ -258,38 +271,49 @@ export function createGitDataClient(kit, options = {}) {
258
271
 
259
272
  /** @typedef {ReturnType<typeof createGitDataClient>} GitDataClient */
260
273
 
261
- /** The two write-files operations. @param {GitDataClient} git */
262
- export function createFileWriter(git, _optional = {}) {
274
+ /** @param {string} path @param {unknown} entry */
275
+ function stateFromListingEntry(path, entry) {
276
+ if (entry === undefined) return { ok: true, state: { path, exists: false } };
277
+ if (!isRegularFileEntry(entry)) return notRegularFileFailure(path);
278
+ return { ok: true, state: { path, exists: true } };
279
+ }
280
+
281
+ /** @param {{ files: readonly WriteFile[] }} required */
282
+ function groupWriteFilesByDirectory({ files }, _options = {}) {
283
+ /** @type {Map<string, WriteFile[]>} */
284
+ const filesByDir = new Map();
285
+ for (const file of files) {
286
+ const { dir } = splitRepoPath(file.path);
287
+ const bucket = filesByDir.get(dir);
288
+ if (bucket) bucket.push(file);
289
+ else filesByDir.set(dir, [file]);
290
+ }
291
+
292
+ return filesByDir;
293
+ }
294
+
295
+ /** @param {{ entry: any }} required */
296
+ function isModeDirectory({ entry }, _options = {}) {
297
+ return entry.type === "tree" && typeof entry.sha === "string" && !!entry.sha;
298
+ }
299
+
300
+ /** @param {{ entry: any, path: string }} required */
301
+ function modeFromBlobEntry({ entry, path }, _options = {}) {
302
+ if (entry.type !== "blob" || !["100644", "100755"].includes(entry.mode)) return notRegularFileFailure(path);
303
+ return { ok: true, mode: entry.mode };
304
+ }
305
+
306
+ /** @param {GitDataClient} git */
307
+ function createDirectoryFileStateReader(git) {
263
308
  /** @param {Target} target @param {string} branch @param {string} path */
264
309
  async function checkOneFileExistence(target, branch, path) {
265
- const result = await git.getJson(target, `${repoPathOf(target)}/contents/${encPath({ path })}?ref=${enc(branch)}`, `GitHub lookup of '${path}' failed`);
310
+ const result = await git.getJson(target, `${repoPathOf(target)}/contents/${encPath({ path })}?ref=${enc({ value: branch })}`, `GitHub lookup of '${path}' failed`);
266
311
  if (!result.ok) return result;
267
312
  if (!result.found) return { ok: true, state: { path, exists: false } };
268
313
  if (Array.isArray(result.json) || result.json.type !== "file") return notRegularFileFailure(path);
269
314
  return { ok: true, state: { path, exists: true } };
270
315
  }
271
316
 
272
- /** @param {string} path @param {unknown} entry */
273
- function stateFromListingEntry(path, entry) {
274
- if (entry === undefined) return { ok: true, state: { path, exists: false } };
275
- if (!isRegularFileEntry(entry)) return notRegularFileFailure(path);
276
- return { ok: true, state: { path, exists: true } };
277
- }
278
-
279
- /** @param {{ files: readonly WriteFile[] }} required */
280
- function groupWriteFilesByDirectory({ files }, _options = {}) {
281
- /** @type {Map<string, WriteFile[]>} */
282
- const filesByDir = new Map();
283
- for (const file of files) {
284
- const { dir } = splitRepoPath(file.path);
285
- const bucket = filesByDir.get(dir);
286
- if (bucket) bucket.push(file);
287
- else filesByDir.set(dir, [file]);
288
- }
289
-
290
- return filesByDir;
291
- }
292
-
293
317
  /** @param {{ target: Target, branch: string, dirFiles: WriteFile[], entries: any[], stateByPath: Map<string, { path: string, exists: boolean }> }} required */
294
318
  async function resolveDirectoryFileStates({ target, branch, dirFiles, entries, stateByPath }, _options = {}) {
295
319
  const entryByName = new Map(entries.map((entry) => [extractStringField({ value: entry, field: "name" }), entry]));
@@ -306,7 +330,7 @@ export function createFileWriter(git, _optional = {}) {
306
330
  /** @param {{ target: Target, branch: string, dir: string, dirFiles: WriteFile[], stateByPath: Map<string, { path: string, exists: boolean }> }} required */
307
331
  async function checkDirectoryFileExistence({ target, branch, dir, dirFiles, stateByPath }, _options = {}) {
308
332
  const directoryPath = dir ? `/${encPath({ path: dir })}` : "";
309
- const listUrl = `${repoPathOf(target)}/contents${directoryPath}?ref=${enc(branch)}`;
333
+ const listUrl = `${repoPathOf(target)}/contents${directoryPath}?ref=${enc({ value: branch })}`;
310
334
  const listResult = await git.getJson(target, listUrl, `GitHub directory lookup of '${dir}' failed`);
311
335
  if (!listResult.ok) return listResult;
312
336
  if (!listResult.found) {
@@ -320,6 +344,13 @@ export function createFileWriter(git, _optional = {}) {
320
344
  return resolveDirectoryFileStates({ target, branch, dirFiles, entries, stateByPath });
321
345
  }
322
346
 
347
+ return checkDirectoryFileExistence;
348
+ }
349
+
350
+ /** @param {GitDataClient} git */
351
+ function createFileWritePlanner(git) {
352
+ const checkDirectoryFileExistence = createDirectoryFileStateReader(git);
353
+
323
354
  /** One directory listing per distinct parent directory, falling back to a per-file lookup only when
324
355
  * a listing may be truncated. @param {Target} target @param {string} branch @param {readonly WriteFile[]} files */
325
356
  async function checkFileExistence(target, branch, files) {
@@ -343,7 +374,7 @@ export function createFileWriter(git, _optional = {}) {
343
374
  const parentCommitSha = extractStringField({ value: refJson.json.object, field: "sha" });
344
375
  if (!parentCommitSha) return { ok: false, code: PROVIDER_ERROR, message: "GitHub branch lookup response did not include a sha" };
345
376
 
346
- const commitJson = await git.getJson(input, `${repoPath}/git/commits/${enc(parentCommitSha)}`, "GitHub parent-commit lookup failed");
377
+ const commitJson = await git.getJson(input, `${repoPath}/git/commits/${enc({ value: parentCommitSha })}`, "GitHub parent-commit lookup failed");
347
378
  if (!commitJson.ok) return commitJson;
348
379
  if (!commitJson.found) return { ok: false, code: PROVIDER_ERROR, message: "GitHub parent-commit lookup returned 404 for a sha this call just resolved" };
349
380
  const baseTreeSha = extractStringField({ value: commitJson.json.tree, field: "sha" });
@@ -354,11 +385,16 @@ export function createFileWriter(git, _optional = {}) {
354
385
  return { ok: true, plan: { parentCommitSha, baseTreeSha, fileStates: existence.fileStates } };
355
386
  }
356
387
 
388
+ return planFileWrite;
389
+ }
390
+
391
+ /** @param {GitDataClient} git */
392
+ function createFileModeReader(git) {
357
393
  /** @param {{ target: Target, treeSha: string, trees: Map<string, any[]> }} required */
358
394
  async function readModeTree({ target, treeSha, trees }, _options = {}) {
359
395
  let tree = trees.get(treeSha);
360
396
  if (!tree) {
361
- const result = await git.getJson(target, `${repoPathOf(target)}/git/trees/${enc(treeSha)}`, "GitHub file-mode lookup failed");
397
+ const result = await git.getJson(target, `${repoPathOf(target)}/git/trees/${enc({ value: treeSha })}`, "GitHub file-mode lookup failed");
362
398
  if (!result.ok) return result;
363
399
  if (!result.found || !Array.isArray(result.json.tree) || result.json.truncated === true) {
364
400
  return { ok: false, code: PROVIDER_ERROR, message: "GitHub returned an incomplete tree — refusing to guess file modes" };
@@ -369,17 +405,6 @@ export function createFileWriter(git, _optional = {}) {
369
405
  return { ok: true, tree };
370
406
  }
371
407
 
372
- /** @param {{ entry: any }} required */
373
- function isModeDirectory({ entry }, _options = {}) {
374
- return entry.type === "tree" && typeof entry.sha === "string" && !!entry.sha;
375
- }
376
-
377
- /** @param {{ entry: any, path: string }} required */
378
- function modeFromBlobEntry({ entry, path }, _options = {}) {
379
- if (entry.type !== "blob" || !["100644", "100755"].includes(entry.mode)) return notRegularFileFailure(path);
380
- return { ok: true, mode: entry.mode };
381
- }
382
-
383
408
  /** @param {{ target: Target, baseTreeSha: string, file: WriteFile, trees: Map<string, any[]> }} required */
384
409
  async function readFileMode({ target, baseTreeSha, file, trees }, _options = {}) {
385
410
  let treeSha = baseTreeSha;
@@ -412,6 +437,14 @@ export function createFileWriter(git, _optional = {}) {
412
437
  return { ok: true, modes };
413
438
  }
414
439
 
440
+ return readFileModes;
441
+ }
442
+
443
+ /** The two write-files operations. @param {GitDataClient} git */
444
+ export function createFileWriter(git, _optional = {}) {
445
+ const planFileWrite = createFileWritePlanner(git);
446
+ const readFileModes = createFileModeReader(git);
447
+
415
448
  /** @param {{ input: Target & { files: readonly WriteFile[] }, modes: Map<string, string> }} required */
416
449
  async function buildWriteBlobEntries({ input, modes }, _options = {}) {
417
450
  /** @type {Map<string, string>} */