@vectoriox/iox-ui 5.124.0 → 5.125.0

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.
@@ -0,0 +1,103 @@
1
+ import { AI_COMPOSED_PAGES_ESTIMATED, AiFeature } from './ai-run';
2
+ import { GenerationTier, PagePlan, SitePlan, STAMPED_PAGE_ARCHETYPES } from './site-plan.model';
3
+ import { isPerItemPage } from './validate-site-plan';
4
+
5
+ /**
6
+ * The generation tier (award-ingredients-plan §0, AW-D23/AW-D24) — pure. A studio whose plan has `awardSites` builds at
7
+ * the award tier: the model composes every page that may be composed, not two, and a contract row marked
8
+ * `tier: 'award'` is offered to it alone. Basic is today's generation exactly. Read once, when a generation starts, and
9
+ * carried by the generation — never re-read mid-run, never written by the model.
10
+ */
11
+
12
+ export const DEFAULT_GENERATION_TIER: GenerationTier = GenerationTier.Basic;
13
+
14
+ /** The tier a studio's plan features give (the control plane's `features` map; absent or off = Basic). */
15
+ export function generationTierOf(features: Readonly<Record<string, boolean | undefined>> | null | undefined): GenerationTier {
16
+ return features?.[AiFeature.AwardSites] === true ? GenerationTier.Award : GenerationTier.Basic;
17
+ }
18
+
19
+ /** A tier as stored (an older generation holds none) — anything but `award` is Basic. */
20
+ export function tierOf(stored: string | null | undefined): GenerationTier {
21
+ return stored === GenerationTier.Award ? GenerationTier.Award : GenerationTier.Basic;
22
+ }
23
+
24
+ /** The order the tiers open in: a row offered at a tier is offered at every tier above it. */
25
+ const TIER_RANK: Readonly<Record<GenerationTier, number>> = {
26
+ [GenerationTier.Basic]: 0,
27
+ [GenerationTier.Award]: 1,
28
+ };
29
+
30
+ /** A contract row that may be held for a tier (a word, a recipe, a table row) — no `tier` = every tier. */
31
+ export interface TieredRow {
32
+ readonly tier?: `${GenerationTier}` | null;
33
+ }
34
+
35
+ /** May a row of `rowTier` be offered to a build at `tier`? */
36
+ export function tierOffers(rowTier: `${GenerationTier}` | null | undefined, tier: `${GenerationTier}`): boolean {
37
+ return !rowTier || TIER_RANK[rowTier] <= TIER_RANK[tier];
38
+ }
39
+
40
+ /**
41
+ * The rows a build at `tier` is offered — the ONE word filter the plan wire, the layout wire and the checks apply once the
42
+ * contract's rows carry a `tier` (award-ingredients-plan R-H: a lower plan's site never wears an award-only word).
43
+ */
44
+ export function offeredForTier<T extends TieredRow>(rows: ReadonlyArray<T>, tier: `${GenerationTier}`): T[] {
45
+ return rows.filter(row => tierOffers(row.tier, tier));
46
+ }
47
+
48
+ /** May this page be composed at the award tier: not a page per item, not a page type that is always stamped (AW-D24). */
49
+ export function composablePage(page: Pick<PagePlan, 'route' | 'template' | 'routeSource' | 'archetype'>): boolean {
50
+ return !isPerItemPage(page) && !(page.archetype && STAMPED_PAGE_ARCHETYPES.has(page.archetype));
51
+ }
52
+
53
+ /**
54
+ * The plan with the pages its tier composes marked `compose: true` — the generation decides, never the model.
55
+ * Basic (M8-G2-D3): Home is always composed and the model's own mark on one other page is kept, exactly as before.
56
+ * Award (AW-D24): every composable page is composed (home, about, services, a list's page, contact, a landing page)
57
+ * and no other — a page per item and a legal page stay stamped whatever the model wrote.
58
+ */
59
+ export function withComposedPages(plan: SitePlan, tier: `${GenerationTier}`): SitePlan {
60
+ if (tier !== GenerationTier.Award) return { ...plan, pages: plan.pages.map(p => (p.isHome ? { ...p, compose: true } : p)) };
61
+ return {
62
+ ...plan,
63
+ pages: plan.pages.map(p => {
64
+ if (composablePage(p)) return p.compose === true ? p : { ...p, compose: true };
65
+ if (p.compose === undefined) return p;
66
+ const { compose: _dropped, ...rest } = p;
67
+ return rest;
68
+ }),
69
+ };
70
+ }
71
+
72
+ /**
73
+ * The award tier's start estimate counts this many composed pages — the plan is not written yet when a generation
74
+ * starts. A typical award site: home, about, services, a list's page, contact and one more. Once the plan is written the
75
+ * composing step is gated on the pages actually waiting (`composingShare`).
76
+ */
77
+ export const AWARD_COMPOSED_PAGES_ESTIMATED = 6;
78
+
79
+ /** The composed pages a tier's start estimate counts. */
80
+ export const AI_COMPOSED_PAGES_BY_TIER: Readonly<Record<GenerationTier, number>> = {
81
+ [GenerationTier.Basic]: AI_COMPOSED_PAGES_ESTIMATED,
82
+ [GenerationTier.Award]: AWARD_COMPOSED_PAGES_ESTIMATED,
83
+ };
84
+
85
+ /** `pages` composed pages as a share of the composing step's typical estimate (which covers `AI_COMPOSED_PAGES_ESTIMATED`). */
86
+ export function composedPagesShare(pages: number): number {
87
+ return pages / AI_COMPOSED_PAGES_ESTIMATED;
88
+ }
89
+
90
+ /** The composing step's share of a generation's start estimate, at a tier (Basic: exactly the whole step, as before). */
91
+ export function startComposingShare(tier: `${GenerationTier}`): number {
92
+ return composedPagesShare(AI_COMPOSED_PAGES_BY_TIER[tierOf(tier)]);
93
+ }
94
+
95
+ /**
96
+ * What the composing step must find before it starts, as a share of its typical estimate: Basic is held to the whole
97
+ * step (as before — at most its two pages); Award counts every page waiting (AW-D24: the estimate follows the actual
98
+ * composed count). Credits running out mid-run still never fail a build (m8-gate2 §22).
99
+ */
100
+ export function composingShare(waiting: number, tier: `${GenerationTier}`): number {
101
+ const share = composedPagesShare(waiting);
102
+ return tier === GenerationTier.Award ? share : Math.min(1, share);
103
+ }
@@ -27,6 +27,7 @@ export * from './plan-data';
27
27
  export * from './showcase';
