@aglyn/plugins-ai 1.16.0 → 1.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aglyn/plugins-ai",
3
- "version": "1.16.0",
3
+ "version": "1.17.0",
4
4
  "license": "Apache-2.0",
5
5
  "homepage": "https://aglyn.com",
6
6
  "repository": {
@@ -25,22 +25,22 @@
25
25
  "./package.json": "./package.json"
26
26
  },
27
27
  "dependencies": {
28
- "@aglyn/aglyn": "1.16.0",
29
- "@aglyn/shared-data-enums": "1.16.0",
30
- "@aglyn/shared-data-mdi": "1.16.0",
31
- "@aglyn/shared-data-types": "1.16.0",
32
- "@aglyn/shared-ui-email-campaigns": "1.16.0",
33
- "@aglyn/shared-ui-jsx": "1.16.0",
34
- "@aglyn/shared-ui-snackstack": "1.16.0",
35
- "@aglyn/shared-ui-theme": "1.16.0",
36
- "@aglyn/shared-util-email": "1.16.0",
37
- "@aglyn/shared-util-errors": "1.16.0",
38
- "@aglyn/shared-util-http": "1.16.0",
39
- "@aglyn/shared-util-timestamp": "1.16.0",
40
- "@aglyn/shared-util-tools": "1.16.0",
41
- "@aglyn/tenant-data-admin": "1.16.0",
42
- "@aglyn/tenant-feature-instance": "1.16.0",
43
- "@aglyn/tenant-runtime": "1.16.0",
28
+ "@aglyn/aglyn": "1.17.0",
29
+ "@aglyn/shared-data-enums": "1.17.0",
30
+ "@aglyn/shared-data-mdi": "1.17.0",
31
+ "@aglyn/shared-data-types": "1.17.0",
32
+ "@aglyn/shared-ui-email-campaigns": "1.17.0",
33
+ "@aglyn/shared-ui-jsx": "1.17.0",
34
+ "@aglyn/shared-ui-snackstack": "1.17.0",
35
+ "@aglyn/shared-ui-theme": "1.17.0",
36
+ "@aglyn/shared-util-email": "1.17.0",
37
+ "@aglyn/shared-util-errors": "1.17.0",
38
+ "@aglyn/shared-util-http": "1.17.0",
39
+ "@aglyn/shared-util-timestamp": "1.17.0",
40
+ "@aglyn/shared-util-tools": "1.17.0",
41
+ "@aglyn/tenant-data-admin": "1.17.0",
42
+ "@aglyn/tenant-feature-instance": "1.17.0",
43
+ "@aglyn/tenant-runtime": "1.17.0",
44
44
  "@swc/helpers": "0.5.23"
45
45
  },
