@aglyn/plugins-ai 1.0.0-beta.228 → 1.0.0-beta.230

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 (274) hide show
  1. package/README.md +3 -3
  2. package/package.json +17 -17
  3. package/src/lib/activity/ai-activity-actions.js +7 -1
  4. package/src/lib/activity/ai-activity-actions.js.map +1 -1
  5. package/src/lib/components/ai-automation-zones.d.ts +38 -0
  6. package/src/lib/components/ai-automation-zones.js +5 -1
  7. package/src/lib/components/ai-automation-zones.js.map +1 -1
  8. package/src/lib/components/ai-brief-dialog.component.d.ts +20 -2
  9. package/src/lib/components/ai-brief-dialog.component.js +87 -8
  10. package/src/lib/components/ai-brief-dialog.component.js.map +1 -1
  11. package/src/lib/components/ai-campaign-create.component.d.ts +54 -0
  12. package/src/lib/components/ai-campaign-create.component.js +270 -0
  13. package/src/lib/components/ai-campaign-create.component.js.map +1 -0
  14. package/src/lib/components/ai-describe-automation.component.d.ts +8 -3
  15. package/src/lib/components/ai-describe-automation.component.js +15 -6
  16. package/src/lib/components/ai-describe-automation.component.js.map +1 -1
  17. package/src/lib/components/ai-describe-button.component.d.ts +20 -8
  18. package/src/lib/components/ai-describe-button.component.js +19 -36
  19. package/src/lib/components/ai-describe-button.component.js.map +1 -1
  20. package/src/lib/components/ai-describe-email.component.d.ts +31 -0
  21. package/src/lib/components/ai-describe-email.component.js +22 -0
  22. package/src/lib/components/ai-describe-email.component.js.map +1 -0
  23. package/src/lib/components/ai-describe-org-automation.component.d.ts +36 -0
  24. package/src/lib/components/ai-describe-org-automation.component.js +238 -0
  25. package/src/lib/components/ai-describe-org-automation.component.js.map +1 -0
  26. package/src/lib/components/ai-experiment-cards.component.d.ts +9 -1
  27. package/src/lib/components/ai-experiment-cards.component.js +104 -18
  28. package/src/lib/components/ai-experiment-cards.component.js.map +1 -1
  29. package/src/lib/components/ai-explain-automation.component.js +1 -5
  30. package/src/lib/components/ai-explain-automation.component.js.map +1 -1
  31. package/src/lib/components/ai-funnel-zones.component.d.ts +61 -0
  32. package/src/lib/components/ai-funnel-zones.component.js +178 -0
  33. package/src/lib/components/ai-funnel-zones.component.js.map +1 -0
  34. package/src/lib/components/ai-insight-card.component.d.ts +42 -0
  35. package/src/lib/components/ai-insight-card.component.js +137 -0
  36. package/src/lib/components/ai-insight-card.component.js.map +1 -0
  37. package/src/lib/components/ai-insight-dialog.component.d.ts +6 -0
  38. package/src/lib/components/ai-insight-dialog.component.js +9 -3
  39. package/src/lib/components/ai-insight-dialog.component.js.map +1 -1
  40. package/src/lib/components/ai-job-plan.component.d.ts +7 -2
  41. package/src/lib/components/ai-job-plan.component.js +35 -5
  42. package/src/lib/components/ai-job-plan.component.js.map +1 -1
  43. package/src/lib/components/ai-job-requests.d.ts +17 -1
  44. package/src/lib/components/ai-job-requests.js +39 -3
  45. package/src/lib/components/ai-job-requests.js.map +1 -1
  46. package/src/lib/components/ai-jobs-list-page.component.js +12 -1
  47. package/src/lib/components/ai-jobs-list-page.component.js.map +1 -1
  48. package/src/lib/components/ai-logic-zones.d.ts +64 -0
  49. package/src/lib/components/ai-logic-zones.js +18 -0
  50. package/src/lib/components/ai-logic-zones.js.map +1 -0
  51. package/src/lib/components/ai-logic.component.d.ts +77 -0
  52. package/src/lib/components/ai-logic.component.js +553 -0
  53. package/src/lib/components/ai-logic.component.js.map +1 -0
  54. package/src/lib/components/ai-marketing-insight.component.d.ts +30 -0
  55. package/src/lib/components/ai-marketing-insight.component.js +80 -0
  56. package/src/lib/components/ai-marketing-insight.component.js.map +1 -0
  57. package/src/lib/components/ai-media-create.component.d.ts +55 -0
  58. package/src/lib/components/ai-media-create.component.js +433 -0
  59. package/src/lib/components/ai-media-create.component.js.map +1 -0
  60. package/src/lib/components/ai-overlay-cards.component.d.ts +83 -0
  61. package/src/lib/components/ai-overlay-cards.component.js +505 -0
  62. package/src/lib/components/ai-overlay-cards.component.js.map +1 -0
  63. package/src/lib/components/ai-product-zones.d.ts +5 -0
  64. package/src/lib/components/ai-product-zones.js +1 -1
  65. package/src/lib/components/ai-product-zones.js.map +1 -1
  66. package/src/lib/components/ai-products-create-button.component.d.ts +42 -0
  67. package/src/lib/components/ai-products-create-button.component.js +67 -0
  68. package/src/lib/components/ai-products-create-button.component.js.map +1 -0
  69. package/src/lib/components/ai-products-hub-card.component.js +100 -81
  70. package/src/lib/components/ai-products-hub-card.component.js.map +1 -1
  71. package/src/lib/components/ai-revise-automation.component.d.ts +16 -0
  72. package/src/lib/components/ai-revise-automation.component.js +207 -0
  73. package/src/lib/components/ai-revise-automation.component.js.map +1 -0
  74. package/src/lib/components/ai-site-build-page.component.d.ts +1 -1
  75. package/src/lib/components/ai-site-build-page.component.js +177 -20
  76. package/src/lib/components/ai-site-build-page.component.js.map +1 -1
  77. package/src/lib/components/ai-site-start-card.component.d.ts +10 -1
  78. package/src/lib/components/ai-site-start-card.component.js +7 -4
  79. package/src/lib/components/ai-site-start-card.component.js.map +1 -1
  80. package/src/lib/components/ai-upsell-dialog.component.d.ts +53 -0
  81. package/src/lib/components/ai-upsell-dialog.component.js +177 -0
  82. package/src/lib/components/ai-upsell-dialog.component.js.map +1 -0
  83. package/src/lib/components/assist-build-card.component.d.ts +42 -0
  84. package/src/lib/components/assist-build-card.component.js +183 -0
  85. package/src/lib/components/assist-build-card.component.js.map +1 -0
  86. package/src/lib/components/assist-edit-canvas.d.ts +2 -0
  87. package/src/lib/components/assist-edit-canvas.js +56 -1
  88. package/src/lib/components/assist-edit-canvas.js.map +1 -1
  89. package/src/lib/components/assist-jobs-drawer.component.d.ts +11 -0
  90. package/src/lib/components/assist-jobs-drawer.component.js +85 -4
  91. package/src/lib/components/assist-jobs-drawer.component.js.map +1 -1
  92. package/src/lib/components/assist-panel.component.js +51 -2
  93. package/src/lib/components/assist-panel.component.js.map +1 -1
  94. package/src/lib/components/use-ai-job-run.d.ts +3 -14
  95. package/src/lib/components/use-ai-job-run.js +0 -50
  96. package/src/lib/components/use-ai-job-run.js.map +1 -1
  97. package/src/lib/jobs/ai-build-capabilities.d.ts +58 -0
  98. package/src/lib/jobs/ai-build-capabilities.js +256 -0
  99. package/src/lib/jobs/ai-build-capabilities.js.map +1 -0
  100. package/src/lib/jobs/ai-build-unit-outcome.d.ts +52 -0
  101. package/src/lib/jobs/ai-build-unit-outcome.js +138 -0
  102. package/src/lib/jobs/ai-build-unit-outcome.js.map +1 -0
  103. package/src/lib/jobs/ai-job-build-step.d.ts +144 -0
  104. package/src/lib/jobs/ai-job-build-step.js +657 -0
  105. package/src/lib/jobs/ai-job-build-step.js.map +1 -0
  106. package/src/lib/jobs/ai-job-draft-ids.js +9 -1
  107. package/src/lib/jobs/ai-job-draft-ids.js.map +1 -1
  108. package/src/lib/jobs/ai-job-drafts.d.ts +14 -4
  109. package/src/lib/jobs/ai-job-drafts.js +25 -4
  110. package/src/lib/jobs/ai-job-drafts.js.map +1 -1
  111. package/src/lib/jobs/ai-job-layout-site-pages.d.ts +70 -0
  112. package/src/lib/jobs/ai-job-layout-site-pages.js +216 -0
  113. package/src/lib/jobs/ai-job-layout-site-pages.js.map +1 -0
  114. package/src/lib/jobs/ai-job-layout-step.d.ts +2 -2
  115. package/src/lib/jobs/ai-job-layout-step.js +19 -1
  116. package/src/lib/jobs/ai-job-layout-step.js.map +1 -1
  117. package/src/lib/jobs/ai-job-logic-step.d.ts +107 -0
  118. package/src/lib/jobs/ai-job-logic-step.js +395 -0
  119. package/src/lib/jobs/ai-job-logic-step.js.map +1 -0
  120. package/src/lib/jobs/ai-job-overlay-copy.d.ts +70 -0
  121. package/src/lib/jobs/ai-job-overlay-copy.js +178 -0
  122. package/src/lib/jobs/ai-job-overlay-copy.js.map +1 -0
  123. package/src/lib/jobs/ai-job-page-step.js +6 -6
  124. package/src/lib/jobs/ai-job-page-step.js.map +1 -1
  125. package/src/lib/jobs/ai-job-plan-step.d.ts +26 -1
  126. package/src/lib/jobs/ai-job-plan-step.js +79 -11
  127. package/src/lib/jobs/ai-job-plan-step.js.map +1 -1
  128. package/src/lib/jobs/ai-job-site-step.d.ts +15 -1
  129. package/src/lib/jobs/ai-job-site-step.js +207 -58
  130. package/src/lib/jobs/ai-job-site-step.js.map +1 -1
  131. package/src/lib/jobs/ai-job-text-step.d.ts +22 -1
  132. package/src/lib/jobs/ai-job-text-step.js +12 -0
  133. package/src/lib/jobs/ai-job-text-step.js.map +1 -1
  134. package/src/lib/jobs/ai-job-workflow-step.d.ts +54 -4
  135. package/src/lib/jobs/ai-job-workflow-step.js +318 -13
  136. package/src/lib/jobs/ai-job-workflow-step.js.map +1 -1
  137. package/src/lib/jobs/ai-jobs.d.ts +90 -2
  138. package/src/lib/jobs/ai-jobs.js +495 -61
  139. package/src/lib/jobs/ai-jobs.js.map +1 -1
  140. package/src/lib/jobs/ai-logic-records.d.ts +40 -0
  141. package/src/lib/jobs/ai-logic-records.js +55 -0
  142. package/src/lib/jobs/ai-logic-records.js.map +1 -0
  143. package/src/lib/jobs/ai-site-publish.d.ts +7 -0
  144. package/src/lib/jobs/ai-site-publish.js +9 -0
  145. package/src/lib/jobs/ai-site-publish.js.map +1 -1
  146. package/src/lib/jobs/ai-workflow-records.d.ts +4 -0
  147. package/src/lib/jobs/ai-workflow-records.js +40 -1
  148. package/src/lib/jobs/ai-workflow-records.js.map +1 -1
  149. package/src/lib/model/ai-automation-draft.d.ts +18 -0
  150. package/src/lib/model/ai-automation-draft.js +86 -0
  151. package/src/lib/model/ai-automation-draft.js.map +1 -1
  152. package/src/lib/model/ai-build-job.d.ts +201 -0
  153. package/src/lib/model/ai-build-job.js +471 -0
  154. package/src/lib/model/ai-build-job.js.map +1 -0
  155. package/src/lib/model/ai-build-plan.d.ts +61 -0
  156. package/src/lib/model/ai-build-plan.js +154 -9
  157. package/src/lib/model/ai-build-plan.js.map +1 -1
  158. package/src/lib/model/ai-build-progress.d.ts +56 -0
  159. package/src/lib/model/ai-build-progress.js +128 -0
  160. package/src/lib/model/ai-build-progress.js.map +1 -0
  161. package/src/lib/model/ai-insight.d.ts +20 -10
  162. package/src/lib/model/ai-insight.js +72 -9
  163. package/src/lib/model/ai-insight.js.map +1 -1
  164. package/src/lib/model/ai-job-activity.js +3 -1
  165. package/src/lib/model/ai-job-activity.js.map +1 -1
  166. package/src/lib/model/ai-job-failure-copy.d.ts +20 -1
  167. package/src/lib/model/ai-job-failure-copy.js +28 -1
  168. package/src/lib/model/ai-job-failure-copy.js.map +1 -1
  169. package/src/lib/model/ai-job-notice.d.ts +3 -0
  170. package/src/lib/model/ai-job-notice.js +11 -2
  171. package/src/lib/model/ai-job-notice.js.map +1 -1
  172. package/src/lib/model/ai-jobs.types.d.ts +87 -2
  173. package/src/lib/model/ai-jobs.types.js +3 -1
  174. package/src/lib/model/ai-jobs.types.js.map +1 -1
  175. package/src/lib/model/ai-logic-job.d.ts +108 -0
  176. package/src/lib/model/ai-logic-job.js +327 -0
  177. package/src/lib/model/ai-logic-job.js.map +1 -0
  178. package/src/lib/model/ai-media-credits.d.ts +52 -0
  179. package/src/lib/model/ai-media-credits.js +61 -0
  180. package/src/lib/model/ai-media-credits.js.map +1 -0
  181. package/src/lib/model/ai-overlay-copy.d.ts +114 -0
  182. package/src/lib/model/ai-overlay-copy.js +175 -0
  183. package/src/lib/model/ai-overlay-copy.js.map +1 -0
  184. package/src/lib/model/ai-site-build-progress.d.ts +28 -3
  185. package/src/lib/model/ai-site-build-progress.js +231 -17
  186. package/src/lib/model/ai-site-build-progress.js.map +1 -1
  187. package/src/lib/model/ai-site-start-seo.d.ts +16 -0
  188. package/src/lib/model/ai-site-start-seo.js +54 -4
  189. package/src/lib/model/ai-site-start-seo.js.map +1 -1
  190. package/src/lib/model/ai-site-start.d.ts +14 -0
  191. package/src/lib/model/ai-site-start.js +43 -0
  192. package/src/lib/model/ai-site-start.js.map +1 -1
  193. package/src/lib/model/ai-svg.d.ts +69 -0
  194. package/src/lib/model/ai-svg.js +265 -0
  195. package/src/lib/model/ai-svg.js.map +1 -0
  196. package/src/lib/model/ai-usage-by-user.d.ts +3 -2
  197. package/src/lib/model/ai-usage-by-user.js.map +1 -1
  198. package/src/lib/model/ai-workflow-job.d.ts +92 -4
  199. package/src/lib/model/ai-workflow-job.js +124 -7
  200. package/src/lib/model/ai-workflow-job.js.map +1 -1
  201. package/src/lib/model/assist-build.d.ts +58 -0
  202. package/src/lib/model/assist-build.js +52 -0
  203. package/src/lib/model/assist-build.js.map +1 -0
  204. package/src/lib/model/assist-edit.d.ts +48 -3
  205. package/src/lib/model/assist-edit.js +48 -4
  206. package/src/lib/model/assist-edit.js.map +1 -1
  207. package/src/lib/plugin-config.js +2 -0
  208. package/src/lib/plugin-config.js.map +1 -1
  209. package/src/lib/plugin.js +240 -11
  210. package/src/lib/plugin.js.map +1 -1
  211. package/src/lib/providers/catalog.d.ts +81 -4
  212. package/src/lib/providers/catalog.js +80 -9
  213. package/src/lib/providers/catalog.js.map +1 -1
  214. package/src/lib/providers/image-contract.d.ts +116 -0
  215. package/src/lib/providers/image-contract.js +74 -0
  216. package/src/lib/providers/image-contract.js.map +1 -0
  217. package/src/lib/providers/model-choice.js +11 -0
  218. package/src/lib/providers/model-choice.js.map +1 -1
  219. package/src/lib/providers/routing.js +18 -0
  220. package/src/lib/providers/routing.js.map +1 -1
  221. package/src/lib/providers/vertex-image.d.ts +121 -0
  222. package/src/lib/providers/vertex-image.js +312 -0
  223. package/src/lib/providers/vertex-image.js.map +1 -0
  224. package/src/lib/runtime/ai-doctrine-validators.d.ts +19 -0
  225. package/src/lib/runtime/ai-doctrine-validators.js +89 -0
  226. package/src/lib/runtime/ai-doctrine-validators.js.map +1 -1
  227. package/src/lib/runtime/ai-doctrine.d.ts +6 -0
  228. package/src/lib/runtime/ai-doctrine.js +16 -6
  229. package/src/lib/runtime/ai-doctrine.js.map +1 -1
  230. package/src/lib/runtime/ai-eval-live.js +4 -0
  231. package/src/lib/runtime/ai-eval-live.js.map +1 -1
  232. package/src/lib/runtime/ai-eval.d.ts +15 -1
  233. package/src/lib/runtime/ai-eval.js +52 -1
  234. package/src/lib/runtime/ai-eval.js.map +1 -1
  235. package/src/lib/runtime/experiment-variant-copy.d.ts +34 -0
  236. package/src/lib/runtime/experiment-variant-copy.js +102 -0
  237. package/src/lib/runtime/experiment-variant-copy.js.map +1 -0
  238. package/src/lib/server/ai-experiment-versions.d.ts +51 -0
  239. package/src/lib/server/ai-experiment-versions.js +270 -0
  240. package/src/lib/server/ai-experiment-versions.js.map +1 -0
  241. package/src/lib/server/ai-jobs-resume.js +74 -4
  242. package/src/lib/server/ai-jobs-resume.js.map +1 -1
  243. package/src/lib/server/ai-media-image.d.ts +66 -0
  244. package/src/lib/server/ai-media-image.js +521 -0
  245. package/src/lib/server/ai-media-image.js.map +1 -0
  246. package/src/lib/server/ai-media-svg.d.ts +91 -0
  247. package/src/lib/server/ai-media-svg.js +186 -0
  248. package/src/lib/server/ai-media-svg.js.map +1 -0
  249. package/src/lib/server/assist-build.d.ts +54 -0
  250. package/src/lib/server/assist-build.js +121 -0
  251. package/src/lib/server/assist-build.js.map +1 -0
  252. package/src/lib/server/assist-chat.js +108 -12
  253. package/src/lib/server/assist-chat.js.map +1 -1
  254. package/src/lib/server/assist-edit.js +213 -3
  255. package/src/lib/server/assist-edit.js.map +1 -1
  256. package/src/lib/server/assist-view-context.js +242 -4
  257. package/src/lib/server/assist-view-context.js.map +1 -1
  258. package/src/lib/server.js +26 -0
  259. package/src/lib/server.js.map +1 -1
  260. package/src/lib/tools/ai-logic-tool.d.ts +27 -0
  261. package/src/lib/tools/ai-logic-tool.js +207 -0
  262. package/src/lib/tools/ai-logic-tool.js.map +1 -0
  263. package/src/lib/tools/ai-overlay-tool.d.ts +35 -0
  264. package/src/lib/tools/ai-overlay-tool.js +107 -0
  265. package/src/lib/tools/ai-overlay-tool.js.map +1 -0
  266. package/src/lib/tools/ai-workflow-tool.d.ts +11 -0
  267. package/src/lib/tools/ai-workflow-tool.js +31 -0
  268. package/src/lib/tools/ai-workflow-tool.js.map +1 -1
  269. package/src/lib/usage/assist-job-refund.d.ts +31 -3
  270. package/src/lib/usage/assist-job-refund.js +46 -10
  271. package/src/lib/usage/assist-job-refund.js.map +1 -1
  272. package/src/lib/usage/assist-usage.d.ts +5 -0
  273. package/src/lib/usage/assist-usage.js +2 -0
  274. package/src/lib/usage/assist-usage.js.map +1 -1
