misoai-web 1.6.0 → 1.6.1

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.
Files changed (59) hide show
  1. package/dist/es/agent.js +105 -50
  2. package/dist/es/agent.js.map +1 -1
  3. package/dist/es/bridge-mode-browser.js +3 -3
  4. package/dist/es/bridge-mode-browser.js.map +1 -1
  5. package/dist/es/bridge-mode.js +107 -52
  6. package/dist/es/bridge-mode.js.map +1 -1
  7. package/dist/es/chrome-extension.js +106 -51
  8. package/dist/es/chrome-extension.js.map +1 -1
  9. package/dist/es/index.js +106 -51
  10. package/dist/es/index.js.map +1 -1
  11. package/dist/es/midscene-playground.js +108 -53
  12. package/dist/es/midscene-playground.js.map +1 -1
  13. package/dist/es/midscene-server.js +4 -4
  14. package/dist/es/midscene-server.js.map +1 -1
  15. package/dist/es/playground.js +105 -50
  16. package/dist/es/playground.js.map +1 -1
  17. package/dist/es/playwright-report.js +1 -1
  18. package/dist/es/playwright-report.js.map +1 -1
  19. package/dist/es/playwright.js +106 -51
  20. package/dist/es/playwright.js.map +1 -1
  21. package/dist/es/puppeteer-agent-launcher.js +105 -50
  22. package/dist/es/puppeteer-agent-launcher.js.map +1 -1
  23. package/dist/es/puppeteer.js +105 -50
  24. package/dist/es/puppeteer.js.map +1 -1
  25. package/dist/es/utils.js +1 -1
  26. package/dist/es/utils.js.map +1 -1
  27. package/dist/es/yaml.js +1 -1
  28. package/dist/es/yaml.js.map +1 -1
  29. package/dist/lib/agent.js +105 -50
  30. package/dist/lib/agent.js.map +1 -1
  31. package/dist/lib/bridge-mode-browser.js +3 -3
  32. package/dist/lib/bridge-mode-browser.js.map +1 -1
  33. package/dist/lib/bridge-mode.js +107 -52
  34. package/dist/lib/bridge-mode.js.map +1 -1
  35. package/dist/lib/chrome-extension.js +106 -51
  36. package/dist/lib/chrome-extension.js.map +1 -1
  37. package/dist/lib/index.js +106 -51
  38. package/dist/lib/index.js.map +1 -1
  39. package/dist/lib/midscene-playground.js +108 -53
  40. package/dist/lib/midscene-playground.js.map +1 -1
  41. package/dist/lib/midscene-server.js +4 -4
  42. package/dist/lib/midscene-server.js.map +1 -1
  43. package/dist/lib/playground.js +105 -50
  44. package/dist/lib/playground.js.map +1 -1
  45. package/dist/lib/playwright-report.js +1 -1
  46. package/dist/lib/playwright-report.js.map +1 -1
  47. package/dist/lib/playwright.js +106 -51
  48. package/dist/lib/playwright.js.map +1 -1
  49. package/dist/lib/puppeteer-agent-launcher.js +105 -50
  50. package/dist/lib/puppeteer-agent-launcher.js.map +1 -1
  51. package/dist/lib/puppeteer.js +105 -50
  52. package/dist/lib/puppeteer.js.map +1 -1
  53. package/dist/lib/utils.js +1 -1
  54. package/dist/lib/utils.js.map +1 -1
  55. package/dist/lib/yaml.js +1 -1
  56. package/dist/lib/yaml.js.map +1 -1
  57. package/dist/types/index.d.ts +1 -1
  58. package/dist/types/playwright.d.ts +1 -1
  59. package/package.json +18 -54
