@eko-ai/eko-nodejs 3.0.0-alpha.4 → 3.0.0-alpha.6

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.
package/README.md CHANGED
@@ -63,7 +63,7 @@ const llms: LLMs = {
63
63
  },
64
64
  openai: {
65
65
  provider: "openai",
66
- model: "gpt-4.1",
66
+ model: "gpt-5",
67
67
  apiKey: "your-api-key"
68
68
  }
69
69
  };
package/dist/browser.d.ts CHANGED
@@ -10,6 +10,7 @@ export default class BrowserAgent extends BaseBrowserLabelsAgent {
10
10
  private headless;
11
11
  setHeadless(headless: boolean): void;
12
12
  setCdpWsEndpoint(cdpWsEndpoint: string): void;
13
+ initUserDataDir(userDataDir?: string): string | undefined;
13
14
  setOptions(options?: Record<string, any>): void;
14
15
  protected screenshot(agentContext: AgentContext): Promise<{
15
16
  imageBase64: string;
@@ -1 +1 @@
1
- {"version":3,"file":"browser.d.ts","sourceRoot":"","sources":["../src/browser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AACnE,OAAO,EAEL,OAAO,EACP,IAAI,EAEJ,cAAc,EACf,MAAM,YAAY,CAAC;AAEpB,MAAM,CAAC,OAAO,OAAO,YAAa,SAAQ,sBAAsB;IAC9D,OAAO,CAAC,aAAa,CAAC,CAAS;IAC/B,OAAO,CAAC,WAAW,CAAC,CAAS;IAC7B,OAAO,CAAC,OAAO,CAAC,CAAsB;IACtC,SAAS,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAAQ;IACzC,OAAO,CAAC,eAAe,CAA+B;IACtD,OAAO,CAAC,YAAY,CAAqB;IACzC,OAAO,CAAC,QAAQ,CAAkB;IAE3B,WAAW,CAAC,QAAQ,EAAE,OAAO;IAI7B,gBAAgB,CAAC,aAAa,EAAE,MAAM;IAItC,UAAU,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAA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AC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CAqC3E;AAED,OAAO,EAAE,YAAY,EAAE,CAAC"}
package/dist/index.cjs.js CHANGED
@@ -1,12 +1,13 @@
1
1
  'use strict';
2
2
 
3
+ var fs = require('fs');
4
+ var os = require('os');
5
+ var path$1 = require('path');
3
6
  var eko = require('@eko-ai/eko');
4
7
  var playwright = require('playwright');
5
8
  var fs$1 = require('fs/promises');
6
- var path$1 = require('path');
7
9
  var node_url = require('node:url');
8
10
  var node_path = require('node:path');
9
- var fs = require('fs');
10
11
  var actualFS = require('node:fs');
11
12
  var promises = require('node:fs/promises');
12
13
  var node_events = require('node:events');
@@ -31,8 +32,10 @@ function _interopNamespaceDefault(e) {
31
32
  return Object.freeze(n);
32
33
  }
33
34
 
34
- var fs__namespace = /*#__PURE__*/_interopNamespaceDefault(fs$1);
35
+ var fs__namespace = /*#__PURE__*/_interopNamespaceDefault(fs);
36
+ var os__namespace = /*#__PURE__*/_interopNamespaceDefault(os);
35
37
  var path__namespace = /*#__PURE__*/_interopNamespaceDefault(path$1);
38
+ var fs__namespace$1 = /*#__PURE__*/_interopNamespaceDefault(fs$1);
36
39
  var actualFS__namespace = /*#__PURE__*/_interopNamespaceDefault(actualFS);
37
40
 
38
41
  async function getCdpWsEndpoint(port) {
@@ -42,6 +45,104 @@ async function getCdpWsEndpoint(port) {
42
45
  eko.Log.info("browserInfo: ", browserInfo);
43
46
  return browserInfo.webSocketDebuggerUrl;
44
47
  }
48
+ function getDefaultChromeUserDataDir(copyToTempDir = false) {
49
+ const platform = os__namespace.platform();
50
+ const homeDir = os__namespace.homedir();
51
+ let defaultPath;
52
+ switch (platform) {
53
+ case "win32":
54
+ // Windows: %LOCALAPPDATA%\Google\Chrome\User Data
55
+ const localAppData = process.env.LOCALAPPDATA || path__namespace.join(homeDir, "AppData", "Local");
56
+ defaultPath = path__namespace.join(localAppData, "Google", "Chrome", "User Data");
57
+ break;
58
+ case "darwin":
59
+ // macOS: ~/Library/Application Support/Google/Chrome
60
+ defaultPath = path__namespace.join(homeDir, "Library", "Application Support", "Google", "Chrome");
61
+ break;
62
+ case "linux":
63
+ // Linux: ~/.config/google-chrome
64
+ defaultPath = path__namespace.join(homeDir, ".config", "google-chrome");
65
+ break;
66
+ }
67
+ if (defaultPath && fs__namespace.existsSync(defaultPath)) {
68
+ if (copyToTempDir) {
69
+ const tempDir = os__namespace.tmpdir();
70
+ const tempPath = path__namespace.join(tempDir, "chrome-user-data");
71
+ if (fs__namespace.existsSync(tempPath)) {
72
+ eko.Log.info(`Removing existing temp directory: ${tempPath}`);
73
+ fs__namespace.rmSync(tempPath, { recursive: true, force: true });
74
+ }
75
+ fs__namespace.cpSync(defaultPath, tempPath, { recursive: true });
76
+ // Delete all Chrome locked files and directories to prevent startup conflicts.
77
+ removeLockFiles(tempPath);
78
+ const defaultProfilePath = path__namespace.join(tempPath, "Default");
79
+ if (fs__namespace.existsSync(defaultProfilePath)) {
80
+ removeLockFiles(defaultProfilePath);
81
+ }
82
+ eko.Log.info(`Created clean Chrome user data directory: ${tempPath}`);
83
+ return tempPath;
84
+ }
85
+ else {
86
+ return defaultPath;
87
+ }
88
+ }
89
+ return undefined;
90
+ }
91
+ function removeLockFiles(dirPath) {
92
+ try {
93
+ const items = fs__namespace.readdirSync(dirPath);
94
+ items.forEach((item) => {
95
+ const itemPath = path__namespace.join(dirPath, item);
96
+ try {
97
+ const stat = fs__namespace.statSync(itemPath);
98
+ if (stat.isDirectory()) {
99
+ removeLockFiles(itemPath);
100
+ }
101
+ const shouldDelete = item === "SingletonLock" ||
102
+ item === "lockfile" ||
103
+ item === "RunningChromeVersion" ||
104
+ item === "SingletonCookie" ||
105
+ item === "SingletonSocket" ||
106
+ item === "chrome_debug.log" ||
107
+ item === "LOCK" ||
108
+ item === "LOG" ||
109
+ item === "LOG.old" ||
110
+ item.includes(".lock") ||
111
+ item.includes("Lock") ||
112
+ item.includes("LOCK") ||
113
+ item.includes(".tmp") ||
114
+ item.includes("Temp") ||
115
+ item.endsWith(".pid") ||
116
+ item.endsWith(".log") ||
117
+ item.includes("chrome_shutdown_ms.txt") ||
118
+ item.includes("Crashpad") ||
119
+ (stat.isDirectory() &&
120
+ (item.includes("CrashReports") ||
121
+ item.includes("ShaderCache") ||
122
+ item.includes("crashpad_database")));
123
+ if (shouldDelete) {
124
+ fs__namespace.rmSync(itemPath, { recursive: true, force: true });
125
+ }
126
+ }
127
+ catch (statError) {
128
+ if (item.includes("Lock") ||
129
+ item.includes("lock") ||
130
+ item.includes("LOCK")) {
131
+ try {
132
+ eko.Log.info(`Force deleting suspected lock file: ${itemPath}`);
133
+ fs__namespace.rmSync(itemPath, { recursive: true, force: true });
134
+ }
135
+ catch (deleteError) {
136
+ eko.Log.warn(`Failed to force delete ${itemPath}:`, deleteError);
137
+ }
138
+ }
139
+ }
140
+ });
141
+ }
142
+ catch (error) {
143
+ eko.Log.warn(`Error while removing lock files from ${dirPath}:`, error);
144
+ }
145
+ }
45
146
 
46
147
  class BrowserAgent extends eko.BaseBrowserLabelsAgent {
47
148
  constructor() {
@@ -57,6 +158,15 @@ class BrowserAgent extends eko.BaseBrowserLabelsAgent {
57
158
  setCdpWsEndpoint(cdpWsEndpoint) {
58
159
  this.cdpWsEndpoint = cdpWsEndpoint;
59
160
  }
161
+ initUserDataDir(userDataDir) {
162
+ if (userDataDir) {
163
+ this.userDataDir = userDataDir;
164
+ }
165
+ else {
166
+ this.userDataDir = getDefaultChromeUserDataDir(true);
167
+ }
168
+ return this.userDataDir;
169
+ }
60
170
  setOptions(options) {
61
171
  this.options = options;
62
172
  }
@@ -216,13 +326,34 @@ class BrowserAgent extends eko.BaseBrowserLabelsAgent {
216
326
  this.browser_context = await playwright.chromium.launchPersistentContext(this.userDataDir, {
217
327
  headless: this.headless,
218
328
  // channel: 'chrome',
329
+ args: [
330
+ "--no-sandbox",
331
+ "--remote-allow-origins=*",
332
+ "--disable-dev-shm-usage",
333
+ "--disable-popup-blocking",
334
+ "--enable-automation",
335
+ "--ignore-ssl-errors",
336
+ "--ignore-certificate-errors",
337
+ "--ignore-certificate-errors-spki-list",
338
+ "--disable-blink-features=AutomationControlled",
339
+ ],
219
340
  ...this.options,
220
341
  });
221
342
  }
222
343
  else {
223
344
  this.browser = await playwright.chromium.launch({
224
345
  headless: this.headless,
225
- args: ["--no-sandbox"],
346
+ args: [
347
+ "--no-sandbox",
348
+ "--remote-allow-origins=*",
349
+ "--disable-dev-shm-usage",
350
+ "--disable-popup-blocking",
351
+ "--enable-automation",
352
+ "--ignore-ssl-errors",
353
+ "--ignore-certificate-errors",
354
+ "--ignore-certificate-errors-spki-list",
355
+ "--disable-blink-features=AutomationControlled",
356
+ ],
226
357
  ...this.options,
227
358
  });
228
359
  this.browser_context = await this.browser.newContext();
@@ -8189,10 +8320,10 @@ glob.glob = glob;
8189
8320
 
8190
8321
  class FileAgent extends eko.BaseFileAgent {
8191
8322
  async file_list(agentContext, directoryPath) {
8192
- const files = await fs__namespace.readdir(directoryPath);
8323
+ const files = await fs__namespace$1.readdir(directoryPath);
8193
8324
  const fileDetails = await Promise.all(files.map(async (file) => {
8194
8325
  const filePath = path__namespace.join(directoryPath, file);
8195
- const stats = await fs__namespace.stat(filePath);
8326
+ const stats = await fs__namespace$1.stat(filePath);
8196
8327
  return {
8197
8328
  name: file,
8198
8329
  path: filePath,
@@ -8204,32 +8335,32 @@ class FileAgent extends eko.BaseFileAgent {
8204
8335
  return fileDetails;
8205
8336
  }
8206
8337
  async file_read(agentContext, filePath) {
8207
- return await fs__namespace.readFile(filePath, "utf-8");
8338
+ return await fs__namespace$1.readFile(filePath, "utf-8");
8208
8339
  }
8209
8340
  async file_write(agentContext, filePath, content, append) {
8210
8341
  const directory = path__namespace.dirname(filePath);
8211
- await fs__namespace.mkdir(directory, { recursive: true });
8342
+ await fs__namespace$1.mkdir(directory, { recursive: true });
8212
8343
  if (append) {
8213
- await fs__namespace.appendFile(filePath, content, "utf-8");
8344
+ await fs__namespace$1.appendFile(filePath, content, "utf-8");
8214
8345
  }
8215
8346
  else {
8216
- await fs__namespace.writeFile(filePath, content, "utf-8");
8347
+ await fs__namespace$1.writeFile(filePath, content, "utf-8");
8217
8348
  }
8218
8349
  }
8219
8350
  async file_str_replace(agentContext, filePath, oldStr, newStr) {
8220
- let content = await fs__namespace.readFile(filePath, "utf-8");
8351
+ let content = await fs__namespace$1.readFile(filePath, "utf-8");
8221
8352
  const originalContent = content;
8222
8353
  content = content.replace(new RegExp(oldStr, "g"), newStr);
8223
8354
  if (content === originalContent) {
8224
8355
  return;
8225
8356
  }
8226
- await fs__namespace.writeFile(filePath, content, "utf-8");
8357
+ await fs__namespace$1.writeFile(filePath, content, "utf-8");
8227
8358
  }
8228
8359
  async file_find_by_name(agentContext, directoryPath, globPattern) {
8229
8360
  const pattern = path__namespace.join(directoryPath, globPattern);
8230
8361
  const files = await glob.glob(pattern);
8231
8362
  const fileDetails = await Promise.all(files.map(async (file) => {
8232
- const stats = await fs__namespace.stat(file);
8363
+ const stats = await fs__namespace$1.stat(file);
8233
8364
  return {
8234
8365
  name: path__namespace.basename(file),
8235
8366
  path: file,
@@ -8300,7 +8431,9 @@ class SimpleStdioMcpClient {
8300
8431
  const callback = new Promise((resolve, reject) => {
8301
8432
  if (signal) {
8302
8433
  signal.addEventListener("abort", () => {
8303
- reject(new Error("AbortError"));
8434
+ const error = new Error("Operation was interrupted");
8435
+ error.name = "AbortError";
8436
+ reject(error);
8304
8437
  });
8305
8438
  }
8306
8439
  this.requestMap.set(id, resolve);