@aglyn/plugins-ai 1.22.1 → 1.22.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aglyn/plugins-ai",
3
- "version": "1.22.1",
3
+ "version": "1.22.3",
4
4
  "license": "Apache-2.0",
5
5
  "homepage": "https://aglyn.com",
6
6
  "repository": {
@@ -25,22 +25,22 @@
25
25
  "./package.json": "./package.json"
26
26
  },
27
27
  "dependencies": {
28
- "@aglyn/aglyn": "1.22.1",
29
- "@aglyn/shared-data-enums": "1.22.1",
30
- "@aglyn/shared-data-mdi": "1.22.1",
31
- "@aglyn/shared-data-types": "1.22.1",
32
- "@aglyn/shared-ui-email-campaigns": "1.22.1",
33
- "@aglyn/shared-ui-jsx": "1.22.1",
34
- "@aglyn/shared-ui-snackstack": "1.22.1",
35
- "@aglyn/shared-ui-theme": "1.22.1",
36
- "@aglyn/shared-util-email": "1.22.1",
37
- "@aglyn/shared-util-errors": "1.22.1",
38
- "@aglyn/shared-util-http": "1.22.1",
39
- "@aglyn/shared-util-timestamp": "1.22.1",
40
- "@aglyn/shared-util-tools": "1.22.1",
41
- "@aglyn/tenant-data-admin": "1.22.1",
42
- "@aglyn/tenant-feature-instance": "1.22.1",
43
- "@aglyn/tenant-runtime": "1.22.1",
28
+ "@aglyn/aglyn": "1.22.3",
29
+ "@aglyn/shared-data-enums": "1.22.3",
30
+ "@aglyn/shared-data-mdi": "1.22.3",
31
+ "@aglyn/shared-data-types": "1.22.3",
32
+ "@aglyn/shared-ui-email-campaigns": "1.22.3",
33
+ "@aglyn/shared-ui-jsx": "1.22.3",
34
+ "@aglyn/shared-ui-snackstack": "1.22.3",
35
+ "@aglyn/shared-ui-theme": "1.22.3",
36
+ "@aglyn/shared-util-email": "1.22.3",
37
+ "@aglyn/shared-util-errors": "1.22.3",
38
+ "@aglyn/shared-util-http": "1.22.3",
39
+ "@aglyn/shared-util-timestamp": "1.22.3",
40
+ "@aglyn/shared-util-tools": "1.22.3",
41
+ "@aglyn/tenant-data-admin": "1.22.3",
42
+ "@aglyn/tenant-feature-instance": "1.22.3",
43
+ "@aglyn/tenant-runtime": "1.22.3",
44
44
  "@swc/helpers": "0.5.24"
45
45
  },
46
46
  "peerDependencies": {
@@ -1,7 +1,7 @@
1
1
  import { type MaybeTokenSource } from '@aglyn/shared-util-http/authorized-token';
2
2
  import { type AiCreditsPrompt } from '../model/ai-credit-estimate';
3
3
  import type { AiJobSummary } from '../model/ai-jobs.types';
4
- import type { AiSiteImportFinish } from '../model/ai-site-import';
4
+ import type { AiSiteImportFinish, AiSiteImportPlanChoice } from '../model/ai-site-import';
5
5
  import { type AssistBuildProposal } from '../model/assist-build';
6
6
  import { type AssistPageChangeProposal } from '../model/assist-page-change';
7
7
  /**
@@ -50,7 +50,11 @@ export interface AiJobResumeOptions {
50
50
  finish?: AiSiteImportFinish;
51
51
  /** Under Improve it, whether its main pages' wording is improved too (AGL-4152). */
52
52
  wording?: boolean;
53
+ /** The owner's answer to a generative plan (AGL-4152): whether its proposed page and generated pictures are in. */
54
+ plan?: AiSiteImportPlanChoice;
53
55
  }
