@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
@@ -0,0 +1,118 @@
1
+ "use strict";
2
+ /** Aggregate panel selections and board receipts for a single MCP Apps host. @module */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.createPanelContexts = createPanelContexts;
5
+ /** One host snapshot contains the acknowledged selections of every mounted panel. */
6
+ function createPanelContexts(send, clearErrorMessage = () => "Context not updated") {
7
+ const board = Symbol("layout receipt");
8
+ let active = new Map();
9
+ // A lost acknowledgement leaves the host snapshot unknown. Retain only the
10
+ // formats to clear on the next replacement, never the attempted selection.
11
+ let uncertain;
12
+ function liveSelections() {
13
+ return new Map([...active].filter(([, selection]) => !selection.signal.aborted));
14
+ }
15
+ let queued = Promise.resolve();
16
+ function enqueue(work) {
17
+ const next = queued.then(work);
18
+ queued = next.catch(() => { });
19
+ return next;
20
+ }
21
+ function hasSelection(value) {
22
+ return Boolean(value.content?.length ||
23
+ Object.keys(value.structuredContent ?? {}).length);
24
+ }
25
+ function businessSelection(entries, last, boardMetadata) {
26
+ if (entries.length === 0)
27
+ return last;
28
+ if (entries.length === 1) {
29
+ const only = entries[0].value;
30
+ const overlap = boardMetadata &&
31
+ Object.keys(only.structuredContent ?? {}).some((key) => Object.hasOwn(boardMetadata, key));
32
+ if (!overlap)
33
+ return only;
34
+ }
35
+ const content = entries.flatMap(({ value }) => value.content ?? []);
36
+ const panels = entries.flatMap(({ title, value }) => value.structuredContent ? [{ title, context: value.structuredContent }] : []);
37
+ return {
38
+ ...(entries.some(({ value }) => value.content !== undefined) ? { content } : {}),
39
+ ...(panels.length ? { structuredContent: { panels } } : {}),
40
+ };
41
+ }
42
+ function merge(next, last) {
43
+ const receipt = next.get(board)?.value;
44
+ if (!receipt)
45
+ return businessSelection([...next.values()], last);
46
+ const business = businessSelection([...next].filter(([key]) => key !== board).map(([, entry]) => entry), {}, receipt.structuredContent);
47
+ return {
48
+ ...(business.structuredContent || receipt.structuredContent ||
49
+ last.structuredContent
50
+ ? {
51
+ structuredContent: {
52
+ ...business.structuredContent,
53
+ ...receipt.structuredContent,
54
+ },
55
+ }
56
+ : {}),
57
+ ...(business.content || receipt.content || last.content
58
+ ? { content: [...(business.content ?? []), ...(receipt.content ?? [])] }
59
+ : {}),
60
+ };
61
+ }
62
+ async function replace(next, last, options) {
63
+ const update = { ...uncertain, ...merge(next, last) };
64
+ let response;
65
+ try {
66
+ response = await send(update, options);
67
+ }
68
+ catch (cause) {
69
+ uncertain = {
70
+ ...(update.content !== undefined ? { content: [] } : {}),
71
+ ...(update.structuredContent !== undefined ? { structuredContent: {} } : {}),
72
+ };
73
+ throw cause;
74
+ }
75
+ if (!("isError" in response && response.isError)) {
76
+ active = next;
77
+ uncertain = undefined;
78
+ }
79
+ return response;
80
+ }
81
+ function forSource(id, title, signal) {
82
+ return (value, options) => enqueue(async () => {
83
+ signal.throwIfAborted();
84
+ if (id === board && value.structuredContent &&
85
+ Object.hasOwn(value.structuredContent, "panels")) {
86
+ throw new TypeError('Board context reserves "panels" for panel selections');
87
+ }
88
+ const next = liveSelections();
89
+ if (hasSelection(value))
90
+ next.set(id, { title, value, signal });
91
+ else
92
+ next.delete(id);
93
+ return await replace(next, value, options);
94
+ });
95
+ }
96
+ return {
97
+ forPanel: (id, title, signal) => forSource(id, title, signal),
98
+ forBoard: (signal) => forSource(board, "", signal),
99
+ clear() {
100
+ return enqueue(async () => {
101
+ const next = liveSelections();
102
+ if (!uncertain && next.size === active.size)
103
+ return;
104
+ const entries = [...active.values()];
105
+ const empty = {
106
+ ...(entries.some(({ value }) => value.structuredContent !== undefined)
107
+ ? { structuredContent: {} }
108
+ : {}),
109
+ ...(entries.some(({ value }) => value.content !== undefined) ? { content: [] } : {}),
110
+ };
111
+ const response = await replace(next, empty);
112
+ if ("isError" in response && response.isError) {
113
+ throw new Error(clearErrorMessage());
114
+ }
115
+ });
116
+ },
117
+ };
118
+ }
@@ -1,4 +1,5 @@
1
1
  import type { CallToolResult } from "@modelcontextprotocol/client";
