misoai-web 1.5.7 → 1.5.9
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 +410 -25
- package/dist/es/agent.js.map +1 -1
- package/dist/es/bridge-mode-browser.js +3 -3
- package/dist/es/bridge-mode.js +412 -27
- package/dist/es/bridge-mode.js.map +1 -1
- package/dist/es/chrome-extension.js +411 -26
- package/dist/es/chrome-extension.js.map +1 -1
- package/dist/es/index.js +410 -25
- package/dist/es/index.js.map +1 -1
- package/dist/es/midscene-playground.js +410 -25
- package/dist/es/midscene-playground.js.map +1 -1
- package/dist/es/playground.js +410 -25
- package/dist/es/playground.js.map +1 -1
- package/dist/es/playwright.js +410 -25
- package/dist/es/playwright.js.map +1 -1
- package/dist/es/puppeteer-agent-launcher.js +410 -25
- package/dist/es/puppeteer-agent-launcher.js.map +1 -1
- package/dist/es/puppeteer.js +410 -25
- package/dist/es/puppeteer.js.map +1 -1
- package/dist/lib/agent.js +410 -25
- package/dist/lib/agent.js.map +1 -1
- package/dist/lib/bridge-mode-browser.js +3 -3
- package/dist/lib/bridge-mode.js +412 -27
- package/dist/lib/bridge-mode.js.map +1 -1
- package/dist/lib/chrome-extension.js +411 -26
- package/dist/lib/chrome-extension.js.map +1 -1
- package/dist/lib/index.js +410 -25
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/midscene-playground.js +410 -25
- package/dist/lib/midscene-playground.js.map +1 -1
- package/dist/lib/playground.js +410 -25
- package/dist/lib/playground.js.map +1 -1
- package/dist/lib/playwright.js +410 -25
- package/dist/lib/playwright.js.map +1 -1
- package/dist/lib/puppeteer-agent-launcher.js +410 -25
- package/dist/lib/puppeteer-agent-launcher.js.map +1 -1
- package/dist/lib/puppeteer.js +410 -25
- package/dist/lib/puppeteer.js.map +1 -1
- package/dist/types/agent.d.ts +107 -2
- package/package.json +2 -2
package/dist/lib/agent.js
CHANGED
@@ -609,6 +609,94 @@ var replanningCountLimit = 10;
|
|
609
609
|
var isAndroidPage = (page) => {
|
610
610
|
return page.pageType === "android";
|
611
611
|
};
|
612
|
+
var WorkflowMemory = class {
|
613
|
+
constructor(config) {
|
614
|
+
this.workflows = /* @__PURE__ */ new Map();
|
615
|
+
this.config = config;
|
616
|
+
}
|
617
|
+
/**
|
618
|
+
* İş akışı hafızasını getirir
|
619
|
+
*/
|
620
|
+
getWorkflowMemory(workflowId = "default") {
|
621
|
+
const workflow = this.workflows.get(workflowId);
|
622
|
+
return workflow?.memory || [];
|
623
|
+
}
|
624
|
+
/**
|
625
|
+
* İş akışı verilerini getirir
|
626
|
+
*/
|
627
|
+
getWorkflowData(workflowId = "default") {
|
628
|
+
return this.workflows.get(workflowId) || this.createEmptyWorkflowData(workflowId);
|
629
|
+
}
|
630
|
+
/**
|
631
|
+
* İş akışı hafızasını kaydeder
|
632
|
+
*/
|
633
|
+
saveWorkflowMemory(memory, workflowId = "default") {
|
634
|
+
const workflow = this.workflows.get(workflowId) || this.createEmptyWorkflowData(workflowId);
|
635
|
+
workflow.memory = [...memory];
|
636
|
+
workflow.metadata.totalSteps = workflow.steps.length;
|
637
|
+
workflow.metadata.completedSteps = workflow.steps.filter((s) => s.status === "completed").length;
|
638
|
+
workflow.metadata.failedSteps = workflow.steps.filter((s) => s.status === "failed").length;
|
639
|
+
this.workflows.set(workflowId, workflow);
|
640
|
+
this.enforceRetentionPolicy();
|
641
|
+
}
|
642
|
+
/**
|
643
|
+
* İş akışı bağlamını günceller
|
644
|
+
*/
|
645
|
+
updateWorkflowContext(context, workflowId = "default") {
|
646
|
+
const workflow = this.workflows.get(workflowId) || this.createEmptyWorkflowData(workflowId);
|
647
|
+
workflow.context = { ...workflow.context, ...context };
|
648
|
+
if (context.currentStep) {
|
649
|
+
const existingStep = workflow.steps.find((s) => s.stepName === context.currentStep);
|
650
|
+
if (!existingStep) {
|
651
|
+
workflow.steps.push({
|
652
|
+
stepId: `step_${workflow.steps.length + 1}`,
|
653
|
+
stepName: context.currentStep,
|
654
|
+
timestamp: context.timestamp,
|
655
|
+
status: "running",
|
656
|
+
memoryItems: []
|
657
|
+
});
|
658
|
+
}
|
659
|
+
}
|
660
|
+
this.workflows.set(workflowId, workflow);
|
661
|
+
}
|
662
|
+
/**
|
663
|
+
* İş akışını temizler
|
664
|
+
*/
|
665
|
+
clearWorkflow(workflowId = "default") {
|
666
|
+
this.workflows.delete(workflowId);
|
667
|
+
}
|
668
|
+
/**
|
669
|
+
* Tüm iş akışlarını temizler
|
670
|
+
*/
|
671
|
+
clearAll() {
|
672
|
+
this.workflows.clear();
|
673
|
+
}
|
674
|
+
createEmptyWorkflowData(workflowId) {
|
675
|
+
return {
|
676
|
+
workflowId,
|
677
|
+
steps: [],
|
678
|
+
memory: [],
|
679
|
+
context: {
|
680
|
+
pageInfo: { url: "", title: "" },
|
681
|
+
timestamp: Date.now()
|
682
|
+
},
|
683
|
+
metadata: {
|
684
|
+
totalSteps: 0,
|
685
|
+
completedSteps: 0,
|
686
|
+
failedSteps: 0,
|
687
|
+
startTime: Date.now()
|
688
|
+
}
|
689
|
+
};
|
690
|
+
}
|
691
|
+
enforceRetentionPolicy() {
|
692
|
+
const maxWorkflows = 10;
|
693
|
+
if (this.workflows.size > maxWorkflows) {
|
694
|
+
const sortedWorkflows = Array.from(this.workflows.entries()).sort(([, a], [, b]) => (b.metadata.endTime || b.metadata.startTime) - (a.metadata.endTime || a.metadata.startTime));
|
695
|
+
const toDelete = sortedWorkflows.slice(maxWorkflows);
|
696
|
+
toDelete.forEach(([workflowId]) => this.workflows.delete(workflowId));
|
697
|
+
}
|
698
|
+
}
|
699
|
+
};
|
612
700
|
var PageTaskExecutor = class {
|
613
701
|
constructor(page, insight, opts) {
|
614
702
|
this.conversationHistory = [];
|
@@ -616,6 +704,25 @@ var PageTaskExecutor = class {
|
|
616
704
|
this.insight = insight;
|
617
705
|
this.taskCache = opts.taskCache;
|
618
706
|
this.onTaskStartCallback = opts?.onTaskStart;
|
707
|
+
this.memoryConfig = {
|
708
|
+
maxItems: 100,
|
709
|
+
maxAge: 2 * 60 * 60 * 1e3,
|
710
|
+
// 2 saat
|
711
|
+
enablePersistence: true,
|
712
|
+
enableAnalytics: true,
|
713
|
+
filterStrategy: "hybrid",
|
714
|
+
...opts?.memoryConfig
|
715
|
+
};
|
716
|
+
this.sessionContext = {
|
717
|
+
sessionId: opts?.sessionId || this.generateSessionId(),
|
718
|
+
workflowId: opts?.workflowId,
|
719
|
+
startTime: Date.now(),
|
720
|
+
pageInfo: {
|
721
|
+
url: "",
|
722
|
+
title: ""
|
723
|
+
}
|
724
|
+
};
|
725
|
+
this.workflowMemory = new WorkflowMemory(this.memoryConfig);
|
619
726
|
}
|
620
727
|
async recordScreenshot(timing) {
|
621
728
|
const base64 = await this.page.screenshotBase64();
|
@@ -828,8 +935,11 @@ var PageTaskExecutor = class {
|
|
828
935
|
insightDump = dump;
|
829
936
|
};
|
830
937
|
this.insight.onceDumpUpdatedFn = dumpCollector;
|
938
|
+
const memoryContext = this.getMemoryAsContext();
|
831
939
|
const assertion = await this.insight.assert(
|
832
|
-
assertPlan.param.assertion
|
940
|
+
assertPlan.param.assertion,
|
941
|
+
memoryContext
|
942
|
+
// Hafıza bağlamını geç
|
833
943
|
);
|
834
944
|
if (!assertion.pass) {
|
835
945
|
if (plan2.type === "Assert") {
|
@@ -1315,25 +1425,146 @@ var PageTaskExecutor = class {
|
|
1315
1425
|
};
|
1316
1426
|
return task;
|
1317
1427
|
}
|
1428
|
+
/**
|
1429
|
+
* Persistent executor'ı getirir veya oluşturur
|
1430
|
+
*/
|
1431
|
+
getPersistentExecutor() {
|
1432
|
+
if (!this.persistentExecutor || this.persistentExecutor.status === "error") {
|
1433
|
+
const previousMemory = this.workflowMemory.getWorkflowMemory(this.sessionContext.workflowId);
|
1434
|
+
this.persistentExecutor = new import_misoai_core.Executor("Persistent Task Executor", {
|
1435
|
+
onTaskStart: this.onTaskStartCallback,
|
1436
|
+
initialMemory: previousMemory
|
1437
|
+
});
|
1438
|
+
}
|
1439
|
+
return this.persistentExecutor;
|
1440
|
+
}
|
1441
|
+
/**
|
1442
|
+
* Sayfa bağlamını günceller
|
1443
|
+
*/
|
1444
|
+
async updatePageContext() {
|
1445
|
+
try {
|
1446
|
+
if (this.page.url) {
|
1447
|
+
this.sessionContext.pageInfo.url = await this.page.url();
|
1448
|
+
}
|
1449
|
+
if (this.page.pageType === "puppeteer" || this.page.pageType === "playwright") {
|
1450
|
+
this.sessionContext.pageInfo.title = await this.page.title();
|
1451
|
+
}
|
1452
|
+
} catch (e) {
|
1453
|
+
}
|
1454
|
+
}
|
1455
|
+
/**
|
1456
|
+
* Hafızayı temizler
|
1457
|
+
*/
|
1458
|
+
clearMemory() {
|
1459
|
+
if (this.persistentExecutor) {
|
1460
|
+
this.persistentExecutor.clearMemory();
|
1461
|
+
}
|
1462
|
+
this.workflowMemory.clearWorkflow(this.sessionContext.workflowId || "default");
|
1463
|
+
}
|
1464
|
+
/**
|
1465
|
+
* Mevcut hafızayı döndürür
|
1466
|
+
*/
|
1467
|
+
getMemory() {
|
1468
|
+
return this.persistentExecutor?.getMemory() || [];
|
1469
|
+
}
|
1470
|
+
/**
|
1471
|
+
* İş akışı hafızasını döndürür
|
1472
|
+
*/
|
1473
|
+
getWorkflowMemory() {
|
1474
|
+
return this.workflowMemory.getWorkflowData(this.sessionContext.workflowId || "default");
|
1475
|
+
}
|
1476
|
+
/**
|
1477
|
+
* Hafıza istatistiklerini döndürür
|
1478
|
+
*/
|
1479
|
+
getMemoryStats() {
|
1480
|
+
return this.persistentExecutor?.getMemoryStats() || {
|
1481
|
+
totalItems: 0,
|
1482
|
+
analytics: { totalTasks: 0, memoryHits: 0, memoryMisses: 0, averageMemorySize: 0, memoryEffectiveness: 0 },
|
1483
|
+
config: this.memoryConfig
|
1484
|
+
};
|
1485
|
+
}
|
1486
|
+
/**
|
1487
|
+
* Hafıza konfigürasyonunu günceller
|
1488
|
+
*/
|
1489
|
+
updateMemoryConfig(config) {
|
1490
|
+
this.memoryConfig = { ...this.memoryConfig, ...config };
|
1491
|
+
if (this.persistentExecutor) {
|
1492
|
+
this.persistentExecutor.updateMemoryConfig(this.memoryConfig);
|
1493
|
+
}
|
1494
|
+
}
|
1495
|
+
/**
|
1496
|
+
* Oturum ID'sini oluşturur
|
1497
|
+
*/
|
1498
|
+
generateSessionId() {
|
1499
|
+
return `session_${Date.now()}_${Math.random().toString(36).substr(2, 8)}`;
|
1500
|
+
}
|
1501
|
+
/**
|
1502
|
+
* Hafızayı bağlam olarak formatlar
|
1503
|
+
*/
|
1504
|
+
getMemoryAsContext() {
|
1505
|
+
const memory = this.getMemory();
|
1506
|
+
if (memory.length === 0) {
|
1507
|
+
return "";
|
1508
|
+
}
|
1509
|
+
const recentMemory = memory.slice(-5);
|
1510
|
+
return recentMemory.map((item) => `- ${item.summary}`).join("\n");
|
1511
|
+
}
|
1318
1512
|
async runPlans(title, plans, opts) {
|
1319
|
-
|
1320
|
-
|
1321
|
-
|
1513
|
+
await this.updatePageContext();
|
1514
|
+
const useMemory = opts?.useMemory !== false;
|
1515
|
+
let taskExecutor;
|
1516
|
+
if (useMemory) {
|
1517
|
+
taskExecutor = this.getPersistentExecutor();
|
1518
|
+
this.workflowMemory.updateWorkflowContext({
|
1519
|
+
currentStep: title,
|
1520
|
+
pageInfo: this.sessionContext.pageInfo,
|
1521
|
+
timestamp: Date.now()
|
1522
|
+
}, this.sessionContext.workflowId || "default");
|
1523
|
+
} else {
|
1524
|
+
taskExecutor = new import_misoai_core.Executor(title, {
|
1525
|
+
onTaskStart: this.onTaskStartCallback
|
1526
|
+
});
|
1527
|
+
}
|
1322
1528
|
const { tasks } = await this.convertPlanToExecutable(plans, opts);
|
1529
|
+
tasks.forEach((task) => {
|
1530
|
+
task.context = {
|
1531
|
+
...task.context,
|
1532
|
+
...this.sessionContext.pageInfo,
|
1533
|
+
workflowId: this.sessionContext.workflowId,
|
1534
|
+
sessionId: this.sessionContext.sessionId
|
1535
|
+
};
|
1536
|
+
});
|
1323
1537
|
await taskExecutor.append(tasks);
|
1324
1538
|
const result = await taskExecutor.flush();
|
1539
|
+
if (useMemory) {
|
1540
|
+
this.workflowMemory.saveWorkflowMemory(
|
1541
|
+
taskExecutor.getMemory(),
|
1542
|
+
this.sessionContext.workflowId || "default"
|
1543
|
+
);
|
1544
|
+
}
|
1325
1545
|
return {
|
1326
1546
|
output: result,
|
1327
1547
|
executor: taskExecutor
|
1328
1548
|
};
|
1329
1549
|
}
|
1330
1550
|
async action(userPrompt, actionContext, opts) {
|
1331
|
-
const
|
1332
|
-
|
1333
|
-
|
1334
|
-
|
1551
|
+
const useMemory = true;
|
1552
|
+
let taskExecutor;
|
1553
|
+
if (useMemory) {
|
1554
|
+
taskExecutor = this.getPersistentExecutor();
|
1555
|
+
} else {
|
1556
|
+
taskExecutor = new import_misoai_core.Executor(taskTitleStr("Action", userPrompt), {
|
1557
|
+
onTaskStart: this.onTaskStartCallback
|
1558
|
+
});
|
1559
|
+
}
|
1560
|
+
const memoryContext = this.getMemoryAsContext();
|
1561
|
+
const initialLog = memoryContext ? memoryContext : void 0;
|
1562
|
+
let planningTask = this.planningTaskFromPrompt(userPrompt, initialLog, actionContext);
|
1335
1563
|
let replanCount = 0;
|
1336
1564
|
const logList = [];
|
1565
|
+
if (memoryContext) {
|
1566
|
+
logList.push(memoryContext);
|
1567
|
+
}
|
1337
1568
|
const yamlFlow = [];
|
1338
1569
|
while (planningTask) {
|
1339
1570
|
if (replanCount > replanningCountLimit) {
|
@@ -1443,15 +1674,21 @@ var PageTaskExecutor = class {
|
|
1443
1674
|
};
|
1444
1675
|
}
|
1445
1676
|
async createTypeQueryTask(type, demand, opt) {
|
1446
|
-
const
|
1447
|
-
|
1448
|
-
|
1449
|
-
|
1450
|
-
|
1451
|
-
|
1452
|
-
|
1453
|
-
|
1454
|
-
|
1677
|
+
const useMemory = true;
|
1678
|
+
let taskExecutor;
|
1679
|
+
if (useMemory) {
|
1680
|
+
taskExecutor = this.getPersistentExecutor();
|
1681
|
+
} else {
|
1682
|
+
taskExecutor = new import_misoai_core.Executor(
|
1683
|
+
taskTitleStr(
|
1684
|
+
type,
|
1685
|
+
typeof demand === "string" ? demand : JSON.stringify(demand)
|
1686
|
+
),
|
1687
|
+
{
|
1688
|
+
onTaskStart: this.onTaskStartCallback
|
1689
|
+
}
|
1690
|
+
);
|
1691
|
+
}
|
1455
1692
|
const queryTask = {
|
1456
1693
|
type: "Insight",
|
1457
1694
|
subType: type,
|
@@ -1473,9 +1710,12 @@ var PageTaskExecutor = class {
|
|
1473
1710
|
result: `${type}, ${demand}`
|
1474
1711
|
};
|
1475
1712
|
}
|
1713
|
+
const memoryContext = this.getMemoryAsContext();
|
1476
1714
|
const { data, usage } = await this.insight.extract(
|
1477
1715
|
demandInput,
|
1478
|
-
opt
|
1716
|
+
opt,
|
1717
|
+
memoryContext
|
1718
|
+
// Hafıza bağlamını geç
|
1479
1719
|
);
|
1480
1720
|
let outputResult = data;
|
1481
1721
|
if (ifTypeRestricted) {
|
@@ -1508,11 +1748,17 @@ var PageTaskExecutor = class {
|
|
1508
1748
|
async string(prompt, opt) {
|
1509
1749
|
return this.createTypeQueryTask("String", prompt, opt);
|
1510
1750
|
}
|
1511
|
-
async assert(assertion) {
|
1751
|
+
async assert(assertion, memoryContext) {
|
1512
1752
|
const description = `assert: ${assertion}`;
|
1513
|
-
const
|
1514
|
-
|
1515
|
-
|
1753
|
+
const useMemory = true;
|
1754
|
+
let taskExecutor;
|
1755
|
+
if (useMemory) {
|
1756
|
+
taskExecutor = this.getPersistentExecutor();
|
1757
|
+
} else {
|
1758
|
+
taskExecutor = new import_misoai_core.Executor(taskTitleStr("Assert", description), {
|
1759
|
+
onTaskStart: this.onTaskStartCallback
|
1760
|
+
});
|
1761
|
+
}
|
1516
1762
|
const assertionPlan = {
|
1517
1763
|
type: "Assert",
|
1518
1764
|
param: {
|
@@ -1722,7 +1968,7 @@ var import_js_yaml3 = __toESM(require("js-yaml"));
|
|
1722
1968
|
var import_semver = __toESM(require("semver"));
|
1723
1969
|
|
1724
1970
|
// package.json
|
1725
|
-
var version = "1.
|
1971
|
+
var version = "1.5.8";
|
1726
1972
|
|
1727
1973
|
// src/common/task-cache.ts
|
1728
1974
|
var debug3 = (0, import_logger3.getDebug)("cache");
|
@@ -2209,7 +2455,13 @@ var PageAgent = class {
|
|
2209
2455
|
metadata: metadata2
|
2210
2456
|
};
|
2211
2457
|
}
|
2212
|
-
const
|
2458
|
+
const memoryContext = this.getMemoryAsContext();
|
2459
|
+
const enhancedActionContext = this.opts.aiActionContext ? `${this.opts.aiActionContext}
|
2460
|
+
|
2461
|
+
Previous workflow steps:
|
2462
|
+
${memoryContext}` : memoryContext ? `Previous workflow steps:
|
2463
|
+
${memoryContext}` : void 0;
|
2464
|
+
const { output, executor } = await (isVlmUiTars ? this.taskExecutor.actionToGoal(taskPrompt, { cacheable }) : this.taskExecutor.action(taskPrompt, enhancedActionContext, {
|
2213
2465
|
cacheable
|
2214
2466
|
}));
|
2215
2467
|
if (this.taskCache && output?.yamlFlow && cacheable !== false) {
|
@@ -2355,8 +2607,9 @@ var PageAgent = class {
|
|
2355
2607
|
} catch (e) {
|
2356
2608
|
}
|
2357
2609
|
}
|
2610
|
+
const memoryContext = this.getMemoryAsContext();
|
2358
2611
|
const assertionWithContext = currentUrl ? `For the page at URL "${currentUrl}", ${assertion}` : assertion;
|
2359
|
-
const { output, executor } = await this.taskExecutor.assert(assertionWithContext);
|
2612
|
+
const { output, executor } = await this.taskExecutor.assert(assertionWithContext, memoryContext);
|
2360
2613
|
const metadata = this.afterTaskRunning(executor, true);
|
2361
2614
|
if (output && opt?.keepRawResponse) {
|
2362
2615
|
return {
|
@@ -2603,6 +2856,138 @@ ${errors}`);
|
|
2603
2856
|
async destroy() {
|
2604
2857
|
await this.page.destroy();
|
2605
2858
|
}
|
2859
|
+
/**
|
2860
|
+
* Hafızayı bağlam olarak formatlar
|
2861
|
+
*/
|
2862
|
+
getMemoryAsContext() {
|
2863
|
+
const memory = this.taskExecutor.getMemory();
|
2864
|
+
if (memory.length === 0) {
|
2865
|
+
return "";
|
2866
|
+
}
|
2867
|
+
const recentMemory = memory.slice(-5);
|
2868
|
+
return recentMemory.map((item) => `- ${item.summary}`).join("\n");
|
2869
|
+
}
|
2870
|
+
/**
|
2871
|
+
* Mevcut hafızayı döndürür
|
2872
|
+
*/
|
2873
|
+
getMemory() {
|
2874
|
+
return this.taskExecutor.getMemory();
|
2875
|
+
}
|
2876
|
+
/**
|
2877
|
+
* Hafıza istatistiklerini döndürür
|
2878
|
+
*/
|
2879
|
+
getMemoryStats() {
|
2880
|
+
return this.taskExecutor.getMemoryStats();
|
2881
|
+
}
|
2882
|
+
/**
|
2883
|
+
* Hafızayı temizler
|
2884
|
+
*/
|
2885
|
+
clearMemory() {
|
2886
|
+
this.taskExecutor.clearMemory();
|
2887
|
+
}
|
2888
|
+
/**
|
2889
|
+
* Test sonunda kullanım için detaylı hafıza raporu döndürür (JSON formatında)
|
2890
|
+
*/
|
2891
|
+
getMemoryReport() {
|
2892
|
+
const memory = this.getMemory();
|
2893
|
+
const stats = this.getMemoryStats();
|
2894
|
+
return {
|
2895
|
+
summary: {
|
2896
|
+
totalItems: memory.length,
|
2897
|
+
totalTasks: stats.analytics.totalTasks,
|
2898
|
+
memoryHits: stats.analytics.memoryHits,
|
2899
|
+
memoryMisses: stats.analytics.memoryMisses,
|
2900
|
+
memoryEffectiveness: Math.round(stats.analytics.memoryEffectiveness * 100),
|
2901
|
+
averageMemorySize: Math.round(stats.analytics.averageMemorySize * 100) / 100
|
2902
|
+
},
|
2903
|
+
config: stats.config,
|
2904
|
+
items: memory.map((item) => ({
|
2905
|
+
id: item.id,
|
2906
|
+
timestamp: item.timestamp,
|
2907
|
+
taskType: item.taskType,
|
2908
|
+
summary: item.summary,
|
2909
|
+
context: item.context,
|
2910
|
+
metadata: item.metadata,
|
2911
|
+
tags: item.tags,
|
2912
|
+
relativeTime: this.formatRelativeTime(item.timestamp)
|
2913
|
+
})),
|
2914
|
+
analytics: {
|
2915
|
+
taskTypeDistribution: this.getTaskTypeDistribution(memory),
|
2916
|
+
successRate: this.calculateSuccessRate(memory),
|
2917
|
+
averageExecutionTime: this.calculateAverageExecutionTime(memory),
|
2918
|
+
dataExtractionCount: this.countDataExtractions(memory),
|
2919
|
+
workflowSteps: this.extractWorkflowSteps(memory)
|
2920
|
+
}
|
2921
|
+
};
|
2922
|
+
}
|
2923
|
+
/**
|
2924
|
+
* Test sonunda kullanım için basit hafıza özeti döndürür (JSON formatında)
|
2925
|
+
*/
|
2926
|
+
getMemorySummary() {
|
2927
|
+
const memory = this.getMemory();
|
2928
|
+
const stats = this.getMemoryStats();
|
2929
|
+
return {
|
2930
|
+
totalItems: memory.length,
|
2931
|
+
memoryEffectiveness: `${Math.round(stats.analytics.memoryEffectiveness * 100)}%`,
|
2932
|
+
taskTypes: this.getTaskTypeDistribution(memory),
|
2933
|
+
recentSteps: memory.slice(-5).map((item) => ({
|
2934
|
+
step: item.summary,
|
2935
|
+
type: item.taskType,
|
2936
|
+
success: item.metadata?.success || false,
|
2937
|
+
time: this.formatRelativeTime(item.timestamp)
|
2938
|
+
})),
|
2939
|
+
dataExtracted: this.getExtractedDataSummary(memory)
|
2940
|
+
};
|
2941
|
+
}
|
2942
|
+
formatRelativeTime(timestamp) {
|
2943
|
+
const now = Date.now();
|
2944
|
+
const diff = now - timestamp;
|
2945
|
+
const seconds = Math.floor(diff / 1e3);
|
2946
|
+
const minutes = Math.floor(seconds / 60);
|
2947
|
+
const hours = Math.floor(minutes / 60);
|
2948
|
+
if (hours > 0)
|
2949
|
+
return `${hours}h ${minutes % 60}m ago`;
|
2950
|
+
if (minutes > 0)
|
2951
|
+
return `${minutes}m ${seconds % 60}s ago`;
|
2952
|
+
return `${seconds}s ago`;
|
2953
|
+
}
|
2954
|
+
getTaskTypeDistribution(memory) {
|
2955
|
+
const distribution = {};
|
2956
|
+
memory.forEach((item) => {
|
2957
|
+
distribution[item.taskType] = (distribution[item.taskType] || 0) + 1;
|
2958
|
+
});
|
2959
|
+
return distribution;
|
2960
|
+
}
|
2961
|
+
calculateSuccessRate(memory) {
|
2962
|
+
if (memory.length === 0)
|
2963
|
+
return 0;
|
2964
|
+
const successCount = memory.filter((item) => item.metadata?.success !== false).length;
|
2965
|
+
return Math.round(successCount / memory.length * 100);
|
2966
|
+
}
|
2967
|
+
calculateAverageExecutionTime(memory) {
|
2968
|
+
const executionTimes = memory.map((item) => item.metadata?.executionTime).filter((time) => typeof time === "number");
|
2969
|
+
if (executionTimes.length === 0)
|
2970
|
+
return 0;
|
2971
|
+
const average = executionTimes.reduce((sum, time) => sum + time, 0) / executionTimes.length;
|
2972
|
+
return Math.round(average);
|
2973
|
+
}
|
2974
|
+
countDataExtractions(memory) {
|
2975
|
+
return memory.filter(
|
2976
|
+
(item) => item.context?.dataExtracted || item.taskType === "Insight" && item.summary.includes("Extracted")
|
2977
|
+
).length;
|
2978
|
+
}
|
2979
|
+
extractWorkflowSteps(memory) {
|
2980
|
+
return memory.map((item) => item.summary);
|
2981
|
+
}
|
2982
|
+
getExtractedDataSummary(memory) {
|
2983
|
+
const extractedData = {};
|
2984
|
+
memory.forEach((item, index) => {
|
2985
|
+
if (item.context?.dataExtracted) {
|
2986
|
+
extractedData[`step_${index + 1}`] = item.context.dataExtracted;
|
2987
|
+
}
|
2988
|
+
});
|
2989
|
+
return extractedData;
|
2990
|
+
}
|
2606
2991
|
};
|
2607
2992
|
// Annotate the CommonJS export names for ESM import in node:
|
2608
2993
|
0 && (module.exports = {
|