@mcpview/compose 0.12.0 → 0.13.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.
Files changed (169) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/README.md +104 -1
  3. package/esm/_dnt.polyfills.d.ts +49 -0
  4. package/esm/_dnt.polyfills.d.ts.map +1 -1
  5. package/esm/_dnt.polyfills.js +36 -0
  6. package/esm/src/code-mode/board.d.ts +21 -1
  7. package/esm/src/code-mode/board.d.ts.map +1 -1
  8. package/esm/src/code-mode/board.js +76 -2
  9. package/esm/src/code-mode/chain.d.ts +2 -0
  10. package/esm/src/code-mode/chain.d.ts.map +1 -1
  11. package/esm/src/code-mode/chain.js +34 -8
  12. package/esm/src/code-mode/connections.d.ts +1 -0
  13. package/esm/src/code-mode/connections.d.ts.map +1 -1
  14. package/esm/src/code-mode/connections.js +1 -0
  15. package/esm/src/code-mode/layout-publisher.d.ts +69 -0
  16. package/esm/src/code-mode/layout-publisher.d.ts.map +1 -0
  17. package/esm/src/code-mode/layout-publisher.js +85 -0
  18. package/esm/src/code-mode/layout-runs.d.ts +35 -0
  19. package/esm/src/code-mode/layout-runs.d.ts.map +1 -0
  20. package/esm/src/code-mode/layout-runs.js +130 -0
  21. package/esm/src/code-mode/layout.d.ts +20 -0
  22. package/esm/src/code-mode/layout.d.ts.map +1 -0
  23. package/esm/src/code-mode/layout.js +54 -0
  24. package/esm/src/code-mode/mod.d.ts +1 -0
  25. package/esm/src/code-mode/mod.d.ts.map +1 -1
  26. package/esm/src/code-mode/mod.js +1 -0
  27. package/esm/src/code-mode/panel-contexts.d.ts +25 -0
  28. package/esm/src/code-mode/panel-contexts.d.ts.map +1 -0
  29. package/esm/src/code-mode/panel-contexts.js +115 -0
  30. package/esm/src/code-mode/providers.d.ts +3 -0
  31. package/esm/src/code-mode/providers.d.ts.map +1 -1
  32. package/esm/src/code-mode/sandbox.d.ts.map +1 -1
  33. package/esm/src/code-mode/sandbox.js +2 -1
  34. package/esm/src/code-mode/sync.d.ts +11 -0
  35. package/esm/src/code-mode/sync.d.ts.map +1 -0
  36. package/esm/src/code-mode/sync.js +42 -0
  37. package/esm/src/code-mode/tool.d.ts +1 -1
  38. package/esm/src/code-mode/tool.d.ts.map +1 -1
  39. package/esm/src/code-mode/tool.js +12 -0
  40. package/esm/src/core/collector/collector.d.ts +2 -1
  41. package/esm/src/core/collector/collector.d.ts.map +1 -1
  42. package/esm/src/core/collector/collector.js +6 -0
  43. package/esm/src/core/types/resources.d.ts +4 -0
  44. package/esm/src/core/types/resources.d.ts.map +1 -1
  45. package/esm/src/core/types/resources.js +10 -1
  46. package/esm/src/host/renderer/css/base.d.ts.map +1 -1
  47. package/esm/src/host/renderer/css/base.js +3 -0
  48. package/esm/src/host/renderer/css/layouts.d.ts.map +1 -1
  49. package/esm/src/host/renderer/css/layouts.js +17 -14
  50. package/esm/src/host/renderer/css/panel-controls.d.ts +3 -0
  51. package/esm/src/host/renderer/css/panel-controls.d.ts.map +1 -0
  52. package/esm/src/host/renderer/css/panel-controls.js +89 -0
  53. package/esm/src/host/renderer/html-generator.d.ts.map +1 -1
  54. package/esm/src/host/renderer/html-generator.js +38 -42
  55. package/esm/src/host/renderer/js/card-height.d.ts +3 -0
  56. package/esm/src/host/renderer/js/card-height.d.ts.map +1 -0
  57. package/esm/src/host/renderer/js/card-height.js +58 -0
  58. package/esm/src/host/renderer/js/event-bus.d.ts.map +1 -1
  59. package/esm/src/host/renderer/js/event-bus.js +32 -12
  60. package/esm/src/host/renderer/panel-controls.d.ts +30 -0
  61. package/esm/src/host/renderer/panel-controls.d.ts.map +1 -0
  62. package/esm/src/host/renderer/panel-controls.js +6 -0
  63. package/esm/src/host/renderer/panel-movement.d.ts +8 -0
  64. package/esm/src/host/renderer/panel-movement.d.ts.map +1 -0
  65. package/esm/src/host/renderer/panel-movement.js +396 -0
  66. package/esm/src/host/renderer/panel-reflow.d.ts +17 -0
  67. package/esm/src/host/renderer/panel-reflow.d.ts.map +1 -0
  68. package/esm/src/host/renderer/panel-reflow.js +342 -0
  69. package/esm/src/host/renderer/panel-resizing.d.ts +11 -0
  70. package/esm/src/host/renderer/panel-resizing.d.ts.map +1 -0
  71. package/esm/src/host/renderer/panel-resizing.js +375 -0
  72. package/esm/src/host/renderer/panel-snapshot.d.ts +11 -0
  73. package/esm/src/host/renderer/panel-snapshot.d.ts.map +1 -0
  74. package/esm/src/host/renderer/panel-snapshot.js +65 -0
  75. package/esm/src/runtime/compose.d.ts.map +1 -1
  76. package/esm/src/runtime/compose.js +3 -0
  77. package/esm/src/runtime/manifest.d.ts.map +1 -1
  78. package/esm/src/runtime/manifest.js +4 -0
  79. package/esm/src/runtime/types.d.ts +2 -0
  80. package/esm/src/runtime/types.d.ts.map +1 -1
  81. package/esm/src/sdk/mcp-sdk.d.ts +2 -1
  82. package/esm/src/sdk/mcp-sdk.d.ts.map +1 -1
  83. package/esm/src/sdk/mcp-sdk.js +2 -2
  84. package/esm/src/version.d.ts +1 -1
  85. package/esm/src/version.js +1 -1
  86. package/package.json +9 -1
  87. package/script/_dnt.polyfills.d.ts +49 -0
  88. package/script/_dnt.polyfills.d.ts.map +1 -1
  89. package/script/_dnt.polyfills.js +36 -0
  90. package/script/src/code-mode/board.d.ts +21 -1
  91. package/script/src/code-mode/board.d.ts.map +1 -1
  92. package/script/src/code-mode/board.js +87 -3
  93. package/script/src/code-mode/chain.d.ts +2 -0
  94. package/script/src/code-mode/chain.d.ts.map +1 -1
  95. package/script/src/code-mode/chain.js +34 -8
  96. package/script/src/code-mode/connections.d.ts +1 -0
  97. package/script/src/code-mode/connections.d.ts.map +1 -1
  98. package/script/src/code-mode/connections.js +1 -0
  99. package/script/src/code-mode/layout-publisher.d.ts +69 -0
  100. package/script/src/code-mode/layout-publisher.d.ts.map +1 -0
  101. package/script/src/code-mode/layout-publisher.js +88 -0
  102. package/script/src/code-mode/layout-runs.d.ts +35 -0
  103. package/script/src/code-mode/layout-runs.d.ts.map +1 -0
  104. package/script/src/code-mode/layout-runs.js +134 -0
  105. package/script/src/code-mode/layout.d.ts +20 -0
  106. package/script/src/code-mode/layout.d.ts.map +1 -0
  107. package/script/src/code-mode/layout.js +57 -0
  108. package/script/src/code-mode/mod.d.ts +1 -0
  109. package/script/src/code-mode/mod.d.ts.map +1 -1
  110. package/script/src/code-mode/mod.js +6 -1
  111. package/script/src/code-mode/panel-contexts.d.ts +25 -0
  112. package/script/src/code-mode/panel-contexts.d.ts.map +1 -0
  113. package/script/src/code-mode/panel-contexts.js +118 -0
  114. package/script/src/code-mode/providers.d.ts +3 -0
  115. package/script/src/code-mode/providers.d.ts.map +1 -1
  116. package/script/src/code-mode/sandbox.d.ts.map +1 -1
  117. package/script/src/code-mode/sandbox.js +2 -1
  118. package/script/src/code-mode/sync.d.ts +11 -0
  119. package/script/src/code-mode/sync.d.ts.map +1 -0
  120. package/script/src/code-mode/sync.js +51 -0
  121. package/script/src/code-mode/tool.d.ts +1 -1
  122. package/script/src/code-mode/tool.d.ts.map +1 -1
  123. package/script/src/code-mode/tool.js +12 -0
  124. package/script/src/core/collector/collector.d.ts +2 -1
  125. package/script/src/core/collector/collector.d.ts.map +1 -1
  126. package/script/src/core/collector/collector.js +6 -0
  127. package/script/src/core/types/resources.d.ts +4 -0
  128. package/script/src/core/types/resources.d.ts.map +1 -1
  129. package/script/src/core/types/resources.js +11 -0
  130. package/script/src/host/renderer/css/base.d.ts.map +1 -1
  131. package/script/src/host/renderer/css/base.js +3 -0
  132. package/script/src/host/renderer/css/layouts.d.ts.map +1 -1
  133. package/script/src/host/renderer/css/layouts.js +17 -14
  134. package/script/src/host/renderer/css/panel-controls.d.ts +3 -0
  135. package/script/src/host/renderer/css/panel-controls.d.ts.map +1 -0
  136. package/script/src/host/renderer/css/panel-controls.js +92 -0
  137. package/script/src/host/renderer/html-generator.d.ts.map +1 -1
  138. package/script/src/host/renderer/html-generator.js +38 -42
  139. package/script/src/host/renderer/js/card-height.d.ts +3 -0
  140. package/script/src/host/renderer/js/card-height.d.ts.map +1 -0
  141. package/script/src/host/renderer/js/card-height.js +61 -0
  142. package/script/src/host/renderer/js/event-bus.d.ts.map +1 -1
  143. package/script/src/host/renderer/js/event-bus.js +32 -12
  144. package/script/src/host/renderer/panel-controls.d.ts +30 -0
  145. package/script/src/host/renderer/panel-controls.d.ts.map +1 -0
  146. package/script/src/host/renderer/panel-controls.js +14 -0
  147. package/script/src/host/renderer/panel-movement.d.ts +8 -0
  148. package/script/src/host/renderer/panel-movement.d.ts.map +1 -0
  149. package/script/src/host/renderer/panel-movement.js +399 -0
  150. package/script/src/host/renderer/panel-reflow.d.ts +17 -0
  151. package/script/src/host/renderer/panel-reflow.d.ts.map +1 -0
  152. package/script/src/host/renderer/panel-reflow.js +345 -0
  153. package/script/src/host/renderer/panel-resizing.d.ts +11 -0
  154. package/script/src/host/renderer/panel-resizing.d.ts.map +1 -0
  155. package/script/src/host/renderer/panel-resizing.js +378 -0
  156. package/script/src/host/renderer/panel-snapshot.d.ts +11 -0
  157. package/script/src/host/renderer/panel-snapshot.d.ts.map +1 -0
  158. package/script/src/host/renderer/panel-snapshot.js +69 -0
  159. package/script/src/runtime/compose.d.ts.map +1 -1
  160. package/script/src/runtime/compose.js +3 -0
  161. package/script/src/runtime/manifest.d.ts.map +1 -1
  162. package/script/src/runtime/manifest.js +4 -0
  163. package/script/src/runtime/types.d.ts +2 -0
  164. package/script/src/runtime/types.d.ts.map +1 -1
  165. package/script/src/sdk/mcp-sdk.d.ts +2 -1
  166. package/script/src/sdk/mcp-sdk.d.ts.map +1 -1
  167. package/script/src/sdk/mcp-sdk.js +2 -2
  168. package/script/src/version.d.ts +1 -1
  169. package/script/src/version.js +1 -1
