@runtypelabs/persona 3.18.0 → 3.20.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.
Files changed (42) hide show
  1. package/README.md +45 -2
  2. package/dist/index.cjs +47 -47
  3. package/dist/index.cjs.map +1 -1
  4. package/dist/index.d.cts +383 -6
  5. package/dist/index.d.ts +383 -6
  6. package/dist/index.global.js +102 -1636
  7. package/dist/index.global.js.map +1 -1
  8. package/dist/index.js +47 -47
  9. package/dist/index.js.map +1 -1
  10. package/dist/theme-editor.cjs +1514 -626
  11. package/dist/theme-editor.d.cts +192 -1
  12. package/dist/theme-editor.d.ts +192 -1
  13. package/dist/theme-editor.js +1628 -626
  14. package/dist/widget.css +348 -0
  15. package/package.json +1 -1
  16. package/src/components/composer-builder.test.ts +52 -0
  17. package/src/components/composer-builder.ts +67 -490
  18. package/src/components/composer-parts.test.ts +152 -0
  19. package/src/components/composer-parts.ts +452 -0
  20. package/src/components/header-builder.ts +22 -299
  21. package/src/components/header-parts.ts +360 -0
  22. package/src/components/panel.test.ts +61 -0
  23. package/src/components/panel.ts +262 -5
  24. package/src/components/pill-composer-builder.test.ts +85 -0
  25. package/src/components/pill-composer-builder.ts +183 -0
  26. package/src/index.ts +5 -0
  27. package/src/runtime/init.ts +4 -2
  28. package/src/runtime/persist-state.test.ts +152 -0
  29. package/src/session.test.ts +123 -0
  30. package/src/session.ts +58 -4
  31. package/src/styles/widget.css +348 -0
  32. package/src/types.ts +196 -1
  33. package/src/ui.component-directive.test.ts +183 -0
  34. package/src/ui.composer-bar.test.ts +1009 -0
  35. package/src/ui.ts +827 -72
  36. package/src/utils/attachment-manager.ts +1 -1
  37. package/src/utils/component-middleware.test.ts +134 -0
  38. package/src/utils/component-middleware.ts +44 -13
  39. package/src/utils/dock.test.ts +45 -0
  40. package/src/utils/dock.ts +3 -0
  41. package/src/utils/icons.ts +314 -58
  42. package/src/utils/stream-animation.ts +7 -2
package/README.md CHANGED
@@ -253,6 +253,49 @@ chat.injectAssistantMessage({
253
253
  });
254
254
  ```
255
255
 
256
+ **Component Directives (`injectComponentDirective`)**
257
+
258
+ When you've registered a custom component via `componentRegistry.register(...)`, inject an assistant message that renders that component using the same path Persona uses for streamed JSON directives:
259
+
260
+ ```ts
261
+ import { componentRegistry } from '@runtypelabs/persona';
262
+ import { DynamicForm } from './components';
263
+
264
+ componentRegistry.register('DynamicForm', DynamicForm);
265
+
266
+ chat.injectComponentDirective({
267
+ component: 'DynamicForm',
268
+ props: {
269
+ title: 'Book a demo',
270
+ fields: [
271
+ { label: 'Name', type: 'text', required: true },
272
+ { label: 'Email', type: 'email', required: true }
273
+ ],
274
+ submit_text: 'Request meeting'
275
+ },
276
+ text: 'Share your details to book a demo.',
277
+ llmContent: '[Showed booking form]' // optional, redacted version for the LLM
278
+ });
279
+ ```
280
+
281
+ The helper sets `content` to `text`, `rawContent` to the canonical directive JSON, and forwards `llmContent`. Useful for previews, replays, debug buttons, and local tools that should render a component instead of plain text.
282
+
283
+ If you already have a serialized directive, you can pass it through `rawContent` directly on any inject method:
284
+
285
+ ```ts
286
+ chat.injectAssistantMessage({
287
+ content: 'Booking form',
288
+ rawContent: JSON.stringify({
289
+ text: 'Booking form',
290
+ component: 'DynamicForm',
291
+ props: { /* ... */ }
292
+ }),
293
+ llmContent: '[Showed booking form]'
294
+ });
295
+ ```
296
+
297
+ See [docs/MESSAGE-INJECTION.md](./docs/MESSAGE-INJECTION.md#component-directive-injection) for the full reference.
298
+
256
299
  #### Event Stream Control
257
300
 
258
301
  When the `showEventStreamToggle` feature flag is enabled, you can programmatically control the event stream inspector panel:
@@ -1357,7 +1400,7 @@ The AI responds with JSON like:
1357
1400
  }
1358
1401
  ```
1359
1402
 
1360
- See `examples/embedded-app/json.html` for a full working example.
1403
+ See `examples/embedded-app/dynamic-form.html` for a full working example.
1361
1404
 
1362
1405
  ### Directive postprocessor (Deprecated)
1363
1406
 
@@ -2062,7 +2105,7 @@ In docked mode, `position`, `fullHeight`, and `sidebarMode` are ignored because
2062
2105
 
2063
2106
  | Option | Type | Description |
2064
2107
  | --- | --- | --- |
2065
- | `components` | `Record<string, AgentWidgetComponentRenderer>` | Registry of custom components rendered from JSON directives (`{"component": "Name", "props": {...}}`). Each renderer receives `(props, context)` and returns an `HTMLElement`. |
2108
+ | `components` | `Record<string, AgentWidgetComponentRenderer>` | Registry of custom components rendered from JSON directives (`{"component": "Name", "props": {...}}`). Each renderer receives `(props, context)` and returns an `HTMLElement`. Event listeners attached via `addEventListener` (and any other imperative state on the returned element) are preserved across transcript updates — the widget injects the live element directly into the morphed wrapper so listeners survive subsequent re-renders. The renderer is re-invoked when the directive's props change; for state you want to persist across prop changes, hold it in a closure outside the render. |
2066
2109
 
2067
2110
  ```typescript
2068
2111
  config: {