@lowdefy/server-dev 7.2.0 → 7.4.0

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.
@@ -791,11 +791,12 @@ test('MCP tools/call lowdefy_run_journey reports a runner error as a tool error'
791
791
  await client.close();
792
792
  });
793
793
 
794
- test('MCP instructions teach lowdefy_run_journey as the way to verify behaviour', async () => {
794
+ test('MCP instructions send logic to a direct call and keep journeys for what a browser shows', async () => {
795
795
  const client = await connectClient();
796
796
  const instructions = client.getInstructions();
797
- expect(instructions).toContain('lowdefy_run_journey');
798
- expect(instructions).toContain('verify its behaviour');
797
+ expect(instructions).toContain('check logic with lowdefy_run_request or lowdefy_run_endpoint');
798
+ expect(instructions).toContain('keep lowdefy_run_journey for what only a browser shows');
799
+ expect(instructions).toContain('the merging agent runs these once, after the last merge');
799
800
  await client.close();
800
801
  });
801
802
 
@@ -33,7 +33,7 @@ const INSTRUCTIONS = `Lowdefy dev server for this project: docs for every instal
33
33
 
34
34
  Never guess a type name: lowdefy_list_types lists every installed type, lowdefy_get_schema gives its exact contract, and lowdefy_get_examples, lowdefy_get_doc and lowdefy_search_docs the docs, the app's own plugin and module docs included. lowdefy_app_map maps an existing app.
35
35
 
36
- After EVERY config edit, call lowdefy_build_status with wait: true. It answers once the edit is processed and the pages it touched are built, with the build status, located errors and recent browser and server errors. Fix what it reports, then check the page with lowdefy_get_page_config and lowdefy_screenshot_page, and verify its behaviour with lowdefy_run_journey. Call lowdefy_check before saying a change is done.
36
+ After EVERY config edit, call lowdefy_build_status with wait: true. It waits for the build and returns its status, located errors and recent browser and server errors. Fix what it reports. When the change is done, check logic with lowdefy_run_request or lowdefy_run_endpoint, keep lowdefy_run_journey for what only a browser shows, then call lowdefy_check. When agents share a change, the merging agent runs these once, after the last merge.
37
37
 
38
38
  If a tool result begins with "STALE:", the last build FAILED and the answer comes from the previous successful build, not from your latest edits: call lowdefy_build_status and fix the reported errors before trusting anything else.
39
39
 
@@ -69,7 +69,7 @@ const dataSchema = z
69
69
  // Shared by every tool that names a page instance: a page whose `path` has
70
70
  // placeholders has one instance per set of values.
71
71
  const pathParamsSchema = z
72
- .record(z.union([z.string(), z.number()]))
72
+ .record(z.string(), z.union([z.string(), z.number()]))
73
73
  .optional()
74
74
  .describe(
75
75
  'Values for the placeholders of a page whose path has them, read by _path_params, e.g. {"space": "support", "ticket_id": "1234"} for path "tickets/{space}/{ticket_id}" (lowdefy_app_map shows each page\'s path). Required to open such a page headless; a missing placeholder is an error naming it.'
@@ -128,7 +128,10 @@ const devToolDefinitions = {
128
128
  inputSchema: {
129
129
  pageId: z.string().describe('The page the request is defined on.'),
130
130
  requestId: z.string().describe('The request id.'),
131
- payload: z.record(z.any()).optional().describe('Test payload for _payload operators.'),
131
+ payload: z
132
+ .record(z.string(), z.any())
133
+ .optional()
134
+ .describe('Test payload for _payload operators.'),
132
135
  user: userSchema,
133
136
  data: dataSchema,
134
137
  saveResponse: saveResponseSchema,
@@ -141,7 +144,10 @@ const devToolDefinitions = {
141
144
  CALLER_NOTE,
142
145
  inputSchema: {
143
146
  endpointId: z.string().describe('The Api endpoint id.'),
144
- payload: z.record(z.any()).optional().describe('Test payload for _payload operators.'),
147
+ payload: z
148
+ .record(z.string(), z.any())
149
+ .optional()
150
+ .describe('Test payload for _payload operators.'),
145
151
  user: userSchema,
146
152
  data: dataSchema,
147
153
  system: z
@@ -223,13 +229,13 @@ const devToolDefinitions = {
223
229
  ),
224
230
  pathParams: pathParamsSchema,
225
231
  urlQuery: z
226
- .record(z.any())
232
+ .record(z.string(), z.any())
227
233
  .optional()
228
234
  .describe(
229
235
  'Query params to open the page with, read by _url_query, e.g. {"framework": "popia"}.'
230
236
  ),
231
237
  steps: z
232
- .array(z.record(z.any()))
238
+ .array(z.record(z.string(), z.any()))
233
239
  .optional()
234
240
  .describe(
235
241
  'Steps run in order after the page settles and before the capture, the same steps as lowdefy_run_journey (lowdefy_get_schema kind "journey-step" gives the grammar), e.g. [{"open": "status"}] to capture an open dropdown or [{"click": "add"}] for a modal. A {"screenshot": name} step captures an earlier state too. If a step fails the screenshot still returns, showing where it stopped.'
@@ -278,12 +284,12 @@ const devToolDefinitions = {
278
284
 
279
285
  lowdefy_run_journey: {
280
286
  description:
281
- 'Drive a page of the running dev server headless through declarative steps and assert what happens - the way to verify behaviour (a form submits, a modal opens, a filter works), not just layout. A step that fails stops the journey and comes back as data (passed: false, failure with index, step, expected, actual and message, later steps skipped), never as a tool error. A journey also fails at the step that raises an app error (an action error that is not a user error, an uncaught page error, a server error or 5xx): failure.kind "app-error" with errors [{kind, message, source, configKey}]. A failed Validate, a Throw action and 401/403 refusals never count; {"expect": {"error": text}} straight after an interaction claims an intended error. Returns the final page state (see state) and any screenshots, as images after the JSON.' +
287
+ 'Drive a page of the running dev server headless through declarative steps and assert what happens - the way to verify behaviour (a form submits, a modal opens, a filter works), not just layout. A step that fails stops the journey and comes back as data (passed: false, failure with index, step, expected, actual and message, later steps skipped), never as a tool error. A journey also fails at the step that raises an app error (an action error that is not a user error, an uncaught page error, a server error or 5xx): failure.kind "app-error" with errors [{kind, message, source, configKey}]. failure.kind "dev-server" means the dev server lost its web server and the request got no answer, so the result says nothing about the app: check the dev server log and run it again. A failed Validate, a Throw action and 401/403 refusals never count; {"expect": {"error": text}} straight after an interaction claims an intended error. Returns the final page state (see state) and any screenshots, as images after the JSON.' +
282
288
  CALLER_NOTE,
283
289
  inputSchema: {
284
290
  pageId: z.string().describe('The page id to open.'),
285
291
  steps: z
286
- .array(z.record(z.any()))
292
+ .array(z.record(z.string(), z.any()))
287
293
  .describe(
288
294
  'Ordered steps, one key each: click, open, fill, select, press, back, goto, email, as, wait, screenshot, expect. lowdefy_get_schema with kind "journey-step" returns the grammar of every step with examples, or of one with type, e.g. "expect". A target is a blockId or {"blockId", "row", "column", "text", "containing", "nth"}; "text" alone reaches dialog, menu and email buttons. Every id a step names is checked against the build before it runs. On a phone (device) only click, fill, select, press, wait, screenshot and expect state run.'
289
295
  ),
@@ -306,13 +312,13 @@ const devToolDefinitions = {
306
312
  'A data set in tests/data/<name>.yaml: the journey runs on a fresh in-memory MongoDB database loaded with it, so it may write freely, and user and "as" can name its users. Format: lowdefy_get_doc testing/journey-data-sets.'
307
313
  ),
308
314
  pathParams: z
309
- .record(z.string())
315
+ .record(z.string(), z.string())
310
316
  .optional()
311
317
  .describe(
312
318
  'Values for the placeholders of the page\'s path, read by _path_params, e.g. {"space": "support", "ticket_id": "1"} for path "{space}/tickets/{ticket_id}".'
313
319
  ),
314
320
  urlQuery: z
315
- .record(z.any())
321
+ .record(z.string(), z.any())
316
322
  .optional()
317
323
  .describe('Query params to open the page with, read by _url_query, e.g. {"id": "1"}.'),
318
324
  timeout: z
@@ -21,7 +21,6 @@ import createBrowserLifecycle from './createBrowserLifecycle.js';
21
21
  import guardJourneyOrigin from './guardJourneyOrigin.js';
22
22
  import isPageReady from './isPageReady.js';
23
23
  import launchBrowser from './launchBrowser.js';
24
- import { HEADLESS_USER_COOKIE } from '../server/auth/headlessUser.js';
25
24
  import resolveHeadlessUser from '../server/auth/resolveHeadlessUser.js';
26
25
  import { JOURNEY_COOKIES, writeJourneyCookie } from '../server/journeyCookies.js';
27
26
  import recordingCookiePayload from '../server/recording/recordingCookiePayload.js';
@@ -98,19 +97,20 @@ async function openPage({
98
97
  await onContext(context);
99
98
  }
100
99
  // Inject an authenticated user so auth-protected pages don't 404 for the
101
- // cookieless headless context. Mirrors the e2e user-cookie pattern; scoped to
102
- // `origin` so it rides along on the same-origin /api/* fetches. A user the
100
+ // cookieless headless context. Signed with the dev server's token like the
101
+ // other journey cookies, so no other client can name a user this way; scoped
102
+ // to `origin` so it rides along on the same-origin /api/* fetches. A user the
103
103
  // caller named is explicit: it beats a dev mock user (createLowdefyContext),
104
104
  // while the roleless default does not, so a screenshot under a mock user
105
105
  // still sees what the developer sees.
106
106
  if (injectedUser !== null) {
107
107
  const caller = { user: injectedUser, explicit: !type.isNone(user) };
108
108
  await context.addCookies([
109
- {
110
- name: HEADLESS_USER_COOKIE,
111
- value: Buffer.from(JSON.stringify(caller)).toString('base64'),
112
- url: origin,
113
- },
109
+ writeJourneyCookie({
110
+ name: JOURNEY_COOKIES.headlessUser.name,
111
+ payload: Buffer.from(JSON.stringify(caller)).toString('base64'),
112
+ origin,
113
+ }),
114
114
  ]);
115
115
  }
116
116
  // clientAddress is the address the context's requests come from, as far
@@ -21,6 +21,8 @@ import path from 'path';
21
21
  import { Hono } from 'hono';
22
22
  import { vi, afterAll, afterEach, expect, test } from 'vitest';
23
23
 
24
+ import getHeadlessUser from '../server/auth/getHeadlessUser.js';
25
+
24
26
  const mockLaunch = vi.fn();
25
27
  vi.doMock('playwright-core', () => ({
26
28
  chromium: { launch: mockLaunch },
@@ -82,9 +84,15 @@ function createBrowser() {
82
84
  };
83
85
  }
84
86
 
87
+ // Reads the cookie back through the dev server's own reader, so these tests
88
+ // also check that what the headless browser writes passes signature checks.
85
89
  function decodeCallerCookie(addCookies) {
86
90
  const [[[cookie]]] = addCookies.mock.calls;
87
- return JSON.parse(Buffer.from(cookie.value, 'base64').toString());
91
+ expect(cookie.httpOnly).toBe(true);
92
+ const cookieHeader = `${cookie.name}=${cookie.value}`;
93
+ return getHeadlessUser({
94
+ req: { header: (name) => (name === 'cookie' ? cookieHeader : undefined) },
95
+ });
88
96
  }
89
97
 
90
98
  function decodeUserCookie(addCookies) {
@@ -21,12 +21,13 @@ import fs from 'fs';
21
21
  // that was killed or crashed after the executable landed leaves a directory
22
22
  // without it: chromium.launch() checks only the executable and fails with a
23
23
  // launch error, while a new `playwright install` sees the missing marker and
24
- // installs again. The registry is Playwright's own (an exported subpath of the
25
- // pinned playwright-core), so the directory honours PLAYWRIGHT_BROWSERS_PATH.
24
+ // installs again. The registry is Playwright's own (the `registry` namespace of
25
+ // the pinned playwright-core's exported core bundle), so the directory honours
26
+ // PLAYWRIGHT_BROWSERS_PATH.
26
27
  async function isHeadlessShellIncomplete() {
27
- const { browserDirectoryToMarkerFilePath, registry } = await import(
28
- 'playwright-core/lib/server/registry/index'
29
- );
28
+ const {
29
+ registry: { browserDirectoryToMarkerFilePath, registry },
30
+ } = await import('playwright-core/lib/coreBundle');
30
31
  const { directory } = registry.findExecutable('chromium-headless-shell');
31
32
  return fs.existsSync(directory) && !fs.existsSync(browserDirectoryToMarkerFilePath(directory));
32
33
  }
@@ -24,7 +24,9 @@ import { afterAll, afterEach, expect, test } from 'vitest';
24
24
  const browsersPath = fs.mkdtempSync(path.join(os.tmpdir(), 'lowdefy-shell-'));
25
25
  process.env.PLAYWRIGHT_BROWSERS_PATH = browsersPath;
26
26
 
27
- const { registry } = await import('playwright-core/lib/server/registry/index');
27
+ const {
28
+ registry: { registry },
29
+ } = await import('playwright-core/lib/coreBundle');
28
30
  const { default: isHeadlessShellIncomplete } = await import('./isHeadlessShellIncomplete.js');
29
31
 
30
32
  const { directory } = registry.findExecutable('chromium-headless-shell');
@@ -56,10 +56,11 @@ function createContext() {
56
56
  failure: () => ({ errorText: 'net::ERR_ABORTED' }),
57
57
  });
58
58
  },
59
- respond({ url, status }) {
59
+ respond({ url, status, headers = {} }) {
60
60
  listeners.response({
61
61
  url: () => url,
62
62
  status: () => status,
63
+ headers: () => headers,
63
64
  request: () => ({ method: () => 'POST' }),
64
65
  });
65
66
  },
@@ -138,6 +139,19 @@ test('an unexplained 5xx from an app API route fails the step as request-failed'
138
139
  expect(findings.map((finding) => finding.kind)).toEqual(['request-failed']);
139
140
  });
140
141
 
142
+ test('a 502 the proxy answered itself fails the step as dev-server, not request-failed', async () => {
143
+ const findings = await runStepWindow({
144
+ step: { click: 'save' },
145
+ during: () =>
146
+ context.respond({
147
+ url: `${origin}/api/request/orders/save`,
148
+ status: 502,
149
+ headers: { 'x-lowdefy-child': 'dropped' },
150
+ }),
151
+ });
152
+ expect(findings.map((finding) => finding.kind)).toEqual(['dev-server']);
153
+ });
154
+
141
155
  test.each([
142
156
  ['AuthorizationError', 403],
143
157
  ['AuthenticationError', 401],
@@ -28,6 +28,7 @@ const SEVERITY = {
28
28
  'client-error': 'error',
29
29
  'server-error': 'error',
30
30
  'request-failed': 'error',
31
+ 'dev-server': 'error',
31
32
  'dead-click': 'warning',
32
33
  environment: 'info',
33
34
  };
@@ -64,6 +65,9 @@ function isDeadClick({ step, result, window }) {
64
65
  // server-error a server error entry this run caused
65
66
  // request-failed a 5xx from the app's request or endpoint routes that no
66
67
  // server error entry in the window explains
68
+ // dev-server the dev server's proxy answered for a child it could not
69
+ // reach: the request may not have run, and the app is not
70
+ // at fault
67
71
  // dead-click a click that succeeded and changed nothing: no event, no
68
72
  // lasting DOM change, no app request, no URL change
69
73
  // environment a server error from a request using a $search or
@@ -147,8 +151,23 @@ async function evaluateInvariants({
147
151
  source: entry.source,
148
152
  });
149
153
  });
154
+ window.responses
155
+ .filter((response) => !type.isNone(response.childState))
156
+ .forEach((response) => {
157
+ add({
158
+ kind: 'dev-server',
159
+ message: `${response.method} ${
160
+ new URL(response.url).pathname
161
+ } got no answer from the app: the dev server's connection to its web server failed (${
162
+ response.status
163
+ }, ${
164
+ response.childState
165
+ }). This is not an app error. Check the dev server log for a restart or crash, then run the journey again.`,
166
+ });
167
+ });
150
168
  window.responses
151
169
  .filter((response) => response.status >= 500)
170
+ .filter((response) => type.isNone(response.childState))
152
171
  .filter((response) => !isExplained({ response, serverEntries, basePath }))
153
172
  .forEach((response) => {
154
173
  add({
@@ -170,6 +189,10 @@ async function evaluateInvariants({
170
189
  if (findings.some((finding) => finding.kind === 'environment')) {
171
190
  findings = findings.filter((finding) => finding.kind === 'environment');
172
191
  }
192
+ // The page's own errors about a request that got no answer are only its echo.
193
+ if (findings.some((finding) => finding.kind === 'dev-server')) {
194
+ findings = findings.filter((finding) => finding.kind === 'dev-server');
195
+ }
173
196
  const seen = new Set();
174
197
  return findings
175
198
  .map((finding) => ({ ...finding, key: findingKey(finding) }))
@@ -170,6 +170,32 @@ test('a server error entry is a server-error, or environment when its request us
170
170
  ).toEqual([['environment', 'info']]);
171
171
  });
172
172
 
173
+ test('an answer from the proxy is a dev-server finding, and drops the errors that echo it', async () => {
174
+ const response = {
175
+ url: `${origin}/api/request/tickets/get_ticket`,
176
+ method: 'POST',
177
+ status: 502,
178
+ childState: 'dropped',
179
+ };
180
+ const findings = await evaluate({
181
+ window: quietWindow({
182
+ requests: [response],
183
+ responses: [response],
184
+ emits: [failedEmit('RequestError')],
185
+ errors: [{ store: 'client', message: 'Lowdefy dev server connection dropped.' }],
186
+ }),
187
+ });
188
+ expect(findings).toEqual([
189
+ expect.objectContaining({
190
+ kind: 'dev-server',
191
+ severity: 'error',
192
+ message: expect.stringContaining(
193
+ 'POST /api/request/tickets/get_ticket got no answer from the app'
194
+ ),
195
+ }),
196
+ ]);
197
+ });
198
+
173
199
  test('a 5xx from an app route is request-failed unless a server error entry for that request explains it', async () => {
174
200
  const response = {
175
201
  url: `${origin}/api/endpoints/assign_ticket`,
@@ -29,7 +29,8 @@ function describeWhere({ phase, index, step }) {
29
29
  // error with its kind, message, config source and finding key.
30
30
  // When the step also failed on its own, the app error leads the message, since
31
31
  // it is usually the cause, and the step's own message follows (and is kept
32
- // apart as stepMessage).
32
+ // apart as stepMessage). A dev-server finding makes it a dev server failure,
33
+ // not an app error: the journey says nothing about the app.
33
34
  function toAppErrorFailure({ findings, phase, index, step, stepFailure }) {
34
35
  const errors = findings.map(({ kind, message, source, configKey, key }) => ({
35
36
  kind,
@@ -39,12 +40,14 @@ function toAppErrorFailure({ findings, phase, index, step, stepFailure }) {
39
40
  key,
40
41
  }));
41
42
  const actual = errors.map((error) => `${error.kind}: ${error.message}`);
43
+ const lostDevServer = errors.some((error) => error.kind === 'dev-server');
42
44
  const count = errors.length === 1 ? 'an app error' : `${errors.length} app errors`;
43
- const message = `${describeWhere({ phase, index, step })} caused ${count}: ${actual.join('; ')}`;
45
+ const outcome = lostDevServer ? 'lost the dev server' : `caused ${count}`;
46
+ const message = `${describeWhere({ phase, index, step })} ${outcome}: ${actual.join('; ')}`;
44
47
  const failure = {
45
- kind: 'app-error',
48
+ kind: lostDevServer ? 'dev-server' : 'app-error',
46
49
  message,
47
- expected: 'no app error',
50
+ expected: lostDevServer ? 'the dev server to answer' : 'no app error',
48
51
  actual,
49
52
  errors,
50
53
  };
@@ -68,6 +68,7 @@ function watchJourneyContext({ context, events, origin, basePath }) {
68
68
  url: response.url(),
69
69
  method: response.request().method(),
70
70
  status: response.status(),
71
+ childState: response.headers()['x-lowdefy-child'] ?? null,
71
72
  });
72
73
  });
73
74
  }
@@ -66,6 +66,27 @@ test('withAppErrors fails a step that passed with the app errors its window held
66
66
  });
67
67
  });
68
68
 
69
+ test('withAppErrors reports a dev-server finding as a dev server failure, not an app error', () => {
70
+ const failure = withAppErrors({
71
+ findings: [
72
+ {
73
+ kind: 'dev-server',
74
+ message: 'POST /api/request/home/get_user got no answer from the app.',
75
+ },
76
+ ],
77
+ index: 2,
78
+ step: { goto: 'home' },
79
+ });
80
+ expect(failure).toEqual(
81
+ expect.objectContaining({
82
+ kind: 'dev-server',
83
+ expected: 'the dev server to answer',
84
+ message:
85
+ 'Step 2 (goto) lost the dev server: dev-server: POST /api/request/home/get_user got no answer from the app.',
86
+ })
87
+ );
88
+ });
89
+
69
90
  test('withAppErrors leads with the app error when the step also failed on its own', () => {
70
91
  const failure = withAppErrors({
71
92
  failure: { index: 0, step: { click: 'save' }, message: 'Expected text "Saved".' },
@@ -19,6 +19,8 @@ import os from 'os';
19
19
  import path from 'path';
20
20
  import { vi, afterAll, expect, test } from 'vitest';
21
21
 
22
+ import { journeyActorToken } from '../server/auth/journeyActor.js';
23
+
22
24
  // A real screenshot needs an installed browser, which jest can't rely on, so
23
25
  // this only covers the error paths: bad input, and chromium.launch failing
24
26
  // (the "no browser installed" case). chromium.launch is mocked so the real
@@ -273,7 +275,10 @@ test("screenshotPage renders as a data set user, on the data set's own database"
273
275
  dataSet: { name: 'crm', users: { member } },
274
276
  });
275
277
  const headless = cookies.find((cookie) => cookie.name === 'lowdefy_headless_user');
276
- const caller = JSON.parse(Buffer.from(headless.value, 'base64').toString());
278
+ expect(headless.httpOnly).toBe(true);
279
+ const [token, payload] = headless.value.split('.');
280
+ expect(token).toEqual(journeyActorToken);
281
+ const caller = JSON.parse(Buffer.from(payload, 'base64').toString());
277
282
  expect(caller.explicit).toBe(true);
278
283
  expect(caller.user).toMatchObject({ id: 'u_member', roles: ['member'] });
279
284
  expect(cookies.map((cookie) => cookie.name)).toContain('lowdefy_journey_data');
@@ -14,31 +14,34 @@
14
14
  limitations under the License.
15
15
  */
16
16
 
17
+ import JOURNEY_COOKIES from '../journeyCookies/JOURNEY_COOKIES.js';
18
+ import readJourneyCookie from '../journeyCookies/readJourneyCookie.js';
17
19
  import { remoteCallerHeader } from '../pairingHeaders.js';
18
- import { HEADLESS_USER_COOKIE } from './headlessUser.js';
19
20
 
20
- // Mirrors the e2e user-injection pattern (server-e2e/lib/server/auth/getUser.js):
21
- // the headless renderer sets a base64-JSON caller cookie on its own browser
22
- // context, so its /api/* fetches carry a pre-resolved caller while the
23
- // developer's real browser (no cookie) is unaffected. Returns { user, explicit }
24
- // as getBrowser.js wrote it, or null on miss - the caller floors the user's
25
- // shape via normalizeInjectedCaller. `explicit` is true when the tool call or
26
- // journey named the user, so createLowdefyContext lets it beat a dev mock user.
21
+ // The headless renderer (getBrowser.js) sets a signed caller cookie on its own
22
+ // browser context, so its /api/* fetches carry a pre-resolved caller while the
23
+ // developer's real browser (no cookie) is unaffected. Only a cookie signed with
24
+ // this dev server's journeyActorToken is read: any other request could
25
+ // otherwise name its own user and roles. Returns { user, explicit } as
26
+ // getBrowser.js wrote it, or null on miss - the caller floors the user's shape
27
+ // via normalizeInjectedCaller. `explicit` is true when the tool call or journey
28
+ // named the user, so createLowdefyContext lets it beat a dev mock user.
27
29
  // A request from another machine (a phone paired with `lowdefy dev --lan`) is
28
- // never a headless one: the cookie would let it sign in as anyone.
30
+ // never a headless one, so it is refused even with a valid cookie.
29
31
  function getHeadlessUser(c) {
30
32
  if (c.req.header(remoteCallerHeader) !== undefined) {
31
33
  return null;
32
34
  }
33
- const cookieHeader = c.req.header('cookie') ?? '';
34
- const match = cookieHeader.match(new RegExp(`${HEADLESS_USER_COOKIE}=([^;]+)`));
35
- if (!match) {
35
+ const payload = readJourneyCookie({
36
+ cookieHeader: c.req.header('cookie'),
37
+ name: JOURNEY_COOKIES.headlessUser.name,
38
+ });
39
+ if (payload === null) {
36
40
  return null;
37
41
  }
38
42
 
39
43
  try {
40
- const decoded = Buffer.from(decodeURIComponent(match[1]), 'base64').toString();
41
- return JSON.parse(decoded);
44
+ return JSON.parse(Buffer.from(payload, 'base64').toString());
42
45
  } catch {
43
46
  return null;
44
47
  }
@@ -14,9 +14,14 @@
14
14
  limitations under the License.
15
15
  */
16
16
 
17
- import getHeadlessUser from './getHeadlessUser.js';
18
17
  import { expect, test } from 'vitest';
19
18
 
19
+ import getHeadlessUser from './getHeadlessUser.js';
20
+ import JOURNEY_COOKIES from '../journeyCookies/JOURNEY_COOKIES.js';
21
+ import writeJourneyCookie from '../journeyCookies/writeJourneyCookie.js';
22
+
23
+ const caller = { user: { id: 'agent', roles: ['admin'] }, explicit: true };
24
+
20
25
  function contextWithCookie(cookie, headers = {}) {
21
26
  const all = { ...headers, cookie };
22
27
  return { req: { header: (name) => all[name] } };
@@ -26,11 +31,17 @@ function encode(value) {
26
31
  return Buffer.from(JSON.stringify(value)).toString('base64');
27
32
  }
28
33
 
29
- test('getHeadlessUser reads the user and whether the caller named it', () => {
30
- const caller = { user: { id: 'agent', roles: ['admin'] }, explicit: true };
31
- expect(
32
- getHeadlessUser(contextWithCookie(`other=1; lowdefy_headless_user=${encode(caller)}`))
33
- ).toEqual(caller);
34
+ function signedCookie(value) {
35
+ const { name, value: signed } = writeJourneyCookie({
36
+ name: JOURNEY_COOKIES.headlessUser.name,
37
+ payload: encode(value),
38
+ origin: 'http://localhost:3000',
39
+ });
40
+ return `${name}=${signed}`;
41
+ }
42
+
43
+ test('getHeadlessUser reads the user and whether the caller named it from a signed cookie', () => {
44
+ expect(getHeadlessUser(contextWithCookie(`other=1; ${signedCookie(caller)}`))).toEqual(caller);
34
45
  });
35
46
 
36
47
  test('getHeadlessUser returns null with no headless cookie', () => {
@@ -38,15 +49,38 @@ test('getHeadlessUser returns null with no headless cookie', () => {
38
49
  expect(getHeadlessUser(contextWithCookie('other=1'))).toBeNull();
39
50
  });
40
51
 
41
- test('getHeadlessUser returns null for a cookie that is not base64 JSON', () => {
42
- expect(getHeadlessUser(contextWithCookie('lowdefy_headless_user=%%%'))).toBeNull();
52
+ test('getHeadlessUser refuses an unsigned headless cookie', () => {
53
+ expect(getHeadlessUser(contextWithCookie(`lowdefy_headless_user=${encode(caller)}`))).toBeNull();
43
54
  });
44
55
 
45
- test('getHeadlessUser ignores the headless cookie on a request from another machine', () => {
46
- const caller = { user: { id: 'agent', roles: ['admin'] }, explicit: true };
56
+ test('getHeadlessUser refuses a headless cookie signed with another token', () => {
57
+ const forgedToken = 'f'.repeat(64);
58
+ expect(
59
+ getHeadlessUser(contextWithCookie(`lowdefy_headless_user=${forgedToken}.${encode(caller)}`))
60
+ ).toBeNull();
61
+ });
62
+
63
+ test('getHeadlessUser refuses a headless cookie whose token was cut short', () => {
64
+ const [, signed] = signedCookie(caller).split('=');
65
+ const token = signed.slice(0, signed.indexOf('.'));
47
66
  expect(
48
67
  getHeadlessUser(
49
- contextWithCookie(`lowdefy_headless_user=${encode(caller)}`, { 'x-lowdefy-dev-remote': '1' })
68
+ contextWithCookie(`lowdefy_headless_user=${token.slice(0, 10)}.${encode(caller)}`)
50
69
  )
51
70
  ).toBeNull();
52
71
  });
72
+
73
+ test('getHeadlessUser returns null for a signed cookie whose payload is not base64 JSON', () => {
74
+ const { value } = writeJourneyCookie({
75
+ name: JOURNEY_COOKIES.headlessUser.name,
76
+ payload: '%%%',
77
+ origin: 'http://localhost:3000',
78
+ });
79
+ expect(getHeadlessUser(contextWithCookie(`lowdefy_headless_user=${value}`))).toBeNull();
80
+ });
81
+
82
+ test('getHeadlessUser ignores a signed headless cookie on a request from another machine', () => {
83
+ expect(
84
+ getHeadlessUser(contextWithCookie(signedCookie(caller), { 'x-lowdefy-dev-remote': '1' }))
85
+ ).toBeNull();
86
+ });
@@ -14,10 +14,9 @@
14
14
  limitations under the License.
15
15
  */
16
16
 
17
- // Shared between the headless renderer (getBrowser.js, which sets the cookie on
18
- // its browser context) and the dev caller resolver (getHeadlessUser.js, which
19
- // decodes it) so the cookie name and injected user shape live in one place.
20
- const HEADLESS_USER_COOKIE = 'lowdefy_headless_user';
17
+ // The roleless user a headless browser context acts as when its caller names
18
+ // none (resolveHeadlessUser.js). The cookie that carries it is
19
+ // JOURNEY_COOKIES.headlessUser.
21
20
 
22
21
  // BetterAuth's session user carries `id`, never `sub`. attributes is floored to
23
22
  // {} by normalizeInjectedCaller at injection, so it is not spelled out here.
@@ -27,4 +26,4 @@ const headlessUser = {
27
26
  roles: [],
28
27
  };
29
28
 
30
- export { HEADLESS_USER_COOKIE, headlessUser };
29
+ export { headlessUser };
@@ -14,10 +14,11 @@
14
14
  limitations under the License.
15
15
  */
16
16
 
17
- // Every cookie the dev server's own headless browser sets on a journey
18
- // context. Each value is "<journeyActorToken>.<payload>", so only that browser
19
- // can set one: a cookie from anywhere else fails verification and is ignored.
20
- // The production server never reads any of them.
17
+ // Every cookie the dev server's own headless browser sets on its browser
18
+ // contexts (screenshots, journeys and the other headless tools). Each value is
19
+ // "<journeyActorToken>.<payload>", so only that browser can set one: a cookie
20
+ // from anywhere else fails verification and is ignored. The production server
21
+ // never reads any of them.
21
22
  //
22
23
  // kind: an inline cookie carries its whole meaning in the payload (an actor's
23
24
  // client address); a registry cookie carries the id of an entry the dev server
@@ -25,10 +26,17 @@
25
26
  //
26
27
  // loopback: a detached CallApi loops back through /api/detached/* as a fresh
27
28
  // request, so a cookie whose state must reach that request (the data set, the
28
- // mutant) is forwarded on it - see forwardJourneyCookies. The actor and
29
- // recording cookies describe the browser, not the work, and stay behind.
29
+ // mutant) is forwarded on it - see forwardJourneyCookies. The actor, headless
30
+ // user and recording cookies describe the browser, not the work, and stay
31
+ // behind.
32
+ //
33
+ // headlessUser carries the caller the headless context acts as (getBrowser.js
34
+ // writes it, getHeadlessUser.js reads it). Its signature is what keeps a
35
+ // request from outside the dev server's own browser from naming its own user
36
+ // and roles.
30
37
  const JOURNEY_COOKIES = {
31
38
  actor: { name: 'lowdefy_journey_actor', kind: 'inline', loopback: false },
39
+ headlessUser: { name: 'lowdefy_headless_user', kind: 'inline', loopback: false },
32
40
  recording: { name: 'lowdefy_recording', kind: 'inline', loopback: false },
33
41
  data: { name: 'lowdefy_journey_data', kind: 'registry', loopback: true },
34
42
  mutant: { name: 'lowdefy_journey_mutant', kind: 'registry', loopback: true },
@@ -0,0 +1,36 @@
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
+ // The manager's proxy (startProxy) is the only HTTP client of this server, and
18
+ // reuses its connections to it. Node closes a connection left idle past
19
+ // keepAliveTimeout on a timer, and timers run before the event loop reads
20
+ // sockets. So when synchronous work blocks the loop for longer than the timer
21
+ // (a page build deserializing large build artifacts takes seconds), a request
22
+ // the proxy has already written is never read: the expired timer closes the
23
+ // socket over it, the client sees ECONNRESET, and a POST cannot be replayed
24
+ // because the proxy cannot tell whether the app ran it. With no timer here, the
25
+ // proxy's agent alone decides when an idle connection closes, and a request
26
+ // waits out the blocked loop instead.
27
+ function keepIdleConnectionsOpen() {
28
+ return {
29
+ name: 'lowdefy-keep-idle-connections-open',
30
+ configureServer(server) {
31
+ server.httpServer.keepAliveTimeout = 0;
32
+ },
33
+ };
34
+ }
35
+
36
+ export default keepIdleConnectionsOpen;
@@ -0,0 +1,104 @@
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 { spawn } from 'node:child_process';
18
+ import net from 'node:net';
19
+
20
+ import { afterEach, expect, test } from 'vitest';
21
+
22
+ const pluginUrl = new URL('./keepIdleConnectionsOpen.js', import.meta.url).href;
23
+
24
+ const BLOCK_MS = 1000;
25
+
26
+ // Runs in its own process, so its blocked event loop does not block the test's
27
+ // client. A timer far shorter than Node's default keeps the test quick; it
28
+ // expires during the block just as the default does in a long page build.
29
+ function serverScript({ applyPlugin }) {
30
+ return `
31
+ import http from 'node:http';
32
+ import keepIdleConnectionsOpen from ${JSON.stringify(pluginUrl)};
33
+ const server = http.createServer((req, res) => {
34
+ req.resume();
35
+ req.on('end', () => {
36
+ if (req.url === '/block') {
37
+ res.on('finish', () => setImmediate(() => {
38
+ const until = Date.now() + ${BLOCK_MS};
39
+ while (Date.now() < until);
40
+ }));
41
+ }
42
+ res.end('answered ' + req.url);
43
+ });
44
+ });
45
+ server.keepAliveTimeout = 100;
46
+ server.keepAliveTimeoutBuffer = 0;
47
+ ${applyPlugin ? 'keepIdleConnectionsOpen().configureServer({ httpServer: server });' : ''}
48
+ server.listen(0, '127.0.0.1', () => console.log(server.address().port));
49
+ `;
50
+ }
51
+
52
+ let serverProcess;
53
+
54
+ afterEach(() => {
55
+ serverProcess?.kill();
56
+ });
57
+
58
+ function startServer({ applyPlugin }) {
59
+ serverProcess = spawn(process.execPath, [
60
+ '--input-type=module',
61
+ '-e',
62
+ serverScript({ applyPlugin }),
63
+ ]);
64
+ return new Promise((resolve, reject) => {
65
+ serverProcess.once('error', reject);
66
+ serverProcess.stdout.once('data', (data) => resolve(Number(String(data))));
67
+ });
68
+ }
69
+
70
+ // Writes the second request on the first's connection while the server is
71
+ // blocked, as the proxy's agent does when it reuses an idle socket.
72
+ function postDuringBlock({ port }) {
73
+ return new Promise((resolve) => {
74
+ const socket = net.connect({ host: '127.0.0.1', port });
75
+ let responses = '';
76
+ let posted = false;
77
+ socket.on('error', (error) => resolve({ error: error.code }));
78
+ socket.on('close', () => resolve({ responses }));
79
+ socket.on('data', (data) => {
80
+ responses += String(data);
81
+ if (!posted && responses.includes('answered /block')) {
82
+ posted = true;
83
+ setTimeout(() => {
84
+ socket.write('POST /save HTTP/1.1\r\nHost: x\r\nContent-Length: 0\r\n\r\n');
85
+ }, 50);
86
+ }
87
+ if (responses.includes('answered /save')) {
88
+ socket.destroy();
89
+ }
90
+ });
91
+ socket.write('GET /block HTTP/1.1\r\nHost: x\r\n\r\n');
92
+ });
93
+ }
94
+
95
+ test('a keep-alive timer that expires while the event loop is blocked resets a request already sent', async () => {
96
+ const port = await startServer({ applyPlugin: false });
97
+ expect(await postDuringBlock({ port })).toEqual({ error: 'ECONNRESET' });
98
+ });
99
+
100
+ test('keepIdleConnectionsOpen answers a request sent while the event loop is blocked', async () => {
101
+ const port = await startServer({ applyPlugin: true });
102
+ const { responses } = await postDuringBlock({ port });
103
+ expect(responses).toContain('answered /save');
104
+ });
@@ -53,6 +53,13 @@ child (a refused connect, or a keep-alive socket the dying child had closed)
53
53
  is replayed through the hold rather than answered 502: a child can close its
54
54
  sockets before the manager sees it exit.
55
55
 
56
+ Any other request that loses the child answers 502, and is never replayed: it
57
+ may already have run. A live child does not cause this, since it leaves idle
58
+ connections open for this proxy's agent to close (keepIdleConnectionsOpen).
59
+ What the proxy answers itself, because the child could not, says so in
60
+ x-lowdefy-child, and a journey reports it as a dev server failure rather than
61
+ an app error (evaluateInvariants).
62
+
56
63
  A child stopped for being idle (createIdleChild) is started again only by a
57
64
  request that is use (isActivity), which is held as for a restart. A request
58
65
  that is not use - a passive read, an event-stream GET, a websocket upgrade -
@@ -178,7 +185,7 @@ function forwardRequest(
178
185
  return;
179
186
  }
180
187
  if (!up) {
181
- res.writeHead(503, { 'content-type': 'application/json' });
188
+ res.writeHead(503, { 'content-type': 'application/json', 'x-lowdefy-child': 'restarting' });
182
189
  res.end(JSON.stringify({ message: 'Lowdefy dev server is restarting.' }));
183
190
  return;
184
191
  }
@@ -213,7 +220,7 @@ function forwardRequest(
213
220
  res.destroy();
214
221
  return;
215
222
  }
216
- res.writeHead(502, { 'content-type': 'application/json' });
223
+ res.writeHead(502, { 'content-type': 'application/json', 'x-lowdefy-child': 'dropped' });
217
224
  res.end(JSON.stringify({ message: 'Lowdefy dev server connection dropped.' }));
218
225
  });
219
226
  // A body read to recognise a build-status wait is sent as read. A
@@ -147,9 +147,9 @@ test('startProxy sends requests back through the hold once a confirmed child goe
147
147
  // A POST's body was consumed by the failed forward, so it fails once, and
148
148
  // the next request waits for the child instead of failing too.
149
149
  await stopChildAndRestartSoon();
150
- expect(
151
- (await fetch(`http://localhost:${port}/save`, { method: 'POST', body: '{}' })).status
152
- ).toBe(502);
150
+ const dropped = await fetch(`http://localhost:${port}/save`, { method: 'POST', body: '{}' });
151
+ expect(dropped.status).toBe(502);
152
+ expect(dropped.headers.get('x-lowdefy-child')).toBe('dropped');
153
153
  expect(await (await fetch(`http://localhost:${port}/c.js`)).text()).toBe('ok');
