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
@@ -1808,9 +1808,15 @@ var PageTaskExecutor = class {
1808
1808
  }
1809
1809
  async waitFor(assertion, opt) {
1810
1810
  const description = `waitFor: ${assertion}`;
1811
- const taskExecutor = new import_misoai_core.Executor(taskTitleStr("WaitFor", description), {
1812
- onTaskStart: this.onTaskStartCallback
1813
- });
1811
+ const useMemory = true;
1812
+ let taskExecutor;
1813
+ if (useMemory) {
1814
+ taskExecutor = this.getPersistentExecutor();
1815
+ } else {
1816
+ taskExecutor = new import_misoai_core.Executor(taskTitleStr("WaitFor", description), {
1817
+ onTaskStart: this.onTaskStartCallback
1818
+ });
1819
+ }
1814
1820
  const { timeoutMs, checkIntervalMs } = opt;
1815
1821
  (0, import_utils6.assert)(assertion, "No assertion for waitFor");
1816
1822
  (0, import_utils6.assert)(timeoutMs, "No timeoutMs for waitFor");
@@ -1865,6 +1871,20 @@ var PageTaskExecutor = class {
1865
1871
  `waitFor timeout: ${errorThought}`
1866
1872
  );
1867
1873
  }
1874
+ /**
1875
+ * Hafızaya yeni bir öğe ekler
1876
+ */
1877
+ addToMemory(memoryItem) {
1878
+ if (!this.persistentExecutor || this.persistentExecutor.status === "error") {
1879
+ const previousMemory = this.workflowMemory.getWorkflowMemory(this.sessionContext.workflowId);
1880
+ this.persistentExecutor = new import_misoai_core.Executor("Persistent Task Executor", {
1881
+ onTaskStart: this.onTaskStartCallback,
1882
+ initialMemory: previousMemory
1883
+ });
1884
+ }
1885
+ this.persistentExecutor.memoryStore?.add(memoryItem);
1886
+ this.persistentExecutor.memoryAnalytics?.recordMemoryOperation("add", memoryItem);
1887
+ }
1868
1888
  };
1869
1889
 
1870
1890
  // src/common/plan-builder.ts
@@ -1959,7 +1979,7 @@ var import_js_yaml3 = __toESM(require("js-yaml"));
1959
1979
  var import_semver = __toESM(require("semver"));
1960
1980
 
1961
1981
  // package.json
1962
- var version = "1.5.7";
1982
+ var version = "1.6.0";
1963
1983
 
1964
1984
  // src/common/task-cache.ts
1965
1985
  var debug3 = (0, import_logger3.getDebug)("cache");
@@ -2170,7 +2190,10 @@ var PageAgent = class {
2170
2190
  }
2171
2191
  this.taskExecutor = new PageTaskExecutor(this.page, this.insight, {
2172
2192
  taskCache: this.taskCache,
2173
- onTaskStart: this.callbackOnTaskStartTip.bind(this)
2193
+ onTaskStart: this.callbackOnTaskStartTip.bind(this),
2194
+ memoryConfig: opts?.memoryConfig,
2195
+ sessionId: opts?.sessionId,
2196
+ workflowId: opts?.workflowId
2174
2197
  });
2175
2198
  this.dump = this.resetDump();
2176
2199
  this.reportFileName = reportFileName(
@@ -2621,6 +2644,7 @@ ${reasonMsg}`);
2621
2644
  }
2622
2645
  async aiCaptcha(options) {
2623
2646
  const { deepThink = false, autoDetectComplexity = true } = options || {};
2647
+ const memoryContext = this.getMemoryAsContext();
2624
2648
  let shouldUseDeepThink = deepThink;
2625
2649
  if (autoDetectComplexity && !deepThink) {
2626
2650
  const context = await this.getUIContext();
@@ -2701,6 +2725,26 @@ Return only "complex" or "simple" based on your analysis.
2701
2725
  }
2702
2726
  }
2703
2727
  await new Promise((resolve2) => setTimeout(resolve2, 3e3));
2728
+ const captchaMemoryItem = {
2729
+ id: `captcha_${Date.now()}`,
2730
+ timestamp: Date.now(),
2731
+ taskType: "Action",
2732
+ summary: `Solved ${captchaResult.captchaType} CAPTCHA: ${captchaResult.thought}`,
2733
+ context: {
2734
+ url: await this.page.url?.() || "",
2735
+ captchaType: captchaResult.captchaType,
2736
+ actions: captchaResult.actions,
2737
+ deepThink: actualDeepThink
2738
+ },
2739
+ metadata: {
2740
+ executionTime: Date.now() - Date.now(),
2741
+ // Will be updated
2742
+ success: true,
2743
+ confidence: 0.9
2744
+ },
2745
+ tags: ["captcha", "action", captchaResult.captchaType]
2746
+ };
2747
+ this.taskExecutor.addToMemory(captchaMemoryItem);
2704
2748
  const metadata = {
2705
2749
  status: "finished",
2706
2750
  usage,
@@ -2717,10 +2761,15 @@ Return only "complex" or "simple" based on your analysis.
2717
2761
  }
2718
2762
  async aiWaitFor(assertion, opt) {
2719
2763
  const startTime = Date.now();
2720
- const { executor } = await this.taskExecutor.waitFor(assertion, {
2764
+ const memoryContext = this.getMemoryAsContext();
2765
+ const assertionWithContext = memoryContext ? `${assertion}
2766
+
2767
+ Previous workflow steps:
2768
+ ${memoryContext}` : assertion;
2769
+ const { executor } = await this.taskExecutor.waitFor(assertionWithContext, {
2721
2770
  timeoutMs: opt?.timeoutMs || 15 * 1e3,
2722
2771
  checkIntervalMs: opt?.checkIntervalMs || 3 * 1e3,
2723
- assertion
2772
+ assertion: assertionWithContext
2724
2773
  });
2725
2774
  const metadata = {
2726
2775
  status: executor.isInErrorState() ? "failed" : "finished",
@@ -2876,6 +2925,109 @@ ${errors}`);
2876
2925
  clearMemory() {
2877
2926
  this.taskExecutor.clearMemory();
2878
2927
  }
