@aglyn/plugins-ai 1.31.0 → 1.33.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/README.md +2 -1
- package/package.json +17 -17
- package/src/lib/components/site-chat-api.d.ts +38 -0
- package/src/lib/components/site-chat-api.js +65 -0
- package/src/lib/components/site-chat-api.js.map +1 -0
- package/src/lib/components/site-chat-card.component.d.ts +31 -0
- package/src/lib/components/site-chat-card.component.js +474 -0
- package/src/lib/components/site-chat-card.component.js.map +1 -0
- package/src/lib/components/site-chat-panel.d.ts +38 -0
- package/src/lib/components/site-chat-panel.js +749 -0
- package/src/lib/components/site-chat-panel.js.map +1 -0
- package/src/lib/components/site-chat-runtime.d.ts +29 -0
- package/src/lib/components/site-chat-runtime.js +166 -0
- package/src/lib/components/site-chat-runtime.js.map +1 -0
- package/src/lib/declarations.js +5 -0
- package/src/lib/declarations.js.map +1 -1
- package/src/lib/jobs/ai-job-campaign-step.js +1 -0
- package/src/lib/jobs/ai-job-campaign-step.js.map +1 -1
- package/src/lib/jobs/ai-job-component-step.js +2 -1
- package/src/lib/jobs/ai-job-component-step.js.map +1 -1
- package/src/lib/jobs/ai-job-drafts.d.ts +8 -0
- package/src/lib/jobs/ai-job-drafts.js +18 -12
- package/src/lib/jobs/ai-job-drafts.js.map +1 -1
- package/src/lib/jobs/ai-job-edit-step.d.ts +5 -0
- package/src/lib/jobs/ai-job-edit-step.js +16 -9
- package/src/lib/jobs/ai-job-edit-step.js.map +1 -1
- package/src/lib/jobs/ai-job-email-step.js +1 -0
- package/src/lib/jobs/ai-job-email-step.js.map +1 -1
- package/src/lib/jobs/ai-job-form-step.js +2 -1
- package/src/lib/jobs/ai-job-form-step.js.map +1 -1
- package/src/lib/jobs/ai-job-layout-step.js +4 -1
- package/src/lib/jobs/ai-job-layout-step.js.map +1 -1
- package/src/lib/jobs/ai-job-navigation-step.js +7 -3
- package/src/lib/jobs/ai-job-navigation-step.js.map +1 -1
- package/src/lib/jobs/ai-job-page-step.js +7 -1
- package/src/lib/jobs/ai-job-page-step.js.map +1 -1
- package/src/lib/jobs/ai-job-privacy-step.d.ts +2 -0
- package/src/lib/jobs/ai-job-privacy-step.js +7 -4
- package/src/lib/jobs/ai-job-privacy-step.js.map +1 -1
- package/src/lib/jobs/ai-job-site-store-pages.js +3 -1
- package/src/lib/jobs/ai-job-site-store-pages.js.map +1 -1
- package/src/lib/jobs/ai-job-store-links-layout.js +8 -4
- package/src/lib/jobs/ai-job-store-links-layout.js.map +1 -1
- package/src/lib/jobs/ai-job-template-step.js +2 -1
- package/src/lib/jobs/ai-job-template-step.js.map +1 -1
- package/src/lib/jobs/ai-site-import-forms.js +2 -1
- package/src/lib/jobs/ai-site-import-forms.js.map +1 -1
- package/src/lib/jobs/ai-site-import-publish.d.ts +1 -1
- package/src/lib/jobs/ai-site-import-publish.js.map +1 -1
- package/src/lib/jobs/ai-site-late-photos.js +2 -1
- package/src/lib/jobs/ai-site-late-photos.js.map +1 -1
- package/src/lib/jobs/ai-site-publish.d.ts +2 -2
- package/src/lib/jobs/ai-site-publish.js +23 -15
- package/src/lib/jobs/ai-site-publish.js.map +1 -1
- package/src/lib/layout-language/ai-layout-frame-source.js +1 -0
- package/src/lib/layout-language/ai-layout-frame-source.js.map +1 -1
- package/src/lib/model/site-chat.d.ts +219 -0
- package/src/lib/model/site-chat.js +200 -0
- package/src/lib/model/site-chat.js.map +1 -0
- package/src/lib/plugin.js +10 -0
- package/src/lib/plugin.js.map +1 -1
- package/src/lib/runtime/ai-palette.generated.js +131 -0
- package/src/lib/runtime/ai-palette.generated.js.map +1 -1
- package/src/lib/server/ai-experiment-versions.js +6 -3
- package/src/lib/server/ai-experiment-versions.js.map +1 -1
- package/src/lib/server/ai-page-content.js +2 -1
- package/src/lib/server/ai-page-content.js.map +1 -1
- package/src/lib/server/ai-seo-apply.js +6 -3
- package/src/lib/server/ai-seo-apply.js.map +1 -1
- package/src/lib/server/site-chat-enricher.d.ts +29 -0
- package/src/lib/server/site-chat-enricher.js +41 -0
- package/src/lib/server/site-chat-enricher.js.map +1 -0
- package/src/lib/server/site-chat-owner-routes.d.ts +56 -0
- package/src/lib/server/site-chat-owner-routes.js +209 -0
- package/src/lib/server/site-chat-owner-routes.js.map +1 -0
- package/src/lib/server/site-chat-page-reads.d.ts +23 -0
- package/src/lib/server/site-chat-page-reads.js +32 -0
- package/src/lib/server/site-chat-page-reads.js.map +1 -0
- package/src/lib/server/site-chat-platform.d.ts +25 -0
- package/src/lib/server/site-chat-platform.js +405 -0
- package/src/lib/server/site-chat-platform.js.map +1 -0
- package/src/lib/server/site-chat-prompt.d.ts +83 -0
- package/src/lib/server/site-chat-prompt.js +166 -0
- package/src/lib/server/site-chat-prompt.js.map +1 -0
- package/src/lib/server/site-chat-session.d.ts +33 -0
- package/src/lib/server/site-chat-session.js +105 -0
- package/src/lib/server/site-chat-session.js.map +1 -0
- package/src/lib/server/site-chat-visitor-routes.d.ts +46 -0
- package/src/lib/server/site-chat-visitor-routes.js +105 -0
- package/src/lib/server/site-chat-visitor-routes.js.map +1 -0
- package/src/lib/server/site-chat.d.ts +119 -0
- package/src/lib/server/site-chat.js +500 -0
- package/src/lib/server/site-chat.js.map +1 -0
- package/src/lib/server.js +4 -0
- package/src/lib/server.js.map +1 -1
- package/src/lib/site-server.d.ts +23 -0
- package/src/lib/site-server.js +41 -0
- package/src/lib/site-server.js.map +1 -0
- package/src/lib/site.d.ts +23 -0
- package/src/lib/site.js +33 -0
- package/src/lib/site.js.map +1 -0
- package/src/lib/usage/site-chat-meter.d.ts +68 -0
- package/src/lib/usage/site-chat-meter.js +125 -0
- package/src/lib/usage/site-chat-meter.js.map +1 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/jobs/ai-site-late-photos.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 { CANVAS_ROOT_ELEMENT_ID } from '@aglyn/aglyn/foundation/constants/canvas'\nimport { pluginMediaIngest, type PluginMediaIngest } from '@aglyn/aglyn/plugin-manager/plugin-media-ingest'\nimport { pluginResourceDraftWriter } from '@aglyn/aglyn/plugin-manager/plugin-resource-drafts'\nimport {\n stockPhotoProvider,\n stockPhotoSourceKey,\n type StockPhotoProvider,\n} from '@aglyn/aglyn/plugin-manager/stock-photo-provider'\nimport type { NodesMap } from '@aglyn/aglyn/types/nodes'\nimport type { Firestore } from 'firebase-admin/firestore'\nimport {\n aiLayoutJobPhotoPicks,\n aiLayoutPlacePictures,\n type AiLayoutPicturePhoto,\n type AiLayoutPictureSlot,\n} from '../layout-language/ai-layout-pictures'\nimport type { AiJob } from '../model/ai-jobs.types'\nimport { aiSiteWords } from '../model/ai-site-job'\nimport {\n aiSiteIsStarterSrc,\n aiSitePhotosLastRefusalMs,\n type AiSitePhotos,\n type AiSiteStarterList,\n type AiStockRefusedPicks,\n} from '../model/ai-site-photos'\nimport { AI_DATASET_DRAFT_RESOURCE } from './ai-build-unit-outcome'\nimport { aiOriginJobId } from './ai-job-draft-ids'\nimport { readAiDraftNodes, updateAiDraftNodes } from './ai-job-drafts'\nimport { aiSiteProductPhotoSrc } from './ai-job-site-content'\nimport { aiSiteDatasetPlacedPhotoDetails, aiSiteDatasetRecordsFromOwn } from './ai-job-site-datasets'\nimport {\n AI_LAYOUT_STOCK_MAX_BYTES,\n AI_STOCK_PHOTO_OWN_REFUSALS,\n aiStockIngestRequest,\n aiStockPhotoAlt,\n aiStockPhotoWordsOf,\n aiStockPlacedPhotos,\n aiStockProperWords,\n} from './ai-layout-stock-photos'\n\n/**\n * THE LATE PHOTO PASS OF A SITE START (AGL-3988).\n *\n * Every page and every dataset of a guided start is built in a pass of its\n * own, and each copies its own stock photos as it goes. Pixabay's image hosts\n * (behind Cloudflare) answer a burst of downloads with 429 for minutes at a\n * time, whatever the client waits inside one pass. The v1.0.0-beta.271 Laurel\n * Fork Photography start (job yZUqIPmjIZ, 2026-10-19 23:05Z) had 22 cover\n * downloads refused in the beat that built its datasets, 11 on its home page\n * and 20 later. Photo 1846114, refused at 23:08, was copied at 23:10:42. The\n * \"Gallery collections\" covers were written before the job had copied any\n * photo, and the home page was built first, so each fell back to the office\n * team and the desk, which also became the site's share image.\n *\n * So once every page is built, and before the site is published, the site\n * step runs this pass over what the job holds in `sitePhotos`:\n *\n * 1. **The refused picks again, after the burst.** It waits until\n * {@link AI_SITE_LATE_PHOTOS_WAIT_MS} after the last refusal, then asks\n * each picture's own picks for again from the search that found them,\n * which the provider's 24-hour cache answers. No model, no credits. A\n * pick a later page copied is taken from the library; two downloads\n * refused in a row say the burst is not over, and nothing more is\n * downloaded.\n * 2. **Then the job's own photos, everywhere.** A picture still on a starter\n * takes (a) its own pick where the page does not show it yet, else (b)\n * one of the photos the job copied that the page does not show, by the\n * matchers its pages and covers already use: a page's picture by role,\n * shape and words, a hero a wide photo (`aiLayoutJobPhotoPicks`); and\n * only where none is left, (c) one the page shows elsewhere, and last\n * the photo beside it, since the other choice is a starter that shows\n * another business. A record goes by its category, then the people its\n * moment shows, its neighbor's photo only where nothing else is left,\n * from the end that repeats least (`aiSiteDatasetRecordsFromOwn`). A\n * team's records take only their own picks, never a photo of something\n * else.\n *\n * The pages' drafts are written in place, only where a picture still holds\n * a starter; the records through the data plugin's writer, only where a\n * record still holds the starter it was written with. A job that copied no\n * photo at all keeps its starters. Nothing here throws: a picture is\n * decoration, and a site is never held back by one.\n */\n\n/** How long after the image hosts refused a pick it is asked for again: their bursts clear within minutes. */\nexport const AI_SITE_LATE_PHOTOS_WAIT_MS = 60_000\n\n/** The wall clock the refused picks may take to copy, inside the pass's signal. */\nexport const AI_SITE_LATE_PHOTOS_COPY_MS = 30_000\n\n/**\n * Downloads refused in a row after which the pass downloads nothing more: the\n * burst is not over, and each refusal costs the image hosts' own backoff.\n */\nexport const AI_SITE_LATE_PHOTOS_REFUSALS_IN_A_ROW = 2\n\n/** ASSUMED: the pages' drafts, the records, and the publish that follows in the same pass. */\nexport const AI_SITE_LATE_PHOTOS_WRITES_MS = 20_000\n\n/** The least time the pass needs: the wait, the copies, and the writes after them. */\nexport const AI_SITE_LATE_PHOTOS_MINIMUM_MS =\n AI_SITE_LATE_PHOTOS_WAIT_MS + AI_SITE_LATE_PHOTOS_COPY_MS + AI_SITE_LATE_PHOTOS_WRITES_MS\n\nexport interface AiSiteLatePhotosInput {\n firestore: Firestore\n job: Pick<AiJob, '$id' | 'orgId' | 'hostId' | 'createdBy' | 'inputs' | 'plan' | 'outputs'>\n photos: AiSitePhotos\n /** The pages the start built: only their pictures are filled, and only their photos are the job's. */\n pageIds: readonly string[]\n org: Readonly<Record<string, unknown>> | null\n now: Date\n signal?: AbortSignal\n}\n\nexport interface AiSiteLatePhotosResult {\n /** What is left for another pass, where this one ran out of time; `null` once it is done. */\n photos: AiSitePhotos | null\n /** Pictures whose refused picks were asked for again, and of them copied. */\n retried: number\n copied: number\n /** Pictures given one of the job's own photos. */\n filled: number\n /** Pictures still on a starter. */\n left: number\n}\n\nexport interface AiSiteLatePhotosDeps {\n provider?: () => StockPhotoProvider | null\n ingest?: () => PluginMediaIngest | null\n readNodes?: typeof readAiDraftNodes\n updateNodes?: typeof updateAiDraftNodes\n writerFor?: typeof pluginResourceDraftWriter\n now?: () => number\n sleep?: (ms: number, signal?: AbortSignal) => Promise<void>\n}\n\n/** Waits `ms`, or less when `signal` aborts first; resolves either way. */\nfunction sleepFor(ms: number, signal?: AbortSignal): Promise<void> {\n return new Promise((resolve) => {\n if (signal?.aborted || ms <= 0) return resolve()\n const timer = setTimeout(done, ms)\n function done() {\n clearTimeout(timer)\n signal?.removeEventListener('abort', done)\n resolve()\n }\n signal?.addEventListener('abort', done, { once: true })\n })\n}\n\n/** One image of a stored page, in document order. */\ninterface PageImage {\n imageId: string\n src: string\n width: number\n height: number\n alt: string\n}\n\n/**\n * A stored page's pictures in document order, as its picture slots were:\n * every `image` showing a photo, never one bound to a record's field.\n */\nexport function aiSitePageImages(nodes: NodesMap, rootId = CANVAS_ROOT_ELEMENT_ID): PageImage[] {\n const map = nodes as unknown as Record<string, { componentId?: string; props?: Record<string, unknown>; nodes?: string[] }>\n const images: PageImage[] = []\n const seen = new Set<string>()\n const visit = (id: string) => {\n if (seen.has(id)) return\n seen.add(id)\n const node = map[id]\n if (!node) return\n if (node.componentId === 'image') {\n const src = node.props?.['src']\n if (typeof src === 'string' && src.trim() && !src.includes('{{')) {\n images.push({\n imageId: id,\n src,\n width: Number(node.props?.['intrinsicWidth']) || 0,\n height: Number(node.props?.['intrinsicHeight']) || 0,\n alt: typeof node.props?.['alt'] === 'string' ? (node.props['alt'] as string) : '',\n })\n }\n }\n for (const child of node.nodes ?? []) visit(child)\n }\n visit(rootId)\n return images\n}\n\n/** A starter slot as the matchers read it: its words, role and shape, and nothing it is not. */\nfunction slotOf(\n imageId: string,\n entry: { words: string; role: AiLayoutPictureSlot['role']; aspect: number } | null,\n): AiLayoutPictureSlot {\n return {\n imageId,\n frameId: null,\n iconId: null,\n alt: entry?.words ?? '',\n aspect: entry && entry.aspect > 0 ? entry.aspect : 1,\n sectionIndex: entry?.role === 'hero' ? 0 : 1,\n role: entry?.role ?? 'gallery',\n }\n}\n\n/**\n * The page with each starter its plan names given its photo, re-read on the\n * stored page: an image that no longer holds a starter is left as it is.\n */\nexport function aiSitePageWithPhotos(\n nodes: NodesMap,\n plan: ReadonlyArray<{ slot: AiLayoutPictureSlot; photo: AiLayoutPicturePhoto }>,\n): NodesMap | null {\n const map = nodes as unknown as Record<string, { props?: Record<string, unknown> }>\n const live = plan.filter(({ slot }) => aiSiteIsStarterSrc(map[slot.imageId]?.props?.['src']))\n if (!live.length) return null\n return aiLayoutPlacePictures(\n nodes,\n live.map(({ slot }) => slot),\n // A photo that brings no words of its own takes the slot's, never the starter's (AGL-3831).\n live.map(({ slot, photo }) => (photo.alt?.trim() || !slot.alt ? photo : { ...photo, alt: slot.alt })),\n )\n}\n\n/** Runs the late photo pass (see the module note). Never throws. */\nexport async function aiSiteLatePhotos(\n input: AiSiteLatePhotosInput,\n deps: AiSiteLatePhotosDeps = {},\n): Promise<AiSiteLatePhotosResult> {\n const { job, signal } = input\n const now = deps.now ?? Date.now\n const sleep = deps.sleep ?? sleepFor\n const readNodes = deps.readNodes ?? readAiDraftNodes\n const updateNodes = deps.updateNodes ?? updateAiDraftNodes\n const writerFor = deps.writerFor ?? pluginResourceDraftWriter\n const hostId = job.hostId ?? ''\n const built = new Set(input.pageIds)\n const pages = input.photos.pages.filter((page) => built.has(page.screen) && page.slots.length)\n const lists = input.photos.lists\n const counts = { retried: 0, copied: 0, filled: 0, left: 0 }\n const done = (): AiSiteLatePhotosResult => ({ photos: null, ...counts })\n if (!hostId || (!pages.length && !lists.length)) return done()\n const provider = (deps.provider ?? stockPhotoProvider)()\n const ingest = (deps.ingest ?? pluginMediaIngest)()\n try {\n // ── 1. The refused picks, asked for again once the burst is over ──\n const retried = new Map<string, AiLayoutPicturePhoto>()\n const asked: Array<{ key: string; picks: AiStockRefusedPicks; slot: AiLayoutPictureSlot }> = [\n // The pages first, each one's hero first: what a visitor sees first.\n ...pages.flatMap((page) =>\n [...page.slots]\n .sort((a, b) => Number(b.role === 'hero') - Number(a.role === 'hero'))\n .flatMap((slot) => (slot.refused ? [{ key: `${page.screen}:${slot.image}`, picks: slot.refused, slot: slotOf(slot.image, slot) }] : [])),\n ),\n ...lists.flatMap((list) =>\n list.records.flatMap((record, index) =>\n record.refused && aiSiteIsStarterSrc(record.value)\n ? [\n {\n key: `${list.dataset}:${index}`,\n picks: record.refused,\n slot: {\n ...slotOf(`record${index}`, { words: record.name, role: list.people ? 'about' : 'gallery', aspect: list.people ? 4 / 5 : 4 / 3 }),\n // A record's name is a search's words, never what its photo shows (AGL-3856).\n standIn: true,\n },\n },\n ]\n : [],\n ),\n ),\n ]\n if (asked.length && provider && ingest) {\n const last = aiSitePhotosLastRefusalMs({ pages, lists })\n const wait = last === null ? 0 : Math.min(AI_SITE_LATE_PHOTOS_WAIT_MS, Math.max(0, last + AI_SITE_LATE_PHOTOS_WAIT_MS - now()))\n if (wait > 0) await sleep(wait, signal)\n // The pass's own time ran out while it waited: the next pass picks it up.\n if (signal?.aborted) return { photos: input.photos, ...counts }\n const timeout = AbortSignal.timeout(AI_SITE_LATE_PHOTOS_COPY_MS)\n const copying = signal ? AbortSignal.any([signal, timeout]) : timeout\n const words = aiStockPhotoWordsOf(job)\n const proper = aiStockProperWords(aiSiteWords(job.inputs).about)\n /**\n * Whether a pick not in the site's library yet is still downloaded:\n * not once the library refused to store one, nor once two downloads\n * in a row were refused, which says the burst is not over. The picks\n * a later page copied are still looked up in the library.\n */\n let downloading = true\n let refusedInARow = 0\n for (const entry of asked) {\n if (copying.aborted) break\n counts.retried += 1\n const found = await provider.search(entry.picks.request, { signal: copying }).catch(() => null)\n for (const sourceKey of entry.picks.keys) {\n if (copying.aborted) break\n const photo = found?.photos.find((hit) => stockPhotoSourceKey(hit) === sourceKey)\n if (!photo) continue\n const alt = aiStockPhotoAlt(photo, entry.slot, { ...(words.language ? { language: words.language } : {}), proper }) ?? entry.slot.alt\n const kept = await ingest.findStockPhoto({ hostId, sourceKey }).catch(() => null)\n if (kept) {\n retried.set(entry.key, { src: kept.src, width: kept.width ?? photo.width, height: kept.height ?? photo.height, alt })\n break\n }\n if (!downloading) continue\n const bytes = await provider.download(photo, { maxBytes: AI_LAYOUT_STOCK_MAX_BYTES, signal: copying }).catch(() => null)\n if (copying.aborted) break\n if (!bytes) {\n refusedInARow += 1\n if (refusedInARow >= AI_SITE_LATE_PHOTOS_REFUSALS_IN_A_ROW) downloading = false\n continue\n }\n refusedInARow = 0\n const stored = await ingest\n .ingest(aiStockIngestRequest(provider, { hostId, uid: job.createdBy, photo, bytes, alt, query: entry.picks.request.query }))\n .catch(() => null)\n if (stored?.ok) {\n retried.set(entry.key, { src: stored.src, width: stored.width ?? photo.width, height: stored.height ?? photo.height, alt })\n counts.copied += 1\n break\n }\n // A refusal of this photo's own bytes tries the next pick; any other holds for the pass (AGL-3923).\n if (!stored || !AI_STOCK_PHOTO_OWN_REFUSALS.has(stored.status)) downloading = false\n }\n }\n }\n\n // The pass's own time ran out while it copied: the next pass finds what it copied in the library.\n if (signal?.aborted) return { photos: input.photos, ...counts }\n\n // ── 2. The job's own photos, for every picture still on a starter ──\n const read = new Map<string, NodesMap | null>()\n for (const id of built) {\n const stored = await readNodes(input.firestore, { kind: 'screen', hostId, id }).catch(() => null)\n read.set(id, stored?.nodes ?? null)\n }\n const seen = new Set<string>()\n const pool = [\n ...[...read.values()].flatMap((nodes) => aiStockPlacedPhotos(nodes)),\n ...lists.flatMap((list) => list.records.flatMap((record) => (record.photo ? [record.photo] : []))),\n ...aiSiteDatasetPlacedPhotoDetails(job.outputs ?? []),\n ...retried.values(),\n ].filter((photo) => photo.src.startsWith('media:') && !seen.has(photo.src) && Boolean(seen.add(photo.src)))\n const origin = aiOriginJobId(job)\n\n for (const page of pages) {\n const nodes = read.get(page.screen)\n if (!nodes) continue\n const images = aiSitePageImages(nodes)\n const entries = new Map(page.slots.map((slot) => [slot.image, slot]))\n const slots = images.map((image) => slotOf(image.imageId, entries.get(image.imageId) ?? null))\n const placed: Array<AiLayoutPicturePhoto | null> = images.map((image) =>\n aiSiteIsStarterSrc(image.src) ? null : { src: image.src, width: image.width, height: image.height, alt: image.alt },\n )\n const need = images.map((image) => entries.has(image.imageId) && aiSiteIsStarterSrc(image.src))\n const photos: Array<AiLayoutPicturePhoto | null> = images.map(() => null)\n // (a) A picture's own pick first, where the page does not show it yet;\n // else it is one of the job's photos like any other.\n images.forEach((image, index) => {\n const own = need[index] ? retried.get(`${page.screen}:${image.imageId}`) : undefined\n if (!own || placed.some((photo) => photo?.src === own.src)) return\n photos[index] = own\n placed[index] = own\n need[index] = false\n })\n // (b) Then the job's photos, by the matcher the page's own pass used: one\n // the page does not show first; (c) a repeat only where nothing else is\n // left, since the other choice is a starter that shows another business.\n if (pool.length) {\n aiLayoutJobPhotoPicks(slots, need, pool, placed, `${origin}:${page.screen}:late`, { repeats: 'last' }).forEach((pick, index) => {\n if (pick && need[index]) photos[index] = pick\n })\n }\n const starters = images.filter((image) => entries.has(image.imageId) && aiSiteIsStarterSrc(image.src)).length\n const plan = images.flatMap((image, index) => {\n const photo = photos[index]\n return photo ? [{ slot: slots[index] as AiLayoutPictureSlot, photo }] : []\n })\n const update = plan.length\n ? await updateNodes(input.firestore, {\n kind: 'screen',\n hostId,\n id: page.screen,\n now: input.now,\n update: (current) => aiSitePageWithPhotos(current, plan),\n })\n : null\n const filled = update?.ok ? plan.length : 0\n counts.filled += filled\n counts.left += Math.max(0, starters - filled)\n }\n\n for (const list of lists) {\n const filled = aiSiteListPhotos(list, retried, pool, `${origin}:${list.dataset}:late`)\n const records = filled.flatMap((photo, index) => {\n const record = list.records[index]\n const value = photo ? aiSiteProductPhotoSrc(photo.src, hostId) : null\n if (!record || !photo || !value || !aiSiteIsStarterSrc(record.value)) return []\n return [\n {\n order: index,\n // The starter's words go with it: a photo that brings none leaves the description empty (AGL-3856).\n values: { [list.imageField]: value, ...(list.altField ? { [list.altField]: photo.alt?.trim() ?? '' } : {}) },\n where: { [list.imageField]: record.value },\n },\n ]\n })\n const starters = list.records.filter((record) => aiSiteIsStarterSrc(record.value)).length\n if (!records.length) {\n counts.left += starters\n continue\n }\n const keeper = writerFor(AI_DATASET_DRAFT_RESOURCE)\n if (!keeper?.writer.reviseRecords) {\n console.warn('ai site late photos: the dataset writer cannot change records here', { jobId: job.$id, dataset: list.dataset })\n counts.left += starters\n continue\n }\n const revised = await keeper.writer.reviseRecords({\n orgId: job.orgId,\n hostId,\n uid: job.createdBy,\n org: input.org,\n now: input.now,\n id: list.dataset,\n records,\n })\n const changed = revised.ok ? revised.changed : 0\n if (revised.ok === false) {\n console.warn('ai site late photos: the dataset writer refused the covers', { jobId: job.$id, dataset: list.dataset, status: revised.status })\n }\n counts.filled += changed\n counts.left += Math.max(0, starters - changed)\n }\n console.info('ai site late photos', { jobId: job.$id, hostId, ...counts })\n return done()\n } catch (error) {\n // The site is built either way; its pictures keep what they hold.\n if (signal?.aborted) return { photos: input.photos, ...counts }\n console.error('ai site late photos failed; the site keeps its pictures as they are', { jobId: job.$id, error: String(error) })\n return done()\n }\n}\n\n/**\n * A list's records' photos once the late pass is done (AGL-3988): each\n * record's own refused pick where it was copied, then, for a list of things,\n * one of the photos it or the job shows (`aiSiteDatasetRecordsFromOwn`). A\n * team's records take only their own picks: no photo of the job's is of\n * one of the business's people. Pure.\n */\nexport function aiSiteListPhotos(\n list: AiSiteStarterList,\n retried: ReadonlyMap<string, AiLayoutPicturePhoto>,\n pool: readonly AiLayoutPicturePhoto[],\n seed: string,\n): Array<AiLayoutPicturePhoto | null> {\n const current = list.records.map((record, index): AiLayoutPicturePhoto | null =>\n aiSiteIsStarterSrc(record.value) ? (retried.get(`${list.dataset}:${index}`) ?? null) : (record.photo ?? null),\n )\n if (list.people) return current\n return aiSiteDatasetRecordsFromOwn(\n list.records.map((record) => ({ name: record.name, category: record.category ?? null, ...(record.itsOwn ? { itsOwn: true } : {}) })),\n current,\n seed,\n pool,\n // A starter is the other choice: a record every photo sits beside takes one anyway.\n { besideLast: true },\n )\n}\n"],"names":["CANVAS_ROOT_ELEMENT_ID","pluginMediaIngest","pluginResourceDraftWriter","stockPhotoProvider","stockPhotoSourceKey","aiLayoutJobPhotoPicks","aiLayoutPlacePictures","aiSiteWords","aiSiteIsStarterSrc","aiSitePhotosLastRefusalMs","AI_DATASET_DRAFT_RESOURCE","aiOriginJobId","readAiDraftNodes","updateAiDraftNodes","aiSiteProductPhotoSrc","aiSiteDatasetPlacedPhotoDetails","aiSiteDatasetRecordsFromOwn","AI_LAYOUT_STOCK_MAX_BYTES","AI_STOCK_PHOTO_OWN_REFUSALS","aiStockIngestRequest","aiStockPhotoAlt","aiStockPhotoWordsOf","aiStockPlacedPhotos","aiStockProperWords","AI_SITE_LATE_PHOTOS_WAIT_MS","AI_SITE_LATE_PHOTOS_COPY_MS","AI_SITE_LATE_PHOTOS_REFUSALS_IN_A_ROW","AI_SITE_LATE_PHOTOS_WRITES_MS","AI_SITE_LATE_PHOTOS_MINIMUM_MS","sleepFor","ms","signal","Promise","resolve","aborted","timer","setTimeout","done","clearTimeout","removeEventListener","addEventListener","once","aiSitePageImages","nodes","rootId","map","images","seen","Set","visit","id","node","has","add","componentId","src","props","trim","includes","push","imageId","width","Number","height","alt","child","slotOf","entry","frameId","iconId","words","aspect","sectionIndex","role","aiSitePageWithPhotos","plan","live","filter","slot","length","photo","aiSiteLatePhotos","input","deps","job","now","Date","sleep","readNodes","updateNodes","writerFor","hostId","built","pageIds","pages","photos","page","screen","slots","lists","counts","retried","copied","filled","left","provider","ingest","Map","asked","flatMap","sort","a","b","refused","key","image","picks","list","records","record","index","value","dataset","name","people","standIn","last","wait","Math","min","max","timeout","AbortSignal","copying","any","proper","inputs","about","downloading","refusedInARow","found","search","request","catch","sourceKey","keys","find","hit","language","kept","findStockPhoto","set","bytes","download","maxBytes","stored","uid","createdBy","query","ok","status","read","firestore","kind","pool","values","outputs","startsWith","Boolean","origin","get","entries","placed","need","forEach","own","undefined","some","repeats","pick","starters","update","current","aiSiteListPhotos","order","imageField","altField","where","keeper","writer","reviseRecords","console","warn","jobId","$id","revised","orgId","org","changed","info","error","String","seed","category","itsOwn","besideLast"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,sBAAsB,QAAQ,2CAA0C;AACjF,SAASC,iBAAiB,QAAgC,kDAAiD;AAC3G,SAASC,yBAAyB,QAAQ,qDAAoD;AAC9F,SACEC,kBAAk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OAAOD;QAAO;QAC5H,OAAOnK;IACT;AACF;AAEA;;;;;;CAMC,GACD,OAAO,SAASkJ,iBACdlE,IAAuB,EACvBhB,OAAkD,EAClD+D,IAAqC,EACrCsC,IAAY;IAEZ,MAAMpB,UAAUjE,KAAKC,OAAO,CAACzE,GAAG,CAAC,CAAC0E,QAAQC;YACJnB,cAAoDkB;eAAxF/G,mBAAmB+G,OAAOE,KAAK,KAAKpB,eAAAA,QAAQqE,GAAG,CAAC,GAAGrD,KAAKK,OAAO,CAAC,CAAC,EAAEF,OAAO,aAAtCnB,eAA2C,QAASkB,gBAAAA,OAAOvC,KAAK,YAAZuC,gBAAgB;;IAE1G,IAAIF,KAAKO,MAAM,EAAE,OAAO0D;IACxB,OAAOtK,4BACLqG,KAAKC,OAAO,CAACzE,GAAG,CAAC,CAAC0E;YAA2CA;eAA/B;YAAEI,MAAMJ,OAAOI,IAAI;YAAEgF,QAAQ,GAAEpF,mBAAAA,OAAOoF,QAAQ,YAAfpF,mBAAmB;WAAUA,OAAOqF,MAAM,GAAG;YAAEA,QAAQ;QAAK,IAAI,CAAC;QAC9HtB,SACAoB,MACAtC,MACA,oFAAoF;IACpF;QAAEyC,YAAY;IAAK;AAEvB"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/jobs/ai-site-late-photos.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 { CANVAS_ROOT_ELEMENT_ID } from '@aglyn/aglyn/foundation/constants/canvas'\nimport { pluginMediaIngest, type PluginMediaIngest } from '@aglyn/aglyn/plugin-manager/plugin-media-ingest'\nimport { pluginResourceDraftWriter } from '@aglyn/aglyn/plugin-manager/plugin-resource-drafts'\nimport {\n stockPhotoProvider,\n stockPhotoSourceKey,\n type StockPhotoProvider,\n} from '@aglyn/aglyn/plugin-manager/stock-photo-provider'\nimport type { NodesMap } from '@aglyn/aglyn/types/nodes'\nimport type { Firestore } from 'firebase-admin/firestore'\nimport {\n aiLayoutJobPhotoPicks,\n aiLayoutPlacePictures,\n type AiLayoutPicturePhoto,\n type AiLayoutPictureSlot,\n} from '../layout-language/ai-layout-pictures'\nimport type { AiJob } from '../model/ai-jobs.types'\nimport { aiSiteWords } from '../model/ai-site-job'\nimport {\n aiSiteIsStarterSrc,\n aiSitePhotosLastRefusalMs,\n type AiSitePhotos,\n type AiSiteStarterList,\n type AiStockRefusedPicks,\n} from '../model/ai-site-photos'\nimport { AI_DATASET_DRAFT_RESOURCE } from './ai-build-unit-outcome'\nimport { aiOriginJobId } from './ai-job-draft-ids'\nimport { aiJobContentActor, readAiDraftNodes, updateAiDraftNodes } from './ai-job-drafts'\nimport { aiSiteProductPhotoSrc } from './ai-job-site-content'\nimport { aiSiteDatasetPlacedPhotoDetails, aiSiteDatasetRecordsFromOwn } from './ai-job-site-datasets'\nimport {\n AI_LAYOUT_STOCK_MAX_BYTES,\n AI_STOCK_PHOTO_OWN_REFUSALS,\n aiStockIngestRequest,\n aiStockPhotoAlt,\n aiStockPhotoWordsOf,\n aiStockPlacedPhotos,\n aiStockProperWords,\n} from './ai-layout-stock-photos'\n\n/**\n * THE LATE PHOTO PASS OF A SITE START (AGL-3988).\n *\n * Every page and every dataset of a guided start is built in a pass of its\n * own, and each copies its own stock photos as it goes. Pixabay's image hosts\n * (behind Cloudflare) answer a burst of downloads with 429 for minutes at a\n * time, whatever the client waits inside one pass. The v1.0.0-beta.271 Laurel\n * Fork Photography start (job yZUqIPmjIZ, 2026-10-19 23:05Z) had 22 cover\n * downloads refused in the beat that built its datasets, 11 on its home page\n * and 20 later. Photo 1846114, refused at 23:08, was copied at 23:10:42. The\n * \"Gallery collections\" covers were written before the job had copied any\n * photo, and the home page was built first, so each fell back to the office\n * team and the desk, which also became the site's share image.\n *\n * So once every page is built, and before the site is published, the site\n * step runs this pass over what the job holds in `sitePhotos`:\n *\n * 1. **The refused picks again, after the burst.** It waits until\n * {@link AI_SITE_LATE_PHOTOS_WAIT_MS} after the last refusal, then asks\n * each picture's own picks for again from the search that found them,\n * which the provider's 24-hour cache answers. No model, no credits. A\n * pick a later page copied is taken from the library; two downloads\n * refused in a row say the burst is not over, and nothing more is\n * downloaded.\n * 2. **Then the job's own photos, everywhere.** A picture still on a starter\n * takes (a) its own pick where the page does not show it yet, else (b)\n * one of the photos the job copied that the page does not show, by the\n * matchers its pages and covers already use: a page's picture by role,\n * shape and words, a hero a wide photo (`aiLayoutJobPhotoPicks`); and\n * only where none is left, (c) one the page shows elsewhere, and last\n * the photo beside it, since the other choice is a starter that shows\n * another business. A record goes by its category, then the people its\n * moment shows, its neighbor's photo only where nothing else is left,\n * from the end that repeats least (`aiSiteDatasetRecordsFromOwn`). A\n * team's records take only their own picks, never a photo of something\n * else.\n *\n * The pages' drafts are written in place, only where a picture still holds\n * a starter; the records through the data plugin's writer, only where a\n * record still holds the starter it was written with. A job that copied no\n * photo at all keeps its starters. Nothing here throws: a picture is\n * decoration, and a site is never held back by one.\n */\n\n/** How long after the image hosts refused a pick it is asked for again: their bursts clear within minutes. */\nexport const AI_SITE_LATE_PHOTOS_WAIT_MS = 60_000\n\n/** The wall clock the refused picks may take to copy, inside the pass's signal. */\nexport const AI_SITE_LATE_PHOTOS_COPY_MS = 30_000\n\n/**\n * Downloads refused in a row after which the pass downloads nothing more: the\n * burst is not over, and each refusal costs the image hosts' own backoff.\n */\nexport const AI_SITE_LATE_PHOTOS_REFUSALS_IN_A_ROW = 2\n\n/** ASSUMED: the pages' drafts, the records, and the publish that follows in the same pass. */\nexport const AI_SITE_LATE_PHOTOS_WRITES_MS = 20_000\n\n/** The least time the pass needs: the wait, the copies, and the writes after them. */\nexport const AI_SITE_LATE_PHOTOS_MINIMUM_MS =\n AI_SITE_LATE_PHOTOS_WAIT_MS + AI_SITE_LATE_PHOTOS_COPY_MS + AI_SITE_LATE_PHOTOS_WRITES_MS\n\nexport interface AiSiteLatePhotosInput {\n firestore: Firestore\n job: Pick<AiJob, '$id' | 'orgId' | 'hostId' | 'createdBy' | 'inputs' | 'plan' | 'outputs'>\n photos: AiSitePhotos\n /** The pages the start built: only their pictures are filled, and only their photos are the job's. */\n pageIds: readonly string[]\n org: Readonly<Record<string, unknown>> | null\n now: Date\n signal?: AbortSignal\n}\n\nexport interface AiSiteLatePhotosResult {\n /** What is left for another pass, where this one ran out of time; `null` once it is done. */\n photos: AiSitePhotos | null\n /** Pictures whose refused picks were asked for again, and of them copied. */\n retried: number\n copied: number\n /** Pictures given one of the job's own photos. */\n filled: number\n /** Pictures still on a starter. */\n left: number\n}\n\nexport interface AiSiteLatePhotosDeps {\n provider?: () => StockPhotoProvider | null\n ingest?: () => PluginMediaIngest | null\n readNodes?: typeof readAiDraftNodes\n updateNodes?: typeof updateAiDraftNodes\n writerFor?: typeof pluginResourceDraftWriter\n now?: () => number\n sleep?: (ms: number, signal?: AbortSignal) => Promise<void>\n}\n\n/** Waits `ms`, or less when `signal` aborts first; resolves either way. */\nfunction sleepFor(ms: number, signal?: AbortSignal): Promise<void> {\n return new Promise((resolve) => {\n if (signal?.aborted || ms <= 0) return resolve()\n const timer = setTimeout(done, ms)\n function done() {\n clearTimeout(timer)\n signal?.removeEventListener('abort', done)\n resolve()\n }\n signal?.addEventListener('abort', done, { once: true })\n })\n}\n\n/** One image of a stored page, in document order. */\ninterface PageImage {\n imageId: string\n src: string\n width: number\n height: number\n alt: string\n}\n\n/**\n * A stored page's pictures in document order, as its picture slots were:\n * every `image` showing a photo, never one bound to a record's field.\n */\nexport function aiSitePageImages(nodes: NodesMap, rootId = CANVAS_ROOT_ELEMENT_ID): PageImage[] {\n const map = nodes as unknown as Record<string, { componentId?: string; props?: Record<string, unknown>; nodes?: string[] }>\n const images: PageImage[] = []\n const seen = new Set<string>()\n const visit = (id: string) => {\n if (seen.has(id)) return\n seen.add(id)\n const node = map[id]\n if (!node) return\n if (node.componentId === 'image') {\n const src = node.props?.['src']\n if (typeof src === 'string' && src.trim() && !src.includes('{{')) {\n images.push({\n imageId: id,\n src,\n width: Number(node.props?.['intrinsicWidth']) || 0,\n height: Number(node.props?.['intrinsicHeight']) || 0,\n alt: typeof node.props?.['alt'] === 'string' ? (node.props['alt'] as string) : '',\n })\n }\n }\n for (const child of node.nodes ?? []) visit(child)\n }\n visit(rootId)\n return images\n}\n\n/** A starter slot as the matchers read it: its words, role and shape, and nothing it is not. */\nfunction slotOf(\n imageId: string,\n entry: { words: string; role: AiLayoutPictureSlot['role']; aspect: number } | null,\n): AiLayoutPictureSlot {\n return {\n imageId,\n frameId: null,\n iconId: null,\n alt: entry?.words ?? '',\n aspect: entry && entry.aspect > 0 ? entry.aspect : 1,\n sectionIndex: entry?.role === 'hero' ? 0 : 1,\n role: entry?.role ?? 'gallery',\n }\n}\n\n/**\n * The page with each starter its plan names given its photo, re-read on the\n * stored page: an image that no longer holds a starter is left as it is.\n */\nexport function aiSitePageWithPhotos(\n nodes: NodesMap,\n plan: ReadonlyArray<{ slot: AiLayoutPictureSlot; photo: AiLayoutPicturePhoto }>,\n): NodesMap | null {\n const map = nodes as unknown as Record<string, { props?: Record<string, unknown> }>\n const live = plan.filter(({ slot }) => aiSiteIsStarterSrc(map[slot.imageId]?.props?.['src']))\n if (!live.length) return null\n return aiLayoutPlacePictures(\n nodes,\n live.map(({ slot }) => slot),\n // A photo that brings no words of its own takes the slot's, never the starter's (AGL-3831).\n live.map(({ slot, photo }) => (photo.alt?.trim() || !slot.alt ? photo : { ...photo, alt: slot.alt })),\n )\n}\n\n/** Runs the late photo pass (see the module note). Never throws. */\nexport async function aiSiteLatePhotos(\n input: AiSiteLatePhotosInput,\n deps: AiSiteLatePhotosDeps = {},\n): Promise<AiSiteLatePhotosResult> {\n const { job, signal } = input\n const now = deps.now ?? Date.now\n const sleep = deps.sleep ?? sleepFor\n const readNodes = deps.readNodes ?? readAiDraftNodes\n const updateNodes = deps.updateNodes ?? updateAiDraftNodes\n const writerFor = deps.writerFor ?? pluginResourceDraftWriter\n const hostId = job.hostId ?? ''\n const built = new Set(input.pageIds)\n const pages = input.photos.pages.filter((page) => built.has(page.screen) && page.slots.length)\n const lists = input.photos.lists\n const counts = { retried: 0, copied: 0, filled: 0, left: 0 }\n const done = (): AiSiteLatePhotosResult => ({ photos: null, ...counts })\n if (!hostId || (!pages.length && !lists.length)) return done()\n const provider = (deps.provider ?? stockPhotoProvider)()\n const ingest = (deps.ingest ?? pluginMediaIngest)()\n try {\n // ── 1. The refused picks, asked for again once the burst is over ──\n const retried = new Map<string, AiLayoutPicturePhoto>()\n const asked: Array<{ key: string; picks: AiStockRefusedPicks; slot: AiLayoutPictureSlot }> = [\n // The pages first, each one's hero first: what a visitor sees first.\n ...pages.flatMap((page) =>\n [...page.slots]\n .sort((a, b) => Number(b.role === 'hero') - Number(a.role === 'hero'))\n .flatMap((slot) => (slot.refused ? [{ key: `${page.screen}:${slot.image}`, picks: slot.refused, slot: slotOf(slot.image, slot) }] : [])),\n ),\n ...lists.flatMap((list) =>\n list.records.flatMap((record, index) =>\n record.refused && aiSiteIsStarterSrc(record.value)\n ? [\n {\n key: `${list.dataset}:${index}`,\n picks: record.refused,\n slot: {\n ...slotOf(`record${index}`, { words: record.name, role: list.people ? 'about' : 'gallery', aspect: list.people ? 4 / 5 : 4 / 3 }),\n // A record's name is a search's words, never what its photo shows (AGL-3856).\n standIn: true,\n },\n },\n ]\n : [],\n ),\n ),\n ]\n if (asked.length && provider && ingest) {\n const last = aiSitePhotosLastRefusalMs({ pages, lists })\n const wait = last === null ? 0 : Math.min(AI_SITE_LATE_PHOTOS_WAIT_MS, Math.max(0, last + AI_SITE_LATE_PHOTOS_WAIT_MS - now()))\n if (wait > 0) await sleep(wait, signal)\n // The pass's own time ran out while it waited: the next pass picks it up.\n if (signal?.aborted) return { photos: input.photos, ...counts }\n const timeout = AbortSignal.timeout(AI_SITE_LATE_PHOTOS_COPY_MS)\n const copying = signal ? AbortSignal.any([signal, timeout]) : timeout\n const words = aiStockPhotoWordsOf(job)\n const proper = aiStockProperWords(aiSiteWords(job.inputs).about)\n /**\n * Whether a pick not in the site's library yet is still downloaded:\n * not once the library refused to store one, nor once two downloads\n * in a row were refused, which says the burst is not over. The picks\n * a later page copied are still looked up in the library.\n */\n let downloading = true\n let refusedInARow = 0\n for (const entry of asked) {\n if (copying.aborted) break\n counts.retried += 1\n const found = await provider.search(entry.picks.request, { signal: copying }).catch(() => null)\n for (const sourceKey of entry.picks.keys) {\n if (copying.aborted) break\n const photo = found?.photos.find((hit) => stockPhotoSourceKey(hit) === sourceKey)\n if (!photo) continue\n const alt = aiStockPhotoAlt(photo, entry.slot, { ...(words.language ? { language: words.language } : {}), proper }) ?? entry.slot.alt\n const kept = await ingest.findStockPhoto({ hostId, sourceKey }).catch(() => null)\n if (kept) {\n retried.set(entry.key, { src: kept.src, width: kept.width ?? photo.width, height: kept.height ?? photo.height, alt })\n break\n }\n if (!downloading) continue\n const bytes = await provider.download(photo, { maxBytes: AI_LAYOUT_STOCK_MAX_BYTES, signal: copying }).catch(() => null)\n if (copying.aborted) break\n if (!bytes) {\n refusedInARow += 1\n if (refusedInARow >= AI_SITE_LATE_PHOTOS_REFUSALS_IN_A_ROW) downloading = false\n continue\n }\n refusedInARow = 0\n const stored = await ingest\n .ingest(aiStockIngestRequest(provider, { hostId, uid: job.createdBy, photo, bytes, alt, query: entry.picks.request.query }))\n .catch(() => null)\n if (stored?.ok) {\n retried.set(entry.key, { src: stored.src, width: stored.width ?? photo.width, height: stored.height ?? photo.height, alt })\n counts.copied += 1\n break\n }\n // A refusal of this photo's own bytes tries the next pick; any other holds for the pass (AGL-3923).\n if (!stored || !AI_STOCK_PHOTO_OWN_REFUSALS.has(stored.status)) downloading = false\n }\n }\n }\n\n // The pass's own time ran out while it copied: the next pass finds what it copied in the library.\n if (signal?.aborted) return { photos: input.photos, ...counts }\n\n // ── 2. The job's own photos, for every picture still on a starter ──\n const read = new Map<string, NodesMap | null>()\n for (const id of built) {\n const stored = await readNodes(input.firestore, { kind: 'screen', hostId, id }).catch(() => null)\n read.set(id, stored?.nodes ?? null)\n }\n const seen = new Set<string>()\n const pool = [\n ...[...read.values()].flatMap((nodes) => aiStockPlacedPhotos(nodes)),\n ...lists.flatMap((list) => list.records.flatMap((record) => (record.photo ? [record.photo] : []))),\n ...aiSiteDatasetPlacedPhotoDetails(job.outputs ?? []),\n ...retried.values(),\n ].filter((photo) => photo.src.startsWith('media:') && !seen.has(photo.src) && Boolean(seen.add(photo.src)))\n const origin = aiOriginJobId(job)\n\n for (const page of pages) {\n const nodes = read.get(page.screen)\n if (!nodes) continue\n const images = aiSitePageImages(nodes)\n const entries = new Map(page.slots.map((slot) => [slot.image, slot]))\n const slots = images.map((image) => slotOf(image.imageId, entries.get(image.imageId) ?? null))\n const placed: Array<AiLayoutPicturePhoto | null> = images.map((image) =>\n aiSiteIsStarterSrc(image.src) ? null : { src: image.src, width: image.width, height: image.height, alt: image.alt },\n )\n const need = images.map((image) => entries.has(image.imageId) && aiSiteIsStarterSrc(image.src))\n const photos: Array<AiLayoutPicturePhoto | null> = images.map(() => null)\n // (a) A picture's own pick first, where the page does not show it yet;\n // else it is one of the job's photos like any other.\n images.forEach((image, index) => {\n const own = need[index] ? retried.get(`${page.screen}:${image.imageId}`) : undefined\n if (!own || placed.some((photo) => photo?.src === own.src)) return\n photos[index] = own\n placed[index] = own\n need[index] = false\n })\n // (b) Then the job's photos, by the matcher the page's own pass used: one\n // the page does not show first; (c) a repeat only where nothing else is\n // left, since the other choice is a starter that shows another business.\n if (pool.length) {\n aiLayoutJobPhotoPicks(slots, need, pool, placed, `${origin}:${page.screen}:late`, { repeats: 'last' }).forEach((pick, index) => {\n if (pick && need[index]) photos[index] = pick\n })\n }\n const starters = images.filter((image) => entries.has(image.imageId) && aiSiteIsStarterSrc(image.src)).length\n const plan = images.flatMap((image, index) => {\n const photo = photos[index]\n return photo ? [{ slot: slots[index] as AiLayoutPictureSlot, photo }] : []\n })\n const update = plan.length\n ? await updateNodes(input.firestore, {\n kind: 'screen',\n hostId,\n id: page.screen,\n actor: aiJobContentActor(job),\n now: input.now,\n update: (current) => aiSitePageWithPhotos(current, plan),\n })\n : null\n const filled = update?.ok ? plan.length : 0\n counts.filled += filled\n counts.left += Math.max(0, starters - filled)\n }\n\n for (const list of lists) {\n const filled = aiSiteListPhotos(list, retried, pool, `${origin}:${list.dataset}:late`)\n const records = filled.flatMap((photo, index) => {\n const record = list.records[index]\n const value = photo ? aiSiteProductPhotoSrc(photo.src, hostId) : null\n if (!record || !photo || !value || !aiSiteIsStarterSrc(record.value)) return []\n return [\n {\n order: index,\n // The starter's words go with it: a photo that brings none leaves the description empty (AGL-3856).\n values: { [list.imageField]: value, ...(list.altField ? { [list.altField]: photo.alt?.trim() ?? '' } : {}) },\n where: { [list.imageField]: record.value },\n },\n ]\n })\n const starters = list.records.filter((record) => aiSiteIsStarterSrc(record.value)).length\n if (!records.length) {\n counts.left += starters\n continue\n }\n const keeper = writerFor(AI_DATASET_DRAFT_RESOURCE)\n if (!keeper?.writer.reviseRecords) {\n console.warn('ai site late photos: the dataset writer cannot change records here', { jobId: job.$id, dataset: list.dataset })\n counts.left += starters\n continue\n }\n const revised = await keeper.writer.reviseRecords({\n orgId: job.orgId,\n hostId,\n uid: job.createdBy,\n org: input.org,\n now: input.now,\n id: list.dataset,\n records,\n })\n const changed = revised.ok ? revised.changed : 0\n if (revised.ok === false) {\n console.warn('ai site late photos: the dataset writer refused the covers', { jobId: job.$id, dataset: list.dataset, status: revised.status })\n }\n counts.filled += changed\n counts.left += Math.max(0, starters - changed)\n }\n console.info('ai site late photos', { jobId: job.$id, hostId, ...counts })\n return done()\n } catch (error) {\n // The site is built either way; its pictures keep what they hold.\n if (signal?.aborted) return { photos: input.photos, ...counts }\n console.error('ai site late photos failed; the site keeps its pictures as they are', { jobId: job.$id, error: String(error) })\n return done()\n }\n}\n\n/**\n * A list's records' photos once the late pass is done (AGL-3988): each\n * record's own refused pick where it was copied, then, for a list of things,\n * one of the photos it or the job shows (`aiSiteDatasetRecordsFromOwn`). A\n * team's records take only their own picks: no photo of the job's is of\n * one of the business's people. Pure.\n */\nexport function aiSiteListPhotos(\n list: AiSiteStarterList,\n retried: ReadonlyMap<string, AiLayoutPicturePhoto>,\n pool: readonly AiLayoutPicturePhoto[],\n seed: string,\n): Array<AiLayoutPicturePhoto | null> {\n const current = list.records.map((record, index): AiLayoutPicturePhoto | null =>\n aiSiteIsStarterSrc(record.value) ? (retried.get(`${list.dataset}:${index}`) ?? null) : (record.photo ?? null),\n )\n if (list.people) return current\n return aiSiteDatasetRecordsFromOwn(\n list.records.map((record) => ({ name: record.name, category: record.category ?? null, ...(record.itsOwn ? { itsOwn: true } : {}) })),\n current,\n seed,\n pool,\n // A starter is the other choice: a record every photo sits beside takes one anyway.\n { besideLast: true },\n )\n}\n"],"names":["CANVAS_ROOT_ELEMENT_ID","pluginMediaIngest","pluginResourceDraftWriter","stockPhotoProvider","stockPhotoSourceKey","aiLayoutJobPhotoPicks","aiLayoutPlacePictures","aiSiteWords","aiSiteIsStarterSrc","aiSitePhotosLastRefusalMs","AI_DATASET_DRAFT_RESOURCE","aiOriginJobId","aiJobContentActor","readAiDraftNodes","updateAiDraftNodes","aiSiteProductPhotoSrc","aiSiteDatasetPlacedPhotoDetails","aiSiteDatasetRecordsFromOwn","AI_LAYOUT_STOCK_MAX_BYTES","AI_STOCK_PHOTO_OWN_REFUSALS","aiStockIngestRequest","aiStockPhotoAlt","aiStockPhotoWordsOf","aiStockPlacedPhotos","aiStockProperWords","AI_SITE_LATE_PHOTOS_WAIT_MS","AI_SITE_LATE_PHOTOS_COPY_MS","AI_SITE_LATE_PHOTOS_REFUSALS_IN_A_ROW","AI_SITE_LATE_PHOTOS_WRITES_MS","AI_SITE_LATE_PHOTOS_MINIMUM_MS","sleepFor","ms","signal","Promise","resolve","aborted","timer","setTimeout","done","clearTimeout","removeEventListener","addEventListener","once","aiSitePageImages","nodes","rootId","map","images","seen","Set","visit","id","node","has","add","componentId","src","props","trim","includes","push","imageId","width","Number","height","alt","child","slotOf","entry","frameId","iconId","words","aspect","sectionIndex","role","aiSitePageWithPhotos","plan","live","filter","slot","length","photo","aiSiteLatePhotos","input","deps","job","now","Date","sleep","readNodes","updateNodes","writerFor","hostId","built","pageIds","pages","photos","page","screen","slots","lists","counts","retried","copied","filled","left","provider","ingest","Map","asked","flatMap","sort","a","b","refused","key","image","picks","list","records","record","index","value","dataset","name","people","standIn","last","wait","Math","min","max","timeout","AbortSignal","copying","any","proper","inputs","about","downloading","refusedInARow","found","search","request","catch","sourceKey","keys","find","hit","language","kept","findStockPhoto","set","bytes","download","maxBytes","stored","uid","createdBy","query","ok","status","read","firestore","kind","pool","values","outputs","startsWith","Boolean","origin","get","entries","placed","need","forEach","own","undefined","some","repeats","pick","starters","update","actor","current","aiSiteListPhotos","order","imageField","altField","where","keeper","writer","reviseRecords","console","warn","jobId","$id","revised","orgId","org","changed","info","error","String","seed","category","itsOwn","besideLast"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,sBAAsB,QAAQ,2CAA0C;AACjF,SAASC,iBAAiB,QAAgC,kDAAiD;AAC3G,SAASC,yBAAyB,QAAQ,qDAAoD;AAC9F,SACEC,kBAAkB,EAClBC,mBAAmB,QAEd,mDAAkD;AAGzD,SACEC,qBAAqB,EACrBC,qBAAqB,QAGhB,2CAAuC;AAE9C,SAASC,WAAW,QAAQ,0BAAsB;AAClD,SACEC,kBAAkB,EAClBC,yBAAyB,QAIpB,6BAAyB;AAChC,SAASC,yBAAyB,QAAQ,6BAAyB;AACnE,SAASC,aAAa,QAAQ,wBAAoB;AAClD,SAASC,iBAAiB,EAAEC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B;eAAxFhH,mBAAmBgH,OAAOE,KAAK,KAAKpB,eAAAA,QAAQqE,GAAG,CAAC,GAAGrD,KAAKK,OAAO,CAAC,CAAC,EAAEF,OAAO,aAAtCnB,eAA2C,QAASkB,gBAAAA,OAAOvC,KAAK,YAAZuC,gBAAgB;;IAE1G,IAAIF,KAAKO,MAAM,EAAE,OAAO2D;IACxB,OAAOvK,4BACLqG,KAAKC,OAAO,CAACzE,GAAG,CAAC,CAAC0E;YAA2CA;eAA/B;YAAEI,MAAMJ,OAAOI,IAAI;YAAEiF,QAAQ,GAAErF,mBAAAA,OAAOqF,QAAQ,YAAfrF,mBAAmB;WAAUA,OAAOsF,MAAM,GAAG;YAAEA,QAAQ;QAAK,IAAI,CAAC;QAC9HtB,SACAoB,MACAvC,MACA,oFAAoF;IACpF;QAAE0C,YAAY;IAAK;AAEvB"}
|
|
@@ -180,7 +180,7 @@ export declare function aiLayoutWithBlogEntry(nodes: NodesMap, input: {
|
|
|
180
180
|
* whether the entry went live; never throws for a layout it cannot change.
|
|
181
181
|
*/
|
|
182
182
|
export declare function aiRestoreGuidedBlogEntry(firestore: Firestore, input: {
|
|
183
|
-
job: Pick<AiJob, '$id' | 'hostId'>;
|
|
183
|
+
job: Pick<AiJob, '$id' | 'hostId' | 'createdBy'>;
|
|
184
184
|
/** The start's published pages: the layout they share is the one changed. */
|
|
185
185
|
pageIds: readonly string[];
|
|
186
186
|
/** The published home page, which the blog's entry follows. */
|
|
@@ -217,7 +217,7 @@ export declare function aiMergeSitePublish(previous: AiJobSitePublish, retried:
|
|
|
217
217
|
* draft, for the same reason, and is logged.
|
|
218
218
|
*/
|
|
219
219
|
export declare function aiPublishGuidedSite(firestore: Firestore, input: {
|
|
220
|
-
job: Pick<AiJob, '$id' | 'orgId' | 'hostId'> & Partial<Pick<AiJob, 'inputs'>>;
|
|
220
|
+
job: Pick<AiJob, '$id' | 'orgId' | 'hostId' | 'createdBy'> & Partial<Pick<AiJob, 'inputs'>>;
|
|
221
221
|
outputs: readonly AiJobOutput[];
|
|
222
222
|
now: Date;
|
|
223
223
|
/** The start owed its blog's posts and wrote none (AGL-3660): its links to the blog come out. */
|
|
@@ -15,6 +15,7 @@ import { _ as _extends } from "@swc/helpers/_/_extends";
|
|
|
15
15
|
* See the License for the specific language governing permissions and
|
|
16
16
|
* limitations under the License.
|
|
17
17
|
*/ import { isFirstPublishedRoute } from "@aglyn/aglyn/app-utils/analytics-events";
|
|
18
|
+
import { contentEditStamp, parentPublishStamp, versionPublishStamp } from "@aglyn/aglyn/app-utils/content-write-stamp";
|
|
18
19
|
import { createResourceUid } from "@aglyn/aglyn/app-utils/create-resource-uid";
|
|
19
20
|
import { hostPublicOrigin } from "@aglyn/aglyn/app-utils/host-naming";
|
|
20
21
|
import { blockingRouteOwner, normalizeScreenSlug, SCREEN_ROOT_PATH, screenRoutePathToUrl } from "@aglyn/aglyn/app-utils/screen-route";
|
|
@@ -31,7 +32,7 @@ import { aiSiteSeoProposalForInputs } from "../model/ai-site-start-seo.js";
|
|
|
31
32
|
import { aiLayoutWithStoreLinks } from "../model/ai-layout-store-links.js";
|
|
32
33
|
import { aiLayoutWithMenuChanges, aiNoMenuChanges } from "../model/ai-layout-menus.js";
|
|
33
34
|
import { AI_STORE_LINKS_SOURCE_FIELD as STORE_LINKS_SOURCE_FIELD } from "./ai-job-store-links-layout.js";
|
|
34
|
-
import { readAiDraftNodes, updateAiDraftNodes } from "./ai-job-drafts.js";
|
|
35
|
+
import { aiJobContentActor, readAiDraftNodes, updateAiDraftNodes } from "./ai-job-drafts.js";
|
|
35
36
|
import { aiSiteIsStarterSrc } from "../model/ai-site-photos.js";
|
|
36
37
|
/**
|
|
37
38
|
* Whether a build puts its pages live (AGL-3616): only where its request
|
|
@@ -344,6 +345,7 @@ function navEntriesOf(outputs) {
|
|
|
344
345
|
const dropCache = (_deps_dropCache = deps.dropCache) != null ? _deps_dropCache : dropPluginSiteCache;
|
|
345
346
|
const hostId = (_input_job_hostId = input.job.hostId) != null ? _input_job_hostId : '';
|
|
346
347
|
if (!hostId || !input.pageIds.length) return false;
|
|
348
|
+
const actor = aiJobContentActor(input.job);
|
|
347
349
|
const layoutId = await aiPagesLayoutId(firestore, hostId, input.pageIds);
|
|
348
350
|
if (!layoutId) return false;
|
|
349
351
|
const write = await aiLayoutVersionWrite(firestore, {
|
|
@@ -358,16 +360,14 @@ function navEntriesOf(outputs) {
|
|
|
358
360
|
},
|
|
359
361
|
storeLinks: null,
|
|
360
362
|
jobId: input.job.$id,
|
|
363
|
+
actor,
|
|
361
364
|
now: input.now,
|
|
362
365
|
displayName: 'Navigation for the blog'
|
|
363
366
|
});
|
|
364
367
|
if (!(write == null ? void 0 : write.version)) return false;
|
|
365
368
|
const batch = firestore.batch();
|
|
366
369
|
batch.create(write.versionRef, write.version);
|
|
367
|
-
batch.set(write.layoutRef, {
|
|
368
|
-
versionId: write.versionRef.id,
|
|
369
|
-
updatedAt: input.now
|
|
370
|
-
}, {
|
|
370
|
+
batch.set(write.layoutRef, layoutPointerWrite(write, actor, input.now), {
|
|
371
371
|
merge: true
|
|
372
372
|
});
|
|
373
373
|
// A layout change reaches every page, so the announce asks for the whole site.
|
|
@@ -508,6 +508,7 @@ function navEntriesOf(outputs) {
|
|
|
508
508
|
const dropCache = (_deps_dropCache = deps.dropCache) != null ? _deps_dropCache : dropPluginSiteCache;
|
|
509
509
|
const { job, now } = input;
|
|
510
510
|
const hostId = (_job_hostId = job.hostId) != null ? _job_hostId : '';
|
|
511
|
+
const actor = aiJobContentActor(job);
|
|
511
512
|
const pages = input.outputs.filter((output, index, all)=>{
|
|
512
513
|
var _output_hostId;
|
|
513
514
|
return output.resource === 'screen' && ((_output_hostId = output.hostId) != null ? _output_hostId : hostId) === hostId && all.findIndex((other)=>other.resource === 'screen' && other.id === output.id) === index;
|
|
@@ -594,6 +595,7 @@ function navEntriesOf(outputs) {
|
|
|
594
595
|
kind: 'screen',
|
|
595
596
|
hostId,
|
|
596
597
|
id: page.id,
|
|
598
|
+
actor,
|
|
597
599
|
now,
|
|
598
600
|
update: (nodes)=>aiPageWithoutLinksTo(nodes, notLive, {
|
|
599
601
|
keepWords: input.keepLinkWords === true
|
|
@@ -627,6 +629,7 @@ function navEntriesOf(outputs) {
|
|
|
627
629
|
retiredHomeId: releases,
|
|
628
630
|
homeId: (_ref = home == null ? void 0 : home.id) != null ? _ref : null,
|
|
629
631
|
jobId: job.$id,
|
|
632
|
+
actor,
|
|
630
633
|
now,
|
|
631
634
|
storeLinks: (_input_storeLinks = input.storeLinks) != null ? _input_storeLinks : null
|
|
632
635
|
}).catch((error)=>{
|
|
@@ -645,6 +648,7 @@ function navEntriesOf(outputs) {
|
|
|
645
648
|
transform: ()=>null,
|
|
646
649
|
storeLinks,
|
|
647
650
|
jobId: job.$id,
|
|
651
|
+
actor,
|
|
648
652
|
now
|
|
649
653
|
}).catch((error)=>{
|
|
650
654
|
console.error('ai site publish: store links not applied', {
|
|
@@ -678,7 +682,7 @@ function navEntriesOf(outputs) {
|
|
|
678
682
|
publishedAt: FieldValue.delete()
|
|
679
683
|
}, retire ? {
|
|
680
684
|
deletedAt: now
|
|
681
|
-
} : {}), {
|
|
685
|
+
} : {}, contentEditStamp(actor, now)), {
|
|
682
686
|
merge: true
|
|
683
687
|
});
|
|
684
688
|
} else if (placeholder && entries[placeholder]) {
|
|
@@ -736,16 +740,14 @@ function navEntriesOf(outputs) {
|
|
|
736
740
|
publishedAt: now
|
|
737
741
|
}, page.order !== undefined ? {
|
|
738
742
|
order: page.order
|
|
739
|
-
} : {}), {
|
|
743
|
+
} : {}, contentEditStamp(actor, now), parentPublishStamp(actor, now)), {
|
|
740
744
|
merge: true
|
|
741
745
|
});
|
|
742
746
|
}
|
|
743
747
|
for (const write of layoutWrites){
|
|
744
748
|
if (write.version) batch.create(write.versionRef, write.version);
|
|
745
|
-
batch.
|
|
746
|
-
|
|
747
|
-
updatedAt: now
|
|
748
|
-
}, {
|
|
749
|
+
else batch.update(write.versionRef, versionPublishStamp(actor, now));
|
|
750
|
+
batch.set(write.layoutRef, layoutPointerWrite(write, actor, now), {
|
|
749
751
|
merge: true
|
|
750
752
|
});
|
|
751
753
|
}
|
|
@@ -819,6 +821,11 @@ function navEntriesOf(outputs) {
|
|
|
819
821
|
]);
|
|
820
822
|
return aiSiteSharePhoto(home != null ? home : null, others);
|
|
821
823
|
}
|
|
824
|
+
/** The layout's pointer moved onto the version going live, with who published it. */ function layoutPointerWrite(write, actor, now) {
|
|
825
|
+
return _extends({
|
|
826
|
+
versionId: write.versionRef.id
|
|
827
|
+
}, contentEditStamp(actor, now), parentPublishStamp(actor, now));
|
|
828
|
+
}
|
|
822
829
|
/**
|
|
823
830
|
* The new live version of the layout the published pages render inside, with
|
|
824
831
|
* their navigation entries and the home link moved off a retired starter;
|
|
@@ -834,6 +841,7 @@ function navEntriesOf(outputs) {
|
|
|
834
841
|
transform: (nodes)=>aiLayoutWithNavigation(nodes, input),
|
|
835
842
|
storeLinks: (_input_storeLinks = input.storeLinks) != null ? _input_storeLinks : null,
|
|
836
843
|
jobId: input.jobId,
|
|
844
|
+
actor: input.actor,
|
|
837
845
|
now: input.now
|
|
838
846
|
});
|
|
839
847
|
}
|
|
@@ -900,15 +908,15 @@ function navEntriesOf(outputs) {
|
|
|
900
908
|
return {
|
|
901
909
|
layoutRef,
|
|
902
910
|
versionRef,
|
|
903
|
-
version: {
|
|
911
|
+
version: _extends({
|
|
904
912
|
layoutId,
|
|
905
913
|
hostId: input.hostId,
|
|
906
914
|
displayName: (_input_displayName = input.displayName) != null ? _input_displayName : 'Navigation for the new pages',
|
|
907
915
|
nodes: Buffer.from(packed),
|
|
908
|
-
createdAt: input.now
|
|
909
|
-
|
|
916
|
+
createdAt: input.now
|
|
917
|
+
}, contentEditStamp(input.actor, input.now), versionPublishStamp(input.actor, input.now), {
|
|
910
918
|
aiJobId: input.jobId
|
|
911
|
-
}
|
|
919
|
+
})
|
|
912
920
|
};
|
|
913
921
|
}
|
|
914
922
|
|