misoai-web 1.5.8 → 1.6.0

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 (40) hide show
  1. package/dist/es/agent.js +159 -7
  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.js +161 -9
  5. package/dist/es/bridge-mode.js.map +1 -1
  6. package/dist/es/chrome-extension.js +160 -8
  7. package/dist/es/chrome-extension.js.map +1 -1
  8. package/dist/es/index.js +159 -7
  9. package/dist/es/index.js.map +1 -1
  10. package/dist/es/midscene-playground.js +159 -7
  11. package/dist/es/midscene-playground.js.map +1 -1
  12. package/dist/es/playground.js +159 -7
  13. package/dist/es/playground.js.map +1 -1
  14. package/dist/es/playwright.js +159 -7
  15. package/dist/es/playwright.js.map +1 -1
  16. package/dist/es/puppeteer-agent-launcher.js +159 -7
  17. package/dist/es/puppeteer-agent-launcher.js.map +1 -1
  18. package/dist/es/puppeteer.js +159 -7
  19. package/dist/es/puppeteer.js.map +1 -1
  20. package/dist/lib/agent.js +159 -7
  21. package/dist/lib/agent.js.map +1 -1
  22. package/dist/lib/bridge-mode-browser.js +3 -3
  23. package/dist/lib/bridge-mode.js +161 -9
  24. package/dist/lib/bridge-mode.js.map +1 -1
  25. package/dist/lib/chrome-extension.js +160 -8
  26. package/dist/lib/chrome-extension.js.map +1 -1
  27. package/dist/lib/index.js +159 -7
  28. package/dist/lib/index.js.map +1 -1
  29. package/dist/lib/midscene-playground.js +159 -7
  30. package/dist/lib/midscene-playground.js.map +1 -1
  31. package/dist/lib/playground.js +159 -7
  32. package/dist/lib/playground.js.map +1 -1
  33. package/dist/lib/playwright.js +159 -7
  34. package/dist/lib/playwright.js.map +1 -1
  35. package/dist/lib/puppeteer-agent-launcher.js +159 -7
  36. package/dist/lib/puppeteer-agent-launcher.js.map +1 -1
  37. package/dist/lib/puppeteer.js +159 -7
  38. package/dist/lib/puppeteer.js.map +1 -1
  39. package/dist/types/agent.d.ts +24 -2
  40. package/package.json +2 -2
package/dist/es/index.js CHANGED
@@ -1831,9 +1831,15 @@ var PageTaskExecutor = class {
1831
1831
  }
1832
1832
  async waitFor(assertion, opt) {
1833
1833
  const description = `waitFor: ${assertion}`;
1834
- const taskExecutor = new Executor(taskTitleStr("WaitFor", description), {
1835
- onTaskStart: this.onTaskStartCallback
1836
- });
1834
+ const useMemory = true;
1835
+ let taskExecutor;
1836
+ if (useMemory) {
1837
+ taskExecutor = this.getPersistentExecutor();
1838
+ } else {
1839
+ taskExecutor = new Executor(taskTitleStr("WaitFor", description), {
1840
+ onTaskStart: this.onTaskStartCallback
1841
+ });
1842
+ }
1837
1843
  const { timeoutMs, checkIntervalMs } = opt;
1838
1844
  assert4(assertion, "No assertion for waitFor");
1839
1845
  assert4(timeoutMs, "No timeoutMs for waitFor");
@@ -1888,6 +1894,20 @@ var PageTaskExecutor = class {
1888
1894
  `waitFor timeout: ${errorThought}`
1889
1895
  );
1890
1896
  }
1897
+ /**
1898
+ * Hafızaya yeni bir öğe ekler
1899
+ */
1900
+ addToMemory(memoryItem) {
1901
+ if (!this.persistentExecutor || this.persistentExecutor.status === "error") {
1902
+ const previousMemory = this.workflowMemory.getWorkflowMemory(this.sessionContext.workflowId);
1903
+ this.persistentExecutor = new Executor("Persistent Task Executor", {
1904
+ onTaskStart: this.onTaskStartCallback,
1905
+ initialMemory: previousMemory
1906
+ });
1907
+ }
1908
+ this.persistentExecutor.memoryStore?.add(memoryItem);
1909
+ this.persistentExecutor.memoryAnalytics?.recordMemoryOperation("add", memoryItem);
1910
+ }
1891
1911
  };
1892
1912
 
1893
1913
  // src/common/plan-builder.ts
