@lowdefy/server-dev 0.0.0-experimental-20260420110710 → 0.0.0-experimental-20260420135540

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.
@@ -20,6 +20,7 @@ import { getSecretsFromEnv } from '@lowdefy/node-utils';
20
20
  import { serializer } from '@lowdefy/helpers';
21
21
  import { v4 as uuid } from 'uuid';
22
22
 
23
+ import agents from '../../build/plugins/agents.js';
23
24
  import config from '../build/config.js';
24
25
  import connections from '../../build/plugins/connections.js';
25
26
  import createLogger from './log/createLogger.js';
@@ -65,6 +66,7 @@ function apiWrapper(handler) {
65
66
  const context = {
66
67
  // Important to give absolute path so Next can trace build files
67
68
  rid: uuid(),
69
+ agents,
68
70
  buildDirectory,
69
71
  configDirectory: process.env.LOWDEFY_DIRECTORY_CONFIG || process.cwd(),
70
72
  config,
@@ -39,6 +39,7 @@ async function getPluginDefinitions({ directories }) {
39
39
  async function createCustomPluginTypesMap({ directories, logger }) {
40
40
  const customTypesMap = {
41
41
  actions: {},
42
+ agents: {},
42
43
  auth: {
43
44
  adapters: {},
44
45
  callbacks: {},
package/next.config.js CHANGED
@@ -4,7 +4,12 @@ const blockPackages = require('./build/blockPackages.json');
4
4
  // Transpile @lowdefy/client plus all block plugin packages that may
5
5
  // contain CSS imports (e.g., AG Grid themes, loaders, markdown).
6
6
  // Built dynamically so custom user plugins are included automatically.
7
- const transpilePackages = ['@lowdefy/client', ...blockPackages];
7
+ const transpilePackages = [
8
+ '@lowdefy/client',
9
+ '@ant-design/x',
10
+ '@ant-design/x-markdown',
11
+ ...blockPackages,
12
+ ];
8
13
 
9
14
  const nextConfig = {
10
15
  basePath: lowdefyConfig.basePath,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lowdefy/server-dev",
3
- "version": "0.0.0-experimental-20260420110710",
3
+ "version": "0.0.0-experimental-20260420135540",
4
4
  "license": "Apache-2.0",
5
5
  "description": "",
6
6
  "homepage": "https://lowdefy.com",
@@ -36,33 +36,34 @@
36
36
  ".npmrc"
37
37
  ],
38
38
  "dependencies": {
39
- "@lowdefy/actions-core": "0.0.0-experimental-20260420110710",
40
- "@lowdefy/api": "0.0.0-experimental-20260420110710",
41
- "@lowdefy/block-utils": "0.0.0-experimental-20260420110710",
42
- "@lowdefy/blocks-aggrid": "0.0.0-experimental-20260420110710",
43
- "@lowdefy/blocks-antd": "0.0.0-experimental-20260420110710",
44
- "@lowdefy/blocks-basic": "0.0.0-experimental-20260420110710",
45
- "@lowdefy/blocks-echarts": "0.0.0-experimental-20260420110710",
46
- "@lowdefy/blocks-loaders": "0.0.0-experimental-20260420110710",
47
- "@lowdefy/blocks-markdown": "0.0.0-experimental-20260420110710",
48
- "@lowdefy/build": "0.0.0-experimental-20260420110710",
49
- "@lowdefy/client": "0.0.0-experimental-20260420110710",
50
- "@lowdefy/connection-axios-http": "0.0.0-experimental-20260420110710",
51
- "@lowdefy/engine": "0.0.0-experimental-20260420110710",
52
- "@lowdefy/errors": "0.0.0-experimental-20260420110710",
53
- "@lowdefy/helpers": "0.0.0-experimental-20260420110710",
54
- "@lowdefy/layout": "0.0.0-experimental-20260420110710",
55
- "@lowdefy/logger": "0.0.0-experimental-20260420110710",
56
- "@lowdefy/node-utils": "0.0.0-experimental-20260420110710",
57
- "@lowdefy/operators-change-case": "0.0.0-experimental-20260420110710",
58
- "@lowdefy/operators-dayjs": "0.0.0-experimental-20260420110710",
59
- "@lowdefy/operators-diff": "0.0.0-experimental-20260420110710",
60
- "@lowdefy/operators-js": "0.0.0-experimental-20260420110710",
61
- "@lowdefy/operators-mql": "0.0.0-experimental-20260420110710",
62
- "@lowdefy/operators-nunjucks": "0.0.0-experimental-20260420110710",
63
- "@lowdefy/operators-uuid": "0.0.0-experimental-20260420110710",
64
- "@lowdefy/operators-yaml": "0.0.0-experimental-20260420110710",
65
- "@lowdefy/plugin-next-auth": "0.0.0-experimental-20260420110710",
39
+ "@lowdefy/actions-core": "0.0.0-experimental-20260420135540",
40
+ "@lowdefy/api": "0.0.0-experimental-20260420135540",
41
+ "@lowdefy/block-utils": "0.0.0-experimental-20260420135540",
42
+ "@lowdefy/blocks-aggrid": "0.0.0-experimental-20260420135540",
43
+ "@lowdefy/blocks-antd": "0.0.0-experimental-20260420135540",
44
+ "@lowdefy/blocks-antd-x": "0.0.0-experimental-20260420135540",
45
+ "@lowdefy/blocks-basic": "0.0.0-experimental-20260420135540",
46
+ "@lowdefy/blocks-echarts": "0.0.0-experimental-20260420135540",
47
+ "@lowdefy/blocks-loaders": "0.0.0-experimental-20260420135540",
48
+ "@lowdefy/blocks-markdown": "0.0.0-experimental-20260420135540",
49
+ "@lowdefy/build": "0.0.0-experimental-20260420135540",
50
+ "@lowdefy/client": "0.0.0-experimental-20260420135540",
51
+ "@lowdefy/connection-axios-http": "0.0.0-experimental-20260420135540",
52
+ "@lowdefy/engine": "0.0.0-experimental-20260420135540",
53
+ "@lowdefy/errors": "0.0.0-experimental-20260420135540",
54
+ "@lowdefy/helpers": "0.0.0-experimental-20260420135540",
55
+ "@lowdefy/layout": "0.0.0-experimental-20260420135540",
56
+ "@lowdefy/logger": "0.0.0-experimental-20260420135540",
57
+ "@lowdefy/node-utils": "0.0.0-experimental-20260420135540",
58
+ "@lowdefy/operators-change-case": "0.0.0-experimental-20260420135540",
59
+ "@lowdefy/operators-dayjs": "0.0.0-experimental-20260420135540",
60
+ "@lowdefy/operators-diff": "0.0.0-experimental-20260420135540",
61
+ "@lowdefy/operators-js": "0.0.0-experimental-20260420135540",
62
+ "@lowdefy/operators-mql": "0.0.0-experimental-20260420135540",
63
+ "@lowdefy/operators-nunjucks": "0.0.0-experimental-20260420135540",
64
+ "@lowdefy/operators-uuid": "0.0.0-experimental-20260420135540",
65
+ "@lowdefy/operators-yaml": "0.0.0-experimental-20260420135540",
66
+ "@lowdefy/plugin-next-auth": "0.0.0-experimental-20260420135540",
66
67
  "@ant-design/cssinjs": "2.1.2",
67
68
  "antd": "6.3.1",
68
69
  "dayjs": "1.11.19",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lowdefy/server-dev",
3
- "version": "0.0.0-experimental-20260420110710",
3
+ "version": "0.0.0-experimental-20260420135540",
4
4
  "license": "Apache-2.0",
5
5
  "description": "",
6
6
  "homepage": "https://lowdefy.com",
@@ -44,33 +44,34 @@
44
44
  "prepublishOnly": "pnpm build"
45
45
  },
46
46
  "dependencies": {
47
- "@lowdefy/actions-core": "0.0.0-experimental-20260420110710",
48
- "@lowdefy/api": "0.0.0-experimental-20260420110710",
49
- "@lowdefy/block-utils": "0.0.0-experimental-20260420110710",
50
- "@lowdefy/blocks-aggrid": "0.0.0-experimental-20260420110710",
51
- "@lowdefy/blocks-antd": "0.0.0-experimental-20260420110710",
52
- "@lowdefy/blocks-basic": "0.0.0-experimental-20260420110710",
53
- "@lowdefy/blocks-echarts": "0.0.0-experimental-20260420110710",
54
- "@lowdefy/blocks-loaders": "0.0.0-experimental-20260420110710",
55
- "@lowdefy/blocks-markdown": "0.0.0-experimental-20260420110710",
56
- "@lowdefy/build": "0.0.0-experimental-20260420110710",
57
- "@lowdefy/client": "0.0.0-experimental-20260420110710",
58
- "@lowdefy/connection-axios-http": "0.0.0-experimental-20260420110710",
59
- "@lowdefy/engine": "0.0.0-experimental-20260420110710",
60
- "@lowdefy/errors": "0.0.0-experimental-20260420110710",
61
- "@lowdefy/helpers": "0.0.0-experimental-20260420110710",
62
- "@lowdefy/layout": "0.0.0-experimental-20260420110710",
63
- "@lowdefy/logger": "0.0.0-experimental-20260420110710",
64
- "@lowdefy/node-utils": "0.0.0-experimental-20260420110710",
65
- "@lowdefy/operators-change-case": "0.0.0-experimental-20260420110710",
66
- "@lowdefy/operators-dayjs": "0.0.0-experimental-20260420110710",
67
- "@lowdefy/operators-diff": "0.0.0-experimental-20260420110710",
68
- "@lowdefy/operators-js": "0.0.0-experimental-20260420110710",
69
- "@lowdefy/operators-mql": "0.0.0-experimental-20260420110710",
70
- "@lowdefy/operators-nunjucks": "0.0.0-experimental-20260420110710",
71
- "@lowdefy/operators-uuid": "0.0.0-experimental-20260420110710",
72
- "@lowdefy/operators-yaml": "0.0.0-experimental-20260420110710",
73
- "@lowdefy/plugin-next-auth": "0.0.0-experimental-20260420110710",
47
+ "@lowdefy/actions-core": "0.0.0-experimental-20260420135540",
48
+ "@lowdefy/api": "0.0.0-experimental-20260420135540",
49
+ "@lowdefy/block-utils": "0.0.0-experimental-20260420135540",
50
+ "@lowdefy/blocks-aggrid": "0.0.0-experimental-20260420135540",
51
+ "@lowdefy/blocks-antd": "0.0.0-experimental-20260420135540",
52
+ "@lowdefy/blocks-antd-x": "0.0.0-experimental-20260420135540",
53
+ "@lowdefy/blocks-basic": "0.0.0-experimental-20260420135540",
54
+ "@lowdefy/blocks-echarts": "0.0.0-experimental-20260420135540",
55
+ "@lowdefy/blocks-loaders": "0.0.0-experimental-20260420135540",
56
+ "@lowdefy/blocks-markdown": "0.0.0-experimental-20260420135540",
57
+ "@lowdefy/build": "0.0.0-experimental-20260420135540",
58
+ "@lowdefy/client": "0.0.0-experimental-20260420135540",
59
+ "@lowdefy/connection-axios-http": "0.0.0-experimental-20260420135540",
60
+ "@lowdefy/engine": "0.0.0-experimental-20260420135540",
61
+ "@lowdefy/errors": "0.0.0-experimental-20260420135540",
62
+ "@lowdefy/helpers": "0.0.0-experimental-20260420135540",
63
+ "@lowdefy/layout": "0.0.0-experimental-20260420135540",
64
+ "@lowdefy/logger": "0.0.0-experimental-20260420135540",
65
+ "@lowdefy/node-utils": "0.0.0-experimental-20260420135540",
66
+ "@lowdefy/operators-change-case": "0.0.0-experimental-20260420135540",
67
+ "@lowdefy/operators-dayjs": "0.0.0-experimental-20260420135540",
68
+ "@lowdefy/operators-diff": "0.0.0-experimental-20260420135540",
69
+ "@lowdefy/operators-js": "0.0.0-experimental-20260420135540",
70
+ "@lowdefy/operators-mql": "0.0.0-experimental-20260420135540",
71
+ "@lowdefy/operators-nunjucks": "0.0.0-experimental-20260420135540",
72
+ "@lowdefy/operators-uuid": "0.0.0-experimental-20260420135540",
73
+ "@lowdefy/operators-yaml": "0.0.0-experimental-20260420135540",
74
+ "@lowdefy/plugin-next-auth": "0.0.0-experimental-20260420135540",
74
75
  "@ant-design/cssinjs": "2.1.2",
75
76
  "antd": "6.3.1",
76
77
  "dayjs": "1.11.19",
package/pages/_app.js CHANGED
@@ -57,19 +57,11 @@ function App({ Component }) {
57
57
  lowdefyRef.current.theme = rootConfig.theme;
58
58
  }
59
59
 
60
- const { algorithm, token, components } = useDarkMode({
61
- antd: lowdefyRef.current.theme?.antd,
60
+ const algorithm = useDarkMode({
61
+ baseAlgorithm: lowdefyRef.current.theme?.antd?.algorithm,
62
62
  configDarkMode: lowdefyRef.current.theme?.darkMode,
63
63
  });
64
64
 
65
- const {
66
- lightToken: _lightToken,
67
- darkToken: _darkToken,
68
- lightComponents: _lightComponents,
69
- darkComponents: _darkComponents,
70
- ...antdConfig
71
- } = lowdefyRef.current.theme?.antd ?? {};
72
-
73
65
  // Runtime error callback — pushes errors to state for ErrorBar display.
74
66
  // Accepts Error objects (with .name) or plain objects (with .type) from build warnings.
75
67
  lowdefyRef.current._runtimeErrorCallback = useCallback((error) => {
@@ -103,9 +95,7 @@ function App({ Component }) {
103
95
  <StyleProvider layer>
104
96
  <ConfigProvider
105
97
  theme={{
106
- ...antdConfig,
107
- token,
108
- components,
98
+ ...lowdefyRef.current.theme?.antd,
109
99
  cssVar: { key: 'lowdefy' },
110
100
  hashed: false,
111
101
  algorithm,
@@ -26,27 +26,6 @@ const VALID_COLOR_MODES = ['system', 'light', 'dark'];
26
26
  const configColorMode = VALID_COLOR_MODES.includes(themeConfig.darkMode)
27
27
  ? themeConfig.darkMode
28
28
  : 'system';
29
- const darkBg = themeConfig?.antd?.darkToken?.colorBgLayout ?? '#000';
30
- const lightBg = themeConfig?.antd?.lightToken?.colorBgLayout ?? '';
31
-
32
- // Escape characters that could break out of the enclosing <script> tag or
33
- // terminate a JS string literal. Used to defuse the js/bad-code-sanitization
34
- // class of injection for values embedded into the pre-hydration inline script.
35
- const SCRIPT_ESCAPES = {
36
- '<': '\\u003C',
37
- '>': '\\u003E',
38
- '\b': '\\b',
39
- '\f': '\\f',
40
- '\n': '\\n',
41
- '\r': '\\r',
42
- '\t': '\\t',
43
- '\0': '\\0',
44
- '\u2028': '\\u2028',
45
- '\u2029': '\\u2029',
46
- };
47
- function safeScriptJson(value) {
48
- return JSON.stringify(value).replace(/[<>\b\f\n\r\t\0\u2028\u2029]/g, (c) => SCRIPT_ESCAPES[c]);
49
- }
50
29
 
51
30
  class LowdefyDocument extends Document {
52
31
  render() {
@@ -64,19 +43,12 @@ class LowdefyDocument extends Document {
64
43
  __html: `(function(){var s=document.createElement("style");s.id="__lf-layer-order";s.textContent="@layer theme, base, antd, components, utilities;";document.head.prepend(s);new MutationObserver(function(){if(document.head.firstChild!==s)document.head.prepend(s)}).observe(document.head,{childList:true})})();`,
65
44
  }}
66
45
  />
67
- {/* Synchronous pre-hydration background script — prevents mode-mismatch
68
- flash on page navigation. Mirrors useDarkMode.js resolution order:
69
- configDarkMode → localStorage → prefers-color-scheme. Uses the user's
70
- configured colorBgLayout tokens when present (theme.antd.darkToken and
71
- theme.antd.lightToken), falling back to #000 in dark and no inline style
72
- in light so default behavior is unchanged. */}
46
+ {/* Synchronous dark-mode background script — prevents white flash during
47
+ page navigation when the user is in dark mode. Mirrors the logic in
48
+ useDarkMode.js: configDarkMode → localStorage → prefers-color-scheme. */}
73
49
  <script
74
50
  dangerouslySetInnerHTML={{
75
- __html: `(function(){var c=${safeScriptJson(configColorMode)};var db=${safeScriptJson(
76
- darkBg
77
- )};var lb=${safeScriptJson(
78
- lightBg
79
- )};var d;if(c==="dark")d=true;else if(c==="light")d=false;else{try{var p=localStorage.getItem("lowdefy_darkMode");if(p==="dark")d=true;else if(p==="light")d=false;else d=window.matchMedia("(prefers-color-scheme:dark)").matches}catch(e){d=window.matchMedia("(prefers-color-scheme:dark)").matches}}var bg=d?db:lb;if(bg)document.documentElement.style.backgroundColor=bg})();`,
51
+ __html: `(function(){var c="${configColorMode}";if(c==="light")return;var d=false;if(c==="dark"){d=true}else{try{var p=localStorage.getItem("lowdefy_darkMode");if(p==="dark")d=true;else if(p==="light")d=false;else d=window.matchMedia("(prefers-color-scheme:dark)").matches}catch(e){d=window.matchMedia("(prefers-color-scheme:dark)").matches}}if(d)document.documentElement.style.backgroundColor="#000"})();`,
80
52
  }}
81
53
  />
82
54
  <link rel="manifest" href={`${basePath}/manifest.webmanifest`} />
@@ -0,0 +1,133 @@
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 crypto from 'crypto';
18
+
19
+ import { callAgent } from '@lowdefy/api';
20
+ import { createPhaseLogger } from '@lowdefy/ai-utils';
21
+ import { type } from '@lowdefy/helpers';
22
+
23
+ import apiWrapper from '../../../lib/server/apiWrapper.js';
24
+
25
+ async function handler({ context, req, res }) {
26
+ if (req.method !== 'POST') {
27
+ throw new Error('Only POST requests are supported.');
28
+ }
29
+ const segments = req.query.path;
30
+ if (!segments || segments.length < 2) {
31
+ res.status(400).json({ error: 'Invalid agent path' });
32
+ return;
33
+ }
34
+ const agentId = segments[segments.length - 1];
35
+ const pageId = segments.slice(0, -1).join('/');
36
+ context.logger.info({ color: 'gray' }, `Agent: ${pageId} → ${agentId}`);
37
+ const { conversationId } = req.query;
38
+ const { messages, urlQuery, sharedState, turnId: clientTurnId } = req.body;
39
+ if (!Array.isArray(messages)) {
40
+ res.status(400).json({ error: 'messages must be an array' });
41
+ return;
42
+ }
43
+ if (urlQuery != null && (typeof urlQuery !== 'object' || Array.isArray(urlQuery))) {
44
+ res.status(400).json({ error: 'urlQuery must be an object' });
45
+ return;
46
+ }
47
+ if (sharedState != null && !type.isObject(sharedState)) {
48
+ res.status(400).json({ error: 'sharedState must be an object' });
49
+ return;
50
+ }
51
+
52
+ const turnId =
53
+ typeof clientTurnId === 'string' && clientTurnId ? clientTurnId : crypto.randomUUID();
54
+ const turnStart = Date.now();
55
+ const phaseLogger = createPhaseLogger({
56
+ logger: context.logger,
57
+ agentId,
58
+ pageId,
59
+ conversationId: conversationId ?? undefined,
60
+ turnId,
61
+ turnStart,
62
+ });
63
+
64
+ const bodySize = (() => {
65
+ try {
66
+ return Buffer.byteLength(JSON.stringify(req.body ?? ''));
67
+ } catch {
68
+ return -1;
69
+ }
70
+ })();
71
+ const hasFiles = Array.isArray(messages)
72
+ ? messages.some((m) => (m?.parts ?? []).some((p) => p?.type === 'file'))
73
+ : false;
74
+ phaseLogger.phase('ingress.received', {
75
+ bodySize,
76
+ messageCount: messages.length,
77
+ hasFiles,
78
+ sharedStateKeys: sharedState ? Object.keys(sharedState).length : 0,
79
+ urlQueryKeys: urlQuery ? Object.keys(urlQuery).length : 0,
80
+ });
81
+
82
+ const { response: webResponse } = await callAgent(context, {
83
+ agentId,
84
+ pageId,
85
+ messages,
86
+ conversationId: conversationId ?? undefined,
87
+ sharedState: sharedState ?? undefined,
88
+ urlQuery: urlQuery ?? undefined,
89
+ phaseLogger,
90
+ turnId,
91
+ });
92
+
93
+ // Stream the Web Response body to the Next.js response
94
+ res.setHeader('Content-Type', 'text/event-stream');
95
+ res.setHeader('Cache-Control', 'no-cache');
96
+ res.setHeader('Connection', 'keep-alive');
97
+ res.setHeader('Content-Encoding', 'none');
98
+ res.setHeader('Transfer-Encoding', 'chunked');
99
+
100
+ phaseLogger.phase('ingress.stream.forward.start');
101
+
102
+ const reader = webResponse.body.getReader();
103
+ const decoder = new TextDecoder();
104
+ let done = false;
105
+ let firstByteLogged = false;
106
+ let chunkCount = 0;
107
+ let totalBytes = 0;
108
+ while (!done) {
109
+ const { value, done: readerDone } = await reader.read();
110
+ done = readerDone;
111
+ if (value) {
112
+ if (!firstByteLogged) {
113
+ firstByteLogged = true;
114
+ phaseLogger.phase('ingress.stream.first_byte', { bytes: value.byteLength });
115
+ }
116
+ chunkCount += 1;
117
+ totalBytes += value.byteLength;
118
+ res.write(decoder.decode(value, { stream: true }));
119
+ }
120
+ }
121
+ res.end();
122
+ phaseLogger.phase('ingress.stream.forward.done', { chunkCount, totalBytes });
123
+ }
124
+
125
+ export const config = {
126
+ api: {
127
+ bodyParser: {
128
+ sizeLimit: '10mb',
129
+ },
130
+ },
131
+ };
132
+
133
+ export default apiWrapper(handler);