package/CHANGELOG.md CHANGED
@@ -5,6 +5,28 @@ documented in this file.
5
5
 
6
6
  ## [Unreleased]
7
7
 
8
+ ## [0.13.1] - 2026-11-27
9
+
10
+ ### Added
11
+
12
+ - Route events between mounted Code Mode panels through their declared ports. A linked panel can
13
+ update its result while the user keeps a separate selection in the conversation.
14
+ - Capture and restore a dashboard's committed positions and supported widths using stable panel IDs.
15
+ Hosts can associate an acknowledged layout revision with an authenticated Code Mode execution.
16
+ - The Code Mode board can publish layout acknowledgements and merge selections from mounted panels
17
+ into the host's conversation context.
18
+
19
+ ## [0.13.0] - 2026-11-27
20
+
21
+ ### Added
22
+
23
+ - Drag a viewer by its top-left grip to swap or position it beside or below another viewer. Embedded
24
+ dashboards report their height to the host as rows appear or disappear. The bottom-right corner
25
+ snaps to widths declared by the viewer's Compose manifest or local adapter. A skeleton reserves
26
+ the destination during the drag so neighbors can move before release. Each App keeps its content
27
+ height, mounted state and event routes. Code Mode boards can use the same controls for locally
28
+ rendered panels.
29
+
8
30
  ## [0.12.0] - 2026-11-26
