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 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
- ### Directive postprocessor
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 (forms, cards, etc.). See `examples/embedded-app/json.html` for a full working example that submits to the proxy’s `/form` endpoint and posts a follow-up message back into the chat.
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