react-formule 1.5.0 â 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +129 -5
- package/dist/admin/components/SchemaCodeEditor.d.ts +8 -0
- package/dist/admin/utils/fieldTypes.d.ts +1667 -549
- package/dist/admin/utils/index.d.ts +1 -1
- package/dist/ai/AiChatFooter.d.ts +9 -0
- package/dist/ai/AiDiff.d.ts +9 -0
- package/dist/ai/AiSettingsDialog.d.ts +7 -0
- package/dist/ai/defaults.d.ts +4 -0
- package/dist/ai/hooks.d.ts +4 -0
- package/dist/ai/utils.d.ts +5 -0
- package/dist/contexts/CustomizationContext.d.ts +3 -1
- package/dist/exposed.d.ts +1 -1
- package/dist/forms/Form.d.ts +2 -0
- package/dist/forms/fields/base/CodeEditorField.d.ts +1 -2
- package/dist/forms/templates/ArrayFieldTemplates/AccordionArrayFieldTemplate.d.ts +1 -1
- package/dist/forms/templates/ArrayFieldTemplates/LayerArrayFieldTemplate.d.ts +1 -1
- package/dist/forms/templates/utils/index.d.ts +1 -0
- package/dist/forms/widgets/base/MaskedInput/MaskedInput.d.ts +2 -1
- package/dist/forms/widgets/base/RichEditorWidget.d.ts +10 -1
- package/dist/forms/widgets/base/SliderWidget.d.ts +25 -0
- package/dist/forms/widgets/base/index.d.ts +3 -0
- package/dist/index.d.ts +8 -0
- package/dist/react-formule.js +87300 -81900
- package/dist/react-formule.umd.cjs +576 -457
- package/dist/store/schemaWizard.d.ts +1 -1
- package/dist/types/index.d.ts +74 -0
- package/dist/utils/CodeDiffViewer.d.ts +2 -1
- package/dist/utils/FieldMessageTag.d.ts +4 -0
- package/package.json +6 -3
- package/dist/admin/formComponents/widgets/SliderWidget.d.ts +0 -14
- package/dist/admin/formComponents/widgets/index.d.ts +0 -5
package/README.md
CHANGED
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
|
|
5
5
|
[](https://cern-sis.github.io/react-formule/)
|
|
6
6
|
|
|
7
|
+
</div>
|
|
8
|
+
|
|
7
9
|
[](https://opensource.org/licenses/MIT)
|
|
8
10
|
[](https://www.npmjs.com/package/react-formule?activeTab=readme)
|
|
9
11
|
[](https://github.com/cern-sis/react-formule/commits/master/)
|
|
@@ -13,8 +15,6 @@
|
|
|
13
15
|
[](https://github.com/cern-sis/react-formule/actions/workflows/cypress.yml)
|
|
14
16
|
[](https://github.com/cern-sis/react-formule/actions/workflows/commit-lint.yml)
|
|
15
17
|
|
|
16
|
-
</div>
|
|
17
|
-
|
|
18
18
|
## :horse: What is Formule?
|
|
19
19
|
|
|
20
20
|
Formule is a **powerful, user-friendly, extensible and mobile-friendly form building library** based on [JSON Schema](https://json-schema.org/) and [RJSF](https://github.com/rjsf-team/react-jsonschema-form), which aims to make form creation easier for both technical and non-technical people.
|
|
@@ -73,7 +73,7 @@ Formule includes a variety of predefined field types, grouped in three categorie
|
|
|
73
73
|
- `Accordion`: It works as a `List` with collapsible entries.
|
|
74
74
|
- `Layer`: It works as a `List` whose entries will open in a dialog window.
|
|
75
75
|
- `Tab`: It's commonly supposed to be used as a wrapper around the rest of the elements. You will normally want to add an `Object` inside and you can use it to separate the form in different pages or sections.
|
|
76
|
-
- **Advanced fields**: More complex or situational fields such as `URI`, `Rich/Latex editor`, `Tags`, `ID Fetcher`, `Code Editor` and `
|
|
76
|
+
- **Advanced fields**: More complex or situational fields such as `URI`, `Rich/Latex editor`, `Tags`, `ID Fetcher`, `Code Editor`, `Files` and `Slider`.
|
|
77
77
|
|
|
78
78
|
You can freely remove some of these predefined fields and add your own custom fields and widgets following the JSON Schema specifications. More details below.
|
|
79
79
|
|
|
@@ -276,9 +276,133 @@ const handleSubmit = () => {
|
|
|
276
276
|
|
|
277
277
|
</details>
|
|
278
278
|
|
|
279
|
-
|
|
280
|
-
|
|
279
|
+
## ⨠FormuleAI
|
|
280
|
+
|
|
281
|
+
FormuleAI brings Artificial Intelligence capabilities to Formule, allowing users to **generate and modify form schemas using natural language** prompts. This feature leverages Large Language Models to understand user requirements and automatically create or update form structures.
|
|
282
|
+
|
|
283
|
+
### How it works
|
|
284
|
+
|
|
285
|
+
FormuleAI integrates AI providers (like OpenAI or Gemini) to process natural language requests and generate corresponding JSON schemas. The AI understands the current form context and can add new fields, modify existing ones, or restructure entire sections based on your prompts.
|
|
286
|
+
|
|
287
|
+
By default FormuleAI includes providers for **OpenAI** and **Gemini**, and has been tested to work particularly with `GPT 4.1 Mini` and `Gemini 2.0 Flash`, although it allows you to choose any other model offered by these providers. You can also provide your own API key.
|
|
288
|
+
|
|
289
|
+
Once you send a request and receive a response back from the LLM, a popover will be displayed showing the diff between the current form and the suggestion, as well as between both JSON schemas, and you will be able to either reject or approve the changes. In the FormuleAI settings, you can also activate the "Vibe Mode", which will auto-apply any change without showing you a diff and asking for approval (use at your own risk).
|
|
290
|
+
|
|
291
|
+
**Note:** For the moment FormuleAI doesn't keep conversation history, so make sure to always be clear and provide all necessary details in each request.
|
|
292
|
+
|
|
293
|
+
### Basic usage
|
|
294
|
+
|
|
295
|
+
The main component you will need to use is **`AiChatFooter`**, a chat interface where users can input their prompts, toggle diffs, and accept or reject changes. It will also allow you to configure some settings and provide some usage instructions.
|
|
296
|
+
|
|
297
|
+
It can receive the following props: `onApply` and `onReject` callbacks, `hideHelp` and `hideSettings`, and `vibeMode` (false to disable, true to enable, unset to leave the decision up to users via settings).
|
|
298
|
+
|
|
299
|
+
A basic configuration would be simply:
|
|
300
|
+
|
|
301
|
+
```jsx
|
|
302
|
+
import { FormuleContext, AiChatFooter } from "react-formule";
|
|
303
|
+
|
|
304
|
+
<FormuleContext>
|
|
305
|
+
// your other main formule components
|
|
306
|
+
<AiChatFooter />
|
|
307
|
+
</FormuleContext>;
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
<details>
|
|
311
|
+
<summary>Adding <b>custom providers</b> and advanced configuration</summary>
|
|
312
|
+
|
|
313
|
+
### Customizing AI providers
|
|
314
|
+
|
|
315
|
+
You can add a new provider, whether commercial or self-hosted, in the following way:
|
|
316
|
+
|
|
317
|
+
```jsx
|
|
318
|
+
import { defaultProviders } from "react-formule";
|
|
319
|
+
|
|
320
|
+
const customProviders = {
|
|
321
|
+
"local-llama": {
|
|
322
|
+
label: <span>Local llama</span>,
|
|
323
|
+
// Optional, otherwise users can provide their own via settings
|
|
324
|
+
apiKey: "your-api-key",
|
|
325
|
+
// Optional, otherwise users can select one via settings (you need to define fetchModels for that)
|
|
326
|
+
model: "llama3.1",
|
|
327
|
+
// Optional (not needed when providing a model), it preselects that model in the model list
|
|
328
|
+
recommendedModel: { id: "llama3.1", name: "LLaMA 3.1" }
|
|
329
|
+
// Optional, needed only if you don't provide a model
|
|
330
|
+
fetchModels: async (apiKey) => {
|
|
331
|
+
const response = await fetch("https://your-ai-endpoint/models", {
|
|
332
|
+
headers: { Authorization: `Bearer ${apiKey}` },
|
|
333
|
+
});
|
|
334
|
+
const data = await response.json();
|
|
335
|
+
return data.models.map((model) => ({
|
|
336
|
+
id: model.id,
|
|
337
|
+
name: model.display_name,
|
|
338
|
+
}));
|
|
339
|
+
},
|
|
340
|
+
generateSchema: async (
|
|
341
|
+
prompt,
|
|
342
|
+
currentSchema,
|
|
343
|
+
fieldTypes,
|
|
344
|
+
apiKey,
|
|
345
|
+
model
|
|
346
|
+
) => {
|
|
347
|
+
const response = await fetch("https://your-ai-endpoint", {
|
|
348
|
+
method: "POST",
|
|
349
|
+
headers: { Authorization: `Bearer ${apiKey}` },
|
|
350
|
+
body: JSON.stringify({
|
|
351
|
+
model: model,
|
|
352
|
+
messages: [
|
|
353
|
+
{
|
|
354
|
+
role: "system",
|
|
355
|
+
content: "<your system prompt>",
|
|
356
|
+
},
|
|
357
|
+
{
|
|
358
|
+
role: "user",
|
|
359
|
+
content: "<your user prompt including fieldTpes and currentSchema>"
|
|
360
|
+
}
|
|
361
|
+
],
|
|
362
|
+
response_format: { type: "json_object" }
|
|
363
|
+
}),
|
|
364
|
+
});
|
|
365
|
+
return {
|
|
366
|
+
schema: content.schema,
|
|
367
|
+
uiSchema: content.uiSchema,
|
|
368
|
+
usage, // Optionally you can include token usage stats to be displayed to users
|
|
369
|
+
};
|
|
370
|
+
// If error, `return { error: "the error message" }` instead
|
|
371
|
+
},
|
|
372
|
+
},
|
|
373
|
+
};
|
|
374
|
+
|
|
375
|
+
<FormuleContext ai={{ providers: { ...defaultProviders, ...customProviders } }}>
|
|
376
|
+
// ...
|
|
377
|
+
</FormuleContext>;
|
|
378
|
+
```
|
|
379
|
+
|
|
380
|
+
If you want to keep the default providers along with your custom ones, you can import `defaultProviders` and include it in your providers object (as you can see in the previous example). Otherwise your new providers will override that configuration.
|
|
381
|
+
|
|
382
|
+
If an API key or a model is defined in a provider, users will not be able to modify them in the settings for that provider.
|
|
383
|
+
|
|
384
|
+
### Utility functions, hooks and components
|
|
385
|
+
|
|
386
|
+
FormuleAI exports several utilities for advanced use cases:
|
|
387
|
+
|
|
388
|
+
- **`useGenerateSchema`**: Hook for triggering schema generation programmatically
|
|
389
|
+
- **`useGetProvider`**: Hook to access configured AI providers. It will return the provider selected by the user (from localStorage) or otherwise a valid provider which is fully configured (with API key and model) in `ai.providers` if any.
|
|
390
|
+
- **`generatePatches`**: Utility to create JSON patches between schemas, used by FormuleAI for the form diff.
|
|
391
|
+
- **`defaultProviders`**: Configuration of the default providers, mentioned in the examples above.
|
|
392
|
+
- **`defaultGenerationPrompt`**: The default system prompt used by the current providers. It can help as a starting point to experiment with custom providers, but you will likely have to do some adjustments for each one.
|
|
393
|
+
|
|
394
|
+
There are also two more components that you would normally not need to use explicitly (they are already used by default from `AiChatFooter`) but which are still exposed to give you more flexiility in case you want further customization or to use them on your own custom chat interface implementation:
|
|
395
|
+
|
|
396
|
+
- **`AiDiff`**: Shows a visual diff of proposed changes before applying them
|
|
397
|
+
- **`AiSettingsDialog`**: Configuration panel for API keys and model selection
|
|
398
|
+
|
|
399
|
+
For implementation examples and advanced configurations, refer to the default provider implementations in the codebase.
|
|
400
|
+
|
|
401
|
+
</details>
|
|
281
402
|
|
|
282
403
|
## :space_invader: Local demo & how to contribute
|
|
283
404
|
|
|
284
405
|
Apart from trying the online [demo](https://cern-sis.github.io/react-formule/) you can clone the repo and run `formule-demo` to play around. Follow the instructions in its [README](./formule-demo/README.md): it will explain how to install `react-formule` as a local dependency so that you can modify Formule and test the changes live in your host app, which will be ideal if you want to troubleshoot or contribute to the project. Your contributions are welcome! :rocket:
|
|
406
|
+
|
|
407
|
+
> [!TIP]
|
|
408
|
+
> For more examples, feel free to browse around formule-demo and the [CERN Analysis Preservation](https://github.com/cernanalysispreservation/analysispreservation.cern.ch) repository, where we use most of the features mentioned above.
|