@lowdefy/server-dev 0.0.0-experimental-20261025074501 → 0.0.0-experimental-20261027111447
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/openInEditor/OpenInEditorListener.jsx +23 -1
- package/client/openInEditor/OpenInEditorListener.test.mjs +116 -0
- package/client/recorder/createPairingBuffer.test.mjs +4 -3
- package/client/recorder/createRecorder.js +10 -6
- package/client/recorder/isPasswordElement.js +41 -0
- package/lib/build/mobileConfig.js +26 -0
- package/lib/configTree/runConfigTreeBuild.mjs +2 -1
- package/lib/configTree/runConfigTreeBuild.skipPluginChecks.test.mjs +1 -1
- package/lib/docs/createDocsMcpServer.js +170 -32
- package/lib/docs/createDocsMcpServer.test.mjs +187 -3
- package/lib/docs/dataSets/getDataStore.js +11 -3
- package/lib/docs/dataSets/getDataStore.test.mjs +1 -1
- package/lib/docs/dataSets/openDataSession.js +4 -2
- package/lib/docs/dataSets/openDataSession.mongodb.test.mjs +5 -1
- package/lib/docs/devToolDefinitions.js +63 -5
- package/lib/docs/device/buildDeviceCommand.js +103 -0
- package/lib/docs/device/buildDeviceCommand.test.mjs +142 -0
- package/lib/docs/device/captureDevice.js +85 -0
- package/lib/docs/device/checkShownPage.js +56 -0
- package/lib/docs/device/createFakePhoneTab.mjs +77 -0
- package/lib/docs/device/deviceAction.js +74 -0
- package/lib/docs/device/deviceTools.test.mjs +604 -0
- package/lib/docs/device/findDeviceTab.js +50 -0
- package/lib/docs/device/findDeviceTarget.js +73 -0
- package/lib/docs/device/injectDevice.js +160 -0
- package/lib/docs/device/listDevices.js +100 -0
- package/lib/docs/device/listDevices.test.mjs +105 -0
- package/lib/docs/device/runDeviceJourney.js +68 -0
- package/lib/docs/device/runDeviceSteps.js +164 -0
- package/lib/docs/device/screenshotDevice.js +68 -0
- package/lib/docs/device/sendDeviceStep.js +52 -0
- package/lib/docs/device/startDevice.js +150 -0
- package/lib/docs/docs.test.mjs +32 -0
- package/lib/docs/findConfig.js +2 -2
- package/lib/docs/getHazards.js +4 -1
- package/lib/docs/getHazards.test.mjs +6 -4
- package/lib/docs/inspectState.js +62 -0
- package/lib/docs/inspectStateFromTab.js +15 -6
- package/lib/docs/installHeadlessShell.failure.test.mjs +6 -2
- package/lib/docs/installHeadlessShell.js +5 -2
- package/lib/docs/installHeadlessShell.test.mjs +4 -1
- package/lib/docs/installHeadlessShell.timeout.test.mjs +6 -2
- package/lib/docs/isDeepEqual.js +37 -0
- package/lib/docs/listTypes.js +58 -8
- package/lib/docs/pollTab.js +100 -0
- package/lib/docs/pollTab.test.mjs +64 -0
- package/lib/docs/rails/authEngineMethods.test.mjs +1 -1
- package/lib/docs/reportDevToolFault.js +29 -0
- package/lib/docs/reportDevToolFault.test.mjs +34 -0
- package/lib/docs/runCheckChild.js +2 -1
- package/lib/docs/runEndpoint.js +22 -9
- package/lib/docs/runEndpoint.test.mjs +20 -15
- package/lib/docs/runJourney.js +21 -1
- package/lib/docs/runJourney.test.mjs +57 -37
- package/lib/docs/runJourneySteps.js +8 -29
- package/lib/docs/runRequest.js +5 -5
- package/lib/docs/runRequest.test.mjs +5 -5
- package/lib/docs/setupTestFixtures.mjs +25 -0
- package/lib/docs/tabChannel.js +82 -14
- package/lib/docs/tabChannel.test.mjs +12 -0
- package/lib/server/auth/getHeadlessUser.js +6 -0
- package/lib/server/auth/getHeadlessUser.test.mjs +12 -2
- package/lib/server/createLowdefyContext.js +5 -1
- package/lib/server/jitPageBuilder.js +27 -3
- package/lib/server/jitPageBuilder.mobileTypes.test.mjs +65 -0
- package/lib/server/loadDynamicJsMap.js +10 -1
- package/lib/server/log/createHandleError.js +10 -5
- package/lib/server/log/createHandleError.test.mjs +11 -0
- package/lib/server/pairingHeaders.js +26 -0
- package/manager/getContext.mjs +4 -0
- package/manager/processes/checkPendingPlugins.mjs +49 -0
- package/manager/processes/checkPendingPlugins.test.mjs +107 -0
- package/manager/processes/initialBuild.mjs +2 -15
- package/manager/processes/initialBuild.test.mjs +5 -37
- package/manager/processes/lowdefyBuild.mjs +7 -4
- package/manager/processes/lowdefyBuild.skipPluginChecks.test.mjs +1 -1
- package/manager/processes/lowdefyBuild.test.mjs +3 -1
- package/manager/processes/startFirstServer.test.mjs +2 -1
- package/manager/processes/startMailSink.mjs +11 -3
- package/manager/processes/startMailSink.test.mjs +26 -0
- package/manager/processes/startProxy.mjs +68 -17
- package/manager/processes/startProxy.pairing.test.mjs +204 -0
- package/manager/processes/startServer.mjs +5 -7
- package/manager/processes/startServer.test.mjs +2 -1
- package/manager/run.mjs +16 -1
- package/manager/utils/BatchChanges.mjs +1 -1
- package/manager/utils/checkPairing.mjs +45 -0
- package/manager/utils/checkPairing.test.mjs +53 -0
- package/manager/utils/createCustomPluginMessagesMap.mjs +8 -3
- package/manager/utils/createCustomPluginTypesMap.mjs +48 -12
- package/manager/utils/createCustomPluginTypesMap.test.mjs +174 -12
- package/manager/utils/createLanPairing.mjs +34 -0
- package/manager/utils/createLanPairing.test.mjs +46 -0
- package/manager/utils/createServerArtifactTracker.mjs +1 -0
- package/{client/recorder/collectEventActions.js → manager/utils/findSignInCode.mjs} +13 -10
- package/manager/utils/findSignInCode.test.mjs +33 -0
- package/manager/utils/formatLanPairing.mjs +32 -0
- package/manager/utils/formatLanPairing.test.mjs +40 -0
- package/manager/utils/getLanAddress.mjs +83 -0
- package/manager/utils/getLanAddress.test.mjs +70 -0
- package/{client/recorder/toJsonSafe.js → manager/utils/isLoopbackAddress.mjs} +12 -10
- package/manager/utils/pluginTypeCache.mjs +100 -0
- package/manager/utils/pluginTypeCache.test.mjs +141 -0
- package/manager/utils/readPluginDefinitions.mjs +6 -6
- package/manager/utils/renderTerminalQr.mjs +54 -0
- package/manager/watchers/envWatcher.mjs +3 -0
- package/manager/watchers/envWatcher.test.mjs +9 -0
- package/manager/watchers/listServerPluginFiles.mjs +188 -0
- package/manager/watchers/listServerPluginFiles.test.mjs +257 -0
- package/manager/watchers/lowdefyBuildWatcher.mjs +5 -0
- package/manager/watchers/lowdefyBuildWatcher.test.mjs +22 -1
- package/manager/watchers/pluginSourceWatcher.mjs +45 -17
- package/manager/watchers/pluginSourceWatcher.test.mjs +90 -14
- package/manager/watchers/resolveFile.mjs +46 -0
- package/manager/watchers/resolveFile.test.mjs +67 -0
- package/manager/watchers/resolvePackageSpecifier.mjs +127 -0
- package/manager/watchers/resolvePackageSpecifier.test.mjs +151 -0
- package/manager/watchers/restartRequestWatcher.mjs +7 -4
- package/manager/watchers/restartRequestWatcher.test.mjs +37 -0
- package/package.json +43 -41
- package/package.original.json +43 -41
- package/src/app.js +79 -31
- package/src/lib/getPathSegments.js +16 -1
- package/{client/recorder/jsonType.js → src/lib/getRequestSurface.js} +5 -19
- package/src/lib/isTabAnswer.js +32 -0
- package/src/lib/isTabChannelCaller.js +35 -0
- package/src/middleware/apiContext.js +4 -2
- package/src/middleware/errorHandler.js +33 -45
- package/src/middleware/localDevToolsOnly.js +13 -1
- package/src/middleware/localDevToolsOnly.test.mjs +33 -0
- package/src/routes/agentBearer.test.mjs +183 -0
- package/src/routes/clientError.js +21 -4
- package/src/routes/clientError.test.mjs +127 -0
- package/src/routes/devInspect.js +4 -16
- package/src/routes/devInspect.test.mjs +125 -0
- package/src/routes/devRecording.js +5 -16
- package/src/routes/devRecording.test.mjs +52 -1
- package/src/routes/docs/find.js +3 -3
- package/src/routes/docs/loadDocsRoutes.js +70 -0
- package/src/routes/docs/loadDocsRoutes.test.mjs +110 -0
- package/src/routes/docs/mutants.js +7 -0
- package/src/routes/docs/mutants.test.mjs +16 -2
- package/src/routes/endpoints.js +24 -0
- package/src/routes/endpointsLink.test.mjs +111 -0
- package/src/routes/jitPage.js +13 -1
- package/src/routes/jitPage.test.mjs +25 -0
- package/src/routes/mobileRoot.js +30 -0
- package/src/routes/mobileRoutes.test.mjs +223 -0
- package/src/routes/mobileSignIn.js +58 -0
- package/src/routes/mobileSignIn.test.mjs +59 -0
- package/src/routes/mobileSignInCallback.js +34 -0
- package/src/routes/mobileSignInCallback.test.mjs +51 -0
- package/src/routes/mountDevPageRoutes.js +10 -2
- package/src/routes/mountDevPageRoutes.test.mjs +25 -2
- package/src/routes/mountMobileWellKnown.js +35 -0
- package/src/routes/mountMobileWellKnown.test.mjs +79 -0
- package/src/routes/reload.js +101 -20
- package/src/routes/reload.test.mjs +153 -0
- package/vite.config.js +13 -1
- package/client/recorder/buildEngineRecord.js +0 -37
- package/client/recorder/buildInteractionRecord.js +0 -64
- package/client/recorder/buildTraceEvent.js +0 -57
- package/client/recorder/buildTraceEvent.test.mjs +0 -82
- package/client/recorder/chunkRecords.js +0 -69
- package/client/recorder/chunkRecords.test.mjs +0 -60
- package/client/recorder/collectEventEndpoints.js +0 -40
- package/client/recorder/collectEventRequests.js +0 -39
- package/client/recorder/createPairingBuffer.js +0 -187
- package/client/recorder/createPasswordRedactor.js +0 -84
- package/client/recorder/createRecordBatcher.js +0 -54
- package/client/recorder/createRecordBatcher.test.mjs +0 -92
- package/client/recorder/createRecordingSession.js +0 -61
- package/client/recorder/createRecordingSession.test.mjs +0 -73
- package/client/recorder/diffStateWrites.js +0 -77
- package/client/recorder/diffStateWrites.test.mjs +0 -67
- package/client/recorder/isEventCall.js +0 -30
- package/client/recorder/sendRecords.js +0 -40
- package/manager/watchers/listServerSidePackages.mjs +0 -47
- package/manager/watchers/listServerSidePackages.test.mjs +0 -39
|
@@ -76,6 +76,7 @@ function OpenInEditorListener({ basePath, pageId }) {
|
|
|
76
76
|
const hoverRef = useRef(hoverBlock);
|
|
77
77
|
hoverRef.current = hoverBlock;
|
|
78
78
|
const lastPointerRef = useRef(null); // { x, y }
|
|
79
|
+
const frameRef = useRef(null); // pending animation frame of a hover resolve
|
|
79
80
|
|
|
80
81
|
// Style tag lifecycle — the listener is always mounted, so this lives for
|
|
81
82
|
// the app's lifetime and only the body class toggles per hover.
|
|
@@ -103,6 +104,7 @@ function OpenInEditorListener({ basePath, pageId }) {
|
|
|
103
104
|
|
|
104
105
|
useEffect(() => {
|
|
105
106
|
function clearHover() {
|
|
107
|
+
cancelScheduledHover();
|
|
106
108
|
if (hoverRef.current) {
|
|
107
109
|
setHoverBlock(null);
|
|
108
110
|
}
|
|
@@ -132,11 +134,30 @@ function OpenInEditorListener({ basePath, pageId }) {
|
|
|
132
134
|
}
|
|
133
135
|
}
|
|
134
136
|
|
|
137
|
+
// elementFromPoint and getBoundingClientRect force layout, so pointer moves
|
|
138
|
+
// resolve the hover at most once per animation frame, at the latest point.
|
|
139
|
+
function scheduleResolveHover() {
|
|
140
|
+
if (frameRef.current !== null) {
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
frameRef.current = requestAnimationFrame(() => {
|
|
144
|
+
frameRef.current = null;
|
|
145
|
+
resolveHover();
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function cancelScheduledHover() {
|
|
150
|
+
if (frameRef.current !== null) {
|
|
151
|
+
cancelAnimationFrame(frameRef.current);
|
|
152
|
+
frameRef.current = null;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
135
156
|
function onPointerMove(event) {
|
|
136
157
|
try {
|
|
137
158
|
lastPointerRef.current = { x: event.clientX, y: event.clientY };
|
|
138
159
|
if (isOpenModifier(event)) {
|
|
139
|
-
|
|
160
|
+
scheduleResolveHover();
|
|
140
161
|
} else {
|
|
141
162
|
clearHover();
|
|
142
163
|
}
|
|
@@ -220,6 +241,7 @@ function OpenInEditorListener({ basePath, pageId }) {
|
|
|
220
241
|
window.addEventListener('scroll', onScroll, true);
|
|
221
242
|
window.addEventListener('click', onClickCapture, { capture: true });
|
|
222
243
|
return () => {
|
|
244
|
+
cancelScheduledHover();
|
|
223
245
|
window.removeEventListener('pointermove', onPointerMove);
|
|
224
246
|
window.removeEventListener('keydown', onKeyDown);
|
|
225
247
|
window.removeEventListener('keyup', onKeyUp);
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
/*
|
|
3
|
+
Copyright 2020-2026 Lowdefy, Inc
|
|
4
|
+
|
|
5
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
you may not use this file except in compliance with the License.
|
|
7
|
+
You may obtain a copy of the License at
|
|
8
|
+
|
|
9
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
|
|
11
|
+
Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
See the License for the specific language governing permissions and
|
|
15
|
+
limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import React from 'react';
|
|
19
|
+
import { act } from 'react-dom/test-utils';
|
|
20
|
+
import { createRoot } from 'react-dom/client';
|
|
21
|
+
import { afterEach, beforeEach, expect, test, vi } from 'vitest';
|
|
22
|
+
|
|
23
|
+
import OpenInEditorListener from './OpenInEditorListener.jsx';
|
|
24
|
+
|
|
25
|
+
globalThis.IS_REACT_ACT_ENVIRONMENT = true;
|
|
26
|
+
|
|
27
|
+
let container;
|
|
28
|
+
let root;
|
|
29
|
+
let frames;
|
|
30
|
+
let elementFromPoint;
|
|
31
|
+
|
|
32
|
+
function flushFrames() {
|
|
33
|
+
const pending = [...frames];
|
|
34
|
+
frames.length = 0;
|
|
35
|
+
act(() => {
|
|
36
|
+
pending.forEach((callback) => callback?.());
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function move(x, y, init = {}) {
|
|
41
|
+
const event = new MouseEvent('pointermove', {
|
|
42
|
+
clientX: x,
|
|
43
|
+
clientY: y,
|
|
44
|
+
altKey: true,
|
|
45
|
+
bubbles: true,
|
|
46
|
+
...init,
|
|
47
|
+
});
|
|
48
|
+
act(() => {
|
|
49
|
+
window.dispatchEvent(event);
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
beforeEach(() => {
|
|
54
|
+
frames = [];
|
|
55
|
+
vi.stubGlobal('requestAnimationFrame', (callback) => frames.push(callback));
|
|
56
|
+
vi.stubGlobal('cancelAnimationFrame', (id) => {
|
|
57
|
+
frames[id - 1] = null;
|
|
58
|
+
});
|
|
59
|
+
document.body.innerHTML = '<div id="bl-a"></div><div id="bl-b"></div>';
|
|
60
|
+
elementFromPoint = vi.fn((x) => document.getElementById(x < 100 ? 'bl-a' : 'bl-b'));
|
|
61
|
+
document.elementFromPoint = elementFromPoint;
|
|
62
|
+
container = document.createElement('div');
|
|
63
|
+
document.body.appendChild(container);
|
|
64
|
+
root = createRoot(container);
|
|
65
|
+
act(() => {
|
|
66
|
+
root.render(React.createElement(OpenInEditorListener, { basePath: '', pageId: 'page' }));
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
afterEach(() => {
|
|
71
|
+
act(() => root.unmount());
|
|
72
|
+
vi.unstubAllGlobals();
|
|
73
|
+
document.body.innerHTML = '';
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
test('many pointer moves with Alt held resolve the hover once, at the latest point', () => {
|
|
77
|
+
move(10, 10);
|
|
78
|
+
move(20, 20);
|
|
79
|
+
move(150, 30);
|
|
80
|
+
expect(frames.filter(Boolean)).toHaveLength(1);
|
|
81
|
+
expect(elementFromPoint).not.toHaveBeenCalled();
|
|
82
|
+
|
|
83
|
+
flushFrames();
|
|
84
|
+
expect(elementFromPoint).toHaveBeenCalledTimes(1);
|
|
85
|
+
expect(elementFromPoint).toHaveBeenCalledWith(150, 30);
|
|
86
|
+
expect(document.body.textContent).toContain('b');
|
|
87
|
+
expect(document.body.classList.contains('lowdefy-open-in-editor-target')).toBe(true);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
test('a move in a later frame schedules a new resolve', () => {
|
|
91
|
+
move(10, 10);
|
|
92
|
+
flushFrames();
|
|
93
|
+
move(150, 10);
|
|
94
|
+
flushFrames();
|
|
95
|
+
expect(elementFromPoint).toHaveBeenCalledTimes(2);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
test('a move without the modifier cancels the pending resolve and clears the highlight', () => {
|
|
99
|
+
move(10, 10);
|
|
100
|
+
flushFrames();
|
|
101
|
+
expect(document.body.classList.contains('lowdefy-open-in-editor-target')).toBe(true);
|
|
102
|
+
|
|
103
|
+
move(10, 10);
|
|
104
|
+
move(11, 11, { altKey: false });
|
|
105
|
+
flushFrames();
|
|
106
|
+
expect(elementFromPoint).toHaveBeenCalledTimes(1);
|
|
107
|
+
expect(document.body.classList.contains('lowdefy-open-in-editor-target')).toBe(false);
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
test('unmount cancels a pending resolve', () => {
|
|
111
|
+
move(10, 10);
|
|
112
|
+
act(() => root.unmount());
|
|
113
|
+
flushFrames();
|
|
114
|
+
expect(elementFromPoint).not.toHaveBeenCalled();
|
|
115
|
+
root = createRoot(container);
|
|
116
|
+
});
|
|
@@ -18,11 +18,12 @@
|
|
|
18
18
|
*/
|
|
19
19
|
|
|
20
20
|
import { vi, afterEach, beforeEach, expect, test } from 'vitest';
|
|
21
|
+
import createPairingBuffer, { HOLD_MS } from '@lowdefy/client-core/recorder/createPairingBuffer.js';
|
|
22
|
+
import createPasswordRedactor from '@lowdefy/client-core/recorder/createPasswordRedactor.js';
|
|
21
23
|
// Only the validator: the package index loads undici, which needs Node globals jsdom lacks.
|
|
22
24
|
import validateTraceRecord from '@lowdefy/node-utils/journeyTrace/validateTraceRecord.js';
|
|
23
25
|
|
|
24
|
-
import
|
|
25
|
-
import createPasswordRedactor from './createPasswordRedactor.js';
|
|
26
|
+
import isPasswordElement from './isPasswordElement.js';
|
|
26
27
|
|
|
27
28
|
const START = Date.parse('2026-10-03T14:00:00.000Z');
|
|
28
29
|
const SESSION = '20261003T140000Z-k3x9qa';
|
|
@@ -131,7 +132,7 @@ beforeEach(() => {
|
|
|
131
132
|
getSession: () => SESSION,
|
|
132
133
|
getRoles: () => ['support'],
|
|
133
134
|
getBuild: () => build,
|
|
134
|
-
redactor: createPasswordRedactor(),
|
|
135
|
+
redactor: createPasswordRedactor({ isPassword: isPasswordElement }),
|
|
135
136
|
});
|
|
136
137
|
build = BUILD_A;
|
|
137
138
|
document.body.innerHTML = `
|
|
@@ -14,12 +14,16 @@
|
|
|
14
14
|
limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
import
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
import {
|
|
18
|
+
createPairingBuffer,
|
|
19
|
+
createPasswordRedactor,
|
|
20
|
+
createRecordBatcher,
|
|
21
|
+
createRecordingSession,
|
|
22
|
+
sendRecords,
|
|
23
|
+
} from '@lowdefy/client-core';
|
|
24
|
+
|
|
25
|
+
import isPasswordElement from './isPasswordElement.js';
|
|
21
26
|
import keyChord from './keyChord.js';
|
|
22
|
-
import sendRecords from './sendRecords.js';
|
|
23
27
|
|
|
24
28
|
// Dev tools draw their own UI over the app; clicks on it are not the app.
|
|
25
29
|
const IGNORED_ROOTS = '[data-lowdefy-dev-tools]';
|
|
@@ -67,7 +71,7 @@ function createRecorder({ basePath, lowdefy, recording, window, getTrace }) {
|
|
|
67
71
|
getSession: () => session.getId(),
|
|
68
72
|
getRoles: () => lowdefy.user?.roles ?? [],
|
|
69
73
|
getBuild: () => lowdefy._devBuildId ?? null,
|
|
70
|
-
redactor: createPasswordRedactor(),
|
|
74
|
+
redactor: createPasswordRedactor({ isPassword: isPasswordElement }),
|
|
71
75
|
});
|
|
72
76
|
let pageId = null;
|
|
73
77
|
// A pageview waits here until the page it shows is on screen, because only
|
|
@@ -0,0 +1,41 @@
|
|
|
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 { journeyTargetSelectors } from '@lowdefy/helpers';
|
|
18
|
+
|
|
19
|
+
const { blockWrapperPrefix } = journeyTargetSelectors;
|
|
20
|
+
|
|
21
|
+
function isPasswordInput(element) {
|
|
22
|
+
return (
|
|
23
|
+
typeof element?.tagName === 'string' &&
|
|
24
|
+
element.tagName.toLowerCase() === 'input' &&
|
|
25
|
+
element.type === 'password'
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Whether an interaction's element belongs to a password block: the element,
|
|
30
|
+
// or its block's `<blockId>_input` element, is an `<input type="password">`.
|
|
31
|
+
// The visibility toggle turns the input into `type="text"`, so the block's own
|
|
32
|
+
// input is checked too, which a click on the toggle reaches.
|
|
33
|
+
function isPasswordElement(element) {
|
|
34
|
+
if (isPasswordInput(element)) return true;
|
|
35
|
+
const wrapper = element?.closest?.(`[id^="${blockWrapperPrefix}"]`);
|
|
36
|
+
if (!wrapper) return false;
|
|
37
|
+
const blockId = wrapper.id.slice(blockWrapperPrefix.length);
|
|
38
|
+
return isPasswordInput(element.ownerDocument?.getElementById(`${blockId}_input`));
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export default isPasswordElement;
|
|
@@ -0,0 +1,26 @@
|
|
|
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
|
+
// Build artifacts are read from disk because the Hono server runs as
|
|
18
|
+
// unbundled Node.js ESM — JSON imports would need import attributes, and
|
|
19
|
+
// client code imports the build JSON directly through Vite instead.
|
|
20
|
+
import fs from 'node:fs';
|
|
21
|
+
import path from 'node:path';
|
|
22
|
+
|
|
23
|
+
// {} for an app without a mobile key.
|
|
24
|
+
export default JSON.parse(
|
|
25
|
+
fs.readFileSync(path.join(process.cwd(), 'build/mobile/config.json'), 'utf8')
|
|
26
|
+
);
|
|
@@ -55,13 +55,14 @@ async function runConfigTreeBuild({
|
|
|
55
55
|
await prepareScratchServer({ devDirectory, serverDirectory: directories.server });
|
|
56
56
|
let result;
|
|
57
57
|
try {
|
|
58
|
-
const [customTypesMap, customMessagesMap] = await Promise.all([
|
|
58
|
+
const [{ customTypesMap, customTypesMapMobile }, customMessagesMap] = await Promise.all([
|
|
59
59
|
createCustomPluginTypesMap({ directories, logger }),
|
|
60
60
|
createCustomPluginMessagesMap({ directories, logger }),
|
|
61
61
|
]);
|
|
62
62
|
await build({
|
|
63
63
|
customMessagesMap,
|
|
64
64
|
customTypesMap,
|
|
65
|
+
customTypesMapMobile,
|
|
65
66
|
directories,
|
|
66
67
|
logger,
|
|
67
68
|
refResolver,
|
|
@@ -29,7 +29,7 @@ vi.doMock('./prepareScratchServer.mjs', () => ({
|
|
|
29
29
|
default: vi.fn().mockResolvedValue(),
|
|
30
30
|
}));
|
|
31
31
|
vi.doMock('../../manager/utils/createCustomPluginTypesMap.mjs', () => ({
|
|
32
|
-
default: vi.fn().mockResolvedValue({}),
|
|
32
|
+
default: vi.fn().mockResolvedValue({ customTypesMap: {}, customTypesMapMobile: {} }),
|
|
33
33
|
}));
|
|
34
34
|
vi.doMock('../../manager/utils/createCustomPluginMessagesMap.mjs', () => ({
|
|
35
35
|
default: vi.fn().mockResolvedValue({}),
|
|
@@ -15,9 +15,11 @@
|
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
17
|
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
18
|
+
import { isExpectedError } from '@lowdefy/errors';
|
|
18
19
|
import { createTraceId, type } from '@lowdefy/helpers';
|
|
19
20
|
import { validateJourneyUser } from '@lowdefy/node-utils';
|
|
20
21
|
|
|
22
|
+
import deviceAction from './device/deviceAction.js';
|
|
21
23
|
import { subscribe as subscribeToDevEvents } from './devEventBus.js';
|
|
22
24
|
import findConfig from './findConfig.js';
|
|
23
25
|
import findPageBlock from './findPageBlock.js';
|
|
@@ -34,16 +36,19 @@ import getSchema from './getSchema.js';
|
|
|
34
36
|
import getStaleStatus from './getStaleStatus.js';
|
|
35
37
|
import inspectState from './inspectState.js';
|
|
36
38
|
import listTypes from './listTypes.js';
|
|
39
|
+
import reportDevToolFault from './reportDevToolFault.js';
|
|
37
40
|
import requestRestart from './requestRestart.js';
|
|
38
41
|
import runCheck from './runCheck.js';
|
|
39
42
|
import runEndpoint from './runEndpoint.js';
|
|
40
43
|
import runJourney from './runJourney.js';
|
|
41
44
|
import runJourneyAsUsers from './runJourneyAsUsers.js';
|
|
42
45
|
import selectExercised from './selectExercised.js';
|
|
46
|
+
import runDeviceJourney from './device/runDeviceJourney.js';
|
|
43
47
|
import runRequest from './runRequest.js';
|
|
44
48
|
import createLogger from '../server/log/createLogger.js';
|
|
45
49
|
import lowdefyConfig from '../build/config.js';
|
|
46
50
|
import devToolDefinitions, { INSTRUCTIONS } from './devToolDefinitions.js';
|
|
51
|
+
import screenshotDevice from './device/screenshotDevice.js';
|
|
47
52
|
import screenshotPage from './screenshotPage.js';
|
|
48
53
|
import searchDocs from './searchDocs.js';
|
|
49
54
|
import searchIcons from './searchIcons.js';
|
|
@@ -73,6 +78,67 @@ function notFoundResult(message) {
|
|
|
73
78
|
return { content: [{ type: 'text', text: message }], isError: true };
|
|
74
79
|
}
|
|
75
80
|
|
|
81
|
+
// A screenshot result (screenshotPage, or screenshotDevice for a phone) as MCP
|
|
82
|
+
// content. The final capture shows the page where the steps (or the failing
|
|
83
|
+
// step) left it; the images of `screenshot` steps follow it in step order, named
|
|
84
|
+
// in the JSON. A phone's capture also says how it was taken.
|
|
85
|
+
function imageResult(result) {
|
|
86
|
+
if (result.error) {
|
|
87
|
+
return notFoundResult(result.error);
|
|
88
|
+
}
|
|
89
|
+
const image = { type: 'image', data: result.data, mimeType: result.mimeType };
|
|
90
|
+
const fromDevice = !type.isUndefined(result.device);
|
|
91
|
+
if (!fromDevice && !result.failure && result.screenshots.length === 0) {
|
|
92
|
+
return { content: [image] };
|
|
93
|
+
}
|
|
94
|
+
const summary = { passed: !result.failure, failure: result.failure };
|
|
95
|
+
if (fromDevice) {
|
|
96
|
+
summary.device = result.device;
|
|
97
|
+
summary.capture = result.capture;
|
|
98
|
+
if (!type.isUndefined(result.note)) {
|
|
99
|
+
summary.note = result.note;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
if (result.screenshots.length > 0) {
|
|
103
|
+
summary.screenshots = result.screenshots.map(({ name }) => ({ name }));
|
|
104
|
+
}
|
|
105
|
+
return {
|
|
106
|
+
content: [
|
|
107
|
+
{ type: 'text', text: JSON.stringify(summary) },
|
|
108
|
+
image,
|
|
109
|
+
...result.screenshots.map(({ data, mimeType }) => ({ type: 'image', data, mimeType })),
|
|
110
|
+
],
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// A journey result's PNGs travel as image content blocks (the shape
|
|
115
|
+
// lowdefy_screenshot_page returns) so an MCP client renders them; the JSON keeps
|
|
116
|
+
// only their names.
|
|
117
|
+
function journeyResult({ summary, screenshots }) {
|
|
118
|
+
return {
|
|
119
|
+
content: [
|
|
120
|
+
{ type: 'text', text: JSON.stringify(summary) },
|
|
121
|
+
...screenshots.map(({ data, mimeType }) => ({ type: 'image', data, mimeType })),
|
|
122
|
+
],
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// The params a tool takes for the headless browser mean nothing on a phone:
|
|
127
|
+
// named back to the agent rather than silently dropped.
|
|
128
|
+
function deviceParamsError({ tool, params, names }) {
|
|
129
|
+
const given = names.filter((name) => !type.isNone(params[name]));
|
|
130
|
+
if (given.length === 0) {
|
|
131
|
+
return null;
|
|
132
|
+
}
|
|
133
|
+
return notFoundResult(
|
|
134
|
+
`${tool} with device acts on the phone as it is: ${given.join(', ')} ${
|
|
135
|
+
given.length === 1 ? 'applies' : 'apply'
|
|
136
|
+
} to the headless browser only. Leave ${
|
|
137
|
+
given.length === 1 ? 'it' : 'them'
|
|
138
|
+
} out, or leave device out.`
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
|
|
76
142
|
function createDocsMcpServer({ origin, honoContext, version } = {}) {
|
|
77
143
|
const server = new McpServer(
|
|
78
144
|
{ name: 'lowdefy', version },
|
|
@@ -87,6 +153,9 @@ function createDocsMcpServer({ origin, honoContext, version } = {}) {
|
|
|
87
153
|
//
|
|
88
154
|
// It also debug-logs every tool call (name + args, never the response) so
|
|
89
155
|
// agent activity is visible in the dev terminal with --log-level=debug.
|
|
156
|
+
//
|
|
157
|
+
// A handler that throws is caught here: left to the MCP SDK it became a bare
|
|
158
|
+
// tool error, with nothing logged and no stack.
|
|
90
159
|
const registered = new Set();
|
|
91
160
|
function registerDevTool(name, handler) {
|
|
92
161
|
const definition = devToolDefinitions[name];
|
|
@@ -100,7 +169,15 @@ function createDocsMcpServer({ origin, honoContext, version } = {}) {
|
|
|
100
169
|
} catch {
|
|
101
170
|
// Logging must never break a tool call.
|
|
102
171
|
}
|
|
103
|
-
|
|
172
|
+
let result;
|
|
173
|
+
try {
|
|
174
|
+
result = await handler(args, extra);
|
|
175
|
+
} catch (error) {
|
|
176
|
+
if (isExpectedError(error)) {
|
|
177
|
+
return notFoundResult(error.message);
|
|
178
|
+
}
|
|
179
|
+
return notFoundResult(reportDevToolFault({ error, logger, tool: name }));
|
|
180
|
+
}
|
|
104
181
|
try {
|
|
105
182
|
const stale = getStaleStatus();
|
|
106
183
|
// Prepended rather than merged so it covers textResult, notFoundResult
|
|
@@ -131,6 +208,21 @@ function createDocsMcpServer({ origin, honoContext, version } = {}) {
|
|
|
131
208
|
return textResult(result);
|
|
132
209
|
});
|
|
133
210
|
|
|
211
|
+
registerDevTool('lowdefy_device', async ({ action, platform, device, inject }) => {
|
|
212
|
+
const result = await deviceAction({
|
|
213
|
+
action,
|
|
214
|
+
platform,
|
|
215
|
+
device,
|
|
216
|
+
inject,
|
|
217
|
+
origin,
|
|
218
|
+
log: (message) => logger.info({ event: 'lowdefy_device' }, message),
|
|
219
|
+
});
|
|
220
|
+
if (result.error) {
|
|
221
|
+
return notFoundResult(result.error);
|
|
222
|
+
}
|
|
223
|
+
return textResult(result);
|
|
224
|
+
});
|
|
225
|
+
|
|
134
226
|
registerDevTool(
|
|
135
227
|
'lowdefy_run_request',
|
|
136
228
|
async ({ pageId, requestId, payload, user, data, saveResponse }) =>
|
|
@@ -213,7 +305,41 @@ function createDocsMcpServer({ origin, honoContext, version } = {}) {
|
|
|
213
305
|
width,
|
|
214
306
|
height,
|
|
215
307
|
colorScheme,
|
|
308
|
+
device,
|
|
216
309
|
}) => {
|
|
310
|
+
if (!type.isNone(device)) {
|
|
311
|
+
const refused = deviceParamsError({
|
|
312
|
+
tool: 'lowdefy_screenshot_page',
|
|
313
|
+
params: {
|
|
314
|
+
urlQuery,
|
|
315
|
+
fullPage,
|
|
316
|
+
clip,
|
|
317
|
+
scrollX,
|
|
318
|
+
scrollY,
|
|
319
|
+
width,
|
|
320
|
+
height,
|
|
321
|
+
colorScheme,
|
|
322
|
+
user,
|
|
323
|
+
data,
|
|
324
|
+
},
|
|
325
|
+
names: [
|
|
326
|
+
'urlQuery',
|
|
327
|
+
'fullPage',
|
|
328
|
+
'clip',
|
|
329
|
+
'scrollX',
|
|
330
|
+
'scrollY',
|
|
331
|
+
'width',
|
|
332
|
+
'height',
|
|
333
|
+
'colorScheme',
|
|
334
|
+
'user',
|
|
335
|
+
'data',
|
|
336
|
+
],
|
|
337
|
+
});
|
|
338
|
+
if (refused !== null) {
|
|
339
|
+
return refused;
|
|
340
|
+
}
|
|
341
|
+
return imageResult(await screenshotDevice({ device, pageId, pathParams, steps }));
|
|
342
|
+
}
|
|
217
343
|
if (!origin) {
|
|
218
344
|
return notFoundResult('Screenshot unavailable: server origin unknown for this transport.');
|
|
219
345
|
}
|
|
@@ -233,33 +359,50 @@ function createDocsMcpServer({ origin, honoContext, version } = {}) {
|
|
|
233
359
|
height,
|
|
234
360
|
colorScheme,
|
|
235
361
|
});
|
|
236
|
-
|
|
237
|
-
return notFoundResult(result.error);
|
|
238
|
-
}
|
|
239
|
-
const image = { type: 'image', data: result.data, mimeType: result.mimeType };
|
|
240
|
-
if (!result.failure && result.screenshots.length === 0) {
|
|
241
|
-
return { content: [image] };
|
|
242
|
-
}
|
|
243
|
-
// The final capture shows the page where the steps (or the failing step)
|
|
244
|
-
// left it; the images of `screenshot` steps follow it in step order, named
|
|
245
|
-
// in the JSON.
|
|
246
|
-
const summary = { passed: !result.failure, failure: result.failure };
|
|
247
|
-
if (result.screenshots.length > 0) {
|
|
248
|
-
summary.screenshots = result.screenshots.map(({ name }) => ({ name }));
|
|
249
|
-
}
|
|
250
|
-
return {
|
|
251
|
-
content: [
|
|
252
|
-
{ type: 'text', text: JSON.stringify(summary) },
|
|
253
|
-
image,
|
|
254
|
-
...result.screenshots.map(({ data, mimeType }) => ({ type: 'image', data, mimeType })),
|
|
255
|
-
],
|
|
256
|
-
};
|
|
362
|
+
return imageResult(result);
|
|
257
363
|
}
|
|
258
364
|
);
|
|
259
365
|
|
|
260
366
|
registerDevTool(
|
|
261
367
|
'lowdefy_run_journey',
|
|
262
|
-
async ({
|
|
368
|
+
async ({
|
|
369
|
+
pageId,
|
|
370
|
+
pathParams,
|
|
371
|
+
steps,
|
|
372
|
+
user,
|
|
373
|
+
urlQuery,
|
|
374
|
+
state,
|
|
375
|
+
timeout,
|
|
376
|
+
data,
|
|
377
|
+
exercised,
|
|
378
|
+
device,
|
|
379
|
+
}) => {
|
|
380
|
+
if (!type.isNone(device)) {
|
|
381
|
+
const refused = deviceParamsError({
|
|
382
|
+
tool: 'lowdefy_run_journey',
|
|
383
|
+
params: { urlQuery, user, data, exercised },
|
|
384
|
+
names: ['urlQuery', 'user', 'data', 'exercised'],
|
|
385
|
+
});
|
|
386
|
+
if (refused !== null) {
|
|
387
|
+
return refused;
|
|
388
|
+
}
|
|
389
|
+
const result = await runDeviceJourney({
|
|
390
|
+
device,
|
|
391
|
+
pageId,
|
|
392
|
+
pathParams,
|
|
393
|
+
steps,
|
|
394
|
+
stepTimeout: timeout,
|
|
395
|
+
state,
|
|
396
|
+
});
|
|
397
|
+
if (result.error) {
|
|
398
|
+
return notFoundResult(result.error);
|
|
399
|
+
}
|
|
400
|
+
const { screenshots, ...rest } = result;
|
|
401
|
+
return journeyResult({
|
|
402
|
+
summary: { ...rest, screenshots: screenshots.map(({ name }) => ({ name })) },
|
|
403
|
+
screenshots,
|
|
404
|
+
});
|
|
405
|
+
}
|
|
263
406
|
if (!origin) {
|
|
264
407
|
return notFoundResult('Journey unavailable: server origin unknown for this transport.');
|
|
265
408
|
}
|
|
@@ -315,24 +458,19 @@ function createDocsMcpServer({ origin, honoContext, version } = {}) {
|
|
|
315
458
|
if (result.error) {
|
|
316
459
|
return notFoundResult(result.error);
|
|
317
460
|
}
|
|
318
|
-
// The PNGs travel as image content blocks (the shape lowdefy_screenshot_page
|
|
319
|
-
// returns) so an MCP client renders them; the JSON keeps only their names.
|
|
320
461
|
const { screenshots, exercised: resultExercised, ...rest } = result;
|
|
321
462
|
const summary = {
|
|
322
463
|
...rest,
|
|
323
464
|
...selectExercised({ exercised: resultExercised, selection: exercised }),
|
|
324
465
|
screenshots: screenshots.map(({ name }) => ({ name })),
|
|
325
466
|
};
|
|
326
|
-
return {
|
|
327
|
-
content: [
|
|
328
|
-
{ type: 'text', text: JSON.stringify(summary) },
|
|
329
|
-
...screenshots.map(({ data, mimeType }) => ({ type: 'image', data, mimeType })),
|
|
330
|
-
],
|
|
331
|
-
};
|
|
467
|
+
return journeyResult({ summary, screenshots });
|
|
332
468
|
}
|
|
333
469
|
);
|
|
334
470
|
|
|
335
|
-
registerDevTool('lowdefy_list_types', ({ kind }) =>
|
|
471
|
+
registerDevTool('lowdefy_list_types', ({ kind, target }) =>
|
|
472
|
+
textResult(listTypes({ kind, target }))
|
|
473
|
+
);
|
|
336
474
|
|
|
337
475
|
registerDevTool('lowdefy_get_schema', ({ kind, type }) => {
|
|
338
476
|
const schema = getSchema({ kind, type });
|