@aglyn/plugins-ai 1.0.0-beta.218 → 1.0.0-beta.220
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/README.md +2 -2
- package/package.json +18 -18
- package/src/index.d.ts +1 -0
- package/src/index.js.map +1 -1
- package/src/lib/activity/ai-activity-actions.js +8 -1
- package/src/lib/activity/ai-activity-actions.js.map +1 -1
- package/src/lib/billing/ai-month-meter.d.ts +51 -0
- package/src/lib/billing/ai-month-meter.js +89 -0
- package/src/lib/billing/ai-month-meter.js.map +1 -0
- package/src/lib/billing/ai-overage-close.d.ts +11 -33
- package/src/lib/billing/ai-overage-close.js +4 -3
- package/src/lib/billing/ai-overage-close.js.map +1 -1
- package/src/lib/billing/ai-overage-cutover.d.ts +28 -12
- package/src/lib/billing/ai-overage-cutover.js +1 -28
- package/src/lib/billing/ai-overage-cutover.js.map +1 -1
- package/src/lib/billing/ai-overage-ledger.js +1 -1
- package/src/lib/billing/ai-overage-ledger.js.map +1 -1
- package/src/lib/billing/ai-overage-standing.js +1 -1
- package/src/lib/billing/ai-overage-standing.js.map +1 -1
- package/src/lib/components/ai-allotment-editor.component.js +1 -1
- package/src/lib/components/ai-allotment-editor.component.js.map +1 -1
- package/src/lib/components/ai-assist-provider.component.js +5 -4
- package/src/lib/components/ai-assist-provider.component.js.map +1 -1
- package/src/lib/components/ai-automation-zones.d.ts +63 -0
- package/src/lib/components/ai-automation-zones.js +31 -0
- package/src/lib/components/ai-automation-zones.js.map +1 -0
- package/src/lib/components/ai-brief-dialog.component.js +3 -3
- package/src/lib/components/ai-brief-dialog.component.js.map +1 -1
- package/src/lib/components/ai-describe-automation.component.d.ts +1 -1
- package/src/lib/components/ai-describe-automation.component.js.map +1 -1
- package/src/lib/components/ai-describe-button.component.d.ts +6 -3
- package/src/lib/components/ai-describe-button.component.js +4 -1
- package/src/lib/components/ai-describe-button.component.js.map +1 -1
- package/src/lib/components/ai-experiment-cards.component.js +1 -1
- package/src/lib/components/ai-experiment-cards.component.js.map +1 -1
- package/src/lib/components/ai-explain-automation.component.d.ts +1 -1
- package/src/lib/components/ai-explain-automation.component.js.map +1 -1
- package/src/lib/components/ai-job-plan.component.d.ts +8 -0
- package/src/lib/components/ai-job-plan.component.js +21 -4
- package/src/lib/components/ai-job-plan.component.js.map +1 -1
- package/src/lib/components/ai-permissions-on-host.component.d.ts +12 -2
- package/src/lib/components/ai-permissions-on-host.component.js +12 -3
- package/src/lib/components/ai-permissions-on-host.component.js.map +1 -1
- package/src/lib/components/ai-product-copy-card.component.d.ts +1 -1
- package/src/lib/components/ai-product-copy-card.component.js.map +1 -1
- package/src/lib/components/ai-product-import-option.component.d.ts +1 -1
- package/src/lib/components/ai-product-import-option.component.js.map +1 -1
- package/src/lib/components/ai-product-zones.d.ts +124 -0
- package/src/lib/components/ai-product-zones.js +32 -0
- package/src/lib/components/ai-product-zones.js.map +1 -0
- package/src/lib/components/ai-products-hub-card.component.d.ts +1 -1
- package/src/lib/components/ai-products-hub-card.component.js.map +1 -1
- package/src/lib/components/ai-products-proposals.component.d.ts +1 -1
- package/src/lib/components/ai-products-proposals.component.js.map +1 -1
- package/src/lib/components/ai-seo-audit-card.component.js +35 -92
- package/src/lib/components/ai-seo-audit-card.component.js.map +1 -1
- package/src/lib/components/ai-seo-fields-card.component.js.map +1 -1
- package/src/lib/components/ai-theme-proposal-card.component.js.map +1 -1
- package/src/lib/components/assist-jobs-drawer.component.js +21 -15
- package/src/lib/components/assist-jobs-drawer.component.js.map +1 -1
- package/src/lib/components/assist-panel.component.js +2 -2
- package/src/lib/components/assist-panel.component.js.map +1 -1
- package/src/lib/components/assist-signals-page.component.js +2 -2
- package/src/lib/components/assist-signals-page.component.js.map +1 -1
- package/src/lib/components/billing-ai-allotments.component.js +1 -1
- package/src/lib/components/billing-ai-allotments.component.js.map +1 -1
- package/src/lib/components/billing-assist-overage-card.component.js +1 -1
- package/src/lib/components/billing-assist-overage-card.component.js.map +1 -1
- package/src/lib/constants.d.ts +5 -0
- package/src/lib/constants.js +4 -0
- package/src/lib/constants.js.map +1 -1
- package/src/lib/declarations.js +2 -0
- package/src/lib/declarations.js.map +1 -1
- package/src/lib/declarations.server.js +24 -10
- package/src/lib/declarations.server.js.map +1 -1
- package/src/lib/insights/ai-dataset-catalog.d.ts +49 -0
- package/src/lib/insights/ai-dataset-catalog.js +57 -0
- package/src/lib/insights/ai-dataset-catalog.js.map +1 -0
- package/src/lib/insights/ai-figure-readers.d.ts +6 -39
- package/src/lib/insights/ai-figure-readers.js +2 -391
- package/src/lib/insights/ai-figure-readers.js.map +1 -1
- package/src/lib/insights/ai-insight-digest.d.ts +10 -1
- package/src/lib/insights/ai-insight-digest.js +16 -4
- package/src/lib/insights/ai-insight-digest.js.map +1 -1
- package/src/lib/insights/ai-insight-readers.d.ts +1 -1
- package/src/lib/insights/ai-insight-readers.js.map +1 -1
- package/src/lib/jobs/ai-email-bindings.d.ts +28 -21
- package/src/lib/jobs/ai-email-bindings.js +75 -42
- package/src/lib/jobs/ai-email-bindings.js.map +1 -1
- package/src/lib/jobs/ai-job-campaign-step.d.ts +0 -2
- package/src/lib/jobs/ai-job-campaign-step.js +5 -10
- package/src/lib/jobs/ai-job-campaign-step.js.map +1 -1
- package/src/lib/jobs/ai-job-component-step.d.ts +6 -1
- package/src/lib/jobs/ai-job-component-step.js +32 -9
- package/src/lib/jobs/ai-job-component-step.js.map +1 -1
- package/src/lib/jobs/ai-job-draft-ids.js +11 -0
- package/src/lib/jobs/ai-job-draft-ids.js.map +1 -1
- package/src/lib/jobs/ai-job-drafts.js +1 -1
- package/src/lib/jobs/ai-job-drafts.js.map +1 -1
- package/src/lib/jobs/ai-job-email-step.d.ts +5 -3
- package/src/lib/jobs/ai-job-email-step.js +11 -4
- package/src/lib/jobs/ai-job-email-step.js.map +1 -1
- package/src/lib/jobs/ai-job-experiment-step.d.ts +1 -1
- package/src/lib/jobs/ai-job-experiment-step.js +1 -1
- package/src/lib/jobs/ai-job-experiment-step.js.map +1 -1
- package/src/lib/jobs/ai-job-form-step.d.ts +17 -1
- package/src/lib/jobs/ai-job-form-step.js +60 -8
- package/src/lib/jobs/ai-job-form-step.js.map +1 -1
- package/src/lib/jobs/ai-job-generation.d.ts +22 -1
- package/src/lib/jobs/ai-job-generation.js +63 -3
- package/src/lib/jobs/ai-job-generation.js.map +1 -1
- package/src/lib/jobs/ai-job-insight-step.js +1 -1
- package/src/lib/jobs/ai-job-insight-step.js.map +1 -1
- package/src/lib/jobs/ai-job-layout-step.d.ts +15 -4
- package/src/lib/jobs/ai-job-layout-step.js +46 -13
- package/src/lib/jobs/ai-job-layout-step.js.map +1 -1
- package/src/lib/jobs/ai-job-page-sections.d.ts +4 -2
- package/src/lib/jobs/ai-job-page-sections.js +7 -4
- package/src/lib/jobs/ai-job-page-sections.js.map +1 -1
- package/src/lib/jobs/ai-job-page-step.js +7 -2
- package/src/lib/jobs/ai-job-page-step.js.map +1 -1
- package/src/lib/jobs/ai-job-plan-conformance.d.ts +5 -0
- package/src/lib/jobs/ai-job-plan-conformance.js +40 -1
- package/src/lib/jobs/ai-job-plan-conformance.js.map +1 -1
- package/src/lib/jobs/ai-job-plan-creations.d.ts +80 -0
- package/src/lib/jobs/ai-job-plan-creations.js +199 -0
- package/src/lib/jobs/ai-job-plan-creations.js.map +1 -0
- package/src/lib/jobs/ai-job-plan-step.d.ts +11 -2
- package/src/lib/jobs/ai-job-plan-step.js +49 -23
- package/src/lib/jobs/ai-job-plan-step.js.map +1 -1
- package/src/lib/jobs/ai-job-plugin-drafts.d.ts +14 -6
- package/src/lib/jobs/ai-job-plugin-drafts.js +12 -4
- package/src/lib/jobs/ai-job-plugin-drafts.js.map +1 -1
- package/src/lib/jobs/ai-job-products-step.d.ts +7 -0
- package/src/lib/jobs/ai-job-products-step.js +54 -32
- package/src/lib/jobs/ai-job-products-step.js.map +1 -1
- package/src/lib/jobs/ai-job-seo-step.d.ts +3 -24
- package/src/lib/jobs/ai-job-seo-step.js +35 -108
- package/src/lib/jobs/ai-job-seo-step.js.map +1 -1
- package/src/lib/jobs/ai-job-site-step.d.ts +2 -0
- package/src/lib/jobs/ai-job-site-step.js +6 -6
- package/src/lib/jobs/ai-job-site-step.js.map +1 -1
- package/src/lib/jobs/ai-job-template-step.d.ts +9 -6
- package/src/lib/jobs/ai-job-template-step.js +73 -15
- package/src/lib/jobs/ai-job-template-step.js.map +1 -1
- package/src/lib/jobs/ai-job-theme-step.d.ts +1 -1
- package/src/lib/jobs/ai-job-theme-step.js +1 -1
- package/src/lib/jobs/ai-job-theme-step.js.map +1 -1
- package/src/lib/jobs/ai-job-workflow-step.js +17 -9
- package/src/lib/jobs/ai-job-workflow-step.js.map +1 -1
- package/src/lib/jobs/ai-jobs.js +1 -1
- package/src/lib/jobs/ai-jobs.js.map +1 -1
- package/src/lib/jobs/ai-workflow-records.d.ts +20 -11
- package/src/lib/jobs/ai-workflow-records.js +80 -43
- package/src/lib/jobs/ai-workflow-records.js.map +1 -1
- package/src/lib/model/ai-allotments.d.ts +27 -6
- package/src/lib/model/ai-allotments.js +54 -14
- package/src/lib/model/ai-allotments.js.map +1 -1
- package/src/lib/model/ai-automation-outline.d.ts +21 -2
- package/src/lib/model/ai-automation-outline.js.map +1 -1
- package/src/lib/model/ai-build-plan.d.ts +57 -0
- package/src/lib/model/ai-build-plan.js +116 -7
- package/src/lib/model/ai-build-plan.js.map +1 -1
- package/src/lib/model/ai-job-creations.d.ts +55 -0
- package/src/lib/model/ai-job-creations.js +85 -0
- package/src/lib/model/ai-job-creations.js.map +1 -0
- package/src/lib/model/ai-page-job.d.ts +3 -2
- package/src/lib/model/ai-page-job.js +4 -3
- package/src/lib/model/ai-page-job.js.map +1 -1
- package/src/lib/model/ai-seo.d.ts +11 -51
- package/src/lib/model/ai-seo.js +0 -17
- package/src/lib/model/ai-seo.js.map +1 -1
- package/src/lib/model/ai-site-inventory.js +1 -1
- package/src/lib/model/ai-site-inventory.js.map +1 -1
- package/src/lib/model/ai-site-job.d.ts +4 -2
- package/src/lib/model/ai-site-job.js +8 -4
- package/src/lib/model/ai-site-job.js.map +1 -1
- package/src/lib/model/ai-template-subjects.d.ts +10 -0
- package/src/lib/model/ai-template-subjects.js +16 -2
- package/src/lib/model/ai-template-subjects.js.map +1 -1
- package/src/lib/model/ai-theme-proposal.d.ts +1 -1
- package/src/lib/model/ai-theme-proposal.js +1 -1
- package/src/lib/model/ai-theme-proposal.js.map +1 -1
- package/src/lib/model/ai-tokens.js +1 -1
- package/src/lib/model/ai-tokens.js.map +1 -1
- package/src/lib/model/ai-usage-by-user.js +1 -1
- package/src/lib/model/ai-usage-by-user.js.map +1 -1
- package/src/lib/model/ai-workflow-job.d.ts +1 -3
- package/src/lib/model/ai-workflow-job.js +1 -2
- package/src/lib/model/ai-workflow-job.js.map +1 -1
- package/src/lib/plan-entitlements.d.ts +149 -0
- package/src/lib/plan-entitlements.js +168 -0
- package/src/lib/plan-entitlements.js.map +1 -0
- package/src/lib/plugin.js +1 -1
- package/src/lib/plugin.js.map +1 -1
- package/src/lib/providers/catalog.js +1 -1
- package/src/lib/providers/catalog.js.map +1 -1
- package/src/lib/providers/model-choice.js +1 -1
- package/src/lib/providers/model-choice.js.map +1 -1
- package/src/lib/runtime/ai-device-audit.d.ts +1 -1
- package/src/lib/runtime/ai-device-audit.js +1 -1
- package/src/lib/runtime/ai-device-audit.js.map +1 -1
- package/src/lib/runtime/ai-doctrine-validators.d.ts +25 -4
- package/src/lib/runtime/ai-doctrine-validators.js +178 -21
- package/src/lib/runtime/ai-doctrine-validators.js.map +1 -1
- package/src/lib/runtime/ai-doctrine.js +5 -5
- package/src/lib/runtime/ai-doctrine.js.map +1 -1
- package/src/lib/runtime/ai-eval-live.js +30 -15
- package/src/lib/runtime/ai-eval-live.js.map +1 -1
- package/src/lib/runtime/ai-eval.d.ts +9 -2
- package/src/lib/runtime/ai-eval.js +29 -2
- package/src/lib/runtime/ai-eval.js.map +1 -1
- package/src/lib/runtime/ai-gate.js +1 -1
- package/src/lib/runtime/ai-gate.js.map +1 -1
- package/src/lib/runtime/ai-node-tree.js +3 -3
- package/src/lib/runtime/ai-node-tree.js.map +1 -1
- package/src/lib/runtime/ai-palette.d.ts +7 -1
- package/src/lib/runtime/ai-palette.generated.d.ts +1 -1
- package/src/lib/runtime/ai-palette.generated.js +16 -13
- package/src/lib/runtime/ai-palette.generated.js.map +1 -1
- package/src/lib/runtime/ai-palette.js +7 -1
- package/src/lib/runtime/ai-palette.js.map +1 -1
- package/src/lib/runtime/seo-audit.d.ts +13 -63
- package/src/lib/runtime/seo-audit.js +22 -207
- package/src/lib/runtime/seo-audit.js.map +1 -1
- package/src/lib/runtime/site-inventory.js +29 -23
- package/src/lib/runtime/site-inventory.js.map +1 -1
- package/src/lib/server/ai-admin-org.js +1 -1
- package/src/lib/server/ai-admin-org.js.map +1 -1
- package/src/lib/server/ai-admin-orgs-spend.js +1 -1
- package/src/lib/server/ai-admin-orgs-spend.js.map +1 -1
- package/src/lib/server/ai-admin-signals.js +1 -1
- package/src/lib/server/ai-admin-signals.js.map +1 -1
- package/src/lib/server/ai-allotments.js +1 -1
- package/src/lib/server/ai-allotments.js.map +1 -1
- package/src/lib/server/ai-assist-prompts.js +3 -3
- package/src/lib/server/ai-assist-prompts.js.map +1 -1
- package/src/lib/server/ai-assist.js +2 -2
- package/src/lib/server/ai-assist.js.map +1 -1
- package/src/lib/server/assist-chat.d.ts +1 -1
- package/src/lib/server/assist-chat.js +13 -12
- package/src/lib/server/assist-chat.js.map +1 -1
- package/src/lib/server/assist-view-context.js +23 -23
- package/src/lib/server/assist-view-context.js.map +1 -1
- package/src/lib/server/billing-credits.d.ts +5 -0
- package/src/lib/server/billing-credits.js +8 -2
- package/src/lib/server/billing-credits.js.map +1 -1
- package/src/lib/server/billing-overage.js +2 -2
- package/src/lib/server/billing-overage.js.map +1 -1
- package/src/lib/server.d.ts +1 -0
- package/src/lib/server.js.map +1 -1
- package/src/lib/testing/stand-in-automation-index.d.ts +20 -0
- package/src/lib/testing/stand-in-automation-index.js +102 -0
- package/src/lib/testing/stand-in-automation-index.js.map +1 -0
- package/src/lib/testing/stand-in-dataset-index.d.ts +20 -0
- package/src/lib/testing/stand-in-dataset-index.js +80 -0
- package/src/lib/testing/stand-in-dataset-index.js.map +1 -0
- package/src/lib/testing/stand-in-list-send-time.d.ts +4 -0
- package/src/lib/testing/stand-in-list-send-time.js +77 -0
- package/src/lib/testing/stand-in-list-send-time.js.map +1 -0
- package/src/lib/testing/stand-in-pipeline-index.d.ts +32 -0
- package/src/lib/testing/stand-in-pipeline-index.js +59 -0
- package/src/lib/testing/stand-in-pipeline-index.js.map +1 -0
- package/src/lib/testing/stand-in-product-index.d.ts +20 -0
- package/src/lib/testing/stand-in-product-index.js +105 -0
- package/src/lib/testing/stand-in-product-index.js.map +1 -0
- package/src/lib/tools/ai-component-tool.js +2 -2
- package/src/lib/tools/ai-component-tool.js.map +1 -1
- package/src/lib/tools/ai-duplicate-resource-tool.js +1 -1
- package/src/lib/tools/ai-duplicate-resource-tool.js.map +1 -1
- package/src/lib/tools/ai-seo-tool.d.ts +6 -18
- package/src/lib/tools/ai-seo-tool.js +7 -38
- package/src/lib/tools/ai-seo-tool.js.map +1 -1
- package/src/lib/tools/ai-workflow-tool.d.ts +1 -1
- package/src/lib/tools/ai-workflow-tool.js +1 -1
- package/src/lib/tools/ai-workflow-tool.js.map +1 -1
- package/src/lib/usage/ai-allotment-alerts.d.ts +10 -7
- package/src/lib/usage/ai-allotment-alerts.js +39 -15
- package/src/lib/usage/ai-allotment-alerts.js.map +1 -1
- package/src/lib/usage/ai-quota-checks.d.ts +37 -0
- package/src/lib/usage/ai-quota-checks.js +69 -0
- package/src/lib/usage/ai-quota-checks.js.map +1 -0
- package/src/lib/usage/ai-usage-alerts.js +22 -10
- package/src/lib/usage/ai-usage-alerts.js.map +1 -1
- package/src/lib/usage/ai-usage-by-user.js +1 -1
- package/src/lib/usage/ai-usage-by-user.js.map +1 -1
- package/src/lib/usage/assist-ceiling.d.ts +2 -2
- package/src/lib/usage/assist-ceiling.js +4 -4
- package/src/lib/usage/assist-ceiling.js.map +1 -1
- package/src/lib/usage/assist-credits.d.ts +494 -0
- package/src/lib/usage/assist-credits.js +524 -0
- package/src/lib/usage/assist-credits.js.map +1 -0
- package/src/lib/usage/assist-free-taste.d.ts +1 -1
- package/src/lib/usage/assist-free-taste.js +3 -2
- package/src/lib/usage/assist-free-taste.js.map +1 -1
- package/src/lib/usage/assist-signal-mining.js +1 -1
- package/src/lib/usage/assist-signal-mining.js.map +1 -1
- package/src/lib/usage/assist-spend-guards.d.ts +153 -0
- package/src/lib/usage/assist-spend-guards.js +182 -0
- package/src/lib/usage/assist-spend-guards.js.map +1 -0
- package/src/lib/usage/assist-usage.d.ts +1 -1
- package/src/lib/usage/assist-usage.js +1 -1
- package/src/lib/usage/assist-usage.js.map +1 -1
- package/src/lib/usage/staff-org-ai.js +1 -1
- package/src/lib/usage/staff-org-ai.js.map +1 -1
- package/src/lib/usage-axes.d.ts +49 -0
- package/src/lib/usage-axes.js +108 -0
- package/src/lib/usage-axes.js.map +1 -0
- package/src/lib/runtime/seo-page-facts.d.ts +0 -61
- package/src/lib/runtime/seo-page-facts.js +0 -150
- package/src/lib/runtime/seo-page-facts.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/components/ai-products-hub-card.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 type { ConsoleProductsHubZoneProps } from '@aglyn/aglyn/plugin-manager/feature-plugins'\nimport { ListTable, type ListTableProps } from '@aglyn/shared-ui-jsx/components/list-table.component'\nimport {\n Alert,\n Box,\n Button,\n Chip,\n Dialog,\n DialogActions,\n DialogContent,\n DialogTitle,\n Link,\n Stack,\n TextField,\n Typography,\n} from '@mui/material'\nimport { useCallback, useEffect, useMemo, useRef, useState } from 'react'\nimport type { AiJobSummary } from '../model/ai-jobs.types'\nimport {\n AI_PRODUCTS_BULK_MAX,\n AI_PRODUCTS_IMPORT_WRITE_COPY,\n aiProductsBulkBrief,\n aiProductsBulkCount,\n aiProductsJobInputs,\n aiProductsProposalOfKind,\n} from '../model/ai-products'\nimport { AiBulkCopyReview, AiCatalogReview, AiCategoriesReview } from './ai-products-proposals.component'\nimport { useAiProductsJobs } from './use-ai-products-jobs'\n\n/**\n * Commerce by AI on the products hub (AGL-2916), through the `productsHub`\n * zone. Three things a person asks for, each a `products` job, and each\n * proposal reviewed in a table before anything is written:\n *\n * - **Write copy for products** — up to 50 saved products, picked from the\n * hub's rows; a job works through them a product at a time, and each row is\n * applied on its own or all at once.\n * - **Propose products** — a store's first products from a brief, created as\n * drafts with their prices empty and no photo, both marked for the person to\n * set.\n * - **Propose categories and discounts** — from a brief, created as the\n * catalog and discounts cards create them, every discount switched off.\n *\n * An import whose `productImport` option asked for it starts a copy job for\n * the products the import created, as they land. Every write is the hub's\n * (`ConsoleProductsHubZoneProps`); this card writes nothing itself.\n */\n\nconst BRIEF_MAX_CHARS = 4_000\n\n/** A column of the product picker, in the shared list table's own terms. */\ntype GridColDef = NonNullable<ListTableProps['columns']>[number]\n\ntype BriefKind = 'catalog' | 'categories'\n\n/** What each brief dialog says. */\nexport const AI_PRODUCTS_BRIEF_COPY: Readonly<\n Record<BriefKind, { title: string; label: string; placeholder: string; next: string; submit: string }>\n> = {\n catalog: {\n title: 'Propose products',\n label: 'What does the store sell?',\n placeholder: 'A candle studio in Asheville: hand-poured soy candles in 8 oz and 16 oz jars, and wax melts',\n next:\n 'You review up to twelve proposed products before any is created. Each is created as a draft with its ' +\n 'price left empty and no photo, and nothing is on your storefront until you price it and activate it.',\n submit: 'Propose products',\n },\n categories: {\n title: 'Propose categories and discounts',\n label: 'What should shoppers be able to browse, and what offers suit the store?',\n placeholder: 'A trail running shop: shoes, apparel and hydration packs, with a welcome offer for new runners',\n next:\n 'You review the proposed categories and discounts before any is created. Discounts are created switched ' +\n 'off, and a shopper sees none until you switch it on.',\n submit: 'Propose',\n },\n}\n\nconst nameKey = (name: string) => name.replace(/\\s+/g, ' ').trim().toLowerCase()\n\n/** Which card a `products` job belongs to: from what it proposed, or from what this card started. */\nfunction targetOf(job: AiJobSummary, started: Readonly<Record<string, string>>): string | null {\n if (started[job.id]) return started[job.id]\n if (aiProductsBulkCount(job) !== null) return 'bulk'\n if (aiProductsProposalOfKind(job, 'catalog')) return 'catalog'\n if (aiProductsProposalOfKind(job, 'categories')) return 'categories'\n return null\n}\n\nexport function AiProductsHubCard(props: ConsoleProductsHubZoneProps) {\n const { hostId, products, lastImport, applyProductCopy, createProductDrafts, createCategories, createDiscountDrafts } =\n props\n const { orgId, verdict, jobs, notice, start } = useAiProductsJobs({\n hostId,\n orgId: props.orgId,\n // A bulk job is known by its brief while it runs; a catalog or categories\n // job started elsewhere is shown once it has proposed.\n follows: (job) => aiProductsBulkCount(job) !== null,\n })\n const [started, setStarted] = useState<Record<string, string>>({})\n const [picking, setPicking] = useState(false)\n const [picked, setPicked] = useState<string[]>([])\n const [brief, setBrief] = useState<{ kind: BriefKind; text: string } | null>(null)\n const [busy, setBusy] = useState(false)\n const handledImports = useRef(new Set<string>())\n\n const startBulk = useCallback(\n async (productIds: readonly string[]) => {\n const ids = productIds.slice(0, AI_PRODUCTS_BULK_MAX)\n if (!ids.length) return false\n const job = await start(aiProductsBulkBrief(ids.length), aiProductsJobInputs({ target: 'bulk', productIds: [...ids] }))\n if (job) setStarted((current) => ({ ...current, [job.id]: 'bulk' }))\n return Boolean(job)\n },\n [start],\n )\n\n // An import that asked for its copy starts the job once, as the import lands.\n useEffect(() => {\n if (verdict !== 'ready' || !lastImport || handledImports.current.has(lastImport.key)) return\n handledImports.current.add(lastImport.key)\n if (lastImport.options[AI_PRODUCTS_IMPORT_WRITE_COPY] && lastImport.productIds.length) {\n void startBulk(lastImport.productIds)\n }\n }, [verdict, lastImport, startBulk])\n\n const heldNames = useMemo(() => new Set(products.map((product) => nameKey(product.name))), [products])\n const pickerRows = useMemo(\n () =>\n products.map((product) => ({\n $id: product.id,\n name: product.name,\n status: product.status,\n photo: product.hasPhoto ? 'Yes' : 'No photo',\n })),\n [products],\n )\n const pickerColumns = useMemo<GridColDef[]>(\n () => [\n { field: 'name', headerName: 'Product', flex: 1, minWidth: 180 },\n { field: 'status', headerName: 'Status', width: 110 },\n { field: 'photo', headerName: 'Photo', width: 110 },\n ],\n [],\n )\n\n if (verdict !== 'ready') return null\n\n const latest = (target: string) => jobs.find((job) => targetOf(job, started) === target) ?? null\n const bulkJob = latest('bulk')\n const catalogJob = latest('catalog')\n const categoriesJob = latest('categories')\n const tooMany = picked.length > AI_PRODUCTS_BULK_MAX\n const help = pluginDocsHelp('aiProducts', {\n excerpt:\n 'Write product copy, propose a first catalog, or propose categories and discounts from a brief. You review every proposal before anything is saved.',\n })\n const copy = brief ? AI_PRODUCTS_BRIEF_COPY[brief.kind] : null\n\n const submitBrief = async () => {\n if (!brief?.text.trim()) return\n setBusy(true)\n try {\n const job = await start(brief.text.trim(), aiProductsJobInputs({ target: brief.kind }))\n if (job) {\n setStarted((current) => ({ ...current, [job.id]: brief.kind }))\n setBrief(null)\n }\n } finally {\n setBusy(false)\n }\n }\n\n const submitPicked = async () => {\n setBusy(true)\n try {\n if (await startBulk(picked)) {\n setPicking(false)\n setPicked([])\n }\n } finally {\n setBusy(false)\n }\n }\n\n return (\n <Box sx={{ border: 1, borderColor: 'divider', borderRadius: 1, p: 1.5 }} aria-label=\"Products assistant\">\n <Stack spacing={1.5}>\n <Stack direction=\"row\" spacing={1} sx={{ alignItems: 'baseline' }}>\n <Typography variant=\"subtitle2\" sx={{ flexGrow: 1 }}>\n {'Build your catalog with AI'}\n </Typography>\n <Link href={help.href} target=\"_blank\" rel=\"noopener\" variant=\"caption\" title={help.excerpt}>\n {'How it works'}\n </Link>\n </Stack>\n <Stack direction={{ xs: 'column', sm: 'row' }} spacing={1}>\n <Button size=\"small\" variant=\"outlined\" disabled={!orgId || !products.length} onClick={() => setPicking(true)}>\n {'Write copy for products'}\n </Button>\n <Button size=\"small\" variant=\"outlined\" disabled={!orgId} onClick={() => setBrief({ kind: 'catalog', text: '' })}>\n {'Propose products'}\n </Button>\n <Button\n size=\"small\"\n variant=\"outlined\"\n disabled={!orgId}\n onClick={() => setBrief({ kind: 'categories', text: '' })}\n >\n {'Propose categories and discounts'}\n </Button>\n </Stack>\n {notice ? <Alert severity=\"warning\">{notice}</Alert> : null}\n {bulkJob ? (\n <AiBulkCopyReview key={bulkJob.id} job={bulkJob} applyProductCopy={applyProductCopy} />\n ) : null}\n {catalogJob ? (\n <AiCatalogReview\n key={catalogJob.id}\n job={catalogJob}\n heldNames={heldNames}\n createProductDrafts={createProductDrafts}\n />\n ) : null}\n {categoriesJob ? (\n <AiCategoriesReview\n key={categoriesJob.id}\n job={categoriesJob}\n createCategories={createCategories}\n createDiscountDrafts={createDiscountDrafts}\n />\n ) : null}\n </Stack>\n\n <Dialog open={picking} onClose={busy ? undefined : () => setPicking(false)} fullWidth maxWidth=\"md\">\n <DialogTitle>{'Write copy for products'}</DialogTitle>\n <DialogContent>\n <Stack spacing={1.5} sx={{ pt: 1 }}>\n <Typography variant=\"body2\" color=\"text.secondary\">\n {`Pick up to ${AI_PRODUCTS_BULK_MAX} products. Each gets a proposed description, search listing and ` +\n 'tags from its name, text, options and first photo, and you review every one before it is saved. ' +\n 'Prices are never written.'}\n </Typography>\n <ListTable\n rows={pickerRows}\n columns={pickerColumns}\n // A picker over the rows the hub hands its zone, not a list to\n // search: a filter here would narrow only those rows (AGL-3321).\n disableColumnFilter\n quickFilter={false}\n selectable={{ selected: picked, onChange: setPicked }}\n />\n {tooMany ? (\n <Alert severity=\"info\">{`Pick at most ${AI_PRODUCTS_BULK_MAX} products at a time.`}</Alert>\n ) : null}\n {notice ? <Alert severity=\"warning\">{notice}</Alert> : null}\n </Stack>\n </DialogContent>\n <DialogActions>\n <Button onClick={() => setPicking(false)} disabled={busy}>\n {'Cancel'}\n </Button>\n <Button variant=\"contained\" disabled={busy || !picked.length || tooMany} onClick={() => void submitPicked()}>\n {picked.length ? `Write copy for ${picked.length}` : 'Write copy'}\n </Button>\n </DialogActions>\n </Dialog>\n\n <Dialog open={Boolean(brief)} onClose={busy ? undefined : () => setBrief(null)} fullWidth maxWidth=\"sm\">\n <DialogTitle>{copy?.title}</DialogTitle>\n <DialogContent>\n <Stack spacing={2} sx={{ pt: 1 }}>\n <TextField\n label={copy?.label}\n placeholder={copy?.placeholder}\n multiline\n minRows={4}\n value={brief?.text ?? ''}\n onChange={(event) =>\n setBrief((current) => (current ? { ...current, text: event.target.value.slice(0, BRIEF_MAX_CHARS) } : current))\n }\n helperText={`${(brief?.text.length ?? 0).toLocaleString('en-US')} / ${BRIEF_MAX_CHARS.toLocaleString('en-US')}`}\n disabled={busy}\n autoFocus\n />\n <Typography variant=\"body2\" color=\"text.secondary\">\n {copy?.next}\n </Typography>\n {brief?.kind === 'catalog' ? (\n <Stack direction=\"row\" spacing={1} useFlexGap sx={{ flexWrap: 'wrap' }}>\n <Chip size=\"small\" color=\"warning\" variant=\"outlined\" label=\"Prices stay empty\" />\n <Chip size=\"small\" color=\"warning\" variant=\"outlined\" label=\"Photos are yours to add\" />\n </Stack>\n ) : null}\n {notice ? <Alert severity=\"warning\">{notice}</Alert> : null}\n </Stack>\n </DialogContent>\n <DialogActions>\n <Button onClick={() => setBrief(null)} disabled={busy}>\n {'Cancel'}\n </Button>\n <Button variant=\"contained\" disabled={busy || !orgId || !brief?.text.trim()} onClick={() => void submitBrief()}>\n {copy?.submit}\n </Button>\n </DialogActions>\n </Dialog>\n </Box>\n )\n}\nAiProductsHubCard.displayName = 'AiProductsHubCard'\n\nexport default AiProductsHubCard\n"],"names":["pluginDocsHelp","ListTable","Alert","Box","Button","Chip","Dialog","DialogActions","DialogContent","DialogTitle","Link","Stack","TextField","Typography","useCallback","useEffect","useMemo","useRef","useState","AI_PRODUCTS_BULK_MAX","AI_PRODUCTS_IMPORT_WRITE_COPY","aiProductsBulkBrief","aiProductsBulkCount","aiProductsJobInputs","aiProductsProposalOfKind","AiBulkCopyReview","AiCatalogReview","AiCategoriesReview","useAiProductsJobs","BRIEF_MAX_CHARS","AI_PRODUCTS_BRIEF_COPY","catalog","title","label","placeholder","next","submit","categories","nameKey","name","replace","trim","toLowerCase","targetOf","job","started","id","AiProductsHubCard","props","hostId","products","lastImport","applyProductCopy","createProductDrafts","createCategories","createDiscountDrafts","orgId","verdict","jobs","notice","start","follows","setStarted","picking","setPicking","picked","setPicked","brief","setBrief","busy","setBusy","handledImports","Set","startBulk","productIds","ids","slice","length","target","current","Boolean","has","key","add","options","heldNames","map","product","pickerRows","$id","status","photo","hasPhoto","pickerColumns","field","headerName","flex","minWidth","width","latest","find","bulkJob","catalogJob","categoriesJob","tooMany","help","excerpt","copy","kind","submitBrief","text","submitPicked","sx","border","borderColor","borderRadius","p","aria-label","spacing","direction","alignItems","variant","flexGrow","href","rel","xs","sm","size","disabled","onClick","severity","open","onClose","undefined","fullWidth","maxWidth","pt","color","rows","columns","disableColumnFilter","quickFilter","selectable","selected","onChange","multiline","minRows","value","event","helperText","toLocaleString","autoFocus","useFlexGap","flexWrap","displayName"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GACD;;;AAEA,SAASA,cAAc,QAAQ,mCAAkC;AAEjE,SAASC,SAAS,QAA6B,uDAAsD;AACrG,SACEC,KAAK,EACLC,GAAG,EACHC,MAAM,EACNC,IAAI,EACJC,MAAM,EACNC,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AAM;4CAAUhB,SAAQ;4CAAWxF,OAAM;;;qCAE5D;gCACH0B,uBAAS,KAACzD;oCAAMgI,UAAS;8CAAWvE;qCAAkB;;;;kCAG3D,MAACpD;;0CACC,KAACH;gCAAO6H,SAAS,IAAM7D,SAAS;gCAAO4D,UAAU3D;0CAC9C;;0CAEH,KAACjE;gCAAOqH,SAAQ;gCAAYO,UAAU3D,QAAQ,CAACb,SAAS,EAACW,yBAAAA,MAAO2C,IAAI,CAACrE,IAAI;gCAAIwF,SAAS,IAAM,KAAKpB;0CAC9FF,wBAAAA,KAAMvE,MAAM;;;;;;;;AAMzB;AACAW,kBAAkB2G,WAAW,GAAG;AAEhC,eAAe3G,kBAAiB"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/components/ai-products-hub-card.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 type { ConsoleProductsHubZoneProps } from './ai-product-zones'\nimport { ListTable, type ListTableProps } from '@aglyn/shared-ui-jsx/components/list-table.component'\nimport {\n Alert,\n Box,\n Button,\n Chip,\n Dialog,\n DialogActions,\n DialogContent,\n DialogTitle,\n Link,\n Stack,\n TextField,\n Typography,\n} from '@mui/material'\nimport { useCallback, useEffect, useMemo, useRef, useState } from 'react'\nimport type { AiJobSummary } from '../model/ai-jobs.types'\nimport {\n AI_PRODUCTS_BULK_MAX,\n AI_PRODUCTS_IMPORT_WRITE_COPY,\n aiProductsBulkBrief,\n aiProductsBulkCount,\n aiProductsJobInputs,\n aiProductsProposalOfKind,\n} from '../model/ai-products'\nimport { AiBulkCopyReview, AiCatalogReview, AiCategoriesReview } from './ai-products-proposals.component'\nimport { useAiProductsJobs } from './use-ai-products-jobs'\n\n/**\n * Commerce by AI on the products hub (AGL-2916), through the `productsHub`\n * zone. Three things a person asks for, each a `products` job, and each\n * proposal reviewed in a table before anything is written:\n *\n * - **Write copy for products** — up to 50 saved products, picked from the\n * hub's rows; a job works through them a product at a time, and each row is\n * applied on its own or all at once.\n * - **Propose products** — a store's first products from a brief, created as\n * drafts with their prices empty and no photo, both marked for the person to\n * set.\n * - **Propose categories and discounts** — from a brief, created as the\n * catalog and discounts cards create them, every discount switched off.\n *\n * An import whose `productImport` option asked for it starts a copy job for\n * the products the import created, as they land. Every write is the hub's\n * (`ConsoleProductsHubZoneProps`); this card writes nothing itself.\n */\n\nconst BRIEF_MAX_CHARS = 4_000\n\n/** A column of the product picker, in the shared list table's own terms. */\ntype GridColDef = NonNullable<ListTableProps['columns']>[number]\n\ntype BriefKind = 'catalog' | 'categories'\n\n/** What each brief dialog says. */\nexport const AI_PRODUCTS_BRIEF_COPY: Readonly<\n Record<BriefKind, { title: string; label: string; placeholder: string; next: string; submit: string }>\n> = {\n catalog: {\n title: 'Propose products',\n label: 'What does the store sell?',\n placeholder: 'A candle studio in Asheville: hand-poured soy candles in 8 oz and 16 oz jars, and wax melts',\n next:\n 'You review up to twelve proposed products before any is created. Each is created as a draft with its ' +\n 'price left empty and no photo, and nothing is on your storefront until you price it and activate it.',\n submit: 'Propose products',\n },\n categories: {\n title: 'Propose categories and discounts',\n label: 'What should shoppers be able to browse, and what offers suit the store?',\n placeholder: 'A trail running shop: shoes, apparel and hydration packs, with a welcome offer for new runners',\n next:\n 'You review the proposed categories and discounts before any is created. Discounts are created switched ' +\n 'off, and a shopper sees none until you switch it on.',\n submit: 'Propose',\n },\n}\n\nconst nameKey = (name: string) => name.replace(/\\s+/g, ' ').trim().toLowerCase()\n\n/** Which card a `products` job belongs to: from what it proposed, or from what this card started. */\nfunction targetOf(job: AiJobSummary, started: Readonly<Record<string, string>>): string | null {\n if (started[job.id]) return started[job.id]\n if (aiProductsBulkCount(job) !== null) return 'bulk'\n if (aiProductsProposalOfKind(job, 'catalog')) return 'catalog'\n if (aiProductsProposalOfKind(job, 'categories')) return 'categories'\n return null\n}\n\nexport function AiProductsHubCard(props: ConsoleProductsHubZoneProps) {\n const { hostId, products, lastImport, applyProductCopy, createProductDrafts, createCategories, createDiscountDrafts } =\n props\n const { orgId, verdict, jobs, notice, start } = useAiProductsJobs({\n hostId,\n orgId: props.orgId,\n // A bulk job is known by its brief while it runs; a catalog or categories\n // job started elsewhere is shown once it has proposed.\n follows: (job) => aiProductsBulkCount(job) !== null,\n })\n const [started, setStarted] = useState<Record<string, string>>({})\n const [picking, setPicking] = useState(false)\n const [picked, setPicked] = useState<string[]>([])\n const [brief, setBrief] = useState<{ kind: BriefKind; text: string } | null>(null)\n const [busy, setBusy] = useState(false)\n const handledImports = useRef(new Set<string>())\n\n const startBulk = useCallback(\n async (productIds: readonly string[]) => {\n const ids = productIds.slice(0, AI_PRODUCTS_BULK_MAX)\n if (!ids.length) return false\n const job = await start(aiProductsBulkBrief(ids.length), aiProductsJobInputs({ target: 'bulk', productIds: [...ids] }))\n if (job) setStarted((current) => ({ ...current, [job.id]: 'bulk' }))\n return Boolean(job)\n },\n [start],\n )\n\n // An import that asked for its copy starts the job once, as the import lands.\n useEffect(() => {\n if (verdict !== 'ready' || !lastImport || handledImports.current.has(lastImport.key)) return\n handledImports.current.add(lastImport.key)\n if (lastImport.options[AI_PRODUCTS_IMPORT_WRITE_COPY] && lastImport.productIds.length) {\n void startBulk(lastImport.productIds)\n }\n }, [verdict, lastImport, startBulk])\n\n const heldNames = useMemo(() => new Set(products.map((product) => nameKey(product.name))), [products])\n const pickerRows = useMemo(\n () =>\n products.map((product) => ({\n $id: product.id,\n name: product.name,\n status: product.status,\n photo: product.hasPhoto ? 'Yes' : 'No photo',\n })),\n [products],\n )\n const pickerColumns = useMemo<GridColDef[]>(\n () => [\n { field: 'name', headerName: 'Product', flex: 1, minWidth: 180 },\n { field: 'status', headerName: 'Status', width: 110 },\n { field: 'photo', headerName: 'Photo', width: 110 },\n ],\n [],\n )\n\n if (verdict !== 'ready') return null\n\n const latest = (target: string) => jobs.find((job) => targetOf(job, started) === target) ?? null\n const bulkJob = latest('bulk')\n const catalogJob = latest('catalog')\n const categoriesJob = latest('categories')\n const tooMany = picked.length > AI_PRODUCTS_BULK_MAX\n const help = pluginDocsHelp('aiProducts', {\n excerpt:\n 'Write product copy, propose a first catalog, or propose categories and discounts from a brief. You review every proposal before anything is saved.',\n })\n const copy = brief ? AI_PRODUCTS_BRIEF_COPY[brief.kind] : null\n\n const submitBrief = async () => {\n if (!brief?.text.trim()) return\n setBusy(true)\n try {\n const job = await start(brief.text.trim(), aiProductsJobInputs({ target: brief.kind }))\n if (job) {\n setStarted((current) => ({ ...current, [job.id]: brief.kind }))\n setBrief(null)\n }\n } finally {\n setBusy(false)\n }\n }\n\n const submitPicked = async () => {\n setBusy(true)\n try {\n if (await startBulk(picked)) {\n setPicking(false)\n setPicked([])\n }\n } finally {\n setBusy(false)\n }\n }\n\n return (\n <Box sx={{ border: 1, borderColor: 'divider', borderRadius: 1, p: 1.5 }} aria-label=\"Products assistant\">\n <Stack spacing={1.5}>\n <Stack direction=\"row\" spacing={1} sx={{ alignItems: 'baseline' }}>\n <Typography variant=\"subtitle2\" sx={{ flexGrow: 1 }}>\n {'Build your catalog with AI'}\n </Typography>\n <Link href={help.href} target=\"_blank\" rel=\"noopener\" variant=\"caption\" title={help.excerpt}>\n {'How it works'}\n </Link>\n </Stack>\n <Stack direction={{ xs: 'column', sm: 'row' }} spacing={1}>\n <Button size=\"small\" variant=\"outlined\" disabled={!orgId || !products.length} onClick={() => setPicking(true)}>\n {'Write copy for products'}\n </Button>\n <Button size=\"small\" variant=\"outlined\" disabled={!orgId} onClick={() => setBrief({ kind: 'catalog', text: '' })}>\n {'Propose products'}\n </Button>\n <Button\n size=\"small\"\n variant=\"outlined\"\n disabled={!orgId}\n onClick={() => setBrief({ kind: 'categories', text: '' })}\n >\n {'Propose categories and discounts'}\n </Button>\n </Stack>\n {notice ? <Alert severity=\"warning\">{notice}</Alert> : null}\n {bulkJob ? (\n <AiBulkCopyReview key={bulkJob.id} job={bulkJob} applyProductCopy={applyProductCopy} />\n ) : null}\n {catalogJob ? (\n <AiCatalogReview\n key={catalogJob.id}\n job={catalogJob}\n heldNames={heldNames}\n createProductDrafts={createProductDrafts}\n />\n ) : null}\n {categoriesJob ? (\n <AiCategoriesReview\n key={categoriesJob.id}\n job={categoriesJob}\n createCategories={createCategories}\n createDiscountDrafts={createDiscountDrafts}\n />\n ) : null}\n </Stack>\n\n <Dialog open={picking} onClose={busy ? undefined : () => setPicking(false)} fullWidth maxWidth=\"md\">\n <DialogTitle>{'Write copy for products'}</DialogTitle>\n <DialogContent>\n <Stack spacing={1.5} sx={{ pt: 1 }}>\n <Typography variant=\"body2\" color=\"text.secondary\">\n {`Pick up to ${AI_PRODUCTS_BULK_MAX} products. Each gets a proposed description, search listing and ` +\n 'tags from its name, text, options and first photo, and you review every one before it is saved. ' +\n 'Prices are never written.'}\n </Typography>\n <ListTable\n rows={pickerRows}\n columns={pickerColumns}\n // A picker over the rows the hub hands its zone, not a list to\n // search: a filter here would narrow only those rows (AGL-3321).\n disableColumnFilter\n quickFilter={false}\n selectable={{ selected: picked, onChange: setPicked }}\n />\n {tooMany ? (\n <Alert severity=\"info\">{`Pick at most ${AI_PRODUCTS_BULK_MAX} products at a time.`}</Alert>\n ) : null}\n {notice ? <Alert severity=\"warning\">{notice}</Alert> : null}\n </Stack>\n </DialogContent>\n <DialogActions>\n <Button onClick={() => setPicking(false)} disabled={busy}>\n {'Cancel'}\n </Button>\n <Button variant=\"contained\" disabled={busy || !picked.length || tooMany} onClick={() => void submitPicked()}>\n {picked.length ? `Write copy for ${picked.length}` : 'Write copy'}\n </Button>\n </DialogActions>\n </Dialog>\n\n <Dialog open={Boolean(brief)} onClose={busy ? undefined : () => setBrief(null)} fullWidth maxWidth=\"sm\">\n <DialogTitle>{copy?.title}</DialogTitle>\n <DialogContent>\n <Stack spacing={2} sx={{ pt: 1 }}>\n <TextField\n label={copy?.label}\n placeholder={copy?.placeholder}\n multiline\n minRows={4}\n value={brief?.text ?? ''}\n onChange={(event) =>\n setBrief((current) => (current ? { ...current, text: event.target.value.slice(0, BRIEF_MAX_CHARS) } : current))\n }\n helperText={`${(brief?.text.length ?? 0).toLocaleString('en-US')} / ${BRIEF_MAX_CHARS.toLocaleString('en-US')}`}\n disabled={busy}\n autoFocus\n />\n <Typography variant=\"body2\" color=\"text.secondary\">\n {copy?.next}\n </Typography>\n {brief?.kind === 'catalog' ? (\n <Stack direction=\"row\" spacing={1} useFlexGap sx={{ flexWrap: 'wrap' }}>\n <Chip size=\"small\" color=\"warning\" variant=\"outlined\" label=\"Prices stay empty\" />\n <Chip size=\"small\" color=\"warning\" variant=\"outlined\" label=\"Photos are yours to add\" />\n </Stack>\n ) : null}\n {notice ? <Alert severity=\"warning\">{notice}</Alert> : null}\n </Stack>\n </DialogContent>\n <DialogActions>\n <Button onClick={() => setBrief(null)} disabled={busy}>\n {'Cancel'}\n </Button>\n <Button variant=\"contained\" disabled={busy || !orgId || !brief?.text.trim()} onClick={() => void submitBrief()}>\n {copy?.submit}\n </Button>\n </DialogActions>\n </Dialog>\n </Box>\n )\n}\nAiProductsHubCard.displayName = 'AiProductsHubCard'\n\nexport default AiProductsHubCard\n"],"names":["pluginDocsHelp","ListTable","Alert","Box","Button","Chip","Dialog","DialogActions","DialogContent","DialogTitle","Link","Stack","TextField","Typography","useCallback","useEffect","useMemo","useRef","useState","AI_PRODUCTS_BULK_MAX","AI_PRODUCTS_IMPORT_WRITE_COPY","aiProductsBulkBrief","aiProductsBulkCount","aiProductsJobInputs","aiProductsProposalOfKind","AiBulkCopyReview","AiCatalogReview","AiCategoriesReview","useAiProductsJobs","BRIEF_MAX_CHARS","AI_PRODUCTS_BRIEF_COPY","catalog","title","label","placeholder","next","submit","categories","nameKey","name","replace","trim","toLowerCase","targetOf","job","started","id","AiProductsHubCard","props","hostId","products","lastImport","applyProductCopy","createProductDrafts","createCategories","createDiscountDrafts","orgId","verdict","jobs","notice","start","follows","setStarted","picking","setPicking","picked","setPicked","brief","setBrief","busy","setBusy","handledImports","Set","startBulk","productIds","ids","slice","length","target","current","Boolean","has","key","add","options","heldNames","map","product","pickerRows","$id","status","photo","hasPhoto","pickerColumns","field","headerName","flex","minWidth","width","latest","find","bulkJob","catalogJob","categoriesJob","tooMany","help","excerpt","copy","kind","submitBrief","text","submitPicked","sx","border","borderColor","borderRadius","p","aria-label","spacing","direction","alignItems","variant","flexGrow","href","rel","xs","sm","size","disabled","onClick","severity","open","onClose","undefined","fullWidth","maxWidth","pt","color","rows","columns","disableColumnFilter","quickFilter","selectable","selected","onChange","multiline","minRows","value","event","helperText","toLocaleString","autoFocus","useFlexGap","flexWrap","displayName"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GACD;;;AAEA,SAASA,cAAc,QAAQ,mCAAkC;AAEjE,SAASC,SAAS,QAA6B,uDAAsD;AACrG,SACEC,KAAK,EACLC,GAAG,EACHC,MAAM,EACNC,IAAI,EACJC,MAAM,EACNC,aAAa,EACbC,aAAa,EACbC,WAAW,EACXC,IAAI,EACJC,KAAK,EACLC,SAAS,EACTC,UAAU,QACL,gBAAe;AACtB,SAASC,WAAW,EAAEC,SAAS,EAAEC,OAAO,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,QAAO;AAEzE,SACEC,oBAAoB,EACpBC,6BAA6B,EAC7BC,mBAAmB,EACnBC,mBAAmB,EACnBC,mBAAmB,EACnBC,wBAAwB,QACnB,0BAAsB;AAC7B,SAASC,gBAAgB,EAAEC,eAAe,EAAEC,kBAAkB,QAAQ,uCAAmC;AACzG,SAASC,iBAAiB,QAAQ,4BAAwB;A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B2G,WAAW,GAAG;AAEhC,eAAe3G,kBAAiB"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ConsoleProductsHubZoneProps } from '
|
|
1
|
+
import type { ConsoleProductsHubZoneProps } from './ai-product-zones';
|
|
2
2
|
import type { AiJobSummary } from '../model/ai-jobs.types';
|
|
3
3
|
import { type AiProposedDiscount } from '../model/ai-products';
|
|
4
4
|
/** A discount's offer, in the words the discounts card uses. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/components/ai-products-proposals.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 type { ConsoleProductsHubZoneProps } from '@aglyn/aglyn/plugin-manager/feature-plugins'\nimport { ListTable, type ListTableProps } from '@aglyn/shared-ui-jsx/components/list-table.component'\nimport { Alert, Button, Chip, CircularProgress, Stack, Typography } from '@mui/material'\nimport { useCallback, useMemo, useState } from 'react'\nimport type { AiJobSummary } from '../model/ai-jobs.types'\nimport {\n aiProductCopyProposals,\n aiProductsBulkCount,\n aiProductsProposalOfKind,\n type AiProductCopyProposal,\n type AiProposedDiscount,\n} from '../model/ai-products'\nimport { aiProductCopyValues } from './ai-product-copy-card.component'\nimport { isAiJobMoving } from './use-ai-products-jobs'\n\n/**\n * The review tables of the products hub's AI card (AGL-2916): what a\n * `products` job proposed, row by row, before anything is written. Every\n * write is one the hub makes when a person asks for it — Apply, Apply to all,\n * Create drafts, Create selected — and the hub passes over what the site\n * already has, so a proposal applied twice creates nothing twice.\n *\n * Each table is one job's whole answer, held in hand and capped by the job\n * (`AI_PRODUCTS_BULK_MAX`, `AI_CATEGORIES_MAX`, `AI_DISCOUNTS_MAX`, a dozen\n * proposed products), so none offers a Filters panel or a search box: a\n * bounded readout is read whole, and a grid that filtered the rows it holds\n * is the pattern every list is leaving (AGL-3321).\n */\n\n/** A column of a review table, in the shared list table's own terms. */\ntype GridColDef = NonNullable<ListTableProps['columns']>[number]\n\nconst clip = (text: string, max: number) => (text.length > max ? `${text.slice(0, max - 1)}…` : text)\n\nconst messageOf = (error: unknown, fallback: string) =>\n error instanceof Error && error.message ? error.message : fallback\n\n/** A discount's offer, in the words the discounts card uses. */\nexport function aiDiscountOffer(discount: AiProposedDiscount): string {\n if (discount.kind === 'percent') return `${discount.valuePct ?? 0}% off`\n if (discount.kind === 'fixed') return `$${((discount.valueCents ?? 0) / 100).toFixed(2)} off`\n return 'Free shipping'\n}\n\nfunction JobState(props: { job: AiJobSummary; doing: string }) {\n const { job } = props\n if (isAiJobMoving(job)) {\n return (\n <Stack direction=\"row\" spacing={1} sx={{ alignItems: 'center' }}>\n <CircularProgress size={16} aria-label={props.doing} />\n <Typography variant=\"body2\" color=\"text.secondary\">\n {props.doing}\n </Typography>\n </Stack>\n )\n }\n return job.error ? <Alert severity={job.status === 'failed' ? 'error' : 'warning'}>{job.error}</Alert> : null\n}\n\n/* ------------------------------------------------------------------------ *\n * Copy for many products\n * ------------------------------------------------------------------------ */\n\ntype RowState = 'applying' | 'applied' | { error: string }\n\nexport function AiBulkCopyReview(props: {\n job: AiJobSummary\n applyProductCopy: ConsoleProductsHubZoneProps['applyProductCopy']\n}) {\n const { job, applyProductCopy } = props\n const proposals = aiProductCopyProposals(job)\n const asked = aiProductsBulkCount(job) ?? proposals.length\n const [rows, setRows] = useState<Record<string, RowState>>({})\n const [applyingAll, setApplyingAll] = useState(false)\n\n const ready = (proposal: AiProductCopyProposal) =>\n Boolean(proposal.values && proposal.product.id) && rows[proposal.product.id as string] !== 'applied'\n\n const apply = useCallback(\n async (proposal: AiProductCopyProposal) => {\n const id = proposal.product.id\n if (!id || !proposal.values) return\n setRows((current) => ({ ...current, [id]: 'applying' }))\n try {\n await applyProductCopy(id, aiProductCopyValues(proposal))\n setRows((current) => ({ ...current, [id]: 'applied' }))\n } catch (error) {\n setRows((current) => ({ ...current, [id]: { error: messageOf(error, 'The copy could not be saved.') } }))\n }\n },\n [applyProductCopy],\n )\n\n /** Applies each proposal in turn, so one refusal names its product and the rest still land. */\n const applyAll = useCallback(\n async (targets: readonly AiProductCopyProposal[]) => {\n setApplyingAll(true)\n try {\n for (const proposal of targets) await apply(proposal)\n } finally {\n setApplyingAll(false)\n }\n },\n [apply],\n )\n\n const columns = useMemo<GridColDef[]>(\n () => [\n { field: 'name', headerName: 'Product', flex: 1, minWidth: 160 },\n { field: 'description', headerName: 'Proposed description', flex: 2, minWidth: 220 },\n { field: 'seoTitle', headerName: 'Search title', flex: 1, minWidth: 160 },\n {\n field: 'actions',\n headerName: '',\n width: 170,\n sortable: false,\n renderCell: ({ row }: { row: { proposal: AiProductCopyProposal } }) => {\n const { proposal } = row\n if (proposal.skipped) return <Chip size=\"small\" variant=\"outlined\" label=\"Skipped\" title={proposal.skipped} />\n const state = proposal.product.id ? rows[proposal.product.id] : undefined\n if (state === 'applied') return <Chip size=\"small\" color=\"success\" variant=\"outlined\" label=\"Applied\" />\n if (typeof state === 'object') return <Chip size=\"small\" color=\"error\" variant=\"outlined\" label=\"Not saved\" title={state.error} />\n return (\n <Button size=\"small\" disabled={state === 'applying' || applyingAll} onClick={() => void apply(proposal)}>\n {'Apply'}\n </Button>\n )\n },\n },\n ],\n [rows, applyingAll, apply],\n )\n\n const tableRows = proposals.map((proposal) => ({\n $id: proposal.product.id ?? proposal.product.name,\n name: proposal.product.name,\n description: proposal.values ? clip(proposal.values.description, 140) : (proposal.skipped ?? ''),\n seoTitle: proposal.values?.seoTitle ?? '',\n proposal,\n }))\n const readyCount = proposals.filter(ready).length\n const errors = Object.values(rows).filter((state): state is { error: string } => typeof state === 'object')\n const gaps = proposals.filter((proposal) => proposal.gaps.length).length\n\n return (\n <Stack spacing={1} aria-label=\"Proposed product copy\">\n <Typography variant=\"subtitle2\">{`Product copy · ${proposals.length} of ${asked}`}</Typography>\n <JobState job={job} doing={`Writing copy: ${proposals.length} of ${asked}`} />\n {tableRows.length ? <ListTable rows={tableRows} columns={columns} hideFooter disableColumnFilter quickFilter={false} /> : null}\n {gaps ? (\n <Alert severity=\"warning\">\n {`${gaps} ${gaps === 1 ? 'description marks' : 'descriptions mark'} facts in [brackets] to fill in before you publish.`}\n </Alert>\n ) : null}\n {errors.length ? <Alert severity=\"error\">{errors[0].error}</Alert> : null}\n <Button\n size=\"small\"\n variant=\"contained\"\n sx={{ alignSelf: 'flex-start' }}\n disabled={!readyCount || applyingAll}\n onClick={() => void applyAll(proposals.filter(ready))}\n >\n {readyCount ? `Apply to all ${readyCount}` : 'Apply to all'}\n </Button>\n </Stack>\n )\n}\n\n/* ------------------------------------------------------------------------ *\n * A store's first products\n * ------------------------------------------------------------------------ */\n\nexport function AiCatalogReview(props: {\n job: AiJobSummary\n heldNames: ReadonlySet<string>\n createProductDrafts: ConsoleProductsHubZoneProps['createProductDrafts']\n}) {\n const { job, heldNames, createProductDrafts } = props\n const proposal = aiProductsProposalOfKind(job, 'catalog')\n const products = useMemo(() => proposal?.products ?? [], [proposal])\n const held = (name: string) => heldNames.has(name.replace(/\\s+/g, ' ').trim().toLowerCase())\n const [selected, setSelected] = useState<string[] | null>(null)\n const [busy, setBusy] = useState(false)\n const [result, setResult] = useState<{ severity: 'success' | 'error'; text: string } | null>(null)\n\n const rows = products.map((product, index) => ({\n $id: `p${index}`,\n name: product.name,\n type: product.type,\n options: product.options.map((option) => `${option.name}: ${option.values.join(', ')}`).join(' · ') || '—',\n photo: product.photo,\n inCatalog: held(product.name),\n product,\n }))\n const chosen = selected ?? rows.filter((row) => !row.inCatalog).map((row) => row.$id)\n\n const columns = useMemo<GridColDef[]>(\n () => [\n { field: 'name', headerName: 'Product', flex: 1, minWidth: 180 },\n { field: 'options', headerName: 'Options', flex: 1, minWidth: 160 },\n {\n field: 'price',\n headerName: 'Price',\n width: 130,\n sortable: false,\n // Never proposed: prices are the merchant's to set.\n renderCell: () => <Chip size=\"small\" color=\"warning\" variant=\"outlined\" label=\"Set a price\" />,\n },\n {\n field: 'photo',\n headerName: 'Photo',\n flex: 1,\n minWidth: 200,\n sortable: false,\n renderCell: ({ row }: { row: { photo: string; inCatalog: boolean } }) => (\n <Stack spacing={0.25} sx={{ py: 0.5 }}>\n <Chip size=\"small\" color=\"warning\" variant=\"outlined\" label=\"Needs a photo\" sx={{ alignSelf: 'flex-start' }} />\n <Typography variant=\"caption\" color=\"text.secondary\" sx={{ whiteSpace: 'normal' }}>\n {row.photo}\n </Typography>\n </Stack>\n ),\n },\n {\n field: 'inCatalog',\n headerName: '',\n width: 150,\n sortable: false,\n renderCell: ({ row }: { row: { inCatalog: boolean } }) =>\n row.inCatalog ? <Chip size=\"small\" variant=\"outlined\" label=\"In your catalog\" /> : null,\n },\n ],\n [],\n )\n\n const create = useCallback(async () => {\n const picks = rows.filter((row) => chosen.includes(row.$id)).map((row) => row.product)\n if (!picks.length) return\n setBusy(true)\n setResult(null)\n try {\n const created = await createProductDrafts(\n picks.map((product) => ({\n name: product.name,\n type: product.type,\n description: product.description,\n tags: product.tags,\n options: product.options,\n seoTitle: product.seoTitle,\n seoDescription: product.seoDescription,\n })),\n )\n const passed = picks.length - created.length\n setResult({\n severity: 'success',\n text:\n `Created ${created.length} draft ${created.length === 1 ? 'product' : 'products'}. ` +\n 'Each needs a price and a photo before you activate it.' +\n (passed ? ` ${passed} already in your catalog ${passed === 1 ? 'was' : 'were'} left as they are.` : ''),\n })\n setSelected([])\n } catch (error) {\n setResult({ severity: 'error', text: messageOf(error, 'The draft products could not be created.') })\n } finally {\n setBusy(false)\n }\n }, [rows, chosen, createProductDrafts])\n\n return (\n <Stack spacing={1} aria-label=\"Proposed products\">\n <Typography variant=\"subtitle2\">{'Proposed products'}</Typography>\n <JobState job={job} doing=\"Proposing products from your brief\" />\n {rows.length ? (\n <>\n <Typography variant=\"body2\" color=\"text.secondary\">\n {'Each is created as a draft with its price left empty and no photo. Set both in the product editor, ' +\n 'then activate it.'}\n </Typography>\n <ListTable\n rows={rows}\n columns={columns}\n hideFooter\n disableColumnFilter\n quickFilter={false}\n getRowHeight={() => 'auto'}\n selectable={{ selected: chosen, onChange: setSelected }}\n />\n <Button\n size=\"small\"\n variant=\"contained\"\n sx={{ alignSelf: 'flex-start' }}\n disabled={busy || !chosen.length}\n onClick={() => void create()}\n >\n {`Create ${chosen.length} ${chosen.length === 1 ? 'draft' : 'drafts'}`}\n </Button>\n </>\n ) : null}\n {result ? <Alert severity={result.severity}>{result.text}</Alert> : null}\n </Stack>\n )\n}\n\n/* ------------------------------------------------------------------------ *\n * Categories and discounts\n * ------------------------------------------------------------------------ */\n\nexport function AiCategoriesReview(props: {\n job: AiJobSummary\n createCategories: ConsoleProductsHubZoneProps['createCategories']\n createDiscountDrafts: ConsoleProductsHubZoneProps['createDiscountDrafts']\n}) {\n const { job, createCategories, createDiscountDrafts } = props\n const proposal = aiProductsProposalOfKind(job, 'categories')\n const categoryRows = (proposal?.categories ?? []).map((category, index) => ({\n $id: `c${index}`,\n name: category.name,\n why: category.why,\n }))\n const discountRows = (proposal?.discounts ?? []).map((discount, index) => ({\n $id: `d${index}`,\n name: discount.name,\n code: discount.code ?? 'Applies on its own',\n offer: aiDiscountOffer(discount),\n minimum: discount.minSubtotalCents ? `$${(discount.minSubtotalCents / 100).toFixed(2)}` : 'Any order',\n why: discount.why,\n discount,\n }))\n const [categories, setCategories] = useState<string[] | null>(null)\n const [discounts, setDiscounts] = useState<string[] | null>(null)\n const [busy, setBusy] = useState(false)\n const [result, setResult] = useState<{ severity: 'success' | 'error'; text: string } | null>(null)\n const chosenCategories = categories ?? categoryRows.map((row) => row.$id)\n const chosenDiscounts = discounts ?? discountRows.map((row) => row.$id)\n\n const categoryColumns = useMemo<GridColDef[]>(\n () => [\n { field: 'name', headerName: 'Category', flex: 1, minWidth: 160 },\n { field: 'why', headerName: 'Why', flex: 2, minWidth: 220 },\n ],\n [],\n )\n const discountColumns = useMemo<GridColDef[]>(\n () => [\n { field: 'name', headerName: 'Discount', flex: 1, minWidth: 150 },\n { field: 'code', headerName: 'Code', width: 150 },\n { field: 'offer', headerName: 'Offer', width: 120 },\n { field: 'minimum', headerName: 'Minimum order', width: 130 },\n { field: 'why', headerName: 'Why', flex: 2, minWidth: 200 },\n ],\n [],\n )\n\n const create = useCallback(async () => {\n setBusy(true)\n setResult(null)\n try {\n const madeCategories = await createCategories(\n categoryRows.filter((row) => chosenCategories.includes(row.$id)).map((row) => row.name),\n )\n const madeDiscounts = await createDiscountDrafts(\n discountRows\n .filter((row) => chosenDiscounts.includes(row.$id))\n .map(({ discount }) => ({\n name: discount.name,\n code: discount.code,\n kind: discount.kind,\n valuePct: discount.valuePct,\n valueCents: discount.valueCents,\n minSubtotalCents: discount.minSubtotalCents,\n })),\n )\n setResult({\n severity: 'success',\n text:\n `Created ${madeCategories} ${madeCategories === 1 ? 'category' : 'categories'} and ` +\n `${madeDiscounts} ${madeDiscounts === 1 ? 'discount' : 'discounts'}. ` +\n 'Discounts start switched off: switch each on under Promotions when you are ready. ' +\n 'Anything your store already had was left as it is.',\n })\n setCategories([])\n setDiscounts([])\n } catch (error) {\n setResult({ severity: 'error', text: messageOf(error, 'The categories and discounts could not be created.') })\n } finally {\n setBusy(false)\n }\n }, [categoryRows, discountRows, chosenCategories, chosenDiscounts, createCategories, createDiscountDrafts])\n\n const any = chosenCategories.length + chosenDiscounts.length\n return (\n <Stack spacing={1} aria-label=\"Proposed categories and discounts\">\n <Typography variant=\"subtitle2\">{'Proposed categories and discounts'}</Typography>\n <JobState job={job} doing=\"Proposing categories and discounts from your brief\" />\n {categoryRows.length ? (\n <ListTable\n rows={categoryRows}\n columns={categoryColumns}\n hideFooter\n disableColumnFilter\n quickFilter={false}\n selectable={{ selected: chosenCategories, onChange: setCategories }}\n />\n ) : null}\n {discountRows.length ? (\n <ListTable\n rows={discountRows}\n columns={discountColumns}\n hideFooter\n disableColumnFilter\n quickFilter={false}\n selectable={{ selected: chosenDiscounts, onChange: setDiscounts }}\n />\n ) : null}\n {categoryRows.length || discountRows.length ? (\n <Button\n size=\"small\"\n variant=\"contained\"\n sx={{ alignSelf: 'flex-start' }}\n disabled={busy || !any}\n onClick={() => void create()}\n >\n {'Create selected'}\n </Button>\n ) : null}\n {result ? <Alert severity={result.severity}>{result.text}</Alert> : null}\n </Stack>\n )\n}\n"],"names":["ListTable","Alert","Button","Chip","CircularProgress","Stack","Typography","useCallback","useMemo","useState","aiProductCopyProposals","aiProductsBulkCount","aiProductsProposalOfKind","aiProductCopyValues","isAiJobMoving","clip","text","max","length","slice","messageOf","error","fallback","Error","message","aiDiscountOffer","discount","kind","valuePct","valueCents","toFixed","JobState","props","job","direction","spacing","sx","alignItems","size","aria-label","doing","variant","color","severity","status","AiBulkCopyReview","applyProductCopy","proposals","asked","rows","setRows","applyingAll","setApplyingAll","ready","proposal","Boolean","values","product","id","apply","current","applyAll","targets","columns","field","headerName","flex","minWidth","width","sortable","renderCell","row","skipped","label","title","state","undefined","disabled","onClick","tableRows","map","$id","name","description","seoTitle","readyCount","filter","errors","Object","gaps","hideFooter","disableColumnFilter","quickFilter","alignSelf","AiCatalogReview","heldNames","createProductDrafts","products","held","has","replace","trim","toLowerCase","selected","setSelected","busy","setBusy","result","setResult","index","type","options","option","join","photo","inCatalog","chosen","py","whiteSpace","create","picks","includes","created","tags","seoDescription","passed","getRowHeight","selectable","onChange","AiCategoriesReview","createCategories","createDiscountDrafts","categoryRows","categories","category","why","discountRows","discounts","code","offer","minimum","minSubtotalCents","setCategories","setDiscounts","chosenCategories","chosenDiscounts","categoryColumns","discountColumns","madeCategories","madeDiscounts","any"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GACD;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ChB;gBACCoC,MAAK;gBACLG,SAAQ;gBACRL,IAAI;oBAAEyD,WAAW;gBAAa;gBAC9BhB,UAAU4B,QAAQ,CAAC6C;gBACnBxE,SAAS,IAAM,KAAKyC;0BAEnB;iBAED;YACHZ,uBAAS,KAAC1G;gBAAM0C,UAAUgE,OAAOhE,QAAQ;0BAAGgE,OAAO3F,IAAI;iBAAY;;;AAG1E"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/components/ai-products-proposals.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 type { ConsoleProductsHubZoneProps } from './ai-product-zones'\nimport { ListTable, type ListTableProps } from '@aglyn/shared-ui-jsx/components/list-table.component'\nimport { Alert, Button, Chip, CircularProgress, Stack, Typography } from '@mui/material'\nimport { useCallback, useMemo, useState } from 'react'\nimport type { AiJobSummary } from '../model/ai-jobs.types'\nimport {\n aiProductCopyProposals,\n aiProductsBulkCount,\n aiProductsProposalOfKind,\n type AiProductCopyProposal,\n type AiProposedDiscount,\n} from '../model/ai-products'\nimport { aiProductCopyValues } from './ai-product-copy-card.component'\nimport { isAiJobMoving } from './use-ai-products-jobs'\n\n/**\n * The review tables of the products hub's AI card (AGL-2916): what a\n * `products` job proposed, row by row, before anything is written. Every\n * write is one the hub makes when a person asks for it — Apply, Apply to all,\n * Create drafts, Create selected — and the hub passes over what the site\n * already has, so a proposal applied twice creates nothing twice.\n *\n * Each table is one job's whole answer, held in hand and capped by the job\n * (`AI_PRODUCTS_BULK_MAX`, `AI_CATEGORIES_MAX`, `AI_DISCOUNTS_MAX`, a dozen\n * proposed products), so none offers a Filters panel or a search box: a\n * bounded readout is read whole, and a grid that filtered the rows it holds\n * is the pattern every list is leaving (AGL-3321).\n */\n\n/** A column of a review table, in the shared list table's own terms. */\ntype GridColDef = NonNullable<ListTableProps['columns']>[number]\n\nconst clip = (text: string, max: number) => (text.length > max ? `${text.slice(0, max - 1)}…` : text)\n\nconst messageOf = (error: unknown, fallback: string) =>\n error instanceof Error && error.message ? error.message : fallback\n\n/** A discount's offer, in the words the discounts card uses. */\nexport function aiDiscountOffer(discount: AiProposedDiscount): string {\n if (discount.kind === 'percent') return `${discount.valuePct ?? 0}% off`\n if (discount.kind === 'fixed') return `$${((discount.valueCents ?? 0) / 100).toFixed(2)} off`\n return 'Free shipping'\n}\n\nfunction JobState(props: { job: AiJobSummary; doing: string }) {\n const { job } = props\n if (isAiJobMoving(job)) {\n return (\n <Stack direction=\"row\" spacing={1} sx={{ alignItems: 'center' }}>\n <CircularProgress size={16} aria-label={props.doing} />\n <Typography variant=\"body2\" color=\"text.secondary\">\n {props.doing}\n </Typography>\n </Stack>\n )\n }\n return job.error ? <Alert severity={job.status === 'failed' ? 'error' : 'warning'}>{job.error}</Alert> : null\n}\n\n/* ------------------------------------------------------------------------ *\n * Copy for many products\n * ------------------------------------------------------------------------ */\n\ntype RowState = 'applying' | 'applied' | { error: string }\n\nexport function AiBulkCopyReview(props: {\n job: AiJobSummary\n applyProductCopy: ConsoleProductsHubZoneProps['applyProductCopy']\n}) {\n const { job, applyProductCopy } = props\n const proposals = aiProductCopyProposals(job)\n const asked = aiProductsBulkCount(job) ?? proposals.length\n const [rows, setRows] = useState<Record<string, RowState>>({})\n const [applyingAll, setApplyingAll] = useState(false)\n\n const ready = (proposal: AiProductCopyProposal) =>\n Boolean(proposal.values && proposal.product.id) && rows[proposal.product.id as string] !== 'applied'\n\n const apply = useCallback(\n async (proposal: AiProductCopyProposal) => {\n const id = proposal.product.id\n if (!id || !proposal.values) return\n setRows((current) => ({ ...current, [id]: 'applying' }))\n try {\n await applyProductCopy(id, aiProductCopyValues(proposal))\n setRows((current) => ({ ...current, [id]: 'applied' }))\n } catch (error) {\n setRows((current) => ({ ...current, [id]: { error: messageOf(error, 'The copy could not be saved.') } }))\n }\n },\n [applyProductCopy],\n )\n\n /** Applies each proposal in turn, so one refusal names its product and the rest still land. */\n const applyAll = useCallback(\n async (targets: readonly AiProductCopyProposal[]) => {\n setApplyingAll(true)\n try {\n for (const proposal of targets) await apply(proposal)\n } finally {\n setApplyingAll(false)\n }\n },\n [apply],\n )\n\n const columns = useMemo<GridColDef[]>(\n () => [\n { field: 'name', headerName: 'Product', flex: 1, minWidth: 160 },\n { field: 'description', headerName: 'Proposed description', flex: 2, minWidth: 220 },\n { field: 'seoTitle', headerName: 'Search title', flex: 1, minWidth: 160 },\n {\n field: 'actions',\n headerName: '',\n width: 170,\n sortable: false,\n renderCell: ({ row }: { row: { proposal: AiProductCopyProposal } }) => {\n const { proposal } = row\n if (proposal.skipped) return <Chip size=\"small\" variant=\"outlined\" label=\"Skipped\" title={proposal.skipped} />\n const state = proposal.product.id ? rows[proposal.product.id] : undefined\n if (state === 'applied') return <Chip size=\"small\" color=\"success\" variant=\"outlined\" label=\"Applied\" />\n if (typeof state === 'object') return <Chip size=\"small\" color=\"error\" variant=\"outlined\" label=\"Not saved\" title={state.error} />\n return (\n <Button size=\"small\" disabled={state === 'applying' || applyingAll} onClick={() => void apply(proposal)}>\n {'Apply'}\n </Button>\n )\n },\n },\n ],\n [rows, applyingAll, apply],\n )\n\n const tableRows = proposals.map((proposal) => ({\n $id: proposal.product.id ?? proposal.product.name,\n name: proposal.product.name,\n description: proposal.values ? clip(proposal.values.description, 140) : (proposal.skipped ?? ''),\n seoTitle: proposal.values?.seoTitle ?? '',\n proposal,\n }))\n const readyCount = proposals.filter(ready).length\n const errors = Object.values(rows).filter((state): state is { error: string } => typeof state === 'object')\n const gaps = proposals.filter((proposal) => proposal.gaps.length).length\n\n return (\n <Stack spacing={1} aria-label=\"Proposed product copy\">\n <Typography variant=\"subtitle2\">{`Product copy · ${proposals.length} of ${asked}`}</Typography>\n <JobState job={job} doing={`Writing copy: ${proposals.length} of ${asked}`} />\n {tableRows.length ? <ListTable rows={tableRows} columns={columns} hideFooter disableColumnFilter quickFilter={false} /> : null}\n {gaps ? (\n <Alert severity=\"warning\">\n {`${gaps} ${gaps === 1 ? 'description marks' : 'descriptions mark'} facts in [brackets] to fill in before you publish.`}\n </Alert>\n ) : null}\n {errors.length ? <Alert severity=\"error\">{errors[0].error}</Alert> : null}\n <Button\n size=\"small\"\n variant=\"contained\"\n sx={{ alignSelf: 'flex-start' }}\n disabled={!readyCount || applyingAll}\n onClick={() => void applyAll(proposals.filter(ready))}\n >\n {readyCount ? `Apply to all ${readyCount}` : 'Apply to all'}\n </Button>\n </Stack>\n )\n}\n\n/* ------------------------------------------------------------------------ *\n * A store's first products\n * ------------------------------------------------------------------------ */\n\nexport function AiCatalogReview(props: {\n job: AiJobSummary\n heldNames: ReadonlySet<string>\n createProductDrafts: ConsoleProductsHubZoneProps['createProductDrafts']\n}) {\n const { job, heldNames, createProductDrafts } = props\n const proposal = aiProductsProposalOfKind(job, 'catalog')\n const products = useMemo(() => proposal?.products ?? [], [proposal])\n const held = (name: string) => heldNames.has(name.replace(/\\s+/g, ' ').trim().toLowerCase())\n const [selected, setSelected] = useState<string[] | null>(null)\n const [busy, setBusy] = useState(false)\n const [result, setResult] = useState<{ severity: 'success' | 'error'; text: string } | null>(null)\n\n const rows = products.map((product, index) => ({\n $id: `p${index}`,\n name: product.name,\n type: product.type,\n options: product.options.map((option) => `${option.name}: ${option.values.join(', ')}`).join(' · ') || '—',\n photo: product.photo,\n inCatalog: held(product.name),\n product,\n }))\n const chosen = selected ?? rows.filter((row) => !row.inCatalog).map((row) => row.$id)\n\n const columns = useMemo<GridColDef[]>(\n () => [\n { field: 'name', headerName: 'Product', flex: 1, minWidth: 180 },\n { field: 'options', headerName: 'Options', flex: 1, minWidth: 160 },\n {\n field: 'price',\n headerName: 'Price',\n width: 130,\n sortable: false,\n // Never proposed: prices are the merchant's to set.\n renderCell: () => <Chip size=\"small\" color=\"warning\" variant=\"outlined\" label=\"Set a price\" />,\n },\n {\n field: 'photo',\n headerName: 'Photo',\n flex: 1,\n minWidth: 200,\n sortable: false,\n renderCell: ({ row }: { row: { photo: string; inCatalog: boolean } }) => (\n <Stack spacing={0.25} sx={{ py: 0.5 }}>\n <Chip size=\"small\" color=\"warning\" variant=\"outlined\" label=\"Needs a photo\" sx={{ alignSelf: 'flex-start' }} />\n <Typography variant=\"caption\" color=\"text.secondary\" sx={{ whiteSpace: 'normal' }}>\n {row.photo}\n </Typography>\n </Stack>\n ),\n },\n {\n field: 'inCatalog',\n headerName: '',\n width: 150,\n sortable: false,\n renderCell: ({ row }: { row: { inCatalog: boolean } }) =>\n row.inCatalog ? <Chip size=\"small\" variant=\"outlined\" label=\"In your catalog\" /> : null,\n },\n ],\n [],\n )\n\n const create = useCallback(async () => {\n const picks = rows.filter((row) => chosen.includes(row.$id)).map((row) => row.product)\n if (!picks.length) return\n setBusy(true)\n setResult(null)\n try {\n const created = await createProductDrafts(\n picks.map((product) => ({\n name: product.name,\n type: product.type,\n description: product.description,\n tags: product.tags,\n options: product.options,\n seoTitle: product.seoTitle,\n seoDescription: product.seoDescription,\n })),\n )\n const passed = picks.length - created.length\n setResult({\n severity: 'success',\n text:\n `Created ${created.length} draft ${created.length === 1 ? 'product' : 'products'}. ` +\n 'Each needs a price and a photo before you activate it.' +\n (passed ? ` ${passed} already in your catalog ${passed === 1 ? 'was' : 'were'} left as they are.` : ''),\n })\n setSelected([])\n } catch (error) {\n setResult({ severity: 'error', text: messageOf(error, 'The draft products could not be created.') })\n } finally {\n setBusy(false)\n }\n }, [rows, chosen, createProductDrafts])\n\n return (\n <Stack spacing={1} aria-label=\"Proposed products\">\n <Typography variant=\"subtitle2\">{'Proposed products'}</Typography>\n <JobState job={job} doing=\"Proposing products from your brief\" />\n {rows.length ? (\n <>\n <Typography variant=\"body2\" color=\"text.secondary\">\n {'Each is created as a draft with its price left empty and no photo. Set both in the product editor, ' +\n 'then activate it.'}\n </Typography>\n <ListTable\n rows={rows}\n columns={columns}\n hideFooter\n disableColumnFilter\n quickFilter={false}\n getRowHeight={() => 'auto'}\n selectable={{ selected: chosen, onChange: setSelected }}\n />\n <Button\n size=\"small\"\n variant=\"contained\"\n sx={{ alignSelf: 'flex-start' }}\n disabled={busy || !chosen.length}\n onClick={() => void create()}\n >\n {`Create ${chosen.length} ${chosen.length === 1 ? 'draft' : 'drafts'}`}\n </Button>\n </>\n ) : null}\n {result ? <Alert severity={result.severity}>{result.text}</Alert> : null}\n </Stack>\n )\n}\n\n/* ------------------------------------------------------------------------ *\n * Categories and discounts\n * ------------------------------------------------------------------------ */\n\nexport function AiCategoriesReview(props: {\n job: AiJobSummary\n createCategories: ConsoleProductsHubZoneProps['createCategories']\n createDiscountDrafts: ConsoleProductsHubZoneProps['createDiscountDrafts']\n}) {\n const { job, createCategories, createDiscountDrafts } = props\n const proposal = aiProductsProposalOfKind(job, 'categories')\n const categoryRows = (proposal?.categories ?? []).map((category, index) => ({\n $id: `c${index}`,\n name: category.name,\n why: category.why,\n }))\n const discountRows = (proposal?.discounts ?? []).map((discount, index) => ({\n $id: `d${index}`,\n name: discount.name,\n code: discount.code ?? 'Applies on its own',\n offer: aiDiscountOffer(discount),\n minimum: discount.minSubtotalCents ? `$${(discount.minSubtotalCents / 100).toFixed(2)}` : 'Any order',\n why: discount.why,\n discount,\n }))\n const [categories, setCategories] = useState<string[] | null>(null)\n const [discounts, setDiscounts] = useState<string[] | null>(null)\n const [busy, setBusy] = useState(false)\n const [result, setResult] = useState<{ severity: 'success' | 'error'; text: string } | null>(null)\n const chosenCategories = categories ?? categoryRows.map((row) => row.$id)\n const chosenDiscounts = discounts ?? discountRows.map((row) => row.$id)\n\n const categoryColumns = useMemo<GridColDef[]>(\n () => [\n { field: 'name', headerName: 'Category', flex: 1, minWidth: 160 },\n { field: 'why', headerName: 'Why', flex: 2, minWidth: 220 },\n ],\n [],\n )\n const discountColumns = useMemo<GridColDef[]>(\n () => [\n { field: 'name', headerName: 'Discount', flex: 1, minWidth: 150 },\n { field: 'code', headerName: 'Code', width: 150 },\n { field: 'offer', headerName: 'Offer', width: 120 },\n { field: 'minimum', headerName: 'Minimum order', width: 130 },\n { field: 'why', headerName: 'Why', flex: 2, minWidth: 200 },\n ],\n [],\n )\n\n const create = useCallback(async () => {\n setBusy(true)\n setResult(null)\n try {\n const madeCategories = await createCategories(\n categoryRows.filter((row) => chosenCategories.includes(row.$id)).map((row) => row.name),\n )\n const madeDiscounts = await createDiscountDrafts(\n discountRows\n .filter((row) => chosenDiscounts.includes(row.$id))\n .map(({ discount }) => ({\n name: discount.name,\n code: discount.code,\n kind: discount.kind,\n valuePct: discount.valuePct,\n valueCents: discount.valueCents,\n minSubtotalCents: discount.minSubtotalCents,\n })),\n )\n setResult({\n severity: 'success',\n text:\n `Created ${madeCategories} ${madeCategories === 1 ? 'category' : 'categories'} and ` +\n `${madeDiscounts} ${madeDiscounts === 1 ? 'discount' : 'discounts'}. ` +\n 'Discounts start switched off: switch each on under Promotions when you are ready. ' +\n 'Anything your store already had was left as it is.',\n })\n setCategories([])\n setDiscounts([])\n } catch (error) {\n setResult({ severity: 'error', text: messageOf(error, 'The categories and discounts could not be created.') })\n } finally {\n setBusy(false)\n }\n }, [categoryRows, discountRows, chosenCategories, chosenDiscounts, createCategories, createDiscountDrafts])\n\n const any = chosenCategories.length + chosenDiscounts.length\n return (\n <Stack spacing={1} aria-label=\"Proposed categories and discounts\">\n <Typography variant=\"subtitle2\">{'Proposed categories and discounts'}</Typography>\n <JobState job={job} doing=\"Proposing categories and discounts from your brief\" />\n {categoryRows.length ? (\n <ListTable\n rows={categoryRows}\n columns={categoryColumns}\n hideFooter\n disableColumnFilter\n quickFilter={false}\n selectable={{ selected: chosenCategories, onChange: setCategories }}\n />\n ) : null}\n {discountRows.length ? (\n <ListTable\n rows={discountRows}\n columns={discountColumns}\n hideFooter\n disableColumnFilter\n quickFilter={false}\n selectable={{ selected: chosenDiscounts, onChange: setDiscounts }}\n />\n ) : null}\n {categoryRows.length || discountRows.length ? (\n <Button\n size=\"small\"\n variant=\"contained\"\n sx={{ alignSelf: 'flex-start' }}\n disabled={busy || !any}\n onClick={() => void create()}\n >\n {'Create selected'}\n </Button>\n ) : null}\n {result ? <Alert severity={result.severity}>{result.text}</Alert> : null}\n </Stack>\n )\n}\n"],"names":["ListTable","Alert","Button","Chip","CircularProgress","Stack","Typography","useCallback","useMemo","useState","aiProductCopyProposals","aiProductsBulkCount","aiProductsProposalOfKind","aiProductCopyValues","isAiJobMoving","clip","text","max","length","slice","messageOf","error","fallback","Error","message","aiDiscountOffer","discount","kind","valuePct","valueCents","toFixed","JobState","props","job","direction","spacing","sx","alignItems","size","aria-label","doing","variant","color","severity","status","AiBulkCopyReview","applyProductCopy","proposals","asked","rows","setRows","applyingAll","setApplyingAll","ready","proposal","Boolean","values","product","id","apply","current","applyAll","targets","columns","field","headerName","flex","minWidth","width","sortable","renderCell","row","skipped","label","title","state","undefined","disabled","onClick","tableRows","map","$id","name","description","seoTitle","readyCount","filter","errors","Object","gaps","hideFooter","disableColumnFilter","quickFilter","alignSelf","AiCatalogReview","heldNames","createProductDrafts","products","held","has","replace","trim","toLowerCase","selected","setSelected","busy","setBusy","result","setResult","index","type","options","option","join","photo","inCatalog","chosen","py","whiteSpace","create","picks","includes","created","tags","seoDescription","passed","getRowHeight","selectable","onChange","AiCategoriesReview","createCategories","createDiscountDrafts","categoryRows","categories","category","why","discountRows","discounts","code","offer","minimum","minSubtotalCents","setCategories","setDiscounts","chosenCategories","chosenDiscounts","categoryColumns","discountColumns","madeCategories","madeDiscounts","any"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GACD;;;AAGA,SAASA,SAAS,QAA6B,uDAAsD;AACrG,SAASC,KAAK,EAAEC,MAAM,EAAEC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9BhB,UAAU4B,QAAQ,CAAC6C;gBACnBxE,SAAS,IAAM,KAAKyC;0BAEnB;iBAED;YACHZ,uBAAS,KAAC1G;gBAAM0C,UAAUgE,OAAOhE,QAAQ;0BAAGgE,OAAO3F,IAAI;iBAAY;;;AAG1E"}
|
|
@@ -23,16 +23,20 @@ import { ScrollTable } from "@aglyn/shared-ui-jsx/components/scroll-table.compon
|
|
|
23
23
|
import { TABLE_PAGE_SIZE_DEFAULT } from "@aglyn/shared-ui-jsx/const/table-pagination";
|
|
24
24
|
import { authorizedFetch } from "@aglyn/shared-util-http/authorized-token";
|
|
25
25
|
import { useUser } from "@aglyn/tenant-feature-instance";
|
|
26
|
-
import { Alert, Box, Button,
|
|
26
|
+
import { Alert, Box, Button, CircularProgress, Collapse, Stack, TableBody, TableCell, TableHead, TableRow, Typography } from "@mui/material";
|
|
27
27
|
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
28
28
|
import { AI_JOB_TERMINAL_STATUSES } from "../model/ai-jobs.types.js";
|
|
29
|
-
import {
|
|
29
|
+
import { aiSeoApplyCounts, aiSeoAuditView } from "../model/ai-seo.js";
|
|
30
30
|
import { readEventFrames } from "./assist-jobs-drawer.component.js";
|
|
31
31
|
/**
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
32
|
+
* SEO fixes (AGL-2910), on the site's SEO section through the `hostSeo` zone,
|
|
33
|
+
* under the platform's SEO check. The check lists what is wrong for every
|
|
34
|
+
* site owner; this card adds what only a model can: a person asks, and an
|
|
35
|
+
* `seo` job audits the same pages through the same check, proposes a fix per
|
|
36
|
+
* finding, and drafts the structured data and the agent guidance
|
|
37
|
+
* `/llms.txt` leads with. The findings are never listed here — the check
|
|
38
|
+
* above draws them — so this card shows the fixes, page by page. The target
|
|
39
|
+
* keywords are the ones the check was last run with (`check.keywords`).
|
|
36
40
|
*
|
|
37
41
|
* Nothing it shows is saved. "Put in the form" stages the site-wide proposal
|
|
38
42
|
* in the SEO form below as unsaved edits, and the form's Update is the write.
|
|
@@ -41,7 +45,6 @@ import { readEventFrames } from "./assist-jobs-drawer.component.js";
|
|
|
41
45
|
* listing for its SEO card — the live site serves none of it until a person
|
|
42
46
|
* saves or publishes.
|
|
43
47
|
*/ /** How many recent jobs the card reads to find this site's last audit. */ const RECENT_JOBS_READ = 20;
|
|
44
|
-
const KEYWORDS_MAX_CHARS = 3000;
|
|
45
48
|
const isTerminal = (job)=>AI_JOB_TERMINAL_STATUSES.includes(job.status);
|
|
46
49
|
/** What each site SEO form field is called where the proposal lists it. */ export const AI_SEO_SITE_FIELD_LABELS = {
|
|
47
50
|
'seo.entity.type': 'Published by',
|
|
@@ -69,16 +72,16 @@ const ENTITY_TYPE_WORDS = {
|
|
|
69
72
|
return parts.join(' · ');
|
|
70
73
|
}
|
|
71
74
|
export function AiSeoAuditCard(props) {
|
|
72
|
-
var _ref, _ref1, _ref2, _ref3, _ref4;
|
|
75
|
+
var _ref, _ref1, _ref2, _ref3, _ref4, _ref5;
|
|
73
76
|
var _view_site;
|
|
74
|
-
const { hostId, orgId, orgSlug, host, proposeDraft } = props;
|
|
77
|
+
const { hostId, orgId, orgSlug, host, proposeDraft, check } = props;
|
|
78
|
+
const keywords = (_ref = check == null ? void 0 : check.keywords) != null ? _ref : '';
|
|
75
79
|
const { data: user } = useUser();
|
|
76
80
|
const userRef = useRef(user);
|
|
77
81
|
userRef.current = user;
|
|
78
|
-
const uid = (
|
|
82
|
+
const uid = (_ref1 = user == null ? void 0 : user.uid) != null ? _ref1 : null;
|
|
79
83
|
const [verdict, setVerdict] = useState('checking');
|
|
80
84
|
const [notice, setNotice] = useState(null);
|
|
81
|
-
const [keywords, setKeywords] = useState('');
|
|
82
85
|
const [busy, setBusy] = useState(false);
|
|
83
86
|
const [job, setJob] = useState(null);
|
|
84
87
|
const [siteStaged, setSiteStaged] = useState(null);
|
|
@@ -180,7 +183,7 @@ export function AiSeoAuditCard(props) {
|
|
|
180
183
|
orgId,
|
|
181
184
|
hostId,
|
|
182
185
|
kind: 'seo',
|
|
183
|
-
brief: '
|
|
186
|
+
brief: 'Propose fixes for the SEO of this site',
|
|
184
187
|
inputs: {
|
|
185
188
|
target: 'site',
|
|
186
189
|
keywords: keywords.trim()
|
|
@@ -212,7 +215,7 @@ export function AiSeoAuditCard(props) {
|
|
|
212
215
|
const view = useMemo(()=>job ? aiSeoAuditView(job.outputs) : null, [
|
|
213
216
|
job
|
|
214
217
|
]);
|
|
215
|
-
const siteValues = (
|
|
218
|
+
const siteValues = (_ref2 = view == null ? void 0 : (_view_site = view.site) == null ? void 0 : _view_site.values) != null ? _ref2 : {};
|
|
216
219
|
const siteFields = Object.keys(siteValues);
|
|
217
220
|
const stageSite = useCallback(()=>{
|
|
218
221
|
if (!job || !siteFields.length) return;
|
|
@@ -268,16 +271,17 @@ export function AiSeoAuditCard(props) {
|
|
|
268
271
|
]);
|
|
269
272
|
if (verdict !== 'ready') return null;
|
|
270
273
|
const running = Boolean(job && !isTerminal(job));
|
|
271
|
-
const report = (
|
|
272
|
-
const findings = report ? report.pages.reduce((sum, entry)=>sum + entry.findings.length, report.site.length) : 0;
|
|
274
|
+
const report = (_ref3 = view == null ? void 0 : view.report) != null ? _ref3 : null;
|
|
273
275
|
const owedBatches = report ? Math.ceil(report.queue.length / Math.max(1, report.batchSize)) : 0;
|
|
274
276
|
const counts = view ? aiSeoApplyCounts(view) : {
|
|
275
277
|
pagesWithContent: 0,
|
|
276
278
|
pagesWithValues: 0
|
|
277
279
|
};
|
|
278
280
|
const somethingToApply = counts.pagesWithContent + counts.pagesWithValues + siteFields.length > 0;
|
|
279
|
-
|
|
280
|
-
const
|
|
281
|
+
// The pages a fix was proposed for, or is still owed to; the check above lists the rest.
|
|
282
|
+
const fixRows = report ? report.pages.filter((entry)=>(view == null ? void 0 : view.fixes[entry.screenId]) || report.queue.includes(entry.screenId)) : [];
|
|
283
|
+
const pageRows = fixRows.slice(page * pageSize, (page + 1) * pageSize);
|
|
284
|
+
const names = new Map(((_ref4 = report == null ? void 0 : report.pages) != null ? _ref4 : []).map((entry)=>[
|
|
281
285
|
entry.screenId,
|
|
282
286
|
entry
|
|
283
287
|
]));
|
|
@@ -285,10 +289,10 @@ export function AiSeoAuditCard(props) {
|
|
|
285
289
|
return /*#__PURE__*/ _jsx(CardDisplay, {
|
|
286
290
|
contentGutterX: true,
|
|
287
291
|
contentGutterY: true,
|
|
288
|
-
header: "SEO
|
|
292
|
+
header: "SEO fixes",
|
|
289
293
|
help: pluginDocsHelp('aiSeo', {
|
|
290
|
-
anchor: '#
|
|
291
|
-
excerpt: '
|
|
294
|
+
anchor: '#fix-what-the-seo-check-finds',
|
|
295
|
+
excerpt: 'Get a proposed fix for each finding of the SEO check. Nothing changes on your live site until you save or publish.'
|
|
292
296
|
}),
|
|
293
297
|
children: /*#__PURE__*/ _jsxs(Stack, {
|
|
294
298
|
spacing: 2,
|
|
@@ -296,18 +300,7 @@ export function AiSeoAuditCard(props) {
|
|
|
296
300
|
/*#__PURE__*/ _jsx(Typography, {
|
|
297
301
|
variant: "body2",
|
|
298
302
|
color: "text.secondary",
|
|
299
|
-
children: '
|
|
300
|
-
}),
|
|
301
|
-
/*#__PURE__*/ _jsx(TextField, {
|
|
302
|
-
multiline: true,
|
|
303
|
-
minRows: 2,
|
|
304
|
-
fullWidth: true,
|
|
305
|
-
label: "Target keywords by page (optional)",
|
|
306
|
-
placeholder: '/pricing: pricing, plans\n/lamps: brass desk lamps',
|
|
307
|
-
helperText: "One line per page. A keyword is used only where the page is about it.",
|
|
308
|
-
value: keywords,
|
|
309
|
-
onChange: (event)=>setKeywords(event.target.value.slice(0, KEYWORDS_MAX_CHARS)),
|
|
310
|
-
disabled: busy || running
|
|
303
|
+
children: keywords ? 'Proposes a fix for each finding of the SEO check above, using the target keywords it was run with. Nothing changes on your live site until you save or publish it.' : 'Proposes a fix for each finding of the SEO check above. Nothing changes on your live site until you save or publish it.'
|
|
311
304
|
}),
|
|
312
305
|
/*#__PURE__*/ _jsxs(Stack, {
|
|
313
306
|
direction: "row",
|
|
@@ -320,16 +313,16 @@ export function AiSeoAuditCard(props) {
|
|
|
320
313
|
variant: "contained",
|
|
321
314
|
disabled: busy || running || !orgId,
|
|
322
315
|
onClick: ()=>void run(),
|
|
323
|
-
children: report ? '
|
|
316
|
+
children: report ? 'Propose fixes again' : 'Propose fixes'
|
|
324
317
|
}),
|
|
325
318
|
running ? /*#__PURE__*/ _jsx(CircularProgress, {
|
|
326
319
|
size: 18,
|
|
327
|
-
"aria-label": "
|
|
320
|
+
"aria-label": "Proposing fixes"
|
|
328
321
|
}) : null,
|
|
329
322
|
running && report ? /*#__PURE__*/ _jsx(Typography, {
|
|
330
323
|
variant: "caption",
|
|
331
324
|
color: "text.secondary",
|
|
332
|
-
children: `Proposing fixes: ${(
|
|
325
|
+
children: `Proposing fixes: ${(_ref5 = view == null ? void 0 : view.batches) != null ? _ref5 : 0} of ${owedBatches} batches`
|
|
333
326
|
}) : null
|
|
334
327
|
]
|
|
335
328
|
}),
|
|
@@ -343,28 +336,13 @@ export function AiSeoAuditCard(props) {
|
|
|
343
336
|
}) : null,
|
|
344
337
|
report && job ? /*#__PURE__*/ _jsxs(Stack, {
|
|
345
338
|
spacing: 2,
|
|
346
|
-
"aria-label": "SEO
|
|
339
|
+
"aria-label": "SEO fixes",
|
|
347
340
|
children: [
|
|
348
|
-
/*#__PURE__*/ _jsx(Typography, {
|
|
349
|
-
variant: "subtitle1",
|
|
350
|
-
children: `Score ${report.score} of 100 · ${report.pages.length} ${report.pages.length === 1 ? 'page' : 'pages'} · ${findings} ${findings === 1 ? 'finding' : 'findings'}`
|
|
351
|
-
}),
|
|
352
341
|
job.creditsSpent > 0 ? /*#__PURE__*/ _jsx(Typography, {
|
|
353
342
|
variant: "caption",
|
|
354
343
|
color: "text.secondary",
|
|
355
|
-
children: `
|
|
356
|
-
}) : null,
|
|
357
|
-
report.skipped > 0 ? /*#__PURE__*/ _jsx(Alert, {
|
|
358
|
-
severity: "info",
|
|
359
|
-
children: `${report.skipped} more published ${report.skipped === 1 ? 'page was' : 'pages were'} not audited this time.`
|
|
344
|
+
children: `These fixes used ${job.creditsSpent} ${job.creditsSpent === 1 ? 'credit' : 'credits'}.`
|
|
360
345
|
}) : null,
|
|
361
|
-
[
|
|
362
|
-
...report.site.map((entry)=>entry.message),
|
|
363
|
-
...report.notes
|
|
364
|
-
].map((line)=>/*#__PURE__*/ _jsx(Typography, {
|
|
365
|
-
variant: "body2",
|
|
366
|
-
children: line
|
|
367
|
-
}, line)),
|
|
368
346
|
(view == null ? void 0 : view.site) ? /*#__PURE__*/ _jsxs(Stack, {
|
|
369
347
|
spacing: 1,
|
|
370
348
|
"aria-label": "Structured data and agent guidance",
|
|
@@ -441,11 +419,11 @@ export function AiSeoAuditCard(props) {
|
|
|
441
419
|
}) : null
|
|
442
420
|
]
|
|
443
421
|
}) : null,
|
|
444
|
-
|
|
422
|
+
fixRows.length ? /*#__PURE__*/ _jsxs(Box, {
|
|
445
423
|
children: [
|
|
446
424
|
/*#__PURE__*/ _jsxs(ScrollTable, {
|
|
447
425
|
size: "small",
|
|
448
|
-
"aria-label": "
|
|
426
|
+
"aria-label": "Proposed fixes",
|
|
449
427
|
children: [
|
|
450
428
|
/*#__PURE__*/ _jsx(TableHead, {
|
|
451
429
|
children: /*#__PURE__*/ _jsxs(TableRow, {
|
|
@@ -453,13 +431,6 @@ export function AiSeoAuditCard(props) {
|
|
|
453
431
|
/*#__PURE__*/ _jsx(TableCell, {
|
|
454
432
|
children: 'Page'
|
|
455
433
|
}),
|
|
456
|
-
/*#__PURE__*/ _jsx(TableCell, {
|
|
457
|
-
align: "right",
|
|
458
|
-
children: 'Score'
|
|
459
|
-
}),
|
|
460
|
-
/*#__PURE__*/ _jsx(TableCell, {
|
|
461
|
-
children: 'Found'
|
|
462
|
-
}),
|
|
463
434
|
/*#__PURE__*/ _jsx(TableCell, {
|
|
464
435
|
children: 'Proposed'
|
|
465
436
|
})
|
|
@@ -482,41 +453,13 @@ export function AiSeoAuditCard(props) {
|
|
|
482
453
|
})
|
|
483
454
|
]
|
|
484
455
|
}),
|
|
485
|
-
/*#__PURE__*/ _jsx(TableCell, {
|
|
486
|
-
align: "right",
|
|
487
|
-
children: row.score
|
|
488
|
-
}),
|
|
489
|
-
/*#__PURE__*/ _jsx(TableCell, {
|
|
490
|
-
children: /*#__PURE__*/ _jsx(Stack, {
|
|
491
|
-
direction: "row",
|
|
492
|
-
spacing: 0.5,
|
|
493
|
-
sx: {
|
|
494
|
-
flexWrap: 'wrap',
|
|
495
|
-
rowGap: 0.5
|
|
496
|
-
},
|
|
497
|
-
children: row.findings.length ? row.findings.map((entry)=>{
|
|
498
|
-
var _entry_keyword;
|
|
499
|
-
return /*#__PURE__*/ _jsx(Chip, {
|
|
500
|
-
size: "small",
|
|
501
|
-
variant: "outlined",
|
|
502
|
-
color: entry.severity === 'high' ? 'error' : entry.severity === 'medium' ? 'warning' : 'default',
|
|
503
|
-
label: entry.keyword ? `${AI_SEO_FINDING_LABELS[entry.code]}: ${entry.keyword}` : AI_SEO_FINDING_LABELS[entry.code],
|
|
504
|
-
title: entry.message
|
|
505
|
-
}, `${entry.code}:${(_entry_keyword = entry.keyword) != null ? _entry_keyword : ''}`);
|
|
506
|
-
}) : /*#__PURE__*/ _jsx(Typography, {
|
|
507
|
-
variant: "caption",
|
|
508
|
-
color: "text.secondary",
|
|
509
|
-
children: 'Nothing found'
|
|
510
|
-
})
|
|
511
|
-
})
|
|
512
|
-
}),
|
|
513
456
|
/*#__PURE__*/ _jsx(TableCell, {
|
|
514
457
|
children: /*#__PURE__*/ _jsx(Typography, {
|
|
515
458
|
variant: "body2",
|
|
516
459
|
sx: {
|
|
517
460
|
wordBreak: 'break-word'
|
|
518
461
|
},
|
|
519
|
-
children: fixSummary(view == null ? void 0 : view.fixes[row.screenId]) || (
|
|
462
|
+
children: fixSummary(view == null ? void 0 : view.fixes[row.screenId]) || (running ? 'Being proposed…' : '')
|
|
520
463
|
})
|
|
521
464
|
})
|
|
522
465
|
]
|
|
@@ -528,7 +471,7 @@ export function AiSeoAuditCard(props) {
|
|
|
528
471
|
page: page,
|
|
529
472
|
pageSize: pageSize,
|
|
530
473
|
rowCount: pageRows.length,
|
|
531
|
-
count:
|
|
474
|
+
count: fixRows.length,
|
|
532
475
|
onPageChange: setPage,
|
|
533
476
|
onPageSizeChange: (size)=>{
|
|
534
477
|
setPageSize(size);
|
|
@@ -538,7 +481,7 @@ export function AiSeoAuditCard(props) {
|
|
|
538
481
|
]
|
|
539
482
|
}) : /*#__PURE__*/ _jsx(Typography, {
|
|
540
483
|
variant: "body2",
|
|
541
|
-
children: 'This site has no published public pages to
|
|
484
|
+
children: report.pages.length ? 'No page needs a written fix.' : 'This site has no published public pages to fix.'
|
|
542
485
|
}),
|
|
543
486
|
/*#__PURE__*/ _jsxs(Stack, {
|
|
544
487
|
spacing: 1,
|