vantuz 3.4.1 → 3.5.0

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.
Files changed (70) hide show
  1. package/LICENSE +45 -45
  2. package/admin-keygen.js +51 -0
  3. package/cli.js +685 -585
  4. package/config.js +733 -733
  5. package/core/agent-loop.js +190 -190
  6. package/core/ai-provider.js +298 -261
  7. package/core/automation.js +523 -523
  8. package/core/brand-analyst.js +101 -0
  9. package/core/channels.js +167 -167
  10. package/core/dashboard.js +230 -230
  11. package/core/database.js +135 -36
  12. package/core/eia-monitor.js +3 -1
  13. package/core/engine.js +648 -636
  14. package/core/gateway.js +447 -447
  15. package/core/learning.js +214 -214
  16. package/core/license.js +113 -0
  17. package/core/marketplace-adapter.js +168 -168
  18. package/core/memory.js +190 -190
  19. package/core/migrations/001-initial-schema.sql +1 -1
  20. package/core/queue.js +120 -120
  21. package/core/self-healer.js +314 -314
  22. package/core/unified-product.js +214 -214
  23. package/core/vision-service.js +113 -113
  24. package/index.js +217 -174
  25. package/modules/crm/sentiment-crm.js +231 -231
  26. package/modules/healer/listing-healer.js +201 -201
  27. package/modules/oracle/predictor.js +214 -214
  28. package/modules/researcher/agent.js +169 -169
  29. package/modules/team/agents/base.js +92 -92
  30. package/modules/team/agents/dev.js +33 -33
  31. package/modules/team/agents/josh.js +40 -40
  32. package/modules/team/agents/marketing.js +33 -33
  33. package/modules/team/agents/milo.js +36 -36
  34. package/modules/team/index.js +78 -78
  35. package/modules/team/shared-memory.js +87 -87
  36. package/modules/war-room/competitor-tracker.js +250 -250
  37. package/modules/war-room/pricing-engine.js +308 -308
  38. package/nodes/warehouse.js +238 -238
  39. package/onboard.js +1 -1
  40. package/package.json +7 -6
  41. package/platforms/pttavm.js +14 -14
  42. package/plugins/vantuz/index.js +528 -528
  43. package/plugins/vantuz/memory/hippocampus.js +465 -464
  44. package/plugins/vantuz/package.json +20 -20
  45. package/plugins/vantuz/platforms/_template.js +118 -118
  46. package/plugins/vantuz/platforms/amazon.js +236 -236
  47. package/plugins/vantuz/platforms/ciceksepeti.js +166 -166
  48. package/plugins/vantuz/platforms/hepsiburada.js +180 -180
  49. package/plugins/vantuz/platforms/index.js +165 -165
  50. package/plugins/vantuz/platforms/n11.js +229 -229
  51. package/plugins/vantuz/platforms/pazarama.js +154 -154
  52. package/plugins/vantuz/platforms/pttavm.js +127 -127
  53. package/plugins/vantuz/platforms/trendyol.js +326 -326
  54. package/plugins/vantuz/services/alerts.js +253 -253
  55. package/plugins/vantuz/services/license.js +34 -34
  56. package/plugins/vantuz/services/scheduler.js +232 -232
  57. package/plugins/vantuz/tools/analytics.js +152 -152
  58. package/plugins/vantuz/tools/crossborder.js +187 -187
  59. package/plugins/vantuz/tools/nl-parser.js +211 -211
  60. package/plugins/vantuz/tools/product.js +110 -110
  61. package/plugins/vantuz/tools/quick-report.js +175 -175
  62. package/plugins/vantuz/tools/repricer.js +314 -314
  63. package/plugins/vantuz/tools/sentiment.js +115 -115
  64. package/plugins/vantuz/tools/vision.js +257 -257
  65. package/private.pem +28 -0
  66. package/public.pem +9 -0
  67. package/server/app.js +260 -260
  68. package/server/public/index.html +514 -514
  69. package/start.bat +33 -33
  70. package/vantuz.sqlite +0 -0
