@qwik.dev/mcp 0.0.0-stage → 2.0.0-beta.47
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/LICENSE +22 -0
- package/README.md +99 -2
- package/dist/browser.js +286 -0
- package/dist/cli.js +366 -0
- package/dist/docs.json +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1686 -0
- package/package.json +53 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 QwikDev
|
|
4
|
+
Copyright (c) 2021 BuilderIO
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,100 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Qwik MCP
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
`@qwik.dev/mcp` connects an MCP client to a running Qwik development server. It supports browser rendering and Router SSR and works independently of the DevTools panel.
|
|
4
|
+
|
|
5
|
+
## Setup
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
pnpm add -D @qwik.dev/mcp
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Add `qwikMcp()` before `qwikVite()` in `vite.config.ts`:
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { defineConfig } from 'vite';
|
|
15
|
+
import { qwikVite } from '@qwik.dev/core/optimizer';
|
|
16
|
+
import { qwikRouter } from '@qwik.dev/router/vite';
|
|
17
|
+
import { qwikMcp } from '@qwik.dev/mcp';
|
|
18
|
+
|
|
19
|
+
export default defineConfig({
|
|
20
|
+
plugins: [qwikMcp(), qwikRouter(), qwikVite()],
|
|
21
|
+
});
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
For a browser-only Qwik app, omit `qwikRouter()` and keep your existing `qwikVite({ csr: true })` configuration. Start Vite and open the app in a local browser.
|
|
25
|
+
|
|
26
|
+
Configure your MCP client to launch the locally installed binary through stdio:
|
|
27
|
+
|
|
28
|
+
```json
|
|
29
|
+
{
|
|
30
|
+
"mcpServers": {
|
|
31
|
+
"qwik": {
|
|
32
|
+
"command": "npx",
|
|
33
|
+
"args": ["--no-install", "qwik-mcp", "/absolute/path/to/project"]
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Set the client's working directory to your project so `npx --no-install` resolves its local dependency. The optional positional path selects the Vite project root; it defaults to the process's working directory. No package download occurs when launching this configuration.
|
|
40
|
+
|
|
41
|
+
## Tools
|
|
42
|
+
|
|
43
|
+
| Tool | Inputs | Result |
|
|
44
|
+
| -------------------- | ------------------------------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------- |
|
|
45
|
+
| `get_project_info` | `{}` | Installed versions, script names, documentation match and optional dev URL |
|
|
46
|
+
| `list_routes` | `{}` | `routerInstalled` and Router's routes, source files, parameters, layouts |
|
|
47
|
+
| `get_dev_errors` | `{ url? }` | Vite errors observed by the selected page, with source locations |
|
|
48
|
+
| `inspect_page` | `{ url?, selector?, includeHtml?, includeSignalValues?, includeSerializedState?, includeSerializedVNodeTree?, offset? }` | Component tree, hooks, optional HTML, signal values, parsed state and VNode tree |
|
|
49
|
+
| `search_docs` | `{ query, limit? }` | Ranked documentation page IDs, titles, snippets and snapshot version |
|
|
50
|
+
| `get_doc` | `{ id }` | Full Markdown page, source URL and snapshot version |
|
|
51
|
+
| `get_best_practices` | `{}` | Short Qwik coding guide and its bundled version |
|
|
52
|
+
|
|
53
|
+
`includeHtml` and `includeSignalValues` default to `false`. `selector` scopes the HTML fragment; component metadata still describes the page. HTML is current DOM, marked `source: "live-dom"`, limited to 64 KiB of UTF-8, with `truncated` indicating an incomplete fragment. It is not the original SSR response.
|
|
54
|
+
|
|
55
|
+
`includeSerializedState` and `includeSerializedVNodeTree` also default to `false`. They parse the page's Qwik state scripts and reconstruct a VNode tree from a copy of the DOM. Each returns `null` when no Qwik container or relevant state exists, or `{ source: "serialized-dom", content, truncated, nextOffset }` with a 64 KiB UTF-8 limit. These snapshots may differ from current signal values after interaction. `selector` does not scope them.
|
|
56
|
+
|
|
57
|
+
Each text result also includes `nextOffset`. If `truncated` is `true`, call `inspect_page` again with the same include flag and `offset: nextOffset`. Repeat until `nextOffset` is `null`. The offset counts UTF-8 bytes and applies to every selected text field, so request one text field at a time when paging. Page changes can mix snapshots across calls; if an offset becomes invalid, restart at `0`.
|
|
58
|
+
|
|
59
|
+
Hook metadata is collected by the shared DevTools instrumentation as components execute and their document-ready tasks run. Components that have not executed in the browser may appear in the tree without hook metadata. Snapshot entries are grouped by component source, so repeated instances share that metadata.
|
|
60
|
+
|
|
61
|
+
With several pages connected, provide the exact page URL. Duplicate tabs with the same URL must be closed until one remains. Missing pages, invalid selectors, missing runtime and disconnected servers return tool errors. Vite errors clear after successful HMR; this is not a project-wide typecheck or build report.
|
|
62
|
+
|
|
63
|
+
## Offline documentation
|
|
64
|
+
|
|
65
|
+
`get_best_practices`, `search_docs` and `get_doc` work without Vite, an open browser or network access. The short guide and documentation snapshot are bundled with the MCP package and carry its version. The snapshot is generated from all Qwik documentation and API pages during the MCP build. MCP uses the same complete manifest as `llms.txt`; new documentation pages are discovered automatically during the build. It describes that release, which may differ from the Qwik version installed in your application.
|
|
66
|
+
|
|
67
|
+
The MCP server also sends workflow instructions during initialization: read the guide for Qwik code, search for specific topics, then fetch the full page. The instructions describe which live tools require Vite and a connected browser.
|
|
68
|
+
|
|
69
|
+
`get_project_info` reads installed Qwik packages and project script names even when Vite is stopped. It returns `documentation.version` and `documentation.matchesProject`, which compares the bundled documentation version with the installed Qwik core version exactly. `devServerRunning` is `false` and `devUrl` is absent until Vite starts. `routerVersion` reports the installed Router package; use `list_routes` to see whether the Router plugin is active.
|
|
70
|
+
|
|
71
|
+
Search first, then use a returned page ID to read the full document:
|
|
72
|
+
|
|
73
|
+
```json
|
|
74
|
+
{ "query": "useSignal", "limit": 5 }
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
```json
|
|
78
|
+
{ "id": "/docs/core/state/" }
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Search matches words in page titles, descriptions and Markdown content, with title matches ranked first. `limit` defaults to 5 and accepts 1–20. An unknown page ID returns a tool error.
|
|
82
|
+
|
|
83
|
+
## Local access
|
|
84
|
+
|
|
85
|
+
The plugin runs only during development. Its internal endpoint accepts loopback connections with a random session token and rejects browser origins. Discovery files live in `node_modules/.cache/qwik-mcp`, have owner-only permissions on Unix, and are removed when the server closes. Stale files from terminated processes are ignored.
|
|
86
|
+
|
|
87
|
+
Use a standalone HTTP Vite server with HMR enabled. HTTPS and middleware mode are currently unsupported. The CLI sends only MCP protocol messages to stdout. Tools inspect the running app and do not edit files, install packages or start builds. Returned HTML, hook metadata, signal values, parsed state and VNode tree are application content and may contain private information.
|
|
88
|
+
|
|
89
|
+
## Development
|
|
90
|
+
|
|
91
|
+
From the monorepo root:
|
|
92
|
+
|
|
93
|
+
```sh
|
|
94
|
+
pnpm build.core.dev
|
|
95
|
+
pnpm build.mcp
|
|
96
|
+
pnpm --filter @qwik.dev/mcp typecheck
|
|
97
|
+
pnpm test.mcp
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
Browser integration tests require Playwright Chromium. MCP bundles selected shared DevTools sources at build time, so publishing it does not require the DevTools UI package.
|
package/dist/browser.js
ADDED
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
// ../devtools/kit/src/protocol/globals.ts
|
|
2
|
+
var QWIK_DEVTOOLS_GLOBAL = {
|
|
3
|
+
key: "__QWIK_DEVTOOLS__",
|
|
4
|
+
version: 1,
|
|
5
|
+
props: {
|
|
6
|
+
componentState: "componentState",
|
|
7
|
+
hook: "hook",
|
|
8
|
+
pageDataSource: "pageDataSource",
|
|
9
|
+
dataProvider: "dataProvider",
|
|
10
|
+
perf: "perf",
|
|
11
|
+
preloads: "preloads",
|
|
12
|
+
ssrPreloads: "ssrPreloads"
|
|
13
|
+
},
|
|
14
|
+
ssr: {
|
|
15
|
+
perfStore: "__QWIK_SSR_PERF__",
|
|
16
|
+
preloadsProcessStore: "__QWIK_SSR_PRELOADS__",
|
|
17
|
+
perfId: "__QWIK_SSR_PERF_ID__",
|
|
18
|
+
perfIndex: "__QWIK_SSR_PERF_INDEX__",
|
|
19
|
+
perfCount: "__QWIK_SSR_PERF_COUNT__"
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
// ../devtools/kit/src/global-store.ts
|
|
24
|
+
function getDefaultWindow() {
|
|
25
|
+
return typeof window === "undefined" ? void 0 : window;
|
|
26
|
+
}
|
|
27
|
+
function getQwikDevtoolsGlobal(pageWindow = getDefaultWindow()) {
|
|
28
|
+
return pageWindow ? pageWindow[QWIK_DEVTOOLS_GLOBAL.key] : void 0;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// ../devtools/kit/src/protocol/messages.ts
|
|
32
|
+
var DEVTOOLS_MESSAGES = {
|
|
33
|
+
pageSource: "qwik-devtools",
|
|
34
|
+
viteMessagingEvent: "qwik_tools:vite_messaging_event",
|
|
35
|
+
types: {
|
|
36
|
+
render: "RENDER_EVENT",
|
|
37
|
+
componentTreeUpdate: "COMPONENT_TREE_UPDATE"
|
|
38
|
+
},
|
|
39
|
+
events: {
|
|
40
|
+
preloadsUpdate: "qwik:preloads-update",
|
|
41
|
+
ssrPerf: "qwik:ssr-perf",
|
|
42
|
+
ssrPreloads: "qwik:ssr-preloads"
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
// ../devtools/kit/src/client-bridge.ts
|
|
47
|
+
function getPageWindow(isBrowser) {
|
|
48
|
+
if (!isBrowser || typeof window === "undefined") {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
return window;
|
|
52
|
+
}
|
|
53
|
+
function getHook(pageWindow) {
|
|
54
|
+
return getQwikDevtoolsGlobal(pageWindow)?.[QWIK_DEVTOOLS_GLOBAL.props.hook];
|
|
55
|
+
}
|
|
56
|
+
function createInPageBridge(options) {
|
|
57
|
+
const getWindow = () => getPageWindow(options.isBrowser);
|
|
58
|
+
return {
|
|
59
|
+
async readPerfData() {
|
|
60
|
+
return getQwikDevtoolsGlobal(getWindow())?.[QWIK_DEVTOOLS_GLOBAL.props.perf] ?? null;
|
|
61
|
+
},
|
|
62
|
+
async readPreloadStore() {
|
|
63
|
+
return getQwikDevtoolsGlobal(getWindow())?.[QWIK_DEVTOOLS_GLOBAL.props.preloads] ?? null;
|
|
64
|
+
},
|
|
65
|
+
async clearPreloadStore() {
|
|
66
|
+
getQwikDevtoolsGlobal(getWindow())?.[QWIK_DEVTOOLS_GLOBAL.props.preloads]?.clear();
|
|
67
|
+
},
|
|
68
|
+
subscribePreloadUpdates(cb) {
|
|
69
|
+
const pageWindow = getWindow();
|
|
70
|
+
if (!pageWindow) {
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
pageWindow.addEventListener(DEVTOOLS_MESSAGES.events.preloadsUpdate, cb);
|
|
74
|
+
return () => pageWindow.removeEventListener(DEVTOOLS_MESSAGES.events.preloadsUpdate, cb);
|
|
75
|
+
},
|
|
76
|
+
async readComponentTree() {
|
|
77
|
+
return getHook(getWindow())?.getComponentTreeSnapshot() ?? null;
|
|
78
|
+
},
|
|
79
|
+
async readSignals() {
|
|
80
|
+
return getHook(getWindow())?.getSignalsSnapshot() ?? null;
|
|
81
|
+
},
|
|
82
|
+
async readVNodeTree() {
|
|
83
|
+
return getHook(getWindow())?.getVNodeTree?.() ?? null;
|
|
84
|
+
},
|
|
85
|
+
subscribeTreeUpdates(cb) {
|
|
86
|
+
const pageWindow = getWindow();
|
|
87
|
+
if (!pageWindow) {
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
const handler = (event) => {
|
|
91
|
+
const message = event.data;
|
|
92
|
+
if (message?.source === DEVTOOLS_MESSAGES.pageSource && message.type === DEVTOOLS_MESSAGES.types.componentTreeUpdate && Array.isArray(message.tree)) {
|
|
93
|
+
cb(message.tree);
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
pageWindow.addEventListener("message", handler);
|
|
97
|
+
return () => pageWindow.removeEventListener("message", handler);
|
|
98
|
+
},
|
|
99
|
+
async readComponentDetail(componentName, qrlChunk) {
|
|
100
|
+
return getHook(getWindow())?.getComponentDetail?.(componentName, qrlChunk) ?? null;
|
|
101
|
+
},
|
|
102
|
+
async readNodeProps(nodeId) {
|
|
103
|
+
return getHook(getWindow())?.getNodeProps?.(nodeId) ?? null;
|
|
104
|
+
},
|
|
105
|
+
async setSignalValue(componentName, qrlChunk, variableName, newValue) {
|
|
106
|
+
return getHook(getWindow())?.setSignalValue?.(componentName, qrlChunk, variableName, newValue) ?? false;
|
|
107
|
+
},
|
|
108
|
+
subscribeRenderEvents(cb) {
|
|
109
|
+
const pageWindow = getWindow();
|
|
110
|
+
if (!pageWindow) {
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
113
|
+
const handler = (event) => {
|
|
114
|
+
const message = event.data;
|
|
115
|
+
if (message?.source === DEVTOOLS_MESSAGES.pageSource && message.type === DEVTOOLS_MESSAGES.types.render && message.event) {
|
|
116
|
+
cb(message.event);
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
pageWindow.addEventListener("message", handler);
|
|
120
|
+
return () => pageWindow.removeEventListener("message", handler);
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// src/serialized.ts
|
|
126
|
+
import * as qwikInternal from "@qwik.dev/core/internal";
|
|
127
|
+
var containerSelector = "[q\\:container]";
|
|
128
|
+
var forwardRefsType = 14;
|
|
129
|
+
function readSerializedState(doc) {
|
|
130
|
+
const container = doc.querySelector(containerSelector);
|
|
131
|
+
if (!container) {
|
|
132
|
+
return null;
|
|
133
|
+
}
|
|
134
|
+
const instance = container.getAttribute("q:instance");
|
|
135
|
+
const scripts = [...container.querySelectorAll('script[type="qwik/state"]')].filter(
|
|
136
|
+
(script) => script.closest(containerSelector) === container && (instance === null || script.getAttribute("q:instance") === instance)
|
|
137
|
+
);
|
|
138
|
+
const root = scripts.find((script) => !script.hasAttribute("q:patch"));
|
|
139
|
+
if (!root && !scripts.some((script) => script.hasAttribute("q:patch"))) {
|
|
140
|
+
return null;
|
|
141
|
+
}
|
|
142
|
+
const state = JSON.parse(root?.textContent || "[]");
|
|
143
|
+
if (!Array.isArray(state)) {
|
|
144
|
+
throw new Error("Invalid serialized Qwik state.");
|
|
145
|
+
}
|
|
146
|
+
const patchForwardRefs = [];
|
|
147
|
+
for (const patch of scripts.filter((script) => script.hasAttribute("q:patch"))) {
|
|
148
|
+
const [start, entries, forwardRefs] = JSON.parse(patch.textContent || "[]");
|
|
149
|
+
if (!Number.isInteger(start) || !Array.isArray(entries)) {
|
|
150
|
+
throw new Error("Invalid serialized Qwik state patch.");
|
|
151
|
+
}
|
|
152
|
+
for (let index = 0; index < entries.length; index++) {
|
|
153
|
+
state[start * 2 + index] = entries[index];
|
|
154
|
+
}
|
|
155
|
+
if (forwardRefs) {
|
|
156
|
+
patchForwardRefs.push(...forwardRefs.filter((ref) => ref !== void 0));
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
if (patchForwardRefs.length) {
|
|
160
|
+
const forwardRefsIndex = state.findIndex(
|
|
161
|
+
(value, index) => index % 2 === 0 && value === forwardRefsType
|
|
162
|
+
);
|
|
163
|
+
if (forwardRefsIndex === -1) {
|
|
164
|
+
state.push(forwardRefsType, patchForwardRefs);
|
|
165
|
+
} else {
|
|
166
|
+
const existing = state[forwardRefsIndex + 1];
|
|
167
|
+
state[forwardRefsIndex + 1] = Array.isArray(existing) ? [...existing, ...patchForwardRefs] : patchForwardRefs;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
qwikInternal._preprocessState(state, { $forwardRefs$: null });
|
|
171
|
+
return qwikInternal._dumpState(state, false, "", null).replace(/^\n/, "");
|
|
172
|
+
}
|
|
173
|
+
async function readSerializedVNodeTree(doc) {
|
|
174
|
+
const clone = new DOMParser().parseFromString(doc.documentElement.outerHTML, "text/html");
|
|
175
|
+
const container = clone.querySelector(containerSelector);
|
|
176
|
+
if (!container) {
|
|
177
|
+
return null;
|
|
178
|
+
}
|
|
179
|
+
const domContainer = qwikInternal._getDomContainer(container);
|
|
180
|
+
return await qwikInternal._whenContainerDataReady(
|
|
181
|
+
domContainer,
|
|
182
|
+
() => qwikInternal._vnode_toString.call(domContainer.rootVNode, 20, "", true, false, false)
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// src/page.ts
|
|
187
|
+
var outputLimit = 65536;
|
|
188
|
+
var bounded = (content, source, offset = 0) => {
|
|
189
|
+
const bytes = new TextEncoder().encode(content);
|
|
190
|
+
if (offset > bytes.length || offset < bytes.length && (bytes[offset] & 192) === 128) {
|
|
191
|
+
throw new Error("Invalid offset for current content. Restart at offset 0.");
|
|
192
|
+
}
|
|
193
|
+
let end = Math.min(offset + outputLimit, bytes.length);
|
|
194
|
+
while (end < bytes.length && (bytes[end] & 192) === 128) {
|
|
195
|
+
end--;
|
|
196
|
+
}
|
|
197
|
+
return {
|
|
198
|
+
source,
|
|
199
|
+
content: new TextDecoder("utf-8", { fatal: true }).decode(bytes.subarray(offset, end)),
|
|
200
|
+
truncated: end < bytes.length,
|
|
201
|
+
nextOffset: end < bytes.length ? end : null
|
|
202
|
+
};
|
|
203
|
+
};
|
|
204
|
+
async function readPage(options, doc, bridge2, url) {
|
|
205
|
+
const element = options.selector ? doc.querySelector(options.selector) : doc.documentElement;
|
|
206
|
+
if (!element) {
|
|
207
|
+
throw new Error(`No element matches selector: ${options.selector}`);
|
|
208
|
+
}
|
|
209
|
+
const components = await bridge2.readComponentTree();
|
|
210
|
+
const tree = await bridge2.readVNodeTree();
|
|
211
|
+
if (!components || !tree) {
|
|
212
|
+
throw new Error("Qwik inspection runtime is unavailable. Wait for the page to finish loading.");
|
|
213
|
+
}
|
|
214
|
+
const stripProps = (nodes) => nodes.map(({ props: _props, children, ...node }) => ({
|
|
215
|
+
...node,
|
|
216
|
+
...children ? { children: stripProps(children) } : {}
|
|
217
|
+
}));
|
|
218
|
+
const html = options.includeHtml ? bounded(element.outerHTML, "live-dom", options.offset) : null;
|
|
219
|
+
const state = options.includeSerializedState ? readSerializedState(doc) : null;
|
|
220
|
+
const vnodeTree = options.includeSerializedVNodeTree ? await readSerializedVNodeTree(doc) : null;
|
|
221
|
+
return {
|
|
222
|
+
url,
|
|
223
|
+
tree: stripProps(tree),
|
|
224
|
+
components: components.map((component) => ({
|
|
225
|
+
...component,
|
|
226
|
+
signals: component.signals.map(
|
|
227
|
+
({ value, ...signal }) => options.includeSignalValues ? { ...signal, value } : signal
|
|
228
|
+
)
|
|
229
|
+
})),
|
|
230
|
+
...html ? { html } : {},
|
|
231
|
+
...options.includeSerializedState ? {
|
|
232
|
+
serializedState: state === null ? null : bounded(state, "serialized-dom", options.offset)
|
|
233
|
+
} : {},
|
|
234
|
+
...options.includeSerializedVNodeTree ? {
|
|
235
|
+
serializedVNodeTree: vnodeTree === null ? null : bounded(vnodeTree, "serialized-dom", options.offset)
|
|
236
|
+
} : {}
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
// src/browser.ts
|
|
241
|
+
var hot = import.meta.hot;
|
|
242
|
+
var pageId = crypto.randomUUID();
|
|
243
|
+
var bridge = createInPageBridge({ isBrowser: true });
|
|
244
|
+
var errors = [];
|
|
245
|
+
var register = () => hot.send("qwik:mcp:page", { pageId, url: location.href });
|
|
246
|
+
hot.on("vite:ws:connect", register);
|
|
247
|
+
hot.on("vite:error", ({ err }) => {
|
|
248
|
+
errors = [
|
|
249
|
+
{
|
|
250
|
+
message: err.message,
|
|
251
|
+
file: err.loc?.file ?? err.id,
|
|
252
|
+
line: err.loc?.line,
|
|
253
|
+
column: err.loc?.column
|
|
254
|
+
}
|
|
255
|
+
];
|
|
256
|
+
});
|
|
257
|
+
hot.on("vite:afterUpdate", () => {
|
|
258
|
+
errors = [];
|
|
259
|
+
register();
|
|
260
|
+
});
|
|
261
|
+
hot.on(
|
|
262
|
+
"qwik:mcp:request",
|
|
263
|
+
async ({
|
|
264
|
+
id,
|
|
265
|
+
name,
|
|
266
|
+
args
|
|
267
|
+
}) => {
|
|
268
|
+
try {
|
|
269
|
+
if (args.url && args.url !== location.href) {
|
|
270
|
+
throw new Error(`Page navigated. Retry with url: ${location.href}`);
|
|
271
|
+
}
|
|
272
|
+
const result = name === "get_dev_errors" ? { url: location.href, errors } : await readPage(args, document, bridge, location.href);
|
|
273
|
+
hot.send("qwik:mcp:response", { id, result });
|
|
274
|
+
} catch (error) {
|
|
275
|
+
hot.send("qwik:mcp:response", { id, error: String(error) });
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
);
|
|
279
|
+
window.addEventListener("pagehide", () => hot.send("qwik:mcp:leave", { pageId }));
|
|
280
|
+
window.addEventListener("popstate", register);
|
|
281
|
+
var heartbeat = setInterval(register, 2e3);
|
|
282
|
+
register();
|
|
283
|
+
hot.dispose(() => {
|
|
284
|
+
clearInterval(heartbeat);
|
|
285
|
+
hot.send("qwik:mcp:leave", { pageId });
|
|
286
|
+
});
|