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/lib/agent.js CHANGED
@@ -1817,9 +1817,15 @@ var PageTaskExecutor = class {
1817
1817
  }
1818
1818
  async waitFor(assertion, opt) {
1819
1819
  const description = `waitFor: ${assertion}`;
1820
- const taskExecutor = new import_misoai_core.Executor(taskTitleStr("WaitFor", description), {
1821
- onTaskStart: this.onTaskStartCallback
1822
- });
1820
+ const useMemory = true;
1821
+ let taskExecutor;
1822
+ if (useMemory) {
1823
+ taskExecutor = this.getPersistentExecutor();
1824
+ } else {
1825
+ taskExecutor = new import_misoai_core.Executor(taskTitleStr("WaitFor", description), {
1826
+ onTaskStart: this.onTaskStartCallback
1827
+ });
1828
+ }
1823
1829
  const { timeoutMs, checkIntervalMs } = opt;
1824
1830
  (0, import_utils6.assert)(assertion, "No assertion for waitFor");
1825
1831
  (0, import_utils6.assert)(timeoutMs, "No timeoutMs for waitFor");
@@ -1874,6 +1880,20 @@ var PageTaskExecutor = class {
1874
1880
  `waitFor timeout: ${errorThought}`
1875
1881
  );
1876
1882
  }
1883
+ /**
1884
+ * Hafızaya yeni bir öğe ekler
1885
+ */
1886
+ addToMemory(memoryItem) {
1887
+ if (!this.persistentExecutor || this.persistentExecutor.status === "error") {
1888
+ const previousMemory = this.workflowMemory.getWorkflowMemory(this.sessionContext.workflowId);
1889
+ this.persistentExecutor = new import_misoai_core.Executor("Persistent Task Executor", {
1890
+ onTaskStart: this.onTaskStartCallback,
1891
+ initialMemory: previousMemory
1892
+ });
1893
+ }
1894
+ this.persistentExecutor.memoryStore?.add(memoryItem);
1895
+ this.persistentExecutor.memoryAnalytics?.recordMemoryOperation("add", memoryItem);
1896
+ }
1877
1897
  };
1878
1898
 
1879
1899
  // src/common/plan-builder.ts
@@ -1968,7 +1988,7 @@ var import_js_yaml3 = __toESM(require("js-yaml"));
1968
1988
  var import_semver = __toESM(require("semver"));
1969
1989
 
1970
1990
  // package.json
1971
- var version = "1.5.7";
1991
+ var version = "1.6.0";
1972
1992
 
1973
1993
  // src/common/task-cache.ts
1974
1994
  var debug3 = (0, import_logger3.getDebug)("cache");
@@ -2179,7 +2199,10 @@ var PageAgent = class {
2179
2199
  }
2180
2200
  this.taskExecutor = new PageTaskExecutor(this.page, this.insight, {
2181
2201
  taskCache: this.taskCache,
2182
- onTaskStart: this.callbackOnTaskStartTip.bind(this)
2202
+ onTaskStart: this.callbackOnTaskStartTip.bind(this),
2203
+ memoryConfig: opts?.memoryConfig,
2204
+ sessionId: opts?.sessionId,
2205
+ workflowId: opts?.workflowId
2183
2206
  });
2184
2207
  this.dump = this.resetDump();
2185
2208
  this.reportFileName = reportFileName(
@@ -2630,6 +2653,7 @@ ${reasonMsg}`);
2630
2653
  }
2631
2654
  async aiCaptcha(options) {
2632
2655
  const { deepThink = false, autoDetectComplexity = true } = options || {};
2656
+ const memoryContext = this.getMemoryAsContext();
2633
2657
  let shouldUseDeepThink = deepThink;
2634
2658
  if (autoDetectComplexity && !deepThink) {
2635
2659
  const context = await this.getUIContext();
@@ -2710,6 +2734,26 @@ Return only "complex" or "simple" based on your analysis.
2710
2734
  }
2711
2735
  }
2712
2736
  await new Promise((resolve2) => setTimeout(resolve2, 3e3));
2737
+ const captchaMemoryItem = {
2738
+ id: `captcha_${Date.now()}`,
2739
+ timestamp: Date.now(),
2740
+ taskType: "Action",
2741
+ summary: `Solved ${captchaResult.captchaType} CAPTCHA: ${captchaResult.thought}`,
2742
+ context: {
2743
+ url: await this.page.url?.() || "",
2744
+ captchaType: captchaResult.captchaType,
2745
+ actions: captchaResult.actions,
2746
+ deepThink: actualDeepThink
2747
+ },
2748
+ metadata: {
2749
+ executionTime: Date.now() - Date.now(),
2750
+ // Will be updated
2751
+ success: true,
2752
+ confidence: 0.9
2753
+ },
2754
+ tags: ["captcha", "action", captchaResult.captchaType]
2755
+ };
2756
+ this.taskExecutor.addToMemory(captchaMemoryItem);
2713
2757
  const metadata = {
2714
2758
  status: "finished",
2715
2759
  usage,
@@ -2726,10 +2770,15 @@ Return only "complex" or "simple" based on your analysis.
2726
2770
  }
2727
2771
  async aiWaitFor(assertion, opt) {
2728
2772
  const startTime = Date.now();
2729
- const { executor } = await this.taskExecutor.waitFor(assertion, {
2773
+ const memoryContext = this.getMemoryAsContext();
2774
+ const assertionWithContext = memoryContext ? `${assertion}
2775
+
2776
+ Previous workflow steps:
2777
+ ${memoryContext}` : assertion;
2778
+ const { executor } = await this.taskExecutor.waitFor(assertionWithContext, {
2730
2779
  timeoutMs: opt?.timeoutMs || 15 * 1e3,
2731
2780
  checkIntervalMs: opt?.checkIntervalMs || 3 * 1e3,
2732
- assertion
2781
+ assertion: assertionWithContext
2733
2782
  });
2734
2783
  const metadata = {
2735
2784
  status: executor.isInErrorState() ? "failed" : "finished",
@@ -2885,6 +2934,109 @@ ${errors}`);
2885
2934
  clearMemory() {
2886
2935
  this.taskExecutor.clearMemory();
2887
2936
  }
