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/agent.js CHANGED
@@ -1803,9 +1803,15 @@ var PageTaskExecutor = class {
1803
1803
  }
1804
1804
  async waitFor(assertion, opt) {
1805
1805
  const description = `waitFor: ${assertion}`;
1806
- const taskExecutor = new Executor(taskTitleStr("WaitFor", description), {
1807
- onTaskStart: this.onTaskStartCallback
1808
- });
1806
+ const useMemory = true;
1807
+ let taskExecutor;
1808
+ if (useMemory) {
1809
+ taskExecutor = this.getPersistentExecutor();
1810
+ } else {
1811
+ taskExecutor = new Executor(taskTitleStr("WaitFor", description), {
1812
+ onTaskStart: this.onTaskStartCallback
1813
+ });
1814
+ }
1809
1815
  const { timeoutMs, checkIntervalMs } = opt;
1810
1816
  assert4(assertion, "No assertion for waitFor");
1811
1817
  assert4(timeoutMs, "No timeoutMs for waitFor");
@@ -1860,6 +1866,20 @@ var PageTaskExecutor = class {
1860
1866
  `waitFor timeout: ${errorThought}`
1861
1867
  );
1862
1868
  }
1869
+ /**
1870
+ * Hafızaya yeni bir öğe ekler
1871
+ */
1872
+ addToMemory(memoryItem) {
1873
+ if (!this.persistentExecutor || this.persistentExecutor.status === "error") {
1874
+ const previousMemory = this.workflowMemory.getWorkflowMemory(this.sessionContext.workflowId);
1875
+ this.persistentExecutor = new Executor("Persistent Task Executor", {
1876
+ onTaskStart: this.onTaskStartCallback,
1877
+ initialMemory: previousMemory
1878
+ });
1879
+ }
1880
+ this.persistentExecutor.memoryStore?.add(memoryItem);
1881
+ this.persistentExecutor.memoryAnalytics?.recordMemoryOperation("add", memoryItem);
1882
+ }
1863
1883
  };
1864
1884
 
1865
1885
  // src/common/plan-builder.ts
@@ -1954,7 +1974,7 @@ import yaml3 from "js-yaml";
1954
1974
  import semver from "semver";
1955
1975
 
1956
1976
  // package.json
1957
- var version = "1.5.7";
1977
+ var version = "1.6.0";
1958
1978
 
1959
1979
  // src/common/task-cache.ts
1960
1980
  var debug3 = getDebug3("cache");
@@ -2165,7 +2185,10 @@ var PageAgent = class {
2165
2185
  }
2166
2186
  this.taskExecutor = new PageTaskExecutor(this.page, this.insight, {
2167
2187
  taskCache: this.taskCache,
2168
- onTaskStart: this.callbackOnTaskStartTip.bind(this)
2188
+ onTaskStart: this.callbackOnTaskStartTip.bind(this),
2189
+ memoryConfig: opts?.memoryConfig,
2190
+ sessionId: opts?.sessionId,
2191
+ workflowId: opts?.workflowId
2169
2192
  });
2170
2193
  this.dump = this.resetDump();
2171
2194
  this.reportFileName = reportFileName(
@@ -2616,6 +2639,7 @@ ${reasonMsg}`);
2616
2639
  }
2617
2640
  async aiCaptcha(options) {
2618
2641
  const { deepThink = false, autoDetectComplexity = true } = options || {};
2642
+ const memoryContext = this.getMemoryAsContext();
2619
2643
  let shouldUseDeepThink = deepThink;
2620
2644
  if (autoDetectComplexity && !deepThink) {
2621
2645
  const context = await this.getUIContext();
@@ -2696,6 +2720,26 @@ Return only "complex" or "simple" based on your analysis.
2696
2720
  }
2697
2721
  }
2698
2722
  await new Promise((resolve2) => setTimeout(resolve2, 3e3));
2723
+ const captchaMemoryItem = {
2724
+ id: `captcha_${Date.now()}`,
2725
+ timestamp: Date.now(),
2726
+ taskType: "Action",
2727
+ summary: `Solved ${captchaResult.captchaType} CAPTCHA: ${captchaResult.thought}`,
2728
+ context: {
2729
+ url: await this.page.url?.() || "",
2730
+ captchaType: captchaResult.captchaType,
2731
+ actions: captchaResult.actions,
2732
+ deepThink: actualDeepThink
2733
+ },
2734
+ metadata: {
2735
+ executionTime: Date.now() - Date.now(),
2736
+ // Will be updated
2737
+ success: true,
2738
+ confidence: 0.9
2739
+ },
2740
+ tags: ["captcha", "action", captchaResult.captchaType]
2741
+ };
2742
+ this.taskExecutor.addToMemory(captchaMemoryItem);
2699
2743
  const metadata = {
2700
2744
  status: "finished",
2701
2745
  usage,
@@ -2712,10 +2756,15 @@ Return only "complex" or "simple" based on your analysis.
2712
2756
  }
2713
2757
  async aiWaitFor(assertion, opt) {
2714
2758
  const startTime = Date.now();
2715
- const { executor } = await this.taskExecutor.waitFor(assertion, {
2759
+ const memoryContext = this.getMemoryAsContext();
2760
+ const assertionWithContext = memoryContext ? `${assertion}
2761
+
2762
+ Previous workflow steps:
2763
+ ${memoryContext}` : assertion;
2764
+ const { executor } = await this.taskExecutor.waitFor(assertionWithContext, {
2716
2765
  timeoutMs: opt?.timeoutMs || 15 * 1e3,
2717
2766
  checkIntervalMs: opt?.checkIntervalMs || 3 * 1e3,
2718
- assertion
2767
+ assertion: assertionWithContext
2719
2768
  });
2720
2769
  const metadata = {
2721
2770
  status: executor.isInErrorState() ? "failed" : "finished",
@@ -2871,6 +2920,109 @@ ${errors}`);
2871
2920
  clearMemory() {
2872
2921
  this.taskExecutor.clearMemory();
2873
2922
  }
