@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-eval-live.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 { assistCreditsFromUsd } from '@aglyn/aglyn/app-utils/assist-credits'\nimport { LAYOUT_SLOT_COMPONENT_ID } from '@aglyn/aglyn/app-utils/compose-layout-nodes'\nimport { stampDocumentLandmark } from '@aglyn/aglyn/app-utils/document-landmark'\nimport { decodeStoredNodes } from '@aglyn/aglyn/app-utils/stored-nodes'\nimport { CANVAS_ROOT_ELEMENT_ID } from '@aglyn/aglyn/foundation/constants/canvas'\nimport { createAiJobComponentStep } from '../jobs/ai-job-component-step'\nimport { aiJobDraftId, aiMintJobDraftIds } from '../jobs/ai-job-draft-ids'\nimport { createAiJobFormStep } from '../jobs/ai-job-form-step'\nimport { createAiJobLayoutStep } from '../jobs/ai-job-layout-step'\nimport { aiPageJobUnits, createAiJobPageStep } from '../jobs/ai-job-page-step'\nimport { AI_JOB_PLAN_SCOPES, createAiJobPlanStep } from '../jobs/ai-job-plan-step'\nimport { createAiJobProductsStep } from '../jobs/ai-job-products-step'\nimport { aiSitePendingUnits } from '../jobs/ai-job-site-step'\nimport type { AiJobStepOutcome } from '../jobs/ai-job-text-step'\nimport { runAiJobTextStep } from '../jobs/ai-job-text-step'\nimport { aiJobThemeCheck, aiJobThemeGeneration, aiJobThemeMode } from '../jobs/ai-job-theme-step'\nimport {\n aiJobWorkflowDraftGeneration,\n aiJobWorkflowExplainGeneration,\n aiJobWorkflowModel,\n} from '../jobs/ai-job-workflow-step'\nimport { readAiProductImage, type AiProductImageSeams } from '../jobs/ai-product-image'\nimport { emptyAiAutomationRecords, type AiAutomationRecords } from '../model/ai-automation-draft'\nimport { aiActionOutline, aiActionRecordKinds, aiRunOutline } from '../model/ai-automation-outline'\nimport type { AiJob, AiJobOutput, AiJobPlan } from '../model/ai-jobs.types'\nimport { aiPlanCapabilitiesForJob, aiPlanCapabilityLines } from '../model/ai-plan-capabilities'\nimport { aiProductsJobInputs, aiProductsProposalOf, type AiProductsProposal } from '../model/ai-products'\nimport { aiDefaultModelFor, type AiStepKind } from '../providers/catalog'\nimport type { AiImagePart, AiProvider, AiSystemBlock, AiTool, AiUsage } from '../providers/contract'\nimport { aiModelForStep, resolveAiProvider } from '../providers/routing'\nimport { aiSiteInventoryBlock, runValidatedGeneration, type AiCustomGenerationInput } from './ai-doctrine'\nimport {\n AI_EVAL_AUTOMATION_CAPABILITIES,\n AI_EVAL_SITE_ID,\n AI_EVAL_TREE_OUTPUT,\n type AiEvalCandidate,\n type AiEvalCase,\n type AiEvalKind,\n type AiEvalRecordedScreen,\n type AiEvalRecordedStep,\n type AiEvalRubric,\n} from './ai-eval'\nimport { aiEvalMemoryFirestore, aiEvalMemoryInventory } from './ai-eval-memory-firestore'\nimport { aiCategoriesPrompt, aiProductCopyPrompt } from './ai-products-generation'\nimport { aiModelReadsImages } from './ai-runtime'\n\n/**\n * THE EVAL HARNESS, LIVE (AGL-2937): recording new answers from the model.\n *\n * Offline scoring reads fixtures and costs nothing. A live run asks the\n * provider for real answers to the golden briefs, grades each with a\n * stronger model, and hands back recordings the offline harness then scores\n * like any fixture. It spends real money, so it runs only when\n * `AI_EVAL_LIVE=1` names it, and it is never part of CI or a deployment.\n *\n * A recording is only worth having if it measures what production sends. So\n * each recorder answers a brief through the door that answers that kind in\n * production — the plan step's runner, the text step's runner, the products\n * step's runner, the theme and workflow steps' own generation calls — with\n * the case's site handed in where the door would read one. Nothing here\n * writes a prompt of its own for a kind.\n *\n * A kind with no recorder is skipped before any request, saying where\n * production answers it (`AI_EVAL_UNRECORDED_DOORS`): a request route no job\n * runs (the copy assistant's section, element and blog modes, the chat door),\n * or a job step no recorder drives yet. A planned kind's document records the\n * plan alone until its generator is recorded. A door that gains a recorder\n * registers it with `registerAiEvalRecorder`.\n *\n * An automation brief is recorded through the workflow step's own generation\n * call (AGL-3074) — a draft from the workspace's reach and the site's records,\n * an explanation from the outline of the saved automation — because the\n * step's runner keeps the tool's input nowhere: it writes the draft it makes\n * of it, or the text it reads out of it, and the harness scores the input. A\n * product brief is recorded through the products step's runner, against the\n * case's store in memory, its photo read from the case's fixtures through the\n * step's own resize-and-strip path, and its answer read back off the proposal\n * the runner makes.\n *\n * A page brief is recorded END TO END (AGL-3030): the plan step's runner,\n * the plan confirmed as a member confirms it, and every pass of the page\n * step's runner against a site kept in memory — the layout, forms and\n * components its plan creates built first by their own steps (AGL-3031) —\n * each exchange's spend kept as the machine meters it. That is what proves\n * what one page costs, on the workspace the case describes. Beside the page's\n * tree it keeps the draft's screen — its address, its listing and the layout\n * it renders inside — which the page's grader is shown with the plan\n * (AGL-3073).\n */\n\n/** The environment variable a live run must be named by. */\nexport const AI_EVAL_LIVE_ENV = 'AI_EVAL_LIVE'\n\nexport const AI_EVAL_LIVE_REFUSAL =\n `A live eval run asks the AI provider for real answers and spends real money. It runs only when ${AI_EVAL_LIVE_ENV}=1 is set, from a machine that holds a provider key, and never in CI or on a deployment.`\n\nexport class AiEvalLiveRefusedError extends Error {\n constructor() {\n super(AI_EVAL_LIVE_REFUSAL)\n this.name = 'AiEvalLiveRefusedError'\n }\n}\n\n/** Whether the environment names a live run. */\nexport function aiEvalLiveAllowed(env: Record<string, string | undefined>): boolean {\n return env[AI_EVAL_LIVE_ENV] === '1'\n}\n\n/**\n * The variable a live run names the briefs it records by: case ids, comma\n * separated. Unset records every brief a recorder covers.\n */\nexport const AI_EVAL_CASES_ENV = 'AI_EVAL_CASES'\n\n/** The briefs a run records: the ones `AI_EVAL_CASES` names, else every one. */\nexport function aiEvalCasesNamed<T extends { id: string }>(\n cases: readonly T[],\n env: Record<string, string | undefined>,\n): T[] {\n const named = (env[AI_EVAL_CASES_ENV] ?? '')\n .split(',')\n .map((id) => id.trim())\n .filter(Boolean)\n if (!named.length) return [...cases]\n const unknown = named.filter((id) => !cases.some((evalCase) => evalCase.id === id))\n if (unknown.length) throw new Error(`${AI_EVAL_CASES_ENV} names no golden brief: ${unknown.join(', ')}`)\n return cases.filter((evalCase) => named.includes(evalCase.id))\n}\n\nexport interface AiEvalLiveOptions {\n env: Record<string, string | undefined>\n /** A provider chosen ahead of the registered ones; specs use it. */\n provider?: AiProvider\n /** The model every recorder asks, in place of the routing table's answer. */\n model?: string\n /** The grader's model; the provider's deepest tier when absent. */\n graderModel?: string\n now?: Date\n /**\n * Reads a file a case's `media` names, by its path under\n * `tools/ai-eval/fixtures` (AGL-3074). A run that records a case naming\n * media is refused without one, before any request.\n */\n readFixture?: (file: string) => Promise<Buffer>\n}\n\n/** An answer to one brief, before it is graded. */\nexport type AiEvalRecordedAnswer = Omit<AiEvalCandidate, 'rubric'>\n\nexport type AiEvalRecorder = (\n evalCase: AiEvalCase,\n options: AiEvalLiveOptions,\n) => Promise<AiEvalRecordedAnswer>\n\nconst recorders = new Map<AiEvalKind, AiEvalRecorder>()\n\n/** Idempotent per kind; last registration wins. */\nexport function registerAiEvalRecorder(kind: AiEvalKind, recorder: AiEvalRecorder): void {\n recorders.set(kind, recorder)\n}\n\nexport function aiEvalRecorderFor(kind: AiEvalKind): AiEvalRecorder | null {\n return recorders.get(kind) ?? null\n}\n\nconst EVAL_ORG = 'eval-org'\n\n/** A job for a golden brief, in the shape a step runner reads: its drafts named as a created job's are. */\nfunction evalJob(evalCase: AiEvalCase, kind: AiJob['kind']): AiJob {\n const now = new Date(0)\n const draftIds = aiMintJobDraftIds(kind)\n return {\n $id: `eval-${evalCase.id}`,\n orgId: EVAL_ORG,\n hostId: evalCase.inventory?.hostId ?? null,\n kind,\n status: 'running',\n brief: evalCase.brief,\n inputs: {},\n steps: draftIds ? [{ name: 'generate', status: 'running', creditsSpent: 0, draftIds }] : [],\n outputs: [],\n creditsReserved: 0,\n creditsSpent: 0,\n createdBy: 'eval',\n createdAt: now as unknown as AiJob['createdAt'],\n updatedAt: now as unknown as AiJob['updatedAt'],\n expiresAt: now as unknown as AiJob['expiresAt'],\n }\n}\n\n/**\n * The model a step runner is handed: the one the run names, else the routing\n * table's. A runner reaches its provider through the runtime's registry.\n */\nfunction modelFor(options: AiEvalLiveOptions): (step: AiStepKind) => string | undefined {\n return (step) => options.model ?? aiModelForStep(step)\n}\n\n/** Runs the doctrine's call with the provider a live run chose, when it chose one. */\nfunction withProvider<T extends object>(input: T, options: AiEvalLiveOptions): T {\n return options.provider ? { ...input, provider: options.provider } : input\n}\n\n/** The case's site, as a reader the step runners are handed. */\nfunction inventoryOf(evalCase: AiEvalCase) {\n return async () => {\n if (!evalCase.inventory) throw new Error(`${evalCase.id} has no inventory to build from`)\n return evalCase.inventory\n }\n}\n\n/**\n * The plan step's runner for a brief, on the case's site and the case's\n * workspace. No plan reuse in a recording (AGL-2937): the point of a live run\n * is to measure what the model answers for this brief, and a reused plan\n * would record someone else's answer as this case's. No admission either: a\n * recording writes to no workspace a door would count against.\n */\nfunction evalPlanStep(evalCase: AiEvalCase) {\n return createAiJobPlanStep({\n readInventory: inventoryOf(evalCase),\n findPlansByKey: null,\n readCapabilities: async () => evalCase.capabilities ?? null,\n admissionRefusal: async () => null,\n })\n}\n\n/** A plan outcome's plan, as a candidate records it. */\nfunction planOf(outcome: AiJobStepOutcome): AiEvalRecordedAnswer['plan'] {\n return outcome.plan\n ? { reuse: outcome.plan.reuse, create: outcome.plan.create, screens: outcome.plan.screens }\n : null\n}\n\n/** A planned kind's brief, recorded through the plan step: the plan alone. */\nconst recordPlan: AiEvalRecorder = async (evalCase, options) => {\n const kind = evalCase.kind as AiJob['kind']\n const outcome = await evalPlanStep(evalCase)({\n job: evalJob(evalCase, kind),\n stepIndex: 0,\n now: options.now ?? new Date(),\n firestore: {} as FirebaseFirestore.Firestore,\n modelFor: modelFor(options),\n })\n return {\n source: 'recorded',\n scope: 'plan',\n step: 'job.plan',\n model: outcome.model,\n effort: outcome.effort ?? null,\n plan: planOf(outcome),\n answer: null,\n usage: outcome.usage,\n note: outcome.review?.reason === 'doctrine' ? `needs review: ${outcome.review.message}` : undefined,\n }\n}\n\n/** The most passes a recorded page may take: the plan limit's sections and the listing, with room. */\nconst AI_EVAL_PAGE_MAX_PASSES = 64\n\n/** One exchange's spend, as the machine meters a step. */\nfunction recordedStep(\n step: AiStepKind,\n outcome: Pick<AiJobStepOutcome, 'model' | 'usage' | 'estCostUsd'>,\n): AiEvalRecordedStep {\n return {\n step,\n model: outcome.model,\n usage: outcome.usage,\n estCostUsd: outcome.estCostUsd,\n credits: assistCreditsFromUsd(outcome.estCostUsd),\n }\n}\n\n/** Several exchanges' tokens, added. */\nfunction totalUsage(steps: readonly AiEvalRecordedStep[]): AiUsage {\n return steps.reduce<AiUsage>(\n (sum, step) => ({\n inputTokens: sum.inputTokens + step.usage.inputTokens,\n outputTokens: sum.outputTokens + step.usage.outputTokens,\n cacheReadTokens: sum.cacheReadTokens + step.usage.cacheReadTokens,\n cacheWriteTokens: sum.cacheWriteTokens + step.usage.cacheWriteTokens,\n }),\n { inputTokens: 0, outputTokens: 0, cacheReadTokens: 0, cacheWriteTokens: 0 },\n )\n}\n\n/**\n * The workspace a case describes, as the org document the page step reads:\n * a workspace that keeps no reusable components is the Free plan's shape,\n * and any other is a plan that keeps them.\n */\nfunction evalOrgDocument(evalCase: AiEvalCase): Record<string, unknown> {\n return evalCase.capabilities?.reusableComponents === false\n ? { plan: 'free' }\n : { plan: 'business', billingStatus: 'active' }\n}\n\n/**\n * A page brief, recorded end to end (AGL-3030): the plan, confirmed, then the\n * page step's passes until it reports the draft or stops for a person. What\n * it answers is the page as the draft holds it, and what it spent is every\n * exchange, each metered as the machine meters a step. A plan that stops for\n * review records the plan alone, as a plan answer.\n */\nconst recordPage: AiEvalRecorder = async (evalCase, options) => {\n const now = options.now ?? new Date()\n const job = evalJob(evalCase, 'page')\n const hostId = job.hostId as string\n const org = evalOrgDocument(evalCase)\n // The page step names the site in the listing request by its host\n // document, so the site is named only as the case names it (AGL-3077).\n const site = aiEvalMemoryFirestore({\n [`orgs/${EVAL_ORG}`]: org,\n [`hosts/${hostId}`]: {\n ...(evalCase.siteName ? { displayName: evalCase.siteName } : {}),\n screens: Object.fromEntries((evalCase.inventory?.screens ?? []).map((row) => [row.id, row.slug])),\n },\n })\n const context = { stepIndex: 0, now, firestore: site.firestore, modelFor: modelFor(options), org }\n const planned = await evalPlanStep(evalCase)({ ...context, job })\n const steps: AiEvalRecordedStep[] = [recordedStep('job.plan', planned)]\n const planOnly = (note?: string): AiEvalRecordedAnswer => ({\n source: 'recorded',\n scope: 'plan',\n step: 'job.plan',\n model: planned.model,\n effort: planned.effort ?? null,\n plan: planOf(planned),\n answer: null,\n usage: planned.usage,\n ...(note ? { note } : {}),\n })\n if (!planned.plan || planned.review?.reason !== 'plan') {\n return planOnly(\n planned.failure\n ? `refused before confirm: ${planned.failure}`\n : planned.review\n ? `needs review: ${planned.review.message}`\n : undefined,\n )\n }\n\n const confirmed: AiJob = {\n ...job,\n plan: {\n ...planned.plan,\n status: 'confirmed',\n confirmedAt: now as unknown as AiJobPlan['confirmedAt'],\n confirmedBy: 'eval',\n },\n }\n // The site as the steps read it: the case's rows, and what the job has\n // built there so far. A case's site holds no documents to copy, so a plan\n // that starts from a copy is built from its brief, as a step builds one\n // whose source is gone.\n const readers = {\n readInventory: async () => {\n if (!evalCase.inventory) throw new Error(`${evalCase.id} has no inventory to build from`)\n return aiEvalMemoryInventory(evalCase.inventory, site.docs)\n },\n duplicate: async () => ({ ok: false as const, status: 404, error: 'A recording copies nothing' }),\n }\n const creations = {\n layout: createAiJobLayoutStep(readers),\n form: createAiJobFormStep(readers),\n component: createAiJobComponentStep(readers),\n } as const\n const generate = createAiJobPageStep({\n ...readers,\n runnerFor: (kind) => (kind in creations ? creations[kind as keyof typeof creations] : null),\n })\n const units = aiPageJobUnits(confirmed.plan as AiJobPlan)\n let outputs: AiJobOutput[] = []\n let stopped: string | undefined\n for (let pass = 0; pass < AI_EVAL_PAGE_MAX_PASSES; pass += 1) {\n const [unit] = aiSitePendingUnits(units, outputs)\n const outcome = await generate({ ...context, stepIndex: 1, job: { ...confirmed, outputs } })\n // A creation's pass is its own step's; the pass that reports the draft\n // asks for the listing, on the SEO step's model.\n const kind: AiStepKind = unit\n ? (`job.${unit.jobKind}` as AiStepKind)\n : outcome.outputs.some((output) => output.resource === 'screen')\n ? 'job.seo'\n : 'job.page'\n steps.push(recordedStep(kind, outcome))\n outputs = [...outputs, ...outcome.outputs]\n if (outcome.refused || outcome.failure || outcome.review) {\n stopped = outcome.refused ? 'refused' : (outcome.failure ?? outcome.review?.message)\n break\n }\n if (!outcome.continue) break\n }\n\n const screenPath = `hosts/${hostId}/screens/${aiJobDraftId(confirmed, 'screen')}`\n const nodes = storedTree(site.docs, screenPath)\n const built = outputs.some((output) => output.resource === 'screen')\n const screen = built && nodes ? recordedScreen(evalCase, site.docs, screenPath, outputs) : undefined\n return {\n source: 'recorded',\n scope: built && nodes ? 'full' : 'plan',\n step: 'job.page',\n model: steps.find((entry) => entry.step === 'job.page')?.model ?? planned.model,\n effort: null,\n plan: planOf(planned),\n answer: built && nodes ? { tree: { rootId: CANVAS_ROOT_ELEMENT_ID, nodes } } : null,\n usage: totalUsage(steps),\n steps,\n ...(screen ? { screen } : {}),\n ...(stopped ? { note: `stopped: ${stopped}` } : {}),\n }\n}\n\n/** A string a stored document holds, trimmed; `null` for none. */\nfunction storedText(value: unknown): string | null {\n return typeof value === 'string' && value.trim() ? value.trim() : null\n}\n\n/** The node map a versioned draft's first version holds, decoded; `null` when there is none. */\nfunction storedTree(docs: ReadonlyMap<string, Record<string, unknown>>, draftPath: string): Record<string, unknown> | null {\n const draft = docs.get(draftPath)\n const version = draft ? docs.get(`${draftPath}/versions/${String(draft['versionId'])}`) : undefined\n return version ? decodeStoredNodes<Record<string, unknown>>(version['nodes']) : null\n}\n\n/**\n * The draft screen a page job wrote, as its grader reads it beside the tree\n * (AGL-3073): the address and listing the draft holds, whether its output\n * proposes a navigation entry, and the layout its version renders inside —\n * one this job built, with its tree, or one the case's site lists by name.\n */\nfunction recordedScreen(\n evalCase: AiEvalCase,\n docs: ReadonlyMap<string, Record<string, unknown>>,\n screenPath: string,\n outputs: readonly AiJobOutput[],\n): AiEvalRecordedScreen | undefined {\n const screen = docs.get(screenPath)\n const version = screen ? docs.get(`${screenPath}/versions/${String(screen['versionId'])}`) : undefined\n if (!screen || !version) return undefined\n const seo = (screen['seo'] ?? {}) as Record<string, unknown>\n const layoutId = storedText(version['layoutId'])\n const layoutPath = `${screenPath.split('/').slice(0, 2).join('/')}/layouts/${layoutId}`\n const built = layoutId ? docs.get(layoutPath) : undefined\n const listed = layoutId ? evalCase.inventory?.layouts.find((row) => row.id === layoutId) : undefined\n const nodes = built ? storedTree(docs, layoutPath) : null\n return {\n slug: String(screen['slug'] ?? ''),\n seoTitle: storedText(seo['title']),\n seoDescription: storedText(seo['description']),\n nav: outputs.some((output) => output.resource === 'screen' && output.proposal?.['navigation'] != null),\n layout:\n layoutId && (built || listed)\n ? {\n id: layoutId,\n name: storedText(built?.['displayName']) ?? listed?.name ?? layoutId,\n built: Boolean(built),\n tree: nodes ? { rootId: CANVAS_ROOT_ELEMENT_ID, nodes } : null,\n }\n : null,\n }\n}\n\n/** A text brief, recorded through the text step. */\nconst recordText: AiEvalRecorder = async (evalCase, options) => {\n const outcome = await runAiJobTextStep({\n job: evalJob(evalCase, 'text'),\n stepIndex: 0,\n now: options.now ?? new Date(),\n firestore: {} as FirebaseFirestore.Firestore,\n modelFor: modelFor(options),\n })\n return {\n source: 'recorded',\n scope: 'full',\n step: 'job.text',\n model: outcome.model,\n effort: outcome.effort ?? null,\n plan: null,\n answer: outcome.outputs[0]?.text ?? null,\n usage: outcome.usage,\n }\n}\n\n/**\n * A theme brief, recorded through the theme step's own generation call. The\n * tool's raw input is kept, because that is what the harness scores; the\n * site's theme comes from the case rather than a host document.\n */\nconst recordTheme: AiEvalRecorder = async (evalCase, options) => {\n const model = options.model ?? aiModelForStep('job.theme')\n let raw: Record<string, unknown> | null = null\n const generation = aiJobThemeGeneration({\n brief: evalCase.brief,\n mode: aiJobThemeMode(undefined),\n theme: evalCase.siteTheme,\n source: evalCase.themeSource ?? 'default',\n brand: [],\n model,\n })\n const result = await runValidatedGeneration(\n 'theme',\n withProvider(\n {\n ...generation,\n check: (answer: Record<string, unknown>) => {\n raw = answer\n return aiJobThemeCheck(answer)\n },\n },\n options,\n ),\n )\n return {\n source: 'recorded',\n scope: 'full',\n step: 'job.theme',\n model: result.model,\n effort: result.effort,\n plan: null,\n answer: result.status === 'refused' ? null : raw,\n usage: result.usage,\n }\n}\n\n/**\n * The workflow step's generation for an automation brief (AGL-3074), from\n * the case as the step's runner builds it from a site: a draft from what the\n * workspace can run and the site's forms and datasets; or, for a brief about\n * a saved action, an explanation from the action's outline, told whether the\n * records its steps name exist as the runner reads only those, with a failed\n * run's outline where the case gives one.\n */\nexport function aiEvalWorkflowGeneration(evalCase: AiEvalCase, model: string): AiCustomGenerationInput<unknown> {\n const records = evalCase.automationRecords ?? emptyAiAutomationRecords()\n const automation = evalCase.automation\n if (!automation) {\n return aiJobWorkflowDraftGeneration({\n brief: evalCase.brief,\n capabilities: evalCase.automationCapabilities ?? AI_EVAL_AUTOMATION_CAPABILITIES,\n records,\n model,\n }) as AiCustomGenerationInput<unknown>\n }\n const named = aiActionRecordKinds(automation.action)\n const read = Object.fromEntries(\n Object.entries(records).map(([kind, rows]) => [kind, named.includes(kind as keyof AiAutomationRecords) ? rows : []]),\n ) as unknown as AiAutomationRecords\n return aiJobWorkflowExplainGeneration({\n brief: evalCase.brief,\n mode: automation.run ? 'diagnose' : 'explain',\n outline: aiActionOutline(automation.action, read),\n run: automation.run ? aiRunOutline(automation.run) : null,\n model,\n }) as AiCustomGenerationInput<unknown>\n}\n\n/**\n * An automation brief, recorded through the workflow step's own generation\n * call (AGL-3074). The tool's raw input is kept, because that is what the\n * harness scores: the step's runner turns a draft into the action it writes,\n * and an explanation into the text it reports, and keeps the input nowhere.\n */\nconst recordWorkflow: AiEvalRecorder = async (evalCase, options) => {\n const generation = aiEvalWorkflowGeneration(evalCase, options.model ?? aiJobWorkflowModel())\n let raw: Record<string, unknown> | null = null\n const result = await runValidatedGeneration(\n 'workflow',\n withProvider(\n {\n ...generation,\n check: (answer: Record<string, unknown>) => {\n raw = answer\n return generation.check(answer)\n },\n },\n options,\n ),\n )\n return {\n source: 'recorded',\n scope: 'full',\n step: 'job.workflow',\n model: result.model,\n effort: result.effort,\n plan: null,\n answer: result.status === 'refused' ? null : raw,\n usage: result.usage,\n steps: [recordedStep('job.workflow', result)],\n ...(result.status === 'needs_input'\n ? {\n note: `needs review: ${result.message}`,\n // An automation draft is the largest thing anything here asks for,\n // so it is the one that runs out of ceiling (AGL-3143). What the\n // provider wrote goes on the recording, where the run that paid for\n // it can still be read after it ends.\n ...(result.rawOutput ? { rawOutput: result.rawOutput } : {}),\n }\n : {}),\n }\n}\n\n/** The site a case's job runs on: its inventory's, or the harness's own. */\nfunction aiEvalSiteId(evalCase: AiEvalCase): string {\n return evalCase.inventory?.hostId ?? AI_EVAL_SITE_ID\n}\n\n/** A products brief's job inputs, as the editor or a products card hands them over. */\nfunction aiEvalProductsInputs(evalCase: AiEvalCase): Record<string, string> {\n if (evalCase.kind === 'catalog') return aiProductsJobInputs({ target: 'catalog' })\n if (evalCase.kind === 'categories') return aiProductsJobInputs({ target: 'categories' })\n if (!evalCase.product) throw new Error(`${evalCase.id} names no product to write copy for`)\n return aiProductsJobInputs({ target: 'product', product: evalCase.product.facts })\n}\n\n/** A picture's content type, from the extension of the fixture that holds it. */\nfunction fixtureContentType(file: string): string {\n const extension = file.slice(file.lastIndexOf('.') + 1).toLowerCase()\n return `image/${extension === 'jpg' ? 'jpeg' : extension}`\n}\n\n/**\n * The storage read of a case's media library (AGL-3074): the fixture the case\n * names for an asset of its own site's library, and nothing for any other. It\n * stands in for the download alone, so the products step's own path still\n * locates the photo, decodes it, turns it upright, resizes it and encodes the\n * JPEG the model is sent.\n */\nfunction aiEvalMediaSeams(evalCase: AiEvalCase, options: AiEvalLiveOptions): AiProductImageSeams {\n return {\n readBytes: async (_firestore, location, hostId) => {\n const own = !location.scope.isOrg && location.scope.scopeId === hostId\n const file = own ? evalCase.media?.[location.mediaId] : undefined\n if (!file || !options.readFixture) return null\n return { buffer: await options.readFixture(file), contentType: fixtureContentType(file) }\n },\n }\n}\n\n/**\n * A product case's photo, as the products step sends it (AGL-3074): read\n * through `ai-product-image.ts` from the case's fixtures. `null` for a case\n * whose product has none, or whose photo cannot be read.\n */\nexport async function aiEvalCasePhoto(evalCase: AiEvalCase, options: AiEvalLiveOptions): Promise<AiImagePart | null> {\n const value = evalCase.product?.facts.imageUrl\n if (!value) return null\n const read = await readAiProductImage(\n {} as FirebaseFirestore.Firestore,\n { value, hostId: aiEvalSiteId(evalCase), orgId: EVAL_ORG },\n aiEvalMediaSeams(evalCase, options),\n )\n return read.status === 'read' ? read.image : null\n}\n\n/**\n * A products proposal read back as the tool input the harness scores\n * (AGL-3074): a product's copy as its check kept it, a catalog's products,\n * and categories with each discount in the tool's own terms — a percentage or\n * dollars, a minimum order in dollars, and an empty code for a discount that\n * applies on its own.\n */\nexport function aiEvalProductsAnswer(proposal: AiProductsProposal): Record<string, unknown> | null {\n if (proposal.kind === 'copy') return proposal.values ? { ...proposal.values } : null\n if (proposal.kind === 'catalog') return { products: proposal.products }\n return {\n categories: proposal.categories,\n discounts: proposal.discounts.map((discount) => ({\n name: discount.name,\n code: discount.code ?? '',\n kind: discount.kind,\n value:\n discount.kind === 'percent'\n ? (discount.valuePct ?? 0)\n : discount.kind === 'fixed'\n ? (discount.valueCents ?? 0) / 100\n : 0,\n minimumOrderUsd: (discount.minSubtotalCents ?? 0) / 100,\n why: discount.why,\n })),\n }\n}\n\n/**\n * A products brief — one product's copy, a store's first catalog, or its\n * categories and discounts — recorded through the products step's runner\n * (AGL-3074), against the case's store kept in memory: its name, its\n * categories, and the photo its media names. What it answers is read back off\n * the proposal the runner makes.\n */\nconst recordProducts: AiEvalRecorder = async (evalCase, options) => {\n const hostId = aiEvalSiteId(evalCase)\n const categories =\n evalCase.kind === 'product'\n ? (evalCase.product?.categories ?? [])\n : (evalCase.existingCategoryNames ?? []).map((name, index) => ({ id: `category-${index + 1}`, name }))\n const store = aiEvalMemoryFirestore({\n [`hosts/${hostId}`]: { orgId: EVAL_ORG, ...(evalCase.siteName ? { displayName: evalCase.siteName } : {}) },\n ...Object.fromEntries(\n categories.map((category) => [`hosts/${hostId}/productCategories/${category.id}`, { name: category.name }]),\n ),\n })\n const outcome = await createAiJobProductsStep({ image: aiEvalMediaSeams(evalCase, options) })({\n job: { ...evalJob(evalCase, 'products'), hostId, inputs: aiEvalProductsInputs(evalCase) },\n stepIndex: 0,\n now: options.now ?? new Date(),\n firestore: store.firestore,\n modelFor: modelFor(options),\n })\n const proposal = aiProductsProposalOf(outcome.outputs[0])\n const stopped = outcome.refused ? 'refused' : outcome.failure\n return {\n source: 'recorded',\n scope: 'full',\n step: 'job.products',\n model: outcome.model,\n effort: outcome.effort ?? null,\n plan: null,\n answer: proposal ? aiEvalProductsAnswer(proposal) : null,\n usage: outcome.usage,\n steps: [recordedStep('job.products', outcome)],\n ...(proposal?.kind === 'copy' ? { photo: proposal.photo } : {}),\n ...(stopped ? { note: `stopped: ${stopped}` } : {}),\n }\n}\n\n/** Where production answers a kind no recorder covers. */\nexport type AiEvalUnrecordedDoor =\n /** A request route no job runs, by what it is and the module that answers it. */\n | { route: string; file: string }\n /** A job step no recorder drives yet, by its job kind and module. */\n | { step: AiJob['kind']; file: string }\n\n/**\n * Every kind no recorder covers, and the door that answers it in production\n * (AGL-3074), so a skipped brief says why truthfully. Modules are named from\n * the plugin's `src/lib`.\n */\nexport const AI_EVAL_UNRECORDED_DOORS: Readonly<Partial<Record<AiEvalKind, AiEvalUnrecordedDoor>>> = {\n section: { route: 'the copy assistant’s section mode', file: 'server/ai-assist.ts' },\n element: { route: 'the copy assistant’s element mode', file: 'server/ai-assist.ts' },\n blog: { route: 'the copy assistant’s blog mode', file: 'server/ai-assist.ts' },\n chat: { route: 'the console assistant', file: 'server/assist-chat.ts' },\n email: { step: 'email', file: 'jobs/ai-job-email-step.ts' },\n seo: { step: 'seo', file: 'jobs/ai-job-seo-step.ts' },\n insight: { step: 'insight', file: 'jobs/ai-job-insight-step.ts' },\n crm: { step: 'crm', file: 'jobs/ai-job-crm-step.ts' },\n experiment: { step: 'experiment', file: 'jobs/ai-job-experiment-step.ts' },\n}\n\n/** Why a brief of this kind is skipped: where its door is, and that no recorder drives it. */\nexport function aiEvalSkipReason(kind: AiEvalKind): string {\n const door = AI_EVAL_UNRECORDED_DOORS[kind]\n if (!door) return 'no recorder: none is registered for this kind'\n return 'route' in door\n ? `no recorder: the door that answers this kind is a request route (${door.route}, ${door.file}), not a job step`\n : `no recorder yet: this kind is answered by the ${door.step} job step (${door.file}), which no recorder drives`\n}\n\nfor (const kind of Object.keys(AI_EVAL_TREE_OUTPUT) as AiEvalKind[]) {\n // A section rewrite is the copy assistant's, a request route: no plan step.\n if (kind !== 'section' && kind !== 'email') registerAiEvalRecorder(kind, recordPlan)\n}\nregisterAiEvalRecorder('page', recordPage)\nregisterAiEvalRecorder('text', recordText)\nregisterAiEvalRecorder('theme', recordTheme)\nregisterAiEvalRecorder('workflow', recordWorkflow)\nfor (const kind of ['product', 'catalog', 'categories'] as const) registerAiEvalRecorder(kind, recordProducts)\n\n// ── The grader ────────────────────────────────────────────────────────────\n\nexport const AI_EVAL_RUBRIC_TOOL: AiTool = {\n name: 'grade_output',\n description: 'Grade the output against the brief it was built from.',\n strict: true,\n inputSchema: {\n type: 'object',\n additionalProperties: false,\n required: ['structure', 'copy', 'reuse', 'notes'],\n properties: {\n structure: {\n type: 'integer',\n description: 'From 1 (fails) to 5 (excellent): organized the way the brief needs, with nothing missing or extra.',\n },\n copy: {\n type: 'integer',\n description: 'From 1 to 5: the words fit the brief, the site and its audience, with no filler.',\n },\n reuse: {\n anyOf: [{ type: 'integer' }, { type: 'null' }],\n description: 'From 1 to 5: reuses what the site inventory lists before creating, and creates only what nothing listed can do. Null when the output places nothing.',\n },\n notes: { type: 'string', description: 'One or two sentences on the lowest grade.' },\n },\n },\n}\n\nexport const AI_EVAL_GRADER_INSTRUCTIONS: readonly AiSystemBlock[] = [\n {\n text:\n 'You grade an output an AI produced for a website builder, against the brief it was built from and the site it was built for. ' +\n 'Grade three things from 1 to 5: structure, copy and reuse, as the grade_output tool describes them. ' +\n 'A 3 is usable as it is; a 5 is what a careful professional would have made. Judge only what you are shown, and answer through grade_output.',\n },\n]\n\n/**\n * What a build plan is, for the grader that grades one (AGL-3022).\n *\n * A plan is the proposal a member confirms, not the document the generation\n * step writes afterwards, and `AI_BUILD_PLAN_TOOL` gives it nowhere to put a\n * node tree, a heading order, a landmark or a line of body copy. Graded\n * against a finished page it loses marks for every one of those, on structure\n * and on copy alike, and the grade then measures the schema rather than the\n * answer. So the grader is told the shape it is reading, and that the only\n * words a plan writes are the ones `aiPlanCopy` collects.\n *\n * Two facts it cannot read off the schema are stated as well. Only a page or\n * site job plans screens: the plan step tells a component, layout, template,\n * form or email job to plan none, so an empty `screens` on one of those is the\n * answer working, and a grader that does not know it marks the plan down for\n * doing what it was told. And a search is an element, never a form: a form\n * collects submissions, and a grader that does not know the platform has\n * search elements rewards a plan for creating a form to search with.\n */\nexport const AI_EVAL_PLAN_GRADER_NOTE =\n 'A build plan is not the finished output: it is the proposal a member confirms before anything is generated. ' +\n 'It holds only what it reuses by inventory id, what it creates and why, and its screens — each with a title, ' +\n 'slug, layout, template, nav flag, search title and description, and sections named with what they place and ' +\n 'how many items they hold. Only a page or site job plans screens: the plan of a component, layout, template, ' +\n 'form or email job has an empty screens list by design, and is never marked down for it. ' +\n 'A plan has no node tree, no heading order, no landmarks, no theme tokens, no field ' +\n 'labels or validation, and no body copy; all of those belong to the generation step that runs once the plan is ' +\n 'confirmed. Grade structure on whether the plan proposes the right screens, sections, fields and creations for ' +\n 'the brief. A search box is a Search Box element, or a Collection Search element over a collection\\'s entries, ' +\n 'and never a new form, because a form collects submissions: a plan that creates a form to search with has ' +\n 'proposed the wrong creation. Grade copy on the only words a plan writes: screen titles, search titles and ' +\n 'descriptions, and the names and rationales of what it creates. Do not mark a plan down for anything a plan ' +\n 'cannot hold.'\n\n/**\n * What the grader of a case with capabilities is told beside them (AGL-3040).\n *\n * A case that describes its workspace had its plan told what that workspace\n * may create, and a workspace that keeps no reusable components or saved\n * forms builds the only way it can: a list's repeated items drawn in one\n * section, the form carried by the page. A grader told none of that grades\n * the doctrine whole, and marks reuse down for exactly the build the workspace\n * required, as it marked down the first live recording of the Free brief.\n */\nexport const AI_EVAL_CAPABILITIES_GRADER_NOTE =\n '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.'\n\n/**\n * Beside that, where the workspace keeps no reusable components or saved\n * forms, which the capability lines have already said.\n */\nexport const AI_EVAL_INLINE_GRADER_NOTE =\n \"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.\"\n\n/**\n * What a section's `uses` can hold on such a workspace (AGL-3143).\n *\n * A section's `uses` names what the section PLACES, and the only things it\n * can name are an inventory id and a `new:<name>` creation. A workspace that\n * keeps no reusable components or saved forms has neither to name, and the\n * capability lines above have already refused the job the creations — so\n * every inline section leaves `uses` empty because it is the only answer it\n * can give. A grader that does not know it reads the empty list as a section\n * that places nothing and marks the plan down for being correct, which drags\n * the floors down for a reason that has nothing to do with the answer.\n */\nexport const AI_EVAL_INLINE_USES_GRADER_NOTE =\n \"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.\"\n\n/**\n * The workspace a case describes, as its grader reads it: the capability\n * lines the plan step was sent, narrowed to what the job builds the way the\n * step narrows them, and the notes on grading against them. `null` for a\n * case that describes no workspace, whose output is held to the doctrine\n * whole.\n */\nexport function aiEvalGraderCapabilities(evalCase: AiEvalCase): string | null {\n if (!evalCase.capabilities) return null\n const scope = AI_JOB_PLAN_SCOPES[evalCase.kind as AiJob['kind']] ?? null\n const capabilities = aiPlanCapabilitiesForJob(evalCase.capabilities, scope)\n return [\n ...aiPlanCapabilityLines(capabilities),\n AI_EVAL_CAPABILITIES_GRADER_NOTE,\n ...(capabilities.reusableComponents\n ? []\n : [AI_EVAL_INLINE_GRADER_NOTE, AI_EVAL_INLINE_USES_GRADER_NOTE]),\n ].join('\\n')\n}\n\n/**\n * What the grader of a built page is told beside it (AGL-3073).\n *\n * A page's tree holds only what the page adds. The site's header, navigation\n * and footer are its layout's; the one main landmark is placed when the page\n * is composed (`stampDocumentLandmark`), on the layout's slot where the page\n * renders, or on the page's root when it renders inside none; and its address\n * and listing are fields of its screen. A grader shown the tree alone marks a\n * page down for a layout, a landmark and a listing the page has.\n */\nexport const AI_EVAL_PAGE_GRADER_NOTE =\n 'A page is built inside its layout and published as a screen, so its tree holds only what the page adds: ' +\n \"the site's header, navigation and footer are the layout's; the page's one main landmark is placed when it is \" +\n \"published, on the layout's slot where the page renders, or on the page's root when it has no layout; and its \" +\n 'address, search title and description are fields of its screen. Grade the page as built with all of them, as ' +\n 'listed above, and never mark it down for a layout, a landmark, an address or a listing its tree does not repeat.'\n\n/** The most elements a layout's outline lists; the rest are counted. */\nexport const AI_EVAL_LAYOUT_OUTLINE_MAX_LINES = 40\n\n/** The most characters of an element's own text an outline quotes. */\nconst AI_EVAL_OUTLINE_TEXT_MAX_CHARS = 48\n\ntype Loose = Record<string, unknown>\n\nconst isLoose = (value: unknown): value is Loose =>\n typeof value === 'object' && value !== null && !Array.isArray(value)\n\nconst looseList = (value: unknown): Loose[] => (Array.isArray(value) ? value.filter(isLoose) : [])\n\nconst looseText = (value: unknown): string => (typeof value === 'string' ? value.replace(/\\s+/g, ' ').trim() : '')\n\n/** An element of an outline: what it renders as, its component, and its own text, quoted short. */\nfunction outlineLine(node: Loose): string {\n const props = isLoose(node['props']) ? node['props'] : {}\n const element = looseText(props['component']) || looseText(props['element'])\n const text = looseText(props['children'])\n const quoted = text\n ? ` \"${text.length > AI_EVAL_OUTLINE_TEXT_MAX_CHARS ? `${text.slice(0, AI_EVAL_OUTLINE_TEXT_MAX_CHARS)}…` : text}\"`\n : ''\n const slot = node['componentId'] === LAYOUT_SLOT_COMPONENT_ID ? ' ← the page renders here' : ''\n return `${element ? `${element} · ` : ''}${String(node['componentId'] ?? '?')}${quoted}${slot}`\n}\n\n/**\n * A layout as its page's grader reads it (AGL-3073): an element a line,\n * indented by depth, named by the element it renders as and its component,\n * with its own text quoted short. The main landmark is placed where a\n * published page places it, by the function that places it there.\n */\nexport function aiEvalLayoutOutline(tree: { rootId: string; nodes: Record<string, unknown> }): string {\n const nodes = stampDocumentLandmark(tree.nodes as never) as Record<string, unknown>\n const lines: string[] = []\n const seen = new Set<string>()\n let unlisted = 0\n const visit = (id: string, depth: number): void => {\n const node = nodes[id]\n if (!isLoose(node) || seen.has(id)) return\n seen.add(id)\n if (lines.length < AI_EVAL_LAYOUT_OUTLINE_MAX_LINES) lines.push(`${' '.repeat(depth)}${outlineLine(node)}`)\n else unlisted += 1\n for (const child of Array.isArray(node['nodes']) ? node['nodes'] : []) {\n if (typeof child === 'string') visit(child, depth + 1)\n }\n }\n visit(tree.rootId, 0)\n return [...lines, ...(unlisted ? [`… and ${unlisted} more elements`] : [])].join('\\n')\n}\n\n/**\n * The plan a built answer came from, as its grader reads it (AGL-3073): what\n * it reuses and creates, and each screen's sections in order, with what each\n * places and how many items it shows. `null` for an answer with no plan.\n */\nexport function aiEvalPlanOutline(plan: unknown): string | null {\n if (!isLoose(plan)) return null\n const lines = ['The plan it was built from, as the member confirmed it:']\n for (const entry of looseList(plan['reuse'])) {\n lines.push(`- reuses the ${looseText(entry['kind'])} ${looseText(entry['id'])}: ${looseText(entry['purpose'])}`)\n }\n for (const entry of looseList(plan['create'])) {\n const fields = Array.isArray(entry['fields']) ? entry['fields'].map(looseText).filter(Boolean) : []\n lines.push(\n `- creates the ${looseText(entry['kind'])} \"${looseText(entry['name'])}\": ${looseText(entry['why'])}${\n fields.length ? ` Holds: ${fields.join('; ')}.` : ''\n }`,\n )\n }\n for (const screen of looseList(plan['screens'])) {\n lines.push(`- the screen \"${looseText(screen['title'])}\", its sections in order:`)\n looseList(screen['sections']).forEach((section, index) => {\n const uses = Array.isArray(section['uses']) ? section['uses'].map(looseText).filter(Boolean) : []\n const items = Number(section['items'])\n lines.push(\n ` ${index + 1}. ${looseText(section['name'])}${uses.length ? `, placing ${uses.join(', ')}` : ''}${\n items > 0 ? `, ${items} ${items === 1 ? 'item' : 'items'}` : ''\n }`,\n )\n })\n }\n return lines.length > 1 ? lines.join('\\n') : null\n}\n\n/** A screen's address as a visitor reads it. */\nfunction addressOf(slug: string): string {\n return slug.startsWith('/') ? slug : `/${slug}`\n}\n\n/** A listing value quoted, or said to be missing. */\nfunction listingValue(value: string | null | undefined): string {\n return value ? `\"${value}\"` : 'none'\n}\n\n/**\n * A built page's screen and layout, as its grader reads them (AGL-3073). A\n * recording that kept the draft's screen gives its stored address and listing\n * and the layout it renders inside, outlined from its tree. One made before\n * that was kept gives its plan's screen instead, which is what the page step\n * builds from, and says so.\n */\nexport function aiEvalBuiltPage(answer: AiEvalRecordedAnswer): string | null {\n const recorded = answer.screen\n const plan = isLoose(answer.plan) ? answer.plan : null\n const planned = looseList(plan?.['screens'])[0]\n if (!recorded && !planned) return null\n if (recorded) {\n const layout = recorded.layout\n return [\n 'The page as built:',\n `- address: ${addressOf(recorded.slug)}`,\n `- search title: ${listingValue(recorded.seoTitle)}`,\n `- search description: ${listingValue(recorded.seoDescription)}`,\n `- navigation: ${recorded.nav ? 'an entry for the page is proposed' : 'no entry is proposed'}`,\n !layout\n ? \"- layout: none, so the page's root is its main landmark\"\n : layout.tree\n ? `- layout: \"${layout.name}\", ${layout.built ? 'built by this job before the page' : 'which the site already had'}. Its outline:\\n${aiEvalLayoutOutline(layout.tree)\n .split('\\n')\n .map((line) => ` ${line}`)\n .join('\\n')}`\n : `- layout: \"${layout.name}\", which the site already has; the page renders in its slot`,\n ].join('\\n')\n }\n const reference = looseText(planned['layout'])\n const created = reference.startsWith('new:')\n ? looseList(plan?.['create']).find(\n (entry) => entry['kind'] === 'layout' && looseText(entry['name']) === reference.slice('new:'.length),\n )\n : undefined\n const builtByJob = (answer.steps ?? []).some((step) => step.step === 'job.layout')\n // What the layout holds is on the plan's own line above; it is not repeated.\n const layout = !reference\n ? \"- layout: none, so the page's root is its main landmark\"\n : created\n ? `- layout: \"${looseText(created['name'])}\", which the plan creates${\n builtByJob ? ' and this job built before the page' : ''\n }. A layout this job builds holds one Layout Slot, where the page renders, and the slot is the page's main landmark; the recording kept no tree of it`\n : `- layout: ${reference}, which the site already has; the page renders in its slot`\n return [\n \"The page as its plan built it (the recording kept no record of the draft's screen):\",\n `- address: ${addressOf(looseText(planned['slug']))}`,\n `- search title, as planned: ${listingValue(looseText(planned['seoTitle']))}`,\n `- search description, as planned: ${listingValue(looseText(planned['seoDescription']))}`,\n `- navigation: ${planned['nav'] === true ? 'an entry for the page is proposed' : 'no entry is proposed'}`,\n layout,\n ].join('\\n')\n}\n\n/** Keys a stored node keeps for the store: its own id, its parent, its node type and its plugin. */\nfunction graderNode(id: string, node: unknown): unknown {\n if (!isLoose(node)) return node\n const kept: Loose = {}\n for (const [key, value] of Object.entries(node)) {\n if (key === 'parentId' || key === 'pluginId') continue\n if (key === '$id' && value === id) continue\n if (key === 'type' && value === 'node') continue\n kept[key] = value\n }\n return kept\n}\n\n/**\n * An answer's output as its grader reads it: copy as written, and anything\n * else as JSON, a tree's nodes without the keys the store keeps for itself\n * (AGL-3073). Those are about a third of a recorded page, and a grade reads\n * none of them: a node's id is its key and its parent is the node that lists\n * it.\n */\nexport function aiEvalGraderOutput(output: unknown): string {\n if (typeof output === 'string') return output\n const tree = isLoose(output) && isLoose(output['tree']) ? output['tree'] : null\n if (!isLoose(output) || !tree || !isLoose(tree['nodes'])) return JSON.stringify(output)\n const nodes = Object.fromEntries(Object.entries(tree['nodes']).map(([id, node]) => [id, graderNode(id, node)]))\n return JSON.stringify({ ...output, tree: { ...tree, nodes } })\n}\n\n/**\n * What the grader of an answer written from more than its brief is shown of\n * the request (AGL-3074): the user turn the kind's step sends, built from the\n * case by the step's own prompt builder — a product and the categories it may\n * go in, the categories a store already has, or what an automation draft or\n * explanation was asked from. A grader that is not shown them grades copy\n * against a product it never saw, and an explanation against an automation it\n * never read. `null` for a kind whose request is its brief and its site.\n */\nexport function aiEvalGraderRequest(evalCase: AiEvalCase, answer: AiEvalRecordedAnswer): string | null {\n if (evalCase.kind === 'product') {\n return evalCase.product\n ? aiProductCopyPrompt({\n store: evalCase.siteName ?? '',\n product: evalCase.product.facts,\n categories: evalCase.product.categories,\n photo: answer.photo === 'read',\n })\n : null\n }\n if (evalCase.kind === 'categories') {\n return aiCategoriesPrompt({\n store: evalCase.siteName ?? '',\n brief: evalCase.brief,\n existingCategoryNames: evalCase.existingCategoryNames ?? [],\n })\n }\n if (evalCase.kind === 'workflow') {\n const [turn] = aiEvalWorkflowGeneration(evalCase, answer.model ?? aiJobWorkflowModel()).messages\n return typeof turn?.content === 'string' ? turn.content : null\n }\n return null\n}\n\n/** What the grader of product copy written with its photo in view is told beside the photo (AGL-3074). */\nexport const AI_EVAL_PHOTO_GRADER_NOTE =\n \"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.\"\n\n/** What the grader is told when the photo the copy was written with cannot be shown to it. */\nexport const AI_EVAL_PHOTO_UNSHOWN_GRADER_NOTE =\n \"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.\"\n\n/**\n * The grader's user turn: the brief, its site, the workspace where the case\n * describes one, the request beyond the brief, the plan a built answer came\n * from, the screen and layout a built page was built as, and the answer.\n * `shown.photo` says the product's photo rides beside this turn.\n */\nexport function aiEvalGraderPrompt(\n evalCase: AiEvalCase,\n answer: AiEvalRecordedAnswer,\n shown: { photo?: boolean } = {},\n): string {\n const planScope = answer.scope === 'plan'\n const output = planScope ? answer.plan : answer.answer\n const workspace = aiEvalGraderCapabilities(evalCase)\n const request = planScope ? null : aiEvalGraderRequest(evalCase, answer)\n const plan = planScope ? null : aiEvalPlanOutline(answer.plan)\n const page = !planScope && evalCase.kind === 'page' ? aiEvalBuiltPage(answer) : null\n return [\n `Output kind: ${evalCase.kind}${planScope ? ' (its build plan)' : ''}`,\n ...(planScope ? [AI_EVAL_PLAN_GRADER_NOTE] : []),\n `Brief: ${evalCase.brief}`,\n aiSiteInventoryBlock(evalCase.inventory),\n ...(workspace ? [workspace] : []),\n ...(request ? [`The request the answer was written from:\\n${request}`] : []),\n ...(answer.photo === 'read' ? [shown.photo ? AI_EVAL_PHOTO_GRADER_NOTE : AI_EVAL_PHOTO_UNSHOWN_GRADER_NOTE] : []),\n ...(plan ? [plan] : []),\n ...(page ? [page, AI_EVAL_PAGE_GRADER_NOTE] : []),\n `Output:\\n${aiEvalGraderOutput(output)}`,\n ].join('\\n\\n')\n}\n\n/** A grade tool call read as a rubric; `null` when a grade is missing. */\nexport function readAiEvalGrade(\n answer: Record<string, unknown>,\n grader: string,\n): AiEvalRubric | null {\n const grade = (value: unknown): number | null => {\n const parsed = Number(value)\n return Number.isInteger(parsed) && parsed >= 1 && parsed <= 5 ? parsed : null\n }\n const structure = grade(answer['structure'])\n const copy = grade(answer['copy'])\n if (structure === null || copy === null) return null\n return {\n structure,\n copy,\n reuse: answer['reuse'] === null ? null : grade(answer['reuse']),\n grader,\n ...(typeof answer['notes'] === 'string' && answer['notes'] ? { notes: answer['notes'] } : {}),\n }\n}\n\n/** Grade one recorded answer with a stronger model, through the doctrine's loop. */\nexport async function gradeAiEvalCandidate(\n evalCase: AiEvalCase,\n answer: AiEvalRecordedAnswer,\n options: AiEvalLiveOptions,\n): Promise<AiEvalRubric> {\n const provider = options.provider ?? resolveAiProvider()\n const model = options.graderModel ?? (provider ? aiDefaultModelFor(provider.id, 'deep') : undefined)\n if (!model) throw new Error('no grader model: the provider serves no deep tier and none was named')\n // Copy written with the product's photo in view is graded with the same\n // picture, where the grader's model reads one (AGL-3074).\n const photo =\n answer.photo === 'read' && provider && aiModelReadsImages(provider, model)\n ? await aiEvalCasePhoto(evalCase, options)\n : null\n const prompt = aiEvalGraderPrompt(evalCase, answer, { photo: Boolean(photo) })\n const result = await runValidatedGeneration(\n 'eval-grade',\n withProvider(\n {\n model,\n instructions: AI_EVAL_GRADER_INSTRUCTIONS,\n messages: [\n { role: 'user' as const, content: photo ? [photo, { type: 'text' as const, text: prompt }] : prompt },\n ],\n tool: AI_EVAL_RUBRIC_TOOL,\n maxTokens: 2_000,\n thinking: 'adaptive' as const,\n check: (raw: Record<string, unknown>) => {\n const rubric = readAiEvalGrade(raw, model)\n return rubric\n ? { value: rubric, violations: [] }\n : {\n value: null,\n violations: [{ rule: null, code: 'grade-missing', message: 'Every grade is a whole number from 1 to 5.' }],\n }\n },\n },\n options,\n ),\n )\n if (result.status !== 'ok') {\n return { structure: 1, copy: 1, reuse: null, grader: model, notes: `the grader returned ${result.status}` }\n }\n return result.value\n}\n\n/** Which half of a case's run threw: asking for the answer, or grading it. */\nexport type AiEvalLiveStep = 'record' | 'grade'\n\n/** A brief whose run threw, as the report keeps it. */\nexport interface AiEvalLiveFailure {\n caseId: string\n kind: AiEvalKind\n step: AiEvalLiveStep\n /** What was thrown, as a sentence. */\n error: string\n /** The provider's request id, when the throw carried one — the vendor log's join key. */\n requestId: string | null\n}\n\nexport interface AiEvalLiveReport {\n recorded: Array<{ caseId: string; kind: AiEvalKind; candidate: AiEvalCandidate }>\n skipped: Array<{ caseId: string; kind: AiEvalKind; why: string }>\n /** The briefs whose run threw; empty when every brief a recorder covers came back. */\n failed: AiEvalLiveFailure[]\n}\n\n/** The vendor's request id off a thrown `UpstreamServiceError`, when it carried one. */\nfunction requestIdOfThrown(error: unknown): string | null {\n const id = (error as { requestId?: unknown } | null)?.requestId\n return typeof id === 'string' && id ? id : null\n}\n\nfunction messageOfThrown(error: unknown): string {\n return error instanceof Error ? `${error.name}: ${error.message}` : String(error)\n}\n\n/**\n * Record and grade an answer for every brief a recorder covers. Refused\n * before anything else unless `AI_EVAL_LIVE=1` names the run, and before any\n * request when a brief it would record names media the run cannot read.\n *\n * ONE BRIEF'S FAILURE IS NOT THE RUN'S (AGL-3143). A run is owner-approved\n * spend, and a provider that refuses one brief — a tool it will not compile,\n * a rate limit — used to end the whole run with the answers already paid for\n * still in memory and never written. Each brief is run on its own instead:\n * one that throws is kept as a failure naming what was thrown, the vendor's\n * request id and which half of its run threw, and the briefs behind it are\n * still recorded. The caller writes what came back and decides what a\n * non-empty `failed` means for its exit status.\n *\n * A brief whose GRADE threw is in both halves: recorded, with its grade\n * marked missing, and failed, naming what the grader threw.\n */\nexport async function recordAiEvalLive(\n cases: readonly AiEvalCase[],\n options: AiEvalLiveOptions,\n): Promise<AiEvalLiveReport> {\n if (!aiEvalLiveAllowed(options.env)) throw new AiEvalLiveRefusedError()\n const unreadable = cases.filter((evalCase) => evalCase.media && aiEvalRecorderFor(evalCase.kind) && !options.readFixture)\n if (unreadable.length) {\n throw new Error(\n `${unreadable.map((evalCase) => evalCase.id).join(', ')} name media, and this run was given no readFixture to read them with`,\n )\n }\n const report: AiEvalLiveReport = { recorded: [], skipped: [], failed: [] }\n for (const evalCase of cases) {\n const recorder = aiEvalRecorderFor(evalCase.kind)\n if (!recorder) {\n report.skipped.push({ caseId: evalCase.id, kind: evalCase.kind, why: aiEvalSkipReason(evalCase.kind) })\n continue\n }\n const failure = (step: AiEvalLiveStep, error: unknown): void => {\n report.failed.push({\n caseId: evalCase.id,\n kind: evalCase.kind,\n step,\n error: messageOfThrown(error),\n requestId: requestIdOfThrown(error),\n })\n }\n let answer: AiEvalRecordedAnswer\n try {\n answer = await recorder(evalCase, options)\n } catch (error) {\n failure('record', error)\n continue\n }\n // A GRADER THAT THROWS DOES NOT TAKE THE ANSWER WITH IT (AGL-3143). The\n // brief is already paid for by here, and grading is a second request that\n // can fail on its own — a rate limit, a tool the provider will not\n // compile. The answer is recorded with its grade marked missing, and the\n // throw is still reported, so the run exits non-zero without the next\n // one having to buy this answer again.\n try {\n const rubric = await gradeAiEvalCandidate(evalCase, answer, options)\n report.recorded.push({ caseId: evalCase.id, kind: evalCase.kind, candidate: { ...answer, rubric } })\n } catch (error) {\n report.recorded.push({ caseId: evalCase.id, kind: evalCase.kind, candidate: { ...answer, rubric: null } })\n failure('grade', error)\n }\n }\n return report\n}\n"],"names":["assistCreditsFromUsd","LAYOUT_SLOT_COMPONENT_ID","stampDocumentLandmark","decodeStoredNodes","CANVAS_ROOT_ELEMENT_ID","createAiJobComponentStep","aiJobDraftId","aiMintJobDraftIds","createAiJobFormStep","createAiJobLayoutStep","aiPageJobUnits","createAiJobPageStep","AI_JOB_PLAN_SCOPES","createAiJobPlanStep","createAiJobProductsStep","aiSitePendingUnits","runAiJobTextStep","aiJobThemeCheck","aiJobThemeGeneration","aiJobThemeMode","aiJobWorkflowDraftGeneration","aiJobWorkflowExplainGeneration","aiJobWorkflowModel","readAiProductImage","emptyAiAutomationRecords","aiActionOutline","aiActionRecordKinds","aiRunOutline","aiPlanCapabilitiesForJob","aiPlanCapabilityLines","aiProductsJobInputs","aiProductsProposalOf","aiDefaultModelFor","aiModelForStep","resolveAiProvider","aiSiteInventoryBlock","runValidatedGeneration","AI_EVAL_AUTOMATION_CAPABILITIES","AI_EVAL_SITE_ID","AI_EVAL_TREE_OUTPUT","aiEvalMemoryFirestore","aiEvalMemoryInventory","aiCategoriesPrompt","aiProductCopyPrompt","aiModelReadsImages","AI_EVAL_LIVE_ENV","AI_EVAL_LIVE_REFUSAL","AiEvalLiveRefusedError","Error","name","aiEvalLiveAllowed","env","AI_EVAL_CASES_ENV","aiEvalCasesNamed","cases","named","split","map","id","trim","filter","Boolean","length","unknown","some","evalCase","join","includes","recorders","Map","registerAiEvalRecorder","kind","recorder","set","aiEvalRecorderFor","get","EVAL_ORG","evalJob","now","Date","draftIds","$id","orgId","hostId","inventory","status","brief","inputs","steps","creditsSpent","outputs","creditsReserved","createdBy","createdAt","updatedAt","expiresAt","modelFor","options","step","model","withProvider","input","provider","inventoryOf","evalPlanStep","readInventory","findPlansByKey","readCapabilities","capabilities","admissionRefusal","planOf","outcome","plan","reuse","create","screens","recordPlan","job","stepIndex","firestore","source","scope","effort","answer","usage","note","review","reason","message","undefined","AI_EVAL_PAGE_MAX_PASSES","recordedStep","estCostUsd","credits","totalUsage","reduce","sum","inputTokens","outputTokens","cacheReadTokens","cacheWriteTokens","evalOrgDocument","reusableComponents","billingStatus","recordPage","planned","org","site","siteName","displayName","Object","fromEntries","row","slug","context","planOnly","failure","confirmed","confirmedAt","confirmedBy","readers","docs","duplicate","ok","error","creations","layout","form","component","generate","runnerFor","units","stopped","pass","unit","jobKind","output","resource","push","refused","continue","screenPath","nodes","storedTree","built","screen","recordedScreen","find","entry","tree","rootId","storedText","value","draftPath","draft","version","String","seo","layoutId","layoutPath","slice","listed","layouts","seoTitle","seoDescription","nav","proposal","recordText","text","recordTheme","raw","generation","mode","theme","siteTheme","themeSource","brand","result","check","aiEvalWorkflowGeneration","records","automationRecords","automation","automationCapabilities","action","read","entries","rows","run","outline","recordWorkflow","rawOutput","aiEvalSiteId","aiEvalProductsInputs","target","product","facts","fixtureContentType","file","extension","lastIndexOf","toLowerCase","aiEvalMediaSeams","readBytes","_firestore","location","own","isOrg","scopeId","media","mediaId","readFixture","buffer","contentType","aiEvalCasePhoto","imageUrl","image","aiEvalProductsAnswer","values","products","categories","discounts","discount","code","valuePct","valueCents","minimumOrderUsd","minSubtotalCents","why","recordProducts","existingCategoryNames","index","store","category","photo","AI_EVAL_UNRECORDED_DOORS","section","route","element","blog","chat","email","insight","crm","experiment","aiEvalSkipReason","door","keys","AI_EVAL_RUBRIC_TOOL","description","strict","inputSchema","type","additionalProperties","required","properties","structure","copy","anyOf","notes","AI_EVAL_GRADER_INSTRUCTIONS","AI_EVAL_PLAN_GRADER_NOTE","AI_EVAL_CAPABILITIES_GRADER_NOTE","AI_EVAL_INLINE_GRADER_NOTE","AI_EVAL_INLINE_USES_GRADER_NOTE","aiEvalGraderCapabilities","AI_EVAL_PAGE_GRADER_NOTE","AI_EVAL_LAYOUT_OUTLINE_MAX_LINES","AI_EVAL_OUTLINE_TEXT_MAX_CHARS","isLoose","Array","isArray","looseList","looseText","replace","outlineLine","node","props","quoted","slot","aiEvalLayoutOutline","lines","seen","Set","unlisted","visit","depth","has","add","repeat","child","aiEvalPlanOutline","fields","forEach","uses","items","Number","addressOf","startsWith","listingValue","aiEvalBuiltPage","recorded","line","reference","created","builtByJob","graderNode","kept","key","aiEvalGraderOutput","JSON","stringify","aiEvalGraderRequest","turn","messages","content","AI_EVAL_PHOTO_GRADER_NOTE","AI_EVAL_PHOTO_UNSHOWN_GRADER_NOTE","aiEvalGraderPrompt","shown","planScope","workspace","request","page","readAiEvalGrade","grader","grade","parsed","isInteger","gradeAiEvalCandidate","graderModel","prompt","instructions","role","tool","maxTokens","thinking","rubric","violations","rule","requestIdOfThrown","requestId","messageOfThrown","recordAiEvalLive","unreadable","report","skipped","failed","caseId","candidate"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,oBAAoB,QAAQ,wCAAuC;AAC5E,SAASC,wBAAwB,QAAQ,8CAA6C;AACtF,SAASC,qBAAqB,QAAQ,2CAA0C;AAChF,SAASC,iBAAiB,QAAQ,sCAAqC;AACvE,SAASC,sBAAsB,QAAQ,2CAA0C;AACjF,SAASC,wBAAwB,QAAQ,mCAA+B;AACxE,SAASC,YAAY,EAAEC,iBAAiB,QAAQ,8BAA0B;AAC1E,SAASC,mBAAmB,QAAQ,8BAA0B;AAC9D,SAASC,qBAAqB,QAAQ,gCAA4B;AAClE,SAASC,cAAc,EAAEC,mBAAmB,QAAQ,8BAA0B;AAC9E,SAASC,kBAAkB,EAAEC,mBAAmB,QAAQ,8BAA0B;AAClF,SAASC,uBAAuB,QAAQ,kCAA8B;AACtE,SAASC,kBAAkB,QAAQ,8BAA0B;AAE7D,SAASC,gBAAgB,QAAQ,8BAA0B;AAC3D,SAASC,eAAe,EAAEC,oBAAoB,EAAEC,cAAc,QAAQ,+BAA2B;AACjG,SACEC,4BAA4B,EAC5BC,8BAA8B,EAC9BC,kBAAkB,QACb,kCAA8B;AACrC,SAASC,kBAAkB,QAAkC,8BAA0B;AACvF,SAASC,wBAAwB,QAAkC,kCAA8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AS;QACpG,EAAE,OAAOrN,OAAO;YACd6N,OAAO5C,QAAQ,CAACnK,IAAI,CAAC;gBAAEkN,QAAQnU,SAASP,EAAE;gBAAEa,MAAMN,SAASM,IAAI;gBAAE8T,WAAW,aAAK1Q;oBAAQ8P,QAAQ;;YAAO;YACxG7N,QAAQ,SAASQ;QACnB;IACF;IACA,OAAO6N;AACT"}
@@ -0,0 +1,51 @@
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
+ /**
18
+ * A site in memory, for a live eval run that builds a whole job (AGL-3030).
19
+ *
20
+ * A recording is worth having only when it measures what production sends,
21
+ * so the page recorder runs the page job's own step runners — which write
22
+ * their drafts through the draft writer — rather than a copy of their
23
+ * prompts. Those runners take the machine's Firestore handle; this is a handle
24
+ * that keeps every document in a map instead, for the length of one recording.
25
+ *
26
+ * It answers exactly the calls the draft writer and the generation steps
27
+ * make: a document read, a projection of a collection with its limit, and a
28
+ * transaction that reads before it creates or updates. Anything else throws,
29
+ * so a step that starts reading something new fails the recording loudly
30
+ * rather than reading nothing. It never runs in production: nothing a
31
+ * deployment loads imports it.
32
+ */
33
+ import type { AiSiteInventory } from '../model/ai-site-inventory';
34
+ type Data = Record<string, unknown>;
35
+ export interface AiEvalMemoryFirestore {
36
+ /** The handle a step runner is given. */
37
+ firestore: FirebaseFirestore.Firestore;
38
+ /** Every document by its path, as the runners left it. */
39
+ docs: Map<string, Data>;
40
+ }
41
+ /** A Firestore handle over an in-memory map, seeded with documents by path. */
42
+ export declare function aiEvalMemoryFirestore(seed?: Record<string, Data>): AiEvalMemoryFirestore;
43
+ /**
44
+ * A site's inventory as the reader would list it from the documents in
45
+ * memory (AGL-3031): the case's own rows, and every layout, form and
46
+ * component a job has written there since. A page job builds its creations
47
+ * before its page, and the page is held to placing them, so the inventory it
48
+ * reads has to change as the job builds — as the real reader's does.
49
+ */
50
+ export declare function aiEvalMemoryInventory(base: AiSiteInventory, docs: ReadonlyMap<string, Data>): AiSiteInventory;
51
+ export {};
@@ -0,0 +1,183 @@
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
+ * A site in memory, for a live eval run that builds a whole job (AGL-3030).
18
+ *
19
+ * A recording is worth having only when it measures what production sends,
20
+ * so the page recorder runs the page job's own step runners — which write
21
+ * their drafts through the draft writer — rather than a copy of their
22
+ * prompts. Those runners take the machine's Firestore handle; this is a handle
23
+ * that keeps every document in a map instead, for the length of one recording.
24
+ *
25
+ * It answers exactly the calls the draft writer and the generation steps
26
+ * make: a document read, a projection of a collection with its limit, and a
27
+ * transaction that reads before it creates or updates. Anything else throws,
28
+ * so a step that starts reading something new fails the recording loudly
29
+ * rather than reading nothing. It never runs in production: nothing a
30
+ * deployment loads imports it.
31
+ */ import { _ as _extends } from "@swc/helpers/_/_extends";
32
+ import { aiBracketedFacts } from "./ai-doctrine-validators.js";
33
+ function valueAt(data, path) {
34
+ return path.split('.').reduce((value, key)=>value && typeof value === 'object' ? value[key] : undefined, data);
35
+ }
36
+ function setAt(data, dotted, value) {
37
+ const keys = dotted.split('.');
38
+ let cursor = data;
39
+ for (const key of keys.slice(0, -1)){
40
+ var _cursor_key;
41
+ cursor[key] = _extends({}, (_cursor_key = cursor[key]) != null ? _cursor_key : {});
42
+ cursor = cursor[key];
43
+ }
44
+ cursor[keys[keys.length - 1]] = value;
45
+ }
46
+ /** A Firestore handle over an in-memory map, seeded with documents by path. */ export function aiEvalMemoryFirestore(seed = {}) {
47
+ const docs = new Map(Object.entries(seed));
48
+ const snapshotOf = (path)=>{
49
+ const data = docs.get(path);
50
+ return {
51
+ id: path.split('/').pop(),
52
+ exists: data !== undefined,
53
+ data: ()=>data,
54
+ get: (field)=>data ? valueAt(data, field) : undefined
55
+ };
56
+ };
57
+ const queryOf = (path, max = Number.POSITIVE_INFINITY)=>({
58
+ kind: 'query',
59
+ // The products step reads a site's categories a page at a time (AGL-3074).
60
+ limit: (count)=>queryOf(path, Math.min(max, count)),
61
+ get: async ()=>({
62
+ docs: [
63
+ ...docs.keys()
64
+ ].filter((key)=>key.startsWith(`${path}/`) && !key.slice(path.length + 1).includes('/')).sort().slice(0, max).map(snapshotOf)
65
+ })
66
+ });
67
+ const collectionRef = (path)=>{
68
+ const query = queryOf(path);
69
+ return {
70
+ path,
71
+ doc: (id)=>docRef(`${path}/${id}`),
72
+ select: ()=>query,
73
+ get: query.get
74
+ };
75
+ };
76
+ const docRef = (path)=>({
77
+ kind: 'doc',
78
+ path,
79
+ id: path.split('/').pop(),
80
+ collection: (name)=>collectionRef(`${path}/${name}`),
81
+ get: async ()=>snapshotOf(path)
82
+ });
83
+ const firestore = {
84
+ collection: (name)=>collectionRef(name),
85
+ runTransaction: async (fn)=>{
86
+ const writes = [];
87
+ const result = await fn({
88
+ get: async (target)=>target.kind === 'query' ? target.get() : snapshotOf(target.path),
89
+ create: (ref, data)=>writes.push(()=>{
90
+ if (docs.has(ref.path)) throw new Error(`6 ALREADY_EXISTS: ${ref.path}`);
91
+ docs.set(ref.path, data);
92
+ }),
93
+ update: (ref, patch)=>writes.push(()=>{
94
+ const current = docs.get(ref.path);
95
+ if (!current) throw new Error(`5 NOT_FOUND: ${ref.path}`);
96
+ const next = _extends({}, current);
97
+ for (const [key, value] of Object.entries(patch))setAt(next, key, value);
98
+ docs.set(ref.path, next);
99
+ }),
100
+ set: (ref, data)=>writes.push(()=>{
101
+ var _docs_get;
102
+ docs.set(ref.path, _extends({}, (_docs_get = docs.get(ref.path)) != null ? _docs_get : {}, data));
103
+ })
104
+ });
105
+ for (const write of writes)write();
106
+ return result;
107
+ }
108
+ };
109
+ return {
110
+ firestore: firestore,
111
+ docs
112
+ };
113
+ }
114
+ /**
115
+ * A site's inventory as the reader would list it from the documents in
116
+ * memory (AGL-3031): the case's own rows, and every layout, form and
117
+ * component a job has written there since. A page job builds its creations
118
+ * before its page, and the page is held to placing them, so the inventory it
119
+ * reads has to change as the job builds — as the real reader's does.
120
+ */ export function aiEvalMemoryInventory(base, docs) {
121
+ const rows = (collection)=>[
122
+ ...docs.entries()
123
+ ].filter(([path])=>path.startsWith(`hosts/${base.hostId}/${collection}/`) && path.split('/').length === 4).map(([path, data])=>({
124
+ id: path.split('/')[3],
125
+ data
126
+ })).filter(({ data })=>data['deletedAt'] == null);
127
+ const listed = (ids)=>new Set(ids.map((row)=>row.id));
128
+ const layouts = listed(base.layouts);
129
+ const components = listed(base.components);
130
+ const forms = listed(base.forms);
131
+ return _extends({}, base, {
132
+ layouts: [
133
+ ...base.layouts,
134
+ ...rows('layouts').filter(({ id })=>!layouts.has(id)).map(({ id, data })=>{
135
+ var _data_displayName;
136
+ return {
137
+ id,
138
+ name: String((_data_displayName = data['displayName']) != null ? _data_displayName : id),
139
+ parentId: null
140
+ };
141
+ })
142
+ ],
143
+ components: [
144
+ ...base.components,
145
+ ...rows('components').filter(({ id, data })=>!components.has(id) && Boolean(data['rootId'] || data['versionId'])).map(({ id, data })=>{
146
+ var _data_props, _data_displayName;
147
+ const props = ((_data_props = data['props']) != null ? _data_props : []).filter((prop)=>typeof prop.name === 'string' && prop.name);
148
+ const bracketedDefaults = Object.fromEntries(props.map((prop)=>[
149
+ prop.name,
150
+ aiBracketedFacts([
151
+ typeof prop.defaultValue === 'string' ? prop.defaultValue : ''
152
+ ])
153
+ ]).filter(([, facts])=>facts.length));
154
+ return _extends({
155
+ id,
156
+ name: String((_data_displayName = data['displayName']) != null ? _data_displayName : id),
157
+ props: Object.fromEntries(props.map((prop)=>[
158
+ prop.name,
159
+ prop.type || 'text'
160
+ ]))
161
+ }, Object.keys(bracketedDefaults).length ? {
162
+ bracketedDefaults
163
+ } : {});
164
+ })
165
+ ],
166
+ forms: [
167
+ ...base.forms,
168
+ ...rows('forms').filter(({ id })=>!forms.has(id)).map(({ id, data })=>{
169
+ var _data_displayName, _data_fields;
170
+ return {
171
+ id,
172
+ name: String((_data_displayName = data['displayName']) != null ? _data_displayName : id),
173
+ fields: ((_data_fields = data['fields']) != null ? _data_fields : []).map((field)=>{
174
+ var _field_fieldName;
175
+ return (_field_fieldName = field.fieldName) != null ? _field_fieldName : '';
176
+ }).filter(Boolean)
177
+ };
178
+ })
179
+ ]
180
+ });
181
+ }
182
+
183
+ //# sourceMappingURL=ai-eval-memory-firestore.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/runtime/ai-eval-memory-firestore.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\n/**\n * A site in memory, for a live eval run that builds a whole job (AGL-3030).\n *\n * A recording is worth having only when it measures what production sends,\n * so the page recorder runs the page job's own step runners — which write\n * their drafts through the draft writer — rather than a copy of their\n * prompts. Those runners take the machine's Firestore handle; this is a handle\n * that keeps every document in a map instead, for the length of one recording.\n *\n * It answers exactly the calls the draft writer and the generation steps\n * make: a document read, a projection of a collection with its limit, and a\n * transaction that reads before it creates or updates. Anything else throws,\n * so a step that starts reading something new fails the recording loudly\n * rather than reading nothing. It never runs in production: nothing a\n * deployment loads imports it.\n */\n\nimport type { AiSiteInventory } from '../model/ai-site-inventory'\nimport { aiBracketedFacts } from './ai-doctrine-validators'\n\ntype Data = Record<string, unknown>\n\nfunction valueAt(data: unknown, path: string): unknown {\n return path\n .split('.')\n .reduce<unknown>(\n (value, key) => (value && typeof value === 'object' ? (value as Data)[key] : undefined),\n data,\n )\n}\n\nfunction setAt(data: Data, dotted: string, value: unknown): void {\n const keys = dotted.split('.')\n let cursor = data\n for (const key of keys.slice(0, -1)) {\n cursor[key] = { ...((cursor[key] as Data | undefined) ?? {}) }\n cursor = cursor[key] as Data\n }\n cursor[keys[keys.length - 1]] = value\n}\n\nexport interface AiEvalMemoryFirestore {\n /** The handle a step runner is given. */\n firestore: FirebaseFirestore.Firestore\n /** Every document by its path, as the runners left it. */\n docs: Map<string, Data>\n}\n\n/** A Firestore handle over an in-memory map, seeded with documents by path. */\nexport function aiEvalMemoryFirestore(seed: Record<string, Data> = {}): AiEvalMemoryFirestore {\n const docs = new Map<string, Data>(Object.entries(seed))\n\n const snapshotOf = (path: string) => {\n const data = docs.get(path)\n return {\n id: path.split('/').pop() as string,\n exists: data !== undefined,\n data: () => data,\n get: (field: string) => (data ? valueAt(data, field) : undefined),\n }\n }\n\n interface Query {\n kind: 'query'\n limit: (count: number) => Query\n get: () => Promise<{ docs: Array<ReturnType<typeof snapshotOf>> }>\n }\n\n const queryOf = (path: string, max = Number.POSITIVE_INFINITY): Query => ({\n kind: 'query',\n // The products step reads a site's categories a page at a time (AGL-3074).\n limit: (count) => queryOf(path, Math.min(max, count)),\n get: async () => ({\n docs: [...docs.keys()]\n .filter((key) => key.startsWith(`${path}/`) && !key.slice(path.length + 1).includes('/'))\n .sort()\n .slice(0, max)\n .map(snapshotOf),\n }),\n })\n\n const collectionRef = (path: string): Data => {\n const query = queryOf(path)\n return {\n path,\n doc: (id: string) => docRef(`${path}/${id}`),\n select: () => query,\n get: query.get,\n }\n }\n\n const docRef = (path: string): Data => ({\n kind: 'doc',\n path,\n id: path.split('/').pop(),\n collection: (name: string) => collectionRef(`${path}/${name}`),\n get: async () => snapshotOf(path),\n })\n\n type Target = { kind: 'doc'; path: string } | ReturnType<typeof queryOf>\n\n const firestore = {\n collection: (name: string) => collectionRef(name),\n runTransaction: async (fn: (tx: unknown) => Promise<unknown>) => {\n const writes: Array<() => void> = []\n const result = await fn({\n get: async (target: Target) => (target.kind === 'query' ? target.get() : snapshotOf(target.path)),\n create: (ref: { path: string }, data: Data) =>\n writes.push(() => {\n if (docs.has(ref.path)) throw new Error(`6 ALREADY_EXISTS: ${ref.path}`)\n docs.set(ref.path, data)\n }),\n update: (ref: { path: string }, patch: Data) =>\n writes.push(() => {\n const current = docs.get(ref.path)\n if (!current) throw new Error(`5 NOT_FOUND: ${ref.path}`)\n const next = { ...current }\n for (const [key, value] of Object.entries(patch)) setAt(next, key, value)\n docs.set(ref.path, next)\n }),\n set: (ref: { path: string }, data: Data) =>\n writes.push(() => {\n docs.set(ref.path, { ...(docs.get(ref.path) ?? {}), ...data })\n }),\n })\n for (const write of writes) write()\n return result\n },\n }\n return { firestore: firestore as unknown as FirebaseFirestore.Firestore, docs }\n}\n\n/**\n * A site's inventory as the reader would list it from the documents in\n * memory (AGL-3031): the case's own rows, and every layout, form and\n * component a job has written there since. A page job builds its creations\n * before its page, and the page is held to placing them, so the inventory it\n * reads has to change as the job builds — as the real reader's does.\n */\nexport function aiEvalMemoryInventory(base: AiSiteInventory, docs: ReadonlyMap<string, Data>): AiSiteInventory {\n const rows = (collection: string) =>\n [...docs.entries()]\n .filter(([path]) => path.startsWith(`hosts/${base.hostId}/${collection}/`) && path.split('/').length === 4)\n .map(([path, data]) => ({ id: path.split('/')[3], data }))\n .filter(({ data }) => data['deletedAt'] == null)\n const listed = (ids: readonly { id: string }[]) => new Set(ids.map((row) => row.id))\n const layouts = listed(base.layouts)\n const components = listed(base.components)\n const forms = listed(base.forms)\n return {\n ...base,\n layouts: [\n ...base.layouts,\n ...rows('layouts')\n .filter(({ id }) => !layouts.has(id))\n .map(({ id, data }) => ({ id, name: String(data['displayName'] ?? id), parentId: null })),\n ],\n components: [\n ...base.components,\n ...rows('components')\n .filter(({ id, data }) => !components.has(id) && Boolean(data['rootId'] || data['versionId']))\n .map(({ id, data }) => {\n const props = ((data['props'] as Array<{ name?: string; type?: string; defaultValue?: unknown }> | undefined) ?? []).filter(\n (prop) => typeof prop.name === 'string' && prop.name,\n )\n const bracketedDefaults = Object.fromEntries(\n props\n .map((prop) => [prop.name as string, aiBracketedFacts([typeof prop.defaultValue === 'string' ? prop.defaultValue : ''])] as const)\n .filter(([, facts]) => facts.length),\n )\n return {\n id,\n name: String(data['displayName'] ?? id),\n props: Object.fromEntries(props.map((prop) => [prop.name as string, prop.type || 'text'])),\n ...(Object.keys(bracketedDefaults).length ? { bracketedDefaults } : {}),\n }\n }),\n ],\n forms: [\n ...base.forms,\n ...rows('forms')\n .filter(({ id }) => !forms.has(id))\n .map(({ id, data }) => ({\n id,\n name: String(data['displayName'] ?? id),\n fields: ((data['fields'] as Array<{ fieldName?: string }> | undefined) ?? [])\n .map((field) => field.fieldName ?? '')\n .filter(Boolean),\n })),\n ],\n }\n}\n"],"names":["aiBracketedFacts","valueAt","data","path","split","reduce","value","key","undefined","setAt","dotted","keys","cursor","slice","length","aiEvalMemoryFirestore","seed","docs","Map","Object","entries","snapshotOf","get","id","pop","exists","field","queryOf","max","Number","POSITIVE_INFINITY","kind","limit","count","Math","min","filter","startsWith","includes","sort","map","collectionRef","query","doc","docRef","select","collection","name","firestore","runTransaction","fn","writes","result","target","create","ref","push","has","Error","set","update","patch","current","next","write","aiEvalMemoryInventory","base","rows","hostId","listed","ids","Set","row","layouts","components","forms","String","parentId","Boolean","props","prop","bracketedDefaults","fromEntries","defaultValue","facts","type","fields","fieldName"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED;;;;;;;;;;;;;;;CAeC;AAGD,SAASA,gBAAgB,QAAQ,8BAA0B;AAI3D,SAASC,QAAQC,IAAa,EAAEC,IAAY;IAC1C,OAAOA,KACJC,KAAK,CAAC,KACNC,MAAM,CACL,CAACC,OAAOC,MAASD,SAAS,OAAOA,UAAU,WAAW,AAACA,KAAc,CAACC,IAAI,GAAGC,WAC7EN;AAEN;AAEA,SAASO,MAAMP,IAAU,EAAEQ,MAAc,EAAEJ,KAAc;IACvD,MAAMK,OAAOD,OAAON,KAAK,CAAC;IAC1B,IAAIQ,SAASV;IACb,KAAK,MAAMK,OAAOI,KAAKE,KAAK,CAAC,GAAG,CAAC,GAAI;YACdD;QAArBA,MAAM,CAACL,IAAI,GAAG,cAAOK,cAAAA,MAAM,CAACL,IAAI,YAAXK,cAAoC,CAAC;QAC1DA,SAASA,MAAM,CAACL,IAAI;IACtB;IACAK,MAAM,CAACD,IAAI,CAACA,KAAKG,MAAM,GAAG,EAAE,CAAC,GAAGR;AAClC;AASA,6EAA6E,GAC7E,OAAO,SAASS,sBAAsBC,OAA6B,CAAC,CAAC;IACnE,MAAMC,OAAO,IAAIC,IAAkBC,OAAOC,OAAO,CAACJ;IAElD,MAAMK,aAAa,CAAClB;QAClB,MAAMD,OAAOe,KAAKK,GAAG,CAACnB;QACtB,OAAO;YACLoB,IAAIpB,KAAKC,KAAK,CAAC,KAAKoB,GAAG;YACvBC,QAAQvB,SAASM;YACjBN,MAAM,IAAMA;YACZoB,KAAK,CAACI,QAAmBxB,OAAOD,QAAQC,MAAMwB,SAASlB;QACzD;IACF;IAQA,MAAMmB,UAAU,CAACxB,MAAcyB,MAAMC,OAAOC,iBAAiB,GAAa,CAAA;YACxEC,MAAM;YACN,2EAA2E;YAC3EC,OAA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