@vectoriox/iox-ui 5.151.1 → 5.153.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.
@@ -1,5 +1,5 @@
1
- import { AiStep, STRICT_SCHEMA_BUDGET, strictSchemaComplexity, jsonText, jsonListOf, jsonOneOf, jsonClosedObject, jsonAnyOf, PlanWordIssueCode, factIssues, walkSerialized, AdjustKind, AdjustAxis, adjustStepOf, ADJUST_STEPS, NODE_BASELINES, adjustStyleProps, ADJUST_AXIS_LABELS, adjustStepLabel, patternById, carryInto, composeSection } from '@vectoriox/iox-ui/generation-core';
2
- import { elementStylesFor, colorSchemeOf, ColorScheme, COLOR_SCHEME_TYPES, elementStyleById, COLOR_SCHEMES, NEW_NODE_STYLE_DEFAULTS, setColorScheme, switchElementStyle, flavorPackById, parseHexColor, resolveDesignChoices, SPEC_AXES, stylePresetOfChoices, BETWEEN_IDS, ANIMATE_IDS, SCROLL_IDS, TINT_IDS, STYLE_PRESETS, stylePresetById, presetChoices, designTokenRows, auditDesignContrast } from '@vectoriox/iox-ui/design-core';
1
+ import { AiStep, STRICT_SCHEMA_BUDGET, strictSchemaComplexity, jsonText, jsonListOf, jsonOneOf, jsonClosedObject, jsonAnyOf, PlanWordIssueCode, factIssues, walkSerialized, AdjustKind, AdjustAxis, adjustStepOf, ADJUST_STEPS, NODE_BASELINES, adjustStyleProps, ADJUST_AXIS_LABELS, adjustStepLabel, patternById, carryInto, composeSection, PICTURE_ASPECTS, artDirectionPreamble, frameWords, emptyAreaPhrase, estimateStepCredits, creditsOfUsd, modelCanDo, AiFeature, AI_STEP_FEATURE, AiRefusalCode, aiRefusalNext, pictureReviewPasses } from '@vectoriox/iox-ui/generation-core';
2
+ import { elementStylesFor, colorSchemeOf, ColorScheme, COLOR_SCHEME_TYPES, elementStyleById, COLOR_SCHEMES, NEW_NODE_STYLE_DEFAULTS, setColorScheme, switchElementStyle, flavorPackById, parseHexColor, resolveDesignChoices, SPEC_AXES, stylePresetOfChoices, BETWEEN_IDS, ANIMATE_IDS, SCROLL_IDS, COLUMN_IDS, TINT_IDS, STYLE_PRESETS, stylePresetById, presetChoices, designTokenRows, auditDesignContrast } from '@vectoriox/iox-ui/design-core';
3
3
 
4
4
  /**
5
5
  * The surfaces AI Assist runs on (ai-assist-plan §2, §4): each screen that offers a prompt registers ONE spec — what it
@@ -175,6 +175,9 @@ const SURFACES = {
175
175
  scopes: [AssistScope.Field, AssistScope.Item],
176
176
  status: SurfaceStatus.Planned,
177
177
  }),
178
+ // S7 Files box ▸ Generate: no sentence is routed and no Assist step runs — the box IS the request (`media-generate.ts`:
179
+ // what may be asked, the prompt, the cost before the button, the refusal before any call). It writes assets, so a
180
+ // press is a Run; placing a made picture is the Files box's own pick, one builder step. Built when the box ships.
178
181
  [AssistSurface.Media]: spec({
179
182
  surface: AssistSurface.Media,
180
183
  families: [EditFamily.Media],
@@ -2007,8 +2010,8 @@ function applySectionEdits(layout, edits, ctx) {
2007
2010
  /**
2008
2011
  * Surface S1 (the builder), family `look` (ai-assist-plan §4 AI2e; ai-session-panel-plan `setLook` / `setMotion`): the
2009
2012
  * SITE's look and motion — every page follows — changed only along the contract's own axes: a style preset, the brand
2010
- * colour, the background tint, corners, pill buttons, spacing, the type pairing, the colour mode, speed, scrolling, how
2011
- * animated and the change between pages. Never a token value, never CSS. A preset brings its whole look and keeps the
2013
+ * colour, the background tint, corners, pill buttons, spacing, the content width (award §0c CW4), the type pairing, the
2014
+ * colour mode, speed, scrolling, how animated and the change between pages. Never a token value, never CSS. A preset brings its whole look and keeps the
2012
2015
  * site's own Scrolling · How animated · Between pages (MO-D3, as Design ▸ Look does); a type pairing is one of the worn
2013
2016
  * style's own. The colour is checked by the SAME audit the contract gates every preset with (`auditDesignContrast`, in
2014
2017
  * every mode the look is worn) — a colour that fails is refused, never worn (R4: the AA gate decides the colour).
@@ -2024,6 +2027,8 @@ var LookAxis;
2024
2027
  LookAxis["Corners"] = "corners";
2025
2028
  LookAxis["Buttons"] = "buttons";
2026
2029
  LookAxis["Spacing"] = "spacing";
2030
+ /** The site's content column (award §0c, AW-D33): wide · contained · narrow — every page without its own word follows. */
2031
+ LookAxis["Column"] = "column";
2027
2032
  LookAxis["Type"] = "type";
2028
2033
  LookAxis["Mode"] = "mode";