46
46
  "peerDependencies": {
@@ -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 AiLayoutSettlement } from '../layout-language/ai-layout-language';
18
+ import { type AiLayoutImportHero, type AiLayoutItem, type AiLayoutSection, 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';
@@ -205,8 +205,38 @@ export interface AiSiteImportImprovedPage {
205
205
  added: AiSiteImportAddedSection[];
206
206
  pictures: AiSiteImportPagePictures;
207
207
  }
208
+ /**
209
+ * The opening of a redesign without a brand's mark for its photo (AGL-4152):
210
+ * a picture the source names a logo, a badge or an icon (`aiSiteImportIsBrandMark`)
211
+ * that the answer keeps in its first section takes the page's widest photo no
212
+ * section placed instead, or, where it has none, is left out, and a row it
213
+ * leaves a column empty in is drawn as one column. A client's logo the source
214
+ * showed beside its words read, as a cover, as the page's own work.
215
+ */
216
+ export declare function aiSiteImportOpeningPhoto(answer: readonly AiSiteImportImprovedSection[], input: {
217
+ doc: Pick<AiSiteImportDocument, 'blocks' | 'photos'>;
218
+ ledger: Pick<SiteImportLedger, 'items'>;
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'>;
208
238
  /** The sections a redesign holds, in the compiler's language: every `keep` expanded to the source's own blocks, every link resolved. */
209
- export declare function aiSiteImportImprovedPage(answer: readonly AiSiteImportImprovedSection[], input: AiSiteImportImproveCompileInput): AiSiteImportImprovedPage;
239
+ export declare function aiSiteImportImprovedPage(given: readonly AiSiteImportImprovedSection[], input: AiSiteImportImproveCompileInput): AiSiteImportImprovedPage;
210
240
  /** The most an answer may ask for, whatever the page and the model: a whole page's design and words, with its thinking. */
211
241
  export declare const AI_SITE_IMPORT_IMPROVE_MOST_TOKENS = 8000;
212
242
  /**
@@ -43,6 +43,7 @@ import { AI_LAYOUT_ALIGNS, AI_LAYOUT_BANDS, AI_LAYOUT_MAX_COLS, AI_LAYOUT_STYLES
43
43
  import { AI_ICON_WORDS } from "../runtime/ai-icon-library.js";
44
44
  import { aiSiteHomeArc } from "../model/ai-site-home-arcs.js";
45
45
  import { SITE_IMPORT_IMPROVED_MEANING, SITE_IMPORT_MEANING_FLOOR, siteImportContentKept, siteImportContentWords } from "../model/ai-site-import-fidelity.js";
46
+ import { aiSiteImportIsBrandMark } from "../model/ai-site-import-marks.js";
46
47
  import { siteImportLedger } from "../model/ai-site-import-ledger.js";
47
48
  import { AI_SITE_IMPORT_PAGE_CEILING_CREDITS } from "../model/ai-site-import.js";
48
49
  import { estimateAiBilledUsd } from "../providers/catalog.js";
@@ -836,8 +837,277 @@ const WORD_KINDS = new Set([
836
837
  return name;
837
838
  });
838
839
  }
839
- /** 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(answer, input) {
840
+ /**
841
+ * The opening of a redesign without a brand's mark for its photo (AGL-4152):
842
+ * a picture the source names a logo, a badge or an icon (`aiSiteImportIsBrandMark`)
843
+ * that the answer keeps in its first section takes the page's widest photo no
844
+ * section placed instead, or, where it has none, is left out, and a row it
845
+ * leaves a column empty in is drawn as one column. A client's logo the source
846
+ * showed beside its words read, as a cover, as the page's own work.
847
+ */ export function aiSiteImportOpeningPhoto(answer, input) {
848
+ const [first, ...rest] = answer;
849
+ if (!first) return [
850
+ ...answer
851
+ ];
852
+ const { doc, ledger } = input;
853
+ const items = new Map(ledger.items.map((item)=>[
854
+ item.ref,
855
+ item
856
+ ]));
857
+ const imageOf = (ref)=>{
858
+ const item = items.get(ref);
859
+ const block = (item == null ? void 0 : item.kind) === 'picture' ? doc.blocks[item.lines[0]] : undefined;
860
+ return (block == null ? void 0 : block.kind) === 'image' ? block : null;
861
+ };
862
+ const markAt = (ref)=>{
863
+ const image = imageOf(ref);
864
+ return !!image && aiSiteImportIsBrandMark({
865
+ url: image.url,
866
+ alt: image.alt
867
+ });
868
+ };
869
+ const marks = new Set(first.blocks.filter((block)=>block.kind === 'keep' && markAt(block.ref)));
870
+ if (!marks.size) return [
871
+ ...answer
872
+ ];
873
+ const placed = new Set(aiSiteImportImprovedPlaced(answer, ledger));
874
+ const ratioOf = (ref)=>{
875
+ var _imageOf;
876
+ const url = (_imageOf = imageOf(ref)) == null ? void 0 : _imageOf.url;
877
+ const photo = url ? doc.photos.find((entry)=>entry.from === url) : undefined;
878
+ return (photo == null ? void 0 : photo.width) && photo.height ? photo.width / photo.height : 0;
879
+ };
880
+ const spare = ledger.items.filter((item)=>item.kind === 'picture' && !placed.has(item.ref) && !markAt(item.ref)).sort((a, b)=>ratioOf(b.ref) - ratioOf(a.ref));
881
+ let next = 0;
882
+ const blocks = first.blocks.flatMap((block)=>{
883
+ if (!marks.has(block) || block.kind !== 'keep') return [
884
+ block
885
+ ];
886
+ const instead = spare[next++];
887
+ return instead ? [
888
+ _extends({}, block, {
889
+ ref: instead.ref
890
+ })
891
+ ] : [];
892
+ });
893
+ // A row with a column left empty is no row.
894
+ const cols = first.cols;
895
+ const emptied = !!cols && cols.some((_, col)=>!blocks.some((block)=>block.col === col));
896
+ const opening = emptied ? _extends({}, first.band ? {
897
+ band: first.band
898
+ } : {}, first.align ? {
899
+ align: first.align
900
+ } : {}, {
901
+ blocks: blocks.map((_0)=>{
902
+ let { col: _col } = _0, block = _object_without_properties_loose(_0, [
903
+ "col"
904
+ ]);
905
+ return block;
906
+ })
907
+ }) : _extends({}, first, {
908
+ blocks
909
+ });
910
+ return [
911
+ opening,
912
+ ...rest
913
+ ];
914
+ }
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
+ /** 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) {
840
1105
  const { doc, ledger, design, destinations } = input;
1106
+ // A brand's mark is never the opening's photo (AGL-4152).
1107
+ const answer = aiSiteImportOpeningPhoto(given, {
1108
+ doc,
1109
+ ledger
1110
+ });
841
1111
  const scope = aiSiteImportMapScope(doc, {
842
1112
  formId: input.formId,
843
1113
  finish: 'improve'
@@ -916,7 +1186,7 @@ const WORD_KINDS = new Set([
916
1186
  const carded = aiSiteImportCardPictures(answer, ledger);
917
1187
  const sections = answer.map((section, index)=>{
918
1188
  var _pictures__picture;
919
- var _pictures_;
1189
+ var _input_plan_nav_primaryCta, _input_plan, _pictures_;
920
1190
  scope.at = `sections[${index}]`;
921
1191
  const words = section.blocks.flatMap((block)=>{
922
1192
  var _block_text;
@@ -924,7 +1194,7 @@ const WORD_KINDS = new Set([
924
1194
  (_block_text = block.text) != null ? _block_text : ''
925
1195
  ] : [];
926
1196
  }).join(' ');
927
- const blocks = section.blocks.flatMap((raw)=>{
1197
+ const drawn = section.blocks.flatMap((raw)=>{
928
1198
  var _block_items;
929
1199
  if (raw.kind === 'keep') return keepOf(raw.ref, raw.col);
930
1200
  const block = raw;
@@ -1011,6 +1281,12 @@ const WORD_KINDS = new Set([
1011
1281
  })
1012
1282
  ];
1013
1283
  });
1284
+ // Each call to action once, in its place (AGL-4152).
1285
+ const tidy = aiSiteImportSectionActions({
1286
+ cols: section.cols,
1287
+ blocks: drawn
1288
+ }, (_input_plan = input.plan) == null ? void 0 : (_input_plan_nav_primaryCta = _input_plan.nav.primaryCta) == null ? void 0 : _input_plan_nav_primaryCta.label);
1289
+ const blocks = tidy.blocks;
1014
1290
  const pictures = blocks.filter((block)=>block.kind === 'image' || block.kind === 'video');
1015
1291
  const opens = index === 0 && pictures.length === 1 && blocks.every((block)=>block.kind === 'image' || block.kind === 'video' || WORD_KINDS.has(block.kind));
1016
1292
  const opening = ((_pictures_ = pictures[0]) == null ? void 0 : _pictures_.kind) === 'image' ? (_pictures__picture = pictures[0].picture) != null ? _pictures__picture : null : null;
@@ -1020,8 +1296,8 @@ const WORD_KINDS = new Set([
1020
1296
  band
1021
1297
  } : {}, section.align ? {
1022
1298
  align: section.align
1023
- } : {}, section.cols && !hero ? {
1024
- cols: section.cols
1299
+ } : {}, tidy.cols && !hero ? {
1300
+ cols: tidy.cols
1025
1301
  } : {}, hero ? {
1026
1302
  hero,
1027
1303
  blocks: blocks.map((block)=>block.kind === 'image' && block.picture ? _extends({}, block, {