vantuz 3.3.6 → 3.4.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 (46) hide show
  1. package/README.md +25 -31
  2. package/cli.js +0 -0
  3. package/config.js +24 -0
  4. package/core/agent-loop.js +190 -0
  5. package/core/ai-analyst.js +2 -2
  6. package/core/ai-provider.js +41 -7
  7. package/core/automation.js +43 -24
  8. package/core/dashboard.js +230 -0
  9. package/core/database.js +63 -72
  10. package/core/engine.js +31 -4
  11. package/core/learning.js +214 -0
  12. package/core/license-manager.js +9 -9
  13. package/core/marketplace-adapter.js +168 -0
  14. package/core/memory.js +190 -0
  15. package/core/queue.js +120 -0
  16. package/core/scheduler.js +111 -31
  17. package/core/self-healer.js +314 -0
  18. package/core/unified-product.js +214 -0
  19. package/core/vector-db.js +83 -17
  20. package/core/vision-service.js +113 -0
  21. package/index.js +175 -0
  22. package/modules/crm/sentiment-crm.js +231 -0
  23. package/modules/healer/listing-healer.js +201 -0
  24. package/modules/oracle/predictor.js +214 -0
  25. package/modules/researcher/agent.js +169 -0
  26. package/modules/team/agents/base.js +92 -0
  27. package/modules/team/agents/dev.js +33 -0
  28. package/modules/team/agents/josh.js +40 -0
  29. package/modules/team/agents/marketing.js +33 -0
  30. package/modules/team/agents/milo.js +36 -0
  31. package/modules/team/index.js +78 -0
  32. package/modules/team/shared-memory.js +87 -0
  33. package/modules/war-room/competitor-tracker.js +250 -0
  34. package/modules/war-room/pricing-engine.js +308 -0
  35. package/nodes/warehouse.js +238 -0
  36. package/onboard.js +0 -0
  37. package/package.json +47 -87
  38. package/platforms/amazon.js +3 -8
  39. package/platforms/ciceksepeti.js +2 -5
  40. package/platforms/hepsiburada.js +4 -6
  41. package/platforms/n11.js +3 -5
  42. package/platforms/pazarama.js +2 -5
  43. package/platforms/trendyol.js +3 -3
  44. package/plugins/vantuz/index.js +48 -0
  45. package/server/app.js +142 -29
  46. package/vantuz-3.3.4.tgz +0 -0
