@aglyn/plugins-ai 1.0.0-beta.285 → 1.0.0-beta.288
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +17 -17
- package/src/lib/assets/site-styles/nonprofit.webp +0 -0
- package/src/lib/assets/site-styles/professional.webp +0 -0
- package/src/lib/assets/site-styles/store.webp +0 -0
- package/src/lib/assets/site-styles/trades.webp +0 -0
- package/src/lib/components/ai-theme-proposal-card.component.js +12 -3
- package/src/lib/components/ai-theme-proposal-card.component.js.map +1 -1
- package/src/lib/declarations.js +5 -2
- package/src/lib/declarations.js.map +1 -1
- package/src/lib/declarations.server.js +12 -0
- package/src/lib/declarations.server.js.map +1 -1
- package/src/lib/jobs/ai-build-capabilities.d.ts +3 -1
- package/src/lib/jobs/ai-build-capabilities.js +27 -2
- package/src/lib/jobs/ai-build-capabilities.js.map +1 -1
- package/src/lib/jobs/ai-business-profile-prefill.js +6 -3
- package/src/lib/jobs/ai-business-profile-prefill.js.map +1 -1
- package/src/lib/jobs/ai-image-reads.d.ts +59 -0
- package/src/lib/jobs/ai-image-reads.js +138 -0
- package/src/lib/jobs/ai-image-reads.js.map +1 -0
- package/src/lib/jobs/ai-job-build-step.d.ts +29 -0
- package/src/lib/jobs/ai-job-build-step.js +83 -12
- package/src/lib/jobs/ai-job-build-step.js.map +1 -1
- package/src/lib/jobs/ai-job-duplicate-step.d.ts +2 -1
- package/src/lib/jobs/ai-job-duplicate-step.js +6 -6
- package/src/lib/jobs/ai-job-duplicate-step.js.map +1 -1
- package/src/lib/jobs/ai-job-import-step.d.ts +4 -2
- package/src/lib/jobs/ai-job-import-step.js +15 -11
- package/src/lib/jobs/ai-job-import-step.js.map +1 -1
- package/src/lib/jobs/ai-job-insight-step.d.ts +10 -0
- package/src/lib/jobs/ai-job-insight-step.js +23 -5
- package/src/lib/jobs/ai-job-insight-step.js.map +1 -1
- package/src/lib/jobs/ai-job-layout-language.js +2 -1
- package/src/lib/jobs/ai-job-layout-language.js.map +1 -1
- package/src/lib/jobs/ai-job-media-step.d.ts +2 -1
- package/src/lib/jobs/ai-job-media-step.js +6 -8
- package/src/lib/jobs/ai-job-media-step.js.map +1 -1
- package/src/lib/jobs/ai-job-navigation-step.d.ts +2 -1
- package/src/lib/jobs/ai-job-navigation-step.js +7 -9
- package/src/lib/jobs/ai-job-navigation-step.js.map +1 -1
- package/src/lib/jobs/ai-job-page-language.js +7 -1
- package/src/lib/jobs/ai-job-page-language.js.map +1 -1
- package/src/lib/jobs/ai-job-page-sections.js +16 -3
- package/src/lib/jobs/ai-job-page-sections.js.map +1 -1
- package/src/lib/jobs/ai-job-page-step.js +9 -1
- package/src/lib/jobs/ai-job-page-step.js.map +1 -1
- package/src/lib/jobs/ai-job-plan-step.d.ts +30 -8
- package/src/lib/jobs/ai-job-plan-step.js +78 -13
- package/src/lib/jobs/ai-job-plan-step.js.map +1 -1
- package/src/lib/jobs/ai-job-privacy-step.d.ts +4 -2
- package/src/lib/jobs/ai-job-privacy-step.js +14 -15
- package/src/lib/jobs/ai-job-privacy-step.js.map +1 -1
- package/src/lib/jobs/ai-job-products-step.js +5 -3
- package/src/lib/jobs/ai-job-products-step.js.map +1 -1
- package/src/lib/jobs/ai-job-settings-step.d.ts +2 -1
- package/src/lib/jobs/ai-job-settings-step.js +7 -8
- package/src/lib/jobs/ai-job-settings-step.js.map +1 -1
- package/src/lib/jobs/ai-job-site-content.d.ts +34 -1
- package/src/lib/jobs/ai-job-site-content.js +67 -8
- package/src/lib/jobs/ai-job-site-content.js.map +1 -1
- package/src/lib/jobs/ai-job-site-datasets.d.ts +53 -3
- package/src/lib/jobs/ai-job-site-datasets.js +300 -30
- package/src/lib/jobs/ai-job-site-datasets.js.map +1 -1
- package/src/lib/jobs/ai-job-site-step.js +6 -3
- package/src/lib/jobs/ai-job-site-step.js.map +1 -1
- package/src/lib/jobs/ai-job-site-store-pages.js +3 -3
- package/src/lib/jobs/ai-job-site-store-pages.js.map +1 -1
- package/src/lib/jobs/ai-job-text-step.js +2 -1
- package/src/lib/jobs/ai-job-text-step.js.map +1 -1
- package/src/lib/jobs/ai-job-tracking-step.d.ts +2 -1
- package/src/lib/jobs/ai-job-tracking-step.js +7 -8
- package/src/lib/jobs/ai-job-tracking-step.js.map +1 -1
- package/src/lib/jobs/ai-jobs-beat.d.ts +11 -7
- package/src/lib/jobs/ai-jobs-beat.js +18 -8
- package/src/lib/jobs/ai-jobs-beat.js.map +1 -1
- package/src/lib/jobs/ai-jobs-notify.d.ts +66 -1
- package/src/lib/jobs/ai-jobs-notify.js +136 -3
- package/src/lib/jobs/ai-jobs-notify.js.map +1 -1
- package/src/lib/jobs/ai-layout-stock-photos.d.ts +155 -7
- package/src/lib/jobs/ai-layout-stock-photos.js +1517 -220
- package/src/lib/jobs/ai-layout-stock-photos.js.map +1 -1
- package/src/lib/jobs/ai-product-image.d.ts +14 -0
- package/src/lib/jobs/ai-product-image.js +73 -21
- package/src/lib/jobs/ai-product-image.js.map +1 -1
- package/src/lib/jobs/ai-theme-brand-inputs.d.ts +9 -1
- package/src/lib/jobs/ai-theme-brand-inputs.js +28 -2
- package/src/lib/jobs/ai-theme-brand-inputs.js.map +1 -1
- package/src/lib/jobs/fixtures/ai-site-agl4065-datasets.d.ts +175 -0
- package/src/lib/jobs/fixtures/ai-site-agl4065-datasets.js +601 -0
- package/src/lib/jobs/fixtures/ai-site-agl4065-datasets.js.map +1 -0
- package/src/lib/jobs/fixtures/ai-site-agl4065-pages.d.ts +46 -0
- package/src/lib/jobs/fixtures/ai-site-agl4065-pages.js +2862 -0
- package/src/lib/jobs/fixtures/ai-site-agl4065-pages.js.map +1 -0
- package/src/lib/jobs/fixtures/ai-site-agl4065-plans.d.ts +74 -0
- package/src/lib/jobs/fixtures/ai-site-agl4065-plans.js +888 -0
- package/src/lib/jobs/fixtures/ai-site-agl4065-plans.js.map +1 -0
- package/src/lib/jobs/fixtures/ai-site-agl4092-datasets.d.ts +120 -0
- package/src/lib/jobs/fixtures/ai-site-agl4092-datasets.js +410 -0
- package/src/lib/jobs/fixtures/ai-site-agl4092-datasets.js.map +1 -0
- package/src/lib/jobs/fixtures/ai-stock-photo-agl4065-judge.d.ts +29 -0
- package/src/lib/jobs/fixtures/ai-stock-photo-agl4065-judge.js +81 -0
- package/src/lib/jobs/fixtures/ai-stock-photo-agl4065-judge.js.map +1 -0
- package/src/lib/jobs/fixtures/ai-stock-photo-agl4065-recordings.d.ts +87 -0
- package/src/lib/jobs/fixtures/ai-stock-photo-agl4065-recordings.js +225 -0
- package/src/lib/jobs/fixtures/ai-stock-photo-agl4065-recordings.js.map +1 -0
- package/src/lib/jobs/fixtures/ai-stock-photo-agl4092-recordings.d.ts +26 -0
- package/src/lib/jobs/fixtures/ai-stock-photo-agl4092-recordings.js +714 -0
- package/src/lib/jobs/fixtures/ai-stock-photo-agl4092-recordings.js.map +1 -0
- package/src/lib/layout-language/ai-layout-compiler.d.ts +11 -0
- package/src/lib/layout-language/ai-layout-compiler.js +194 -18
- package/src/lib/layout-language/ai-layout-compiler.js.map +1 -1
- package/src/lib/layout-language/ai-layout-copy.d.ts +37 -0
- package/src/lib/layout-language/ai-layout-copy.js +383 -3
- package/src/lib/layout-language/ai-layout-copy.js.map +1 -1
- package/src/lib/layout-language/ai-layout-design.d.ts +19 -0
- package/src/lib/layout-language/ai-layout-design.js +31 -11
- package/src/lib/layout-language/ai-layout-design.js.map +1 -1
- package/src/lib/layout-language/ai-layout-listings.d.ts +7 -1
- package/src/lib/layout-language/ai-layout-listings.js +9 -1
- package/src/lib/layout-language/ai-layout-listings.js.map +1 -1
- package/src/lib/layout-language/ai-layout-pictures.d.ts +39 -1
- package/src/lib/layout-language/ai-layout-pictures.js +141 -4
- package/src/lib/layout-language/ai-layout-pictures.js.map +1 -1
- package/src/lib/layout-language/ai-layout-storefront.d.ts +18 -4
- package/src/lib/layout-language/ai-layout-storefront.js +100 -20
- package/src/lib/layout-language/ai-layout-storefront.js.map +1 -1
- package/src/lib/model/ai-build-job.d.ts +7 -0
- package/src/lib/model/ai-build-job.js +36 -7
- package/src/lib/model/ai-build-job.js.map +1 -1
- package/src/lib/model/ai-build-plan.d.ts +28 -4
- package/src/lib/model/ai-build-plan.js +49 -9
- package/src/lib/model/ai-build-plan.js.map +1 -1
- package/src/lib/model/ai-build-progress.js +3 -1
- package/src/lib/model/ai-build-progress.js.map +1 -1
- package/src/lib/model/ai-job-notice.d.ts +8 -0
- package/src/lib/model/ai-job-notice.js +33 -0
- package/src/lib/model/ai-job-notice.js.map +1 -1
- package/src/lib/model/ai-job-plan-lines.d.ts +2 -1
- package/src/lib/model/ai-job-plan-lines.js +6 -1
- package/src/lib/model/ai-job-plan-lines.js.map +1 -1
- package/src/lib/model/ai-jobs.types.d.ts +8 -0
- package/src/lib/model/ai-jobs.types.js.map +1 -1
- package/src/lib/model/ai-permissions.d.ts +13 -0
- package/src/lib/model/ai-permissions.js +29 -1
- package/src/lib/model/ai-permissions.js.map +1 -1
- package/src/lib/model/ai-plan-said-sections.d.ts +12 -3
- package/src/lib/model/ai-plan-said-sections.js +22 -5
- package/src/lib/model/ai-plan-said-sections.js.map +1 -1
- package/src/lib/model/ai-products.d.ts +18 -0
- package/src/lib/model/ai-products.js +32 -0
- package/src/lib/model/ai-products.js.map +1 -1
- package/src/lib/model/ai-site-context.d.ts +6 -2
- package/src/lib/model/ai-site-context.js +8 -2
- package/src/lib/model/ai-site-context.js.map +1 -1
- package/src/lib/model/ai-site-inspiration.d.ts +3 -2
- package/src/lib/model/ai-site-inspiration.js +3 -2
- package/src/lib/model/ai-site-inspiration.js.map +1 -1
- package/src/lib/plugin.js +4 -13
- package/src/lib/plugin.js.map +1 -1
- package/src/lib/providers/anthropic.js +9 -2
- package/src/lib/providers/anthropic.js.map +1 -1
- package/src/lib/providers/catalog.js +14 -5
- package/src/lib/providers/catalog.js.map +1 -1
- package/src/lib/providers/contract.d.ts +24 -1
- package/src/lib/providers/contract.js.map +1 -1
- package/src/lib/providers/routing.js +5 -2
- package/src/lib/providers/routing.js.map +1 -1
- package/src/lib/runtime/ai-dataset-generation.d.ts +120 -1
- package/src/lib/runtime/ai-dataset-generation.js +352 -3
- package/src/lib/runtime/ai-dataset-generation.js.map +1 -1
- package/src/lib/runtime/ai-dev-replay.d.ts +1 -0
- package/src/lib/runtime/ai-dev-replay.js +4 -2
- package/src/lib/runtime/ai-dev-replay.js.map +1 -1
- package/src/lib/runtime/ai-doctrine-validators.d.ts +47 -3
- package/src/lib/runtime/ai-doctrine-validators.js +345 -28
- package/src/lib/runtime/ai-doctrine-validators.js.map +1 -1
- package/src/lib/runtime/ai-doctrine.d.ts +5 -4
- package/src/lib/runtime/ai-doctrine.js +10 -3
- package/src/lib/runtime/ai-doctrine.js.map +1 -1
- package/src/lib/runtime/ai-icon-library.d.ts +27 -1
- package/src/lib/runtime/ai-icon-library.js +30 -3
- package/src/lib/runtime/ai-icon-library.js.map +1 -1
- package/src/lib/runtime/ai-products-generation.d.ts +11 -1
- package/src/lib/runtime/ai-products-generation.js +51 -4
- package/src/lib/runtime/ai-products-generation.js.map +1 -1
- package/src/lib/runtime/assist-answer-cache.d.ts +2 -0
- package/src/lib/runtime/assist-answer-cache.js +5 -2
- package/src/lib/runtime/assist-answer-cache.js.map +1 -1
- package/src/lib/server/ai-allotments.js +7 -2
- package/src/lib/server/ai-allotments.js.map +1 -1
- package/src/lib/server/ai-experiment-versions.js +5 -5
- package/src/lib/server/ai-experiment-versions.js.map +1 -1
- package/src/lib/server/ai-host-permissions-roster.d.ts +25 -0
- package/src/lib/server/ai-host-permissions-roster.js +33 -0
- package/src/lib/server/ai-host-permissions-roster.js.map +1 -0
- package/src/lib/server/ai-host-permissions.js +8 -6
- package/src/lib/server/ai-host-permissions.js.map +1 -1
- package/src/lib/server/ai-image-reads-route.d.ts +17 -0
- package/src/lib/server/ai-image-reads-route.js +106 -0
- package/src/lib/server/ai-image-reads-route.js.map +1 -0
- package/src/lib/server/ai-seo-apply.js +5 -5
- package/src/lib/server/ai-seo-apply.js.map +1 -1
- package/src/lib/server/ai-site-import-route.js +7 -4
- package/src/lib/server/ai-site-import-route.js.map +1 -1
- package/src/lib/server/assist-build.d.ts +15 -1
- package/src/lib/server/assist-build.js +30 -3
- package/src/lib/server/assist-build.js.map +1 -1
- package/src/lib/server/assist-chat.d.ts +11 -7
- package/src/lib/server/assist-chat.js +185 -48
- package/src/lib/server/assist-chat.js.map +1 -1
- package/src/lib/server/assist-docs-query.d.ts +51 -0
- package/src/lib/server/assist-docs-query.js +57 -0
- package/src/lib/server/assist-docs-query.js.map +1 -0
- package/src/lib/server/assist-jobs-context.d.ts +102 -0
- package/src/lib/server/assist-jobs-context.js +227 -0
- package/src/lib/server/assist-jobs-context.js.map +1 -0
- package/src/lib/server/assist-view-context.d.ts +8 -4
- package/src/lib/server/assist-view-context.js +12 -7
- package/src/lib/server/assist-view-context.js.map +1 -1
- package/src/lib/server.js +12 -0
- package/src/lib/server.js.map +1 -1
- package/src/lib/tools/ai-dataset-tool.d.ts +11 -1
- package/src/lib/tools/ai-dataset-tool.js +24 -7
- package/src/lib/tools/ai-dataset-tool.js.map +1 -1
- package/src/lib/tools/ai-duplicate-resource-tool.js +5 -6
- package/src/lib/tools/ai-duplicate-resource-tool.js.map +1 -1
- package/src/lib/components/ai-collaborator-permissions-column.component.d.ts +0 -32
- package/src/lib/components/ai-collaborator-permissions-column.component.js +0 -132
- package/src/lib/components/ai-collaborator-permissions-column.component.js.map +0 -1
|
@@ -65,6 +65,16 @@ import { AI_CREDIT_RANGE_ZERO, AI_MEASURED_PASS_CREDITS, aiCreditRangeAdd, aiCre
|
|
|
65
65
|
'page',
|
|
66
66
|
...AI_BUILD_CREATE_KINDS
|
|
67
67
|
];
|
|
68
|
+
/**
|
|
69
|
+
* The operation that proposes a change to the site's theme (AGL-4077): the
|
|
70
|
+
* theme runner's proposal, which the owner applies in Setup → Theme. Planned
|
|
71
|
+
* as an item; a plan that names it as its `theme-change` creation, the
|
|
72
|
+
* doctrine's word for it, is built by the same operation rather than refused.
|
|
73
|
+
*/ export const AI_BUILD_THEME_OP = 'theme';
|
|
74
|
+
/** The creations a build builds as units: its structural kinds, and a theme change, as the theme operation. */ const AI_BUILD_UNIT_CREATE_KINDS = [
|
|
75
|
+
...AI_BUILD_CREATE_KINDS,
|
|
76
|
+
'theme-change'
|
|
77
|
+
];
|
|
68
78
|
/**
|
|
69
79
|
* What a build hands an item it made before it (AGL-3728): its pages, by the
|
|
70
80
|
* title the plan gave each and the id it was written under, and its layouts,
|
|
@@ -72,13 +82,13 @@ import { AI_CREDIT_RANGE_ZERO, AI_MEASURED_PASS_CREDITS, aiCreditRangeAdd, aiCre
|
|
|
72
82
|
*/ export const AI_BUILD_MADE_INPUT = 'buildMade';
|
|
73
83
|
/** The job input a build's Assist proposal sets when the brief asked to publish. */ export const AI_BUILD_PUBLISH_INPUT = 'publish';
|
|
74
84
|
/** The operation a creation is built as. */ function creationOp(creation) {
|
|
75
|
-
return creation.kind;
|
|
85
|
+
return creation.kind === 'theme-change' ? AI_BUILD_THEME_OP : creation.kind;
|
|
76
86
|
}
|
|
77
87
|
/** A plan's `new:<name>` names, each to the slot that builds it. */ function namedSlots(plan) {
|
|
78
88
|
var _plan_items;
|
|
79
89
|
const slots = new Map();
|
|
80
90
|
plan.create.forEach((creation, index)=>{
|
|
81
|
-
if (
|
|
91
|
+
if (AI_BUILD_UNIT_CREATE_KINDS.includes(creation.kind)) slots.set(creation.name.toLowerCase(), `c${index}`);
|
|
82
92
|
});
|
|
83
93
|
for (const item of (_plan_items = plan.items) != null ? _plan_items : [])slots.set(item.name.toLowerCase(), item.slot);
|
|
84
94
|
return slots;
|
|
@@ -146,7 +156,7 @@ import { AI_CREDIT_RANGE_ZERO, AI_MEASURED_PASS_CREDITS, aiCreditRangeAdd, aiCre
|
|
|
146
156
|
const units = [];
|
|
147
157
|
plan.create.forEach((creation, index)=>{
|
|
148
158
|
var _creation_writesTo;
|
|
149
|
-
if (!
|
|
159
|
+
if (!AI_BUILD_UNIT_CREATE_KINDS.includes(creation.kind)) return;
|
|
150
160
|
const slot = `c${index}`;
|
|
151
161
|
// A form is built after the dataset it writes to (AGL-3616).
|
|
152
162
|
units.push({
|
|
@@ -267,20 +277,28 @@ import { AI_CREDIT_RANGE_ZERO, AI_MEASURED_PASS_CREDITS, aiCreditRangeAdd, aiCre
|
|
|
267
277
|
if (slugs.has(slug)) return `Two pages in this plan share the address ${screen.slug}.`;
|
|
268
278
|
slugs.add(slug);
|
|
269
279
|
}
|
|
280
|
+
const ops = options.ops;
|
|
270
281
|
for (const creation of plan.create){
|
|
271
|
-
if (
|
|
272
|
-
|
|
282
|
+
if (AI_BUILD_CREATE_KINDS.includes(creation.kind)) continue;
|
|
283
|
+
if (creation.kind !== 'theme-change') {
|
|
284
|
+
return `A build does not create ${creation.kind}s (“${creation.name}”). Take it out of create.`;
|
|
273
285
|
}
|
|
286
|
+
// A theme change is the theme operation's (AGL-4077), held as its item would be.
|
|
287
|
+
const refusal = aiBuildThemeRefusal(creation.name, 'create', options);
|
|
288
|
+
if (refusal) return refusal;
|
|
274
289
|
}
|
|
275
290
|
const graph = aiBuildGraphProblems(plan);
|
|
276
291
|
if (graph.length) return graph[0];
|
|
277
|
-
const ops = options.ops;
|
|
278
292
|
const counts = new Map();
|
|
279
293
|
for (const unit of units)counts.set(unit.op, ((_counts_get = counts.get(unit.op)) != null ? _counts_get : 0) + 1);
|
|
280
294
|
for (const item of (_plan_items = plan.items) != null ? _plan_items : []){
|
|
281
295
|
if (AI_BUILD_STRUCTURAL_OPS.includes(item.op)) {
|
|
282
296
|
return item.op === 'page' ? `“${item.name}” is a page: plan it in screens, not items.` : `“${item.name}” is ${item.op === 'email' ? 'an' : 'a'} ${item.op}: plan it in create, not items.`;
|
|
283
297
|
}
|
|
298
|
+
if (item.op === AI_BUILD_THEME_OP) {
|
|
299
|
+
const refusal = aiBuildThemeRefusal(item.name, 'items', options);
|
|
300
|
+
if (refusal) return refusal;
|
|
301
|
+
}
|
|
284
302
|
if (!ops) continue;
|
|
285
303
|
const capability = ops.get(item.op);
|
|
286
304
|
if (!capability) return `Nothing on this site can make “${item.name}” (${item.op}). Take it out of items.`;
|
|
@@ -300,6 +318,17 @@ import { AI_CREDIT_RANGE_ZERO, AI_MEASURED_PASS_CREDITS, aiCreditRangeAdd, aiCre
|
|
|
300
318
|
}
|
|
301
319
|
return null;
|
|
302
320
|
}
|
|
321
|
+
/**
|
|
322
|
+
* Why a build cannot make this theme change (AGL-4077), naming the list the
|
|
323
|
+
* plan put it in; `null` when it can, or when there are no operations to
|
|
324
|
+
* judge it against. The Free taste is named for what it is: its operations
|
|
325
|
+
* never hold the theme operation, which only paid plans are offered.
|
|
326
|
+
*/ function aiBuildThemeRefusal(name, list, options) {
|
|
327
|
+
if (!options.ops) return null;
|
|
328
|
+
if (options.freeTaste) return `A Free workspace cannot have a theme change made (“${name}”). Take it out of ${list}.`;
|
|
329
|
+
if (!options.ops.has(AI_BUILD_THEME_OP)) return `Nothing on this site can make “${name}” (theme change). Take it out of ${list}.`;
|
|
330
|
+
return null;
|
|
331
|
+
}
|
|
303
332
|
/**
|
|
304
333
|
* What the person must still say before this plan can be built, as the
|
|
305
334
|
* questions its operations ask (`missingInput`), or `null` when nothing is
|
|
@@ -458,7 +487,7 @@ import { AI_CREDIT_RANGE_ZERO, AI_MEASURED_PASS_CREDITS, aiCreditRangeAdd, aiCre
|
|
|
458
487
|
}
|
|
459
488
|
if (keep.size === units.length) return null;
|
|
460
489
|
const screen = plan.screens[index];
|
|
461
|
-
const create = plan.create.filter((creation, at)=>!
|
|
490
|
+
const create = plan.create.filter((creation, at)=>!AI_BUILD_UNIT_CREATE_KINDS.includes(creation.kind) || keep.has(`c${at}`));
|
|
462
491
|
const items = ((_plan_items = plan.items) != null ? _plan_items : []).filter((item)=>keep.has(item.slot));
|
|
463
492
|
const kept = new Set([
|
|
464
493
|
screen.slug,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/model/ai-build-job.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n pluginAiCapabilityArgsProblems,\n type PluginAiCapability,\n} from '@aglyn/aglyn/plugin-manager/plugin-ai-capabilities'\nimport type { PluginDraftRecord } from '@aglyn/aglyn/plugin-manager/plugin-resource-drafts'\nimport {\n AI_PLAN_NEW_REF_PREFIX,\n isAiPlanNewRef,\n type AiBuildItem,\n type AiBuildPlan,\n type AiBuildPlanCreate,\n type AiBuildPlanCreateKind,\n type AiBuildPlanScreen,\n} from './ai-build-plan'\nimport type { AiJobInputField, AiJobItemLedger, AiJobItemStatus } from './ai-jobs.types'\nimport {\n AI_BUILD_STORE_OP,\n AI_BUILD_STORE_PAGES_LABEL,\n AI_BUILD_STORE_SLOT,\n aiBuildMakesStore,\n aiBuildStorePagesAdded,\n} from './ai-build-store-pages'\nimport {\n AI_SITE_HOME_FIRST_LABEL,\n AI_SITE_MAX_SECTIONS,\n AI_SITE_PASS_CREDITS,\n aiCreationMeasuredCredits,\n aiJobPlanCreditEstimate,\n aiJobPlanCreditRange,\n aiSitePlanIsHome,\n aiStandaloneScreenCreditRange,\n} from './ai-site-job'\nimport {\n AI_CREDIT_RANGE_ZERO,\n AI_MEASURED_PASS_CREDITS,\n aiCreditRangeAdd,\n aiCreditRangeOf,\n aiCreditRangeOrdered,\n type AiCreditRange,\n type AiCreditsSmaller,\n} from './ai-credit-estimate'\n\n/**\n * What a `build` job is (AGL-3616): one request — \"a few pages, a contact\n * form and a way to book me\" — planned as creations, pages and items, built\n * one UNIT a pass in dependency order, and settled ITEM BY ITEM.\n *\n * A build is a generalized site scaffold. Every unit is handed to what\n * already builds that kind of thing — a page to the page step, a form to the\n * form step, another plugin's resource to that plugin's draft writer — so a\n * build cannot drift from what it builds. What is new is the settlement: one\n * failed unit does not end the job. It gives back its own spend, the units\n * that depended on it are built without it (or skipped, when they cannot\n * stand without it), and the job is `done` when anything was delivered.\n *\n * This module is the build's MODEL — its units, their order, how a failure\n * travels to what depends on it, what it is estimated to cost, and the\n * ledger arithmetic — and does no I/O, so the step, the machine, the doors\n * and the console read one vocabulary.\n */\n\n/** How much one build holds: what one proposal can describe and one person can read. */\nexport const AI_BUILD_LIMITS = {\n /** Creations, pages and items together. */\n units: 16,\n pages: 8,\n /** A Free workspace's pages. */\n freePages: 2,\n} as const\n\n/**\n * What a Free build's plan card says when it holds as many pages as a Free\n * build makes (AGL-3722): the plan is told the cap and plans the first pages\n * a request asks for, so a request for three — \"About us, Custom cakes and\n * Catering\", 2026-10-10 — came back as two with nothing saying why. `null`\n * when the plan holds fewer, or on a paid workspace.\n */\nexport function aiBuildFreePageCapNote(plan: Pick<AiBuildPlan, 'screens'>, freeTaste: boolean): string | null {\n const cap = AI_BUILD_LIMITS.freePages\n if (!freeTaste || plan.screens.length < cap) return null\n return `A Free workspace’s build makes up to ${cap} pages at a time. If you asked for more, ask Assist for the rest once this build is done.`\n}\n\n/** What a build creates through its `create` list; everything else beyond pages is an item. */\nexport const AI_BUILD_CREATE_KINDS: readonly AiBuildPlanCreateKind[] = ['layout', 'form', 'component', 'email']\n\n/**\n * The operations a build plans through `create` and `screens` rather than\n * `items`: an item naming one is a plan that put it in the wrong list.\n */\nexport const AI_BUILD_STRUCTURAL_OPS: readonly string[] = ['page', ...AI_BUILD_CREATE_KINDS]\n\n/**\n * What a build hands an item it made before it (AGL-3728): its pages, by the\n * title the plan gave each and the id it was written under, and its layouts,\n * by name. An item's `new:<title>` destinations are read against it.\n */\nexport const AI_BUILD_MADE_INPUT = 'buildMade'\n\nexport interface AiBuildMade {\n pages: Array<{ title: string; id: string }>\n layouts: Array<{ name: string; id: string }>\n}\n\n/** The job input a build's Assist proposal sets when the brief asked to publish. */\nexport const AI_BUILD_PUBLISH_INPUT = 'publish'\n\n/** A unit of a build: a creation, a page, or an item. */\nexport interface AiBuildUnit {\n slot: string\n /** The capability operation that builds it. */\n op: string\n label: string\n creation?: AiBuildPlanCreate\n screen?: AiBuildPlanScreen\n item?: AiBuildItem\n /** The slots it is built after, in plan order. */\n deps: string[]\n}\n\n/** The operation a creation is built as. */\nfunction creationOp(creation: AiBuildPlanCreate): string {\n return creation.kind\n}\n\n/** A plan's `new:<name>` names, each to the slot that builds it. */\nfunction namedSlots(plan: AiBuildPlan): Map<string, string> {\n const slots = new Map<string, string>()\n plan.create.forEach((creation, index) => {\n if (AI_BUILD_CREATE_KINDS.includes(creation.kind)) slots.set(creation.name.toLowerCase(), `c${index}`)\n })\n for (const item of plan.items ?? []) slots.set(item.name.toLowerCase(), item.slot)\n return slots\n}\n\n/** The name a `new:<name>` reference gives, lowercased. */\nexport function aiBuildRefName(ref: string): string {\n return ref.slice(AI_PLAN_NEW_REF_PREFIX.length).trim().toLowerCase()\n}\n\n/**\n * The `new:<name>` references an item's arguments make (AGL-3728): an\n * argument that is one, or the destination after `=>` in an entry such as a\n * menu item's `About => new:About`. Read from the arguments, never from the\n * model's `dependsOn`, so what an item links is always built before it.\n */\nexport function aiBuildItemArgRefs(args: Readonly<Record<string, unknown>> | null | undefined): string[] {\n const refs: string[] = []\n const take = (value: unknown) => {\n if (typeof value !== 'string') return\n for (const part of [value, value.split('=>').slice(-1)[0] ?? '']) {\n const ref = part.trim()\n if (isAiPlanNewRef(ref) && !refs.includes(ref)) refs.push(ref)\n }\n }\n for (const value of Object.values(args ?? {})) {\n if (Array.isArray(value)) value.forEach(take)\n else take(value)\n }\n return refs\n}\n\n/** Every reference a page makes: its layout, template, starting page and what its sections place. */\nexport function aiBuildScreenRefs(screen: AiBuildPlanScreen): string[] {\n return [\n screen.layout,\n screen.template,\n screen.duplicateOf,\n ...screen.sections.flatMap((section) => section.uses),\n ].filter((ref): ref is string => typeof ref === 'string' && ref.length > 0)\n}\n\n/**\n * The units a plan implies, in plan order: creations, then items, then\n * pages — the order a member reads them in, and the one a page that places\n * a creation or an item is built after anyway. `aiBuildOrder` sorts them on\n * their dependencies.\n */\nexport function aiBuildUnits(plan: AiBuildPlan): AiBuildUnit[] {\n const slots = namedSlots(plan)\n // A page, by the title the plan gave it: what an item's arguments may link\n // as `new:<title>` (a menu item, AGL-3728), built before the item.\n const pageSlots = new Map<string, string>()\n plan.screens.forEach((screen, index) => {\n const title = screen.title.trim().toLowerCase()\n if (title && !pageSlots.has(title)) pageSlots.set(title, `p${index}`)\n })\n const depsOf = (refs: readonly (string | null)[], self: string, pages = false): string[] => {\n const deps: string[] = []\n for (const ref of refs) {\n if (!isAiPlanNewRef(ref)) continue\n const slot = slots.get(aiBuildRefName(ref)) ?? (pages ? pageSlots.get(aiBuildRefName(ref)) : undefined)\n if (slot && slot !== self && !deps.includes(slot)) deps.push(slot)\n }\n return deps\n }\n const units: AiBuildUnit[] = []\n plan.create.forEach((creation, index) => {\n if (!AI_BUILD_CREATE_KINDS.includes(creation.kind)) return\n const slot = `c${index}`\n // A form is built after the dataset it writes to (AGL-3616).\n units.push({\n slot,\n op: creationOp(creation),\n label: creation.name,\n creation,\n deps: depsOf([creation.duplicateOf, creation.kind === 'form' ? (creation.writesTo ?? null) : null], slot),\n })\n })\n for (const item of plan.items ?? []) {\n units.push({\n slot: item.slot,\n op: item.op,\n label: item.name,\n item,\n // What it depends on, and what its arguments link as `new:` (AGL-3728).\n deps: depsOf([...item.dependsOn, ...aiBuildItemArgRefs(item.args)], item.slot, true),\n })\n }\n plan.screens.forEach((screen, index) => {\n const slot = `p${index}`\n units.push({ slot, op: 'page', label: screen.title, screen, deps: depsOf(aiBuildScreenRefs(screen), slot) })\n })\n // A store's own pages (AGL-3676), added by the platform: last, so every\n // planned page keeps the first claim on the site's pages allowance.\n if (aiBuildStorePagesAdded(plan).length) {\n units.push({ slot: AI_BUILD_STORE_SLOT, op: AI_BUILD_STORE_OP, label: AI_BUILD_STORE_PAGES_LABEL, deps: [] })\n }\n return units\n}\n\n/** Whether a unit is one the platform adds rather than the plan (AGL-3676): a store's own pages. */\nexport function aiBuildUnitIsPlatform(unit: Pick<AiBuildUnit, 'op'>): boolean {\n return unit.op === AI_BUILD_STORE_OP\n}\n\n/**\n * The units in an order that builds every dependency before what depends on\n * it, plan order otherwise; `null` when the dependencies hold a cycle.\n */\nexport function aiBuildOrder(units: readonly AiBuildUnit[]): AiBuildUnit[] | null {\n const ordered: AiBuildUnit[] = []\n const placed = new Set<string>()\n const known = new Set(units.map((unit) => unit.slot))\n while (ordered.length < units.length) {\n const next = units.find(\n (unit) => !placed.has(unit.slot) && unit.deps.every((dep) => placed.has(dep) || !known.has(dep)),\n )\n if (!next) return null\n ordered.push(next)\n placed.add(next.slot)\n }\n return ordered\n}\n\n/**\n * What is wrong with a plan's references as a build reads them: a\n * `new:<name>` an item depends on that nothing in the plan makes, and a\n * cycle. Each is a sentence the plan's one re-ask carries.\n */\nexport function aiBuildGraphProblems(plan: AiBuildPlan): string[] {\n const problems: string[] = []\n const slots = namedSlots(plan)\n for (const item of plan.items ?? []) {\n for (const ref of item.dependsOn) {\n if (!isAiPlanNewRef(ref)) continue\n if (!slots.has(aiBuildRefName(ref))) {\n problems.push(`The item \"${item.name}\" depends on ${ref}, which the plan never makes. Declare it, or take it out of dependsOn.`)\n } else if (aiBuildRefName(ref) === item.name.toLowerCase()) {\n problems.push(`The item \"${item.name}\" depends on itself. Take it out of its own dependsOn.`)\n }\n }\n }\n if (!aiBuildOrder(aiBuildUnits(plan))) {\n problems.push('The plan’s dependencies go round in a circle, so nothing in the circle can be built first. Make one of them depend on nothing.')\n }\n return problems\n}\n\n/** The operations a build may plan, as the registry and the gates left them, by op. */\nexport type AiBuildOps = ReadonlyMap<string, PluginAiCapability>\n\n/** How many pages a build may hold on this workspace. */\nexport function aiBuildPageLimit(freeTaste: boolean | null | undefined): number {\n return freeTaste ? AI_BUILD_LIMITS.freePages : AI_BUILD_LIMITS.pages\n}\n\n/**\n * Why a build cannot build a plan of this shape, in a sentence a member\n * reads; `null` when it can. Held to the plan with the one re-ask (the plan\n * step's scope), and again by the doors before a confirmed plan runs.\n * `ops` is what may be planned on this site; absent, items are not judged\n * against the registry (a console reading a kept plan).\n */\nexport function aiBuildPlanShapeRefusal(\n plan: AiBuildPlan,\n options: { freeTaste?: boolean; ops?: AiBuildOps } = {},\n): string | null {\n // What the platform adds beside the plan (a store's own pages) is no part of its size.\n const units = aiBuildUnits(plan).filter((unit) => !aiBuildUnitIsPlatform(unit))\n if (!units.length) return 'This plan builds nothing. Describe what to build again.'\n if (units.length > AI_BUILD_LIMITS.units) {\n return `This plan builds ${units.length} things, and one build holds ${AI_BUILD_LIMITS.units}. Ask for the rest in a second request.`\n }\n const pages = aiBuildPageLimit(options.freeTaste)\n if (plan.screens.length > pages) {\n return options.freeTaste\n ? `This plan builds ${plan.screens.length} pages, and a Free workspace's build makes at most ${pages}. Paid plans can build more.`\n : `This plan builds ${plan.screens.length} pages, and one build makes at most ${pages}.`\n }\n const slugs = new Set<string>()\n for (const screen of plan.screens) {\n if (!screen.sections.length) return `The page “${screen.title}” has no sections to build.`\n if (screen.sections.length > AI_SITE_MAX_SECTIONS) {\n return `The page “${screen.title}” has ${screen.sections.length} sections, and a built page holds ${AI_SITE_MAX_SECTIONS}.`\n }\n const slug = screen.slug.trim().toLowerCase()\n if (slugs.has(slug)) return `Two pages in this plan share the address ${screen.slug}.`\n slugs.add(slug)\n }\n for (const creation of plan.create) {\n if (!AI_BUILD_CREATE_KINDS.includes(creation.kind)) {\n return `A build does not create ${creation.kind === 'theme-change' ? 'theme changes' : `${creation.kind}s`} (“${creation.name}”). Take it out of create.`\n }\n }\n const graph = aiBuildGraphProblems(plan)\n if (graph.length) return graph[0]\n const ops = options.ops\n const counts = new Map<string, number>()\n for (const unit of units) counts.set(unit.op, (counts.get(unit.op) ?? 0) + 1)\n for (const item of plan.items ?? []) {\n if (AI_BUILD_STRUCTURAL_OPS.includes(item.op)) {\n return item.op === 'page'\n ? `“${item.name}” is a page: plan it in screens, not items.`\n : `“${item.name}” is ${item.op === 'email' ? 'an' : 'a'} ${item.op}: plan it in create, not items.`\n }\n if (!ops) continue\n const capability = ops.get(item.op)\n if (!capability) return `Nothing on this site can make “${item.name}” (${item.op}). Take it out of items.`\n if (options.freeTaste && !capability.freeAllowed) {\n return `A Free workspace cannot have ${aiArticle(capability.noun)} made (“${item.name}”). Take it out of items.`\n }\n const problems = pluginAiCapabilityArgsProblems(capability.argsSchema, item.args)\n if (problems.length) return `The arguments of “${item.name}” do not read: ${problems.join('; ')}.`\n }\n if (ops) {\n for (const [op, count] of counts) {\n const capability = ops.get(op)\n if (capability && count > capability.maxPerPlan) {\n return `This plan makes ${count} of “${capability.noun}”, and one build makes at most ${capability.maxPerPlan}.`\n }\n }\n }\n return null\n}\n\n/**\n * What the person must still say before this plan can be built, as the\n * questions its operations ask (`missingInput`), or `null` when nothing is\n * missing: an item the planner kept with nothing it may build from — a\n * tracking change naming no id, AGL-3751 — is asked about, never built\n * empty or from a value the planner made up. Not a plan rule: a re-ask\n * cannot supply what only the person knows, so the plan is not kept and\n * the build answers with the question.\n */\nexport function aiBuildPlanMissingInput(plan: AiBuildPlan, ops: AiBuildOps | null | undefined): string | null {\n if (!ops) return null\n const questions: string[] = []\n for (const item of plan.items ?? []) {\n const question = ops.get(item.op)?.missingInput?.({ name: item.name, why: item.why, args: item.args })\n if (question && !questions.includes(question)) questions.push(question)\n }\n return questions.length ? questions.join(' ') : null\n}\n\n/**\n * The code on the build's admission refusal for a plan only the person can\n * complete (AGL-3978): the plan step keeps such a plan and waits in\n * `needs_input` for the fields `aiBuildPlanInputFields` reads, where the\n * operations describe them.\n */\nexport const AI_BUILD_NEEDS_INPUT_CODE = 'needs-input'\n\n/**\n * The fields the person fills before this plan can be built (AGL-3978), one\n * per id an item asks for, as its operation describes them (`inputFields`).\n * Empty when nothing asks, or when an item asks without fields to fill — a\n * tracking change naming no tag at all — which the build answers with its\n * question instead.\n */\nexport function aiBuildPlanInputFields(plan: AiBuildPlan, ops: AiBuildOps | null | undefined): AiJobInputField[] {\n if (!ops) return []\n const fields: AiJobInputField[] = []\n for (const item of plan.items ?? []) {\n const capability = ops.get(item.op)\n const one = { name: item.name, why: item.why, args: item.args }\n if (!capability?.missingInput?.(one)) continue\n const asked = capability.inputFields?.(one) ?? []\n if (!asked.length) return []\n for (const field of asked) {\n fields.push({ item: item.name, arg: field.arg, label: field.label, shape: field.shape, pattern: field.pattern.source })\n }\n }\n return fields\n}\n\n/** \"a booking service\", \"an email design\". */\nexport function aiArticle(noun: string): string {\n return `${/^[aeiou]/i.test(noun) ? 'an' : 'a'} ${noun}`\n}\n\n/** The passes one unit is estimated at: a page's sections and its listing, one for a creation. */\nfunction unitPasses(unit: AiBuildUnit): number {\n if (unit.screen) return unit.screen.sections.length + 1\n return 1\n}\n\n/**\n * About what one unit costs, in credits: a page or a creation by the passes\n * it implies at the nominal credits a pass is held against, as a site's are;\n * an item by its capability's own estimate, recorded on the plan when it was\n * kept.\n */\nexport function aiBuildUnitCreditEstimate(unit: AiBuildUnit, ops?: AiBuildOps): number {\n // A store's own pages are written by code, with no model: no credits (AGL-3676).\n if (aiBuildUnitIsPlatform(unit)) return 0\n if (unit.item) {\n if (typeof unit.item.credits === 'number') return unit.item.credits\n const capability = ops?.get(unit.item.op)\n if (capability) return Math.max(0, Math.floor(capability.estimateCredits(unit.item.args)))\n return AI_SITE_PASS_CREDITS\n }\n return unitPasses(unit) * AI_SITE_PASS_CREDITS\n}\n\n/**\n * About what a build costs, in credits: every unit's estimate, or only the\n * units named in `slots` — what Try again shows. The ceiling a member\n * confirms; the meter charges what actually runs.\n */\nexport function aiBuildCreditEstimate(\n plan: AiBuildPlan,\n options: { ops?: AiBuildOps; slots?: ReadonlySet<string> } = {},\n): number {\n return aiBuildUnits(plan)\n .filter((unit) => !options.slots || options.slots.has(unit.slot))\n .reduce((total, unit) => total + aiBuildUnitCreditEstimate(unit, options.ops), 0)\n}\n\n/**\n * About what a job of this kind costs to build from its plan: a build's\n * units, every other planned kind as `aiJobPlanCreditEstimate` counts it.\n */\nexport function aiJobCreditEstimate(kind: string, plan: AiBuildPlan): number {\n return kind === 'build' ? aiBuildCreditEstimate(plan) : aiJobPlanCreditEstimate(kind, plan)\n}\n\n/**\n * What one unit is likely to cost, its p90 and its ceiling (AGL-3722): a page\n * as a page written on its own measured (a fixed cost and one per section), a creation at what its kind\n * measured, an item at the measured pass times the passes its capability\n * estimates (none for a draft another plugin writes, which asks no model).\n * The ceiling is `aiBuildUnitCreditEstimate`, unchanged.\n */\nexport function aiBuildUnitCreditRange(unit: AiBuildUnit, ops?: AiBuildOps): AiCreditRange {\n const ceiling = aiBuildUnitCreditEstimate(unit, ops)\n // A build writes each page on its own, never in a site start's warm run (AGL-3722).\n if (unit.screen) return aiStandaloneScreenCreditRange(unit.screen.sections.length)\n if (unit.creation) return aiCreditRangeOf(aiCreationMeasuredCredits(unit.creation.kind, { standalone: true }), ceiling)\n const passes = Math.ceil(ceiling / AI_SITE_PASS_CREDITS)\n return aiCreditRangeOf(\n { median: passes * AI_MEASURED_PASS_CREDITS.median, p90: passes * AI_MEASURED_PASS_CREDITS.p90 },\n ceiling,\n )\n}\n\n/**\n * What a build is likely to cost, its p90 and its ceiling (AGL-3722): every\n * unit's range, or only the units named in `slots` — what Try again runs.\n * The plan card, Try again and the Free admission all read this; the meter\n * charges what actually runs.\n */\nexport function aiBuildCreditRange(\n plan: AiBuildPlan,\n options: { ops?: AiBuildOps; slots?: ReadonlySet<string> } = {},\n): AiCreditRange {\n return aiCreditRangeOrdered(\n aiBuildUnits(plan)\n .filter((unit) => !options.slots || options.slots.has(unit.slot))\n .reduce((total, unit) => aiCreditRangeAdd(total, aiBuildUnitCreditRange(unit, options.ops)), AI_CREDIT_RANGE_ZERO),\n )\n}\n\n/** `aiJobCreditEstimate` as a range (AGL-3722). */\nexport function aiJobCreditRange(kind: string, plan: AiBuildPlan): AiCreditRange {\n return kind === 'build' ? aiBuildCreditRange(plan) : aiJobPlanCreditRange(kind, plan)\n}\n\n/**\n * A smaller first build (AGL-3722): the plan's home page — its first page\n * where it has no home — and only what that page needs, transitively: the\n * layout it is drawn in, the form and anything else its sections place.\n * Every other page, and what only they needed, waits for a later request.\n * `null` when the plan has no page, or when the smaller plan is the whole one.\n */\nexport function aiBuildFirstPagePlan<T extends AiBuildPlan>(plan: T): T | null {\n if (!plan.screens.length) return null\n const index = Math.max(0, plan.screens.findIndex(aiSitePlanIsHome))\n const units = aiBuildUnits(plan).filter((unit) => !aiBuildUnitIsPlatform(unit))\n const bySlot = new Map(units.map((unit) => [unit.slot, unit]))\n const keep = new Set<string>()\n const queue = [`p${index}`]\n while (queue.length) {\n const slot = queue.shift() as string\n if (keep.has(slot)) continue\n keep.add(slot)\n for (const dep of bySlot.get(slot)?.deps ?? []) queue.push(dep)\n }\n if (keep.size === units.length) return null\n const screen = plan.screens[index]\n const create = plan.create.filter((creation, at) => !AI_BUILD_CREATE_KINDS.includes(creation.kind) || keep.has(`c${at}`))\n const items = (plan.items ?? []).filter((item) => keep.has(item.slot))\n const kept = new Set([screen.slug, ...create.map((entry) => `${AI_PLAN_NEW_REF_PREFIX}${entry.name}`)])\n const smaller: T = {\n ...plan,\n create,\n screens: [screen],\n ...(plan.items ? { items } : {}),\n ...(plan.embeds ? { embeds: plan.embeds.filter((embed) => kept.has(embed.where)) } : {}),\n }\n // The store's own pages stay only while the smaller build still makes a store (AGL-3676).\n if (smaller.storePages && !aiBuildMakesStore(smaller)) delete smaller.storePages\n return smaller\n}\n\n/** The smaller first build a build that does not fit is offered (AGL-3722), with its range; `null` when there is none. */\nexport function aiBuildSmaller(plan: AiBuildPlan, ops?: AiBuildOps): AiCreditsSmaller | null {\n const smaller = aiBuildFirstPagePlan(plan)\n if (!smaller) return null\n const screen = smaller.screens[0]\n const label = aiSitePlanIsHome(screen) ? AI_SITE_HOME_FIRST_LABEL : `Build the ${screen.title} page first`\n return { label, ...aiBuildCreditRange(smaller, { ops }) }\n}\n\n/** A fresh ledger: one pending row per unit, first attempt. */\nexport function aiBuildInitialLedger(units: readonly AiBuildUnit[]): AiJobItemLedger[] {\n return units.map((unit) => ({\n slot: unit.slot,\n op: unit.op,\n label: unit.label,\n status: 'pending',\n attempt: 1,\n creditsSpent: 0,\n attemptCredits: 0,\n creditsRefunded: 0,\n failure: null,\n outputs: [],\n }))\n}\n\nconst OPEN: readonly AiJobItemStatus[] = ['pending', 'running']\n\n/** Whether an item is still to be built. */\nexport function aiBuildItemOpen(row: Pick<AiJobItemLedger, 'status'>): boolean {\n return OPEN.includes(row.status)\n}\n\n/** Whether an item delivered: built as planned, or built without something that failed. */\nexport function aiBuildItemDelivered(row: Pick<AiJobItemLedger, 'status'>): boolean {\n return row.status === 'succeeded' || row.status === 'degraded'\n}\n\n/**\n * The next unit to build: the first in build order whose row is still open.\n * Its dependencies come before it, so by then each is settled one way or the\n * other. `null` when nothing is left.\n */\nexport function aiBuildNextUnit(\n ordered: readonly AiBuildUnit[],\n ledger: readonly AiJobItemLedger[],\n): AiBuildUnit | null {\n const rows = new Map(ledger.map((row) => [row.slot, row]))\n return ordered.find((unit) => {\n const row = rows.get(unit.slot)\n return !row || aiBuildItemOpen(row)\n }) ?? null\n}\n\n/** How a unit is built given what its dependencies came to. */\nexport interface AiBuildDegradation {\n /** The unit is not built at all, with the sentence why; nothing is spent. */\n skip: string | null\n /** The failed dependencies that change how it is built. */\n degradedBy: string[]\n /** What the person reads about the change; one per failed dependency. */\n notes: string[]\n /** `new:<name>` references (lowercased names) to leave out. */\n dropped: Set<string>\n /** Brief lines for the unit's own job: what to leave out, and what to place. */\n briefLines: string[]\n}\n\n/**\n * How a unit is built when some of what it depends on failed (AGL-3616).\n *\n * A PAGE is always built: a failed layout falls back to the site's own, a\n * failed form or component is left out of its section, and a failed item a\n * section places (a booking service) takes its block out of the page — each\n * with a note. Any OTHER unit whose dependency failed is skipped when that\n * dependency's capability says `omit` (a campaign whose email design failed\n * has nothing to send), and built without it when it says `fallback`.\n */\nexport function aiBuildDegradation(\n unit: AiBuildUnit,\n context: {\n units: readonly AiBuildUnit[]\n ledger: readonly AiJobItemLedger[]\n ops?: AiBuildOps\n },\n): AiBuildDegradation {\n const rows = new Map(context.ledger.map((row) => [row.slot, row]))\n const bySlot = new Map(context.units.map((one) => [one.slot, one]))\n const result: AiBuildDegradation = { skip: null, degradedBy: [], notes: [], dropped: new Set(), briefLines: [] }\n for (const slot of unit.deps) {\n const dep = bySlot.get(slot)\n const row = rows.get(slot)\n if (!dep || !row || aiBuildItemDelivered(row)) continue\n const noun = dep.creation\n ? aiBuildCreationNoun(dep.creation.kind)\n : (context.ops?.get(dep.op)?.noun ?? dep.op)\n const capability = dep.item ? context.ops?.get(dep.op) : undefined\n const degrade = dep.item?.degrade ?? capability?.degrade ?? (dep.creation?.kind === 'layout' ? 'fallback' : 'omit')\n // A form whose dataset could not be made is built without it (AGL-3616):\n // its submissions reach the Inbox, as any form's do.\n if (aiBuildUnitWritesTo(unit) === dep.label.toLowerCase()) {\n result.degradedBy.push(slot)\n result.notes.push(`Its submissions arrive in the Inbox only: the dataset “${dep.label}” could not be created.`)\n continue\n }\n // An item that links pages this build makes (a menu's entries, AGL-3728)\n // is built with the ones it made and without the ones it could not\n // (AGL-3832), and skipped only when it made none of them.\n const madeAPage = unit.deps.some((one) => {\n const made = rows.get(one)\n return !!bySlot.get(one)?.screen && !!made && aiBuildItemDelivered(made)\n })\n if (!unit.screen && dep.screen && madeAPage) {\n result.degradedBy.push(slot)\n result.dropped.add(dep.label.toLowerCase())\n result.notes.push(`Built without the ${noun} “${dep.label}”: it could not be created.`)\n continue\n }\n if (!unit.screen && degrade === 'omit') {\n result.skip = `Not built: the ${noun} “${dep.label}” it needs could not be created.`\n result.degradedBy.push(slot)\n return result\n }\n result.degradedBy.push(slot)\n result.dropped.add(dep.label.toLowerCase())\n if (dep.creation?.kind === 'layout') {\n result.notes.push(`Built inside the site’s own layout: the layout “${dep.label}” could not be created.`)\n continue\n }\n if (unit.screen) {\n const section = unit.screen.sections.find((one) =>\n one.uses.some((ref) => isAiPlanNewRef(ref) && aiBuildRefName(ref) === dep.label.toLowerCase()),\n )\n // Another item this section places with the same block was built (one\n // of several events, AGL-3743): the block stays, and only this item is\n // missing from what it shows.\n const blockStays = Boolean(\n section &&\n capability?.pageBlocks?.length &&\n aiBuildSectionDeliveredBlocks(section, { ...context, rows, except: slot }).has(aiBuildBlocksKey(capability.pageBlocks)),\n )\n if (blockStays) {\n result.notes.push(`Built without the ${noun} “${dep.label}”: it could not be created.`)\n result.briefLines.push(`Leave the ${noun} “${dep.label}” out of the “${section?.name}” section: it could not be created.`)\n continue\n }\n const blocks = capability?.pageBlocks?.length ? ` the ${capability.pageBlocks.join(' or ')} block` : ''\n result.notes.push(\n `Built without${blocks || ` the ${noun}`}: the ${noun} “${dep.label}” could not be created.`,\n )\n result.briefLines.push(\n `${section ? `Build the “${section.name}” section` : 'Build the page'} without the ${noun} “${dep.label}”${blocks ? ` and without${blocks}` : ''}: it could not be created.`,\n )\n } else {\n result.notes.push(`Built without the ${noun} “${dep.label}”: it could not be created.`)\n }\n }\n return result\n}\n\n/** The dataset a form unit writes to, by its `new:` name lowercased; `null` for any other unit (AGL-3616). */\nexport function aiBuildUnitWritesTo(unit: Pick<AiBuildUnit, 'creation'>): string | null {\n const ref = unit.creation?.kind === 'form' ? unit.creation.writesTo : null\n return isAiPlanNewRef(ref) ? aiBuildRefName(ref) : null\n}\n\n/** What each creation is called in a note. */\nexport function aiBuildCreationNoun(kind: AiBuildPlanCreateKind): string {\n return kind === 'email' ? 'email design' : kind === 'theme-change' ? 'theme change' : kind\n}\n\n/**\n * The brief lines a page is told about the items its sections place and\n * that were built: the block to put there, in the owner's words.\n */\nexport function aiBuildPlacedItemLines(\n unit: AiBuildUnit,\n context: {\n units: readonly AiBuildUnit[]\n ledger: readonly AiJobItemLedger[]\n ops?: AiBuildOps\n /** Operations whose items the platform places itself (a listing), so the page is told nothing of them. */\n placedByCode?: readonly string[]\n },\n): string[] {\n if (!unit.screen) return []\n const rows = new Map(context.ledger.map((row) => [row.slot, row]))\n const lines: string[] = []\n for (const section of unit.screen.sections) {\n // One line per block a section places, naming every built item it shows:\n // a section listing four events places the Event List once (AGL-3743).\n const placed = new Map<string, { blocks: readonly string[]; noun: string; labels: string[] }>()\n for (const { dep, capability } of aiBuildSectionItems(section, context.units, context.ops)) {\n const row = rows.get(dep.slot)\n if (!row || !aiBuildItemDelivered(row)) continue\n if (context.placedByCode?.includes(dep.op)) continue\n const blocks = capability?.pageBlocks ?? []\n if (!blocks.length) continue\n const key = aiBuildBlocksKey(blocks)\n const entry = placed.get(key) ?? { blocks, noun: capability?.noun ?? dep.op, labels: [] }\n entry.labels.push(`“${dep.label}”`)\n placed.set(key, entry)\n }\n for (const { blocks, noun, labels } of placed.values()) {\n const named =\n labels.length === 1\n ? `the ${noun} ${labels[0]}`\n : `the ${noun}s ${labels.slice(0, -1).join(', ')} and ${labels[labels.length - 1]}`\n lines.push(`In the “${section.name}” section, place the ${blocks.join(' or ')} block for ${named}.`)\n }\n }\n return lines\n}\n\n/** The items a page section places, each with its capability, in the order its uses name them. */\nfunction aiBuildSectionItems(\n section: { uses: readonly string[] },\n units: readonly AiBuildUnit[],\n ops: AiBuildOps | undefined,\n): Array<{ dep: AiBuildUnit; capability: PluginAiCapability | undefined }> {\n const found: Array<{ dep: AiBuildUnit; capability: PluginAiCapability | undefined }> = []\n for (const ref of section.uses) {\n if (!isAiPlanNewRef(ref)) continue\n const dep = units.find((one) => one.item && one.item.name.toLowerCase() === aiBuildRefName(ref))\n if (dep?.item) found.push({ dep, capability: ops?.get(dep.op) })\n }\n return found\n}\n\n/** The blocks a section's built items place, each set as one key; `except` leaves one item out. */\nfunction aiBuildSectionDeliveredBlocks(\n section: { uses: readonly string[] },\n context: { units: readonly AiBuildUnit[]; rows: ReadonlyMap<string, AiJobItemLedger>; ops?: AiBuildOps; except: string },\n): Set<string> {\n const keys = new Set<string>()\n for (const { dep, capability } of aiBuildSectionItems(section, context.units, context.ops)) {\n if (dep.slot === context.except || !capability?.pageBlocks?.length) continue\n const row = context.rows.get(dep.slot)\n if (row && aiBuildItemDelivered(row)) keys.add(aiBuildBlocksKey(capability.pageBlocks))\n }\n return keys\n}\n\nfunction aiBuildBlocksKey(blocks: readonly string[]): string {\n return [...blocks].sort().join('|')\n}\n\n/** What a build came to: whether anything was delivered, and whether anything is left. */\nexport function aiBuildSettlement(ledger: readonly AiJobItemLedger[]): {\n delivered: boolean\n open: boolean\n failed: number\n} {\n return {\n delivered: ledger.some(aiBuildItemDelivered),\n open: ledger.some(aiBuildItemOpen),\n failed: ledger.filter((row) => row.status === 'failed').length,\n }\n}\n\n/**\n * The ledger Try again runs (AGL-3616): every failed item back to `pending`\n * on its next attempt, with the items left unbuilt because of it — skipped,\n * or degraded with no draft — and every item the build never reached. An\n * item that succeeded is never run again, and a degraded page that has its\n * draft keeps it, with a note that the page needs an edit. `retried` names\n * the slots that will run, which is what the estimate is shown for.\n */\nexport function aiBuildRetryLedger(\n ledger: readonly AiJobItemLedger[],\n units: readonly AiBuildUnit[],\n): { ledger: AiJobItemLedger[]; retried: string[] } {\n const failed = new Set(ledger.filter((row) => row.status === 'failed').map((row) => row.slot))\n const dependents = new Map<string, string[]>()\n for (const unit of units) {\n for (const dep of unit.deps) dependents.set(dep, [...(dependents.get(dep) ?? []), unit.slot])\n }\n // Everything downstream of a failed item, transitively.\n const downstream = new Set<string>()\n const queue = [...failed]\n while (queue.length) {\n const slot = queue.shift() as string\n for (const next of dependents.get(slot) ?? []) {\n if (downstream.has(next)) continue\n downstream.add(next)\n queue.push(next)\n }\n }\n const retried: string[] = []\n const next = ledger.map((row): AiJobItemLedger => {\n const again =\n row.status === 'failed' ||\n (row.status === 'skipped' && (downstream.has(row.slot) || !(row.degradedBy ?? []).length)) ||\n (row.status === 'degraded' && downstream.has(row.slot) && !row.outputs.length)\n if (again) {\n retried.push(row.slot)\n return {\n ...row,\n status: 'pending',\n attempt: row.attempt + 1,\n attemptCredits: 0,\n failure: null,\n note: null,\n degradedBy: [],\n settledAt: null,\n }\n }\n if (row.status === 'degraded' && downstream.has(row.slot) && row.outputs.length) {\n return {\n ...row,\n note: `${row.note ? `${row.note} ` : ''}It keeps its draft: once the rest is built, edit this page to add what it is missing.`,\n }\n }\n return row\n })\n return { ledger: next, retried }\n}\n\n/**\n * Units read back off a ledger alone (AGL-3616), for a job whose units are\n * not a build plan's — a site scaffold's: each row as its unit, and every\n * page built after the layouts and forms the ledger holds.\n */\nexport function aiLedgerUnits(ledger: readonly AiJobItemLedger[]): AiBuildUnit[] {\n const creations = ledger.filter((row) => row.op === 'layout' || row.op === 'form').map((row) => row.slot)\n return ledger.map((row) => ({\n slot: row.slot,\n op: row.op,\n label: row.label,\n deps: row.op === 'page' ? creations : [],\n }))\n}\n\n/**\n * What the job drawer says under an item another plugin's writer made: a\n * draft, or, for setup its writer saves live (`live`, a CRM pipeline or\n * field, AGL-3746), that it was saved. A writer that went live only when the\n * member may (an event the publishing role publishes, AGL-3755) reports\n * `live: false` for one it kept as a draft, with its `notice` saying why.\n */\nexport function aiBuildItemOutputNote(\n capability: Pick<PluginAiCapability, 'where' | 'live'>,\n written?: Pick<PluginDraftRecord, 'live' | 'notice'>,\n): string {\n const live = written?.live ?? capability.live\n const said = live ? `Live now, in ${capability.where}.` : `A draft, in ${capability.where}.`\n const notice = written?.notice?.trim()\n return notice ? `${said} ${notice}` : said\n}\n"],"names":["pluginAiCapabilityArgsProblems","AI_PLAN_NEW_REF_PREFIX","isAiPlanNewRef","AI_BUILD_STORE_OP","AI_BUILD_STORE_PAGES_LABEL","AI_BUILD_STORE_SLOT","aiBuildMakesStore","aiBuildStorePagesAdded","AI_SITE_HOME_FIRST_LABEL","AI_SITE_MAX_SECTIONS","AI_SITE_PASS_CREDITS","aiCreationMeasuredCredits","aiJobPlanCreditEstimate","aiJobPlanCreditRange","aiSitePlanIsHome","aiStandaloneScreenCreditRange","AI_CREDIT_RANGE_ZERO","AI_MEASURED_PASS_CREDITS","aiCreditRangeAdd","aiCreditRangeOf","aiCreditRangeOrdered","AI_BUILD_LIMITS","units","pages","freePages","aiBuildFreePageCapNote","plan","freeTaste","cap","screens","length","AI_BUILD_CREATE_KINDS","AI_BUILD_STRUCTURAL_OPS","AI_BUILD_MADE_INPUT","AI_BUILD_PUBLISH_INPUT","creationOp","creation","kind","namedSlots","slots","Map","create","forEach","index","includes","set","name","toLowerCase","item","items","slot","aiBuildRefName","ref","slice","trim","aiBuildItemArgRefs","args","refs","take","value","part","split","push","Object","values","Array","isArray","aiBuildScreenRefs","screen","layout","template","duplicateOf","sections","flatMap","section","uses","filter","aiBuildUnits","pageSlots","title","has","depsOf","self","deps","get","undefined","op","label","writesTo","dependsOn","aiBuildUnitIsPlatform","unit","aiBuildOrder","ordered","placed","Set","known","map","next","find","every","dep","add","aiBuildGraphProblems","problems","aiBuildPageLimit","aiBuildPlanShapeRefusal","options","counts","slugs","slug","graph","ops","capability","freeAllowed","aiArticle","noun","argsSchema","join","count","maxPerPlan","aiBuildPlanMissingInput","questions","question","missingInput","why","AI_BUILD_NEEDS_INPUT_CODE","aiBuildPlanInputFields","fields","one","asked","inputFields","field","arg","shape","pattern","source","test","unitPasses","aiBuildUnitCreditEstimate","credits","Math","max","floor","estimateCredits","aiBuildCreditEstimate","reduce","total","aiJobCreditEstimate","aiBuildUnitCreditRange","ceiling","standalone","passes","ceil","median","p90","aiBuildCreditRange","aiJobCreditRange","aiBuildFirstPagePlan","findIndex","bySlot","keep","queue","shift","size","at","kept","entry","smaller","embeds","embed","where","storePages","aiBuildSmaller","aiBuildInitialLedger","status","attempt","creditsSpent","attemptCredits","creditsRefunded","failure","outputs","OPEN","aiBuildItemOpen","row","aiBuildItemDelivered","aiBuildNextUnit","ledger","rows","aiBuildDegradation","context","result","skip","degradedBy","notes","dropped","briefLines","aiBuildCreationNoun","degrade","aiBuildUnitWritesTo","madeAPage","some","made","blockStays","Boolean","pageBlocks","aiBuildSectionDeliveredBlocks","except","aiBuildBlocksKey","blocks","aiBuildPlacedItemLines","lines","aiBuildSectionItems","placedByCode","key","labels","named","found","keys","sort","aiBuildSettlement","delivered","open","failed","aiBuildRetryLedger","dependents","downstream","retried","again","note","settledAt","aiLedgerUnits","creations","aiBuildItemOutputNote","written","live","said","notice"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SACEA,8BAA8B,QAEzB,qDAAoD;AAE3D,SACEC,sBAAsB,EACtBC,cAAc,QAMT,qBAAiB;AAExB,SACEC,iBAAiB,EACjBC,0BAA0B,EAC1BC,mBAAmB,EACnBC,iBAAiB,EACjBC,sBAAsB,QACjB,4BAAwB;AAC/B,SACEC,wBAAwB,EACxBC,oBAAoB,EACpBC,oBAAoB,EACpBC,yBAAyB,EACzBC,uBAAuB,EACvBC,oBAAoB,EACpBC,gBAAgB,EAChBC,6BAA6B,QACxB,mBAAe;AACtB,SACEC,oBAAoB,EACpBC,wBAAwB,EACxBC,gBAAgB,EAChBC,eAAe,EACfC,oBAAoB,QAGf,0BAAsB;AAE7B;;;;;;;;;;;;;;;;;CAiBC,GAED,sFAAsF,GACtF,OAAO,MAAMC,kBAAkB;IAC7B,yCAAyC,GACzCC,OAAO;IACPC,OAAO;IACP,8BAA8B,GAC9BC,WAAW;AACb,EAAU;AAEV;;;;;;CAMC,GACD,OAAO,SAASC,uBAAuBC,IAAkC,EAAEC,SAAkB;IAC3F,MAAMC,MAAMP,gBAAgBG,SAAS;IACrC,IAAI,CAACG,aAAaD,KAAKG,OAAO,CAACC,MAAM,GAAGF,KAAK,OAAO;IACpD,OAAO,CAAC,qCAAqC,EAAEA,IAAI,yFAAyF,CAAC;AAC/I;AAEA,6FAA6F,GAC7F,OAAO,MA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F,MAAS,CAAA;YAC1BtI,MAAMsI,IAAItI,IAAI;YACdoC,IAAIkG,IAAIlG,EAAE;YACVC,OAAOiG,IAAIjG,KAAK;YAChBJ,MAAMqG,IAAIlG,EAAE,KAAK,SAASkJ,YAAY,EAAE;QAC1C,CAAA;AACF;AAEA;;;;;;CAMC,GACD,OAAO,SAASC,sBACdxH,UAAsD,EACtDyH,OAAoD;;QAIrCA;IAFf,MAAMC,eAAOD,2BAAAA,QAASC,IAAI,mBAAI1H,WAAW0H,IAAI;IAC7C,MAAMC,OAAOD,OAAO,CAAC,aAAa,EAAE1H,WAAW0D,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,YAAY,EAAE1D,WAAW0D,KAAK,CAAC,CAAC,CAAC;IAC5F,MAAMkE,SAASH,4BAAAA,kBAAAA,QAASG,MAAM,qBAAfH,gBAAiBpL,IAAI;IACpC,OAAOuL,SAAS,GAAGD,KAAK,CAAC,EAAEC,QAAQ,GAAGD;AACxC"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/model/ai-build-job.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n pluginAiCapabilityArgsProblems,\n type PluginAiCapability,\n} from '@aglyn/aglyn/plugin-manager/plugin-ai-capabilities'\nimport type { PluginDraftRecord } from '@aglyn/aglyn/plugin-manager/plugin-resource-drafts'\nimport {\n AI_PLAN_NEW_REF_PREFIX,\n isAiPlanNewRef,\n type AiBuildItem,\n type AiBuildPlan,\n type AiBuildPlanCreate,\n type AiBuildPlanCreateKind,\n type AiBuildPlanScreen,\n} from './ai-build-plan'\nimport type { AiJobInputField, AiJobItemLedger, AiJobItemStatus } from './ai-jobs.types'\nimport {\n AI_BUILD_STORE_OP,\n AI_BUILD_STORE_PAGES_LABEL,\n AI_BUILD_STORE_SLOT,\n aiBuildMakesStore,\n aiBuildStorePagesAdded,\n} from './ai-build-store-pages'\nimport {\n AI_SITE_HOME_FIRST_LABEL,\n AI_SITE_MAX_SECTIONS,\n AI_SITE_PASS_CREDITS,\n aiCreationMeasuredCredits,\n aiJobPlanCreditEstimate,\n aiJobPlanCreditRange,\n aiSitePlanIsHome,\n aiStandaloneScreenCreditRange,\n} from './ai-site-job'\nimport {\n AI_CREDIT_RANGE_ZERO,\n AI_MEASURED_PASS_CREDITS,\n aiCreditRangeAdd,\n aiCreditRangeOf,\n aiCreditRangeOrdered,\n type AiCreditRange,\n type AiCreditsSmaller,\n} from './ai-credit-estimate'\n\n/**\n * What a `build` job is (AGL-3616): one request — \"a few pages, a contact\n * form and a way to book me\" — planned as creations, pages and items, built\n * one UNIT a pass in dependency order, and settled ITEM BY ITEM.\n *\n * A build is a generalized site scaffold. Every unit is handed to what\n * already builds that kind of thing — a page to the page step, a form to the\n * form step, another plugin's resource to that plugin's draft writer — so a\n * build cannot drift from what it builds. What is new is the settlement: one\n * failed unit does not end the job. It gives back its own spend, the units\n * that depended on it are built without it (or skipped, when they cannot\n * stand without it), and the job is `done` when anything was delivered.\n *\n * This module is the build's MODEL — its units, their order, how a failure\n * travels to what depends on it, what it is estimated to cost, and the\n * ledger arithmetic — and does no I/O, so the step, the machine, the doors\n * and the console read one vocabulary.\n */\n\n/** How much one build holds: what one proposal can describe and one person can read. */\nexport const AI_BUILD_LIMITS = {\n /** Creations, pages and items together. */\n units: 16,\n pages: 8,\n /** A Free workspace's pages. */\n freePages: 2,\n} as const\n\n/**\n * What a Free build's plan card says when it holds as many pages as a Free\n * build makes (AGL-3722): the plan is told the cap and plans the first pages\n * a request asks for, so a request for three — \"About us, Custom cakes and\n * Catering\", 2026-10-10 — came back as two with nothing saying why. `null`\n * when the plan holds fewer, or on a paid workspace.\n */\nexport function aiBuildFreePageCapNote(plan: Pick<AiBuildPlan, 'screens'>, freeTaste: boolean): string | null {\n const cap = AI_BUILD_LIMITS.freePages\n if (!freeTaste || plan.screens.length < cap) return null\n return `A Free workspace’s build makes up to ${cap} pages at a time. If you asked for more, ask Assist for the rest once this build is done.`\n}\n\n/** What a build creates through its `create` list; everything else beyond pages is an item. */\nexport const AI_BUILD_CREATE_KINDS: readonly AiBuildPlanCreateKind[] = ['layout', 'form', 'component', 'email']\n\n/**\n * The operations a build plans through `create` and `screens` rather than\n * `items`: an item naming one is a plan that put it in the wrong list.\n */\nexport const AI_BUILD_STRUCTURAL_OPS: readonly string[] = ['page', ...AI_BUILD_CREATE_KINDS]\n\n/**\n * The operation that proposes a change to the site's theme (AGL-4077): the\n * theme runner's proposal, which the owner applies in Setup → Theme. Planned\n * as an item; a plan that names it as its `theme-change` creation, the\n * doctrine's word for it, is built by the same operation rather than refused.\n */\nexport const AI_BUILD_THEME_OP = 'theme'\n\n/** The creations a build builds as units: its structural kinds, and a theme change, as the theme operation. */\nconst AI_BUILD_UNIT_CREATE_KINDS: readonly AiBuildPlanCreateKind[] = [...AI_BUILD_CREATE_KINDS, 'theme-change']\n\n/**\n * What a build hands an item it made before it (AGL-3728): its pages, by the\n * title the plan gave each and the id it was written under, and its layouts,\n * by name. An item's `new:<title>` destinations are read against it.\n */\nexport const AI_BUILD_MADE_INPUT = 'buildMade'\n\nexport interface AiBuildMade {\n pages: Array<{ title: string; id: string }>\n layouts: Array<{ name: string; id: string }>\n}\n\n/** The job input a build's Assist proposal sets when the brief asked to publish. */\nexport const AI_BUILD_PUBLISH_INPUT = 'publish'\n\n/** A unit of a build: a creation, a page, or an item. */\nexport interface AiBuildUnit {\n slot: string\n /** The capability operation that builds it. */\n op: string\n label: string\n creation?: AiBuildPlanCreate\n screen?: AiBuildPlanScreen\n item?: AiBuildItem\n /** The slots it is built after, in plan order. */\n deps: string[]\n}\n\n/** The operation a creation is built as. */\nfunction creationOp(creation: AiBuildPlanCreate): string {\n return creation.kind === 'theme-change' ? AI_BUILD_THEME_OP : creation.kind\n}\n\n/** A plan's `new:<name>` names, each to the slot that builds it. */\nfunction namedSlots(plan: AiBuildPlan): Map<string, string> {\n const slots = new Map<string, string>()\n plan.create.forEach((creation, index) => {\n if (AI_BUILD_UNIT_CREATE_KINDS.includes(creation.kind)) slots.set(creation.name.toLowerCase(), `c${index}`)\n })\n for (const item of plan.items ?? []) slots.set(item.name.toLowerCase(), item.slot)\n return slots\n}\n\n/** The name a `new:<name>` reference gives, lowercased. */\nexport function aiBuildRefName(ref: string): string {\n return ref.slice(AI_PLAN_NEW_REF_PREFIX.length).trim().toLowerCase()\n}\n\n/**\n * The `new:<name>` references an item's arguments make (AGL-3728): an\n * argument that is one, or the destination after `=>` in an entry such as a\n * menu item's `About => new:About`. Read from the arguments, never from the\n * model's `dependsOn`, so what an item links is always built before it.\n */\nexport function aiBuildItemArgRefs(args: Readonly<Record<string, unknown>> | null | undefined): string[] {\n const refs: string[] = []\n const take = (value: unknown) => {\n if (typeof value !== 'string') return\n for (const part of [value, value.split('=>').slice(-1)[0] ?? '']) {\n const ref = part.trim()\n if (isAiPlanNewRef(ref) && !refs.includes(ref)) refs.push(ref)\n }\n }\n for (const value of Object.values(args ?? {})) {\n if (Array.isArray(value)) value.forEach(take)\n else take(value)\n }\n return refs\n}\n\n/** Every reference a page makes: its layout, template, starting page and what its sections place. */\nexport function aiBuildScreenRefs(screen: AiBuildPlanScreen): string[] {\n return [\n screen.layout,\n screen.template,\n screen.duplicateOf,\n ...screen.sections.flatMap((section) => section.uses),\n ].filter((ref): ref is string => typeof ref === 'string' && ref.length > 0)\n}\n\n/**\n * The units a plan implies, in plan order: creations, then items, then\n * pages — the order a member reads them in, and the one a page that places\n * a creation or an item is built after anyway. `aiBuildOrder` sorts them on\n * their dependencies.\n */\nexport function aiBuildUnits(plan: AiBuildPlan): AiBuildUnit[] {\n const slots = namedSlots(plan)\n // A page, by the title the plan gave it: what an item's arguments may link\n // as `new:<title>` (a menu item, AGL-3728), built before the item.\n const pageSlots = new Map<string, string>()\n plan.screens.forEach((screen, index) => {\n const title = screen.title.trim().toLowerCase()\n if (title && !pageSlots.has(title)) pageSlots.set(title, `p${index}`)\n })\n const depsOf = (refs: readonly (string | null)[], self: string, pages = false): string[] => {\n const deps: string[] = []\n for (const ref of refs) {\n if (!isAiPlanNewRef(ref)) continue\n const slot = slots.get(aiBuildRefName(ref)) ?? (pages ? pageSlots.get(aiBuildRefName(ref)) : undefined)\n if (slot && slot !== self && !deps.includes(slot)) deps.push(slot)\n }\n return deps\n }\n const units: AiBuildUnit[] = []\n plan.create.forEach((creation, index) => {\n if (!AI_BUILD_UNIT_CREATE_KINDS.includes(creation.kind)) return\n const slot = `c${index}`\n // A form is built after the dataset it writes to (AGL-3616).\n units.push({\n slot,\n op: creationOp(creation),\n label: creation.name,\n creation,\n deps: depsOf([creation.duplicateOf, creation.kind === 'form' ? (creation.writesTo ?? null) : null], slot),\n })\n })\n for (const item of plan.items ?? []) {\n units.push({\n slot: item.slot,\n op: item.op,\n label: item.name,\n item,\n // What it depends on, and what its arguments link as `new:` (AGL-3728).\n deps: depsOf([...item.dependsOn, ...aiBuildItemArgRefs(item.args)], item.slot, true),\n })\n }\n plan.screens.forEach((screen, index) => {\n const slot = `p${index}`\n units.push({ slot, op: 'page', label: screen.title, screen, deps: depsOf(aiBuildScreenRefs(screen), slot) })\n })\n // A store's own pages (AGL-3676), added by the platform: last, so every\n // planned page keeps the first claim on the site's pages allowance.\n if (aiBuildStorePagesAdded(plan).length) {\n units.push({ slot: AI_BUILD_STORE_SLOT, op: AI_BUILD_STORE_OP, label: AI_BUILD_STORE_PAGES_LABEL, deps: [] })\n }\n return units\n}\n\n/** Whether a unit is one the platform adds rather than the plan (AGL-3676): a store's own pages. */\nexport function aiBuildUnitIsPlatform(unit: Pick<AiBuildUnit, 'op'>): boolean {\n return unit.op === AI_BUILD_STORE_OP\n}\n\n/**\n * The units in an order that builds every dependency before what depends on\n * it, plan order otherwise; `null` when the dependencies hold a cycle.\n */\nexport function aiBuildOrder(units: readonly AiBuildUnit[]): AiBuildUnit[] | null {\n const ordered: AiBuildUnit[] = []\n const placed = new Set<string>()\n const known = new Set(units.map((unit) => unit.slot))\n while (ordered.length < units.length) {\n const next = units.find(\n (unit) => !placed.has(unit.slot) && unit.deps.every((dep) => placed.has(dep) || !known.has(dep)),\n )\n if (!next) return null\n ordered.push(next)\n placed.add(next.slot)\n }\n return ordered\n}\n\n/**\n * What is wrong with a plan's references as a build reads them: a\n * `new:<name>` an item depends on that nothing in the plan makes, and a\n * cycle. Each is a sentence the plan's one re-ask carries.\n */\nexport function aiBuildGraphProblems(plan: AiBuildPlan): string[] {\n const problems: string[] = []\n const slots = namedSlots(plan)\n for (const item of plan.items ?? []) {\n for (const ref of item.dependsOn) {\n if (!isAiPlanNewRef(ref)) continue\n if (!slots.has(aiBuildRefName(ref))) {\n problems.push(`The item \"${item.name}\" depends on ${ref}, which the plan never makes. Declare it, or take it out of dependsOn.`)\n } else if (aiBuildRefName(ref) === item.name.toLowerCase()) {\n problems.push(`The item \"${item.name}\" depends on itself. Take it out of its own dependsOn.`)\n }\n }\n }\n if (!aiBuildOrder(aiBuildUnits(plan))) {\n problems.push('The plan’s dependencies go round in a circle, so nothing in the circle can be built first. Make one of them depend on nothing.')\n }\n return problems\n}\n\n/** The operations a build may plan, as the registry and the gates left them, by op. */\nexport type AiBuildOps = ReadonlyMap<string, PluginAiCapability>\n\n/** How many pages a build may hold on this workspace. */\nexport function aiBuildPageLimit(freeTaste: boolean | null | undefined): number {\n return freeTaste ? AI_BUILD_LIMITS.freePages : AI_BUILD_LIMITS.pages\n}\n\n/**\n * Why a build cannot build a plan of this shape, in a sentence a member\n * reads; `null` when it can. Held to the plan with the one re-ask (the plan\n * step's scope), and again by the doors before a confirmed plan runs.\n * `ops` is what may be planned on this site; absent, items are not judged\n * against the registry (a console reading a kept plan).\n */\nexport function aiBuildPlanShapeRefusal(\n plan: AiBuildPlan,\n options: { freeTaste?: boolean; ops?: AiBuildOps } = {},\n): string | null {\n // What the platform adds beside the plan (a store's own pages) is no part of its size.\n const units = aiBuildUnits(plan).filter((unit) => !aiBuildUnitIsPlatform(unit))\n if (!units.length) return 'This plan builds nothing. Describe what to build again.'\n if (units.length > AI_BUILD_LIMITS.units) {\n return `This plan builds ${units.length} things, and one build holds ${AI_BUILD_LIMITS.units}. Ask for the rest in a second request.`\n }\n const pages = aiBuildPageLimit(options.freeTaste)\n if (plan.screens.length > pages) {\n return options.freeTaste\n ? `This plan builds ${plan.screens.length} pages, and a Free workspace's build makes at most ${pages}. Paid plans can build more.`\n : `This plan builds ${plan.screens.length} pages, and one build makes at most ${pages}.`\n }\n const slugs = new Set<string>()\n for (const screen of plan.screens) {\n if (!screen.sections.length) return `The page “${screen.title}” has no sections to build.`\n if (screen.sections.length > AI_SITE_MAX_SECTIONS) {\n return `The page “${screen.title}” has ${screen.sections.length} sections, and a built page holds ${AI_SITE_MAX_SECTIONS}.`\n }\n const slug = screen.slug.trim().toLowerCase()\n if (slugs.has(slug)) return `Two pages in this plan share the address ${screen.slug}.`\n slugs.add(slug)\n }\n const ops = options.ops\n for (const creation of plan.create) {\n if (AI_BUILD_CREATE_KINDS.includes(creation.kind)) continue\n if (creation.kind !== 'theme-change') {\n return `A build does not create ${creation.kind}s (“${creation.name}”). Take it out of create.`\n }\n // A theme change is the theme operation's (AGL-4077), held as its item would be.\n const refusal = aiBuildThemeRefusal(creation.name, 'create', options)\n if (refusal) return refusal\n }\n const graph = aiBuildGraphProblems(plan)\n if (graph.length) return graph[0]\n const counts = new Map<string, number>()\n for (const unit of units) counts.set(unit.op, (counts.get(unit.op) ?? 0) + 1)\n for (const item of plan.items ?? []) {\n if (AI_BUILD_STRUCTURAL_OPS.includes(item.op)) {\n return item.op === 'page'\n ? `“${item.name}” is a page: plan it in screens, not items.`\n : `“${item.name}” is ${item.op === 'email' ? 'an' : 'a'} ${item.op}: plan it in create, not items.`\n }\n if (item.op === AI_BUILD_THEME_OP) {\n const refusal = aiBuildThemeRefusal(item.name, 'items', options)\n if (refusal) return refusal\n }\n if (!ops) continue\n const capability = ops.get(item.op)\n if (!capability) return `Nothing on this site can make “${item.name}” (${item.op}). Take it out of items.`\n if (options.freeTaste && !capability.freeAllowed) {\n return `A Free workspace cannot have ${aiArticle(capability.noun)} made (“${item.name}”). Take it out of items.`\n }\n const problems = pluginAiCapabilityArgsProblems(capability.argsSchema, item.args)\n if (problems.length) return `The arguments of “${item.name}” do not read: ${problems.join('; ')}.`\n }\n if (ops) {\n for (const [op, count] of counts) {\n const capability = ops.get(op)\n if (capability && count > capability.maxPerPlan) {\n return `This plan makes ${count} of “${capability.noun}”, and one build makes at most ${capability.maxPerPlan}.`\n }\n }\n }\n return null\n}\n\n/**\n * Why a build cannot make this theme change (AGL-4077), naming the list the\n * plan put it in; `null` when it can, or when there are no operations to\n * judge it against. The Free taste is named for what it is: its operations\n * never hold the theme operation, which only paid plans are offered.\n */\nfunction aiBuildThemeRefusal(\n name: string,\n list: 'create' | 'items',\n options: { freeTaste?: boolean; ops?: AiBuildOps },\n): string | null {\n if (!options.ops) return null\n if (options.freeTaste) return `A Free workspace cannot have a theme change made (“${name}”). Take it out of ${list}.`\n if (!options.ops.has(AI_BUILD_THEME_OP)) return `Nothing on this site can make “${name}” (theme change). Take it out of ${list}.`\n return null\n}\n\n/**\n * What the person must still say before this plan can be built, as the\n * questions its operations ask (`missingInput`), or `null` when nothing is\n * missing: an item the planner kept with nothing it may build from — a\n * tracking change naming no id, AGL-3751 — is asked about, never built\n * empty or from a value the planner made up. Not a plan rule: a re-ask\n * cannot supply what only the person knows, so the plan is not kept and\n * the build answers with the question.\n */\nexport function aiBuildPlanMissingInput(plan: AiBuildPlan, ops: AiBuildOps | null | undefined): string | null {\n if (!ops) return null\n const questions: string[] = []\n for (const item of plan.items ?? []) {\n const question = ops.get(item.op)?.missingInput?.({ name: item.name, why: item.why, args: item.args })\n if (question && !questions.includes(question)) questions.push(question)\n }\n return questions.length ? questions.join(' ') : null\n}\n\n/**\n * The code on the build's admission refusal for a plan only the person can\n * complete (AGL-3978): the plan step keeps such a plan and waits in\n * `needs_input` for the fields `aiBuildPlanInputFields` reads, where the\n * operations describe them.\n */\nexport const AI_BUILD_NEEDS_INPUT_CODE = 'needs-input'\n\n/**\n * The fields the person fills before this plan can be built (AGL-3978), one\n * per id an item asks for, as its operation describes them (`inputFields`).\n * Empty when nothing asks, or when an item asks without fields to fill — a\n * tracking change naming no tag at all — which the build answers with its\n * question instead.\n */\nexport function aiBuildPlanInputFields(plan: AiBuildPlan, ops: AiBuildOps | null | undefined): AiJobInputField[] {\n if (!ops) return []\n const fields: AiJobInputField[] = []\n for (const item of plan.items ?? []) {\n const capability = ops.get(item.op)\n const one = { name: item.name, why: item.why, args: item.args }\n if (!capability?.missingInput?.(one)) continue\n const asked = capability.inputFields?.(one) ?? []\n if (!asked.length) return []\n for (const field of asked) {\n fields.push({ item: item.name, arg: field.arg, label: field.label, shape: field.shape, pattern: field.pattern.source })\n }\n }\n return fields\n}\n\n/** \"a booking service\", \"an email design\". */\nexport function aiArticle(noun: string): string {\n return `${/^[aeiou]/i.test(noun) ? 'an' : 'a'} ${noun}`\n}\n\n/** The passes one unit is estimated at: a page's sections and its listing, one for a creation. */\nfunction unitPasses(unit: AiBuildUnit): number {\n if (unit.screen) return unit.screen.sections.length + 1\n return 1\n}\n\n/**\n * About what one unit costs, in credits: a page or a creation by the passes\n * it implies at the nominal credits a pass is held against, as a site's are;\n * an item by its capability's own estimate, recorded on the plan when it was\n * kept.\n */\nexport function aiBuildUnitCreditEstimate(unit: AiBuildUnit, ops?: AiBuildOps): number {\n // A store's own pages are written by code, with no model: no credits (AGL-3676).\n if (aiBuildUnitIsPlatform(unit)) return 0\n if (unit.item) {\n if (typeof unit.item.credits === 'number') return unit.item.credits\n const capability = ops?.get(unit.item.op)\n if (capability) return Math.max(0, Math.floor(capability.estimateCredits(unit.item.args)))\n return AI_SITE_PASS_CREDITS\n }\n return unitPasses(unit) * AI_SITE_PASS_CREDITS\n}\n\n/**\n * About what a build costs, in credits: every unit's estimate, or only the\n * units named in `slots` — what Try again shows. The ceiling a member\n * confirms; the meter charges what actually runs.\n */\nexport function aiBuildCreditEstimate(\n plan: AiBuildPlan,\n options: { ops?: AiBuildOps; slots?: ReadonlySet<string> } = {},\n): number {\n return aiBuildUnits(plan)\n .filter((unit) => !options.slots || options.slots.has(unit.slot))\n .reduce((total, unit) => total + aiBuildUnitCreditEstimate(unit, options.ops), 0)\n}\n\n/**\n * About what a job of this kind costs to build from its plan: a build's\n * units, every other planned kind as `aiJobPlanCreditEstimate` counts it.\n */\nexport function aiJobCreditEstimate(kind: string, plan: AiBuildPlan): number {\n return kind === 'build' ? aiBuildCreditEstimate(plan) : aiJobPlanCreditEstimate(kind, plan)\n}\n\n/**\n * What one unit is likely to cost, its p90 and its ceiling (AGL-3722): a page\n * as a page written on its own measured (a fixed cost and one per section), a creation at what its kind\n * measured, an item at the measured pass times the passes its capability\n * estimates (none for a draft another plugin writes, which asks no model).\n * The ceiling is `aiBuildUnitCreditEstimate`, unchanged.\n */\nexport function aiBuildUnitCreditRange(unit: AiBuildUnit, ops?: AiBuildOps): AiCreditRange {\n const ceiling = aiBuildUnitCreditEstimate(unit, ops)\n // A build writes each page on its own, never in a site start's warm run (AGL-3722).\n if (unit.screen) return aiStandaloneScreenCreditRange(unit.screen.sections.length)\n if (unit.creation) return aiCreditRangeOf(aiCreationMeasuredCredits(unit.creation.kind, { standalone: true }), ceiling)\n const passes = Math.ceil(ceiling / AI_SITE_PASS_CREDITS)\n return aiCreditRangeOf(\n { median: passes * AI_MEASURED_PASS_CREDITS.median, p90: passes * AI_MEASURED_PASS_CREDITS.p90 },\n ceiling,\n )\n}\n\n/**\n * What a build is likely to cost, its p90 and its ceiling (AGL-3722): every\n * unit's range, or only the units named in `slots` — what Try again runs.\n * The plan card, Try again and the Free admission all read this; the meter\n * charges what actually runs.\n */\nexport function aiBuildCreditRange(\n plan: AiBuildPlan,\n options: { ops?: AiBuildOps; slots?: ReadonlySet<string> } = {},\n): AiCreditRange {\n return aiCreditRangeOrdered(\n aiBuildUnits(plan)\n .filter((unit) => !options.slots || options.slots.has(unit.slot))\n .reduce((total, unit) => aiCreditRangeAdd(total, aiBuildUnitCreditRange(unit, options.ops)), AI_CREDIT_RANGE_ZERO),\n )\n}\n\n/** `aiJobCreditEstimate` as a range (AGL-3722). */\nexport function aiJobCreditRange(kind: string, plan: AiBuildPlan): AiCreditRange {\n return kind === 'build' ? aiBuildCreditRange(plan) : aiJobPlanCreditRange(kind, plan)\n}\n\n/**\n * A smaller first build (AGL-3722): the plan's home page — its first page\n * where it has no home — and only what that page needs, transitively: the\n * layout it is drawn in, the form and anything else its sections place.\n * Every other page, and what only they needed, waits for a later request.\n * `null` when the plan has no page, or when the smaller plan is the whole one.\n */\nexport function aiBuildFirstPagePlan<T extends AiBuildPlan>(plan: T): T | null {\n if (!plan.screens.length) return null\n const index = Math.max(0, plan.screens.findIndex(aiSitePlanIsHome))\n const units = aiBuildUnits(plan).filter((unit) => !aiBuildUnitIsPlatform(unit))\n const bySlot = new Map(units.map((unit) => [unit.slot, unit]))\n const keep = new Set<string>()\n const queue = [`p${index}`]\n while (queue.length) {\n const slot = queue.shift() as string\n if (keep.has(slot)) continue\n keep.add(slot)\n for (const dep of bySlot.get(slot)?.deps ?? []) queue.push(dep)\n }\n if (keep.size === units.length) return null\n const screen = plan.screens[index]\n const create = plan.create.filter((creation, at) => !AI_BUILD_UNIT_CREATE_KINDS.includes(creation.kind) || keep.has(`c${at}`))\n const items = (plan.items ?? []).filter((item) => keep.has(item.slot))\n const kept = new Set([screen.slug, ...create.map((entry) => `${AI_PLAN_NEW_REF_PREFIX}${entry.name}`)])\n const smaller: T = {\n ...plan,\n create,\n screens: [screen],\n ...(plan.items ? { items } : {}),\n ...(plan.embeds ? { embeds: plan.embeds.filter((embed) => kept.has(embed.where)) } : {}),\n }\n // The store's own pages stay only while the smaller build still makes a store (AGL-3676).\n if (smaller.storePages && !aiBuildMakesStore(smaller)) delete smaller.storePages\n return smaller\n}\n\n/** The smaller first build a build that does not fit is offered (AGL-3722), with its range; `null` when there is none. */\nexport function aiBuildSmaller(plan: AiBuildPlan, ops?: AiBuildOps): AiCreditsSmaller | null {\n const smaller = aiBuildFirstPagePlan(plan)\n if (!smaller) return null\n const screen = smaller.screens[0]\n const label = aiSitePlanIsHome(screen) ? AI_SITE_HOME_FIRST_LABEL : `Build the ${screen.title} page first`\n return { label, ...aiBuildCreditRange(smaller, { ops }) }\n}\n\n/** A fresh ledger: one pending row per unit, first attempt. */\nexport function aiBuildInitialLedger(units: readonly AiBuildUnit[]): AiJobItemLedger[] {\n return units.map((unit) => ({\n slot: unit.slot,\n op: unit.op,\n label: unit.label,\n status: 'pending',\n attempt: 1,\n creditsSpent: 0,\n attemptCredits: 0,\n creditsRefunded: 0,\n failure: null,\n outputs: [],\n }))\n}\n\nconst OPEN: readonly AiJobItemStatus[] = ['pending', 'running']\n\n/** Whether an item is still to be built. */\nexport function aiBuildItemOpen(row: Pick<AiJobItemLedger, 'status'>): boolean {\n return OPEN.includes(row.status)\n}\n\n/** Whether an item delivered: built as planned, or built without something that failed. */\nexport function aiBuildItemDelivered(row: Pick<AiJobItemLedger, 'status'>): boolean {\n return row.status === 'succeeded' || row.status === 'degraded'\n}\n\n/**\n * The next unit to build: the first in build order whose row is still open.\n * Its dependencies come before it, so by then each is settled one way or the\n * other. `null` when nothing is left.\n */\nexport function aiBuildNextUnit(\n ordered: readonly AiBuildUnit[],\n ledger: readonly AiJobItemLedger[],\n): AiBuildUnit | null {\n const rows = new Map(ledger.map((row) => [row.slot, row]))\n return ordered.find((unit) => {\n const row = rows.get(unit.slot)\n return !row || aiBuildItemOpen(row)\n }) ?? null\n}\n\n/** How a unit is built given what its dependencies came to. */\nexport interface AiBuildDegradation {\n /** The unit is not built at all, with the sentence why; nothing is spent. */\n skip: string | null\n /** The failed dependencies that change how it is built. */\n degradedBy: string[]\n /** What the person reads about the change; one per failed dependency. */\n notes: string[]\n /** `new:<name>` references (lowercased names) to leave out. */\n dropped: Set<string>\n /** Brief lines for the unit's own job: what to leave out, and what to place. */\n briefLines: string[]\n}\n\n/**\n * How a unit is built when some of what it depends on failed (AGL-3616).\n *\n * A PAGE is always built: a failed layout falls back to the site's own, a\n * failed form or component is left out of its section, and a failed item a\n * section places (a booking service) takes its block out of the page — each\n * with a note. Any OTHER unit whose dependency failed is skipped when that\n * dependency's capability says `omit` (a campaign whose email design failed\n * has nothing to send), and built without it when it says `fallback`.\n */\nexport function aiBuildDegradation(\n unit: AiBuildUnit,\n context: {\n units: readonly AiBuildUnit[]\n ledger: readonly AiJobItemLedger[]\n ops?: AiBuildOps\n },\n): AiBuildDegradation {\n const rows = new Map(context.ledger.map((row) => [row.slot, row]))\n const bySlot = new Map(context.units.map((one) => [one.slot, one]))\n const result: AiBuildDegradation = { skip: null, degradedBy: [], notes: [], dropped: new Set(), briefLines: [] }\n for (const slot of unit.deps) {\n const dep = bySlot.get(slot)\n const row = rows.get(slot)\n if (!dep || !row || aiBuildItemDelivered(row)) continue\n const noun = dep.creation\n ? aiBuildCreationNoun(dep.creation.kind)\n : (context.ops?.get(dep.op)?.noun ?? dep.op)\n const capability = dep.item ? context.ops?.get(dep.op) : undefined\n const degrade = dep.item?.degrade ?? capability?.degrade ?? (dep.creation?.kind === 'layout' ? 'fallback' : 'omit')\n // A form whose dataset could not be made is built without it (AGL-3616):\n // its submissions reach the Inbox, as any form's do.\n if (aiBuildUnitWritesTo(unit) === dep.label.toLowerCase()) {\n result.degradedBy.push(slot)\n result.notes.push(`Its submissions arrive in the Inbox only: the dataset “${dep.label}” could not be created.`)\n continue\n }\n // An item that links pages this build makes (a menu's entries, AGL-3728)\n // is built with the ones it made and without the ones it could not\n // (AGL-3832), and skipped only when it made none of them.\n const madeAPage = unit.deps.some((one) => {\n const made = rows.get(one)\n return !!bySlot.get(one)?.screen && !!made && aiBuildItemDelivered(made)\n })\n if (!unit.screen && dep.screen && madeAPage) {\n result.degradedBy.push(slot)\n result.dropped.add(dep.label.toLowerCase())\n result.notes.push(`Built without the ${noun} “${dep.label}”: it could not be created.`)\n continue\n }\n if (!unit.screen && degrade === 'omit') {\n result.skip = `Not built: the ${noun} “${dep.label}” it needs could not be created.`\n result.degradedBy.push(slot)\n return result\n }\n result.degradedBy.push(slot)\n result.dropped.add(dep.label.toLowerCase())\n if (dep.creation?.kind === 'layout') {\n result.notes.push(`Built inside the site’s own layout: the layout “${dep.label}” could not be created.`)\n continue\n }\n if (unit.screen) {\n const section = unit.screen.sections.find((one) =>\n one.uses.some((ref) => isAiPlanNewRef(ref) && aiBuildRefName(ref) === dep.label.toLowerCase()),\n )\n // Another item this section places with the same block was built (one\n // of several events, AGL-3743): the block stays, and only this item is\n // missing from what it shows.\n const blockStays = Boolean(\n section &&\n capability?.pageBlocks?.length &&\n aiBuildSectionDeliveredBlocks(section, { ...context, rows, except: slot }).has(aiBuildBlocksKey(capability.pageBlocks)),\n )\n if (blockStays) {\n result.notes.push(`Built without the ${noun} “${dep.label}”: it could not be created.`)\n result.briefLines.push(`Leave the ${noun} “${dep.label}” out of the “${section?.name}” section: it could not be created.`)\n continue\n }\n const blocks = capability?.pageBlocks?.length ? ` the ${capability.pageBlocks.join(' or ')} block` : ''\n result.notes.push(\n `Built without${blocks || ` the ${noun}`}: the ${noun} “${dep.label}” could not be created.`,\n )\n result.briefLines.push(\n `${section ? `Build the “${section.name}” section` : 'Build the page'} without the ${noun} “${dep.label}”${blocks ? ` and without${blocks}` : ''}: it could not be created.`,\n )\n } else {\n result.notes.push(`Built without the ${noun} “${dep.label}”: it could not be created.`)\n }\n }\n return result\n}\n\n/** The dataset a form unit writes to, by its `new:` name lowercased; `null` for any other unit (AGL-3616). */\nexport function aiBuildUnitWritesTo(unit: Pick<AiBuildUnit, 'creation'>): string | null {\n const ref = unit.creation?.kind === 'form' ? unit.creation.writesTo : null\n return isAiPlanNewRef(ref) ? aiBuildRefName(ref) : null\n}\n\n/** What each creation is called in a note. */\nexport function aiBuildCreationNoun(kind: AiBuildPlanCreateKind): string {\n return kind === 'email' ? 'email design' : kind === 'theme-change' ? 'theme change' : kind\n}\n\n/**\n * The brief lines a page is told about the items its sections place and\n * that were built: the block to put there, in the owner's words.\n */\nexport function aiBuildPlacedItemLines(\n unit: AiBuildUnit,\n context: {\n units: readonly AiBuildUnit[]\n ledger: readonly AiJobItemLedger[]\n ops?: AiBuildOps\n /** Operations whose items the platform places itself (a listing), so the page is told nothing of them. */\n placedByCode?: readonly string[]\n },\n): string[] {\n if (!unit.screen) return []\n const rows = new Map(context.ledger.map((row) => [row.slot, row]))\n const lines: string[] = []\n for (const section of unit.screen.sections) {\n // One line per block a section places, naming every built item it shows:\n // a section listing four events places the Event List once (AGL-3743).\n const placed = new Map<string, { blocks: readonly string[]; noun: string; labels: string[] }>()\n for (const { dep, capability } of aiBuildSectionItems(section, context.units, context.ops)) {\n const row = rows.get(dep.slot)\n if (!row || !aiBuildItemDelivered(row)) continue\n if (context.placedByCode?.includes(dep.op)) continue\n const blocks = capability?.pageBlocks ?? []\n if (!blocks.length) continue\n const key = aiBuildBlocksKey(blocks)\n const entry = placed.get(key) ?? { blocks, noun: capability?.noun ?? dep.op, labels: [] }\n entry.labels.push(`“${dep.label}”`)\n placed.set(key, entry)\n }\n for (const { blocks, noun, labels } of placed.values()) {\n const named =\n labels.length === 1\n ? `the ${noun} ${labels[0]}`\n : `the ${noun}s ${labels.slice(0, -1).join(', ')} and ${labels[labels.length - 1]}`\n lines.push(`In the “${section.name}” section, place the ${blocks.join(' or ')} block for ${named}.`)\n }\n }\n return lines\n}\n\n/** The items a page section places, each with its capability, in the order its uses name them. */\nfunction aiBuildSectionItems(\n section: { uses: readonly string[] },\n units: readonly AiBuildUnit[],\n ops: AiBuildOps | undefined,\n): Array<{ dep: AiBuildUnit; capability: PluginAiCapability | undefined }> {\n const found: Array<{ dep: AiBuildUnit; capability: PluginAiCapability | undefined }> = []\n for (const ref of section.uses) {\n if (!isAiPlanNewRef(ref)) continue\n const dep = units.find((one) => one.item && one.item.name.toLowerCase() === aiBuildRefName(ref))\n if (dep?.item) found.push({ dep, capability: ops?.get(dep.op) })\n }\n return found\n}\n\n/** The blocks a section's built items place, each set as one key; `except` leaves one item out. */\nfunction aiBuildSectionDeliveredBlocks(\n section: { uses: readonly string[] },\n context: { units: readonly AiBuildUnit[]; rows: ReadonlyMap<string, AiJobItemLedger>; ops?: AiBuildOps; except: string },\n): Set<string> {\n const keys = new Set<string>()\n for (const { dep, capability } of aiBuildSectionItems(section, context.units, context.ops)) {\n if (dep.slot === context.except || !capability?.pageBlocks?.length) continue\n const row = context.rows.get(dep.slot)\n if (row && aiBuildItemDelivered(row)) keys.add(aiBuildBlocksKey(capability.pageBlocks))\n }\n return keys\n}\n\nfunction aiBuildBlocksKey(blocks: readonly string[]): string {\n return [...blocks].sort().join('|')\n}\n\n/** What a build came to: whether anything was delivered, and whether anything is left. */\nexport function aiBuildSettlement(ledger: readonly AiJobItemLedger[]): {\n delivered: boolean\n open: boolean\n failed: number\n} {\n return {\n delivered: ledger.some(aiBuildItemDelivered),\n open: ledger.some(aiBuildItemOpen),\n failed: ledger.filter((row) => row.status === 'failed').length,\n }\n}\n\n/**\n * The ledger Try again runs (AGL-3616): every failed item back to `pending`\n * on its next attempt, with the items left unbuilt because of it — skipped,\n * or degraded with no draft — and every item the build never reached. An\n * item that succeeded is never run again, and a degraded page that has its\n * draft keeps it, with a note that the page needs an edit. `retried` names\n * the slots that will run, which is what the estimate is shown for.\n */\nexport function aiBuildRetryLedger(\n ledger: readonly AiJobItemLedger[],\n units: readonly AiBuildUnit[],\n): { ledger: AiJobItemLedger[]; retried: string[] } {\n const failed = new Set(ledger.filter((row) => row.status === 'failed').map((row) => row.slot))\n const dependents = new Map<string, string[]>()\n for (const unit of units) {\n for (const dep of unit.deps) dependents.set(dep, [...(dependents.get(dep) ?? []), unit.slot])\n }\n // Everything downstream of a failed item, transitively.\n const downstream = new Set<string>()\n const queue = [...failed]\n while (queue.length) {\n const slot = queue.shift() as string\n for (const next of dependents.get(slot) ?? []) {\n if (downstream.has(next)) continue\n downstream.add(next)\n queue.push(next)\n }\n }\n const retried: string[] = []\n const next = ledger.map((row): AiJobItemLedger => {\n const again =\n row.status === 'failed' ||\n (row.status === 'skipped' && (downstream.has(row.slot) || !(row.degradedBy ?? []).length)) ||\n (row.status === 'degraded' && downstream.has(row.slot) && !row.outputs.length)\n if (again) {\n retried.push(row.slot)\n return {\n ...row,\n status: 'pending',\n attempt: row.attempt + 1,\n attemptCredits: 0,\n failure: null,\n note: null,\n degradedBy: [],\n settledAt: null,\n }\n }\n if (row.status === 'degraded' && downstream.has(row.slot) && row.outputs.length) {\n return {\n ...row,\n note: `${row.note ? `${row.note} ` : ''}It keeps its draft: once the rest is built, edit this page to add what it is missing.`,\n }\n }\n return row\n })\n return { ledger: next, retried }\n}\n\n/**\n * Units read back off a ledger alone (AGL-3616), for a job whose units are\n * not a build plan's — a site scaffold's: each row as its unit, and every\n * page built after the layouts and forms the ledger holds.\n */\nexport function aiLedgerUnits(ledger: readonly AiJobItemLedger[]): AiBuildUnit[] {\n const creations = ledger.filter((row) => row.op === 'layout' || row.op === 'form').map((row) => row.slot)\n return ledger.map((row) => ({\n slot: row.slot,\n op: row.op,\n label: row.label,\n deps: row.op === 'page' ? creations : [],\n }))\n}\n\n/**\n * What the job drawer says under an item another plugin's writer made: a\n * draft, or, for setup its writer saves live (`live`, a CRM pipeline or\n * field, AGL-3746), that it was saved. A writer that went live only when the\n * member may (an event the publishing role publishes, AGL-3755) reports\n * `live: false` for one it kept as a draft, with its `notice` saying why.\n */\nexport function aiBuildItemOutputNote(\n capability: Pick<PluginAiCapability, 'where' | 'live'>,\n written?: Pick<PluginDraftRecord, 'live' | 'notice'>,\n): string {\n const live = written?.live ?? capability.live\n const said = live ? `Live now, in ${capability.where}.` : `A draft, in ${capability.where}.`\n const notice = written?.notice?.trim()\n return notice ? `${said} ${notice}` : said\n}\n"],"names":["pluginAiCapabilityArgsProblems","AI_PLAN_NEW_REF_PREFIX","isAiPlanNewRef","AI_BUILD_STORE_OP","AI_BUILD_STORE_PAGES_LABEL","AI_BUILD_STORE_SLOT","aiBuildMakesStore","aiBuildStorePagesAdded","AI_SITE_HOME_FIRST_LABEL","AI_SITE_MAX_SECTIONS","AI_SITE_PASS_CREDITS","aiCreationMeasuredCredits","aiJobPlanCreditEstimate","aiJobPlanCreditRange","aiSitePlanIsHome","aiStandaloneScreenCreditRange","AI_CREDIT_RANGE_ZERO","AI_MEASURED_PASS_CREDITS","aiCreditRangeAdd","aiCreditRangeOf","aiCreditRangeOrdered","AI_BUILD_LIMITS","units","pages","freePages","aiBuildFreePageCapNote","plan","freeTaste","cap","screens","length","AI_BUILD_CREATE_KINDS","AI_BUILD_STRUCTURAL_OPS","AI_BUILD_THEME_OP","AI_BUILD_UNIT_CREATE_KINDS","AI_BUILD_MADE_INPUT","AI_BUILD_PUBLISH_INPUT","creationOp","creation","kind","namedSlots","slots","Map","create","forEach","index","includes","set","name","toLowerCase","item","items","slot","aiBuildRefName","ref","slice","trim","aiBuildItemArgRefs","args","refs","take","value","part","split","push","Object","values","Array","isArray","aiBuildScreenRefs","screen","layout","template","duplicateOf","sections","flatMap","section","uses","filter","aiBuildUnits","pageSlots","title","has","depsOf","self","deps","get","undefined","op","label","writesTo","dependsOn","aiBuildUnitIsPlatform","unit","aiBuildOrder","ordered","placed","Set","known","map","next","find","every","dep","add","aiBuildGraphProblems","problems","aiBuildPageLimit","aiBuildPlanShapeRefusal","options","counts","slugs","slug","ops","refusal","aiBuildThemeRefusal","graph","capability","freeAllowed","aiArticle","noun","argsSchema","join","count","maxPerPlan","list","aiBuildPlanMissingInput","questions","question","missingInput","why","AI_BUILD_NEEDS_INPUT_CODE","aiBuildPlanInputFields","fields","one","asked","inputFields","field","arg","shape","pattern","source","test","unitPasses","aiBuildUnitCreditEstimate","credits","Math","max","floor","estimateCredits","aiBuildCreditEstimate","reduce","total","aiJobCreditEstimate","aiBuildUnitCreditRange","ceiling","standalone","passes","ceil","median","p90","aiBuildCreditRange","aiJobCreditRange","aiBuildFirstPagePlan","findIndex","bySlot","keep","queue","shift","size","at","kept","entry","smaller","embeds","embed","where","storePages","aiBuildSmaller","aiBuildInitialLedger","status","attempt","creditsSpent","attemptCredits","creditsRefunded","failure","outputs","OPEN","aiBuildItemOpen","row","aiBuildItemDelivered","aiBuildNextUnit","ledger","rows","aiBuildDegradation","context","result","skip","degradedBy","notes","dropped","briefLines","aiBuildCreationNoun","degrade","aiBuildUnitWritesTo","madeAPage","some","made","blockStays","Boolean","pageBlocks","aiBuildSectionDeliveredBlocks","except","aiBuildBlocksKey","blocks","aiBuildPlacedItemLines","lines","aiBuildSectionItems","placedByCode","key","labels","named","found","keys","sort","aiBuildSettlement","delivered","open","failed","aiBuildRetryLedger","dependents","downstream","retried","again","note","settledAt","aiLedgerUnits","creations","aiBuildItemOutputNote","written","live","said","notice"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SACEA,8BAA8B,QAEzB,qDAAoD;AAE3D,SACEC,sBAAsB,EACtBC,cAAc,QAMT,qBAAiB;AAExB,SACEC,iBAAiB,EACjBC,0BAA0B,EAC1BC,mBAAmB,EACnBC,iBAAiB,EACjBC,sBAAsB,QACjB,4BAAwB;AAC/B,SACEC,wBAAwB,EACxBC,oBAAoB,EACpBC,oBAAoB,EACpBC,yBAAyB,EACzBC,uBAAuB,EACvBC,oBAAoB,EACpBC,gBAAgB,EAChBC,6BAA6B,QACxB,mBAAe;AACtB,SACEC,oBAAoB,EACpBC,wBAAwB,EACxBC,gBAAgB,EAChBC,eAAe,EACfC,oBAAoB,QAGf,0BAAsB;AAE7B;;;;;;;;;;;;;;;;;CAiBC,GAED,sFAAsF,GACtF,OAAO,MA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,OAAOoG,IAAIpG,KAAK;YAChBJ,MAAMwG,IAAIrG,EAAE,KAAK,SAASqJ,YAAY,EAAE;QAC1C,CAAA;AACF;AAEA;;;;;;CAMC,GACD,OAAO,SAASC,sBACdzH,UAAsD,EACtD0H,OAAoD;;QAIrCA;IAFf,MAAMC,eAAOD,2BAAAA,QAASC,IAAI,mBAAI3H,WAAW2H,IAAI;IAC7C,MAAMC,OAAOD,OAAO,CAAC,aAAa,EAAE3H,WAAW2D,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,YAAY,EAAE3D,WAAW2D,KAAK,CAAC,CAAC,CAAC;IAC5F,MAAMkE,SAASH,4BAAAA,kBAAAA,QAASG,MAAM,qBAAfH,gBAAiBvL,IAAI;IACpC,OAAO0L,SAAS,GAAGD,KAAK,CAAC,EAAEC,QAAQ,GAAGD;AACxC"}
|
|
@@ -196,6 +196,21 @@ export interface AiBuildItem {
|
|
|
196
196
|
/** The most it can cost in credits, from its capability, recorded when the plan is kept. */
|
|
197
197
|
credits?: number;
|
|
198
198
|
}
|
|
199
|
+
/**
|
|
200
|
+
* Something a `build` plan's brief asks for that the plan does not build
|
|
201
|
+
* (AGL-4087): a page or a feature the site has no way to make work, or more
|
|
202
|
+
* than one build holds. Named in the brief's words, with why, so the member
|
|
203
|
+
* reads it before confirming. A Free build of 2026-10-28 asked for a home and
|
|
204
|
+
* a "review helper" page that writes a review draft from a customer's
|
|
205
|
+
* choices; its plan held the home alone, whose sections still sent visitors
|
|
206
|
+
* to the helper, and nothing said the helper was left out.
|
|
207
|
+
*/
|
|
208
|
+
export interface AiBuildPlanLeftOut {
|
|
209
|
+
/** What the brief asks for, in its own words. */
|
|
210
|
+
asked: string;
|
|
211
|
+
/** Why the plan does not build it, in one sentence. */
|
|
212
|
+
why: string;
|
|
213
|
+
}
|
|
199
214
|
export interface AiBuildPlan {
|
|
200
215
|
reuse: AiBuildPlanReuse[];
|
|
201
216
|
create: AiBuildPlanCreate[];
|
|
@@ -210,6 +225,12 @@ export interface AiBuildPlan {
|
|
|
210
225
|
* Absent is none: every other kind's plan.
|
|
211
226
|
*/
|
|
212
227
|
items?: AiBuildItem[];
|
|
228
|
+
/**
|
|
229
|
+
* What a `build` plan's brief asks for that it does not build (AGL-4087).
|
|
230
|
+
* Absent is none: every other kind's plan, a build kept before the list
|
|
231
|
+
* existed, and a build that makes all of it.
|
|
232
|
+
*/
|
|
233
|
+
leftOut?: AiBuildPlanLeftOut[];
|
|
213
234
|
/**
|
|
214
235
|
* The store pages a `build` adds where its plan turns the site into a store
|
|
215
236
|
* (AGL-3676): worked out by code as the plan is kept, never by the model,
|
|
@@ -260,6 +281,8 @@ export declare const AI_BUILD_PLAN_LIMITS: {
|
|
|
260
281
|
readonly dependsOn: 8;
|
|
261
282
|
/** The arguments one item carries, as JSON. */
|
|
262
283
|
readonly argsChars: 2000;
|
|
284
|
+
/** What a build plan says it leaves out (AGL-4087); past it the rest is cut, never refused. */
|
|
285
|
+
readonly leftOut: 8;
|
|
263
286
|
};
|
|
264
287
|
/**
|
|
265
288
|
* The plan as a strict tool's input schema. Only the keywords strict
|
|
@@ -296,10 +319,11 @@ export declare const AI_BUILD_PLAN_EMBEDS_TOOL: AiTool;
|
|
|
296
319
|
export declare const AI_BUILD_PLAN_RECORDS_TOOL: AiTool;
|
|
297
320
|
export declare const AI_BUILD_PLAN_EMBEDS_RECORDS_TOOL: AiTool;
|
|
298
321
|
/**
|
|
299
|
-
* Any plan tool with a build's items (AGL-3616)
|
|
300
|
-
* job. The items' arguments travel as
|
|
301
|
-
* request lists per operation, so the tool
|
|
302
|
-
* whichever plugins registered operations, and
|
|
322
|
+
* Any plan tool with a build's items (AGL-3616) and what it leaves out
|
|
323
|
+
* (AGL-4087), offered only to a `build` job. The items' arguments travel as
|
|
324
|
+
* one JSON string whose fields the request lists per operation, so the tool
|
|
325
|
+
* stays byte for byte the same whichever plugins registered operations, and
|
|
326
|
+
* the prompt cache keeps it.
|
|
303
327
|
*/
|
|
304
328
|
export declare function withBuildItems(tool: AiTool): AiTool;
|
|
305
329
|
/** The most words a plan's photo words keep. */
|
|
@@ -119,7 +119,8 @@ export const AI_BUILD_ITEM_DEGRADES = [
|
|
|
119
119
|
items: 500,
|
|
120
120
|
/** A build plan's items (AGL-3616). */ buildItems: 16,
|
|
121
121
|
/** What one item depends on. */ dependsOn: 8,
|
|
122
|
-
/** The arguments one item carries, as JSON. */ argsChars: 2000
|
|
122
|
+
/** The arguments one item carries, as JSON. */ argsChars: 2000,
|
|
123
|
+
/** What a build plan says it leaves out (AGL-4087); past it the rest is cut, never refused. */ leftOut: 8
|
|
123
124
|
};
|
|
124
125
|
const string = (description)=>({
|
|
125
126
|
type: 'string',
|
|
@@ -419,20 +420,39 @@ const ITEMS_SCHEMA = {
|
|
|
419
420
|
}
|
|
420
421
|
}
|
|
421
422
|
};
|
|
423
|
+
const LEFT_OUT_SCHEMA = {
|
|
424
|
+
type: 'array',
|
|
425
|
+
description: 'What the brief asks for that this plan does not build: a page or a feature the site has no way to make work, or more than this build holds. Empty when the plan builds everything the brief asks for.',
|
|
426
|
+
items: {
|
|
427
|
+
type: 'object',
|
|
428
|
+
additionalProperties: false,
|
|
429
|
+
required: [
|
|
430
|
+
'asked',
|
|
431
|
+
'why'
|
|
432
|
+
],
|
|
433
|
+
properties: {
|
|
434
|
+
asked: string(`What the brief asks for, in its own words, ${atMost()}.`),
|
|
435
|
+
why: string(`Why this build does not make it, in one sentence for the site owner, ${atMost()}.`)
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
};
|
|
422
439
|
/**
|
|
423
|
-
* Any plan tool with a build's items (AGL-3616)
|
|
424
|
-
* job. The items' arguments travel as
|
|
425
|
-
* request lists per operation, so the tool
|
|
426
|
-
* whichever plugins registered operations, and
|
|
440
|
+
* Any plan tool with a build's items (AGL-3616) and what it leaves out
|
|
441
|
+
* (AGL-4087), offered only to a `build` job. The items' arguments travel as
|
|
442
|
+
* one JSON string whose fields the request lists per operation, so the tool
|
|
443
|
+
* stays byte for byte the same whichever plugins registered operations, and
|
|
444
|
+
* the prompt cache keeps it.
|
|
427
445
|
*/ export function withBuildItems(tool) {
|
|
428
446
|
return _extends({}, tool, {
|
|
429
447
|
inputSchema: _extends({}, tool.inputSchema, {
|
|
430
448
|
required: [
|
|
431
449
|
...tool.inputSchema['required'],
|
|
432
|
-
'items'
|
|
450
|
+
'items',
|
|
451
|
+
'leftOut'
|
|
433
452
|
],
|
|
434
453
|
properties: _extends({}, tool.inputSchema['properties'], {
|
|
435
|
-
items: ITEMS_SCHEMA
|
|
454
|
+
items: ITEMS_SCHEMA,
|
|
455
|
+
leftOut: LEFT_OUT_SCHEMA
|
|
436
456
|
})
|
|
437
457
|
})
|
|
438
458
|
});
|
|
@@ -607,7 +627,7 @@ export function parseAiBuildPlan(input) {
|
|
|
607
627
|
};
|
|
608
628
|
};
|
|
609
629
|
try {
|
|
610
|
-
var _root_embeds, _root_items;
|
|
630
|
+
var _root_embeds, _root_items, _root_leftOut;
|
|
611
631
|
const root = record(input, 'plan');
|
|
612
632
|
const reuse = list(root['reuse'], 'reuse', AI_BUILD_PLAN_LIMITS.reuse).map((raw, index)=>{
|
|
613
633
|
const entry = record(raw, `reuse[${index}]`);
|
|
@@ -712,6 +732,24 @@ export function parseAiBuildPlan(input) {
|
|
|
712
732
|
credits: Math.max(0, Math.floor(entry['credits']))
|
|
713
733
|
} : {});
|
|
714
734
|
});
|
|
735
|
+
// What a build leaves out is read for the member, never refused (AGL-4087):
|
|
736
|
+
// past the limit the rest is cut, and an entry that names nothing is dropped.
|
|
737
|
+
const leftOutRaw = (_root_leftOut = root['leftOut']) != null ? _root_leftOut : [];
|
|
738
|
+
if (!Array.isArray(leftOutRaw)) throw new PlanShapeError('leftOut is not a list');
|
|
739
|
+
if (leftOutRaw.length > AI_BUILD_PLAN_LIMITS.leftOut) {
|
|
740
|
+
repairs.push(`leftOut listed ${leftOutRaw.length}; kept the first ${AI_BUILD_PLAN_LIMITS.leftOut}`);
|
|
741
|
+
}
|
|
742
|
+
const leftOut = leftOutRaw.slice(0, AI_BUILD_PLAN_LIMITS.leftOut).flatMap((raw, index)=>{
|
|
743
|
+
var _entry_why;
|
|
744
|
+
const entry = record(raw, `leftOut[${index}]`);
|
|
745
|
+
const asked = text(entry['asked'], `leftOut[${index}].asked`);
|
|
746
|
+
return asked ? [
|
|
747
|
+
{
|
|
748
|
+
asked,
|
|
749
|
+
why: text((_entry_why = entry['why']) != null ? _entry_why : '', `leftOut[${index}].why`)
|
|
750
|
+
}
|
|
751
|
+
] : [];
|
|
752
|
+
});
|
|
715
753
|
// A language that is no code is dropped, never refused (AGL-3750): the
|
|
716
754
|
// site keeps the language it has.
|
|
717
755
|
const language = siteLanguageCode(root['language']);
|
|
@@ -724,7 +762,7 @@ export function parseAiBuildPlan(input) {
|
|
|
724
762
|
repairs.push(`photoWords "${root['photoWords'].trim().slice(0, 40)}" is not plain English; ignored`);
|
|
725
763
|
}
|
|
726
764
|
// A plan whose brief asks for no player carries no list, as it did before the list existed;
|
|
727
|
-
// so does a plan with no items.
|
|
765
|
+
// so does a plan with no items, and one that leaves nothing out.
|
|
728
766
|
return {
|
|
729
767
|
ok: true,
|
|
730
768
|
plan: _extends({
|
|
@@ -735,6 +773,8 @@ export function parseAiBuildPlan(input) {
|
|
|
735
773
|
embeds
|
|
736
774
|
} : {}, items.length ? {
|
|
737
775
|
items
|
|
776
|
+
} : {}, leftOut.length ? {
|
|
777
|
+
leftOut
|
|
738
778
|
} : {}, language ? {
|
|
739
779
|
language
|
|
740
780
|
} : {}, photoWords ? {
|