@aglyn/plugins-ai 1.0.0-beta.233 → 1.0.0-beta.235
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.
- package/package.json +17 -17
- package/src/lib/activity/ai-activity-actions.d.ts +25 -0
- package/src/lib/activity/ai-activity-actions.js +85 -4
- package/src/lib/activity/ai-activity-actions.js.map +1 -1
- package/src/lib/components/ai-brief-dialog.component.js +46 -2
- package/src/lib/components/ai-brief-dialog.component.js.map +1 -1
- package/src/lib/components/ai-campaign-create.component.js +1 -1
- package/src/lib/components/ai-campaign-create.component.js.map +1 -1
- package/src/lib/components/ai-credits-card.component.js +3 -3
- package/src/lib/components/ai-credits-card.component.js.map +1 -1
- package/src/lib/components/ai-crm-email-draft.component.js +1 -1
- package/src/lib/components/ai-crm-email-draft.component.js.map +1 -1
- package/src/lib/components/ai-crm-import-mapping.component.js +1 -1
- package/src/lib/components/ai-crm-import-mapping.component.js.map +1 -1
- package/src/lib/components/ai-crm-record-card.component.js +1 -1
- package/src/lib/components/ai-crm-record-card.component.js.map +1 -1
- package/src/lib/components/ai-describe-automation.component.js +4 -2
- package/src/lib/components/ai-describe-automation.component.js.map +1 -1
- package/src/lib/components/ai-describe-org-automation.component.js +1 -1
- package/src/lib/components/ai-describe-org-automation.component.js.map +1 -1
- package/src/lib/components/ai-experiment-cards.component.js +2 -2
- package/src/lib/components/ai-experiment-cards.component.js.map +1 -1
- package/src/lib/components/ai-explain-automation.component.js +1 -1
- package/src/lib/components/ai-explain-automation.component.js.map +1 -1
- package/src/lib/components/ai-insight-card.component.js +3 -1
- package/src/lib/components/ai-insight-card.component.js.map +1 -1
- package/src/lib/components/ai-job-links.d.ts +6 -0
- package/src/lib/components/ai-job-links.js +9 -0
- package/src/lib/components/ai-job-links.js.map +1 -1
- package/src/lib/components/ai-jobs-list-page.component.d.ts +6 -1
- package/src/lib/components/ai-jobs-list-page.component.js +15 -2
- package/src/lib/components/ai-jobs-list-page.component.js.map +1 -1
- package/src/lib/components/ai-logic.component.js +5 -3
- package/src/lib/components/ai-logic.component.js.map +1 -1
- package/src/lib/components/ai-media-create.component.js +88 -16
- package/src/lib/components/ai-media-create.component.js.map +1 -1
- package/src/lib/components/ai-model-selector.component.js +8 -0
- package/src/lib/components/ai-model-selector.component.js.map +1 -1
- package/src/lib/components/ai-overlay-cards.component.js +2 -2
- package/src/lib/components/ai-overlay-cards.component.js.map +1 -1
- package/src/lib/components/ai-product-copy-card.component.js +2 -1
- package/src/lib/components/ai-product-copy-card.component.js.map +1 -1
- package/src/lib/components/ai-products-hub-card.component.js +2 -1
- package/src/lib/components/ai-products-hub-card.component.js.map +1 -1
- package/src/lib/components/ai-revise-automation.component.js +1 -1
- package/src/lib/components/ai-revise-automation.component.js.map +1 -1
- package/src/lib/components/ai-seo-fields-card.component.js +7 -3
- package/src/lib/components/ai-seo-fields-card.component.js.map +1 -1
- package/src/lib/components/ai-site-batch-card.component.js +7 -4
- package/src/lib/components/ai-site-batch-card.component.js.map +1 -1
- package/src/lib/components/ai-site-build-page.component.js +48 -6
- package/src/lib/components/ai-site-build-page.component.js.map +1 -1
- package/src/lib/components/ai-site-seo-start-card.component.js +7 -4
- package/src/lib/components/ai-site-seo-start-card.component.js.map +1 -1
- package/src/lib/components/ai-site-start-card.component.js +152 -36
- package/src/lib/components/ai-site-start-card.component.js.map +1 -1
- package/src/lib/components/ai-theme-proposal-card.component.js +1 -0
- package/src/lib/components/ai-theme-proposal-card.component.js.map +1 -1
- package/src/lib/components/ai-upsell-dialog.component.js +17 -3
- package/src/lib/components/ai-upsell-dialog.component.js.map +1 -1
- package/src/lib/components/ai-usage-strip.component.js +13 -2
- package/src/lib/components/ai-usage-strip.component.js.map +1 -1
- package/src/lib/components/assist-build-card.component.js +20 -3
- package/src/lib/components/assist-build-card.component.js.map +1 -1
- package/src/lib/components/assist-jobs-drawer.component.js +7 -1
- package/src/lib/components/assist-jobs-drawer.component.js.map +1 -1
- package/src/lib/components/billing-ai-allotments.component.js +2 -2
- package/src/lib/components/billing-ai-allotments.component.js.map +1 -1
- package/src/lib/components/billing-ai-top-users.component.js +1 -0
- package/src/lib/components/billing-ai-top-users.component.js.map +1 -1
- package/src/lib/components/billing-assist-overage-card.component.js +2 -2
- package/src/lib/components/billing-assist-overage-card.component.js.map +1 -1
- package/src/lib/components/host-ai-allotments.component.js +2 -2
- package/src/lib/components/host-ai-allotments.component.js.map +1 -1
- package/src/lib/components/member-ai-allotment-card.component.js +2 -2
- package/src/lib/components/member-ai-allotment-card.component.js.map +1 -1
- package/src/lib/components/staff-org-ai-card.component.js +1 -0
- package/src/lib/components/staff-org-ai-card.component.js.map +1 -1
- package/src/lib/components/staff-org-ai-conversations.component.d.ts +9 -3
- package/src/lib/components/staff-org-ai-conversations.component.js +174 -83
- package/src/lib/components/staff-org-ai-conversations.component.js.map +1 -1
- package/src/lib/components/staff-user-ai-usage-card.component.js +2 -1
- package/src/lib/components/staff-user-ai-usage-card.component.js.map +1 -1
- package/src/lib/jobs/ai-job-admission.d.ts +2 -1
- package/src/lib/jobs/ai-job-admission.js.map +1 -1
- package/src/lib/jobs/ai-job-email-step.d.ts +39 -0
- package/src/lib/jobs/ai-job-email-step.js +116 -5
- package/src/lib/jobs/ai-job-email-step.js.map +1 -1
- package/src/lib/jobs/ai-job-layout-language.d.ts +3 -0
- package/src/lib/jobs/ai-job-layout-language.js +6 -1
- package/src/lib/jobs/ai-job-layout-language.js.map +1 -1
- package/src/lib/jobs/ai-job-layout-site-pages.d.ts +14 -0
- package/src/lib/jobs/ai-job-layout-site-pages.js +43 -11
- package/src/lib/jobs/ai-job-layout-site-pages.js.map +1 -1
- package/src/lib/jobs/ai-job-layout-step.js +3 -2
- package/src/lib/jobs/ai-job-layout-step.js.map +1 -1
- package/src/lib/jobs/ai-job-page-language.d.ts +26 -1
- package/src/lib/jobs/ai-job-page-language.js +75 -13
- package/src/lib/jobs/ai-job-page-language.js.map +1 -1
- package/src/lib/jobs/ai-job-page-step.d.ts +3 -0
- package/src/lib/jobs/ai-job-page-step.js +32 -7
- package/src/lib/jobs/ai-job-page-step.js.map +1 -1
- package/src/lib/jobs/ai-job-plan-step.d.ts +34 -0
- package/src/lib/jobs/ai-job-plan-step.js +106 -14
- package/src/lib/jobs/ai-job-plan-step.js.map +1 -1
- package/src/lib/jobs/ai-job-site-content.d.ts +81 -13
- package/src/lib/jobs/ai-job-site-content.js +210 -43
- package/src/lib/jobs/ai-job-site-content.js.map +1 -1
- package/src/lib/jobs/ai-job-site-step.d.ts +19 -0
- package/src/lib/jobs/ai-job-site-step.js +152 -51
- package/src/lib/jobs/ai-job-site-step.js.map +1 -1
- package/src/lib/jobs/ai-jobs.d.ts +8 -4
- package/src/lib/jobs/ai-jobs.js +19 -2
- package/src/lib/jobs/ai-jobs.js.map +1 -1
- package/src/lib/jobs/ai-layout-stock-photos.d.ts +98 -0
- package/src/lib/jobs/ai-layout-stock-photos.js +248 -0
- package/src/lib/jobs/ai-layout-stock-photos.js.map +1 -0
- package/src/lib/jobs/ai-site-publish.d.ts +11 -0
- package/src/lib/jobs/ai-site-publish.js +31 -1
- package/src/lib/jobs/ai-site-publish.js.map +1 -1
- package/src/lib/jobs/fixtures/ai-juniper-portfolio-page-recording.d.ts +151 -0
- package/src/lib/jobs/fixtures/ai-juniper-portfolio-page-recording.js +183 -0
- package/src/lib/jobs/fixtures/ai-juniper-portfolio-page-recording.js.map +1 -0
- package/src/lib/jobs/fixtures/ai-slow-roads-site-plan-recording.d.ts +27 -0
- package/src/lib/jobs/fixtures/ai-slow-roads-site-plan-recording.js +192 -0
- package/src/lib/jobs/fixtures/ai-slow-roads-site-plan-recording.js.map +1 -0
- package/src/lib/jobs/fixtures/ai-yoga-site-plan-recording.d.ts +27 -0
- package/src/lib/jobs/fixtures/ai-yoga-site-plan-recording.js +222 -0
- package/src/lib/jobs/fixtures/ai-yoga-site-plan-recording.js.map +1 -0
- package/src/lib/layout-language/ai-layout-compiler.d.ts +37 -0
- package/src/lib/layout-language/ai-layout-compiler.js +1003 -19
- package/src/lib/layout-language/ai-layout-compiler.js.map +1 -1
- package/src/lib/layout-language/ai-layout-design.d.ts +114 -0
- package/src/lib/layout-language/ai-layout-design.js +209 -0
- package/src/lib/layout-language/ai-layout-design.js.map +1 -0
- package/src/lib/layout-language/ai-layout-frame.d.ts +12 -0
- package/src/lib/layout-language/ai-layout-frame.js +33 -8
- package/src/lib/layout-language/ai-layout-frame.js.map +1 -1
- package/src/lib/layout-language/ai-layout-gaps.js +18 -2
- package/src/lib/layout-language/ai-layout-gaps.js.map +1 -1
- package/src/lib/layout-language/ai-layout-language.d.ts +2 -0
- package/src/lib/layout-language/ai-layout-language.js +15 -1
- package/src/lib/layout-language/ai-layout-language.js.map +1 -1
- package/src/lib/layout-language/ai-layout-links.d.ts +36 -0
- package/src/lib/layout-language/ai-layout-links.js +26 -2
- package/src/lib/layout-language/ai-layout-links.js.map +1 -1
- package/src/lib/layout-language/ai-layout-listings.d.ts +125 -0
- package/src/lib/layout-language/ai-layout-listings.js +187 -0
- package/src/lib/layout-language/ai-layout-listings.js.map +1 -0
- package/src/lib/layout-language/ai-layout-pictures.d.ts +11 -5
- package/src/lib/layout-language/ai-layout-pictures.js +80 -17
- package/src/lib/layout-language/ai-layout-pictures.js.map +1 -1
- package/src/lib/model/ai-job-notice.d.ts +9 -1
- package/src/lib/model/ai-job-notice.js +23 -0
- package/src/lib/model/ai-job-notice.js.map +1 -1
- package/src/lib/model/ai-plan-capabilities.d.ts +7 -0
- package/src/lib/model/ai-plan-capabilities.js.map +1 -1
- package/src/lib/model/ai-site-build-progress.d.ts +12 -2
- package/src/lib/model/ai-site-build-progress.js +104 -15
- package/src/lib/model/ai-site-build-progress.js.map +1 -1
- package/src/lib/model/ai-site-job.d.ts +236 -24
- package/src/lib/model/ai-site-job.js +269 -22
- package/src/lib/model/ai-site-job.js.map +1 -1
- package/src/lib/model/ai-site-kinds.d.ts +30 -8
- package/src/lib/model/ai-site-kinds.js +735 -116
- package/src/lib/model/ai-site-kinds.js.map +1 -1
- package/src/lib/model/ai-site-look.d.ts +21 -0
- package/src/lib/model/ai-site-look.js +63 -14
- package/src/lib/model/ai-site-look.js.map +1 -1
- package/src/lib/model/ai-site-start-seo.d.ts +30 -0
- package/src/lib/model/ai-site-start-seo.js +132 -11
- package/src/lib/model/ai-site-start-seo.js.map +1 -1
- package/src/lib/model/ai-site-start.d.ts +2 -2
- package/src/lib/model/ai-site-start.js +3 -3
- package/src/lib/model/ai-site-start.js.map +1 -1
- package/src/lib/plugin.js +15 -3
- package/src/lib/plugin.js.map +1 -1
- package/src/lib/runtime/ai-doctrine-validators.d.ts +32 -1
- package/src/lib/runtime/ai-doctrine-validators.js +227 -4
- package/src/lib/runtime/ai-doctrine-validators.js.map +1 -1
- package/src/lib/runtime/ai-doctrine.js +5 -3
- package/src/lib/runtime/ai-doctrine.js.map +1 -1
- package/src/lib/runtime/ai-palette.generated.d.ts +2 -0
- package/src/lib/runtime/ai-palette.generated.js +31 -5
- package/src/lib/runtime/ai-palette.generated.js.map +1 -1
- package/src/lib/server/ai-admin-conversations.d.ts +9 -0
- package/src/lib/server/ai-admin-conversations.js +151 -9
- package/src/lib/server/ai-admin-conversations.js.map +1 -1
- package/src/lib/server/ai-jobs-resume.js.map +1 -1
- package/src/lib/server/ai-jobs-route.js +15 -3
- package/src/lib/server/ai-jobs-route.js.map +1 -1
- package/src/lib/server/assist-edit.js +5 -2
- package/src/lib/server/assist-edit.js.map +1 -1
- package/src/lib/usage/free-ai-credits-left.d.ts +54 -0
- package/src/lib/usage/free-ai-credits-left.js +62 -0
- package/src/lib/usage/free-ai-credits-left.js.map +1 -0
- package/src/lib/usage/staff-org-ai-conversations.d.ts +23 -0
- package/src/lib/usage/staff-org-ai-conversations.js +45 -0
- package/src/lib/usage/staff-org-ai-conversations.js.map +1 -1
|
@@ -261,7 +261,7 @@ const VERSIONS_FAILED_COPY = 'The draft versions could not be made. Try again.';
|
|
|
261
261
|
target: "_blank",
|
|
262
262
|
rel: "noopener",
|
|
263
263
|
variant: "caption",
|
|
264
|
-
title: variantsHelp.
|
|
264
|
+
title: variantsHelp.excerptText,
|
|
265
265
|
children: 'How it works'
|
|
266
266
|
})
|
|
267
267
|
]
|
|
@@ -609,7 +609,7 @@ AiExperimentExplanation.displayName = 'AiExperimentExplanation';
|
|
|
609
609
|
target: "_blank",
|
|
610
610
|
rel: "noopener",
|
|
611
611
|
variant: "caption",
|
|
612
|
-
title: resultHelp.
|
|
612
|
+
title: resultHelp.excerptText,
|
|
613
613
|
children: 'How it works'
|
|
614
614
|
}),
|
|
615
615
|
/*#__PURE__*/ _jsx(Button, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/components/ai-experiment-cards.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 { pluginDocsHelp } from '@aglyn/aglyn/app-utils/docs-help'\nimport { authorizedFetch } from '@aglyn/shared-util-http/authorized-token'\nimport { ScrollTable } from '@aglyn/shared-ui-jsx/components/scroll-table.component'\nimport { useHostOrgId, useUser } from '@aglyn/tenant-feature-instance'\nimport {\n Alert,\n Box,\n Button,\n Chip,\n CircularProgress,\n Link,\n Stack,\n TableBody,\n TableCell,\n TableHead,\n TableRow,\n TextField,\n Typography,\n} from '@mui/material'\nimport { useEffect, useMemo, useState } from 'react'\nimport {\n AI_EXPERIMENT_SUBJECT_MAX_CHARS,\n type AiExperimentArm,\n type AiExperimentTarget,\n} from '../model/ai-experiment'\nimport {\n aiExperimentArmIsNamed,\n aiExperimentVerdictDisplay,\n readAiExperimentExplanation,\n readAiExperimentVariants,\n type AiExperimentExplanationProposal,\n type AiExperimentVariantsProposalView,\n} from '../model/ai-experiment-proposal'\nimport type { AiJobSummary } from '../model/ai-jobs.types'\nimport { aiJobProblem, useAiJobRun } from './use-ai-job-run'\n\n/**\n * A/B tests by AI in the console (AGL-2914): the two doors a person reaches\n * the `experiment` job through, and the surfaces that render what it answers.\n *\n * Both are widgets in zones the A/B TESTING card hosts, not surfaces of this\n * plugin's own. The test, the experiment document, the traffic split and the\n * counters belong to the plugin that draws that card, and neither plugin\n * imports the other: the zone's id and the props it hands a widget are the\n * whole contract, and the interfaces below restate the halves this widget\n * reads rather than importing the owner's.\n *\n * ## The result surface may not decide anything\n *\n * The step reached the verdict from the counts before a model was asked, and\n * cut the answer back to it. A card can undo all of that silently — a\n * confident heading, a highlighted row, a badge saying which to ship — and\n * the reader will take the layout for the claim. So {@link AiExperimentResultCard}\n * asks `aiExperimentVerdictDisplay` what the verdict permits before it draws\n * anything: an undecided result gets a neutral chip, a sentence saying it\n * settled nothing ABOVE the explanation, no marked arm and no recommendation.\n * Nothing on it is conditioned on which arm has the best rate.\n *\n * ## Neither card writes\n *\n * The variants card fills the experiment editor's own fields, unsaved, and\n * the dialog's Save is the write. The result card has nothing to apply.\n */\n\nconst VARIANTS_FAILED_COPY = 'Variants could not be written. Try again.'\nconst EXPLAIN_FAILED_COPY = 'The result could not be explained. Try again.'\n\n/** What the test varies, in the words this card's own copy uses. */\nconst TARGET_NOUN: Record<AiExperimentTarget, string> = {\n screen: 'page',\n section: 'section',\n email: 'email',\n}\n\n/** One of the experiment editor's variants, as the zone hands it over. */\nexport interface AiExperimentZoneVariant {\n id: string\n name: string\n subject: string\n body: string\n /** The screen version a page or section variant pins; empty for the published one. */\n versionId?: string\n}\n\n/** What the variants zone hands this widget. */\nexport interface AiExperimentVariantsCardProps {\n hostId: string\n experimentId: string\n name: string\n target: AiExperimentTarget\n goal: string\n /** A page or section test's page; empty until one is picked (AGL-3603). */\n screenId?: string\n /** A section test's element; empty until one is picked. */\n nodeId?: string\n variants: AiExperimentZoneVariant[]\n proposeVariants: (\n variants: readonly AiExperimentZoneVariant[],\n key: string,\n ) => void\n}\n\n/** What the result zone hands this widget. */\nexport interface AiExperimentResultCardProps {\n hostId: string\n experimentId: string\n test: string\n}\n\n/** The proposal a finished experiment job carries, whichever task it ran. */\nfunction proposalOf(job: AiJobSummary | null): Record<string, unknown> | null {\n if (job?.status !== 'done') return null\n return job.outputs.find((output) => output.resource === 'experiment')?.proposal ?? null\n}\n\nconst rateText = (value: number | null): string =>\n value === null ? '—' : `${value}%`\n\nconst liftText = (value: number | null): string =>\n value === null ? '—' : `${value >= 0 ? '+' : ''}${value}%`\n\n/**\n * The copy an email test varies, as the editor holds it: the FIRST variant's\n * subject and body, which is the control. A screen or a section varies a\n * screen version, which the editor does not hold, so there is nothing to\n * prefill and the person pastes what is under test.\n */\nexport function aiExperimentSubjectFrom(\n target: AiExperimentTarget,\n variants: readonly AiExperimentZoneVariant[],\n): string {\n if (target !== 'email') return ''\n const control = variants[0]\n if (!control) return ''\n return [control.subject, control.body].filter(Boolean).join('\\n\\n')\n}\n\n/**\n * A proposal mapped onto the editor's variants, in order. Only the fields\n * that target has a place for are filled: an email varies its subject and\n * body, and a screen or a section varies a screen version, so there only the\n * name is filled and the copy is read on the card.\n */\nexport function aiExperimentVariantDrafts(\n target: AiExperimentTarget,\n variants: readonly AiExperimentZoneVariant[],\n proposal: AiExperimentVariantsProposalView,\n /** Draft versions made for a page or section test (AGL-3603), by the proposal's index. */\n versions: ReadonlyMap<number, string> = new Map(),\n): AiExperimentZoneVariant[] {\n return variants.map((variant, index) => {\n const proposed = proposal.variants[index]\n if (!proposed) return variant\n const versionId = target === 'email' ? undefined : versions.get(index)\n return {\n id: variant.id,\n name: proposed.name,\n subject: target === 'email' ? proposed.subject : '',\n body: target === 'email' ? proposed.body : '',\n ...(versionId ? { versionId } : {}),\n }\n })\n}\n\n/** What the draft versions door answers. */\ninterface AiExperimentVersionsAnswer {\n versions?: Array<{ index: number; name: string; versionId: string }>\n skipped?: Array<{ index: number; reason: string }>\n error?: string\n}\n\n/** Where a proposed variant's copy lands, said before the person presses the button. */\nexport function aiExperimentApplyCopy(target: AiExperimentTarget): string {\n return target === 'email'\n ? 'Each variant above takes its name, subject and body. Nothing is saved until you save the experiment.'\n : 'Each variant above takes its name. Make draft versions to put each variant’s copy into a new unpublished version of the page, pinned to its variant; the first stays on the published page as the control.'\n}\n\nconst VERSIONS_FAILED_COPY = 'The draft versions could not be made. Try again.'\n\n/**\n * \"Write variants with AI\", in the experiment editor beneath the variants it\n * writes for. It proposes COPY: no weight, no traffic split, no goal and no\n * schedule, and the first variant it writes is the copy as it stands so the\n * test has something to measure against.\n */\nexport function AiExperimentVariantsCard(props: AiExperimentVariantsCardProps) {\n const { hostId, target, variants, proposeVariants } = props\n // The zone hands the SITE, which is what the card it is drawn in knows. The\n // organization is this widget's to resolve, as every AI widget in another\n // plugin's zone resolves it.\n const orgId = useHostOrgId(hostId) ?? undefined\n const { data: user } = useUser()\n const run = useAiJobRun(user, VARIANTS_FAILED_COPY)\n const prefill = useMemo(\n () => aiExperimentSubjectFrom(target, variants),\n [target, variants],\n )\n const [subject, setSubject] = useState(prefill)\n const [applied, setApplied] = useState<string | null>(null)\n const [versioning, setVersioning] = useState(false)\n const [versionsNote, setVersionsNote] = useState<{ ok: boolean; text: string } | null>(null)\n // The control's copy follows the editor until the person edits this field,\n // so switching a draft test from a page to an email fills it rather than\n // leaving the earlier target's copy under a question about a new one.\n const [typed, setTyped] = useState(false)\n useEffect(() => {\n if (!typed) setSubject(prefill)\n }, [prefill, typed])\n\n const proposal = useMemo(\n () => readAiExperimentVariants(proposalOf(run.job)),\n [run.job],\n )\n const problem =\n aiJobProblem(run.job, VARIANTS_FAILED_COPY) ??\n (run.job?.status === 'done' && !proposal ? VARIANTS_FAILED_COPY : null)\n\n\n const busy = run.starting || run.running\n const noun = TARGET_NOUN[target]\n const variantsHelp = pluginDocsHelp('aiExperiments', {\n anchor: '#write-variants',\n excerpt:\n 'Writes two to four variants of the copy under test, the first of them your copy unchanged. They go into the editor’s fields unsaved; nothing is saved until you save the experiment.',\n })\n const write = () => {\n if (!orgId || !subject.trim()) return\n setApplied(null)\n void run.start({\n orgId,\n hostId,\n kind: 'experiment',\n brief:\n `Write variants of this ${noun} for the A/B test ` +\n `“${props.name.trim() || 'this test'}”.`,\n inputs: {\n task: 'variants',\n target,\n subject: subject.trim().slice(0, AI_EXPERIMENT_SUBJECT_MAX_CHARS),\n goal: props.goal,\n ...(props.experimentId ? { experimentId: props.experimentId } : {}),\n },\n })\n }\n\n const apply = () => {\n if (!proposal || !run.job) return\n proposeVariants(\n aiExperimentVariantDrafts(target, variants, proposal),\n run.job.id,\n )\n setApplied(run.job.id)\n }\n\n /*\n * A page or a section varies a VERSION of the page (AGL-3603): the door\n * copies the published version once per variant past the control, puts\n * the variant's copy into it, and stores it unpublished; the versions are\n * then pinned to the variants here as unsaved edits.\n */\n const screenId = props.screenId ?? ''\n const nodeId = props.nodeId ?? ''\n const versionsBlocked =\n target === 'email'\n ? null\n : !screenId\n ? 'Pick the page under test above to make draft versions.'\n : target === 'section' && !nodeId\n ? 'Pick the section under test above to make draft versions.'\n : null\n const makeVersions = async () => {\n if (!proposal || !run.job || !orgId || versionsBlocked) return\n const jobId = run.job.id\n setVersioning(true)\n setVersionsNote(null)\n try {\n const response = await authorizedFetch(user, '/api/ai/experiments/versions', {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({ orgId, hostId, jobId, screenId, ...(nodeId ? { nodeId } : {}) }),\n })\n const answer = ((await response.json().catch(() => null)) ?? {}) as AiExperimentVersionsAnswer\n if (!response.ok) {\n setVersionsNote({ ok: false, text: answer.error || VERSIONS_FAILED_COPY })\n return\n }\n const made = new Map((answer.versions ?? []).map((entry) => [entry.index, entry.versionId]))\n proposeVariants(aiExperimentVariantDrafts(target, variants, proposal, made), jobId)\n setApplied(jobId)\n const names = (answer.versions ?? []).map((entry) => entry.name)\n const skipped = answer.skipped ?? []\n setVersionsNote({\n ok: names.length > 0,\n text: [\n names.length\n ? `Draft versions made and pinned above: ${names.join(', ')}. Open each in the editor to check it, then Save the experiment. Nothing is published.`\n : 'No draft version could be made.',\n ...skipped.map((entry) => `Variant ${entry.index + 1}: ${entry.reason}`),\n ].join(' '),\n })\n } catch {\n setVersionsNote({ ok: false, text: VERSIONS_FAILED_COPY })\n } finally {\n setVersioning(false)\n }\n }\n\n return (\n <Box\n sx={{ border: 1, borderColor: 'divider', borderRadius: 1, p: 1.5 }}\n aria-label=\"Write variants with AI\"\n >\n <Stack spacing={1}>\n <Stack direction=\"row\" spacing={1} sx={{ alignItems: 'baseline' }}>\n <Typography variant=\"subtitle2\" sx={{ flexGrow: 1 }}>\n {'Write variants with AI'}\n </Typography>\n <Link\n href={variantsHelp.href}\n target=\"_blank\"\n rel=\"noopener\"\n variant=\"caption\"\n title={variantsHelp.excerpt}\n >\n {'How it works'}\n </Link>\n </Stack>\n <TextField\n size=\"small\"\n multiline\n minRows={2}\n label={`The ${noun} copy under test`}\n placeholder={\n target === 'email'\n ? 'The subject line and message as they stand'\n : 'The headline and copy as they stand on the page'\n }\n helperText={\n 'Variants are written from this. The first one it writes is this copy unchanged, so the test has a control.'\n }\n value={subject}\n onChange={(event) => {\n setTyped(true)\n setSubject(event.target.value.slice(0, AI_EXPERIMENT_SUBJECT_MAX_CHARS))\n }}\n disabled={busy}\n />\n <Stack direction=\"row\" spacing={1} sx={{ alignItems: 'center' }}>\n <Button\n size=\"small\"\n variant=\"outlined\"\n disabled={busy || !orgId || !subject.trim()}\n onClick={write}\n >\n {run.job && !busy ? 'Write them again' : 'Write variants'}\n </Button>\n {busy ? <CircularProgress size={16} aria-label=\"Writing variants\" /> : null}\n </Stack>\n {run.notice ? <Alert severity=\"warning\">{run.notice}</Alert> : null}\n {problem ? (\n <Alert severity={run.job?.status === 'failed' ? 'error' : 'warning'}>\n {problem}\n </Alert>\n ) : null}\n\n {proposal ? (\n <Stack spacing={1} aria-label=\"Proposed variants\">\n {proposal.goal ? (\n <Typography variant=\"body2\" color=\"text.secondary\">\n {`Written to move: ${proposal.goal}`}\n </Typography>\n ) : null}\n {proposal.variants.map((variant, index) => (\n <Box\n key={`${index}:${variant.name}`}\n sx={{ border: 1, borderColor: 'divider', borderRadius: 1, p: 1 }}\n >\n <Stack spacing={0.5}>\n <Typography variant=\"subtitle2\">\n {variant.name || `Variant ${index + 1}`}\n </Typography>\n {variant.subject ? (\n <Typography variant=\"body2\">{`Subject: ${variant.subject}`}</Typography>\n ) : null}\n {variant.preheader ? (\n <Typography variant=\"body2\">{`Preheader: ${variant.preheader}`}</Typography>\n ) : null}\n {variant.headline ? (\n <Typography variant=\"body2\">{variant.headline}</Typography>\n ) : null}\n {variant.body ? (\n <Typography\n variant=\"body2\"\n sx={{ whiteSpace: 'pre-line', wordBreak: 'break-word' }}\n >\n {variant.body}\n </Typography>\n ) : null}\n {variant.rationale ? (\n <Typography variant=\"caption\" color=\"text.secondary\">\n {variant.rationale}\n </Typography>\n ) : null}\n </Stack>\n </Box>\n ))}\n <Typography variant=\"caption\" color=\"text.secondary\">\n {aiExperimentApplyCopy(target)}\n </Typography>\n <Stack direction=\"row\" spacing={1}>\n <Button\n size=\"small\"\n variant=\"contained\"\n disabled={applied === run.job?.id}\n onClick={apply}\n >\n {'Put into the variants'}\n </Button>\n {target === 'email' ? null : (\n <Button\n size=\"small\"\n variant=\"outlined\"\n disabled={versioning || Boolean(versionsBlocked)}\n onClick={() => void makeVersions()}\n >\n {'Make draft versions'}\n </Button>\n )}\n {versioning ? <CircularProgress size={16} aria-label=\"Making draft versions\" /> : null}\n </Stack>\n {versionsBlocked && target !== 'email' ? (\n <Typography variant=\"caption\" color=\"text.secondary\">\n {versionsBlocked}\n </Typography>\n ) : null}\n {versionsNote ? (\n <Alert severity={versionsNote.ok ? 'success' : 'warning'}>{versionsNote.text}</Alert>\n ) : null}\n {applied === run.job?.id ? (\n <Alert severity=\"success\">\n {'In the variants above. Review them, then Save the experiment — or Cancel to leave it as it was.'}\n </Alert>\n ) : null}\n </Stack>\n ) : null}\n </Stack>\n </Box>\n )\n}\nAiExperimentVariantsCard.displayName = 'AiExperimentVariantsCard'\n\n/** One arm, drawn the same way whatever the figures say about it. */\nfunction ArmRow({\n arm,\n named,\n}: {\n arm: AiExperimentArm\n named: boolean\n}) {\n return (\n <TableRow>\n <TableCell>\n <Stack direction=\"row\" spacing={1} sx={{ alignItems: 'center' }}>\n <Typography variant=\"body2\">{arm.id}</Typography>\n {named ? <Chip size=\"small\" color=\"success\" label=\"Ahead\" /> : null}\n </Stack>\n </TableCell>\n <TableCell>{arm.exposures}</TableCell>\n <TableCell>{arm.conversions}</TableCell>\n <TableCell>{rateText(arm.rate)}</TableCell>\n <TableCell>{liftText(arm.lift)}</TableCell>\n <TableCell>{rateText(arm.confidence)}</TableCell>\n </TableRow>\n )\n}\n\n/**\n * The explanation, drawn to the verdict rather than to the numbers.\n *\n * The chip and the caveat come FIRST, above the prose: a reader who stops\n * after one line must stop on what the result settled, not on a sentence\n * about one variant. No row is marked unless the verdict names an arm, and\n * `aiExperimentArmIsNamed` is asked per row rather than `winnerId` compared\n * directly, so a stored winner beside an undecided verdict marks nothing.\n */\nexport function AiExperimentExplanation({\n explanation,\n}: {\n explanation: AiExperimentExplanationProposal\n}) {\n const display = aiExperimentVerdictDisplay(explanation.verdict)\n return (\n <Stack spacing={1} aria-label=\"What this result shows\">\n <Stack direction=\"row\" spacing={1} sx={{ alignItems: 'center' }}>\n <Chip size=\"small\" color={display.tone} label={display.status} />\n {display.namesAnArm ? (\n <Typography variant=\"caption\" color=\"text.secondary\">\n {`Called at ${explanation.threshold}% confidence.`}\n </Typography>\n ) : null}\n </Stack>\n {display.caveat ? (\n <Typography variant=\"body2\">{display.caveat}</Typography>\n ) : null}\n <Typography variant=\"body2\" sx={{ wordBreak: 'break-word' }}>\n {explanation.headline}\n </Typography>\n {explanation.points.map((point) => (\n <Typography key={point} variant=\"body2\" color=\"text.secondary\">\n {point}\n </Typography>\n ))}\n {explanation.arms.length ? (\n <ScrollTable size=\"small\" aria-label=\"The figures this reads\">\n <TableHead>\n <TableRow>\n <TableCell>{'Variant'}</TableCell>\n <TableCell>{'Shown'}</TableCell>\n <TableCell>{'Conversions'}</TableCell>\n <TableCell>{'Rate'}</TableCell>\n <TableCell>{'Lift'}</TableCell>\n <TableCell>{'Confidence'}</TableCell>\n </TableRow>\n </TableHead>\n <TableBody>\n {explanation.arms.map((arm) => (\n <ArmRow\n key={arm.id}\n arm={arm}\n named={aiExperimentArmIsNamed(explanation, arm.id)}\n />\n ))}\n </TableBody>\n </ScrollTable>\n ) : null}\n {explanation.next ? (\n <Typography variant=\"body2\">{explanation.next}</Typography>\n ) : null}\n </Stack>\n )\n}\nAiExperimentExplanation.displayName = 'AiExperimentExplanation'\n\n/**\n * \"Explain this result\", below one test's figures. It starts an `experiment`\n * job, which reads the same figures the dialog above it shows, decides what\n * they support in code, and asks a model only for the words.\n */\nexport function AiExperimentResultCard(props: AiExperimentResultCardProps) {\n const { hostId, test } = props\n const orgId = useHostOrgId(hostId) ?? undefined\n const { data: user } = useUser()\n const run = useAiJobRun(user, EXPLAIN_FAILED_COPY)\n const explanation = useMemo(\n () => readAiExperimentExplanation(proposalOf(run.job)),\n [run.job],\n )\n const problem =\n aiJobProblem(run.job, EXPLAIN_FAILED_COPY) ??\n (run.job?.status === 'done' && !explanation ? EXPLAIN_FAILED_COPY : null)\n\n\n const busy = run.starting || run.running\n const resultHelp = pluginDocsHelp('aiExperiments', {\n anchor: '#the-verdict',\n excerpt:\n 'What the figures support is worked out from the counts before a model is asked anything, and the explanation is held to it — so an undecided test reads as undecided and no variant is named.',\n })\n const explain = () => {\n if (!orgId || !test) return\n void run.start({\n orgId,\n hostId,\n kind: 'experiment',\n brief: `Explain the result of the A/B test “${test}” in plain words.`,\n inputs: {\n task: 'explain',\n test,\n ...(props.experimentId ? { experimentId: props.experimentId } : {}),\n },\n })\n }\n\n return (\n <Box\n sx={{ border: 1, borderColor: 'divider', borderRadius: 1, p: 1.5, mt: 2 }}\n aria-label=\"Explain this result with AI\"\n >\n <Stack spacing={1}>\n <Stack direction=\"row\" spacing={1} sx={{ alignItems: 'center' }}>\n <Typography variant=\"body2\" color=\"text.secondary\" sx={{ flexGrow: 1 }}>\n {'Read these figures in plain words, including whether they settle anything yet.'}\n </Typography>\n <Link\n href={resultHelp.href}\n target=\"_blank\"\n rel=\"noopener\"\n variant=\"caption\"\n title={resultHelp.excerpt}\n >\n {'How it works'}\n </Link>\n <Button\n size=\"small\"\n variant=\"outlined\"\n disabled={busy || !orgId || !test}\n onClick={explain}\n >\n {run.job && !busy ? 'Ask again' : 'Explain this result'}\n </Button>\n </Stack>\n {busy ? (\n <Stack direction=\"row\" spacing={1} sx={{ alignItems: 'center' }}>\n <CircularProgress size={16} aria-label=\"Reading the result\" />\n <Typography variant=\"body2\" color=\"text.secondary\">\n {'Reading the result.'}\n </Typography>\n </Stack>\n ) : null}\n {run.notice ? <Alert severity=\"warning\">{run.notice}</Alert> : null}\n {problem ? (\n <Alert severity={run.job?.status === 'failed' ? 'error' : 'warning'}>\n {problem}\n </Alert>\n ) : null}\n {explanation ? <AiExperimentExplanation explanation={explanation} /> : null}\n </Stack>\n </Box>\n )\n}\nAiExperimentResultCard.displayName = 'AiExperimentResultCard'\n"],"names":["pluginDocsHelp","authorizedFetch","ScrollTable","useHostOrgId","useUser","Alert","Box","Button","Chip","CircularProgress","Link","Stack","TableBody","TableCell","TableHead","TableRow","TextField","Typography","useEffect","useMemo","useState","AI_EXPERIMENT_SUBJECT_MAX_CHARS","aiExperimentArmIsNamed","aiExperimentVerdictDisplay","readAiExperimentExplanation","readAiExperimentVariants","aiJobProblem","useAiJobRun","VARIANTS_FAILED_COPY","EXPLAIN_FAILED_COPY","TARGET_NOUN","screen","section","email","proposalOf","job","status","outputs","find","output","resource","proposal","rateText","value","liftText","aiExperimentSubjectFrom","target","variants","control","subject","body","filter","Boolean","join","aiExperimentVariantDrafts","versions","Map","map","variant","index","proposed","versionId","undefined","get","id","name","aiExperimentApplyCopy","VERSIONS_FAILED_COPY","AiExperimentVariantsCard","props","run","hostId","proposeVariants","orgId","data","user","prefill","setSubject","applied","setApplied","versioning","setVersioning","versionsNote","setVersionsNote","typed","setTyped","problem","busy","starting","running","noun","variantsHelp","anchor","excerpt","write","trim","start","kind","brief","inputs","task","slice","goal","experimentId","apply","screenId","nodeId","versionsBlocked","makeVersions","jobId","answer","response","method","headers","JSON","stringify","json","catch","ok","text","error","made","entry","names","skipped","length","reason","sx","border","borderColor","borderRadius","p","aria-label","spacing","direction","alignItems","flexGrow","href","rel","title","size","multiline","minRows","label","placeholder","helperText","onChange","event","disabled","onClick","notice","severity","color","preheader","headline","whiteSpace","wordBreak","rationale","displayName","ArmRow","arm","named","exposures","conversions","rate","lift","confidence","AiExperimentExplanation","explanation","display","verdict","tone","namesAnArm","threshold","caveat","points","point","arms","next","AiExperimentResultCard","test","resultHelp","explain","mt"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GACD;;;AAEA,SAASA,cAAc,QAAQ,mCAAkC;AACjE,SAASC,eAAe,QAAQ,2CAA0C;AAC1E,SAASC,WAAW,QAAQ,yDAAwD;AACpF,SAASC,YAAY,EAAEC,OAAO,QAAQ,iCAAgC;AACtE,SACEC,KAAK,EACLC,GAAG,EACHC,MAAM,EACNC,IAAI,EACJC,gBAAgB,EAChBC,IAAI,EACJC,KAAK,EACLC,SAAS,EACTC,SAAS,EACTC,SAAS,EACTC,QAAQ,EACRC,SAAS,EACTC,UAAU,QACL,gBAAe;AACtB,SAASC,SAAS,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,QAAO;AACpD,SACEC,+BAA+B,QAG1B,4BAAwB;AAC/B,SACEC,sBAAsB,EACtBC,0BAA0B,EAC1BC,2BAA2B,EAC3BC,wBAA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ACvDkD;qBAED;gBACHkF,4BAAc,KAACD;oBAAwBC,aAAaA;qBAAkB;;;;AAI/E;AACAW,uBAAuBrB,WAAW,GAAG"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/components/ai-experiment-cards.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 { pluginDocsHelp } from '@aglyn/aglyn/app-utils/docs-help'\nimport { authorizedFetch } from '@aglyn/shared-util-http/authorized-token'\nimport { ScrollTable } from '@aglyn/shared-ui-jsx/components/scroll-table.component'\nimport { useHostOrgId, useUser } from '@aglyn/tenant-feature-instance'\nimport {\n Alert,\n Box,\n Button,\n Chip,\n CircularProgress,\n Link,\n Stack,\n TableBody,\n TableCell,\n TableHead,\n TableRow,\n TextField,\n Typography,\n} from '@mui/material'\nimport { useEffect, useMemo, useState } from 'react'\nimport {\n AI_EXPERIMENT_SUBJECT_MAX_CHARS,\n type AiExperimentArm,\n type AiExperimentTarget,\n} from '../model/ai-experiment'\nimport {\n aiExperimentArmIsNamed,\n aiExperimentVerdictDisplay,\n readAiExperimentExplanation,\n readAiExperimentVariants,\n type AiExperimentExplanationProposal,\n type AiExperimentVariantsProposalView,\n} from '../model/ai-experiment-proposal'\nimport type { AiJobSummary } from '../model/ai-jobs.types'\nimport { aiJobProblem, useAiJobRun } from './use-ai-job-run'\n\n/**\n * A/B tests by AI in the console (AGL-2914): the two doors a person reaches\n * the `experiment` job through, and the surfaces that render what it answers.\n *\n * Both are widgets in zones the A/B TESTING card hosts, not surfaces of this\n * plugin's own. The test, the experiment document, the traffic split and the\n * counters belong to the plugin that draws that card, and neither plugin\n * imports the other: the zone's id and the props it hands a widget are the\n * whole contract, and the interfaces below restate the halves this widget\n * reads rather than importing the owner's.\n *\n * ## The result surface may not decide anything\n *\n * The step reached the verdict from the counts before a model was asked, and\n * cut the answer back to it. A card can undo all of that silently — a\n * confident heading, a highlighted row, a badge saying which to ship — and\n * the reader will take the layout for the claim. So {@link AiExperimentResultCard}\n * asks `aiExperimentVerdictDisplay` what the verdict permits before it draws\n * anything: an undecided result gets a neutral chip, a sentence saying it\n * settled nothing ABOVE the explanation, no marked arm and no recommendation.\n * Nothing on it is conditioned on which arm has the best rate.\n *\n * ## Neither card writes\n *\n * The variants card fills the experiment editor's own fields, unsaved, and\n * the dialog's Save is the write. The result card has nothing to apply.\n */\n\nconst VARIANTS_FAILED_COPY = 'Variants could not be written. Try again.'\nconst EXPLAIN_FAILED_COPY = 'The result could not be explained. Try again.'\n\n/** What the test varies, in the words this card's own copy uses. */\nconst TARGET_NOUN: Record<AiExperimentTarget, string> = {\n screen: 'page',\n section: 'section',\n email: 'email',\n}\n\n/** One of the experiment editor's variants, as the zone hands it over. */\nexport interface AiExperimentZoneVariant {\n id: string\n name: string\n subject: string\n body: string\n /** The screen version a page or section variant pins; empty for the published one. */\n versionId?: string\n}\n\n/** What the variants zone hands this widget. */\nexport interface AiExperimentVariantsCardProps {\n hostId: string\n experimentId: string\n name: string\n target: AiExperimentTarget\n goal: string\n /** A page or section test's page; empty until one is picked (AGL-3603). */\n screenId?: string\n /** A section test's element; empty until one is picked. */\n nodeId?: string\n variants: AiExperimentZoneVariant[]\n proposeVariants: (\n variants: readonly AiExperimentZoneVariant[],\n key: string,\n ) => void\n}\n\n/** What the result zone hands this widget. */\nexport interface AiExperimentResultCardProps {\n hostId: string\n experimentId: string\n test: string\n}\n\n/** The proposal a finished experiment job carries, whichever task it ran. */\nfunction proposalOf(job: AiJobSummary | null): Record<string, unknown> | null {\n if (job?.status !== 'done') return null\n return job.outputs.find((output) => output.resource === 'experiment')?.proposal ?? null\n}\n\nconst rateText = (value: number | null): string =>\n value === null ? '—' : `${value}%`\n\nconst liftText = (value: number | null): string =>\n value === null ? '—' : `${value >= 0 ? '+' : ''}${value}%`\n\n/**\n * The copy an email test varies, as the editor holds it: the FIRST variant's\n * subject and body, which is the control. A screen or a section varies a\n * screen version, which the editor does not hold, so there is nothing to\n * prefill and the person pastes what is under test.\n */\nexport function aiExperimentSubjectFrom(\n target: AiExperimentTarget,\n variants: readonly AiExperimentZoneVariant[],\n): string {\n if (target !== 'email') return ''\n const control = variants[0]\n if (!control) return ''\n return [control.subject, control.body].filter(Boolean).join('\\n\\n')\n}\n\n/**\n * A proposal mapped onto the editor's variants, in order. Only the fields\n * that target has a place for are filled: an email varies its subject and\n * body, and a screen or a section varies a screen version, so there only the\n * name is filled and the copy is read on the card.\n */\nexport function aiExperimentVariantDrafts(\n target: AiExperimentTarget,\n variants: readonly AiExperimentZoneVariant[],\n proposal: AiExperimentVariantsProposalView,\n /** Draft versions made for a page or section test (AGL-3603), by the proposal's index. */\n versions: ReadonlyMap<number, string> = new Map(),\n): AiExperimentZoneVariant[] {\n return variants.map((variant, index) => {\n const proposed = proposal.variants[index]\n if (!proposed) return variant\n const versionId = target === 'email' ? undefined : versions.get(index)\n return {\n id: variant.id,\n name: proposed.name,\n subject: target === 'email' ? proposed.subject : '',\n body: target === 'email' ? proposed.body : '',\n ...(versionId ? { versionId } : {}),\n }\n })\n}\n\n/** What the draft versions door answers. */\ninterface AiExperimentVersionsAnswer {\n versions?: Array<{ index: number; name: string; versionId: string }>\n skipped?: Array<{ index: number; reason: string }>\n error?: string\n}\n\n/** Where a proposed variant's copy lands, said before the person presses the button. */\nexport function aiExperimentApplyCopy(target: AiExperimentTarget): string {\n return target === 'email'\n ? 'Each variant above takes its name, subject and body. Nothing is saved until you save the experiment.'\n : 'Each variant above takes its name. Make draft versions to put each variant’s copy into a new unpublished version of the page, pinned to its variant; the first stays on the published page as the control.'\n}\n\nconst VERSIONS_FAILED_COPY = 'The draft versions could not be made. Try again.'\n\n/**\n * \"Write variants with AI\", in the experiment editor beneath the variants it\n * writes for. It proposes COPY: no weight, no traffic split, no goal and no\n * schedule, and the first variant it writes is the copy as it stands so the\n * test has something to measure against.\n */\nexport function AiExperimentVariantsCard(props: AiExperimentVariantsCardProps) {\n const { hostId, target, variants, proposeVariants } = props\n // The zone hands the SITE, which is what the card it is drawn in knows. The\n // organization is this widget's to resolve, as every AI widget in another\n // plugin's zone resolves it.\n const orgId = useHostOrgId(hostId) ?? undefined\n const { data: user } = useUser()\n const run = useAiJobRun(user, VARIANTS_FAILED_COPY)\n const prefill = useMemo(\n () => aiExperimentSubjectFrom(target, variants),\n [target, variants],\n )\n const [subject, setSubject] = useState(prefill)\n const [applied, setApplied] = useState<string | null>(null)\n const [versioning, setVersioning] = useState(false)\n const [versionsNote, setVersionsNote] = useState<{ ok: boolean; text: string } | null>(null)\n // The control's copy follows the editor until the person edits this field,\n // so switching a draft test from a page to an email fills it rather than\n // leaving the earlier target's copy under a question about a new one.\n const [typed, setTyped] = useState(false)\n useEffect(() => {\n if (!typed) setSubject(prefill)\n }, [prefill, typed])\n\n const proposal = useMemo(\n () => readAiExperimentVariants(proposalOf(run.job)),\n [run.job],\n )\n const problem =\n aiJobProblem(run.job, VARIANTS_FAILED_COPY) ??\n (run.job?.status === 'done' && !proposal ? VARIANTS_FAILED_COPY : null)\n\n\n const busy = run.starting || run.running\n const noun = TARGET_NOUN[target]\n const variantsHelp = pluginDocsHelp('aiExperiments', {\n anchor: '#write-variants',\n excerpt:\n 'Writes two to four variants of the copy under test, the first of them your copy unchanged. They go into the editor’s fields unsaved; nothing is saved until you save the experiment.',\n })\n const write = () => {\n if (!orgId || !subject.trim()) return\n setApplied(null)\n void run.start({\n orgId,\n hostId,\n kind: 'experiment',\n brief:\n `Write variants of this ${noun} for the A/B test ` +\n `“${props.name.trim() || 'this test'}”.`,\n inputs: {\n task: 'variants',\n target,\n subject: subject.trim().slice(0, AI_EXPERIMENT_SUBJECT_MAX_CHARS),\n goal: props.goal,\n ...(props.experimentId ? { experimentId: props.experimentId } : {}),\n },\n })\n }\n\n const apply = () => {\n if (!proposal || !run.job) return\n proposeVariants(\n aiExperimentVariantDrafts(target, variants, proposal),\n run.job.id,\n )\n setApplied(run.job.id)\n }\n\n /*\n * A page or a section varies a VERSION of the page (AGL-3603): the door\n * copies the published version once per variant past the control, puts\n * the variant's copy into it, and stores it unpublished; the versions are\n * then pinned to the variants here as unsaved edits.\n */\n const screenId = props.screenId ?? ''\n const nodeId = props.nodeId ?? ''\n const versionsBlocked =\n target === 'email'\n ? null\n : !screenId\n ? 'Pick the page under test above to make draft versions.'\n : target === 'section' && !nodeId\n ? 'Pick the section under test above to make draft versions.'\n : null\n const makeVersions = async () => {\n if (!proposal || !run.job || !orgId || versionsBlocked) return\n const jobId = run.job.id\n setVersioning(true)\n setVersionsNote(null)\n try {\n const response = await authorizedFetch(user, '/api/ai/experiments/versions', {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({ orgId, hostId, jobId, screenId, ...(nodeId ? { nodeId } : {}) }),\n })\n const answer = ((await response.json().catch(() => null)) ?? {}) as AiExperimentVersionsAnswer\n if (!response.ok) {\n setVersionsNote({ ok: false, text: answer.error || VERSIONS_FAILED_COPY })\n return\n }\n const made = new Map((answer.versions ?? []).map((entry) => [entry.index, entry.versionId]))\n proposeVariants(aiExperimentVariantDrafts(target, variants, proposal, made), jobId)\n setApplied(jobId)\n const names = (answer.versions ?? []).map((entry) => entry.name)\n const skipped = answer.skipped ?? []\n setVersionsNote({\n ok: names.length > 0,\n text: [\n names.length\n ? `Draft versions made and pinned above: ${names.join(', ')}. Open each in the editor to check it, then Save the experiment. Nothing is published.`\n : 'No draft version could be made.',\n ...skipped.map((entry) => `Variant ${entry.index + 1}: ${entry.reason}`),\n ].join(' '),\n })\n } catch {\n setVersionsNote({ ok: false, text: VERSIONS_FAILED_COPY })\n } finally {\n setVersioning(false)\n }\n }\n\n return (\n <Box\n sx={{ border: 1, borderColor: 'divider', borderRadius: 1, p: 1.5 }}\n aria-label=\"Write variants with AI\"\n >\n <Stack spacing={1}>\n <Stack direction=\"row\" spacing={1} sx={{ alignItems: 'baseline' }}>\n <Typography variant=\"subtitle2\" sx={{ flexGrow: 1 }}>\n {'Write variants with AI'}\n </Typography>\n <Link\n href={variantsHelp.href}\n target=\"_blank\"\n rel=\"noopener\"\n variant=\"caption\"\n title={variantsHelp.excerptText}\n >\n {'How it works'}\n </Link>\n </Stack>\n <TextField\n size=\"small\"\n multiline\n minRows={2}\n label={`The ${noun} copy under test`}\n placeholder={\n target === 'email'\n ? 'The subject line and message as they stand'\n : 'The headline and copy as they stand on the page'\n }\n helperText={\n 'Variants are written from this. The first one it writes is this copy unchanged, so the test has a control.'\n }\n value={subject}\n onChange={(event) => {\n setTyped(true)\n setSubject(event.target.value.slice(0, AI_EXPERIMENT_SUBJECT_MAX_CHARS))\n }}\n disabled={busy}\n />\n <Stack direction=\"row\" spacing={1} sx={{ alignItems: 'center' }}>\n <Button\n size=\"small\"\n variant=\"outlined\"\n disabled={busy || !orgId || !subject.trim()}\n onClick={write}\n >\n {run.job && !busy ? 'Write them again' : 'Write variants'}\n </Button>\n {busy ? <CircularProgress size={16} aria-label=\"Writing variants\" /> : null}\n </Stack>\n {run.notice ? <Alert severity=\"warning\">{run.notice}</Alert> : null}\n {problem ? (\n <Alert severity={run.job?.status === 'failed' ? 'error' : 'warning'}>\n {problem}\n </Alert>\n ) : null}\n\n {proposal ? (\n <Stack spacing={1} aria-label=\"Proposed variants\">\n {proposal.goal ? (\n <Typography variant=\"body2\" color=\"text.secondary\">\n {`Written to move: ${proposal.goal}`}\n </Typography>\n ) : null}\n {proposal.variants.map((variant, index) => (\n <Box\n key={`${index}:${variant.name}`}\n sx={{ border: 1, borderColor: 'divider', borderRadius: 1, p: 1 }}\n >\n <Stack spacing={0.5}>\n <Typography variant=\"subtitle2\">\n {variant.name || `Variant ${index + 1}`}\n </Typography>\n {variant.subject ? (\n <Typography variant=\"body2\">{`Subject: ${variant.subject}`}</Typography>\n ) : null}\n {variant.preheader ? (\n <Typography variant=\"body2\">{`Preheader: ${variant.preheader}`}</Typography>\n ) : null}\n {variant.headline ? (\n <Typography variant=\"body2\">{variant.headline}</Typography>\n ) : null}\n {variant.body ? (\n <Typography\n variant=\"body2\"\n sx={{ whiteSpace: 'pre-line', wordBreak: 'break-word' }}\n >\n {variant.body}\n </Typography>\n ) : null}\n {variant.rationale ? (\n <Typography variant=\"caption\" color=\"text.secondary\">\n {variant.rationale}\n </Typography>\n ) : null}\n </Stack>\n </Box>\n ))}\n <Typography variant=\"caption\" color=\"text.secondary\">\n {aiExperimentApplyCopy(target)}\n </Typography>\n <Stack direction=\"row\" spacing={1}>\n <Button\n size=\"small\"\n variant=\"contained\"\n disabled={applied === run.job?.id}\n onClick={apply}\n >\n {'Put into the variants'}\n </Button>\n {target === 'email' ? null : (\n <Button\n size=\"small\"\n variant=\"outlined\"\n disabled={versioning || Boolean(versionsBlocked)}\n onClick={() => void makeVersions()}\n >\n {'Make draft versions'}\n </Button>\n )}\n {versioning ? <CircularProgress size={16} aria-label=\"Making draft versions\" /> : null}\n </Stack>\n {versionsBlocked && target !== 'email' ? (\n <Typography variant=\"caption\" color=\"text.secondary\">\n {versionsBlocked}\n </Typography>\n ) : null}\n {versionsNote ? (\n <Alert severity={versionsNote.ok ? 'success' : 'warning'}>{versionsNote.text}</Alert>\n ) : null}\n {applied === run.job?.id ? (\n <Alert severity=\"success\">\n {'In the variants above. Review them, then Save the experiment — or Cancel to leave it as it was.'}\n </Alert>\n ) : null}\n </Stack>\n ) : null}\n </Stack>\n </Box>\n )\n}\nAiExperimentVariantsCard.displayName = 'AiExperimentVariantsCard'\n\n/** One arm, drawn the same way whatever the figures say about it. */\nfunction ArmRow({\n arm,\n named,\n}: {\n arm: AiExperimentArm\n named: boolean\n}) {\n return (\n <TableRow>\n <TableCell>\n <Stack direction=\"row\" spacing={1} sx={{ alignItems: 'center' }}>\n <Typography variant=\"body2\">{arm.id}</Typography>\n {named ? <Chip size=\"small\" color=\"success\" label=\"Ahead\" /> : null}\n </Stack>\n </TableCell>\n <TableCell>{arm.exposures}</TableCell>\n <TableCell>{arm.conversions}</TableCell>\n <TableCell>{rateText(arm.rate)}</TableCell>\n <TableCell>{liftText(arm.lift)}</TableCell>\n <TableCell>{rateText(arm.confidence)}</TableCell>\n </TableRow>\n )\n}\n\n/**\n * The explanation, drawn to the verdict rather than to the numbers.\n *\n * The chip and the caveat come FIRST, above the prose: a reader who stops\n * after one line must stop on what the result settled, not on a sentence\n * about one variant. No row is marked unless the verdict names an arm, and\n * `aiExperimentArmIsNamed` is asked per row rather than `winnerId` compared\n * directly, so a stored winner beside an undecided verdict marks nothing.\n */\nexport function AiExperimentExplanation({\n explanation,\n}: {\n explanation: AiExperimentExplanationProposal\n}) {\n const display = aiExperimentVerdictDisplay(explanation.verdict)\n return (\n <Stack spacing={1} aria-label=\"What this result shows\">\n <Stack direction=\"row\" spacing={1} sx={{ alignItems: 'center' }}>\n <Chip size=\"small\" color={display.tone} label={display.status} />\n {display.namesAnArm ? (\n <Typography variant=\"caption\" color=\"text.secondary\">\n {`Called at ${explanation.threshold}% confidence.`}\n </Typography>\n ) : null}\n </Stack>\n {display.caveat ? (\n <Typography variant=\"body2\">{display.caveat}</Typography>\n ) : null}\n <Typography variant=\"body2\" sx={{ wordBreak: 'break-word' }}>\n {explanation.headline}\n </Typography>\n {explanation.points.map((point) => (\n <Typography key={point} variant=\"body2\" color=\"text.secondary\">\n {point}\n </Typography>\n ))}\n {explanation.arms.length ? (\n <ScrollTable size=\"small\" aria-label=\"The figures this reads\">\n <TableHead>\n <TableRow>\n <TableCell>{'Variant'}</TableCell>\n <TableCell>{'Shown'}</TableCell>\n <TableCell>{'Conversions'}</TableCell>\n <TableCell>{'Rate'}</TableCell>\n <TableCell>{'Lift'}</TableCell>\n <TableCell>{'Confidence'}</TableCell>\n </TableRow>\n </TableHead>\n <TableBody>\n {explanation.arms.map((arm) => (\n <ArmRow\n key={arm.id}\n arm={arm}\n named={aiExperimentArmIsNamed(explanation, arm.id)}\n />\n ))}\n </TableBody>\n </ScrollTable>\n ) : null}\n {explanation.next ? (\n <Typography variant=\"body2\">{explanation.next}</Typography>\n ) : null}\n </Stack>\n )\n}\nAiExperimentExplanation.displayName = 'AiExperimentExplanation'\n\n/**\n * \"Explain this result\", below one test's figures. It starts an `experiment`\n * job, which reads the same figures the dialog above it shows, decides what\n * they support in code, and asks a model only for the words.\n */\nexport function AiExperimentResultCard(props: AiExperimentResultCardProps) {\n const { hostId, test } = props\n const orgId = useHostOrgId(hostId) ?? undefined\n const { data: user } = useUser()\n const run = useAiJobRun(user, EXPLAIN_FAILED_COPY)\n const explanation = useMemo(\n () => readAiExperimentExplanation(proposalOf(run.job)),\n [run.job],\n )\n const problem =\n aiJobProblem(run.job, EXPLAIN_FAILED_COPY) ??\n (run.job?.status === 'done' && !explanation ? EXPLAIN_FAILED_COPY : null)\n\n\n const busy = run.starting || run.running\n const resultHelp = pluginDocsHelp('aiExperiments', {\n anchor: '#the-verdict',\n excerpt:\n 'What the figures support is worked out from the counts before a model is asked anything, and the explanation is held to it — so an undecided test reads as undecided and no variant is named.',\n })\n const explain = () => {\n if (!orgId || !test) return\n void run.start({\n orgId,\n hostId,\n kind: 'experiment',\n brief: `Explain the result of the A/B test “${test}” in plain words.`,\n inputs: {\n task: 'explain',\n test,\n ...(props.experimentId ? { experimentId: props.experimentId } : {}),\n },\n })\n }\n\n return (\n <Box\n sx={{ border: 1, borderColor: 'divider', borderRadius: 1, p: 1.5, mt: 2 }}\n aria-label=\"Explain this result with AI\"\n >\n <Stack spacing={1}>\n <Stack direction=\"row\" spacing={1} sx={{ alignItems: 'center' }}>\n <Typography variant=\"body2\" color=\"text.secondary\" sx={{ flexGrow: 1 }}>\n {'Read these figures in plain words, including whether they settle anything yet.'}\n </Typography>\n <Link\n href={resultHelp.href}\n target=\"_blank\"\n rel=\"noopener\"\n variant=\"caption\"\n title={resultHelp.excerptText}\n >\n {'How it works'}\n </Link>\n <Button\n size=\"small\"\n variant=\"outlined\"\n disabled={busy || !orgId || !test}\n onClick={explain}\n >\n {run.job && !busy ? 'Ask again' : 'Explain this result'}\n </Button>\n </Stack>\n {busy ? (\n <Stack direction=\"row\" spacing={1} sx={{ alignItems: 'center' }}>\n <CircularProgress size={16} aria-label=\"Reading the result\" />\n <Typography variant=\"body2\" color=\"text.secondary\">\n {'Reading the result.'}\n </Typography>\n </Stack>\n ) : null}\n {run.notice ? <Alert severity=\"warning\">{run.notice}</Alert> : null}\n {problem ? (\n <Alert severity={run.job?.status === 'failed' ? 'error' : 'warning'}>\n {problem}\n </Alert>\n ) : null}\n {explanation ? <AiExperimentExplanation explanation={explanation} /> : null}\n </Stack>\n </Box>\n )\n}\nAiExperimentResultCard.displayName = 'AiExperimentResultCard'\n"],"names":["pluginDocsHelp","authorizedFetch","ScrollTable","useHostOrgId","useUser","Alert","Box","Button","Chip","CircularProgress","Link","Stack","TableBody","TableCell","TableHead","TableRow","TextField","Typography","useEffect","useMemo","useState","AI_EXPERIMENT_SUBJECT_MAX_CHARS","aiExperimentArmIsNamed","aiExperimentVerdictDisplay","readAiExperimentExplanation","readAiExperimentVariants","aiJobProblem","useAiJobRun","VARIANTS_FAILED_COPY","EXPLAIN_FAILED_COPY","TARGET_NOUN","screen","section","email","proposalOf","job","status","outputs","find","output","resource","proposal","rateText","value","liftText","aiExperimentSubjectFrom","target","variants","control","subject","body","filter","Boolean","join","aiExperimentVariantDrafts","versions","Map","map","variant","index","proposed","versionId","undefined","get","id","name","aiExperimentApplyCopy","VERSIONS_FAILED_COPY","AiExperimentVariantsCard","props","run","hostId","proposeVariants","orgId","data","user","prefill","setSubject","applied","setApplied","versioning","setVersioning","versionsNote","setVersionsNote","typed","setTyped","problem","busy","starting","running","noun","variantsHelp","anchor","excerpt","write","trim","start","kind","brief","inputs","task","slice","goal","experimentId","apply","screenId","nodeId","versionsBlocked","makeVersions","jobId","answer","response","method","headers","JSON","stringify","json","catch","ok","text","error","made","entry","names","skipped","length","reason","sx","border","borderColor","borderRadius","p","aria-label","spacing","direction","alignItems","flexGrow","href","rel","title","excerptText","size","multiline","minRows","label","placeholder","helperText","onChange","event","disabled","onClick","notice","severity","color","preheader","headline","whiteSpace","wordBreak","rationale","displayName","ArmRow","arm","named","exposures","conversions","rate","lift","confidence","AiExperimentExplanation","explanation","display","verdict","tone","namesAnArm","threshold","caveat","points","point","arms","next","AiExperimentResultCard","test","resultHelp","explain","mt"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GACD;;;AAEA,SAASA,cAAc,QAAQ,mCAAkC;AACjE,SAASC,eAAe,QAAQ,2CAA0C;AAC1E,SAASC,WAAW,QAAQ,yDAAwD;AACpF,SAASC,YAAY,EAAEC,OAAO,QAAQ,iCAAgC;AACtE,SACEC,KAAK,EACLC,GAAG,EACHC,MAAM,EACNC,IAAI,EACJC,gBAAgB,EAChBC,IAAI,EACJC,KAAK,EACLC,SAAS,EACTC,SAAS,EACTC,SAAS,EACTC,QAAQ,EACRC,SAAS,EACTC,UAAU,QACL,gBAAe;AACtB,SAASC,SAAS,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,QAAO;AACpD,SACEC,+BAA+B,QAG1B,4BAAwB;AAC/B,SACEC,sBAAsB,EACtBC,0BAA0B,EAC1BC,2BAA2B,EAC3BC,wBAAwB,QAGnB,qCAAiC;AAExC,SAASC,YAAY,EAAEC,WAAW,QAAQ,sBAAkB;AAE5D;;;;;;;;;;;;;;;;;;;;;;;;;;CA0BC,GAED,MAAMC,uBAAuB;AAC7B,MAAMC,sBAAsB;AAE5B,kEAAkE,GAClE,MAAMC,cAAkD;IACtDC,QAAQ;IACRC,SAAS;IACTC,OAAO;AACT;AAqCA,2EAA2E,GAC3E,SAASC,WAAWC,GAAwB;;QAEnCA;IADP,IAAIA,CAAAA,uBAA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W;kBAEX,cAAA,MAACzH;YAAM0H,SAAS;;8BACd,MAAC1H;oBAAM2H,WAAU;oBAAMD,SAAS;oBAAGN,IAAI;wBAAEQ,YAAY;oBAAS;;sCAC5D,KAACtH;4BAAWyC,SAAQ;4BAAQ+F,OAAM;4BAAiB1B,IAAI;gCAAES,UAAU;4BAAE;sCAClE;;sCAEH,KAAC9H;4BACC+H,MAAM6C,WAAW7C,IAAI;4BACrB3F,QAAO;4BACP4F,KAAI;4BACJhF,SAAQ;4BACRiF,OAAO2C,WAAW1C,WAAW;sCAE5B;;sCAEH,KAACrI;4BACCsI,MAAK;4BACLnF,SAAQ;4BACR2F,UAAU9D,QAAQ,CAACd,SAAS,CAAC4G;4BAC7B/B,SAASiC;sCAERjH,IAAInC,GAAG,IAAI,CAACoD,OAAO,cAAc;;;;gBAGrCA,qBACC,MAAC5E;oBAAM2H,WAAU;oBAAMD,SAAS;oBAAGN,IAAI;wBAAEQ,YAAY;oBAAS;;sCAC5D,KAAC9H;4BAAiBoI,MAAM;4BAAIT,cAAW;;sCACvC,KAACnH;4BAAWyC,SAAQ;4BAAQ+F,OAAM;sCAC/B;;;qBAGH;gBACHnF,IAAIiF,MAAM,iBAAG,KAAClJ;oBAAMmJ,UAAS;8BAAWlF,IAAIiF,MAAM;qBAAY;gBAC9DjE,wBACC,KAACjF;oBAAMmJ,UAAUlF,EAAAA,YAAAA,IAAInC,GAAG,qBAAPmC,UAASlC,MAAM,MAAK,WAAW,UAAU;8BACvDkD;qBAED;gBACHmF,4BAAc,KAACD;oBAAwBC,aAAaA;qBAAkB;;;;AAI/E;AACAW,uBAAuBrB,WAAW,GAAG"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/components/ai-explain-automation.component.tsx"],"sourcesContent":["'use client'\n\n/**\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 { pluginDocsHelp } from '@aglyn/aglyn/app-utils/docs-help'\nimport { useUser } from '@aglyn/tenant-feature-instance'\nimport {\n Alert,\n Box,\n Button,\n CircularProgress,\n Dialog,\n DialogActions,\n DialogContent,\n DialogTitle,\n Link,\n Stack,\n Typography,\n} from '@mui/material'\nimport { useState } from 'react'\nimport type { AiJobSummary } from '../model/ai-jobs.types'\nimport { aiJobProblem, useAiJobRun, type AiJobRun } from './use-ai-job-run'\nimport type {\n ConsoleAutomationEditorZoneProps,\n ConsoleAutomationRunZoneProps,\n} from './ai-automation-zones'\n\n/**\n * \"Explain it\" in the editor of a saved automation, and \"Why did this fail?\"\n * on a failed run in its run history (AGL-2919), through the\n * `automationEditor` and `automationRun` zones. Each starts a `workflow` job\n * that reads the automation as it is saved — and, for a run, what the run\n * history recorded — and answers in plain words. Nothing is changed.\n */\n\nexport const AI_AUTOMATION_EXPLAIN_COPY = {\n explain: {\n action: 'Explain it',\n intro: 'Get a plain-words account of what this automation does, and anything in it worth checking.',\n saved: 'It reads the automation as it is saved, not changes you have not saved yet.',\n running: 'Reading the automation. This can take a few minutes.',\n again: 'Explain it again',\n failed: 'The automation could not be explained. Try again.',\n brief: (name: string) => `Explain what “${name}” does, and anything in it worth checking.`,\n },\n diagnose: {\n action: 'Why did this fail?',\n title: 'Why this run failed',\n running: 'Reading the run and the automation. This can take a few minutes.',\n again: 'Ask again',\n failed: 'The run could not be explained. Try again.',\n brief: (name: string) => `Why did a run of “${name}” fail, and how can it be fixed?`,\n },\n} as const\n\n/** The explanation a finished job wrote. */\nfunction explanationOf(job: AiJobSummary | null): string | null {\n if (job?.status !== 'done') return null\n return job.outputs.find((output) => output.resource === 'text' && output.text)?.text ?? null\n}\n\n/** Progress, the explanation, or why there is none. */\nfunction Answer({ run, running, failed }: { run: AiJobRun; running: string; failed: string }) {\n const text = explanationOf(run.job)\n const problem =\n aiJobProblem(run.job, failed) ?? (run.job?.status === 'done' && !text ? failed : null)\n return (\n <>\n {run.running ? (\n <Stack direction=\"row\" spacing={1} sx={{ alignItems: 'center' }}>\n <CircularProgress size={16} aria-label=\"Explaining\" />\n <Typography variant=\"body2\" color=\"text.secondary\">\n {running}\n </Typography>\n </Stack>\n ) : null}\n {text ? (\n <Typography variant=\"body2\" component=\"div\" sx={{ whiteSpace: 'pre-line', wordBreak: 'break-word' }}>\n {text}\n </Typography>\n ) : null}\n {problem ? <Alert severity={run.job?.status === 'failed' ? 'error' : 'warning'}>{problem}</Alert> : null}\n {run.notice ? <Alert severity=\"warning\">{run.notice}</Alert> : null}\n </>\n )\n}\n\n/** \"Explain it\", at the top of the editor of a saved action or workflow. */\nexport function AiExplainAutomation({ hostId, orgId, target }: ConsoleAutomationEditorZoneProps) {\n const copy = AI_AUTOMATION_EXPLAIN_COPY.explain\n const help = pluginDocsHelp('aiAutomations', { anchor: '#explain' })\n const { data: user } = useUser()\n const run = useAiJobRun(user, copy.failed)\n\n const asked = Boolean(run.job || run.notice)\n const busy = run.starting || run.running\n\n const explain = () => {\n if (!orgId) return\n void run.start({\n orgId,\n hostId,\n kind: 'workflow',\n brief: copy.brief(target.name),\n inputs: { mode: 'explain', targetType: target.type, targetId: target.id },\n })\n }\n\n return (\n <Box sx={{ border: 1, borderColor: 'divider', borderRadius: 1, p: 1.5 }} aria-label=\"Explain this automation\">\n <Stack spacing={1}>\n <Stack direction=\"row\" spacing={1} sx={{ alignItems: 'center' }}>\n <Typography variant=\"body2\" color=\"text.secondary\" sx={{ flexGrow: 1 }}>\n {asked ? copy.saved : copy.intro}{' '}\n <Link href={help.href} target=\"_blank\" rel=\"noopener\" title={help.excerpt}>\n {'How it works'}\n </Link>\n </Typography>\n <Button size=\"small\" variant=\"outlined\" disabled={busy || !orgId} onClick={explain}>\n {asked && !busy ? copy.again : copy.action}\n </Button>\n </Stack>\n <Answer run={run} running={copy.running} failed={copy.failed} />\n </Stack>\n </Box>\n )\n}\n\n/** \"Why did this fail?\", on a failed run: the answer opens over the run history. */\nexport function AiExplainRunFailure({ hostId, orgId, target, runId }: ConsoleAutomationRunZoneProps) {\n const copy = AI_AUTOMATION_EXPLAIN_COPY.diagnose\n const { data: user } = useUser()\n const run = useAiJobRun(user, copy.failed)\n const [open, setOpen] = useState(false)\n\n const busy = run.starting || run.running\n\n const ask = () => {\n if (!orgId) return\n void run.start({\n orgId,\n hostId,\n kind: 'workflow',\n brief: copy.brief(target.name),\n inputs: { mode: 'diagnose', targetType: target.type, targetId: target.id, runId },\n })\n }\n\n const openAndAsk = () => {\n setOpen(true)\n // A run already explained, or being explained, is shown again rather than asked again.\n if (!run.job) ask()\n }\n\n const close = () => {\n setOpen(false)\n // A refusal is not kept: asking again later should ask the route again.\n if (run.notice) run.reset()\n }\n\n return (\n <>\n <Button size=\"small\" variant=\"text\" sx={{ px: 0.5, minWidth: 0 }} onClick={openAndAsk}>\n {copy.action}\n </Button>\n <Dialog open={open} onClose={close} fullWidth maxWidth=\"sm\">\n <DialogTitle>{copy.title}</DialogTitle>\n <DialogContent>\n <Stack spacing={1.5} sx={{ pt: 1 }}>\n <Answer run={run} running={copy.running} failed={copy.failed} />\n </Stack>\n </DialogContent>\n <DialogActions>\n <Button onClick={close}>{'Close'}</Button>\n {!busy && (run.notice || aiJobProblem(run.job, copy.failed)) ? (\n <Button variant=\"outlined\" onClick={ask} disabled={!orgId}>\n {copy.again}\n </Button>\n ) : null}\n </DialogActions>\n </Dialog>\n </>\n )\n}\n"],"names":["pluginDocsHelp","useUser","Alert","Box","Button","CircularProgress","Dialog","DialogActions","DialogContent","DialogTitle","Link","Stack","Typography","useState","aiJobProblem","useAiJobRun","AI_AUTOMATION_EXPLAIN_COPY","explain","action","intro","saved","running","again","failed","brief","name","diagnose","title","explanationOf","job","status","outputs","find","output","resource","text","Answer","run","problem","direction","spacing","sx","alignItems","size","aria-label","variant","color","component","whiteSpace","wordBreak","severity","notice","AiExplainAutomation","hostId","orgId","target","copy","help","anchor","data","user","asked","Boolean","busy","starting","start","kind","inputs","mode","targetType","type","targetId","id","border","borderColor","borderRadius","p","flexGrow","href","rel","excerpt","disabled","onClick","AiExplainRunFailure","runId","open","setOpen","ask","openAndAsk","close","reset","px","minWidth","onClose","fullWidth","maxWidth","pt"],"mappings":"AAAA;;AAEA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,cAAc,QAAQ,mCAAkC;AACjE,SAASC,OAAO,QAAQ,iCAAgC;AACxD,SACEC,KAAK,EACLC,GAAG,EACHC,MAAM,EACNC,gBAAgB,EAChBC,MAAM,EACNC,aAAa,EACbC,aAAa,EACbC,WAAW,EACXC,IAAI,EACJC,KAAK,EACLC,UAAU,QACL,gBAAe;AACtB,SAASC,QAAQ,QAAQ,QAAO;AAEhC,SAASC,YAAY,EAAEC,WAAW,QAAuB,sBAAkB;AAM3E;;;;;;CAMC,GAED,OAAO,MAAMC,6BAA6B;IACxCC,SAAS;QACPC,QAAQ;QACRC,OAAO;QACPC,OAAO;QACPC,SAAS;QACTC,OAAO;QACPC,QAAQ;QACRC,OAAO,CAACC,OAAiB,CAAC,cAAc,EAAEA,KAAK,0CAA0C,CAAC;IAC5F;IACAC,UAAU;QACRR,QAAQ;QACRS,OAAO;QACPN,SAAS;QACTC,OAAO;QACPC,QAAQ;QACRC,OAAO,CAACC,OAAiB,CAAC,kBAAkB,EAAEA,KAAK,gCAAgC,CAAC;IACtF;AACF,EAAU;AAEV,0CAA0C,GAC1C,SAASG,cAAcC,GAAwB;;QAEtCA;IADP,IAAIA,CAAAA,uBAAAA,IAAKC,MAAM,MAAK,QAAQ,OAAO;IACnC,gBAAOD,oBAAAA,IAAIE,OAAO,CAACC,IAAI,CAAC,CAACC,SAAWA,OAAOC,QAAQ,KAAK,UAAUD,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O;0CAAQ;;4BACxB,CAAC1B,QAAS1B,CAAAA,IAAIc,MAAM,IAAIrC,aAAauB,IAAIR,GAAG,EAAE2B,KAAKjC,MAAM,CAAA,kBACxD,KAACnB;gCAAOyC,SAAQ;gCAAWqC,SAASK;gCAAKN,UAAU,CAAC3B;0CACjDE,KAAKlC,KAAK;iCAEX;;;;;;;AAKd"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/components/ai-explain-automation.component.tsx"],"sourcesContent":["'use client'\n\n/**\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 { pluginDocsHelp } from '@aglyn/aglyn/app-utils/docs-help'\nimport { useUser } from '@aglyn/tenant-feature-instance'\nimport {\n Alert,\n Box,\n Button,\n CircularProgress,\n Dialog,\n DialogActions,\n DialogContent,\n DialogTitle,\n Link,\n Stack,\n Typography,\n} from '@mui/material'\nimport { useState } from 'react'\nimport type { AiJobSummary } from '../model/ai-jobs.types'\nimport { aiJobProblem, useAiJobRun, type AiJobRun } from './use-ai-job-run'\nimport type {\n ConsoleAutomationEditorZoneProps,\n ConsoleAutomationRunZoneProps,\n} from './ai-automation-zones'\n\n/**\n * \"Explain it\" in the editor of a saved automation, and \"Why did this fail?\"\n * on a failed run in its run history (AGL-2919), through the\n * `automationEditor` and `automationRun` zones. Each starts a `workflow` job\n * that reads the automation as it is saved — and, for a run, what the run\n * history recorded — and answers in plain words. Nothing is changed.\n */\n\nexport const AI_AUTOMATION_EXPLAIN_COPY = {\n explain: {\n action: 'Explain it',\n intro: 'Get a plain-words account of what this automation does, and anything in it worth checking.',\n saved: 'It reads the automation as it is saved, not changes you have not saved yet.',\n running: 'Reading the automation. This can take a few minutes.',\n again: 'Explain it again',\n failed: 'The automation could not be explained. Try again.',\n brief: (name: string) => `Explain what “${name}” does, and anything in it worth checking.`,\n },\n diagnose: {\n action: 'Why did this fail?',\n title: 'Why this run failed',\n running: 'Reading the run and the automation. This can take a few minutes.',\n again: 'Ask again',\n failed: 'The run could not be explained. Try again.',\n brief: (name: string) => `Why did a run of “${name}” fail, and how can it be fixed?`,\n },\n} as const\n\n/** The explanation a finished job wrote. */\nfunction explanationOf(job: AiJobSummary | null): string | null {\n if (job?.status !== 'done') return null\n return job.outputs.find((output) => output.resource === 'text' && output.text)?.text ?? null\n}\n\n/** Progress, the explanation, or why there is none. */\nfunction Answer({ run, running, failed }: { run: AiJobRun; running: string; failed: string }) {\n const text = explanationOf(run.job)\n const problem =\n aiJobProblem(run.job, failed) ?? (run.job?.status === 'done' && !text ? failed : null)\n return (\n <>\n {run.running ? (\n <Stack direction=\"row\" spacing={1} sx={{ alignItems: 'center' }}>\n <CircularProgress size={16} aria-label=\"Explaining\" />\n <Typography variant=\"body2\" color=\"text.secondary\">\n {running}\n </Typography>\n </Stack>\n ) : null}\n {text ? (\n <Typography variant=\"body2\" component=\"div\" sx={{ whiteSpace: 'pre-line', wordBreak: 'break-word' }}>\n {text}\n </Typography>\n ) : null}\n {problem ? <Alert severity={run.job?.status === 'failed' ? 'error' : 'warning'}>{problem}</Alert> : null}\n {run.notice ? <Alert severity=\"warning\">{run.notice}</Alert> : null}\n </>\n )\n}\n\n/** \"Explain it\", at the top of the editor of a saved action or workflow. */\nexport function AiExplainAutomation({ hostId, orgId, target }: ConsoleAutomationEditorZoneProps) {\n const copy = AI_AUTOMATION_EXPLAIN_COPY.explain\n const help = pluginDocsHelp('aiAutomations', { anchor: '#explain' })\n const { data: user } = useUser()\n const run = useAiJobRun(user, copy.failed)\n\n const asked = Boolean(run.job || run.notice)\n const busy = run.starting || run.running\n\n const explain = () => {\n if (!orgId) return\n void run.start({\n orgId,\n hostId,\n kind: 'workflow',\n brief: copy.brief(target.name),\n inputs: { mode: 'explain', targetType: target.type, targetId: target.id },\n })\n }\n\n return (\n <Box sx={{ border: 1, borderColor: 'divider', borderRadius: 1, p: 1.5 }} aria-label=\"Explain this automation\">\n <Stack spacing={1}>\n <Stack direction=\"row\" spacing={1} sx={{ alignItems: 'center' }}>\n <Typography variant=\"body2\" color=\"text.secondary\" sx={{ flexGrow: 1 }}>\n {asked ? copy.saved : copy.intro}{' '}\n <Link href={help.href} target=\"_blank\" rel=\"noopener\" title={help.excerptText}>\n {'How it works'}\n </Link>\n </Typography>\n <Button size=\"small\" variant=\"outlined\" disabled={busy || !orgId} onClick={explain}>\n {asked && !busy ? copy.again : copy.action}\n </Button>\n </Stack>\n <Answer run={run} running={copy.running} failed={copy.failed} />\n </Stack>\n </Box>\n )\n}\n\n/** \"Why did this fail?\", on a failed run: the answer opens over the run history. */\nexport function AiExplainRunFailure({ hostId, orgId, target, runId }: ConsoleAutomationRunZoneProps) {\n const copy = AI_AUTOMATION_EXPLAIN_COPY.diagnose\n const { data: user } = useUser()\n const run = useAiJobRun(user, copy.failed)\n const [open, setOpen] = useState(false)\n\n const busy = run.starting || run.running\n\n const ask = () => {\n if (!orgId) return\n void run.start({\n orgId,\n hostId,\n kind: 'workflow',\n brief: copy.brief(target.name),\n inputs: { mode: 'diagnose', targetType: target.type, targetId: target.id, runId },\n })\n }\n\n const openAndAsk = () => {\n setOpen(true)\n // A run already explained, or being explained, is shown again rather than asked again.\n if (!run.job) ask()\n }\n\n const close = () => {\n setOpen(false)\n // A refusal is not kept: asking again later should ask the route again.\n if (run.notice) run.reset()\n }\n\n return (\n <>\n <Button size=\"small\" variant=\"text\" sx={{ px: 0.5, minWidth: 0 }} onClick={openAndAsk}>\n {copy.action}\n </Button>\n <Dialog open={open} onClose={close} fullWidth maxWidth=\"sm\">\n <DialogTitle>{copy.title}</DialogTitle>\n <DialogContent>\n <Stack spacing={1.5} sx={{ pt: 1 }}>\n <Answer run={run} running={copy.running} failed={copy.failed} />\n </Stack>\n </DialogContent>\n <DialogActions>\n <Button onClick={close}>{'Close'}</Button>\n {!busy && (run.notice || aiJobProblem(run.job, copy.failed)) ? (\n <Button variant=\"outlined\" onClick={ask} disabled={!orgId}>\n {copy.again}\n </Button>\n ) : null}\n </DialogActions>\n </Dialog>\n </>\n )\n}\n"],"names":["pluginDocsHelp","useUser","Alert","Box","Button","CircularProgress","Dialog","DialogActions","DialogContent","DialogTitle","Link","Stack","Typography","useState","aiJobProblem","useAiJobRun","AI_AUTOMATION_EXPLAIN_COPY","explain","action","intro","saved","running","again","failed","brief","name","diagnose","title","explanationOf","job","status","outputs","find","output","resource","text","Answer","run","problem","direction","spacing","sx","alignItems","size","aria-label","variant","color","component","whiteSpace","wordBreak","severity","notice","AiExplainAutomation","hostId","orgId","target","copy","help","anchor","data","user","asked","Boolean","busy","starting","start","kind","inputs","mode","targetType","type","targetId","id","border","borderColor","borderRadius","p","flexGrow","href","rel","excerptText","disabled","onClick","AiExplainRunFailure","runId","open","setOpen","ask","openAndAsk","close","reset","px","minWidth","onClose","fullWidth","maxWidth","pt"],"mappings":"AAAA;;AAEA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,cAAc,QAAQ,mCAAkC;AACjE,SAASC,OAAO,QAAQ,iCAAgC;AACxD,SACEC,KAAK,EACLC,GAAG,EACHC,MAAM,EACNC,gBAAgB,EAChBC,MAAM,EACNC,aAAa,EACbC,aAAa,EACbC,WAAW,EACXC,IAAI,EACJC,KAAK,EACLC,UAAU,QACL,gBAAe;AACtB,SAASC,QAAQ,QAAQ,QAAO;AAEhC,SAASC,YAAY,EAAEC,WAAW,QAAuB,sBAAkB;AAM3E;;;;;;CAMC,GAED,OAAO,MAAMC,6BAA6B;IACxCC,SAAS;QACPC,QAAQ;QACRC,OAAO;QACPC,OAAO;QACPC,SAAS;QACTC,OAAO;QACPC,QAAQ;QACRC,OAAO,CAACC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AEkD,IAAI;oBAAKC,UAAU;gBAAE;gBAAGV,SAASM;0BACxEhC,KAAKtC,MAAM;;0BAEd,MAACZ;gBAAO+E,MAAMA;gBAAMQ,SAASJ;gBAAOK,SAAS;gBAACC,UAAS;;kCACrD,KAACtF;kCAAa+C,KAAK7B,KAAK;;kCACxB,KAACnB;kCACC,cAAA,KAACG;4BAAM6B,SAAS;4BAAKC,IAAI;gCAAEuD,IAAI;4BAAE;sCAC/B,cAAA,KAAC5D;gCAAOC,KAAKA;gCAAKhB,SAASmC,KAAKnC,OAAO;gCAAEE,QAAQiC,KAAKjC,MAAM;;;;kCAGhE,MAAChB;;0CACC,KAACH;gCAAO8E,SAASO;0CAAQ;;4BACxB,CAAC1B,QAAS1B,CAAAA,IAAIc,MAAM,IAAIrC,aAAauB,IAAIR,GAAG,EAAE2B,KAAKjC,MAAM,CAAA,kBACxD,KAACnB;gCAAOyC,SAAQ;gCAAWqC,SAASK;gCAAKN,UAAU,CAAC3B;0CACjDE,KAAKlC,KAAK;iCAEX;;;;;;;AAKd"}
|
|
@@ -24,7 +24,9 @@ import { AiUpsellDialog } from "./ai-upsell-dialog.component.js";
|
|
|
24
24
|
action: 'Ask a question'
|
|
25
25
|
};
|
|
26
26
|
function InsightTile(props) {
|
|
27
|
-
const help = pluginDocsHelp('aiInsights'
|
|
27
|
+
const help = pluginDocsHelp('aiInsights', {
|
|
28
|
+
anchor: '#asking-a-question'
|
|
29
|
+
});
|
|
28
30
|
return /*#__PURE__*/ _jsx(CardDisplay, {
|
|
29
31
|
header: AI_INSIGHT_CARD_COPY.title,
|
|
30
32
|
help: help,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/components/ai-insight-card.component.tsx"],"sourcesContent":["'use client'\n\n/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { ConsoleWidgetEntitlementProps } from '@aglyn/aglyn/plugin-manager/feature-plugins'\nimport type { ConsolePluginOrgMount } from '@aglyn/aglyn'\nimport { pluginDocsHelp } from '@aglyn/aglyn/app-utils/docs-help'\nimport { mdiCreation } from '@aglyn/shared-data-mdi'\nimport { CardDisplay, MdiIcon } from '@aglyn/shared-ui-jsx'\nimport { useConsoleHostRoute, useHostOrgId, useUser } from '@aglyn/tenant-feature-instance'\nimport { Button, Stack, Typography } from '@mui/material'\nimport { useState } from 'react'\nimport { AiInsightDialog } from './ai-insight-dialog.component'\nimport { AiUpsellDialog } from './ai-upsell-dialog.component'\n\n/**\n * \"Ask AI about these numbers\" (AGL-3603): a tile on a site's dashboard and\n * Analytics page (`hostDashboard`, which both draw) and on the workspace's\n * sites page (`orgDashboard`), opening the insight dialog the Assist panel\n * opens. A question becomes an `insight` job — the figures read by code\n * through the readers the surface offers, every insight traced to the rows\n * it cites — charged as that job is. Drawn from the shell's gates alone\n * (AGL-3601): nothing asks a server until a question is asked, and on a plan\n * without the AI add-on the same tile opens the add-on's dialog.\n */\n\nexport const AI_INSIGHT_CARD_COPY = {\n title: 'Ask AI about these numbers',\n site: 'Ask a question about this site’s traffic, sales, bookings, automation runs and pipeline. Every answer shows the figures it is built from.',\n workspace: 'Ask a question about your workspace’s pipeline, the deals it closed and your datasets. Every answer shows the figures it is built from.',\n action: 'Ask a question',\n} as const\n\nfunction InsightTile(props: {\n text: string\n onAsk: () => void\n}) {\n const help = pluginDocsHelp('aiInsights')\n return (\n <CardDisplay header={AI_INSIGHT_CARD_COPY.title} help={help} contentGutterX contentGutterY>\n <Stack spacing={1.5} sx={{ alignItems: 'flex-start' }}>\n <Typography variant=\"body2\" color=\"text.secondary\">\n {props.text}\n </Typography>\n <Button\n size=\"small\"\n variant=\"outlined\"\n startIcon={<MdiIcon path={mdiCreation.path} />}\n onClick={props.onAsk}\n >\n {AI_INSIGHT_CARD_COPY.action}\n </Button>\n </Stack>\n </CardDisplay>\n )\n}\n\n/** The tile on a plan without the AI add-on: the same tile, opening the add-on's dialog. */\nfunction InsightUpsellTile({ text, upgrade }: { text: string; upgrade: ConsoleWidgetEntitlementProps['upgrade'] }) {\n const [open, setOpen] = useState(false)\n if (!upgrade) return null\n return (\n <>\n <InsightTile text={text} onAsk={() => setOpen(true)} />\n <AiUpsellDialog kind=\"insight\" open={open} onClose={() => setOpen(false)} upgrade={upgrade} />\n </>\n )\n}\n\n/** On a site's dashboard and its Analytics page. */\nexport function AiInsightHostCard({\n hostId,\n entitled,\n upgrade,\n}: { hostId: string } & ConsoleWidgetEntitlementProps) {\n const { data: user } = useUser()\n const orgId = useHostOrgId(hostId)\n const route = useConsoleHostRoute(hostId)\n const [open, setOpen] = useState(false)\n if (entitled === false) return <InsightUpsellTile text={AI_INSIGHT_CARD_COPY.site} upgrade={upgrade} />\n if (!orgId) return null\n return (\n <>\n <InsightTile text={AI_INSIGHT_CARD_COPY.site} onAsk={() => setOpen(true)} />\n {open ? (\n <AiInsightDialog\n open\n onClose={() => setOpen(false)}\n orgId={orgId}\n orgSlug={route.orgSlug ?? ''}\n hostId={hostId}\n host={route.subdomain}\n surface=\"analytics\"\n user={user}\n uid={(user as { uid?: string } | null | undefined)?.uid ?? null}\n />\n ) : null}\n </>\n )\n}\n\n/** On the workspace's sites page, totaling the organization rather than one site. */\nexport function AiInsightOrgCard({\n orgMount,\n entitled,\n upgrade,\n}: { orgMount?: ConsolePluginOrgMount | null } & ConsoleWidgetEntitlementProps) {\n const { data: user } = useUser()\n const orgId = orgMount?.orgId ?? null\n const [open, setOpen] = useState(false)\n if (entitled === false) return <InsightUpsellTile text={AI_INSIGHT_CARD_COPY.workspace} upgrade={upgrade} />\n if (!orgId) return null\n return (\n <>\n <InsightTile text={AI_INSIGHT_CARD_COPY.workspace} onAsk={() => setOpen(true)} />\n {open ? (\n <AiInsightDialog\n open\n onClose={() => setOpen(false)}\n orgId={orgId}\n orgSlug={orgMount?.orgSlug ?? ''}\n hostId={null}\n host={null}\n surface=\"workspace\"\n user={user}\n uid={(user as { uid?: string } | null | undefined)?.uid ?? null}\n />\n ) : null}\n </>\n )\n}\n"],"names":["pluginDocsHelp","mdiCreation","CardDisplay","MdiIcon","useConsoleHostRoute","useHostOrgId","useUser","Button","Stack","Typography","useState","AiInsightDialog","AiUpsellDialog","AI_INSIGHT_CARD_COPY","title","site","workspace","action","InsightTile","props","help","header","contentGutterX","contentGutterY","spacing","sx","alignItems","variant","color","text","size","startIcon","path","onClick","onAsk","InsightUpsellTile","upgrade","open","setOpen","kind","onClose","AiInsightHostCard","hostId","entitled","route","data","user","orgId","orgSlug","host","subdomain","surface","uid","AiInsightOrgCard","orgMount"],"mappings":"AAAA;;AAqBA,SAASA,cAAc,QAAQ,mCAAkC;AACjE,SAASC,WAAW,QAAQ,yBAAwB;AACpD,SAASC,WAAW,EAAEC,OAAO,QAAQ,uBAAsB;AAC3D,SAASC,mBAAmB,EAAEC,YAAY,EAAEC,OAAO,QAAQ,iCAAgC;AAC3F,SAASC,MAAM,EAAEC,KAAK,EAAEC,UAAU,QAAQ,gBAAe;AACzD,SAASC,QAAQ,QAAQ,QAAO;AAChC,SAASC,eAAe,QAAQ,mCAA+B;AAC/D,SAASC,cAAc,QAAQ,kCAA8B;AAE7D;;;;;;;;;CASC,GAED,OAAO,MAAMC,uBAAuB;IAClCC,OAAO;IACPC,MAAM;IACNC,WAAW;IACXC,QAAQ;AACV,EAAU;AAEV,SAASC,YAAYC,KAGpB;IACC,MAAMC,OAAOpB,eAAe;
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/components/ai-insight-card.component.tsx"],"sourcesContent":["'use client'\n\n/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { ConsoleWidgetEntitlementProps } from '@aglyn/aglyn/plugin-manager/feature-plugins'\nimport type { ConsolePluginOrgMount } from '@aglyn/aglyn'\nimport { pluginDocsHelp } from '@aglyn/aglyn/app-utils/docs-help'\nimport { mdiCreation } from '@aglyn/shared-data-mdi'\nimport { CardDisplay, MdiIcon } from '@aglyn/shared-ui-jsx'\nimport { useConsoleHostRoute, useHostOrgId, useUser } from '@aglyn/tenant-feature-instance'\nimport { Button, Stack, Typography } from '@mui/material'\nimport { useState } from 'react'\nimport { AiInsightDialog } from './ai-insight-dialog.component'\nimport { AiUpsellDialog } from './ai-upsell-dialog.component'\n\n/**\n * \"Ask AI about these numbers\" (AGL-3603): a tile on a site's dashboard and\n * Analytics page (`hostDashboard`, which both draw) and on the workspace's\n * sites page (`orgDashboard`), opening the insight dialog the Assist panel\n * opens. A question becomes an `insight` job — the figures read by code\n * through the readers the surface offers, every insight traced to the rows\n * it cites — charged as that job is. Drawn from the shell's gates alone\n * (AGL-3601): nothing asks a server until a question is asked, and on a plan\n * without the AI add-on the same tile opens the add-on's dialog.\n */\n\nexport const AI_INSIGHT_CARD_COPY = {\n title: 'Ask AI about these numbers',\n site: 'Ask a question about this site’s traffic, sales, bookings, automation runs and pipeline. Every answer shows the figures it is built from.',\n workspace: 'Ask a question about your workspace’s pipeline, the deals it closed and your datasets. Every answer shows the figures it is built from.',\n action: 'Ask a question',\n} as const\n\nfunction InsightTile(props: {\n text: string\n onAsk: () => void\n}) {\n const help = pluginDocsHelp('aiInsights', { anchor: '#asking-a-question' })\n return (\n <CardDisplay header={AI_INSIGHT_CARD_COPY.title} help={help} contentGutterX contentGutterY>\n <Stack spacing={1.5} sx={{ alignItems: 'flex-start' }}>\n <Typography variant=\"body2\" color=\"text.secondary\">\n {props.text}\n </Typography>\n <Button\n size=\"small\"\n variant=\"outlined\"\n startIcon={<MdiIcon path={mdiCreation.path} />}\n onClick={props.onAsk}\n >\n {AI_INSIGHT_CARD_COPY.action}\n </Button>\n </Stack>\n </CardDisplay>\n )\n}\n\n/** The tile on a plan without the AI add-on: the same tile, opening the add-on's dialog. */\nfunction InsightUpsellTile({ text, upgrade }: { text: string; upgrade: ConsoleWidgetEntitlementProps['upgrade'] }) {\n const [open, setOpen] = useState(false)\n if (!upgrade) return null\n return (\n <>\n <InsightTile text={text} onAsk={() => setOpen(true)} />\n <AiUpsellDialog kind=\"insight\" open={open} onClose={() => setOpen(false)} upgrade={upgrade} />\n </>\n )\n}\n\n/** On a site's dashboard and its Analytics page. */\nexport function AiInsightHostCard({\n hostId,\n entitled,\n upgrade,\n}: { hostId: string } & ConsoleWidgetEntitlementProps) {\n const { data: user } = useUser()\n const orgId = useHostOrgId(hostId)\n const route = useConsoleHostRoute(hostId)\n const [open, setOpen] = useState(false)\n if (entitled === false) return <InsightUpsellTile text={AI_INSIGHT_CARD_COPY.site} upgrade={upgrade} />\n if (!orgId) return null\n return (\n <>\n <InsightTile text={AI_INSIGHT_CARD_COPY.site} onAsk={() => setOpen(true)} />\n {open ? (\n <AiInsightDialog\n open\n onClose={() => setOpen(false)}\n orgId={orgId}\n orgSlug={route.orgSlug ?? ''}\n hostId={hostId}\n host={route.subdomain}\n surface=\"analytics\"\n user={user}\n uid={(user as { uid?: string } | null | undefined)?.uid ?? null}\n />\n ) : null}\n </>\n )\n}\n\n/** On the workspace's sites page, totaling the organization rather than one site. */\nexport function AiInsightOrgCard({\n orgMount,\n entitled,\n upgrade,\n}: { orgMount?: ConsolePluginOrgMount | null } & ConsoleWidgetEntitlementProps) {\n const { data: user } = useUser()\n const orgId = orgMount?.orgId ?? null\n const [open, setOpen] = useState(false)\n if (entitled === false) return <InsightUpsellTile text={AI_INSIGHT_CARD_COPY.workspace} upgrade={upgrade} />\n if (!orgId) return null\n return (\n <>\n <InsightTile text={AI_INSIGHT_CARD_COPY.workspace} onAsk={() => setOpen(true)} />\n {open ? (\n <AiInsightDialog\n open\n onClose={() => setOpen(false)}\n orgId={orgId}\n orgSlug={orgMount?.orgSlug ?? ''}\n hostId={null}\n host={null}\n surface=\"workspace\"\n user={user}\n uid={(user as { uid?: string } | null | undefined)?.uid ?? null}\n />\n ) : null}\n </>\n )\n}\n"],"names":["pluginDocsHelp","mdiCreation","CardDisplay","MdiIcon","useConsoleHostRoute","useHostOrgId","useUser","Button","Stack","Typography","useState","AiInsightDialog","AiUpsellDialog","AI_INSIGHT_CARD_COPY","title","site","workspace","action","InsightTile","props","help","anchor","header","contentGutterX","contentGutterY","spacing","sx","alignItems","variant","color","text","size","startIcon","path","onClick","onAsk","InsightUpsellTile","upgrade","open","setOpen","kind","onClose","AiInsightHostCard","hostId","entitled","route","data","user","orgId","orgSlug","host","subdomain","surface","uid","AiInsightOrgCard","orgMount"],"mappings":"AAAA;;AAqBA,SAASA,cAAc,QAAQ,mCAAkC;AACjE,SAASC,WAAW,QAAQ,yBAAwB;AACpD,SAASC,WAAW,EAAEC,OAAO,QAAQ,uBAAsB;AAC3D,SAASC,mBAAmB,EAAEC,YAAY,EAAEC,OAAO,QAAQ,iCAAgC;AAC3F,SAASC,MAAM,EAAEC,KAAK,EAAEC,UAAU,QAAQ,gBAAe;AACzD,SAASC,QAAQ,QAAQ,QAAO;AAChC,SAASC,eAAe,QAAQ,mCAA+B;AAC/D,SAASC,cAAc,QAAQ,kCAA8B;AAE7D;;;;;;;;;CASC,GAED,OAAO,MAAMC,uBAAuB;IAClCC,OAAO;IACPC,MAAM;IACNC,WAAW;IACXC,QAAQ;AACV,EAAU;AAEV,SAASC,YAAYC,KAGpB;IACC,MAAMC,OAAOpB,e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ACC,KAAC3B;gBACC2B,IAAI;gBACJG,SAAS,IAAMF,QAAQ;gBACvBS,OAAOA;gBACPC,OAAO,GAAEJ,iBAAAA,MAAMI,OAAO,YAAbJ,iBAAiB;gBAC1BF,QAAQA;gBACRO,MAAML,MAAMM,SAAS;gBACrBC,SAAQ;gBACRL,MAAMA;gBACNM,GAAG,UAAGN,wBAAD,AAACA,KAA8CM,GAAG,mBAAI;iBAE3D;;;AAGV;AAEA,mFAAmF,GACnF,OAAO,SAASC,iBAAiB,EAC/BC,QAAQ,EACRX,QAAQ,EACRP,OAAO,EACqE;;IAC5E,MAAM,EAAES,MAAMC,IAAI,EAAE,GAAGzC;IACvB,MAAM0C,gBAAQO,4BAAAA,SAAUP,KAAK,mBAAI;IACjC,MAAM,CAACV,MAAMC,QAAQ,GAAG7B,SAAS;IACjC,IAAIkC,aAAa,OAAO,qBAAO,KAACR;QAAkBN,MAAMjB,qBAAqBG,SAAS;QAAEqB,SAASA;;IACjG,IAAI,CAACW,OAAO,OAAO;IACnB,qBACE;;0BACE,KAAC9B;gBAAYY,MAAMjB,qBAAqBG,SAAS;gBAAEmB,OAAO,IAAMI,QAAQ;;YACvED,qBACC,KAAC3B;gBACC2B,IAAI;gBACJG,SAAS,IAAMF,QAAQ;gBACvBS,OAAOA;gBACPC,OAAO,WAAEM,4BAAAA,SAAUN,OAAO,oBAAI;gBAC9BN,QAAQ;gBACRO,MAAM;gBACNE,SAAQ;gBACRL,MAAMA;gBACNM,GAAG,WAAGN,wBAAD,AAACA,KAA8CM,GAAG,oBAAI;iBAE3D;;;AAGV"}
|
|
@@ -40,3 +40,9 @@ export declare function aiSiteBuildDoneLinks(job: Pick<AiJobSummary, 'outputs'>,
|
|
|
40
40
|
view: string | null;
|
|
41
41
|
pages: string | null;
|
|
42
42
|
};
|
|
43
|
+
/**
|
|
44
|
+
* Where a person gets more AI credits (AGL-3660): the workspace's Billing
|
|
45
|
+
* page at its plans, where an upgrade and the AI add-on are both sold — the
|
|
46
|
+
* door the AI credits meter's own upgrade link opens.
|
|
47
|
+
*/
|
|
48
|
+
export declare function aiCreditsBillingHref(orgSlug: string): string;
|
|
@@ -149,5 +149,14 @@ export { AI_SITE_BUILD_HREF };
|
|
|
149
149
|
})
|
|
150
150
|
};
|
|
151
151
|
}
|
|
152
|
+
/**
|
|
153
|
+
* Where a person gets more AI credits (AGL-3660): the workspace's Billing
|
|
154
|
+
* page at its plans, where an upgrade and the AI add-on are both sold — the
|
|
155
|
+
* door the AI credits meter's own upgrade link opens.
|
|
156
|
+
*/ export function aiCreditsBillingHref(orgSlug) {
|
|
157
|
+
return `${buildRoute(Route.MANAGE_BILLING, {
|
|
158
|
+
orgSlug
|
|
159
|
+
})}#plans`;
|
|
160
|
+
}
|
|
152
161
|
|
|
153
162
|
//# sourceMappingURL=ai-job-links.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/components/ai-job-links.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 */\nimport { buildRoute, Route } from '@aglyn/aglyn/app-utils/console-routes'\nimport {\n pluginRecordHref,\n pluginRecordListHref,\n} from '@aglyn/aglyn/plugin-manager/plugin-record-routes'\nimport { AI_JOB_BESIGNER_SEGMENT as BESIGNER_SEGMENT, AI_SITE_BUILD_HREF } from '../model/ai-job-notice'\nimport type { AiJobOutput, AiJobSummary } from '../model/ai-jobs.types'\n\n// Where a job's work opens in the console (AGL-2904), shared by the AI jobs\n// drawer and every dialog that follows the job it started (AGL-3593).\n\n/**\n * Where \"open draft\" goes, or `null` when the output has no page of its\n * own — a `text` output carries its copy on the job and is shown inline.\n * A versioned resource opens in the besigner on the version the job wrote;\n * one the console lists without a detail page opens its list; a `theme`\n * proposal opens the site's Theme section, where it is put in the editor.\n *\n * A console URL names a site by its SUBDOMAIN: the `[host]` segment resolves\n * through the member's host projection by subdomain, never by document id.\n * So an output that carries no `hostSubdomain` gets no link rather than one\n * that opens no site.\n */\nexport function aiJobOutputHref(output: AiJobOutput, orgSlug: string): string | null {\n const host = output.hostSubdomain\n if (!orgSlug || !host) return null\n const segment = BESIGNER_SEGMENT[output.resource]\n if (segment) {\n const base = `/${orgSlug}/hosts/${host}/${segment}/${output.id}`\n return output.versionId ? `${base}/versions/${output.versionId}/besigner` : base\n }\n if (output.resource === 'product') {\n // The catalog a drafted product lands in: the commerce plugin's address\n // for it (AGL-3080), or no link where commerce is not loaded.\n return pluginRecordListHref('product', { orgSlug, host })\n }\n if (output.resource === 'workflow') {\n // A drafted automation is an action (AGL-2919), listed switched off on\n // the workflows plugin's list of actions, or no link where it is not loaded.\n return pluginRecordListHref('action', { orgSlug, host })\n }\n if (output.resource === 'entry') {\n // A post a guided start wrote (AGL-3676) opens in its blog's list in Content.\n const collectionSlug = output.proposal?.['collectionSlug']\n return typeof collectionSlug === 'string' && collectionSlug\n ? buildRoute(Route.HOST_CONTENT_COLLECTION, { orgSlug, host, collectionSlug })\n : buildRoute(Route.HOST_CONTENT, { orgSlug, host })\n }\n if (output.resource === 'theme') {\n return buildRoute(Route.HOST_SETUP_THEME, { orgSlug, host })\n }\n if (output.resource === 'form') {\n // A new form has no version for the besigner to open: its own page — the\n // forms plugin's address for it — mints the first one, and holds the\n // routing and consent it declares.\n return pluginRecordHref('form', { orgSlug, host }, output.id)\n }\n if (output.resource === 'campaign') {\n // A campaign's page is the marketing plugin's, under the site: its\n // address for the campaign (AGL-3080), or no link where it is not loaded.\n return pluginRecordHref('campaign', { orgSlug, host }, output.id)\n }\n return null\n}\n\n/**\n * The ONE action a finished job's row, its notification and the dialog that\n * started it lead with (AGL-3593): what the job built. Several pages from one\n * job — a site's — open the site's Pages list, where they wait as drafts; one\n * output with a page of its own opens that page; anything else has no single\n * place to go, and the row's own links stand. `null` until the job is done.\n */\nexport function aiJobPrimaryLink(\n job: Pick<AiJobSummary, 'status' | 'outputs'>,\n orgSlug: string,\n): { href: string; label: string } | null {\n if (job.status !== 'done' || !orgSlug) return null\n const screens = job.outputs.filter(\n (output) => output.resource === 'screen' && output.hostSubdomain,\n )\n if (screens.length > 1) {\n return {\n href: buildRoute(Route.HOST_SCREENS, { orgSlug, host: String(screens[0].hostSubdomain) }),\n label: 'Open your draft pages',\n }\n }\n for (const output of job.outputs) {\n const href = aiJobOutputHref(output, orgSlug)\n if (href) {\n return {\n href,\n label: output.resource === 'screen' ? 'Open the draft page' : `Open ${output.label}`,\n }\n }\n }\n return null\n}\n\nexport { AI_SITE_BUILD_HREF }\n\n/**\n * The \"Building your site\" page for one site job (AGL-3594): linkable, so the\n * guided start lands on it, a reload keeps it and a notification opens it.\n * `null` without the org slug or the site's subdomain a console URL needs.\n */\nexport function aiSiteBuildHref(\n orgSlug: string | null | undefined,\n hostSubdomain: string | null | undefined,\n jobId: string,\n): string | null {\n if (!orgSlug || !hostSubdomain || !jobId) return null\n return `/${orgSlug}/hosts/${hostSubdomain}${AI_SITE_BUILD_HREF}/${encodeURIComponent(jobId)}`\n}\n\n/**\n * A finished site's two ways in (AGL-3594): its first page's draft, opened in\n * the console's preview of that version, and the Pages list every draft waits\n * in. Either is `null` where the job reported nothing to open.\n */\nexport function aiSiteBuildDoneLinks(\n job: Pick<AiJobSummary, 'outputs'>,\n orgSlug: string,\n): { view: string | null; pages: string | null } {\n const screens = job.outputs.filter((output) => output.resource === 'screen' && output.hostSubdomain)\n const first = screens[0]\n if (!first || !orgSlug) return { view: null, pages: null }\n const host = String(first.hostSubdomain)\n return {\n view: first.versionId\n ? `/${orgSlug}/hosts/${host}/screens/${first.id}/versions/${first.versionId}/view`\n : null,\n pages: buildRoute(Route.HOST_SCREENS, { orgSlug, host }),\n }\n}\n"],"names":["buildRoute","Route","pluginRecordHref","pluginRecordListHref","AI_JOB_BESIGNER_SEGMENT","BESIGNER_SEGMENT","AI_SITE_BUILD_HREF","aiJobOutputHref","output","orgSlug","host","hostSubdomain","segment","resource","base","id","versionId","collectionSlug","proposal","HOST_CONTENT_COLLECTION","HOST_CONTENT","HOST_SETUP_THEME","aiJobPrimaryLink","job","status","screens","outputs","filter","length","href","HOST_SCREENS","String","label","aiSiteBuildHref","jobId","encodeURIComponent","aiSiteBuildDoneLinks","first","view","pages"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GACD,SAASA,UAAU,EAAEC,KAAK,QAAQ,wCAAuC;AACzE,SACEC,gBAAgB,EAChBC,oBAAoB,QACf,mDAAkD;AACzD,SAASC,2BAA2BC,gBAAgB,EAAEC,kBAAkB,QAAQ,4BAAwB;AAGxG,4EAA4E;AAC5E,sEAAsE;AAEtE;;;;;;;;;;;CAWC,GACD,OAAO,SAASC,gBAAgBC,MAAmB,EAAEC,OAAe;IAClE,MAAMC,OAAOF,OAAOG,aAAa;IACjC,IAAI,CAACF,WAAW,CAACC,MAAM,OAAO;IAC9B,MAAME,UAAUP,gBAAgB,CAACG,OAAOK,QAAQ,CAAC;IACjD,IAAID,SAAS;QACX,MAAME,OAAO,CAAC,CAAC,EAAEL,QAAQ,OAAO,EAAEC,KAAK,CAAC,EAAEE,QAAQ,CAAC,EAAEJ,OAAOO,EAAE,EAAE;QAChE,OAAOP,OAAOQ,SAAS,GAAG,GAAGF,KAAK,UAAU,EAAEN,OAAOQ,SAAS,CAAC,SAAS,CAAC,GAAGF;IAC9E;IACA,IAAIN,OAAOK,QAAQ,KAAK,WAAW;QACjC,wEAAwE;QACxE,8DAA8D;QAC9D,OAAOV,qBAAqB,WAAW;YAAEM;YAASC;QAAK;IACzD;IACA,IAAIF,OAAOK,QAAQ,KAAK,YAAY;QAClC,uEAAuE;QACvE,6EAA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IG,OAAO,CAAE;QAChC,MAAMG,OAAOtB,gBAAgBC,QAAQC;QACrC,IAAIoB,MAAM;YACR,OAAO;gBACLA;gBACAG,OAAOxB,OAAOK,QAAQ,KAAK,WAAW,wBAAwB,CAAC,KAAK,EAAEL,OAAOwB,KAAK,EAAE;YACtF;QACF;IACF;IACA,OAAO;AACT;AAEA,SAAS1B,kBAAkB,GAAE;AAE7B;;;;CAIC,GACD,OAAO,SAAS2B,gBACdxB,OAAkC,EAClCE,aAAwC,EACxCuB,KAAa;IAEb,IAAI,CAACzB,WAAW,CAACE,iBAAiB,CAACuB,OAAO,OAAO;IACjD,OAAO,CAAC,CAAC,EAAEzB,QAAQ,OAAO,EAAEE,gBAAgBL,mBAAmB,CAAC,EAAE6B,mBAAmBD,QAAQ;AAC/F;AAEA;;;;CAIC,GACD,OAAO,SAASE,qBACdb,GAAkC,EAClCd,OAAe;IAEf,MAAMgB,UAAUF,IAAIG,OAAO,CAACC,MAAM,CAAC,CAACnB,SAAWA,OAAOK,QAAQ,KAAK,YAAYL,OAAOG,aAAa;IACnG,MAAM0B,QAAQZ,OAAO,CAAC,EAAE;IACxB,IAAI,CAACY,SAAS,CAAC5B,SAAS,OAAO;QAAE6B,MAAM;QAAMC,OAAO;IAAK;IACzD,MAAM7B,OAAOqB,OAAOM,MAAM1B,aAAa;IACvC,OAAO;QACL2B,MAAMD,MAAMrB,SAAS,GACjB,CAAC,CAAC,EAAEP,QAAQ,OAAO,EAAEC,KAAK,SAAS,EAAE2B,MAAMtB,EAAE,CAAC,UAAU,EAAEsB,MAAMrB,SAAS,CAAC,KAAK,CAAC,GAChF;QACJuB,OAAOvC,WAAWC,MAAM6B,YAAY,EAAE;YAAErB;YAASC;QAAK;IACxD;AACF"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/components/ai-job-links.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 */\nimport { buildRoute, Route } from '@aglyn/aglyn/app-utils/console-routes'\nimport {\n pluginRecordHref,\n pluginRecordListHref,\n} from '@aglyn/aglyn/plugin-manager/plugin-record-routes'\nimport { AI_JOB_BESIGNER_SEGMENT as BESIGNER_SEGMENT, AI_SITE_BUILD_HREF } from '../model/ai-job-notice'\nimport type { AiJobOutput, AiJobSummary } from '../model/ai-jobs.types'\n\n// Where a job's work opens in the console (AGL-2904), shared by the AI jobs\n// drawer and every dialog that follows the job it started (AGL-3593).\n\n/**\n * Where \"open draft\" goes, or `null` when the output has no page of its\n * own — a `text` output carries its copy on the job and is shown inline.\n * A versioned resource opens in the besigner on the version the job wrote;\n * one the console lists without a detail page opens its list; a `theme`\n * proposal opens the site's Theme section, where it is put in the editor.\n *\n * A console URL names a site by its SUBDOMAIN: the `[host]` segment resolves\n * through the member's host projection by subdomain, never by document id.\n * So an output that carries no `hostSubdomain` gets no link rather than one\n * that opens no site.\n */\nexport function aiJobOutputHref(output: AiJobOutput, orgSlug: string): string | null {\n const host = output.hostSubdomain\n if (!orgSlug || !host) return null\n const segment = BESIGNER_SEGMENT[output.resource]\n if (segment) {\n const base = `/${orgSlug}/hosts/${host}/${segment}/${output.id}`\n return output.versionId ? `${base}/versions/${output.versionId}/besigner` : base\n }\n if (output.resource === 'product') {\n // The catalog a drafted product lands in: the commerce plugin's address\n // for it (AGL-3080), or no link where commerce is not loaded.\n return pluginRecordListHref('product', { orgSlug, host })\n }\n if (output.resource === 'workflow') {\n // A drafted automation is an action (AGL-2919), listed switched off on\n // the workflows plugin's list of actions, or no link where it is not loaded.\n return pluginRecordListHref('action', { orgSlug, host })\n }\n if (output.resource === 'entry') {\n // A post a guided start wrote (AGL-3676) opens in its blog's list in Content.\n const collectionSlug = output.proposal?.['collectionSlug']\n return typeof collectionSlug === 'string' && collectionSlug\n ? buildRoute(Route.HOST_CONTENT_COLLECTION, { orgSlug, host, collectionSlug })\n : buildRoute(Route.HOST_CONTENT, { orgSlug, host })\n }\n if (output.resource === 'theme') {\n return buildRoute(Route.HOST_SETUP_THEME, { orgSlug, host })\n }\n if (output.resource === 'form') {\n // A new form has no version for the besigner to open: its own page — the\n // forms plugin's address for it — mints the first one, and holds the\n // routing and consent it declares.\n return pluginRecordHref('form', { orgSlug, host }, output.id)\n }\n if (output.resource === 'campaign') {\n // A campaign's page is the marketing plugin's, under the site: its\n // address for the campaign (AGL-3080), or no link where it is not loaded.\n return pluginRecordHref('campaign', { orgSlug, host }, output.id)\n }\n return null\n}\n\n/**\n * The ONE action a finished job's row, its notification and the dialog that\n * started it lead with (AGL-3593): what the job built. Several pages from one\n * job — a site's — open the site's Pages list, where they wait as drafts; one\n * output with a page of its own opens that page; anything else has no single\n * place to go, and the row's own links stand. `null` until the job is done.\n */\nexport function aiJobPrimaryLink(\n job: Pick<AiJobSummary, 'status' | 'outputs'>,\n orgSlug: string,\n): { href: string; label: string } | null {\n if (job.status !== 'done' || !orgSlug) return null\n const screens = job.outputs.filter(\n (output) => output.resource === 'screen' && output.hostSubdomain,\n )\n if (screens.length > 1) {\n return {\n href: buildRoute(Route.HOST_SCREENS, { orgSlug, host: String(screens[0].hostSubdomain) }),\n label: 'Open your draft pages',\n }\n }\n for (const output of job.outputs) {\n const href = aiJobOutputHref(output, orgSlug)\n if (href) {\n return {\n href,\n label: output.resource === 'screen' ? 'Open the draft page' : `Open ${output.label}`,\n }\n }\n }\n return null\n}\n\nexport { AI_SITE_BUILD_HREF }\n\n/**\n * The \"Building your site\" page for one site job (AGL-3594): linkable, so the\n * guided start lands on it, a reload keeps it and a notification opens it.\n * `null` without the org slug or the site's subdomain a console URL needs.\n */\nexport function aiSiteBuildHref(\n orgSlug: string | null | undefined,\n hostSubdomain: string | null | undefined,\n jobId: string,\n): string | null {\n if (!orgSlug || !hostSubdomain || !jobId) return null\n return `/${orgSlug}/hosts/${hostSubdomain}${AI_SITE_BUILD_HREF}/${encodeURIComponent(jobId)}`\n}\n\n/**\n * A finished site's two ways in (AGL-3594): its first page's draft, opened in\n * the console's preview of that version, and the Pages list every draft waits\n * in. Either is `null` where the job reported nothing to open.\n */\nexport function aiSiteBuildDoneLinks(\n job: Pick<AiJobSummary, 'outputs'>,\n orgSlug: string,\n): { view: string | null; pages: string | null } {\n const screens = job.outputs.filter((output) => output.resource === 'screen' && output.hostSubdomain)\n const first = screens[0]\n if (!first || !orgSlug) return { view: null, pages: null }\n const host = String(first.hostSubdomain)\n return {\n view: first.versionId\n ? `/${orgSlug}/hosts/${host}/screens/${first.id}/versions/${first.versionId}/view`\n : null,\n pages: buildRoute(Route.HOST_SCREENS, { orgSlug, host }),\n }\n}\n\n/**\n * Where a person gets more AI credits (AGL-3660): the workspace's Billing\n * page at its plans, where an upgrade and the AI add-on are both sold — the\n * door the AI credits meter's own upgrade link opens.\n */\nexport function aiCreditsBillingHref(orgSlug: string): string {\n return `${buildRoute(Route.MANAGE_BILLING, { orgSlug })}#plans`\n}\n"],"names":["buildRoute","Route","pluginRecordHref","pluginRecordListHref","AI_JOB_BESIGNER_SEGMENT","BESIGNER_SEGMENT","AI_SITE_BUILD_HREF","aiJobOutputHref","output","orgSlug","host","hostSubdomain","segment","resource","base","id","versionId","collectionSlug","proposal","HOST_CONTENT_COLLECTION","HOST_CONTENT","HOST_SETUP_THEME","aiJobPrimaryLink","job","status","screens","outputs","filter","length","href","HOST_SCREENS","String","label","aiSiteBuildHref","jobId","encodeURIComponent","aiSiteBuildDoneLinks","first","view","pages","aiCreditsBillingHref","MANAGE_BILLING"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GACD,SAASA,UAAU,EAAEC,KAAK,QAAQ,wCAAuC;AACzE,SACEC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AAmBD,QAAQ;AAC/F;AAEA;;;;CAIC,GACD,OAAO,SAASE,qBACdb,GAAkC,EAClCd,OAAe;IAEf,MAAMgB,UAAUF,IAAIG,OAAO,CAACC,MAAM,CAAC,CAACnB,SAAWA,OAAOK,QAAQ,KAAK,YAAYL,OAAOG,aAAa;IACnG,MAAM0B,QAAQZ,OAAO,CAAC,EAAE;IACxB,IAAI,CAACY,SAAS,CAAC5B,SAAS,OAAO;QAAE6B,MAAM;QAAMC,OAAO;IAAK;IACzD,MAAM7B,OAAOqB,OAAOM,MAAM1B,aAAa;IACvC,OAAO;QACL2B,MAAMD,MAAMrB,SAAS,GACjB,CAAC,CAAC,EAAEP,QAAQ,OAAO,EAAEC,KAAK,SAAS,EAAE2B,MAAMtB,EAAE,CAAC,UAAU,EAAEsB,MAAMrB,SAAS,CAAC,KAAK,CAAC,GAChF;QACJuB,OAAOvC,WAAWC,MAAM6B,YAAY,EAAE;YAAErB;YAASC;QAAK;IACxD;AACF;AAEA;;;;CAIC,GACD,OAAO,SAAS8B,qBAAqB/B,OAAe;IAClD,OAAO,GAAGT,WAAWC,MAAMwC,cAAc,EAAE;QAAEhC;IAAQ,GAAG,MAAM,CAAC;AACjE"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ConsolePluginPageProps } from '@aglyn/aglyn/plugin-manager/feature-plugins';
|
|
2
|
-
import type
|
|
2
|
+
import { type AiJobSummary } from '../model/ai-jobs.types';
|
|
3
3
|
/**
|
|
4
4
|
* A site's AI jobs (AGL-3596), at `/ai-jobs` under the site: every job that
|
|
5
5
|
* worked on this site, newest first, each linking to its own page.
|
|
@@ -19,5 +19,10 @@ export declare const AI_JOBS_LIST_TIMEOUT_MS = 20000;
|
|
|
19
19
|
export declare function aiJobNetCredits(job: Pick<AiJobSummary, 'creditsSpent' | 'refundedCredits'>): number;
|
|
20
20
|
/** The kind as a row names it: `Site`, `Page`, `AI job`. */
|
|
21
21
|
export declare function aiJobKindLabel(kind: AiJobSummary['kind']): string;
|
|
22
|
+
/**
|
|
23
|
+
* Every kind a row can name, in the kinds registry's order: the labels the
|
|
24
|
+
* rows' chips read, so the empty state never falls behind a new kind.
|
|
25
|
+
*/
|
|
26
|
+
export declare function aiJobKindLabels(): string[];
|
|
22
27
|
export declare function AiJobsListPage({ hostId, basePath }: ConsolePluginPageProps): import("react").JSX.Element;
|
|
23
28
|
export default AiJobsListPage;
|
|
@@ -23,6 +23,7 @@ import { useUser } from "@aglyn/tenant-feature-instance";
|
|
|
23
23
|
import { Alert, Box, Button, Card, Chip, CircularProgress, Container, List, ListItemButton, Stack, Typography } from "@mui/material";
|
|
24
24
|
import { useCallback, useEffect, useRef, useState } from "react";
|
|
25
25
|
import { AI_JOB_PHASE_LABELS, aiJobKindNoun, aiJobPhase } from "../model/ai-job-activity.js";
|
|
26
|
+
import { AI_JOB_KINDS } from "../model/ai-jobs.types.js";
|
|
26
27
|
import { publishAiJob } from "./ai-jobs-store.js";
|
|
27
28
|
import { useAiJobSite } from "./ai-job-site.js";
|
|
28
29
|
/**
|
|
@@ -60,6 +61,18 @@ const WHEN = new Intl.DateTimeFormat('en-US', {
|
|
|
60
61
|
const noun = aiJobKindNoun(kind);
|
|
61
62
|
return noun === 'AI job' ? noun : noun.charAt(0).toUpperCase() + noun.slice(1);
|
|
62
63
|
}
|
|
64
|
+
/**
|
|
65
|
+
* Every kind a row can name, in the kinds registry's order: the labels the
|
|
66
|
+
* rows' chips read, so the empty state never falls behind a new kind.
|
|
67
|
+
*/ export function aiJobKindLabels() {
|
|
68
|
+
const labels = AI_JOB_KINDS.map(aiJobKindLabel).filter((label)=>label !== 'AI job');
|
|
69
|
+
return [
|
|
70
|
+
...new Set(labels)
|
|
71
|
+
];
|
|
72
|
+
}
|
|
73
|
+
/** `A, B and C`. */ function listOf(items) {
|
|
74
|
+
return items.length < 2 ? items.join('') : `${items.slice(0, -1).join(', ')} and ${items[items.length - 1]}`;
|
|
75
|
+
}
|
|
63
76
|
const LOAD_ERROR = 'This site’s AI jobs could not be loaded. Try again in a moment.';
|
|
64
77
|
async function readSiteJobs(user, orgId, hostId, signal) {
|
|
65
78
|
try {
|
|
@@ -209,12 +222,12 @@ export function AiJobsListPage({ hostId, basePath }) {
|
|
|
209
222
|
/*#__PURE__*/ _jsx(Typography, {
|
|
210
223
|
variant: "body1",
|
|
211
224
|
color: "text.secondary",
|
|
212
|
-
children: `An AI job is ${PLATFORM_BRAND_NAME} AI
|
|
225
|
+
children: `An AI job is ${PLATFORM_BRAND_NAME} AI making something for this site from a short ` + `description you write. Each job is one of these kinds: ${listOf(aiJobKindLabels())}. ` + 'Each one gets a page here that shows its progress and what it made.'
|
|
213
226
|
}),
|
|
214
227
|
/*#__PURE__*/ _jsx(Typography, {
|
|
215
228
|
variant: "body1",
|
|
216
229
|
color: "text.secondary",
|
|
217
|
-
children: 'To start one, choose Create with AI on
|
|
230
|
+
children: 'To start one, choose Create with AI on any list that offers it, such as this site’s ' + 'Pages or Forms. A new site can also be built with AI when it is created.'
|
|
218
231
|
})
|
|
219
232
|
]
|
|
220
233
|
})
|