@rebasepro/plugin-ai 0.23.0 → 0.24.1-canary.g56af4a4
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/README.md +7 -0
- package/dist/api.d.ts +12 -3
- package/dist/index.es.js +96 -59
- package/dist/index.es.js.map +1 -1
- package/dist/utils/values.d.ts +11 -0
- package/package.json +8 -8
package/README.md
CHANGED
|
@@ -114,6 +114,13 @@ A non-2xx answer to `/autofill` or `/autocomplete` carries its message as
|
|
|
114
114
|
|
|
115
115
|
### Editor AI Autocomplete
|
|
116
116
|
|
|
117
|
+
The plugin gives every markdown field in a form the **Autocomplete** slash
|
|
118
|
+
command on its own, behind the same gate as Autofill (`GET /status` available,
|
|
119
|
+
and `getConfigForPath` allowing the collection). It does this through
|
|
120
|
+
`EditorAIControllerProvider` from `@rebasepro/cms`; a field whose
|
|
121
|
+
`customProps.editorProps.aiController` names one keeps its own. The hook below
|
|
122
|
+
is for a rich-text editor you render yourself:
|
|
123
|
+
|
|
117
124
|
```tsx
|
|
118
125
|
import { useEditorAIController } from "@rebasepro/plugin-ai";
|
|
119
126
|
|
package/dist/api.d.ts
CHANGED
|
@@ -39,9 +39,11 @@ export declare function fetchAiStatus(props: {
|
|
|
39
39
|
* the button flicker in and out for everyone behind it.
|
|
40
40
|
*
|
|
41
41
|
* Availability changes on the order of a deploy or a daily quota reset, not of a
|
|
42
|
-
* form open, so
|
|
43
|
-
* to `available: false` and
|
|
44
|
-
*
|
|
42
|
+
* form open, so the service's answer is kept for the session. A failed probe is
|
|
43
|
+
* not an answer: it resolves to `available: false` and is kept for 30 seconds,
|
|
44
|
+
* so a burst of form opens still asks once, and the first form opened after
|
|
45
|
+
* that asks again. Kept for the session, one dropped request hid Autofill until
|
|
46
|
+
* the page was reloaded.
|
|
45
47
|
*/
|
|
46
48
|
export declare function fetchAiStatusCached(props: {
|
|
47
49
|
endpoint?: string;
|
|
@@ -65,6 +67,13 @@ export declare function autofillStream(props: {
|
|
|
65
67
|
onValue: (key: string, value: unknown) => void;
|
|
66
68
|
}): Promise<AutofillResult>;
|
|
67
69
|
/** Inline continuation for the rich-text editor. Streams plain text. */
|
|
70
|
+
/**
|
|
71
|
+
* How many characters of the document the slash autocomplete sends on each
|
|
72
|
+
* side of the cursor. The hosted service keeps exactly this much and discards
|
|
73
|
+
* the rest, so sending more costs upload time on every request and buys
|
|
74
|
+
* nothing.
|
|
75
|
+
*/
|
|
76
|
+
export declare const MAX_AUTOCOMPLETE_CONTEXT = 8000;
|
|
68
77
|
export declare function autocompleteStream(props: {
|
|
69
78
|
textBefore?: string;
|
|
70
79
|
textAfter?: string;
|
package/dist/index.es.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React, { useCallback, useContext, useEffect, useMemo, useRef, useState } from "react";
|
|
2
|
+
import { EditorAIControllerProvider, getFieldId } from "@rebasepro/cms";
|
|
2
3
|
import { AIIcon, isDisabled, isHidden, isReadOnly, useAuthController } from "@rebasepro/app";
|
|
3
|
-
import { getFieldId } from "@rebasepro/cms";
|
|
4
4
|
import { isPropertyBuilder, stripCollectionPath } from "@rebasepro/common";
|
|
5
5
|
import { getValueInPath } from "@rebasepro/utils";
|
|
6
6
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
@@ -78,27 +78,36 @@ async function errorFrom(response, fallback) {
|
|
|
78
78
|
return new Error(fallback);
|
|
79
79
|
}
|
|
80
80
|
/**
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
* exhausted daily quota or an unreachable host all resolve to `available:
|
|
85
|
-
* false`, and the Autofill button is simply not rendered — rather than
|
|
86
|
-
* rendered, clicked, and failed.
|
|
81
|
+
* The status, and whether the service gave it. An error status (a 429 from the
|
|
82
|
+
* host's per-IP limit, a 503 mid-deploy) says nothing about the service and
|
|
83
|
+
* reads as `available: false` all the same; the cache below tells the two apart.
|
|
87
84
|
*/
|
|
88
|
-
async function
|
|
85
|
+
async function probeAiStatus(props) {
|
|
89
86
|
const response = await fetch(endpointOf(props.endpoint, "/status"), {
|
|
90
87
|
method: "GET",
|
|
91
88
|
signal: props.signal
|
|
92
89
|
});
|
|
93
|
-
if (!response.ok) return {
|
|
90
|
+
if (!response.ok) return {
|
|
91
|
+
status: { available: false },
|
|
92
|
+
answered: false
|
|
93
|
+
};
|
|
94
94
|
const body = await response.json();
|
|
95
95
|
return {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
96
|
+
status: {
|
|
97
|
+
available: Boolean(body?.available),
|
|
98
|
+
model: typeof body?.model === "string" ? body.model : void 0,
|
|
99
|
+
features: Array.isArray(body?.features) ? body.features : void 0
|
|
100
|
+
},
|
|
101
|
+
answered: true
|
|
99
102
|
};
|
|
100
103
|
}
|
|
101
|
-
/**
|
|
104
|
+
/** How long a failed probe's `available: false` stands before the next caller asks again. */
|
|
105
|
+
var FAILED_PROBE_TTL_MS = 3e4;
|
|
106
|
+
/**
|
|
107
|
+
* One probe per endpoint. Key: the status URL. An answer from the service is
|
|
108
|
+
* kept for the life of the page; a failed probe (unreachable host, an error
|
|
109
|
+
* status) for {@link FAILED_PROBE_TTL_MS}. Cleared by {@link clearAiStatusCache}.
|
|
110
|
+
*/
|
|
102
111
|
var statusProbes = /* @__PURE__ */ new Map();
|
|
103
112
|
/**
|
|
104
113
|
* {@link fetchAiStatus}, asked once per endpoint per session.
|
|
@@ -110,17 +119,23 @@ var statusProbes = /* @__PURE__ */ new Map();
|
|
|
110
119
|
* the button flicker in and out for everyone behind it.
|
|
111
120
|
*
|
|
112
121
|
* Availability changes on the order of a deploy or a daily quota reset, not of a
|
|
113
|
-
* form open, so
|
|
114
|
-
* to `available: false` and
|
|
115
|
-
*
|
|
122
|
+
* form open, so the service's answer is kept for the session. A failed probe is
|
|
123
|
+
* not an answer: it resolves to `available: false` and is kept for 30 seconds,
|
|
124
|
+
* so a burst of form opens still asks once, and the first form opened after
|
|
125
|
+
* that asks again. Kept for the session, one dropped request hid Autofill until
|
|
126
|
+
* the page was reloaded.
|
|
116
127
|
*/
|
|
117
128
|
function fetchAiStatusCached(props) {
|
|
118
129
|
const key = endpointOf(props.endpoint, "/status");
|
|
119
130
|
const existing = statusProbes.get(key);
|
|
120
|
-
if (existing) return existing;
|
|
121
|
-
const
|
|
122
|
-
|
|
123
|
-
|
|
131
|
+
if (existing && (existing.retryAfter === void 0 || Date.now() < existing.retryAfter)) return existing.answer;
|
|
132
|
+
const failed = () => {
|
|
133
|
+
entry.retryAfter = Date.now() + FAILED_PROBE_TTL_MS;
|
|
134
|
+
return { available: false };
|
|
135
|
+
};
|
|
136
|
+
const entry = { answer: probeAiStatus({ endpoint: props.endpoint }).then(({ status, answered }) => answered ? status : failed(), failed) };
|
|
137
|
+
statusProbes.set(key, entry);
|
|
138
|
+
return entry.answer;
|
|
124
139
|
}
|
|
125
140
|
/**
|
|
126
141
|
* Fill a record, streaming each field as the service writes it.
|
|
@@ -170,13 +185,20 @@ async function autofillStream(props) {
|
|
|
170
185
|
return result;
|
|
171
186
|
}
|
|
172
187
|
/** Inline continuation for the rich-text editor. Streams plain text. */
|
|
188
|
+
/**
|
|
189
|
+
* How many characters of the document the slash autocomplete sends on each
|
|
190
|
+
* side of the cursor. The hosted service keeps exactly this much and discards
|
|
191
|
+
* the rest, so sending more costs upload time on every request and buys
|
|
192
|
+
* nothing.
|
|
193
|
+
*/
|
|
194
|
+
var MAX_AUTOCOMPLETE_CONTEXT = 8e3;
|
|
173
195
|
async function autocompleteStream(props) {
|
|
174
196
|
const response = await fetch(endpointOf(props.endpoint, "/autocomplete"), {
|
|
175
197
|
method: "POST",
|
|
176
198
|
headers: { "Content-Type": "application/json" },
|
|
177
199
|
body: JSON.stringify({
|
|
178
|
-
textBefore: props.textBefore ?? "",
|
|
179
|
-
textAfter: props.textAfter ?? ""
|
|
200
|
+
textBefore: (props.textBefore ?? "").slice(-8e3),
|
|
201
|
+
textAfter: (props.textAfter ?? "").slice(0, MAX_AUTOCOMPLETE_CONTEXT)
|
|
180
202
|
}),
|
|
181
203
|
signal: props.signal
|
|
182
204
|
});
|
|
@@ -228,16 +250,23 @@ async function fetchPromptSuggestions(props) {
|
|
|
228
250
|
}
|
|
229
251
|
//#endregion
|
|
230
252
|
//#region src/utils/properties.ts
|
|
253
|
+
/**
|
|
254
|
+
* Merge `parts` into one record, in order, into a single accumulator.
|
|
255
|
+
*
|
|
256
|
+
* `reduce((a, b) => ({ ...a, ...b }))` copied everything gathered so far once
|
|
257
|
+
* per part: quadratic, and a page-builder record with 1,000 blocks took 371 ms.
|
|
258
|
+
*/
|
|
259
|
+
function mergeAll(parts, into = {}) {
|
|
260
|
+
for (const part of parts) Object.assign(into, part);
|
|
261
|
+
return into;
|
|
262
|
+
}
|
|
231
263
|
function getSimplifiedProperties(properties, values, path = "") {
|
|
232
264
|
if (!properties) return {};
|
|
233
|
-
return Object.entries(properties).map(([key, property]) => {
|
|
265
|
+
return mergeAll(Object.entries(properties).map(([key, property]) => {
|
|
234
266
|
if (isPropertyBuilder(property)) return {};
|
|
235
267
|
const fullKey = path ? `${path}.${key}` : key;
|
|
236
268
|
return getSimplifiedProperty(property, fullKey, getValueInPath(values, fullKey));
|
|
237
|
-
})
|
|
238
|
-
...a,
|
|
239
|
-
...b
|
|
240
|
-
}), {});
|
|
269
|
+
}));
|
|
241
270
|
}
|
|
242
271
|
/**
|
|
243
272
|
* Whether the form will not let anyone edit this field.
|
|
@@ -289,14 +318,11 @@ function getSimplifiedProperty(property, path, value, lockedByParent = false) {
|
|
|
289
318
|
oneOf: {
|
|
290
319
|
typeField: property.oneOf.typeField,
|
|
291
320
|
valueField: property.oneOf.valueField,
|
|
292
|
-
properties: Object.entries(property.oneOf.properties).map(([key, prop]) => ({ [key]: getSimpleProperty(prop, locked) }))
|
|
293
|
-
...a,
|
|
294
|
-
...b
|
|
295
|
-
}), {})
|
|
321
|
+
properties: mergeAll(Object.entries(property.oneOf.properties).map(([key, prop]) => ({ [key]: getSimpleProperty(prop, locked) })))
|
|
296
322
|
}
|
|
297
323
|
};
|
|
298
324
|
if (!Array.isArray(value)) return { [path]: arrayParentProperty };
|
|
299
|
-
return value.map((v, i) => {
|
|
325
|
+
return mergeAll(value.map((v, i) => {
|
|
300
326
|
if (v == null) return {};
|
|
301
327
|
const typeKey = property.oneOf.typeField ?? "type";
|
|
302
328
|
const oneOfType = v[typeKey];
|
|
@@ -312,19 +338,13 @@ function getSimplifiedProperty(property, path, value, lockedByParent = false) {
|
|
|
312
338
|
[`${path}.${i}.${typeKey}`]: oneOfType,
|
|
313
339
|
...simplifiedProperty
|
|
314
340
|
};
|
|
315
|
-
}).reduce((a, b) => ({
|
|
316
|
-
...a,
|
|
317
|
-
...b
|
|
318
341
|
}), { [path]: arrayParentProperty });
|
|
319
342
|
}
|
|
320
343
|
} else if (property.type === "map") {
|
|
321
344
|
if (property.properties) {
|
|
322
|
-
const mapProperties = Object.entries(property.properties).map(([key, childProperty]) => {
|
|
345
|
+
const mapProperties = mergeAll(Object.entries(property.properties).map(([key, childProperty]) => {
|
|
323
346
|
return getSimplifiedProperty(childProperty, key, value && typeof value === "object" ? value[key] : void 0, locked);
|
|
324
|
-
}).map((o) => attachPathToKeys(o, path))
|
|
325
|
-
...a,
|
|
326
|
-
...b
|
|
327
|
-
}), {});
|
|
347
|
+
}).map((o) => attachPathToKeys(o, path)));
|
|
328
348
|
if (Object.keys(mapProperties).length === 0) return {};
|
|
329
349
|
const mapParentProperty = {
|
|
330
350
|
name: property.name,
|
|
@@ -348,12 +368,9 @@ function getSimplifiedProperty(property, path, value, lockedByParent = false) {
|
|
|
348
368
|
return {};
|
|
349
369
|
}
|
|
350
370
|
function attachPathToKeys(obj, path = "") {
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
...a,
|
|
355
|
-
...b
|
|
356
|
-
}), {});
|
|
371
|
+
const out = {};
|
|
372
|
+
for (const [key, value] of Object.entries(obj)) out[path ? `${path}.${key}` : key] = value;
|
|
373
|
+
return out;
|
|
357
374
|
}
|
|
358
375
|
function getSimpleEnumValues(enumValues) {
|
|
359
376
|
if (Array.isArray(enumValues)) return enumValues.map((v) => String(v.id));
|
|
@@ -419,6 +436,21 @@ function omitDisabledValues(values, properties) {
|
|
|
419
436
|
if (disabled.length === 0) return values;
|
|
420
437
|
return Object.fromEntries(Object.entries(values).filter(([key]) => !disabled.some((prefix) => key === prefix || key.startsWith(`${prefix}.`))));
|
|
421
438
|
}
|
|
439
|
+
/**
|
|
440
|
+
* Whether a suggestion the service sent for `key` may reach the review: `key`
|
|
441
|
+
* is a property the request described, and neither it nor a map above it is
|
|
442
|
+
* disabled.
|
|
443
|
+
*
|
|
444
|
+
* The service answers with whatever keys it likes, steered by the record's
|
|
445
|
+
* other values — which visitors may have written. A suggestion for a locked
|
|
446
|
+
* field, or for a key that is no property at all, is one the request never
|
|
447
|
+
* asked for, and applying it writes past the lock the request stated.
|
|
448
|
+
*/
|
|
449
|
+
function isRequestedSuggestion(key, properties) {
|
|
450
|
+
const property = Object.hasOwn(properties ?? {}, key) ? properties[key] : void 0;
|
|
451
|
+
if (!property || typeof property !== "object" || property.disabled) return false;
|
|
452
|
+
return !Object.entries(properties).some(([prefix, other]) => other && typeof other === "object" && other.disabled && key.startsWith(`${prefix}.`));
|
|
453
|
+
}
|
|
422
454
|
//#endregion
|
|
423
455
|
//#region src/editor/useEditorAIController.tsx
|
|
424
456
|
/**
|
|
@@ -468,17 +500,17 @@ function DataEnhancementControllerProvider({ getConfigForPath, children, endpoin
|
|
|
468
500
|
const [allowedHere, setAllowedHere] = useState(false);
|
|
469
501
|
const [serviceAvailable, setServiceAvailable] = useState(false);
|
|
470
502
|
const [review, setReview] = useState(null);
|
|
471
|
-
const properties = useMemo(() => getSimplifiedProperties(collection.properties, formContext?.values ?? {}), [collection.properties, formContext?.values]);
|
|
472
503
|
/**
|
|
473
|
-
*
|
|
474
|
-
*
|
|
504
|
+
* The form's values as of the latest render, which the property map of a
|
|
505
|
+
* run is built from (a block list contributes one entry per block).
|
|
475
506
|
*
|
|
476
|
-
*
|
|
477
|
-
*
|
|
478
|
-
*
|
|
507
|
+
* Built in `generate`, once per run, rather than memoised on the values:
|
|
508
|
+
* that rebuilt it on every keystroke of every form, whether or not anybody
|
|
509
|
+
* ever pressed Autofill. The run's callbacks keep the map they started
|
|
510
|
+
* with — the operator is free to keep typing while the model works.
|
|
479
511
|
*/
|
|
480
|
-
const
|
|
481
|
-
|
|
512
|
+
const formValuesRef = useRef(formContext?.values);
|
|
513
|
+
formValuesRef.current = formContext?.values;
|
|
482
514
|
const user = useAuthController()?.user ?? null;
|
|
483
515
|
useEffect(() => {
|
|
484
516
|
if (!getConfigForPath) {
|
|
@@ -551,7 +583,7 @@ function DataEnhancementControllerProvider({ getConfigForPath, children, endpoin
|
|
|
551
583
|
});
|
|
552
584
|
}, []);
|
|
553
585
|
const generate = useCallback(async (params) => {
|
|
554
|
-
const currentProperties =
|
|
586
|
+
const currentProperties = getSimplifiedProperties(collection.properties, formValuesRef.current ?? {});
|
|
555
587
|
const flatValues = omitDisabledValues(flatMapEntityValues(params.values ?? {}), currentProperties);
|
|
556
588
|
setReview({
|
|
557
589
|
status: "generating",
|
|
@@ -577,7 +609,7 @@ function DataEnhancementControllerProvider({ getConfigForPath, children, endpoin
|
|
|
577
609
|
instructions: params.instructions
|
|
578
610
|
},
|
|
579
611
|
onDelta: (key, text) => {
|
|
580
|
-
if (!isCurrent()) return;
|
|
612
|
+
if (!isCurrent() || !isRequestedSuggestion(key, currentProperties)) return;
|
|
581
613
|
upsertField(key, (existing) => existing ? {
|
|
582
614
|
...existing,
|
|
583
615
|
proposed: String(existing.proposed ?? "") + text
|
|
@@ -591,7 +623,7 @@ function DataEnhancementControllerProvider({ getConfigForPath, children, endpoin
|
|
|
591
623
|
});
|
|
592
624
|
},
|
|
593
625
|
onValue: (key, value) => {
|
|
594
|
-
if (!isCurrent()) return;
|
|
626
|
+
if (!isCurrent() || !isRequestedSuggestion(key, currentProperties)) return;
|
|
595
627
|
const coerced = coerceToProperty(value, getPropertyFromKey(currentProperties, key));
|
|
596
628
|
upsertField(key, (existing) => ({
|
|
597
629
|
key,
|
|
@@ -691,7 +723,10 @@ function DataEnhancementControllerProvider({ getConfigForPath, children, endpoin
|
|
|
691
723
|
]);
|
|
692
724
|
return /* @__PURE__ */ jsx(DataEnhancementControllerContext.Provider, {
|
|
693
725
|
value: dataEnhancementController,
|
|
694
|
-
children
|
|
726
|
+
children: /* @__PURE__ */ jsx(EditorAIControllerProvider, {
|
|
727
|
+
controller: enabled ? editorAIController : void 0,
|
|
728
|
+
children
|
|
729
|
+
})
|
|
695
730
|
});
|
|
696
731
|
}
|
|
697
732
|
//#endregion
|
|
@@ -972,6 +1007,7 @@ function FormEnhanceAction({ path, status, collection, formContext }) {
|
|
|
972
1007
|
className: "pl-9 grow text-text-secondary dark:text-text-secondary-dark",
|
|
973
1008
|
children: samplePrompt.prompt
|
|
974
1009
|
}), samplePrompt.type === "recent" && /* @__PURE__ */ jsx(IconButton, {
|
|
1010
|
+
"aria-label": "Remove prompt",
|
|
975
1011
|
onClick: (e) => {
|
|
976
1012
|
e.preventDefault();
|
|
977
1013
|
e.stopPropagation();
|
|
@@ -1010,6 +1046,7 @@ function FormEnhanceAction({ path, status, collection, formContext }) {
|
|
|
1010
1046
|
}), instructions.length > 0 && !loading && /* @__PURE__ */ jsx("div", {
|
|
1011
1047
|
className: "flex flex-row justify-center items-center absolute h-full right-0 top-0 mr-2",
|
|
1012
1048
|
children: /* @__PURE__ */ jsx(IconButton, {
|
|
1049
|
+
"aria-label": "Clear instructions",
|
|
1013
1050
|
size: "small",
|
|
1014
1051
|
onClick: () => {
|
|
1015
1052
|
setInstructions("");
|
|
@@ -1018,9 +1055,9 @@ function FormEnhanceAction({ path, status, collection, formContext }) {
|
|
|
1018
1055
|
})
|
|
1019
1056
|
})]
|
|
1020
1057
|
}), /* @__PURE__ */ jsxs(IconButton, {
|
|
1058
|
+
"aria-label": "Generate",
|
|
1021
1059
|
onClick: () => generate(instructions),
|
|
1022
1060
|
size: "small",
|
|
1023
|
-
color: !instructions ? "primary" : void 0,
|
|
1024
1061
|
disabled: loading || !instructions,
|
|
1025
1062
|
children: [loading && /* @__PURE__ */ jsx(CircularProgress, { size: "smallest" }), !loading && /* @__PURE__ */ jsx(SendIcon, { size: iconSize.small })]
|
|
1026
1063
|
})]
|
package/dist/index.es.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.es.js","names":[],"sources":["../src/api.ts","../src/utils/properties.ts","../src/utils/values.ts","../src/editor/useEditorAIController.tsx","../src/components/DataEnhancementControllerProvider.tsx","../src/components/AutofillReviewDialog.tsx","../src/components/FormEnhanceAction.tsx","../src/useDataEnhancementPlugin.tsx"],"sourcesContent":["import {\n AutofillRequest,\n AutofillResult,\n AiStatus,\n SamplePromptsResult\n} from \"./types/data_enhancement_controller\";\n\n/**\n * The hosted service Rebase runs for this plugin.\n *\n * **This is where the entity's field values go.** Autofill posts them to\n * generate a suggestion, and unless the host sets `endpoint`, they go to this\n * address — off their machine, to a service Rebase operates. That is disclosed\n * on the plugins page rather than only here, because the person who needs to\n * know is the one deciding whether the data in those fields may leave.\n *\n * No credential travels with them; see the note below.\n *\n * The previous value here was `https://api.rebase.pro`, a FireCMS-era host that\n * resolves but serves nothing — every path 404s — so Autofill had never worked\n * in a Rebase install. This one is served by the control plane\n * (`saas/backend/functions/ai.ts`). Point `endpoint` somewhere else to run your\n * own; the wire format below is the whole contract.\n */\nexport const DEFAULT_AI_ENDPOINT = \"https://app.rebase.pro/api/functions/ai\";\n\n/**\n * ## No credentials cross this boundary\n *\n * The old client sent the tenant's Rebase JWT as `Authorization: Basic <jwt>`\n * plus a hardcoded `fcms-…` key compiled into the published package. Both were\n * wrong in the same way: a self-hosted backend signs its tokens with its own\n * secret, so no external service can verify one — sending it only handed a live\n * credential to a third party that had no use for it.\n *\n * These requests are anonymous. The service bounds cost by rate limit and daily\n * ceiling rather than by identity, and reports through {@link fetchAiStatus}\n * when it can no longer serve — which is what keeps the UI from offering an\n * action that is going to fail.\n */\nfunction endpointOf(endpoint: string | undefined, path: string): string {\n return (endpoint ?? DEFAULT_AI_ENDPOINT).replace(/\\/+$/, \"\") + path;\n}\n\n/** One `event:`/`data:` pair off the wire. */\ntype ServerSentEvent = { event: string; data: string };\n\n/** Not global: `exec` must not carry `lastIndex` between buffer reads. */\nconst SSE_SEPARATOR = /\\r?\\n\\r?\\n/;\n\n/**\n * Parse an SSE body incrementally.\n *\n * The framing this replaces split each chunk on the literal `\"&$# \"` and\n * `JSON.parse`d the pieces, which corrupted itself the moment a delimiter\n * straddled two reads — and network reads land wherever they land. Buffering\n * until a blank line is the fix, and it is also just what SSE specifies.\n */\nasync function* readServerSentEvents(response: Response): AsyncGenerator<ServerSentEvent> {\n const reader = response.body?.getReader();\n if (!reader) throw new Error(\"The AI service returned no response body\");\n\n const decoder = new TextDecoder();\n let buffer = \"\";\n\n for (;;) {\n const { done, value } = await reader.read();\n if (done) break;\n buffer += decoder.decode(value, { stream: true });\n\n // A record ends at a blank line. `\\r\\n` is tolerated because proxies\n // rewrite line endings. The separator is located with `exec` rather\n // than `search` so its actual length is known — a `\\r\\n\\r\\n` boundary\n // is four characters, not two, and slicing by the wrong count leaves a\n // stray newline that swallows the next record's `event:` field.\n let match = SSE_SEPARATOR.exec(buffer);\n while (match) {\n const raw = buffer.slice(0, match.index);\n buffer = buffer.slice(match.index + match[0].length);\n const parsed = parseEventBlock(raw);\n if (parsed) yield parsed;\n match = SSE_SEPARATOR.exec(buffer);\n }\n }\n}\n\nfunction parseEventBlock(block: string): ServerSentEvent | undefined {\n let event = \"message\";\n const dataLines: string[] = [];\n for (const line of block.split(/\\r?\\n/)) {\n if (line.startsWith(\":\")) continue; // comment / keep-alive\n const separator = line.indexOf(\":\");\n const field = separator === -1 ? line : line.slice(0, separator);\n const rawValue = separator === -1 ? \"\" : line.slice(separator + 1);\n const value = rawValue.startsWith(\" \") ? rawValue.slice(1) : rawValue;\n if (field === \"event\") event = value;\n else if (field === \"data\") dataLines.push(value);\n }\n if (dataLines.length === 0) return undefined;\n return { event,\ndata: dataLines.join(\"\\n\") };\n}\n\n/** Pull a message out of the control plane's `{ error: { message } }` envelope. */\nasync function errorFrom(response: Response, fallback: string): Promise<Error> {\n try {\n const body = await response.json();\n const message = body?.error?.message;\n if (typeof message === \"string\" && message) return new Error(message);\n } catch {\n /* not JSON — fall through */\n }\n return new Error(fallback);\n}\n\n/**\n * Ask the service whether it can serve a request at all.\n *\n * The plugin gates every affordance on this. A missing provider key, an\n * exhausted daily quota or an unreachable host all resolve to `available:\n * false`, and the Autofill button is simply not rendered — rather than\n * rendered, clicked, and failed.\n */\nexport async function fetchAiStatus(props: { endpoint?: string; signal?: AbortSignal }): Promise<AiStatus> {\n const response = await fetch(endpointOf(props.endpoint, \"/status\"), {\n method: \"GET\",\n signal: props.signal\n });\n if (!response.ok) return { available: false };\n const body = await response.json();\n return {\n available: Boolean(body?.available),\n model: typeof body?.model === \"string\" ? body.model : undefined,\n features: Array.isArray(body?.features) ? body.features : undefined\n };\n}\n\n/** One in-flight or settled probe per endpoint, for the life of the page. */\nconst statusProbes = new Map<string, Promise<AiStatus>>();\n\n/**\n * {@link fetchAiStatus}, asked once per endpoint per session.\n *\n * The provider is form-scoped, so the uncached call meant one request to the\n * host every time any record was opened — a beacon on an install that may never\n * click Autofill, and enough traffic from one NAT'd office to spend the host's\n * per-IP rate limit on nothing, which reads back as `available: false` and makes\n * the button flicker in and out for everyone behind it.\n *\n * Availability changes on the order of a deploy or a daily quota reset, not of a\n * form open, so a session-long answer is the right resolution. Failures resolve\n * to `available: false` and are cached like any other answer — retrying per form\n * open is the behaviour this replaces.\n */\nexport function fetchAiStatusCached(props: { endpoint?: string }): Promise<AiStatus> {\n const key = endpointOf(props.endpoint, \"/status\");\n const existing = statusProbes.get(key);\n if (existing) return existing;\n const probe = fetchAiStatus({ endpoint: props.endpoint })\n .catch(() => ({ available: false }) as AiStatus);\n statusProbes.set(key, probe);\n return probe;\n}\n\n/** Forget every cached probe, so the next caller asks again. */\nexport function clearAiStatusCache(): void {\n statusProbes.clear();\n}\n\n/**\n * Fill a record, streaming each field as the service writes it.\n *\n * `onDelta` fires with more text for a field still being written; `onValue`\n * fires once a field is complete and carries its final, correctly typed value.\n * A caller that implements only `onValue` still ends up with the right record —\n * the deltas exist so a long text field fills in visibly instead of appearing\n * all at once.\n */\nexport async function autofillStream(props: {\n request: AutofillRequest;\n endpoint?: string;\n signal?: AbortSignal;\n onDelta: (key: string, text: string) => void;\n onValue: (key: string, value: unknown) => void;\n}): Promise<AutofillResult> {\n const response = await fetch(endpointOf(props.endpoint, \"/autofill\"), {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify(props.request),\n signal: props.signal\n });\n\n if (!response.ok) {\n throw await errorFrom(response, \"The AI service could not complete this request.\");\n }\n\n let result: AutofillResult = { suggestions: {} };\n let done = false;\n let delivered = 0;\n let discarded = 0;\n\n for await (const { event, data } of readServerSentEvents(response)) {\n let payload: any;\n try {\n payload = JSON.parse(data);\n } catch {\n // One malformed record must not abort a stream that is otherwise\n // delivering good fields — but it is counted, because a run that\n // delivered nothing *but* malformed records is a failure, not an\n // answer of \"there was nothing to fill in\".\n discarded++;\n continue;\n }\n\n if (event === \"suggestion_delta\") {\n delivered++;\n props.onDelta(payload.key, payload.text);\n } else if (event === \"suggestion\") {\n delivered++;\n props.onValue(payload.key, payload.value);\n } else if (event === \"done\") {\n done = true;\n result = {\n suggestions: payload.suggestions ?? {},\n usage: payload.usage\n };\n } else if (event === \"error\") {\n throw new Error(payload.message ?? \"The AI service reported an error.\");\n }\n }\n\n // The service closes every run it finished with a `done` record — including\n // the run that had nothing to fill, which is an empty `done` and not an\n // empty body. So a body that simply stops is a truncation: a rolled pod, a\n // proxy timeout, a dropped connection. Reported as one, because the caller's\n // only other reading of an empty result is \"nothing needed filling\", and\n // telling an operator that their empty fields are fields the model would not\n // improve on is a confident, wrong answer they have no way to question.\n if (!done) {\n throw new Error(\"The connection to the AI service ended before it finished.\");\n }\n if (discarded > 0 && delivered === 0) {\n throw new Error(\"The AI service's response could not be read.\");\n }\n\n return result;\n}\n\n/** Inline continuation for the rich-text editor. Streams plain text. */\nexport async function autocompleteStream(props: {\n textBefore?: string;\n textAfter?: string;\n endpoint?: string;\n signal?: AbortSignal;\n onDelta: (text: string) => void;\n}): Promise<string> {\n const response = await fetch(endpointOf(props.endpoint, \"/autocomplete\"), {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify({\n textBefore: props.textBefore ?? \"\",\n textAfter: props.textAfter ?? \"\"\n }),\n signal: props.signal\n });\n\n if (!response.ok) {\n throw await errorFrom(response, \"The AI service could not complete this request.\");\n }\n\n let text = \"\";\n for await (const { event, data } of readServerSentEvents(response)) {\n let payload: any;\n try {\n payload = JSON.parse(data);\n } catch {\n continue;\n }\n if (event === \"error\") {\n throw new Error(payload?.message ?? \"The AI service reported an error.\");\n }\n if (event === \"delta\" && typeof payload?.text === \"string\") {\n text += payload.text;\n props.onDelta(payload.text);\n }\n }\n return text;\n}\n\n/**\n * Sample prompts for the Autofill menu.\n *\n * Failure is deliberately not thrown: the menu has built-in prompts to fall\n * back on, and an empty suggestion list is a far better outcome than an error\n * toast for something nobody asked for.\n */\nexport async function fetchPromptSuggestions(props: {\n entityName: string;\n /** Ties suggestions to the domain — see the note on the service's side. */\n entityDescription?: string;\n input?: string;\n endpoint?: string;\n signal?: AbortSignal;\n}): Promise<SamplePromptsResult> {\n try {\n const response = await fetch(endpointOf(props.endpoint, \"/prompts\"), {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify({\n entityName: props.entityName,\n entityDescription: props.entityDescription,\n input: props.input\n }),\n signal: props.signal\n });\n if (!response.ok) return { prompts: [] };\n const body = await response.json();\n const prompts: string[] = Array.isArray(body?.prompts) ? body.prompts : [];\n return {\n prompts: prompts\n .filter((p): p is string => typeof p === \"string\")\n .map((prompt) => ({ prompt,\ntype: \"sample\" as const }))\n };\n } catch {\n return { prompts: [] };\n }\n}\n","import { getFieldId } from \"@rebasepro/cms\";\nimport { EnumValues, Properties, Property } from \"@rebasepro/types\";\nimport { isPropertyBuilder } from \"@rebasepro/common\";\nimport { InputProperty } from \"../types/data_enhancement_controller\";\nimport { getValueInPath } from \"@rebasepro/utils\";\nimport { isDisabled, isHidden, isReadOnly } from \"@rebasepro/app\";\n\nexport function getSimplifiedProperties<M extends Record<string, any>>(properties: Properties, values: M, path = \"\"): Record<string, InputProperty> {\n if (!properties) return {};\n return Object.entries(properties)\n .map(([key, property]) => {\n if (isPropertyBuilder(property)) return {};\n const fullKey = path ? `${path}.${key}` : key;\n const valueInPath = getValueInPath(values, fullKey);\n return getSimplifiedProperty(property, fullKey, valueInPath)\n })\n .reduce((a, b) => ({ ...a,\n...b }), {});\n}\n\n/**\n * Whether the form will not let anyone edit this field.\n *\n * The same three gates the form lays a field out with, so a literal\n * `conditions.readOnly` or a date the backend stamps is locked here too. A\n * locked container locks everything under it: the form disables a map's\n * children with the map, so they are not the model's to fill either.\n */\nfunction isLocked(property: Property, lockedByParent: boolean): boolean {\n return lockedByParent || isReadOnly(property) || isDisabled(property) || isHidden(property);\n}\n\nfunction getSimpleProperty(property: Property, lockedByParent = false): InputProperty {\n const fieldId = getFieldId(property);\n if (!fieldId) {\n console.error(\"No fieldId found for property\", property);\n throw new Error(\"Field id not found\");\n }\n return {\n name: property.name,\n description: property.description,\n type: property.type,\n fieldConfigId: fieldId,\n enum: \"enum\" in property && property.enum\n ? getSimpleEnumValues(property.enum)\n : undefined,\n disabled: isLocked(property, lockedByParent)\n };\n}\n\nfunction getSimplifiedProperty(property: Property, path: string, value?: unknown, lockedByParent = false): Record<string, InputProperty> {\n if (isPropertyBuilder(property)) return {};\n const locked = isLocked(property, lockedByParent);\n if (property.type === \"array\") {\n\n if (property.of && !Array.isArray(property.of) && !isPropertyBuilder(property.of)) {\n const arrayParentProperty: InputProperty = {\n name: property.name,\n description: property.description,\n type: property.type,\n fieldConfigId: \"repeat\",\n disabled: locked,\n of: getSimpleProperty(property.of as Property, locked)\n };\n\n const result = { [path]: arrayParentProperty };\n // if (Array.isArray(value)) {\n // result = {\n // ...result,\n // ...value\n // .map((v, i) => getSimplifiedProperty(property.of, `${path}.${i}`, v))\n // .reduce((a, b) => ({ ...a, ...b }), {})\n // };\n // }\n //\n // const existingValuesCount = Array.isArray(value) ? value.length : 0;\n //\n // const newValuesCount = property.of && !isPropertyBuilder<any, any>(property.of) && (property.of as Property).type === \"map\" ? 1 : 3;\n // result = {\n // ...result,\n // // ...Array.from(Array(newValuesCount))\n // // .map((v, i) => getSimplifiedProperty(property.of, `${path}.${i + existingValuesCount}`, v))\n // // .reduce((a, b) => ({ ...a, ...b }), {})\n // }\n\n return result;\n } else if (property.oneOf) {\n\n const arrayParentProperty: InputProperty = {\n name: property.name,\n description: property.description,\n type: property.type,\n fieldConfigId: \"block\",\n disabled: locked,\n oneOf: {\n typeField: property.oneOf.typeField,\n valueField: property.oneOf.valueField,\n properties: Object.entries(property.oneOf.properties)\n .map(([key, prop]) => ({ [key]: getSimpleProperty(prop, locked) }))\n .reduce((a, b) => ({ ...a,\n...b }), {})\n }\n };\n\n if (!Array.isArray(value)) {\n return { [path]: arrayParentProperty };\n }\n\n return value.map((v, i) => {\n if (v == null) return {};\n const typeKey = property.oneOf!.typeField ?? \"type\";\n const oneOfType = v[typeKey];\n const valueKey = property.oneOf!.valueField ?? \"value\";\n const oneOfValue = v[valueKey];\n const childProperty = property.oneOf!.properties[oneOfType];\n if (childProperty === undefined) {\n console.error(`No property found for type ${oneOfType}`, property.oneOf!.properties);\n return {};\n }\n const simplifiedProperty = getSimplifiedProperty(childProperty, `${path}.${i}.${valueKey}`, oneOfValue, locked);\n return {\n [`${path}.${i}.${typeKey}`]: oneOfType,\n ...simplifiedProperty\n };\n }).reduce((a, b) => ({ ...a,\n...b }), { [path]: arrayParentProperty });\n }\n } else if (property.type === \"map\") {\n if (property.properties) {\n const mapProperties: Record<string, InputProperty> = Object.entries(property.properties)\n .map(([key, childProperty]) => {\n const childValue = value && typeof value === \"object\" ? (value as Record<string, unknown>)[key] : undefined;\n return getSimplifiedProperty(childProperty, key, childValue, locked);\n })\n .map(o => attachPathToKeys(o, path))\n .reduce((a, b) => ({ ...a,\n...b }), {});\n\n if (Object.keys(mapProperties).length === 0) return {};\n const mapParentProperty: InputProperty = {\n name: property.name,\n description: property.description,\n type: property.type,\n fieldConfigId: \"group\",\n disabled: locked\n };\n return {\n [path]: mapParentProperty,\n ...mapProperties\n } as Record<string, InputProperty>;\n }\n } else {\n const fieldId = getFieldId(property);\n if (!fieldId) {\n console.warn(`No fieldId found for property ${path} with type ${property.type}`);\n return {};\n }\n return {\n [path]: getSimpleProperty(property, lockedByParent)\n };\n }\n return {};\n}\n\n// attach a path to every key in an object\nfunction attachPathToKeys(obj: Record<string, InputProperty>, path = \"\"): Record<string, InputProperty> {\n return Object.entries(obj)\n .map(([key, value]) => {\n const fullKey = path ? `${path}.${key}` : key;\n return { [fullKey]: value };\n })\n .reduce((a, b) => ({ ...a,\n...b }), {});\n}\n\nfunction getSimpleEnumValues(enumValues: EnumValues): string[] {\n if (Array.isArray(enumValues))\n return enumValues.map(v => String(v.id));\n if (typeof enumValues === \"object\")\n return Object.keys(enumValues);\n throw Error(\"getSimpleEnumValues: Invalid enumValues\");\n}\n","import { InputProperty } from \"../types/data_enhancement_controller\";\n\n/**\n * Flatten a record onto the dotted paths the property map uses.\n *\n * The two halves of an autofill request have to be keyed the same way: the\n * service decides a field is empty by looking up `values[key]` for every `key`\n * in `properties`, so a value filed under a key the property map has never\n * heard of is a value the service cannot see.\n *\n * Only plain objects are containers. This used to recurse into anything\n * `typeof value === \"object\"`, which is both an array and a `Date` — so\n * `tags: [\"a\", \"b\"]` was sent as `tags.0`/`tags.1` while the property map still\n * called it `tags`, and a `Date` disappeared entirely (`Object.entries(date)` is\n * `[]`). Both then read as empty on the far side and came back in the review\n * pre-ticked to replace a value the record already had. `getSimplifiedProperties`\n * names an array by its own path and never descends into one, so neither does\n * this.\n */\nexport function flatMapEntityValues<M extends object>(values: M, path = \"\"): Record<string, unknown> {\n if (!values) return {};\n return Object.entries(values).flatMap(([key, value]) => {\n const currentPath = path ? `${path}.${key}` : key;\n if (isPlainObject(value)) {\n return flatMapEntityValues(value, currentPath);\n } else {\n return { [currentPath]: value };\n }\n }).reduce((acc, curr) => ({ ...acc,\n...curr }), {});\n}\n\n/**\n * A container, as opposed to a leaf value.\n *\n * Arrays, dates, files and every other class instance are values in their own\n * right — a map property is the only thing whose children are separate fields.\n */\nfunction isPlainObject(value: unknown): value is Record<string, unknown> {\n if (value === null || typeof value !== \"object\") return false;\n const proto = Object.getPrototypeOf(value);\n return proto === Object.prototype || proto === null;\n}\n\n/**\n * Drop the values of properties the panel will not let anyone edit.\n *\n * A `readOnly` or `disabled` property is already excluded from what the service\n * may fill, but the values map was built from the whole record, and the prompt\n * includes every value it is given as context. So a field marked read-only\n * because a backend hook owns it — an internal note, a customer id — was still\n * being transmitted and pasted into the prompt. The collection config lives\n * here, so this is the honest place to decide it: disabled means neither\n * fillable nor context.\n *\n * Prefixes match too: a disabled map takes its children with it.\n */\nexport function omitDisabledValues(\n values: Record<string, unknown>,\n properties: Record<string, InputProperty>\n): Record<string, unknown> {\n const disabled = Object.entries(properties ?? {})\n // A property map can carry a non-object at a path (see the `oneOf`\n // branch of `getSimplifiedProperty`), and `\"disabled\" in aString` throws.\n .filter(([, property]) => property && typeof property === \"object\" && property.disabled)\n .map(([key]) => key);\n if (disabled.length === 0) return values;\n return Object.fromEntries(\n Object.entries(values).filter(([key]) =>\n !disabled.some((prefix) => key === prefix || key.startsWith(`${prefix}.`)))\n );\n}\n","import React from \"react\";\nimport { autocompleteStream } from \"../api\";\nimport { EditorAIController } from \"@rebasepro/cms\";\n\n/**\n * Inline continuation for the rich-text editor's slash command.\n *\n * No token is threaded through any more. The previous version demanded a\n * Firebase ID token and threw `\"Firebase token is required\"` when it could not\n * get one — in a Rebase app there is no such thing, and the token it actually\n * sent was a Rebase JWT the receiving service had no way to verify. The hosted\n * service authenticates nobody; see `src/api.ts`.\n */\nexport function useEditorAIController({ endpoint }: { endpoint?: string } = {}): EditorAIController {\n return React.useMemo(() => ({\n autocomplete: (textBefore: string, textAfter: string, onUpdate: (delta: string) => void) =>\n autocompleteStream({\n endpoint,\n textBefore,\n textAfter,\n onDelta: onUpdate\n })\n }), [endpoint]);\n}\n","import React, { PropsWithChildren, useCallback, useContext, useEffect, useMemo, useRef, useState } from \"react\";\n\nimport {\n AutofillReview,\n DataEnhancementController,\n GenerateParams,\n InputProperty,\n ProposedField\n} from \"../types/data_enhancement_controller\";\nimport { CollectionConfig, User } from \"@rebasepro/types\";\nimport { PluginFormActionProps } from \"@rebasepro/cms-types\";\nimport { useAuthController } from \"@rebasepro/app\";\nimport { autofillStream, fetchAiStatusCached, fetchPromptSuggestions } from \"../api\";\nimport { getSimplifiedProperties } from \"../utils/properties\";\nimport { flatMapEntityValues, omitDisabledValues } from \"../utils/values\";\nimport { useEditorAIController } from \"../editor/useEditorAIController\";\nimport { getValueInPath } from \"@rebasepro/utils\";\n\nconst DataEnhancementControllerContext = React.createContext<DataEnhancementController>(null! as DataEnhancementController);\n\ntype DataEnhancementControllerProviderProps = {\n\n /**\n * Kept in step with `DataEnhancementPluginProps.getConfigForPath`, which is\n * the signature the host app actually writes against: the plugin hands this\n * component through as `ComponentType<any>`, so nothing but agreement here\n * makes the two match.\n */\n getConfigForPath?: (props: {\n path: string,\n collection: CollectionConfig,\n user: User | null\n }) => boolean;\n\n endpoint?: string;\n}\n\nexport const useDataEnhancementController = (): DataEnhancementController => useContext(DataEnhancementControllerContext);\n\nfunction getPropertyFromKey(properties: Record<string, InputProperty>, propertyKey: string): InputProperty | undefined {\n if (propertyKey in properties) {\n return properties[propertyKey];\n }\n const split = propertyKey.split(\".\");\n if (split.length === 1) return undefined;\n return getPropertyFromKey(properties, split.slice(0, -1).join(\".\"));\n}\n\n/**\n * Convert a value off the wire into what the form field expects.\n *\n * Only dates need converting: the service answers ISO-8601 strings because JSON\n * has no date type, and handing a date field a string stores the wrong type\n * without complaining. Everything else — strings, numbers, booleans, arrays of\n * scalars — is already the shape the field wants, which is the point of having\n * the service constrain its answer to a schema derived from these properties.\n */\nfunction coerceToProperty(value: unknown, property: InputProperty | undefined): unknown {\n if (property?.type === \"date\" && typeof value === \"string\") {\n const date = new Date(value);\n return Number.isNaN(date.getTime()) ? undefined : date;\n }\n return value;\n}\n\nexport function DataEnhancementControllerProvider({\n getConfigForPath,\n children,\n endpoint,\n path,\n collection,\n formContext\n}: PropsWithChildren<DataEnhancementControllerProviderProps & PluginFormActionProps>) {\n\n const [allowedHere, setAllowedHere] = useState(false);\n const [serviceAvailable, setServiceAvailable] = useState(false);\n const [review, setReview] = useState<AutofillReview | null>(null);\n\n const properties = useMemo(\n () => getSimplifiedProperties(collection.properties, formContext?.values ?? {}),\n [collection.properties, formContext?.values]\n );\n\n /**\n * Read inside the streaming callbacks, which outlive the render that\n * started the run.\n *\n * The operator is free to keep typing while the model works — nothing here\n * writes to the form — so the callbacks must not close over a stale\n * property map from whichever render happened to kick the run off.\n */\n const propertiesRef = useRef(properties);\n propertiesRef.current = properties;\n\n /**\n * The host app's own opt-out.\n *\n * `user` is part of the documented signature and was never passed, so\n * `getConfigForPath: ({ user }) => user?.roles?.includes(\"editor\")` was\n * `Boolean(undefined)` for everyone — an access rule that silently decided\n * nothing, in whichever direction the host had written it.\n */\n const authController = useAuthController();\n const user: User | null = authController?.user ?? null;\n\n useEffect(() => {\n if (!getConfigForPath) {\n setAllowedHere(true);\n return;\n }\n setAllowedHere(Boolean(getConfigForPath({ path,\ncollection,\nuser })));\n }, [getConfigForPath, path, collection, user]);\n\n /**\n * The service's own availability.\n *\n * Nothing renders until this comes back true. An unreachable host, an\n * unconfigured provider key or an exhausted daily quota all land here, and\n * all of them mean the same thing to the operator: no Autofill button,\n * rather than a button that fails when clicked.\n *\n * Asked through the session cache: this provider is form-scoped, so an\n * uncached probe is one request to the host per record opened, by an install\n * that may never use the feature. The probe is shared rather than aborted on\n * unmount — cancelling it would cancel it for whatever else is waiting on the\n * same answer — so unmounting only stops this component from reading it.\n */\n useEffect(() => {\n if (!allowedHere) return;\n let cancelled = false;\n fetchAiStatusCached({ endpoint })\n .then((status) => {\n if (!cancelled) setServiceAvailable(status.available);\n });\n return () => {\n cancelled = true;\n };\n }, [allowedHere, endpoint]);\n\n const enabled = allowedHere && serviceAvailable;\n\n /**\n * The run whose review is on screen.\n *\n * A run outlives the review it was started for: the operator can discard\n * it, or start another, while its stream is still arriving. Every callback\n * checks it is still the current run before touching the review, and a run\n * that stops being current has its request cancelled. Without this, a\n * discarded run kept writing into the next run's review and, when it ended,\n * marked that review ready while the new run was still writing.\n */\n const currentRunRef = useRef<AbortController | null>(null);\n\n const cancelCurrentRun = useCallback(() => {\n currentRunRef.current?.abort();\n currentRunRef.current = null;\n }, []);\n\n // A form closed mid-run has nobody left to review what it produces.\n useEffect(() => cancelCurrentRun, [cancelCurrentRun]);\n\n /** Add or update one row in the review, preserving arrival order. */\n const upsertField = useCallback((key: string, update: (existing: ProposedField | undefined) => ProposedField) => {\n setReview((current) => {\n if (!current) return current;\n const index = current.fields.findIndex((f) => f.key === key);\n const next = update(index === -1 ? undefined : current.fields[index]);\n const fields = index === -1\n ? [...current.fields, next]\n : current.fields.map((f, i) => (i === index ? next : f));\n return { ...current,\nfields };\n });\n }, []);\n\n const generate = useCallback(async (params: GenerateParams<Record<string, unknown>>): Promise<void> => {\n\n const currentProperties = propertiesRef.current;\n const flatValues = omitDisabledValues(\n flatMapEntityValues(params.values ?? {}),\n currentProperties\n );\n\n setReview({\n status: \"generating\",\n fields: [],\n instructions: params.instructions\n });\n\n const labelFor = (key: string) => currentProperties[key]?.name ?? key;\n\n cancelCurrentRun();\n const run = new AbortController();\n currentRunRef.current = run;\n const isCurrent = () => currentRunRef.current === run;\n\n try {\n await autofillStream({\n endpoint,\n signal: run.signal,\n request: {\n entityName: collection.singularName ?? collection.name,\n entityDescription: collection.description,\n // Flattened to dotted paths so the keys line up with the\n // property map: the service is told about `seo.title`, so it\n // has to be told the value of `seo.title` too, not of `seo`.\n // Exactly the same rule in both directions — an array or a\n // date is one value under one key here because it is one\n // property under one key there. Where they disagreed, the\n // service read a filled field as empty and offered to\n // rewrite it. Values of properties nobody may edit do not\n // travel at all.\n values: flatValues,\n properties: currentProperties,\n propertyKey: params.propertyKey,\n propertyInstructions: params.propertyInstructions,\n instructions: params.instructions\n },\n onDelta: (key, text) => {\n if (!isCurrent()) return;\n upsertField(key, (existing) => existing\n ? { ...existing,\nproposed: String(existing.proposed ?? \"\") + text }\n : {\n key,\n label: labelFor(key),\n currentValue: getValueInPath(params.values, key),\n proposed: text,\n pending: true,\n selected: true\n });\n },\n onValue: (key, value) => {\n if (!isCurrent()) return;\n const coerced = coerceToProperty(value, getPropertyFromKey(currentProperties, key));\n upsertField(key, (existing) => ({\n key,\n label: existing?.label ?? labelFor(key),\n currentValue: existing?.currentValue ?? getValueInPath(params.values, key),\n proposed: coerced,\n pending: false,\n // A row the operator already deselected mid-stream stays\n // deselected when its final value lands.\n selected: existing?.selected ?? true\n }));\n }\n });\n\n if (!isCurrent()) return;\n currentRunRef.current = null;\n setReview((current) => current && {\n ...current,\n status: \"ready\",\n // Fields still pending when the run ended never received a final\n // value — the model's JSON was cut off mid-string, so all we\n // hold is a half-written sentence. Marking them complete would\n // make that sentence applicable, which is the exact outcome the\n // review exists to prevent. They are dropped instead: the review\n // only ever offers what the service actually finished.\n fields: current.fields.filter((f) => !f.pending)\n });\n } catch (e: unknown) {\n // A run that was discarded or replaced fails with the abort, and\n // has nothing left to report to.\n if (!isCurrent()) return;\n currentRunRef.current = null;\n const message = e instanceof Error ? e.message : \"Autofill could not be completed\";\n // Kept in the review rather than fired into a snackbar: a run that\n // produced three good fields and then failed should still let the\n // operator apply the three.\n setReview((current) => current && {\n ...current,\n status: \"failed\",\n error: message,\n // Same rule as the success path: a field interrupted mid-write\n // is not something the operator can be offered.\n fields: current.fields.filter((f) => !f.pending)\n });\n }\n }, [collection, endpoint, upsertField, cancelCurrentRun]);\n\n const toggleField = useCallback((key: string) => {\n setReview((current) => current && {\n ...current,\n fields: current.fields.map((f) => (f.key === key ? { ...f,\nselected: !f.selected } : f))\n });\n }, []);\n\n const toggleAll = useCallback((selected: boolean) => {\n setReview((current) => current && {\n ...current,\n fields: current.fields.map((f) => ({ ...f,\nselected }))\n });\n }, []);\n\n const dismissReview = useCallback(() => {\n cancelCurrentRun();\n setReview(null);\n }, [cancelCurrentRun]);\n\n const applyReview = useCallback(() => {\n // Applied mid-stream, the rest of the run has no review to land in.\n cancelCurrentRun();\n setReview((current) => {\n if (!current) return null;\n for (const field of current.fields) {\n if (!field.selected || field.pending) continue;\n if (field.proposed === undefined || field.proposed === null) continue;\n formContext?.setFieldValue(field.key, field.proposed);\n }\n return null;\n });\n }, [formContext, cancelCurrentRun]);\n\n const editorAIController = useEditorAIController({ endpoint });\n\n const getSamplePrompts = useCallback(\n (entityName: string, input?: string) => fetchPromptSuggestions({\n endpoint,\n entityName,\n entityDescription: collection.description,\n input\n }),\n [endpoint, collection.description]\n );\n\n const dataEnhancementController: DataEnhancementController = useMemo(() => ({\n enabled,\n review,\n generate,\n toggleField,\n toggleAll,\n applyReview,\n dismissReview,\n getSamplePrompts,\n editorAIController\n }), [\n enabled,\n review,\n generate,\n toggleField,\n toggleAll,\n applyReview,\n dismissReview,\n getSamplePrompts,\n editorAIController\n ]);\n\n return (\n <DataEnhancementControllerContext.Provider\n value={dataEnhancementController}>\n {children}\n </DataEnhancementControllerContext.Provider>\n );\n}\n","import React from \"react\";\n\nimport {\n Button,\n Checkbox,\n CircularProgress,\n cls,\n Dialog,\n DialogActions,\n DialogContent,\n DialogTitle,\n Separator,\n Typography\n} from \"@rebasepro/ui\";\n\nimport { ProposedField } from \"../types/data_enhancement_controller\";\nimport { useDataEnhancementController } from \"./DataEnhancementControllerProvider\";\n\n/**\n * The review step.\n *\n * Autofill used to write generated text into the live form as it streamed —\n * fields mutating under the cursor, half-written sentences that looked like\n * bugs, and a pile of heuristics deciding whether each token should append to\n * or replace what the operator had already typed. Getting the old value back\n * meant retyping it.\n *\n * So the generated values land here instead. Streaming still happens, and is\n * still worth having — rows appear and fill in as the model works, so a long\n * run shows progress — but it happens in a surface that owns nothing. The\n * record changes on **Apply**, once, for the rows still ticked.\n */\nexport function AutofillReviewDialog() {\n\n const controller = useDataEnhancementController();\n const review = controller?.review;\n\n if (!review) return null;\n\n const generating = review.status === \"generating\";\n const applicable = review.fields.filter((f) => !f.pending && f.selected);\n const allSelected = review.fields.length > 0 && review.fields.every((f) => f.selected);\n\n return (\n <Dialog\n open={true}\n maxWidth={\"2xl\"}\n onOpenChange={(open) => {\n if (!open) controller.dismissReview();\n }}>\n\n <DialogTitle variant={\"subtitle1\"} gutterBottom={false}>\n Review autofill\n </DialogTitle>\n\n <DialogContent className={\"flex flex-col gap-2\"}>\n\n {review.instructions && (\n <Typography variant={\"body2\"} color={\"secondary\"} className={\"italic\"}>\n “{review.instructions}”\n </Typography>\n )}\n\n {review.fields.length > 1 && (\n <>\n <label className={\"flex items-center gap-3 py-1 cursor-pointer select-none\"}>\n <Checkbox\n checked={allSelected}\n size={\"small\"}\n onCheckedChange={() => controller.toggleAll(!allSelected)}\n />\n {/* `component=\"span\"`: the Typography `label`\n variant renders a <label> element, and this sits\n inside the row's own <label>. Nested labels are\n invalid HTML and stop the text toggling the\n checkbox — clicking \"Select all\" did nothing. */}\n <Typography variant={\"label\"} component={\"span\"} color={\"secondary\"}>\n {allSelected ? \"Deselect all\" : \"Select all\"}\n </Typography>\n </label>\n <Separator orientation={\"horizontal\"} className={\"my-0\"}/>\n </>\n )}\n\n <div className={\"flex flex-col divide-y divide-surface-accent-100 dark:divide-surface-accent-800\"}>\n {review.fields.map((field) => (\n <ProposedFieldRow\n key={field.key}\n field={field}\n onToggle={() => controller.toggleField(field.key)}\n />\n ))}\n </div>\n\n {generating && (\n <div className={\"flex items-center gap-3 py-4 text-text-secondary dark:text-text-secondary-dark\"}>\n <CircularProgress size={\"smallest\"}/>\n <Typography variant={\"body2\"} color={\"secondary\"}>\n {review.fields.length === 0 ? \"Thinking…\" : \"Writing the remaining fields…\"}\n </Typography>\n </div>\n )}\n\n {review.status === \"failed\" && (\n <Typography variant={\"body2\"} className={\"py-2 text-red-600 dark:text-red-400\"}>\n {review.error}\n {review.fields.length > 0 && \" You can still apply what was written before it stopped.\"}\n </Typography>\n )}\n\n {!generating && review.fields.length === 0 && review.status !== \"failed\" && (\n <Typography variant={\"body2\"} color={\"secondary\"} className={\"py-4\"}>\n Nothing to fill in — every field either already has a value the model would not\n improve on, or is not one it can write.\n </Typography>\n )}\n\n </DialogContent>\n\n <DialogActions>\n <Button variant={\"text\"}\n color={\"neutral\"}\n onClick={controller.dismissReview}>\n {/* Named for what it does to the record, not to the dialog:\n nothing has been written, so there is nothing to undo. */}\n Discard\n </Button>\n <Button variant={\"filled\"}\n disabled={applicable.length === 0}\n onClick={controller.applyReview}>\n {applicable.length === 1 ? \"Apply 1 field\" : `Apply ${applicable.length} fields`}\n </Button>\n </DialogActions>\n\n </Dialog>\n );\n}\n\nfunction ProposedFieldRow({ field, onToggle }: { field: ProposedField, onToggle: () => void }) {\n\n const replaces = hasValue(field.currentValue) && !isSameValue(field.currentValue, field.proposed);\n\n return (\n <label className={cls(\n \"flex items-start gap-3 py-3 cursor-pointer\",\n !field.selected && \"opacity-50\"\n )}>\n <div className={\"mt-0.5 shrink-0\"}>\n <Checkbox\n checked={field.selected}\n size={\"small\"}\n onCheckedChange={onToggle}\n />\n </div>\n\n <div className={\"flex flex-col gap-1 min-w-0 grow\"}>\n <div className={\"flex items-center gap-2\"}>\n {/* See the note above: never a bare `label` variant inside a <label>. */}\n <Typography variant={\"label\"} component={\"span\"}>{field.label}</Typography>\n {replaces && (\n <Typography variant={\"caption\"} color={\"secondary\"}>\n replaces the current value\n </Typography>\n )}\n {field.pending && <CircularProgress size={\"smallest\"}/>}\n </div>\n\n {replaces && (\n <Typography\n variant={\"body2\"}\n color={\"secondary\"}\n className={\"line-through whitespace-pre-wrap break-words\"}>\n {renderValue(field.currentValue)}\n </Typography>\n )}\n\n <Typography variant={\"body2\"} className={\"whitespace-pre-wrap break-words\"}>\n {renderValue(field.proposed)}\n </Typography>\n </div>\n </label>\n );\n}\n\nfunction hasValue(value: unknown): boolean {\n if (value === null || value === undefined) return false;\n if (typeof value === \"string\") return value.trim().length > 0;\n if (Array.isArray(value)) return value.length > 0;\n return true;\n}\n\nfunction isSameValue(a: unknown, b: unknown): boolean {\n if (a === b) return true;\n if (a instanceof Date && b instanceof Date) return a.getTime() === b.getTime();\n if (Array.isArray(a) && Array.isArray(b)) {\n return a.length === b.length && a.every((v, i) => isSameValue(v, b[i]));\n }\n return false;\n}\n\n/** Values are shown, never edited here — so a readable string is all that is needed. */\nfunction renderValue(value: unknown): string {\n if (value === null || value === undefined) return \"\";\n if (value instanceof Date) return value.toLocaleString();\n if (Array.isArray(value)) return value.map((v) => renderValue(v)).join(\", \");\n if (typeof value === \"boolean\") return value ? \"Yes\" : \"No\";\n if (typeof value === \"object\") return JSON.stringify(value);\n return String(value);\n}\n","import React, { useCallback, useEffect, useRef } from \"react\";\n\nimport {\n CircularProgress,\n cls,\n fieldBackgroundMixin,\n focusedDisabled,\n IconButton,\n iconSize,\n Menu,\n MenuItem,\n SendIcon,\n Separator,\n TextareaAutosize,\n XIcon\n} from \"@rebasepro/ui\";\nimport {\n AIIcon\n} from \"@rebasepro/app\";\nimport { EntityStatus, Properties, Property } from \"@rebasepro/types\";\nimport { PluginFormActionProps } from \"@rebasepro/cms-types\";\nimport { isPropertyBuilder, stripCollectionPath } from \"@rebasepro/common\";\nimport { useDataEnhancementController } from \"./DataEnhancementControllerProvider\";\nimport { AutofillReviewDialog } from \"./AutofillReviewDialog\";\nimport { SamplePrompt } from \"../types/data_enhancement_controller\";\n\nexport function FormEnhanceAction({\n path,\n status,\n collection,\n formContext\n}: PluginFormActionProps) {\n\n const storageKey = createLocalStorageKey(path, status);\n\n const dataEnhancementController = useDataEnhancementController();\n\n const [samplePrompts, setSamplePrompts] = React.useState<SamplePrompt[] | undefined>(undefined);\n const [instructions, setInstructions] = React.useState<string>(\"\");\n\n const getSamplePrompts = dataEnhancementController?.getSamplePrompts;\n\n /**\n * Driven by the controller rather than by local state.\n *\n * There is exactly one run at a time, and the review owns it — a second\n * `loading` flag here could disagree with the dialog about whether the\n * model is still writing.\n */\n const loading = dataEnhancementController?.review?.status === \"generating\";\n\n const loadingPrompts = useRef(false);\n const updateSuggestedPrompts = useCallback(async function updateSuggestedPrompts(instructions?: string) {\n if (!getSamplePrompts) return;\n if (loadingPrompts.current) return;\n loadingPrompts.current = true;\n const prompts = status === \"new\"\n ? (await getSamplePrompts(collection.singularName ?? collection.name, instructions)).prompts\n : getPromptsForExistingEntities(collection.properties);\n\n const recentPromptsFromStorage = getRecentPromptsFromStorage(storageKey);\n const recentPrompts = recentPromptsFromStorage.map(prompt => prompt.prompt);\n setSamplePrompts([...recentPromptsFromStorage, ...prompts.filter(p => !recentPrompts.includes(p.prompt))].slice(0, 5));\n loadingPrompts.current = false;\n },\n [collection.name, collection.singularName, getSamplePrompts, status]);\n\n useEffect(() => {\n if (!dataEnhancementController) return;\n if (!samplePrompts) {\n setSamplePrompts(getRecentPromptsFromStorage(storageKey));\n updateSuggestedPrompts().then();\n }\n }, [dataEnhancementController, samplePrompts, storageKey, updateSuggestedPrompts, instructions, status]);\n\n useEffect(() => {\n if (!dataEnhancementController) return;\n updateSuggestedPrompts().then();\n }, [dataEnhancementController, status]);\n\n /**\n * Starts a run and opens the review. Nothing is written to the form here —\n * see {@link AutofillReviewDialog}.\n */\n const generate = (prompt?: string) => {\n if (!dataEnhancementController || !formContext?.values) return;\n if (prompt) {\n addRecentPrompt(storageKey, prompt);\n setSamplePrompts([{\n prompt,\n type: \"recent\"\n }, ...(samplePrompts ?? []).slice(0, 5)]);\n }\n // The controller records a failure in the review itself, so there is\n // nothing to catch here — but the promise is still explicitly handled\n // so a rejection can never surface as an unhandled one.\n dataEnhancementController.generate({\n values: formContext.values,\n instructions: prompt\n }).catch(() => undefined);\n };\n\n if (!dataEnhancementController?.enabled)\n return null;\n\n function submit() {\n generate(instructions);\n }\n\n return (\n <>\n <Menu\n align={\"end\"}\n sideOffset={8}\n className={\"max-w-[100vw]\"}\n // Never full width: this used to stretch to fill the form's\n // `w-80 2xl:w-96` side rail in full screen. That rail is gone, and\n // in the footer a stretched button reads as the primary action.\n // Icon only. The label is carried by `aria-label`/`title` — a\n // `Tooltip` here would swallow the menu: both it and\n // `DropdownMenu.Trigger` render `asChild`, and `Tooltip` drops\n // the props Radix clones onto it, so the menu never opens.\n trigger={<IconButton variant={\"filled\"}\n size={\"small\"}\n aria-label={\"Autofill\"}\n title={\"Autofill\"}\n disabled={loading}>\n {!loading && <AIIcon size={\"small\"}/>}\n {loading && <CircularProgress size={\"small\"}/>}\n </IconButton>}>\n\n <MenuItem className={\"py-4\"}\n onClick={() => {\n generate();\n }}>\n <AIIcon size={\"small\"}/>\n Autofill based on the current content\n </MenuItem>\n\n <Separator orientation={\"horizontal\"} className={\"mt-2\"}/>\n\n {samplePrompts?.map((samplePrompt, index) => {\n return <MenuItem\n key={index + \"_\" + samplePrompt.prompt}\n onClick={() => {\n setInstructions(samplePrompt.prompt);\n generate(samplePrompt.prompt);\n }}\n >\n <div className={\"pl-9 grow text-text-secondary dark:text-text-secondary-dark\"}>\n {samplePrompt.prompt}\n </div>\n\n {samplePrompt.type === \"recent\" && <IconButton\n onClick={(e) => {\n e.preventDefault();\n e.stopPropagation();\n removeRecentPrompt(storageKey, samplePrompt.prompt);\n setSamplePrompts((samplePrompts ?? []).filter(p => p.prompt !== samplePrompt.prompt));\n }}\n size={\"smallest\"}\n >\n <XIcon size={iconSize.smallest}/>\n </IconButton>\n }\n </MenuItem>;\n })}\n\n <Separator orientation={\"horizontal\"}/>\n\n {/* `px-4` and `gap-4` are MenuItem's own paddings, so the input\n row lines up with the items above it instead of sitting 8px\n to their left — which is what `mx-2` on the textarea did. */}\n {/* `items-center` so the send button sits on the field's centre\n line rather than pinned to its top edge as the textarea grows. */}\n <div\n className={cls(\n \"my-2 px-4 py-2 gap-4 w-[500px] max-w-full flex items-center text-surface-700 dark:text-surface-200\"\n )}>\n\n <div className={\"relative w-full grow\"}>\n {/* `fieldBackgroundMixin`, the same surface every other input\n in the codebase uses. It was `dark:bg-surface-950`, which\n theme.css defines as literal `#000000` — a pure black\n rectangle inside an already-dark menu. */}\n <TextareaAutosize\n className={cls(\"p-3 pr-12 rounded-lg resize-none w-full outline-hidden max-h-[300px] overflow-auto\", fieldBackgroundMixin, focusedDisabled)}\n value={instructions}\n autoFocus={status === \"new\"}\n disabled={loading}\n onFocus={(event) => {\n event.stopPropagation();\n }}\n placeholder={\"...or provide instructions\"}\n onKeyDown={(e) => {\n e.stopPropagation();\n if (e.key === \"Enter\" && !e.shiftKey) {\n e.preventDefault();\n submit();\n }\n\n }}\n onChange={(e) => {\n setInstructions(e.target.value);\n }}\n />\n\n {/* Inside the field and only when there is something to\n clear — a permanently-visible X on an empty box is a\n control that does nothing. Positioned exactly as\n `TextFieldBinding` positions its own clearable X, so\n it stays centred as the textarea grows. */}\n {instructions.length > 0 && !loading && (\n <div\n className={\"flex flex-row justify-center items-center absolute h-full right-0 top-0 mr-2\"}>\n <IconButton\n size={\"small\"}\n onClick={() => {\n setInstructions(\"\");\n }}>\n <XIcon size={iconSize.small}/>\n </IconButton>\n </div>\n )}\n </div>\n\n <IconButton\n onClick={() => generate(instructions)}\n size={\"small\"}\n color={!instructions ? \"primary\" : undefined}\n disabled={loading || !instructions}>\n {loading &&\n <CircularProgress size={\"smallest\"}/>}\n {/* Sized, and no `color`. These icons are re-exported\n straight from lucide, so `color` lands on the SVG as\n a CSS colour — and `\"primary\"` is not one, which is\n why this button rendered empty. Every other icon in\n the codebase passes `size` alone and inherits\n `currentColor` from the button. */}\n {!loading &&\n <SendIcon size={iconSize.small}/>}\n </IconButton>\n\n </div>\n\n </Menu>\n\n <AutofillReviewDialog/>\n </>\n );\n}\n\nfunction getPromptsForExistingEntities(properties: Properties): SamplePrompt[] {\n\n const multilineProperties = Object.values(properties).filter((p: Property) => {\n if (isPropertyBuilder(p)) {\n return false;\n }\n return p.type === \"string\" && (p.admin?.markdown || p.admin?.multiline);\n });\n\n const multilinePrompt: Property | undefined = multilineProperties.length > 0\n ? multilineProperties[Math.floor(Math.random() * multilineProperties.length)] as Property\n : undefined;\n\n const prompts = [\n \"Fill the missing fields\",\n \"Translate the missing content\"\n ];\n if (multilinePrompt) {\n prompts.push(`Add 2 paragraphs to '${multilinePrompt.name}'`);\n }\n return prompts.map(p => ({\n prompt: p,\n type: \"sample\"\n }));\n}\n\nconst createLocalStorageKey = (path: string, status: EntityStatus) => {\n const statusString = status === \"new\" ? \"new\" : \"existing\";\n return `data_enhancement::${statusString}::${stripCollectionPath(path)}`;\n};\n\nconst getRecentPromptsFromStorage = (storageKey: string): SamplePrompt[] => {\n const item = localStorage.getItem(storageKey);\n return item ? JSON.parse(item).map((e: string) => ({\n prompt: e,\n type: \"recent\"\n })) : [];\n};\n\nconst addRecentPrompt = (storageKey: string, prompt: string) => {\n if (!prompt || prompt.trim().length === 0) {\n return;\n }\n const recentPrompts = getRecentPromptsFromStorage(storageKey);\n localStorage.setItem(storageKey, JSON.stringify([prompt, ...recentPrompts\n .map(e => e.prompt)\n .filter(e => e !== prompt)\n .slice(0, 5)]));\n};\n\nconst removeRecentPrompt = (storageKey: string, prompt: string) => {\n localStorage.setItem(storageKey, JSON.stringify(getRecentPromptsFromStorage(storageKey)\n .map(e => e.prompt)\n .filter(e => e !== prompt)));\n};\n","import React from \"react\";\n\nimport { CollectionConfig, User } from \"@rebasepro/types\";\nimport { RebasePlugin } from \"@rebasepro/cms-types\";\nimport { DataEnhancementControllerProvider } from \"./components/DataEnhancementControllerProvider\";\nimport { FormEnhanceAction } from \"./components/FormEnhanceAction\";\n\nexport interface DataEnhancementPluginProps {\n\n /**\n * Use this function to determine if the data enhancement plugin should be enabled for a given path.\n * If this function is not provided, the plugin will be enabled for all paths.\n * If the function returns false, the plugin will be disabled for the given path.\n *\n * @param path\n * @param collection\n */\n getConfigForPath?: (props: {\n path: string,\n collection: CollectionConfig,\n user: User | null\n }) => boolean;\n\n /**\n * Base URL of the AI service.\n *\n * Defaults to the one Rebase hosts, which is free to use and needs no\n * configuration. Point it at your own deployment to keep generation inside\n * your infrastructure — the wire format is documented in `src/api.ts`, and\n * the reference implementation is `saas/backend/functions/ai.ts`.\n *\n * Whatever it points at, the plugin renders nothing until that host's\n * `GET /status` reports itself available.\n */\n endpoint?: string;\n}\n\n/**\n * Use this hook to initialise the data enhancement plugin.\n * This is likely the only hook you will need to use.\n * @param props\n */\nexport function useDataEnhancementPlugin(props?: DataEnhancementPluginProps): RebasePlugin {\n\n const getConfigForPath = props?.getConfigForPath;\n const endpoint = props?.endpoint;\n\n return React.useMemo(() => ({\n key: \"data_enhancement\",\n slots: [\n {\n slot: \"form.actions\",\n Component: FormEnhanceAction,\n order: 40\n }\n ],\n providers: [\n {\n scope: \"form\" as const,\n Component: DataEnhancementControllerProvider as React.ComponentType<any>,\n props: {\n getConfigForPath,\n endpoint\n }\n }\n ]\n }), [getConfigForPath, endpoint]);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAwCA,SAAS,WAAW,UAA8B,MAAsB;CACpE,QAAQ,YAAA,0CAAA,CAAiC,QAAQ,QAAQ,EAAE,IAAI;AACnE;;AAMA,IAAM,gBAAgB;;;;;;;;;AAUtB,gBAAgB,qBAAqB,UAAqD;CACtF,MAAM,SAAS,SAAS,MAAM,UAAU;CACxC,IAAI,CAAC,QAAQ,MAAM,IAAI,MAAM,0CAA0C;CAEvE,MAAM,UAAU,IAAI,YAAY;CAChC,IAAI,SAAS;C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AM,MAAM,CAAC,CAAC;AACnC;;;;;;;;ACxQA,SAAgB,yBAAyB,OAAkD;CAEvF,MAAM,mBAAmB,OAAO;CAChC,MAAM,WAAW,OAAO;CAExB,OAAO,MAAM,eAAe;EACxB,KAAK;EACL,OAAO,CACH;GACI,MAAM;GACN,WAAW;GACX,OAAO;EACX,CACJ;EACA,WAAW,CACP;GACI,OAAO;GACP,WAAW;GACX,OAAO;IACH;IACA;GACJ;EACJ,CACJ;CACJ,IAAI,CAAC,kBAAkB,QAAQ,CAAC;AACpC"}
|
|
1
|
+
{"version":3,"file":"index.es.js","names":[],"sources":["../src/api.ts","../src/utils/properties.ts","../src/utils/values.ts","../src/editor/useEditorAIController.tsx","../src/components/DataEnhancementControllerProvider.tsx","../src/components/AutofillReviewDialog.tsx","../src/components/FormEnhanceAction.tsx","../src/useDataEnhancementPlugin.tsx"],"sourcesContent":["import {\n AutofillRequest,\n AutofillResult,\n AiStatus,\n SamplePromptsResult\n} from \"./types/data_enhancement_controller\";\n\n/**\n * The hosted service Rebase runs for this plugin.\n *\n * **This is where the entity's field values go.** Autofill posts them to\n * generate a suggestion, and unless the host sets `endpoint`, they go to this\n * address — off their machine, to a service Rebase operates. That is disclosed\n * on the plugins page rather than only here, because the person who needs to\n * know is the one deciding whether the data in those fields may leave.\n *\n * No credential travels with them; see the note below.\n *\n * The previous value here was `https://api.rebase.pro`, a FireCMS-era host that\n * resolves but serves nothing — every path 404s — so Autofill had never worked\n * in a Rebase install. This one is served by the control plane\n * (`saas/backend/functions/ai.ts`). Point `endpoint` somewhere else to run your\n * own; the wire format below is the whole contract.\n */\nexport const DEFAULT_AI_ENDPOINT = \"https://app.rebase.pro/api/functions/ai\";\n\n/**\n * ## No credentials cross this boundary\n *\n * The old client sent the tenant's Rebase JWT as `Authorization: Basic <jwt>`\n * plus a hardcoded `fcms-…` key compiled into the published package. Both were\n * wrong in the same way: a self-hosted backend signs its tokens with its own\n * secret, so no external service can verify one — sending it only handed a live\n * credential to a third party that had no use for it.\n *\n * These requests are anonymous. The service bounds cost by rate limit and daily\n * ceiling rather than by identity, and reports through {@link fetchAiStatus}\n * when it can no longer serve — which is what keeps the UI from offering an\n * action that is going to fail.\n */\nfunction endpointOf(endpoint: string | undefined, path: string): string {\n return (endpoint ?? DEFAULT_AI_ENDPOINT).replace(/\\/+$/, \"\") + path;\n}\n\n/** One `event:`/`data:` pair off the wire. */\ntype ServerSentEvent = { event: string; data: string };\n\n/** Not global: `exec` must not carry `lastIndex` between buffer reads. */\nconst SSE_SEPARATOR = /\\r?\\n\\r?\\n/;\n\n/**\n * Parse an SSE body incrementally.\n *\n * The framing this replaces split each chunk on the literal `\"&$# \"` and\n * `JSON.parse`d the pieces, which corrupted itself the moment a delimiter\n * straddled two reads — and network reads land wherever they land. Buffering\n * until a blank line is the fix, and it is also just what SSE specifies.\n */\nasync function* readServerSentEvents(response: Response): AsyncGenerator<ServerSentEvent> {\n const reader = response.body?.getReader();\n if (!reader) throw new Error(\"The AI service returned no response body\");\n\n const decoder = new TextDecoder();\n let buffer = \"\";\n\n for (;;) {\n const { done, value } = await reader.read();\n if (done) break;\n buffer += decoder.decode(value, { stream: true });\n\n // A record ends at a blank line. `\\r\\n` is tolerated because proxies\n // rewrite line endings. The separator is located with `exec` rather\n // than `search` so its actual length is known — a `\\r\\n\\r\\n` boundary\n // is four characters, not two, and slicing by the wrong count leaves a\n // stray newline that swallows the next record's `event:` field.\n let match = SSE_SEPARATOR.exec(buffer);\n while (match) {\n const raw = buffer.slice(0, match.index);\n buffer = buffer.slice(match.index + match[0].length);\n const parsed = parseEventBlock(raw);\n if (parsed) yield parsed;\n match = SSE_SEPARATOR.exec(buffer);\n }\n }\n}\n\nfunction parseEventBlock(block: string): ServerSentEvent | undefined {\n let event = \"message\";\n const dataLines: string[] = [];\n for (const line of block.split(/\\r?\\n/)) {\n if (line.startsWith(\":\")) continue; // comment / keep-alive\n const separator = line.indexOf(\":\");\n const field = separator === -1 ? line : line.slice(0, separator);\n const rawValue = separator === -1 ? \"\" : line.slice(separator + 1);\n const value = rawValue.startsWith(\" \") ? rawValue.slice(1) : rawValue;\n if (field === \"event\") event = value;\n else if (field === \"data\") dataLines.push(value);\n }\n if (dataLines.length === 0) return undefined;\n return { event,\ndata: dataLines.join(\"\\n\") };\n}\n\n/** Pull a message out of the control plane's `{ error: { message } }` envelope. */\nasync function errorFrom(response: Response, fallback: string): Promise<Error> {\n try {\n const body = await response.json();\n const message = body?.error?.message;\n if (typeof message === \"string\" && message) return new Error(message);\n } catch {\n /* not JSON — fall through */\n }\n return new Error(fallback);\n}\n\n/**\n * Ask the service whether it can serve a request at all.\n *\n * The plugin gates every affordance on this. A missing provider key, an\n * exhausted daily quota or an unreachable host all resolve to `available:\n * false`, and the Autofill button is simply not rendered — rather than\n * rendered, clicked, and failed.\n */\nexport async function fetchAiStatus(props: { endpoint?: string; signal?: AbortSignal }): Promise<AiStatus> {\n return (await probeAiStatus(props)).status;\n}\n\n/**\n * The status, and whether the service gave it. An error status (a 429 from the\n * host's per-IP limit, a 503 mid-deploy) says nothing about the service and\n * reads as `available: false` all the same; the cache below tells the two apart.\n */\nasync function probeAiStatus(props: { endpoint?: string; signal?: AbortSignal }): Promise<{ status: AiStatus; answered: boolean }> {\n const response = await fetch(endpointOf(props.endpoint, \"/status\"), {\n method: \"GET\",\n signal: props.signal\n });\n if (!response.ok) return { status: { available: false }, answered: false };\n const body = await response.json();\n return {\n status: {\n available: Boolean(body?.available),\n model: typeof body?.model === \"string\" ? body.model : undefined,\n features: Array.isArray(body?.features) ? body.features : undefined\n },\n answered: true\n };\n}\n\n/** How long a failed probe's `available: false` stands before the next caller asks again. */\nconst FAILED_PROBE_TTL_MS = 30_000;\n\ninterface StatusProbe {\n answer: Promise<AiStatus>;\n /** Set once the probe has failed: from then, the time after which it is asked again. */\n retryAfter?: number;\n}\n\n/**\n * One probe per endpoint. Key: the status URL. An answer from the service is\n * kept for the life of the page; a failed probe (unreachable host, an error\n * status) for {@link FAILED_PROBE_TTL_MS}. Cleared by {@link clearAiStatusCache}.\n */\nconst statusProbes = new Map<string, StatusProbe>();\n\n/**\n * {@link fetchAiStatus}, asked once per endpoint per session.\n *\n * The provider is form-scoped, so the uncached call meant one request to the\n * host every time any record was opened — a beacon on an install that may never\n * click Autofill, and enough traffic from one NAT'd office to spend the host's\n * per-IP rate limit on nothing, which reads back as `available: false` and makes\n * the button flicker in and out for everyone behind it.\n *\n * Availability changes on the order of a deploy or a daily quota reset, not of a\n * form open, so the service's answer is kept for the session. A failed probe is\n * not an answer: it resolves to `available: false` and is kept for 30 seconds,\n * so a burst of form opens still asks once, and the first form opened after\n * that asks again. Kept for the session, one dropped request hid Autofill until\n * the page was reloaded.\n */\nexport function fetchAiStatusCached(props: { endpoint?: string }): Promise<AiStatus> {\n const key = endpointOf(props.endpoint, \"/status\");\n const existing = statusProbes.get(key);\n if (existing && (existing.retryAfter === undefined || Date.now() < existing.retryAfter)) {\n return existing.answer;\n }\n const failed = (): AiStatus => {\n entry.retryAfter = Date.now() + FAILED_PROBE_TTL_MS;\n return { available: false };\n };\n const entry: StatusProbe = {\n answer: probeAiStatus({ endpoint: props.endpoint })\n .then(({ status, answered }) => answered ? status : failed(), failed)\n };\n statusProbes.set(key, entry);\n return entry.answer;\n}\n\n/** Forget every cached probe, so the next caller asks again. */\nexport function clearAiStatusCache(): void {\n statusProbes.clear();\n}\n\n/**\n * Fill a record, streaming each field as the service writes it.\n *\n * `onDelta` fires with more text for a field still being written; `onValue`\n * fires once a field is complete and carries its final, correctly typed value.\n * A caller that implements only `onValue` still ends up with the right record —\n * the deltas exist so a long text field fills in visibly instead of appearing\n * all at once.\n */\nexport async function autofillStream(props: {\n request: AutofillRequest;\n endpoint?: string;\n signal?: AbortSignal;\n onDelta: (key: string, text: string) => void;\n onValue: (key: string, value: unknown) => void;\n}): Promise<AutofillResult> {\n const response = await fetch(endpointOf(props.endpoint, \"/autofill\"), {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify(props.request),\n signal: props.signal\n });\n\n if (!response.ok) {\n throw await errorFrom(response, \"The AI service could not complete this request.\");\n }\n\n let result: AutofillResult = { suggestions: {} };\n let done = false;\n let delivered = 0;\n let discarded = 0;\n\n for await (const { event, data } of readServerSentEvents(response)) {\n let payload: any;\n try {\n payload = JSON.parse(data);\n } catch {\n // One malformed record must not abort a stream that is otherwise\n // delivering good fields — but it is counted, because a run that\n // delivered nothing *but* malformed records is a failure, not an\n // answer of \"there was nothing to fill in\".\n discarded++;\n continue;\n }\n\n if (event === \"suggestion_delta\") {\n delivered++;\n props.onDelta(payload.key, payload.text);\n } else if (event === \"suggestion\") {\n delivered++;\n props.onValue(payload.key, payload.value);\n } else if (event === \"done\") {\n done = true;\n result = {\n suggestions: payload.suggestions ?? {},\n usage: payload.usage\n };\n } else if (event === \"error\") {\n throw new Error(payload.message ?? \"The AI service reported an error.\");\n }\n }\n\n // The service closes every run it finished with a `done` record — including\n // the run that had nothing to fill, which is an empty `done` and not an\n // empty body. So a body that simply stops is a truncation: a rolled pod, a\n // proxy timeout, a dropped connection. Reported as one, because the caller's\n // only other reading of an empty result is \"nothing needed filling\", and\n // telling an operator that their empty fields are fields the model would not\n // improve on is a confident, wrong answer they have no way to question.\n if (!done) {\n throw new Error(\"The connection to the AI service ended before it finished.\");\n }\n if (discarded > 0 && delivered === 0) {\n throw new Error(\"The AI service's response could not be read.\");\n }\n\n return result;\n}\n\n/** Inline continuation for the rich-text editor. Streams plain text. */\n/**\n * How many characters of the document the slash autocomplete sends on each\n * side of the cursor. The hosted service keeps exactly this much and discards\n * the rest, so sending more costs upload time on every request and buys\n * nothing.\n */\nexport const MAX_AUTOCOMPLETE_CONTEXT = 8000;\n\nexport async function autocompleteStream(props: {\n textBefore?: string;\n textAfter?: string;\n endpoint?: string;\n signal?: AbortSignal;\n onDelta: (text: string) => void;\n}): Promise<string> {\n const response = await fetch(endpointOf(props.endpoint, \"/autocomplete\"), {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify({\n // The characters nearest the cursor: the end of what is before\n // it, the start of what is after it.\n textBefore: (props.textBefore ?? \"\").slice(-MAX_AUTOCOMPLETE_CONTEXT),\n textAfter: (props.textAfter ?? \"\").slice(0, MAX_AUTOCOMPLETE_CONTEXT)\n }),\n signal: props.signal\n });\n\n if (!response.ok) {\n throw await errorFrom(response, \"The AI service could not complete this request.\");\n }\n\n let text = \"\";\n for await (const { event, data } of readServerSentEvents(response)) {\n let payload: any;\n try {\n payload = JSON.parse(data);\n } catch {\n continue;\n }\n if (event === \"error\") {\n throw new Error(payload?.message ?? \"The AI service reported an error.\");\n }\n if (event === \"delta\" && typeof payload?.text === \"string\") {\n text += payload.text;\n props.onDelta(payload.text);\n }\n }\n return text;\n}\n\n/**\n * Sample prompts for the Autofill menu.\n *\n * Failure is deliberately not thrown: the menu has built-in prompts to fall\n * back on, and an empty suggestion list is a far better outcome than an error\n * toast for something nobody asked for.\n */\nexport async function fetchPromptSuggestions(props: {\n entityName: string;\n /** Ties suggestions to the domain — see the note on the service's side. */\n entityDescription?: string;\n input?: string;\n endpoint?: string;\n signal?: AbortSignal;\n}): Promise<SamplePromptsResult> {\n try {\n const response = await fetch(endpointOf(props.endpoint, \"/prompts\"), {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify({\n entityName: props.entityName,\n entityDescription: props.entityDescription,\n input: props.input\n }),\n signal: props.signal\n });\n if (!response.ok) return { prompts: [] };\n const body = await response.json();\n const prompts: string[] = Array.isArray(body?.prompts) ? body.prompts : [];\n return {\n prompts: prompts\n .filter((p): p is string => typeof p === \"string\")\n .map((prompt) => ({ prompt,\ntype: \"sample\" as const }))\n };\n } catch {\n return { prompts: [] };\n }\n}\n","import { getFieldId } from \"@rebasepro/cms\";\nimport { EnumValues, Properties, Property } from \"@rebasepro/types\";\nimport { isPropertyBuilder } from \"@rebasepro/common\";\nimport { InputProperty } from \"../types/data_enhancement_controller\";\nimport { getValueInPath } from \"@rebasepro/utils\";\nimport { isDisabled, isHidden, isReadOnly } from \"@rebasepro/app\";\n\n/**\n * Merge `parts` into one record, in order, into a single accumulator.\n *\n * `reduce((a, b) => ({ ...a, ...b }))` copied everything gathered so far once\n * per part: quadratic, and a page-builder record with 1,000 blocks took 371 ms.\n */\nfunction mergeAll<T>(parts: Record<string, T>[], into: Record<string, T> = {}): Record<string, T> {\n for (const part of parts) Object.assign(into, part);\n return into;\n}\n\nexport function getSimplifiedProperties<M extends Record<string, any>>(properties: Properties, values: M, path = \"\"): Record<string, InputProperty> {\n if (!properties) return {};\n return mergeAll(Object.entries(properties)\n .map(([key, property]) => {\n if (isPropertyBuilder(property)) return {};\n const fullKey = path ? `${path}.${key}` : key;\n const valueInPath = getValueInPath(values, fullKey);\n return getSimplifiedProperty(property, fullKey, valueInPath)\n }));\n}\n\n/**\n * Whether the form will not let anyone edit this field.\n *\n * The same three gates the form lays a field out with, so a literal\n * `conditions.readOnly` or a date the backend stamps is locked here too. A\n * locked container locks everything under it: the form disables a map's\n * children with the map, so they are not the model's to fill either.\n */\nfunction isLocked(property: Property, lockedByParent: boolean): boolean {\n return lockedByParent || isReadOnly(property) || isDisabled(property) || isHidden(property);\n}\n\nfunction getSimpleProperty(property: Property, lockedByParent = false): InputProperty {\n const fieldId = getFieldId(property);\n if (!fieldId) {\n console.error(\"No fieldId found for property\", property);\n throw new Error(\"Field id not found\");\n }\n return {\n name: property.name,\n description: property.description,\n type: property.type,\n fieldConfigId: fieldId,\n enum: \"enum\" in property && property.enum\n ? getSimpleEnumValues(property.enum)\n : undefined,\n disabled: isLocked(property, lockedByParent)\n };\n}\n\nfunction getSimplifiedProperty(property: Property, path: string, value?: unknown, lockedByParent = false): Record<string, InputProperty> {\n if (isPropertyBuilder(property)) return {};\n const locked = isLocked(property, lockedByParent);\n if (property.type === \"array\") {\n\n if (property.of && !Array.isArray(property.of) && !isPropertyBuilder(property.of)) {\n const arrayParentProperty: InputProperty = {\n name: property.name,\n description: property.description,\n type: property.type,\n fieldConfigId: \"repeat\",\n disabled: locked,\n of: getSimpleProperty(property.of as Property, locked)\n };\n\n const result = { [path]: arrayParentProperty };\n // if (Array.isArray(value)) {\n // result = {\n // ...result,\n // ...value\n // .map((v, i) => getSimplifiedProperty(property.of, `${path}.${i}`, v))\n // .reduce((a, b) => ({ ...a, ...b }), {})\n // };\n // }\n //\n // const existingValuesCount = Array.isArray(value) ? value.length : 0;\n //\n // const newValuesCount = property.of && !isPropertyBuilder<any, any>(property.of) && (property.of as Property).type === \"map\" ? 1 : 3;\n // result = {\n // ...result,\n // // ...Array.from(Array(newValuesCount))\n // // .map((v, i) => getSimplifiedProperty(property.of, `${path}.${i + existingValuesCount}`, v))\n // // .reduce((a, b) => ({ ...a, ...b }), {})\n // }\n\n return result;\n } else if (property.oneOf) {\n\n const arrayParentProperty: InputProperty = {\n name: property.name,\n description: property.description,\n type: property.type,\n fieldConfigId: \"block\",\n disabled: locked,\n oneOf: {\n typeField: property.oneOf.typeField,\n valueField: property.oneOf.valueField,\n properties: mergeAll(Object.entries(property.oneOf.properties)\n .map(([key, prop]) => ({ [key]: getSimpleProperty(prop, locked) })))\n }\n };\n\n if (!Array.isArray(value)) {\n return { [path]: arrayParentProperty };\n }\n\n return mergeAll(value.map((v, i) => {\n if (v == null) return {};\n const typeKey = property.oneOf!.typeField ?? \"type\";\n const oneOfType = v[typeKey];\n const valueKey = property.oneOf!.valueField ?? \"value\";\n const oneOfValue = v[valueKey];\n const childProperty = property.oneOf!.properties[oneOfType];\n if (childProperty === undefined) {\n console.error(`No property found for type ${oneOfType}`, property.oneOf!.properties);\n return {};\n }\n const simplifiedProperty = getSimplifiedProperty(childProperty, `${path}.${i}.${valueKey}`, oneOfValue, locked);\n return {\n [`${path}.${i}.${typeKey}`]: oneOfType,\n ...simplifiedProperty\n };\n }), { [path]: arrayParentProperty });\n }\n } else if (property.type === \"map\") {\n if (property.properties) {\n const mapProperties: Record<string, InputProperty> = mergeAll(Object.entries(property.properties)\n .map(([key, childProperty]) => {\n const childValue = value && typeof value === \"object\" ? (value as Record<string, unknown>)[key] : undefined;\n return getSimplifiedProperty(childProperty, key, childValue, locked);\n })\n .map(o => attachPathToKeys(o, path)));\n\n if (Object.keys(mapProperties).length === 0) return {};\n const mapParentProperty: InputProperty = {\n name: property.name,\n description: property.description,\n type: property.type,\n fieldConfigId: \"group\",\n disabled: locked\n };\n return {\n [path]: mapParentProperty,\n ...mapProperties\n } as Record<string, InputProperty>;\n }\n } else {\n const fieldId = getFieldId(property);\n if (!fieldId) {\n console.warn(`No fieldId found for property ${path} with type ${property.type}`);\n return {};\n }\n return {\n [path]: getSimpleProperty(property, lockedByParent)\n };\n }\n return {};\n}\n\n// attach a path to every key in an object\nfunction attachPathToKeys(obj: Record<string, InputProperty>, path = \"\"): Record<string, InputProperty> {\n const out: Record<string, InputProperty> = {};\n for (const [key, value] of Object.entries(obj)) {\n out[path ? `${path}.${key}` : key] = value;\n }\n return out;\n}\n\nfunction getSimpleEnumValues(enumValues: EnumValues): string[] {\n if (Array.isArray(enumValues))\n return enumValues.map(v => String(v.id));\n if (typeof enumValues === \"object\")\n return Object.keys(enumValues);\n throw Error(\"getSimpleEnumValues: Invalid enumValues\");\n}\n","import { InputProperty } from \"../types/data_enhancement_controller\";\n\n/**\n * Flatten a record onto the dotted paths the property map uses.\n *\n * The two halves of an autofill request have to be keyed the same way: the\n * service decides a field is empty by looking up `values[key]` for every `key`\n * in `properties`, so a value filed under a key the property map has never\n * heard of is a value the service cannot see.\n *\n * Only plain objects are containers. This used to recurse into anything\n * `typeof value === \"object\"`, which is both an array and a `Date` — so\n * `tags: [\"a\", \"b\"]` was sent as `tags.0`/`tags.1` while the property map still\n * called it `tags`, and a `Date` disappeared entirely (`Object.entries(date)` is\n * `[]`). Both then read as empty on the far side and came back in the review\n * pre-ticked to replace a value the record already had. `getSimplifiedProperties`\n * names an array by its own path and never descends into one, so neither does\n * this.\n */\nexport function flatMapEntityValues<M extends object>(values: M, path = \"\"): Record<string, unknown> {\n if (!values) return {};\n return Object.entries(values).flatMap(([key, value]) => {\n const currentPath = path ? `${path}.${key}` : key;\n if (isPlainObject(value)) {\n return flatMapEntityValues(value, currentPath);\n } else {\n return { [currentPath]: value };\n }\n }).reduce((acc, curr) => ({ ...acc,\n...curr }), {});\n}\n\n/**\n * A container, as opposed to a leaf value.\n *\n * Arrays, dates, files and every other class instance are values in their own\n * right — a map property is the only thing whose children are separate fields.\n */\nfunction isPlainObject(value: unknown): value is Record<string, unknown> {\n if (value === null || typeof value !== \"object\") return false;\n const proto = Object.getPrototypeOf(value);\n return proto === Object.prototype || proto === null;\n}\n\n/**\n * Drop the values of properties the panel will not let anyone edit.\n *\n * A `readOnly` or `disabled` property is already excluded from what the service\n * may fill, but the values map was built from the whole record, and the prompt\n * includes every value it is given as context. So a field marked read-only\n * because a backend hook owns it — an internal note, a customer id — was still\n * being transmitted and pasted into the prompt. The collection config lives\n * here, so this is the honest place to decide it: disabled means neither\n * fillable nor context.\n *\n * Prefixes match too: a disabled map takes its children with it.\n */\nexport function omitDisabledValues(\n values: Record<string, unknown>,\n properties: Record<string, InputProperty>\n): Record<string, unknown> {\n const disabled = Object.entries(properties ?? {})\n // A property map can carry a non-object at a path (see the `oneOf`\n // branch of `getSimplifiedProperty`), and `\"disabled\" in aString` throws.\n .filter(([, property]) => property && typeof property === \"object\" && property.disabled)\n .map(([key]) => key);\n if (disabled.length === 0) return values;\n return Object.fromEntries(\n Object.entries(values).filter(([key]) =>\n !disabled.some((prefix) => key === prefix || key.startsWith(`${prefix}.`)))\n );\n}\n\n/**\n * Whether a suggestion the service sent for `key` may reach the review: `key`\n * is a property the request described, and neither it nor a map above it is\n * disabled.\n *\n * The service answers with whatever keys it likes, steered by the record's\n * other values — which visitors may have written. A suggestion for a locked\n * field, or for a key that is no property at all, is one the request never\n * asked for, and applying it writes past the lock the request stated.\n */\nexport function isRequestedSuggestion(key: string, properties: Record<string, InputProperty>): boolean {\n const property = Object.hasOwn(properties ?? {}, key) ? properties[key] : undefined;\n if (!property || typeof property !== \"object\" || property.disabled) return false;\n return !Object.entries(properties).some(([prefix, other]) =>\n other && typeof other === \"object\" && other.disabled && key.startsWith(`${prefix}.`));\n}\n","import React from \"react\";\nimport { autocompleteStream } from \"../api\";\nimport { EditorAIController } from \"@rebasepro/cms\";\n\n/**\n * Inline continuation for the rich-text editor's slash command.\n *\n * No token is threaded through any more. The previous version demanded a\n * Firebase ID token and threw `\"Firebase token is required\"` when it could not\n * get one — in a Rebase app there is no such thing, and the token it actually\n * sent was a Rebase JWT the receiving service had no way to verify. The hosted\n * service authenticates nobody; see `src/api.ts`.\n */\nexport function useEditorAIController({ endpoint }: { endpoint?: string } = {}): EditorAIController {\n return React.useMemo(() => ({\n autocomplete: (textBefore: string, textAfter: string, onUpdate: (delta: string) => void) =>\n autocompleteStream({\n endpoint,\n textBefore,\n textAfter,\n onDelta: onUpdate\n })\n }), [endpoint]);\n}\n","import React, { PropsWithChildren, useCallback, useContext, useEffect, useMemo, useRef, useState } from \"react\";\n\nimport {\n AutofillReview,\n DataEnhancementController,\n GenerateParams,\n InputProperty,\n ProposedField\n} from \"../types/data_enhancement_controller\";\nimport { CollectionConfig, User } from \"@rebasepro/types\";\nimport { PluginFormActionProps } from \"@rebasepro/cms-types\";\nimport { EditorAIControllerProvider } from \"@rebasepro/cms\";\nimport { useAuthController } from \"@rebasepro/app\";\nimport { autofillStream, fetchAiStatusCached, fetchPromptSuggestions } from \"../api\";\nimport { getSimplifiedProperties } from \"../utils/properties\";\nimport { flatMapEntityValues, isRequestedSuggestion, omitDisabledValues } from \"../utils/values\";\nimport { useEditorAIController } from \"../editor/useEditorAIController\";\nimport { getValueInPath } from \"@rebasepro/utils\";\n\nconst DataEnhancementControllerContext = React.createContext<DataEnhancementController>(null! as DataEnhancementController);\n\ntype DataEnhancementControllerProviderProps = {\n\n /**\n * Kept in step with `DataEnhancementPluginProps.getConfigForPath`, which is\n * the signature the host app actually writes against: the plugin hands this\n * component through as `ComponentType<any>`, so nothing but agreement here\n * makes the two match.\n */\n getConfigForPath?: (props: {\n path: string,\n collection: CollectionConfig,\n user: User | null\n }) => boolean;\n\n endpoint?: string;\n}\n\nexport const useDataEnhancementController = (): DataEnhancementController => useContext(DataEnhancementControllerContext);\n\nfunction getPropertyFromKey(properties: Record<string, InputProperty>, propertyKey: string): InputProperty | undefined {\n if (propertyKey in properties) {\n return properties[propertyKey];\n }\n const split = propertyKey.split(\".\");\n if (split.length === 1) return undefined;\n return getPropertyFromKey(properties, split.slice(0, -1).join(\".\"));\n}\n\n/**\n * Convert a value off the wire into what the form field expects.\n *\n * Only dates need converting: the service answers ISO-8601 strings because JSON\n * has no date type, and handing a date field a string stores the wrong type\n * without complaining. Everything else — strings, numbers, booleans, arrays of\n * scalars — is already the shape the field wants, which is the point of having\n * the service constrain its answer to a schema derived from these properties.\n */\nfunction coerceToProperty(value: unknown, property: InputProperty | undefined): unknown {\n if (property?.type === \"date\" && typeof value === \"string\") {\n const date = new Date(value);\n return Number.isNaN(date.getTime()) ? undefined : date;\n }\n return value;\n}\n\nexport function DataEnhancementControllerProvider({\n getConfigForPath,\n children,\n endpoint,\n path,\n collection,\n formContext\n}: PropsWithChildren<DataEnhancementControllerProviderProps & PluginFormActionProps>) {\n\n const [allowedHere, setAllowedHere] = useState(false);\n const [serviceAvailable, setServiceAvailable] = useState(false);\n const [review, setReview] = useState<AutofillReview | null>(null);\n\n /**\n * The form's values as of the latest render, which the property map of a\n * run is built from (a block list contributes one entry per block).\n *\n * Built in `generate`, once per run, rather than memoised on the values:\n * that rebuilt it on every keystroke of every form, whether or not anybody\n * ever pressed Autofill. The run's callbacks keep the map they started\n * with — the operator is free to keep typing while the model works.\n */\n const formValuesRef = useRef(formContext?.values);\n formValuesRef.current = formContext?.values;\n\n /**\n * The host app's own opt-out.\n *\n * `user` is part of the documented signature and was never passed, so\n * `getConfigForPath: ({ user }) => user?.roles?.includes(\"editor\")` was\n * `Boolean(undefined)` for everyone — an access rule that silently decided\n * nothing, in whichever direction the host had written it.\n */\n const authController = useAuthController();\n const user: User | null = authController?.user ?? null;\n\n useEffect(() => {\n if (!getConfigForPath) {\n setAllowedHere(true);\n return;\n }\n setAllowedHere(Boolean(getConfigForPath({ path,\ncollection,\nuser })));\n }, [getConfigForPath, path, collection, user]);\n\n /**\n * The service's own availability.\n *\n * Nothing renders until this comes back true. An unreachable host, an\n * unconfigured provider key or an exhausted daily quota all land here, and\n * all of them mean the same thing to the operator: no Autofill button,\n * rather than a button that fails when clicked.\n *\n * Asked through the session cache: this provider is form-scoped, so an\n * uncached probe is one request to the host per record opened, by an install\n * that may never use the feature. The probe is shared rather than aborted on\n * unmount — cancelling it would cancel it for whatever else is waiting on the\n * same answer — so unmounting only stops this component from reading it.\n */\n useEffect(() => {\n if (!allowedHere) return;\n let cancelled = false;\n fetchAiStatusCached({ endpoint })\n .then((status) => {\n if (!cancelled) setServiceAvailable(status.available);\n });\n return () => {\n cancelled = true;\n };\n }, [allowedHere, endpoint]);\n\n const enabled = allowedHere && serviceAvailable;\n\n /**\n * The run whose review is on screen.\n *\n * A run outlives the review it was started for: the operator can discard\n * it, or start another, while its stream is still arriving. Every callback\n * checks it is still the current run before touching the review, and a run\n * that stops being current has its request cancelled. Without this, a\n * discarded run kept writing into the next run's review and, when it ended,\n * marked that review ready while the new run was still writing.\n */\n const currentRunRef = useRef<AbortController | null>(null);\n\n const cancelCurrentRun = useCallback(() => {\n currentRunRef.current?.abort();\n currentRunRef.current = null;\n }, []);\n\n // A form closed mid-run has nobody left to review what it produces.\n useEffect(() => cancelCurrentRun, [cancelCurrentRun]);\n\n /** Add or update one row in the review, preserving arrival order. */\n const upsertField = useCallback((key: string, update: (existing: ProposedField | undefined) => ProposedField) => {\n setReview((current) => {\n if (!current) return current;\n const index = current.fields.findIndex((f) => f.key === key);\n const next = update(index === -1 ? undefined : current.fields[index]);\n const fields = index === -1\n ? [...current.fields, next]\n : current.fields.map((f, i) => (i === index ? next : f));\n return { ...current,\nfields };\n });\n }, []);\n\n const generate = useCallback(async (params: GenerateParams<Record<string, unknown>>): Promise<void> => {\n\n const currentProperties = getSimplifiedProperties(collection.properties, formValuesRef.current ?? {});\n const flatValues = omitDisabledValues(\n flatMapEntityValues(params.values ?? {}),\n currentProperties\n );\n\n setReview({\n status: \"generating\",\n fields: [],\n instructions: params.instructions\n });\n\n const labelFor = (key: string) => currentProperties[key]?.name ?? key;\n\n cancelCurrentRun();\n const run = new AbortController();\n currentRunRef.current = run;\n const isCurrent = () => currentRunRef.current === run;\n\n try {\n await autofillStream({\n endpoint,\n signal: run.signal,\n request: {\n entityName: collection.singularName ?? collection.name,\n entityDescription: collection.description,\n // Flattened to dotted paths so the keys line up with the\n // property map: the service is told about `seo.title`, so it\n // has to be told the value of `seo.title` too, not of `seo`.\n // Exactly the same rule in both directions — an array or a\n // date is one value under one key here because it is one\n // property under one key there. Where they disagreed, the\n // service read a filled field as empty and offered to\n // rewrite it. Values of properties nobody may edit do not\n // travel at all.\n values: flatValues,\n properties: currentProperties,\n propertyKey: params.propertyKey,\n propertyInstructions: params.propertyInstructions,\n instructions: params.instructions\n },\n onDelta: (key, text) => {\n if (!isCurrent() || !isRequestedSuggestion(key, currentProperties)) return;\n upsertField(key, (existing) => existing\n ? { ...existing,\nproposed: String(existing.proposed ?? \"\") + text }\n : {\n key,\n label: labelFor(key),\n currentValue: getValueInPath(params.values, key),\n proposed: text,\n pending: true,\n selected: true\n });\n },\n onValue: (key, value) => {\n if (!isCurrent() || !isRequestedSuggestion(key, currentProperties)) return;\n const coerced = coerceToProperty(value, getPropertyFromKey(currentProperties, key));\n upsertField(key, (existing) => ({\n key,\n label: existing?.label ?? labelFor(key),\n currentValue: existing?.currentValue ?? getValueInPath(params.values, key),\n proposed: coerced,\n pending: false,\n // A row the operator already deselected mid-stream stays\n // deselected when its final value lands.\n selected: existing?.selected ?? true\n }));\n }\n });\n\n if (!isCurrent()) return;\n currentRunRef.current = null;\n setReview((current) => current && {\n ...current,\n status: \"ready\",\n // Fields still pending when the run ended never received a final\n // value — the model's JSON was cut off mid-string, so all we\n // hold is a half-written sentence. Marking them complete would\n // make that sentence applicable, which is the exact outcome the\n // review exists to prevent. They are dropped instead: the review\n // only ever offers what the service actually finished.\n fields: current.fields.filter((f) => !f.pending)\n });\n } catch (e: unknown) {\n // A run that was discarded or replaced fails with the abort, and\n // has nothing left to report to.\n if (!isCurrent()) return;\n currentRunRef.current = null;\n const message = e instanceof Error ? e.message : \"Autofill could not be completed\";\n // Kept in the review rather than fired into a snackbar: a run that\n // produced three good fields and then failed should still let the\n // operator apply the three.\n setReview((current) => current && {\n ...current,\n status: \"failed\",\n error: message,\n // Same rule as the success path: a field interrupted mid-write\n // is not something the operator can be offered.\n fields: current.fields.filter((f) => !f.pending)\n });\n }\n }, [collection, endpoint, upsertField, cancelCurrentRun]);\n\n const toggleField = useCallback((key: string) => {\n setReview((current) => current && {\n ...current,\n fields: current.fields.map((f) => (f.key === key ? { ...f,\nselected: !f.selected } : f))\n });\n }, []);\n\n const toggleAll = useCallback((selected: boolean) => {\n setReview((current) => current && {\n ...current,\n fields: current.fields.map((f) => ({ ...f,\nselected }))\n });\n }, []);\n\n const dismissReview = useCallback(() => {\n cancelCurrentRun();\n setReview(null);\n }, [cancelCurrentRun]);\n\n const applyReview = useCallback(() => {\n // Applied mid-stream, the rest of the run has no review to land in.\n cancelCurrentRun();\n setReview((current) => {\n if (!current) return null;\n for (const field of current.fields) {\n if (!field.selected || field.pending) continue;\n if (field.proposed === undefined || field.proposed === null) continue;\n formContext?.setFieldValue(field.key, field.proposed);\n }\n return null;\n });\n }, [formContext, cancelCurrentRun]);\n\n const editorAIController = useEditorAIController({ endpoint });\n\n const getSamplePrompts = useCallback(\n (entityName: string, input?: string) => fetchPromptSuggestions({\n endpoint,\n entityName,\n entityDescription: collection.description,\n input\n }),\n [endpoint, collection.description]\n );\n\n const dataEnhancementController: DataEnhancementController = useMemo(() => ({\n enabled,\n review,\n generate,\n toggleField,\n toggleAll,\n applyReview,\n dismissReview,\n getSamplePrompts,\n editorAIController\n }), [\n enabled,\n review,\n generate,\n toggleField,\n toggleAll,\n applyReview,\n dismissReview,\n getSamplePrompts,\n editorAIController\n ]);\n\n return (\n <DataEnhancementControllerContext.Provider\n value={dataEnhancementController}>\n {/* The form's markdown fields continue text through the same\n service, behind the same gate as Autofill: nothing until the\n service is available and the host allows this collection. */}\n <EditorAIControllerProvider controller={enabled ? editorAIController : undefined}>\n {children}\n </EditorAIControllerProvider>\n </DataEnhancementControllerContext.Provider>\n );\n}\n","import React from \"react\";\n\nimport {\n Button,\n Checkbox,\n CircularProgress,\n cls,\n Dialog,\n DialogActions,\n DialogContent,\n DialogTitle,\n Separator,\n Typography\n} from \"@rebasepro/ui\";\n\nimport { ProposedField } from \"../types/data_enhancement_controller\";\nimport { useDataEnhancementController } from \"./DataEnhancementControllerProvider\";\n\n/**\n * The review step.\n *\n * Autofill used to write generated text into the live form as it streamed —\n * fields mutating under the cursor, half-written sentences that looked like\n * bugs, and a pile of heuristics deciding whether each token should append to\n * or replace what the operator had already typed. Getting the old value back\n * meant retyping it.\n *\n * So the generated values land here instead. Streaming still happens, and is\n * still worth having — rows appear and fill in as the model works, so a long\n * run shows progress — but it happens in a surface that owns nothing. The\n * record changes on **Apply**, once, for the rows still ticked.\n */\nexport function AutofillReviewDialog() {\n\n const controller = useDataEnhancementController();\n const review = controller?.review;\n\n if (!review) return null;\n\n const generating = review.status === \"generating\";\n const applicable = review.fields.filter((f) => !f.pending && f.selected);\n const allSelected = review.fields.length > 0 && review.fields.every((f) => f.selected);\n\n return (\n <Dialog\n open={true}\n maxWidth={\"2xl\"}\n onOpenChange={(open) => {\n if (!open) controller.dismissReview();\n }}>\n\n <DialogTitle variant={\"subtitle1\"} gutterBottom={false}>\n Review autofill\n </DialogTitle>\n\n <DialogContent className={\"flex flex-col gap-2\"}>\n\n {review.instructions && (\n <Typography variant={\"body2\"} color={\"secondary\"} className={\"italic\"}>\n “{review.instructions}”\n </Typography>\n )}\n\n {review.fields.length > 1 && (\n <>\n <label className={\"flex items-center gap-3 py-1 cursor-pointer select-none\"}>\n <Checkbox\n checked={allSelected}\n size={\"small\"}\n onCheckedChange={() => controller.toggleAll(!allSelected)}\n />\n {/* `component=\"span\"`: the Typography `label`\n variant renders a <label> element, and this sits\n inside the row's own <label>. Nested labels are\n invalid HTML and stop the text toggling the\n checkbox — clicking \"Select all\" did nothing. */}\n <Typography variant={\"label\"} component={\"span\"} color={\"secondary\"}>\n {allSelected ? \"Deselect all\" : \"Select all\"}\n </Typography>\n </label>\n <Separator orientation={\"horizontal\"} className={\"my-0\"}/>\n </>\n )}\n\n <div className={\"flex flex-col divide-y divide-surface-accent-100 dark:divide-surface-accent-800\"}>\n {review.fields.map((field) => (\n <ProposedFieldRow\n key={field.key}\n field={field}\n onToggle={() => controller.toggleField(field.key)}\n />\n ))}\n </div>\n\n {generating && (\n <div className={\"flex items-center gap-3 py-4 text-text-secondary dark:text-text-secondary-dark\"}>\n <CircularProgress size={\"smallest\"}/>\n <Typography variant={\"body2\"} color={\"secondary\"}>\n {review.fields.length === 0 ? \"Thinking…\" : \"Writing the remaining fields…\"}\n </Typography>\n </div>\n )}\n\n {review.status === \"failed\" && (\n <Typography variant={\"body2\"} className={\"py-2 text-red-600 dark:text-red-400\"}>\n {review.error}\n {review.fields.length > 0 && \" You can still apply what was written before it stopped.\"}\n </Typography>\n )}\n\n {!generating && review.fields.length === 0 && review.status !== \"failed\" && (\n <Typography variant={\"body2\"} color={\"secondary\"} className={\"py-4\"}>\n Nothing to fill in — every field either already has a value the model would not\n improve on, or is not one it can write.\n </Typography>\n )}\n\n </DialogContent>\n\n <DialogActions>\n <Button variant={\"text\"}\n color={\"neutral\"}\n onClick={controller.dismissReview}>\n {/* Named for what it does to the record, not to the dialog:\n nothing has been written, so there is nothing to undo. */}\n Discard\n </Button>\n <Button variant={\"filled\"}\n disabled={applicable.length === 0}\n onClick={controller.applyReview}>\n {applicable.length === 1 ? \"Apply 1 field\" : `Apply ${applicable.length} fields`}\n </Button>\n </DialogActions>\n\n </Dialog>\n );\n}\n\nfunction ProposedFieldRow({ field, onToggle }: { field: ProposedField, onToggle: () => void }) {\n\n const replaces = hasValue(field.currentValue) && !isSameValue(field.currentValue, field.proposed);\n\n return (\n <label className={cls(\n \"flex items-start gap-3 py-3 cursor-pointer\",\n !field.selected && \"opacity-50\"\n )}>\n <div className={\"mt-0.5 shrink-0\"}>\n <Checkbox\n checked={field.selected}\n size={\"small\"}\n onCheckedChange={onToggle}\n />\n </div>\n\n <div className={\"flex flex-col gap-1 min-w-0 grow\"}>\n <div className={\"flex items-center gap-2\"}>\n {/* See the note above: never a bare `label` variant inside a <label>. */}\n <Typography variant={\"label\"} component={\"span\"}>{field.label}</Typography>\n {replaces && (\n <Typography variant={\"caption\"} color={\"secondary\"}>\n replaces the current value\n </Typography>\n )}\n {field.pending && <CircularProgress size={\"smallest\"}/>}\n </div>\n\n {replaces && (\n <Typography\n variant={\"body2\"}\n color={\"secondary\"}\n className={\"line-through whitespace-pre-wrap break-words\"}>\n {renderValue(field.currentValue)}\n </Typography>\n )}\n\n <Typography variant={\"body2\"} className={\"whitespace-pre-wrap break-words\"}>\n {renderValue(field.proposed)}\n </Typography>\n </div>\n </label>\n );\n}\n\nfunction hasValue(value: unknown): boolean {\n if (value === null || value === undefined) return false;\n if (typeof value === \"string\") return value.trim().length > 0;\n if (Array.isArray(value)) return value.length > 0;\n return true;\n}\n\nfunction isSameValue(a: unknown, b: unknown): boolean {\n if (a === b) return true;\n if (a instanceof Date && b instanceof Date) return a.getTime() === b.getTime();\n if (Array.isArray(a) && Array.isArray(b)) {\n return a.length === b.length && a.every((v, i) => isSameValue(v, b[i]));\n }\n return false;\n}\n\n/** Values are shown, never edited here — so a readable string is all that is needed. */\nfunction renderValue(value: unknown): string {\n if (value === null || value === undefined) return \"\";\n if (value instanceof Date) return value.toLocaleString();\n if (Array.isArray(value)) return value.map((v) => renderValue(v)).join(\", \");\n if (typeof value === \"boolean\") return value ? \"Yes\" : \"No\";\n if (typeof value === \"object\") return JSON.stringify(value);\n return String(value);\n}\n","import React, { useCallback, useEffect, useRef } from \"react\";\n\nimport {\n CircularProgress,\n cls,\n fieldBackgroundMixin,\n focusedDisabled,\n IconButton,\n iconSize,\n Menu,\n MenuItem,\n SendIcon,\n Separator,\n TextareaAutosize,\n XIcon\n} from \"@rebasepro/ui\";\nimport {\n AIIcon\n} from \"@rebasepro/app\";\nimport { EntityStatus, Properties, Property } from \"@rebasepro/types\";\nimport { PluginFormActionProps } from \"@rebasepro/cms-types\";\nimport { isPropertyBuilder, stripCollectionPath } from \"@rebasepro/common\";\nimport { useDataEnhancementController } from \"./DataEnhancementControllerProvider\";\nimport { AutofillReviewDialog } from \"./AutofillReviewDialog\";\nimport { SamplePrompt } from \"../types/data_enhancement_controller\";\n\nexport function FormEnhanceAction({\n path,\n status,\n collection,\n formContext\n}: PluginFormActionProps) {\n\n const storageKey = createLocalStorageKey(path, status);\n\n const dataEnhancementController = useDataEnhancementController();\n\n const [samplePrompts, setSamplePrompts] = React.useState<SamplePrompt[] | undefined>(undefined);\n const [instructions, setInstructions] = React.useState<string>(\"\");\n\n const getSamplePrompts = dataEnhancementController?.getSamplePrompts;\n\n /**\n * Driven by the controller rather than by local state.\n *\n * There is exactly one run at a time, and the review owns it — a second\n * `loading` flag here could disagree with the dialog about whether the\n * model is still writing.\n */\n const loading = dataEnhancementController?.review?.status === \"generating\";\n\n const loadingPrompts = useRef(false);\n const updateSuggestedPrompts = useCallback(async function updateSuggestedPrompts(instructions?: string) {\n if (!getSamplePrompts) return;\n if (loadingPrompts.current) return;\n loadingPrompts.current = true;\n const prompts = status === \"new\"\n ? (await getSamplePrompts(collection.singularName ?? collection.name, instructions)).prompts\n : getPromptsForExistingEntities(collection.properties);\n\n const recentPromptsFromStorage = getRecentPromptsFromStorage(storageKey);\n const recentPrompts = recentPromptsFromStorage.map(prompt => prompt.prompt);\n setSamplePrompts([...recentPromptsFromStorage, ...prompts.filter(p => !recentPrompts.includes(p.prompt))].slice(0, 5));\n loadingPrompts.current = false;\n },\n [collection.name, collection.singularName, getSamplePrompts, status]);\n\n useEffect(() => {\n if (!dataEnhancementController) return;\n if (!samplePrompts) {\n setSamplePrompts(getRecentPromptsFromStorage(storageKey));\n updateSuggestedPrompts().then();\n }\n }, [dataEnhancementController, samplePrompts, storageKey, updateSuggestedPrompts, instructions, status]);\n\n useEffect(() => {\n if (!dataEnhancementController) return;\n updateSuggestedPrompts().then();\n }, [dataEnhancementController, status]);\n\n /**\n * Starts a run and opens the review. Nothing is written to the form here —\n * see {@link AutofillReviewDialog}.\n */\n const generate = (prompt?: string) => {\n if (!dataEnhancementController || !formContext?.values) return;\n if (prompt) {\n addRecentPrompt(storageKey, prompt);\n setSamplePrompts([{\n prompt,\n type: \"recent\"\n }, ...(samplePrompts ?? []).slice(0, 5)]);\n }\n // The controller records a failure in the review itself, so there is\n // nothing to catch here — but the promise is still explicitly handled\n // so a rejection can never surface as an unhandled one.\n dataEnhancementController.generate({\n values: formContext.values,\n instructions: prompt\n }).catch(() => undefined);\n };\n\n if (!dataEnhancementController?.enabled)\n return null;\n\n function submit() {\n generate(instructions);\n }\n\n return (\n <>\n <Menu\n align={\"end\"}\n sideOffset={8}\n className={\"max-w-[100vw]\"}\n // Never full width: this used to stretch to fill the form's\n // `w-80 2xl:w-96` side rail in full screen. That rail is gone, and\n // in the footer a stretched button reads as the primary action.\n // Icon only. The label is carried by `aria-label`/`title` — a\n // `Tooltip` here would swallow the menu: both it and\n // `DropdownMenu.Trigger` render `asChild`, and `Tooltip` drops\n // the props Radix clones onto it, so the menu never opens.\n trigger={<IconButton variant={\"filled\"}\n size={\"small\"}\n aria-label={\"Autofill\"}\n title={\"Autofill\"}\n disabled={loading}>\n {!loading && <AIIcon size={\"small\"}/>}\n {loading && <CircularProgress size={\"small\"}/>}\n </IconButton>}>\n\n <MenuItem className={\"py-4\"}\n onClick={() => {\n generate();\n }}>\n <AIIcon size={\"small\"}/>\n Autofill based on the current content\n </MenuItem>\n\n <Separator orientation={\"horizontal\"} className={\"mt-2\"}/>\n\n {samplePrompts?.map((samplePrompt, index) => {\n return <MenuItem\n key={index + \"_\" + samplePrompt.prompt}\n onClick={() => {\n setInstructions(samplePrompt.prompt);\n generate(samplePrompt.prompt);\n }}\n >\n <div className={\"pl-9 grow text-text-secondary dark:text-text-secondary-dark\"}>\n {samplePrompt.prompt}\n </div>\n\n {samplePrompt.type === \"recent\" && <IconButton aria-label=\"Remove prompt\"\n onClick={(e) => {\n e.preventDefault();\n e.stopPropagation();\n removeRecentPrompt(storageKey, samplePrompt.prompt);\n setSamplePrompts((samplePrompts ?? []).filter(p => p.prompt !== samplePrompt.prompt));\n }}\n size={\"smallest\"}\n >\n <XIcon size={iconSize.smallest}/>\n </IconButton>\n }\n </MenuItem>;\n })}\n\n <Separator orientation={\"horizontal\"}/>\n\n {/* `px-4` and `gap-4` are MenuItem's own paddings, so the input\n row lines up with the items above it instead of sitting 8px\n to their left — which is what `mx-2` on the textarea did. */}\n {/* `items-center` so the send button sits on the field's centre\n line rather than pinned to its top edge as the textarea grows. */}\n <div\n className={cls(\n \"my-2 px-4 py-2 gap-4 w-[500px] max-w-full flex items-center text-surface-700 dark:text-surface-200\"\n )}>\n\n <div className={\"relative w-full grow\"}>\n {/* `fieldBackgroundMixin`, the same surface every other input\n in the codebase uses. It was `dark:bg-surface-950`, which\n theme.css defines as literal `#000000` — a pure black\n rectangle inside an already-dark menu. */}\n <TextareaAutosize\n className={cls(\"p-3 pr-12 rounded-lg resize-none w-full outline-hidden max-h-[300px] overflow-auto\", fieldBackgroundMixin, focusedDisabled)}\n value={instructions}\n autoFocus={status === \"new\"}\n disabled={loading}\n onFocus={(event) => {\n event.stopPropagation();\n }}\n placeholder={\"...or provide instructions\"}\n onKeyDown={(e) => {\n e.stopPropagation();\n if (e.key === \"Enter\" && !e.shiftKey) {\n e.preventDefault();\n submit();\n }\n\n }}\n onChange={(e) => {\n setInstructions(e.target.value);\n }}\n />\n\n {/* Inside the field and only when there is something to\n clear — a permanently-visible X on an empty box is a\n control that does nothing. Positioned exactly as\n `TextFieldBinding` positions its own clearable X, so\n it stays centred as the textarea grows. */}\n {instructions.length > 0 && !loading && (\n <div\n className={\"flex flex-row justify-center items-center absolute h-full right-0 top-0 mr-2\"}>\n <IconButton aria-label=\"Clear instructions\"\n size={\"small\"}\n onClick={() => {\n setInstructions(\"\");\n }}>\n <XIcon size={iconSize.small}/>\n </IconButton>\n </div>\n )}\n </div>\n\n <IconButton aria-label=\"Generate\"\n onClick={() => generate(instructions)}\n size={\"small\"}\n disabled={loading || !instructions}>\n {loading &&\n <CircularProgress size={\"smallest\"}/>}\n {/* Sized, and no `color`. These icons are re-exported\n straight from lucide, so `color` lands on the SVG as\n a CSS colour — and `\"primary\"` is not one, which is\n why this button rendered empty. Every other icon in\n the codebase passes `size` alone and inherits\n `currentColor` from the button. */}\n {!loading &&\n <SendIcon size={iconSize.small}/>}\n </IconButton>\n\n </div>\n\n </Menu>\n\n <AutofillReviewDialog/>\n </>\n );\n}\n\nfunction getPromptsForExistingEntities(properties: Properties): SamplePrompt[] {\n\n const multilineProperties = Object.values(properties).filter((p: Property) => {\n if (isPropertyBuilder(p)) {\n return false;\n }\n return p.type === \"string\" && (p.admin?.markdown || p.admin?.multiline);\n });\n\n const multilinePrompt: Property | undefined = multilineProperties.length > 0\n ? multilineProperties[Math.floor(Math.random() * multilineProperties.length)] as Property\n : undefined;\n\n const prompts = [\n \"Fill the missing fields\",\n \"Translate the missing content\"\n ];\n if (multilinePrompt) {\n prompts.push(`Add 2 paragraphs to '${multilinePrompt.name}'`);\n }\n return prompts.map(p => ({\n prompt: p,\n type: \"sample\"\n }));\n}\n\nconst createLocalStorageKey = (path: string, status: EntityStatus) => {\n const statusString = status === \"new\" ? \"new\" : \"existing\";\n return `data_enhancement::${statusString}::${stripCollectionPath(path)}`;\n};\n\nconst getRecentPromptsFromStorage = (storageKey: string): SamplePrompt[] => {\n const item = localStorage.getItem(storageKey);\n return item ? JSON.parse(item).map((e: string) => ({\n prompt: e,\n type: \"recent\"\n })) : [];\n};\n\nconst addRecentPrompt = (storageKey: string, prompt: string) => {\n if (!prompt || prompt.trim().length === 0) {\n return;\n }\n const recentPrompts = getRecentPromptsFromStorage(storageKey);\n localStorage.setItem(storageKey, JSON.stringify([prompt, ...recentPrompts\n .map(e => e.prompt)\n .filter(e => e !== prompt)\n .slice(0, 5)]));\n};\n\nconst removeRecentPrompt = (storageKey: string, prompt: string) => {\n localStorage.setItem(storageKey, JSON.stringify(getRecentPromptsFromStorage(storageKey)\n .map(e => e.prompt)\n .filter(e => e !== prompt)));\n};\n","import React from \"react\";\n\nimport { CollectionConfig, User } from \"@rebasepro/types\";\nimport { RebasePlugin } from \"@rebasepro/cms-types\";\nimport { DataEnhancementControllerProvider } from \"./components/DataEnhancementControllerProvider\";\nimport { FormEnhanceAction } from \"./components/FormEnhanceAction\";\n\nexport interface DataEnhancementPluginProps {\n\n /**\n * Use this function to determine if the data enhancement plugin should be enabled for a given path.\n * If this function is not provided, the plugin will be enabled for all paths.\n * If the function returns false, the plugin will be disabled for the given path.\n *\n * @param path\n * @param collection\n */\n getConfigForPath?: (props: {\n path: string,\n collection: CollectionConfig,\n user: User | null\n }) => boolean;\n\n /**\n * Base URL of the AI service.\n *\n * Defaults to the one Rebase hosts, which is free to use and needs no\n * configuration. Point it at your own deployment to keep generation inside\n * your infrastructure — the wire format is documented in `src/api.ts`, and\n * the reference implementation is `saas/backend/functions/ai.ts`.\n *\n * Whatever it points at, the plugin renders nothing until that host's\n * `GET /status` reports itself available.\n */\n endpoint?: string;\n}\n\n/**\n * Use this hook to initialise the data enhancement plugin.\n * This is likely the only hook you will need to use.\n * @param props\n */\nexport function useDataEnhancementPlugin(props?: DataEnhancementPluginProps): RebasePlugin {\n\n const getConfigForPath = props?.getConfigForPath;\n const endpoint = props?.endpoint;\n\n return React.useMemo(() => ({\n key: \"data_enhancement\",\n slots: [\n {\n slot: \"form.actions\",\n Component: FormEnhanceAction,\n order: 40\n }\n ],\n providers: [\n {\n scope: \"form\" as const,\n Component: DataEnhancementControllerProvider as React.ComponentType<any>,\n props: {\n getConfigForPath,\n endpoint\n }\n }\n ]\n }), [getConfigForPath, endpoint]);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAwCA,SAAS,WAAW,UAA8B,MAAsB;CACpE,QAAQ,YAAA,0CAAA,CAAiC,QAAQ,QAAQ,EAAE,IAAI;AACnE;;AAMA,IAAM,gBAAgB;;;;;;;;;AAUtB,gBAAgB,qBAAqB,UAAqD;CACtF,MAAM,SAAS,SAAS,MAAM,UAAU;CACxC,IAAI,CAAC,QAAQ,MAAM,IAAI,MAAM,0CAA0C;CAEvE,MAAM,UAAU,IAAI,YAAY;CAChC,IAAI,SAAS;CAEb,SAAS;EACL,MAAM,EAAE,MAAM,UAAU,MAAM,OAAO,KAAK;EAC1C,IAAI,MAAM;EACV,UAAU,QAAQ,OAAO,OAAO,EAAE,QAAQ,KAAK,CAAC;EAOhD,IAAI,QAAQ,cAAc,KAAK,MAAM;EACrC,OAAO,OAAO;GACV,MAAM,MAAM,OAAO,MAAM,GAAG,MAAM,KAAK;GACvC,SAAS,OAAO,MAAM,MAAM,QAAQ,MAAM,EAAE,CAAC,MAAM;GACnD,MAAM,SAAS,gBAAgB,GAAG;GAClC,IAAI,QAAQ,MAAM;GAClB,QAAQ,cAAc,KAAK,MAAM;EACrC;CACJ;AACJ;AAEA,SAAS,gBAAgB,OAA4C;CACjE,IAAI,QAAQ;CACZ,MAAM,YAAsB,CAAC;CAC7B,KAAK,MAAM,QAAQ,MAAM,MAAM,OAAO,GAAG;EACrC,IAAI,KAAK,WAAW,GAAG,GAAG;EAC1B,MAAM,YAAY,KAAK,QAAQ,GAAG;EAClC,MAAM,QAAQ,cAAc,KAAK,OAAO,KAAK,MAAM,GAAG,SAAS;EAC/D,MAAM,WAAW,cAAc,KAAK,KAAK,KAAK,MAAM,Y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;CAExB,OAAO,MAAM,eAAe;EACxB,KAAK;EACL,OAAO,CACH;GACI,MAAM;GACN,WAAW;GACX,OAAO;EACX,CACJ;EACA,WAAW,CACP;GACI,OAAO;GACP,WAAW;GACX,OAAO;IACH;IACA;GACJ;EACJ,CACJ;CACJ,IAAI,CAAC,kBAAkB,QAAQ,CAAC;AACpC"}
|
package/dist/utils/values.d.ts
CHANGED
|
@@ -31,3 +31,14 @@ export declare function flatMapEntityValues<M extends object>(values: M, path?:
|
|
|
31
31
|
* Prefixes match too: a disabled map takes its children with it.
|
|
32
32
|
*/
|
|
33
33
|
export declare function omitDisabledValues(values: Record<string, unknown>, properties: Record<string, InputProperty>): Record<string, unknown>;
|
|
34
|
+
/**
|
|
35
|
+
* Whether a suggestion the service sent for `key` may reach the review: `key`
|
|
36
|
+
* is a property the request described, and neither it nor a map above it is
|
|
37
|
+
* disabled.
|
|
38
|
+
*
|
|
39
|
+
* The service answers with whatever keys it likes, steered by the record's
|
|
40
|
+
* other values — which visitors may have written. A suggestion for a locked
|
|
41
|
+
* field, or for a key that is no property at all, is one the request never
|
|
42
|
+
* asked for, and applying it writes past the lock the request stated.
|
|
43
|
+
*/
|
|
44
|
+
export declare function isRequestedSuggestion(key: string, properties: Record<string, InputProperty>): boolean;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rebasepro/plugin-ai",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.24.1-canary.g56af4a4",
|
|
4
4
|
"description": "AI plugin for the Rebase admin panel: field generation and content assistance.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"rebase",
|
|
@@ -35,13 +35,13 @@
|
|
|
35
35
|
"./package.json": "./package.json"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@rebasepro/cms": "0.
|
|
39
|
-
"@rebasepro/cms-types": "0.
|
|
40
|
-
"@rebasepro/common": "0.
|
|
41
|
-
"@rebasepro/app": "0.
|
|
42
|
-
"@rebasepro/types": "0.
|
|
43
|
-
"@rebasepro/ui": "0.
|
|
44
|
-
"@rebasepro/utils": "0.
|
|
38
|
+
"@rebasepro/cms": "0.24.1-canary.g56af4a4",
|
|
39
|
+
"@rebasepro/cms-types": "0.24.1-canary.g56af4a4",
|
|
40
|
+
"@rebasepro/common": "0.24.1-canary.g56af4a4",
|
|
41
|
+
"@rebasepro/app": "0.24.1-canary.g56af4a4",
|
|
42
|
+
"@rebasepro/types": "0.24.1-canary.g56af4a4",
|
|
43
|
+
"@rebasepro/ui": "0.24.1-canary.g56af4a4",
|
|
44
|
+
"@rebasepro/utils": "0.24.1-canary.g56af4a4"
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
|
47
47
|
"react": "^19.2.7",
|