@@ -1982,7 +2002,7 @@ import yaml3 from "js-yaml";
1982
2002
  import semver from "semver";
1983
2003
 
1984
2004
  // package.json
1985
- var version = "1.5.7";
2005
+ var version = "1.6.0";
1986
2006
 
1987
2007
  // src/common/task-cache.ts
1988
2008
  var debug3 = getDebug3("cache");
@@ -2193,7 +2213,10 @@ var PageAgent = class {
2193
2213
  }
2194
2214
  this.taskExecutor = new PageTaskExecutor(this.page, this.insight, {
2195
2215
  taskCache: this.taskCache,
2196
- onTaskStart: this.callbackOnTaskStartTip.bind(this)
2216
+ onTaskStart: this.callbackOnTaskStartTip.bind(this),
2217
+ memoryConfig: opts?.memoryConfig,
2218
+ sessionId: opts?.sessionId,
2219
+ workflowId: opts?.workflowId
2197
2220
  });
2198
2221
  this.dump = this.resetDump();
2199
2222
  this.reportFileName = reportFileName(
@@ -2644,6 +2667,7 @@ ${reasonMsg}`);
2644
2667
  }
2645
2668
  async aiCaptcha(options) {
2646
2669
  const { deepThink = false, autoDetectComplexity = true } = options || {};
2670
+ const memoryContext = this.getMemoryAsContext();
2647
2671
  let shouldUseDeepThink = deepThink;
2648
2672
  if (autoDetectComplexity && !deepThink) {
2649
2673
  const context = await this.getUIContext();
@@ -2724,6 +2748,26 @@ Return only "complex" or "simple" based on your analysis.
2724
2748
  }
2725
2749
  }
2726
2750
  await new Promise((resolve2) => setTimeout(resolve2, 3e3));
2751
+ const captchaMemoryItem = {
2752
+ id: `captcha_${Date.now()}`,
2753
+ timestamp: Date.now(),
2754
+ taskType: "Action",
2755
+ summary: `Solved ${captchaResult.captchaType} CAPTCHA: ${captchaResult.thought}`,
2756
+ context: {
2757
+ url: await this.page.url?.() || "",
2758
+ captchaType: captchaResult.captchaType,
2759
+ actions: captchaResult.actions,
2760
+ deepThink: actualDeepThink
2761
+ },
2762
+ metadata: {
2763
+ executionTime: Date.now() - Date.now(),
2764
+ // Will be updated
2765
+ success: true,
2766
+ confidence: 0.9
2767
+ },
2768
+ tags: ["captcha", "action", captchaResult.captchaType]
2769
+ };
2770
+ this.taskExecutor.addToMemory(captchaMemoryItem);
2727
2771
  const metadata = {
2728
2772
  status: "finished",
2729
2773
  usage,
@@ -2740,10 +2784,15 @@ Return only "complex" or "simple" based on your analysis.
2740
2784
  }
2741
2785
  async aiWaitFor(assertion, opt) {
2742
2786
  const startTime = Date.now();
2743
- const { executor } = await this.taskExecutor.waitFor(assertion, {
2787
+ const memoryContext = this.getMemoryAsContext();
2788
+ const assertionWithContext = memoryContext ? `${assertion}
2789
+
2790
+ Previous workflow steps:
2791
+ ${memoryContext}` : assertion;
2792
+ const { executor } = await this.taskExecutor.waitFor(assertionWithContext, {
2744
2793
  timeoutMs: opt?.timeoutMs || 15 * 1e3,
2745
2794
  checkIntervalMs: opt?.checkIntervalMs || 3 * 1e3,
2746
- assertion
2795
+ assertion: assertionWithContext
2747
2796
  });
2748
2797
  const metadata = {
2749
2798
  status: executor.isInErrorState() ? "failed" : "finished",
@@ -2899,6 +2948,109 @@ ${errors}`);
2899
2948
  clearMemory() {
2900
2949
  this.taskExecutor.clearMemory();
2901
2950
  }
