@aglyn/plugins-ai 1.17.0 → 1.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. package/package.json +17 -17
  2. package/src/lib/jobs/ai-job-import-step.js +7 -4
  3. package/src/lib/jobs/ai-job-import-step.js.map +1 -1
  4. package/src/lib/jobs/ai-job-page-step.js +7 -4
  5. package/src/lib/jobs/ai-job-page-step.js.map +1 -1
  6. package/src/lib/jobs/ai-layout-stock-photos.d.ts +9 -0
  7. package/src/lib/jobs/ai-layout-stock-photos.js +4 -0
  8. package/src/lib/jobs/ai-layout-stock-photos.js.map +1 -1
  9. package/src/lib/jobs/ai-site-import-actions.d.ts +35 -0
  10. package/src/lib/jobs/ai-site-import-actions.js +215 -0
  11. package/src/lib/jobs/ai-site-import-actions.js.map +1 -0
  12. package/src/lib/jobs/ai-site-import-compile.d.ts +7 -0
  13. package/src/lib/jobs/ai-site-import-compile.js +34 -4
  14. package/src/lib/jobs/ai-site-import-compile.js.map +1 -1
  15. package/src/lib/jobs/ai-site-import-improve.d.ts +1 -19
  16. package/src/lib/jobs/ai-site-import-improve.js +61 -196
  17. package/src/lib/jobs/ai-site-import-improve.js.map +1 -1
  18. package/src/lib/jobs/ai-site-import-plan.d.ts +52 -0
  19. package/src/lib/jobs/ai-site-import-plan.js +146 -3
  20. package/src/lib/jobs/ai-site-import-plan.js.map +1 -1
  21. package/src/lib/model/ai-site-import-fidelity.d.ts +6 -0
  22. package/src/lib/model/ai-site-import-fidelity.js +88 -10
  23. package/src/lib/model/ai-site-import-fidelity.js.map +1 -1
  24. package/src/lib/model/ai-site-import-marks.d.ts +7 -0
  25. package/src/lib/model/ai-site-import-marks.js +14 -0
  26. package/src/lib/model/ai-site-import-marks.js.map +1 -1
  27. package/src/lib/model/ai-site-import.d.ts +11 -1
  28. package/src/lib/model/ai-site-import.js +14 -2
  29. package/src/lib/model/ai-site-import.js.map +1 -1
  30. package/src/lib/site-import/site-import-images.js +9 -6
  31. package/src/lib/site-import/site-import-images.js.map +1 -1
@@ -15,7 +15,7 @@
15
15
  * limitations under the License.
16
16
  */
17
17
  import type { AiLayoutDesign } from '../layout-language/ai-layout-design';
18
- import { type AiLayoutImportHero, type AiLayoutItem, type AiLayoutSection, type AiLayoutSettlement } from '../layout-language/ai-layout-language';
18
+ import { type AiLayoutImportHero, type AiLayoutItem, type AiLayoutSettlement } from '../layout-language/ai-layout-language';
19
19
  import type { AiSiteImportAddedSection, AiSiteImportPagePictures, AiSiteImportPageRole, AiSiteImportPlan } from '../model/ai-site-import';
20
20
  import { type SiteImportFidelityTheme, type SiteImportPageFidelity } from '../model/ai-site-import-fidelity';
21
21
  import { type SiteImportLedger, type SiteImportLedgerLine } from '../model/ai-site-import-ledger';
@@ -217,24 +217,6 @@ export declare function aiSiteImportOpeningPhoto(answer: readonly AiSiteImportIm
217
217
  doc: Pick<AiSiteImportDocument, 'blocks' | 'photos'>;
218
218
  ledger: Pick<SiteImportLedger, 'items'>;
219
219
  }): AiSiteImportImprovedSection[];
220
- /**
221
- * A redesigned section's calls to action, each once and each where it belongs
222
- * (AGL-4152), whatever the answer and the source's kept groups gave:
223
- *
224
- * - Buttons placed in a row's columns under a group that runs the row's width,
225
- * with nothing else in those columns, sit in the cards they go to where each
226
- * goes where exactly one card does, else together under the group: a row of
227
- * two buttons under three cards read as a grid half filled.
228
- * - A link with the same words to the same place on every item of a group
229
- * (each review's "See more reviews") is shown once, as a button after the
230
- * group, unless the section already has that button. Where only some items
231
- * carry it, each is that item's own action and stays.
232
- * - The same button twice in a section is shown once, the first.
233
- * - Two buttons side by side to the same place are one: the one with the
234
- * header's words where one has them, else the first. Of buttons side by
235
- * side, only the first is filled; the rest are outlined.
236
- */
237
- export declare function aiSiteImportSectionActions(section: Pick<AiLayoutSection, 'cols' | 'blocks'>, cta?: string | null): Pick<AiLayoutSection, 'cols' | 'blocks'>;
238
220
  /** The sections a redesign holds, in the compiler's language: every `keep` expanded to the source's own blocks, every link resolved. */
