@aglyn/plugins-ai 1.5.0 → 1.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/README.md +2 -2
  2. package/package.json +17 -17
  3. package/src/lib/components/ai-insight-dialog.component.js +14 -0
  4. package/src/lib/components/ai-insight-dialog.component.js.map +1 -1
  5. package/src/lib/components/ai-seo-audit-card.component.d.ts +7 -0
  6. package/src/lib/components/ai-seo-audit-card.component.js +32 -4
  7. package/src/lib/components/ai-seo-audit-card.component.js.map +1 -1
  8. package/src/lib/insights/ai-figure-readers.d.ts +13 -0
  9. package/src/lib/insights/ai-figure-readers.js +158 -11
  10. package/src/lib/insights/ai-figure-readers.js.map +1 -1
  11. package/src/lib/insights/ai-figure-summaries.js +4 -2
  12. package/src/lib/insights/ai-figure-summaries.js.map +1 -1
  13. package/src/lib/insights/ai-insight-digest.d.ts +27 -17
  14. package/src/lib/insights/ai-insight-digest.js +96 -107
  15. package/src/lib/insights/ai-insight-digest.js.map +1 -1
  16. package/src/lib/jobs/ai-job-insight-budget.d.ts +19 -3
  17. package/src/lib/jobs/ai-job-insight-budget.js +18 -4
  18. package/src/lib/jobs/ai-job-insight-budget.js.map +1 -1
  19. package/src/lib/jobs/ai-job-insight-step.d.ts +2 -2
  20. package/src/lib/jobs/ai-job-insight-step.js +17 -7
  21. package/src/lib/jobs/ai-job-insight-step.js.map +1 -1
  22. package/src/lib/jobs/ai-job-seo-step.d.ts +4 -0
  23. package/src/lib/jobs/ai-job-seo-step.js +9 -4
  24. package/src/lib/jobs/ai-job-seo-step.js.map +1 -1
  25. package/src/lib/jobs/ai-job-settings-step.d.ts +6 -2
  26. package/src/lib/jobs/ai-job-settings-step.js +45 -6
  27. package/src/lib/jobs/ai-job-settings-step.js.map +1 -1
  28. package/src/lib/jobs/ai-site-publish.js +1 -1
  29. package/src/lib/jobs/ai-site-publish.js.map +1 -1
  30. package/src/lib/model/ai-insight.d.ts +23 -3
  31. package/src/lib/model/ai-insight.js +17 -3
  32. package/src/lib/model/ai-insight.js.map +1 -1
  33. package/src/lib/model/ai-site-entity.d.ts +4 -4
  34. package/src/lib/model/ai-site-entity.js +3 -3
  35. package/src/lib/model/ai-site-entity.js.map +1 -1
  36. package/src/lib/providers/routing.js +3 -1
  37. package/src/lib/providers/routing.js.map +1 -1
  38. package/src/lib/runtime/ai-insight-check.d.ts +7 -0
  39. package/src/lib/runtime/ai-insight-check.js +111 -27
  40. package/src/lib/runtime/ai-insight-check.js.map +1 -1
  41. package/src/lib/tools/ai-insight-tool.js +45 -2
  42. package/src/lib/tools/ai-insight-tool.js.map +1 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/jobs/ai-job-seo-step.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { hostCollectionKind } from '@aglyn/aglyn/app-utils/collection-kind'\nimport { hostPublicOrigin } from '@aglyn/aglyn/app-utils/host-naming'\nimport {\n buildLlmsTxt,\n type LlmsTxtCollection,\n type LlmsTxtPage,\n} from '@aglyn/aglyn/app-utils/llms-txt'\nimport { screenRoutePathToUrl } from '@aglyn/aglyn/app-utils/screen-route'\nimport { SEO_FINDING_LABELS } from '@aglyn/aglyn/app-utils/seo-audit'\nimport {\n SEO_MAX_KEYWORDS,\n seoKeywordCoverage,\n seoKeywordSplit,\n seoQuotedKeywords,\n} from '@aglyn/aglyn/app-utils/seo-keywords'\nimport {\n SCREEN_SEO_LISTING_FIELDS,\n isSeoListingFieldKey,\n type SeoListingFieldKey,\n} from '@aglyn/aglyn/app-utils/seo-listing-fields'\nimport {\n SEO_PAGE_TEXT_MAX_CHARS,\n seoPageFacts,\n type SeoPageFacts,\n} from '@aglyn/aglyn/app-utils/seo-page-facts'\nimport {\n composeSeoPages,\n scanSeoSite,\n seoAuditSiteOf,\n type SeoRepeatRowsReader,\n type SeoSiteScan,\n} from '@aglyn/aglyn/app-utils/seo-site-scan'\n// By path, never through a barrel: only a server composition asks it.\nimport { readRepeatRows } from '@aglyn/aglyn/plugin-manager/repeat-rows'\nimport { decodeStoredNodes } from '@aglyn/aglyn/app-utils/stored-nodes'\nimport { getTemplateScreenIds } from '@aglyn/tenant-runtime/template-screens'\nimport type { AiJob, AiJobOutput } from '../model/ai-jobs.types'\nimport {\n AI_SEO_OUTPUT_IDS,\n aiSeoAuditView,\n aiSeoJobTarget,\n type AiSeoAuditReport,\n type AiSeoContentFix,\n type AiSeoFieldsProposal,\n type AiSeoFieldValues,\n type AiSeoPageFix,\n type AiSeoSiteFormField,\n type AiSeoSiteProposal,\n} from '../model/ai-seo'\nimport { aiModelForStep, aiRouteSettings } from '../providers/routing'\nimport type { AiSystemBlock, AiUsage } from '../runtime/ai-runtime'\nimport { aiSeoAudit, aiSeoAuditBatches, aiSeoHeadingDemotions } from '../runtime/seo-audit'\nimport {\n runValidatedGeneration,\n type AiGenerationSpend,\n type AiValidatedGeneration,\n} from '../runtime/ai-doctrine'\nimport { AI_SEO_FIELDS_MAX_TOKENS, aiFitSeoOverrun, generateSeoFields } from '../runtime/seo-fields'\nimport {\n AI_SEO_FIXES_TOOL_NAME,\n AI_SEO_SITE_TOOL_NAME,\n aiSeoFixImages,\n aiSeoFixesTool,\n aiSeoSiteTool,\n checkAiSeoFixes,\n checkAiSeoSite,\n fitAiSeoFixLengths,\n type AiSeoBatchAnswer,\n type AiSeoBatchPage,\n} from '../tools/ai-seo-tool'\nimport {\n AI_SEO_FIXES_MAX_TOKENS,\n AI_SEO_SITE_MAX_TOKENS,\n aiSeoGenerationMaxTokens,\n} from './ai-job-seo-budget'\nimport { aiCacheWriteHourSum } from '../providers/cache-write-hour'\nimport type { AiJobStepContext, AiJobStepOutcome, AiJobStepRunner } from './ai-job-text-step'\n\n/**\n * The `seo` step (AGL-2910): search listings and a site audit, as proposals.\n *\n * `inputs.target` says what the job is about:\n *\n * - `screen` — one page's listing, written from the version the person is\n * looking at (`screenId`, `versionId`), for the page's SEO card;\n * - `product` — one product's listing, from the name and description the\n * product editor handed over (`name`, `text`), for the product editor;\n * - `site` — the audit of every published page the sitemap lists, with a\n * proposed fix per finding, structured data for the site's entity, and the\n * agent guidance `/llms.txt` leads with.\n *\n * ## It writes nothing\n *\n * Like every runner, this reads, asks and returns. A listing is served\n * straight from the screen document, the structured data and `/llms.txt`\n * from the host document, and a page's content from its published version,\n * so the values ride on the job's outputs and nothing else: a person puts\n * them in the page's SEO card or the site SEO form and saves them there, and\n * content fixes become a new version only through the apply door.\n *\n * ## An audit, a unit at a time\n *\n * The first pass reads the site — every published page's version and the\n * shared layouts, for the links between them — and scores it without a\n * model, through the platform's SEO check (the same findings the site's SEO\n * section lists to every owner); it records the report, and runs the first unit of generated work. Each later\n * pass runs one more unit: the site-wide proposal, then the page fixes in\n * batches. Every pass is one reservation and one provider exchange, and it\n * asks the machine to continue until nothing is left, so a large site is a\n * few beats of work rather than one request that cannot finish.\n */\n\nexport const AI_SEO_NO_SITE_COPY = 'This SEO job names a site this workspace does not have.'\nexport const AI_SEO_NO_PAGE_COPY = 'This page is no longer on the site.'\nexport const AI_SEO_NO_TARGET_COPY = 'This SEO job does not say what to write about.'\nexport const AI_SEO_NO_PRODUCT_COPY = 'Give the product a name before writing its listing.'\n\n/** How much of each page a batch of fixes carries. */\nexport const AI_SEO_BATCH_PAGE_TEXT_CHARS = 700\n\n/**\n * Output budgets, declared with the step's time (`ai-job-seo-budget.ts`,\n * AGL-3035). A batch's largest answer — every page with a title, description,\n * heading and image descriptions at their limits — and the site proposal's are\n * measured in `ai-job-seo-step.spec.ts`.\n */\nexport { AI_SEO_FIXES_MAX_TOKENS, AI_SEO_SITE_MAX_TOKENS }\n\n/** Pages the site prompt and the llms.txt preview list. */\nconst SITE_PAGES_LISTED = 25\n\n/** The fields a product's listing holds. */\nconst PRODUCT_LISTING_FIELDS: readonly SeoListingFieldKey[] = ['title', 'description']\n\nconst ZERO_USAGE: AiUsage = {\n inputTokens: 0,\n outputTokens: 0,\n cacheReadTokens: 0,\n cacheWriteTokens: 0,\n}\n\ntype Firestore = FirebaseFirestore.Firestore\ntype DocumentReference = FirebaseFirestore.DocumentReference\ntype Spent = Pick<AiJobStepOutcome, 'usage' | 'estCostUsd' | 'model' | 'stopReason'>\n\n/** The host document fields this step reads. */\nexport interface SeoHostDocument {\n orgId?: string\n displayName?: string\n subdomain?: string | null\n cname?: string | null\n screens?: Record<string, string>\n errorScreens?: Record<string, string>\n notFoundScreenId?: string | null\n seo?: {\n title?: string\n description?: string\n discourageSearchEngines?: boolean\n entity?: {\n type?: unknown\n name?: string\n description?: string\n email?: string\n telephone?: string\n contactType?: string\n }\n agent?: { whenToUse?: string; howToUse?: string }\n }\n}\n\n/** The screen document fields this step reads. */\ninterface SeoScreenDocument {\n displayName?: string\n description?: string\n versionId?: string\n visibility?: unknown\n deletedAt?: unknown\n seo?: {\n title?: string\n description?: string\n breadcrumb?: string\n image?: string\n imageAlt?: string\n }\n}\n\nconst str = (value: unknown): string => (typeof value === 'string' ? value.trim() : '')\n\nconst round6 = (value: number): number => Math.round(value * 1_000_000) / 1_000_000\n\nfunction modelOf(context: AiJobStepContext): string {\n return context.modelFor?.('job.seo') ?? aiModelForStep('job.seo')\n}\n\nfunction spentNothing(model: string): Spent {\n return { usage: ZERO_USAGE, estCostUsd: 0, model, stopReason: null }\n}\n\nfunction spentBy(generation: AiGenerationSpend): Spent {\n return {\n usage: generation.usage,\n estCostUsd: generation.estCostUsd,\n model: generation.model,\n stopReason: generation.stopReason,\n }\n}\n\nfunction addSpent(a: Spent, b: Spent): Spent {\n return {\n usage: {\n inputTokens: a.usage.inputTokens + b.usage.inputTokens,\n outputTokens: a.usage.outputTokens + b.usage.outputTokens,\n cacheReadTokens: a.usage.cacheReadTokens + b.usage.cacheReadTokens,\n cacheWriteTokens: a.usage.cacheWriteTokens + b.usage.cacheWriteTokens,\n ...aiCacheWriteHourSum(a.usage, b.usage),\n },\n estCostUsd: round6(a.estCostUsd + b.estCostUsd),\n model: b.model || a.model,\n stopReason: b.stopReason ?? a.stopReason,\n }\n}\n\n/** Through JSON, so no `undefined` reaches the job document's write. */\nconst plain = <T>(value: T): Record<string, unknown> =>\n JSON.parse(JSON.stringify(value)) as Record<string, unknown>\n\n/**\n * The fields a listing job writes: the ones the editor named (`inputs.fields`,\n * comma-separated) that the target's editor holds, or all of those.\n */\nexport function aiSeoRequestedFields(\n raw: unknown,\n allowed: readonly SeoListingFieldKey[],\n): SeoListingFieldKey[] {\n const named = String(raw ?? '')\n .split(',')\n .map((part) => part.trim())\n .filter(isSeoListingFieldKey)\n const wanted = new Set<SeoListingFieldKey>(named.length ? named : allowed)\n return allowed.filter((key) => wanted.has(key))\n}\n\n/** The site's name, as its visitors read it. */\nfunction brandOf(host: SeoHostDocument): string {\n return str(host.seo?.title) || str(host.displayName) || str(host.subdomain)\n}\n\n/** The site a job names, read and checked against the job's org. */\nasync function loadSite(\n firestore: Firestore,\n job: AiJob,\n): Promise<{ host: SeoHostDocument } | { failure: string }> {\n if (!job.hostId) return { failure: AI_SEO_NO_SITE_COPY }\n const snapshot = await firestore.collection('hosts').doc(job.hostId).get()\n const host = snapshot.exists ? (snapshot.data() as SeoHostDocument) : null\n // The route checks the caller's membership of the org the job is metered\n // against, not that the site belongs to it. A site of another org is\n // refused here, before anything about it reaches a prompt.\n if (!host || host.orgId !== job.orgId) return { failure: AI_SEO_NO_SITE_COPY }\n return { host }\n}\n\n/** The rows a site's repeats render, through the platform's repeat-rows contract. */\nconst siteRepeatRows =\n (hostId: string): SeoRepeatRowsReader =>\n (keys) =>\n readRepeatRows({ hostId, keys })\n\n/**\n * Pages' facts as the SEO check reads them (AGL-3501): each version composed\n * as it publishes — components grafted, repeats expanded — and read against\n * the page's own map, so a fix is only ever offered for what the page holds.\n */\nasync function composedPageFacts(\n firestore: Firestore,\n hostId: string,\n versions: readonly ({ nodes: Record<string, unknown>; rootId?: string } | null)[],\n): Promise<SeoPageFacts[]> {\n const { composed } = await composeSeoPages(\n firestore,\n hostId,\n versions.map((version) => version?.nodes ?? null),\n { readRepeatRows: siteRepeatRows(hostId) },\n )\n return versions.map((version, index) =>\n seoPageFacts(composed[index] as never, { rootId: version?.rootId, pageNodes: version?.nodes as never }),\n )\n}\n\n/** A version's node map and root, or `null` when it cannot be read. */\nasync function readVersionNodes(\n hostRef: DocumentReference,\n screenId: string,\n versionId: string,\n): Promise<{ nodes: Record<string, unknown>; rootId?: string } | null> {\n if (!versionId) return null\n const snapshot = await hostRef\n .collection('screens')\n .doc(screenId)\n .collection('versions')\n .doc(versionId)\n .get()\n if (!snapshot.exists) return null\n const nodes = decodeStoredNodes<Record<string, unknown>>(snapshot.get('nodes'))\n if (!nodes) return null\n const rootId = snapshot.get('rootId')\n return { nodes, ...(typeof rootId === 'string' ? { rootId } : {}) }\n}\n\n/** Every other page's search title, for a proposal not to repeat. */\nasync function siteTitles(hostRef: DocumentReference, except: ReadonlySet<string>): Promise<string[]> {\n const snapshot = await hostRef.collection('screens').select('seo', 'deletedAt').limit(1000).get()\n return snapshot.docs\n .filter((doc) => !except.has(doc.id) && !doc.get('deletedAt'))\n .map((doc) => str((doc.get('seo') as SeoScreenDocument['seo'])?.title))\n .filter(Boolean)\n}\n\n/* ------------------------------------------------------------------------ *\n * One listing: a page or a product\n * ------------------------------------------------------------------------ */\n\nfunction listingOutcome(\n generation: AiValidatedGeneration<AiSeoFieldValues>,\n job: AiJob,\n subject: AiSeoFieldsProposal['subject'],\n context: {\n keywords: readonly string[]\n /** Keywords past the limit, which the proposal did not aim for. */\n unchecked: readonly string[]\n facts: SeoPageFacts | null\n fields: readonly SeoListingFieldKey[]\n hasImage: boolean\n },\n): AiJobStepOutcome {\n const spent = spentBy(generation)\n if (generation.status === 'refused') return { outputs: [], ...spent, refused: true }\n if (generation.status === 'needs_input') return { outputs: [], ...spent, failure: generation.message }\n const values = generation.value\n const notes: string[] = []\n if (context.fields.includes('imageAlt') && context.hasImage && !values.imageAlt) {\n notes.push('No image description was proposed: nothing on the page says what the picture shows.')\n }\n if (context.unchecked.length) {\n notes.push(\n `Only the first ${SEO_MAX_KEYWORDS} keywords were used, so ${seoQuotedKeywords(context.unchecked)} ${context.unchecked.length === 1 ? 'was' : 'were'} not.`,\n )\n }\n const proposal: AiSeoFieldsProposal = {\n kind: 'fields',\n subject,\n values,\n keywords: seoKeywordCoverage(context.keywords, {\n title: values.title,\n description: values.description,\n h1: context.facts?.h1s[0]?.text,\n body: context.facts?.text,\n }),\n notes,\n }\n const output: AiJobOutput = {\n resource: 'seo',\n id: AI_SEO_OUTPUT_IDS.fields(subject.kind, subject.id),\n hostId: job.hostId ?? null,\n label: `SEO proposal · ${subject.name}`,\n proposal: plain(proposal),\n }\n return { outputs: [output], ...spent }\n}\n\nasync function runScreenListing(\n context: AiJobStepContext & { firestore: Firestore },\n host: SeoHostDocument,\n): Promise<AiJobStepOutcome> {\n const { job, firestore, signal } = context\n const model = modelOf(context)\n const hostRef = firestore.collection('hosts').doc(job.hostId as string)\n const screenId = str(job.inputs?.['screenId'])\n const snapshot = screenId ? await hostRef.collection('screens').doc(screenId).get() : null\n const screen = snapshot?.exists ? (snapshot.data() as SeoScreenDocument) : null\n if (!screen || screen.deletedAt) {\n return { outputs: [], ...spentNothing(model), failure: AI_SEO_NO_PAGE_COPY }\n }\n\n const versionId = str(job.inputs?.['versionId']) || str(screen.versionId)\n const version = await readVersionNodes(hostRef, screenId, versionId)\n const [facts] = await composedPageFacts(firestore, job.hostId as string, [version])\n const fields = aiSeoRequestedFields(job.inputs?.['fields'], SCREEN_SEO_LISTING_FIELDS)\n const seo = screen.seo ?? {}\n const hasImage = Boolean(str(seo.image))\n // The share image is often a picture the page shows too: its description\n // and the text beside it there are what is known about it.\n const onPage = hasImage ? facts.images.find((image) => image.src === str(seo.image)) : undefined\n const route = host.screens?.[screenId]\n const path = typeof route === 'string' ? screenRoutePathToUrl(route) : null\n const name = str(screen.displayName) || path || 'Untitled page'\n const { keywords, unchecked } = seoKeywordSplit(job.inputs?.['keywords'])\n const generation = await generateSeoFields({\n subject: { kind: 'screen', name, path },\n brand: brandOf(host),\n text: facts.text || str(screen.description),\n fields,\n current: {\n title: str(seo.title),\n description: str(seo.description),\n breadcrumb: str(seo.breadcrumb),\n imageAlt: str(seo.imageAlt),\n },\n image: hasImage ? { alt: str(seo.imageAlt) || onPage?.alt || null, context: onPage?.context || null } : null,\n keywords,\n otherTitles: await siteTitles(hostRef, new Set([screenId])),\n model,\n maxTokens: aiSeoGenerationMaxTokens(model, AI_SEO_FIELDS_MAX_TOKENS),\n ...(signal ? { signal } : {}),\n })\n return listingOutcome(generation, job, { kind: 'screen', id: screenId, name, path }, {\n keywords,\n unchecked,\n facts,\n fields,\n hasImage,\n })\n}\n\nasync function runProductListing(\n context: AiJobStepContext & { firestore: Firestore },\n host: SeoHostDocument,\n): Promise<AiJobStepOutcome> {\n const { job, signal } = context\n const model = modelOf(context)\n const name = str(job.inputs?.['name']).slice(0, 200)\n if (!name) return { outputs: [], ...spentNothing(model), failure: AI_SEO_NO_PRODUCT_COPY }\n const fields = aiSeoRequestedFields(job.inputs?.['fields'], PRODUCT_LISTING_FIELDS)\n const { keywords, unchecked } = seoKeywordSplit(job.inputs?.['keywords'])\n const productId = str(job.inputs?.['productId']) || null\n const generation = await generateSeoFields({\n subject: { kind: 'product', name },\n brand: brandOf(host),\n // The product's own words, as its editor handed them over: the product\n // document is the commerce plugin's, and this step never reads it.\n text: str(job.inputs?.['text']).slice(0, SEO_PAGE_TEXT_MAX_CHARS),\n fields,\n current: {\n title: str(job.inputs?.['currentTitle']),\n description: str(job.inputs?.['currentDescription']),\n },\n image: null,\n keywords,\n model,\n maxTokens: aiSeoGenerationMaxTokens(model, AI_SEO_FIELDS_MAX_TOKENS),\n ...(signal ? { signal } : {}),\n })\n return listingOutcome(generation, job, { kind: 'product', id: productId, name }, {\n keywords,\n unchecked,\n facts: null,\n fields,\n hasImage: false,\n })\n}\n\n/* ------------------------------------------------------------------------ *\n * The site audit\n * ------------------------------------------------------------------------ */\n\n/**\n * Read the site for an audit: the platform SEO check's scan\n * (`@aglyn/aglyn/app-utils/seo-site-scan`), which the site's SEO section\n * reads through too, so a job audits exactly the pages the check lists.\n */\nasync function scanSite(\n firestore: Firestore,\n hostId: string,\n host: SeoHostDocument,\n keywords: unknown,\n): Promise<SeoSiteScan> {\n return scanSeoSite(firestore, hostId, host, {\n keywords,\n templateScreenIds: await getTemplateScreenIds({ hostId }),\n readRepeatRows: siteRepeatRows(hostId),\n })\n}\n\n/** One unit of generated work an audit still owes. */\nexport type AiSeoAuditUnit =\n | { kind: 'site' }\n | { kind: 'batch'; batch: number; of: number; screenIds: string[] }\n\n/** The units an audit owes after the outputs recorded so far, in the order they run. */\nexport function aiSeoPendingUnits(\n report: AiSeoAuditReport,\n outputs: readonly Pick<AiJobOutput, 'id'>[],\n): AiSeoAuditUnit[] {\n const done = new Set(outputs.map((output) => output.id))\n const units: AiSeoAuditUnit[] = []\n if (report.siteProposal && !done.has(AI_SEO_OUTPUT_IDS.site)) units.push({ kind: 'site' })\n const batches = aiSeoAuditBatches(report)\n batches.forEach((screenIds, index) => {\n if (!done.has(AI_SEO_OUTPUT_IDS.fixes(index + 1))) {\n units.push({ kind: 'batch', batch: index + 1, of: batches.length, screenIds })\n }\n })\n return units\n}\n\ninterface UnitResult {\n output: AiJobOutput\n spent: Spent\n}\n\n/* ---- The site-wide proposal ---------------------------------------------- */\n\nexport const AI_SEO_SITE_INSTRUCTIONS: AiSystemBlock[] = [\n {\n text:\n 'You propose two things for a website: the structured data that says who publishes it, and ' +\n 'the guidance an AI agent reads first in its /llms.txt.\\n\\n' +\n `Answer by calling ${AI_SEO_SITE_TOOL_NAME} exactly once. A reply in prose cannot be used.\\n\\n` +\n 'Rules:\\n' +\n '- Fill only the fields you are told are empty; answer null for every other one.\\n' +\n '- Use only what the pages you are given state. A contact email or telephone number goes in ' +\n 'only when a page shows it exactly; never compose one.\\n' +\n '- The entity description says what the publisher is, in one plain sentence, not what one page ' +\n 'offers.\\n' +\n '- The agent guidance is checkable and specific: the questions this site answers and which ' +\n 'pages answer them. No marketing language: an agent discounts a claim it cannot check.\\n' +\n '- Keep every length the tool states, and write in the language of the pages.',\n cacheBreakpoint: true,\n },\n]\n\n/** The site SEO form fields blank on the site now. */\nexport function aiSeoBlankSiteFields(host: SeoHostDocument): Set<AiSeoSiteFormField> {\n const entity = host.seo?.entity ?? {}\n const agent = host.seo?.agent ?? {}\n const blank = new Set<AiSeoSiteFormField>()\n if (entity.type === undefined || entity.type === null || entity.type === '') blank.add('seo.entity.type')\n if (!str(entity.name)) blank.add('seo.entity.name')\n if (!str(entity.description)) blank.add('seo.entity.description')\n if (!str(entity.email)) blank.add('seo.entity.email')\n if (!str(entity.telephone)) blank.add('seo.entity.telephone')\n if (!str(entity.contactType)) blank.add('seo.entity.contactType')\n if (!str(agent.whenToUse)) blank.add('seo.agent.whenToUse')\n if (!str(agent.howToUse)) blank.add('seo.agent.howToUse')\n return blank\n}\n\n/** The site's content collections, for the llms.txt preview. */\nasync function readContentCollections(hostRef: DocumentReference): Promise<LlmsTxtCollection[]> {\n try {\n const snapshot = await hostRef.collection('collections').select('slug', 'displayName', 'kind').limit(50).get()\n return snapshot.docs\n .filter((doc) => hostCollectionKind(doc.data()) === 'content' && str(doc.get('slug')))\n .map((doc) => ({ slug: str(doc.get('slug')), name: str(doc.get('displayName')) || undefined }))\n } catch {\n // A preview without the feeds is still a preview of the guidance.\n return []\n }\n}\n\n/** `/llms.txt` as it reads with `values` saved over what the site stores now. */\nexport function aiSeoLlmsPreview(\n host: SeoHostDocument,\n values: Partial<Record<AiSeoSiteFormField, string>>,\n pages: readonly LlmsTxtPage[],\n collections: readonly LlmsTxtCollection[],\n): string {\n return buildLlmsTxt({\n siteName: str(host.seo?.title) || str(host.displayName) || 'Site',\n origin: hostPublicOrigin(host) ?? '',\n description: str(host.seo?.description) || undefined,\n agent: {\n whenToUse: values['seo.agent.whenToUse'] ?? host.seo?.agent?.whenToUse,\n howToUse: values['seo.agent.howToUse'] ?? host.seo?.agent?.howToUse,\n },\n pages,\n collections,\n hasSearch: true,\n contactEmail: values['seo.entity.email'] ?? (str(host.seo?.entity?.email) || undefined),\n })\n}\n\nasync function proposeSite(\n context: AiJobStepContext & { firestore: Firestore },\n host: SeoHostDocument,\n scan: SeoSiteScan,\n): Promise<UnitResult> {\n const { job, firestore, signal } = context\n const model = modelOf(context)\n const hostRef = firestore.collection('hosts').doc(job.hostId as string)\n const blank = aiSeoBlankSiteFields(host)\n const collections = await readContentCollections(hostRef)\n const topLevel: LlmsTxtPage[] = scan.pages\n .filter((page) => !page.path.replace(/^\\//, '').includes('/'))\n .slice(0, SITE_PAGES_LISTED)\n .map((page) => ({ path: page.path, ...(page.name ? { title: page.name } : {}) }))\n // The pages that say who publishes a site: the home page, and whatever is\n // about the company or how to reach it.\n const telling = scan.pages\n .filter((page) => page.path === '/' || /about|contact|company|team|who/i.test(page.path))\n .slice(0, 4)\n const prompt = [\n `Site: ${brandOf(host) || 'untitled site'}`,\n host.seo?.description ? `Site description: ${str(host.seo.description)}` : '',\n `Empty fields you may fill: ${[...blank].join(', ') || 'none'}`,\n 'Pages:',\n ...scan.pages\n .slice(0, SITE_PAGES_LISTED)\n .map((page) => `- ${page.path} — ${page.name}${str(page.seo.title) ? ` — ${str(page.seo.title)}` : ''}`),\n collections.length\n ? `Content collections: ${collections.map((entry) => entry.name || entry.slug).join(', ')}`\n : '',\n ...telling.flatMap((page) => ['', `Text of ${page.path}:`, page.facts.text.slice(0, 1_200) || '(no text)']),\n ]\n .filter((line) => line !== '')\n .join('\\n')\n const siteText = scan.pages.map((page) => page.facts.text).join('\\n')\n const generation = await runValidatedGeneration('seo-site', {\n step: 'job.seo',\n ...aiRouteSettings('job.seo'),\n model,\n instructions: AI_SEO_SITE_INSTRUCTIONS,\n messages: [{ role: 'user', content: prompt }],\n tool: aiSeoSiteTool(),\n maxTokens: aiSeoGenerationMaxTokens(model, AI_SEO_SITE_MAX_TOKENS),\n ...(signal ? { signal } : {}),\n check: (answer) => checkAiSeoSite(answer, { blank, siteText }),\n })\n const proposed = generation.status === 'ok' ? generation.value : { values: {}, notes: [] }\n const notes =\n generation.status === 'ok'\n ? proposed.notes\n : [\n generation.status === 'refused'\n ? 'The AI declined to propose structured data for this site.'\n : generation.message,\n ]\n const site: AiSeoSiteProposal = {\n values: proposed.values,\n llmsPreview: aiSeoLlmsPreview(host, proposed.values, topLevel, collections),\n notes,\n }\n return {\n output: {\n resource: 'seo',\n id: AI_SEO_OUTPUT_IDS.site,\n hostId: job.hostId ?? null,\n label: 'SEO audit · structured data and agent guidance',\n proposal: plain({ kind: 'site', site }),\n },\n spent: spentBy(generation),\n }\n}\n\n/* ---- A batch of page fixes ------------------------------------------------ */\n\nexport const AI_SEO_FIXES_INSTRUCTIONS: AiSystemBlock[] = [\n {\n text:\n 'You fix the search listings and headings of a website’s pages. For each page you are given ' +\n 'what an audit found, what the page shows now, and its text.\\n\\n' +\n `Answer by calling ${AI_SEO_FIXES_TOOL_NAME} exactly once, with one entry per page. A reply in ` +\n 'prose cannot be used.\\n\\n' +\n 'Rules:\\n' +\n '- Fix only what the audit found. Answer null for a value it did not find a problem with.\\n' +\n '- Write only from the page’s own text. Never invent a fact, a price, a name, a place or a claim.\\n' +\n '- A title says what the page is, specifically. No two pages share a title, and none repeats a ' +\n 'title you are told another page uses.\\n' +\n '- A description is one or two sentences telling a searcher what they will find.\\n' +\n '- The main heading names what the page is about in a few plain words.\\n' +\n '- An image description says what the picture most likely shows, from the text beside it. ' +\n 'Leave an image out when the text gives no idea.\\n' +\n '- A target keyword goes in only where the page is about it and it reads naturally: at most ' +\n 'once in a title and once in a description. Never list keywords or repeat a word to rank.\\n' +\n '- Keep every length the tool states, and write in the language of each page.',\n cacheBreakpoint: true,\n },\n]\n\n/** The fixes one page gets: the model's values, its content fixes, and the guidance no fix can give. */\nexport function aiSeoPageFixFor(page: AiSeoBatchPage, answer: AiSeoBatchAnswer | null): AiSeoPageFix {\n const values: AiSeoFieldValues = {}\n if (answer?.title) values.title = answer.title\n if (answer?.description) values.description = answer.description\n const content: AiSeoContentFix[] = []\n for (const alt of answer?.imageAlts ?? []) content.push({ kind: 'image-alt', nodeId: alt.nodeId, alt: alt.alt })\n if (answer?.h1) {\n const first = page.facts.h1s[0]\n const promotable = page.facts.headings.find((heading) => heading.editable && heading.nodeId)\n if (page.codes.has('h1-thin') && first?.editable && first.nodeId) {\n content.push({ kind: 'h1-set', nodeId: first.nodeId, text: answer.h1 })\n } else if (page.codes.has('h1-missing') && promotable?.nodeId) {\n content.push({ kind: 'h1-set', nodeId: promotable.nodeId, text: answer.h1 })\n } else if (page.codes.has('h1-missing')) {\n content.push({ kind: 'h1-insert', text: answer.h1 })\n }\n }\n if (page.codes.has('h1-multiple')) content.push(...aiSeoHeadingDemotions(page.facts))\n const guidance: string[] = []\n if (page.codes.has('orphan')) {\n guidance.push('Link to this page from your navigation or a related page. Where it belongs is yours to choose.')\n }\n return { screenId: page.screenId, values, content, guidance }\n}\n\n/** The user turn for one batch: each page's findings, what it shows now, and its text. */\nexport function aiSeoFixesPrompt(pages: readonly AiSeoBatchPage[], titlesElsewhere: readonly string[]): string {\n const titles = titlesElsewhere.length\n ? `Titles other pages use:\\n${titlesElsewhere.slice(0, 40).map((title) => `- ${title}`).join('\\n')}\\n\\n`\n : ''\n const blocks = pages.map((page) => {\n const lines = [\n `### Page ${page.screenId}: ${page.name} (${page.path})`,\n `Found: ${[...page.codes].map((code) => SEO_FINDING_LABELS[code]).join('; ')}`,\n `Title now: ${str(page.seo?.title) || '(none)'}`,\n `Description now: ${str(page.seo?.description) || '(none)'}`,\n `Main heading now: ${page.facts.h1s[0]?.text || '(none)'}`,\n ]\n if (page.keywords.length) lines.push(`Target keywords: ${page.keywords.join(', ')}`)\n const images = aiSeoFixImages(page)\n if (images.length) {\n lines.push(\n 'Images without a description:',\n ...images.map((image) => `- ${image.nodeId}: beside \"${image.context || 'no text'}\"`),\n )\n }\n lines.push('Text:', page.facts.text.slice(0, AI_SEO_BATCH_PAGE_TEXT_CHARS) || '(no text)')\n return lines.join('\\n')\n })\n return `${titles}${blocks.join('\\n\\n')}`\n}\n\nasync function proposeFixes(\n context: AiJobStepContext & { firestore: Firestore },\n report: AiSeoAuditReport,\n unit: Extract<AiSeoAuditUnit, { kind: 'batch' }>,\n): Promise<UnitResult> {\n const { job, firestore, signal } = context\n const model = modelOf(context)\n const hostRef = firestore.collection('hosts').doc(job.hostId as string)\n const reports = new Map(report.pages.map((page) => [page.screenId, page]))\n // Read now, not as audited: a page edited since keeps its edits, and one\n // deleted since is skipped.\n const read = await Promise.all(\n unit.screenIds.map(async (screenId) => {\n const pageReport = reports.get(screenId)\n const snapshot = await hostRef.collection('screens').doc(screenId).get()\n const screen = snapshot.exists ? (snapshot.data() as SeoScreenDocument) : null\n if (!pageReport || !screen || screen.deletedAt) return null\n const version = await readVersionNodes(hostRef, screenId, str(screen.versionId))\n return { screenId, pageReport, screen, version }\n }),\n )\n const live = read.filter((entry): entry is NonNullable<typeof entry> => entry !== null)\n // Read as the audit read them, composed: a heading a component renders is\n // the page's, and is never offered to a fix that would rewrite the page.\n const facts = await composedPageFacts(\n firestore,\n job.hostId as string,\n live.map((entry) => entry.version),\n )\n const pages: AiSeoBatchPage[] = live.map(({ screenId, pageReport, screen }, index) => ({\n screenId,\n path: pageReport.path,\n name: pageReport.name,\n codes: new Set(pageReport.findings.map((entry) => entry.code)),\n keywords: pageReport.keywords.map((entry) => entry.keyword),\n seo: screen.seo ?? {},\n facts: facts[index],\n }))\n const titlesElsewhere = await siteTitles(hostRef, new Set(pages.map((page) => page.screenId)))\n\n let spent = spentNothing(model)\n let answers: Record<string, AiSeoBatchAnswer> = {}\n const notes: string[] = []\n if (pages.length) {\n const check = (answer: Record<string, unknown>) => checkAiSeoFixes(answer, pages, titlesElsewhere)\n const asked = await runValidatedGeneration('seo-fixes', {\n step: 'job.seo',\n ...aiRouteSettings('job.seo'),\n model,\n instructions: AI_SEO_FIXES_INSTRUCTIONS,\n messages: [{ role: 'user', content: aiSeoFixesPrompt(pages, titlesElsewhere) }],\n tool: aiSeoFixesTool(pages.map((page) => page.screenId)),\n // Lowered on a tier too slow to answer a whole batch and ask again\n // inside the least time the step registers.\n maxTokens: aiSeoGenerationMaxTokens(model, AI_SEO_FIXES_MAX_TOKENS),\n ...(signal ? { signal } : {}),\n check,\n })\n // A batch the re-ask still left past a length keeps its fixes, fitted\n // (AGL-4016): one long title used to drop every page's fixes.\n const generation = aiFitSeoOverrun('seo-fixes', asked, fitAiSeoFixLengths, check)\n spent = spentBy(generation)\n if (generation.status === 'ok') {\n answers = generation.value\n } else {\n notes.push(\n generation.status === 'refused'\n ? 'The AI declined to propose fixes for these pages.'\n : generation.message,\n )\n }\n }\n const fixes = pages.map((page) => aiSeoPageFixFor(page, answers[page.screenId] ?? null))\n const skipped = unit.screenIds.length - pages.length\n if (skipped > 0) {\n notes.push(`${skipped} ${skipped === 1 ? 'page was' : 'pages were'} deleted since the audit and left out.`)\n }\n return {\n output: {\n resource: 'seo',\n id: AI_SEO_OUTPUT_IDS.fixes(unit.batch),\n hostId: job.hostId ?? null,\n label: `SEO audit · fixes ${unit.batch} of ${unit.of}`,\n proposal: plain({ kind: 'fixes', batch: unit.batch, fixes, notes }),\n },\n spent,\n }\n}\n\nasync function runSiteAuditPass(\n context: AiJobStepContext & { firestore: Firestore },\n host: SeoHostDocument,\n): Promise<AiJobStepOutcome> {\n const { job, firestore } = context\n const model = modelOf(context)\n const recorded = aiSeoAuditView(job.outputs ?? [])\n const outputs: AiJobOutput[] = []\n let spent = spentNothing(model)\n let report: AiSeoAuditReport\n let scan: SeoSiteScan | null = null\n if (recorded) {\n report = recorded.report\n } else {\n scan = await scanSite(firestore, job.hostId as string, host, job.inputs?.['keywords'])\n report = aiSeoAudit(scan.pages, seoAuditSiteOf(host), { skipped: scan.skipped, notes: scan.notes })\n const findings = report.pages.reduce((sum, page) => sum + page.findings.length, report.site.length)\n outputs.push({\n resource: 'seo',\n id: AI_SEO_OUTPUT_IDS.report,\n hostId: job.hostId ?? null,\n label: `SEO audit · ${report.pages.length} ${report.pages.length === 1 ? 'page' : 'pages'} · ${findings} ${findings === 1 ? 'finding' : 'findings'}`,\n proposal: plain(report),\n })\n }\n const units = aiSeoPendingUnits(report, [...(job.outputs ?? []), ...outputs])\n if (!units.length) return { outputs, ...spent }\n const [unit] = units\n const result =\n unit.kind === 'site'\n ? await proposeSite(\n context,\n host,\n scan ?? (await scanSite(firestore, job.hostId as string, host, job.inputs?.['keywords'])),\n )\n : await proposeFixes(context, report, unit)\n outputs.push(result.output)\n spent = addSpent(spent, result.spent)\n return { outputs, ...spent, ...(units.length > 1 ? { continue: true } : {}) }\n}\n\nexport const runAiJobSeoStep: AiJobStepRunner = async (context) => {\n const { job, firestore } = context\n if (!firestore) {\n // The machine always hands one in; a runner called without it is a\n // wiring fault, not a customer path.\n throw new Error('the SEO step reads the site it writes about and was given no Firestore')\n }\n const target = aiSeoJobTarget(job.inputs)\n if (!target) return { outputs: [], ...spentNothing(modelOf(context)), failure: AI_SEO_NO_TARGET_COPY }\n const site = await loadSite(firestore, job)\n if ('failure' in site) return { outputs: [], ...spentNothing(modelOf(context)), failure: site.failure }\n const withFirestore = { ...context, firestore }\n switch (target) {\n case 'screen':\n return runScreenListing(withFirestore, site.host)\n case 'product':\n return runProductListing(withFirestore, site.host)\n case 'site':\n return runSiteAuditPass(withFirestore, site.host)\n }\n}\n"],"names":["hostCollectionKind","hostPublicOrigin","buildLlmsTxt","screenRoutePathToUrl","SEO_FINDING_LABELS","SEO_MAX_KEYWORDS","seoKeywordCoverage","seoKeywordSplit","seoQuotedKeywords","SCREEN_SEO_LISTING_FIELDS","isSeoListingFieldKey","SEO_PAGE_TEXT_MAX_CHARS","seoPageFacts","composeSeoPages","scanSeoSite","seoAuditSiteOf","readRepeatRows","decodeStoredNodes","getTemplateScreenIds","AI_SEO_OUTPUT_IDS","aiSeoAuditView","aiSeoJobTarget","aiModelForStep","aiRouteSettings","aiSeoAudit","aiSeoAuditBatches","aiSeoHeadingDemotions","runValidatedGeneration","AI_SEO_FIELDS_MAX_TOKENS","aiFitSeoOverrun","generateSeoFields","AI_SEO_FIXES_TOOL_NAME","AI_SEO_SITE_TOOL_NAME","aiSeoFixImages","aiSeoFixesTool","aiSeoSiteTool","checkAiSeoFixes","checkAiSeoSite","fitAiSeoFixLengths","AI_SEO_FIXES_MAX_TOKENS","AI_SEO_SITE_MAX_TOKENS","aiSeoGenerationMaxTokens","aiCacheWriteHourSum","AI_SEO_NO_SITE_COPY","AI_SEO_NO_PAGE_COPY","AI_SEO_NO_TARGET_COPY","AI_SEO_NO_PRODUCT_COPY","AI_SEO_BATCH_PAGE_TEXT_CHARS","SITE_PAGES_LISTED","PRODUCT_LISTING_FIELDS","ZERO_USAGE","inputTokens","outputTokens","cacheReadTokens","cacheWriteTokens","str","value","trim","round6","Math","round","modelOf","context","modelFor","spentNothing","model","usage","estCostUsd","stopReason","spentBy","generation","addSpent","a","b","plain","JSON","parse","stringify","aiSeoRequestedFields","raw","allowed","named","String","split","map","part","filter","wanted","Set","length","key","has","brandOf","host","seo","title","displayName","subdomain","loadSite","firestore","job","hostId","failure","snapshot","collection","doc","get","exists","data","orgId","siteRepeatRows","keys","composedPageFacts","versions","composed","version","nodes","index","rootId","pageNodes","readVersionNodes","hostRef","screenId","versionId","siteTitles","except","select","limit","docs","id","Boolean","listingOutcome","subject","spent","status","outputs","refused","message","values","notes","fields","includes","hasImage","imageAlt","push","unchecked","proposal","kind","keywords","description","h1","facts","h1s","text","body","output","resource","label","name","runScreenListing","screen","signal","inputs","deletedAt","image","onPage","images","find","src","undefined","route","screens","path","brand","current","breadcrumb","alt","otherTitles","maxTokens","runProductListing","slice","productId","scanSite","templateScreenIds","aiSeoPendingUnits","report","done","units","siteProposal","site","batches","forEach","screenIds","fixes","batch","of","AI_SEO_SITE_INSTRUCTIONS","cacheBreakpoint","aiSeoBlankSiteFields","entity","agent","blank","type","add","email","telephone","contactType","whenToUse","howToUse","readContentCollections","slug","aiSeoLlmsPreview","pages","collections","siteName","origin","hasSearch","contactEmail","proposeSite","scan","topLevel","page","replace","telling","test","prompt","join","entry","flatMap","line","siteText","step","instructions","messages","role","content","tool","check","answer","proposed","llmsPreview","AI_SEO_FIXES_INSTRUCTIONS","aiSeoPageFixFor","imageAlts","nodeId","first","promotable","headings","heading","editable","codes","guidance","aiSeoFixesPrompt","titlesElsewhere","titles","blocks","lines","code","proposeFixes","unit","reports","Map","read","Promise","all","pageReport","live","findings","keyword","answers","asked","skipped","runSiteAuditPass","recorded","reduce","sum","result","continue","runAiJobSeoStep","Error","target","withFirestore"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,kBAAkB,QAAQ,yCAAwC;AAC3E,SAASC,gBAAgB,QAAQ,qCAAoC;AACrE,SACEC,YAAY,QAGP,kCAAiC;AACxC,SAASC,oBAAoB,QAAQ,sCAAqC;AAC1E,SAASC,kBAAkB,QAAQ,mCAAkC;AACrE,SACEC,gBAAgB,EAChBC,kBAAkB,EAClBC,eAAe,EACfC,iBAAiB,QACZ,sCAAqC;AAC5C,SACEC,yBAAyB,EACzBC,oBAAoB,QAEf,4CAA2C;AAClD,SACEC,uBAAuB,EACvBC,YAAY,QAEP,wCAAuC;AAC9C,SACEC,eAAe,EACfC,WAAW,EACXC,cAAc,QAGT,uCAAsC;AAC7C,sEAAsE;AACtE,SAASC,cAAc,QAAQ,0CAAyC;AACxE,SAASC,iBAAiB,QAAQ,sCAAqC;AACvE,SAASC,oBAAoB,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MAAMgJ,OAAO,MAAM3F,SAASC,WAAWC;IACvC,IAAI,aAAayF,MAAM,OAAO;QAAEtD,SAAS,EAAE;OAAKvE,aAAaH,QAAQC;QAAWwC,SAASuF,KAAKvF,OAAO;;IACrG,MAAMmL,gBAAgB,aAAK3N;QAASqC;;IACpC,OAAQqL;QACN,KAAK;YACH,OAAOzH,iBAAiB0H,eAAe5F,KAAKhG,IAAI;QAClD,KAAK;YACH,OAAOsF,kBAAkBsG,eAAe5F,KAAKhG,IAAI;QACnD,KAAK;YACH,OAAOmL,iBAAiBS,eAAe5F,KAAKhG,IAAI;IACpD;AACF,EAAC"}
