@mcpview/compose 0.13.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 (101) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/README.md +79 -2
  3. package/esm/_dnt.polyfills.d.ts +11 -11
  4. package/esm/_dnt.polyfills.d.ts.map +1 -1
  5. package/esm/_dnt.polyfills.js +14 -14
  6. package/esm/src/code-mode/board.d.ts +18 -2
  7. package/esm/src/code-mode/board.d.ts.map +1 -1
  8. package/esm/src/code-mode/board.js +74 -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/host/renderer/html-generator.js +2 -2
  41. package/esm/src/host/renderer/panel-controls.d.ts +7 -0
  42. package/esm/src/host/renderer/panel-controls.js +1 -0
  43. package/esm/src/host/renderer/panel-movement.d.ts.map +1 -1
  44. package/esm/src/host/renderer/panel-movement.js +5 -1
  45. package/esm/src/host/renderer/panel-resizing.d.ts.map +1 -1
  46. package/esm/src/host/renderer/panel-resizing.js +28 -0
  47. package/esm/src/host/renderer/panel-snapshot.d.ts +11 -0
  48. package/esm/src/host/renderer/panel-snapshot.d.ts.map +1 -0
  49. package/esm/src/host/renderer/panel-snapshot.js +65 -0
  50. package/esm/src/version.d.ts +1 -1
  51. package/esm/src/version.js +1 -1
  52. package/package.json +9 -1
  53. package/script/_dnt.polyfills.d.ts +11 -11
  54. package/script/_dnt.polyfills.d.ts.map +1 -1
  55. package/script/_dnt.polyfills.js +14 -14
  56. package/script/src/code-mode/board.d.ts +18 -2
  57. package/script/src/code-mode/board.d.ts.map +1 -1
  58. package/script/src/code-mode/board.js +81 -2
  59. package/script/src/code-mode/chain.d.ts +2 -0
  60. package/script/src/code-mode/chain.d.ts.map +1 -1
  61. package/script/src/code-mode/chain.js +34 -8
  62. package/script/src/code-mode/connections.d.ts +1 -0
  63. package/script/src/code-mode/connections.d.ts.map +1 -1
  64. package/script/src/code-mode/connections.js +1 -0
  65. package/script/src/code-mode/layout-publisher.d.ts +69 -0
  66. package/script/src/code-mode/layout-publisher.d.ts.map +1 -0
  67. package/script/src/code-mode/layout-publisher.js +88 -0
  68. package/script/src/code-mode/layout-runs.d.ts +35 -0
  69. package/script/src/code-mode/layout-runs.d.ts.map +1 -0
  70. package/script/src/code-mode/layout-runs.js +134 -0
  71. package/script/src/code-mode/layout.d.ts +20 -0
  72. package/script/src/code-mode/layout.d.ts.map +1 -0
  73. package/script/src/code-mode/layout.js +57 -0
  74. package/script/src/code-mode/mod.d.ts +1 -0
  75. package/script/src/code-mode/mod.d.ts.map +1 -1
  76. package/script/src/code-mode/mod.js +6 -1
  77. package/script/src/code-mode/panel-contexts.d.ts +25 -0
  78. package/script/src/code-mode/panel-contexts.d.ts.map +1 -0
  79. package/script/src/code-mode/panel-contexts.js +118 -0
  80. package/script/src/code-mode/providers.d.ts +3 -0
  81. package/script/src/code-mode/providers.d.ts.map +1 -1
  82. package/script/src/code-mode/sandbox.d.ts.map +1 -1
  83. package/script/src/code-mode/sandbox.js +2 -1
  84. package/script/src/code-mode/sync.d.ts +11 -0
  85. package/script/src/code-mode/sync.d.ts.map +1 -0
  86. package/script/src/code-mode/sync.js +51 -0
  87. package/script/src/code-mode/tool.d.ts +1 -1
  88. package/script/src/code-mode/tool.d.ts.map +1 -1
  89. package/script/src/code-mode/tool.js +12 -0
  90. package/script/src/host/renderer/html-generator.js +2 -2
  91. package/script/src/host/renderer/panel-controls.d.ts +7 -0
  92. package/script/src/host/renderer/panel-controls.js +4 -1
  93. package/script/src/host/renderer/panel-movement.d.ts.map +1 -1
  94. package/script/src/host/renderer/panel-movement.js +5 -1
  95. package/script/src/host/renderer/panel-resizing.d.ts.map +1 -1
  96. package/script/src/host/renderer/panel-resizing.js +28 -0
  97. package/script/src/host/renderer/panel-snapshot.d.ts +11 -0
  98. package/script/src/host/renderer/panel-snapshot.d.ts.map +1 -0
  99. package/script/src/host/renderer/panel-snapshot.js +69 -0
  100. package/script/src/version.d.ts +1 -1
  101. package/script/src/version.js +1 -1
