@lowdefy/server-dev 0.0.0-experimental-20260720072521 → 0.0.0-experimental-20260720135014

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.
Files changed (196) hide show
  1. package/.eslintrc.yaml +1 -0
  2. package/lib/build/app.js +1 -8
  3. package/lib/build/appMeta.js +1 -8
  4. package/lib/build/auth.js +1 -8
  5. package/lib/build/config.js +1 -8
  6. package/lib/build/i18n.js +1 -8
  7. package/lib/build/logger.js +1 -8
  8. package/lib/build/theme.js +1 -8
  9. package/lib/client/App.js +80 -0
  10. package/{client/Page.jsx → lib/client/Page.js} +5 -5
  11. package/{client/Reload.jsx → lib/client/Reload.js} +7 -5
  12. package/lib/client/auth/{Auth.jsx → Auth.js} +5 -12
  13. package/lib/client/auth/AuthConfigured.js +61 -0
  14. package/lib/client/auth/AuthNotConfigured.js +2 -22
  15. package/lib/client/setPageId.js +5 -6
  16. package/lib/client/utils/useMutateCache.js +1 -14
  17. package/lib/client/utils/usePageConfig.js +11 -31
  18. package/lib/server/apiWrapper.js +116 -0
  19. package/lib/server/auth/{getStrategies.js → getAuthOptions.js} +9 -14
  20. package/lib/server/auth/{getMockUser.js → getMockSession.js} +19 -10
  21. package/{src/routes/docs/checkpointsRevert.js → lib/server/auth/getServerSession.js} +13 -11
  22. package/lib/server/compileCss.js +39 -0
  23. package/lib/server/jitPageBuilder.js +11 -36
  24. package/lib/server/log/logRequest.js +3 -1
  25. package/manager/getContext.mjs +7 -3
  26. package/manager/processes/compileCss.mjs +54 -0
  27. package/manager/processes/initialBuild.mjs +2 -0
  28. package/manager/processes/installPlugins.mjs +11 -19
  29. package/manager/processes/lowdefyBuild.mjs +7 -29
  30. package/manager/processes/nextBuild.mjs +50 -0
  31. package/manager/processes/readDotEnv.mjs +1 -13
  32. package/manager/processes/shutdownServer.mjs +6 -6
  33. package/manager/processes/startServer.mjs +7 -8
  34. package/manager/processes/startWatchers.mjs +2 -2
  35. package/manager/run.mjs +0 -41
  36. package/manager/utils/createCustomPluginMessagesMap.mjs +1 -8
  37. package/manager/utils/createCustomPluginTypesMap.mjs +2 -3
  38. package/manager/utils/{getViteBin.mjs → getNextBin.mjs} +10 -7
  39. package/manager/utils/updatePageTailwindCss.mjs +1 -7
  40. package/manager/watchers/lowdefyBuildWatcher.mjs +1 -0
  41. package/manager/watchers/moduleBuildWatcher.mjs +1 -0
  42. package/manager/watchers/{serverArtifactWatcher.mjs → nextBuildWatcher.mjs} +22 -18
  43. package/next.config.js +25 -0
  44. package/package.json +47 -63
  45. package/package.original.json +55 -66
  46. package/{src/routes/devTools.js → pages/404.js} +2 -4
  47. package/{src/routes/docs/appMap.js → pages/[[...pageId]].js} +2 -6
  48. package/{client/App.jsx → pages/_app.js} +33 -21
  49. package/pages/_document.js +107 -0
  50. package/pages/api/agent/[...path].js +86 -0
  51. package/pages/api/auth/[...nextauth].js +48 -0
  52. package/pages/api/client-error.js +45 -0
  53. package/{src/routes/docs/buildStatus.js → pages/api/dev-tools.js} +4 -5
  54. package/{lib/docs/clientErrorStore.js → pages/api/endpoints/[...endpointId].js} +11 -15
  55. package/{src/lib/serveBuildJs.js → pages/api/icons/dynamic.js} +12 -8
  56. package/{src/routes/jsEnv.js → pages/api/js/[env].js} +20 -8
  57. package/pages/api/page/[...pageId].js +74 -0
  58. package/{src/routes → pages/api}/ping.js +2 -4
  59. package/pages/api/reload.js +53 -0
  60. package/pages/api/request/[...path].js +41 -0
  61. package/{src/routes → pages/api}/root.js +4 -4
  62. package/client/Inspector.jsx +0 -206
  63. package/client/Routing.jsx +0 -106
  64. package/client/feedback/FeedbackMount.jsx +0 -83
  65. package/client/feedback/FeedbackOverlay.jsx +0 -901
  66. package/client/feedback/captureTabScreenshot.js +0 -84
  67. package/client/feedback/copyToClipboard.js +0 -45
  68. package/client/feedback/drawAnnotationsSvg.js +0 -119
  69. package/client/feedback/elementInspect.js +0 -99
  70. package/client/feedback/feedbackStyles.js +0 -301
  71. package/client/feedback/pinResponsiveImages.js +0 -59
  72. package/client/feedback/sendFeedback.js +0 -39
  73. package/client/feedback/useFeedbackToggle.js +0 -70
  74. package/client/main.jsx +0 -42
  75. package/client/openInEditor/OpenInEditorListener.jsx +0 -261
  76. package/client/openInEditor/findBlockLocation.js +0 -51
  77. package/lib/client/auth/AuthConfigured.jsx +0 -155
  78. package/lib/docs/captureAnnotatedScreenshot.js +0 -88
  79. package/lib/docs/checkpointPaths.js +0 -91
  80. package/lib/docs/checkpointStore.js +0 -234
  81. package/lib/docs/checkpointToMocks.js +0 -65
  82. package/lib/docs/configCheckpoints.test.mjs +0 -156
  83. package/lib/docs/createConfigCheckpoint.js +0 -92
  84. package/lib/docs/createDocsMcpServer.js +0 -506
  85. package/lib/docs/createDocsMcpServer.test.mjs +0 -123
  86. package/lib/docs/devMockRegistry.js +0 -68
  87. package/lib/docs/docs.test.mjs +0 -448
  88. package/lib/docs/enrichFeedback.js +0 -71
  89. package/lib/docs/evalOperator.js +0 -39
  90. package/lib/docs/evalOperator.test.mjs +0 -112
  91. package/lib/docs/evalOperatorHeadless.js +0 -87
  92. package/lib/docs/evalOperatorHeadless.test.mjs +0 -72
  93. package/lib/docs/evalOperatorInTab.js +0 -48
  94. package/lib/docs/findConfig.js +0 -260
  95. package/lib/docs/formatFeedback.js +0 -121
  96. package/lib/docs/formatFeedback.test.mjs +0 -204
  97. package/lib/docs/getAppMap.js +0 -180
  98. package/lib/docs/getBrowser.js +0 -115
  99. package/lib/docs/getBuildStatus.js +0 -37
  100. package/lib/docs/getCoreDoc.js +0 -63
  101. package/lib/docs/getDocsManifest.js +0 -40
  102. package/lib/docs/getExamples.js +0 -58
  103. package/lib/docs/getOverview.js +0 -115
  104. package/lib/docs/getPageConfig.js +0 -53
  105. package/lib/docs/getPluginDoc.js +0 -55
  106. package/lib/docs/getSchema.js +0 -65
  107. package/lib/docs/inspectState.js +0 -41
  108. package/lib/docs/inspectState.test.mjs +0 -91
  109. package/lib/docs/inspectStateFromTab.js +0 -40
  110. package/lib/docs/inspectStateHeadless.js +0 -84
  111. package/lib/docs/inspectStateHeadless.test.mjs +0 -60
  112. package/lib/docs/isWriteRequestsAllowed.js +0 -50
  113. package/lib/docs/listConfigCheckpoints.js +0 -55
  114. package/lib/docs/listPlugins.js +0 -80
  115. package/lib/docs/listTypes.js +0 -105
  116. package/lib/docs/loadState.js +0 -139
  117. package/lib/docs/mapPageBuildErrors.js +0 -28
  118. package/lib/docs/normalizeTypeKind.js +0 -40
  119. package/lib/docs/readBuildArtifact.js +0 -35
  120. package/lib/docs/readPageArtifact.js +0 -26
  121. package/lib/docs/resolvePluginDir.js +0 -49
  122. package/lib/docs/revertConfigCheckpoint.js +0 -73
  123. package/lib/docs/runRequest.js +0 -141
  124. package/lib/docs/saveAnnotatedScreenshot.js +0 -43
  125. package/lib/docs/scaffoldPage.js +0 -75
  126. package/lib/docs/scaffoldPage.test.mjs +0 -97
  127. package/lib/docs/screenshotPage.js +0 -109
  128. package/lib/docs/screenshotPage.test.mjs +0 -59
  129. package/lib/docs/screenshotPageClip.test.mjs +0 -102
  130. package/lib/docs/searchDocs.js +0 -67
  131. package/lib/docs/setupTestFixtures.mjs +0 -335
  132. package/lib/docs/snapshotState.js +0 -59
  133. package/lib/docs/stateCheckpoints.test.mjs +0 -348
  134. package/lib/docs/tabAvailable.js +0 -28
  135. package/lib/docs/tabChannel.js +0 -119
  136. package/lib/docs/tabChannel.test.mjs +0 -130
  137. package/lib/server/auth/createSystemContext.js +0 -70
  138. package/lib/server/auth/getAuth.js +0 -46
  139. package/lib/server/auth/getHeadlessUser.js +0 -39
  140. package/lib/server/auth/headlessUser.js +0 -30
  141. package/lib/server/createLowdefyContext.js +0 -133
  142. package/lib/server/loadDynamicJsMap.js +0 -47
  143. package/manager/processes/lowdefyBuild.test.mjs +0 -102
  144. package/manager/utils/formatNoticeBox.mjs +0 -30
  145. package/manager/utils/writeBuildStatus.mjs +0 -39
  146. package/manager/utils/writeBuildStatus.test.mjs +0 -76
  147. package/postcss.config.cjs +0 -1
  148. package/src/app.js +0 -188
  149. package/src/html/renderDevPage.js +0 -86
  150. package/src/lib/getPathSegments.js +0 -25
  151. package/src/lib/safeScriptJson.js +0 -38
  152. package/src/middleware/apiContext.js +0 -32
  153. package/src/middleware/errorHandler.js +0 -55
  154. package/src/routes/agent.js +0 -64
  155. package/src/routes/auth.js +0 -43
  156. package/src/routes/clientError.js +0 -57
  157. package/src/routes/cron.js +0 -44
  158. package/src/routes/detached.js +0 -51
  159. package/src/routes/devInspect.js +0 -94
  160. package/src/routes/docs/checkpointsCreate.js +0 -28
  161. package/src/routes/docs/checkpointsList.js +0 -23
  162. package/src/routes/docs/content.js +0 -31
  163. package/src/routes/docs/evalOperator.js +0 -46
  164. package/src/routes/docs/examples.js +0 -33
  165. package/src/routes/docs/find.js +0 -30
  166. package/src/routes/docs/index.js +0 -23
  167. package/src/routes/docs/inspectState.js +0 -34
  168. package/src/routes/docs/loadState.js +0 -38
  169. package/src/routes/docs/mcp.js +0 -30
  170. package/src/routes/docs/pageConfig.js +0 -36
  171. package/src/routes/docs/pluginDoc.js +0 -33
  172. package/src/routes/docs/plugins.js +0 -23
  173. package/src/routes/docs/runRequest.js +0 -34
  174. package/src/routes/docs/schema.js +0 -37
  175. package/src/routes/docs/screenshot.js +0 -66
  176. package/src/routes/docs/search.js +0 -27
  177. package/src/routes/docs/snapshotState.js +0 -36
  178. package/src/routes/docs/stateCheckpointsList.js +0 -26
  179. package/src/routes/docs/types.js +0 -33
  180. package/src/routes/endpoints.js +0 -76
  181. package/src/routes/feedback.js +0 -110
  182. package/src/routes/feedback.test.mjs +0 -204
  183. package/src/routes/iconsDynamic.js +0 -25
  184. package/src/routes/jitPage.js +0 -99
  185. package/src/routes/reload.js +0 -81
  186. package/src/routes/request.js +0 -66
  187. package/src/routes/usage.js +0 -46
  188. package/src/routes/user.js +0 -27
  189. package/src/routes/websocket.js +0 -33
  190. package/src/websocket/devWebSocket.js +0 -78
  191. package/vite.config.js +0 -111
  192. /package/lib/client/{BuildErrorPage.jsx → BuildErrorPage.js} +0 -0
  193. /package/lib/client/{BuildingPage.jsx → BuildingPage.js} +0 -0
  194. /package/lib/client/{ErrorBar.jsx → ErrorBar.js} +0 -0
  195. /package/lib/client/{InstallingPluginsPage.jsx → InstallingPluginsPage.js} +0 -0
  196. /package/lib/client/{RestartingPage.jsx → RestartingPage.js} +0 -0