56
+ /** The plan answer the resume door reads (AGL-4152): only the switches the owner set. */
57
+ export declare function aiJobResumePlan(plan: AiSiteImportPlanChoice): AiSiteImportPlanChoice;
54
58
  /**
55
59
  * Confirms a plan, or tries again a step whose answer broke a building rule
56
60
  * (AGL-2935). The door runs the next step inline and answers with the job.
@@ -20,6 +20,13 @@ import { AI_CREDITS_CONFIRM_CODE } from "../model/ai-credit-estimate.js";
20
20
  import { assistBuildJobRequest } from "../model/assist-build.js";
21
21
  import { assistPageChangeJobRequest } from "../model/assist-page-change.js";
22
22
  import { publishAiJob } from "./ai-jobs-store.js";
23
+ /** The plan answer the resume door reads (AGL-4152): only the switches the owner set. */ export function aiJobResumePlan(plan) {
24
+ return _extends({}, typeof plan.addPage === 'boolean' ? {
25
+ addPage: plan.addPage
26
+ } : {}, typeof plan.pictures === 'boolean' ? {
27
+ pictures: plan.pictures
28
+ } : {});
29
+ }
23
30
  /**
24
31
  * Confirms a plan, or tries again a step whose answer broke a building rule
25
32
  * (AGL-2935). The door runs the next step inline and answers with the job.
@@ -50,6 +57,8 @@ import { publishAiJob } from "./ai-jobs-store.js";
50
57
  finish: options.finish
51
58
  } : {}, typeof options.wording === 'boolean' ? {
52
59
  wording: options.wording
60
+ } : {}, options.plan ? {
61
+ plan: aiJobResumePlan(options.plan)
53
62
  } : {}))
54
63
  });
55
64
  const payload = await response.json().catch(()=>null);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/components/ai-job-requests.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n'use client'\n\nimport { authorizedFetch, type MaybeTokenSource } from '@aglyn/shared-util-http/authorized-token'\nimport { AI_CREDITS_CONFIRM_CODE, type AiCreditsPrompt } from '../model/ai-credit-estimate'\nimport type { AiJobSummary } from '../model/ai-jobs.types'\nimport type { AiSiteImportFinish } from '../model/ai-site-import'\nimport { assistBuildJobRequest, type AssistBuildProposal } from '../model/assist-build'\nimport { assistPageChangeJobRequest, type AssistPageChangeProposal } from '../model/assist-page-change'\nimport { publishAiJob } from './ai-jobs-store'\n\n/**\n * The two decisions a person makes about a job — confirm its plan (or try a\n * refused step again), and cancel it — as ONE request each, whichever\n * surface they press it on (AGL-3593). The AI jobs drawer and the dialog that\n * started the job both call these, so confirming in the dialog is the same\n * door, the same body and the same answer as confirming in the drawer.\n *\n * Each hands the job it gets back to every counting surface, so the top-bar\n * indicator stops saying \"plan ready\" the moment the plan is confirmed.\n */\n\n/** A door's answer: the job as it now stands, and the refusal when there is one. */\nexport interface AiJobDecision {\n job: AiJobSummary | null\n error: string | null\n /**\n * A Free job past what is left (AGL-3722): the door's 409 asks for the\n * person's go-ahead with these figures and choices instead of starting it.\n */\n credits?: AiCreditsPrompt | null\n /**\n * The usage strip's envelope the job door answered with, when it ran a step\n * inline (AGL-3722): what the plan just spent, so the strip moves with it.\n */\n meter?: unknown\n /** Why each answer a `needs_input` job asked for cannot be used, by field (AGL-3978). */\n fieldErrors?: Record<string, string> | null\n}\n\n/**\n * What a resume asks beyond confirming (AGL-3616): a build's plan confirmed\n * with its publish box ticked, or a finished build's failed items tried again.\n */\nexport interface AiJobResumeOptions {\n publish?: boolean\n retry?: 'failed-items'\n /** \"Build what fits\" (AGL-3722): a Free job past what is left, started on the person's go-ahead. */\n creditsConfirmed?: boolean\n /** \"Build the home page first\" (AGL-3722): the plan narrowed to its home page and what it needs. */\n reduce?: 'first-page'\n /** The answers a job waiting in `needs_input` asks for (AGL-3978), by `aiJobInputKey`. */\n input?: Record<string, string>\n /** \"Start every remaining wave\" (AGL-4084): an import starts its next wave and every one after it. */\n startAll?: boolean\n /** Keep my site or Improve it (AGL-4152): how an import's waves not yet started are built. */\n finish?: AiSiteImportFinish\n /** Under Improve it, whether its main pages' wording is improved too (AGL-4152). */\n wording?: boolean\n}\n\n/**\n * Confirms a plan, or tries again a step whose answer broke a building rule\n * (AGL-2935). The door runs the next step inline and answers with the job.\n */\nexport async function resumeAiJobRequest(\n user: MaybeTokenSource,\n orgId: string,\n job: Pick<AiJobSummary, 'id' | 'hostId'>,\n options: AiJobResumeOptions = {},\n): Promise<AiJobDecision> {\n try {\n const response = await authorizedFetch(\n user,\n `/api/ai/jobs/${encodeURIComponent(job.id)}/resume`,\n {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({\n orgId,\n hostId: job.hostId,\n ...(options.publish ? { publish: true } : {}),\n ...(options.retry ? { retry: options.retry } : {}),\n ...(options.creditsConfirmed ? { creditsConfirmed: true } : {}),\n ...(options.reduce ? { reduce: options.reduce } : {}),\n ...(options.input ? { input: options.input } : {}),\n ...(options.startAll ? { startAll: true } : {}),\n ...(options.finish ? { finish: options.finish } : {}),\n ...(typeof options.wording === 'boolean' ? { wording: options.wording } : {}),\n }),\n },\n )\n const payload = await response.json().catch(() => null)\n const next = (payload?.job as AiJobSummary | undefined) ?? null\n publishAiJob(next)\n const credits =\n response.status === 409 && payload?.code === AI_CREDITS_CONFIRM_CODE\n ? ((payload?.credits as AiCreditsPrompt | undefined) ?? null)\n : null\n return {\n job: next,\n error: response.ok\n ? null\n : String(payload?.error ?? 'The job could not be resumed — try again.'),\n ...(credits ? { credits } : {}),\n ...(payload?.fieldErrors ? { fieldErrors: payload.fieldErrors as Record<string, string> } : {}),\n }\n } catch {\n return { job: null, error: 'The job could not be resumed — try again.' }\n }\n}\n\n/**\n * Starts the build a chat turn proposed (AGL-3616): one `build` job on the\n * proposal's site, through the same door every job is created by, which\n * climbs its own gates and plans inline. What comes back stops at its plan\n * card; nothing is built until the person confirms it.\n */\nexport async function startAssistBuildRequest(\n user: MaybeTokenSource,\n orgId: string,\n proposal: AssistBuildProposal,\n): Promise<AiJobDecision> {\n const failed = 'The build could not be planned — try asking again.'\n try {\n const response = await authorizedFetch(user, '/api/ai/jobs', {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify(assistBuildJobRequest(orgId, proposal)),\n })\n const payload = await response.json().catch(() => null)\n const next = (payload?.job as AiJobSummary | undefined) ?? null\n if (response.ok && next) publishAiJob(next)\n return {\n job: response.ok ? next : null,\n error: response.ok && next ? null : String(payload?.error ?? failed),\n ...(payload?.meter ? { meter: payload.meter } : {}),\n }\n } catch {\n return { job: null, error: failed }\n }\n}\n\n/**\n * Starts the change to a page a chat turn asked for (AGL-4116): one `edit`\n * job on that page, through the door every job is created by, which checks\n * the page and the plan again. There is no plan to confirm: what comes back\n * is the job making the draft, or the reason it could not start.\n * `versionId` continues the draft an earlier change in the conversation made.\n */\nexport async function startAssistPageChangeRequest(\n user: MaybeTokenSource,\n orgId: string,\n proposal: AssistPageChangeProposal,\n versionId: string | null,\n): Promise<AiJobDecision> {\n const failed = 'The change could not be started — try asking again.'\n try {\n const response = await authorizedFetch(user, '/api/ai/jobs', {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify(assistPageChangeJobRequest(orgId, proposal, versionId)),\n })\n const payload = await response.json().catch(() => null)\n const next = (payload?.job as AiJobSummary | undefined) ?? null\n if (response.ok && next) publishAiJob(next)\n return {\n job: response.ok ? next : null,\n error: response.ok && next ? null : String(payload?.error ?? failed),\n ...(payload?.meter ? { meter: payload.meter } : {}),\n }\n } catch {\n return { job: null, error: failed }\n }\n}\n\n/** Cancels a job that has not settled. */\nexport async function cancelAiJobRequest(\n user: MaybeTokenSource,\n orgId: string,\n jobId: string,\n): Promise<AiJobDecision> {\n try {\n const response = await authorizedFetch(\n user,\n `/api/ai/jobs/${encodeURIComponent(jobId)}/cancel`,\n {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({ orgId }),\n },\n )\n const payload = await response.json().catch(() => null)\n const next = (payload?.job as AiJobSummary | undefined) ?? null\n publishAiJob(next)\n return {\n job: next,\n error: response.ok\n ? null\n : String(payload?.error ?? 'The job could not be canceled — try again.'),\n }\n } catch {\n return { job: null, error: 'The job could not be canceled — try again.' }\n }\n}\n"],"names":["authorizedFetch","AI_CREDITS_CONFIRM_CODE","assistBuildJobRequest","assistPageChangeJobRequest","publishAiJob","resumeAiJobRequest","user","orgId","job","options","response","encodeURIComponent","id","method","headers","body","JSON","stringify","hostId","publish","retry","creditsConfirmed","reduce","input","startAll","finish","wording","payload","json","catch","next","credits","status","code","error","ok","String","fieldErrors","startAssistBuildRequest","proposal","failed","meter","startAssistPageChangeRequest","versionId","cancelAiJob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,SAASyB,EAAE,GACd,OACAC,gBAAOT,2BAAAA,QAASO,KAAK,oBAAI;QAC/B;IACF,EAAE,eAAM;QACN,OAAO;YAAE1B,KAAK;YAAM0B,OAAO;QAA6C;IAC1E;AACF"}
