@vectoriox/iox-ui 5.111.0 → 5.112.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.
- package/assist-core/index.d.ts +650 -0
- package/assist-core/package.json +3 -0
- package/fesm2022/vectoriox-iox-ui-assist-core.mjs +1144 -0
- package/fesm2022/vectoriox-iox-ui-assist-core.mjs.map +1 -0
- package/fesm2022/vectoriox-iox-ui-generation-core.mjs +45 -4
- package/fesm2022/vectoriox-iox-ui-generation-core.mjs.map +1 -1
- package/generation-core/index.d.ts +18 -3
- package/package.json +5 -1
- package/src/assist-core/assist-locale.ts +73 -0
- package/src/assist-core/assist-turn.ts +240 -0
- package/src/assist-core/brief.ts +98 -0
- package/src/assist-core/budget.ts +34 -0
- package/src/assist-core/content-fields.ts +256 -0
- package/src/assist-core/field-edits.ts +178 -0
- package/src/assist-core/field-values.ts +42 -0
- package/src/assist-core/fields-schema.ts +117 -0
- package/src/assist-core/public-api.ts +24 -0
- package/src/assist-core/rich-text.ts +32 -0
- package/src/assist-core/route-schema.ts +49 -0
- package/src/assist-core/summarize-item.ts +219 -0
- package/src/assist-core/surfaces.ts +235 -0
- package/src/generation-core/ai-run.ts +34 -0
- package/src/generation-core/plan-words.ts +12 -3
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { jsonAnyOf, jsonClosedObject, jsonListOf, jsonOneOf, JsonSchema, jsonText } from '@vectoriox/iox-ui/generation-core';
|
|
2
|
+
|
|
3
|
+
import { assertAssistBudget, MAX_ROUTE_PROPERTIES } from './budget';
|
|
4
|
+
import { AssistIssue, AssistIssueCode } from './brief';
|
|
5
|
+
import { AssistSurface, EditFamily, SURFACES } from './surfaces';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* The route request (plan §3c rule 5): the first, small, fast question of every turn — which of THIS surface's
|
|
9
|
+
* families the sentence needs, or `cannot` with one line for the owner. Its family enum is the surface's, so the model
|
|
10
|
+
* cannot route a content-item sentence to the builder's Style.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
export enum RouteAnswerKey {
|
|
14
|
+
Families = 'families',
|
|
15
|
+
Cannot = 'cannot',
|
|
16
|
+
Reply = 'reply',
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function routeJsonSchema(surface: AssistSurface): JsonSchema {
|
|
20
|
+
const schema = jsonClosedObject({
|
|
21
|
+
[RouteAnswerKey.Families]: { ...jsonListOf(jsonOneOf(SURFACES[surface].families)), description: 'The kinds of change the sentence asks for, in the order to make them. [] when it cannot be done here.' },
|
|
22
|
+
[RouteAnswerKey.Cannot]: { ...jsonAnyOf([jsonText(), { type: 'null' }]), description: 'Why it cannot be done here, in one line in the sentence\'s language — or null.' },
|
|
23
|
+
[RouteAnswerKey.Reply]: { ...jsonText(), description: 'One short line to the owner, in the sentence\'s language.' },
|
|
24
|
+
}, Object.values(RouteAnswerKey));
|
|
25
|
+
assertAssistBudget(`route ${surface}`, [schema], MAX_ROUTE_PROPERTIES);
|
|
26
|
+
return schema;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface AssistRoute {
|
|
30
|
+
readonly ok: boolean;
|
|
31
|
+
readonly families: ReadonlyArray<EditFamily>;
|
|
32
|
+
readonly cannot: string | null;
|
|
33
|
+
readonly reply: string;
|
|
34
|
+
readonly issues: ReadonlyArray<AssistIssue>;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const text = (v: unknown): string => (typeof v === 'string' ? v.trim() : '');
|
|
38
|
+
|
|
39
|
+
/** A route answer, checked against its surface: a family the surface does not have is refused, repeats dropped. */
|
|
40
|
+
export function readRoute(surface: AssistSurface, answer: unknown): AssistRoute {
|
|
41
|
+
const a = (answer && typeof answer === 'object' ? answer : {}) as Record<string, unknown>;
|
|
42
|
+
const allowed = new Set<string>(SURFACES[surface].families);
|
|
43
|
+
const named = Array.isArray(a[RouteAnswerKey.Families]) ? (a[RouteAnswerKey.Families] as unknown[]).map(String) : [];
|
|
44
|
+
const issues: AssistIssue[] = named.filter(f => !allowed.has(f))
|
|
45
|
+
.map(f => ({ code: AssistIssueCode.UnknownFamily, message: `"${f}" is not a family of ${surface}` }));
|
|
46
|
+
const families = [...new Set(named.filter(f => allowed.has(f)))] as EditFamily[];
|
|
47
|
+
const cannot = text(a[RouteAnswerKey.Cannot]) || null;
|
|
48
|
+
return { ok: !issues.length, families: cannot ? [] : families, cannot, reply: text(a[RouteAnswerKey.Reply]), issues };
|
|
49
|
+
}
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import { AROUND_ITEMS_MAX, AROUND_TEXT_CHARS, MEMORY_TURNS } from './budget';
|
|
2
|
+
import { AssistBriefError, AssistIssueCode, Brief, FIELD_HANDLE_PREFIX, HandleMap, HandleTarget, NeverWrite, SIBLING_HANDLE_PREFIX } from './brief';
|
|
3
|
+
import { AssistField, AssistFieldKind, assistFields, ContentTypeSchema, isWritable, NeverWriteReason, titleField } from './content-fields';
|
|
4
|
+
import { BriefValue, isEmptyFieldValue, readFieldValue, readLocaleValues } from './field-values';
|
|
5
|
+
import { AssistScope, AssistSurface, SURFACES } from './surfaces';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* The brief of surface S2 — one content item (plan §3c, §4 S2). Focus = the item (every field as a handle `f.<key>`,
|
|
9
|
+
* its kind, label, full value, which locales a multiLang field has filled) or ONE field when the owner opened the
|
|
10
|
+
* field's sparkle; around = the rest of the item (when the focus is a field) and up to five sibling items of the type,
|
|
11
|
+
* each value clipped to 160 characters — examples of the studio's voice, never something to copy.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
export type ContentRecord = Readonly<Record<string, unknown>>;
|
|
15
|
+
|
|
16
|
+
export interface ItemBriefField {
|
|
17
|
+
readonly handle: string;
|
|
18
|
+
readonly label: string;
|
|
19
|
+
readonly kind: AssistFieldKind;
|
|
20
|
+
readonly required: boolean;
|
|
21
|
+
/** In the write locale for a multiLang field. */
|
|
22
|
+
readonly empty: boolean;
|
|
23
|
+
/** Absent on a never-written field: the model only learns whether it is filled. */
|
|
24
|
+
readonly value?: BriefValue;
|
|
25
|
+
readonly options?: ReadonlyArray<string>;
|
|
26
|
+
readonly locales?: { readonly filled: ReadonlyArray<string>; readonly empty: ReadonlyArray<string> };
|
|
27
|
+
readonly never?: NeverWriteReason;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface ItemFocus {
|
|
31
|
+
readonly scope: AssistScope;
|
|
32
|
+
readonly type: { readonly name: string; readonly label: string };
|
|
33
|
+
/** The item's name as the list shows it ('' for a new item). */
|
|
34
|
+
readonly title: string;
|
|
35
|
+
/** The `@title` field's handle, when the type has one. */
|
|
36
|
+
readonly titleHandle: string | null;
|
|
37
|
+
readonly fields: ReadonlyArray<ItemBriefField>;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface ItemSummary {
|
|
41
|
+
readonly handle: string;
|
|
42
|
+
readonly title: string;
|
|
43
|
+
/** handle → value, ≤ 160 characters. */
|
|
44
|
+
readonly fields: Readonly<Record<string, string>>;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface ItemAround {
|
|
48
|
+
/** The item's other fields, summarised — only when the focus is one field. */
|
|
49
|
+
readonly item: Readonly<Record<string, string>> | null;
|
|
50
|
+
readonly siblings: ReadonlyArray<ItemSummary>;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export type ItemBrief = Brief<ItemFocus, ItemAround>;
|
|
54
|
+
|
|
55
|
+
export interface ItemBriefContext {
|
|
56
|
+
/** The locale the turn writes in. */
|
|
57
|
+
readonly locale: string;
|
|
58
|
+
/** One field's key or handle: the per-field sparkle. */
|
|
59
|
+
readonly focusField?: string;
|
|
60
|
+
/** Other items of the type (the item itself is skipped); the first five are sent. */
|
|
61
|
+
readonly siblings?: ReadonlyArray<ContentRecord>;
|
|
62
|
+
readonly owner?: string | null;
|
|
63
|
+
readonly memory?: ReadonlyArray<string>;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export interface SummarizedItem {
|
|
67
|
+
readonly brief: ItemBrief;
|
|
68
|
+
readonly handles: HandleMap;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const ID_KEY = '_id';
|
|
72
|
+
const ELLIPSIS = '…';
|
|
73
|
+
const LIST_JOIN = ', ';
|
|
74
|
+
const PARAGRAPH_JOIN = '\n\n';
|
|
75
|
+
|
|
76
|
+
const TEXT_KINDS: ReadonlySet<AssistFieldKind> = new Set([AssistFieldKind.Text, AssistFieldKind.Textarea, AssistFieldKind.RichText]);
|
|
77
|
+
|
|
78
|
+
export const clipText = (text: string, max: number = AROUND_TEXT_CHARS): string =>
|
|
79
|
+
text.length <= max ? text : `${text.slice(0, max - ELLIPSIS.length).trimEnd()}${ELLIPSIS}`;
|
|
80
|
+
|
|
81
|
+
function briefField(field: AssistField, raw: unknown, locale: string): ItemBriefField {
|
|
82
|
+
const base = { handle: field.handle, label: field.label, kind: field.kind, required: field.required };
|
|
83
|
+
if (field.never) return { ...base, empty: isEmptyFieldValue(raw), never: field.never };
|
|
84
|
+
const options = field.options ? { options: field.options } : {};
|
|
85
|
+
if (field.locales) {
|
|
86
|
+
const values = readLocaleValues(field.kind, field.locales, raw);
|
|
87
|
+
const filled = field.locales.filter(l => !isEmptyFieldValue(values[l]));
|
|
88
|
+
return {
|
|
89
|
+
...base, ...options,
|
|
90
|
+
empty: isEmptyFieldValue(values[locale]),
|
|
91
|
+
value: values as Record<string, string | ReadonlyArray<string>>,
|
|
92
|
+
locales: { filled, empty: field.locales.filter(l => !filled.includes(l)) },
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
const value = readFieldValue(field.kind, raw);
|
|
96
|
+
return { ...base, ...options, empty: isEmptyFieldValue(value), value };
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const localeOrFirst = (values: Record<string, BriefValue>, locale: string): BriefValue =>
|
|
100
|
+
!isEmptyFieldValue(values[locale]) ? values[locale] : Object.values(values).find(v => !isEmptyFieldValue(v)) ?? null;
|
|
101
|
+
|
|
102
|
+
/** A value as one clipped line: the write locale first (else the first filled one), paragraphs and lists joined. */
|
|
103
|
+
function summaryText(field: AssistField, raw: unknown, locale: string): string {
|
|
104
|
+
const value = field.locales ? localeOrFirst(readLocaleValues(field.kind, field.locales, raw), locale) : readFieldValue(field.kind, raw);
|
|
105
|
+
if (value === null) return '';
|
|
106
|
+
const text = Array.isArray(value) ? value.join(field.kind === AssistFieldKind.RichText ? PARAGRAPH_JOIN : LIST_JOIN) : String(value);
|
|
107
|
+
return clipText(text.replace(/\s+/g, ' ').trim());
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function summaries(fields: ReadonlyArray<AssistField>, record: ContentRecord, locale: string): Record<string, string> {
|
|
111
|
+
return Object.fromEntries(fields
|
|
112
|
+
.map(f => [f.handle, summaryText(f, record[f.key], locale)] as const)
|
|
113
|
+
.filter(([, text]) => text !== ''));
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function findFocusField(fields: ReadonlyArray<AssistField>, focus: string): AssistField {
|
|
117
|
+
const found = fields.find(f => f.key === focus || f.handle === focus || f.handle === `${FIELD_HANDLE_PREFIX}${focus}`);
|
|
118
|
+
if (!found) throw new AssistBriefError(AssistIssueCode.UnknownHandle, `"${focus}" is not a field of this type`);
|
|
119
|
+
return found;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const neverList = (fields: ReadonlyArray<AssistField>): NeverWrite[] =>
|
|
123
|
+
fields.filter(f => f.never).map(f => ({ handle: f.handle, label: f.label, reason: f.never as string }));
|
|
124
|
+
|
|
125
|
+
function siblingsOf(record: ContentRecord, siblings: ReadonlyArray<ContentRecord>): ContentRecord[] {
|
|
126
|
+
const own = record[ID_KEY];
|
|
127
|
+
return siblings.filter(s => own === undefined || s[ID_KEY] !== own).slice(0, AROUND_ITEMS_MAX);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/** S2's brief and its handle map: `f.<key>` per field, `s<n>` per sibling (its id stays in the map, never sent). */
|
|
131
|
+
export function summarizeItem(schema: ContentTypeSchema, item: ContentRecord, ctx: ItemBriefContext): SummarizedItem {
|
|
132
|
+
const fields = assistFields(schema);
|
|
133
|
+
const focused = ctx.focusField ? findFocusField(fields, ctx.focusField) : null;
|
|
134
|
+
const title = titleField(schema, fields);
|
|
135
|
+
const voiceFields = fields.filter(f => isWritable(f) && TEXT_KINDS.has(f.kind));
|
|
136
|
+
const siblings = siblingsOf(item, ctx.siblings ?? []);
|
|
137
|
+
const siblingHandle = (i: number) => `${SIBLING_HANDLE_PREFIX}${i + 1}`;
|
|
138
|
+
const surface = SURFACES[AssistSurface.ContentItem];
|
|
139
|
+
const scope = focused ? AssistScope.Field : AssistScope.Item;
|
|
140
|
+
|
|
141
|
+
const handles: Record<string, HandleTarget> = Object.fromEntries([
|
|
142
|
+
...fields.map(f => [f.handle, { key: f.key, path: [f.key] }] as const),
|
|
143
|
+
...siblings.map((s, i) => [siblingHandle(i), { key: siblingHandle(i), path: [], ...(s[ID_KEY] !== undefined ? { id: String(s[ID_KEY]) } : {}) }] as const),
|
|
144
|
+
]);
|
|
145
|
+
|
|
146
|
+
const brief: ItemBrief = {
|
|
147
|
+
surface: AssistSurface.ContentItem,
|
|
148
|
+
focus: {
|
|
149
|
+
scope,
|
|
150
|
+
type: { name: schema.name, label: schema.metaData?.label || schema.name },
|
|
151
|
+
title: title ? summaryText(title, item[title.key], ctx.locale) : '',
|
|
152
|
+
titleHandle: title?.handle ?? null,
|
|
153
|
+
fields: (focused ? [focused] : fields).map(f => briefField(f, item[f.key], ctx.locale)),
|
|
154
|
+
},
|
|
155
|
+
around: {
|
|
156
|
+
item: focused ? summaries(fields.filter(f => f !== focused && isWritable(f)), item, ctx.locale) : null,
|
|
157
|
+
siblings: siblings.map((s, i) => ({
|
|
158
|
+
handle: siblingHandle(i),
|
|
159
|
+
title: title ? summaryText(title, s[title.key], ctx.locale) : '',
|
|
160
|
+
fields: summaries(voiceFields, s, ctx.locale),
|
|
161
|
+
})),
|
|
162
|
+
},
|
|
163
|
+
owner: ctx.owner ?? null,
|
|
164
|
+
rules: {
|
|
165
|
+
families: surface.families,
|
|
166
|
+
locale: ctx.locale,
|
|
167
|
+
never: neverList(fields),
|
|
168
|
+
scope,
|
|
169
|
+
widensTo: surface.scopes.slice(surface.scopes.indexOf(scope) + 1),
|
|
170
|
+
},
|
|
171
|
+
memory: (ctx.memory ?? []).slice(-MEMORY_TURNS),
|
|
172
|
+
};
|
|
173
|
+
return { brief, handles };
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export enum ItemSuggestionKind {
|
|
177
|
+
FillEmpty = 'fillEmpty',
|
|
178
|
+
Translate = 'translate',
|
|
179
|
+
Shorten = 'shorten',
|
|
180
|
+
WriteSeo = 'writeSeo',
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/** A quick action the box offers, built from the brief (never canned text — the client words it). */
|
|
184
|
+
export interface ItemSuggestion {
|
|
185
|
+
readonly kind: ItemSuggestionKind;
|
|
186
|
+
readonly handles: ReadonlyArray<string>;
|
|
187
|
+
/** Translate: the locale to fill. */
|
|
188
|
+
readonly locale?: string;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/** A text this long is worth a "Shorten". */
|
|
192
|
+
export const SHORTEN_FROM_CHARS = 280;
|
|
193
|
+
const SEO_WORDS: ReadonlyArray<string> = ['seo', 'meta'];
|
|
194
|
+
|
|
195
|
+
const textLength = (v: BriefValue | undefined): number =>
|
|
196
|
+
typeof v === 'string' ? v.length : Array.isArray(v) ? v.join(' ').length : 0;
|
|
197
|
+
|
|
198
|
+
function translations(writable: ReadonlyArray<ItemBriefField>): ItemSuggestion[] {
|
|
199
|
+
const byLocale = new Map<string, string[]>();
|
|
200
|
+
for (const f of writable) {
|
|
201
|
+
if (!f.locales || !f.locales.filled.length) continue;
|
|
202
|
+
for (const l of f.locales.empty) byLocale.set(l, [...(byLocale.get(l) ?? []), f.handle]);
|
|
203
|
+
}
|
|
204
|
+
return [...byLocale].map(([locale, handles]) => ({ kind: ItemSuggestionKind.Translate, locale, handles }));
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/** S2's quick actions: Fill empty fields, Translate to <locale>, Shorten, Write SEO — each only when it applies. */
|
|
208
|
+
export function itemSuggestions(brief: ItemBrief): ItemSuggestion[] {
|
|
209
|
+
const writable = brief.focus.fields.filter(f => !f.never);
|
|
210
|
+
const empty = writable.filter(f => f.empty).map(f => f.handle);
|
|
211
|
+
const long = writable.filter(f => TEXT_KINDS.has(f.kind) && !f.locales && textLength(f.value) >= SHORTEN_FROM_CHARS).map(f => f.handle);
|
|
212
|
+
const seo = writable.filter(f => SEO_WORDS.some(w => f.handle.slice(FIELD_HANDLE_PREFIX.length).toLowerCase().startsWith(w))).map(f => f.handle);
|
|
213
|
+
return [
|
|
214
|
+
...(empty.length ? [{ kind: ItemSuggestionKind.FillEmpty, handles: empty }] : []),
|
|
215
|
+
...translations(writable),
|
|
216
|
+
...(long.length ? [{ kind: ItemSuggestionKind.Shorten, handles: long }] : []),
|
|
217
|
+
...(seo.length ? [{ kind: ItemSuggestionKind.WriteSeo, handles: seo }] : []),
|
|
218
|
+
];
|
|
219
|
+
}
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
import { AiStep } from '@vectoriox/iox-ui/generation-core';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The surfaces AI Assist runs on (ai-assist-plan §2, §4): each screen that offers a prompt registers ONE spec — what it
|
|
5
|
+
* may change (families), how an accepted change is committed, which model steps a turn uses, the role actions the
|
|
6
|
+
* server re-checks, whether it reads photos and the focus ladder its chip widens along.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
export enum AssistSurface {
|
|
10
|
+
BuilderPage = 'builderPage',
|
|
11
|
+
ContentItem = 'contentItem',
|
|
12
|
+
ContentFromPhotos = 'contentFromPhotos',
|
|
13
|
+
ContentList = 'contentList',
|
|
14
|
+
SchemaType = 'schemaType',
|
|
15
|
+
ShopProduct = 'shopProduct',
|
|
16
|
+
Media = 'media',
|
|
17
|
+
BuilderSite = 'builderSite',
|
|
18
|
+
FormInbox = 'formInbox',
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** How an accepted turn reaches the studio (plan §3e). */
|
|
22
|
+
export enum CommitKind {
|
|
23
|
+
/** One builder history step. */
|
|
24
|
+
BuilderStep = 'builderStep',
|
|
25
|
+
/** Written into the screen's form; Save stays the owner's. */
|
|
26
|
+
FormFill = 'formFill',
|
|
27
|
+
/** A server run that writes drafts, with its own Undo. */
|
|
28
|
+
Run = 'run',
|
|
29
|
+
/** Nothing is written: filters, a copied reply. */
|
|
30
|
+
View = 'view',
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** The closed edit families a sentence may be answered in — one strict request each. */
|
|
34
|
+
export enum EditFamily {
|
|
35
|
+
Words = 'words',
|
|
36
|
+
Sections = 'sections',
|
|
37
|
+
Style = 'style',
|
|
38
|
+
Look = 'look',
|
|
39
|
+
Fields = 'fields',
|
|
40
|
+
Items = 'items',
|
|
41
|
+
View = 'view',
|
|
42
|
+
Schema = 'schema',
|
|
43
|
+
Media = 'media',
|
|
44
|
+
Plan = 'plan',
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** The model steps of a turn — generation-core's `AiStep` rows (Settings ▸ AI ▸ Models), never a second spelling. */
|
|
48
|
+
export const AssistStep = {
|
|
49
|
+
AssistRoute: AiStep.AssistRoute,
|
|
50
|
+
AssistEdit: AiStep.AssistEdit,
|
|
51
|
+
AssistRead: AiStep.AssistRead,
|
|
52
|
+
} as const;
|
|
53
|
+
export type AssistStep = typeof AssistStep[keyof typeof AssistStep];
|
|
54
|
+
|
|
55
|
+
/** One rung of a surface's focus ladder — the chip's ✕ widens to the next rung. */
|
|
56
|
+
export enum AssistScope {
|
|
57
|
+
Field = 'field',
|
|
58
|
+
Item = 'item',
|
|
59
|
+
Type = 'type',
|
|
60
|
+
Types = 'types',
|
|
61
|
+
Node = 'node',
|
|
62
|
+
Section = 'section',
|
|
63
|
+
Page = 'page',
|
|
64
|
+
Site = 'site',
|
|
65
|
+
Photo = 'photo',
|
|
66
|
+
Photos = 'photos',
|
|
67
|
+
Rows = 'rows',
|
|
68
|
+
Slot = 'slot',
|
|
69
|
+
Library = 'library',
|
|
70
|
+
Submission = 'submission',
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** iox-cms role actions (`roles/enums.ts` `Permissions`) a surface needs — the server re-checks them, never only the client. */
|
|
74
|
+
export enum AssistPermission {
|
|
75
|
+
SchemaAll = 'schema_all',
|
|
76
|
+
ContentRead = 'content_read',
|
|
77
|
+
ContentCreate = 'content_create',
|
|
78
|
+
ContentUpdate = 'content_update',
|
|
79
|
+
PageRead = 'page_read',
|
|
80
|
+
PageCreate = 'page_create',
|
|
81
|
+
PageUpdate = 'page_update',
|
|
82
|
+
PageDelete = 'page_delete',
|
|
83
|
+
StorageAll = 'storage_all',
|
|
84
|
+
ProductsAll = 'products_all',
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export enum SurfaceStatus {
|
|
88
|
+
Built = 'built',
|
|
89
|
+
Planned = 'planned',
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export interface SurfaceSpec {
|
|
93
|
+
readonly surface: AssistSurface;
|
|
94
|
+
readonly families: ReadonlyArray<EditFamily>;
|
|
95
|
+
readonly commit: CommitKind;
|
|
96
|
+
/** A family committed differently from the surface (the list's items are a Run; its filters a View). */
|
|
97
|
+
readonly familyCommits?: Readonly<Partial<Record<EditFamily, CommitKind>>>;
|
|
98
|
+
/** Model steps a turn may use. Media (S7) uses the picture steps of generation-core, none of these. */
|
|
99
|
+
readonly steps: ReadonlyArray<AssistStep>;
|
|
100
|
+
/** Every one is required. `content_<action>` is specialised per content type when `perContentType`. */
|
|
101
|
+
readonly permissions: ReadonlyArray<AssistPermission>;
|
|
102
|
+
/** A family that needs more than the surface does. */
|
|
103
|
+
readonly familyPermissions?: Readonly<Partial<Record<EditFamily, ReadonlyArray<AssistPermission>>>>;
|
|
104
|
+
/** The content permissions name a type (`content_<type>_<action>`), as the iox-cms guard specialises them. */
|
|
105
|
+
readonly perContentType: boolean;
|
|
106
|
+
readonly readsPhotos: boolean;
|
|
107
|
+
/** The focus ladder, narrowest first. */
|
|
108
|
+
readonly scopes: ReadonlyArray<AssistScope>;
|
|
109
|
+
readonly status: SurfaceStatus;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const spec = (s: Omit<SurfaceSpec, 'perContentType' | 'readsPhotos'> & Partial<Pick<SurfaceSpec, 'perContentType' | 'readsPhotos'>>): SurfaceSpec => ({
|
|
113
|
+
perContentType: false,
|
|
114
|
+
readsPhotos: false,
|
|
115
|
+
...s,
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
export const SURFACES: Readonly<Record<AssistSurface, SurfaceSpec>> = {
|
|
119
|
+
[AssistSurface.BuilderPage]: spec({
|
|
120
|
+
surface: AssistSurface.BuilderPage,
|
|
121
|
+
families: [EditFamily.Words, EditFamily.Sections, EditFamily.Style, EditFamily.Look],
|
|
122
|
+
commit: CommitKind.BuilderStep,
|
|
123
|
+
steps: [AssistStep.AssistRoute, AssistStep.AssistEdit],
|
|
124
|
+
permissions: [AssistPermission.PageUpdate],
|
|
125
|
+
scopes: [AssistScope.Node, AssistScope.Section, AssistScope.Page],
|
|
126
|
+
status: SurfaceStatus.Planned,
|
|
127
|
+
}),
|
|
128
|
+
[AssistSurface.ContentItem]: spec({
|
|
129
|
+
surface: AssistSurface.ContentItem,
|
|
130
|
+
families: [EditFamily.Fields],
|
|
131
|
+
commit: CommitKind.FormFill,
|
|
132
|
+
steps: [AssistStep.AssistRoute, AssistStep.AssistEdit],
|
|
133
|
+
permissions: [AssistPermission.ContentUpdate],
|
|
134
|
+
perContentType: true,
|
|
135
|
+
scopes: [AssistScope.Field, AssistScope.Item, AssistScope.Type],
|
|
136
|
+
status: SurfaceStatus.Built,
|
|
137
|
+
}),
|
|
138
|
+
[AssistSurface.ContentFromPhotos]: spec({
|
|
139
|
+
surface: AssistSurface.ContentFromPhotos,
|
|
140
|
+
families: [EditFamily.Fields, EditFamily.Media],
|
|
141
|
+
commit: CommitKind.Run,
|
|
142
|
+
steps: [AssistStep.AssistRoute, AssistStep.AssistRead, AssistStep.AssistEdit],
|
|
143
|
+
permissions: [AssistPermission.ContentCreate, AssistPermission.StorageAll],
|
|
144
|
+
perContentType: true,
|
|
145
|
+
readsPhotos: true,
|
|
146
|
+
scopes: [AssistScope.Photo, AssistScope.Photos, AssistScope.Type],
|
|
147
|
+
status: SurfaceStatus.Planned,
|
|
148
|
+
}),
|
|
149
|
+
[AssistSurface.ContentList]: spec({
|
|
150
|
+
surface: AssistSurface.ContentList,
|
|
151
|
+
families: [EditFamily.View, EditFamily.Items],
|
|
152
|
+
commit: CommitKind.View,
|
|
153
|
+
familyCommits: { [EditFamily.Items]: CommitKind.Run },
|
|
154
|
+
steps: [AssistStep.AssistRoute, AssistStep.AssistEdit],
|
|
155
|
+
permissions: [AssistPermission.ContentRead],
|
|
156
|
+
familyPermissions: { [EditFamily.Items]: [AssistPermission.ContentCreate, AssistPermission.ContentUpdate] },
|
|
157
|
+
perContentType: true,
|
|
158
|
+
scopes: [AssistScope.Rows, AssistScope.Type],
|
|
159
|
+
status: SurfaceStatus.Planned,
|
|
160
|
+
}),
|
|
161
|
+
[AssistSurface.SchemaType]: spec({
|
|
162
|
+
surface: AssistSurface.SchemaType,
|
|
163
|
+
families: [EditFamily.Schema],
|
|
164
|
+
commit: CommitKind.FormFill,
|
|
165
|
+
steps: [AssistStep.AssistRoute, AssistStep.AssistEdit],
|
|
166
|
+
permissions: [AssistPermission.SchemaAll],
|
|
167
|
+
scopes: [AssistScope.Field, AssistScope.Type, AssistScope.Types],
|
|
168
|
+
status: SurfaceStatus.Planned,
|
|
169
|
+
}),
|
|
170
|
+
[AssistSurface.ShopProduct]: spec({
|
|
171
|
+
surface: AssistSurface.ShopProduct,
|
|
172
|
+
families: [EditFamily.Fields],
|
|
173
|
+
commit: CommitKind.FormFill,
|
|
174
|
+
steps: [AssistStep.AssistRoute, AssistStep.AssistRead, AssistStep.AssistEdit],
|
|
175
|
+
permissions: [AssistPermission.ProductsAll],
|
|
176
|
+
readsPhotos: true,
|
|
177
|
+
scopes: [AssistScope.Field, AssistScope.Item],
|
|
178
|
+
status: SurfaceStatus.Planned,
|
|
179
|
+
}),
|
|
180
|
+
[AssistSurface.Media]: spec({
|
|
181
|
+
surface: AssistSurface.Media,
|
|
182
|
+
families: [EditFamily.Media],
|
|
183
|
+
commit: CommitKind.Run,
|
|
184
|
+
steps: [],
|
|
185
|
+
permissions: [AssistPermission.StorageAll],
|
|
186
|
+
readsPhotos: true,
|
|
187
|
+
scopes: [AssistScope.Slot, AssistScope.Library],
|
|
188
|
+
status: SurfaceStatus.Planned,
|
|
189
|
+
}),
|
|
190
|
+
[AssistSurface.BuilderSite]: spec({
|
|
191
|
+
surface: AssistSurface.BuilderSite,
|
|
192
|
+
families: [EditFamily.Plan, EditFamily.Sections],
|
|
193
|
+
commit: CommitKind.Run,
|
|
194
|
+
steps: [AssistStep.AssistRoute, AssistStep.AssistEdit],
|
|
195
|
+
permissions: [AssistPermission.PageCreate, AssistPermission.PageUpdate, AssistPermission.PageDelete],
|
|
196
|
+
familyPermissions: { [EditFamily.Plan]: [AssistPermission.SchemaAll] },
|
|
197
|
+
scopes: [AssistScope.Page, AssistScope.Site],
|
|
198
|
+
status: SurfaceStatus.Planned,
|
|
199
|
+
}),
|
|
200
|
+
[AssistSurface.FormInbox]: spec({
|
|
201
|
+
surface: AssistSurface.FormInbox,
|
|
202
|
+
families: [EditFamily.Words],
|
|
203
|
+
commit: CommitKind.View,
|
|
204
|
+
steps: [AssistStep.AssistRoute, AssistStep.AssistEdit],
|
|
205
|
+
permissions: [AssistPermission.PageRead],
|
|
206
|
+
scopes: [AssistScope.Submission],
|
|
207
|
+
status: SurfaceStatus.Planned,
|
|
208
|
+
}),
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
export const surfaceSpec = (surface: AssistSurface): SurfaceSpec => SURFACES[surface];
|
|
212
|
+
|
|
213
|
+
export const builtSurfaces = (): AssistSurface[] =>
|
|
214
|
+
Object.values(SURFACES).filter(s => s.status === SurfaceStatus.Built).map(s => s.surface);
|
|
215
|
+
|
|
216
|
+
export const commitOf = (surface: AssistSurface, family: EditFamily): CommitKind =>
|
|
217
|
+
SURFACES[surface].familyCommits?.[family] ?? SURFACES[surface].commit;
|
|
218
|
+
|
|
219
|
+
const CONTENT_PERMISSION_PREFIX = 'content_';
|
|
220
|
+
const ALL_SUFFIX = '_all';
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* The permission strings the server checks for a turn on this surface (and these families): `content_<action>` becomes
|
|
224
|
+
* `content_<type>_<action>` on a per-type surface — the same specialisation iox-cms's AuthorizationGuard applies to a
|
|
225
|
+
* `:resource` route, so a user granted only `content_posts_update` may assist on posts and nowhere else.
|
|
226
|
+
*/
|
|
227
|
+
export function surfacePermissions(surface: AssistSurface, contentType?: string, families: ReadonlyArray<EditFamily> = []): string[] {
|
|
228
|
+
const s = SURFACES[surface];
|
|
229
|
+
const all = [...s.permissions, ...families.flatMap(f => s.familyPermissions?.[f] ?? [])];
|
|
230
|
+
const named = all.map(p => {
|
|
231
|
+
if (!s.perContentType || !contentType || !p.startsWith(CONTENT_PERMISSION_PREFIX) || p.endsWith(ALL_SUFFIX)) return p as string;
|
|
232
|
+
return `${CONTENT_PERMISSION_PREFIX}${contentType}_${p.slice(CONTENT_PERMISSION_PREFIX.length)}`;
|
|
233
|
+
});
|
|
234
|
+
return [...new Set(named)];
|
|
235
|
+
}
|
|
@@ -32,6 +32,12 @@ export enum AiStep {
|
|
|
32
32
|
NameStructures = 'scanNaming',
|
|
33
33
|
/** M8 gate 2: each composed page's layout, one strict request a page, after the plan (M8-G2-D2). */
|
|
34
34
|
ComposePages = 'composePages',
|
|
35
|
+
/** AI Assist (A-D7): which edit families a sentence on a screen asks for — or that it cannot be done. Fast, small. */
|
|
36
|
+
AssistRoute = 'assistRoute',
|
|
37
|
+
/** AI Assist: the edits themselves, one strict request per routed family. */
|
|
38
|
+
AssistEdit = 'assistEdit',
|
|
39
|
+
/** AI Assist: photos read into content (≤ 6 a request, S3). */
|
|
40
|
+
AssistRead = 'assistRead',
|
|
35
41
|
}
|
|
36
42
|
|
|
37
43
|
export const AI_STEPS: ReadonlyArray<AiStep> = Object.values(AiStep);
|
|
@@ -45,6 +51,9 @@ export const AI_STEP_LABELS: Readonly<Record<AiStep, string>> = {
|
|
|
45
51
|
[AiStep.CheckPictures]: 'Check pictures',
|
|
46
52
|
[AiStep.NameStructures]: 'Name repeated structures',
|
|
47
53
|
[AiStep.ComposePages]: 'Compose your pages',
|
|
54
|
+
[AiStep.AssistRoute]: 'Understand your request',
|
|
55
|
+
[AiStep.AssistEdit]: 'Make the change',
|
|
56
|
+
[AiStep.AssistRead]: 'Read your photos',
|
|
48
57
|
};
|
|
49
58
|
|
|
50
59
|
/** What a model must be able to do for a step to run on it. */
|
|
@@ -62,6 +71,9 @@ export const AI_STEP_NEEDS: Readonly<Record<AiStep, ReadonlyArray<AiCapability>>
|
|
|
62
71
|
[AiStep.CheckPictures]: [AiCapability.StructuredOutput, AiCapability.ImageInput],
|
|
63
72
|
[AiStep.NameStructures]: [AiCapability.StructuredOutput],
|
|
64
73
|
[AiStep.ComposePages]: [AiCapability.StructuredOutput],
|
|
74
|
+
[AiStep.AssistRoute]: [AiCapability.StructuredOutput],
|
|
75
|
+
[AiStep.AssistEdit]: [AiCapability.StructuredOutput],
|
|
76
|
+
[AiStep.AssistRead]: [AiCapability.StructuredOutput, AiCapability.ImageInput],
|
|
65
77
|
};
|
|
66
78
|
|
|
67
79
|
/**
|
|
@@ -128,6 +140,12 @@ export const AI_STEP_TYPICAL_TOKENS: Readonly<Record<AiStep, AiTokenCounts>> = {
|
|
|
128
140
|
// for the two pages and their repairs, where 14k / 18k (41.6) had been counted. Counted as plain input so the Start
|
|
129
141
|
// gate holds the whole cost (iox-cms#43).
|
|
130
142
|
[AiStep.ComposePages]: { input: 36_000, output: 22_000, cacheWrite: 0, cacheRead: 0 },
|
|
143
|
+
// AI Assist (plan §3c): the route reads the brief's names and the sentence and answers ≤ 12 properties; an edit reads
|
|
144
|
+
// the focus in full (a content item, a page summary) and writes ≤ 40 properties of values; a read takes ≤ 6 photos
|
|
145
|
+
// downscaled (~1.6k tokens each) with the type's fields. Not yet measured live — counted high, as every first estimate.
|
|
146
|
+
[AiStep.AssistRoute]: { input: 3_000, output: 300, cacheWrite: 0, cacheRead: 0 },
|
|
147
|
+
[AiStep.AssistEdit]: { input: 8_000, output: 2_000, cacheWrite: 0, cacheRead: 0 },
|
|
148
|
+
[AiStep.AssistRead]: { input: 12_000, output: 2_000, cacheWrite: 0, cacheRead: 0 },
|
|
131
149
|
};
|
|
132
150
|
|
|
133
151
|
/** Tokens by the class a provider prices them in. */
|
|
@@ -300,8 +318,24 @@ export interface AiMeter {
|
|
|
300
318
|
/** The plan entitlements AI reads (the control plane's `features` / `limits` keys) — ONE spelling. */
|
|
301
319
|
export enum AiFeature {
|
|
302
320
|
SiteGeneration = 'aiSiteGeneration',
|
|
321
|
+
/** AI Assist on every screen (ai-assist-plan A-D6): its own switch, the plan's shared credits. */
|
|
322
|
+
Assist = 'aiAssist',
|
|
303
323
|
}
|
|
304
324
|
|
|
325
|
+
/** The feature a step belongs to — the gate refuses a step whose feature the plan does not include. */
|
|
326
|
+
export const AI_STEP_FEATURE: Readonly<Record<AiStep, AiFeature>> = {
|
|
327
|
+
[AiStep.ReadMessage]: AiFeature.SiteGeneration,
|
|
328
|
+
[AiStep.PlanSite]: AiFeature.SiteGeneration,
|
|
329
|
+
[AiStep.ChangePlan]: AiFeature.SiteGeneration,
|
|
330
|
+
[AiStep.MakePictures]: AiFeature.SiteGeneration,
|
|
331
|
+
[AiStep.CheckPictures]: AiFeature.SiteGeneration,
|
|
332
|
+
[AiStep.NameStructures]: AiFeature.SiteGeneration,
|
|
333
|
+
[AiStep.ComposePages]: AiFeature.SiteGeneration,
|
|
334
|
+
[AiStep.AssistRoute]: AiFeature.Assist,
|
|
335
|
+
[AiStep.AssistEdit]: AiFeature.Assist,
|
|
336
|
+
[AiStep.AssistRead]: AiFeature.Assist,
|
|
337
|
+
};
|
|
338
|
+
|
|
305
339
|
export enum AiLimit {
|
|
306
340
|
CreditsPerMonth = 'aiCreditsPerMonth',
|
|
307
341
|
CreditsPerGeneration = 'aiCreditsPerGeneration',
|
|
@@ -107,12 +107,15 @@ function ownedKeys(facts: PlanWordContext['facts']): Set<string> {
|
|
|
107
107
|
return keys;
|
|
108
108
|
}
|
|
109
109
|
|
|
110
|
-
/**
|
|
111
|
-
|
|
110
|
+
/**
|
|
111
|
+
* The words to avoid and the facts never given, in any texts a model wrote — the plan's (`planWordIssues`) and an AI
|
|
112
|
+
* Assist turn's field values (assist-core, R-H2): ONE judge of what a model may write.
|
|
113
|
+
*/
|
|
114
|
+
export function factIssues(texts: ReadonlyArray<WrittenText>, ctx: PlanWordContext): PlanWordIssue[] {
|
|
112
115
|
const issues: PlanWordIssue[] = [];
|
|
113
116
|
const avoid = [...new Set(ctx.avoidWords.map(w => w.trim()).filter(Boolean))].map(w => ({ word: w, pattern: wordPattern(w) }));
|
|
114
117
|
const owned = ownedKeys(ctx.facts);
|
|
115
|
-
for (const { path, text } of
|
|
118
|
+
for (const { path, text } of texts) {
|
|
116
119
|
const words = normalise(text);
|
|
117
120
|
for (const a of avoid) if (a.pattern.test(words)) issues.push({ code: PlanWordIssueCode.AvoidWord, path, message: `uses "${a.word}" — a word this site must not use` });
|
|
118
121
|
for (const shape of FACT_SHAPES) {
|
|
@@ -123,6 +126,12 @@ export function planWordIssues(plan: SitePlan, ctx: PlanWordContext): PlanWordIs
|
|
|
123
126
|
}
|
|
124
127
|
}
|
|
125
128
|
}
|
|
129
|
+
return issues;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** The words to avoid and the facts never given, in every written text of the plan. */
|
|
133
|
+
export function planWordIssues(plan: SitePlan, ctx: PlanWordContext): PlanWordIssue[] {
|
|
134
|
+
const issues = factIssues(writtenTexts(plan), ctx);
|
|
126
135
|
for (const [key, value] of Object.entries(plan.business?.facts ?? {})) {
|
|
127
136
|
const own = ctx.facts[key as FactKey];
|
|
128
137
|
if (!(FACT_KEYS as ReadonlyArray<string>).includes(key)) continue;
|