@@ -0,0 +1,33 @@
1
+ // modules/team/agents/dev.js
2
+ import { BaseAgent } from './base.js';
3
+
4
+ export class DevAgent extends BaseAgent {
5
+ constructor(api) {
6
+ super('Dev', 'Dev Agent', { api });
7
+ }
8
+
9
+ async getSystemPrompt() {
10
+ const base = await super.getSystemPrompt();
11
+ return `${base}
12
+
13
+ ## SENİN ÖZEL ROLÜN: YAZILIM AJANI (DEV)
14
+ - Titiz, detaycı ve güvenlik bilinci yüksek birisin.
15
+ - **Sorumlulukların**:
16
+ - Sistem sağlığını (loglar, hatalar) izlemek.
17
+ - Yeni özelliklerin teknik uygulamasını incelemek.
18
+ - Teknik borçları yönetmek.
19
+ - **Araçlar**:
20
+ - Log Analizi
21
+ - Konfigürasyon Yönetimi
22
+
23
+ ## GÜNLÜK RUTİN
24
+ - Sistem loglarında hata olup olmadığını kontrol et.
25
+ - API bağlantılarını doğrula.
26
+ `;
27
+ }
28
+
29
+ async checkSystemHealth() {
30
+ // Placeholder for health check logic
31
+ return { status: 'healthy', timestamp: new Date() };
32
+ }
33
+ }
@@ -0,0 +1,40 @@
1
+ // modules/team/agents/josh.js
2
+ import { BaseAgent } from './base.js';
3
+ import { repricerTool } from '../../plugins/vantuz/tools/repricer.js';
4
+ import { analyticsTool } from '../../plugins/vantuz/tools/analytics.js';
5
+
6
+ export class JoshAgent extends BaseAgent {
7
+ constructor(api) {
8
+ super('Josh', 'Business & Growth Analyst', { api });
9
+ }
10
+
11
+ async getSystemPrompt() {
12
+ const base = await super.getSystemPrompt();
13
+ return `${base}
14
+
15
+ ## SENİN ÖZEL ROLÜN: JOSH (İŞ ANALİSTİ)
16
+ - Sen sayılarla konuşan adamsın. Pragmatik, sonuç odaklı.
17
+ - **Sorumlulukların**:
18
+ - Ciro, kar ve marjları takip etmek.
19
+ - Rakip fiyatlandırmasını izlemek.
20
+ - Fiyatlandırma stratejileri önermek.
21
+ - **Araçlar**:
22
+ - Rakip Analizi (Repricer)
23
+ - Satış Raporları (Analytics)
24
+
25
+ ## GÜNLÜK RUTİN
26
+ - Sabah 09:00'da temel metrikleri çek.
27
+ - Kar marjları hedefin altına düşerse takımı uyar.
28
+ `;
29
+ }
30
+
31
+ // Agent-specific actions
32
+ async checkCompetitors(barcode) {
33
+ // Use existing Vantuz tools
34
+ return await repricerTool.analyzeCompetitors(barcode, this.context);
35
+ }
36
+
37
+ async getSalesReport() {
38
+ return await analyticsTool.getSalesReport('7d', this.context);
39
+ }
40
+ }
@@ -0,0 +1,33 @@
1
+ // modules/team/agents/marketing.js
2
+ import { BaseAgent } from './base.js';
3
+ import { sentimentTool } from '../../plugins/vantuz/tools/sentiment.js';
4
+
5
+ export class MarketingAgent extends BaseAgent {
6
+ constructor(api) {
7
+ super('Marketing', 'Marketing Researcher', { api });
8
+ }
9
+
10
+ async getSystemPrompt() {
11
+ const base = await super.getSystemPrompt();
12
+ return `${base}
13
+
14
+ ## SENİN ÖZEL ROLÜN: PAZARLAMA AJANI
15
+ - Yaratıcı, trendleri takip eden ve meraklı birisin.
16
+ - **Sorumlulukların**:
17
+ - Sosyal medya için içerik fikirleri üretmek.
18
+ - Müşteri duyarlılığını (yorumlar, sorular) izlemek.
19
+ - SEO optimizasyonları.
20
+ - **Araçlar**:
21
+ - Duygu Analizi (Sentiment)
22
+ - Vision AI (ürün fotoğrafları için)
23
+
24
+ ## GÜNLÜK RUTİN
25
+ - Her gün 3 içerik fikri sun.
26
+ - Negatif yorum trendlerini kontrol et.
27
+ `;
28
+ }
29
+
30
+ async analyzeSentiment(productId) {
31
+ return await sentimentTool.execute({ productId, platform: 'all', period: '7d' }, this.context);
32
+ }
33
+ }
@@ -0,0 +1,36 @@
1
+ // modules/team/agents/milo.js
2
+ import { BaseAgent } from './base.js';
3
+ import sharedMemory from '../shared-memory.js';
4
+
5
+ export class MiloAgent extends BaseAgent {
6
+ constructor(api) {
7
+ super('Milo', 'Strategy Lead', { api });
8
+ }
9
+
10
+ async getSystemPrompt() {
11
+ const base = await super.getSystemPrompt();
12
+ return `${base}
13
+
14
+ ## SENİN ÖZEL ROLÜN: MILO (STRATEJİ LİDERİ)
15
+ - Sen takım liderisin. Kendine güvenen, karizmatik ve büyük resmi gören birisin.
16
+ - **Sorumlulukların**:
17
+ - Takımı yönetmek (Josh, Pazarlama, Yazılım).
18
+ - Haftalık hedefleri GOALS.md dosyasına girmek.
19
+ - Diğer ajanlardan gelen raporları sentezlemek.
20
+ - Üst düzey kararlar almak.
21
+ - **Araçlar**:
22
+ - Diğer ajanlardan rapor isteyebilirsin.
23
+ - GOALS.md dosyasını güncelleyebilirsin.
24
+
25
+ ## GÜNLÜK RUTİN
26
+ - Gece yapılan ilerlemeyi incele.
27
+ - Sabah toplantı özetini yayınla.
28
+ - Gün sonu özeti geç.
29
+ `;
30
+ }
31
+
32
+ async setGoal(goalText) {
33
+ sharedMemory.writeFile('GOALS.md', `# Current Goals & OKRs\n\n${goalText}`);
34
+ return 'Goals updated successfully.';
35
+ }
36
+ }
@@ -0,0 +1,78 @@
1
+ // modules/team/index.js
2
+ import { MiloAgent } from './agents/milo.js';
3
+ import { JoshAgent } from './agents/josh.js';
4
+ import { MarketingAgent } from './agents/marketing.js';
5
+ import { DevAgent } from './agents/dev.js';
6
+ import sharedMemory from './shared-memory.js';
7
+ import { log } from '../../core/ai-provider.js';
8
+
9
+ class TeamModule {
10
+ constructor(api) {
11
+ this.api = api;
12
+ this.agents = {};
13
+ this.initialized = false;
14
+ }
15
+
16
+ async initialize() {
17
+ if (this.initialized) return;
18
+
19
+ this.agents = {
20
+ milo: new MiloAgent(this.api),
21
+ josh: new JoshAgent(this.api),
22
+ marketing: new MarketingAgent(this.api),
23
+ dev: new DevAgent(this.api)
24
+ };
25
+
26
+ // Ensure shared memory structure
27
+ sharedMemory.ensureStructure();
28
+
29
+ this.initialized = true;
30
+ log('INFO', 'Team Module initialized with agents: Milo, Josh, Marketing, Dev');
31
+ }
32
+
33
+ getAgent(name) {
34
+ return this.agents[name.toLowerCase()];
35
+ }
36
+
37
+ async chat(agentName, message, depth = 0) {
38
+ if (depth > 3) return "Hata: Çok fazla delegasyon döngüsü (max 3).";
39
+
40
+ const agent = this.getAgent(agentName);
41
+ if (!agent) {
42
+ return `Agent '${agentName}' bulunamadı. Mevcut: ${Object.keys(this.agents).join(', ')}`;
43
+ }
44
+
45
+ let response = await agent.process(message);
46
+
47
+ // Delegasyon Kontrolü: [DELEGATE: TargetAgent Message]
48
+ const delegateMatch = response.match(/\[DELEGATE:\s*(\w+)\s+(.*?)\]/i);
49
+ if (delegateMatch) {
50
+ const targetAgentName = delegateMatch[1];
51
+ const targetMessage = delegateMatch[2];
52
+
53
+ log('INFO', `Delegasyon: ${agentName} -> ${targetAgentName}: ${targetMessage}`);
54
+
55
+ const delegateResponse = await this.chat(targetAgentName, targetMessage, depth + 1);
56
+
57
+ // Cevabı orijinal ajana geri bildir ve nihai cevabı al
58
+ const followupMessage = `[SİSTEM]: ${targetAgentName} şu cevabı verdi: "${delegateResponse}". Buna göre kullanıcıya nihai cevabını ver.`;
59
+ response = await agent.process(followupMessage);
60
+ }
61
+
62
+ return response;
63
+ }
64
+
65
+ async broadcast(message) {
66
+ const results = {};
67
+ for (const [name, agent] of Object.entries(this.agents)) {
68
+ results[name] = await agent.process(message);
69
+ }
70
+ return results;
71
+ }
72
+
73
+ getSharedMemory() {
74
+ return sharedMemory;
75
+ }
76
+ }
77
+
78
+ export default TeamModule;
@@ -0,0 +1,87 @@
1
+ // modules/team/shared-memory.js
2
+ import fs from 'fs';
3
+ import path from 'path';
4
+ import { log } from '../../core/ai-provider.js';
5
+
6
+ const TEAM_DIR = path.join(process.cwd(), 'workspace', 'team');
7
+
8
+ export class SharedMemory {
9
+ constructor() {
10
+ this.ensureStructure();
11
+ }
12
+
13
+ ensureStructure() {
14
+ if (!fs.existsSync(TEAM_DIR)) {
15
+ fs.mkdirSync(TEAM_DIR, { recursive: true });
16
+ }
17
+
18
+ // Standart dosyaların varlığını kontrol et
19
+ const defaults = {
20
+ 'GOALS.md': '# Mevcut Hedefler & OKR\'lar\n\nHenüz bir hedef belirlenmedi.',
21
+ 'DECISIONS.md': '# Karar Günlüğü\n\nHenüz bir karar alınmadı.',
22
+ 'PROJECT_STATUS.md': '# Proje Durumu\n\nDurum: Başlatılıyor...'
23
+ };
24
+
25
+ for (const [file, content] of Object.entries(defaults)) {
26
+ const filePath = path.join(TEAM_DIR, file);
27
+ if (!fs.existsSync(filePath)) {
28
+ fs.writeFileSync(filePath, content, 'utf-8');
29
+ }
30
+ }
31
+ }
32
+
33
+ getAgentDir(agentName) {
34
+ const dir = path.join(TEAM_DIR, 'agents', agentName);
35
+ if (!fs.existsSync(dir)) {
36
+ fs.mkdirSync(dir, { recursive: true });
37
+ }
38
+ return dir;
39
+ }
40
+
41
+ readFile(filename) {
42
+ try {
43
+ const filePath = path.join(TEAM_DIR, filename);
44
+ if (fs.existsSync(filePath)) {
45
+ return fs.readFileSync(filePath, 'utf-8');
46
+ }
47
+ } catch (e) {
48
+ log('ERROR', `SharedMemory read failed: ${filename}`, { error: e.message });
49
+ }
50
+ return '';
51
+ }
52
+
53
+ writeFile(filename, content) {
54
+ try {
55
+ const filePath = path.join(TEAM_DIR, filename);
56
+ fs.writeFileSync(filePath, content, 'utf-8');
57
+ log('INFO', `SharedMemory updated: ${filename}`);
58
+ return true;
59
+ } catch (e) {
60
+ log('ERROR', `SharedMemory write failed: ${filename}`, { error: e.message });
61
+ return false;
62
+ }
63
+ }
64
+
65
+ appendFile(filename, content) {
66
+ try {
67
+ const filePath = path.join(TEAM_DIR, filename);
68
+ const timestamp = new Date().toISOString().replace('T', ' ').substring(0, 19);
69
+ const formatted = `\n\n### [${timestamp}] Update\n${content}`;
70
+ fs.appendFileSync(filePath, formatted, 'utf-8');
71
+ return true;
72
+ } catch (e) {
73
+ log('ERROR', `SharedMemory append failed: ${filename}`, { error: e.message });
74
+ return false;
75
+ }
76
+ }
77
+
78
+ getEverything() {
79
+ return {
80
+ goals: this.readFile('GOALS.md'),
81
+ decisions: this.readFile('DECISIONS.md'),
82
+ status: this.readFile('PROJECT_STATUS.md')
83
+ };
84
+ }
85
+ }
86
+
87
+ export default new SharedMemory();
@@ -0,0 +1,250 @@
1
+ // modules/war-room/competitor-tracker.js
2
+ // Competitor Price Tracker for Vantuz OS V2
3
+ // Monitors rival prices with POLITENESS MODE to avoid IP bans.
4
+
5
+ import fs from 'fs';
6
+ import path from 'path';
7
+ import os from 'os';
8
+ import { log } from '../../core/ai-provider.js';
9
+
10
+ const HISTORY_FILE = path.join(os.homedir(), '.vantuz', 'memory', 'competitor-history.json');
11
+ const MAX_HISTORY = 1000;
12
+
13
+ // ═══════════════════════════════════════════════════════════════════════════
14
+ // POLITENESS MODE — Anti-Ban Protection
15
+ // ═══════════════════════════════════════════════════════════════════════════
16
+
17
+ function randomDelay(minMs = 2000, maxMs = 5000) {
18
+ const delay = Math.floor(Math.random() * (maxMs - minMs + 1)) + minMs;
19
+ return new Promise(resolve => setTimeout(resolve, delay));
20
+ }
21
+
22
+ const RATE_LIMITS = new Map(); // platform -> { count, resetAt }
23
+ const MAX_REQUESTS_PER_HOUR = 120;
24
+
25
+ function checkRateLimit(platform) {
26
+ const now = Date.now();
27
+ let limit = RATE_LIMITS.get(platform);
28
+
29
+ if (!limit || now > limit.resetAt) {
30
+ limit = { count: 0, resetAt: now + 3600000 }; // 1 hour window
31
+ RATE_LIMITS.set(platform, limit);
32
+ }
33
+
34
+ if (limit.count >= MAX_REQUESTS_PER_HOUR) {
35
+ log('WARN', `Rate limit reached for ${platform}`, {
36
+ count: limit.count,
37
+ resetIn: Math.round((limit.resetAt - now) / 60000) + ' min'
38
+ });
39
+ return false;
40
+ }
41
+
42
+ limit.count++;
43
+ return true;
44
+ }
45
+
46
+ // ═══════════════════════════════════════════════════════════════════════════
47
+ // HISTORY PERSISTENCE
48
+ // ═══════════════════════════════════════════════════════════════════════════
49
+
50
+ function loadHistory() {
51
+ try {
52
+ if (fs.existsSync(HISTORY_FILE)) {
53
+ return JSON.parse(fs.readFileSync(HISTORY_FILE, 'utf-8'));
54
+ }
55
+ } catch (e) { /* ignore */ }
56
+ return {};
57
+ }
58
+
59
+ function saveHistory(history) {
60
+ const dir = path.dirname(HISTORY_FILE);
61
+ if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
62
+ const tmp = HISTORY_FILE + '.tmp';
63
+ fs.writeFileSync(tmp, JSON.stringify(history, null, 2), 'utf-8');
64
+ fs.renameSync(tmp, HISTORY_FILE);
65
+ }
66
+
67
+ // ═══════════════════════════════════════════════════════════════════════════
68
+ // COMPETITOR TRACKER
69
+ // ═══════════════════════════════════════════════════════════════════════════
70
+
71
+ class CompetitorTracker {
72
+ constructor() {
73
+ this.history = loadHistory(); // barcode -> [{timestamp, platform, competitors[]}]
74
+ this.adapters = null; // Set by init()
75
+ log('INFO', 'CompetitorTracker initialized', {
76
+ trackedProducts: Object.keys(this.history).length
77
+ });
78
+ }
79
+
80
+ /**
81
+ * Set adapter registry reference.
82
+ */
83
+ setAdapters(adapterRegistry) {
84
+ this.adapters = adapterRegistry;
85
+ }
86
+
87
+ /**
88
+ * Track competitor prices for a single product.
89
+ * @param {string} barcode
90
+ * @param {string} platform - Platform to check (default: all active).
91
+ * @returns {{ competitors: array, alert: string|null }}
92
+ */
93
+ async trackProduct(barcode, platform = null) {
94
+ const competitors = [];
95
+ const platforms = platform
96
+ ? [platform]
97
+ : (this.adapters?.getActive() || []).map(a => a.name);
98
+
99
+ for (const pName of platforms) {
100
+ // Rate limit check
101
+ if (!checkRateLimit(pName)) {
102
+ log('WARN', `Skipping ${pName} for ${barcode}: rate limited`);
103
+ continue;
104
+ }
105
+
106
+ const adapter = this.adapters?.get(pName);
107
+ if (!adapter || typeof adapter.getCompetitorPrices !== 'function') {
108
+ continue;
109
+ }
110
+
111
+ try {
112
+ // POLITENESS MODE: Random delay before each request
113
+ await randomDelay(2000, 5000);
114
+
115
+ const result = await adapter.getCompetitorPrices(barcode);
116
+ if (result?.success && result.data) {
117
+ for (const comp of result.data) {
118
+ competitors.push({
119
+ platform: pName,
120
+ seller: comp.seller || comp.merchantName || 'unknown',
121
+ price: parseFloat(comp.price || comp.salePrice || 0),
122
+ stock: comp.stock ?? comp.hasStock ?? null,
123
+ rating: comp.rating || null,
124
+ fetchedAt: new Date().toISOString()
125
+ });
126
+ }
127
+ }
128
+ } catch (e) {
129
+ log('ERROR', `Competitor fetch failed: ${pName}/${barcode}`, { error: e.message });
130
+ }
131
+ }
132
+
133
+ // Store in history
134
+ this._recordHistory(barcode, competitors);
135
+
136
+ // Detect alerts
137
+ const alert = this._detectAlerts(barcode, competitors);
138
+
139
+ return { barcode, competitors, alert };
140
+ }
141
+
142
+ /**
143
+ * Track multiple products in batch (respects rate limits).
144
+ * @param {string[]} barcodes
145
+ */
146
+ async trackBatch(barcodes) {
147
+ const results = [];
148
+
149
+ for (const barcode of barcodes) {
150
+ const result = await this.trackProduct(barcode);
151
+ results.push(result);
152
+
153
+ // Extra delay between products for politeness
154
+ await randomDelay(1000, 3000);
155
+ }
156
+
157
+ log('INFO', `Batch tracking complete`, {
158
+ products: barcodes.length,
159
+ totalCompetitors: results.reduce((s, r) => s + r.competitors.length, 0)
160
+ });
161
+
162
+ return results;
163
+ }
164
+
165
+ /**
166
+ * Get price history for a product.
167
+ */
168
+ getHistory(barcode) {
169
+ return this.history[barcode] || [];
170
+ }
171
+
172
+ /**
173
+ * Get competitor summary: cheapest, average, count.
174
+ */
175
+ getSummary(barcode) {
176
+ const entries = this.history[barcode] || [];
177
+ if (entries.length === 0) return null;
178
+
179
+ const latest = entries[entries.length - 1];
180
+ const prices = latest.competitors.map(c => c.price).filter(p => p > 0);
181
+
182
+ return {
183
+ barcode,
184
+ sellerCount: latest.competitors.length,
185
+ cheapest: prices.length > 0 ? Math.min(...prices) : null,
186
+ average: prices.length > 0 ? prices.reduce((a, b) => a + b, 0) / prices.length : null,
187
+ mostExpensive: prices.length > 0 ? Math.max(...prices) : null,
188
+ lastChecked: latest.timestamp
189
+ };
190
+ }
191
+
192
+ // ─────────────────────────────────────────────────────────────────────
193
+ // PRIVATE
194
+ // ─────────────────────────────────────────────────────────────────────
195
+
196
+ _recordHistory(barcode, competitors) {
197
+ if (!this.history[barcode]) {
198
+ this.history[barcode] = [];
199
+ }
200
+
201
+ this.history[barcode].push({
202
+ timestamp: new Date().toISOString(),
203
+ competitors
204
+ });
205
+
206
+ // Keep only recent entries per product
207
+ if (this.history[barcode].length > 50) {
208
+ this.history[barcode] = this.history[barcode].slice(-50);
209
+ }
210
+
211
+ // Limit total history size
212
+ const total = Object.values(this.history).reduce((s, arr) => s + arr.length, 0);
213
+ if (total > MAX_HISTORY) {
214
+ // Remove oldest product histories
215
+ const sorted = Object.entries(this.history)
216
+ .sort((a, b) => a[1].length - b[1].length);
217
+ delete this.history[sorted[0][0]];
218
+ }
219
+
220
+ saveHistory(this.history);
221
+ }
222
+
223
+ _detectAlerts(barcode, competitors) {
224
+ if (competitors.length === 0) return null;
225
+
226
+ const prices = competitors.map(c => c.price).filter(p => p > 0);
227
+ if (prices.length === 0) return null;
228
+
229
+ const cheapest = Math.min(...prices);
230
+ const lowStockSellers = competitors.filter(c => c.stock !== null && c.stock < 5);
231
+
232
+ // Alert: all competitors low stock → opportunity!
233
+ if (lowStockSellers.length > 0 && lowStockSellers.length >= competitors.length * 0.7) {
234
+ return `🔥 FIRSAT: ${barcode} — Rakiplerin %${Math.round(lowStockSellers.length / competitors.length * 100)}'i düşük stokta. Fiyat artırma fırsatı!`;
235
+ }
236
+
237
+ return null;
238
+ }
239
+ }
240
+
241
+ let trackerInstance = null;
242
+
243
+ export function getCompetitorTracker() {
244
+ if (!trackerInstance) {
245
+ trackerInstance = new CompetitorTracker();
246
+ }
247
+ return trackerInstance;
248
+ }
249
+
250
+ export default CompetitorTracker;