@aglyn/plugins-ai 1.32.0 → 1.33.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +17 -17
- package/src/lib/jobs/ai-job-campaign-step.js +1 -0
- package/src/lib/jobs/ai-job-campaign-step.js.map +1 -1
- package/src/lib/jobs/ai-job-component-step.js +2 -1
- package/src/lib/jobs/ai-job-component-step.js.map +1 -1
- package/src/lib/jobs/ai-job-drafts.d.ts +8 -0
- package/src/lib/jobs/ai-job-drafts.js +18 -12
- package/src/lib/jobs/ai-job-drafts.js.map +1 -1
- package/src/lib/jobs/ai-job-edit-step.d.ts +5 -0
- package/src/lib/jobs/ai-job-edit-step.js +16 -9
- package/src/lib/jobs/ai-job-edit-step.js.map +1 -1
- package/src/lib/jobs/ai-job-email-step.js +1 -0
- package/src/lib/jobs/ai-job-email-step.js.map +1 -1
- package/src/lib/jobs/ai-job-form-step.js +2 -1
- package/src/lib/jobs/ai-job-form-step.js.map +1 -1
- package/src/lib/jobs/ai-job-layout-step.js +4 -1
- package/src/lib/jobs/ai-job-layout-step.js.map +1 -1
- package/src/lib/jobs/ai-job-navigation-step.js +7 -3
- package/src/lib/jobs/ai-job-navigation-step.js.map +1 -1
- package/src/lib/jobs/ai-job-page-step.js +7 -1
- package/src/lib/jobs/ai-job-page-step.js.map +1 -1
- package/src/lib/jobs/ai-job-privacy-step.d.ts +2 -0
- package/src/lib/jobs/ai-job-privacy-step.js +7 -4
- package/src/lib/jobs/ai-job-privacy-step.js.map +1 -1
- package/src/lib/jobs/ai-job-site-store-pages.js +3 -1
- package/src/lib/jobs/ai-job-site-store-pages.js.map +1 -1
- package/src/lib/jobs/ai-job-store-links-layout.js +8 -4
- package/src/lib/jobs/ai-job-store-links-layout.js.map +1 -1
- package/src/lib/jobs/ai-job-template-step.js +2 -1
- package/src/lib/jobs/ai-job-template-step.js.map +1 -1
- package/src/lib/jobs/ai-site-import-forms.js +2 -1
- package/src/lib/jobs/ai-site-import-forms.js.map +1 -1
- package/src/lib/jobs/ai-site-import-publish.d.ts +1 -1
- package/src/lib/jobs/ai-site-import-publish.js.map +1 -1
- package/src/lib/jobs/ai-site-late-photos.js +2 -1
- package/src/lib/jobs/ai-site-late-photos.js.map +1 -1
- package/src/lib/jobs/ai-site-publish.d.ts +2 -2
- package/src/lib/jobs/ai-site-publish.js +23 -15
- package/src/lib/jobs/ai-site-publish.js.map +1 -1
- package/src/lib/layout-language/ai-layout-frame-source.js +1 -0
- package/src/lib/layout-language/ai-layout-frame-source.js.map +1 -1
- package/src/lib/runtime/ai-palette.generated.js +7 -0
- package/src/lib/runtime/ai-palette.generated.js.map +1 -1
- package/src/lib/server/ai-experiment-versions.js +6 -3
- package/src/lib/server/ai-experiment-versions.js.map +1 -1
- package/src/lib/server/ai-page-content.js +2 -1
- package/src/lib/server/ai-page-content.js.map +1 -1
- package/src/lib/server/ai-seo-apply.js +6 -3
- package/src/lib/server/ai-seo-apply.js.map +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/jobs/ai-job-privacy-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 { createResourceUid } from '@aglyn/aglyn/app-utils/create-resource-uid'\nimport { holdsSiteKey } from '@aglyn/aglyn/app-utils/host-permissions'\nimport { orgPermissionLabel } from '@aglyn/aglyn/app-utils/org-permissions'\nimport {\n aiAddonName,\n checkEntitlement,\n ENTERPRISE_PLAN_LABEL,\n planLabelGrantingFeature,\n} from '@aglyn/aglyn/app-utils/plan-entitlements'\nimport { PLATFORM_BRAND_NAME } from '@aglyn/aglyn/app-utils/platform-brand'\nimport { SCREEN_ROOT_PATH } from '@aglyn/aglyn/app-utils/screen-route'\nimport { HostScreenVisibility } from '@aglyn/aglyn/foundation/definitions/platform.types'\nimport { dropPluginSiteCache } from '@aglyn/aglyn/plugin-manager/plugin-site-cache'\nimport type { PluginAiCapabilityArgsSchema } from '@aglyn/aglyn/plugin-manager/plugin-ai-capabilities'\nimport { getLockdownVerdict } from '@aglyn/tenant-data-admin/server/lockdown'\nimport { resolveOrgIdForHost } from '@aglyn/tenant-data-admin/server/organizations'\nimport { FieldValue, type Firestore } from 'firebase-admin/firestore'\nimport type { AiJobOutput } from '../model/ai-jobs.types'\nimport { registerAiJobAdmission, type AiJobAdmission, type AiJobAdmissionRefusal } from './ai-job-admission'\nimport { aiJobEditModel } from './ai-job-edit-step'\nimport { aiLimitReview, aiUnspentOutcome } from './ai-job-generation'\nimport type { AiJobStepOutcome, AiJobStepRunner } from './ai-job-text-step'\nimport { registerAiJobStep } from './ai-jobs'\n\n/**\n * The `privacy` step (AGL-4033): who can see the site, as the console's own\n * three controls set it — maintenance mode (Admin → Error pages), the\n * Discourage search engines switch (Setup → SEO) and a page's Visibility\n * (its Page Access card) — as a first-class build operation, so \"make my site\n * private until launch\" or \"hide the pricing page\" is one item on Assist's\n * plan card. The docs page it mirrors is Site Protection → Make your site\n * private.\n *\n * NO MODEL. The planner already wrote the choices as the item's arguments;\n * this checks each against the rule the console's own control holds it to and\n * writes it, so it costs no credits.\n *\n * ── Only the controls' own fields ────────────────────────────────────────\n *\n * `maintenance` (true, or deleted on the way off, as the Error pages card\n * writes it), `seo.discourageSearchEngines` (likewise, as the Search engines\n * card does), and a page's `visibility` as Public, Unlisted or Members only.\n * Leaving password mode drops the page's stored hash, as the Page Access card\n * does, so protection never lingers on a page that no longer asks for it.\n *\n * NEVER: a page password. Setting one would put the password in the chat and\n * the plan, so it is not an argument; the note sends the person to the Page\n * Access card instead. Nor layouts, emails or record templates, which have no\n * Page Access card, nor the error pages themselves.\n *\n * ── Who may ──────────────────────────────────────────────────────────────\n *\n * Search indexing and page visibility: the Firestore rules' own for those\n * keys, a member with a write role on the site (admin, editor or author)\n * while no lockdown freezes it. Maintenance mode takes every page of the site\n * offline for every visitor, so, as the console keeps its card in the Admin\n * area, only a site ADMIN may change it here. A non-admin's request still\n * makes the rest of its changes and says why that one was not made.\n *\n * Members only is made only where the plan has content gating (Business and\n * above): the tenant serves gated pages nowhere else, so on a lower plan the\n * write would close the page to everyone, and the note says why it was not.\n *\n * ── Live on confirm, idempotent ──────────────────────────────────────────\n *\n * As the `settings` and `tracking` steps: none of these has a draft, so the\n * plan card's confirm is the agreement and the write is live. One transaction\n * re-reads the host and each page, re-checks the role, writes only what\n * differs, and queues a site-wide publish outbox entry, because visibility\n * changes navigation and the sitemap and both switches change every page.\n */\n\nexport const AI_PRIVACY_KIND = 'privacy' as const\n\n/** ASSUMED: the least time the step needs — the site, the org, the pages named and one transaction. */\nexport const AI_JOB_PRIVACY_STEP_MINIMUM_MS = 5_000\n\nexport const AI_PRIVACY_NO_SITE_COPY = 'Open the site whose privacy should change.'\n/** Names \"Edit site content\" (`site.edit`, AGL-4047), never a role. */\nexport const AI_PRIVACY_ROLE_COPY = `Changing who can see the site needs the \"${orgPermissionLabel('site.edit')}\" permission on this site — ask an organization admin.`\n/** Names \"Manage site settings\" (`site.manage`, AGL-4047), never a role. */\nexport const AI_PRIVACY_ADMIN_COPY = `Turning maintenance mode on or off needs the \"${orgPermissionLabel('site.manage')}\" permission, so it was left as it is.`\nexport const AI_PRIVACY_LOCKED_COPY = 'This site is not accepting changes right now.'\nexport const AI_PRIVACY_NOTHING_COPY = 'The request named no privacy change this could make.'\nexport const AI_PRIVACY_PASSWORD_COPY =\n `To put a page behind a password, set it in that page’s Page Access card; ${aiAddonName()} never handles passwords.`\n\n/** The most pages one item may change. */\n/**\n * The cheapest plan with members-only pages (`contentGating`), read from\n * `PLAN_ENTITLEMENTS` so the copy can never name a retired plan (AGL-4158).\n */\nexport const AI_MEMBERS_ONLY_PLAN_LABEL =\n planLabelGrantingFeature('contentGating') ?? ENTERPRISE_PLAN_LABEL\n\nexport const AI_PRIVACY_MAX_PAGES = 20\n\n/** The visibilities a build may set, by the Page Access card's labels. */\nexport const AI_PRIVACY_VISIBILITIES = ['public', 'unlisted', 'members'] as const\nexport type AiPrivacyVisibility = (typeof AI_PRIVACY_VISIBILITIES)[number]\n\nconst VISIBILITY_VALUES: Readonly<Record<AiPrivacyVisibility, HostScreenVisibility>> = {\n public: HostScreenVisibility.PUBLIC,\n unlisted: HostScreenVisibility.UNLISTED,\n members: HostScreenVisibility.AUTHENTICATED,\n}\n\nconst VISIBILITY_LABELS: Readonly<Record<AiPrivacyVisibility, string>> = {\n public: 'Public',\n unlisted: 'Unlisted',\n members: 'Members only',\n}\n\n/** Where a person finds each change, as the output links and notes name it. */\nexport const AI_PRIVACY_OUTPUTS = {\n maintenance: { id: 'maintenance', label: 'Maintenance mode', where: 'Admin → Error pages' },\n search: { id: 'search', label: 'Search engines', where: 'Setup → SEO' },\n pages: { id: 'pages', label: 'Page access', where: 'each page’s Page Access card' },\n} as const\n\n/** Where the operation's changes are made, as the build's notes name it. */\nexport const AI_PRIVACY_WHERE = 'the site’s privacy settings'\n\n/** The item's arguments, as the planner fills them in. Every one optional. */\nexport const AI_PRIVACY_ARGS_SCHEMA: PluginAiCapabilityArgsSchema = {\n type: 'object',\n properties: {\n maintenance: {\n type: 'boolean',\n description:\n 'true takes the whole site offline for visitors: every address shows its 503 page to every visitor, including anyone with a link, until it is turned off, while the site team still sees the site. false brings the site back. Leave it out unless the person asked to take the whole site offline, keep it from everyone until launch, or bring it back.',\n },\n discourageSearchEngines: {\n type: 'boolean',\n description:\n 'true asks search engines not to index any page of the site (it stays open to anyone with a link); false lets them index it again. Leave it out unless the person asked about search engines or Google.',\n },\n publicPages: {\n type: 'array',\n description: 'Pages to make Public: anyone can open them, and they are offered to search engines. Each by its id from the site inventory.',\n items: { type: 'string', maxLength: 64 },\n maxItems: AI_PRIVACY_MAX_PAGES,\n },\n unlistedPages: {\n type: 'array',\n description: 'Pages to make Unlisted: anyone with the link can open them, kept out of search results, the sitemap and navigation. Each by its id from the site inventory.',\n items: { type: 'string', maxLength: 64 },\n maxItems: AI_PRIVACY_MAX_PAGES,\n },\n membersPages: {\n type: 'array',\n description: `Pages to make Members only: only visitors signed in to the site can open them (the ${AI_MEMBERS_ONLY_PLAN_LABEL} plan and above). Each by its id from the site inventory.`,\n items: { type: 'string', maxLength: 64 },\n maxItems: AI_PRIVACY_MAX_PAGES,\n },\n },\n additionalProperties: false,\n}\n\n/** Each visibility's argument, as the planner lists the pages for it. */\nconst VISIBILITY_ARGS: Readonly<Record<AiPrivacyVisibility, string>> = {\n public: 'publicPages',\n unlisted: 'unlistedPages',\n members: 'membersPages',\n}\n\n/** What an item asks: each switch to set, and each page's new visibility. */\nexport interface AiPrivacyRequest {\n maintenance: boolean | null\n discourageSearchEngines: boolean | null\n pages: { page: string; visibility: AiPrivacyVisibility }[]\n}\n\nexport interface AiPrivacyRead {\n request: AiPrivacyRequest\n /** A sentence per value that could not be used, so the rest still are. */\n problems: string[]\n}\n\nconst flag = (value: unknown): boolean | null => (typeof value === 'boolean' ? value : null)\n\n/** A page id as the site inventory gives it: one document id, never a path. */\nconst PAGE_ID = /^[A-Za-z0-9_-]{1,64}$/\n\n/** The item's arguments read: what may be written, and a sentence for each that may not. */\nexport function aiPrivacyRequestOf(inputs: Readonly<Record<string, unknown>> | null | undefined): AiPrivacyRead {\n const problems: string[] = []\n const pages: AiPrivacyRequest['pages'] = []\n const asked = new Map<string, Set<AiPrivacyVisibility>>()\n for (const visibility of AI_PRIVACY_VISIBILITIES) {\n const listed = inputs?.[VISIBILITY_ARGS[visibility]]\n for (const entry of Array.isArray(listed) ? listed : []) {\n const page = typeof entry === 'string' ? entry.trim() : ''\n if (PAGE_ID.test(page)) asked.set(page, (asked.get(page) ?? new Set()).add(visibility))\n }\n }\n for (const [page, visibilities] of asked) {\n // A page asked to be two things is left alone rather than guessed at.\n if (visibilities.size > 1) problems.push('A page was asked to be two things at once, so it was left as it is.')\n else pages.push({ page, visibility: [...visibilities][0] })\n }\n if (pages.length > AI_PRIVACY_MAX_PAGES) {\n pages.splice(AI_PRIVACY_MAX_PAGES)\n problems.push(`Only the first ${AI_PRIVACY_MAX_PAGES} pages were changed; ask again for the rest.`)\n }\n return {\n request: {\n maintenance: flag(inputs?.['maintenance']),\n discourageSearchEngines: flag(inputs?.['discourageSearchEngines']),\n pages,\n },\n problems,\n }\n}\n\n/** Whether a read request asks for anything at all. */\nexport function aiPrivacyRequestEmpty(request: AiPrivacyRequest): boolean {\n return request.maintenance === null && request.discourageSearchEngines === null && request.pages.length === 0\n}\n\n// ── The write ─────────────────────────────────────────────────────────────\n\nexport type AiPrivacyWrite =\n | {\n ok: true\n /** A sentence per change asked, made now or already so, by output id. */\n done: { output: keyof typeof AI_PRIVACY_OUTPUTS; said: string }[]\n /** A sentence per part that was not made, and why. */\n notDone: string[]\n changedAny: boolean\n outboxId: string | null\n }\n | { ok: false; error: string }\n\n/**\n * The changes written, in one transaction that reads the host and each named\n * page as they are stored NOW: the member still holds a write role (and is an\n * admin, for maintenance), each page exists and is a page, and only what\n * differs from what is stored is written, with a site-wide publish outbox\n * entry beside it so the live site's cached pages are dropped.\n */\nexport async function writeAiSitePrivacy(\n firestore: Firestore,\n input: { hostId: string; uid: string; request: AiPrivacyRequest; contentGating: boolean; now: Date },\n): Promise<AiPrivacyWrite> {\n const hostRef = firestore.collection('hosts').doc(input.hostId)\n const screens = hostRef.collection('screens')\n return firestore.runTransaction(async (tx): Promise<AiPrivacyWrite> => {\n const host = await tx.get(hostRef)\n if (!host.exists) return { ok: false, error: 'Unknown site' }\n if (!holdsSiteKey(host, input.uid, 'site.edit')) return { ok: false, error: AI_PRIVACY_ROLE_COPY }\n const managesSite = holdsSiteKey(host, input.uid, 'site.manage')\n const pageDocs = await Promise.all(input.request.pages.map((one) => tx.get(screens.doc(one.page))))\n\n const done: { output: keyof typeof AI_PRIVACY_OUTPUTS; said: string }[] = []\n const notDone: string[] = []\n const hostUpdates: Record<string, unknown> = {}\n const pageUpdates: { ref: FirebaseFirestore.DocumentReference; update: Record<string, unknown> }[] = []\n\n const { maintenance, discourageSearchEngines } = input.request\n if (maintenance !== null) {\n if (!managesSite) {\n notDone.push(AI_PRIVACY_ADMIN_COPY)\n } else {\n if ((host.get('maintenance') === true) !== maintenance) {\n hostUpdates['maintenance'] = maintenance || FieldValue.delete()\n }\n const assigned = !!(host.get('errorScreens') as Record<string, unknown> | undefined)?.['unavailable']\n done.push({\n output: 'maintenance',\n said: maintenance\n ? `Maintenance mode is on: every address shows ${assigned ? 'your 503 page' : `${PLATFORM_BRAND_NAME}’s plain “undergoing maintenance” notice, because no 503 page is assigned yet`} to every visitor. You and your team still see the site.`\n : 'Maintenance mode is off: the site is open to visitors again.',\n })\n }\n }\n if (discourageSearchEngines !== null) {\n const stored = (host.get('seo') as Record<string, unknown> | undefined)?.['discourageSearchEngines'] === true\n if (stored !== discourageSearchEngines) {\n hostUpdates['seo.discourageSearchEngines'] = discourageSearchEngines || FieldValue.delete()\n }\n done.push({\n output: 'search',\n said: discourageSearchEngines\n ? 'Search engines are asked not to index this site. Anyone with a link can still open it.'\n : 'Search engines may index this site again. They take days to come back.',\n })\n }\n input.request.pages.forEach((asked, index) => {\n const page = pageDocs[index]\n if (!page.exists || page.get('deletedAt') != null || page.get('kind')) {\n notDone.push('A page named is not one of this site’s pages, so it was left out.')\n return\n }\n const name = String(page.get('displayName') ?? '').trim() || 'A page'\n if (asked.visibility === 'members' && !input.contentGating) {\n // The tenant serves gated pages only on plans with content gating, so\n // writing it here would close the page to everyone.\n notDone.push(`“${name}” was not made Members only: members-only pages need the ${AI_MEMBERS_ONLY_PLAN_LABEL} plan or above.`)\n return\n }\n const value = VISIBILITY_VALUES[asked.visibility]\n const update: Record<string, unknown> = {}\n if ((page.get('visibility') ?? HostScreenVisibility.PUBLIC) !== value) update['visibility'] = value\n const hadPassword = !!(page.get('protection') as Record<string, unknown> | undefined)?.['passwordHash']\n if (hadPassword) update['protection'] = FieldValue.delete()\n if (Object.keys(update).length) pageUpdates.push({ ref: page.ref, update: { ...update, updatedAt: input.now } })\n const extra = hadPassword ? ' Its page password was removed.' : ''\n done.push({ output: 'pages', said: `“${name}” is now ${VISIBILITY_LABELS[asked.visibility]}.${extra}` })\n })\n\n const changedAny = Object.keys(hostUpdates).length > 0 || pageUpdates.length > 0\n if (!changedAny) return { ok: true, done, notDone, changedAny, outboxId: null }\n if (Object.keys(hostUpdates).length) tx.update(hostRef, { ...hostUpdates, updatedAt: input.now })\n for (const { ref, update } of pageUpdates) tx.update(ref, update)\n // Both switches change every page, and a page's visibility changes the\n // navigation and the sitemap every other page carries.\n const outboxRef = firestore.collection('publishOutbox').doc(createResourceUid())\n tx.set(outboxRef, {\n hostId: input.hostId,\n paths: [SCREEN_ROOT_PATH],\n entireHost: true,\n createdAt: FieldValue.serverTimestamp(),\n attempts: 0,\n })\n return { ok: true, done, notDone, changedAny, outboxId: outboxRef.id }\n })\n}\n\n// ── The step ──────────────────────────────────────────────────────────────\n\n/** Why this member may not change who can see this site now, or `null`. */\nexport async function aiPrivacyAccessRefusal(\n input: { host: FirebaseFirestore.DocumentSnapshot; uid: string; org: object | null; request: AiPrivacyRequest },\n deps: { lockdown?: typeof getLockdownVerdict } = {},\n): Promise<string | null> {\n if (!input.host.exists) return 'Unknown site'\n if (!holdsSiteKey(input.host, input.uid, 'site.edit')) return AI_PRIVACY_ROLE_COPY\n // A request that is ONLY maintenance has nothing a non-admin may make.\n const onlyMaintenance =\n input.request.maintenance !== null && input.request.discourageSearchEngines === null && !input.request.pages.length\n if (onlyMaintenance && !holdsSiteKey(input.host, input.uid, 'site.manage')) return AI_PRIVACY_ADMIN_COPY\n const locked = await (deps.lockdown ?? getLockdownVerdict)({\n staff: false,\n uid: input.uid,\n org: input.org as never,\n host: input.host.data() as never,\n intent: 'write',\n })\n return locked ? AI_PRIVACY_LOCKED_COPY : null\n}\n\n/** One output's note: what changed, that it is live, and what was not done. */\nexport function aiPrivacyOutputNote(said: readonly string[], where: string, notDone: readonly string[], changedAny: boolean): string {\n const did = said.length\n ? `${said.join(' ')} Live now, in ${where}.${changedAny ? '' : ' It already was, so nothing was written.'}`\n : 'Nothing needed changing.'\n const not = notDone.length ? ` Not done: ${notDone.join(' ')}` : ''\n return `${did}${not}`.slice(0, 1_000)\n}\n\nexport interface AiJobPrivacyStepDeps {\n write?: typeof writeAiSitePrivacy\n lockdown?: typeof getLockdownVerdict\n dropCache?: typeof dropPluginSiteCache\n}\n\nexport function createAiJobPrivacyStep(deps: AiJobPrivacyStepDeps = {}): AiJobStepRunner {\n const write = deps.write ?? writeAiSitePrivacy\n const dropCache = deps.dropCache ?? dropPluginSiteCache\n return async ({ job, now, firestore, org, modelFor }): Promise<AiJobStepOutcome> => {\n // No model is asked: the outcome records the edit step's at no cost.\n const model = modelFor?.('job.edit') ?? aiJobEditModel()\n const unspent = (failure: string): AiJobStepOutcome => ({ ...aiUnspentOutcome(model), failure })\n const hostId = job.hostId\n if (!hostId) return unspent(AI_PRIVACY_NO_SITE_COPY)\n const read = aiPrivacyRequestOf(job.inputs)\n if (aiPrivacyRequestEmpty(read.request)) return unspent([AI_PRIVACY_NOTHING_COPY, ...read.problems].join(' '))\n const orgData = (org ?? ((await firestore.collection('orgs').doc(job.orgId).get()).data() ?? null)) as Record<string, unknown> | null\n const host = await firestore.collection('hosts').doc(hostId).get()\n const refused = await aiPrivacyAccessRefusal({ host, uid: job.createdBy, org: orgData, request: read.request }, { lockdown: deps.lockdown })\n if (refused) return aiUnspentOutcome(model, { review: aiLimitReview(refused) })\n const written = await write(firestore, {\n hostId,\n uid: job.createdBy,\n request: read.request,\n contentGating: checkEntitlement(orgData as never, 'contentGating'),\n now,\n })\n if (written.ok === false) return unspent(written.error)\n if (written.outboxId) {\n // The live site's cached pages go now; the outbox entry stays for the\n // drain unless the drop certainly happened.\n const dropped = await dropCache({ hostIds: [hostId], reason: 'AI build changed site privacy' }).catch(() => ({ complete: false }))\n if (dropped.complete) await firestore.collection('publishOutbox').doc(written.outboxId).delete().catch(() => undefined)\n }\n const notDone = [...read.problems, ...written.notDone]\n const hostSubdomain = (typeof host.get('subdomain') === 'string' && host.get('subdomain')) || null\n const outputs: AiJobOutput[] = (Object.keys(AI_PRIVACY_OUTPUTS) as (keyof typeof AI_PRIVACY_OUTPUTS)[])\n .filter((key) => written.done.some((one) => one.output === key))\n .map((key, index) => ({\n resource: 'privacy',\n id: AI_PRIVACY_OUTPUTS[key].id,\n hostId,\n hostSubdomain,\n label: AI_PRIVACY_OUTPUTS[key].label,\n note: aiPrivacyOutputNote(\n written.done.filter((one) => one.output === key).map((one) => one.said),\n AI_PRIVACY_OUTPUTS[key].where,\n // What was not done is said once, on the first output.\n index === 0 ? notDone : [],\n written.changedAny,\n ),\n }))\n if (!outputs.length) return unspent([AI_PRIVACY_NOTHING_COPY, ...notDone].join(' '))\n return aiUnspentOutcome(model, { outputs })\n }\n}\n\nexport const runAiJobPrivacyStep = createAiJobPrivacyStep()\n\n// ── Admission ─────────────────────────────────────────────────────────────\n\nexport interface AiPrivacyJobAdmissionDeps {\n ownerOf?: typeof resolveOrgIdForHost\n lockdown?: typeof getLockdownVerdict\n}\n\n/**\n * A privacy change is admitted on a site of the job's own org, for a member\n * who may write it now, where the request names at least one change this can\n * make. Refused in those words before anything is written.\n */\nexport function createAiPrivacyJobAdmission(deps: AiPrivacyJobAdmissionDeps = {}): AiJobAdmission {\n const ownerOf = deps.ownerOf ?? resolveOrgIdForHost\n return async (context): Promise<AiJobAdmissionRefusal | null> => {\n if (!context.hostId) return { status: 400, error: AI_PRIVACY_NO_SITE_COPY }\n const owner = await ownerOf(context.hostId)\n if (!owner || owner !== context.orgId) return { status: 404, error: 'Unknown site' }\n const read = aiPrivacyRequestOf(context.inputs as Record<string, unknown>)\n if (aiPrivacyRequestEmpty(read.request)) return { status: 400, error: [AI_PRIVACY_NOTHING_COPY, ...read.problems].join(' ') }\n const host = await context.firestore.collection('hosts').doc(context.hostId).get()\n const refused = await aiPrivacyAccessRefusal(\n { host, uid: context.uid ?? '', org: context.org, request: read.request },\n { lockdown: deps.lockdown },\n )\n return refused ? { status: 403, error: refused } : null\n }\n}\n\nexport const aiPrivacyJobAdmission = createAiPrivacyJobAdmission()\n\n/** Registers the privacy step and its door (AGL-4033). */\nexport function registerAiPrivacyJob(): void {\n registerAiJobStep(AI_PRIVACY_KIND, runAiJobPrivacyStep, { minimumMs: AI_JOB_PRIVACY_STEP_MINIMUM_MS })\n registerAiJobAdmission(AI_PRIVACY_KIND, aiPrivacyJobAdmission)\n}\n"],"names":["planLabelGrantingFeature","createResourceUid","holdsSiteKey","orgPermissionLabel","aiAddonName","checkEntitlement","ENTERPRISE_PLAN_LABEL","PLATFORM_BRAND_NAME","SCREEN_ROOT_PATH","HostScreenVisibility","dropPluginSiteCache","getLockdownVerdict","resolveOrgIdForHost","FieldValue","registerAiJobAdmission","aiJobEditModel","aiLimitReview","aiUnspentOutcome","registerAiJobStep","AI_PRIVACY_KIND","AI_JOB_PRIVACY_STEP_MINIMUM_MS","AI_PRIVACY_NO_SITE_COPY","AI_PRIVACY_ROLE_COPY","AI_PRIVACY_ADMIN_COPY","AI_PRIVACY_LOCKED_COPY","AI_PRIVACY_NOTHING_COPY","AI_PRIVACY_PASSWORD_COPY","AI_MEMBERS_ONLY_PLAN_LABEL","AI_PRIVACY_MAX_PAGES","AI_PRIVACY_VISIBILITIES","VISIBILITY_VALUES","public","PUBLIC","unlisted","UNLISTED","members","AUTHENTICATED","VISIBILITY_LABELS","AI_PRIVACY_OUTPUTS","maintenance","id","label","where","search","pages","AI_PRIVACY_WHERE","AI_PRIVACY_ARGS_SCHEMA","type","properties","description","discourageSearchEngines","publicPages","items","maxLength","maxItems","unlistedPages","membersPages","additionalProperties","VISIBILITY_ARGS","flag","value","PAGE_ID","aiPrivacyRequestOf","inputs","problems","asked","Map","visibility","listed","entry","Array","isArray","page","trim","test","set","get","Set","add","visibilities","size","push","length","splice","request","aiPrivacyRequestEmpty","writeAiSitePrivacy","firestore","input","hostRef","collection","doc","hostId","screens","runTransaction","tx","host","exists","ok","error","uid","managesSite","pageDocs","Promise","all","map","one","done","notDone","hostUpdates","pageUpdates","delete","assigned","output","said","stored","forEach","index","name","String","contentGating","update","hadPassword","Object","keys","ref","updatedAt","now","extra","changedAny","outboxId","outboxRef","paths","entireHost","createdAt","serverTimestamp","attempts","aiPrivacyAccessRefusal","deps","onlyMaintenance","locked","lockdown","staff","org","data","intent","aiPrivacyOutputNote","did","join","not","slice","createAiJobPrivacyStep","write","dropCache","job","modelFor","model","unspent","failure","read","orgData","orgId","refused","createdBy","review","written","dropped","hostIds","reason","catch","complete","undefined","hostSubdomain","outputs","filter","key","some","resource","note","runAiJobPrivacyStep","createAiPrivacyJobAdmission","ownerOf","context","status","owner","aiPrivacyJobAdmission","registerAiPrivacyJob","minimumMs"],"mappings":";IA8GEA;AA9GF;;;;;;;;;;;;;;;CAeC,GAED,SAASC,iBAAiB,QAAQ,6CAA4C;AAC9E,SAASC,YAAY,QAAQ,0CAAyC;AACtE,SAASC,kBAAkB,QAAQ,yCAAwC;AAC3E,SACEC,WAAW,EACXC,gBAAgB,EAChBC,qBAAqB,EACrBN,wBAAwB,QACnB,2CAA0C;AACjD,SAASO,mBAAmB,QAAQ,wCAAuC;AAC3E,SAASC,gBAAgB,QAAQ,sCAAqC;AACtE,SAASC,oBAAoB,QAAQ,qDAAoD;AACzF,SAASC,mBAAmB,QAAQ,gDAA+C;AAEnF,SAASC,kBAAkB,QAAQ,2CAA0C;AAC7E,SAASC,mBAAmB,QAAQ,gDAA+C;AACnF,SAASC,UAAU,QAAwB,2BAA0B;AAErE,SAASC,sBAAsB,QAAyD,wBAAoB;AAC5G,SAASC,cAAc,QAAQ,wBAAoB;A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APf,IAAI,CAACA,QAAQ1F,MAAM,EAAE,OAAO;YAAE2F,QAAQ;YAAKpF,OAAO9E;QAAwB;QAC1E,MAAMmK,QAAQ,MAAMH,QAAQC,QAAQ1F,MAAM;QAC1C,IAAI,CAAC4F,SAASA,UAAUF,QAAQrB,KAAK,EAAE,OAAO;YAAEsB,QAAQ;YAAKpF,OAAO;QAAe;QACnF,MAAM4D,OAAOjG,mBAAmBwH,QAAQvH,MAAM;QAC9C,IAAIsB,sBAAsB0E,KAAK3E,OAAO,GAAG,OAAO;YAAEmG,QAAQ;YAAKpF,OAAO;gBAAC1E;mBAA4BsI,KAAK/F,QAAQ;aAAC,CAACoF,IAAI,CAAC;QAAK;QAC5H,MAAMpD,OAAO,MAAMsF,QAAQ/F,SAAS,CAACG,UAAU,CAAC,SAASC,GAAG,CAAC2F,QAAQ1F,MAAM,EAAEhB,GAAG;QAChF,MAAMsF,UAAU,MAAMzB,uBACpB;YAAEzC;YAAMI,GAAG,GAAEkF,eAAAA,QAAQlF,GAAG,YAAXkF,eAAe;YAAIvC,KAAKuC,QAAQvC,GAAG;YAAE3D,SAAS2E,KAAK3E,OAAO;QAAC,GACxE;YAAEyD,UAAUH,KAAKG,QAAQ;QAAC;QAE5B,OAAOqB,UAAU;YAAEqB,QAAQ;YAAKpF,OAAO+D;QAAQ,IAAI;IACrD;AACF;AAEA,OAAO,MAAMuB,wBAAwBL,8BAA6B;AAElE,wDAAwD,GACxD,OAAO,SAASM;IACdxK,kBAAkBC,iBAAiBgK,qBAAqB;QAAEQ,WAAWvK;IAA+B;IACpGN,uBAAuBK,iBAAiBsK;AAC1C"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/jobs/ai-job-privacy-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 { contentEditStamp, type ContentWriteActor } from '@aglyn/aglyn/app-utils/content-write-stamp'\nimport { createResourceUid } from '@aglyn/aglyn/app-utils/create-resource-uid'\nimport { holdsSiteKey } from '@aglyn/aglyn/app-utils/host-permissions'\nimport { orgPermissionLabel } from '@aglyn/aglyn/app-utils/org-permissions'\nimport {\n aiAddonName,\n checkEntitlement,\n ENTERPRISE_PLAN_LABEL,\n planLabelGrantingFeature,\n} from '@aglyn/aglyn/app-utils/plan-entitlements'\nimport { PLATFORM_BRAND_NAME } from '@aglyn/aglyn/app-utils/platform-brand'\nimport { SCREEN_ROOT_PATH } from '@aglyn/aglyn/app-utils/screen-route'\nimport { HostScreenVisibility } from '@aglyn/aglyn/foundation/definitions/platform.types'\nimport { dropPluginSiteCache } from '@aglyn/aglyn/plugin-manager/plugin-site-cache'\nimport type { PluginAiCapabilityArgsSchema } from '@aglyn/aglyn/plugin-manager/plugin-ai-capabilities'\nimport { getLockdownVerdict } from '@aglyn/tenant-data-admin/server/lockdown'\nimport { resolveOrgIdForHost } from '@aglyn/tenant-data-admin/server/organizations'\nimport { FieldValue, type Firestore } from 'firebase-admin/firestore'\nimport type { AiJobOutput } from '../model/ai-jobs.types'\nimport { registerAiJobAdmission, type AiJobAdmission, type AiJobAdmissionRefusal } from './ai-job-admission'\nimport { aiJobEditModel } from './ai-job-edit-step'\nimport { aiLimitReview, aiUnspentOutcome } from './ai-job-generation'\nimport type { AiJobStepOutcome, AiJobStepRunner } from './ai-job-text-step'\nimport { registerAiJobStep } from './ai-jobs'\n\n/**\n * The `privacy` step (AGL-4033): who can see the site, as the console's own\n * three controls set it — maintenance mode (Admin → Error pages), the\n * Discourage search engines switch (Setup → SEO) and a page's Visibility\n * (its Page Access card) — as a first-class build operation, so \"make my site\n * private until launch\" or \"hide the pricing page\" is one item on Assist's\n * plan card. The docs page it mirrors is Site Protection → Make your site\n * private.\n *\n * NO MODEL. The planner already wrote the choices as the item's arguments;\n * this checks each against the rule the console's own control holds it to and\n * writes it, so it costs no credits.\n *\n * ── Only the controls' own fields ────────────────────────────────────────\n *\n * `maintenance` (true, or deleted on the way off, as the Error pages card\n * writes it), `seo.discourageSearchEngines` (likewise, as the Search engines\n * card does), and a page's `visibility` as Public, Unlisted or Members only.\n * Leaving password mode drops the page's stored hash, as the Page Access card\n * does, so protection never lingers on a page that no longer asks for it.\n *\n * NEVER: a page password. Setting one would put the password in the chat and\n * the plan, so it is not an argument; the note sends the person to the Page\n * Access card instead. Nor layouts, emails or record templates, which have no\n * Page Access card, nor the error pages themselves.\n *\n * ── Who may ──────────────────────────────────────────────────────────────\n *\n * Search indexing and page visibility: the Firestore rules' own for those\n * keys, a member with a write role on the site (admin, editor or author)\n * while no lockdown freezes it. Maintenance mode takes every page of the site\n * offline for every visitor, so, as the console keeps its card in the Admin\n * area, only a site ADMIN may change it here. A non-admin's request still\n * makes the rest of its changes and says why that one was not made.\n *\n * Members only is made only where the plan has content gating (Business and\n * above): the tenant serves gated pages nowhere else, so on a lower plan the\n * write would close the page to everyone, and the note says why it was not.\n *\n * ── Live on confirm, idempotent ──────────────────────────────────────────\n *\n * As the `settings` and `tracking` steps: none of these has a draft, so the\n * plan card's confirm is the agreement and the write is live. One transaction\n * re-reads the host and each page, re-checks the role, writes only what\n * differs, and queues a site-wide publish outbox entry, because visibility\n * changes navigation and the sitemap and both switches change every page.\n */\n\nexport const AI_PRIVACY_KIND = 'privacy' as const\n\n/** ASSUMED: the least time the step needs — the site, the org, the pages named and one transaction. */\nexport const AI_JOB_PRIVACY_STEP_MINIMUM_MS = 5_000\n\nexport const AI_PRIVACY_NO_SITE_COPY = 'Open the site whose privacy should change.'\n/** Names \"Edit site content\" (`site.edit`, AGL-4047), never a role. */\nexport const AI_PRIVACY_ROLE_COPY = `Changing who can see the site needs the \"${orgPermissionLabel('site.edit')}\" permission on this site — ask an organization admin.`\n/** Names \"Manage site settings\" (`site.manage`, AGL-4047), never a role. */\nexport const AI_PRIVACY_ADMIN_COPY = `Turning maintenance mode on or off needs the \"${orgPermissionLabel('site.manage')}\" permission, so it was left as it is.`\nexport const AI_PRIVACY_LOCKED_COPY = 'This site is not accepting changes right now.'\nexport const AI_PRIVACY_NOTHING_COPY = 'The request named no privacy change this could make.'\nexport const AI_PRIVACY_PASSWORD_COPY =\n `To put a page behind a password, set it in that page’s Page Access card; ${aiAddonName()} never handles passwords.`\n\n/** The most pages one item may change. */\n/**\n * The cheapest plan with members-only pages (`contentGating`), read from\n * `PLAN_ENTITLEMENTS` so the copy can never name a retired plan (AGL-4158).\n */\nexport const AI_MEMBERS_ONLY_PLAN_LABEL =\n planLabelGrantingFeature('contentGating') ?? ENTERPRISE_PLAN_LABEL\n\nexport const AI_PRIVACY_MAX_PAGES = 20\n\n/** The visibilities a build may set, by the Page Access card's labels. */\nexport const AI_PRIVACY_VISIBILITIES = ['public', 'unlisted', 'members'] as const\nexport type AiPrivacyVisibility = (typeof AI_PRIVACY_VISIBILITIES)[number]\n\nconst VISIBILITY_VALUES: Readonly<Record<AiPrivacyVisibility, HostScreenVisibility>> = {\n public: HostScreenVisibility.PUBLIC,\n unlisted: HostScreenVisibility.UNLISTED,\n members: HostScreenVisibility.AUTHENTICATED,\n}\n\nconst VISIBILITY_LABELS: Readonly<Record<AiPrivacyVisibility, string>> = {\n public: 'Public',\n unlisted: 'Unlisted',\n members: 'Members only',\n}\n\n/** Where a person finds each change, as the output links and notes name it. */\nexport const AI_PRIVACY_OUTPUTS = {\n maintenance: { id: 'maintenance', label: 'Maintenance mode', where: 'Admin → Error pages' },\n search: { id: 'search', label: 'Search engines', where: 'Setup → SEO' },\n pages: { id: 'pages', label: 'Page access', where: 'each page’s Page Access card' },\n} as const\n\n/** Where the operation's changes are made, as the build's notes name it. */\nexport const AI_PRIVACY_WHERE = 'the site’s privacy settings'\n\n/** The item's arguments, as the planner fills them in. Every one optional. */\nexport const AI_PRIVACY_ARGS_SCHEMA: PluginAiCapabilityArgsSchema = {\n type: 'object',\n properties: {\n maintenance: {\n type: 'boolean',\n description:\n 'true takes the whole site offline for visitors: every address shows its 503 page to every visitor, including anyone with a link, until it is turned off, while the site team still sees the site. false brings the site back. Leave it out unless the person asked to take the whole site offline, keep it from everyone until launch, or bring it back.',\n },\n discourageSearchEngines: {\n type: 'boolean',\n description:\n 'true asks search engines not to index any page of the site (it stays open to anyone with a link); false lets them index it again. Leave it out unless the person asked about search engines or Google.',\n },\n publicPages: {\n type: 'array',\n description: 'Pages to make Public: anyone can open them, and they are offered to search engines. Each by its id from the site inventory.',\n items: { type: 'string', maxLength: 64 },\n maxItems: AI_PRIVACY_MAX_PAGES,\n },\n unlistedPages: {\n type: 'array',\n description: 'Pages to make Unlisted: anyone with the link can open them, kept out of search results, the sitemap and navigation. Each by its id from the site inventory.',\n items: { type: 'string', maxLength: 64 },\n maxItems: AI_PRIVACY_MAX_PAGES,\n },\n membersPages: {\n type: 'array',\n description: `Pages to make Members only: only visitors signed in to the site can open them (the ${AI_MEMBERS_ONLY_PLAN_LABEL} plan and above). Each by its id from the site inventory.`,\n items: { type: 'string', maxLength: 64 },\n maxItems: AI_PRIVACY_MAX_PAGES,\n },\n },\n additionalProperties: false,\n}\n\n/** Each visibility's argument, as the planner lists the pages for it. */\nconst VISIBILITY_ARGS: Readonly<Record<AiPrivacyVisibility, string>> = {\n public: 'publicPages',\n unlisted: 'unlistedPages',\n members: 'membersPages',\n}\n\n/** What an item asks: each switch to set, and each page's new visibility. */\nexport interface AiPrivacyRequest {\n maintenance: boolean | null\n discourageSearchEngines: boolean | null\n pages: { page: string; visibility: AiPrivacyVisibility }[]\n}\n\nexport interface AiPrivacyRead {\n request: AiPrivacyRequest\n /** A sentence per value that could not be used, so the rest still are. */\n problems: string[]\n}\n\nconst flag = (value: unknown): boolean | null => (typeof value === 'boolean' ? value : null)\n\n/** A page id as the site inventory gives it: one document id, never a path. */\nconst PAGE_ID = /^[A-Za-z0-9_-]{1,64}$/\n\n/** The item's arguments read: what may be written, and a sentence for each that may not. */\nexport function aiPrivacyRequestOf(inputs: Readonly<Record<string, unknown>> | null | undefined): AiPrivacyRead {\n const problems: string[] = []\n const pages: AiPrivacyRequest['pages'] = []\n const asked = new Map<string, Set<AiPrivacyVisibility>>()\n for (const visibility of AI_PRIVACY_VISIBILITIES) {\n const listed = inputs?.[VISIBILITY_ARGS[visibility]]\n for (const entry of Array.isArray(listed) ? listed : []) {\n const page = typeof entry === 'string' ? entry.trim() : ''\n if (PAGE_ID.test(page)) asked.set(page, (asked.get(page) ?? new Set()).add(visibility))\n }\n }\n for (const [page, visibilities] of asked) {\n // A page asked to be two things is left alone rather than guessed at.\n if (visibilities.size > 1) problems.push('A page was asked to be two things at once, so it was left as it is.')\n else pages.push({ page, visibility: [...visibilities][0] })\n }\n if (pages.length > AI_PRIVACY_MAX_PAGES) {\n pages.splice(AI_PRIVACY_MAX_PAGES)\n problems.push(`Only the first ${AI_PRIVACY_MAX_PAGES} pages were changed; ask again for the rest.`)\n }\n return {\n request: {\n maintenance: flag(inputs?.['maintenance']),\n discourageSearchEngines: flag(inputs?.['discourageSearchEngines']),\n pages,\n },\n problems,\n }\n}\n\n/** Whether a read request asks for anything at all. */\nexport function aiPrivacyRequestEmpty(request: AiPrivacyRequest): boolean {\n return request.maintenance === null && request.discourageSearchEngines === null && request.pages.length === 0\n}\n\n// ── The write ─────────────────────────────────────────────────────────────\n\nexport type AiPrivacyWrite =\n | {\n ok: true\n /** A sentence per change asked, made now or already so, by output id. */\n done: { output: keyof typeof AI_PRIVACY_OUTPUTS; said: string }[]\n /** A sentence per part that was not made, and why. */\n notDone: string[]\n changedAny: boolean\n outboxId: string | null\n }\n | { ok: false; error: string }\n\n/**\n * The changes written, in one transaction that reads the host and each named\n * page as they are stored NOW: the member still holds a write role (and is an\n * admin, for maintenance), each page exists and is a page, and only what\n * differs from what is stored is written, with a site-wide publish outbox\n * entry beside it so the live site's cached pages are dropped.\n */\nexport async function writeAiSitePrivacy(\n firestore: Firestore,\n input: { hostId: string; uid: string; actor: ContentWriteActor; request: AiPrivacyRequest; contentGating: boolean; now: Date },\n): Promise<AiPrivacyWrite> {\n const hostRef = firestore.collection('hosts').doc(input.hostId)\n const screens = hostRef.collection('screens')\n return firestore.runTransaction(async (tx): Promise<AiPrivacyWrite> => {\n const host = await tx.get(hostRef)\n if (!host.exists) return { ok: false, error: 'Unknown site' }\n if (!holdsSiteKey(host, input.uid, 'site.edit')) return { ok: false, error: AI_PRIVACY_ROLE_COPY }\n const managesSite = holdsSiteKey(host, input.uid, 'site.manage')\n const pageDocs = await Promise.all(input.request.pages.map((one) => tx.get(screens.doc(one.page))))\n\n const done: { output: keyof typeof AI_PRIVACY_OUTPUTS; said: string }[] = []\n const notDone: string[] = []\n const hostUpdates: Record<string, unknown> = {}\n const pageUpdates: { ref: FirebaseFirestore.DocumentReference; update: Record<string, unknown> }[] = []\n\n const { maintenance, discourageSearchEngines } = input.request\n if (maintenance !== null) {\n if (!managesSite) {\n notDone.push(AI_PRIVACY_ADMIN_COPY)\n } else {\n if ((host.get('maintenance') === true) !== maintenance) {\n hostUpdates['maintenance'] = maintenance || FieldValue.delete()\n }\n const assigned = !!(host.get('errorScreens') as Record<string, unknown> | undefined)?.['unavailable']\n done.push({\n output: 'maintenance',\n said: maintenance\n ? `Maintenance mode is on: every address shows ${assigned ? 'your 503 page' : `${PLATFORM_BRAND_NAME}’s plain “undergoing maintenance” notice, because no 503 page is assigned yet`} to every visitor. You and your team still see the site.`\n : 'Maintenance mode is off: the site is open to visitors again.',\n })\n }\n }\n if (discourageSearchEngines !== null) {\n const stored = (host.get('seo') as Record<string, unknown> | undefined)?.['discourageSearchEngines'] === true\n if (stored !== discourageSearchEngines) {\n hostUpdates['seo.discourageSearchEngines'] = discourageSearchEngines || FieldValue.delete()\n }\n done.push({\n output: 'search',\n said: discourageSearchEngines\n ? 'Search engines are asked not to index this site. Anyone with a link can still open it.'\n : 'Search engines may index this site again. They take days to come back.',\n })\n }\n input.request.pages.forEach((asked, index) => {\n const page = pageDocs[index]\n if (!page.exists || page.get('deletedAt') != null || page.get('kind')) {\n notDone.push('A page named is not one of this site’s pages, so it was left out.')\n return\n }\n const name = String(page.get('displayName') ?? '').trim() || 'A page'\n if (asked.visibility === 'members' && !input.contentGating) {\n // The tenant serves gated pages only on plans with content gating, so\n // writing it here would close the page to everyone.\n notDone.push(`“${name}” was not made Members only: members-only pages need the ${AI_MEMBERS_ONLY_PLAN_LABEL} plan or above.`)\n return\n }\n const value = VISIBILITY_VALUES[asked.visibility]\n const update: Record<string, unknown> = {}\n if ((page.get('visibility') ?? HostScreenVisibility.PUBLIC) !== value) update['visibility'] = value\n const hadPassword = !!(page.get('protection') as Record<string, unknown> | undefined)?.['passwordHash']\n if (hadPassword) update['protection'] = FieldValue.delete()\n if (Object.keys(update).length) pageUpdates.push({ ref: page.ref, update: { ...update, ...contentEditStamp(input.actor, input.now) } })\n const extra = hadPassword ? ' Its page password was removed.' : ''\n done.push({ output: 'pages', said: `“${name}” is now ${VISIBILITY_LABELS[asked.visibility]}.${extra}` })\n })\n\n const changedAny = Object.keys(hostUpdates).length > 0 || pageUpdates.length > 0\n if (!changedAny) return { ok: true, done, notDone, changedAny, outboxId: null }\n if (Object.keys(hostUpdates).length) tx.update(hostRef, { ...hostUpdates, updatedAt: input.now })\n for (const { ref, update } of pageUpdates) tx.update(ref, update)\n // Both switches change every page, and a page's visibility changes the\n // navigation and the sitemap every other page carries.\n const outboxRef = firestore.collection('publishOutbox').doc(createResourceUid())\n tx.set(outboxRef, {\n hostId: input.hostId,\n paths: [SCREEN_ROOT_PATH],\n entireHost: true,\n createdAt: FieldValue.serverTimestamp(),\n attempts: 0,\n })\n return { ok: true, done, notDone, changedAny, outboxId: outboxRef.id }\n })\n}\n\n// ── The step ──────────────────────────────────────────────────────────────\n\n/** Why this member may not change who can see this site now, or `null`. */\nexport async function aiPrivacyAccessRefusal(\n input: { host: FirebaseFirestore.DocumentSnapshot; uid: string; org: object | null; request: AiPrivacyRequest },\n deps: { lockdown?: typeof getLockdownVerdict } = {},\n): Promise<string | null> {\n if (!input.host.exists) return 'Unknown site'\n if (!holdsSiteKey(input.host, input.uid, 'site.edit')) return AI_PRIVACY_ROLE_COPY\n // A request that is ONLY maintenance has nothing a non-admin may make.\n const onlyMaintenance =\n input.request.maintenance !== null && input.request.discourageSearchEngines === null && !input.request.pages.length\n if (onlyMaintenance && !holdsSiteKey(input.host, input.uid, 'site.manage')) return AI_PRIVACY_ADMIN_COPY\n const locked = await (deps.lockdown ?? getLockdownVerdict)({\n staff: false,\n uid: input.uid,\n org: input.org as never,\n host: input.host.data() as never,\n intent: 'write',\n })\n return locked ? AI_PRIVACY_LOCKED_COPY : null\n}\n\n/** One output's note: what changed, that it is live, and what was not done. */\nexport function aiPrivacyOutputNote(said: readonly string[], where: string, notDone: readonly string[], changedAny: boolean): string {\n const did = said.length\n ? `${said.join(' ')} Live now, in ${where}.${changedAny ? '' : ' It already was, so nothing was written.'}`\n : 'Nothing needed changing.'\n const not = notDone.length ? ` Not done: ${notDone.join(' ')}` : ''\n return `${did}${not}`.slice(0, 1_000)\n}\n\nexport interface AiJobPrivacyStepDeps {\n write?: typeof writeAiSitePrivacy\n lockdown?: typeof getLockdownVerdict\n dropCache?: typeof dropPluginSiteCache\n}\n\nexport function createAiJobPrivacyStep(deps: AiJobPrivacyStepDeps = {}): AiJobStepRunner {\n const write = deps.write ?? writeAiSitePrivacy\n const dropCache = deps.dropCache ?? dropPluginSiteCache\n return async ({ job, now, firestore, org, modelFor }): Promise<AiJobStepOutcome> => {\n // No model is asked: the outcome records the edit step's at no cost.\n const model = modelFor?.('job.edit') ?? aiJobEditModel()\n const unspent = (failure: string): AiJobStepOutcome => ({ ...aiUnspentOutcome(model), failure })\n const hostId = job.hostId\n if (!hostId) return unspent(AI_PRIVACY_NO_SITE_COPY)\n const read = aiPrivacyRequestOf(job.inputs)\n if (aiPrivacyRequestEmpty(read.request)) return unspent([AI_PRIVACY_NOTHING_COPY, ...read.problems].join(' '))\n const orgData = (org ?? ((await firestore.collection('orgs').doc(job.orgId).get()).data() ?? null)) as Record<string, unknown> | null\n const host = await firestore.collection('hosts').doc(hostId).get()\n const refused = await aiPrivacyAccessRefusal({ host, uid: job.createdBy, org: orgData, request: read.request }, { lockdown: deps.lockdown })\n if (refused) return aiUnspentOutcome(model, { review: aiLimitReview(refused) })\n const written = await write(firestore, {\n hostId,\n uid: job.createdBy,\n actor: { uid: job.createdBy, via: `ai-job:${job.$id}` },\n request: read.request,\n contentGating: checkEntitlement(orgData as never, 'contentGating'),\n now,\n })\n if (written.ok === false) return unspent(written.error)\n if (written.outboxId) {\n // The live site's cached pages go now; the outbox entry stays for the\n // drain unless the drop certainly happened.\n const dropped = await dropCache({ hostIds: [hostId], reason: 'AI build changed site privacy' }).catch(() => ({ complete: false }))\n if (dropped.complete) await firestore.collection('publishOutbox').doc(written.outboxId).delete().catch(() => undefined)\n }\n const notDone = [...read.problems, ...written.notDone]\n const hostSubdomain = (typeof host.get('subdomain') === 'string' && host.get('subdomain')) || null\n const outputs: AiJobOutput[] = (Object.keys(AI_PRIVACY_OUTPUTS) as (keyof typeof AI_PRIVACY_OUTPUTS)[])\n .filter((key) => written.done.some((one) => one.output === key))\n .map((key, index) => ({\n resource: 'privacy',\n id: AI_PRIVACY_OUTPUTS[key].id,\n hostId,\n hostSubdomain,\n label: AI_PRIVACY_OUTPUTS[key].label,\n note: aiPrivacyOutputNote(\n written.done.filter((one) => one.output === key).map((one) => one.said),\n AI_PRIVACY_OUTPUTS[key].where,\n // What was not done is said once, on the first output.\n index === 0 ? notDone : [],\n written.changedAny,\n ),\n }))\n if (!outputs.length) return unspent([AI_PRIVACY_NOTHING_COPY, ...notDone].join(' '))\n return aiUnspentOutcome(model, { outputs })\n }\n}\n\nexport const runAiJobPrivacyStep = createAiJobPrivacyStep()\n\n// ── Admission ─────────────────────────────────────────────────────────────\n\nexport interface AiPrivacyJobAdmissionDeps {\n ownerOf?: typeof resolveOrgIdForHost\n lockdown?: typeof getLockdownVerdict\n}\n\n/**\n * A privacy change is admitted on a site of the job's own org, for a member\n * who may write it now, where the request names at least one change this can\n * make. Refused in those words before anything is written.\n */\nexport function createAiPrivacyJobAdmission(deps: AiPrivacyJobAdmissionDeps = {}): AiJobAdmission {\n const ownerOf = deps.ownerOf ?? resolveOrgIdForHost\n return async (context): Promise<AiJobAdmissionRefusal | null> => {\n if (!context.hostId) return { status: 400, error: AI_PRIVACY_NO_SITE_COPY }\n const owner = await ownerOf(context.hostId)\n if (!owner || owner !== context.orgId) return { status: 404, error: 'Unknown site' }\n const read = aiPrivacyRequestOf(context.inputs as Record<string, unknown>)\n if (aiPrivacyRequestEmpty(read.request)) return { status: 400, error: [AI_PRIVACY_NOTHING_COPY, ...read.problems].join(' ') }\n const host = await context.firestore.collection('hosts').doc(context.hostId).get()\n const refused = await aiPrivacyAccessRefusal(\n { host, uid: context.uid ?? '', org: context.org, request: read.request },\n { lockdown: deps.lockdown },\n )\n return refused ? { status: 403, error: refused } : null\n }\n}\n\nexport const aiPrivacyJobAdmission = createAiPrivacyJobAdmission()\n\n/** Registers the privacy step and its door (AGL-4033). */\nexport function registerAiPrivacyJob(): void {\n registerAiJobStep(AI_PRIVACY_KIND, runAiJobPrivacyStep, { minimumMs: AI_JOB_PRIVACY_STEP_MINIMUM_MS })\n registerAiJobAdmission(AI_PRIVACY_KIND, aiPrivacyJobAdmission)\n}\n"],"names":["planLabelGrantingFeature","contentEditStamp","createResourceUid","holdsSiteKey","orgPermissionLabel","aiAddonName","checkEntitlement","ENTERPRISE_PLAN_LABEL","PLATFORM_BRAND_NAME","SCREEN_ROOT_PATH","HostScreenVisibility","dropPluginSiteCache","getLockdownVerdict","resolveOrgIdForHost","FieldValue","registerAiJobAdmission","aiJobEditModel","aiLimitReview","aiUnspentOutcome","registerAiJobStep","AI_PRIVACY_KIND","AI_JOB_PRIVACY_STEP_MINIMUM_MS","AI_PRIVACY_NO_SITE_COPY","AI_PRIVACY_ROLE_COPY","AI_PRIVACY_ADMIN_COPY","AI_PRIVACY_LOCKED_COPY","AI_PRIVACY_NOTHING_COPY","AI_PRIVACY_PASSWORD_COPY","AI_MEMBERS_ONLY_PLAN_LABEL","AI_PRIVACY_MAX_PAGES","AI_PRIVACY_VISIBILITIES","VISIBILITY_VALUES","public","PUBLIC","unlisted","UNLISTED","members","AUTHENTICATED","VISIBILITY_LABELS","AI_PRIVACY_OUTPUTS","maintenance","id","label","where","search","pages","AI_PRIVACY_WHERE","AI_PRIVACY_ARGS_SCHEMA","type","properties","description","discourageSearchEngines","publicPages","items","maxLength","maxItems","unlistedPages","membersPages","additionalProperties","VISIBILITY_ARGS","flag","value","PAGE_ID","aiPrivacyRequestOf","inputs","problems","asked","Map","visibility","listed","entry","Array","isArray","page","trim","test","set","get","Set","add","visibilities","size","push","length","splice","request","aiPrivacyRequestEmpty","writeAiSitePrivacy","firestore","input","hostRef","collection","doc","hostId","screens","runTransaction","tx","host","exists","ok","error","uid","managesSite","pageDocs","Promise","all","map","one","done","notDone","hostUpdates","pageUpdates","delete","assigned","output","said","stored","forEach","index","name","String","contentGating","update","hadPassword","Object","keys","ref","actor","now","extra","changedAny","outboxId","updatedAt","outboxRef","paths","entireHost","createdAt","serverTimestamp","attempts","aiPrivacyAccessRefusal","deps","onlyMaintenance","locked","lockdown","staff","org","data","intent","aiPrivacyOutputNote","did","join","not","slice","createAiJobPrivacyStep","write","dropCache","job","modelFor","model","unspent","failure","read","orgData","orgId","refused","createdBy","review","written","via","$id","dropped","hostIds","reason","catch","complete","undefined","hostSubdomain","outputs","filter","key","some","resource","note","runAiJobPrivacyStep","createAiPrivacyJobAdmission","ownerOf","context","status","owner","aiPrivacyJobAdmission","registerAiPrivacyJob","minimumMs"],"mappings":";IA+GEA;AA/GF;;;;;;;;;;;;;;;CAe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G;QAChF,MAAMuF,UAAU,MAAMzB,uBACpB;YAAE1C;YAAMI,GAAG,GAAEqF,eAAAA,QAAQrF,GAAG,YAAXqF,eAAe;YAAIzC,KAAKyC,QAAQzC,GAAG;YAAE5D,SAAS4E,KAAK5E,OAAO;QAAC,GACxE;YAAE0D,UAAUH,KAAKG,QAAQ;QAAC;QAE5B,OAAOqB,UAAU;YAAEuB,QAAQ;YAAKvF,OAAOgE;QAAQ,IAAI;IACrD;AACF;AAEA,OAAO,MAAMyB,wBAAwBL,8BAA6B;AAElE,wDAAwD,GACxD,OAAO,SAASM;IACd3K,kBAAkBC,iBAAiBmK,qBAAqB;QAAEQ,WAAW1K;IAA+B;IACpGN,uBAAuBK,iBAAiByK;AAC1C"}
|
|
@@ -22,7 +22,7 @@ import { FieldValue } from "firebase-admin/firestore";
|
|
|
22
22
|
import { aiStorePageNodes, aiStorePagesToWrite, AI_STORE_PAGES } from "../model/ai-site-store-pages.js";
|
|
23
23
|
import { aiModelForStep } from "../providers/routing.js";
|
|
24
24
|
import { aiOriginJobId } from "./ai-job-draft-ids.js";
|
|
25
|
-
import { writeAiDraft, writeAiDraftScreenSeo } from "./ai-job-drafts.js";
|
|
25
|
+
import { aiJobContentActor, writeAiDraft, writeAiDraftScreenSeo } from "./ai-job-drafts.js";
|
|
26
26
|
import { aiUnspentOutcome } from "./ai-job-generation.js";
|
|
27
27
|
import { aiPluginDraftAdmissionRefusal } from "./ai-job-plugin-drafts.js";
|
|
28
28
|
/**
|
|
@@ -120,6 +120,7 @@ function inputOf(job) {
|
|
|
120
120
|
hostId,
|
|
121
121
|
id,
|
|
122
122
|
uid: job.createdBy,
|
|
123
|
+
actor: aiJobContentActor(job),
|
|
123
124
|
org: (_context_org = context.org) != null ? _context_org : null,
|
|
124
125
|
name: definition.title,
|
|
125
126
|
slug: page.slug,
|
|
@@ -140,6 +141,7 @@ function inputOf(job) {
|
|
|
140
141
|
hostId,
|
|
141
142
|
id,
|
|
142
143
|
seo: definition.seo,
|
|
144
|
+
actor: aiJobContentActor(job),
|
|
143
145
|
now
|
|
144
146
|
});
|
|
145
147
|
outputs.push({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/jobs/ai-job-site-store-pages.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 { checkEntitlement } from '@aglyn/aglyn/app-utils/plan-entitlements'\nimport { holdsSiteKey, siteKeyRefusal } from '@aglyn/aglyn/app-utils/host-permissions'\nimport { ACCOUNTS_PLUGIN_ID } from '@aglyn/aglyn/plugin-manager/enabled-plugins'\nimport { HostScreenVisibility } from '@aglyn/aglyn/foundation/definitions/platform.types'\nimport type { NodesMap } from '@aglyn/aglyn/types/nodes'\nimport { FieldValue } from 'firebase-admin/firestore'\nimport type { AiJob, AiJobOutput } from '../model/ai-jobs.types'\nimport {\n aiStorePageNodes,\n aiStorePagesToWrite,\n AI_STORE_PAGES,\n type AiStorePageFacts,\n type AiStorePagePlan,\n} from '../model/ai-site-store-pages'\nimport { aiModelForStep } from '../providers/routing'\nimport { aiOriginJobId } from './ai-job-draft-ids'\nimport { writeAiDraft, writeAiDraftScreenSeo } from './ai-job-drafts'\nimport { aiUnspentOutcome } from './ai-job-generation'\nimport { aiPluginDraftAdmissionRefusal } from './ai-job-plugin-drafts'\nimport type { AiJobStepContext, AiJobStepOutcome, AiJobStepRunner } from './ai-job-text-step'\n\n/**\n * The store pages' unit of a site start (AGL-3676): the account, cart and\n * policy pages a paid store gets beside its planned pages\n * (`model/ai-site-store-pages.ts`), written by code in one pass that asks no\n * model and costs no credits.\n *\n * Each page is a draft written through the same writer, under the same pages\n * allowance, as every page the start builds (`writeAiDraft`), under an id\n * derived from the unit's job, so a pass run again finds its own drafts. The\n * guided start's publish then puts them live with the rest.\n *\n * The site's user accounts are turned on here too: the Customer account's\n * sign-in, and the platform's /signin and /signup, answer only where the site\n * serves accounts (`accounts` is off by default on a site that predates\n * 2026-08; every new site is born with it). A site whose owner switched them\n * off keeps them off: an explicit deny is theirs.\n */\n\n/** The unit input a store pages unit carries what it writes in. */\nexport const AI_SITE_STORE_PAGES_INPUT = 'storePages'\n\n/** What a store pages unit is told: the store pages the plan implies, and what their words link. */\nexport interface AiSiteStorePagesInput {\n pages: AiStorePagePlan[]\n facts: AiStorePageFacts\n /** The layout the start built, which the pages render inside; the site's otherwise. */\n layoutId: string | null\n}\n\n/** The commerce plugin's name, in the refusal that asks for it. */\nconst STORE_LABEL = 'Commerce'\n\n/** What a store pages row says where nothing could be written: our failure. */\nexport const AI_SITE_STORE_PAGES_NOT_WRITTEN_COPY = 'Your account, cart and policy pages could not be added this time.'\n\n/** The id of the store page a unit writes for `key`. */\nexport function aiSiteStorePageId(unitJobId: string, key: string): string {\n return `${unitJobId}-${key}`\n}\n\nconst PATH = /^\\/[a-z0-9-]*$/\n\nfunction inputOf(job: Pick<AiJob, 'inputs'>): AiSiteStorePagesInput | null {\n const raw = job.inputs?.[AI_SITE_STORE_PAGES_INPUT] as Partial<AiSiteStorePagesInput> | undefined\n if (!raw || !Array.isArray(raw.pages) || !raw.facts) return null\n const keys = new Set(AI_STORE_PAGES.map((page) => page.key))\n const pages = raw.pages.filter((page) => page && keys.has(page.key) && typeof page.slug === 'string')\n const path = (value: unknown, fallback: string) => (typeof value === 'string' && PATH.test(value) ? value : fallback)\n return {\n pages,\n facts: {\n contactPath: raw.facts.contactPath ? path(raw.facts.contactPath, '') || null : null,\n shopPath: path(raw.facts.shopPath, '/shop'),\n shippingPath: path(raw.facts.shippingPath, '/shipping-returns'),\n },\n layoutId: typeof raw.layoutId === 'string' && raw.layoutId ? raw.layoutId : null,\n }\n}\n\n/**\n * Whether the store pages may be added for this member on this site, asked\n * before their pass so a refusal spends nothing; `null` admits. The plan must\n * include a store (Starter and up), the commerce plugin must run here, and the\n * member must be able to edit the site's pages.\n */\nexport async function aiSiteStorePagesRefusal(\n context: Pick<AiJobStepContext, 'firestore' | 'org' | 'now'> & { job: Pick<AiJob, 'orgId' | 'hostId' | 'createdBy'> },\n deps: { admission?: typeof aiPluginDraftAdmissionRefusal } = {},\n): Promise<string | null> {\n const { job, firestore } = context\n if (!job.hostId) return 'Open the site first.'\n if (!checkEntitlement((context.org ?? null) as never, 'commerce')) return 'Your plan does not include a store.'\n const refused = await (deps.admission ?? aiPluginDraftAdmissionRefusal)(\n { firestore, orgId: job.orgId, hostId: job.hostId, inputs: {}, org: context.org ?? null },\n { kind: 'site', drafts: [{ resource: 'product', label: STORE_LABEL }], now: context.now },\n )\n if (refused) return refused.error\n const host = await firestore.collection('hosts').doc(job.hostId).get()\n return holdsSiteKey(host, job.createdBy, 'site.edit') ? null : siteKeyRefusal('site.edit')\n}\n\nexport interface AiSiteStorePagesRunnerDeps {\n write?: typeof writeAiDraft\n writeSeo?: typeof writeAiDraftScreenSeo\n}\n\n/** The store pages' pass: every page written, user accounts on, one output a page. */\nexport function createAiSiteStorePagesRunner(deps: AiSiteStorePagesRunnerDeps = {}): AiJobStepRunner {\n const write = deps.write ?? writeAiDraft\n const writeSeo = deps.writeSeo ?? writeAiDraftScreenSeo\n return async (context): Promise<AiJobStepOutcome> => {\n const { job, firestore, now } = context\n const model = context.modelFor?.('job.plan') ?? aiModelForStep('job.plan')\n const input = inputOf(job)\n const hostId = job.hostId\n if (!input || !hostId) return { ...aiUnspentOutcome(model), failure: AI_SITE_STORE_PAGES_NOT_WRITTEN_COPY }\n const outputs: AiJobOutput[] = []\n let refusal: string | null = null\n for (const page of aiStorePagesToWrite(input.pages)) {\n const definition = AI_STORE_PAGES.find((one) => one.key === page.key)\n if (!definition) continue\n const id = aiSiteStorePageId(job.$id, page.key)\n const draft = await write(firestore, {\n kind: 'screen',\n hostId,\n id,\n uid: job.createdBy,\n org: context.org ?? null,\n name: definition.title,\n slug: page.slug,\n nodes: aiStorePageNodes(page.key, input.facts) as unknown as NodesMap,\n layoutId: input.layoutId,\n // The account and the cart are a shopper's own pages: unlisted, noindex (AGL-3676).\n ...(definition.noindex ? { visibility: HostScreenVisibility.UNLISTED } : {}),\n aiJobId: aiOriginJobId(job),\n now,\n })\n if (draft.ok === false) {\n // The pages allowance is full, or the site is gone: what was written stays.\n refusal = draft.error\n break\n }\n await writeSeo(firestore, { hostId, id, seo: definition.seo, now })\n outputs.push({\n resource: 'screen',\n id,\n versionId: draft.versionId,\n hostId,\n hostSubdomain: draft.hostSubdomain,\n label: draft.name,\n proposal: { storePage: page.key, path: page.href },\n })\n }\n if (outputs.length) await turnOnSiteAccounts(firestore, hostId, now)\n if (!outputs.length) {\n return refusal\n ? aiUnspentOutcome(model, { review: { reason: 'limit', message: refusal, findings: [] } })\n : { ...aiUnspentOutcome(model), failure: AI_SITE_STORE_PAGES_NOT_WRITTEN_COPY }\n }\n return aiUnspentOutcome(model, { outputs })\n }\n}\n\nexport const runAiSiteStorePagesUnit = createAiSiteStorePagesRunner()\n\n/**\n * Turns on the site's user accounts (`accounts`, default-off per site), so\n * the account page's sign-in and the platform's /signin and /signup answer.\n * An owner's explicit switch-off is left as it is.\n */\nexport async function turnOnSiteAccounts(firestore: FirebaseFirestore.Firestore, hostId: string, now: Date): Promise<boolean> {\n const hostRef = firestore.collection('hosts').doc(hostId)\n const host = await hostRef.get()\n if (!host.exists) return false\n const disabled = (host.get('disabledPlugins') ?? []) as unknown[]\n const enabled = (host.get('enabledPlugins') ?? []) as unknown[]\n if (disabled.includes(ACCOUNTS_PLUGIN_ID) || enabled.includes(ACCOUNTS_PLUGIN_ID)) return false\n await hostRef.update({ enabledPlugins: FieldValue.arrayUnion(ACCOUNTS_PLUGIN_ID), updatedAt: now })\n return true\n}\n"],"names":["checkEntitlement","holdsSiteKey","siteKeyRefusal","ACCOUNTS_PLUGIN_ID","HostScreenVisibility","FieldValue","aiStorePageNodes","aiStorePagesToWrite","AI_STORE_PAGES","aiModelForStep","aiOriginJobId","writeAiDraft","writeAiDraftScreenSeo","aiUnspentOutcome","aiPluginDraftAdmissionRefusal","AI_SITE_STORE_PAGES_INPUT","STORE_LABEL","AI_SITE_STORE_PAGES_NOT_WRITTEN_COPY","aiSiteStorePageId","unitJobId","key","PATH","inputOf","job","raw","inputs","Array","isArray","pages","facts","keys","Set","map","page","filter","has","slug","path","value","fallback","test","contactPath","shopPath","shippingPath","layoutId","aiSiteStorePagesRefusal","context","deps","firestore","hostId","org","refused","admission","orgId","kind","drafts","resource","label","now","error","host","collection","doc","get","createdBy","createAiSiteStorePagesRunner","write","writeSeo","model","modelFor","input","failure","outputs","refusal","definition","find","one","id","$id","draft","uid","name","title","nodes","noindex","visibility","UNLISTED","aiJobId","ok","seo","push","versionId","hostSubdomain","proposal","storePage","href","length","turnOnSiteAccounts","review","reason","message","findings","runAiSiteStorePagesUnit","hostRef","exists","disabled","enabled","includes","update","enabledPlugins","arrayUnion","updatedAt"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,gBAAgB,QAAQ,2CAA0C;AAC3E,SAASC,YAAY,EAAEC,cAAc,QAAQ,0CAAyC;AACtF,SAASC,kBAAkB,QAAQ,8CAA6C;AAChF,SAASC,oBAAoB,QAAQ,qDAAoD;AAEzF,SAASC,UAAU,QAAQ,2BAA0B;AAErD,SACEC,gBAAgB,EAChBC,mBAAmB,EACnBC,cAAc,QAGT,kCAA8B;AACrC,SAASC,cAAc,QAAQ,0BAAsB;AACrD,SAASC,aAAa,QAAQ,wBAAoB;AAClD,SAASC,YAAY,EAAEC,qBAAqB,QAAQ,qBAAiB;AACrE,SAASC,gBAAgB,QAAQ,yBAAqB;AACtD,SAASC,6BAA6B,QAAQ,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AW7D,KAAKb,GAAG;oBAAEiB,MAAMJ,KAAK8D,IAAI;gBAAC;YACnD;QACF;QACA,IAAIvB,QAAQwB,MAAM,EAAE,MAAMC,mBAAmBjD,WAAWC,QAAQS;QAChE,IAAI,CAACc,QAAQwB,MAAM,EAAE;YACnB,OAAOvB,UACH5D,iBAAiBuD,OAAO;gBAAE8B,QAAQ;oBAAEC,QAAQ;oBAASC,SAAS3B;oBAAS4B,UAAU,EAAE;gBAAC;YAAE,KACtF,aAAKxF,iBAAiBuD;gBAAQG,SAAStD;;QAC7C;QACA,OAAOJ,iBAAiBuD,OAAO;YAAEI;QAAQ;IAC3C;AACF;AAEA,OAAO,MAAM8B,0BAA0BrC,+BAA8B;AAErE;;;;CAIC,GACD,OAAO,eAAegC,mBAAmBjD,SAAsC,EAAEC,MAAc,EAAES,GAAS;QAItFE,WACDA;IAJjB,MAAM2C,UAAUvD,UAAUa,UAAU,CAAC,SAASC,GAAG,CAACb;IAClD,MAAMW,OAAO,MAAM2C,QAAQxC,GAAG;IAC9B,IAAI,CAACH,KAAK4C,MAAM,EAAE,OAAO;IACzB,MAAMC,YAAY7C,YAAAA,KAAKG,GAAG,CAAC,8BAATH,YAA+B,EAAE;IACnD,MAAM8C,WAAW9C,aAAAA,KAAKG,GAAG,CAAC,6BAATH,aAA8B,EAAE;IACjD,IAAI6C,SAASE,QAAQ,CAACxG,uBAAuBuG,QAAQC,QAAQ,CAACxG,qBAAqB,OAAO;IAC1F,MAAMoG,QAAQK,MAAM,CAAC;QAAEC,gBAAgBxG,WAAWyG,UAAU,CAAC3G;QAAqB4G,WAAWrD;IAAI;IACjG,OAAO;AACT"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/jobs/ai-job-site-store-pages.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 { checkEntitlement } from '@aglyn/aglyn/app-utils/plan-entitlements'\nimport { holdsSiteKey, siteKeyRefusal } from '@aglyn/aglyn/app-utils/host-permissions'\nimport { ACCOUNTS_PLUGIN_ID } from '@aglyn/aglyn/plugin-manager/enabled-plugins'\nimport { HostScreenVisibility } from '@aglyn/aglyn/foundation/definitions/platform.types'\nimport type { NodesMap } from '@aglyn/aglyn/types/nodes'\nimport { FieldValue } from 'firebase-admin/firestore'\nimport type { AiJob, AiJobOutput } from '../model/ai-jobs.types'\nimport {\n aiStorePageNodes,\n aiStorePagesToWrite,\n AI_STORE_PAGES,\n type AiStorePageFacts,\n type AiStorePagePlan,\n} from '../model/ai-site-store-pages'\nimport { aiModelForStep } from '../providers/routing'\nimport { aiOriginJobId } from './ai-job-draft-ids'\nimport { aiJobContentActor, writeAiDraft, writeAiDraftScreenSeo } from './ai-job-drafts'\nimport { aiUnspentOutcome } from './ai-job-generation'\nimport { aiPluginDraftAdmissionRefusal } from './ai-job-plugin-drafts'\nimport type { AiJobStepContext, AiJobStepOutcome, AiJobStepRunner } from './ai-job-text-step'\n\n/**\n * The store pages' unit of a site start (AGL-3676): the account, cart and\n * policy pages a paid store gets beside its planned pages\n * (`model/ai-site-store-pages.ts`), written by code in one pass that asks no\n * model and costs no credits.\n *\n * Each page is a draft written through the same writer, under the same pages\n * allowance, as every page the start builds (`writeAiDraft`), under an id\n * derived from the unit's job, so a pass run again finds its own drafts. The\n * guided start's publish then puts them live with the rest.\n *\n * The site's user accounts are turned on here too: the Customer account's\n * sign-in, and the platform's /signin and /signup, answer only where the site\n * serves accounts (`accounts` is off by default on a site that predates\n * 2026-08; every new site is born with it). A site whose owner switched them\n * off keeps them off: an explicit deny is theirs.\n */\n\n/** The unit input a store pages unit carries what it writes in. */\nexport const AI_SITE_STORE_PAGES_INPUT = 'storePages'\n\n/** What a store pages unit is told: the store pages the plan implies, and what their words link. */\nexport interface AiSiteStorePagesInput {\n pages: AiStorePagePlan[]\n facts: AiStorePageFacts\n /** The layout the start built, which the pages render inside; the site's otherwise. */\n layoutId: string | null\n}\n\n/** The commerce plugin's name, in the refusal that asks for it. */\nconst STORE_LABEL = 'Commerce'\n\n/** What a store pages row says where nothing could be written: our failure. */\nexport const AI_SITE_STORE_PAGES_NOT_WRITTEN_COPY = 'Your account, cart and policy pages could not be added this time.'\n\n/** The id of the store page a unit writes for `key`. */\nexport function aiSiteStorePageId(unitJobId: string, key: string): string {\n return `${unitJobId}-${key}`\n}\n\nconst PATH = /^\\/[a-z0-9-]*$/\n\nfunction inputOf(job: Pick<AiJob, 'inputs'>): AiSiteStorePagesInput | null {\n const raw = job.inputs?.[AI_SITE_STORE_PAGES_INPUT] as Partial<AiSiteStorePagesInput> | undefined\n if (!raw || !Array.isArray(raw.pages) || !raw.facts) return null\n const keys = new Set(AI_STORE_PAGES.map((page) => page.key))\n const pages = raw.pages.filter((page) => page && keys.has(page.key) && typeof page.slug === 'string')\n const path = (value: unknown, fallback: string) => (typeof value === 'string' && PATH.test(value) ? value : fallback)\n return {\n pages,\n facts: {\n contactPath: raw.facts.contactPath ? path(raw.facts.contactPath, '') || null : null,\n shopPath: path(raw.facts.shopPath, '/shop'),\n shippingPath: path(raw.facts.shippingPath, '/shipping-returns'),\n },\n layoutId: typeof raw.layoutId === 'string' && raw.layoutId ? raw.layoutId : null,\n }\n}\n\n/**\n * Whether the store pages may be added for this member on this site, asked\n * before their pass so a refusal spends nothing; `null` admits. The plan must\n * include a store (Starter and up), the commerce plugin must run here, and the\n * member must be able to edit the site's pages.\n */\nexport async function aiSiteStorePagesRefusal(\n context: Pick<AiJobStepContext, 'firestore' | 'org' | 'now'> & { job: Pick<AiJob, 'orgId' | 'hostId' | 'createdBy'> },\n deps: { admission?: typeof aiPluginDraftAdmissionRefusal } = {},\n): Promise<string | null> {\n const { job, firestore } = context\n if (!job.hostId) return 'Open the site first.'\n if (!checkEntitlement((context.org ?? null) as never, 'commerce')) return 'Your plan does not include a store.'\n const refused = await (deps.admission ?? aiPluginDraftAdmissionRefusal)(\n { firestore, orgId: job.orgId, hostId: job.hostId, inputs: {}, org: context.org ?? null },\n { kind: 'site', drafts: [{ resource: 'product', label: STORE_LABEL }], now: context.now },\n )\n if (refused) return refused.error\n const host = await firestore.collection('hosts').doc(job.hostId).get()\n return holdsSiteKey(host, job.createdBy, 'site.edit') ? null : siteKeyRefusal('site.edit')\n}\n\nexport interface AiSiteStorePagesRunnerDeps {\n write?: typeof writeAiDraft\n writeSeo?: typeof writeAiDraftScreenSeo\n}\n\n/** The store pages' pass: every page written, user accounts on, one output a page. */\nexport function createAiSiteStorePagesRunner(deps: AiSiteStorePagesRunnerDeps = {}): AiJobStepRunner {\n const write = deps.write ?? writeAiDraft\n const writeSeo = deps.writeSeo ?? writeAiDraftScreenSeo\n return async (context): Promise<AiJobStepOutcome> => {\n const { job, firestore, now } = context\n const model = context.modelFor?.('job.plan') ?? aiModelForStep('job.plan')\n const input = inputOf(job)\n const hostId = job.hostId\n if (!input || !hostId) return { ...aiUnspentOutcome(model), failure: AI_SITE_STORE_PAGES_NOT_WRITTEN_COPY }\n const outputs: AiJobOutput[] = []\n let refusal: string | null = null\n for (const page of aiStorePagesToWrite(input.pages)) {\n const definition = AI_STORE_PAGES.find((one) => one.key === page.key)\n if (!definition) continue\n const id = aiSiteStorePageId(job.$id, page.key)\n const draft = await write(firestore, {\n kind: 'screen',\n hostId,\n id,\n uid: job.createdBy,\n actor: aiJobContentActor(job),\n org: context.org ?? null,\n name: definition.title,\n slug: page.slug,\n nodes: aiStorePageNodes(page.key, input.facts) as unknown as NodesMap,\n layoutId: input.layoutId,\n // The account and the cart are a shopper's own pages: unlisted, noindex (AGL-3676).\n ...(definition.noindex ? { visibility: HostScreenVisibility.UNLISTED } : {}),\n aiJobId: aiOriginJobId(job),\n now,\n })\n if (draft.ok === false) {\n // The pages allowance is full, or the site is gone: what was written stays.\n refusal = draft.error\n break\n }\n await writeSeo(firestore, { hostId, id, seo: definition.seo, actor: aiJobContentActor(job), now })\n outputs.push({\n resource: 'screen',\n id,\n versionId: draft.versionId,\n hostId,\n hostSubdomain: draft.hostSubdomain,\n label: draft.name,\n proposal: { storePage: page.key, path: page.href },\n })\n }\n if (outputs.length) await turnOnSiteAccounts(firestore, hostId, now)\n if (!outputs.length) {\n return refusal\n ? aiUnspentOutcome(model, { review: { reason: 'limit', message: refusal, findings: [] } })\n : { ...aiUnspentOutcome(model), failure: AI_SITE_STORE_PAGES_NOT_WRITTEN_COPY }\n }\n return aiUnspentOutcome(model, { outputs })\n }\n}\n\nexport const runAiSiteStorePagesUnit = createAiSiteStorePagesRunner()\n\n/**\n * Turns on the site's user accounts (`accounts`, default-off per site), so\n * the account page's sign-in and the platform's /signin and /signup answer.\n * An owner's explicit switch-off is left as it is.\n */\nexport async function turnOnSiteAccounts(firestore: FirebaseFirestore.Firestore, hostId: string, now: Date): Promise<boolean> {\n const hostRef = firestore.collection('hosts').doc(hostId)\n const host = await hostRef.get()\n if (!host.exists) return false\n const disabled = (host.get('disabledPlugins') ?? []) as unknown[]\n const enabled = (host.get('enabledPlugins') ?? []) as unknown[]\n if (disabled.includes(ACCOUNTS_PLUGIN_ID) || enabled.includes(ACCOUNTS_PLUGIN_ID)) return false\n await hostRef.update({ enabledPlugins: FieldValue.arrayUnion(ACCOUNTS_PLUGIN_ID), updatedAt: now })\n return true\n}\n"],"names":["checkEntitlement","holdsSiteKey","siteKeyRefusal","ACCOUNTS_PLUGIN_ID","HostScreenVisibility","FieldValue","aiStorePageNodes","aiStorePagesToWrite","AI_STORE_PAGES","aiModelForStep","aiOriginJobId","aiJobContentActor","writeAiDraft","writeAiDraftScreenSeo","aiUnspentOutcome","aiPluginDraftAdmissionRefusal","AI_SITE_STORE_PAGES_INPUT","STORE_LABEL","AI_SITE_STORE_PAGES_NOT_WRITTEN_COPY","aiSiteStorePageId","unitJobId","key","PATH","inputOf","job","raw","inputs","Array","isArray","pages","facts","keys","Set","map","page","filter","has","slug","path","value","fallback","test","contactPath","shopPath","shippingPath","layoutId","aiSiteStorePagesRefusal","context","deps","firestore","hostId","org","refused","admission","orgId","kind","drafts","resource","label","now","error","host","collection","doc","get","createdBy","createAiSiteStorePagesRunner","write","writeSeo","model","modelFor","input","failure","outputs","refusal","definition","find","one","id","$id","draft","uid","actor","name","title","nodes","noindex","visibility","UNLISTED","aiJobId","ok","seo","push","versionId","hostSubdomain","proposal","storePage","href","length","turnOnSiteAccounts","review","reason","message","findings","runAiSiteStorePagesUnit","hostRef","exists","disabled","enabled","includes","update","enabledPlugins","arrayUnion","updatedAt"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,gBAAgB,QAAQ,2CAA0C;AAC3E,SAASC,YAAY,EAAEC,cAAc,QAAQ,0CAAyC;AACtF,SAASC,kBAAkB,QAAQ,8CAA6C;AAChF,SAASC,oBAAoB,QAAQ,qDAAoD;AAEzF,SAASC,UAAU,QAAQ,2BAA0B;AAErD,SACEC,gBAAgB,EAChBC,mBAAmB,EACnBC,cAAc,QAGT,kCAA8B;AACrC,SAASC,cAAc,QAAQ,0BAAsB;AACrD,SAASC,aAAa,QAAQ,wBAAoB;AAClD,SAASC,iBAAiB,EAAEC,YAAY,EAAEC,qBAAqB,QAAQ,qBAAiB;AACxF,SAASC,gBAAgB,QAAQ,yBAAqB;AACtD,SAASC,6BAA6B,QAAQ,4BAAwB;AAGtE;;;;;;;;;;;;;;;;CAgBC,GAED,iEAAiE,GACjE,OAAO,MAAMC,4BAA4B,aAAY;AAUrD,iEAAiE,GACjE,MAAMC,cAAc;AAEpB,6EAA6E,GAC7E,OAAO,MAAMC,uCAAuC,oEAAmE;AAEvH,sDAAsD,GACtD,OAAO,SAASC,kBAAkBC,SAAiB,EAAEC,GA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,OAAOxB,UACH5D,iBAAiBuD,OAAO;gBAAE+B,QAAQ;oBAAEC,QAAQ;oBAASC,SAAS5B;oBAAS6B,UAAU,EAAE;gBAAC;YAAE,KACtF,aAAKzF,iBAAiBuD;gBAAQG,SAAStD;;QAC7C;QACA,OAAOJ,iBAAiBuD,OAAO;YAAEI;QAAQ;IAC3C;AACF;AAEA,OAAO,MAAM+B,0BAA0BtC,+BAA8B;AAErE;;;;CAIC,GACD,OAAO,eAAeiC,mBAAmBlD,SAAsC,EAAEC,MAAc,EAAES,GAAS;QAItFE,WACDA;IAJjB,MAAM4C,UAAUxD,UAAUa,UAAU,CAAC,SAASC,GAAG,CAACb;IAClD,MAAMW,OAAO,MAAM4C,QAAQzC,GAAG;IAC9B,IAAI,CAACH,KAAK6C,MAAM,EAAE,OAAO;IACzB,MAAMC,YAAY9C,YAAAA,KAAKG,GAAG,CAAC,8BAATH,YAA+B,EAAE;IACnD,MAAM+C,WAAW/C,aAAAA,KAAKG,GAAG,CAAC,6BAATH,aAA8B,EAAE;IACjD,IAAI8C,SAASE,QAAQ,CAAC1G,uBAAuByG,QAAQC,QAAQ,CAAC1G,qBAAqB,OAAO;IAC1F,MAAMsG,QAAQK,MAAM,CAAC;QAAEC,gBAAgB1G,WAAW2G,UAAU,CAAC7G;QAAqB8G,WAAWtD;IAAI;IACjG,OAAO;AACT"}
|
|
@@ -14,7 +14,8 @@ import { _ as _extends } from "@swc/helpers/_/_extends";
|
|
|
14
14
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
15
|
* See the License for the specific language governing permissions and
|
|
16
16
|
* limitations under the License.
|
|
17
|
-
*/ import {
|
|
17
|
+
*/ import { contentEditStamp, withoutVersionPublishStamp } from "@aglyn/aglyn/app-utils/content-write-stamp";
|
|
18
|
+
import { decodeStoredNodes, encodeStoredNodes } from "@aglyn/aglyn/app-utils/stored-nodes";
|
|
18
19
|
import { aiLayoutWithStoreLinks } from "../model/ai-layout-store-links.js";
|
|
19
20
|
/**
|
|
20
21
|
* A store's links in the site's own layout, as a DRAFT (AGL-3676): a build
|
|
@@ -68,14 +69,17 @@ import { aiLayoutWithStoreLinks } from "../model/ai-layout-store-links.js";
|
|
|
68
69
|
versionId: null,
|
|
69
70
|
name
|
|
70
71
|
};
|
|
71
|
-
const copy = _extends({}, current.data());
|
|
72
|
+
const copy = withoutVersionPublishStamp(_extends({}, current.data()));
|
|
72
73
|
delete copy['aiEditJobId'];
|
|
73
74
|
await draftRef.create(_extends({}, copy, {
|
|
74
75
|
nodes: Buffer.from(packed),
|
|
75
76
|
displayName: AI_STORE_LINKS_VERSION_NAME,
|
|
76
77
|
createdAt: input.now,
|
|
77
|
-
|
|
78
|
-
|
|
78
|
+
createdBy: input.uid
|
|
79
|
+
}, contentEditStamp({
|
|
80
|
+
uid: input.uid,
|
|
81
|
+
via: `ai-job:${input.aiJobId}`
|
|
82
|
+
}, input.now), {
|
|
79
83
|
aiJobId: input.aiJobId,
|
|
80
84
|
[AI_STORE_LINKS_SOURCE_FIELD]: currentVersionId
|
|
81
85
|
}));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/jobs/ai-job-store-links-layout.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 { decodeStoredNodes, encodeStoredNodes } from '@aglyn/aglyn/app-utils/stored-nodes'\nimport type { Firestore } from 'firebase-admin/firestore'\nimport { aiLayoutWithStoreLinks, type AiStoreLayoutLinks } from '../model/ai-layout-store-links'\n\n/**\n * A store's links in the site's own layout, as a DRAFT (AGL-3676): a build\n * that makes the site a store and builds no layout writes a new version of\n * the layout its store pages render inside, with Account (and Cart, where\n * the header has none) in the header and the account and policies in the\n * footer (`aiLayoutWithStoreLinks`). The layout's current version — the one\n * visitors see — is never touched: the new version waits beside it, and goes\n * live only when the build publishes (`aiPublishGuidedSite`'s `storeLinks`),\n * as every draft the build makes does.\n */\n\n/** The field a draft version keeps the version it was made from in, so a publish knows whether it is still current. */\nexport const AI_STORE_LINKS_SOURCE_FIELD = 'aiStoreLinksSourceVersionId'\n\n/** What a store links draft version is called in the layout's versions. */\nexport const AI_STORE_LINKS_VERSION_NAME = 'Account and policy links'\n\n/** What writing a store's links into the site's layout came to. */\nexport type AiStoreLinksLayoutDraft =\n | { status: 'written'; layoutId: string; versionId: string; name: string }\n /** Every link was already there. */\n | { status: 'present'; layoutId: string }\n /** The layout has no header list or no footer list to add to: what it had room for, if anything, was written. */\n | { status: 'unrecognized'; layoutId: string; versionId: string | null; name: string }\n /** The layout is gone, or has no current version to start from. */\n | { status: 'gone' }\n\n/**\n * Writes the draft version (idempotent: a version with this id already\n * written is that draft). Reads the layout's current version and writes the\n * new one beside it, a copy of it — its fields, everything the editor stored\n * — with the links added.\n */\nexport async function writeAiStoreLinksLayoutDraft(\n firestore: Firestore,\n input: {\n hostId: string\n layoutId: string\n versionId: string\n links: AiStoreLayoutLinks\n screenPaths: Readonly<Record<string, string>>\n uid: string\n aiJobId: string\n now: Date\n },\n): Promise<AiStoreLinksLayoutDraft> {\n const layoutRef = firestore.collection('hosts').doc(input.hostId).collection('layouts').doc(input.layoutId)\n const layout = await layoutRef.get()\n const currentVersionId = layout.get('versionId')\n if (!layout.exists || layout.get('deletedAt') != null || typeof currentVersionId !== 'string' || !currentVersionId) {\n return { status: 'gone' }\n }\n const name = String(layout.get('displayName') ?? '') || 'Layout'\n const draftRef = layoutRef.collection('versions').doc(input.versionId)\n const already = await draftRef.get()\n if (already.exists) return { status: 'written', layoutId: input.layoutId, versionId: input.versionId, name }\n const current = await layoutRef.collection('versions').doc(currentVersionId).get()\n const nodes = current.exists ? decodeStoredNodes<Record<string, unknown>>(current.get('nodes')) : null\n if (!nodes) return { status: 'gone' }\n const result = aiLayoutWithStoreLinks(nodes, input.links, input.screenPaths)\n const recognized = result.header && result.footer\n const packed = result.nodes ? encodeStoredNodes(result.nodes as never) : null\n if (!packed) return recognized ? { status: 'present', layoutId: input.layoutId } : { status: 'unrecognized', layoutId: input.layoutId, versionId: null, name }\n const copy = { ...(current.data() as Record<string, unknown>) }\n delete copy['aiEditJobId']\n await draftRef.create({\n ...copy,\n nodes: Buffer.from(packed),\n displayName: AI_STORE_LINKS_VERSION_NAME,\n createdAt: input.now,\n
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/ai/src/lib/jobs/ai-job-store-links-layout.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 { contentEditStamp, withoutVersionPublishStamp } from '@aglyn/aglyn/app-utils/content-write-stamp'\nimport { decodeStoredNodes, encodeStoredNodes } from '@aglyn/aglyn/app-utils/stored-nodes'\nimport type { Firestore } from 'firebase-admin/firestore'\nimport { aiLayoutWithStoreLinks, type AiStoreLayoutLinks } from '../model/ai-layout-store-links'\n\n/**\n * A store's links in the site's own layout, as a DRAFT (AGL-3676): a build\n * that makes the site a store and builds no layout writes a new version of\n * the layout its store pages render inside, with Account (and Cart, where\n * the header has none) in the header and the account and policies in the\n * footer (`aiLayoutWithStoreLinks`). The layout's current version — the one\n * visitors see — is never touched: the new version waits beside it, and goes\n * live only when the build publishes (`aiPublishGuidedSite`'s `storeLinks`),\n * as every draft the build makes does.\n */\n\n/** The field a draft version keeps the version it was made from in, so a publish knows whether it is still current. */\nexport const AI_STORE_LINKS_SOURCE_FIELD = 'aiStoreLinksSourceVersionId'\n\n/** What a store links draft version is called in the layout's versions. */\nexport const AI_STORE_LINKS_VERSION_NAME = 'Account and policy links'\n\n/** What writing a store's links into the site's layout came to. */\nexport type AiStoreLinksLayoutDraft =\n | { status: 'written'; layoutId: string; versionId: string; name: string }\n /** Every link was already there. */\n | { status: 'present'; layoutId: string }\n /** The layout has no header list or no footer list to add to: what it had room for, if anything, was written. */\n | { status: 'unrecognized'; layoutId: string; versionId: string | null; name: string }\n /** The layout is gone, or has no current version to start from. */\n | { status: 'gone' }\n\n/**\n * Writes the draft version (idempotent: a version with this id already\n * written is that draft). Reads the layout's current version and writes the\n * new one beside it, a copy of it — its fields, everything the editor stored\n * — with the links added.\n */\nexport async function writeAiStoreLinksLayoutDraft(\n firestore: Firestore,\n input: {\n hostId: string\n layoutId: string\n versionId: string\n links: AiStoreLayoutLinks\n screenPaths: Readonly<Record<string, string>>\n uid: string\n aiJobId: string\n now: Date\n },\n): Promise<AiStoreLinksLayoutDraft> {\n const layoutRef = firestore.collection('hosts').doc(input.hostId).collection('layouts').doc(input.layoutId)\n const layout = await layoutRef.get()\n const currentVersionId = layout.get('versionId')\n if (!layout.exists || layout.get('deletedAt') != null || typeof currentVersionId !== 'string' || !currentVersionId) {\n return { status: 'gone' }\n }\n const name = String(layout.get('displayName') ?? '') || 'Layout'\n const draftRef = layoutRef.collection('versions').doc(input.versionId)\n const already = await draftRef.get()\n if (already.exists) return { status: 'written', layoutId: input.layoutId, versionId: input.versionId, name }\n const current = await layoutRef.collection('versions').doc(currentVersionId).get()\n const nodes = current.exists ? decodeStoredNodes<Record<string, unknown>>(current.get('nodes')) : null\n if (!nodes) return { status: 'gone' }\n const result = aiLayoutWithStoreLinks(nodes, input.links, input.screenPaths)\n const recognized = result.header && result.footer\n const packed = result.nodes ? encodeStoredNodes(result.nodes as never) : null\n if (!packed) return recognized ? { status: 'present', layoutId: input.layoutId } : { status: 'unrecognized', layoutId: input.layoutId, versionId: null, name }\n const copy = withoutVersionPublishStamp({ ...(current.data() as Record<string, unknown>) })\n delete copy['aiEditJobId']\n await draftRef.create({\n ...copy,\n nodes: Buffer.from(packed),\n displayName: AI_STORE_LINKS_VERSION_NAME,\n createdAt: input.now,\n createdBy: input.uid,\n ...contentEditStamp({ uid: input.uid, via: `ai-job:${input.aiJobId}` }, input.now),\n aiJobId: input.aiJobId,\n [AI_STORE_LINKS_SOURCE_FIELD]: currentVersionId,\n })\n return recognized\n ? { status: 'written', layoutId: input.layoutId, versionId: input.versionId, name }\n : { status: 'unrecognized', layoutId: input.layoutId, versionId: input.versionId, name }\n}\n"],"names":["contentEditStamp","withoutVersionPublishStamp","decodeStoredNodes","encodeStoredNodes","aiLayoutWithStoreLinks","AI_STORE_LINKS_SOURCE_FIELD","AI_STORE_LINKS_VERSION_NAME","writeAiStoreLinksLayoutDraft","firestore","input","layout","layoutRef","collection","doc","hostId","layoutId","get","currentVersionId","exists","status","name","String","draftRef","versionId","already","current","nodes","result","links","screenPaths","recognized","header","footer","packed","copy","data","create","Buffer","from","displayName","createdAt","now","createdBy","uid","via","aiJobId"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,gBAAgB,EAAEC,0BAA0B,QAAQ,6CAA4C;AACzG,SAASC,iBAAiB,EAAEC,iBAAiB,QAAQ,sCAAqC;AAE1F,SAASC,sBAAsB,QAAiC,oCAAgC;AAEhG;;;;;;;;;CASC,GAED,qHAAqH,GACrH,OAAO,MAAMC,8BAA8B,8BAA6B;AAExE,yEAAyE,GACzE,OAAO,MAAMC,8BAA8B,2BAA0B;AAYrE;;;;;CAKC,GACD,OAAO,eAAeC,6BACpBC,SAAoB,EACpBC,KASC;QAQmBC;IANpB,MAAMC,YAAYH,UAAUI,UAAU,CAAC,SAASC,G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2BAA2B,aAAMwB,QAAQU,IAAI;IAC1D,OAAOD,IAAI,CAAC,cAAc;IAC1B,MAAMZ,SAASc,MAAM,CAAC,aACjBF;QACHR,OAAOW,OAAOC,IAAI,CAACL;QACnBM,aAAajC;QACbkC,WAAW/B,MAAMgC,GAAG;QACpBC,WAAWjC,MAAMkC,GAAG;OACjB3C,iBAAiB;QAAE2C,KAAKlC,MAAMkC,GAAG;QAAEC,KAAK,CAAC,OAAO,EAAEnC,MAAMoC,OAAO,EAAE;IAAC,GAAGpC,MAAMgC,GAAG;QACjFI,SAASpC,MAAMoC,OAAO;QACtB,CAACxC,4BAA4B,EAAEY;;IAEjC,OAAOa,aACH;QAAEX,QAAQ;QAAWJ,UAAUN,MAAMM,QAAQ;QAAEQ,WAAWd,MAAMc,SAAS;QAAEH;IAAK,IAChF;QAAED,QAAQ;QAAgBJ,UAAUN,MAAMM,QAAQ;QAAEQ,WAAWd,MAAMc,SAAS;QAAEH;IAAK;AAC3F"}
|
|
@@ -31,7 +31,7 @@ import { registerAiJobAdmission } from "./ai-job-admission.js";
|
|
|
31
31
|
import { aiJobDraftId } from "./ai-job-draft-ids.js";
|
|
32
32
|
import { aiLayoutMotionSiteOf } from "./ai-job-page-language.js";
|
|
33
33
|
import { aiWithSiteMotion } from "../layout-language/ai-layout-motion.js";
|
|
34
|
-
import { aiDraftAdmissionRefusal, aiDraftAllowanceRefusal, aiSiteSubdomain, readAiDraft, readAiTemplateDraftNodes, writeAiDraft } from "./ai-job-drafts.js";
|
|
34
|
+
import { aiDraftAdmissionRefusal, aiDraftAllowanceRefusal, aiSiteSubdomain, readAiDraft, readAiTemplateDraftNodes, aiJobContentActor, writeAiDraft } from "./ai-job-drafts.js";
|
|
35
35
|
import { aiConfirmedPlan, aiCopySourceLines, aiDoctrineReview, aiGenerationSpent, aiJobBriefLine, aiLimitReview, aiModelNodeIds, aiPlacedComponentIds, aiPlanCreation, aiPlanReferenceLines, aiPlanReuseViolations, aiUnspentOutcome } from "./ai-job-generation.js";
|
|
36
36
|
import { aiPlannedTemplateTokens, aiPlanTemplateTokenViolations } from "./ai-job-plan-conformance.js";
|
|
37
37
|
import { aiBuildingPlanCreations, aiJobPlanCreationsRefusal, aiPlanCreationsRunMinimumMs } from "./ai-job-plan-creations.js";
|
|
@@ -493,6 +493,7 @@ export function createAiJobTemplateStep(deps = {}) {
|
|
|
493
493
|
hostId,
|
|
494
494
|
id: draftId,
|
|
495
495
|
uid: job.createdBy,
|
|
496
|
+
actor: aiJobContentActor(job),
|
|
496
497
|
org,
|
|
497
498
|
name,
|
|
498
499
|
// The site's entrance motion, as its pages have (AGL-3838): a post or a
|