1
+ {"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/jobs/ai-job-seo-step.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { hostCollectionKind } from '@aglyn/aglyn/app-utils/collection-kind'\nimport { hostPublicOrigin } from '@aglyn/aglyn/app-utils/host-naming'\nimport {\n buildLlmsTxt,\n type LlmsTxtCollection,\n type LlmsTxtPage,\n} from '@aglyn/aglyn/app-utils/llms-txt'\nimport { screenRoutePathToUrl } from '@aglyn/aglyn/app-utils/screen-route'\nimport { SEO_FINDING_LABELS } from '@aglyn/aglyn/app-utils/seo-audit'\nimport {\n SEO_MAX_KEYWORDS,\n seoKeywordCoverage,\n seoKeywordSplit,\n seoQuotedKeywords,\n} from '@aglyn/aglyn/app-utils/seo-keywords'\nimport {\n SCREEN_SEO_LISTING_FIELDS,\n isSeoListingFieldKey,\n type SeoListingFieldKey,\n} from '@aglyn/aglyn/app-utils/seo-listing-fields'\nimport {\n SEO_PAGE_TEXT_MAX_CHARS,\n seoPageFacts,\n type SeoPageFacts,\n} from '@aglyn/aglyn/app-utils/seo-page-facts'\nimport {\n composeSeoPages,\n scanSeoSite,\n seoAuditSiteOf,\n type SeoRepeatRowsReader,\n type SeoSiteScan,\n} from '@aglyn/aglyn/app-utils/seo-site-scan'\n// By path, never through a barrel: only a server composition asks it.\nimport { readRepeatRows } from '@aglyn/aglyn/plugin-manager/repeat-rows'\nimport { decodeStoredNodes } from '@aglyn/aglyn/app-utils/stored-nodes'\nimport { getTemplateScreenIds } from '@aglyn/tenant-runtime/template-screens'\nimport type { AiJob, AiJobOutput } from '../model/ai-jobs.types'\nimport {\n AI_SEO_OUTPUT_IDS,\n aiSeoAuditView,\n aiSeoJobTarget,\n type AiSeoAuditReport,\n type AiSeoContentFix,\n type AiSeoFieldsProposal,\n type AiSeoFieldValues,\n type AiSeoPageFix,\n type AiSeoSiteFormField,\n type AiSeoSiteProposal,\n} from '../model/ai-seo'\nimport { aiModelForStep, aiRouteSettings } from '../providers/routing'\nimport type { AiSystemBlock, AiUsage } from '../runtime/ai-runtime'\nimport { aiSeoAudit, aiSeoAuditBatches, aiSeoHeadingDemotions } from '../runtime/seo-audit'\nimport {\n runValidatedGeneration,\n type AiGenerationSpend,\n type AiValidatedGeneration,\n} from '../runtime/ai-doctrine'\nimport { AI_SEO_FIELDS_MAX_TOKENS, aiFitSeoOverrun, generateSeoFields } from '../runtime/seo-fields'\nimport {\n AI_SEO_FIXES_TOOL_NAME,\n AI_SEO_SITE_TOOL_NAME,\n aiSeoFixImages,\n aiSeoFixesTool,\n aiSeoSiteTool,\n checkAiSeoFixes,\n checkAiSeoSite,\n fitAiSeoFixLengths,\n type AiSeoBatchAnswer,\n type AiSeoBatchPage,\n} from '../tools/ai-seo-tool'\nimport {\n AI_SEO_FIXES_MAX_TOKENS,\n AI_SEO_SITE_MAX_TOKENS,\n aiSeoGenerationMaxTokens,\n} from './ai-job-seo-budget'\nimport { aiCacheWriteHourSum } from '../providers/cache-write-hour'\nimport type { AiJobStepContext, AiJobStepOutcome, AiJobStepRunner } from './ai-job-text-step'\n\n/**\n * The `seo` step (AGL-2910): search listings and a site audit, as proposals.\n *\n * `inputs.target` says what the job is about:\n *\n * - `screen` — one page's listing, written from the version the person is\n * looking at (`screenId`, `versionId`), for the page's SEO card;\n * - `product` — one product's listing, from the name and description the\n * product editor handed over (`name`, `text`), for the product editor;\n * - `site` — the audit of every published page the sitemap lists, with a\n * proposed fix per finding, structured data for the site's entity, and the\n * agent guidance `/llms.txt` leads with.\n *\n * ## It writes nothing\n *\n * Like every runner, this reads, asks and returns. A listing is served\n * straight from the screen document, the structured data and `/llms.txt`\n * from the host document, and a page's content from its published version,\n * so the values ride on the job's outputs and nothing else: a person puts\n * them in the page's SEO card or the site SEO form and saves them there, and\n * content fixes become a new version only through the apply door.\n *\n * ## An audit, a unit at a time\n *\n * The first pass reads the site — every published page's version and the\n * shared layouts, for the links between them — and scores it without a\n * model, through the platform's SEO check (the same findings the site's SEO\n * section lists to every owner); it records the report, and runs the first unit of generated work. Each later\n * pass runs one more unit: the site-wide proposal, then the page fixes in\n * batches. Every pass is one reservation and one provider exchange, and it\n * asks the machine to continue until nothing is left, so a large site is a\n * few beats of work rather than one request that cannot finish.\n */\n\nexport const AI_SEO_NO_SITE_COPY = 'This SEO job names a site this workspace does not have.'\nexport const AI_SEO_NO_PAGE_COPY = 'This page is no longer on the site.'\nexport const AI_SEO_NO_TARGET_COPY = 'This SEO job does not say what to write about.'\nexport const AI_SEO_NO_PRODUCT_COPY = 'Give the product a name before writing its listing.'\n\n/** How much of each page a batch of fixes carries. */\nexport const AI_SEO_BATCH_PAGE_TEXT_CHARS = 700\n\n/**\n * Output budgets, declared with the step's time (`ai-job-seo-budget.ts`,\n * AGL-3035). A batch's largest answer — every page with a title, description,\n * heading and image descriptions at their limits — and the site proposal's are\n * measured in `ai-job-seo-step.spec.ts`.\n */\nexport { AI_SEO_FIXES_MAX_TOKENS, AI_SEO_SITE_MAX_TOKENS }\n\n/** Pages the site prompt and the llms.txt preview list. */\nconst SITE_PAGES_LISTED = 25\n\n/** The fields a product's listing holds. */\nconst PRODUCT_LISTING_FIELDS: readonly SeoListingFieldKey[] = ['title', 'description']\n\nconst ZERO_USAGE: AiUsage = {\n inputTokens: 0,\n outputTokens: 0,\n cacheReadTokens: 0,\n cacheWriteTokens: 0,\n}\n\ntype Firestore = FirebaseFirestore.Firestore\ntype DocumentReference = FirebaseFirestore.DocumentReference\ntype Spent = Pick<AiJobStepOutcome, 'usage' | 'estCostUsd' | 'model' | 'stopReason'>\n\n/** The host document fields this step reads. */\nexport interface SeoHostDocument {\n orgId?: string\n displayName?: string\n subdomain?: string | null\n cname?: string | null\n screens?: Record<string, string>\n errorScreens?: Record<string, string>\n notFoundScreenId?: string | null\n seo?: {\n title?: string\n description?: string\n discourageSearchEngines?: boolean\n entity?: {\n type?: unknown\n name?: string\n description?: string\n email?: string\n telephone?: string\n contactType?: string\n }\n agent?: { whenToUse?: string; howToUse?: string }\n }\n /** The one-block copy of the site's email, read when the entity has none (AGL-4136). */\n business?: { supportEmail?: string }\n}\n\n/** The screen document fields this step reads. */\ninterface SeoScreenDocument {\n displayName?: string\n description?: string\n versionId?: string\n visibility?: unknown\n deletedAt?: unknown\n seo?: {\n title?: string\n description?: string\n breadcrumb?: string\n image?: string\n imageAlt?: string\n }\n}\n\nconst str = (value: unknown): string => (typeof value === 'string' ? value.trim() : '')\n\nconst round6 = (value: number): number => Math.round(value * 1_000_000) / 1_000_000\n\nfunction modelOf(context: AiJobStepContext): string {\n return context.modelFor?.('job.seo') ?? aiModelForStep('job.seo')\n}\n\nfunction spentNothing(model: string): Spent {\n return { usage: ZERO_USAGE, estCostUsd: 0, model, stopReason: null }\n}\n\nfunction spentBy(generation: AiGenerationSpend): Spent {\n return {\n usage: generation.usage,\n estCostUsd: generation.estCostUsd,\n model: generation.model,\n stopReason: generation.stopReason,\n }\n}\n\nfunction addSpent(a: Spent, b: Spent): Spent {\n return {\n usage: {\n inputTokens: a.usage.inputTokens + b.usage.inputTokens,\n outputTokens: a.usage.outputTokens + b.usage.outputTokens,\n cacheReadTokens: a.usage.cacheReadTokens + b.usage.cacheReadTokens,\n cacheWriteTokens: a.usage.cacheWriteTokens + b.usage.cacheWriteTokens,\n ...aiCacheWriteHourSum(a.usage, b.usage),\n },\n estCostUsd: round6(a.estCostUsd + b.estCostUsd),\n model: b.model || a.model,\n stopReason: b.stopReason ?? a.stopReason,\n }\n}\n\n/** Through JSON, so no `undefined` reaches the job document's write. */\nconst plain = <T>(value: T): Record<string, unknown> =>\n JSON.parse(JSON.stringify(value)) as Record<string, unknown>\n\n/**\n * The fields a listing job writes: the ones the editor named (`inputs.fields`,\n * comma-separated) that the target's editor holds, or all of those.\n */\nexport function aiSeoRequestedFields(\n raw: unknown,\n allowed: readonly SeoListingFieldKey[],\n): SeoListingFieldKey[] {\n const named = String(raw ?? '')\n .split(',')\n .map((part) => part.trim())\n .filter(isSeoListingFieldKey)\n const wanted = new Set<SeoListingFieldKey>(named.length ? named : allowed)\n return allowed.filter((key) => wanted.has(key))\n}\n\n/** The site's name, as its visitors read it. */\nfunction brandOf(host: SeoHostDocument): string {\n return str(host.seo?.title) || str(host.displayName) || str(host.subdomain)\n}\n\n/** The site a job names, read and checked against the job's org. */\nasync function loadSite(\n firestore: Firestore,\n job: AiJob,\n): Promise<{ host: SeoHostDocument } | { failure: string }> {\n if (!job.hostId) return { failure: AI_SEO_NO_SITE_COPY }\n const snapshot = await firestore.collection('hosts').doc(job.hostId).get()\n const host = snapshot.exists ? (snapshot.data() as SeoHostDocument) : null\n // The route checks the caller's membership of the org the job is metered\n // against, not that the site belongs to it. A site of another org is\n // refused here, before anything about it reaches a prompt.\n if (!host || host.orgId !== job.orgId) return { failure: AI_SEO_NO_SITE_COPY }\n return { host }\n}\n\n/** The rows a site's repeats render, through the platform's repeat-rows contract. */\nconst siteRepeatRows =\n (hostId: string): SeoRepeatRowsReader =>\n (keys) =>\n readRepeatRows({ hostId, keys })\n\n/**\n * Pages' facts as the SEO check reads them (AGL-3501): each version composed\n * as it publishes — components grafted, repeats expanded — and read against\n * the page's own map, so a fix is only ever offered for what the page holds.\n */\nasync function composedPageFacts(\n firestore: Firestore,\n hostId: string,\n versions: readonly ({ nodes: Record<string, unknown>; rootId?: string } | null)[],\n): Promise<SeoPageFacts[]> {\n const { composed } = await composeSeoPages(\n firestore,\n hostId,\n versions.map((version) => version?.nodes ?? null),\n { readRepeatRows: siteRepeatRows(hostId) },\n )\n return versions.map((version, index) =>\n seoPageFacts(composed[index] as never, { rootId: version?.rootId, pageNodes: version?.nodes as never }),\n )\n}\n\n/** A version's node map and root, or `null` when it cannot be read. */\nasync function readVersionNodes(\n hostRef: DocumentReference,\n screenId: string,\n versionId: string,\n): Promise<{ nodes: Record<string, unknown>; rootId?: string } | null> {\n if (!versionId) return null\n const snapshot = await hostRef\n .collection('screens')\n .doc(screenId)\n .collection('versions')\n .doc(versionId)\n .get()\n if (!snapshot.exists) return null\n const nodes = decodeStoredNodes<Record<string, unknown>>(snapshot.get('nodes'))\n if (!nodes) return null\n const rootId = snapshot.get('rootId')\n return { nodes, ...(typeof rootId === 'string' ? { rootId } : {}) }\n}\n\n/** Every other page's search title, for a proposal not to repeat. */\nasync function siteTitles(hostRef: DocumentReference, except: ReadonlySet<string>): Promise<string[]> {\n const snapshot = await hostRef.collection('screens').select('seo', 'deletedAt').limit(1000).get()\n return snapshot.docs\n .filter((doc) => !except.has(doc.id) && !doc.get('deletedAt'))\n .map((doc) => str((doc.get('seo') as SeoScreenDocument['seo'])?.title))\n .filter(Boolean)\n}\n\n/* ------------------------------------------------------------------------ *\n * One listing: a page or a product\n * ------------------------------------------------------------------------ */\n\nfunction listingOutcome(\n generation: AiValidatedGeneration<AiSeoFieldValues>,\n job: AiJob,\n subject: AiSeoFieldsProposal['subject'],\n context: {\n keywords: readonly string[]\n /** Keywords past the limit, which the proposal did not aim for. */\n unchecked: readonly string[]\n facts: SeoPageFacts | null\n fields: readonly SeoListingFieldKey[]\n hasImage: boolean\n },\n): AiJobStepOutcome {\n const spent = spentBy(generation)\n if (generation.status === 'refused') return { outputs: [], ...spent, refused: true }\n if (generation.status === 'needs_input') return { outputs: [], ...spent, failure: generation.message }\n const values = generation.value\n const notes: string[] = []\n if (context.fields.includes('imageAlt') && context.hasImage && !values.imageAlt) {\n notes.push('No image description was proposed: nothing on the page says what the picture shows.')\n }\n if (context.unchecked.length) {\n notes.push(\n `Only the first ${SEO_MAX_KEYWORDS} keywords were used, so ${seoQuotedKeywords(context.unchecked)} ${context.unchecked.length === 1 ? 'was' : 'were'} not.`,\n )\n }\n const proposal: AiSeoFieldsProposal = {\n kind: 'fields',\n subject,\n values,\n keywords: seoKeywordCoverage(context.keywords, {\n title: values.title,\n description: values.description,\n h1: context.facts?.h1s[0]?.text,\n body: context.facts?.text,\n }),\n notes,\n }\n const output: AiJobOutput = {\n resource: 'seo',\n id: AI_SEO_OUTPUT_IDS.fields(subject.kind, subject.id),\n hostId: job.hostId ?? null,\n label: `SEO proposal · ${subject.name}`,\n proposal: plain(proposal),\n }\n return { outputs: [output], ...spent }\n}\n\nasync function runScreenListing(\n context: AiJobStepContext & { firestore: Firestore },\n host: SeoHostDocument,\n): Promise<AiJobStepOutcome> {\n const { job, firestore, signal } = context\n const model = modelOf(context)\n const hostRef = firestore.collection('hosts').doc(job.hostId as string)\n const screenId = str(job.inputs?.['screenId'])\n const snapshot = screenId ? await hostRef.collection('screens').doc(screenId).get() : null\n const screen = snapshot?.exists ? (snapshot.data() as SeoScreenDocument) : null\n if (!screen || screen.deletedAt) {\n return { outputs: [], ...spentNothing(model), failure: AI_SEO_NO_PAGE_COPY }\n }\n\n const versionId = str(job.inputs?.['versionId']) || str(screen.versionId)\n const version = await readVersionNodes(hostRef, screenId, versionId)\n const [facts] = await composedPageFacts(firestore, job.hostId as string, [version])\n const fields = aiSeoRequestedFields(job.inputs?.['fields'], SCREEN_SEO_LISTING_FIELDS)\n const seo = screen.seo ?? {}\n const hasImage = Boolean(str(seo.image))\n // The share image is often a picture the page shows too: its description\n // and the text beside it there are what is known about it.\n const onPage = hasImage ? facts.images.find((image) => image.src === str(seo.image)) : undefined\n const route = host.screens?.[screenId]\n const path = typeof route === 'string' ? screenRoutePathToUrl(route) : null\n const name = str(screen.displayName) || path || 'Untitled page'\n const { keywords, unchecked } = seoKeywordSplit(job.inputs?.['keywords'])\n const generation = await generateSeoFields({\n subject: { kind: 'screen', name, path },\n brand: brandOf(host),\n text: facts.text || str(screen.description),\n fields,\n current: {\n title: str(seo.title),\n description: str(seo.description),\n breadcrumb: str(seo.breadcrumb),\n imageAlt: str(seo.imageAlt),\n },\n image: hasImage ? { alt: str(seo.imageAlt) || onPage?.alt || null, context: onPage?.context || null } : null,\n keywords,\n otherTitles: await siteTitles(hostRef, new Set([screenId])),\n model,\n maxTokens: aiSeoGenerationMaxTokens(model, AI_SEO_FIELDS_MAX_TOKENS),\n ...(signal ? { signal } : {}),\n })\n return listingOutcome(generation, job, { kind: 'screen', id: screenId, name, path }, {\n keywords,\n unchecked,\n facts,\n fields,\n hasImage,\n })\n}\n\nasync function runProductListing(\n context: AiJobStepContext & { firestore: Firestore },\n host: SeoHostDocument,\n): Promise<AiJobStepOutcome> {\n const { job, signal } = context\n const model = modelOf(context)\n const name = str(job.inputs?.['name']).slice(0, 200)\n if (!name) return { outputs: [], ...spentNothing(model), failure: AI_SEO_NO_PRODUCT_COPY }\n const fields = aiSeoRequestedFields(job.inputs?.['fields'], PRODUCT_LISTING_FIELDS)\n const { keywords, unchecked } = seoKeywordSplit(job.inputs?.['keywords'])\n const productId = str(job.inputs?.['productId']) || null\n const generation = await generateSeoFields({\n subject: { kind: 'product', name },\n brand: brandOf(host),\n // The product's own words, as its editor handed them over: the product\n // document is the commerce plugin's, and this step never reads it.\n text: str(job.inputs?.['text']).slice(0, SEO_PAGE_TEXT_MAX_CHARS),\n fields,\n current: {\n title: str(job.inputs?.['currentTitle']),\n description: str(job.inputs?.['currentDescription']),\n },\n image: null,\n keywords,\n model,\n maxTokens: aiSeoGenerationMaxTokens(model, AI_SEO_FIELDS_MAX_TOKENS),\n ...(signal ? { signal } : {}),\n })\n return listingOutcome(generation, job, { kind: 'product', id: productId, name }, {\n keywords,\n unchecked,\n facts: null,\n fields,\n hasImage: false,\n })\n}\n\n/* ------------------------------------------------------------------------ *\n * The site audit\n * ------------------------------------------------------------------------ */\n\n/**\n * Read the site for an audit: the platform SEO check's scan\n * (`@aglyn/aglyn/app-utils/seo-site-scan`), which the site's SEO section\n * reads through too, so a job audits exactly the pages the check lists.\n */\nasync function scanSite(\n firestore: Firestore,\n hostId: string,\n host: SeoHostDocument,\n keywords: unknown,\n): Promise<SeoSiteScan> {\n return scanSeoSite(firestore, hostId, host, {\n keywords,\n templateScreenIds: await getTemplateScreenIds({ hostId }),\n readRepeatRows: siteRepeatRows(hostId),\n })\n}\n\n/** One unit of generated work an audit still owes. */\nexport type AiSeoAuditUnit =\n | { kind: 'site' }\n | { kind: 'batch'; batch: number; of: number; screenIds: string[] }\n\n/** The units an audit owes after the outputs recorded so far, in the order they run. */\nexport function aiSeoPendingUnits(\n report: AiSeoAuditReport,\n outputs: readonly Pick<AiJobOutput, 'id'>[],\n): AiSeoAuditUnit[] {\n const done = new Set(outputs.map((output) => output.id))\n const units: AiSeoAuditUnit[] = []\n if (report.siteProposal && !done.has(AI_SEO_OUTPUT_IDS.site)) units.push({ kind: 'site' })\n const batches = aiSeoAuditBatches(report)\n batches.forEach((screenIds, index) => {\n if (!done.has(AI_SEO_OUTPUT_IDS.fixes(index + 1))) {\n units.push({ kind: 'batch', batch: index + 1, of: batches.length, screenIds })\n }\n })\n return units\n}\n\ninterface UnitResult {\n output: AiJobOutput\n spent: Spent\n}\n\n/* ---- The site-wide proposal ---------------------------------------------- */\n\nexport const AI_SEO_SITE_INSTRUCTIONS: AiSystemBlock[] = [\n {\n text:\n 'You propose two things for a website: the structured data that says who publishes it, and ' +\n 'the guidance an AI agent reads first in its /llms.txt.\\n\\n' +\n `Answer by calling ${AI_SEO_SITE_TOOL_NAME} exactly once. A reply in prose cannot be used.\\n\\n` +\n 'Rules:\\n' +\n '- Fill only the fields you are told are empty; answer null for every other one.\\n' +\n '- Use only what the pages you are given state. A contact email or telephone number goes in ' +\n 'only when a page shows it exactly; never compose one.\\n' +\n '- The entity description says what the publisher is, in one plain sentence, not what one page ' +\n 'offers.\\n' +\n '- The agent guidance is checkable and specific: the questions this site answers and which ' +\n 'pages answer them. No marketing language: an agent discounts a claim it cannot check.\\n' +\n '- Keep every length the tool states, and write in the language of the pages.',\n cacheBreakpoint: true,\n },\n]\n\n/** The site SEO form fields blank on the site now. */\nexport function aiSeoBlankSiteFields(host: SeoHostDocument): Set<AiSeoSiteFormField> {\n const entity = host.seo?.entity ?? {}\n const agent = host.seo?.agent ?? {}\n const blank = new Set<AiSeoSiteFormField>()\n if (entity.type === undefined || entity.type === null || entity.type === '') blank.add('seo.entity.type')\n if (!str(entity.name)) blank.add('seo.entity.name')\n if (!str(entity.description)) blank.add('seo.entity.description')\n // The site's one email is the entity's, else the older one-block copy\n // (AGL-4136); Setup → Business profile shows the copy in its Email field, so a\n // site with only the copy has an email, and a proposal would replace it.\n if (!str(entity.email) && !str(host.business?.supportEmail)) blank.add('seo.entity.email')\n if (!str(entity.telephone)) blank.add('seo.entity.telephone')\n if (!str(entity.contactType)) blank.add('seo.entity.contactType')\n if (!str(agent.whenToUse)) blank.add('seo.agent.whenToUse')\n if (!str(agent.howToUse)) blank.add('seo.agent.howToUse')\n return blank\n}\n\n/** The site's content collections, for the llms.txt preview. */\nasync function readContentCollections(hostRef: DocumentReference): Promise<LlmsTxtCollection[]> {\n try {\n const snapshot = await hostRef.collection('collections').select('slug', 'displayName', 'kind').limit(50).get()\n return snapshot.docs\n .filter((doc) => hostCollectionKind(doc.data()) === 'content' && str(doc.get('slug')))\n .map((doc) => ({ slug: str(doc.get('slug')), name: str(doc.get('displayName')) || undefined }))\n } catch {\n // A preview without the feeds is still a preview of the guidance.\n return []\n }\n}\n\n/** `/llms.txt` as it reads with `values` saved over what the site stores now. */\nexport function aiSeoLlmsPreview(\n host: SeoHostDocument,\n values: Partial<Record<AiSeoSiteFormField, string>>,\n pages: readonly LlmsTxtPage[],\n collections: readonly LlmsTxtCollection[],\n): string {\n return buildLlmsTxt({\n siteName: str(host.seo?.title) || str(host.displayName) || 'Site',\n origin: hostPublicOrigin(host) ?? '',\n description: str(host.seo?.description) || undefined,\n agent: {\n whenToUse: values['seo.agent.whenToUse'] ?? host.seo?.agent?.whenToUse,\n howToUse: values['seo.agent.howToUse'] ?? host.seo?.agent?.howToUse,\n },\n pages,\n collections,\n hasSearch: true,\n // As the site's own /llms.txt names it (AGL-4136): the entity's email,\n // else the older one-block copy.\n contactEmail:\n values['seo.entity.email'] ?? (str(host.seo?.entity?.email) || str(host.business?.supportEmail) || undefined),\n })\n}\n\nasync function proposeSite(\n context: AiJobStepContext & { firestore: Firestore },\n host: SeoHostDocument,\n scan: SeoSiteScan,\n): Promise<UnitResult> {\n const { job, firestore, signal } = context\n const model = modelOf(context)\n const hostRef = firestore.collection('hosts').doc(job.hostId as string)\n const blank = aiSeoBlankSiteFields(host)\n const collections = await readContentCollections(hostRef)\n const topLevel: LlmsTxtPage[] = scan.pages\n .filter((page) => !page.path.replace(/^\\//, '').includes('/'))\n .slice(0, SITE_PAGES_LISTED)\n .map((page) => ({ path: page.path, ...(page.name ? { title: page.name } : {}) }))\n // The pages that say who publishes a site: the home page, and whatever is\n // about the company or how to reach it.\n const telling = scan.pages\n .filter((page) => page.path === '/' || /about|contact|company|team|who/i.test(page.path))\n .slice(0, 4)\n const prompt = [\n `Site: ${brandOf(host) || 'untitled site'}`,\n host.seo?.description ? `Site description: ${str(host.seo.description)}` : '',\n `Empty fields you may fill: ${[...blank].join(', ') || 'none'}`,\n 'Pages:',\n ...scan.pages\n .slice(0, SITE_PAGES_LISTED)\n .map((page) => `- ${page.path} — ${page.name}${str(page.seo.title) ? ` — ${str(page.seo.title)}` : ''}`),\n collections.length\n ? `Content collections: ${collections.map((entry) => entry.name || entry.slug).join(', ')}`\n : '',\n ...telling.flatMap((page) => ['', `Text of ${page.path}:`, page.facts.text.slice(0, 1_200) || '(no text)']),\n ]\n .filter((line) => line !== '')\n .join('\\n')\n const siteText = scan.pages.map((page) => page.facts.text).join('\\n')\n const generation = await runValidatedGeneration('seo-site', {\n step: 'job.seo',\n ...aiRouteSettings('job.seo'),\n model,\n instructions: AI_SEO_SITE_INSTRUCTIONS,\n messages: [{ role: 'user', content: prompt }],\n tool: aiSeoSiteTool(),\n maxTokens: aiSeoGenerationMaxTokens(model, AI_SEO_SITE_MAX_TOKENS),\n ...(signal ? { signal } : {}),\n check: (answer) => checkAiSeoSite(answer, { blank, siteText }),\n })\n const proposed = generation.status === 'ok' ? generation.value : { values: {}, notes: [] }\n const notes =\n generation.status === 'ok'\n ? proposed.notes\n : [\n generation.status === 'refused'\n ? 'The AI declined to propose structured data for this site.'\n : generation.message,\n ]\n const site: AiSeoSiteProposal = {\n values: proposed.values,\n llmsPreview: aiSeoLlmsPreview(host, proposed.values, topLevel, collections),\n notes,\n }\n return {\n output: {\n resource: 'seo',\n id: AI_SEO_OUTPUT_IDS.site,\n hostId: job.hostId ?? null,\n label: 'SEO audit · structured data and agent guidance',\n proposal: plain({ kind: 'site', site }),\n },\n spent: spentBy(generation),\n }\n}\n\n/* ---- A batch of page fixes ------------------------------------------------ */\n\nexport const AI_SEO_FIXES_INSTRUCTIONS: AiSystemBlock[] = [\n {\n text:\n 'You fix the search listings and headings of a website’s pages. For each page you are given ' +\n 'what an audit found, what the page shows now, and its text.\\n\\n' +\n `Answer by calling ${AI_SEO_FIXES_TOOL_NAME} exactly once, with one entry per page. A reply in ` +\n 'prose cannot be used.\\n\\n' +\n 'Rules:\\n' +\n '- Fix only what the audit found. Answer null for a value it did not find a problem with.\\n' +\n '- Write only from the page’s own text. Never invent a fact, a price, a name, a place or a claim.\\n' +\n '- A title says what the page is, specifically. No two pages share a title, and none repeats a ' +\n 'title you are told another page uses.\\n' +\n '- A description is one or two sentences telling a searcher what they will find.\\n' +\n '- The main heading names what the page is about in a few plain words.\\n' +\n '- An image description says what the picture most likely shows, from the text beside it. ' +\n 'Leave an image out when the text gives no idea.\\n' +\n '- A target keyword goes in only where the page is about it and it reads naturally: at most ' +\n 'once in a title and once in a description. Never list keywords or repeat a word to rank.\\n' +\n '- Keep every length the tool states, and write in the language of each page.',\n cacheBreakpoint: true,\n },\n]\n\n/** The fixes one page gets: the model's values, its content fixes, and the guidance no fix can give. */\nexport function aiSeoPageFixFor(page: AiSeoBatchPage, answer: AiSeoBatchAnswer | null): AiSeoPageFix {\n const values: AiSeoFieldValues = {}\n if (answer?.title) values.title = answer.title\n if (answer?.description) values.description = answer.description\n const content: AiSeoContentFix[] = []\n for (const alt of answer?.imageAlts ?? []) content.push({ kind: 'image-alt', nodeId: alt.nodeId, alt: alt.alt })\n if (answer?.h1) {\n const first = page.facts.h1s[0]\n const promotable = page.facts.headings.find((heading) => heading.editable && heading.nodeId)\n if (page.codes.has('h1-thin') && first?.editable && first.nodeId) {\n content.push({ kind: 'h1-set', nodeId: first.nodeId, text: answer.h1 })\n } else if (page.codes.has('h1-missing') && promotable?.nodeId) {\n content.push({ kind: 'h1-set', nodeId: promotable.nodeId, text: answer.h1 })\n } else if (page.codes.has('h1-missing')) {\n content.push({ kind: 'h1-insert', text: answer.h1 })\n }\n }\n if (page.codes.has('h1-multiple')) content.push(...aiSeoHeadingDemotions(page.facts))\n const guidance: string[] = []\n if (page.codes.has('orphan')) {\n guidance.push('Link to this page from your navigation or a related page. Where it belongs is yours to choose.')\n }\n return { screenId: page.screenId, values, content, guidance }\n}\n\n/** The user turn for one batch: each page's findings, what it shows now, and its text. */\nexport function aiSeoFixesPrompt(pages: readonly AiSeoBatchPage[], titlesElsewhere: readonly string[]): string {\n const titles = titlesElsewhere.length\n ? `Titles other pages use:\\n${titlesElsewhere.slice(0, 40).map((title) => `- ${title}`).join('\\n')}\\n\\n`\n : ''\n const blocks = pages.map((page) => {\n const lines = [\n `### Page ${page.screenId}: ${page.name} (${page.path})`,\n `Found: ${[...page.codes].map((code) => SEO_FINDING_LABELS[code]).join('; ')}`,\n `Title now: ${str(page.seo?.title) || '(none)'}`,\n `Description now: ${str(page.seo?.description) || '(none)'}`,\n `Main heading now: ${page.facts.h1s[0]?.text || '(none)'}`,\n ]\n if (page.keywords.length) lines.push(`Target keywords: ${page.keywords.join(', ')}`)\n const images = aiSeoFixImages(page)\n if (images.length) {\n lines.push(\n 'Images without a description:',\n ...images.map((image) => `- ${image.nodeId}: beside \"${image.context || 'no text'}\"`),\n )\n }\n lines.push('Text:', page.facts.text.slice(0, AI_SEO_BATCH_PAGE_TEXT_CHARS) || '(no text)')\n return lines.join('\\n')\n })\n return `${titles}${blocks.join('\\n\\n')}`\n}\n\nasync function proposeFixes(\n context: AiJobStepContext & { firestore: Firestore },\n report: AiSeoAuditReport,\n unit: Extract<AiSeoAuditUnit, { kind: 'batch' }>,\n): Promise<UnitResult> {\n const { job, firestore, signal } = context\n const model = modelOf(context)\n const hostRef = firestore.collection('hosts').doc(job.hostId as string)\n const reports = new Map(report.pages.map((page) => [page.screenId, page]))\n // Read now, not as audited: a page edited since keeps its edits, and one\n // deleted since is skipped.\n const read = await Promise.all(\n unit.screenIds.map(async (screenId) => {\n const pageReport = reports.get(screenId)\n const snapshot = await hostRef.collection('screens').doc(screenId).get()\n const screen = snapshot.exists ? (snapshot.data() as SeoScreenDocument) : null\n if (!pageReport || !screen || screen.deletedAt) return null\n const version = await readVersionNodes(hostRef, screenId, str(screen.versionId))\n return { screenId, pageReport, screen, version }\n }),\n )\n const live = read.filter((entry): entry is NonNullable<typeof entry> => entry !== null)\n // Read as the audit read them, composed: a heading a component renders is\n // the page's, and is never offered to a fix that would rewrite the page.\n const facts = await composedPageFacts(\n firestore,\n job.hostId as string,\n live.map((entry) => entry.version),\n )\n const pages: AiSeoBatchPage[] = live.map(({ screenId, pageReport, screen }, index) => ({\n screenId,\n path: pageReport.path,\n name: pageReport.name,\n codes: new Set(pageReport.findings.map((entry) => entry.code)),\n keywords: pageReport.keywords.map((entry) => entry.keyword),\n seo: screen.seo ?? {},\n facts: facts[index],\n }))\n const titlesElsewhere = await siteTitles(hostRef, new Set(pages.map((page) => page.screenId)))\n\n let spent = spentNothing(model)\n let answers: Record<string, AiSeoBatchAnswer> = {}\n const notes: string[] = []\n if (pages.length) {\n const check = (answer: Record<string, unknown>) => checkAiSeoFixes(answer, pages, titlesElsewhere)\n const asked = await runValidatedGeneration('seo-fixes', {\n step: 'job.seo',\n ...aiRouteSettings('job.seo'),\n model,\n instructions: AI_SEO_FIXES_INSTRUCTIONS,\n messages: [{ role: 'user', content: aiSeoFixesPrompt(pages, titlesElsewhere) }],\n tool: aiSeoFixesTool(pages.map((page) => page.screenId)),\n // Lowered on a tier too slow to answer a whole batch and ask again\n // inside the least time the step registers.\n maxTokens: aiSeoGenerationMaxTokens(model, AI_SEO_FIXES_MAX_TOKENS),\n ...(signal ? { signal } : {}),\n check,\n })\n // A batch the re-ask still left past a length keeps its fixes, fitted\n // (AGL-4016): one long title used to drop every page's fixes.\n const generation = aiFitSeoOverrun('seo-fixes', asked, fitAiSeoFixLengths, check)\n spent = spentBy(generation)\n if (generation.status === 'ok') {\n answers = generation.value\n } else {\n notes.push(\n generation.status === 'refused'\n ? 'The AI declined to propose fixes for these pages.'\n : generation.message,\n )\n }\n }\n const fixes = pages.map((page) => aiSeoPageFixFor(page, answers[page.screenId] ?? null))\n const skipped = unit.screenIds.length - pages.length\n if (skipped > 0) {\n notes.push(`${skipped} ${skipped === 1 ? 'page was' : 'pages were'} deleted since the audit and left out.`)\n }\n return {\n output: {\n resource: 'seo',\n id: AI_SEO_OUTPUT_IDS.fixes(unit.batch),\n hostId: job.hostId ?? null,\n label: `SEO audit · fixes ${unit.batch} of ${unit.of}`,\n proposal: plain({ kind: 'fixes', batch: unit.batch, fixes, notes }),\n },\n spent,\n }\n}\n\nasync function runSiteAuditPass(\n context: AiJobStepContext & { firestore: Firestore },\n host: SeoHostDocument,\n): Promise<AiJobStepOutcome> {\n const { job, firestore } = context\n const model = modelOf(context)\n const recorded = aiSeoAuditView(job.outputs ?? [])\n const outputs: AiJobOutput[] = []\n let spent = spentNothing(model)\n let report: AiSeoAuditReport\n let scan: SeoSiteScan | null = null\n if (recorded) {\n report = recorded.report\n } else {\n scan = await scanSite(firestore, job.hostId as string, host, job.inputs?.['keywords'])\n report = aiSeoAudit(scan.pages, seoAuditSiteOf(host), { skipped: scan.skipped, notes: scan.notes })\n const findings = report.pages.reduce((sum, page) => sum + page.findings.length, report.site.length)\n outputs.push({\n resource: 'seo',\n id: AI_SEO_OUTPUT_IDS.report,\n hostId: job.hostId ?? null,\n label: `SEO audit · ${report.pages.length} ${report.pages.length === 1 ? 'page' : 'pages'} · ${findings} ${findings === 1 ? 'finding' : 'findings'}`,\n proposal: plain(report),\n })\n }\n const units = aiSeoPendingUnits(report, [...(job.outputs ?? []), ...outputs])\n if (!units.length) return { outputs, ...spent }\n const [unit] = units\n const result =\n unit.kind === 'site'\n ? await proposeSite(\n context,\n host,\n scan ?? (await scanSite(firestore, job.hostId as string, host, job.inputs?.['keywords'])),\n )\n : await proposeFixes(context, report, unit)\n outputs.push(result.output)\n spent = addSpent(spent, result.spent)\n return { outputs, ...spent, ...(units.length > 1 ? { continue: true } : {}) }\n}\n\nexport const runAiJobSeoStep: AiJobStepRunner = async (context) => {\n const { job, firestore } = context\n if (!firestore) {\n // The machine always hands one in; a runner called without it is a\n // wiring fault, not a customer path.\n throw new Error('the SEO step reads the site it writes about and was given no Firestore')\n }\n const target = aiSeoJobTarget(job.inputs)\n if (!target) return { outputs: [], ...spentNothing(modelOf(context)), failure: AI_SEO_NO_TARGET_COPY }\n const site = await loadSite(firestore, job)\n if ('failure' in site) return { outputs: [], ...spentNothing(modelOf(context)), failure: site.failure }\n const withFirestore = { ...context, firestore }\n switch (target) {\n case 'screen':\n return runScreenListing(withFirestore, site.host)\n case 'product':\n return runProductListing(withFirestore, site.host)\n case 'site':\n return runSiteAuditPass(withFirestore, site.host)\n }\n}\n"],"names":["hostCollectionKind","hostPublicOrigin","buildLlmsTxt","screenRoutePathToUrl","SEO_FINDING_LABELS","SEO_MAX_KEYWORDS","seoKeywordCoverage","seoKeywordSplit","seoQuotedKeywords","SCREEN_SEO_LISTING_FIELDS","isSeoListingFieldKey","SEO_PAGE_TEXT_MAX_CHARS","seoPageFacts","composeSeoPages","scanSeoSite","seoAuditSiteOf","readRepeatRows","decodeStoredNodes","getTemplateScreenIds","AI_SEO_OUTPUT_IDS","aiSeoAuditView","aiSeoJobTarget","aiModelForStep","aiRouteSettings","aiSeoAudit","aiSeoAuditBatches","aiSeoHeadingDemotions","runValidatedGeneration","AI_SEO_FIELDS_MAX_TOKENS","aiFitSeoOverrun","generateSeoFields","AI_SEO_FIXES_TOOL_NAME","AI_SEO_SITE_TOOL_NAME","aiSeoFixImages","aiSeoFixesTool","aiSeoSiteTool","checkAiSeoFixes","checkAiSeoSite","fitAiSeoFixLengths","AI_SEO_FIXES_MAX_TOKENS","AI_SEO_SITE_MAX_TOKENS","aiSeoGenerationMaxTokens","aiCacheWriteHourSum","AI_SEO_NO_SITE_COPY","AI_SEO_NO_PAGE_COPY","AI_SEO_NO_TARGET_COPY","AI_SEO_NO_PRODUCT_COPY","AI_SEO_BATCH_PAGE_TEXT_CHARS","SITE_PAGES_LISTED","PRODUCT_LISTING_FIELDS","ZERO_USAGE","inputTokens","outputTokens","cacheReadTokens","cacheWriteTokens","str","value","trim","round6","Math","round","modelOf","context","modelFor","spentNothing","model","usage","estCostUsd","stopReason","spentBy","generation","addSpent","a","b","plain","JSON","parse","stringify","aiSeoRequestedFields","raw","allowed","named","String","split","map","part","filter","wanted","Set","length","key","has","brandOf","host","seo","title","displayName","subdomain","loadSite","firestore","job","hostId","failure","snapshot","collection","doc","get","exists","data","orgId","siteRepeatRows","keys","composedPageFacts","versions","composed","version","nodes","index","rootId","pageNodes","readVersionNodes","hostRef","screenId","versionId","siteTitles","except","select","limit","docs","id","Boolean","listingOutcome","subject","spent","status","outputs","refused","message","values","notes","fields","includes","hasImage","imageAlt","push","unchecked","proposal","kind","keywords","description","h1","facts","h1s","text","body","output","resource","label","name","runScreenListing","screen","signal","inputs","deletedAt","image","onPage","images","find","src","undefined","route","screens","path","brand","current","breadcrumb","alt","otherTitles","maxTokens","runProductListing","slice","productId","scanSite","templateScreenIds","aiSeoPendingUnits","report","done","units","siteProposal","site","batches","forEach","screenIds","fixes","batch","of","AI_SEO_SITE_INSTRUCTIONS","cacheBreakpoint","aiSeoBlankSiteFields","entity","agent","blank","type","add","email","business","supportEmail","telephone","contactType","whenToUse","howToUse","readContentCollections","slug","aiSeoLlmsPreview","pages","collections","siteName","origin","hasSearch","contactEmail","proposeSite","scan","topLevel","page","replace","telling","test","prompt","join","entry","flatMap","line","siteText","step","instructions","messages","role","content","tool","check","answer","proposed","llmsPreview","AI_SEO_FIXES_INSTRUCTIONS","aiSeoPageFixFor","imageAlts","nodeId","first","promotable","headings","heading","editable","codes","guidance","aiSeoFixesPrompt","titlesElsewhere","titles","blocks","lines","code","proposeFixes","unit","reports","Map","read","Promise","all","pageReport","live","findings","keyword","answers","asked","skipped","runSiteAuditPass","recorded","reduce","sum","result","continue","runAiJobSeoStep","Error","target","withFirestore"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,kBAAkB,QAAQ,yCAAwC;AAC3E,SAASC,gBAAgB,QAAQ,qCAAoC;AACrE,SACEC,YAAY,QAGP,kCAAiC;AACxC,SAASC,oBAAoB,QAAQ,sCAAqC;AAC1E,SAASC,kBAAkB,QAAQ,mCAAkC;AACrE,SACEC,gBAAgB,EAChBC,kBAAkB,EAClBC,eAAe,EACfC,iBAAiB,QACZ,sCAAqC;AAC5C,SACEC,yBAAyB,EACzBC,oBAAoB,QAEf,4CAA2C;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AAOiJ,OAAOjJ,KAAK;IACpC,OAAO;QAAEE;OAAYF,OAAWsD,MAAMlG,MAAM,GAAG,IAAI;QAAE8L,UAAU;IAAK,IAAI,CAAC;AAC3E;AAEA,OAAO,MAAMC,kBAAmC,OAAO1N;IACrD,MAAM,EAAEsC,GAAG,EAAED,SAAS,EAAE,GAAGrC;IAC3B,IAAI,CAACqC,WAAW;QACd,mEAAmE;QACnE,qCAAqC;QACrC,MAAM,IAAIsL,MAAM;IAClB;IACA,MAAMC,SAASrQ,eAAe+E,IAAI8D,MAAM;IACxC,IAAI,CAACwH,QAAQ,OAAO;QAAEnJ,SAAS,EAAE;OAAKvE,aAAaH,QAAQC;QAAWwC,SAASzD;;IAC/E,MAAMgJ,OAAO,MAAM3F,SAASC,WAAWC;IACvC,IAAI,aAAayF,MAAM,OAAO;QAAEtD,SAAS,EAAE;OAAKvE,aAAaH,QAAQC;QAAWwC,SAASuF,KAAKvF,OAAO;;IACrG,MAAMqL,gBAAgB,aAAK7N;QAASqC;;IACpC,OAAQuL;QACN,KAAK;YACH,OAAO3H,iBAAiB4H,eAAe9F,KAAKhG,IAAI;QAClD,KAAK;YACH,OAAOsF,kBAAkBwG,eAAe9F,KAAKhG,IAAI;QACnD,KAAK;YACH,OAAOqL,iBAAiBS,eAAe9F,KAAKhG,IAAI;IACpD;AACF,EAAC"}
@@ -40,8 +40,10 @@ import type { AiJobStepRunner } from './ai-job-text-step';
40
40
  * name and to the same limit: `displayName` (Admin → General, 30), `seo.title`
41
41
  * (60), `seo.description` (155), `seo.separator` (3), `seo.titlePattern`
42
42
  * (120, its own variables only), `seo.entity.name`, `seo.entity.description`
43
- * (300), `seo.entity.telephone`, `business.supportEmail` and
44
- * `business.address` (the Business details card), `locales`/`defaultLocale`
43
+ * (300), `seo.entity.telephone`, `seo.entity.email` with its
44
+ * `business.supportEmail` copy, and the address as `seo.entity.address`'s
45
+ * street with its `business.address` copy (Setup → Business profile's
46
+ * Business details card, AGL-4136), `locales`/`defaultLocale`
45
47
  * (the Languages card), `timeZone` (one of the zones the console offers),
46
48
  * `consent.mode` (the consent banner card), and `seo.favicon`, `logoUrl` and
47
49
  * `seo.image` (with its size and alt) written as the media pickers write
@@ -193,6 +195,8 @@ interface AiSettingsChange {
193
195
  path: string;
194
196
  value: unknown;
195
197
  said: string;
198
+ /** The field is deleted rather than set; `value` is then ignored. */
199
+ remove?: true;
196
200
  }
197
201
  /**
198
202
  * The language change, as the Languages card would save it: a site with no
@@ -51,8 +51,10 @@ import { registerAiJobStep } from "./ai-jobs.js";
51
51
  * name and to the same limit: `displayName` (Admin → General, 30), `seo.title`
52
52
  * (60), `seo.description` (155), `seo.separator` (3), `seo.titlePattern`
53
53
  * (120, its own variables only), `seo.entity.name`, `seo.entity.description`
54
- * (300), `seo.entity.telephone`, `business.supportEmail` and
55
- * `business.address` (the Business details card), `locales`/`defaultLocale`
54
+ * (300), `seo.entity.telephone`, `seo.entity.email` with its
55
+ * `business.supportEmail` copy, and the address as `seo.entity.address`'s
56
+ * street with its `business.address` copy (Setup → Business profile's
57
+ * Business details card, AGL-4136), `locales`/`defaultLocale`
56
58
  * (the Languages card), `timeZone` (one of the zones the console offers),
57
59
  * `consent.mode` (the consent banner card), and `seo.favicon`, `logoUrl` and
58
60
  * `seo.image` (with its size and alt) written as the media pickers write
@@ -360,6 +362,17 @@ function mediaRowOf(doc, org) {
360
362
  fileName: row.fileName || row.id
361
363
  };
362
364
  }
365
+ /**
366
+ * The structured address parts a one-line address leaves empty (AGL-4136):
367
+ * the line is the street, and a city or postal code still stored from an
368
+ * older address would contradict it.
369
+ */ const ADDRESS_PARTS_A_LINE_REPLACES = [
370
+ 'addressLocality',
371
+ 'addressRegion',
372
+ 'postalCode',
373
+ 'addressCountry'
374
+ ];
375
+ /** Whether a stored value is there to delete. */ const isStored = (value)=>value !== undefined && value !== null && !(typeof value === 'string' && value.trim() === '');
363
376
  const getPath = (data, path)=>path.split('.').reduce((at, key)=>at && typeof at === 'object' ? at[key] : undefined, data);
364
377
  const sameValue = (a, b)=>JSON.stringify(a != null ? a : null) === JSON.stringify(b != null ? b : null);
365
378
  /**
@@ -415,8 +428,34 @@ const sameValue = (a, b)=>JSON.stringify(a != null ? a : null) === JSON.stringif
415
428
  if (request.businessName) set('seo.entity.name', request.businessName, `The business name is now “${request.businessName}”.`);
416
429
  if (request.businessDescription) set('seo.entity.description', request.businessDescription, 'The business description is set.');
417
430
  if (request.telephone) set('seo.entity.telephone', request.telephone, `The phone number is now ${request.telephone}.`);
418
- if (request.supportEmail) set('business.supportEmail', request.supportEmail, `The contact email is now ${request.supportEmail}.`);
419
- if (request.address) set('business.address', request.address, 'The address is set.');
431
+ if (request.supportEmail) {
432
+ // The site's one email (AGL-4136): the canonical `seo.entity.email`, and
433
+ // the `business.supportEmail` copy Setup → Business profile keeps in step for the
434
+ // native apps, so every reader shows the new address at once.
435
+ const said = `The contact email is now ${request.supportEmail}.`;
436
+ set('seo.entity.email', request.supportEmail, said);
437
+ set('business.supportEmail', request.supportEmail, said);
438
+ }
439
+ if (request.address) {
440
+ // The address arrives as ONE line, which cannot be split into the parts
441
+ // Setup → Business profile stores (AGL-4136). So the whole line is the
442
+ // street, the other parts are deleted where the site has them, so an
443
+ // older city or postal code cannot contradict it, and the one-block
444
+ // `business.address` copy says the same. Every reader then shows the
445
+ // new address, whichever path it reads.
446
+ const said = 'The address is set.';
447
+ set('seo.entity.address.streetAddress', request.address, said);
448
+ for (const part of ADDRESS_PARTS_A_LINE_REPLACES){
449
+ const path = `seo.entity.address.${part}`;
450
+ if (isStored(getPath(host, path))) changes.push({
451
+ path,
452
+ value: null,
453
+ said,
454
+ remove: true
455
+ });
456
+ }
457
+ set('business.address', request.address, said);
458
+ }
420
459
  if (request.timeZone) set('timeZone', request.timeZone, `The site’s time zone is now ${request.timeZone}.`);
421
460
  if (request.consentMode) {
422
461
  set('consent.mode', request.consentMode, request.consentMode === 'strict' ? 'The cookie banner now asks every visitor.' : 'The cookie banner now asks where the law requires.');
@@ -467,7 +506,7 @@ const sameValue = (a, b)=>JSON.stringify(a != null ? a : null) === JSON.stringif
467
506
  };
468
507
  const data = (_host_data = host.data()) != null ? _host_data : {};
469
508
  const { changes, problems } = aiSettingsChanges(data, input.request, input.media);
470
- const changed = changes.filter((change)=>!sameValue(getPath(data, change.path), change.value));
509
+ const changed = changes.filter((change)=>change.remove ? isStored(getPath(data, change.path)) : !sameValue(getPath(data, change.path), change.value));
471
510
  const done = [
472
511
  ...new Set(changes.map((change)=>change.said))
473
512
  ];
@@ -481,7 +520,7 @@ const sameValue = (a, b)=>JSON.stringify(a != null ? a : null) === JSON.stringif
481
520
  const updates = {
482
521
  updatedAt: input.now
483
522
  };
484
- for (const change of changed)updates[change.path] = change.value;
523
+ for (const change of changed)updates[change.path] = change.remove ? FieldValue.delete() : change.value;
485
524
  tx.update(hostRef, updates);
486
525
  // The announce, written down in the save's own transaction: a setting
487
526
  // has no address, so it asks for the whole site, as the console's does.