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
@@ -1856,9 +1856,15 @@ var PageTaskExecutor = class {
1856
1856
  }
1857
1857
  async waitFor(assertion, opt) {
1858
1858
  const description = `waitFor: ${assertion}`;
1859
- const taskExecutor = new import_misoai_core.Executor(taskTitleStr("WaitFor", description), {
1860
- onTaskStart: this.onTaskStartCallback
1861
- });
1859
+ const useMemory = true;
1860
+ let taskExecutor;
1861
+ if (useMemory) {
1862
+ taskExecutor = this.getPersistentExecutor();
1863
+ } else {
1864
+ taskExecutor = new import_misoai_core.Executor(taskTitleStr("WaitFor", description), {
1865
+ onTaskStart: this.onTaskStartCallback
1866
+ });
1867
+ }
1862
1868
  const { timeoutMs, checkIntervalMs } = opt;
1863
1869
  (0, import_utils6.assert)(assertion, "No assertion for waitFor");
1864
1870
  (0, import_utils6.assert)(timeoutMs, "No timeoutMs for waitFor");
@@ -1913,6 +1919,20 @@ var PageTaskExecutor = class {
1913
1919
  `waitFor timeout: ${errorThought}`
1914
1920
  );
1915
1921
  }
1922
+ /**
1923
+ * Hafızaya yeni bir öğe ekler
1924
+ */
1925
+ addToMemory(memoryItem) {
1926
+ if (!this.persistentExecutor || this.persistentExecutor.status === "error") {
1927
+ const previousMemory = this.workflowMemory.getWorkflowMemory(this.sessionContext.workflowId);
1928
+ this.persistentExecutor = new import_misoai_core.Executor("Persistent Task Executor", {
1929
+ onTaskStart: this.onTaskStartCallback,
1930
+ initialMemory: previousMemory
1931
+ });
1932
+ }
1933
+ this.persistentExecutor.memoryStore?.add(memoryItem);
1934
+ this.persistentExecutor.memoryAnalytics?.recordMemoryOperation("add", memoryItem);
1935
+ }
1916
1936
  };
1917
1937
 
1918
1938
  // src/common/plan-builder.ts
@@ -2007,7 +2027,7 @@ var import_js_yaml3 = __toESM(require("js-yaml"));
2007
2027
  var import_semver = __toESM(require("semver"));
2008
2028
 
2009
2029
  // package.json
2010
- var version = "1.5.7";
2030
+ var version = "1.6.0";
2011
2031
 
2012
2032
  // src/common/task-cache.ts
2013
2033
  var debug3 = (0, import_logger3.getDebug)("cache");
@@ -2218,7 +2238,10 @@ var PageAgent = class {
2218
2238
  }
2219
2239
  this.taskExecutor = new PageTaskExecutor(this.page, this.insight, {
2220
2240
  taskCache: this.taskCache,
2221
- onTaskStart: this.callbackOnTaskStartTip.bind(this)
2241
+ onTaskStart: this.callbackOnTaskStartTip.bind(this),
2242
+ memoryConfig: opts?.memoryConfig,
2243
+ sessionId: opts?.sessionId,
2244
+ workflowId: opts?.workflowId
2222
2245
  });
2223
2246
  this.dump = this.resetDump();
2224
2247
  this.reportFileName = reportFileName(
@@ -2669,6 +2692,7 @@ ${reasonMsg}`);
2669
2692
  }
2670
2693
  async aiCaptcha(options) {
2671
2694
  const { deepThink = false, autoDetectComplexity = true } = options || {};
2695
+ const memoryContext = this.getMemoryAsContext();
2672
2696
  let shouldUseDeepThink = deepThink;
2673
2697
  if (autoDetectComplexity && !deepThink) {
2674
2698
  const context = await this.getUIContext();
@@ -2749,6 +2773,26 @@ Return only "complex" or "simple" based on your analysis.
2749
2773
  }
2750
2774
  }
2751
2775
  await new Promise((resolve2) => setTimeout(resolve2, 3e3));
2776
+ const captchaMemoryItem = {
2777
+ id: `captcha_${Date.now()}`,
2778
+ timestamp: Date.now(),
2779
+ taskType: "Action",
2780
+ summary: `Solved ${captchaResult.captchaType} CAPTCHA: ${captchaResult.thought}`,
2781
+ context: {
2782
+ url: await this.page.url?.() || "",
2783
+ captchaType: captchaResult.captchaType,
2784
+ actions: captchaResult.actions,
2785
+ deepThink: actualDeepThink
2786
+ },
2787
+ metadata: {
2788
+ executionTime: Date.now() - Date.now(),
2789
+ // Will be updated
2790
+ success: true,
2791
+ confidence: 0.9
2792
+ },
2793
+ tags: ["captcha", "action", captchaResult.captchaType]
2794
+ };
2795
+ this.taskExecutor.addToMemory(captchaMemoryItem);
2752
2796
  const metadata = {
2753
2797
  status: "finished",
2754
2798
  usage,
@@ -2765,10 +2809,15 @@ Return only "complex" or "simple" based on your analysis.
2765
2809
  }
2766
2810
  async aiWaitFor(assertion, opt) {
2767
2811
  const startTime = Date.now();
2768
- const { executor } = await this.taskExecutor.waitFor(assertion, {
2812
+ const memoryContext = this.getMemoryAsContext();
2813
+ const assertionWithContext = memoryContext ? `${assertion}
2814
+
2815
+ Previous workflow steps:
2816
+ ${memoryContext}` : assertion;
2817
+ const { executor } = await this.taskExecutor.waitFor(assertionWithContext, {
2769
2818
  timeoutMs: opt?.timeoutMs || 15 * 1e3,
2770
2819
  checkIntervalMs: opt?.checkIntervalMs || 3 * 1e3,
2771
- assertion
2820
+ assertion: assertionWithContext
2772
2821
  });
2773
2822
  const metadata = {
2774
2823
  status: executor.isInErrorState() ? "failed" : "finished",
@@ -2924,6 +2973,109 @@ ${errors}`);
2924
2973
  clearMemory() {
2925
2974
  this.taskExecutor.clearMemory();
2926
2975
  }