2
+ import type { ViewComponentEventPorts } from "../core/types/components.js";
2
3
  /** Trusted, per-request server context, supplied by the host rather than guest code. */
3
4
  export interface SnippetChainContext {
4
5
  /** Catalog partition derived from the authenticated principal and integration. */
@@ -10,6 +11,8 @@ export interface SnippetChainContext {
10
11
  export interface SnippetProvider {
11
12
  /** The subset of this provider's snippets reachable by a program. */
12
13
  readonly names: readonly string[];
14
+ /** Board event ports declared by the host for exact snippet names. */
15
+ readonly events?: Readonly<Record<string, ViewComponentEventPorts>>;
13
16
  /** Forward only these protocol operations with host-owned transport credentials. */
14
17
  call(tool: "list_snippets" | "run_snippet", args: Record<string, unknown>, signal: AbortSignal, context: SnippetChainContext): Promise<CallToolResult>;
15
18
  }
@@ -1 +1 @@
1
- {"version":3,"file":"providers.d.ts","sourceRoot":"","sources":["../../../src/src/code-mode/providers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAEnE,wFAAwF;AACxF,MAAM,WAAW,mBAAmB;IAClC,kFAAkF;IAClF,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,gDAAgD;IAChD,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC;CAC/B;AAED,iGAAiG;AACjG,MAAM,WAAW,eAAe;IAC9B,qEAAqE;IACrE,QAAQ,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,CAAC;IAClC,oFAAoF;IACpF,IAAI,CACF,IAAI,EAAE,eAAe,GAAG,aAAa,EACrC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,MAAM,EAAE,WAAW,EACnB,OAAO,EAAE,mBAAmB,GAC3B,OAAO,CAAC,cAAc,CAAC,CAAC;CAC5B;AAED,6DAA6D;AAC7D,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAEnE;AAED,oFAAoF;AACpF,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAG7D"}
1
+ {"version":3,"file":"providers.d.ts","sourceRoot":"","sources":["../../../src/src/code-mode/providers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAE3E,wFAAwF;AACxF,MAAM,WAAW,mBAAmB;IAClC,kFAAkF;IAClF,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,gDAAgD;IAChD,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC;CAC/B;AAED,iGAAiG;AACjG,MAAM,WAAW,eAAe;IAC9B,qEAAqE;IACrE,QAAQ,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,CAAC;IAClC,sEAAsE;IACtE,QAAQ,CAAC,MAAM,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,uBAAuB,CAAC,CAAC,CAAC;IACpE,oFAAoF;IACpF,IAAI,CACF,IAAI,EAAE,eAAe,GAAG,aAAa,EACrC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,MAAM,EAAE,WAAW,EACnB,OAAO,EAAE,mBAAmB,GAC3B,OAAO,CAAC,cAAc,CAAC,CAAC;CAC5B;AAED,6DAA6D;AAC7D,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAEnE;AAED,oFAAoF;AACpF,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAG7D"}
@@ -1 +1 @@
1
- {"version":3,"file":"sandbox.d.ts","sourceRoot":"","sources":["../../../src/src/code-mode/sandbox.ts"],"names":[],"mappings":"AAEA,oEAAoE;AACpE,eAAO,MAAM,aAAa,QAAS,CAAC;AAIpC,8EAA8E;AAC9E,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,SAAiB,GAAG,MAAM,CAM1E;AAkBD;;;GAGG;AACH,wBAAsB,UAAU,CAC9B,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/B,MAAM,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,MAAM,EAAE,WAAW,KAAK,OAAO,CAAC,OAAO,CAAC,EACrF,YAAY,CAAC,EAAE,WAAW,GACzB,OAAO,CAAC,OAAO,CAAC,CA4HlB"}
1
+ {"version":3,"file":"sandbox.d.ts","sourceRoot":"","sources":["../../../src/src/code-mode/sandbox.ts"],"names":[],"mappings":"AAEA,oEAAoE;AACpE,eAAO,MAAM,aAAa,QAAS,CAAC;AAIpC,8EAA8E;AAC9E,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,SAAiB,GAAG,MAAM,CAM1E;AAkBD;;;GAGG;AACH,wBAAsB,UAAU,CAC9B,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/B,MAAM,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,MAAM,EAAE,WAAW,KAAK,OAAO,CAAC,OAAO,CAAC,EACrF,YAAY,CAAC,EAAE,WAAW,GACzB,OAAO,CAAC,OAAO,CAAC,CA6HlB"}
@@ -111,6 +111,7 @@ async function runProgram(code, params, invoke, callerSignal) {
111
111
  listSnippets: (...args) => call("listSnippets", args),
112
112
  runSnippet: (...args) => call("runSnippet", args),
113
113
  panel: (...args) => call("panel", args),
114
+ sync: (...args) => call("sync", args),
114
115
  });
115
116
  return (async function(api) { "use strict";\n${code}\n})(api);
116
117
  })()`, "mcpview-code-mode.js", { type: "global" })));
@@ -123,7 +124,7 @@ async function runProgram(code, params, invoke, callerSignal) {
123
124
  if (state.type === "fulfilled") {
124
125
  const value = scope.manage(state.value);
125
126
  if (pending.length) {
126
- throw new Error("Await every snippet operation, including api.panel().");
127
+ throw new Error("Await every snippet operation, including api.panel() and api.sync().");
127
128
  }
128
129
  return vm.typeof(value) === "undefined" ? null : read(value);
129
130
  }
@@ -0,0 +1,11 @@
1
+ import type { ViewComponentEventPorts } from "../core/types/components.js";
2
+ import type { UiSyncRule } from "../core/types/sync-rules.js";
3
+ /** App-only metadata for explicit, receipt-scoped Compose rules. */
4
+ export declare const SNIPPET_SYNC_META_KEY = "io.mcpview/snippet-sync";
5
+ export declare function isPortName(value: unknown): value is string;
6
+ export declare function snippetPorts(events: Readonly<Record<string, ViewComponentEventPorts>> | undefined, name: string): ViewComponentEventPorts | undefined;
7
+ export declare function readSnippetEventPorts(value: unknown): ViewComponentEventPorts | undefined;
8
+ export declare function parseSnippetSyncRule(value: unknown): UiSyncRule | undefined;
9
+ export declare function supportsSnippetSync(rule: UiSyncRule, panels: ReadonlyMap<string, ViewComponentEventPorts | undefined>): boolean;
10
+ export declare function snippetSyncKey({ from, event, to, action }: UiSyncRule): string;
11
+ //# sourceMappingURL=sync.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sync.d.ts","sourceRoot":"","sources":["../../../src/src/code-mode/sync.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAC3E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAE9D,oEAAoE;AACpE,eAAO,MAAM,qBAAqB,4BAA4B,CAAC;AAE/D,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAG1D;AAED,wBAAgB,YAAY,CAC1B,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,uBAAuB,CAAC,CAAC,GAAG,SAAS,EACrE,IAAI,EAAE,MAAM,GACX,uBAAuB,GAAG,SAAS,CAGrC;AAED,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,OAAO,GAAG,uBAAuB,GAAG,SAAS,CAQzF;AAED,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,OAAO,GAAG,UAAU,GAAG,SAAS,CAW3E;AAED,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,UAAU,EAChB,MAAM,EAAE,WAAW,CAAC,MAAM,EAAE,uBAAuB,GAAG,SAAS,CAAC,GAC/D,OAAO,CAIT;AAED,wBAAgB,cAAc,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,UAAU,GAAG,MAAM,CAE9E"}
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SNIPPET_SYNC_META_KEY = void 0;
4
+ exports.isPortName = isPortName;
5
+ exports.snippetPorts = snippetPorts;
6
+ exports.readSnippetEventPorts = readSnippetEventPorts;
7
+ exports.parseSnippetSyncRule = parseSnippetSyncRule;
8
+ exports.supportsSnippetSync = supportsSnippetSync;
9
+ exports.snippetSyncKey = snippetSyncKey;
10
+ const validator_js_1 = require("../core/sync/validator.js");
11
+ /** App-only metadata for explicit, receipt-scoped Compose rules. */
12
+ exports.SNIPPET_SYNC_META_KEY = "io.mcpview/snippet-sync";
13
+ function isPortName(value) {
14
+ return typeof value === "string" && value.length > 0 && value.length <= 120 &&
15
+ value.trim() === value && value !== "*";
16
+ }
17
+ function snippetPorts(events, name) {
18
+ if (!events || !Object.hasOwn(events, name))
19
+ return;
20
+ return readSnippetEventPorts(events[name]);
21
+ }
22
+ function readSnippetEventPorts(value) {
23
+ if (value === null || typeof value !== "object" || Array.isArray(value))
24
+ return;
25
+ const ports = value;
26
+ const names = (values) => Array.isArray(values) ? [...new Set(values.filter(isPortName))] : [];
27
+ const emits = names(ports.emits);
28
+ const accepts = names(ports.accepts);
29
+ if (emits.length || accepts.length)
30
+ return { emits, accepts };
31
+ }
32
+ function parseSnippetSyncRule(value) {
33
+ if (value === null || typeof value !== "object" || Array.isArray(value))
34
+ return;
35
+ const fields = ["from", "event", "to", "action"];
36
+ if (Object.keys(value).length !== fields.length || !fields.every((key) => Object.hasOwn(value, key))) {
37
+ return;
38
+ }
39
+ const { from, event, to, action } = value;
40
+ if (!isPortName(from) || !isPortName(event) || !isPortName(to) || !isPortName(action))
41
+ return;
42
+ return { from, event, to, action };
43
+ }
44
+ function supportsSnippetSync(rule, panels) {
45
+ return (0, validator_js_1.validateSyncRules)([rule], [rule.from, rule.to].filter((id) => panels.has(id))).valid &&
46
+ panels.get(rule.from)?.emits?.includes(rule.event) === true &&
47
+ panels.get(rule.to)?.accepts?.includes(rule.action) === true;
48
+ }
49
+ function snippetSyncKey({ from, event, to, action }) {
50
+ return JSON.stringify([from, event, to, action]);
51
+ }
@@ -3,7 +3,7 @@ import type { SnippetProvider } from "./providers.js";
3
3
  /** Configure the single model-facing tool and its MCP Apps board resource. */
4
4
  export interface SnippetExecuteToolOptions {
5
5
  readonly resourceUri: string;
6
- readonly providers: ReadonlyMap<string, Pick<SnippetProvider, "names">>;
6
+ readonly providers: ReadonlyMap<string, Pick<SnippetProvider, "names" | "events">>;
7
7
  /** Enable this when the chain uses a catalog and the host supplies a trusted scope. */
8
8
  readonly savedChains?: boolean;
9
9
  readonly annotations?: MCPTool["annotations"];
@@ -1 +1 @@
1
- {"version":3,"file":"tool.d.ts","sourceRoot":"","sources":["../../../src/src/code-mode/tool.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAGtD,8EAA8E;AAC9E,MAAM,WAAW,yBAAyB;IACxC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,SAAS,EAAE,WAAW,CAAC,MAAM,EAAE,IAAI,CAAC,eAAe,EAAE,OAAO,CAAC,CAAC,CAAC;IACxE,uFAAuF;IACvF,QAAQ,CAAC,WAAW,CAAC,EAAE,OAAO,CAAC;IAC/B,QAAQ,CAAC,WAAW,CAAC,EAAE,OAAO,CAAC,aAAa,CAAC,CAAC;CAC/C;AAED,0EAA0E;AAC1E,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,yBAAyB,GAAG,OAAO,CAqDpF"}
1
+ {"version":3,"file":"tool.d.ts","sourceRoot":"","sources":["../../../src/src/code-mode/tool.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAItD,8EAA8E;AAC9E,MAAM,WAAW,yBAAyB;IACxC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,SAAS,EAAE,WAAW,CAAC,MAAM,EAAE,IAAI,CAAC,eAAe,EAAE,OAAO,GAAG,QAAQ,CAAC,CAAC,CAAC;IACnF,uFAAuF;IACvF,QAAQ,CAAC,WAAW,CAAC,EAAE,OAAO,CAAC;IAC/B,QAAQ,CAAC,WAAW,CAAC,EAAE,OAAO,CAAC,aAAa,CAAC,CAAC;CAC/C;AAED,0EAA0E;AAC1E,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,yBAAyB,GAAG,OAAO,CAkEpF"}
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createSnippetExecuteTool = createSnippetExecuteTool;
4
+ const sync_js_1 = require("./sync.js");
4
5
  const sandbox_js_1 = require("./sandbox.js");
5
6
  /** Build the tool declaration for registration with an MCPView server. */
6
7
  function createSnippetExecuteTool(options) {
@@ -9,6 +10,10 @@ function createSnippetExecuteTool(options) {
9
10
  throw new Error("Supply a ui:// resource URI for the board.");
10
11
  }
11
12
  const available = [...options.providers.keys()];
13
+ const eventPorts = [...options.providers].flatMap(([provider, config]) => config.names.flatMap((snippet) => {
14
+ const ports = (0, sync_js_1.snippetPorts)(config.events, snippet);
15
+ return ports ? [{ provider, snippet, ...ports }] : [];
16
+ }));
12
17
  return {
13
18
  name: "execute",
14
19
  description: [
@@ -17,6 +22,13 @@ function createSnippetExecuteTool(options) {
17
22
  "Configured provider aliases: " + JSON.stringify(available) + ".",
18
23
  "await api.runSnippet(provider, name, input) returns a receipt {id, value}.",
19
24
  "Pass values between calls. Use await api.panel(receipt.id, optionalTitle) for each result to display, in display order. Return a JSON summary.",
25
+ ...(eventPorts.length
26
+ ? [
27
+ "After selecting both panels, use await api.sync({from: source.id, event, to: target.id, action}) to route a UI event between them.",
28
+ "Use the source's declared emits and the target's declared accepts. Available panel event ports: " +
29
+ JSON.stringify(eventPorts) + ".",
30
+ ]
31
+ : []),
20
32
  ...(options.savedChains
21
33
  ? [
22
34
  "Use saveAs to save a successful chain, listSaved to list your saved chains, or replay with the saved name and new params.",
@@ -95,7 +95,7 @@ function generateBodyContent(descriptor, slots) {
95
95
  const widths = (0, resources_js_1.isSupportedWidths)(child.supportedWidths) && child.supportedWidths.length
96
96
  ? ` data-compose-widths="${child.supportedWidths.join(" ")}"`
97
97
  : "";
98
- return `<section class="compose-viewer" data-compose-panel data-panel-label="${escapeAttr(id)}"${area}${widths}>
98
+ return `<section class="compose-viewer" data-compose-panel data-compose-panel-id="${escapeAttr(id)}" data-panel-label="${escapeAttr(id)}"${area}${widths}>
99
99
  ${descriptor.children.length > 1 ? grip(child) : ""}
100
100
  ${generateIframe(child, slots.get(child.slot))}
101
101
  </section>`;
@@ -115,7 +115,7 @@ function generateTabsLayout(descriptor, slots) {
115
115
  </div>`;
116
116
  }
117
117
  const tabButtons = descriptor.children
118
- .map((child, i) => `<div data-compose-panel data-panel-label="${escapeAttr(child.componentId ?? child.source)}">
118
+ .map((child, i) => `<div data-compose-panel data-compose-panel-id="${escapeAttr(child.componentId ?? child.source)}" data-panel-label="${escapeAttr(child.componentId ?? child.source)}">
119
119
  ${descriptor.children.length > 1 ? grip(child) : ""}
120
120
  <button type="button" class="tab${i === 0 ? " active" : ""}" data-slot="${child.slot}">${escapeHtml(child.source)}</button></div>`)
121
121
  .join("\n ");
@@ -1,8 +1,15 @@
1
+ import type { PanelLayoutSnapshot } from "../../code-mode/layout.js";
2
+
1
3
  /** The board element available to a caller running in a DOM environment. */
2
4
  type PanelContainer = typeof globalThis extends { HTMLElement: { prototype: infer Element } }
3
5
  ? Element
4
6
  : never;
5
7
 
8
+ /** Capture the current board's committed choices, keeping the requested widths across viewport changes. */
9
+ export declare function capturePanelLayout(board: PanelContainer): PanelLayoutSnapshot | undefined;
10
+ /** Restore the snapshot in place on a compatible mounted board. */
11
+ export declare function restorePanelLayout(board: PanelContainer, value: unknown): boolean;
12
+
6
13
  /** Install pointer and keyboard controls for moving panels within a Compose board. */
7
14
  export declare function installPanelMovement(container: PanelContainer, signal?: AbortSignal): void;
8
15
 
@@ -1,10 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.installPanelResizing = exports.createPanelReflow = exports.installPanelMovement = void 0;
3
+ exports.installPanelResizing = exports.createPanelReflow = exports.restorePanelLayout = exports.capturePanelLayout = exports.installPanelMovement = void 0;
4
4
  // @ts-self-types="./panel-controls.d.ts"
5
5
  // Server consumers embed these functions in HTML. Only browsers execute their DOM code.
6
6
  var panel_movement_js_1 = require("./panel-movement.js");
7
7
  Object.defineProperty(exports, "installPanelMovement", { enumerable: true, get: function () { return panel_movement_js_1.installPanelMovement; } });
8
+ var panel_snapshot_js_1 = require("./panel-snapshot.js");
9
+ Object.defineProperty(exports, "capturePanelLayout", { enumerable: true, get: function () { return panel_snapshot_js_1.capturePanelLayout; } });
10
+ Object.defineProperty(exports, "restorePanelLayout", { enumerable: true, get: function () { return panel_snapshot_js_1.restorePanelLayout; } });
8
11
  var panel_reflow_js_1 = require("./panel-reflow.js");
9
12
  Object.defineProperty(exports, "createPanelReflow", { enumerable: true, get: function () { return panel_reflow_js_1.createPanelReflow; } });
10
13
  var panel_resizing_js_1 = require("./panel-resizing.js");
@@ -1 +1 @@
1
- {"version":3,"file":"panel-movement.d.ts","sourceRoot":"","sources":["../../../../src/src/host/renderer/panel-movement.js"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,gDAHW,WAAW,0CA+XrB"}
1
+ {"version":3,"file":"panel-movement.d.ts","sourceRoot":"","sources":["../../../../src/src/host/renderer/panel-movement.js"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,gDAHW,WAAW,0CAkYrB"}
@@ -107,6 +107,7 @@ function installPanelMovement(container, signal) {
107
107
  function announceSwap(from, to) {
108
108
  status.textContent = label(from) + " swapped with " + label(to) + ".";
109
109
  container.dispatchEvent(new Event("compose-layout-change"));
110
+ container.dispatchEvent(new Event("compose-panel-layout-committed"));
110
111
  }
111
112
  /** @param {"preview" | "commit" | "cancel"} phase @param {FreePlace} place */
112
113
  function placeBeside(phase, place) {
@@ -276,7 +277,9 @@ function installPanelMovement(container, signal) {
276
277
  return best;
277
278
  }
278
279
  for (const [index, panel] of panels.entries()) {
279
- if (!namedAreas)
280
+ if (namedAreas)
281
+ panel.dataset.composeTemplateArea ??= panel.dataset.area;
282
+ else
280
283
  panel.style.order = String(index);
281
284
  let grip = /** @type {HTMLButtonElement | null} */ (panel.querySelector("[data-compose-grip]"));
282
285
  if (!grip) {
@@ -370,6 +373,7 @@ function installPanelMovement(container, signal) {
370
373
  const where = placement.side === "below" ? " below " : " beside ";
371
374
  status.textContent = label(from) + " placed" + where + label(placement.beside) + ".";
372
375
  container.dispatchEvent(new Event("compose-layout-change"));
376
+ container.dispatchEvent(new Event("compose-panel-layout-committed"));
373
377
  }
374
378
  select();
375
379
  }
@@ -1 +1 @@
1
- {"version":3,"file":"panel-resizing.d.ts","sourceRoot":"","sources":["../../../../src/src/host/renderer/panel-resizing.js"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AACH,gDAJW,WAAW,+FAuVrB;kCA7ViC,mBAAmB"}
1
+ {"version":3,"file":"panel-resizing.d.ts","sourceRoot":"","sources":["../../../../src/src/host/renderer/panel-resizing.js"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AACH,gDAJW,WAAW,+FAoXrB;kCA1XiC,mBAAmB"}
@@ -88,6 +88,7 @@ function installPanelResizing(container, signal, createReflow = panel_reflow_js_
88
88
  function commitWidth(panel, width) {
89
89
  choices.set(panel, width);
90
90
  place();
91
+ container.dispatchEvent(new browser.Event("compose-panel-layout-committed"));
91
92
  status.textContent = (panel.dataset.panelLabel || "Viewer") + " width " + width + " pixels.";
92
93
  }
93
94
  /** @param {KeyboardEvent} event @param {HTMLElement} panel @param {number[]} widths */
@@ -336,7 +337,34 @@ function installPanelResizing(container, signal, createReflow = panel_reflow_js_
336
337
  manualPreview = proposed;
337
338
  schedule();
338
339
  }, { signal });
340
+ // Expose committed preferences to the owning board without touching viewer results or iframes.
341
+ // Symbol.for also connects hosts that embed these controls as standalone JavaScript.
342
+ const slotState = Symbol.for("@mcpview/compose/panel-layout-controls/v1");
343
+ Reflect.set(container, slotState, {
344
+ read: () => ({
345
+ widths: Array.from(choices, ([p, width]) => ({ panel: p.dataset.composePanelId, width })),
346
+ placements: Array.from(placements, ([p, { beside, side }]) => ({
347
+ panel: p.dataset.composePanelId,
348
+ beside: beside.dataset.composePanelId,
349
+ side,
350
+ })),
351
+ }),
352
+ supports: (/** @type {HTMLElement} */ panel, /** @type {number} */ width) => declared.get(panel)?.includes(width) === true,
353
+ restore: (
354
+ /** @type {Array<[HTMLElement, number]>} */ widths,
355
+ /** @type {Array<[HTMLElement, Placement]>} */ positions) => {
356
+ choices.clear();
357
+ for (const [panel, width] of widths)
358
+ choices.set(panel, width);
359
+ placements = new Map(positions);
360
+ lastSlots = panels.map(slot);
361
+ manualPreview = undefined;
362
+ place();
363
+ schedule();
364
+ },
365
+ });
339
366
  signal?.addEventListener("abort", () => {
367
+ Reflect.deleteProperty(container, slotState);
340
368
  cancelDrag?.();
341
369
  observer.disconnect();
342
370
  browser.cancelAnimationFrame(pending);
@@ -0,0 +1,11 @@
1
+ /** Read only the last committed layout preferences.
2
+ * @param {HTMLElement} board
3
+ * @returns {import("../../code-mode/layout.ts").PanelLayoutSnapshot | undefined}
4
+ */
5
+ export function capturePanelLayout(board: HTMLElement): import("../../code-mode/layout.ts").PanelLayoutSnapshot | undefined;
6
+ /** Apply a saved preference only to matching panels and current viewer width declarations.
7
+ * @param {HTMLElement} board
8
+ * @param {unknown} snapshot
9
+ */
10
+ export function restorePanelLayout(board: HTMLElement, snapshot: unknown): boolean;
11
+ //# sourceMappingURL=panel-snapshot.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"panel-snapshot.d.ts","sourceRoot":"","sources":["../../../../src/src/host/renderer/panel-snapshot.js"],"names":[],"mappings":"AAuBA;;;GAGG;AACH,0CAHW,WAAW,GACT,OAAO,2BAA2B,EAAE,mBAAmB,GAAG,SAAS,CAe/E;AAED;;;GAGG;AACH,0CAHW,WAAW,YACX,OAAO,WA2BjB"}
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.capturePanelLayout = capturePanelLayout;
4
+ exports.restorePanelLayout = restorePanelLayout;
5
+ const layout_js_1 = require("../../code-mode/layout.js");
6
+ const slotState = Symbol.for("@mcpview/compose/panel-layout-controls/v1");
7
+ /** @param {HTMLElement} board */
8
+ function panelSlots(board) {
9
+ const panels = Array.from(
10
+ /** @type {NodeListOf<HTMLElement>} */ (board.querySelectorAll(":scope > [data-compose-panel]")));
11
+ const ids = panels.map((node) => node.dataset.composePanelId);
12
+ if (!ids.every(Boolean) || new Set(ids).size !== ids.length)
13
+ return;
14
+ const named = panels.every((node) => node.dataset.area);
15
+ // Named areas follow the template even when the viewport changes its number of columns.
16
+ const slots = panels.map((node, i) => named ? node.dataset.composeTemplateArea ?? node.dataset.area ?? "" : String(i));
17
+ if (new Set(slots).size !== slots.length)
18
+ return;
19
+ return { panels, slots, named, byId: new Map(panels.map((p) => [p.dataset.composePanelId, p])) };
20
+ }
21
+ /** Read only the last committed layout preferences.
22
+ * @param {HTMLElement} board
23
+ * @returns {import("../../code-mode/layout.ts").PanelLayoutSnapshot | undefined}
24
+ */
25
+ function capturePanelLayout(board) {
26
+ if (board.hasAttribute("data-compose-dragging"))
27
+ return;
28
+ const table = panelSlots(board);
29
+ if (!table)
30
+ return;
31
+ const { panels, named, slots } = table;
32
+ const occupants = new Map(panels.map((panel, i) => [
33
+ named ? panel.dataset.area : (panel.style.order || String(i)),
34
+ panel.dataset.composePanelId,
35
+ ]));
36
+ const controls = Reflect.get(board, slotState);
37
+ const geometry = controls?.read() ?? { widths: [], placements: [] };
38
+ const snapshot = { version: 1, order: slots.map((slot) => occupants.get(slot)), ...geometry };
39
+ return (0, layout_js_1.isPanelLayoutSnapshot)(snapshot) ? snapshot : undefined;
40
+ }
41
+ /** Apply a saved preference only to matching panels and current viewer width declarations.
42
+ * @param {HTMLElement} board
43
+ * @param {unknown} snapshot
44
+ */
45
+ function restorePanelLayout(board, snapshot) {
46
+ if (!(0, layout_js_1.isPanelLayoutSnapshot)(snapshot) || board.hasAttribute("data-compose-dragging"))
47
+ return false;
48
+ const table = panelSlots(board);
49
+ if (!table || snapshot.order.length !== table.panels.length ||
50
+ !snapshot.order.every((id) => table.byId.has(id)))
51
+ return false;
52
+ const controls = Reflect.get(board, slotState);
53
+ if ((snapshot.widths.length || snapshot.placements.length) && !controls)
54
+ return false;
55
+ if (!snapshot.widths.every(({ panel, width }) => controls?.supports(table.byId.get(panel), width)))
56
+ return false;
57
+ snapshot.order.forEach((id, index) => {
58
+ const panel = /** @type {HTMLElement} */ (table.byId.get(id));
59
+ if (table.named)
60
+ panel.dataset.area = table.slots[index];
61
+ else
62
+ panel.style.order = table.slots[index];
63
+ });
64
+ controls?.restore(snapshot.widths.map(({ panel, width }) => [table.byId.get(panel), width]), snapshot.placements.map(({ panel, beside, side }) => [
65
+ table.byId.get(panel),
66
+ { beside: table.byId.get(beside), side },
67
+ ]));
68
+ return true;
69
+ }
@@ -17,7 +17,7 @@
17
17
  * @module lib/version
18
18
  */
19
19
  /** @mcpview/compose package version. */
20
- export declare const COMPOSE_VERSION: "0.13.0";
20
+ export declare const COMPOSE_VERSION: "0.13.1";
21
21
  /**
22
22
  * MCP Apps protocol version targeted by compose.
23
23
  *
@@ -20,7 +20,7 @@
20
20
  Object.defineProperty(exports, "__esModule", { value: true });
21
21
  exports.MCP_APPS_PROTOCOL_VERSION = exports.COMPOSE_VERSION = void 0;
22
22
  /** @mcpview/compose package version. */
23
- exports.COMPOSE_VERSION = "0.13.0";
23
+ exports.COMPOSE_VERSION = "0.13.1";
24
24
  /**
25
25
  * MCP Apps protocol version targeted by compose.
26
26
  *