vantuz 3.3.7 → 3.4.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.
@@ -0,0 +1,169 @@
1
+ // modules/researcher/agent.js
2
+ // Research Agent for Vantuz OS V2
3
+ // Performs web research on demand, summarizes findings, stores in memory.
4
+
5
+ import axios from 'axios';
6
+ import { log } from '../../core/ai-provider.js';
7
+ import { getMemory } from '../../core/memory.js';
8
+
9
+ // ═══════════════════════════════════════════════════════════════════════════
10
+ // WEB SEARCH PROVIDERS
11
+ // ═══════════════════════════════════════════════════════════════════════════
12
+
13
+ async function searchBrave(query, apiKey) {
14
+ const response = await axios.get('https://api.search.brave.com/res/v1/web/search', {
15
+ params: { q: query, count: 5 },
16
+ headers: { 'X-Subscription-Token': apiKey }
17
+ });
18
+ return (response.data.web?.results || []).map(r => ({
19
+ title: r.title,
20
+ url: r.url,
21
+ snippet: r.description
22
+ }));
23
+ }
24
+
25
+ async function searchGoogle(query, apiKey, cx) {
26
+ const response = await axios.get('https://www.googleapis.com/customsearch/v1', {
27
+ params: { q: query, key: apiKey, cx, num: 5 }
28
+ });
29
+ return (response.data.items || []).map(r => ({
30
+ title: r.title,
31
+ url: r.link,
32
+ snippet: r.snippet
33
+ }));
34
+ }
35
+
36
+ // Fallback: No API — use AI's existing knowledge
37
+ async function searchFallback(query) {
38
+ return [{
39
+ title: 'AI Bilgi Tabanı',
40
+ url: 'internal',
41
+ snippet: `"${query}" hakkında web araması yapılamadı. API anahtarı eksik. AI bilgisiyle yanıt veriliyor.`
42
+ }];
43
+ }
44
+
45
+ // ═══════════════════════════════════════════════════════════════════════════
46
+ // RESEARCH AGENT
47
+ // ═══════════════════════════════════════════════════════════════════════════
48
+
49
+ class ResearchAgent {
50
+ constructor(config = {}) {
51
+ this.braveApiKey = config.braveApiKey || process.env.BRAVE_SEARCH_API_KEY || null;
52
+ this.googleApiKey = config.googleApiKey || process.env.GOOGLE_SEARCH_API_KEY || null;
53
+ this.googleCx = config.googleCx || process.env.GOOGLE_SEARCH_CX || null;
54
+ this.aiChat = config.aiChat || null; // AI chat function for summarization
55
+ this.history = [];
56
+ log('INFO', 'ResearchAgent initialized', {
57
+ brave: !!this.braveApiKey,
58
+ google: !!this.googleApiKey
59
+ });
60
+ }
61
+
62
+ /**
63
+ * Set the AI chat function for summarization.
64
+ */
65
+ setAiChat(fn) {
66
+ this.aiChat = fn;
67
+ }
68
+
69
+ /**
70
+ * Perform a research query.
71
+ * @param {string} query - The research question.
72
+ * @returns {{ query, results, summary, savedToMemory }}
73
+ */
74
+ async research(query) {
75
+ log('INFO', `🔍 Researching: "${query}"`);
76
+
77
+ // Step 1: Web search
78
+ let results;
79
+ try {
80
+ if (this.braveApiKey) {
81
+ results = await searchBrave(query, this.braveApiKey);
82
+ } else if (this.googleApiKey && this.googleCx) {
83
+ results = await searchGoogle(query, this.googleApiKey, this.googleCx);
84
+ } else {
85
+ results = await searchFallback(query);
86
+ }
87
+ } catch (e) {
88
+ log('ERROR', 'Web search failed', { error: e.message });
89
+ results = await searchFallback(query);
90
+ }
91
+
92
+ // Step 2: AI summarization
93
+ let summary = '';
94
+ if (this.aiChat && results.length > 0) {
95
+ const context = results.map((r, i) =>
96
+ `${i + 1}. ${r.title}\n ${r.snippet}\n Kaynak: ${r.url}`
97
+ ).join('\n\n');
98
+
99
+ const prompt = `Şu araştırma sorusu için web sonuçlarını analiz et ve 3 maddelik özet yap. Türkçe yanıtla.
100
+
101
+ Soru: "${query}"
102
+
103
+ Web Sonuçları:
104
+ ${context}
105
+
106
+ Formatın:
107
+ 1. [Ana bulgu]
108
+ 2. [Ana bulgu]
109
+ 3. [Ana bulgu]
110
+
111
+ Kaynak: [URL listesi]`;
112
+
113
+ try {
114
+ summary = await this.aiChat(prompt);
115
+ } catch (e) {
116
+ summary = `Özet oluşturulamadı: ${e.message}`;
117
+ }
118
+ } else {
119
+ summary = results.map(r => `• ${r.title}: ${r.snippet}`).join('\n');
120
+ }
121
+
122
+ // Step 3: Save to memory
123
+ let savedToMemory = false;
124
+ try {
125
+ const memory = getMemory();
126
+ memory.remember(`Araştırma: "${query}" — ${summary.substring(0, 200)}...`, 'research');
127
+ savedToMemory = true;
128
+ } catch (e) { /* ignore */ }
129
+
130
+ const report = {
131
+ query,
132
+ results,
133
+ summary,
134
+ savedToMemory,
135
+ timestamp: new Date().toISOString()
136
+ };
137
+
138
+ this.history.push(report);
139
+ if (this.history.length > 50) this.history = this.history.slice(-50);
140
+
141
+ log('INFO', `Research complete: "${query}"`, { resultCount: results.length });
142
+ return report;
143
+ }
144
+
145
+ /**
146
+ * Get previous research results.
147
+ */
148
+ getHistory(limit = 10) {
149
+ return this.history.slice(-limit);
150
+ }
151
+
152
+ getStatus() {
153
+ return {
154
+ provider: this.braveApiKey ? 'Brave' : this.googleApiKey ? 'Google' : 'Fallback (AI)',
155
+ researchCount: this.history.length
156
+ };
157
+ }
158
+ }
159
+
160
+ let researcherInstance = null;
161
+
162
+ export function getResearchAgent(config = {}) {
163
+ if (!researcherInstance) {
164
+ researcherInstance = new ResearchAgent(config);
165
+ }
166
+ return researcherInstance;
167
+ }
168
+
169
+ export default ResearchAgent;
@@ -0,0 +1,92 @@
1
+ // modules/team/agents/base.js
2
+ import fs from 'fs';
3
+ import path from 'path';
4
+ import { chat, log } from '../../core/ai-provider.js';
5
+ import sharedMemory from '../shared-memory.js';
6
+
7
+ export class BaseAgent {
8
+ constructor(name, role, context = {}) {
9
+ this.name = name.toLowerCase();
10
+ this.displayName = name;
11
+ this.role = role;
12
+ this.context = context; // API, config, etc.
13
+ this.agentDir = sharedMemory.getAgentDir(this.name);
14
+
15
+ this.ensureSoul();
16
+ }
17
+
18
+ ensureSoul() {
19
+ const soulPath = path.join(this.agentDir, 'SOUL.md');
20
+ if (!fs.existsSync(soulPath)) {
21
+ const defaultSoul = `# SOUL.md — ${this.displayName}
22
+
23
+ Sen ${this.displayName}, ${this.role} rolündesin.
24
+
25
+ ## Sorumlulukların
26
+ - [Buraya sorumlulukları girin]
27
+
28
+ ## Kişilik
29
+ - Profesyonel, verimli.
30
+
31
+ ## Kanal
32
+ - Telegram/CLI (@${this.name} yanıt verir)
33
+ `;
34
+ fs.writeFileSync(soulPath, defaultSoul, 'utf-8');
35
+ }
36
+ }
37
+
38
+ getSoul() {
39
+ return fs.readFileSync(path.join(this.agentDir, 'SOUL.md'), 'utf-8');
40
+ }
41
+
42
+ async getSystemPrompt() {
43
+ const shared = sharedMemory.getEverything();
44
+ const soul = this.getSoul();
45
+
46
+ return `${soul}
47
+
48
+ ## TAKIM PAYLAŞILAN BAĞLAMI
49
+ Sen çoklu-ajan takımının bir parçasısın. Aşağıdaki paylaşılan belgelere erişimin var:
50
+
51
+ ### HEDEFLER (GOALS)
52
+ ${shared.goals}
53
+
54
+ ### PROJE DURUMU (STATUS)
55
+ ${shared.status}
56
+
57
+ ### KARAR GÜNLÜĞÜ (DECISIONS)
58
+ ${shared.decisions}
59
+
60
+ ## TALİMATLAR
61
+ 1. SOUL.md ve Rolüne uygun hareket et.
62
+ 2. Önemli bir karar alırsan, DECISIONS.md dosyasını güncellemeyi talep et.
63
+ 3. Eğer başka bir ajanın uzmanlığına ihtiyacın varsa, yanıtında şu formatı kullan:
64
+ `[DELEGATE: AjanIsmi Soru veya Görev]`
65
+ Örnek: `[DELEGATE: Josh iPhone kılıflarının kar marjını kontrol et]`
66
+ 4. Kısa ve öz ol.`;
67
+ }
68
+
69
+ async think(userMessage, conversationHistory = []) {
70
+ try {
71
+ const systemPrompt = await this.getSystemPrompt();
72
+
73
+ // Format history for the AI provider if needed, or just append to prompt
74
+ // For now, we rely on the provider's handling or just send the current message + context
75
+
76
+ const response = await chat(userMessage, {
77
+ aiProvider: process.env.VANTUZ_AI_PROVIDER || 'gemini',
78
+ systemContext: systemPrompt
79
+ }, process.env);
80
+
81
+ return response;
82
+ } catch (error) {
83
+ log('ERROR', `Agent ${this.displayName} crashed`, { error: error.message });
84
+ return `I encountered an error: ${error.message}`;
85
+ }
86
+ }
87
+
88
+ async process(message) {
89
+ log('INFO', `Agent ${this.displayName} processing message`);
90
+ return await this.think(message);
91
+ }
92
+ }
@@ -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();