@runtypelabs/persona 3.1.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 +31 -3
- package/dist/index.cjs +35 -35
- 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 +49 -49
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +35 -35
- package/dist/index.js.map +1 -1
- package/dist/widget.css +7 -0
- package/package.json +1 -1
- package/src/styles/widget.css +7 -0
- package/src/types.ts +32 -2
- package/src/ui.ts +18 -2
package/dist/widget.css
CHANGED
|
@@ -1299,6 +1299,7 @@
|
|
|
1299
1299
|
/* Ensure user message paragraphs and lists have proper styling too */
|
|
1300
1300
|
.vanilla-message-user-bubble p {
|
|
1301
1301
|
margin: 0;
|
|
1302
|
+
color: inherit;
|
|
1302
1303
|
}
|
|
1303
1304
|
|
|
1304
1305
|
.vanilla-message-user-bubble p + p {
|
|
@@ -1322,6 +1323,12 @@
|
|
|
1322
1323
|
.vanilla-message-user-bubble li {
|
|
1323
1324
|
margin: 0.25rem 0;
|
|
1324
1325
|
padding-left: 0.25rem;
|
|
1326
|
+
color: inherit;
|
|
1327
|
+
}
|
|
1328
|
+
|
|
1329
|
+
.vanilla-message-assistant-bubble p,
|
|
1330
|
+
.vanilla-message-assistant-bubble li {
|
|
1331
|
+
color: inherit;
|
|
1325
1332
|
}
|
|
1326
1333
|
|
|
1327
1334
|
/* ============================================
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@runtypelabs/persona",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.1",
|
|
4
4
|
"description": "Themeable, pluggable streaming agent widget for websites, in plain JS with support for voice input and reasoning / tool output.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.cjs",
|
package/src/styles/widget.css
CHANGED
|
@@ -1299,6 +1299,7 @@
|
|
|
1299
1299
|
/* Ensure user message paragraphs and lists have proper styling too */
|
|
1300
1300
|
.vanilla-message-user-bubble p {
|
|
1301
1301
|
margin: 0;
|
|
1302
|
+
color: inherit;
|
|
1302
1303
|
}
|
|
1303
1304
|
|
|
1304
1305
|
.vanilla-message-user-bubble p + p {
|
|
@@ -1322,6 +1323,12 @@
|
|
|
1322
1323
|
.vanilla-message-user-bubble li {
|
|
1323
1324
|
margin: 0.25rem 0;
|
|
1324
1325
|
padding-left: 0.25rem;
|
|
1326
|
+
color: inherit;
|
|
1327
|
+
}
|
|
1328
|
+
|
|
1329
|
+
.vanilla-message-assistant-bubble p,
|
|
1330
|
+
.vanilla-message-assistant-bubble li {
|
|
1331
|
+
color: inherit;
|
|
1325
1332
|
}
|
|
1326
1333
|
|
|
1327
1334
|
/* ============================================
|
package/src/types.ts
CHANGED
|
@@ -2346,11 +2346,15 @@ export type AgentWidgetConfig = {
|
|
|
2346
2346
|
*
|
|
2347
2347
|
* This hook runs synchronously and must return the (potentially modified) state.
|
|
2348
2348
|
*
|
|
2349
|
+
* Returning `{ state, open: true }` also signals that the widget panel should
|
|
2350
|
+
* open after initialization — useful when injecting a post-navigation message
|
|
2351
|
+
* that the user should immediately see.
|
|
2352
|
+
*
|
|
2349
2353
|
* @example
|
|
2350
2354
|
* ```typescript
|
|
2355
|
+
* // Plain state transform (existing form, still supported)
|
|
2351
2356
|
* config: {
|
|
2352
2357
|
* onStateLoaded: (state) => {
|
|
2353
|
-
* // Check for pending navigation message
|
|
2354
2358
|
* const navMessage = consumeNavigationFlag();
|
|
2355
2359
|
* if (navMessage) {
|
|
2356
2360
|
* return {
|
|
@@ -2367,8 +2371,34 @@ export type AgentWidgetConfig = {
|
|
|
2367
2371
|
* }
|
|
2368
2372
|
* }
|
|
2369
2373
|
* ```
|
|
2374
|
+
*
|
|
2375
|
+
* @example
|
|
2376
|
+
* ```typescript
|
|
2377
|
+
* // Return { state, open: true } to also open the panel
|
|
2378
|
+
* config: {
|
|
2379
|
+
* onStateLoaded: (state) => {
|
|
2380
|
+
* const navMessage = consumeNavigationFlag();
|
|
2381
|
+
* if (navMessage) {
|
|
2382
|
+
* return {
|
|
2383
|
+
* state: {
|
|
2384
|
+
* ...state,
|
|
2385
|
+
* messages: [...(state.messages || []), {
|
|
2386
|
+
* id: `nav-${Date.now()}`,
|
|
2387
|
+
* role: 'assistant',
|
|
2388
|
+
* content: navMessage,
|
|
2389
|
+
* createdAt: new Date().toISOString()
|
|
2390
|
+
* }]
|
|
2391
|
+
* },
|
|
2392
|
+
* open: true
|
|
2393
|
+
* };
|
|
2394
|
+
* }
|
|
2395
|
+
* return state;
|
|
2396
|
+
* }
|
|
2397
|
+
* }
|
|
2398
|
+
* ```
|
|
2370
2399
|
*/
|
|
2371
|
-
onStateLoaded?: (state: AgentWidgetStoredState) =>
|
|
2400
|
+
onStateLoaded?: (state: AgentWidgetStoredState) =>
|
|
2401
|
+
AgentWidgetStoredState | { state: AgentWidgetStoredState; open?: boolean };
|
|
2372
2402
|
/**
|
|
2373
2403
|
* Registry of custom components that can be rendered from JSON directives.
|
|
2374
2404
|
* Components are registered by name and can be invoked via JSON responses
|
package/src/ui.ts
CHANGED
|
@@ -412,11 +412,20 @@ export const createAgentExperience = (
|
|
|
412
412
|
let persistentMetadata: Record<string, unknown> = {};
|
|
413
413
|
let pendingStoredState: Promise<AgentWidgetStoredState | null> | null = null;
|
|
414
414
|
|
|
415
|
-
|
|
415
|
+
let shouldOpenAfterStateLoaded = false;
|
|
416
|
+
|
|
417
|
+
// Helper to apply onStateLoaded hook and extract state.
|
|
418
|
+
// Supports both the legacy plain-state return and the new { state, open? } return.
|
|
416
419
|
const applyStateLoadedHook = (state: AgentWidgetStoredState): AgentWidgetStoredState => {
|
|
417
420
|
if (config.onStateLoaded) {
|
|
418
421
|
try {
|
|
419
|
-
|
|
422
|
+
const result = config.onStateLoaded(state);
|
|
423
|
+
if (result && typeof result === 'object' && 'state' in result) {
|
|
424
|
+
const { state: processedState, open } = result as { state: AgentWidgetStoredState; open?: boolean };
|
|
425
|
+
if (open) shouldOpenAfterStateLoaded = true;
|
|
426
|
+
return processedState;
|
|
427
|
+
}
|
|
428
|
+
return result as AgentWidgetStoredState;
|
|
420
429
|
} catch (error) {
|
|
421
430
|
if (typeof console !== "undefined") {
|
|
422
431
|
// eslint-disable-next-line no-console
|
|
@@ -5379,6 +5388,13 @@ export const createAgentExperience = (
|
|
|
5379
5388
|
}
|
|
5380
5389
|
}
|
|
5381
5390
|
|
|
5391
|
+
// If onStateLoaded signalled open: true, open the panel after init.
|
|
5392
|
+
// Mirrors the same setTimeout(0) pattern used by persistState restore so both
|
|
5393
|
+
// can fire independently without interfering with each other.
|
|
5394
|
+
if (shouldOpenAfterStateLoaded && launcherEnabled) {
|
|
5395
|
+
setTimeout(() => { controller.open(); }, 0);
|
|
5396
|
+
}
|
|
5397
|
+
|
|
5382
5398
|
return controller;
|
|
5383
5399
|
};
|
|
5384
5400
|
|