package/CHANGELOG.md CHANGED
@@ -5,6 +5,17 @@ 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
+
8
19
  ## [0.13.0] - 2026-11-27
9
20
 
10
21
  ### 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
@@ -240,8 +262,63 @@ Drag the bottom-right corner to preview an allowed width. At the right edge of t
240
262
  to reach a wider format. The skeleton reserves the space and neighbors shift sideways or wrap to a
241
263
  new row. When the viewer shrinks, its neighbor returns beside it with the template's original gap as
242
264
  soon as both fit. Release to apply the width or press Escape to cancel. The left and right arrow
243
- keys step between available widths when the corner has focus. Reopening the dashboard restores the
244
- template layout. Each iframe stays mounted and reports its own content height as its width changes.
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.
245
322
 
246
323
  For a Code Mode board with local renderers, `@mcpview/compose/code-mode/board` exports
247
324
  `getPanelControlsCss()`, `installPanelMovement(board, signal?)` and
@@ -1,3 +1,14 @@
1
+ declare global {
2
+ interface Object {
3
+ /**
4
+ * Determines whether an object has a property with the specified name.
5
+ * @param o An object.
6
+ * @param v A property name.
7
+ */
8
+ hasOwn(o: object, v: PropertyKey): boolean;
9
+ }
10
+ }
11
+ export {};
1
12
  declare global {
2
13
  interface Array<T> {
3
14
  /**
@@ -47,17 +58,6 @@ declare global {
47
58
  }
48
59
  }
49
60
  export {};
50
- declare global {
51
- interface Object {
52
- /**
53
- * Determines whether an object has a property with the specified name.
54
- * @param o An object.
55
- * @param v A property name.
56
- */
57
- hasOwn(o: object, v: PropertyKey): boolean;
58
- }
59
- }
60
- export {};
61
61
  declare global {
62
62
  interface Error {
63
63
  cause?: unknown;
@@ -1 +1 @@
1
- {"version":3,"file":"_dnt.polyfills.d.ts","sourceRoot":"","sources":["../src/_dnt.polyfills.ts"],"names":[],"mappings":"AACA,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,KAAK,CAAC,CAAC;QACf;;;;;;;;WAQG;QACH,QAAQ,CAAC,CAAC,SAAS,CAAC,EAClB,SAAS,EAAE,CAAC,IAAI,EAAE,IAAI,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CAAC,SAAS,MAAM,EACvB,SAAS,EAAE,CACP,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,UAAU,KAChB,KAAK,IAAI,CAAC,EACf,OAAO,CAAC,EAAE,GAAG,GACZ,CAAC,GAAG,SAAS,CAAC;QACjB,QAAQ,CACJ,SAAS,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,KAAK,OAAO,EACvE,OAAO,CAAC,EAAE,GAAG,GACd,MAAM,GAAG,SAAS,CAAC;QAEtB;;;;;;;;WAQG;QACH,aAAa,CACT,SAAS,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,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"}
@@ -1,3 +1,17 @@
1
+ // https://github.com/tc39/proposal-accessible-object-hasownproperty/blob/main/polyfill.js
2
+ if (!Object.hasOwn) {
3
+ Object.defineProperty(Object, "hasOwn", {
4
+ value: function (object, property) {
5
+ if (object == null) {
6
+ throw new TypeError("Cannot convert undefined or null to object");
7
+ }
8
+ return Object.prototype.hasOwnProperty.call(Object(object), property);
9
+ },
10
+ configurable: true,
11
+ enumerable: false,
12
+ writable: true,
13
+ });
14
+ }
1
15
  function findLastIndex(self, callbackfn, that) {
2
16
  const boundFunc = that === undefined ? callbackfn : callbackfn.bind(that);
3
17
  let index = self.length - 1;
@@ -34,18 +48,4 @@ if (!Uint8Array.prototype.findLast) {
34
48
  return findLast(this, callbackfn, that);
35
49
  };
36
50
  }
37
- // https://github.com/tc39/proposal-accessible-object-hasownproperty/blob/main/polyfill.js
38
- if (!Object.hasOwn) {
39
- Object.defineProperty(Object, "hasOwn", {
40
- value: function (object, property) {
41
- if (object == null) {
42
- throw new TypeError("Cannot convert undefined or null to object");
43
- }
44
- return Object.prototype.hasOwnProperty.call(Object(object), property);
45
- },
46
- configurable: true,
47
- enumerable: false,
48
- writable: true,
49
- });
50
- }
51
51
  export {};
@@ -3,11 +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";
9
14
  export { getPanelControlsCss } from "../host/renderer/css/panel-controls.js";
10
- export { installPanelMovement, installPanelResizing } from "../host/renderer/panel-controls.js";
15
+ export { isPanelLayoutSnapshot, type PanelLayoutSnapshot } from "./layout.js";
16
+ export { capturePanelLayout, installPanelMovement, installPanelResizing, restorePanelLayout, } from "../host/renderer/panel-controls.js";
11
17
  /** MCP App result metadata containing the receipts selected by the program. */
12
18
  export declare const SNIPPET_PANELS_META_KEY = "io.mcpview/snippet-panels";
13
19
  /** A selected provider result. The receipt ID distinguishes calls to the same snippet. */
@@ -17,6 +23,7 @@ export interface SnippetPanel {
17
23
  readonly name: string;
18
24
  readonly title: string;
19
25
  readonly result: Record<string, unknown>;
26
+ readonly events?: ViewComponentEventPorts;
20
27
  }
21
28
  /** An App-owned view for a receipt, with optional renderer data and component selection. */
22
29
  export interface SnippetPanelView {
@@ -25,6 +32,8 @@ export interface SnippetPanelView {
25
32
  readonly surface?: ComponentSurface;
26
33
  /** Widths offered by this local view in CSS pixels. An empty list disables resizing. */
27
34
  readonly supportedWidths?: readonly number[];
35
+ /** Restrict routing to the ports implemented by this local view. */
36
+ readonly events?: ViewComponentEventPorts;
28
37
  }
29
38
  /** Display options supplied by the board hosting the results. */
30
39
  export interface SnippetBoardOptions {
@@ -46,6 +55,8 @@ export interface SnippetBoardOptions {
46
55
  * ```
47
56
  */
48
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[];
49
60
  /**
50
61
  * Build a Compose descriptor from the current execution, without making any provider calls.
51
62
  * Each child keeps its receipt in `context.panel` and adapter data in `context.view`.
@@ -63,4 +74,9 @@ export declare function readSnippetPanels(result: unknown): SnippetPanel[];
63
74
  * ```
64
75
  */
65
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;
66
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,OAAO,EAAE,mBAAmB,EAAE,MAAM,wCAAwC,CAAC;AAC7E,OAA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O,KAAK,IAAI,GACxE,IAAI,CAoBN"}
@@ -6,8 +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";
9
13
  export { getPanelControlsCss } from "../host/renderer/css/panel-controls.js";
10
- export { installPanelMovement, installPanelResizing } from "../host/renderer/panel-controls.js";
14
+ export { isPanelLayoutSnapshot } from "./layout.js";
15
+ export { capturePanelLayout, installPanelMovement, installPanelResizing, restorePanelLayout, } from "../host/renderer/panel-controls.js";
11
16
  /** MCP App result metadata containing the receipts selected by the program. */
12
17
  export const SNIPPET_PANELS_META_KEY = "io.mcpview/snippet-panels";
13
18
  function record(value) {
@@ -48,6 +53,33 @@ export function readSnippetPanels(result) {
48
53
  }
49
54
  return panels;
50
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
+ }
51
83
  /**
52
84
  * Build a Compose descriptor from the current execution, without making any provider calls.
53
85
  * Each child keeps its receipt in `context.panel` and adapter data in `context.view`.
@@ -69,13 +101,24 @@ export function composeSnippetBoard(result, options = {}) {
69
101
  ? result.structuredContent
70
102
  : {};
71
103
  const collector = createCollector();
104
+ const mountedPorts = new Map();
72
105
  for (const panel of readSnippetPanels(result)) {
73
106
  const view = options.resolveView?.(panel);
74
107
  const resourceUri = view?.resourceUri ?? extractUiMeta(panel.result)?.resourceUri;
75
108
  if (!resourceUri || !/^ui:\/\/[^\s]+$/.test(resourceUri))
76
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);
77
119
  collector.collect(`${panel.provider}:${panel.name}`, { _meta: { ui: { resourceUri } } }, {
78
120
  panel,
121
+ panelEvents,
79
122
  ...(view?.context === undefined ? {} : { view: view.context }),
80
123
  ...(Object.hasOwn(summary, "value") ? { value: summary.value } : {}),
81
124
  }, { componentId: panel.id, surface: view?.surface, supportedWidths: view?.supportedWidths });
@@ -84,5 +127,34 @@ export function composeSnippetBoard(result, options = {}) {
84
127
  const layout = typeof options.layout === "function"
85
128
  ? options.layout(resources.length)
86
129
  : options.layout;
87
- 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
+ }
88
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,KAA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AO,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,KAAK,eAAe,EACrB,MAAM,gBAAgB,CAAC;AAExB,mGAAmG;AACnG,MAAM,MAAM,gBAAgB,GAAG,IAAI,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;AAExD,gFAAgF;AAChF,MAAM,MAAM,sBAAsB,GAC9B;IACA,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAC;CACtC,GACC,CAAC;IACD,QAAQ,CAAC,GAAG,EAAE,GAAG,GAAG,MAAM,CAAC;IAC3B,QAAQ,CAAC,WAAW,CAAC,EAAE,WAAW,CAAC;IACnC,QAAQ,CAAC,MAAM,CAAC,EAAE,KAAK,CAAC;CACzB,GAAG;IACF,+EAA+E;IAC/E,QAAQ,CAAC,MAAM,EACX,gBAAgB,GAChB,CAAC,CAAC,OAAO,EAAE,mBAAmB,KAAK,g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ACF,+EAA+E;IAC/E,QAAQ,CAAC,MAAM,EACX,gBAAgB,GAChB,CAAC,CAAC,OAAO,EAAE,mBAAmB,KAAK,gBAAgB,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC,CAAC;IACrF,QAAQ,CAAC,GAAG,CAAC,EAAE,KAAK,CAAC;IACrB,QAAQ,CAAC,WAAW,CAAC,EAAE,KAAK,CAAC;CAC9B,CAAC,CAAC;AAEL,iGAAiG;AACjG,MAAM,WAAW,0BAA0B;IACzC,QAAQ,CAAC,SAAS,EAAE,WAAW,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;IACzD,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB;AAED;;;;;GAKG;AACH,wBAAsB,uBAAuB,CAC3C,QAAQ,EAAE,SAAS,sBAAsB,EAAE,EAC3C,OAAO,GAAE;IAAE,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAA;CAAO,GAC9C,OAAO,CAAC,0BAA0B,CAAC,CAkHrC"}
@@ -81,6 +81,7 @@ export async function connectSnippetProviders(bindings, options = {}) {
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)
@@ -0,0 +1,69 @@
1
+ /** Browser-side transport for user-edited Code Mode dashboard layouts. @module */
2
+ import { capturePanelLayout } from "../host/renderer/panel-controls.js";
3
+ import type { PanelLayoutSnapshot } from "./layout.js";
4
+ /** The conversation receives a reference to the staged geometry. */
5
+ export interface SnippetLayoutReceipt {
6
+ /** Execution reference supplied by the server that owns the snippet. */
7
+ runId: string;
8
+ /** Monotonic revision within this mounted board. */
9
+ revision: number;
10
+ /** Whether the server has acknowledged this revision for saving. */
11
+ status: "pending" | "ready" | "failed";
12
+ }
13
+ /** State available to an App's translated layout feedback and retry controls. */
14
+ export type SnippetLayoutStatus = SnippetLayoutReceipt["status"] | "local" | "restore-failed";
15
+ /** MCP Apps host methods and the board's context writer, which can aggregate panel selections. */
16
+ export interface SnippetBoardLayoutOptions {
17
+ /** Connected MCP App providing the negotiated capabilities and the staging callback. */
18
+ host: {
19
+ getHostCapabilities(): {
20
+ serverTools?: unknown;
21
+ updateModelContext?: {
22
+ structuredContent?: unknown;
23
+ text?: unknown;
24
+ };
25
+ } | undefined;
26
+ callServerTool(params: {
27
+ name: string;
28
+ arguments: {
29
+ runId: string;
30
+ revision: number;
31
+ layout: PanelLayoutSnapshot;
32
+ };
33
+ }, options: {
34
+ signal: AbortSignal;
35
+ }): Promise<{
36
+ structuredContent?: unknown;
37
+ isError?: boolean;
38
+ }>;
39
+ };
40
+ /** The board's context writer, shared with the panels in this App. */
41
+ updateContext(update: {
42
+ structuredContent: {
43
+ snippetLayout: SnippetLayoutReceipt;
44
+ };
45
+ } | {
46
+ content: {
47
+ type: "text";
48
+ text: string;
49
+ }[];
50
+ }): Promise<object>;
51
+ /** App-only callback that stages the geometry and returns the matching run ID and revision. */
52
+ stageTool: string;
53
+ /** Execution metadata from the tool result. Without a reference, edits stay local. */
54
+ runId?: unknown;
55
+ /** Previously saved geometry supplied on replay. */
56
+ savedLayout?: unknown;
57
+ /** Signals the end of this board's display lifetime. */
58
+ signal: AbortSignal;
59
+ /** Receives updates for the App's own feedback, including recoverable errors. */
60
+ onStatus?(status: SnippetLayoutStatus): void;
61
+ }
62
+ /**
63
+ * Install the controls and restore a saved layout on a mounted board. Each
64
+ * committed gesture stages its geometry and publishes an acknowledgement for
65
+ * the next model turn. Pass the board's context writer when other panels share
66
+ * its context. The returned callback retries the current layout after an error.
67
+ */
68
+ export declare function connectSnippetBoardLayout(board: Parameters<typeof capturePanelLayout>[0], { host, updateContext, stageTool, runId, savedLayout, signal, onStatus }: SnippetBoardLayoutOptions): () => Promise<void>;
69
+ //# sourceMappingURL=layout-publisher.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"layout-publisher.d.ts","sourceRoot":"","sources":["../../../src/src/code-mode/layout-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