@aglyn/plugins-ai 1.14.0 → 1.15.1

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 (131) hide show
  1. package/package.json +17 -17
  2. package/src/lib/components/ai-site-build-page.component.js +5 -3
  3. package/src/lib/components/ai-site-build-page.component.js.map +1 -1
  4. package/src/lib/components/ai-site-import-finish.component.d.ts +3 -1
  5. package/src/lib/components/ai-site-import-finish.component.js +3 -3
  6. package/src/lib/components/ai-site-import-finish.component.js.map +1 -1
  7. package/src/lib/components/ai-site-import-job.component.d.ts +4 -3
  8. package/src/lib/components/ai-site-import-job.component.js +141 -43
  9. package/src/lib/components/ai-site-import-job.component.js.map +1 -1
  10. package/src/lib/components/ai-site-import-plan.component.d.ts +42 -0
  11. package/src/lib/components/ai-site-import-plan.component.js +246 -0
  12. package/src/lib/components/ai-site-import-plan.component.js.map +1 -0
  13. package/src/lib/components/ai-site-import-start.component.d.ts +3 -1
  14. package/src/lib/components/ai-site-import-start.component.js +6 -3
  15. package/src/lib/components/ai-site-import-start.component.js.map +1 -1
  16. package/src/lib/components/ai-site-start-card.component.js +6 -2
  17. package/src/lib/components/ai-site-start-card.component.js.map +1 -1
  18. package/src/lib/components/ai-site-start-steps.component.d.ts +3 -2
  19. package/src/lib/components/ai-site-start-steps.component.js +12 -5
  20. package/src/lib/components/ai-site-start-steps.component.js.map +1 -1
  21. package/src/lib/jobs/ai-job-import-step.d.ts +63 -2
  22. package/src/lib/jobs/ai-job-import-step.js +372 -22
  23. package/src/lib/jobs/ai-job-import-step.js.map +1 -1
  24. package/src/lib/jobs/ai-job-layout-language.js +4 -1
  25. package/src/lib/jobs/ai-job-layout-language.js.map +1 -1
  26. package/src/lib/jobs/ai-job-page-language.d.ts +23 -2
  27. package/src/lib/jobs/ai-job-page-language.js +252 -5
  28. package/src/lib/jobs/ai-job-page-language.js.map +1 -1
  29. package/src/lib/jobs/ai-job-page-step.d.ts +7 -0
  30. package/src/lib/jobs/ai-job-page-step.js +75 -12
  31. package/src/lib/jobs/ai-job-page-step.js.map +1 -1
  32. package/src/lib/jobs/ai-job-plan-step.js +4 -2
  33. package/src/lib/jobs/ai-job-plan-step.js.map +1 -1
  34. package/src/lib/jobs/ai-job-site-look.js +14 -5
  35. package/src/lib/jobs/ai-job-site-look.js.map +1 -1
  36. package/src/lib/jobs/ai-job-text-step.d.ts +11 -2
  37. package/src/lib/jobs/ai-job-text-step.js.map +1 -1
  38. package/src/lib/jobs/ai-jobs.js +2 -1
  39. package/src/lib/jobs/ai-jobs.js.map +1 -1
  40. package/src/lib/jobs/ai-site-import-compile.d.ts +43 -2
  41. package/src/lib/jobs/ai-site-import-compile.js +131 -63
  42. package/src/lib/jobs/ai-site-import-compile.js.map +1 -1
  43. package/src/lib/jobs/ai-site-import-document.d.ts +25 -1
  44. package/src/lib/jobs/ai-site-import-document.js +26 -7
  45. package/src/lib/jobs/ai-site-import-document.js.map +1 -1
  46. package/src/lib/jobs/ai-site-import-honesty.d.ts +65 -0
  47. package/src/lib/jobs/ai-site-import-honesty.js +271 -0
  48. package/src/lib/jobs/ai-site-import-honesty.js.map +1 -0
  49. package/src/lib/jobs/ai-site-import-improve.d.ts +286 -0
  50. package/src/lib/jobs/ai-site-import-improve.js +1281 -0
  51. package/src/lib/jobs/ai-site-import-improve.js.map +1 -0
  52. package/src/lib/jobs/ai-site-import-look.d.ts +4 -0
  53. package/src/lib/jobs/ai-site-import-look.js +16 -6
  54. package/src/lib/jobs/ai-site-import-look.js.map +1 -1
  55. package/src/lib/jobs/ai-site-import-pictures.d.ts +83 -0
  56. package/src/lib/jobs/ai-site-import-pictures.js +261 -0
  57. package/src/lib/jobs/ai-site-import-pictures.js.map +1 -0
  58. package/src/lib/jobs/ai-site-import-plan.d.ts +78 -0
  59. package/src/lib/jobs/ai-site-import-plan.js +627 -0
  60. package/src/lib/jobs/ai-site-import-plan.js.map +1 -0
  61. package/src/lib/jobs/ai-site-import-wording.js +2 -5
  62. package/src/lib/jobs/ai-site-import-wording.js.map +1 -1
  63. package/src/lib/layout-language/ai-layout-compiler.d.ts +6 -0
  64. package/src/lib/layout-language/ai-layout-compiler.js +10 -6
  65. package/src/lib/layout-language/ai-layout-compiler.js.map +1 -1
  66. package/src/lib/layout-language/ai-layout-design.d.ts +9 -0
  67. package/src/lib/layout-language/ai-layout-design.js +29 -3
  68. package/src/lib/layout-language/ai-layout-design.js.map +1 -1
  69. package/src/lib/layout-language/ai-layout-frame-source.d.ts +5 -0
  70. package/src/lib/layout-language/ai-layout-frame-source.js +4 -2
  71. package/src/lib/layout-language/ai-layout-frame-source.js.map +1 -1
  72. package/src/lib/layout-language/ai-layout-frame.d.ts +2 -0
  73. package/src/lib/layout-language/ai-layout-frame.js +20 -12
  74. package/src/lib/layout-language/ai-layout-frame.js.map +1 -1
  75. package/src/lib/layout-language/ai-layout-language.d.ts +8 -0
  76. package/src/lib/layout-language/ai-layout-language.js +7 -3
  77. package/src/lib/layout-language/ai-layout-language.js.map +1 -1
  78. package/src/lib/model/ai-credit-estimate.d.ts +16 -0
  79. package/src/lib/model/ai-credit-estimate.js +14 -0
  80. package/src/lib/model/ai-credit-estimate.js.map +1 -1
  81. package/src/lib/model/ai-site-import-fidelity.d.ts +64 -0
  82. package/src/lib/model/ai-site-import-fidelity.js +380 -0
  83. package/src/lib/model/ai-site-import-fidelity.js.map +1 -1
  84. package/src/lib/model/ai-site-import-ledger.d.ts +82 -0
  85. package/src/lib/model/ai-site-import-ledger.js +254 -0
  86. package/src/lib/model/ai-site-import-ledger.js.map +1 -0
  87. package/src/lib/model/ai-site-import-view.d.ts +113 -7
  88. package/src/lib/model/ai-site-import-view.js +174 -16
  89. package/src/lib/model/ai-site-import-view.js.map +1 -1
  90. package/src/lib/model/ai-site-import.d.ts +253 -3
  91. package/src/lib/model/ai-site-import.js +371 -25
  92. package/src/lib/model/ai-site-import.js.map +1 -1
  93. package/src/lib/model/ai-site-job.js +4 -0
  94. package/src/lib/model/ai-site-job.js.map +1 -1
  95. package/src/lib/model/ai-site-kinds.d.ts +2 -0
  96. package/src/lib/model/ai-site-kinds.js +7 -0
  97. package/src/lib/model/ai-site-kinds.js.map +1 -1
  98. package/src/lib/model/ai-site-look.d.ts +14 -5
  99. package/src/lib/model/ai-site-look.js +22 -16
  100. package/src/lib/model/ai-site-look.js.map +1 -1
  101. package/src/lib/model/ai-site-start.d.ts +37 -7
  102. package/src/lib/model/ai-site-start.js +54 -10
  103. package/src/lib/model/ai-site-start.js.map +1 -1
  104. package/src/lib/model/ai-site-starter-look.d.ts +69 -0
  105. package/src/lib/model/ai-site-starter-look.js +90 -0
  106. package/src/lib/model/ai-site-starter-look.js.map +1 -0
  107. package/src/lib/runtime/ai-doctrine-validators.d.ts +7 -0
  108. package/src/lib/runtime/ai-doctrine-validators.js +3 -2
  109. package/src/lib/runtime/ai-doctrine-validators.js.map +1 -1
  110. package/src/lib/runtime/ai-doctrine.d.ts +10 -0
  111. package/src/lib/runtime/ai-doctrine.js +16 -2
  112. package/src/lib/runtime/ai-doctrine.js.map +1 -1
  113. package/src/lib/server/ai-jobs-resume.js +12 -3
  114. package/src/lib/server/ai-jobs-resume.js.map +1 -1
  115. package/src/lib/server/ai-jobs-route.js +5 -1
  116. package/src/lib/server/ai-jobs-route.js.map +1 -1
  117. package/src/lib/server/ai-site-import-route.d.ts +6 -0
  118. package/src/lib/server/ai-site-import-route.js +8 -1
  119. package/src/lib/server/ai-site-import-route.js.map +1 -1
  120. package/src/lib/site-import/fixtures/site-import-fidelity-replay.d.ts +46 -7
  121. package/src/lib/site-import/fixtures/site-import-fidelity-replay.js +260 -14
  122. package/src/lib/site-import/fixtures/site-import-fidelity-replay.js.map +1 -1
  123. package/src/lib/site-import/fixtures/site-import-improve-answers.d.ts +33 -0
  124. package/src/lib/site-import/fixtures/site-import-improve-answers.js +457 -0
  125. package/src/lib/site-import/fixtures/site-import-improve-answers.js.map +1 -0
  126. package/src/lib/site-import/fixtures/site-layout-recordings.d.ts +29 -0
  127. package/src/lib/site-import/fixtures/site-layout-recordings.js +26 -0
  128. package/src/lib/site-import/fixtures/site-layout-recordings.js.map +1 -1
  129. package/src/lib/site-import/site-import-flag.d.ts +17 -0
  130. package/src/lib/site-import/site-import-flag.js +15 -0
  131. package/src/lib/site-import/site-import-flag.js.map +1 -1