@@ -0,0 +1,471 @@
1
+ import { _ as _extends } from "@swc/helpers/_/_extends";
2
+ /**
3
+ * @license
4
+ * Copyright 2026 Aglyn LLC
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */ import { pluginAiCapabilityArgsProblems } from "@aglyn/aglyn/plugin-manager/plugin-ai-capabilities";
18
+ import { AI_PLAN_NEW_REF_PREFIX, isAiPlanNewRef } from "./ai-build-plan.js";
19
+ import { AI_SITE_MAX_SECTIONS, AI_SITE_PASS_CREDITS, aiJobPlanCreditEstimate } from "./ai-site-job.js";
20
+ /**
21
+ * What a `build` job is (AGL-3616): one request — "a few pages, a contact
22
+ * form and a way to book me" — planned as creations, pages and items, built
23
+ * one UNIT a pass in dependency order, and settled ITEM BY ITEM.
24
+ *
25
+ * A build is a generalized site scaffold. Every unit is handed to what
26
+ * already builds that kind of thing — a page to the page step, a form to the
27
+ * form step, another plugin's resource to that plugin's draft writer — so a
28
+ * build cannot drift from what it builds. What is new is the settlement: one
29
+ * failed unit does not end the job. It gives back its own spend, the units
30
+ * that depended on it are built without it (or skipped, when they cannot
31
+ * stand without it), and the job is `done` when anything was delivered.
32
+ *
33
+ * This module is the build's MODEL — its units, their order, how a failure
34
+ * travels to what depends on it, what it is estimated to cost, and the
35
+ * ledger arithmetic — and does no I/O, so the step, the machine, the doors
36
+ * and the console read one vocabulary.
37
+ */ /** How much one build holds: what one proposal can describe and one person can read. */ export const AI_BUILD_LIMITS = {
38
+ /** Creations, pages and items together. */ units: 16,
39
+ pages: 8,
40
+ /** A Free workspace's pages. */ freePages: 2
41
+ };
42
+ /** What a build creates through its `create` list; everything else beyond pages is an item. */ export const AI_BUILD_CREATE_KINDS = [
43
+ 'layout',
44
+ 'form',
45
+ 'component',
46
+ 'email'
47
+ ];
48
+ /**
49
+ * The operations a build plans through `create` and `screens` rather than
50
+ * `items`: an item naming one is a plan that put it in the wrong list.
51
+ */ export const AI_BUILD_STRUCTURAL_OPS = [
52
+ 'page',
53
+ ...AI_BUILD_CREATE_KINDS
54
+ ];
55
+ /** The job input a build's Assist proposal sets when the brief asked to publish. */ export const AI_BUILD_PUBLISH_INPUT = 'publish';
56
+ /** The operation a creation is built as. */ function creationOp(creation) {
57
+ return creation.kind;
58
+ }
59
+ /** A plan's `new:<name>` names, each to the slot that builds it. */ function namedSlots(plan) {
60
+ var _plan_items;
61
+ const slots = new Map();
62
+ plan.create.forEach((creation, index)=>{
63
+ if (AI_BUILD_CREATE_KINDS.includes(creation.kind)) slots.set(creation.name.toLowerCase(), `c${index}`);
64
+ });
65
+ for (const item of (_plan_items = plan.items) != null ? _plan_items : [])slots.set(item.name.toLowerCase(), item.slot);
66
+ return slots;
67
+ }
68
+ /** The name a `new:<name>` reference gives, lowercased. */ export function aiBuildRefName(ref) {
69
+ return ref.slice(AI_PLAN_NEW_REF_PREFIX.length).trim().toLowerCase();
70
+ }
71
+ /** Every reference a page makes: its layout, template, starting page and what its sections place. */ export function aiBuildScreenRefs(screen) {
72
+ return [
73
+ screen.layout,
74
+ screen.template,
75
+ screen.duplicateOf,
76
+ ...screen.sections.flatMap((section)=>section.uses)
77
+ ].filter((ref)=>typeof ref === 'string' && ref.length > 0);
78
+ }
79
+ /**
80
+ * The units a plan implies, in plan order: creations, then items, then
81
+ * pages — the order a member reads them in, and the one a page that places
82
+ * a creation or an item is built after anyway. `aiBuildOrder` sorts them on
83
+ * their dependencies.
84
+ */ export function aiBuildUnits(plan) {
85
+ var _plan_items;
86
+ const slots = namedSlots(plan);
87
+ const depsOf = (refs, self)=>{
88
+ const deps = [];
89
+ for (const ref of refs){
90
+ if (!isAiPlanNewRef(ref)) continue;
91
+ const slot = slots.get(aiBuildRefName(ref));
92
+ if (slot && slot !== self && !deps.includes(slot)) deps.push(slot);
93
+ }
94
+ return deps;
95
+ };
96
+ const units = [];
97
+ plan.create.forEach((creation, index)=>{
98
+ if (!AI_BUILD_CREATE_KINDS.includes(creation.kind)) return;
99
+ const slot = `c${index}`;
100
+ units.push({
101
+ slot,
102
+ op: creationOp(creation),
103
+ label: creation.name,
104
+ creation,
105
+ deps: depsOf([
106
+ creation.duplicateOf
107
+ ], slot)
108
+ });
109
+ });
110
+ for (const item of (_plan_items = plan.items) != null ? _plan_items : []){
111
+ units.push({
112
+ slot: item.slot,
113
+ op: item.op,
114
+ label: item.name,
115
+ item,
116
+ deps: depsOf(item.dependsOn, item.slot)
117
+ });
118
+ }
119
+ plan.screens.forEach((screen, index)=>{
120
+ const slot = `p${index}`;
121
+ units.push({
122
+ slot,
123
+ op: 'page',
124
+ label: screen.title,
125
+ screen,
126
+ deps: depsOf(aiBuildScreenRefs(screen), slot)
127
+ });
128
+ });
129
+ return units;
130
+ }
131
+ /**
132
+ * The units in an order that builds every dependency before what depends on
133
+ * it, plan order otherwise; `null` when the dependencies hold a cycle.
134
+ */ export function aiBuildOrder(units) {
135
+ const ordered = [];
136
+ const placed = new Set();
137
+ const known = new Set(units.map((unit)=>unit.slot));
138
+ while(ordered.length < units.length){
139
+ const next = units.find((unit)=>!placed.has(unit.slot) && unit.deps.every((dep)=>placed.has(dep) || !known.has(dep)));
140
+ if (!next) return null;
141
+ ordered.push(next);
142
+ placed.add(next.slot);
143
+ }
144
+ return ordered;
145
+ }
146
+ /**
147
+ * What is wrong with a plan's references as a build reads them: a
148
+ * `new:<name>` an item depends on that nothing in the plan makes, and a
149
+ * cycle. Each is a sentence the plan's one re-ask carries.
150
+ */ export function aiBuildGraphProblems(plan) {
151
+ var _plan_items;
152
+ const problems = [];
153
+ const slots = namedSlots(plan);
154
+ for (const item of (_plan_items = plan.items) != null ? _plan_items : []){
155
+ for (const ref of item.dependsOn){
156
+ if (!isAiPlanNewRef(ref)) continue;
157
+ if (!slots.has(aiBuildRefName(ref))) {
158
+ problems.push(`The item "${item.name}" depends on ${ref}, which the plan never makes. Declare it, or take it out of dependsOn.`);
159
+ } else if (aiBuildRefName(ref) === item.name.toLowerCase()) {
160
+ problems.push(`The item "${item.name}" depends on itself. Take it out of its own dependsOn.`);
161
+ }
162
+ }
163
+ }
164
+ if (!aiBuildOrder(aiBuildUnits(plan))) {
165
+ problems.push('The plan’s dependencies go round in a circle, so nothing in the circle can be built first. Make one of them depend on nothing.');
166
+ }
167
+ return problems;
168
+ }
169
+ /** How many pages a build may hold on this workspace. */ export function aiBuildPageLimit(freeTaste) {
170
+ return freeTaste ? AI_BUILD_LIMITS.freePages : AI_BUILD_LIMITS.pages;
171
+ }
172
+ /**
173
+ * Why a build cannot build a plan of this shape, in a sentence a member
174
+ * reads; `null` when it can. Held to the plan with the one re-ask (the plan
175
+ * step's scope), and again by the doors before a confirmed plan runs.
176
+ * `ops` is what may be planned on this site; absent, items are not judged
177
+ * against the registry (a console reading a kept plan).
178
+ */ export function aiBuildPlanShapeRefusal(plan, options = {}) {
179
+ var _counts_get, _plan_items;
180
+ const units = aiBuildUnits(plan);
181
+ if (!units.length) return 'This plan builds nothing. Describe what to build again.';
182
+ if (units.length > AI_BUILD_LIMITS.units) {
183
+ return `This plan builds ${units.length} things, and one build holds ${AI_BUILD_LIMITS.units}. Ask for the rest in a second request.`;
184
+ }
185
+ const pages = aiBuildPageLimit(options.freeTaste);
186
+ if (plan.screens.length > pages) {
187
+ return options.freeTaste ? `This plan builds ${plan.screens.length} pages, and a Free workspace's build makes at most ${pages}. Paid plans can build more.` : `This plan builds ${plan.screens.length} pages, and one build makes at most ${pages}.`;
188
+ }
189
+ const slugs = new Set();
190
+ for (const screen of plan.screens){
191
+ if (!screen.sections.length) return `The page “${screen.title}” has no sections to build.`;
192
+ if (screen.sections.length > AI_SITE_MAX_SECTIONS) {
193
+ return `The page “${screen.title}” has ${screen.sections.length} sections, and a built page holds ${AI_SITE_MAX_SECTIONS}.`;
194
+ }
195
+ const slug = screen.slug.trim().toLowerCase();
196
+ if (slugs.has(slug)) return `Two pages in this plan share the address ${screen.slug}.`;
197
+ slugs.add(slug);
198
+ }
199
+ for (const creation of plan.create){
200
+ if (!AI_BUILD_CREATE_KINDS.includes(creation.kind)) {
201
+ return `A build does not create ${creation.kind === 'theme-change' ? 'theme changes' : `${creation.kind}s`} (“${creation.name}”). Take it out of create.`;
202
+ }
203
+ }
204
+ const graph = aiBuildGraphProblems(plan);
205
+ if (graph.length) return graph[0];
206
+ const ops = options.ops;
207
+ const counts = new Map();
208
+ for (const unit of units)counts.set(unit.op, ((_counts_get = counts.get(unit.op)) != null ? _counts_get : 0) + 1);
209
+ for (const item of (_plan_items = plan.items) != null ? _plan_items : []){
210
+ if (AI_BUILD_STRUCTURAL_OPS.includes(item.op)) {
211
+ return item.op === 'page' ? `“${item.name}” is a page: plan it in screens, not items.` : `“${item.name}” is ${item.op === 'email' ? 'an' : 'a'} ${item.op}: plan it in create, not items.`;
212
+ }
213
+ if (!ops) continue;
214
+ const capability = ops.get(item.op);
215
+ if (!capability) return `Nothing on this site can make “${item.name}” (${item.op}). Take it out of items.`;
216
+ if (options.freeTaste && !capability.freeAllowed) {
217
+ return `A Free workspace cannot have ${aiArticle(capability.noun)} made (“${item.name}”). Take it out of items.`;
218
+ }
219
+ const problems = pluginAiCapabilityArgsProblems(capability.argsSchema, item.args);
220
+ if (problems.length) return `The arguments of “${item.name}” do not read: ${problems.join('; ')}.`;
221
+ }
222
+ if (ops) {
223
+ for (const [op, count] of counts){
224
+ const capability = ops.get(op);
225
+ if (capability && count > capability.maxPerPlan) {
226
+ return `This plan makes ${count} of “${capability.noun}”, and one build makes at most ${capability.maxPerPlan}.`;
227
+ }
228
+ }
229
+ }
230
+ return null;
231
+ }
232
+ /** "a booking service", "an email design". */ export function aiArticle(noun) {
233
+ return `${/^[aeiou]/i.test(noun) ? 'an' : 'a'} ${noun}`;
234
+ }
235
+ /** The passes one unit is estimated at: a page's sections and its listing, one for a creation. */ function unitPasses(unit) {
236
+ if (unit.screen) return unit.screen.sections.length + 1;
237
+ return 1;
238
+ }
239
+ /**
240
+ * About what one unit costs, in credits: a page or a creation by the passes
241
+ * it implies at the nominal credits a pass is held against, as a site's are;
242
+ * an item by its capability's own estimate, recorded on the plan when it was
243
+ * kept.
244
+ */ export function aiBuildUnitCreditEstimate(unit, ops) {
245
+ if (unit.item) {
246
+ if (typeof unit.item.credits === 'number') return unit.item.credits;
247
+ const capability = ops == null ? void 0 : ops.get(unit.item.op);
248
+ if (capability) return Math.max(0, Math.floor(capability.estimateCredits(unit.item.args)));
249
+ return AI_SITE_PASS_CREDITS;
250
+ }
251
+ return unitPasses(unit) * AI_SITE_PASS_CREDITS;
252
+ }
253
+ /**
254
+ * About what a build costs, in credits: every unit's estimate, or only the
255
+ * units named in `slots` — what Try again shows. The ceiling a member
256
+ * confirms; the meter charges what actually runs.
257
+ */ export function aiBuildCreditEstimate(plan, options = {}) {
258
+ return aiBuildUnits(plan).filter((unit)=>!options.slots || options.slots.has(unit.slot)).reduce((total, unit)=>total + aiBuildUnitCreditEstimate(unit, options.ops), 0);
259
+ }
260
+ /**
261
+ * About what a job of this kind costs to build from its plan: a build's
262
+ * units, every other planned kind as `aiJobPlanCreditEstimate` counts it.
263
+ */ export function aiJobCreditEstimate(kind, plan) {
264
+ return kind === 'build' ? aiBuildCreditEstimate(plan) : aiJobPlanCreditEstimate(kind, plan);
265
+ }
266
+ /** A fresh ledger: one pending row per unit, first attempt. */ export function aiBuildInitialLedger(units) {
267
+ return units.map((unit)=>({
268
+ slot: unit.slot,
269
+ op: unit.op,
270
+ label: unit.label,
271
+ status: 'pending',
272
+ attempt: 1,
273
+ creditsSpent: 0,
274
+ attemptCredits: 0,
275
+ creditsRefunded: 0,
276
+ failure: null,
277
+ outputs: []
278
+ }));
279
+ }
280
+ const OPEN = [
281
+ 'pending',
282
+ 'running'
283
+ ];
284
+ /** Whether an item is still to be built. */ export function aiBuildItemOpen(row) {
285
+ return OPEN.includes(row.status);
286
+ }
287
+ /** Whether an item delivered: built as planned, or built without something that failed. */ export function aiBuildItemDelivered(row) {
288
+ return row.status === 'succeeded' || row.status === 'degraded';
289
+ }
290
+ /**
291
+ * The next unit to build: the first in build order whose row is still open.
292
+ * Its dependencies come before it, so by then each is settled one way or the
293
+ * other. `null` when nothing is left.
294
+ */ export function aiBuildNextUnit(ordered, ledger) {
295
+ var _ordered_find;
296
+ const rows = new Map(ledger.map((row)=>[
297
+ row.slot,
298
+ row
299
+ ]));
300
+ return (_ordered_find = ordered.find((unit)=>{
301
+ const row = rows.get(unit.slot);
302
+ return !row || aiBuildItemOpen(row);
303
+ })) != null ? _ordered_find : null;
304
+ }
305
+ /**
306
+ * How a unit is built when some of what it depends on failed (AGL-3616).
307
+ *
308
+ * A PAGE is always built: a failed layout falls back to the site's own, a
309
+ * failed form or component is left out of its section, and a failed item a
310
+ * section places (a booking service) takes its block out of the page — each
311
+ * with a note. Any OTHER unit whose dependency failed is skipped when that
312
+ * dependency's capability says `omit` (a campaign whose email design failed
313
+ * has nothing to send), and built without it when it says `fallback`.
314
+ */ export function aiBuildDegradation(unit, context) {
315
+ const rows = new Map(context.ledger.map((row)=>[
316
+ row.slot,
317
+ row
318
+ ]));
319
+ const bySlot = new Map(context.units.map((one)=>[
320
+ one.slot,
321
+ one
322
+ ]));
323
+ const result = {
324
+ skip: null,
325
+ degradedBy: [],
326
+ notes: [],
327
+ dropped: new Set(),
328
+ briefLines: []
329
+ };
330
+ for (const slot of unit.deps){
331
+ var _ref, _ref1, _ref2;
332
+ var _context_ops_get, _context_ops, _context_ops1, _dep_item, _dep_creation, _dep_creation1;
333
+ const dep = bySlot.get(slot);
334
+ const row = rows.get(slot);
335
+ if (!dep || !row || aiBuildItemDelivered(row)) continue;
336
+ const noun = dep.creation ? aiBuildCreationNoun(dep.creation.kind) : (_ref = (_context_ops = context.ops) == null ? void 0 : (_context_ops_get = _context_ops.get(dep.op)) == null ? void 0 : _context_ops_get.noun) != null ? _ref : dep.op;
337
+ const capability = dep.item ? (_context_ops1 = context.ops) == null ? void 0 : _context_ops1.get(dep.op) : undefined;
338
+ const degrade = (_ref1 = (_ref2 = (_dep_item = dep.item) == null ? void 0 : _dep_item.degrade) != null ? _ref2 : capability == null ? void 0 : capability.degrade) != null ? _ref1 : ((_dep_creation = dep.creation) == null ? void 0 : _dep_creation.kind) === 'layout' ? 'fallback' : 'omit';
339
+ if (!unit.screen && degrade === 'omit') {
340
+ result.skip = `Not built: the ${noun} “${dep.label}” it needs could not be created.`;
341
+ result.degradedBy.push(slot);
342
+ return result;
343
+ }
344
+ result.degradedBy.push(slot);
345
+ result.dropped.add(dep.label.toLowerCase());
346
+ if (((_dep_creation1 = dep.creation) == null ? void 0 : _dep_creation1.kind) === 'layout') {
347
+ result.notes.push(`Built inside the site’s own layout: the layout “${dep.label}” could not be created.`);
348
+ continue;
349
+ }
350
+ if (unit.screen) {
351
+ var _capability_pageBlocks;
352
+ const section = unit.screen.sections.find((one)=>one.uses.some((ref)=>isAiPlanNewRef(ref) && aiBuildRefName(ref) === dep.label.toLowerCase()));
353
+ const blocks = (capability == null ? void 0 : (_capability_pageBlocks = capability.pageBlocks) == null ? void 0 : _capability_pageBlocks.length) ? ` the ${capability.pageBlocks.join(' or ')} block` : '';
354
+ result.notes.push(`Built without${blocks || ` the ${noun}`}: the ${noun} “${dep.label}” could not be created.`);
355
+ result.briefLines.push(`${section ? `Build the “${section.name}” section` : 'Build the page'} without the ${noun} “${dep.label}”${blocks ? ` and without${blocks}` : ''}: it could not be created.`);
356
+ } else {
357
+ result.notes.push(`Built without the ${noun} “${dep.label}”: it could not be created.`);
358
+ }
359
+ }
360
+ return result;
361
+ }
362
+ /** What each creation is called in a note. */ export function aiBuildCreationNoun(kind) {
363
+ return kind === 'email' ? 'email design' : kind === 'theme-change' ? 'theme change' : kind;
364
+ }
365
+ /**
366
+ * The brief lines a page is told about the items its sections place and
367
+ * that were built: the block to put there, in the owner's words.
368
+ */ export function aiBuildPlacedItemLines(unit, context) {
369
+ if (!unit.screen) return [];
370
+ const rows = new Map(context.ledger.map((row)=>[
371
+ row.slot,
372
+ row
373
+ ]));
374
+ const lines = [];
375
+ for (const section of unit.screen.sections){
376
+ for (const ref of section.uses){
377
+ var _ref, _ref1;
378
+ var _context_ops;
379
+ if (!isAiPlanNewRef(ref)) continue;
380
+ const dep = context.units.find((one)=>one.item && one.item.name.toLowerCase() === aiBuildRefName(ref));
381
+ if (!(dep == null ? void 0 : dep.item)) continue;
382
+ const row = rows.get(dep.slot);
383
+ if (!row || !aiBuildItemDelivered(row)) continue;
384
+ const capability = (_context_ops = context.ops) == null ? void 0 : _context_ops.get(dep.op);
385
+ const blocks = (_ref = capability == null ? void 0 : capability.pageBlocks) != null ? _ref : [];
386
+ if (!blocks.length) continue;
387
+ lines.push(`In the “${section.name}” section, place the ${blocks.join(' or ')} block for the ${(_ref1 = capability == null ? void 0 : capability.noun) != null ? _ref1 : dep.op} “${dep.label}”.`);
388
+ }
389
+ }
390
+ return lines;
391
+ }
392
+ /** What a build came to: whether anything was delivered, and whether anything is left. */ export function aiBuildSettlement(ledger) {
393
+ return {
394
+ delivered: ledger.some(aiBuildItemDelivered),
395
+ open: ledger.some(aiBuildItemOpen),
396
+ failed: ledger.filter((row)=>row.status === 'failed').length
397
+ };
398
+ }
399
+ /**
400
+ * The ledger Try again runs (AGL-3616): every failed item back to `pending`
401
+ * on its next attempt, with the items left unbuilt because of it — skipped,
402
+ * or degraded with no draft — and every item the build never reached. An
403
+ * item that succeeded is never run again, and a degraded page that has its
404
+ * draft keeps it, with a note that the page needs an edit. `retried` names
405
+ * the slots that will run, which is what the estimate is shown for.
406
+ */ export function aiBuildRetryLedger(ledger, units) {
407
+ const failed = new Set(ledger.filter((row)=>row.status === 'failed').map((row)=>row.slot));
408
+ const dependents = new Map();
409
+ for (const unit of units){
410
+ var _dependents_get;
411
+ for (const dep of unit.deps)dependents.set(dep, [
412
+ ...(_dependents_get = dependents.get(dep)) != null ? _dependents_get : [],
413
+ unit.slot
414
+ ]);
415
+ }
416
+ // Everything downstream of a failed item, transitively.
417
+ const downstream = new Set();
418
+ const queue = [
419
+ ...failed
420
+ ];
421
+ while(queue.length){
422
+ var _dependents_get1;
423
+ const slot = queue.shift();
424
+ for (const next of (_dependents_get1 = dependents.get(slot)) != null ? _dependents_get1 : []){
425
+ if (downstream.has(next)) continue;
426
+ downstream.add(next);
427
+ queue.push(next);
428
+ }
429
+ }
430
+ const retried = [];
431
+ const next = ledger.map((row)=>{
432
+ var _row_degradedBy;
433
+ const again = row.status === 'failed' || row.status === 'skipped' && (downstream.has(row.slot) || !((_row_degradedBy = row.degradedBy) != null ? _row_degradedBy : []).length) || row.status === 'degraded' && downstream.has(row.slot) && !row.outputs.length;
434
+ if (again) {
435
+ retried.push(row.slot);
436
+ return _extends({}, row, {
437
+ status: 'pending',
438
+ attempt: row.attempt + 1,
439
+ attemptCredits: 0,
440
+ failure: null,
441
+ note: null,
442
+ degradedBy: []
443
+ });
444
+ }
445
+ if (row.status === 'degraded' && downstream.has(row.slot) && row.outputs.length) {
446
+ return _extends({}, row, {
447
+ note: `${row.note ? `${row.note} ` : ''}It keeps its draft: once the rest is built, edit this page to add what it is missing.`
448
+ });
449
+ }
450
+ return row;
451
+ });
452
+ return {
453
+ ledger: next,
454
+ retried
455
+ };
456
+ }
457
+ /**
458
+ * Units read back off a ledger alone (AGL-3616), for a job whose units are
459
+ * not a build plan's — a site scaffold's: each row as its unit, and every
460
+ * page built after the layouts and forms the ledger holds.
461
+ */ export function aiLedgerUnits(ledger) {
462
+ const creations = ledger.filter((row)=>row.op === 'layout' || row.op === 'form').map((row)=>row.slot);
463
+ return ledger.map((row)=>({
464
+ slot: row.slot,
465
+ op: row.op,
466
+ label: row.label,
467
+ deps: row.op === 'page' ? creations : []
468
+ }));
469
+ }
470
+
471
+ //# sourceMappingURL=ai-build-job.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/model/ai-build-job.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n pluginAiCapabilityArgsProblems,\n type PluginAiCapability,\n} from '@aglyn/aglyn/plugin-manager/plugin-ai-capabilities'\nimport {\n AI_PLAN_NEW_REF_PREFIX,\n isAiPlanNewRef,\n type AiBuildItem,\n type AiBuildPlan,\n type AiBuildPlanCreate,\n type AiBuildPlanCreateKind,\n type AiBuildPlanScreen,\n} from './ai-build-plan'\nimport type { AiJobItemLedger, AiJobItemStatus } from './ai-jobs.types'\nimport { AI_SITE_MAX_SECTIONS, AI_SITE_PASS_CREDITS, aiJobPlanCreditEstimate } from './ai-site-job'\n\n/**\n * What a `build` job is (AGL-3616): one request — \"a few pages, a contact\n * form and a way to book me\" — planned as creations, pages and items, built\n * one UNIT a pass in dependency order, and settled ITEM BY ITEM.\n *\n * A build is a generalized site scaffold. Every unit is handed to what\n * already builds that kind of thing — a page to the page step, a form to the\n * form step, another plugin's resource to that plugin's draft writer — so a\n * build cannot drift from what it builds. What is new is the settlement: one\n * failed unit does not end the job. It gives back its own spend, the units\n * that depended on it are built without it (or skipped, when they cannot\n * stand without it), and the job is `done` when anything was delivered.\n *\n * This module is the build's MODEL — its units, their order, how a failure\n * travels to what depends on it, what it is estimated to cost, and the\n * ledger arithmetic — and does no I/O, so the step, the machine, the doors\n * and the console read one vocabulary.\n */\n\n/** How much one build holds: what one proposal can describe and one person can read. */\nexport const AI_BUILD_LIMITS = {\n /** Creations, pages and items together. */\n units: 16,\n pages: 8,\n /** A Free workspace's pages. */\n freePages: 2,\n} as const\n\n/** What a build creates through its `create` list; everything else beyond pages is an item. */\nexport const AI_BUILD_CREATE_KINDS: readonly AiBuildPlanCreateKind[] = ['layout', 'form', 'component', 'email']\n\n/**\n * The operations a build plans through `create` and `screens` rather than\n * `items`: an item naming one is a plan that put it in the wrong list.\n */\nexport const AI_BUILD_STRUCTURAL_OPS: readonly string[] = ['page', ...AI_BUILD_CREATE_KINDS]\n\n/** The job input a build's Assist proposal sets when the brief asked to publish. */\nexport const AI_BUILD_PUBLISH_INPUT = 'publish'\n\n/** A unit of a build: a creation, a page, or an item. */\nexport interface AiBuildUnit {\n slot: string\n /** The capability operation that builds it. */\n op: string\n label: string\n creation?: AiBuildPlanCreate\n screen?: AiBuildPlanScreen\n item?: AiBuildItem\n /** The slots it is built after, in plan order. */\n deps: string[]\n}\n\n/** The operation a creation is built as. */\nfunction creationOp(creation: AiBuildPlanCreate): string {\n return creation.kind\n}\n\n/** A plan's `new:<name>` names, each to the slot that builds it. */\nfunction namedSlots(plan: AiBuildPlan): Map<string, string> {\n const slots = new Map<string, string>()\n plan.create.forEach((creation, index) => {\n if (AI_BUILD_CREATE_KINDS.includes(creation.kind)) slots.set(creation.name.toLowerCase(), `c${index}`)\n })\n for (const item of plan.items ?? []) slots.set(item.name.toLowerCase(), item.slot)\n return slots\n}\n\n/** The name a `new:<name>` reference gives, lowercased. */\nexport function aiBuildRefName(ref: string): string {\n return ref.slice(AI_PLAN_NEW_REF_PREFIX.length).trim().toLowerCase()\n}\n\n/** Every reference a page makes: its layout, template, starting page and what its sections place. */\nexport function aiBuildScreenRefs(screen: AiBuildPlanScreen): string[] {\n return [\n screen.layout,\n screen.template,\n screen.duplicateOf,\n ...screen.sections.flatMap((section) => section.uses),\n ].filter((ref): ref is string => typeof ref === 'string' && ref.length > 0)\n}\n\n/**\n * The units a plan implies, in plan order: creations, then items, then\n * pages — the order a member reads them in, and the one a page that places\n * a creation or an item is built after anyway. `aiBuildOrder` sorts them on\n * their dependencies.\n */\nexport function aiBuildUnits(plan: AiBuildPlan): AiBuildUnit[] {\n const slots = namedSlots(plan)\n const depsOf = (refs: readonly (string | null)[], self: string): string[] => {\n const deps: string[] = []\n for (const ref of refs) {\n if (!isAiPlanNewRef(ref)) continue\n const slot = slots.get(aiBuildRefName(ref))\n if (slot && slot !== self && !deps.includes(slot)) deps.push(slot)\n }\n return deps\n }\n const units: AiBuildUnit[] = []\n plan.create.forEach((creation, index) => {\n if (!AI_BUILD_CREATE_KINDS.includes(creation.kind)) return\n const slot = `c${index}`\n units.push({ slot, op: creationOp(creation), label: creation.name, creation, deps: depsOf([creation.duplicateOf], slot) })\n })\n for (const item of plan.items ?? []) {\n units.push({ slot: item.slot, op: item.op, label: item.name, item, deps: depsOf(item.dependsOn, item.slot) })\n }\n plan.screens.forEach((screen, index) => {\n const slot = `p${index}`\n units.push({ slot, op: 'page', label: screen.title, screen, deps: depsOf(aiBuildScreenRefs(screen), slot) })\n })\n return units\n}\n\n/**\n * The units in an order that builds every dependency before what depends on\n * it, plan order otherwise; `null` when the dependencies hold a cycle.\n */\nexport function aiBuildOrder(units: readonly AiBuildUnit[]): AiBuildUnit[] | null {\n const ordered: AiBuildUnit[] = []\n const placed = new Set<string>()\n const known = new Set(units.map((unit) => unit.slot))\n while (ordered.length < units.length) {\n const next = units.find(\n (unit) => !placed.has(unit.slot) && unit.deps.every((dep) => placed.has(dep) || !known.has(dep)),\n )\n if (!next) return null\n ordered.push(next)\n placed.add(next.slot)\n }\n return ordered\n}\n\n/**\n * What is wrong with a plan's references as a build reads them: a\n * `new:<name>` an item depends on that nothing in the plan makes, and a\n * cycle. Each is a sentence the plan's one re-ask carries.\n */\nexport function aiBuildGraphProblems(plan: AiBuildPlan): string[] {\n const problems: string[] = []\n const slots = namedSlots(plan)\n for (const item of plan.items ?? []) {\n for (const ref of item.dependsOn) {\n if (!isAiPlanNewRef(ref)) continue\n if (!slots.has(aiBuildRefName(ref))) {\n problems.push(`The item \"${item.name}\" depends on ${ref}, which the plan never makes. Declare it, or take it out of dependsOn.`)\n } else if (aiBuildRefName(ref) === item.name.toLowerCase()) {\n problems.push(`The item \"${item.name}\" depends on itself. Take it out of its own dependsOn.`)\n }\n }\n }\n if (!aiBuildOrder(aiBuildUnits(plan))) {\n problems.push('The plan’s dependencies go round in a circle, so nothing in the circle can be built first. Make one of them depend on nothing.')\n }\n return problems\n}\n\n/** The operations a build may plan, as the registry and the gates left them, by op. */\nexport type AiBuildOps = ReadonlyMap<string, PluginAiCapability>\n\n/** How many pages a build may hold on this workspace. */\nexport function aiBuildPageLimit(freeTaste: boolean | null | undefined): number {\n return freeTaste ? AI_BUILD_LIMITS.freePages : AI_BUILD_LIMITS.pages\n}\n\n/**\n * Why a build cannot build a plan of this shape, in a sentence a member\n * reads; `null` when it can. Held to the plan with the one re-ask (the plan\n * step's scope), and again by the doors before a confirmed plan runs.\n * `ops` is what may be planned on this site; absent, items are not judged\n * against the registry (a console reading a kept plan).\n */\nexport function aiBuildPlanShapeRefusal(\n plan: AiBuildPlan,\n options: { freeTaste?: boolean; ops?: AiBuildOps } = {},\n): string | null {\n const units = aiBuildUnits(plan)\n if (!units.length) return 'This plan builds nothing. Describe what to build again.'\n if (units.length > AI_BUILD_LIMITS.units) {\n return `This plan builds ${units.length} things, and one build holds ${AI_BUILD_LIMITS.units}. Ask for the rest in a second request.`\n }\n const pages = aiBuildPageLimit(options.freeTaste)\n if (plan.screens.length > pages) {\n return options.freeTaste\n ? `This plan builds ${plan.screens.length} pages, and a Free workspace's build makes at most ${pages}. Paid plans can build more.`\n : `This plan builds ${plan.screens.length} pages, and one build makes at most ${pages}.`\n }\n const slugs = new Set<string>()\n for (const screen of plan.screens) {\n if (!screen.sections.length) return `The page “${screen.title}” has no sections to build.`\n if (screen.sections.length > AI_SITE_MAX_SECTIONS) {\n return `The page “${screen.title}” has ${screen.sections.length} sections, and a built page holds ${AI_SITE_MAX_SECTIONS}.`\n }\n const slug = screen.slug.trim().toLowerCase()\n if (slugs.has(slug)) return `Two pages in this plan share the address ${screen.slug}.`\n slugs.add(slug)\n }\n for (const creation of plan.create) {\n if (!AI_BUILD_CREATE_KINDS.includes(creation.kind)) {\n return `A build does not create ${creation.kind === 'theme-change' ? 'theme changes' : `${creation.kind}s`} (“${creation.name}”). Take it out of create.`\n }\n }\n const graph = aiBuildGraphProblems(plan)\n if (graph.length) return graph[0]\n const ops = options.ops\n const counts = new Map<string, number>()\n for (const unit of units) counts.set(unit.op, (counts.get(unit.op) ?? 0) + 1)\n for (const item of plan.items ?? []) {\n if (AI_BUILD_STRUCTURAL_OPS.includes(item.op)) {\n return item.op === 'page'\n ? `“${item.name}” is a page: plan it in screens, not items.`\n : `“${item.name}” is ${item.op === 'email' ? 'an' : 'a'} ${item.op}: plan it in create, not items.`\n }\n if (!ops) continue\n const capability = ops.get(item.op)\n if (!capability) return `Nothing on this site can make “${item.name}” (${item.op}). Take it out of items.`\n if (options.freeTaste && !capability.freeAllowed) {\n return `A Free workspace cannot have ${aiArticle(capability.noun)} made (“${item.name}”). Take it out of items.`\n }\n const problems = pluginAiCapabilityArgsProblems(capability.argsSchema, item.args)\n if (problems.length) return `The arguments of “${item.name}” do not read: ${problems.join('; ')}.`\n }\n if (ops) {\n for (const [op, count] of counts) {\n const capability = ops.get(op)\n if (capability && count > capability.maxPerPlan) {\n return `This plan makes ${count} of “${capability.noun}”, and one build makes at most ${capability.maxPerPlan}.`\n }\n }\n }\n return null\n}\n\n/** \"a booking service\", \"an email design\". */\nexport function aiArticle(noun: string): string {\n return `${/^[aeiou]/i.test(noun) ? 'an' : 'a'} ${noun}`\n}\n\n/** The passes one unit is estimated at: a page's sections and its listing, one for a creation. */\nfunction unitPasses(unit: AiBuildUnit): number {\n if (unit.screen) return unit.screen.sections.length + 1\n return 1\n}\n\n/**\n * About what one unit costs, in credits: a page or a creation by the passes\n * it implies at the nominal credits a pass is held against, as a site's are;\n * an item by its capability's own estimate, recorded on the plan when it was\n * kept.\n */\nexport function aiBuildUnitCreditEstimate(unit: AiBuildUnit, ops?: AiBuildOps): number {\n if (unit.item) {\n if (typeof unit.item.credits === 'number') return unit.item.credits\n const capability = ops?.get(unit.item.op)\n if (capability) return Math.max(0, Math.floor(capability.estimateCredits(unit.item.args)))\n return AI_SITE_PASS_CREDITS\n }\n return unitPasses(unit) * AI_SITE_PASS_CREDITS\n}\n\n/**\n * About what a build costs, in credits: every unit's estimate, or only the\n * units named in `slots` — what Try again shows. The ceiling a member\n * confirms; the meter charges what actually runs.\n */\nexport function aiBuildCreditEstimate(\n plan: AiBuildPlan,\n options: { ops?: AiBuildOps; slots?: ReadonlySet<string> } = {},\n): number {\n return aiBuildUnits(plan)\n .filter((unit) => !options.slots || options.slots.has(unit.slot))\n .reduce((total, unit) => total + aiBuildUnitCreditEstimate(unit, options.ops), 0)\n}\n\n/**\n * About what a job of this kind costs to build from its plan: a build's\n * units, every other planned kind as `aiJobPlanCreditEstimate` counts it.\n */\nexport function aiJobCreditEstimate(kind: string, plan: AiBuildPlan): number {\n return kind === 'build' ? aiBuildCreditEstimate(plan) : aiJobPlanCreditEstimate(kind, plan)\n}\n\n/** A fresh ledger: one pending row per unit, first attempt. */\nexport function aiBuildInitialLedger(units: readonly AiBuildUnit[]): AiJobItemLedger[] {\n return units.map((unit) => ({\n slot: unit.slot,\n op: unit.op,\n label: unit.label,\n status: 'pending',\n attempt: 1,\n creditsSpent: 0,\n attemptCredits: 0,\n creditsRefunded: 0,\n failure: null,\n outputs: [],\n }))\n}\n\nconst OPEN: readonly AiJobItemStatus[] = ['pending', 'running']\n\n/** Whether an item is still to be built. */\nexport function aiBuildItemOpen(row: Pick<AiJobItemLedger, 'status'>): boolean {\n return OPEN.includes(row.status)\n}\n\n/** Whether an item delivered: built as planned, or built without something that failed. */\nexport function aiBuildItemDelivered(row: Pick<AiJobItemLedger, 'status'>): boolean {\n return row.status === 'succeeded' || row.status === 'degraded'\n}\n\n/**\n * The next unit to build: the first in build order whose row is still open.\n * Its dependencies come before it, so by then each is settled one way or the\n * other. `null` when nothing is left.\n */\nexport function aiBuildNextUnit(\n ordered: readonly AiBuildUnit[],\n ledger: readonly AiJobItemLedger[],\n): AiBuildUnit | null {\n const rows = new Map(ledger.map((row) => [row.slot, row]))\n return ordered.find((unit) => {\n const row = rows.get(unit.slot)\n return !row || aiBuildItemOpen(row)\n }) ?? null\n}\n\n/** How a unit is built given what its dependencies came to. */\nexport interface AiBuildDegradation {\n /** The unit is not built at all, with the sentence why; nothing is spent. */\n skip: string | null\n /** The failed dependencies that change how it is built. */\n degradedBy: string[]\n /** What the person reads about the change; one per failed dependency. */\n notes: string[]\n /** `new:<name>` references (lowercased names) to leave out. */\n dropped: Set<string>\n /** Brief lines for the unit's own job: what to leave out, and what to place. */\n briefLines: string[]\n}\n\n/**\n * How a unit is built when some of what it depends on failed (AGL-3616).\n *\n * A PAGE is always built: a failed layout falls back to the site's own, a\n * failed form or component is left out of its section, and a failed item a\n * section places (a booking service) takes its block out of the page — each\n * with a note. Any OTHER unit whose dependency failed is skipped when that\n * dependency's capability says `omit` (a campaign whose email design failed\n * has nothing to send), and built without it when it says `fallback`.\n */\nexport function aiBuildDegradation(\n unit: AiBuildUnit,\n context: {\n units: readonly AiBuildUnit[]\n ledger: readonly AiJobItemLedger[]\n ops?: AiBuildOps\n },\n): AiBuildDegradation {\n const rows = new Map(context.ledger.map((row) => [row.slot, row]))\n const bySlot = new Map(context.units.map((one) => [one.slot, one]))\n const result: AiBuildDegradation = { skip: null, degradedBy: [], notes: [], dropped: new Set(), briefLines: [] }\n for (const slot of unit.deps) {\n const dep = bySlot.get(slot)\n const row = rows.get(slot)\n if (!dep || !row || aiBuildItemDelivered(row)) continue\n const noun = dep.creation\n ? aiBuildCreationNoun(dep.creation.kind)\n : (context.ops?.get(dep.op)?.noun ?? dep.op)\n const capability = dep.item ? context.ops?.get(dep.op) : undefined\n const degrade = dep.item?.degrade ?? capability?.degrade ?? (dep.creation?.kind === 'layout' ? 'fallback' : 'omit')\n if (!unit.screen && degrade === 'omit') {\n result.skip = `Not built: the ${noun} “${dep.label}” it needs could not be created.`\n result.degradedBy.push(slot)\n return result\n }\n result.degradedBy.push(slot)\n result.dropped.add(dep.label.toLowerCase())\n if (dep.creation?.kind === 'layout') {\n result.notes.push(`Built inside the site’s own layout: the layout “${dep.label}” could not be created.`)\n continue\n }\n if (unit.screen) {\n const section = unit.screen.sections.find((one) =>\n one.uses.some((ref) => isAiPlanNewRef(ref) && aiBuildRefName(ref) === dep.label.toLowerCase()),\n )\n const blocks = capability?.pageBlocks?.length ? ` the ${capability.pageBlocks.join(' or ')} block` : ''\n result.notes.push(\n `Built without${blocks || ` the ${noun}`}: the ${noun} “${dep.label}” could not be created.`,\n )\n result.briefLines.push(\n `${section ? `Build the “${section.name}” section` : 'Build the page'} without the ${noun} “${dep.label}”${blocks ? ` and without${blocks}` : ''}: it could not be created.`,\n )\n } else {\n result.notes.push(`Built without the ${noun} “${dep.label}”: it could not be created.`)\n }\n }\n return result\n}\n\n/** What each creation is called in a note. */\nexport function aiBuildCreationNoun(kind: AiBuildPlanCreateKind): string {\n return kind === 'email' ? 'email design' : kind === 'theme-change' ? 'theme change' : kind\n}\n\n/**\n * The brief lines a page is told about the items its sections place and\n * that were built: the block to put there, in the owner's words.\n */\nexport function aiBuildPlacedItemLines(\n unit: AiBuildUnit,\n context: { units: readonly AiBuildUnit[]; ledger: readonly AiJobItemLedger[]; ops?: AiBuildOps },\n): string[] {\n if (!unit.screen) return []\n const rows = new Map(context.ledger.map((row) => [row.slot, row]))\n const lines: string[] = []\n for (const section of unit.screen.sections) {\n for (const ref of section.uses) {\n if (!isAiPlanNewRef(ref)) continue\n const dep = context.units.find((one) => one.item && one.item.name.toLowerCase() === aiBuildRefName(ref))\n if (!dep?.item) continue\n const row = rows.get(dep.slot)\n if (!row || !aiBuildItemDelivered(row)) continue\n const capability = context.ops?.get(dep.op)\n const blocks = capability?.pageBlocks ?? []\n if (!blocks.length) continue\n lines.push(\n `In the “${section.name}” section, place the ${blocks.join(' or ')} block for the ${capability?.noun ?? dep.op} “${dep.label}”.`,\n )\n }\n }\n return lines\n}\n\n/** What a build came to: whether anything was delivered, and whether anything is left. */\nexport function aiBuildSettlement(ledger: readonly AiJobItemLedger[]): {\n delivered: boolean\n open: boolean\n failed: number\n} {\n return {\n delivered: ledger.some(aiBuildItemDelivered),\n open: ledger.some(aiBuildItemOpen),\n failed: ledger.filter((row) => row.status === 'failed').length,\n }\n}\n\n/**\n * The ledger Try again runs (AGL-3616): every failed item back to `pending`\n * on its next attempt, with the items left unbuilt because of it — skipped,\n * or degraded with no draft — and every item the build never reached. An\n * item that succeeded is never run again, and a degraded page that has its\n * draft keeps it, with a note that the page needs an edit. `retried` names\n * the slots that will run, which is what the estimate is shown for.\n */\nexport function aiBuildRetryLedger(\n ledger: readonly AiJobItemLedger[],\n units: readonly AiBuildUnit[],\n): { ledger: AiJobItemLedger[]; retried: string[] } {\n const failed = new Set(ledger.filter((row) => row.status === 'failed').map((row) => row.slot))\n const dependents = new Map<string, string[]>()\n for (const unit of units) {\n for (const dep of unit.deps) dependents.set(dep, [...(dependents.get(dep) ?? []), unit.slot])\n }\n // Everything downstream of a failed item, transitively.\n const downstream = new Set<string>()\n const queue = [...failed]\n while (queue.length) {\n const slot = queue.shift() as string\n for (const next of dependents.get(slot) ?? []) {\n if (downstream.has(next)) continue\n downstream.add(next)\n queue.push(next)\n }\n }\n const retried: string[] = []\n const next = ledger.map((row): AiJobItemLedger => {\n const again =\n row.status === 'failed' ||\n (row.status === 'skipped' && (downstream.has(row.slot) || !(row.degradedBy ?? []).length)) ||\n (row.status === 'degraded' && downstream.has(row.slot) && !row.outputs.length)\n if (again) {\n retried.push(row.slot)\n return {\n ...row,\n status: 'pending',\n attempt: row.attempt + 1,\n attemptCredits: 0,\n failure: null,\n note: null,\n degradedBy: [],\n }\n }\n if (row.status === 'degraded' && downstream.has(row.slot) && row.outputs.length) {\n return {\n ...row,\n note: `${row.note ? `${row.note} ` : ''}It keeps its draft: once the rest is built, edit this page to add what it is missing.`,\n }\n }\n return row\n })\n return { ledger: next, retried }\n}\n\n/**\n * Units read back off a ledger alone (AGL-3616), for a job whose units are\n * not a build plan's — a site scaffold's: each row as its unit, and every\n * page built after the layouts and forms the ledger holds.\n */\nexport function aiLedgerUnits(ledger: readonly AiJobItemLedger[]): AiBuildUnit[] {\n const creations = ledger.filter((row) => row.op === 'layout' || row.op === 'form').map((row) => row.slot)\n return ledger.map((row) => ({\n slot: row.slot,\n op: row.op,\n label: row.label,\n deps: row.op === 'page' ? creations : [],\n }))\n}\n"],"names":["pluginAiCapabilityArgsProblems","AI_PLAN_NEW_REF_PREFIX","isAiPlanNewRef","AI_SITE_MAX_SECTIONS","AI_SITE_PASS_CREDITS","aiJobPlanCreditEstimate","AI_BUILD_LIMITS","units","pages","freePages","AI_BUILD_CREATE_KINDS","AI_BUILD_STRUCTURAL_OPS","AI_BUILD_PUBLISH_INPUT","creationOp","creation","kind","namedSlots","plan","slots","Map","create","forEach","index","includes","set","name","toLowerCase","item","items","slot","aiBuildRefName","ref","slice","length","trim","aiBuildScreenRefs","screen","layout","template","duplicateOf","sections","flatMap","section","uses","filter","aiBuildUnits","depsOf","refs","self","deps","get","push","op","label","dependsOn","screens","title","aiBuildOrder","ordered","placed","Set","known","map","unit","next","find","has","every","dep","add","aiBuildGraphProblems","problems","aiBuildPageLimit","freeTaste","aiBuildPlanShapeRefusal","options","counts","slugs","slug","graph","ops","capability","freeAllowed","aiArticle","noun","argsSchema","args","join","count","maxPerPlan","test","unitPasses","aiBuildUnitCreditEstimate","credits","Math","max","floor","estimateCredits","aiBuildCreditEstimate","reduce","total","aiJobCreditEstimate","aiBuildInitialLedger","status","attempt","creditsSpent","attemptCredits","creditsRefunded","failure","outputs","OPEN","aiBuildItemOpen","row","aiBuildItemDelivered","aiBuildNextUnit","ledger","rows","aiBuildDegradation","context","bySlot","one","result","skip","degradedBy","notes","dropped","briefLines","aiBuildCreationNoun","undefined","degrade","some","blocks","pageBlocks","aiBuildPlacedItemLines","lines","aiBuildSettlement","delivered","open","failed","aiBuildRetryLedger","dependents","downstream","queue","shift","retried","again","note","aiLedgerUnits","creations"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SACEA,8BAA8B,QAEzB,qDAAoD;AAC3D,SACEC,sBAAsB,EACtBC,cAAc,QAMT,qBAAiB;AAExB,SAASC,oBAAoB,EAAEC,oBAAoB,EAAEC,uBAAuB,QAAQ,mBAAe;AAEnG;;;;;;;;;;;;;;;;;CAiBC,GAED,sFAAsF,GACtF,OAAO,MAAMC,kBAAkB;IAC7B,yCAAyC,GACzCC,OAAO;IACPC,OAAO;IACP,8BAA8B,GAC9BC,WAAW;AACb,EAAU;AAEV,6FAA6F,GAC7F,OAAO,MAAMC,wBAA0D;IAAC;IAAU;IAAQ;IAAa;CAAQ,CAAA;AAE/G;;;CAGC,GACD,OAAO,MAAMC,0BAA6C;IAAC;OAAWD;CAAsB,CAAA;AAE5F,kFAAkF,GAClF,OAAO,MAAME,yBAAyB,UAAS;AAe/C,0CAA0C,GAC1C,SAASC,WAAWC,QAA2B;IAC7C,OAAOA,SAASC,IAAI;AACtB;AAEA,kEAAkE,GAClE,SAASC,WAAWC,IAAiB;QAKhBA;IAJnB,MAAMC,QAAQ,IAAIC;IAClBF,KAAKG,MAAM,CAACC,OAAO,CAAC,CAACP,UAAUQ;QAC7B,IAAIZ,sBAAsBa,QAAQ,CAACT,SAASC,IAAI,GAAGG,MAAMM,GAAG,CAACV,SAASW,IAAI,CAACC,WAAW,IAAI,CAAC,CA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