9
31
 
10
32
  ### Added
package/README.md CHANGED
@@ -127,6 +127,28 @@ path uses results already returned by the script. The runnable engineering examp
127
127
  server, both providers, and a single-frame board with a 3D viewer and interactive print report.
128
128
  [Engineering example and setup](https://github.com/mcpview/mcpview/tree/main/packages/compose/examples/multi-mcp-snippets)
129
129
 
130
+ The server can declare event ports for each snippet under the provider binding's `events` field. For
131
+ example, use
132
+ `{ "invoice-list": { emits: ["invoice.selected"] }, "invoice-detail": {
133
+ accepts: ["invoice.focus"] } }`.
134
+ The `execute` description advertises the configured ports. Once the program has selected both
135
+ receipts with `api.panel`, it can add a route:
136
+
137
+ ```js
138
+ await api.sync({
139
+ from: list.id,
140
+ event: "invoice.selected",
141
+ to: detail.id,
142
+ action: "invoice.focus",
143
+ });
144
+ ```
145
+
146
+ The route is scoped to those two receipts in the current result. For local renderers, declare the
147
+ implemented ports in each `resolveView` result and call
148
+ `emitSnippetBoardEvent(descriptor, sourceReceiptId, event, data, deliver)` with the active board
149
+ descriptor. The board's `deliver(targetReceiptId, action, data)` callback handles the action
150
+ locally. The target view owns validation of its action data.
151
+
130
152
  ## MCP SDK compatibility
131
153
 
132
154
  Compose uses MCP Apps 2.x and the split MCP SDK 2.x packages. Integrations importing SDK types or
@@ -220,11 +242,92 @@ Each step is a pure function. Use them independently or together.
220
242
 
221
243
  | Layout | Description |
222
244
  | ------- | ----------------------------- |
223
- | `split` | Side-by-side panels (flexbox) |
245
+ | `split` | Side-by-side panels |
224
246
  | `tabs` | Tabbed interface with tab bar |
225
247
  | `grid` | Auto-fit grid for dashboards |
226
248
  | `stack` | Vertical stack (default) |
227
249
 
250
+ Drag the grip in the top-left corner to move a viewer. Aim at the bottom edge of another viewer to
251
+ place it on the row below. Drop beside it to return to one row when both widths fit, or drop in its
252
+ center to swap. The skeleton shows where the viewer will land. An embedded Compose board reports its
253
+ content height to the host as the rows change, including during the preview and on cancellation. You
254
+ can also swap by clicking or tapping two handles in sequence. In a tabbed dashboard the handles
255
+ reorder the tabs.
256
+
257
+ Declare a viewer's supported widths in CSS pixels on its Compose manifest tool, for example
258
+ `"supportedWidths": [380, 640]`. Programmatic descriptors and local Code Mode view adapters accept
259
+ the same field. Omit it for a viewer that should keep its template size.
260
+
261
+ Drag the bottom-right corner to preview an allowed width. At the right edge of the screen, pull down
262
+ to reach a wider format. The skeleton reserves the space and neighbors shift sideways or wrap to a
263
+ new row. When the viewer shrinks, its neighbor returns beside it with the template's original gap as
264
+ soon as both fit. Release to apply the width or press Escape to cancel. The left and right arrow
265
+ keys step between available widths when the corner has focus. The template supplies the initial
266
+ layout unless the host restores a saved layout. Each iframe stays mounted and reports its own
267
+ content height as its width changes.
268
+
269
+ A Code Mode host can store panel order, requested widths and relative placements with a snippet.
270
+ Give each panel a stable `data-compose-panel-id` across runs, including when two panels use the same
271
+ viewer.
272
+
273
+ Use one context writer per mounted App. Give each panel its own writer with
274
+ `contexts.forPanel(id, title, basketSignal)`. The board uses the same queue to publish the execution
275
+ reference and revision that the model can use to save a layout. A month or record selected in a
276
+ panel stays in the conversation when the user moves the panel.
277
+
278
+ ```ts
279
+ import { connectSnippetBoardLayout, createPanelContexts } from "@mcpview/compose/code-mode/board";
280
+
281
+ const contexts = createPanelContexts(app.updateModelContext.bind(app));
282
+ const retry = connectSnippetBoardLayout(board, {
283
+ host: app,
284
+ stageTool: "stage_dashboard_layout", // App-only callback registered by your server
285
+ runId,
286
+ savedLayout,
287
+ updateContext: contexts.forBoard(displaySignal),
288
+ signal: displaySignal,
289
+ onStatus: showLayoutStatus,
290
+ });
291
+ ```
292
+
293
+ `connectSnippetBoardLayout` installs the move and resize controls, restores a saved layout and
294
+ stages each committed gesture. The server acknowledges the revision before the writer publishes its
295
+ `ready` receipt using the host's supported context format. The App supplies its own status display
296
+ and can call `retry()` after an error. Give the layout receipt the lifetime of the displayed board.
297
+ If a save confirmation replaces the board while the basket still belongs to the conversation, end
298
+ the display lifetime and call `contexts.clear()` to remove expired contributions. End the basket
299
+ lifetime and clear again when the selection is discarded.
300
+
301
+ On a text-only host, Compose forwards the panels' content blocks in order. In structured context,
302
+ multiple selections are grouped under `panels` with their titles. A single panel keeps its original
303
+ shape unless a board metadata key overlaps, in which case its selection also appears under `panels`.
304
+
305
+ To associate edits with the correct execution, the server can use `BoardLayoutRuns` from
306
+ `@mcpview/compose/code-mode/layout-runs`. Register the scoped execution with `open`, passing a map
307
+ from stable panel IDs to their declared widths. `stage` acknowledges a snapshot and revision from
308
+ the app. On an explicit save or update, `selected` supplies the acknowledged geometry to the snippet
309
+ catalog. Call `saved` only after a successful save. Updates accept names bound by saving or
310
+ replaying this dashboard. Repeating a stage request with the same revision and geometry is safe if
311
+ the response was lost. A user-initiated retry in the App stages the current layout with a new
312
+ revision.
313
+
314
+ On a fresh board, `restorePanelLayout(board, snapshot)` applies the saved preference once the
315
+ controls are installed. It returns false if the panel IDs or supported widths have changed
316
+ incompatibly. On narrow screens the controls apply a width that fits and retain the requested width
317
+ for a larger screen.
318
+
319
+ `@mcpview/compose/code-mode/layout` exports the `PanelLayoutSnapshot` type and the DOM-independent
320
+ `isPanelLayoutSnapshot` validator. The board entry point (`@mcpview/compose/code-mode/board`) also
321
+ exports these and the browser capture and restore functions.
322
+
323
+ For a Code Mode board with local renderers, `@mcpview/compose/code-mode/board` exports
324
+ `getPanelControlsCss()`, `installPanelMovement(board, signal?)` and
325
+ `installPanelResizing(board, signal?)`. Mark the grid with `data-compose-board` and its direct panel
326
+ elements with `data-compose-panel` and `data-panel-label`. Set `data-compose-widths` to the
327
+ space-separated widths of each resizable local viewer. Place a `button[data-compose-grip]` inside
328
+ each panel. Named layouts identify each panel's grid area with `data-area`. The
329
+ [CAD and print estimate board](./examples/multi-mcp-snippets/ui/main.ts) shows the full setup.
330
+
228
331
  ## Sync Rules
229
332
 
230
333
  Declarative event routing between UIs:
@@ -9,6 +9,55 @@ declare global {
9
9
  }
10
10
  }
