donobu 5.18.1 → 5.18.2

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.
@@ -1,10 +1,12 @@
1
1
  import type { GptClient } from '../../clients/GptClient';
2
2
  import type { BrowserStorageState } from '../../models/BrowserStorageState';
3
+ import { FlowLogBuffer } from '../../utils/FlowLogBuffer';
3
4
  import type { DonobuExtendedPage } from '../page/DonobuExtendedPage';
4
5
  export * from 'playwright/test';
5
6
  export declare const test: import("@playwright/test").TestType<import("@playwright/test").PlaywrightTestArgs & import("@playwright/test").PlaywrightTestOptions & {
6
7
  flowLoggingContext: {
7
8
  flowId: string;
9
+ logBuffer: FlowLogBuffer;
8
10
  };
9
11
  storageState?: BrowserStorageState | Promise<BrowserStorageState>;
10
12
  gptClient?: GptClient;
@@ -22,6 +22,7 @@ const v4_1 = require("zod/v4");
22
22
  const envVars_1 = require("../../envVars");
23
23
  const DonobuFlowsManager_1 = require("../../managers/DonobuFlowsManager");
24
24
  const BrowserUtils_1 = require("../../utils/BrowserUtils");
25
+ const FlowLogBuffer_1 = require("../../utils/FlowLogBuffer");
25
26
  const Logger_1 = require("../../utils/Logger");
26
27
  const MiscUtils_1 = require("../../utils/MiscUtils");
27
28
  const cacheLocator_1 = require("../ai/cache/cacheLocator");
@@ -55,16 +56,19 @@ exports.test = test_1.test.extend({
55
56
  // Donobu flow ID, so metadata would overwrite and concurrent executions could
56
57
  // clobber each other.
57
58
  const flowId = (0, crypto_1.randomUUID)();
58
- const flowContext = { flowId };
59
+ const logBuffer = new FlowLogBuffer_1.FlowLogBuffer();
60
+ const flowContext = { flowId, logBuffer };
59
61
  const asyncScope = new async_hooks_1.AsyncResource('DonobuFlowContext');
60
62
  await Logger_1.loggingContext.run(flowContext, async () => {
61
63
  Logger_1.loggingContext.enterWith(flowContext);
62
64
  (0, Logger_1.setProcessLocalFlowId)(flowId);
65
+ (0, Logger_1.setProcessLocalLogBuffer)(logBuffer);
63
66
  try {
64
- await asyncScope.runInAsyncScope(() => use({ flowId }));
67
+ await asyncScope.runInAsyncScope(() => use({ flowId, logBuffer }));
65
68
  }
66
69
  finally {
67
70
  (0, Logger_1.setProcessLocalFlowId)(null);
71
+ (0, Logger_1.setProcessLocalLogBuffer)(null);
68
72
  }
69
73
  });
70
74
  },
@@ -84,7 +88,7 @@ exports.test = test_1.test.extend({
84
88
  .optional()
85
89
  .default(250)
86
90
  .parse(testInfo.project.metadata['visualCueDurationMs']);
87
- const { flowId } = flowLoggingContext;
91
+ const { flowId, logBuffer } = flowLoggingContext;
88
92
  const extendedPage = await (0, extendPage_1.extendPage)(page, {
89
93
  flowId: flowId,
90
94
  visualCueDurationMs: visualCueDurationMs,
@@ -113,7 +117,7 @@ exports.test = test_1.test.extend({
113
117
  throw error;
114
118
  }
115
119
  finally {
116
- await finalizeTest(extendedPage, testInfo);
120
+ await finalizeTest(extendedPage, testInfo, logBuffer);
117
121
  }
118
122
  },
119
123
  });
@@ -224,7 +228,7 @@ async function attachStepScreenshots(sharedState, testInfo) {
224
228
  contentType: 'application/json',
225
229
  });
226
230
  }
227
- async function finalizeTest(page, testInfo) {
231
+ async function finalizeTest(page, testInfo, logBuffer) {
228
232
  const sharedState = page._dnb;
229
233
  try {
230
234
  sharedState.donobuFlowMetadata.state =
@@ -237,6 +241,17 @@ async function finalizeTest(page, testInfo) {
237
241
  body: JSON.stringify(sharedState.donobuFlowMetadata, null, 2),
238
242
  contentType: 'application/json',
239
243
  });
244
+ // Persist captured flow logs so they are available in the Donobu UI,
245
+ // mirroring what DonobuFlowsManager does for Studio-launched flows.
246
+ if (logBuffer) {
247
+ try {
248
+ const snapshot = logBuffer.snapshot();
249
+ await sharedState.persistence.setFlowFile(sharedState.donobuFlowMetadata.id, 'logs.json', Buffer.from(JSON.stringify(snapshot)));
250
+ }
251
+ catch (error) {
252
+ Logger_1.appLogger.error('Failed to persist flow logs:', error);
253
+ }
254
+ }
240
255
  // Attach step-level screenshots from the flow's tool call history.
241
256
  // These enable the HTML report to show a visual timeline of what the
242
257
  // AI agent saw at each step.
@@ -1,5 +1,6 @@
1
1
  import { AsyncLocalStorage } from 'async_hooks';
2
2
  import winston from 'winston';
3
+ import type { FlowLogBuffer } from '../utils/FlowLogBuffer';
3
4
  export declare const loggingContext: AsyncLocalStorage<unknown>;
4
5
  /**
5
6
  * ###################################################################################
@@ -12,11 +13,12 @@ export declare const loggingContext: AsyncLocalStorage<unknown>;
12
13
  * outside the ALS store even though we seed it later in the fixture.
13
14
  *
14
15
  * We therefore keep a *process-local* fallback that stores the most recent flow
15
- * ID for the worker. Because Playwright guarantees only one test runs at a time
16
- * per process, this is safe: there is no race between concurrent tests in the
17
- * same worker, yet we still avoid leaking IDs across workers.
16
+ * ID and log buffer for the worker. Because Playwright guarantees only one test
17
+ * runs at a time per process, this is safe: there is no race between concurrent
18
+ * tests in the same worker, yet we still avoid leaking IDs across workers.
18
19
  */
19
20
  export declare function setProcessLocalFlowId(flowId: string | null): void;
21
+ export declare function setProcessLocalLogBuffer(buffer: FlowLogBuffer | null): void;
20
22
  export declare const appLogger: winston.Logger;
21
23
  export declare const accessLogger: winston.Logger;
22
24
  export declare const browserLogger: winston.Logger;
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.networkLogger = exports.browserLogger = exports.accessLogger = exports.appLogger = exports.loggingContext = void 0;
7
7
  exports.setProcessLocalFlowId = setProcessLocalFlowId;
8
+ exports.setProcessLocalLogBuffer = setProcessLocalLogBuffer;
8
9
  exports.logErrorWithoutStack = logErrorWithoutStack;
9
10
  exports.formatLogInfoForTest = formatLogInfoForTest;
10
11
  const async_hooks_1 = require("async_hooks");
@@ -142,13 +143,15 @@ class FlowLogBufferTransport extends winston_transport_1.default {
142
143
  }
143
144
  log(info, callback) {
144
145
  const store = exports.loggingContext.getStore();
145
- if (store?.logBuffer) {
146
- store.logBuffer.push({ ...info, source: this.source });
146
+ const buffer = store?.logBuffer || processLocalLogBuffer;
147
+ if (buffer) {
148
+ buffer.push({ ...info, source: this.source });
147
149
  }
148
150
  callback();
149
151
  }
150
152
  }
151
153
  let processLocalFlowId = null;
154
+ let processLocalLogBuffer = null;
152
155
  /**
153
156
  * ###################################################################################
154
157
  * # WARNING! Only use this function within the context of Playwright test fixtures! #
@@ -160,13 +163,16 @@ let processLocalFlowId = null;
160
163
  * outside the ALS store even though we seed it later in the fixture.
161
164
  *
162
165
  * We therefore keep a *process-local* fallback that stores the most recent flow
163
- * ID for the worker. Because Playwright guarantees only one test runs at a time
164
- * per process, this is safe: there is no race between concurrent tests in the
165
- * same worker, yet we still avoid leaking IDs across workers.
166
+ * ID and log buffer for the worker. Because Playwright guarantees only one test
167
+ * runs at a time per process, this is safe: there is no race between concurrent
168
+ * tests in the same worker, yet we still avoid leaking IDs across workers.
166
169
  */
167
170
  function setProcessLocalFlowId(flowId) {
168
171
  processLocalFlowId = flowId;
169
172
  }
173
+ function setProcessLocalLogBuffer(buffer) {
174
+ processLocalLogBuffer = buffer;
175
+ }
170
176
  // Format to add the currently running flow's ID (if any) from AsyncLocalStorage
171
177
  const flowIdFormat = winston_1.default.format((info) => {
172
178
  const store = exports.loggingContext.getStore();
@@ -1,10 +1,12 @@
1
1
  import type { GptClient } from '../../clients/GptClient';
2
2
  import type { BrowserStorageState } from '../../models/BrowserStorageState';
3
+ import { FlowLogBuffer } from '../../utils/FlowLogBuffer';
3
4
  import type { DonobuExtendedPage } from '../page/DonobuExtendedPage';
4
5
  export * from 'playwright/test';
5
6
  export declare const test: import("@playwright/test").TestType<import("@playwright/test").PlaywrightTestArgs & import("@playwright/test").PlaywrightTestOptions & {
6
7
  flowLoggingContext: {
7
8
  flowId: string;
9
+ logBuffer: FlowLogBuffer;
8
10
  };
9
11
  storageState?: BrowserStorageState | Promise<BrowserStorageState>;
10
12
  gptClient?: GptClient;
@@ -22,6 +22,7 @@ const v4_1 = require("zod/v4");
22
22
  const envVars_1 = require("../../envVars");
23
23
  const DonobuFlowsManager_1 = require("../../managers/DonobuFlowsManager");
24
24
  const BrowserUtils_1 = require("../../utils/BrowserUtils");
25
+ const FlowLogBuffer_1 = require("../../utils/FlowLogBuffer");
25
26
  const Logger_1 = require("../../utils/Logger");
26
27
  const MiscUtils_1 = require("../../utils/MiscUtils");
27
28
  const cacheLocator_1 = require("../ai/cache/cacheLocator");
@@ -55,16 +56,19 @@ exports.test = test_1.test.extend({
55
56
  // Donobu flow ID, so metadata would overwrite and concurrent executions could
56
57
  // clobber each other.
57
58
  const flowId = (0, crypto_1.randomUUID)();
58
- const flowContext = { flowId };
59
+ const logBuffer = new FlowLogBuffer_1.FlowLogBuffer();
60
+ const flowContext = { flowId, logBuffer };
59
61
  const asyncScope = new async_hooks_1.AsyncResource('DonobuFlowContext');
60
62
  await Logger_1.loggingContext.run(flowContext, async () => {
61
63
  Logger_1.loggingContext.enterWith(flowContext);
62
64
  (0, Logger_1.setProcessLocalFlowId)(flowId);
65
+ (0, Logger_1.setProcessLocalLogBuffer)(logBuffer);
63
66
  try {
64
- await asyncScope.runInAsyncScope(() => use({ flowId }));
67
+ await asyncScope.runInAsyncScope(() => use({ flowId, logBuffer }));
65
68
  }
66
69
  finally {
67
70
  (0, Logger_1.setProcessLocalFlowId)(null);
71
+ (0, Logger_1.setProcessLocalLogBuffer)(null);
68
72
  }
69
73
  });
70
74
  },
@@ -84,7 +88,7 @@ exports.test = test_1.test.extend({
84
88
  .optional()
85
89
  .default(250)
86
90
  .parse(testInfo.project.metadata['visualCueDurationMs']);
87
- const { flowId } = flowLoggingContext;
91
+ const { flowId, logBuffer } = flowLoggingContext;
88
92
  const extendedPage = await (0, extendPage_1.extendPage)(page, {
89
93
  flowId: flowId,
90
94
  visualCueDurationMs: visualCueDurationMs,
@@ -113,7 +117,7 @@ exports.test = test_1.test.extend({
113
117
  throw error;
114
118
  }
115
119
  finally {
116
- await finalizeTest(extendedPage, testInfo);
120
+ await finalizeTest(extendedPage, testInfo, logBuffer);
117
121
  }
118
122
  },
119
123
  });
@@ -224,7 +228,7 @@ async function attachStepScreenshots(sharedState, testInfo) {
224
228
  contentType: 'application/json',
225
229
  });
226
230
  }
227
- async function finalizeTest(page, testInfo) {
231
+ async function finalizeTest(page, testInfo, logBuffer) {
228
232
  const sharedState = page._dnb;
229
233
  try {
230
234
  sharedState.donobuFlowMetadata.state =
@@ -237,6 +241,17 @@ async function finalizeTest(page, testInfo) {
237
241
  body: JSON.stringify(sharedState.donobuFlowMetadata, null, 2),
238
242
  contentType: 'application/json',
239
243
  });
244
+ // Persist captured flow logs so they are available in the Donobu UI,
245
+ // mirroring what DonobuFlowsManager does for Studio-launched flows.
246
+ if (logBuffer) {
247
+ try {
248
+ const snapshot = logBuffer.snapshot();
249
+ await sharedState.persistence.setFlowFile(sharedState.donobuFlowMetadata.id, 'logs.json', Buffer.from(JSON.stringify(snapshot)));
250
+ }
251
+ catch (error) {
252
+ Logger_1.appLogger.error('Failed to persist flow logs:', error);
253
+ }
254
+ }
240
255
  // Attach step-level screenshots from the flow's tool call history.
241
256
  // These enable the HTML report to show a visual timeline of what the
242
257
  // AI agent saw at each step.
@@ -1,5 +1,6 @@
1
1
  import { AsyncLocalStorage } from 'async_hooks';
2
2
  import winston from 'winston';
3
+ import type { FlowLogBuffer } from '../utils/FlowLogBuffer';
3
4
  export declare const loggingContext: AsyncLocalStorage<unknown>;
4
5
  /**
5
6
  * ###################################################################################
@@ -12,11 +13,12 @@ export declare const loggingContext: AsyncLocalStorage<unknown>;
12
13
  * outside the ALS store even though we seed it later in the fixture.
13
14
  *
14
15
  * We therefore keep a *process-local* fallback that stores the most recent flow
15
- * ID for the worker. Because Playwright guarantees only one test runs at a time
16
- * per process, this is safe: there is no race between concurrent tests in the
17
- * same worker, yet we still avoid leaking IDs across workers.
16
+ * ID and log buffer for the worker. Because Playwright guarantees only one test
17
+ * runs at a time per process, this is safe: there is no race between concurrent
18
+ * tests in the same worker, yet we still avoid leaking IDs across workers.
18
19
  */
19
20
  export declare function setProcessLocalFlowId(flowId: string | null): void;
21
+ export declare function setProcessLocalLogBuffer(buffer: FlowLogBuffer | null): void;
20
22
  export declare const appLogger: winston.Logger;
21
23
  export declare const accessLogger: winston.Logger;
22
24
  export declare const browserLogger: winston.Logger;
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.networkLogger = exports.browserLogger = exports.accessLogger = exports.appLogger = exports.loggingContext = void 0;
7
7
  exports.setProcessLocalFlowId = setProcessLocalFlowId;
8
+ exports.setProcessLocalLogBuffer = setProcessLocalLogBuffer;
8
9
  exports.logErrorWithoutStack = logErrorWithoutStack;
9
10
  exports.formatLogInfoForTest = formatLogInfoForTest;
10
11
  const async_hooks_1 = require("async_hooks");
@@ -142,13 +143,15 @@ class FlowLogBufferTransport extends winston_transport_1.default {
142
143
  }
143
144
  log(info, callback) {
144
145
  const store = exports.loggingContext.getStore();
145
- if (store?.logBuffer) {
146
- store.logBuffer.push({ ...info, source: this.source });
146
+ const buffer = store?.logBuffer || processLocalLogBuffer;
147
+ if (buffer) {
148
+ buffer.push({ ...info, source: this.source });
147
149
  }
148
150
  callback();
149
151
  }
150
152
  }
151
153
  let processLocalFlowId = null;
154
+ let processLocalLogBuffer = null;
152
155
  /**
153
156
  * ###################################################################################
154
157
  * # WARNING! Only use this function within the context of Playwright test fixtures! #
@@ -160,13 +163,16 @@ let processLocalFlowId = null;
160
163
  * outside the ALS store even though we seed it later in the fixture.
161
164
  *
162
165
  * We therefore keep a *process-local* fallback that stores the most recent flow
163
- * ID for the worker. Because Playwright guarantees only one test runs at a time
164
- * per process, this is safe: there is no race between concurrent tests in the
165
- * same worker, yet we still avoid leaking IDs across workers.
166
+ * ID and log buffer for the worker. Because Playwright guarantees only one test
167
+ * runs at a time per process, this is safe: there is no race between concurrent
168
+ * tests in the same worker, yet we still avoid leaking IDs across workers.
166
169
  */
167
170
  function setProcessLocalFlowId(flowId) {
168
171
  processLocalFlowId = flowId;
169
172
  }
173
+ function setProcessLocalLogBuffer(buffer) {
174
+ processLocalLogBuffer = buffer;
175
+ }
170
176
  // Format to add the currently running flow's ID (if any) from AsyncLocalStorage
171
177
  const flowIdFormat = winston_1.default.format((info) => {
172
178
  const store = exports.loggingContext.getStore();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "donobu",
3
- "version": "5.18.1",
3
+ "version": "5.18.2",
4
4
  "description": "Create browser automations with an LLM agent and replay them as Playwright scripts.",
5
5
  "main": "dist/main.js",
6
6
  "module": "dist/esm/main.js",