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
@@ -41,7 +41,8 @@ var WebElementInfo = class {
|
|
41
41
|
id,
|
42
42
|
attributes,
|
43
43
|
indexId,
|
44
|
-
xpaths
|
44
|
+
xpaths,
|
45
|
+
isVisible
|
45
46
|
}) {
|
46
47
|
this.content = content;
|
47
48
|
this.rect = rect;
|
@@ -54,6 +55,7 @@ var WebElementInfo = class {
|
|
54
55
|
this.attributes = attributes;
|
55
56
|
this.indexId = indexId;
|
56
57
|
this.xpaths = xpaths;
|
58
|
+
this.isVisible = isVisible;
|
57
59
|
}
|
58
60
|
};
|
59
61
|
|
@@ -76,14 +78,15 @@ async function parseContextFromWebPage(page, _opt) {
|
|
76
78
|
})
|
77
79
|
]);
|
78
80
|
const webTree = (0, import_extractor.traverseTree)(tree, (elementInfo) => {
|
79
|
-
const { rect, id, content, attributes, locator, indexId } = elementInfo;
|
81
|
+
const { rect, id, content, attributes, locator, indexId, isVisible } = elementInfo;
|
80
82
|
return new WebElementInfo({
|
81
83
|
rect,
|
82
84
|
locator,
|
83
85
|
id,
|
84
86
|
content,
|
85
87
|
attributes,
|
86
|
-
indexId
|
88
|
+
indexId,
|
89
|
+
isVisible
|
87
90
|
});
|
88
91
|
});
|
89
92
|
(0, import_utils2.assert)(screenshotBase64, "screenshotBase64 is required");
|
@@ -114,7 +117,7 @@ function printReportMsg(filepath) {
|
|
114
117
|
}
|
115
118
|
var ERROR_CODE_NOT_IMPLEMENTED_AS_DESIGNED = "NOT_IMPLEMENTED_AS_DESIGNED";
|
116
119
|
function replaceIllegalPathCharsAndSpace(str) {
|
117
|
-
return str.replace(/[
|
120
|
+
return str.replace(/[:*?"<>| ]/g, "-");
|
118
121
|
}
|
119
122
|
function matchElementFromPlan(planLocateParam, tree) {
|
120
123
|
if (!planLocateParam) {
|
@@ -244,6 +247,10 @@ var ScriptPlayer = class {
|
|
244
247
|
} else if ("aiQuery" in flowItem) {
|
245
248
|
const queryTask = flowItem;
|
246
249
|
const prompt = queryTask.aiQuery;
|
250
|
+
const options = {
|
251
|
+
domIncluded: queryTask.domIncluded,
|
252
|
+
screenshotIncluded: queryTask.screenshotIncluded
|
253
|
+
};
|
247
254
|
(0, import_utils3.assert)(prompt, "missing prompt for aiQuery");
|
248
255
|
(0, import_utils3.assert)(
|
249
256
|
typeof prompt === "string",
|
@@ -254,6 +261,10 @@ var ScriptPlayer = class {
|
|
254
261
|
} else if ("aiNumber" in flowItem) {
|
255
262
|
const numberTask = flowItem;
|
256
263
|
const prompt = numberTask.aiNumber;
|
264
|
+
const options = {
|
265
|
+
domIncluded: numberTask.domIncluded,
|
266
|
+
screenshotIncluded: numberTask.screenshotIncluded
|
267
|
+
};
|
257
268
|
(0, import_utils3.assert)(prompt, "missing prompt for number");
|
258
269
|
(0, import_utils3.assert)(
|
259
270
|
typeof prompt === "string",
|
@@ -264,6 +275,10 @@ var ScriptPlayer = class {
|
|
264
275
|
} else if ("aiString" in flowItem) {
|
265
276
|
const stringTask = flowItem;
|
266
277
|
const prompt = stringTask.aiString;
|
278
|
+
const options = {
|
279
|
+
domIncluded: stringTask.domIncluded,
|
280
|
+
screenshotIncluded: stringTask.screenshotIncluded
|
281
|
+
};
|
267
282
|
(0, import_utils3.assert)(prompt, "missing prompt for string");
|
268
283
|
(0, import_utils3.assert)(
|
269
284
|
typeof prompt === "string",
|
@@ -274,6 +289,10 @@ var ScriptPlayer = class {
|
|
274
289
|
} else if ("aiBoolean" in flowItem) {
|
275
290
|
const booleanTask = flowItem;
|
276
291
|
const prompt = booleanTask.aiBoolean;
|
292
|
+
const options = {
|
293
|
+
domIncluded: booleanTask.domIncluded,
|
294
|
+
screenshotIncluded: booleanTask.screenshotIncluded
|
295
|
+
};
|
277
296
|
(0, import_utils3.assert)(prompt, "missing prompt for boolean");
|
278
297
|
(0, import_utils3.assert)(
|
279
298
|
typeof prompt === "string",
|
@@ -316,6 +335,9 @@ var ScriptPlayer = class {
|
|
316
335
|
} else if ("aiTap" in flowItem) {
|
317
336
|
const tapTask = flowItem;
|
318
337
|
await agent.aiTap(tapTask.aiTap, tapTask);
|
338
|
+
} else if ("aiRightClick" in flowItem) {
|
339
|
+
const rightClickTask = flowItem;
|
340
|
+
await agent.aiRightClick(rightClickTask.aiRightClick, rightClickTask);
|
319
341
|
} else if ("aiHover" in flowItem) {
|
320
342
|
const hoverTask = flowItem;
|
321
343
|
await agent.aiHover(hoverTask.aiHover, hoverTask);
|
@@ -338,6 +360,11 @@ var ScriptPlayer = class {
|
|
338
360
|
evaluateJavaScriptTask.javascript
|
339
361
|
);
|
340
362
|
this.setResult(evaluateJavaScriptTask.name, result);
|
363
|
+
} else if ("logScreenshot" in flowItem) {
|
364
|
+
const logScreenshotTask = flowItem;
|
365
|
+
await agent.logScreenshot(logScreenshotTask.logScreenshot, {
|
366
|
+
content: logScreenshotTask.content || ""
|
367
|
+
});
|
341
368
|
} else {
|
342
369
|
throw new Error(`unknown flowItem: ${JSON.stringify(flowItem)}`);
|
343
370
|
}
|
@@ -573,6 +600,94 @@ var replanningCountLimit = 10;
|
|
573
600
|
var isAndroidPage = (page) => {
|
574
601
|
return page.pageType === "android";
|
575
602
|
};
|
603
|
+
var WorkflowMemory = class {
|
604
|
+
constructor(config) {
|
605
|
+
this.workflows = /* @__PURE__ */ new Map();
|
606
|
+
this.config = config;
|
607
|
+
}
|
608
|
+
/**
|
609
|
+
* İş akışı hafızasını getirir
|
610
|
+
*/
|
611
|
+
getWorkflowMemory(workflowId = "default") {
|
612
|
+
const workflow = this.workflows.get(workflowId);
|
613
|
+
return workflow?.memory || [];
|
614
|
+
}
|
615
|
+
/**
|
616
|
+
* İş akışı verilerini getirir
|
617
|
+
*/
|
618
|
+
getWorkflowData(workflowId = "default") {
|
619
|
+
return this.workflows.get(workflowId) || this.createEmptyWorkflowData(workflowId);
|
620
|
+
}
|
621
|
+
/**
|
622
|
+
* İş akışı hafızasını kaydeder
|
623
|
+
*/
|
624
|
+
saveWorkflowMemory(memory, workflowId = "default") {
|
625
|
+
const workflow = this.workflows.get(workflowId) || this.createEmptyWorkflowData(workflowId);
|
626
|
+
workflow.memory = [...memory];
|
627
|
+
workflow.metadata.totalSteps = workflow.steps.length;
|
628
|
+
workflow.metadata.completedSteps = workflow.steps.filter((s) => s.status === "completed").length;
|
629
|
+
workflow.metadata.failedSteps = workflow.steps.filter((s) => s.status === "failed").length;
|
630
|
+
this.workflows.set(workflowId, workflow);
|
631
|
+
this.enforceRetentionPolicy();
|
632
|
+
}
|
633
|
+
/**
|
634
|
+
* İş akışı bağlamını günceller
|
635
|
+
*/
|
636
|
+
updateWorkflowContext(context, workflowId = "default") {
|
637
|
+
const workflow = this.workflows.get(workflowId) || this.createEmptyWorkflowData(workflowId);
|
638
|
+
workflow.context = { ...workflow.context, ...context };
|
639
|
+
if (context.currentStep) {
|
640
|
+
const existingStep = workflow.steps.find((s) => s.stepName === context.currentStep);
|
641
|
+
if (!existingStep) {
|
642
|
+
workflow.steps.push({
|
643
|
+
stepId: `step_${workflow.steps.length + 1}`,
|
644
|
+
stepName: context.currentStep,
|
645
|
+
timestamp: context.timestamp,
|
646
|
+
status: "running",
|
647
|
+
memoryItems: []
|
648
|
+
});
|
649
|
+
}
|
650
|
+
}
|
651
|
+
this.workflows.set(workflowId, workflow);
|
652
|
+
}
|
653
|
+
/**
|
654
|
+
* İş akışını temizler
|
655
|
+
*/
|
656
|
+
clearWorkflow(workflowId = "default") {
|
657
|
+
this.workflows.delete(workflowId);
|
658
|
+
}
|
659
|
+
/**
|
660
|
+
* Tüm iş akışlarını temizler
|
661
|
+
*/
|
662
|
+
clearAll() {
|
663
|
+
this.workflows.clear();
|
664
|
+
}
|
665
|
+
createEmptyWorkflowData(workflowId) {
|
666
|
+
return {
|
667
|
+
workflowId,
|
668
|
+
steps: [],
|
669
|
+
memory: [],
|
670
|
+
context: {
|
671
|
+
pageInfo: { url: "", title: "" },
|
672
|
+
timestamp: Date.now()
|
673
|
+
},
|
674
|
+
metadata: {
|
675
|
+
totalSteps: 0,
|
676
|
+
completedSteps: 0,
|
677
|
+
failedSteps: 0,
|
678
|
+
startTime: Date.now()
|
679
|
+
}
|
680
|
+
};
|
681
|
+
}
|
682
|
+
enforceRetentionPolicy() {
|
683
|
+
const maxWorkflows = 10;
|
684
|
+
if (this.workflows.size > maxWorkflows) {
|
685
|
+
const sortedWorkflows = Array.from(this.workflows.entries()).sort(([, a], [, b]) => (b.metadata.endTime || b.metadata.startTime) - (a.metadata.endTime || a.metadata.startTime));
|
686
|
+
const toDelete = sortedWorkflows.slice(maxWorkflows);
|
687
|
+
toDelete.forEach(([workflowId]) => this.workflows.delete(workflowId));
|
688
|
+
}
|
689
|
+
}
|
690
|
+
};
|
576
691
|
var PageTaskExecutor = class {
|
577
692
|
constructor(page, insight, opts) {
|
578
693
|
this.conversationHistory = [];
|
@@ -580,6 +695,25 @@ var PageTaskExecutor = class {
|
|
580
695
|
this.insight = insight;
|
581
696
|
this.taskCache = opts.taskCache;
|
582
697
|
this.onTaskStartCallback = opts?.onTaskStart;
|
698
|
+
this.memoryConfig = {
|
699
|
+
maxItems: 100,
|
700
|
+
maxAge: 2 * 60 * 60 * 1e3,
|
701
|
+
// 2 saat
|
702
|
+
enablePersistence: true,
|
703
|
+
enableAnalytics: true,
|
704
|
+
filterStrategy: "hybrid",
|
705
|
+
...opts?.memoryConfig
|
706
|
+
};
|
707
|
+
this.sessionContext = {
|
708
|
+
sessionId: opts?.sessionId || this.generateSessionId(),
|
709
|
+
workflowId: opts?.workflowId,
|
710
|
+
startTime: Date.now(),
|
711
|
+
pageInfo: {
|
712
|
+
url: "",
|
713
|
+
title: ""
|
714
|
+
}
|
715
|
+
};
|
716
|
+
this.workflowMemory = new WorkflowMemory(this.memoryConfig);
|
583
717
|
}
|
584
718
|
async recordScreenshot(timing) {
|
585
719
|
const base64 = await this.page.screenshotBase64();
|
@@ -792,8 +926,11 @@ var PageTaskExecutor = class {
|
|
792
926
|
insightDump = dump;
|
793
927
|
};
|
794
928
|
this.insight.onceDumpUpdatedFn = dumpCollector;
|
929
|
+
const memoryContext = this.getMemoryAsContext();
|
795
930
|
const assertion = await this.insight.assert(
|
796
|
-
assertPlan.param.assertion
|
931
|
+
assertPlan.param.assertion,
|
932
|
+
memoryContext
|
933
|
+
// Hafıza bağlamını geç
|
797
934
|
);
|
798
935
|
if (!assertion.pass) {
|
799
936
|
if (plan2.type === "Assert") {
|
@@ -830,10 +967,10 @@ var PageTaskExecutor = class {
|
|
830
967
|
if (!taskParam || !taskParam.value) {
|
831
968
|
return;
|
832
969
|
}
|
833
|
-
await this.page.keyboard.type(taskParam.value);
|
834
|
-
} else {
|
835
|
-
await this.page.keyboard.type(taskParam.value);
|
836
970
|
}
|
971
|
+
await this.page.keyboard.type(taskParam.value, {
|
972
|
+
autoDismissKeyboard: taskParam.autoDismissKeyboard
|
973
|
+
});
|
837
974
|
}
|
838
975
|
};
|
839
976
|
tasks.push(taskActionInput);
|
@@ -862,6 +999,22 @@ var PageTaskExecutor = class {
|
|
862
999
|
}
|
863
1000
|
};
|
864
1001
|
tasks.push(taskActionTap);
|
1002
|
+
} else if (plan2.type === "RightClick") {
|
1003
|
+
const taskActionRightClick = {
|
1004
|
+
type: "Action",
|
1005
|
+
subType: "RightClick",
|
1006
|
+
thought: plan2.thought,
|
1007
|
+
locate: plan2.locate,
|
1008
|
+
executor: async (param, { element }) => {
|
1009
|
+
(0, import_utils6.assert)(element, "Element not found, cannot right click");
|
1010
|
+
await this.page.mouse.click(
|
1011
|
+
element.center[0],
|
1012
|
+
element.center[1],
|
1013
|
+
{ button: "right" }
|
1014
|
+
);
|
1015
|
+
}
|
1016
|
+
};
|
1017
|
+
tasks.push(taskActionRightClick);
|
865
1018
|
} else if (plan2.type === "Drag") {
|
866
1019
|
const taskActionDrag = {
|
867
1020
|
type: "Action",
|
@@ -1263,25 +1416,146 @@ var PageTaskExecutor = class {
|
|
1263
1416
|
};
|
1264
1417
|
return task;
|
1265
1418
|
}
|
1419
|
+
/**
|
1420
|
+
* Persistent executor'ı getirir veya oluşturur
|
1421
|
+
*/
|
1422
|
+
getPersistentExecutor() {
|
1423
|
+
if (!this.persistentExecutor || this.persistentExecutor.status === "error") {
|
1424
|
+
const previousMemory = this.workflowMemory.getWorkflowMemory(this.sessionContext.workflowId);
|
1425
|
+
this.persistentExecutor = new import_misoai_core.Executor("Persistent Task Executor", {
|
1426
|
+
onTaskStart: this.onTaskStartCallback,
|
1427
|
+
initialMemory: previousMemory
|
1428
|
+
});
|
1429
|
+
}
|
1430
|
+
return this.persistentExecutor;
|
1431
|
+
}
|
1432
|
+
/**
|
1433
|
+
* Sayfa bağlamını günceller
|
1434
|
+
*/
|
1435
|
+
async updatePageContext() {
|
1436
|
+
try {
|
1437
|
+
if (this.page.url) {
|
1438
|
+
this.sessionContext.pageInfo.url = await this.page.url();
|
1439
|
+
}
|
1440
|
+
if (this.page.pageType === "puppeteer" || this.page.pageType === "playwright") {
|
1441
|
+
this.sessionContext.pageInfo.title = await this.page.title();
|
1442
|
+
}
|
1443
|
+
} catch (e) {
|
1444
|
+
}
|
1445
|
+
}
|
1446
|
+
/**
|
1447
|
+
* Hafızayı temizler
|
1448
|
+
*/
|
1449
|
+
clearMemory() {
|
1450
|
+
if (this.persistentExecutor) {
|
1451
|
+
this.persistentExecutor.clearMemory();
|
1452
|
+
}
|
1453
|
+
this.workflowMemory.clearWorkflow(this.sessionContext.workflowId || "default");
|
1454
|
+
}
|
1455
|
+
/**
|
1456
|
+
* Mevcut hafızayı döndürür
|
1457
|
+
*/
|
1458
|
+
getMemory() {
|
1459
|
+
return this.persistentExecutor?.getMemory() || [];
|
1460
|
+
}
|
1461
|
+
/**
|
1462
|
+
* İş akışı hafızasını döndürür
|
1463
|
+
*/
|
1464
|
+
getWorkflowMemory() {
|
1465
|
+
return this.workflowMemory.getWorkflowData(this.sessionContext.workflowId || "default");
|
1466
|
+
}
|
1467
|
+
/**
|
1468
|
+
* Hafıza istatistiklerini döndürür
|
1469
|
+
*/
|
1470
|
+
getMemoryStats() {
|
1471
|
+
return this.persistentExecutor?.getMemoryStats() || {
|
1472
|
+
totalItems: 0,
|
1473
|
+
analytics: { totalTasks: 0, memoryHits: 0, memoryMisses: 0, averageMemorySize: 0, memoryEffectiveness: 0 },
|
1474
|
+
config: this.memoryConfig
|
1475
|
+
};
|
1476
|
+
}
|
1477
|
+
/**
|
1478
|
+
* Hafıza konfigürasyonunu günceller
|
1479
|
+
*/
|
1480
|
+
updateMemoryConfig(config) {
|
1481
|
+
this.memoryConfig = { ...this.memoryConfig, ...config };
|
1482
|
+
if (this.persistentExecutor) {
|
1483
|
+
this.persistentExecutor.updateMemoryConfig(this.memoryConfig);
|
1484
|
+
}
|
1485
|
+
}
|
1486
|
+
/**
|
1487
|
+
* Oturum ID'sini oluşturur
|
1488
|
+
*/
|
1489
|
+
generateSessionId() {
|
1490
|
+
return `session_${Date.now()}_${Math.random().toString(36).substr(2, 8)}`;
|
1491
|
+
}
|
1492
|
+
/**
|
1493
|
+
* Hafızayı bağlam olarak formatlar
|
1494
|
+
*/
|
1495
|
+
getMemoryAsContext() {
|
1496
|
+
const memory = this.getMemory();
|
1497
|
+
if (memory.length === 0) {
|
1498
|
+
return "";
|
1499
|
+
}
|
1500
|
+
const recentMemory = memory.slice(-5);
|
1501
|
+
return recentMemory.map((item) => `- ${item.summary}`).join("\n");
|
1502
|
+
}
|
1266
1503
|
async runPlans(title, plans, opts) {
|
1267
|
-
|
1268
|
-
|
1269
|
-
|
1504
|
+
await this.updatePageContext();
|
1505
|
+
const useMemory = opts?.useMemory !== false;
|
1506
|
+
let taskExecutor;
|
1507
|
+
if (useMemory) {
|
1508
|
+
taskExecutor = this.getPersistentExecutor();
|
1509
|
+
this.workflowMemory.updateWorkflowContext({
|
1510
|
+
currentStep: title,
|
1511
|
+
pageInfo: this.sessionContext.pageInfo,
|
1512
|
+
timestamp: Date.now()
|
1513
|
+
}, this.sessionContext.workflowId || "default");
|
1514
|
+
} else {
|
1515
|
+
taskExecutor = new import_misoai_core.Executor(title, {
|
1516
|
+
onTaskStart: this.onTaskStartCallback
|
1517
|
+
});
|
1518
|
+
}
|
1270
1519
|
const { tasks } = await this.convertPlanToExecutable(plans, opts);
|
1520
|
+
tasks.forEach((task) => {
|
1521
|
+
task.context = {
|
1522
|
+
...task.context,
|
1523
|
+
...this.sessionContext.pageInfo,
|
1524
|
+
workflowId: this.sessionContext.workflowId,
|
1525
|
+
sessionId: this.sessionContext.sessionId
|
1526
|
+
};
|
1527
|
+
});
|
1271
1528
|
await taskExecutor.append(tasks);
|
1272
1529
|
const result = await taskExecutor.flush();
|
1530
|
+
if (useMemory) {
|
1531
|
+
this.workflowMemory.saveWorkflowMemory(
|
1532
|
+
taskExecutor.getMemory(),
|
1533
|
+
this.sessionContext.workflowId || "default"
|
1534
|
+
);
|
1535
|
+
}
|
1273
1536
|
return {
|
1274
1537
|
output: result,
|
1275
1538
|
executor: taskExecutor
|
1276
1539
|
};
|
1277
1540
|
}
|
1278
1541
|
async action(userPrompt, actionContext, opts) {
|
1279
|
-
const
|
1280
|
-
|
1281
|
-
|
1282
|
-
|
1542
|
+
const useMemory = true;
|
1543
|
+
let taskExecutor;
|
1544
|
+
if (useMemory) {
|
1545
|
+
taskExecutor = this.getPersistentExecutor();
|
1546
|
+
} else {
|
1547
|
+
taskExecutor = new import_misoai_core.Executor(taskTitleStr("Action", userPrompt), {
|
1548
|
+
onTaskStart: this.onTaskStartCallback
|
1549
|
+
});
|
1550
|
+
}
|
1551
|
+
const memoryContext = this.getMemoryAsContext();
|
1552
|
+
const initialLog = memoryContext ? memoryContext : void 0;
|
1553
|
+
let planningTask = this.planningTaskFromPrompt(userPrompt, initialLog, actionContext);
|
1283
1554
|
let replanCount = 0;
|
1284
1555
|
const logList = [];
|
1556
|
+
if (memoryContext) {
|
1557
|
+
logList.push(memoryContext);
|
1558
|
+
}
|
1285
1559
|
const yamlFlow = [];
|
1286
1560
|
while (planningTask) {
|
1287
1561
|
if (replanCount > replanningCountLimit) {
|
@@ -1390,16 +1664,22 @@ var PageTaskExecutor = class {
|
|
1390
1664
|
executor: taskExecutor
|
1391
1665
|
};
|
1392
1666
|
}
|
1393
|
-
async createTypeQueryTask(type, demand) {
|
1394
|
-
const
|
1395
|
-
|
1396
|
-
|
1397
|
-
|
1398
|
-
|
1399
|
-
|
1400
|
-
|
1401
|
-
|
1402
|
-
|
1667
|
+
async createTypeQueryTask(type, demand, opt) {
|
1668
|
+
const useMemory = true;
|
1669
|
+
let taskExecutor;
|
1670
|
+
if (useMemory) {
|
1671
|
+
taskExecutor = this.getPersistentExecutor();
|
1672
|
+
} else {
|
1673
|
+
taskExecutor = new import_misoai_core.Executor(
|
1674
|
+
taskTitleStr(
|
1675
|
+
type,
|
1676
|
+
typeof demand === "string" ? demand : JSON.stringify(demand)
|
1677
|
+
),
|
1678
|
+
{
|
1679
|
+
onTaskStart: this.onTaskStartCallback
|
1680
|
+
}
|
1681
|
+
);
|
1682
|
+
}
|
1403
1683
|
const queryTask = {
|
1404
1684
|
type: "Insight",
|
1405
1685
|
subType: type,
|
@@ -1421,7 +1701,13 @@ var PageTaskExecutor = class {
|
|
1421
1701
|
result: `${type}, ${demand}`
|
1422
1702
|
};
|
1423
1703
|
}
|
1424
|
-
const
|
1704
|
+
const memoryContext = this.getMemoryAsContext();
|
1705
|
+
const { data, usage } = await this.insight.extract(
|
1706
|
+
demandInput,
|
1707
|
+
opt,
|
1708
|
+
memoryContext
|
1709
|
+
// Hafıza bağlamını geç
|
1710
|
+
);
|
1425
1711
|
let outputResult = data;
|
1426
1712
|
if (ifTypeRestricted) {
|
1427
1713
|
(0, import_utils6.assert)(data?.result !== void 0, "No result in query data");
|
@@ -1441,23 +1727,29 @@ var PageTaskExecutor = class {
|
|
1441
1727
|
executor: taskExecutor
|
1442
1728
|
};
|
1443
1729
|
}
|
1444
|
-
async query(demand) {
|
1445
|
-
return this.createTypeQueryTask("Query", demand);
|
1730
|
+
async query(demand, opt) {
|
1731
|
+
return this.createTypeQueryTask("Query", demand, opt);
|
1446
1732
|
}
|
1447
|
-
async boolean(prompt) {
|
1448
|
-
return this.createTypeQueryTask("Boolean", prompt);
|
1733
|
+
async boolean(prompt, opt) {
|
1734
|
+
return this.createTypeQueryTask("Boolean", prompt, opt);
|
1449
1735
|
}
|
1450
|
-
async number(prompt) {
|
1451
|
-
return this.createTypeQueryTask("Number", prompt);
|
1736
|
+
async number(prompt, opt) {
|
1737
|
+
return this.createTypeQueryTask("Number", prompt, opt);
|
1452
1738
|
}
|
1453
|
-
async string(prompt) {
|
1454
|
-
return this.createTypeQueryTask("String", prompt);
|
1739
|
+
async string(prompt, opt) {
|
1740
|
+
return this.createTypeQueryTask("String", prompt, opt);
|
1455
1741
|
}
|
1456
|
-
async assert(assertion) {
|
1742
|
+
async assert(assertion, memoryContext) {
|
1457
1743
|
const description = `assert: ${assertion}`;
|
1458
|
-
const
|
1459
|
-
|
1460
|
-
|
1744
|
+
const useMemory = true;
|
1745
|
+
let taskExecutor;
|
1746
|
+
if (useMemory) {
|
1747
|
+
taskExecutor = this.getPersistentExecutor();
|
1748
|
+
} else {
|
1749
|
+
taskExecutor = new import_misoai_core.Executor(taskTitleStr("Assert", description), {
|
1750
|
+
onTaskStart: this.onTaskStartCallback
|
1751
|
+
});
|
1752
|
+
}
|
1461
1753
|
const assertionPlan = {
|
1462
1754
|
type: "Assert",
|
1463
1755
|
param: {
|
@@ -1587,7 +1879,7 @@ function buildPlans(type, locateParam, param) {
|
|
1587
1879
|
param: locateParam,
|
1588
1880
|
thought: ""
|
1589
1881
|
} : null;
|
1590
|
-
if (type === "Tap" || type === "Hover") {
|
1882
|
+
if (type === "Tap" || type === "Hover" || type === "RightClick") {
|
1591
1883
|
(0, import_utils8.assert)(locateParam, `missing locate info for action "${type}"`);
|
1592
1884
|
(0, import_utils8.assert)(locatePlan, `missing locate info for action "${type}"`);
|
1593
1885
|
const tapPlan = {
|
@@ -1667,7 +1959,7 @@ var import_js_yaml3 = __toESM(require("js-yaml"));
|
|
1667
1959
|
var import_semver = __toESM(require("semver"));
|
1668
1960
|
|
1669
1961
|
// package.json
|
1670
|
-
var version = "1.5.
|
1962
|
+
var version = "1.5.7";
|
1671
1963
|
|
1672
1964
|
// src/common/task-cache.ts
|
1673
1965
|
var debug3 = (0, import_logger3.getDebug)("cache");
|
@@ -1798,8 +2090,14 @@ cache file: ${cacheFile}`
|
|
1798
2090
|
return;
|
1799
2091
|
}
|
1800
2092
|
try {
|
2093
|
+
const dir = (0, import_node_path2.dirname)(this.cacheFilePath);
|
2094
|
+
if (!(0, import_node_fs2.existsSync)(dir)) {
|
2095
|
+
(0, import_node_fs2.mkdirSync)(dir, { recursive: true });
|
2096
|
+
debug3("created cache directory: %s", dir);
|
2097
|
+
}
|
1801
2098
|
const yamlData = import_js_yaml3.default.dump(this.cache);
|
1802
2099
|
(0, import_node_fs2.writeFileSync)(this.cacheFilePath, yamlData);
|
2100
|
+
debug3("cache flushed to file: %s", this.cacheFilePath);
|
1803
2101
|
} catch (err) {
|
1804
2102
|
debug3(
|
1805
2103
|
"write cache to file failed, path: %s, error: %s",
|
@@ -2057,6 +2355,23 @@ var PageAgent = class {
|
|
2057
2355
|
metadata
|
2058
2356
|
};
|
2059
2357
|
}
|
2358
|
+
async aiRightClick(locatePrompt, opt) {
|
2359
|
+
const detailedLocateParam = this.buildDetailedLocateParam(
|
2360
|
+
locatePrompt,
|
2361
|
+
opt
|
2362
|
+
);
|
2363
|
+
const plans = buildPlans("RightClick", detailedLocateParam);
|
2364
|
+
const { executor, output } = await this.taskExecutor.runPlans(
|
2365
|
+
taskTitleStr("RightClick", locateParamStr(detailedLocateParam)),
|
2366
|
+
plans,
|
2367
|
+
{ cacheable: opt?.cacheable }
|
2368
|
+
);
|
2369
|
+
const metadata = this.afterTaskRunning(executor);
|
2370
|
+
return {
|
2371
|
+
result: output,
|
2372
|
+
metadata
|
2373
|
+
};
|
2374
|
+
}
|
2060
2375
|
async aiInput(value, locatePrompt, opt) {
|
2061
2376
|
(0, import_utils12.assert)(
|
2062
2377
|
typeof value === "string",
|
@@ -2131,7 +2446,13 @@ var PageAgent = class {
|
|
2131
2446
|
metadata: metadata2
|
2132
2447
|
};
|
2133
2448
|
}
|
2134
|
-
const
|
2449
|
+
const memoryContext = this.getMemoryAsContext();
|
2450
|
+
const enhancedActionContext = this.opts.aiActionContext ? `${this.opts.aiActionContext}
|
2451
|
+
|
2452
|
+
Previous workflow steps:
|
2453
|
+
${memoryContext}` : memoryContext ? `Previous workflow steps:
|
2454
|
+
${memoryContext}` : void 0;
|
2455
|
+
const { output, executor } = await (isVlmUiTars ? this.taskExecutor.actionToGoal(taskPrompt, { cacheable }) : this.taskExecutor.action(taskPrompt, enhancedActionContext, {
|
2135
2456
|
cacheable
|
2136
2457
|
}));
|
2137
2458
|
if (this.taskCache && output?.yamlFlow && cacheable !== false) {
|
@@ -2277,8 +2598,9 @@ var PageAgent = class {
|
|
2277
2598
|
} catch (e) {
|
2278
2599
|
}
|
2279
2600
|
}
|
2601
|
+
const memoryContext = this.getMemoryAsContext();
|
2280
2602
|
const assertionWithContext = currentUrl ? `For the page at URL "${currentUrl}", ${assertion}` : assertion;
|
2281
|
-
const { output, executor } = await this.taskExecutor.assert(assertionWithContext);
|
2603
|
+
const { output, executor } = await this.taskExecutor.assert(assertionWithContext, memoryContext);
|
2282
2604
|
const metadata = this.afterTaskRunning(executor, true);
|
2283
2605
|
if (output && opt?.keepRawResponse) {
|
2284
2606
|
return {
|
@@ -2488,9 +2810,72 @@ ${errors}`);
|
|
2488
2810
|
}
|
2489
2811
|
throw new Error("evaluateJavaScript is not supported in current agent");
|
2490
2812
|
}
|
2813
|
+
async logScreenshot(title, options) {
|
2814
|
+
const screenshotTitle = title || "untitled";
|
2815
|
+
const content = options?.content || "";
|
2816
|
+
const screenshot = await this.page.screenshotBase64?.();
|
2817
|
+
if (screenshot) {
|
2818
|
+
const executionDump = {
|
2819
|
+
name: screenshotTitle,
|
2820
|
+
description: content,
|
2821
|
+
tasks: [{
|
2822
|
+
type: "Screenshot",
|
2823
|
+
subType: "log",
|
2824
|
+
status: "finished",
|
2825
|
+
executor: null,
|
2826
|
+
param: {
|
2827
|
+
title: screenshotTitle,
|
2828
|
+
content
|
2829
|
+
},
|
2830
|
+
output: {
|
2831
|
+
screenshot
|
2832
|
+
},
|
2833
|
+
thought: `Logged screenshot: ${screenshotTitle}`,
|
2834
|
+
timing: {
|
2835
|
+
start: Date.now(),
|
2836
|
+
end: Date.now(),
|
2837
|
+
cost: 0
|
2838
|
+
}
|
2839
|
+
}],
|
2840
|
+
sdkVersion: "1.0.0",
|
2841
|
+
logTime: Date.now(),
|
2842
|
+
model_name: "screenshot"
|
2843
|
+
};
|
2844
|
+
this.appendExecutionDump(executionDump);
|
2845
|
+
}
|
2846
|
+
}
|
2491
2847
|
async destroy() {
|
2492
2848
|
await this.page.destroy();
|
2493
2849
|
}
|
2850
|
+
/**
|
2851
|
+
* Hafızayı bağlam olarak formatlar
|
2852
|
+
*/
|
2853
|
+
getMemoryAsContext() {
|
2854
|
+
const memory = this.taskExecutor.getMemory();
|
2855
|
+
if (memory.length === 0) {
|
2856
|
+
return "";
|
2857
|
+
}
|
2858
|
+
const recentMemory = memory.slice(-5);
|
2859
|
+
return recentMemory.map((item) => `- ${item.summary}`).join("\n");
|
2860
|
+
}
|
2861
|
+
/**
|
2862
|
+
* Mevcut hafızayı döndürür
|
2863
|
+
*/
|
2864
|
+
getMemory() {
|
2865
|
+
return this.taskExecutor.getMemory();
|
2866
|
+
}
|
2867
|
+
/**
|
2868
|
+
* Hafıza istatistiklerini döndürür
|
2869
|
+
*/
|
2870
|
+
getMemoryStats() {
|
2871
|
+
return this.taskExecutor.getMemoryStats();
|
2872
|
+
}
|
2873
|
+
/**
|
2874
|
+
* Hafızayı temizler
|
2875
|
+
*/
|
2876
|
+
clearMemory() {
|
2877
|
+
this.taskExecutor.clearMemory();
|
2878
|
+
}
|
2494
2879
|
};
|
2495
2880
|
|
2496
2881
|
// src/playground/agent.ts
|