11
11
  export {};
12
+ declare global {
13
+ interface Array<T> {
14
+ /**
15
+ * Returns the value of the last element in the array where predicate is true, and undefined
16
+ * otherwise.
17
+ * @param predicate find calls predicate once for each element of the array, in ascending
18
+ * order, until it finds one where predicate returns true. If such an element is found, find
19
+ * immediately returns that element value. Otherwise, find returns undefined.
20
+ * @param thisArg If provided, it will be used as the this value for each invocation of
21
+ * predicate. If it is not provided, undefined is used instead.
22
+ */
23
+ findLast<S extends T>(predicate: (this: void, value: T, index: number, obj: T[]) => value is S, thisArg?: any): S | undefined;
24
+ findLast(predicate: (value: T, index: number, obj: T[]) => unknown, thisArg?: any): T | undefined;
25
+ /**
26
+ * Returns the index of the last element in the array where predicate is true, and -1
27
+ * otherwise.
28
+ * @param predicate find calls predicate once for each element of the array, in ascending
29
+ * order, until it finds one where predicate returns true. If such an element is found,
30
+ * findIndex immediately returns that element index. Otherwise, findIndex returns -1.
31
+ * @param thisArg If provided, it will be used as the this value for each invocation of
32
+ * predicate. If it is not provided, undefined is used instead.
33
+ */
34
+ findLastIndex(predicate: (value: T, index: number, obj: T[]) => unknown, thisArg?: any): number;
35
+ }
36
+ interface Uint8Array {
37
+ /**
38
+ * Returns the value of the last element in the array where predicate is true, and undefined
39
+ * otherwise.
40
+ * @param predicate findLast calls predicate once for each element of the array, in descending
41
+ * order, until it finds one where predicate returns true. If such an element is found, findLast
42
+ * immediately returns that element value. Otherwise, findLast returns undefined.
43
+ * @param thisArg If provided, it will be used as the this value for each invocation of
44
+ * predicate. If it is not provided, undefined is used instead.
45
+ */
46
+ findLast<S extends number>(predicate: (value: number, index: number, array: Uint8Array) => value is S, thisArg?: any): S | undefined;
47
+ findLast(predicate: (value: number, index: number, array: Uint8Array) => unknown, thisArg?: any): number | undefined;
48
+ /**
49
+ * Returns the index of the last element in the array where predicate is true, and -1
50
+ * otherwise.
51
+ * @param predicate findLastIndex calls predicate once for each element of the array, in descending
52
+ * order, until it finds one where predicate returns true. If such an element is found,
53
+ * findLastIndex immediately returns that element index. Otherwise, findLastIndex returns -1.
54
+ * @param thisArg If provided, it will be used as the this value for each invocation of
55
+ * predicate. If it is not provided, undefined is used instead.
56
+ */
57
+ findLastIndex(predicate: (value: number, index: number, array: Uint8Array) => unknown, thisArg?: any): number;
58
+ }
59
+ }
60
+ export {};
12
61
  declare global {
13
62
  interface Error {
14
63
  cause?: unknown;
@@ -1 +1 @@
1
- {"version":3,"file":"_dnt.polyfills.d.ts","sourceRoot":"","sources":["../src/_dnt.polyfills.ts"],"names":[],"mappings":"AAeA,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd;;;;WAIG;QACH,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC;KAC5C;CACF;AAED,OAAO,EAAE,CAAC;AACV,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,KAAK;QACb,KAAK,CAAC,EAAE,OAAO,CAAC;KACjB;CACF;AAED,OAAO,EAAE,CAAC"}
1
+ {"version":3,"file":"_dnt.polyfills.d.ts","sourceRoot":"","sources":["../src/_dnt.polyfills.ts"],"names":[],"mappings":"AAeA,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd;;;;WAIG;QACH,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,WAAW,GAAG,OAAO,C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K,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,KAAK,OAAO,EACvE,OAAO,CAAC,EAAE,GAAG,GACd,MAAM,CAAC;KACX;CACF;AA4CD,OAAO,EAAE,CAAC;AACV,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,KAAK;QACb,KAAK,CAAC,EAAE,OAAO,CAAC;KACjB;CACF;AAED,OAAO,EAAE,CAAC"}
@@ -12,4 +12,40 @@ if (!Object.hasOwn) {
12
12
  writable: true,
13
13
  });
14
14
  }
