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

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 (203) hide show
  1. package/README.md +3 -2
  2. package/package.json +17 -17
  3. package/src/lib/billing/ai-month-meter.js +5 -3
  4. package/src/lib/billing/ai-month-meter.js.map +1 -1
  5. package/src/lib/billing/ai-overage-ledger.js +3 -1
  6. package/src/lib/billing/ai-overage-ledger.js.map +1 -1
  7. package/src/lib/components/ai-brief-dialog.component.d.ts +6 -2
  8. package/src/lib/components/ai-brief-dialog.component.js +36 -18
  9. package/src/lib/components/ai-brief-dialog.component.js.map +1 -1
  10. package/src/lib/components/ai-describe-automation.component.js +24 -4
  11. package/src/lib/components/ai-describe-automation.component.js.map +1 -1
  12. package/src/lib/components/ai-describe-button.component.js +6 -1
  13. package/src/lib/components/ai-describe-button.component.js.map +1 -1
  14. package/src/lib/components/ai-describe-page.component.d.ts +1 -1
  15. package/src/lib/components/ai-describe-page.component.js +1 -1
  16. package/src/lib/components/ai-describe-page.component.js.map +1 -1
  17. package/src/lib/components/ai-insight-dialog.component.js +24 -2
  18. package/src/lib/components/ai-insight-dialog.component.js.map +1 -1
  19. package/src/lib/components/ai-job-events.d.ts +20 -0
  20. package/src/lib/components/ai-job-events.js +78 -0
  21. package/src/lib/components/ai-job-events.js.map +1 -0
  22. package/src/lib/components/ai-job-follow.component.d.ts +49 -0
  23. package/src/lib/components/ai-job-follow.component.js +210 -0
  24. package/src/lib/components/ai-job-follow.component.js.map +1 -0
  25. package/src/lib/components/ai-job-links.d.ts +42 -0
  26. package/src/lib/components/ai-job-links.js +140 -0
  27. package/src/lib/components/ai-job-links.js.map +1 -0
  28. package/src/lib/components/ai-job-plan.component.d.ts +13 -6
  29. package/src/lib/components/ai-job-plan.component.js +29 -3
  30. package/src/lib/components/ai-job-plan.component.js.map +1 -1
  31. package/src/lib/components/ai-job-requests.d.ts +24 -0
  32. package/src/lib/components/ai-job-requests.js +76 -0
  33. package/src/lib/components/ai-job-requests.js.map +1 -0
  34. package/src/lib/components/ai-job-site.d.ts +22 -0
  35. package/src/lib/components/ai-job-site.js +73 -0
  36. package/src/lib/components/ai-job-site.js.map +1 -0
  37. package/src/lib/components/ai-jobs-indicator.component.d.ts +25 -0
  38. package/src/lib/components/ai-jobs-indicator.component.js +80 -0
  39. package/src/lib/components/ai-jobs-indicator.component.js.map +1 -0
  40. package/src/lib/components/ai-jobs-list-page.component.d.ts +23 -0
  41. package/src/lib/components/ai-jobs-list-page.component.js +303 -0
  42. package/src/lib/components/ai-jobs-list-page.component.js.map +1 -0
  43. package/src/lib/components/ai-jobs-page.component.d.ts +7 -0
  44. package/src/lib/components/ai-jobs-page.component.js +30 -0
  45. package/src/lib/components/ai-jobs-page.component.js.map +1 -0
  46. package/src/lib/components/ai-jobs-store.d.ts +81 -0
  47. package/src/lib/components/ai-jobs-store.js +218 -0
  48. package/src/lib/components/ai-jobs-store.js.map +1 -0
  49. package/src/lib/components/ai-page-brief-dialog.component.d.ts +4 -4
  50. package/src/lib/components/ai-page-brief-dialog.component.js.map +1 -1
  51. package/src/lib/components/ai-site-build-page.component.d.ts +51 -0
  52. package/src/lib/components/ai-site-build-page.component.js +495 -0
  53. package/src/lib/components/ai-site-build-page.component.js.map +1 -0
  54. package/src/lib/components/ai-site-start-card.component.d.ts +9 -1
  55. package/src/lib/components/ai-site-start-card.component.js +533 -132
  56. package/src/lib/components/ai-site-start-card.component.js.map +1 -1
  57. package/src/lib/components/ai-site-starter-fallback.component.d.ts +24 -0
  58. package/src/lib/components/ai-site-starter-fallback.component.js +112 -0
  59. package/src/lib/components/ai-site-starter-fallback.component.js.map +1 -0
  60. package/src/lib/components/assist-jobs-drawer.component.d.ts +18 -20
  61. package/src/lib/components/assist-jobs-drawer.component.js +152 -172
  62. package/src/lib/components/assist-jobs-drawer.component.js.map +1 -1
  63. package/src/lib/components/assist-panel.component.js +69 -8
  64. package/src/lib/components/assist-panel.component.js.map +1 -1
  65. package/src/lib/components/staff-ai-credit-return.component.d.ts +55 -0
  66. package/src/lib/components/staff-ai-credit-return.component.js +346 -0
  67. package/src/lib/components/staff-ai-credit-return.component.js.map +1 -0
  68. package/src/lib/components/staff-org-ai-card.component.js +364 -279
  69. package/src/lib/components/staff-org-ai-card.component.js.map +1 -1
  70. package/src/lib/components/staff-user-ai-usage-card.component.d.ts +4 -0
  71. package/src/lib/components/staff-user-ai-usage-card.component.js +83 -28
  72. package/src/lib/components/staff-user-ai-usage-card.component.js.map +1 -1
  73. package/src/lib/components/use-ai-job-run.js +5 -18
  74. package/src/lib/components/use-ai-job-run.js.map +1 -1
  75. package/src/lib/jobs/ai-job-auto-confirm.d.ts +52 -0
  76. package/src/lib/jobs/ai-job-auto-confirm.js +62 -0
  77. package/src/lib/jobs/ai-job-auto-confirm.js.map +1 -0
  78. package/src/lib/jobs/ai-job-draft-ids.d.ts +6 -0
  79. package/src/lib/jobs/ai-job-draft-ids.js +9 -0
  80. package/src/lib/jobs/ai-job-draft-ids.js.map +1 -1
  81. package/src/lib/jobs/ai-job-drafts.d.ts +7 -0
  82. package/src/lib/jobs/ai-job-drafts.js +16 -7
  83. package/src/lib/jobs/ai-job-drafts.js.map +1 -1
  84. package/src/lib/jobs/ai-job-layout-step.js +2 -1
  85. package/src/lib/jobs/ai-job-layout-step.js.map +1 -1
  86. package/src/lib/jobs/ai-job-page-sections.d.ts +6 -5
  87. package/src/lib/jobs/ai-job-page-sections.js +3 -3
  88. package/src/lib/jobs/ai-job-page-sections.js.map +1 -1
  89. package/src/lib/jobs/ai-job-page-step.d.ts +19 -1
  90. package/src/lib/jobs/ai-job-page-step.js +50 -8
  91. package/src/lib/jobs/ai-job-page-step.js.map +1 -1
  92. package/src/lib/jobs/ai-job-plan-step.d.ts +33 -2
  93. package/src/lib/jobs/ai-job-plan-step.js +167 -18
  94. package/src/lib/jobs/ai-job-plan-step.js.map +1 -1
  95. package/src/lib/jobs/ai-job-site-step.d.ts +28 -0
  96. package/src/lib/jobs/ai-job-site-step.js +130 -21
  97. package/src/lib/jobs/ai-job-site-step.js.map +1 -1
  98. package/src/lib/jobs/ai-job-text-step.d.ts +14 -1
  99. package/src/lib/jobs/ai-job-text-step.js.map +1 -1
  100. package/src/lib/jobs/ai-jobs-notify.d.ts +37 -0
  101. package/src/lib/jobs/ai-jobs-notify.js +51 -0
  102. package/src/lib/jobs/ai-jobs-notify.js.map +1 -0
  103. package/src/lib/jobs/ai-jobs.d.ts +39 -4
  104. package/src/lib/jobs/ai-jobs.js +205 -34
  105. package/src/lib/jobs/ai-jobs.js.map +1 -1
  106. package/src/lib/jobs/ai-site-publish.d.ts +98 -0
  107. package/src/lib/jobs/ai-site-publish.js +372 -0
  108. package/src/lib/jobs/ai-site-publish.js.map +1 -0
  109. package/src/lib/jobs/fixtures/ai-page-briefs.d.ts +7 -6
  110. package/src/lib/jobs/fixtures/ai-page-briefs.js +23 -56
  111. package/src/lib/jobs/fixtures/ai-page-briefs.js.map +1 -1
  112. package/src/lib/model/ai-job-activity.d.ts +112 -0
  113. package/src/lib/model/ai-job-activity.js +144 -0
  114. package/src/lib/model/ai-job-activity.js.map +1 -0
  115. package/src/lib/model/ai-job-failure-copy.d.ts +69 -0
  116. package/src/lib/model/ai-job-failure-copy.js +78 -0
  117. package/src/lib/model/ai-job-failure-copy.js.map +1 -0
  118. package/src/lib/model/ai-job-notice.d.ts +63 -0
  119. package/src/lib/model/ai-job-notice.js +129 -0
  120. package/src/lib/model/ai-job-notice.js.map +1 -0
  121. package/src/lib/model/ai-jobs.types.d.ts +53 -0
  122. package/src/lib/model/ai-jobs.types.js +1 -0
  123. package/src/lib/model/ai-jobs.types.js.map +1 -1
  124. package/src/lib/model/ai-plan-capabilities.d.ts +32 -10
  125. package/src/lib/model/ai-plan-capabilities.js +15 -2
  126. package/src/lib/model/ai-plan-capabilities.js.map +1 -1
  127. package/src/lib/model/ai-site-build-progress.d.ts +61 -0
  128. package/src/lib/model/ai-site-build-progress.js +136 -0
  129. package/src/lib/model/ai-site-build-progress.js.map +1 -0
  130. package/src/lib/model/ai-site-inventory.d.ts +9 -0
  131. package/src/lib/model/ai-site-inventory.js +7 -2
  132. package/src/lib/model/ai-site-inventory.js.map +1 -1
  133. package/src/lib/model/ai-site-job.d.ts +93 -2
  134. package/src/lib/model/ai-site-job.js +88 -7
  135. package/src/lib/model/ai-site-job.js.map +1 -1
  136. package/src/lib/model/ai-site-start-seo.d.ts +19 -0
  137. package/src/lib/model/ai-site-start-seo.js +91 -3
  138. package/src/lib/model/ai-site-start-seo.js.map +1 -1
  139. package/src/lib/model/ai-site-start.d.ts +3 -1
  140. package/src/lib/model/ai-site-start.js +6 -4
  141. package/src/lib/model/ai-site-start.js.map +1 -1
  142. package/src/lib/plan-entitlements.d.ts +3 -3
  143. package/src/lib/plan-entitlements.js +3 -3
  144. package/src/lib/plan-entitlements.js.map +1 -1
  145. package/src/lib/plugin.js +38 -2
  146. package/src/lib/plugin.js.map +1 -1
  147. package/src/lib/runtime/ai-abuse-guards.d.ts +9 -6
  148. package/src/lib/runtime/ai-abuse-guards.js +10 -7
  149. package/src/lib/runtime/ai-abuse-guards.js.map +1 -1
  150. package/src/lib/runtime/ai-doctrine-validators.d.ts +16 -12
  151. package/src/lib/runtime/ai-doctrine-validators.js +50 -40
  152. package/src/lib/runtime/ai-doctrine-validators.js.map +1 -1
  153. package/src/lib/runtime/ai-doctrine.js +1 -1
  154. package/src/lib/runtime/ai-doctrine.js.map +1 -1
  155. package/src/lib/runtime/ai-eval-live.d.ts +1 -1
  156. package/src/lib/runtime/ai-eval-live.js +1 -1
  157. package/src/lib/runtime/ai-eval-live.js.map +1 -1
  158. package/src/lib/runtime/ai-gate.d.ts +3 -2
  159. package/src/lib/runtime/ai-gate.js +3 -2
  160. package/src/lib/runtime/ai-gate.js.map +1 -1
  161. package/src/lib/runtime/site-inventory.d.ts +16 -1
  162. package/src/lib/runtime/site-inventory.js +43 -3
  163. package/src/lib/runtime/site-inventory.js.map +1 -1
  164. package/src/lib/server/ai-admin-credits.d.ts +21 -0
  165. package/src/lib/server/ai-admin-credits.js +213 -0
  166. package/src/lib/server/ai-admin-credits.js.map +1 -0
  167. package/src/lib/server/ai-admin-org.js +12 -5
  168. package/src/lib/server/ai-admin-org.js.map +1 -1
  169. package/src/lib/server/ai-admin-signals.js +3 -1
  170. package/src/lib/server/ai-admin-signals.js.map +1 -1
  171. package/src/lib/server/ai-admin-user.js +12 -1
  172. package/src/lib/server/ai-admin-user.js.map +1 -1
  173. package/src/lib/server/ai-allotments.js +3 -2
  174. package/src/lib/server/ai-allotments.js.map +1 -1
  175. package/src/lib/server/ai-jobs-live-sites.d.ts +26 -0
  176. package/src/lib/server/ai-jobs-live-sites.js +58 -0
  177. package/src/lib/server/ai-jobs-live-sites.js.map +1 -0
  178. package/src/lib/server/ai-jobs-route.js +42 -5
  179. package/src/lib/server/ai-jobs-route.js.map +1 -1
  180. package/src/lib/server/assist-chat.js +3 -2
  181. package/src/lib/server/assist-chat.js.map +1 -1
  182. package/src/lib/server/billing-credits.js +4 -3
  183. package/src/lib/server/billing-credits.js.map +1 -1
  184. package/src/lib/server/billing-overage.js +3 -2
  185. package/src/lib/server/billing-overage.js.map +1 -1
  186. package/src/lib/server.js +11 -0
  187. package/src/lib/server.js.map +1 -1
  188. package/src/lib/usage/assist-credit-returns-write.d.ts +75 -0
  189. package/src/lib/usage/assist-credit-returns-write.js +150 -0
  190. package/src/lib/usage/assist-credit-returns-write.js.map +1 -0
  191. package/src/lib/usage/assist-credit-returns.d.ts +68 -0
  192. package/src/lib/usage/assist-credit-returns.js +79 -0
  193. package/src/lib/usage/assist-credit-returns.js.map +1 -0
  194. package/src/lib/usage/assist-free-taste.js +6 -3
  195. package/src/lib/usage/assist-free-taste.js.map +1 -1
  196. package/src/lib/usage/assist-job-refund.d.ts +100 -0
  197. package/src/lib/usage/assist-job-refund.js +109 -0
  198. package/src/lib/usage/assist-job-refund.js.map +1 -0
  199. package/src/lib/usage/assist-usage.js +5 -2
  200. package/src/lib/usage/assist-usage.js.map +1 -1
  201. package/src/lib/usage/staff-org-ai.d.ts +31 -1
  202. package/src/lib/usage/staff-org-ai.js +19 -2
  203. package/src/lib/usage/staff-org-ai.js.map +1 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/components/ai-job-plan.component.tsx"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n AI_BUILD_PLAN_CREATION_NOUNS,\n AI_BUILD_PLAN_EMBED_HOST_NAMES,\n isAiPlanNewRef,\n type AiBuildPlanEmbed,\n} from '../model/ai-build-plan'\nimport type { AiJobReview, AiJobSummary } from '../model/ai-jobs.types'\nimport { aiJobPlanCreditEstimate } from '../model/ai-site-job'\nimport { Box, Button, Collapse, Stack, Typography } from '@mui/material'\nimport { useState } from 'react'\n\n/**\n * A job's plan and what it waits for (AGL-2935), inside the AI jobs drawer:\n * what the job reuses from the site, what it creates and why, the screens it\n * builds — and, while the job waits for a person, the one button that\n * confirms the plan or tries a refused step again. The drawer owns the\n * request; this renders.\n */\nexport interface AiJobPlanProps {\n job: AiJobSummary\n /** Confirms the plan, or tries the refused step again. */\n onResume: (job: AiJobSummary) => void\n /** A resume for this job is in flight. */\n busy?: boolean\n /**\n * The viewer is staff (AGL-3078), who can open where a refused answer broke\n * its rules and the outline of those parts, to tell a shape the rules should\n * allow from an answer that ignored its re-ask. A member reads the findings.\n */\n staff?: boolean\n}\n\n/**\n * Where a refused answer broke its rules, and the outline of those parts, as\n * lines staff read (AGL-3078): each finding with the nodes or plan entries it\n * names, then each outlined node indented by its depth, with its element, a\n * Grid's layout as written, and the names of what it sets and holds.\n */\nexport function aiJobReviewDetails(review: AiJobReview | null): string[] {\n if (review?.reason !== 'doctrine') return []\n const lines = review.findings.flatMap((finding) => {\n const where = finding.nodeIds?.length\n ? `nodes ${finding.nodeIds.join(', ')}`\n : finding.paths?.length\n ? `at ${finding.paths.join(', ')}`\n : null\n return where ? [`${finding.rule === null ? '' : `Rule ${finding.rule} `}${finding.code}: ${where}`] : []\n })\n for (const node of review.outline ?? []) {\n lines.push(\n [\n `${' '.repeat(node.depth)}${node.id} ${node.componentId}`,\n ...Object.entries(node.grid ?? {}).map(([name, value]) => `${name}=${JSON.stringify(value)}`),\n ...(node.props.length ? [`props ${node.props.join(', ')}`] : []),\n ...(node.sx?.length ? [`sx ${node.sx.join(', ')}`] : []),\n ...(node.children.length ? [`holds ${node.children.join(', ')}`] : []),\n ].join(' · '),\n )\n }\n return lines\n}\n\n/**\n * A third-party player the plan lists, with what it costs the page, read\n * before the member confirms it (rule 16, AGL-3433). The cost is the\n * platform's sentence, never the model's: the player is framed lazily, so its\n * host's code loads when a visitor reaches it, whether or not they press play.\n */\nexport function aiPlanEmbedLine(\n embed: AiBuildPlanEmbed,\n named: (ref: string) => string,\n): string {\n const host = AI_BUILD_PLAN_EMBED_HOST_NAMES[embed.host]\n const where = isAiPlanNewRef(embed.where) ? `the component ${named(embed.where)}` : embed.where\n const link = embed.url ? ` playing ${embed.url}` : ', its link left for you to paste'\n return `Embeds a ${host} player on ${where}${link}, as you asked (“${embed.asked}”). It loads ${host}’s own code when a visitor reaches it, whether or not they press play.`\n}\n\nexport function AiJobPlan({\n job,\n onResume,\n busy = false,\n staff = false,\n}: AiJobPlanProps): JSX.Element | null {\n const [detailsOpen, setDetailsOpen] = useState(false)\n const { plan, review } = job\n if (!plan && !review) return null\n const details = staff ? aiJobReviewDetails(review) : []\n /** A reference as a person reads it: the record's name, or what the plan creates. */\n const named = (ref: string | null): string =>\n !ref\n ? ''\n : isAiPlanNewRef(ref)\n ? ref.slice('new:'.length)\n : (plan?.labels[ref] ?? ref)\n const waiting = job.status === 'needs_review' && review !== null\n // The guard rail (AGL-2911): what the plan is estimated to cost is read\n // before it is confirmed, not after it has been spent. An estimate, and\n // said to be one — the plan's own passes at the nominal credits a step\n // holds, where what a step really costs is its model's tokens. A page job\n // counts the creations it builds before its page (AGL-3031).\n const estimate =\n plan && waiting && review.reason === 'plan' ? aiJobPlanCreditEstimate(job.kind, plan) : 0\n return (\n <Box sx={{ mt: 1 }}>\n {plan && (\n <Stack spacing={0.5} role=\"list\" aria-label=\"Plan\">\n <Typography variant=\"caption\" color=\"text.secondary\">\n {plan.status === 'confirmed' ? 'Confirmed plan' : 'Proposed plan'}\n </Typography>\n {plan.reuse.map((entry, index) => (\n <Typography key={`reuse-${index}`} variant=\"body2\" role=\"listitem\">\n Reuses the {entry.kind === 'screen' ? 'page' : entry.kind} {named(entry.id)} — {entry.purpose}\n </Typography>\n ))}\n {plan.create.map((entry, index) => (\n <Typography key={`create-${index}`} variant=\"body2\" role=\"listitem\">\n Creates the {AI_BUILD_PLAN_CREATION_NOUNS[entry.kind].noun} {entry.name}\n {entry.duplicateOf\n ? `, from a copy of ${named(entry.duplicateOf)}`\n : ''}{' '}\n — {entry.why}\n </Typography>\n ))}\n {plan.screens.map((screen, index) => (\n <Typography key={`screen-${index}`} variant=\"body2\" role=\"listitem\">\n {screen.record\n ? `Builds the record template ${screen.title}, a page per record of ${named(screen.record.dataset)} at /${screen.record.base}/…`\n : `Builds the page ${screen.title} at ${screen.slug}`}\n {screen.duplicateOf\n ? `, from a copy of ${named(screen.duplicateOf)}`\n : ''}\n {screen.layout ? ` in ${named(screen.layout)}` : ''}\n {screen.sections.length\n ? `: ${screen.sections.map((section) => section.name).join(', ')}`\n : ''}\n </Typography>\n ))}\n {(plan.embeds ?? []).map((embed, index) => (\n <Typography key={`embed-${index}`} variant=\"body2\" role=\"listitem\">\n {aiPlanEmbedLine(embed, named)}\n </Typography>\n ))}\n </Stack>\n )}\n {review?.reason === 'doctrine' && review.findings.length > 0 && (\n <Box\n component=\"ul\"\n sx={{ my: 0.5, pl: 2.5 }}\n aria-label=\"Building rules broken\"\n >\n {review.findings.map((finding, index) => (\n <Typography\n key={`finding-${index}`}\n component=\"li\"\n variant=\"caption\"\n >\n {finding.message}\n </Typography>\n ))}\n </Box>\n )}\n {details.length > 0 && (\n <Box sx={{ mt: 0.5 }}>\n <Button\n size=\"small\"\n aria-expanded={detailsOpen}\n onClick={() => setDetailsOpen((prior) => !prior)}\n >\n {detailsOpen ? 'Hide what was refused' : 'Show what was refused'}\n </Button>\n <Collapse in={detailsOpen} unmountOnExit>\n <Typography\n variant=\"caption\"\n component=\"pre\"\n aria-label=\"What was refused\"\n sx={{ m: 0, fontFamily: 'monospace', whiteSpace: 'pre', overflowX: 'auto' }}\n >\n {details.join('\\n')}\n </Typography>\n </Collapse>\n </Box>\n )}\n {estimate > 0 && (\n <Typography\n variant=\"caption\"\n color=\"text.secondary\"\n sx={{ display: 'block', mt: 1 }}\n >\n {`Estimated cost: about ${estimate.toLocaleString('en-US')} credits. What it costs is what its steps spend.`}\n </Typography>\n )}\n {waiting && (\n <Button\n size=\"small\"\n variant=\"contained\"\n disabled={busy}\n onClick={() => onResume(job)}\n sx={{ mt: 1 }}\n >\n {review.reason === 'plan' ? 'Confirm plan' : 'Try again'}\n </Button>\n )}\n </Box>\n )\n}\n\nexport default AiJobPlan\n"],"names":["AI_BUILD_PLAN_CREATION_NOUNS","AI_BUILD_PLAN_EMBED_HOST_NAMES","isAiPlanNewRef","aiJobPlanCreditEstimate","Box","Button","Collapse","Stack","Typography","useState","aiJobReviewDetails","review","reason","lines","findings","flatMap","finding","where","nodeIds","length","join","paths","rule","code","node","outline","push","repeat","depth","id","componentId","Object","entries","grid","map","name","value","JSON","stringify","props","sx","children","aiPlanEmbedLine","embed","named","host","link","url","asked","AiJobPlan","job","onResume","busy","staff","plan","detailsOpen","setDetailsOpen","details","ref","slice","labels","waiting","status","estimate","kind","mt","spacing","role","aria-label","variant","color","reuse","entry","index","purpose","create","noun","duplicateOf","why","screens","screen","record","title","dataset","base","slug","layout","sections","section","embeds","component","my","pl","message","size","aria-expanded","onClick","prior","in","unmountOnExit","m","fontFamily","whiteSpace","overflowX","display","toLocaleString","disabled"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SACEA,4BAA4B,EAC5BC,8BAA8B,EAC9BC,cAAc,QAET,4BAAwB;AAE/B,SAASC,uBAAuB,QAAQ,0BAAsB;AAC9D,SAASC,GAAG,EAAEC,MAAM,EAAEC,QAAQ,EAAEC,KAAK,EAAEC,UAAU,QAAQ,gBAAe;AACxE,SAASC,QAAQ,QAAQ,QAAO;AAuBhC;;;;;CAKC,GACD,OAAO,SAASC,mBAAmBC,MAA0B;QAUxCA;IATnB,IAAIA,CAAAA,0BAAAA,OAAQC,MAAM,MAAK,YAAY,OAAO,EAAE;IAC5C,MAAMC,QAAQF,OAAOG,QAAQ,CAACC,OAAO,CAAC,CAACC;YACvBA,kBAEVA;QAFJ,MAAMC,QAAQD,EAAAA,mBAAAA,QAAQE,OAAO,qBAAfF,iBAAiBG,MAAM,IACjC,CAAC,MAAM,EAAEH,QAAQE,OAAO,CAACE,IAAI,CAAC,OAAO,GACrCJ,EAAAA,iBAAAA,QAAQK,KAAK,qBAAbL,eAAeG,MAAM,IACnB,CAAC,GAAG,EAAEH,QAAQK,KAAK,CAACD,IAAI,CAAC,OAAO,GAChC;QACN,OAAOH,QAAQ;YAAC,GAAGD,QAAQM,IAAI,KAAK,OAAO,KAAK,CAAC,KAAK,EAAEN,QAAQM,IAAI,CAAC,CAAC,CAAC,GAAGN,QAAQO,IAAI,CAAC,EAAE,EAAEN,OAAO;SAAC,GAAG,EAAE;IAC1G;IACA,KAAK,MAAMO,SAAQb,kBAAAA,OAAOc,OAAO,YAAdd,kBAAkB,EAAE,CAAE;YAIjBa;YA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.tsx"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n AI_BUILD_PLAN_CREATION_NOUNS,\n AI_BUILD_PLAN_EMBED_HOST_NAMES,\n isAiPlanNewRef,\n type AiBuildPlanEmbed,\n} from '../model/ai-build-plan'\nimport type { AiJobReview, AiJobSummary } from '../model/ai-jobs.types'\nimport { aiJobPlanCreditEstimate } from '../model/ai-site-job'\nimport { aiSiteStarterFallbackOffered } from '../model/ai-job-failure-copy'\nimport { AiSiteStarterFallback } from './ai-site-starter-fallback.component'\nimport { Box, Button, Collapse, Stack, Typography } from '@mui/material'\nimport { useState } from 'react'\n\n/**\n * A job's plan and what it waits for (AGL-2935), inside the AI jobs drawer\n * and the dialog that started the job (AGL-3593): what the job reuses from\n * the site, what it creates and why, the screens it builds — and, while the\n * job waits for a person, the one button that confirms the plan or tries a\n * refused step again. Both send the same request (`resumeAiJobRequest`);\n * this renders.\n */\nexport interface AiJobPlanProps {\n job: AiJobSummary\n /** Confirms the plan, or tries the refused step again. */\n onResume: (job: AiJobSummary) => void\n /** A resume for this job is in flight. */\n busy?: boolean\n /**\n * The viewer is staff (AGL-3078), who can open where a refused answer broke\n * its rules and the outline of those parts, to tell a shape the rules should\n * allow from an answer that ignored its re-ask. A member reads the findings.\n */\n staff?: boolean\n /**\n * The signed-in user, for \"Use the starter site instead\" on a guided start\n * that did not work out (AGL-3594); the action is drawn only when given.\n */\n user?: Parameters<typeof AiSiteStarterFallback>[0]['user']\n}\n\n/**\n * Where a refused answer broke its rules, and the outline of those parts, as\n * lines staff read (AGL-3078): each finding with the nodes or plan entries it\n * names, then each outlined node indented by its depth, with its element, a\n * Grid's layout as written, and the names of what it sets and holds.\n */\nexport function aiJobReviewDetails(review: AiJobReview | null): string[] {\n if (review?.reason !== 'doctrine') return []\n const lines = review.findings.flatMap((finding) => {\n const where = finding.nodeIds?.length\n ? `nodes ${finding.nodeIds.join(', ')}`\n : finding.paths?.length\n ? `at ${finding.paths.join(', ')}`\n : null\n return where ? [`${finding.rule === null ? '' : `Rule ${finding.rule} `}${finding.code}: ${where}`] : []\n })\n for (const node of review.outline ?? []) {\n lines.push(\n [\n `${' '.repeat(node.depth)}${node.id} ${node.componentId}`,\n ...Object.entries(node.grid ?? {}).map(([name, value]) => `${name}=${JSON.stringify(value)}`),\n ...(node.props.length ? [`props ${node.props.join(', ')}`] : []),\n ...(node.sx?.length ? [`sx ${node.sx.join(', ')}`] : []),\n ...(node.children.length ? [`holds ${node.children.join(', ')}`] : []),\n ].join(' · '),\n )\n }\n return lines\n}\n\n/**\n * A third-party player the plan lists, with what it costs the page, read\n * before the member confirms it (rule 16, AGL-3433). The cost is the\n * platform's sentence, never the model's: the player is framed lazily, so its\n * host's code loads when a visitor reaches it, whether or not they press play.\n */\nexport function aiPlanEmbedLine(\n embed: AiBuildPlanEmbed,\n named: (ref: string) => string,\n): string {\n const host = AI_BUILD_PLAN_EMBED_HOST_NAMES[embed.host]\n const where = isAiPlanNewRef(embed.where) ? `the component ${named(embed.where)}` : embed.where\n const link = embed.url ? ` playing ${embed.url}` : ', its link left for you to paste'\n return `Embeds a ${host} player on ${where}${link}, as you asked (“${embed.asked}”). It loads ${host}’s own code when a visitor reaches it, whether or not they press play.`\n}\n\nexport function AiJobPlan({\n job,\n onResume,\n busy = false,\n staff = false,\n user,\n}: AiJobPlanProps): JSX.Element | null {\n const [detailsOpen, setDetailsOpen] = useState(false)\n const { plan, review } = job\n if (!plan && !review) return null\n const details = staff ? aiJobReviewDetails(review) : []\n /** A reference as a person reads it: the record's name, or what the plan creates. */\n const named = (ref: string | null): string =>\n !ref\n ? ''\n : isAiPlanNewRef(ref)\n ? ref.slice('new:'.length)\n : (plan?.labels[ref] ?? ref)\n const waiting = job.status === 'needs_review' && review !== null\n // The guard rail (AGL-2911): what the plan is estimated to cost is read\n // before it is confirmed, not after it has been spent. An estimate, and\n // said to be one — the plan's own passes at the nominal credits a step\n // holds, where what a step really costs is its model's tokens. A page job\n // counts the creations it builds before its page (AGL-3031).\n const estimate =\n plan && waiting && review.reason === 'plan' ? aiJobPlanCreditEstimate(job.kind, plan) : 0\n return (\n <Box sx={{ mt: 1 }}>\n {plan && (\n <Stack spacing={0.5} role=\"list\" aria-label=\"Plan\">\n <Typography variant=\"caption\" color=\"text.secondary\">\n {plan.status === 'confirmed' ? 'Confirmed plan' : 'Proposed plan'}\n </Typography>\n {plan.reuse.map((entry, index) => (\n <Typography key={`reuse-${index}`} variant=\"body2\" role=\"listitem\">\n Reuses the {entry.kind === 'screen' ? 'page' : entry.kind} {named(entry.id)} — {entry.purpose}\n </Typography>\n ))}\n {plan.create.map((entry, index) => (\n <Typography key={`create-${index}`} variant=\"body2\" role=\"listitem\">\n Creates the {AI_BUILD_PLAN_CREATION_NOUNS[entry.kind].noun} {entry.name}\n {entry.duplicateOf\n ? `, from a copy of ${named(entry.duplicateOf)}`\n : ''}{' '}\n — {entry.why}\n </Typography>\n ))}\n {plan.screens.map((screen, index) => (\n <Typography key={`screen-${index}`} variant=\"body2\" role=\"listitem\">\n {screen.record\n ? `Builds the record template ${screen.title}, a page per record of ${named(screen.record.dataset)} at /${screen.record.base}/…`\n : `Builds the page ${screen.title} at ${screen.slug}`}\n {screen.duplicateOf\n ? `, from a copy of ${named(screen.duplicateOf)}`\n : ''}\n {screen.layout ? ` in ${named(screen.layout)}` : ''}\n {screen.sections.length\n ? `: ${screen.sections.map((section) => section.name).join(', ')}`\n : ''}\n </Typography>\n ))}\n {(plan.embeds ?? []).map((embed, index) => (\n <Typography key={`embed-${index}`} variant=\"body2\" role=\"listitem\">\n {aiPlanEmbedLine(embed, named)}\n </Typography>\n ))}\n </Stack>\n )}\n {/*\n A review written for the member (AGL-3594) carries the checks' own\n sentence as `detail`: its findings are then staff reading too, and the\n member reads the job's one sentence alone.\n */}\n {staff && review?.detail && (\n <Typography variant=\"caption\" color=\"text.secondary\" component=\"div\" sx={{ mt: 0.5 }}>\n {review.detail}\n </Typography>\n )}\n {review?.reason === 'doctrine' && review.findings.length > 0 && (staff || !review.detail) && (\n <Box\n component=\"ul\"\n sx={{ my: 0.5, pl: 2.5 }}\n aria-label=\"Building rules broken\"\n >\n {review.findings.map((finding, index) => (\n <Typography\n key={`finding-${index}`}\n component=\"li\"\n variant=\"caption\"\n >\n {finding.message}\n </Typography>\n ))}\n </Box>\n )}\n {details.length > 0 && (\n <Box sx={{ mt: 0.5 }}>\n <Button\n size=\"small\"\n aria-expanded={detailsOpen}\n onClick={() => setDetailsOpen((prior) => !prior)}\n >\n {detailsOpen ? 'Hide what was refused' : 'Show what was refused'}\n </Button>\n <Collapse in={detailsOpen} unmountOnExit>\n <Typography\n variant=\"caption\"\n component=\"pre\"\n aria-label=\"What was refused\"\n sx={{ m: 0, fontFamily: 'monospace', whiteSpace: 'pre', overflowX: 'auto' }}\n >\n {details.join('\\n')}\n </Typography>\n </Collapse>\n </Box>\n )}\n {estimate > 0 && (\n <Typography\n variant=\"caption\"\n color=\"text.secondary\"\n sx={{ display: 'block', mt: 1 }}\n >\n {`Estimated cost: about ${estimate.toLocaleString('en-US')} credits. What it costs is what its steps spend.`}\n </Typography>\n )}\n {waiting && review.retryRefusal && review.reason !== 'plan' && (\n <Typography variant=\"caption\" color=\"text.secondary\" component=\"div\" sx={{ mt: 1 }}>\n {review.retryRefusal}\n </Typography>\n )}\n {waiting && (\n <Button\n size=\"small\"\n variant=\"contained\"\n // Disabled with its reason above when the Free allowance left\n // cannot pay for another try (AGL-3594).\n disabled={busy || (review.reason !== 'plan' && Boolean(review.retryRefusal))}\n onClick={() => onResume(job)}\n sx={{ mt: 1 }}\n >\n {review.reason === 'plan' ? 'Confirm plan' : 'Try again'}\n </Button>\n )}\n {/* A guided start that did not work out can take the starter instead (AGL-3594). */}\n {waiting && user && aiSiteStarterFallbackOffered(job) && <AiSiteStarterFallback job={job} user={user} />}\n </Box>\n )\n}\n\nexport default AiJobPlan\n"],"names":["AI_BUILD_PLAN_CREATION_NOUNS","AI_BUILD_PLAN_EMBED_HOST_NAMES","isAiPlanNewRef","aiJobPlanCreditEstimate","aiSiteStarterFallbackOffered","AiSiteStarterFallback","Box","Button","Collapse","Stack","Typography","useState","aiJobReviewDetails","review","reason","lines","findings","flatMap","finding","where","nodeIds","length","join","paths","rule","code","node","outline","push","repeat","depth","id","componentId","Object","entries","grid","map","name","value","JSON","stringify","props","sx","children","aiPlanEmbedLine","embed","named","host","link","url","asked","AiJobPlan","job","onResume","busy","staff","user","plan","detailsOpen","setDetailsOpen","details","ref","slice","labels","waiting","status","estimate","kind","mt","spacing","role","aria-label","variant","color","reuse","entry","index","purpose","create","noun","duplicateOf","why","screens","screen","record","title","dataset","base","slug","layout","sections","section","embeds","detail","component","my","pl","message","size","aria-expanded","onClick","prior","in","unmountOnExit","m","fontFamily","whiteSpace","overflowX","display","toLocaleString","retryRefusal","disabled","Boolean"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SACEA,4BAA4B,EAC5BC,8BAA8B,EAC9BC,cAAc,QAET,4BAAwB;AAE/B,SAASC,uBAAuB,QAAQ,0BAAsB;AAC9D,SAASC,4BAA4B,QAAQ,kCAA8B;AAC3E,SAASC,qBAAqB,QAAQ,0CAAsC;AAC5E,SAASC,GAAG,EAAEC,MAAM,EAAEC,QAAQ,EAAEC,KAAK,EAAEC,UAAU,QAAQ,gBAAe;AACxE,SAASC,QAAQ,QAAQ,QAAO;AA6BhC;;;;;CAKC,GACD,OAAO,SAASC,mBAAmBC,MAA0B;QAUxCA;IATnB,IAAIA,CAAAA,0BAAAA,OAAQC,MAAM,MAAK,YAAY,OAAO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AiJobSummary } from '../model/ai-jobs.types';
