@runtypelabs/persona 3.0.0 → 3.1.1
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 +33 -5
- package/dist/index.cjs +39 -39
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +34 -2
- package/dist/index.d.ts +34 -2
- package/dist/index.global.js +76 -76
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +39 -39
- package/dist/index.js.map +1 -1
- package/dist/widget.css +90 -83
- package/package.json +1 -3
- package/src/components/artifact-pane.ts +3 -3
- package/src/components/header-builder.ts +1 -1
- package/src/runtime/host-layout.test.ts +137 -0
- package/src/runtime/host-layout.ts +81 -0
- package/src/runtime/init.test.ts +36 -1
- package/src/runtime/init.ts +1 -1
- package/src/styles/widget.css +90 -83
- package/src/types.ts +32 -2
- package/src/ui.ts +24 -6
- package/src/utils/artifact-gate.ts +1 -1
- package/src/styles/tailwind.css +0 -20
package/README.md
CHANGED
|
@@ -624,13 +624,15 @@ initAgentWidget({
|
|
|
624
624
|
|
|
625
625
|
The `onStateLoaded` hook is called after state is loaded from the storage adapter, but before the widget initializes. Use this to transform or inject messages based on external state (e.g., navigation flags, checkout returns).
|
|
626
626
|
|
|
627
|
+
Returning `{ state, open: true }` also tells the widget to open the panel after initialization — useful when injecting a post-navigation message that the user should immediately see.
|
|
628
|
+
|
|
627
629
|
```ts
|
|
630
|
+
// Plain state transform
|
|
628
631
|
initAgentWidget({
|
|
629
632
|
target: 'body',
|
|
630
633
|
config: {
|
|
631
634
|
storageAdapter: createLocalStorageAdapter('my-chat'),
|
|
632
635
|
onStateLoaded: (state) => {
|
|
633
|
-
// Check for pending navigation message
|
|
634
636
|
const navMessage = consumeNavigationFlag();
|
|
635
637
|
if (navMessage) {
|
|
636
638
|
return {
|
|
@@ -647,10 +649,36 @@ initAgentWidget({
|
|
|
647
649
|
}
|
|
648
650
|
}
|
|
649
651
|
});
|
|
652
|
+
|
|
653
|
+
// Return { state, open: true } to also open the panel
|
|
654
|
+
initAgentWidget({
|
|
655
|
+
target: 'body',
|
|
656
|
+
config: {
|
|
657
|
+
storageAdapter: createLocalStorageAdapter('my-chat'),
|
|
658
|
+
onStateLoaded: (state) => {
|
|
659
|
+
const navMessage = consumeNavigationFlag();
|
|
660
|
+
if (navMessage) {
|
|
661
|
+
return {
|
|
662
|
+
state: {
|
|
663
|
+
...state,
|
|
664
|
+
messages: [...(state.messages || []), {
|
|
665
|
+
id: `nav-${Date.now()}`,
|
|
666
|
+
role: 'assistant',
|
|
667
|
+
content: navMessage,
|
|
668
|
+
createdAt: new Date().toISOString()
|
|
669
|
+
}]
|
|
670
|
+
},
|
|
671
|
+
open: true
|
|
672
|
+
};
|
|
673
|
+
}
|
|
674
|
+
return state;
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
});
|
|
650
678
|
```
|
|
651
679
|
|
|
652
680
|
**Use cases:**
|
|
653
|
-
- Inject messages after page navigation (e.g., "Here are our products!")
|
|
681
|
+
- Inject messages after page navigation (e.g., "Here are our products!") and open the panel
|
|
654
682
|
- Add confirmation messages after checkout/payment returns
|
|
655
683
|
- Transform or filter loaded messages
|
|
656
684
|
- Inject system messages based on external state
|
|
@@ -935,7 +963,7 @@ const dropdown = createDropdownMenu({
|
|
|
935
963
|
onSelect: (id) => { /* handle */ },
|
|
936
964
|
anchor: myButton,
|
|
937
965
|
position: 'bottom-right',
|
|
938
|
-
portal: document.querySelector('
|
|
966
|
+
portal: document.querySelector('[data-persona-root]')!,
|
|
939
967
|
});
|
|
940
968
|
// No need to append — portal mode appends automatically
|
|
941
969
|
```
|
|
@@ -2019,7 +2047,7 @@ config: {
|
|
|
2019
2047
|
| `initialMessages` | `AgentWidgetMessage[]` | Seed the conversation transcript with initial messages. |
|
|
2020
2048
|
| `persistState` | `boolean \| AgentWidgetPersistStateConfig` | Persist widget state across page navigations. `true` uses defaults (sessionStorage). |
|
|
2021
2049
|
| `storageAdapter` | `AgentWidgetStorageAdapter` | Custom storage adapter with `load()`, `save(state)`, and `clear()` methods. |
|
|
2022
|
-
| `onStateLoaded` | `(state: AgentWidgetStoredState) => AgentWidgetStoredState` | Transform state after loading from storage but before widget initialization. |
|
|
2050
|
+
| `onStateLoaded` | `(state: AgentWidgetStoredState) => AgentWidgetStoredState \| { state: AgentWidgetStoredState; open?: boolean }` | Transform state after loading from storage but before widget initialization. Return `{ state, open: true }` to also open the panel. |
|
|
2023
2051
|
| `clearChatHistoryStorageKey` | `string` | Additional localStorage key to clear on chat reset. The widget clears `"persona-chat-history"` by default. |
|
|
2024
2052
|
|
|
2025
2053
|
**`persistState`** — `AgentWidgetPersistStateConfig`
|
|
@@ -2322,6 +2350,6 @@ Add `RUNTYPE_API_KEY` to your environment. The proxy constructs the Runtype payl
|
|
|
2322
2350
|
### Development notes
|
|
2323
2351
|
|
|
2324
2352
|
- The widget streams results using SSE and mirrors the backend `flow_complete`/`step_chunk` events.
|
|
2325
|
-
- Tailwind-esc classes are prefixed with `tvw-` and scoped to
|
|
2353
|
+
- Tailwind-esc classes are prefixed with `tvw-` and scoped to `[data-persona-root]`, so they won't collide with the host page.
|
|
2326
2354
|
- Run `pnpm dev` from the repository root to boot the example proxy (`examples/proxy`) and the vanilla demo (`examples/embedded-app`).
|
|
2327
2355
|
- The proxy prefers port `43111` but automatically selects the next free port if needed.
|