15
+ function findLastIndex(self, callbackfn, that) {
16
+ const boundFunc = that === undefined ? callbackfn : callbackfn.bind(that);
17
+ let index = self.length - 1;
18
+ while (index >= 0) {
19
+ const result = boundFunc(self[index], index, self);
20
+ if (result) {
21
+ return index;
22
+ }
23
+ index--;
24
+ }
25
+ return -1;
26
+ }
27
+ function findLast(self, callbackfn, that) {
28
+ const index = self.findLastIndex(callbackfn, that);
29
+ return index === -1 ? undefined : self[index];
30
+ }
31
+ if (!Array.prototype.findLastIndex) {
32
+ Array.prototype.findLastIndex = function (callbackfn, that) {
33
+ return findLastIndex(this, callbackfn, that);
34
+ };
35
+ }
36
+ if (!Array.prototype.findLast) {
37
+ Array.prototype.findLast = function (callbackfn, that) {
38
+ return findLast(this, callbackfn, that);
39
+ };
40
+ }
41
+ if (!Uint8Array.prototype.findLastIndex) {
42
+ Uint8Array.prototype.findLastIndex = function (callbackfn, that) {
43
+ return findLastIndex(this, callbackfn, that);
44
+ };
45
+ }
46
+ if (!Uint8Array.prototype.findLast) {
47
+ Uint8Array.prototype.findLast = function (callbackfn, that) {
48
+ return findLast(this, callbackfn, that);
49
+ };
50
+ }
15
51
  export {};
@@ -3,9 +3,17 @@
3
3
  * @module
4
4
  */
5
5
  import "../../_dnt.polyfills.js";
6
- import type { ComponentSurface } from "../core/types/components.js";
6
+ import type { ComponentSurface, ViewComponentEventPorts } from "../core/types/components.js";
7
7
  import type { CompositeUiDescriptor } from "../core/types/descriptor.js";
8
8
  import type { UiLayout } from "../core/types/layout.js";
9
+ import type { UiSyncRule } from "../core/types/sync-rules.js";
10
+ import { SNIPPET_SYNC_META_KEY } from "./sync.js";
11
+ export { SNIPPET_SYNC_META_KEY };
12
+ export { createPanelContexts, type PanelContexts, type PanelContextUpdate, type SendPanelContext, } from "./panel-contexts.js";
13
+ export { connectSnippetBoardLayout, type SnippetBoardLayoutOptions, type SnippetLayoutReceipt, type SnippetLayoutStatus, } from "./layout-publisher.js";
14
+ export { getPanelControlsCss } from "../host/renderer/css/panel-controls.js";
15
+ export { isPanelLayoutSnapshot, type PanelLayoutSnapshot } from "./layout.js";
16
+ export { capturePanelLayout, installPanelMovement, installPanelResizing, restorePanelLayout, } from "../host/renderer/panel-controls.js";
9
17
  /** MCP App result metadata containing the receipts selected by the program. */
10
18
  export declare const SNIPPET_PANELS_META_KEY = "io.mcpview/snippet-panels";
11
19
  /** A selected provider result. The receipt ID distinguishes calls to the same snippet. */
@@ -15,12 +23,17 @@ export interface SnippetPanel {
15
23
  readonly name: string;
16
24
  readonly title: string;
17
25
  readonly result: Record<string, unknown>;
26
+ readonly events?: ViewComponentEventPorts;
18
27
  }
19
28
  /** An App-owned view for a receipt, with optional renderer data and component selection. */
20
29
  export interface SnippetPanelView {
21
30
  readonly resourceUri: string;
22
31
  readonly context?: Record<string, unknown>;
23
32
  readonly surface?: ComponentSurface;
33
+ /** Widths offered by this local view in CSS pixels. An empty list disables resizing. */
34
+ readonly supportedWidths?: readonly number[];
35
+ /** Restrict routing to the ports implemented by this local view. */
36
+ readonly events?: ViewComponentEventPorts;
24
37
  }
25
38
  /** Display options supplied by the board hosting the results. */