@@ -49,7 +49,8 @@ import { _ as _object_without_properties_loose } from "@swc/helpers/_/_object_wi
49
49
  * site. The person is told why and checks again.
50
50
  *=========================================*/ import { PLATFORM_BRAND_NAME } from "@aglyn/aglyn/app-utils/platform-brand";
51
51
  import { videoEmbedOf } from "@aglyn/aglyn/plugin-manager/video-embed-provider";
52
- import { aiCreditRangeOrdered, aiCreditRangeText, AI_MEASURED_IMPORT_CREDITS } from "./ai-credit-estimate.js";
52
+ import { aiCreditRangeOrdered, aiCreditRangeText, AI_MEASURED_IMPORT_CREDITS, AI_MEASURED_PAID_SITE_CREDITS } from "./ai-credit-estimate.js";
53
+ import { aiMediaCreditsPerPicture } from "./ai-media-credits.js";
53
54
  /** The job kind. */ export const AI_SITE_IMPORT_KIND = 'import';
54
55
  /** The input naming the proved domain the job brings in. */ export const AI_SITE_IMPORT_DOMAIN_INPUT = 'domain';
55
56
  /** The most pages one wave brings in. */ export const AI_SITE_IMPORT_WAVE_PAGES = 10;
@@ -470,6 +471,49 @@ function trimItem(item, keep) {
470
471
  'imprint',
471
472
  'impressum'
472
473
  ];