154
154
 
155
155
  // An exit the manager has seen sends the very next request through the hold.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lowdefy/server-dev",
3
- "version": "7.2.0",
3
+ "version": "7.4.0",
4
4
  "license": "Apache-2.0",
5
5
  "description": "",
6
6
  "homepage": "https://lowdefy.com",
@@ -43,45 +43,45 @@
43
43
  "@better-auth/oauth-provider": "1.7.7",
44
44
  "@better-auth/passkey": "1.7.7",
45
45
  "@hono/mcp": "0.3.2",
46
- "@hono/node-server": "2.0.10",
46
+ "@hono/node-server": "2.1.3",
47
47
  "@hono/vite-dev-server": "0.26.0",
48
- "@lowdefy/actions-core": "7.2.0",
49
- "@lowdefy/api": "7.2.0",
50
- "@lowdefy/block-utils": "7.2.0",
51
- "@lowdefy/blocks-aggrid": "7.2.0",
52
- "@lowdefy/blocks-antd": "7.2.0",
53
- "@lowdefy/blocks-antd-x": "7.2.0",
54
- "@lowdefy/blocks-basic": "7.2.0",
55
- "@lowdefy/blocks-captcha": "7.2.0",
56
- "@lowdefy/blocks-echarts": "7.2.0",
57
- "@lowdefy/blocks-loaders": "7.2.0",
58
- "@lowdefy/blocks-markdown": "7.2.0",
59
- "@lowdefy/blocks-table": "7.2.0",
60
- "@lowdefy/blocks-tiptap": "7.2.0",
61
- "@lowdefy/build": "7.2.0",
62
- "@lowdefy/client": "7.2.0",
63
- "@lowdefy/client-core": "7.2.0",
64
- "@lowdefy/connection-axios-http": "7.2.0",
65
- "@lowdefy/connection-mongodb": "7.2.0",
66
- "@lowdefy/docs-content": "7.2.0",
67
- "@lowdefy/e2e-utils": "7.2.0",
68
- "@lowdefy/engine": "7.2.0",
69
- "@lowdefy/errors": "7.2.0",
70
- "@lowdefy/helpers": "7.2.0",
71
- "@lowdefy/layout": "7.2.0",
72
- "@lowdefy/logger": "7.2.0",
73
- "@lowdefy/node-utils": "7.2.0",
74
- "@lowdefy/operators-change-case": "7.2.0",
75
- "@lowdefy/operators-cron": "7.2.0",
76
- "@lowdefy/operators-dayjs": "7.2.0",
77
- "@lowdefy/operators-diff": "7.2.0",
78
- "@lowdefy/operators-js": "7.2.0",
79
- "@lowdefy/operators-mql": "7.2.0",
80
- "@lowdefy/operators-nunjucks": "7.2.0",
81
- "@lowdefy/operators-uuid": "7.2.0",
82
- "@lowdefy/operators-yaml": "7.2.0",
83
- "@lowdefy/plugin-better-auth": "7.2.0",
84
- "@lowdefy/websockets-core": "7.2.0",
48
+ "@lowdefy/actions-core": "7.4.0",
49
+ "@lowdefy/api": "7.4.0",
50
+ "@lowdefy/block-utils": "7.4.0",
51
+ "@lowdefy/blocks-aggrid": "7.4.0",
52
+ "@lowdefy/blocks-antd": "7.4.0",
53
+ "@lowdefy/blocks-antd-x": "7.4.0",
54
+ "@lowdefy/blocks-basic": "7.4.0",
55
+ "@lowdefy/blocks-captcha": "7.4.0",
56
+ "@lowdefy/blocks-echarts": "7.4.0",
57
+ "@lowdefy/blocks-loaders": "7.4.0",
58
+ "@lowdefy/blocks-markdown": "7.4.0",
59
+ "@lowdefy/blocks-table": "7.4.0",
60
+ "@lowdefy/blocks-tiptap": "7.4.0",
61
+ "@lowdefy/build": "7.4.0",
62
+ "@lowdefy/client": "7.4.0",
63
+ "@lowdefy/client-core": "7.4.0",
64
+ "@lowdefy/connection-axios-http": "7.4.0",
65
+ "@lowdefy/connection-mongodb": "7.4.0",
66
+ "@lowdefy/docs-content": "7.4.0",
67
+ "@lowdefy/e2e-utils": "7.4.0",
68
+ "@lowdefy/engine": "7.4.0",
69
+ "@lowdefy/errors": "7.4.0",
70
+ "@lowdefy/helpers": "7.4.0",
71
+ "@lowdefy/layout": "7.4.0",
72
+ "@lowdefy/logger": "7.4.0",
73
+ "@lowdefy/node-utils": "7.4.0",
74
+ "@lowdefy/operators-change-case": "7.4.0",
75
+ "@lowdefy/operators-cron": "7.4.0",
76
+ "@lowdefy/operators-dayjs": "7.4.0",
77
+ "@lowdefy/operators-diff": "7.4.0",
78
+ "@lowdefy/operators-js": "7.4.0",
79
+ "@lowdefy/operators-mql": "7.4.0",
80
+ "@lowdefy/operators-nunjucks": "7.4.0",
81
+ "@lowdefy/operators-uuid": "7.4.0",
82
+ "@lowdefy/operators-yaml": "7.4.0",
83
+ "@lowdefy/plugin-better-auth": "7.4.0",
84
+ "@lowdefy/websockets-core": "7.4.0",
85
85
  "@modelcontextprotocol/sdk": "1.32.2",
