vantuz 3.4.2 → 3.5.1

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 (92) hide show
  1. package/.env.example +21 -0
  2. package/.openclaw/completions/openclaw.bash +227 -0
  3. package/.openclaw/completions/openclaw.fish +1552 -0
  4. package/.openclaw/completions/openclaw.ps1 +1966 -0
  5. package/.openclaw/completions/openclaw.zsh +3571 -0
  6. package/.openclaw/gateway.cmd +10 -0
  7. package/.openclaw/identity/device.json +7 -0
  8. package/.openclaw/openclaw.json +40 -0
  9. package/.windsurf/workflows/vantuz-dev.md +31 -0
  10. package/DOCS_TR.md +80 -0
  11. package/LICENSE +45 -45
  12. package/README.md +52 -21
  13. package/cli.js +685 -585
  14. package/config.js +733 -733
  15. package/core/agent-loop.js +190 -190
  16. package/core/ai-provider.js +298 -261
  17. package/core/automation.js +523 -523
  18. package/core/brand-analyst.js +101 -0
  19. package/core/channels.js +167 -167
  20. package/core/dashboard.js +230 -230
  21. package/core/database.js +135 -37
  22. package/core/eia-monitor.js +3 -1
  23. package/core/engine.js +648 -636
  24. package/core/gateway.js +447 -447
  25. package/core/learning.js +214 -214
  26. package/core/license.js +113 -0
  27. package/core/marketplace-adapter.js +168 -168
  28. package/core/memory.js +190 -190
  29. package/core/migrations/001-initial-schema.sql +1 -1
  30. package/core/queue.js +120 -120
  31. package/core/self-healer.js +314 -314
  32. package/core/unified-product.js +214 -214
  33. package/core/vision-service.js +113 -113
  34. package/index.js +217 -174
  35. package/modules/crm/sentiment-crm.js +231 -231
  36. package/modules/healer/listing-healer.js +201 -201
  37. package/modules/oracle/predictor.js +214 -214
  38. package/modules/researcher/agent.js +169 -169
  39. package/modules/team/agents/base.js +92 -92
  40. package/modules/team/agents/dev.js +33 -33
  41. package/modules/team/agents/josh.js +40 -40
  42. package/modules/team/agents/marketing.js +33 -33
  43. package/modules/team/agents/milo.js +36 -36
  44. package/modules/team/index.js +78 -78
  45. package/modules/team/shared-memory.js +87 -87
  46. package/modules/war-room/competitor-tracker.js +250 -250
  47. package/modules/war-room/pricing-engine.js +308 -308
  48. package/n11docs.md +1680 -0
  49. package/nodes/warehouse.js +238 -238
  50. package/onboard.js +1 -1
  51. package/openclawdocs.md +3 -0
  52. package/package.json +7 -5
  53. package/platforms/pttavm.js +14 -14
  54. package/plugins/vantuz/index.js +528 -528
  55. package/plugins/vantuz/memory/hippocampus.js +465 -465
  56. package/plugins/vantuz/package.json +20 -20
  57. package/plugins/vantuz/platforms/_template.js +118 -118
  58. package/plugins/vantuz/platforms/amazon.js +236 -236
  59. package/plugins/vantuz/platforms/ciceksepeti.js +166 -166
  60. package/plugins/vantuz/platforms/hepsiburada.js +180 -180
  61. package/plugins/vantuz/platforms/index.js +165 -165
  62. package/plugins/vantuz/platforms/n11.js +229 -229
  63. package/plugins/vantuz/platforms/pazarama.js +154 -154
  64. package/plugins/vantuz/platforms/pttavm.js +127 -127
  65. package/plugins/vantuz/platforms/trendyol.js +326 -326
  66. package/plugins/vantuz/services/alerts.js +253 -253
  67. package/plugins/vantuz/services/license.js +34 -34
  68. package/plugins/vantuz/services/scheduler.js +232 -232
  69. package/plugins/vantuz/tools/analytics.js +152 -152
  70. package/plugins/vantuz/tools/crossborder.js +187 -187
  71. package/plugins/vantuz/tools/nl-parser.js +211 -211
  72. package/plugins/vantuz/tools/product.js +110 -110
  73. package/plugins/vantuz/tools/quick-report.js +175 -175
  74. package/plugins/vantuz/tools/repricer.js +314 -314
  75. package/plugins/vantuz/tools/sentiment.js +115 -115
  76. package/plugins/vantuz/tools/vision.js +257 -257
  77. package/public.pem +9 -0
  78. package/server/app.js +260 -260
  79. package/server/public/index.html +514 -514
  80. package/start.bat +33 -33
  81. package/vantuz.sqlite +0 -0
  82. package/workspace/AGENTS.md +73 -0
  83. package/workspace/BRAND.md +29 -0
  84. package/workspace/SOUL.md +72 -0
  85. package/workspace/team/DECISIONS.md +3 -0
  86. package/workspace/team/GOALS.md +3 -0
  87. package/workspace/team/PROJECT_STATUS.md +3 -0
  88. package/workspace/team/agents/dev/SOUL.md +12 -0
  89. package/workspace/team/agents/josh/SOUL.md +12 -0
  90. package/workspace/team/agents/marketing/SOUL.md +12 -0
  91. package/workspace/team/agents/milo/SOUL.md +12 -0
  92. package/vantuz-3.3.4.tgz +0 -0
