@eko-ai/eko 3.1.3 → 3.1.5

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
@@ -75,7 +75,7 @@ Follow these steps when moving an existing Eko 2.x project to 3.0:
75
75
  const llms: LLMs = {
76
76
  default: {
77
77
  provider: "anthropic",
78
- model: "claude-sonnet-4-20250514",
78
+ model: "claude-sonnet-4-5-20250929",
79
79
  apiKey: "your-api-key"
80
80
  },
81
81
  gemini: {
@@ -1 +1 @@
1
- {"version":3,"file":"build_dom_tree.d.ts","sourceRoot":"","sources":["../../../src/agent/browser/build_dom_tree.ts"],"names":[],"mappings":"AACA,wBAAgB,kBAAkB,SAuxBjC"}
1
+ {"version":3,"file":"build_dom_tree.d.ts","sourceRoot":"","sources":["../../../src/agent/browser/build_dom_tree.ts"],"names":[],"mappings":"AACA,wBAAgB,kBAAkB,SAoxBjC"}
@@ -11,13 +11,4 @@ export declare function mark_screenshot_highlight_elements(screenshot: {
11
11
  width: number;
12
12
  height: number;
13
13
  }): Promise<string>;
14
- export declare function compress_image(imageBase64: string, imageType: "image/jpeg" | "image/png", compress: {
15
- scale: number;
16
- } | {
17
- resizeWidth: number;
18
- resizeHeight: number;
19
- }, quality?: number): Promise<{
20
- imageBase64: string;
21
- imageType: "image/jpeg" | "image/png";
22
- }>;
23
14
  //# sourceMappingURL=utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/agent/browser/utils.ts"],"names":[],"mappings":"AAAA,wBAAgB,oBAAoB,CAClC,cAAc,SAAM,EACpB,kBAAkB,SAAQ,UAoH3B;AAED,wBAAgB,kCAAkC,CAChD,UAAU,EAAE;IACV,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,YAAY,GAAG,WAAW,CAAC;CACvC,EACD,QAAQ,EAAE,MAAM,CACd,MAAM,EACN;IAAE,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CACxD,EACD,WAAW,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAC7C,OAAO,CAAC,MAAM,CAAC,CA+GjB;AAED,wBAAsB,cAAc,CAClC,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,YAAY,GAAG,WAAW,EACrC,QAAQ,EACJ;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,GACjB;IACE,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;CACtB,EACL,OAAO,GAAE,MAAU,GAClB,OAAO,CAAC;IACT,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,YAAY,GAAG,WAAW,CAAC;CACvC,CAAC,CA0CD"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/agent/browser/utils.ts"],"names":[],"mappings":"AAEA,wBAAgB,oBAAoB,CAClC,cAAc,SAAM,EACpB,kBAAkB,SAAQ,UAoH3B;AAED,wBAAgB,kCAAkC,CAChD,UAAU,EAAE;IACV,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,YAAY,GAAG,WAAW,CAAC;CACvC,EACD,QAAQ,EAAE,MAAM,CACd,MAAM,EACN;IAAE,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CACxD,EACD,WAAW,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAC7C,OAAO,CAAC,MAAM,CAAC,CA2KjB"}
@@ -8,9 +8,19 @@ export declare function convertToolSchema(tool: ToolSchema): LanguageModelV2Func
8
8
  export declare function toImage(mediaData: string): Uint8Array | string | URL;
9
9
  export declare function toFile(mediaData: string, type?: "base64|url" | "binary|url"): Uint8Array | string | URL;
10
10
  export declare function getMimeType(data: string): string;
11
+ export declare function compressImageData(imageBase64: string, imageType: "image/jpeg" | "image/png", compress: {
12
+ scale: number;
13
+ } | {
14
+ resizeWidth: number;
15
+ resizeHeight: number;
16
+ }, quality?: number): Promise<{
17
+ imageBase64: string;
18
+ imageType: "image/jpeg" | "image/png";
19
+ }>;
11
20
  export declare function mergeTools<T extends Tool | LanguageModelV2FunctionTool>(tools1: T[], tools2: T[]): T[];
12
21
  export declare function mergeAgents(agents1: Agent[], agents2: Agent[]): Agent[];
13
22
  export declare function sub(str: string, maxLength: number, appendPoint?: boolean): string;
14
23
  export declare function fixJson(code: string): any;
15
24
  export declare function fixXmlTag(code: string): string;
25
+ export declare function loadPackage(packageName: string): Promise<any>;
16
26
  //# sourceMappingURL=utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/common/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,2BAA2B,EAAE,MAAM,kBAAkB,CAAC;AAE/D,wBAAgB,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAEjD;AAED,wBAAgB,MAAM,IAAI,MAAM,CAM/B;AAED,wBAAgB,YAAY,CAAC,CAAC,SAAS,OAAO,CAAC,GAAG,CAAC,EACjD,GAAG,EAAE,MAAM,CAAC,EACZ,OAAO,EAAE,MAAM,EACf,cAAc,CAAC,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,IAAI,GACnC,OAAO,CAAC,CAAC,CAAC,CAgBZ;AAED,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,UAAU,GACf,2BAA2B,CA8B7B;AAED,wBAAgB,OAAO,CAAC,SAAS,EAAE,MAAM,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,OAAO,CAAC,GAAG,CAAC,CAWnE"}
package/dist/index.cjs.js CHANGED
@@ -286,6 +286,132 @@ function getMimeType(data) {
286
286
  }
287
287
  return mediaType;
288
288
  }
289
+ async function compressImageData(imageBase64, imageType, compress, quality) {
290
+ const base64Data = imageBase64;
291
+ const binaryString = typeof atob !== "undefined"
292
+ ? atob(base64Data)
293
+ // @ts-ignore
294
+ : Buffer.from(base64Data, "base64").toString("binary");
295
+ const bytes = new Uint8Array(binaryString.length);
296
+ for (let i = 0; i < binaryString.length; i++) {
297
+ bytes[i] = binaryString.charCodeAt(i);
298
+ }
299
+ if (!quality) {
300
+ if (bytes.length >= 1024 * 1024 * 3) {
301
+ quality = 0.6;
302
+ }
303
+ else if (bytes.length >= 1024 * 1024 * 1.5) {
304
+ quality = 0.8;
305
+ }
306
+ else {
307
+ quality = 1;
308
+ }
309
+ }
310
+ const targetByScale = (bitmapWidth, bitmapHeight) => ({
311
+ width: compress.scale
312
+ ? bitmapWidth * compress.scale
313
+ : compress.resizeWidth,
314
+ height: compress.scale
315
+ ? bitmapHeight * compress.scale
316
+ : compress.resizeHeight,
317
+ });
318
+ const hasOffscreen = typeof OffscreenCanvas !== "undefined";
319
+ const hasCreateImageBitmap = typeof createImageBitmap !== "undefined";
320
+ const hasDOM = typeof document !== "undefined" && typeof Image !== "undefined";
321
+ // @ts-ignore
322
+ const isNode = typeof window === "undefined" && typeof process !== "undefined" && !!process.versions && !!process.versions.node;
323
+ const loadImageAny = async () => {
324
+ if (hasCreateImageBitmap) {
325
+ const blob = new Blob([bytes], { type: imageType });
326
+ const bitmap = await createImageBitmap(blob);
327
+ return { img: bitmap, width: bitmap.width, height: bitmap.height };
328
+ }
329
+ if (hasDOM) {
330
+ const img = await new Promise((resolve, reject) => {
331
+ const image = new Image();
332
+ image.onload = () => resolve(image);
333
+ image.onerror = (e) => reject(e);
334
+ image.src = `data:${imageType};base64,${imageBase64}`;
335
+ });
336
+ return { img, width: img.width, height: img.height };
337
+ }
338
+ if (isNode) {
339
+ const canvasMod = await loadPackage("canvas");
340
+ const { loadImage } = canvasMod;
341
+ const dataUrl = `data:${imageType};base64,${imageBase64}`;
342
+ const img = await loadImage(dataUrl);
343
+ return { img, width: img.width, height: img.height };
344
+ }
345
+ throw new Error("No image environment available");
346
+ };
347
+ const createCanvasAny = async (width, height) => {
348
+ if (hasOffscreen) {
349
+ const canvas = new OffscreenCanvas(width, height);
350
+ return {
351
+ ctx: canvas.getContext("2d"),
352
+ exportBase64: async (mime, q) => {
353
+ const blob = await canvas.convertToBlob({ type: mime, quality: q });
354
+ return await new Promise((res, rej) => {
355
+ const reader = new FileReader();
356
+ reader.onloadend = () => {
357
+ const url = reader.result;
358
+ res(url.substring(url.indexOf("base64,") + 7));
359
+ };
360
+ reader.onerror = () => rej(new Error("Failed to convert blob to base64"));
361
+ reader.readAsDataURL(blob);
362
+ });
363
+ },
364
+ };
365
+ }
366
+ if (hasDOM) {
367
+ const canvas = document.createElement("canvas");
368
+ canvas.width = width;
369
+ canvas.height = height;
370
+ return {
371
+ ctx: canvas.getContext("2d"),
372
+ exportBase64: async (mime, q) => {
373
+ const dataUrl = canvas.toDataURL(mime, q);
374
+ return dataUrl.substring(dataUrl.indexOf("base64,") + 7);
375
+ },
376
+ };
377
+ }
378
+ if (isNode) {
379
+ const canvasMod = await loadPackage("canvas");
380
+ const { createCanvas } = canvasMod;
381
+ const canvas = createCanvas(width, height);
382
+ return {
383
+ ctx: canvas.getContext("2d"),
384
+ exportBase64: async (mime, q) => {
385
+ const buffer = canvas.toBuffer(mime, { quality: q });
386
+ // @ts-ignore
387
+ return (typeof Buffer !== "undefined" ? Buffer.from(buffer) : buffer).toString("base64");
388
+ },
389
+ };
390
+ }
391
+ throw new Error("No canvas environment available");
392
+ };
393
+ const loaded = await loadImageAny();
394
+ const { width, height } = targetByScale(loaded.width, loaded.height);
395
+ if (loaded.width == width && loaded.height == height && quality == 1) {
396
+ return {
397
+ imageBase64: imageBase64,
398
+ imageType: imageType,
399
+ };
400
+ }
401
+ const { ctx, exportBase64 } = await createCanvasAny(width, height);
402
+ if (!ctx) {
403
+ return {
404
+ imageBase64: imageBase64,
405
+ imageType: imageType,
406
+ };
407
+ }
408
+ ctx.drawImage(loaded.img, 0, 0, width, height);
409
+ const outBase64 = await exportBase64("image/jpeg", quality);
410
+ return {
411
+ imageBase64: outBase64,
412
+ imageType: "image/jpeg",
413
+ };
414
+ }
289
415
  function mergeTools(tools1, tools2) {
290
416
  let tools = [];
291
417
  let toolMap2 = tools2.reduce((map, tool) => {
@@ -491,6 +617,19 @@ function fixXmlTag(code) {
491
617
  let completedCode = code + missingParts.join("");
492
618
  return completedCode;
493
619
  }
620
+ async function loadPackage(packageName) {
621
+ // @ts-ignore
622
+ if (typeof require !== 'undefined') {
623
+ try {
624
+ return await import(packageName);
625
+ }
626
+ catch {
627
+ // @ts-ignore
628
+ return require(packageName);
629
+ }
630
+ }
631
+ return await import(packageName);
632
+ }
494
633
 
495
634
  // src/errors/ai-sdk-error.ts
496
635
  var marker$1 = "vercel.ai.error";
@@ -35134,28 +35273,92 @@ function extract_page_content(max_url_length = 200, max_content_length = 50000)
35134
35273
  function mark_screenshot_highlight_elements(screenshot, area_map, client_rect) {
35135
35274
  return new Promise(async (resolve, reject) => {
35136
35275
  try {
35137
- // Convert base64 to Blob
35138
- const base64Data = screenshot.imageBase64;
35139
- const binaryString = atob(base64Data);
35140
- const bytes = new Uint8Array(binaryString.length);
35141
- for (let i = 0; i < binaryString.length; i++) {
35142
- bytes[i] = binaryString.charCodeAt(i);
35143
- }
35144
- const blob = new Blob([bytes], { type: screenshot.imageType });
35145
- const imageBitmap = await createImageBitmap(blob, {
35146
- resizeQuality: "high",
35147
- resizeWidth: client_rect.width,
35148
- resizeHeight: client_rect.height,
35149
- });
35150
- const canvas = new OffscreenCanvas(imageBitmap.width, imageBitmap.height);
35151
- const ctx = canvas.getContext("2d");
35276
+ const hasOffscreen = typeof OffscreenCanvas !== "undefined";
35277
+ const hasCreateImageBitmap = typeof createImageBitmap !== "undefined";
35278
+ const hasDOM = typeof document !== "undefined" && typeof Image !== "undefined";
35279
+ // @ts-ignore
35280
+ const isNode = typeof window === "undefined" && typeof process !== "undefined" && !!process.versions && !!process.versions.node;
35281
+ const loadImageAny = async () => {
35282
+ if (hasCreateImageBitmap) {
35283
+ const base64Data = screenshot.imageBase64;
35284
+ const binaryString = atob(base64Data);
35285
+ const bytes = new Uint8Array(binaryString.length);
35286
+ for (let i = 0; i < binaryString.length; i++) {
35287
+ bytes[i] = binaryString.charCodeAt(i);
35288
+ }
35289
+ const blob = new Blob([bytes], { type: screenshot.imageType });
35290
+ const imageBitmap = await createImageBitmap(blob, {
35291
+ resizeQuality: "high",
35292
+ resizeWidth: client_rect.width,
35293
+ resizeHeight: client_rect.height,
35294
+ });
35295
+ return { img: imageBitmap };
35296
+ }
35297
+ if (hasDOM) {
35298
+ const img = await new Promise((resolveImg, rejectImg) => {
35299
+ const image = new Image();
35300
+ image.onload = () => resolveImg(image);
35301
+ image.onerror = (e) => rejectImg(e);
35302
+ image.src = `data:${screenshot.imageType};base64,${screenshot.imageBase64}`;
35303
+ });
35304
+ return { img };
35305
+ }
35306
+ if (isNode) {
35307
+ const canvasMod = await loadPackage("canvas");
35308
+ const { loadImage } = canvasMod;
35309
+ const dataUrl = `data:${screenshot.imageType};base64,${screenshot.imageBase64}`;
35310
+ const img = await loadImage(dataUrl);
35311
+ return { img };
35312
+ }
35313
+ throw new Error("No image environment available");
35314
+ };
35315
+ const createCanvasAny = async (width, height) => {
35316
+ if (hasOffscreen) {
35317
+ const canvas = new OffscreenCanvas(width, height);
35318
+ return {
35319
+ ctx: canvas.getContext("2d"),
35320
+ exportDataUrl: async (mime) => {
35321
+ const blob = await canvas.convertToBlob({ type: mime });
35322
+ return await new Promise((res, rej) => {
35323
+ const reader = new FileReader();
35324
+ reader.onloadend = () => res(reader.result);
35325
+ reader.onerror = () => rej(new Error("Failed to convert blob to base64"));
35326
+ reader.readAsDataURL(blob);
35327
+ });
35328
+ },
35329
+ };
35330
+ }
35331
+ if (hasDOM) {
35332
+ const canvas = document.createElement("canvas");
35333
+ canvas.width = width;
35334
+ canvas.height = height;
35335
+ return {
35336
+ ctx: canvas.getContext("2d"),
35337
+ exportDataUrl: async (mime) => canvas.toDataURL(mime),
35338
+ };
35339
+ }
35340
+ if (isNode) {
35341
+ const canvasMod = await loadPackage("canvas");
35342
+ const { createCanvas } = canvasMod;
35343
+ const canvas = createCanvas(width, height);
35344
+ return {
35345
+ ctx: canvas.getContext("2d"),
35346
+ exportDataUrl: async (mime) => canvas.toDataURL(mime),
35347
+ };
35348
+ }
35349
+ throw new Error("No canvas environment available");
35350
+ };
35351
+ const loaded = await loadImageAny();
35352
+ const targetWidth = client_rect.width;
35353
+ const targetHeight = client_rect.height;
35354
+ const { ctx, exportDataUrl } = await createCanvasAny(targetWidth, targetHeight);
35152
35355
  if (!ctx) {
35153
35356
  reject(new Error("Failed to get canvas context"));
35154
35357
  return;
35155
35358
  }
35156
35359
  ctx.imageSmoothingEnabled = true;
35157
35360
  ctx.imageSmoothingQuality = "high";
35158
- ctx.drawImage(imageBitmap, 0, 0);
35361
+ ctx.drawImage(loaded.img, 0, 0, targetWidth, targetHeight);
35159
35362
  const sortedEntries = Object.entries(area_map)
35160
35363
  .filter(([id, area]) => area.width > 0 && area.height > 0)
35161
35364
  .sort((a, b) => {
@@ -35191,9 +35394,10 @@ function mark_screenshot_highlight_elements(screenshot, area_map, client_rect) {
35191
35394
  // Draw ID tag background
35192
35395
  const fontSize = Math.min(12, Math.max(8, area.height / 2));
35193
35396
  ctx.font = `${fontSize}px sans-serif`;
35194
- const textMetrics = ctx.measureText(id);
35397
+ const metrics = ctx.measureText(id);
35398
+ const textWidth = metrics && metrics.width ? metrics.width : 0;
35195
35399
  const padding = 4;
35196
- const labelWidth = textMetrics.width + padding * 2;
35400
+ const labelWidth = textWidth + padding * 2;
35197
35401
  const labelHeight = fontSize + padding * 2;
35198
35402
  // The tag position is in the upper right corner.
35199
35403
  const labelX = area.x + area.width - labelWidth;
@@ -35211,66 +35415,15 @@ function mark_screenshot_highlight_elements(screenshot, area_map, client_rect) {
35211
35415
  ctx.textBaseline = "top";
35212
35416
  ctx.fillText(id, labelX + padding, labelY + padding);
35213
35417
  });
35214
- // Convert OffscreenCanvas to Blob, then to base64
35215
- const resultBlob = await canvas.convertToBlob({
35216
- type: screenshot.imageType,
35217
- });
35218
- const reader = new FileReader();
35219
- reader.onloadend = () => {
35220
- const resultBase64 = reader.result;
35221
- resolve(resultBase64);
35222
- };
35223
- reader.onerror = () => {
35224
- reject(new Error("Failed to convert blob to base64"));
35225
- };
35226
- reader.readAsDataURL(resultBlob);
35418
+ // Export the image
35419
+ const out = await exportDataUrl(screenshot.imageType);
35420
+ resolve(out);
35227
35421
  }
35228
35422
  catch (error) {
35229
35423
  reject(error);
35230
35424
  }
35231
35425
  });
35232
35426
  }
35233
- async function compress_image(imageBase64, imageType, compress, quality = 1) {
35234
- const base64Data = imageBase64;
35235
- const binaryString = atob(base64Data);
35236
- const bytes = new Uint8Array(binaryString.length);
35237
- for (let i = 0; i < binaryString.length; i++) {
35238
- bytes[i] = binaryString.charCodeAt(i);
35239
- }
35240
- const blob = new Blob([bytes], { type: imageType });
35241
- const bitmap = await createImageBitmap(blob);
35242
- const width = compress.scale
35243
- ? bitmap.width * compress.scale
35244
- : compress.resizeWidth;
35245
- const height = compress.scale
35246
- ? bitmap.height * compress.scale
35247
- : compress.resizeHeight;
35248
- if (bitmap.width == width && bitmap.height == height && quality == 1) {
35249
- return {
35250
- imageBase64: imageBase64,
35251
- imageType: imageType,
35252
- };
35253
- }
35254
- const canvas = new OffscreenCanvas(width, height);
35255
- const ctx = canvas.getContext("2d");
35256
- ctx.drawImage(bitmap, 0, 0, width, height);
35257
- const resultBlob = await canvas.convertToBlob({
35258
- type: "image/jpeg",
35259
- quality: quality,
35260
- });
35261
- return new Promise((resolve) => {
35262
- const reader = new FileReader();
35263
- reader.onloadend = () => {
35264
- let imageDataUrl = reader.result;
35265
- let imageBase64 = imageDataUrl.substring(imageDataUrl.indexOf("base64,") + 7);
35266
- resolve({
35267
- imageBase64: imageBase64,
35268
- imageType: "image/jpeg",
35269
- });
35270
- };
35271
- reader.readAsDataURL(resultBlob);
35272
- });
35273
- }
35274
35427
 
35275
35428
  const AGENT_NAME = "Browser";
35276
35429
  class BaseBrowserAgent extends Agent {
@@ -35943,18 +36096,14 @@ function run_build_dom_tree() {
35943
36096
  }
35944
36097
  return false;
35945
36098
  }
35946
- // Helper function to check if element exists
35947
- function isElementExist(element) {
35948
- const style = getCachedComputedStyle(element);
35949
- return (style?.visibility !== 'hidden' &&
35950
- style?.display !== 'none');
35951
- }
35952
36099
  // Helper function to check if element is visible
35953
36100
  function isElementVisible(element) {
35954
36101
  if (element.offsetWidth === 0 && element.offsetHeight === 0) {
35955
36102
  return false;
35956
36103
  }
35957
- return isElementExist(element);
36104
+ const style = getCachedComputedStyle(element);
36105
+ return (style?.visibility !== 'hidden' &&
36106
+ style?.display !== 'none');
35958
36107
  }
35959
36108
  // Helper function to check if element is the top element at its position
35960
36109
  function isTopElement(element) {
@@ -36108,7 +36257,8 @@ function run_build_dom_tree() {
36108
36257
  }
36109
36258
  }
36110
36259
  else {
36111
- if (isElementExist(node)) {
36260
+ const style = getCachedComputedStyle(node);
36261
+ if (style && style.display !== 'none') {
36112
36262
  const children = Array.from(node.children).map((child) => buildDomTree(child, parentIframe)).filter(child => child !== null);
36113
36263
  nodeData.children.push(...children);
36114
36264
  }
@@ -36284,7 +36434,7 @@ class BaseBrowserLabelsAgent extends BaseBrowserAgent {
36284
36434
  if (!client_rect || !screenshot) {
36285
36435
  return screenshot;
36286
36436
  }
36287
- const compressedImage = await compress_image(screenshot.imageBase64, screenshot.imageType, {
36437
+ const compressedImage = await compressImageData(screenshot.imageBase64, screenshot.imageType, {
36288
36438
  resizeWidth: client_rect.width,
36289
36439
  resizeHeight: client_rect.height,
36290
36440
  });
@@ -37234,6 +37384,7 @@ exports.WatchTriggerTool = WatchTriggerTool;
37234
37384
  exports.buildAgentTree = buildAgentTree;
37235
37385
  exports.buildSimpleAgentWorkflow = buildSimpleAgentWorkflow;
37236
37386
  exports.call_timeout = call_timeout;
37387
+ exports.compressImageData = compressImageData;
37237
37388
  exports.config = config$1;
37238
37389
  exports.convertToolSchema = convertToolSchema;
37239
37390
  exports.default = Eko;