misoai-web 1.5.7 → 1.5.8

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 +307 -25
  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 +309 -27
  5. package/dist/es/bridge-mode.js.map +1 -1
  6. package/dist/es/chrome-extension.js +308 -26
  7. package/dist/es/chrome-extension.js.map +1 -1
  8. package/dist/es/index.js +307 -25
  9. package/dist/es/index.js.map +1 -1
  10. package/dist/es/midscene-playground.js +307 -25
  11. package/dist/es/midscene-playground.js.map +1 -1
  12. package/dist/es/playground.js +307 -25
  13. package/dist/es/playground.js.map +1 -1
  14. package/dist/es/playwright.js +307 -25
  15. package/dist/es/playwright.js.map +1 -1
  16. package/dist/es/puppeteer-agent-launcher.js +307 -25
  17. package/dist/es/puppeteer-agent-launcher.js.map +1 -1
  18. package/dist/es/puppeteer.js +307 -25
  19. package/dist/es/puppeteer.js.map +1 -1
  20. package/dist/lib/agent.js +307 -25
  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 +309 -27
  24. package/dist/lib/bridge-mode.js.map +1 -1
  25. package/dist/lib/chrome-extension.js +308 -26
  26. package/dist/lib/chrome-extension.js.map +1 -1
  27. package/dist/lib/index.js +307 -25
  28. package/dist/lib/index.js.map +1 -1
  29. package/dist/lib/midscene-playground.js +307 -25
  30. package/dist/lib/midscene-playground.js.map +1 -1
  31. package/dist/lib/playground.js +307 -25
  32. package/dist/lib/playground.js.map +1 -1
  33. package/dist/lib/playwright.js +307 -25
  34. package/dist/lib/playwright.js.map +1 -1
  35. package/dist/lib/puppeteer-agent-launcher.js +307 -25
  36. package/dist/lib/puppeteer-agent-launcher.js.map +1 -1
  37. package/dist/lib/puppeteer.js +307 -25
  38. package/dist/lib/puppeteer.js.map +1 -1
  39. package/dist/types/agent.d.ts +92 -2
  40. package/package.json +2 -2
@@ -641,6 +641,94 @@ var replanningCountLimit = 10;
641
641
  var isAndroidPage = (page) => {
642
642
  return page.pageType === "android";
643
643
  };
