@runtypelabs/persona 3.1.0 → 3.2.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 +32 -3
- package/dist/index.cjs +38 -38
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +41 -2
- package/dist/index.d.ts +41 -2
- package/dist/index.global.js +51 -51
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +38 -38
- package/dist/index.js.map +1 -1
- package/dist/widget.css +12 -0
- package/package.json +1 -1
- package/src/components/launcher.test.ts +58 -0
- package/src/components/launcher.ts +10 -6
- package/src/styles/widget.css +12 -0
- package/src/types.ts +39 -2
- package/src/ui.ts +18 -2
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
|
|
@@ -1717,6 +1745,7 @@ Controls the floating launcher button and panel.
|
|
|
1717
1745
|
| `clearChat` | `AgentWidgetClearChatConfig?` | Clear chat button configuration (enabled, placement, icon, styling). |
|
|
1718
1746
|
| `border` | `string?` | Border style for the launcher button. Default: `'1px solid #e5e7eb'`. |
|
|
1719
1747
|
| `shadow` | `string?` | Box shadow for the launcher button. |
|
|
1748
|
+
| `collapsedMaxWidth` | `string?` | CSS `max-width` for the floating launcher pill when the panel is closed (title/subtitle truncate with ellipsis; full text in `title` tooltip). Does not affect the open panel (`width`). |
|
|
1720
1749
|
|
|
1721
1750
|
In docked mode, `position`, `fullHeight`, and `sidebarMode` are ignored because the widget fills the dock slot created around the target container.
|
|
1722
1751
|
|
|
@@ -2019,7 +2048,7 @@ config: {
|
|
|
2019
2048
|
| `initialMessages` | `AgentWidgetMessage[]` | Seed the conversation transcript with initial messages. |
|
|
2020
2049
|
| `persistState` | `boolean \| AgentWidgetPersistStateConfig` | Persist widget state across page navigations. `true` uses defaults (sessionStorage). |
|
|
2021
2050
|
| `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. |
|
|
2051
|
+
| `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
2052
|
| `clearChatHistoryStorageKey` | `string` | Additional localStorage key to clear on chat reset. The widget clears `"persona-chat-history"` by default. |
|
|
2024
2053
|
|
|
2025
2054
|
**`persistState`** — `AgentWidgetPersistStateConfig`
|