@vectoriox/iox-ui 5.113.0 → 5.114.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 +234 -7
- package/fesm2022/vectoriox-iox-ui-assist-core.mjs +480 -75
- package/fesm2022/vectoriox-iox-ui-assist-core.mjs.map +1 -1
- package/fesm2022/vectoriox-iox-ui-generation-core.mjs +3 -3
- package/fesm2022/vectoriox-iox-ui-generation-core.mjs.map +1 -1
- package/generation-core/index.d.ts +5 -0
- package/package.json +1 -1
- package/src/assist-core/assist-facts.ts +36 -0
- package/src/assist-core/assist-turn.ts +28 -6
- package/src/assist-core/brief.ts +4 -0
- package/src/assist-core/field-edits.ts +14 -0
- package/src/assist-core/page-words.ts +503 -0
- package/src/assist-core/public-api.ts +5 -3
- package/src/assist-core/rich-text.ts +3 -0
- package/src/assist-core/surfaces.ts +4 -2
- package/src/generation-core/plan-words.ts +8 -3
|
@@ -9108,6 +9108,11 @@ interface PlanWordContext {
|
|
|
9108
9108
|
avoidWords: ReadonlyArray<string>;
|
|
9109
9109
|
/** The owner's own facts (the analysis's, as corrected) — the only ones a plan may carry. */
|
|
9110
9110
|
facts: Readonly<Partial<Record<FactKey, string>>>;
|
|
9111
|
+
/**
|
|
9112
|
+
* Other texts whose facts are the owner's too (AI Assist, R-H2): the owner's sentence, and the words already on what
|
|
9113
|
+
* they are editing — a phone number on their own page is theirs to move or keep. Never a model's earlier answer.
|
|
9114
|
+
*/
|
|
9115
|
+
known?: ReadonlyArray<string>;
|
|
9111
9116
|
}
|
|
9112
9117
|
/** A text a model wrote, and where. */
|
|
9113
9118
|
interface WrittenText {
|
package/package.json
CHANGED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { factIssues, PlanWordContext, PlanWordIssueCode } from '@vectoriox/iox-ui/generation-core';
|
|
2
|
+
|
|
3
|
+
import { AssistIssue, AssistIssueCode } from './brief';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The fact gate of every Assist family (ai-assist-plan §3c rule 4, R-H2): generation-core's `factIssues` — the SAME judge
|
|
7
|
+
* the plan uses — over the words a model wrote. What counts as the owner's: their reading's facts, the sentence they
|
|
8
|
+
* typed, and the words already on what they are editing (a phone already on their page is theirs to keep or move).
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/** The owner's words to avoid and own facts (the business reading); absent → none beyond the known texts. */
|
|
12
|
+
export type AssistWordContext = Partial<PlanWordContext>;
|
|
13
|
+
|
|
14
|
+
const CODES: Readonly<Record<string, AssistIssueCode>> = {
|
|
15
|
+
[PlanWordIssueCode.InventedFact]: AssistIssueCode.InventedFact,
|
|
16
|
+
[PlanWordIssueCode.AvoidWord]: AssistIssueCode.AvoidWord,
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export interface WrittenWords {
|
|
20
|
+
readonly handle: string;
|
|
21
|
+
readonly text: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function assistFactIssues(written: ReadonlyArray<WrittenWords>, ctx: {
|
|
25
|
+
readonly words?: AssistWordContext;
|
|
26
|
+
readonly sentence?: string;
|
|
27
|
+
/** The texts already on the thing being edited. */
|
|
28
|
+
readonly existing: ReadonlyArray<string>;
|
|
29
|
+
}): AssistIssue[] {
|
|
30
|
+
if (!written.length) return [];
|
|
31
|
+
return factIssues(written.map(w => ({ path: w.handle, text: w.text })), {
|
|
32
|
+
avoidWords: ctx.words?.avoidWords ?? [],
|
|
33
|
+
facts: ctx.words?.facts ?? {},
|
|
34
|
+
known: [...(ctx.words?.known ?? []), ...(ctx.sentence ? [ctx.sentence] : []), ...ctx.existing],
|
|
35
|
+
}).map(f => ({ code: CODES[f.code] ?? AssistIssueCode.InventedFact, handle: f.path, message: f.message }));
|
|
36
|
+
}
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { AROUND_TEXT_CHARS, MEMORY_TURNS } from './budget';
|
|
2
2
|
import { AssistIssue, AssistIssueCode, Brief, HandleMap } from './brief';
|
|
3
|
+
import type { SerializedNode } from '@vectoriox/iox-ui/generation-core';
|
|
4
|
+
|
|
3
5
|
import { FieldChange } from './field-edits';
|
|
4
6
|
import { FieldEdit } from './fields-schema';
|
|
7
|
+
import { WordChange, WordEdit } from './page-words';
|
|
5
8
|
import { ContentRecord, clipText } from './summarize-item';
|
|
6
|
-
import { AssistSurface, CommitKind, EditFamily, SURFACES, SurfaceStatus } from './surfaces';
|
|
9
|
+
import { AssistScope, AssistSurface, CommitKind, EditFamily, SURFACES, SurfaceStatus } from './surfaces';
|
|
7
10
|
|
|
8
11
|
/**
|
|
9
12
|
* The turn wire (plan §3d) — what cms-client posts and polls and iox-cms stores and answers, ONE definition both sides
|
|
@@ -48,8 +51,24 @@ export interface AssistTurnRequest {
|
|
|
48
51
|
readonly values?: ContentRecord;
|
|
49
52
|
/** Field keys the owner changed since the last AI turn — kept unless the sentence names them (rule 9). */
|
|
50
53
|
readonly ownerEdited?: ReadonlyArray<string>;
|
|
54
|
+
/** A builder surface: the page the turn is about. */
|
|
55
|
+
readonly pageId?: string;
|
|
56
|
+
/** A builder surface: the page's layout as the canvas holds it now (it may be unsaved) — the saved shape. */
|
|
57
|
+
readonly layout?: ReadonlyArray<SerializedNode>;
|
|
58
|
+
/** A builder surface: the selected node ("this"), or none. */
|
|
59
|
+
readonly selectedId?: string | null;
|
|
60
|
+
/** The focus rung the owner widened to (the chip's ✕); absent = what the selection gives. */
|
|
61
|
+
readonly scope?: AssistScope;
|
|
62
|
+
/** A builder surface: the page as the owner names it. */
|
|
63
|
+
readonly page?: { readonly name: string; readonly route: string };
|
|
51
64
|
}
|
|
52
65
|
|
|
66
|
+
/** What a turn proposes, per family: a field's value (`fields`) or a part's words (`words`). */
|
|
67
|
+
export type AssistEdit = FieldEdit | WordEdit;
|
|
68
|
+
|
|
69
|
+
/** What a turn changed, as the card says it. */
|
|
70
|
+
export type AssistChange = FieldChange | WordChange;
|
|
71
|
+
|
|
53
72
|
/** POST's 202 answer. */
|
|
54
73
|
export interface AssistTurnAccepted {
|
|
55
74
|
readonly turnId: string;
|
|
@@ -91,9 +110,9 @@ export interface AssistTurn {
|
|
|
91
110
|
readonly model?: string;
|
|
92
111
|
readonly families?: ReadonlyArray<EditFamily>;
|
|
93
112
|
readonly reply?: string;
|
|
94
|
-
readonly edits?: ReadonlyArray<
|
|
95
|
-
readonly changes?: ReadonlyArray<
|
|
96
|
-
readonly kept?: ReadonlyArray<
|
|
113
|
+
readonly edits?: ReadonlyArray<AssistEdit>;
|
|
114
|
+
readonly changes?: ReadonlyArray<AssistChange>;
|
|
115
|
+
readonly kept?: ReadonlyArray<AssistChange>;
|
|
97
116
|
readonly issues?: ReadonlyArray<AssistIssue>;
|
|
98
117
|
readonly refusal?: AssistTurnRefusal;
|
|
99
118
|
readonly credits?: number;
|
|
@@ -164,8 +183,8 @@ export interface AssistMemoryLine {
|
|
|
164
183
|
const SENTENCE_IN_MEMORY_CHARS = 80;
|
|
165
184
|
|
|
166
185
|
function outcome(turn: AssistTurn): string {
|
|
167
|
-
const named = (list: ReadonlyArray<
|
|
168
|
-
(list ?? []).map(c => (c.locale ? `${c.label} (${c.locale})` : c.label)).join(', ');
|
|
186
|
+
const named = (list: ReadonlyArray<AssistChange> | undefined) =>
|
|
187
|
+
(list ?? []).map(c => ('locale' in c && c.locale ? `${c.label} (${c.locale})` : c.label)).join(', ');
|
|
169
188
|
switch (turn.status) {
|
|
170
189
|
case AssistTurnStatus.Refused: return `refused: ${turn.refusal?.message ?? ''}`.trim();
|
|
171
190
|
case AssistTurnStatus.Failed: return 'failed';
|
|
@@ -234,6 +253,9 @@ export function validateTurnRequest(req: unknown): AssistIssue[] {
|
|
|
234
253
|
...(!isObject(brief) || brief['surface'] !== surface ? [issue(AssistIssueCode.BadRequest, `the brief is not a ${surface} brief`)] : []),
|
|
235
254
|
...(!isObject(req['handles']) || !Object.keys(req['handles']).length ? [issue(AssistIssueCode.MissingHandles, 'the brief\'s handles are missing')] : []),
|
|
236
255
|
...(spec.commit === CommitKind.FormFill && !isObject(req['values']) ? [issue(AssistIssueCode.MissingValues, 'a form-fill turn carries the form\'s values')] : []),
|
|
256
|
+
...(spec.commit === CommitKind.BuilderStep && (!Array.isArray(req['layout']) || !req['layout'].length || !req['layout'].every(isObject))
|
|
257
|
+
? [issue(AssistIssueCode.MissingValues, 'a builder turn carries the page\'s layout')] : []),
|
|
258
|
+
...(spec.commit === CommitKind.BuilderStep && !nonEmpty(req['pageId']) ? [issue(AssistIssueCode.BadRequest, `${surface} names its page`)] : []),
|
|
237
259
|
...(!isOwnerEdited(req['ownerEdited']) ? [issue(AssistIssueCode.BadRequest, 'ownerEdited is a list of field keys')] : []),
|
|
238
260
|
...(spec.perContentType && !nonEmpty(req['contentType']) ? [issue(AssistIssueCode.BadRequest, `${surface} names its content type`)] : []),
|
|
239
261
|
];
|
package/src/assist-core/brief.ts
CHANGED
|
@@ -61,6 +61,10 @@ export enum AssistIssueCode {
|
|
|
61
61
|
SentenceTooLong = 'sentenceTooLong',
|
|
62
62
|
MissingHandles = 'missingHandles',
|
|
63
63
|
MissingValues = 'missingValues',
|
|
64
|
+
/** Looks like an e-mail, phone, price or time nobody gave (generation-core `factIssues`, R-H2). */
|
|
65
|
+
InventedFact = 'inventedFact',
|
|
66
|
+
/** A word this site must not use. */
|
|
67
|
+
AvoidWord = 'avoidWord',
|
|
64
68
|
}
|
|
65
69
|
|
|
66
70
|
export interface AssistIssue {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { assistFactIssues, AssistWordContext } from './assist-facts';
|
|
1
2
|
import { AssistIssue, AssistIssueCode, HandleMap, resolveHandle } from './brief';
|
|
2
3
|
import { AssistField, AssistFieldKind, assistFields, ContentTypeSchema } from './content-fields';
|
|
3
4
|
import { BOOLEAN_FALSE, BOOLEAN_TRUE, FieldEdit } from './fields-schema';
|
|
@@ -27,6 +28,8 @@ export interface FieldEditContext {
|
|
|
27
28
|
/** Fields (keys or handles) the sentence names. Default: read from `sentence` by `fieldsNamedIn`. */
|
|
28
29
|
readonly named?: ReadonlyArray<string>;
|
|
29
30
|
readonly sentence?: string;
|
|
31
|
+
/** The owner's words to avoid and own facts (R-H2) — a fact in the sentence or already in the item is theirs. */
|
|
32
|
+
readonly words?: AssistWordContext;
|
|
30
33
|
}
|
|
31
34
|
|
|
32
35
|
export interface FieldChange {
|
|
@@ -144,6 +147,14 @@ function plan(field: AssistField, handle: string, values: ContentRecord, coerced
|
|
|
144
147
|
return { field, stored, change };
|
|
145
148
|
}
|
|
146
149
|
|
|
150
|
+
/** The words in a value (a text, paragraphs, a list, a multiLang record) — what the fact gate reads. */
|
|
151
|
+
function wordsOf(value: unknown): string[] {
|
|
152
|
+
if (typeof value === 'string') return value.trim() ? [value] : [];
|
|
153
|
+
if (Array.isArray(value)) return value.flatMap(wordsOf);
|
|
154
|
+
if (isPlainRecord(value)) return Object.values(value).flatMap(wordsOf);
|
|
155
|
+
return [];
|
|
156
|
+
}
|
|
157
|
+
|
|
147
158
|
export function applyFieldEdits(values: ContentRecord, edits: ReadonlyArray<FieldEdit>, ctx: FieldEditContext): FieldEditsOutcome {
|
|
148
159
|
const fields = assistFields(ctx.schema);
|
|
149
160
|
const issues: AssistIssue[] = [];
|
|
@@ -166,6 +177,9 @@ export function applyFieldEdits(values: ContentRecord, edits: ReadonlyArray<Fiel
|
|
|
166
177
|
if (p) planned.push(p);
|
|
167
178
|
}
|
|
168
179
|
|
|
180
|
+
issues.push(...assistFactIssues(planned.flatMap(p => wordsOf(p.change.after).map(text => ({ handle: p.change.handle, text }))), {
|
|
181
|
+
words: ctx.words, sentence: ctx.sentence, existing: Object.values(values).flatMap(wordsOf),
|
|
182
|
+
}));
|
|
169
183
|
if (issues.length) return { ok: false, result: { ...values }, changes: [], kept: [], issues };
|
|
170
184
|
|
|
171
185
|
const edited = names(ctx.ownerEdited, fields);
|