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