644
+ var WorkflowMemory = class {
645
+ constructor(config) {
646
+ this.workflows = /* @__PURE__ */ new Map();
647
+ this.config = config;
648
+ }
649
+ /**
650
+ * İş akışı hafızasını getirir
651
+ */
652
+ getWorkflowMemory(workflowId = "default") {
653
+ const workflow = this.workflows.get(workflowId);
654
+ return workflow?.memory || [];
655
+ }
656
+ /**
657
+ * İş akışı verilerini getirir
658
+ */
659
+ getWorkflowData(workflowId = "default") {
660
+ return this.workflows.get(workflowId) || this.createEmptyWorkflowData(workflowId);
661
+ }
662
+ /**
663
+ * İş akışı hafızasını kaydeder
664
+ */
665
+ saveWorkflowMemory(memory, workflowId = "default") {
666
+ const workflow = this.workflows.get(workflowId) || this.createEmptyWorkflowData(workflowId);
667
+ workflow.memory = [...memory];
668
+ workflow.metadata.totalSteps = workflow.steps.length;
669
+ workflow.metadata.completedSteps = workflow.steps.filter((s) => s.status === "completed").length;
670
+ workflow.metadata.failedSteps = workflow.steps.filter((s) => s.status === "failed").length;
671
+ this.workflows.set(workflowId, workflow);
672
+ this.enforceRetentionPolicy();
673
+ }
674
+ /**
675
+ * İş akışı bağlamını günceller
676
+ */
677
+ updateWorkflowContext(context, workflowId = "default") {
678
+ const workflow = this.workflows.get(workflowId) || this.createEmptyWorkflowData(workflowId);
679
+ workflow.context = { ...workflow.context, ...context };
680
+ if (context.currentStep) {
681
+ const existingStep = workflow.steps.find((s) => s.stepName === context.currentStep);
682
+ if (!existingStep) {
683
+ workflow.steps.push({
684
+ stepId: `step_${workflow.steps.length + 1}`,
685
+ stepName: context.currentStep,
686
+ timestamp: context.timestamp,
687
+ status: "running",
688
+ memoryItems: []
689
+ });
690
+ }
691
+ }
692
+ this.workflows.set(workflowId, workflow);
693
+ }
694
+ /**
695
+ * İş akışını temizler
696
+ */
697
+ clearWorkflow(workflowId = "default") {
698
+ this.workflows.delete(workflowId);
699
+ }
700
+ /**
701
+ * Tüm iş akışlarını temizler
702
+ */
703
+ clearAll() {
704
+ this.workflows.clear();
705
+ }
706
+ createEmptyWorkflowData(workflowId) {
707
+ return {
708
+ workflowId,
709
+ steps: [],
710
+ memory: [],
711
+ context: {
712
+ pageInfo: { url: "", title: "" },
713
+ timestamp: Date.now()
714
+ },
715
+ metadata: {
716
+ totalSteps: 0,
717
+ completedSteps: 0,
718
+ failedSteps: 0,
719
+ startTime: Date.now()
720
+ }
721
+ };
722
+ }
723
+ enforceRetentionPolicy() {
724
+ const maxWorkflows = 10;
725
+ if (this.workflows.size > maxWorkflows) {
726
+ const sortedWorkflows = Array.from(this.workflows.entries()).sort(([, a], [, b]) => (b.metadata.endTime || b.metadata.startTime) - (a.metadata.endTime || a.metadata.startTime));
727
+ const toDelete = sortedWorkflows.slice(maxWorkflows);
728
+ toDelete.forEach(([workflowId]) => this.workflows.delete(workflowId));
729
+ }
730
+ }
731
+ };
644
732
  var PageTaskExecutor = class {
645
733
  constructor(page, insight, opts) {
646
734
  this.conversationHistory = [];
@@ -648,6 +736,25 @@ var PageTaskExecutor = class {
648
736
  this.insight = insight;
649
737
  this.taskCache = opts.taskCache;
650
738
  this.onTaskStartCallback = opts?.onTaskStart;
739
+ this.memoryConfig = {
740
+ maxItems: 100,
741
+ maxAge: 2 * 60 * 60 * 1e3,
742
+ // 2 saat
743
+ enablePersistence: true,
744
+ enableAnalytics: true,
745
+ filterStrategy: "hybrid",
746
+ ...opts?.memoryConfig
747
+ };
748
+ this.sessionContext = {
749
+ sessionId: opts?.sessionId || this.generateSessionId(),
750
+ workflowId: opts?.workflowId,
751
+ startTime: Date.now(),
752
+ pageInfo: {
753
+ url: "",
754
+ title: ""
755
+ }
756
+ };
757
+ this.workflowMemory = new WorkflowMemory(this.memoryConfig);
651
758
  }
652
759
  async recordScreenshot(timing) {
653
760
  const base64 = await this.page.screenshotBase64();
@@ -860,8 +967,11 @@ var PageTaskExecutor = class {
860
967
  insightDump = dump;
861
968
  };
862
969
  this.insight.onceDumpUpdatedFn = dumpCollector;
970
+ const memoryContext = this.getMemoryAsContext();
863
971
  const assertion = await this.insight.assert(
864
- assertPlan.param.assertion
972
+ assertPlan.param.assertion,
973
+ memoryContext
974
+ // Hafıza bağlamını geç
865
975
  );
866
976
  if (!assertion.pass) {
867
977
  if (plan2.type === "Assert") {
@@ -1347,25 +1457,146 @@ var PageTaskExecutor = class {
1347
1457
  };
1348
1458
  return task;
1349
1459
  }
1460
+ /**
1461
+ * Persistent executor'ı getirir veya oluşturur
1462
+ */
1463
+ getPersistentExecutor() {
1464
+ if (!this.persistentExecutor || this.persistentExecutor.status === "error") {
1465
+ const previousMemory = this.workflowMemory.getWorkflowMemory(this.sessionContext.workflowId);
1466
+ this.persistentExecutor = new import_misoai_core.Executor("Persistent Task Executor", {
1467
+ onTaskStart: this.onTaskStartCallback,
1468
+ initialMemory: previousMemory
1469
+ });
1470
+ }
1471
+ return this.persistentExecutor;
1472
+ }
1473
+ /**
1474
+ * Sayfa bağlamını günceller
1475
+ */
1476
+ async updatePageContext() {
1477
+ try {
1478
+ if (this.page.url) {
1479
+ this.sessionContext.pageInfo.url = await this.page.url();
1480
+ }
1481
+ if (this.page.pageType === "puppeteer" || this.page.pageType === "playwright") {
1482
+ this.sessionContext.pageInfo.title = await this.page.title();
1483
+ }
1484
+ } catch (e) {
1485
+ }
1486
+ }
1487
+ /**
1488
+ * Hafızayı temizler
1489
+ */
1490
+ clearMemory() {
1491
+ if (this.persistentExecutor) {
1492
+ this.persistentExecutor.clearMemory();
1493
+ }
1494
+ this.workflowMemory.clearWorkflow(this.sessionContext.workflowId || "default");
1495
+ }
1496
+ /**
1497
+ * Mevcut hafızayı döndürür
1498
+ */
1499
+ getMemory() {
1500
+ return this.persistentExecutor?.getMemory() || [];
1501
+ }
1502
+ /**
1503
+ * İş akışı hafızasını döndürür
1504
+ */
1505
+ getWorkflowMemory() {
1506
+ return this.workflowMemory.getWorkflowData(this.sessionContext.workflowId || "default");
1507
+ }
1508
+ /**
1509
+ * Hafıza istatistiklerini döndürür
1510
+ */
1511
+ getMemoryStats() {
1512
+ return this.persistentExecutor?.getMemoryStats() || {
1513
+ totalItems: 0,
1514
+ analytics: { totalTasks: 0, memoryHits: 0, memoryMisses: 0, averageMemorySize: 0, memoryEffectiveness: 0 },
1515
+ config: this.memoryConfig
1516
+ };
1517
+ }
1518
+ /**
1519
+ * Hafıza konfigürasyonunu günceller
1520
+ */
1521
+ updateMemoryConfig(config) {
1522
+ this.memoryConfig = { ...this.memoryConfig, ...config };
1523
+ if (this.persistentExecutor) {
1524
+ this.persistentExecutor.updateMemoryConfig(this.memoryConfig);
1525
+ }
1526
+ }
1527
+ /**
1528
+ * Oturum ID'sini oluşturur
1529
+ */
1530
+ generateSessionId() {
1531
+ return `session_${Date.now()}_${Math.random().toString(36).substr(2, 8)}`;
1532
+ }
1533
+ /**
1534
+ * Hafızayı bağlam olarak formatlar
1535
+ */
1536
+ getMemoryAsContext() {
1537
+ const memory = this.getMemory();
1538
+ if (memory.length === 0) {
1539
+ return "";
1540
+ }
1541
+ const recentMemory = memory.slice(-5);
1542
+ return recentMemory.map((item) => `- ${item.summary}`).join("\n");
1543
+ }
1350
1544
  async runPlans(title, plans, opts) {
1351
- const taskExecutor = new import_misoai_core.Executor(title, {
1352
- onTaskStart: this.onTaskStartCallback
1353
- });
1545
+ await this.updatePageContext();
1546
+ const useMemory = opts?.useMemory !== false;
1547
+ let taskExecutor;
1548
+ if (useMemory) {
1549
+ taskExecutor = this.getPersistentExecutor();
1550
+ this.workflowMemory.updateWorkflowContext({
1551
+ currentStep: title,
1552
+ pageInfo: this.sessionContext.pageInfo,
1553
+ timestamp: Date.now()
1554
+ }, this.sessionContext.workflowId || "default");
1555
+ } else {
1556
+ taskExecutor = new import_misoai_core.Executor(title, {
1557
+ onTaskStart: this.onTaskStartCallback
1558
+ });
1559
+ }
1354
1560
  const { tasks } = await this.convertPlanToExecutable(plans, opts);
1561
+ tasks.forEach((task) => {
1562
+ task.context = {
1563
+ ...task.context,
1564
+ ...this.sessionContext.pageInfo,
1565
+ workflowId: this.sessionContext.workflowId,
1566
+ sessionId: this.sessionContext.sessionId
1567
+ };
1568
+ });
1355
1569
  await taskExecutor.append(tasks);
1356
1570
  const result = await taskExecutor.flush();
1571
+ if (useMemory) {
1572
+ this.workflowMemory.saveWorkflowMemory(
1573
+ taskExecutor.getMemory(),
1574
+ this.sessionContext.workflowId || "default"
1575
+ );
1576
+ }
1357
1577
  return {
1358
1578
  output: result,
1359
1579
  executor: taskExecutor
1360
1580
  };
1361
1581
  }
1362
1582
  async action(userPrompt, actionContext, opts) {
1363
- const taskExecutor = new import_misoai_core.Executor(taskTitleStr("Action", userPrompt), {
1364
- onTaskStart: this.onTaskStartCallback
1365
- });
1366
- let planningTask = this.planningTaskFromPrompt(userPrompt, void 0, actionContext);
1583
+ const useMemory = true;
1584
+ let taskExecutor;
1585
+ if (useMemory) {
1586
+ taskExecutor = this.getPersistentExecutor();
1587
+ } else {
1588
+ taskExecutor = new import_misoai_core.Executor(taskTitleStr("Action", userPrompt), {
1589
+ onTaskStart: this.onTaskStartCallback
1590
+ });
1591
+ }
1592
+ const memoryContext = this.getMemoryAsContext();
1593
+ const initialLog = memoryContext ? memoryContext : void 0;
1594
+ let planningTask = this.planningTaskFromPrompt(userPrompt, initialLog, actionContext);
1367
1595
  let replanCount = 0;
1368
1596
  const logList = [];
1597
+ if (memoryContext) {
1598
+ logList.push(memoryContext);
1599
+ }
1369
1600
  const yamlFlow = [];
1370
1601
  while (planningTask) {
1371
1602
  if (replanCount > replanningCountLimit) {
@@ -1475,15 +1706,21 @@ var PageTaskExecutor = class {
1475
1706
  };
1476
1707
  }
1477
1708
  async createTypeQueryTask(type, demand, opt) {
1478
- const taskExecutor = new import_misoai_core.Executor(
1479
- taskTitleStr(
1480
- type,
1481
- typeof demand === "string" ? demand : JSON.stringify(demand)
1482
- ),
1483
- {
1484
- onTaskStart: this.onTaskStartCallback
1485
- }
1486
- );
1709
+ const useMemory = true;
1710
+ let taskExecutor;
1711
+ if (useMemory) {
1712
+ taskExecutor = this.getPersistentExecutor();
1713
+ } else {
1714
+ taskExecutor = new import_misoai_core.Executor(
1715
+ taskTitleStr(
1716
+ type,
1717
+ typeof demand === "string" ? demand : JSON.stringify(demand)
1718
+ ),
1719
+ {
1720
+ onTaskStart: this.onTaskStartCallback
1721
+ }
1722
+ );
1723
+ }
1487
1724
  const queryTask = {
1488
1725
  type: "Insight",
1489
1726
  subType: type,
@@ -1505,9 +1742,12 @@ var PageTaskExecutor = class {
1505
1742
  result: `${type}, ${demand}`
1506
1743
  };
1507
1744
  }
1745
+ const memoryContext = this.getMemoryAsContext();
1508
1746
  const { data, usage } = await this.insight.extract(
1509
1747
  demandInput,
1510
- opt
1748
+ opt,
1749
+ memoryContext
1750
+ // Hafıza bağlamını geç
1511
1751
  );
1512
1752
  let outputResult = data;
1513
1753
  if (ifTypeRestricted) {
@@ -1540,11 +1780,17 @@ var PageTaskExecutor = class {
1540
1780
  async string(prompt, opt) {
1541
1781
  return this.createTypeQueryTask("String", prompt, opt);
1542
1782
  }
1543
- async assert(assertion) {
1783
+ async assert(assertion, memoryContext) {
1544
1784
  const description = `assert: ${assertion}`;
1545
- const taskExecutor = new import_misoai_core.Executor(taskTitleStr("Assert", description), {
1546
- onTaskStart: this.onTaskStartCallback
1547
- });
1785
+ const useMemory = true;
1786
+ let taskExecutor;
1787
+ if (useMemory) {
1788
+ taskExecutor = this.getPersistentExecutor();
1789
+ } else {
1790
+ taskExecutor = new import_misoai_core.Executor(taskTitleStr("Assert", description), {
1791
+ onTaskStart: this.onTaskStartCallback
1792
+ });
1793
+ }
1548
1794
  const assertionPlan = {
1549
1795
  type: "Assert",
1550
1796
  param: {
@@ -1754,7 +2000,7 @@ var import_js_yaml3 = __toESM(require("js-yaml"));
1754
2000
  var import_semver = __toESM(require("semver"));
1755
2001
 
1756
2002
  // package.json
1757
- var version = "1.0.3";
2003
+ var version = "1.5.7";
1758
2004
 
1759
2005
  // src/common/task-cache.ts
1760
2006
  var debug3 = (0, import_logger3.getDebug)("cache");
@@ -2241,7 +2487,13 @@ var PageAgent = class {
2241
2487
  metadata: metadata2
2242
2488
  };
2243
2489
  }
2244
- const { output, executor } = await (isVlmUiTars ? this.taskExecutor.actionToGoal(taskPrompt, { cacheable }) : this.taskExecutor.action(taskPrompt, this.opts.aiActionContext, {
2490
+ const memoryContext = this.getMemoryAsContext();
2491
+ const enhancedActionContext = this.opts.aiActionContext ? `${this.opts.aiActionContext}
2492
+
2493
+ Previous workflow steps:
2494
+ ${memoryContext}` : memoryContext ? `Previous workflow steps:
2495
+ ${memoryContext}` : void 0;
2496
+ const { output, executor } = await (isVlmUiTars ? this.taskExecutor.actionToGoal(taskPrompt, { cacheable }) : this.taskExecutor.action(taskPrompt, enhancedActionContext, {
2245
2497
  cacheable
2246
2498
  }));
2247
2499
  if (this.taskCache && output?.yamlFlow && cacheable !== false) {
@@ -2387,8 +2639,9 @@ var PageAgent = class {
2387
2639
  } catch (e) {
2388
2640
  }
2389
2641
  }
2642
+ const memoryContext = this.getMemoryAsContext();
2390
2643
  const assertionWithContext = currentUrl ? `For the page at URL "${currentUrl}", ${assertion}` : assertion;
2391
- const { output, executor } = await this.taskExecutor.assert(assertionWithContext);
2644
+ const { output, executor } = await this.taskExecutor.assert(assertionWithContext, memoryContext);
2392
2645
  const metadata = this.afterTaskRunning(executor, true);
2393
2646
  if (output && opt?.keepRawResponse) {
2394
2647
  return {
@@ -2635,6 +2888,35 @@ ${errors}`);
2635
2888
  async destroy() {
2636
2889
  await this.page.destroy();
2637
2890
  }
2891
+ /**
2892
+ * Hafızayı bağlam olarak formatlar
2893
+ */
2894
+ getMemoryAsContext() {
2895
+ const memory = this.taskExecutor.getMemory();
2896
+ if (memory.length === 0) {
2897
+ return "";
2898
+ }
2899
+ const recentMemory = memory.slice(-5);
2900
+ return recentMemory.map((item) => `- ${item.summary}`).join("\n");
2901
+ }
2902
+ /**
2903
+ * Mevcut hafızayı döndürür
2904
+ */
2905
+ getMemory() {
2906
+ return this.taskExecutor.getMemory();
2907
+ }
2908
+ /**
2909
+ * Hafıza istatistiklerini döndürür
2910
+ */
2911
+ getMemoryStats() {
2912
+ return this.taskExecutor.getMemoryStats();
2913
+ }
2914
+ /**
2915
+ * Hafızayı temizler
2916
+ */
2917
+ clearMemory() {
2918
+ this.taskExecutor.clearMemory();
2919
+ }
2638
2920
  };
2639
2921
 
2640
2922
  // src/puppeteer/index.ts