@@ -306,8 +306,8 @@ var ScriptPlayer = class {
306
306
  import yaml from "js-yaml";
307
307
 
308
308
  // src/yaml/utils.ts
309
- import { assert as assert2 } from "misoai-shared/utils";
310
309
  import yaml2 from "js-yaml";
310
+ import { assert as assert2 } from "misoai-shared/utils";
311
311
  function interpolateEnvVars(content) {
312
312
  return content.replace(/\$\{([^}]+)\}/g, (_, envVar) => {
313
313
  const value = process.env[envVar.trim()];
@@ -468,6 +468,7 @@ function paramStr(task) {
468
468
  }
469
469
 
470
470
  // src/common/utils.ts
471
+ import dayjs from "dayjs";
471
472
  import { elementByPositionWithElementInfo } from "misoai-core/ai-model";
472
473
  import { uploadTestInfoToServer } from "misoai-core/utils";
473
474
  import { MIDSCENE_REPORT_TAG_NAME, getAIConfig } from "misoai-shared/env";
@@ -479,7 +480,6 @@ import {
479
480
  } from "misoai-shared/extractor";
480
481
  import { resizeImgBase64 } from "misoai-shared/img";
481
482
  import { assert as assert3, logMsg, uuid } from "misoai-shared/utils";
482
- import dayjs from "dayjs";
483
483
 
484
484
  // src/web-element.ts
485
485
  var WebElementInfo = class {
@@ -648,8 +648,12 @@ var WorkflowMemory = class {
648
648
  const workflow = this.workflows.get(workflowId) || this.createEmptyWorkflowData(workflowId);
649
649
  workflow.memory = [...memory];
650
650
  workflow.metadata.totalSteps = workflow.steps.length;
651
- workflow.metadata.completedSteps = workflow.steps.filter((s) => s.status === "completed").length;
652
- workflow.metadata.failedSteps = workflow.steps.filter((s) => s.status === "failed").length;
651
+ workflow.metadata.completedSteps = workflow.steps.filter(
652
+ (s) => s.status === "completed"
653
+ ).length;
654
+ workflow.metadata.failedSteps = workflow.steps.filter(
655
+ (s) => s.status === "failed"
656
+ ).length;
653
657
  this.workflows.set(workflowId, workflow);
654
658
  this.enforceRetentionPolicy();
655
659
  }
@@ -660,7 +664,9 @@ var WorkflowMemory = class {
660
664
  const workflow = this.workflows.get(workflowId) || this.createEmptyWorkflowData(workflowId);
661
665
  workflow.context = { ...workflow.context, ...context };
662
666
  if (context.currentStep) {
663
- const existingStep = workflow.steps.find((s) => s.stepName === context.currentStep);
667
+ const existingStep = workflow.steps.find(
668
+ (s) => s.stepName === context.currentStep
669
+ );
664
670
  if (!existingStep) {
665
671
  workflow.steps.push({
666
672
  stepId: `step_${workflow.steps.length + 1}`,
@@ -705,7 +711,9 @@ var WorkflowMemory = class {
705
711
  enforceRetentionPolicy() {
706
712
  const maxWorkflows = 10;
707
713
  if (this.workflows.size > maxWorkflows) {
708
- const sortedWorkflows = Array.from(this.workflows.entries()).sort(([, a], [, b]) => (b.metadata.endTime || b.metadata.startTime) - (a.metadata.endTime || a.metadata.startTime));
714
+ const sortedWorkflows = Array.from(this.workflows.entries()).sort(
715
+ ([, a], [, b]) => (b.metadata.endTime || b.metadata.startTime) - (a.metadata.endTime || a.metadata.startTime)
716
+ );
709
717
  const toDelete = sortedWorkflows.slice(maxWorkflows);
710
718
  toDelete.forEach(([workflowId]) => this.workflows.delete(workflowId));
711
719
  }
@@ -1444,7 +1452,9 @@ var PageTaskExecutor = class {
1444
1452
  */
1445
1453
  getPersistentExecutor() {
1446
1454
  if (!this.persistentExecutor || this.persistentExecutor.status === "error") {
1447
- const previousMemory = this.workflowMemory.getWorkflowMemory(this.sessionContext.workflowId);
1455
+ const previousMemory = this.workflowMemory.getWorkflowMemory(
1456
+ this.sessionContext.workflowId
1457
+ );
1448
1458
  this.persistentExecutor = new Executor("Persistent Task Executor", {
1449
1459
  onTaskStart: this.onTaskStartCallback,
1450
1460
  initialMemory: previousMemory
@@ -1473,7 +1483,9 @@ var PageTaskExecutor = class {
1473
1483
  if (this.persistentExecutor) {
1474
1484
  this.persistentExecutor.clearMemory();
1475
1485
  }
1476
- this.workflowMemory.clearWorkflow(this.sessionContext.workflowId || "default");
1486
+ this.workflowMemory.clearWorkflow(
1487
+ this.sessionContext.workflowId || "default"
1488
+ );
1477
1489
  }
1478
1490
  /**
1479
1491
  * Mevcut hafızayı döndürür
@@ -1485,7 +1497,9 @@ var PageTaskExecutor = class {
1485
1497
  * İş akışı hafızasını döndürür
1486
1498
  */
1487
1499
  getWorkflowMemory() {
1488
- return this.workflowMemory.getWorkflowData(this.sessionContext.workflowId || "default");
1500
+ return this.workflowMemory.getWorkflowData(
1501
+ this.sessionContext.workflowId || "default"
1502
+ );
1489
1503
  }
1490
1504
  /**
1491
1505
  * Hafıza istatistiklerini döndürür
@@ -1493,7 +1507,13 @@ var PageTaskExecutor = class {
1493
1507
  getMemoryStats() {
1494
1508
  return this.persistentExecutor?.getMemoryStats() || {
1495
1509
  totalItems: 0,
1496
- analytics: { totalTasks: 0, memoryHits: 0, memoryMisses: 0, averageMemorySize: 0, memoryEffectiveness: 0 },
1510
+ analytics: {
1511
+ totalTasks: 0,
1512
+ memoryHits: 0,
1513
+ memoryMisses: 0,
1514
+ averageMemorySize: 0,
1515
+ memoryEffectiveness: 0
1516
+ },
1497
1517
  config: this.memoryConfig
1498
1518
  };
1499
1519
  }
@@ -1529,11 +1549,14 @@ var PageTaskExecutor = class {
1529
1549
  let taskExecutor;
1530
1550
  if (useMemory) {
1531
1551
  taskExecutor = this.getPersistentExecutor();
1532
- this.workflowMemory.updateWorkflowContext({
1533
- currentStep: title,
1534
- pageInfo: this.sessionContext.pageInfo,
1535
- timestamp: Date.now()
1536
- }, this.sessionContext.workflowId || "default");
1552
+ this.workflowMemory.updateWorkflowContext(
1553
+ {
1554
+ currentStep: title,
1555
+ pageInfo: this.sessionContext.pageInfo,
1556
+ timestamp: Date.now()
1557
+ },
1558
+ this.sessionContext.workflowId || "default"
1559
+ );
1537
1560
  } else {
1538
1561
  taskExecutor = new Executor(title, {
1539
1562
  onTaskStart: this.onTaskStartCallback
@@ -1899,14 +1922,19 @@ var PageTaskExecutor = class {
1899
1922
  */
1900
1923
  addToMemory(memoryItem) {
1901
1924
  if (!this.persistentExecutor || this.persistentExecutor.status === "error") {
1902
- const previousMemory = this.workflowMemory.getWorkflowMemory(this.sessionContext.workflowId);
1925
+ const previousMemory = this.workflowMemory.getWorkflowMemory(
1926
+ this.sessionContext.workflowId
1927
+ );
1903
1928
  this.persistentExecutor = new Executor("Persistent Task Executor", {
1904
1929
  onTaskStart: this.onTaskStartCallback,
1905
1930
  initialMemory: previousMemory
1906
1931
  });
1907
1932
  }
1908
1933
  this.persistentExecutor.memoryStore?.add(memoryItem);
1909
- this.persistentExecutor.memoryAnalytics?.recordMemoryOperation("add", memoryItem);
1934
+ this.persistentExecutor.memoryAnalytics?.recordMemoryOperation(
1935
+ "add",
1936
+ memoryItem
1937
+ );
1910
1938
  }
1911
1939
  };
1912
1940
 
@@ -1995,14 +2023,14 @@ function buildPlans(type, locateParam, param) {
1995
2023
  import assert6 from "assert";
1996
2024
  import { existsSync as existsSync2, mkdirSync as mkdirSync2, readFileSync, writeFileSync as writeFileSync2 } from "fs";
1997
2025
  import { dirname as dirname2, join as join2 } from "path";
2026
+ import yaml3 from "js-yaml";
1998
2027
  import { getMidsceneRunSubDir as getMidsceneRunSubDir2 } from "misoai-shared/common";
1999
2028
  import { getDebug as getDebug3 } from "misoai-shared/logger";
2000
2029
  import { ifInBrowser as ifInBrowser2 } from "misoai-shared/utils";
2001
- import yaml3 from "js-yaml";
2002
2030
  import semver from "semver";
2003
2031
 
2004
2032
  // package.json
2005
- var version = "1.6.0";
2033
+ var version = "1.6.1";
2006
2034
 
2007
2035
  // src/common/task-cache.ts
2008
2036
  var debug3 = getDebug3("cache");
@@ -2297,22 +2325,28 @@ var PageAgent = class {
2297
2325
  const allThoughts = executor.tasks.filter((task) => task.thought).map((task) => task.thought);
2298
2326
  const allLocates = executor.tasks.filter((task) => task.locate).map((task) => task.locate);
2299
2327
  const allPlans = executor.tasks.filter((task) => task.param?.plans).map((task) => task.param?.plans);
2300
- const planningTasks = executor.tasks.filter((task) => task.type === "Planning");
2301
- const insightTasks = executor.tasks.filter((task) => task.type === "Insight");
2328
+ const planningTasks = executor.tasks.filter(
2329
+ (task) => task.type === "Planning"
2330
+ );
2331
+ const insightTasks = executor.tasks.filter(
2332
+ (task) => task.type === "Insight"
2333
+ );
2302
2334
  const actionTasks = executor.tasks.filter((task) => task.type === "Action");
2303
2335
  const planning = planningTasks.length > 0 ? {
2304
2336
  type: "Planning",
2305
- description: `Planning for task execution`,
2337
+ description: "Planning for task execution",
2306
2338
  steps: planningTasks.map((task) => task.thought || "Planning step")
2307
2339
  } : void 0;
2308
2340
  const insight = insightTasks.length > 0 ? {
2309
2341
  type: "Insight",
2310
- description: `Insight for task execution`,
2311
- elements: insightTasks.map((task) => task.thought || "Insight element")
2342
+ description: "Insight for task execution",
2343
+ elements: insightTasks.map(
2344
+ (task) => task.thought || "Insight element"
2345
+ )
2312
2346
  } : void 0;
2313
2347
  const action = actionTasks.length > 0 ? {
2314
2348
  type: "Action",
2315
- description: `Action for task execution`,
2349
+ description: "Action for task execution",
2316
2350
  result: lastTask?.output
2317
2351
  } : void 0;
2318
2352
  const actionDetails = executor.tasks.map((task) => ({
@@ -2646,7 +2680,10 @@ ${memoryContext}` : void 0;
2646
2680
  }
2647
2681
  const memoryContext = this.getMemoryAsContext();
2648
2682
  const assertionWithContext = currentUrl ? `For the page at URL "${currentUrl}", ${assertion}` : assertion;
2649
- const { output, executor } = await this.taskExecutor.assert(assertionWithContext, memoryContext);
2683
+ const { output, executor } = await this.taskExecutor.assert(
2684
+ assertionWithContext,
2685
+ memoryContext
2686
+ );
2650
2687
  const metadata = this.afterTaskRunning(executor, true);
2651
2688
  if (output && opt?.keepRawResponse) {
2652
2689
  return {
@@ -2685,7 +2722,10 @@ A complex CAPTCHA typically has one or more of these characteristics:
2685
2722
  Return only "complex" or "simple" based on your analysis.
2686
2723
  `;
2687
2724
  const complexityMsgs = [
2688
- { role: "system", content: "You are an AI assistant that analyzes screenshots to determine CAPTCHA complexity." },
2725
+ {
2726
+ role: "system",
2727
+ content: "You are an AI assistant that analyzes screenshots to determine CAPTCHA complexity."
2728
+ },
2689
2729
  {
2690
2730
  role: "user",
2691
2731
  content: [
@@ -2709,7 +2749,12 @@ Return only "complex" or "simple" based on your analysis.
2709
2749
  );
2710
2750
  const responseText = typeof complexityResult.content === "string" ? complexityResult.content.toLowerCase() : JSON.stringify(complexityResult.content).toLowerCase();
2711
2751
  shouldUseDeepThink = responseText.includes("complex");
2712
- debug4("CAPTCHA complexity analysis:", responseText, "Using deep think:", shouldUseDeepThink);
2752
+ debug4(
2753
+ "CAPTCHA complexity analysis:",
2754
+ responseText,
2755
+ "Using deep think:",
2756
+ shouldUseDeepThink
2757
+ );
2713
2758
  } catch (error) {
2714
2759
  debug4("Failed to analyze CAPTCHA complexity:", error);
2715
2760
  }
@@ -2726,7 +2771,9 @@ Return only "complex" or "simple" based on your analysis.
2726
2771
  await this.aiTap(action.target, { deepThink: shouldUseDeepThink });
2727
2772
  } else if (action.type === "input" && action.value) {
2728
2773
  if (action.target) {
2729
- await this.aiInput(action.value, action.target, { deepThink: shouldUseDeepThink });
2774
+ await this.aiInput(action.value, action.target, {
2775
+ deepThink: shouldUseDeepThink
2776
+ });
2730
2777
  }
2731
2778
  } else if (action.type === "verify" && action.target) {
2732
2779
  await this.aiTap(action.target, { deepThink: shouldUseDeepThink });
@@ -2738,7 +2785,9 @@ Return only "complex" or "simple" based on your analysis.
2738
2785
  if (action.coordinates) {
2739
2786
  const x = action.coordinates[0];
2740
2787
  const y = action.coordinates[1];
2741
- await this.aiTap(`element at coordinates (${x}, ${y})`, { deepThink: shouldUseDeepThink });
2788
+ await this.aiTap(`element at coordinates (${x}, ${y})`, {
2789
+ deepThink: shouldUseDeepThink
2790
+ });
2742
2791
  } else if (action.target) {
2743
2792
  await this.aiTap(action.target, { deepThink: shouldUseDeepThink });
2744
2793
  }
@@ -2890,25 +2939,27 @@ ${errors}`);
2890
2939
  const executionDump = {
2891
2940
  name: screenshotTitle,
2892
2941
  description: content,
2893
- tasks: [{
2894
- type: "Screenshot",
2895
- subType: "log",
2896
- status: "finished",
2897
- executor: null,
2898
- param: {
2899
- title: screenshotTitle,
2900
- content
2901
- },
2902
- output: {
2903
- screenshot
2904
- },
2905
- thought: `Logged screenshot: ${screenshotTitle}`,
2906
- timing: {
2907
- start: Date.now(),
2908
- end: Date.now(),
2909
- cost: 0
2942
+ tasks: [
2943
+ {
2944
+ type: "Screenshot",
2945
+ subType: "log",
2946
+ status: "finished",
2947
+ executor: null,
2948
+ param: {
2949
+ title: screenshotTitle,
2950
+ content
2951
+ },
2952
+ output: {
2953
+ screenshot
2954
+ },
2955
+ thought: `Logged screenshot: ${screenshotTitle}`,
2956
+ timing: {
2957
+ start: Date.now(),
2958
+ end: Date.now(),
2959
+ cost: 0
2960
+ }
2910
2961
  }
2911
- }],
2962
+ ],
2912
2963
  sdkVersion: "1.0.0",
2913
2964
  logTime: Date.now(),
2914
2965
  model_name: "screenshot"
@@ -2960,7 +3011,9 @@ ${errors}`);
2960
3011
  totalTasks: stats.analytics.totalTasks,
2961
3012
  memoryHits: stats.analytics.memoryHits,
2962
3013
  memoryMisses: stats.analytics.memoryMisses,
2963
- memoryEffectiveness: Math.round(stats.analytics.memoryEffectiveness * 100),
3014
+ memoryEffectiveness: Math.round(
3015
+ stats.analytics.memoryEffectiveness * 100
3016
+ ),
2964
3017
  averageMemorySize: Math.round(stats.analytics.averageMemorySize * 100) / 100
2965
3018
  },
2966
3019
  config: stats.config,
@@ -3024,7 +3077,9 @@ ${errors}`);
3024
3077
  calculateSuccessRate(memory) {
3025
3078
  if (memory.length === 0)
3026
3079
  return 0;
3027
- const successCount = memory.filter((item) => item.metadata?.success !== false).length;
3080
+ const successCount = memory.filter(
3081
+ (item) => item.metadata?.success !== false
3082
+ ).length;
3028
3083
  return Math.round(successCount / memory.length * 100);
3029
3084
  }
3030
3085
  calculateAverageExecutionTime(memory) {