@minded-ai/mindedjs 2.0.9-beta.1 → 2.0.9-beta.3

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 +1 @@
1
- {"version":3,"file":"localBrowserTask.d.ts","sourceRoot":"","sources":["../../src/browserTask/localBrowserTask.ts"],"names":[],"mappings":"AAeA,MAAM,MAAM,oBAAoB,GAAG;IACjC,yDAAyD;IACzD,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,2CAA2C;IAC3C,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IACrB,0GAA0G;IAC1G,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,sBAAsB;IACtB,GAAG,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC;IACxB,6EAA6E;IAC7E,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF;;;GAGG;AACH,wBAAsB,kBAAkB,CACtC,IAAI,EAAE,oBAAoB,GACzB,OAAO,CAAC;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC,CAsJ7B;AA0BD,wBAAsB,IAAI,kBAMzB"}
1
+ {"version":3,"file":"localBrowserTask.d.ts","sourceRoot":"","sources":["../../src/browserTask/localBrowserTask.ts"],"names":[],"mappings":"AAeA,MAAM,MAAM,oBAAoB,GAAG;IACjC,yDAAyD;IACzD,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,2CAA2C;IAC3C,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IACrB,0GAA0G;IAC1G,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,sBAAsB;IACtB,GAAG,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC;IACxB,6EAA6E;IAC7E,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF;;;GAGG;AACH,wBAAsB,kBAAkB,CACtC,IAAI,EAAE,oBAAoB,GACzB,OAAO,CAAC;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC,CAgH7B;AAwBD,wBAAsB,IAAI,kBAMzB"}
@@ -28,13 +28,12 @@ exports.kill = kill;
28
28
  // getOrStartLocalCDP.ts
29
29
  const child_process_1 = require("child_process");
30
30
  const fs = __importStar(require("fs/promises"));
31
- const fscb = __importStar(require("fs"));
32
31
  const path = __importStar(require("path"));
33
- const http = __importStar(require("http"));
34
32
  const playwright_1 = require("playwright");
35
33
  const logger_1 = require("../utils/logger");
36
34
  const wait_1 = require("../utils/wait");
37
35
  let localBrowserTask = null;