2029
2034
  LookAxis["Speed"] = "speed";
@@ -2034,7 +2039,7 @@ var LookAxis;
2034
2039
  /** How the card names each axis (the builder translates it by the axis). */
2035
2040
  const LOOK_AXIS_LABELS = {
2036
2041
  [LookAxis.Style]: 'Style', [LookAxis.Colour]: 'Brand colour', [LookAxis.Tint]: 'Background tint', [LookAxis.Corners]: 'Corners',
2037
- [LookAxis.Buttons]: 'Buttons', [LookAxis.Spacing]: 'Spacing', [LookAxis.Type]: 'Fonts', [LookAxis.Mode]: 'Mode', [LookAxis.Speed]: 'Speed',
2042
+ [LookAxis.Buttons]: 'Buttons', [LookAxis.Spacing]: 'Spacing', [LookAxis.Column]: 'Content width', [LookAxis.Type]: 'Fonts', [LookAxis.Mode]: 'Mode', [LookAxis.Speed]: 'Speed',
2038
2043
  [LookAxis.Scrolling]: 'Scrolling', [LookAxis.Entrances]: 'How animated', [LookAxis.Between]: 'Between pages',
2039
2044
  };
2040
2045
  /** The axes in the order a card lists them (and the answer asks them). */
@@ -2087,6 +2092,7 @@ function lookAxisValue(choices, axis) {
2087
2092
  return { id, label: BUTTON_LABELS[id] };
2088
2093
  }
2089
2094
  case LookAxis.Spacing: return { id: c.density, label: labelOf(SPEC_AXES.densities, c.density) };
2095
+ case LookAxis.Column: return { id: c.column ?? '', label: labelOf(SPEC_AXES.columns, c.column ?? '') };
2090
2096
  case LookAxis.Type: return { id: c.pairId, label: pairsOf(c.flavorId).find(p => p.id === c.pairId)?.label ?? c.pairId };
2091
2097
  case LookAxis.Mode: return { id: c.mode, label: MODE_LABELS[c.mode] ?? c.mode };
2092
2098
  case LookAxis.Speed: return { id: c.motion, label: labelOf(SPEC_AXES.motions, c.motion) };
