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/index.js
CHANGED
@@ -623,6 +623,94 @@ var replanningCountLimit = 10;
|
|
623
623
|
var isAndroidPage = (page) => {
|
624
624
|
return page.pageType === "android";
|
625
625
|
};
|
626
|
+
var WorkflowMemory = class {
|
627
|
+
constructor(config) {
|
628
|
+
this.workflows = /* @__PURE__ */ new Map();
|
629
|
+
this.config = config;
|
630
|
+
}
|
631
|
+
/**
|
632
|
+
* İş akışı hafızasını getirir
|
633
|
+
*/
|
634
|
+
getWorkflowMemory(workflowId = "default") {
|
635
|
+
const workflow = this.workflows.get(workflowId);
|
636
|
+
return workflow?.memory || [];
|
637
|
+
}
|
638
|
+
/**
|
639
|
+
* İş akışı verilerini getirir
|
640
|
+
*/
|
641
|
+
getWorkflowData(workflowId = "default") {
|
642
|
+
return this.workflows.get(workflowId) || this.createEmptyWorkflowData(workflowId);
|
643
|
+
}
|
644
|
+
/**
|
645
|
+
* İş akışı hafızasını kaydeder
|
646
|
+
*/
|
647
|
+
saveWorkflowMemory(memory, workflowId = "default") {
|
648
|
+
const workflow = this.workflows.get(workflowId) || this.createEmptyWorkflowData(workflowId);
|
649
|
+
workflow.memory = [...memory];
|
650
|
+
workflow.metadata.totalSteps = workflow.steps.length;
|
651
|
+
workflow.metadata.completedSteps = workflow.steps.filter((s) => s.status === "completed").length;
|
652
|
+
workflow.metadata.failedSteps = workflow.steps.filter((s) => s.status === "failed").length;
|
653
|
+
this.workflows.set(workflowId, workflow);
|
654
|
+
this.enforceRetentionPolicy();
|
655
|
+
}
|
656
|
+
/**
|
657
|
+
* İş akışı bağlamını günceller
|
658
|
+
*/
|
659
|
+
updateWorkflowContext(context, workflowId = "default") {
|
660
|
+
const workflow = this.workflows.get(workflowId) || this.createEmptyWorkflowData(workflowId);
|
661
|
+
workflow.context = { ...workflow.context, ...context };
|
662
|
+
if (context.currentStep) {
|
663
|
+
const existingStep = workflow.steps.find((s) => s.stepName === context.currentStep);
|
664
|
+
if (!existingStep) {
|
665
|
+
workflow.steps.push({
|
666
|
+
stepId: `step_${workflow.steps.length + 1}`,
|
667
|
+
stepName: context.currentStep,
|
668
|
+
timestamp: context.timestamp,
|
669
|
+
status: "running",
|
670
|
+
memoryItems: []
|
671
|
+
});
|
672
|
+
}
|
673
|
+
}
|
674
|
+
this.workflows.set(workflowId, workflow);
|
675
|
+
}
|
676
|
+
/**
|
677
|
+
* İş akışını temizler
|
678
|
+
*/
|
679
|
+
clearWorkflow(workflowId = "default") {
|
680
|
+
this.workflows.delete(workflowId);
|
681
|
+
}
|
682
|
+
/**
|
683
|
+
* Tüm iş akışlarını temizler
|
684
|
+
*/
|
685
|
+
clearAll() {
|
686
|
+
this.workflows.clear();
|
687
|
+
}
|
688
|
+
createEmptyWorkflowData(workflowId) {
|
689
|
+
return {
|
690
|
+
workflowId,
|
691
|
+
steps: [],
|
692
|
+
memory: [],
|
693
|
+
context: {
|
694
|
+
pageInfo: { url: "", title: "" },
|
695
|
+
timestamp: Date.now()
|
696
|
+
},
|
697
|
+
metadata: {
|
698
|
+
totalSteps: 0,
|
699
|
+
completedSteps: 0,
|
700
|
+
failedSteps: 0,
|
701
|
+
startTime: Date.now()
|
702
|
+
}
|
703
|
+
};
|
704
|
+
}
|
705
|
+
enforceRetentionPolicy() {
|
706
|
+
const maxWorkflows = 10;
|
707
|
+
if (this.workflows.size > maxWorkflows) {
|
708
|
+
const sortedWorkflows = Array.from(this.workflows.entries()).sort(([, a], [, b]) => (b.metadata.endTime || b.metadata.startTime) - (a.metadata.endTime || a.metadata.startTime));
|
709
|
+
const toDelete = sortedWorkflows.slice(maxWorkflows);
|
710
|
+
toDelete.forEach(([workflowId]) => this.workflows.delete(workflowId));
|
711
|
+
}
|
712
|
+
}
|
713
|
+
};
|
626
714
|
var PageTaskExecutor = class {
|
627
715
|
constructor(page, insight, opts) {
|
628
716
|
this.conversationHistory = [];
|
@@ -630,6 +718,25 @@ var PageTaskExecutor = class {
|
|
630
718
|
this.insight = insight;
|
631
719
|
this.taskCache = opts.taskCache;
|
632
720
|
this.onTaskStartCallback = opts?.onTaskStart;
|
721
|
+
this.memoryConfig = {
|
722
|
+
maxItems: 100,
|
723
|
+
maxAge: 2 * 60 * 60 * 1e3,
|
724
|
+
// 2 saat
|
725
|
+
enablePersistence: true,
|
726
|
+
enableAnalytics: true,
|
727
|
+
filterStrategy: "hybrid",
|
728
|
+
...opts?.memoryConfig
|
729
|
+
};
|
730
|
+
this.sessionContext = {
|
731
|
+
sessionId: opts?.sessionId || this.generateSessionId(),
|
732
|
+
workflowId: opts?.workflowId,
|
733
|
+
startTime: Date.now(),
|
734
|
+
pageInfo: {
|
735
|
+
url: "",
|
736
|
+
title: ""
|
737
|
+
}
|
738
|
+
};
|
739
|
+
this.workflowMemory = new WorkflowMemory(this.memoryConfig);
|
633
740
|
}
|
634
741
|
async recordScreenshot(timing) {
|
635
742
|
const base64 = await this.page.screenshotBase64();
|
@@ -842,8 +949,11 @@ var PageTaskExecutor = class {
|
|
842
949
|
insightDump = dump;
|
843
950
|
};
|
844
951
|
this.insight.onceDumpUpdatedFn = dumpCollector;
|
952
|
+
const memoryContext = this.getMemoryAsContext();
|
845
953
|
const assertion = await this.insight.assert(
|
846
|
-
assertPlan.param.assertion
|
954
|
+
assertPlan.param.assertion,
|
955
|
+
memoryContext
|
956
|
+
// Hafıza bağlamını geç
|
847
957
|
);
|
848
958
|
if (!assertion.pass) {
|
849
959
|
if (plan2.type === "Assert") {
|
@@ -1329,25 +1439,146 @@ var PageTaskExecutor = class {
|
|
1329
1439
|
};
|
1330
1440
|
return task;
|
1331
1441
|
}
|
1442
|
+
/**
|
1443
|
+
* Persistent executor'ı getirir veya oluşturur
|
1444
|
+
*/
|
1445
|
+
getPersistentExecutor() {
|
1446
|
+
if (!this.persistentExecutor || this.persistentExecutor.status === "error") {
|
1447
|
+
const previousMemory = this.workflowMemory.getWorkflowMemory(this.sessionContext.workflowId);
|
1448
|
+
this.persistentExecutor = new Executor("Persistent Task Executor", {
|
1449
|
+
onTaskStart: this.onTaskStartCallback,
|
1450
|
+
initialMemory: previousMemory
|
1451
|
+
});
|
1452
|
+
}
|
1453
|
+
return this.persistentExecutor;
|
1454
|
+
}
|
1455
|
+
/**
|
1456
|
+
* Sayfa bağlamını günceller
|
1457
|
+
*/
|
1458
|
+
async updatePageContext() {
|
1459
|
+
try {
|
1460
|
+
if (this.page.url) {
|
1461
|
+
this.sessionContext.pageInfo.url = await this.page.url();
|
1462
|
+
}
|
1463
|
+
if (this.page.pageType === "puppeteer" || this.page.pageType === "playwright") {
|
1464
|
+
this.sessionContext.pageInfo.title = await this.page.title();
|
1465
|
+
}
|
1466
|
+
} catch (e) {
|
1467
|
+
}
|
1468
|
+
}
|
1469
|
+
/**
|
1470
|
+
* Hafızayı temizler
|
1471
|
+
*/
|
1472
|
+
clearMemory() {
|
1473
|
+
if (this.persistentExecutor) {
|
1474
|
+
this.persistentExecutor.clearMemory();
|
1475
|
+
}
|
1476
|
+
this.workflowMemory.clearWorkflow(this.sessionContext.workflowId || "default");
|
1477
|
+
}
|
1478
|
+
/**
|
1479
|
+
* Mevcut hafızayı döndürür
|
1480
|
+
*/
|
1481
|
+
getMemory() {
|
1482
|
+
return this.persistentExecutor?.getMemory() || [];
|
1483
|
+
}
|
1484
|
+
/**
|
1485
|
+
* İş akışı hafızasını döndürür
|
1486
|
+
*/
|
1487
|
+
getWorkflowMemory() {
|
1488
|
+
return this.workflowMemory.getWorkflowData(this.sessionContext.workflowId || "default");
|
1489
|
+
}
|
1490
|
+
/**
|
1491
|
+
* Hafıza istatistiklerini döndürür
|
1492
|
+
*/
|
1493
|
+
getMemoryStats() {
|
1494
|
+
return this.persistentExecutor?.getMemoryStats() || {
|
1495
|
+
totalItems: 0,
|
1496
|
+
analytics: { totalTasks: 0, memoryHits: 0, memoryMisses: 0, averageMemorySize: 0, memoryEffectiveness: 0 },
|
1497
|
+
config: this.memoryConfig
|
1498
|
+
};
|
1499
|
+
}
|
1500
|
+
/**
|
1501
|
+
* Hafıza konfigürasyonunu günceller
|
1502
|
+
*/
|
1503
|
+
updateMemoryConfig(config) {
|
1504
|
+
this.memoryConfig = { ...this.memoryConfig, ...config };
|
1505
|
+
if (this.persistentExecutor) {
|
1506
|
+
this.persistentExecutor.updateMemoryConfig(this.memoryConfig);
|
1507
|
+
}
|
1508
|
+
}
|
1509
|
+
/**
|
1510
|
+
* Oturum ID'sini oluşturur
|
1511
|
+
*/
|
1512
|
+
generateSessionId() {
|
1513
|
+
return `session_${Date.now()}_${Math.random().toString(36).substr(2, 8)}`;
|
1514
|
+
}
|
1515
|
+
/**
|
1516
|
+
* Hafızayı bağlam olarak formatlar
|
1517
|
+
*/
|
1518
|
+
getMemoryAsContext() {
|
1519
|
+
const memory = this.getMemory();
|
1520
|
+
if (memory.length === 0) {
|
1521
|
+
return "";
|
1522
|
+
}
|
1523
|
+
const recentMemory = memory.slice(-5);
|
1524
|
+
return recentMemory.map((item) => `- ${item.summary}`).join("\n");
|
1525
|
+
}
|
1332
1526
|
async runPlans(title, plans, opts) {
|
1333
|
-
|
1334
|
-
|
1335
|
-
|
1527
|
+
await this.updatePageContext();
|
1528
|
+
const useMemory = opts?.useMemory !== false;
|
1529
|
+
let taskExecutor;
|
1530
|
+
if (useMemory) {
|
1531
|
+
taskExecutor = this.getPersistentExecutor();
|
1532
|
+
this.workflowMemory.updateWorkflowContext({
|
1533
|
+
currentStep: title,
|
1534
|
+
pageInfo: this.sessionContext.pageInfo,
|
1535
|
+
timestamp: Date.now()
|
1536
|
+
}, this.sessionContext.workflowId || "default");
|
1537
|
+
} else {
|
1538
|
+
taskExecutor = new Executor(title, {
|
1539
|
+
onTaskStart: this.onTaskStartCallback
|
1540
|
+
});
|
1541
|
+
}
|
1336
1542
|
const { tasks } = await this.convertPlanToExecutable(plans, opts);
|
1543
|
+
tasks.forEach((task) => {
|
1544
|
+
task.context = {
|
1545
|
+
...task.context,
|
1546
|
+
...this.sessionContext.pageInfo,
|
1547
|
+
workflowId: this.sessionContext.workflowId,
|
1548
|
+
sessionId: this.sessionContext.sessionId
|
1549
|
+
};
|
1550
|
+
});
|
1337
1551
|
await taskExecutor.append(tasks);
|
1338
1552
|
const result = await taskExecutor.flush();
|
1553
|
+
if (useMemory) {
|
1554
|
+
this.workflowMemory.saveWorkflowMemory(
|
1555
|
+
taskExecutor.getMemory(),
|
1556
|
+
this.sessionContext.workflowId || "default"
|
1557
|
+
);
|
1558
|
+
}
|
1339
1559
|
return {
|
1340
1560
|
output: result,
|
1341
1561
|
executor: taskExecutor
|
1342
1562
|
};
|
1343
1563
|
}
|
1344
1564
|
async action(userPrompt, actionContext, opts) {
|
1345
|
-
const
|
1346
|
-
|
1347
|
-
|
1348
|
-
|
1565
|
+
const useMemory = true;
|
1566
|
+
let taskExecutor;
|
1567
|
+
if (useMemory) {
|
1568
|
+
taskExecutor = this.getPersistentExecutor();
|
1569
|
+
} else {
|
1570
|
+
taskExecutor = new Executor(taskTitleStr("Action", userPrompt), {
|
1571
|
+
onTaskStart: this.onTaskStartCallback
|
1572
|
+
});
|
1573
|
+
}
|
1574
|
+
const memoryContext = this.getMemoryAsContext();
|
1575
|
+
const initialLog = memoryContext ? memoryContext : void 0;
|
1576
|
+
let planningTask = this.planningTaskFromPrompt(userPrompt, initialLog, actionContext);
|
1349
1577
|
let replanCount = 0;
|
1350
1578
|
const logList = [];
|
1579
|
+
if (memoryContext) {
|
1580
|
+
logList.push(memoryContext);
|
1581
|
+
}
|
1351
1582
|
const yamlFlow = [];
|
1352
1583
|
while (planningTask) {
|
1353
1584
|
if (replanCount > replanningCountLimit) {
|
@@ -1457,15 +1688,21 @@ var PageTaskExecutor = class {
|
|
1457
1688
|
};
|
1458
1689
|
}
|
1459
1690
|
async createTypeQueryTask(type, demand, opt) {
|
1460
|
-
const
|
1461
|
-
|
1462
|
-
|
1463
|
-
|
1464
|
-
|
1465
|
-
|
1466
|
-
|
1467
|
-
|
1468
|
-
|
1691
|
+
const useMemory = true;
|
1692
|
+
let taskExecutor;
|
1693
|
+
if (useMemory) {
|
1694
|
+
taskExecutor = this.getPersistentExecutor();
|
1695
|
+
} else {
|
1696
|
+
taskExecutor = new Executor(
|
1697
|
+
taskTitleStr(
|
1698
|
+
type,
|
1699
|
+
typeof demand === "string" ? demand : JSON.stringify(demand)
|
1700
|
+
),
|
1701
|
+
{
|
1702
|
+
onTaskStart: this.onTaskStartCallback
|
1703
|
+
}
|
1704
|
+
);
|
1705
|
+
}
|
1469
1706
|
const queryTask = {
|
1470
1707
|
type: "Insight",
|
1471
1708
|
subType: type,
|
@@ -1487,9 +1724,12 @@ var PageTaskExecutor = class {
|
|
1487
1724
|
result: `${type}, ${demand}`
|
1488
1725
|
};
|
1489
1726
|
}
|
1727
|
+
const memoryContext = this.getMemoryAsContext();
|
1490
1728
|
const { data, usage } = await this.insight.extract(
|
1491
1729
|
demandInput,
|
1492
|
-
opt
|
1730
|
+
opt,
|
1731
|
+
memoryContext
|
1732
|
+
// Hafıza bağlamını geç
|
1493
1733
|
);
|
1494
1734
|
let outputResult = data;
|
1495
1735
|
if (ifTypeRestricted) {
|
@@ -1522,11 +1762,17 @@ var PageTaskExecutor = class {
|
|
1522
1762
|
async string(prompt, opt) {
|
1523
1763
|
return this.createTypeQueryTask("String", prompt, opt);
|
1524
1764
|
}
|
1525
|
-
async assert(assertion) {
|
1765
|
+
async assert(assertion, memoryContext) {
|
1526
1766
|
const description = `assert: ${assertion}`;
|
1527
|
-
const
|
1528
|
-
|
1529
|
-
|
1767
|
+
const useMemory = true;
|
1768
|
+
let taskExecutor;
|
1769
|
+
if (useMemory) {
|
1770
|
+
taskExecutor = this.getPersistentExecutor();
|
1771
|
+
} else {
|
1772
|
+
taskExecutor = new Executor(taskTitleStr("Assert", description), {
|
1773
|
+
onTaskStart: this.onTaskStartCallback
|
1774
|
+
});
|
1775
|
+
}
|
1530
1776
|
const assertionPlan = {
|
1531
1777
|
type: "Assert",
|
1532
1778
|
param: {
|
@@ -1736,7 +1982,7 @@ import yaml3 from "js-yaml";
|
|
1736
1982
|
import semver from "semver";
|
1737
1983
|
|
1738
1984
|
// package.json
|
1739
|
-
var version = "1.
|
1985
|
+
var version = "1.5.7";
|
1740
1986
|
|
1741
1987
|
// src/common/task-cache.ts
|
1742
1988
|
var debug3 = getDebug3("cache");
|
@@ -2223,7 +2469,13 @@ var PageAgent = class {
|
|
2223
2469
|
metadata: metadata2
|
2224
2470
|
};
|
2225
2471
|
}
|
2226
|
-
const
|
2472
|
+
const memoryContext = this.getMemoryAsContext();
|
2473
|
+
const enhancedActionContext = this.opts.aiActionContext ? `${this.opts.aiActionContext}
|
2474
|
+
|
2475
|
+
Previous workflow steps:
|
2476
|
+
${memoryContext}` : memoryContext ? `Previous workflow steps:
|
2477
|
+
${memoryContext}` : void 0;
|
2478
|
+
const { output, executor } = await (isVlmUiTars ? this.taskExecutor.actionToGoal(taskPrompt, { cacheable }) : this.taskExecutor.action(taskPrompt, enhancedActionContext, {
|
2227
2479
|
cacheable
|
2228
2480
|
}));
|
2229
2481
|
if (this.taskCache && output?.yamlFlow && cacheable !== false) {
|
@@ -2369,8 +2621,9 @@ var PageAgent = class {
|
|
2369
2621
|
} catch (e) {
|
2370
2622
|
}
|
2371
2623
|
}
|
2624
|
+
const memoryContext = this.getMemoryAsContext();
|
2372
2625
|
const assertionWithContext = currentUrl ? `For the page at URL "${currentUrl}", ${assertion}` : assertion;
|
2373
|
-
const { output, executor } = await this.taskExecutor.assert(assertionWithContext);
|
2626
|
+
const { output, executor } = await this.taskExecutor.assert(assertionWithContext, memoryContext);
|
2374
2627
|
const metadata = this.afterTaskRunning(executor, true);
|
2375
2628
|
if (output && opt?.keepRawResponse) {
|
2376
2629
|
return {
|
@@ -2617,6 +2870,35 @@ ${errors}`);
|
|
2617
2870
|
async destroy() {
|
2618
2871
|
await this.page.destroy();
|
2619
2872
|
}
|
2873
|
+
/**
|
2874
|
+
* Hafızayı bağlam olarak formatlar
|
2875
|
+
*/
|
2876
|
+
getMemoryAsContext() {
|
2877
|
+
const memory = this.taskExecutor.getMemory();
|
2878
|
+
if (memory.length === 0) {
|
2879
|
+
return "";
|
2880
|
+
}
|
2881
|
+
const recentMemory = memory.slice(-5);
|
2882
|
+
return recentMemory.map((item) => `- ${item.summary}`).join("\n");
|
2883
|
+
}
|
2884
|
+
/**
|
2885
|
+
* Mevcut hafızayı döndürür
|
2886
|
+
*/
|
2887
|
+
getMemory() {
|
2888
|
+
return this.taskExecutor.getMemory();
|
2889
|
+
}
|
2890
|
+
/**
|
2891
|
+
* Hafıza istatistiklerini döndürür
|
2892
|
+
*/
|
2893
|
+
getMemoryStats() {
|
2894
|
+
return this.taskExecutor.getMemoryStats();
|
2895
|
+
}
|
2896
|
+
/**
|
2897
|
+
* Hafızayı temizler
|
2898
|
+
*/
|
2899
|
+
clearMemory() {
|
2900
|
+
this.taskExecutor.clearMemory();
|
2901
|
+
}
|
2620
2902
|
};
|
2621
2903
|
|
2622
2904
|
// src/puppeteer/base-page.ts
|