@runtypelabs/persona 3.21.3 → 3.22.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.
Files changed (57) hide show
  1. package/README.md +67 -0
  2. package/dist/animations/glyph-cycle.d.cts +1 -1
  3. package/dist/animations/glyph-cycle.d.ts +1 -1
  4. package/dist/animations/{types-CWPIj66R.d.cts → types-BZVr1YOV.d.cts} +10 -0
  5. package/dist/animations/{types-CWPIj66R.d.ts → types-BZVr1YOV.d.ts} +10 -0
  6. package/dist/animations/wipe.d.cts +1 -1
  7. package/dist/animations/wipe.d.ts +1 -1
  8. package/dist/index.cjs +50 -43
  9. package/dist/index.cjs.map +1 -1
  10. package/dist/index.d.cts +474 -6
  11. package/dist/index.d.ts +474 -6
  12. package/dist/index.global.js +98 -88
  13. package/dist/index.global.js.map +1 -1
  14. package/dist/index.js +48 -41
  15. package/dist/index.js.map +1 -1
  16. package/dist/smart-dom-reader.cjs +1875 -0
  17. package/dist/smart-dom-reader.d.cts +4521 -0
  18. package/dist/smart-dom-reader.d.ts +4521 -0
  19. package/dist/smart-dom-reader.js +1848 -0
  20. package/dist/theme-editor.cjs +2281 -84
  21. package/dist/theme-editor.d.cts +348 -1
  22. package/dist/theme-editor.d.ts +348 -1
  23. package/dist/theme-editor.js +2260 -78
  24. package/package.json +9 -2
  25. package/src/client.test.ts +165 -0
  26. package/src/client.ts +144 -23
  27. package/src/index.ts +26 -0
  28. package/src/session.test.ts +258 -0
  29. package/src/session.ts +886 -30
  30. package/src/session.webmcp.test.ts +815 -0
  31. package/src/smart-dom-reader.test.ts +135 -0
  32. package/src/smart-dom-reader.ts +135 -0
  33. package/src/theme-editor/color-utils.test.ts +59 -0
  34. package/src/theme-editor/color-utils.ts +38 -2
  35. package/src/theme-editor/index.ts +35 -0
  36. package/src/theme-editor/webmcp/coerce.test.ts +86 -0
  37. package/src/theme-editor/webmcp/coerce.ts +286 -0
  38. package/src/theme-editor/webmcp/index.ts +45 -0
  39. package/src/theme-editor/webmcp/summary.ts +324 -0
  40. package/src/theme-editor/webmcp/tools.test.ts +205 -0
  41. package/src/theme-editor/webmcp/tools.ts +795 -0
  42. package/src/theme-editor/webmcp/types.ts +87 -0
  43. package/src/types.ts +186 -0
  44. package/src/ui.composer-keyboard.test.ts +229 -0
  45. package/src/ui.ts +127 -5
  46. package/src/utils/composer-history.test.ts +128 -0
  47. package/src/utils/composer-history.ts +113 -0
  48. package/src/utils/message-fingerprint.test.ts +20 -0
  49. package/src/utils/message-fingerprint.ts +2 -0
  50. package/src/utils/smart-dom-adapter.test.ts +257 -0
  51. package/src/utils/smart-dom-adapter.ts +217 -0
  52. package/{LICENSE → src/vendor/smart-dom-reader/LICENSE} +2 -2
  53. package/src/vendor/smart-dom-reader/README.md +61 -0
  54. package/src/vendor/smart-dom-reader/index.d.ts +476 -0
  55. package/src/vendor/smart-dom-reader/index.js +1618 -0
  56. package/src/webmcp-bridge.test.ts +429 -0
  57. package/src/webmcp-bridge.ts +547 -0
package/README.md CHANGED
@@ -459,6 +459,72 @@ const myRules: ParseRule[] = [
459
459
  ];