1
+ {"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/components/ai-job-requests.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n'use client'\n\nimport { authorizedFetch, type MaybeTokenSource } from '@aglyn/shared-util-http/authorized-token'\nimport { AI_CREDITS_CONFIRM_CODE, type AiCreditsPrompt } from '../model/ai-credit-estimate'\nimport type { AiJobSummary } from '../model/ai-jobs.types'\nimport type { AiSiteImportFinish, AiSiteImportPlanChoice } from '../model/ai-site-import'\nimport { assistBuildJobRequest, type AssistBuildProposal } from '../model/assist-build'\nimport { assistPageChangeJobRequest, type AssistPageChangeProposal } from '../model/assist-page-change'\nimport { publishAiJob } from './ai-jobs-store'\n\n/**\n * The two decisions a person makes about a job — confirm its plan (or try a\n * refused step again), and cancel it — as ONE request each, whichever\n * surface they press it on (AGL-3593). The AI jobs drawer and the dialog that\n * started the job both call these, so confirming in the dialog is the same\n * door, the same body and the same answer as confirming in the drawer.\n *\n * Each hands the job it gets back to every counting surface, so the top-bar\n * indicator stops saying \"plan ready\" the moment the plan is confirmed.\n */\n\n/** A door's answer: the job as it now stands, and the refusal when there is one. */\nexport interface AiJobDecision {\n job: AiJobSummary | null\n error: string | null\n /**\n * A Free job past what is left (AGL-3722): the door's 409 asks for the\n * person's go-ahead with these figures and choices instead of starting it.\n */\n credits?: AiCreditsPrompt | null\n /**\n * The usage strip's envelope the job door answered with, when it ran a step\n * inline (AGL-3722): what the plan just spent, so the strip moves with it.\n */\n meter?: unknown\n /** Why each answer a `needs_input` job asked for cannot be used, by field (AGL-3978). */\n fieldErrors?: Record<string, string> | null\n}\n\n/**\n * What a resume asks beyond confirming (AGL-3616): a build's plan confirmed\n * with its publish box ticked, or a finished build's failed items tried again.\n */\nexport interface AiJobResumeOptions {\n publish?: boolean\n retry?: 'failed-items'\n /** \"Build what fits\" (AGL-3722): a Free job past what is left, started on the person's go-ahead. */\n creditsConfirmed?: boolean\n /** \"Build the home page first\" (AGL-3722): the plan narrowed to its home page and what it needs. */\n reduce?: 'first-page'\n /** The answers a job waiting in `needs_input` asks for (AGL-3978), by `aiJobInputKey`. */\n input?: Record<string, string>\n /** \"Start every remaining wave\" (AGL-4084): an import starts its next wave and every one after it. */\n startAll?: boolean\n /** Keep my site or Improve it (AGL-4152): how an import's waves not yet started are built. */\n finish?: AiSiteImportFinish\n /** Under Improve it, whether its main pages' wording is improved too (AGL-4152). */\n wording?: boolean\n /** The owner's answer to a generative plan (AGL-4152): whether its proposed page and generated pictures are in. */\n plan?: AiSiteImportPlanChoice\n}\n\n/** The plan answer the resume door reads (AGL-4152): only the switches the owner set. */\nexport function aiJobResumePlan(plan: AiSiteImportPlanChoice): AiSiteImportPlanChoice {\n return {\n ...(typeof plan.addPage === 'boolean' ? { addPage: plan.addPage } : {}),\n ...(typeof plan.pictures === 'boolean' ? { pictures: plan.pictures } : {}),\n }\n}\n\n/**\n * Confirms a plan, or tries again a step whose answer broke a building rule\n * (AGL-2935). The door runs the next step inline and answers with the job.\n */\nexport async function resumeAiJobRequest(\n user: MaybeTokenSource,\n orgId: string,\n job: Pick<AiJobSummary, 'id' | 'hostId'>,\n options: AiJobResumeOptions = {},\n): Promise<AiJobDecision> {\n try {\n const response = await authorizedFetch(\n user,\n `/api/ai/jobs/${encodeURIComponent(job.id)}/resume`,\n {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({\n orgId,\n hostId: job.hostId,\n ...(options.publish ? { publish: true } : {}),\n ...(options.retry ? { retry: options.retry } : {}),\n ...(options.creditsConfirmed ? { creditsConfirmed: true } : {}),\n ...(options.reduce ? { reduce: options.reduce } : {}),\n ...(options.input ? { input: options.input } : {}),\n ...(options.startAll ? { startAll: true } : {}),\n ...(options.finish ? { finish: options.finish } : {}),\n ...(typeof options.wording === 'boolean' ? { wording: options.wording } : {}),\n // The plan's two switches: left out, the door keeps the proposed page and generated pictures on.\n ...(options.plan ? { plan: aiJobResumePlan(options.plan) } : {}),\n }),\n },\n )\n const payload = await response.json().catch(() => null)\n const next = (payload?.job as AiJobSummary | undefined) ?? null\n publishAiJob(next)\n const credits =\n response.status === 409 && payload?.code === AI_CREDITS_CONFIRM_CODE\n ? ((payload?.credits as AiCreditsPrompt | undefined) ?? null)\n : null\n return {\n job: next,\n error: response.ok\n ? null\n : String(payload?.error ?? 'The job could not be resumed — try again.'),\n ...(credits ? { credits } : {}),\n ...(payload?.fieldErrors ? { fieldErrors: payload.fieldErrors as Record<string, string> } : {}),\n }\n } catch {\n return { job: null, error: 'The job could not be resumed — try again.' }\n }\n}\n\n/**\n * Starts the build a chat turn proposed (AGL-3616): one `build` job on the\n * proposal's site, through the same door every job is created by, which\n * climbs its own gates and plans inline. What comes back stops at its plan\n * card; nothing is built until the person confirms it.\n */\nexport async function startAssistBuildRequest(\n user: MaybeTokenSource,\n orgId: string,\n proposal: AssistBuildProposal,\n): Promise<AiJobDecision> {\n const failed = 'The build could not be planned — try asking again.'\n try {\n const response = await authorizedFetch(user, '/api/ai/jobs', {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify(assistBuildJobRequest(orgId, proposal)),\n })\n const payload = await response.json().catch(() => null)\n const next = (payload?.job as AiJobSummary | undefined) ?? null\n if (response.ok && next) publishAiJob(next)\n return {\n job: response.ok ? next : null,\n error: response.ok && next ? null : String(payload?.error ?? failed),\n ...(payload?.meter ? { meter: payload.meter } : {}),\n }\n } catch {\n return { job: null, error: failed }\n }\n}\n\n/**\n * Starts the change to a page a chat turn asked for (AGL-4116): one `edit`\n * job on that page, through the door every job is created by, which checks\n * the page and the plan again. There is no plan to confirm: what comes back\n * is the job making the draft, or the reason it could not start.\n * `versionId` continues the draft an earlier change in the conversation made.\n */\nexport async function startAssistPageChangeRequest(\n user: MaybeTokenSource,\n orgId: string,\n proposal: AssistPageChangeProposal,\n versionId: string | null,\n): Promise<AiJobDecision> {\n const failed = 'The change could not be started — try asking again.'\n try {\n const response = await authorizedFetch(user, '/api/ai/jobs', {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify(assistPageChangeJobRequest(orgId, proposal, versionId)),\n })\n const payload = await response.json().catch(() => null)\n const next = (payload?.job as AiJobSummary | undefined) ?? null\n if (response.ok && next) publishAiJob(next)\n return {\n job: response.ok ? next : null,\n error: response.ok && next ? null : String(payload?.error ?? failed),\n ...(payload?.meter ? { meter: payload.meter } : {}),\n }\n } catch {\n return { job: null, error: failed }\n }\n}\n\n/** Cancels a job that has not settled. */\nexport async function cancelAiJobRequest(\n user: MaybeTokenSource,\n orgId: string,\n jobId: string,\n): Promise<AiJobDecision> {\n try {\n const response = await authorizedFetch(\n user,\n `/api/ai/jobs/${encodeURIComponent(jobId)}/cancel`,\n {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({ orgId }),\n },\n )\n const payload = await response.json().catch(() => null)\n const next = (payload?.job as AiJobSummary | undefined) ?? null\n publishAiJob(next)\n return {\n job: next,\n error: response.ok\n ? null\n : String(payload?.error ?? 'The job could not be canceled — try again.'),\n }\n } catch {\n return { job: null, error: 'The job could not be canceled — try again.' }\n }\n}\n"],"names":["authorizedFetch","AI_CREDITS_CONFIRM_CODE","assistBuildJobRequest","assistPageChangeJobRequest","publishAiJob","aiJobResumePlan","plan","addPage","pictures","resumeAiJobRequest","user","orgId","job","options","response","encodeURIComponent","id","method","headers","body","JSON","stringify","hostId","publish","retry","creditsConfirmed","reduce","input","startAll","finish","wording","payload","json","catch","next","credits","status","code","error","ok","String","fieldErrors","startAssistBuildRequest","proposal","failed","meter","startAssistPageChangeRequest","versionId","cancelAiJobRequest","jobId"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GACD;;AAEA,SAASA,eAAe,QAA+B,2CAA0C;AACjG,SAASC,uBAAuB,QAA8B,iCAA6B;AAG3F,SAASC,qBAAqB,QAAkC,2BAAuB;AACvF,SAASC,0BAA0B,QAAuC,iCAA6B;AACvG,SAASC,YAAY,QAAQ,qBAAiB;AAsD9C,uFAAuF,GACvF,OAAO,SAASC,gBAAgBC,IAA4B;IAC1D,OAAO,aACD,OAAOA,KAAKC,OAAO,KAAK,YAAY;QAAEA,SAASD,KAAKC,OAAO;IAAC,IAAI,CAAC,GACjE,OAAOD,KAAKE,QAAQ,KAAK,YAAY;QAAEA,UAAUF,KAAKE,QAAQ;IAAC,IAAI,CAAC;AAE5E;AAEA;;;CAGC,GACD,OAAO,eAAeC,mBACpBC,IAAsB,EACtBC,KAAa,EACbC,GAAwC,EACxCC,UAA8B,CAAC,CAAC;IAEhC,IAAI;;QACF,MAAMC,WAAW,MAAMd,gBACrBU,MACA,CAAC,aAAa,EAAEK,mBAAmBH,IAAII,EAAE,EAAE,OAAO,CAAC,EACnD;YACEC,QAAQ;YACRC,SAAS;gBAAE,gBAAgB;YAAmB;YAC9CC,MAAMC,KAAKC,SAAS,CAAC;gBACnBV;gBACAW,QAAQV,IAAIU,MAAM;eACdT,QAAQU,OAAO,GAAG;gBAAEA,SAAS;YAAK,IAAI,CAAC,GACvCV,QAAQW,KAAK,GAAG;gBAAEA,OAAOX,QAAQW,KAAK;YAAC,IAAI,CAAC,GAC5CX,QAAQY,gBAAgB,GAAG;gBAAEA,kBAAkB;YAAK,IAAI,CAAC,GACzDZ,QAAQa,MAAM,GAAG;gBAAEA,QAAQb,QAAQa,MAAM;YAAC,I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,OAAOM;QAAO;IACpC;AACF;AAEA,wCAAwC,GACxC,OAAO,eAAeI,mBACpBtC,IAAsB,EACtBC,KAAa,EACbsC,KAAa;IAEb,IAAI;;QACF,MAAMnC,WAAW,MAAMd,gBACrBU,MACA,CAAC,aAAa,EAAEK,mBAAmBkC,OAAO,OAAO,CAAC,EAClD;YACEhC,QAAQ;YACRC,SAAS;gBAAE,gBAAgB;YAAmB;YAC9CC,MAAMC,KAAKC,SAAS,CAAC;gBAAEV;YAAM;QAC/B;QAEF,MAAMoB,UAAU,MAAMjB,SAASkB,IAAI,GAAGC,KAAK,CAAC,IAAM;QAClD,MAAMC,eAAQH,2BAAAA,QAASnB,GAAG,mBAAiC;QAC3DR,aAAa8B;QACb,OAAO;YACLtB,KAAKsB;YACLI,OAAOxB,SAASyB,EAAE,GACd,OACAC,gBAAOT,2BAAAA,QAASO,KAAK,oBAAI;QAC/B;IACF,EAAE,eAAM;QACN,OAAO;YAAE1B,KAAK;YAAM0B,OAAO;QAA6C;IAC1E;AACF"}
@@ -21,6 +21,12 @@ import type { AiLayoutSection } from '../layout-language/ai-layout-language';
21
21
  * trailing slash, anything else as written.
22
22
  */
23
23
  export declare function aiSiteImportDestinationKey(to: string): string;
24
+ /**
25
+ * A call button's words without the stray mark its source left after the
26
+ * verb (AGL-4152): a contractor's "Call- 555-010-0142" reads "Call
27
+ * 555-010-0142". Only the mark goes; every word stays as written.
28
+ */
29
+ export declare function aiSiteImportCallLabel(text: string): string;
24
30
  /**
25
31
  * A redesigned section's calls to action, each once and each where it belongs
26
32
  * (AGL-4152), whatever the answer and the source's kept groups gave:
@@ -39,6 +45,7 @@ export declare function aiSiteImportDestinationKey(to: string): string;
39
45
  * words where one of them has them. A call and a page are two places. A
40
46
  * closing band's "Contact us" and "Request a quote", both to the contact
41
47
  * page with a call between them, read as a mistake.
48
+ * - A call button's words lose a stray mark after the verb ("Call- 555…").
42
49
  * - Of buttons side by side, only the first is filled; the rest are outlined.
43
50
  */
44
51
  export declare function aiSiteImportSectionActions(section: Pick<AiLayoutSection, 'cols' | 'blocks'>, cta?: string | null): Pick<AiLayoutSection, 'cols' | 'blocks'>;
@@ -35,6 +35,13 @@ const clean = (text)=>typeof text === 'string' ? text.replace(/\s+/g, ' ').trim(
35
35
  if (/^https?:\/\//i.test(value)) return value.toLowerCase().replace(/^http:/, 'https:').replace(/[/?#]+$/, '');
36
36
  return value;
37
37
  }
38
+ /**
39
+ * A call button's words without the stray mark its source left after the
40
+ * verb (AGL-4152): a contractor's "Call- 555-010-0142" reads "Call
41
+ * 555-010-0142". Only the mark goes; every word stays as written.
42
+ */ export function aiSiteImportCallLabel(text) {
43
+ return text.replace(/^(\s*(?:call|text|phone|tel)\b)\s*[-\u2013\u2014:|]+\s*(?=[+(\d])/i, '$1 ');
44
+ }
38
45
  /** Whether a button is drawn filled: the compiler's default, `primary` or `large`. */ const filled = (block)=>block.kind === 'button' && (block.style === undefined || block.style === 'primary' || block.style === 'large');
39
46
  /**
40
47
  * A redesigned section's calls to action, each once and each where it belongs
@@ -54,6 +61,7 @@ const clean = (text)=>typeof text === 'string' ? text.replace(/\s+/g, ' ').trim(
54
61
  * words where one of them has them. A call and a page are two places. A
55
62
  * closing band's "Contact us" and "Request a quote", both to the contact
56
63
  * page with a call between them, read as a mistake.
64
+ * - A call button's words lose a stray mark after the verb ("Call- 555…").
57
65
  * - Of buttons side by side, only the first is filled; the rest are outlined.
58
66
  */ export function aiSiteImportSectionActions(section, cta) {
59
67
  let { cols, blocks } = section;
@@ -213,6 +221,13 @@ const clean = (text)=>typeof text === 'string' ? text.replace(/\s+/g, ' ').trim(
213
221
  }) : block
214
222
  ];
215
223
  });