2923
+ /**
2924
+ * Test sonunda kullanım için detaylı hafıza raporu döndürür (JSON formatında)
2925
+ */
2926
+ getMemoryReport() {
2927
+ const memory = this.getMemory();
2928
+ const stats = this.getMemoryStats();
2929
+ return {
2930
+ summary: {
2931
+ totalItems: memory.length,
2932
+ totalTasks: stats.analytics.totalTasks,
2933
+ memoryHits: stats.analytics.memoryHits,
2934
+ memoryMisses: stats.analytics.memoryMisses,
2935
+ memoryEffectiveness: Math.round(stats.analytics.memoryEffectiveness * 100),
2936
+ averageMemorySize: Math.round(stats.analytics.averageMemorySize * 100) / 100
2937
+ },
2938
+ config: stats.config,
2939
+ items: memory.map((item) => ({
2940
+ id: item.id,
2941
+ timestamp: item.timestamp,
2942
+ taskType: item.taskType,
2943
+ summary: item.summary,
2944
+ context: item.context,
2945
+ metadata: item.metadata,
2946
+ tags: item.tags,
2947
+ relativeTime: this.formatRelativeTime(item.timestamp)
2948
+ })),
2949
+ analytics: {
2950
+ taskTypeDistribution: this.getTaskTypeDistribution(memory),
2951
+ successRate: this.calculateSuccessRate(memory),
2952
+ averageExecutionTime: this.calculateAverageExecutionTime(memory),
2953
+ dataExtractionCount: this.countDataExtractions(memory),
2954
+ workflowSteps: this.extractWorkflowSteps(memory)
2955
+ }
2956
+ };
2957
+ }
2958
+ /**
2959
+ * Test sonunda kullanım için basit hafıza özeti döndürür (JSON formatında)
2960
+ */
2961
+ getMemorySummary() {
2962
+ const memory = this.getMemory();
2963
+ const stats = this.getMemoryStats();
2964
+ return {
2965
+ totalItems: memory.length,
2966
+ memoryEffectiveness: `${Math.round(stats.analytics.memoryEffectiveness * 100)}%`,
2967
+ taskTypes: this.getTaskTypeDistribution(memory),
2968
+ recentSteps: memory.slice(-5).map((item) => ({
2969
+ step: item.summary,
2970
+ type: item.taskType,
2971
+ success: item.metadata?.success || false,
2972
+ time: this.formatRelativeTime(item.timestamp)
2973
+ })),
2974
+ dataExtracted: this.getExtractedDataSummary(memory)
2975
+ };
2976
+ }
2977
+ formatRelativeTime(timestamp) {
2978
+ const now = Date.now();
2979
+ const diff = now - timestamp;
2980
+ const seconds = Math.floor(diff / 1e3);
2981
+ const minutes = Math.floor(seconds / 60);
2982
+ const hours = Math.floor(minutes / 60);
2983
+ if (hours > 0)
2984
+ return `${hours}h ${minutes % 60}m ago`;
2985
+ if (minutes > 0)
2986
+ return `${minutes}m ${seconds % 60}s ago`;
2987
+ return `${seconds}s ago`;
2988
+ }
2989
+ getTaskTypeDistribution(memory) {
2990
+ const distribution = {};
2991
+ memory.forEach((item) => {
2992
+ distribution[item.taskType] = (distribution[item.taskType] || 0) + 1;
2993
+ });
2994
+ return distribution;
2995
+ }
2996
+ calculateSuccessRate(memory) {
2997
+ if (memory.length === 0)
2998
+ return 0;
2999
+ const successCount = memory.filter((item) => item.metadata?.success !== false).length;
3000
+ return Math.round(successCount / memory.length * 100);
3001
+ }
3002
+ calculateAverageExecutionTime(memory) {
3003
+ const executionTimes = memory.map((item) => item.metadata?.executionTime).filter((time) => typeof time === "number");
3004
+ if (executionTimes.length === 0)
3005
+ return 0;
3006
+ const average = executionTimes.reduce((sum, time) => sum + time, 0) / executionTimes.length;
3007
+ return Math.round(average);
3008
+ }
3009
+ countDataExtractions(memory) {
3010
+ return memory.filter(
3011
+ (item) => item.context?.dataExtracted || item.taskType === "Insight" && item.summary.includes("Extracted")
3012
+ ).length;
3013
+ }
3014
+ extractWorkflowSteps(memory) {
3015
+ return memory.map((item) => item.summary);
3016
+ }
3017
+ getExtractedDataSummary(memory) {
3018
+ const extractedData = {};
3019
+ memory.forEach((item, index) => {
3020
+ if (item.context?.dataExtracted) {
3021
+ extractedData[`step_${index + 1}`] = item.context.dataExtracted;
3022
+ }
3023
+ });
3024
+ return extractedData;
3025
+ }
2874
3026
  };
2875
3027
  export {
2876
3028
  PageAgent