@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.
- package/CHANGELOG.md +22 -0
- package/README.md +104 -1
- package/esm/_dnt.polyfills.d.ts +49 -0
- package/esm/_dnt.polyfills.d.ts.map +1 -1
- package/esm/_dnt.polyfills.js +36 -0
- package/esm/src/code-mode/board.d.ts +21 -1
- package/esm/src/code-mode/board.d.ts.map +1 -1
- package/esm/src/code-mode/board.js +76 -2
- package/esm/src/code-mode/chain.d.ts +2 -0
- package/esm/src/code-mode/chain.d.ts.map +1 -1
- package/esm/src/code-mode/chain.js +34 -8
- package/esm/src/code-mode/connections.d.ts +1 -0
- package/esm/src/code-mode/connections.d.ts.map +1 -1
- package/esm/src/code-mode/connections.js +1 -0
- package/esm/src/code-mode/layout-publisher.d.ts +69 -0
- package/esm/src/code-mode/layout-publisher.d.ts.map +1 -0
- package/esm/src/code-mode/layout-publisher.js +85 -0
- package/esm/src/code-mode/layout-runs.d.ts +35 -0
- package/esm/src/code-mode/layout-runs.d.ts.map +1 -0
- package/esm/src/code-mode/layout-runs.js +130 -0
- package/esm/src/code-mode/layout.d.ts +20 -0
- package/esm/src/code-mode/layout.d.ts.map +1 -0
- package/esm/src/code-mode/layout.js +54 -0
- package/esm/src/code-mode/mod.d.ts +1 -0
- package/esm/src/code-mode/mod.d.ts.map +1 -1
- package/esm/src/code-mode/mod.js +1 -0
- package/esm/src/code-mode/panel-contexts.d.ts +25 -0
- package/esm/src/code-mode/panel-contexts.d.ts.map +1 -0
- package/esm/src/code-mode/panel-contexts.js +115 -0
- package/esm/src/code-mode/providers.d.ts +3 -0
- package/esm/src/code-mode/providers.d.ts.map +1 -1
- package/esm/src/code-mode/sandbox.d.ts.map +1 -1
- package/esm/src/code-mode/sandbox.js +2 -1
- package/esm/src/code-mode/sync.d.ts +11 -0
- package/esm/src/code-mode/sync.d.ts.map +1 -0
- package/esm/src/code-mode/sync.js +42 -0
- package/esm/src/code-mode/tool.d.ts +1 -1
- package/esm/src/code-mode/tool.d.ts.map +1 -1
- package/esm/src/code-mode/tool.js +12 -0
- package/esm/src/core/collector/collector.d.ts +2 -1
- package/esm/src/core/collector/collector.d.ts.map +1 -1
- package/esm/src/core/collector/collector.js +6 -0
- package/esm/src/core/types/resources.d.ts +4 -0
- package/esm/src/core/types/resources.d.ts.map +1 -1
- package/esm/src/core/types/resources.js +10 -1
- package/esm/src/host/renderer/css/base.d.ts.map +1 -1
- package/esm/src/host/renderer/css/base.js +3 -0
- package/esm/src/host/renderer/css/layouts.d.ts.map +1 -1
- package/esm/src/host/renderer/css/layouts.js +17 -14
- package/esm/src/host/renderer/css/panel-controls.d.ts +3 -0
- package/esm/src/host/renderer/css/panel-controls.d.ts.map +1 -0
- package/esm/src/host/renderer/css/panel-controls.js +89 -0
- package/esm/src/host/renderer/html-generator.d.ts.map +1 -1
- package/esm/src/host/renderer/html-generator.js +38 -42
- package/esm/src/host/renderer/js/card-height.d.ts +3 -0
- package/esm/src/host/renderer/js/card-height.d.ts.map +1 -0
- package/esm/src/host/renderer/js/card-height.js +58 -0
- package/esm/src/host/renderer/js/event-bus.d.ts.map +1 -1
- package/esm/src/host/renderer/js/event-bus.js +32 -12
- package/esm/src/host/renderer/panel-controls.d.ts +30 -0
- package/esm/src/host/renderer/panel-controls.d.ts.map +1 -0
- package/esm/src/host/renderer/panel-controls.js +6 -0
- package/esm/src/host/renderer/panel-movement.d.ts +8 -0
- package/esm/src/host/renderer/panel-movement.d.ts.map +1 -0
- package/esm/src/host/renderer/panel-movement.js +396 -0
- package/esm/src/host/renderer/panel-reflow.d.ts +17 -0
- package/esm/src/host/renderer/panel-reflow.d.ts.map +1 -0
- package/esm/src/host/renderer/panel-reflow.js +342 -0
- package/esm/src/host/renderer/panel-resizing.d.ts +11 -0
- package/esm/src/host/renderer/panel-resizing.d.ts.map +1 -0
- package/esm/src/host/renderer/panel-resizing.js +375 -0
- package/esm/src/host/renderer/panel-snapshot.d.ts +11 -0
- package/esm/src/host/renderer/panel-snapshot.d.ts.map +1 -0
- package/esm/src/host/renderer/panel-snapshot.js +65 -0
- package/esm/src/runtime/compose.d.ts.map +1 -1
- package/esm/src/runtime/compose.js +3 -0
- package/esm/src/runtime/manifest.d.ts.map +1 -1
- package/esm/src/runtime/manifest.js +4 -0
- package/esm/src/runtime/types.d.ts +2 -0
- package/esm/src/runtime/types.d.ts.map +1 -1
- package/esm/src/sdk/mcp-sdk.d.ts +2 -1
- package/esm/src/sdk/mcp-sdk.d.ts.map +1 -1
- package/esm/src/sdk/mcp-sdk.js +2 -2
- package/esm/src/version.d.ts +1 -1
- package/esm/src/version.js +1 -1
- package/package.json +9 -1
- package/script/_dnt.polyfills.d.ts +49 -0
- package/script/_dnt.polyfills.d.ts.map +1 -1
- package/script/_dnt.polyfills.js +36 -0
- package/script/src/code-mode/board.d.ts +21 -1
- package/script/src/code-mode/board.d.ts.map +1 -1
- package/script/src/code-mode/board.js +87 -3
- package/script/src/code-mode/chain.d.ts +2 -0
- package/script/src/code-mode/chain.d.ts.map +1 -1
- package/script/src/code-mode/chain.js +34 -8
- package/script/src/code-mode/connections.d.ts +1 -0
- package/script/src/code-mode/connections.d.ts.map +1 -1
- package/script/src/code-mode/connections.js +1 -0
- package/script/src/code-mode/layout-publisher.d.ts +69 -0
- package/script/src/code-mode/layout-publisher.d.ts.map +1 -0
- package/script/src/code-mode/layout-publisher.js +88 -0
- package/script/src/code-mode/layout-runs.d.ts +35 -0
- package/script/src/code-mode/layout-runs.d.ts.map +1 -0
- package/script/src/code-mode/layout-runs.js +134 -0
- package/script/src/code-mode/layout.d.ts +20 -0
- package/script/src/code-mode/layout.d.ts.map +1 -0
- package/script/src/code-mode/layout.js +57 -0
- package/script/src/code-mode/mod.d.ts +1 -0
- package/script/src/code-mode/mod.d.ts.map +1 -1
- package/script/src/code-mode/mod.js +6 -1
- package/script/src/code-mode/panel-contexts.d.ts +25 -0
- package/script/src/code-mode/panel-contexts.d.ts.map +1 -0
- package/script/src/code-mode/panel-contexts.js +118 -0
- package/script/src/code-mode/providers.d.ts +3 -0
- package/script/src/code-mode/providers.d.ts.map +1 -1
- package/script/src/code-mode/sandbox.d.ts.map +1 -1
- package/script/src/code-mode/sandbox.js +2 -1
- package/script/src/code-mode/sync.d.ts +11 -0
- package/script/src/code-mode/sync.d.ts.map +1 -0
- package/script/src/code-mode/sync.js +51 -0
- package/script/src/code-mode/tool.d.ts +1 -1
- package/script/src/code-mode/tool.d.ts.map +1 -1
- package/script/src/code-mode/tool.js +12 -0
- package/script/src/core/collector/collector.d.ts +2 -1
- package/script/src/core/collector/collector.d.ts.map +1 -1
- package/script/src/core/collector/collector.js +6 -0
- package/script/src/core/types/resources.d.ts +4 -0
- package/script/src/core/types/resources.d.ts.map +1 -1
- package/script/src/core/types/resources.js +11 -0
- package/script/src/host/renderer/css/base.d.ts.map +1 -1
- package/script/src/host/renderer/css/base.js +3 -0
- package/script/src/host/renderer/css/layouts.d.ts.map +1 -1
- package/script/src/host/renderer/css/layouts.js +17 -14
- package/script/src/host/renderer/css/panel-controls.d.ts +3 -0
- package/script/src/host/renderer/css/panel-controls.d.ts.map +1 -0
- package/script/src/host/renderer/css/panel-controls.js +92 -0
- package/script/src/host/renderer/html-generator.d.ts.map +1 -1
- package/script/src/host/renderer/html-generator.js +38 -42
- package/script/src/host/renderer/js/card-height.d.ts +3 -0
- package/script/src/host/renderer/js/card-height.d.ts.map +1 -0
- package/script/src/host/renderer/js/card-height.js +61 -0
- package/script/src/host/renderer/js/event-bus.d.ts.map +1 -1
- package/script/src/host/renderer/js/event-bus.js +32 -12
- package/script/src/host/renderer/panel-controls.d.ts +30 -0
- package/script/src/host/renderer/panel-controls.d.ts.map +1 -0
- package/script/src/host/renderer/panel-controls.js +14 -0
- package/script/src/host/renderer/panel-movement.d.ts +8 -0
- package/script/src/host/renderer/panel-movement.d.ts.map +1 -0
- package/script/src/host/renderer/panel-movement.js +399 -0
- package/script/src/host/renderer/panel-reflow.d.ts +17 -0
- package/script/src/host/renderer/panel-reflow.d.ts.map +1 -0
- package/script/src/host/renderer/panel-reflow.js +345 -0
- package/script/src/host/renderer/panel-resizing.d.ts +11 -0
- package/script/src/host/renderer/panel-resizing.d.ts.map +1 -0
- package/script/src/host/renderer/panel-resizing.js +378 -0
- package/script/src/host/renderer/panel-snapshot.d.ts +11 -0
- package/script/src/host/renderer/panel-snapshot.d.ts.map +1 -0
- package/script/src/host/renderer/panel-snapshot.js +69 -0
- package/script/src/runtime/compose.d.ts.map +1 -1
- package/script/src/runtime/compose.js +3 -0
- package/script/src/runtime/manifest.d.ts.map +1 -1
- package/script/src/runtime/manifest.js +4 -0
- package/script/src/runtime/types.d.ts +2 -0
- package/script/src/runtime/types.d.ts.map +1 -1
- package/script/src/sdk/mcp-sdk.d.ts +2 -1
- package/script/src/sdk/mcp-sdk.d.ts.map +1 -1
- package/script/src/sdk/mcp-sdk.js +2 -2
- package/script/src/version.d.ts +1 -1
- package/script/src/version.js +1 -1
|
@@ -9,6 +9,55 @@ declare global {
|
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
11
|
export {};
|
|
12
|
+
declare global {
|
|
13
|
+
interface Array<T> {
|
|
14
|
+
/**
|
|
15
|
+
* Returns the value of the last element in the array where predicate is true, and undefined
|
|
16
|
+
* otherwise.
|
|
17
|
+
* @param predicate find calls predicate once for each element of the array, in ascending
|
|
18
|
+
* order, until it finds one where predicate returns true. If such an element is found, find
|
|
19
|
+
* immediately returns that element value. Otherwise, find returns undefined.
|
|
20
|
+
* @param thisArg If provided, it will be used as the this value for each invocation of
|
|
21
|
+
* predicate. If it is not provided, undefined is used instead.
|
|
22
|
+
*/
|
|
23
|
+
findLast<S extends T>(predicate: (this: void, value: T, index: number, obj: T[]) => value is S, thisArg?: any): S | undefined;
|
|
24
|
+
findLast(predicate: (value: T, index: number, obj: T[]) => unknown, thisArg?: any): T | undefined;
|
|
25
|
+
/**
|
|
26
|
+
* Returns the index of the last element in the array where predicate is true, and -1
|
|
27
|
+
* otherwise.
|
|
28
|
+
* @param predicate find calls predicate once for each element of the array, in ascending
|
|
29
|
+
* order, until it finds one where predicate returns true. If such an element is found,
|
|
30
|
+
* findIndex immediately returns that element index. Otherwise, findIndex returns -1.
|
|
31
|
+
* @param thisArg If provided, it will be used as the this value for each invocation of
|
|
32
|
+
* predicate. If it is not provided, undefined is used instead.
|
|
33
|
+
*/
|
|
34
|
+
findLastIndex(predicate: (value: T, index: number, obj: T[]) => unknown, thisArg?: any): number;
|
|
35
|
+
}
|
|
36
|
+
interface Uint8Array {
|
|
37
|
+
/**
|
|
38
|
+
* Returns the value of the last element in the array where predicate is true, and undefined
|
|
39
|
+
* otherwise.
|
|
40
|
+
* @param predicate findLast calls predicate once for each element of the array, in descending
|
|
41
|
+
* order, until it finds one where predicate returns true. If such an element is found, findLast
|
|
42
|
+
* immediately returns that element value. Otherwise, findLast returns undefined.
|
|
43
|
+
* @param thisArg If provided, it will be used as the this value for each invocation of
|
|
44
|
+
* predicate. If it is not provided, undefined is used instead.
|
|
45
|
+
*/
|
|
46
|
+
findLast<S extends number>(predicate: (value: number, index: number, array: Uint8Array) => value is S, thisArg?: any): S | undefined;
|
|
47
|
+
findLast(predicate: (value: number, index: number, array: Uint8Array) => unknown, thisArg?: any): number | undefined;
|
|
48
|
+
/**
|
|
49
|
+
* Returns the index of the last element in the array where predicate is true, and -1
|
|
50
|
+
* otherwise.
|
|
51
|
+
* @param predicate findLastIndex calls predicate once for each element of the array, in descending
|
|
52
|
+
* order, until it finds one where predicate returns true. If such an element is found,
|
|
53
|
+
* findLastIndex immediately returns that element index. Otherwise, findLastIndex returns -1.
|
|
54
|
+
* @param thisArg If provided, it will be used as the this value for each invocation of
|
|
55
|
+
* predicate. If it is not provided, undefined is used instead.
|
|
56
|
+
*/
|
|
57
|
+
findLastIndex(predicate: (value: number, index: number, array: Uint8Array) => unknown, thisArg?: any): number;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
export {};
|
|
12
61
|
declare global {
|
|
13
62
|
interface Error {
|
|
14
63
|
cause?: unknown;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_dnt.polyfills.d.ts","sourceRoot":"","sources":["../src/_dnt.polyfills.ts"],"names":[],"mappings":"AAeA,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd;;;;WAIG;QACH,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC;KAC5C;CACF;AAED,OAAO,EAAE,CAAC;AACV,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,KAAK;QACb,KAAK,CAAC,EAAE,OAAO,CAAC;KACjB;CACF;AAED,OAAO,EAAE,CAAC"}
|
|
1
|
+
{"version":3,"file":"_dnt.polyfills.d.ts","sourceRoot":"","sources":["../src/_dnt.polyfills.ts"],"names":[],"mappings":"AAeA,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd;;;;WAIG;QACH,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC;KAC5C;CACF;AAED,OAAO,EAAE,CAAC;AAEV,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,KAAK,CAAC,CAAC;QACf;;;;;;;;WAQG;QACH,QAAQ,CAAC,CAAC,SAAS,CAAC,EAClB,SAAS,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,EAAE,KAAK,KAAK,IAAI,CAAC,EACxE,OAAO,CAAC,EAAE,GAAG,GACZ,CAAC,GAAG,SAAS,CAAC;QACjB,QAAQ,CACN,SAAS,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,EAAE,KAAK,OAAO,EACzD,OAAO,CAAC,EAAE,GAAG,GACZ,CAAC,GAAG,SAAS,CAAC;QAEjB;;;;;;;;WAQG;QACH,aAAa,CACX,SAAS,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,EAAE,KAAK,OAAO,EACzD,OAAO,CAAC,EAAE,GAAG,GACZ,MAAM,CAAC;KACX;IACD,UAAU,UAAU;QAClB;;;;;;;;WAQG;QACH,QAAQ,CAAC,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"}
|
package/script/_dnt.polyfills.js
CHANGED
|
@@ -14,3 +14,39 @@ if (!Object.hasOwn) {
|
|
|
14
14
|
writable: true,
|
|
15
15
|
});
|
|
16
16
|
}
|
|
17
|
+
function findLastIndex(self, callbackfn, that) {
|
|
18
|
+
const boundFunc = that === undefined ? callbackfn : callbackfn.bind(that);
|
|
19
|
+
let index = self.length - 1;
|
|
20
|
+
while (index >= 0) {
|
|
21
|
+
const result = boundFunc(self[index], index, self);
|
|
22
|
+
if (result) {
|
|
23
|
+
return index;
|
|
24
|
+
}
|
|
25
|
+
index--;
|
|
26
|
+
}
|
|
27
|
+
return -1;
|
|
28
|
+
}
|
|
29
|
+
function findLast(self, callbackfn, that) {
|
|
30
|
+
const index = self.findLastIndex(callbackfn, that);
|
|
31
|
+
return index === -1 ? undefined : self[index];
|
|
32
|
+
}
|
|
33
|
+
if (!Array.prototype.findLastIndex) {
|
|
34
|
+
Array.prototype.findLastIndex = function (callbackfn, that) {
|
|
35
|
+
return findLastIndex(this, callbackfn, that);
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
if (!Array.prototype.findLast) {
|
|
39
|
+
Array.prototype.findLast = function (callbackfn, that) {
|
|
40
|
+
return findLast(this, callbackfn, that);
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
if (!Uint8Array.prototype.findLastIndex) {
|
|
44
|
+
Uint8Array.prototype.findLastIndex = function (callbackfn, that) {
|
|
45
|
+
return findLastIndex(this, callbackfn, that);
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
if (!Uint8Array.prototype.findLast) {
|
|
49
|
+
Uint8Array.prototype.findLast = function (callbackfn, that) {
|
|
50
|
+
return findLast(this, callbackfn, that);
|
|
51
|
+
};
|
|
52
|
+
}
|
|
@@ -3,9 +3,17 @@
|
|
|
3
3
|
* @module
|
|
4
4
|
*/
|
|
5
5
|
import "../../_dnt.polyfills.js";
|
|
6
|
-
import type { ComponentSurface } from "../core/types/components.js";
|
|
6
|
+
import type { ComponentSurface, ViewComponentEventPorts } from "../core/types/components.js";
|
|
7
7
|
import type { CompositeUiDescriptor } from "../core/types/descriptor.js";
|
|
8
8
|
import type { UiLayout } from "../core/types/layout.js";
|
|
9
|
+
import type { UiSyncRule } from "../core/types/sync-rules.js";
|
|
10
|
+
import { SNIPPET_SYNC_META_KEY } from "./sync.js";
|
|
11
|
+
export { SNIPPET_SYNC_META_KEY };
|
|
12
|
+
export { createPanelContexts, type PanelContexts, type PanelContextUpdate, type SendPanelContext, } from "./panel-contexts.js";
|
|
13
|
+
export { connectSnippetBoardLayout, type SnippetBoardLayoutOptions, type SnippetLayoutReceipt, type SnippetLayoutStatus, } from "./layout-publisher.js";
|
|
14
|
+
export { getPanelControlsCss } from "../host/renderer/css/panel-controls.js";
|
|
15
|
+
export { isPanelLayoutSnapshot, type PanelLayoutSnapshot } from "./layout.js";
|
|
16
|
+
export { capturePanelLayout, installPanelMovement, installPanelResizing, restorePanelLayout, } from "../host/renderer/panel-controls.js";
|
|
9
17
|
/** MCP App result metadata containing the receipts selected by the program. */
|
|
10
18
|
export declare const SNIPPET_PANELS_META_KEY = "io.mcpview/snippet-panels";
|
|
11
19
|
/** A selected provider result. The receipt ID distinguishes calls to the same snippet. */
|
|
@@ -15,12 +23,17 @@ export interface SnippetPanel {
|
|
|
15
23
|
readonly name: string;
|
|
16
24
|
readonly title: string;
|
|
17
25
|
readonly result: Record<string, unknown>;
|
|
26
|
+
readonly events?: ViewComponentEventPorts;
|
|
18
27
|
}
|
|
19
28
|
/** An App-owned view for a receipt, with optional renderer data and component selection. */
|
|
20
29
|
export interface SnippetPanelView {
|
|
21
30
|
readonly resourceUri: string;
|
|
22
31
|
readonly context?: Record<string, unknown>;
|
|
23
32
|
readonly surface?: ComponentSurface;
|
|
33
|
+
/** Widths offered by this local view in CSS pixels. An empty list disables resizing. */
|
|
34
|
+
readonly supportedWidths?: readonly number[];
|
|
35
|
+
/** Restrict routing to the ports implemented by this local view. */
|
|
36
|
+
readonly events?: ViewComponentEventPorts;
|
|
24
37
|
}
|
|
25
38
|
/** Display options supplied by the board hosting the results. */
|
|
26
39
|
export interface SnippetBoardOptions {
|
|
@@ -42,6 +55,8 @@ export interface SnippetBoardOptions {
|
|
|
42
55
|
* ```
|
|
43
56
|
*/
|
|
44
57
|
export declare function readSnippetPanels(result: unknown): SnippetPanel[];
|
|
58
|
+
/** Read unique, declared Compose routes between panels in this result. */
|
|
59
|
+
export declare function readSnippetSyncRules(result: unknown): UiSyncRule[];
|
|
45
60
|
/**
|
|
46
61
|
* Build a Compose descriptor from the current execution, without making any provider calls.
|
|
47
62
|
* Each child keeps its receipt in `context.panel` and adapter data in `context.view`.
|
|
@@ -59,4 +74,9 @@ export declare function readSnippetPanels(result: unknown): SnippetPanel[];
|
|
|
59
74
|
* ```
|
|
60
75
|
*/
|
|
61
76
|
export declare function composeSnippetBoard(result: unknown, options?: SnippetBoardOptions): CompositeUiDescriptor;
|
|
77
|
+
/**
|
|
78
|
+
* Deliver a JSON event through the current board's declared routes to mounted views.
|
|
79
|
+
* The board owns dispatch and supplies the receipts and data from its active UI.
|
|
80
|
+
*/
|
|
81
|
+
export declare function emitSnippetBoardEvent(descriptor: CompositeUiDescriptor, sourceReceiptId: string, event: string, data: unknown, deliver: (targetReceiptId: string, action: string, data: unknown) => void): void;
|
|
62
82
|
//# sourceMappingURL=board.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"board.d.ts","sourceRoot":"","sources":["../../../src/src/code-mode/board.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,yBAAyB,CAAC;AAMjC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;
|
|
1
|
+
{"version":3,"file":"board.d.ts","sourceRoot":"","sources":["../../../src/src/code-mode/board.ts"],"names":[],"mappings":"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"}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SNIPPET_PANELS_META_KEY = void 0;
|
|
3
|
+
exports.SNIPPET_PANELS_META_KEY = exports.restorePanelLayout = exports.installPanelResizing = exports.installPanelMovement = exports.capturePanelLayout = exports.isPanelLayoutSnapshot = exports.getPanelControlsCss = exports.connectSnippetBoardLayout = exports.createPanelContexts = exports.SNIPPET_SYNC_META_KEY = void 0;
|
|
4
4
|
exports.readSnippetPanels = readSnippetPanels;
|
|
5
|
+
exports.readSnippetSyncRules = readSnippetSyncRules;
|
|
5
6
|
exports.composeSnippetBoard = composeSnippetBoard;
|
|
7
|
+
exports.emitSnippetBoardEvent = emitSnippetBoardEvent;
|
|
6
8
|
/**
|
|
7
9
|
* Browser-side composition of completed Code Mode results.
|
|
8
10
|
* @module
|
|
@@ -11,6 +13,21 @@ require("../../_dnt.polyfills.js");
|
|
|
11
13
|
const collector_js_1 = require("../core/collector/collector.js");
|
|
12
14
|
const extractor_js_1 = require("../core/collector/extractor.js");
|
|
13
15
|
const composer_js_1 = require("../core/composer/composer.js");
|
|
16
|
+
const sync_js_1 = require("./sync.js");
|
|
17
|
+
Object.defineProperty(exports, "SNIPPET_SYNC_META_KEY", { enumerable: true, get: function () { return sync_js_1.SNIPPET_SYNC_META_KEY; } });
|
|
18
|
+
var panel_contexts_js_1 = require("./panel-contexts.js");
|
|
19
|
+
Object.defineProperty(exports, "createPanelContexts", { enumerable: true, get: function () { return panel_contexts_js_1.createPanelContexts; } });
|
|
20
|
+
var layout_publisher_js_1 = require("./layout-publisher.js");
|
|
21
|
+
Object.defineProperty(exports, "connectSnippetBoardLayout", { enumerable: true, get: function () { return layout_publisher_js_1.connectSnippetBoardLayout; } });
|
|
22
|
+
var panel_controls_js_1 = require("../host/renderer/css/panel-controls.js");
|
|
23
|
+
Object.defineProperty(exports, "getPanelControlsCss", { enumerable: true, get: function () { return panel_controls_js_1.getPanelControlsCss; } });
|
|
24
|
+
var layout_js_1 = require("./layout.js");
|
|
25
|
+
Object.defineProperty(exports, "isPanelLayoutSnapshot", { enumerable: true, get: function () { return layout_js_1.isPanelLayoutSnapshot; } });
|
|
26
|
+
var panel_controls_js_2 = require("../host/renderer/panel-controls.js");
|
|
27
|
+
Object.defineProperty(exports, "capturePanelLayout", { enumerable: true, get: function () { return panel_controls_js_2.capturePanelLayout; } });
|
|
28
|
+
Object.defineProperty(exports, "installPanelMovement", { enumerable: true, get: function () { return panel_controls_js_2.installPanelMovement; } });
|
|
29
|
+
Object.defineProperty(exports, "installPanelResizing", { enumerable: true, get: function () { return panel_controls_js_2.installPanelResizing; } });
|
|
30
|
+
Object.defineProperty(exports, "restorePanelLayout", { enumerable: true, get: function () { return panel_controls_js_2.restorePanelLayout; } });
|
|
14
31
|
/** MCP App result metadata containing the receipts selected by the program. */
|
|
15
32
|
exports.SNIPPET_PANELS_META_KEY = "io.mcpview/snippet-panels";
|
|
16
33
|
function record(value) {
|
|
@@ -51,6 +68,33 @@ function readSnippetPanels(result) {
|
|
|
51
68
|
}
|
|
52
69
|
return panels;
|
|
53
70
|
}
|
|
71
|
+
/** Read unique, declared Compose routes between panels in this result. */
|
|
72
|
+
function readSnippetSyncRules(result) {
|
|
73
|
+
if (!record(result) || !record(result._meta))
|
|
74
|
+
return [];
|
|
75
|
+
const routes = result._meta[sync_js_1.SNIPPET_SYNC_META_KEY];
|
|
76
|
+
const items = result._meta[exports.SNIPPET_PANELS_META_KEY];
|
|
77
|
+
if (!Array.isArray(routes) || !Array.isArray(items))
|
|
78
|
+
return [];
|
|
79
|
+
const panels = new Map();
|
|
80
|
+
const duplicates = new Set();
|
|
81
|
+
for (const item of items) {
|
|
82
|
+
if (!isPanel(item))
|
|
83
|
+
continue;
|
|
84
|
+
if (panels.has(item.id))
|
|
85
|
+
duplicates.add(item.id);
|
|
86
|
+
panels.set(item.id, (0, sync_js_1.readSnippetEventPorts)(item.events));
|
|
87
|
+
}
|
|
88
|
+
for (const id of duplicates)
|
|
89
|
+
panels.delete(id);
|
|
90
|
+
const rules = new Map();
|
|
91
|
+
for (const item of routes) {
|
|
92
|
+
const rule = (0, sync_js_1.parseSnippetSyncRule)(item);
|
|
93
|
+
if (rule && (0, sync_js_1.supportsSnippetSync)(rule, panels))
|
|
94
|
+
rules.set((0, sync_js_1.snippetSyncKey)(rule), rule);
|
|
95
|
+
}
|
|
96
|
+
return [...rules.values()];
|
|
97
|
+
}
|
|
54
98
|
/**
|
|
55
99
|
* Build a Compose descriptor from the current execution, without making any provider calls.
|
|
56
100
|
* Each child keeps its receipt in `context.panel` and adapter data in `context.view`.
|
|
@@ -72,20 +116,60 @@ function composeSnippetBoard(result, options = {}) {
|
|
|
72
116
|
? result.structuredContent
|
|
73
117
|
: {};
|
|
74
118
|
const collector = (0, collector_js_1.createCollector)();
|
|
119
|
+
const mountedPorts = new Map();
|
|
75
120
|
for (const panel of readSnippetPanels(result)) {
|
|
76
121
|
const view = options.resolveView?.(panel);
|
|
77
122
|
const resourceUri = view?.resourceUri ?? (0, extractor_js_1.extractUiMeta)(panel.result)?.resourceUri;
|
|
78
123
|
if (!resourceUri || !/^ui:\/\/[^\s]+$/.test(resourceUri))
|
|
79
124
|
continue;
|
|
125
|
+
const declared = (0, sync_js_1.readSnippetEventPorts)(panel.events);
|
|
126
|
+
const viewEvents = (0, sync_js_1.readSnippetEventPorts)(view?.events);
|
|
127
|
+
const panelEvents = view
|
|
128
|
+
? {
|
|
129
|
+
emits: declared?.emits?.filter((name) => viewEvents?.emits?.includes(name)),
|
|
130
|
+
accepts: declared?.accepts?.filter((name) => viewEvents?.accepts?.includes(name)),
|
|
131
|
+
}
|
|
132
|
+
: declared;
|
|
133
|
+
mountedPorts.set(panel.id, panelEvents);
|
|
80
134
|
collector.collect(`${panel.provider}:${panel.name}`, { _meta: { ui: { resourceUri } } }, {
|
|
81
135
|
panel,
|
|
136
|
+
panelEvents,
|
|
82
137
|
...(view?.context === undefined ? {} : { view: view.context }),
|
|
83
138
|
...(Object.hasOwn(summary, "value") ? { value: summary.value } : {}),
|
|
84
|
-
}, { componentId: panel.id, surface: view?.surface });
|
|
139
|
+
}, { componentId: panel.id, surface: view?.surface, supportedWidths: view?.supportedWidths });
|
|
85
140
|
}
|
|
86
141
|
const resources = collector.getResources();
|
|
87
142
|
const layout = typeof options.layout === "function"
|
|
88
143
|
? options.layout(resources.length)
|
|
89
144
|
: options.layout;
|
|
90
|
-
|
|
145
|
+
const sync = readSnippetSyncRules(result).filter((rule) => (0, sync_js_1.supportsSnippetSync)(rule, mountedPorts));
|
|
146
|
+
return (0, composer_js_1.buildCompositeUi)(resources, { layout: layout ?? "stack", sharedContext: ["value"], sync });
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Deliver a JSON event through the current board's declared routes to mounted views.
|
|
150
|
+
* The board owns dispatch and supplies the receipts and data from its active UI.
|
|
151
|
+
*/
|
|
152
|
+
function emitSnippetBoardEvent(descriptor, sourceReceiptId, event, data, deliver) {
|
|
153
|
+
const source = descriptor.children.find((child) => child.componentId === sourceReceiptId);
|
|
154
|
+
if (!source || !(0, sync_js_1.readSnippetEventPorts)(source.context?.panelEvents)?.emits?.includes(event)) {
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
let payload;
|
|
158
|
+
try {
|
|
159
|
+
payload = JSON.stringify(data);
|
|
160
|
+
}
|
|
161
|
+
catch {
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
if (payload === undefined || payload.length > 128 * 1024)
|
|
165
|
+
return;
|
|
166
|
+
for (const rule of descriptor.sync) {
|
|
167
|
+
if (rule.from !== source.slot || rule.event !== event || rule.to === "*")
|
|
168
|
+
continue;
|
|
169
|
+
const target = descriptor.children.find((child) => child.slot === rule.to);
|
|
170
|
+
const ports = (0, sync_js_1.readSnippetEventPorts)(target?.context?.panelEvents);
|
|
171
|
+
if (target?.componentId && ports?.accepts?.includes(rule.action)) {
|
|
172
|
+
deliver(target.componentId, rule.action, JSON.parse(payload));
|
|
173
|
+
}
|
|
174
|
+
}
|
|
91
175
|
}
|
|
@@ -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;
|
|
1
|
+
{"version":3,"file":"chain.d.ts","sourceRoot":"","sources":["../../../src/src/code-mode/chain.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,KAAK,EAAE,cAAc,EAAqB,MAAM,0BAA0B,CAAC;AAClF,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAU3E,OAAO,EAAiB,KAAK,mBAAmB,EAAE,KAAK,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAI/F,gFAAgF;AAChF,MAAM,WAAW,mBAAmB;IAClC,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,cAAc,CAAC;IACvB,MAAM,CAAC,EAAE,uBAAuB,CAAC;CAClC;AAyED,6FAA6F;AAC7F,MAAM,MAAM,oBAAoB,GAAG,CACjC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC9B,OAAO,CAAC,EAAE,mBAAmB,KAC1B,OAAO,CAAC,cAAc,CAAC,CAAC;AAE7B;;;;GAIG;AACH,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,WAAW,CAAC,MAAM,EAAE,eAAe,CAAC,EAC/C,OAAO,CAAC,EAAE,cAAc,GACvB,oBAAoB,CA+NtB"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createSnippetChain = createSnippetChain;
|
|
4
|
+
const sync_js_1 = require("./sync.js");
|
|
4
5
|
const board_js_1 = require("./board.js");
|
|
5
6
|
const providers_js_1 = require("./providers.js");
|
|
6
7
|
const sandbox_js_1 = require("./sandbox.js");
|
|
@@ -42,16 +43,19 @@ function validateParams(input, shape) {
|
|
|
42
43
|
}
|
|
43
44
|
return input;
|
|
44
45
|
}
|
|
45
|
-
function output(value, panels = [], saved) {
|
|
46
|
+
function output(value, panels = [], saved, sync = []) {
|
|
46
47
|
const visible = {
|
|
47
48
|
value,
|
|
48
|
-
panels: panels.map(({ result: _result, ...panel }) => panel),
|
|
49
|
+
panels: panels.map(({ result: _result, events: _events, ...panel }) => panel),
|
|
49
50
|
...(saved === undefined ? {} : { saved }),
|
|
50
51
|
};
|
|
51
52
|
return {
|
|
52
53
|
content: [{ type: "text", text: JSON.stringify(visible) }],
|
|
53
54
|
structuredContent: visible,
|
|
54
|
-
_meta: {
|
|
55
|
+
_meta: {
|
|
56
|
+
[board_js_1.SNIPPET_PANELS_META_KEY]: panels,
|
|
57
|
+
...(sync.length ? { [sync_js_1.SNIPPET_SYNC_META_KEY]: sync } : {}),
|
|
58
|
+
},
|
|
55
59
|
};
|
|
56
60
|
}
|
|
57
61
|
/**
|
|
@@ -66,6 +70,8 @@ function createSnippetChain(providers, catalog) {
|
|
|
66
70
|
async function execute(code, params, context, status) {
|
|
67
71
|
const receipts = new Map();
|
|
68
72
|
const selected = new Map();
|
|
73
|
+
const exposedPorts = new Map();
|
|
74
|
+
const sync = new Map();
|
|
69
75
|
let totalBytes = 0;
|
|
70
76
|
const value = await (0, sandbox_js_1.runProgram)(code, params, async (operation, args, signal) => {
|
|
71
77
|
signal.throwIfAborted();
|
|
@@ -78,6 +84,18 @@ function createSnippetChain(providers, catalog) {
|
|
|
78
84
|
throw new Error("Panel titles may contain at most 120 characters.");
|
|
79
85
|
}
|
|
80
86
|
selected.set(panel.id, { ...panel, title: second ?? panel.title });
|
|
87
|
+
exposedPorts.set(panel.id, panel.events);
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
if (operation === "sync") {
|
|
91
|
+
const rule = args.length === 1 ? (0, sync_js_1.parseSnippetSyncRule)(first) : undefined;
|
|
92
|
+
if (!rule || !(0, sync_js_1.supportsSnippetSync)(rule, exposedPorts)) {
|
|
93
|
+
status.diagnostic =
|
|
94
|
+
"Sync requires distinct selected panel receipts and their declared event and action.";
|
|
95
|
+
throw new Error(status.diagnostic);
|
|
96
|
+
}
|
|
97
|
+
const key = (0, sync_js_1.snippetSyncKey)(rule);
|
|
98
|
+
sync.set(key, rule);
|
|
81
99
|
return null;
|
|
82
100
|
}
|
|
83
101
|
const provider = typeof first === "string" ? providers.get(first) : undefined;
|
|
@@ -117,10 +135,18 @@ function createSnippetChain(providers, catalog) {
|
|
|
117
135
|
throw new Error("Native snippet receipts exceed the board size limit.");
|
|
118
136
|
}
|
|
119
137
|
const id = crypto.randomUUID();
|
|
120
|
-
|
|
138
|
+
const events = (0, sync_js_1.snippetPorts)(provider.events, second);
|
|
139
|
+
receipts.set(id, {
|
|
140
|
+
id,
|
|
141
|
+
provider: first,
|
|
142
|
+
name: second,
|
|
143
|
+
title: second,
|
|
144
|
+
result,
|
|
145
|
+
...(events ? { events } : {}),
|
|
146
|
+
});
|
|
121
147
|
return { id, value };
|
|
122
148
|
}, context.signal);
|
|
123
|
-
return { value, panels: [...selected.values()] };
|
|
149
|
+
return { value, panels: [...selected.values()], sync: [...sync.values()] };
|
|
124
150
|
}
|
|
125
151
|
async function call(input, context, status) {
|
|
126
152
|
const { signal, scope } = context;
|
|
@@ -134,7 +160,7 @@ function createSnippetChain(providers, catalog) {
|
|
|
134
160
|
throw new Error("Supply a JavaScript function body.");
|
|
135
161
|
const result = await execute(input.code, validateParams(input.params === undefined ? {} : input.params), context, status);
|
|
136
162
|
signal?.throwIfAborted();
|
|
137
|
-
return output(result.value, result.panels);
|
|
163
|
+
return output(result.value, result.panels, undefined, result.sync);
|
|
138
164
|
}
|
|
139
165
|
if (!catalog || typeof scope !== "string" || !scope.trim()) {
|
|
140
166
|
throw new Error("Saved chains require a configured catalog and a trusted scope.");
|
|
@@ -150,7 +176,7 @@ function createSnippetChain(providers, catalog) {
|
|
|
150
176
|
execute: (code, params) => execute(code, params, context, status),
|
|
151
177
|
});
|
|
152
178
|
signal?.throwIfAborted();
|
|
153
|
-
return output(result.value, result.panels);
|
|
179
|
+
return output(result.value, result.panels, undefined, result.sync);
|
|
154
180
|
}
|
|
155
181
|
if (typeof input.code !== "string" || !has("saveAs") || !keysAllowed("code", "saveAs", "params")) {
|
|
156
182
|
throw new Error("Supply code, replay, or listSaved.");
|
|
@@ -202,7 +228,7 @@ function createSnippetChain(providers, catalog) {
|
|
|
202
228
|
const ref = catalog.recordSuccess(scope, input.code, params);
|
|
203
229
|
const saved = await catalog.save(scope, ref, name);
|
|
204
230
|
reserved = false;
|
|
205
|
-
return output(result.value, result.panels, saved.name);
|
|
231
|
+
return output(result.value, result.panels, saved.name, result.sync);
|
|
206
232
|
}
|
|
207
233
|
finally {
|
|
208
234
|
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;
|
|
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;IACrC,QAAQ,CAAC,MAAM,CAAC,EAAE,eAAe,CAAC,QAAQ,CAAC,CAAC;CAC7C,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,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"}
|
|
@@ -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,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.connectSnippetBoardLayout = connectSnippetBoardLayout;
|
|
4
|
+
/** Browser-side transport for user-edited Code Mode dashboard layouts. @module */
|
|
5
|
+
const panel_controls_js_1 = require("../host/renderer/panel-controls.js");
|
|
6
|
+
/**
|
|
7
|
+
* Install the controls and restore a saved layout on a mounted board. Each
|
|
8
|
+
* committed gesture stages its geometry and publishes an acknowledgement for
|
|
9
|
+
* the next model turn. Pass the board's context writer when other panels share
|
|
10
|
+
* its context. The returned callback retries the current layout after an error.
|
|
11
|
+
*/
|
|
12
|
+
function connectSnippetBoardLayout(board, { host, updateContext, stageTool, runId, savedLayout, signal, onStatus }) {
|
|
13
|
+
(0, panel_controls_js_1.installPanelMovement)(board, signal);
|
|
14
|
+
(0, panel_controls_js_1.installPanelResizing)(board, signal);
|
|
15
|
+
if (!signal.aborted && savedLayout !== undefined && !(0, panel_controls_js_1.restorePanelLayout)(board, savedLayout)) {
|
|
16
|
+
onStatus?.("restore-failed");
|
|
17
|
+
}
|
|
18
|
+
const capabilities = host.getHostCapabilities();
|
|
19
|
+
const formats = capabilities?.updateModelContext;
|
|
20
|
+
const structured = typeof formats?.structuredContent === "object" &&
|
|
21
|
+
formats.structuredContent !== null;
|
|
22
|
+
const text = typeof formats?.text === "object" && formats.text !== null;
|
|
23
|
+
let latest = 0;
|
|
24
|
+
let contextSent = Promise.resolve();
|
|
25
|
+
function sendReceipt(receipt) {
|
|
26
|
+
// Wait for the preceding context write even if the host delivers requests out of order.
|
|
27
|
+
const next = contextSent.then(async () => {
|
|
28
|
+
signal.throwIfAborted();
|
|
29
|
+
if (receipt.status !== "pending" && receipt.revision !== latest)
|
|
30
|
+
return;
|
|
31
|
+
const value = { snippetLayout: receipt };
|
|
32
|
+
// Once sent, an App-wide context update may include live selections from
|
|
33
|
+
// other panels. Let its acknowledgement settle even if this board closes.
|
|
34
|
+
const response = await updateContext(structured
|
|
35
|
+
? { structuredContent: value }
|
|
36
|
+
: { content: [{ type: "text", text: JSON.stringify(value) }] });
|
|
37
|
+
if ("isError" in response && response.isError)
|
|
38
|
+
throw new Error("Layout receipt rejected");
|
|
39
|
+
});
|
|
40
|
+
contextSent = next.catch(() => { });
|
|
41
|
+
return next;
|
|
42
|
+
}
|
|
43
|
+
async function commit() {
|
|
44
|
+
if (signal.aborted)
|
|
45
|
+
return;
|
|
46
|
+
if (typeof runId !== "string" || !capabilities?.serverTools || !(structured || text)) {
|
|
47
|
+
onStatus?.("local");
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
const layout = (0, panel_controls_js_1.capturePanelLayout)(board);
|
|
51
|
+
if (!layout) {
|
|
52
|
+
onStatus?.("local");
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
const revision = ++latest;
|
|
56
|
+
const current = () => latest === revision && !signal.aborted;
|
|
57
|
+
onStatus?.("pending");
|
|
58
|
+
try {
|
|
59
|
+
const [staged] = await Promise.all([
|
|
60
|
+
host.callServerTool({ name: stageTool, arguments: { runId, revision, layout } }, {
|
|
61
|
+
signal,
|
|
62
|
+
}),
|
|
63
|
+
sendReceipt({ runId, revision, status: "pending" }),
|
|
64
|
+
]);
|
|
65
|
+
const ack = staged.structuredContent;
|
|
66
|
+
if (staged.isError || !ack || typeof ack !== "object" ||
|
|
67
|
+
!("runId" in ack) || ack.runId !== runId ||
|
|
68
|
+
!("revision" in ack) || ack.revision !== revision) {
|
|
69
|
+
throw new Error("Layout revision not acknowledged");
|
|
70
|
+
}
|
|
71
|
+
if (!current())
|
|
72
|
+
return;
|
|
73
|
+
await sendReceipt({ runId, revision, status: "ready" });
|
|
74
|
+
if (current())
|
|
75
|
+
onStatus?.("ready");
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
if (!current())
|
|
79
|
+
return;
|
|
80
|
+
onStatus?.("failed");
|
|
81
|
+
// Leave retry available even when a disconnected host rejects the failure notice.
|
|
82
|
+
await sendReceipt({ runId, revision, status: "failed" }).catch(() => { });
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
const events = board;
|
|
86
|
+
events.addEventListener("compose-panel-layout-committed", commit, { signal });
|
|
87
|
+
return commit;
|
|
88
|
+
}
|