@@ -2107,6 +2113,7 @@ function axisOptions(axis, current) {
2107
2113
  case LookAxis.Corners: return Object.keys(SPEC_AXES.shapes);
2108
2114
  case LookAxis.Buttons: return Object.values(LookButtons);
2109
2115
  case LookAxis.Spacing: return Object.keys(SPEC_AXES.densities);
2116
+ case LookAxis.Column: return COLUMN_IDS;
2110
2117
  case LookAxis.Type: return pairsOf(resolveDesignChoices(current).flavorId).map(p => p.id);
2111
2118
  case LookAxis.Mode: return SPEC_AXES.modes;
2112
2119
  case LookAxis.Speed: return Object.keys(SPEC_AXES.motions);
@@ -2133,6 +2140,8 @@ function axisDescription(axis, current) {
2133
2140
  case LookAxis.Corners: return `Corner roundness everywhere. ${keep} ${options(Object.keys(SPEC_AXES.shapes), id => labelOf(SPEC_AXES.shapes, id))}`;
2134
2141
  case LookAxis.Buttons: return `Button shape. ${keep} ${options(Object.values(LookButtons), id => BUTTON_LABELS[id])}`;
2135
2142
  case LookAxis.Spacing: return `Space around and between every section of the site. ${keep} ${options(Object.keys(SPEC_AXES.densities), id => labelOf(SPEC_AXES.densities, id))}`;
2143
+ case LookAxis.Column: return `How wide the column the site's words, cards and lists sit in is — backgrounds, pictures and `
2144
+ + `Scenes still reach the edges; a page that set its own keeps it. ${keep} ${options(COLUMN_IDS, id => `${labelOf(SPEC_AXES.columns, id)}: ${SPEC_AXES.columns[id].desc}`)}`;
2136
2145
  case LookAxis.Type: return `The site's fonts, as one of the pairings the current style offers. ${keep} ${options(axisOptions(axis, current), id => pairsOf(resolveDesignChoices(current).flavorId).find(p => p.id === id)?.label ?? id)}`;
2137
2146
  case LookAxis.Mode: return `Light or dark site. ${keep} ${options(SPEC_AXES.modes, id => MODE_LABELS[id])}`;
2138
2147
  case LookAxis.Speed: return `How fast buttons and cards respond and things move. ${keep} ${options(Object.keys(SPEC_AXES.motions), id => labelOf(SPEC_AXES.motions, id))}`;
@@ -2235,6 +2244,12 @@ function applyLookEdits(current, edits) {
2235
2244
  if (v)
2236
2245
  next = { ...next, density: v };
2237
2246
  }
2247
+ // A width is layout, never paint: it moves no colour, so it never meets the contrast audit below.
2248
+ if (has(LookAxis.Column)) {
2249
+ const v = valid(LookAxis.Column, COLUMN_IDS);
2250
+ if (v)
2251
+ next = { ...next, column: v };
2252
+ }
2238
2253
  if (has(LookAxis.Type)) {
2239
2254
  const pairs = pairsOf(next.flavorId);
2240
2255
  const v = asked[LookAxis.Type];
@@ -2775,7 +2790,7 @@ const isRunBusy = (status) => !!status && RUN_BUSY.has(status);
2775
2790
  /** What the server refuses in a run request against the turn's drafts: none, unknown or repeated picks. */
2776
2791
  function validateRunRequest(req, drafts) {
2777
2792
  const issue = (code, message, handle) => ({ code, message, ...(handle ? { handle } : {}) });
2778
- if (!isObject(req))
2793
+ if (!isObject$1(req))
2779
2794
  return [issue(AssistIssueCode.BadRequest, 'a run is an object')];
2780
2795
  const picks = req['picks'];
2781
2796
  if (!Array.isArray(picks) || !picks.length || !picks.every(nonEmpty))
@@ -2784,7 +2799,7 @@ function validateRunRequest(req, drafts) {
2784
2799
  return [
2785
2800
  ...picks.filter(p => !known.has(p)).map(p => issue(AssistIssueCode.UnknownHandle, `"${p}" is not a draft of this turn`, p)),
2786
2801
  ...(new Set(picks).size !== picks.length ? [issue(AssistIssueCode.Duplicate, 'a draft is picked twice')] : []),
2787
- ...(req['fill'] !== undefined && !isObject(req['fill']) ? [issue(AssistIssueCode.BadRequest, 'fill is an object of field → text')] : []),
2802
+ ...(req['fill'] !== undefined && !isObject$1(req['fill']) ? [issue(AssistIssueCode.BadRequest, 'fill is an object of field → text')] : []),
2788
2803
  ];
2789
2804
  }
2790
2805
  var AssistRouteKey;
@@ -2897,7 +2912,7 @@ function sessionMemory(turns) {
2897
2912
  .slice(-MEMORY_TURNS)
2898
2913
  .map(memoryLine);
2899
2914
  }
2900
- const isObject = (v) => !!v && typeof v === 'object' && !Array.isArray(v);
2915
+ const isObject$1 = (v) => !!v && typeof v === 'object' && !Array.isArray(v);
2901
2916
  const nonEmpty = (v) => typeof v === 'string' && v.trim() !== '';
2902
2917
  /** Absent, or a list of non-empty field keys. */
2903
2918
  const isOwnerEdited = (v) => v === undefined || (Array.isArray(v) && v.every(nonEmpty));
@@ -2912,7 +2927,7 @@ function photoIssues(photos, grouping) {
2912
2927
  out.push(issue('a photos turn names its photos'));
2913
2928
  else if (photos.length > MAX_ASSIST_PHOTOS)
2914
2929
  out.push(issue(`at most ${MAX_ASSIST_PHOTOS} photos a turn`));
2915
- else if (!photos.every(p => isObject(p) && nonEmpty(p['key'])))
2930
+ else if (!photos.every(p => isObject$1(p) && nonEmpty(p['key'])))
2916
2931
  out.push(issue('each photo is its storage key'));
2917
2932
  else if (new Set(photos.map(p => p['key'])).size !== photos.length)
2918
2933
  out.push(issue('a photo is named twice'));
@@ -2923,7 +2938,7 @@ function photoIssues(photos, grouping) {
2923
2938
  /** What the server refuses in a posted turn before anything runs. Empty = accepted. */
2924
2939
  function validateTurnRequest(req) {
2925
2940
  const issue = (code, message) => ({ code, message });
2926
- if (!isObject(req))
2941
+ if (!isObject$1(req))
2927
2942
  return [issue(AssistIssueCode.BadRequest, 'a turn is an object')];
2928
2943
  const surface = req['surface'];
2929
2944
  const spec = Object.prototype.hasOwnProperty.call(SURFACES, surface) ? SURFACES[surface] : undefined;
@@ -2940,10 +2955,10 @@ function validateTurnRequest(req) {
2940
2955
  ...(spec.readsPhotos && spec.commit === CommitKind.Run ? photoIssues(req['photos'], req['grouping']) : []),
2941
2956
  ...(nonEmpty(sentence) && sentence.length > MAX_SENTENCE_CHARS ? [issue(AssistIssueCode.SentenceTooLong, `the sentence is over ${MAX_SENTENCE_CHARS} characters`)] : []),
2942
2957
  ...(!nonEmpty(req['model']) ? [issue(AssistIssueCode.BadRequest, 'no model choice (auto or a model id)')] : []),
2943
- ...(!isObject(brief) || brief['surface'] !== surface ? [issue(AssistIssueCode.BadRequest, `the brief is not a ${surface} brief`)] : []),
2944
- ...(!isObject(req['handles']) || !Object.keys(req['handles']).length ? [issue(AssistIssueCode.MissingHandles, 'the brief\'s handles are missing')] : []),
2945
- ...(spec.commit === CommitKind.FormFill && !isObject(req['values']) ? [issue(AssistIssueCode.MissingValues, 'a form-fill turn carries the form\'s values')] : []),
2946
- ...(spec.commit === CommitKind.BuilderStep && (!Array.isArray(req['layout']) || !req['layout'].length || !req['layout'].every(isObject))
2958
+ ...(!isObject$1(brief) || brief['surface'] !== surface ? [issue(AssistIssueCode.BadRequest, `the brief is not a ${surface} brief`)] : []),
2959
+ ...(!isObject$1(req['handles']) || !Object.keys(req['handles']).length ? [issue(AssistIssueCode.MissingHandles, 'the brief\'s handles are missing')] : []),
2960
+ ...(spec.commit === CommitKind.FormFill && !isObject$1(req['values']) ? [issue(AssistIssueCode.MissingValues, 'a form-fill turn carries the form\'s values')] : []),
2961
+ ...(spec.commit === CommitKind.BuilderStep && (!Array.isArray(req['layout']) || !req['layout'].length || !req['layout'].every(isObject$1))
2947
2962
  ? [issue(AssistIssueCode.MissingValues, 'a builder turn carries the page\'s layout')] : []),
2948
2963
  ...(spec.commit === CommitKind.BuilderStep && !nonEmpty(req['pageId']) ? [issue(AssistIssueCode.BadRequest, `${surface} names its page`)] : []),
2949
2964
  ...(!isOwnerEdited(req['ownerEdited']) ? [issue(AssistIssueCode.BadRequest, 'ownerEdited is a list of field keys')] : []),
@@ -2951,6 +2966,249 @@ function validateTurnRequest(req) {
2951
2966
  ];
2952
2967
  }
2953
2968
 
2969
+ /**
2970
+ * FILES BOX ▸ GENERATE — the vocabulary of AI Assist's surface S7 (ai-assist-plan §2 "S7", A-D14 · A-D15 · A-D16), the
2971
+ * pictures half. ONE spelling for the Files box (iox-cms-client), the route that makes the pictures (iox-cms) and the
2972
+ * proof: what may be asked, how the asked words become the prompt, what it costs before the button, when it is refused
2973
+ * before any call, and what a made picture is afterwards.
2974
+ *
2975
+ * It adds NO generator: a picture is made by the M7 pipeline (`AiStep.MakePictures`), looked at by the same review
2976
+ * (`AiStep.CheckPictures`, `PictureReview`), under the same art-direction preamble (`artDirectionPreamble`). What differs
2977
+ * from a site build's pictures is the owner's part: THEY write the words, THEY choose how many, and every candidate made
2978
+ * is charged and KEPT — a review that says no marks the picture, it does not buy a second try (gateway rule 3, R-H12).
2979
+ */
2980
+ var GenerateKind;
2981
+ (function (GenerateKind) {
2982
+ GenerateKind["Photo"] = "photo";
2983
+ GenerateKind["Video"] = "video";
2984
+ })(GenerateKind || (GenerateKind = {}));
2985
+ /** Why a kind cannot be made yet — the Files box says it in words, never with a button that fails (R-H13). */
2986
+ var GenerateUnavailable;
2987
+ (function (GenerateUnavailable) {
2988
+ /** No provider makes a video from a start picture yet (`generateVideo`, premium-sites SC6c). */
2989
+ GenerateUnavailable["NoProvider"] = "noProvider";
2990
+ })(GenerateUnavailable || (GenerateUnavailable = {}));
2991
+ /** What each kind can do today. Video turns on here, in one place, the day a provider exists. */
2992
+ const GENERATE_KINDS = {
2993
+ [GenerateKind.Photo]: { available: true },
2994
+ [GenerateKind.Video]: { available: false, why: GenerateUnavailable.NoProvider },
2995
+ };
2996
+ /** How many candidates one press makes. */
2997
+ const GENERATE_COUNTS = [1, 2, 4];
2998
+ const GENERATE_COUNT_DEFAULT = 4;
2999
+ /** The frames offered (each a frame the image model is asked for — `PICTURE_ASPECTS`), widest first. */
3000
+ const GENERATE_SHAPES = ['16:9', '4:3', '1:1', '3:4', '9:16'];
3001
+ const GENERATE_SHAPE_DEFAULT = '4:3';
3002
+ const GENERATE_PROMPT_MIN = 3;
3003
+ const GENERATE_PROMPT_MAX = 600;
3004
+ var GenerateIssueCode;
3005
+ (function (GenerateIssueCode) {
3006
+ GenerateIssueCode["Shape"] = "shape";
3007
+ GenerateIssueCode["Kind"] = "kind";
3008
+ GenerateIssueCode["KindUnavailable"] = "kindUnavailable";
3009
+ GenerateIssueCode["Prompt"] = "prompt";
3010
+ GenerateIssueCode["PromptTooLong"] = "promptTooLong";
3011
+ GenerateIssueCode["Frame"] = "frame";
3012
+ GenerateIssueCode["Count"] = "count";
3013
+ GenerateIssueCode["Model"] = "model";
3014
+ })(GenerateIssueCode || (GenerateIssueCode = {}));
3015
+ const isObject = (v) => !!v && typeof v === 'object' && !Array.isArray(v);
3016
+ const REQUEST_KEYS = ['kind', 'prompt', 'shape', 'count', 'look', 'model', 'slot'];
3017
+ /** What is wrong with a value as a request to generate pictures — nothing is repaired, each fault has its path. */
3018
+ function generateRequestIssues(value) {
3019
+ if (!isObject(value))
3020
+ return [{ code: GenerateIssueCode.Shape, path: '', message: 'must be an object' }];
3021
+ const v = value;
3022
+ const issues = [];
3023
+ const say = (code, path, message) => issues.push({ code, path, message });
3024
+ const kinds = Object.values(GenerateKind);
3025
+ if (typeof v.kind !== 'string' || !kinds.includes(v.kind))
3026
+ say(GenerateIssueCode.Kind, 'kind', `one of ${kinds.join(', ')}`);
3027
+ else if (!GENERATE_KINDS[v.kind].available)
3028
+ say(GenerateIssueCode.KindUnavailable, 'kind', `${v.kind} cannot be made yet`);
3029
+ const prompt = typeof v.prompt === 'string' ? v.prompt.trim() : '';
3030
+ if (prompt.length < GENERATE_PROMPT_MIN)
3031
+ say(GenerateIssueCode.Prompt, 'prompt', 'describe the picture');
3032
+ else if (prompt.length > GENERATE_PROMPT_MAX)
3033
+ say(GenerateIssueCode.PromptTooLong, 'prompt', `at most ${GENERATE_PROMPT_MAX} characters`);
3034
+ if (typeof v.shape !== 'string' || !GENERATE_SHAPES.includes(v.shape))
3035
+ say(GenerateIssueCode.Frame, 'shape', `one of ${GENERATE_SHAPES.join(', ')}`);
3036
+ if (typeof v.count !== 'number' || !GENERATE_COUNTS.includes(v.count))
3037
+ say(GenerateIssueCode.Count, 'count', `one of ${GENERATE_COUNTS.join(', ')}`);
3038
+ if (typeof v.look !== 'boolean')
3039
+ say(GenerateIssueCode.Shape, 'look', 'must be true or false');
3040
+ if (v.model !== undefined && (typeof v.model !== 'string' || !v.model))
3041
+ say(GenerateIssueCode.Model, 'model', 'a model id, or absent');
3042
+ if (v.slot !== undefined) {
3043
+ if (!isObject(v.slot))
3044
+ say(GenerateIssueCode.Shape, 'slot', 'must be an object');
3045
+ else {
3046
+ const slot = v.slot;
3047
+ if (slot.aspect !== undefined && !(typeof slot.aspect === 'number' && slot.aspect > 0 && Number.isFinite(slot.aspect)))
3048
+ say(GenerateIssueCode.Shape, 'slot.aspect', 'a positive number');
3049
+ const area = slot.wordsArea;
3050
+ const good = !!area && typeof area === 'object' && (area.edge === 'top' || area.edge === 'bottom') && typeof area.share === 'number' && area.share > 0 && area.share <= 1;
3051
+ if (slot.wordsArea !== undefined && !good)
3052
+ say(GenerateIssueCode.Shape, 'slot.wordsArea', '{ edge: top | bottom, share: 0–1 }');
3053
+ }
3054
+ }
3055
+ for (const key of Object.keys(value))
3056
+ if (!REQUEST_KEYS.includes(key))
3057
+ say(GenerateIssueCode.Shape, key, 'is not a key of the request');
3058
+ return issues;
3059
+ }
3060
+ /**
3061
+ * The offered frame nearest a slot ("fits the slot"): by the ratio of the two shapes, so 4:5 goes to 3:4 and never to
3062
+ * 1:1 by a hair. No slot, or one with no shape yet = the default.
3063
+ */
3064
+ function shapeForSlot(aspect) {
3065
+ if (!(typeof aspect === 'number' && aspect > 0 && Number.isFinite(aspect)))
3066
+ return GENERATE_SHAPE_DEFAULT;
3067
+ let best = GENERATE_SHAPE_DEFAULT, distance = Infinity;
3068
+ for (const shape of GENERATE_SHAPES) {
3069
+ const d = Math.abs(Math.log(PICTURE_ASPECTS[shape] / aspect));
3070
+ if (d < distance) {
3071
+ best = shape;
3072
+ distance = d;
3073
+ }
3074
+ }
3075
+ return best;
3076
+ }
3077
+ /**
3078
+ * The prompt a generated picture is asked with: the site's preamble VERBATIM when "Your look" is on (the same one a
3079
+ * site build's pictures get — one preamble per prompt), then the OWNER'S WORDS as written, the frame, and the part left
3080
+ * calm for words when the slot has words over it. Nothing else is added and nothing of the owner's is rewritten.
3081
+ */
3082
+ function generatePicturePrompt(request, direction) {
3083
+ return [
3084
+ ...(request.look && direction ? [artDirectionPreamble(direction)] : []),
3085
+ request.prompt.trim(),
3086
+ frameWords(request.shape),
3087
+ ...(request.slot?.wordsArea ? [emptyAreaPhrase(request.slot.wordsArea)] : []),
3088
+ ].join('\n');
3089
+ }
3090
+ /** Words an image model draws badly: asked for inside the picture, they come out wrong (the honesty line). */
3091
+ const WORDS_ASKED = /\b(logo|text|words?|sign|signage|letters?|caption|title|headline|slogan|typography)\b|כיתוב|טקסט|לוגו|כותרת|אותיות|שלט|סלוגן/i;
3092
+ /** True when the owner's words ask for writing INSIDE the picture — the box says "put the words on the page". */
3093
+ function promptAsksForWords(prompt) {
3094
+ return WORDS_ASKED.test(prompt ?? '');
3095
+ }
3096
+ /**
3097
+ * "Describe from the page": the words the box fills in for the element that opened it — the section's own words and
3098
+ * the kind of business, never the business's name (it would be drawn). No model is asked; empty when the page says
3099
+ * nothing.
3100
+ */
3101
+ function describeFromPage(context) {
3102
+ const business = (context.business ?? '').trim();
3103
+ const words = (context.words ?? '').replace(/\s+/g, ' ').trim().slice(0, 240);
3104
+ if (!business && !words)
3105
+ return '';
3106
+ const subject = business ? `A picture for ${business}` : 'A picture for this part of the page';
3107
+ return (words ? `${subject}. It goes beside these words: “${words}”.` : `${subject}.`).slice(0, GENERATE_PROMPT_MAX);
3108
+ }
3109
+ /**
3110
+ * The cost shown under the box (A-D15: the owner chooses the cost): every candidate is made once and looked at once.
3111
+ * Unlike a site build's pictures (`estimatePictures`) there is NO second try in it — a candidate the review says no to
3112
+ * is kept and marked, and the owner decides whether to press again.
3113
+ */
3114
+ function estimateGenerate(count, prices) {
3115
+ const picture = estimateStepCredits(AiStep.MakePictures, prices.image);
3116
+ const review = estimateStepCredits(AiStep.CheckPictures, prices.review);
3117
+ const n = Math.max(0, Math.floor(count));
3118
+ return { count: n, picture, review, each: creditsOfUsd((picture + review) / 100), total: creditsOfUsd((n * (picture + review)) / 100) };
3119
+ }
3120
+ /**
3121
+ * The picture models of the vetted list, each with its estimate for ONE candidate, the default first. A retired model
3122
+ * or one that cannot make a picture is never offered.
3123
+ */
3124
+ function generateModelChoices(models, review) {
3125
+ const step = AiStep.MakePictures;
3126
+ return models
3127
+ .filter(m => !m.retired && m.steps.includes(step) && modelCanDo(m, step))
3128
+ .map(m => ({ id: m.id, label: m.label, recommended: !!m.recommendedFor?.includes(step), each: m.price ? estimateGenerate(1, { image: m.price, review }).each : null }))
3129
+ .sort((a, b) => Number(b.recommended) - Number(a.recommended));
3130
+ }
3131
+ /**
3132
+ * The plan features Generate needs: the surface's own (AI Assist, A-D6) AND the one each step it runs belongs to
3133
+ * (`AI_STEP_FEATURE` — the picture steps are the site generator's). A plan missing any is refused `NotInPlan`.
3134
+ */
3135
+ const GENERATE_FEATURES = Array.from(new Set([AiFeature.Assist, AI_STEP_FEATURE[AiStep.MakePictures], AI_STEP_FEATURE[AiStep.CheckPictures]]));
3136
+ /**
3137
+ * May this press run? The answer BEFORE any provider call (R-H12): the plan is known, it includes what Generate needs,
3138
+ * and the credits left cover the cost shown. The Files box asks it to disable the button and say why; iox-cms asks it
3139
+ * again with its own numbers before the first call — the client's are never trusted. Null = go.
3140
+ * A studio on its own key has no meter (`remaining: null`) and is never refused for credits.
3141
+ */
3142
+ function generateRefusal(estimate, entitlements) {
3143
+ if (!entitlements || !entitlements.known)
3144
+ return { code: AiRefusalCode.PlanUnknown, next: { kind: aiRefusalNext(AiRefusalCode.PlanUnknown) } };
3145
+ const missing = GENERATE_FEATURES.find(f => entitlements.features?.[f] !== true);
3146
+ if (missing)
3147
+ return { code: AiRefusalCode.NotInPlan, planName: entitlements.planName, next: { kind: aiRefusalNext(AiRefusalCode.NotInPlan) } };
3148
+ const remaining = entitlements.meter?.remaining;
3149
+ if (typeof remaining === 'number' && estimate.total > remaining) {
3150
+ const buy = entitlements.meter?.buy ?? null;
3151
+ return {
3152
+ code: AiRefusalCode.OutOfCredits, planName: entitlements.planName, remaining, estimate: estimate.total,
3153
+ next: { kind: aiRefusalNext(AiRefusalCode.OutOfCredits, buy), ...(buy ? { href: buy.url } : {}) },
3154
+ };
3155
+ }
3156
+ return null;
3157
+ }
3158
+ // ── A candidate, once made ────────────────────────────────────────────────────────────────────
3159
+ /** Where one candidate stands — the tile's state in the grid. */
3160
+ var CandidateState;
3161
+ (function (CandidateState) {
3162
+ CandidateState["Making"] = "making";
3163
+ CandidateState["Checking"] = "checking";
3164
+ /** Made, looked at, kept. */
3165
+ CandidateState["Kept"] = "kept";
3166
+ /** Made and kept, but the look found something the owner should see (words in it, a warped hand). */
3167
+ CandidateState["Flagged"] = "flagged";
3168
+ /** Not made: the provider failed. Nothing was charged for it. */
3169
+ CandidateState["Failed"] = "failed";
3170
+ })(CandidateState || (CandidateState = {}));
3171
+ /** What the look found, in the order the tile says it. */
3172
+ var CandidateFlag;
3173
+ (function (CandidateFlag) {
3174
+ /** Writing, a logo or a watermark inside the picture. */
3175
+ CandidateFlag["Words"] = "words";
3176
+ /** Warped hands, faces or objects. */
3177
+ CandidateFlag["Anatomy"] = "anatomy";
3178
+ /** Not what was asked for. */
3179
+ CandidateFlag["Subject"] = "subject";
3180
+ /** The part left for words is too busy to read over. */
3181
+ CandidateFlag["CalmArea"] = "calmArea";
3182
+ })(CandidateFlag || (CandidateFlag = {}));
3183
+ /**
3184
+ * A made picture after its look: KEPT either way (it was paid for), flagged when the review says no — the same four
3185
+ * answers a site build's review gives (`pictureReviewPasses`), read here as marks instead of a reason to try again.
3186
+ */
3187
+ function candidateVerdict(review, slot) {
3188
+ const flags = [];
3189
+ if (!review.clean)
3190
+ flags.push(CandidateFlag.Words);
3191
+ if (!review.anatomy)
3192
+ flags.push(CandidateFlag.Anatomy);
3193
+ if (!review.subject)
3194
+ flags.push(CandidateFlag.Subject);
3195
+ if (slot?.wordsArea && !review.calmArea)
3196
+ flags.push(CandidateFlag.CalmArea);
3197
+ const passes = pictureReviewPasses(review, { wordsArea: slot?.wordsArea });
3198
+ return { state: passes ? CandidateState.Kept : CandidateState.Flagged, flags: passes ? [] : flags, alt: review.alt.trim() };
3199
+ }
3200
+ const FINAL = [CandidateState.Kept, CandidateState.Flagged, CandidateState.Failed];
3201
+ function generateOutcome(candidates) {
3202
+ const made = candidates.filter(c => c.state === CandidateState.Kept || c.state === CandidateState.Flagged);
3203
+ return {
3204
+ made: made.length,
3205
+ flagged: candidates.filter(c => c.state === CandidateState.Flagged).length,
3206
+ failed: candidates.filter(c => c.state === CandidateState.Failed).length,
3207
+ credits: creditsOfUsd(candidates.reduce((sum, c) => sum + (c.credits ?? 0), 0) / 100),
3208
+ done: candidates.length > 0 && candidates.every(c => FINAL.includes(c.state)),
3209
+ };
3210
+ }
3211
+
2954
3212
  /**
2955
3213
  * @vectoriox/iox-ui/assist-core — the shared, FRAMEWORK-FREE vocabulary of AI Assist (iox-ai-guidance
2956
3214
  * `architecture/ai/ai-assist-plan.md` §3b): the surfaces and their specs, the brief and its handle map, the route
@@ -2971,5 +3229,5 @@ function validateTurnRequest(req) {
2971
3229
  * Generated bundle index. Do not edit.
2972
3230
  */
2973
3231
 
2974
- export { AI_DRAFT_SOURCE, AROUND_ITEMS_MAX, AROUND_TEXT_CHARS, ASK_SECTION_PATTERNS, ASK_STYLE_SETS, ASSIST_MODEL_AUTO, ASSIST_POLL_MS, ASSIST_ROUTES, AssistBriefError, AssistBudgetError, AssistFieldKind, AssistHandOff, AssistIssueCode, AssistMemoryOutcome, AssistPathError, AssistPermission, AssistRefusalCode, AssistRouteKey, AssistRunStatus, AssistScope, AssistStep, AssistSurface, AssistTurnStatus, BOOLEAN_FALSE, BOOLEAN_TRUE, CommitKind, EditFamily, FIELDS_PER_PART, FIELD_HANDLE_PREFIX, FOCUS_TEXT_CHARS, FieldsAnswerKey, ItemSuggestionKind, LOCALE_NAME_LANGUAGES, LOOK_AXES, LOOK_AXIS_LABELS, LOOK_KEEP, LookAnswerKey, LookAxis, LookButtons, MAX_ASSIST_PHOTOS, MAX_ASSIST_PROPERTIES, MAX_ROUTE_PROPERTIES, MAX_SENTENCE_CHARS, MEMORY_TURNS, MODE_LABELS, NEW_TARGET, NONE_TEXT, NeverWriteReason, OWNER_FILL_MAX_CHARS, PAGE_WORD_SLOTS, PHOTOS_PER_READ, PHOTO_GROUP_HANDLE_PREFIX, PageChangeOp, PagePartKind, PageSuggestionKind, PhotoAnswerKey, PhotoGrouping, RouteAnswerKey, SECTION_START, SHORTEN_FROM_CHARS, SHORTEN_HEADING_FROM_CHARS, SHORTEN_TEXT_FROM_CHARS, SIBLING_HANDLE_PREFIX, SURFACES, SectionChangeKind, SectionsAnswerKey, StyleAnswerKey, SurfaceStatus, ValueSource, WORDS_PER_PART, WordsAnswerKey, adjustAxesOf, aiDraftStamp, applyFieldEdits, applyLookEdits, applyPageEdits, applySectionEdits, applyStyleEdits, applyWordEdits, askSectionPatternNames, askableStyles, assertAssistBudget, assistBudgetIssues, assistFactIssues, assistFields, assistPath, assistSession, assistSessionKey, builtSurfaces, clipText, commitOf, containsHtml, decodeFieldsAnswers, decodeLookAnswers, decodePhotoDraftAnswers, decodeSectionsAnswers, decodeStyleAnswers, decodeWordsAnswers, draftFromPhotos, escapeText, fieldHandle, fieldsJsonSchema, fieldsNamedIn, groupPhotos, isAiDraft, isEmptyFieldValue, isPlainRecord, isRunBusy, isSchemeEdit, isSectionEdit, isSessionOf, isSiteLookEdit, isSizeEdit, isStyleEdit, isTerminalTurn, isWritable, itemLocales, itemSuggestions, languageName, lookAxisValue, lookHex, lookJsonSchema, lookNames, memoryLine, namedLocale, ownerFillFields, ownerFillIssues, pageLooks, pageSuggestions, pageWriteLocale, paragraphsToRichText, photoDraftJsonSchema, photoGroupBrief, photoGroupHandle, photoReadCount, photoSlots, primaryLocale, readFieldValue, readLocaleValues, readRoute, readableWords, resolveHandle, richTextParagraphs, routeJsonSchema, sectionLabel, sectionPatternOf, sectionsJsonSchema, serializedBaselineStyles, sessionMemory, styleJsonSchema, suggestPhotoType, summarizeItem, summarizeLook, summarizePage, summarizePhotos, surfacePermissions, surfaceSpec, surfaceUndoPermissions, takesPhotos, titleField, turnLocale, unknownHandles, validateRunRequest, validateTurnRequest, withOwnerFill, wordsJsonSchema };
3232
+ export { AI_DRAFT_SOURCE, AROUND_ITEMS_MAX, AROUND_TEXT_CHARS, ASK_SECTION_PATTERNS, ASK_STYLE_SETS, ASSIST_MODEL_AUTO, ASSIST_POLL_MS, ASSIST_ROUTES, AssistBriefError, AssistBudgetError, AssistFieldKind, AssistHandOff, AssistIssueCode, AssistMemoryOutcome, AssistPathError, AssistPermission, AssistRefusalCode, AssistRouteKey, AssistRunStatus, AssistScope, AssistStep, AssistSurface, AssistTurnStatus, BOOLEAN_FALSE, BOOLEAN_TRUE, CandidateFlag, CandidateState, CommitKind, EditFamily, FIELDS_PER_PART, FIELD_HANDLE_PREFIX, FOCUS_TEXT_CHARS, FieldsAnswerKey, GENERATE_COUNTS, GENERATE_COUNT_DEFAULT, GENERATE_FEATURES, GENERATE_KINDS, GENERATE_PROMPT_MAX, GENERATE_PROMPT_MIN, GENERATE_SHAPES, GENERATE_SHAPE_DEFAULT, GenerateIssueCode, GenerateKind, GenerateUnavailable, ItemSuggestionKind, LOCALE_NAME_LANGUAGES, LOOK_AXES, LOOK_AXIS_LABELS, LOOK_KEEP, LookAnswerKey, LookAxis, LookButtons, MAX_ASSIST_PHOTOS, MAX_ASSIST_PROPERTIES, MAX_ROUTE_PROPERTIES, MAX_SENTENCE_CHARS, MEMORY_TURNS, MODE_LABELS, NEW_TARGET, NONE_TEXT, NeverWriteReason, OWNER_FILL_MAX_CHARS, PAGE_WORD_SLOTS, PHOTOS_PER_READ, PHOTO_GROUP_HANDLE_PREFIX, PageChangeOp, PagePartKind, PageSuggestionKind, PhotoAnswerKey, PhotoGrouping, RouteAnswerKey, SECTION_START, SHORTEN_FROM_CHARS, SHORTEN_HEADING_FROM_CHARS, SHORTEN_TEXT_FROM_CHARS, SIBLING_HANDLE_PREFIX, SURFACES, SectionChangeKind, SectionsAnswerKey, StyleAnswerKey, SurfaceStatus, ValueSource, WORDS_PER_PART, WordsAnswerKey, adjustAxesOf, aiDraftStamp, applyFieldEdits, applyLookEdits, applyPageEdits, applySectionEdits, applyStyleEdits, applyWordEdits, askSectionPatternNames, askableStyles, assertAssistBudget, assistBudgetIssues, assistFactIssues, assistFields, assistPath, assistSession, assistSessionKey, builtSurfaces, candidateVerdict, clipText, commitOf, containsHtml, decodeFieldsAnswers, decodeLookAnswers, decodePhotoDraftAnswers, decodeSectionsAnswers, decodeStyleAnswers, decodeWordsAnswers, describeFromPage, draftFromPhotos, escapeText, estimateGenerate, fieldHandle, fieldsJsonSchema, fieldsNamedIn, generateModelChoices, generateOutcome, generatePicturePrompt, generateRefusal, generateRequestIssues, groupPhotos, isAiDraft, isEmptyFieldValue, isPlainRecord, isRunBusy, isSchemeEdit, isSectionEdit, isSessionOf, isSiteLookEdit, isSizeEdit, isStyleEdit, isTerminalTurn, isWritable, itemLocales, itemSuggestions, languageName, lookAxisValue, lookHex, lookJsonSchema, lookNames, memoryLine, namedLocale, ownerFillFields, ownerFillIssues, pageLooks, pageSuggestions, pageWriteLocale, paragraphsToRichText, photoDraftJsonSchema, photoGroupBrief, photoGroupHandle, photoReadCount, photoSlots, primaryLocale, promptAsksForWords, readFieldValue, readLocaleValues, readRoute, readableWords, resolveHandle, richTextParagraphs, routeJsonSchema, sectionLabel, sectionPatternOf, sectionsJsonSchema, serializedBaselineStyles, sessionMemory, shapeForSlot, styleJsonSchema, suggestPhotoType, summarizeItem, summarizeLook, summarizePage, summarizePhotos, surfacePermissions, surfaceSpec, surfaceUndoPermissions, takesPhotos, titleField, turnLocale, unknownHandles, validateRunRequest, validateTurnRequest, withOwnerFill, wordsJsonSchema };
2975
3233
  //# sourceMappingURL=vectoriox-iox-ui-assist-core.mjs.map