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.
- package/dist/es/agent.js +429 -44
- package/dist/es/agent.js.map +1 -1
- package/dist/es/bridge-mode-browser.js +10 -9
- package/dist/es/bridge-mode-browser.js.map +1 -1
- package/dist/es/bridge-mode.js +431 -46
- package/dist/es/bridge-mode.js.map +1 -1
- package/dist/es/chrome-extension.js +437 -51
- package/dist/es/chrome-extension.js.map +1 -1
- package/dist/es/index.js +445 -44
- package/dist/es/index.js.map +1 -1
- package/dist/es/midscene-playground.js +429 -44
- package/dist/es/midscene-playground.js.map +1 -1
- package/dist/es/midscene-server.js.map +1 -1
- package/dist/es/playground.js +429 -44
- package/dist/es/playground.js.map +1 -1
- package/dist/es/playwright-report.js +1 -1
- package/dist/es/playwright-report.js.map +1 -1
- package/dist/es/playwright.js +445 -44
- package/dist/es/playwright.js.map +1 -1
- package/dist/es/puppeteer-agent-launcher.js +429 -44
- package/dist/es/puppeteer-agent-launcher.js.map +1 -1
- package/dist/es/puppeteer.js +429 -44
- package/dist/es/puppeteer.js.map +1 -1
- package/dist/es/ui-utils.js.map +1 -1
- package/dist/es/utils.js +7 -4
- package/dist/es/utils.js.map +1 -1
- package/dist/es/yaml.js +24 -0
- package/dist/es/yaml.js.map +1 -1
- package/dist/lib/agent.js +427 -42
- package/dist/lib/agent.js.map +1 -1
- package/dist/lib/bridge-mode-browser.js +10 -9
- package/dist/lib/bridge-mode-browser.js.map +1 -1
- package/dist/lib/bridge-mode.js +429 -44
- package/dist/lib/bridge-mode.js.map +1 -1
- package/dist/lib/chrome-extension.js +435 -49
- package/dist/lib/chrome-extension.js.map +1 -1
- package/dist/lib/index.js +443 -42
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/midscene-playground.js +427 -42
- package/dist/lib/midscene-playground.js.map +1 -1
- package/dist/lib/midscene-server.js.map +1 -1
- package/dist/lib/playground.js +427 -42
- package/dist/lib/playground.js.map +1 -1
- package/dist/lib/playwright-report.js +1 -1
- package/dist/lib/playwright-report.js.map +1 -1
- package/dist/lib/playwright.js +443 -42
- package/dist/lib/playwright.js.map +1 -1
- package/dist/lib/puppeteer-agent-launcher.js +427 -42
- package/dist/lib/puppeteer-agent-launcher.js.map +1 -1
- package/dist/lib/puppeteer.js +427 -42
- package/dist/lib/puppeteer.js.map +1 -1
- package/dist/lib/ui-utils.js.map +1 -1
- package/dist/lib/utils.js +7 -4
- package/dist/lib/utils.js.map +1 -1
- package/dist/lib/yaml.js +24 -0
- package/dist/lib/yaml.js.map +1 -1
- package/dist/types/agent.d.ts +101 -8
- package/dist/types/bridge-mode-browser.d.ts +2 -3
- package/dist/types/bridge-mode.d.ts +2 -3
- package/dist/types/{browser-aec1055d.d.ts → browser-9b472ffb.d.ts} +1 -1
- package/dist/types/chrome-extension.d.ts +2 -3
- package/dist/types/index.d.ts +1 -2
- package/dist/types/midscene-server.d.ts +1 -2
- package/dist/types/{page-86ab0fe1.d.ts → page-ed0ecb44.d.ts} +19 -9
- package/dist/types/playground.d.ts +2 -3
- package/dist/types/playwright.d.ts +9 -2
- package/dist/types/puppeteer-agent-launcher.d.ts +1 -2
- package/dist/types/puppeteer.d.ts +6 -5
- package/dist/types/ui-utils.d.ts +1 -1
- package/dist/types/utils.d.ts +1 -2
- package/dist/types/yaml.d.ts +1 -2
- package/iife-script/htmlElement.js +51 -73
- package/iife-script/htmlElementDebug.js +33 -54
- package/package.json +23 -23
- package/LICENSE +0 -21
package/dist/lib/agent.js
CHANGED
@@ -139,6 +139,10 @@ var ScriptPlayer = class {
|
|
139
139
|
} else if ("aiQuery" in flowItem) {
|
140
140
|
const queryTask = flowItem;
|
141
141
|
const prompt = queryTask.aiQuery;
|
142
|
+
const options = {
|
143
|
+
domIncluded: queryTask.domIncluded,
|
144
|
+
screenshotIncluded: queryTask.screenshotIncluded
|
145
|
+
};
|
142
146
|
(0, import_utils.assert)(prompt, "missing prompt for aiQuery");
|
143
147
|
(0, import_utils.assert)(
|
144
148
|
typeof prompt === "string",
|
@@ -149,6 +153,10 @@ var ScriptPlayer = class {
|
|
149
153
|
} else if ("aiNumber" in flowItem) {
|
150
154
|
const numberTask = flowItem;
|
151
155
|
const prompt = numberTask.aiNumber;
|
156
|
+
const options = {
|
157
|
+
domIncluded: numberTask.domIncluded,
|
158
|
+
screenshotIncluded: numberTask.screenshotIncluded
|
159
|
+
};
|
152
160
|
(0, import_utils.assert)(prompt, "missing prompt for number");
|
153
161
|
(0, import_utils.assert)(
|
154
162
|
typeof prompt === "string",
|
@@ -159,6 +167,10 @@ var ScriptPlayer = class {
|
|
159
167
|
} else if ("aiString" in flowItem) {
|
160
168
|
const stringTask = flowItem;
|
161
169
|
const prompt = stringTask.aiString;
|
170
|
+
const options = {
|
171
|
+
domIncluded: stringTask.domIncluded,
|
172
|
+
screenshotIncluded: stringTask.screenshotIncluded
|
173
|
+
};
|
162
174
|
(0, import_utils.assert)(prompt, "missing prompt for string");
|
163
175
|
(0, import_utils.assert)(
|
164
176
|
typeof prompt === "string",
|
@@ -169,6 +181,10 @@ var ScriptPlayer = class {
|
|
169
181
|
} else if ("aiBoolean" in flowItem) {
|
170
182
|
const booleanTask = flowItem;
|
171
183
|
const prompt = booleanTask.aiBoolean;
|
184
|
+
const options = {
|
185
|
+
domIncluded: booleanTask.domIncluded,
|
186
|
+
screenshotIncluded: booleanTask.screenshotIncluded
|
187
|
+
};
|
172
188
|
(0, import_utils.assert)(prompt, "missing prompt for boolean");
|
173
189
|
(0, import_utils.assert)(
|
174
190
|
typeof prompt === "string",
|
@@ -211,6 +227,9 @@ var ScriptPlayer = class {
|
|
211
227
|
} else if ("aiTap" in flowItem) {
|
212
228
|
const tapTask = flowItem;
|
213
229
|
await agent.aiTap(tapTask.aiTap, tapTask);
|
230
|
+
} else if ("aiRightClick" in flowItem) {
|
231
|
+
const rightClickTask = flowItem;
|
232
|
+
await agent.aiRightClick(rightClickTask.aiRightClick, rightClickTask);
|
214
233
|
} else if ("aiHover" in flowItem) {
|
215
234
|
const hoverTask = flowItem;
|
216
235
|
await agent.aiHover(hoverTask.aiHover, hoverTask);
|
@@ -233,6 +252,11 @@ var ScriptPlayer = class {
|
|
233
252
|
evaluateJavaScriptTask.javascript
|
234
253
|
);
|
235
254
|
this.setResult(evaluateJavaScriptTask.name, result);
|
255
|
+
} else if ("logScreenshot" in flowItem) {
|
256
|
+
const logScreenshotTask = flowItem;
|
257
|
+
await agent.logScreenshot(logScreenshotTask.logScreenshot, {
|
258
|
+
content: logScreenshotTask.content || ""
|
259
|
+
});
|
236
260
|
} else {
|
237
261
|
throw new Error(`unknown flowItem: ${JSON.stringify(flowItem)}`);
|
238
262
|
}
|
@@ -481,7 +505,8 @@ var WebElementInfo = class {
|
|
481
505
|
id,
|
482
506
|
attributes,
|
483
507
|
indexId,
|
484
|
-
xpaths
|
508
|
+
xpaths,
|
509
|
+
isVisible
|
485
510
|
}) {
|
486
511
|
this.content = content;
|
487
512
|
this.rect = rect;
|
@@ -494,6 +519,7 @@ var WebElementInfo = class {
|
|
494
519
|
this.attributes = attributes;
|
495
520
|
this.indexId = indexId;
|
496
521
|
this.xpaths = xpaths;
|
522
|
+
this.isVisible = isVisible;
|
497
523
|
}
|
498
524
|
};
|
499
525
|
|
@@ -516,14 +542,15 @@ async function parseContextFromWebPage(page, _opt) {
|
|
516
542
|
})
|
517
543
|
]);
|
518
544
|
const webTree = (0, import_extractor.traverseTree)(tree, (elementInfo) => {
|
519
|
-
const { rect, id, content, attributes, locator, indexId } = elementInfo;
|
545
|
+
const { rect, id, content, attributes, locator, indexId, isVisible } = elementInfo;
|
520
546
|
return new WebElementInfo({
|
521
547
|
rect,
|
522
548
|
locator,
|
523
549
|
id,
|
524
550
|
content,
|
525
551
|
attributes,
|
526
|
-
indexId
|
552
|
+
indexId,
|
553
|
+
isVisible
|
527
554
|
});
|
528
555
|
});
|
529
556
|
(0, import_utils4.assert)(screenshotBase64, "screenshotBase64 is required");
|
@@ -553,7 +580,7 @@ function printReportMsg(filepath) {
|
|
553
580
|
(0, import_utils4.logMsg)(`Midscene - report file updated: ${filepath}`);
|
554
581
|
}
|
555
582
|
function replaceIllegalPathCharsAndSpace(str) {
|
556
|
-
return str.replace(/[
|
583
|
+
return str.replace(/[:*?"<>| ]/g, "-");
|
557
584
|
}
|
558
585
|
function matchElementFromPlan(planLocateParam, tree) {
|
559
586
|
if (!planLocateParam) {
|
@@ -582,6 +609,94 @@ var replanningCountLimit = 10;
|
|
582
609
|
var isAndroidPage = (page) => {
|
583
610
|
return page.pageType === "android";
|
584
611
|
};
|
612
|
+
var WorkflowMemory = class {
|
613
|
+
constructor(config) {
|
614
|
+
this.workflows = /* @__PURE__ */ new Map();
|
615
|
+
this.config = config;
|
616
|
+
}
|
617
|
+
/**
|
618
|
+
* İş akışı hafızasını getirir
|
619
|
+
*/
|
620
|
+
getWorkflowMemory(workflowId = "default") {
|
621
|
+
const workflow = this.workflows.get(workflowId);
|
622
|
+
return workflow?.memory || [];
|
623
|
+
}
|
624
|
+
/**
|
625
|
+
* İş akışı verilerini getirir
|
626
|
+
*/
|
627
|
+
getWorkflowData(workflowId = "default") {
|
628
|
+
return this.workflows.get(workflowId) || this.createEmptyWorkflowData(workflowId);
|
629
|
+
}
|
630
|
+
/**
|
631
|
+
* İş akışı hafızasını kaydeder
|
632
|
+
*/
|
633
|
+
saveWorkflowMemory(memory, workflowId = "default") {
|
634
|
+
const workflow = this.workflows.get(workflowId) || this.createEmptyWorkflowData(workflowId);
|
635
|
+
workflow.memory = [...memory];
|
636
|
+
workflow.metadata.totalSteps = workflow.steps.length;
|
637
|
+
workflow.metadata.completedSteps = workflow.steps.filter((s) => s.status === "completed").length;
|
638
|
+
workflow.metadata.failedSteps = workflow.steps.filter((s) => s.status === "failed").length;
|
639
|
+
this.workflows.set(workflowId, workflow);
|
640
|
+
this.enforceRetentionPolicy();
|
641
|
+
}
|
642
|
+
/**
|
643
|
+
* İş akışı bağlamını günceller
|
644
|
+
*/
|
645
|
+
updateWorkflowContext(context, workflowId = "default") {
|
646
|
+
const workflow = this.workflows.get(workflowId) || this.createEmptyWorkflowData(workflowId);
|
647
|
+
workflow.context = { ...workflow.context, ...context };
|
648
|
+
if (context.currentStep) {
|
649
|
+
const existingStep = workflow.steps.find((s) => s.stepName === context.currentStep);
|
650
|
+
if (!existingStep) {
|
651
|
+
workflow.steps.push({
|
652
|
+
stepId: `step_${workflow.steps.length + 1}`,
|
653
|
+
stepName: context.currentStep,
|
654
|
+
timestamp: context.timestamp,
|
655
|
+
status: "running",
|
656
|
+
memoryItems: []
|
657
|
+
});
|
658
|
+
}
|
659
|
+
}
|
660
|
+
this.workflows.set(workflowId, workflow);
|
661
|
+
}
|
662
|
+
/**
|
663
|
+
* İş akışını temizler
|
664
|
+
*/
|
665
|
+
clearWorkflow(workflowId = "default") {
|
666
|
+
this.workflows.delete(workflowId);
|
667
|
+
}
|
668
|
+
/**
|
669
|
+
* Tüm iş akışlarını temizler
|
670
|
+
*/
|
671
|
+
clearAll() {
|
672
|
+
this.workflows.clear();
|
673
|
+
}
|
674
|
+
createEmptyWorkflowData(workflowId) {
|
675
|
+
return {
|
676
|
+
workflowId,
|
677
|
+
steps: [],
|
678
|
+
memory: [],
|
679
|
+
context: {
|
680
|
+
pageInfo: { url: "", title: "" },
|
681
|
+
timestamp: Date.now()
|
682
|
+
},
|
683
|
+
metadata: {
|
684
|
+
totalSteps: 0,
|
685
|
+
completedSteps: 0,
|
686
|
+
failedSteps: 0,
|
687
|
+
startTime: Date.now()
|
688
|
+
}
|
689
|
+
};
|
690
|
+
}
|
691
|
+
enforceRetentionPolicy() {
|
692
|
+
const maxWorkflows = 10;
|
693
|
+
if (this.workflows.size > maxWorkflows) {
|
694
|
+
const sortedWorkflows = Array.from(this.workflows.entries()).sort(([, a], [, b]) => (b.metadata.endTime || b.metadata.startTime) - (a.metadata.endTime || a.metadata.startTime));
|
695
|
+
const toDelete = sortedWorkflows.slice(maxWorkflows);
|
696
|
+
toDelete.forEach(([workflowId]) => this.workflows.delete(workflowId));
|
697
|
+
}
|
698
|
+
}
|
699
|
+
};
|
585
700
|
var PageTaskExecutor = class {
|
586
701
|
constructor(page, insight, opts) {
|
587
702
|
this.conversationHistory = [];
|
@@ -589,6 +704,25 @@ var PageTaskExecutor = class {
|
|
589
704
|
this.insight = insight;
|
590
705
|
this.taskCache = opts.taskCache;
|
591
706
|
this.onTaskStartCallback = opts?.onTaskStart;
|
707
|
+
this.memoryConfig = {
|
708
|
+
maxItems: 100,
|
709
|
+
maxAge: 2 * 60 * 60 * 1e3,
|
710
|
+
// 2 saat
|
711
|
+
enablePersistence: true,
|
712
|
+
enableAnalytics: true,
|
713
|
+
filterStrategy: "hybrid",
|
714
|
+
...opts?.memoryConfig
|
715
|
+
};
|
716
|
+
this.sessionContext = {
|
717
|
+
sessionId: opts?.sessionId || this.generateSessionId(),
|
718
|
+
workflowId: opts?.workflowId,
|
719
|
+
startTime: Date.now(),
|
720
|
+
pageInfo: {
|
721
|
+
url: "",
|
722
|
+
title: ""
|
723
|
+
}
|
724
|
+
};
|
725
|
+
this.workflowMemory = new WorkflowMemory(this.memoryConfig);
|
592
726
|
}
|
593
727
|
async recordScreenshot(timing) {
|
594
728
|
const base64 = await this.page.screenshotBase64();
|
@@ -801,8 +935,11 @@ var PageTaskExecutor = class {
|
|
801
935
|
insightDump = dump;
|
802
936
|
};
|
803
937
|
this.insight.onceDumpUpdatedFn = dumpCollector;
|
938
|
+
const memoryContext = this.getMemoryAsContext();
|
804
939
|
const assertion = await this.insight.assert(
|
805
|
-
assertPlan.param.assertion
|
940
|
+
assertPlan.param.assertion,
|
941
|
+
memoryContext
|
942
|
+
// Hafıza bağlamını geç
|
806
943
|
);
|
807
944
|
if (!assertion.pass) {
|
808
945
|
if (plan2.type === "Assert") {
|
@@ -839,10 +976,10 @@ var PageTaskExecutor = class {
|
|
839
976
|
if (!taskParam || !taskParam.value) {
|
840
977
|
return;
|
841
978
|
}
|
842
|
-
await this.page.keyboard.type(taskParam.value);
|
843
|
-
} else {
|
844
|
-
await this.page.keyboard.type(taskParam.value);
|
845
979
|
}
|
980
|
+
await this.page.keyboard.type(taskParam.value, {
|
981
|
+
autoDismissKeyboard: taskParam.autoDismissKeyboard
|
982
|
+
});
|
846
983
|
}
|
847
984
|
};
|
848
985
|
tasks.push(taskActionInput);
|
@@ -871,6 +1008,22 @@ var PageTaskExecutor = class {
|
|
871
1008
|
}
|
872
1009
|
};
|
873
1010
|
tasks.push(taskActionTap);
|
1011
|
+
} else if (plan2.type === "RightClick") {
|
1012
|
+
const taskActionRightClick = {
|
1013
|
+
type: "Action",
|
1014
|
+
subType: "RightClick",
|
1015
|
+
thought: plan2.thought,
|
1016
|
+
locate: plan2.locate,
|
1017
|
+
executor: async (param, { element }) => {
|
1018
|
+
(0, import_utils6.assert)(element, "Element not found, cannot right click");
|
1019
|
+
await this.page.mouse.click(
|
1020
|
+
element.center[0],
|
1021
|
+
element.center[1],
|
1022
|
+
{ button: "right" }
|
1023
|
+
);
|
1024
|
+
}
|
1025
|
+
};
|
1026
|
+
tasks.push(taskActionRightClick);
|
874
1027
|
} else if (plan2.type === "Drag") {
|
875
1028
|
const taskActionDrag = {
|
876
1029
|
type: "Action",
|
@@ -1272,25 +1425,146 @@ var PageTaskExecutor = class {
|
|
1272
1425
|
};
|
1273
1426
|
return task;
|
1274
1427
|
}
|
1428
|
+
/**
|
1429
|
+
* Persistent executor'ı getirir veya oluşturur
|
1430
|
+
*/
|
1431
|
+
getPersistentExecutor() {
|
1432
|
+
if (!this.persistentExecutor || this.persistentExecutor.status === "error") {
|
1433
|
+
const previousMemory = this.workflowMemory.getWorkflowMemory(this.sessionContext.workflowId);
|
1434
|
+
this.persistentExecutor = new import_misoai_core.Executor("Persistent Task Executor", {
|
1435
|
+
onTaskStart: this.onTaskStartCallback,
|
1436
|
+
initialMemory: previousMemory
|
1437
|
+
});
|
1438
|
+
}
|
1439
|
+
return this.persistentExecutor;
|
1440
|
+
}
|
1441
|
+
/**
|
1442
|
+
* Sayfa bağlamını günceller
|
1443
|
+
*/
|
1444
|
+
async updatePageContext() {
|
1445
|
+
try {
|
1446
|
+
if (this.page.url) {
|
1447
|
+
this.sessionContext.pageInfo.url = await this.page.url();
|
1448
|
+
}
|
1449
|
+
if (this.page.pageType === "puppeteer" || this.page.pageType === "playwright") {
|
1450
|
+
this.sessionContext.pageInfo.title = await this.page.title();
|
1451
|
+
}
|
1452
|
+
} catch (e) {
|
1453
|
+
}
|
1454
|
+
}
|
1455
|
+
/**
|
1456
|
+
* Hafızayı temizler
|
1457
|
+
*/
|
1458
|
+
clearMemory() {
|
1459
|
+
if (this.persistentExecutor) {
|
1460
|
+
this.persistentExecutor.clearMemory();
|
1461
|
+
}
|
1462
|
+
this.workflowMemory.clearWorkflow(this.sessionContext.workflowId || "default");
|
1463
|
+
}
|
1464
|
+
/**
|
1465
|
+
* Mevcut hafızayı döndürür
|
1466
|
+
*/
|
1467
|
+
getMemory() {
|
1468
|
+
return this.persistentExecutor?.getMemory() || [];
|
1469
|
+
}
|
1470
|
+
/**
|
1471
|
+
* İş akışı hafızasını döndürür
|
1472
|
+
*/
|
1473
|
+
getWorkflowMemory() {
|
1474
|
+
return this.workflowMemory.getWorkflowData(this.sessionContext.workflowId || "default");
|
1475
|
+
}
|
1476
|
+
/**
|
1477
|
+
* Hafıza istatistiklerini döndürür
|
1478
|
+
*/
|
1479
|
+
getMemoryStats() {
|
1480
|
+
return this.persistentExecutor?.getMemoryStats() || {
|
1481
|
+
totalItems: 0,
|
1482
|
+
analytics: { totalTasks: 0, memoryHits: 0, memoryMisses: 0, averageMemorySize: 0, memoryEffectiveness: 0 },
|
1483
|
+
config: this.memoryConfig
|
1484
|
+
};
|
1485
|
+
}
|
1486
|
+
/**
|
1487
|
+
* Hafıza konfigürasyonunu günceller
|
1488
|
+
*/
|
1489
|
+
updateMemoryConfig(config) {
|
1490
|
+
this.memoryConfig = { ...this.memoryConfig, ...config };
|
1491
|
+
if (this.persistentExecutor) {
|
1492
|
+
this.persistentExecutor.updateMemoryConfig(this.memoryConfig);
|
1493
|
+
}
|
1494
|
+
}
|
1495
|
+
/**
|
1496
|
+
* Oturum ID'sini oluşturur
|
1497
|
+
*/
|
1498
|
+
generateSessionId() {
|
1499
|
+
return `session_${Date.now()}_${Math.random().toString(36).substr(2, 8)}`;
|
1500
|
+
}
|
1501
|
+
/**
|
1502
|
+
* Hafızayı bağlam olarak formatlar
|
1503
|
+
*/
|
1504
|
+
getMemoryAsContext() {
|
1505
|
+
const memory = this.getMemory();
|
1506
|
+
if (memory.length === 0) {
|
1507
|
+
return "";
|
1508
|
+
}
|
1509
|
+
const recentMemory = memory.slice(-5);
|
1510
|
+
return recentMemory.map((item) => `- ${item.summary}`).join("\n");
|
1511
|
+
}
|
1275
1512
|
async runPlans(title, plans, opts) {
|
1276
|
-
|
1277
|
-
|
1278
|
-
|
1513
|
+
await this.updatePageContext();
|
1514
|
+
const useMemory = opts?.useMemory !== false;
|
1515
|
+
let taskExecutor;
|
1516
|
+
if (useMemory) {
|
1517
|
+
taskExecutor = this.getPersistentExecutor();
|
1518
|
+
this.workflowMemory.updateWorkflowContext({
|
1519
|
+
currentStep: title,
|
1520
|
+
pageInfo: this.sessionContext.pageInfo,
|
1521
|
+
timestamp: Date.now()
|
1522
|
+
}, this.sessionContext.workflowId || "default");
|
1523
|
+
} else {
|
1524
|
+
taskExecutor = new import_misoai_core.Executor(title, {
|
1525
|
+
onTaskStart: this.onTaskStartCallback
|
1526
|
+
});
|
1527
|
+
}
|
1279
1528
|
const { tasks } = await this.convertPlanToExecutable(plans, opts);
|
1529
|
+
tasks.forEach((task) => {
|
1530
|
+
task.context = {
|
1531
|
+
...task.context,
|
1532
|
+
...this.sessionContext.pageInfo,
|
1533
|
+
workflowId: this.sessionContext.workflowId,
|
1534
|
+
sessionId: this.sessionContext.sessionId
|
1535
|
+
};
|
1536
|
+
});
|
1280
1537
|
await taskExecutor.append(tasks);
|
1281
1538
|
const result = await taskExecutor.flush();
|
1539
|
+
if (useMemory) {
|
1540
|
+
this.workflowMemory.saveWorkflowMemory(
|
1541
|
+
taskExecutor.getMemory(),
|
1542
|
+
this.sessionContext.workflowId || "default"
|
1543
|
+
);
|
1544
|
+
}
|
1282
1545
|
return {
|
1283
1546
|
output: result,
|
1284
1547
|
executor: taskExecutor
|
1285
1548
|
};
|
1286
1549
|
}
|
1287
1550
|
async action(userPrompt, actionContext, opts) {
|
1288
|
-
const
|
1289
|
-
|
1290
|
-
|
1291
|
-
|
1551
|
+
const useMemory = true;
|
1552
|
+
let taskExecutor;
|
1553
|
+
if (useMemory) {
|
1554
|
+
taskExecutor = this.getPersistentExecutor();
|
1555
|
+
} else {
|
1556
|
+
taskExecutor = new import_misoai_core.Executor(taskTitleStr("Action", userPrompt), {
|
1557
|
+
onTaskStart: this.onTaskStartCallback
|
1558
|
+
});
|
1559
|
+
}
|
1560
|
+
const memoryContext = this.getMemoryAsContext();
|
1561
|
+
const initialLog = memoryContext ? memoryContext : void 0;
|
1562
|
+
let planningTask = this.planningTaskFromPrompt(userPrompt, initialLog, actionContext);
|
1292
1563
|
let replanCount = 0;
|
1293
1564
|
const logList = [];
|
1565
|
+
if (memoryContext) {
|
1566
|
+
logList.push(memoryContext);
|
1567
|
+
}
|
1294
1568
|
const yamlFlow = [];
|
1295
1569
|
while (planningTask) {
|
1296
1570
|
if (replanCount > replanningCountLimit) {
|
@@ -1399,16 +1673,22 @@ var PageTaskExecutor = class {
|
|
1399
1673
|
executor: taskExecutor
|
1400
1674
|
};
|
1401
1675
|
}
|
1402
|
-
async createTypeQueryTask(type, demand) {
|
1403
|
-
const
|
1404
|
-
|
1405
|
-
|
1406
|
-
|
1407
|
-
|
1408
|
-
|
1409
|
-
|
1410
|
-
|
1411
|
-
|
1676
|
+
async createTypeQueryTask(type, demand, opt) {
|
1677
|
+
const useMemory = true;
|
1678
|
+
let taskExecutor;
|
1679
|
+
if (useMemory) {
|
1680
|
+
taskExecutor = this.getPersistentExecutor();
|
1681
|
+
} else {
|
1682
|
+
taskExecutor = new import_misoai_core.Executor(
|
1683
|
+
taskTitleStr(
|
1684
|
+
type,
|
1685
|
+
typeof demand === "string" ? demand : JSON.stringify(demand)
|
1686
|
+
),
|
1687
|
+
{
|
1688
|
+
onTaskStart: this.onTaskStartCallback
|
1689
|
+
}
|
1690
|
+
);
|
1691
|
+
}
|
1412
1692
|
const queryTask = {
|
1413
1693
|
type: "Insight",
|
1414
1694
|
subType: type,
|
@@ -1430,7 +1710,13 @@ var PageTaskExecutor = class {
|
|
1430
1710
|
result: `${type}, ${demand}`
|
1431
1711
|
};
|
1432
1712
|
}
|
1433
|
-
const
|
1713
|
+
const memoryContext = this.getMemoryAsContext();
|
1714
|
+
const { data, usage } = await this.insight.extract(
|
1715
|
+
demandInput,
|
1716
|
+
opt,
|
1717
|
+
memoryContext
|
1718
|
+
// Hafıza bağlamını geç
|
1719
|
+
);
|
1434
1720
|
let outputResult = data;
|
1435
1721
|
if (ifTypeRestricted) {
|
1436
1722
|
(0, import_utils6.assert)(data?.result !== void 0, "No result in query data");
|
@@ -1450,23 +1736,29 @@ var PageTaskExecutor = class {
|
|
1450
1736
|
executor: taskExecutor
|
1451
1737
|
};
|
1452
1738
|
}
|
1453
|
-
async query(demand) {
|
1454
|
-
return this.createTypeQueryTask("Query", demand);
|
1739
|
+
async query(demand, opt) {
|
1740
|
+
return this.createTypeQueryTask("Query", demand, opt);
|
1455
1741
|
}
|
1456
|
-
async boolean(prompt) {
|
1457
|
-
return this.createTypeQueryTask("Boolean", prompt);
|
1742
|
+
async boolean(prompt, opt) {
|
1743
|
+
return this.createTypeQueryTask("Boolean", prompt, opt);
|
1458
1744
|
}
|
1459
|
-
async number(prompt) {
|
1460
|
-
return this.createTypeQueryTask("Number", prompt);
|
1745
|
+
async number(prompt, opt) {
|
1746
|
+
return this.createTypeQueryTask("Number", prompt, opt);
|
1461
1747
|
}
|
1462
|
-
async string(prompt) {
|
1463
|
-
return this.createTypeQueryTask("String", prompt);
|
1748
|
+
async string(prompt, opt) {
|
1749
|
+
return this.createTypeQueryTask("String", prompt, opt);
|
1464
1750
|
}
|
1465
|
-
async assert(assertion) {
|
1751
|
+
async assert(assertion, memoryContext) {
|
1466
1752
|
const description = `assert: ${assertion}`;
|
1467
|
-
const
|
1468
|
-
|
1469
|
-
|
1753
|
+
const useMemory = true;
|
1754
|
+
let taskExecutor;
|
1755
|
+
if (useMemory) {
|
1756
|
+
taskExecutor = this.getPersistentExecutor();
|
1757
|
+
} else {
|
1758
|
+
taskExecutor = new import_misoai_core.Executor(taskTitleStr("Assert", description), {
|
1759
|
+
onTaskStart: this.onTaskStartCallback
|
1760
|
+
});
|
1761
|
+
}
|
1470
1762
|
const assertionPlan = {
|
1471
1763
|
type: "Assert",
|
1472
1764
|
param: {
|
@@ -1596,7 +1888,7 @@ function buildPlans(type, locateParam, param) {
|
|
1596
1888
|
param: locateParam,
|
1597
1889
|
thought: ""
|
1598
1890
|
} : null;
|
1599
|
-
if (type === "Tap" || type === "Hover") {
|
1891
|
+
if (type === "Tap" || type === "Hover" || type === "RightClick") {
|
1600
1892
|
(0, import_utils8.assert)(locateParam, `missing locate info for action "${type}"`);
|
1601
1893
|
(0, import_utils8.assert)(locatePlan, `missing locate info for action "${type}"`);
|
1602
1894
|
const tapPlan = {
|
@@ -1676,7 +1968,7 @@ var import_js_yaml3 = __toESM(require("js-yaml"));
|
|
1676
1968
|
var import_semver = __toESM(require("semver"));
|
1677
1969
|
|
1678
1970
|
// package.json
|
1679
|
-
var version = "1.5.
|
1971
|
+
var version = "1.5.7";
|
1680
1972
|
|
1681
1973
|
// src/common/task-cache.ts
|
1682
1974
|
var debug3 = (0, import_logger3.getDebug)("cache");
|
@@ -1807,8 +2099,14 @@ cache file: ${cacheFile}`
|
|
1807
2099
|
return;
|
1808
2100
|
}
|
1809
2101
|
try {
|
2102
|
+
const dir = (0, import_node_path2.dirname)(this.cacheFilePath);
|
2103
|
+
if (!(0, import_node_fs2.existsSync)(dir)) {
|
2104
|
+
(0, import_node_fs2.mkdirSync)(dir, { recursive: true });
|
2105
|
+
debug3("created cache directory: %s", dir);
|
2106
|
+
}
|
1810
2107
|
const yamlData = import_js_yaml3.default.dump(this.cache);
|
1811
2108
|
(0, import_node_fs2.writeFileSync)(this.cacheFilePath, yamlData);
|
2109
|
+
debug3("cache flushed to file: %s", this.cacheFilePath);
|
1812
2110
|
} catch (err) {
|
1813
2111
|
debug3(
|
1814
2112
|
"write cache to file failed, path: %s, error: %s",
|
@@ -2066,6 +2364,23 @@ var PageAgent = class {
|
|
2066
2364
|
metadata
|
2067
2365
|
};
|
2068
2366
|
}
|
2367
|
+
async aiRightClick(locatePrompt, opt) {
|
2368
|
+
const detailedLocateParam = this.buildDetailedLocateParam(
|
2369
|
+
locatePrompt,
|
2370
|
+
opt
|
2371
|
+
);
|
2372
|
+
const plans = buildPlans("RightClick", detailedLocateParam);
|
2373
|
+
const { executor, output } = await this.taskExecutor.runPlans(
|
2374
|
+
taskTitleStr("RightClick", locateParamStr(detailedLocateParam)),
|
2375
|
+
plans,
|
2376
|
+
{ cacheable: opt?.cacheable }
|
2377
|
+
);
|
2378
|
+
const metadata = this.afterTaskRunning(executor);
|
2379
|
+
return {
|
2380
|
+
result: output,
|
2381
|
+
metadata
|
2382
|
+
};
|
2383
|
+
}
|
2069
2384
|
async aiInput(value, locatePrompt, opt) {
|
2070
2385
|
(0, import_utils12.assert)(
|
2071
2386
|
typeof value === "string",
|
@@ -2140,7 +2455,13 @@ var PageAgent = class {
|
|
2140
2455
|
metadata: metadata2
|
2141
2456
|
};
|
2142
2457
|
}
|
2143
|
-
const
|
2458
|
+
const memoryContext = this.getMemoryAsContext();
|
2459
|
+
const enhancedActionContext = this.opts.aiActionContext ? `${this.opts.aiActionContext}
|
2460
|
+
|
2461
|
+
Previous workflow steps:
|
2462
|
+
${memoryContext}` : memoryContext ? `Previous workflow steps:
|
2463
|
+
${memoryContext}` : void 0;
|
2464
|
+
const { output, executor } = await (isVlmUiTars ? this.taskExecutor.actionToGoal(taskPrompt, { cacheable }) : this.taskExecutor.action(taskPrompt, enhancedActionContext, {
|
2144
2465
|
cacheable
|
2145
2466
|
}));
|
2146
2467
|
if (this.taskCache && output?.yamlFlow && cacheable !== false) {
|
@@ -2286,8 +2607,9 @@ var PageAgent = class {
|
|
2286
2607
|
} catch (e) {
|
2287
2608
|
}
|
2288
2609
|
}
|
2610
|
+
const memoryContext = this.getMemoryAsContext();
|
2289
2611
|
const assertionWithContext = currentUrl ? `For the page at URL "${currentUrl}", ${assertion}` : assertion;
|
2290
|
-
const { output, executor } = await this.taskExecutor.assert(assertionWithContext);
|
2612
|
+
const { output, executor } = await this.taskExecutor.assert(assertionWithContext, memoryContext);
|
2291
2613
|
const metadata = this.afterTaskRunning(executor, true);
|
2292
2614
|
if (output && opt?.keepRawResponse) {
|
2293
2615
|
return {
|
@@ -2497,9 +2819,72 @@ ${errors}`);
|
|
2497
2819
|
}
|
2498
2820
|
throw new Error("evaluateJavaScript is not supported in current agent");
|
2499
2821
|
}
|
2822
|
+
async logScreenshot(title, options) {
|
2823
|
+
const screenshotTitle = title || "untitled";
|
2824
|
+
const content = options?.content || "";
|
2825
|
+
const screenshot = await this.page.screenshotBase64?.();
|
2826
|
+
if (screenshot) {
|
2827
|
+
const executionDump = {
|
2828
|
+
name: screenshotTitle,
|
2829
|
+
description: content,
|
2830
|
+
tasks: [{
|
2831
|
+
type: "Screenshot",
|
2832
|
+
subType: "log",
|
2833
|
+
status: "finished",
|
2834
|
+
executor: null,
|
2835
|
+
param: {
|
2836
|
+
title: screenshotTitle,
|
2837
|
+
content
|
2838
|
+
},
|
2839
|
+
output: {
|
2840
|
+
screenshot
|
2841
|
+
},
|
2842
|
+
thought: `Logged screenshot: ${screenshotTitle}`,
|
2843
|
+
timing: {
|
2844
|
+
start: Date.now(),
|
2845
|
+
end: Date.now(),
|
2846
|
+
cost: 0
|
2847
|
+
}
|
2848
|
+
}],
|
2849
|
+
sdkVersion: "1.0.0",
|
2850
|
+
logTime: Date.now(),
|
2851
|
+
model_name: "screenshot"
|
2852
|
+
};
|
2853
|
+
this.appendExecutionDump(executionDump);
|
2854
|
+
}
|
2855
|
+
}
|
2500
2856
|
async destroy() {
|
2501
2857
|
await this.page.destroy();
|
2502
2858
|
}
|
2859
|
+
/**
|
2860
|
+
* Hafızayı bağlam olarak formatlar
|
2861
|
+
*/
|
2862
|
+
getMemoryAsContext() {
|
2863
|
+
const memory = this.taskExecutor.getMemory();
|
2864
|
+
if (memory.length === 0) {
|
2865
|
+
return "";
|
2866
|
+
}
|
2867
|
+
const recentMemory = memory.slice(-5);
|
2868
|
+
return recentMemory.map((item) => `- ${item.summary}`).join("\n");
|
2869
|
+
}
|
2870
|
+
/**
|
2871
|
+
* Mevcut hafızayı döndürür
|
2872
|
+
*/
|
2873
|
+
getMemory() {
|
2874
|
+
return this.taskExecutor.getMemory();
|
2875
|
+
}
|
2876
|
+
/**
|
2877
|
+
* Hafıza istatistiklerini döndürür
|
2878
|
+
*/
|
2879
|
+
getMemoryStats() {
|
2880
|
+
return this.taskExecutor.getMemoryStats();
|
2881
|
+
}
|
2882
|
+
/**
|
2883
|
+
* Hafızayı temizler
|
2884
|
+
*/
|
2885
|
+
clearMemory() {
|
2886
|
+
this.taskExecutor.clearMemory();
|
2887
|
+
}
|
2503
2888
|
};
|
2504
2889
|
// Annotate the CommonJS export names for ESM import in node:
|
2505
2890
|
0 && (module.exports = {
|