3
+ /**
4
+ * The two decisions a person makes about a job — confirm its plan (or try a
5
+ * refused step again), and cancel it — as ONE request each, whichever
6
+ * surface they press it on (AGL-3593). The AI jobs drawer and the dialog that
7
+ * started the job both call these, so confirming in the dialog is the same
8
+ * door, the same body and the same answer as confirming in the drawer.
9
+ *
10
+ * Each hands the job it gets back to every counting surface, so the top-bar
11
+ * indicator stops saying "plan ready" the moment the plan is confirmed.
12
+ */
13
+ /** A door's answer: the job as it now stands, and the refusal when there is one. */
14
+ export interface AiJobDecision {
15
+ job: AiJobSummary | null;
16
+ error: string | null;
17
+ }
18
+ /**
19
+ * Confirms a plan, or tries again a step whose answer broke a building rule
20
+ * (AGL-2935). The door runs the next step inline and answers with the job.
21
+ */
22
+ export declare function resumeAiJobRequest(user: MaybeTokenSource, orgId: string, job: Pick<AiJobSummary, 'id' | 'hostId'>): Promise<AiJobDecision>;
23
+ /** Cancels a job that has not settled. */
24
+ export declare function cancelAiJobRequest(user: MaybeTokenSource, orgId: string, jobId: string): Promise<AiJobDecision>;
@@ -0,0 +1,76 @@
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
+ */ 'use client';
17
+ import { authorizedFetch } from "@aglyn/shared-util-http/authorized-token";
18
+ import { publishAiJob } from "./ai-jobs-store.js";
19
+ /**
20
+ * Confirms a plan, or tries again a step whose answer broke a building rule
21
+ * (AGL-2935). The door runs the next step inline and answers with the job.
22
+ */ export async function resumeAiJobRequest(user, orgId, job) {
23
+ try {
24
+ var _ref, _ref1;
25
+ const response = await authorizedFetch(user, `/api/ai/jobs/${encodeURIComponent(job.id)}/resume`, {
26
+ method: 'POST',
27
+ headers: {
28
+ 'Content-Type': 'application/json'
29
+ },
30
+ body: JSON.stringify({
31
+ orgId,
32
+ hostId: job.hostId
33
+ })
34
+ });
35
+ const payload = await response.json().catch(()=>null);
36
+ const next = (_ref = payload == null ? void 0 : payload.job) != null ? _ref : null;
37
+ publishAiJob(next);
38
+ return {
39
+ job: next,
40
+ error: response.ok ? null : String((_ref1 = payload == null ? void 0 : payload.error) != null ? _ref1 : 'The job could not be resumed — try again.')
41
+ };
42
+ } catch (unused) {
43
+ return {
44
+ job: null,
45
+ error: 'The job could not be resumed — try again.'
46
+ };
47
+ }
48
+ }
49
+ /** Cancels a job that has not settled. */ export async function cancelAiJobRequest(user, orgId, jobId) {
50
+ try {
51
+ var _ref, _ref1;
52
+ const response = await authorizedFetch(user, `/api/ai/jobs/${encodeURIComponent(jobId)}/cancel`, {
53
+ method: 'POST',
54
+ headers: {
55
+ 'Content-Type': 'application/json'
56
+ },
57
+ body: JSON.stringify({
58
+ orgId
59
+ })
60
+ });
61
+ const payload = await response.json().catch(()=>null);
62
+ const next = (_ref = payload == null ? void 0 : payload.job) != null ? _ref : null;
63
+ publishAiJob(next);
64
+ return {
65
+ job: next,
66
+ error: response.ok ? null : String((_ref1 = payload == null ? void 0 : payload.error) != null ? _ref1 : 'The job could not be canceled — try again.')
67
+ };
68
+ } catch (unused) {
69
+ return {
70
+ job: null,
71
+ error: 'The job could not be canceled — try again.'
72
+ };
73
+ }
74
+ }
75
+
76
+ //# sourceMappingURL=ai-job-requests.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/components/ai-job-requests.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'use client'\n\nimport { authorizedFetch, type MaybeTokenSource } from '@aglyn/shared-util-http/authorized-token'\nimport type { AiJobSummary } from '../model/ai-jobs.types'\nimport { publishAiJob } from './ai-jobs-store'\n\n/**\n * The two decisions a person makes about a job — confirm its plan (or try a\n * refused step again), and cancel it — as ONE request each, whichever\n * surface they press it on (AGL-3593). The AI jobs drawer and the dialog that\n * started the job both call these, so confirming in the dialog is the same\n * door, the same body and the same answer as confirming in the drawer.\n *\n * Each hands the job it gets back to every counting surface, so the top-bar\n * indicator stops saying \"plan ready\" the moment the plan is confirmed.\n */\n\n/** A door's answer: the job as it now stands, and the refusal when there is one. */\nexport interface AiJobDecision {\n job: AiJobSummary | null\n error: string | null\n}\n\n/**\n * Confirms a plan, or tries again a step whose answer broke a building rule\n * (AGL-2935). The door runs the next step inline and answers with the job.\n */\nexport async function resumeAiJobRequest(\n user: MaybeTokenSource,\n orgId: string,\n job: Pick<AiJobSummary, 'id' | 'hostId'>,\n): Promise<AiJobDecision> {\n try {\n const response = await authorizedFetch(\n user,\n `/api/ai/jobs/${encodeURIComponent(job.id)}/resume`,\n {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({ orgId, hostId: job.hostId }),\n },\n )\n const payload = await response.json().catch(() => null)\n const next = (payload?.job as AiJobSummary | undefined) ?? null\n publishAiJob(next)\n return {\n job: next,\n error: response.ok\n ? null\n : String(payload?.error ?? 'The job could not be resumed — try again.'),\n }\n } catch {\n return { job: null, error: 'The job could not be resumed — try again.' }\n }\n}\n\n/** Cancels a job that has not settled. */\nexport async function cancelAiJobRequest(\n user: MaybeTokenSource,\n orgId: string,\n jobId: string,\n): Promise<AiJobDecision> {\n try {\n const response = await authorizedFetch(\n user,\n `/api/ai/jobs/${encodeURIComponent(jobId)}/cancel`,\n {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({ orgId }),\n },\n )\n const payload = await response.json().catch(() => null)\n const next = (payload?.job as AiJobSummary | undefined) ?? null\n publishAiJob(next)\n return {\n job: next,\n error: response.ok\n ? null\n : String(payload?.error ?? 'The job could not be canceled — try again.'),\n }\n } catch {\n return { job: null, error: 'The job could not be canceled — try again.' }\n }\n}\n"],"names":["authorizedFetch","publishAiJob","resumeAiJobRequest","user","orgId","job","response","encodeURIComponent","id","method","headers","body","JSON","stringify","hostId","payload","json","catch","next","error","ok","String","cancelAiJobRequest","jobId"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GACD;AAEA,SAASA,eAAe,QAA+B,2CAA0C;AAEjG,SAASC,YAAY,QAAQ,qBAAiB;AAmB9C;;;CAGC,GACD,OAAO,eAAeC,mBACpBC,IAAsB,EACtBC,KAAa,EACbC,GAAwC;IAExC,IAAI;;QACF,MAAMC,WAAW,MAAMN,gBACrBG,MACA,CAAC,aAAa,EAAEI,mBAAmBF,IAAIG,EAAE,EAAE,OAAO,CAAC,EACnD;YACEC,QAAQ;YACRC,SAAS;gBAAE,gBAAgB;YAAmB;YAC9CC,MAAMC,KAAKC,SAAS,CAAC;gBAAET;gBAAOU,QAAQT,IAAIS,MAAM;YAAC;QACnD;QAEF,MAAMC,UAAU,MAAMT,SAASU,IAAI,GAAGC,KAAK,CAAC,IAAM;QAClD,MAAMC,eAAQH,2BAAAA,QAASV,GAAG,mBAAiC;QAC3DJ,aAAaiB;QACb,OAAO;YACLb,KAAKa;YACLC,OAAOb,SAASc,EAAE,GACd,OACAC,gBAAON,2BAAAA,QAASI,KAAK,oBAAI;QAC/B;IACF,EAAE,eAAM;QACN,OAAO;YAAEd,KAAK;YAAMc,OAAO;QAA4C;IACzE;AACF;AAEA,wCAAwC,GACxC,OAAO,eAAeG,mBACpBnB,IAAsB,EACtBC,KAAa,EACbmB,KAAa;IAEb,IAAI;;QACF,MAAMjB,WAAW,MAAMN,gBACrBG,MACA,CAAC,aAAa,EAAEI,mBAAmBgB,OAAO,OAAO,CAAC,EAClD;YACEd,QAAQ;YACRC,SAAS;gBAAE,gBAAgB;YAAmB;YAC9CC,MAAMC,KAAKC,SAAS,CAAC;gBAAET;YAAM;QAC/B;QAEF,MAAMW,UAAU,MAAMT,SAASU,IAAI,GAAGC,KAAK,CAAC,IAAM;QAClD,MAAMC,eAAQH,2BAAAA,QAASV,GAAG,mBAAiC;QAC3DJ,aAAaiB;QACb,OAAO;YACLb,KAAKa;YACLC,OAAOb,SAASc,EAAE,GACd,OACAC,gBAAON,2BAAAA,QAASI,KAAK,oBAAI;QAC/B;IACF,EAAE,eAAM;QACN,OAAO;YAAEd,KAAK;YAAMc,OAAO;QAA6C;IAC1E;AACF"}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * The site a site's AI jobs pages are about (AGL-3596): its workspace, which
3
+ * every jobs request names, and its display name. Read once off the site
4
+ * document the reader may already read.
5
+ *
6
+ * It always settles. A read that fails, a document without a workspace, or a
7
+ * read still out after {@link AI_JOB_SITE_TIMEOUT_MS} is `error`, so a page
8
+ * waiting on it says so instead of spinning: without a workspace there is no
9
+ * job to ask for, and nothing would ever arrive to end the wait.
10
+ */
11
+ export type AiJobSite = {
12
+ status: 'loading';
13
+ } | {
14
+ status: 'ready';
15
+ orgId: string;
16
+ name: string;
17
+ } | {
18
+ status: 'error';
19
+ };
20
+ /** How long the site's read may take before the page says it could not be read. */
21
+ export declare const AI_JOB_SITE_TIMEOUT_MS = 15000;
22
+ export declare function useAiJobSite(hostId: string | null | undefined): AiJobSite;
@@ -0,0 +1,73 @@
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
+ */ 'use client';
17
+ import { useFirestore } from "@aglyn/tenant-feature-instance";
18
+ import { doc, getDoc } from "firebase/firestore";
19
+ import { useEffect, useRef, useState } from "react";
20
+ /** How long the site's read may take before the page says it could not be read. */ export const AI_JOB_SITE_TIMEOUT_MS = 15000;
21
+ export function useAiJobSite(hostId) {
22
+ // Read through a ref: the read is keyed on the site alone, so a provider
23
+ // that hands back a new handle each render does not read it again.
24
+ const firestore = useFirestore();
25
+ const firestoreRef = useRef(firestore);
26
+ firestoreRef.current = firestore;
27
+ const [site, setSite] = useState({
28
+ status: 'loading'
29
+ });
30
+ useEffect(()=>{
31
+ if (!hostId) {
32
+ setSite({
33
+ status: 'error'
34
+ });
35
+ return undefined;
36
+ }
37
+ let active = true;
38
+ setSite((current)=>current.status === 'loading' ? current : {
39
+ status: 'loading'
40
+ });
41
+ const settle = (next)=>{
42
+ if (!active) return;
43
+ active = false;
44
+ setSite(next);
45
+ };
46
+ const timer = setTimeout(()=>settle({
47
+ status: 'error'
48
+ }), AI_JOB_SITE_TIMEOUT_MS);
49
+ void getDoc(doc(firestoreRef.current, 'hosts', hostId)).then((snapshot)=>{
50
+ var _snapshot_data;
51
+ const data = (_snapshot_data = snapshot.data()) != null ? _snapshot_data : {};
52
+ const orgId = typeof data.orgId === 'string' ? data.orgId : '';
53
+ settle(orgId ? {
54
+ status: 'ready',
55
+ orgId,
56
+ name: typeof data.displayName === 'string' ? data.displayName : ''
57
+ } : {
58
+ status: 'error'
59
+ });
60
+ }).catch(()=>settle({
61
+ status: 'error'
62
+ }));
63
+ return ()=>{
64
+ active = false;
65
+ clearTimeout(timer);
66
+ };
67
+ }, [
68
+ hostId
69
+ ]);
70
+ return site;
71
+ }
72
+
73
+ //# sourceMappingURL=ai-job-site.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/components/ai-job-site.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'use client'\n\nimport { useFirestore } from '@aglyn/tenant-feature-instance'\nimport { doc, getDoc } from 'firebase/firestore'\nimport { useEffect, useRef, useState } from 'react'\n\n/**\n * The site a site's AI jobs pages are about (AGL-3596): its workspace, which\n * every jobs request names, and its display name. Read once off the site\n * document the reader may already read.\n *\n * It always settles. A read that fails, a document without a workspace, or a\n * read still out after {@link AI_JOB_SITE_TIMEOUT_MS} is `error`, so a page\n * waiting on it says so instead of spinning: without a workspace there is no\n * job to ask for, and nothing would ever arrive to end the wait.\n */\nexport type AiJobSite =\n | { status: 'loading' }\n | { status: 'ready'; orgId: string; name: string }\n | { status: 'error' }\n\n/** How long the site's read may take before the page says it could not be read. */\nexport const AI_JOB_SITE_TIMEOUT_MS = 15_000\n\nexport function useAiJobSite(hostId: string | null | undefined): AiJobSite {\n // Read through a ref: the read is keyed on the site alone, so a provider\n // that hands back a new handle each render does not read it again.\n const firestore = useFirestore()\n const firestoreRef = useRef(firestore)\n firestoreRef.current = firestore\n const [site, setSite] = useState<AiJobSite>({ status: 'loading' })\n useEffect(() => {\n if (!hostId) {\n setSite({ status: 'error' })\n return undefined\n }\n let active = true\n setSite((current) => (current.status === 'loading' ? current : { status: 'loading' }))\n const settle = (next: AiJobSite) => {\n if (!active) return\n active = false\n setSite(next)\n }\n const timer = setTimeout(() => settle({ status: 'error' }), AI_JOB_SITE_TIMEOUT_MS)\n void getDoc(doc(firestoreRef.current, 'hosts', hostId))\n .then((snapshot) => {\n const data = (snapshot.data() ?? {}) as { orgId?: unknown; displayName?: unknown }\n const orgId = typeof data.orgId === 'string' ? data.orgId : ''\n settle(\n orgId\n ? { status: 'ready', orgId, name: typeof data.displayName === 'string' ? data.displayName : '' }\n : { status: 'error' },\n )\n })\n .catch(() => settle({ status: 'error' }))\n return () => {\n active = false\n clearTimeout(timer)\n }\n }, [hostId])\n return site\n}\n"],"names":["useFirestore","doc","getDoc","useEffect","useRef","useState","AI_JOB_SITE_TIMEOUT_MS","useAiJobSite","hostId","firestore","firestoreRef","current","site","setSite","status","undefined","active","settle","next","timer","setTimeout","then","snapshot","data","orgId","name","displayName","catch","clearTimeout"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GACD;AAEA,SAASA,YAAY,QAAQ,iCAAgC;AAC7D,SAASC,GAAG,EAAEC,MAAM,QAAQ,qBAAoB;AAChD,SAASC,SAAS,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,QAAO;AAiBnD,iFAAiF,GACjF,OAAO,MAAMC,yBAAyB,MAAM;AAE5C,OAAO,SAASC,aAAaC,MAAiC;IAC5D,yEAAyE;IACzE,mEAAmE;IACnE,MAAMC,YAAYT;IAClB,MAAMU,eAAeN,OAAOK;IAC5BC,aAAaC,OAAO,GAAGF;IACvB,MAAM,CAACG,MAAMC,QAAQ,GAAGR,SAAoB;QAAES,QAAQ;IAAU;IAChEX,UAAU;QACR,IAAI,CAACK,QAAQ;YACXK,QAAQ;gBAAEC,QAAQ;YAAQ;YAC1B,OAAOC;QACT;QACA,IAAIC,SAAS;QACbH,QAAQ,CAACF,UAAaA,QAAQG,MAAM,KAAK,YAAYH,UAAU;gBAAEG,QAAQ;YAAU;QACnF,MAAMG,SAAS,CAACC;YACd,IAAI,CAACF,QAAQ;YACbA,SAAS;YACTH,QAAQK;QACV;QACA,MAAMC,QAAQC,WAAW,IAAMH,OAAO;gBAAEH,QAAQ;YAAQ,IAAIR;QAC5D,KAAKJ,OAAOD,IAAIS,aAAaC,OAAO,EAAE,SAASH,SAC5Ca,IAAI,CAAC,CAACC;gBACSA;YAAd,MAAMC,QAAQD,iBAAAA,SAASC,IAAI,cAAbD,iBAAmB,CAAC;YAClC,MAAME,QAAQ,OAAOD,KAAKC,KAAK,KAAK,WAAWD,KAAKC,KAAK,GAAG;YAC5DP,OACEO,QACI;gBAAEV,QAAQ;gBAASU;gBAAOC,MAAM,OAAOF,KAAKG,WAAW,KAAK,WAAWH,KAAKG,WAAW,GAAG;YAAG,IAC7F;gBAAEZ,QAAQ;YAAQ;QAE1B,GACCa,KAAK,CAAC,IAAMV,OAAO;gBAAEH,QAAQ;YAAQ;QACxC,OAAO;YACLE,SAAS;YACTY,aAAaT;QACf;IACF,GAAG;QAACX;KAAO;IACX,OAAOI;AACT"}
@@ -0,0 +1,25 @@
1
+ import { type ConsoleTopBarZoneProps } from '@aglyn/aglyn';
2
+ /**
3
+ * The AI jobs indicator in the console's top bar (AGL-3593), on the
4
+ * `consoleTopBar` zone: one small chip while any of the workspace's jobs is
5
+ * moving or waiting on a person, saying which — `AI · plan ready` before
6
+ * `AI · needs attention` before `AI · planning` — and how many. Pressing it
7
+ * opens AI jobs in the Assist panel on the job that has waited longest.
8
+ *
9
+ * Nothing at all when nothing is in flight, so a workspace with no AI work
10
+ * sees the bar it always had. It reads the shared list the launcher's badge
11
+ * and the drawer read ({@link useAiJobsActivity}): one read per page load,
12
+ * and a re-read only while something is moving.
13
+ *
14
+ * Gated as the plugin's other generative widgets are — the plan's
15
+ * `aiGenerative` and the reader's `ai.generate` at registration — and, here,
16
+ * on the two release flags the drawer it opens needs: `release_ai_generative`
17
+ * for the jobs, `release_assist` for the panel they are listed in. The
18
+ * reader's `ai.generate` on the site in view is asked again, because on a
19
+ * site's pages a collaborator's permission is the site's, not the org's.
20
+ */
21
+ export declare function AiJobsTopBarIndicator({ scopedOrgId, org, orgReady, releaseVerdict, permissionsOnHost, productName, }: ConsoleTopBarZoneProps): import("react").JSX.Element;
22
+ export declare namespace AiJobsTopBarIndicator {
23
+ var displayName: string;
24
+ }
25
+ export default AiJobsTopBarIndicator;
@@ -0,0 +1,80 @@
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
+ */ 'use client';
17
+ import { jsx as _jsx } from "react/jsx-runtime";
18
+ import { checkEntitlement } from "@aglyn/aglyn";
19
+ import { mdiAutoFix } from "@aglyn/shared-data-mdi";
20
+ import { MdiIcon } from "@aglyn/shared-ui-jsx";
21
+ import { useUser } from "@aglyn/tenant-feature-instance";
22
+ import { Chip, CircularProgress, Tooltip } from "@mui/material";
23
+ import { aiJobsActivityLabel } from "../model/ai-job-activity.js";
24
+ import { aiPermissionsOf } from "../model/ai-permissions.js";
25
+ import { openAiJobs, useAiJobsActivity } from "./ai-jobs-store.js";
26
+ /**
27
+ * The AI jobs indicator in the console's top bar (AGL-3593), on the
28
+ * `consoleTopBar` zone: one small chip while any of the workspace's jobs is
29
+ * moving or waiting on a person, saying which — `AI · plan ready` before
30
+ * `AI · needs attention` before `AI · planning` — and how many. Pressing it
31
+ * opens AI jobs in the Assist panel on the job that has waited longest.
32
+ *
33
+ * Nothing at all when nothing is in flight, so a workspace with no AI work
34
+ * sees the bar it always had. It reads the shared list the launcher's badge
35
+ * and the drawer read ({@link useAiJobsActivity}): one read per page load,
36
+ * and a re-read only while something is moving.
37
+ *
38
+ * Gated as the plugin's other generative widgets are — the plan's
39
+ * `aiGenerative` and the reader's `ai.generate` at registration — and, here,
40
+ * on the two release flags the drawer it opens needs: `release_ai_generative`
41
+ * for the jobs, `release_assist` for the panel they are listed in. The
42
+ * reader's `ai.generate` on the site in view is asked again, because on a
43
+ * site's pages a collaborator's permission is the site's, not the org's.
44
+ */ export function AiJobsTopBarIndicator({ scopedOrgId, org, orgReady, releaseVerdict, permissionsOnHost, productName }) {
45
+ const { data: user } = useUser();
46
+ const generate = (permissionsOnHost == null ? void 0 : permissionsOnHost.loaded) === true && aiPermissionsOf(permissionsOnHost.granted)['ai.generate'] === true;
47
+ const visible = Boolean(scopedOrgId) && orgReady && checkEntitlement(org, 'aiGenerative') && releaseVerdict('release_ai_generative').visible && releaseVerdict('release_assist').visible && generate;
48
+ const activity = useAiJobsActivity(user, scopedOrgId, visible);
49
+ if (!visible || !activity) return null;
50
+ const waiting = activity.state !== 'running';
51
+ return /*#__PURE__*/ _jsx(Tooltip, {
52
+ title: `Open AI jobs in ${productName} Assist`,
53
+ children: /*#__PURE__*/ _jsx(Chip, {
54
+ size: "small",
55
+ clickable: true,
56
+ color: waiting ? 'warning' : 'primary',
57
+ variant: waiting ? 'filled' : 'outlined',
58
+ icon: waiting ? /*#__PURE__*/ _jsx(MdiIcon, {
59
+ path: mdiAutoFix.path
60
+ }) : /*#__PURE__*/ _jsx(CircularProgress, {
61
+ size: 12,
62
+ color: "inherit",
63
+ "aria-hidden": true
64
+ }),
65
+ label: aiJobsActivityLabel(activity),
66
+ "aria-label": `${aiJobsActivityLabel(activity)}. Open AI jobs`,
67
+ onClick: ()=>openAiJobs({
68
+ jobId: activity.job.id
69
+ }),
70
+ "data-ai-jobs-state": activity.state,
71
+ sx: {
72
+ mx: 0.5
73
+ }
74
+ })
75
+ });
76
+ }
77
+ AiJobsTopBarIndicator.displayName = 'AiJobsTopBarIndicator';
78
+ export default AiJobsTopBarIndicator;
79
+
80
+ //# sourceMappingURL=ai-jobs-indicator.component.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/components/ai-jobs-indicator.component.tsx"],"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'use client'\n\nimport { checkEntitlement, type ConsoleTopBarZoneProps } from '@aglyn/aglyn'\nimport { mdiAutoFix } from '@aglyn/shared-data-mdi'\nimport { MdiIcon } from '@aglyn/shared-ui-jsx'\nimport { useUser } from '@aglyn/tenant-feature-instance'\nimport { Chip, CircularProgress, Tooltip } from '@mui/material'\nimport { aiJobsActivityLabel } from '../model/ai-job-activity'\nimport { aiPermissionsOf } from '../model/ai-permissions'\nimport { openAiJobs, useAiJobsActivity } from './ai-jobs-store'\n\n/**\n * The AI jobs indicator in the console's top bar (AGL-3593), on the\n * `consoleTopBar` zone: one small chip while any of the workspace's jobs is\n * moving or waiting on a person, saying which — `AI · plan ready` before\n * `AI · needs attention` before `AI · planning` — and how many. Pressing it\n * opens AI jobs in the Assist panel on the job that has waited longest.\n *\n * Nothing at all when nothing is in flight, so a workspace with no AI work\n * sees the bar it always had. It reads the shared list the launcher's badge\n * and the drawer read ({@link useAiJobsActivity}): one read per page load,\n * and a re-read only while something is moving.\n *\n * Gated as the plugin's other generative widgets are — the plan's\n * `aiGenerative` and the reader's `ai.generate` at registration — and, here,\n * on the two release flags the drawer it opens needs: `release_ai_generative`\n * for the jobs, `release_assist` for the panel they are listed in. The\n * reader's `ai.generate` on the site in view is asked again, because on a\n * site's pages a collaborator's permission is the site's, not the org's.\n */\nexport function AiJobsTopBarIndicator({\n scopedOrgId,\n org,\n orgReady,\n releaseVerdict,\n permissionsOnHost,\n productName,\n}: ConsoleTopBarZoneProps) {\n const { data: user } = useUser()\n const generate =\n permissionsOnHost?.loaded === true &&\n aiPermissionsOf(permissionsOnHost.granted)['ai.generate'] === true\n const visible =\n Boolean(scopedOrgId) &&\n orgReady &&\n checkEntitlement(org as never, 'aiGenerative') &&\n releaseVerdict('release_ai_generative').visible &&\n releaseVerdict('release_assist').visible &&\n generate\n const activity = useAiJobsActivity(user, scopedOrgId, visible)\n if (!visible || !activity) return null\n\n const waiting = activity.state !== 'running'\n return (\n <Tooltip title={`Open AI jobs in ${productName} Assist`}>\n <Chip\n size=\"small\"\n clickable\n color={waiting ? 'warning' : 'primary'}\n variant={waiting ? 'filled' : 'outlined'}\n icon={\n waiting ? (\n <MdiIcon path={mdiAutoFix.path} />\n ) : (\n <CircularProgress size={12} color=\"inherit\" aria-hidden />\n )\n }\n label={aiJobsActivityLabel(activity)}\n aria-label={`${aiJobsActivityLabel(activity)}. Open AI jobs`}\n onClick={() => openAiJobs({ jobId: activity.job.id })}\n data-ai-jobs-state={activity.state}\n sx={{ mx: 0.5 }}\n />\n </Tooltip>\n )\n}\nAiJobsTopBarIndicator.displayName = 'AiJobsTopBarIndicator'\n\nexport default AiJobsTopBarIndicator\n"],"names":["checkEntitlement","mdiAutoFix","MdiIcon","useUser","Chip","CircularProgress","Tooltip","aiJobsActivityLabel","aiPermissionsOf","openAiJobs","useAiJobsActivity","AiJobsTopBarIndicator","scopedOrgId","org","orgReady","releaseVerdict","permissionsOnHost","productName","data","user","generate","loaded","granted","visible","Boolean","activity","waiting","state","title","size","clickable","color","variant","icon","path","aria-hidden","label","aria-label","onClick","jobId","job","id","data-ai-jobs-state","sx","mx","displayName"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GACD;;AAEA,SAASA,gBAAgB,QAAqC,eAAc;AAC5E,SAASC,UAAU,QAAQ,yBAAwB;AACnD,SAASC,OAAO,QAAQ,uBAAsB;AAC9C,SAASC,OAAO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E,KAAK;YAClCgB,IAAI;gBAAEC,IAAI;YAAI;;;AAItB;AACAjC,sBAAsBkC,WAAW,GAAG;AAEpC,eAAelC,sBAAqB"}
@@ -0,0 +1,23 @@
1
+ import type { ConsolePluginPageProps } from '@aglyn/aglyn/plugin-manager/feature-plugins';
2
+ import type { AiJobSummary } from '../model/ai-jobs.types';
3
+ /**
4
+ * A site's AI jobs (AGL-3596), at `/ai-jobs` under the site: every job that
5
+ * worked on this site, newest first, each linking to its own page.
6
+ *
7
+ * Read through the jobs route, never Firestore, so the membership, flag and
8
+ * plan rungs that answer every other jobs read answer this one. The site is
9
+ * a query on the route (`hostId`), not a filter of the workspace's list.
10
+ *
11
+ * Every wait ends: the site's read and the list's each settle on content,
12
+ * the empty state, or a sentence with Try again.
13
+ */
14
+ /** The most jobs the page lists; the newest, which is what a person comes for. */
15
+ export declare const AI_JOBS_PAGE_LIMIT = 50;
16
+ /** How long the list may take before the page says it could not be loaded. */
17
+ export declare const AI_JOBS_LIST_TIMEOUT_MS = 20000;
18
+ /** What a job cost the person: what it spent, less what we refunded. */
19
+ export declare function aiJobNetCredits(job: Pick<AiJobSummary, 'creditsSpent' | 'refundedCredits'>): number;
20
+ /** The kind as a row names it: `Site`, `Page`, `AI job`. */
21
+ export declare function aiJobKindLabel(kind: AiJobSummary['kind']): string;
22
+ export declare function AiJobsListPage({ hostId, basePath }: ConsolePluginPageProps): import("react").JSX.Element;
23
+ export default AiJobsListPage;