224
+ // A call button's words without a stray mark after the verb.
225
+ blocks = blocks.map((block)=>{
226
+ var _block_to;
227
+ return block.kind === 'button' && /^tel:/i.test((_block_to = block.to) != null ? _block_to : '') && block.text ? _extends({}, block, {
228
+ text: aiSiteImportCallLabel(block.text)
229
+ }) : block;
230
+ });
216
231
  // Buttons side by side, each to its own place: the first filled.
217
232
  const out = [];
218
233
  for (const block of blocks){
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/jobs/ai-site-import-actions.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/*==========================================\n * A PAGE'S CALLS TO ACTION UNDER IMPROVE IT (AGL-4152).\n *\n * The mechanical tidying of a section's buttons, the same whether a\n * redesign drew the page or the page kept its source's layout: each call to\n * action once, where it belongs. No model is asked; nothing is reworded.\n *=========================================*/\n\nimport type { AiLayoutBlock, AiLayoutItem, AiLayoutSection } from '../layout-language/ai-layout-language'\n\nconst clean = (text: unknown): string => (typeof text === 'string' ? text.replace(/\\s+/g, ' ').trim() : '')\n\n/** A button's words and where it goes, as one key: two that share it are the same action. */\nconst actionKey = (text: string | undefined, to: string | undefined): string => `${clean(text).toLowerCase()}\\u0000${to ?? ''}`\n\n/** How strongly a button asks: filled 0, outlined 1, quiet 2. */\nconst strength = (block: AiLayoutBlock): number => (filled(block) ? 0 : block.style === 'secondary' ? 1 : 2)\n\n/**\n * Where a button goes, as two that go to one place share it (AGL-4152): a\n * phone by its digits, an email and a web address in any case and without a\n * trailing slash, anything else as written.\n */\nexport function aiSiteImportDestinationKey(to: string): string {\n const value = to.trim()\n if (/^tel:/i.test(value)) return `tel:${value.slice(4).replace(/[^\\d+]/g, '')}`\n if (/^mailto:/i.test(value)) return value.toLowerCase()\n if (/^https?:\\/\\//i.test(value)) return value.toLowerCase().replace(/^http:/, 'https:').replace(/[/?#]+$/, '')\n return value\n}\n\n/** Whether a button is drawn filled: the compiler's default, `primary` or `large`. */\nconst filled = (block: AiLayoutBlock): boolean => block.kind === 'button' && (block.style === undefined || block.style === 'primary' || block.style === 'large')\n\n/**\n * A redesigned section's calls to action, each once and each where it belongs\n * (AGL-4152), whatever the answer and the source's kept groups gave:\n *\n * - Buttons placed in a row's columns under a group that runs the row's width,\n * with nothing else in those columns, sit in the cards they go to where each\n * goes where exactly one card does, else together under the group: a row of\n * two buttons under three cards read as a grid half filled.\n * - A link with the same words to the same place on every item of a group\n * (each review's \"See more reviews\") is shown once, as a button after the\n * group, unless the section already has that button. Where only some items\n * carry it, each is that item's own action and stays.\n * - The same button twice in a section is shown once, the first.\n * - Buttons anywhere in a section to the same place are one: the strongest,\n * filled over outlined over quiet, the first of equals, with the header's\n * words where one of them has them. A call and a page are two places. A\n * closing band's \"Contact us\" and \"Request a quote\", both to the contact\n * page with a call between them, read as a mistake.\n * - Of buttons side by side, only the first is filled; the rest are outlined.\n */\nexport function aiSiteImportSectionActions(section: Pick<AiLayoutSection, 'cols' | 'blocks'>, cta?: string | null): Pick<AiLayoutSection, 'cols' | 'blocks'> {\n let { cols, blocks } = section\n // Buttons in columns under a group across the row.\n const placed = blocks.filter((block) => block.col !== undefined)\n const group = blocks.find((block) => block.col === undefined && (block.items?.length ?? 0) >= 2 && block.kind !== 'list' && block.kind !== 'faq')\n if (cols && cols.length >= 2 && group && placed.length && placed.every((block) => block.kind === 'button')) {\n const items = group.items as AiLayoutItem[]\n const cards = placed.map((button) => items.flatMap((item, at) => (button.to && item.to === button.to && !item.links?.length ? [at] : [])))\n const own = cards.every((found) => found.length === 1) && new Set(cards.map((found) => found[0])).size === cards.length\n if (own) {\n const into = new Map(placed.map((button, at) => [cards[at]?.[0] as number, button]))\n const carded = { ...group, items: items.map((item, at) => (into.has(at) ? { ...item, links: [{ text: into.get(at)?.text ?? '', to: item.to as string, style: 'secondary' as const }] } : item)) }\n blocks = blocks.flatMap((block) => (block === group ? [carded] : placed.includes(block) ? [] : [block]))\n } else blocks = blocks.map((block) => (placed.includes(block) ? (({ col: _col, ...rest }) => rest)(block) : block))\n cols = undefined\n }\n // A link repeated across a group's items, once after the group.\n const buttons = new Set(blocks.flatMap((block) => (block.kind === 'button' ? [actionKey(block.text, block.to)] : [])))\n blocks = blocks.flatMap((block) => {\n const items = block.items\n if (!items || items.length < 2) return [block]\n const counted = new Map<string, { text: string; to?: string; style?: AiLayoutBlock['style']; on: number }>()\n for (const item of items) {\n for (const key of new Set((item.links ?? []).map((link) => actionKey(link.text, link.to)))) {\n const link = item.links?.find((entry) => actionKey(entry.text, entry.to) === key)\n const was = counted.get(key)\n if (link) counted.set(key, { text: link.text, ...(link.to ? { to: link.to } : {}), ...(link.style ? { style: link.style } : {}), on: (was?.on ?? 0) + 1 })\n }\n }\n const repeated = new Map([...counted].filter(([, entry]) => entry.on === items.length))\n if (!repeated.size) return [block]\n const stripped = items.map((item) => {\n if (!item.links?.length) return item\n const links = item.links.filter((link) => !repeated.has(actionKey(link.text, link.to)))\n const { links: _links, ...rest } = item\n return links.length ? { ...rest, links } : rest\n })\n const after = [...repeated].flatMap(([key, entry]): AiLayoutBlock[] => {\n if (buttons.has(key)) return []\n buttons.add(key)\n return [{ kind: 'button', text: entry.text, ...(entry.to ? { to: entry.to } : {}), ...(entry.style ? { style: entry.style } : {}), ...(block.col !== undefined ? { col: block.col } : {}) }]\n })\n return [{ ...block, items: stripped }, ...after]\n })\n // The same button twice, once.\n const seen = new Set<string>()\n blocks = blocks.filter((block) => {\n if (block.kind !== 'button' || !block.to) return true\n const key = actionKey(block.text, block.to)\n if (seen.has(key)) return false\n seen.add(key)\n return true\n })\n // Buttons anywhere in the section to one place: one, the strongest (filled over outlined over quiet), the first of\n // equals, in its own place; with the header's words where one of them has them. A call and a page are two places.\n const wanted = clean(cta).toLowerCase()\n const kept = new Map<string, AiLayoutBlock>()\n const worded = new Map<string, AiLayoutBlock>()\n for (const block of blocks) {\n if (block.kind !== 'button' || !block.to) continue\n const key = aiSiteImportDestinationKey(block.to)\n const was = kept.get(key)\n if (!was || strength(block) < strength(was)) kept.set(key, block)\n if (wanted && clean(block.text).toLowerCase() === wanted && !worded.has(key)) worded.set(key, block)\n }\n blocks = blocks.flatMap((block) => {\n if (block.kind !== 'button' || !block.to) return [block]\n const key = aiSiteImportDestinationKey(block.to)\n if (kept.get(key) !== block) return []\n const words = worded.get(key)\n return [words && clean(block.text).toLowerCase() !== wanted ? { ...block, text: words.text } : block]\n })\n // Buttons side by side, each to its own place: the first filled.\n const out: AiLayoutBlock[] = []\n for (const block of blocks) {\n const before = out[out.length - 1]\n if (block.kind === 'button' && before?.kind === 'button' && before.col === block.col) {\n // Back over the run this button stands in.\n let start = out.length - 1\n while (start > 0 && out[start - 1]?.kind === 'button' && out[start - 1]?.col === block.col) start -= 1\n const run = out.slice(start)\n out.push(run.some(filled) && filled(block) ? { ...block, style: 'secondary' } : block)\n continue\n }\n out.push(block)\n }\n return { ...(cols ? { cols } : {}), blocks: out }\n}\n"],"names":["clean","text","replace","trim","actionKey","to","toLowerCase","strength","block","filled","style","aiSiteImportDestinationKey","value","test","slice","kind","undefined","aiSiteImportSectionActions","section","cta","cols","blocks","placed","filter","col","group","find","items","length","every","cards","map","button","flatMap","item","at","links","own","found","Set","size","into","Map","carded","has","get","includes","_col","rest","buttons","counted","key","link","entry","was","set","on","repeated","stripped","_links","after","add","seen","wanted","kept","worded","words","out","before","start","run","push","some"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED;;;;;;2CAM2C;;AAI3C,MAAMA,QAAQ,CAACC,OAA2B,OAAOA,SAAS,WAAWA,KAAKC,OAAO,CAAC,QAAQ,KAAKC,IAAI,KAAK;AAExG,2FAA2F,GAC3F,MAAMC,YAAY,CAACH,MAA0BI,KAAmC,GAAGL,MAAMC,MAAMK,WAAW,GAAG,MAAM,EAAED,aAAAA,KAAM,IAAI;AAE/H,+DAA+D,GAC/D,MAAME,WAAW,CAACC,QAAkCC,OAAOD,SAAS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E2C,OAAqCA;YAFzD,2CAA2C;YAC3C,IAAIE,QAAQF,IAAIvC,MAAM,GAAG;YACzB,MAAOyC,QAAQ,KAAKF,EAAAA,QAAAA,GAAG,CAACE,QAAQ,EAAE,qBAAdF,MAAgBpD,IAAI,MAAK,YAAYoD,EAAAA,SAAAA,GAAG,CAACE,QAAQ,EAAE,qBAAdF,OAAgB3C,GAAG,MAAKhB,MAAMgB,GAAG,CAAE6C,SAAS;YACrG,MAAMC,MAAMH,IAAIrD,KAAK,CAACuD;YACtBF,IAAII,IAAI,CAACD,IAAIE,IAAI,CAAC/D,WAAWA,OAAOD,SAAS,aAAKA;gBAAOE,OAAO;iBAAgBF;YAChF;QACF;QACA2D,IAAII,IAAI,CAAC/D;IACX;IACA,OAAO,aAAMY,OAAO;QAAEA;IAAK,IAAI,CAAC;QAAIC,QAAQ8C;;AAC9C"}
1
+ {"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/jobs/ai-site-import-actions.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/*==========================================\n * A PAGE'S CALLS TO ACTION UNDER IMPROVE IT (AGL-4152).\n *\n * The mechanical tidying of a section's buttons, the same whether a\n * redesign drew the page or the page kept its source's layout: each call to\n * action once, where it belongs. No model is asked; nothing is reworded.\n *=========================================*/\n\nimport type { AiLayoutBlock, AiLayoutItem, AiLayoutSection } from '../layout-language/ai-layout-language'\n\nconst clean = (text: unknown): string => (typeof text === 'string' ? text.replace(/\\s+/g, ' ').trim() : '')\n\n/** A button's words and where it goes, as one key: two that share it are the same action. */\nconst actionKey = (text: string | undefined, to: string | undefined): string => `${clean(text).toLowerCase()}\\u0000${to ?? ''}`\n\n/** How strongly a button asks: filled 0, outlined 1, quiet 2. */\nconst strength = (block: AiLayoutBlock): number => (filled(block) ? 0 : block.style === 'secondary' ? 1 : 2)\n\n/**\n * Where a button goes, as two that go to one place share it (AGL-4152): a\n * phone by its digits, an email and a web address in any case and without a\n * trailing slash, anything else as written.\n */\nexport function aiSiteImportDestinationKey(to: string): string {\n const value = to.trim()\n if (/^tel:/i.test(value)) return `tel:${value.slice(4).replace(/[^\\d+]/g, '')}`\n if (/^mailto:/i.test(value)) return value.toLowerCase()\n if (/^https?:\\/\\//i.test(value)) return value.toLowerCase().replace(/^http:/, 'https:').replace(/[/?#]+$/, '')\n return value\n}\n\n/**\n * A call button's words without the stray mark its source left after the\n * verb (AGL-4152): a contractor's \"Call- 555-010-0142\" reads \"Call\n * 555-010-0142\". Only the mark goes; every word stays as written.\n */\nexport function aiSiteImportCallLabel(text: string): string {\n return text.replace(/^(\\s*(?:call|text|phone|tel)\\b)\\s*[-\\u2013\\u2014:|]+\\s*(?=[+(\\d])/i, '$1 ')\n}\n\n/** Whether a button is drawn filled: the compiler's default, `primary` or `large`. */\nconst filled = (block: AiLayoutBlock): boolean => block.kind === 'button' && (block.style === undefined || block.style === 'primary' || block.style === 'large')\n\n/**\n * A redesigned section's calls to action, each once and each where it belongs\n * (AGL-4152), whatever the answer and the source's kept groups gave:\n *\n * - Buttons placed in a row's columns under a group that runs the row's width,\n * with nothing else in those columns, sit in the cards they go to where each\n * goes where exactly one card does, else together under the group: a row of\n * two buttons under three cards read as a grid half filled.\n * - A link with the same words to the same place on every item of a group\n * (each review's \"See more reviews\") is shown once, as a button after the\n * group, unless the section already has that button. Where only some items\n * carry it, each is that item's own action and stays.\n * - The same button twice in a section is shown once, the first.\n * - Buttons anywhere in a section to the same place are one: the strongest,\n * filled over outlined over quiet, the first of equals, with the header's\n * words where one of them has them. A call and a page are two places. A\n * closing band's \"Contact us\" and \"Request a quote\", both to the contact\n * page with a call between them, read as a mistake.\n * - A call button's words lose a stray mark after the verb (\"Call- 555…\").\n * - Of buttons side by side, only the first is filled; the rest are outlined.\n */\nexport function aiSiteImportSectionActions(section: Pick<AiLayoutSection, 'cols' | 'blocks'>, cta?: string | null): Pick<AiLayoutSection, 'cols' | 'blocks'> {\n let { cols, blocks } = section\n // Buttons in columns under a group across the row.\n const placed = blocks.filter((block) => block.col !== undefined)\n const group = blocks.find((block) => block.col === undefined && (block.items?.length ?? 0) >= 2 && block.kind !== 'list' && block.kind !== 'faq')\n if (cols && cols.length >= 2 && group && placed.length && placed.every((block) => block.kind === 'button')) {\n const items = group.items as AiLayoutItem[]\n const cards = placed.map((button) => items.flatMap((item, at) => (button.to && item.to === button.to && !item.links?.length ? [at] : [])))\n const own = cards.every((found) => found.length === 1) && new Set(cards.map((found) => found[0])).size === cards.length\n if (own) {\n const into = new Map(placed.map((button, at) => [cards[at]?.[0] as number, button]))\n const carded = { ...group, items: items.map((item, at) => (into.has(at) ? { ...item, links: [{ text: into.get(at)?.text ?? '', to: item.to as string, style: 'secondary' as const }] } : item)) }\n blocks = blocks.flatMap((block) => (block === group ? [carded] : placed.includes(block) ? [] : [block]))\n } else blocks = blocks.map((block) => (placed.includes(block) ? (({ col: _col, ...rest }) => rest)(block) : block))\n cols = undefined\n }\n // A link repeated across a group's items, once after the group.\n const buttons = new Set(blocks.flatMap((block) => (block.kind === 'button' ? [actionKey(block.text, block.to)] : [])))\n blocks = blocks.flatMap((block) => {\n const items = block.items\n if (!items || items.length < 2) return [block]\n const counted = new Map<string, { text: string; to?: string; style?: AiLayoutBlock['style']; on: number }>()\n for (const item of items) {\n for (const key of new Set((item.links ?? []).map((link) => actionKey(link.text, link.to)))) {\n const link = item.links?.find((entry) => actionKey(entry.text, entry.to) === key)\n const was = counted.get(key)\n if (link) counted.set(key, { text: link.text, ...(link.to ? { to: link.to } : {}), ...(link.style ? { style: link.style } : {}), on: (was?.on ?? 0) + 1 })\n }\n }\n const repeated = new Map([...counted].filter(([, entry]) => entry.on === items.length))\n if (!repeated.size) return [block]\n const stripped = items.map((item) => {\n if (!item.links?.length) return item\n const links = item.links.filter((link) => !repeated.has(actionKey(link.text, link.to)))\n const { links: _links, ...rest } = item\n return links.length ? { ...rest, links } : rest\n })\n const after = [...repeated].flatMap(([key, entry]): AiLayoutBlock[] => {\n if (buttons.has(key)) return []\n buttons.add(key)\n return [{ kind: 'button', text: entry.text, ...(entry.to ? { to: entry.to } : {}), ...(entry.style ? { style: entry.style } : {}), ...(block.col !== undefined ? { col: block.col } : {}) }]\n })\n return [{ ...block, items: stripped }, ...after]\n })\n // The same button twice, once.\n const seen = new Set<string>()\n blocks = blocks.filter((block) => {\n if (block.kind !== 'button' || !block.to) return true\n const key = actionKey(block.text, block.to)\n if (seen.has(key)) return false\n seen.add(key)\n return true\n })\n // Buttons anywhere in the section to one place: one, the strongest (filled over outlined over quiet), the first of\n // equals, in its own place; with the header's words where one of them has them. A call and a page are two places.\n const wanted = clean(cta).toLowerCase()\n const kept = new Map<string, AiLayoutBlock>()\n const worded = new Map<string, AiLayoutBlock>()\n for (const block of blocks) {\n if (block.kind !== 'button' || !block.to) continue\n const key = aiSiteImportDestinationKey(block.to)\n const was = kept.get(key)\n if (!was || strength(block) < strength(was)) kept.set(key, block)\n if (wanted && clean(block.text).toLowerCase() === wanted && !worded.has(key)) worded.set(key, block)\n }\n blocks = blocks.flatMap((block) => {\n if (block.kind !== 'button' || !block.to) return [block]\n const key = aiSiteImportDestinationKey(block.to)\n if (kept.get(key) !== block) return []\n const words = worded.get(key)\n return [words && clean(block.text).toLowerCase() !== wanted ? { ...block, text: words.text } : block]\n })\n // A call button's words without a stray mark after the verb.\n blocks = blocks.map((block) => (block.kind === 'button' && /^tel:/i.test(block.to ?? '') && block.text ? { ...block, text: aiSiteImportCallLabel(block.text) } : block))\n // Buttons side by side, each to its own place: the first filled.\n const out: AiLayoutBlock[] = []\n for (const block of blocks) {\n const before = out[out.length - 1]\n if (block.kind === 'button' && before?.kind === 'button' && before.col === block.col) {\n // Back over the run this button stands in.\n let start = out.length - 1\n while (start > 0 && out[start - 1]?.kind === 'button' && out[start - 1]?.col === block.col) start -= 1\n const run = out.slice(start)\n out.push(run.some(filled) && filled(block) ? { ...block, style: 'secondary' } : block)\n continue\n }\n out.push(block)\n }\n return { ...(cols ? { cols } : {}), blocks: out }\n}\n"],"names":["clean","text","replace","trim","actionKey","to","toLowerCase","strength","block","filled","style","aiSiteImportDestinationKey","value","test","slice","aiSiteImportCallLabel","kind","undefined","aiSiteImportSectionActions","section","cta","cols","blocks","placed","filter","col","group","find","items","length","every","cards","map","button","flatMap","item","at","links","own","found","Set","size","into","Map","carded","has","get","includes","_col","rest","buttons","counted","key","link","entry","was","set","on","repeated","stripped","_links","after","add","seen","wanted","kept","worded","words","out","before","start","run","push","some"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED;;;;;;2CAM2C;;AAI3C,MAAMA,QAAQ,CAACC,OAA2B,OAAOA,SAAS,WAAWA,KAAKC,OAAO,CAAC,QAAQ,KAAKC,IAAI,KAAK;AAExG,2FAA2F,GAC3F,MAAMC,YAAY,CAACH,MAA0BI,KAAmC,GAAGL,MAAMC,MAAMK,WAAW,GAAG,MAAM,EAAED,aAAAA,KAAM,IAAI;AAE/H,+DAA+D,GAC/D,MAAME,WAAW,CAACC,QAAkCC,OAAOD,SAAS,IAAIA,MAAME,KAAK,KAAK,cAAc,IAAI;AAE1G;;;;CAIC,GACD,OAAO,SAASC,2BAA2BN,EAAU;IACnD,MAAMO,QAAQP,GAAGF,IAAI;IACrB,IAAI,SAASU,IAAI,CAACD,QAAQ,OAAO,CAAC,IAAI,EAAEA,MAAME,KAAK,CAAC,GAAGZ,OAAO,CAAC,WAAW,KAAK;IAC/E,IAAI,YAAYW,IAAI,CAACD,QAAQ,OAAOA,MAAMN,WAAW;IACrD,IAAI,gBAAgBO,IAAI,CAACD,QAAQ,OAAOA,MAA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C,OAAqCA;YAFzD,2CAA2C;YAC3C,IAAIE,QAAQF,IAAIvC,MAAM,GAAG;YACzB,MAAOyC,QAAQ,KAAKF,EAAAA,QAAAA,GAAG,CAACE,QAAQ,EAAE,qBAAdF,MAAgBpD,IAAI,MAAK,YAAYoD,EAAAA,SAAAA,GAAG,CAACE,QAAQ,EAAE,qBAAdF,OAAgB3C,GAAG,MAAKjB,MAAMiB,GAAG,CAAE6C,SAAS;YACrG,MAAMC,MAAMH,IAAItD,KAAK,CAACwD;YACtBF,IAAII,IAAI,CAACD,IAAIE,IAAI,CAAChE,WAAWA,OAAOD,SAAS,aAAKA;gBAAOE,OAAO;iBAAgBF;YAChF;QACF;QACA4D,IAAII,IAAI,CAAChE;IACX;IACA,OAAO,aAAMa,OAAO;QAAEA;IAAK,IAAI,CAAC;QAAIC,QAAQ8C;;AAC9C"}
@@ -1374,10 +1374,53 @@ function takeItems(scope, items) {
1374
1374
  const kept = takeItems(scope, items);
1375
1375
  items.length = kept.length;
1376
1376
  }
1377
+ /**
1378
+ * A row's icons, every item or none (AGL-4152). A row the design gave icons
1379
+ * drew a card with none where its word was one the library does not have: a
1380
+ * contractor's redesigned services row showed icons on two cards of three.
1381
+ * An item whose word names nothing takes one its own words suggest, else the
1382
+ * row's neutral icon; a row where fewer than half the items name an icon
1383
+ * draws none. A row with the source's own drawings stays as it is.
1384
+ */ function evenItemIcons(scope, block, items) {
1385
+ var _scope_words;
1386
+ if (items.length < 2 || items.some((item)=>item.iconPath) || aiIconOfWord(block.icon)) return items.slice();
1387
+ const named = items.filter((item)=>{
1388
+ var _item_icon;
1389
+ return (_item_icon = item.icon) == null ? void 0 : _item_icon.trim();
1390
+ }).length;
1391
+ const drawn = items.filter((item)=>aiIconOfWord(item.icon)).length;
1392
+ if (drawn === 0 || drawn === items.length) return items.slice();
1393
+ if (named * 2 <= items.length) {
1394
+ scope.page.settled.push({
1395
+ at: scope.at,
1396
+ what: `${items.length} items drawn with no icon, ${drawn} of them named one`
1397
+ });
1398
+ return items.map((_0)=>{
1399
+ let { icon: _icon } = _0, item = _object_without_properties_loose(_0, [
1400
+ "icon"
1401
+ ]);
1402
+ return item;
1403
+ });
1404
+ }
1405
+ const words = aiStorefrontItemIcons(items, (word)=>!!aiIconOfWord(word), _extends({
1406
+ section: (_scope_words = scope.words) != null ? _scope_words : ''
1407
+ }, scope.page.design ? {
1408
+ kind: scope.page.design.input.kind
1409
+ } : {}));
1410
+ scope.page.settled.push({
1411
+ at: scope.at,
1412
+ what: `${items.length - drawn} of ${items.length} items given an icon their words suggest`
1413
+ });
1414
+ return items.map((item, at)=>aiIconOfWord(item.icon) ? item : _extends({}, item, {
1415
+ icon: words[at]
1416
+ }));
1417
+ }
1377
1418
  function group(scope, block, room) {
1378
- var _block_items;
1379
- if (scope.page.options.verbatim) return importedGroup(scope, block, room);
1380
- const items = takeItems(scope, cleanItems(scope, (_block_items = block.items) != null ? _block_items : []));
1419
+ var _block_items, _block_items1;
1420
+ if (scope.page.options.verbatim) return importedGroup(scope, _extends({}, block, {
1421
+ items: evenItemIcons(scope, block, (_block_items = block.items) != null ? _block_items : [])
1422
+ }), room);
1423
+ const items = takeItems(scope, evenItemIcons(scope, block, cleanItems(scope, (_block_items1 = block.items) != null ? _block_items1 : [])));
1381
1424
  if (!items.length) return null;
1382
1425
  const perRow = across(items.length, room, block.kind);
1383
1426
  const placed = componentOf(scope.page.targets, block.to);