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