@aglyn/plugins-ai 1.20.2 → 1.20.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +17 -17
- package/src/lib/jobs/ai-image-reads.d.ts +22 -5
- package/src/lib/jobs/ai-image-reads.js +1 -0
- package/src/lib/jobs/ai-image-reads.js.map +1 -1
- package/src/lib/jobs/ai-job-import-step.d.ts +3 -0
- package/src/lib/jobs/ai-job-import-step.js +14 -2
- package/src/lib/jobs/ai-job-import-step.js.map +1 -1
- package/src/lib/jobs/ai-site-import-document.js +2 -0
- package/src/lib/jobs/ai-site-import-document.js.map +1 -1
- package/src/lib/jobs/ai-site-import-graphics.d.ts +47 -0
- package/src/lib/jobs/ai-site-import-graphics.js +151 -0
- package/src/lib/jobs/ai-site-import-graphics.js.map +1 -0
- package/src/lib/jobs/ai-site-import-improve.d.ts +2 -1
- package/src/lib/jobs/ai-site-import-improve.js +7 -11
- package/src/lib/jobs/ai-site-import-improve.js.map +1 -1
- package/src/lib/jobs/ai-site-import-pictures.js +1 -1
- package/src/lib/jobs/ai-site-import-pictures.js.map +1 -1
- package/src/lib/model/ai-site-import-fidelity.d.ts +1 -0
- package/src/lib/model/ai-site-import-fidelity.js +4 -2
- package/src/lib/model/ai-site-import-fidelity.js.map +1 -1
- package/src/lib/model/ai-site-import-graphic.d.ts +49 -0
- package/src/lib/model/ai-site-import-graphic.js +124 -0
- package/src/lib/model/ai-site-import-graphic.js.map +1 -0
- package/src/lib/model/ai-site-import-ledger.d.ts +8 -1
- package/src/lib/model/ai-site-import-ledger.js +7 -7
- package/src/lib/model/ai-site-import-ledger.js.map +1 -1
- package/src/lib/model/ai-site-import-marks.d.ts +24 -6
- package/src/lib/model/ai-site-import-marks.js +23 -6
- package/src/lib/model/ai-site-import-marks.js.map +1 -1
- package/src/lib/model/ai-site-import.d.ts +7 -0
- package/src/lib/model/ai-site-import.js.map +1 -1
- package/src/lib/server/ai-image-reads-route.js +30 -2
- package/src/lib/server/ai-image-reads-route.js.map +1 -1
|
@@ -74,7 +74,7 @@ export function aiSiteImportPictureTally() {
|
|
|
74
74
|
var _input_cap;
|
|
75
75
|
const { next, make, tally } = input;
|
|
76
76
|
// A photo the library holds no size for cannot be framed, and a brand's mark is no photo (AGL-4152): a slot is a
|
|
77
|
-
// photo's place, and a client's logo filled a page's cover.
|
|
77
|
+
// photo's place, and a client's logo filled a page's cover. A mark by its name, or by its pixels (`graphic`).
|
|
78
78
|
const photos = input.photos.filter((photo)=>photo.width && photo.height && !aiSiteImportIsBrandMark(photo));
|
|
79
79
|
if (!photos.length && !next && !make) return null;
|
|
80
80
|
const froms = new Map(photos.map((photo)=>{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/jobs/ai-site-import-pictures.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/*==========================================\n * IMPROVE IT, GENERATIVE: A REDESIGNED PAGE'S PICTURES (AGL-4152).\n *\n * A redesign may ask for a picture where its own do not fit: a slot, which\n * `aiResolveLayoutPictures` fills or drops. This is the order it fills from,\n * first to last:\n *\n * 1. the page's own photos no `keep` placed;\n * 2. the source photos the site's earlier pages left off;\n * 3. what the site's own photo links hold, then the stock library\n * (`aiLayoutSitePhotoSource`): no credits, copied into the library, its\n * photographer kept, its brand-tag refusal held;\n * 4. only where the owner switched them on, and it is quoted, a generated\n * picture: a hero or a section's lead, never a person or a product, at most\n * `AI_SITE_IMPORT_GENERATED_PICTURES_PER_PAGE` a page.\n *\n * A slot nothing fills is dropped, and the row around it redraws without a gap\n * (`aiLayoutDropEmptyPictures`). The tally is what the page's row says.\n *=========================================*/\n\nimport type { PluginMediaIngest } from '@aglyn/aglyn/plugin-manager/plugin-media-ingest'\nimport { aiLayoutPictureBandCells, type AiLayoutPicturePhoto, type AiLayoutPictureSlot, type AiLayoutPictureSource } from '../layout-language/ai-layout-pictures'\nimport { AI_SITE_IMPORT_GENERATED_PICTURES_PER_PAGE, type AiSiteImportPagePictures, type AiSiteImportPhoto } from '../model/ai-site-import'\nimport { aiMediaCreditsPerPicture } from '../model/ai-media-credits'\nimport { aiSiteImportIsBrandMark } from '../model/ai-site-import-marks'\nimport { estimateAiBilledUsd } from '../providers/catalog'\nimport { AiImageSafetyRefusal, type AiImageAspectRatio, type AiImageProvider } from '../providers/image-contract'\nimport { aiImageAltText, aiImageFileName } from '../server/ai-media-image'\nimport { aiMediaRasterPrompt } from '../server/ai-media-raster-prompt'\nimport { recordAssistCost } from '../usage/assist-usage'\nimport { aiAssignOwnerPhotos } from './ai-layout-owner-photos'\n\ntype NodesMap = Parameters<typeof aiLayoutPictureBandCells>[0]\n\n/** How long one generated picture is waited on: a picture is decoration, and a page never fails over one. */\nexport const AI_SITE_IMPORT_GENERATED_PICTURE_MS = 40_000\n\n/** What a slot's picture came from, as the page's row tells it. */\nexport interface AiSiteImportPictureTally {\n source: number\n stock: number\n generated: number\n /** What the generated pictures cost at the billed rates. */\n generatedUsd: number\n /** The addresses of the source's photos a slot took. */\n placed: string[]\n}\n\nexport function aiSiteImportPictureTally(): AiSiteImportPictureTally {\n return { source: 0, stock: 0, generated: 0, generatedUsd: 0, placed: [] }\n}\n\n/** A generated picture for a slot, stored and metered; `null` where it could not be made or kept. */\nexport type AiSiteImportPictureMaker = (slot: AiLayoutPictureSlot, tally: AiSiteImportPictureTally) => Promise<AiLayoutPicturePhoto | null>\n\n/** The words that say a picture shows a person: a generated one would show someone who does not exist as if they did. */\nconst SHOWS_PEOPLE = /\\b(?:team|staff|crew|owner|owners|founder|founders|person|people|portrait|headshot|family|families|customer|customers|client|clients|patient|patients|doctor|dentist|stylist|therapist|attorney|lawyer|accountant)\\b/i\n\n/**\n * Which slots may take a generated picture (AGL-4152): the page's hero, or the\n * first picture of a section that is no cell of a band, and none that shows a\n * person, a product or a record's own thing.\n */\nexport function aiSiteImportGeneratedSlots(nodes: NodesMap, slots: readonly AiLayoutPictureSlot[]): boolean[] {\n const cells = aiLayoutPictureBandCells(nodes, slots)\n const seen = new Set<number>()\n return slots.map((slot, index) => {\n const lead = !seen.has(slot.sectionIndex)\n seen.add(slot.sectionIndex)\n return lead && !cells[index] && !slot.product && !slot.people && !slot.record && !SHOWS_PEOPLE.test(slot.alt)\n })\n}\n\n/**\n * The source a redesigned page's slots fill from, in the order above. `next`\n * answers the slots the source's own photos leave and tallies its own stock\n * photos; a slot it leaves empty takes a generated picture where one is allowed.\n */\nexport function aiSiteImportPictureSource(input: {\n photos: readonly AiSiteImportPhoto[]\n next: AiLayoutPictureSource | null\n make?: AiSiteImportPictureMaker | null\n nodes: NodesMap\n tally: AiSiteImportPictureTally\n /** The most generated pictures this page may take. */\n cap?: number\n}): AiLayoutPictureSource | null {\n const { next, make, tally } = input\n // A photo the library holds no size for cannot be framed, and a brand's mark is no photo (AGL-4152): a slot is a\n // photo's place, and a client's logo filled a page's cover.\n const photos = input.photos.filter((photo) => photo.width && photo.height && !aiSiteImportIsBrandMark(photo))\n if (!photos.length && !next && !make) return null\n const froms = new Map(photos.map((photo) => [photo.src, photo.from ?? '']))\n const cap = input.cap ?? AI_SITE_IMPORT_GENERATED_PICTURES_PER_PAGE\n return async (slots, report) => {\n const own = aiAssignOwnerPhotos(slots, photos)\n own.forEach((photo) => {\n if (!photo) return\n tally.source += 1\n const from = froms.get(photo.src)\n if (from) tally.placed.push(from)\n })\n const open = slots.filter((_slot, index) => !own[index])\n const found = next && open.length ? await next(open, report) : []\n let at = 0\n const answers = own.map((photo) => photo ?? found[at++] ?? null)\n if (!make) return answers\n const allowed = aiSiteImportGeneratedSlots(input.nodes, slots)\n let left = Math.max(0, cap)\n const out: Array<AiLayoutPicturePhoto | null> = [...answers]\n // One at a time, so the cap holds whatever each comes to: the hero first, the biggest seen first.\n const order = slots.map((slot, index) => ({ slot, index })).sort((a, b) => Number(b.slot.role === 'hero') - Number(a.slot.role === 'hero') || a.index - b.index)\n for (const { slot, index } of order) {\n if (left <= 0) break\n if (answers[index]?.src || !allowed[index]) continue\n const made = await make(slot, tally)\n if (made) {\n out[index] = made\n left -= 1\n }\n }\n return out\n }\n}\n\n/** The nearest shape the image models draw to a slot's frame. */\nexport function aiSiteImportPictureShape(aspect: number): AiImageAspectRatio {\n const shapes: ReadonlyArray<readonly [AiImageAspectRatio, number]> = [['16:9', 16 / 9], ['4:3', 4 / 3], ['1:1', 1], ['3:4', 3 / 4], ['9:16', 9 / 16]]\n const wanted = aspect > 0 && Number.isFinite(aspect) ? aspect : 4 / 3\n return [...shapes].sort((a, b) => Math.abs(a[1] - wanted) - Math.abs(b[1] - wanted))[0]?.[0] ?? '4:3'\n}\n\n/** What a generated picture is made through, and whether the workspace's meter has room for it. */\nexport interface AiSiteImportPictureMakerInput {\n provider: AiImageProvider | null\n ingest: PluginMediaIngest | null\n firestore: FirebaseFirestore.Firestore\n orgId: string\n hostId: string\n uid: string\n /** What the site is, which a picture's own words are read with. */\n about: string\n /** Whether the workspace's meter has room for a picture now. */\n roomFor?: (credits: number) => boolean\n record?: typeof recordAssistCost\n}\n\n/**\n * A generated picture through the Media door's own parts (AGL-4152): the image\n * provider at a paid plan's size, the fixed style wording, the media library's\n * ingest as an upload this member made, the same provenance on the asset, and the\n * same meter, charged only once it is stored. `null` where it cannot run here.\n */\nexport function aiSiteImportPictureMaker(input: AiSiteImportPictureMakerInput): AiSiteImportPictureMaker | null {\n const { provider, ingest } = input\n if (!provider?.configured() || !ingest) return null\n const size = '1K' as const\n return async (slot, tally) => {\n const model = provider.defaultModel()\n if (input.roomFor && !input.roomFor(aiMediaCreditsPerPicture('photo', model, size))) return null\n const words = `${slot.alt}. For a website about: ${input.about}`.replace(/\\s+/g, ' ').trim()\n const timeout = new Promise<null>((resolve) => setTimeout(() => resolve(null), AI_SITE_IMPORT_GENERATED_PICTURE_MS))\n try {\n const result = await Promise.race([\n provider.generate({ model, prompt: aiMediaRasterPrompt(words, 'natural'), aspectRatio: aiSiteImportPictureShape(slot.aspect), size, count: 1 }),\n timeout,\n ])\n const image = result?.images[0]\n if (!result || !image) return null\n const alt = aiImageAltText(slot.alt)\n const stored = await ingest.ingest({\n hostId: input.hostId,\n uid: input.uid,\n fileName: aiImageFileName(slot.alt, 0, image.mimeType),\n contentType: image.mimeType,\n bytes: Buffer.from(image.base64, 'base64'),\n alt,\n description: 'Created with AI from a description.',\n })\n if (!stored.ok) return null\n const usage = { ...result.usage, images: 1, imageSize: size }\n let signalId: string | null = null\n try {\n signalId = await (input.record ?? recordAssistCost)(input.firestore, input.orgId, {\n route: 'ai/jobs',\n hostId: input.hostId,\n model,\n tier: 'entitled',\n usage,\n docsPaths: [],\n stopReason: 'end_turn',\n free: null,\n uid: input.uid,\n kind: 'image',\n })\n } catch (error) {\n console.error('ai site import: a generated picture’s usage was not recorded', { orgId: input.orgId, error })\n }\n await input.firestore\n .collection('hosts')\n .doc(input.hostId)\n .collection('media')\n .doc(stored.mediaId)\n .update({ aiGenerated: { model, prompt: slot.alt, mode: 'photo', style: 'natural', aspectRatio: aiSiteImportPictureShape(slot.aspect), signalId, generatedBy: input.uid, createdAt: new Date() } })\n .catch((error: unknown) => console.error('ai site import: a generated picture’s record was not written', { mediaId: stored.mediaId, error }))\n tally.generated += 1\n tally.generatedUsd += estimateAiBilledUsd(usage, model)\n return { src: stored.src, width: stored.width ?? 1024, height: stored.height ?? 1024, alt }\n } catch (error) {\n if (!(error instanceof AiImageSafetyRefusal)) console.warn('ai site import: a generated picture failed; its slot is dropped', { error })\n return null\n }\n }\n}\n\n/** A page's pictures, as its row reads them once its slots are filled. */\nexport function aiSiteImportPagePicturesOf(pictures: AiSiteImportPagePictures, tally: AiSiteImportPictureTally): AiSiteImportPagePictures {\n const taken = new Set(tally.placed)\n return { source: pictures.source + tally.source, stock: tally.stock, generated: tally.generated, slots: 0, unplaced: pictures.unplaced.filter((url) => !taken.has(url)) }\n}\n"],"names":["aiLayoutPictureBandCells","AI_SITE_IMPORT_GENERATED_PICTURES_PER_PAGE","aiMediaCreditsPerPicture","aiSiteImportIsBrandMark","estimateAiBilledUsd","AiImageSafetyRefusal","aiImageAltText","aiImageFileName","aiMediaRasterPrompt","recordAssistCost","aiAssignOwnerPhotos","AI_SITE_IMPORT_GENERATED_PICTURE_MS","aiSiteImportPictureTally","source","stock","generated","generatedUsd","placed","SHOWS_PEOPLE","aiSiteImportGeneratedSlots","nodes","slots","cells","seen","Set","map","slot","index","lead","has","sectionIndex","add","product","people","record","test","alt","aiSiteImportPictureSource","input","next","make","tally","photos","filter","photo","width","height","length","froms","Map","src","from","cap","report","own","forEach","get","push","open","_slot","found","at","answers","allowed","left","Math","max","out","order","sort","a","b","Number","role","made","aiSiteImportPictureShape","aspect","shapes","wanted","isFinite","abs","aiSiteImportPictureMaker","provider","ingest","configured","size","model","defaultModel","roomFor","words","about","replace","trim","timeout","Promise","resolve","setTimeout","stored","result","race","generate","prompt","aspectRatio","count","image","images","hostId","uid","fileName","mimeType","contentType","bytes","Buffer","base64","description","ok","usage","imageSize","signalId","firestore","orgId","route","tier","docsPaths","stopReason","free","kind","error","console","collection","doc","mediaId","update","aiGenerated","mode","style","generatedBy","createdAt","Date","catch","warn","aiSiteImportPagePicturesOf","pictures","taken","unplaced","url"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED;;;;;;;;;;;;;;;;;;2CAkB2C;AAG3C,SAASA,wBAAwB,QAAyF,2CAAuC;AACjK,SAASC,0CAA0C,QAA+D,6BAAyB;AAC3I,SAASC,wBAAwB,QAAQ,+BAA2B;AACpE,SAASC,uBAAuB,QAAQ,mCAA+B;AAC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AIvH,IAAIiB,MAAMxB,MAAM;IAClC,OAAO;QAAEJ,QAAQiI,SAASjI,MAAM,GAAG4B,MAAM5B,MAAM;QAAEC,OAAO2B,MAAM3B,KAAK;QAAEC,WAAW0B,MAAM1B,SAAS;QAAEM,OAAO;QAAG2H,UAAUF,SAASE,QAAQ,CAACrG,MAAM,CAAC,CAACsG,MAAQ,CAACF,MAAMlH,GAAG,CAACoH;IAAM;AAC1K"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/jobs/ai-site-import-pictures.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/*==========================================\n * IMPROVE IT, GENERATIVE: A REDESIGNED PAGE'S PICTURES (AGL-4152).\n *\n * A redesign may ask for a picture where its own do not fit: a slot, which\n * `aiResolveLayoutPictures` fills or drops. This is the order it fills from,\n * first to last:\n *\n * 1. the page's own photos no `keep` placed;\n * 2. the source photos the site's earlier pages left off;\n * 3. what the site's own photo links hold, then the stock library\n * (`aiLayoutSitePhotoSource`): no credits, copied into the library, its\n * photographer kept, its brand-tag refusal held;\n * 4. only where the owner switched them on, and it is quoted, a generated\n * picture: a hero or a section's lead, never a person or a product, at most\n * `AI_SITE_IMPORT_GENERATED_PICTURES_PER_PAGE` a page.\n *\n * A slot nothing fills is dropped, and the row around it redraws without a gap\n * (`aiLayoutDropEmptyPictures`). The tally is what the page's row says.\n *=========================================*/\n\nimport type { PluginMediaIngest } from '@aglyn/aglyn/plugin-manager/plugin-media-ingest'\nimport { aiLayoutPictureBandCells, type AiLayoutPicturePhoto, type AiLayoutPictureSlot, type AiLayoutPictureSource } from '../layout-language/ai-layout-pictures'\nimport { AI_SITE_IMPORT_GENERATED_PICTURES_PER_PAGE, type AiSiteImportPagePictures, type AiSiteImportPhoto } from '../model/ai-site-import'\nimport { aiMediaCreditsPerPicture } from '../model/ai-media-credits'\nimport { aiSiteImportIsBrandMark } from '../model/ai-site-import-marks'\nimport { estimateAiBilledUsd } from '../providers/catalog'\nimport { AiImageSafetyRefusal, type AiImageAspectRatio, type AiImageProvider } from '../providers/image-contract'\nimport { aiImageAltText, aiImageFileName } from '../server/ai-media-image'\nimport { aiMediaRasterPrompt } from '../server/ai-media-raster-prompt'\nimport { recordAssistCost } from '../usage/assist-usage'\nimport { aiAssignOwnerPhotos } from './ai-layout-owner-photos'\n\ntype NodesMap = Parameters<typeof aiLayoutPictureBandCells>[0]\n\n/** How long one generated picture is waited on: a picture is decoration, and a page never fails over one. */\nexport const AI_SITE_IMPORT_GENERATED_PICTURE_MS = 40_000\n\n/** What a slot's picture came from, as the page's row tells it. */\nexport interface AiSiteImportPictureTally {\n source: number\n stock: number\n generated: number\n /** What the generated pictures cost at the billed rates. */\n generatedUsd: number\n /** The addresses of the source's photos a slot took. */\n placed: string[]\n}\n\nexport function aiSiteImportPictureTally(): AiSiteImportPictureTally {\n return { source: 0, stock: 0, generated: 0, generatedUsd: 0, placed: [] }\n}\n\n/** A generated picture for a slot, stored and metered; `null` where it could not be made or kept. */\nexport type AiSiteImportPictureMaker = (slot: AiLayoutPictureSlot, tally: AiSiteImportPictureTally) => Promise<AiLayoutPicturePhoto | null>\n\n/** The words that say a picture shows a person: a generated one would show someone who does not exist as if they did. */\nconst SHOWS_PEOPLE = /\\b(?:team|staff|crew|owner|owners|founder|founders|person|people|portrait|headshot|family|families|customer|customers|client|clients|patient|patients|doctor|dentist|stylist|therapist|attorney|lawyer|accountant)\\b/i\n\n/**\n * Which slots may take a generated picture (AGL-4152): the page's hero, or the\n * first picture of a section that is no cell of a band, and none that shows a\n * person, a product or a record's own thing.\n */\nexport function aiSiteImportGeneratedSlots(nodes: NodesMap, slots: readonly AiLayoutPictureSlot[]): boolean[] {\n const cells = aiLayoutPictureBandCells(nodes, slots)\n const seen = new Set<number>()\n return slots.map((slot, index) => {\n const lead = !seen.has(slot.sectionIndex)\n seen.add(slot.sectionIndex)\n return lead && !cells[index] && !slot.product && !slot.people && !slot.record && !SHOWS_PEOPLE.test(slot.alt)\n })\n}\n\n/**\n * The source a redesigned page's slots fill from, in the order above. `next`\n * answers the slots the source's own photos leave and tallies its own stock\n * photos; a slot it leaves empty takes a generated picture where one is allowed.\n */\nexport function aiSiteImportPictureSource(input: {\n photos: readonly AiSiteImportPhoto[]\n next: AiLayoutPictureSource | null\n make?: AiSiteImportPictureMaker | null\n nodes: NodesMap\n tally: AiSiteImportPictureTally\n /** The most generated pictures this page may take. */\n cap?: number\n}): AiLayoutPictureSource | null {\n const { next, make, tally } = input\n // A photo the library holds no size for cannot be framed, and a brand's mark is no photo (AGL-4152): a slot is a\n // photo's place, and a client's logo filled a page's cover. A mark by its name, or by its pixels (`graphic`).\n const photos = input.photos.filter((photo) => photo.width && photo.height && !aiSiteImportIsBrandMark(photo))\n if (!photos.length && !next && !make) return null\n const froms = new Map(photos.map((photo) => [photo.src, photo.from ?? '']))\n const cap = input.cap ?? AI_SITE_IMPORT_GENERATED_PICTURES_PER_PAGE\n return async (slots, report) => {\n const own = aiAssignOwnerPhotos(slots, photos)\n own.forEach((photo) => {\n if (!photo) return\n tally.source += 1\n const from = froms.get(photo.src)\n if (from) tally.placed.push(from)\n })\n const open = slots.filter((_slot, index) => !own[index])\n const found = next && open.length ? await next(open, report) : []\n let at = 0\n const answers = own.map((photo) => photo ?? found[at++] ?? null)\n if (!make) return answers\n const allowed = aiSiteImportGeneratedSlots(input.nodes, slots)\n let left = Math.max(0, cap)\n const out: Array<AiLayoutPicturePhoto | null> = [...answers]\n // One at a time, so the cap holds whatever each comes to: the hero first, the biggest seen first.\n const order = slots.map((slot, index) => ({ slot, index })).sort((a, b) => Number(b.slot.role === 'hero') - Number(a.slot.role === 'hero') || a.index - b.index)\n for (const { slot, index } of order) {\n if (left <= 0) break\n if (answers[index]?.src || !allowed[index]) continue\n const made = await make(slot, tally)\n if (made) {\n out[index] = made\n left -= 1\n }\n }\n return out\n }\n}\n\n/** The nearest shape the image models draw to a slot's frame. */\nexport function aiSiteImportPictureShape(aspect: number): AiImageAspectRatio {\n const shapes: ReadonlyArray<readonly [AiImageAspectRatio, number]> = [['16:9', 16 / 9], ['4:3', 4 / 3], ['1:1', 1], ['3:4', 3 / 4], ['9:16', 9 / 16]]\n const wanted = aspect > 0 && Number.isFinite(aspect) ? aspect : 4 / 3\n return [...shapes].sort((a, b) => Math.abs(a[1] - wanted) - Math.abs(b[1] - wanted))[0]?.[0] ?? '4:3'\n}\n\n/** What a generated picture is made through, and whether the workspace's meter has room for it. */\nexport interface AiSiteImportPictureMakerInput {\n provider: AiImageProvider | null\n ingest: PluginMediaIngest | null\n firestore: FirebaseFirestore.Firestore\n orgId: string\n hostId: string\n uid: string\n /** What the site is, which a picture's own words are read with. */\n about: string\n /** Whether the workspace's meter has room for a picture now. */\n roomFor?: (credits: number) => boolean\n record?: typeof recordAssistCost\n}\n\n/**\n * A generated picture through the Media door's own parts (AGL-4152): the image\n * provider at a paid plan's size, the fixed style wording, the media library's\n * ingest as an upload this member made, the same provenance on the asset, and the\n * same meter, charged only once it is stored. `null` where it cannot run here.\n */\nexport function aiSiteImportPictureMaker(input: AiSiteImportPictureMakerInput): AiSiteImportPictureMaker | null {\n const { provider, ingest } = input\n if (!provider?.configured() || !ingest) return null\n const size = '1K' as const\n return async (slot, tally) => {\n const model = provider.defaultModel()\n if (input.roomFor && !input.roomFor(aiMediaCreditsPerPicture('photo', model, size))) return null\n const words = `${slot.alt}. For a website about: ${input.about}`.replace(/\\s+/g, ' ').trim()\n const timeout = new Promise<null>((resolve) => setTimeout(() => resolve(null), AI_SITE_IMPORT_GENERATED_PICTURE_MS))\n try {\n const result = await Promise.race([\n provider.generate({ model, prompt: aiMediaRasterPrompt(words, 'natural'), aspectRatio: aiSiteImportPictureShape(slot.aspect), size, count: 1 }),\n timeout,\n ])\n const image = result?.images[0]\n if (!result || !image) return null\n const alt = aiImageAltText(slot.alt)\n const stored = await ingest.ingest({\n hostId: input.hostId,\n uid: input.uid,\n fileName: aiImageFileName(slot.alt, 0, image.mimeType),\n contentType: image.mimeType,\n bytes: Buffer.from(image.base64, 'base64'),\n alt,\n description: 'Created with AI from a description.',\n })\n if (!stored.ok) return null\n const usage = { ...result.usage, images: 1, imageSize: size }\n let signalId: string | null = null\n try {\n signalId = await (input.record ?? recordAssistCost)(input.firestore, input.orgId, {\n route: 'ai/jobs',\n hostId: input.hostId,\n model,\n tier: 'entitled',\n usage,\n docsPaths: [],\n stopReason: 'end_turn',\n free: null,\n uid: input.uid,\n kind: 'image',\n })\n } catch (error) {\n console.error('ai site import: a generated picture’s usage was not recorded', { orgId: input.orgId, error })\n }\n await input.firestore\n .collection('hosts')\n .doc(input.hostId)\n .collection('media')\n .doc(stored.mediaId)\n .update({ aiGenerated: { model, prompt: slot.alt, mode: 'photo', style: 'natural', aspectRatio: aiSiteImportPictureShape(slot.aspect), signalId, generatedBy: input.uid, createdAt: new Date() } })\n .catch((error: unknown) => console.error('ai site import: a generated picture’s record was not written', { mediaId: stored.mediaId, error }))\n tally.generated += 1\n tally.generatedUsd += estimateAiBilledUsd(usage, model)\n return { src: stored.src, width: stored.width ?? 1024, height: stored.height ?? 1024, alt }\n } catch (error) {\n if (!(error instanceof AiImageSafetyRefusal)) console.warn('ai site import: a generated picture failed; its slot is dropped', { error })\n return null\n }\n }\n}\n\n/** A page's pictures, as its row reads them once its slots are filled. */\nexport function aiSiteImportPagePicturesOf(pictures: AiSiteImportPagePictures, tally: AiSiteImportPictureTally): AiSiteImportPagePictures {\n const taken = new Set(tally.placed)\n return { source: pictures.source + tally.source, stock: tally.stock, generated: tally.generated, slots: 0, unplaced: pictures.unplaced.filter((url) => !taken.has(url)) }\n}\n"],"names":["aiLayoutPictureBandCells","AI_SITE_IMPORT_GENERATED_PICTURES_PER_PAGE","aiMediaCreditsPerPicture","aiSiteImportIsBrandMark","estimateAiBilledUsd","AiImageSafetyRefusal","aiImageAltText","aiImageFileName","aiMediaRasterPrompt","recordAssistCost","aiAssignOwnerPhotos","AI_SITE_IMPORT_GENERATED_PICTURE_MS","aiSiteImportPictureTally","source","stock","generated","generatedUsd","placed","SHOWS_PEOPLE","aiSiteImportGeneratedSlots","nodes","slots","cells","seen","Set","map","slot","index","lead","has","sectionIndex","add","product","people","record","test","alt","aiSiteImportPictureSource","input","next","make","tally","photos","filter","photo","width","height","length","froms","Map","src","from","cap","report","own","forEach","get","push","open","_slot","found","at","answers","allowed","left","Math","max","out","order","sort","a","b","Number","role","made","aiSiteImportPictureShape","aspect","shapes","wanted","isFinite","abs","aiSiteImportPictureMaker","provider","ingest","configured","size","model","defaultModel","roomFor","words","about","replace","trim","timeout","Promise","resolve","setTimeout","stored","result","race","generate","prompt","aspectRatio","count","image","images","hostId","uid","fileName","mimeType","contentType","bytes","Buffer","base64","description","ok","usage","imageSize","signalId","firestore","orgId","route","tier","docsPaths","stopReason","free","kind","error","console","collection","doc","mediaId","update","aiGenerated","mode","style","generatedBy","createdAt","Date","catch","warn","aiSiteImportPagePicturesOf","pictures","taken","unplaced","url"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED;;;;;;;;;;;;;;;;;;2CAkB2C;AAG3C,SAASA,wBAAwB,QAAyF,2CAAuC;AACjK,SAASC,0CAA0C,QAA+D,6BAAyB;AAC3I,SAASC,wBAAwB,QAAQ,+BAA2B;AACpE,SAASC,uBAAuB,QAAQ,mCAA+B;AACvE,SAASC,mBAAmB,QAAQ,0BAAsB;AAC1D,SAASC,oBAAoB,QAAuD,iCAA6B;AACjH,SAASC,cAAc,EAAEC,eAAe,QAAQ,8BAA0B;AAC1E,SAASC,mBAAmB,QAAQ,sCAAkC;A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AEM,OAAO;QAAG2H,UAAUF,SAASE,QAAQ,CAACrG,MAAM,CAAC,CAACsG,MAAQ,CAACF,MAAMlH,GAAG,CAACoH;IAAM;AAC1K"}
|
|
@@ -411,6 +411,7 @@ export interface SiteImportFidelitySource {
|
|
|
411
411
|
src: string;
|
|
412
412
|
width?: number;
|
|
413
413
|
height?: number;
|
|
414
|
+
graphic?: boolean;
|
|
414
415
|
}>;
|
|
415
416
|
/** What the source holds that a visitor cannot see (AGL-4152): a build that draws any of it fails `concealed`. */
|
|
416
417
|
concealed?: {
|
|
@@ -2291,10 +2291,12 @@ const isHeading = (node)=>{
|
|
|
2291
2291
|
};
|
|
2292
2292
|
/** The kept ledger and the design lines of a page a generative Improve it built (AGL-4152). */ function improvedScore(source, built, look, drawnSections, options) {
|
|
2293
2293
|
var _options_scope, _options_vocabulary, _source_photos, _options_forms, _options_destinations, _options_meaning, _source_photos1, _ref, _look_theme_button_fill;
|
|
2294
|
-
const ledger = siteImportLedger({
|
|
2294
|
+
const ledger = siteImportLedger(_extends({
|
|
2295
2295
|
layout: source.layout,
|
|
2296
2296
|
blocks: source.blocks
|
|
2297
|
-
}
|
|
2297
|
+
}, source.photos ? {
|
|
2298
|
+
photos: source.photos
|
|
2299
|
+
} : {}));
|
|
2298
2300
|
const pieces = built.pieces;
|
|
2299
2301
|
const sourceTexts = source.blocks.flatMap((block)=>isLine(block) && block.kind !== 'image' ? [
|
|
2300
2302
|
clean(block.text)
|