2937
+ /**
2938
+ * Test sonunda kullanım için detaylı hafıza raporu döndürür (JSON formatında)
2939
+ */
2940
+ getMemoryReport() {
2941
+ const memory = this.getMemory();
2942
+ const stats = this.getMemoryStats();
2943
+ return {
2944
+ summary: {
2945
+ totalItems: memory.length,
2946
+ totalTasks: stats.analytics.totalTasks,
2947
+ memoryHits: stats.analytics.memoryHits,
2948
+ memoryMisses: stats.analytics.memoryMisses,
2949
+ memoryEffectiveness: Math.round(stats.analytics.memoryEffectiveness * 100),
2950
+ averageMemorySize: Math.round(stats.analytics.averageMemorySize * 100) / 100
2951
+ },
2952
+ config: stats.config,
2953
+ items: memory.map((item) => ({
2954
+ id: item.id,
2955
+ timestamp: item.timestamp,
2956
+ taskType: item.taskType,
2957
+ summary: item.summary,
2958
+ context: item.context,
2959
+ metadata: item.metadata,
2960
+ tags: item.tags,
2961
+ relativeTime: this.formatRelativeTime(item.timestamp)
2962
+ })),
2963
+ analytics: {
2964
+ taskTypeDistribution: this.getTaskTypeDistribution(memory),
2965
+ successRate: this.calculateSuccessRate(memory),
2966
+ averageExecutionTime: this.calculateAverageExecutionTime(memory),
2967
+ dataExtractionCount: this.countDataExtractions(memory),
2968
+ workflowSteps: this.extractWorkflowSteps(memory)
2969
+ }
2970
+ };
2971
+ }
2972
+ /**
2973
+ * Test sonunda kullanım için basit hafıza özeti döndürür (JSON formatında)
2974
+ */
2975
+ getMemorySummary() {
2976
+ const memory = this.getMemory();
2977
+ const stats = this.getMemoryStats();
2978
+ return {
2979
+ totalItems: memory.length,
2980
+ memoryEffectiveness: `${Math.round(stats.analytics.memoryEffectiveness * 100)}%`,
2981
+ taskTypes: this.getTaskTypeDistribution(memory),
2982
+ recentSteps: memory.slice(-5).map((item) => ({
2983
+ step: item.summary,
2984
+ type: item.taskType,
2985
+ success: item.metadata?.success || false,
2986
+ time: this.formatRelativeTime(item.timestamp)
2987
+ })),
2988
+ dataExtracted: this.getExtractedDataSummary(memory)
2989
+ };
2990
+ }
2991
+ formatRelativeTime(timestamp) {
2992
+ const now = Date.now();
2993
+ const diff = now - timestamp;
2994
+ const seconds = Math.floor(diff / 1e3);
2995
+ const minutes = Math.floor(seconds / 60);
2996
+ const hours = Math.floor(minutes / 60);
2997
+ if (hours > 0)
2998
+ return `${hours}h ${minutes % 60}m ago`;
2999
+ if (minutes > 0)
3000
+ return `${minutes}m ${seconds % 60}s ago`;
3001
+ return `${seconds}s ago`;
3002
+ }
3003
+ getTaskTypeDistribution(memory) {
3004
+ const distribution = {};
3005
+ memory.forEach((item) => {
3006
+ distribution[item.taskType] = (distribution[item.taskType] || 0) + 1;
3007
+ });
3008
+ return distribution;
3009
+ }
3010
+ calculateSuccessRate(memory) {
3011
+ if (memory.length === 0)
3012
+ return 0;
3013
+ const successCount = memory.filter((item) => item.metadata?.success !== false).length;
3014
+ return Math.round(successCount / memory.length * 100);
3015
+ }
3016
+ calculateAverageExecutionTime(memory) {
3017
+ const executionTimes = memory.map((item) => item.metadata?.executionTime).filter((time) => typeof time === "number");
3018
+ if (executionTimes.length === 0)
3019
+ return 0;
3020
+ const average = executionTimes.reduce((sum, time) => sum + time, 0) / executionTimes.length;
3021
+ return Math.round(average);
3022
+ }
3023
+ countDataExtractions(memory) {
3024
+ return memory.filter(
3025
+ (item) => item.context?.dataExtracted || item.taskType === "Insight" && item.summary.includes("Extracted")
3026
+ ).length;
3027
+ }
3028
+ extractWorkflowSteps(memory) {
3029
+ return memory.map((item) => item.summary);
3030
+ }
3031
+ getExtractedDataSummary(memory) {
3032
+ const extractedData = {};
3033
+ memory.forEach((item, index) => {
3034
+ if (item.context?.dataExtracted) {
3035
+ extractedData[`step_${index + 1}`] = item.context.dataExtracted;
3036
+ }
3037
+ });
3038
+ return extractedData;
3039
+ }
2888
3040
  };
2889
3041
  // Annotate the CommonJS export names for ESM import in node:
2890
3042
  0 && (module.exports = {