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.
- package/dist/es/agent.js +307 -25
- package/dist/es/agent.js.map +1 -1
- package/dist/es/bridge-mode-browser.js +3 -3
- package/dist/es/bridge-mode.js +309 -27
- package/dist/es/bridge-mode.js.map +1 -1
- package/dist/es/chrome-extension.js +308 -26
- package/dist/es/chrome-extension.js.map +1 -1
- package/dist/es/index.js +307 -25
- package/dist/es/index.js.map +1 -1
- package/dist/es/midscene-playground.js +307 -25
- package/dist/es/midscene-playground.js.map +1 -1
- package/dist/es/playground.js +307 -25
- package/dist/es/playground.js.map +1 -1
- package/dist/es/playwright.js +307 -25
- package/dist/es/playwright.js.map +1 -1
- package/dist/es/puppeteer-agent-launcher.js +307 -25
- package/dist/es/puppeteer-agent-launcher.js.map +1 -1
- package/dist/es/puppeteer.js +307 -25
- package/dist/es/puppeteer.js.map +1 -1
- package/dist/lib/agent.js +307 -25
- package/dist/lib/agent.js.map +1 -1
- package/dist/lib/bridge-mode-browser.js +3 -3
- package/dist/lib/bridge-mode.js +309 -27
- package/dist/lib/bridge-mode.js.map +1 -1
- package/dist/lib/chrome-extension.js +308 -26
- package/dist/lib/chrome-extension.js.map +1 -1
- package/dist/lib/index.js +307 -25
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/midscene-playground.js +307 -25
- package/dist/lib/midscene-playground.js.map +1 -1
- package/dist/lib/playground.js +307 -25
- package/dist/lib/playground.js.map +1 -1
- package/dist/lib/playwright.js +307 -25
- package/dist/lib/playwright.js.map +1 -1
- package/dist/lib/puppeteer-agent-launcher.js +307 -25
- package/dist/lib/puppeteer-agent-launcher.js.map +1 -1
- package/dist/lib/puppeteer.js +307 -25
- package/dist/lib/puppeteer.js.map +1 -1
- package/dist/types/agent.d.ts +92 -2
- package/package.json +2 -2
package/dist/es/agent.js
CHANGED
@@ -595,6 +595,94 @@ var replanningCountLimit = 10;
|
|
595
595
|
var isAndroidPage = (page) => {
|
596
596
|
return page.pageType === "android";
|
597
597
|
};
|
598
|
+
var WorkflowMemory = class {
|
599
|
+
constructor(config) {
|
600
|
+
this.workflows = /* @__PURE__ */ new Map();
|
601
|
+
this.config = config;
|
602
|
+
}
|
603
|
+
/**
|
604
|
+
* İş akışı hafızasını getirir
|
605
|
+
*/
|
606
|
+
getWorkflowMemory(workflowId = "default") {
|
607
|
+
const workflow = this.workflows.get(workflowId);
|
608
|
+
return workflow?.memory || [];
|
609
|
+
}
|
610
|
+
/**
|
611
|
+
* İş akışı verilerini getirir
|
612
|
+
*/
|
613
|
+
getWorkflowData(workflowId = "default") {
|
614
|
+
return this.workflows.get(workflowId) || this.createEmptyWorkflowData(workflowId);
|
615
|
+
}
|
616
|
+
/**
|
617
|
+
* İş akışı hafızasını kaydeder
|
618
|
+
*/
|
619
|
+
saveWorkflowMemory(memory, workflowId = "default") {
|
620
|
+
const workflow = this.workflows.get(workflowId) || this.createEmptyWorkflowData(workflowId);
|
621
|
+
workflow.memory = [...memory];
|
622
|
+
workflow.metadata.totalSteps = workflow.steps.length;
|
623
|
+
workflow.metadata.completedSteps = workflow.steps.filter((s) => s.status === "completed").length;
|
624
|
+
workflow.metadata.failedSteps = workflow.steps.filter((s) => s.status === "failed").length;
|
625
|
+
this.workflows.set(workflowId, workflow);
|
626
|
+
this.enforceRetentionPolicy();
|
627
|
+
}
|
628
|
+
/**
|
629
|
+
* İş akışı bağlamını günceller
|
630
|
+
*/
|
631
|
+
updateWorkflowContext(context, workflowId = "default") {
|
632
|
+
const workflow = this.workflows.get(workflowId) || this.createEmptyWorkflowData(workflowId);
|
633
|
+
workflow.context = { ...workflow.context, ...context };
|
634
|
+
if (context.currentStep) {
|
635
|
+
const existingStep = workflow.steps.find((s) => s.stepName === context.currentStep);
|
636
|
+
if (!existingStep) {
|
637
|
+
workflow.steps.push({
|
638
|
+
stepId: `step_${workflow.steps.length + 1}`,
|
639
|
+
stepName: context.currentStep,
|
640
|
+
timestamp: context.timestamp,
|
641
|
+
status: "running",
|
642
|
+
memoryItems: []
|
643
|
+
});
|
644
|
+
}
|
645
|
+
}
|
646
|
+
this.workflows.set(workflowId, workflow);
|
647
|
+
}
|
648
|
+
/**
|
649
|
+
* İş akışını temizler
|
650
|
+
*/
|
651
|
+
clearWorkflow(workflowId = "default") {
|
652
|
+
this.workflows.delete(workflowId);
|
653
|
+
}
|
654
|
+
/**
|
655
|
+
* Tüm iş akışlarını temizler
|
656
|
+
*/
|
657
|
+
clearAll() {
|
658
|
+
this.workflows.clear();
|
659
|
+
}
|
660
|
+
createEmptyWorkflowData(workflowId) {
|
661
|
+
return {
|
662
|
+
workflowId,
|
663
|
+
steps: [],
|
664
|
+
memory: [],
|
665
|
+
context: {
|
666
|
+
pageInfo: { url: "", title: "" },
|
667
|
+
timestamp: Date.now()
|
668
|
+
},
|
669
|
+
metadata: {
|
670
|
+
totalSteps: 0,
|
671
|
+
completedSteps: 0,
|
672
|
+
failedSteps: 0,
|
673
|
+
startTime: Date.now()
|
674
|
+
}
|
675
|
+
};
|
676
|
+
}
|
677
|
+
enforceRetentionPolicy() {
|
678
|
+
const maxWorkflows = 10;
|
679
|
+
if (this.workflows.size > maxWorkflows) {
|
680
|
+
const sortedWorkflows = Array.from(this.workflows.entries()).sort(([, a], [, b]) => (b.metadata.endTime || b.metadata.startTime) - (a.metadata.endTime || a.metadata.startTime));
|
681
|
+
const toDelete = sortedWorkflows.slice(maxWorkflows);
|
682
|
+
toDelete.forEach(([workflowId]) => this.workflows.delete(workflowId));
|
683
|
+
}
|
684
|
+
}
|
685
|
+
};
|
598
686
|
var PageTaskExecutor = class {
|
599
687
|
constructor(page, insight, opts) {
|
600
688
|
this.conversationHistory = [];
|
@@ -602,6 +690,25 @@ var PageTaskExecutor = class {
|
|
602
690
|
this.insight = insight;
|
603
691
|
this.taskCache = opts.taskCache;
|
604
692
|
this.onTaskStartCallback = opts?.onTaskStart;
|
693
|
+
this.memoryConfig = {
|
694
|
+
maxItems: 100,
|
695
|
+
maxAge: 2 * 60 * 60 * 1e3,
|
696
|
+
// 2 saat
|
697
|
+
enablePersistence: true,
|
698
|
+
enableAnalytics: true,
|
699
|
+
filterStrategy: "hybrid",
|
700
|
+
...opts?.memoryConfig
|
701
|
+
};
|
702
|
+
this.sessionContext = {
|
703
|
+
sessionId: opts?.sessionId || this.generateSessionId(),
|
704
|
+
workflowId: opts?.workflowId,
|
705
|
+
startTime: Date.now(),
|
706
|
+
pageInfo: {
|
707
|
+
url: "",
|
708
|
+
title: ""
|
709
|
+
}
|
710
|
+
};
|
711
|
+
this.workflowMemory = new WorkflowMemory(this.memoryConfig);
|
605
712
|
}
|
606
713
|
async recordScreenshot(timing) {
|
607
714
|
const base64 = await this.page.screenshotBase64();
|
@@ -814,8 +921,11 @@ var PageTaskExecutor = class {
|
|
814
921
|
insightDump = dump;
|
815
922
|
};
|
816
923
|
this.insight.onceDumpUpdatedFn = dumpCollector;
|
924
|
+
const memoryContext = this.getMemoryAsContext();
|
817
925
|
const assertion = await this.insight.assert(
|
818
|
-
assertPlan.param.assertion
|
926
|
+
assertPlan.param.assertion,
|
927
|
+
memoryContext
|
928
|
+
// Hafıza bağlamını geç
|
819
929
|
);
|
820
930
|
if (!assertion.pass) {
|
821
931
|
if (plan2.type === "Assert") {
|
@@ -1301,25 +1411,146 @@ var PageTaskExecutor = class {
|
|
1301
1411
|
};
|
1302
1412
|
return task;
|
1303
1413
|
}
|
1414
|
+
/**
|
1415
|
+
* Persistent executor'ı getirir veya oluşturur
|
1416
|
+
*/
|
1417
|
+
getPersistentExecutor() {
|
1418
|
+
if (!this.persistentExecutor || this.persistentExecutor.status === "error") {
|
1419
|
+
const previousMemory = this.workflowMemory.getWorkflowMemory(this.sessionContext.workflowId);
|
1420
|
+
this.persistentExecutor = new Executor("Persistent Task Executor", {
|
1421
|
+
onTaskStart: this.onTaskStartCallback,
|
1422
|
+
initialMemory: previousMemory
|
1423
|
+
});
|
1424
|
+
}
|
1425
|
+
return this.persistentExecutor;
|
1426
|
+
}
|
1427
|
+
/**
|
1428
|
+
* Sayfa bağlamını günceller
|
1429
|
+
*/
|
1430
|
+
async updatePageContext() {
|
1431
|
+
try {
|
1432
|
+
if (this.page.url) {
|
1433
|
+
this.sessionContext.pageInfo.url = await this.page.url();
|
1434
|
+
}
|
1435
|
+
if (this.page.pageType === "puppeteer" || this.page.pageType === "playwright") {
|
1436
|
+
this.sessionContext.pageInfo.title = await this.page.title();
|
1437
|
+
}
|
1438
|
+
} catch (e) {
|
1439
|
+
}
|
1440
|
+
}
|
1441
|
+
/**
|
1442
|
+
* Hafızayı temizler
|
1443
|
+
*/
|
1444
|
+
clearMemory() {
|
1445
|
+
if (this.persistentExecutor) {
|
1446
|
+
this.persistentExecutor.clearMemory();
|
1447
|
+
}
|
1448
|
+
this.workflowMemory.clearWorkflow(this.sessionContext.workflowId || "default");
|
1449
|
+
}
|
1450
|
+
/**
|
1451
|
+
* Mevcut hafızayı döndürür
|
1452
|
+
*/
|
1453
|
+
getMemory() {
|
1454
|
+
return this.persistentExecutor?.getMemory() || [];
|
1455
|
+
}
|
1456
|
+
/**
|
1457
|
+
* İş akışı hafızasını döndürür
|
1458
|
+
*/
|
1459
|
+
getWorkflowMemory() {
|
1460
|
+
return this.workflowMemory.getWorkflowData(this.sessionContext.workflowId || "default");
|
1461
|
+
}
|
1462
|
+
/**
|
1463
|
+
* Hafıza istatistiklerini döndürür
|
1464
|
+
*/
|
1465
|
+
getMemoryStats() {
|
1466
|
+
return this.persistentExecutor?.getMemoryStats() || {
|
1467
|
+
totalItems: 0,
|
1468
|
+
analytics: { totalTasks: 0, memoryHits: 0, memoryMisses: 0, averageMemorySize: 0, memoryEffectiveness: 0 },
|
1469
|
+
config: this.memoryConfig
|
1470
|
+
};
|
1471
|
+
}
|
1472
|
+
/**
|
1473
|
+
* Hafıza konfigürasyonunu günceller
|
1474
|
+
*/
|
1475
|
+
updateMemoryConfig(config) {
|
1476
|
+
this.memoryConfig = { ...this.memoryConfig, ...config };
|
1477
|
+
if (this.persistentExecutor) {
|
1478
|
+
this.persistentExecutor.updateMemoryConfig(this.memoryConfig);
|
1479
|
+
}
|
1480
|
+
}
|
1481
|
+
/**
|
1482
|
+
* Oturum ID'sini oluşturur
|
1483
|
+
*/
|
1484
|
+
generateSessionId() {
|
1485
|
+
return `session_${Date.now()}_${Math.random().toString(36).substr(2, 8)}`;
|
1486
|
+
}
|
1487
|
+
/**
|
1488
|
+
* Hafızayı bağlam olarak formatlar
|
1489
|
+
*/
|
1490
|
+
getMemoryAsContext() {
|
1491
|
+
const memory = this.getMemory();
|
1492
|
+
if (memory.length === 0) {
|
1493
|
+
return "";
|
1494
|
+
}
|
1495
|
+
const recentMemory = memory.slice(-5);
|
1496
|
+
return recentMemory.map((item) => `- ${item.summary}`).join("\n");
|
1497
|
+
}
|
1304
1498
|
async runPlans(title, plans, opts) {
|
1305
|
-
|
1306
|
-
|
1307
|
-
|
1499
|
+
await this.updatePageContext();
|
1500
|
+
const useMemory = opts?.useMemory !== false;
|
1501
|
+
let taskExecutor;
|
1502
|
+
if (useMemory) {
|
1503
|
+
taskExecutor = this.getPersistentExecutor();
|
1504
|
+
this.workflowMemory.updateWorkflowContext({
|
1505
|
+
currentStep: title,
|
1506
|
+
pageInfo: this.sessionContext.pageInfo,
|
1507
|
+
timestamp: Date.now()
|
1508
|
+
}, this.sessionContext.workflowId || "default");
|
1509
|
+
} else {
|
1510
|
+
taskExecutor = new Executor(title, {
|
1511
|
+
onTaskStart: this.onTaskStartCallback
|
1512
|
+
});
|
1513
|
+
}
|
1308
1514
|
const { tasks } = await this.convertPlanToExecutable(plans, opts);
|
1515
|
+
tasks.forEach((task) => {
|
1516
|
+
task.context = {
|
1517
|
+
...task.context,
|
1518
|
+
...this.sessionContext.pageInfo,
|
1519
|
+
workflowId: this.sessionContext.workflowId,
|
1520
|
+
sessionId: this.sessionContext.sessionId
|
1521
|
+
};
|
1522
|
+
});
|
1309
1523
|
await taskExecutor.append(tasks);
|
1310
1524
|
const result = await taskExecutor.flush();
|
1525
|
+
if (useMemory) {
|
1526
|
+
this.workflowMemory.saveWorkflowMemory(
|
1527
|
+
taskExecutor.getMemory(),
|
1528
|
+
this.sessionContext.workflowId || "default"
|
1529
|
+
);
|
1530
|
+
}
|
1311
1531
|
return {
|
1312
1532
|
output: result,
|
1313
1533
|
executor: taskExecutor
|
1314
1534
|
};
|
1315
1535
|
}
|
1316
1536
|
async action(userPrompt, actionContext, opts) {
|
1317
|
-
const
|
1318
|
-
|
1319
|
-
|
1320
|
-
|
1537
|
+
const useMemory = true;
|
1538
|
+
let taskExecutor;
|
1539
|
+
if (useMemory) {
|
1540
|
+
taskExecutor = this.getPersistentExecutor();
|
1541
|
+
} else {
|
1542
|
+
taskExecutor = new Executor(taskTitleStr("Action", userPrompt), {
|
1543
|
+
onTaskStart: this.onTaskStartCallback
|
1544
|
+
});
|
1545
|
+
}
|
1546
|
+
const memoryContext = this.getMemoryAsContext();
|
1547
|
+
const initialLog = memoryContext ? memoryContext : void 0;
|
1548
|
+
let planningTask = this.planningTaskFromPrompt(userPrompt, initialLog, actionContext);
|
1321
1549
|
let replanCount = 0;
|
1322
1550
|
const logList = [];
|
1551
|
+
if (memoryContext) {
|
1552
|
+
logList.push(memoryContext);
|
1553
|
+
}
|
1323
1554
|
const yamlFlow = [];
|
1324
1555
|
while (planningTask) {
|
1325
1556
|
if (replanCount > replanningCountLimit) {
|
@@ -1429,15 +1660,21 @@ var PageTaskExecutor = class {
|
|
1429
1660
|
};
|
1430
1661
|
}
|
1431
1662
|
async createTypeQueryTask(type, demand, opt) {
|
1432
|
-
const
|
1433
|
-
|
1434
|
-
|
1435
|
-
|
1436
|
-
|
1437
|
-
|
1438
|
-
|
1439
|
-
|
1440
|
-
|
1663
|
+
const useMemory = true;
|
1664
|
+
let taskExecutor;
|
1665
|
+
if (useMemory) {
|
1666
|
+
taskExecutor = this.getPersistentExecutor();
|
1667
|
+
} else {
|
1668
|
+
taskExecutor = new Executor(
|
1669
|
+
taskTitleStr(
|
1670
|
+
type,
|
1671
|
+
typeof demand === "string" ? demand : JSON.stringify(demand)
|
1672
|
+
),
|
1673
|
+
{
|
1674
|
+
onTaskStart: this.onTaskStartCallback
|
1675
|
+
}
|
1676
|
+
);
|
1677
|
+
}
|
1441
1678
|
const queryTask = {
|
1442
1679
|
type: "Insight",
|
1443
1680
|
subType: type,
|
@@ -1459,9 +1696,12 @@ var PageTaskExecutor = class {
|
|
1459
1696
|
result: `${type}, ${demand}`
|
1460
1697
|
};
|
1461
1698
|
}
|
1699
|
+
const memoryContext = this.getMemoryAsContext();
|
1462
1700
|
const { data, usage } = await this.insight.extract(
|
1463
1701
|
demandInput,
|
1464
|
-
opt
|
1702
|
+
opt,
|
1703
|
+
memoryContext
|
1704
|
+
// Hafıza bağlamını geç
|
1465
1705
|
);
|
1466
1706
|
let outputResult = data;
|
1467
1707
|
if (ifTypeRestricted) {
|
@@ -1494,11 +1734,17 @@ var PageTaskExecutor = class {
|
|
1494
1734
|
async string(prompt, opt) {
|
1495
1735
|
return this.createTypeQueryTask("String", prompt, opt);
|
1496
1736
|
}
|
1497
|
-
async assert(assertion) {
|
1737
|
+
async assert(assertion, memoryContext) {
|
1498
1738
|
const description = `assert: ${assertion}`;
|
1499
|
-
const
|
1500
|
-
|
1501
|
-
|
1739
|
+
const useMemory = true;
|
1740
|
+
let taskExecutor;
|
1741
|
+
if (useMemory) {
|
1742
|
+
taskExecutor = this.getPersistentExecutor();
|
1743
|
+
} else {
|
1744
|
+
taskExecutor = new Executor(taskTitleStr("Assert", description), {
|
1745
|
+
onTaskStart: this.onTaskStartCallback
|
1746
|
+
});
|
1747
|
+
}
|
1502
1748
|
const assertionPlan = {
|
1503
1749
|
type: "Assert",
|
1504
1750
|
param: {
|
@@ -1708,7 +1954,7 @@ import yaml3 from "js-yaml";
|
|
1708
1954
|
import semver from "semver";
|
1709
1955
|
|
1710
1956
|
// package.json
|
1711
|
-
var version = "1.
|
1957
|
+
var version = "1.5.7";
|
1712
1958
|
|
1713
1959
|
// src/common/task-cache.ts
|
1714
1960
|
var debug3 = getDebug3("cache");
|
@@ -2195,7 +2441,13 @@ var PageAgent = class {
|
|
2195
2441
|
metadata: metadata2
|
2196
2442
|
};
|
2197
2443
|
}
|
2198
|
-
const
|
2444
|
+
const memoryContext = this.getMemoryAsContext();
|
2445
|
+
const enhancedActionContext = this.opts.aiActionContext ? `${this.opts.aiActionContext}
|
2446
|
+
|
2447
|
+
Previous workflow steps:
|
2448
|
+
${memoryContext}` : memoryContext ? `Previous workflow steps:
|
2449
|
+
${memoryContext}` : void 0;
|
2450
|
+
const { output, executor } = await (isVlmUiTars ? this.taskExecutor.actionToGoal(taskPrompt, { cacheable }) : this.taskExecutor.action(taskPrompt, enhancedActionContext, {
|
2199
2451
|
cacheable
|
2200
2452
|
}));
|
2201
2453
|
if (this.taskCache && output?.yamlFlow && cacheable !== false) {
|
@@ -2341,8 +2593,9 @@ var PageAgent = class {
|
|
2341
2593
|
} catch (e) {
|
2342
2594
|
}
|
2343
2595
|
}
|
2596
|
+
const memoryContext = this.getMemoryAsContext();
|
2344
2597
|
const assertionWithContext = currentUrl ? `For the page at URL "${currentUrl}", ${assertion}` : assertion;
|
2345
|
-
const { output, executor } = await this.taskExecutor.assert(assertionWithContext);
|
2598
|
+
const { output, executor } = await this.taskExecutor.assert(assertionWithContext, memoryContext);
|
2346
2599
|
const metadata = this.afterTaskRunning(executor, true);
|
2347
2600
|
if (output && opt?.keepRawResponse) {
|
2348
2601
|
return {
|
@@ -2589,6 +2842,35 @@ ${errors}`);
|
|
2589
2842
|
async destroy() {
|
2590
2843
|
await this.page.destroy();
|
2591
2844
|
}
|
2845
|
+
/**
|
2846
|
+
* Hafızayı bağlam olarak formatlar
|
2847
|
+
*/
|
2848
|
+
getMemoryAsContext() {
|
2849
|
+
const memory = this.taskExecutor.getMemory();
|
2850
|
+
if (memory.length === 0) {
|
2851
|
+
return "";
|
2852
|
+
}
|
2853
|
+
const recentMemory = memory.slice(-5);
|
2854
|
+
return recentMemory.map((item) => `- ${item.summary}`).join("\n");
|
2855
|
+
}
|
2856
|
+
/**
|
2857
|
+
* Mevcut hafızayı döndürür
|
2858
|
+
*/
|
2859
|
+
getMemory() {
|
2860
|
+
return this.taskExecutor.getMemory();
|
2861
|
+
}
|
2862
|
+
/**
|
2863
|
+
* Hafıza istatistiklerini döndürür
|
2864
|
+
*/
|
2865
|
+
getMemoryStats() {
|
2866
|
+
return this.taskExecutor.getMemoryStats();
|
2867
|
+
}
|
2868
|
+
/**
|
2869
|
+
* Hafızayı temizler
|
2870
|
+
*/
|
2871
|
+
clearMemory() {
|
2872
|
+
this.taskExecutor.clearMemory();
|
2873
|
+
}
|
2592
2874
|
};
|
2593
2875
|
export {
|
2594
2876
|
PageAgent
|