2976
+ /**
2977
+ * Test sonunda kullanım için detaylı hafıza raporu döndürür (JSON formatında)
2978
+ */
2979
+ getMemoryReport() {
2980
+ const memory = this.getMemory();
2981
+ const stats = this.getMemoryStats();
2982
+ return {
2983
+ summary: {
2984
+ totalItems: memory.length,
2985
+ totalTasks: stats.analytics.totalTasks,
2986
+ memoryHits: stats.analytics.memoryHits,
2987
+ memoryMisses: stats.analytics.memoryMisses,
2988
+ memoryEffectiveness: Math.round(stats.analytics.memoryEffectiveness * 100),
2989
+ averageMemorySize: Math.round(stats.analytics.averageMemorySize * 100) / 100
2990
+ },
2991
+ config: stats.config,
2992
+ items: memory.map((item) => ({
2993
+ id: item.id,
2994
+ timestamp: item.timestamp,
2995
+ taskType: item.taskType,
2996
+ summary: item.summary,
2997
+ context: item.context,
2998
+ metadata: item.metadata,
2999
+ tags: item.tags,
3000
+ relativeTime: this.formatRelativeTime(item.timestamp)
3001
+ })),
3002
+ analytics: {
3003
+ taskTypeDistribution: this.getTaskTypeDistribution(memory),
3004
+ successRate: this.calculateSuccessRate(memory),
3005
+ averageExecutionTime: this.calculateAverageExecutionTime(memory),
3006
+ dataExtractionCount: this.countDataExtractions(memory),
3007
+ workflowSteps: this.extractWorkflowSteps(memory)
3008
+ }
3009
+ };
3010
+ }
3011
+ /**
3012
+ * Test sonunda kullanım için basit hafıza özeti döndürür (JSON formatında)
3013
+ */
3014
+ getMemorySummary() {
3015
+ const memory = this.getMemory();
3016
+ const stats = this.getMemoryStats();
3017
+ return {
3018
+ totalItems: memory.length,
3019
+ memoryEffectiveness: `${Math.round(stats.analytics.memoryEffectiveness * 100)}%`,
3020
+ taskTypes: this.getTaskTypeDistribution(memory),
3021
+ recentSteps: memory.slice(-5).map((item) => ({
3022
+ step: item.summary,
3023
+ type: item.taskType,
3024
+ success: item.metadata?.success || false,
3025
+ time: this.formatRelativeTime(item.timestamp)
3026
+ })),
3027
+ dataExtracted: this.getExtractedDataSummary(memory)
3028
+ };
3029
+ }
3030
+ formatRelativeTime(timestamp) {
3031
+ const now = Date.now();
3032
+ const diff = now - timestamp;
3033
+ const seconds = Math.floor(diff / 1e3);
3034
+ const minutes = Math.floor(seconds / 60);
3035
+ const hours = Math.floor(minutes / 60);
3036
+ if (hours > 0)
3037
+ return `${hours}h ${minutes % 60}m ago`;
3038
+ if (minutes > 0)
3039
+ return `${minutes}m ${seconds % 60}s ago`;
3040
+ return `${seconds}s ago`;
3041
+ }
3042
+ getTaskTypeDistribution(memory) {
3043
+ const distribution = {};
3044
+ memory.forEach((item) => {
3045
+ distribution[item.taskType] = (distribution[item.taskType] || 0) + 1;
3046
+ });
3047
+ return distribution;
3048
+ }
3049
+ calculateSuccessRate(memory) {
3050
+ if (memory.length === 0)
3051
+ return 0;
3052
+ const successCount = memory.filter((item) => item.metadata?.success !== false).length;
3053
+ return Math.round(successCount / memory.length * 100);
3054
+ }
3055
+ calculateAverageExecutionTime(memory) {
3056
+ const executionTimes = memory.map((item) => item.metadata?.executionTime).filter((time) => typeof time === "number");
3057
+ if (executionTimes.length === 0)
3058
+ return 0;
3059
+ const average = executionTimes.reduce((sum, time) => sum + time, 0) / executionTimes.length;
3060
+ return Math.round(average);
3061
+ }
3062
+ countDataExtractions(memory) {
3063
+ return memory.filter(
3064
+ (item) => item.context?.dataExtracted || item.taskType === "Insight" && item.summary.includes("Extracted")
3065
+ ).length;
3066
+ }
3067
+ extractWorkflowSteps(memory) {
3068
+ return memory.map((item) => item.summary);
3069
+ }
3070
+ getExtractedDataSummary(memory) {
3071
+ const extractedData = {};
3072
+ memory.forEach((item, index) => {
3073
+ if (item.context?.dataExtracted) {
3074
+ extractedData[`step_${index + 1}`] = item.context.dataExtracted;
3075
+ }
3076
+ });
3077
+ return extractedData;
3078
+ }
2927
3079
  };
2928
3080
 
2929
3081
  // src/puppeteer/index.ts