86
86
  "@rc-component/qrcode": "2.0.0",
87
87
  "@tailwindcss/postcss": "4.3.3",
@@ -98,8 +98,8 @@
98
98
  "opener": "1.5.2",
99
99
  "picomatch": "4.0.7",
100
100
  "pino": "10.3.1",
101
- "playwright-core": "1.59.1",
102
- "postal-mime": "3.0.0",
101
+ "playwright-core": "1.65.0",
102
+ "postal-mime": "4.0.8",
103
103
  "react": "18.2.0",
104
104
  "react-dom": "18.2.0",
105
105
  "smtp-server": "3.19.13",
@@ -111,7 +111,7 @@
111
111
  "ws": "8.21.0",
112
112
  "yaml": "2.9.0",
113
113
  "yargs": "18.0.0",
114
- "zod": "3.25.76"
114
+ "zod": "4.6.7"
115
115
  },
116
116
  "devDependencies": {
117
117
  "jsdom": "19.0.0",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lowdefy/server-dev",
3
- "version": "7.2.0",
3
+ "version": "7.4.0",
4
4
  "license": "Apache-2.0",
5
5
  "description": "",
6
6
  "homepage": "https://lowdefy.com",
@@ -51,45 +51,45 @@
51
51
  "@better-auth/oauth-provider": "1.7.7",
52
52
  "@better-auth/passkey": "1.7.7",
53
53
  "@hono/mcp": "0.3.2",
54
- "@hono/node-server": "2.0.10",
54
+ "@hono/node-server": "2.1.3",
55
55
  "@hono/vite-dev-server": "0.26.0",
56
- "@lowdefy/actions-core": "7.2.0",
57
- "@lowdefy/api": "7.2.0",
58
- "@lowdefy/block-utils": "7.2.0",
59
- "@lowdefy/blocks-aggrid": "7.2.0",
60
- "@lowdefy/blocks-antd": "7.2.0",
61
- "@lowdefy/blocks-antd-x": "7.2.0",
62
- "@lowdefy/blocks-basic": "7.2.0",
63
- "@lowdefy/blocks-captcha": "7.2.0",
64
- "@lowdefy/blocks-echarts": "7.2.0",
65
- "@lowdefy/blocks-loaders": "7.2.0",
66
- "@lowdefy/blocks-markdown": "7.2.0",
67
- "@lowdefy/blocks-table": "7.2.0",
68
- "@lowdefy/blocks-tiptap": "7.2.0",
69
- "@lowdefy/build": "7.2.0",
70
- "@lowdefy/client": "7.2.0",
71
- "@lowdefy/client-core": "7.2.0",
72
- "@lowdefy/connection-axios-http": "7.2.0",
73
- "@lowdefy/connection-mongodb": "7.2.0",
74
- "@lowdefy/docs-content": "7.2.0",
75
- "@lowdefy/e2e-utils": "7.2.0",
76
- "@lowdefy/engine": "7.2.0",
77
- "@lowdefy/errors": "7.2.0",
78
- "@lowdefy/helpers": "7.2.0",
79
- "@lowdefy/layout": "7.2.0",
80
- "@lowdefy/logger": "7.2.0",
81
- "@lowdefy/node-utils": "7.2.0",
82
- "@lowdefy/operators-change-case": "7.2.0",
83
- "@lowdefy/operators-cron": "7.2.0",
84
- "@lowdefy/operators-dayjs": "7.2.0",
85
- "@lowdefy/operators-diff": "7.2.0",
86
- "@lowdefy/operators-js": "7.2.0",
87
- "@lowdefy/operators-mql": "7.2.0",
88
- "@lowdefy/operators-nunjucks": "7.2.0",
89
- "@lowdefy/operators-uuid": "7.2.0",
90
- "@lowdefy/operators-yaml": "7.2.0",
91
- "@lowdefy/plugin-better-auth": "7.2.0",
92
- "@lowdefy/websockets-core": "7.2.0",
56
+ "@lowdefy/actions-core": "7.4.0",
57
+ "@lowdefy/api": "7.4.0",
58
+ "@lowdefy/block-utils": "7.4.0",
59
+ "@lowdefy/blocks-aggrid": "7.4.0",
60
+ "@lowdefy/blocks-antd": "7.4.0",
61
+ "@lowdefy/blocks-antd-x": "7.4.0",
62
+ "@lowdefy/blocks-basic": "7.4.0",
63
+ "@lowdefy/blocks-captcha": "7.4.0",
64
+ "@lowdefy/blocks-echarts": "7.4.0",
65
+ "@lowdefy/blocks-loaders": "7.4.0",
66
+ "@lowdefy/blocks-markdown": "7.4.0",
67
+ "@lowdefy/blocks-table": "7.4.0",
68
+ "@lowdefy/blocks-tiptap": "7.4.0",
69
+ "@lowdefy/build": "7.4.0",
70
+ "@lowdefy/client": "7.4.0",
71
+ "@lowdefy/client-core": "7.4.0",
72
+ "@lowdefy/connection-axios-http": "7.4.0",
73
+ "@lowdefy/connection-mongodb": "7.4.0",
74
+ "@lowdefy/docs-content": "7.4.0",
75
+ "@lowdefy/e2e-utils": "7.4.0",
76
+ "@lowdefy/engine": "7.4.0",
77
+ "@lowdefy/errors": "7.4.0",
78
+ "@lowdefy/helpers": "7.4.0",
79
+ "@lowdefy/layout": "7.4.0",
80
+ "@lowdefy/logger": "7.4.0",
81
+ "@lowdefy/node-utils": "7.4.0",
82
+ "@lowdefy/operators-change-case": "7.4.0",
83
+ "@lowdefy/operators-cron": "7.4.0",
84
+ "@lowdefy/operators-dayjs": "7.4.0",
85
+ "@lowdefy/operators-diff": "7.4.0",
86
+ "@lowdefy/operators-js": "7.4.0",
87
+ "@lowdefy/operators-mql": "7.4.0",
88
+ "@lowdefy/operators-nunjucks": "7.4.0",
89
+ "@lowdefy/operators-uuid": "7.4.0",
90
+ "@lowdefy/operators-yaml": "7.4.0",
91
+ "@lowdefy/plugin-better-auth": "7.4.0",
92
+ "@lowdefy/websockets-core": "7.4.0",
93
93
  "@modelcontextprotocol/sdk": "1.32.2",
94
94
  "@rc-component/qrcode": "2.0.0",
95
95
  "@tailwindcss/postcss": "4.3.3",
@@ -106,8 +106,8 @@
106
106
  "opener": "1.5.2",
107
107
  "picomatch": "4.0.7",
108
108
  "pino": "10.3.1",
109
- "playwright-core": "1.59.1",
110
- "postal-mime": "3.0.0",
109
+ "playwright-core": "1.65.0",
110
+ "postal-mime": "4.0.8",
111
111
  "react": "18.2.0",
112
112
  "react-dom": "18.2.0",
113
113
  "smtp-server": "3.19.13",
@@ -119,7 +119,7 @@
119
119
  "ws": "8.21.0",
120
120
  "yaml": "2.9.0",
121
121
  "yargs": "18.0.0",
122
- "zod": "3.25.76"
122
+ "zod": "4.6.7"
123
123
  },
