vantuz 3.3.5 → 3.3.7
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/README.md +62 -26
- package/config.js +55 -8
- package/core/agent-loop.js +190 -0
- package/core/ai-provider.js +41 -7
- package/core/automation.js +43 -24
- package/core/dashboard.js +230 -0
- package/core/engine.js +323 -339
- package/core/gateway.js +139 -68
- package/core/learning.js +214 -0
- package/core/marketplace-adapter.js +168 -0
- package/core/memory.js +190 -0
- package/core/queue.js +120 -0
- package/core/scheduler.js +111 -31
- package/core/self-healer.js +314 -0
- package/core/unified-product.js +214 -0
- package/core/vector-db.js +83 -17
- package/core/vision-service.js +113 -0
- package/package.json +1 -1
- package/platforms/amazon.js +4 -1
- package/platforms/ciceksepeti.js +2 -1
- package/platforms/n11.js +2 -2
- package/platforms/pazarama.js +2 -1
- package/platforms/pttavm.js +14 -0
- package/server/app.js +142 -29
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
// core/dashboard.js
|
|
2
|
+
// System Health Dashboard — Vantuz OS V2 Control Tower
|
|
3
|
+
// Aggregates status from all modules into a single real-time overview.
|
|
4
|
+
|
|
5
|
+
import os from 'os';
|
|
6
|
+
import { log } from './ai-provider.js';
|
|
7
|
+
|
|
8
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
9
|
+
// UPTIME TRACKER
|
|
10
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
11
|
+
|
|
12
|
+
const BOOT_TIME = Date.now();
|
|
13
|
+
|
|
14
|
+
function formatUptime(ms) {
|
|
15
|
+
const seconds = Math.floor(ms / 1000);
|
|
16
|
+
const days = Math.floor(seconds / 86400);
|
|
17
|
+
const hours = Math.floor((seconds % 86400) / 3600);
|
|
18
|
+
const minutes = Math.floor((seconds % 3600) / 60);
|
|
19
|
+
|
|
20
|
+
const parts = [];
|
|
21
|
+
if (days > 0) parts.push(`${days}g`);
|
|
22
|
+
if (hours > 0) parts.push(`${hours}s`);
|
|
23
|
+
parts.push(`${minutes}dk`);
|
|
24
|
+
return parts.join(' ');
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
28
|
+
// DASHBOARD
|
|
29
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
30
|
+
|
|
31
|
+
class Dashboard {
|
|
32
|
+
constructor() {
|
|
33
|
+
this.moduleRefs = {}; // name -> getter function
|
|
34
|
+
this.customMetrics = {}; // name -> { value, updatedAt }
|
|
35
|
+
this.alerts = []; // { level, message, timestamp }
|
|
36
|
+
log('INFO', '📊 Dashboard initialized');
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Register a module for health reporting.
|
|
41
|
+
* @param {string} name - Module name (e.g., 'warroom', 'oracle').
|
|
42
|
+
* @param {function} statusFn - Function that returns module status object.
|
|
43
|
+
*/
|
|
44
|
+
registerModule(name, statusFn) {
|
|
45
|
+
this.moduleRefs[name] = statusFn;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Set a custom metric (can be called from anywhere).
|
|
50
|
+
*/
|
|
51
|
+
setMetric(name, value) {
|
|
52
|
+
this.customMetrics[name] = { value, updatedAt: new Date().toISOString() };
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Push a dashboard alert.
|
|
57
|
+
*/
|
|
58
|
+
pushAlert(level, message) {
|
|
59
|
+
this.alerts.push({
|
|
60
|
+
level, // 'info', 'warning', 'critical'
|
|
61
|
+
message,
|
|
62
|
+
timestamp: new Date().toISOString()
|
|
63
|
+
});
|
|
64
|
+
// Keep last 50
|
|
65
|
+
if (this.alerts.length > 50) this.alerts = this.alerts.slice(-50);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Get full system health report.
|
|
70
|
+
* @returns {object} Complete health snapshot.
|
|
71
|
+
*/
|
|
72
|
+
getHealth() {
|
|
73
|
+
const uptimeMs = Date.now() - BOOT_TIME;
|
|
74
|
+
|
|
75
|
+
// ── System Info ──
|
|
76
|
+
const system = {
|
|
77
|
+
uptime: formatUptime(uptimeMs),
|
|
78
|
+
uptimeMs,
|
|
79
|
+
bootTime: new Date(BOOT_TIME).toISOString(),
|
|
80
|
+
memory: {
|
|
81
|
+
total: Math.round(os.totalmem() / 1024 / 1024) + ' MB',
|
|
82
|
+
free: Math.round(os.freemem() / 1024 / 1024) + ' MB',
|
|
83
|
+
usage: Math.round((1 - os.freemem() / os.totalmem()) * 100) + '%'
|
|
84
|
+
},
|
|
85
|
+
platform: os.platform(),
|
|
86
|
+
nodeVersion: process.version
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
// ── Module Status ──
|
|
90
|
+
const modules = {};
|
|
91
|
+
for (const [name, statusFn] of Object.entries(this.moduleRefs)) {
|
|
92
|
+
try {
|
|
93
|
+
modules[name] = { status: 'online', ...statusFn() };
|
|
94
|
+
} catch (e) {
|
|
95
|
+
modules[name] = { status: 'error', error: e.message };
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// ── Overall Health Score ──
|
|
100
|
+
const moduleCount = Object.keys(modules).length;
|
|
101
|
+
const onlineCount = Object.values(modules).filter(m => m.status === 'online').length;
|
|
102
|
+
const healthPercent = moduleCount > 0 ? Math.round((onlineCount / moduleCount) * 100) : 0;
|
|
103
|
+
|
|
104
|
+
let overallStatus = '🟢 Healthy';
|
|
105
|
+
if (healthPercent < 100) overallStatus = '🟡 Degraded';
|
|
106
|
+
if (healthPercent < 50) overallStatus = '🔴 Critical';
|
|
107
|
+
|
|
108
|
+
return {
|
|
109
|
+
overallStatus,
|
|
110
|
+
healthPercent,
|
|
111
|
+
system,
|
|
112
|
+
modules,
|
|
113
|
+
metrics: this.customMetrics,
|
|
114
|
+
recentAlerts: this.alerts.slice(-10),
|
|
115
|
+
generatedAt: new Date().toISOString()
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Get a human-readable summary (for TUI / AI context).
|
|
121
|
+
*/
|
|
122
|
+
getSummary() {
|
|
123
|
+
const h = this.getHealth();
|
|
124
|
+
const lines = [
|
|
125
|
+
`${h.overallStatus} | Uptime: ${h.system.uptime} | RAM: ${h.system.memory.usage}`,
|
|
126
|
+
`Modüller: ${h.healthPercent}% online (${Object.keys(h.modules).length} kayıtlı)`,
|
|
127
|
+
''
|
|
128
|
+
];
|
|
129
|
+
|
|
130
|
+
for (const [name, mod] of Object.entries(h.modules)) {
|
|
131
|
+
const icon = mod.status === 'online' ? '✅' : '❌';
|
|
132
|
+
const details = [];
|
|
133
|
+
|
|
134
|
+
// Module-specific summary lines
|
|
135
|
+
if (mod.autonomous !== undefined) {
|
|
136
|
+
details.push(mod.autonomous ? 'Otonom' : '⚠️ Manuel Mod');
|
|
137
|
+
}
|
|
138
|
+
if (mod.netScore !== undefined) {
|
|
139
|
+
details.push(`Skor: ${mod.netScore}`);
|
|
140
|
+
}
|
|
141
|
+
if (mod.totalErrors !== undefined) {
|
|
142
|
+
details.push(`Hata: ${mod.totalErrors}`);
|
|
143
|
+
}
|
|
144
|
+
if (mod.trackedProducts !== undefined) {
|
|
145
|
+
details.push(`Takip: ${mod.trackedProducts} ürün`);
|
|
146
|
+
}
|
|
147
|
+
if (mod.critical !== undefined) {
|
|
148
|
+
details.push(`Kritik: ${mod.critical}`);
|
|
149
|
+
}
|
|
150
|
+
if (mod.recentDecisions !== undefined) {
|
|
151
|
+
details.push(`Karar: ${mod.recentDecisions}`);
|
|
152
|
+
}
|
|
153
|
+
if (mod.killSwitch?.active) {
|
|
154
|
+
details.push('🛑 KILL SWITCH AKTİF');
|
|
155
|
+
}
|
|
156
|
+
if (mod.activeModules !== undefined) {
|
|
157
|
+
details.push(`Aktif: ${mod.activeModules}/${mod.totalModules}`);
|
|
158
|
+
}
|
|
159
|
+
if (mod.running !== undefined) {
|
|
160
|
+
details.push(mod.running ? '🫀 Çalışıyor' : '⏸️ Durdu');
|
|
161
|
+
}
|
|
162
|
+
if (mod.avgScore !== undefined) {
|
|
163
|
+
details.push(`Sağlık: ${mod.avgScore}/100`);
|
|
164
|
+
}
|
|
165
|
+
if (mod.totalProcessed !== undefined) {
|
|
166
|
+
details.push(`İşlenen: ${mod.totalProcessed}`);
|
|
167
|
+
}
|
|
168
|
+
if (mod.escalatedCount !== undefined && mod.escalatedCount > 0) {
|
|
169
|
+
details.push(`🚨 Eskalasyon: ${mod.escalatedCount}`);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
lines.push(`${icon} ${name}: ${details.join(' | ') || mod.status}`);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// Custom metrics
|
|
176
|
+
if (Object.keys(h.metrics).length > 0) {
|
|
177
|
+
lines.push('', '📈 Metrikler:');
|
|
178
|
+
for (const [name, m] of Object.entries(h.metrics)) {
|
|
179
|
+
lines.push(` ${name}: ${m.value}`);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// Recent alerts
|
|
184
|
+
const criticalAlerts = h.recentAlerts.filter(a => a.level === 'critical');
|
|
185
|
+
if (criticalAlerts.length > 0) {
|
|
186
|
+
lines.push('', '🚨 Kritik Uyarılar:');
|
|
187
|
+
for (const a of criticalAlerts.slice(-3)) {
|
|
188
|
+
lines.push(` ${a.message}`);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
return lines.join('\n');
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
let dashboardInstance = null;
|
|
197
|
+
|
|
198
|
+
export function getDashboard() {
|
|
199
|
+
if (!dashboardInstance) {
|
|
200
|
+
dashboardInstance = new Dashboard();
|
|
201
|
+
}
|
|
202
|
+
return dashboardInstance;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Helper: Wire up all V2 modules to the dashboard.
|
|
207
|
+
* Call this after all modules are initialized.
|
|
208
|
+
*/
|
|
209
|
+
export function wireModulesToDashboard(refs = {}) {
|
|
210
|
+
const dash = getDashboard();
|
|
211
|
+
|
|
212
|
+
if (refs.agentLoop) dash.registerModule('AgentLoop', () => refs.agentLoop.getStatus());
|
|
213
|
+
if (refs.pricingEngine) dash.registerModule('WarRoom', () => refs.pricingEngine.getStatus());
|
|
214
|
+
if (refs.oracle) dash.registerModule('Oracle', () => refs.oracle.getStatus());
|
|
215
|
+
if (refs.crm) dash.registerModule('CRM', () => refs.crm.getStatus());
|
|
216
|
+
if (refs.healer) dash.registerModule('ListingHealer', () => refs.healer.getStatus());
|
|
217
|
+
if (refs.selfHealer) dash.registerModule('SelfHealer', () => refs.selfHealer.getStatus());
|
|
218
|
+
if (refs.learning) dash.registerModule('Learning', () => refs.learning.getStatus());
|
|
219
|
+
if (refs.researcher) dash.registerModule('Researcher', () => refs.researcher.getStatus());
|
|
220
|
+
if (refs.queue) dash.registerModule('Queue', () => refs.queue.getStatus());
|
|
221
|
+
if (refs.memory) dash.registerModule('Memory', () => ({
|
|
222
|
+
factsCount: refs.memory.facts?.length || 0,
|
|
223
|
+
strategiesCount: refs.memory.strategies?.length || 0
|
|
224
|
+
}));
|
|
225
|
+
|
|
226
|
+
log('INFO', `📊 Dashboard wired: ${Object.keys(refs).length} modules`);
|
|
227
|
+
return dash;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
export default Dashboard;
|