@runtypelabs/persona 3.25.0 → 3.27.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 CHANGED
@@ -92,7 +92,8 @@ const docked = initAgentWidget({
92
92
  | `target` | `string \| HTMLElement` | CSS selector or element where widget mounts. |
93
93
  | `config` | `AgentWidgetConfig` | Widget configuration object (see [Configuration reference](#configuration-reference) below). |
94
94
  | `useShadowDom` | `boolean` | Use Shadow DOM for style isolation (default: `true`). |
95
- | `onReady` | `() => void` | Callback fired when widget is initialized. |
95
+ | `onChatReady` | `() => void` | Callback fired when the widget is initialized and its API is callable. |
96
+ | `onReady` | `() => void` | **Deprecated** alias of `onChatReady`; still works, removed in the next major. |
96
97
  | `windowKey` | `string` | If provided, stores the controller on `window[windowKey]` for global access. Automatically cleaned up on `destroy()`. |
97
98
 
98
99
  When `config.launcher.mountMode` is `'docked'`, `target` is treated as the page container that Persona should wrap. Use a concrete element such as `#workspace-main`; `body` and `html` are rejected.
@@ -354,7 +355,7 @@ window.chatController.submitMessage("Test message")
354
355
  window.chatController.startVoiceRecognition()
355
356
  ```
356
357
 
357
- When using the automatic installer script (`install.global.js`), see [Programmatic access with the installer](#programmatic-access-with-the-installer) for additional approaches including the `onReady` callback and `persona:ready` event.
358
+ When using the automatic installer script (`install.global.js`), see [Programmatic access with the installer](#programmatic-access-with-the-installer) for additional approaches including the `onChatReady` callback and `persona:chat-ready` event.
358
359
 
359
360
  #### Message Types
360
361
 
@@ -525,6 +526,31 @@ inside the subtree is still pierced.
525
526
  > provenance and update steps. Once upstream republishes correctly this can revert to a
526
527
  > normal optional peer dependency.
527
528
 
529
+ ### WebMCP page tools
530
+
531
+ When `webmcp: { enabled: true }` is set, the widget consumes tools the page
532
+ registers on `document.modelContext` (the [WebMCP](https://github.com/webmachinelearning/webmcp)
533
+ producer surface), snapshots them into each request as `clientTools[]`, runs the
534
+ agent's calls on the page, and gates each behind a confirm bubble (override with
535
+ `autoApprove` / `onConfirm`).
536
+
537
+ ```ts
538
+ initAgentWidget({
539
+ // ...config
540
+ webmcp: {
541
+ enabled: true,
542
+ autoApprove: (info) => READ_ONLY_TOOLS.has(info.toolName),
543
+ },
544
+ });
545
+ ```
546
+
547
+ **Using WebMCP against a non-Runtype backend (e.g. the Vercel AI SDK)?** The
548
+ widget's WebMCP loop expects Runtype's proxy wire protocol (a `step_await` pause
549
+ → `/resume` round-trip). See
550
+ [`docs/webmcp-without-runtype.md`](../../docs/webmcp-without-runtype.md) for the
551
+ exact contract and two integration paths, with a runnable Next.js example at
552
+ [`examples/ai-sdk-webmcp/`](../../examples/ai-sdk-webmcp/).
553
+
528
554
  ### DOM Events
529
555
 
530
556
  The widget dispatches custom DOM events that you can listen to for integration with your application:
@@ -594,19 +620,30 @@ window.dispatchEvent(new CustomEvent('persona:focusInput', {
594
620
 
595
621
  **Instance scoping:** Same as `persona:showEventStream` — use `detail.instanceId` to target a specific widget. Without `instanceId`, all instances receive the event.
596
622
 
597
- #### `persona:ready`
623
+ #### `persona:chat-ready`
598
624
 
599
- Dispatched on `window` by the automatic installer script (`install.global.js`) after the widget is initialized. The `event.detail` contains the `AgentWidgetInitHandle` (the same object returned by `initAgentWidget()`).
625
+ Dispatched on `window` by the automatic installer script (`install.global.js`) when the widget is initialized and its controller API is callable. The `event.detail` contains the `AgentWidgetInitHandle` (the same object returned by `initAgentWidget()`). In a deferred install (the default floating-launcher case) this fires after the user first opens the panel; in an eager install it fires on page load.
600
626
 
601
627
  ```ts
602
- window.addEventListener('persona:ready', (e) => {
628
+ window.addEventListener('persona:chat-ready', (e) => {
603
629
  const handle = e.detail;
604
630
  handle.on('message:sent', (msg) => console.log(msg));
605
631
  handle.open();
606
632
  });
607
633
  ```
608
634
 
609
- > **Note:** This event is only dispatched by the automatic installer script. Direct calls to `initAgentWidget()` return the handle synchronously and do not fire this event.
635
+ The installer also dispatches sibling lifecycle events for diagnostics and analytics:
636
+
637
+ | Event | `detail` | Fires |
638
+ | --- | --- | --- |
639
+ | `persona:script-load` | `{ version }` | the installer script executed (before any loading) |
640
+ | `persona:launcher-shown` | `{ deferred, element? }` | the floating launcher painted on the page (page-load time) |
641
+ | `persona:chat-ready` | the widget handle | the widget is initialized and its API is callable |
642
+ | `persona:error` | `{ phase, error }` | a load step (`css` / `bundle` / `init`) failed |
643
+
644
+ > **Note:** These events are only dispatched by the automatic installer script. Direct calls to `initAgentWidget()` return the handle synchronously and do not fire them.
645
+ >
646
+ > `persona:ready` is still dispatched as a **deprecated** alias of `persona:chat-ready` and will be removed in the next major.
610
647
 
611
648
  ### Controller Events
612
649
 
@@ -1528,7 +1565,11 @@ The easiest way is to use the automatic installer script. It handles loading CSS
1528
1565
  - `previewQueryParam` - Query parameter key that gates widget loading; widget only loads when the parameter is present and truthy
1529
1566
  - `useShadowDom` - Use Shadow DOM for style isolation (default: `false`)
1530
1567
  - `windowKey` - If provided, stores the widget handle on `window[windowKey]` for programmatic access
1531
- - `onReady` - Callback fired with the widget handle after initialization; signature: `(handle) => void`
1568
+ - `onScriptLoad` - Fired as soon as the installer script executes, before it loads or gates anything (diagnostics / timing); signature: `({ version }) => void`
1569
+ - `onLauncherShown` - Fired when the floating launcher is painted on the page (page-load time — for "widget appeared" analytics); signature: `({ deferred, element? }) => void`
1570
+ - `onChatReady` - Fired when the widget is initialized and its controller API is callable (after first open in a deferred install); signature: `(handle) => void`
1571
+ - `onError` - Fired when a load step fails (`css` / `bundle` / `init`), so ad-blocked / timed-out installs don't fail silently; signature: `({ phase, error }) => void`
1572
+ - `onReady` - **Deprecated** alias of `onChatReady`; still works, removed in the next major; signature: `(handle) => void`
1532
1573
 
1533
1574
  **Example with version pinning:**
1534
1575
 
@@ -1549,14 +1590,14 @@ The easiest way is to use the automatic installer script. It handles loading CSS
1549
1590
 
1550
1591
  The installer is fully asynchronous (it waits for framework hydration, then loads CSS and JS). To interact with the widget after it initializes, use one of these approaches:
1551
1592
 
1552
- **`onReady` callback** — best when config and access logic live in the same script:
1593
+ **`onChatReady` callback** — best when config and access logic live in the same script:
1553
1594
 
1554
1595
  ```html
1555
1596
  <script>
1556
1597
  window.siteAgentConfig = {
1557
1598
  clientToken: 'YOUR_TOKEN',
1558
1599
  windowKey: 'myChat',
1559
- onReady(handle) {
1600
+ onChatReady(handle) {
1560
1601
  handle.on('message:sent', (e) => console.log('sent:', e));
1561
1602
  handle.on('message:received', (e) => console.log('received:', e));
1562
1603
  }
@@ -1565,11 +1606,11 @@ The installer is fully asynchronous (it waits for framework hydration, then load
1565
1606
  <script src="https://cdn.jsdelivr.net/npm/@runtypelabs/persona@latest/dist/install.global.js"></script>
1566
1607
  ```
1567
1608
 
1568
- **`persona:ready` event** — best for decoupled integration (e.g. tag managers, separate scripts):
1609
+ **`persona:chat-ready` event** — best for decoupled integration (e.g. tag managers, separate scripts):
1569
1610
 
1570
1611
  ```html
1571
1612
  <script>
1572
- window.addEventListener('persona:ready', (e) => {
1613
+ window.addEventListener('persona:chat-ready', (e) => {
1573
1614
  const handle = e.detail;
1574
1615
  handle.on('message:sent', (e) => console.log('sent:', e));
1575
1616
  });
@@ -1582,7 +1623,7 @@ The installer is fully asynchronous (it waits for framework hydration, then load
1582
1623
  <script src="https://cdn.jsdelivr.net/npm/@runtypelabs/persona@latest/dist/install.global.js"></script>
1583
1624
  ```
1584
1625
 
1585
- **`windowKey`** — stores the handle on `window[windowKey]` for persistent global access. Combine with `onReady` or `persona:ready` to know when it's available:
1626
+ **`windowKey`** — stores the handle on `window[windowKey]` for persistent global access. Combine with `onChatReady` or `persona:chat-ready` to know when it's available:
1586
1627
 
1587
1628
  ```html
1588
1629
  <script>
@@ -1594,7 +1635,7 @@ The installer is fully asynchronous (it waits for framework hydration, then load
1594
1635
  <script src="https://cdn.jsdelivr.net/npm/@runtypelabs/persona@latest/dist/install.global.js"></script>
1595
1636
 
1596
1637
  <script>
1597
- window.addEventListener('persona:ready', () => {
1638
+ window.addEventListener('persona:chat-ready', () => {
1598
1639
  // window.myChat is now available and persists until destroy()
1599
1640
  window.myChat.open();
1600
1641
  });
@@ -1,4 +1,4 @@
1
- import { S as StreamAnimationPlugin } from './types-BZVr1YOV.cjs';
1
+ import { S as StreamAnimationPlugin } from './types-CxvHw0X6.cjs';
2
2
 
3
3
  declare const glyphCycle: StreamAnimationPlugin;
4
4
 
@@ -1,4 +1,4 @@
1
- import { S as StreamAnimationPlugin } from './types-BZVr1YOV.js';
1
+ import { S as StreamAnimationPlugin } from './types-CxvHw0X6.js';
2
2
 
3
3
  declare const glyphCycle: StreamAnimationPlugin;
4
4