460
460
  ```
461
461
 
462
+ #### Optional: smart-dom-reader provider
463
+
464
+ The default reader above is a zero-dependency `TreeWalker` and **does not pierce shadow
465
+ DOM**. For pages built from web components, an optional provider backed by a
466
+ vendored copy of [`@mcp-b/smart-dom-reader`](https://github.com/WebMCP-org/npm-packages/tree/main/packages/smart-dom-reader)
467
+ ships as a **separate entry point**, `@runtypelabs/persona/smart-dom-reader`. It is **not**
468
+ imported by the main bundle, so consumers who never import this subpath pay nothing — no
469
+ extra install, no bundle weight, no IIFE/CDN impact.
470
+
471
+ It adds, over the default reader: **Shadow-DOM piercing**, form grouping, and page
472
+ landmarks/state — while still emitting Persona's `EnrichedPageElement[]` shape so it
473
+ formats and flows through the same pipeline.
474
+
475
+ ```ts
476
+ import initAgentWidget from '@runtypelabs/persona';
477
+ import { createSmartDomReaderContextProvider } from '@runtypelabs/persona/smart-dom-reader';
478
+
479
+ initAgentWidget({
480
+ // ...config
481
+ contextProviders: [
482
+ createSmartDomReaderContextProvider({
483
+ // 'interactive' (default) | 'full' — full adds semantic content AND is required
484
+ // for shadow-DOM piercing (shadow descendants surface only in full mode).
485
+ mode: 'full',
486
+ contextKey: 'pageContext', // key under payload.context (default)
487
+ // root: document.querySelector('main') // optional: scope to a subtree, skip chrome
488
+ })
489
+ ]
490
+ });
491
+ ```
492
+
493
+ `contextProviders` are honored on the **agent** send path (`buildAgentPayload` merges each
494
+ provider's result into `payload.context` on every request). If you drive the legacy
495
+ flow/`buildPayload` path, call `collectSmartDomContext()` yourself and inject the result.
496
+
497
+ You can also use the pieces directly:
498
+
499
+ ```ts
500
+ import {
501
+ collectSmartDomContext, // → EnrichedPageElement[] (parity with collectEnrichedPageContext)
502
+ smartDomResultToEnriched // pure mapper: SmartDOMResult → EnrichedPageElement[]
503
+ } from '@runtypelabs/persona/smart-dom-reader';
504
+ import { formatEnrichedContext } from '@runtypelabs/persona';
505
+
506
+ const pageContext = formatEnrichedContext(collectSmartDomContext({ mode: 'full' }));
507
+ ```
508
+
509
+ Both `collectSmartDomContext()` and `createSmartDomReaderContextProvider()` accept a
510
+ `root` element to scope extraction to a subtree (parity with `collectEnrichedPageContext`'s
511
+ `root`) — useful to read only your main content region and skip nav/sidebars. Shadow DOM
512
+ inside the subtree is still pierced.
513
+
514
+ > **Actionability caveat.** Persona's click loop (`utils/actions.ts`) drives
515
+ > `document.querySelector`, which cannot pierce shadow roots or evaluate XPath. The adapter
516
+ > therefore prefers plain-CSS selectors; elements reachable only via shadow-piercing or
517
+ > XPath selectors are surfaced to the model as **context only** and are **not clickable**
518
+ > through the current `message_and_click` handler.
519
+
520
+ > **Why vendored, not a dependency.** Every published version of `@mcp-b/smart-dom-reader`
521
+ > (2.3.1–3.0.0) is mis-published — its `package.json` points to `dist/index.js` /
522
+ > `dist/index.d.ts` while the build only ships `.mjs` / `.d.mts`, so it cannot be imported
523
+ > by name in Node or any bundler. The library (MIT, zero-dep) is therefore vendored under
524
+ > `packages/widget/src/vendor/smart-dom-reader/`; see that directory's `README.md` for
525
+ > provenance and update steps. Once upstream republishes correctly this can revert to a
526
+ > normal optional peer dependency.
527
+
462
528
  ### DOM Events
463
529
 
464
530
  The widget dispatches custom DOM events that you can listen to for integration with your application:
@@ -2278,6 +2344,7 @@ config: {
2278
2344
  | `showReasoning` | `boolean?` | Show thinking/reasoning bubbles. Default: `true`. |
2279
2345
  | `showToolCalls` | `boolean?` | Show tool usage bubbles. Default: `true`. |
2280
2346
  | `showEventStreamToggle` | `boolean?` | Show the event stream inspector toggle in the header. Default: `false`. |
2347
+ | `composerHistory` | `boolean?` | `Up`/`Down` arrows in the composer navigate previously sent user messages for re-entry/editing (shell / Slack style). Entered only when the caret is at the start of the input, so multi-line cursor movement is preserved. Default: `true`. |
2281
2348
  | `eventStream` | `EventStreamConfig?` | Event stream inspector configuration: `badgeColors`, `timestampFormat`, `showSequenceNumbers`, `maxEvents`, `descriptionFields`, `classNames`. |
2282
2349
  | `artifacts` | `AgentWidgetArtifactsFeature?` | Artifact sidebar: `enabled`, `allowedTypes`, optional `layout` (see below). |
2283
2350
 
@@ -1,4 +1,4 @@
1
- import { S as StreamAnimationPlugin } from './types-CWPIj66R.cjs';
1
+ import { S as StreamAnimationPlugin } from './types-BZVr1YOV.cjs';
2
2
 
3
3
  declare const glyphCycle: StreamAnimationPlugin;
4
4
 
@@ -1,4 +1,4 @@
1
- import { S as StreamAnimationPlugin } from './types-CWPIj66R.js';
1
+ import { S as StreamAnimationPlugin } from './types-BZVr1YOV.js';
2
2
 
3
3
  declare const glyphCycle: StreamAnimationPlugin;
4
4
 
@@ -73,6 +73,16 @@ type AgentMessageMetadata = {
73
73
  * `POST /v1/dispatch/resume` with the user's answer keyed by tool name.
74
74
  */
75
75
  awaitingLocalTool?: boolean;
76
+ /**
77
+ * The provider per-call id (`toolu_…`) carried on the `step_await` /
78
+ * `flow_await` events for a LOCAL tool (core#3878). Present only when the
79
+ * server emits it. Two PARALLEL calls to the same tool in one turn share a
80
+ * `toolName` (and a collapsed `toolId`) but get DISTINCT `webMcpToolCallId`s,
81
+ * so this is the key the widget batches a single `/resume` on — preferred
82
+ * over tool name, which collides for same-tool parallel calls. Absent →
83
+ * fall back to the legacy name-keyed resume contract.
84
+ */
85
+ webMcpToolCallId?: string;
76
86
  /**
77
87
  * Set to `true` once the user has picked / typed / dismissed an answer for
78
88
  * an `ask_user_question` tool call, so renderers stop re-mounting the
@@ -73,6 +73,16 @@ type AgentMessageMetadata = {
73
73
  * `POST /v1/dispatch/resume` with the user's answer keyed by tool name.
74
74
  */
75
75
  awaitingLocalTool?: boolean;
76
+ /**
77
+ * The provider per-call id (`toolu_…`) carried on the `step_await` /
78
+ * `flow_await` events for a LOCAL tool (core#3878). Present only when the
79
+ * server emits it. Two PARALLEL calls to the same tool in one turn share a
80
+ * `toolName` (and a collapsed `toolId`) but get DISTINCT `webMcpToolCallId`s,
81
+ * so this is the key the widget batches a single `/resume` on — preferred
82
+ * over tool name, which collides for same-tool parallel calls. Absent →
83
+ * fall back to the legacy name-keyed resume contract.
84
+ */
85
+ webMcpToolCallId?: string;
76
86
  /**
77
87
  * Set to `true` once the user has picked / typed / dismissed an answer for
78
88
  * an `ask_user_question` tool call, so renderers stop re-mounting the
@@ -1,4 +1,4 @@
1
- import { S as StreamAnimationPlugin } from './types-CWPIj66R.cjs';
1
+ import { S as StreamAnimationPlugin } from './types-BZVr1YOV.cjs';
2
2
 
3
3
  declare const wipe: StreamAnimationPlugin;
4
4
 
@@ -1,4 +1,4 @@
1
- import { S as StreamAnimationPlugin } from './types-CWPIj66R.js';
1
+ import { S as StreamAnimationPlugin } from './types-BZVr1YOV.js';
2
2
 
3
3
  declare const wipe: StreamAnimationPlugin;
4
4