2928
+ /**
2929
+ * Test sonunda kullanım için detaylı hafıza raporu döndürür (JSON formatında)
2930
+ */
2931
+ getMemoryReport() {
2932
+ const memory = this.getMemory();
2933
+ const stats = this.getMemoryStats();
2934
+ return {
2935
+ summary: {
2936
+ totalItems: memory.length,
2937
+ totalTasks: stats.analytics.totalTasks,
2938
+ memoryHits: stats.analytics.memoryHits,
2939
+ memoryMisses: stats.analytics.memoryMisses,
2940
+ memoryEffectiveness: Math.round(stats.analytics.memoryEffectiveness * 100),
2941
+ averageMemorySize: Math.round(stats.analytics.averageMemorySize * 100) / 100
2942
+ },
2943
+ config: stats.config,
2944
+ items: memory.map((item) => ({
2945
+ id: item.id,
2946
+ timestamp: item.timestamp,
2947
+ taskType: item.taskType,
2948
+ summary: item.summary,
2949
+ context: item.context,
2950
+ metadata: item.metadata,
2951
+ tags: item.tags,
2952
+ relativeTime: this.formatRelativeTime(item.timestamp)
2953
+ })),
2954
+ analytics: {
2955
+ taskTypeDistribution: this.getTaskTypeDistribution(memory),
2956
+ successRate: this.calculateSuccessRate(memory),
2957
+ averageExecutionTime: this.calculateAverageExecutionTime(memory),
2958
+ dataExtractionCount: this.countDataExtractions(memory),
2959
+ workflowSteps: this.extractWorkflowSteps(memory)
2960
+ }
2961
+ };
2962
+ }
2963
+ /**
2964
+ * Test sonunda kullanım için basit hafıza özeti döndürür (JSON formatında)
2965
+ */
2966
+ getMemorySummary() {
2967
+ const memory = this.getMemory();
2968
+ const stats = this.getMemoryStats();
2969
+ return {
2970
+ totalItems: memory.length,
2971
+ memoryEffectiveness: `${Math.round(stats.analytics.memoryEffectiveness * 100)}%`,
2972
+ taskTypes: this.getTaskTypeDistribution(memory),
2973
+ recentSteps: memory.slice(-5).map((item) => ({
2974
+ step: item.summary,
2975
+ type: item.taskType,
2976
+ success: item.metadata?.success || false,
2977
+ time: this.formatRelativeTime(item.timestamp)
2978
+ })),
2979
+ dataExtracted: this.getExtractedDataSummary(memory)
2980
+ };
2981
+ }
2982
+ formatRelativeTime(timestamp) {
2983
+ const now = Date.now();
2984
+ const diff = now - timestamp;
2985
+ const seconds = Math.floor(diff / 1e3);
2986
+ const minutes = Math.floor(seconds / 60);
2987
+ const hours = Math.floor(minutes / 60);
2988
+ if (hours > 0)
2989
+ return `${hours}h ${minutes % 60}m ago`;
2990
+ if (minutes > 0)
2991
+ return `${minutes}m ${seconds % 60}s ago`;
2992
+ return `${seconds}s ago`;
2993
+ }
2994
+ getTaskTypeDistribution(memory) {
2995
+ const distribution = {};
2996
+ memory.forEach((item) => {
2997
+ distribution[item.taskType] = (distribution[item.taskType] || 0) + 1;
2998
+ });
2999
+ return distribution;
3000
+ }
3001
+ calculateSuccessRate(memory) {
3002
+ if (memory.length === 0)
3003
+ return 0;
3004
+ const successCount = memory.filter((item) => item.metadata?.success !== false).length;
3005
+ return Math.round(successCount / memory.length * 100);
3006
+ }
3007
+ calculateAverageExecutionTime(memory) {
3008
+ const executionTimes = memory.map((item) => item.metadata?.executionTime).filter((time) => typeof time === "number");
3009
+ if (executionTimes.length === 0)
3010
+ return 0;
3011
+ const average = executionTimes.reduce((sum, time) => sum + time, 0) / executionTimes.length;
3012
+ return Math.round(average);
3013
+ }
3014
+ countDataExtractions(memory) {
3015
+ return memory.filter(
3016
+ (item) => item.context?.dataExtracted || item.taskType === "Insight" && item.summary.includes("Extracted")
3017
+ ).length;
3018
+ }
3019
+ extractWorkflowSteps(memory) {
3020
+ return memory.map((item) => item.summary);
3021
+ }
3022
+ getExtractedDataSummary(memory) {
3023
+ const extractedData = {};
3024
+ memory.forEach((item, index) => {
3025
+ if (item.context?.dataExtracted) {
3026
+ extractedData[`step_${index + 1}`] = item.context.dataExtracted;
3027
+ }
3028
+ });
3029
+ return extractedData;
3030
+ }
2879
3031
  };
2880
3032
 
2881
3033
  // src/playground/agent.ts