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,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
+ }