474
+ /** What a page's row says where its redesign did not pass (AGL-4152). */ export const AI_SITE_IMPORT_LAYOUT_KEPT = 'Layout kept: the redesign did not pass';
475
+ /** What a proposed page's row says where it could not be written: it has no old page to keep, so it is left out. */ export const AI_SITE_IMPORT_PROPOSED_NOT_WRITTEN = 'This new page was left out: it could not be written without inventing facts. Its credits are given back.';
476
+ /** The most characters of what the site's pages say an import keeps for its redesigns' facts (AGL-4152). */ export const AI_SITE_IMPORT_SAID_MAX_CHARS = 16000;
477
+ /** What the site's pages say, with these reads' lines added where there is room (AGL-4152). */ export function aiSiteImportSaid(said, reads) {
478
+ const out = [
479
+ ...said != null ? said : []
480
+ ];
481
+ const seen = new Set(out);
482
+ let chars = out.reduce((sum, line)=>sum + line.length, 0);
483
+ for (const read of reads){
484
+ var _read_blocks;
485
+ if (typeof read === 'string') continue;
486
+ for (const block of (_read_blocks = read.blocks) != null ? _read_blocks : []){
487
+ if (block.kind === 'image') continue;
488
+ const line = block.text.replace(/\s+/g, ' ').trim();
489
+ if (!line || seen.has(line) || chars + line.length > AI_SITE_IMPORT_SAID_MAX_CHARS) continue;
490
+ seen.add(line);
491
+ out.push(line);
492
+ chars += line.length;
493
+ }
494
+ }
495
+ return out;
496
+ }
497
+ export const AI_SITE_IMPORT_PAGE_ROLES = [
498
+ 'home',
499
+ 'service',
500
+ 'about',
501
+ 'contact',
502
+ 'gallery',
503
+ 'pricing',
504
+ 'faq',
505
+ 'other'
506
+ ];
507
+ /**
508
+ * Whether generated pictures are on where the owner has not said (AGL-4152):
509
+ * on, with a switch. A picture costs credits, so a wave that may take them
510
+ * quotes them in its ceiling before it starts, and the switch turns them off.
511
+ */ export const AI_SITE_IMPORT_GENERATED_PICTURES_DEFAULT = true;
512
+ /** What a plan's row and panel say where it did not pass (AGL-4152). */ export const AI_SITE_IMPORT_PLAN_FELL_BACK = 'Your menu and footer stay as your site has them: the plan for your new site did not pass.';
513
+ /** The ledger slot of the plan's proposed page. */ export const AI_SITE_IMPORT_PROPOSED_SLOT = 'proposed';
514
+ /** What a plan's answer calls its proposed page before it has an id. */ export const AI_SITE_IMPORT_PROPOSED_PAGE = 'new';
515
+ /** The most generated pictures one page takes (AGL-4152), a hero or a section's lead only. */ export const AI_SITE_IMPORT_GENERATED_PICTURES_PER_PAGE = 2;
516
+ /** What the plan's own pass may spend at most: its answer and its one re-ask at the measured p90. */ export const AI_SITE_IMPORT_PLAN_CEILING_CREDITS = 180;
473
517
  /**
474
518
  * Whether the site's header and footer are built from the source's own menu
475
519
  * (AGL-4108), with no model: the home page's menu was read. Then the frame
@@ -965,6 +1009,7 @@ const OPEN = new Set([
965
1009
  return read.layout.sections.some((section)=>holds(section.nodes));
966
1010
  }
967
1011
  /** What the next pass of the step does. */ export function aiSiteImportNextWork(state, items) {
1012
+ var _state_waves_;
968
1013
  // A read that stopped at its home page reads again: the person's Check again.
969
1014
  if (!state || aiSiteImportReadStops(state.verdict)) return {
970
1015
  kind: 'inventory'
@@ -990,6 +1035,17 @@ const OPEN = new Set([
990
1035
  wave: running,
991
1036
  pages: unread
992
1037
  };
1038
+ // A generative Improve it plans the site once, before anything of it is built (AGL-4152).
1039
+ if (running.generative && running.frame && ((_state_waves_ = state.waves[0]) == null ? void 0 : _state_waves_.index) === running.index) {
1040
+ if (state.plan === undefined) return {
1041
+ kind: 'plan',
1042
+ wave: running
1043
+ };
1044
+ if (state.plan && !state.planAccepted) return {
1045
+ kind: 'plan-accepted',
1046
+ wave: running
1047
+ };
1048
+ }
993
1049
  if (running.frame && state.frame && aiSiteImportItemOpen(items, AI_SITE_IMPORT_FRAME_SLOT)) {
994
1050
  return {
995
1051
  kind: 'frame',
@@ -1117,6 +1173,10 @@ const readChars = (read)=>{
1117
1173
  title: clipLabel(read.title) || ((_next_pages_find = next.pages.find((page)=>page.slot === slot)) == null ? void 0 : _next_pages_find.title) || ''
1118
1174
  });
1119
1175
  }
1176
+ // A generative wave keeps what its pages say past each page (AGL-4152); any other leaves the state as it was.
1177
+ if (next.waves.some((wave)=>wave.status === 'running' && wave.generative)) next = _extends({}, next, {
1178
+ said: aiSiteImportSaid(next.said, reads.values())
1179
+ });
1120
1180
  return next;
1121
1181
  }
1122
1182
  /** A page's photos are in the library. */ export function aiSiteImportPhotosIn(state, slot, photos) {
@@ -1193,7 +1253,11 @@ const readChars = (read)=>{
1193
1253
  }
1194
1254
  /** The state as the console reads it: every page's read text left off. */ export function aiSiteImportWire(state) {
1195
1255
  if (!state) return null;
1196
- return _extends({}, state, {
1256
+ // What the site's pages say is the redesigns' (AGL-4152): the console reads none of it.
1257
+ const { said: _said } = state, rest = _object_without_properties_loose(state, [
1258
+ "said"
1259
+ ]);
1260
+ return _extends({}, rest, {
1197
1261
  pages: state.pages.map((page)=>page.read ? _extends({}, page, {
1198
1262
  read: _extends({}, page.read, {
1199
1263
  text: '',
@@ -1271,20 +1335,33 @@ const readChars = (read)=>{
1271
1335
  * of its pages with whether its words are kept or improved. The step stamps a
1272
1336
  * wave once, when it starts, so a change made before a later wave reaches only
1273
1337
  * the waves that have not started.
1274
- */ export function aiSiteImportWaveStamped(state, index) {
1338
+ */ export function aiSiteImportWaveStamped(state, index, options = {}) {
1275
1339
  const wave = state.waves.find((entry)=>entry.index === index);
1276
1340
  if (!wave) return state;
1277
1341
  const choice = aiSiteImportChoiceOf(state);
1278
1342
  const slots = new Set(wave.slots);
1343
+ // A generative Improve it plans the site and its design with new copy or without (AGL-4152):
1344
+ // a page is redesigned from its ledger only where its words are improved too.
1345
+ const generative = options.generative === true && choice.finish === 'improve';
1279
1346
  return _extends({}, state, {
1280
1347
  waves: state.waves.map((entry)=>entry.index === index ? _extends({}, entry, {
1281
1348
  finish: choice.finish,
1282
1349
  wording: choice.wording
1283
- }) : entry),
1350
+ }, generative ? {
1351
+ generative: true
1352
+ } : {}, options.videoPosters === true ? {
1353
+ videoPosters: true
1354
+ } : {}) : entry),
1284
1355
  pages: state.pages.map((page)=>slots.has(page.slot) ? _extends({}, page, {
1285
1356
  wording: aiSiteImportPageWording(page, choice)
1286
1357
  }) : page)
1287
- });
1358
+ }, generative ? {
1359
+ said: aiSiteImportSaid(state.said, [
1360
+ ...state.pages
1361
+ ].sort((a, b)=>Number(b.slug === '/') - Number(a.slug === '/')).flatMap((page)=>slots.has(page.slot) && page.read ? [
1362
+ page.read
1363
+ ] : []))
1364
+ } : {});
1288
1365
  }
1289
1366
  /**
1290
1367
  * The owner's change between waves (AGL-4152), as the resume door writes it
@@ -1306,6 +1383,215 @@ const readChars = (read)=>{
1306
1383
  'siteImport.wording': aiSiteImportWordingOf(finish, asked)
1307
1384
  };
1308
1385
  }
1386
+ /** The most source photos an import holds for a later page's slots: each is a library reference, and every page rides one job document. */ const SITE_PHOTOS_HELD = 24;
1387
+ /**
1388
+ * How a page's generative Improve it came out (AGL-4152), what it added and what
1389
+ * it shows, for its row; and the source's photos it left off, which a later
1390
+ * page's slot takes before a stock photo.
1391
+ */ export function aiSiteImportRedesignOf(state, slot, redesign, added, pictures, missed) {
1392
+ var _ref, _ref1, _next_sitePhotos;
1393
+ var _state_pages_find_photos, _state_pages_find;
1394
+ const next = withPage(state, slot, _extends({
1395
+ redesign
1396
+ }, (added == null ? void 0 : added.length) ? {
1397
+ added: [
1398
+ ...added
1399
+ ]
1400
+ } : {}, pictures ? {
1401
+ pictures
1402
+ } : {}, (missed == null ? void 0 : missed.length) ? {
1403
+ redesignMissed: missed.slice(0, 8).map((code)=>code.slice(0, 40))
1404
+ } : {}));
1405
+ const left = new Set((_ref = pictures == null ? void 0 : pictures.unplaced) != null ? _ref : []);
1406
+ if (!left.size) return next;
1407
+ const assets = (_ref1 = (_state_pages_find = state.pages.find((page)=>page.slot === slot)) == null ? void 0 : (_state_pages_find_photos = _state_pages_find.photos) == null ? void 0 : _state_pages_find_photos.assets) != null ? _ref1 : [];
1408
+ const held = (_next_sitePhotos = next.sitePhotos) != null ? _next_sitePhotos : [];
1409
+ const pool = [
1410
+ ...held,
1411
+ ...assets.filter((photo)=>!!photo.from && left.has(photo.from) && !held.some((other)=>other.src === photo.src))
1412
+ ].slice(0, SITE_PHOTOS_HELD);
1413
+ return pool.length ? _extends({}, next, {
1414
+ sitePhotos: pool
1415
+ }) : next;
1416
+ }
1417
+ /*------------------------------------------
1418
+ * The site's plan (AGL-4152)
1419
+ *-----------------------------------------*/ /** Whether generated pictures are on for an import: as its owner said, else the default. */ export function aiSiteImportGeneratedPicturesOn(state) {
1420
+ return typeof (state == null ? void 0 : state.generatedPictures) === 'boolean' ? state.generatedPictures : AI_SITE_IMPORT_GENERATED_PICTURES_DEFAULT;
1421
+ }
1422
+ /** Whether the job waits on its owner's say-so over a plan (AGL-4152): shown, and nothing of the site built. */ export function aiSiteImportPlanAwaits(state) {
1423
+ return !!(state == null ? void 0 : state.plan) && !state.planAccepted;
1424
+ }
1425
+ /** Whether the site has room for a page more than the import brings in (AGL-4152): the plan's count, against what is there and what is coming. */ export function aiSiteImportHasRoomForPage(state, room) {
1426
+ if (room.limit === null) return true;
1427
+ return room.limit - room.used - state.pages.filter((page)=>!page.refused).length >= 1;
1428
+ }
1429
+ /**
1430
+ * The plan in, or the plan that did not pass (`null`). A proposed page takes
1431
+ * its place in the wave's rows as a page of its own, new, with no source: its
1432
+ * words are written from what the site says, so its one line is its purpose.
1433
+ */ export function aiSiteImportPlanIn(state, wave, plan, at, draftId) {
1434
+ if (!(plan == null ? void 0 : plan.proposed)) return _extends({}, state, {
1435
+ plan
1436
+ });
1437
+ const proposed = plan.proposed;
1438
+ const named = (pages)=>pages.map((page)=>page === AI_SITE_IMPORT_PROPOSED_PAGE ? draftId : page);
1439
+ const page = {
1440
+ slot: AI_SITE_IMPORT_PROPOSED_SLOT,
1441
+ url: `https://${state.domain}/${proposed.slug}`,
1442
+ path: `/${proposed.slug}`,
1443
+ title: proposed.title,
1444
+ group: 'main',
1445
+ wave: wave.index,
1446
+ draftId,
1447
+ slug: proposed.slug,
1448
+ words: 0,
1449
+ images: 0,
1450
+ origin: 'proposed',
1451
+ build: 'arranged',
1452
+ wording: 'improved',
1453
+ photos: {
1454
+ brought: 0,
1455
+ reused: 0,
1456
+ skipped: 0,
1457
+ assets: []
1458
+ },
1459
+ read: {
1460
+ at,
1461
+ title: proposed.title,
1462
+ text: proposed.purpose,
1463
+ sections: [
1464
+ proposed.title
1465
+ ],
1466
+ images: [],
1467
+ blocks: [
1468
+ {
1469
+ kind: 'heading',
1470
+ level: 1,
1471
+ text: proposed.title,
1472
+ region: 'main'
1473
+ },
1474
+ {
1475
+ kind: 'paragraph',
1476
+ text: proposed.purpose,
1477
+ region: 'main'
1478
+ }
1479
+ ],
1480
+ words: proposed.purpose.split(/\s+/).filter(Boolean).length,
1481
+ forms: [],
1482
+ layout: null
1483
+ }
1484
+ };
1485
+ const cta = plan.nav.primaryCta;
1486
+ return _extends({}, state, {
1487
+ plan: _extends({}, plan, {
1488
+ nav: {
1489
+ groups: plan.nav.groups.map((group)=>_extends({}, group, {
1490
+ pages: named(group.pages)
1491
+ })),
1492
+ primaryCta: cta && cta.target === AI_SITE_IMPORT_PROPOSED_PAGE ? _extends({}, cta, {
1493
+ target: draftId
1494
+ }) : cta,
1495
+ footer: plan.nav.footer.map((column)=>_extends({}, column, {
1496
+ pages: named(column.pages)
1497
+ }))
1498
+ },
1499
+ proposed: _extends({}, proposed, {
1500
+ draftId
1501
+ })
1502
+ }, plan.roles ? {
1503
+ roles: Object.fromEntries(Object.entries(plan.roles).map(([id, role])=>[
1504
+ id === AI_SITE_IMPORT_PROPOSED_PAGE ? draftId : id,
1505
+ role
1506
+ ]))
1507
+ } : {}),
1508
+ pages: [
1509
+ ...state.pages,
1510
+ page
1511
+ ],
1512
+ waves: state.waves.map((entry)=>entry.index === wave.index ? _extends({}, entry, {
1513
+ slots: [
1514
+ ...entry.slots,
1515
+ AI_SITE_IMPORT_PROPOSED_SLOT
1516
+ ]
1517
+ }) : entry)
1518
+ });
1519
+ }
1520
+ /** A plan with its proposed page's row: pending, unless it is the one row a plan has already added. */ export function aiSiteImportPlanRow(state, items) {
1521
+ var _state_plan;
1522
+ const proposed = (_state_plan = state.plan) == null ? void 0 : _state_plan.proposed;
1523
+ if (!proposed || items.some((row)=>row.slot === AI_SITE_IMPORT_PROPOSED_SLOT)) return [
1524
+ ...items
1525
+ ];
1526
+ return [
1527
+ ...items,
1528
+ {
1529
+ slot: AI_SITE_IMPORT_PROPOSED_SLOT,
1530
+ op: 'page',
1531
+ label: proposed.title,
1532
+ status: 'pending',
1533
+ attempt: 1,
1534
+ creditsSpent: 0,
1535
+ creditsRefunded: 0,
1536
+ outputs: []
1537
+ }
1538
+ ];
1539
+ }
1540
+ /**
1541
+ * The owner started the build (AGL-4152). A proposed page they switched off is
1542
+ * gone: its row, its place in the wave, and every menu entry that named it.
1543
+ */ export function aiSiteImportPlanAccepted(state, items) {
1544
+ const plan = state.plan;
1545
+ if (!(plan == null ? void 0 : plan.proposed) || plan.proposed.on) return {
1546
+ state: _extends({}, state, {
1547
+ planAccepted: true
1548
+ }),
1549
+ items: [
1550
+ ...items
1551
+ ]
1552
+ };
1553
+ const off = plan.proposed.draftId;
1554
+ const kept = (pages)=>pages.filter((page)=>page !== off);
1555
+ const cta = plan.nav.primaryCta;
1556
+ return {
1557
+ state: _extends({}, state, {
1558
+ planAccepted: true,
1559
+ plan: _extends({}, plan, {
1560
+ nav: {
1561
+ groups: plan.nav.groups.map((group)=>_extends({}, group, {
1562
+ pages: kept(group.pages)
1563
+ })).filter((group)=>group.pages.length),
1564
+ primaryCta: (cta == null ? void 0 : cta.target) === off ? null : cta,
1565
+ footer: plan.nav.footer.map((column)=>_extends({}, column, {
1566
+ pages: kept(column.pages)
1567
+ })).filter((column)=>column.pages.length)
1568
+ },
1569
+ proposed: _extends({}, plan.proposed, {
1570
+ on: false
1571
+ })
1572
+ }),
1573
+ pages: state.pages.filter((page)=>page.slot !== AI_SITE_IMPORT_PROPOSED_SLOT),
1574
+ waves: state.waves.map((wave)=>_extends({}, wave, {
1575
+ slots: wave.slots.filter((slot)=>slot !== AI_SITE_IMPORT_PROPOSED_SLOT)
1576
+ }))
1577
+ }),
1578
+ items: items.filter((row)=>row.slot !== AI_SITE_IMPORT_PROPOSED_SLOT)
1579
+ };
1580
+ }
1581
+ /**
1582
+ * The owner's answer to a plan (AGL-4152), as the resume door writes it onto
1583
+ * an import waiting on one. What is not given stands. `null` when the job is
1584
+ * not an import waiting on a plan, or nothing is asked.
1585
+ */ export function aiSiteImportPlanUpdate(job, change) {
1586
+ var _job_siteImport;
1587
+ var _job_review, _state_plan;
1588
+ const state = (_job_siteImport = job.siteImport) != null ? _job_siteImport : null;
1589
+ if (job.kind !== AI_SITE_IMPORT_KIND || job.status !== 'needs_review' || ((_job_review = job.review) == null ? void 0 : _job_review.reason) !== 'wave' || !aiSiteImportPlanAwaits(state)) return null;
1590
+ const update = {};
1591
+ if (typeof change.addPage === 'boolean' && (state == null ? void 0 : (_state_plan = state.plan) == null ? void 0 : _state_plan.proposed)) update['siteImport.plan.proposed.on'] = change.addPage;
1592
+ if (typeof change.pictures === 'boolean') update['siteImport.generatedPictures'] = change.pictures;
1593
+ return Object.keys(update).length ? update : null;
1594
+ }
1309
1595
  /**
1310
1596
  * A page whose rewrite was refused (AGL-4152): it keeps every word as
1311
1597
  * written, and its row reads as kept. Only a page stamped `improved` changes.
@@ -1330,12 +1616,14 @@ const readChars = (read)=>{
1330
1616
  * arranged one, its design answer and its wording together, so each adds the
1331
1617
  * difference between the two. Its ceiling, the page's two passes, does not
1332
1618
  * move, and no price is new.
1333
- */ export function aiSiteImportWordingCredits(pages) {
1619
+ */ export function aiSiteImportWordingCredits(pages, options = {}) {
1334
1620
  const count = whole(pages);
1335
- const { reworded, arranged } = AI_MEASURED_IMPORT_CREDITS;
1621
+ // Under a generative Improve it (AGL-4152) new copy is a redesign from the ledger, measured on its own row.
1622
+ const { arranged } = AI_MEASURED_IMPORT_CREDITS;
1623
+ const worded = options.generative ? AI_MEASURED_IMPORT_CREDITS.redesigned : AI_MEASURED_IMPORT_CREDITS.reworded;
1336
1624
  return {
1337
- likely: count * (reworded.median - arranged.median),
1338
- p90: count * (reworded.p90 - arranged.p90)
1625
+ likely: count * (worded.median - arranged.median),
1626
+ p90: count * (worded.p90 - arranged.p90)
1339
1627
  };
1340
1628
  }
1341
1629
  /*------------------------------------------
@@ -1359,14 +1647,21 @@ const whole = (value)=>Math.max(0, Math.floor(Number.isFinite(value) ? value : 0
1359
1647
  * priced as an AI page, inside the same ceiling.
1360
1648
  */ export function aiSiteImportCreditRange(pages, options = {}) {
1361
1649
  const count = whole(pages);
1362
- const arranged = whole(options.arranged);
1650
+ const proposed = whole(options.proposed);
1651
+ const arranged = whole(options.arranged) + proposed;
1363
1652
  const copied = whole(options.copied);
1364
- const wording = aiSiteImportWordingCredits(Math.min(arranged, whole(options.reworded)));
1653
+ const wording = aiSiteImportWordingCredits(Math.min(arranged, whole(options.reworded) + proposed), options.generative ? {
1654
+ generative: true
1655
+ } : {});
1365
1656
  const measured = AI_MEASURED_IMPORT_CREDITS;
1657
+ const plan = options.plan ? AI_MEASURED_PAID_SITE_CREDITS.plan : {
1658
+ median: 0,
1659
+ p90: 0
1660
+ };
1366
1661
  return aiCreditRangeOrdered({
1367
- likely: count * measured.page.median + arranged * measured.arranged.median + wording.likely + copied * measured.copied.median + (options.frame ? measured.frame.median : 0),
1368
- p90: count * measured.page.p90 + arranged * measured.arranged.p90 + wording.p90 + copied * measured.copied.p90 + (options.frame ? measured.frame.p90 : 0),
1369
- ceiling: (count + arranged) * AI_SITE_IMPORT_PAGE_CEILING_CREDITS + copied * AI_SITE_IMPORT_COPIED_CEILING_CREDITS + (options.frame ? AI_SITE_IMPORT_FRAME_CEILING_CREDITS : 0)
1662
+ likely: count * measured.page.median + arranged * measured.arranged.median + wording.likely + copied * measured.copied.median + (options.frame ? measured.frame.median : 0) + plan.median,
1663
+ p90: count * measured.page.p90 + arranged * measured.arranged.p90 + wording.p90 + copied * measured.copied.p90 + (options.frame ? measured.frame.p90 : 0) + plan.p90,
1664
+ ceiling: (count + arranged) * AI_SITE_IMPORT_PAGE_CEILING_CREDITS + copied * AI_SITE_IMPORT_COPIED_CEILING_CREDITS + (options.frame ? AI_SITE_IMPORT_FRAME_CEILING_CREDITS : 0) + (options.plan ? AI_SITE_IMPORT_PLAN_CEILING_CREDITS : 0) + whole(options.pictures) * aiMediaCreditsPerPicture('photo', undefined, '1K')
1370
1665
  });
1371
1666
  }
1372
1667
  /**
@@ -1375,15 +1670,19 @@ const whole = (value)=>Math.max(0, Math.floor(Number.isFinite(value) ? value : 0
1375
1670
  * wave improves (AGL-4152): as stamped once it has started, and as the
1376
1671
  * import's choice now would stamp them before.
1377
1672
  */ export function aiSiteImportWaveOwed(state, wave, items) {
1673
+ var _state_waves_;
1378
1674
  const owed = (slot)=>items ? aiSiteImportItemOpen(items, slot) : true;
1379
1675
  const choice = aiSiteImportWaveChoice(state, wave);
1676
+ // A generative Improve it's own (AGL-4152): its frame draws from the plan, and a plan is owed once.
1677
+ const generative = aiSiteImportWaveIsGenerative(state, wave);
1678
+ const planned = generative && !!state.plan;
1380
1679
  // A header and footer drawn from the source's own menu ask no model (AGL-4108), so are owed nothing.
1381
1680
  const counts = {
1382
1681
  pages: 0,
1383
1682
  arranged: 0,
1384
1683
  reworded: 0,
1385
1684
  copied: 0,
1386
- frame: wave.frame && !!state.frame && !aiSiteImportFrameIsRead(state) && owed(AI_SITE_IMPORT_FRAME_SLOT)
1685
+ frame: wave.frame && !!state.frame && !aiSiteImportFrameIsRead(state) && !planned && owed(AI_SITE_IMPORT_FRAME_SLOT)
1387
1686
  };
1388
1687
  for (const slot of wave.slots){
1389
1688
  const page = state.pages.find((entry)=>entry.slot === slot);
@@ -1394,16 +1693,44 @@ const whole = (value)=>Math.max(0, Math.floor(Number.isFinite(value) ? value : 0
1394
1693
  } else if ((page == null ? void 0 : page.build) === 'copied') counts.copied += 1;
1395
1694
  else counts.pages += 1;
1396
1695
  }
1397
- return counts;
1696
+ if (!generative) return counts;
1697
+ const first = ((_state_waves_ = state.waves[0]) == null ? void 0 : _state_waves_.index) === wave.index && wave.frame;
1698
+ // Before the plan is in, a page it may propose is quoted, where the plan's count has room for one.
1699
+ const proposed = first && state.plan === undefined && choice.wording && aiSiteImportHasRoomForPage(state, {
1700
+ limit: state.pageLimit,
1701
+ used: state.existingPages
1702
+ }) ? 1 : 0;
1703
+ const pictures = choice.wording && aiSiteImportGeneratedPicturesOn(state) ? (counts.reworded + proposed) * AI_SITE_IMPORT_GENERATED_PICTURES_PER_PAGE : 0;
1704
+ return _extends({}, counts, {
1705
+ generative: true
1706
+ }, first && state.plan === undefined ? {
1707
+ plan: true
1708
+ } : {}, proposed ? {
1709
+ proposed
1710
+ } : {}, pictures ? {
1711
+ pictures
1712
+ } : {});
1713
+ }
1714
+ /**
1715
+ * Whether a wave is a generative Improve it (AGL-4152): as stamped once it has
1716
+ * started; before, whether the import was read under the flag and asks to be
1717
+ * improved now.
1718
+ */ export function aiSiteImportWaveIsGenerative(state, wave) {
1719
+ return wave.startedAt ? wave.generative === true : state.generative === true && aiSiteImportChoiceOf(state).finish === 'improve';
1398
1720
  }
1399
1721
  /** A wave's quote: the pages it has still to bring in, and its header and footer while they are owed. */ export function aiSiteImportWaveCreditRange(state, wave, items) {
1400
1722
  const owed = aiSiteImportWaveOwed(state, wave, items);
1401
- return aiSiteImportCreditRange(owed.pages, {
1723
+ return aiSiteImportCreditRange(owed.pages, _extends({
1402
1724
  frame: owed.frame,
1403
1725
  arranged: owed.arranged,
1404
1726
  reworded: owed.reworded,
1405
- copied: owed.copied
1406
- });
1727
+ copied: owed.copied,
1728
+ plan: owed.plan,
1729
+ proposed: owed.proposed,
1730
+ pictures: owed.pictures
1731
+ }, owed.generative ? {
1732
+ generative: true
1733
+ } : {}));
1407
1734
  }
1408
1735
  /** Every wave still waiting, quoted at once: "Start every remaining wave" (AGL-4083). */ export function aiSiteImportRemainingCreditRange(state, items) {
1409
1736
  const total = {
@@ -1411,9 +1738,14 @@ const whole = (value)=>Math.max(0, Math.floor(Number.isFinite(value) ? value : 0
1411
1738
  arranged: 0,
1412
1739
  reworded: 0,
1413
1740
  copied: 0,
1414
- frame: false
1741
+ frame: false,
1742
+ plan: false,
1743
+ proposed: 0,
1744
+ pictures: 0,
1745
+ generative: false
1415
1746
  };
1416
1747
  for (const wave of state.waves){
1748
+ var _owed_proposed, _owed_pictures;
1417
1749
  if (wave.status !== 'waiting') continue;
1418
1750
  const owed = aiSiteImportWaveOwed(state, wave, items);
1419
1751
  total.pages += owed.pages;
@@ -1421,24 +1753,34 @@ const whole = (value)=>Math.max(0, Math.floor(Number.isFinite(value) ? value : 0
1421
1753
  total.reworded += owed.reworded;
1422
1754
  total.copied += owed.copied;
1423
1755
  total.frame = total.frame || owed.frame;
1756
+ total.plan = total.plan || owed.plan === true;
1757
+ total.proposed += (_owed_proposed = owed.proposed) != null ? _owed_proposed : 0;
1758
+ total.pictures += (_owed_pictures = owed.pictures) != null ? _owed_pictures : 0;
1759
+ total.generative = total.generative || owed.generative === true;
1424
1760
  }
1425
- return aiSiteImportCreditRange(total.pages, {
1761
+ return aiSiteImportCreditRange(total.pages, _extends({
1426
1762
  frame: total.frame,
1427
1763
  arranged: total.arranged,
1428
1764
  reworded: total.reworded,
1429
- copied: total.copied
1430
- });
1765
+ copied: total.copied,
1766
+ plan: total.plan,
1767
+ proposed: total.proposed,
1768
+ pictures: total.pictures
1769
+ }, total.generative ? {
1770
+ generative: true
1771
+ } : {}));
1431
1772
  }
1432
1773
  /**
1433
1774
  * "About 95 credits (up to 600): 7 pages arranged by Aglyn AI, 3 copied as
1434
1775
  * they are"; the build is named once the step has chosen, and pages whose
1435
1776
  * words are improved too (AGL-4152) as "arranged and reworded by Aglyn AI".
1436
- */ export function aiSiteImportQuoteText(range, owed) {
1777
+ */ export function aiSiteImportQuoteText(range, owed, options = {}) {
1437
1778
  const reworded = Math.min(owed.arranged, whole(owed.reworded));
1438
1779
  const runs = [
1780
+ // Under a generative Improve it, a page redesigned from its ledger (AGL-4152).
1439
1781
  [
1440
1782
  reworded,
1441
- ()=>`arranged and reworded by ${PLATFORM_BRAND_NAME} AI`
1783
+ ()=>options.generative ? `redesigned by ${PLATFORM_BRAND_NAME} AI` : `arranged and reworded by ${PLATFORM_BRAND_NAME} AI`
1442
1784
  ],
1443
1785
  [
1444
1786
  owed.arranged - reworded,
@@ -1455,6 +1797,10 @@ const whole = (value)=>Math.max(0, Math.floor(Number.isFinite(value) ? value : 0
1455
1797
  // The first run names its pages; the rest are counted beside it.
1456
1798
  parts.push(`${parts.length ? count.toLocaleString('en-US') : aiSiteImportPagesText(count)} ${what(count)}`);
1457
1799
  }
1800
+ // What a generative Improve it adds (AGL-4152): its plan, the page it may propose, the pictures it may generate.
1801
+ if (owed.plan) parts.unshift('your site’s plan');
1802
+ if (owed.proposed) parts.push('a new page if the plan proposes one');
1803
+ if (owed.pictures) parts.push(`up to ${owed.pictures.toLocaleString('en-US')} generated pictures`);
1458
1804
  return parts.length ? `${aiCreditRangeText(range)}: ${parts.join(', ')}` : aiCreditRangeText(range);
1459
1805
  }
1460
1806
  /*------------------------------------------