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