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
@@ -1849,9 +1849,15 @@ var PageTaskExecutor = class {
1849
1849
  }
1850
1850
  async waitFor(assertion, opt) {
1851
1851
  const description = `waitFor: ${assertion}`;
1852
- const taskExecutor = new import_misoai_core.Executor(taskTitleStr("WaitFor", description), {
1853
- onTaskStart: this.onTaskStartCallback
1854
- });
1852
+ const useMemory = true;
1853
+ let taskExecutor;
1854
+ if (useMemory) {
1855
+ taskExecutor = this.getPersistentExecutor();
1856
+ } else {
1857
+ taskExecutor = new import_misoai_core.Executor(taskTitleStr("WaitFor", description), {
1858
+ onTaskStart: this.onTaskStartCallback
1859
+ });
1860
+ }
1855
1861
  const { timeoutMs, checkIntervalMs } = opt;
1856
1862
  (0, import_utils6.assert)(assertion, "No assertion for waitFor");
1857
1863
  (0, import_utils6.assert)(timeoutMs, "No timeoutMs for waitFor");
@@ -1906,6 +1912,20 @@ var PageTaskExecutor = class {
1906
1912
  `waitFor timeout: ${errorThought}`
1907
1913
  );
1908
1914
  }
1915
+ /**
1916
+ * Hafızaya yeni bir öğe ekler
1917
+ */
1918
+ addToMemory(memoryItem) {
1919
+ if (!this.persistentExecutor || this.persistentExecutor.status === "error") {
1920
+ const previousMemory = this.workflowMemory.getWorkflowMemory(this.sessionContext.workflowId);
1921
+ this.persistentExecutor = new import_misoai_core.Executor("Persistent Task Executor", {
1922
+ onTaskStart: this.onTaskStartCallback,
1923
+ initialMemory: previousMemory
1924
+ });
1925
+ }
1926
+ this.persistentExecutor.memoryStore?.add(memoryItem);
1927
+ this.persistentExecutor.memoryAnalytics?.recordMemoryOperation("add", memoryItem);
1928
+ }
1909
1929
  };
1910
1930
 
1911
1931
  // src/common/plan-builder.ts
@@ -2000,7 +2020,7 @@ var import_js_yaml3 = __toESM(require("js-yaml"));
2000
2020
  var import_semver = __toESM(require("semver"));
2001
2021
 
2002
2022
  // package.json
2003
- var version = "1.5.7";
2023
+ var version = "1.6.0";
2004
2024
 
2005
2025
  // src/common/task-cache.ts
2006
2026
  var debug3 = (0, import_logger3.getDebug)("cache");
@@ -2211,7 +2231,10 @@ var PageAgent = class {
2211
2231
  }
2212
2232
  this.taskExecutor = new PageTaskExecutor(this.page, this.insight, {
2213
2233
  taskCache: this.taskCache,
2214
- onTaskStart: this.callbackOnTaskStartTip.bind(this)
2234
+ onTaskStart: this.callbackOnTaskStartTip.bind(this),
2235
+ memoryConfig: opts?.memoryConfig,
2236
+ sessionId: opts?.sessionId,
2237
+ workflowId: opts?.workflowId
2215
2238
  });
2216
2239
  this.dump = this.resetDump();
2217
2240
  this.reportFileName = reportFileName(
@@ -2662,6 +2685,7 @@ ${reasonMsg}`);
2662
2685
  }
2663
2686
  async aiCaptcha(options) {
2664
2687
  const { deepThink = false, autoDetectComplexity = true } = options || {};
2688
+ const memoryContext = this.getMemoryAsContext();
2665
2689
  let shouldUseDeepThink = deepThink;
2666
2690
  if (autoDetectComplexity && !deepThink) {
2667
2691
  const context = await this.getUIContext();
@@ -2742,6 +2766,26 @@ Return only "complex" or "simple" based on your analysis.
2742
2766
  }
2743
2767
  }
2744
2768
  await new Promise((resolve2) => setTimeout(resolve2, 3e3));
2769
+ const captchaMemoryItem = {
2770
+ id: `captcha_${Date.now()}`,
2771
+ timestamp: Date.now(),
2772
+ taskType: "Action",
2773
+ summary: `Solved ${captchaResult.captchaType} CAPTCHA: ${captchaResult.thought}`,
2774
+ context: {
2775
+ url: await this.page.url?.() || "",
2776
+ captchaType: captchaResult.captchaType,
2777
+ actions: captchaResult.actions,
2778
+ deepThink: actualDeepThink
2779
+ },
2780
+ metadata: {
2781
+ executionTime: Date.now() - Date.now(),
2782
+ // Will be updated
2783
+ success: true,
2784
+ confidence: 0.9
2785
+ },
2786
+ tags: ["captcha", "action", captchaResult.captchaType]
2787
+ };
2788
+ this.taskExecutor.addToMemory(captchaMemoryItem);
2745
2789
  const metadata = {
2746
2790
  status: "finished",
2747
2791
  usage,
@@ -2758,10 +2802,15 @@ Return only "complex" or "simple" based on your analysis.
2758
2802
  }
2759
2803
  async aiWaitFor(assertion, opt) {
2760
2804
  const startTime = Date.now();
2761
- const { executor } = await this.taskExecutor.waitFor(assertion, {
2805
+ const memoryContext = this.getMemoryAsContext();
2806
+ const assertionWithContext = memoryContext ? `${assertion}
2807
+
2808
+ Previous workflow steps:
2809
+ ${memoryContext}` : assertion;
2810
+ const { executor } = await this.taskExecutor.waitFor(assertionWithContext, {
2762
2811
  timeoutMs: opt?.timeoutMs || 15 * 1e3,
2763
2812
  checkIntervalMs: opt?.checkIntervalMs || 3 * 1e3,
2764
- assertion
2813
+ assertion: assertionWithContext
2765
2814
  });
2766
2815
  const metadata = {
2767
2816
  status: executor.isInErrorState() ? "failed" : "finished",
@@ -2917,6 +2966,109 @@ ${errors}`);
2917
2966
  clearMemory() {
2918
2967
  this.taskExecutor.clearMemory();
2919
2968
  }