26
39
  export interface SnippetBoardOptions {
@@ -42,6 +55,8 @@ export interface SnippetBoardOptions {
42
55
  * ```
43
56
  */
44
57
  export declare function readSnippetPanels(result: unknown): SnippetPanel[];
58
+ /** Read unique, declared Compose routes between panels in this result. */
59
+ export declare function readSnippetSyncRules(result: unknown): UiSyncRule[];
45
60
  /**
46
61
  * Build a Compose descriptor from the current execution, without making any provider calls.
47
62
  * Each child keeps its receipt in `context.panel` and adapter data in `context.view`.
@@ -59,4 +74,9 @@ export declare function readSnippetPanels(result: unknown): SnippetPanel[];
59
74
  * ```
60
75
  */
61
76
  export declare function composeSnippetBoard(result: unknown, options?: SnippetBoardOptions): CompositeUiDescriptor;
77
+ /**
78
+ * Deliver a JSON event through the current board's declared routes to mounted views.
79
+ * The board owns dispatch and supplies the receipts and data from its active UI.
80
+ */
81
+ export declare function emitSnippetBoardEvent(descriptor: CompositeUiDescriptor, sourceReceiptId: string, event: string, data: unknown, deliver: (targetReceiptId: string, action: string, data: unknown) => void): void;
62
82
  //# sourceMappingURL=board.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"board.d.ts","sourceRoot":"","sources":["../../../src/src/code-mode/board.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,yBAAyB,CAAC;AAMjC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AACpE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AACzE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AAExD,+EAA+E;AAC/E,eAAO,MAAM,uBAAuB,8BAA8B,CAAC;AAEnE,0FAA0F;AAC1F,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC1C;AAED,4FAA4F;AAC5F,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OA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AAE,CAAC,KAAK,EAAE,YAAY,KAAK,gBAAgB,GAAG,SAAS,CAAC;CAC9E;AAcD;;;;;;;;;;;GAWG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,OAAO,GAAG,YAAY,EAAE,CAajE;AAED,0EAA0E;AAC1E,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,OAAO,GAAG,UAAU,EAAE,CAmBlE;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,OAAO,EACf,OAAO,GAAE,mBAAwB,GAChC,qBAAqB,CAuCvB;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CACnC,UAAU,EAAE,qBAAqB,EACjC,eAAe,EAAE,MAAM,EACvB,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,OAAO,EACb,OAAO,EAAE,CAAC,eAAe,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,KAAK,IAAI,GACxE,IAAI,CAoBN"}
@@ -6,6 +6,13 @@ import "../../_dnt.polyfills.js";
6
6
  import { createCollector } from "../core/collector/collector.js";
7
7
  import { extractUiMeta } from "../core/collector/extractor.js";
8
8
  import { buildCompositeUi } from "../core/composer/composer.js";
9
+ import { parseSnippetSyncRule, readSnippetEventPorts, SNIPPET_SYNC_META_KEY, snippetSyncKey, supportsSnippetSync, } from "./sync.js";
10
+ export { SNIPPET_SYNC_META_KEY };
11
+ export { createPanelContexts, } from "./panel-contexts.js";
12
+ export { connectSnippetBoardLayout, } from "./layout-publisher.js";
13
+ export { getPanelControlsCss } from "../host/renderer/css/panel-controls.js";
14
+ export { isPanelLayoutSnapshot } from "./layout.js";
15
+ export { capturePanelLayout, installPanelMovement, installPanelResizing, restorePanelLayout, } from "../host/renderer/panel-controls.js";
9
16
  /** MCP App result metadata containing the receipts selected by the program. */
10
17
  export const SNIPPET_PANELS_META_KEY = "io.mcpview/snippet-panels";
11
18
  function record(value) {
@@ -46,6 +53,33 @@ export function readSnippetPanels(result) {
46
53
  }
47
54
  return panels;
48
55
  }
56
+ /** Read unique, declared Compose routes between panels in this result. */
57
+ export function readSnippetSyncRules(result) {
58
+ if (!record(result) || !record(result._meta))
59
+ return [];
60
+ const routes = result._meta[SNIPPET_SYNC_META_KEY];
61
+ const items = result._meta[SNIPPET_PANELS_META_KEY];
62
+ if (!Array.isArray(routes) || !Array.isArray(items))
63
+ return [];
64
+ const panels = new Map();
65
+ const duplicates = new Set();
66
+ for (const item of items) {
67
+ if (!isPanel(item))
68
+ continue;
69
+ if (panels.has(item.id))
70
+ duplicates.add(item.id);
71
+ panels.set(item.id, readSnippetEventPorts(item.events));
72
+ }
73
+ for (const id of duplicates)
74
+ panels.delete(id);
75
+ const rules = new Map();
76
+ for (const item of routes) {
77
+ const rule = parseSnippetSyncRule(item);
78
+ if (rule && supportsSnippetSync(rule, panels))
79
+ rules.set(snippetSyncKey(rule), rule);
80
+ }
81
+ return [...rules.values()];
82
+ }
49
83
  /**
50
84
  * Build a Compose descriptor from the current execution, without making any provider calls.
51
85
  * Each child keeps its receipt in `context.panel` and adapter data in `context.view`.
@@ -67,20 +101,60 @@ export function composeSnippetBoard(result, options = {}) {
67
101
  ? result.structuredContent
68
102
  : {};
69
103
  const collector = createCollector();
104
+ const mountedPorts = new Map();
70
105
  for (const panel of readSnippetPanels(result)) {
71
106
  const view = options.resolveView?.(panel);
72
107
  const resourceUri = view?.resourceUri ?? extractUiMeta(panel.result)?.resourceUri;
73
108
  if (!resourceUri || !/^ui:\/\/[^\s]+$/.test(resourceUri))
74
109
  continue;
110
+ const declared = readSnippetEventPorts(panel.events);
111
+ const viewEvents = readSnippetEventPorts(view?.events);
112
+ const panelEvents = view
113
+ ? {
114
+ emits: declared?.emits?.filter((name) => viewEvents?.emits?.includes(name)),
115
+ accepts: declared?.accepts?.filter((name) => viewEvents?.accepts?.includes(name)),
116
+ }
117
+ : declared;
118
+ mountedPorts.set(panel.id, panelEvents);
75
119
  collector.collect(`${panel.provider}:${panel.name}`, { _meta: { ui: { resourceUri } } }, {
76
120
  panel,
121
+ panelEvents,
77
122
  ...(view?.context === undefined ? {} : { view: view.context }),
78
123
  ...(Object.hasOwn(summary, "value") ? { value: summary.value } : {}),
79
- }, { componentId: panel.id, surface: view?.surface });
124
+ }, { componentId: panel.id, surface: view?.surface, supportedWidths: view?.supportedWidths });
80
125
  }
81
126
  const resources = collector.getResources();
82
127
  const layout = typeof options.layout === "function"
83
128
  ? options.layout(resources.length)
84
129
  : options.layout;
85
- return buildCompositeUi(resources, { layout: layout ?? "stack", sharedContext: ["value"] });
130
+ const sync = readSnippetSyncRules(result).filter((rule) => supportsSnippetSync(rule, mountedPorts));
131
+ return buildCompositeUi(resources, { layout: layout ?? "stack", sharedContext: ["value"], sync });
132
+ }
133
+ /**
134
+ * Deliver a JSON event through the current board's declared routes to mounted views.
135
+ * The board owns dispatch and supplies the receipts and data from its active UI.
136
+ */
137
+ export function emitSnippetBoardEvent(descriptor, sourceReceiptId, event, data, deliver) {
138
+ const source = descriptor.children.find((child) => child.componentId === sourceReceiptId);
139
+ if (!source || !readSnippetEventPorts(source.context?.panelEvents)?.emits?.includes(event)) {
140
+ return;
141
+ }
142
+ let payload;
143
+ try {
144
+ payload = JSON.stringify(data);
145
+ }
146
+ catch {
147
+ return;
148
+ }
149
+ if (payload === undefined || payload.length > 128 * 1024)
150
+ return;
151
+ for (const rule of descriptor.sync) {
152
+ if (rule.from !== source.slot || rule.event !== event || rule.to === "*")
153
+ continue;
154
+ const target = descriptor.children.find((child) => child.slot === rule.to);
155
+ const ports = readSnippetEventPorts(target?.context?.panelEvents);
156
+ if (target?.componentId && ports?.accepts?.includes(rule.action)) {
157
+ deliver(target.componentId, rule.action, JSON.parse(payload));
158
+ }
159
+ }
86
160
  }
@@ -1,5 +1,6 @@
1
1
  import type { CallToolResult } from "@modelcontextprotocol/client";
2
2
  import type { SnippetCatalog } from "@mcpview/server/snippets";
3
+ import type { ViewComponentEventPorts } from "../core/types/components.js";
3
4
  import { type SnippetChainContext, type SnippetProvider } from "./providers.js";
4
5
  /** Selected native result, available only to the MCP App in result metadata. */
5
6
  export interface SnippetPanelReceipt {
@@ -8,6 +9,7 @@ export interface SnippetPanelReceipt {
8
9
  name: string;
9
10
  title: string;
10
11
  result: CallToolResult;
12
+ events?: ViewComponentEventPorts;
11
13
  }
12
14
  /** Execute input from the MCP tool using trusted context supplied separately by the host. */
13
15
  export type SnippetChainExecutor = (input: Record<string, unknown>, context?: SnippetChainContext) => Promise<CallToolResult>;
@@ -1 +1 @@
1
- {"version":3,"file":"chain.d.ts","sourceRoot":"","sources":["../../../src/src/code-mode/chain.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,KAAK,EAAE,cAAc,EAAqB,MAAM,0BAA0B,CAAC;AAElF,OAAO,EAAiB,KAAK,mBAAmB,EAAE,KAAK,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAI/F,gFAAgF;AAChF,MAAM,WAAW,mBAAmB;IAClC,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,cAAc,CAAC;CACxB;AAqED,6FAA6F;AAC7F,MAAM,MAAM,oBAAoB,GAAG,CACjC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC9B,OAAO,CAAC,EAAE,mBAAmB,KAC1B,OAAO,CAAC,cAAc,CAAC,CAAC;AAE7B;;;;GAIG;AACH,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,WAAW,CAAC,MAAM,EAAE,eAAe,CAAC,EAC/C,OAAO,CAAC,EAAE,cAAc,GACvB,oBAAoB,CAyMtB"}
1
+ {"version":3,"file":"chain.d.ts","sourceRoot":"","sources":["../../../src/src/code-mode/chain.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,KAAK,EAAE,cAAc,EAAqB,MAAM,0BAA0B,CAAC;AAClF,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAU3E,OAAO,EAAiB,KAAK,mBAAmB,EAAE,KAAK,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAI/F,gFAAgF;AAChF,MAAM,WAAW,mBAAmB;IAClC,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,cAAc,CAAC;IACvB,MAAM,CAAC,EAAE,uBAAuB,CAAC;CAClC;AAyED,6FAA6F;AAC7F,MAAM,MAAM,oBAAoB,GAAG,CACjC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC9B,OAAO,CAAC,EAAE,mBAAmB,KAC1B,OAAO,CAAC,cAAc,CAAC,CAAC;AAE7B;;;;GAIG;AACH,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,WAAW,CAAC,MAAM,EAAE,eAAe,CAAC,EAC/C,OAAO,CAAC,EAAE,cAAc,GACvB,oBAAoB,CA+NtB"}
@@ -1,3 +1,4 @@
1
+ import { parseSnippetSyncRule, SNIPPET_SYNC_META_KEY, snippetPorts, snippetSyncKey, supportsSnippetSync, } from "./sync.js";
1
2
  import { SNIPPET_PANELS_META_KEY } from "./board.js";
2
3
  import { isSnippetName } from "./providers.js";
3
4
  import { encodeValue, runProgram } from "./sandbox.js";
@@ -39,16 +40,19 @@ function validateParams(input, shape) {
39
40
  }
40
41
  return input;
41
42
  }
42
- function output(value, panels = [], saved) {
43
+ function output(value, panels = [], saved, sync = []) {
43
44
  const visible = {
44
45
  value,
45
- panels: panels.map(({ result: _result, ...panel }) => panel),
46
+ panels: panels.map(({ result: _result, events: _events, ...panel }) => panel),
46
47
  ...(saved === undefined ? {} : { saved }),
47
48
  };
48
49
  return {
49
50
  content: [{ type: "text", text: JSON.stringify(visible) }],
50
51
  structuredContent: visible,
51
- _meta: { [SNIPPET_PANELS_META_KEY]: panels },
52
+ _meta: {
53
+ [SNIPPET_PANELS_META_KEY]: panels,
54
+ ...(sync.length ? { [SNIPPET_SYNC_META_KEY]: sync } : {}),
55
+ },
52
56
  };
53
57
  }
54
58
  /**
@@ -63,6 +67,8 @@ export function createSnippetChain(providers, catalog) {
63
67
  async function execute(code, params, context, status) {
64
68
  const receipts = new Map();
65
69
  const selected = new Map();
70
+ const exposedPorts = new Map();
71
+ const sync = new Map();
66
72
  let totalBytes = 0;
67
73
  const value = await runProgram(code, params, async (operation, args, signal) => {
68
74
  signal.throwIfAborted();
@@ -75,6 +81,18 @@ export function createSnippetChain(providers, catalog) {
75
81
  throw new Error("Panel titles may contain at most 120 characters.");
76
82
  }
77
83
  selected.set(panel.id, { ...panel, title: second ?? panel.title });
84
+ exposedPorts.set(panel.id, panel.events);
85
+ return null;
86
+ }
87
+ if (operation === "sync") {
88
+ const rule = args.length === 1 ? parseSnippetSyncRule(first) : undefined;
89
+ if (!rule || !supportsSnippetSync(rule, exposedPorts)) {
90
+ status.diagnostic =
91
+ "Sync requires distinct selected panel receipts and their declared event and action.";
92
+ throw new Error(status.diagnostic);
93
+ }
94
+ const key = snippetSyncKey(rule);
95
+ sync.set(key, rule);
78
96
  return null;
79
97
  }
80
98
  const provider = typeof first === "string" ? providers.get(first) : undefined;
@@ -114,10 +132,18 @@ export function createSnippetChain(providers, catalog) {
114
132
  throw new Error("Native snippet receipts exceed the board size limit.");
115
133
  }
116
134
  const id = crypto.randomUUID();
117
- receipts.set(id, { id, provider: first, name: second, title: second, result });
135
+ const events = snippetPorts(provider.events, second);
136
+ receipts.set(id, {
137
+ id,
138
+ provider: first,
139
+ name: second,
140
+ title: second,
141
+ result,
142
+ ...(events ? { events } : {}),
143
+ });
118
144
  return { id, value };
119
145
  }, context.signal);
120
- return { value, panels: [...selected.values()] };
146
+ return { value, panels: [...selected.values()], sync: [...sync.values()] };
121
147
  }
122
148
  async function call(input, context, status) {
123
149
  const { signal, scope } = context;
@@ -131,7 +157,7 @@ export function createSnippetChain(providers, catalog) {
131
157
  throw new Error("Supply a JavaScript function body.");
132
158
  const result = await execute(input.code, validateParams(input.params === undefined ? {} : input.params), context, status);
133
159
  signal?.throwIfAborted();
134
- return output(result.value, result.panels);
160
+ return output(result.value, result.panels, undefined, result.sync);
135
161
  }
136
162
  if (!catalog || typeof scope !== "string" || !scope.trim()) {
137
163
  throw new Error("Saved chains require a configured catalog and a trusted scope.");
@@ -147,7 +173,7 @@ export function createSnippetChain(providers, catalog) {
147
173
  execute: (code, params) => execute(code, params, context, status),
148
174
  });
149
175
  signal?.throwIfAborted();
150
- return output(result.value, result.panels);
176
+ return output(result.value, result.panels, undefined, result.sync);
151
177
  }
152
178
  if (typeof input.code !== "string" || !has("saveAs") || !keysAllowed("code", "saveAs", "params")) {
153
179
  throw new Error("Supply code, replay, or listSaved.");
@@ -199,7 +225,7 @@ export function createSnippetChain(providers, catalog) {
199
225
  const ref = catalog.recordSuccess(scope, input.code, params);
200
226
  const saved = await catalog.save(scope, ref, name);
201
227
  reserved = false;
202
- return output(result.value, result.panels, saved.name);
228
+ return output(result.value, result.panels, saved.name, result.sync);
203
229
  }
204
230
  finally {
205
231
  usage.saving.delete(name);
@@ -6,6 +6,7 @@ export type SnippetMcpClient = Pick<Client, "callTool">;
6
6
  export type SnippetProviderBinding = {
7
7
  readonly alias: string;
8
8
  readonly snippets: readonly string[];
9
+ readonly events?: SnippetProvider["events"];
9
10
  } & ({
10
11
  readonly url: URL | string;
11
12
  readonly requestInit?: RequestInit;
@@ -1 +1 @@
1
- {"version":3,"file":"connections.d.ts","sourceRoot":"","sources":["../../../src/src/code-mode/connections.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAiC,MAAM,8BAA8B,CAAC;AACrF,OAAO,EAGL,KAAK,mBAAmB,EACxB,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}) {
81
81
  const clientSource = source;
82
82
  const provider = {
83
83
  names,
84
+ events: binding.events,
84
85
  async call(tool, args, signal, context) {
85
86
  signal.throwIfAborted();
86
87
  if (closing)