@aglyn/plugins-ai 1.0.0-beta.240 → 1.0.0-beta.242
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/components/ai-job-links.d.ts +17 -0
- package/src/lib/components/ai-job-links.js +63 -0
- package/src/lib/components/ai-job-links.js.map +1 -1
- package/src/lib/components/ai-job-plan.component.js +8 -1
- package/src/lib/components/ai-job-plan.component.js.map +1 -1
- package/src/lib/components/ai-site-build-page.component.js +7 -1
- package/src/lib/components/ai-site-build-page.component.js.map +1 -1
- package/src/lib/components/ai-store-finish-card.component.d.ts +28 -0
- package/src/lib/components/ai-store-finish-card.component.js +116 -0
- package/src/lib/components/ai-store-finish-card.component.js.map +1 -0
- package/src/lib/components/assist-build-card.component.js +12 -1
- package/src/lib/components/assist-build-card.component.js.map +1 -1
- package/src/lib/jobs/ai-job-build-step.d.ts +45 -1
- package/src/lib/jobs/ai-job-build-step.js +283 -7
- package/src/lib/jobs/ai-job-build-step.js.map +1 -1
- package/src/lib/jobs/ai-job-drafts.d.ts +9 -1
- package/src/lib/jobs/ai-job-drafts.js +4 -1
- package/src/lib/jobs/ai-job-drafts.js.map +1 -1
- package/src/lib/jobs/ai-job-layout-language.d.ts +3 -0
- package/src/lib/jobs/ai-job-layout-language.js +4 -2
- package/src/lib/jobs/ai-job-layout-language.js.map +1 -1
- package/src/lib/jobs/ai-job-layout-step.js +3 -1
- package/src/lib/jobs/ai-job-layout-step.js.map +1 -1
- package/src/lib/jobs/ai-job-page-language.d.ts +2 -1
- package/src/lib/jobs/ai-job-page-language.js +19 -7
- package/src/lib/jobs/ai-job-page-language.js.map +1 -1
- package/src/lib/jobs/ai-job-page-sections.d.ts +11 -0
- package/src/lib/jobs/ai-job-page-sections.js +40 -3
- package/src/lib/jobs/ai-job-page-sections.js.map +1 -1
- package/src/lib/jobs/ai-job-page-step.d.ts +2 -1
- package/src/lib/jobs/ai-job-page-step.js +19 -8
- package/src/lib/jobs/ai-job-page-step.js.map +1 -1
- package/src/lib/jobs/ai-job-plan-step.d.ts +12 -0
- package/src/lib/jobs/ai-job-plan-step.js +41 -7
- package/src/lib/jobs/ai-job-plan-step.js.map +1 -1
- package/src/lib/jobs/ai-job-site-content.js +3 -2
- package/src/lib/jobs/ai-job-site-content.js.map +1 -1
- package/src/lib/jobs/ai-job-site-datasets.d.ts +76 -2
- package/src/lib/jobs/ai-job-site-datasets.js +206 -13
- package/src/lib/jobs/ai-job-site-datasets.js.map +1 -1
- package/src/lib/jobs/ai-job-site-step.d.ts +18 -2
- package/src/lib/jobs/ai-job-site-step.js +109 -22
- package/src/lib/jobs/ai-job-site-step.js.map +1 -1
- package/src/lib/jobs/ai-job-site-store-pages.d.ts +75 -0
- package/src/lib/jobs/ai-job-site-store-pages.js +195 -0
- package/src/lib/jobs/ai-job-site-store-pages.js.map +1 -0
- package/src/lib/jobs/ai-job-store-links-layout.d.ts +71 -0
- package/src/lib/jobs/ai-job-store-links-layout.js +95 -0
- package/src/lib/jobs/ai-job-store-links-layout.js.map +1 -0
- package/src/lib/jobs/ai-layout-stock-photos.d.ts +129 -8
- package/src/lib/jobs/ai-layout-stock-photos.js +919 -75
- package/src/lib/jobs/ai-layout-stock-photos.js.map +1 -1
- package/src/lib/jobs/ai-site-publish.d.ts +18 -0
- package/src/lib/jobs/ai-site-publish.js +76 -15
- package/src/lib/jobs/ai-site-publish.js.map +1 -1
- package/src/lib/jobs/fixtures/ai-stock-photo-ember-oak-hits.d.ts +43 -0
- package/src/lib/jobs/fixtures/ai-stock-photo-ember-oak-hits.js +61 -0
- package/src/lib/jobs/fixtures/ai-stock-photo-ember-oak-hits.js.map +1 -0
- package/src/lib/jobs/fixtures/ai-stock-photo-saltmarsh-recordings.d.ts +39 -0
- package/src/lib/jobs/fixtures/ai-stock-photo-saltmarsh-recordings.js +508 -0
- package/src/lib/jobs/fixtures/ai-stock-photo-saltmarsh-recordings.js.map +1 -0
- package/src/lib/layout-language/ai-layout-compiler.js +25 -2
- package/src/lib/layout-language/ai-layout-compiler.js.map +1 -1
- package/src/lib/layout-language/ai-layout-frame.d.ts +10 -0
- package/src/lib/layout-language/ai-layout-frame.js +58 -4
- package/src/lib/layout-language/ai-layout-frame.js.map +1 -1
- package/src/lib/layout-language/ai-layout-listings.d.ts +6 -0
- package/src/lib/layout-language/ai-layout-listings.js +3 -0
- package/src/lib/layout-language/ai-layout-listings.js.map +1 -1
- package/src/lib/model/ai-build-job.d.ts +2 -0
- package/src/lib/model/ai-build-job.js +23 -3
- package/src/lib/model/ai-build-job.js.map +1 -1
- package/src/lib/model/ai-build-plan.d.ts +7 -0
- 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-build-store-pages.d.ts +133 -0
- package/src/lib/model/ai-build-store-pages.js +209 -0
- package/src/lib/model/ai-build-store-pages.js.map +1 -0
- package/src/lib/model/ai-layout-store-links.d.ts +64 -0
- package/src/lib/model/ai-layout-store-links.js +165 -0
- package/src/lib/model/ai-layout-store-links.js.map +1 -0
- package/src/lib/model/ai-site-inventory.d.ts +5 -0
- package/src/lib/model/ai-site-inventory.js.map +1 -1
- package/src/lib/model/ai-site-store-pages.d.ts +192 -0
- package/src/lib/model/ai-site-store-pages.js +383 -0
- package/src/lib/model/ai-site-store-pages.js.map +1 -0
- package/src/lib/runtime/site-inventory.js +8 -3
- package/src/lib/runtime/site-inventory.js.map +1 -1
- package/src/lib/testing/stand-in-dataset-index.js +8 -4
- package/src/lib/testing/stand-in-dataset-index.js.map +1 -1
|
@@ -22,6 +22,11 @@ import { AI_STEP_TIERS } from "../providers/catalog.js";
|
|
|
22
22
|
import { aiModelForStep } from "../providers/routing.js";
|
|
23
23
|
import { AI_DATASET_MAX_TOKENS, AI_DATASET_STEP, aiDatasetDraftContent, generateAiDataset } from "../runtime/ai-dataset-generation.js";
|
|
24
24
|
import { aiLayoutListingId, aiLayoutRecordsPlacements } from "../layout-language/ai-layout-listings.js";
|
|
25
|
+
import { aiLayoutStarterPhotos } from "../layout-language/ai-layout-pictures.js";
|
|
26
|
+
import { aiSiteWords } from "../model/ai-site-job.js";
|
|
27
|
+
import { aiOriginJobId } from "./ai-job-draft-ids.js";
|
|
28
|
+
import { aiSiteProductPhotoSrc } from "./ai-job-site-content.js";
|
|
29
|
+
import { aiLayoutStockPhotoSource } from "./ai-layout-stock-photos.js";
|
|
25
30
|
import { AI_DATASET_DRAFT_RESOURCE } from "./ai-build-unit-outcome.js";
|
|
26
31
|
import { aiJobStepBudget } from "./ai-job-budget.js";
|
|
27
32
|
import { aiGenerationSpent, aiUnspentOutcome } from "./ai-job-generation.js";
|
|
@@ -49,10 +54,20 @@ import { aiPluginDraftAdmissionRefusal } from "./ai-job-plugin-drafts.js";
|
|
|
49
54
|
* has: the member's role and `data.manage`, `release_data_store`,
|
|
50
55
|
* `dataStore` (Starter and up), `datasetsPerOrg` counted inside the create,
|
|
51
56
|
* `recordsPerDataset` and the storage band.
|
|
57
|
+
* - PICTURED where the plan lists it the way a gallery is listed (Zach,
|
|
58
|
+
* 2026-10-10: a ceramic artist's "Selected work" came back as text-only
|
|
59
|
+
* cards, where it had been an image-led gallery): a portfolio's pieces, a
|
|
60
|
+
* team, a menu, classes and events, and services or offerings whose
|
|
61
|
+
* section says it shows them in pictures (`aiSiteDatasetPicturesOf`). Such
|
|
62
|
+
* a dataset gets an Image field, and each record a stock photo of its own
|
|
63
|
+
* name in the site's craft, copied into the site's library — never one the
|
|
64
|
+
* job already placed, else a starter photo — searched in code, so it
|
|
65
|
+
* costs no credits (`aiSiteDatasetRecordPhotos`).
|
|
52
66
|
* - LISTED by the pages built after it: each section naming it repeats over
|
|
53
67
|
* the dataset (`aiSiteDatasetListings`, a `records` listing the layout
|
|
54
|
-
* compiler draws
|
|
55
|
-
*
|
|
68
|
+
* compiler draws, its card led by the record's photo where it has one),
|
|
69
|
+
* and a page the plan made its record template binds its fields by id,
|
|
70
|
+
* its photo the record's, and keeps the address field the writer added.
|
|
56
71
|
*
|
|
57
72
|
* Where datasets cannot be created — the Free taste, Starter's two used up,
|
|
58
73
|
* the data store not released — the plan is told so and creates none, so its
|
|
@@ -63,6 +78,29 @@ import { aiPluginDraftAdmissionRefusal } from "./ai-job-plugin-drafts.js";
|
|
|
63
78
|
/** The resource the data plugin's writer is registered under. */ export const AI_SITE_DATASET_RESOURCE = AI_DATASET_DRAFT_RESOURCE;
|
|
64
79
|
/** What the site's plugin list calls the plugin, for "Turn on Data for this site". */ const DATA_PLUGIN_LABEL = 'Data';
|
|
65
80
|
/** The input a dataset unit's own job carries what it needs in. */ export const AI_SITE_DATASET_INPUT = 'siteDataset';
|
|
81
|
+
/** A list of questions, voices or plain facts: read, never pictured. */ const READ_ONLY_LIST = /\b(faqs?|questions?|q ?& ?a|answers?|testimonials?|reviews?|quotes?|voices|hours|opening|steps?|process|policies|policy|terms|stats?|numbers|figures|milestones|timeline|values|benefits|reasons|features|requirements|checklist|ingredients|donations?|needs|partners|sponsors|supporters|roles|positions|jobs|openings)\b/i;
|
|
82
|
+
/** A list of people: its photos are of the business's people. */ const PEOPLE_LIST = /\b(team|staff|people|crew|instructors?|teachers?|tutors?|stylists?|barbers?|therapists?|coaches?|trainers?|chefs?|doctors?|dentists?|hygienists?|practitioners?|artists?|musicians?|performers?|speakers?|founders?|members?)\b/i;
|
|
83
|
+
/** A list a visitor looks at before reading: pictured wherever it is listed. */ const PICTURED_LIST = /\b(portfolio|pieces?|works?|projects?|gallery|galleries|collections?|series|menus?|dishes|plates|drinks|cocktails|wines?|beers?|coffees?|pastries|cakes|products?|items|events?|classes|class|workshops?|courses?|retreats?|tours?|trips?|adventures?|experiences?|rooms?|suites?|cabins?|properties|listings|homes|venues?|spaces?|recipes?|artworks?|paintings?|prints?|photos?|photographs?|designs?|commissions?|builds?|vehicles?|animals?|pets?|plants?|flowers?|bouquets?|arrangements?|case studies)\b/i;
|
|
84
|
+
/** A section that says it shows its items in pictures: a gallery, a grid of photos, tiles. */ const PICTURED_SECTION = /\b(gallery|galleries|grid|images?|photos?|photographs?|pictures?|lightbox|portfolio|showcase|tiles?|visuals?|lookbook|carousel|slideshow|mosaic|thumbnails?)\b/i;
|
|
85
|
+
/**
|
|
86
|
+
* Whether a dataset's records carry a photo, read off the plan (AGL-3616):
|
|
87
|
+
* its name and the names of the sections that list it. Questions, voices and
|
|
88
|
+
* plain facts never; people as people; a list a visitor looks at — pieces,
|
|
89
|
+
* dishes, classes, events, rooms — always; any other list (services,
|
|
90
|
+
* offerings, programs) only where a section that lists it says it shows them
|
|
91
|
+
* in pictures, or names one of those. A dataset no page lists is not
|
|
92
|
+
* pictured. Pure.
|
|
93
|
+
*/ export function aiSiteDatasetPicturesOf(dataset, sections) {
|
|
94
|
+
if (!sections.length) return null;
|
|
95
|
+
const own = dataset.name;
|
|
96
|
+
if (READ_ONLY_LIST.test(own)) return null;
|
|
97
|
+
if (PEOPLE_LIST.test(own)) return 'people';
|
|
98
|
+
if (PICTURED_LIST.test(own)) return 'things';
|
|
99
|
+
if (sections.some((section)=>READ_ONLY_LIST.test(section) && !PICTURED_SECTION.test(section))) return null;
|
|
100
|
+
if (sections.some((section)=>PEOPLE_LIST.test(section))) return 'people';
|
|
101
|
+
if (sections.some((section)=>PICTURED_LIST.test(section) || PICTURED_SECTION.test(section))) return 'things';
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
66
104
|
/** What a dataset row says when its design could not be written: our failure, refunded. */ export const AI_SITE_DATASET_NOT_WRITTEN_COPY = 'This dataset could not be added this time.';
|
|
67
105
|
/** The note a written dataset carries on the job's page. */ export function aiSiteDatasetNote(records) {
|
|
68
106
|
return `${records} ${records === 1 ? 'record' : 'records'} to start, in Data. Edit them there and every page that lists them follows.`;
|
|
@@ -84,14 +122,18 @@ const str = (value)=>typeof value === 'string' ? value.trim() : '';
|
|
|
84
122
|
}
|
|
85
123
|
/** Where the plan lists a dataset, in words its design reads, whether a page is its record template, and the form that writes to it. */ export function aiSiteDatasetInputOf(dataset, screens, create = []) {
|
|
86
124
|
const shownIn = [];
|
|
125
|
+
const sectionNames = [];
|
|
87
126
|
for (const screen of screens){
|
|
88
127
|
for (const section of screen.sections){
|
|
89
128
|
if (!section.uses.some((ref)=>namesDataset(ref, dataset.name))) continue;
|
|
90
129
|
shownIn.push(`${screen.title} › ${section.name}${section.items ? ` (${section.items} items)` : ''}`);
|
|
130
|
+
sectionNames.push(section.name);
|
|
91
131
|
}
|
|
92
132
|
}
|
|
93
133
|
const recordPages = screens.some((screen)=>!!screen.record && namesDataset(screen.record.dataset, dataset.name));
|
|
94
134
|
const form = create.find((entry)=>entry.kind === 'form' && !!entry.writesTo && namesDataset(entry.writesTo, dataset.name));
|
|
135
|
+
// A form's dataset holds its submissions: nobody's photo.
|
|
136
|
+
const pictures = form ? null : aiSiteDatasetPicturesOf(dataset, sectionNames);
|
|
95
137
|
return _extends({
|
|
96
138
|
shownIn: shownIn.slice(0, 8),
|
|
97
139
|
recordPages
|
|
@@ -100,6 +142,8 @@ const str = (value)=>typeof value === 'string' ? value.trim() : '';
|
|
|
100
142
|
name: form.name,
|
|
101
143
|
fields: form.fields.slice(0, AI_SITE_FORM_DATASET_FIELDS_MAX)
|
|
102
144
|
}
|
|
145
|
+
} : {}, pictures ? {
|
|
146
|
+
pictures
|
|
103
147
|
} : {});
|
|
104
148
|
}
|
|
105
149
|
/** Whether a plan screen is the record template of a dataset the plan creates, and which. */ export function aiSiteRecordTemplateOf(screen) {
|
|
@@ -120,6 +164,8 @@ function datasetInputOf(job) {
|
|
|
120
164
|
name: str(form.name),
|
|
121
165
|
fields: Array.isArray(form.fields) ? form.fields.map(str).filter(Boolean).slice(0, AI_SITE_FORM_DATASET_FIELDS_MAX) : []
|
|
122
166
|
}
|
|
167
|
+
} : {}, raw.pictures === 'things' || raw.pictures === 'people' ? {
|
|
168
|
+
pictures: raw.pictures
|
|
123
169
|
} : {});
|
|
124
170
|
}
|
|
125
171
|
/** The most fields a form's dataset is designed with: the data plugin writer's own ceiling is higher. */ export const AI_SITE_FORM_DATASET_FIELDS_MAX = 12;
|
|
@@ -171,6 +217,110 @@ const limitReview = (message)=>({
|
|
|
171
217
|
message,
|
|
172
218
|
findings: []
|
|
173
219
|
});
|
|
220
|
+
/** The wall clock a dataset's photos may take inside its pass: the 20 seconds a page's pictures had (AGL-3660). */ export const AI_SITE_DATASET_PHOTOS_BUDGET_MS = 20000;
|
|
221
|
+
/** The field a pictured dataset's photo is kept in, where the plan gave it none. */ export const AI_SITE_DATASET_IMAGE_FIELD = 'Image';
|
|
222
|
+
/** A planned field that already names a record's photo. */ const IMAGE_FIELD_NAME = /^(?:main |cover |hero |featured? )?(?:image|photo|picture|photograph|thumbnail|headshot|portrait|cover)s?$/i;
|
|
223
|
+
/**
|
|
224
|
+
* A photo for each record of a pictured dataset (AGL-3616), in order: a stock
|
|
225
|
+
* photo of the record's own name, in the site's craft ("ceramic speckled
|
|
226
|
+
* serving bowl"), copied into the site's library, where the deployment has a
|
|
227
|
+
* stock library — never twice in the dataset nor one another part of the job
|
|
228
|
+
* placed, inside {@link AI_SITE_DATASET_PHOTOS_BUDGET_MS} — else a starter
|
|
229
|
+
* photo, as a page's empty picture takes one. A team is searched as the
|
|
230
|
+
* business's people. The photo is kept as the asset's CDN path, the form a
|
|
231
|
+
* product keeps (`aiSiteProductPhotoSrc`), so a replace in the library still
|
|
232
|
+
* reaches it. No AI model is asked, so no credits; never throws.
|
|
233
|
+
*/ export async function aiSiteDatasetRecordPhotos(input) {
|
|
234
|
+
const { job } = input;
|
|
235
|
+
if (!input.names.length || !job.hostId) return input.names.map(()=>({
|
|
236
|
+
src: null,
|
|
237
|
+
placed: null
|
|
238
|
+
}));
|
|
239
|
+
const people = input.pictures === 'people';
|
|
240
|
+
const slots = input.names.map((name, index)=>({
|
|
241
|
+
imageId: `record${index}`,
|
|
242
|
+
frameId: null,
|
|
243
|
+
iconId: null,
|
|
244
|
+
alt: name.trim() || input.name,
|
|
245
|
+
// The record card's own shape: a team's portraits stand, pieces sit wide.
|
|
246
|
+
aspect: people ? 4 / 5 : 4 / 3,
|
|
247
|
+
sectionIndex: 0,
|
|
248
|
+
role: people ? 'about' : 'gallery'
|
|
249
|
+
}));
|
|
250
|
+
const seed = `${job.$id}:records`;
|
|
251
|
+
let found = [];
|
|
252
|
+
try {
|
|
253
|
+
var _input_stockPhotos;
|
|
254
|
+
const source = ((_input_stockPhotos = input.stockPhotos) != null ? _input_stockPhotos : aiLayoutStockPhotoSource)(_extends({
|
|
255
|
+
hostId: job.hostId,
|
|
256
|
+
uid: job.createdBy,
|
|
257
|
+
seed,
|
|
258
|
+
business: aiSiteWords(job.inputs).about || job.brief,
|
|
259
|
+
sectionNames: [
|
|
260
|
+
input.name
|
|
261
|
+
],
|
|
262
|
+
jobId: aiOriginJobId(job),
|
|
263
|
+
// Each record may try its name, its object and the site's world.
|
|
264
|
+
searches: slots.length * 3
|
|
265
|
+
}, input.signal ? {
|
|
266
|
+
signal: input.signal
|
|
267
|
+
} : {}), {
|
|
268
|
+
budgetMs: AI_SITE_DATASET_PHOTOS_BUDGET_MS
|
|
269
|
+
});
|
|
270
|
+
if (source) found = await source(slots);
|
|
271
|
+
} catch (error) {
|
|
272
|
+
console.warn('ai site dataset: the stock photos failed; starter photos fill them', {
|
|
273
|
+
error: String(error)
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
const starters = aiLayoutStarterPhotos(slots, seed);
|
|
277
|
+
const hostId = job.hostId;
|
|
278
|
+
return slots.map((_slot, index)=>{
|
|
279
|
+
var _ref;
|
|
280
|
+
var _found_index, _found_index1, _starters_index;
|
|
281
|
+
const stock = aiSiteProductPhotoSrc((_found_index = found[index]) == null ? void 0 : _found_index.src, hostId);
|
|
282
|
+
if (stock) return {
|
|
283
|
+
src: stock,
|
|
284
|
+
placed: (_ref = (_found_index1 = found[index]) == null ? void 0 : _found_index1.src) != null ? _ref : null
|
|
285
|
+
};
|
|
286
|
+
return {
|
|
287
|
+
src: aiSiteProductPhotoSrc((_starters_index = starters[index]) == null ? void 0 : _starters_index.src, hostId),
|
|
288
|
+
placed: null
|
|
289
|
+
};
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* A designed dataset's content with its records' photos (AGL-3616): the
|
|
294
|
+
* planned field that names a photo ("Image", "Photo") becomes the data
|
|
295
|
+
* plugin's `image` field, else one called "Image" is added after the others,
|
|
296
|
+
* and each record holds its photo there; a record with none holds nothing.
|
|
297
|
+
* Pure.
|
|
298
|
+
*/ export function aiSiteDatasetContentWithPhotos(content, photos) {
|
|
299
|
+
const fields = Array.isArray(content['fields']) ? content['fields'] : [];
|
|
300
|
+
const named = fields.find((field)=>IMAGE_FIELD_NAME.test(str(field.name)));
|
|
301
|
+
const fieldName = named ? named.name : AI_SITE_DATASET_IMAGE_FIELD;
|
|
302
|
+
const nextFields = named ? fields.map((field)=>field === named ? _extends({}, field, {
|
|
303
|
+
type: 'image'
|
|
304
|
+
}) : field) : [
|
|
305
|
+
...fields,
|
|
306
|
+
{
|
|
307
|
+
name: AI_SITE_DATASET_IMAGE_FIELD,
|
|
308
|
+
type: 'image'
|
|
309
|
+
}
|
|
310
|
+
];
|
|
311
|
+
const records = Array.isArray(content['records']) ? content['records'] : [];
|
|
312
|
+
return _extends({}, content, {
|
|
313
|
+
fields: nextFields,
|
|
314
|
+
records: records.map((record, index)=>{
|
|
315
|
+
const next = _extends({}, record);
|
|
316
|
+
delete next[fieldName];
|
|
317
|
+
const photo = photos[index];
|
|
318
|
+
return photo ? _extends({}, next, {
|
|
319
|
+
[fieldName]: photo
|
|
320
|
+
}) : next;
|
|
321
|
+
})
|
|
322
|
+
});
|
|
323
|
+
}
|
|
174
324
|
/**
|
|
175
325
|
* The fields of a designed dataset that its records leave empty on most of
|
|
176
326
|
* them — every record, or more than half — by the id the data plugin gave
|
|
@@ -207,6 +357,8 @@ function proposalOf(output) {
|
|
|
207
357
|
})) : [],
|
|
208
358
|
recordNames: Array.isArray(raw.recordNames) ? raw.recordNames.map(str).filter(Boolean).slice(0, 12) : [],
|
|
209
359
|
addressField: str(raw.addressField) || null,
|
|
360
|
+
imageField: str(raw.imageField) || null,
|
|
361
|
+
photos: Array.isArray(raw.photos) ? raw.photos.map(str).filter((src)=>src.startsWith('media:')).slice(0, 24) : [],
|
|
210
362
|
sparseFields: Array.isArray(raw.sparseFields) ? raw.sparseFields.map(str).filter(Boolean) : []
|
|
211
363
|
};
|
|
212
364
|
}
|
|
@@ -216,9 +368,10 @@ function proposalOf(output) {
|
|
|
216
368
|
* plugin, under the creation's own id. A pass repeated after its write finds
|
|
217
369
|
* the dataset the writer wrote and reports it again, spending nothing.
|
|
218
370
|
*/ export function createAiSiteDatasetRunner(deps = {}) {
|
|
219
|
-
var _deps_generate, _deps_writerFor;
|
|
371
|
+
var _deps_generate, _deps_writerFor, _deps_photos;
|
|
220
372
|
const generate = (_deps_generate = deps.generate) != null ? _deps_generate : generateAiDataset;
|
|
221
373
|
const writerFor = (_deps_writerFor = deps.writerFor) != null ? _deps_writerFor : pluginResourceDraftWriter;
|
|
374
|
+
const photosFor = (_deps_photos = deps.photos) != null ? _deps_photos : aiSiteDatasetRecordPhotos;
|
|
222
375
|
return async (context)=>{
|
|
223
376
|
var _ref, _context_org, _facts_fields, _facts_addressField, _facts_fields1, _facts_records;
|
|
224
377
|
var _job_plan_create, _job_plan;
|
|
@@ -254,12 +407,13 @@ function proposalOf(output) {
|
|
|
254
407
|
id: job.$id
|
|
255
408
|
});
|
|
256
409
|
if (written) {
|
|
257
|
-
var _facts_fields2, _facts_addressField1;
|
|
410
|
+
var _facts_fields2, _facts_addressField1, _facts_imageField;
|
|
258
411
|
const facts = written.facts;
|
|
259
412
|
const again = output(written.id, written.name || creation.name, {
|
|
260
413
|
fields: (_facts_fields2 = facts.fields) != null ? _facts_fields2 : [],
|
|
261
414
|
recordNames: [],
|
|
262
|
-
addressField: (_facts_addressField1 = facts.addressField) != null ? _facts_addressField1 : null
|
|
415
|
+
addressField: (_facts_addressField1 = facts.addressField) != null ? _facts_addressField1 : null,
|
|
416
|
+
imageField: (_facts_imageField = facts.imageField) != null ? _facts_imageField : null
|
|
263
417
|
}, 0);
|
|
264
418
|
return aiUnspentOutcome(model, {
|
|
265
419
|
outputs: [
|
|
@@ -338,9 +492,27 @@ function proposalOf(output) {
|
|
|
338
492
|
if (generation.status === 'needs_input') return _extends({}, spent, {
|
|
339
493
|
failure: generation.message
|
|
340
494
|
});
|
|
341
|
-
const
|
|
495
|
+
const designed = aiDatasetDraftContent(creation.name, generation.value, {
|
|
342
496
|
recordPages: input.recordPages
|
|
343
497
|
});
|
|
498
|
+
// A list a visitor looks at keeps its records' photos (AGL-3616): searched
|
|
499
|
+
// in code, never asked of the model, so they cost no credits.
|
|
500
|
+
const photos = input.pictures ? await photosFor(_extends({
|
|
501
|
+
job,
|
|
502
|
+
name: creation.name,
|
|
503
|
+
names: generation.value.records.map((values)=>{
|
|
504
|
+
var _values_;
|
|
505
|
+
return (_values_ = values[0]) != null ? _values_ : '';
|
|
506
|
+
}),
|
|
507
|
+
pictures: input.pictures
|
|
508
|
+
}, signal ? {
|
|
509
|
+
signal
|
|
510
|
+
} : {})).catch(()=>[]) : [];
|
|
511
|
+
const content = input.pictures ? aiSiteDatasetContentWithPhotos(designed, generation.value.records.map((_values, index)=>{
|
|
512
|
+
var _ref;
|
|
513
|
+
var _photos_index;
|
|
514
|
+
return (_ref = (_photos_index = photos[index]) == null ? void 0 : _photos_index.src) != null ? _ref : null;
|
|
515
|
+
})) : designed;
|
|
344
516
|
// The data plugin's own rules, before anything is written: content we
|
|
345
517
|
// made that its model refuses is our failure, refunded.
|
|
346
518
|
const checked = keeper.writer.check(content, {
|
|
@@ -376,15 +548,23 @@ function proposalOf(output) {
|
|
|
376
548
|
});
|
|
377
549
|
}
|
|
378
550
|
const facts = result.facts;
|
|
379
|
-
const
|
|
551
|
+
const placed = photos.flatMap((photo)=>photo.placed ? [
|
|
552
|
+
photo.placed
|
|
553
|
+
] : []);
|
|
554
|
+
const proposal = _extends({
|
|
380
555
|
fields: (_facts_fields = facts.fields) != null ? _facts_fields : [],
|
|
381
556
|
recordNames: generation.value.records.map((values)=>{
|
|
382
557
|
var _values_;
|
|
383
558
|
return (_values_ = values[0]) != null ? _values_ : '';
|
|
384
559
|
}).filter(Boolean).slice(0, 12),
|
|
385
|
-
addressField: (_facts_addressField = facts.addressField) != null ? _facts_addressField : null
|
|
560
|
+
addressField: (_facts_addressField = facts.addressField) != null ? _facts_addressField : null
|
|
561
|
+
}, facts.imageField ? {
|
|
562
|
+
imageField: facts.imageField
|
|
563
|
+
} : {}, placed.length ? {
|
|
564
|
+
photos: placed
|
|
565
|
+
} : {}, {
|
|
386
566
|
sparseFields: aiDatasetSparseFields(generation.value, (_facts_fields1 = facts.fields) != null ? _facts_fields1 : [])
|
|
387
|
-
};
|
|
567
|
+
});
|
|
388
568
|
return _extends({}, spent, {
|
|
389
569
|
outputs: [
|
|
390
570
|
output(result.id, result.name, proposal, (_facts_records = facts.records) != null ? _facts_records : generation.value.records.length)
|
|
@@ -483,6 +663,8 @@ export const runAiSiteDatasetUnit = createAiSiteDatasetRunner();
|
|
|
483
663
|
datasetId: dataset.id
|
|
484
664
|
}, ((_dataset_fields = dataset.fields) == null ? void 0 : _dataset_fields.length) ? {
|
|
485
665
|
fields: dataset.fields
|
|
666
|
+
} : {}, dataset.imageField ? {
|
|
667
|
+
imageField: dataset.imageField
|
|
486
668
|
} : {}, {
|
|
487
669
|
placements
|
|
488
670
|
})
|
|
@@ -496,6 +678,7 @@ export const runAiSiteDatasetUnit = createAiSiteDatasetRunner();
|
|
|
496
678
|
* nowhere: the pages built without it write the items out.
|
|
497
679
|
*/ export function aiSiteDatasetListings(input) {
|
|
498
680
|
const made = input.datasets.flatMap((dataset)=>{
|
|
681
|
+
var _proposal_imageField;
|
|
499
682
|
const id = input.delivered.get(dataset.name.trim().toLowerCase());
|
|
500
683
|
const output = id ? input.outputs.find((entry)=>entry.resource === 'draft' && entry.draftResource === AI_SITE_DATASET_RESOURCE && entry.id === id) : undefined;
|
|
501
684
|
if (!id || !output) return [];
|
|
@@ -506,17 +689,27 @@ export const runAiSiteDatasetUnit = createAiSiteDatasetRunner();
|
|
|
506
689
|
// Placed by the name the plan's sections gave it.
|
|
507
690
|
name: dataset.name,
|
|
508
691
|
records: proposal.recordNames,
|
|
509
|
-
// The address field is the record page's, never a card's words;
|
|
510
|
-
//
|
|
692
|
+
// The address field is the record page's, never a card's words; the
|
|
693
|
+
// photo is the card's picture, never its words; a field most records
|
|
694
|
+
// leave empty is no card's either (AGL-3616).
|
|
511
695
|
fields: proposal.fields.filter((field, index)=>{
|
|
512
696
|
var _proposal_sparseFields;
|
|
513
|
-
return field.id !== proposal.addressField && (index === 0 || !((_proposal_sparseFields = proposal.sparseFields) == null ? void 0 : _proposal_sparseFields.includes(field.id)));
|
|
514
|
-
})
|
|
697
|
+
return field.id !== proposal.addressField && field.id !== proposal.imageField && (index === 0 || !((_proposal_sparseFields = proposal.sparseFields) == null ? void 0 : _proposal_sparseFields.includes(field.id)));
|
|
698
|
+
}),
|
|
699
|
+
imageField: (_proposal_imageField = proposal.imageField) != null ? _proposal_imageField : null
|
|
515
700
|
}
|
|
516
701
|
];
|
|
517
702
|
});
|
|
518
703
|
return aiDatasetListingsOf(made, input.screens);
|
|
519
704
|
}
|
|
705
|
+
/** The library photos the site's datasets' records show (AGL-3616), which a page does not place again. */ export function aiSiteDatasetPlacedPhotos(outputs) {
|
|
706
|
+
return [
|
|
707
|
+
...new Set(outputs.filter((output)=>output.resource === 'draft' && output.draftResource === AI_SITE_DATASET_RESOURCE).flatMap((output)=>{
|
|
708
|
+
var _proposalOf_photos;
|
|
709
|
+
return (_proposalOf_photos = proposalOf(output).photos) != null ? _proposalOf_photos : [];
|
|
710
|
+
}))
|
|
711
|
+
];
|
|
712
|
+
}
|
|
520
713
|
/** What a page is told about the datasets built before it. */ export function aiSiteDatasetBriefLines(outputs) {
|
|
521
714
|
const datasets = outputs.filter((output)=>output.resource === 'draft' && output.draftResource === AI_SITE_DATASET_RESOURCE);
|
|
522
715
|
return datasets.flatMap((output)=>{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/jobs/ai-job-site-datasets.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 { checkDatasetQuota } from '@aglyn/aglyn/app-utils/plan-entitlements'\nimport { pluginResourceDraftWriter } from '@aglyn/aglyn/plugin-manager/plugin-resource-drafts'\nimport { isAiPlanNewRef, type AiBuildPlanCreate, type AiBuildPlanScreen } from '../model/ai-build-plan'\nimport type { AiJob, AiJobOutput, AiJobPlan } from '../model/ai-jobs.types'\nimport type { AiPlanCapabilities } from '../model/ai-plan-capabilities'\nimport { AI_SITE_DATASETS_MAX } from '../model/ai-site-job'\nimport { AI_STEP_TIERS } from '../providers/catalog'\nimport { aiModelForStep } from '../providers/routing'\nimport {\n AI_DATASET_MAX_TOKENS,\n AI_DATASET_STEP,\n aiDatasetDraftContent,\n generateAiDataset,\n} from '../runtime/ai-dataset-generation'\nimport {\n aiLayoutListingId,\n aiLayoutRecordsPlacements,\n type AiLayoutListing,\n type AiLayoutListingField,\n type AiLayoutListingScreen,\n} from '../layout-language/ai-layout-listings'\nimport type { AiJobAdmissionContext } from './ai-job-admission'\nimport { AI_DATASET_DRAFT_RESOURCE } from './ai-build-unit-outcome'\nimport { aiJobStepBudget } from './ai-job-budget'\nimport { aiGenerationSpent, aiUnspentOutcome } from './ai-job-generation'\nimport { aiPluginDraftAdmissionRefusal } from './ai-job-plugin-drafts'\nimport type { AiJobStepContext, AiJobStepOutcome, AiJobStepRunner } from './ai-job-text-step'\n\n/**\n * A SITE START'S DATASETS (AGL-3616): \"Aglyn AI can also use/create datasets\n * too for whatever it needs\" (Zach, 2026-10-10).\n *\n * A site whose content is a list of like things — a restaurant's menu, a\n * studio's team, a contractor's services, a photographer's portfolio, an\n * events list, its questions and answers — keeps it as a DATASET, the way the\n * docs teach a person to: the owner edits one record and every page listing\n * it follows. On a workspace that may create datasets, the site plan creates\n * one for such content (`create`, kind `dataset`) and names it in the `uses`\n * of each section that lists it. The scaffold then builds each dataset as a\n * unit of its own, after the layout and before the form (which may write\n * its submissions to one) and the pages:\n *\n * - DESIGNED by the `submit_dataset` generation (`ai-dataset-generation.ts`):\n * the planned fields typed, at most a few more, and 3 to 12 records seeded\n * from the brief. Nothing anybody did not say: no review, testimonial,\n * rating, quote or person's name, no price the brief does not state.\n * - WRITTEN by the data plugin's `dataset` writer — this plugin never names\n * the datasets collection — with every rule the console's datasets route\n * has: the member's role and `data.manage`, `release_data_store`,\n * `dataStore` (Starter and up), `datasetsPerOrg` counted inside the create,\n * `recordsPerDataset` and the storage band.\n * - LISTED by the pages built after it: each section naming it repeats over\n * the dataset (`aiSiteDatasetListings`, a `records` listing the layout\n * compiler draws), and a page the plan made its record template binds its\n * fields by id and keeps the address field the writer added.\n *\n * Where datasets cannot be created — the Free taste, Starter's two used up,\n * the data store not released — the plan is told so and creates none, so its\n * sections write the items out. A dataset unit that fails or is refused\n * leaves the pages that list it built without it (they say so), and its\n * record page is not built.\n */\n\n/** The most datasets one site start creates. */\nexport { AI_SITE_DATASETS_MAX } from '../model/ai-site-job'\n\n/** The resource the data plugin's writer is registered under. */\nexport const AI_SITE_DATASET_RESOURCE = AI_DATASET_DRAFT_RESOURCE\n\n/** What the site's plugin list calls the plugin, for \"Turn on Data for this site\". */\nconst DATA_PLUGIN_LABEL = 'Data'\n\n/** The input a dataset unit's own job carries what it needs in. */\nexport const AI_SITE_DATASET_INPUT = 'siteDataset'\n\n/** What a dataset unit's job is told beside its creation. */\nexport interface AiSiteDatasetInput {\n /** The sections that list it, by page: \"Menu › Our dishes (12 items)\". */\n shownIn: string[]\n /** Whether a page of the plan is its record template. */\n recordPages: boolean\n /**\n * The form of the plan that writes its submissions to it (AGL-3616), by\n * name, with that form's planned fields; absent where no form does.\n */\n forForm?: { name: string; fields: string[] }\n}\n\n/** What a dataset row says when its design could not be written: our failure, refunded. */\nexport const AI_SITE_DATASET_NOT_WRITTEN_COPY = 'This dataset could not be added this time.'\n\n/** The note a written dataset carries on the job's page. */\nexport function aiSiteDatasetNote(records: number): string {\n return `${records} ${records === 1 ? 'record' : 'records'} to start, in Data. Edit them there and every page that lists them follows.`\n}\n\n/** The note a record template's row adds: the binding is the member's to save (rule 13). */\nexport const AI_SITE_RECORD_PAGE_NOTE =\n 'A page per record is drafted, not live: open Page Properties → Record pages to save it.'\n\n/** ASSUMED: what one dataset pass reads and writes beside its generation: the site, the writer's reads and its transaction. */\nexport const AI_SITE_DATASET_WRITES_MS = 2_000\n\n/** One dataset's pass: its generation and re-ask at its ceiling, and its writes. */\nexport const AI_SITE_DATASET_BUDGET = aiJobStepBudget({\n tier: AI_STEP_TIERS[AI_DATASET_STEP],\n maxTokens: AI_DATASET_MAX_TOKENS,\n lookups: 0,\n ownReadsMs: AI_SITE_DATASET_WRITES_MS,\n})\n\nconst str = (value: unknown): string => (typeof value === 'string' ? value.trim() : '')\n\n/** The plan's reference to a dataset as a section names it: `new:<name>`, compared lowercased. */\nfunction namesDataset(ref: string, name: string): boolean {\n return isAiPlanNewRef(ref) && ref.slice(ref.indexOf(':') + 1).trim().toLowerCase() === name.trim().toLowerCase()\n}\n\n/** The plan's datasets, in plan order, at most the most a start creates. */\nexport function aiSitePlanDatasets(plan: Pick<AiJobPlan, 'create'>): AiBuildPlanCreate[] {\n return plan.create.filter((entry) => entry.kind === 'dataset').slice(0, AI_SITE_DATASETS_MAX)\n}\n\n/** Where the plan lists a dataset, in words its design reads, whether a page is its record template, and the form that writes to it. */\nexport function aiSiteDatasetInputOf(\n dataset: Pick<AiBuildPlanCreate, 'name'>,\n screens: readonly AiBuildPlanScreen[],\n create: readonly AiBuildPlanCreate[] = [],\n): AiSiteDatasetInput {\n const shownIn: string[] = []\n for (const screen of screens) {\n for (const section of screen.sections) {\n if (!section.uses.some((ref) => namesDataset(ref, dataset.name))) continue\n shownIn.push(`${screen.title} › ${section.name}${section.items ? ` (${section.items} items)` : ''}`)\n }\n }\n const recordPages = screens.some((screen) => !!screen.record && namesDataset(screen.record.dataset, dataset.name))\n const form = create.find((entry) => entry.kind === 'form' && !!entry.writesTo && namesDataset(entry.writesTo, dataset.name))\n return {\n shownIn: shownIn.slice(0, 8),\n recordPages,\n ...(form ? { forForm: { name: form.name, fields: form.fields.slice(0, AI_SITE_FORM_DATASET_FIELDS_MAX) } } : {}),\n }\n}\n\n/** Whether a plan screen is the record template of a dataset the plan creates, and which. */\nexport function aiSiteRecordTemplateOf(screen: Pick<AiBuildPlanScreen, 'record'>): string | null {\n const ref = screen.record?.dataset\n return ref && isAiPlanNewRef(ref) ? ref.slice(ref.indexOf(':') + 1).trim() : null\n}\n\nfunction datasetInputOf(job: Pick<AiJob, 'inputs'>): AiSiteDatasetInput {\n const raw = (job.inputs?.[AI_SITE_DATASET_INPUT] ?? {}) as Partial<AiSiteDatasetInput>\n const form = raw.forForm && typeof raw.forForm === 'object' ? raw.forForm : null\n return {\n shownIn: Array.isArray(raw.shownIn) ? raw.shownIn.map(str).filter(Boolean).slice(0, 8) : [],\n recordPages: raw.recordPages === true,\n ...(form && str(form.name)\n ? {\n forForm: {\n name: str(form.name),\n fields: Array.isArray(form.fields) ? form.fields.map(str).filter(Boolean).slice(0, AI_SITE_FORM_DATASET_FIELDS_MAX) : [],\n },\n }\n : {}),\n }\n}\n\n/** The most fields a form's dataset is designed with: the data plugin writer's own ceiling is higher. */\nexport const AI_SITE_FORM_DATASET_FIELDS_MAX = 12\n\n/** The field types a planned `Name:type` may name, as the data plugin's writer takes them. */\nconst FORM_DATASET_FIELD_TYPES = ['text', 'number', 'integer', 'boolean', 'list'] as const\n\n/** A planned field as a person reads it: `fullName` and `full_name` are \"Full name\". */\nexport function aiSiteDatasetFieldName(planned: string): string {\n const words = planned\n .replace(/([a-z0-9])([A-Z])/g, '$1 $2')\n .replace(/[_-]+/g, ' ')\n .replace(/\\s+/g, ' ')\n .trim()\n return words ? words.charAt(0).toUpperCase() + words.slice(1).toLowerCase() : ''\n}\n\n/**\n * A dataset a form writes to, as the data plugin's writer takes it\n * (AGL-3616): designed with no model, since its records are the\n * submissions. Its fields are its planned ones — or, where the plan gave it\n * none, the form's — each a person's words for it, text unless the plan\n * typed it as `Name:type`, never required, so a submission that leaves one\n * blank is still a record. It starts with no records. Pure.\n */\nexport function aiSiteFormDatasetContent(\n name: string,\n planned: readonly string[],\n form: { fields: readonly string[] },\n): Record<string, unknown> {\n const specs = (planned.length ? planned : form.fields).slice(0, AI_SITE_FORM_DATASET_FIELDS_MAX)\n const seen = new Set<string>()\n const fields: Array<{ name: string; type: string }> = []\n for (const spec of specs) {\n const at = spec.lastIndexOf(':')\n const typed = at > 0 ? spec.slice(at + 1).trim().toLowerCase() : ''\n const type = (FORM_DATASET_FIELD_TYPES as readonly string[]).includes(typed) ? typed : 'text'\n const fieldName = aiSiteDatasetFieldName(type === typed ? spec.slice(0, at) : spec).slice(0, 60)\n if (!fieldName || seen.has(fieldName.toLowerCase())) continue\n seen.add(fieldName.toLowerCase())\n fields.push({ name: fieldName, type })\n }\n return { name, fields, records: [] }\n}\n\n/** The note a form's dataset carries on the job's page. */\nexport function aiSiteFormDatasetNote(form: string): string {\n return `Empty to start: each submission of the form “${form}” is added here, in Data.`\n}\n\nconst limitReview = (message: string) => ({ reason: 'limit' as const, message, findings: [] })\n\nexport interface AiSiteDatasetRunnerDeps {\n generate?: typeof generateAiDataset\n writerFor?: typeof pluginResourceDraftWriter\n}\n\n/** The fields and record names a written dataset reports, as its output's proposal keeps them. */\ninterface AiSiteDatasetProposal {\n fields: AiLayoutListingField[]\n /** Each record's name: its first field's value. */\n recordNames: string[]\n addressField: string | null\n /**\n * The fields most of its first records leave empty, by id (AGL-3616): a\n * tour's venues not yet known. A card never binds one — it would print\n * nothing on most records — so its listing leaves them out.\n */\n sparseFields?: string[]\n}\n\n/**\n * The fields of a designed dataset that its records leave empty on most of\n * them — every record, or more than half — by the id the data plugin gave\n * each (AGL-3616). Its first field is the record's name and is never one. The\n * live low-tide-hollow start (beta.239) seeded its tour dates with no venue,\n * rightly inventing none, and its cards bound the venue as their eyebrow.\n */\nexport function aiDatasetSparseFields(\n dataset: { fields: ReadonlyArray<{ name: string }>; records: ReadonlyArray<ReadonlyArray<string | undefined>> },\n written: readonly AiLayoutListingField[],\n): string[] {\n if (!dataset.records.length) return []\n const idOf = (name: string, column: number) =>\n written.find((field) => field.name.trim().toLowerCase() === name.trim().toLowerCase())?.id ?? written[column]?.id ?? null\n return dataset.fields.flatMap((field, column) => {\n if (column === 0) return []\n const filled = dataset.records.filter((values) => (values[column] ?? '').trim()).length\n const id = idOf(field.name, column)\n return id && filled * 2 <= dataset.records.length ? [id] : []\n })\n}\n\nfunction proposalOf(output: Pick<AiJobOutput, 'proposal'>): AiSiteDatasetProposal {\n const raw = (output.proposal ?? {}) as Partial<AiSiteDatasetProposal>\n return {\n fields: Array.isArray(raw.fields)\n ? raw.fields.filter((field) => field && typeof field.id === 'string' && field.id).map((field) => ({ id: field.id, name: str(field.name) || field.id, type: str(field.type) || 'text' }))\n : [],\n recordNames: Array.isArray(raw.recordNames) ? raw.recordNames.map(str).filter(Boolean).slice(0, 12) : [],\n addressField: str(raw.addressField) || null,\n sparseFields: Array.isArray(raw.sparseFields) ? raw.sparseFields.map(str).filter(Boolean) : [],\n }\n}\n\n/**\n * The dataset unit's runner, on the job the scaffold derived for it: the one\n * creation its plan carries, designed by the model and written by the data\n * plugin, under the creation's own id. A pass repeated after its write finds\n * the dataset the writer wrote and reports it again, spending nothing.\n */\nexport function createAiSiteDatasetRunner(deps: AiSiteDatasetRunnerDeps = {}): AiJobStepRunner {\n const generate = deps.generate ?? generateAiDataset\n const writerFor = deps.writerFor ?? pluginResourceDraftWriter\n return async (context): Promise<AiJobStepOutcome> => {\n const { job, firestore, signal } = context\n const model = context.modelFor?.(AI_DATASET_STEP) ?? aiModelForStep(AI_DATASET_STEP)\n const creation = (job.plan as AiJobPlan | null)?.create?.find((entry) => entry.kind === 'dataset')\n const keeper = writerFor(AI_SITE_DATASET_RESOURCE)\n if (!job.hostId || !creation) return { ...aiUnspentOutcome(model), failure: 'Open the site before adding its data.' }\n if (!keeper) return { ...aiUnspentOutcome(model), failure: 'Datasets are not available on this site.' }\n const host = await firestore.collection('hosts').doc(job.hostId).get()\n const hostSubdomain = str(host.get('subdomain')) || null\n const output = (id: string, name: string, proposal: AiSiteDatasetProposal, records: number): AiJobOutput => ({\n resource: 'draft',\n draftResource: AI_SITE_DATASET_RESOURCE,\n id,\n hostId: job.hostId ?? null,\n hostSubdomain,\n label: name,\n note: aiSiteDatasetNote(records),\n proposal: proposal as unknown as Record<string, unknown>,\n })\n const input = datasetInputOf(job)\n // Asked again under the same id: the dataset already written.\n const written = await keeper.writer.read({ hostId: job.hostId, id: job.$id })\n if (written) {\n const facts = written.facts as { fields?: AiLayoutListingField[]; addressField?: string | null }\n const again = output(written.id, written.name || creation.name, { fields: facts.fields ?? [], recordNames: [], addressField: facts.addressField ?? null }, 0)\n return aiUnspentOutcome(model, {\n outputs: [input.forForm ? { ...again, note: aiSiteFormDatasetNote(input.forForm.name) } : again],\n })\n }\n // A form's dataset (AGL-3616): its records are the submissions, so it is\n // designed from the plan with no model, and starts empty.\n if (input.forForm) {\n const content = aiSiteFormDatasetContent(creation.name, creation.fields, input.forForm)\n const checked = keeper.writer.check(content, { hostId: job.hostId })\n if (checked.ok === false) {\n console.error('ai site dataset: the dataset writer refused a form dataset we made', { orgId: job.orgId, jobId: job.$id, problems: checked.problems })\n return { ...aiUnspentOutcome(model), failure: AI_SITE_DATASET_NOT_WRITTEN_COPY }\n }\n const result = await keeper.writer.write({\n orgId: job.orgId,\n hostId: job.hostId,\n uid: job.createdBy,\n org: (context.org ?? null) as Readonly<Record<string, unknown>> | null,\n now: context.now,\n id: job.$id,\n name: creation.name,\n content,\n })\n if (result.ok === false) {\n if (result.status === 400) return { ...aiUnspentOutcome(model), failure: AI_SITE_DATASET_NOT_WRITTEN_COPY }\n return { ...aiUnspentOutcome(model), review: limitReview(result.error) }\n }\n const facts = result.facts as { fields?: AiLayoutListingField[]; addressField?: string | null }\n return aiUnspentOutcome(model, {\n outputs: [\n {\n ...output(result.id, result.name, { fields: facts.fields ?? [], recordNames: [], addressField: null }, 0),\n note: aiSiteFormDatasetNote(input.forForm.name),\n },\n ],\n })\n }\n const generation = await generate({\n brief: job.brief,\n merchantWords: job.brief,\n name: creation.name,\n why: creation.why,\n fields: creation.fields,\n shownIn: input.shownIn,\n recordPages: input.recordPages,\n model,\n maxTokens: AI_SITE_DATASET_BUDGET.maxTokens(model),\n ...(signal ? { signal } : {}),\n })\n const spent = aiGenerationSpent(generation)\n if (generation.status === 'refused') return { ...spent, refused: true }\n if (generation.status === 'needs_input') return { ...spent, failure: generation.message }\n const content = aiDatasetDraftContent(creation.name, generation.value, { recordPages: input.recordPages })\n // The data plugin's own rules, before anything is written: content we\n // made that its model refuses is our failure, refunded.\n const checked = keeper.writer.check(content, { hostId: job.hostId })\n if (checked.ok === false) {\n console.error('ai site dataset: the dataset writer refused a dataset we made', { orgId: job.orgId, jobId: job.$id, problems: checked.problems })\n return { ...spent, failure: AI_SITE_DATASET_NOT_WRITTEN_COPY }\n }\n const result = await keeper.writer.write({\n orgId: job.orgId,\n hostId: job.hostId,\n uid: job.createdBy,\n org: (context.org ?? null) as Readonly<Record<string, unknown>> | null,\n now: context.now,\n id: job.$id,\n name: creation.name,\n content,\n })\n if (result.ok === false) {\n if (result.status === 400) return { ...spent, failure: AI_SITE_DATASET_NOT_WRITTEN_COPY }\n // The allowance, the role, the plan or the flag: the workspace's to change.\n return { ...spent, review: limitReview(result.error) }\n }\n const facts = result.facts as { fields?: AiLayoutListingField[]; records?: number; addressField?: string | null }\n const proposal: AiSiteDatasetProposal = {\n fields: facts.fields ?? [],\n recordNames: generation.value.records.map((values) => values[0] ?? '').filter(Boolean).slice(0, 12),\n addressField: facts.addressField ?? null,\n sparseFields: aiDatasetSparseFields(generation.value, facts.fields ?? []),\n }\n return { ...spent, outputs: [output(result.id, result.name, proposal, facts.records ?? generation.value.records.length)] }\n }\n}\n\nexport const runAiSiteDatasetUnit = createAiSiteDatasetRunner()\n\n/**\n * Whether a dataset may be created for this member on this site, asked before\n * its first pass so a refusal spends nothing; `null` admits. The data plugin\n * must run here (on for the workspace and the site, past its release flag),\n * and its writer says whether this member may make one now: the role, the\n * plan, the flag, the allowance.\n */\nexport async function aiSiteDatasetRefusal(\n context: Pick<AiJobStepContext, 'firestore' | 'org' | 'now'> & { job: Pick<AiJob, 'orgId' | 'hostId' | 'createdBy'> },\n deps: { admission?: typeof aiPluginDraftAdmissionRefusal; writerFor?: (resource: string) => ReturnType<typeof pluginResourceDraftWriter> } = {},\n): Promise<string | null> {\n const { job } = context\n if (!job.hostId) return 'Open the site first.'\n const writerFor = deps.writerFor ?? pluginResourceDraftWriter\n const admission: AiJobAdmissionContext = {\n firestore: context.firestore,\n orgId: job.orgId,\n hostId: job.hostId,\n inputs: {},\n org: context.org ?? null,\n uid: job.createdBy,\n }\n const refused = await (deps.admission ?? aiPluginDraftAdmissionRefusal)(admission, {\n kind: 'site',\n drafts: [{ resource: AI_SITE_DATASET_RESOURCE, label: DATA_PLUGIN_LABEL }],\n writerFor: (resource) => writerFor(resource)?.writer ?? null,\n ownerFor: (resource) => writerFor(resource)?.pluginId ?? null,\n now: context.now,\n })\n return refused?.error ?? null\n}\n\n/**\n * A site plan's dataset capability on this workspace (AGL-3616): where the\n * workspace's plan includes datasets, whether the data plugin runs here and\n * this member may create one now, and how many a start may make. A clause the\n * plan's turn completes is the reason where it may not.\n */\nexport async function aiSitePlanDatasetCapability(\n capabilities: AiPlanCapabilities,\n context: Parameters<typeof aiSiteDatasetRefusal>[0],\n deps: Parameters<typeof aiSiteDatasetRefusal>[1] = {},\n): Promise<AiPlanCapabilities> {\n if (!capabilities.create.dataset.allowed) return capabilities\n const refusal = await aiSiteDatasetRefusal(context, deps).catch((error: unknown) => {\n console.error('ai site plan: the dataset admission failed', { orgId: context.job.orgId, error })\n return 'datasets could not be checked just now'\n })\n const left = Math.min(AI_SITE_DATASETS_MAX, checkDatasetQuota(context.org as never, 0).limit)\n const dataset = refusal\n ? { allowed: false, left: 0, reason: `datasets cannot be created here: ${refusal.replace(/\\.$/, '')}` }\n : { allowed: true, left, reason: null }\n return { ...capabilities, create: { ...capabilities.create, dataset } }\n}\n\n/**\n * A `records` listing for each dataset that was made and that a section of the\n * plan names (AGL-3616). Its fields, where none are given, are read off the\n * site's inventory when the page is designed (`aiLayoutListingsWithDatasets`).\n */\nexport function aiDatasetListingsOf(\n datasets: ReadonlyArray<{ id: string; name: string; records?: string[]; fields?: AiLayoutListingField[] }>,\n screens: readonly AiLayoutListingScreen[],\n): AiLayoutListing[] {\n return datasets.flatMap((dataset) => {\n const placements = aiLayoutRecordsPlacements(dataset, screens)\n if (!placements.length) return []\n return [\n {\n id: aiLayoutListingId('records', dataset.id),\n kind: 'records' as const,\n name: dataset.name,\n records: dataset.records ?? [],\n datasetId: dataset.id,\n ...(dataset.fields?.length ? { fields: dataset.fields } : {}),\n placements,\n },\n ]\n })\n}\n\n/**\n * The site's datasets a layout or a page unit is handed (AGL-3616), each a\n * `records` listing with the sections of the plan's pages that name it, once\n * its unit wrote it. A dataset not yet written, or one that failed, lists\n * nowhere: the pages built without it write the items out.\n */\nexport function aiSiteDatasetListings(input: {\n outputs: readonly AiJobOutput[]\n datasets: ReadonlyArray<Pick<AiBuildPlanCreate, 'name'>>\n screens: readonly AiLayoutListingScreen[]\n /** The ids each dataset's unit delivered, by plan name lowercased. */\n delivered: ReadonlyMap<string, string>\n}): AiLayoutListing[] {\n const made = input.datasets.flatMap((dataset) => {\n const id = input.delivered.get(dataset.name.trim().toLowerCase())\n const output = id\n ? input.outputs.find((entry) => entry.resource === 'draft' && entry.draftResource === AI_SITE_DATASET_RESOURCE && entry.id === id)\n : undefined\n if (!id || !output) return []\n const proposal = proposalOf(output)\n return [\n {\n id,\n // Placed by the name the plan's sections gave it.\n name: dataset.name,\n records: proposal.recordNames,\n // The address field is the record page's, never a card's words; a\n // field most records leave empty is no card's either (AGL-3616).\n fields: proposal.fields.filter(\n (field, index) => field.id !== proposal.addressField && (index === 0 || !proposal.sparseFields?.includes(field.id)),\n ),\n },\n ]\n })\n return aiDatasetListingsOf(made, input.screens)\n}\n\n/** What a page is told about the datasets built before it. */\nexport function aiSiteDatasetBriefLines(outputs: readonly AiJobOutput[]): string[] {\n const datasets = outputs.filter((output) => output.resource === 'draft' && output.draftResource === AI_SITE_DATASET_RESOURCE)\n return datasets.flatMap((output) => {\n const names = proposalOf(output).recordNames\n return names.length\n ? [`This site's dataset “${output.label}” holds: ${names.map((name) => `“${name}”`).join(', ')}. Where a page names one, name it as written; never name one that is not in this list.`]\n : []\n })\n}\n"],"names":["checkDatasetQuota","pluginResourceDraftWriter","isAiPlanNewRef","AI_SITE_DATASETS_MAX","AI_STEP_TIERS","aiModelForStep","AI_DATASET_MAX_TOKENS","AI_DATASET_STEP","aiDatasetDraftContent","generateAiDataset","aiLayoutListingId","aiLayoutRecordsPlacements","AI_DATASET_DRAFT_RESOURCE","aiJobStepBudget","aiGenerationSpent","aiUnspentOutcome","aiPluginDraftAdmissionRefusal","AI_SITE_DATASET_RESOURCE","DATA_PLUGIN_LABEL","AI_SITE_DATASET_INPUT","AI_SITE_DATASET_NOT_WRITTEN_COPY","aiSiteDatasetNote","records","AI_SITE_RECORD_PAGE_NOTE","AI_SITE_DATASET_WRITES_MS","AI_SITE_DATASET_BUDGET","tier","maxTokens","lookups","ownReadsMs","str","value","trim","namesDataset","ref","name","slice","indexOf","toLowerCase","aiSitePlanDatasets","plan","create","filter","entry","kind","aiSiteDatasetInputOf","dataset","screens","shownIn","screen","section","sections","uses","some","push","title","items","recordPages","record","form","find","writesTo","forForm","fields","AI_SITE_FORM_DATASET_FIELDS_MAX","aiSiteRecordTemplateOf","datasetInputOf","job","raw","inputs","Array","isArray","map","Boolean","FORM_DATASET_FIELD_TYPES","aiSiteDatasetFieldName","planned","words","replace","charAt","toUpperCase","aiSiteFormDatasetContent","specs","length","seen","Set","spec","at","lastIndexOf","typed","type","includes","fieldName","has","add","aiSiteFormDatasetNote","limitReview","message","reason","findings","aiDatasetSparseFields","written","idOf","column","field","id","flatMap","filled","values","proposalOf","output","proposal","recordNames","addressField","sparseFields","createAiSiteDatasetRunner","deps","generate","writerFor","context","facts","firestore","signal","model","modelFor","creation","keeper","hostId","failure","host","collection","doc","get","hostSubdomain","resource","draftResource","label","note","input","writer","read","$id","again","outputs","content","checked","check","ok","console","error","orgId","jobId","problems","result","write","uid","createdBy","org","now","status","review","generation","brief","merchantWords","why","spent","refused","runAiSiteDatasetUnit","aiSiteDatasetRefusal","admission","drafts","ownerFor","pluginId","aiSitePlanDatasetCapability","capabilities","allowed","refusal","catch","left","Math","min","limit","aiDatasetListingsOf","datasets","placements","datasetId","aiSiteDatasetListings","made","delivered","undefined","index","aiSiteDatasetBriefLines","names","join"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,iBAAiB,QAAQ,2CAA0C;AAC5E,SAASC,yBAAyB,QAAQ,qDAAoD;AAC9F,SAASC,cAAc,QAAwD,4BAAwB;AAGvG,SAASC,oBAAoB,QAAQ,0BAAsB;AAC3D,SAASC,aAAa,QAAQ,0BAAsB;AACpD,SAASC,cAAc,QAAQ,0BAAsB;AACrD,SACEC,qBAAqB,EACrBC,eAAe,EACfC,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,EAAA;;YAErH;SACD;IACH;IACA,OAAO6E,oBAAoBK,MAAMjD,MAAM3F,OAAO;AAChD;AAEA,4DAA4D,GAC5D,OAAO,SAASgJ,wBAAwBhD,OAA+B;IACrE,MAAMwC,WAAWxC,QAAQrG,MAAM,CAAC,CAACoE,SAAWA,OAAOwB,QAAQ,KAAK,WAAWxB,OAAOyB,aAAa,KAAKtH;IACpG,OAAOsK,SAAS7E,OAAO,CAAC,CAACI;QACvB,MAAMkF,QAAQnF,WAAWC,QAAQE,WAAW;QAC5C,OAAOgF,MAAM7G,MAAM,GACf;YAAC,CAAC,qBAAqB,EAAE2B,OAAO0B,KAAK,CAAC,SAAS,EAAEwD,MAAMxH,GAAG,CAAC,CAACrC,OAAS,CAAC,CAAC,EAAEA,KAAK,CAAC,CAAC,EAAE8J,IAAI,CAAC,MAAM,sFAAsF,CAAC;SAAC,GACrL,EAAE;IACR;AACF"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/jobs/ai-job-site-datasets.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 { checkDatasetQuota } from '@aglyn/aglyn/app-utils/plan-entitlements'\nimport { pluginResourceDraftWriter } from '@aglyn/aglyn/plugin-manager/plugin-resource-drafts'\nimport { isAiPlanNewRef, type AiBuildPlanCreate, type AiBuildPlanScreen } from '../model/ai-build-plan'\nimport type { AiJob, AiJobOutput, AiJobPlan } from '../model/ai-jobs.types'\nimport type { AiPlanCapabilities } from '../model/ai-plan-capabilities'\nimport { AI_SITE_DATASETS_MAX } from '../model/ai-site-job'\nimport { AI_STEP_TIERS } from '../providers/catalog'\nimport { aiModelForStep } from '../providers/routing'\nimport {\n AI_DATASET_MAX_TOKENS,\n AI_DATASET_STEP,\n aiDatasetDraftContent,\n generateAiDataset,\n} from '../runtime/ai-dataset-generation'\nimport {\n aiLayoutListingId,\n aiLayoutRecordsPlacements,\n type AiLayoutListing,\n type AiLayoutListingField,\n type AiLayoutListingScreen,\n} from '../layout-language/ai-layout-listings'\nimport {\n aiLayoutStarterPhotos,\n type AiLayoutPicturePhoto,\n type AiLayoutPictureSlot,\n} from '../layout-language/ai-layout-pictures'\nimport { aiSiteWords } from '../model/ai-site-job'\nimport type { AiJobAdmissionContext } from './ai-job-admission'\nimport { aiOriginJobId } from './ai-job-draft-ids'\nimport { aiSiteProductPhotoSrc } from './ai-job-site-content'\nimport { aiLayoutStockPhotoSource } from './ai-layout-stock-photos'\nimport { AI_DATASET_DRAFT_RESOURCE } from './ai-build-unit-outcome'\nimport { aiJobStepBudget } from './ai-job-budget'\nimport { aiGenerationSpent, aiUnspentOutcome } from './ai-job-generation'\nimport { aiPluginDraftAdmissionRefusal } from './ai-job-plugin-drafts'\nimport type { AiJobStepContext, AiJobStepOutcome, AiJobStepRunner } from './ai-job-text-step'\n\n/**\n * A SITE START'S DATASETS (AGL-3616): \"Aglyn AI can also use/create datasets\n * too for whatever it needs\" (Zach, 2026-10-10).\n *\n * A site whose content is a list of like things — a restaurant's menu, a\n * studio's team, a contractor's services, a photographer's portfolio, an\n * events list, its questions and answers — keeps it as a DATASET, the way the\n * docs teach a person to: the owner edits one record and every page listing\n * it follows. On a workspace that may create datasets, the site plan creates\n * one for such content (`create`, kind `dataset`) and names it in the `uses`\n * of each section that lists it. The scaffold then builds each dataset as a\n * unit of its own, after the layout and before the form (which may write\n * its submissions to one) and the pages:\n *\n * - DESIGNED by the `submit_dataset` generation (`ai-dataset-generation.ts`):\n * the planned fields typed, at most a few more, and 3 to 12 records seeded\n * from the brief. Nothing anybody did not say: no review, testimonial,\n * rating, quote or person's name, no price the brief does not state.\n * - WRITTEN by the data plugin's `dataset` writer — this plugin never names\n * the datasets collection — with every rule the console's datasets route\n * has: the member's role and `data.manage`, `release_data_store`,\n * `dataStore` (Starter and up), `datasetsPerOrg` counted inside the create,\n * `recordsPerDataset` and the storage band.\n * - PICTURED where the plan lists it the way a gallery is listed (Zach,\n * 2026-10-10: a ceramic artist's \"Selected work\" came back as text-only\n * cards, where it had been an image-led gallery): a portfolio's pieces, a\n * team, a menu, classes and events, and services or offerings whose\n * section says it shows them in pictures (`aiSiteDatasetPicturesOf`). Such\n * a dataset gets an Image field, and each record a stock photo of its own\n * name in the site's craft, copied into the site's library — never one the\n * job already placed, else a starter photo — searched in code, so it\n * costs no credits (`aiSiteDatasetRecordPhotos`).\n * - LISTED by the pages built after it: each section naming it repeats over\n * the dataset (`aiSiteDatasetListings`, a `records` listing the layout\n * compiler draws, its card led by the record's photo where it has one),\n * and a page the plan made its record template binds its fields by id,\n * its photo the record's, and keeps the address field the writer added.\n *\n * Where datasets cannot be created — the Free taste, Starter's two used up,\n * the data store not released — the plan is told so and creates none, so its\n * sections write the items out. A dataset unit that fails or is refused\n * leaves the pages that list it built without it (they say so), and its\n * record page is not built.\n */\n\n/** The most datasets one site start creates. */\nexport { AI_SITE_DATASETS_MAX } from '../model/ai-site-job'\n\n/** The resource the data plugin's writer is registered under. */\nexport const AI_SITE_DATASET_RESOURCE = AI_DATASET_DRAFT_RESOURCE\n\n/** What the site's plugin list calls the plugin, for \"Turn on Data for this site\". */\nconst DATA_PLUGIN_LABEL = 'Data'\n\n/** The input a dataset unit's own job carries what it needs in. */\nexport const AI_SITE_DATASET_INPUT = 'siteDataset'\n\n/** What a dataset unit's job is told beside its creation. */\nexport interface AiSiteDatasetInput {\n /** The sections that list it, by page: \"Menu › Our dishes (12 items)\". */\n shownIn: string[]\n /** Whether a page of the plan is its record template. */\n recordPages: boolean\n /**\n * The form of the plan that writes its submissions to it (AGL-3616), by\n * name, with that form's planned fields; absent where no form does.\n */\n forForm?: { name: string; fields: string[] }\n /**\n * Whether its records carry a photo, and of what (AGL-3616): `things` for a\n * portfolio's pieces, a menu, classes; `people` for a team. Absent for a\n * list a visitor reads rather than looks at: questions, steps, hours.\n */\n pictures?: AiSiteDatasetPictures\n}\n\n/** What a dataset's records are pictured as: things or people. */\nexport type AiSiteDatasetPictures = 'things' | 'people'\n\n/** A list of questions, voices or plain facts: read, never pictured. */\nconst READ_ONLY_LIST =\n /\\b(faqs?|questions?|q ?& ?a|answers?|testimonials?|reviews?|quotes?|voices|hours|opening|steps?|process|policies|policy|terms|stats?|numbers|figures|milestones|timeline|values|benefits|reasons|features|requirements|checklist|ingredients|donations?|needs|partners|sponsors|supporters|roles|positions|jobs|openings)\\b/i\n/** A list of people: its photos are of the business's people. */\nconst PEOPLE_LIST =\n /\\b(team|staff|people|crew|instructors?|teachers?|tutors?|stylists?|barbers?|therapists?|coaches?|trainers?|chefs?|doctors?|dentists?|hygienists?|practitioners?|artists?|musicians?|performers?|speakers?|founders?|members?)\\b/i\n/** A list a visitor looks at before reading: pictured wherever it is listed. */\nconst PICTURED_LIST =\n /\\b(portfolio|pieces?|works?|projects?|gallery|galleries|collections?|series|menus?|dishes|plates|drinks|cocktails|wines?|beers?|coffees?|pastries|cakes|products?|items|events?|classes|class|workshops?|courses?|retreats?|tours?|trips?|adventures?|experiences?|rooms?|suites?|cabins?|properties|listings|homes|venues?|spaces?|recipes?|artworks?|paintings?|prints?|photos?|photographs?|designs?|commissions?|builds?|vehicles?|animals?|pets?|plants?|flowers?|bouquets?|arrangements?|case studies)\\b/i\n/** A section that says it shows its items in pictures: a gallery, a grid of photos, tiles. */\nconst PICTURED_SECTION =\n /\\b(gallery|galleries|grid|images?|photos?|photographs?|pictures?|lightbox|portfolio|showcase|tiles?|visuals?|lookbook|carousel|slideshow|mosaic|thumbnails?)\\b/i\n\n/**\n * Whether a dataset's records carry a photo, read off the plan (AGL-3616):\n * its name and the names of the sections that list it. Questions, voices and\n * plain facts never; people as people; a list a visitor looks at — pieces,\n * dishes, classes, events, rooms — always; any other list (services,\n * offerings, programs) only where a section that lists it says it shows them\n * in pictures, or names one of those. A dataset no page lists is not\n * pictured. Pure.\n */\nexport function aiSiteDatasetPicturesOf(\n dataset: Pick<AiBuildPlanCreate, 'name'>,\n sections: readonly string[],\n): AiSiteDatasetPictures | null {\n if (!sections.length) return null\n const own = dataset.name\n if (READ_ONLY_LIST.test(own)) return null\n if (PEOPLE_LIST.test(own)) return 'people'\n if (PICTURED_LIST.test(own)) return 'things'\n if (sections.some((section) => READ_ONLY_LIST.test(section) && !PICTURED_SECTION.test(section))) return null\n if (sections.some((section) => PEOPLE_LIST.test(section))) return 'people'\n if (sections.some((section) => PICTURED_LIST.test(section) || PICTURED_SECTION.test(section))) return 'things'\n return null\n}\n\n/** What a dataset row says when its design could not be written: our failure, refunded. */\nexport const AI_SITE_DATASET_NOT_WRITTEN_COPY = 'This dataset could not be added this time.'\n\n/** The note a written dataset carries on the job's page. */\nexport function aiSiteDatasetNote(records: number): string {\n return `${records} ${records === 1 ? 'record' : 'records'} to start, in Data. Edit them there and every page that lists them follows.`\n}\n\n/** The note a record template's row adds: the binding is the member's to save (rule 13). */\nexport const AI_SITE_RECORD_PAGE_NOTE =\n 'A page per record is drafted, not live: open Page Properties → Record pages to save it.'\n\n/** ASSUMED: what one dataset pass reads and writes beside its generation: the site, the writer's reads and its transaction. */\nexport const AI_SITE_DATASET_WRITES_MS = 2_000\n\n/** One dataset's pass: its generation and re-ask at its ceiling, and its writes. */\nexport const AI_SITE_DATASET_BUDGET = aiJobStepBudget({\n tier: AI_STEP_TIERS[AI_DATASET_STEP],\n maxTokens: AI_DATASET_MAX_TOKENS,\n lookups: 0,\n ownReadsMs: AI_SITE_DATASET_WRITES_MS,\n})\n\nconst str = (value: unknown): string => (typeof value === 'string' ? value.trim() : '')\n\n/** The plan's reference to a dataset as a section names it: `new:<name>`, compared lowercased. */\nfunction namesDataset(ref: string, name: string): boolean {\n return isAiPlanNewRef(ref) && ref.slice(ref.indexOf(':') + 1).trim().toLowerCase() === name.trim().toLowerCase()\n}\n\n/** The plan's datasets, in plan order, at most the most a start creates. */\nexport function aiSitePlanDatasets(plan: Pick<AiJobPlan, 'create'>): AiBuildPlanCreate[] {\n return plan.create.filter((entry) => entry.kind === 'dataset').slice(0, AI_SITE_DATASETS_MAX)\n}\n\n/** Where the plan lists a dataset, in words its design reads, whether a page is its record template, and the form that writes to it. */\nexport function aiSiteDatasetInputOf(\n dataset: Pick<AiBuildPlanCreate, 'name'>,\n screens: readonly AiBuildPlanScreen[],\n create: readonly AiBuildPlanCreate[] = [],\n): AiSiteDatasetInput {\n const shownIn: string[] = []\n const sectionNames: string[] = []\n for (const screen of screens) {\n for (const section of screen.sections) {\n if (!section.uses.some((ref) => namesDataset(ref, dataset.name))) continue\n shownIn.push(`${screen.title} › ${section.name}${section.items ? ` (${section.items} items)` : ''}`)\n sectionNames.push(section.name)\n }\n }\n const recordPages = screens.some((screen) => !!screen.record && namesDataset(screen.record.dataset, dataset.name))\n const form = create.find((entry) => entry.kind === 'form' && !!entry.writesTo && namesDataset(entry.writesTo, dataset.name))\n // A form's dataset holds its submissions: nobody's photo.\n const pictures = form ? null : aiSiteDatasetPicturesOf(dataset, sectionNames)\n return {\n shownIn: shownIn.slice(0, 8),\n recordPages,\n ...(form ? { forForm: { name: form.name, fields: form.fields.slice(0, AI_SITE_FORM_DATASET_FIELDS_MAX) } } : {}),\n ...(pictures ? { pictures } : {}),\n }\n}\n\n/** Whether a plan screen is the record template of a dataset the plan creates, and which. */\nexport function aiSiteRecordTemplateOf(screen: Pick<AiBuildPlanScreen, 'record'>): string | null {\n const ref = screen.record?.dataset\n return ref && isAiPlanNewRef(ref) ? ref.slice(ref.indexOf(':') + 1).trim() : null\n}\n\nfunction datasetInputOf(job: Pick<AiJob, 'inputs'>): AiSiteDatasetInput {\n const raw = (job.inputs?.[AI_SITE_DATASET_INPUT] ?? {}) as Partial<AiSiteDatasetInput>\n const form = raw.forForm && typeof raw.forForm === 'object' ? raw.forForm : null\n return {\n shownIn: Array.isArray(raw.shownIn) ? raw.shownIn.map(str).filter(Boolean).slice(0, 8) : [],\n recordPages: raw.recordPages === true,\n ...(form && str(form.name)\n ? {\n forForm: {\n name: str(form.name),\n fields: Array.isArray(form.fields) ? form.fields.map(str).filter(Boolean).slice(0, AI_SITE_FORM_DATASET_FIELDS_MAX) : [],\n },\n }\n : {}),\n ...(raw.pictures === 'things' || raw.pictures === 'people' ? { pictures: raw.pictures } : {}),\n }\n}\n\n/** The most fields a form's dataset is designed with: the data plugin writer's own ceiling is higher. */\nexport const AI_SITE_FORM_DATASET_FIELDS_MAX = 12\n\n/** The field types a planned `Name:type` may name, as the data plugin's writer takes them. */\nconst FORM_DATASET_FIELD_TYPES = ['text', 'number', 'integer', 'boolean', 'list'] as const\n\n/** A planned field as a person reads it: `fullName` and `full_name` are \"Full name\". */\nexport function aiSiteDatasetFieldName(planned: string): string {\n const words = planned\n .replace(/([a-z0-9])([A-Z])/g, '$1 $2')\n .replace(/[_-]+/g, ' ')\n .replace(/\\s+/g, ' ')\n .trim()\n return words ? words.charAt(0).toUpperCase() + words.slice(1).toLowerCase() : ''\n}\n\n/**\n * A dataset a form writes to, as the data plugin's writer takes it\n * (AGL-3616): designed with no model, since its records are the\n * submissions. Its fields are its planned ones — or, where the plan gave it\n * none, the form's — each a person's words for it, text unless the plan\n * typed it as `Name:type`, never required, so a submission that leaves one\n * blank is still a record. It starts with no records. Pure.\n */\nexport function aiSiteFormDatasetContent(\n name: string,\n planned: readonly string[],\n form: { fields: readonly string[] },\n): Record<string, unknown> {\n const specs = (planned.length ? planned : form.fields).slice(0, AI_SITE_FORM_DATASET_FIELDS_MAX)\n const seen = new Set<string>()\n const fields: Array<{ name: string; type: string }> = []\n for (const spec of specs) {\n const at = spec.lastIndexOf(':')\n const typed = at > 0 ? spec.slice(at + 1).trim().toLowerCase() : ''\n const type = (FORM_DATASET_FIELD_TYPES as readonly string[]).includes(typed) ? typed : 'text'\n const fieldName = aiSiteDatasetFieldName(type === typed ? spec.slice(0, at) : spec).slice(0, 60)\n if (!fieldName || seen.has(fieldName.toLowerCase())) continue\n seen.add(fieldName.toLowerCase())\n fields.push({ name: fieldName, type })\n }\n return { name, fields, records: [] }\n}\n\n/** The note a form's dataset carries on the job's page. */\nexport function aiSiteFormDatasetNote(form: string): string {\n return `Empty to start: each submission of the form “${form}” is added here, in Data.`\n}\n\nconst limitReview = (message: string) => ({ reason: 'limit' as const, message, findings: [] })\n\n/** The wall clock a dataset's photos may take inside its pass: the 20 seconds a page's pictures had (AGL-3660). */\nexport const AI_SITE_DATASET_PHOTOS_BUDGET_MS = 20_000\n\n/** The field a pictured dataset's photo is kept in, where the plan gave it none. */\nexport const AI_SITE_DATASET_IMAGE_FIELD = 'Image'\n\n/** A planned field that already names a record's photo. */\nconst IMAGE_FIELD_NAME =\n /^(?:main |cover |hero |featured? )?(?:image|photo|picture|photograph|thumbnail|headshot|portrait|cover)s?$/i\n\n/** One record's photo: the address its Image shows, and the library asset placed, which no page shows again. */\nexport interface AiSiteDatasetRecordPhoto {\n /** The media library's CDN path, or a starter's site path; `null` for none. */\n src: string | null\n /** The `media:` reference of the stock photo placed, or `null` for a starter. */\n placed: string | null\n}\n\n/**\n * A photo for each record of a pictured dataset (AGL-3616), in order: a stock\n * photo of the record's own name, in the site's craft (\"ceramic speckled\n * serving bowl\"), copied into the site's library, where the deployment has a\n * stock library — never twice in the dataset nor one another part of the job\n * placed, inside {@link AI_SITE_DATASET_PHOTOS_BUDGET_MS} — else a starter\n * photo, as a page's empty picture takes one. A team is searched as the\n * business's people. The photo is kept as the asset's CDN path, the form a\n * product keeps (`aiSiteProductPhotoSrc`), so a replace in the library still\n * reaches it. No AI model is asked, so no credits; never throws.\n */\nexport async function aiSiteDatasetRecordPhotos(input: {\n job: Pick<AiJob, '$id' | 'hostId' | 'createdBy' | 'inputs' | 'brief'>\n /** The dataset, as the plan named it. */\n name: string\n /** Each record's name, by position. */\n names: readonly string[]\n pictures: AiSiteDatasetPictures\n signal?: AbortSignal\n stockPhotos?: typeof aiLayoutStockPhotoSource\n}): Promise<AiSiteDatasetRecordPhoto[]> {\n const { job } = input\n if (!input.names.length || !job.hostId) return input.names.map(() => ({ src: null, placed: null }))\n const people = input.pictures === 'people'\n const slots: AiLayoutPictureSlot[] = input.names.map((name, index) => ({\n imageId: `record${index}`,\n frameId: null,\n iconId: null,\n alt: name.trim() || input.name,\n // The record card's own shape: a team's portraits stand, pieces sit wide.\n aspect: people ? 4 / 5 : 4 / 3,\n sectionIndex: 0,\n role: people ? ('about' as const) : ('gallery' as const),\n }))\n const seed = `${job.$id}:records`\n let found: ReadonlyArray<AiLayoutPicturePhoto | null> = []\n try {\n const source = (input.stockPhotos ?? aiLayoutStockPhotoSource)(\n {\n hostId: job.hostId,\n uid: job.createdBy,\n seed,\n business: aiSiteWords(job.inputs).about || job.brief,\n sectionNames: [input.name],\n jobId: aiOriginJobId(job),\n // Each record may try its name, its object and the site's world.\n searches: slots.length * 3,\n ...(input.signal ? { signal: input.signal } : {}),\n },\n { budgetMs: AI_SITE_DATASET_PHOTOS_BUDGET_MS },\n )\n if (source) found = await source(slots)\n } catch (error) {\n console.warn('ai site dataset: the stock photos failed; starter photos fill them', { error: String(error) })\n }\n const starters = aiLayoutStarterPhotos(slots, seed)\n const hostId = job.hostId\n return slots.map((_slot, index) => {\n const stock = aiSiteProductPhotoSrc(found[index]?.src, hostId)\n if (stock) return { src: stock, placed: found[index]?.src ?? null }\n return { src: aiSiteProductPhotoSrc(starters[index]?.src, hostId), placed: null }\n })\n}\n\n/**\n * A designed dataset's content with its records' photos (AGL-3616): the\n * planned field that names a photo (\"Image\", \"Photo\") becomes the data\n * plugin's `image` field, else one called \"Image\" is added after the others,\n * and each record holds its photo there; a record with none holds nothing.\n * Pure.\n */\nexport function aiSiteDatasetContentWithPhotos(\n content: Record<string, unknown>,\n photos: ReadonlyArray<string | null>,\n): Record<string, unknown> {\n const fields = (Array.isArray(content['fields']) ? content['fields'] : []) as Array<{ name: string; type?: string }>\n const named = fields.find((field) => IMAGE_FIELD_NAME.test(str(field.name)))\n const fieldName = named ? named.name : AI_SITE_DATASET_IMAGE_FIELD\n const nextFields = named\n ? fields.map((field) => (field === named ? { ...field, type: 'image' } : field))\n : [...fields, { name: AI_SITE_DATASET_IMAGE_FIELD, type: 'image' }]\n const records = (Array.isArray(content['records']) ? content['records'] : []) as Array<Record<string, unknown>>\n return {\n ...content,\n fields: nextFields,\n records: records.map((record, index) => {\n const next = { ...record }\n delete next[fieldName]\n const photo = photos[index]\n return photo ? { ...next, [fieldName]: photo } : next\n }),\n }\n}\n\nexport interface AiSiteDatasetRunnerDeps {\n generate?: typeof generateAiDataset\n writerFor?: typeof pluginResourceDraftWriter\n /** Where a pictured dataset's photos come from; the stock library, else the starters, otherwise. */\n photos?: typeof aiSiteDatasetRecordPhotos\n}\n\n/** The fields and record names a written dataset reports, as its output's proposal keeps them. */\ninterface AiSiteDatasetProposal {\n fields: AiLayoutListingField[]\n /** Each record's name: its first field's value. */\n recordNames: string[]\n addressField: string | null\n /** The field each record's photo is in, where it has one (AGL-3616). */\n imageField?: string | null\n /** The library photos its records show (`media:` references), which no page places again. */\n photos?: string[]\n /**\n * The fields most of its first records leave empty, by id (AGL-3616): a\n * tour's venues not yet known. A card never binds one — it would print\n * nothing on most records — so its listing leaves them out.\n */\n sparseFields?: string[]\n}\n\n/**\n * The fields of a designed dataset that its records leave empty on most of\n * them — every record, or more than half — by the id the data plugin gave\n * each (AGL-3616). Its first field is the record's name and is never one. The\n * live low-tide-hollow start (beta.239) seeded its tour dates with no venue,\n * rightly inventing none, and its cards bound the venue as their eyebrow.\n */\nexport function aiDatasetSparseFields(\n dataset: { fields: ReadonlyArray<{ name: string }>; records: ReadonlyArray<ReadonlyArray<string | undefined>> },\n written: readonly AiLayoutListingField[],\n): string[] {\n if (!dataset.records.length) return []\n const idOf = (name: string, column: number) =>\n written.find((field) => field.name.trim().toLowerCase() === name.trim().toLowerCase())?.id ?? written[column]?.id ?? null\n return dataset.fields.flatMap((field, column) => {\n if (column === 0) return []\n const filled = dataset.records.filter((values) => (values[column] ?? '').trim()).length\n const id = idOf(field.name, column)\n return id && filled * 2 <= dataset.records.length ? [id] : []\n })\n}\n\nfunction proposalOf(output: Pick<AiJobOutput, 'proposal'>): AiSiteDatasetProposal {\n const raw = (output.proposal ?? {}) as Partial<AiSiteDatasetProposal>\n return {\n fields: Array.isArray(raw.fields)\n ? raw.fields.filter((field) => field && typeof field.id === 'string' && field.id).map((field) => ({ id: field.id, name: str(field.name) || field.id, type: str(field.type) || 'text' }))\n : [],\n recordNames: Array.isArray(raw.recordNames) ? raw.recordNames.map(str).filter(Boolean).slice(0, 12) : [],\n addressField: str(raw.addressField) || null,\n imageField: str(raw.imageField) || null,\n photos: Array.isArray(raw.photos) ? raw.photos.map(str).filter((src) => src.startsWith('media:')).slice(0, 24) : [],\n sparseFields: Array.isArray(raw.sparseFields) ? raw.sparseFields.map(str).filter(Boolean) : [],\n }\n}\n\n/**\n * The dataset unit's runner, on the job the scaffold derived for it: the one\n * creation its plan carries, designed by the model and written by the data\n * plugin, under the creation's own id. A pass repeated after its write finds\n * the dataset the writer wrote and reports it again, spending nothing.\n */\nexport function createAiSiteDatasetRunner(deps: AiSiteDatasetRunnerDeps = {}): AiJobStepRunner {\n const generate = deps.generate ?? generateAiDataset\n const writerFor = deps.writerFor ?? pluginResourceDraftWriter\n const photosFor = deps.photos ?? aiSiteDatasetRecordPhotos\n return async (context): Promise<AiJobStepOutcome> => {\n const { job, firestore, signal } = context\n const model = context.modelFor?.(AI_DATASET_STEP) ?? aiModelForStep(AI_DATASET_STEP)\n const creation = (job.plan as AiJobPlan | null)?.create?.find((entry) => entry.kind === 'dataset')\n const keeper = writerFor(AI_SITE_DATASET_RESOURCE)\n if (!job.hostId || !creation) return { ...aiUnspentOutcome(model), failure: 'Open the site before adding its data.' }\n if (!keeper) return { ...aiUnspentOutcome(model), failure: 'Datasets are not available on this site.' }\n const host = await firestore.collection('hosts').doc(job.hostId).get()\n const hostSubdomain = str(host.get('subdomain')) || null\n const output = (id: string, name: string, proposal: AiSiteDatasetProposal, records: number): AiJobOutput => ({\n resource: 'draft',\n draftResource: AI_SITE_DATASET_RESOURCE,\n id,\n hostId: job.hostId ?? null,\n hostSubdomain,\n label: name,\n note: aiSiteDatasetNote(records),\n proposal: proposal as unknown as Record<string, unknown>,\n })\n const input = datasetInputOf(job)\n // Asked again under the same id: the dataset already written.\n const written = await keeper.writer.read({ hostId: job.hostId, id: job.$id })\n if (written) {\n const facts = written.facts as { fields?: AiLayoutListingField[]; addressField?: string | null; imageField?: string | null }\n const again = output(\n written.id,\n written.name || creation.name,\n { fields: facts.fields ?? [], recordNames: [], addressField: facts.addressField ?? null, imageField: facts.imageField ?? null },\n 0,\n )\n return aiUnspentOutcome(model, {\n outputs: [input.forForm ? { ...again, note: aiSiteFormDatasetNote(input.forForm.name) } : again],\n })\n }\n // A form's dataset (AGL-3616): its records are the submissions, so it is\n // designed from the plan with no model, and starts empty.\n if (input.forForm) {\n const content = aiSiteFormDatasetContent(creation.name, creation.fields, input.forForm)\n const checked = keeper.writer.check(content, { hostId: job.hostId })\n if (checked.ok === false) {\n console.error('ai site dataset: the dataset writer refused a form dataset we made', { orgId: job.orgId, jobId: job.$id, problems: checked.problems })\n return { ...aiUnspentOutcome(model), failure: AI_SITE_DATASET_NOT_WRITTEN_COPY }\n }\n const result = await keeper.writer.write({\n orgId: job.orgId,\n hostId: job.hostId,\n uid: job.createdBy,\n org: (context.org ?? null) as Readonly<Record<string, unknown>> | null,\n now: context.now,\n id: job.$id,\n name: creation.name,\n content,\n })\n if (result.ok === false) {\n if (result.status === 400) return { ...aiUnspentOutcome(model), failure: AI_SITE_DATASET_NOT_WRITTEN_COPY }\n return { ...aiUnspentOutcome(model), review: limitReview(result.error) }\n }\n const facts = result.facts as { fields?: AiLayoutListingField[]; addressField?: string | null }\n return aiUnspentOutcome(model, {\n outputs: [\n {\n ...output(result.id, result.name, { fields: facts.fields ?? [], recordNames: [], addressField: null }, 0),\n note: aiSiteFormDatasetNote(input.forForm.name),\n },\n ],\n })\n }\n const generation = await generate({\n brief: job.brief,\n merchantWords: job.brief,\n name: creation.name,\n why: creation.why,\n fields: creation.fields,\n shownIn: input.shownIn,\n recordPages: input.recordPages,\n model,\n maxTokens: AI_SITE_DATASET_BUDGET.maxTokens(model),\n ...(signal ? { signal } : {}),\n })\n const spent = aiGenerationSpent(generation)\n if (generation.status === 'refused') return { ...spent, refused: true }\n if (generation.status === 'needs_input') return { ...spent, failure: generation.message }\n const designed = aiDatasetDraftContent(creation.name, generation.value, { recordPages: input.recordPages })\n // A list a visitor looks at keeps its records' photos (AGL-3616): searched\n // in code, never asked of the model, so they cost no credits.\n const photos = input.pictures\n ? await photosFor({\n job,\n name: creation.name,\n names: generation.value.records.map((values) => values[0] ?? ''),\n pictures: input.pictures,\n ...(signal ? { signal } : {}),\n }).catch(() => [] as AiSiteDatasetRecordPhoto[])\n : []\n const content = input.pictures\n ? aiSiteDatasetContentWithPhotos(designed, generation.value.records.map((_values, index) => photos[index]?.src ?? null))\n : designed\n // The data plugin's own rules, before anything is written: content we\n // made that its model refuses is our failure, refunded.\n const checked = keeper.writer.check(content, { hostId: job.hostId })\n if (checked.ok === false) {\n console.error('ai site dataset: the dataset writer refused a dataset we made', { orgId: job.orgId, jobId: job.$id, problems: checked.problems })\n return { ...spent, failure: AI_SITE_DATASET_NOT_WRITTEN_COPY }\n }\n const result = await keeper.writer.write({\n orgId: job.orgId,\n hostId: job.hostId,\n uid: job.createdBy,\n org: (context.org ?? null) as Readonly<Record<string, unknown>> | null,\n now: context.now,\n id: job.$id,\n name: creation.name,\n content,\n })\n if (result.ok === false) {\n if (result.status === 400) return { ...spent, failure: AI_SITE_DATASET_NOT_WRITTEN_COPY }\n // The allowance, the role, the plan or the flag: the workspace's to change.\n return { ...spent, review: limitReview(result.error) }\n }\n const facts = result.facts as {\n fields?: AiLayoutListingField[]\n records?: number\n addressField?: string | null\n imageField?: string | null\n }\n const placed = photos.flatMap((photo) => (photo.placed ? [photo.placed] : []))\n const proposal: AiSiteDatasetProposal = {\n fields: facts.fields ?? [],\n recordNames: generation.value.records.map((values) => values[0] ?? '').filter(Boolean).slice(0, 12),\n addressField: facts.addressField ?? null,\n ...(facts.imageField ? { imageField: facts.imageField } : {}),\n ...(placed.length ? { photos: placed } : {}),\n sparseFields: aiDatasetSparseFields(generation.value, facts.fields ?? []),\n }\n return { ...spent, outputs: [output(result.id, result.name, proposal, facts.records ?? generation.value.records.length)] }\n }\n}\n\nexport const runAiSiteDatasetUnit = createAiSiteDatasetRunner()\n\n/**\n * Whether a dataset may be created for this member on this site, asked before\n * its first pass so a refusal spends nothing; `null` admits. The data plugin\n * must run here (on for the workspace and the site, past its release flag),\n * and its writer says whether this member may make one now: the role, the\n * plan, the flag, the allowance.\n */\nexport async function aiSiteDatasetRefusal(\n context: Pick<AiJobStepContext, 'firestore' | 'org' | 'now'> & { job: Pick<AiJob, 'orgId' | 'hostId' | 'createdBy'> },\n deps: { admission?: typeof aiPluginDraftAdmissionRefusal; writerFor?: (resource: string) => ReturnType<typeof pluginResourceDraftWriter> } = {},\n): Promise<string | null> {\n const { job } = context\n if (!job.hostId) return 'Open the site first.'\n const writerFor = deps.writerFor ?? pluginResourceDraftWriter\n const admission: AiJobAdmissionContext = {\n firestore: context.firestore,\n orgId: job.orgId,\n hostId: job.hostId,\n inputs: {},\n org: context.org ?? null,\n uid: job.createdBy,\n }\n const refused = await (deps.admission ?? aiPluginDraftAdmissionRefusal)(admission, {\n kind: 'site',\n drafts: [{ resource: AI_SITE_DATASET_RESOURCE, label: DATA_PLUGIN_LABEL }],\n writerFor: (resource) => writerFor(resource)?.writer ?? null,\n ownerFor: (resource) => writerFor(resource)?.pluginId ?? null,\n now: context.now,\n })\n return refused?.error ?? null\n}\n\n/**\n * A site plan's dataset capability on this workspace (AGL-3616): where the\n * workspace's plan includes datasets, whether the data plugin runs here and\n * this member may create one now, and how many a start may make. A clause the\n * plan's turn completes is the reason where it may not.\n */\nexport async function aiSitePlanDatasetCapability(\n capabilities: AiPlanCapabilities,\n context: Parameters<typeof aiSiteDatasetRefusal>[0],\n deps: Parameters<typeof aiSiteDatasetRefusal>[1] = {},\n): Promise<AiPlanCapabilities> {\n if (!capabilities.create.dataset.allowed) return capabilities\n const refusal = await aiSiteDatasetRefusal(context, deps).catch((error: unknown) => {\n console.error('ai site plan: the dataset admission failed', { orgId: context.job.orgId, error })\n return 'datasets could not be checked just now'\n })\n const left = Math.min(AI_SITE_DATASETS_MAX, checkDatasetQuota(context.org as never, 0).limit)\n const dataset = refusal\n ? { allowed: false, left: 0, reason: `datasets cannot be created here: ${refusal.replace(/\\.$/, '')}` }\n : { allowed: true, left, reason: null }\n return { ...capabilities, create: { ...capabilities.create, dataset } }\n}\n\n/**\n * A `records` listing for each dataset that was made and that a section of the\n * plan names (AGL-3616). Its fields, where none are given, are read off the\n * site's inventory when the page is designed (`aiLayoutListingsWithDatasets`).\n */\nexport function aiDatasetListingsOf(\n datasets: ReadonlyArray<{ id: string; name: string; records?: string[]; fields?: AiLayoutListingField[]; imageField?: string | null }>,\n screens: readonly AiLayoutListingScreen[],\n): AiLayoutListing[] {\n return datasets.flatMap((dataset) => {\n const placements = aiLayoutRecordsPlacements(dataset, screens)\n if (!placements.length) return []\n return [\n {\n id: aiLayoutListingId('records', dataset.id),\n kind: 'records' as const,\n name: dataset.name,\n records: dataset.records ?? [],\n datasetId: dataset.id,\n ...(dataset.fields?.length ? { fields: dataset.fields } : {}),\n // Its card leads with the record's photo (AGL-3616).\n ...(dataset.imageField ? { imageField: dataset.imageField } : {}),\n placements,\n },\n ]\n })\n}\n\n/**\n * The site's datasets a layout or a page unit is handed (AGL-3616), each a\n * `records` listing with the sections of the plan's pages that name it, once\n * its unit wrote it. A dataset not yet written, or one that failed, lists\n * nowhere: the pages built without it write the items out.\n */\nexport function aiSiteDatasetListings(input: {\n outputs: readonly AiJobOutput[]\n datasets: ReadonlyArray<Pick<AiBuildPlanCreate, 'name'>>\n screens: readonly AiLayoutListingScreen[]\n /** The ids each dataset's unit delivered, by plan name lowercased. */\n delivered: ReadonlyMap<string, string>\n}): AiLayoutListing[] {\n const made = input.datasets.flatMap((dataset) => {\n const id = input.delivered.get(dataset.name.trim().toLowerCase())\n const output = id\n ? input.outputs.find((entry) => entry.resource === 'draft' && entry.draftResource === AI_SITE_DATASET_RESOURCE && entry.id === id)\n : undefined\n if (!id || !output) return []\n const proposal = proposalOf(output)\n return [\n {\n id,\n // Placed by the name the plan's sections gave it.\n name: dataset.name,\n records: proposal.recordNames,\n // The address field is the record page's, never a card's words; the\n // photo is the card's picture, never its words; a field most records\n // leave empty is no card's either (AGL-3616).\n fields: proposal.fields.filter(\n (field, index) =>\n field.id !== proposal.addressField &&\n field.id !== proposal.imageField &&\n (index === 0 || !proposal.sparseFields?.includes(field.id)),\n ),\n imageField: proposal.imageField ?? null,\n },\n ]\n })\n return aiDatasetListingsOf(made, input.screens)\n}\n\n/** The library photos the site's datasets' records show (AGL-3616), which a page does not place again. */\nexport function aiSiteDatasetPlacedPhotos(outputs: readonly AiJobOutput[]): string[] {\n return [\n ...new Set(\n outputs\n .filter((output) => output.resource === 'draft' && output.draftResource === AI_SITE_DATASET_RESOURCE)\n .flatMap((output) => proposalOf(output).photos ?? []),\n ),\n ]\n}\n\n/** What a page is told about the datasets built before it. */\nexport function aiSiteDatasetBriefLines(outputs: readonly AiJobOutput[]): string[] {\n const datasets = outputs.filter((output) => output.resource === 'draft' && output.draftResource === AI_SITE_DATASET_RESOURCE)\n return datasets.flatMap((output) => {\n const names = proposalOf(output).recordNames\n return names.length\n ? [`This site's dataset “${output.label}” holds: ${names.map((name) => `“${name}”`).join(', ')}. Where a page names one, name it as written; never name one that is not in this list.`]\n : []\n })\n}\n"],"names":["checkDatasetQuota","pluginResourceDraftWriter","isAiPlanNewRef","AI_SITE_DATASETS_MAX","AI_STEP_TIERS","aiModelForStep","AI_DATASET_MAX_TOKENS","AI_DATASET_STEP","aiDatasetDraftContent","generateAiDataset","aiLayoutListingId","aiLayoutRecordsPlacements","aiLayoutStarterPhotos","aiSiteWords","aiOriginJobId","aiSiteProductPhotoSrc","aiLayoutStockPhotoSource","AI_DATASET_DRAFT_RESOURCE","aiJobStepBudget","aiGenerationSpent","aiUnspentOutcome","aiPluginDraftAdmissionRefusal","AI_SITE_DATASET_RESOURCE","DATA_PLUGIN_LABEL","AI_SITE_DATASET_INPUT","READ_ONLY_LIST","PEOPLE_LIST","PICTURED_LIST","PICTURED_SECTION","aiSiteDatasetPicturesOf","dataset","sections","length","own","name","test","some","section","AI_SITE_DATASET_NOT_WRITTEN_COPY","aiSiteDatasetNote","records","AI_SITE_RECORD_PAGE_NOTE","AI_SITE_DATASET_WRITES_MS","AI_SITE_DATASET_BUDGET","tier","maxTokens","lookups","ownReadsMs","str","value","trim","namesDataset","ref","slice","indexOf","toLowerCase","aiSitePlanDatasets","plan","create","filter","entry","kind","aiSiteDatasetInputOf","screens","shownIn","sectionNames","screen","uses","push","title","items","recordPages","record","form","find","writesTo","pictures","forForm","fields","AI_SITE_FORM_DATASET_FIELDS_MAX","aiSiteRecordTemplateOf","datasetInputOf","job","raw","inputs","Array","isArray","map","Boolean","FORM_DATASET_FIELD_TYPES","aiSiteDatasetFieldName","planned","words","replace","charAt","toUpperCase","aiSiteFormDatasetContent","specs","seen","Set","spec","at","lastIndexOf","typed","type","includes","fieldName","has","add","aiSiteFormDatasetNote","limitReview","message","reason","findings","AI_SITE_DATASET_PHOTOS_BUDGET_MS","AI_SITE_DATASET_IMAGE_FIELD","IMAGE_FIELD_NAME","aiSiteDatasetRecordPhotos","input","names","hostId","src","placed","people","slots","index","imageId","frameId","iconId","alt","aspect","sectionIndex","role","seed","$id","found","source","stockPhotos","uid","createdBy","business","about","brief","jobId","searches","signal","budgetMs","error","console","warn","String","starters","_slot","stock","aiSiteDatasetContentWithPhotos","content","photos","named","field","nextFields","next","photo","aiDatasetSparseFields","written","idOf","column","id","flatMap","filled","values","proposalOf","output","proposal","recordNames","addressField","imageField","startsWith","sparseFields","createAiSiteDatasetRunner","deps","generate","writerFor","photosFor","context","facts","firestore","model","modelFor","creation","keeper","failure","host","collection","doc","get","hostSubdomain","resource","draftResource","label","note","writer","read","again","outputs","checked","check","ok","orgId","problems","result","write","org","now","status","review","generation","merchantWords","why","spent","refused","designed","catch","_values","runAiSiteDatasetUnit","aiSiteDatasetRefusal","admission","drafts","ownerFor","pluginId","aiSitePlanDatasetCapability","capabilities","allowed","refusal","left","Math","min","limit","aiDatasetListingsOf","datasets","placements","datasetId","aiSiteDatasetListings","made","delivered","undefined","aiSiteDatasetPlacedPhotos","aiSiteDatasetBriefLines","join"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,iBAAiB,QAAQ,2CAA0C;AAC5E,SAASC,yBAAyB,QAAQ,qDAAoD;AAC9F,SAASC,cAAc,QAAwD,4BAAwB;AAGvG,SAASC,oBAAoB,QAAQ,0BAAsB;AAC3D,SAASC,aAAa,QAAQ,0BAAsB;AACpD,SAASC,cAAc,QAAQ,0BAAsB;AACrD,SACEC,qBAAqB,EACrBC,eAAe,EACfC,qBAAqB,EACrBC,iBAAiB,QACZ,sCAAkC;AACzC,SACEC,iBAAiB,EACjBC,yBAAyB,QAIpB,2CAAuC;AAC9C,SACEC,qBAAqB,QAGhB,2CAAuC;AAC9C,SAASC,WAAW,QAAQ,0BAAsB;AAElD,SAASC,aAAa,QAAQ,wBAAoB;AAClD,SAASC,qBAAqB,QAAQ,2BAAuB;AAC7D,SAASC,wBAAwB,QAAQ,8BAA0B;AACnE,SAASC,yBAAyB,QAAQ,6BAAyB;AACnE,SAASC,eAAe,QAAQ,qBAAiB;AACjD,SAASC,iBAAiB,EAAEC,gBAAgB,QAAQ,yBAAqB;AACzE,SAASC,6BAA6B,QAAQ,4BAAwB;AAGtE;;;;;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