misoai-web 1.5.6 → 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 (75) hide show
  1. package/dist/es/agent.js +429 -44
  2. package/dist/es/agent.js.map +1 -1
  3. package/dist/es/bridge-mode-browser.js +10 -9
  4. package/dist/es/bridge-mode-browser.js.map +1 -1
  5. package/dist/es/bridge-mode.js +431 -46
  6. package/dist/es/bridge-mode.js.map +1 -1
  7. package/dist/es/chrome-extension.js +437 -51
  8. package/dist/es/chrome-extension.js.map +1 -1
  9. package/dist/es/index.js +445 -44
  10. package/dist/es/index.js.map +1 -1
  11. package/dist/es/midscene-playground.js +429 -44
  12. package/dist/es/midscene-playground.js.map +1 -1
  13. package/dist/es/midscene-server.js.map +1 -1
  14. package/dist/es/playground.js +429 -44
  15. package/dist/es/playground.js.map +1 -1
  16. package/dist/es/playwright-report.js +1 -1
  17. package/dist/es/playwright-report.js.map +1 -1
  18. package/dist/es/playwright.js +445 -44
  19. package/dist/es/playwright.js.map +1 -1
  20. package/dist/es/puppeteer-agent-launcher.js +429 -44
  21. package/dist/es/puppeteer-agent-launcher.js.map +1 -1
  22. package/dist/es/puppeteer.js +429 -44
  23. package/dist/es/puppeteer.js.map +1 -1
  24. package/dist/es/ui-utils.js.map +1 -1
  25. package/dist/es/utils.js +7 -4
  26. package/dist/es/utils.js.map +1 -1
  27. package/dist/es/yaml.js +24 -0
  28. package/dist/es/yaml.js.map +1 -1
  29. package/dist/lib/agent.js +427 -42
  30. package/dist/lib/agent.js.map +1 -1
  31. package/dist/lib/bridge-mode-browser.js +10 -9
  32. package/dist/lib/bridge-mode-browser.js.map +1 -1
  33. package/dist/lib/bridge-mode.js +429 -44
  34. package/dist/lib/bridge-mode.js.map +1 -1
  35. package/dist/lib/chrome-extension.js +435 -49
  36. package/dist/lib/chrome-extension.js.map +1 -1
  37. package/dist/lib/index.js +443 -42
  38. package/dist/lib/index.js.map +1 -1
  39. package/dist/lib/midscene-playground.js +427 -42
  40. package/dist/lib/midscene-playground.js.map +1 -1
  41. package/dist/lib/midscene-server.js.map +1 -1
  42. package/dist/lib/playground.js +427 -42
  43. package/dist/lib/playground.js.map +1 -1
  44. package/dist/lib/playwright-report.js +1 -1
  45. package/dist/lib/playwright-report.js.map +1 -1
  46. package/dist/lib/playwright.js +443 -42
  47. package/dist/lib/playwright.js.map +1 -1
  48. package/dist/lib/puppeteer-agent-launcher.js +427 -42
  49. package/dist/lib/puppeteer-agent-launcher.js.map +1 -1
  50. package/dist/lib/puppeteer.js +427 -42
  51. package/dist/lib/puppeteer.js.map +1 -1
  52. package/dist/lib/ui-utils.js.map +1 -1
  53. package/dist/lib/utils.js +7 -4
  54. package/dist/lib/utils.js.map +1 -1
  55. package/dist/lib/yaml.js +24 -0
  56. package/dist/lib/yaml.js.map +1 -1
  57. package/dist/types/agent.d.ts +101 -8
  58. package/dist/types/bridge-mode-browser.d.ts +2 -3
  59. package/dist/types/bridge-mode.d.ts +2 -3
  60. package/dist/types/{browser-aec1055d.d.ts → browser-9b472ffb.d.ts} +1 -1
  61. package/dist/types/chrome-extension.d.ts +2 -3
  62. package/dist/types/index.d.ts +1 -2
  63. package/dist/types/midscene-server.d.ts +1 -2
  64. package/dist/types/{page-86ab0fe1.d.ts → page-ed0ecb44.d.ts} +19 -9
  65. package/dist/types/playground.d.ts +2 -3
  66. package/dist/types/playwright.d.ts +9 -2
  67. package/dist/types/puppeteer-agent-launcher.d.ts +1 -2
  68. package/dist/types/puppeteer.d.ts +6 -5
  69. package/dist/types/ui-utils.d.ts +1 -1
  70. package/dist/types/utils.d.ts +1 -2
  71. package/dist/types/yaml.d.ts +1 -2
  72. package/iife-script/htmlElement.js +51 -73
  73. package/iife-script/htmlElementDebug.js +33 -54
  74. package/package.json +23 -23
  75. package/LICENSE +0 -21
