@aglyn/plugins-ai 1.0.0-beta.143

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 (717) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +25 -0
  3. package/package.json +60 -0
  4. package/src/index.d.ts +21 -0
  5. package/src/index.js +22 -0
  6. package/src/index.js.map +1 -0
  7. package/src/lib/activity/ai-activity-actions.d.ts +106 -0
  8. package/src/lib/activity/ai-activity-actions.js +209 -0
  9. package/src/lib/activity/ai-activity-actions.js.map +1 -0
  10. package/src/lib/activity/ai-activity.d.ts +219 -0
  11. package/src/lib/activity/ai-activity.js +251 -0
  12. package/src/lib/activity/ai-activity.js.map +1 -0
  13. package/src/lib/billing/ai-overage-charge.d.ts +102 -0
  14. package/src/lib/billing/ai-overage-charge.js +258 -0
  15. package/src/lib/billing/ai-overage-charge.js.map +1 -0
  16. package/src/lib/billing/ai-overage-close.d.ts +62 -0
  17. package/src/lib/billing/ai-overage-close.js +129 -0
  18. package/src/lib/billing/ai-overage-close.js.map +1 -0
  19. package/src/lib/billing/ai-overage-cutover.d.ts +63 -0
  20. package/src/lib/billing/ai-overage-cutover.js +114 -0
  21. package/src/lib/billing/ai-overage-cutover.js.map +1 -0
  22. package/src/lib/billing/ai-overage-events.d.ts +77 -0
  23. package/src/lib/billing/ai-overage-events.js +174 -0
  24. package/src/lib/billing/ai-overage-events.js.map +1 -0
  25. package/src/lib/billing/ai-overage-gate.d.ts +147 -0
  26. package/src/lib/billing/ai-overage-gate.js +177 -0
  27. package/src/lib/billing/ai-overage-gate.js.map +1 -0
  28. package/src/lib/billing/ai-overage-ledger.d.ts +135 -0
  29. package/src/lib/billing/ai-overage-ledger.js +278 -0
  30. package/src/lib/billing/ai-overage-ledger.js.map +1 -0
  31. package/src/lib/billing/ai-overage-standing-writes.d.ts +110 -0
  32. package/src/lib/billing/ai-overage-standing-writes.js +205 -0
  33. package/src/lib/billing/ai-overage-standing-writes.js.map +1 -0
  34. package/src/lib/billing/ai-overage-standing.d.ts +168 -0
  35. package/src/lib/billing/ai-overage-standing.js +215 -0
  36. package/src/lib/billing/ai-overage-standing.js.map +1 -0
  37. package/src/lib/billing/ai-overage-trigger.d.ts +30 -0
  38. package/src/lib/billing/ai-overage-trigger.js +76 -0
  39. package/src/lib/billing/ai-overage-trigger.js.map +1 -0
  40. package/src/lib/components/ai-allotment-editor.component.d.ts +40 -0
  41. package/src/lib/components/ai-allotment-editor.component.js +213 -0
  42. package/src/lib/components/ai-allotment-editor.component.js.map +1 -0
  43. package/src/lib/components/ai-assist-actions-context.d.ts +13 -0
  44. package/src/lib/components/ai-assist-actions-context.js +21 -0
  45. package/src/lib/components/ai-assist-actions-context.js.map +1 -0
  46. package/src/lib/components/ai-assist-provider.component.d.ts +51 -0
  47. package/src/lib/components/ai-assist-provider.component.js +519 -0
  48. package/src/lib/components/ai-assist-provider.component.js.map +1 -0
  49. package/src/lib/components/ai-brief-dialog.component.d.ts +56 -0
  50. package/src/lib/components/ai-brief-dialog.component.js +319 -0
  51. package/src/lib/components/ai-brief-dialog.component.js.map +1 -0
  52. package/src/lib/components/ai-collaborator-permissions-column.component.d.ts +32 -0
  53. package/src/lib/components/ai-collaborator-permissions-column.component.js +132 -0
  54. package/src/lib/components/ai-collaborator-permissions-column.component.js.map +1 -0
  55. package/src/lib/components/ai-credits-card.component.d.ts +34 -0
  56. package/src/lib/components/ai-credits-card.component.js +131 -0
  57. package/src/lib/components/ai-credits-card.component.js.map +1 -0
  58. package/src/lib/components/ai-credits-columns.component.d.ts +56 -0
  59. package/src/lib/components/ai-credits-columns.component.js +118 -0
  60. package/src/lib/components/ai-credits-columns.component.js.map +1 -0
  61. package/src/lib/components/ai-crm-email-draft.component.d.ts +17 -0
  62. package/src/lib/components/ai-crm-email-draft.component.js +159 -0
  63. package/src/lib/components/ai-crm-email-draft.component.js.map +1 -0
  64. package/src/lib/components/ai-crm-import-mapping.component.d.ts +20 -0
  65. package/src/lib/components/ai-crm-import-mapping.component.js +167 -0
  66. package/src/lib/components/ai-crm-import-mapping.component.js.map +1 -0
  67. package/src/lib/components/ai-crm-record-card.component.d.ts +27 -0
  68. package/src/lib/components/ai-crm-record-card.component.js +263 -0
  69. package/src/lib/components/ai-crm-record-card.component.js.map +1 -0
  70. package/src/lib/components/ai-describe-automation.component.d.ts +31 -0
  71. package/src/lib/components/ai-describe-automation.component.js +226 -0
  72. package/src/lib/components/ai-describe-automation.component.js.map +1 -0
  73. package/src/lib/components/ai-describe-button.component.d.ts +39 -0
  74. package/src/lib/components/ai-describe-button.component.js +87 -0
  75. package/src/lib/components/ai-describe-button.component.js.map +1 -0
  76. package/src/lib/components/ai-describe-page.component.d.ts +26 -0
  77. package/src/lib/components/ai-describe-page.component.js +18 -0
  78. package/src/lib/components/ai-describe-page.component.js.map +1 -0
  79. package/src/lib/components/ai-experiment-cards.component.d.ts +75 -0
  80. package/src/lib/components/ai-experiment-cards.component.js +573 -0
  81. package/src/lib/components/ai-experiment-cards.component.js.map +1 -0
  82. package/src/lib/components/ai-explain-automation.component.d.ts +31 -0
  83. package/src/lib/components/ai-explain-automation.component.js +265 -0
  84. package/src/lib/components/ai-explain-automation.component.js.map +1 -0
  85. package/src/lib/components/ai-insight-dialog.component.d.ts +37 -0
  86. package/src/lib/components/ai-insight-dialog.component.js +441 -0
  87. package/src/lib/components/ai-insight-dialog.component.js.map +1 -0
  88. package/src/lib/components/ai-job-plan.component.d.ts +46 -0
  89. package/src/lib/components/ai-job-plan.component.js +192 -0
  90. package/src/lib/components/ai-job-plan.component.js.map +1 -0
  91. package/src/lib/components/ai-model-selector.component.d.ts +21 -0
  92. package/src/lib/components/ai-model-selector.component.js +109 -0
  93. package/src/lib/components/ai-model-selector.component.js.map +1 -0
  94. package/src/lib/components/ai-page-brief-dialog.component.d.ts +29 -0
  95. package/src/lib/components/ai-page-brief-dialog.component.js +27 -0
  96. package/src/lib/components/ai-page-brief-dialog.component.js.map +1 -0
  97. package/src/lib/components/ai-permissions-on-host.component.d.ts +55 -0
  98. package/src/lib/components/ai-permissions-on-host.component.js +91 -0
  99. package/src/lib/components/ai-permissions-on-host.component.js.map +1 -0
  100. package/src/lib/components/ai-product-copy-card.component.d.ts +25 -0
  101. package/src/lib/components/ai-product-copy-card.component.js +328 -0
  102. package/src/lib/components/ai-product-copy-card.component.js.map +1 -0
  103. package/src/lib/components/ai-product-import-option.component.d.ts +14 -0
  104. package/src/lib/components/ai-product-import-option.component.js +58 -0
  105. package/src/lib/components/ai-product-import-option.component.js.map +1 -0
  106. package/src/lib/components/ai-products-hub-card.component.d.ts +15 -0
  107. package/src/lib/components/ai-products-hub-card.component.js +418 -0
  108. package/src/lib/components/ai-products-hub-card.component.js.map +1 -0
  109. package/src/lib/components/ai-products-proposals.component.d.ts +19 -0
  110. package/src/lib/components/ai-products-proposals.component.js +547 -0
  111. package/src/lib/components/ai-products-proposals.component.js.map +1 -0
  112. package/src/lib/components/ai-save-as-component.component.d.ts +38 -0
  113. package/src/lib/components/ai-save-as-component.component.js +231 -0
  114. package/src/lib/components/ai-save-as-component.component.js.map +1 -0
  115. package/src/lib/components/ai-seo-audit-card.component.d.ts +9 -0
  116. package/src/lib/components/ai-seo-audit-card.component.js +620 -0
  117. package/src/lib/components/ai-seo-audit-card.component.js.map +1 -0
  118. package/src/lib/components/ai-seo-fields-card.component.d.ts +10 -0
  119. package/src/lib/components/ai-seo-fields-card.component.js +453 -0
  120. package/src/lib/components/ai-seo-fields-card.component.js.map +1 -0
  121. package/src/lib/components/ai-site-batch-card.component.d.ts +32 -0
  122. package/src/lib/components/ai-site-batch-card.component.js +531 -0
  123. package/src/lib/components/ai-site-batch-card.component.js.map +1 -0
  124. package/src/lib/components/ai-site-seo-start-card.component.d.ts +26 -0
  125. package/src/lib/components/ai-site-seo-start-card.component.js +178 -0
  126. package/src/lib/components/ai-site-seo-start-card.component.js.map +1 -0
  127. package/src/lib/components/ai-site-start-card.component.d.ts +19 -0
  128. package/src/lib/components/ai-site-start-card.component.js +348 -0
  129. package/src/lib/components/ai-site-start-card.component.js.map +1 -0
  130. package/src/lib/components/ai-template-collection-field.component.d.ts +32 -0
  131. package/src/lib/components/ai-template-collection-field.component.js +63 -0
  132. package/src/lib/components/ai-template-collection-field.component.js.map +1 -0
  133. package/src/lib/components/ai-theme-proposal-card.component.d.ts +6 -0
  134. package/src/lib/components/ai-theme-proposal-card.component.js +619 -0
  135. package/src/lib/components/ai-theme-proposal-card.component.js.map +1 -0
  136. package/src/lib/components/ai-usage-strip.component.d.ts +27 -0
  137. package/src/lib/components/ai-usage-strip.component.js +145 -0
  138. package/src/lib/components/ai-usage-strip.component.js.map +1 -0
  139. package/src/lib/components/assist-edit-canvas.d.ts +169 -0
  140. package/src/lib/components/assist-edit-canvas.js +636 -0
  141. package/src/lib/components/assist-edit-canvas.js.map +1 -0
  142. package/src/lib/components/assist-edit-card.component.d.ts +16 -0
  143. package/src/lib/components/assist-edit-card.component.js +181 -0
  144. package/src/lib/components/assist-edit-card.component.js.map +1 -0
  145. package/src/lib/components/assist-jobs-drawer.component.d.ts +72 -0
  146. package/src/lib/components/assist-jobs-drawer.component.js +626 -0
  147. package/src/lib/components/assist-jobs-drawer.component.js.map +1 -0
  148. package/src/lib/components/assist-panel.component.d.ts +136 -0
  149. package/src/lib/components/assist-panel.component.js +1099 -0
  150. package/src/lib/components/assist-panel.component.js.map +1 -0
  151. package/src/lib/components/assist-signals-page.component.d.ts +3 -0
  152. package/src/lib/components/assist-signals-page.component.js +1017 -0
  153. package/src/lib/components/assist-signals-page.component.js.map +1 -0
  154. package/src/lib/components/besigner-ai-controls.component.d.ts +29 -0
  155. package/src/lib/components/besigner-ai-controls.component.js +81 -0
  156. package/src/lib/components/besigner-ai-controls.component.js.map +1 -0
  157. package/src/lib/components/billing-ai-allotments.component.d.ts +36 -0
  158. package/src/lib/components/billing-ai-allotments.component.js +486 -0
  159. package/src/lib/components/billing-ai-allotments.component.js.map +1 -0
  160. package/src/lib/components/billing-ai-top-users.component.d.ts +44 -0
  161. package/src/lib/components/billing-ai-top-users.component.js +304 -0
  162. package/src/lib/components/billing-ai-top-users.component.js.map +1 -0
  163. package/src/lib/components/billing-assist-overage-card.component.d.ts +69 -0
  164. package/src/lib/components/billing-assist-overage-card.component.js +437 -0
  165. package/src/lib/components/billing-assist-overage-card.component.js.map +1 -0
  166. package/src/lib/components/host-ai-allotments.component.d.ts +40 -0
  167. package/src/lib/components/host-ai-allotments.component.js +239 -0
  168. package/src/lib/components/host-ai-allotments.component.js.map +1 -0
  169. package/src/lib/components/member-ai-allotment-card.component.d.ts +28 -0
  170. package/src/lib/components/member-ai-allotment-card.component.js +172 -0
  171. package/src/lib/components/member-ai-allotment-card.component.js.map +1 -0
  172. package/src/lib/components/member-ai-usage-card.component.d.ts +28 -0
  173. package/src/lib/components/member-ai-usage-card.component.js +240 -0
  174. package/src/lib/components/member-ai-usage-card.component.js.map +1 -0
  175. package/src/lib/components/staff-org-ai-card.component.d.ts +17 -0
  176. package/src/lib/components/staff-org-ai-card.component.js +739 -0
  177. package/src/lib/components/staff-org-ai-card.component.js.map +1 -0
  178. package/src/lib/components/staff-org-usage-ai-columns.component.d.ts +41 -0
  179. package/src/lib/components/staff-org-usage-ai-columns.component.js +65 -0
  180. package/src/lib/components/staff-org-usage-ai-columns.component.js.map +1 -0
  181. package/src/lib/components/staff-orgs-ai-spend-column.component.d.ts +28 -0
  182. package/src/lib/components/staff-orgs-ai-spend-column.component.js +89 -0
  183. package/src/lib/components/staff-orgs-ai-spend-column.component.js.map +1 -0
  184. package/src/lib/components/staff-user-ai-usage-card.component.d.ts +27 -0
  185. package/src/lib/components/staff-user-ai-usage-card.component.js +183 -0
  186. package/src/lib/components/staff-user-ai-usage-card.component.js.map +1 -0
  187. package/src/lib/components/use-ai-allotments.d.ts +49 -0
  188. package/src/lib/components/use-ai-allotments.js +171 -0
  189. package/src/lib/components/use-ai-allotments.js.map +1 -0
  190. package/src/lib/components/use-ai-crm-answer.d.ts +50 -0
  191. package/src/lib/components/use-ai-crm-answer.js +220 -0
  192. package/src/lib/components/use-ai-crm-answer.js.map +1 -0
  193. package/src/lib/components/use-ai-job-run.d.ts +51 -0
  194. package/src/lib/components/use-ai-job-run.js +176 -0
  195. package/src/lib/components/use-ai-job-run.js.map +1 -0
  196. package/src/lib/components/use-ai-model-choice.d.ts +47 -0
  197. package/src/lib/components/use-ai-model-choice.js +150 -0
  198. package/src/lib/components/use-ai-model-choice.js.map +1 -0
  199. package/src/lib/components/use-ai-products-jobs.d.ts +36 -0
  200. package/src/lib/components/use-ai-products-jobs.js +190 -0
  201. package/src/lib/components/use-ai-products-jobs.js.map +1 -0
  202. package/src/lib/components/use-ai-usage-meter.d.ts +11 -0
  203. package/src/lib/components/use-ai-usage-meter.js +96 -0
  204. package/src/lib/components/use-ai-usage-meter.js.map +1 -0
  205. package/src/lib/components/use-org-ai-usage.d.ts +42 -0
  206. package/src/lib/components/use-org-ai-usage.js +181 -0
  207. package/src/lib/components/use-org-ai-usage.js.map +1 -0
  208. package/src/lib/components/use-staff-orgs-ai-spend.d.ts +18 -0
  209. package/src/lib/components/use-staff-orgs-ai-spend.js +127 -0
  210. package/src/lib/components/use-staff-orgs-ai-spend.js.map +1 -0
  211. package/src/lib/constants.d.ts +24 -0
  212. package/src/lib/constants.js +23 -0
  213. package/src/lib/constants.js.map +1 -0
  214. package/src/lib/declarations.d.ts +48 -0
  215. package/src/lib/declarations.js +129 -0
  216. package/src/lib/declarations.js.map +1 -0
  217. package/src/lib/declarations.server.d.ts +35 -0
  218. package/src/lib/declarations.server.js +138 -0
  219. package/src/lib/declarations.server.js.map +1 -0
  220. package/src/lib/insights/ai-figure-readers.d.ts +90 -0
  221. package/src/lib/insights/ai-figure-readers.js +863 -0
  222. package/src/lib/insights/ai-figure-readers.js.map +1 -0
  223. package/src/lib/insights/ai-insight-digest.d.ts +165 -0
  224. package/src/lib/insights/ai-insight-digest.js +363 -0
  225. package/src/lib/insights/ai-insight-digest.js.map +1 -0
  226. package/src/lib/insights/ai-insight-readers.d.ts +71 -0
  227. package/src/lib/insights/ai-insight-readers.js +141 -0
  228. package/src/lib/insights/ai-insight-readers.js.map +1 -0
  229. package/src/lib/jobs/ai-crm-access.d.ts +61 -0
  230. package/src/lib/jobs/ai-crm-access.js +94 -0
  231. package/src/lib/jobs/ai-crm-access.js.map +1 -0
  232. package/src/lib/jobs/ai-email-bindings.d.ts +97 -0
  233. package/src/lib/jobs/ai-email-bindings.js +147 -0
  234. package/src/lib/jobs/ai-email-bindings.js.map +1 -0
  235. package/src/lib/jobs/ai-job-admission.d.ts +82 -0
  236. package/src/lib/jobs/ai-job-admission.js +45 -0
  237. package/src/lib/jobs/ai-job-admission.js.map +1 -0
  238. package/src/lib/jobs/ai-job-budget.d.ts +167 -0
  239. package/src/lib/jobs/ai-job-budget.js +161 -0
  240. package/src/lib/jobs/ai-job-budget.js.map +1 -0
  241. package/src/lib/jobs/ai-job-campaign-step.d.ts +108 -0
  242. package/src/lib/jobs/ai-job-campaign-step.js +340 -0
  243. package/src/lib/jobs/ai-job-campaign-step.js.map +1 -0
  244. package/src/lib/jobs/ai-job-component-checks.d.ts +74 -0
  245. package/src/lib/jobs/ai-job-component-checks.js +442 -0
  246. package/src/lib/jobs/ai-job-component-checks.js.map +1 -0
  247. package/src/lib/jobs/ai-job-component-step.d.ts +75 -0
  248. package/src/lib/jobs/ai-job-component-step.js +262 -0
  249. package/src/lib/jobs/ai-job-component-step.js.map +1 -0
  250. package/src/lib/jobs/ai-job-crm-step.d.ts +192 -0
  251. package/src/lib/jobs/ai-job-crm-step.js +734 -0
  252. package/src/lib/jobs/ai-job-crm-step.js.map +1 -0
  253. package/src/lib/jobs/ai-job-draft-ids.d.ts +62 -0
  254. package/src/lib/jobs/ai-job-draft-ids.js +132 -0
  255. package/src/lib/jobs/ai-job-draft-ids.js.map +1 -0
  256. package/src/lib/jobs/ai-job-drafts.d.ts +304 -0
  257. package/src/lib/jobs/ai-job-drafts.js +557 -0
  258. package/src/lib/jobs/ai-job-drafts.js.map +1 -0
  259. package/src/lib/jobs/ai-job-email-step.d.ts +195 -0
  260. package/src/lib/jobs/ai-job-email-step.js +547 -0
  261. package/src/lib/jobs/ai-job-email-step.js.map +1 -0
  262. package/src/lib/jobs/ai-job-experiment-step.d.ts +105 -0
  263. package/src/lib/jobs/ai-job-experiment-step.js +445 -0
  264. package/src/lib/jobs/ai-job-experiment-step.js.map +1 -0
  265. package/src/lib/jobs/ai-job-form-step.d.ts +250 -0
  266. package/src/lib/jobs/ai-job-form-step.js +634 -0
  267. package/src/lib/jobs/ai-job-form-step.js.map +1 -0
  268. package/src/lib/jobs/ai-job-generation.d.ts +114 -0
  269. package/src/lib/jobs/ai-job-generation.js +384 -0
  270. package/src/lib/jobs/ai-job-generation.js.map +1 -0
  271. package/src/lib/jobs/ai-job-insight-budget.d.ts +41 -0
  272. package/src/lib/jobs/ai-job-insight-budget.js +46 -0
  273. package/src/lib/jobs/ai-job-insight-budget.js.map +1 -0
  274. package/src/lib/jobs/ai-job-insight-step.d.ts +58 -0
  275. package/src/lib/jobs/ai-job-insight-step.js +350 -0
  276. package/src/lib/jobs/ai-job-insight-step.js.map +1 -0
  277. package/src/lib/jobs/ai-job-layout-step.d.ts +103 -0
  278. package/src/lib/jobs/ai-job-layout-step.js +340 -0
  279. package/src/lib/jobs/ai-job-layout-step.js.map +1 -0
  280. package/src/lib/jobs/ai-job-page-budget.d.ts +57 -0
  281. package/src/lib/jobs/ai-job-page-budget.js +60 -0
  282. package/src/lib/jobs/ai-job-page-budget.js.map +1 -0
  283. package/src/lib/jobs/ai-job-page-sections.d.ts +150 -0
  284. package/src/lib/jobs/ai-job-page-sections.js +450 -0
  285. package/src/lib/jobs/ai-job-page-sections.js.map +1 -0
  286. package/src/lib/jobs/ai-job-page-step.d.ts +198 -0
  287. package/src/lib/jobs/ai-job-page-step.js +667 -0
  288. package/src/lib/jobs/ai-job-page-step.js.map +1 -0
  289. package/src/lib/jobs/ai-job-plan-conformance.d.ts +107 -0
  290. package/src/lib/jobs/ai-job-plan-conformance.js +164 -0
  291. package/src/lib/jobs/ai-job-plan-conformance.js.map +1 -0
  292. package/src/lib/jobs/ai-job-plan-step.d.ts +196 -0
  293. package/src/lib/jobs/ai-job-plan-step.js +458 -0
  294. package/src/lib/jobs/ai-job-plan-step.js.map +1 -0
  295. package/src/lib/jobs/ai-job-plugin-drafts.d.ts +76 -0
  296. package/src/lib/jobs/ai-job-plugin-drafts.js +91 -0
  297. package/src/lib/jobs/ai-job-plugin-drafts.js.map +1 -0
  298. package/src/lib/jobs/ai-job-products-step.d.ts +106 -0
  299. package/src/lib/jobs/ai-job-products-step.js +436 -0
  300. package/src/lib/jobs/ai-job-products-step.js.map +1 -0
  301. package/src/lib/jobs/ai-job-seo-budget.d.ts +52 -0
  302. package/src/lib/jobs/ai-job-seo-budget.js +63 -0
  303. package/src/lib/jobs/ai-job-seo-budget.js.map +1 -0
  304. package/src/lib/jobs/ai-job-seo-step.d.ts +145 -0
  305. package/src/lib/jobs/ai-job-seo-step.js +809 -0
  306. package/src/lib/jobs/ai-job-seo-step.js.map +1 -0
  307. package/src/lib/jobs/ai-job-site-step.d.ts +252 -0
  308. package/src/lib/jobs/ai-job-site-step.js +538 -0
  309. package/src/lib/jobs/ai-job-site-step.js.map +1 -0
  310. package/src/lib/jobs/ai-job-template-step.d.ts +105 -0
  311. package/src/lib/jobs/ai-job-template-step.js +391 -0
  312. package/src/lib/jobs/ai-job-template-step.js.map +1 -0
  313. package/src/lib/jobs/ai-job-text-step.d.ts +125 -0
  314. package/src/lib/jobs/ai-job-text-step.js +128 -0
  315. package/src/lib/jobs/ai-job-text-step.js.map +1 -0
  316. package/src/lib/jobs/ai-job-theme-budget.d.ts +38 -0
  317. package/src/lib/jobs/ai-job-theme-budget.js +43 -0
  318. package/src/lib/jobs/ai-job-theme-budget.js.map +1 -0
  319. package/src/lib/jobs/ai-job-theme-step.d.ts +115 -0
  320. package/src/lib/jobs/ai-job-theme-step.js +337 -0
  321. package/src/lib/jobs/ai-job-theme-step.js.map +1 -0
  322. package/src/lib/jobs/ai-job-workflow-step.d.ts +139 -0
  323. package/src/lib/jobs/ai-job-workflow-step.js +530 -0
  324. package/src/lib/jobs/ai-job-workflow-step.js.map +1 -0
  325. package/src/lib/jobs/ai-jobs-beat.d.ts +78 -0
  326. package/src/lib/jobs/ai-jobs-beat.js +93 -0
  327. package/src/lib/jobs/ai-jobs-beat.js.map +1 -0
  328. package/src/lib/jobs/ai-jobs-pause.d.ts +38 -0
  329. package/src/lib/jobs/ai-jobs-pause.js +45 -0
  330. package/src/lib/jobs/ai-jobs-pause.js.map +1 -0
  331. package/src/lib/jobs/ai-jobs.d.ts +558 -0
  332. package/src/lib/jobs/ai-jobs.js +1410 -0
  333. package/src/lib/jobs/ai-jobs.js.map +1 -0
  334. package/src/lib/jobs/ai-media-asset-server.d.ts +34 -0
  335. package/src/lib/jobs/ai-media-asset-server.js +34 -0
  336. package/src/lib/jobs/ai-media-asset-server.js.map +1 -0
  337. package/src/lib/jobs/ai-media-asset.d.ts +59 -0
  338. package/src/lib/jobs/ai-media-asset.js +86 -0
  339. package/src/lib/jobs/ai-media-asset.js.map +1 -0
  340. package/src/lib/jobs/ai-product-image.d.ts +78 -0
  341. package/src/lib/jobs/ai-product-image.js +113 -0
  342. package/src/lib/jobs/ai-product-image.js.map +1 -0
  343. package/src/lib/jobs/ai-theme-brand-inputs.d.ts +125 -0
  344. package/src/lib/jobs/ai-theme-brand-inputs.js +378 -0
  345. package/src/lib/jobs/ai-theme-brand-inputs.js.map +1 -0
  346. package/src/lib/jobs/ai-theme-brand-server.d.ts +33 -0
  347. package/src/lib/jobs/ai-theme-brand-server.js +33 -0
  348. package/src/lib/jobs/ai-theme-brand-server.js.map +1 -0
  349. package/src/lib/jobs/ai-workflow-records.d.ts +84 -0
  350. package/src/lib/jobs/ai-workflow-records.js +158 -0
  351. package/src/lib/jobs/ai-workflow-records.js.map +1 -0
  352. package/src/lib/jobs/fixtures/ai-free-page-built-recording.d.ts +31 -0
  353. package/src/lib/jobs/fixtures/ai-free-page-built-recording.js +367 -0
  354. package/src/lib/jobs/fixtures/ai-free-page-built-recording.js.map +1 -0
  355. package/src/lib/jobs/fixtures/ai-free-page-recording.d.ts +69 -0
  356. package/src/lib/jobs/fixtures/ai-free-page-recording.js +442 -0
  357. package/src/lib/jobs/fixtures/ai-free-page-recording.js.map +1 -0
  358. package/src/lib/jobs/fixtures/ai-page-briefs.d.ts +146 -0
  359. package/src/lib/jobs/fixtures/ai-page-briefs.js +1850 -0
  360. package/src/lib/jobs/fixtures/ai-page-briefs.js.map +1 -0
  361. package/src/lib/model/ai-allotments.d.ts +208 -0
  362. package/src/lib/model/ai-allotments.js +269 -0
  363. package/src/lib/model/ai-allotments.js.map +1 -0
  364. package/src/lib/model/ai-automation-draft.d.ts +74 -0
  365. package/src/lib/model/ai-automation-draft.js +310 -0
  366. package/src/lib/model/ai-automation-draft.js.map +1 -0
  367. package/src/lib/model/ai-automation-outline.d.ts +50 -0
  368. package/src/lib/model/ai-automation-outline.js +262 -0
  369. package/src/lib/model/ai-automation-outline.js.map +1 -0
  370. package/src/lib/model/ai-build-plan.d.ts +197 -0
  371. package/src/lib/model/ai-build-plan.js +438 -0
  372. package/src/lib/model/ai-build-plan.js.map +1 -0
  373. package/src/lib/model/ai-crm.d.ts +237 -0
  374. package/src/lib/model/ai-crm.js +225 -0
  375. package/src/lib/model/ai-crm.js.map +1 -0
  376. package/src/lib/model/ai-experiment-proposal.d.ts +68 -0
  377. package/src/lib/model/ai-experiment-proposal.js +146 -0
  378. package/src/lib/model/ai-experiment-proposal.js.map +1 -0
  379. package/src/lib/model/ai-experiment.d.ts +309 -0
  380. package/src/lib/model/ai-experiment.js +395 -0
  381. package/src/lib/model/ai-experiment.js.map +1 -0
  382. package/src/lib/model/ai-insight.d.ts +178 -0
  383. package/src/lib/model/ai-insight.js +201 -0
  384. package/src/lib/model/ai-insight.js.map +1 -0
  385. package/src/lib/model/ai-jobs.types.d.ts +412 -0
  386. package/src/lib/model/ai-jobs.types.js +42 -0
  387. package/src/lib/model/ai-jobs.types.js.map +1 -0
  388. package/src/lib/model/ai-page-job.d.ts +92 -0
  389. package/src/lib/model/ai-page-job.js +159 -0
  390. package/src/lib/model/ai-page-job.js.map +1 -0
  391. package/src/lib/model/ai-permissions.d.ts +49 -0
  392. package/src/lib/model/ai-permissions.js +97 -0
  393. package/src/lib/model/ai-permissions.js.map +1 -0
  394. package/src/lib/model/ai-plan-capabilities.d.ts +139 -0
  395. package/src/lib/model/ai-plan-capabilities.js +149 -0
  396. package/src/lib/model/ai-plan-capabilities.js.map +1 -0
  397. package/src/lib/model/ai-products.d.ts +251 -0
  398. package/src/lib/model/ai-products.js +253 -0
  399. package/src/lib/model/ai-products.js.map +1 -0
  400. package/src/lib/model/ai-seo.d.ts +208 -0
  401. package/src/lib/model/ai-seo.js +150 -0
  402. package/src/lib/model/ai-seo.js.map +1 -0
  403. package/src/lib/model/ai-site-inventory.d.ts +164 -0
  404. package/src/lib/model/ai-site-inventory.js +145 -0
  405. package/src/lib/model/ai-site-inventory.js.map +1 -0
  406. package/src/lib/model/ai-site-job.d.ts +247 -0
  407. package/src/lib/model/ai-site-job.js +314 -0
  408. package/src/lib/model/ai-site-job.js.map +1 -0
  409. package/src/lib/model/ai-site-start-seo.d.ts +103 -0
  410. package/src/lib/model/ai-site-start-seo.js +154 -0
  411. package/src/lib/model/ai-site-start-seo.js.map +1 -0
  412. package/src/lib/model/ai-site-start.d.ts +122 -0
  413. package/src/lib/model/ai-site-start.js +159 -0
  414. package/src/lib/model/ai-site-start.js.map +1 -0
  415. package/src/lib/model/ai-site-switch.d.ts +56 -0
  416. package/src/lib/model/ai-site-switch.js +73 -0
  417. package/src/lib/model/ai-site-switch.js.map +1 -0
  418. package/src/lib/model/ai-storefront-claims.d.ts +70 -0
  419. package/src/lib/model/ai-storefront-claims.js +130 -0
  420. package/src/lib/model/ai-storefront-claims.js.map +1 -0
  421. package/src/lib/model/ai-template-subjects.d.ts +82 -0
  422. package/src/lib/model/ai-template-subjects.js +136 -0
  423. package/src/lib/model/ai-template-subjects.js.map +1 -0
  424. package/src/lib/model/ai-theme-proposal.d.ts +210 -0
  425. package/src/lib/model/ai-theme-proposal.js +506 -0
  426. package/src/lib/model/ai-theme-proposal.js.map +1 -0
  427. package/src/lib/model/ai-tokens.d.ts +96 -0
  428. package/src/lib/model/ai-tokens.js +117 -0
  429. package/src/lib/model/ai-tokens.js.map +1 -0
  430. package/src/lib/model/ai-usage-by-user.d.ts +120 -0
  431. package/src/lib/model/ai-usage-by-user.js +139 -0
  432. package/src/lib/model/ai-usage-by-user.js.map +1 -0
  433. package/src/lib/model/ai-workflow-job.d.ts +111 -0
  434. package/src/lib/model/ai-workflow-job.js +183 -0
  435. package/src/lib/model/ai-workflow-job.js.map +1 -0
  436. package/src/lib/model/assist-edit.d.ts +261 -0
  437. package/src/lib/model/assist-edit.js +175 -0
  438. package/src/lib/model/assist-edit.js.map +1 -0
  439. package/src/lib/plugin-config.d.ts +33 -0
  440. package/src/lib/plugin-config.js +118 -0
  441. package/src/lib/plugin-config.js.map +1 -0
  442. package/src/lib/plugin.d.ts +30 -0
  443. package/src/lib/plugin.js +525 -0
  444. package/src/lib/plugin.js.map +1 -0
  445. package/src/lib/providers/anthropic.d.ts +84 -0
  446. package/src/lib/providers/anthropic.js +432 -0
  447. package/src/lib/providers/anthropic.js.map +1 -0
  448. package/src/lib/providers/catalog.d.ts +197 -0
  449. package/src/lib/providers/catalog.js +312 -0
  450. package/src/lib/providers/catalog.js.map +1 -0
  451. package/src/lib/providers/contract.d.ts +464 -0
  452. package/src/lib/providers/contract.js +274 -0
  453. package/src/lib/providers/contract.js.map +1 -0
  454. package/src/lib/providers/model-choice.d.ts +119 -0
  455. package/src/lib/providers/model-choice.js +416 -0
  456. package/src/lib/providers/model-choice.js.map +1 -0
  457. package/src/lib/providers/openai-compatible.d.ts +58 -0
  458. package/src/lib/providers/openai-compatible.js +361 -0
  459. package/src/lib/providers/openai-compatible.js.map +1 -0
  460. package/src/lib/providers/registry.d.ts +49 -0
  461. package/src/lib/providers/registry.js +71 -0
  462. package/src/lib/providers/registry.js.map +1 -0
  463. package/src/lib/providers/routing.d.ts +98 -0
  464. package/src/lib/providers/routing.js +450 -0
  465. package/src/lib/providers/routing.js.map +1 -0
  466. package/src/lib/runtime/ai-abuse-guards.d.ts +113 -0
  467. package/src/lib/runtime/ai-abuse-guards.js +148 -0
  468. package/src/lib/runtime/ai-abuse-guards.js.map +1 -0
  469. package/src/lib/runtime/ai-component-bindings.d.ts +67 -0
  470. package/src/lib/runtime/ai-component-bindings.js +106 -0
  471. package/src/lib/runtime/ai-component-bindings.js.map +1 -0
  472. package/src/lib/runtime/ai-device-audit.d.ts +109 -0
  473. package/src/lib/runtime/ai-device-audit.js +97 -0
  474. package/src/lib/runtime/ai-device-audit.js.map +1 -0
  475. package/src/lib/runtime/ai-doctrine-validators.d.ts +720 -0
  476. package/src/lib/runtime/ai-doctrine-validators.js +3133 -0
  477. package/src/lib/runtime/ai-doctrine-validators.js.map +1 -0
  478. package/src/lib/runtime/ai-doctrine.d.ts +372 -0
  479. package/src/lib/runtime/ai-doctrine.js +944 -0
  480. package/src/lib/runtime/ai-doctrine.js.map +1 -0
  481. package/src/lib/runtime/ai-eval-live.d.ts +321 -0
  482. package/src/lib/runtime/ai-eval-live.js +1257 -0
  483. package/src/lib/runtime/ai-eval-live.js.map +1 -0
  484. package/src/lib/runtime/ai-eval-memory-firestore.d.ts +51 -0
  485. package/src/lib/runtime/ai-eval-memory-firestore.js +183 -0
  486. package/src/lib/runtime/ai-eval-memory-firestore.js.map +1 -0
  487. package/src/lib/runtime/ai-eval.d.ts +441 -0
  488. package/src/lib/runtime/ai-eval.js +1151 -0
  489. package/src/lib/runtime/ai-eval.js.map +1 -0
  490. package/src/lib/runtime/ai-gate.d.ts +130 -0
  491. package/src/lib/runtime/ai-gate.js +272 -0
  492. package/src/lib/runtime/ai-gate.js.map +1 -0
  493. package/src/lib/runtime/ai-generation-bounds.d.ts +24 -0
  494. package/src/lib/runtime/ai-generation-bounds.js +23 -0
  495. package/src/lib/runtime/ai-generation-bounds.js.map +1 -0
  496. package/src/lib/runtime/ai-insight-check.d.ts +76 -0
  497. package/src/lib/runtime/ai-insight-check.js +281 -0
  498. package/src/lib/runtime/ai-insight-check.js.map +1 -0
  499. package/src/lib/runtime/ai-node-tree.d.ts +181 -0
  500. package/src/lib/runtime/ai-node-tree.js +931 -0
  501. package/src/lib/runtime/ai-node-tree.js.map +1 -0
  502. package/src/lib/runtime/ai-page-links.d.ts +79 -0
  503. package/src/lib/runtime/ai-page-links.js +135 -0
  504. package/src/lib/runtime/ai-page-links.js.map +1 -0
  505. package/src/lib/runtime/ai-palette.d.ts +252 -0
  506. package/src/lib/runtime/ai-palette.generated.d.ts +34 -0
  507. package/src/lib/runtime/ai-palette.generated.js +5263 -0
  508. package/src/lib/runtime/ai-palette.generated.js.map +1 -0
  509. package/src/lib/runtime/ai-palette.js +187 -0
  510. package/src/lib/runtime/ai-palette.js.map +1 -0
  511. package/src/lib/runtime/ai-products-generation.d.ts +107 -0
  512. package/src/lib/runtime/ai-products-generation.js +250 -0
  513. package/src/lib/runtime/ai-products-generation.js.map +1 -0
  514. package/src/lib/runtime/ai-repeated-items.d.ts +95 -0
  515. package/src/lib/runtime/ai-repeated-items.js +397 -0
  516. package/src/lib/runtime/ai-repeated-items.js.map +1 -0
  517. package/src/lib/runtime/ai-runtime.d.ts +148 -0
  518. package/src/lib/runtime/ai-runtime.js +237 -0
  519. package/src/lib/runtime/ai-runtime.js.map +1 -0
  520. package/src/lib/runtime/ai-template-examples.d.ts +71 -0
  521. package/src/lib/runtime/ai-template-examples.js +135 -0
  522. package/src/lib/runtime/ai-template-examples.js.map +1 -0
  523. package/src/lib/runtime/assist-answer-cache.d.ts +80 -0
  524. package/src/lib/runtime/assist-answer-cache.js +184 -0
  525. package/src/lib/runtime/assist-answer-cache.js.map +1 -0
  526. package/src/lib/runtime/seo-audit.d.ts +93 -0
  527. package/src/lib/runtime/seo-audit.js +260 -0
  528. package/src/lib/runtime/seo-audit.js.map +1 -0
  529. package/src/lib/runtime/seo-content-fixes.d.ts +41 -0
  530. package/src/lib/runtime/seo-content-fixes.js +168 -0
  531. package/src/lib/runtime/seo-content-fixes.js.map +1 -0
  532. package/src/lib/runtime/seo-fields.d.ts +152 -0
  533. package/src/lib/runtime/seo-fields.js +215 -0
  534. package/src/lib/runtime/seo-fields.js.map +1 -0
  535. package/src/lib/runtime/seo-page-facts.d.ts +61 -0
  536. package/src/lib/runtime/seo-page-facts.js +150 -0
  537. package/src/lib/runtime/seo-page-facts.js.map +1 -0
  538. package/src/lib/runtime/site-inventory.d.ts +63 -0
  539. package/src/lib/runtime/site-inventory.js +230 -0
  540. package/src/lib/runtime/site-inventory.js.map +1 -0
  541. package/src/lib/server/ai-admin-org.d.ts +33 -0
  542. package/src/lib/server/ai-admin-org.js +381 -0
  543. package/src/lib/server/ai-admin-org.js.map +1 -0
  544. package/src/lib/server/ai-admin-orgs-spend.d.ts +40 -0
  545. package/src/lib/server/ai-admin-orgs-spend.js +129 -0
  546. package/src/lib/server/ai-admin-orgs-spend.js.map +1 -0
  547. package/src/lib/server/ai-admin-overage.d.ts +19 -0
  548. package/src/lib/server/ai-admin-overage.js +246 -0
  549. package/src/lib/server/ai-admin-overage.js.map +1 -0
  550. package/src/lib/server/ai-admin-signals.d.ts +34 -0
  551. package/src/lib/server/ai-admin-signals.js +330 -0
  552. package/src/lib/server/ai-admin-signals.js.map +1 -0
  553. package/src/lib/server/ai-admin-user.d.ts +27 -0
  554. package/src/lib/server/ai-admin-user.js +128 -0
  555. package/src/lib/server/ai-admin-user.js.map +1 -0
  556. package/src/lib/server/ai-allotments.d.ts +27 -0
  557. package/src/lib/server/ai-allotments.js +544 -0
  558. package/src/lib/server/ai-allotments.js.map +1 -0
  559. package/src/lib/server/ai-assist-prompts.d.ts +102 -0
  560. package/src/lib/server/ai-assist-prompts.js +207 -0
  561. package/src/lib/server/ai-assist-prompts.js.map +1 -0
  562. package/src/lib/server/ai-assist.d.ts +119 -0
  563. package/src/lib/server/ai-assist.js +517 -0
  564. package/src/lib/server/ai-assist.js.map +1 -0
  565. package/src/lib/server/ai-crm-answer.d.ts +30 -0
  566. package/src/lib/server/ai-crm-answer.js +98 -0
  567. package/src/lib/server/ai-crm-answer.js.map +1 -0
  568. package/src/lib/server/ai-generate-component.d.ts +111 -0
  569. package/src/lib/server/ai-generate-component.js +643 -0
  570. package/src/lib/server/ai-generate-component.js.map +1 -0
  571. package/src/lib/server/ai-host-permissions.d.ts +46 -0
  572. package/src/lib/server/ai-host-permissions.js +204 -0
  573. package/src/lib/server/ai-host-permissions.js.map +1 -0
  574. package/src/lib/server/ai-insight-answer.d.ts +30 -0
  575. package/src/lib/server/ai-insight-answer.js +83 -0
  576. package/src/lib/server/ai-insight-answer.js.map +1 -0
  577. package/src/lib/server/ai-insight-digest-route.d.ts +30 -0
  578. package/src/lib/server/ai-insight-digest-route.js +156 -0
  579. package/src/lib/server/ai-insight-digest-route.js.map +1 -0
  580. package/src/lib/server/ai-jobs-batch.d.ts +48 -0
  581. package/src/lib/server/ai-jobs-batch.js +306 -0
  582. package/src/lib/server/ai-jobs-batch.js.map +1 -0
  583. package/src/lib/server/ai-jobs-beat-route.d.ts +36 -0
  584. package/src/lib/server/ai-jobs-beat-route.js +86 -0
  585. package/src/lib/server/ai-jobs-beat-route.js.map +1 -0
  586. package/src/lib/server/ai-jobs-cancel.d.ts +30 -0
  587. package/src/lib/server/ai-jobs-cancel.js +74 -0
  588. package/src/lib/server/ai-jobs-cancel.js.map +1 -0
  589. package/src/lib/server/ai-jobs-events-route.d.ts +31 -0
  590. package/src/lib/server/ai-jobs-events-route.js +51 -0
  591. package/src/lib/server/ai-jobs-events-route.js.map +1 -0
  592. package/src/lib/server/ai-jobs-events.d.ts +55 -0
  593. package/src/lib/server/ai-jobs-events.js +144 -0
  594. package/src/lib/server/ai-jobs-events.js.map +1 -0
  595. package/src/lib/server/ai-jobs-gate.d.ts +47 -0
  596. package/src/lib/server/ai-jobs-gate.js +106 -0
  597. package/src/lib/server/ai-jobs-gate.js.map +1 -0
  598. package/src/lib/server/ai-jobs-resume.d.ts +23 -0
  599. package/src/lib/server/ai-jobs-resume.js +209 -0
  600. package/src/lib/server/ai-jobs-resume.js.map +1 -0
  601. package/src/lib/server/ai-jobs-route.d.ts +32 -0
  602. package/src/lib/server/ai-jobs-route.js +307 -0
  603. package/src/lib/server/ai-jobs-route.js.map +1 -0
  604. package/src/lib/server/ai-models.d.ts +18 -0
  605. package/src/lib/server/ai-models.js +134 -0
  606. package/src/lib/server/ai-models.js.map +1 -0
  607. package/src/lib/server/ai-seo-apply.d.ts +53 -0
  608. package/src/lib/server/ai-seo-apply.js +294 -0
  609. package/src/lib/server/ai-seo-apply.js.map +1 -0
  610. package/src/lib/server/ai-usage.d.ts +18 -0
  611. package/src/lib/server/ai-usage.js +220 -0
  612. package/src/lib/server/ai-usage.js.map +1 -0
  613. package/src/lib/server/assist-chat.d.ts +234 -0
  614. package/src/lib/server/assist-chat.js +1446 -0
  615. package/src/lib/server/assist-chat.js.map +1 -0
  616. package/src/lib/server/assist-edit-applied.d.ts +22 -0
  617. package/src/lib/server/assist-edit-applied.js +239 -0
  618. package/src/lib/server/assist-edit-applied.js.map +1 -0
  619. package/src/lib/server/assist-edit.d.ts +124 -0
  620. package/src/lib/server/assist-edit.js +1000 -0
  621. package/src/lib/server/assist-edit.js.map +1 -0
  622. package/src/lib/server/assist-feedback.d.ts +31 -0
  623. package/src/lib/server/assist-feedback.js +115 -0
  624. package/src/lib/server/assist-feedback.js.map +1 -0
  625. package/src/lib/server/assist-view-context.d.ts +343 -0
  626. package/src/lib/server/assist-view-context.js +690 -0
  627. package/src/lib/server/assist-view-context.js.map +1 -0
  628. package/src/lib/server/billing-credits.d.ts +59 -0
  629. package/src/lib/server/billing-credits.js +146 -0
  630. package/src/lib/server/billing-credits.js.map +1 -0
  631. package/src/lib/server/billing-overage.d.ts +19 -0
  632. package/src/lib/server/billing-overage.js +337 -0
  633. package/src/lib/server/billing-overage.js.map +1 -0
  634. package/src/lib/server.d.ts +32 -0
  635. package/src/lib/server.js +265 -0
  636. package/src/lib/server.js.map +1 -0
  637. package/src/lib/subprocessors.d.ts +18 -0
  638. package/src/lib/subprocessors.js +52 -0
  639. package/src/lib/subprocessors.js.map +1 -0
  640. package/src/lib/tools/ai-component-tool.d.ts +99 -0
  641. package/src/lib/tools/ai-component-tool.js +369 -0
  642. package/src/lib/tools/ai-component-tool.js.map +1 -0
  643. package/src/lib/tools/ai-crm-tool.d.ts +106 -0
  644. package/src/lib/tools/ai-crm-tool.js +488 -0
  645. package/src/lib/tools/ai-crm-tool.js.map +1 -0
  646. package/src/lib/tools/ai-duplicate-resource-tool.d.ts +71 -0
  647. package/src/lib/tools/ai-duplicate-resource-tool.js +164 -0
  648. package/src/lib/tools/ai-duplicate-resource-tool.js.map +1 -0
  649. package/src/lib/tools/ai-experiment-tool.d.ts +40 -0
  650. package/src/lib/tools/ai-experiment-tool.js +155 -0
  651. package/src/lib/tools/ai-experiment-tool.js.map +1 -0
  652. package/src/lib/tools/ai-insight-tool.d.ts +46 -0
  653. package/src/lib/tools/ai-insight-tool.js +200 -0
  654. package/src/lib/tools/ai-insight-tool.js.map +1 -0
  655. package/src/lib/tools/ai-inventory-lookup-tool.d.ts +86 -0
  656. package/src/lib/tools/ai-inventory-lookup-tool.js +164 -0
  657. package/src/lib/tools/ai-inventory-lookup-tool.js.map +1 -0
  658. package/src/lib/tools/ai-products-tool.d.ts +65 -0
  659. package/src/lib/tools/ai-products-tool.js +644 -0
  660. package/src/lib/tools/ai-products-tool.js.map +1 -0
  661. package/src/lib/tools/ai-seo-tool.d.ts +162 -0
  662. package/src/lib/tools/ai-seo-tool.js +546 -0
  663. package/src/lib/tools/ai-seo-tool.js.map +1 -0
  664. package/src/lib/tools/ai-theme-tool.d.ts +101 -0
  665. package/src/lib/tools/ai-theme-tool.js +562 -0
  666. package/src/lib/tools/ai-theme-tool.js.map +1 -0
  667. package/src/lib/tools/ai-workflow-tool.d.ts +166 -0
  668. package/src/lib/tools/ai-workflow-tool.js +860 -0
  669. package/src/lib/tools/ai-workflow-tool.js.map +1 -0
  670. package/src/lib/usage/ai-allotment-alerts.d.ts +72 -0
  671. package/src/lib/usage/ai-allotment-alerts.js +157 -0
  672. package/src/lib/usage/ai-allotment-alerts.js.map +1 -0
  673. package/src/lib/usage/ai-allotments.d.ts +125 -0
  674. package/src/lib/usage/ai-allotments.js +239 -0
  675. package/src/lib/usage/ai-allotments.js.map +1 -0
  676. package/src/lib/usage/ai-model-sample.d.ts +36 -0
  677. package/src/lib/usage/ai-model-sample.js +68 -0
  678. package/src/lib/usage/ai-model-sample.js.map +1 -0
  679. package/src/lib/usage/ai-usage-alerts.d.ts +55 -0
  680. package/src/lib/usage/ai-usage-alerts.js +114 -0
  681. package/src/lib/usage/ai-usage-alerts.js.map +1 -0
  682. package/src/lib/usage/ai-usage-by-user.d.ts +161 -0
  683. package/src/lib/usage/ai-usage-by-user.js +211 -0
  684. package/src/lib/usage/ai-usage-by-user.js.map +1 -0
  685. package/src/lib/usage/ai-usage-eraser.d.ts +29 -0
  686. package/src/lib/usage/ai-usage-eraser.js +40 -0
  687. package/src/lib/usage/ai-usage-eraser.js.map +1 -0
  688. package/src/lib/usage/ai-usage-meter.d.ts +39 -0
  689. package/src/lib/usage/ai-usage-meter.js +85 -0
  690. package/src/lib/usage/ai-usage-meter.js.map +1 -0
  691. package/src/lib/usage/ai-usage-wire.d.ts +184 -0
  692. package/src/lib/usage/ai-usage-wire.js +98 -0
  693. package/src/lib/usage/ai-usage-wire.js.map +1 -0
  694. package/src/lib/usage/assist-ceiling.d.ts +87 -0
  695. package/src/lib/usage/assist-ceiling.js +110 -0
  696. package/src/lib/usage/assist-ceiling.js.map +1 -0
  697. package/src/lib/usage/assist-free-taste.d.ts +225 -0
  698. package/src/lib/usage/assist-free-taste.js +308 -0
  699. package/src/lib/usage/assist-free-taste.js.map +1 -0
  700. package/src/lib/usage/assist-refusals.d.ts +69 -0
  701. package/src/lib/usage/assist-refusals.js +79 -0
  702. package/src/lib/usage/assist-refusals.js.map +1 -0
  703. package/src/lib/usage/assist-signal-mining.d.ts +375 -0
  704. package/src/lib/usage/assist-signal-mining.js +344 -0
  705. package/src/lib/usage/assist-signal-mining.js.map +1 -0
  706. package/src/lib/usage/assist-usage.d.ts +571 -0
  707. package/src/lib/usage/assist-usage.js +978 -0
  708. package/src/lib/usage/assist-usage.js.map +1 -0
  709. package/src/lib/usage/staff-org-ai.d.ts +242 -0
  710. package/src/lib/usage/staff-org-ai.js +173 -0
  711. package/src/lib/usage/staff-org-ai.js.map +1 -0
  712. package/src/lib/usage/staff-org-usage-ai.d.ts +83 -0
  713. package/src/lib/usage/staff-org-usage-ai.js +59 -0
  714. package/src/lib/usage/staff-org-usage-ai.js.map +1 -0
  715. package/src/lib/usage/staff-orgs-ai-spend.d.ts +83 -0
  716. package/src/lib/usage/staff-orgs-ai-spend.js +114 -0
  717. package/src/lib/usage/staff-orgs-ai-spend.js.map +1 -0
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/runtime/ai-doctrine.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 type { NodesMap } from '@aglyn/aglyn/types/nodes'\nimport { parseAiBuildPlan, type AiBuildPlan } from '../model/ai-build-plan'\nimport type { AiPlanCapabilities } from '../model/ai-plan-capabilities'\nimport {\n AI_INVENTORY_KINDS,\n AI_INVENTORY_KIND_HEADINGS,\n AI_SITE_INVENTORY_LISTED_PER_KIND,\n AI_SITE_INVENTORY_MAX_CHARS,\n aiHomeScreenIds,\n aiInventoryLine,\n aiInventoryRows,\n type AiInventoryKind,\n type AiSiteInventory,\n} from '../model/ai-site-inventory'\nimport type { AiStepKind } from '../providers/catalog'\nimport { aiCutOffFigures, aiStoppedAtCeiling, type AiProvider } from '../providers/contract'\nimport { AI_ROUTING_TABLE, aiModelForStep, type AiPluginSettings } from '../providers/routing'\nimport {\n AI_ACCEPTABLE_USE_BLOCK,\n runAiRequest,\n type AiCompletion,\n type AiEffort,\n type AiMessage,\n type AiSystemBlock,\n type AiThinking,\n type AiTool,\n type AiUsage,\n} from './ai-runtime'\nimport {\n AI_SIMILAR_PAGES_MIN,\n aiDoctrineViolationText,\n detectPublishIntent,\n validateAiBuildPlan,\n validateAiDoctrineTree,\n type AiCopyFraming,\n type AiDoctrineTree,\n type AiDoctrineTreeContext,\n type AiDoctrineViolation,\n type AiOutputScore,\n} from './ai-doctrine-validators'\nimport {\n AI_INVENTORY_LOOKUP_MAX_ROUNDS,\n AI_INVENTORY_LOOKUP_TOOL_NAME,\n aiInventoryLookupTool,\n answerAiInventoryLookup,\n} from '../tools/ai-inventory-lookup-tool'\nimport { AI_GENERATION_MAX_ATTEMPTS } from './ai-generation-bounds'\nimport type { AiNodeTreeContext } from './ai-node-tree'\nimport {\n AI_OUTPUT_BUDGETS,\n AI_OUTPUT_KINDS,\n AI_OUTPUT_SURFACE,\n type AiLoadEstimate,\n type AiOutputKind,\n type AiSurface,\n} from './ai-palette'\nimport { AI_PALETTE_CATALOG } from './ai-palette.generated'\n\n/**\n * The building doctrine (AGL-2935): the one place the procedures a generator\n * follows live, and the one loop every generator runs them through.\n *\n * A page with the same card twelve times, a header pasted on every screen, a\n * form drawn inline, a hex color in an `sx`: each is what a careless author\n * does, and the AI must never do it. So no generator carries its own copy of\n * the rules. It hands its instructions, its tool and the brief to\n * `runValidatedGeneration(kind, …)`, which\n *\n * 1. prefixes the doctrine as a CACHED system block — byte-identical for\n * every org, so it is one cache entry for the platform — then the door's\n * own instructions, then the palette catalog for the output's surface,\n * and last the site inventory as a VOLATILE block, the one per-site part;\n * 2. calls the runtime once, reads the answer off the tool, and holds it to\n * the doctrine's validators (`ai-doctrine-validators.ts`) — the doctrine\n * always runs for a kind it knows, and a door can only ADD checks;\n * 2a. answers, from the window already in memory, a turn that asked to look\n * a record up rather than answering (AGL-2937): a site larger than its\n * prompt block can list is found by asking, not by listing more on every\n * request. Bounded, and not an answer attempt;\n * 3. on a violation, asks ONCE more with the broken rules named and the\n * offending parts quoted — never the whole document again (AGL-2937);\n * an answer cut off at its output ceiling is asked for smaller instead,\n * whatever its truncated input made the check say (AGL-3042);\n * 4. and when the second answer still breaks a rule, gives up with\n * `needs_input`: a person decides, rather than a loop spending on the\n * same refusal.\n *\n * Tokens from every attempt are summed on the result, so the caller meters\n * what was actually spent. Nothing here writes a document or publishes.\n *\n * A door whose answer streams to its reader as it arrives — the chat door's\n * edit rung — has no turn left to re-ask in once the answer can be read, so\n * it holds what arrived to the same check through\n * `validateStreamedGeneration`, and composes its own prompt around\n * `aiDoctrineCatalog`, the catalog this loop shows a surface.\n */\n\n// ── The doctrine block ───────────────────────────────────────────────────\n\nfunction kilobytes(bytes: number): string {\n return bytes >= 1_000_000\n ? `${(bytes / 1_000_000).toLocaleString('en-US', { maximumFractionDigits: 1 })} MB`\n : `${Math.round(bytes / 1_000)} KB`\n}\n\nfunction budgetLine(kind: AiOutputKind): string {\n const budget = AI_OUTPUT_BUDGETS[kind]\n const parts = [\n `${budget.nodes} elements`,\n `${kilobytes(budget.bytes)} stored`,\n budget.imageBytes ? `${kilobytes(budget.imageBytes)} of images` : 'no images',\n budget.embeds ? `${budget.embeds} embed` : 'no embeds',\n ]\n if (budget.emailHtmlBytes) parts.push(`${kilobytes(budget.emailHtmlBytes)} of rendered HTML`)\n return `${/^[aeiou]/.test(kind) ? 'an' : 'a'} ${kind} at most ${parts.join(', ')}`\n}\n\n/**\n * What a generation kind produces, and therefore which of the rules below can\n * bind it (AGL-2937).\n *\n * The seventeen rules are written for a kind that composes a DOCUMENT: they\n * name nodes, instances, layouts, slugs and budgets. A kind that produces\n * short fields a door checks itself — a page's search listing, an audit's\n * fixes — can break exactly one of them, and the other sixteen are bytes it\n * pays for on every attempt without ever being held to them. On a fast-tier\n * model, whose cached-prefix minimum no SEO prompt reaches, those bytes are\n * billed at full input rate every single time.\n *\n * Sending fewer rules is not only cheaper here, it is more accurate: rule 14\n * tells a writer to mark a fact it lacks in square brackets, which is right\n * for page copy a person edits before publishing and wrong for a search title\n * that is published exactly as written — and the SEO doors' own rules already\n * say to write only from the text they were given.\n */\nexport type AiDoctrineScope =\n /** A document the palette composes, or a plan for them: all seventeen rules. */\n | 'documents'\n /** Values a door reads and checks itself, composing nothing. */\n | 'fields'\n\n/** One numbered rule, and the scopes it binds. */\ninterface AiDoctrineRuleText {\n /**\n * The rule's number, which the re-ask and every violation name. It is fixed\n * to the rule and not to its position, so a scope that renders a subset\n * still calls rule 13 rule 13.\n */\n n: number\n scopes: readonly AiDoctrineScope[]\n text: string\n}\n\nconst DOCUMENTS: readonly AiDoctrineScope[] = ['documents']\nconst EVERY_SCOPE: readonly AiDoctrineScope[] = ['documents', 'fields']\n\nconst AI_DOCTRINE_RULE_TEXT: readonly AiDoctrineRuleText[] = [\n { n: 1, scopes: DOCUMENTS, text: 'Repeats become one reusable component. A block with the same elements and props that differs only in its copy, links or images, appearing 3 or more times on a page or on 2 pages built together, is one reusable component with typed props, placed as instances: a \"reusableInstance\" node whose \"refId\" names the component and whose \"propValues\" fill its props. Search the site inventory first, and never create a component that duplicates one listed there; reuse it, or propose extending it. Where the request says the workspace keeps no reusable components, draw the block each time it repeats instead.' },\n { n: 2, scopes: DOCUMENTS, text: 'Site-wide regions live in the layout. A header, navigation, footer, announcement bar or cookie notice belongs in a layout. Every screen declares the site\\'s layout, or one the plan creates, and never carries its own copy of a layout region.' },\n { n: 3, scopes: DOCUMENTS, text: 'Forms are built on the Forms page, then placed. A form is created there with its fields, validation, consent and routing, and a page places a \"form\" element bound by its \"formId\", with no fields drawn inside it. Where the request says the workspace keeps no saved forms, the page carries the form itself: a \"form\" element with no \"formId\", holding its \"formField\" elements. Never draw loose form fields on a page. Search is a \"searchBox\" or a collection\\'s \"collectionSearch\", never a form, which collects submissions.' },\n { n: 4, scopes: DOCUMENTS, text: `Similar pages share one template. When ${AI_SIMILAR_PAGES_MIN} or more pages share one structure and differ by copy or data (products, locations, team members, services), plan one template and apply it once per page, or bind it to a collection when the data exists. Fewer than ${AI_SIMILAR_PAGES_MIN} is not a template.` },\n { n: 5, scopes: DOCUMENTS, text: 'Colors, spacing and type come from the theme. Use palette tokens such as \"primary.main\", \"text.secondary\" and \"background.paper\", plain numbers on the spacing scale, the theme\\'s shape and its typography variants. Never write a hex, rgb or named color, or a px, rem or em length. A color the theme lacks is a theme change in the plan, never a value on an element.' },\n { n: 6, scopes: DOCUMENTS, text: 'Emails use the brand. An email uses only the brand colors and fonts the site inventory lists, and a campaign starts from an email template rather than a one-off design.' },\n { n: 7, scopes: DOCUMENTS, text: 'Reuse before creating. Prefer what the site inventory lists: components, layouts, templates, forms, themes, datasets, collections and screens, referenced by id. Creating is the exception, and every creation says why nothing listed will do. In a plan, refer to something the plan itself creates as new:<name>, and create only what the request says this job may create on this site.' },\n { n: 8, scopes: DOCUMENTS, text: 'Data is bound, not typed. A list that exists as a dataset, collection, product or record is bound to it and never copied into text; a long list the site lacks becomes a dataset in the plan.' },\n { n: 9, scopes: DOCUMENTS, text: 'Images come from the media library, with alt text. Place images by media reference, or leave \"src\" empty for an upload; never link an image from another website. Every image has alt text describing it, or \"decorative\": true.' },\n { n: 10, scopes: DOCUMENTS, text: 'Navigation and SEO travel with a page. Every new screen has a slug of lowercase words joined by hyphens that the site does not already use, a search title of at most 70 characters, a search description of at most 170, and a navigation entry when the brief implies one. A link goes to a screen that does what its words say, or is left out.' },\n { n: 11, scopes: DOCUMENTS, text: 'One main landmark and an ordered outline. A page declares at most one \"main\"; a component, form or email declares none; a layout has exactly one \"layoutSlot\". A page has exactly one h1 and never skips a heading level, and a layout has no h1. Set a heading\\'s level with the Typography \"component\" (h1 to h6).' },\n { n: 12, scopes: DOCUMENTS, text: 'Responsive by the theme\\'s breakpoints. Widths come from a Container\\'s maxWidth, a Grid\\'s size, a percentage, or responsive values keyed by xs, sm, md, lg and xl, never a fixed px or viewport width.' },\n { n: 13, scopes: EVERY_SCOPE, text: 'Drafts only. Everything you produce is a new draft that a person reviews and publishes. Never ask to publish, and never change something already live.' },\n { n: 14, scopes: DOCUMENTS, text: 'The site\\'s voice, with no filler. Write real copy in the tone of the site and the brief, never lorem ipsum or \"your text here\". When the brief lacks a fact such as a phone number, a price or a name, mark it in square brackets instead of inventing it. For agencies and enterprises, never call the work simple, cheap or effortless.' },\n { n: 15, scopes: DOCUMENTS, text: 'Start from a duplicate of the nearest thing. When the site has a similar screen, template or email, plan a duplicate of it and edit that, which keeps its versions, bindings and SEO.' },\n { n: 16, scopes: DOCUMENTS, text: 'The smallest document that does the job. Build the flattest tree that renders the design: no container wrapping a single container, no empty containers, no inline style repeated across elements, text as text, images lazy below the first, video by poster and click-to-play, no fonts beyond the theme\\'s, and no third-party embed or script unless the brief asks for it and the plan names its cost.' },\n { n: 17, scopes: DOCUMENTS, text: `A measured budget for every output. Each document is measured and refused over its budget: ${AI_OUTPUT_KINDS.map(budgetLine).join('; ')}.` },\n]\n\n/** How a scope opens: what the rules under it are for. */\nconst SCOPE_OPENING: Readonly<Record<AiDoctrineScope, string>> = {\n documents:\n 'How to build on this platform. Every plan and every document you produce is checked against these rules; an answer that breaks one is refused and asked for again with the rule named.',\n fields:\n 'An answer that breaks one of these rules is refused and asked for again with the rule named.',\n}\n\n/**\n * How a scope closes. The document scope names the tool generically because\n * every generator it serves is handed a different one; the field doors name\n * their own tool in their own rules, so repeating it here would be the same\n * sentence twice.\n */\nconst SCOPE_CLOSING: Readonly<Record<AiDoctrineScope, string | null>> = {\n documents:\n 'Answer through the tool you are given, and only through it.',\n fields: null,\n}\n\n/**\n * The procedures in the model's terms, for one scope. Static text only: the\n * budgets are read from `AI_OUTPUT_BUDGETS` once, at load, so a scope's text\n * is the same bytes on every request and changes only when a budget does.\n */\nexport function aiBuildingDoctrine(scope: AiDoctrineScope): string {\n const closing = SCOPE_CLOSING[scope]\n return [\n SCOPE_OPENING[scope],\n '',\n ...AI_DOCTRINE_RULE_TEXT.filter((rule) => rule.scopes.includes(scope)).map(\n (rule) => `${rule.n}. ${rule.text}`,\n ),\n ...(closing ? ['', closing] : []),\n ].join('\\n')\n}\n\n/** Every rule, as the kinds that compose a document are told them. */\nexport const AI_BUILDING_DOCTRINE = aiBuildingDoctrine('documents')\n\n/**\n * The doctrine as the cached system block, one per scope: the procedures and\n * the platform's acceptable-use rules (AGL-2925), which every generation\n * prompt carries and which ride here so a generator cannot leave them out.\n *\n * The acceptable-use rules are in EVERY scope, whole. They are the platform's\n * abuse guard rather than a building rule, a published title can carry a scam\n * claim as easily as a page can, and a scope that dropped them to save bytes\n * would be trading the thing this issue is forbidden to trade.\n *\n * Built once, at load, so a scope's block is the same object and the same\n * bytes on every request: two workspaces on one door share one cache entry,\n * and `runtime/ai-prompt-cache.spec.ts` holds them to it.\n */\nconst AI_DOCTRINE_SCOPE_BLOCKS: Readonly<Record<AiDoctrineScope, AiSystemBlock>> = {\n documents: {\n text: `${aiBuildingDoctrine('documents')}\\n\\n${AI_ACCEPTABLE_USE_BLOCK}`,\n cacheBreakpoint: true,\n },\n fields: {\n text: `${aiBuildingDoctrine('fields')}\\n\\n${AI_ACCEPTABLE_USE_BLOCK}`,\n cacheBreakpoint: true,\n },\n}\n\n/** The doctrine block a kind that composes a document is sent. */\nexport const AI_DOCTRINE_SYSTEM_BLOCK: AiSystemBlock = AI_DOCTRINE_SCOPE_BLOCKS.documents\n\n/** The doctrine block for one scope. */\nexport function aiDoctrineSystemBlock(scope: AiDoctrineScope): AiSystemBlock {\n return AI_DOCTRINE_SCOPE_BLOCKS[scope]\n}\n\n/**\n * The scope a generation kind is told the rules in. A kind absent from this\n * map composes a document and is told all seventeen — the three SEO kinds are\n * the only ones today that write values instead, and a new kind that does the\n * same names itself here rather than paying for rules it cannot break.\n */\nexport const AI_DOCTRINE_KIND_SCOPE: Readonly<Record<string, AiDoctrineScope>> = {\n 'seo-fields': 'fields',\n 'seo-site': 'fields',\n 'seo-fixes': 'fields',\n // CRM by AI (AGL-2917): a record's summary, an email draft, an import's\n // column matches — values the CRM's own forms take, composing nothing.\n 'crm-email': 'fields',\n 'crm-mapping': 'fields',\n 'crm-record': 'fields',\n}\n\n/** The scope for a kind; `documents` unless the kind names another. */\nexport function aiDoctrineScopeFor(kind: string): AiDoctrineScope {\n return AI_DOCTRINE_KIND_SCOPE[kind] ?? 'documents'\n}\n\n// ── The inventory block ──────────────────────────────────────────────────\n\n/**\n * The inventory as the prompt's VOLATILE block: per site, so it never sits\n * inside a cached prefix. Held to `AI_SITE_INVENTORY_MAX_CHARS` by cutting\n * the longest kind a line at a time, each cut kind named, so no one kind can\n * crowd the others out.\n *\n * It lists `AI_SITE_INVENTORY_LISTED_PER_KIND` records of each kind, not the\n * whole window the reader holds (AGL-2937): the block is billed at full input\n * rate on every attempt, so a large site would spend most of a plan's prompt\n * on rows it will not use. A kind with more — cut by the listing cap or by\n * the read itself — is named as having more, and the sentence points at the\n * lookup tool the loop offers beside the door's own, so the answer to \"is\n * there already a pricing card?\" is a question the model can ask rather than\n * a gap it fills by creating one.\n */\nexport function aiSiteInventoryBlock(inventory: AiSiteInventory | null): string {\n if (!inventory) {\n return 'Site inventory: none was read for this request. Reuse nothing by id, and name every creation as new.'\n }\n // Only the first rows of each kind are listed; the rest are held for the\n // lookup tool, and a kind cut by either the listing cap or the read is\n // named as having more.\n const lines = Object.fromEntries(\n AI_INVENTORY_KINDS.map((kind) => [\n kind,\n aiInventoryRows(inventory, kind)\n .slice(0, AI_SITE_INVENTORY_LISTED_PER_KIND)\n .map((row) => aiInventoryLine(kind, row)),\n ]),\n ) as Record<AiInventoryKind, string[]>\n const truncated = new Set([\n ...inventory.truncated,\n ...AI_INVENTORY_KINDS.filter(\n (kind) => aiInventoryRows(inventory, kind).length > AI_SITE_INVENTORY_LISTED_PER_KIND,\n ),\n ])\n const render = (): string => {\n const parts = [\n 'Site inventory: what this site already has. Reuse these by id before creating anything.',\n ]\n for (const kind of AI_INVENTORY_KINDS) {\n parts.push(`${AI_INVENTORY_KIND_HEADINGS[kind]}:`)\n parts.push(...(lines[kind].length ? lines[kind].map((line) => `- ${line}`) : ['- none']))\n }\n if (inventory.theme) {\n parts.push(`Theme: ${inventory.theme.summary.join('; ') || 'the platform default'}.`)\n const colors = Object.entries(inventory.theme.colors)\n .map(([path, value]) => `${path}=${value}`)\n .join(', ')\n if (colors) parts.push(`Brand colors (light scheme): ${colors}`)\n if (inventory.theme.fonts.length) {\n parts.push(`Brand fonts: ${inventory.theme.fonts.join(', ')}`)\n }\n }\n if (truncated.size) {\n parts.push(\n `More exist than are listed for: ${AI_INVENTORY_KINDS.filter((kind) => truncated.has(kind)).join(', ')}. Do not assume one is missing because it is not listed — call ${AI_INVENTORY_LOOKUP_TOOL_NAME} to find it.`,\n )\n }\n return parts.join('\\n')\n }\n let block = render()\n while (block.length > AI_SITE_INVENTORY_MAX_CHARS) {\n const longest = AI_INVENTORY_KINDS.reduce((a, b) =>\n lines[b].length > lines[a].length ? b : a,\n )\n if (!lines[longest].length) break\n lines[longest] = lines[longest].slice(0, -1)\n truncated.add(longest)\n block = render()\n }\n return block.length > AI_SITE_INVENTORY_MAX_CHARS\n ? block.slice(0, AI_SITE_INVENTORY_MAX_CHARS)\n : block\n}\n\n/** What a tree generated against this inventory may reference, for `validateAiNodeTree`. */\nexport function aiNodeTreeContextFromInventory(\n inventory: AiSiteInventory | null,\n): AiNodeTreeContext {\n if (!inventory) return {}\n return {\n screenIds: inventory.screens.map((screen) => screen.id),\n componentIds: inventory.components.map((component) => component.id),\n componentProps: Object.fromEntries(\n inventory.components.map((component) => [component.id, component.props]),\n ),\n formIds: inventory.forms.map((form) => form.id),\n datasetIds: inventory.datasets.map((dataset) => dataset.id),\n }\n}\n\nexport interface AiDoctrineSystemOptions {\n /** The door's own static instructions, cached after the doctrine. */\n instructions?: readonly AiSystemBlock[]\n /** The palette surface a tree is composed on; its catalog is cached after the instructions. */\n surface?: AiSurface\n /** Which rules the doctrine block states; `documents` when the door names none. */\n scope?: AiDoctrineScope\n}\n\n/**\n * The palette catalog a generation on this surface is shown: the elements the\n * surface allows, the props each takes and the named blocks to imitate. The\n * one reader of it, so a door that composes its own prompt shows the model\n * the catalog the loop below shows it.\n */\nexport function aiDoctrineCatalog(surface: AiSurface): string {\n return AI_PALETTE_CATALOG[surface]\n}\n\n/**\n * The system prompt every generator sends, in cache order: the doctrine\n * (cached), the door's instructions, the surface's palette catalog (cached),\n * then the site inventory (volatile). With no catalog behind them, the\n * instructions close the cached prefix themselves. The runtime refuses the\n * request if a door slips a volatile block inside the cached span.\n *\n * `null` is a site whose inventory was not read, and the model is told so;\n * `undefined` is a kind that builds from no site structure at all — a theme\n * builds from the theme — and sends no inventory block.\n */\nexport function aiDoctrineSystemBlocks(\n inventory: AiSiteInventory | null | undefined,\n options: AiDoctrineSystemOptions = {},\n): AiSystemBlock[] {\n const instructions = [...(options.instructions ?? [])]\n const catalog: AiSystemBlock[] = options.surface\n ? [{ text: aiDoctrineCatalog(options.surface), cacheBreakpoint: true }]\n : []\n const last = instructions.length - 1\n if (\n !catalog.length &&\n last >= 0 &&\n !instructions[last].volatile &&\n !instructions.some((block) => block.cacheBreakpoint)\n ) {\n instructions[last] = { ...instructions[last], cacheBreakpoint: true }\n }\n return [\n aiDoctrineSystemBlock(options.scope ?? 'documents'),\n ...instructions,\n ...catalog,\n ...(inventory === undefined\n ? []\n : [{ text: aiSiteInventoryBlock(inventory), volatile: true as const }]),\n ]\n}\n\n// ── Reading and checking an answer ───────────────────────────────────────\n\n/** What a generation kind is: a document the palette composes, a plan, or a door's own kind. */\nexport type AiGenerationKind = AiOutputKind | 'plan'\n\n/**\n * `max_tokens` per kind (AGL-2937): the ceiling of one answer, sized to the\n * kind's budget with room for the model's reasoning. A kind a door brings\n * with its own check takes `AI_CUSTOM_GENERATION_MAX_TOKENS` unless the door\n * names its own.\n */\nexport const AI_GENERATION_MAX_TOKENS: Record<AiGenerationKind, number> = {\n plan: AI_ROUTING_TABLE['job.plan'].maxTokens,\n page: 32_000,\n template: 32_000,\n component: 8_000,\n layout: 12_000,\n form: 6_000,\n email: 16_000,\n}\n\nexport const AI_CUSTOM_GENERATION_MAX_TOKENS = 8_000\n\n/** One answer, and one re-ask with the violations named. */\nexport { AI_GENERATION_MAX_ATTEMPTS }\n\n/** How much of the offending parts a re-ask quotes. */\nexport const AI_REASK_OFFENDING_MAX_CHARS = 6_000\n\nexport function isAiOutputKind(kind: string): kind is AiOutputKind {\n return (AI_OUTPUT_KINDS as readonly string[]).includes(kind)\n}\n\n/** What one check made of one answer. */\nexport interface AiGenerationCheckResult<T> {\n /** The value to keep; `null` when the answer could not be read as one. */\n value: T | null\n violations: AiDoctrineViolation[]\n /** The parts of the answer at fault, keyed as the model wrote them, for the re-ask. */\n offending?: Record<string, unknown>\n}\n\nexport type AiGenerationCheck<T> = (\n answer: Record<string, unknown>,\n) => AiGenerationCheckResult<T>\n\n/** A tree that passed the palette validator and every doctrine rule. */\nexport interface AiValidatedTree {\n rootId: string\n nodes: NodesMap\n /** What the palette validator dropped or normalized on the way in. */\n repairs: string[]\n /** Each minted id → the id the model wrote for that node. */\n sourceIds: Record<string, string>\n score: AiOutputScore\n /** The weight the proposal shows; `null` for an email. */\n load: AiLoadEstimate | null\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value)\n}\n\n/**\n * The strict tool a tree arrives through. The node map rides as JSON text:\n * a map keyed by the model's own node ids has no fixed properties, and a\n * strict schema must close every object it declares.\n */\nexport function aiDoctrineTreeTool(kind: AiOutputKind): AiTool {\n return {\n name: `submit_${kind}`,\n description: `Submit the ${kind} as one flat node map.`,\n strict: true,\n inputSchema: {\n type: 'object',\n additionalProperties: false,\n required: ['tree'],\n properties: {\n tree: {\n type: 'string',\n description:\n 'The node map as JSON: {\"rootId\": \"<id>\", \"nodes\": {\"<id>\": {\"componentId\": \"...\", \"props\": {...}, \"sx\": {...}, \"nodes\": [\"<child id>\", ...]}}}.',\n },\n },\n },\n }\n}\n\n/** The tree a tool answer carries: `tree` as an object or JSON text, else the answer itself. */\nexport function aiAnswerTree(answer: Record<string, unknown>): unknown {\n const tree = answer['tree']\n if (typeof tree === 'string') {\n try {\n return JSON.parse(tree) as unknown\n } catch {\n return tree\n }\n }\n return isRecord(tree) ? tree : answer\n}\n\n/**\n * The answer a completion carries: the named tool's input, or — from a model\n * that answered in text instead — the text as a JSON object.\n */\nfunction answerOf(result: AiCompletion, toolName: string): Record<string, unknown> | null {\n const call = result.toolUse.find((use) => use.name === toolName)\n if (call) return call.input\n const text = result.text.trim()\n const fenced = /```(?:json)?\\s*([\\s\\S]*?)```/.exec(text)?.[1]\n for (const candidate of [text, fenced]) {\n if (!candidate) continue\n try {\n const parsed = JSON.parse(candidate) as unknown\n if (isRecord(parsed)) return parsed\n } catch {\n // Not JSON; the next candidate, or no answer.\n }\n }\n return null\n}\n\n/** A JSON value capped to a character budget, entry by entry. */\nfunction capped(entries: Array<[string, unknown]>): Record<string, unknown> | undefined {\n const out: Record<string, unknown> = {}\n let used = 2\n for (const [key, value] of entries) {\n const size = JSON.stringify(value ?? null).length + key.length + 4\n if (used + size > AI_REASK_OFFENDING_MAX_CHARS) break\n out[key] = value\n used += size\n }\n return Object.keys(out).length ? out : undefined\n}\n\n/** The value at a path such as `screens[1].sections[2]`. */\nfunction valueAtPath(root: unknown, path: string): unknown {\n let value: unknown = root\n for (const part of path.match(/[^.[\\]]+/g) ?? []) {\n if (Array.isArray(value)) value = value[Number(part)]\n else if (isRecord(value)) value = value[part]\n else return undefined\n }\n return value\n}\n\n/**\n * The doctrine's check for a tree kind: the palette validator, every tree\n * rule and the budget, with each offending node reported and quoted by the\n * id the MODEL wrote — the minted ids are ones it never saw.\n */\nexport function aiDoctrineTreeCheck(\n kind: AiOutputKind,\n context: AiDoctrineTreeContext = {},\n otherPages: readonly AiDoctrineTree[] = [],\n): AiGenerationCheck<AiValidatedTree> {\n return (answer) => {\n const input = aiAnswerTree(answer)\n const report = validateAiDoctrineTree(input, kind, context, otherPages)\n if (!report.tree || !report.score) {\n return { value: null, violations: report.violations }\n }\n const { sourceIds } = report.tree\n const violations = report.violations.map((violation) =>\n violation.nodeIds\n ? { ...violation, nodeIds: violation.nodeIds.map((id) => sourceIds[id] ?? id) }\n : violation,\n )\n const rawNodes = isRecord(input) && isRecord(input['nodes']) ? input['nodes'] : {}\n const quoted: Array<[string, unknown]> = []\n const seen = new Set<string>()\n const quote = (id: string) => {\n const node = rawNodes[id]\n if (seen.has(id) || !isRecord(node)) return\n seen.add(id)\n quoted.push([id, node])\n for (const child of Array.isArray(node['nodes']) ? node['nodes'] : []) {\n if (typeof child === 'string') quote(child)\n }\n }\n for (const violation of violations) for (const id of violation.nodeIds ?? []) quote(id)\n return {\n value: {\n rootId: report.tree.rootId,\n nodes: report.tree.nodes,\n repairs: report.tree.repairs,\n sourceIds,\n score: report.score,\n load: report.load,\n },\n violations,\n offending: capped(quoted),\n }\n }\n}\n\n/**\n * The doctrine's check for a plan: its shape, then every plan rule against\n * the inventory and, where the job read them, against what it may create on\n * the site (AGL-3030).\n */\nexport function aiDoctrinePlanCheck(\n inventory: AiSiteInventory | null,\n framing: AiCopyFraming = null,\n capabilities: AiPlanCapabilities | null = null,\n): AiGenerationCheck<AiBuildPlan> {\n return (answer) => {\n const publish = detectPublishIntent(answer)\n const parsed = parseAiBuildPlan(answer)\n if (parsed.ok === false) {\n return {\n value: null,\n violations: [\n {\n rule: null,\n code: 'plan-shape',\n message: 'The answer could not be read as a plan.',\n detail: parsed.error,\n },\n ...publish,\n ],\n }\n }\n const violations = [\n ...publish,\n ...validateAiBuildPlan(parsed.plan, inventory, framing, capabilities),\n ]\n const paths = [...new Set(violations.flatMap((violation) => violation.paths ?? []))]\n return {\n value: parsed.plan,\n violations,\n offending: capped(paths.map((path) => [path, valueAtPath(parsed.plan, path)])),\n }\n }\n}\n\n// ── An answer cut off at its ceiling ─────────────────────────────────────\n\n/** The finding an answer that ran past its output ceiling is refused for (AGL-3042). */\nexport const AI_ANSWER_CUT_OFF_CODE = 'answer-cut-off'\n\n/**\n * Whether a model call stopped at its output ceiling (AGL-3042). The\n * contract owns the predicate, because an adapter reads it to decide whether\n * to keep the call's raw output; the doctrine re-exports it, which is where\n * every door already reads it from.\n */\nexport { aiStoppedAtCeiling }\n\n/**\n * How a door names what it generates, and what makes it smaller, for an\n * answer cut off at its ceiling (AGL-3042).\n */\nexport interface AiGenerationCutOff {\n /** What a person calls the output: `section` reads \"This section was too large to build in one pass.\" */\n noun: string\n /**\n * What the re-ask tells the model makes an answer of this kind smaller, in\n * its own sentence: a section's element budget, shorter copy, a repeated\n * item placed as an instance.\n */\n smaller: string\n}\n\n/**\n * The refusal of an answer that ran past its ceiling. The message is what a\n * person reads, so it names the output as they call it and says what helps;\n * the detail is what the model is told makes it smaller. A plan or a palette\n * kind is called by its kind, and any other a door leaves unnamed an answer.\n */\nfunction cutOffAnswer(kind: string, cutOff: AiGenerationCutOff | undefined): AiDoctrineViolation {\n const noun = cutOff?.noun ?? (kind === 'plan' || isAiOutputKind(kind) ? kind : 'answer')\n return {\n rule: null,\n code: AI_ANSWER_CUT_OFF_CODE,\n message: `This ${noun} was too large to build in one pass. Try again, or describe it smaller.`,\n detail: cutOff?.smaller ?? `Build a smaller ${kind}.`,\n }\n}\n\nfunction unreadableAnswer(toolName: string): AiDoctrineViolation {\n return {\n rule: null,\n code: 'answer-unreadable',\n message: `The answer did not come through ${toolName}.`,\n }\n}\n\n/**\n * The re-ask: the rules broken, where, and the offending parts as the model\n * wrote them. An answer cut off at its ceiling is told that first, with what\n * makes it smaller (AGL-3042): it broke no rule it can mend by reading one,\n * and asking for the same answer again is asking to be cut off again.\n */\nexport function aiReaskMessage(\n kind: string,\n toolName: string,\n violations: readonly AiDoctrineViolation[],\n offending?: Record<string, unknown>,\n): string {\n const cutOff = violations.find((violation) => violation.code === AI_ANSWER_CUT_OFF_CODE)\n const broken = cutOff ? violations.filter((violation) => violation !== cutOff) : violations\n const lines = cutOff\n ? [\n `Your ${kind} was not used: it ran past the size one answer may have, and was cut off before it was whole.`,\n ...(cutOff.detail ? [cutOff.detail] : []),\n ...(broken.length ? ['It also breaks these building rules:'] : []),\n ]\n : [`Your ${kind} was not used, because it breaks these building rules:`]\n for (const violation of broken) {\n const where = violation.nodeIds?.length\n ? ` (nodes ${violation.nodeIds.join(', ')})`\n : violation.paths?.length\n ? ` (at ${violation.paths.join(', ')})`\n : ''\n const detail = violation.detail ? ` ${violation.detail}` : ''\n lines.push(`- ${aiDoctrineViolationText(violation)}${detail}${where}`)\n }\n if (offending && Object.keys(offending).length) {\n lines.push('', 'The parts at fault, as you wrote them:', JSON.stringify(offending))\n }\n lines.push(\n '',\n cutOff\n ? `Answer again with ${toolName}: the whole ${kind}, smaller than the one that was cut off${\n broken.length ? ', and built so that none of these rules is broken' : ''\n }.`\n : `Answer again with ${toolName}: the whole ${kind}, built so that none of these rules is broken.`,\n )\n return lines.join('\\n')\n}\n\n/**\n * What a person reads when the second answer still broke a rule. An answer\n * cut off at its ceiling broke none (AGL-3042), so its own sentence is what\n * they read: it was too large, and what helps.\n */\nexport function aiDoctrineNeedsInputMessage(violations: readonly AiDoctrineViolation[]): string {\n const cutOff = violations.find((violation) => violation.code === AI_ANSWER_CUT_OFF_CODE)\n if (cutOff) return cutOff.message\n const first = violations.find((violation) => violation.rule !== null) ?? violations[0]\n if (!first) return 'This could not be built within the building rules.'\n const others = violations.length - 1\n return `This could not be built within the building rules. ${aiDoctrineViolationText(first)}${\n others > 0 ? ` (${others} more ${others === 1 ? 'rule was' : 'rules were'} also broken.)` : ''\n }`\n}\n\n// ── The loop ─────────────────────────────────────────────────────────────\n\ninterface AiGenerationInputBase {\n /**\n * The routing table's step kind: it decides the model (never a model\n * literal) unless `model` names one already resolved. One of the two is\n * required.\n */\n step?: AiStepKind\n /** The org's resolved `pluginSettings/ai`, for its provider and model choices. */\n settings?: AiPluginSettings\n /** A route the door already resolved; the routing table's answer for `step` otherwise. */\n model?: string\n /** The door's own static instructions. */\n instructions: readonly AiSystemBlock[]\n /** The site the output is built for; `null` when none was read. */\n inventory: AiSiteInventory | null\n /** The brief and whatever the door sends in the user turn. */\n messages: readonly AiMessage[]\n /** The strict tool the answer arrives through. */\n tool: AiTool\n /**\n * The ceiling of one answer; `AI_GENERATION_MAX_TOKENS` for the kind when\n * absent. The whole generation — its answers and every lookup round before\n * them — spends at most `AI_GENERATION_MAX_ATTEMPTS` of it (AGL-3036).\n */\n maxTokens?: number\n /**\n * What the output is called, and what makes it smaller, when an answer is\n * cut off at `maxTokens` (AGL-3042). Absent, a plan or a palette kind is\n * called by its kind, any other output an answer, and the model is asked\n * for a smaller one of its kind.\n */\n cutOff?: AiGenerationCutOff\n thinking?: AiThinking\n effort?: AiEffort\n signal?: AbortSignal\n /** A provider chosen ahead of every setting; specs use it. */\n provider?: AiProvider\n}\n\nexport interface AiTreeGenerationInput extends AiGenerationInputBase {\n /** What the tree rules read beyond the inventory: asset sizes, the brand, embeds, framing. */\n context?: AiDoctrineTreeContext\n /** Trees generated beside this one, for rule 1 across pages. */\n otherPages?: readonly AiDoctrineTree[]\n /** Checks the door adds to the doctrine's own, run on a tree the doctrine admitted. */\n extend?: (tree: AiValidatedTree, answer: Record<string, unknown>) => AiDoctrineViolation[]\n}\n\nexport interface AiPlanGenerationInput extends AiGenerationInputBase {\n framing?: AiCopyFraming\n /**\n * What the job may create on its site (AGL-3030). The plan rules refuse a\n * creation outside it, and build inline where the workspace keeps no\n * reusable components; absent, the doctrine applies whole.\n */\n capabilities?: AiPlanCapabilities | null\n /** Checks the door adds to the doctrine's own, run on a plan that parsed. */\n extend?: (plan: AiBuildPlan, answer: Record<string, unknown>) => AiDoctrineViolation[]\n}\n\nexport interface AiCustomGenerationInput<T> extends Omit<AiGenerationInputBase, 'inventory'> {\n /**\n * The site the output is built for, `null` when none was read. A kind that\n * builds from no site structure — a theme builds from the theme — leaves it\n * out, and no inventory block is sent.\n */\n inventory?: AiSiteInventory | null\n /**\n * How a kind the doctrine has no reader for is read and checked — a theme\n * change, an edit. Rule 13 is held on every answer whatever it returns.\n */\n check: AiGenerationCheck<T>\n}\n\n/** What a generation spent, whatever its outcome. */\nexport interface AiGenerationSpend {\n /**\n * Model calls made, all of which the meter bills: one per answer — 2 when\n * the first was re-asked — plus one per site-inventory lookup answered\n * along the way (AGL-2937).\n */\n attempts: number\n /** Tokens across every attempt; the meter bills all of them. */\n usage: AiUsage\n estCostUsd: number\n model: string\n stopReason: string | null\n /** The thinking effort the requests asked for; `null` when they named none. */\n effort: AiEffort | null\n}\n\nexport type AiValidatedGeneration<T> =\n | (AiGenerationSpend & { status: 'ok'; value: T })\n /** The re-ask still broke a rule: a person decides. `message` is customer-safe. */\n | (AiGenerationSpend & {\n status: 'needs_input'\n violations: AiDoctrineViolation[]\n message: string\n /**\n * The answer the violations were found in, as it came through the tool\n * (AGL-3078): what a job's review outlines the parts they name from.\n * Held in memory only, and `null` when no answer arrived.\n */\n answer?: Record<string, unknown> | null\n /**\n * What the provider wrote for the attempt its ceiling cut off\n * (AGL-3143), when it sent it: the bytes behind `answer`, which is only\n * as much of them as still parsed. Held in memory only, like `answer`,\n * and `null` when nothing was cut off. It is the trace's, never a\n * customer's — a caller that keeps it keeps it out of what it shows.\n */\n rawOutput?: string | null\n })\n /** The model declined; tokens were spent. */\n | (AiGenerationSpend & { status: 'refused' })\n\nfunction withExtension<T>(\n check: AiGenerationCheck<T>,\n extend: ((value: T, answer: Record<string, unknown>) => AiDoctrineViolation[]) | undefined,\n): AiGenerationCheck<T> {\n if (!extend) return check\n return (answer) => {\n const result = check(answer)\n return result.value === null\n ? result\n : { ...result, violations: [...result.violations, ...extend(result.value, answer)] }\n }\n}\n\n/** A door's own check, with rule 13 held on every answer it reads. */\nfunction withDraftsOnly<T>(check: AiGenerationCheck<T>): AiGenerationCheck<T> {\n return (answer) => {\n const result = check(answer)\n return { ...result, violations: [...detectPublishIntent(answer), ...result.violations] }\n }\n}\n\n/**\n * What a tree built for this site is checked against: the brand an email is\n * held to, the ids the inventory lists, and whatever the door adds — asset\n * sizes, embeds, framing.\n */\nexport function aiDoctrineTreeContext(\n inventory: AiSiteInventory | null,\n extra: AiDoctrineTreeContext = {},\n): AiDoctrineTreeContext {\n return {\n brand: inventory?.theme\n ? { colors: inventory.theme.colors, fonts: inventory.theme.fonts }\n : null,\n ...aiNodeTreeContextFromInventory(inventory),\n homeScreenIds: aiHomeScreenIds(inventory),\n ...extra,\n }\n}\n\nfunction checkFor(kind: string, input: object): AiGenerationCheck<unknown> {\n if (kind === 'plan') {\n const plan = input as AiPlanGenerationInput\n return withExtension(\n aiDoctrinePlanCheck(plan.inventory, plan.framing ?? null, plan.capabilities ?? null),\n plan.extend,\n ) as AiGenerationCheck<unknown>\n }\n if (isAiOutputKind(kind)) {\n const tree = input as AiTreeGenerationInput\n return withExtension(\n aiDoctrineTreeCheck(kind, aiDoctrineTreeContext(tree.inventory, tree.context), tree.otherPages),\n tree.extend,\n ) as AiGenerationCheck<unknown>\n }\n const custom = (input as Partial<AiCustomGenerationInput<unknown>>).check\n if (!custom) {\n throw new Error(`runValidatedGeneration: the doctrine has no reader for \"${kind}\"; pass check`)\n }\n return withDraftsOnly(custom)\n}\n\n/**\n * Generate one output under the doctrine: ask, check, re-ask once with the\n * violations named, and give up with `needs_input` rather than spend again.\n *\n * `kind` decides the check: `'plan'` and the six palette kinds are read and\n * held by the doctrine itself; any other kind brings its own `check`, and the\n * doctrine still holds rule 13 on it. Throws only what the runtime throws — a\n * provider failure, an abort, a prompt the cache guard refuses — so a job\n * step's retry and failure paths stay the machine's.\n */\nexport function runValidatedGeneration(\n kind: 'plan',\n input: AiPlanGenerationInput,\n): Promise<AiValidatedGeneration<AiBuildPlan>>\nexport function runValidatedGeneration(\n kind: AiOutputKind,\n input: AiTreeGenerationInput,\n): Promise<AiValidatedGeneration<AiValidatedTree>>\nexport function runValidatedGeneration<T>(\n kind: string,\n input: AiCustomGenerationInput<T>,\n): Promise<AiValidatedGeneration<T>>\nexport async function runValidatedGeneration(\n kind: string,\n input: Omit<AiGenerationInputBase, 'inventory'> & { inventory?: AiSiteInventory | null },\n): Promise<AiValidatedGeneration<unknown>> {\n const check = checkFor(kind, input)\n const model =\n input.model ?? (input.step ? aiModelForStep(input.step, input.settings) : undefined)\n if (!model) {\n throw new Error(`runValidatedGeneration: a ${kind} names neither its step nor its model`)\n }\n const system = aiDoctrineSystemBlocks(input.inventory, {\n instructions: input.instructions,\n scope: aiDoctrineScopeFor(kind),\n ...(isAiOutputKind(kind) ? { surface: AI_OUTPUT_SURFACE[kind] } : {}),\n })\n const maxTokens =\n input.maxTokens ??\n AI_GENERATION_MAX_TOKENS[kind as AiGenerationKind] ??\n AI_CUSTOM_GENERATION_MAX_TOKENS\n const spend: AiGenerationSpend = {\n attempts: 0,\n usage: { inputTokens: 0, outputTokens: 0, cacheReadTokens: 0, cacheWriteTokens: 0 },\n estCostUsd: 0,\n model,\n stopReason: null,\n effort: input.effort ?? null,\n }\n // \"More on request\" (AGL-2937). A door that reads a site is offered the\n // lookup tool beside its own on EVERY request, whatever the site's size:\n // the tool list renders ahead of the system blocks and is part of what a\n // cache entry is keyed on, so offering it only to the sites large enough to\n // need it would split the platform's one cached prefix in two. A kind that\n // builds from no site structure — a theme, a listing — passes no inventory\n // and is offered nothing.\n const lookup = input.inventory === undefined ? null : aiInventoryLookupTool()\n const tools = lookup ? [input.tool, lookup] : [input.tool]\n let messages: AiMessage[] = [...input.messages]\n let violations: AiDoctrineViolation[] = []\n // The answer `violations` were found in, for the review a person reads.\n let refused: Record<string, unknown> | null = null\n // What the provider wrote for the attempt its ceiling cut off (AGL-3143).\n let rawOutput: string | null = null\n // Answer attempts, which the re-ask bounds, are counted apart from model\n // calls, which lookups also spend.\n let answers = 0\n let lookups = 0\n // ONE ALLOWANCE OF OUTPUT FOR THE WHOLE GENERATION (AGL-3036): an answer\n // and its re-ask at the ceiling. A lookup round is a model call answered at\n // the same ceiling, and nothing can tell a request that will look something\n // up from one that will answer, so each call is asked for no more than is\n // left of the allowance rather than for a ceiling of its own. What a\n // generation can take is then its calls' waits for a first token plus this\n // allowance, however it splits between lookups and answers — the worst case\n // `jobs/ai-job-budget.ts` plans a step's least time against. A generation\n // that has spent it all stops: nothing is left to answer with.\n const allowance = AI_GENERATION_MAX_ATTEMPTS * maxTokens\n while (answers < AI_GENERATION_MAX_ATTEMPTS) {\n const spent = Number(spend.usage.outputTokens)\n const left = allowance - (Number.isFinite(spent) ? spent : 0)\n if (left <= 0) {\n if (!violations.length) violations = [cutOffAnswer(kind, input.cutOff)]\n break\n }\n spend.attempts += 1\n const result = await runAiRequest({\n model,\n system,\n messages,\n tools,\n maxTokens: Math.min(maxTokens, left),\n stream: false,\n ...(input.thinking ? { thinking: input.thinking } : {}),\n ...(input.effort ? { effort: input.effort } : {}),\n ...(input.signal ? { signal: input.signal } : {}),\n ...(input.settings ? { settings: input.settings } : {}),\n ...(input.provider ? { provider: input.provider } : {}),\n })\n // Thinking tokens add up across the exchanges only where a provider\n // breaks them out; a generation whose provider reports none carries none,\n // rather than a zero that would read as \"it did not think\" (AGL-3143).\n const thinking =\n result.usage.thinkingTokens === undefined\n ? spend.usage.thinkingTokens\n : (spend.usage.thinkingTokens ?? 0) + result.usage.thinkingTokens\n spend.usage = {\n inputTokens: spend.usage.inputTokens + result.usage.inputTokens,\n outputTokens: spend.usage.outputTokens + result.usage.outputTokens,\n cacheReadTokens: spend.usage.cacheReadTokens + result.usage.cacheReadTokens,\n cacheWriteTokens: spend.usage.cacheWriteTokens + result.usage.cacheWriteTokens,\n ...(thinking === undefined ? {} : { thinkingTokens: thinking }),\n }\n spend.estCostUsd = Math.round((spend.estCostUsd + result.estCostUsd) * 1_000_000) / 1_000_000\n spend.stopReason = result.stopReason\n if (result.kind === 'refusal') return { ...spend, status: 'refused' }\n\n const answer = answerOf(result, input.tool.name)\n // A turn that asked to look something up rather than answering is not an\n // answer attempt: it is answered from the window already in memory and\n // the model is asked again. Bounded, because each round is a model call\n // the caller pays for; the last one says so, so the bound costs a turn\n // rather than a re-ask.\n const asked = answer ? undefined : result.toolUse.find((use) => use.name === lookup?.name)\n if (asked && lookups < AI_INVENTORY_LOOKUP_MAX_ROUNDS) {\n lookups += 1\n const last =\n lookups === AI_INVENTORY_LOOKUP_MAX_ROUNDS\n ? `\\n\\nThat was the last lookup. Answer with ${input.tool.name} now.`\n : ''\n messages = [\n ...messages,\n { role: 'assistant', content: `Called ${AI_INVENTORY_LOOKUP_TOOL_NAME}.` },\n {\n role: 'user',\n content: `${answerAiInventoryLookup(input.inventory ?? null, asked.input)}${last}`,\n },\n ]\n continue\n }\n answers += 1\n // CUT OFF WINS (AGL-3042), AND IT IS ASKED BEFORE THE CHECK'S VERDICT IS\n // BELIEVED (AGL-3143). A call that stopped at its ceiling was cut off,\n // whatever reached the tool: a tool input cut mid-answer arrives partial\n // or empty, and a check reads the truncation as a shape error — \"the\n // answer could not be used as a section\" — that a re-ask quoting it\n // cannot mend, so the re-ask is cut off the same way. The attempt is\n // refused as too large instead, and only a numbered rule the part that\n // arrived already broke is named beside it.\n //\n // A truncation does not always break a rule, though. A tool call cut at a\n // point where its valid prefix still parses reads as a smaller but legal\n // answer — three steps asked for, one step delivered — and passes every\n // check there is. Tested after the success path, \"cut off wins\" then\n // fires only where the check ALREADY failed, and the half-answer is\n // handed over with no re-ask spent on it. So the ceiling is tested first,\n // and a cut-off answer is refused whatever its prefix reads as. This is\n // not particular to one kind: any door that can read a partial answer as\n // a whole one has the same hole.\n const cutOff = aiStoppedAtCeiling(result.stopReason)\n const checked = answer ? check(answer) : null\n if (!cutOff && checked && checked.value !== null && checked.violations.length === 0) {\n return { ...spend, status: 'ok', value: checked.value }\n }\n const found = checked?.violations ?? []\n refused = answer\n if (cutOff) {\n rawOutput = result.rawOutput ?? null\n // WHERE THE OUTPUT WENT (AGL-3143). The shapes a cut-off answer comes\n // in are told apart by these figures. Thinking tokens account for the\n // spend first, because the thinking budget is drawn from the same\n // ceiling as the answer: a generation can spend nearly all of one\n // thinking and be cut off mid-call with a correct, tiny tool input, and\n // that is a ceiling to raise rather than a decoder to fix. What thinking\n // does not account for is told apart by the raw output — long, and a\n // runaway string the partial parse discarded; short, and decoding wrote\n // nothing usable. The bytes themselves are the model's own words, which\n // is the site's content, so they travel on the result for a trace to\n // keep and never into the log.\n console.warn('ai answer cut off at its ceiling', {\n kind,\n model,\n maxTokens,\n ...aiCutOffFigures({ usage: spend.usage, parsed: answer, rawOutput }),\n })\n }\n violations = cutOff\n ? [cutOffAnswer(kind, input.cutOff), ...found.filter((violation) => violation.rule !== null)]\n : found.length\n ? found\n : [unreadableAnswer(input.tool.name)]\n const offending = cutOff && violations.length === 1 ? undefined : checked?.offending\n // The re-ask continues the turn rather than replacing it, so whatever the\n // model looked up is still in front of it and is not asked for twice.\n messages = [\n ...messages,\n { role: 'assistant', content: `Submitted the ${kind} with ${input.tool.name}.` },\n {\n role: 'user',\n content: aiReaskMessage(kind, input.tool.name, violations, offending),\n },\n ]\n }\n return {\n ...spend,\n status: 'needs_input',\n violations,\n message: aiDoctrineNeedsInputMessage(violations),\n answer: refused,\n rawOutput,\n }\n}\n\n// ── An answer that streamed ──────────────────────────────────────────────\n\n/** What a streamed answer came to: a value with what its check left out, or the reasons there is none. */\nexport type AiStreamedGeneration<T> =\n | { status: 'ok'; value: T; violations: AiDoctrineViolation[] }\n /** No value, or a numbered rule broken. `message` is customer-safe. */\n | { status: 'needs_input'; violations: AiDoctrineViolation[]; message: string }\n\n/**\n * An answer a door has already received, held to the doctrine without a\n * request. A door that streams its reply to the reader as it arrives — the\n * chat door's edit rung — can read the answer only once it is on screen, with\n * no turn left to re-ask in, so the loop above cannot carry it.\n *\n * The check is the loop's for a kind the doctrine has no reader for: the\n * door's own, with rule 13 held on the answer. So are the verdicts, less the\n * re-ask. No value, or a numbered rule broken, is `needs_input` with the\n * reasons. A value is `ok` with the door's own findings beside it — what its\n * check already left out of the value, such as the changes an edit could not\n * make. A plan or a palette kind is refused here: the loop reads those, and a\n * broken rule in one is asked for again, never kept.\n */\nexport function validateStreamedGeneration<T>(\n kind: string,\n input: { answer: Record<string, unknown>; check: AiGenerationCheck<T> },\n): AiStreamedGeneration<T> {\n if (kind === 'plan' || isAiOutputKind(kind)) {\n throw new Error(\n `validateStreamedGeneration: a ${kind} is generated through runValidatedGeneration, which can re-ask`,\n )\n }\n const { value, violations } = withDraftsOnly(input.check)(input.answer)\n if (value === null || violations.some((violation) => violation.rule !== null)) {\n return { status: 'needs_input', violations, message: aiDoctrineNeedsInputMessage(violations) }\n }\n return { status: 'ok', value, violations }\n}\n"],"names":["parseAiBuildPlan","AI_INVENTORY_KINDS","AI_INVENTORY_KIND_HEADINGS","AI_SITE_INVENTORY_LISTED_PER_KIND","AI_SITE_INVENTORY_MAX_CHARS","aiHomeScreenIds","aiInventoryLine","aiInventoryRows","aiCutOffFigures","aiStoppedAtCeiling","AI_ROUTING_TABLE","aiModelForStep","AI_ACCEPTABLE_USE_BLOCK","runAiRequest","AI_SIMILAR_PAGES_MIN","aiDoctrineViolationText","detectPublishIntent","validateAiBuildPlan","validateAiDoctrineTree","AI_INVENTORY_LOOKUP_MAX_ROUNDS","AI_INVENTORY_LOOKUP_TOOL_NAME","aiInventoryLookupTool","answerAiInventoryLookup","AI_GENERATION_MAX_ATTEMPTS","AI_OUTPUT_BUDGETS","AI_OUTPUT_KINDS","AI_OUTPUT_SURFACE","AI_PALETTE_CATALOG","kilobytes","bytes","toLocaleString","maximumFractionDigits","Math","round","budgetLine","kind","budget","parts","nodes","imageBytes","embeds","emailHtmlBytes","push","test","join","DOCUMENTS","EVERY_SCOPE","AI_DOCTRINE_RULE_TEXT","n","scopes","text","map","SCOPE_OPENING","documents","fields","SCOPE_CLOSING","aiBuildingDoctrine","scope","closing","filter","rule","includes","AI_BUILDING_DOCTRINE","AI_DOCTRINE_SCOPE_BLOCKS","cacheBreakpoint","AI_DOCTRINE_SYSTEM_BLOCK","aiDoctrineSystemBlock","AI_DOCTRINE_KIND_SCOPE","aiDoctrineScopeFor","aiSiteInventoryBlock","inventory","lines","Object","fromEntries","slice","row","truncated","Set","length","render","line","theme","summary","colors","entries","path","value","fonts","size","has","block","longest","reduce","a","b","add","aiNodeTreeContextFromInventory","screenIds","screens","screen","id","componentIds","components","component","componentProps","props","formIds","forms","form","datasetIds","datasets","dataset","aiDoctrineCatalog","surface","aiDoctrineSystemBlocks","options","instructions","catalog","last","volatile","some","undefined","AI_GENERATION_MAX_TOKENS","plan","maxTokens","page","template","layout","email","AI_CUSTOM_GENERATION_MAX_TOKENS","AI_REASK_OFFENDING_MAX_CHARS","isAiOutputKind","isRecord","Array","isArray","aiDoctrineTreeTool","name","description","strict","inputSchema","type","additionalProperties","required","properties","tree","aiAnswerTree","answer","JSON","parse","answerOf","result","toolName","call","toolUse","find","use","input","trim","fenced","exec","candidate","parsed","capped","out","used","key","stringify","keys","valueAtPath","root","part","match","Number","aiDoctrineTreeCheck","context","otherPages","violation","report","score","violations","sourceIds","nodeIds","rawNodes","quoted","seen","quote","node","child","rootId","repairs","load","offending","aiDoctrinePlanCheck","framing","capabilities","publish","ok","code","message","detail","error","paths","flatMap","AI_ANSWER_CUT_OFF_CODE","cutOffAnswer","cutOff","noun","smaller","unreadableAnswer","aiReaskMessage","broken","where","aiDoctrineNeedsInputMessage","first","others","withExtension","check","extend","withDraftsOnly","aiDoctrineTreeContext","extra","brand","homeScreenIds","checkFor","custom","Error","runValidatedGeneration","model","step","settings","system","spend","attempts","usage","inputTokens","outputTokens","cacheReadTokens","cacheWriteTokens","estCostUsd","stopReason","effort","lookup","tools","tool","messages","refused","rawOutput","answers","lookups","allowance","spent","left","isFinite","min","stream","thinking","signal","provider","thinkingTokens","status","asked","role","content","checked","found","console","warn","validateStreamedGeneration"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC;AAGD,SAASA,gBAAgB,QAA0B,4BAAwB;AAE3E,SACEC,kBAAkB,EAClBC,0BAA0B,EAC1BC,iCAAiC,EACjCC,2BAA2B,EAC3BC,eAAe,EACfC,eAAe,EACfC,eAAe,QAGV,gCAA4B;AAEnC,SAASC,eAAe,EAAEC,kBAAkB,QAAyB,2BAAuB;AAC5F,SAASC,gBAAgB,EAAEC,cAAc,QAA+B,0BAAsB;AAC9F,SACEC,uBAAuB,EACvBC,YAAY,QAQP,kBAAc;AACrB,SACEC,oBAAoB,EACpBC,uBAAuB,EACvBC,mBAAmB,EACnBC,mBAAmB,EACnBC,sBAAsB,QAMjB,8BAA0B;AACjC,SACEC,8BAA8B,EAC9BC,6BAA6B,EAC7BC,qBAAqB,EACrBC,uBAAuB,QAClB,uCAAmC;AAC1C,SAASC,0BAA0B,QAAQ,4BAAwB;AAEnE,SACEC,iBAAiB,EACjBC,eAAe,EACfC,iBAAiB,QAIZ,kBAAc;AACrB,SAASC,kBAAkB,QAAQ,4BAAwB;AAE3D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAqCC,GAED,4EAA4E;AAE5E,SAASC,UAAUC,KAAa;IAC9B,OAAOA,SAAS,UACZ,GAAG,AAACA,CAAAA,QAAQ,OAAQ,EAAGC,cAAc,CAAC,SAAS;QAAEC,uBAAuB;IAAE,GAAG,GAAG,CAAC,GACjF,GAAGC,KAAKC,KAAK,CAACJ,QAAQ,MAAO,GAAG,CAAC;AACvC;AAEA,SAASK,WAAWC,IAAkB;IACpC,MAAMC,SAASZ,iBAAiB,CAACW,KAAK;IACtC,MAAME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AAM,IAAI8L,MACR,CAAC,8BAA8B,EAAE9L,KAAK,8DAA8D,CAAC;IAEzG;IACA,MAAM,EAAEmD,KAAK,EAAE6F,UAAU,EAAE,GAAGuC,eAAe9D,MAAM4D,KAAK,EAAE5D,MAAMV,MAAM;IACtE,IAAI5D,UAAU,QAAQ6F,WAAW3D,IAAI,CAAC,CAACwD,YAAcA,UAAUpH,IAAI,KAAK,OAAO;QAC7E,OAAO;YAAEuM,QAAQ;YAAehF;YAAYmB,SAASc,4BAA4BjC;QAAY;IAC/F;IACA,OAAO;QAAEgF,QAAQ;QAAM7K;QAAO6F;IAAW;AAC3C"}
@@ -0,0 +1,321 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Aglyn LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ import type { AiJob } from '../model/ai-jobs.types';
18
+ import { type AiProductsProposal } from '../model/ai-products';
19
+ import type { AiImagePart, AiProvider, AiSystemBlock, AiTool } from '../providers/contract';
20
+ import { type AiCustomGenerationInput } from './ai-doctrine';
21
+ import { type AiEvalCandidate, type AiEvalCase, type AiEvalKind, type AiEvalRubric } from './ai-eval';
22
+ /**
23
+ * THE EVAL HARNESS, LIVE (AGL-2937): recording new answers from the model.
24
+ *
25
+ * Offline scoring reads fixtures and costs nothing. A live run asks the
26
+ * provider for real answers to the golden briefs, grades each with a
27
+ * stronger model, and hands back recordings the offline harness then scores
28
+ * like any fixture. It spends real money, so it runs only when
29
+ * `AI_EVAL_LIVE=1` names it, and it is never part of CI or a deployment.
30
+ *
31
+ * A recording is only worth having if it measures what production sends. So
32
+ * each recorder answers a brief through the door that answers that kind in
33
+ * production — the plan step's runner, the text step's runner, the products
34
+ * step's runner, the theme and workflow steps' own generation calls — with
35
+ * the case's site handed in where the door would read one. Nothing here
36
+ * writes a prompt of its own for a kind.
37
+ *
38
+ * A kind with no recorder is skipped before any request, saying where
39
+ * production answers it (`AI_EVAL_UNRECORDED_DOORS`): a request route no job
40
+ * runs (the copy assistant's section, element and blog modes, the chat door),
41
+ * or a job step no recorder drives yet. A planned kind's document records the
42
+ * plan alone until its generator is recorded. A door that gains a recorder
43
+ * registers it with `registerAiEvalRecorder`.
44
+ *
45
+ * An automation brief is recorded through the workflow step's own generation
46
+ * call (AGL-3074) — a draft from the workspace's reach and the site's records,
47
+ * an explanation from the outline of the saved automation — because the
48
+ * step's runner keeps the tool's input nowhere: it writes the draft it makes
49
+ * of it, or the text it reads out of it, and the harness scores the input. A
50
+ * product brief is recorded through the products step's runner, against the
51
+ * case's store in memory, its photo read from the case's fixtures through the
52
+ * step's own resize-and-strip path, and its answer read back off the proposal
53
+ * the runner makes.
54
+ *
55
+ * A page brief is recorded END TO END (AGL-3030): the plan step's runner,
56
+ * the plan confirmed as a member confirms it, and every pass of the page
57
+ * step's runner against a site kept in memory — the layout, forms and
58
+ * components its plan creates built first by their own steps (AGL-3031) —
59
+ * each exchange's spend kept as the machine meters it. That is what proves
60
+ * what one page costs, on the workspace the case describes. Beside the page's
61
+ * tree it keeps the draft's screen — its address, its listing and the layout
62
+ * it renders inside — which the page's grader is shown with the plan
63
+ * (AGL-3073).
64
+ */
65
+ /** The environment variable a live run must be named by. */
66
+ export declare const AI_EVAL_LIVE_ENV = "AI_EVAL_LIVE";
67
+ export declare const AI_EVAL_LIVE_REFUSAL = "A live eval run asks the AI provider for real answers and spends real money. It runs only when AI_EVAL_LIVE=1 is set, from a machine that holds a provider key, and never in CI or on a deployment.";
68
+ export declare class AiEvalLiveRefusedError extends Error {
69
+ constructor();
70
+ }
71
+ /** Whether the environment names a live run. */
72
+ export declare function aiEvalLiveAllowed(env: Record<string, string | undefined>): boolean;
73
+ /**
74
+ * The variable a live run names the briefs it records by: case ids, comma
75
+ * separated. Unset records every brief a recorder covers.
76
+ */
77
+ export declare const AI_EVAL_CASES_ENV = "AI_EVAL_CASES";
78
+ /** The briefs a run records: the ones `AI_EVAL_CASES` names, else every one. */
79
+ export declare function aiEvalCasesNamed<T extends {
80
+ id: string;
81
+ }>(cases: readonly T[], env: Record<string, string | undefined>): T[];
82
+ export interface AiEvalLiveOptions {
83
+ env: Record<string, string | undefined>;
84
+ /** A provider chosen ahead of the registered ones; specs use it. */
85
+ provider?: AiProvider;
86
+ /** The model every recorder asks, in place of the routing table's answer. */
87
+ model?: string;
88
+ /** The grader's model; the provider's deepest tier when absent. */
89
+ graderModel?: string;
90
+ now?: Date;
91
+ /**
92
+ * Reads a file a case's `media` names, by its path under
93
+ * `tools/ai-eval/fixtures` (AGL-3074). A run that records a case naming
94
+ * media is refused without one, before any request.
95
+ */
96
+ readFixture?: (file: string) => Promise<Buffer>;
97
+ }
98
+ /** An answer to one brief, before it is graded. */
99
+ export type AiEvalRecordedAnswer = Omit<AiEvalCandidate, 'rubric'>;
100
+ export type AiEvalRecorder = (evalCase: AiEvalCase, options: AiEvalLiveOptions) => Promise<AiEvalRecordedAnswer>;
101
+ /** Idempotent per kind; last registration wins. */
102
+ export declare function registerAiEvalRecorder(kind: AiEvalKind, recorder: AiEvalRecorder): void;
103
+ export declare function aiEvalRecorderFor(kind: AiEvalKind): AiEvalRecorder | null;
104
+ /**
105
+ * The workflow step's generation for an automation brief (AGL-3074), from
106
+ * the case as the step's runner builds it from a site: a draft from what the
107
+ * workspace can run and the site's forms and datasets; or, for a brief about
108
+ * a saved action, an explanation from the action's outline, told whether the
109
+ * records its steps name exist as the runner reads only those, with a failed
110
+ * run's outline where the case gives one.
111
+ */
112
+ export declare function aiEvalWorkflowGeneration(evalCase: AiEvalCase, model: string): AiCustomGenerationInput<unknown>;
113
+ /**
114
+ * A product case's photo, as the products step sends it (AGL-3074): read
115
+ * through `ai-product-image.ts` from the case's fixtures. `null` for a case
116
+ * whose product has none, or whose photo cannot be read.
117
+ */
118
+ export declare function aiEvalCasePhoto(evalCase: AiEvalCase, options: AiEvalLiveOptions): Promise<AiImagePart | null>;
119
+ /**
120
+ * A products proposal read back as the tool input the harness scores
121
+ * (AGL-3074): a product's copy as its check kept it, a catalog's products,
122
+ * and categories with each discount in the tool's own terms — a percentage or
123
+ * dollars, a minimum order in dollars, and an empty code for a discount that
124
+ * applies on its own.
125
+ */
126
+ export declare function aiEvalProductsAnswer(proposal: AiProductsProposal): Record<string, unknown> | null;
127
+ /** Where production answers a kind no recorder covers. */
128
+ export type AiEvalUnrecordedDoor =
129
+ /** A request route no job runs, by what it is and the module that answers it. */
130
+ {
131
+ route: string;
132
+ file: string;
133
+ }
134
+ /** A job step no recorder drives yet, by its job kind and module. */
135
+ | {
136
+ step: AiJob['kind'];
137
+ file: string;
138
+ };
139
+ /**
140
+ * Every kind no recorder covers, and the door that answers it in production
141
+ * (AGL-3074), so a skipped brief says why truthfully. Modules are named from
142
+ * the plugin's `src/lib`.
143
+ */
144
+ export declare const AI_EVAL_UNRECORDED_DOORS: Readonly<Partial<Record<AiEvalKind, AiEvalUnrecordedDoor>>>;
145
+ /** Why a brief of this kind is skipped: where its door is, and that no recorder drives it. */
146
+ export declare function aiEvalSkipReason(kind: AiEvalKind): string;
147
+ export declare const AI_EVAL_RUBRIC_TOOL: AiTool;
148
+ export declare const AI_EVAL_GRADER_INSTRUCTIONS: readonly AiSystemBlock[];
149
+ /**
150
+ * What a build plan is, for the grader that grades one (AGL-3022).
151
+ *
152
+ * A plan is the proposal a member confirms, not the document the generation
153
+ * step writes afterwards, and `AI_BUILD_PLAN_TOOL` gives it nowhere to put a
154
+ * node tree, a heading order, a landmark or a line of body copy. Graded
155
+ * against a finished page it loses marks for every one of those, on structure
156
+ * and on copy alike, and the grade then measures the schema rather than the
157
+ * answer. So the grader is told the shape it is reading, and that the only
158
+ * words a plan writes are the ones `aiPlanCopy` collects.
159
+ *
160
+ * Two facts it cannot read off the schema are stated as well. Only a page or
161
+ * site job plans screens: the plan step tells a component, layout, template,
162
+ * form or email job to plan none, so an empty `screens` on one of those is the
163
+ * answer working, and a grader that does not know it marks the plan down for
164
+ * doing what it was told. And a search is an element, never a form: a form
165
+ * collects submissions, and a grader that does not know the platform has
166
+ * search elements rewards a plan for creating a form to search with.
167
+ */
168
+ export declare const AI_EVAL_PLAN_GRADER_NOTE: string;
169
+ /**
170
+ * What the grader of a case with capabilities is told beside them (AGL-3040).
171
+ *
172
+ * A case that describes its workspace had its plan told what that workspace
173
+ * may create, and a workspace that keeps no reusable components or saved
174
+ * forms builds the only way it can: a list's repeated items drawn in one
175
+ * section, the form carried by the page. A grader told none of that grades
176
+ * the doctrine whole, and marks reuse down for exactly the build the workspace
177
+ * required, as it marked down the first live recording of the Free brief.
178
+ */
179
+ export declare const AI_EVAL_CAPABILITIES_GRADER_NOTE = "Grade reuse against what this workspace may create, as listed above: never mark an output down for not creating what the workspace may not make.";
180
+ /**
181
+ * Beside that, where the workspace keeps no reusable components or saved
182
+ * forms, which the capability lines have already said.
183
+ */
184
+ export declare const AI_EVAL_INLINE_GRADER_NOTE = "On this workspace, a list's repeated items drawn in one section and a form drawn on the page, as a Form element holding its Form Fields, are the correct build and never a missed reuse.";
185
+ /**
186
+ * What a section's `uses` can hold on such a workspace (AGL-3143).
187
+ *
188
+ * A section's `uses` names what the section PLACES, and the only things it
189
+ * can name are an inventory id and a `new:<name>` creation. A workspace that
190
+ * keeps no reusable components or saved forms has neither to name, and the
191
+ * capability lines above have already refused the job the creations — so
192
+ * every inline section leaves `uses` empty because it is the only answer it
193
+ * can give. A grader that does not know it reads the empty list as a section
194
+ * that places nothing and marks the plan down for being correct, which drags
195
+ * the floors down for a reason that has nothing to do with the answer.
196
+ */
197
+ export declare const AI_EVAL_INLINE_USES_GRADER_NOTE = "A section's `uses` names what it places, and can name only an inventory id or a creation. This workspace has neither to place and may create neither, so an empty `uses` on a section drawn inline is the only answer there is: never mark a plan or a section down for it.";
198
+ /**
199
+ * The workspace a case describes, as its grader reads it: the capability
200
+ * lines the plan step was sent, narrowed to what the job builds the way the
201
+ * step narrows them, and the notes on grading against them. `null` for a
202
+ * case that describes no workspace, whose output is held to the doctrine
203
+ * whole.
204
+ */
205
+ export declare function aiEvalGraderCapabilities(evalCase: AiEvalCase): string | null;
206
+ /**
207
+ * What the grader of a built page is told beside it (AGL-3073).
208
+ *
209
+ * A page's tree holds only what the page adds. The site's header, navigation
210
+ * and footer are its layout's; the one main landmark is placed when the page
211
+ * is composed (`stampDocumentLandmark`), on the layout's slot where the page
212
+ * renders, or on the page's root when it renders inside none; and its address
213
+ * and listing are fields of its screen. A grader shown the tree alone marks a
214
+ * page down for a layout, a landmark and a listing the page has.
215
+ */
216
+ export declare const AI_EVAL_PAGE_GRADER_NOTE: string;
217
+ /** The most elements a layout's outline lists; the rest are counted. */
218
+ export declare const AI_EVAL_LAYOUT_OUTLINE_MAX_LINES = 40;
219
+ /**
220
+ * A layout as its page's grader reads it (AGL-3073): an element a line,
221
+ * indented by depth, named by the element it renders as and its component,
222
+ * with its own text quoted short. The main landmark is placed where a
223
+ * published page places it, by the function that places it there.
224
+ */
225
+ export declare function aiEvalLayoutOutline(tree: {
226
+ rootId: string;
227
+ nodes: Record<string, unknown>;
228
+ }): string;
229
+ /**
230
+ * The plan a built answer came from, as its grader reads it (AGL-3073): what
231
+ * it reuses and creates, and each screen's sections in order, with what each
232
+ * places and how many items it shows. `null` for an answer with no plan.
233
+ */
234
+ export declare function aiEvalPlanOutline(plan: unknown): string | null;
235
+ /**
236
+ * A built page's screen and layout, as its grader reads them (AGL-3073). A
237
+ * recording that kept the draft's screen gives its stored address and listing
238
+ * and the layout it renders inside, outlined from its tree. One made before
239
+ * that was kept gives its plan's screen instead, which is what the page step
240
+ * builds from, and says so.
241
+ */
242
+ export declare function aiEvalBuiltPage(answer: AiEvalRecordedAnswer): string | null;
243
+ /**
244
+ * An answer's output as its grader reads it: copy as written, and anything
245
+ * else as JSON, a tree's nodes without the keys the store keeps for itself
246
+ * (AGL-3073). Those are about a third of a recorded page, and a grade reads
247
+ * none of them: a node's id is its key and its parent is the node that lists
248
+ * it.
249
+ */
250
+ export declare function aiEvalGraderOutput(output: unknown): string;
251
+ /**
252
+ * What the grader of an answer written from more than its brief is shown of
253
+ * the request (AGL-3074): the user turn the kind's step sends, built from the
254
+ * case by the step's own prompt builder — a product and the categories it may
255
+ * go in, the categories a store already has, or what an automation draft or
256
+ * explanation was asked from. A grader that is not shown them grades copy
257
+ * against a product it never saw, and an explanation against an automation it
258
+ * never read. `null` for a kind whose request is its brief and its site.
259
+ */
260
+ export declare function aiEvalGraderRequest(evalCase: AiEvalCase, answer: AiEvalRecordedAnswer): string | null;
261
+ /** What the grader of product copy written with its photo in view is told beside the photo (AGL-3074). */
262
+ export declare const AI_EVAL_PHOTO_GRADER_NOTE = "The product's photo is attached, as the job sent it. Copy may state what the photo plainly shows and is never marked down for it; it is marked down for what neither the photo nor the product's words show.";
263
+ /** What the grader is told when the photo the copy was written with cannot be shown to it. */
264
+ export declare const AI_EVAL_PHOTO_UNSHOWN_GRADER_NOTE = "The copy was written with the product's photo in view, and this grader is not shown it: never mark copy down for a detail only the photo could show.";
265
+ /**
266
+ * The grader's user turn: the brief, its site, the workspace where the case
267
+ * describes one, the request beyond the brief, the plan a built answer came
268
+ * from, the screen and layout a built page was built as, and the answer.
269
+ * `shown.photo` says the product's photo rides beside this turn.
270
+ */
271
+ export declare function aiEvalGraderPrompt(evalCase: AiEvalCase, answer: AiEvalRecordedAnswer, shown?: {
272
+ photo?: boolean;
273
+ }): string;
274
+ /** A grade tool call read as a rubric; `null` when a grade is missing. */
275
+ export declare function readAiEvalGrade(answer: Record<string, unknown>, grader: string): AiEvalRubric | null;
276
+ /** Grade one recorded answer with a stronger model, through the doctrine's loop. */
277
+ export declare function gradeAiEvalCandidate(evalCase: AiEvalCase, answer: AiEvalRecordedAnswer, options: AiEvalLiveOptions): Promise<AiEvalRubric>;
278
+ /** Which half of a case's run threw: asking for the answer, or grading it. */
279
+ export type AiEvalLiveStep = 'record' | 'grade';
280
+ /** A brief whose run threw, as the report keeps it. */
281
+ export interface AiEvalLiveFailure {
282
+ caseId: string;
283
+ kind: AiEvalKind;
284
+ step: AiEvalLiveStep;
285
+ /** What was thrown, as a sentence. */
286
+ error: string;
287
+ /** The provider's request id, when the throw carried one — the vendor log's join key. */
288
+ requestId: string | null;
289
+ }
290
+ export interface AiEvalLiveReport {
291
+ recorded: Array<{
292
+ caseId: string;
293
+ kind: AiEvalKind;
294
+ candidate: AiEvalCandidate;
295
+ }>;
296
+ skipped: Array<{
297
+ caseId: string;
298
+ kind: AiEvalKind;
299
+ why: string;
300
+ }>;
301
+ /** The briefs whose run threw; empty when every brief a recorder covers came back. */
302
+ failed: AiEvalLiveFailure[];
303
+ }
304
+ /**
305
+ * Record and grade an answer for every brief a recorder covers. Refused
306
+ * before anything else unless `AI_EVAL_LIVE=1` names the run, and before any
307
+ * request when a brief it would record names media the run cannot read.
308
+ *
309
+ * ONE BRIEF'S FAILURE IS NOT THE RUN'S (AGL-3143). A run is owner-approved
310
+ * spend, and a provider that refuses one brief — a tool it will not compile,
311
+ * a rate limit — used to end the whole run with the answers already paid for
312
+ * still in memory and never written. Each brief is run on its own instead:
313
+ * one that throws is kept as a failure naming what was thrown, the vendor's
314
+ * request id and which half of its run threw, and the briefs behind it are
315
+ * still recorded. The caller writes what came back and decides what a
316
+ * non-empty `failed` means for its exit status.
317
+ *
318
+ * A brief whose GRADE threw is in both halves: recorded, with its grade
319
+ * marked missing, and failed, naming what the grader threw.
320
+ */
321
+ export declare function recordAiEvalLive(cases: readonly AiEvalCase[], options: AiEvalLiveOptions): Promise<AiEvalLiveReport>;