natureco-cli 2.4.3 → 2.4.5
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.
- package/package.json +1 -1
- package/src/commands/chat.js +4 -1
- package/src/commands/dashboard.js +2 -2
- package/src/commands/gateway-server.js +9 -2
- package/src/utils/api.js +1 -1
- package/src/utils/memory.js +47 -12
package/package.json
CHANGED
package/src/commands/chat.js
CHANGED
|
@@ -292,6 +292,9 @@ async function chat(botName, options = {}) {
|
|
|
292
292
|
|
|
293
293
|
const memory = loadMemory(bot.id);
|
|
294
294
|
console.log(chalk.yellow('\nHafıza:\n'));
|
|
295
|
+
if (memory.botName) {
|
|
296
|
+
console.log(chalk.cyan(' Bot Adı:'), chalk.white(memory.botName));
|
|
297
|
+
}
|
|
295
298
|
if (memory.name) {
|
|
296
299
|
console.log(chalk.cyan(' İsim:'), chalk.white(memory.name));
|
|
297
300
|
}
|
|
@@ -309,7 +312,7 @@ async function chat(botName, options = {}) {
|
|
|
309
312
|
console.log(chalk.white(` • ${f.value}`) + chalk.gray(` (skor: ${f.score})`));
|
|
310
313
|
});
|
|
311
314
|
}
|
|
312
|
-
if (!memory.name && memory.preferences.length === 0 && memory.facts.length === 0) {
|
|
315
|
+
if (!memory.botName && !memory.name && memory.preferences.length === 0 && memory.facts.length === 0) {
|
|
313
316
|
console.log(chalk.gray(' Henüz hafıza yok'));
|
|
314
317
|
}
|
|
315
318
|
console.log('');
|
|
@@ -211,7 +211,7 @@ body::before{
|
|
|
211
211
|
<div class="header-bot-name" id="header-bot-name">Nature Bot</div>
|
|
212
212
|
<div class="header-bot-model" id="header-bot-model">NatureCo</div>
|
|
213
213
|
</div>
|
|
214
|
-
<div class="version-badge" id="version-badge">v2.4.
|
|
214
|
+
<div class="version-badge" id="version-badge">v2.4.5</div>
|
|
215
215
|
</div>
|
|
216
216
|
<div class="messages" id="messages"></div>
|
|
217
217
|
<div class="input-area">
|
|
@@ -341,7 +341,7 @@ function dashboard(action) {
|
|
|
341
341
|
apiKey: cfg.apiKey,
|
|
342
342
|
defaultBot: cfg.defaultBot,
|
|
343
343
|
defaultBotId: cfg.defaultBotId,
|
|
344
|
-
version: 'v2.4.
|
|
344
|
+
version: 'v2.4.5',
|
|
345
345
|
bots: cfg.bots || [],
|
|
346
346
|
telegramToken: cfg.telegramToken || null,
|
|
347
347
|
whatsappConnected: cfg.whatsappConnected || false,
|
|
@@ -128,7 +128,7 @@ async function startGateway() {
|
|
|
128
128
|
|
|
129
129
|
async function runGatewayWorker() {
|
|
130
130
|
// This runs in the background
|
|
131
|
-
log('gateway', 'Starting NatureCo Gateway v2.4.
|
|
131
|
+
log('gateway', 'Starting NatureCo Gateway v2.4.5...', 'green');
|
|
132
132
|
|
|
133
133
|
// Load config
|
|
134
134
|
const { getConfig } = require('../utils/config');
|
|
@@ -293,7 +293,7 @@ async function startWhatsAppProvider(sessionDir, config) {
|
|
|
293
293
|
try {
|
|
294
294
|
// v2.x: Send to universal provider (Groq/OpenAI/Anthropic)
|
|
295
295
|
const { sendMessage } = require('../utils/api');
|
|
296
|
-
const { getMemoryPrompt } = require('../utils/memory');
|
|
296
|
+
const { getMemoryPrompt, extractMemoryFromMessage, addMemoryEntry } = require('../utils/memory');
|
|
297
297
|
|
|
298
298
|
log('whatsapp', 'Sending to AI provider...', 'cyan');
|
|
299
299
|
|
|
@@ -323,6 +323,13 @@ async function startWhatsAppProvider(sessionDir, config) {
|
|
|
323
323
|
lastBotReply = reply;
|
|
324
324
|
|
|
325
325
|
log('whatsapp', `Reply sent (${reply.length} chars)`, 'green');
|
|
326
|
+
|
|
327
|
+
// Extract and save memory from user message
|
|
328
|
+
const memoryEntries = extractMemoryFromMessage(messageText);
|
|
329
|
+
for (const entry of memoryEntries) {
|
|
330
|
+
addMemoryEntry(botId, entry.key, entry.value);
|
|
331
|
+
log('whatsapp', `Memory saved: ${entry.key} = ${entry.value}`, 'gray');
|
|
332
|
+
}
|
|
326
333
|
} else {
|
|
327
334
|
log('whatsapp', 'No reply from provider', 'yellow');
|
|
328
335
|
}
|
package/src/utils/api.js
CHANGED
package/src/utils/memory.js
CHANGED
|
@@ -24,6 +24,7 @@ function loadMemory(botId) {
|
|
|
24
24
|
if (!fs.existsSync(filePath)) {
|
|
25
25
|
return {
|
|
26
26
|
name: null,
|
|
27
|
+
botName: null,
|
|
27
28
|
preferences: [],
|
|
28
29
|
facts: [],
|
|
29
30
|
lastSeen: null,
|
|
@@ -42,10 +43,16 @@ function loadMemory(botId) {
|
|
|
42
43
|
memory.facts = memory.facts.map(f => ({ value: f, score: 5, updatedAt: new Date().toISOString() }));
|
|
43
44
|
}
|
|
44
45
|
|
|
46
|
+
// Ensure botName field exists
|
|
47
|
+
if (!memory.hasOwnProperty('botName')) {
|
|
48
|
+
memory.botName = null;
|
|
49
|
+
}
|
|
50
|
+
|
|
45
51
|
return memory;
|
|
46
52
|
} catch {
|
|
47
53
|
return {
|
|
48
54
|
name: null,
|
|
55
|
+
botName: null,
|
|
49
56
|
preferences: [],
|
|
50
57
|
facts: [],
|
|
51
58
|
lastSeen: null,
|
|
@@ -72,6 +79,8 @@ function addMemoryEntry(botId, key, value) {
|
|
|
72
79
|
|
|
73
80
|
if (key === 'name') {
|
|
74
81
|
memory.name = value;
|
|
82
|
+
} else if (key === 'botName') {
|
|
83
|
+
memory.botName = value;
|
|
75
84
|
} else if (key === 'preference') {
|
|
76
85
|
// Check for duplicate
|
|
77
86
|
const existing = memory.preferences.find(p => p.value.toLowerCase() === value.toLowerCase());
|
|
@@ -125,6 +134,22 @@ function extractMemoryFromMessage(message) {
|
|
|
125
134
|
// Check if message is a question
|
|
126
135
|
const isQuestion = questionWords.some(q => message.toLowerCase().includes(q)) || message.includes('?');
|
|
127
136
|
|
|
137
|
+
// Bot name patterns: "senin adın X", "sana X diyeceğim", "adın X olsun"
|
|
138
|
+
const botNamePatterns = [
|
|
139
|
+
/senin\s+ad[ıi]n\s+([A-ZÇĞİÖŞÜ][a-zçğıöşü]+)/i,
|
|
140
|
+
/sana\s+([A-ZÇĞİÖŞÜ][a-zçğıöşü]+)\s+diyece[ğg]im/i,
|
|
141
|
+
/ad[ıi]n\s+([A-ZÇĞİÖŞÜ][a-zçğıöşü]+)\s+olsun/i,
|
|
142
|
+
/seni\s+([A-ZÇĞİÖŞÜ][a-zçğıöşü]+)\s+olarak\s+çağ[ıi]raca[ğg][ıi]m/i,
|
|
143
|
+
];
|
|
144
|
+
|
|
145
|
+
for (const pattern of botNamePatterns) {
|
|
146
|
+
const match = message.match(pattern);
|
|
147
|
+
if (match) {
|
|
148
|
+
extracted.push({ key: 'botName', value: match[1] });
|
|
149
|
+
break;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
128
153
|
// Name patterns: "adım X", "ben X'im", "ismim X", "benim adım X"
|
|
129
154
|
// Only extract if NOT a question
|
|
130
155
|
if (!isQuestion) {
|
|
@@ -171,24 +196,34 @@ function extractMemoryFromMessage(message) {
|
|
|
171
196
|
function getMemoryPrompt(botId) {
|
|
172
197
|
const memory = loadMemory(botId);
|
|
173
198
|
|
|
174
|
-
if (!memory.name && memory.preferences.length === 0 && memory.facts.length === 0) {
|
|
199
|
+
if (!memory.name && !memory.botName && memory.preferences.length === 0 && memory.facts.length === 0) {
|
|
175
200
|
return '';
|
|
176
201
|
}
|
|
177
202
|
|
|
178
|
-
const parts = [
|
|
203
|
+
const parts = [];
|
|
179
204
|
|
|
180
|
-
|
|
181
|
-
|
|
205
|
+
// Add bot name if set
|
|
206
|
+
if (memory.botName) {
|
|
207
|
+
parts.push(`Your name is ${memory.botName}.`);
|
|
182
208
|
}
|
|
183
209
|
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
parts.push(
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
210
|
+
// Add user memory section
|
|
211
|
+
if (memory.name || memory.preferences.length > 0 || memory.facts.length > 0) {
|
|
212
|
+
parts.push('## Kullanıcı Hafızası');
|
|
213
|
+
|
|
214
|
+
if (memory.name) {
|
|
215
|
+
parts.push(`İsim: ${memory.name}`);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
if (memory.preferences.length > 0) {
|
|
219
|
+
const sorted = memory.preferences.sort((a, b) => b.score - a.score);
|
|
220
|
+
parts.push(`Tercihler: ${sorted.map(p => p.value).join(', ')}`);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
if (memory.facts.length > 0) {
|
|
224
|
+
const sorted = memory.facts.sort((a, b) => b.score - a.score);
|
|
225
|
+
parts.push(`Bilgiler: ${sorted.map(f => f.value).join(', ')}`);
|
|
226
|
+
}
|
|
192
227
|
}
|
|
193
228
|
|
|
194
229
|
return parts.join('\n');
|