@@ -143,6 +143,10 @@ var ScriptPlayer = class {
143
143
  } else if ("aiQuery" in flowItem) {
144
144
  const queryTask = flowItem;
145
145
  const prompt = queryTask.aiQuery;
146
+ const options = {
147
+ domIncluded: queryTask.domIncluded,
148
+ screenshotIncluded: queryTask.screenshotIncluded
149
+ };
146
150
  (0, import_utils.assert)(prompt, "missing prompt for aiQuery");
147
151
  (0, import_utils.assert)(
148
152
  typeof prompt === "string",
@@ -153,6 +157,10 @@ var ScriptPlayer = class {
153
157
  } else if ("aiNumber" in flowItem) {
154
158
  const numberTask = flowItem;
155
159
  const prompt = numberTask.aiNumber;
160
+ const options = {
161
+ domIncluded: numberTask.domIncluded,
162
+ screenshotIncluded: numberTask.screenshotIncluded
163
+ };
156
164
  (0, import_utils.assert)(prompt, "missing prompt for number");
157
165
  (0, import_utils.assert)(
158
166
  typeof prompt === "string",
@@ -163,6 +171,10 @@ var ScriptPlayer = class {
163
171
  } else if ("aiString" in flowItem) {
164
172
  const stringTask = flowItem;
165
173
  const prompt = stringTask.aiString;
174
+ const options = {
175
+ domIncluded: stringTask.domIncluded,
176
+ screenshotIncluded: stringTask.screenshotIncluded
177
+ };
166
178
  (0, import_utils.assert)(prompt, "missing prompt for string");
167
179
  (0, import_utils.assert)(
168
180
  typeof prompt === "string",
@@ -173,6 +185,10 @@ var ScriptPlayer = class {
173
185
  } else if ("aiBoolean" in flowItem) {
174
186
  const booleanTask = flowItem;
175
187
  const prompt = booleanTask.aiBoolean;
188
+ const options = {
189
+ domIncluded: booleanTask.domIncluded,
190
+ screenshotIncluded: booleanTask.screenshotIncluded
191
+ };
176
192
  (0, import_utils.assert)(prompt, "missing prompt for boolean");
177
193
  (0, import_utils.assert)(
178
194
  typeof prompt === "string",
@@ -215,6 +231,9 @@ var ScriptPlayer = class {
215
231
  } else if ("aiTap" in flowItem) {
216
232
  const tapTask = flowItem;
217
233
  await agent.aiTap(tapTask.aiTap, tapTask);
234
+ } else if ("aiRightClick" in flowItem) {
235
+ const rightClickTask = flowItem;
236
+ await agent.aiRightClick(rightClickTask.aiRightClick, rightClickTask);
218
237
  } else if ("aiHover" in flowItem) {
219
238
  const hoverTask = flowItem;
220
239
  await agent.aiHover(hoverTask.aiHover, hoverTask);
@@ -237,6 +256,11 @@ var ScriptPlayer = class {
237
256
  evaluateJavaScriptTask.javascript
238
257
  );
239
258
  this.setResult(evaluateJavaScriptTask.name, result);
259
+ } else if ("logScreenshot" in flowItem) {
260
+ const logScreenshotTask = flowItem;
261
+ await agent.logScreenshot(logScreenshotTask.logScreenshot, {
262
+ content: logScreenshotTask.content || ""
263
+ });
240
264
  } else {
241
265
  throw new Error(`unknown flowItem: ${JSON.stringify(flowItem)}`);
242
266
  }
@@ -485,7 +509,8 @@ var WebElementInfo = class {
485
509
  id,
486
510
  attributes,
487
511
  indexId,
488
- xpaths
512
+ xpaths,
513
+ isVisible
489
514
  }) {
490
515
  this.content = content;
491
516
  this.rect = rect;
@@ -498,6 +523,7 @@ var WebElementInfo = class {
498
523
  this.attributes = attributes;
499
524
  this.indexId = indexId;
500
525
  this.xpaths = xpaths;
526
+ this.isVisible = isVisible;
501
527
  }
502
528
  };
503
529
 
@@ -520,14 +546,15 @@ async function parseContextFromWebPage(page, _opt) {
520
546
  })
521
547
  ]);
522
548
  const webTree = (0, import_extractor.traverseTree)(tree, (elementInfo) => {
523
- const { rect, id, content, attributes, locator, indexId } = elementInfo;
549
+ const { rect, id, content, attributes, locator, indexId, isVisible } = elementInfo;
524
550
  return new WebElementInfo({
525
551
  rect,
526
552
  locator,
527
553
  id,
528
554
  content,
529
555
  attributes,
530
- indexId
556
+ indexId,
557
+ isVisible
531
558
  });
532
559
  });
533
560
  (0, import_utils4.assert)(screenshotBase64, "screenshotBase64 is required");
@@ -557,7 +584,7 @@ function printReportMsg(filepath) {
557
584
  (0, import_utils4.logMsg)(`Midscene - report file updated: ${filepath}`);
558
585
  }
559
586
  function replaceIllegalPathCharsAndSpace(str) {
560
- return str.replace(/[/\\:*?"<>| ]/g, "-");
587
+ return str.replace(/[:*?"<>| ]/g, "-");
561
588
  }
562
589
  function forceClosePopup(page, debug6) {
563
590
  page.on("popup", async (popup) => {
@@ -614,6 +641,94 @@ var replanningCountLimit = 10;
614
641
  var isAndroidPage = (page) => {
615
642
  return page.pageType === "android";
616
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
+ };
617
732
  var PageTaskExecutor = class {
618
733
  constructor(page, insight, opts) {
619
734
  this.conversationHistory = [];
@@ -621,6 +736,25 @@ var PageTaskExecutor = class {
621
736
  this.insight = insight;
622
737
  this.taskCache = opts.taskCache;
623
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);
624
758
  }
625
759
  async recordScreenshot(timing) {
626
760
  const base64 = await this.page.screenshotBase64();
@@ -833,8 +967,11 @@ var PageTaskExecutor = class {
833
967
  insightDump = dump;
834
968
  };
835
969
  this.insight.onceDumpUpdatedFn = dumpCollector;
970
+ const memoryContext = this.getMemoryAsContext();
836
971
  const assertion = await this.insight.assert(
837
- assertPlan.param.assertion
972
+ assertPlan.param.assertion,
973
+ memoryContext
974
+ // Hafıza bağlamını geç
838
975
  );
839
976
  if (!assertion.pass) {
840
977
  if (plan2.type === "Assert") {
@@ -871,10 +1008,10 @@ var PageTaskExecutor = class {
871
1008
  if (!taskParam || !taskParam.value) {
872
1009
  return;
873
1010
  }
874
- await this.page.keyboard.type(taskParam.value);
875
- } else {
876
- await this.page.keyboard.type(taskParam.value);
877
1011
  }
1012
+ await this.page.keyboard.type(taskParam.value, {
1013
+ autoDismissKeyboard: taskParam.autoDismissKeyboard
1014
+ });
878
1015
  }
879
1016
  };
880
1017
  tasks.push(taskActionInput);
@@ -903,6 +1040,22 @@ var PageTaskExecutor = class {
903
1040
  }
904
1041
  };
905
1042
  tasks.push(taskActionTap);
1043
+ } else if (plan2.type === "RightClick") {
1044
+ const taskActionRightClick = {
1045
+ type: "Action",
1046
+ subType: "RightClick",
1047
+ thought: plan2.thought,
1048
+ locate: plan2.locate,
1049
+ executor: async (param, { element }) => {
1050
+ (0, import_utils6.assert)(element, "Element not found, cannot right click");
1051
+ await this.page.mouse.click(
1052
+ element.center[0],
1053
+ element.center[1],
1054
+ { button: "right" }
1055
+ );
1056
+ }
1057
+ };
1058
+ tasks.push(taskActionRightClick);
906
1059
  } else if (plan2.type === "Drag") {
907
1060
  const taskActionDrag = {
908
1061
  type: "Action",
@@ -1304,25 +1457,146 @@ var PageTaskExecutor = class {
1304
1457
  };
1305
1458
  return task;
1306
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
+ }
1307
1544
  async runPlans(title, plans, opts) {
1308
- const taskExecutor = new import_misoai_core.Executor(title, {
1309
- onTaskStart: this.onTaskStartCallback
1310
- });
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
+ }
1311
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
+ });
1312
1569
  await taskExecutor.append(tasks);
1313
1570
  const result = await taskExecutor.flush();
1571
+ if (useMemory) {
1572
+ this.workflowMemory.saveWorkflowMemory(
1573
+ taskExecutor.getMemory(),
1574
+ this.sessionContext.workflowId || "default"
1575
+ );
1576
+ }
1314
1577
  return {
1315
1578
  output: result,
1316
1579
  executor: taskExecutor
1317
1580
  };
1318
1581
  }
1319
1582
  async action(userPrompt, actionContext, opts) {
1320
- const taskExecutor = new import_misoai_core.Executor(taskTitleStr("Action", userPrompt), {
1321
- onTaskStart: this.onTaskStartCallback
1322
- });
1323
- 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);
1324
1595
  let replanCount = 0;
1325
1596
  const logList = [];
1597
+ if (memoryContext) {
1598
+ logList.push(memoryContext);
1599
+ }
1326
1600
  const yamlFlow = [];
1327
1601
  while (planningTask) {
1328
1602
  if (replanCount > replanningCountLimit) {
@@ -1431,16 +1705,22 @@ var PageTaskExecutor = class {
1431
1705
  executor: taskExecutor
1432
1706
  };
1433
1707
  }
1434
- async createTypeQueryTask(type, demand) {
1435
- const taskExecutor = new import_misoai_core.Executor(
1436
- taskTitleStr(
1437
- type,
1438
- typeof demand === "string" ? demand : JSON.stringify(demand)
1439
- ),
1440
- {
1441
- onTaskStart: this.onTaskStartCallback
1442
- }
1443
- );
1708
+ async createTypeQueryTask(type, demand, opt) {
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
+ }
1444
1724
  const queryTask = {
1445
1725
  type: "Insight",
1446
1726
  subType: type,
@@ -1462,7 +1742,13 @@ var PageTaskExecutor = class {
1462
1742
  result: `${type}, ${demand}`
1463
1743
  };
1464
1744
  }
1465
- const { data, usage } = await this.insight.extract(demandInput);
1745
+ const memoryContext = this.getMemoryAsContext();
1746
+ const { data, usage } = await this.insight.extract(
1747
+ demandInput,
1748
+ opt,
1749
+ memoryContext
1750
+ // Hafıza bağlamını geç
1751
+ );
1466
1752
  let outputResult = data;
1467
1753
  if (ifTypeRestricted) {
1468
1754
  (0, import_utils6.assert)(data?.result !== void 0, "No result in query data");
@@ -1482,23 +1768,29 @@ var PageTaskExecutor = class {
1482
1768
  executor: taskExecutor
1483
1769
  };
1484
1770
  }
1485
- async query(demand) {
1486
- return this.createTypeQueryTask("Query", demand);
1771
+ async query(demand, opt) {
1772
+ return this.createTypeQueryTask("Query", demand, opt);
1487
1773
  }
1488
- async boolean(prompt) {
1489
- return this.createTypeQueryTask("Boolean", prompt);
1774
+ async boolean(prompt, opt) {
1775
+ return this.createTypeQueryTask("Boolean", prompt, opt);
1490
1776
  }
1491
- async number(prompt) {
1492
- return this.createTypeQueryTask("Number", prompt);
1777
+ async number(prompt, opt) {
1778
+ return this.createTypeQueryTask("Number", prompt, opt);
1493
1779
  }
1494
- async string(prompt) {
1495
- return this.createTypeQueryTask("String", prompt);
1780
+ async string(prompt, opt) {
1781
+ return this.createTypeQueryTask("String", prompt, opt);
1496
1782
  }
1497
- async assert(assertion) {
1783
+ async assert(assertion, memoryContext) {
1498
1784
  const description = `assert: ${assertion}`;
1499
- const taskExecutor = new import_misoai_core.Executor(taskTitleStr("Assert", description), {
1500
- onTaskStart: this.onTaskStartCallback
1501
- });
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
+ }
1502
1794
  const assertionPlan = {
1503
1795
  type: "Assert",
1504
1796
  param: {
@@ -1628,7 +1920,7 @@ function buildPlans(type, locateParam, param) {
1628
1920
  param: locateParam,
1629
1921
  thought: ""
1630
1922
  } : null;
1631
- if (type === "Tap" || type === "Hover") {
1923
+ if (type === "Tap" || type === "Hover" || type === "RightClick") {
1632
1924
  (0, import_utils8.assert)(locateParam, `missing locate info for action "${type}"`);
1633
1925
  (0, import_utils8.assert)(locatePlan, `missing locate info for action "${type}"`);
1634
1926
  const tapPlan = {
@@ -1708,7 +2000,7 @@ var import_js_yaml3 = __toESM(require("js-yaml"));
1708
2000
  var import_semver = __toESM(require("semver"));
1709
2001
 
1710
2002
  // package.json
1711
- var version = "1.5.6";
2003
+ var version = "1.5.7";
1712
2004
 
1713
2005
  // src/common/task-cache.ts
1714
2006
  var debug3 = (0, import_logger3.getDebug)("cache");
@@ -1839,8 +2131,14 @@ cache file: ${cacheFile}`
1839
2131
  return;
1840
2132
  }
1841
2133
  try {
2134
+ const dir = (0, import_node_path2.dirname)(this.cacheFilePath);
2135
+ if (!(0, import_node_fs2.existsSync)(dir)) {
2136
+ (0, import_node_fs2.mkdirSync)(dir, { recursive: true });
2137
+ debug3("created cache directory: %s", dir);
2138
+ }
1842
2139
  const yamlData = import_js_yaml3.default.dump(this.cache);
1843
2140
  (0, import_node_fs2.writeFileSync)(this.cacheFilePath, yamlData);
2141
+ debug3("cache flushed to file: %s", this.cacheFilePath);
1844
2142
  } catch (err) {
1845
2143
  debug3(
1846
2144
  "write cache to file failed, path: %s, error: %s",
@@ -2098,6 +2396,23 @@ var PageAgent = class {
2098
2396
  metadata
2099
2397
  };
2100
2398
  }
2399
+ async aiRightClick(locatePrompt, opt) {
2400
+ const detailedLocateParam = this.buildDetailedLocateParam(
2401
+ locatePrompt,
2402
+ opt
2403
+ );
2404
+ const plans = buildPlans("RightClick", detailedLocateParam);
2405
+ const { executor, output } = await this.taskExecutor.runPlans(
2406
+ taskTitleStr("RightClick", locateParamStr(detailedLocateParam)),
2407
+ plans,
2408
+ { cacheable: opt?.cacheable }
2409
+ );
2410
+ const metadata = this.afterTaskRunning(executor);
2411
+ return {
2412
+ result: output,
2413
+ metadata
2414
+ };
2415
+ }
2101
2416
  async aiInput(value, locatePrompt, opt) {
2102
2417
  (0, import_utils12.assert)(
2103
2418
  typeof value === "string",
@@ -2172,7 +2487,13 @@ var PageAgent = class {
2172
2487
  metadata: metadata2
2173
2488
  };
2174
2489
  }
2175
- 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, {
2176
2497
  cacheable
2177
2498
  }));
2178
2499
  if (this.taskCache && output?.yamlFlow && cacheable !== false) {
@@ -2318,8 +2639,9 @@ var PageAgent = class {
2318
2639
  } catch (e) {
2319
2640
  }
2320
2641
  }
2642
+ const memoryContext = this.getMemoryAsContext();
2321
2643
  const assertionWithContext = currentUrl ? `For the page at URL "${currentUrl}", ${assertion}` : assertion;
2322
- const { output, executor } = await this.taskExecutor.assert(assertionWithContext);
2644
+ const { output, executor } = await this.taskExecutor.assert(assertionWithContext, memoryContext);
2323
2645
  const metadata = this.afterTaskRunning(executor, true);
2324
2646
  if (output && opt?.keepRawResponse) {
2325
2647
  return {
@@ -2529,9 +2851,72 @@ ${errors}`);
2529
2851
  }
2530
2852
  throw new Error("evaluateJavaScript is not supported in current agent");
2531
2853
  }
2854
+ async logScreenshot(title, options) {
2855
+ const screenshotTitle = title || "untitled";
2856
+ const content = options?.content || "";
2857
+ const screenshot = await this.page.screenshotBase64?.();
2858
+ if (screenshot) {
2859
+ const executionDump = {
2860
+ name: screenshotTitle,
2861
+ description: content,
2862
+ tasks: [{
2863
+ type: "Screenshot",
2864
+ subType: "log",
2865
+ status: "finished",
2866
+ executor: null,
2867
+ param: {
2868
+ title: screenshotTitle,
2869
+ content
2870
+ },
2871
+ output: {
2872
+ screenshot
2873
+ },
2874
+ thought: `Logged screenshot: ${screenshotTitle}`,
2875
+ timing: {
2876
+ start: Date.now(),
2877
+ end: Date.now(),
2878
+ cost: 0
2879
+ }
2880
+ }],
2881
+ sdkVersion: "1.0.0",
2882
+ logTime: Date.now(),
2883
+ model_name: "screenshot"
2884
+ };
2885
+ this.appendExecutionDump(executionDump);
2886
+ }
2887
+ }
2532
2888
  async destroy() {
2533
2889
  await this.page.destroy();
2534
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
+ }
2535
2920
  };
2536
2921
 
2537
2922
  // src/puppeteer/index.ts