@mcpview/compose 0.13.0 → 0.14.0
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 +120 -0
- package/README.md +131 -2
- package/esm/_dnt.polyfills.d.ts +11 -11
- package/esm/_dnt.polyfills.d.ts.map +1 -1
- package/esm/_dnt.polyfills.js +14 -14
- package/esm/src/code-mode/board.d.ts +18 -2
- package/esm/src/code-mode/board.d.ts.map +1 -1
- package/esm/src/code-mode/board.js +74 -2
- package/esm/src/code-mode/chain.d.ts +26 -1
- package/esm/src/code-mode/chain.d.ts.map +1 -1
- package/esm/src/code-mode/chain.js +248 -89
- 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/errors.d.ts +80 -0
- package/esm/src/code-mode/errors.d.ts.map +1 -0
- package/esm/src/code-mode/errors.js +140 -0
- package/esm/src/code-mode/guest-worker.d.ts +11 -0
- package/esm/src/code-mode/guest-worker.d.ts.map +1 -0
- package/esm/src/code-mode/guest-worker.js +80 -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 +4 -1
- package/esm/src/code-mode/mod.d.ts.map +1 -1
- package/esm/src/code-mode/mod.js +3 -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-core.d.ts +61 -0
- package/esm/src/code-mode/sandbox-core.d.ts.map +1 -0
- package/esm/src/code-mode/sandbox-core.js +424 -0
- package/esm/src/code-mode/sandbox.d.ts +68 -7
- package/esm/src/code-mode/sandbox.d.ts.map +1 -1
- package/esm/src/code-mode/sandbox.js +180 -119
- 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 +14 -0
- package/esm/src/code-mode/worker-host.d.ts +70 -0
- package/esm/src/code-mode/worker-host.d.ts.map +1 -0
- package/esm/src/code-mode/worker-host.js +355 -0
- package/esm/src/code-mode/worker-protocol.d.ts +44 -0
- package/esm/src/code-mode/worker-protocol.d.ts.map +1 -0
- package/esm/src/code-mode/worker-protocol.js +7 -0
- package/esm/src/host/renderer/css/panel-controls.d.ts.map +1 -1
- package/esm/src/host/renderer/css/panel-controls.js +5 -1
- package/esm/src/host/renderer/html-generator.js +2 -2
- package/esm/src/host/renderer/js/card-height.d.ts +11 -1
- package/esm/src/host/renderer/js/card-height.d.ts.map +1 -1
- package/esm/src/host/renderer/js/card-height.js +57 -10
- package/esm/src/host/renderer/js/event-bus.d.ts +11 -0
- package/esm/src/host/renderer/js/event-bus.d.ts.map +1 -1
- package/esm/src/host/renderer/js/event-bus.js +49 -8
- package/esm/src/host/renderer/js/intrinsic-layout.d.ts +26 -0
- package/esm/src/host/renderer/js/intrinsic-layout.d.ts.map +1 -0
- package/esm/src/host/renderer/js/intrinsic-layout.js +44 -0
- package/esm/src/host/renderer/panel-controls.d.ts +7 -0
- package/esm/src/host/renderer/panel-controls.js +1 -0
- package/esm/src/host/renderer/panel-movement.d.ts.map +1 -1
- package/esm/src/host/renderer/panel-movement.js +5 -1
- package/esm/src/host/renderer/panel-resizing.d.ts.map +1 -1
- package/esm/src/host/renderer/panel-resizing.js +36 -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/version.d.ts +1 -1
- package/esm/src/version.js +1 -1
- package/package.json +9 -1
- package/script/_dnt.polyfills.d.ts +11 -11
- package/script/_dnt.polyfills.d.ts.map +1 -1
- package/script/_dnt.polyfills.js +14 -14
- package/script/src/code-mode/board.d.ts +18 -2
- package/script/src/code-mode/board.d.ts.map +1 -1
- package/script/src/code-mode/board.js +81 -2
- package/script/src/code-mode/chain.d.ts +26 -1
- package/script/src/code-mode/chain.d.ts.map +1 -1
- package/script/src/code-mode/chain.js +247 -88
- 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/errors.d.ts +80 -0
- package/script/src/code-mode/errors.d.ts.map +1 -0
- package/script/src/code-mode/errors.js +148 -0
- package/script/src/code-mode/guest-worker.d.ts +11 -0
- package/script/src/code-mode/guest-worker.d.ts.map +1 -0
- package/script/src/code-mode/guest-worker.js +105 -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 +4 -1
- package/script/src/code-mode/mod.d.ts.map +1 -1
- package/script/src/code-mode/mod.js +14 -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-core.d.ts +61 -0
- package/script/src/code-mode/sandbox-core.d.ts.map +1 -0
- package/script/src/code-mode/sandbox-core.js +430 -0
- package/script/src/code-mode/sandbox.d.ts +68 -7
- package/script/src/code-mode/sandbox.d.ts.map +1 -1
- package/script/src/code-mode/sandbox.js +188 -121
- 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 +14 -0
- package/script/src/code-mode/worker-host.d.ts +70 -0
- package/script/src/code-mode/worker-host.d.ts.map +1 -0
- package/script/src/code-mode/worker-host.js +389 -0
- package/script/src/code-mode/worker-protocol.d.ts +44 -0
- package/script/src/code-mode/worker-protocol.d.ts.map +1 -0
- package/script/src/code-mode/worker-protocol.js +8 -0
- package/script/src/host/renderer/css/panel-controls.d.ts.map +1 -1
- package/script/src/host/renderer/css/panel-controls.js +5 -1
- package/script/src/host/renderer/html-generator.js +2 -2
- package/script/src/host/renderer/js/card-height.d.ts +11 -1
- package/script/src/host/renderer/js/card-height.d.ts.map +1 -1
- package/script/src/host/renderer/js/card-height.js +57 -10
- package/script/src/host/renderer/js/event-bus.d.ts +11 -0
- package/script/src/host/renderer/js/event-bus.d.ts.map +1 -1
- package/script/src/host/renderer/js/event-bus.js +50 -8
- package/script/src/host/renderer/js/intrinsic-layout.d.ts +26 -0
- package/script/src/host/renderer/js/intrinsic-layout.d.ts.map +1 -0
- package/script/src/host/renderer/js/intrinsic-layout.js +48 -0
- package/script/src/host/renderer/panel-controls.d.ts +7 -0
- package/script/src/host/renderer/panel-controls.js +4 -1
- package/script/src/host/renderer/panel-movement.d.ts.map +1 -1
- package/script/src/host/renderer/panel-movement.js +5 -1
- package/script/src/host/renderer/panel-resizing.d.ts.map +1 -1
- package/script/src/host/renderer/panel-resizing.js +36 -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/version.d.ts +1 -1
- package/script/src/version.js +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,126 @@ documented in this file.
|
|
|
5
5
|
|
|
6
6
|
## [Unreleased]
|
|
7
7
|
|
|
8
|
+
## [0.14.0] - 2026-11-29
|
|
9
|
+
|
|
10
|
+
**Breaking** (0.x minor): Code Mode now runs programs in a worker by default (runtimes without
|
|
11
|
+
workers must pass `isolation: "inline"` or fail with `SANDBOX_UNAVAILABLE`); failures are coded
|
|
12
|
+
`CodeModeError`s instead of prose messages; and api calls are lazy, dispatched in the order the
|
|
13
|
+
program awaits them, with never-started calls failing as `UNAWAITED_OPERATION`. See the **Changed**
|
|
14
|
+
section below for the migration notes.
|
|
15
|
+
|
|
16
|
+
### Changed
|
|
17
|
+
|
|
18
|
+
- Code Mode programs run in a short-lived worker by default, so a CPU-bound program no longer blocks
|
|
19
|
+
the server's event loop for up to 2 s. A shared flag stops the guest within milliseconds on abort
|
|
20
|
+
or timeout. `createSnippetChain` and `runProgram` accept `isolation: "worker" | "inline"`.
|
|
21
|
+
Runtimes or bundles without workers must pass `"inline"` explicitly; otherwise configuration fails
|
|
22
|
+
with `SANDBOX_UNAVAILABLE`. Under Deno the worker inherits the host's permissions and needs read
|
|
23
|
+
access to the whole `code-mode` directory (or import access from JSR) and to the QuickJS WASM file
|
|
24
|
+
of `quickjs-emscripten`. Configuration only checks the worker module, so a missing grant for the
|
|
25
|
+
other files shows up at the first run as `SANDBOX_FAILED`. The npm package ships the worker as an
|
|
26
|
+
internal file; it is not a public export. Node options such as `--max-old-space-size` and
|
|
27
|
+
`--input-type` no longer reach the worker, whether they come from `execArgv` or `NODE_OPTIONS`.
|
|
28
|
+
Browsers cannot run the worker guest: configuring `"worker"` there fails with
|
|
29
|
+
`SANDBOX_UNAVAILABLE`, so use `"inline"`.
|
|
30
|
+
- Code Mode failures are `CodeModeError`s with a stable `code`, `recovery` and `context`, rendered
|
|
31
|
+
as `[execute] CODE: detail. Recovery: hint.` instead of prose such as `JavaScript failed.` or
|
|
32
|
+
`Chain execution failed.`. Inside a program, a failed api call throws an `Error` that carries the
|
|
33
|
+
same fields, so `e.code` works in a `catch`. Once a provider call was dispatched, errors carry
|
|
34
|
+
`effects: "possible"` and keep hiding guest, provider and transport text.
|
|
35
|
+
- **Breaking:** api calls are dispatched in the order the program awaits them, not in declaration
|
|
36
|
+
order. A saved chain that assigns `const write = api.runSnippet(...)`, awaits a read, then awaits
|
|
37
|
+
`write` now runs the read first and can return stale data. Migration: await calls in the order
|
|
38
|
+
they must run, and re-save any chain that depended on declaration order.
|
|
39
|
+
- An api call reaches the host once the program starts it (awaits it or attaches a handler). A call
|
|
40
|
+
that was started is committed, like an in-flight promise: it runs before the program completes,
|
|
41
|
+
even when `Promise.race` or a failed `Promise.all` moved on or the program returned without
|
|
42
|
+
waiting. A call that was never started no longer runs in the background; the program fails with
|
|
43
|
+
`UNAWAITED_OPERATION` and nothing was sent for it. Arguments are copied when the call is made.
|
|
44
|
+
- `panel` and `sync` no longer consume the provider budget: a program can make 16 provider calls and
|
|
45
|
+
48 board operations, so a board is no longer capped at 8 panels. `CODE_MODE_LIMITS` exports the
|
|
46
|
+
defaults, and `limits` overrides them.
|
|
47
|
+
|
|
48
|
+
### Added
|
|
49
|
+
|
|
50
|
+
- `CodeModeError`, `CODE_MODE_ERROR_CODES`, `formatCodeModeError`, `isCodeModeError`,
|
|
51
|
+
`CODE_MODE_LIMITS`, `assertSandboxIsolation` and the `SnippetChainOptions` type from
|
|
52
|
+
`@mcpview/compose/code-mode`.
|
|
53
|
+
- ADR 0006 records how Compose runs agent-written Code Mode programs.
|
|
54
|
+
|
|
55
|
+
### Fixed
|
|
56
|
+
|
|
57
|
+
- Cap the height a viewer can claim with `ui/notifications/size-changed` at 2400 px, advertised as
|
|
58
|
+
`containerDimensions.maxHeight`. A report such as `1e12` no longer stretches the board, and a
|
|
59
|
+
viewer whose content follows its own frame (`min-height: 100vh` plus padding) stops growing there.
|
|
60
|
+
`VIEWER_HEIGHT_CAPPED` is logged once per viewer.
|
|
61
|
+
- Keep the template height of a viewer that never reports its height once the board sizes its rows
|
|
62
|
+
from content, instead of dropping it to 200 px.
|
|
63
|
+
- Apply viewer heights at once, as before, even while an embedded board's MCP Apps handshake is
|
|
64
|
+
pending, so plain iframe embeds keep resizing their viewers. Only an enclosing host that
|
|
65
|
+
explicitly refuses `ui/initialize` (an error reply or another protocol version) makes the board
|
|
66
|
+
fill its frame again, drop its native heights and ignore later viewer reports for sizing. The
|
|
67
|
+
refusal is logged as `CARD_HANDSHAKE_FAILED` with the expected and received protocol versions.
|
|
68
|
+
Committed panel placements are recomputed when the board changes layout mode. If ChatGPT's height
|
|
69
|
+
bridge appears after a refusal, the board is sized through it again.
|
|
70
|
+
- A host error whose serializer throws no longer causes an unhandled rejection in the host: replies
|
|
71
|
+
are built from the error's base fields and any failure settles the run with `SANDBOX_FAILED`.
|
|
72
|
+
- An unexpected worker exit aborts in-flight provider calls (their signal), and still reports
|
|
73
|
+
`SANDBOX_FAILED`.
|
|
74
|
+
- Quoted values in `NODE_OPTIONS` (for example `--conditions="custom condition"`) are parsed and
|
|
75
|
+
forwarded to the worker with Node's quoting rules.
|
|
76
|
+
- `PROVIDER_UNAVAILABLE` after a dispatch tells the guest to check whether the operation took effect
|
|
77
|
+
before retrying.
|
|
78
|
+
- A never-started call is reported as `UNAWAITED_OPERATION` before an invalid return value.
|
|
79
|
+
- A parameter rejected before the store write is reported as such, not as an uncertain
|
|
80
|
+
`SAVE_FAILED`.
|
|
81
|
+
- README: before provider dispatch, `execute` preserves the caller's original abort reason.
|
|
82
|
+
- Code Mode never starts a provider call after the wall deadline, even when a slow `names` lookup
|
|
83
|
+
held the event loop; inline startup of QuickJS is cancellable; calls started by a `toJSON` that
|
|
84
|
+
then fails are still run before `RESULT_INVALID`; a guest error property read that crosses the CPU
|
|
85
|
+
limit reports `TIME_LIMIT`; a store's own `AbortError` is `CATALOG_ERROR` and a caller's abort
|
|
86
|
+
reason is kept when a catalog lookup fails meanwhile.
|
|
87
|
+
- A provider error with code `UNAVAILABLE` is reported as such instead of a generic execution error.
|
|
88
|
+
- `listSnippets` counts as a provider dispatch: guest text is redacted and errors carry
|
|
89
|
+
`effects: "possible"` after a catalogue read, as after `runSnippet`.
|
|
90
|
+
- The wall deadline is checked right before a provider call starts, so work queued behind a busy
|
|
91
|
+
event loop no longer begins after the deadline.
|
|
92
|
+
- A host result that decodes past the VM's memory reports `RESOURCE_LIMIT` instead of
|
|
93
|
+
`OPERATION_FAILED`. The host also rejects a result over `valueLength` before posting it to the
|
|
94
|
+
worker.
|
|
95
|
+
- A save whose acknowledgement is lost reports `SAVE_FAILED` (check `listSaved` before retrying)
|
|
96
|
+
even when the program called no provider. A caller's own abort reason is preserved before any
|
|
97
|
+
provider call.
|
|
98
|
+
- `memoryBytes` and `stackBytes` above 2 GiB - 1 are rejected instead of wrapping at the WASM
|
|
99
|
+
boundary. Values too small for the VM to start (under 64 KiB of memory or 16 KiB of stack) are
|
|
100
|
+
rejected at configuration instead of failing every run with `SANDBOX_FAILED`.
|
|
101
|
+
- A stack or memory overflow while serializing a program's result or an api argument (a recursive
|
|
102
|
+
`toJSON`) reports `RESOURCE_LIMIT` instead of `RESULT_INVALID` or `ARGUMENT_INVALID`.
|
|
103
|
+
- A call started by a result's `toJSON` runs before the program completes, and a call it declared
|
|
104
|
+
without starting reports `UNAWAITED_OPERATION`, like any other call.
|
|
105
|
+
- A browser-targeted bundle that selects `isolation: "inline"` no longer fails to resolve
|
|
106
|
+
`node:worker_threads`: the Node worker adapter loads it at run time.
|
|
107
|
+
- Under Node's permission model without `--allow-worker`, worker isolation fails with
|
|
108
|
+
`SANDBOX_UNAVAILABLE` (at configuration, or when the worker constructor is refused) instead of
|
|
109
|
+
`SANDBOX_FAILED`. Audit mode is not treated as a denial.
|
|
110
|
+
- A catalog write that the store confirmed after the caller aborted is reported as interrupted (the
|
|
111
|
+
message says the chain was saved and to call `listSaved`); the name stays counted. A store that
|
|
112
|
+
fails with a `DOMException` while writing reports `SAVE_FAILED`, not the raw exception.
|
|
113
|
+
- Documented: a caller abort rejects with a `DOMException` (`AbortError` or `TimeoutError`), not a
|
|
114
|
+
`CodeModeError`, so it carries no `effects` field. The 128 KiB value limit counts UTF-16 code
|
|
115
|
+
units of the JSON text, not UTF-8 bytes.
|
|
116
|
+
|
|
117
|
+
## [0.13.1] - 2026-11-27
|
|
118
|
+
|
|
119
|
+
### Added
|
|
120
|
+
|
|
121
|
+
- Route events between mounted Code Mode panels through their declared ports. A linked panel can
|
|
122
|
+
update its result while the user keeps a separate selection in the conversation.
|
|
123
|
+
- Capture and restore a dashboard's committed positions and supported widths using stable panel IDs.
|
|
124
|
+
Hosts can associate an acknowledged layout revision with an authenticated Code Mode execution.
|
|
125
|
+
- The Code Mode board can publish layout acknowledgements and merge selections from mounted panels
|
|
126
|
+
into the host's conversation context.
|
|
127
|
+
|
|
8
128
|
## [0.13.0] - 2026-11-27
|
|
9
129
|
|
|
10
130
|
### Added
|
package/README.md
CHANGED
|
@@ -119,6 +119,55 @@ per call. The host derives this scope from the authenticated user and integratio
|
|
|
119
119
|
the program and its parameter types. `replay` runs it with fresh inputs and the caller's current
|
|
120
120
|
provider permissions.
|
|
121
121
|
|
|
122
|
+
Each program runs in QuickJS with no host bindings. By default it runs in a short-lived worker, so a
|
|
123
|
+
CPU-bound program cannot block the server: `createSnippetChain(providers, catalog, { isolation })`
|
|
124
|
+
accepts `"worker"` (default) or `"inline"`. Use `"inline"` explicitly in runtimes or bundles that
|
|
125
|
+
cannot start the worker module. An unavailable isolation fails at configuration with
|
|
126
|
+
`SANDBOX_UNAVAILABLE`, never by falling back silently. Under Deno the worker inherits the host's
|
|
127
|
+
permissions: grant read access to the `code-mode` directory of the package (import access when
|
|
128
|
+
loaded from JSR) and to the QuickJS WASM file shipped with `quickjs-emscripten`. Configuration only
|
|
129
|
+
checks the worker module itself; a missing grant for the other files fails the first run with
|
|
130
|
+
`SANDBOX_FAILED`, so run one program at startup to verify the setup. `CODE_MODE_LIMITS` gives the
|
|
131
|
+
defaults: 2 s of guest CPU (host calls excluded), 30 s of wall time, 12 MiB of memory, 16 provider
|
|
132
|
+
calls (`listSnippets`, `runSnippet`) and 48 board operations (`panel`, `sync`) per program. Pass
|
|
133
|
+
`limits` to override some of them (`memoryBytes` must be at least 64 KiB and `stackBytes` at least
|
|
134
|
+
16 KiB, or configuration throws a `RangeError`). `valueLength` counts UTF-16 code units of the JSON
|
|
135
|
+
text, not UTF-8 bytes. Under Node's permission model, workers need `--allow-worker`; without it
|
|
136
|
+
configuration fails with `SANDBOX_UNAVAILABLE` (audit mode does not count). Browsers have no worker
|
|
137
|
+
guest: a browser-targeted bundle must use `isolation: "inline"` (the default `"worker"` fails at
|
|
138
|
+
configuration with `SANDBOX_UNAVAILABLE`); the Node worker adapter is loaded at run time, so
|
|
139
|
+
bundlers do not resolve `node:worker_threads`. `NODE_OPTIONS` that a worker cannot start with (such
|
|
140
|
+
as `--input-type`) are not passed to it either.
|
|
141
|
+
|
|
142
|
+
**Breaking change: calls dispatch in the order they are awaited.** A call reaches the provider when
|
|
143
|
+
the program starts it, not where it is written. A program that stores
|
|
144
|
+
`const write =
|
|
145
|
+
api.runSnippet(...)`, awaits a read and only then awaits `write` now sends the read
|
|
146
|
+
first; before, the provider received the write first. Await calls in the order they must run,
|
|
147
|
+
including in saved chains: edit any saved chain that relied on declaration order and save it again.
|
|
148
|
+
|
|
149
|
+
Every api call is lazy: it reaches the host once the program starts it (awaits it or attaches a
|
|
150
|
+
handler). A started call is committed like an in-flight promise and runs before the program
|
|
151
|
+
completes, even if `Promise.race` moved on. A call the program never started never runs and the
|
|
152
|
+
program fails with `UNAWAITED_OPERATION`; that check applies when the program returns, so a program
|
|
153
|
+
that throws or stalls reports `GUEST_ERROR` or `GUEST_STALLED` instead. A provider call never starts
|
|
154
|
+
after the wall limit has passed, and an exhausted CPU or wall limit wins over a guest error.
|
|
155
|
+
Failures are `CodeModeError`s whose message reads `[execute] CODE: detail. Recovery: hint.`, so a
|
|
156
|
+
host that forwards `error.message` keeps the code. Inside the program, a failed api call throws an
|
|
157
|
+
`Error` with `code`, `recovery` and `context`. Once a provider call was dispatched, errors carry
|
|
158
|
+
`effects: "possible"` and never repeat guest, provider or transport text. A program's result is
|
|
159
|
+
serialized once at the end, and calls its `toJSON` starts are run before the program completes.
|
|
160
|
+
|
|
161
|
+
A caller abort is not a `CodeModeError`: once a provider was dispatched or a save confirmed,
|
|
162
|
+
`execute` rejects with a `DOMException` (`AbortError`, or `TimeoutError` for a timeout) so a host
|
|
163
|
+
can tell a cancelled task from a failed one. Before any provider dispatch, `execute` preserves the
|
|
164
|
+
caller's original abort reason, whatever its type (for example `new Error("stop")`), so detect a
|
|
165
|
+
cancellation through your own `AbortSignal`, not through `DOMException` alone. A `DOMException` has
|
|
166
|
+
no `effects` field: after a provider call was dispatched, or after a chain was saved, its message
|
|
167
|
+
reads `[execute] INTERRUPTED: ... Recovery: ...` and says to check the effects or call `listSaved`.
|
|
168
|
+
A save the store confirmed after the caller aborted is still saved. A failure of the catalog write
|
|
169
|
+
itself is `SAVE_FAILED`, whatever exception the store threw.
|
|
170
|
+
|
|
122
171
|
In the board's MCP Apps tool-result handler, call `composeSnippetBoard(result, { layout: "split" })`
|
|
123
172
|
from `@mcpview/compose/code-mode/board`. Each selected receipt has its own component ID, including
|
|
124
173
|
two instances of the same viewer. The board renders each child from `child.context.panel.result`.
|
|
@@ -127,6 +176,28 @@ path uses results already returned by the script. The runnable engineering examp
|
|
|
127
176
|
server, both providers, and a single-frame board with a 3D viewer and interactive print report.
|
|
128
177
|
[Engineering example and setup](https://github.com/mcpview/mcpview/tree/main/packages/compose/examples/multi-mcp-snippets)
|
|
129
178
|
|
|
179
|
+
The server can declare event ports for each snippet under the provider binding's `events` field. For
|
|
180
|
+
example, use
|
|
181
|
+
`{ "invoice-list": { emits: ["invoice.selected"] }, "invoice-detail": {
|
|
182
|
+
accepts: ["invoice.focus"] } }`.
|
|
183
|
+
The `execute` description advertises the configured ports. Once the program has selected both
|
|
184
|
+
receipts with `api.panel`, it can add a route:
|
|
185
|
+
|
|
186
|
+
```js
|
|
187
|
+
await api.sync({
|
|
188
|
+
from: list.id,
|
|
189
|
+
event: "invoice.selected",
|
|
190
|
+
to: detail.id,
|
|
191
|
+
action: "invoice.focus",
|
|
192
|
+
});
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
The route is scoped to those two receipts in the current result. For local renderers, declare the
|
|
196
|
+
implemented ports in each `resolveView` result and call
|
|
197
|
+
`emitSnippetBoardEvent(descriptor, sourceReceiptId, event, data, deliver)` with the active board
|
|
198
|
+
descriptor. The board's `deliver(targetReceiptId, action, data)` callback handles the action
|
|
199
|
+
locally. The target view owns validation of its action data.
|
|
200
|
+
|
|
130
201
|
## MCP SDK compatibility
|
|
131
202
|
|
|
132
203
|
Compose uses MCP Apps 2.x and the split MCP SDK 2.x packages. Integrations importing SDK types or
|
|
@@ -240,8 +311,63 @@ Drag the bottom-right corner to preview an allowed width. At the right edge of t
|
|
|
240
311
|
to reach a wider format. The skeleton reserves the space and neighbors shift sideways or wrap to a
|
|
241
312
|
new row. When the viewer shrinks, its neighbor returns beside it with the template's original gap as
|
|
242
313
|
soon as both fit. Release to apply the width or press Escape to cancel. The left and right arrow
|
|
243
|
-
keys step between available widths when the corner has focus.
|
|
244
|
-
|
|
314
|
+
keys step between available widths when the corner has focus. The template supplies the initial
|
|
315
|
+
layout unless the host restores a saved layout. Each iframe stays mounted and reports its own
|
|
316
|
+
content height as its width changes.
|
|
317
|
+
|
|
318
|
+
A Code Mode host can store panel order, requested widths and relative placements with a snippet.
|
|
319
|
+
Give each panel a stable `data-compose-panel-id` across runs, including when two panels use the same
|
|
320
|
+
viewer.
|
|
321
|
+
|
|
322
|
+
Use one context writer per mounted App. Give each panel its own writer with
|
|
323
|
+
`contexts.forPanel(id, title, basketSignal)`. The board uses the same queue to publish the execution
|
|
324
|
+
reference and revision that the model can use to save a layout. A month or record selected in a
|
|
325
|
+
panel stays in the conversation when the user moves the panel.
|
|
326
|
+
|
|
327
|
+
```ts
|
|
328
|
+
import { connectSnippetBoardLayout, createPanelContexts } from "@mcpview/compose/code-mode/board";
|
|
329
|
+
|
|
330
|
+
const contexts = createPanelContexts(app.updateModelContext.bind(app));
|
|
331
|
+
const retry = connectSnippetBoardLayout(board, {
|
|
332
|
+
host: app,
|
|
333
|
+
stageTool: "stage_dashboard_layout", // App-only callback registered by your server
|
|
334
|
+
runId,
|
|
335
|
+
savedLayout,
|
|
336
|
+
updateContext: contexts.forBoard(displaySignal),
|
|
337
|
+
signal: displaySignal,
|
|
338
|
+
onStatus: showLayoutStatus,
|
|
339
|
+
});
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
`connectSnippetBoardLayout` installs the move and resize controls, restores a saved layout and
|
|
343
|
+
stages each committed gesture. The server acknowledges the revision before the writer publishes its
|
|
344
|
+
`ready` receipt using the host's supported context format. The App supplies its own status display
|
|
345
|
+
and can call `retry()` after an error. Give the layout receipt the lifetime of the displayed board.
|
|
346
|
+
If a save confirmation replaces the board while the basket still belongs to the conversation, end
|
|
347
|
+
the display lifetime and call `contexts.clear()` to remove expired contributions. End the basket
|
|
348
|
+
lifetime and clear again when the selection is discarded.
|
|
349
|
+
|
|
350
|
+
On a text-only host, Compose forwards the panels' content blocks in order. In structured context,
|
|
351
|
+
multiple selections are grouped under `panels` with their titles. A single panel keeps its original
|
|
352
|
+
shape unless a board metadata key overlaps, in which case its selection also appears under `panels`.
|
|
353
|
+
|
|
354
|
+
To associate edits with the correct execution, the server can use `BoardLayoutRuns` from
|
|
355
|
+
`@mcpview/compose/code-mode/layout-runs`. Register the scoped execution with `open`, passing a map
|
|
356
|
+
from stable panel IDs to their declared widths. `stage` acknowledges a snapshot and revision from
|
|
357
|
+
the app. On an explicit save or update, `selected` supplies the acknowledged geometry to the snippet
|
|
358
|
+
catalog. Call `saved` only after a successful save. Updates accept names bound by saving or
|
|
359
|
+
replaying this dashboard. Repeating a stage request with the same revision and geometry is safe if
|
|
360
|
+
the response was lost. A user-initiated retry in the App stages the current layout with a new
|
|
361
|
+
revision.
|
|
362
|
+
|
|
363
|
+
On a fresh board, `restorePanelLayout(board, snapshot)` applies the saved preference once the
|
|
364
|
+
controls are installed. It returns false if the panel IDs or supported widths have changed
|
|
365
|
+
incompatibly. On narrow screens the controls apply a width that fits and retain the requested width
|
|
366
|
+
for a larger screen.
|
|
367
|
+
|
|
368
|
+
`@mcpview/compose/code-mode/layout` exports the `PanelLayoutSnapshot` type and the DOM-independent
|
|
369
|
+
`isPanelLayoutSnapshot` validator. The board entry point (`@mcpview/compose/code-mode/board`) also
|
|
370
|
+
exports these and the browser capture and restore functions.
|
|
245
371
|
|
|
246
372
|
For a Code Mode board with local renderers, `@mcpview/compose/code-mode/board` exports
|
|
247
373
|
`getPanelControlsCss()`, `installPanelMovement(board, signal?)` and
|
|
@@ -561,6 +687,9 @@ acknowledgement; notifications without an `id` receive no response. This follows
|
|
|
561
687
|
| `NO_UI_METADATA` | Tool result has no UI metadata |
|
|
562
688
|
| `EMPTY_RESOURCES` | No resources provided to composer |
|
|
563
689
|
|
|
690
|
+
**Code Mode errors (`CodeModeErrorCode`):** see `CODE_MODE_ERROR_CODES` in
|
|
691
|
+
`@mcpview/compose/code-mode`. Messages read `[execute] CODE: detail. Recovery: hint.`
|
|
692
|
+
|
|
564
693
|
**Runtime errors (`RuntimeErrorCode`):**
|
|
565
694
|
|
|
566
695
|
| Code | Description |
|
package/esm/_dnt.polyfills.d.ts
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
declare global {
|
|
2
|
+
interface Object {
|
|
3
|
+
/**
|
|
4
|
+
* Determines whether an object has a property with the specified name.
|
|
5
|
+
* @param o An object.
|
|
6
|
+
* @param v A property name.
|
|
7
|
+
*/
|
|
8
|
+
hasOwn(o: object, v: PropertyKey): boolean;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
export {};
|
|
1
12
|
declare global {
|
|
2
13
|
interface Array<T> {
|
|
3
14
|
/**
|
|
@@ -47,17 +58,6 @@ declare global {
|
|
|
47
58
|
}
|
|
48
59
|
}
|
|
49
60
|
export {};
|
|
50
|
-
declare global {
|
|
51
|
-
interface Object {
|
|
52
|
-
/**
|
|
53
|
-
* Determines whether an object has a property with the specified name.
|
|
54
|
-
* @param o An object.
|
|
55
|
-
* @param v A property name.
|
|
56
|
-
*/
|
|
57
|
-
hasOwn(o: object, v: PropertyKey): boolean;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
export {};
|
|
61
61
|
declare global {
|
|
62
62
|
interface Error {
|
|
63
63
|
cause?: unknown;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_dnt.polyfills.d.ts","sourceRoot":"","sources":["../src/_dnt.polyfills.ts"],"names":[],"mappings":"
|
|
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/esm/_dnt.polyfills.js
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
// https://github.com/tc39/proposal-accessible-object-hasownproperty/blob/main/polyfill.js
|
|
2
|
+
if (!Object.hasOwn) {
|
|
3
|
+
Object.defineProperty(Object, "hasOwn", {
|
|
4
|
+
value: function (object, property) {
|
|
5
|
+
if (object == null) {
|
|
6
|
+
throw new TypeError("Cannot convert undefined or null to object");
|
|
7
|
+
}
|
|
8
|
+
return Object.prototype.hasOwnProperty.call(Object(object), property);
|
|
9
|
+
},
|
|
10
|
+
configurable: true,
|
|
11
|
+
enumerable: false,
|
|
12
|
+
writable: true,
|
|
13
|
+
});
|
|
14
|
+
}
|
|
1
15
|
function findLastIndex(self, callbackfn, that) {
|
|
2
16
|
const boundFunc = that === undefined ? callbackfn : callbackfn.bind(that);
|
|
3
17
|
let index = self.length - 1;
|
|
@@ -34,18 +48,4 @@ if (!Uint8Array.prototype.findLast) {
|
|
|
34
48
|
return findLast(this, callbackfn, that);
|
|
35
49
|
};
|
|
36
50
|
}
|
|
37
|
-
// https://github.com/tc39/proposal-accessible-object-hasownproperty/blob/main/polyfill.js
|
|
38
|
-
if (!Object.hasOwn) {
|
|
39
|
-
Object.defineProperty(Object, "hasOwn", {
|
|
40
|
-
value: function (object, property) {
|
|
41
|
-
if (object == null) {
|
|
42
|
-
throw new TypeError("Cannot convert undefined or null to object");
|
|
43
|
-
}
|
|
44
|
-
return Object.prototype.hasOwnProperty.call(Object(object), property);
|
|
45
|
-
},
|
|
46
|
-
configurable: true,
|
|
47
|
-
enumerable: false,
|
|
48
|
-
writable: true,
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
51
|
export {};
|
|
@@ -3,11 +3,17 @@
|
|
|
3
3
|
* @module
|
|
4
4
|
*/
|
|
5
5
|
import "../../_dnt.polyfills.js";
|
|
6
|
-
import type { ComponentSurface } from "../core/types/components.js";
|
|
6
|
+
import type { ComponentSurface, ViewComponentEventPorts } from "../core/types/components.js";
|
|
7
7
|
import type { CompositeUiDescriptor } from "../core/types/descriptor.js";
|
|
8
8
|
import type { UiLayout } from "../core/types/layout.js";
|
|
9
|
+
import type { UiSyncRule } from "../core/types/sync-rules.js";
|
|
10
|
+
import { SNIPPET_SYNC_META_KEY } from "./sync.js";
|
|
11
|
+
export { SNIPPET_SYNC_META_KEY };
|
|
12
|
+
export { createPanelContexts, type PanelContexts, type PanelContextUpdate, type SendPanelContext, } from "./panel-contexts.js";
|
|
13
|
+
export { connectSnippetBoardLayout, type SnippetBoardLayoutOptions, type SnippetLayoutReceipt, type SnippetLayoutStatus, } from "./layout-publisher.js";
|
|
9
14
|
export { getPanelControlsCss } from "../host/renderer/css/panel-controls.js";
|
|
10
|
-
export {
|
|
15
|
+
export { isPanelLayoutSnapshot, type PanelLayoutSnapshot } from "./layout.js";
|
|
16
|
+
export { capturePanelLayout, installPanelMovement, installPanelResizing, restorePanelLayout, } from "../host/renderer/panel-controls.js";
|
|
11
17
|
/** MCP App result metadata containing the receipts selected by the program. */
|
|
12
18
|
export declare const SNIPPET_PANELS_META_KEY = "io.mcpview/snippet-panels";
|
|
13
19
|
/** A selected provider result. The receipt ID distinguishes calls to the same snippet. */
|
|
@@ -17,6 +23,7 @@ export interface SnippetPanel {
|
|
|
17
23
|
readonly name: string;
|
|
18
24
|
readonly title: string;
|
|
19
25
|
readonly result: Record<string, unknown>;
|
|
26
|
+
readonly events?: ViewComponentEventPorts;
|
|
20
27
|
}
|
|
21
28
|
/** An App-owned view for a receipt, with optional renderer data and component selection. */
|
|
22
29
|
export interface SnippetPanelView {
|
|
@@ -25,6 +32,8 @@ export interface SnippetPanelView {
|
|
|
25
32
|
readonly surface?: ComponentSurface;
|
|
26
33
|
/** Widths offered by this local view in CSS pixels. An empty list disables resizing. */
|
|
27
34
|
readonly supportedWidths?: readonly number[];
|
|
35
|
+
/** Restrict routing to the ports implemented by this local view. */
|
|
36
|
+
readonly events?: ViewComponentEventPorts;
|
|
28
37
|
}
|
|
29
38
|
/** Display options supplied by the board hosting the results. */
|
|
30
39
|
export interface SnippetBoardOptions {
|
|
@@ -46,6 +55,8 @@ export interface SnippetBoardOptions {
|
|
|
46
55
|
* ```
|
|
47
56
|
*/
|
|
48
57
|
export declare function readSnippetPanels(result: unknown): SnippetPanel[];
|
|
58
|
+
/** Read unique, declared Compose routes between panels in this result. */
|
|
59
|
+
export declare function readSnippetSyncRules(result: unknown): UiSyncRule[];
|
|
49
60
|
/**
|
|
50
61
|
* Build a Compose descriptor from the current execution, without making any provider calls.
|
|
51
62
|
* Each child keeps its receipt in `context.panel` and adapter data in `context.view`.
|
|
@@ -63,4 +74,9 @@ export declare function readSnippetPanels(result: unknown): SnippetPanel[];
|
|
|
63
74
|
* ```
|
|
64
75
|
*/
|
|
65
76
|
export declare function composeSnippetBoard(result: unknown, options?: SnippetBoardOptions): CompositeUiDescriptor;
|
|
77
|
+
/**
|
|
78
|
+
* Deliver a JSON event through the current board's declared routes to mounted views.
|
|
79
|
+
* The board owns dispatch and supplies the receipts and data from its active UI.
|
|
80
|
+
*/
|
|
81
|
+
export declare function emitSnippetBoardEvent(descriptor: CompositeUiDescriptor, sourceReceiptId: string, event: string, data: unknown, deliver: (targetReceiptId: string, action: string, data: unknown) => void): void;
|
|
66
82
|
//# sourceMappingURL=board.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"board.d.ts","sourceRoot":"","sources":["../../../src/src/code-mode/board.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,yBAAyB,CAAC;AAMjC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;
|
|
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,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAC7F,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AACzE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EAGL,qBAAqB,EAGtB,MAAM,WAAW,CAAC;AAEnB,OAAO,EAAE,qBAAqB,EAAE,CAAC;AAEjC,OAAO,EACL,mBAAmB,EACnB,KAAK,aAAa,EAClB,KAAK,kBAAkB,EACvB,KAAK,gBAAgB,GACtB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,yBAAyB,EACzB,KAAK,yBAAyB,EAC9B,KAAK,oBAAoB,EACzB,KAAK,mBAAmB,GACzB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,mBAAmB,EAAE,MAAM,wCAAwC,CAAC;AAC7E,OAAO,EAAE,qBAAqB,EAAE,KAAK,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAC9E,OAAO,EACL,kBAAkB,EAClB,oBAAoB,EACpB,oBAAoB,EACpB,kBAAkB,GACnB,MAAM,oCAAoC,CAAC;AAE5C,+EAA+E;AAC/E,eAAO,MAAM,uBAAuB,8BAA8B,CAAC;AAEnE,0FAA0F;AAC1F,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACzC,QAAQ,CAAC,MAAM,CAAC,EAAE,uBAAuB,CAAC;CAC3C;AAED,4FAA4F;AAC5F,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC3C,QAAQ,CAAC,OAAO,CAAC,EAAE,gBAAgB,CAAC;IACpC,wFAAwF;IACxF,QAAQ,CAAC,eAAe,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC7C,oEAAoE;IACpE,QAAQ,CAAC,MAAM,CAAC,EAAE,uBAAuB,CAAC;CAC3C;AAED,iEAAiE;AACjE,MAAM,WAAW,mBAAmB;IAClC,yFAAyF;IACzF,QAAQ,CAAC,MAAM,CAAC,EAAE,QAAQ,GAAG,CAAC,CAAC,KAAK,EAAE,MAAM,KAAK,QAAQ,CAAC,CAAC;IAC3D,+FAA+F;IAC/F,QAAQ,CAAC,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,gBAAgB,GAAG,SAAS,CAAC;CAC9E;AAcD;;;;;;;;;;;GAWG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,OAAO,GAAG,YAAY,EAAE,CAajE;AAED,0EAA0E;AAC1E,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,OAAO,GAAG,UAAU,EAAE,CAmBlE;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,OAAO,EACf,OAAO,GAAE,mBAAwB,GAChC,qBAAqB,CAuCvB;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CACnC,UAAU,EAAE,qBAAqB,EACjC,eAAe,EAAE,MAAM,EACvB,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,OAAO,EACb,OAAO,EAAE,CAAC,eAAe,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,KAAK,IAAI,GACxE,IAAI,CAoBN"}
|
|
@@ -6,8 +6,13 @@ import "../../_dnt.polyfills.js";
|
|
|
6
6
|
import { createCollector } from "../core/collector/collector.js";
|
|
7
7
|
import { extractUiMeta } from "../core/collector/extractor.js";
|
|
8
8
|
import { buildCompositeUi } from "../core/composer/composer.js";
|
|
9
|
+
import { parseSnippetSyncRule, readSnippetEventPorts, SNIPPET_SYNC_META_KEY, snippetSyncKey, supportsSnippetSync, } from "./sync.js";
|
|
10
|
+
export { SNIPPET_SYNC_META_KEY };
|
|
11
|
+
export { createPanelContexts, } from "./panel-contexts.js";
|
|
12
|
+
export { connectSnippetBoardLayout, } from "./layout-publisher.js";
|
|
9
13
|
export { getPanelControlsCss } from "../host/renderer/css/panel-controls.js";
|
|
10
|
-
export {
|
|
14
|
+
export { isPanelLayoutSnapshot } from "./layout.js";
|
|
15
|
+
export { capturePanelLayout, installPanelMovement, installPanelResizing, restorePanelLayout, } from "../host/renderer/panel-controls.js";
|
|
11
16
|
/** MCP App result metadata containing the receipts selected by the program. */
|
|
12
17
|
export const SNIPPET_PANELS_META_KEY = "io.mcpview/snippet-panels";
|
|
13
18
|
function record(value) {
|
|
@@ -48,6 +53,33 @@ export function readSnippetPanels(result) {
|
|
|
48
53
|
}
|
|
49
54
|
return panels;
|
|
50
55
|
}
|
|
56
|
+
/** Read unique, declared Compose routes between panels in this result. */
|
|
57
|
+
export function readSnippetSyncRules(result) {
|
|
58
|
+
if (!record(result) || !record(result._meta))
|
|
59
|
+
return [];
|
|
60
|
+
const routes = result._meta[SNIPPET_SYNC_META_KEY];
|
|
61
|
+
const items = result._meta[SNIPPET_PANELS_META_KEY];
|
|
62
|
+
if (!Array.isArray(routes) || !Array.isArray(items))
|
|
63
|
+
return [];
|
|
64
|
+
const panels = new Map();
|
|
65
|
+
const duplicates = new Set();
|
|
66
|
+
for (const item of items) {
|
|
67
|
+
if (!isPanel(item))
|
|
68
|
+
continue;
|
|
69
|
+
if (panels.has(item.id))
|
|
70
|
+
duplicates.add(item.id);
|
|
71
|
+
panels.set(item.id, readSnippetEventPorts(item.events));
|
|
72
|
+
}
|
|
73
|
+
for (const id of duplicates)
|
|
74
|
+
panels.delete(id);
|
|
75
|
+
const rules = new Map();
|
|
76
|
+
for (const item of routes) {
|
|
77
|
+
const rule = parseSnippetSyncRule(item);
|
|
78
|
+
if (rule && supportsSnippetSync(rule, panels))
|
|
79
|
+
rules.set(snippetSyncKey(rule), rule);
|
|
80
|
+
}
|
|
81
|
+
return [...rules.values()];
|
|
82
|
+
}
|
|
51
83
|
/**
|
|
52
84
|
* Build a Compose descriptor from the current execution, without making any provider calls.
|
|
53
85
|
* Each child keeps its receipt in `context.panel` and adapter data in `context.view`.
|
|
@@ -69,13 +101,24 @@ export function composeSnippetBoard(result, options = {}) {
|
|
|
69
101
|
? result.structuredContent
|
|
70
102
|
: {};
|
|
71
103
|
const collector = createCollector();
|
|
104
|
+
const mountedPorts = new Map();
|
|
72
105
|
for (const panel of readSnippetPanels(result)) {
|
|
73
106
|
const view = options.resolveView?.(panel);
|
|
74
107
|
const resourceUri = view?.resourceUri ?? extractUiMeta(panel.result)?.resourceUri;
|
|
75
108
|
if (!resourceUri || !/^ui:\/\/[^\s]+$/.test(resourceUri))
|
|
76
109
|
continue;
|
|
110
|
+
const declared = readSnippetEventPorts(panel.events);
|
|
111
|
+
const viewEvents = readSnippetEventPorts(view?.events);
|
|
112
|
+
const panelEvents = view
|
|
113
|
+
? {
|
|
114
|
+
emits: declared?.emits?.filter((name) => viewEvents?.emits?.includes(name)),
|
|
115
|
+
accepts: declared?.accepts?.filter((name) => viewEvents?.accepts?.includes(name)),
|
|
116
|
+
}
|
|
117
|
+
: declared;
|
|
118
|
+
mountedPorts.set(panel.id, panelEvents);
|
|
77
119
|
collector.collect(`${panel.provider}:${panel.name}`, { _meta: { ui: { resourceUri } } }, {
|
|
78
120
|
panel,
|
|
121
|
+
panelEvents,
|
|
79
122
|
...(view?.context === undefined ? {} : { view: view.context }),
|
|
80
123
|
...(Object.hasOwn(summary, "value") ? { value: summary.value } : {}),
|
|
81
124
|
}, { componentId: panel.id, surface: view?.surface, supportedWidths: view?.supportedWidths });
|
|
@@ -84,5 +127,34 @@ export function composeSnippetBoard(result, options = {}) {
|
|
|
84
127
|
const layout = typeof options.layout === "function"
|
|
85
128
|
? options.layout(resources.length)
|
|
86
129
|
: options.layout;
|
|
87
|
-
|
|
130
|
+
const sync = readSnippetSyncRules(result).filter((rule) => supportsSnippetSync(rule, mountedPorts));
|
|
131
|
+
return buildCompositeUi(resources, { layout: layout ?? "stack", sharedContext: ["value"], sync });
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Deliver a JSON event through the current board's declared routes to mounted views.
|
|
135
|
+
* The board owns dispatch and supplies the receipts and data from its active UI.
|
|
136
|
+
*/
|
|
137
|
+
export function emitSnippetBoardEvent(descriptor, sourceReceiptId, event, data, deliver) {
|
|
138
|
+
const source = descriptor.children.find((child) => child.componentId === sourceReceiptId);
|
|
139
|
+
if (!source || !readSnippetEventPorts(source.context?.panelEvents)?.emits?.includes(event)) {
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
let payload;
|
|
143
|
+
try {
|
|
144
|
+
payload = JSON.stringify(data);
|
|
145
|
+
}
|
|
146
|
+
catch {
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
if (payload === undefined || payload.length > 128 * 1024)
|
|
150
|
+
return;
|
|
151
|
+
for (const rule of descriptor.sync) {
|
|
152
|
+
if (rule.from !== source.slot || rule.event !== event || rule.to === "*")
|
|
153
|
+
continue;
|
|
154
|
+
const target = descriptor.children.find((child) => child.slot === rule.to);
|
|
155
|
+
const ports = readSnippetEventPorts(target?.context?.panelEvents);
|
|
156
|
+
if (target?.componentId && ports?.accepts?.includes(rule.action)) {
|
|
157
|
+
deliver(target.componentId, rule.action, JSON.parse(payload));
|
|
158
|
+
}
|
|
159
|
+
}
|
|
88
160
|
}
|
|
@@ -1,6 +1,8 @@
|
|
|
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";
|
|
5
|
+
import { type SandboxIsolation, type SandboxLimits } from "./sandbox.js";
|
|
4
6
|
/** Selected native result, available only to the MCP App in result metadata. */
|
|
5
7
|
export interface SnippetPanelReceipt {
|
|
6
8
|
id: string;
|
|
@@ -8,6 +10,18 @@ export interface SnippetPanelReceipt {
|
|
|
8
10
|
name: string;
|
|
9
11
|
title: string;
|
|
10
12
|
result: CallToolResult;
|
|
13
|
+
events?: ViewComponentEventPorts;
|
|
14
|
+
}
|
|
15
|
+
/** Options of {@link createSnippetChain}. */
|
|
16
|
+
export interface SnippetChainOptions {
|
|
17
|
+
/**
|
|
18
|
+
* Where programs run. Defaults to `"worker"`, which keeps the host
|
|
19
|
+
* responsive. Use `"inline"` explicitly in runtimes or bundles without
|
|
20
|
+
* workers. An unavailable isolation fails here with `SANDBOX_UNAVAILABLE`.
|
|
21
|
+
*/
|
|
22
|
+
readonly isolation?: SandboxIsolation;
|
|
23
|
+
/** Override some limits of each program (see `CODE_MODE_LIMITS`). */
|
|
24
|
+
readonly limits?: Partial<SandboxLimits>;
|
|
11
25
|
}
|
|
12
26
|
/** Execute input from the MCP tool using trusted context supplied separately by the host. */
|
|
13
27
|
export type SnippetChainExecutor = (input: Record<string, unknown>, context?: SnippetChainContext) => Promise<CallToolResult>;
|
|
@@ -15,6 +29,17 @@ export type SnippetChainExecutor = (input: Record<string, unknown>, context?: Sn
|
|
|
15
29
|
* Run JavaScript against host-configured snippet providers. Selected results stay
|
|
16
30
|
* out of guest memory except for their declared JSON value. Supplying a catalog
|
|
17
31
|
* enables named chains for calls with a trusted scope.
|
|
32
|
+
*
|
|
33
|
+
* Failures are {@link CodeModeError}s whose message reads
|
|
34
|
+
* `[execute] CODE: detail. Recovery: hint.`; a caller abort rejects with a
|
|
35
|
+
* DOMException. Once an upstream snippet call was dispatched, errors carry
|
|
36
|
+
* `effects: "possible"` and never repeat guest, provider or transport text.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```ts
|
|
40
|
+
* const execute = createSnippetChain(providers, catalog, { isolation: "worker" });
|
|
41
|
+
* const result = await execute({ code: "return 1;" }, { scope: "user-1" });
|
|
42
|
+
* ```
|
|
18
43
|
*/
|
|
19
|
-
export declare function createSnippetChain(providers: ReadonlyMap<string, SnippetProvider>, catalog?: SnippetCatalog): SnippetChainExecutor;
|
|
44
|
+
export declare function createSnippetChain(providers: ReadonlyMap<string, SnippetProvider>, catalog?: SnippetCatalog, options?: SnippetChainOptions): SnippetChainExecutor;
|
|
20
45
|
//# sourceMappingURL=chain.d.ts.map
|
|
@@ -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;AAE/F,OAAO,EAKL,KAAK,gBAAgB,EACrB,KAAK,aAAa,EACnB,MAAM,cAAc,CAAC;AAGtB,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;AAED,6CAA6C;AAC7C,MAAM,WAAW,mBAAmB;IAClC;;;;OAIG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,gBAAgB,CAAC;IACtC,qEAAqE;IACrE,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,aAAa,CAAC,CAAC;CAC1C;AAuKD,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;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,WAAW,CAAC,MAAM,EAAE,eAAe,CAAC,EAC/C,OAAO,CAAC,EAAE,cAAc,EACxB,OAAO,GAAE,mBAAwB,GAChC,oBAAoB,CAwYtB"}
|