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
@@ -660,6 +660,94 @@ var replanningCountLimit = 10;
|
|
660
660
|
var isAndroidPage = (page) => {
|
661
661
|
return page.pageType === "android";
|
662
662
|
};
|
663
|
+
var WorkflowMemory = class {
|
664
|
+
constructor(config) {
|
665
|
+
this.workflows = /* @__PURE__ */ new Map();
|
666
|
+
this.config = config;
|
667
|
+
}
|
668
|
+
/**
|
669
|
+
* İş akışı hafızasını getirir
|
670
|
+
*/
|
671
|
+
getWorkflowMemory(workflowId = "default") {
|
672
|
+
const workflow = this.workflows.get(workflowId);
|
673
|
+
return workflow?.memory || [];
|
674
|
+
}
|
675
|
+
/**
|
676
|
+
* İş akışı verilerini getirir
|
677
|
+
*/
|
678
|
+
getWorkflowData(workflowId = "default") {
|
679
|
+
return this.workflows.get(workflowId) || this.createEmptyWorkflowData(workflowId);
|
680
|
+
}
|
681
|
+
/**
|
682
|
+
* İş akışı hafızasını kaydeder
|
683
|
+
*/
|
684
|
+
saveWorkflowMemory(memory, workflowId = "default") {
|
685
|
+
const workflow = this.workflows.get(workflowId) || this.createEmptyWorkflowData(workflowId);
|
686
|
+
workflow.memory = [...memory];
|
687
|
+
workflow.metadata.totalSteps = workflow.steps.length;
|
688
|
+
workflow.metadata.completedSteps = workflow.steps.filter((s) => s.status === "completed").length;
|
689
|
+
workflow.metadata.failedSteps = workflow.steps.filter((s) => s.status === "failed").length;
|
690
|
+
this.workflows.set(workflowId, workflow);
|
691
|
+
this.enforceRetentionPolicy();
|
692
|
+
}
|
693
|
+
/**
|
694
|
+
* İş akışı bağlamını günceller
|
695
|
+
*/
|
696
|
+
updateWorkflowContext(context, workflowId = "default") {
|
697
|
+
const workflow = this.workflows.get(workflowId) || this.createEmptyWorkflowData(workflowId);
|
698
|
+
workflow.context = { ...workflow.context, ...context };
|
699
|
+
if (context.currentStep) {
|
700
|
+
const existingStep = workflow.steps.find((s) => s.stepName === context.currentStep);
|
701
|
+
if (!existingStep) {
|
702
|
+
workflow.steps.push({
|
703
|
+
stepId: `step_${workflow.steps.length + 1}`,
|
704
|
+
stepName: context.currentStep,
|
705
|
+
timestamp: context.timestamp,
|
706
|
+
status: "running",
|
707
|
+
memoryItems: []
|
708
|
+
});
|
709
|
+
}
|
710
|
+
}
|
711
|
+
this.workflows.set(workflowId, workflow);
|
712
|
+
}
|
713
|
+
/**
|
714
|
+
* İş akışını temizler
|
715
|
+
*/
|
716
|
+
clearWorkflow(workflowId = "default") {
|
717
|
+
this.workflows.delete(workflowId);
|
718
|
+
}
|
719
|
+
/**
|
720
|
+
* Tüm iş akışlarını temizler
|
721
|
+
*/
|
722
|
+
clearAll() {
|
723
|
+
this.workflows.clear();
|
724
|
+
}
|
725
|
+
createEmptyWorkflowData(workflowId) {
|
726
|
+
return {
|
727
|
+
workflowId,
|
728
|
+
steps: [],
|
729
|
+
memory: [],
|
730
|
+
context: {
|
731
|
+
pageInfo: { url: "", title: "" },
|
732
|
+
timestamp: Date.now()
|
733
|
+
},
|
734
|
+
metadata: {
|
735
|
+
totalSteps: 0,
|
736
|
+
completedSteps: 0,
|
737
|
+
failedSteps: 0,
|
738
|
+
startTime: Date.now()
|
739
|
+
}
|
740
|
+
};
|
741
|
+
}
|
742
|
+
enforceRetentionPolicy() {
|
743
|
+
const maxWorkflows = 10;
|
744
|
+
if (this.workflows.size > maxWorkflows) {
|
745
|
+
const sortedWorkflows = Array.from(this.workflows.entries()).sort(([, a], [, b]) => (b.metadata.endTime || b.metadata.startTime) - (a.metadata.endTime || a.metadata.startTime));
|
746
|
+
const toDelete = sortedWorkflows.slice(maxWorkflows);
|
747
|
+
toDelete.forEach(([workflowId]) => this.workflows.delete(workflowId));
|
748
|
+
}
|
749
|
+
}
|
750
|
+
};
|
663
751
|
var PageTaskExecutor = class {
|
664
752
|
constructor(page, insight, opts) {
|
665
753
|
this.conversationHistory = [];
|
@@ -667,6 +755,25 @@ var PageTaskExecutor = class {
|
|
667
755
|
this.insight = insight;
|
668
756
|
this.taskCache = opts.taskCache;
|
669
757
|
this.onTaskStartCallback = opts?.onTaskStart;
|
758
|
+
this.memoryConfig = {
|
759
|
+
maxItems: 100,
|
760
|
+
maxAge: 2 * 60 * 60 * 1e3,
|
761
|
+
// 2 saat
|
762
|
+
enablePersistence: true,
|
763
|
+
enableAnalytics: true,
|
764
|
+
filterStrategy: "hybrid",
|
765
|
+
...opts?.memoryConfig
|
766
|
+
};
|
767
|
+
this.sessionContext = {
|
768
|
+
sessionId: opts?.sessionId || this.generateSessionId(),
|
769
|
+
workflowId: opts?.workflowId,
|
770
|
+
startTime: Date.now(),
|
771
|
+
pageInfo: {
|
772
|
+
url: "",
|
773
|
+
title: ""
|
774
|
+
}
|
775
|
+
};
|
776
|
+
this.workflowMemory = new WorkflowMemory(this.memoryConfig);
|
670
777
|
}
|
671
778
|
async recordScreenshot(timing) {
|
672
779
|
const base64 = await this.page.screenshotBase64();
|
@@ -879,8 +986,11 @@ var PageTaskExecutor = class {
|
|
879
986
|
insightDump = dump;
|
880
987
|
};
|
881
988
|
this.insight.onceDumpUpdatedFn = dumpCollector;
|
989
|
+
const memoryContext = this.getMemoryAsContext();
|
882
990
|
const assertion = await this.insight.assert(
|
883
|
-
assertPlan.param.assertion
|
991
|
+
assertPlan.param.assertion,
|
992
|
+
memoryContext
|
993
|
+
// Hafıza bağlamını geç
|
884
994
|
);
|
885
995
|
if (!assertion.pass) {
|
886
996
|
if (plan2.type === "Assert") {
|
@@ -1366,25 +1476,146 @@ var PageTaskExecutor = class {
|
|
1366
1476
|
};
|
1367
1477
|
return task;
|
1368
1478
|
}
|
1479
|
+
/**
|
1480
|
+
* Persistent executor'ı getirir veya oluşturur
|
1481
|
+
*/
|
1482
|
+
getPersistentExecutor() {
|
1483
|
+
if (!this.persistentExecutor || this.persistentExecutor.status === "error") {
|
1484
|
+
const previousMemory = this.workflowMemory.getWorkflowMemory(this.sessionContext.workflowId);
|
1485
|
+
this.persistentExecutor = new import_misoai_core.Executor("Persistent Task Executor", {
|
1486
|
+
onTaskStart: this.onTaskStartCallback,
|
1487
|
+
initialMemory: previousMemory
|
1488
|
+
});
|
1489
|
+
}
|
1490
|
+
return this.persistentExecutor;
|
1491
|
+
}
|
1492
|
+
/**
|
1493
|
+
* Sayfa bağlamını günceller
|
1494
|
+
*/
|
1495
|
+
async updatePageContext() {
|
1496
|
+
try {
|
1497
|
+
if (this.page.url) {
|
1498
|
+
this.sessionContext.pageInfo.url = await this.page.url();
|
1499
|
+
}
|
1500
|
+
if (this.page.pageType === "puppeteer" || this.page.pageType === "playwright") {
|
1501
|
+
this.sessionContext.pageInfo.title = await this.page.title();
|
1502
|
+
}
|
1503
|
+
} catch (e) {
|
1504
|
+
}
|
1505
|
+
}
|
1506
|
+
/**
|
1507
|
+
* Hafızayı temizler
|
1508
|
+
*/
|
1509
|
+
clearMemory() {
|
1510
|
+
if (this.persistentExecutor) {
|
1511
|
+
this.persistentExecutor.clearMemory();
|
1512
|
+
}
|
1513
|
+
this.workflowMemory.clearWorkflow(this.sessionContext.workflowId || "default");
|
1514
|
+
}
|
1515
|
+
/**
|
1516
|
+
* Mevcut hafızayı döndürür
|
1517
|
+
*/
|
1518
|
+
getMemory() {
|
1519
|
+
return this.persistentExecutor?.getMemory() || [];
|
1520
|
+
}
|
1521
|
+
/**
|
1522
|
+
* İş akışı hafızasını döndürür
|
1523
|
+
*/
|
1524
|
+
getWorkflowMemory() {
|
1525
|
+
return this.workflowMemory.getWorkflowData(this.sessionContext.workflowId || "default");
|
1526
|
+
}
|
1527
|
+
/**
|
1528
|
+
* Hafıza istatistiklerini döndürür
|
1529
|
+
*/
|
1530
|
+
getMemoryStats() {
|
1531
|
+
return this.persistentExecutor?.getMemoryStats() || {
|
1532
|
+
totalItems: 0,
|
1533
|
+
analytics: { totalTasks: 0, memoryHits: 0, memoryMisses: 0, averageMemorySize: 0, memoryEffectiveness: 0 },
|
1534
|
+
config: this.memoryConfig
|
1535
|
+
};
|
1536
|
+
}
|
1537
|
+
/**
|
1538
|
+
* Hafıza konfigürasyonunu günceller
|
1539
|
+
*/
|
1540
|
+
updateMemoryConfig(config) {
|
1541
|
+
this.memoryConfig = { ...this.memoryConfig, ...config };
|
1542
|
+
if (this.persistentExecutor) {
|
1543
|
+
this.persistentExecutor.updateMemoryConfig(this.memoryConfig);
|
1544
|
+
}
|
1545
|
+
}
|
1546
|
+
/**
|
1547
|
+
* Oturum ID'sini oluşturur
|
1548
|
+
*/
|
1549
|
+
generateSessionId() {
|
1550
|
+
return `session_${Date.now()}_${Math.random().toString(36).substr(2, 8)}`;
|
1551
|
+
}
|
1552
|
+
/**
|
1553
|
+
* Hafızayı bağlam olarak formatlar
|
1554
|
+
*/
|
1555
|
+
getMemoryAsContext() {
|
1556
|
+
const memory = this.getMemory();
|
1557
|
+
if (memory.length === 0) {
|
1558
|
+
return "";
|
1559
|
+
}
|
1560
|
+
const recentMemory = memory.slice(-5);
|
1561
|
+
return recentMemory.map((item) => `- ${item.summary}`).join("\n");
|
1562
|
+
}
|
1369
1563
|
async runPlans(title, plans, opts) {
|
1370
|
-
|
1371
|
-
|
1372
|
-
|
1564
|
+
await this.updatePageContext();
|
1565
|
+
const useMemory = opts?.useMemory !== false;
|
1566
|
+
let taskExecutor;
|
1567
|
+
if (useMemory) {
|
1568
|
+
taskExecutor = this.getPersistentExecutor();
|
1569
|
+
this.workflowMemory.updateWorkflowContext({
|
1570
|
+
currentStep: title,
|
1571
|
+
pageInfo: this.sessionContext.pageInfo,
|
1572
|
+
timestamp: Date.now()
|
1573
|
+
}, this.sessionContext.workflowId || "default");
|
1574
|
+
} else {
|
1575
|
+
taskExecutor = new import_misoai_core.Executor(title, {
|
1576
|
+
onTaskStart: this.onTaskStartCallback
|
1577
|
+
});
|
1578
|
+
}
|
1373
1579
|
const { tasks } = await this.convertPlanToExecutable(plans, opts);
|
1580
|
+
tasks.forEach((task) => {
|
1581
|
+
task.context = {
|
1582
|
+
...task.context,
|
1583
|
+
...this.sessionContext.pageInfo,
|
1584
|
+
workflowId: this.sessionContext.workflowId,
|
1585
|
+
sessionId: this.sessionContext.sessionId
|
1586
|
+
};
|
1587
|
+
});
|
1374
1588
|
await taskExecutor.append(tasks);
|
1375
1589
|
const result = await taskExecutor.flush();
|
1590
|
+
if (useMemory) {
|
1591
|
+
this.workflowMemory.saveWorkflowMemory(
|
1592
|
+
taskExecutor.getMemory(),
|
1593
|
+
this.sessionContext.workflowId || "default"
|
1594
|
+
);
|
1595
|
+
}
|
1376
1596
|
return {
|
1377
1597
|
output: result,
|
1378
1598
|
executor: taskExecutor
|
1379
1599
|
};
|
1380
1600
|
}
|
1381
1601
|
async action(userPrompt, actionContext, opts) {
|
1382
|
-
const
|
1383
|
-
|
1384
|
-
|
1385
|
-
|
1602
|
+
const useMemory = true;
|
1603
|
+
let taskExecutor;
|
1604
|
+
if (useMemory) {
|
1605
|
+
taskExecutor = this.getPersistentExecutor();
|
1606
|
+
} else {
|
1607
|
+
taskExecutor = new import_misoai_core.Executor(taskTitleStr("Action", userPrompt), {
|
1608
|
+
onTaskStart: this.onTaskStartCallback
|
1609
|
+
});
|
1610
|
+
}
|
1611
|
+
const memoryContext = this.getMemoryAsContext();
|
1612
|
+
const initialLog = memoryContext ? memoryContext : void 0;
|
1613
|
+
let planningTask = this.planningTaskFromPrompt(userPrompt, initialLog, actionContext);
|
1386
1614
|
let replanCount = 0;
|
1387
1615
|
const logList = [];
|
1616
|
+
if (memoryContext) {
|
1617
|
+
logList.push(memoryContext);
|
1618
|
+
}
|
1388
1619
|
const yamlFlow = [];
|
1389
1620
|
while (planningTask) {
|
1390
1621
|
if (replanCount > replanningCountLimit) {
|
@@ -1494,15 +1725,21 @@ var PageTaskExecutor = class {
|
|
1494
1725
|
};
|
1495
1726
|
}
|
1496
1727
|
async createTypeQueryTask(type, demand, opt) {
|
1497
|
-
const
|
1498
|
-
|
1499
|
-
|
1500
|
-
|
1501
|
-
|
1502
|
-
|
1503
|
-
|
1504
|
-
|
1505
|
-
|
1728
|
+
const useMemory = true;
|
1729
|
+
let taskExecutor;
|
1730
|
+
if (useMemory) {
|
1731
|
+
taskExecutor = this.getPersistentExecutor();
|
1732
|
+
} else {
|
1733
|
+
taskExecutor = new import_misoai_core.Executor(
|
1734
|
+
taskTitleStr(
|
1735
|
+
type,
|
1736
|
+
typeof demand === "string" ? demand : JSON.stringify(demand)
|
1737
|
+
),
|
1738
|
+
{
|
1739
|
+
onTaskStart: this.onTaskStartCallback
|
1740
|
+
}
|
1741
|
+
);
|
1742
|
+
}
|
1506
1743
|
const queryTask = {
|
1507
1744
|
type: "Insight",
|
1508
1745
|
subType: type,
|
@@ -1524,9 +1761,12 @@ var PageTaskExecutor = class {
|
|
1524
1761
|
result: `${type}, ${demand}`
|
1525
1762
|
};
|
1526
1763
|
}
|
1764
|
+
const memoryContext = this.getMemoryAsContext();
|
1527
1765
|
const { data, usage } = await this.insight.extract(
|
1528
1766
|
demandInput,
|
1529
|
-
opt
|
1767
|
+
opt,
|
1768
|
+
memoryContext
|
1769
|
+
// Hafıza bağlamını geç
|
1530
1770
|
);
|
1531
1771
|
let outputResult = data;
|
1532
1772
|
if (ifTypeRestricted) {
|
@@ -1559,11 +1799,17 @@ var PageTaskExecutor = class {
|
|
1559
1799
|
async string(prompt, opt) {
|
1560
1800
|
return this.createTypeQueryTask("String", prompt, opt);
|
1561
1801
|
}
|
1562
|
-
async assert(assertion) {
|
1802
|
+
async assert(assertion, memoryContext) {
|
1563
1803
|
const description = `assert: ${assertion}`;
|
1564
|
-
const
|
1565
|
-
|
1566
|
-
|
1804
|
+
const useMemory = true;
|
1805
|
+
let taskExecutor;
|
1806
|
+
if (useMemory) {
|
1807
|
+
taskExecutor = this.getPersistentExecutor();
|
1808
|
+
} else {
|
1809
|
+
taskExecutor = new import_misoai_core.Executor(taskTitleStr("Assert", description), {
|
1810
|
+
onTaskStart: this.onTaskStartCallback
|
1811
|
+
});
|
1812
|
+
}
|
1567
1813
|
const assertionPlan = {
|
1568
1814
|
type: "Assert",
|
1569
1815
|
param: {
|
@@ -1773,7 +2019,7 @@ var import_js_yaml3 = __toESM(require("js-yaml"));
|
|
1773
2019
|
var import_semver = __toESM(require("semver"));
|
1774
2020
|
|
1775
2021
|
// package.json
|
1776
|
-
var version = "1.
|
2022
|
+
var version = "1.5.7";
|
1777
2023
|
|
1778
2024
|
// src/common/task-cache.ts
|
1779
2025
|
var debug3 = (0, import_logger3.getDebug)("cache");
|
@@ -2260,7 +2506,13 @@ var PageAgent = class {
|
|
2260
2506
|
metadata: metadata2
|
2261
2507
|
};
|
2262
2508
|
}
|
2263
|
-
const
|
2509
|
+
const memoryContext = this.getMemoryAsContext();
|
2510
|
+
const enhancedActionContext = this.opts.aiActionContext ? `${this.opts.aiActionContext}
|
2511
|
+
|
2512
|
+
Previous workflow steps:
|
2513
|
+
${memoryContext}` : memoryContext ? `Previous workflow steps:
|
2514
|
+
${memoryContext}` : void 0;
|
2515
|
+
const { output, executor } = await (isVlmUiTars ? this.taskExecutor.actionToGoal(taskPrompt, { cacheable }) : this.taskExecutor.action(taskPrompt, enhancedActionContext, {
|
2264
2516
|
cacheable
|
2265
2517
|
}));
|
2266
2518
|
if (this.taskCache && output?.yamlFlow && cacheable !== false) {
|
@@ -2406,8 +2658,9 @@ var PageAgent = class {
|
|
2406
2658
|
} catch (e) {
|
2407
2659
|
}
|
2408
2660
|
}
|
2661
|
+
const memoryContext = this.getMemoryAsContext();
|
2409
2662
|
const assertionWithContext = currentUrl ? `For the page at URL "${currentUrl}", ${assertion}` : assertion;
|
2410
|
-
const { output, executor } = await this.taskExecutor.assert(assertionWithContext);
|
2663
|
+
const { output, executor } = await this.taskExecutor.assert(assertionWithContext, memoryContext);
|
2411
2664
|
const metadata = this.afterTaskRunning(executor, true);
|
2412
2665
|
if (output && opt?.keepRawResponse) {
|
2413
2666
|
return {
|
@@ -2654,6 +2907,35 @@ ${errors}`);
|
|
2654
2907
|
async destroy() {
|
2655
2908
|
await this.page.destroy();
|
2656
2909
|
}
|
2910
|
+
/**
|
2911
|
+
* Hafızayı bağlam olarak formatlar
|
2912
|
+
*/
|
2913
|
+
getMemoryAsContext() {
|
2914
|
+
const memory = this.taskExecutor.getMemory();
|
2915
|
+
if (memory.length === 0) {
|
2916
|
+
return "";
|
2917
|
+
}
|
2918
|
+
const recentMemory = memory.slice(-5);
|
2919
|
+
return recentMemory.map((item) => `- ${item.summary}`).join("\n");
|
2920
|
+
}
|
2921
|
+
/**
|
2922
|
+
* Mevcut hafızayı döndürür
|
2923
|
+
*/
|
2924
|
+
getMemory() {
|
2925
|
+
return this.taskExecutor.getMemory();
|
2926
|
+
}
|
2927
|
+
/**
|
2928
|
+
* Hafıza istatistiklerini döndürür
|
2929
|
+
*/
|
2930
|
+
getMemoryStats() {
|
2931
|
+
return this.taskExecutor.getMemoryStats();
|
2932
|
+
}
|
2933
|
+
/**
|
2934
|
+
* Hafızayı temizler
|
2935
|
+
*/
|
2936
|
+
clearMemory() {
|
2937
|
+
this.taskExecutor.clearMemory();
|
2938
|
+
}
|
2657
2939
|
};
|
2658
2940
|
|
2659
2941
|
// src/chrome-extension/agent.ts
|
@@ -2871,7 +3153,7 @@ function sleep2(ms) {
|
|
2871
3153
|
var ChromeExtensionProxyPage = class {
|
2872
3154
|
constructor(forceSameTabNavigation) {
|
2873
3155
|
this.pageType = "chrome-extension-proxy";
|
2874
|
-
this.version = "1.
|
3156
|
+
this.version = "1.5.7";
|
2875
3157
|
this.activeTabId = null;
|
2876
3158
|
this.tabIdOfDebuggerAttached = null;
|
2877
3159
|
this.attachingDebugger = null;
|