@@ -1,528 +1,528 @@
1
- /**
2
- * 🐙 VANTUZ AI v3.1
3
- * E-Ticaretin Yapay Zeka Beyni
4
- *
5
- * Bu plugin şunları sağlar:
6
- * - 7 Pazaryeri API Entegrasyonu (Trendyol, HB, N11, Amazon, CS, PTT, Pazarama)
7
- * - E-ticaret araçları (repricer, vision, sentiment, crossborder)
8
- * - Özel komutlar (/stok, /fiyat, /rapor, /uyari)
9
- * - Cron zamanlama ve otomasyon
10
- * - Hippocampus hafıza sistemi
11
- */
12
-
13
- import { Hippocampus } from './memory/hippocampus.js';
14
- import { LicenseManager } from './services/license.js';
15
- import SchedulerService from './services/scheduler.js';
16
- import AlertService from './services/alerts.js';
17
-
18
- // Tools
19
- import { repricerTool } from './tools/repricer.js';
20
- import { visionTool } from './tools/vision.js';
21
- import { sentimentTool } from './tools/sentiment.js';
22
- import { crossborderTool } from './tools/crossborder.js';
23
- import { productTool } from './tools/product.js';
24
- import { analyticsTool } from './tools/analytics.js';
25
- import { quickReportTool } from './tools/quick-report.js';
26
- import NLParser from './tools/nl-parser.js';
27
-
28
- // Platform APIs
29
- import platformHub, {
30
- trendyolApi,
31
- hepsiburadaApi,
32
- n11Api,
33
- amazonApi,
34
- ciceksepetiApi,
35
- pttavmApi,
36
- pazaramaApi
37
- } from './platforms/index.js';
38
-
39
-
40
- const PLUGIN_ID = 'vantuz';
41
- const PLUGIN_VERSION = '3.0.0';
42
-
43
- export default function (api) {
44
- const logger = api.logger;
45
- const config = api.config;
46
-
47
- // Hippocampus hafıza sistemi
48
- const memory = new Hippocampus(api);
49
-
50
- // Lisans yöneticisi
51
- const license = new LicenseManager(api);
52
-
53
- // ═══════════════════════════════════════════════════════════════════════════
54
- // 🔧 TOOLS - AI tarafından çağrılabilir araçlar
55
- // ═══════════════════════════════════════════════════════════════════════════
56
-
57
- // 🩸 Kan Emici Repricer
58
- api.registerTool({
59
- name: 'vantuz.repricer',
60
- description: `Rakip fiyatlarını analiz et ve optimal fiyat öner.
61
- Akıllı kararlar verir:
62
- - Rakip stoku azsa → Fiyatı yükselt
63
- - Rakip fiyat düşürdüyse → Kar marjına göre takip et
64
- - Satış hızı yüksekse → Fiyatı optimize et`,
65
- parameters: {
66
- type: 'object',
67
- properties: {
68
- barcode: {
69
- type: 'string',
70
- description: 'Ürün barkodu veya SKU'
71
- },
72
- platform: {
73
- type: 'string',
74
- enum: ['trendyol', 'hepsiburada', 'amazon', 'n11', 'all'],
75
- description: 'Hedef pazaryeri'
76
- },
77
- targetMargin: {
78
- type: 'number',
79
- description: 'Hedef kar marjı yüzdesi (örn: 20)'
80
- },
81
- action: {
82
- type: 'string',
83
- enum: ['analyze', 'apply', 'schedule'],
84
- description: 'Sadece analiz, uygula veya zamanla'
85
- }
86
- },
87
- required: ['barcode']
88
- },
89
- handler: async (params) => repricerTool.execute(params, { api, memory, license })
90
- });
91
-
92
- // 👁️ Vision AI
93
- api.registerTool({
94
- name: 'vantuz.vision',
95
- description: `Fotoğraftan ürün bilgisi çıkar ve pazaryerlerine ekle.
96
- - SEO uyumlu başlık oluşturur
97
- - Detaylı açıklama yazar
98
- - Kategori eşleştirir (5 pazaryeri için)
99
- - Tahmini fiyat önerir`,
100
- parameters: {
101
- type: 'object',
102
- properties: {
103
- imageUrl: {
104
- type: 'string',
105
- description: 'Ürün fotoğrafı URL veya base64'
106
- },
107
- targetPlatforms: {
108
- type: 'array',
109
- items: { type: 'string' },
110
- description: 'Hedef pazaryerleri: trendyol, hepsiburada, amazon_de, amazon_us, n11'
111
- },
112
- autoPublish: {
113
- type: 'boolean',
114
- description: 'Otomatik yayınla (true) veya önizleme (false)'
115
- }
116
- },
117
- required: ['imageUrl']
118
- },
119
- handler: async (params) => visionTool.execute(params, { api, memory, license })
120
- });
121
-
122
- // 🧠 Sentiment AI
123
- api.registerTool({
124
- name: 'vantuz.sentiment',
125
- description: `Müşteri yorumlarını analiz et ve aksiyon öner.
126
- - Pozitif/negatif oranları
127
- - Ana şikayet konuları tespit
128
- - Tedarikçi kalite sorunları
129
- - Otomatik yanıt önerileri`,
130
- parameters: {
131
- type: 'object',
132
- properties: {
133
- productId: {
134
- type: 'string',
135
- description: 'Ürün ID veya barkod'
136
- },
137
- platform: {
138
- type: 'string',
139
- enum: ['trendyol', 'hepsiburada', 'amazon', 'n11', 'all'],
140
- description: 'Pazaryeri'
141
- },
142
- period: {
143
- type: 'string',
144
- enum: ['7d', '30d', '90d', 'all'],
145
- description: 'Analiz dönemi'
146
- }
147
- },
148
- required: ['productId']
149
- },
150
- handler: async (params) => sentimentTool.execute(params, { api, memory, license })
151
- });
152
-
153
- // 🌍 Cross-Border
154
- api.registerTool({
155
- name: 'vantuz.crossborder',
156
- description: `Ürünü yurt dışı pazarına uyarla ve sat.
157
- - Dil çevirisi (Almanca, İngilizce)
158
- - Döviz hesaplama
159
- - Kargo + FBA komisyon hesabı
160
- - Optimal satış fiyatı`,
161
- parameters: {
162
- type: 'object',
163
- properties: {
164
- productId: {
165
- type: 'string',
166
- description: 'Kaynak ürün ID veya barkod'
167
- },
168
- sourcePlatform: {
169
- type: 'string',
170
- enum: ['trendyol', 'hepsiburada', 'n11'],
171
- description: 'Kaynak pazaryeri'
172
- },
173
- targetMarket: {
174
- type: 'string',
175
- enum: ['de', 'us', 'uk', 'fr'],
176
- description: 'Hedef pazar'
177
- },
178
- fulfillment: {
179
- type: 'string',
180
- enum: ['fba', 'fbm', 'self'],
181
- description: 'Fulfillment yöntemi'
182
- }
183
- },
184
- required: ['productId', 'targetMarket']
185
- },
186
- handler: async (params) => crossborderTool.execute(params, { api, memory, license })
187
- });
188
-
189
- // 📦 Ürün Yönetimi
190
- api.registerTool({
191
- name: 'vantuz.product',
192
- description: `Ürün işlemleri: liste, güncelle, stok, fiyat.`,
193
- parameters: {
194
- type: 'object',
195
- properties: {
196
- action: {
197
- type: 'string',
198
- enum: ['list', 'get', 'update', 'updatePrice', 'updateStock', 'publish', 'unpublish'],
199
- description: 'Yapılacak işlem'
200
- },
201
- productId: { type: 'string' },
202
- platform: { type: 'string' },
203
- data: { type: 'object', description: 'Güncelleme verisi' }
204
- },
205
- required: ['action']
206
- },
207
- handler: async (params) => productTool.execute(params, { api, memory, license })
208
- });
209
-
210
- // 📊 Analitik
211
- api.registerTool({
212
- name: 'vantuz.analytics',
213
- description: `Satış, stok ve performans raporları.`,
214
- parameters: {
215
- type: 'object',
216
- properties: {
217
- reportType: {
218
- type: 'string',
219
- enum: ['sales', 'stock', 'profit', 'competitors', 'trends'],
220
- description: 'Rapor türü'
221
- },
222
- platform: { type: 'string' },
223
- period: {
224
- type: 'string',
225
- enum: ['today', '7d', '30d', '90d'],
226
- description: 'Dönem'
227
- }
228
- },
229
- required: ['reportType']
230
- },
231
- handler: async (params) => analyticsTool.execute(params, { api, memory, license })
232
- });
233
-
234
- // 🧠 Hafıza Arama
235
- api.registerTool({
236
- name: 'vantuz.memory_search',
237
- description: `Hippocampus hafıza sisteminde arama yap.
238
- Geçmiş kararları, fiyat değişikliklerini, ürün geçmişini sorgula.`,
239
- parameters: {
240
- type: 'object',
241
- properties: {
242
- query: { type: 'string', description: 'Arama sorgusu' },
243
- type: {
244
- type: 'string',
245
- enum: ['decision', 'price_change', 'product', 'conversation', 'all'],
246
- description: 'Hafıza türü'
247
- },
248
- limit: { type: 'number', description: 'Maksimum sonuç' }
249
- },
250
- required: ['query']
251
- },
252
- handler: async (params) => memory.search(params)
253
- });
254
-
255
- // ═══════════════════════════════════════════════════════════════════════════
256
- // 📝 COMMANDS - Kullanıcı tarafından doğrudan çağrılan komutlar
257
- // ═══════════════════════════════════════════════════════════════════════════
258
-
259
- api.registerCommand({
260
- name: 'stok',
261
- description: 'Stok durumunu göster',
262
- acceptsArgs: true,
263
- handler: async (ctx) => {
264
- const platform = ctx.args?.trim() || 'all';
265
- const stocks = await productTool.getStockSummary(platform, { api, memory });
266
- return { text: formatStockReport(stocks) };
267
- }
268
- });
269
-
270
- api.registerCommand({
271
- name: 'fiyat',
272
- description: 'Ürün fiyatını güncelle',
273
- acceptsArgs: true,
274
- handler: async (ctx) => {
275
- // Parse: "iPhone kılıf 199 TL" veya "SKU-123 %10 indirim"
276
- const result = await productTool.parseAndUpdatePrice(ctx.args, { api, memory });
277
- return { text: result.message };
278
- }
279
- });
280
-
281
- api.registerCommand({
282
- name: 'rapor',
283
- description: 'Satış raporu göster',
284
- acceptsArgs: true,
285
- handler: async (ctx) => {
286
- const period = ctx.args?.trim() || '7d';
287
- const report = await analyticsTool.getSalesReport(period, { api, memory });
288
- return { text: formatSalesReport(report) };
289
- }
290
- });
291
-
292
- api.registerCommand({
293
- name: 'rakip',
294
- description: 'Rakip fiyatlarını kontrol et',
295
- acceptsArgs: true,
296
- handler: async (ctx) => {
297
- const barcode = ctx.args?.trim();
298
- if (!barcode) return { text: '❌ Barkod veya ürün adı belirtin.' };
299
- const result = await repricerTool.analyzeCompetitors(barcode, { api, memory });
300
- return { text: formatCompetitorReport(result) };
301
- }
302
- });
303
-
304
- api.registerCommand({
305
- name: 'lisans',
306
- description: 'Lisans durumunu göster',
307
- handler: async () => {
308
- const status = await license.getStatus();
309
- return { text: formatLicenseStatus(status) };
310
- }
311
- });
312
-
313
- api.registerCommand({
314
- name: 'uyari',
315
- description: 'Uyarıları göster',
316
- handler: async () => {
317
- const alerts = alertService.alerts.filter(a => !a.read);
318
- return { text: alertService.formatAlerts(alerts) };
319
- }
320
- });
321
-
322
- api.registerCommand({
323
- name: 'zamanlama',
324
- description: 'Zamanlanmış görevleri göster',
325
- acceptsArgs: true,
326
- handler: async (ctx) => {
327
- if (ctx.args?.includes('ekle')) {
328
- const templates = scheduler.getTemplates();
329
- let msg = '📅 **Hazır Şablonlar**\n\n';
330
- templates.forEach(t => {
331
- msg += `• \`${t.name}\`: ${t.scheduleHuman}\n`;
332
- });
333
- msg += '\n*Eklemek için: /zamanlama ekle [şablon]*';
334
- return { text: msg };
335
- }
336
- const jobs = await scheduler.listJobs();
337
- return { text: formatScheduleList(jobs) };
338
- }
339
- });
340
-
341
- api.registerCommand({
342
- name: 'platformlar',
343
- description: 'Bağlı platformları göster',
344
- handler: async () => {
345
- const result = quickReportTool.generatePlatformStatus();
346
- return { text: result.report };
347
- }
348
- });
349
-
350
- // 👥 Multi-Agent Team Command
351
- api.registerCommand({
352
- name: 'team',
353
- description: 'Yapay Zeka Takımı ile konuş (Milo, Josh, Marketing, Dev)',
354
- acceptsArgs: true,
355
- handler: async (ctx) => {
356
- // Lazy load to avoid circular deps or early init issues
357
- const TeamModule = (await import('../../modules/team/index.js')).default;
358
- const team = new TeamModule(api);
359
- await team.initialize();
360
-
361
- const args = ctx.args ? ctx.args.trim().split(' ') : [];
362
- const subCommand = args[0];
363
-
364
- if (!subCommand) {
365
- return { text: 'Komutlar: /team chat [agent] [mesaj], /team status, /team broadcast [mesaj]' };
366
- }
367
-
368
- if (subCommand === 'chat') {
369
- const agentName = args[1];
370
- const message = args.slice(2).join(' ');
371
- if (!agentName || !message) return { text: 'Kullanım: /team chat [milo|josh|marketing|dev] [mesaj]' };
372
-
373
- const response = await team.chat(agentName, message);
374
- return { text: `**@${agentName}**: ${response}` };
375
- }
376
-
377
- if (subCommand === 'broadcast') {
378
- const message = args.slice(1).join(' ');
379
- if (!message) return { text: 'Mesaj yazın.' };
380
-
381
- const results = await team.broadcast(message);
382
- let report = '📢 **Takım Yanıtları**\n\n';
383
- for (const [name, res] of Object.entries(results)) {
384
- report += `**@${name}**: ${res}\n\n`;
385
- }
386
- return { text: report };
387
- }
388
-
389
- if (subCommand === 'status') {
390
- const memory = team.getSharedMemory().getEverything();
391
- return { text: `📝 **Takım Durumu**\n\n**Hedefler:**\n${memory.goals}\n\n**Durum:**\n${memory.status}` };
392
- }
393
-
394
- return { text: 'Geçersiz komut. Kullanılabilir: chat, broadcast, status' };
395
- }
396
- });
397
-
398
- // ═══════════════════════════════════════════════════════════════════════════
399
- // ⚙️ SERVICES - Arka plan servisleri
400
- // ═══════════════════════════════════════════════════════════════════════════
401
-
402
- // Lisans Doğrulama Servisi
403
- api.registerService({
404
- id: 'vantuz-license',
405
- start: async () => {
406
- logger.info('🔐 Lisans servisi başlatılıyor...');
407
- await license.initialize();
408
-
409
- // Her 24 saatte bir lisans kontrolü
410
- setInterval(() => license.verify(), 24 * 60 * 60 * 1000);
411
- },
412
- stop: () => {
413
- logger.info('🔐 Lisans servisi durduruluyor...');
414
- }
415
- });
416
-
417
- // Hippocampus Hafıza Servisi
418
- api.registerService({
419
- id: 'vantuz-memory',
420
- start: async () => {
421
- logger.info('🧠 Hippocampus hafıza sistemi başlatılıyor...');
422
- await memory.initialize();
423
- },
424
- stop: async () => {
425
- logger.info('🧠 Hippocampus kapatılıyor...');
426
- await memory.close();
427
- }
428
- });
429
-
430
- // Repricer Daemon (Arka planda fiyat kontrolü)
431
- api.registerService({
432
- id: 'vantuz-repricer-daemon',
433
- start: () => {
434
- logger.info('🩸 Kan Emici Repricer daemon başlatılıyor...');
435
-
436
- // Her 15 dakikada bir fiyat kontrolü
437
- const interval = setInterval(async () => {
438
- if (!license.isValid()) return;
439
-
440
- try {
441
- const decisions = await repricerTool.runAutoCycle({ api, memory, license });
442
- if (decisions.length > 0) {
443
- logger.info(`💰 ${decisions.length} fiyat kararı alındı.`);
444
- }
445
- } catch (err) {
446
- logger.error('Repricer hatası:', err);
447
- }
448
- }, 15 * 60 * 1000);
449
-
450
- // Store interval for cleanup
451
- this._repricerInterval = interval;
452
- },
453
- stop: () => {
454
- if (this._repricerInterval) {
455
- clearInterval(this._repricerInterval);
456
- }
457
- logger.info('🩸 Repricer daemon durduruluyor...');
458
- }
459
- });
460
-
461
- // ═══════════════════════════════════════════════════════════════════════════
462
- // 🚀 GATEWAY RPC - Harici API metodları
463
- // ═══════════════════════════════════════════════════════════════════════════
464
-
465
- api.registerGatewayMethod('vantuz.status', ({ respond }) => {
466
- respond(true, {
467
- version: PLUGIN_VERSION,
468
- license: license.getStatus(),
469
- memory: memory.getStats(),
470
- platforms: platformHub.getStatus()
471
- });
472
- });
473
-
474
- api.registerGatewayMethod('vantuz.config', ({ respond, params }) => {
475
- if (params.action === 'get') {
476
- respond(true, config.get('vantuz') || {});
477
- } else if (params.action === 'set') {
478
- config.set('vantuz', params.data);
479
- respond(true, { success: true });
480
- }
481
- });
482
-
483
- // ═══════════════════════════════════════════════════════════════════════════
484
- // 📊 HELPER FUNCTIONS
485
- // ═══════════════════════════════════════════════════════════════════════════
486
-
487
- function formatStockReport(stocks) {
488
- let report = '📦 **Stok Durumu**\n\n';
489
- for (const [platform, data] of Object.entries(stocks)) {
490
- report += `**${platform}**\n`;
491
- report += `• Toplam: ${data.total} ürün\n`;
492
- report += `• Kritik (<5): ${data.critical} ürün\n`;
493
- report += `• Sıfır stok: ${data.zero} ürün\n\n`;
494
- }
495
- return report;
496
- }
497
-
498
- function formatSalesReport(report) {
499
- return `📊 **Satış Raporu (${report.period})**
500
-
501
- 💰 Toplam Ciro: ${report.revenue.toLocaleString('tr-TR')} ₺
502
- 📦 Toplam Sipariş: ${report.orders}
503
- 📈 Ortalama Sepet: ${report.avgBasket.toLocaleString('tr-TR')} ₺
504
- 🏆 En Çok Satan: ${report.topProduct}`;
505
- }
506
-
507
- function formatCompetitorReport(result) {
508
- let report = `🔍 **Rakip Analizi: ${result.product}**\n\n`;
509
- for (const comp of result.competitors) {
510
- report += `• ${comp.name}: ${comp.price} ₺ (Stok: ${comp.stock})\n`;
511
- }
512
- report += `\n💡 **Öneri**: ${result.recommendation}`;
513
- return report;
514
- }
515
-
516
- function formatLicenseStatus(status) {
517
- if (!status.valid) {
518
- return `❌ **Lisans Geçersiz**\nNeden: ${status.reason}`;
519
- }
520
- return `✅ **Lisans Aktif**
521
- 👤 Müşteri: ${status.customer}
522
- 📅 Bitiş: ${status.expiry}
523
- ⏰ Kalan: ${status.daysLeft} gün`;
524
- }
525
-
526
- // Plugin yüklendi
527
- logger.info(`🐙 Vantuz AI v${PLUGIN_VERSION} yüklendi!`);
528
- }
1
+ /**
2
+ * 🐙 VANTUZ AI v3.1
3
+ * E-Ticaretin Yapay Zeka Beyni
4
+ *
5
+ * Bu plugin şunları sağlar:
6
+ * - 7 Pazaryeri API Entegrasyonu (Trendyol, HB, N11, Amazon, CS, PTT, Pazarama)
7
+ * - E-ticaret araçları (repricer, vision, sentiment, crossborder)
8
+ * - Özel komutlar (/stok, /fiyat, /rapor, /uyari)
9
+ * - Cron zamanlama ve otomasyon
10
+ * - Hippocampus hafıza sistemi
11
+ */
12
+
13
+ import { Hippocampus } from './memory/hippocampus.js';
14
+ import { LicenseManager } from './services/license.js';
15
+ import SchedulerService from './services/scheduler.js';
16
+ import AlertService from './services/alerts.js';
17
+
18
+ // Tools
19
+ import { repricerTool } from './tools/repricer.js';
20
+ import { visionTool } from './tools/vision.js';
21
+ import { sentimentTool } from './tools/sentiment.js';
22
+ import { crossborderTool } from './tools/crossborder.js';
23
+ import { productTool } from './tools/product.js';
24
+ import { analyticsTool } from './tools/analytics.js';
25
+ import { quickReportTool } from './tools/quick-report.js';
26
+ import NLParser from './tools/nl-parser.js';
27
+
28
+ // Platform APIs
29
+ import platformHub, {
30
+ trendyolApi,
31
+ hepsiburadaApi,
32
+ n11Api,
33
+ amazonApi,
34
+ ciceksepetiApi,
35
+ pttavmApi,
36
+ pazaramaApi
37
+ } from './platforms/index.js';
38
+
39
+
40
+ const PLUGIN_ID = 'vantuz';
41
+ const PLUGIN_VERSION = '3.0.0';
42
+
43
+ export default function (api) {
44
+ const logger = api.logger;
45
+ const config = api.config;
46
+
47
+ // Hippocampus hafıza sistemi
48
+ const memory = new Hippocampus(api);
49
+
50
+ // Lisans yöneticisi
51
+ const license = new LicenseManager(api);
52
+
53
+ // ═══════════════════════════════════════════════════════════════════════════
54
+ // 🔧 TOOLS - AI tarafından çağrılabilir araçlar
55
+ // ═══════════════════════════════════════════════════════════════════════════
56
+
57
+ // 🩸 Kan Emici Repricer
58
+ api.registerTool({
59
+ name: 'vantuz.repricer',
60
+ description: `Rakip fiyatlarını analiz et ve optimal fiyat öner.
61
+ Akıllı kararlar verir:
62
+ - Rakip stoku azsa → Fiyatı yükselt
63
+ - Rakip fiyat düşürdüyse → Kar marjına göre takip et
64
+ - Satış hızı yüksekse → Fiyatı optimize et`,
65
+ parameters: {
66
+ type: 'object',
67
+ properties: {
68
+ barcode: {
69
+ type: 'string',
70
+ description: 'Ürün barkodu veya SKU'
71
+ },
72
+ platform: {
73
+ type: 'string',
74
+ enum: ['trendyol', 'hepsiburada', 'amazon', 'n11', 'all'],
75
+ description: 'Hedef pazaryeri'
76
+ },
77
+ targetMargin: {
78
+ type: 'number',
79
+ description: 'Hedef kar marjı yüzdesi (örn: 20)'
80
+ },
81
+ action: {
82
+ type: 'string',
83
+ enum: ['analyze', 'apply', 'schedule'],
84
+ description: 'Sadece analiz, uygula veya zamanla'
85
+ }
86
+ },
87
+ required: ['barcode']
88
+ },
89
+ handler: async (params) => repricerTool.execute(params, { api, memory, license })
90
+ });
91
+
92
+ // 👁️ Vision AI
93
+ api.registerTool({
94
+ name: 'vantuz.vision',
95
+ description: `Fotoğraftan ürün bilgisi çıkar ve pazaryerlerine ekle.
96
+ - SEO uyumlu başlık oluşturur
97
+ - Detaylı açıklama yazar
98
+ - Kategori eşleştirir (5 pazaryeri için)
99
+ - Tahmini fiyat önerir`,
100
+ parameters: {
101
+ type: 'object',
102
+ properties: {
103
+ imageUrl: {
104
+ type: 'string',
105
+ description: 'Ürün fotoğrafı URL veya base64'
106
+ },
107
+ targetPlatforms: {
108
+ type: 'array',
109
+ items: { type: 'string' },
110
+ description: 'Hedef pazaryerleri: trendyol, hepsiburada, amazon_de, amazon_us, n11'
111
+ },
112
+ autoPublish: {
113
+ type: 'boolean',
114
+ description: 'Otomatik yayınla (true) veya önizleme (false)'
115
+ }
116
+ },
117
+ required: ['imageUrl']
118
+ },
119
+ handler: async (params) => visionTool.execute(params, { api, memory, license })
120
+ });
121
+
122
+ // 🧠 Sentiment AI
123
+ api.registerTool({
124
+ name: 'vantuz.sentiment',
125
+ description: `Müşteri yorumlarını analiz et ve aksiyon öner.
126
+ - Pozitif/negatif oranları
127
+ - Ana şikayet konuları tespit
128
+ - Tedarikçi kalite sorunları
129
+ - Otomatik yanıt önerileri`,
130
+ parameters: {
131
+ type: 'object',
132
+ properties: {
133
+ productId: {
134
+ type: 'string',
135
+ description: 'Ürün ID veya barkod'
136
+ },
137
+ platform: {
138
+ type: 'string',
139
+ enum: ['trendyol', 'hepsiburada', 'amazon', 'n11', 'all'],
140
+ description: 'Pazaryeri'
141
+ },
142
+ period: {
143
+ type: 'string',
144
+ enum: ['7d', '30d', '90d', 'all'],
145
+ description: 'Analiz dönemi'
146
+ }
147
+ },
148
+ required: ['productId']
149
+ },
150
+ handler: async (params) => sentimentTool.execute(params, { api, memory, license })
151
+ });
152
+
153
+ // 🌍 Cross-Border
154
+ api.registerTool({
155
+ name: 'vantuz.crossborder',
156
+ description: `Ürünü yurt dışı pazarına uyarla ve sat.
157
+ - Dil çevirisi (Almanca, İngilizce)
158
+ - Döviz hesaplama
159
+ - Kargo + FBA komisyon hesabı
160
+ - Optimal satış fiyatı`,
161
+ parameters: {
162
+ type: 'object',
163
+ properties: {
164
+ productId: {
165
+ type: 'string',
166
+ description: 'Kaynak ürün ID veya barkod'
167
+ },
168
+ sourcePlatform: {
169
+ type: 'string',
170
+ enum: ['trendyol', 'hepsiburada', 'n11'],
171
+ description: 'Kaynak pazaryeri'
172
+ },
173
+ targetMarket: {
174
+ type: 'string',
175
+ enum: ['de', 'us', 'uk', 'fr'],
176
+ description: 'Hedef pazar'
177
+ },
178
+ fulfillment: {
179
+ type: 'string',
180
+ enum: ['fba', 'fbm', 'self'],
181
+ description: 'Fulfillment yöntemi'
182
+ }
183
+ },
184
+ required: ['productId', 'targetMarket']
185
+ },
186
+ handler: async (params) => crossborderTool.execute(params, { api, memory, license })
187
+ });
188
+
189
+ // 📦 Ürün Yönetimi
190
+ api.registerTool({
191
+ name: 'vantuz.product',
192
+ description: `Ürün işlemleri: liste, güncelle, stok, fiyat.`,
193
+ parameters: {
194
+ type: 'object',
195
+ properties: {
196
+ action: {
197
+ type: 'string',
198
+ enum: ['list', 'get', 'update', 'updatePrice', 'updateStock', 'publish', 'unpublish'],
199
+ description: 'Yapılacak işlem'
200
+ },
201
+ productId: { type: 'string' },
202
+ platform: { type: 'string' },
203
+ data: { type: 'object', description: 'Güncelleme verisi' }
204
+ },
205
+ required: ['action']
206
+ },
207
+ handler: async (params) => productTool.execute(params, { api, memory, license })
208
+ });
209
+
210
+ // 📊 Analitik
211
+ api.registerTool({
212
+ name: 'vantuz.analytics',
213
+ description: `Satış, stok ve performans raporları.`,
214
+ parameters: {
215
+ type: 'object',
216
+ properties: {
217
+ reportType: {
218
+ type: 'string',
219
+ enum: ['sales', 'stock', 'profit', 'competitors', 'trends'],
220
+ description: 'Rapor türü'
221
+ },
222
+ platform: { type: 'string' },
223
+ period: {
224
+ type: 'string',
225
+ enum: ['today', '7d', '30d', '90d'],
226
+ description: 'Dönem'
227
+ }
228
+ },
229
+ required: ['reportType']
230
+ },
231
+ handler: async (params) => analyticsTool.execute(params, { api, memory, license })
232
+ });
233
+
234
+ // 🧠 Hafıza Arama
235
+ api.registerTool({
236
+ name: 'vantuz.memory_search',
237
+ description: `Hippocampus hafıza sisteminde arama yap.
238
+ Geçmiş kararları, fiyat değişikliklerini, ürün geçmişini sorgula.`,
239
+ parameters: {
240
+ type: 'object',
241
+ properties: {
242
+ query: { type: 'string', description: 'Arama sorgusu' },
243
+ type: {
244
+ type: 'string',
245
+ enum: ['decision', 'price_change', 'product', 'conversation', 'all'],
246
+ description: 'Hafıza türü'
247
+ },
248
+ limit: { type: 'number', description: 'Maksimum sonuç' }
249
+ },
250
+ required: ['query']
251
+ },
252
+ handler: async (params) => memory.search(params)
253
+ });
254
+
255
+ // ═══════════════════════════════════════════════════════════════════════════
256
+ // 📝 COMMANDS - Kullanıcı tarafından doğrudan çağrılan komutlar
257
+ // ═══════════════════════════════════════════════════════════════════════════
258
+
259
+ api.registerCommand({
260
+ name: 'stok',
261
+ description: 'Stok durumunu göster',
262
+ acceptsArgs: true,
263
+ handler: async (ctx) => {
264
+ const platform = ctx.args?.trim() || 'all';
265
+ const stocks = await productTool.getStockSummary(platform, { api, memory });
266
+ return { text: formatStockReport(stocks) };
267
+ }
268
+ });
269
+
270
+ api.registerCommand({
271
+ name: 'fiyat',
272
+ description: 'Ürün fiyatını güncelle',
273
+ acceptsArgs: true,
274
+ handler: async (ctx) => {
275
+ // Parse: "iPhone kılıf 199 TL" veya "SKU-123 %10 indirim"
276
+ const result = await productTool.parseAndUpdatePrice(ctx.args, { api, memory });
277
+ return { text: result.message };
278
+ }
279
+ });
280
+
281
+ api.registerCommand({
282
+ name: 'rapor',
283
+ description: 'Satış raporu göster',
284
+ acceptsArgs: true,
285
+ handler: async (ctx) => {
286
+ const period = ctx.args?.trim() || '7d';
287
+ const report = await analyticsTool.getSalesReport(period, { api, memory });
288
+ return { text: formatSalesReport(report) };
289
+ }
290
+ });
291
+
292
+ api.registerCommand({
293
+ name: 'rakip',
294
+ description: 'Rakip fiyatlarını kontrol et',
295
+ acceptsArgs: true,
296
+ handler: async (ctx) => {
297
+ const barcode = ctx.args?.trim();
298
+ if (!barcode) return { text: '❌ Barkod veya ürün adı belirtin.' };
299
+ const result = await repricerTool.analyzeCompetitors(barcode, { api, memory });
300
+ return { text: formatCompetitorReport(result) };
301
+ }
302
+ });
303
+
304
+ api.registerCommand({
305
+ name: 'lisans',
306
+ description: 'Lisans durumunu göster',
307
+ handler: async () => {
308
+ const status = await license.getStatus();
309
+ return { text: formatLicenseStatus(status) };
310
+ }
311
+ });
312
+
313
+ api.registerCommand({
314
+ name: 'uyari',
315
+ description: 'Uyarıları göster',
316
+ handler: async () => {
317
+ const alerts = alertService.alerts.filter(a => !a.read);
318
+ return { text: alertService.formatAlerts(alerts) };
319
+ }
320
+ });
321
+
322
+ api.registerCommand({
323
+ name: 'zamanlama',
324
+ description: 'Zamanlanmış görevleri göster',
325
+ acceptsArgs: true,
326
+ handler: async (ctx) => {
327
+ if (ctx.args?.includes('ekle')) {
328
+ const templates = scheduler.getTemplates();
329
+ let msg = '📅 **Hazır Şablonlar**\n\n';
330
+ templates.forEach(t => {
331
+ msg += `• \`${t.name}\`: ${t.scheduleHuman}\n`;
332
+ });
333
+ msg += '\n*Eklemek için: /zamanlama ekle [şablon]*';
334
+ return { text: msg };
335
+ }
336
+ const jobs = await scheduler.listJobs();
337
+ return { text: formatScheduleList(jobs) };
338
+ }
339
+ });
340
+
341
+ api.registerCommand({
342
+ name: 'platformlar',
343
+ description: 'Bağlı platformları göster',
344
+ handler: async () => {
345
+ const result = quickReportTool.generatePlatformStatus();
346
+ return { text: result.report };
347
+ }
348
+ });
349
+
350
+ // 👥 Multi-Agent Team Command
351
+ api.registerCommand({
352
+ name: 'team',
353
+ description: 'Yapay Zeka Takımı ile konuş (Milo, Josh, Marketing, Dev)',
354
+ acceptsArgs: true,
355
+ handler: async (ctx) => {
356
+ // Lazy load to avoid circular deps or early init issues
357
+ const TeamModule = (await import('../../modules/team/index.js')).default;
358
+ const team = new TeamModule(api);
359
+ await team.initialize();
360
+
361
+ const args = ctx.args ? ctx.args.trim().split(' ') : [];
362
+ const subCommand = args[0];
363
+
364
+ if (!subCommand) {
365
+ return { text: 'Komutlar: /team chat [agent] [mesaj], /team status, /team broadcast [mesaj]' };
366
+ }
367
+
368
+ if (subCommand === 'chat') {
369
+ const agentName = args[1];
370
+ const message = args.slice(2).join(' ');
371
+ if (!agentName || !message) return { text: 'Kullanım: /team chat [milo|josh|marketing|dev] [mesaj]' };
372
+
373
+ const response = await team.chat(agentName, message);
374
+ return { text: `**@${agentName}**: ${response}` };
375
+ }
376
+
377
+ if (subCommand === 'broadcast') {
378
+ const message = args.slice(1).join(' ');
379
+ if (!message) return { text: 'Mesaj yazın.' };
380
+
381
+ const results = await team.broadcast(message);
382
+ let report = '📢 **Takım Yanıtları**\n\n';
383
+ for (const [name, res] of Object.entries(results)) {
384
+ report += `**@${name}**: ${res}\n\n`;
385
+ }
386
+ return { text: report };
387
+ }
388
+
389
+ if (subCommand === 'status') {
390
+ const memory = team.getSharedMemory().getEverything();
391
+ return { text: `📝 **Takım Durumu**\n\n**Hedefler:**\n${memory.goals}\n\n**Durum:**\n${memory.status}` };
392
+ }
393
+
394
+ return { text: 'Geçersiz komut. Kullanılabilir: chat, broadcast, status' };
395
+ }
396
+ });
397
+
398
+ // ═══════════════════════════════════════════════════════════════════════════
399
+ // ⚙️ SERVICES - Arka plan servisleri
400
+ // ═══════════════════════════════════════════════════════════════════════════
401
+
402
+ // Lisans Doğrulama Servisi
403
+ api.registerService({
404
+ id: 'vantuz-license',
405
+ start: async () => {
406
+ logger.info('🔐 Lisans servisi başlatılıyor...');
407
+ await license.initialize();
408
+
409
+ // Her 24 saatte bir lisans kontrolü
410
+ setInterval(() => license.verify(), 24 * 60 * 60 * 1000);
411
+ },
412
+ stop: () => {
413
+ logger.info('🔐 Lisans servisi durduruluyor...');
414
+ }
415
+ });
416
+
417
+ // Hippocampus Hafıza Servisi
418
+ api.registerService({
419
+ id: 'vantuz-memory',
420
+ start: async () => {
421
+ logger.info('🧠 Hippocampus hafıza sistemi başlatılıyor...');
422
+ await memory.initialize();
423
+ },
424
+ stop: async () => {
425
+ logger.info('🧠 Hippocampus kapatılıyor...');
426
+ await memory.close();
427
+ }
428
+ });
429
+
430
+ // Repricer Daemon (Arka planda fiyat kontrolü)
431
+ api.registerService({
432
+ id: 'vantuz-repricer-daemon',
433
+ start: () => {
434
+ logger.info('🩸 Kan Emici Repricer daemon başlatılıyor...');
435
+
436
+ // Her 15 dakikada bir fiyat kontrolü
437
+ const interval = setInterval(async () => {
438
+ if (!license.isValid()) return;
439
+
440
+ try {
441
+ const decisions = await repricerTool.runAutoCycle({ api, memory, license });
442
+ if (decisions.length > 0) {
443
+ logger.info(`💰 ${decisions.length} fiyat kararı alındı.`);
444
+ }
445
+ } catch (err) {
446
+ logger.error('Repricer hatası:', err);
447
+ }
448
+ }, 15 * 60 * 1000);
449
+
450
+ // Store interval for cleanup
451
+ this._repricerInterval = interval;
452
+ },
453
+ stop: () => {
454
+ if (this._repricerInterval) {
455
+ clearInterval(this._repricerInterval);
456
+ }
457
+ logger.info('🩸 Repricer daemon durduruluyor...');
458
+ }
459
+ });
460
+
461
+ // ═══════════════════════════════════════════════════════════════════════════
462
+ // 🚀 GATEWAY RPC - Harici API metodları
463
+ // ═══════════════════════════════════════════════════════════════════════════
464
+
465
+ api.registerGatewayMethod('vantuz.status', ({ respond }) => {
466
+ respond(true, {
467
+ version: PLUGIN_VERSION,
468
+ license: license.getStatus(),
469
+ memory: memory.getStats(),
470
+ platforms: platformHub.getStatus()
471
+ });
472
+ });
473
+
474
+ api.registerGatewayMethod('vantuz.config', ({ respond, params }) => {
475
+ if (params.action === 'get') {
476
+ respond(true, config.get('vantuz') || {});
477
+ } else if (params.action === 'set') {
478
+ config.set('vantuz', params.data);
479
+ respond(true, { success: true });
480
+ }
481
+ });
482
+
483
+ // ═══════════════════════════════════════════════════════════════════════════
484
+ // 📊 HELPER FUNCTIONS
485
+ // ═══════════════════════════════════════════════════════════════════════════
486
+
487
+ function formatStockReport(stocks) {
488
+ let report = '📦 **Stok Durumu**\n\n';
489
+ for (const [platform, data] of Object.entries(stocks)) {
490
+ report += `**${platform}**\n`;
491
+ report += `• Toplam: ${data.total} ürün\n`;
492
+ report += `• Kritik (<5): ${data.critical} ürün\n`;
493
+ report += `• Sıfır stok: ${data.zero} ürün\n\n`;
494
+ }
495
+ return report;
496
+ }
497
+
498
+ function formatSalesReport(report) {
499
+ return `📊 **Satış Raporu (${report.period})**
500
+
501
+ 💰 Toplam Ciro: ${report.revenue.toLocaleString('tr-TR')} ₺
502
+ 📦 Toplam Sipariş: ${report.orders}
503
+ 📈 Ortalama Sepet: ${report.avgBasket.toLocaleString('tr-TR')} ₺
504
+ 🏆 En Çok Satan: ${report.topProduct}`;
505
+ }
506
+
507
+ function formatCompetitorReport(result) {
508
+ let report = `🔍 **Rakip Analizi: ${result.product}**\n\n`;
509
+ for (const comp of result.competitors) {
510
+ report += `• ${comp.name}: ${comp.price} ₺ (Stok: ${comp.stock})\n`;
511
+ }
512
+ report += `\n💡 **Öneri**: ${result.recommendation}`;
513
+ return report;
514
+ }
515
+
516
+ function formatLicenseStatus(status) {
517
+ if (!status.valid) {
518
+ return `❌ **Lisans Geçersiz**\nNeden: ${status.reason}`;
519
+ }
520
+ return `✅ **Lisans Aktif**
521
+ 👤 Müşteri: ${status.customer}
522
+ 📅 Bitiş: ${status.expiry}
523
+ ⏰ Kalan: ${status.daysLeft} gün`;
524
+ }
525
+
526
+ // Plugin yüklendi
527
+ logger.info(`🐙 Vantuz AI v${PLUGIN_VERSION} yüklendi!`);
528
+ }