239
221
  export declare function aiSiteImportImprovedPage(given: readonly AiSiteImportImprovedSection[], input: AiSiteImportImproveCompileInput): AiSiteImportImprovedPage;
240
222
  /** The most an answer may ask for, whatever the page and the model: a whole page's design and words, with its thinking. */
@@ -50,6 +50,7 @@ import { estimateAiBilledUsd } from "../providers/catalog.js";
50
50
  import { assistCreditsFromUsd } from "../usage/assist-credits.js";
51
51
  import { siteImportLabel } from "../site-import/site-import-page.js";
52
52
  import { aiSiteImportHonesty, aiSiteImportImprovedPlaced } from "./ai-site-import-honesty.js";
53
+ import { aiSiteImportSectionActions } from "./ai-site-import-actions.js";
53
54
  import { aiSiteImportLayoutOf, aiSiteImportLinkTo, aiSiteImportMapScope, aiSiteImportNodeBlocks, aiSiteImportTakePicture } from "./ai-site-import-compile.js";
54
55
  import { aiSiteImportTextParts } from "./ai-site-import-document.js";
55
56
  const clean = (text)=>typeof text === 'string' ? text.replace(/\s+/g, ' ').trim() : '';
@@ -732,6 +733,11 @@ const short = (text, most = 80)=>text.length > most ? `${text.slice(0, most - 1)
732
733
  'column',
733
734
  'editorial'
734
735
  ]);
736
+ /** The heroes that lay their photo edge to edge behind the words, which a square or a portrait cannot fill. */ const COVERING_HEROES = new Set([
737
+ 'cover',
738
+ 'poster',
739
+ 'panel'
740
+ ]);
735
741
  /**
736
742
  * The site's hero as a page brought in draws it: a collage or a portrait holds
737
743
  * what a page brought in does not. A redesign whose opening holds the page's
@@ -741,7 +747,10 @@ const short = (text, most = 80)=>text.length > most ? `${text.slice(0, most - 1)
741
747
  */ export function aiSiteImportImproveHero(design, plan, opening) {
742
748
  var _ref, _ref1;
743
749
  const chosen = (_ref = plan == null ? void 0 : plan.design.hero) != null ? _ref : aiLayoutDesignChoices(design).hero;
744
- if (BOXED_HEROES.has(chosen) && ((_ref1 = opening == null ? void 0 : opening.ratio) != null ? _ref1 : 0) >= AI_SITE_IMPORT_COVER_LEAST_RATIO) return 'cover';
750
+ const ratio = (_ref1 = opening == null ? void 0 : opening.ratio) != null ? _ref1 : 0;
751
+ if (BOXED_HEROES.has(chosen) && ratio >= AI_SITE_IMPORT_COVER_LEAST_RATIO) return 'cover';
752
+ // A square or a portrait is never stretched behind the words (AGL-4152): it sits beside them.
753
+ if (COVERING_HEROES.has(chosen) && ratio > 0 && ratio < AI_SITE_IMPORT_COVER_LEAST_RATIO) return 'split';
745
754
  return chosen === 'collage' || chosen === 'portrait' ? 'split' : chosen;
746
755
  }
747
756
  /** How many of a group's items sit across: planned for how much each says. */ export function aiSiteImportImproveColumns(items) {
@@ -912,195 +921,6 @@ const WORD_KINDS = new Set([
912
921
  ...rest
913
922
  ];
914
923
  }
915
- /** A button's words and where it goes, as one key: two that share it are the same action. */ const actionKey = (text, to)=>`${clean(text).toLowerCase()}\u0000${to != null ? to : ''}`;
916
- /** Whether a button is drawn filled: the compiler's default, `primary` or `large`. */ const filled = (block)=>block.kind === 'button' && (block.style === undefined || block.style === 'primary' || block.style === 'large');
917
- /**
918
- * A redesigned section's calls to action, each once and each where it belongs
919
- * (AGL-4152), whatever the answer and the source's kept groups gave:
920
- *
921
- * - Buttons placed in a row's columns under a group that runs the row's width,
922
- * with nothing else in those columns, sit in the cards they go to where each
923
- * goes where exactly one card does, else together under the group: a row of
924
- * two buttons under three cards read as a grid half filled.
925
- * - A link with the same words to the same place on every item of a group
926
- * (each review's "See more reviews") is shown once, as a button after the
927
- * group, unless the section already has that button. Where only some items
928
- * carry it, each is that item's own action and stays.
929
- * - The same button twice in a section is shown once, the first.
930
- * - Two buttons side by side to the same place are one: the one with the
931
- * header's words where one has them, else the first. Of buttons side by
932
- * side, only the first is filled; the rest are outlined.
933
- */ export function aiSiteImportSectionActions(section, cta) {
934
- let { cols, blocks } = section;
935
- // Buttons in columns under a group across the row.
936
- const placed = blocks.filter((block)=>block.col !== undefined);
937
- const group = blocks.find((block)=>{
938
- var _ref;
939
- var _block_items;
940
- return block.col === undefined && ((_ref = (_block_items = block.items) == null ? void 0 : _block_items.length) != null ? _ref : 0) >= 2 && block.kind !== 'list' && block.kind !== 'faq';
941
- });
942
- if (cols && cols.length >= 2 && group && placed.length && placed.every((block)=>block.kind === 'button')) {
943
- const items = group.items;
944
- const cards = placed.map((button)=>items.flatMap((item, at)=>{
945
- var _item_links;
946
- return button.to && item.to === button.to && !((_item_links = item.links) == null ? void 0 : _item_links.length) ? [
947
- at
948
- ] : [];
949
- }));
950
- const own = cards.every((found)=>found.length === 1) && new Set(cards.map((found)=>found[0])).size === cards.length;
951
- if (own) {
952
- const into = new Map(placed.map((button, at)=>{
953
- var _cards_at;
954
- return [
955
- (_cards_at = cards[at]) == null ? void 0 : _cards_at[0],
956
- button
957
- ];
958
- }));
959
- const carded = _extends({}, group, {
960
- items: items.map((item, at)=>{
961
- var _ref;
962
- var _into_get;
963
- return into.has(at) ? _extends({}, item, {
964
- links: [
965
- {
966
- text: (_ref = (_into_get = into.get(at)) == null ? void 0 : _into_get.text) != null ? _ref : '',
967
- to: item.to,
968
- style: 'secondary'
969
- }
970
- ]
971
- }) : item;
972
- })
973
- });
974
- blocks = blocks.flatMap((block)=>block === group ? [
975
- carded
976
- ] : placed.includes(block) ? [] : [
977
- block
978
- ]);
979
- } else blocks = blocks.map((block)=>placed.includes(block) ? ((_0)=>{
980
- let { col: _col } = _0, rest = _object_without_properties_loose(_0, [
981
- "col"
982
- ]);
983
- return rest;
984
- })(block) : block);
985
- cols = undefined;
986
- }
987
- // A link repeated across a group's items, once after the group.
988
- const buttons = new Set(blocks.flatMap((block)=>block.kind === 'button' ? [
989
- actionKey(block.text, block.to)
990
- ] : []));
991
- blocks = blocks.flatMap((block)=>{
992
- const items = block.items;
993
- if (!items || items.length < 2) return [
994
- block
995
- ];
996
- const counted = new Map();
997
- for (const item of items){
998
- var _item_links;
999
- for (const key of new Set(((_item_links = item.links) != null ? _item_links : []).map((link)=>actionKey(link.text, link.to)))){
1000
- var _ref;
1001
- var _item_links1;
1002
- const link = (_item_links1 = item.links) == null ? void 0 : _item_links1.find((entry)=>actionKey(entry.text, entry.to) === key);
1003
- const was = counted.get(key);
1004
- if (link) counted.set(key, _extends({
1005
- text: link.text
1006
- }, link.to ? {
1007
- to: link.to
1008
- } : {}, link.style ? {
1009
- style: link.style
1010
- } : {}, {
1011
- on: ((_ref = was == null ? void 0 : was.on) != null ? _ref : 0) + 1
1012
- }));
1013
- }
1014
- }
1015
- const repeated = new Map([
1016
- ...counted
1017
- ].filter(([, entry])=>entry.on === items.length));
1018
- if (!repeated.size) return [
1019
- block
1020
- ];
1021
- const stripped = items.map((item)=>{
1022
- var _item_links;
1023
- if (!((_item_links = item.links) == null ? void 0 : _item_links.length)) return item;
1024
- const links = item.links.filter((link)=>!repeated.has(actionKey(link.text, link.to)));
1025
- const { links: _links } = item, rest = _object_without_properties_loose(item, [
1026
- "links"
1027
- ]);
1028
- return links.length ? _extends({}, rest, {
1029
- links
1030
- }) : rest;
1031
- });
1032
- const after = [
1033
- ...repeated
1034
- ].flatMap(([key, entry])=>{
1035
- if (buttons.has(key)) return [];
1036
- buttons.add(key);
1037
- return [
1038
- _extends({
1039
- kind: 'button',
1040
- text: entry.text
1041
- }, entry.to ? {
1042
- to: entry.to
1043
- } : {}, entry.style ? {
1044
- style: entry.style
1045
- } : {}, block.col !== undefined ? {
1046
- col: block.col
1047
- } : {})
1048
- ];
1049
- });
1050
- return [
1051
- _extends({}, block, {
1052
- items: stripped
1053
- }),
1054
- ...after
1055
- ];
1056
- });
1057
- // The same button twice, once.
1058
- const seen = new Set();
1059
- blocks = blocks.filter((block)=>{
1060
- if (block.kind !== 'button' || !block.to) return true;
1061
- const key = actionKey(block.text, block.to);
1062
- if (seen.has(key)) return false;
1063
- seen.add(key);
1064
- return true;
1065
- });
1066
- // Buttons side by side: one to each place, the first filled.
1067
- const wanted = clean(cta).toLowerCase();
1068
- const out = [];
1069
- for (const block of blocks){
1070
- const before = out[out.length - 1];
1071
- if (block.kind === 'button' && (before == null ? void 0 : before.kind) === 'button' && before.col === block.col) {
1072
- var _out_, _out_1;
1073
- // Back over the run this button stands in.
1074
- let start = out.length - 1;
1075
- while(start > 0 && ((_out_ = out[start - 1]) == null ? void 0 : _out_.kind) === 'button' && ((_out_1 = out[start - 1]) == null ? void 0 : _out_1.col) === block.col)start -= 1;
1076
- const run = out.slice(start);
1077
- const same = block.to ? run.findIndex((entry)=>entry.to === block.to) : -1;
1078
- if (same !== -1) {
1079
- // The header's words win the place; the run keeps its first button's place and fill.
1080
- const kept = run[same];
1081
- if (wanted && clean(block.text).toLowerCase() === wanted && clean(kept.text).toLowerCase() !== wanted) {
1082
- const { style: _style } = block, words = _object_without_properties_loose(block, [
1083
- "style"
1084
- ]);
1085
- out[start + same] = _extends({}, words, kept.style ? {
1086
- style: kept.style
1087
- } : {});
1088
- }
1089
- continue;
1090
- }
1091
- out.push(run.some(filled) && filled(block) ? _extends({}, block, {
1092
- style: 'secondary'
1093
- }) : block);
1094
- continue;
1095
- }
1096
- out.push(block);
1097
- }
1098
- return _extends({}, cols ? {
1099
- cols
1100
- } : {}, {
1101
- blocks: out
1102
- });
1103
- }
1104
924
  /** The sections a redesign holds, in the compiler's language: every `keep` expanded to the source's own blocks, every link resolved. */ export function aiSiteImportImprovedPage(given, input) {
1105
925
  const { doc, ledger, design, destinations } = input;
1106
926
  // A brand's mark is never the opening's photo (AGL-4152).
@@ -1184,6 +1004,44 @@ const WORD_KINDS = new Set([
1184
1004
  };
1185
1005
  // The source's pictures a written set of cards stands for, where the answer gave them none (AGL-4152).
1186
1006
  const carded = aiSiteImportCardPictures(answer, ledger);
1007
+ // The page's own photo an opening that asks for a picture takes (AGL-4152), and which of its things it was.
1008
+ const asked = new Set([
1009
+ ...aiSiteImportImprovedPlaced(answer, ledger),
1010
+ ...[
1011
+ ...carded.values()
1012
+ ].flat()
1013
+ ]);
1014
+ const ownOpening = {
1015
+ ref: null,
1016
+ taken: false
1017
+ };
1018
+ const openingPicture = ()=>{
1019
+ var _widest, _ref;
1020
+ if (ownOpening.taken) return null;
1021
+ const ratioOf = (line)=>{
1022
+ const image = line === undefined || scope.used.has(line) ? undefined : doc.blocks[line];
1023
+ if ((image == null ? void 0 : image.kind) !== 'image' || aiSiteImportIsBrandMark({
1024
+ url: image.url,
1025
+ alt: image.alt
1026
+ })) return 0;
1027
+ const photo = scope.photos.get(image.url);
1028
+ return (photo == null ? void 0 : photo.width) && photo.height ? photo.width / photo.height : 0;
1029
+ };
1030
+ const widest = (found)=>found.filter((entry)=>ratioOf(entry.line) > 0).sort((a, b)=>ratioOf(b.line) - ratioOf(a.line))[0];
1031
+ // Its photo no section places; else one of a gallery it keeps, which shows the rest.
1032
+ const pick = (_widest = widest(ledger.items.filter((item)=>item.kind === 'picture' && !asked.has(item.ref)).map((item)=>({
1033
+ ref: item.ref,
1034
+ line: item.lines[0]
1035
+ })))) != null ? _widest : widest(ledger.items.filter((item)=>item.kind === 'gallery' && asked.has(item.ref)).flatMap((item)=>item.lines.map((line)=>({
1036
+ ref: null,
1037
+ line
1038
+ }))));
1039
+ const picture = pick ? aiSiteImportTakePicture(scope, pick.line) : null;
1040
+ if (!picture) return null;
1041
+ ownOpening.taken = true;
1042
+ ownOpening.ref = (_ref = pick == null ? void 0 : pick.ref) != null ? _ref : null;
1043
+ return picture;
1044
+ };
1187
1045
  const sections = answer.map((section, index)=>{
1188
1046
  var _pictures__picture;
1189
1047
  var _input_plan_nav_primaryCta, _input_plan, _pictures_;
@@ -1202,11 +1060,17 @@ const WORD_KINDS = new Set([
1202
1060
  col: block.col
1203
1061
  } : {};
1204
1062
  if (block.kind === 'image') {
1063
+ var _block_picture;
1205
1064
  const { col: _col } = block, rest = _object_without_properties_loose(block, [
1206
1065
  "col"
1207
1066
  ]);
1067
+ // An opening that asks for a picture shows the page's own where it has one (AGL-4152): a slot the
1068
+ // library fills is searched by words alone, and put a stranger's desk on a builder's gallery.
1069
+ const own = index === 0 && !((_block_picture = block.picture) == null ? void 0 : _block_picture.src) ? openingPicture() : null;
1208
1070
  return [
1209
- _extends({}, rest, placed)
1071
+ _extends({}, rest, own ? {
1072
+ picture: own
1073
+ } : {}, placed)
1210
1074
  ];
1211
1075
  }
1212
1076
  if (block.kind === 'text' || block.kind === 'lede' || block.kind === 'note') {
@@ -1323,10 +1187,10 @@ const WORD_KINDS = new Set([
1323
1187
  } : {});
1324
1188
  });
1325
1189
  const placed = new Set([
1326
- ...aiSiteImportImprovedPlaced(answer, ledger),
1327
- ...[
1328
- ...carded.values()
1329
- ].flat()
1190
+ ...asked,
1191
+ ...ownOpening.ref ? [
1192
+ ownOpening.ref
1193
+ ] : []
1330
1194
  ]);
1331
1195
  const allPictures = ledger.items.filter((item)=>item.kind === 'picture');
1332
1196
  const unplaced = allPictures.filter((item)=>!placed.has(item.ref)).flatMap((item)=>{
@@ -1346,7 +1210,8 @@ const WORD_KINDS = new Set([
1346
1210
  written,
1347
1211
  added,
1348
1212
  pictures: {
1349
- source: allPictures.length - unplaced.length,
1213
+ // A gallery's photo the opening shows is the source's too.
1214
+ source: allPictures.length - unplaced.length + (ownOpening.taken && !ownOpening.ref ? 1 : 0),
1350
1215
  stock: 0,
1351
1216
  generated: 0,
1352
1217
  slots: sections.reduce((total, section)=>total + section.blocks.filter((block)=>block.kind === 'image' && !block.picture).length, 0),