36
+ const port = 9222;
38
37
  /**
39
38
  * Launch Chromium with --remote-debugging-port=0 and return the CDP ws URL.
40
39
  * Works with Chrome/Chromium/Chrome for Testing.
@@ -46,7 +45,7 @@ async function getOrStartLocalCDP(opts) {
46
45
  cdpUrl: localBrowserTask.cdpUrl,
47
46
  };
48
47
  }
49
- const { env, timeoutMs = 10000, } = opts;
48
+ const { env } = opts;
50
49
  const executablePath = playwright_1.chromium.executablePath();
51
50
  const profileDir = path.join(__dirname, "profile");
52
51
  await fs.mkdir(profileDir, { recursive: true });
@@ -116,7 +115,7 @@ async function getOrStartLocalCDP(opts) {
116
115
  "--enable-extensions",
117
116
  "--disable-extensions-file-access-check",
118
117
  "--enable-extension-activity-logging",
119
- `--remote-debugging-port=0`,
118
+ `--remote-debugging-port=${port}`,
120
119
  "--remote-debugging-address=0.0.0.0",
121
120
  "about:blank",
122
121
  ];
@@ -124,71 +123,41 @@ async function getOrStartLocalCDP(opts) {
124
123
  stdio: ["ignore", "ignore", "pipe"], // stderr is useful for debugging
125
124
  env: { ...process.env, ...env },
126
125
  });
127
- // If Chromium dies early, surface the error.
128
- const earlyExit = new Promise((_, reject) => {
129
- proc.once("exit", (code, signal) => {
130
- reject(new Error(`Chromium exited prematurely (code=${code}, signal=${signal}).`));
131
- });
126
+ proc.on("error", (error) => {
127
+ logger_1.logger.error({ message: 'Chromium error', error });
132
128
  });
133
- const devtoolsPortFile = path.join(userDataDir, "DevToolsActivePort");
134
- // Wait for DevToolsActivePort file to appear, then read it for port + browserId.
135
- const whenReady = (async () => {
136
- const startedAt = Date.now();
137
- while (Date.now() - startedAt < timeoutMs) {
138
- try {
139
- // Access succeeds once the file is written.
140
- await fs.access(devtoolsPortFile, fscb.constants.F_OK);
141
- break;
142
- }
143
- catch (_a) {
144
- await (0, wait_1.wait)(50);
145
- }
146
- }
147
- // If still not there, bail.
148
- await fs.access(devtoolsPortFile, fscb.constants.F_OK).catch(() => {
149
- throw new Error(`Timed out after ${timeoutMs}ms waiting for DevToolsActivePort at ${devtoolsPortFile}`);
150
- });
151
- const raw = await fs.readFile(devtoolsPortFile, "utf8");
152
- const [portLine] = raw.trim().split(/\r?\n/);
153
- const port = Number(portLine);
154
- if (!Number.isFinite(port)) {
155
- throw new Error(`Invalid DevTools port read from file: "${portLine}"`);
156
- }
157
- // Optional: ping /json/version to ensure the endpoint is responsive.
158
- await waitForHttpOk(`http://127.0.0.1:${port}/json/version`, timeoutMs);
159
- const cdpUrl = `http://127.0.0.1:${port}`;
160
- localBrowserTask = {
161
- cdpUrl,
162
- proc,
163
- };
164
- return { cdpUrl };
165
- })();
166
- const { cdpUrl } = await Promise.race([whenReady, earlyExit]);
129
+ proc.on("exit", (code, signal) => {
130
+ logger_1.logger.error({ message: 'Chromium exited', code, signal });
131
+ });
132
+ await waitForCdpEndpoint(port, 30);
133
+ const cdpUrl = `http://127.0.0.1:${port}`;
134
+ localBrowserTask = {
135
+ cdpUrl,
136
+ proc,
137
+ };
167
138
  logger_1.logger.info({ message: 'Local browser task started', cdpUrl });
168
139
  return { cdpUrl };
169
140
  }
170
- async function waitForHttpOk(url, timeoutMs) {
171
- const startedAt = Date.now();
172
- while (Date.now() - startedAt < timeoutMs) {
173
- const ok = await httpGetOk(url).catch(() => false);
174
- if (ok)
175
- return;
176
- await (0, wait_1.wait)(50);
141
+ // Legacy HTTP polling helpers removed in favor of waitForCdpEndpoint
142
+ async function waitForCdpEndpoint(port, maxAttempts) {
143
+ logger_1.logger.info({ message: `Waiting for CDP endpoint on port ${port}...` });
144
+ for (let attemptIndex = 0; attemptIndex < maxAttempts; attemptIndex++) {
145
+ try {
146
+ const response = await fetch(`http://127.0.0.1:${port}/json/version`);
147
+ if (response.ok) {
148
+ const version = await response.json();
149
+ logger_1.logger.info({ message: `CDP endpoint ready on port ${port}`, version: version["Browser"] });
150
+ return;
151
+ }
152
+ }
153
+ catch (error) {
154
+ if (attemptIndex % 5 === 0) {
155
+ logger_1.logger.debug({ message: `CDP endpoint not ready yet, attempt ${attemptIndex + 1}/${maxAttempts}`, error });
156
+ }
157
+ }
158
+ await (0, wait_1.wait)(1000);
177
159
  }
178
- throw new Error(`Timed out after ${timeoutMs}ms waiting for ${url}`);
179
- }
180
- function httpGetOk(urlStr) {
181
- return new Promise((resolve, reject) => {
182
- const req = http.get(urlStr, (res) => {
183
- // Drain data to allow socket reuse.
184
- res.resume();
185
- resolve(res.statusCode === 200);
186
- });
187
- req.on("error", reject);
188
- req.setTimeout(3000, () => {
189
- req.destroy(new Error("HTTP timeout"));
190
- });
191
- });
160
+ throw new Error(`CDP endpoint not available on port ${port} after ${maxAttempts} attempts`);
192
161
  }
193
162
  async function kill() {
194
163
  if (localBrowserTask) {
@@ -1 +1 @@
1
- {"version":3,"file":"localBrowserTask.js","sourceRoot":"","sources":["../../src/browserTask/localBrowserTask.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAgCA,gDAwJC;AA0BD,oBAMC;AAxND,wBAAwB;AACxB,iDAAoD;AACpD,gDAAkC;AAClC,yCAA2B;AAC3B,2CAA6B;AAC7B,2CAA6B;AAC7B,2CAAsC;AACtC,4CAAyC;AACzC,wCAAqC;AAErC,IAAI,gBAAgB,GAGT,IAAI,CAAC;AAehB;;;GAGG;AACI,KAAK,UAAU,kBAAkB,CACtC,IAA0B;;IAG1B,IAAI,gBAAgB,EAAE,CAAC;QACrB,OAAO;YACL,MAAM,EAAE,gBAAgB,CAAC,MAAM;SAChC,CAAC;IACJ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AAEM,KAAK,UAAU,IAAI;IACxB,IAAI,gBAAgB,EAAE,CAAC;QACrB,gBAAgB,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QACtC,MAAM,IAAA,WAAI,EAAC,GAAG,CAAC,CAAC;QAChB,gBAAgB,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IACxC,CAAC;AACH,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@minded-ai/mindedjs",
3
- "version": "2.0.9-beta.1",
3
+ "version": "2.0.9-beta.3",
4
4
  "description": "MindedJS is a TypeScript library for building agents.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1,9 +1,7 @@
1
1
  // getOrStartLocalCDP.ts
2
2
  import { spawn, ChildProcess } from "child_process";
3
3
  import * as fs from "fs/promises";
4
- import * as fscb from "fs";
5
4
  import * as path from "path";
6
- import * as http from "http";
7
5
  import { chromium } from "playwright";
8
6
  import { logger } from "../utils/logger";
9
7
  import { wait } from "../utils/wait";
@@ -13,6 +11,8 @@ let localBrowserTask: {
13
11
  proc: ChildProcess;
14
12
  } | null = null;
15
13
 
14
+ const port = 9222;
15
+
16
16
  export type StartChromiumOptions = {
17
17
  /** Headless by default. Set to false to see a window. */