28
28
  export * from './site-build-run';
29
29
  export * from './ai-run';
30
+ export * from './generation-tier';
30
31
  export * from './recipe-fields';
31
32
  export * from './plan-derived';
32
33
  export * from './shop-plan';
@@ -280,6 +280,23 @@ export interface PagePlan {
280
280
  readonly layout?: LayoutPage;
281
281
  }
282
282
 
283
+ /**
284
+ * What a build is made at (award-ingredients-plan AW-D23): read from the studio's plan (`awardSites`), never from the
285
+ * model. Basic = today's generation exactly (Home + one page composed by the model); Award = the model composes most
286
+ * pages (AW-D24) and the award-only words are offered (each contract row's `tier`, filtered by `offeredForTier`).
287
+ */
288
+ export enum GenerationTier {
289
+ Basic = 'basic',
290
+ Award = 'award',
291
+ }
292
+
293
+ /**
294
+ * The page types never composed on any tier (AW-D24): a page per item shows its item from patterns, a legal page is the
295
+ * owner's own words. `legal` joins the contract's page types with AW1 — named here so a legal page is never composed
296
+ * the day it lands.
297
+ */
298
+ export const STAMPED_PAGE_ARCHETYPES: ReadonlySet<string> = new Set(['detail', 'legal']);
299
+
283
300
  export enum GlobalSlot {
284
301
  Header = 'header',
285
302
  Footer = 'footer',
@@ -8,7 +8,7 @@ import {
8
8
  patternSlots, PatternGlobalPosition, slotBudget, SCENE_LEVEL, SCENE_OTHER_PAGES } from './patterns';
9
9
  import { ContentFieldControl, FIELD_TYPE_OF_CONTROL,
10
10
  FACT_KEYS, GlobalSlot, PAGE_ARCHETYPES, SITE_NEED_IDS, PlanDataSourceMode, PlanDataSourceType, RelativeOp, REQUIRED_CONTENT_ROLES, ShopResource, SitePlan,
11
- SitePlanSourceKind, SITE_LOCALES, SITE_PLAN_VERSION,
11
+ SitePlanSourceKind, SITE_LOCALES, SITE_PLAN_VERSION, GenerationTier, STAMPED_PAGE_ARCHETYPES,
12
12
  } from './site-plan.model';
13
13
  import { pricesIn } from './plan-words';
14
14
  import { isShopResource, planSells, SHOP_PRODUCTS_MAX, SHOP_SLUG_FIELD, shopContentType } from './shop-plan';
@@ -105,6 +105,11 @@ export interface SitePlanContext {
105
105
  /** True: the business sells (the reading's need `products`) — the plan must name what. False: it sells nothing — the
106
106
  * plan holds no shop. Absent: the plan is judged as written (a template, a stored plan). */
107
107
  readonly sells?: boolean;
108
+ /** The tier the plan was made at (AW-D23) — how many pages it may compose: Basic (and ABSENT — the safe default) at
109
+ * most `site.layout.limits.composedPages`; only an explicit Award lifts the count, to every page that is not a page
110
+ * per item or a stamped type. A plan made on Pro builds after a downgrade because its own generation's stored tier
111
+ * is passed here, never because a tier is missing. */
112
+ readonly tier?: `${GenerationTier}`;
108
113
  }
109
114
 
110
115
  export type SitePlanIssue = PathIssue<SitePlanIssueCode>;
@@ -169,6 +174,17 @@ export function routeParams(route: string): string[] {
169
174
  return [...route.matchAll(ROUTE_PARAM)].map(m => m[1]);
170
175
  }
171
176
 
177
+ /** A page per item — a template page, a page bound to the route item, or a route with a param: it shows its item from
178
+ * patterns and is never composed. Duck-typed: the validator asks it of a page as written. */
179
+ export function isPerItemPage(page: { readonly template?: unknown; readonly routeSource?: unknown; readonly route?: unknown }): boolean {
180
+ return page.template !== undefined || page.routeSource !== undefined || (typeof page.route === 'string' && routeParams(page.route).length > 0);
181
+ }
182
+
183
+ /** How many pages a tier composes at most (Infinity: no count — every page that may be composed). */
184
+ export function composedPagesMax(tier: `${GenerationTier}`): number {
185
+ return tier === GenerationTier.Award ? Infinity : COMPOSED_PAGES_MAX;
186
+ }
187
+
172
188
  class Collector extends PathIssueCollector<SitePlanIssueCode> {
173
189
  constructor() {
174
190
  super('plan', { shape: SitePlanIssueCode.Shape, unknownKey: SitePlanIssueCode.UnknownKey, duplicate: SitePlanIssueCode.Duplicate });
@@ -730,7 +746,7 @@ export function validateSitePlan(plan: unknown, ctx: SitePlanContext = {}): Site
730
746
  validateFilm(c, plan['film'], c.array(plan, 'pages', ''));
731
747
  validateArtDirection(c, plan['artDirection']);
732
748
  validateDirection(c, plan['direction']);
733
- validateComposed(c, c.array(plan, 'pages', ''));
749
+ validateComposed(c, c.array(plan, 'pages', ''), ctx.tier);
734
750
  return { valid: c.issues.length === 0, issues: c.issues };
735
751
  }
736
752
 
@@ -751,7 +767,7 @@ function validateDirection(c: Collector, direction: unknown): void {
751
767
  * item); a layout only on a page marked `compose`, its dial one of the dials and 4–8 sections (the rest is `checkLayout`'s
752
768
  * — the plan stage runs it with the photos, `layoutIssues` on a whole plan).
753
769
  */
754
- function validateComposed(c: Collector, pages: unknown[]): void {
770
+ function validateComposed(c: Collector, pages: unknown[], tier: `${GenerationTier}` | undefined): void {
755
771
  let composed = 0;
756
772
  pages.forEach((raw, i) => {
757
773
  if (!isObject(raw)) return;
@@ -760,8 +776,10 @@ function validateComposed(c: Collector, pages: unknown[]): void {
760
776
  const compose = raw['compose'] === true;
761
777
  if (compose) {
762
778
  composed++;
763
- if (raw['template'] !== undefined || raw['routeSource'] !== undefined || (typeof raw['route'] === 'string' && routeParams(raw['route']).length)) {
779
+ if (isPerItemPage(raw)) {
764
780
  c.add(SitePlanIssueCode.Compose, `${path}.compose`, 'a per-item page shows its item from patterns — it is not composed');
781
+ } else if (tier === GenerationTier.Award && typeof raw['archetype'] === 'string' && STAMPED_PAGE_ARCHETYPES.has(raw['archetype'])) {
782
+ c.add(SitePlanIssueCode.Compose, `${path}.compose`, `a ${raw['archetype']} page is stamped from patterns — it is not composed`);
765
783
  }
766
784
  }
767
785
  const layout = raw['layout'];
@@ -772,7 +790,7 @@ function validateComposed(c: Collector, pages: unknown[]): void {
772
790
  if (!LAYOUT_DIALS.includes(String(layout['dial']))) c.add(SitePlanIssueCode.Layout, `${path}.layout.dial`, LAYOUT_DIALS.join(' | '));
773
791
  if (!Array.isArray(layout['sections'])) c.add(SitePlanIssueCode.Shape, `${path}.layout.sections`, 'must be an array');
774
792
  });
775
- if (composed > COMPOSED_PAGES_MAX) c.add(SitePlanIssueCode.Compose, 'pages', `${composed} composed pages — the home page and at most ${COMPOSED_PAGES_MAX - 1} other`);
793
+ if (composed > composedPagesMax(tier ?? GenerationTier.Basic)) c.add(SitePlanIssueCode.Compose, 'pages', `${composed} composed pages — the home page and at most ${COMPOSED_PAGES_MAX - 1} other`);
776
794
  }
777
795
 
778
796
  /** The plan's content types and, for each shop list a source reads, the shop's own (fixed fields and roles). */
@@ -787,8 +805,8 @@ function withShopTypes(types: Map<string, ContentTypeInfo>, sources: Map<string,
787
805
  }
788
806
 
789
807
  /** Throw a `SitePlanError` carrying every issue unless the plan is valid. */
790
- export function assertValidSitePlan(plan: unknown): void {
791
- const result = validateSitePlan(plan);
808
+ export function assertValidSitePlan(plan: unknown, ctx: SitePlanContext = {}): void {
809
+ const result = validateSitePlan(plan, ctx);
792
810
  if (!result.valid) throw new SitePlanError(result.issues);
793
811
  }
794
812