2969
+ /**
2970
+ * Test sonunda kullanım için detaylı hafıza raporu döndürür (JSON formatında)
2971
+ */
2972
+ getMemoryReport() {
2973
+ const memory = this.getMemory();
2974
+ const stats = this.getMemoryStats();
2975
+ return {
2976
+ summary: {
2977
+ totalItems: memory.length,
2978
+ totalTasks: stats.analytics.totalTasks,
2979
+ memoryHits: stats.analytics.memoryHits,
2980
+ memoryMisses: stats.analytics.memoryMisses,
2981
+ memoryEffectiveness: Math.round(stats.analytics.memoryEffectiveness * 100),
2982
+ averageMemorySize: Math.round(stats.analytics.averageMemorySize * 100) / 100
2983
+ },
2984
+ config: stats.config,
2985
+ items: memory.map((item) => ({
2986
+ id: item.id,
2987
+ timestamp: item.timestamp,
2988
+ taskType: item.taskType,
2989
+ summary: item.summary,
2990
+ context: item.context,
2991
+ metadata: item.metadata,
2992
+ tags: item.tags,
2993
+ relativeTime: this.formatRelativeTime(item.timestamp)
2994
+ })),
2995
+ analytics: {
2996
+ taskTypeDistribution: this.getTaskTypeDistribution(memory),
2997
+ successRate: this.calculateSuccessRate(memory),
2998
+ averageExecutionTime: this.calculateAverageExecutionTime(memory),
2999
+ dataExtractionCount: this.countDataExtractions(memory),
3000
+ workflowSteps: this.extractWorkflowSteps(memory)
3001
+ }
3002
+ };
3003
+ }
3004
+ /**
3005
+ * Test sonunda kullanım için basit hafıza özeti döndürür (JSON formatında)
3006
+ */
3007
+ getMemorySummary() {
3008
+ const memory = this.getMemory();
3009
+ const stats = this.getMemoryStats();
3010
+ return {
3011
+ totalItems: memory.length,
3012
+ memoryEffectiveness: `${Math.round(stats.analytics.memoryEffectiveness * 100)}%`,
3013
+ taskTypes: this.getTaskTypeDistribution(memory),
3014
+ recentSteps: memory.slice(-5).map((item) => ({
3015
+ step: item.summary,
3016
+ type: item.taskType,
3017
+ success: item.metadata?.success || false,
3018
+ time: this.formatRelativeTime(item.timestamp)
3019
+ })),
3020
+ dataExtracted: this.getExtractedDataSummary(memory)
3021
+ };
3022
+ }
3023
+ formatRelativeTime(timestamp) {
3024
+ const now = Date.now();
3025
+ const diff = now - timestamp;
3026
+ const seconds = Math.floor(diff / 1e3);
3027
+ const minutes = Math.floor(seconds / 60);
3028
+ const hours = Math.floor(minutes / 60);
3029
+ if (hours > 0)
3030
+ return `${hours}h ${minutes % 60}m ago`;
3031
+ if (minutes > 0)
3032
+ return `${minutes}m ${seconds % 60}s ago`;
3033
+ return `${seconds}s ago`;
3034
+ }
3035
+ getTaskTypeDistribution(memory) {
3036
+ const distribution = {};
3037
+ memory.forEach((item) => {
3038
+ distribution[item.taskType] = (distribution[item.taskType] || 0) + 1;
3039
+ });
3040
+ return distribution;
3041
+ }
3042
+ calculateSuccessRate(memory) {
3043
+ if (memory.length === 0)
3044
+ return 0;
3045
+ const successCount = memory.filter((item) => item.metadata?.success !== false).length;
3046
+ return Math.round(successCount / memory.length * 100);
3047
+ }
3048
+ calculateAverageExecutionTime(memory) {
3049
+ const executionTimes = memory.map((item) => item.metadata?.executionTime).filter((time) => typeof time === "number");
3050
+ if (executionTimes.length === 0)
3051
+ return 0;
3052
+ const average = executionTimes.reduce((sum, time) => sum + time, 0) / executionTimes.length;
3053
+ return Math.round(average);
3054
+ }
3055
+ countDataExtractions(memory) {
3056
+ return memory.filter(
3057
+ (item) => item.context?.dataExtracted || item.taskType === "Insight" && item.summary.includes("Extracted")
3058
+ ).length;
3059
+ }
3060
+ extractWorkflowSteps(memory) {
3061
+ return memory.map((item) => item.summary);
3062
+ }
3063
+ getExtractedDataSummary(memory) {
3064
+ const extractedData = {};
3065
+ memory.forEach((item, index) => {
3066
+ if (item.context?.dataExtracted) {
3067
+ extractedData[`step_${index + 1}`] = item.context.dataExtracted;
3068
+ }
3069
+ });
3070
+ return extractedData;
3071
+ }
2920
3072
  };
2921
3073
 
2922
3074
  // src/puppeteer/index.ts