vanilla-agent 1.10.0 → 1.11.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 +57 -8
- package/dist/index.cjs +46 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +305 -1
- package/dist/index.d.ts +305 -1
- package/dist/index.global.js +69 -30
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +46 -7
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/components/composer-builder.ts +366 -0
- package/src/components/header-builder.ts +454 -0
- package/src/components/header-layouts.ts +303 -0
- package/src/components/message-bubble.ts +251 -34
- package/src/components/panel.ts +46 -684
- package/src/defaults.ts +49 -1
- package/src/index.ts +43 -1
- package/src/runtime/init.ts +26 -0
- package/src/types.ts +231 -0
- package/src/ui.ts +452 -34
package/README.md
CHANGED
|
@@ -26,7 +26,6 @@ import {
|
|
|
26
26
|
initAgentWidget,
|
|
27
27
|
createAgentExperience,
|
|
28
28
|
markdownPostprocessor,
|
|
29
|
-
directivePostprocessor,
|
|
30
29
|
DEFAULT_WIDGET_CONFIG
|
|
31
30
|
} from 'vanilla-agent';
|
|
32
31
|
|
|
@@ -61,13 +60,10 @@ const controller = initAgentWidget({
|
|
|
61
60
|
}
|
|
62
61
|
});
|
|
63
62
|
|
|
63
|
+
// Runtime theme update
|
|
64
64
|
document.querySelector('#dark-mode')?.addEventListener('click', () => {
|
|
65
65
|
controller.update({ theme: { surface: '#0f172a', primary: '#f8fafc' } });
|
|
66
66
|
});
|
|
67
|
-
controller.update({
|
|
68
|
-
postprocessMessage: ({ text, streaming }) =>
|
|
69
|
-
streaming ? markdownPostprocessor(text) : directivePostprocessor(text)
|
|
70
|
-
});
|
|
71
67
|
```
|
|
72
68
|
|
|
73
69
|
### Initialization options
|
|
@@ -238,10 +234,62 @@ The client simply sends messages to the proxy, which constructs the full Travrse
|
|
|
238
234
|
- Enforce security and cost controls centrally
|
|
239
235
|
- Support multiple flows for different use cases
|
|
240
236
|
|
|
241
|
-
###
|
|
237
|
+
### Dynamic Forms (Recommended)
|
|
238
|
+
|
|
239
|
+
For rendering AI-generated forms, use the **component middleware** approach with the `DynamicForm` component. This allows the AI to create contextually appropriate forms with any fields:
|
|
240
|
+
|
|
241
|
+
```typescript
|
|
242
|
+
import { componentRegistry, initAgentWidget } from "vanilla-agent";
|
|
243
|
+
import { DynamicForm } from "./components"; // Your DynamicForm component
|
|
244
|
+
|
|
245
|
+
// Register the component
|
|
246
|
+
componentRegistry.register("DynamicForm", DynamicForm);
|
|
247
|
+
|
|
248
|
+
initAgentWidget({
|
|
249
|
+
target: "#app",
|
|
250
|
+
config: {
|
|
251
|
+
apiUrl: "/api/chat/dispatch-directive",
|
|
252
|
+
parserType: "json",
|
|
253
|
+
enableComponentStreaming: true,
|
|
254
|
+
formEndpoint: "/form",
|
|
255
|
+
// Optional: customize form appearance
|
|
256
|
+
formStyles: {
|
|
257
|
+
borderRadius: "16px",
|
|
258
|
+
borderWidth: "1px",
|
|
259
|
+
borderColor: "#e5e7eb",
|
|
260
|
+
padding: "1.5rem",
|
|
261
|
+
titleFontSize: "1.25rem",
|
|
262
|
+
buttonBorderRadius: "9999px"
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
});
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
The AI responds with JSON like:
|
|
269
|
+
|
|
270
|
+
```json
|
|
271
|
+
{
|
|
272
|
+
"text": "Please fill out this form:",
|
|
273
|
+
"component": "DynamicForm",
|
|
274
|
+
"props": {
|
|
275
|
+
"title": "Contact Us",
|
|
276
|
+
"fields": [
|
|
277
|
+
{ "label": "Name", "type": "text", "required": true },
|
|
278
|
+
{ "label": "Email", "type": "email", "required": true }
|
|
279
|
+
],
|
|
280
|
+
"submit_text": "Submit"
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
See `examples/embedded-app/json.html` for a full working example.
|
|
286
|
+
|
|
287
|
+
### Directive postprocessor (Deprecated)
|
|
288
|
+
|
|
289
|
+
> **⚠️ Deprecated:** The `directivePostprocessor` approach is deprecated in favor of the component middleware with `DynamicForm`. The old approach only supports predefined form templates ("init" and "followup"), while the new approach allows AI-generated forms with any fields.
|
|
242
290
|
|
|
243
291
|
`directivePostprocessor` looks for either `<Form type="init" />` tokens or
|
|
244
|
-
`<Directive>{"component":"form","type":"init"}</Directive>` blocks and swaps them for placeholders that the widget upgrades into interactive UI
|
|
292
|
+
`<Directive>{"component":"form","type":"init"}</Directive>` blocks and swaps them for placeholders that the widget upgrades into interactive UI. This approach is limited to the predefined form templates in `formDefinitions`.
|
|
245
293
|
|
|
246
294
|
### Script tag installation
|
|
247
295
|
|
|
@@ -357,7 +405,8 @@ The script build exposes a `window.AgentWidget` global with `initAgentWidget()`
|
|
|
357
405
|
- `window.AgentWidget.createJsonStreamParser()` - JSON parser using schema-stream
|
|
358
406
|
- `window.AgentWidget.createXmlParser()` - XML parser
|
|
359
407
|
- `window.AgentWidget.markdownPostprocessor()` - Markdown postprocessor
|
|
360
|
-
- `window.AgentWidget.directivePostprocessor()` - Directive postprocessor
|
|
408
|
+
- `window.AgentWidget.directivePostprocessor()` - Directive postprocessor *(deprecated)*
|
|
409
|
+
- `window.AgentWidget.componentRegistry` - Component registry for custom components
|
|
361
410
|
|
|
362
411
|
### React Framework Integration
|
|
363
412
|
|