natureco-cli 2.17.7 → 2.17.9
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 +94 -222
package/package.json
CHANGED
package/src/commands/chat.js
CHANGED
|
@@ -1,40 +1,42 @@
|
|
|
1
1
|
const path = require('path');
|
|
2
2
|
const os = require('os');
|
|
3
3
|
const fs = require('fs');
|
|
4
|
+
const readline = require('readline');
|
|
4
5
|
const inquirer = require('inquirer');
|
|
5
6
|
const chalk = require('chalk');
|
|
6
7
|
const { getApiKey, getConfig } = require('../utils/config');
|
|
7
8
|
const { getBots, sendMessage, _sendMessage } = require('../utils/api');
|
|
8
9
|
const { getSkillPrompts, getSkills } = require('../utils/skills');
|
|
9
10
|
const { getAgentsPrompt } = require('../utils/agents');
|
|
10
|
-
const { addToHistory
|
|
11
|
+
const { addToHistory } = require('../utils/history');
|
|
11
12
|
const { getMemoryPrompt, extractMemoryFromMessage, loadMemory, clearMemory, addMemoryEntry } = require('../utils/memory');
|
|
12
13
|
const { getCommands, getCommandContent } = require('../utils/commands');
|
|
13
14
|
const { runHooks } = require('../utils/hooks');
|
|
14
15
|
const { createSession, loadSession, getLatestSession, addMessageToSession } = require('../utils/sessions');
|
|
15
|
-
const { addBackgroundTask, updateBackgroundTask } = require('../utils/background');
|
|
16
16
|
const { getToolDefinitions, executeToolCalls } = require('../utils/tool-runner');
|
|
17
17
|
const { extractToolCalls } = require('../utils/tool-adapter');
|
|
18
18
|
|
|
19
19
|
// ── ASCII Logo ────────────────────────────────────────────────────────────────
|
|
20
20
|
const ASCII_LOGO = [
|
|
21
|
-
'
|
|
22
|
-
'
|
|
23
|
-
'
|
|
24
|
-
'
|
|
25
|
-
'
|
|
26
|
-
'
|
|
27
|
-
]
|
|
21
|
+
'███╗ ██╗ █████╗ ████████╗██╗ ██╗██████╗ ███████╗ ██████╗ ██████╗',
|
|
22
|
+
'████╗ ██║██╔══██╗╚══██╔══╝██║ ██║██╔══██╗██╔════╝██╔════╝ ██╔═══██╗',
|
|
23
|
+
'██╔██╗ ██║███████║ ██║ ██║ ██║██████╔╝█████╗ ██║ ██║ ██║',
|
|
24
|
+
'██║╚██╗██║██╔══██║ ██║ ██║ ██║██╔══██╗██╔══╝ ██║ ██║ ██║',
|
|
25
|
+
'██║ ╚████║██║ ██║ ██║ ╚██████╔╝██║ ██║███████╗╚██████╗ ╚██████╔╝',
|
|
26
|
+
'╚═╝ ╚═══╝╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝ ╚═════╝ ╚═════╝',
|
|
27
|
+
];
|
|
28
28
|
|
|
29
29
|
// ── What's New ────────────────────────────────────────────────────────────────
|
|
30
30
|
const CHANGELOG = [
|
|
31
|
-
'Eklendi:
|
|
31
|
+
'Eklendi: Chalk TUI — saf readline tabanlı arayüz',
|
|
32
32
|
'Eklendi: agents, plugins, pairing, uninstall komutları',
|
|
33
33
|
'Eklendi: channels, models, memory, logs, status, security, reset',
|
|
34
|
-
'Düzeltildi:
|
|
34
|
+
'Düzeltildi: Çift karakter ve input sorunu giderildi',
|
|
35
35
|
'Düzeltildi: Token optimizasyonu — sistem prompt sıkıştırıldı',
|
|
36
36
|
];
|
|
37
37
|
|
|
38
|
+
const sep = () => chalk.gray('─'.repeat(process.stdout.columns || 80));
|
|
39
|
+
|
|
38
40
|
async function chat(botName, options = {}) {
|
|
39
41
|
const apiKey = getApiKey();
|
|
40
42
|
const config = getConfig();
|
|
@@ -111,154 +113,75 @@ async function chat(botName, options = {}) {
|
|
|
111
113
|
try { lastVersion = fs.readFileSync(lastVersionFile, 'utf8').trim(); } catch {}
|
|
112
114
|
const isNewVersion = lastVersion !== version;
|
|
113
115
|
|
|
114
|
-
// ──
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
} catch {
|
|
119
|
-
// blessed yüklü değilse fallback
|
|
120
|
-
return chatFallback(bot, botList, displayBotName, userName, shortModel, apiKey, config, systemPrompt, session, conversationId, options);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
const screen = blessed.screen({
|
|
124
|
-
smartCSR: true,
|
|
125
|
-
title: `NatureCo · ${displayBotName}`,
|
|
126
|
-
terminal: 'xterm-256color',
|
|
127
|
-
fullUnicode: true,
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
// ── Logo kutusu (üst %30) ───────────────────────────────────────────────────
|
|
131
|
-
const rabbitLine = `{cyan-fg}(\\_{/}{cyan-fg}/) {/}{white-fg}Hoş geldin, ${userName}{/} {gray-fg}·{/} {cyan-fg}${displayBotName} hazır{/} {gray-fg}·{/} {gray-fg}v${version}{/}`;
|
|
132
|
-
const logoContent = ASCII_LOGO + '\n\n' + rabbitLine;
|
|
133
|
-
|
|
134
|
-
const logoBox = blessed.box({
|
|
135
|
-
top: 0,
|
|
136
|
-
left: 0,
|
|
137
|
-
width: '100%',
|
|
138
|
-
height: '28%',
|
|
139
|
-
content: logoContent,
|
|
140
|
-
align: 'center',
|
|
141
|
-
valign: 'middle',
|
|
142
|
-
tags: true,
|
|
143
|
-
style: { fg: 'green', bg: 'default' },
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
// ── Mesaj alanı (%58) ───────────────────────────────────────────────────────
|
|
147
|
-
const messageBox = blessed.log({
|
|
148
|
-
top: '28%',
|
|
149
|
-
left: 0,
|
|
150
|
-
width: '100%',
|
|
151
|
-
height: '58%',
|
|
152
|
-
scrollable: true,
|
|
153
|
-
alwaysScroll: true,
|
|
154
|
-
tags: true,
|
|
155
|
-
padding: { left: 2, right: 2, top: 1 },
|
|
156
|
-
scrollbar: { ch: '│', style: { fg: 'gray' } },
|
|
157
|
-
style: { bg: 'default' },
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
// ── Input kutusu (3 satır) ──────────────────────────────────────────────────
|
|
161
|
-
const inputSeparator = blessed.line({
|
|
162
|
-
bottom: 4,
|
|
163
|
-
left: 0,
|
|
164
|
-
width: '100%',
|
|
165
|
-
orientation: 'horizontal',
|
|
166
|
-
style: { fg: 'gray' },
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
const inputBox = blessed.textbox({
|
|
170
|
-
bottom: 1,
|
|
171
|
-
left: 0,
|
|
172
|
-
width: '100%',
|
|
173
|
-
height: 3,
|
|
174
|
-
inputOnFocus: false,
|
|
175
|
-
keys: true,
|
|
176
|
-
mouse: true,
|
|
177
|
-
padding: { left: 2 },
|
|
178
|
-
style: {
|
|
179
|
-
fg: 'white',
|
|
180
|
-
bg: 'default',
|
|
181
|
-
},
|
|
182
|
-
});
|
|
183
|
-
|
|
184
|
-
// ── Status bar (en alt 1 satır) ─────────────────────────────────────────────
|
|
185
|
-
const cwd = process.cwd().replace(os.homedir(), '~');
|
|
186
|
-
const statusBar = blessed.box({
|
|
187
|
-
bottom: 0,
|
|
188
|
-
left: 0,
|
|
189
|
-
width: '100%',
|
|
190
|
-
height: 1,
|
|
191
|
-
content: ` {cyan-fg}${displayBotName}{/} {gray-fg}·{/} {gray-fg}${shortModel}{/}{|}${cwd} `,
|
|
192
|
-
tags: true,
|
|
193
|
-
style: { bg: 'default', fg: 'gray' },
|
|
116
|
+
// ── Header ──────────────────────────────────────────────────────────────────
|
|
117
|
+
console.clear();
|
|
118
|
+
ASCII_LOGO.forEach((line, i) => {
|
|
119
|
+
console.log(i < 5 ? chalk.green(line) : chalk.gray(line));
|
|
194
120
|
});
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
screen.append(inputBox);
|
|
200
|
-
screen.append(statusBar);
|
|
201
|
-
|
|
202
|
-
inputBox.focus();
|
|
203
|
-
screen.render();
|
|
121
|
+
console.log();
|
|
122
|
+
console.log(chalk.cyan(` (\\_/) `) + chalk.white(`Hoş geldin, ${userName}`) + chalk.gray(' · ') + chalk.cyan(`${displayBotName} hazır`) + chalk.gray(` · v${version}`));
|
|
123
|
+
console.log(sep());
|
|
124
|
+
console.log();
|
|
204
125
|
|
|
205
126
|
// ── What's New ──────────────────────────────────────────────────────────────
|
|
206
127
|
if (isNewVersion) {
|
|
207
|
-
|
|
208
|
-
CHANGELOG.forEach(c =>
|
|
209
|
-
|
|
128
|
+
console.log(chalk.yellow(`── v${version} yenilikleri ──`));
|
|
129
|
+
CHANGELOG.forEach(c => console.log(chalk.gray(` · ${c}`)));
|
|
130
|
+
console.log();
|
|
210
131
|
try { fs.writeFileSync(lastVersionFile, version); } catch {}
|
|
211
132
|
}
|
|
212
133
|
|
|
213
|
-
// Önceki session
|
|
134
|
+
// ── Önceki session mesajları ─────────────────────────────────────────────────
|
|
214
135
|
if (options.resume && session.messages?.length) {
|
|
215
136
|
const last = session.messages.slice(-5);
|
|
216
137
|
last.forEach(msg => {
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
138
|
+
console.log(chalk.white('You ') + msg.user);
|
|
139
|
+
console.log(chalk.cyan(`${displayBotName} `) + msg.bot);
|
|
140
|
+
console.log();
|
|
220
141
|
});
|
|
221
142
|
}
|
|
222
143
|
|
|
144
|
+
console.log(chalk.gray(` ${shortModel} · /help için yardım · Ctrl+C çıkış`));
|
|
145
|
+
console.log(sep());
|
|
146
|
+
console.log();
|
|
147
|
+
|
|
223
148
|
// ── Yükleme animasyonu ──────────────────────────────────────────────────────
|
|
224
149
|
let loadingTimer = null;
|
|
225
|
-
let loadingFrame = 0;
|
|
226
150
|
const loadingFrames = ['●○○', '○●○', '○○●'];
|
|
151
|
+
let loadingFrame = 0;
|
|
227
152
|
|
|
228
153
|
function startLoading() {
|
|
229
154
|
loadingFrame = 0;
|
|
155
|
+
process.stdout.write(chalk.gray(' ' + loadingFrames[0]));
|
|
230
156
|
loadingTimer = setInterval(() => {
|
|
231
|
-
|
|
157
|
+
process.stdout.write('\r' + chalk.gray(' ' + loadingFrames[loadingFrame]));
|
|
232
158
|
loadingFrame = (loadingFrame + 1) % loadingFrames.length;
|
|
233
|
-
screen.render();
|
|
234
159
|
}, 300);
|
|
235
160
|
}
|
|
236
161
|
|
|
237
162
|
function stopLoading() {
|
|
238
163
|
if (loadingTimer) { clearInterval(loadingTimer); loadingTimer = null; }
|
|
239
|
-
|
|
240
|
-
screen.render();
|
|
164
|
+
process.stdout.write('\r\x1b[2K');
|
|
241
165
|
}
|
|
242
166
|
|
|
243
167
|
// ── Mesaj gönderme ──────────────────────────────────────────────────────────
|
|
244
168
|
async function handleMessage(userMessage) {
|
|
245
169
|
userMessage = userMessage.trim();
|
|
246
|
-
if (!userMessage)
|
|
170
|
+
if (!userMessage) return;
|
|
247
171
|
|
|
248
172
|
// /komutlar
|
|
249
173
|
if (userMessage.startsWith('/')) {
|
|
250
174
|
const [cmd, ...args] = userMessage.slice(1).split(' ');
|
|
251
175
|
switch (cmd.toLowerCase()) {
|
|
252
176
|
case 'clear':
|
|
253
|
-
|
|
254
|
-
screen.render();
|
|
177
|
+
console.clear();
|
|
255
178
|
return;
|
|
256
179
|
case 'bot':
|
|
257
180
|
if (!args.length) {
|
|
258
|
-
|
|
181
|
+
console.log(chalk.yellow('Aktif bot: ') + bot.name);
|
|
259
182
|
botList.bots.forEach(b => {
|
|
260
|
-
const mark = b.id === bot.id ? '
|
|
261
|
-
|
|
183
|
+
const mark = b.id === bot.id ? chalk.green('✓ ') : ' ';
|
|
184
|
+
console.log(mark + chalk.cyan(b.name));
|
|
262
185
|
});
|
|
263
186
|
} else {
|
|
264
187
|
const newName = args.join(' ');
|
|
@@ -267,76 +190,74 @@ async function chat(botName, options = {}) {
|
|
|
267
190
|
bot = newBot;
|
|
268
191
|
conversationId = null;
|
|
269
192
|
session = createSession(bot.id, bot.name);
|
|
270
|
-
|
|
193
|
+
console.log(chalk.green(`Bot değişti: ${newBot.name}`));
|
|
271
194
|
} else {
|
|
272
|
-
|
|
195
|
+
console.log(chalk.red(`Bot bulunamadı: ${newName}`));
|
|
273
196
|
}
|
|
274
197
|
}
|
|
275
|
-
|
|
198
|
+
console.log();
|
|
276
199
|
return;
|
|
277
200
|
case 'skills':
|
|
278
201
|
const skills = getSkills();
|
|
279
|
-
if (!skills.length)
|
|
280
|
-
else skills.forEach(s =>
|
|
281
|
-
|
|
202
|
+
if (!skills.length) console.log(chalk.gray('Yüklü skill yok.'));
|
|
203
|
+
else skills.forEach(s => console.log(chalk.cyan(`· ${s.name}`) + chalk.gray(` ${s.description}`)));
|
|
204
|
+
console.log();
|
|
282
205
|
return;
|
|
283
206
|
case 'memory':
|
|
284
207
|
if (args[0] === 'clear') {
|
|
285
208
|
clearMemory(bot.id);
|
|
286
|
-
|
|
209
|
+
console.log(chalk.green('✓ Hafıza temizlendi'));
|
|
287
210
|
} else {
|
|
288
211
|
const m = loadMemory(bot.id);
|
|
289
|
-
if (m.botName)
|
|
290
|
-
if (m.name)
|
|
212
|
+
if (m.botName) console.log(chalk.cyan('Bot: ') + m.botName);
|
|
213
|
+
if (m.name) console.log(chalk.cyan('İsim: ') + m.name);
|
|
291
214
|
(m.facts || []).slice(0, 8).forEach(f => {
|
|
292
215
|
const v = typeof f === 'string' ? f : f.value;
|
|
293
|
-
|
|
216
|
+
console.log(chalk.gray(`· ${v}`));
|
|
294
217
|
});
|
|
295
218
|
}
|
|
296
|
-
|
|
219
|
+
console.log();
|
|
297
220
|
return;
|
|
298
221
|
case 'help':
|
|
222
|
+
console.log(chalk.yellow('Chat Komutları:'));
|
|
299
223
|
[
|
|
300
|
-
'
|
|
301
|
-
'
|
|
302
|
-
'
|
|
303
|
-
'
|
|
304
|
-
'
|
|
305
|
-
'
|
|
306
|
-
'
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
screen.render();
|
|
224
|
+
['/clear', 'Ekranı temizle'],
|
|
225
|
+
['/bot [ad]', 'Bot değiştir'],
|
|
226
|
+
['/skills', 'Skill listesi'],
|
|
227
|
+
['/memory', 'Hafızayı göster'],
|
|
228
|
+
['/memory clear', 'Hafızayı temizle'],
|
|
229
|
+
['/commands', 'Özel komutlar'],
|
|
230
|
+
['/help', 'Bu yardım'],
|
|
231
|
+
].forEach(([c, d]) => console.log(' ' + chalk.cyan(c.padEnd(16)) + chalk.gray(d)));
|
|
232
|
+
console.log(chalk.gray(' Ctrl+C'.padEnd(18) + 'Çıkış'));
|
|
233
|
+
console.log();
|
|
311
234
|
return;
|
|
312
235
|
case 'commands':
|
|
313
236
|
const cmds = getCommands();
|
|
314
|
-
if (!cmds.length)
|
|
315
|
-
else cmds.forEach(c =>
|
|
316
|
-
|
|
237
|
+
if (!cmds.length) console.log(chalk.gray('Özel komut yok.'));
|
|
238
|
+
else cmds.forEach(c => console.log(chalk.cyan(`/${c.name}`)));
|
|
239
|
+
console.log();
|
|
317
240
|
return;
|
|
318
241
|
default:
|
|
319
242
|
const customCmd = getCommandContent(cmd);
|
|
320
243
|
if (customCmd) {
|
|
321
244
|
const customPrompt = systemPrompt + '\n\n## Custom Command\n' + customCmd;
|
|
322
245
|
const msg = args.length ? args.join(' ') : 'Execute the custom command instruction';
|
|
323
|
-
|
|
246
|
+
console.log(chalk.white('You ') + userMessage);
|
|
324
247
|
startLoading();
|
|
325
248
|
try {
|
|
326
249
|
const res = await sendMessage(apiKey || config.providerApiKey, bot.id, msg, conversationId, customPrompt);
|
|
327
250
|
stopLoading();
|
|
328
251
|
if (res.conversation_id) conversationId = res.conversation_id;
|
|
329
252
|
const reply = res.reply || res.message || '';
|
|
330
|
-
|
|
331
|
-
|
|
253
|
+
console.log(chalk.cyan(`${displayBotName} `) + reply);
|
|
254
|
+
console.log();
|
|
332
255
|
addToHistory(bot.id, userMessage, reply, conversationId);
|
|
333
256
|
addMessageToSession(bot.id, session.id, userMessage, reply);
|
|
334
|
-
} catch (e) { stopLoading();
|
|
335
|
-
messageBox.setScrollPerc(100);
|
|
336
|
-
screen.render();
|
|
257
|
+
} catch (e) { stopLoading(); console.log(chalk.red(`Error: ${e.message}`)); console.log(); }
|
|
337
258
|
} else {
|
|
338
|
-
|
|
339
|
-
|
|
259
|
+
console.log(chalk.red(`Bilinmeyen komut: /${cmd}`));
|
|
260
|
+
console.log();
|
|
340
261
|
}
|
|
341
262
|
return;
|
|
342
263
|
}
|
|
@@ -345,15 +266,13 @@ async function chat(botName, options = {}) {
|
|
|
345
266
|
// exit/quit
|
|
346
267
|
if (userMessage === 'exit' || userMessage === 'quit') {
|
|
347
268
|
await runHooks('on-exit', null, { botId: bot.id, botName: bot.name });
|
|
348
|
-
|
|
269
|
+
console.log(chalk.gray('\n👋 Goodbye!\n'));
|
|
349
270
|
process.exit(0);
|
|
350
271
|
}
|
|
351
272
|
|
|
352
273
|
// Normal mesaj
|
|
353
274
|
userMessage = await runHooks('pre-message', userMessage, { botId: bot.id, botName: bot.name });
|
|
354
|
-
|
|
355
|
-
messageBox.setScrollPerc(100);
|
|
356
|
-
screen.render();
|
|
275
|
+
console.log(chalk.white('You ') + userMessage);
|
|
357
276
|
|
|
358
277
|
startLoading();
|
|
359
278
|
|
|
@@ -369,8 +288,7 @@ async function chat(botName, options = {}) {
|
|
|
369
288
|
while (iter < 5) {
|
|
370
289
|
const toolCalls = extractToolCalls(response);
|
|
371
290
|
if (!toolCalls?.length) break;
|
|
372
|
-
|
|
373
|
-
screen.render();
|
|
291
|
+
console.log(chalk.yellow(`🔧 ${toolCalls.length} tool çalıştırılıyor...`));
|
|
374
292
|
const toolResults = await executeToolCalls(toolCalls);
|
|
375
293
|
const toolMsg = toolResults.map(tr => `Tool: ${tr.name}\nResult: ${tr.result.success ? (tr.result.output || '') : tr.result.error}`).join('\n\n');
|
|
376
294
|
startLoading();
|
|
@@ -383,10 +301,8 @@ async function chat(botName, options = {}) {
|
|
|
383
301
|
let botReply = response.reply || response.message || 'No response';
|
|
384
302
|
botReply = await runHooks('post-message', botReply, { botId: bot.id, botName: bot.name });
|
|
385
303
|
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
messageBox.setScrollPerc(100);
|
|
389
|
-
screen.render();
|
|
304
|
+
console.log(chalk.cyan(`${displayBotName} `) + botReply);
|
|
305
|
+
console.log();
|
|
390
306
|
|
|
391
307
|
addToHistory(bot.id, userMessage, botReply, conversationId);
|
|
392
308
|
addMessageToSession(bot.id, session.id, userMessage, botReply);
|
|
@@ -397,79 +313,35 @@ async function chat(botName, options = {}) {
|
|
|
397
313
|
} catch (err) {
|
|
398
314
|
stopLoading();
|
|
399
315
|
const errMsg = err.message.split('"message":"')[1]?.split('"')[0] || err.message;
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
screen.render();
|
|
316
|
+
console.log(chalk.red(`Error: ${errMsg}`));
|
|
317
|
+
console.log();
|
|
403
318
|
}
|
|
404
|
-
|
|
405
|
-
inputBox.focus();
|
|
406
319
|
}
|
|
407
320
|
|
|
408
|
-
// ──
|
|
409
|
-
|
|
410
|
-
const msg = inputBox.getValue();
|
|
411
|
-
inputBox.clearValue();
|
|
412
|
-
screen.render();
|
|
413
|
-
await handleMessage(msg);
|
|
414
|
-
inputBox.focus();
|
|
415
|
-
screen.render();
|
|
416
|
-
});
|
|
321
|
+
// ── Input loop ───────────────────────────────────────────────────────────────
|
|
322
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stdout, terminal: true });
|
|
417
323
|
|
|
418
|
-
|
|
419
|
-
screen.key(['C-c'], async () => {
|
|
324
|
+
process.on('SIGINT', async () => {
|
|
420
325
|
await runHooks('on-exit', null, { botId: bot.id, botName: bot.name });
|
|
421
|
-
|
|
326
|
+
rl.close();
|
|
327
|
+
console.log(chalk.gray('\n👋 Goodbye!\n'));
|
|
422
328
|
process.exit(0);
|
|
423
329
|
});
|
|
424
330
|
|
|
331
|
+
rl.on('close', () => process.exit(0));
|
|
332
|
+
|
|
425
333
|
// ── on-start hooks ──────────────────────────────────────────────────────────
|
|
426
334
|
await runHooks('on-start', null, { botId: bot.id, botName: bot.name });
|
|
427
335
|
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
console.clear();
|
|
437
|
-
console.log(chalk.green.bold(' (\\_/)'));
|
|
438
|
-
console.log(chalk.green.bold(' (•ᴥ•)'));
|
|
439
|
-
console.log(chalk.green(' />🌿'));
|
|
440
|
-
console.log('');
|
|
441
|
-
const sep = chalk.gray('─'.repeat(process.stdout.columns || 80));
|
|
442
|
-
console.log(sep);
|
|
443
|
-
console.log(chalk.white.bold('NatureCo') + chalk.gray(' · ') + chalk.cyan(displayBotName) + chalk.gray(' · ') + chalk.gray(shortModel));
|
|
444
|
-
console.log(sep);
|
|
445
|
-
console.log('');
|
|
446
|
-
|
|
447
|
-
const rl = readline.createInterface({ input: process.stdin, output: process.stdout, prompt: chalk.gray('You ') });
|
|
448
|
-
rl.prompt();
|
|
449
|
-
|
|
450
|
-
rl.on('line', async (line) => {
|
|
451
|
-
const msg = line.trim();
|
|
452
|
-
if (!msg) { rl.prompt(); return; }
|
|
453
|
-
if (msg === 'exit' || msg === 'quit') { console.log(chalk.gray('\n👋 Goodbye!\n')); process.exit(0); }
|
|
454
|
-
|
|
455
|
-
process.stdout.write(chalk.cyan('... '));
|
|
456
|
-
try {
|
|
457
|
-
const toolDefinitions = getToolDefinitions();
|
|
458
|
-
const response = await _sendMessage(apiKey || config.providerApiKey, bot.id, msg, conversationId, systemPrompt, toolDefinitions);
|
|
459
|
-
process.stdout.write('\r');
|
|
460
|
-
if (response.conversation_id) conversationId = response.conversation_id;
|
|
461
|
-
const reply = response.reply || response.message || '';
|
|
462
|
-
console.log(chalk.cyan(`${displayBotName} `) + reply + '\n');
|
|
463
|
-
addToHistory(bot.id, msg, reply, conversationId);
|
|
464
|
-
addMessageToSession(bot.id, session.id, msg, reply);
|
|
465
|
-
} catch (e) {
|
|
466
|
-
process.stdout.write('\r');
|
|
467
|
-
console.log(chalk.red(`Error: ${e.message}\n`));
|
|
468
|
-
}
|
|
469
|
-
rl.prompt();
|
|
470
|
-
});
|
|
336
|
+
async function promptLoop() {
|
|
337
|
+
rl.question('', async (msg) => {
|
|
338
|
+
process.stdout.write('\x1b[1A\x1b[2K');
|
|
339
|
+
await handleMessage(msg);
|
|
340
|
+
promptLoop();
|
|
341
|
+
});
|
|
342
|
+
}
|
|
471
343
|
|
|
472
|
-
|
|
344
|
+
promptLoop();
|
|
473
345
|
}
|
|
474
346
|
|
|
475
347
|
module.exports = chat;
|