124
124
  "devDependencies": {
125
125
  "jsdom": "19.0.0",
@@ -22,6 +22,12 @@ import { timeout } from 'hono/timeout';
22
22
  // timeout signal (which apiContext folds into context.signal) cancels the upstream
23
23
  // calls the handler is waiting on, such as an AI provider call, instead of letting
24
24
  // them run, and bill, after the response has gone.
25
+ //
26
+ // The 504 has no body. The handler runs on after the 504 is sent, on the same context:
27
+ // a header set on it then, by the middleware around the handler or by the handler
28
+ // itself (c.redirect sets one), makes hono rebuild the sent 504 from its body. Sending
29
+ // it has already read that body, so the rebuild throws. A response with no body
30
+ // rebuilds safely. The client reads any 504 as a timeout.
25
31
  function requestTimeout({ timeoutMs }) {
26
32
  return function requestTimeoutMiddleware(c, next) {
27
33
  const controller = new AbortController();
@@ -30,7 +36,7 @@ function requestTimeout({ timeoutMs }) {
30
36
  controller.abort(
31
37
  new DOMException(`The request timeout of ${timeoutMs}ms was exceeded.`, 'TimeoutError')
32
38
  );
33
- return new HTTPException(504, { message: 'Gateway Timeout' });
39
+ return new HTTPException(504, { res: new Response(null, { status: 504 }) });
34
40
  })(c, next);
35
41
  };
36
42
  }
package/vite.config.js CHANGED
@@ -22,6 +22,7 @@ import { WebSocketServer } from 'ws';
22
22
  import watchOwner from '@lowdefy/node-utils/watchOwner.js';
23
23
 
24
24
  import createDevServerExclude from './lib/vite/createDevServerExclude.js';
25
+ import keepIdleConnectionsOpen from './lib/vite/keepIdleConnectionsOpen.js';
25
26
 
26
27
  const devServerEntry = './src/app.js';
27
28
 
@@ -88,6 +89,7 @@ export default defineConfig(({ mode }) => ({
88
89
  plugins: [
89
90
  react(),
90
91
  lowdefyWebSocket(),
92
+ keepIdleConnectionsOpen(),
91
93
  devServer({
92
94
  entry: devServerEntry,
93
95
  exclude: createDevServerExclude({ basePath }),