@aglyn/plugins-ai 1.2.0 → 1.4.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.
- package/package.json +17 -17
- package/src/lib/components/ai-insight-dialog.component.js +7 -2
- package/src/lib/components/ai-insight-dialog.component.js.map +1 -1
- package/src/lib/components/ai-job-request.component.d.ts +28 -0
- package/src/lib/components/ai-job-request.component.js +103 -0
- package/src/lib/components/ai-job-request.component.js.map +1 -0
- package/src/lib/components/ai-jobs-list-page.component.d.ts +2 -0
- package/src/lib/components/ai-jobs-list-page.component.js +2 -2
- package/src/lib/components/ai-jobs-list-page.component.js.map +1 -1
- package/src/lib/components/ai-site-build-page.component.js +36 -6
- package/src/lib/components/ai-site-build-page.component.js.map +1 -1
- package/src/lib/components/ai-site-import-job.component.js +2 -2
- package/src/lib/components/ai-site-import-job.component.js.map +1 -1
- package/src/lib/insights/ai-insight-digest.d.ts +34 -5
- package/src/lib/insights/ai-insight-digest.js +171 -10
- package/src/lib/insights/ai-insight-digest.js.map +1 -1
- package/src/lib/jobs/ai-job-import-step.d.ts +35 -2
- package/src/lib/jobs/ai-job-import-step.js +124 -12
- package/src/lib/jobs/ai-job-import-step.js.map +1 -1
- package/src/lib/jobs/ai-job-insight-step.d.ts +1 -1
- package/src/lib/jobs/ai-job-insight-step.js +5 -1
- package/src/lib/jobs/ai-job-insight-step.js.map +1 -1
- package/src/lib/jobs/ai-jobs.d.ts +6 -0
- package/src/lib/jobs/ai-jobs.js +43 -6
- package/src/lib/jobs/ai-jobs.js.map +1 -1
- package/src/lib/jobs/ai-layout-stock-photos.d.ts +13 -6
- package/src/lib/jobs/ai-layout-stock-photos.js +104 -32
- package/src/lib/jobs/ai-layout-stock-photos.js.map +1 -1
- package/src/lib/jobs/ai-site-import-compile.js +110 -23
- package/src/lib/jobs/ai-site-import-compile.js.map +1 -1
- package/src/lib/jobs/ai-site-import-document.d.ts +5 -0
- package/src/lib/jobs/ai-site-import-document.js.map +1 -1
- package/src/lib/jobs/ai-site-import-forms.d.ts +83 -0
- package/src/lib/jobs/ai-site-import-forms.js +376 -0
- package/src/lib/jobs/ai-site-import-forms.js.map +1 -0
- package/src/lib/jobs/fixtures/ai-stock-photo-agl4092-1101-recordings.d.ts +21 -0
- package/src/lib/jobs/fixtures/ai-stock-photo-agl4092-1101-recordings.js +77 -0
- package/src/lib/jobs/fixtures/ai-stock-photo-agl4092-1101-recordings.js.map +1 -0
- package/src/lib/layout-language/ai-layout-compiler.d.ts +2 -0
- package/src/lib/layout-language/ai-layout-compiler.js +215 -30
- package/src/lib/layout-language/ai-layout-compiler.js.map +1 -1
- package/src/lib/layout-language/ai-layout-language.d.ts +12 -0
- package/src/lib/layout-language/ai-layout-language.js.map +1 -1
- package/src/lib/model/ai-credit-estimate.d.ts +25 -22
- package/src/lib/model/ai-credit-estimate.js +24 -22
- package/src/lib/model/ai-credit-estimate.js.map +1 -1
- package/src/lib/model/ai-insight.d.ts +4 -0
- package/src/lib/model/ai-insight.js +1 -0
- package/src/lib/model/ai-insight.js.map +1 -1
- package/src/lib/model/ai-site-build-progress.d.ts +8 -0
- package/src/lib/model/ai-site-build-progress.js +62 -1
- package/src/lib/model/ai-site-build-progress.js.map +1 -1
- package/src/lib/model/ai-site-import-fidelity.d.ts +2 -0
- package/src/lib/model/ai-site-import-fidelity.js +41 -5
- package/src/lib/model/ai-site-import-fidelity.js.map +1 -1
- package/src/lib/model/ai-site-import-report.d.ts +60 -0
- package/src/lib/model/ai-site-import-report.js +116 -0
- package/src/lib/model/ai-site-import-report.js.map +1 -0
- package/src/lib/model/ai-site-import-view.d.ts +7 -1
- package/src/lib/model/ai-site-import-view.js +14 -2
- package/src/lib/model/ai-site-import-view.js.map +1 -1
- package/src/lib/model/ai-site-import.d.ts +49 -2
- package/src/lib/model/ai-site-import.js +81 -23
- package/src/lib/model/ai-site-import.js.map +1 -1
- package/src/lib/plugin.js +1 -1
- package/src/lib/plugin.js.map +1 -1
- package/src/lib/runtime/ai-insight-check.js +22 -6
- package/src/lib/runtime/ai-insight-check.js.map +1 -1
- package/src/lib/server/ai-insight-digest-route.js +3 -1
- package/src/lib/server/ai-insight-digest-route.js.map +1 -1
- package/src/lib/site-import/fixtures/site-layout-recordings.d.ts +4 -0
- package/src/lib/site-import/fixtures/site-layout-recordings.js +9 -4
- package/src/lib/site-import/fixtures/site-layout-recordings.js.map +1 -1
- package/src/lib/site-import/site-import-css.d.ts +10 -1
- package/src/lib/site-import/site-import-css.js +19 -12
- package/src/lib/site-import/site-import-css.js.map +1 -1
- package/src/lib/site-import/site-import-html.d.ts +17 -4
- package/src/lib/site-import/site-import-html.js +146 -17
- package/src/lib/site-import/site-import-html.js.map +1 -1
- package/src/lib/site-import/site-import-layout.js +194 -32
- package/src/lib/site-import/site-import-layout.js.map +1 -1
- package/src/lib/tools/ai-insight-tool.js +11 -3
- package/src/lib/tools/ai-insight-tool.js.map +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/model/ai-insight.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 {\n pluginFigureCellText,\n pluginFigureIsoWeek,\n type PluginFigureTable,\n} from '@aglyn/aglyn/plugin-manager/plugin-figures'\nimport { weeklySummaryPeriod } from '@aglyn/aglyn/app-utils/weekly-summary'\nimport type { AiJob, AiJobOutput } from './ai-jobs.types'\nimport { AI_INSIGHT_DEFAULT_DAYS, AI_INSIGHT_WINDOWS } from './ai-insight-ask'\n\nexport {\n AI_INSIGHT_DEFAULT_DAYS,\n AI_INSIGHT_QUESTION_MAX_CHARS,\n AI_INSIGHT_WINDOWS,\n} from './ai-insight-ask'\n\n/**\n * Insights (AGL-2915): what an `insight` job answers, in the shape the step\n * writes and the console reads. Pure data — no server import — so the answer\n * card and the digest email type what they render from the module the step\n * writes it with.\n *\n * ## A number is read, never written\n *\n * The model never runs a query and never sees a record. Code reads figures —\n * traffic, orders, bookings, forms, campaigns, datasets, experiments — through\n * fixed, typed readers, each answering with one compact table that says where\n * its figures come from. The model picks the readers and phrases what their\n * tables say, and every insight it writes cites the rows its figures come from.\n * An insight whose numbers cannot be found in the rows it cites is left out\n * (`runtime/ai-insight-check.ts`), so each one a person reads can be traced to\n * a number they can open in the console.\n *\n * ## Read-only, and kept apart from the job\n *\n * An insight job writes one document besides its own record: the answer, at\n * `orgs/{orgId}/aiInsights/{jobId}`, which no rule lets a client read. The\n * job's output names it and carries no figure, because a job document is\n * readable by every member of the workspace and the figures are not: a\n * collaborator on one site may not see another site's revenue. The answer is\n * served by `GET /api/ai/insights/{jobId}` to the member who asked and, for a\n * weekly digest, to the members who reach its site.\n */\n\n/**\n * Where an insight was asked: the console page whose Assist panel — or\n * whose \"Ask AI about these numbers\" card — asked it, or the weekly digest,\n * which no person asked. A site's Marketing, Automation and Bookings pages\n * and the workspace's own pages joined at AGL-3603.\n */\nexport type AiInsightSurface =\n | 'analytics'\n | 'datasets'\n | 'crm-reports'\n | 'marketing'\n | 'automations'\n | 'bookings'\n | 'workspace'\n | 'digest'\n\nexport const AI_INSIGHT_SURFACES: readonly AiInsightSurface[] = [\n 'analytics',\n 'datasets',\n 'crm-reports',\n 'marketing',\n 'automations',\n 'bookings',\n 'workspace',\n 'digest',\n]\n\n/** The surfaces a person asks from. */\nexport const AI_INSIGHT_ASK_SURFACES: readonly AiInsightSurface[] = [\n 'analytics',\n 'datasets',\n 'crm-reports',\n 'marketing',\n 'automations',\n 'bookings',\n 'workspace',\n]\n\n/** The surface an insight job's inputs name, or `null` for one no insight job is asked from. */\nexport function aiInsightSurface(inputs: Readonly<Record<string, unknown>> | null | undefined): AiInsightSurface | null {\n const surface = inputs?.['surface']\n return typeof surface === 'string' && (AI_INSIGHT_SURFACES as readonly string[]).includes(surface)\n ? (surface as AiInsightSurface)\n : null\n}\n\n/**\n * The readers a surface may offer, by the first word of a reader's id. The\n * Analytics page — and a site's dashboard — answers about the site's traffic,\n * what it sold, took and collected, its automations' runs and its CRM\n * pipeline; a Data page about its datasets; CRM Reports about where people\n * came from, what they did and the pipeline; the Marketing page about what\n * its campaigns, overlays and tests caused and earned, beside the traffic and\n * the forms they drove; the Automation page about its runs; the Bookings page\n * about its bookings; and the workspace's own pages about its pipeline and\n * its datasets.\n */\nexport const AI_INSIGHT_SURFACE_READERS: Readonly<Record<AiInsightSurface, readonly string[]>> = {\n // `funnels` (AGL-3605): a site's funnels, step by step, beside its traffic.\n analytics: ['automations', 'bookings', 'commerce', 'crm', 'forms', 'funnels', 'marketing', 'traffic'],\n datasets: ['datasets'],\n 'crm-reports': ['bookings', 'commerce', 'crm', 'forms', 'marketing', 'traffic'],\n marketing: ['commerce', 'forms', 'marketing', 'traffic'],\n automations: ['automations'],\n bookings: ['bookings'],\n workspace: ['crm', 'datasets'],\n digest: ['bookings', 'commerce', 'forms', 'marketing', 'traffic'],\n}\n\n/** Whether a surface answers about one site; the Data page and the workspace's pages may answer about the whole workspace. */\nexport function aiInsightSurfaceNeedsSite(surface: AiInsightSurface): boolean {\n return surface !== 'datasets' && surface !== 'workspace'\n}\n\n/**\n * The readers a weekly digest reads, in the order the digest names them:\n * the traffic change, the top page, the days that stood out, the forms, the\n * campaigns, and what the site sold and took. Code reads these; no model\n * picks them.\n */\nexport const AI_INSIGHT_DIGEST_READERS: readonly string[] = [\n 'traffic.summary',\n 'traffic.pages',\n 'traffic.daily',\n 'forms.performance',\n 'marketing.campaigns',\n 'commerce.sales',\n 'bookings.services',\n]\n\n/** The window a weekly digest reads. */\nexport const AI_INSIGHT_DIGEST_DAYS = 7\n\n/**\n * The week a digest reads (AGL-3867): Monday to Sunday before the Monday it\n * was made, the same week the free Weekly summary reports, so the two emails\n * a person gets that morning quote the same figures. The sweep stamps the\n * week's last day as `through`; a job made before it did reads the week\n * before `now`.\n */\nexport function aiInsightDigestPeriod(\n inputs: Record<string, unknown> | null | undefined,\n now: Date,\n): ReturnType<typeof weeklySummaryPeriod> {\n const through = typeof inputs?.['through'] === 'string' ? inputs['through'] : ''\n const day = /^\\d{4}-\\d{2}-\\d{2}$/.test(through) ? Date.parse(`${through}T00:00:00Z`) : Number.NaN\n return weeklySummaryPeriod(Number.isFinite(day) ? new Date(day + 86_400_000) : now)\n}\n\n/** A window an insight's inputs or a read names, held to the readers' own ranges. */\nexport function aiInsightDays(value: unknown): number {\n const days = typeof value === 'number' ? value : Number(value)\n return AI_INSIGHT_WINDOWS.includes(days) ? days : AI_INSIGHT_DEFAULT_DAYS\n}\n\n/** The most insights one answer carries: a person reads them at a glance. */\nexport const AI_INSIGHT_MAX_INSIGHTS = 5\n\n/** The longest one insight may run, in characters. */\nexport const AI_INSIGHT_MAX_CHARS = 280\n\n/** The longest the sentence about what the figures could not answer may run. */\nexport const AI_INSIGHT_GAP_MAX_CHARS = 200\n\n/** The most tables one citation list names. */\nexport const AI_INSIGHT_MAX_CITES = 3\n\n/** The most rows one citation names. */\nexport const AI_INSIGHT_MAX_CITED_ROWS = 10\n\n/** The most readers one answer reads. */\nexport const AI_INSIGHT_MAX_READS = 4\n\n/**\n * A table as an insight job keeps it: the figures a reader returned, the\n * handle the model cites them by, and the reader they came from.\n */\nexport interface AiInsightTable extends PluginFigureTable {\n /** `t1`, `t2`, …, in the order the job read them. */\n ref: string\n /** The reader's id (`commerce.sales`). */\n reader: string\n /** The window the reader was asked for, in days; 0 for a reader of current counts. */\n days: number\n /** Whether the table is about one site (its path under that site) or the workspace. */\n scope: 'site' | 'org'\n}\n\n/** The rows of one table an insight's figures come from, by index. */\nexport interface AiInsightCitation {\n table: string\n rows: number[]\n}\n\nexport interface AiInsight {\n /** One or two plain sentences. */\n text: string\n cites: AiInsightCitation[]\n}\n\n/** What the model answers with. */\nexport interface AiInsightAnswer {\n insights: AiInsight[]\n /** What the figures could not answer, in one sentence without numbers; `null` when nothing. */\n gap: string | null\n}\n\n/** The answer collection under the org: server-written, and read through the insights door alone. */\nexport const AI_INSIGHTS_COLLECTION = 'aiInsights'\n\n/** An insight job's answer, as the step stores it. */\nexport interface AiInsightRecord {\n jobId: string\n orgId: string\n hostId: string | null\n surface: AiInsightSurface\n /** The member whose question it answers; for a digest, the member it was made for. */\n createdBy: string\n /** The question, verbatim; a digest's is the digest's own title. */\n question: string\n /** The window the answer was asked about, in days. */\n days: number\n /** The insights that trace to the rows they cite; every other one was left out. */\n insights: AiInsight[]\n gap: string | null\n /** Every table the job read, so each citation opens the figures it names. */\n tables: AiInsightTable[]\n /** How many insights the answer carried that were left out as not traceable. */\n left: number\n /** The ISO week a digest covers (`2026-W38`); `null` on a question. */\n week: string | null\n createdAtMs: number\n}\n\n/** The output id an answer is named by. */\nexport const AI_INSIGHT_OUTPUT_LABEL = 'Answer'\n\n/**\n * The output an insight job records: the answer's address and how many\n * insights it holds, and no figure. The count is a statement about the\n * answer rather than about the site, so every member may read it.\n */\nexport function aiInsightOutput(\n job: Pick<AiJob, '$id' | 'hostId'>,\n record: Pick<AiInsightRecord, 'insights' | 'surface'>,\n hostSubdomain: string | null,\n): AiJobOutput {\n const count = record.insights.length\n return {\n resource: 'insight',\n id: job.$id,\n versionId: null,\n hostId: job.hostId ?? null,\n hostSubdomain,\n label: record.surface === 'digest' ? 'Weekly insights' : AI_INSIGHT_OUTPUT_LABEL,\n note: count\n ? `${count} ${count === 1 ? 'insight' : 'insights'}, each traced to the figures it cites.`\n : 'The figures did not answer this question.',\n }\n}\n\n/** The answer on the wire: the stored record, with nothing a client does not render. */\nexport type AiInsightAnswerWire = AiInsightRecord\n\n/**\n * The Assist panel's insight surface for a console path, or `null` off one:\n * a site's dashboard, Analytics, Data, CRM Reports, Marketing, Automation and\n * Bookings pages; the workspace's Data page; and the workspace's sites page\n * and CRM Reports, which read the workspace's pipeline and datasets. The\n * organization's Marketing page reads site figures, so it is not one — it\n * asks about the site it is showing, through its own in-page entry.\n */\nexport function aiInsightSurfaceForPath(\n pathname: string | null | undefined,\n): { surface: Exclude<AiInsightSurface, 'digest'>; host: string | null } | null {\n const segments = String(pathname ?? '')\n .split('?')[0]\n .split('/')\n .filter(Boolean)\n // `/{org}/hosts/{host}/…` on a site, `/{org}/…` on the workspace.\n if (segments[1] === 'hosts' && segments.length >= 4) {\n const host = segments[2]\n const rest = segments.slice(3)\n if (rest[0] === 'analytics') return { surface: 'analytics', host }\n if (rest[0] === 'data') return { surface: 'datasets', host }\n if (rest[0] === 'crm' && rest[1] === 'reports') return { surface: 'crm-reports', host }\n if (rest[0] === 'marketing') return { surface: 'marketing', host }\n if (rest[0] === 'automation') return { surface: 'automations', host }\n if (rest[0] === 'bookings') return { surface: 'bookings', host }\n return null\n }\n // The site's dashboard is `/{org}/hosts/{host}`.\n if (segments[1] === 'hosts' && segments.length === 3) return { surface: 'analytics', host: segments[2] }\n if (segments.length >= 2 && segments[1] === 'data') return { surface: 'datasets', host: null }\n // The workspace's sites page, `/{org}/hosts`, which carries its dashboard row.\n if (segments.length === 2 && segments[1] === 'hosts') return { surface: 'workspace', host: null }\n if (segments[1] === 'crm' && segments[2] === 'reports') return { surface: 'workspace', host: null }\n return null\n}\n\n/** The console page a table's figures come from, or `null` when the table names none. */\nexport function aiInsightSourceHref(\n table: Pick<AiInsightTable, 'source' | 'scope'>,\n where: { orgSlug: string; host: string | null },\n): string | null {\n const path = table.source.path\n if (!path || !where.orgSlug) return null\n if (table.scope === 'org') return `/${where.orgSlug}/${path}`\n return where.host ? `/${where.orgSlug}/hosts/${where.host}/${path}` : null\n}\n\n/** How a cell reads to a person, by its column's kind; `null` is \"—\". */\nexport function aiInsightCellText(\n table: Pick<AiInsightTable, 'columns'>,\n key: string,\n value: string | number | null | undefined,\n): string {\n return pluginFigureCellText(table, key, value)\n}\n\n/** One cited row as a line a person reads: every column, labeled. */\nexport function aiInsightRowText(table: Pick<AiInsightTable, 'columns' | 'rows'>, index: number): string {\n const row = table.rows[index]\n if (!row) return ''\n return table.columns\n .map((column) => `${column.label}: ${aiInsightCellText(table, column.key, row[column.key])}`)\n .join(' · ')\n}\n\n/** The ISO 8601 week an instant falls in, in UTC (`2026-W38`). */\nexport function aiInsightIsoWeek(at: Date): string {\n return pluginFigureIsoWeek(at)\n}\n"],"names":["pluginFigureCellText","pluginFigureIsoWeek","weeklySummaryPeriod","AI_INSIGHT_DEFAULT_DAYS","AI_INSIGHT_WINDOWS","AI_INSIGHT_QUESTION_MAX_CHARS","AI_INSIGHT_SURFACES","AI_INSIGHT_ASK_SURFACES","aiInsightSurface","inputs","surface","includes","AI_INSIGHT_SURFACE_READERS","analytics","datasets","marketing","automations","bookings","workspace","digest","aiInsightSurfaceNeedsSite","AI_INSIGHT_DIGEST_READERS","AI_INSIGHT_DIGEST_DAYS","aiInsightDigestPeriod","now","through","day","test","Date","parse","Number","NaN","isFinite","aiInsightDays","value","days","AI_INSIGHT_MAX_INSIGHTS","AI_INSIGHT_MAX_CHARS","AI_INSIGHT_GAP_MAX_CHARS","AI_INSIGHT_MAX_CITES","AI_INSIGHT_MAX_CITED_ROWS","AI_INSIGHT_MAX_READS","AI_INSIGHTS_COLLECTION","AI_INSIGHT_OUTPUT_LABEL","aiInsightOutput","job","record","hostSubdomain","count","insights","length","resource","id","$id","versionId","hostId","label","note","aiInsightSurfaceForPath","pathname","segments","String","split","filter","Boolean","host","rest","slice","aiInsightSourceHref","table","where","path","source","orgSlug","scope","aiInsightCellText","key","aiInsightRowText","index","row","rows","columns","map","column","join","aiInsightIsoWeek","at"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED,SACEA,oBAAoB,EACpBC,mBAAmB,QAEd,6CAA4C;AACnD,SAASC,mBAAmB,QAAQ,wCAAuC;AAE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AK,WAAW,OAAO;QAAElD,SAAS;QAAauD,MAAM;IAAK;IAClG,OAAO;AACT;AAEA,uFAAuF,GACvF,OAAO,SAASG,oBACdC,KAA+C,EAC/CC,KAA+C;IAE/C,MAAMC,OAAOF,MAAMG,MAAM,CAACD,IAAI;IAC9B,IAAI,CAACA,QAAQ,CAACD,MAAMG,OAAO,EAAE,OAAO;IACpC,IAAIJ,MAAMK,KAAK,KAAK,OAAO,OAAO,CAAC,CAAC,EAAEJ,MAAMG,OAAO,CAAC,CAAC,EAAEF,MAAM;IAC7D,OAAOD,MAAML,IAAI,GAAG,CAAC,CAAC,EAAEK,MAAMG,OAAO,CAAC,OAAO,EAAEH,MAAML,IAAI,CAAC,CAAC,EAAEM,MAAM,GAAG;AACxE;AAEA,uEAAuE,GACvE,OAAO,SAASI,kBACdN,KAAsC,EACtCO,GAAW,EACX1C,KAAyC;IAEzC,OAAOlC,qBAAqBqE,OAAOO,KAAK1C;AAC1C;AAEA,mEAAmE,GACnE,OAAO,SAAS2C,iBAAiBR,KAA+C,EAAES,KAAa;IAC7F,MAAMC,MAAMV,MAAMW,IAAI,CAACF,MAAM;IAC7B,IAAI,CAACC,KAAK,OAAO;IACjB,OAAOV,MAAMY,OAAO,CACjBC,GAAG,CAAC,CAACC,SAAW,GAAGA,OAAO3B,KAAK,CAAC,EAAE,EAAEmB,kBAAkBN,OAAOc,OAAOP,GAAG,EAAEG,GAAG,CAACI,OAAOP,GAAG,CAAC,GAAG,EAC3FQ,IAAI,CAAC;AACV;AAEA,gEAAgE,GAChE,OAAO,SAASC,iBAAiBC,EAAQ;IACvC,OAAOrF,oBAAoBqF;AAC7B"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/model/ai-insight.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 {\n pluginFigureCellText,\n pluginFigureIsoWeek,\n type PluginFigureTable,\n} from '@aglyn/aglyn/plugin-manager/plugin-figures'\nimport { weeklySummaryPeriod } from '@aglyn/aglyn/app-utils/weekly-summary'\nimport type { AiJob, AiJobOutput } from './ai-jobs.types'\nimport { AI_INSIGHT_DEFAULT_DAYS, AI_INSIGHT_WINDOWS } from './ai-insight-ask'\n\nexport {\n AI_INSIGHT_DEFAULT_DAYS,\n AI_INSIGHT_QUESTION_MAX_CHARS,\n AI_INSIGHT_WINDOWS,\n} from './ai-insight-ask'\n\n/**\n * Insights (AGL-2915): what an `insight` job answers, in the shape the step\n * writes and the console reads. Pure data — no server import — so the answer\n * card and the digest email type what they render from the module the step\n * writes it with.\n *\n * ## A number is read, never written\n *\n * The model never runs a query and never sees a record. Code reads figures —\n * traffic, orders, bookings, forms, campaigns, datasets, experiments — through\n * fixed, typed readers, each answering with one compact table that says where\n * its figures come from. The model picks the readers and phrases what their\n * tables say, and every insight it writes cites the rows its figures come from.\n * An insight whose numbers cannot be found in the rows it cites is left out\n * (`runtime/ai-insight-check.ts`), so each one a person reads can be traced to\n * a number they can open in the console.\n *\n * ## Read-only, and kept apart from the job\n *\n * An insight job writes one document besides its own record: the answer, at\n * `orgs/{orgId}/aiInsights/{jobId}`, which no rule lets a client read. The\n * job's output names it and carries no figure, because a job document is\n * readable by every member of the workspace and the figures are not: a\n * collaborator on one site may not see another site's revenue. The answer is\n * served by `GET /api/ai/insights/{jobId}` to the member who asked and, for a\n * weekly digest, to the members who reach its site.\n */\n\n/**\n * Where an insight was asked: the console page whose Assist panel — or\n * whose \"Ask AI about these numbers\" card — asked it, or the weekly digest,\n * which no person asked. A site's Marketing, Automation and Bookings pages\n * and the workspace's own pages joined at AGL-3603.\n */\nexport type AiInsightSurface =\n | 'analytics'\n | 'datasets'\n | 'crm-reports'\n | 'marketing'\n | 'automations'\n | 'bookings'\n | 'workspace'\n | 'digest'\n\nexport const AI_INSIGHT_SURFACES: readonly AiInsightSurface[] = [\n 'analytics',\n 'datasets',\n 'crm-reports',\n 'marketing',\n 'automations',\n 'bookings',\n 'workspace',\n 'digest',\n]\n\n/** The surfaces a person asks from. */\nexport const AI_INSIGHT_ASK_SURFACES: readonly AiInsightSurface[] = [\n 'analytics',\n 'datasets',\n 'crm-reports',\n 'marketing',\n 'automations',\n 'bookings',\n 'workspace',\n]\n\n/** The surface an insight job's inputs name, or `null` for one no insight job is asked from. */\nexport function aiInsightSurface(inputs: Readonly<Record<string, unknown>> | null | undefined): AiInsightSurface | null {\n const surface = inputs?.['surface']\n return typeof surface === 'string' && (AI_INSIGHT_SURFACES as readonly string[]).includes(surface)\n ? (surface as AiInsightSurface)\n : null\n}\n\n/**\n * The readers a surface may offer, by the first word of a reader's id. The\n * Analytics page — and a site's dashboard — answers about the site's traffic,\n * what it sold, took and collected, its automations' runs and its CRM\n * pipeline; a Data page about its datasets; CRM Reports about where people\n * came from, what they did and the pipeline; the Marketing page about what\n * its campaigns, overlays and tests caused and earned, beside the traffic and\n * the forms they drove; the Automation page about its runs; the Bookings page\n * about its bookings; and the workspace's own pages about its pipeline and\n * its datasets.\n */\nexport const AI_INSIGHT_SURFACE_READERS: Readonly<Record<AiInsightSurface, readonly string[]>> = {\n // `funnels` (AGL-3605): a site's funnels, step by step, beside its traffic.\n analytics: ['automations', 'bookings', 'commerce', 'crm', 'forms', 'funnels', 'marketing', 'traffic'],\n datasets: ['datasets'],\n 'crm-reports': ['bookings', 'commerce', 'crm', 'forms', 'marketing', 'traffic'],\n marketing: ['commerce', 'forms', 'marketing', 'traffic'],\n automations: ['automations'],\n bookings: ['bookings'],\n workspace: ['crm', 'datasets'],\n digest: ['bookings', 'commerce', 'forms', 'marketing', 'traffic'],\n}\n\n/** Whether a surface answers about one site; the Data page and the workspace's pages may answer about the whole workspace. */\nexport function aiInsightSurfaceNeedsSite(surface: AiInsightSurface): boolean {\n return surface !== 'datasets' && surface !== 'workspace'\n}\n\n/**\n * The readers a weekly digest reads, in the order the digest names them:\n * the traffic change, the top page, the days that stood out, the forms, the\n * campaigns, and what the site sold and took. Code reads these; no model\n * picks them.\n */\nexport const AI_INSIGHT_DIGEST_READERS: readonly string[] = [\n 'traffic.summary',\n 'traffic.pages',\n 'traffic.daily',\n 'forms.performance',\n 'marketing.campaigns',\n 'commerce.sales',\n 'bookings.services',\n]\n\n/** The window a weekly digest reads. */\nexport const AI_INSIGHT_DIGEST_DAYS = 7\n\n/**\n * The week a digest reads (AGL-3867): Monday to Sunday before the Monday it\n * was made, the same week the free Weekly summary reports, so the two emails\n * a person gets that morning quote the same figures. The sweep stamps the\n * week's last day as `through`; a job made before it did reads the week\n * before `now`.\n */\nexport function aiInsightDigestPeriod(\n inputs: Record<string, unknown> | null | undefined,\n now: Date,\n): ReturnType<typeof weeklySummaryPeriod> {\n const through = typeof inputs?.['through'] === 'string' ? inputs['through'] : ''\n const day = /^\\d{4}-\\d{2}-\\d{2}$/.test(through) ? Date.parse(`${through}T00:00:00Z`) : Number.NaN\n return weeklySummaryPeriod(Number.isFinite(day) ? new Date(day + 86_400_000) : now)\n}\n\n/** A window an insight's inputs or a read names, held to the readers' own ranges. */\nexport function aiInsightDays(value: unknown): number {\n const days = typeof value === 'number' ? value : Number(value)\n return AI_INSIGHT_WINDOWS.includes(days) ? days : AI_INSIGHT_DEFAULT_DAYS\n}\n\n/** The most insights one answer carries: a person reads them at a glance. */\nexport const AI_INSIGHT_MAX_INSIGHTS = 5\n\n/** The longest one insight may run, in characters. */\nexport const AI_INSIGHT_MAX_CHARS = 280\n\n/** How long an insight's headline may run. */\nexport const AI_INSIGHT_HEADLINE_MAX_CHARS = 60\n\n/** The longest the sentence about what the figures could not answer may run. */\nexport const AI_INSIGHT_GAP_MAX_CHARS = 200\n\n/** The most tables one citation list names. */\nexport const AI_INSIGHT_MAX_CITES = 3\n\n/** The most rows one citation names. */\nexport const AI_INSIGHT_MAX_CITED_ROWS = 10\n\n/** The most readers one answer reads. */\nexport const AI_INSIGHT_MAX_READS = 4\n\n/**\n * A table as an insight job keeps it: the figures a reader returned, the\n * handle the model cites them by, and the reader they came from.\n */\nexport interface AiInsightTable extends PluginFigureTable {\n /** `t1`, `t2`, …, in the order the job read them. */\n ref: string\n /** The reader's id (`commerce.sales`). */\n reader: string\n /** The window the reader was asked for, in days; 0 for a reader of current counts. */\n days: number\n /** Whether the table is about one site (its path under that site) or the workspace. */\n scope: 'site' | 'org'\n}\n\n/** The rows of one table an insight's figures come from, by index. */\nexport interface AiInsightCitation {\n table: string\n rows: number[]\n}\n\nexport interface AiInsight {\n /** What happened, in a few words: what the eye lands on. Absent on an answer from before it was asked for. */\n headline?: string\n /** One or two plain sentences. */\n text: string\n cites: AiInsightCitation[]\n}\n\n/** What the model answers with. */\nexport interface AiInsightAnswer {\n insights: AiInsight[]\n /** What the figures could not answer, in one sentence without numbers; `null` when nothing. */\n gap: string | null\n}\n\n/** The answer collection under the org: server-written, and read through the insights door alone. */\nexport const AI_INSIGHTS_COLLECTION = 'aiInsights'\n\n/** An insight job's answer, as the step stores it. */\nexport interface AiInsightRecord {\n jobId: string\n orgId: string\n hostId: string | null\n surface: AiInsightSurface\n /** The member whose question it answers; for a digest, the member it was made for. */\n createdBy: string\n /** The question, verbatim; a digest's is the digest's own title. */\n question: string\n /** The window the answer was asked about, in days. */\n days: number\n /** The insights that trace to the rows they cite; every other one was left out. */\n insights: AiInsight[]\n gap: string | null\n /** Every table the job read, so each citation opens the figures it names. */\n tables: AiInsightTable[]\n /** How many insights the answer carried that were left out as not traceable. */\n left: number\n /** The ISO week a digest covers (`2026-W38`); `null` on a question. */\n week: string | null\n createdAtMs: number\n}\n\n/** The output id an answer is named by. */\nexport const AI_INSIGHT_OUTPUT_LABEL = 'Answer'\n\n/**\n * The output an insight job records: the answer's address and how many\n * insights it holds, and no figure. The count is a statement about the\n * answer rather than about the site, so every member may read it.\n */\nexport function aiInsightOutput(\n job: Pick<AiJob, '$id' | 'hostId'>,\n record: Pick<AiInsightRecord, 'insights' | 'surface'>,\n hostSubdomain: string | null,\n): AiJobOutput {\n const count = record.insights.length\n return {\n resource: 'insight',\n id: job.$id,\n versionId: null,\n hostId: job.hostId ?? null,\n hostSubdomain,\n label: record.surface === 'digest' ? 'Weekly insights' : AI_INSIGHT_OUTPUT_LABEL,\n note: count\n ? `${count} ${count === 1 ? 'insight' : 'insights'}, each traced to the figures it cites.`\n : 'The figures did not answer this question.',\n }\n}\n\n/** The answer on the wire: the stored record, with nothing a client does not render. */\nexport type AiInsightAnswerWire = AiInsightRecord\n\n/**\n * The Assist panel's insight surface for a console path, or `null` off one:\n * a site's dashboard, Analytics, Data, CRM Reports, Marketing, Automation and\n * Bookings pages; the workspace's Data page; and the workspace's sites page\n * and CRM Reports, which read the workspace's pipeline and datasets. The\n * organization's Marketing page reads site figures, so it is not one — it\n * asks about the site it is showing, through its own in-page entry.\n */\nexport function aiInsightSurfaceForPath(\n pathname: string | null | undefined,\n): { surface: Exclude<AiInsightSurface, 'digest'>; host: string | null } | null {\n const segments = String(pathname ?? '')\n .split('?')[0]\n .split('/')\n .filter(Boolean)\n // `/{org}/hosts/{host}/…` on a site, `/{org}/…` on the workspace.\n if (segments[1] === 'hosts' && segments.length >= 4) {\n const host = segments[2]\n const rest = segments.slice(3)\n if (rest[0] === 'analytics') return { surface: 'analytics', host }\n if (rest[0] === 'data') return { surface: 'datasets', host }\n if (rest[0] === 'crm' && rest[1] === 'reports') return { surface: 'crm-reports', host }\n if (rest[0] === 'marketing') return { surface: 'marketing', host }\n if (rest[0] === 'automation') return { surface: 'automations', host }\n if (rest[0] === 'bookings') return { surface: 'bookings', host }\n return null\n }\n // The site's dashboard is `/{org}/hosts/{host}`.\n if (segments[1] === 'hosts' && segments.length === 3) return { surface: 'analytics', host: segments[2] }\n if (segments.length >= 2 && segments[1] === 'data') return { surface: 'datasets', host: null }\n // The workspace's sites page, `/{org}/hosts`, which carries its dashboard row.\n if (segments.length === 2 && segments[1] === 'hosts') return { surface: 'workspace', host: null }\n if (segments[1] === 'crm' && segments[2] === 'reports') return { surface: 'workspace', host: null }\n return null\n}\n\n/** The console page a table's figures come from, or `null` when the table names none. */\nexport function aiInsightSourceHref(\n table: Pick<AiInsightTable, 'source' | 'scope'>,\n where: { orgSlug: string; host: string | null },\n): string | null {\n const path = table.source.path\n if (!path || !where.orgSlug) return null\n if (table.scope === 'org') return `/${where.orgSlug}/${path}`\n return where.host ? `/${where.orgSlug}/hosts/${where.host}/${path}` : null\n}\n\n/** How a cell reads to a person, by its column's kind; `null` is \"—\". */\nexport function aiInsightCellText(\n table: Pick<AiInsightTable, 'columns'>,\n key: string,\n value: string | number | null | undefined,\n): string {\n return pluginFigureCellText(table, key, value)\n}\n\n/** One cited row as a line a person reads: every column, labeled. */\nexport function aiInsightRowText(table: Pick<AiInsightTable, 'columns' | 'rows'>, index: number): string {\n const row = table.rows[index]\n if (!row) return ''\n return table.columns\n .map((column) => `${column.label}: ${aiInsightCellText(table, column.key, row[column.key])}`)\n .join(' · ')\n}\n\n/** The ISO 8601 week an instant falls in, in UTC (`2026-W38`). */\nexport function aiInsightIsoWeek(at: Date): string {\n return pluginFigureIsoWeek(at)\n}\n"],"names":["pluginFigureCellText","pluginFigureIsoWeek","weeklySummaryPeriod","AI_INSIGHT_DEFAULT_DAYS","AI_INSIGHT_WINDOWS","AI_INSIGHT_QUESTION_MAX_CHARS","AI_INSIGHT_SURFACES","AI_INSIGHT_ASK_SURFACES","aiInsightSurface","inputs","surface","includes","AI_INSIGHT_SURFACE_READERS","analytics","datasets","marketing","automations","bookings","workspace","digest","aiInsightSurfaceNeedsSite","AI_INSIGHT_DIGEST_READERS","AI_INSIGHT_DIGEST_DAYS","aiInsightDigestPeriod","now","through","day","test","Date","parse","Number","NaN","isFinite","aiInsightDays","value","days","AI_INSIGHT_MAX_INSIGHTS","AI_INSIGHT_MAX_CHARS","AI_INSIGHT_HEADLINE_MAX_CHARS","AI_INSIGHT_GAP_MAX_CHARS","AI_INSIGHT_MAX_CITES","AI_INSIGHT_MAX_CITED_ROWS","AI_INSIGHT_MAX_READS","AI_INSIGHTS_COLLECTION","AI_INSIGHT_OUTPUT_LABEL","aiInsightOutput","job","record","hostSubdomain","count","insights","length","resource","id","$id","versionId","hostId","label","note","aiInsightSurfaceForPath","pathname","segments","String","split","filter","Boolean","host","rest","slice","aiInsightSourceHref","table","where","path","source","orgSlug","scope","aiInsightCellText","key","aiInsightRowText","index","row","rows","columns","map","column","join","aiInsightIsoWeek","at"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED,SACEA,oBAAoB,EACpBC,mBAAmB,QAEd,6CAA4C;AACnD,SAASC,mBAAmB,QAAQ,wCAAuC;AAE3E,SAASC,uBAAuB,EAAEC,kBAAkB,QAAQ,sBAAkB;AAE9E,SACED,uBAAuB,EACvBE,6BAA6B,EAC7BD,kBAAkB,QACb,sBAAkB;AA8CzB,OAAO,MAAME,sBAAmD;IAC9D;IACA;IACA;IACA;IACA;IACA;IACA;IACA;CACD,CAAA;AAED,qCAAqC,GACrC,OAAO,MAAMC,0BAAuD;IAClE;IACA;IACA;IACA;IACA;IACA;IACA;CACD,CAAA;AAED,8FAA8F,GAC9F,OAAO,SAASC,iBAAiBC,MAA4D;IAC3F,MAAMC,UAAUD,0BAAAA,MAAQ,CAAC,UAAU;IACnC,OAAO,OAAOC,YAAY,YAAY,AAACJ,oBAA0CK,QAAQ,CAACD,WACrFA,UACD;AACN;AAEA;;;;;;;;;;CAUC,GACD,OAAO,MAAME,6BAAoF;IAC/F,4EAA4E;IAC5EC,WAAW;QAAC;QAAe;QAAY;QAAY;QAAO;QAAS;QAAW;QAAa;KAAU;IACrGC,UAAU;QAAC;KAAW;IACtB,eAAe;QAAC;QAAY;QAAY;QAAO;QAAS;QA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EAAmE,GACnE,OAAO,SAAS4C,iBAAiBR,KAA+C,EAAES,KAAa;IAC7F,MAAMC,MAAMV,MAAMW,IAAI,CAACF,MAAM;IAC7B,IAAI,CAACC,KAAK,OAAO;IACjB,OAAOV,MAAMY,OAAO,CACjBC,GAAG,CAAC,CAACC,SAAW,GAAGA,OAAO3B,KAAK,CAAC,EAAE,EAAEmB,kBAAkBN,OAAOc,OAAOP,GAAG,EAAEG,GAAG,CAACI,OAAOP,GAAG,CAAC,GAAG,EAC3FQ,IAAI,CAAC;AACV;AAEA,gEAAgE,GAChE,OAAO,SAASC,iBAAiBC,EAAQ;IACvC,OAAOtF,oBAAoBsF;AAC7B"}
|
|
@@ -80,6 +80,14 @@ export declare function aiSiteBuildFraction(rows: readonly AiSiteBuildRow[]): nu
|
|
|
80
80
|
* back, that nothing was charged.
|
|
81
81
|
*/
|
|
82
82
|
export declare function aiSiteBuildCreditsLine(job: Pick<AiJobSummary, 'status' | 'creditsSpent' | 'refundedCredits'> & Partial<Pick<AiJobSummary, 'kind'>>): string | null;
|
|
83
|
+
/** The most of a request a job's title carries. */
|
|
84
|
+
export declare const AI_JOB_TITLE_MAX_CHARS = 60;
|
|
85
|
+
/**
|
|
86
|
+
* What a job's page is called: the first line of what was asked, so one job
|
|
87
|
+
* among many can be told from the rest. Its state is the heading on the page.
|
|
88
|
+
* `null` for a job with no request to name it by.
|
|
89
|
+
*/
|
|
90
|
+
export declare function aiJobPageTitle(job: Pick<AiJobSummary, 'brief'>): string | null;
|
|
83
91
|
/** The heading and the sentence under it, for one job's page in its current phase. */
|
|
84
92
|
export interface AiJobPageCopy {
|
|
85
93
|
heading: string;
|
|
@@ -138,6 +138,10 @@ function aiSiteBuildRowsOf(job) {
|
|
|
138
138
|
];
|
|
139
139
|
}
|
|
140
140
|
const planStep = job.steps.find((step)=>step.name === 'plan');
|
|
141
|
+
// A job with no plan is not building pages: an answer, a summary, one change.
|
|
142
|
+
if (job.steps.length > 0 && !planStep && !job.plan && job.kind !== 'site' && job.kind !== 'build') {
|
|
143
|
+
return aiJobStepRows(job, phase);
|
|
144
|
+
}
|
|
141
145
|
const planDone = (planStep == null ? void 0 : planStep.status) === 'done' || Boolean(job.plan);
|
|
142
146
|
const stopped = phase === 'failed' || phase === 'stopped';
|
|
143
147
|
const paused = job.status === 'needs_input';
|
|
@@ -255,6 +259,34 @@ function aiSiteBuildRowsOf(job) {
|
|
|
255
259
|
rows.push(...aiSitePublishRow(job, phase));
|
|
256
260
|
return rows;
|
|
257
261
|
}
|
|
262
|
+
/**
|
|
263
|
+
* A job with no plan and no parts of its own to count: one row while it works,
|
|
264
|
+
* and what it made once it is done, by the name each output carries.
|
|
265
|
+
*/ function aiJobStepRows(job, phase) {
|
|
266
|
+
var _ref;
|
|
267
|
+
var _job_steps_;
|
|
268
|
+
if (phase === 'done' && job.outputs.length > 0) {
|
|
269
|
+
return job.outputs.map((output, index)=>{
|
|
270
|
+
var _ref, _output_note;
|
|
271
|
+
return {
|
|
272
|
+
id: `output-${index}`,
|
|
273
|
+
label: output.label,
|
|
274
|
+
state: 'done',
|
|
275
|
+
detail: (_ref = (_output_note = output.note) != null ? _output_note : output.text) != null ? _ref : null
|
|
276
|
+
};
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
const noun = job.kind ? aiJobKindNoun(job.kind) : 'AI job';
|
|
280
|
+
const state = phase === 'done' ? 'done' : phase === 'working' ? 'active' : phase === 'stopped' ? 'paused' : phase === 'canceled' ? 'skipped' : 'failed';
|
|
281
|
+
return [
|
|
282
|
+
{
|
|
283
|
+
id: 'work',
|
|
284
|
+
label: phase === 'done' ? 'Finished' : `Working on ${noun === 'AI job' ? 'this job' : `your ${noun}`}`,
|
|
285
|
+
state,
|
|
286
|
+
startedAt: (_ref = (_job_steps_ = job.steps[job.steps.length - 1]) == null ? void 0 : _job_steps_.startedAt) != null ? _ref : null
|
|
287
|
+
}
|
|
288
|
+
];
|
|
289
|
+
}
|
|
258
290
|
/** The row the site's look is designed on (AGL-3660). */ export const AI_SITE_LOOK_ROW_LABEL = 'Designing your look';
|
|
259
291
|
/** What the look's row says while it runs. */ export const AI_SITE_LOOK_HINT = 'Choosing a base theme, colors, fonts and the style of your buttons, cards and forms for your kind of site. This takes a few seconds.';
|
|
260
292
|
/** What the planning row says while it runs. */ export const AI_SITE_PLAN_HINT = 'Reading your answers and choosing your pages, what each one says, and the forms and layout they need. This usually takes under a minute.';
|
|
@@ -314,6 +346,35 @@ function aiSiteBuildRowsOf(job) {
|
|
|
314
346
|
if (refund) return `${subject} used ${net} credits. ${refund}`;
|
|
315
347
|
return net > 0 ? `${subject} used ${net} credits.` : null;
|
|
316
348
|
}
|
|
349
|
+
/** The most of a request a job's title carries. */ export const AI_JOB_TITLE_MAX_CHARS = 60;
|
|
350
|
+
/**
|
|
351
|
+
* What a job's page is called: the first line of what was asked, so one job
|
|
352
|
+
* among many can be told from the rest. Its state is the heading on the page.
|
|
353
|
+
* `null` for a job with no request to name it by.
|
|
354
|
+
*/ export function aiJobPageTitle(job) {
|
|
355
|
+
const line = job.brief.split('\n').map((part)=>part.trim()).find(Boolean);
|
|
356
|
+
if (!line) return null;
|
|
357
|
+
return line.length > AI_JOB_TITLE_MAX_CHARS ? `${line.slice(0, AI_JOB_TITLE_MAX_CHARS).trimEnd()}…` : line;
|
|
358
|
+
}
|
|
359
|
+
/** What a job leaves that is not a draft: saved straight onto the site. */ const AI_JOB_LIVE_RESOURCES = [
|
|
360
|
+
'settings',
|
|
361
|
+
'media',
|
|
362
|
+
'tracking',
|
|
363
|
+
'privacy'
|
|
364
|
+
];
|
|
365
|
+
/** What a job leaves that touches no site: words for a person to read. */ const AI_JOB_ANSWER_RESOURCES = [
|
|
366
|
+
'insight',
|
|
367
|
+
'crm',
|
|
368
|
+
'text'
|
|
369
|
+
];
|
|
370
|
+
/** The sentence under a finished job's heading, by what it actually left. */ function aiJobDoneLede(job) {
|
|
371
|
+
var _job_outputs;
|
|
372
|
+
const resources = ((_job_outputs = job.outputs) != null ? _job_outputs : []).map((output)=>output.resource);
|
|
373
|
+
const all = (kinds)=>resources.length > 0 && resources.every((resource)=>kinds.includes(resource));
|
|
374
|
+
if (all(AI_JOB_ANSWER_RESOURCES)) return 'Nothing on your site changed.';
|
|
375
|
+
if (all(AI_JOB_LIVE_RESOURCES)) return 'Its changes are saved and already live.';
|
|
376
|
+
return 'Everything it built is an unpublished draft until you publish it.';
|
|
377
|
+
}
|
|
317
378
|
/**
|
|
318
379
|
* What one job's page says at the top (AGL-3594, AGL-3596). A site job reads
|
|
319
380
|
* as "Building your site"; any other kind names what it makes — "Building
|
|
@@ -383,7 +444,7 @@ function aiSiteBuildRowsOf(job) {
|
|
|
383
444
|
}
|
|
384
445
|
return {
|
|
385
446
|
heading: generic ? 'Your AI job finished' : `Your ${noun} ${isAre} ready`,
|
|
386
|
-
lede: job.kind === 'site' ? 'Your new pages are drafts. Publish them when you’re happy.' :
|
|
447
|
+
lede: job.kind === 'site' ? 'Your new pages are drafts. Publish them when you’re happy.' : aiJobDoneLede(job)
|
|
387
448
|
};
|
|
388
449
|
}
|
|
389
450
|
if (phase === 'canceled') {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/model/ai-site-build-progress.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 { AI_JOB_CANCELED_LEDE, aiJobCanceledCreditsCopy } from './ai-job-cancel-copy'\nimport { aiJobConfirmingOwnPlan, aiJobKindNoun } from './ai-job-activity'\nimport { aiJobRefundCopy } from './ai-job-failure-copy'\nimport { aiBuildItemRows, aiBuildOpNoun, aiBuildOutcomeLine, aiSitePartialCopy } from './ai-build-progress'\nimport { AI_JOB_PAUSED_NEXT_COPY, aiJobPausedTitle } from './ai-job-notice'\nimport type { AiJobSummary } from './ai-jobs.types'\n\n/**\n * What the \"Building your site\" page shows of a site job (AGL-3594): one row\n * a stage — planning the pages, then each page — with its state, the state\n * the whole job is in, and the job's one price.\n *\n * Read off the job summary every surface already follows: the plan step's\n * status, the plan's pages, and the pages the build has reported as outputs.\n * A scaffold builds its units in plan order and reports each page when it is\n * written, so the pages written so far are the first pages of the plan.\n *\n * Pure: no React, no request. The page and its spec read the same rows.\n */\n\n/**\n * `paused` (AGL-3660): the row a job the meter paused stopped at — not\n * running, not failed, and carried on from by Resume.\n */\nexport type AiSiteBuildRowState = 'done' | 'active' | 'waiting' | 'failed' | 'skipped' | 'paused'\n\nexport interface AiSiteBuildRow {\n id: string\n label: string\n state: AiSiteBuildRowState\n /** What the person should know about this row (AGL-3616): a build item's failure, note or refund. */\n detail?: string | null\n /** What the row is doing while it is the active one, in a sentence. */\n hint?: string | null\n /** A page's planned sections, in order, so the person sees what is being written. */\n sections?: string[]\n /** The credits this row's work used, once it has finished; absent while it runs. */\n credits?: number\n /** When this row's work started, for the elapsed time beside the active row. */\n startedAt?: string | null\n}\n\n/** Where the whole job stands, as the page's header and actions read it. */\nexport type AiSiteBuildPhase = 'working' | 'done' | 'stopped' | 'failed' | 'canceled'\n\nexport function aiSiteBuildPhase(\n job: Pick<AiJobSummary, 'status'> & Partial<Pick<AiJobSummary, 'review' | 'autoConfirm' | 'updatedAt'>>,\n): AiSiteBuildPhase {\n // A guided start's plan parked for the instant its confirmation takes is\n // the build going on (AGL-3596), never a stop.\n if (aiJobConfirmingOwnPlan(job)) return 'working'\n switch (job.status) {\n case 'done':\n return 'done'\n case 'failed':\n return 'failed'\n case 'canceled':\n return 'canceled'\n case 'needs_review':\n case 'needs_input':\n return 'stopped'\n default:\n return 'working'\n }\n}\n\n/** The creations a scaffold builds before its pages, in its build order, and what each row says. */\nconst CREATION_ROWS: ReadonlyArray<{ kind: string; resource: string; label: (name: string) => string }> = [\n { kind: 'theme-change', resource: 'theme', label: () => AI_SITE_LOOK_ROW_LABEL },\n { kind: 'layout', resource: 'layout', label: (name) => `Building the header and footer: ${name}` },\n { kind: 'form', resource: 'form', label: (name) => `Building the form: ${name}` },\n]\n\n/**\n * One row a stage: planning, then each creation the plan builds before its\n * pages — the colors, the layout, the form — then each page (AGL-3596). A\n * scaffold builds them in that order and reports each as an output when it\n * is written, so the first row without its output is where the build is, and\n * where a failure stopped it: a layout that broke is the layout's row, never\n * the first page's.\n */\nexport function aiSiteBuildRows(\n job: Pick<AiJobSummary, 'status' | 'steps' | 'plan' | 'outputs' | 'review'> &\n Partial<Pick<AiJobSummary, 'items' | 'kind' | 'siteInputs' | 'sitePublish'>>,\n): AiSiteBuildRow[] {\n const rows = aiSiteBuildRowsOf(job)\n return job.status === 'needs_input' ? aiPausedRows(rows) : rows\n}\n\n/**\n * A job the meter paused (AGL-3660) shows no spinner: the row it stopped at —\n * one still marked running, else the first not yet built — reads `paused`,\n * with no running clock and no \"building now\" hint, and every row after it\n * keeps waiting.\n */\nfunction aiPausedRows(rows: AiSiteBuildRow[]): AiSiteBuildRow[] {\n const at = rows.findIndex((row) => row.state === 'active' || row.state === 'paused')\n const index = at >= 0 ? at : rows.findIndex((row) => row.state === 'waiting')\n return rows.map((row, position) => {\n if (row.state === 'active' && position !== index) return { ...row, state: 'waiting', hint: null, startedAt: null }\n if (position !== index) return row\n return { ...row, state: 'paused', hint: null, startedAt: null }\n })\n}\n\nfunction aiSiteBuildRowsOf(\n job: Pick<AiJobSummary, 'status' | 'steps' | 'plan' | 'outputs' | 'review'> &\n Partial<Pick<AiJobSummary, 'items' | 'kind' | 'siteInputs' | 'sitePublish'>>,\n): AiSiteBuildRow[] {\n const phase = aiSiteBuildPhase(job)\n // A build is read off its item ledger (AGL-3616): one row an item, each with\n // its own state and what became of its credits.\n if (job.items?.length) {\n const site = job.kind !== 'build'\n const pages = (job.items ?? []).filter((row) => row.op === 'page')\n // The plan keeps the credits it used once the items take over the page.\n const planStep = job.steps.find((step) => step.name === 'plan')\n return [\n {\n id: 'plan',\n label: site ? 'Planning your pages' : 'Planning what to build',\n state: 'done',\n ...(planStep ? { credits: Math.max(0, Math.floor(planStep.creditsSpent ?? 0)) } : {}),\n },\n ...aiBuildItemRows(job).map((row, index) => {\n const ledger = (job.items ?? [])[index]\n // A site keeps the scaffold's own words for each stage (AGL-3596).\n const label =\n !site || !ledger\n ? row.label\n : ledger.op === 'theme'\n ? AI_SITE_LOOK_ROW_LABEL\n : ledger.op === 'layout'\n ? `Building the header and footer: ${ledger.label}`\n : ledger.op === 'form'\n ? `Building the form: ${ledger.label}`\n : ledger.op === 'page'\n ? `Writing page ${pages.indexOf(ledger) + 1} of ${pages.length}: ${ledger.label}`\n : ledger.op === 'email'\n ? 'Writing your welcome email'\n : row.label\n const screen = ledger?.op === 'page' ? aiPlanScreenFor(job.plan, ledger.label, pages.indexOf(ledger)) : null\n const finished = row.state === 'done' || row.state === 'failed'\n const net = ledger ? Math.max(0, Math.floor((ledger.creditsSpent ?? 0) - (ledger.creditsRefunded ?? 0))) : 0\n return {\n id: row.slot,\n label,\n state: row.state,\n // A part that failed while the rest is still being built says the\n // build goes on (AGL-3596): read alone, it looked like the site had.\n detail:\n row.state === 'failed' && phase === 'working'\n ? [row.detail, site ? 'The rest of your site keeps building.' : 'The rest keeps building.'].filter(Boolean).join(' ')\n : row.detail,\n ...(row.state === 'active'\n ? {\n startedAt: row.startedAt ?? null,\n hint:\n ledger?.op === 'page'\n ? AI_SITE_PAGE_HINT\n : site && ledger?.op === 'theme'\n ? AI_SITE_LOOK_HINT\n : AI_SITE_ITEM_HINT,\n }\n : {}),\n ...(screen?.sections.length ? { sections: screen.sections.map((section) => section.name) } : {}),\n ...(finished && ledger ? { credits: net } : {}),\n }\n }),\n ...aiSitePublishRow(job, phase),\n ]\n }\n const planStep = job.steps.find((step) => step.name === 'plan')\n const planDone = planStep?.status === 'done' || Boolean(job.plan)\n const stopped = phase === 'failed' || phase === 'stopped'\n const paused = job.status === 'needs_input'\n const planState: AiSiteBuildRowState = planDone\n ? 'done'\n : paused\n ? 'paused'\n : stopped\n ? 'failed'\n : phase === 'working'\n ? 'active'\n : 'waiting'\n const rows: AiSiteBuildRow[] = [\n {\n id: 'plan',\n label: 'Planning your pages',\n state: planState,\n startedAt: planStep?.startedAt ?? null,\n hint: planState === 'active' ? AI_SITE_PLAN_HINT : null,\n ...(planDone && planStep ? { credits: Math.max(0, Math.floor(planStep.creditsSpent ?? 0)) } : {}),\n },\n ]\n // Before there is a plan, the stages a guided start always goes through\n // are named from its answers, so the page shows the whole way from the\n // start rather than one row.\n if (!job.plan && job.kind !== 'build') {\n const pagesAsked = typeof job.siteInputs?.['pages'] === 'number' ? Math.round(job.siteInputs['pages'] as number) : 0\n if (job.siteInputs) {\n // The look is designed first, before the header and footer (AGL-3660).\n rows.push({ id: 'look', label: AI_SITE_LOOK_ROW_LABEL, state: 'waiting' })\n rows.push({ id: 'layout', label: 'Building the header and footer', state: 'waiting' })\n // A guided start that says where its contact form's submissions go\n // plans that form, built after the layout and before the pages (AGL-3596).\n const submissions = job.siteInputs['submissions']\n if (submissions === 'inbox' || submissions === 'lead') {\n rows.push({ id: 'form', label: 'Building your contact form', state: 'waiting' })\n }\n rows.push({\n id: 'pages',\n label: pagesAsked > 1 ? `Writing your ${pagesAsked} pages` : 'Writing your pages',\n state: 'waiting',\n })\n rows.push(...aiSitePublishRow(job, phase))\n }\n return rows\n }\n const built = new Map<string, number>()\n for (const output of job.outputs) built.set(output.resource, (built.get(output.resource) ?? 0) + 1)\n const take = (resource: string): boolean => {\n const left = built.get(resource) ?? 0\n if (left <= 0) return false\n built.set(resource, left - 1)\n return true\n }\n const stages: Array<{ id: string; label: string; resource: string; sections?: string[]; hint?: string }> = []\n // A scaffold designs its look first on every start (AGL-3660), and writes\n // its item ledger only with that first pass's outcome — so while the look\n // is being designed, the job is read here, without a ledger, and the look\n // is the stage it is on: a moving site job that has built nothing yet. A\n // job read without its ledger that has built something and no look is one\n // from before the look had a unit of its own, and has the stage only where\n // it built one.\n const moving = (phase === 'working' || paused) && job.outputs.length === 0\n for (const row of CREATION_ROWS) {\n const creation = job.plan?.create.find((entry) => entry.kind === row.kind)\n const look = row.resource === 'theme'\n if (\n creation ||\n (look && job.kind !== 'build' && moving) ||\n (look && job.outputs.some((output) => output.resource === 'theme'))\n ) {\n stages.push({\n id: look ? 'look' : row.resource,\n label: row.label(creation?.name ?? ''),\n resource: row.resource,\n ...(look ? { hint: AI_SITE_LOOK_HINT } : {}),\n })\n }\n }\n const pages = job.plan?.screens ?? []\n pages.forEach((page, index) => {\n stages.push({\n id: `page-${index}`,\n label: `Writing page ${index + 1} of ${pages.length}: ${page.title}`,\n resource: 'screen',\n sections: page.sections.map((section) => section.name),\n })\n })\n // The build step's start: when the first stage after the plan began.\n const buildStartedAt = job.steps.find((step) => step.name !== 'plan' && step.startedAt)?.startedAt ?? null\n let reached = false\n for (const stage of stages) {\n const done = phase === 'done' || take(stage.resource)\n const current = !done && !reached && planDone\n if (current) reached = true\n const state: AiSiteBuildRowState = done\n ? 'done'\n : current && paused\n ? 'paused'\n : current && stopped\n ? 'failed'\n : current && phase === 'working'\n ? 'active'\n : 'waiting'\n rows.push({\n id: stage.id,\n label: stage.label,\n state,\n ...(state === 'active' && stage.hint ? { hint: stage.hint, startedAt: buildStartedAt } : {}),\n ...(stage.sections?.length ? { sections: stage.sections } : {}),\n })\n }\n rows.push(...aiSitePublishRow(job, phase))\n return rows\n}\n\n/** The row the site's look is designed on (AGL-3660). */\nexport const AI_SITE_LOOK_ROW_LABEL = 'Designing your look'\n\n/** What the look's row says while it runs. */\nexport const AI_SITE_LOOK_HINT =\n 'Choosing a base theme, colors, fonts and the style of your buttons, cards and forms for your kind of site. This takes a few seconds.'\n\n/** What the planning row says while it runs. */\nexport const AI_SITE_PLAN_HINT =\n 'Reading your answers and choosing your pages, what each one says, and the forms and layout they need. This usually takes under a minute.'\n\n/** What the page being written says while it is the active row (AGL-3596). */\nexport const AI_SITE_PAGE_HINT =\n 'Writing this page’s sections from your plan. It is done once every section is in.'\n\n/** What any other part being built says while it is the active row. */\nexport const AI_SITE_ITEM_HINT = 'Building this now. The next step starts when it is done.'\n\n/** The plan's page an item builds: by its title, else by its place among the pages. */\nfunction aiPlanScreenFor(\n plan: AiJobSummary['plan'],\n title: string,\n index: number,\n): NonNullable<AiJobSummary['plan']>['screens'][number] | null {\n const screens = plan?.screens ?? []\n return screens.find((screen) => screen.title === title) ?? (index >= 0 ? (screens[index] ?? null) : null)\n}\n\n/**\n * A guided start ends by putting its pages live (AGL-3596): the last row, so\n * the person sees that step coming and when it is done. Only a site job\n * publishes on its own; a build publishes when asked, and says so in its plan.\n */\nfunction aiSitePublishRow(\n job: Pick<AiJobSummary, 'status'> & Partial<Pick<AiJobSummary, 'kind' | 'sitePublish'>>,\n phase: AiSiteBuildPhase,\n): AiSiteBuildRow[] {\n if (job.kind !== 'site') return []\n const published = (job.sitePublish?.published.length ?? 0) > 0\n return [\n {\n id: 'publish',\n label: 'Publishing your site',\n // A job that stopped or failed publishes nothing, so the row is passed over.\n state: phase === 'done' ? (published ? 'done' : 'skipped') : phase === 'working' ? 'waiting' : 'skipped',\n },\n ]\n}\n\n/**\n * How far the job is, from 0 to 1, by its rows: a finished row counts whole\n * and the active one half. `null` before there is more than one row to count.\n */\nexport function aiSiteBuildFraction(rows: readonly AiSiteBuildRow[]): number | null {\n if (rows.length < 2) return null\n const counted = rows.reduce(\n (sum, row) => sum + (row.state === 'active' ? 0.5 : row.state === 'waiting' || row.state === 'paused' ? 0 : 1),\n 0,\n )\n return Math.min(1, counted / rows.length)\n}\n\n/**\n * The job's one price (AGL-3594), never a plan's on its own: what it has used\n * so far while it works, what it used once done, and, on a failure we gave\n * back, that nothing was charged.\n */\nexport function aiSiteBuildCreditsLine(\n job: Pick<AiJobSummary, 'status' | 'creditsSpent' | 'refundedCredits'> & Partial<Pick<AiJobSummary, 'kind'>>,\n): string | null {\n const spent = Math.max(0, job.creditsSpent ?? 0)\n const refunded = Math.max(0, job.refundedCredits ?? 0)\n const net = Math.max(0, spent - refunded)\n const phase = aiSiteBuildPhase(job)\n // What the job made, by its kind; a job that names none is a site's.\n const subject = !job.kind || job.kind === 'site' ? 'This site' : aiJobKindNoun(job.kind) === 'AI job' ? 'This AI job' : `This ${aiJobKindNoun(job.kind)}`\n // A failure on our side says so in the words every surface uses (AGL-3596),\n // from the job's recorded give-back.\n const refund = phase === 'working' || phase === 'done' ? null : aiJobRefundCopy(job)\n if (refund && refunded > 0) return refund\n // A person's cancel keeps what ran charged, and says how much (AGL-3616).\n if (phase === 'canceled') return aiJobCanceledCreditsCopy(job)\n if (phase === 'done') return `${subject} used ${net} credits.`\n if (phase === 'working') return `Credits used so far: ${net}`\n if (refund) return `${subject} used ${net} credits. ${refund}`\n return net > 0 ? `${subject} used ${net} credits.` : null\n}\n\n/** The heading and the sentence under it, for one job's page in its current phase. */\nexport interface AiJobPageCopy {\n heading: string\n lede: string\n}\n\n/**\n * What one job's page says at the top (AGL-3594, AGL-3596). A site job reads\n * as \"Building your site\"; any other kind names what it makes — \"Building\n * your page\" — or, for a kind with no noun, the job itself.\n *\n * A guided site start publishes its pages when it finishes, and says so\n * (`sitePublish`): with a page live the heading is \"Your site is live\". A\n * done site job without that record — an older job, or one that was not a\n * guided start — built drafts, and says that instead.\n */\nexport function aiJobPageCopy(\n job: Pick<AiJobSummary, 'kind' | 'status' | 'review' | 'error'> &\n Partial<Pick<AiJobSummary, 'sitePublish' | 'items' | 'outputs'>>,\n brand: string,\n): AiJobPageCopy {\n const phase = aiSiteBuildPhase(job)\n // Paused by the meter (AGL-3660): why, what is already built, and that it\n // carries on — never \"was not built\", which read as a dead end.\n if (job.status === 'needs_input') {\n return {\n heading: aiJobPausedTitle(job.kind),\n lede: [job.error, aiJobBuiltSoFar(job), AI_JOB_PAUSED_NEXT_COPY].filter(Boolean).join(' '),\n }\n }\n // A build is what the person asked for, item by item (AGL-3616).\n if (job.kind === 'build') return aiBuildPageCopy(job, brand)\n const noun = job.kind === 'site' ? 'site' : aiJobKindNoun(job.kind)\n const generic = noun === 'AI job'\n // `products` is the one plural noun.\n const isAre = noun.endsWith('s') ? 'are' : 'is'\n const why = job.review?.message ?? job.error ?? null\n if (phase === 'working') {\n return {\n heading: generic ? 'Your AI job is running' : `Building your ${noun}`,\n lede:\n job.kind === 'site'\n ? `${brand} AI is planning your pages and writing each one. You can leave this page; it keeps going.`\n : `${brand} AI is working on it. You can leave this page; it keeps going.`,\n }\n }\n if (phase === 'done') {\n const published = job.sitePublish?.published.length ?? 0\n // Part of the site was built (AGL-3616): what was, what was not, and its credits.\n const partial = job.kind === 'site' ? aiSitePartialCopy({ items: job.items, status: job.status }) : null\n if (job.kind === 'site' && published > 0) {\n return {\n heading: 'Your site is live',\n lede: [\n partial,\n job.sitePublish?.drafts.length\n ? 'Your pages are published, except the ones listed below, which stayed drafts.'\n : 'Your pages are published, and anyone can visit your site now.',\n ]\n .filter(Boolean)\n .join(' '),\n }\n }\n if (partial) return { heading: 'Your site is ready', lede: `${partial} Your new pages are drafts. Publish them when you’re happy.` }\n if (job.kind === 'site' && job.sitePublish) {\n return {\n heading: 'Your site is ready',\n lede: 'None of your new pages could be published, so they are drafts. The reasons are below.',\n }\n }\n return {\n heading: generic ? 'Your AI job finished' : `Your ${noun} ${isAre} ready`,\n lede:\n job.kind === 'site'\n ? 'Your new pages are drafts. Publish them when you’re happy.'\n : 'Everything it built is an unpublished draft until you publish it.',\n }\n }\n if (phase === 'canceled') {\n return { heading: generic ? 'Your AI job was canceled' : `You canceled your ${noun}`, lede: AI_JOB_CANCELED_LEDE }\n }\n return {\n heading: generic ? 'Your AI job stopped' : `Your ${noun} ${noun.endsWith('s') ? 'were' : 'was'} not built`,\n lede: why ?? (generic ? 'Something went wrong running this job.' : `Something went wrong building your ${noun}.`),\n }\n}\n\nconst joinWords = (names: string[]): string =>\n names.length <= 1 ? (names[0] ?? '') : `${names.slice(0, -1).join(', ')} and ${names[names.length - 1]}`\n\n/**\n * What a job has already built, in a sentence (AGL-3660): its look, the header\n * and footer, its form, its pages — from the item ledger where it has one,\n * else from what it has reported as outputs. `null` when it has built nothing.\n */\nexport function aiJobBuiltSoFar(\n job: Pick<AiJobSummary, 'kind'> & Partial<Pick<AiJobSummary, 'items' | 'outputs'>>,\n): string | null {\n const built = (job.items ?? []).filter((row) => row.status === 'succeeded' || row.status === 'degraded')\n const names: string[] = []\n if (job.items?.length) {\n for (const row of built) {\n if (row.op === 'theme') names.push('your look')\n else if (row.op === 'layout') names.push('the header and footer')\n else if (row.op === 'form') names.push(`the form “${row.label}”`)\n else if (row.op === 'page') names.push(`the page “${row.label}”`)\n else if (row.op === 'email') names.push('your welcome email')\n else names.push(`${aiBuildOpNoun(row.op).toLowerCase()} “${row.label}”`)\n }\n } else {\n const outputs = job.outputs ?? []\n const count = (resource: string) => outputs.filter((output) => output.resource === resource).length\n if (count('theme')) names.push('your look')\n if (count('layout')) names.push('the header and footer')\n if (count('form')) names.push(count('form') === 1 ? 'the form' : `${count('form')} forms`)\n const pages = count('screen')\n if (pages) names.push(pages === 1 ? '1 page' : `${pages} pages`)\n }\n return names.length ? `Built so far: ${joinWords(names)}.` : null\n}\n\n/** A build's page heading and sentence (AGL-3616). */\nfunction aiBuildPageCopy(\n job: Pick<AiJobSummary, 'status' | 'review' | 'error'> & Partial<Pick<AiJobSummary, 'items' | 'sitePublish'>>,\n brand: string,\n): AiJobPageCopy {\n const phase = aiSiteBuildPhase(job)\n const outcome = aiBuildOutcomeLine({ items: job.items ?? [], status: job.status })\n if (phase === 'working') {\n return {\n heading: 'Building what you asked for',\n lede: `${brand} AI is building each part in turn. You can leave this page; it keeps going.`,\n }\n }\n if (phase === 'stopped') {\n return {\n heading: job.review?.reason === 'plan' ? 'Your plan is ready' : 'Your build needs you',\n lede: job.review?.message ?? job.error ?? 'It waits for your decision.',\n }\n }\n if (phase === 'done') {\n const failed = (job.items ?? []).some((row) => row.status === 'failed' || row.status === 'skipped')\n const live = job.sitePublish?.published.length ?? 0\n return {\n heading: failed ? 'Most of it is ready' : 'Everything you asked for is ready',\n lede: [\n outcome,\n live ? 'Your new pages are published.' : 'Everything it built is an unpublished draft until you publish it.',\n failed ? 'Try again builds only what failed.' : '',\n ]\n .filter(Boolean)\n .join(' '),\n }\n }\n if (phase === 'canceled') return { heading: 'Your build was canceled', lede: AI_JOB_CANCELED_LEDE }\n return {\n heading: 'Nothing could be built',\n lede: [job.error ?? 'Something went wrong building what you asked for.', outcome].filter(Boolean).join(' '),\n }\n}\n"],"names":["AI_JOB_CANCELED_LEDE","aiJobCanceledCreditsCopy","aiJobConfirmingOwnPlan","aiJobKindNoun","aiJobRefundCopy","aiBuildItemRows","aiBuildOpNoun","aiBuildOutcomeLine","aiSitePartialCopy","AI_JOB_PAUSED_NEXT_COPY","aiJobPausedTitle","aiSiteBuildPhase","job","status","CREATION_ROWS","kind","resource","label","AI_SITE_LOOK_ROW_LABEL","name","aiSiteBuildRows","rows","aiSiteBuildRowsOf","aiPausedRows","at","findIndex","row","state","index","map","position","hint","startedAt","planStep","built","phase","items","length","site","pages","filter","op","steps","find","step","id","credits","Math","max","floor","creditsSpent","ledger","indexOf","screen","aiPlanScreenFor","plan","finished","net","creditsRefunded","slot","detail","Boolean","join","AI_SITE_PAGE_HINT","AI_SITE_LOOK_HINT","AI_SITE_ITEM_HINT","sections","section","aiSitePublishRow","planDone","stopped","paused","planState","AI_SITE_PLAN_HINT","pagesAsked","siteInputs","round","push","submissions","Map","output","outputs","set","get","take","left","stages","moving","creation","create","entry","look","some","screens","forEach","page","title","buildStartedAt","reached","stage","done","current","published","sitePublish","aiSiteBuildFraction","counted","reduce","sum","min","aiSiteBuildCreditsLine","spent","refunded","refundedCredits","subject","refund","aiJobPageCopy","brand","heading","lede","error","aiJobBuiltSoFar","aiBuildPageCopy","noun","generic","isAre","endsWith","why","review","message","partial","drafts","joinWords","names","slice","toLowerCase","count","outcome","reason","failed","live"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,oBAAoB,EAAEC,wBAAwB,QAAQ,0BAAsB;AACrF,SAASC,sBAAsB,EAAEC,aAAa,QAAQ,uBAAmB;AACzE,SAASC,eAAe,QAAQ,2BAAuB;AACvD,SAASC,eAAe,EAAEC,aAAa,EAAEC,kBAAkB,EAAEC,iBAAiB,QAAQ,yBAAqB;AAC3G,SAASC,uBAAuB,EAAEC,gBAAgB,QAAQ,qBAAiB;AAyC3E,OAAO,SAASC,iBACdC,GAAuG;IAEvG,yEAAyE;IACzE,+CAA+C;IAC/C,IAAIV,uBAAuBU,MAAM,OAAO;IACxC,OAAQA,IAAIC,MAAM;QAChB,KAAK;YACH,OAAO;QACT,KAAK;YACH,OAAO;QACT,KAAK;YACH,OAAO;QACT,KAAK;QACL,KAAK;YACH,OAAO;QACT;YACE,OAAO;IACX;AACF;AAEA,kGAAkG,GAClG,MAAMC,gBAAoG;IACxG;QAAEC,MAAM;QAAgBC,UAAU;QAASC,OAAO,IAAMC;IAAuB;IAC/E;QAAEH,MAAM;QAAUC,UAAU;QAAUC,OAAO,CAACE,OAAS,CAAC,gCAAgC,EAAEA,MAAM;IAAC;IACjG;QAAEJ,MAAM;QAAQC,UAAU;QAAQC,OAAO,CAACE,OAAS,CAAC,mBAAmB,EAAEA,MAAM;IAAC;CACjF;AAED;;;;;;;CAOC,GACD,OAAO,SAASC,gBACdR,GAC8E;IAE9E,MAAMS,OAAOC,kBAAkBV;IAC/B,OAAOA,IAAIC,MAAM,KAAK,gBAAgBU,aAAaF,QAAQA;AAC7D;AAEA;;;;;CAKC,GACD,SAASE,aAAaF,IAAsB;IAC1C,MAAMG,KAAKH,KAAKI,SAAS,CAAC,CAACC,MAAQA,IAAIC,KAAK,KAAK,YAAYD,IAAIC,KAAK,KAAK;I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AAAA,cAAAA,IAAImH,MAAM,qBAAVnH,YAAY6H,MAAM,MAAK,SAAS,uBAAuB;YAChEnB,IAAI,GAAE1G,iBAAAA,eAAAA,IAAImH,MAAM,qBAAVnH,aAAYoH,OAAO,oBAAIpH,IAAI2G,KAAK,YAAhC3G,OAAoC;QAC5C;IACF;IACA,IAAIuB,UAAU,QAAQ;YACJvB;YACHA;QADb,MAAM8H,SAAS,EAAC9H,cAAAA,IAAIwB,KAAK,YAATxB,cAAa,EAAE,EAAEgF,IAAI,CAAC,CAAClE,MAAQA,IAAIb,MAAM,KAAK,YAAYa,IAAIb,MAAM,KAAK;QACzF,MAAM8H,iBAAO/H,mBAAAA,IAAI2F,WAAW,qBAAf3F,iBAAiB0F,SAAS,CAACjE,MAAM,oBAAI;QAClD,OAAO;YACLgF,SAASqB,SAAS,wBAAwB;YAC1CpB,MAAM;gBACJkB;gBACAG,OAAO,kCAAkC;gBACzCD,SAAS,uCAAuC;aACjD,CACElG,MAAM,CAACqB,SACPC,IAAI,CAAC;QACV;IACF;IACA,IAAI3B,UAAU,YAAY,OAAO;QAAEkF,SAAS;QAA2BC,MAAMtH;IAAqB;IAClG,OAAO;QACLqH,SAAS;QACTC,MAAM;aAAC1G,aAAAA,IAAI2G,KAAK,YAAT3G,aAAa;YAAqD4H;SAAQ,CAAChG,MAAM,CAACqB,SAASC,IAAI,CAAC;IACzG;AACF"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/model/ai-site-build-progress.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 { AI_JOB_CANCELED_LEDE, aiJobCanceledCreditsCopy } from './ai-job-cancel-copy'\nimport { aiJobConfirmingOwnPlan, aiJobKindNoun } from './ai-job-activity'\nimport { aiJobRefundCopy } from './ai-job-failure-copy'\nimport { aiBuildItemRows, aiBuildOpNoun, aiBuildOutcomeLine, aiSitePartialCopy } from './ai-build-progress'\nimport { AI_JOB_PAUSED_NEXT_COPY, aiJobPausedTitle } from './ai-job-notice'\nimport type { AiJobOutputResource, AiJobSummary } from './ai-jobs.types'\n\n/**\n * What the \"Building your site\" page shows of a site job (AGL-3594): one row\n * a stage — planning the pages, then each page — with its state, the state\n * the whole job is in, and the job's one price.\n *\n * Read off the job summary every surface already follows: the plan step's\n * status, the plan's pages, and the pages the build has reported as outputs.\n * A scaffold builds its units in plan order and reports each page when it is\n * written, so the pages written so far are the first pages of the plan.\n *\n * Pure: no React, no request. The page and its spec read the same rows.\n */\n\n/**\n * `paused` (AGL-3660): the row a job the meter paused stopped at — not\n * running, not failed, and carried on from by Resume.\n */\nexport type AiSiteBuildRowState = 'done' | 'active' | 'waiting' | 'failed' | 'skipped' | 'paused'\n\nexport interface AiSiteBuildRow {\n id: string\n label: string\n state: AiSiteBuildRowState\n /** What the person should know about this row (AGL-3616): a build item's failure, note or refund. */\n detail?: string | null\n /** What the row is doing while it is the active one, in a sentence. */\n hint?: string | null\n /** A page's planned sections, in order, so the person sees what is being written. */\n sections?: string[]\n /** The credits this row's work used, once it has finished; absent while it runs. */\n credits?: number\n /** When this row's work started, for the elapsed time beside the active row. */\n startedAt?: string | null\n}\n\n/** Where the whole job stands, as the page's header and actions read it. */\nexport type AiSiteBuildPhase = 'working' | 'done' | 'stopped' | 'failed' | 'canceled'\n\nexport function aiSiteBuildPhase(\n job: Pick<AiJobSummary, 'status'> & Partial<Pick<AiJobSummary, 'review' | 'autoConfirm' | 'updatedAt'>>,\n): AiSiteBuildPhase {\n // A guided start's plan parked for the instant its confirmation takes is\n // the build going on (AGL-3596), never a stop.\n if (aiJobConfirmingOwnPlan(job)) return 'working'\n switch (job.status) {\n case 'done':\n return 'done'\n case 'failed':\n return 'failed'\n case 'canceled':\n return 'canceled'\n case 'needs_review':\n case 'needs_input':\n return 'stopped'\n default:\n return 'working'\n }\n}\n\n/** The creations a scaffold builds before its pages, in its build order, and what each row says. */\nconst CREATION_ROWS: ReadonlyArray<{ kind: string; resource: string; label: (name: string) => string }> = [\n { kind: 'theme-change', resource: 'theme', label: () => AI_SITE_LOOK_ROW_LABEL },\n { kind: 'layout', resource: 'layout', label: (name) => `Building the header and footer: ${name}` },\n { kind: 'form', resource: 'form', label: (name) => `Building the form: ${name}` },\n]\n\n/**\n * One row a stage: planning, then each creation the plan builds before its\n * pages — the colors, the layout, the form — then each page (AGL-3596). A\n * scaffold builds them in that order and reports each as an output when it\n * is written, so the first row without its output is where the build is, and\n * where a failure stopped it: a layout that broke is the layout's row, never\n * the first page's.\n */\nexport function aiSiteBuildRows(\n job: Pick<AiJobSummary, 'status' | 'steps' | 'plan' | 'outputs' | 'review'> &\n Partial<Pick<AiJobSummary, 'items' | 'kind' | 'siteInputs' | 'sitePublish'>>,\n): AiSiteBuildRow[] {\n const rows = aiSiteBuildRowsOf(job)\n return job.status === 'needs_input' ? aiPausedRows(rows) : rows\n}\n\n/**\n * A job the meter paused (AGL-3660) shows no spinner: the row it stopped at —\n * one still marked running, else the first not yet built — reads `paused`,\n * with no running clock and no \"building now\" hint, and every row after it\n * keeps waiting.\n */\nfunction aiPausedRows(rows: AiSiteBuildRow[]): AiSiteBuildRow[] {\n const at = rows.findIndex((row) => row.state === 'active' || row.state === 'paused')\n const index = at >= 0 ? at : rows.findIndex((row) => row.state === 'waiting')\n return rows.map((row, position) => {\n if (row.state === 'active' && position !== index) return { ...row, state: 'waiting', hint: null, startedAt: null }\n if (position !== index) return row\n return { ...row, state: 'paused', hint: null, startedAt: null }\n })\n}\n\nfunction aiSiteBuildRowsOf(\n job: Pick<AiJobSummary, 'status' | 'steps' | 'plan' | 'outputs' | 'review'> &\n Partial<Pick<AiJobSummary, 'items' | 'kind' | 'siteInputs' | 'sitePublish'>>,\n): AiSiteBuildRow[] {\n const phase = aiSiteBuildPhase(job)\n // A build is read off its item ledger (AGL-3616): one row an item, each with\n // its own state and what became of its credits.\n if (job.items?.length) {\n const site = job.kind !== 'build'\n const pages = (job.items ?? []).filter((row) => row.op === 'page')\n // The plan keeps the credits it used once the items take over the page.\n const planStep = job.steps.find((step) => step.name === 'plan')\n return [\n {\n id: 'plan',\n label: site ? 'Planning your pages' : 'Planning what to build',\n state: 'done',\n ...(planStep ? { credits: Math.max(0, Math.floor(planStep.creditsSpent ?? 0)) } : {}),\n },\n ...aiBuildItemRows(job).map((row, index) => {\n const ledger = (job.items ?? [])[index]\n // A site keeps the scaffold's own words for each stage (AGL-3596).\n const label =\n !site || !ledger\n ? row.label\n : ledger.op === 'theme'\n ? AI_SITE_LOOK_ROW_LABEL\n : ledger.op === 'layout'\n ? `Building the header and footer: ${ledger.label}`\n : ledger.op === 'form'\n ? `Building the form: ${ledger.label}`\n : ledger.op === 'page'\n ? `Writing page ${pages.indexOf(ledger) + 1} of ${pages.length}: ${ledger.label}`\n : ledger.op === 'email'\n ? 'Writing your welcome email'\n : row.label\n const screen = ledger?.op === 'page' ? aiPlanScreenFor(job.plan, ledger.label, pages.indexOf(ledger)) : null\n const finished = row.state === 'done' || row.state === 'failed'\n const net = ledger ? Math.max(0, Math.floor((ledger.creditsSpent ?? 0) - (ledger.creditsRefunded ?? 0))) : 0\n return {\n id: row.slot,\n label,\n state: row.state,\n // A part that failed while the rest is still being built says the\n // build goes on (AGL-3596): read alone, it looked like the site had.\n detail:\n row.state === 'failed' && phase === 'working'\n ? [row.detail, site ? 'The rest of your site keeps building.' : 'The rest keeps building.'].filter(Boolean).join(' ')\n : row.detail,\n ...(row.state === 'active'\n ? {\n startedAt: row.startedAt ?? null,\n hint:\n ledger?.op === 'page'\n ? AI_SITE_PAGE_HINT\n : site && ledger?.op === 'theme'\n ? AI_SITE_LOOK_HINT\n : AI_SITE_ITEM_HINT,\n }\n : {}),\n ...(screen?.sections.length ? { sections: screen.sections.map((section) => section.name) } : {}),\n ...(finished && ledger ? { credits: net } : {}),\n }\n }),\n ...aiSitePublishRow(job, phase),\n ]\n }\n const planStep = job.steps.find((step) => step.name === 'plan')\n // A job with no plan is not building pages: an answer, a summary, one change.\n if (job.steps.length > 0 && !planStep && !job.plan && job.kind !== 'site' && job.kind !== 'build') {\n return aiJobStepRows(job, phase)\n }\n const planDone = planStep?.status === 'done' || Boolean(job.plan)\n const stopped = phase === 'failed' || phase === 'stopped'\n const paused = job.status === 'needs_input'\n const planState: AiSiteBuildRowState = planDone\n ? 'done'\n : paused\n ? 'paused'\n : stopped\n ? 'failed'\n : phase === 'working'\n ? 'active'\n : 'waiting'\n const rows: AiSiteBuildRow[] = [\n {\n id: 'plan',\n label: 'Planning your pages',\n state: planState,\n startedAt: planStep?.startedAt ?? null,\n hint: planState === 'active' ? AI_SITE_PLAN_HINT : null,\n ...(planDone && planStep ? { credits: Math.max(0, Math.floor(planStep.creditsSpent ?? 0)) } : {}),\n },\n ]\n // Before there is a plan, the stages a guided start always goes through\n // are named from its answers, so the page shows the whole way from the\n // start rather than one row.\n if (!job.plan && job.kind !== 'build') {\n const pagesAsked = typeof job.siteInputs?.['pages'] === 'number' ? Math.round(job.siteInputs['pages'] as number) : 0\n if (job.siteInputs) {\n // The look is designed first, before the header and footer (AGL-3660).\n rows.push({ id: 'look', label: AI_SITE_LOOK_ROW_LABEL, state: 'waiting' })\n rows.push({ id: 'layout', label: 'Building the header and footer', state: 'waiting' })\n // A guided start that says where its contact form's submissions go\n // plans that form, built after the layout and before the pages (AGL-3596).\n const submissions = job.siteInputs['submissions']\n if (submissions === 'inbox' || submissions === 'lead') {\n rows.push({ id: 'form', label: 'Building your contact form', state: 'waiting' })\n }\n rows.push({\n id: 'pages',\n label: pagesAsked > 1 ? `Writing your ${pagesAsked} pages` : 'Writing your pages',\n state: 'waiting',\n })\n rows.push(...aiSitePublishRow(job, phase))\n }\n return rows\n }\n const built = new Map<string, number>()\n for (const output of job.outputs) built.set(output.resource, (built.get(output.resource) ?? 0) + 1)\n const take = (resource: string): boolean => {\n const left = built.get(resource) ?? 0\n if (left <= 0) return false\n built.set(resource, left - 1)\n return true\n }\n const stages: Array<{ id: string; label: string; resource: string; sections?: string[]; hint?: string }> = []\n // A scaffold designs its look first on every start (AGL-3660), and writes\n // its item ledger only with that first pass's outcome — so while the look\n // is being designed, the job is read here, without a ledger, and the look\n // is the stage it is on: a moving site job that has built nothing yet. A\n // job read without its ledger that has built something and no look is one\n // from before the look had a unit of its own, and has the stage only where\n // it built one.\n const moving = (phase === 'working' || paused) && job.outputs.length === 0\n for (const row of CREATION_ROWS) {\n const creation = job.plan?.create.find((entry) => entry.kind === row.kind)\n const look = row.resource === 'theme'\n if (\n creation ||\n (look && job.kind !== 'build' && moving) ||\n (look && job.outputs.some((output) => output.resource === 'theme'))\n ) {\n stages.push({\n id: look ? 'look' : row.resource,\n label: row.label(creation?.name ?? ''),\n resource: row.resource,\n ...(look ? { hint: AI_SITE_LOOK_HINT } : {}),\n })\n }\n }\n const pages = job.plan?.screens ?? []\n pages.forEach((page, index) => {\n stages.push({\n id: `page-${index}`,\n label: `Writing page ${index + 1} of ${pages.length}: ${page.title}`,\n resource: 'screen',\n sections: page.sections.map((section) => section.name),\n })\n })\n // The build step's start: when the first stage after the plan began.\n const buildStartedAt = job.steps.find((step) => step.name !== 'plan' && step.startedAt)?.startedAt ?? null\n let reached = false\n for (const stage of stages) {\n const done = phase === 'done' || take(stage.resource)\n const current = !done && !reached && planDone\n if (current) reached = true\n const state: AiSiteBuildRowState = done\n ? 'done'\n : current && paused\n ? 'paused'\n : current && stopped\n ? 'failed'\n : current && phase === 'working'\n ? 'active'\n : 'waiting'\n rows.push({\n id: stage.id,\n label: stage.label,\n state,\n ...(state === 'active' && stage.hint ? { hint: stage.hint, startedAt: buildStartedAt } : {}),\n ...(stage.sections?.length ? { sections: stage.sections } : {}),\n })\n }\n rows.push(...aiSitePublishRow(job, phase))\n return rows\n}\n\n/**\n * A job with no plan and no parts of its own to count: one row while it works,\n * and what it made once it is done, by the name each output carries.\n */\nfunction aiJobStepRows(\n job: Pick<AiJobSummary, 'status' | 'steps' | 'outputs'> & Partial<Pick<AiJobSummary, 'kind'>>,\n phase: AiSiteBuildPhase,\n): AiSiteBuildRow[] {\n if (phase === 'done' && job.outputs.length > 0) {\n return job.outputs.map((output, index) => ({\n id: `output-${index}`,\n label: output.label,\n state: 'done',\n detail: output.note ?? output.text ?? null,\n }))\n }\n const noun = job.kind ? aiJobKindNoun(job.kind) : 'AI job'\n const state: AiSiteBuildRowState =\n phase === 'done'\n ? 'done'\n : phase === 'working'\n ? 'active'\n : phase === 'stopped'\n ? 'paused'\n : phase === 'canceled'\n ? 'skipped'\n : 'failed'\n return [\n {\n id: 'work',\n label: phase === 'done' ? 'Finished' : `Working on ${noun === 'AI job' ? 'this job' : `your ${noun}`}`,\n state,\n startedAt: job.steps[job.steps.length - 1]?.startedAt ?? null,\n },\n ]\n}\n\n/** The row the site's look is designed on (AGL-3660). */\nexport const AI_SITE_LOOK_ROW_LABEL = 'Designing your look'\n\n/** What the look's row says while it runs. */\nexport const AI_SITE_LOOK_HINT =\n 'Choosing a base theme, colors, fonts and the style of your buttons, cards and forms for your kind of site. This takes a few seconds.'\n\n/** What the planning row says while it runs. */\nexport const AI_SITE_PLAN_HINT =\n 'Reading your answers and choosing your pages, what each one says, and the forms and layout they need. This usually takes under a minute.'\n\n/** What the page being written says while it is the active row (AGL-3596). */\nexport const AI_SITE_PAGE_HINT =\n 'Writing this page’s sections from your plan. It is done once every section is in.'\n\n/** What any other part being built says while it is the active row. */\nexport const AI_SITE_ITEM_HINT = 'Building this now. The next step starts when it is done.'\n\n/** The plan's page an item builds: by its title, else by its place among the pages. */\nfunction aiPlanScreenFor(\n plan: AiJobSummary['plan'],\n title: string,\n index: number,\n): NonNullable<AiJobSummary['plan']>['screens'][number] | null {\n const screens = plan?.screens ?? []\n return screens.find((screen) => screen.title === title) ?? (index >= 0 ? (screens[index] ?? null) : null)\n}\n\n/**\n * A guided start ends by putting its pages live (AGL-3596): the last row, so\n * the person sees that step coming and when it is done. Only a site job\n * publishes on its own; a build publishes when asked, and says so in its plan.\n */\nfunction aiSitePublishRow(\n job: Pick<AiJobSummary, 'status'> & Partial<Pick<AiJobSummary, 'kind' | 'sitePublish'>>,\n phase: AiSiteBuildPhase,\n): AiSiteBuildRow[] {\n if (job.kind !== 'site') return []\n const published = (job.sitePublish?.published.length ?? 0) > 0\n return [\n {\n id: 'publish',\n label: 'Publishing your site',\n // A job that stopped or failed publishes nothing, so the row is passed over.\n state: phase === 'done' ? (published ? 'done' : 'skipped') : phase === 'working' ? 'waiting' : 'skipped',\n },\n ]\n}\n\n/**\n * How far the job is, from 0 to 1, by its rows: a finished row counts whole\n * and the active one half. `null` before there is more than one row to count.\n */\nexport function aiSiteBuildFraction(rows: readonly AiSiteBuildRow[]): number | null {\n if (rows.length < 2) return null\n const counted = rows.reduce(\n (sum, row) => sum + (row.state === 'active' ? 0.5 : row.state === 'waiting' || row.state === 'paused' ? 0 : 1),\n 0,\n )\n return Math.min(1, counted / rows.length)\n}\n\n/**\n * The job's one price (AGL-3594), never a plan's on its own: what it has used\n * so far while it works, what it used once done, and, on a failure we gave\n * back, that nothing was charged.\n */\nexport function aiSiteBuildCreditsLine(\n job: Pick<AiJobSummary, 'status' | 'creditsSpent' | 'refundedCredits'> & Partial<Pick<AiJobSummary, 'kind'>>,\n): string | null {\n const spent = Math.max(0, job.creditsSpent ?? 0)\n const refunded = Math.max(0, job.refundedCredits ?? 0)\n const net = Math.max(0, spent - refunded)\n const phase = aiSiteBuildPhase(job)\n // What the job made, by its kind; a job that names none is a site's.\n const subject = !job.kind || job.kind === 'site' ? 'This site' : aiJobKindNoun(job.kind) === 'AI job' ? 'This AI job' : `This ${aiJobKindNoun(job.kind)}`\n // A failure on our side says so in the words every surface uses (AGL-3596),\n // from the job's recorded give-back.\n const refund = phase === 'working' || phase === 'done' ? null : aiJobRefundCopy(job)\n if (refund && refunded > 0) return refund\n // A person's cancel keeps what ran charged, and says how much (AGL-3616).\n if (phase === 'canceled') return aiJobCanceledCreditsCopy(job)\n if (phase === 'done') return `${subject} used ${net} credits.`\n if (phase === 'working') return `Credits used so far: ${net}`\n if (refund) return `${subject} used ${net} credits. ${refund}`\n return net > 0 ? `${subject} used ${net} credits.` : null\n}\n\n/** The most of a request a job's title carries. */\nexport const AI_JOB_TITLE_MAX_CHARS = 60\n\n/**\n * What a job's page is called: the first line of what was asked, so one job\n * among many can be told from the rest. Its state is the heading on the page.\n * `null` for a job with no request to name it by.\n */\nexport function aiJobPageTitle(job: Pick<AiJobSummary, 'brief'>): string | null {\n const line = job.brief.split('\\n').map((part) => part.trim()).find(Boolean)\n if (!line) return null\n return line.length > AI_JOB_TITLE_MAX_CHARS ? `${line.slice(0, AI_JOB_TITLE_MAX_CHARS).trimEnd()}…` : line\n}\n\n/** What a job leaves that is not a draft: saved straight onto the site. */\nconst AI_JOB_LIVE_RESOURCES: readonly AiJobOutputResource[] = ['settings', 'media', 'tracking', 'privacy']\n\n/** What a job leaves that touches no site: words for a person to read. */\nconst AI_JOB_ANSWER_RESOURCES: readonly AiJobOutputResource[] = ['insight', 'crm', 'text']\n\n/** The sentence under a finished job's heading, by what it actually left. */\nfunction aiJobDoneLede(job: Partial<Pick<AiJobSummary, 'outputs'>>): string {\n const resources = (job.outputs ?? []).map((output) => output.resource)\n const all = (kinds: readonly AiJobOutputResource[]) =>\n resources.length > 0 && resources.every((resource) => kinds.includes(resource))\n if (all(AI_JOB_ANSWER_RESOURCES)) return 'Nothing on your site changed.'\n if (all(AI_JOB_LIVE_RESOURCES)) return 'Its changes are saved and already live.'\n return 'Everything it built is an unpublished draft until you publish it.'\n}\n\n/** The heading and the sentence under it, for one job's page in its current phase. */\nexport interface AiJobPageCopy {\n heading: string\n lede: string\n}\n\n/**\n * What one job's page says at the top (AGL-3594, AGL-3596). A site job reads\n * as \"Building your site\"; any other kind names what it makes — \"Building\n * your page\" — or, for a kind with no noun, the job itself.\n *\n * A guided site start publishes its pages when it finishes, and says so\n * (`sitePublish`): with a page live the heading is \"Your site is live\". A\n * done site job without that record — an older job, or one that was not a\n * guided start — built drafts, and says that instead.\n */\nexport function aiJobPageCopy(\n job: Pick<AiJobSummary, 'kind' | 'status' | 'review' | 'error'> &\n Partial<Pick<AiJobSummary, 'sitePublish' | 'items' | 'outputs'>>,\n brand: string,\n): AiJobPageCopy {\n const phase = aiSiteBuildPhase(job)\n // Paused by the meter (AGL-3660): why, what is already built, and that it\n // carries on — never \"was not built\", which read as a dead end.\n if (job.status === 'needs_input') {\n return {\n heading: aiJobPausedTitle(job.kind),\n lede: [job.error, aiJobBuiltSoFar(job), AI_JOB_PAUSED_NEXT_COPY].filter(Boolean).join(' '),\n }\n }\n // A build is what the person asked for, item by item (AGL-3616).\n if (job.kind === 'build') return aiBuildPageCopy(job, brand)\n const noun = job.kind === 'site' ? 'site' : aiJobKindNoun(job.kind)\n const generic = noun === 'AI job'\n // `products` is the one plural noun.\n const isAre = noun.endsWith('s') ? 'are' : 'is'\n const why = job.review?.message ?? job.error ?? null\n if (phase === 'working') {\n return {\n heading: generic ? 'Your AI job is running' : `Building your ${noun}`,\n lede:\n job.kind === 'site'\n ? `${brand} AI is planning your pages and writing each one. You can leave this page; it keeps going.`\n : `${brand} AI is working on it. You can leave this page; it keeps going.`,\n }\n }\n if (phase === 'done') {\n const published = job.sitePublish?.published.length ?? 0\n // Part of the site was built (AGL-3616): what was, what was not, and its credits.\n const partial = job.kind === 'site' ? aiSitePartialCopy({ items: job.items, status: job.status }) : null\n if (job.kind === 'site' && published > 0) {\n return {\n heading: 'Your site is live',\n lede: [\n partial,\n job.sitePublish?.drafts.length\n ? 'Your pages are published, except the ones listed below, which stayed drafts.'\n : 'Your pages are published, and anyone can visit your site now.',\n ]\n .filter(Boolean)\n .join(' '),\n }\n }\n if (partial) return { heading: 'Your site is ready', lede: `${partial} Your new pages are drafts. Publish them when you’re happy.` }\n if (job.kind === 'site' && job.sitePublish) {\n return {\n heading: 'Your site is ready',\n lede: 'None of your new pages could be published, so they are drafts. The reasons are below.',\n }\n }\n return {\n heading: generic ? 'Your AI job finished' : `Your ${noun} ${isAre} ready`,\n lede:\n job.kind === 'site'\n ? 'Your new pages are drafts. Publish them when you’re happy.'\n : aiJobDoneLede(job),\n }\n }\n if (phase === 'canceled') {\n return { heading: generic ? 'Your AI job was canceled' : `You canceled your ${noun}`, lede: AI_JOB_CANCELED_LEDE }\n }\n return {\n heading: generic ? 'Your AI job stopped' : `Your ${noun} ${noun.endsWith('s') ? 'were' : 'was'} not built`,\n lede: why ?? (generic ? 'Something went wrong running this job.' : `Something went wrong building your ${noun}.`),\n }\n}\n\nconst joinWords = (names: string[]): string =>\n names.length <= 1 ? (names[0] ?? '') : `${names.slice(0, -1).join(', ')} and ${names[names.length - 1]}`\n\n/**\n * What a job has already built, in a sentence (AGL-3660): its look, the header\n * and footer, its form, its pages — from the item ledger where it has one,\n * else from what it has reported as outputs. `null` when it has built nothing.\n */\nexport function aiJobBuiltSoFar(\n job: Pick<AiJobSummary, 'kind'> & Partial<Pick<AiJobSummary, 'items' | 'outputs'>>,\n): string | null {\n const built = (job.items ?? []).filter((row) => row.status === 'succeeded' || row.status === 'degraded')\n const names: string[] = []\n if (job.items?.length) {\n for (const row of built) {\n if (row.op === 'theme') names.push('your look')\n else if (row.op === 'layout') names.push('the header and footer')\n else if (row.op === 'form') names.push(`the form “${row.label}”`)\n else if (row.op === 'page') names.push(`the page “${row.label}”`)\n else if (row.op === 'email') names.push('your welcome email')\n else names.push(`${aiBuildOpNoun(row.op).toLowerCase()} “${row.label}”`)\n }\n } else {\n const outputs = job.outputs ?? []\n const count = (resource: string) => outputs.filter((output) => output.resource === resource).length\n if (count('theme')) names.push('your look')\n if (count('layout')) names.push('the header and footer')\n if (count('form')) names.push(count('form') === 1 ? 'the form' : `${count('form')} forms`)\n const pages = count('screen')\n if (pages) names.push(pages === 1 ? '1 page' : `${pages} pages`)\n }\n return names.length ? `Built so far: ${joinWords(names)}.` : null\n}\n\n/** A build's page heading and sentence (AGL-3616). */\nfunction aiBuildPageCopy(\n job: Pick<AiJobSummary, 'status' | 'review' | 'error'> & Partial<Pick<AiJobSummary, 'items' | 'sitePublish'>>,\n brand: string,\n): AiJobPageCopy {\n const phase = aiSiteBuildPhase(job)\n const outcome = aiBuildOutcomeLine({ items: job.items ?? [], status: job.status })\n if (phase === 'working') {\n return {\n heading: 'Building what you asked for',\n lede: `${brand} AI is building each part in turn. You can leave this page; it keeps going.`,\n }\n }\n if (phase === 'stopped') {\n return {\n heading: job.review?.reason === 'plan' ? 'Your plan is ready' : 'Your build needs you',\n lede: job.review?.message ?? job.error ?? 'It waits for your decision.',\n }\n }\n if (phase === 'done') {\n const failed = (job.items ?? []).some((row) => row.status === 'failed' || row.status === 'skipped')\n const live = job.sitePublish?.published.length ?? 0\n return {\n heading: failed ? 'Most of it is ready' : 'Everything you asked for is ready',\n lede: [\n outcome,\n live ? 'Your new pages are published.' : 'Everything it built is an unpublished draft until you publish it.',\n failed ? 'Try again builds only what failed.' : '',\n ]\n .filter(Boolean)\n .join(' '),\n }\n }\n if (phase === 'canceled') return { heading: 'Your build was canceled', lede: AI_JOB_CANCELED_LEDE }\n return {\n heading: 'Nothing could be built',\n lede: [job.error ?? 'Something went wrong building what you asked for.', outcome].filter(Boolean).join(' '),\n }\n}\n"],"names":["AI_JOB_CANCELED_LEDE","aiJobCanceledCreditsCopy","aiJobConfirmingOwnPlan","aiJobKindNoun","aiJobRefundCopy","aiBuildItemRows","aiBuildOpNoun","aiBuildOutcomeLine","aiSitePartialCopy","AI_JOB_PAUSED_NEXT_COPY","aiJobPausedTitle","aiSiteBuildPhase","job","status","CREATION_ROWS","kind","resource","label","AI_SITE_LOOK_ROW_LABEL","name","aiSiteBuildRows","rows","aiSiteBuildRowsOf","aiPausedRows","at","findIndex","row","state","index","map","position","hint","startedAt","planStep","built","phase","items","length","site","pages","filter","op","steps","find","step","id","credits","Math","max","floor","creditsSpent","ledger","indexOf","screen","aiPlanScreenFor","plan","finished","net","creditsRefunded","slot","detail","Boolean","join","AI_SITE_PAGE_HINT","AI_SITE_LOOK_HINT","AI_SITE_ITEM_HINT","sections","section","aiSitePublishRow","aiJobStepRows","planDone","stopped","paused","planState","AI_SITE_PLAN_HINT","pagesAsked","siteInputs","round","push","submissions","Map","output","outputs","set","get","take","left","stages","moving","creation","create","entry","look","some","screens","forEach","page","title","buildStartedAt","reached","stage","done","current","note","text","noun","published","sitePublish","aiSiteBuildFraction","counted","reduce","sum","min","aiSiteBuildCreditsLine","spent","refunded","refundedCredits","subject","refund","AI_JOB_TITLE_MAX_CHARS","aiJobPageTitle","line","brief","split","part","trim","slice","trimEnd","AI_JOB_LIVE_RESOURCES","AI_JOB_ANSWER_RESOURCES","aiJobDoneLede","resources","all","kinds","every","includes","aiJobPageCopy","brand","heading","lede","error","aiJobBuiltSoFar","aiBuildPageCopy","generic","isAre","endsWith","why","review","message","partial","drafts","joinWords","names","toLowerCase","count","outcome","reason","failed","live"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,oBAAoB,EAAEC,wBAAwB,QAAQ,0BAAsB;AACrF,SAASC,sBAAsB,EAAEC,aAAa,QAAQ,uBAAmB;AACzE,SAASC,eAAe,QAAQ,2BAAuB;AACvD,SAASC,eAAe,EAAEC,aAAa,EAAEC,kBAAkB,EAAEC,iBAAiB,QAAQ,yBAAqB;AAC3G,SAASC,uBAAuB,EAAEC,gBAAgB,QAAQ,qBAAiB;AAyC3E,OAAO,SAASC,iBACdC,GAAuG;IAEvG,yEAAyE;IACzE,+CAA+C;IAC/C,IAAIV,uBAAuBU,MAAM,OAAO;IACxC,OAAQA,IAAIC,MAAM;QAChB,KAAK;YACH,OAAO;QACT,KAAK;YACH,OAAO;QACT,KAAK;YACH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B,UAAU,WAAW;QACvB,OAAO;YACLuG,SAAS;YACTC,MAAM,GAAGF,MAAM,2EAA2E,CAAC;QAC7F;IACF;IACA,IAAItG,UAAU,WAAW;YAGfvB;YADGA,aACHA;QAFR,OAAO;YACL8H,SAAS9H,EAAAA,cAAAA,IAAIuI,MAAM,qBAAVvI,YAAYgJ,MAAM,MAAK,SAAS,uBAAuB;YAChEjB,IAAI,GAAE/H,iBAAAA,eAAAA,IAAIuI,MAAM,qBAAVvI,aAAYwI,OAAO,oBAAIxI,IAAIgI,KAAK,YAAhChI,OAAoC;QAC5C;IACF;IACA,IAAIuB,UAAU,QAAQ;YACJvB;YACHA;QADb,MAAMiJ,SAAS,EAACjJ,cAAAA,IAAIwB,KAAK,YAATxB,cAAa,EAAE,EAAEiF,IAAI,CAAC,CAACnE,MAAQA,IAAIb,MAAM,KAAK,YAAYa,IAAIb,MAAM,KAAK;QACzF,MAAMiJ,iBAAOlJ,mBAAAA,IAAI+F,WAAW,qBAAf/F,iBAAiB8F,SAAS,CAACrE,MAAM,oBAAI;QAClD,OAAO;YACLqG,SAASmB,SAAS,wBAAwB;YAC1ClB,MAAM;gBACJgB;gBACAG,OAAO,kCAAkC;gBACzCD,SAAS,uCAAuC;aACjD,CACErH,MAAM,CAACqB,SACPC,IAAI,CAAC;QACV;IACF;IACA,IAAI3B,UAAU,YAAY,OAAO;QAAEuG,SAAS;QAA2BC,MAAM3I;IAAqB;IAClG,OAAO;QACL0I,SAAS;QACTC,MAAM;aAAC/H,aAAAA,IAAIgI,KAAK,YAAThI,aAAa;YAAqD+I;SAAQ,CAACnH,MAAM,CAACqB,SAASC,IAAI,CAAC;IACzG;AACF"}
|
|
@@ -75,6 +75,8 @@ export interface SiteImportPageFidelity {
|
|
|
75
75
|
read: SiteImportBand[];
|
|
76
76
|
drawn: SiteImportBand[];
|
|
77
77
|
};
|
|
78
|
+
/** Sections drawn as wide as the source runs them, or wider (AGL-4083); one the source sets no cap on counts as kept. */
|
|
79
|
+
widths: SiteImportFidelityCount;
|
|
78
80
|
/** The source's rows of two or more columns, set side by side on the page. */
|
|
79
81
|
rows: SiteImportFidelityCount;
|
|
80
82
|
/** The source's groups by kind. A group of lines that only share a shape (`text`) is drawn as its lines, and is not scored. */
|
|
@@ -25,11 +25,11 @@
|
|
|
25
25
|
*
|
|
26
26
|
* - **The words**: every line of the source exactly once, as written, and
|
|
27
27
|
* none of the page's own. A score of words is 1 or the page is wrong.
|
|
28
|
-
* - **The structure**: its sections
|
|
29
|
-
* side by side; its groups by kind, each item its own
|
|
30
|
-
* parts (an FAQ's question on an accordion, a card's link
|
|
31
|
-
* its tables, tab strips, pictures, icons, buttons as the
|
|
32
|
-
* them, headings and forms.
|
|
28
|
+
* - **The structure**: its sections, their bands and how wide they run; its
|
|
29
|
+
* rows of columns side by side; its groups by kind, each item its own
|
|
30
|
+
* element with its parts (an FAQ's question on an accordion, a card's link
|
|
31
|
+
* on the card); its tables, tab strips, pictures, icons, buttons as the
|
|
32
|
+
* source draws them, headings and forms.
|
|
33
33
|
* - **The frame** (`siteImportFrameFidelity`): the header's top-level items
|
|
34
34
|
* in order, each menu's entries with their lines and icons, the buttons,
|
|
35
35
|
* the phone menu holding all of it, labels on one line; the footer's
|
|
@@ -43,6 +43,7 @@
|
|
|
43
43
|
* site. The score is the lowest ratio of the structure; words are held apart
|
|
44
44
|
* at exactly 1.
|
|
45
45
|
*=========================================*/ import { _ as _extends } from "@swc/helpers/_/_extends";
|
|
46
|
+
import { siteImportWidthOf } from "./ai-site-import.js";
|
|
46
47
|
/** The lowest score of structure a page brought in ships at (AGL-4109); words are held at exactly 1. */ export const SITE_IMPORT_FIDELITY_THRESHOLD = 0.9;
|
|
47
48
|
/*------------------------------------------
|
|
48
49
|
* Words and lines
|
|
@@ -210,6 +211,12 @@ const ratioBoth = (source, built)=>({
|
|
|
210
211
|
const bestGap = Math.abs(best.at - cursor);
|
|
211
212
|
return gap < bestGap || gap === bestGap && piece.at >= cursor && best.at < cursor ? piece : best;
|
|
212
213
|
}, null);
|
|
214
|
+
// A line of marks a build joined to the line before it (a "—" beside its label) is in that line's piece,
|
|
215
|
+
// never the same mark further down the page, which would leave that one's line with nothing.
|
|
216
|
+
if (!wordsOf(text).length && previous !== null) {
|
|
217
|
+
const joined = pieces.find((piece)=>this.claimedBy.get(piece) === previous && clean(piece.text) !== text && clean(piece.text).endsWith(text));
|
|
218
|
+
if (joined) return joined;
|
|
219
|
+
}
|
|
213
220
|
const exact = pieces.filter((piece)=>piece.key === key && this.claimedBy.get(piece) === undefined);
|
|
214
221
|
if (exact.length) return pick(exact);
|
|
215
222
|
const padded = ` ${key} `;
|
|
@@ -522,6 +529,7 @@ const ratioBoth = (source, built)=>({
|
|
|
522
529
|
});
|
|
523
530
|
const pictures = picturesScore(source, built, placement);
|
|
524
531
|
const headings = headingsScore(source, built, placement);
|
|
532
|
+
const widths = widthsScore(sections, built, roots);
|
|
525
533
|
const forms = ratioBoth(sections.reduce((total, section)=>total + layoutNodes(section.nodes).filter((node)=>node.kind === 'form').length, 0), built.order.filter((id)=>{
|
|
526
534
|
var _built_node;
|
|
527
535
|
return ((_built_node = built.node(id)) == null ? void 0 : _built_node.componentId) === 'form';
|
|
@@ -533,6 +541,7 @@ const ratioBoth = (source, built)=>({
|
|
|
533
541
|
read,
|
|
534
542
|
drawn
|
|
535
543
|
}),
|
|
544
|
+
widths,
|
|
536
545
|
rows: ratioKept(rows.source, rows.built),
|
|
537
546
|
groups: Object.fromEntries(Object.entries(groups).map(([kind, entry])=>[
|
|
538
547
|
kind,
|
|
@@ -607,6 +616,29 @@ const ratioBoth = (source, built)=>({
|
|
|
607
616
|
}
|
|
608
617
|
};
|
|
609
618
|
}
|
|
619
|
+
const WIDTH_RANK = {
|
|
620
|
+
sm: 0,
|
|
621
|
+
md: 1,
|
|
622
|
+
lg: 2,
|
|
623
|
+
xl: 3
|
|
624
|
+
};
|
|
625
|
+
/** The sections as wide as their source: each section's Container against the cap the source sets; a section nothing caps runs the whole page. */ function widthsScore(sections, built, roots) {
|
|
626
|
+
const kept = sections.filter((section, index)=>{
|
|
627
|
+
var _built_node_props, _built_node;
|
|
628
|
+
const wanted = siteImportWidthOf(section.width);
|
|
629
|
+
if (!wanted) return true;
|
|
630
|
+
const root = roots[index];
|
|
631
|
+
if (!root) return false;
|
|
632
|
+
const container = built.under(root).find((id)=>{
|
|
633
|
+
var _built_node, _built_node_props, _built_node1;
|
|
634
|
+
return ((_built_node = built.node(id)) == null ? void 0 : _built_node.componentId) === 'muiContainer' && !((_built_node1 = built.node(id)) == null ? void 0 : (_built_node_props = _built_node1.props) == null ? void 0 : _built_node_props['disableGutters']);
|
|
635
|
+
});
|
|
636
|
+
if (!container) return true;
|
|
637
|
+
const rank = WIDTH_RANK[(_built_node = built.node(container)) == null ? void 0 : (_built_node_props = _built_node.props) == null ? void 0 : _built_node_props['maxWidth']];
|
|
638
|
+
return rank !== undefined && rank >= WIDTH_RANK[wanted];
|
|
639
|
+
});
|
|
640
|
+
return ratioKept(sections.length, kept.length);
|
|
641
|
+
}
|
|
610
642
|
/** The pictures: placed where the library's copies are known, else counted. */ function picturesScore(source, built, placement) {
|
|
611
643
|
var _source_photos;
|
|
612
644
|
const refs = source.layout.sections.flatMap((section)=>section.lines).filter((ref)=>{
|
|
@@ -644,6 +676,10 @@ const ratioBoth = (source, built)=>({
|
|
|
644
676
|
'bands',
|
|
645
677
|
report.bands
|
|
646
678
|
],
|
|
679
|
+
[
|
|
680
|
+
'widths',
|
|
681
|
+
report.widths
|
|
682
|
+
],
|
|
647
683
|
[
|
|
648
684
|
'rows',
|
|
649
685
|
report.rows
|