@formio/uag-js 2.0.0-rc.7 → 2.0.0-rc.8
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 +15 -11
- package/index.d.ts +5 -4
- package/index.js +1 -1
- package/package.json +1 -2
- package/uag.use.js +0 -25
package/README.md
CHANGED
|
@@ -13,23 +13,25 @@ Formio.use(UAG('https://uag.example.com'));
|
|
|
13
13
|
Formio.createForm(document.getElementById('claim'), 'https://forms.example.com/myproject/claim');
|
|
14
14
|
```
|
|
15
15
|
|
|
16
|
+
Without a bundler, load the UAG's own `https://uag.example.com/uag-js/uag.use.js` (and `uag-js.css`) after formio.js: it registers itself with that UAG and its modules' components. See [Or load it from the UAG](https://ai.form.io/developers/renderer#or-load-it-from-the-uag).
|
|
17
|
+
|
|
16
18
|
Requests to the UAG carry the user's Form.io token (`x-jwt-token`), as formio.js sends it to Form.io; no other token is needed. Routing in the browser is not a security boundary: protect the fields an agent owns on the server, with an agent role, form permissions and `uagAuthoritative`.
|
|
17
19
|
|
|
18
20
|
## AI Document
|
|
19
21
|
|
|
20
|
-
The **AI Document** component (`uagdocument`) is a UAG module
|
|
22
|
+
The **AI Document** component (`uagdocument`) is a UAG module from [`@formio/uag-extras`](https://github.com/formio/uag-extras) (`npm install @formio/uag-extras@^1`), not from this package. A UAG that uses the module adds the component to its `/uag-js/uag.use.js`; an application with a bundler registers it after this package:
|
|
21
23
|
|
|
22
|
-
|
|
24
|
+
```js
|
|
25
|
+
import aiDocument from '@formio/uag-extras/modules/ai-document/client';
|
|
26
|
+
Formio.use(UAG('https://uag.example.com'));
|
|
27
|
+
Formio.use(aiDocument);
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
See [AI Document](https://ai.form.io/developers/ai-document).
|
|
23
31
|
|
|
24
|
-
|
|
32
|
+
## For components: `client`
|
|
25
33
|
|
|
26
|
-
|
|
27
|
-
|---|---|
|
|
28
|
-
| `url()`, `token(form?)`, `headers(form?)` | The UAG's URL, the user's Form.io token, and the headers that identify the user to the UAG. |
|
|
29
|
-
| `formUrl(definition)` | A form's URL on the UAG, from its definition or a rendered form. |
|
|
30
|
-
| `ready`, `loaded`, `plugins(type?)`, `plugin(type, name)` | The installed plugins (`document`, `converter`, `module`), embedded by the UAG's scripts or fetched with the user's token. |
|
|
31
|
-
| `stream(url, body, { onEvent, signal, form })` | POST JSON, accepting server-sent events: every event goes to `onEvent`; it resolves with the `done` event's data (or the JSON answer), and rejects with the UAG's message, `status` and `code`. |
|
|
32
|
-
| `renderMarkdown(text)`, `escapeHtml(text)` | Markdown as the UAG sanitizes it, rendered with every text escaped. |
|
|
34
|
+
Once the UAG is registered, `client` (also `Formio.uagClient`, `FormioUAG.client` and `UAG.client`) is the browser API that components of UAG modules build on, stable within a major version: the UAG's URL, the user's token and headers, a form's URL on the UAG, the installed plugins, `stream()` for module routes, and Markdown rendering.
|
|
33
35
|
|
|
34
36
|
```js
|
|
35
37
|
import { client } from '@formio/uag-js';
|
|
@@ -37,6 +39,8 @@ await client.ready;
|
|
|
37
39
|
const done = await client.stream(client.formUrl(form) + '/document/process', { path, files }, { onEvent: (name, data) => {} });
|
|
38
40
|
```
|
|
39
41
|
|
|
42
|
+
Every member, and how `stream()` resolves and rejects: [For module components: `client`](https://ai.form.io/developers/renderer#for-module-components-client).
|
|
43
|
+
|
|
40
44
|
## Chat
|
|
41
45
|
|
|
42
46
|
Any form tagged `uag` can also be rendered as a chat, the way `Formio.createForm` renders it as a form. A person describes what they need; the chat asks for what is still missing and fills the form behind it, which validates and submits through the UAG once they confirm. Each turn is the form's `{form}/agent/chat` on the UAG, so there is no model code and no server of your own, and it needs no Agentic Formflow license (the UAG needs an agent engine).
|
|
@@ -44,7 +48,7 @@ Any form tagged `uag` can also be rendered as a chat, the way `Formio.createForm
|
|
|
44
48
|
```js
|
|
45
49
|
Formio.use(UAG('https://uag.example.com'));
|
|
46
50
|
|
|
47
|
-
const chat = await Formio.createChat(document.getElementById('help'), 'https://forms.example.com/myproject/
|
|
51
|
+
const chat = await Formio.createChat(document.getElementById('help'), 'https://forms.example.com/myproject/service-request', {
|
|
48
52
|
suggestions: ['My internet is down'],
|
|
49
53
|
markdown: (text) => marked.parse(text) // optional; the output is sanitized
|
|
50
54
|
});
|
package/index.d.ts
CHANGED
|
@@ -189,11 +189,10 @@ export interface ChatForm {
|
|
|
189
189
|
export interface UAGOptions extends Omit<AttachOptions, 'uagUrl' | 'formUrl'> {
|
|
190
190
|
/** `false` attaches no Agent Input anywhere; submissions of `uag` forms still go to the UAG. */
|
|
191
191
|
agentInput?: boolean;
|
|
192
|
-
/** AI Document options. `auto`: process files on upload unless a component turns it off (default true). */
|
|
193
|
-
documents?: { auto?: boolean };
|
|
194
192
|
/**
|
|
195
|
-
* Portal mode
|
|
196
|
-
*
|
|
193
|
+
* Portal mode, used by the UAG's portal script: registers only the client
|
|
194
|
+
* and the manifest, for the modules' components. Saves are not routed, and
|
|
195
|
+
* neither Agent Input nor the chat is registered.
|
|
197
196
|
*/
|
|
198
197
|
portal?: boolean;
|
|
199
198
|
/** The installed plugins, as `GET {project}/plugins` describes them. Fetched at registration when not given. */
|
|
@@ -328,5 +327,7 @@ declare const uag: {
|
|
|
328
327
|
SSEParser: typeof SSEParser;
|
|
329
328
|
isEmpty: typeof isEmpty;
|
|
330
329
|
CHAT_TEMPLATES: typeof CHAT_TEMPLATES;
|
|
330
|
+
renderMarkdown: typeof renderMarkdown;
|
|
331
|
+
client: typeof client;
|
|
331
332
|
};
|
|
332
333
|
export default uag;
|
package/index.js
CHANGED
|
@@ -734,7 +734,7 @@
|
|
|
734
734
|
* The chat: a formio.js display that renders a form as a conversation.
|
|
735
735
|
*
|
|
736
736
|
* Formio.use(UAG('https://uag.example.com'));
|
|
737
|
-
* Formio.createChat(element, 'https://forms.example.com/myproject/
|
|
737
|
+
* Formio.createChat(element, 'https://forms.example.com/myproject/service-request');
|
|
738
738
|
*
|
|
739
739
|
* Each message the person sends goes to the form's chat on the UAG
|
|
740
740
|
* (`{form}/agent/chat`) with the conversation and the form's data; the
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@formio/uag-js",
|
|
3
|
-
"version": "2.0.0-rc.
|
|
3
|
+
"version": "2.0.0-rc.8",
|
|
4
4
|
"description": "The Form.io UAG for formio.js applications: register it once, and forms tagged \"uag\" save through the UAG and get Agent Input, without overwriting what the user entered.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"formio",
|
|
@@ -30,7 +30,6 @@
|
|
|
30
30
|
"index.mjs",
|
|
31
31
|
"index.d.ts",
|
|
32
32
|
"uag-js.css",
|
|
33
|
-
"uag.use.js",
|
|
34
33
|
"README.md",
|
|
35
34
|
"LICENSE.txt"
|
|
36
35
|
],
|
package/uag.use.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @formio/uag-js for a page without a bundler. Load it after formio.js and
|
|
3
|
-
* this package's index.js, from the UAG it should talk to:
|
|
4
|
-
*
|
|
5
|
-
* <script src="https://cdn.form.io/js/formio.full.min.js"></script>
|
|
6
|
-
* <script src="https://uag.example.com/uag-js/uag.use.js"></script>
|
|
7
|
-
*
|
|
8
|
-
* The UAG serves this file at /uag-js/uag.use.js with the bundle and its
|
|
9
|
-
* manifest included. On its own, it registers FormioUAG (index.js) with the
|
|
10
|
-
* UAG it was loaded from, read from its own src, and fetches the manifest.
|
|
11
|
-
*/
|
|
12
|
-
(function () {
|
|
13
|
-
var script = document.currentScript;
|
|
14
|
-
var src = script && script.src ? new URL(script.src, location.href) : null;
|
|
15
|
-
var uagUrl = src && src.href.indexOf('/uag-js/') !== -1 ? src.href.slice(0, src.href.indexOf('/uag-js/')) : (src ? src.origin : location.origin);
|
|
16
|
-
function register() {
|
|
17
|
-
if (!window.Formio || !window.FormioUAG || typeof window.Formio.use !== 'function') return false;
|
|
18
|
-
window.Formio.use(window.FormioUAG.UAG(uagUrl));
|
|
19
|
-
return true;
|
|
20
|
-
}
|
|
21
|
-
if (!register()) {
|
|
22
|
-
var tries = 0;
|
|
23
|
-
var timer = setInterval(function () { if (register() || ++tries > 600) clearInterval(timer); }, 50);
|
|
24
|
-
}
|
|
25
|
-
})();
|