@runtypelabs/persona 3.19.0 → 3.21.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 +44 -1
- package/dist/animations/glyph-cycle.d.cts +1 -1
- package/dist/animations/glyph-cycle.d.ts +1 -1
- package/dist/animations/{types-cwY5HaFD.d.cts → types-CWPIj66R.d.cts} +19 -1
- package/dist/animations/{types-cwY5HaFD.d.ts → types-CWPIj66R.d.ts} +19 -1
- package/dist/animations/wipe.d.cts +1 -1
- package/dist/animations/wipe.d.ts +1 -1
- package/dist/index.cjs +46 -46
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +122 -4
- package/dist/index.d.ts +122 -4
- package/dist/index.global.js +79 -79
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +46 -46
- package/dist/index.js.map +1 -1
- package/dist/theme-editor.cjs +340 -11
- package/dist/theme-editor.d.cts +92 -1
- package/dist/theme-editor.d.ts +92 -1
- package/dist/theme-editor.js +340 -11
- package/package.json +1 -1
- package/src/client.test.ts +521 -0
- package/src/client.ts +150 -1
- package/src/components/message-bubble.test.ts +192 -0
- package/src/components/message-bubble.ts +200 -0
- package/src/index.ts +1 -0
- package/src/session.test.ts +123 -0
- package/src/session.ts +58 -4
- package/src/types.ts +102 -2
- package/src/ui.ts +18 -0
- package/src/utils/component-middleware.test.ts +134 -0
- package/src/utils/component-middleware.ts +44 -13
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/
|
|
1403
|
+
See `examples/embedded-app/dynamic-form.html` for a full working example.
|
|
1361
1404
|
|
|
1362
1405
|
### Directive postprocessor (Deprecated)
|
|
1363
1406
|
|
|
@@ -25,10 +25,28 @@ type FileContentPart = {
|
|
|
25
25
|
mimeType: string;
|
|
26
26
|
filename: string;
|
|
27
27
|
};
|
|
28
|
+
/**
|
|
29
|
+
* Audio content part for multi-modal messages
|
|
30
|
+
* Supports base64 data URIs or URLs
|
|
31
|
+
*/
|
|
32
|
+
type AudioContentPart = {
|
|
33
|
+
type: 'audio';
|
|
34
|
+
audio: string;
|
|
35
|
+
mimeType?: string;
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Video content part for multi-modal messages
|
|
39
|
+
* Supports base64 data URIs or URLs
|
|
40
|
+
*/
|
|
41
|
+
type VideoContentPart = {
|
|
42
|
+
type: 'video';
|
|
43
|
+
video: string;
|
|
44
|
+
mimeType?: string;
|
|
45
|
+
};
|
|
28
46
|
/**
|
|
29
47
|
* Union type for all content part types
|
|
30
48
|
*/
|
|
31
|
-
type ContentPart = TextContentPart | ImageContentPart | FileContentPart;
|
|
49
|
+
type ContentPart = TextContentPart | ImageContentPart | FileContentPart | AudioContentPart | VideoContentPart;
|
|
32
50
|
/**
|
|
33
51
|
* Metadata attached to messages created during agent execution.
|
|
34
52
|
*/
|
|
@@ -25,10 +25,28 @@ type FileContentPart = {
|
|
|
25
25
|
mimeType: string;
|
|
26
26
|
filename: string;
|
|
27
27
|
};
|
|
28
|
+
/**
|
|
29
|
+
* Audio content part for multi-modal messages
|
|
30
|
+
* Supports base64 data URIs or URLs
|
|
31
|
+
*/
|
|
32
|
+
type AudioContentPart = {
|
|
33
|
+
type: 'audio';
|
|
34
|
+
audio: string;
|
|
35
|
+
mimeType?: string;
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Video content part for multi-modal messages
|
|
39
|
+
* Supports base64 data URIs or URLs
|
|
40
|
+
*/
|
|
41
|
+
type VideoContentPart = {
|
|
42
|
+
type: 'video';
|
|
43
|
+
video: string;
|
|
44
|
+
mimeType?: string;
|
|
45
|
+
};
|
|
28
46
|
/**
|
|
29
47
|
* Union type for all content part types
|
|
30
48
|
*/
|
|
31
|
-
type ContentPart = TextContentPart | ImageContentPart | FileContentPart;
|
|
49
|
+
type ContentPart = TextContentPart | ImageContentPart | FileContentPart | AudioContentPart | VideoContentPart;
|
|
32
50
|
/**
|
|
33
51
|
* Metadata attached to messages created during agent execution.
|
|
34
52
|
*/
|