@lowdefy/server-dev 0.0.0-experimental-20260905100314 → 0.0.0-experimental-20260906143808
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/client/DevStreamContext.js +30 -0
- package/client/Inspector.jsx +44 -24
- package/client/Reload.jsx +20 -1
- package/client/Routing.jsx +34 -31
- package/manager/processes/startProxy.mjs +9 -0
- package/manager/processes/startProxy.test.mjs +102 -0
- package/package.json +35 -35
- package/package.original.json +35 -35
- package/src/routes/devInspect.js +21 -4
- package/src/routes/devInspect.test.mjs +119 -0
- package/src/routes/reload.js +19 -21
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2026 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { createContext } from 'react';
|
|
18
|
+
|
|
19
|
+
// The one /api/reload EventSource a dev tab holds, owned by Reload.jsx and
|
|
20
|
+
// shared with Inspector.jsx: { source, tabId }. Dev runs on HTTP/1.1, where
|
|
21
|
+
// browsers cap connections per host at six and an open event stream holds
|
|
22
|
+
// one for the life of the tab. Two streams per tab meant three tabs of the
|
|
23
|
+
// same app saturated the pool and the next fetch queued forever, so every
|
|
24
|
+
// dev-only channel rides this single stream instead of opening its own.
|
|
25
|
+
// - source: the EventSource, null until Reload's effect has opened it.
|
|
26
|
+
// - tabId: the id the server assigned this connection in its tab registry
|
|
27
|
+
// (lib/docs/tabChannel.js), null until the stream's `tab` event arrives.
|
|
28
|
+
const DevStreamContext = createContext({ source: null, tabId: null });
|
|
29
|
+
|
|
30
|
+
export default DevStreamContext;
|
package/client/Inspector.jsx
CHANGED
|
@@ -14,40 +14,51 @@
|
|
|
14
14
|
limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
import { useEffect, useRef } from 'react';
|
|
17
|
+
import { useContext, useEffect, useRef } from 'react';
|
|
18
18
|
|
|
19
19
|
import { type, serializer } from '@lowdefy/helpers';
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
//
|
|
24
|
-
//
|
|
25
|
-
//
|
|
26
|
-
//
|
|
21
|
+
import DevStreamContext from './DevStreamContext.js';
|
|
22
|
+
|
|
23
|
+
// Dev-only agent-state-xray channel. Listens for inspect-request/eval-request
|
|
24
|
+
// events on the tab's single /api/reload EventSource (owned by Reload.jsx,
|
|
25
|
+
// shared through DevStreamContext) rather than opening its own — a second
|
|
26
|
+
// stream per tab exhausted the browser's HTTP/1.1 connection pool once a few
|
|
27
|
+
// tabs of the same app were open, and every later fetch queued forever.
|
|
27
28
|
//
|
|
28
|
-
// pageId tracking:
|
|
29
|
-
//
|
|
30
|
-
//
|
|
31
|
-
//
|
|
29
|
+
// pageId tracking: routes/reload.js registers every connection as an
|
|
30
|
+
// inspectable tab (lib/docs/tabChannel.js) and announces the tab id on the
|
|
31
|
+
// stream. This component then posts { tabId, pageId } to
|
|
32
|
+
// /api/dev-inspect/page whenever the developer navigates, so the registry's
|
|
33
|
+
// view of "what page is this tab on" stays current without reconnecting.
|
|
32
34
|
//
|
|
33
35
|
// Never let a bad payload or a plugin's operator error crash the app this is
|
|
34
36
|
// piggybacking on — every handler is wrapped, and the component itself
|
|
35
37
|
// always renders null.
|
|
36
|
-
function
|
|
38
|
+
function postJson({ basePath, path, body }) {
|
|
37
39
|
try {
|
|
38
|
-
fetch(`${basePath}/api/dev-inspect`, {
|
|
40
|
+
fetch(`${basePath}/api/dev-inspect${path}`, {
|
|
39
41
|
method: 'POST',
|
|
40
42
|
headers: { 'Content-Type': 'application/json' },
|
|
41
|
-
body: JSON.stringify(
|
|
43
|
+
body: JSON.stringify(body),
|
|
42
44
|
}).catch(() => {
|
|
43
45
|
// Best-effort — a failed callback just leaves the agent's request to
|
|
44
|
-
// time out server-side
|
|
46
|
+
// time out server-side, and a failed page update leaves the tab
|
|
47
|
+
// registered on its previous page.
|
|
45
48
|
});
|
|
46
49
|
} catch {
|
|
47
50
|
// JSON.stringify or fetch throwing synchronously — still best-effort.
|
|
48
51
|
}
|
|
49
52
|
}
|
|
50
53
|
|
|
54
|
+
function postResult({ basePath, requestId, result }) {
|
|
55
|
+
postJson({ basePath, path: '', body: { requestId, result } });
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function postTabPage({ basePath, tabId, pageId }) {
|
|
59
|
+
postJson({ basePath, path: '/page', body: { tabId, pageId } });
|
|
60
|
+
}
|
|
61
|
+
|
|
51
62
|
function buildSnapshot({ lowdefy, pageId }) {
|
|
52
63
|
const context = lowdefy?.contexts?.[`page:${pageId}`];
|
|
53
64
|
if (type.isNone(context)) {
|
|
@@ -133,17 +144,16 @@ function evalExpression({ lowdefy, pageId, expression }) {
|
|
|
133
144
|
}
|
|
134
145
|
|
|
135
146
|
const Inspector = ({ basePath, lowdefy, pageId }) => {
|
|
147
|
+
const { source, tabId } = useContext(DevStreamContext);
|
|
136
148
|
const pageIdRef = useRef(pageId);
|
|
137
149
|
pageIdRef.current = pageId;
|
|
138
150
|
|
|
139
151
|
useEffect(() => {
|
|
140
|
-
if (type.isNone(
|
|
152
|
+
if (type.isNone(source)) {
|
|
141
153
|
return undefined;
|
|
142
154
|
}
|
|
143
155
|
|
|
144
|
-
const
|
|
145
|
-
|
|
146
|
-
sse.addEventListener('inspect-request', (message) => {
|
|
156
|
+
const onInspectRequest = (message) => {
|
|
147
157
|
let requestId;
|
|
148
158
|
try {
|
|
149
159
|
const data = JSON.parse(message.data);
|
|
@@ -154,9 +164,9 @@ const Inspector = ({ basePath, lowdefy, pageId }) => {
|
|
|
154
164
|
} catch (error) {
|
|
155
165
|
postResult({ basePath, requestId, result: { error: error.message } });
|
|
156
166
|
}
|
|
157
|
-
}
|
|
167
|
+
};
|
|
158
168
|
|
|
159
|
-
|
|
169
|
+
const onEvalRequest = (message) => {
|
|
160
170
|
let requestId;
|
|
161
171
|
try {
|
|
162
172
|
const data = JSON.parse(message.data);
|
|
@@ -171,12 +181,22 @@ const Inspector = ({ basePath, lowdefy, pageId }) => {
|
|
|
171
181
|
} catch (error) {
|
|
172
182
|
postResult({ basePath, requestId, result: { error: error.message } });
|
|
173
183
|
}
|
|
174
|
-
}
|
|
184
|
+
};
|
|
175
185
|
|
|
186
|
+
source.addEventListener('inspect-request', onInspectRequest);
|
|
187
|
+
source.addEventListener('eval-request', onEvalRequest);
|
|
176
188
|
return () => {
|
|
177
|
-
|
|
189
|
+
source.removeEventListener('inspect-request', onInspectRequest);
|
|
190
|
+
source.removeEventListener('eval-request', onEvalRequest);
|
|
178
191
|
};
|
|
179
|
-
}, [basePath, lowdefy,
|
|
192
|
+
}, [basePath, lowdefy, source]);
|
|
193
|
+
|
|
194
|
+
useEffect(() => {
|
|
195
|
+
if (type.isNone(tabId) || type.isNone(pageId)) {
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
postTabPage({ basePath, tabId, pageId });
|
|
199
|
+
}, [basePath, tabId, pageId]);
|
|
180
200
|
|
|
181
201
|
useEffect(() => {
|
|
182
202
|
if (type.isNone(pageId)) {
|
package/client/Reload.jsx
CHANGED
|
@@ -16,15 +16,21 @@
|
|
|
16
16
|
|
|
17
17
|
import React, { useEffect, useState } from 'react';
|
|
18
18
|
|
|
19
|
+
import DevStreamContext from './DevStreamContext.js';
|
|
19
20
|
import useMutateCache from '../lib/client/utils/useMutateCache.js';
|
|
20
21
|
import waitForRestartedServer from '../lib/client/utils/waitForRestartedServer.js';
|
|
21
22
|
|
|
22
23
|
// SSE listener — config rebuilds notify via /api/reload. Tailwind CSS updates
|
|
23
24
|
// arrive through Vite HMR now (globals.css is in the dev module graph), so
|
|
24
25
|
// the old tailwind-jit.css link cache-bust is gone.
|
|
26
|
+
//
|
|
27
|
+
// This is the tab's only EventSource. It is shared through DevStreamContext
|
|
28
|
+
// so Inspector.jsx can listen on the same connection instead of opening a
|
|
29
|
+
// second one — see the connection-limit note in DevStreamContext.js.
|
|
25
30
|
const Reload = ({ children, basePath, lowdefy }) => {
|
|
26
31
|
const [reset, setReset] = useState(false);
|
|
27
32
|
const [restarting, setRestarting] = useState(false);
|
|
33
|
+
const [devStream, setDevStream] = useState({ source: null, tabId: null });
|
|
28
34
|
// reset is a one-shot boolean the engine lowers only after a page mounts
|
|
29
35
|
// (getContext.js) — while a page is suspended it stays true and setReset(true)
|
|
30
36
|
// bails out of re-rendering. The tick always changes, so every reload event
|
|
@@ -36,6 +42,15 @@ const Reload = ({ children, basePath, lowdefy }) => {
|
|
|
36
42
|
useEffect(() => {
|
|
37
43
|
const sse = new EventSource(`${basePath}/api/reload`);
|
|
38
44
|
|
|
45
|
+
// routes/reload.js registers every connection as an inspectable tab and
|
|
46
|
+
// announces the id it chose as the first event on the stream. The stream
|
|
47
|
+
// is published to consumers only then, in one state update, so the page
|
|
48
|
+
// subtree re-renders once at mount rather than once per field.
|
|
49
|
+
sse.addEventListener('tab', (message) => {
|
|
50
|
+
const { tabId } = JSON.parse(message.data);
|
|
51
|
+
setDevStream({ source: sse, tabId });
|
|
52
|
+
});
|
|
53
|
+
|
|
39
54
|
sse.addEventListener('reload', () => {
|
|
40
55
|
// add a update delay to prevent rerender before server is shut down for rebuild, ideally we don't want to do this.
|
|
41
56
|
// TODO: We need to pass a flag when a rebuild will happen so that client does not trigger render.
|
|
@@ -60,7 +75,11 @@ const Reload = ({ children, basePath, lowdefy }) => {
|
|
|
60
75
|
sse.close();
|
|
61
76
|
};
|
|
62
77
|
}, []);
|
|
63
|
-
return
|
|
78
|
+
return (
|
|
79
|
+
<DevStreamContext.Provider value={devStream}>
|
|
80
|
+
{children({ reset, setReset, restarting })}
|
|
81
|
+
</DevStreamContext.Provider>
|
|
82
|
+
);
|
|
64
83
|
};
|
|
65
84
|
|
|
66
85
|
export default Reload;
|
package/client/Routing.jsx
CHANGED
|
@@ -72,40 +72,43 @@ function Routing({ auth, lowdefy, router }) {
|
|
|
72
72
|
|
|
73
73
|
return (
|
|
74
74
|
<>
|
|
75
|
-
<Inspector basePath={router.basePath} lowdefy={lowdefy} pageId={pageId} />
|
|
76
75
|
<FeedbackMount basePath={router.basePath} lowdefy={lowdefy} pageId={pageId} />
|
|
77
76
|
<OpenInEditorListener basePath={router.basePath} pageId={pageId} />
|
|
78
77
|
<Reload basePath={router.basePath} lowdefy={lowdefy}>
|
|
79
|
-
{(resetContext) =>
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
<
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
78
|
+
{(resetContext) => (
|
|
79
|
+
<>
|
|
80
|
+
{/* Inside Reload so it can share Reload's event stream (DevStreamContext). */}
|
|
81
|
+
<Inspector basePath={router.basePath} lowdefy={lowdefy} pageId={pageId} />
|
|
82
|
+
{/* Rendered here, not in Page — Page sits below the Suspense boundary
|
|
83
|
+
and cannot render anything while its config fetch is suspended, so
|
|
84
|
+
a restarting server would present as "Building page..." forever. */}
|
|
85
|
+
{resetContext.restarting ? (
|
|
86
|
+
<RestartingPage />
|
|
87
|
+
) : (
|
|
88
|
+
<Suspense key={`${pageId}_${getReloadVersion()}`} fallback={<BuildingPage />}>
|
|
89
|
+
<Page
|
|
90
|
+
auth={auth}
|
|
91
|
+
Components={{ Head, Link }}
|
|
92
|
+
config={{
|
|
93
|
+
rootConfig,
|
|
94
|
+
}}
|
|
95
|
+
jsMap={staticJsMap}
|
|
96
|
+
lowdefy={lowdefy}
|
|
97
|
+
pageId={pageId}
|
|
98
|
+
resetContext={resetContext}
|
|
99
|
+
router={router}
|
|
100
|
+
types={{
|
|
101
|
+
actions,
|
|
102
|
+
blockMetas,
|
|
103
|
+
blocks,
|
|
104
|
+
icons,
|
|
105
|
+
operators,
|
|
106
|
+
}}
|
|
107
|
+
/>
|
|
108
|
+
</Suspense>
|
|
109
|
+
)}
|
|
110
|
+
</>
|
|
111
|
+
)}
|
|
109
112
|
</Reload>
|
|
110
113
|
</>
|
|
111
114
|
);
|
|
@@ -97,6 +97,13 @@ function forwardRequest(context, req, res) {
|
|
|
97
97
|
});
|
|
98
98
|
req.pipe(proxyReq);
|
|
99
99
|
req.on('error', () => proxyReq.destroy());
|
|
100
|
+
// A client that goes away mid-response (a closed browser tab holding the
|
|
101
|
+
// reload SSE stream, an agent dropping its MCP stream) must reach the
|
|
102
|
+
// child as an aborted request — pipe() only unpipes, so without this the
|
|
103
|
+
// child keeps the stream open and, for SSE, its tab registered forever.
|
|
104
|
+
res.on('close', () => {
|
|
105
|
+
if (!res.writableFinished) proxyReq.destroy();
|
|
106
|
+
});
|
|
100
107
|
});
|
|
101
108
|
}
|
|
102
109
|
|
|
@@ -122,6 +129,8 @@ function forwardUpgrade(context, req, socket, head) {
|
|
|
122
129
|
});
|
|
123
130
|
upstream.on('error', () => socket.destroy());
|
|
124
131
|
socket.on('error', () => upstream.destroy());
|
|
132
|
+
upstream.on('close', () => socket.destroy());
|
|
133
|
+
socket.on('close', () => upstream.destroy());
|
|
125
134
|
});
|
|
126
135
|
}
|
|
127
136
|
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2026 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import http from 'node:http';
|
|
18
|
+
import net from 'node:net';
|
|
19
|
+
|
|
20
|
+
import { jest } from '@jest/globals';
|
|
21
|
+
|
|
22
|
+
const { default: startProxy } = await import('./startProxy.mjs');
|
|
23
|
+
|
|
24
|
+
function listen(server) {
|
|
25
|
+
return new Promise((resolve) => {
|
|
26
|
+
server.listen(0, '127.0.0.1', () => resolve(server.address().port));
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function close(server) {
|
|
31
|
+
return new Promise((resolve) => {
|
|
32
|
+
server.closeAllConnections?.();
|
|
33
|
+
server.close(() => resolve());
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function getFreePort() {
|
|
38
|
+
return new Promise((resolve) => {
|
|
39
|
+
const server = net.createServer();
|
|
40
|
+
server.listen(0, '127.0.0.1', () => {
|
|
41
|
+
const { port } = server.address();
|
|
42
|
+
server.close(() => resolve(port));
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
let child;
|
|
48
|
+
let context;
|
|
49
|
+
|
|
50
|
+
afterEach(async () => {
|
|
51
|
+
if (context?.proxyServer) await close(context.proxyServer);
|
|
52
|
+
if (child) await close(child);
|
|
53
|
+
child = undefined;
|
|
54
|
+
context = undefined;
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
async function startChildAndProxy(handler) {
|
|
58
|
+
child = http.createServer(handler);
|
|
59
|
+
const internalPort = await listen(child);
|
|
60
|
+
context = {
|
|
61
|
+
internalPort,
|
|
62
|
+
options: { port: await getFreePort() },
|
|
63
|
+
logger: { debug: jest.fn() },
|
|
64
|
+
};
|
|
65
|
+
await startProxy(context);
|
|
66
|
+
return context.options.port;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
test('startProxy forwards a request to the child and relays its response', async () => {
|
|
70
|
+
const port = await startChildAndProxy((req, res) => {
|
|
71
|
+
res.writeHead(200, { 'content-type': 'application/json' });
|
|
72
|
+
res.end(JSON.stringify({ path: req.url }));
|
|
73
|
+
});
|
|
74
|
+
const response = await fetch(`http://localhost:${port}/api/ping?x=1`);
|
|
75
|
+
expect(response.status).toBe(200);
|
|
76
|
+
expect(await response.json()).toEqual({ path: '/api/ping?x=1' });
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
test('startProxy aborts the child request when the client drops a streaming response', async () => {
|
|
80
|
+
let upstreamClosed;
|
|
81
|
+
const upstreamClosedPromise = new Promise((resolve) => {
|
|
82
|
+
upstreamClosed = resolve;
|
|
83
|
+
});
|
|
84
|
+
const port = await startChildAndProxy((req, res) => {
|
|
85
|
+
res.writeHead(200, { 'content-type': 'text/event-stream' });
|
|
86
|
+
res.flushHeaders();
|
|
87
|
+
res.write('event: tab\ndata: {}\n\n');
|
|
88
|
+
// Never ends — like the reload SSE stream, it lives until the client goes.
|
|
89
|
+
req.on('close', () => upstreamClosed('closed'));
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
const clientRequest = http.get(`http://localhost:${port}/api/reload`);
|
|
93
|
+
const clientResponse = await new Promise((resolve) => clientRequest.on('response', resolve));
|
|
94
|
+
await new Promise((resolve) => clientResponse.once('data', resolve));
|
|
95
|
+
clientRequest.destroy();
|
|
96
|
+
|
|
97
|
+
const outcome = await Promise.race([
|
|
98
|
+
upstreamClosedPromise,
|
|
99
|
+
new Promise((resolve) => setTimeout(() => resolve('still open'), 2000)),
|
|
100
|
+
]);
|
|
101
|
+
expect(outcome).toBe('closed');
|
|
102
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lowdefy/server-dev",
|
|
3
|
-
"version": "0.0.0-experimental-
|
|
3
|
+
"version": "0.0.0-experimental-20260906143808",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"description": "",
|
|
6
6
|
"homepage": "https://lowdefy.com",
|
|
@@ -45,40 +45,40 @@
|
|
|
45
45
|
"@hono/mcp": "0.3.0",
|
|
46
46
|
"@hono/node-server": "2.0.4",
|
|
47
47
|
"@hono/vite-dev-server": "0.26.0",
|
|
48
|
-
"@lowdefy/actions-core": "0.0.0-experimental-
|
|
49
|
-
"@lowdefy/api": "0.0.0-experimental-
|
|
50
|
-
"@lowdefy/block-utils": "0.0.0-experimental-
|
|
51
|
-
"@lowdefy/blocks-aggrid": "0.0.0-experimental-
|
|
52
|
-
"@lowdefy/blocks-antd": "0.0.0-experimental-
|
|
53
|
-
"@lowdefy/blocks-antd-x": "0.0.0-experimental-
|
|
54
|
-
"@lowdefy/blocks-basic": "0.0.0-experimental-
|
|
55
|
-
"@lowdefy/blocks-captcha": "0.0.0-experimental-
|
|
56
|
-
"@lowdefy/blocks-echarts": "0.0.0-experimental-
|
|
57
|
-
"@lowdefy/blocks-loaders": "0.0.0-experimental-
|
|
58
|
-
"@lowdefy/blocks-markdown": "0.0.0-experimental-
|
|
59
|
-
"@lowdefy/blocks-tiptap": "0.0.0-experimental-
|
|
60
|
-
"@lowdefy/build": "0.0.0-experimental-
|
|
61
|
-
"@lowdefy/client": "0.0.0-experimental-
|
|
62
|
-
"@lowdefy/connection-axios-http": "0.0.0-experimental-
|
|
63
|
-
"@lowdefy/connection-mongodb": "0.0.0-experimental-
|
|
64
|
-
"@lowdefy/docs-content": "0.0.0-experimental-
|
|
65
|
-
"@lowdefy/e2e-utils": "0.0.0-experimental-
|
|
66
|
-
"@lowdefy/engine": "0.0.0-experimental-
|
|
67
|
-
"@lowdefy/errors": "0.0.0-experimental-
|
|
68
|
-
"@lowdefy/helpers": "0.0.0-experimental-
|
|
69
|
-
"@lowdefy/layout": "0.0.0-experimental-
|
|
70
|
-
"@lowdefy/logger": "0.0.0-experimental-
|
|
71
|
-
"@lowdefy/node-utils": "0.0.0-experimental-
|
|
72
|
-
"@lowdefy/operators-change-case": "0.0.0-experimental-
|
|
73
|
-
"@lowdefy/operators-dayjs": "0.0.0-experimental-
|
|
74
|
-
"@lowdefy/operators-diff": "0.0.0-experimental-
|
|
75
|
-
"@lowdefy/operators-js": "0.0.0-experimental-
|
|
76
|
-
"@lowdefy/operators-mql": "0.0.0-experimental-
|
|
77
|
-
"@lowdefy/operators-nunjucks": "0.0.0-experimental-
|
|
78
|
-
"@lowdefy/operators-uuid": "0.0.0-experimental-
|
|
79
|
-
"@lowdefy/operators-yaml": "0.0.0-experimental-
|
|
80
|
-
"@lowdefy/plugin-better-auth": "0.0.0-experimental-
|
|
81
|
-
"@lowdefy/websockets-core": "0.0.0-experimental-
|
|
48
|
+
"@lowdefy/actions-core": "0.0.0-experimental-20260906143808",
|
|
49
|
+
"@lowdefy/api": "0.0.0-experimental-20260906143808",
|
|
50
|
+
"@lowdefy/block-utils": "0.0.0-experimental-20260906143808",
|
|
51
|
+
"@lowdefy/blocks-aggrid": "0.0.0-experimental-20260906143808",
|
|
52
|
+
"@lowdefy/blocks-antd": "0.0.0-experimental-20260906143808",
|
|
53
|
+
"@lowdefy/blocks-antd-x": "0.0.0-experimental-20260906143808",
|
|
54
|
+
"@lowdefy/blocks-basic": "0.0.0-experimental-20260906143808",
|
|
55
|
+
"@lowdefy/blocks-captcha": "0.0.0-experimental-20260906143808",
|
|
56
|
+
"@lowdefy/blocks-echarts": "0.0.0-experimental-20260906143808",
|
|
57
|
+
"@lowdefy/blocks-loaders": "0.0.0-experimental-20260906143808",
|
|
58
|
+
"@lowdefy/blocks-markdown": "0.0.0-experimental-20260906143808",
|
|
59
|
+
"@lowdefy/blocks-tiptap": "0.0.0-experimental-20260906143808",
|
|
60
|
+
"@lowdefy/build": "0.0.0-experimental-20260906143808",
|
|
61
|
+
"@lowdefy/client": "0.0.0-experimental-20260906143808",
|
|
62
|
+
"@lowdefy/connection-axios-http": "0.0.0-experimental-20260906143808",
|
|
63
|
+
"@lowdefy/connection-mongodb": "0.0.0-experimental-20260906143808",
|
|
64
|
+
"@lowdefy/docs-content": "0.0.0-experimental-20260906143808",
|
|
65
|
+
"@lowdefy/e2e-utils": "0.0.0-experimental-20260906143808",
|
|
66
|
+
"@lowdefy/engine": "0.0.0-experimental-20260906143808",
|
|
67
|
+
"@lowdefy/errors": "0.0.0-experimental-20260906143808",
|
|
68
|
+
"@lowdefy/helpers": "0.0.0-experimental-20260906143808",
|
|
69
|
+
"@lowdefy/layout": "0.0.0-experimental-20260906143808",
|
|
70
|
+
"@lowdefy/logger": "0.0.0-experimental-20260906143808",
|
|
71
|
+
"@lowdefy/node-utils": "0.0.0-experimental-20260906143808",
|
|
72
|
+
"@lowdefy/operators-change-case": "0.0.0-experimental-20260906143808",
|
|
73
|
+
"@lowdefy/operators-dayjs": "0.0.0-experimental-20260906143808",
|
|
74
|
+
"@lowdefy/operators-diff": "0.0.0-experimental-20260906143808",
|
|
75
|
+
"@lowdefy/operators-js": "0.0.0-experimental-20260906143808",
|
|
76
|
+
"@lowdefy/operators-mql": "0.0.0-experimental-20260906143808",
|
|
77
|
+
"@lowdefy/operators-nunjucks": "0.0.0-experimental-20260906143808",
|
|
78
|
+
"@lowdefy/operators-uuid": "0.0.0-experimental-20260906143808",
|
|
79
|
+
"@lowdefy/operators-yaml": "0.0.0-experimental-20260906143808",
|
|
80
|
+
"@lowdefy/plugin-better-auth": "0.0.0-experimental-20260906143808",
|
|
81
|
+
"@lowdefy/websockets-core": "0.0.0-experimental-20260906143808",
|
|
82
82
|
"@modelcontextprotocol/sdk": "1.29.0",
|
|
83
83
|
"@tailwindcss/postcss": "4.3.1",
|
|
84
84
|
"@vitejs/plugin-react": "6.0.2",
|
package/package.original.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lowdefy/server-dev",
|
|
3
|
-
"version": "0.0.0-experimental-
|
|
3
|
+
"version": "0.0.0-experimental-20260906143808",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"description": "",
|
|
6
6
|
"homepage": "https://lowdefy.com",
|
|
@@ -51,40 +51,40 @@
|
|
|
51
51
|
"@hono/mcp": "0.3.0",
|
|
52
52
|
"@hono/node-server": "2.0.4",
|
|
53
53
|
"@hono/vite-dev-server": "0.26.0",
|
|
54
|
-
"@lowdefy/actions-core": "0.0.0-experimental-
|
|
55
|
-
"@lowdefy/api": "0.0.0-experimental-
|
|
56
|
-
"@lowdefy/block-utils": "0.0.0-experimental-
|
|
57
|
-
"@lowdefy/blocks-aggrid": "0.0.0-experimental-
|
|
58
|
-
"@lowdefy/blocks-antd": "0.0.0-experimental-
|
|
59
|
-
"@lowdefy/blocks-antd-x": "0.0.0-experimental-
|
|
60
|
-
"@lowdefy/blocks-basic": "0.0.0-experimental-
|
|
61
|
-
"@lowdefy/blocks-captcha": "0.0.0-experimental-
|
|
62
|
-
"@lowdefy/blocks-echarts": "0.0.0-experimental-
|
|
63
|
-
"@lowdefy/blocks-loaders": "0.0.0-experimental-
|
|
64
|
-
"@lowdefy/blocks-markdown": "0.0.0-experimental-
|
|
65
|
-
"@lowdefy/blocks-tiptap": "0.0.0-experimental-
|
|
66
|
-
"@lowdefy/build": "0.0.0-experimental-
|
|
67
|
-
"@lowdefy/client": "0.0.0-experimental-
|
|
68
|
-
"@lowdefy/connection-axios-http": "0.0.0-experimental-
|
|
69
|
-
"@lowdefy/connection-mongodb": "0.0.0-experimental-
|
|
70
|
-
"@lowdefy/docs-content": "0.0.0-experimental-
|
|
71
|
-
"@lowdefy/e2e-utils": "0.0.0-experimental-
|
|
72
|
-
"@lowdefy/engine": "0.0.0-experimental-
|
|
73
|
-
"@lowdefy/errors": "0.0.0-experimental-
|
|
74
|
-
"@lowdefy/helpers": "0.0.0-experimental-
|
|
75
|
-
"@lowdefy/layout": "0.0.0-experimental-
|
|
76
|
-
"@lowdefy/logger": "0.0.0-experimental-
|
|
77
|
-
"@lowdefy/node-utils": "0.0.0-experimental-
|
|
78
|
-
"@lowdefy/operators-change-case": "0.0.0-experimental-
|
|
79
|
-
"@lowdefy/operators-dayjs": "0.0.0-experimental-
|
|
80
|
-
"@lowdefy/operators-diff": "0.0.0-experimental-
|
|
81
|
-
"@lowdefy/operators-js": "0.0.0-experimental-
|
|
82
|
-
"@lowdefy/operators-mql": "0.0.0-experimental-
|
|
83
|
-
"@lowdefy/operators-nunjucks": "0.0.0-experimental-
|
|
84
|
-
"@lowdefy/operators-uuid": "0.0.0-experimental-
|
|
85
|
-
"@lowdefy/operators-yaml": "0.0.0-experimental-
|
|
86
|
-
"@lowdefy/plugin-better-auth": "0.0.0-experimental-
|
|
87
|
-
"@lowdefy/websockets-core": "0.0.0-experimental-
|
|
54
|
+
"@lowdefy/actions-core": "0.0.0-experimental-20260906143808",
|
|
55
|
+
"@lowdefy/api": "0.0.0-experimental-20260906143808",
|
|
56
|
+
"@lowdefy/block-utils": "0.0.0-experimental-20260906143808",
|
|
57
|
+
"@lowdefy/blocks-aggrid": "0.0.0-experimental-20260906143808",
|
|
58
|
+
"@lowdefy/blocks-antd": "0.0.0-experimental-20260906143808",
|
|
59
|
+
"@lowdefy/blocks-antd-x": "0.0.0-experimental-20260906143808",
|
|
60
|
+
"@lowdefy/blocks-basic": "0.0.0-experimental-20260906143808",
|
|
61
|
+
"@lowdefy/blocks-captcha": "0.0.0-experimental-20260906143808",
|
|
62
|
+
"@lowdefy/blocks-echarts": "0.0.0-experimental-20260906143808",
|
|
63
|
+
"@lowdefy/blocks-loaders": "0.0.0-experimental-20260906143808",
|
|
64
|
+
"@lowdefy/blocks-markdown": "0.0.0-experimental-20260906143808",
|
|
65
|
+
"@lowdefy/blocks-tiptap": "0.0.0-experimental-20260906143808",
|
|
66
|
+
"@lowdefy/build": "0.0.0-experimental-20260906143808",
|
|
67
|
+
"@lowdefy/client": "0.0.0-experimental-20260906143808",
|
|
68
|
+
"@lowdefy/connection-axios-http": "0.0.0-experimental-20260906143808",
|
|
69
|
+
"@lowdefy/connection-mongodb": "0.0.0-experimental-20260906143808",
|
|
70
|
+
"@lowdefy/docs-content": "0.0.0-experimental-20260906143808",
|
|
71
|
+
"@lowdefy/e2e-utils": "0.0.0-experimental-20260906143808",
|
|
72
|
+
"@lowdefy/engine": "0.0.0-experimental-20260906143808",
|
|
73
|
+
"@lowdefy/errors": "0.0.0-experimental-20260906143808",
|
|
74
|
+
"@lowdefy/helpers": "0.0.0-experimental-20260906143808",
|
|
75
|
+
"@lowdefy/layout": "0.0.0-experimental-20260906143808",
|
|
76
|
+
"@lowdefy/logger": "0.0.0-experimental-20260906143808",
|
|
77
|
+
"@lowdefy/node-utils": "0.0.0-experimental-20260906143808",
|
|
78
|
+
"@lowdefy/operators-change-case": "0.0.0-experimental-20260906143808",
|
|
79
|
+
"@lowdefy/operators-dayjs": "0.0.0-experimental-20260906143808",
|
|
80
|
+
"@lowdefy/operators-diff": "0.0.0-experimental-20260906143808",
|
|
81
|
+
"@lowdefy/operators-js": "0.0.0-experimental-20260906143808",
|
|
82
|
+
"@lowdefy/operators-mql": "0.0.0-experimental-20260906143808",
|
|
83
|
+
"@lowdefy/operators-nunjucks": "0.0.0-experimental-20260906143808",
|
|
84
|
+
"@lowdefy/operators-uuid": "0.0.0-experimental-20260906143808",
|
|
85
|
+
"@lowdefy/operators-yaml": "0.0.0-experimental-20260906143808",
|
|
86
|
+
"@lowdefy/plugin-better-auth": "0.0.0-experimental-20260906143808",
|
|
87
|
+
"@lowdefy/websockets-core": "0.0.0-experimental-20260906143808",
|
|
88
88
|
"@modelcontextprotocol/sdk": "1.29.0",
|
|
89
89
|
"@tailwindcss/postcss": "4.3.1",
|
|
90
90
|
"@vitejs/plugin-react": "6.0.2",
|
package/src/routes/devInspect.js
CHANGED
|
@@ -19,7 +19,7 @@ import { serializer } from '@lowdefy/helpers';
|
|
|
19
19
|
import { readCheckpoint } from '../../lib/docs/checkpointStore.js';
|
|
20
20
|
import { loadMocks } from '../../lib/docs/devMockRegistry.js';
|
|
21
21
|
import getPathSegments from '../lib/getPathSegments.js';
|
|
22
|
-
import { listTabs, resolveTabRequest } from '../../lib/docs/tabChannel.js';
|
|
22
|
+
import { listTabs, resolveTabRequest, updateTabPage } from '../../lib/docs/tabChannel.js';
|
|
23
23
|
|
|
24
24
|
// Origin/host check mirrors clientError.js — this endpoint accepts a POST
|
|
25
25
|
// from Inspector.jsx (a same-origin dev-only browser component), not from
|
|
@@ -62,10 +62,23 @@ function handleCheckpointBootstrap(c, { name }) {
|
|
|
62
62
|
);
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
+
// Inspector.jsx posts { tabId, pageId } here whenever its tab navigates, so
|
|
66
|
+
// the tab registry (lib/docs/tabChannel.js) knows which page each connected
|
|
67
|
+
// tab is on without the tab reconnecting its event stream.
|
|
68
|
+
async function handleTabPage(c) {
|
|
69
|
+
const { tabId, pageId } = await c.req.json();
|
|
70
|
+
if (!tabId) {
|
|
71
|
+
return c.json({ error: 'Missing "tabId".' }, 400);
|
|
72
|
+
}
|
|
73
|
+
updateTabPage({ id: tabId, pageId });
|
|
74
|
+
return c.json({ ok: true });
|
|
75
|
+
}
|
|
76
|
+
|
|
65
77
|
// GET lists connected tabs for diagnostics (or, under /checkpoint/<name>,
|
|
66
|
-
// bootstraps a human tab from a state checkpoint); POST
|
|
67
|
-
// the
|
|
68
|
-
//
|
|
78
|
+
// bootstraps a human tab from a state checkpoint); POST /page updates the
|
|
79
|
+
// page a connected tab is on; POST at the root is the answer leg of the SSE
|
|
80
|
+
// request/response round trip (Inspector.jsx posts back {requestId, result}
|
|
81
|
+
// after handling an inspect-request/eval-request event).
|
|
69
82
|
async function devInspectHandler(c) {
|
|
70
83
|
if (c.req.method === 'GET') {
|
|
71
84
|
const segments = getPathSegments(c, '/api/dev-inspect/');
|
|
@@ -85,6 +98,10 @@ async function devInspectHandler(c) {
|
|
|
85
98
|
return c.json({ error: 'Forbidden' }, 403);
|
|
86
99
|
}
|
|
87
100
|
|
|
101
|
+
if (getPathSegments(c, '/api/dev-inspect/')[0] === 'page') {
|
|
102
|
+
return handleTabPage(c);
|
|
103
|
+
}
|
|
104
|
+
|
|
88
105
|
const { requestId, result } = await c.req.json();
|
|
89
106
|
if (!requestId) {
|
|
90
107
|
return c.json({ error: 'Missing "requestId".' }, 400);
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2026 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { Hono } from 'hono';
|
|
18
|
+
import { jest } from '@jest/globals';
|
|
19
|
+
|
|
20
|
+
const { listTabs, registerTab, requestFromTab, unregisterTab } = await import(
|
|
21
|
+
'../../lib/docs/tabChannel.js'
|
|
22
|
+
);
|
|
23
|
+
const { default: devInspectHandler } = await import('./devInspect.js');
|
|
24
|
+
|
|
25
|
+
function createApp() {
|
|
26
|
+
const app = new Hono();
|
|
27
|
+
app.all('/api/dev-inspect', devInspectHandler);
|
|
28
|
+
app.all('/api/dev-inspect/*', devInspectHandler);
|
|
29
|
+
return app;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const sameOriginHeaders = {
|
|
33
|
+
host: 'localhost:3001',
|
|
34
|
+
origin: 'http://localhost:3001',
|
|
35
|
+
'content-type': 'application/json',
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
// tabChannel keeps its registries at module scope, so clear connected tabs
|
|
39
|
+
// between tests to keep them independent.
|
|
40
|
+
afterEach(() => {
|
|
41
|
+
listTabs().forEach((tab) => unregisterTab({ id: tab.id }));
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
test('GET /api/dev-inspect lists connected tabs', async () => {
|
|
45
|
+
registerTab({ id: 'tab-1', pageId: 'home', send: jest.fn() });
|
|
46
|
+
const res = await createApp().request('/api/dev-inspect');
|
|
47
|
+
expect(res.status).toBe(200);
|
|
48
|
+
const body = await res.json();
|
|
49
|
+
expect(body.tabs).toHaveLength(1);
|
|
50
|
+
expect(body.tabs[0]).toMatchObject({ id: 'tab-1', pageId: 'home' });
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
test('POST /api/dev-inspect/page returns 403 when the Origin header is missing', async () => {
|
|
54
|
+
registerTab({ id: 'tab-1', pageId: 'home', send: jest.fn() });
|
|
55
|
+
const res = await createApp().request('/api/dev-inspect/page', {
|
|
56
|
+
method: 'POST',
|
|
57
|
+
headers: { host: 'localhost:3001', 'content-type': 'application/json' },
|
|
58
|
+
body: JSON.stringify({ tabId: 'tab-1', pageId: 'about' }),
|
|
59
|
+
});
|
|
60
|
+
expect(res.status).toBe(403);
|
|
61
|
+
expect(listTabs()[0].pageId).toBe('home');
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
test('POST /api/dev-inspect/page moves a connected tab to the posted page', async () => {
|
|
65
|
+
registerTab({ id: 'tab-1', pageId: 'home', send: jest.fn() });
|
|
66
|
+
const res = await createApp().request('/api/dev-inspect/page', {
|
|
67
|
+
method: 'POST',
|
|
68
|
+
headers: sameOriginHeaders,
|
|
69
|
+
body: JSON.stringify({ tabId: 'tab-1', pageId: 'about' }),
|
|
70
|
+
});
|
|
71
|
+
expect(res.status).toBe(200);
|
|
72
|
+
expect(await res.json()).toEqual({ ok: true });
|
|
73
|
+
expect(listTabs()[0].pageId).toBe('about');
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
test('POST /api/dev-inspect/page returns 400 when tabId is missing', async () => {
|
|
77
|
+
const res = await createApp().request('/api/dev-inspect/page', {
|
|
78
|
+
method: 'POST',
|
|
79
|
+
headers: sameOriginHeaders,
|
|
80
|
+
body: JSON.stringify({ pageId: 'about' }),
|
|
81
|
+
});
|
|
82
|
+
expect(res.status).toBe(400);
|
|
83
|
+
expect(await res.json()).toEqual({ error: 'Missing "tabId".' });
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
test('POST /api/dev-inspect/page for a tab that already disconnected returns ok', async () => {
|
|
87
|
+
const res = await createApp().request('/api/dev-inspect/page', {
|
|
88
|
+
method: 'POST',
|
|
89
|
+
headers: sameOriginHeaders,
|
|
90
|
+
body: JSON.stringify({ tabId: 'gone', pageId: 'about' }),
|
|
91
|
+
});
|
|
92
|
+
expect(res.status).toBe(200);
|
|
93
|
+
expect(listTabs()).toHaveLength(0);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
test('POST /api/dev-inspect resolves a pending tab request with the posted result', async () => {
|
|
97
|
+
const send = jest.fn();
|
|
98
|
+
registerTab({ id: 'tab-1', pageId: 'home', send });
|
|
99
|
+
const pending = requestFromTab({ pageId: 'home', event: 'inspect-request' });
|
|
100
|
+
const [, { requestId }] = send.mock.calls[0];
|
|
101
|
+
|
|
102
|
+
const res = await createApp().request('/api/dev-inspect', {
|
|
103
|
+
method: 'POST',
|
|
104
|
+
headers: sameOriginHeaders,
|
|
105
|
+
body: JSON.stringify({ requestId, result: { state: { a: 1 } } }),
|
|
106
|
+
});
|
|
107
|
+
expect(res.status).toBe(200);
|
|
108
|
+
expect(await res.json()).toEqual({ ok: true });
|
|
109
|
+
await expect(pending).resolves.toEqual({ state: { a: 1 } });
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
test('POST /api/dev-inspect returns 400 when requestId is missing', async () => {
|
|
113
|
+
const res = await createApp().request('/api/dev-inspect', {
|
|
114
|
+
method: 'POST',
|
|
115
|
+
headers: sameOriginHeaders,
|
|
116
|
+
body: JSON.stringify({ result: {} }),
|
|
117
|
+
});
|
|
118
|
+
expect(res.status).toBe(400);
|
|
119
|
+
});
|
package/src/routes/reload.js
CHANGED
|
@@ -23,16 +23,18 @@ import { registerTab, unregisterTab } from '../../lib/docs/tabChannel.js';
|
|
|
23
23
|
|
|
24
24
|
// SSE endpoint — notifies the client when build/reload is written so it can
|
|
25
25
|
// mutate the SWR cache and refetch config. Also doubles as the transport for
|
|
26
|
-
// the agent-state-xray tab channel (lib/docs/tabChannel.js):
|
|
27
|
-
//
|
|
28
|
-
//
|
|
26
|
+
// the agent-state-xray tab channel (lib/docs/tabChannel.js): every
|
|
27
|
+
// connection is a browser tab (client/Reload.jsx opens exactly one per tab),
|
|
28
|
+
// so each is registered as an inspectable dev tab and told its id in a `tab`
|
|
29
|
+
// event, after which an agent can push it inspect-request/eval-request
|
|
30
|
+
// events on the same stream.
|
|
29
31
|
//
|
|
30
|
-
//
|
|
31
|
-
//
|
|
32
|
-
//
|
|
33
|
-
//
|
|
34
|
-
//
|
|
35
|
-
//
|
|
32
|
+
// One stream per tab is deliberate: dev serves over HTTP/1.1, where browsers
|
|
33
|
+
// allow six connections per host, and an open event stream holds one for the
|
|
34
|
+
// life of the tab. The tab's page is not carried on this connection — it
|
|
35
|
+
// would force a reconnect on every navigation — but posted by
|
|
36
|
+
// client/Inspector.jsx to /api/dev-inspect/page (routes/devInspect.js) as
|
|
37
|
+
// { tabId, pageId } whenever it changes.
|
|
36
38
|
async function reloadHandler(c) {
|
|
37
39
|
return streamSSE(c, async (stream) => {
|
|
38
40
|
const watcher = chokidar.watch(['./build/reload'], {
|
|
@@ -40,25 +42,21 @@ async function reloadHandler(c) {
|
|
|
40
42
|
ignoreInitial: true,
|
|
41
43
|
});
|
|
42
44
|
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
pageId,
|
|
49
|
-
send: (event, data) => stream.writeSSE({ event, data: JSON.stringify(data) }),
|
|
50
|
-
});
|
|
51
|
-
}
|
|
45
|
+
const tabId = randomUUID();
|
|
46
|
+
registerTab({
|
|
47
|
+
id: tabId,
|
|
48
|
+
send: (event, data) => stream.writeSSE({ event, data: JSON.stringify(data) }),
|
|
49
|
+
});
|
|
52
50
|
|
|
53
51
|
let open = true;
|
|
54
52
|
stream.onAbort(() => {
|
|
55
53
|
open = false;
|
|
56
54
|
watcher.close();
|
|
57
|
-
|
|
58
|
-
unregisterTab({ id: tabId });
|
|
59
|
-
}
|
|
55
|
+
unregisterTab({ id: tabId });
|
|
60
56
|
});
|
|
61
57
|
|
|
58
|
+
await stream.writeSSE({ event: 'tab', data: JSON.stringify({ tabId }) });
|
|
59
|
+
|
|
62
60
|
const reload = () => {
|
|
63
61
|
stream.writeSSE({ event: 'reload', data: JSON.stringify({}) });
|
|
64
62
|
};
|