2951
+ /**
2952
+ * Test sonunda kullanım için detaylı hafıza raporu döndürür (JSON formatında)
2953
+ */
2954
+ getMemoryReport() {
2955
+ const memory = this.getMemory();
2956
+ const stats = this.getMemoryStats();
2957
+ return {
2958
+ summary: {
2959
+ totalItems: memory.length,
2960
+ totalTasks: stats.analytics.totalTasks,
2961
+ memoryHits: stats.analytics.memoryHits,
2962
+ memoryMisses: stats.analytics.memoryMisses,
2963
+ memoryEffectiveness: Math.round(stats.analytics.memoryEffectiveness * 100),
2964
+ averageMemorySize: Math.round(stats.analytics.averageMemorySize * 100) / 100
2965
+ },
2966
+ config: stats.config,
2967
+ items: memory.map((item) => ({
2968
+ id: item.id,
2969
+ timestamp: item.timestamp,
2970
+ taskType: item.taskType,
2971
+ summary: item.summary,
2972
+ context: item.context,
2973
+ metadata: item.metadata,
2974
+ tags: item.tags,
2975
+ relativeTime: this.formatRelativeTime(item.timestamp)
2976
+ })),
2977
+ analytics: {
2978
+ taskTypeDistribution: this.getTaskTypeDistribution(memory),
2979
+ successRate: this.calculateSuccessRate(memory),
2980
+ averageExecutionTime: this.calculateAverageExecutionTime(memory),
2981
+ dataExtractionCount: this.countDataExtractions(memory),
2982
+ workflowSteps: this.extractWorkflowSteps(memory)
2983
+ }
2984
+ };
2985
+ }
2986
+ /**
2987
+ * Test sonunda kullanım için basit hafıza özeti döndürür (JSON formatında)
2988
+ */
2989
+ getMemorySummary() {
2990
+ const memory = this.getMemory();
2991
+ const stats = this.getMemoryStats();
2992
+ return {
2993
+ totalItems: memory.length,
2994
+ memoryEffectiveness: `${Math.round(stats.analytics.memoryEffectiveness * 100)}%`,
2995
+ taskTypes: this.getTaskTypeDistribution(memory),
2996
+ recentSteps: memory.slice(-5).map((item) => ({
2997
+ step: item.summary,
2998
+ type: item.taskType,
2999
+ success: item.metadata?.success || false,
3000
+ time: this.formatRelativeTime(item.timestamp)
3001
+ })),
3002
+ dataExtracted: this.getExtractedDataSummary(memory)
3003
+ };
3004
+ }
3005
+ formatRelativeTime(timestamp) {
3006
+ const now = Date.now();
3007
+ const diff = now - timestamp;
3008
+ const seconds = Math.floor(diff / 1e3);
3009
+ const minutes = Math.floor(seconds / 60);
3010
+ const hours = Math.floor(minutes / 60);
3011
+ if (hours > 0)
3012
+ return `${hours}h ${minutes % 60}m ago`;
3013
+ if (minutes > 0)
3014
+ return `${minutes}m ${seconds % 60}s ago`;
3015
+ return `${seconds}s ago`;
3016
+ }
3017
+ getTaskTypeDistribution(memory) {
3018
+ const distribution = {};
3019
+ memory.forEach((item) => {
3020
+ distribution[item.taskType] = (distribution[item.taskType] || 0) + 1;
3021
+ });
3022
+ return distribution;
3023
+ }
3024
+ calculateSuccessRate(memory) {
3025
+ if (memory.length === 0)
3026
+ return 0;
3027
+ const successCount = memory.filter((item) => item.metadata?.success !== false).length;
3028
+ return Math.round(successCount / memory.length * 100);
3029
+ }
3030
+ calculateAverageExecutionTime(memory) {
3031
+ const executionTimes = memory.map((item) => item.metadata?.executionTime).filter((time) => typeof time === "number");
3032
+ if (executionTimes.length === 0)
3033
+ return 0;
3034
+ const average = executionTimes.reduce((sum, time) => sum + time, 0) / executionTimes.length;
3035
+ return Math.round(average);
3036
+ }
3037
+ countDataExtractions(memory) {
3038
+ return memory.filter(
3039
+ (item) => item.context?.dataExtracted || item.taskType === "Insight" && item.summary.includes("Extracted")
3040
+ ).length;
3041
+ }
3042
+ extractWorkflowSteps(memory) {
3043
+ return memory.map((item) => item.summary);
3044
+ }
3045
+ getExtractedDataSummary(memory) {
3046
+ const extractedData = {};
3047
+ memory.forEach((item, index) => {
3048
+ if (item.context?.dataExtracted) {
3049
+ extractedData[`step_${index + 1}`] = item.context.dataExtracted;
3050
+ }
3051
+ });
3052
+ return extractedData;
3053
+ }
2902
3054
  };
2903
3055
 
2904
3056
  // src/puppeteer/base-page.ts