@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
@@ -0,0 +1,627 @@
1
+ import { _ as _extends } from "@swc/helpers/_/_extends";
2
+ /**
3
+ * @license
4
+ * Copyright 2026 Aglyn LLC
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */ /*==========================================
18
+ * IMPROVE IT, GENERATIVE: THE SITE PLANNED ONCE (AGL-4152).
19
+ *
20
+ * A page redesigned on its own cannot reorganize a site. So before anything of
21
+ * it is built, one `submit_site_plan` answer reads what the first wave read and
22
+ * says what the site is, how its menu and footer are organized, where the
23
+ * header's main button goes, how the whole site is drawn, and at most one new
24
+ * page. Every wave's pages are then drawn to it, by code:
25
+ *
26
+ * - the header and footer from `plan.nav`, with no model
27
+ * (`aiSiteImportFrameSource`);
28
+ * - each page's hero, groups, rhythm and closing band from `plan.design`
29
+ * (`aiLayoutDesignChoices`), so the site reads as one design.
30
+ *
31
+ * The answer is held here: every page it names is a real page or the one it
32
+ * proposes, its main button goes somewhere real, nothing the old menu reached
33
+ * is left unreachable, and its words go through the honesty validator. An answer
34
+ * that misses twice, or is refused, is no plan: the import's own frame and
35
+ * design inputs stand, and its page says so.
36
+ *
37
+ * Nothing here runs with the flag off, or for Keep my site.
38
+ *=========================================*/ import { fenceUntrustedText, UNTRUSTED_TEXT_RULE } from "@aglyn/shared-util-tools/untrusted-text";
39
+ import { aiLayoutGuardContacts } from "../layout-language/ai-layout-copy.js";
40
+ import { AI_SITE_IMPORT_PAGE_ROLES, AI_SITE_IMPORT_PROPOSED_PAGE, aiSiteImportPageIsLegal } from "../model/ai-site-import.js";
41
+ import { AI_SITE_KINDS } from "../model/ai-site-kinds.js";
42
+ import { AI_STEP_TIERS } from "../providers/catalog.js";
43
+ import { runValidatedGeneration } from "../runtime/ai-doctrine.js";
44
+ import { aiGenerationMaxTokensWithin, aiJobStepBudget } from "./ai-job-budget.js";
45
+ import { AI_LAYOUT_LANGUAGE_THINKING } from "./ai-job-page-language.js";
46
+ import { AI_SITE_IMPORT_DROPPED_ITEM_CODE, AI_SITE_IMPORT_INVENTED_FACT_CODE, aiSiteImportHonestyFacts, aiSiteImportInventedIn } from "./ai-site-import-honesty.js";
47
+ const clean = (text)=>typeof text === 'string' ? text.replace(/\s+/g, ' ').trim() : '';
48
+ /** The answer's kind of generation: the name its re-ask and its doctrine scope go by. */ export const AI_SITE_IMPORT_PLAN_KIND = 'site-import-plan';
49
+ /** The heroes a plan may choose: those a page brought in can draw from one picture. */ export const AI_SITE_IMPORT_PLAN_HEROES = [
50
+ 'cover',
51
+ 'poster',
52
+ 'split',
53
+ 'bleed',
54
+ 'editorial',
55
+ 'column',
56
+ 'panel'
57
+ ];
58
+ /** The most top-level entries a planned menu holds: more reads as no plan at all. */ export const AI_SITE_IMPORT_PLAN_MAX_GROUPS = 6;
59
+ /** The most characters a menu's label holds, a heading of the footer, or the main button's. */ export const AI_SITE_IMPORT_PLAN_LABEL_MAX_CHARS = 28;
60
+ /** The most characters a proposed page's title holds: its search listing's ceiling. */ export const AI_SITE_IMPORT_PLAN_TITLE_MAX_CHARS = 60;
61
+ const GROUP_SCHEMA = {
62
+ type: 'object',
63
+ additionalProperties: false,
64
+ required: [
65
+ 'label',
66
+ 'pages'
67
+ ],
68
+ properties: {
69
+ label: {
70
+ type: 'string'
71
+ },
72
+ pages: {
73
+ type: 'array',
74
+ items: {
75
+ type: 'string'
76
+ }
77
+ }
78
+ }
79
+ };
80
+ /** The plan's tool: strict, every field always written. */ export const AI_SITE_IMPORT_PLAN_TOOL = {
81
+ name: 'submit_site_plan',
82
+ description: 'Submit the plan of the new site: what it is, its menu and footer, how it is drawn, and at most one new page.',
83
+ strict: true,
84
+ inputSchema: {
85
+ type: 'object',
86
+ additionalProperties: false,
87
+ required: [
88
+ 'site',
89
+ 'nav',
90
+ 'design',
91
+ 'proposed',
92
+ 'roles'
93
+ ],
94
+ properties: {
95
+ site: {
96
+ type: 'object',
97
+ additionalProperties: false,
98
+ required: [
99
+ 'what',
100
+ 'audience',
101
+ 'kind',
102
+ 'voice'
103
+ ],
104
+ properties: {
105
+ what: {
106
+ type: 'string'
107
+ },
108
+ audience: {
109
+ type: 'string'
110
+ },
111
+ kind: {
112
+ type: 'string',
113
+ enum: AI_SITE_KINDS.map((kind)=>kind.id)
114
+ },
115
+ voice: {
116
+ type: 'string'
117
+ }
118
+ }
119
+ },
120
+ nav: {
121
+ type: 'object',
122
+ additionalProperties: false,
123
+ required: [
124
+ 'groups',
125
+ 'cta',
126
+ 'footer'
127
+ ],
128
+ properties: {
129
+ groups: {
130
+ type: 'array',
131
+ items: GROUP_SCHEMA
132
+ },
133
+ cta: {
134
+ type: 'object',
135
+ additionalProperties: false,
136
+ required: [
137
+ 'label',
138
+ 'target'
139
+ ],
140
+ properties: {
141
+ label: {
142
+ type: 'string'
143
+ },
144
+ target: {
145
+ type: 'string'
146
+ }
147
+ }
148
+ },
149
+ footer: {
150
+ type: 'array',
151
+ items: GROUP_SCHEMA
152
+ }
153
+ }
154
+ },
155
+ design: {
156
+ type: 'object',
157
+ additionalProperties: false,
158
+ required: [
159
+ 'hero',
160
+ 'group',
161
+ 'rhythm',
162
+ 'cta'
163
+ ],
164
+ properties: {
165
+ hero: {
166
+ type: 'string',
167
+ enum: [
168
+ ...AI_SITE_IMPORT_PLAN_HEROES
169
+ ]
170
+ },
171
+ group: {
172
+ type: 'string',
173
+ enum: [
174
+ 'cards',
175
+ 'ruled',
176
+ 'icons'
177
+ ]
178
+ },
179
+ rhythm: {
180
+ type: 'string',
181
+ enum: [
182
+ 'alternate',
183
+ 'plain'
184
+ ]
185
+ },
186
+ cta: {
187
+ type: 'string',
188
+ enum: [
189
+ 'band',
190
+ 'photo'
191
+ ]
192
+ }
193
+ }
194
+ },
195
+ proposed: {
196
+ type: 'object',
197
+ additionalProperties: false,
198
+ required: [
199
+ 'title',
200
+ 'slug',
201
+ 'purpose'
202
+ ],
203
+ properties: {
204
+ title: {
205
+ type: 'string'
206
+ },
207
+ slug: {
208
+ type: 'string'
209
+ },
210
+ purpose: {
211
+ type: 'string'
212
+ }
213
+ }
214
+ },
215
+ roles: {
216
+ type: 'array',
217
+ items: {
218
+ type: 'object',
219
+ additionalProperties: false,
220
+ required: [
221
+ 'page',
222
+ 'role'
223
+ ],
224
+ properties: {
225
+ page: {
226
+ type: 'string'
227
+ },
228
+ role: {
229
+ type: 'string',
230
+ enum: [
231
+ ...AI_SITE_IMPORT_PAGE_ROLES
232
+ ]
233
+ }
234
+ }
235
+ }
236
+ }
237
+ }
238
+ }
239
+ };
240
+ /** What a plan is told, cached: every site shares these bytes. */ export const AI_SITE_IMPORT_PLAN_TEXT = [
241
+ "You plan the new website of a small business from what its existing website says. You are its information architect and art director: a visitor should find what they came for in one or two clicks, and the whole site should read as one confident design. The site's old menu is often just its pages in the order they were made. Reorganize it around what a visitor of this kind of business looks for. Answer with submit_site_plan.",
242
+ '',
243
+ 'site: what is one plain sentence saying what the business does; audience is one short phrase saying who it serves; kind is the kind of site this is; voice is a few plain words on how its writing sounds.',
244
+ '',
245
+ 'nav: the menu, the header\'s main button and the footer.',
246
+ `- groups are the menu, at most ${AI_SITE_IMPORT_PLAN_MAX_GROUPS} top-level entries, in the order a visitor needs them. An entry with one page is a link under that label; an entry with several is a menu of them under the label. Pages are named by id, as the page list gives them. Group like pages under a clear label rather than listing them all; never put the home page in the menu, since the logo goes home.`,
247
+ '- Every page the page list marks "in the menu" must stay reachable: in the menu or the footer. A policy page belongs in the footer.',
248
+ '- cta is the header\'s one filled button: the one thing a visitor of this business most wants to do. label is its words; target is a page by id, form for the page holding the site\'s form, or phone for the phone number the site gives. Only what the page list says exists.',
249
+ '- The page the main button goes to is never also a menu entry of its own: the button is its link. Put it in the footer.',
250
+ '- footer is its columns, each a short heading over the pages it links: two to four where there are pages enough, and one where the site has two or three pages, so the footer is never empty.',
251
+ `- Every label is short, at most ${AI_SITE_IMPORT_PLAN_LABEL_MAX_CHARS} characters, plain and in sentence case, so a capital reads as a name.`,
252
+ '',
253
+ 'design: how every page of the site is drawn, chosen once for the whole site from what it is and what it shows. hero: cover, a full-bleed photo with the words over it; poster, the same, taller and centered; split, the words beside a tall photo; bleed, half the band a photo; editorial, display type with a wide photo boxed under it; column, the words centered in a narrow column with a photo boxed under them; panel, the words on a card over a photo. Where the site opens on a wide photo of its work, its place or its people, lay the words over it (cover, poster, panel) or beside it (split, bleed); keep editorial and column for a site with no such photo. Choose a photo-led hero only where the site has photos worth it. group: how a set of services or reasons is drawn: cards, ruled columns, or icons. rhythm: alternate grounds between sections, or plain, one ground with space between. cta: the closing call to action on a strong band, or over a photo.',
254
+ '',
255
+ `roles: what each page of the list is for in the new site, by id, one of ${AI_SITE_IMPORT_PAGE_ROLES.join(', ')}: home for the home page; service for a page about what the business offers; contact for a page whose purpose is reaching it or booking; other where none fits. Every page redesigns to its role, so name each one.`,
256
+ '',
257
+ 'proposed: at most one new page the site lacks and a visitor of this kind of business looks for, such as common questions or how it works, named new in the menu or footer wherever it belongs. Propose one only where the request says there is room, and only what you can write without inventing a fact. title is at most 60 characters; slug is its address in lowercase words and hyphens; purpose is one sentence on what it tells a visitor. No page to propose: write all three as "".',
258
+ '',
259
+ 'Never write a name, number, price, date, testimonial, client, award, credential, address or guarantee the site does not give.'
260
+ ].join('\n');
261
+ /** A plan's system blocks: the platform's text, cached across sites. The site's own words ride the user turn. */ export function aiSiteImportPlanInstructions() {
262
+ return [
263
+ {
264
+ text: UNTRUSTED_TEXT_RULE
265
+ },
266
+ {
267
+ text: AI_SITE_IMPORT_PLAN_TEXT,
268
+ cacheBreakpoint: true
269
+ }
270
+ ];
271
+ }
272
+ /*------------------------------------------
273
+ * What the answer is told
274
+ *-----------------------------------------*/ /** The most characters of a site's own words the answer is told, about the site and about its pages. */ const SITE_MAX_CHARS = 6000;
275
+ const PAGES_MAX_CHARS = 12000;
276
+ /** The headings a page's line names. */ const HEADINGS_PER_PAGE = 8;
277
+ /** What one page tells the plan: its id, title, address, words and headings, and what it holds. */ function pageLine(page, required) {
278
+ var _ref, _ref1;
279
+ var _page_read, _page_read_forms, _page_read1, _page_read2;
280
+ const blocks = (_ref = (_page_read = page.read) == null ? void 0 : _page_read.blocks) != null ? _ref : [];
281
+ const headings = blocks.flatMap((block)=>block.kind === 'heading' && block.text.trim() ? [
282
+ clean(block.text)
283
+ ] : []).slice(0, HEADINGS_PER_PAGE);
284
+ const marks = [
285
+ ...required.has(page.draftId) ? [
286
+ 'in the menu'
287
+ ] : [],
288
+ ...((_page_read1 = page.read) == null ? void 0 : (_page_read_forms = _page_read1.forms) == null ? void 0 : _page_read_forms.length) ? [
289
+ 'holds a form'
290
+ ] : [],
291
+ ...aiSiteImportPageIsLegal(page) ? [
292
+ 'a policy'
293
+ ] : [],
294
+ ...page.group !== 'main' ? [
295
+ `in ${page.group}`
296
+ ] : []
297
+ ];
298
+ return `${page.draftId} | ${page.slug === '/' ? 'home' : `/${page.slug}`} | ${clean(page.title)} | ${((_ref1 = (_page_read2 = page.read) == null ? void 0 : _page_read2.words) != null ? _ref1 : page.words).toLocaleString('en-US')} words${marks.length ? ` | ${marks.join(', ')}` : ''}${headings.length ? ` | headings: ${headings.join('; ')}` : ''}`;
299
+ }
300
+ /** The pages a plan may name: every page the import brings in and can link. */ export function aiSiteImportPlanPages(state) {
301
+ return state.pages.filter((page)=>!page.refused);
302
+ }
303
+ /** A plan's user turn: what the site says of itself and its pages, fenced as the owner's data, and whether there is room for a new page. */ export function aiSiteImportPlanPrompt(input) {
304
+ var _state_home, _ref, _ref1;
305
+ const { state } = input;
306
+ const home = (_state_home = state.home) != null ? _state_home : null;
307
+ const required = new Set(input.required);
308
+ const phones = (_ref = home == null ? void 0 : home.facts.phones) != null ? _ref : [];
309
+ const said = [
310
+ `Name: ${clean(home == null ? void 0 : home.siteName) || clean(state.siteName)}`,
311
+ (home == null ? void 0 : home.title) ? `Title: ${clean(home.title)}` : '',
312
+ (home == null ? void 0 : home.description) ? `Description: ${clean(home.description)}` : '',
313
+ ...(_ref1 = home == null ? void 0 : home.facts.lines) != null ? _ref1 : [],
314
+ phones.length ? `Phone: ${phones[0]}` : ''
315
+ ].filter(Boolean);
316
+ return [
317
+ fenceUntrustedText(`What ${state.domain} says of itself`, said.join('\n'), {
318
+ maxChars: SITE_MAX_CHARS
319
+ }),
320
+ 'The page list, one a line: id | address | title | words | what it holds | headings.',
321
+ fenceUntrustedText('The pages', aiSiteImportPlanPages(state).map((page)=>pageLine(page, required)).join('\n'), {
322
+ maxChars: PAGES_MAX_CHARS
323
+ }),
324
+ input.roomForPage ? 'There is room for one new page.' : 'There is no room for a new page: write proposed as "".',
325
+ phones.length ? 'The site gives a phone number.' : 'The site gives no phone number: target may not be phone.'
326
+ ].join('\n');
327
+ }
328
+ /*------------------------------------------
329
+ * The answer held
330
+ *-----------------------------------------*/ const SLUG = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
331
+ const invented = (message)=>({
332
+ rule: 14,
333
+ code: AI_SITE_IMPORT_INVENTED_FACT_CODE,
334
+ message
335
+ });
336
+ const dropped = (message)=>({
337
+ rule: null,
338
+ code: AI_SITE_IMPORT_DROPPED_ITEM_CODE,
339
+ message
340
+ });
341
+ const unusable = (message)=>({
342
+ rule: null,
343
+ code: 'site-plan-unusable',
344
+ message
345
+ });
346
+ const record = (value)=>value && typeof value === 'object' ? value : {};
347
+ /** A list of groups, as an answer gives them. */ function groupsOf(value) {
348
+ return (Array.isArray(value) ? value : []).map((entry)=>{
349
+ const group = record(entry);
350
+ return {
351
+ label: clean(group['label']),
352
+ pages: (Array.isArray(group['pages']) ? group['pages'] : []).map(clean).filter(Boolean)
353
+ };
354
+ });
355
+ }
356
+ /** Every line of a site's first wave a plan's words are held to, with the page's own titles. */ export function aiSiteImportPlanScopeLines(state, siteLines) {
357
+ const read = state.pages.flatMap((page)=>{
358
+ var _ref;
359
+ var _page_read;
360
+ return [
361
+ page.title,
362
+ ...((_ref = (_page_read = page.read) == null ? void 0 : _page_read.blocks) != null ? _ref : []).flatMap((block)=>block.kind === 'image' ? [] : block.text.trim() ? [
363
+ block.text
364
+ ] : [])
365
+ ];
366
+ });
367
+ return [
368
+ ...siteLines,
369
+ ...read
370
+ ].map(clean).filter(Boolean);
371
+ }
372
+ /**
373
+ * A plan's answer read and held (AGL-4152): a plan to store, or what it broke,
374
+ * each named for the one re-ask. Its words are the honesty validator's: no name
375
+ * or fact the site does not give, in any label or line.
376
+ */ export function aiSiteImportPlanRead(raw, input) {
377
+ const answer = record(raw);
378
+ const site = record(answer['site']);
379
+ const nav = record(answer['nav']);
380
+ const cta = record(nav['cta']);
381
+ const design = record(answer['design']);
382
+ const proposedRaw = record(answer['proposed']);
383
+ const groups = groupsOf(nav['groups']);
384
+ const footer = groupsOf(nav['footer']);
385
+ const out = [];
386
+ const pages = aiSiteImportPlanPages(input.state);
387
+ const ids = new Set(pages.map((page)=>page.draftId));
388
+ const homeIds = new Set(pages.filter((page)=>page.slug === '/').map((page)=>page.draftId));
389
+ const title = clean(proposedRaw['title']);
390
+ const slug = clean(proposedRaw['slug']);
391
+ const purpose = clean(proposedRaw['purpose']);
392
+ const proposes = !!(title || slug || purpose);
393
+ if (proposes) {
394
+ if (!input.roomForPage) out.push(unusable('proposed: there is no room for a new page on this plan. Write title, slug and purpose as "".'));
395
+ if (!title || !purpose) out.push(unusable('proposed: a new page needs its title and its purpose, or all three written as "".'));
396
+ if (title.length > AI_SITE_IMPORT_PLAN_TITLE_MAX_CHARS) out.push(unusable(`proposed: its title is over ${AI_SITE_IMPORT_PLAN_TITLE_MAX_CHARS} characters.`));
397
+ if (!SLUG.test(slug)) out.push(unusable('proposed: its slug is lowercase words and hyphens only.'));
398
+ else if (pages.some((page)=>page.slug === slug || page.path.replace(/^\/+|\/+$/g, '') === slug)) out.push(unusable(`proposed: /${slug} is already a page of this site. Choose another address, or propose no page.`));
399
+ if (pages.some((page)=>clean(page.title).toLowerCase() === title.toLowerCase())) out.push(unusable(`proposed: "${title.slice(0, 60)}" is already a page of this site.`));
400
+ }
401
+ const entry = (name, page)=>{
402
+ if (page === AI_SITE_IMPORT_PROPOSED_PAGE) {
403
+ if (!proposes) out.push(unusable(`${name}: it names the new page, and proposed is empty.`));
404
+ } else if (!ids.has(page)) out.push(unusable(`${name}: "${page.slice(0, 40)}" is not a page of this site. Name pages by the ids the page list gives.`));
405
+ };
406
+ if (!groups.length) out.push(unusable('nav.groups: a menu needs at least one entry.'));
407
+ if (groups.length > AI_SITE_IMPORT_PLAN_MAX_GROUPS) out.push(unusable(`nav.groups: at most ${AI_SITE_IMPORT_PLAN_MAX_GROUPS} top-level entries.`));
408
+ for (const [where, list] of [
409
+ [
410
+ 'nav.groups',
411
+ groups
412
+ ],
413
+ [
414
+ 'nav.footer',
415
+ footer
416
+ ]
417
+ ]){
418
+ list.forEach((group, index)=>{
419
+ const name = `${where}[${index}]`;
420
+ if (!group.label) out.push(unusable(`${name}: it needs a label.`));
421
+ if (group.label.length > AI_SITE_IMPORT_PLAN_LABEL_MAX_CHARS) out.push(unusable(`${name}: "${group.label.slice(0, 40)}" is over ${AI_SITE_IMPORT_PLAN_LABEL_MAX_CHARS} characters.`));
422
+ if (!group.pages.length) out.push(unusable(`${name}: it links no page.`));
423
+ for (const page of group.pages)entry(name, page);
424
+ });
425
+ }
426
+ groups.forEach((group, index)=>{
427
+ if (group.pages.some((page)=>homeIds.has(page))) out.push(unusable(`nav.groups[${index}]: the home page is not in the menu: the logo goes home.`));
428
+ });
429
+ const placed = new Set([
430
+ ...groups,
431
+ ...footer
432
+ ].flatMap((group)=>group.pages));
433
+ for (const page of input.required){
434
+ if (!placed.has(page) && !homeIds.has(page)) {
435
+ var _ref;
436
+ var _pages_find;
437
+ const named = (_ref = (_pages_find = pages.find((other)=>other.draftId === page)) == null ? void 0 : _pages_find.title) != null ? _ref : page;
438
+ out.push(dropped(`"${named.slice(0, 60)}" is in the old menu and nowhere in the new one. Put it in the menu or the footer.`));
439
+ }
440
+ }
441
+ if (proposes && !placed.has(AI_SITE_IMPORT_PROPOSED_PAGE)) out.push(dropped('The new page is linked from nowhere. Put new in the menu or the footer.'));
442
+ // The header's one filled button goes somewhere real.
443
+ const ctaLabel = clean(cta['label']);
444
+ const target = clean(cta['target']);
445
+ let ctaPage;
446
+ if (!ctaLabel || !target) out.push(unusable('nav.cta: the header needs its main button, with its words and where it goes.'));
447
+ else {
448
+ if (ctaLabel.length > AI_SITE_IMPORT_PLAN_LABEL_MAX_CHARS) out.push(unusable(`nav.cta: "${ctaLabel.slice(0, 40)}" is over ${AI_SITE_IMPORT_PLAN_LABEL_MAX_CHARS} characters.`));
449
+ if (target === 'form') {
450
+ var _pages_find1;
451
+ ctaPage = (_pages_find1 = pages.find((page)=>{
452
+ var _page_read_forms, _page_read;
453
+ return (_page_read = page.read) == null ? void 0 : (_page_read_forms = _page_read.forms) == null ? void 0 : _page_read_forms.some((form)=>form.fields.length);
454
+ })) == null ? void 0 : _pages_find1.draftId;
455
+ if (!ctaPage) out.push(unusable('nav.cta: no page of this site holds a form. Send the button to a page, or to phone.'));
456
+ } else if (target === 'phone') {
457
+ var _input_state_home;
458
+ if (!((_input_state_home = input.state.home) == null ? void 0 : _input_state_home.facts.phones.length)) out.push(unusable('nav.cta: the site gives no phone number. Send the button to a page.'));
459
+ } else if (target !== AI_SITE_IMPORT_PROPOSED_PAGE || !proposes) entry('nav.cta', target);
460
+ }
461
+ const kind = clean(site['kind']);
462
+ if (!AI_SITE_KINDS.some((entry)=>entry.id === kind)) out.push(unusable('site.kind: one of the kinds the tool lists.'));
463
+ const what = clean(site['what']);
464
+ const audience = clean(site['audience']);
465
+ if (!what || !audience) out.push(unusable('site: what and audience are each a line, never empty.'));
466
+ const hero = AI_SITE_IMPORT_PLAN_HEROES.find((value)=>value === design['hero']);
467
+ const group = [
468
+ 'cards',
469
+ 'ruled',
470
+ 'icons'
471
+ ].find((value)=>value === design['group']);
472
+ const rhythm = [
473
+ 'alternate',
474
+ 'plain'
475
+ ].find((value)=>value === design['rhythm']);
476
+ const closing = [
477
+ 'band',
478
+ 'photo'
479
+ ].find((value)=>value === design['cta']);
480
+ if (!hero || !group || !rhythm || !closing) out.push(unusable('design: hero, group, rhythm and cta are each one of the values the tool lists.'));
481
+ // Every word held to what the site says.
482
+ const held = aiSiteImportHonestyFacts(input.scope);
483
+ const contacts = input.scope.join(' \n ');
484
+ const lines = [
485
+ [
486
+ 'site.what',
487
+ what
488
+ ],
489
+ [
490
+ 'site.audience',
491
+ audience
492
+ ],
493
+ [
494
+ 'site.voice',
495
+ clean(site['voice'])
496
+ ],
497
+ [
498
+ 'nav.cta',
499
+ ctaLabel
500
+ ],
501
+ ...groups.map((entry, index)=>[
502
+ `nav.groups[${index}]`,
503
+ entry.label
504
+ ]),
505
+ ...footer.map((entry, index)=>[
506
+ `nav.footer[${index}]`,
507
+ entry.label
508
+ ]),
509
+ [
510
+ 'proposed.title',
511
+ title
512
+ ],
513
+ [
514
+ 'proposed.purpose',
515
+ purpose
516
+ ]
517
+ ];
518
+ for (const [where, text] of lines){
519
+ if (!text) continue;
520
+ const reason = aiSiteImportInventedIn(text, held);
521
+ if (reason) out.push(invented(`${where}, "${text.slice(0, 80)}": ${reason}`));
522
+ else if (aiLayoutGuardContacts(text, contacts) !== text) out.push(invented(`${where}, "${text.slice(0, 80)}": it gives a phone number or email the site does not.`));
523
+ }
524
+ if (out.length || !hero || !group || !rhythm || !closing) return {
525
+ plan: null,
526
+ violations: out
527
+ };
528
+ // What each page is for (AGL-4152): a role it does not know, or a page that is none of the site's, is left to the page.
529
+ const roles = {};
530
+ for (const entry of Array.isArray(answer['roles']) ? answer['roles'] : []){
531
+ const named = record(entry);
532
+ const page = clean(named['page']);
533
+ const role = AI_SITE_IMPORT_PAGE_ROLES.find((value)=>value === named['role']);
534
+ if (role && (ids.has(page) || page === AI_SITE_IMPORT_PROPOSED_PAGE && proposes)) roles[page] = role;
535
+ }
536
+ return {
537
+ plan: _extends({
538
+ site: {
539
+ what,
540
+ audience,
541
+ kind,
542
+ voice: clean(site['voice'])
543
+ },
544
+ nav: {
545
+ groups,
546
+ primaryCta: _extends({
547
+ label: ctaLabel,
548
+ target
549
+ }, ctaPage ? {
550
+ page: ctaPage
551
+ } : {}),
552
+ footer
553
+ },
554
+ design: {
555
+ hero,
556
+ group,
557
+ rhythm,
558
+ cta: closing
559
+ },
560
+ proposed: proposes ? {
561
+ title,
562
+ slug,
563
+ purpose,
564
+ on: true
565
+ } : null
566
+ }, Object.keys(roles).length ? {
567
+ roles
568
+ } : {}),
569
+ violations: []
570
+ };
571
+ }
572
+ /** A plan's check, answer by answer, for the one re-ask. */ export function aiSiteImportPlanCheck(input) {
573
+ return (answer)=>{
574
+ const { plan, violations } = aiSiteImportPlanRead(answer, input);
575
+ return plan ? {
576
+ value: plan,
577
+ violations: []
578
+ } : {
579
+ value: null,
580
+ violations
581
+ };
582
+ };
583
+ }
584
+ /*------------------------------------------
585
+ * The answer asked
586
+ *-----------------------------------------*/ /** The most tokens a plan's answer asks, with its thinking. */ export const AI_SITE_IMPORT_PLAN_MOST_TOKENS = 4000;
587
+ /** The least time a plan's pass needs: its answer and its one re-ask on the page step's tier. */ export const AI_SITE_IMPORT_PLAN_BUDGET = aiJobStepBudget({
588
+ tier: AI_STEP_TIERS['job.page'],
589
+ maxTokens: AI_SITE_IMPORT_PLAN_MOST_TOKENS
590
+ });
591
+ /** The ceiling a plan is asked at on this model. */ export function aiSiteImportPlanMaxTokens(model) {
592
+ return aiGenerationMaxTokensWithin({
593
+ model,
594
+ budgetMs: AI_SITE_IMPORT_PLAN_BUDGET.minimumMs,
595
+ cap: AI_SITE_IMPORT_PLAN_MOST_TOKENS,
596
+ lookups: 0
597
+ });
598
+ }
599
+ /** The one plan a generative Improve it asks for, on the page step's tier. */ export async function aiRunSiteImportPlan(input) {
600
+ return runValidatedGeneration(AI_SITE_IMPORT_PLAN_KIND, _extends({
601
+ step: 'job.page',
602
+ model: input.model,
603
+ instructions: aiSiteImportPlanInstructions(),
604
+ messages: [
605
+ {
606
+ role: 'user',
607
+ content: aiSiteImportPlanPrompt({
608
+ state: input.state,
609
+ required: input.required,
610
+ roomForPage: input.roomForPage
611
+ })
612
+ }
613
+ ],
614
+ tool: AI_SITE_IMPORT_PLAN_TOOL,
615
+ maxTokens: aiSiteImportPlanMaxTokens(input.model),
616
+ cutOff: {
617
+ noun: 'plan',
618
+ smaller: 'Write shorter lines.'
619
+ }
620
+ }, AI_LAYOUT_LANGUAGE_THINKING, {
621
+ check: aiSiteImportPlanCheck(input)
622
+ }, input.signal ? {
623
+ signal: input.signal
624
+ } : {}));
625
+ }
626
+
627
+ //# sourceMappingURL=ai-site-import-plan.js.map