@@ -1,84 +0,0 @@
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 { type } from '@lowdefy/helpers';
18
-
19
- import { getBrowser, openPage, buildPageUrl } from './getBrowser.js';
20
-
21
- // Collects a state snapshot from a headless Chromium tab navigated to the
22
- // page's own route. Mirrors Inspector.jsx's buildSnapshot (the live-tab
23
- // equivalent), but window.lowdefy does not expose the app's serializer, so
24
- // the snapshot is round-tripped through JSON.parse(JSON.stringify(...))
25
- // inside the page instead. That strips functions/undefined and turns Dates
26
- // into plain ISO strings — good enough for agent inspection, just not a
27
- // byte-for-byte match of the app's own `~d`-tagged serialization.
28
- async function inspectStateHeadless({ origin, pageId, timeout = 15000 }) {
29
- if (type.isNone(origin) || !type.isString(origin)) {
30
- return {
31
- error: `inspectStateHeadless requires an "origin" string. Received ${JSON.stringify(origin)}.`,
32
- };
33
- }
34
- if (type.isNone(pageId) || !type.isString(pageId)) {
35
- return {
36
- error: `inspectStateHeadless requires a "pageId" string. Received ${JSON.stringify(pageId)}.`,
37
- };
38
- }
39
-
40
- let browser;
41
- try {
42
- browser = await getBrowser();
43
- } catch (error) {
44
- return {
45
- error: `No Chromium available. Run: npx playwright install chromium (${error.message})`,
46
- };
47
- }
48
-
49
- const url = buildPageUrl({ origin, pageId });
50
-
51
- let context;
52
- try {
53
- const opened = await openPage({ browser, origin, pageId, timeout });
54
- context = opened.context;
55
- const snapshot = await opened.page.evaluate((id) => {
56
- const lowdefy = window.lowdefy;
57
- const pageContext = lowdefy?.contexts?.[`page:${id}`];
58
- if (!pageContext) {
59
- return { error: `No live context for page "${id}".` };
60
- }
61
- return JSON.parse(
62
- JSON.stringify({
63
- pageId: id,
64
- state: pageContext.state,
65
- requests: pageContext.requests,
66
- eventLog: (pageContext.eventLog ?? []).slice(-50),
67
- global: lowdefy.lowdefyGlobal,
68
- user: lowdefy.user,
69
- input: lowdefy.inputs?.[`page:${id}`],
70
- urlQuery: window.location.search,
71
- })
72
- );
73
- }, pageId);
74
- return snapshot;
75
- } catch (error) {
76
- return { error: `Failed to inspect state at "${url}": ${error.message}` };
77
- } finally {
78
- if (context) {
79
- await context.close();
80
- }
81
- }
82
- }
83
-
84
- export default inspectStateHeadless;
@@ -1,60 +0,0 @@
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 fs from 'fs';
18
- import os from 'os';
19
- import path from 'path';
20
- import { jest } from '@jest/globals';
21
-
22
- // A real headless inspection needs an installed browser, which jest can't
23
- // rely on, so this only covers the error paths: bad input, and
24
- // chromium.launch failing (the "no browser installed" case). Mirrors
25
- // screenshotPage.test.mjs, which exercises the same getBrowser.js singleton.
26
- jest.unstable_mockModule('playwright-core', () => ({
27
- chromium: { launch: jest.fn().mockRejectedValue(new Error("Executable doesn't exist")) },
28
- }));
29
-
30
- // lib/build/config.js reads build/config.json from process.cwd() at import
31
- // time — chdir into a fixture that has one before getBrowser.js (which
32
- // imports it transitively) is loaded. Mirrors the pattern in
33
- // screenshotPage.test.mjs.
34
- const originalCwd = process.cwd();
35
- const fixtureDir = fs.mkdtempSync(path.join(os.tmpdir(), 'lowdefy-inspect-state-test-'));
36
- fs.mkdirSync(path.join(fixtureDir, 'build'), { recursive: true });
37
- fs.writeFileSync(path.join(fixtureDir, 'build', 'config.json'), JSON.stringify({ basePath: '' }));
38
- process.chdir(fixtureDir);
39
-
40
- const { default: inspectStateHeadless } = await import('./inspectStateHeadless.js');
41
-
42
- afterAll(() => {
43
- process.chdir(originalCwd);
44
- fs.rmSync(fixtureDir, { recursive: true, force: true });
45
- });
46
-
47
- test('inspectStateHeadless returns an error when origin is missing', async () => {
48
- const result = await inspectStateHeadless({ pageId: 'home' });
49
- expect(result.error).toMatch(/requires an "origin" string/);
50
- });
51
-
52
- test('inspectStateHeadless returns an error when pageId is missing', async () => {
53
- const result = await inspectStateHeadless({ origin: 'http://localhost:3001' });
54
- expect(result.error).toMatch(/requires a "pageId" string/);
55
- });
56
-
57
- test('inspectStateHeadless returns an actionable error when no browser is available', async () => {
58
- const result = await inspectStateHeadless({ origin: 'http://localhost:3001', pageId: 'home' });
59
- expect(result.error).toMatch(/No Chromium available. Run: npx playwright install chromium/);
60
- });
@@ -1,50 +0,0 @@
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 path from 'node:path';
18
- import { get, type } from '@lowdefy/helpers';
19
- import { readFile } from '@lowdefy/node-utils';
20
- import YAML from 'yaml';
21
-
22
- // The top-level "cli" key in lowdefy.yaml never reaches a build artifact:
23
- // the build's root schema (packages/build/src/lowdefySchema.js) accepts an
24
- // arbitrary "cli" object, but no builder copies it onto `components`, so it
25
- // is never written to build/config.json (which only ever holds
26
- // components.config — see packages/build/src/build/writeConfig.js). The
27
- // Lowdefy CLI itself reads "cli" straight from lowdefy.yaml rather than from
28
- // a build artifact (packages/cli/src/utils/getLowdefyYaml.js) — this mirrors
29
- // that precedent instead of inventing a new build artifact for one dev-only
30
- // opt-in flag. Read fresh (no caching) so toggling the flag in lowdefy.yaml
31
- // takes effect without a server restart.
32
- async function isWriteRequestsAllowed() {
33
- const configDirectory = process.env.LOWDEFY_DIRECTORY_CONFIG || process.cwd();
34
- let raw = await readFile(path.join(configDirectory, 'lowdefy.yaml'));
35
- if (type.isNone(raw)) {
36
- raw = await readFile(path.join(configDirectory, 'lowdefy.yml'));
37
- }
38
- if (type.isNone(raw)) {
39
- return false;
40
- }
41
- let lowdefy;
42
- try {
43
- lowdefy = YAML.parse(raw);
44
- } catch {
45
- return false;
46
- }
47
- return get(lowdefy, 'cli.agentTools.allowWriteRequests', { default: false }) === true;
48
- }
49
-
50
- export default isWriteRequestsAllowed;
@@ -1,55 +0,0 @@
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 fs from 'fs';
18
- import path from 'path';
19
-
20
- import { getCheckpointsRoot, MANIFEST_FILE_NAME } from './checkpointPaths.js';
21
-
22
- // Lists stored config checkpoints, most recent first. Reads manifest.json
23
- // from each snapshot directory rather than re-scanning the config
24
- // directory — the manifest is the source of truth for what a checkpoint
25
- // contains, and stays accurate even after later checkpoints or reverts.
26
- function listConfigCheckpoints() {
27
- const checkpointsRoot = getCheckpointsRoot();
28
- if (!fs.existsSync(checkpointsRoot)) {
29
- return [];
30
- }
31
-
32
- const checkpoints = fs
33
- .readdirSync(checkpointsRoot, { withFileTypes: true })
34
- .filter((entry) => entry.isDirectory())
35
- .map((entry) => {
36
- const manifestPath = path.join(checkpointsRoot, entry.name, MANIFEST_FILE_NAME);
37
- if (!fs.existsSync(manifestPath)) {
38
- // A checkpoint directory without a manifest is not one this module
39
- // wrote (or was interrupted mid-write) — skip rather than guess.
40
- return null;
41
- }
42
- const manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf8'));
43
- return {
44
- id: manifest.id,
45
- label: manifest.label,
46
- createdAt: manifest.createdAt,
47
- fileCount: manifest.files.length,
48
- };
49
- })
50
- .filter((checkpoint) => checkpoint !== null);
51
-
52
- return checkpoints.sort((a, b) => (a.id < b.id ? 1 : -1));
53
- }
54
-
55
- export default listConfigCheckpoints;
@@ -1,80 +0,0 @@
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 readBuildArtifact from './readBuildArtifact.js';
18
-
19
- function addTypes({ plugins, store, kind }) {
20
- for (const [typeName, definition] of Object.entries(store ?? {})) {
21
- if (!plugins[definition.package]) {
22
- plugins[definition.package] = { package: definition.package, version: definition.version, types: {} };
23
- }
24
- const plugin = plugins[definition.package];
25
- if (!plugin.types[kind]) {
26
- plugin.types[kind] = [];
27
- }
28
- plugin.types[kind].push(typeName);
29
- }
30
- }
31
-
32
- function listPlugins() {
33
- const availableTypes = readBuildArtifact({ name: 'plugins/availableTypes.json' }) ?? {};
34
- const customTypesMap = readBuildArtifact({ name: 'customTypesMap.json' }) ?? {};
35
- const installedPackages = readBuildArtifact({ name: 'installedPluginPackages.json' }) ?? [];
36
-
37
- const plugins = {};
38
- addTypes({ plugins, store: availableTypes.actions, kind: 'actions' });
39
- addTypes({ plugins, store: availableTypes.agents, kind: 'agents' });
40
- addTypes({ plugins, store: availableTypes.blocks, kind: 'blocks' });
41
- addTypes({ plugins, store: availableTypes.connections, kind: 'connections' });
42
- addTypes({ plugins, store: availableTypes.notifications, kind: 'notifications' });
43
- addTypes({ plugins, store: availableTypes.operators?.client, kind: 'operators' });
44
- addTypes({ plugins, store: availableTypes.operators?.server, kind: 'operators' });
45
- addTypes({ plugins, store: availableTypes.requests, kind: 'requests' });
46
- addTypes({ plugins, store: availableTypes.websockets, kind: 'websockets' });
47
-
48
- const customPackages = new Set();
49
- const customStores = [
50
- customTypesMap.actions,
51
- customTypesMap.agents,
52
- customTypesMap.blocks,
53
- customTypesMap.connections,
54
- customTypesMap.operators?.client,
55
- customTypesMap.operators?.server,
56
- customTypesMap.requests,
57
- customTypesMap.websockets,
58
- ];
59
- for (const store of customStores) {
60
- for (const definition of Object.values(store ?? {})) {
61
- customPackages.add(definition.package);
62
- }
63
- }
64
-
65
- return Object.values(plugins)
66
- .map((plugin) => ({
67
- ...plugin,
68
- custom: customPackages.has(plugin.package),
69
- installed: installedPackages.includes(plugin.package),
70
- types: Object.fromEntries(
71
- Object.entries(plugin.types).map(([kind, typeNames]) => [
72
- kind,
73
- [...new Set(typeNames)].sort(),
74
- ])
75
- ),
76
- }))
77
- .sort((a, b) => a.package.localeCompare(b.package));
78
- }
79
-
80
- export default listPlugins;
@@ -1,105 +0,0 @@
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 { type } from '@lowdefy/helpers';
18
-
19
- import getDocsManifest from './getDocsManifest.js';
20
- import normalizeTypeKind from './normalizeTypeKind.js';
21
- import readBuildArtifact from './readBuildArtifact.js';
22
-
23
- function usedTypeNames({ store }) {
24
- const used = new Set();
25
- for (const [typeName, definition] of Object.entries(store ?? {})) {
26
- if (type.isObject(definition) && (definition.count ?? 0) > 0) {
27
- used.add(typeName);
28
- }
29
- }
30
- return used;
31
- }
32
-
33
- function flattenKind({ kind, availableTypes }) {
34
- if (kind === 'operators') {
35
- const merged = {};
36
- for (const [typeName, definition] of Object.entries(availableTypes.operators?.client ?? {})) {
37
- merged[typeName] = { ...definition, environments: ['client'] };
38
- }
39
- for (const [typeName, definition] of Object.entries(availableTypes.operators?.server ?? {})) {
40
- if (merged[typeName]) {
41
- merged[typeName].environments.push('server');
42
- } else {
43
- merged[typeName] = { ...definition, environments: ['server'] };
44
- }
45
- }
46
- return merged;
47
- }
48
- return availableTypes[kind] ?? {};
49
- }
50
-
51
- function listTypes({ kind }) {
52
- const normalizedKind = normalizeTypeKind({ kind });
53
- if (type.isNone(normalizedKind)) {
54
- throw new Error(
55
- `Unknown type kind. Received ${JSON.stringify(kind)}. Use one of: blocks, operators, actions, connections, requests, agents, notifications, websockets.`
56
- );
57
- }
58
- const availableTypes = readBuildArtifact({ name: 'plugins/availableTypes.json' }) ?? {};
59
- const types = readBuildArtifact({ name: 'types.json', deserialize: true }) ?? {};
60
- const blockMetas = readBuildArtifact({ name: 'plugins/blockMetas.json' }) ?? {};
61
- const manifest = getDocsManifest();
62
-
63
- const docSlugsByType = new Map();
64
- const kindSingular = normalizedKind.slice(0, -1);
65
- for (const doc of manifest?.docs ?? []) {
66
- if (doc.kind === kindSingular && doc.typeName) {
67
- docSlugsByType.set(doc.typeName, doc.slug);
68
- }
69
- }
70
-
71
- let used;
72
- if (normalizedKind === 'operators') {
73
- used = new Set([
74
- ...usedTypeNames({ store: types.operators?.client }),
75
- ...usedTypeNames({ store: types.operators?.server }),
76
- ]);
77
- } else {
78
- used = usedTypeNames({ store: types[normalizedKind] });
79
- }
80
-
81
- const flattened = flattenKind({ kind: normalizedKind, availableTypes });
82
- return Object.entries(flattened)
83
- .map(([typeName, definition]) => {
84
- const entry = {
85
- type: typeName,
86
- kind: normalizedKind,
87
- package: definition.package,
88
- version: definition.version,
89
- used: used.has(typeName),
90
- };
91
- if (definition.environments) {
92
- entry.environments = definition.environments;
93
- }
94
- if (normalizedKind === 'blocks' && blockMetas[typeName]?.category) {
95
- entry.category = blockMetas[typeName].category;
96
- }
97
- if (docSlugsByType.has(typeName)) {
98
- entry.docSlug = docSlugsByType.get(typeName);
99
- }
100
- return entry;
101
- })
102
- .sort((a, b) => a.type.localeCompare(b.type));
103
- }
104
-
105
- export default listTypes;
@@ -1,139 +0,0 @@
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 { type } from '@lowdefy/helpers';
18
-
19
- import lowdefyConfig from '../build/config.js';
20
- import { getBrowser, openPage } from './getBrowser.js';
21
- import { loadMocks } from './devMockRegistry.js';
22
- import { readCheckpoint } from './checkpointStore.js';
23
-
24
- const VERIFY_KEY_COUNT = 3;
25
-
26
- // Loads a state checkpoint's recorded requests into devMockRegistry (shared
27
- // by both modes below — src/routes/request.js consults it regardless of how
28
- // the page was opened), then either:
29
- // - 'headless': drives a headless page to the checkpoint's pageId/urlQuery,
30
- // injects its recorded state directly into the live context, and verifies
31
- // a few keys round-tripped. Good for an agent verifying its own change.
32
- // - 'registry-only': just returns a URL a human can open in a real browser
33
- // tab — client/Inspector.jsx's `?_checkpoint=` bootstrap does the state
34
- // injection client-side once that tab loads.
35
- async function loadState({ origin, name, mode = 'headless' }) {
36
- if (type.isNone(name) || !type.isString(name)) {
37
- return { error: `loadState requires a "name" string. Received ${JSON.stringify(name)}.` };
38
- }
39
-
40
- let checkpoint;
41
- try {
42
- checkpoint = readCheckpoint({ name });
43
- } catch (error) {
44
- return { error: error.message };
45
- }
46
-
47
- const pageId = checkpoint.checkpoint.pageId;
48
- if (type.isNone(pageId)) {
49
- return { error: `Checkpoint "${name}" has no recorded pageId.` };
50
- }
51
-
52
- loadMocks({ pageId, mocks: checkpoint.requests });
53
-
54
- const basePath = lowdefyConfig.basePath ?? '';
55
- const urlQuery = checkpoint.urlQuery ?? '';
56
-
57
- if (mode === 'registry-only') {
58
- const separator = urlQuery.includes('?') ? '&' : '?';
59
- const url = `${origin}${basePath}/${pageId}${urlQuery}${separator}_checkpoint=${encodeURIComponent(
60
- name
61
- )}`;
62
- return {
63
- url,
64
- instructions:
65
- 'Open this URL in a browser — state is injected on load, requests serve recorded data.',
66
- };
67
- }
68
-
69
- if (mode !== 'headless') {
70
- return {
71
- error: `loadState "mode" must be "headless" or "registry-only". Received ${JSON.stringify(
72
- mode
73
- )}.`,
74
- };
75
- }
76
-
77
- if (type.isNone(origin) || !type.isString(origin)) {
78
- return { error: `loadState requires an "origin" string. Received ${JSON.stringify(origin)}.` };
79
- }
80
-
81
- let browser;
82
- try {
83
- browser = await getBrowser();
84
- } catch (error) {
85
- return {
86
- error: `No Chromium available. Run: npx playwright install chromium (${error.message})`,
87
- };
88
- }
89
-
90
- let context;
91
- try {
92
- // buildPageUrl (used internally by openPage) joins origin/basePath/pageId
93
- // as a plain string, so folding the query string into the pageId segment
94
- // reproduces the checkpoint's exact URL without needing a query-aware
95
- // variant of openPage.
96
- const opened = await openPage({ browser, origin, pageId: `${pageId}${urlQuery}` });
97
- context = opened.context;
98
- const { page } = opened;
99
-
100
- await page.waitForFunction((id) => Boolean(window.lowdefy?.contexts?.[`page:${id}`]), pageId, {
101
- timeout: 15000,
102
- });
103
-
104
- const stateEntries = Object.entries(checkpoint.state ?? {});
105
- await page.evaluate(
106
- ({ id, entries }) => {
107
- const pageContext = window.lowdefy.contexts[`page:${id}`];
108
- entries.forEach(([key, value]) => {
109
- pageContext._internal.State.set(key, value);
110
- });
111
- pageContext._internal.update();
112
- },
113
- { id: pageId, entries: stateEntries }
114
- );
115
-
116
- const verifyKeys = stateEntries.slice(0, VERIFY_KEY_COUNT).map(([key]) => key);
117
- const verifiedKeys = await page.evaluate(
118
- ({ id, keys }) => {
119
- const pageContext = window.lowdefy.contexts[`page:${id}`];
120
- const result = {};
121
- keys.forEach((key) => {
122
- result[key] = pageContext.state?.[key];
123
- });
124
- return result;
125
- },
126
- { id: pageId, keys: verifyKeys }
127
- );
128
-
129
- return { loaded: true, mode, url: opened.url, verifiedKeys };
130
- } catch (error) {
131
- return { error: `Failed to load checkpoint "${name}": ${error.message}` };
132
- } finally {
133
- if (context) {
134
- await context.close();
135
- }
136
- }
137
- }
138
-
139
- export default loadState;
@@ -1,28 +0,0 @@
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
- // Mirrors the error mapping in src/routes/jitPage.js so agent-facing page
18
- // config responses carry the same shape as the dev client's JIT build errors.
19
- function mapPageBuildErrors(error) {
20
- const rawErrors = error.buildErrors ?? [error];
21
- return rawErrors.map((err) => ({
22
- type: err.name ?? 'Error',
23
- message: err.message,
24
- source: err.source ?? null,
25
- }));
26
- }
27
-
28
- export default mapPageBuildErrors;
@@ -1,40 +0,0 @@
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
- const KINDS = {
18
- action: 'actions',
19
- actions: 'actions',
20
- agent: 'agents',
21
- agents: 'agents',
22
- block: 'blocks',
23
- blocks: 'blocks',
24
- connection: 'connections',
25
- connections: 'connections',
26
- notification: 'notifications',
27
- notifications: 'notifications',
28
- operator: 'operators',
29
- operators: 'operators',
30
- request: 'requests',
31
- requests: 'requests',
32
- websocket: 'websockets',
33
- websockets: 'websockets',
34
- };
35
-
36
- function normalizeTypeKind({ kind }) {
37
- return KINDS[String(kind ?? '').toLowerCase()] ?? null;
38
- }
39
-
40
- export default normalizeTypeKind;
@@ -1,35 +0,0 @@
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 fs from 'node:fs';
18
- import path from 'node:path';
19
- import { serializer } from '@lowdefy/helpers';
20
-
21
- // Read fresh on every call — the dev build rewrites artifacts on config
22
- // change and the docs routes must serve the current state.
23
- function readBuildArtifact({ name, deserialize = false }) {
24
- const filePath = path.join(process.cwd(), 'build', name);
25
- if (!fs.existsSync(filePath)) {
26
- return null;
27
- }
28
- const raw = JSON.parse(fs.readFileSync(filePath, 'utf8'));
29
- if (deserialize) {
30
- return serializer.deserialize(raw);
31
- }
32
- return raw;
33
- }
34
-
35
- export default readBuildArtifact;