@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
@@ -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-publisher.ts"],"names":[],"mappings":"AAAA,kFAAkF;AAClF,OAAO,EACL,kBAAkB,EAInB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAEvD,oEAAoE;AACpE,MAAM,WAAW,oBAAoB;IACnC,wEAAwE;IACxE,KAAK,EAAE,MAAM,CAAC;IACd,oDAAoD;IACpD,QAAQ,EAAE,MAAM,CAAC;IACjB,oEAAoE;IACpE,MAAM,EAAE,SAAS,GAAG,OAAO,GAAG,QAAQ,CAAC;CACxC;AAED,iFAAiF;AACjF,MAAM,MAAM,mBAAmB,GAAG,oBAAoB,CAAC,QAAQ,CAAC,GAAG,OAAO,GAAG,gBAAgB,CAAC;AAE9F,kGAAkG;AAClG,MAAM,WAAW,yBAAyB;IACxC,wFAAwF;IACxF,IAAI,EAAE;QACJ,mBAAmB,IAAI;YACrB,WAAW,CAAC,EAAE,OAAO,CAAC;YACtB,kBAAkB,CAAC,EAAE;gBAAE,iBAAiB,CAAC,EAAE,OAAO,CAAC;gBAAC,IAAI,CAAC,EAAE,OAAO,CAAA;aAAE,CAAC;SACtE,GAAG,SAAS,CAAC;QACd,cAAc,CACZ,MAAM,EAAE;YACN,IAAI,EAAE,MAAM,CAAC;YACb,SAAS,EAAE;gBAAE,KAAK,EAAE,MAAM,CAAC;gBAAC,QAAQ,EAAE,MAAM,CAAC;gBAAC,MAAM,EAAE,mBAAmB,CAAA;aAAE,CAAC;SAC7E,EACD,OAAO,EAAE;YAAE,MAAM,EAAE,WAAW,CAAA;SAAE,GAC/B,OAAO,CAAC;YAAE,iBAAiB,CAAC,EAAE,OAAO,CAAC;YAAC,OAAO,CAAC,EAAE,OAAO,CAAA;SAAE,CAAC,CAAC;KAChE,CAAC;IACF,sEAAsE;IACtE,aAAa,CACX,MAAM,EACF;QAAE,iBAAiB,EAAE;YAAE,aAAa,EAAE,oBAAoB,CAAA;SAAE,CAAA;KAAE,GAC9D;QAAE,OAAO,EAAE;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,IAAI,EAAE,MAAM,CAAA;SAAE,EAAE,CAAA;KAAE,GAChD,OAAO,CAAC,MAAM,CAAC,CAAC;IACnB,+FAA+F;IAC/F,SAAS,EAAE,MAAM,CAAC;IAClB,sFAAsF;IACtF,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,oDAAoD;IACpD,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,wDAAwD;IACxD,MAAM,EAAE,WAAW,CAAC;IACpB,iFAAiF;IACjF,QAAQ,CAAC,CAAC,MAAM,EAAE,mBAAmB,GAAG,IAAI,CAAC;CAC9C;AAED;;;;;GAKG;AACH,wBAAgB,yBAAyB,CACvC,KAAK,EAAE,UAAU,CAAC,OAAO,kBAAkB,CAAC,CAAC,CAAC,CAAC,EAC/C,EAAE,IAAI,EAAE,aAAa,EAAE,SAAS,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,QAAQ,EAAE,EACtE,yBAAyB,GAC1B,MAAM,OAAO,CAAC,IAAI,CAAC,CA4ErB"}
@@ -0,0 +1,85 @@
1
+ /** Browser-side transport for user-edited Code Mode dashboard layouts. @module */
2
+ import { capturePanelLayout, installPanelMovement, installPanelResizing, restorePanelLayout, } from "../host/renderer/panel-controls.js";
3
+ /**
4
+ * Install the controls and restore a saved layout on a mounted board. Each
5
+ * committed gesture stages its geometry and publishes an acknowledgement for
6
+ * the next model turn. Pass the board's context writer when other panels share
7
+ * its context. The returned callback retries the current layout after an error.
8
+ */
9
+ export function connectSnippetBoardLayout(board, { host, updateContext, stageTool, runId, savedLayout, signal, onStatus }) {
10
+ installPanelMovement(board, signal);
11
+ installPanelResizing(board, signal);
12
+ if (!signal.aborted && savedLayout !== undefined && !restorePanelLayout(board, savedLayout)) {
13
+ onStatus?.("restore-failed");
14
+ }
15
+ const capabilities = host.getHostCapabilities();
16
+ const formats = capabilities?.updateModelContext;
17
+ const structured = typeof formats?.structuredContent === "object" &&
18
+ formats.structuredContent !== null;
19
+ const text = typeof formats?.text === "object" && formats.text !== null;
20
+ let latest = 0;
21
+ let contextSent = Promise.resolve();
22
+ function sendReceipt(receipt) {
23
+ // Wait for the preceding context write even if the host delivers requests out of order.
24
+ const next = contextSent.then(async () => {
25
+ signal.throwIfAborted();
26
+ if (receipt.status !== "pending" && receipt.revision !== latest)
27
+ return;
28
+ const value = { snippetLayout: receipt };
29
+ // Once sent, an App-wide context update may include live selections from
30
+ // other panels. Let its acknowledgement settle even if this board closes.
31
+ const response = await updateContext(structured
32
+ ? { structuredContent: value }
33
+ : { content: [{ type: "text", text: JSON.stringify(value) }] });
34
+ if ("isError" in response && response.isError)
35
+ throw new Error("Layout receipt rejected");
36
+ });
37
+ contextSent = next.catch(() => { });
38
+ return next;
39
+ }
40
+ async function commit() {
41
+ if (signal.aborted)
42
+ return;
43
+ if (typeof runId !== "string" || !capabilities?.serverTools || !(structured || text)) {
44
+ onStatus?.("local");
45
+ return;
46
+ }
47
+ const layout = capturePanelLayout(board);
48
+ if (!layout) {
49
+ onStatus?.("local");
50
+ return;
51
+ }
52
+ const revision = ++latest;
53
+ const current = () => latest === revision && !signal.aborted;
54
+ onStatus?.("pending");
55
+ try {
56
+ const [staged] = await Promise.all([
57
+ host.callServerTool({ name: stageTool, arguments: { runId, revision, layout } }, {
58
+ signal,
59
+ }),
60
+ sendReceipt({ runId, revision, status: "pending" }),
61
+ ]);
62
+ const ack = staged.structuredContent;
63
+ if (staged.isError || !ack || typeof ack !== "object" ||
64
+ !("runId" in ack) || ack.runId !== runId ||
65
+ !("revision" in ack) || ack.revision !== revision) {
66
+ throw new Error("Layout revision not acknowledged");
67
+ }
68
+ if (!current())
69
+ return;
70
+ await sendReceipt({ runId, revision, status: "ready" });
71
+ if (current())
72
+ onStatus?.("ready");
73
+ }
74
+ catch {
75
+ if (!current())
76
+ return;
77
+ onStatus?.("failed");
78
+ // Leave retry available even when a disconnected host rejects the failure notice.
79
+ await sendReceipt({ runId, revision, status: "failed" }).catch(() => { });
80
+ }
81
+ }
82
+ const events = board;
83
+ events.addEventListener("compose-panel-layout-committed", commit, { signal });
84
+ return commit;
85
+ }
@@ -0,0 +1,35 @@
1
+ /** Scoped layout drafts for saved Code Mode dashboards. @module */
2
+ import "../../_dnt.polyfills.js";
3
+ import { type PanelLayoutSnapshot } from "./layout.js";
4
+ /** Accepted widths per stable panel ID. Use an empty list for a fixed-width viewer. */
5
+ export type PanelWidths = ReadonlyMap<string, readonly number[]>;
6
+ /** Correlate app gestures and explicit snippet saves within a trusted execution scope. */
7
+ export declare class BoardLayoutRuns<Receipt = void> {
8
+ private readonly runs;
9
+ private readonly referenceTtlMs;
10
+ private readonly maxPendingReferences;
11
+ /** Pass the reference lifetime and capacity used by the snippet catalog. */
12
+ constructor(options?: {
13
+ referenceTtlMs?: number;
14
+ maxPendingReferences?: number;
15
+ });
16
+ /** Register a successful run and return the saved layout if it fits today's panel declarations. */
17
+ open(scope: string, runId: string, panels: PanelWidths, replayedName?: string, savedLayout?: unknown): PanelLayoutSnapshot | undefined;
18
+ private find;
19
+ /** Bind the name only after the scoped catalog has successfully saved the program. */
20
+ saved(scope: string, runId: string, name: string): void;
21
+ /** Acknowledge a committed layout, including an identical retry after a lost response. */
22
+ stage(scope: string, runId: unknown, revision: unknown, snapshot: unknown): {
23
+ runId: string;
24
+ revision: number;
25
+ };
26
+ /** Return only acknowledged geometry for save or update. An update must target a bound name. */
27
+ selected(scope: string, runId: string, revision?: unknown, updateName?: string): PanelLayoutSnapshot | undefined;
28
+ /**
29
+ * Apply the explicit update once per named board revision. Retain only the
30
+ * latest receipt per bound name until this execution expires. A failed
31
+ * write can be retried, and an older in-flight write finishes before a newer one.
32
+ */
33
+ commitUpdate(scope: string, runId: string, revision: number, name: string, write: (layout: PanelLayoutSnapshot) => Promise<Receipt>): Promise<Receipt>;
34
+ }
35
+ //# sourceMappingURL=layout-runs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"layout-runs.d.ts","sourceRoot":"","sources":["../../../src/src/code-mode/layout-runs.ts"],"names":[],"mappings":"AAAA,mEAAmE;AACnE,OAAO,yBAAyB,CAAC;AAEjC,OAAO,EAAyB,KAAK,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAE9E,uFAAuF;AACvF,MAAM,MAAM,WAAW,GAAG,WAAW,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC,CAAC;AA0BjE,0FAA0F;AAC1F,qBAAa,eAAe,CAAC,OAAO,GAAG,IAAI;IACzC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAwC;IAC7D,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAS;IACxC,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAAS;IAE9C,4EAA4E;gBAChE,OAAO,GAAE;QAAE,cAAc,CAAC,EAAE,MAAM,CAAC;QAAC,oBAAoB,CAAC,EAAE,MAAM,CAAA;KAAO;IAUpF,mGAAmG;IACnG,IAAI,CACF,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,WAAW,EACnB,YAAY,CAAC,EAAE,MAAM,EACrB,WAAW,CAAC,EAAE,OAAO,GACpB,mBAAmB,GAAG,SAAS;IAuBlC,OAAO,CAAC,IAAI;IAKZ,sFAAsF;IACtF,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI;IAQvD,0FAA0F;IAC1F,KAAK,CACH,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,OAAO,EACd,QAAQ,EAAE,OAAO,EACjB,QAAQ,EAAE,OAAO,GAChB;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE;IAuBtC,gGAAgG;IAChG,QAAQ,CACN,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,EACb,QAAQ,CAAC,EAAE,OAAO,EAClB,UAAU,CAAC,EAAE,MAAM,GAClB,mBAAmB,GAAG,SAAS;IAgBlC;;;;OAIG;IACG,YAAY,CAChB,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,CAAC,MAAM,EAAE,mBAAmB,KAAK,OAAO,CAAC,OAAO,CAAC,GACvD,OAAO,CAAC,OAAO,CAAC;CAiBpB"}
@@ -0,0 +1,130 @@
1
+ /** Scoped layout drafts for saved Code Mode dashboards. @module */
2
+ import "../../_dnt.polyfills.js";
3
+ import { isPanelLayoutSnapshot } from "./layout.js";
4
+ function matchesBoard(value, panels) {
5
+ return isPanelLayoutSnapshot(value) && value.order.length === panels.size &&
6
+ value.order.every((id) => panels.has(id)) &&
7
+ value.widths.every(({ panel, width }) => panels.get(panel)?.includes(width));
8
+ }
9
+ function copyLayout({ order, widths, placements }) {
10
+ return {
11
+ version: 1,
12
+ order: [...order],
13
+ widths: widths.map(({ panel, width }) => ({ panel, width })),
14
+ placements: placements.map(({ panel, beside, side }) => ({ panel, beside, side })),
15
+ };
16
+ }
17
+ /** Correlate app gestures and explicit snippet saves within a trusted execution scope. */
18
+ export class BoardLayoutRuns {
19
+ runs = new Map();
20
+ referenceTtlMs;
21
+ maxPendingReferences;
22
+ /** Pass the reference lifetime and capacity used by the snippet catalog. */
23
+ constructor(options = {}) {
24
+ this.referenceTtlMs = options.referenceTtlMs ?? 10 * 60_000;
25
+ this.maxPendingReferences = options.maxPendingReferences ?? 1024;
26
+ for (const limit of [this.referenceTtlMs, this.maxPendingReferences]) {
27
+ if (!Number.isSafeInteger(limit) || limit <= 0) {
28
+ throw new RangeError("Invalid reference limit");
29
+ }
30
+ }
31
+ }
32
+ /** Register a successful run and return the saved layout if it fits today's panel declarations. */
33
+ open(scope, runId, panels, replayedName, savedLayout) {
34
+ if (!scope.trim() || !runId.trim()) {
35
+ throw new TypeError("Dashboard runs require a scope and run ID");
36
+ }
37
+ const now = Date.now();
38
+ if ((this.runs.get(runId)?.expiresAt ?? 0) > now) {
39
+ throw new Error("Dashboard execution already registered");
40
+ }
41
+ for (const [key, run] of this.runs) {
42
+ if (run.expiresAt > now && this.runs.size < this.maxPendingReferences)
43
+ break;
44
+ this.runs.delete(key);
45
+ }
46
+ const initial = matchesBoard(savedLayout, panels) ? copyLayout(savedLayout) : undefined;
47
+ this.runs.set(runId, {
48
+ scope,
49
+ panels: new Map(Array.from(panels, ([id, widths]) => [id, [...widths]])),
50
+ names: new Map(replayedName === undefined ? [] : [[replayedName, undefined]]),
51
+ initial,
52
+ expiresAt: now + this.referenceTtlMs,
53
+ });
54
+ return initial && copyLayout(initial);
55
+ }
56
+ find(scope, runId) {
57
+ const run = this.runs.get(runId);
58
+ if (run?.scope === scope && run.expiresAt > Date.now())
59
+ return run;
60
+ }
61
+ /** Bind the name only after the scoped catalog has successfully saved the program. */
62
+ saved(scope, runId, name) {
63
+ const run = this.find(scope, runId);
64
+ if (!run || run.names.has(name))
65
+ return;
66
+ // Cap both bound aliases and retained receipts. A dropped alias can be reopened normally.
67
+ if (run.names.size >= 32)
68
+ run.names.delete(run.names.keys().next().value);
69
+ run.names.set(name, undefined);
70
+ }
71
+ /** Acknowledge a committed layout, including an identical retry after a lost response. */
72
+ stage(scope, runId, revision, snapshot) {
73
+ const run = typeof runId === "string" && this.find(scope, runId);
74
+ if (!run || typeof runId !== "string") {
75
+ throw new Error("Dashboard execution expired or unavailable. Reopen the dashboard.");
76
+ }
77
+ if (typeof revision !== "number" || !Number.isSafeInteger(revision) || revision < 1 ||
78
+ !matchesBoard(snapshot, run.panels)) {
79
+ throw new Error("Invalid layout for this dashboard execution.");
80
+ }
81
+ const layout = copyLayout(snapshot);
82
+ if (run.draft && (revision < run.draft.revision ||
83
+ (revision === run.draft.revision &&
84
+ JSON.stringify(layout) !== JSON.stringify(run.draft.layout)))) {
85
+ throw new Error("The dashboard layout revision is stale.");
86
+ }
87
+ run.draft = { revision, layout };
88
+ return { runId, revision };
89
+ }
90
+ /** Return only acknowledged geometry for save or update. An update must target a bound name. */
91
+ selected(scope, runId, revision, updateName) {
92
+ const run = this.find(scope, runId);
93
+ if (revision === undefined && updateName === undefined && !run?.draft) {
94
+ return run?.initial && copyLayout(run.initial);
95
+ }
96
+ if (!run?.draft || revision !== run.draft.revision) {
97
+ throw new Error("Use the latest ready snippetLayout runId and revision from the dashboard.");
98
+ }
99
+ if (updateName !== undefined && !run.names.has(updateName)) {
100
+ throw new Error("This dashboard belongs to a different snippet. Open or save the requested snippet first.");
101
+ }
102
+ return copyLayout(run.draft.layout);
103
+ }
104
+ /**
105
+ * Apply the explicit update once per named board revision. Retain only the
106
+ * latest receipt per bound name until this execution expires. A failed
107
+ * write can be retried, and an older in-flight write finishes before a newer one.
108
+ */
109
+ async commitUpdate(scope, runId, revision, name, write) {
110
+ const layout = this.selected(scope, runId, revision, name);
111
+ if (!layout)
112
+ throw new Error("The dashboard has no acknowledged layout.");
113
+ const run = this.runs.get(runId);
114
+ const previous = run.names.get(name);
115
+ if (previous?.revision === revision)
116
+ return await previous.receipt;
117
+ const receipt = (previous?.receipt ?? Promise.resolve())
118
+ .catch(() => { })
119
+ .then(() => write(layout));
120
+ run.names.set(name, { revision, receipt });
121
+ try {
122
+ return await receipt;
123
+ }
124
+ catch (error) {
125
+ if (run.names.get(name)?.receipt === receipt)
126
+ run.names.set(name, undefined);
127
+ throw error;
128
+ }
129
+ }
130
+ }
@@ -0,0 +1,20 @@
1
+ /** Versioned layout preferences for a Code Mode dashboard. @module */
2
+ /** User-selected panel positions and supported widths, independent of ERP data and chat context. */
3
+ import "../../_dnt.polyfills.js";
4
+ export type PanelLayoutSnapshot = {
5
+ readonly version: 1;
6
+ /** Panel IDs in the template's original slot order. */
7
+ readonly order: readonly string[];
8
+ readonly widths: readonly {
9
+ readonly panel: string;
10
+ readonly width: number;
11
+ }[];
12
+ readonly placements: readonly {
13
+ readonly panel: string;
14
+ readonly beside: string;
15
+ readonly side: "left" | "right" | "below";
16
+ }[];
17
+ };
18
+ /** Validate an untrusted JSON snapshot, including placement anchors and their dependencies. */
19
+ export declare function isPanelLayoutSnapshot(value: unknown): value is PanelLayoutSnapshot;
20
+ //# sourceMappingURL=layout.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"layout.d.ts","sourceRoot":"","sources":["../../../src/src/code-mode/layout.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,oGAAoG;AACpG,OAAO,yBAAyB,CAAC;AAEjC,MAAM,MAAM,mBAAmB,GAAG;IAChC,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC;IACpB,uDAAuD;IACvD,QAAQ,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,CAAC;IAClC,QAAQ,CAAC,MAAM,EAAE,SAAS;QAAE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IAC/E,QAAQ,CAAC,UAAU,EAAE,SAAS;QAC5B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;QACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;QACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,GAAG,OAAO,CAAC;KAC3C,EAAE,CAAC;CACL,CAAC;AAiBF,+FAA+F;AAC/F,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,mBAAmB,CAsClF"}
@@ -0,0 +1,54 @@
1
+ /** Versioned layout preferences for a Code Mode dashboard. @module */
2
+ /** User-selected panel positions and supported widths, independent of ERP data and chat context. */
3
+ import "../../_dnt.polyfills.js";
4
+ // This is a versioned wire format. Only geometry crosses the snippet boundary.
5
+ const maxPanels = 128;
6
+ const maxIdLength = 256;
7
+ function fields(value, keys) {
8
+ return value !== null && typeof value === "object" && !Array.isArray(value) &&
9
+ Object.keys(value).length === keys.length &&
10
+ keys.every((key) => Object.hasOwn(value, key));
11
+ }
12
+ function validId(value) {
13
+ return typeof value === "string" && value.trim().length > 0 && value.length <= maxIdLength &&
14
+ !Array.from(value).some((ch) => ch.charCodeAt(0) < 32);
15
+ }
16
+ /** Validate an untrusted JSON snapshot, including placement anchors and their dependencies. */
17
+ export function isPanelLayoutSnapshot(value) {
18
+ if (!fields(value, ["version", "order", "widths", "placements"]) || value.version !== 1) {
19
+ return false;
20
+ }
21
+ const { order, widths, placements } = value;
22
+ if (!Array.isArray(order) || !order.length || order.length > maxPanels ||
23
+ !Array.isArray(widths) || widths.length > order.length ||
24
+ !Array.isArray(placements) || placements.length >= order.length)
25
+ return false;
26
+ const ids = new Set(order);
27
+ if (ids.size !== order.length || !Array.from(ids).every(validId))
28
+ return false;
29
+ const resized = new Set();
30
+ for (const item of widths) {
31
+ if (!fields(item, ["panel", "width"]) || !ids.has(item.panel) || resized.has(item.panel) ||
32
+ typeof item.width !== "number" || !Number.isSafeInteger(item.width) || item.width <= 0)
33
+ return false;
34
+ resized.add(item.panel);
35
+ }
36
+ const anchors = new Map();
37
+ for (const item of placements) {
38
+ if (!fields(item, ["panel", "beside", "side"]) || !ids.has(item.panel) || !ids.has(item.beside) ||
39
+ anchors.has(item.panel) ||
40
+ (item.side !== "left" && item.side !== "right" && item.side !== "below"))
41
+ return false;
42
+ anchors.set(item.panel, item.beside);
43
+ }
44
+ for (let id of anchors.keys()) {
45
+ const seen = new Set();
46
+ while (anchors.has(id)) {
47
+ if (seen.has(id))
48
+ return false;
49
+ seen.add(id);
50
+ id = anchors.get(id);
51
+ }
52
+ }
53
+ return true;
54
+ }
@@ -5,4 +5,5 @@ export { connectSnippetProviders, type SnippetMcpClient, type SnippetProviderBin
5
5
  export type { SnippetChainContext, SnippetProvider } from "./providers.js";
6
6
  export { createSnippetExecuteTool, type SnippetExecuteToolOptions } from "./tool.js";
7
7
  export { type ProviderSnippetDefinition, registerSnippetProvider, type SnippetProviderOptions, } from "./provider-tools.js";
8
+ export { parseSnippetSyncRule, SNIPPET_SYNC_META_KEY, snippetSyncKey, supportsSnippetSync, } from "./sync.js";
8
9
  //# sourceMappingURL=mod.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../src/src/code-mode/mod.ts"],"names":[],"mappings":"AAAA,wFAAwF;AACxF,OAAO,yBAAyB,CAAC;AAEjC,OAAO,EACL,kBAAkB,EAClB,KAAK,oBAAoB,EACzB,KAAK,mBAAmB,GACzB,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,uBAAuB,EACvB,KAAK,gBAAgB,EACrB,KAAK,sBAAsB,EAC3B,KAAK,0BAA0B,GAChC,MAAM,kBAAkB,CAAC;AAC1B,YAAY,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAC3E,OAAO,EAAE,wBAAwB,EAAE,KAAK,yBAAyB,EAAE,MAAM,WAAW,CAAC;AACrF,OAAO,EACL,KAAK,yBAAyB,EAC9B,uBAAuB,EACvB,KAAK,sBAAsB,GAC5B,MAAM,qBAAqB,CAAC"}
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../src/src/code-mode/mod.ts"],"names":[],"mappings":"AAAA,wFAAwF;AACxF,OAAO,yBAAyB,CAAC;AAEjC,OAAO,EACL,kBAAkB,EAClB,KAAK,oBAAoB,EACzB,KAAK,mBAAmB,GACzB,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,uBAAuB,EACvB,KAAK,gBAAgB,EACrB,KAAK,sBAAsB,EAC3B,KAAK,0BAA0B,GAChC,MAAM,kBAAkB,CAAC;AAC1B,YAAY,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAC3E,OAAO,EAAE,wBAAwB,EAAE,KAAK,yBAAyB,EAAE,MAAM,WAAW,CAAC;AACrF,OAAO,EACL,KAAK,yBAAyB,EAC9B,uBAAuB,EACvB,KAAK,sBAAsB,GAC5B,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EACL,oBAAoB,EACpB,qBAAqB,EACrB,cAAc,EACd,mBAAmB,GACpB,MAAM,WAAW,CAAC"}
@@ -4,3 +4,4 @@ export { createSnippetChain, } from "./chain.js";
4
4
  export { connectSnippetProviders, } from "./connections.js";
5
5
  export { createSnippetExecuteTool } from "./tool.js";
6
6
  export { registerSnippetProvider, } from "./provider-tools.js";
7
+ export { parseSnippetSyncRule, SNIPPET_SYNC_META_KEY, snippetSyncKey, supportsSnippetSync, } from "./sync.js";
@@ -0,0 +1,25 @@
1
+ /** Aggregate panel selections and board receipts for a single MCP Apps host. @module */
2
+ /** Replacement snapshot accepted by the host in its negotiated content formats. */
3
+ export interface PanelContextUpdate<Block> {
4
+ /** Content blocks offered to hosts that accept text or resources. */
5
+ content?: Block[];
6
+ /** Structured context offered to hosts that accept JSON. */
7
+ structuredContent?: Record<string, unknown>;
8
+ }
9
+ /** Send one context replacement and return the host acknowledgement. */
10
+ export type SendPanelContext<Block, Options, Response> = (update: PanelContextUpdate<Block>, options?: Options) => Promise<Response>;
11
+ /** Writers share a serialized host update queue and retain only acknowledged contributions. */
12
+ export interface PanelContexts<Block, Options, Response> {
13
+ /** Bind a panel's selection to its identity and lifetime. */
14
+ forPanel(id: string, title: string, signal: AbortSignal): SendPanelContext<Block, Options, Response>;
15
+ /**
16
+ * Publish board metadata using its own lifetime and top-level structured keys.
17
+ * Compose reserves the `panels` key to group panel selections.
18
+ */
19
+ forBoard(signal: AbortSignal): SendPanelContext<Block, Options, Response>;
20
+ /** Send a replacement snapshot after one or more contributor lifetimes end. */
21
+ clear(): Promise<void>;
22
+ }
23
+ /** One host snapshot contains the acknowledged selections of every mounted panel. */
24
+ export declare function createPanelContexts<Block, Options, Response extends object>(send: SendPanelContext<Block, Options, Response>, clearErrorMessage?: () => string): PanelContexts<Block, Options, Response>;
25
+ //# sourceMappingURL=panel-contexts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"panel-contexts.d.ts","sourceRoot":"","sources":["../../../src/src/code-mode/panel-contexts.ts"],"names":[],"mappings":"AAAA,wFAAwF;AAExF,mFAAmF;AACnF,MAAM,WAAW,kBAAkB,CAAC,KAAK;IACvC,qEAAqE;IACrE,OAAO,CAAC,EAAE,KAAK,EAAE,CAAC;IAClB,4DAA4D;IAC5D,iBAAiB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC7C;AAED,wEAAwE;AACxE,MAAM,MAAM,gBAAgB,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,IAAI,CACvD,MAAM,EAAE,kBAAkB,CAAC,KAAK,CAAC,EACjC,OAAO,CAAC,EAAE,OAAO,KACd,OAAO,CAAC,QAAQ,CAAC,CAAC;AAEvB,+FAA+F;AAC/F,MAAM,WAAW,aAAa,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ;IACrD,6DAA6D;IAC7D,QAAQ,CACN,EAAE,EAAE,MAAM,EACV,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,WAAW,GAClB,gBAAgB,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC;IAC9C;;;OAGG;IACH,QAAQ,CAAC,MAAM,EAAE,WAAW,GAAG,gBAAgB,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC;IAC1E,+EAA+E;IAC/E,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB;AAQD,qFAAqF;AACrF,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,SAAS,MAAM,EACzE,IAAI,EAAE,gBAAgB,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,CAAC,EAChD,iBAAiB,GAAE,MAAM,MAAoC,GAC5D,aAAa,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,CAAC,CA4HzC"}
@@ -0,0 +1,115 @@
1
+ /** Aggregate panel selections and board receipts for a single MCP Apps host. @module */
2
+ /** One host snapshot contains the acknowledged selections of every mounted panel. */
3
+ export function createPanelContexts(send, clearErrorMessage = () => "Context not updated") {
4
+ const board = Symbol("layout receipt");
5
+ let active = new Map();
6
+ // A lost acknowledgement leaves the host snapshot unknown. Retain only the
7
+ // formats to clear on the next replacement, never the attempted selection.
8
+ let uncertain;
9
+ function liveSelections() {
10
+ return new Map([...active].filter(([, selection]) => !selection.signal.aborted));
11
+ }
12
+ let queued = Promise.resolve();
13
+ function enqueue(work) {
14
+ const next = queued.then(work);
15
+ queued = next.catch(() => { });
16
+ return next;
17
+ }
18
+ function hasSelection(value) {
19
+ return Boolean(value.content?.length ||
20
+ Object.keys(value.structuredContent ?? {}).length);
21
+ }
22
+ function businessSelection(entries, last, boardMetadata) {
23
+ if (entries.length === 0)
24
+ return last;
25
+ if (entries.length === 1) {
26
+ const only = entries[0].value;
27
+ const overlap = boardMetadata &&
28
+ Object.keys(only.structuredContent ?? {}).some((key) => Object.hasOwn(boardMetadata, key));
29
+ if (!overlap)
30
+ return only;
31
+ }
32
+ const content = entries.flatMap(({ value }) => value.content ?? []);
33
+ const panels = entries.flatMap(({ title, value }) => value.structuredContent ? [{ title, context: value.structuredContent }] : []);
34
+ return {
35
+ ...(entries.some(({ value }) => value.content !== undefined) ? { content } : {}),
36
+ ...(panels.length ? { structuredContent: { panels } } : {}),
37
+ };
38
+ }
39
+ function merge(next, last) {
40
+ const receipt = next.get(board)?.value;
41
+ if (!receipt)
42
+ return businessSelection([...next.values()], last);
43
+ const business = businessSelection([...next].filter(([key]) => key !== board).map(([, entry]) => entry), {}, receipt.structuredContent);
44
+ return {
45
+ ...(business.structuredContent || receipt.structuredContent ||
46
+ last.structuredContent
47
+ ? {
48
+ structuredContent: {
49
+ ...business.structuredContent,
50
+ ...receipt.structuredContent,
51
+ },
52
+ }
53
+ : {}),
54
+ ...(business.content || receipt.content || last.content
55
+ ? { content: [...(business.content ?? []), ...(receipt.content ?? [])] }
56
+ : {}),
57
+ };
58
+ }
59
+ async function replace(next, last, options) {
60
+ const update = { ...uncertain, ...merge(next, last) };
61
+ let response;
62
+ try {
63
+ response = await send(update, options);
64
+ }
65
+ catch (cause) {
66
+ uncertain = {
67
+ ...(update.content !== undefined ? { content: [] } : {}),
68
+ ...(update.structuredContent !== undefined ? { structuredContent: {} } : {}),
69
+ };
70
+ throw cause;
71
+ }
72
+ if (!("isError" in response && response.isError)) {
73
+ active = next;
74
+ uncertain = undefined;
75
+ }
76
+ return response;
77
+ }
78
+ function forSource(id, title, signal) {
79
+ return (value, options) => enqueue(async () => {
80
+ signal.throwIfAborted();
81
+ if (id === board && value.structuredContent &&
82
+ Object.hasOwn(value.structuredContent, "panels")) {
83
+ throw new TypeError('Board context reserves "panels" for panel selections');
84
+ }
85
+ const next = liveSelections();
86
+ if (hasSelection(value))
87
+ next.set(id, { title, value, signal });
88
+ else
89
+ next.delete(id);
90
+ return await replace(next, value, options);
91
+ });
92
+ }
93
+ return {
94
+ forPanel: (id, title, signal) => forSource(id, title, signal),
95
+ forBoard: (signal) => forSource(board, "", signal),
96
+ clear() {
97
+ return enqueue(async () => {
98
+ const next = liveSelections();
99
+ if (!uncertain && next.size === active.size)
100
+ return;
101
+ const entries = [...active.values()];
102
+ const empty = {
103
+ ...(entries.some(({ value }) => value.structuredContent !== undefined)
104
+ ? { structuredContent: {} }
105
+ : {}),
106
+ ...(entries.some(({ value }) => value.content !== undefined) ? { content: [] } : {}),
107
+ };
108
+ const response = await replace(next, empty);
109
+ if ("isError" in response && response.isError) {
110
+ throw new Error(clearErrorMessage());
111
+ }
112
+ });
113
+ },
114
+ };
115
+ }
@@ -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"}
@@ -106,6 +106,7 @@ export async function runProgram(code, params, invoke, callerSignal) {
106
106
  listSnippets: (...args) => call("listSnippets", args),
107
107
  runSnippet: (...args) => call("runSnippet", args),
108
108
  panel: (...args) => call("panel", args),
109
+ sync: (...args) => call("sync", args),
109
110
  });
110
111
  return (async function(api) { "use strict";\n${code}\n})(api);
111
112
  })()`, "mcpview-code-mode.js", { type: "global" })));
@@ -118,7 +119,7 @@ export async function runProgram(code, params, invoke, callerSignal) {
118
119
  if (state.type === "fulfilled") {
119
120
  const value = scope.manage(state.value);
120
121
  if (pending.length) {
121
- throw new Error("Await every snippet operation, including api.panel().");
122
+ throw new Error("Await every snippet operation, including api.panel() and api.sync().");
122
123
  }
123
124
  return vm.typeof(value) === "undefined" ? null : read(value);
124
125
  }
@@ -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"}