@@ -1,190 +1,190 @@
1
- // core/agent-loop.js
2
- // The Heartbeat of Vantuz OS V2 — Autonomous Agent Loop
3
- // Cron-driven cycle that orchestrates all intelligence modules.
4
-
5
- import { log } from './ai-provider.js';
6
- import { getLearning } from './learning.js';
7
- import { getSelfHealer } from './self-healer.js';
8
- import { CronJob } from 'cron';
9
-
10
- // ═══════════════════════════════════════════════════════════════════════════
11
- // AGENT LOOP
12
- // ═══════════════════════════════════════════════════════════════════════════
13
-
14
- class AgentLoop {
15
- constructor() {
16
- this.modules = new Map(); // name -> { fn, interval, enabled }
17
- this.cronJobs = new Map(); // name -> CronJob instance
18
- this.running = false;
19
- this.lastRun = {}; // name -> timestamp
20
- this.results = {}; // name -> last result
21
- this.healer = getSelfHealer();
22
- this.learning = getLearning();
23
-
24
- log('INFO', '🫀 AgentLoop initialized');
25
- }
26
-
27
- /**
28
- * Register a module to run in the loop.
29
- * @param {string} name - Module name (e.g., 'warroom', 'oracle').
30
- * @param {function} fn - Async function to execute.
31
- * @param {string} cronExpr - Cron expression (default: every 30 min).
32
- * @param {boolean} enabled - Start enabled? (default: true).
33
- */
34
- register(name, fn, cronExpr = '*/30 * * * *', enabled = true) {
35
- this.modules.set(name, { fn, cronExpr, enabled });
36
- log('INFO', `AgentLoop: registered "${name}" (${cronExpr}, ${enabled ? 'enabled' : 'disabled'})`);
37
- }
38
-
39
- /**
40
- * Start the loop — creates cron jobs for all registered modules.
41
- */
42
- start() {
43
- if (this.running) {
44
- log('WARN', 'AgentLoop already running');
45
- return;
46
- }
47
-
48
- for (const [name, mod] of this.modules) {
49
- if (!mod.enabled) continue;
50
-
51
- const job = new CronJob(mod.cronExpr, async () => {
52
- await this._executeModule(name);
53
- }, null, false, 'Europe/Istanbul');
54
-
55
- this.cronJobs.set(name, job);
56
- job.start();
57
- }
58
-
59
- this.running = true;
60
- log('INFO', `🫀 AgentLoop STARTED — ${this.cronJobs.size} modules active`);
61
- }
62
-
63
- /**
64
- * Stop the loop.
65
- */
66
- stop() {
67
- for (const [name, job] of this.cronJobs) {
68
- job.stop();
69
- }
70
- this.cronJobs.clear();
71
- this.running = false;
72
- log('INFO', '🫀 AgentLoop STOPPED');
73
- }
74
-
75
- /**
76
- * Enable/disable a module.
77
- */
78
- setEnabled(name, enabled) {
79
- const mod = this.modules.get(name);
80
- if (mod) {
81
- mod.enabled = enabled;
82
- const job = this.cronJobs.get(name);
83
- if (job) {
84
- enabled ? job.start() : job.stop();
85
- }
86
- log('INFO', `AgentLoop: "${name}" ${enabled ? 'enabled' : 'disabled'}`);
87
- }
88
- }
89
-
90
- /**
91
- * Manually trigger a module immediately.
92
- */
93
- async trigger(name) {
94
- if (!this.modules.has(name)) {
95
- return { error: `Module "${name}" not found` };
96
- }
97
- return await this._executeModule(name);
98
- }
99
-
100
- /**
101
- * Run all modules once (manual full cycle).
102
- */
103
- async runFullCycle() {
104
- log('INFO', '🫀 Full cycle triggered manually');
105
- const results = {};
106
- for (const [name, mod] of this.modules) {
107
- if (mod.enabled) {
108
- results[name] = await this._executeModule(name);
109
- }
110
- }
111
- return results;
112
- }
113
-
114
- getStatus() {
115
- const moduleStatus = {};
116
- for (const [name, mod] of this.modules) {
117
- moduleStatus[name] = {
118
- enabled: mod.enabled,
119
- cronExpr: mod.cronExpr,
120
- lastRun: this.lastRun[name] || null,
121
- lastResult: this.results[name] ? 'OK' : null
122
- };
123
- }
124
-
125
- return {
126
- running: this.running,
127
- autonomous: this.learning.isAutonomous(),
128
- netScore: this.learning.getNetScore(),
129
- activeModules: [...this.modules.entries()].filter(([_, m]) => m.enabled).length,
130
- totalModules: this.modules.size,
131
- modules: moduleStatus
132
- };
133
- }
134
-
135
- // ─────────────────────────────────────────────────────────────────────
136
-
137
- async _executeModule(name) {
138
- const mod = this.modules.get(name);
139
- if (!mod) return null;
140
-
141
- // Autonomy check
142
- if (!this.learning.isAutonomous()) {
143
- log('WARN', `AgentLoop: "${name}" skipped — otonom mod kapalı (skor: ${this.learning.getNetScore()})`);
144
- return { skipped: true, reason: 'Autonomous mode disabled' };
145
- }
146
-
147
- log('INFO', `AgentLoop: executing "${name}"`);
148
- const startTime = Date.now();
149
-
150
- try {
151
- // Execute with self-healing wrapper
152
- const result = await this.healer.withHealing(
153
- `agent-loop/${name}`,
154
- () => mod.fn(),
155
- `agent-loop-${name}`,
156
- { module: name, timestamp: new Date().toISOString() }
157
- );
158
-
159
- const duration = Date.now() - startTime;
160
- this.lastRun[name] = new Date().toISOString();
161
- this.results[name] = result;
162
-
163
- // Positive learning
164
- this.learning.record('successful_price_update', `${name} başarılı (${duration}ms)`, name);
165
-
166
- log('INFO', `AgentLoop: "${name}" completed in ${duration}ms`);
167
- return result;
168
-
169
- } catch (e) {
170
- const duration = Date.now() - startTime;
171
-
172
- // Negative learning
173
- this.learning.record('listing_error', `${name} hata: ${e.message}`, name);
174
-
175
- log('ERROR', `AgentLoop: "${name}" failed after ${duration}ms`, { error: e.message });
176
- return { error: e.message };
177
- }
178
- }
179
- }
180
-
181
- let loopInstance = null;
182
-
183
- export function getAgentLoop() {
184
- if (!loopInstance) {
185
- loopInstance = new AgentLoop();
186
- }
187
- return loopInstance;
188
- }
189
-
190
- export default AgentLoop;
1
+ // core/agent-loop.js
2
+ // The Heartbeat of Vantuz OS V2 — Autonomous Agent Loop
3
+ // Cron-driven cycle that orchestrates all intelligence modules.
4
+
5
+ import { log } from './ai-provider.js';
6
+ import { getLearning } from './learning.js';
7
+ import { getSelfHealer } from './self-healer.js';
8
+ import { CronJob } from 'cron';
9
+
10
+ // ═══════════════════════════════════════════════════════════════════════════
11
+ // AGENT LOOP
12
+ // ═══════════════════════════════════════════════════════════════════════════
13
+
14
+ class AgentLoop {
15
+ constructor() {
16
+ this.modules = new Map(); // name -> { fn, interval, enabled }
17
+ this.cronJobs = new Map(); // name -> CronJob instance
18
+ this.running = false;
19
+ this.lastRun = {}; // name -> timestamp
20
+ this.results = {}; // name -> last result
21
+ this.healer = getSelfHealer();
22
+ this.learning = getLearning();
23
+
24
+ log('INFO', '🫀 AgentLoop initialized');
25
+ }
26
+
27
+ /**
28
+ * Register a module to run in the loop.
29
+ * @param {string} name - Module name (e.g., 'warroom', 'oracle').
30
+ * @param {function} fn - Async function to execute.
31
+ * @param {string} cronExpr - Cron expression (default: every 30 min).
32
+ * @param {boolean} enabled - Start enabled? (default: true).
33
+ */
34
+ register(name, fn, cronExpr = '*/30 * * * *', enabled = true) {
35
+ this.modules.set(name, { fn, cronExpr, enabled });
36
+ log('INFO', `AgentLoop: registered "${name}" (${cronExpr}, ${enabled ? 'enabled' : 'disabled'})`);
37
+ }
38
+
39
+ /**
40
+ * Start the loop — creates cron jobs for all registered modules.
41
+ */
42
+ start() {
43
+ if (this.running) {
44
+ log('WARN', 'AgentLoop already running');
45
+ return;
46
+ }
47
+
48
+ for (const [name, mod] of this.modules) {
49
+ if (!mod.enabled) continue;
50
+
51
+ const job = new CronJob(mod.cronExpr, async () => {
52
+ await this._executeModule(name);
53
+ }, null, false, 'Europe/Istanbul');
54
+
55
+ this.cronJobs.set(name, job);
56
+ job.start();
57
+ }
58
+
59
+ this.running = true;
60
+ log('INFO', `🫀 AgentLoop STARTED — ${this.cronJobs.size} modules active`);
61
+ }
62
+
63
+ /**
64
+ * Stop the loop.
65
+ */
66
+ stop() {
67
+ for (const [name, job] of this.cronJobs) {
68
+ job.stop();
69
+ }
70
+ this.cronJobs.clear();
71
+ this.running = false;
72
+ log('INFO', '🫀 AgentLoop STOPPED');
73
+ }
74
+
75
+ /**
76
+ * Enable/disable a module.
77
+ */
78
+ setEnabled(name, enabled) {
79
+ const mod = this.modules.get(name);
80
+ if (mod) {
81
+ mod.enabled = enabled;
82
+ const job = this.cronJobs.get(name);
83
+ if (job) {
84
+ enabled ? job.start() : job.stop();
85
+ }
86
+ log('INFO', `AgentLoop: "${name}" ${enabled ? 'enabled' : 'disabled'}`);
87
+ }
88
+ }
89
+
90
+ /**
91
+ * Manually trigger a module immediately.
92
+ */
93
+ async trigger(name) {
94
+ if (!this.modules.has(name)) {
95
+ return { error: `Module "${name}" not found` };
96
+ }
97
+ return await this._executeModule(name);
98
+ }
99
+
100
+ /**
101
+ * Run all modules once (manual full cycle).
102
+ */
103
+ async runFullCycle() {
104
+ log('INFO', '🫀 Full cycle triggered manually');
105
+ const results = {};
106
+ for (const [name, mod] of this.modules) {
107
+ if (mod.enabled) {
108
+ results[name] = await this._executeModule(name);
109
+ }
110
+ }
111
+ return results;
112
+ }
113
+
114
+ getStatus() {
115
+ const moduleStatus = {};
116
+ for (const [name, mod] of this.modules) {
117
+ moduleStatus[name] = {
118
+ enabled: mod.enabled,
119
+ cronExpr: mod.cronExpr,
120
+ lastRun: this.lastRun[name] || null,
121
+ lastResult: this.results[name] ? 'OK' : null
122
+ };
123
+ }
124
+
125
+ return {
126
+ running: this.running,
127
+ autonomous: this.learning.isAutonomous(),
128
+ netScore: this.learning.getNetScore(),
129
+ activeModules: [...this.modules.entries()].filter(([_, m]) => m.enabled).length,
130
+ totalModules: this.modules.size,
131
+ modules: moduleStatus
132
+ };
133
+ }
134
+
135
+ // ─────────────────────────────────────────────────────────────────────
136
+
137
+ async _executeModule(name) {
138
+ const mod = this.modules.get(name);
139
+ if (!mod) return null;
140
+
141
+ // Autonomy check
142
+ if (!this.learning.isAutonomous()) {
143
+ log('WARN', `AgentLoop: "${name}" skipped — otonom mod kapalı (skor: ${this.learning.getNetScore()})`);
144
+ return { skipped: true, reason: 'Autonomous mode disabled' };
145
+ }
146
+
147
+ log('INFO', `AgentLoop: executing "${name}"`);
148
+ const startTime = Date.now();
149
+
150
+ try {
151
+ // Execute with self-healing wrapper
152
+ const result = await this.healer.withHealing(
153
+ `agent-loop/${name}`,
154
+ () => mod.fn(),
155
+ `agent-loop-${name}`,
156
+ { module: name, timestamp: new Date().toISOString() }
157
+ );
158
+
159
+ const duration = Date.now() - startTime;
160
+ this.lastRun[name] = new Date().toISOString();
161
+ this.results[name] = result;
162
+
163
+ // Positive learning
164
+ this.learning.record('successful_price_update', `${name} başarılı (${duration}ms)`, name);
165
+
166
+ log('INFO', `AgentLoop: "${name}" completed in ${duration}ms`);
167
+ return result;
168
+
169
+ } catch (e) {
170
+ const duration = Date.now() - startTime;
171
+
172
+ // Negative learning
173
+ this.learning.record('listing_error', `${name} hata: ${e.message}`, name);
174
+
175
+ log('ERROR', `AgentLoop: "${name}" failed after ${duration}ms`, { error: e.message });
176
+ return { error: e.message };
177
+ }
178
+ }
179
+ }
180
+
181
+ let loopInstance = null;
182
+
183
+ export function getAgentLoop() {
184
+ if (!loopInstance) {
185
+ loopInstance = new AgentLoop();
186
+ }
187
+ return loopInstance;
188
+ }
189
+
190
+ export default AgentLoop;