18
18
  headless?: boolean;
@@ -40,10 +40,7 @@ export async function getOrStartLocalCDP(
40
40
  };
41
41
  }
42
42
 
43
- const {
44
- env,
45
- timeoutMs = 10_000,
46
- } = opts;
43
+ const { env } = opts;
47
44
 
48
45
  const executablePath = chromium.executablePath();
49
46
 
@@ -117,7 +114,7 @@ export async function getOrStartLocalCDP(
117
114
  "--enable-extensions",
118
115
  "--disable-extensions-file-access-check",
119
116
  "--enable-extension-activity-logging",
120
- `--remote-debugging-port=0`,
117
+ `--remote-debugging-port=${port}`,
121
118
  "--remote-debugging-address=0.0.0.0",
122
119
  "about:blank",
123
120
  ];
@@ -127,85 +124,48 @@ export async function getOrStartLocalCDP(
127
124
  env: { ...process.env, ...env },
128
125
  });
129
126
 
130
- // If Chromium dies early, surface the error.
131
- const earlyExit = new Promise<never>((_, reject) => {
132
- proc.once("exit", (code, signal) => {
133
- reject(
134
- new Error(`Chromium exited prematurely (code=${code}, signal=${signal}).`)
135
- );
136
- });
127
+ proc.on("error", (error) => {
128
+ logger.error({ message: 'Chromium error', error });
137
129
  });
138
130
 
139
- const devtoolsPortFile = path.join(userDataDir, "DevToolsActivePort");
140
-
141
- // Wait for DevToolsActivePort file to appear, then read it for port + browserId.
142
- const whenReady = (async () => {
143
- const startedAt = Date.now();
144
- while (Date.now() - startedAt < timeoutMs) {
145
- try {
146
- // Access succeeds once the file is written.
147
- await fs.access(devtoolsPortFile, fscb.constants.F_OK);
148
- break;
149
- } catch {
150
- await wait(50);
151
- }
152
- }
153
- // If still not there, bail.
154
- await fs.access(devtoolsPortFile, fscb.constants.F_OK).catch(() => {
155
- throw new Error(
156
- `Timed out after ${timeoutMs}ms waiting for DevToolsActivePort at ${devtoolsPortFile}`
157
- );
158
- });
159
-
160
- const raw = await fs.readFile(devtoolsPortFile, "utf8");
161
- const [portLine] = raw.trim().split(/\r?\n/);
162
- const port = Number(portLine);
163
- if (!Number.isFinite(port)) {
164
- throw new Error(`Invalid DevTools port read from file: "${portLine}"`);
165
- }
166
-
167
- // Optional: ping /json/version to ensure the endpoint is responsive.
168
- await waitForHttpOk(`http://127.0.0.1:${port}/json/version`, timeoutMs);
169
-
170
- const cdpUrl = `http://127.0.0.1:${port}`;
131
+ proc.on("exit", (code, signal) => {
132
+ logger.error({ message: 'Chromium exited', code, signal });
133
+ });
171
134
 
172
- localBrowserTask = {
173
- cdpUrl,
174
- proc,
175
- };
135
+ await waitForCdpEndpoint(port, 30);
176
136
 
177
- return { cdpUrl };
178
- })();
137
+ const cdpUrl = `http://127.0.0.1:${port}`;
179
138
 
180
- const { cdpUrl } = await Promise.race([whenReady, earlyExit]);
139
+ localBrowserTask = {
140
+ cdpUrl,
141
+ proc,
142
+ };
181
143
 
182
144
  logger.info({ message: 'Local browser task started', cdpUrl });
183
145
 
184
146
  return { cdpUrl };
185
147
  }
186
148
 
187
- async function waitForHttpOk(url: string, timeoutMs: number) {
188
- const startedAt = Date.now();
189
- while (Date.now() - startedAt < timeoutMs) {
190
- const ok = await httpGetOk(url).catch(() => false);
191
- if (ok) return;
192
- await wait(50);
149
+ // Legacy HTTP polling helpers removed in favor of waitForCdpEndpoint
150
+
151
+ async function waitForCdpEndpoint(port: number, maxAttempts: number): Promise<void> {
152
+ logger.info({ message: `Waiting for CDP endpoint on port ${port}...` });
153
+ for (let attemptIndex = 0; attemptIndex < maxAttempts; attemptIndex++) {
154
+ try {
155
+ const response = await fetch(`http://127.0.0.1:${port}/json/version`);
156
+ if (response.ok) {
157
+ const version = await response.json();
158
+ logger.info({ message: `CDP endpoint ready on port ${port}`, version: version["Browser"] });
159
+ return;
160
+ }
161
+ } catch (error) {
162
+ if (attemptIndex % 5 === 0) {
163
+ logger.debug({ message: `CDP endpoint not ready yet, attempt ${attemptIndex + 1}/${maxAttempts}`, error });
164
+ }
165
+ }
166
+ await wait(1000);
193
167
  }
194
- throw new Error(`Timed out after ${timeoutMs}ms waiting for ${url}`);
195
- }
196
-
197
- function httpGetOk(urlStr: string): Promise<boolean> {
198
- return new Promise((resolve, reject) => {
199
- const req = http.get(urlStr, (res) => {
200
- // Drain data to allow socket reuse.
201
- res.resume();
202
- resolve(res.statusCode === 200);
203
- });
204
- req.on("error", reject);
205
- req.setTimeout(3000, () => {
206
- req.destroy(new Error("HTTP timeout"));
207
- });
208
- });
168
+ throw new Error(`CDP endpoint not available on port ${port} after ${maxAttempts} attempts`);
209
169
  }
210
170
 
211
171
  export async function kill() {