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