@aglyn/plugins-ai 1.0.0-beta.285 → 1.0.0-beta.288
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +17 -17
- package/src/lib/assets/site-styles/nonprofit.webp +0 -0
- package/src/lib/assets/site-styles/professional.webp +0 -0
- package/src/lib/assets/site-styles/store.webp +0 -0
- package/src/lib/assets/site-styles/trades.webp +0 -0
- package/src/lib/components/ai-theme-proposal-card.component.js +12 -3
- package/src/lib/components/ai-theme-proposal-card.component.js.map +1 -1
- package/src/lib/declarations.js +5 -2
- package/src/lib/declarations.js.map +1 -1
- package/src/lib/declarations.server.js +12 -0
- package/src/lib/declarations.server.js.map +1 -1
- package/src/lib/jobs/ai-build-capabilities.d.ts +3 -1
- package/src/lib/jobs/ai-build-capabilities.js +27 -2
- package/src/lib/jobs/ai-build-capabilities.js.map +1 -1
- package/src/lib/jobs/ai-business-profile-prefill.js +6 -3
- package/src/lib/jobs/ai-business-profile-prefill.js.map +1 -1
- package/src/lib/jobs/ai-image-reads.d.ts +59 -0
- package/src/lib/jobs/ai-image-reads.js +138 -0
- package/src/lib/jobs/ai-image-reads.js.map +1 -0
- package/src/lib/jobs/ai-job-build-step.d.ts +29 -0
- package/src/lib/jobs/ai-job-build-step.js +83 -12
- package/src/lib/jobs/ai-job-build-step.js.map +1 -1
- package/src/lib/jobs/ai-job-duplicate-step.d.ts +2 -1
- package/src/lib/jobs/ai-job-duplicate-step.js +6 -6
- package/src/lib/jobs/ai-job-duplicate-step.js.map +1 -1
- package/src/lib/jobs/ai-job-import-step.d.ts +4 -2
- package/src/lib/jobs/ai-job-import-step.js +15 -11
- package/src/lib/jobs/ai-job-import-step.js.map +1 -1
- package/src/lib/jobs/ai-job-insight-step.d.ts +10 -0
- package/src/lib/jobs/ai-job-insight-step.js +23 -5
- package/src/lib/jobs/ai-job-insight-step.js.map +1 -1
- package/src/lib/jobs/ai-job-layout-language.js +2 -1
- package/src/lib/jobs/ai-job-layout-language.js.map +1 -1
- package/src/lib/jobs/ai-job-media-step.d.ts +2 -1
- package/src/lib/jobs/ai-job-media-step.js +6 -8
- package/src/lib/jobs/ai-job-media-step.js.map +1 -1
- package/src/lib/jobs/ai-job-navigation-step.d.ts +2 -1
- package/src/lib/jobs/ai-job-navigation-step.js +7 -9
- package/src/lib/jobs/ai-job-navigation-step.js.map +1 -1
- package/src/lib/jobs/ai-job-page-language.js +7 -1
- package/src/lib/jobs/ai-job-page-language.js.map +1 -1
- package/src/lib/jobs/ai-job-page-sections.js +16 -3
- package/src/lib/jobs/ai-job-page-sections.js.map +1 -1
- package/src/lib/jobs/ai-job-page-step.js +9 -1
- package/src/lib/jobs/ai-job-page-step.js.map +1 -1
- package/src/lib/jobs/ai-job-plan-step.d.ts +30 -8
- package/src/lib/jobs/ai-job-plan-step.js +78 -13
- package/src/lib/jobs/ai-job-plan-step.js.map +1 -1
- package/src/lib/jobs/ai-job-privacy-step.d.ts +4 -2
- package/src/lib/jobs/ai-job-privacy-step.js +14 -15
- package/src/lib/jobs/ai-job-privacy-step.js.map +1 -1
- package/src/lib/jobs/ai-job-products-step.js +5 -3
- package/src/lib/jobs/ai-job-products-step.js.map +1 -1
- package/src/lib/jobs/ai-job-settings-step.d.ts +2 -1
- package/src/lib/jobs/ai-job-settings-step.js +7 -8
- package/src/lib/jobs/ai-job-settings-step.js.map +1 -1
- package/src/lib/jobs/ai-job-site-content.d.ts +34 -1
- package/src/lib/jobs/ai-job-site-content.js +67 -8
- package/src/lib/jobs/ai-job-site-content.js.map +1 -1
- package/src/lib/jobs/ai-job-site-datasets.d.ts +53 -3
- package/src/lib/jobs/ai-job-site-datasets.js +300 -30
- package/src/lib/jobs/ai-job-site-datasets.js.map +1 -1
- package/src/lib/jobs/ai-job-site-step.js +6 -3
- package/src/lib/jobs/ai-job-site-step.js.map +1 -1
- package/src/lib/jobs/ai-job-site-store-pages.js +3 -3
- package/src/lib/jobs/ai-job-site-store-pages.js.map +1 -1
- package/src/lib/jobs/ai-job-text-step.js +2 -1
- package/src/lib/jobs/ai-job-text-step.js.map +1 -1
- package/src/lib/jobs/ai-job-tracking-step.d.ts +2 -1
- package/src/lib/jobs/ai-job-tracking-step.js +7 -8
- package/src/lib/jobs/ai-job-tracking-step.js.map +1 -1
- package/src/lib/jobs/ai-jobs-beat.d.ts +11 -7
- package/src/lib/jobs/ai-jobs-beat.js +18 -8
- package/src/lib/jobs/ai-jobs-beat.js.map +1 -1
- package/src/lib/jobs/ai-jobs-notify.d.ts +66 -1
- package/src/lib/jobs/ai-jobs-notify.js +136 -3
- package/src/lib/jobs/ai-jobs-notify.js.map +1 -1
- package/src/lib/jobs/ai-layout-stock-photos.d.ts +155 -7
- package/src/lib/jobs/ai-layout-stock-photos.js +1517 -220
- package/src/lib/jobs/ai-layout-stock-photos.js.map +1 -1
- package/src/lib/jobs/ai-product-image.d.ts +14 -0
- package/src/lib/jobs/ai-product-image.js +73 -21
- package/src/lib/jobs/ai-product-image.js.map +1 -1
- package/src/lib/jobs/ai-theme-brand-inputs.d.ts +9 -1
- package/src/lib/jobs/ai-theme-brand-inputs.js +28 -2
- package/src/lib/jobs/ai-theme-brand-inputs.js.map +1 -1
- package/src/lib/jobs/fixtures/ai-site-agl4065-datasets.d.ts +175 -0
- package/src/lib/jobs/fixtures/ai-site-agl4065-datasets.js +601 -0
- package/src/lib/jobs/fixtures/ai-site-agl4065-datasets.js.map +1 -0
- package/src/lib/jobs/fixtures/ai-site-agl4065-pages.d.ts +46 -0
- package/src/lib/jobs/fixtures/ai-site-agl4065-pages.js +2862 -0
- package/src/lib/jobs/fixtures/ai-site-agl4065-pages.js.map +1 -0
- package/src/lib/jobs/fixtures/ai-site-agl4065-plans.d.ts +74 -0
- package/src/lib/jobs/fixtures/ai-site-agl4065-plans.js +888 -0
- package/src/lib/jobs/fixtures/ai-site-agl4065-plans.js.map +1 -0
- package/src/lib/jobs/fixtures/ai-site-agl4092-datasets.d.ts +120 -0
- package/src/lib/jobs/fixtures/ai-site-agl4092-datasets.js +410 -0
- package/src/lib/jobs/fixtures/ai-site-agl4092-datasets.js.map +1 -0
- package/src/lib/jobs/fixtures/ai-stock-photo-agl4065-judge.d.ts +29 -0
- package/src/lib/jobs/fixtures/ai-stock-photo-agl4065-judge.js +81 -0
- package/src/lib/jobs/fixtures/ai-stock-photo-agl4065-judge.js.map +1 -0
- package/src/lib/jobs/fixtures/ai-stock-photo-agl4065-recordings.d.ts +87 -0
- package/src/lib/jobs/fixtures/ai-stock-photo-agl4065-recordings.js +225 -0
- package/src/lib/jobs/fixtures/ai-stock-photo-agl4065-recordings.js.map +1 -0
- package/src/lib/jobs/fixtures/ai-stock-photo-agl4092-recordings.d.ts +26 -0
- package/src/lib/jobs/fixtures/ai-stock-photo-agl4092-recordings.js +714 -0
- package/src/lib/jobs/fixtures/ai-stock-photo-agl4092-recordings.js.map +1 -0
- package/src/lib/layout-language/ai-layout-compiler.d.ts +11 -0
- package/src/lib/layout-language/ai-layout-compiler.js +194 -18
- package/src/lib/layout-language/ai-layout-compiler.js.map +1 -1
- package/src/lib/layout-language/ai-layout-copy.d.ts +37 -0
- package/src/lib/layout-language/ai-layout-copy.js +383 -3
- package/src/lib/layout-language/ai-layout-copy.js.map +1 -1
- package/src/lib/layout-language/ai-layout-design.d.ts +19 -0
- package/src/lib/layout-language/ai-layout-design.js +31 -11
- package/src/lib/layout-language/ai-layout-design.js.map +1 -1
- package/src/lib/layout-language/ai-layout-listings.d.ts +7 -1
- package/src/lib/layout-language/ai-layout-listings.js +9 -1
- package/src/lib/layout-language/ai-layout-listings.js.map +1 -1
- package/src/lib/layout-language/ai-layout-pictures.d.ts +39 -1
- package/src/lib/layout-language/ai-layout-pictures.js +141 -4
- package/src/lib/layout-language/ai-layout-pictures.js.map +1 -1
- package/src/lib/layout-language/ai-layout-storefront.d.ts +18 -4
- package/src/lib/layout-language/ai-layout-storefront.js +100 -20
- package/src/lib/layout-language/ai-layout-storefront.js.map +1 -1
- package/src/lib/model/ai-build-job.d.ts +7 -0
- package/src/lib/model/ai-build-job.js +36 -7
- package/src/lib/model/ai-build-job.js.map +1 -1
- package/src/lib/model/ai-build-plan.d.ts +28 -4
- package/src/lib/model/ai-build-plan.js +49 -9
- package/src/lib/model/ai-build-plan.js.map +1 -1
- package/src/lib/model/ai-build-progress.js +3 -1
- package/src/lib/model/ai-build-progress.js.map +1 -1
- package/src/lib/model/ai-job-notice.d.ts +8 -0
- package/src/lib/model/ai-job-notice.js +33 -0
- package/src/lib/model/ai-job-notice.js.map +1 -1
- package/src/lib/model/ai-job-plan-lines.d.ts +2 -1
- package/src/lib/model/ai-job-plan-lines.js +6 -1
- package/src/lib/model/ai-job-plan-lines.js.map +1 -1
- package/src/lib/model/ai-jobs.types.d.ts +8 -0
- package/src/lib/model/ai-jobs.types.js.map +1 -1
- package/src/lib/model/ai-permissions.d.ts +13 -0
- package/src/lib/model/ai-permissions.js +29 -1
- package/src/lib/model/ai-permissions.js.map +1 -1
- package/src/lib/model/ai-plan-said-sections.d.ts +12 -3
- package/src/lib/model/ai-plan-said-sections.js +22 -5
- package/src/lib/model/ai-plan-said-sections.js.map +1 -1
- package/src/lib/model/ai-products.d.ts +18 -0
- package/src/lib/model/ai-products.js +32 -0
- package/src/lib/model/ai-products.js.map +1 -1
- package/src/lib/model/ai-site-context.d.ts +6 -2
- package/src/lib/model/ai-site-context.js +8 -2
- package/src/lib/model/ai-site-context.js.map +1 -1
- package/src/lib/model/ai-site-inspiration.d.ts +3 -2
- package/src/lib/model/ai-site-inspiration.js +3 -2
- package/src/lib/model/ai-site-inspiration.js.map +1 -1
- package/src/lib/plugin.js +4 -13
- package/src/lib/plugin.js.map +1 -1
- package/src/lib/providers/anthropic.js +9 -2
- package/src/lib/providers/anthropic.js.map +1 -1
- package/src/lib/providers/catalog.js +14 -5
- package/src/lib/providers/catalog.js.map +1 -1
- package/src/lib/providers/contract.d.ts +24 -1
- package/src/lib/providers/contract.js.map +1 -1
- package/src/lib/providers/routing.js +5 -2
- package/src/lib/providers/routing.js.map +1 -1
- package/src/lib/runtime/ai-dataset-generation.d.ts +120 -1
- package/src/lib/runtime/ai-dataset-generation.js +352 -3
- package/src/lib/runtime/ai-dataset-generation.js.map +1 -1
- package/src/lib/runtime/ai-dev-replay.d.ts +1 -0
- package/src/lib/runtime/ai-dev-replay.js +4 -2
- package/src/lib/runtime/ai-dev-replay.js.map +1 -1
- package/src/lib/runtime/ai-doctrine-validators.d.ts +47 -3
- package/src/lib/runtime/ai-doctrine-validators.js +345 -28
- package/src/lib/runtime/ai-doctrine-validators.js.map +1 -1
- package/src/lib/runtime/ai-doctrine.d.ts +5 -4
- package/src/lib/runtime/ai-doctrine.js +10 -3
- package/src/lib/runtime/ai-doctrine.js.map +1 -1
- package/src/lib/runtime/ai-icon-library.d.ts +27 -1
- package/src/lib/runtime/ai-icon-library.js +30 -3
- package/src/lib/runtime/ai-icon-library.js.map +1 -1
- package/src/lib/runtime/ai-products-generation.d.ts +11 -1
- package/src/lib/runtime/ai-products-generation.js +51 -4
- package/src/lib/runtime/ai-products-generation.js.map +1 -1
- package/src/lib/runtime/assist-answer-cache.d.ts +2 -0
- package/src/lib/runtime/assist-answer-cache.js +5 -2
- package/src/lib/runtime/assist-answer-cache.js.map +1 -1
- package/src/lib/server/ai-allotments.js +7 -2
- package/src/lib/server/ai-allotments.js.map +1 -1
- package/src/lib/server/ai-experiment-versions.js +5 -5
- package/src/lib/server/ai-experiment-versions.js.map +1 -1
- package/src/lib/server/ai-host-permissions-roster.d.ts +25 -0
- package/src/lib/server/ai-host-permissions-roster.js +33 -0
- package/src/lib/server/ai-host-permissions-roster.js.map +1 -0
- package/src/lib/server/ai-host-permissions.js +8 -6
- package/src/lib/server/ai-host-permissions.js.map +1 -1
- package/src/lib/server/ai-image-reads-route.d.ts +17 -0
- package/src/lib/server/ai-image-reads-route.js +106 -0
- package/src/lib/server/ai-image-reads-route.js.map +1 -0
- package/src/lib/server/ai-seo-apply.js +5 -5
- package/src/lib/server/ai-seo-apply.js.map +1 -1
- package/src/lib/server/ai-site-import-route.js +7 -4
- package/src/lib/server/ai-site-import-route.js.map +1 -1
- package/src/lib/server/assist-build.d.ts +15 -1
- package/src/lib/server/assist-build.js +30 -3
- package/src/lib/server/assist-build.js.map +1 -1
- package/src/lib/server/assist-chat.d.ts +11 -7
- package/src/lib/server/assist-chat.js +185 -48
- package/src/lib/server/assist-chat.js.map +1 -1
- package/src/lib/server/assist-docs-query.d.ts +51 -0
- package/src/lib/server/assist-docs-query.js +57 -0
- package/src/lib/server/assist-docs-query.js.map +1 -0
- package/src/lib/server/assist-jobs-context.d.ts +102 -0
- package/src/lib/server/assist-jobs-context.js +227 -0
- package/src/lib/server/assist-jobs-context.js.map +1 -0
- package/src/lib/server/assist-view-context.d.ts +8 -4
- package/src/lib/server/assist-view-context.js +12 -7
- package/src/lib/server/assist-view-context.js.map +1 -1
- package/src/lib/server.js +12 -0
- package/src/lib/server.js.map +1 -1
- package/src/lib/tools/ai-dataset-tool.d.ts +11 -1
- package/src/lib/tools/ai-dataset-tool.js +24 -7
- package/src/lib/tools/ai-dataset-tool.js.map +1 -1
- package/src/lib/tools/ai-duplicate-resource-tool.js +5 -6
- package/src/lib/tools/ai-duplicate-resource-tool.js.map +1 -1
- package/src/lib/components/ai-collaborator-permissions-column.component.d.ts +0 -32
- package/src/lib/components/ai-collaborator-permissions-column.component.js +0 -132
- package/src/lib/components/ai-collaborator-permissions-column.component.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/jobs/ai-job-site-step.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 { aiJobCancelAsked } from './ai-job-cancel'\nimport { resolveEffectivePlan } from '@aglyn/aglyn/app-utils/plan-entitlements'\nimport { resolveOrgIdForHost } from '@aglyn/tenant-data-admin/server/organizations'\nimport {\n isAiPlanNewRef,\n type AiBuildItem,\n type AiBuildPlanCreate,\n type AiBuildPlanCreateKind,\n type AiBuildPlanScreen,\n} from '../model/ai-build-plan'\nimport type {\n AiJob,\n AiJobItemLedger,\n AiJobKind,\n AiJobOutput,\n AiJobOutputResource,\n AiJobPlan,\n} from '../model/ai-jobs.types'\nimport {\n aiBuildDegradation,\n aiBuildInitialLedger,\n aiBuildItemDelivered,\n aiBuildItemOpen,\n aiBuildNextUnit,\n type AiBuildUnit,\n} from '../model/ai-build-job'\nimport { aiBuildBuiltRefs, aiUnitErrorRetryable, aiUnitFailure, aiUnitSpend } from './ai-build-unit-outcome'\nimport {\n AI_SITE_EMAIL_TYPE,\n AI_SITE_MAX_SECTIONS,\n AI_SITE_PAGES,\n aiFreeCreditsNoneLeftText,\n aiFreeSitePrompt,\n aiSiteNameSentence,\n aiSitePagesRefusal,\n aiSitePlanRefusal,\n aiSiteSubmissions,\n aiSiteWords,\n parseAiSiteJobInputs,\n type AiSiteJobInputs,\n aiSiteBlogNavPage,\n aiSiteIsBlogStandIn,\n aiSitePlanWithoutBlogStandIns,\n} from '../model/ai-site-job'\nimport { readFreeAiCreditsLeft } from '../usage/free-ai-credits-left'\nimport { AI_CREDITS_CONFIRM_CODE, aiCreditsPromptText } from '../model/ai-credit-estimate'\nimport {\n AI_SITE_SEO_OUTPUT_ID,\n aiSiteSeoProposalForInputs,\n} from '../model/ai-site-start-seo'\nimport { aiSiteDetailsBriefLines } from '../model/ai-site-details'\nimport { aiModelForStep } from '../providers/routing'\nimport { registerAiJobAdmission, type AiJobAdmission } from './ai-job-admission'\nimport { aiOriginJobId, aiRecordedJobDraftId } from './ai-job-draft-ids'\nimport { readAiDraftNodes } from './ai-job-drafts'\nimport {\n AI_STOCK_PHOTO_AVOID_INPUT,\n AI_STOCK_PHOTO_JOB_PHOTOS_INPUT,\n AI_STOCK_PHOTO_LATE_PASS_INPUT,\n AI_STOCK_PHOTO_PAGES_INPUT,\n} from './ai-layout-stock-photos'\nimport {\n AI_LAYOUT_SITE_ALIASES_INPUT,\n AI_LAYOUT_SITE_PAGES_INPUT,\n AI_LAYOUT_SITE_PAGES_MAX,\n aiLayoutIsHomeSlug,\n aiLayoutSitePagesOfPlan,\n} from './ai-job-layout-site-pages'\nimport { aiPageSectionNodeId } from './ai-job-page-sections'\nimport { AI_LAYOUT_LISTINGS_INPUT, aiLayoutIsShopPage } from '../layout-language/ai-layout-listings'\nimport { aiSiteKindOfInputs } from '../model/ai-site-kinds'\nimport { AI_LAYOUT_FORM_PAGE_INPUT, AI_LAYOUT_LANGUAGE_INPUT, aiJobUsesLayoutLanguage, aiLayoutFormPageOfPlan } from './ai-job-page-language'\nimport { aiJobPublishesSite, aiMergeSitePublish, aiPublishGuidedSite, aiRestoreGuidedBlogEntry } from './ai-site-publish'\nimport {\n AI_SITE_CONTENT_INPUT,\n AI_SITE_FREE_POSTS,\n AI_SITE_POST_BUDGET,\n AI_SITE_POST_LABEL,\n AI_SITE_POSTS,\n AI_SITE_POSTS_LABEL,\n AI_SITE_PRODUCTS_LABEL,\n AI_SITE_PRODUCTS_PRICE_NOTE,\n aiPublishSitePosts,\n aiSiteContentBriefLines,\n aiSiteContentPart,\n aiSiteContentRefusal,\n aiSiteListings,\n aiSiteProductsBriefLine,\n createAiSiteProductsRunner,\n runAiSitePostsUnit,\n type AiSitePostsInput,\n} from './ai-job-site-content'\nimport { dropPluginSiteCache } from '@aglyn/aglyn/plugin-manager/plugin-site-cache'\nimport {\n AI_SITE_DATASET_BUDGET,\n AI_SITE_DATASET_INPUT,\n AI_SITE_DATASETS_MAX,\n aiSiteDatasetBriefLines,\n aiSiteDatasetInputOf,\n aiSiteDatasetListings,\n aiSiteDatasetPlacedPhotoDetails,\n aiSiteDatasetPlacedPhotos,\n aiSiteDatasetRefusal,\n aiSitePlanDatasets,\n aiSiteReusedDatasetListings,\n aiSiteRecordTemplateOf,\n runAiSiteDatasetUnit,\n} from './ai-job-site-datasets'\nimport {\n AI_SITE_EVENT_INPUT,\n AI_SITE_EVENT_LABEL,\n AI_SITE_EVENT_MINIMUM_MS,\n AI_SITE_EVENTS_MAX,\n aiSiteEventListings,\n aiSiteEventRefusal,\n aiSitePlanEvents,\n runAiSiteEventUnit,\n} from './ai-job-site-events'\nimport { AI_SITE_LOOK_BUDGET, aiRunSiteLook } from './ai-job-site-look'\nimport {\n AI_SITE_STORE_PAGES_INPUT,\n aiSiteStorePagesRefusal,\n runAiSiteStorePagesUnit,\n type AiSiteStorePagesInput,\n} from './ai-job-site-store-pages'\nimport {\n AI_SITE_STORE_LINKS_INPUT,\n AI_SITE_STORE_PAGES_LABEL,\n AI_SITE_STORE_PAGES_NOTE,\n aiStoreFrameLinks,\n aiStorePagesOfPlan,\n} from '../model/ai-site-store-pages'\nimport { AI_FORM_DATASET_MADE_INPUT } from './ai-job-form-dataset'\nimport { aiConfirmedPlan, aiUnspentOutcome } from './ai-job-generation'\nimport {\n AI_JOB_BRIEF_MAX_CHARS,\n type AiJobItemOutcome,\n type AiJobStepContext,\n type AiJobStepOutcome,\n type AiJobStepRunner,\n} from './ai-job-text-step'\nimport { AI_JOB_PAGE_STEP_MINIMUM_MS } from './ai-job-page-budget'\nimport { aiSiteMergePhotos, aiSitePhotosOwed, type AiSitePhotos } from '../model/ai-site-photos'\nimport { AI_SITE_LATE_PHOTOS_MINIMUM_MS, aiSiteLatePhotos } from './ai-site-late-photos'\nimport { AI_SITE_INSPIRATION_SIGNALS_INPUT, aiSiteInspirationReleased } from './ai-site-inspiration'\nimport { aiSiteInspirationRefusal } from '../model/ai-site-inspiration'\nimport {\n aiJobStepRunMinimumMs,\n aiJobStepRunnerFor,\n registerAiJobStep,\n registerAiJobStepPasses,\n} from './ai-jobs'\n\n/**\n * The site scaffold (AGL-2911): the generation step of a `site` job, run once\n * a member confirmed the plan their brief produced.\n *\n * ── It builds nothing itself ─────────────────────────────────────────────\n *\n * A scaffold is a whole site: a palette suggestion, the layout its pages\n * render inside, the contact form they place, four to eight pages with their\n * search listings, and a welcome email. Every one of those is already a job\n * kind with a step of its own, so this step generates nothing and asks no\n * model anything. It works through the confirmed plan one UNIT at a time and\n * hands each unit to the runner registered for the kind that owns it — the\n * theme step for the palette, the page step for a page — under a job of that\n * kind derived from this one.\n *\n * That is why the scaffold cannot drift from the thing it scaffolds: a page\n * it builds is a page job's page, held to the same doctrine, written by the\n * same draft writer, left unpublished by the same rule. A kind whose step\n * this deployment has not loaded is simply not among the units, so nothing\n * here knows which issues have landed.\n *\n * ── One unit a pass ──────────────────────────────────────────────────────\n *\n * The step runs ONE delegated pass and asks the machine to continue, so every\n * pass is one reservation, one provider exchange and one recorded spend, and\n * the org's monthly ceiling binds a scaffold exactly as it binds a chat turn.\n * Credits running out mid-scaffold is therefore the machine's own park: the\n * job waits as `needs_input` with the meter's words, and the beat resumes it\n * where it stopped once the workspace's standing has changed. A pass needs the\n * time its unit's own step needs (`aiSiteJobRunMinimumMs`), so the beat starts\n * a palette change only with a palette change's time left.\n *\n * Where it stopped is read from the job's OUTPUTS rather than kept anywhere:\n * each unit reports exactly one output when it completes, so the units\n * already represented there are the ones already built. A pass interrupted\n * between its work and its record repeats a unit that then finds its own\n * draft and reports it, which is what every step's draft id already gives.\n *\n * ── Never published ──────────────────────────────────────────────────────\n *\n * Nothing here publishes, routes or sends: each delegated step writes the\n * unpublished draft it already wrote for a job of its own kind, and the\n * palette and navigation travel as proposals a member applies.\n *\n * ── The page job builds its creations the same way (AGL-3031) ────────────\n *\n * A page job whose plan creates a layout, forms or components builds them\n * before its page through this same machinery: the units a creation implies\n * (`aiCreationUnit`), where the job stands read from its outputs\n * (`aiSitePendingUnits`), one delegated pass a unit (`aiRunJobUnit`), and the\n * `new:<name>` references resolved to what was built (`aiSiteBuiltRefs`,\n * `aiSiteUnitJob`). There is one loop, and it is the machine's.\n */\n\n/**\n * What a scaffold's units are, in the order it builds them; a component is a\n * page job's. The site's datasets (AGL-3616) are built after the layout and\n * before the form, which may write its submissions to one; a blog's first\n * posts and a store's first products (AGL-3676) after the form; all of them\n * before the pages, which are told what they are. A paid store's account,\n * cart and policy pages (`store`, AGL-3676) come after its planned pages,\n * which keep the first claim on the site's pages allowance.\n */\nexport type AiSiteUnitKind =\n | 'theme'\n | 'layout'\n | 'form'\n | 'component'\n | 'dataset'\n | 'event'\n | 'posts'\n | 'products'\n | 'page'\n | 'store'\n | 'email'\n\nexport interface AiSiteUnit {\n kind: AiSiteUnitKind\n /** The job kind whose registered runner builds it. */\n jobKind: AiJobKind\n /** The resource the unit reports when it completes. */\n resource: AiJobOutputResource\n /** Stable within the job: what the unit's derived job and draft are addressed by. */\n slot: string\n /** The plan screen a page unit builds. */\n screen?: AiBuildPlanScreen\n /** The creation a theme, layout or form unit builds. */\n creation?: AiBuildPlanCreate\n /** The event an event unit drafts (AGL-3755). */\n item?: AiBuildItem\n /** How many first posts a posts unit writes: `AI_SITE_POSTS`, or a Free blog's `AI_SITE_FREE_POSTS`. */\n posts?: number\n /** What the unit is, for the derived job's brief. */\n label: string\n}\n\n/** The job kind and output resource each unit is built through. */\nconst UNIT_KINDS: Record<\n AiSiteUnitKind,\n { jobKind: AiJobKind; resource: AiJobOutputResource }\n> = {\n theme: { jobKind: 'theme', resource: 'theme' },\n layout: { jobKind: 'layout', resource: 'layout' },\n form: { jobKind: 'form', resource: 'form' },\n component: { jobKind: 'component', resource: 'reusableComponent' },\n page: { jobKind: 'page', resource: 'screen' },\n email: { jobKind: 'email', resource: 'emailScreen' },\n // The scaffold's own runner writes them (`ai-job-site-content.ts`); the\n // posts' job kind is the one whose derived job a post's brief is, and the\n // products' the step that proposes the catalog they are written from.\n posts: { jobKind: 'text', resource: 'entry' },\n products: { jobKind: 'products', resource: 'product' },\n // The scaffold's own runner designs it (`ai-job-site-datasets.ts`), and the\n // data plugin's writer keeps it: a draft of another plugin's (AGL-3616).\n dataset: { jobKind: 'text', resource: 'draft' },\n // An event-led start's first events (AGL-3755): the events-calendar\n // plugin's writer keeps each, run by the scaffold's own pass.\n event: { jobKind: 'text', resource: 'draft' },\n // The scaffold's own runner writes them, by code (`ai-job-site-store-pages.ts`).\n store: { jobKind: 'text', resource: 'screen' },\n}\n\n/** The unit kind a creation is built as, where a unit builds it. */\nconst CREATION_UNIT_KINDS: Partial<Record<AiBuildPlanCreateKind, AiSiteUnitKind>> = {\n 'theme-change': 'theme',\n layout: 'layout',\n form: 'form',\n component: 'component',\n}\n\n/**\n * The unit one creation is built as, under the slot its derived job and draft\n * are addressed by; `null` for a creation no unit builds.\n */\nexport function aiCreationUnit(creation: AiBuildPlanCreate, slot: string): AiSiteUnit | null {\n const kind = CREATION_UNIT_KINDS[creation.kind]\n if (!kind) return null\n return { kind, ...UNIT_KINDS[kind], slot, creation, label: creation.name }\n}\n\n/** The creation kinds a unit is built from, by unit kind. */\nconst CREATION_UNITS: Array<{\n unit: AiSiteUnitKind\n create: AiBuildPlanCreateKind\n}> = [\n { unit: 'theme', create: 'theme-change' },\n { unit: 'layout', create: 'layout' },\n { unit: 'form', create: 'form' },\n]\n\n/** What the look's unit is called on the ledger. */\nexport const AI_SITE_LOOK_LABEL = 'Your look'\n\nexport const AI_SITE_NO_PLAN_COPY =\n 'This site job has no confirmed plan to build.'\n\n/** What a scaffold answers where the step that builds a page is not loaded. */\nexport const AI_SITE_NO_PAGE_STEP_COPY =\n 'Building a whole site is not available yet.'\n\n/** A unit that finished without reporting what it built; the scaffold cannot go on. */\nexport const AI_SITE_UNIT_EMPTY_COPY =\n 'Part of this site could not be built. Try the site brief again.'\n\n/**\n * The passes the late photo pass may add (AGL-3988): the one that hands the\n * publish to it, its own, and one more where a beat's time ran out on it.\n * That last one publishes whatever the pictures hold (`latePasses`).\n */\nexport const AI_SITE_LATE_PHOTOS_PASSES = 3\n\n/**\n * The most passes a scaffold's step may take: the largest plan it admits —\n * eight pages of eight sections, its three creations, a blog's first posts\n * (one a pass, the largest part), a welcome email and the late photo pass\n * (AGL-3988) — with nothing to spare, so a runner that never finishes is\n * still bounded while a real site is not.\n */\nexport const AI_SITE_MAX_PASSES =\n AI_SITE_PAGES.max * (AI_SITE_MAX_SECTIONS + 1) +\n CREATION_UNITS.length +\n AI_SITE_DATASETS_MAX +\n AI_SITE_EVENTS_MAX +\n AI_SITE_POSTS +\n 2 +\n AI_SITE_LATE_PHOTOS_PASSES\n\n/**\n * The units a plan implies, in build order: the palette first, because a\n * member reads it while the pages are still building; then the layout every\n * page renders inside, the site's datasets, and the form they place —\n * because a page binds the layout and the form by id, and a form binds the\n * dataset it writes to (AGL-3616), so each needs what it binds to exist;\n * then the pages; then the welcome email, which is about the site rather\n * than part of it.\n */\nexport function aiSiteJobUnits(\n plan: Pick<AiJobPlan, 'create' | 'screens'> & Partial<Pick<AiJobPlan, 'items'>>,\n options: { welcomeEmail?: boolean; content?: 'posts' | 'products' | null; posts?: number } = {},\n): AiSiteUnit[] {\n // The site's look is designed first, on every scaffold (AGL-3660): the\n // header, the footer and every page render in it from their first draft.\n // A theme change the plan names is that same unit, never a second one.\n const units: AiSiteUnit[] = [\n { kind: 'theme', ...UNIT_KINDS.theme, slot: 't', label: AI_SITE_LOOK_LABEL },\n ]\n for (const { unit, create } of CREATION_UNITS) {\n if (unit === 'theme') continue\n // The site's datasets (AGL-3616), before anything that lists them and\n // before the form, which may write its submissions to one of them.\n if (unit === 'form') {\n aiSitePlanDatasets(plan).forEach((creation, index) => {\n units.push({ kind: 'dataset', ...UNIT_KINDS.dataset, slot: `d${index}`, creation, label: creation.name })\n })\n }\n const creation = plan.create.find((entry) => entry.kind === create)\n if (!creation) continue\n units.push({\n kind: unit,\n ...UNIT_KINDS[unit],\n slot: unit[0],\n creation,\n label: creation.name,\n })\n }\n // A blog's first posts — one on the Free taste — and a paid store's first products (AGL-3676).\n if (options.content === 'posts') {\n const posts = options.posts ?? AI_SITE_POSTS\n units.push({ kind: 'posts', ...UNIT_KINDS.posts, slot: 'posts', posts, label: posts === 1 ? AI_SITE_POST_LABEL : AI_SITE_POSTS_LABEL })\n } else if (options.content === 'products') {\n units.push({ kind: 'products', ...UNIT_KINDS.products, slot: 'products', label: AI_SITE_PRODUCTS_LABEL })\n }\n // An event-led start's first events (AGL-3755), before the pages that list them.\n aiSitePlanEvents(plan).forEach((item, index) => {\n units.push({ kind: 'event', ...UNIT_KINDS.event, slot: `v${index}`, item, label: item.name || AI_SITE_EVENT_LABEL })\n })\n plan.screens.forEach((screen, index) => {\n units.push({\n kind: 'page',\n ...UNIT_KINDS.page,\n slot: `p${index}`,\n screen,\n label: screen.title,\n })\n })\n // A paid store's own pages (AGL-3676): outside the plan's pages, after them.\n if (options.content === 'products') {\n units.push({ kind: 'store', ...UNIT_KINDS.store, slot: 'store', label: AI_SITE_STORE_PAGES_LABEL })\n }\n if (options.welcomeEmail) {\n units.push({\n kind: 'email',\n ...UNIT_KINDS.email,\n slot: 'e',\n label: 'Welcome email',\n })\n }\n return units\n}\n\n/**\n * The units a scaffold still owes after the outputs recorded so far. Each\n * unit reports one output of its own resource when it completes, so the\n * outputs already recorded are consumed against the units in build order.\n */\nexport function aiSitePendingUnits(\n units: readonly AiSiteUnit[],\n outputs: readonly Pick<AiJobOutput, 'resource'>[],\n): AiSiteUnit[] {\n const done = new Map<AiJobOutputResource, number>()\n for (const output of outputs) {\n done.set(output.resource, (done.get(output.resource) ?? 0) + 1)\n }\n return units.filter((unit) => {\n const left = done.get(unit.resource) ?? 0\n if (left <= 0) return true\n done.set(unit.resource, left - 1)\n return false\n })\n}\n\n/**\n * The site's own search listing as the scaffold reports it (AGL-2918), or\n * nothing when the job already reported one or its inputs describe no site.\n *\n * It costs nothing and asks no model: the values are arithmetic on the\n * answers (`aiSiteSeoProposal`), so they ride out on the first pass that\n * builds anything rather than waiting for a pass of their own. Its resource\n * is `seo`, which no unit reports, so it cannot be mistaken for a unit's\n * output by `aiSitePendingUnits` and cannot move where the scaffold thinks\n * it is.\n */\nexport function aiSiteSeoOutputs(job: AiJob, siteName?: string | null): AiJobOutput[] {\n if (!aiSiteSeoOutputOwed(job)) return []\n // The site's own name leads it where the start named no business (AGL-3979):\n // the same listing the publish writes over the seeded default.\n const proposal = aiSiteSeoProposalForInputs(job.inputs, job.plan?.language, siteName)\n if (!proposal) return []\n return [\n {\n resource: 'seo',\n id: AI_SITE_SEO_OUTPUT_ID,\n hostId: job.hostId ?? null,\n label: 'The site’s search title and description',\n proposal: proposal as unknown as Record<string, unknown>,\n },\n ]\n}\n\n/** Whether the scaffold has yet to report the site's listing. */\nexport function aiSiteSeoOutputOwed(job: Pick<AiJob, 'outputs'>): boolean {\n return !(job.outputs ?? []).some((output) => output.resource === 'seo' && output.id === AI_SITE_SEO_OUTPUT_ID)\n}\n\n/** The site's own name, which its listing leads with (AGL-3979); `null` when it cannot be read. */\nexport async function aiSiteDisplayName(\n firestore: FirebaseFirestore.Firestore,\n hostId: string | null | undefined,\n): Promise<string | null> {\n if (!hostId) return null\n try {\n const name = (await firestore.collection('hosts').doc(hostId).get()).get('displayName')\n return typeof name === 'string' && name.trim() ? name.trim() : null\n } catch {\n // A listing without the name is the listing every start made before.\n return null\n }\n}\n\n/** A record an earlier unit created, as a later one references it. */\nexport interface AiSiteBuiltRef {\n id: string\n label: string\n /** Only what becomes a record a page can name; a palette change is not one. */\n kind: 'layout' | 'form' | 'component' | 'dataset'\n}\n\n/**\n * What the scaffold has already created, as the plan's `new:<name>`\n * references resolve to: the id of the record each completed creation wrote.\n * A page unit is told about the layout and the form by id, exactly as a page\n * job is told about records the site already had.\n */\nexport function aiSiteBuiltRefs(\n units: readonly AiSiteUnit[],\n outputs: readonly Pick<AiJobOutput, 'resource' | 'id' | 'label'>[],\n): Map<string, AiSiteBuiltRef> {\n const byResource = new Map<\n AiJobOutputResource,\n Array<Pick<AiJobOutput, 'id' | 'label'>>\n >()\n for (const output of outputs) {\n const rows = byResource.get(output.resource) ?? []\n rows.push(output)\n byResource.set(output.resource, rows)\n }\n const built = new Map<string, AiSiteBuiltRef>()\n for (const unit of units) {\n const rows = byResource.get(unit.resource)\n const row = rows?.shift()\n if (!row || !unit.creation) continue\n // A theme change is a proposal with no record to reference; a layout, a\n // form, a component and a dataset (AGL-3616) become ids a page can name.\n if (\n unit.creation.kind !== 'layout' &&\n unit.creation.kind !== 'form' &&\n unit.creation.kind !== 'component' &&\n unit.creation.kind !== 'dataset'\n ) {\n continue\n }\n built.set(unit.creation.name.toLowerCase(), {\n id: row.id,\n label: row.label || unit.creation.name,\n kind: unit.creation.kind,\n })\n }\n return built\n}\n\ntype BuiltRefs = ReturnType<typeof aiSiteBuiltRefs>\n\n/** The layout the scaffold built, when it built one. */\nfunction aiSiteBuiltLayoutId(built: BuiltRefs): string | null {\n for (const entry of built.values()) if (entry.kind === 'layout') return entry.id\n return null\n}\n\n/** A plan reference as the unit's own job reads it: an id the site now has, or nothing. */\nexport function aiSiteResolvedRef(ref: string | null, built: BuiltRefs): string | null {\n if (!ref) return null\n if (!isAiPlanNewRef(ref)) return ref\n return (\n built.get(\n ref\n .slice(ref.indexOf(':') + 1)\n .trim()\n .toLowerCase(),\n )?.id ?? null\n )\n}\n\n/**\n * The site's own words, as every unit's brief carries them.\n *\n * The audience is here rather than left to the brief's prose (AGL-2918). A\n * guided start writes it into the brief itself, but an agency batch's brief\n * is a member's own sentence and may never mention it, and a theme, a layout\n * or a form asked to serve nobody in particular serves nobody in particular.\n *\n * The name is said twice (AGL-3596): as a field, and as the instruction to use\n * it as written. A layout told only \"a dog groomer in Austin\" put a business\n * name of its own in the header and the footer.\n */\nexport function aiSiteBriefLines(\n brief: string,\n inputs: AiSiteJobInputs,\n): string[] {\n const lines = [brief.trim()]\n const site = [\n inputs.businessName ? `name: ${inputs.businessName}` : '',\n `business: ${inputs.businessType}`,\n inputs.audience ? `for: ${inputs.audience}` : '',\n inputs.city ? `city: ${inputs.city}` : '',\n inputs.brand ? `brand: ${inputs.brand}` : '',\n ].filter(Boolean)\n lines.push(`Site — ${site.join('; ')}.`)\n if (inputs.businessName) lines.push(aiSiteNameSentence(inputs.businessName))\n // The business details the person gave (AGL-3979): how to reach it, where\n // and when, and that the pages show the phone and email as written.\n lines.push(...aiSiteDetailsBriefLines(inputs, { city: inputs.city }))\n return lines\n}\n\n/**\n * What a guided start's welcome email is called in Marketing (AGL-3988): the\n * business's welcome email, else \"Welcome email\". The beta.270 Sugar Hollow\n * start's was listed as \"New email\", the email step's name for one nothing\n * named.\n */\nexport function aiSiteWelcomeEmailName(inputs: Readonly<Record<string, unknown>> | null | undefined): string {\n const raw = inputs?.['businessName']\n const business = typeof raw === 'string' ? raw.replace(/\\s+/g, ' ').trim().slice(0, 100) : ''\n return business ? `${business} welcome email` : 'Welcome email'\n}\n\n/**\n * What the welcome email is told (AGL-2918), beyond that it is a welcome\n * email.\n *\n * The scaffold's email unit used to carry one sentence, and a yes/no toggle\n * decided whether it ran — so the draft was a welcome email for a business\n * in general, to nobody in particular, about nothing that had happened. The\n * two answers it is missing are who wrote in and what now becomes of what\n * they wrote, and the second of those is the person's own routing answer, so\n * the email and the form it acknowledges cannot say different things.\n *\n * ⛔ A DRAFT either way. Nothing here sends, schedules or enrolls anybody:\n * the email step writes an unpublished email design and stops.\n */\nexport function aiSiteEmailBriefLines(\n inputs: Readonly<Record<string, unknown>> | null | undefined,\n): string[] {\n const lines = [\n 'Write the welcome email this site sends someone who gets in touch.',\n ]\n const { audience } = aiSiteWords(inputs)\n if (audience) lines.push(`Write it to ${audience}.`)\n const submissions = aiSiteSubmissions(inputs)\n if (submissions === 'lead') {\n lines.push('Their message is a sales lead, so say that somebody will be in touch about it.')\n } else if (submissions === 'inbox') {\n lines.push('Their message has been read, so say it arrived and that a reply is coming.')\n }\n return lines\n}\n\n/**\n * The id a unit's job is named by, and so the id its draft is written under\n * (AGL-3079): the id the plan entry it builds recorded, or for the welcome\n * email the id recorded on this job's step. A unit that writes no draft — a\n * palette change — and a unit whose plan recorded no id are named by this\n * job's id and the unit's slot, the name every draft of such a plan has.\n */\nexport function aiSiteUnitJobId(job: Pick<AiJob, '$id' | 'steps'>, unit: AiSiteUnit): string {\n const recorded =\n unit.creation?.id ??\n unit.screen?.id ??\n unit.item?.id ??\n (unit.kind === 'email' ? aiRecordedJobDraftId(job, 'email') : null)\n return recorded || `${job.$id}-${unit.slot}`\n}\n\n/**\n * The job a unit is built under: this job's org, site, creator and model,\n * the kind that owns the unit, and a plan narrowed to the unit alone.\n *\n * The derived job carries NO steps and NO outputs of the scaffold's: a page\n * job's step reads its own draft and its own plan, and what the other units\n * produced is not its business. Its `$id` is the id the unit's draft is\n * written under (`aiSiteUnitJobId`), which is what a step with no id of its\n * own recorded names its draft by, so a unit re-run after its write finds its\n * own draft rather than writing a second.\n *\n * A creation unit reuses what the plan reuses less what the plan's screens\n * place themselves (AGL-3031): a component a page's section places is the\n * page's to place, and a layout or a card told to place it would be refused\n * for leaving it out.\n */\nexport function aiSiteUnitJob(\n job: AiJob,\n unit: AiSiteUnit,\n built: BuiltRefs,\n): AiJob {\n const plan = job.plan as AiJobPlan\n const labels = { ...(plan.labels ?? {}) }\n for (const entry of built.values()) labels[entry.id] = entry.label\n const inputs = parseAiSiteJobInputs(job.inputs)\n const brief =\n typeof inputs === 'string'\n ? [job.brief]\n : aiSiteBriefLines(job.brief, inputs)\n const unitPlan: AiJobPlan = {\n ...plan,\n labels,\n reuse: [...plan.reuse],\n create: [],\n screens: [],\n }\n if (unit.creation) {\n const placedByScreens = new Set(\n plan.screens.flatMap((screen) => screen.sections.flatMap((section) => section.uses)),\n )\n unitPlan.reuse = plan.reuse.filter((entry) => !placedByScreens.has(entry.id))\n unitPlan.create = [\n {\n ...unit.creation,\n duplicateOf: aiSiteResolvedRef(unit.creation.duplicateOf, built),\n // The dataset a form writes to, once built (AGL-3616); one that\n // failed leaves the form as it always was.\n ...(unit.creation.writesTo ? { writesTo: aiSiteResolvedRef(unit.creation.writesTo, built) } : {}),\n },\n ]\n brief.push(\n `Build the ${unit.creation.kind} “${unit.creation.name}”: ${unit.creation.why}`,\n )\n }\n if (unit.screen) {\n const screen = unit.screen\n // Everything the scaffold has already built is a record the site has, so\n // the page is planned against it the way a page job is planned against\n // what the site always had.\n for (const entry of built.values()) {\n unitPlan.reuse.push({\n kind: entry.kind,\n id: entry.id,\n purpose: `the ${entry.kind} this site’s pages are built on`,\n })\n }\n unitPlan.screens = [\n {\n ...screen,\n // A page the plan named no layout for renders inside the one the\n // scaffold built (AGL-3596); the page step falls back to the site's.\n layout: aiSiteResolvedRef(screen.layout, built) ?? aiSiteBuiltLayoutId(built),\n template: aiSiteResolvedRef(screen.template, built),\n // A scaffold GENERATES every page from its plan (AGL-3596). A page\n // copied from one the site has is not built: a plan that named the\n // starter home page as its home's start produced the starter again,\n // byte for byte, reported as written. A page job keeps rule 15.\n duplicateOf: job.kind === 'site' ? null : aiSiteResolvedRef(screen.duplicateOf, built),\n // A dataset the plan creates and the site has not built yet keeps its\n // name, which the page's draft still binds by (AGL-3475).\n record: screen.record\n ? {\n ...screen.record,\n dataset: aiSiteResolvedRef(screen.record.dataset, built) ?? screen.record.dataset,\n }\n : null,\n sections: screen.sections.map((section) => ({\n ...section,\n uses: section.uses\n .map((ref) => aiSiteResolvedRef(ref, built))\n .filter((ref): ref is string => !!ref),\n })),\n },\n ]\n brief.push(\n `Build the page “${screen.title}” of this site, at ${screen.slug}.`,\n )\n // What the blog's posts or the store's products are, once built (AGL-3676),\n // and what the site's datasets hold (AGL-3616).\n if (job.kind === 'site') {\n brief.push(...aiSiteContentBriefLines(job.outputs ?? []), ...aiSiteDatasetBriefLines(job.outputs ?? []))\n }\n }\n if (unit.kind === 'products') brief.push(aiSiteProductsBriefLine())\n if (unit.kind === 'email') {\n brief.push(...aiSiteEmailBriefLines(job.inputs))\n }\n // The job the member started travels with every unit, so what the unit\n // writes names it (AGL-3596).\n const unitInputs: Record<string, unknown> = { ...job.inputs, originJobId: aiOriginJobId(job) }\n // The look pins what the sites the person likes say of style (AGL-3975):\n // the signals the plan step read, never the sites themselves.\n if (unit.kind === 'theme' && plan.inspiration) unitInputs[AI_SITE_INSPIRATION_SIGNALS_INPUT] = plan.inspiration\n // The welcome email is named for the business in Marketing, never \"New email\" (AGL-3988).\n if (unit.kind === 'email' && typeof unitInputs['name'] !== 'string') unitInputs['name'] = aiSiteWelcomeEmailName(job.inputs)\n // A page is told the pages built before it, whose photos it does not place\n // again (AGL-3660): the maker's portrait in About is never a vase in Work.\n if (unit.screen) {\n const pages = (job.outputs ?? [])\n .filter((output) => output.resource === 'screen' && output.hostId === job.hostId && output.id)\n .map((output) => output.id)\n if (pages.length) unitInputs[AI_STOCK_PHOTO_PAGES_INPUT] = pages\n // Nor a photo the site's datasets' records already show (AGL-3616).\n const records = aiSiteDatasetPlacedPhotos(job.outputs ?? [])\n if (records.length) unitInputs[AI_STOCK_PHOTO_AVOID_INPUT] = records\n // Which a picture the library fails takes before any starter (AGL-3988).\n const recordPhotos = aiSiteDatasetPlacedPhotoDetails(job.outputs ?? [])\n if (recordPhotos.length) unitInputs[AI_STOCK_PHOTO_JOB_PHOTOS_INPUT] = recordPhotos\n // And that the site's late photo pass fills what none of them fits yet (AGL-3988).\n if (job.kind === 'site') unitInputs[AI_STOCK_PHOTO_LATE_PASS_INPUT] = true\n }\n // The layout is built before the pages, so it is told them (AGL-3596): their\n // ids are minted on the plan, and the platform writes the header's links.\n // A page is told them too, so its buttons may go to a page built after it.\n if (job.kind === 'site' && (unit.kind === 'layout' || unit.kind === 'page')) {\n // A guided start links every page the person asked for (AGL-3660), and\n // the blog its first posts are written into, by its path, second after\n // Home (AGL-3676): the live Slow Roads start linked an \"Articles\" page\n // and never the blog.\n // A planned page standing in for that blog — \"Articles\", \"Journal\" — is\n // merged into it (AGL-3676): not linked, not built, and every link to it\n // goes to the blog, under words that name the blog.\n const writesPosts = aiSiteWritesPosts(job)\n const merged = writesPosts ? aiSitePlanWithoutBlogStandIns(plan.screens) : { screens: plan.screens, standIns: [] }\n const planned = aiLayoutSitePagesOfPlan(merged.screens, { guided: true })\n const blogPage = aiSiteBlogNavPage(merged.screens)\n const blog = writesPosts ? [blogPage] : []\n const homes = planned.filter((page) => aiLayoutIsHomeSlug(page.slug))\n const pages = [...homes, ...blog, ...planned.filter((page) => !aiLayoutIsHomeSlug(page.slug))].slice(\n 0,\n AI_LAYOUT_SITE_PAGES_MAX,\n )\n if (pages.length) unitInputs[AI_LAYOUT_SITE_PAGES_INPUT] = pages\n const aliases = merged.standIns\n .filter((screen): screen is typeof screen & { id: string } => typeof screen.id === 'string' && !!screen.id)\n .map((screen) => ({ id: screen.id, label: blogPage.label, slug: blogPage.slug, href: blogPage.href, standsInFor: screen.title }))\n if (aliases.length) unitInputs[AI_LAYOUT_SITE_ALIASES_INPUT] = aliases\n // The store's catalog and the blog, listed by the sections that show them,\n // and the cart in a selling site's header (AGL-3676).\n const listings = aiSiteListings({\n outputs: job.outputs ?? [],\n screens: merged.screens,\n sells: aiSiteSellsProducts(job),\n // A store lists its catalog on its Shop page even when its first\n // products could not be written, or on the Free taste (AGL-3676).\n store: aiSiteKindOfInputs(job.inputs)?.id === 'store',\n // A music site places an empty player for the artist's own tracks (AGL-3716).\n music: aiSiteKindOfInputs(job.inputs)?.id === 'music',\n })\n // The site's datasets, each repeated in the sections that name it (AGL-3616).\n const delivered = new Map([...built.entries()].filter(([, entry]) => entry.kind === 'dataset').map(([name, entry]) => [name, entry.id]))\n listings.push(\n ...aiSiteDatasetListings({ outputs: job.outputs ?? [], datasets: aiSitePlanDatasets(plan), screens: merged.screens, delivered }),\n // The events this start drafted, in the section that names them (AGL-3755).\n ...aiSiteEventListings({ outputs: job.outputs ?? [], items: aiSitePlanEvents(plan), screens: merged.screens }),\n )\n // And the workspace's own datasets the plan reuses, in the sections that name them (AGL-3771).\n listings.push(...aiSiteReusedDatasetListings({ plan, screens: merged.screens, listed: listings }))\n if (listings.length) unitInputs[AI_LAYOUT_LISTINGS_INPUT] = listings\n // A paid store's header links its account beside the cart, and its footer\n // its account and policies (AGL-3676), by path: they are written after.\n if (unit.kind === 'layout' && aiSiteAddsStorePages(job)) {\n unitInputs[AI_SITE_STORE_LINKS_INPUT] = aiStoreFrameLinks(aiStorePagesOfPlan(merged.screens))\n }\n }\n // The store's own pages (AGL-3676): which to write, what their words link,\n // and the layout they render inside.\n if (unit.kind === 'store') unitInputs[AI_SITE_STORE_PAGES_INPUT] = aiSiteStorePagesInputOf(plan, built)\n // A site's pages and its layout are designed in the layout language and\n // compiled (AGL-3660), and a page is told which page places the site's form.\n if (unit.kind === 'layout' || unit.kind === 'page') {\n // The look designed first (AGL-3660): its header arrangement, band rhythm\n // and, where it chose one, how its pages move (AGL-3941).\n const look = (job.outputs ?? []).find((output) => output.resource === 'theme' && output.id === 'look')\n const style = look?.proposal?.['style'] as Record<string, unknown> | undefined\n if (style) {\n unitInputs['siteStyle'] = {\n headerAlign: style['headerAlign'],\n rhythm: style['rhythm'],\n seed: style['seed'],\n ...(typeof style['motion'] === 'string' ? { motion: style['motion'] } : {}),\n }\n }\n unitInputs[AI_LAYOUT_LANGUAGE_INPUT] = true\n const formPage = aiLayoutFormPageOfPlan(plan)\n if (formPage) unitInputs[AI_LAYOUT_FORM_PAGE_INPUT] = formPage\n }\n if (unit.kind === 'posts') {\n // The posts already written (one a pass), the addresses the site's own\n // pages answer at, and the byline the person gave (AGL-3676).\n const posts: AiSitePostsInput = {\n written: (job.outputs ?? [])\n .filter((output) => output.resource === 'entry')\n .map((output) => ({ id: output.id, title: output.label })),\n total: unit.posts ?? AI_SITE_POSTS,\n // A page standing in for the blog is merged into it, so its address is the blog's to take.\n avoidSlugs: aiSitePlanWithoutBlogStandIns(plan.screens)\n .screens.map((screen) => screen.slug.replace(/^\\/+/, '').split('/')[0])\n .filter(Boolean),\n byline: typeof inputs === 'string' ? '' : (inputs.businessName ?? ''),\n }\n unitInputs[AI_SITE_CONTENT_INPUT] = posts\n }\n if (unit.kind === 'products') unitInputs['target'] = 'catalog'\n // The event an event unit drafts (AGL-3755).\n if (unit.kind === 'event' && unit.item) unitInputs[AI_SITE_EVENT_INPUT] = unit.item\n // Where the plan lists a dataset, which its design reads, and the form\n // that writes to it (AGL-3616).\n if (unit.kind === 'dataset' && unit.creation) {\n unitInputs[AI_SITE_DATASET_INPUT] = aiSiteDatasetInputOf(unit.creation, plan.screens, plan.create)\n }\n // A form's dataset this start made, which the form may bind (AGL-3616).\n const writesTo = unit.kind === 'form' ? unitPlan.create[0]?.writesTo : null\n if (writesTo && isAiPlanNewRef(unit.creation?.writesTo)) unitInputs[AI_FORM_DATASET_MADE_INPUT] = writesTo\n return {\n ...job,\n $id: aiSiteUnitJobId(job, unit),\n kind: unit.jobKind,\n steps: [],\n outputs: [],\n plan: unitPlan,\n inputs:\n // A theme change on a site with no theme of its own is a new palette.\n unit.kind === 'theme'\n ? { ...unitInputs, mode: 'create' }\n : // The email step reads the kind off the inputs it is handed, so a\n // job the scaffold composed says which kind it is exactly as a\n // member's own does.\n unit.kind === 'email'\n ? { ...unitInputs, emailType: AI_SITE_EMAIL_TYPE }\n : unitInputs,\n brief: brief.join('\\n').slice(0, AI_JOB_BRIEF_MAX_CHARS),\n }\n}\n\n/** What a store pages unit writes (AGL-3676): the plan's store pages, their words' links, and the layout. */\nexport function aiSiteStorePagesInputOf(plan: Pick<AiJobPlan, 'screens'>, built: BuiltRefs): AiSiteStorePagesInput {\n const pages = aiStorePagesOfPlan(plan.screens)\n const path = (screen: AiBuildPlanScreen | undefined) =>\n screen ? `/${screen.slug.trim().replace(/^\\/+/, '').split('/')[0].toLowerCase()}` : null\n const others = plan.screens.filter((screen) => !screen.record && !aiLayoutIsHomeSlug(screen.slug))\n return {\n pages,\n facts: {\n contactPath: path(others.find((screen) => /\\b(contact|get in touch|visit us)\\b/i.test(`${screen.slug.replace(/-/g, ' ')} ${screen.title}`))),\n shopPath: path(others.find((screen) => aiLayoutIsShopPage(screen))) ?? '/shop',\n shippingPath: pages.find((page) => page.key === 'shipping')?.href ?? '/shipping-returns',\n },\n layoutId: aiSiteBuiltLayoutId(built),\n }\n}\n\n/**\n * Whether this site start adds a store's own pages (AGL-3676): its ledger\n * owes them and has not given up on them. The ledger is written before the\n * layout is built, so the header links the account before the page exists.\n */\nexport function aiSiteAddsStorePages(job: Pick<AiJob, 'items'>): boolean {\n return (job.items ?? []).some((row) => row.slot === 'store' && row.status !== 'skipped' && row.status !== 'failed')\n}\n\n/**\n * Whether this site start writes its first posts (AGL-3676): its ledger owes\n * the posts part and has not given up on it. The ledger is written before the\n * layout is built, so the header knows the blog before it exists.\n */\nexport function aiSiteWritesPosts(job: Pick<AiJob, 'items'>): boolean {\n return (job.items ?? []).some((row) => row.slot === 'posts' && row.status !== 'skipped' && row.status !== 'failed')\n}\n\n/** What the row of a planned page merged into the blog says (AGL-3676). */\nexport const AI_SITE_BLOG_MERGED_NOTE = 'Your blog takes this page’s place: its posts are listed there, and its links go to it.'\n\n/**\n * Whether this site start sells (AGL-3676): its ledger owes the store's first\n * products and has not given up on them, so the layout built before them\n * carries the cart.\n */\nexport function aiSiteSellsProducts(job: Pick<AiJob, 'items'>): boolean {\n return (job.items ?? []).some((row) => row.slot === 'products' && row.status !== 'skipped' && row.status !== 'failed')\n}\n\n/**\n * A scaffold is admitted with inputs that read, for a site of the job's own\n * org, and only where this deployment has loaded the step that builds a page:\n * a scaffold whose pages nothing can build is not a scaffold.\n */\nexport function createAiSiteJobAdmission(\n deps: {\n freeCreditsLeft?: typeof readFreeAiCreditsLeft\n now?: () => Date\n /** Whether `release_ai_site_inspiration` is on for a workspace (AGL-3975). */\n inspirationReleased?: (orgId: string) => Promise<boolean>\n } = {},\n): AiJobAdmission {\n const freeCreditsLeft = deps.freeCreditsLeft ?? readFreeAiCreditsLeft\n const inspirationReleased = deps.inspirationReleased ?? aiSiteInspirationReleased\n const now = deps.now ?? (() => new Date())\n return async (context) => {\n const inputs = parseAiSiteJobInputs(context.inputs)\n if (typeof inputs === 'string') return { status: 400, error: inputs }\n // The workspace's own page band (AGL-3594): one or two pages on the Free\n // taste, four to eight on a paid plan.\n const freeTaste = aiSiteFreeTaste(context.org)\n const pages = aiSitePagesRefusal(inputs.pages, freeTaste)\n if (pages) return { status: 400, error: pages }\n // The sites the person likes (AGL-3975): one on the Free taste, three on\n // a paid plan — asked only while the release flag is on, since with it\n // off they are never read.\n if (inputs.inspiration?.length && (await inspirationReleased(context.orgId))) {\n const inspiration = aiSiteInspirationRefusal(inputs.inspiration, freeTaste)\n if (inspiration) return { status: 400, error: inspiration }\n }\n // A Free start is admitted on its measured p90 (AGL-3722), not its worst\n // case: one that fits what is left of the month starts with no prompt;\n // one that does not is answered with the prompt — what it is likely to\n // cost, what is left, and its choices — until the person chooses to build\n // what fits, which then pauses with Resume where the credits run out.\n // Nothing left at all is refused outright. Only at creation: a resume is\n // the same job carrying on from where it paused.\n if (freeTaste && !context.plan) {\n const credits = await freeCreditsLeft(context.firestore, { orgId: context.orgId, org: context.org, now: now() })\n if (credits && credits.left <= 0) {\n return { status: 429, error: aiFreeCreditsNoneLeftText(credits.resetsOn) }\n }\n // A Free blog's one first post is part of what it costs (AGL-3798).\n const prompt = aiFreeSitePrompt(credits, inputs.pages, { siteKind: aiSiteKindOfInputs(context.inputs)?.id ?? null })\n if (prompt) {\n if (!context.creditsConfirmed) {\n return { status: 409, error: aiCreditsPromptText(prompt, 'site'), code: AI_CREDITS_CONFIRM_CODE, credits: prompt }\n }\n context.onCreditsConfirmed?.(prompt)\n }\n }\n if (context.plan) {\n const shape = aiSitePlanRefusal(context.plan, { freeTaste })\n if (shape) return { status: 400, error: shape }\n }\n if (!context.hostId && !context.siteToCome) {\n return {\n status: 400,\n error: 'Open the site the scaffold is for before starting the job',\n }\n }\n // A site still to come (AGL-3859) is the one \"Create site\" makes for\n // this org once everything else here has said yes.\n if (context.hostId) {\n const owner = await resolveOrgIdForHost(context.hostId)\n if (!owner || owner !== context.orgId)\n return { status: 404, error: 'Unknown site' }\n }\n if (!aiJobStepRunnerFor('page')) {\n return { status: 400, error: AI_SITE_NO_PAGE_STEP_COPY }\n }\n return null\n }\n}\n\nexport const aiSiteJobAdmission: AiJobAdmission = createAiSiteJobAdmission()\n\n/** Whether a scaffold's workspace spends the Free taste (AGL-3594); a missing org reads as paid, as the band has always been. */\nexport function aiSiteFreeTaste(org: object | null | undefined): boolean {\n return Boolean(org) && resolveEffectivePlan(org as never) === 'free'\n}\n\n/**\n * Whether a scaffold drafts its welcome email (AGL-3594): where it was asked\n * for, and never on the Free taste, whose credits its pages need.\n */\nexport function aiSiteWelcomeEmail(inputs: AiSiteJobInputs, freeTaste: boolean): boolean {\n return inputs.welcomeEmail && !freeTaste\n}\n\n/** What one delegated pass came to: the unit's spend as the job records it, and whether the unit is built. */\nexport interface AiJobUnitPass {\n outcome: AiJobStepOutcome\n /** The unit reported what it built and asked for no pass of its own. */\n built: boolean\n}\n\n/**\n * One delegated pass (AGL-2911, AGL-3031): the unit handed to the runner of\n * the kind that owns it, under the job derived for it, and its outcome as the\n * delegating job records it. A delegate proposes a plan for its own job,\n * which does not exist, so no plan is carried back. A unit that stopped for a\n * person, refused or failed is the delegating job's stop; a unit that asked\n * for another pass keeps its turn; and a unit that finished without reporting\n * what it built fails with `emptyCopy`, since another pass would ask the same\n * thing again. The tokens it spent are on the bill either way.\n */\nexport async function aiRunJobUnit(\n context: AiJobStepContext,\n input: {\n unit: AiSiteUnit\n units: readonly AiSiteUnit[]\n runner: AiJobStepRunner\n emptyCopy: string\n },\n): Promise<AiJobUnitPass> {\n const { job } = context\n const outputs = job.outputs ?? []\n const outcome = await input.runner({\n ...context,\n job: aiSiteUnitJob(job, input.unit, aiSiteBuiltRefs(input.units, outputs)),\n })\n const spent: AiJobStepOutcome = {\n outputs: outcome.outputs,\n usage: outcome.usage,\n estCostUsd: outcome.estCostUsd,\n model: outcome.model,\n stopReason: outcome.stopReason,\n ...(outcome.effort ? { effort: outcome.effort } : {}),\n ...(outcome.refused ? { refused: true } : {}),\n ...(outcome.failure ? { failure: outcome.failure } : {}),\n ...(outcome.review ? { review: outcome.review } : {}),\n }\n if (spent.review || spent.refused || spent.failure) return { outcome: spent, built: false }\n if (outcome.continue) return { outcome: { ...spent, continue: true }, built: false }\n if (!outcome.outputs.length) return { outcome: { ...spent, failure: input.emptyCopy }, built: false }\n return { outcome: spent, built: true }\n}\n\nexport interface AiJobSiteStepDeps {\n /** The runner registry; specs hand in a fake for a kind they drive. */\n runnerFor?: typeof aiJobStepRunnerFor\n /** The draft reader a built page is checked through; specs hand in a fake. */\n readNodes?: typeof readAiDraftNodes\n /** The guided start's publish; specs hand in a fake. */\n publish?: typeof aiPublishGuidedSite\n /** The site's own name, which its listing leads with (AGL-3979); specs hand in a fake. */\n siteName?: typeof aiSiteDisplayName\n /** The look's pass (AGL-3660); specs hand in a fake. */\n look?: (context: AiJobStepContext, job: AiJob) => Promise<AiJobStepOutcome>\n /** The first posts' and first products' passes (AGL-3676); specs hand in fakes. */\n posts?: AiJobStepRunner\n products?: AiJobStepRunner\n /** Whether a part may be built for this member, before its first pass. */\n contentRefusal?: typeof aiSiteContentRefusal\n /** The store's own pages' pass and whether they may be added here (AGL-3676); specs hand in fakes. */\n storePages?: AiJobStepRunner\n storePagesRefusal?: typeof aiSiteStorePagesRefusal\n /** A dataset's pass and whether one may be made here (AGL-3616); specs hand in fakes. */\n dataset?: AiJobStepRunner\n datasetRefusal?: typeof aiSiteDatasetRefusal\n /** An event's pass and whether one may be drafted here (AGL-3755); specs hand in fakes. */\n event?: AiJobStepRunner\n eventRefusal?: typeof aiSiteEventRefusal\n /** The posts' publish once the pages are live, and the cache drop after it. */\n publishPosts?: typeof aiPublishSitePosts\n dropCache?: typeof dropPluginSiteCache\n /** The blog's header entry put back once Try again's posts are live (AGL-3747); specs hand in a fake. */\n restoreBlogEntry?: typeof aiRestoreGuidedBlogEntry\n /** The late photo pass before the publish (AGL-3988); specs hand in a fake. */\n latePhotos?: typeof aiSiteLatePhotos\n}\n\n/** The photos state a site job holds once its late photo pass is done: nothing left (AGL-3988). */\nconst AI_SITE_PHOTOS_SETTLED: AiSitePhotos = { pages: [], lists: [] }\n\n/** A page the scaffold reported built that holds none of its plan's sections. */\nexport const AI_SITE_PAGE_NOT_WRITTEN_COPY =\n 'A page of this site was not written from its plan. Try the site brief again.'\n\n/**\n * Whether a page unit's draft holds the sections its plan named, under the\n * ids the page step writes them by (AGL-3596): every one, or for a page in\n * the layout language its first (AGL-3771). A page counts as written only\n * then: a run that reported a page and wrote none of its sections — a copy of\n * a page the site already had, byte for byte — is not a page the job built,\n * and is never reported done.\n */\nexport async function aiSitePageWritten(\n firestore: FirebaseFirestore.Firestore,\n input: {\n hostId: string\n unitJobId: string\n screen: AiBuildPlanScreen\n draftId: string\n /** The page was designed in the layout language (`aiJobUsesLayoutLanguage`). */\n layoutLanguage?: boolean\n },\n readNodes: typeof readAiDraftNodes = readAiDraftNodes,\n): Promise<boolean> {\n if (!input.screen.sections.length) return false\n const stored = await readNodes(firestore, { kind: 'screen', hostId: input.hostId, id: input.draftId })\n if (!stored) return false\n const present = (index: number) => aiPageSectionNodeId(input.unitJobId, index) in stored.nodes\n // A page in the layout language is written whole, its first section\n // heading it (AGL-3660); a later section its last answer could not fill\n // was taken out, and the page says so (AGL-3771). A record template is\n // built section by section, and is written once every section is.\n if (input.layoutLanguage && !input.screen.record) return present(0)\n return input.screen.sections.every((_, index) => present(index))\n}\n\n/**\n * A scaffold's units as a build's (AGL-3616): the same slots, each unit's\n * kind as its operation, and every page built after the layout and the form\n * it renders inside and places. What the build's ledger, degradation and\n * Try again read, so a site is settled item by item exactly as a build is.\n */\nexport function aiSiteLedgerUnits(units: readonly AiSiteUnit[]): AiBuildUnit[] {\n const creations = units.filter((unit) => unit.kind === 'layout' || unit.kind === 'form').map((unit) => unit.slot)\n const datasets = units.filter((unit) => unit.kind === 'dataset' && unit.creation)\n /** The dataset a form writes to (AGL-3616): built before it, and it without the binding if it fails. */\n const writtenTo = (creation: AiBuildPlanCreate | undefined) =>\n datasets\n .filter((unit) => !!creation?.writesTo && creation.writesTo.trim().toLowerCase() === `new:${unit.creation?.name ?? ''}`.trim().toLowerCase())\n .map((unit) => unit.slot)\n /** The datasets a page lists or is the record template of (AGL-3616): built before it, and it without them if they fail. */\n const listed = (screen: AiBuildPlanScreen | undefined) =>\n datasets\n .filter((unit) => {\n const named = `new:${unit.creation?.name ?? ''}`.trim().toLowerCase()\n return (\n screen?.record?.dataset.trim().toLowerCase() === named ||\n (screen?.sections ?? []).some((section) => section.uses.some((ref) => ref.trim().toLowerCase() === named))\n )\n })\n .map((unit) => unit.slot)\n return units.map((unit) => ({\n slot: unit.slot,\n op:\n unit.kind === 'theme' ||\n unit.kind === 'posts' ||\n unit.kind === 'products' ||\n unit.kind === 'dataset' ||\n unit.kind === 'event' ||\n unit.kind === 'store'\n ? unit.kind\n : unit.jobKind,\n label: unit.label,\n ...(unit.creation ? { creation: unit.creation } : {}),\n ...(unit.screen ? { screen: unit.screen } : {}),\n deps: unit.kind === 'page' ? [...creations, ...listed(unit.screen)] : unit.kind === 'form' ? writtenTo(unit.creation) : [],\n }))\n}\n\n/**\n * A scaffold's ledger to start from (AGL-3616): every unit pending, except\n * the units a job already running when the ledger arrived had built, read\n * off its outputs as the scaffold always read them, which stand as built.\n */\nexport function aiSiteInitialLedger(\n units: readonly AiSiteUnit[],\n outputs: readonly AiJobOutput[],\n): AiJobItemLedger[] {\n const pending = new Set(aiSitePendingUnits(units, outputs).map((unit) => unit.slot))\n const byResource = new Map<AiJobOutputResource, string[]>()\n for (const output of outputs) byResource.set(output.resource, [...(byResource.get(output.resource) ?? []), output.id])\n return aiBuildInitialLedger(aiSiteLedgerUnits(units)).map((row, index) => {\n const unit = units[index]\n if (pending.has(unit.slot)) return row\n const id = byResource.get(unit.resource)?.shift()\n return { ...row, status: 'succeeded', outputs: id ? [id] : [] }\n })\n}\n\n/** The units a scaffold owes on this job: what its plan implies that this deployment can build. */\nfunction aiSiteOwedUnits(\n job: AiJob,\n plan: AiJobPlan,\n inputs: AiSiteJobInputs,\n freeTaste: boolean,\n runnerFor: typeof aiJobStepRunnerFor,\n): AiSiteUnit[] {\n // A start whose ledger was written before the store pages existed (AGL-3676)\n // is not owed them: its ledger has no row for them to settle. Nor is a Free\n // blog's ledger written before it was owed its one post (AGL-3798).\n const ledgered = (slot: string) => !job.items?.length || job.items.some((row) => row.slot === slot)\n return aiSiteJobUnits(plan, {\n welcomeEmail: aiSiteWelcomeEmail(inputs, freeTaste),\n content: aiSiteContentPart(job.inputs, freeTaste),\n posts: freeTaste ? AI_SITE_FREE_POSTS : AI_SITE_POSTS,\n }).filter(\n (unit) =>\n (unit.kind === 'store' && ledgered('store')) ||\n unit.kind === 'theme' ||\n (unit.kind === 'posts' && ledgered('posts')) ||\n unit.kind === 'dataset' ||\n unit.kind === 'event' ||\n (unit.kind !== 'store' && runnerFor(unit.jobKind)),\n )\n}\n\nexport function createAiJobSiteStep(\n deps: AiJobSiteStepDeps = {},\n): AiJobStepRunner {\n const runnerFor = deps.runnerFor ?? aiJobStepRunnerFor\n const readNodes = deps.readNodes ?? readAiDraftNodes\n const publish = deps.publish ?? aiPublishGuidedSite\n const siteName = deps.siteName ?? aiSiteDisplayName\n const look = deps.look ?? aiRunSiteLook\n const contentRefusal = deps.contentRefusal ?? aiSiteContentRefusal\n const datasetRefusal = deps.datasetRefusal ?? aiSiteDatasetRefusal\n const eventRefusal = deps.eventRefusal ?? aiSiteEventRefusal\n const storePagesRefusal = deps.storePagesRefusal ?? aiSiteStorePagesRefusal\n const publishPosts = deps.publishPosts ?? aiPublishSitePosts\n const dropCache = deps.dropCache ?? dropPluginSiteCache\n const restoreBlogEntry = deps.restoreBlogEntry ?? aiRestoreGuidedBlogEntry\n const latePhotos = deps.latePhotos ?? aiSiteLatePhotos\n return async (context): Promise<AiJobStepOutcome> => {\n const { job } = context\n // The scaffold asks no model of its own. What it names where it spends\n // nothing is the model its plan ran on, which is the one exchange this\n // job has already had of its own.\n const model = context.modelFor?.('job.plan') ?? aiModelForStep('job.plan')\n const plan = aiConfirmedPlan(job)\n if (!plan)\n return { ...aiUnspentOutcome(model), failure: AI_SITE_NO_PLAN_COPY }\n // The resume door refuses such a plan at confirmation once it can read\n // one; a plan confirmed before a site changed still stops here, unspent.\n const freeTaste = aiSiteFreeTaste(context.org)\n const refusal = aiSitePlanRefusal(plan, { freeTaste })\n if (refusal) return { ...aiUnspentOutcome(model), failure: refusal }\n const inputs = parseAiSiteJobInputs(job.inputs)\n if (typeof inputs === 'string')\n return { ...aiUnspentOutcome(model), failure: inputs }\n\n // A kind this deployment has not loaded is not among the units at all, so\n // a scaffold owes only what something can build.\n const units = aiSiteOwedUnits(job, plan, inputs, freeTaste, runnerFor)\n const ledgerUnits = aiSiteLedgerUnits(units)\n // Settled item by item, like a build (AGL-3616): the ledger, not the\n // outputs, says where the scaffold stands once it has one.\n const starting = !job.items?.length\n const ledger = starting ? aiSiteInitialLedger(units, job.outputs ?? []) : (job.items as AiJobItemLedger[])\n const init = starting ? { items: ledger } : {}\n const rows = new Map(ledger.map((row) => [row.slot, row]))\n const next = aiBuildNextUnit(ledgerUnits, ledger)\n /**\n * The pictures the start left on a starter (AGL-3988): what the job\n * holds, with what this pass's unit reported merged in once it ran.\n */\n let photos: AiSitePhotos | null = job.sitePhotos ?? null\n let photosReported = false\n /**\n * Whether the publish waits for the late photo pass: a record, or a\n * picture of a page it puts live, is still on a starter. A page that\n * failed is not published, so its pictures owe nothing. `pages`: the\n * pages built so far, the one this pass built among them.\n */\n const latePhotosOwed = (pages: readonly AiJobOutput[]) =>\n Boolean(job.hostId) && aiSitePhotosOwed(photos, pages.map((page) => page.id))\n\n /**\n * A guided start's last pass puts what it built on the site (AGL-3596):\n * only its pages that were built. Once it has, Try again's last pass puts\n * only the pages the retry built live (AGL-3730), never the home address\n * or the announce again, merged into the record of the first.\n */\n const finish = async (outcome: AiJobStepOutcome, pages: readonly AiJobOutput[]): Promise<AiJobStepOutcome> => {\n if (!aiJobPublishesSite(job) || !job.hostId) return outcome\n const previous = job.sitePublish ?? null\n const wasLive = Boolean(previous?.published.length)\n const live = new Set((previous?.published ?? []).map((page) => page.id))\n const fresh = pages.filter((page) => !live.has(page.id))\n // Posts Try again wrote for a site already live go live too, pages or not (AGL-3739).\n const postsRetried = wasLive && postsRebuilt()\n if (!fresh.length && !postsRetried) return outcome\n // A canceled start never puts the site live (AGL-3616): its pages stay drafts.\n if (await aiJobCancelAsked(context.firestore, job, context.signal)) return outcome\n if (!fresh.length) {\n if (await finishPosts()) await finishBlogEntry(previous?.published ?? [])\n return outcome\n }\n // A blog the header links by path before its posts exist (AGL-3660):\n // owed and not delivered, its links come out of what is published.\n const postsRow = rows.get('posts')\n const sitePublish = await publish(context.firestore, {\n job,\n outputs: fresh,\n now: context.now,\n ...(postsRow ? { blogUnwritten: !aiBuildItemDelivered(postsRow) || !postsRow.outputs?.length } : {}),\n // The store's pages the header and footer link and the start did not write (AGL-3676).\n ...(rows.get('store') ? { unwrittenHrefs: unwrittenStoreHrefs(pages) } : {}),\n // The pages it planned and did not build, which nothing it publishes links (AGL-3988).\n unbuiltScreenIds: unbuiltPages(),\n // And the order the site lists its pages in, which Pages and the 404 page follow.\n siteOrder: plan.screens.flatMap((screen) => (screen.id ? [screen.id] : [])),\n ...(wasLive ? { retry: true } : {}),\n // The site publishes in the language its brief was written in (AGL-3750).\n ...(plan.language ? { language: plan.language } : {}),\n }).catch((error: unknown) => {\n // The site is built either way; the pages stay drafts and say so.\n console.error('ai site publish threw', { orgId: job.orgId, jobId: job.$id, error })\n return null\n })\n // The blog's posts go live with the first publish that puts a page\n // live, and on a site already live, when Try again wrote them; then\n // the header links the blog again, which the first publish took out.\n if (wasLive ? postsRetried : sitePublish?.published.length) {\n const posted = await finishPosts()\n if (posted && wasLive) await finishBlogEntry([...(previous?.published ?? []), ...(sitePublish?.published ?? [])])\n }\n if (!sitePublish) return outcome\n return { ...outcome, sitePublish: previous ? aiMergeSitePublish(previous, sitePublish) : sitePublish }\n }\n /**\n * Whether the blog's posts part was written by Try again: delivered on a\n * later attempt than its first. Publishing them again on a later retry\n * leaves a post already published as it is.\n */\n const postsRebuilt = (): boolean => {\n const row = rows.get('posts')\n return Boolean(row && row.attempt > 1 && aiBuildItemDelivered(row) && row.outputs?.length)\n }\n /**\n * The blog's posts go live with its pages (AGL-3676), as a person's\n * Publish would put them. Whether any did.\n */\n const finishPosts = async (): Promise<boolean> => {\n const row = rows.get('posts')\n if (!row || !aiBuildItemDelivered(row) || !job.hostId) return false\n const ids = new Set(row.outputs)\n const posts = (job.outputs ?? []).filter((output) => output.resource === 'entry' && ids.has(output.id))\n const published = await publishPosts(context.firestore, { job, outputs: posts, now: context.now })\n if (!published?.paths.length) return false\n await dropCache({\n hostIds: [job.hostId],\n reason: 'guided AI site start published its posts',\n paths: { [job.hostId]: published.paths },\n }).catch((error: unknown) => console.warn('ai site posts: cache not dropped', { jobId: job.$id, error }))\n return true\n }\n /**\n * A blog whose posts Try again put live on a site already live (AGL-3747):\n * the first publish took every link to it out (AGL-3660), so its header\n * entry goes back, after the home page's, where no link opens it yet. The\n * site is live either way; a layout it cannot change is logged.\n */\n const finishBlogEntry = async (published: ReadonlyArray<{ id: string; path: string }>) => {\n const blog = aiSiteBlogNavPage(aiSitePlanWithoutBlogStandIns(plan.screens).screens)\n await restoreBlogEntry(context.firestore, {\n job,\n pageIds: published.map((page) => page.id),\n homeId: published.find((page) => page.path === '/')?.id ?? null,\n blog: { label: blog.label, href: blog.href },\n now: context.now,\n }).catch((error: unknown) => {\n console.error('ai site blog entry not restored', { orgId: job.orgId, jobId: job.$id, error })\n return false\n })\n }\n /**\n * The pages built so far, as the job reported them. A dataset's record\n * template is not among them (AGL-3616): it renders once per record only\n * once the member saves its binding, so it is never published at its own\n * address, where its `{{item.*}}` would show.\n */\n const templates = new Set(units.filter((unit) => unit.kind === 'page' && unit.screen?.record).map((unit) => unit.slot))\n /** The paths of the store's pages the frame links that are not among the pages going live (AGL-3676). */\n const unwrittenStoreHrefs = (pages: readonly AiJobOutput[]) => {\n const live = new Set(pages.map((page) => page.proposal?.['storePage']).filter(Boolean))\n return aiStorePagesOfPlan(plan.screens)\n .filter((page) => !page.planned && !live.has(page.key))\n .map((page) => page.href)\n }\n const builtPages = (extra: readonly AiJobOutput[] = []) => {\n const ids = new Set(\n units\n .filter(\n (unit) =>\n (unit.kind === 'page' || unit.kind === 'store') &&\n !templates.has(unit.slot) &&\n aiBuildItemDelivered(rows.get(unit.slot) ?? { status: 'pending' }),\n )\n .flatMap((unit) => rows.get(unit.slot)?.outputs ?? []),\n )\n return [...(job.outputs ?? []).filter((output) => output.resource === 'screen' && ids.has(output.id)), ...extra]\n }\n /**\n * The pages the start planned and has not built (AGL-3988): a page whose\n * part failed or was refused. The beta.270 Sugar Hollow Galleries page\n * failed its checks, and its home page, header and footer linked it\n * anyway, to a 404.\n */\n const unbuiltPages = () =>\n units.flatMap((unit) =>\n unit.kind === 'page' &&\n !templates.has(unit.slot) &&\n unit.screen?.id &&\n !aiBuildItemDelivered(rows.get(unit.slot) ?? { status: 'pending' })\n ? [unit.screen.id]\n : [],\n )\n\n if (!next) {\n // Every part is built: the pictures left on a starter take the job's\n // own photos before the site goes live (AGL-3988), in a pass of their\n // own, sized to wait out the image hosts' burst.\n if (latePhotosOwed(builtPages()) && photos && !(await aiJobCancelAsked(context.firestore, job, context.signal))) {\n const late = await latePhotos({\n firestore: context.firestore,\n job,\n photos,\n pageIds: builtPages().map((page) => page.id),\n org: (context.org ?? null) as Readonly<Record<string, unknown>> | null,\n now: context.now,\n ...(context.signal ? { signal: context.signal } : {}),\n })\n // A pass whose time ran out while it waited hands what is left to the\n // next, inside the passes the bound gives it: the last one publishes\n // whatever the pictures hold, so a site is never held back by them.\n const latePasses = (photos.latePasses ?? 0) + 1\n if (late.photos && latePasses < AI_SITE_LATE_PHOTOS_PASSES - 1) {\n return { ...aiUnspentOutcome(model), ...init, continue: true, sitePhotos: { ...late.photos, latePasses } }\n }\n return finish({ ...aiUnspentOutcome(model), ...init, sitePhotos: AI_SITE_PHOTOS_SETTLED }, builtPages())\n }\n return finish({ ...aiUnspentOutcome(model), ...init }, builtPages())\n }\n const unit = units.find((one) => one.slot === next.slot) as AiSiteUnit\n // The look is the scaffold's own pass (AGL-3660), not the theme job's proposal.\n const catalog = unit.kind === 'products' ? runnerFor('products') : undefined\n const runner: AiJobStepRunner | undefined =\n unit.kind === 'theme'\n ? (lookContext) => look(lookContext, lookContext.job)\n : unit.kind === 'posts'\n ? (deps.posts ?? runAiSitePostsUnit)\n : unit.kind === 'products'\n ? (deps.products ?? (catalog ? createAiSiteProductsRunner({ catalog }) : undefined))\n : unit.kind === 'dataset'\n ? (deps.dataset ?? runAiSiteDatasetUnit)\n : unit.kind === 'event'\n ? (deps.event ?? runAiSiteEventUnit)\n : unit.kind === 'store'\n ? (deps.storePages ?? runAiSiteStorePagesUnit)\n : runnerFor(unit.jobKind)\n if (!runner) return { ...aiUnspentOutcome(model), ...init }\n const othersOpen = ledgerUnits.some(\n (one) => one.slot !== unit.slot && aiBuildItemOpen(rows.get(one.slot) ?? { status: 'pending' }),\n )\n // The site's own listing rides out beside the first unit's output, once\n // (AGL-2918): it is derived from the answers rather than generated, so it\n // is ready before anything is built and costs the pass nothing.\n const listing = aiSiteSeoOutputOwed(job) ? aiSiteSeoOutputs(job, await siteName(context.firestore, job.hostId)) : []\n const settle = (item: AiJobItemOutcome, spent: AiJobStepOutcome = aiUnspentOutcome(model)): AiJobStepOutcome => ({\n ...spent,\n outputs: [...listing, ...spent.outputs],\n ...init,\n item,\n ...(item.status === 'running' || othersOpen ? { continue: true } : {}),\n ...(photosReported ? { sitePhotos: photos ?? AI_SITE_PHOTOS_SETTLED } : {}),\n })\n /**\n * A unit that failed or was skipped with nothing else open ends the job\n * on this pass (AGL-3676): a guided start whose last unit — its welcome\n * email — failed was never published, because the pass that publishes is\n * the one after. So the end is the publish, whatever the last unit came to.\n */\n const closing = async (outcome: AiJobStepOutcome): Promise<AiJobStepOutcome> =>\n outcome.continue ? outcome : latePhotosOwed(builtPages()) ? { ...outcome, continue: true } : finish(outcome, builtPages())\n\n // A blog's posts and a store's products ask, before their first pass,\n // whether this member may have them here (AGL-3676): a refusal spends\n // nothing, and the row says why, as a build's item does.\n // A planned page standing in for the blog this start writes is merged into\n // it (AGL-3676): not built, its address the blog's, its links the blog's.\n // The plan step asks for a plan without one only once.\n if (unit.kind === 'page' && unit.screen && aiSiteIsBlogStandIn(unit.screen) && aiSiteWritesPosts(job)) {\n return closing(settle({ slot: unit.slot, status: 'skipped', note: AI_SITE_BLOG_MERGED_NOTE }))\n }\n if ((unit.kind === 'posts' || unit.kind === 'products') && rows.get(unit.slot)?.status !== 'running') {\n const refusal = await contentRefusal(unit.kind, { ...context, job }).catch((error: unknown) => {\n console.error('ai site part admission failed', { orgId: job.orgId, jobId: job.$id, slot: unit.slot, error })\n return AI_SITE_UNIT_EMPTY_COPY\n })\n if (refusal) return closing(settle({ slot: unit.slot, status: 'skipped', note: `Not built: ${refusal}` }))\n }\n // A dataset asks the same before its first pass (AGL-3616): the data\n // plugin runs here, and its writer admits this member now.\n if (unit.kind === 'dataset' && rows.get(unit.slot)?.status !== 'running') {\n const refusal = await datasetRefusal({ ...context, job }).catch((error: unknown) => {\n console.error('ai site dataset admission failed', { orgId: job.orgId, jobId: job.$id, slot: unit.slot, error })\n return AI_SITE_UNIT_EMPTY_COPY\n })\n if (refusal) return closing(settle({ slot: unit.slot, status: 'skipped', note: `Not built: ${refusal}` }))\n }\n // An event asks the same (AGL-3755): the events plugin runs here, and its\n // writer admits this member now.\n if (unit.kind === 'event' && rows.get(unit.slot)?.status !== 'running') {\n const refusal = await eventRefusal({ ...context, job }).catch((error: unknown) => {\n console.error('ai site event admission failed', { orgId: job.orgId, jobId: job.$id, slot: unit.slot, error })\n return AI_SITE_UNIT_EMPTY_COPY\n })\n if (refusal) return closing(settle({ slot: unit.slot, status: 'skipped', note: `Not built: ${refusal}` }))\n }\n // The store's own pages ask the same (AGL-3676): a plan with a store, the\n // commerce plugin here, and a member who may edit the site's pages.\n if (unit.kind === 'store' && rows.get(unit.slot)?.status !== 'running') {\n const refusal = await storePagesRefusal({ ...context, job }).catch((error: unknown) => {\n console.error('ai site store pages admission failed', { orgId: job.orgId, jobId: job.$id, error })\n return AI_SITE_UNIT_EMPTY_COPY\n })\n if (refusal) return closing(settle({ slot: unit.slot, status: 'skipped', note: `Not built: ${refusal}` }))\n }\n // A record template whose dataset was not made has nothing to show\n // (AGL-3616): it is not built, and the pages that list the dataset are\n // built without it.\n const templateOf = unit.kind === 'page' && unit.screen ? aiSiteRecordTemplateOf(unit.screen) : null\n if (templateOf) {\n const dataset = units.find((one) => one.kind === 'dataset' && one.creation?.name.trim().toLowerCase() === templateOf.toLowerCase())\n const row = dataset ? rows.get(dataset.slot) : undefined\n if (!row || !aiBuildItemDelivered(row) || !row.outputs.length) {\n return closing(\n settle({\n slot: unit.slot,\n status: 'skipped',\n note: `Not built: the dataset “${templateOf}” it shows a page of each record of could not be created.`,\n ...(dataset ? { degradedBy: [dataset.slot] } : {}),\n }),\n )\n }\n }\n\n // A page whose layout or form failed is built without it, and says so.\n const degradation = aiBuildDegradation(next, { units: ledgerUnits, ledger })\n const degraded = degradation.degradedBy.length > 0\n const note = degradation.notes.length ? degradation.notes.join(' ') : null\n const built = aiBuildBuiltRefs(ledgerUnits, ledger, job.outputs ?? [])\n const derived = aiSiteUnitJob(job, unit, built)\n const handed: AiJob = degradation.briefLines.length\n ? { ...derived, brief: [derived.brief, ...degradation.briefLines].join('\\n').slice(0, AI_JOB_BRIEF_MAX_CHARS) }\n : derived\n\n let outcome: AiJobStepOutcome\n try {\n outcome = await runner({ ...context, job: handed })\n } catch (error) {\n if (aiUnitErrorRetryable(error)) throw error\n console.error('ai site unit threw', { orgId: job.orgId, jobId: job.$id, slot: unit.slot, error })\n return closing(settle({ slot: unit.slot, status: 'failed', failure: { ours: true, reason: 'provider', message: AI_SITE_UNIT_EMPTY_COPY } }))\n }\n // The pictures this unit left on a starter, kept on the job for the late photo pass (AGL-3988).\n if (outcome.sitePhotos) {\n photos = aiSiteMergePhotos(photos, outcome.sitePhotos)\n photosReported = true\n }\n const spent = aiUnitSpend(outcome)\n const stopped = aiUnitFailure(unit.slot, outcome)\n if (stopped) {\n return closing(\n settle(\n stopped.status === 'failed' && stopped.failure && !outcome.failure && !outcome.refused && !outcome.review\n ? { ...stopped, failure: { ...stopped.failure, message: AI_SITE_UNIT_EMPTY_COPY } }\n : stopped,\n spent,\n ),\n )\n }\n // A page counts as built only when its plan's sections are in it\n // (AGL-3596): otherwise the page fails, on our side, and is not reported.\n if (unit.kind === 'page' && unit.screen && job.hostId) {\n const page = outcome.outputs.find((output) => output.resource === 'screen')\n const written =\n page !== undefined &&\n (await aiSitePageWritten(\n context.firestore,\n {\n hostId: job.hostId,\n unitJobId: aiSiteUnitJobId(job, unit),\n screen: unit.screen,\n draftId: page.id,\n layoutLanguage: aiJobUsesLayoutLanguage(handed),\n },\n readNodes,\n ))\n if (!written) {\n return closing(\n settle(\n { slot: unit.slot, status: 'failed', failure: { ours: true, reason: 'step-failure', message: AI_SITE_PAGE_NOT_WRITTEN_COPY } },\n { ...spent, outputs: spent.outputs.filter((output) => output.resource !== 'screen') },\n ),\n )\n }\n }\n const done = settle(\n {\n slot: unit.slot,\n status: degraded ? 'degraded' : 'succeeded',\n outputs: outcome.outputs.map((output) => output.id),\n // A store's products are listed before they are priced (AGL-3676):\n // the row says what is left before the store sells.\n note:\n unit.kind === 'products' && outcome.outputs.length\n ? AI_SITE_PRODUCTS_PRICE_NOTE\n : unit.kind === 'store' && outcome.outputs.length\n ? AI_SITE_STORE_PAGES_NOTE\n : note,\n ...(degraded ? { degradedBy: degradation.degradedBy } : {}),\n },\n spent,\n )\n if (done.continue) return done\n rows.set(unit.slot, { ...(rows.get(unit.slot) as AiJobItemLedger), status: degraded ? 'degraded' : 'succeeded' })\n const live = builtPages(\n (unit.kind === 'page' && !templates.has(unit.slot)) || unit.kind === 'store'\n ? outcome.outputs.filter((output) => output.resource === 'screen')\n : [],\n )\n // The publish waits a pass for the late photo pass (AGL-3988).\n if (latePhotosOwed(live)) return { ...done, continue: true }\n return finish(done, live)\n }\n}\n\nexport const runAiJobSiteStep = createAiJobSiteStep()\n\n/** ASSUMED: what the store pages' pass needs — five draft transactions and their search listings, no model. */\nexport const AI_SITE_STORE_PAGES_MINIMUM_MS = 15_000\n\n/**\n * The least time a scaffold's next pass needs (AGL-3035). The scaffold asks no\n * model itself: each pass hands one unit to the step registered for its kind,\n * under the job derived for it, so it needs what that step registers for that\n * job — a palette change's or a layout's time for those units, a page pass's\n * for a page. A scaffold with nothing left to build, or with no plan it can\n * build, spends nothing, and a page pass's time covers it.\n */\nexport function aiSiteJobRunMinimumMs(job: AiJob): number {\n const plan = aiConfirmedPlan(job)\n const inputs = parseAiSiteJobInputs(job.inputs)\n if (!plan || typeof inputs === 'string') return AI_JOB_PAGE_STEP_MINIMUM_MS\n // The org is not read here, so a blog's or a store's part is counted as a\n // paid plan's; a ledger, once the job has one, says which units it owes.\n const owed = new Set((job.items ?? []).map((row) => row.slot))\n const units = aiSiteJobUnits(plan, {\n welcomeEmail: inputs.welcomeEmail,\n content: aiSiteContentPart(job.inputs, false),\n }).filter(\n (unit) =>\n (unit.kind === 'theme' ||\n unit.kind === 'posts' ||\n unit.kind === 'dataset' ||\n unit.kind === 'event' ||\n unit.kind === 'store' ||\n aiJobStepRunnerFor(unit.jobKind)) &&\n (!owed.size || owed.has(unit.slot)),\n )\n const outputs = job.outputs ?? []\n const ledger = job.items?.length ? job.items : aiSiteInitialLedger(units, outputs)\n const next = aiBuildNextUnit(aiSiteLedgerUnits(units), ledger)\n const unit = next ? units.find((one) => one.slot === next.slot) : undefined\n // Nothing left to build: the late photo pass, where a picture is still on\n // a starter (AGL-3988), and the publish in the same pass.\n if (!unit) return aiSitePhotosOwed(job.sitePhotos) ? Math.max(AI_JOB_PAGE_STEP_MINIMUM_MS, AI_SITE_LATE_PHOTOS_MINIMUM_MS) : AI_JOB_PAGE_STEP_MINIMUM_MS\n if (unit.kind === 'theme') return AI_SITE_LOOK_BUDGET.minimumMs\n if (unit.kind === 'posts') return AI_SITE_POST_BUDGET.minimumMs\n if (unit.kind === 'dataset') return AI_SITE_DATASET_BUDGET.minimumMs\n if (unit.kind === 'event') return AI_SITE_EVENT_MINIMUM_MS\n // The store's pages ask no model: five draft writes (AGL-3676).\n if (unit.kind === 'store') return AI_SITE_STORE_PAGES_MINIMUM_MS\n return aiJobStepRunMinimumMs(aiSiteUnitJob(job, unit, aiBuildBuiltRefs(aiSiteLedgerUnits(units), ledger, outputs)))\n}\n\n/**\n * Registers the site scaffold with the least time a pass needs — every\n * scaffold builds pages, and a page pass needs the least of any unit — and the\n * time its next pass needs, the passes a whole site's plan may take, and the\n * check a site job passes before it is created or resumed.\n */\nexport function registerAiSiteJob(): void {\n registerAiJobStep('site', runAiJobSiteStep, {\n minimumMs: AI_JOB_PAGE_STEP_MINIMUM_MS,\n minimumMsFor: aiSiteJobRunMinimumMs,\n })\n registerAiJobStepPasses('site', AI_SITE_MAX_PASSES)\n registerAiJobAdmission('site', aiSiteJobAdmission)\n}\n"],"names":["aiJobCancelAsked","resolveEffectivePlan","resolveOrgIdForHost","isAiPlanNewRef","aiBuildDegradation","aiBuildInitialLedger","aiBuildItemDelivered","aiBuildItemOpen","aiBuildNextUnit","aiBuildBuiltRefs","aiUnitErrorRetryable","aiUnitFailure","aiUnitSpend","AI_SITE_EMAIL_TYPE","AI_SITE_MAX_SECTIONS","AI_SITE_PAGES","aiFreeCreditsNoneLeftText","aiFreeSitePrompt","aiSiteNameSentence","aiSitePagesRefusal","aiSitePlanRefusal","aiSiteSubmissions","aiSiteWords","parseAiSiteJobInputs","aiSiteBlogNavPage","aiSiteIsBlogStandIn","aiSitePlanWithoutBlogStandIns","readFreeAiCreditsLeft","AI_CREDITS_CONFIRM_CODE","aiCreditsPromptText","AI_SITE_SEO_OUTPUT_ID","aiSiteSeoProposalForInputs","aiSiteDetailsBriefLines","aiModelForStep","registerAiJobAdmission","aiOriginJobId","aiRecordedJobDraftId","readAiDraftNodes","AI_STOCK_PHOTO_AVOID_INPUT","AI_STOCK_PHOTO_JOB_PHOTOS_INPUT","AI_STOCK_PHOTO_LATE_PASS_INPUT","AI_STOCK_PHOTO_PAGES_INPUT","AI_LAYOUT_SITE_ALIASES_INPUT","AI_LAYOUT_SITE_PAGES_INPUT","AI_LAYOUT_SITE_PAGES_MAX","aiLayoutIsHomeSlug","aiLayoutSitePagesOfPlan","aiPageSectionNodeId","AI_LAYOUT_LISTINGS_INPUT","aiLayoutIsShopPage","aiSiteKindOfInputs","AI_LAYOUT_FORM_PAGE_INPUT","AI_LAYOUT_LANGUAGE_INPUT","aiJobUsesLayoutLanguage","aiLayoutFormPageOfPlan","aiJobPublishesSite","aiMergeSitePublish","aiPublishGuidedSite","aiRestoreGuidedBlogEntry","AI_SITE_CONTENT_INPUT","AI_SITE_FREE_POSTS","AI_SITE_POST_BUDGET","AI_SITE_POST_LABEL","AI_SITE_POSTS","AI_SITE_POSTS_LABEL","AI_SITE_PRODUCTS_LABEL","AI_SITE_PRODUCTS_PRICE_NOTE","aiPublishSitePosts","aiSiteContentBriefLines","aiSiteContentPart","aiSiteContentRefusal","aiSiteListings","aiSiteProductsBriefLine","createAiSiteProductsRunner","runAiSitePostsUnit","dropPluginSiteCache","AI_SITE_DATASET_BUDGET","AI_SITE_DATASET_INPUT","AI_SITE_DATASETS_MAX","aiSiteDatasetBriefLines","aiSiteDatasetInputOf","aiSiteDatasetListings","aiSiteDatasetPlacedPhotoDetails","aiSiteDatasetPlacedPhotos","aiSiteDatasetRefusal","aiSitePlanDatasets","aiSiteReusedDatasetListings","aiSiteRecordTemplateOf","runAiSiteDatasetUnit","AI_SITE_EVENT_INPUT","AI_SITE_EVENT_LABEL","AI_SITE_EVENT_MINIMUM_MS","AI_SITE_EVENTS_MAX","aiSiteEventListings","aiSiteEventRefusal","aiSitePlanEvents","runAiSiteEventUnit","AI_SITE_LOOK_BUDGET","aiRunSiteLook","AI_SITE_STORE_PAGES_INPUT","aiSiteStorePagesRefusal","runAiSiteStorePagesUnit","AI_SITE_STORE_LINKS_INPUT","AI_SITE_STORE_PAGES_LABEL","AI_SITE_STORE_PAGES_NOTE","aiStoreFrameLinks","aiStorePagesOfPlan","AI_FORM_DATASET_MADE_INPUT","aiConfirmedPlan","aiUnspentOutcome","AI_JOB_BRIEF_MAX_CHARS","AI_JOB_PAGE_STEP_MINIMUM_MS","aiSiteMergePhotos","aiSitePhotosOwed","AI_SITE_LATE_PHOTOS_MINIMUM_MS","aiSiteLatePhotos","AI_SITE_INSPIRATION_SIGNALS_INPUT","aiSiteInspirationReleased","aiSiteInspirationRefusal","aiJobStepRunMinimumMs","aiJobStepRunnerFor","registerAiJobStep","registerAiJobStepPasses","UNIT_KINDS","theme","jobKind","resource","layout","form","component","page","email","posts","products","dataset","event","store","CREATION_UNIT_KINDS","aiCreationUnit","creation","slot","kind","label","name","CREATION_UNITS","unit","create","AI_SITE_LOOK_LABEL","AI_SITE_NO_PLAN_COPY","AI_SITE_NO_PAGE_STEP_COPY","AI_SITE_UNIT_EMPTY_COPY","AI_SITE_LATE_PHOTOS_PASSES","AI_SITE_MAX_PASSES","max","length","aiSiteJobUnits","plan","options","units","forEach","index","push","find","entry","content","item","screens","screen","title","welcomeEmail","aiSitePendingUnits","outputs","done","Map","output","set","get","filter","left","aiSiteSeoOutputs","job","siteName","aiSiteSeoOutputOwed","proposal","inputs","language","id","hostId","some","aiSiteDisplayName","firestore","collection","doc","trim","aiSiteBuiltRefs","byResource","rows","built","row","shift","toLowerCase","aiSiteBuiltLayoutId","values","aiSiteResolvedRef","ref","slice","indexOf","aiSiteBriefLines","brief","lines","site","businessName","businessType","audience","city","brand","Boolean","join","aiSiteWelcomeEmailName","raw","business","replace","aiSiteEmailBriefLines","submissions","aiSiteUnitJobId","recorded","$id","aiSiteUnitJob","unitPlan","labels","reuse","placedByScreens","Set","flatMap","sections","section","uses","has","duplicateOf","writesTo","why","purpose","template","record","map","slug","unitInputs","originJobId","inspiration","pages","records","recordPhotos","writesPosts","aiSiteWritesPosts","merged","standIns","planned","guided","blogPage","blog","homes","aliases","href","standsInFor","listings","sells","aiSiteSellsProducts","music","delivered","entries","datasets","items","listed","aiSiteAddsStorePages","aiSiteStorePagesInputOf","look","style","headerAlign","rhythm","seed","motion","formPage","written","total","avoidSlugs","split","byline","steps","mode","emailType","path","others","facts","contactPath","test","shopPath","shippingPath","key","layoutId","status","AI_SITE_BLOG_MERGED_NOTE","createAiSiteJobAdmission","deps","freeCreditsLeft","inspirationReleased","now","Date","context","error","freeTaste","aiSiteFreeTaste","org","orgId","credits","resetsOn","prompt","siteKind","creditsConfirmed","code","onCreditsConfirmed","shape","siteToCome","owner","aiSiteJobAdmission","aiSiteWelcomeEmail","aiRunJobUnit","input","outcome","runner","spent","usage","estCostUsd","model","stopReason","effort","refused","failure","review","continue","emptyCopy","AI_SITE_PHOTOS_SETTLED","lists","AI_SITE_PAGE_NOT_WRITTEN_COPY","aiSitePageWritten","readNodes","stored","draftId","present","unitJobId","nodes","layoutLanguage","every","_","aiSiteLedgerUnits","creations","writtenTo","named","op","aiSiteInitialLedger","pending","aiSiteOwedUnits","runnerFor","ledgered","createAiJobSiteStep","publish","contentRefusal","datasetRefusal","eventRefusal","storePagesRefusal","publishPosts","dropCache","restoreBlogEntry","latePhotos","modelFor","refusal","ledgerUnits","starting","ledger","init","next","photos","sitePhotos","photosReported","latePhotosOwed","finish","postsRow","previous","sitePublish","wasLive","published","live","fresh","postsRetried","postsRebuilt","signal","finishPosts","finishBlogEntry","blogUnwritten","unwrittenHrefs","unwrittenStoreHrefs","unbuiltScreenIds","unbuiltPages","siteOrder","retry","catch","console","jobId","posted","attempt","ids","paths","hostIds","reason","warn","pageIds","homeId","templates","builtPages","extra","late","latePasses","one","catalog","undefined","lookContext","storePages","othersOpen","listing","settle","closing","note","templateOf","degradedBy","degradation","degraded","notes","derived","handed","briefLines","ours","message","stopped","runAiJobSiteStep","AI_SITE_STORE_PAGES_MINIMUM_MS","aiSiteJobRunMinimumMs","owed","size","Math","minimumMs","registerAiSiteJob","minimumMsFor"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,gBAAgB,QAAQ,qBAAiB;AAClD,SAASC,oBAAoB,QAAQ,2CAA0C;AAC/E,SAASC,mBAAmB,QAAQ,gDAA+C;AACnF,SACEC,cAAc,QAKT,4BAAwB;AAS/B,SACEC,kBAAkB,EAClBC,oBAAoB,EACpBC,oBAAoB,EACpBC,eAAe,EACfC,eAAe,QAEV,2BAAuB;AAC9B,SAASC,gBAAgB,EAAEC,oBAAoB,EAAEC,aAAa,EAAEC,WAAW,QAAQ,6BAAyB;AAC5G,SACEC,kBAAkB,EAClBC,oBAAoB,EACpBC,aAAa,EACbC,yBAAyB,EACzBC,gBAAgB,EAChBC,kBAAkB,EAClBC,kBAAkB,EAClBC,iBAAiB,EACjBC,iBAAiB,EACjBC,WAAW,EACXC,oBAAoB,EAEpBC,iBAAiB,EACjBC,mBAAmB,EACnBC,6BAA6B,QACxB,0BAAsB;AAC7B,SAASC,qBAAqB,QAAQ,mCAA+B;AACrE,SAASC,uBAAuB,EAAEC,mBAAmB,QAAQ,iCAA6B;AAC1F,SACEC,qBAAqB,EACrBC,0BAA0B,QACrB,gCAA4B;AACnC,SAASC,uBAAuB,QAAQ,8BAA0B;AAClE,SAASC,cAAc,QAAQ,0BAAsB;AACrD,SAASC,sBAAsB,QAA6B,wBAAoB;AAChF,SAASC,aAAa,EAAEC,oBAAoB,QAAQ,wBAAoB;AACxE,SAASC,gBAAgB,QAAQ,qBAAiB;AAClD,SACEC,0BAA0B,EAC1BC,+BAA+B,EAC/BC,8BAA8B,EAC9BC,0BAA0B,QACrB,8BAA0B;AACjC,SACEC,4BAA4B,EAC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AAI,KAAK,SAAS,OAAOlD;IAClC,gEAAgE;IAChE,IAAIsD,KAAKJ,IAAI,KAAK,SAAS,OAAO8S;IAClC,OAAOpU,sBAAsB4G,cAAc/C,KAAKnC,MAAMxI,iBAAiBwV,kBAAkBnM,QAAQ2N,QAAQ9M;AAC3G;AAEA;;;;;CAKC,GACD,OAAO,SAASsR;IACdxU,kBAAkB,QAAQiU,kBAAkB;QAC1CM,WAAWjV;QACXmV,cAAcN;IAChB;IACAlU,wBAAwB,QAAQ8B;IAChCtH,uBAAuB,QAAQiS;AACjC"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/jobs/ai-job-site-step.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 { aiJobCancelAsked } from './ai-job-cancel'\nimport { resolveEffectivePlan } from '@aglyn/aglyn/app-utils/plan-entitlements'\nimport { resolveOrgIdForHost } from '@aglyn/tenant-data-admin/server/organizations'\nimport {\n isAiPlanNewRef,\n type AiBuildItem,\n type AiBuildPlanCreate,\n type AiBuildPlanCreateKind,\n type AiBuildPlanScreen,\n} from '../model/ai-build-plan'\nimport type {\n AiJob,\n AiJobItemLedger,\n AiJobKind,\n AiJobOutput,\n AiJobOutputResource,\n AiJobPlan,\n} from '../model/ai-jobs.types'\nimport {\n aiBuildDegradation,\n aiBuildInitialLedger,\n aiBuildItemDelivered,\n aiBuildItemOpen,\n aiBuildNextUnit,\n type AiBuildUnit,\n} from '../model/ai-build-job'\nimport { aiBuildBuiltRefs, aiUnitErrorRetryable, aiUnitFailure, aiUnitSpend } from './ai-build-unit-outcome'\nimport {\n AI_SITE_EMAIL_TYPE,\n AI_SITE_MAX_SECTIONS,\n AI_SITE_PAGES,\n aiFreeCreditsNoneLeftText,\n aiFreeSitePrompt,\n aiSiteNameSentence,\n aiSitePagesRefusal,\n aiSitePlanRefusal,\n aiSiteSubmissions,\n aiSiteWords,\n parseAiSiteJobInputs,\n type AiSiteJobInputs,\n aiSiteBlogNavPage,\n aiSiteIsBlogStandIn,\n aiSitePlanWithoutBlogStandIns,\n} from '../model/ai-site-job'\nimport { readFreeAiCreditsLeft } from '../usage/free-ai-credits-left'\nimport { AI_CREDITS_CONFIRM_CODE, aiCreditsPromptText } from '../model/ai-credit-estimate'\nimport {\n AI_SITE_SEO_OUTPUT_ID,\n aiSiteSeoProposalForInputs,\n} from '../model/ai-site-start-seo'\nimport { aiSiteDetailsBriefLines } from '../model/ai-site-details'\nimport { aiModelForStep } from '../providers/routing'\nimport { registerAiJobAdmission, type AiJobAdmission } from './ai-job-admission'\nimport { aiOriginJobId, aiRecordedJobDraftId } from './ai-job-draft-ids'\nimport { readAiDraftNodes } from './ai-job-drafts'\nimport {\n AI_STOCK_PHOTO_AVOID_INPUT,\n AI_STOCK_PHOTO_JOB_PHOTOS_INPUT,\n AI_STOCK_PHOTO_LATE_PASS_INPUT,\n AI_STOCK_PHOTO_PAGES_INPUT,\n} from './ai-layout-stock-photos'\nimport {\n AI_LAYOUT_SITE_ALIASES_INPUT,\n AI_LAYOUT_SITE_PAGES_INPUT,\n AI_LAYOUT_SITE_PAGES_MAX,\n aiLayoutIsHomeSlug,\n aiLayoutSitePagesOfPlan,\n} from './ai-job-layout-site-pages'\nimport { aiPageSectionNodeId } from './ai-job-page-sections'\nimport { AI_LAYOUT_LISTINGS_INPUT, aiLayoutIsShopPage } from '../layout-language/ai-layout-listings'\nimport { aiSiteKindOfInputs } from '../model/ai-site-kinds'\nimport { AI_LAYOUT_FORM_PAGE_INPUT, AI_LAYOUT_LANGUAGE_INPUT, aiJobUsesLayoutLanguage, aiLayoutFormPageOfPlan } from './ai-job-page-language'\nimport { aiJobPublishesSite, aiMergeSitePublish, aiPublishGuidedSite, aiRestoreGuidedBlogEntry } from './ai-site-publish'\nimport {\n AI_SITE_CONTENT_INPUT,\n AI_SITE_FREE_POSTS,\n AI_SITE_POST_BUDGET,\n AI_SITE_POST_LABEL,\n AI_SITE_POSTS,\n AI_SITE_POSTS_LABEL,\n AI_SITE_PRODUCTS_LABEL,\n AI_SITE_PRODUCTS_PRICE_NOTE,\n AI_SITE_SAMPLE_PRODUCTS_INPUT,\n AI_SITE_SAMPLE_PRODUCTS_NOTE,\n aiPublishSitePosts,\n aiSiteContentBriefLines,\n aiSiteContentPart,\n aiSiteContentRefusal,\n aiSiteListings,\n aiSiteProductsBriefLine,\n aiSiteSampleProductKinds,\n createAiSiteProductsRunner,\n runAiSitePostsUnit,\n type AiSitePostsInput,\n} from './ai-job-site-content'\nimport { dropPluginSiteCache } from '@aglyn/aglyn/plugin-manager/plugin-site-cache'\nimport {\n AI_SITE_DATASET_BUDGET,\n AI_SITE_DATASET_INPUT,\n AI_SITE_DATASETS_MAX,\n aiSiteDatasetBriefLines,\n aiSiteDatasetInputOf,\n aiSiteDatasetListings,\n aiSiteDatasetPlacedPhotoDetails,\n aiSiteDatasetPlacedPhotos,\n aiSiteDatasetRefusal,\n aiSitePlanDatasets,\n aiSiteReusedDatasetListings,\n aiSiteRecordTemplateOf,\n runAiSiteDatasetUnit,\n} from './ai-job-site-datasets'\nimport {\n AI_SITE_EVENT_INPUT,\n AI_SITE_EVENT_LABEL,\n AI_SITE_EVENT_MINIMUM_MS,\n AI_SITE_EVENTS_MAX,\n aiSiteEventListings,\n aiSiteEventRefusal,\n aiSitePlanEvents,\n runAiSiteEventUnit,\n} from './ai-job-site-events'\nimport { AI_SITE_LOOK_BUDGET, aiRunSiteLook } from './ai-job-site-look'\nimport {\n AI_SITE_STORE_PAGES_INPUT,\n aiSiteStorePagesRefusal,\n runAiSiteStorePagesUnit,\n type AiSiteStorePagesInput,\n} from './ai-job-site-store-pages'\nimport {\n AI_SITE_STORE_LINKS_INPUT,\n AI_SITE_STORE_PAGES_LABEL,\n AI_SITE_STORE_PAGES_NOTE,\n aiStoreFrameLinks,\n aiStorePagesOfPlan,\n} from '../model/ai-site-store-pages'\nimport { AI_FORM_DATASET_MADE_INPUT } from './ai-job-form-dataset'\nimport { aiConfirmedPlan, aiUnspentOutcome } from './ai-job-generation'\nimport {\n AI_JOB_BRIEF_MAX_CHARS,\n type AiJobItemOutcome,\n type AiJobStepContext,\n type AiJobStepOutcome,\n type AiJobStepRunner,\n} from './ai-job-text-step'\nimport { AI_JOB_PAGE_STEP_MINIMUM_MS } from './ai-job-page-budget'\nimport { aiSiteMergePhotos, aiSitePhotosOwed, type AiSitePhotos } from '../model/ai-site-photos'\nimport { AI_SITE_LATE_PHOTOS_MINIMUM_MS, aiSiteLatePhotos } from './ai-site-late-photos'\nimport { AI_SITE_INSPIRATION_SIGNALS_INPUT, aiSiteInspirationReleased } from './ai-site-inspiration'\nimport { aiSiteInspirationRefusal } from '../model/ai-site-inspiration'\nimport {\n aiJobStepRunMinimumMs,\n aiJobStepRunnerFor,\n registerAiJobStep,\n registerAiJobStepPasses,\n} from './ai-jobs'\n\n/**\n * The site scaffold (AGL-2911): the generation step of a `site` job, run once\n * a member confirmed the plan their brief produced.\n *\n * ── It builds nothing itself ─────────────────────────────────────────────\n *\n * A scaffold is a whole site: a palette suggestion, the layout its pages\n * render inside, the contact form they place, four to eight pages with their\n * search listings, and a welcome email. Every one of those is already a job\n * kind with a step of its own, so this step generates nothing and asks no\n * model anything. It works through the confirmed plan one UNIT at a time and\n * hands each unit to the runner registered for the kind that owns it — the\n * theme step for the palette, the page step for a page — under a job of that\n * kind derived from this one.\n *\n * That is why the scaffold cannot drift from the thing it scaffolds: a page\n * it builds is a page job's page, held to the same doctrine, written by the\n * same draft writer, left unpublished by the same rule. A kind whose step\n * this deployment has not loaded is simply not among the units, so nothing\n * here knows which issues have landed.\n *\n * ── One unit a pass ──────────────────────────────────────────────────────\n *\n * The step runs ONE delegated pass and asks the machine to continue, so every\n * pass is one reservation, one provider exchange and one recorded spend, and\n * the org's monthly ceiling binds a scaffold exactly as it binds a chat turn.\n * Credits running out mid-scaffold is therefore the machine's own park: the\n * job waits as `needs_input` with the meter's words, and the beat resumes it\n * where it stopped once the workspace's standing has changed. A pass needs the\n * time its unit's own step needs (`aiSiteJobRunMinimumMs`), so the beat starts\n * a palette change only with a palette change's time left.\n *\n * Where it stopped is read from the job's OUTPUTS rather than kept anywhere:\n * each unit reports exactly one output when it completes, so the units\n * already represented there are the ones already built. A pass interrupted\n * between its work and its record repeats a unit that then finds its own\n * draft and reports it, which is what every step's draft id already gives.\n *\n * ── Never published ──────────────────────────────────────────────────────\n *\n * Nothing here publishes, routes or sends: each delegated step writes the\n * unpublished draft it already wrote for a job of its own kind, and the\n * palette and navigation travel as proposals a member applies.\n *\n * ── The page job builds its creations the same way (AGL-3031) ────────────\n *\n * A page job whose plan creates a layout, forms or components builds them\n * before its page through this same machinery: the units a creation implies\n * (`aiCreationUnit`), where the job stands read from its outputs\n * (`aiSitePendingUnits`), one delegated pass a unit (`aiRunJobUnit`), and the\n * `new:<name>` references resolved to what was built (`aiSiteBuiltRefs`,\n * `aiSiteUnitJob`). There is one loop, and it is the machine's.\n */\n\n/**\n * What a scaffold's units are, in the order it builds them; a component is a\n * page job's. The site's datasets (AGL-3616) are built after the layout and\n * before the form, which may write its submissions to one; a blog's first\n * posts and a store's first products (AGL-3676) after the form; all of them\n * before the pages, which are told what they are. A paid store's account,\n * cart and policy pages (`store`, AGL-3676) come after its planned pages,\n * which keep the first claim on the site's pages allowance.\n */\nexport type AiSiteUnitKind =\n | 'theme'\n | 'layout'\n | 'form'\n | 'component'\n | 'dataset'\n | 'event'\n | 'posts'\n | 'products'\n | 'page'\n | 'store'\n | 'email'\n\nexport interface AiSiteUnit {\n kind: AiSiteUnitKind\n /** The job kind whose registered runner builds it. */\n jobKind: AiJobKind\n /** The resource the unit reports when it completes. */\n resource: AiJobOutputResource\n /** Stable within the job: what the unit's derived job and draft are addressed by. */\n slot: string\n /** The plan screen a page unit builds. */\n screen?: AiBuildPlanScreen\n /** The creation a theme, layout or form unit builds. */\n creation?: AiBuildPlanCreate\n /** The event an event unit drafts (AGL-3755). */\n item?: AiBuildItem\n /** How many first posts a posts unit writes: `AI_SITE_POSTS`, or a Free blog's `AI_SITE_FREE_POSTS`. */\n posts?: number\n /** What the unit is, for the derived job's brief. */\n label: string\n}\n\n/** The job kind and output resource each unit is built through. */\nconst UNIT_KINDS: Record<\n AiSiteUnitKind,\n { jobKind: AiJobKind; resource: AiJobOutputResource }\n> = {\n theme: { jobKind: 'theme', resource: 'theme' },\n layout: { jobKind: 'layout', resource: 'layout' },\n form: { jobKind: 'form', resource: 'form' },\n component: { jobKind: 'component', resource: 'reusableComponent' },\n page: { jobKind: 'page', resource: 'screen' },\n email: { jobKind: 'email', resource: 'emailScreen' },\n // The scaffold's own runner writes them (`ai-job-site-content.ts`); the\n // posts' job kind is the one whose derived job a post's brief is, and the\n // products' the step that proposes the catalog they are written from.\n posts: { jobKind: 'text', resource: 'entry' },\n products: { jobKind: 'products', resource: 'product' },\n // The scaffold's own runner designs it (`ai-job-site-datasets.ts`), and the\n // data plugin's writer keeps it: a draft of another plugin's (AGL-3616).\n dataset: { jobKind: 'text', resource: 'draft' },\n // An event-led start's first events (AGL-3755): the events-calendar\n // plugin's writer keeps each, run by the scaffold's own pass.\n event: { jobKind: 'text', resource: 'draft' },\n // The scaffold's own runner writes them, by code (`ai-job-site-store-pages.ts`).\n store: { jobKind: 'text', resource: 'screen' },\n}\n\n/** The unit kind a creation is built as, where a unit builds it. */\nconst CREATION_UNIT_KINDS: Partial<Record<AiBuildPlanCreateKind, AiSiteUnitKind>> = {\n 'theme-change': 'theme',\n layout: 'layout',\n form: 'form',\n component: 'component',\n}\n\n/**\n * The unit one creation is built as, under the slot its derived job and draft\n * are addressed by; `null` for a creation no unit builds.\n */\nexport function aiCreationUnit(creation: AiBuildPlanCreate, slot: string): AiSiteUnit | null {\n const kind = CREATION_UNIT_KINDS[creation.kind]\n if (!kind) return null\n return { kind, ...UNIT_KINDS[kind], slot, creation, label: creation.name }\n}\n\n/** The creation kinds a unit is built from, by unit kind. */\nconst CREATION_UNITS: Array<{\n unit: AiSiteUnitKind\n create: AiBuildPlanCreateKind\n}> = [\n { unit: 'theme', create: 'theme-change' },\n { unit: 'layout', create: 'layout' },\n { unit: 'form', create: 'form' },\n]\n\n/** What the look's unit is called on the ledger. */\nexport const AI_SITE_LOOK_LABEL = 'Your look'\n\nexport const AI_SITE_NO_PLAN_COPY =\n 'This site job has no confirmed plan to build.'\n\n/** What a scaffold answers where the step that builds a page is not loaded. */\nexport const AI_SITE_NO_PAGE_STEP_COPY =\n 'Building a whole site is not available yet.'\n\n/** A unit that finished without reporting what it built; the scaffold cannot go on. */\nexport const AI_SITE_UNIT_EMPTY_COPY =\n 'Part of this site could not be built. Try the site brief again.'\n\n/**\n * The passes the late photo pass may add (AGL-3988): the one that hands the\n * publish to it, its own, and one more where a beat's time ran out on it.\n * That last one publishes whatever the pictures hold (`latePasses`).\n */\nexport const AI_SITE_LATE_PHOTOS_PASSES = 3\n\n/**\n * The most passes a scaffold's step may take: the largest plan it admits —\n * eight pages of eight sections, its three creations, a blog's first posts\n * (one a pass, the largest part), a welcome email and the late photo pass\n * (AGL-3988) — with nothing to spare, so a runner that never finishes is\n * still bounded while a real site is not.\n */\nexport const AI_SITE_MAX_PASSES =\n AI_SITE_PAGES.max * (AI_SITE_MAX_SECTIONS + 1) +\n CREATION_UNITS.length +\n AI_SITE_DATASETS_MAX +\n AI_SITE_EVENTS_MAX +\n AI_SITE_POSTS +\n 2 +\n AI_SITE_LATE_PHOTOS_PASSES\n\n/**\n * The units a plan implies, in build order: the palette first, because a\n * member reads it while the pages are still building; then the layout every\n * page renders inside, the site's datasets, and the form they place —\n * because a page binds the layout and the form by id, and a form binds the\n * dataset it writes to (AGL-3616), so each needs what it binds to exist;\n * then the pages; then the welcome email, which is about the site rather\n * than part of it.\n */\nexport function aiSiteJobUnits(\n plan: Pick<AiJobPlan, 'create' | 'screens'> & Partial<Pick<AiJobPlan, 'items'>>,\n options: { welcomeEmail?: boolean; content?: 'posts' | 'products' | null; posts?: number } = {},\n): AiSiteUnit[] {\n // The site's look is designed first, on every scaffold (AGL-3660): the\n // header, the footer and every page render in it from their first draft.\n // A theme change the plan names is that same unit, never a second one.\n const units: AiSiteUnit[] = [\n { kind: 'theme', ...UNIT_KINDS.theme, slot: 't', label: AI_SITE_LOOK_LABEL },\n ]\n for (const { unit, create } of CREATION_UNITS) {\n if (unit === 'theme') continue\n // The site's datasets (AGL-3616), before anything that lists them and\n // before the form, which may write its submissions to one of them.\n if (unit === 'form') {\n aiSitePlanDatasets(plan).forEach((creation, index) => {\n units.push({ kind: 'dataset', ...UNIT_KINDS.dataset, slot: `d${index}`, creation, label: creation.name })\n })\n }\n const creation = plan.create.find((entry) => entry.kind === create)\n if (!creation) continue\n units.push({\n kind: unit,\n ...UNIT_KINDS[unit],\n slot: unit[0],\n creation,\n label: creation.name,\n })\n }\n // A blog's first posts — one on the Free taste — and a paid store's first products (AGL-3676).\n if (options.content === 'posts') {\n const posts = options.posts ?? AI_SITE_POSTS\n units.push({ kind: 'posts', ...UNIT_KINDS.posts, slot: 'posts', posts, label: posts === 1 ? AI_SITE_POST_LABEL : AI_SITE_POSTS_LABEL })\n } else if (options.content === 'products') {\n units.push({ kind: 'products', ...UNIT_KINDS.products, slot: 'products', label: AI_SITE_PRODUCTS_LABEL })\n }\n // An event-led start's first events (AGL-3755), before the pages that list them.\n aiSitePlanEvents(plan).forEach((item, index) => {\n units.push({ kind: 'event', ...UNIT_KINDS.event, slot: `v${index}`, item, label: item.name || AI_SITE_EVENT_LABEL })\n })\n plan.screens.forEach((screen, index) => {\n units.push({\n kind: 'page',\n ...UNIT_KINDS.page,\n slot: `p${index}`,\n screen,\n label: screen.title,\n })\n })\n // A paid store's own pages (AGL-3676): outside the plan's pages, after them.\n if (options.content === 'products') {\n units.push({ kind: 'store', ...UNIT_KINDS.store, slot: 'store', label: AI_SITE_STORE_PAGES_LABEL })\n }\n if (options.welcomeEmail) {\n units.push({\n kind: 'email',\n ...UNIT_KINDS.email,\n slot: 'e',\n label: 'Welcome email',\n })\n }\n return units\n}\n\n/**\n * The units a scaffold still owes after the outputs recorded so far. Each\n * unit reports one output of its own resource when it completes, so the\n * outputs already recorded are consumed against the units in build order.\n */\nexport function aiSitePendingUnits(\n units: readonly AiSiteUnit[],\n outputs: readonly Pick<AiJobOutput, 'resource'>[],\n): AiSiteUnit[] {\n const done = new Map<AiJobOutputResource, number>()\n for (const output of outputs) {\n done.set(output.resource, (done.get(output.resource) ?? 0) + 1)\n }\n return units.filter((unit) => {\n const left = done.get(unit.resource) ?? 0\n if (left <= 0) return true\n done.set(unit.resource, left - 1)\n return false\n })\n}\n\n/**\n * The site's own search listing as the scaffold reports it (AGL-2918), or\n * nothing when the job already reported one or its inputs describe no site.\n *\n * It costs nothing and asks no model: the values are arithmetic on the\n * answers (`aiSiteSeoProposal`), so they ride out on the first pass that\n * builds anything rather than waiting for a pass of their own. Its resource\n * is `seo`, which no unit reports, so it cannot be mistaken for a unit's\n * output by `aiSitePendingUnits` and cannot move where the scaffold thinks\n * it is.\n */\nexport function aiSiteSeoOutputs(job: AiJob, siteName?: string | null): AiJobOutput[] {\n if (!aiSiteSeoOutputOwed(job)) return []\n // The site's own name leads it where the start named no business (AGL-3979):\n // the same listing the publish writes over the seeded default.\n const proposal = aiSiteSeoProposalForInputs(job.inputs, job.plan?.language, siteName)\n if (!proposal) return []\n return [\n {\n resource: 'seo',\n id: AI_SITE_SEO_OUTPUT_ID,\n hostId: job.hostId ?? null,\n label: 'The site’s search title and description',\n proposal: proposal as unknown as Record<string, unknown>,\n },\n ]\n}\n\n/** Whether the scaffold has yet to report the site's listing. */\nexport function aiSiteSeoOutputOwed(job: Pick<AiJob, 'outputs'>): boolean {\n return !(job.outputs ?? []).some((output) => output.resource === 'seo' && output.id === AI_SITE_SEO_OUTPUT_ID)\n}\n\n/** The site's own name, which its listing leads with (AGL-3979); `null` when it cannot be read. */\nexport async function aiSiteDisplayName(\n firestore: FirebaseFirestore.Firestore,\n hostId: string | null | undefined,\n): Promise<string | null> {\n if (!hostId) return null\n try {\n const name = (await firestore.collection('hosts').doc(hostId).get()).get('displayName')\n return typeof name === 'string' && name.trim() ? name.trim() : null\n } catch {\n // A listing without the name is the listing every start made before.\n return null\n }\n}\n\n/** A record an earlier unit created, as a later one references it. */\nexport interface AiSiteBuiltRef {\n id: string\n label: string\n /** Only what becomes a record a page can name; a palette change is not one. */\n kind: 'layout' | 'form' | 'component' | 'dataset'\n}\n\n/**\n * What the scaffold has already created, as the plan's `new:<name>`\n * references resolve to: the id of the record each completed creation wrote.\n * A page unit is told about the layout and the form by id, exactly as a page\n * job is told about records the site already had.\n */\nexport function aiSiteBuiltRefs(\n units: readonly AiSiteUnit[],\n outputs: readonly Pick<AiJobOutput, 'resource' | 'id' | 'label'>[],\n): Map<string, AiSiteBuiltRef> {\n const byResource = new Map<\n AiJobOutputResource,\n Array<Pick<AiJobOutput, 'id' | 'label'>>\n >()\n for (const output of outputs) {\n const rows = byResource.get(output.resource) ?? []\n rows.push(output)\n byResource.set(output.resource, rows)\n }\n const built = new Map<string, AiSiteBuiltRef>()\n for (const unit of units) {\n const rows = byResource.get(unit.resource)\n const row = rows?.shift()\n if (!row || !unit.creation) continue\n // A theme change is a proposal with no record to reference; a layout, a\n // form, a component and a dataset (AGL-3616) become ids a page can name.\n if (\n unit.creation.kind !== 'layout' &&\n unit.creation.kind !== 'form' &&\n unit.creation.kind !== 'component' &&\n unit.creation.kind !== 'dataset'\n ) {\n continue\n }\n built.set(unit.creation.name.toLowerCase(), {\n id: row.id,\n label: row.label || unit.creation.name,\n kind: unit.creation.kind,\n })\n }\n return built\n}\n\ntype BuiltRefs = ReturnType<typeof aiSiteBuiltRefs>\n\n/** The layout the scaffold built, when it built one. */\nfunction aiSiteBuiltLayoutId(built: BuiltRefs): string | null {\n for (const entry of built.values()) if (entry.kind === 'layout') return entry.id\n return null\n}\n\n/** A plan reference as the unit's own job reads it: an id the site now has, or nothing. */\nexport function aiSiteResolvedRef(ref: string | null, built: BuiltRefs): string | null {\n if (!ref) return null\n if (!isAiPlanNewRef(ref)) return ref\n return (\n built.get(\n ref\n .slice(ref.indexOf(':') + 1)\n .trim()\n .toLowerCase(),\n )?.id ?? null\n )\n}\n\n/**\n * The site's own words, as every unit's brief carries them.\n *\n * The audience is here rather than left to the brief's prose (AGL-2918). A\n * guided start writes it into the brief itself, but an agency batch's brief\n * is a member's own sentence and may never mention it, and a theme, a layout\n * or a form asked to serve nobody in particular serves nobody in particular.\n *\n * The name is said twice (AGL-3596): as a field, and as the instruction to use\n * it as written. A layout told only \"a dog groomer in Austin\" put a business\n * name of its own in the header and the footer.\n */\nexport function aiSiteBriefLines(\n brief: string,\n inputs: AiSiteJobInputs,\n): string[] {\n const lines = [brief.trim()]\n const site = [\n inputs.businessName ? `name: ${inputs.businessName}` : '',\n `business: ${inputs.businessType}`,\n inputs.audience ? `for: ${inputs.audience}` : '',\n inputs.city ? `city: ${inputs.city}` : '',\n inputs.brand ? `brand: ${inputs.brand}` : '',\n ].filter(Boolean)\n lines.push(`Site — ${site.join('; ')}.`)\n if (inputs.businessName) lines.push(aiSiteNameSentence(inputs.businessName))\n // The business details the person gave (AGL-3979): how to reach it, where\n // and when, and that the pages show the phone and email as written.\n lines.push(...aiSiteDetailsBriefLines(inputs, { city: inputs.city }))\n return lines\n}\n\n/**\n * What a guided start's welcome email is called in Marketing (AGL-3988): the\n * business's welcome email, else \"Welcome email\". The beta.270 Sugar Hollow\n * start's was listed as \"New email\", the email step's name for one nothing\n * named.\n */\nexport function aiSiteWelcomeEmailName(inputs: Readonly<Record<string, unknown>> | null | undefined): string {\n const raw = inputs?.['businessName']\n const business = typeof raw === 'string' ? raw.replace(/\\s+/g, ' ').trim().slice(0, 100) : ''\n return business ? `${business} welcome email` : 'Welcome email'\n}\n\n/**\n * What the welcome email is told (AGL-2918), beyond that it is a welcome\n * email.\n *\n * The scaffold's email unit used to carry one sentence, and a yes/no toggle\n * decided whether it ran — so the draft was a welcome email for a business\n * in general, to nobody in particular, about nothing that had happened. The\n * two answers it is missing are who wrote in and what now becomes of what\n * they wrote, and the second of those is the person's own routing answer, so\n * the email and the form it acknowledges cannot say different things.\n *\n * ⛔ A DRAFT either way. Nothing here sends, schedules or enrolls anybody:\n * the email step writes an unpublished email design and stops.\n */\nexport function aiSiteEmailBriefLines(\n inputs: Readonly<Record<string, unknown>> | null | undefined,\n): string[] {\n const lines = [\n 'Write the welcome email this site sends someone who gets in touch.',\n ]\n const { audience } = aiSiteWords(inputs)\n if (audience) lines.push(`Write it to ${audience}.`)\n const submissions = aiSiteSubmissions(inputs)\n if (submissions === 'lead') {\n lines.push('Their message is a sales lead, so say that somebody will be in touch about it.')\n } else if (submissions === 'inbox') {\n lines.push('Their message has been read, so say it arrived and that a reply is coming.')\n }\n return lines\n}\n\n/**\n * The id a unit's job is named by, and so the id its draft is written under\n * (AGL-3079): the id the plan entry it builds recorded, or for the welcome\n * email the id recorded on this job's step. A unit that writes no draft — a\n * palette change — and a unit whose plan recorded no id are named by this\n * job's id and the unit's slot, the name every draft of such a plan has.\n */\nexport function aiSiteUnitJobId(job: Pick<AiJob, '$id' | 'steps'>, unit: AiSiteUnit): string {\n const recorded =\n unit.creation?.id ??\n unit.screen?.id ??\n unit.item?.id ??\n (unit.kind === 'email' ? aiRecordedJobDraftId(job, 'email') : null)\n return recorded || `${job.$id}-${unit.slot}`\n}\n\n/**\n * The job a unit is built under: this job's org, site, creator and model,\n * the kind that owns the unit, and a plan narrowed to the unit alone.\n *\n * The derived job carries NO steps and NO outputs of the scaffold's: a page\n * job's step reads its own draft and its own plan, and what the other units\n * produced is not its business. Its `$id` is the id the unit's draft is\n * written under (`aiSiteUnitJobId`), which is what a step with no id of its\n * own recorded names its draft by, so a unit re-run after its write finds its\n * own draft rather than writing a second.\n *\n * A creation unit reuses what the plan reuses less what the plan's screens\n * place themselves (AGL-3031): a component a page's section places is the\n * page's to place, and a layout or a card told to place it would be refused\n * for leaving it out.\n */\nexport function aiSiteUnitJob(\n job: AiJob,\n unit: AiSiteUnit,\n built: BuiltRefs,\n): AiJob {\n const plan = job.plan as AiJobPlan\n const labels = { ...(plan.labels ?? {}) }\n for (const entry of built.values()) labels[entry.id] = entry.label\n const inputs = parseAiSiteJobInputs(job.inputs)\n const brief =\n typeof inputs === 'string'\n ? [job.brief]\n : aiSiteBriefLines(job.brief, inputs)\n const unitPlan: AiJobPlan = {\n ...plan,\n labels,\n reuse: [...plan.reuse],\n create: [],\n screens: [],\n }\n if (unit.creation) {\n const placedByScreens = new Set(\n plan.screens.flatMap((screen) => screen.sections.flatMap((section) => section.uses)),\n )\n unitPlan.reuse = plan.reuse.filter((entry) => !placedByScreens.has(entry.id))\n unitPlan.create = [\n {\n ...unit.creation,\n duplicateOf: aiSiteResolvedRef(unit.creation.duplicateOf, built),\n // The dataset a form writes to, once built (AGL-3616); one that\n // failed leaves the form as it always was.\n ...(unit.creation.writesTo ? { writesTo: aiSiteResolvedRef(unit.creation.writesTo, built) } : {}),\n },\n ]\n brief.push(\n `Build the ${unit.creation.kind} “${unit.creation.name}”: ${unit.creation.why}`,\n )\n }\n if (unit.screen) {\n const screen = unit.screen\n // Everything the scaffold has already built is a record the site has, so\n // the page is planned against it the way a page job is planned against\n // what the site always had.\n for (const entry of built.values()) {\n unitPlan.reuse.push({\n kind: entry.kind,\n id: entry.id,\n purpose: `the ${entry.kind} this site’s pages are built on`,\n })\n }\n unitPlan.screens = [\n {\n ...screen,\n // A page the plan named no layout for renders inside the one the\n // scaffold built (AGL-3596); the page step falls back to the site's.\n layout: aiSiteResolvedRef(screen.layout, built) ?? aiSiteBuiltLayoutId(built),\n template: aiSiteResolvedRef(screen.template, built),\n // A scaffold GENERATES every page from its plan (AGL-3596). A page\n // copied from one the site has is not built: a plan that named the\n // starter home page as its home's start produced the starter again,\n // byte for byte, reported as written. A page job keeps rule 15.\n duplicateOf: job.kind === 'site' ? null : aiSiteResolvedRef(screen.duplicateOf, built),\n // A dataset the plan creates and the site has not built yet keeps its\n // name, which the page's draft still binds by (AGL-3475).\n record: screen.record\n ? {\n ...screen.record,\n dataset: aiSiteResolvedRef(screen.record.dataset, built) ?? screen.record.dataset,\n }\n : null,\n sections: screen.sections.map((section) => ({\n ...section,\n uses: section.uses\n .map((ref) => aiSiteResolvedRef(ref, built))\n .filter((ref): ref is string => !!ref),\n })),\n },\n ]\n brief.push(\n `Build the page “${screen.title}” of this site, at ${screen.slug}.`,\n )\n // What the blog's posts or the store's products are, once built (AGL-3676),\n // and what the site's datasets hold (AGL-3616).\n if (job.kind === 'site') {\n brief.push(...aiSiteContentBriefLines(job.outputs ?? []), ...aiSiteDatasetBriefLines(job.outputs ?? []))\n }\n }\n // A store whose brief names only kinds of product starts with samples of them (AGL-4065).\n const sampleKinds = unit.kind === 'products' ? aiSiteSampleProductKinds(job.inputs) : null\n if (unit.kind === 'products') brief.push(aiSiteProductsBriefLine(undefined, sampleKinds))\n if (unit.kind === 'email') {\n brief.push(...aiSiteEmailBriefLines(job.inputs))\n }\n // The job the member started travels with every unit, so what the unit\n // writes names it (AGL-3596).\n const unitInputs: Record<string, unknown> = { ...job.inputs, originJobId: aiOriginJobId(job) }\n // The look pins what the sites the person likes say of style (AGL-3975):\n // the signals the plan step read, never the sites themselves.\n if (unit.kind === 'theme' && plan.inspiration) unitInputs[AI_SITE_INSPIRATION_SIGNALS_INPUT] = plan.inspiration\n // The welcome email is named for the business in Marketing, never \"New email\" (AGL-3988).\n if (unit.kind === 'email' && typeof unitInputs['name'] !== 'string') unitInputs['name'] = aiSiteWelcomeEmailName(job.inputs)\n // A page is told the pages built before it, whose photos it does not place\n // again (AGL-3660): the maker's portrait in About is never a vase in Work.\n if (unit.screen) {\n const pages = (job.outputs ?? [])\n .filter((output) => output.resource === 'screen' && output.hostId === job.hostId && output.id)\n .map((output) => output.id)\n if (pages.length) unitInputs[AI_STOCK_PHOTO_PAGES_INPUT] = pages\n // Nor a photo the site's datasets' records already show (AGL-3616).\n const records = aiSiteDatasetPlacedPhotos(job.outputs ?? [])\n if (records.length) unitInputs[AI_STOCK_PHOTO_AVOID_INPUT] = records\n // Which a picture the library fails takes before any starter (AGL-3988).\n const recordPhotos = aiSiteDatasetPlacedPhotoDetails(job.outputs ?? [])\n if (recordPhotos.length) unitInputs[AI_STOCK_PHOTO_JOB_PHOTOS_INPUT] = recordPhotos\n // And that the site's late photo pass fills what none of them fits yet (AGL-3988).\n if (job.kind === 'site') unitInputs[AI_STOCK_PHOTO_LATE_PASS_INPUT] = true\n }\n // The layout is built before the pages, so it is told them (AGL-3596): their\n // ids are minted on the plan, and the platform writes the header's links.\n // A page is told them too, so its buttons may go to a page built after it.\n if (job.kind === 'site' && (unit.kind === 'layout' || unit.kind === 'page')) {\n // A guided start links every page the person asked for (AGL-3660), and\n // the blog its first posts are written into, by its path, second after\n // Home (AGL-3676): the live Slow Roads start linked an \"Articles\" page\n // and never the blog.\n // A planned page standing in for that blog — \"Articles\", \"Journal\" — is\n // merged into it (AGL-3676): not linked, not built, and every link to it\n // goes to the blog, under words that name the blog.\n const writesPosts = aiSiteWritesPosts(job)\n const merged = writesPosts ? aiSitePlanWithoutBlogStandIns(plan.screens) : { screens: plan.screens, standIns: [] }\n const planned = aiLayoutSitePagesOfPlan(merged.screens, { guided: true })\n const blogPage = aiSiteBlogNavPage(merged.screens)\n const blog = writesPosts ? [blogPage] : []\n const homes = planned.filter((page) => aiLayoutIsHomeSlug(page.slug))\n const pages = [...homes, ...blog, ...planned.filter((page) => !aiLayoutIsHomeSlug(page.slug))].slice(\n 0,\n AI_LAYOUT_SITE_PAGES_MAX,\n )\n if (pages.length) unitInputs[AI_LAYOUT_SITE_PAGES_INPUT] = pages\n const aliases = merged.standIns\n .filter((screen): screen is typeof screen & { id: string } => typeof screen.id === 'string' && !!screen.id)\n .map((screen) => ({ id: screen.id, label: blogPage.label, slug: blogPage.slug, href: blogPage.href, standsInFor: screen.title }))\n if (aliases.length) unitInputs[AI_LAYOUT_SITE_ALIASES_INPUT] = aliases\n // The store's catalog and the blog, listed by the sections that show them,\n // and the cart in a selling site's header (AGL-3676).\n const listings = aiSiteListings({\n outputs: job.outputs ?? [],\n screens: merged.screens,\n sells: aiSiteSellsProducts(job),\n // A store lists its catalog on its Shop page even when its first\n // products could not be written, or on the Free taste (AGL-3676).\n store: aiSiteKindOfInputs(job.inputs)?.id === 'store',\n // A music site places an empty player for the artist's own tracks (AGL-3716).\n music: aiSiteKindOfInputs(job.inputs)?.id === 'music',\n })\n // The site's datasets, each repeated in the sections that name it (AGL-3616).\n const delivered = new Map([...built.entries()].filter(([, entry]) => entry.kind === 'dataset').map(([name, entry]) => [name, entry.id]))\n listings.push(\n ...aiSiteDatasetListings({ outputs: job.outputs ?? [], datasets: aiSitePlanDatasets(plan), screens: merged.screens, delivered }),\n // The events this start drafted, in the section that names them (AGL-3755).\n ...aiSiteEventListings({ outputs: job.outputs ?? [], items: aiSitePlanEvents(plan), screens: merged.screens }),\n )\n // And the workspace's own datasets the plan reuses, in the sections that name them (AGL-3771).\n listings.push(...aiSiteReusedDatasetListings({ plan, screens: merged.screens, listed: listings }))\n if (listings.length) unitInputs[AI_LAYOUT_LISTINGS_INPUT] = listings\n // A paid store's header links its account beside the cart, and its footer\n // its account and policies (AGL-3676), by path: they are written after.\n if (unit.kind === 'layout' && aiSiteAddsStorePages(job)) {\n unitInputs[AI_SITE_STORE_LINKS_INPUT] = aiStoreFrameLinks(aiStorePagesOfPlan(merged.screens))\n }\n }\n // The store's own pages (AGL-3676): which to write, what their words link,\n // and the layout they render inside.\n if (unit.kind === 'store') unitInputs[AI_SITE_STORE_PAGES_INPUT] = aiSiteStorePagesInputOf(plan, built)\n // A site's pages and its layout are designed in the layout language and\n // compiled (AGL-3660), and a page is told which page places the site's form.\n if (unit.kind === 'layout' || unit.kind === 'page') {\n // The look designed first (AGL-3660): its header arrangement, band rhythm\n // and, where it chose one, how its pages move (AGL-3941).\n const look = (job.outputs ?? []).find((output) => output.resource === 'theme' && output.id === 'look')\n const style = look?.proposal?.['style'] as Record<string, unknown> | undefined\n if (style) {\n unitInputs['siteStyle'] = {\n headerAlign: style['headerAlign'],\n rhythm: style['rhythm'],\n seed: style['seed'],\n ...(typeof style['motion'] === 'string' ? { motion: style['motion'] } : {}),\n }\n }\n unitInputs[AI_LAYOUT_LANGUAGE_INPUT] = true\n const formPage = aiLayoutFormPageOfPlan(plan)\n if (formPage) unitInputs[AI_LAYOUT_FORM_PAGE_INPUT] = formPage\n }\n if (unit.kind === 'posts') {\n // The posts already written (one a pass), the addresses the site's own\n // pages answer at, and the byline the person gave (AGL-3676).\n const posts: AiSitePostsInput = {\n written: (job.outputs ?? [])\n .filter((output) => output.resource === 'entry')\n .map((output) => ({ id: output.id, title: output.label })),\n total: unit.posts ?? AI_SITE_POSTS,\n // A page standing in for the blog is merged into it, so its address is the blog's to take.\n avoidSlugs: aiSitePlanWithoutBlogStandIns(plan.screens)\n .screens.map((screen) => screen.slug.replace(/^\\/+/, '').split('/')[0])\n .filter(Boolean),\n byline: typeof inputs === 'string' ? '' : (inputs.businessName ?? ''),\n }\n unitInputs[AI_SITE_CONTENT_INPUT] = posts\n }\n if (unit.kind === 'products') unitInputs['target'] = 'catalog'\n if (sampleKinds) unitInputs[AI_SITE_SAMPLE_PRODUCTS_INPUT] = sampleKinds\n // The event an event unit drafts (AGL-3755).\n if (unit.kind === 'event' && unit.item) unitInputs[AI_SITE_EVENT_INPUT] = unit.item\n // Where the plan lists a dataset, which its design reads, and the form\n // that writes to it (AGL-3616).\n if (unit.kind === 'dataset' && unit.creation) {\n unitInputs[AI_SITE_DATASET_INPUT] = aiSiteDatasetInputOf(unit.creation, plan.screens, plan.create)\n }\n // A form's dataset this start made, which the form may bind (AGL-3616).\n const writesTo = unit.kind === 'form' ? unitPlan.create[0]?.writesTo : null\n if (writesTo && isAiPlanNewRef(unit.creation?.writesTo)) unitInputs[AI_FORM_DATASET_MADE_INPUT] = writesTo\n return {\n ...job,\n $id: aiSiteUnitJobId(job, unit),\n kind: unit.jobKind,\n steps: [],\n outputs: [],\n plan: unitPlan,\n inputs:\n // A theme change on a site with no theme of its own is a new palette.\n unit.kind === 'theme'\n ? { ...unitInputs, mode: 'create' }\n : // The email step reads the kind off the inputs it is handed, so a\n // job the scaffold composed says which kind it is exactly as a\n // member's own does.\n unit.kind === 'email'\n ? { ...unitInputs, emailType: AI_SITE_EMAIL_TYPE }\n : unitInputs,\n brief: brief.join('\\n').slice(0, AI_JOB_BRIEF_MAX_CHARS),\n }\n}\n\n/** What a store pages unit writes (AGL-3676): the plan's store pages, their words' links, and the layout. */\nexport function aiSiteStorePagesInputOf(plan: Pick<AiJobPlan, 'screens'>, built: BuiltRefs): AiSiteStorePagesInput {\n const pages = aiStorePagesOfPlan(plan.screens)\n const path = (screen: AiBuildPlanScreen | undefined) =>\n screen ? `/${screen.slug.trim().replace(/^\\/+/, '').split('/')[0].toLowerCase()}` : null\n const others = plan.screens.filter((screen) => !screen.record && !aiLayoutIsHomeSlug(screen.slug))\n return {\n pages,\n facts: {\n contactPath: path(others.find((screen) => /\\b(contact|get in touch|visit us)\\b/i.test(`${screen.slug.replace(/-/g, ' ')} ${screen.title}`))),\n shopPath: path(others.find((screen) => aiLayoutIsShopPage(screen))) ?? '/shop',\n shippingPath: pages.find((page) => page.key === 'shipping')?.href ?? '/shipping-returns',\n },\n layoutId: aiSiteBuiltLayoutId(built),\n }\n}\n\n/**\n * Whether this site start adds a store's own pages (AGL-3676): its ledger\n * owes them and has not given up on them. The ledger is written before the\n * layout is built, so the header links the account before the page exists.\n */\nexport function aiSiteAddsStorePages(job: Pick<AiJob, 'items'>): boolean {\n return (job.items ?? []).some((row) => row.slot === 'store' && row.status !== 'skipped' && row.status !== 'failed')\n}\n\n/**\n * Whether this site start writes its first posts (AGL-3676): its ledger owes\n * the posts part and has not given up on it. The ledger is written before the\n * layout is built, so the header knows the blog before it exists.\n */\nexport function aiSiteWritesPosts(job: Pick<AiJob, 'items'>): boolean {\n return (job.items ?? []).some((row) => row.slot === 'posts' && row.status !== 'skipped' && row.status !== 'failed')\n}\n\n/** What the row of a planned page merged into the blog says (AGL-3676). */\nexport const AI_SITE_BLOG_MERGED_NOTE = 'Your blog takes this page’s place: its posts are listed there, and its links go to it.'\n\n/**\n * Whether this site start sells (AGL-3676): its ledger owes the store's first\n * products and has not given up on them, so the layout built before them\n * carries the cart.\n */\nexport function aiSiteSellsProducts(job: Pick<AiJob, 'items'>): boolean {\n return (job.items ?? []).some((row) => row.slot === 'products' && row.status !== 'skipped' && row.status !== 'failed')\n}\n\n/**\n * A scaffold is admitted with inputs that read, for a site of the job's own\n * org, and only where this deployment has loaded the step that builds a page:\n * a scaffold whose pages nothing can build is not a scaffold.\n */\nexport function createAiSiteJobAdmission(\n deps: {\n freeCreditsLeft?: typeof readFreeAiCreditsLeft\n now?: () => Date\n /** Whether `release_ai_site_inspiration` is on for a workspace (AGL-3975). */\n inspirationReleased?: (orgId: string) => Promise<boolean>\n } = {},\n): AiJobAdmission {\n const freeCreditsLeft = deps.freeCreditsLeft ?? readFreeAiCreditsLeft\n const inspirationReleased = deps.inspirationReleased ?? aiSiteInspirationReleased\n const now = deps.now ?? (() => new Date())\n return async (context) => {\n const inputs = parseAiSiteJobInputs(context.inputs)\n if (typeof inputs === 'string') return { status: 400, error: inputs }\n // The workspace's own page band (AGL-3594): one or two pages on the Free\n // taste, four to eight on a paid plan.\n const freeTaste = aiSiteFreeTaste(context.org)\n const pages = aiSitePagesRefusal(inputs.pages, freeTaste)\n if (pages) return { status: 400, error: pages }\n // The sites the person likes (AGL-3975): one on the Free taste, three on\n // a paid plan — asked only while the release flag is on, since with it\n // off they are never read.\n if (inputs.inspiration?.length && (await inspirationReleased(context.orgId))) {\n const inspiration = aiSiteInspirationRefusal(inputs.inspiration, freeTaste)\n if (inspiration) return { status: 400, error: inspiration }\n }\n // A Free start is admitted on its measured p90 (AGL-3722), not its worst\n // case: one that fits what is left of the month starts with no prompt;\n // one that does not is answered with the prompt — what it is likely to\n // cost, what is left, and its choices — until the person chooses to build\n // what fits, which then pauses with Resume where the credits run out.\n // Nothing left at all is refused outright. Only at creation: a resume is\n // the same job carrying on from where it paused.\n if (freeTaste && !context.plan) {\n const credits = await freeCreditsLeft(context.firestore, { orgId: context.orgId, org: context.org, now: now() })\n if (credits && credits.left <= 0) {\n return { status: 429, error: aiFreeCreditsNoneLeftText(credits.resetsOn) }\n }\n // A Free blog's one first post is part of what it costs (AGL-3798).\n const prompt = aiFreeSitePrompt(credits, inputs.pages, { siteKind: aiSiteKindOfInputs(context.inputs)?.id ?? null })\n if (prompt) {\n if (!context.creditsConfirmed) {\n return { status: 409, error: aiCreditsPromptText(prompt, 'site'), code: AI_CREDITS_CONFIRM_CODE, credits: prompt }\n }\n context.onCreditsConfirmed?.(prompt)\n }\n }\n if (context.plan) {\n const shape = aiSitePlanRefusal(context.plan, { freeTaste })\n if (shape) return { status: 400, error: shape }\n }\n if (!context.hostId && !context.siteToCome) {\n return {\n status: 400,\n error: 'Open the site the scaffold is for before starting the job',\n }\n }\n // A site still to come (AGL-3859) is the one \"Create site\" makes for\n // this org once everything else here has said yes.\n if (context.hostId) {\n const owner = await resolveOrgIdForHost(context.hostId)\n if (!owner || owner !== context.orgId)\n return { status: 404, error: 'Unknown site' }\n }\n if (!aiJobStepRunnerFor('page')) {\n return { status: 400, error: AI_SITE_NO_PAGE_STEP_COPY }\n }\n return null\n }\n}\n\nexport const aiSiteJobAdmission: AiJobAdmission = createAiSiteJobAdmission()\n\n/** Whether a scaffold's workspace spends the Free taste (AGL-3594); a missing org reads as paid, as the band has always been. */\nexport function aiSiteFreeTaste(org: object | null | undefined): boolean {\n return Boolean(org) && resolveEffectivePlan(org as never) === 'free'\n}\n\n/**\n * Whether a scaffold drafts its welcome email (AGL-3594): where it was asked\n * for, and never on the Free taste, whose credits its pages need.\n */\nexport function aiSiteWelcomeEmail(inputs: AiSiteJobInputs, freeTaste: boolean): boolean {\n return inputs.welcomeEmail && !freeTaste\n}\n\n/** What one delegated pass came to: the unit's spend as the job records it, and whether the unit is built. */\nexport interface AiJobUnitPass {\n outcome: AiJobStepOutcome\n /** The unit reported what it built and asked for no pass of its own. */\n built: boolean\n}\n\n/**\n * One delegated pass (AGL-2911, AGL-3031): the unit handed to the runner of\n * the kind that owns it, under the job derived for it, and its outcome as the\n * delegating job records it. A delegate proposes a plan for its own job,\n * which does not exist, so no plan is carried back. A unit that stopped for a\n * person, refused or failed is the delegating job's stop; a unit that asked\n * for another pass keeps its turn; and a unit that finished without reporting\n * what it built fails with `emptyCopy`, since another pass would ask the same\n * thing again. The tokens it spent are on the bill either way.\n */\nexport async function aiRunJobUnit(\n context: AiJobStepContext,\n input: {\n unit: AiSiteUnit\n units: readonly AiSiteUnit[]\n runner: AiJobStepRunner\n emptyCopy: string\n },\n): Promise<AiJobUnitPass> {\n const { job } = context\n const outputs = job.outputs ?? []\n const outcome = await input.runner({\n ...context,\n job: aiSiteUnitJob(job, input.unit, aiSiteBuiltRefs(input.units, outputs)),\n })\n const spent: AiJobStepOutcome = {\n outputs: outcome.outputs,\n usage: outcome.usage,\n estCostUsd: outcome.estCostUsd,\n model: outcome.model,\n stopReason: outcome.stopReason,\n ...(outcome.effort ? { effort: outcome.effort } : {}),\n ...(outcome.refused ? { refused: true } : {}),\n ...(outcome.failure ? { failure: outcome.failure } : {}),\n ...(outcome.review ? { review: outcome.review } : {}),\n }\n if (spent.review || spent.refused || spent.failure) return { outcome: spent, built: false }\n if (outcome.continue) return { outcome: { ...spent, continue: true }, built: false }\n if (!outcome.outputs.length) return { outcome: { ...spent, failure: input.emptyCopy }, built: false }\n return { outcome: spent, built: true }\n}\n\nexport interface AiJobSiteStepDeps {\n /** The runner registry; specs hand in a fake for a kind they drive. */\n runnerFor?: typeof aiJobStepRunnerFor\n /** The draft reader a built page is checked through; specs hand in a fake. */\n readNodes?: typeof readAiDraftNodes\n /** The guided start's publish; specs hand in a fake. */\n publish?: typeof aiPublishGuidedSite\n /** The site's own name, which its listing leads with (AGL-3979); specs hand in a fake. */\n siteName?: typeof aiSiteDisplayName\n /** The look's pass (AGL-3660); specs hand in a fake. */\n look?: (context: AiJobStepContext, job: AiJob) => Promise<AiJobStepOutcome>\n /** The first posts' and first products' passes (AGL-3676); specs hand in fakes. */\n posts?: AiJobStepRunner\n products?: AiJobStepRunner\n /** Whether a part may be built for this member, before its first pass. */\n contentRefusal?: typeof aiSiteContentRefusal\n /** The store's own pages' pass and whether they may be added here (AGL-3676); specs hand in fakes. */\n storePages?: AiJobStepRunner\n storePagesRefusal?: typeof aiSiteStorePagesRefusal\n /** A dataset's pass and whether one may be made here (AGL-3616); specs hand in fakes. */\n dataset?: AiJobStepRunner\n datasetRefusal?: typeof aiSiteDatasetRefusal\n /** An event's pass and whether one may be drafted here (AGL-3755); specs hand in fakes. */\n event?: AiJobStepRunner\n eventRefusal?: typeof aiSiteEventRefusal\n /** The posts' publish once the pages are live, and the cache drop after it. */\n publishPosts?: typeof aiPublishSitePosts\n dropCache?: typeof dropPluginSiteCache\n /** The blog's header entry put back once Try again's posts are live (AGL-3747); specs hand in a fake. */\n restoreBlogEntry?: typeof aiRestoreGuidedBlogEntry\n /** The late photo pass before the publish (AGL-3988); specs hand in a fake. */\n latePhotos?: typeof aiSiteLatePhotos\n}\n\n/** The photos state a site job holds once its late photo pass is done: nothing left (AGL-3988). */\nconst AI_SITE_PHOTOS_SETTLED: AiSitePhotos = { pages: [], lists: [] }\n\n/** A page the scaffold reported built that holds none of its plan's sections. */\nexport const AI_SITE_PAGE_NOT_WRITTEN_COPY =\n 'A page of this site was not written from its plan. Try the site brief again.'\n\n/**\n * Whether a page unit's draft holds the sections its plan named, under the\n * ids the page step writes them by (AGL-3596): every one, or for a page in\n * the layout language its first (AGL-3771). A page counts as written only\n * then: a run that reported a page and wrote none of its sections — a copy of\n * a page the site already had, byte for byte — is not a page the job built,\n * and is never reported done.\n */\nexport async function aiSitePageWritten(\n firestore: FirebaseFirestore.Firestore,\n input: {\n hostId: string\n unitJobId: string\n screen: AiBuildPlanScreen\n draftId: string\n /** The page was designed in the layout language (`aiJobUsesLayoutLanguage`). */\n layoutLanguage?: boolean\n },\n readNodes: typeof readAiDraftNodes = readAiDraftNodes,\n): Promise<boolean> {\n if (!input.screen.sections.length) return false\n const stored = await readNodes(firestore, { kind: 'screen', hostId: input.hostId, id: input.draftId })\n if (!stored) return false\n const present = (index: number) => aiPageSectionNodeId(input.unitJobId, index) in stored.nodes\n // A page in the layout language is written whole, its first section\n // heading it (AGL-3660); a later section its last answer could not fill\n // was taken out, and the page says so (AGL-3771). A record template is\n // built section by section, and is written once every section is.\n if (input.layoutLanguage && !input.screen.record) return present(0)\n return input.screen.sections.every((_, index) => present(index))\n}\n\n/**\n * A scaffold's units as a build's (AGL-3616): the same slots, each unit's\n * kind as its operation, and every page built after the layout and the form\n * it renders inside and places. What the build's ledger, degradation and\n * Try again read, so a site is settled item by item exactly as a build is.\n */\nexport function aiSiteLedgerUnits(units: readonly AiSiteUnit[]): AiBuildUnit[] {\n const creations = units.filter((unit) => unit.kind === 'layout' || unit.kind === 'form').map((unit) => unit.slot)\n const datasets = units.filter((unit) => unit.kind === 'dataset' && unit.creation)\n /** The dataset a form writes to (AGL-3616): built before it, and it without the binding if it fails. */\n const writtenTo = (creation: AiBuildPlanCreate | undefined) =>\n datasets\n .filter((unit) => !!creation?.writesTo && creation.writesTo.trim().toLowerCase() === `new:${unit.creation?.name ?? ''}`.trim().toLowerCase())\n .map((unit) => unit.slot)\n /** The datasets a page lists or is the record template of (AGL-3616): built before it, and it without them if they fail. */\n const listed = (screen: AiBuildPlanScreen | undefined) =>\n datasets\n .filter((unit) => {\n const named = `new:${unit.creation?.name ?? ''}`.trim().toLowerCase()\n return (\n screen?.record?.dataset.trim().toLowerCase() === named ||\n (screen?.sections ?? []).some((section) => section.uses.some((ref) => ref.trim().toLowerCase() === named))\n )\n })\n .map((unit) => unit.slot)\n return units.map((unit) => ({\n slot: unit.slot,\n op:\n unit.kind === 'theme' ||\n unit.kind === 'posts' ||\n unit.kind === 'products' ||\n unit.kind === 'dataset' ||\n unit.kind === 'event' ||\n unit.kind === 'store'\n ? unit.kind\n : unit.jobKind,\n label: unit.label,\n ...(unit.creation ? { creation: unit.creation } : {}),\n ...(unit.screen ? { screen: unit.screen } : {}),\n deps: unit.kind === 'page' ? [...creations, ...listed(unit.screen)] : unit.kind === 'form' ? writtenTo(unit.creation) : [],\n }))\n}\n\n/**\n * A scaffold's ledger to start from (AGL-3616): every unit pending, except\n * the units a job already running when the ledger arrived had built, read\n * off its outputs as the scaffold always read them, which stand as built.\n */\nexport function aiSiteInitialLedger(\n units: readonly AiSiteUnit[],\n outputs: readonly AiJobOutput[],\n): AiJobItemLedger[] {\n const pending = new Set(aiSitePendingUnits(units, outputs).map((unit) => unit.slot))\n const byResource = new Map<AiJobOutputResource, string[]>()\n for (const output of outputs) byResource.set(output.resource, [...(byResource.get(output.resource) ?? []), output.id])\n return aiBuildInitialLedger(aiSiteLedgerUnits(units)).map((row, index) => {\n const unit = units[index]\n if (pending.has(unit.slot)) return row\n const id = byResource.get(unit.resource)?.shift()\n return { ...row, status: 'succeeded', outputs: id ? [id] : [] }\n })\n}\n\n/** The units a scaffold owes on this job: what its plan implies that this deployment can build. */\nfunction aiSiteOwedUnits(\n job: AiJob,\n plan: AiJobPlan,\n inputs: AiSiteJobInputs,\n freeTaste: boolean,\n runnerFor: typeof aiJobStepRunnerFor,\n): AiSiteUnit[] {\n // A start whose ledger was written before the store pages existed (AGL-3676)\n // is not owed them: its ledger has no row for them to settle. Nor is a Free\n // blog's ledger written before it was owed its one post (AGL-3798).\n const ledgered = (slot: string) => !job.items?.length || job.items.some((row) => row.slot === slot)\n return aiSiteJobUnits(plan, {\n welcomeEmail: aiSiteWelcomeEmail(inputs, freeTaste),\n content: aiSiteContentPart(job.inputs, freeTaste),\n posts: freeTaste ? AI_SITE_FREE_POSTS : AI_SITE_POSTS,\n }).filter(\n (unit) =>\n (unit.kind === 'store' && ledgered('store')) ||\n unit.kind === 'theme' ||\n (unit.kind === 'posts' && ledgered('posts')) ||\n unit.kind === 'dataset' ||\n unit.kind === 'event' ||\n (unit.kind !== 'store' && runnerFor(unit.jobKind)),\n )\n}\n\nexport function createAiJobSiteStep(\n deps: AiJobSiteStepDeps = {},\n): AiJobStepRunner {\n const runnerFor = deps.runnerFor ?? aiJobStepRunnerFor\n const readNodes = deps.readNodes ?? readAiDraftNodes\n const publish = deps.publish ?? aiPublishGuidedSite\n const siteName = deps.siteName ?? aiSiteDisplayName\n const look = deps.look ?? aiRunSiteLook\n const contentRefusal = deps.contentRefusal ?? aiSiteContentRefusal\n const datasetRefusal = deps.datasetRefusal ?? aiSiteDatasetRefusal\n const eventRefusal = deps.eventRefusal ?? aiSiteEventRefusal\n const storePagesRefusal = deps.storePagesRefusal ?? aiSiteStorePagesRefusal\n const publishPosts = deps.publishPosts ?? aiPublishSitePosts\n const dropCache = deps.dropCache ?? dropPluginSiteCache\n const restoreBlogEntry = deps.restoreBlogEntry ?? aiRestoreGuidedBlogEntry\n const latePhotos = deps.latePhotos ?? aiSiteLatePhotos\n return async (context): Promise<AiJobStepOutcome> => {\n const { job } = context\n // The scaffold asks no model of its own. What it names where it spends\n // nothing is the model its plan ran on, which is the one exchange this\n // job has already had of its own.\n const model = context.modelFor?.('job.plan') ?? aiModelForStep('job.plan')\n const plan = aiConfirmedPlan(job)\n if (!plan)\n return { ...aiUnspentOutcome(model), failure: AI_SITE_NO_PLAN_COPY }\n // The resume door refuses such a plan at confirmation once it can read\n // one; a plan confirmed before a site changed still stops here, unspent.\n const freeTaste = aiSiteFreeTaste(context.org)\n const refusal = aiSitePlanRefusal(plan, { freeTaste })\n if (refusal) return { ...aiUnspentOutcome(model), failure: refusal }\n const inputs = parseAiSiteJobInputs(job.inputs)\n if (typeof inputs === 'string')\n return { ...aiUnspentOutcome(model), failure: inputs }\n\n // A kind this deployment has not loaded is not among the units at all, so\n // a scaffold owes only what something can build.\n const units = aiSiteOwedUnits(job, plan, inputs, freeTaste, runnerFor)\n const ledgerUnits = aiSiteLedgerUnits(units)\n // Settled item by item, like a build (AGL-3616): the ledger, not the\n // outputs, says where the scaffold stands once it has one.\n const starting = !job.items?.length\n const ledger = starting ? aiSiteInitialLedger(units, job.outputs ?? []) : (job.items as AiJobItemLedger[])\n const init = starting ? { items: ledger } : {}\n const rows = new Map(ledger.map((row) => [row.slot, row]))\n const next = aiBuildNextUnit(ledgerUnits, ledger)\n /**\n * The pictures the start left on a starter (AGL-3988): what the job\n * holds, with what this pass's unit reported merged in once it ran.\n */\n let photos: AiSitePhotos | null = job.sitePhotos ?? null\n let photosReported = false\n /**\n * Whether the publish waits for the late photo pass: a record, or a\n * picture of a page it puts live, is still on a starter. A page that\n * failed is not published, so its pictures owe nothing. `pages`: the\n * pages built so far, the one this pass built among them.\n */\n const latePhotosOwed = (pages: readonly AiJobOutput[]) =>\n Boolean(job.hostId) && aiSitePhotosOwed(photos, pages.map((page) => page.id))\n\n /**\n * A guided start's last pass puts what it built on the site (AGL-3596):\n * only its pages that were built. Once it has, Try again's last pass puts\n * only the pages the retry built live (AGL-3730), never the home address\n * or the announce again, merged into the record of the first.\n */\n const finish = async (outcome: AiJobStepOutcome, pages: readonly AiJobOutput[]): Promise<AiJobStepOutcome> => {\n if (!aiJobPublishesSite(job) || !job.hostId) return outcome\n const previous = job.sitePublish ?? null\n const wasLive = Boolean(previous?.published.length)\n const live = new Set((previous?.published ?? []).map((page) => page.id))\n const fresh = pages.filter((page) => !live.has(page.id))\n // Posts Try again wrote for a site already live go live too, pages or not (AGL-3739).\n const postsRetried = wasLive && postsRebuilt()\n if (!fresh.length && !postsRetried) return outcome\n // A canceled start never puts the site live (AGL-3616): its pages stay drafts.\n if (await aiJobCancelAsked(context.firestore, job, context.signal)) return outcome\n if (!fresh.length) {\n if (await finishPosts()) await finishBlogEntry(previous?.published ?? [])\n return outcome\n }\n // A blog the header links by path before its posts exist (AGL-3660):\n // owed and not delivered, its links come out of what is published.\n const postsRow = rows.get('posts')\n const sitePublish = await publish(context.firestore, {\n job,\n outputs: fresh,\n now: context.now,\n ...(postsRow ? { blogUnwritten: !aiBuildItemDelivered(postsRow) || !postsRow.outputs?.length } : {}),\n // The store's pages the header and footer link and the start did not write (AGL-3676).\n ...(rows.get('store') ? { unwrittenHrefs: unwrittenStoreHrefs(pages) } : {}),\n // The pages it planned and did not build, which nothing it publishes links (AGL-3988).\n unbuiltScreenIds: unbuiltPages(),\n // And the order the site lists its pages in, which Pages and the 404 page follow.\n siteOrder: plan.screens.flatMap((screen) => (screen.id ? [screen.id] : [])),\n ...(wasLive ? { retry: true } : {}),\n // The site publishes in the language its brief was written in (AGL-3750).\n ...(plan.language ? { language: plan.language } : {}),\n }).catch((error: unknown) => {\n // The site is built either way; the pages stay drafts and say so.\n console.error('ai site publish threw', { orgId: job.orgId, jobId: job.$id, error })\n return null\n })\n // The blog's posts go live with the first publish that puts a page\n // live, and on a site already live, when Try again wrote them; then\n // the header links the blog again, which the first publish took out.\n if (wasLive ? postsRetried : sitePublish?.published.length) {\n const posted = await finishPosts()\n if (posted && wasLive) await finishBlogEntry([...(previous?.published ?? []), ...(sitePublish?.published ?? [])])\n }\n if (!sitePublish) return outcome\n return { ...outcome, sitePublish: previous ? aiMergeSitePublish(previous, sitePublish) : sitePublish }\n }\n /**\n * Whether the blog's posts part was written by Try again: delivered on a\n * later attempt than its first. Publishing them again on a later retry\n * leaves a post already published as it is.\n */\n const postsRebuilt = (): boolean => {\n const row = rows.get('posts')\n return Boolean(row && row.attempt > 1 && aiBuildItemDelivered(row) && row.outputs?.length)\n }\n /**\n * The blog's posts go live with its pages (AGL-3676), as a person's\n * Publish would put them. Whether any did.\n */\n const finishPosts = async (): Promise<boolean> => {\n const row = rows.get('posts')\n if (!row || !aiBuildItemDelivered(row) || !job.hostId) return false\n const ids = new Set(row.outputs)\n const posts = (job.outputs ?? []).filter((output) => output.resource === 'entry' && ids.has(output.id))\n const published = await publishPosts(context.firestore, { job, outputs: posts, now: context.now })\n if (!published?.paths.length) return false\n await dropCache({\n hostIds: [job.hostId],\n reason: 'guided AI site start published its posts',\n paths: { [job.hostId]: published.paths },\n }).catch((error: unknown) => console.warn('ai site posts: cache not dropped', { jobId: job.$id, error }))\n return true\n }\n /**\n * A blog whose posts Try again put live on a site already live (AGL-3747):\n * the first publish took every link to it out (AGL-3660), so its header\n * entry goes back, after the home page's, where no link opens it yet. The\n * site is live either way; a layout it cannot change is logged.\n */\n const finishBlogEntry = async (published: ReadonlyArray<{ id: string; path: string }>) => {\n const blog = aiSiteBlogNavPage(aiSitePlanWithoutBlogStandIns(plan.screens).screens)\n await restoreBlogEntry(context.firestore, {\n job,\n pageIds: published.map((page) => page.id),\n homeId: published.find((page) => page.path === '/')?.id ?? null,\n blog: { label: blog.label, href: blog.href },\n now: context.now,\n }).catch((error: unknown) => {\n console.error('ai site blog entry not restored', { orgId: job.orgId, jobId: job.$id, error })\n return false\n })\n }\n /**\n * The pages built so far, as the job reported them. A dataset's record\n * template is not among them (AGL-3616): it renders once per record only\n * once the member saves its binding, so it is never published at its own\n * address, where its `{{item.*}}` would show.\n */\n const templates = new Set(units.filter((unit) => unit.kind === 'page' && unit.screen?.record).map((unit) => unit.slot))\n /** The paths of the store's pages the frame links that are not among the pages going live (AGL-3676). */\n const unwrittenStoreHrefs = (pages: readonly AiJobOutput[]) => {\n const live = new Set(pages.map((page) => page.proposal?.['storePage']).filter(Boolean))\n return aiStorePagesOfPlan(plan.screens)\n .filter((page) => !page.planned && !live.has(page.key))\n .map((page) => page.href)\n }\n const builtPages = (extra: readonly AiJobOutput[] = []) => {\n const ids = new Set(\n units\n .filter(\n (unit) =>\n (unit.kind === 'page' || unit.kind === 'store') &&\n !templates.has(unit.slot) &&\n aiBuildItemDelivered(rows.get(unit.slot) ?? { status: 'pending' }),\n )\n .flatMap((unit) => rows.get(unit.slot)?.outputs ?? []),\n )\n return [...(job.outputs ?? []).filter((output) => output.resource === 'screen' && ids.has(output.id)), ...extra]\n }\n /**\n * The pages the start planned and has not built (AGL-3988): a page whose\n * part failed or was refused. The beta.270 Sugar Hollow Galleries page\n * failed its checks, and its home page, header and footer linked it\n * anyway, to a 404.\n */\n const unbuiltPages = () =>\n units.flatMap((unit) =>\n unit.kind === 'page' &&\n !templates.has(unit.slot) &&\n unit.screen?.id &&\n !aiBuildItemDelivered(rows.get(unit.slot) ?? { status: 'pending' })\n ? [unit.screen.id]\n : [],\n )\n\n if (!next) {\n // Every part is built: the pictures left on a starter take the job's\n // own photos before the site goes live (AGL-3988), in a pass of their\n // own, sized to wait out the image hosts' burst.\n if (latePhotosOwed(builtPages()) && photos && !(await aiJobCancelAsked(context.firestore, job, context.signal))) {\n const late = await latePhotos({\n firestore: context.firestore,\n job,\n photos,\n pageIds: builtPages().map((page) => page.id),\n org: (context.org ?? null) as Readonly<Record<string, unknown>> | null,\n now: context.now,\n ...(context.signal ? { signal: context.signal } : {}),\n })\n // A pass whose time ran out while it waited hands what is left to the\n // next, inside the passes the bound gives it: the last one publishes\n // whatever the pictures hold, so a site is never held back by them.\n const latePasses = (photos.latePasses ?? 0) + 1\n if (late.photos && latePasses < AI_SITE_LATE_PHOTOS_PASSES - 1) {\n return { ...aiUnspentOutcome(model), ...init, continue: true, sitePhotos: { ...late.photos, latePasses } }\n }\n return finish({ ...aiUnspentOutcome(model), ...init, sitePhotos: AI_SITE_PHOTOS_SETTLED }, builtPages())\n }\n return finish({ ...aiUnspentOutcome(model), ...init }, builtPages())\n }\n const unit = units.find((one) => one.slot === next.slot) as AiSiteUnit\n // The look is the scaffold's own pass (AGL-3660), not the theme job's proposal.\n const catalog = unit.kind === 'products' ? runnerFor('products') : undefined\n const runner: AiJobStepRunner | undefined =\n unit.kind === 'theme'\n ? (lookContext) => look(lookContext, lookContext.job)\n : unit.kind === 'posts'\n ? (deps.posts ?? runAiSitePostsUnit)\n : unit.kind === 'products'\n ? (deps.products ?? (catalog ? createAiSiteProductsRunner({ catalog }) : undefined))\n : unit.kind === 'dataset'\n ? (deps.dataset ?? runAiSiteDatasetUnit)\n : unit.kind === 'event'\n ? (deps.event ?? runAiSiteEventUnit)\n : unit.kind === 'store'\n ? (deps.storePages ?? runAiSiteStorePagesUnit)\n : runnerFor(unit.jobKind)\n if (!runner) return { ...aiUnspentOutcome(model), ...init }\n const othersOpen = ledgerUnits.some(\n (one) => one.slot !== unit.slot && aiBuildItemOpen(rows.get(one.slot) ?? { status: 'pending' }),\n )\n // The site's own listing rides out beside the first unit's output, once\n // (AGL-2918): it is derived from the answers rather than generated, so it\n // is ready before anything is built and costs the pass nothing.\n const listing = aiSiteSeoOutputOwed(job) ? aiSiteSeoOutputs(job, await siteName(context.firestore, job.hostId)) : []\n const settle = (item: AiJobItemOutcome, spent: AiJobStepOutcome = aiUnspentOutcome(model)): AiJobStepOutcome => ({\n ...spent,\n outputs: [...listing, ...spent.outputs],\n ...init,\n item,\n ...(item.status === 'running' || othersOpen ? { continue: true } : {}),\n ...(photosReported ? { sitePhotos: photos ?? AI_SITE_PHOTOS_SETTLED } : {}),\n })\n /**\n * A unit that failed or was skipped with nothing else open ends the job\n * on this pass (AGL-3676): a guided start whose last unit — its welcome\n * email — failed was never published, because the pass that publishes is\n * the one after. So the end is the publish, whatever the last unit came to.\n */\n const closing = async (outcome: AiJobStepOutcome): Promise<AiJobStepOutcome> =>\n outcome.continue ? outcome : latePhotosOwed(builtPages()) ? { ...outcome, continue: true } : finish(outcome, builtPages())\n\n // A blog's posts and a store's products ask, before their first pass,\n // whether this member may have them here (AGL-3676): a refusal spends\n // nothing, and the row says why, as a build's item does.\n // A planned page standing in for the blog this start writes is merged into\n // it (AGL-3676): not built, its address the blog's, its links the blog's.\n // The plan step asks for a plan without one only once.\n if (unit.kind === 'page' && unit.screen && aiSiteIsBlogStandIn(unit.screen) && aiSiteWritesPosts(job)) {\n return closing(settle({ slot: unit.slot, status: 'skipped', note: AI_SITE_BLOG_MERGED_NOTE }))\n }\n if ((unit.kind === 'posts' || unit.kind === 'products') && rows.get(unit.slot)?.status !== 'running') {\n const refusal = await contentRefusal(unit.kind, { ...context, job }).catch((error: unknown) => {\n console.error('ai site part admission failed', { orgId: job.orgId, jobId: job.$id, slot: unit.slot, error })\n return AI_SITE_UNIT_EMPTY_COPY\n })\n if (refusal) return closing(settle({ slot: unit.slot, status: 'skipped', note: `Not built: ${refusal}` }))\n }\n // A dataset asks the same before its first pass (AGL-3616): the data\n // plugin runs here, and its writer admits this member now.\n if (unit.kind === 'dataset' && rows.get(unit.slot)?.status !== 'running') {\n const refusal = await datasetRefusal({ ...context, job }).catch((error: unknown) => {\n console.error('ai site dataset admission failed', { orgId: job.orgId, jobId: job.$id, slot: unit.slot, error })\n return AI_SITE_UNIT_EMPTY_COPY\n })\n if (refusal) return closing(settle({ slot: unit.slot, status: 'skipped', note: `Not built: ${refusal}` }))\n }\n // An event asks the same (AGL-3755): the events plugin runs here, and its\n // writer admits this member now.\n if (unit.kind === 'event' && rows.get(unit.slot)?.status !== 'running') {\n const refusal = await eventRefusal({ ...context, job }).catch((error: unknown) => {\n console.error('ai site event admission failed', { orgId: job.orgId, jobId: job.$id, slot: unit.slot, error })\n return AI_SITE_UNIT_EMPTY_COPY\n })\n if (refusal) return closing(settle({ slot: unit.slot, status: 'skipped', note: `Not built: ${refusal}` }))\n }\n // The store's own pages ask the same (AGL-3676): a plan with a store, the\n // commerce plugin here, and a member who may edit the site's pages.\n if (unit.kind === 'store' && rows.get(unit.slot)?.status !== 'running') {\n const refusal = await storePagesRefusal({ ...context, job }).catch((error: unknown) => {\n console.error('ai site store pages admission failed', { orgId: job.orgId, jobId: job.$id, error })\n return AI_SITE_UNIT_EMPTY_COPY\n })\n if (refusal) return closing(settle({ slot: unit.slot, status: 'skipped', note: `Not built: ${refusal}` }))\n }\n // A record template whose dataset was not made has nothing to show\n // (AGL-3616): it is not built, and the pages that list the dataset are\n // built without it.\n const templateOf = unit.kind === 'page' && unit.screen ? aiSiteRecordTemplateOf(unit.screen) : null\n if (templateOf) {\n const dataset = units.find((one) => one.kind === 'dataset' && one.creation?.name.trim().toLowerCase() === templateOf.toLowerCase())\n const row = dataset ? rows.get(dataset.slot) : undefined\n if (!row || !aiBuildItemDelivered(row) || !row.outputs.length) {\n return closing(\n settle({\n slot: unit.slot,\n status: 'skipped',\n note: `Not built: the dataset “${templateOf}” it shows a page of each record of could not be created.`,\n ...(dataset ? { degradedBy: [dataset.slot] } : {}),\n }),\n )\n }\n }\n\n // A page whose layout or form failed is built without it, and says so.\n const degradation = aiBuildDegradation(next, { units: ledgerUnits, ledger })\n const degraded = degradation.degradedBy.length > 0\n const note = degradation.notes.length ? degradation.notes.join(' ') : null\n const built = aiBuildBuiltRefs(ledgerUnits, ledger, job.outputs ?? [])\n const derived = aiSiteUnitJob(job, unit, built)\n const handed: AiJob = degradation.briefLines.length\n ? { ...derived, brief: [derived.brief, ...degradation.briefLines].join('\\n').slice(0, AI_JOB_BRIEF_MAX_CHARS) }\n : derived\n\n let outcome: AiJobStepOutcome\n try {\n outcome = await runner({ ...context, job: handed })\n } catch (error) {\n if (aiUnitErrorRetryable(error)) throw error\n console.error('ai site unit threw', { orgId: job.orgId, jobId: job.$id, slot: unit.slot, error })\n return closing(settle({ slot: unit.slot, status: 'failed', failure: { ours: true, reason: 'provider', message: AI_SITE_UNIT_EMPTY_COPY } }))\n }\n // The pictures this unit left on a starter, kept on the job for the late photo pass (AGL-3988).\n if (outcome.sitePhotos) {\n photos = aiSiteMergePhotos(photos, outcome.sitePhotos)\n photosReported = true\n }\n const spent = aiUnitSpend(outcome)\n const stopped = aiUnitFailure(unit.slot, outcome)\n if (stopped) {\n return closing(\n settle(\n stopped.status === 'failed' && stopped.failure && !outcome.failure && !outcome.refused && !outcome.review\n ? { ...stopped, failure: { ...stopped.failure, message: AI_SITE_UNIT_EMPTY_COPY } }\n : stopped,\n spent,\n ),\n )\n }\n // A page counts as built only when its plan's sections are in it\n // (AGL-3596): otherwise the page fails, on our side, and is not reported.\n if (unit.kind === 'page' && unit.screen && job.hostId) {\n const page = outcome.outputs.find((output) => output.resource === 'screen')\n const written =\n page !== undefined &&\n (await aiSitePageWritten(\n context.firestore,\n {\n hostId: job.hostId,\n unitJobId: aiSiteUnitJobId(job, unit),\n screen: unit.screen,\n draftId: page.id,\n layoutLanguage: aiJobUsesLayoutLanguage(handed),\n },\n readNodes,\n ))\n if (!written) {\n return closing(\n settle(\n { slot: unit.slot, status: 'failed', failure: { ours: true, reason: 'step-failure', message: AI_SITE_PAGE_NOT_WRITTEN_COPY } },\n { ...spent, outputs: spent.outputs.filter((output) => output.resource !== 'screen') },\n ),\n )\n }\n }\n const done = settle(\n {\n slot: unit.slot,\n status: degraded ? 'degraded' : 'succeeded',\n outputs: outcome.outputs.map((output) => output.id),\n // A store's products are listed before they are priced (AGL-3676):\n // the row says what is left before the store sells.\n note:\n unit.kind === 'products' && outcome.outputs.length\n ? aiSiteSampleProductKinds(job.inputs)\n ? AI_SITE_SAMPLE_PRODUCTS_NOTE\n : AI_SITE_PRODUCTS_PRICE_NOTE\n : unit.kind === 'store' && outcome.outputs.length\n ? AI_SITE_STORE_PAGES_NOTE\n : note,\n ...(degraded ? { degradedBy: degradation.degradedBy } : {}),\n },\n spent,\n )\n if (done.continue) return done\n rows.set(unit.slot, { ...(rows.get(unit.slot) as AiJobItemLedger), status: degraded ? 'degraded' : 'succeeded' })\n const live = builtPages(\n (unit.kind === 'page' && !templates.has(unit.slot)) || unit.kind === 'store'\n ? outcome.outputs.filter((output) => output.resource === 'screen')\n : [],\n )\n // The publish waits a pass for the late photo pass (AGL-3988).\n if (latePhotosOwed(live)) return { ...done, continue: true }\n return finish(done, live)\n }\n}\n\nexport const runAiJobSiteStep = createAiJobSiteStep()\n\n/** ASSUMED: what the store pages' pass needs — five draft transactions and their search listings, no model. */\nexport const AI_SITE_STORE_PAGES_MINIMUM_MS = 15_000\n\n/**\n * The least time a scaffold's next pass needs (AGL-3035). The scaffold asks no\n * model itself: each pass hands one unit to the step registered for its kind,\n * under the job derived for it, so it needs what that step registers for that\n * job — a palette change's or a layout's time for those units, a page pass's\n * for a page. A scaffold with nothing left to build, or with no plan it can\n * build, spends nothing, and a page pass's time covers it.\n */\nexport function aiSiteJobRunMinimumMs(job: AiJob): number {\n const plan = aiConfirmedPlan(job)\n const inputs = parseAiSiteJobInputs(job.inputs)\n if (!plan || typeof inputs === 'string') return AI_JOB_PAGE_STEP_MINIMUM_MS\n // The org is not read here, so a blog's or a store's part is counted as a\n // paid plan's; a ledger, once the job has one, says which units it owes.\n const owed = new Set((job.items ?? []).map((row) => row.slot))\n const units = aiSiteJobUnits(plan, {\n welcomeEmail: inputs.welcomeEmail,\n content: aiSiteContentPart(job.inputs, false),\n }).filter(\n (unit) =>\n (unit.kind === 'theme' ||\n unit.kind === 'posts' ||\n unit.kind === 'dataset' ||\n unit.kind === 'event' ||\n unit.kind === 'store' ||\n aiJobStepRunnerFor(unit.jobKind)) &&\n (!owed.size || owed.has(unit.slot)),\n )\n const outputs = job.outputs ?? []\n const ledger = job.items?.length ? job.items : aiSiteInitialLedger(units, outputs)\n const next = aiBuildNextUnit(aiSiteLedgerUnits(units), ledger)\n const unit = next ? units.find((one) => one.slot === next.slot) : undefined\n // Nothing left to build: the late photo pass, where a picture is still on\n // a starter (AGL-3988), and the publish in the same pass.\n if (!unit) return aiSitePhotosOwed(job.sitePhotos) ? Math.max(AI_JOB_PAGE_STEP_MINIMUM_MS, AI_SITE_LATE_PHOTOS_MINIMUM_MS) : AI_JOB_PAGE_STEP_MINIMUM_MS\n if (unit.kind === 'theme') return AI_SITE_LOOK_BUDGET.minimumMs\n if (unit.kind === 'posts') return AI_SITE_POST_BUDGET.minimumMs\n if (unit.kind === 'dataset') return AI_SITE_DATASET_BUDGET.minimumMs\n if (unit.kind === 'event') return AI_SITE_EVENT_MINIMUM_MS\n // The store's pages ask no model: five draft writes (AGL-3676).\n if (unit.kind === 'store') return AI_SITE_STORE_PAGES_MINIMUM_MS\n return aiJobStepRunMinimumMs(aiSiteUnitJob(job, unit, aiBuildBuiltRefs(aiSiteLedgerUnits(units), ledger, outputs)))\n}\n\n/**\n * Registers the site scaffold with the least time a pass needs — every\n * scaffold builds pages, and a page pass needs the least of any unit — and the\n * time its next pass needs, the passes a whole site's plan may take, and the\n * check a site job passes before it is created or resumed.\n */\nexport function registerAiSiteJob(): void {\n registerAiJobStep('site', runAiJobSiteStep, {\n minimumMs: AI_JOB_PAGE_STEP_MINIMUM_MS,\n minimumMsFor: aiSiteJobRunMinimumMs,\n })\n registerAiJobStepPasses('site', AI_SITE_MAX_PASSES)\n registerAiJobAdmission('site', aiSiteJobAdmission)\n}\n"],"names":["aiJobCancelAsked","resolveEffectivePlan","resolveOrgIdForHost","isAiPlanNewRef","aiBuildDegradation","aiBuildInitialLedger","aiBuildItemDelivered","aiBuildItemOpen","aiBuildNextUnit","aiBuildBuiltRefs","aiUnitErrorRetryable","aiUnitFailure","aiUnitSpend","AI_SITE_EMAIL_TYPE","AI_SITE_MAX_SECTIONS","AI_SITE_PAGES","aiFreeCreditsNoneLeftText","aiFreeSitePrompt","aiSiteNameSentence","aiSitePagesRefusal","aiSitePlanRefusal","aiSiteSubmissions","aiSiteWords","parseAiSiteJobInputs","aiSiteBlogNavPage","aiSiteIsBlogStandIn","aiSitePlanWithoutBlogStandIns","readFreeAiCreditsLeft","AI_CREDITS_CONFIRM_CODE","aiCreditsPromptText","AI_SITE_SEO_OUTPUT_ID","aiSiteSeoProposalForInputs","aiSiteDetailsBriefLines","aiModelForStep","registerAiJobAdmission","aiOriginJobId","aiRecordedJobDraftId","readAiDraftNodes","AI_STOCK_PHOTO_AVOID_INPUT","AI_STOCK_PHOTO_JOB_PHOTOS_INPUT","AI_STOCK_PHOTO_LATE_PASS_INPUT","AI_STOCK_PHOTO_PAGES_INPUT","AI_LAYOUT_SITE_ALIASES_INPUT","AI_LAYOUT_SITE_PAGES_INPUT","AI_LAYOUT_SITE_PAGES_MAX","aiLayoutIsHomeSlug","aiLayoutSitePagesOfPlan","aiPageSectionNodeId","AI_LAYOUT_LISTINGS_INPUT","aiLayoutIsShopPage","aiSiteKindOfInputs","AI_LAYOUT_FORM_PAGE_INPUT","AI_LAYOUT_LANGUAGE_INPUT","aiJobUsesLayoutLanguage","aiLayoutFormPageOfPlan","aiJobPublishesSite","aiMergeSitePublish","aiPublishGuidedSite","aiRestoreGuidedBlogEntry","AI_SITE_CONTENT_INPUT","AI_SITE_FREE_POSTS","AI_SITE_POST_BUDGET","AI_SITE_POST_LABEL","AI_SITE_POSTS","AI_SITE_POSTS_LABEL","AI_SITE_PRODUCTS_LABEL","AI_SITE_PRODUCTS_PRICE_NOTE","AI_SITE_SAMPLE_PRODUCTS_INPUT","AI_SITE_SAMPLE_PRODUCTS_NOTE","aiPublishSitePosts","aiSiteContentBriefLines","aiSiteContentPart","aiSiteContentRefusal","aiSiteListings","aiSiteProductsBriefLine","aiSiteSampleProductKinds","createAiSiteProductsRunner","runAiSitePostsUnit","dropPluginSiteCache","AI_SITE_DATASET_BUDGET","AI_SITE_DATASET_INPUT","AI_SITE_DATASETS_MAX","aiSiteDatasetBriefLines","aiSiteDatasetInputOf","aiSiteDatasetListings","aiSiteDatasetPlacedPhotoDetails","aiSiteDatasetPlacedPhotos","aiSiteDatasetRefusal","aiSitePlanDatasets","aiSiteReusedDatasetListings","aiSiteRecordTemplateOf","runAiSiteDatasetUnit","AI_SITE_EVENT_INPUT","AI_SITE_EVENT_LABEL","AI_SITE_EVENT_MINIMUM_MS","AI_SITE_EVENTS_MAX","aiSiteEventListings","aiSiteEventRefusal","aiSitePlanEvents","runAiSiteEventUnit","AI_SITE_LOOK_BUDGET","aiRunSiteLook","AI_SITE_STORE_PAGES_INPUT","aiSiteStorePagesRefusal","runAiSiteStorePagesUnit","AI_SITE_STORE_LINKS_INPUT","AI_SITE_STORE_PAGES_LABEL","AI_SITE_STORE_PAGES_NOTE","aiStoreFrameLinks","aiStorePagesOfPlan","AI_FORM_DATASET_MADE_INPUT","aiConfirmedPlan","aiUnspentOutcome","AI_JOB_BRIEF_MAX_CHARS","AI_JOB_PAGE_STEP_MINIMUM_MS","aiSiteMergePhotos","aiSitePhotosOwed","AI_SITE_LATE_PHOTOS_MINIMUM_MS","aiSiteLatePhotos","AI_SITE_INSPIRATION_SIGNALS_INPUT","aiSiteInspirationReleased","aiSiteInspirationRefusal","aiJobStepRunMinimumMs","aiJobStepRunnerFor","registerAiJobStep","registerAiJobStepPasses","UNIT_KINDS","theme","jobKind","resource","layout","form","component","page","email","posts","products","dataset","event","store","CREATION_UNIT_KINDS","aiCreationUnit","creation","slot","kind","label","name","CREATION_UNITS","unit","create","AI_SITE_LOOK_LABEL","AI_SITE_NO_PLAN_COPY","AI_SITE_NO_PAGE_STEP_COPY","AI_SITE_UNIT_EMPTY_COPY","AI_SITE_LATE_PHOTOS_PASSES","AI_SITE_MAX_PASSES","max","length","aiSiteJobUnits","plan","options","units","forEach","index","push","find","entry","content","item","screens","screen","title","welcomeEmail","aiSitePendingUnits","outputs","done","Map","output","set","get","filter","left","aiSiteSeoOutputs","job","siteName","aiSiteSeoOutputOwed","proposal","inputs","language","id","hostId","some","aiSiteDisplayName","firestore","collection","doc","trim","aiSiteBuiltRefs","byResource","rows","built","row","shift","toLowerCase","aiSiteBuiltLayoutId","values","aiSiteResolvedRef","ref","slice","indexOf","aiSiteBriefLines","brief","lines","site","businessName","businessType","audience","city","brand","Boolean","join","aiSiteWelcomeEmailName","raw","business","replace","aiSiteEmailBriefLines","submissions","aiSiteUnitJobId","recorded","$id","aiSiteUnitJob","unitPlan","labels","reuse","placedByScreens","Set","flatMap","sections","section","uses","has","duplicateOf","writesTo","why","purpose","template","record","map","slug","sampleKinds","undefined","unitInputs","originJobId","inspiration","pages","records","recordPhotos","writesPosts","aiSiteWritesPosts","merged","standIns","planned","guided","blogPage","blog","homes","aliases","href","standsInFor","listings","sells","aiSiteSellsProducts","music","delivered","entries","datasets","items","listed","aiSiteAddsStorePages","aiSiteStorePagesInputOf","look","style","headerAlign","rhythm","seed","motion","formPage","written","total","avoidSlugs","split","byline","steps","mode","emailType","path","others","facts","contactPath","test","shopPath","shippingPath","key","layoutId","status","AI_SITE_BLOG_MERGED_NOTE","createAiSiteJobAdmission","deps","freeCreditsLeft","inspirationReleased","now","Date","context","error","freeTaste","aiSiteFreeTaste","org","orgId","credits","resetsOn","prompt","siteKind","creditsConfirmed","code","onCreditsConfirmed","shape","siteToCome","owner","aiSiteJobAdmission","aiSiteWelcomeEmail","aiRunJobUnit","input","outcome","runner","spent","usage","estCostUsd","model","stopReason","effort","refused","failure","review","continue","emptyCopy","AI_SITE_PHOTOS_SETTLED","lists","AI_SITE_PAGE_NOT_WRITTEN_COPY","aiSitePageWritten","readNodes","stored","draftId","present","unitJobId","nodes","layoutLanguage","every","_","aiSiteLedgerUnits","creations","writtenTo","named","op","aiSiteInitialLedger","pending","aiSiteOwedUnits","runnerFor","ledgered","createAiJobSiteStep","publish","contentRefusal","datasetRefusal","eventRefusal","storePagesRefusal","publishPosts","dropCache","restoreBlogEntry","latePhotos","modelFor","refusal","ledgerUnits","starting","ledger","init","next","photos","sitePhotos","photosReported","latePhotosOwed","finish","postsRow","previous","sitePublish","wasLive","published","live","fresh","postsRetried","postsRebuilt","signal","finishPosts","finishBlogEntry","blogUnwritten","unwrittenHrefs","unwrittenStoreHrefs","unbuiltScreenIds","unbuiltPages","siteOrder","retry","catch","console","jobId","posted","attempt","ids","paths","hostIds","reason","warn","pageIds","homeId","templates","builtPages","extra","late","latePasses","one","catalog","lookContext","storePages","othersOpen","listing","settle","closing","note","templateOf","degradedBy","degradation","degraded","notes","derived","handed","briefLines","ours","message","stopped","runAiJobSiteStep","AI_SITE_STORE_PAGES_MINIMUM_MS","aiSiteJobRunMinimumM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