natureco-cli 2.15.6 → 2.15.8

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "natureco-cli",
3
- "version": "2.15.6",
3
+ "version": "2.15.8",
4
4
  "description": "NatureCo AI Bot Terminal Interface",
5
5
  "main": "bin/natureco.js",
6
6
  "bin": {
@@ -251,7 +251,7 @@ async function chat(botName, options = {}) {
251
251
  if (session) {
252
252
  console.log(chalk.blue(`Resumed: ${session.id}\n`));
253
253
  // Display last few messages
254
- const lastMessages = session.messages.slice(-3);
254
+ const lastMessages = (session.messages || []).slice(-3);
255
255
  lastMessages.forEach(msg => {
256
256
  console.log(chalk.gray('You ') + msg.user);
257
257
  console.log(chalk.cyan(displayBotName + ' ') + msg.bot);
@@ -267,7 +267,7 @@ async function chat(botName, options = {}) {
267
267
  if (session) {
268
268
  console.log(chalk.blue(`Resumed: ${session.id}\n`));
269
269
  // Display last few messages
270
- const lastMessages = session.messages.slice(-3);
270
+ const lastMessages = (session.messages || []).slice(-3);
271
271
  lastMessages.forEach(msg => {
272
272
  console.log(chalk.gray('You ') + msg.user);
273
273
  console.log(chalk.cyan(displayBotName + ' ') + msg.bot);
@@ -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.15.6</div>
214
+ <div class="version-badge" id="version-badge">v2.15.8</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.15.6',
344
+ version: 'v2.15.8',
345
345
  bots: cfg.bots || [],
346
346
  telegramToken: cfg.telegramToken || null,
347
347
  whatsappConnected: cfg.whatsappConnected || false,
@@ -277,21 +277,62 @@ async function setup() {
277
277
 
278
278
  printDone(L, `${providerUrl.replace('https://', '').split('/')[0]} · ${providerModel}`);
279
279
 
280
- // ── ADIM 2: Bot adı ────────────────────────────────────────────────────────
280
+ // ── ADIM 2: Bot adı — NatureCo provider'da API'den çek ───────────────────
281
281
  printStep(L, 2, L.botNameTitle);
282
282
 
283
- const { botName } = await inquirer.prompt([{
284
- type: 'input',
285
- name: 'botName',
286
- message: L.botNameQ,
287
- default: existingConfig.botName || L.botNameDefault,
288
- validate: (v) => v.trim() ? true : L.nameRequired,
289
- }]);
290
-
291
- printDone(L, botName.trim());
283
+ let safeBotName = existingConfig.botName || 'NatureBot';
292
284
 
293
- // botName'in string olduğunu garantile
294
- const safeBotName = String(botName || 'NatureBot').trim();
285
+ if (isNatureCo) {
286
+ // API'den bot listesini çek
287
+ console.log(chalk.gray(lang === 'tr' ? ' Botlar yükleniyor...' : ' Loading bots...'));
288
+ try {
289
+ const res = await fetch('https://api.natureco.me/api/v1/bots', {
290
+ headers: { 'Authorization': `Bearer ${providerApiKey.trim()}` },
291
+ });
292
+ if (res.ok) {
293
+ const data = await res.json();
294
+ const bots = Array.isArray(data) ? data : (data.bots || data.data || []);
295
+ if (bots.length > 0) {
296
+ if (bots.length === 1) {
297
+ // Tek bot varsa otomatik seç
298
+ safeBotName = bots[0].name;
299
+ printDone(L, safeBotName);
300
+ } else {
301
+ // Birden fazla bot varsa seçtir
302
+ const { selectedBotName } = await inquirer.prompt([{
303
+ type: 'list',
304
+ name: 'selectedBotName',
305
+ message: lang === 'tr' ? ' Hangi botu kullanmak istiyorsunuz?' : ' Which bot do you want to use?',
306
+ choices: bots.map(b => ({ name: b.name, value: b.name })),
307
+ }]);
308
+ safeBotName = selectedBotName;
309
+ printDone(L, safeBotName);
310
+ }
311
+ } else {
312
+ console.log(chalk.yellow(lang === 'tr'
313
+ ? ' Bot bulunamadı. developers.natureco.me\'den bot oluşturun.'
314
+ : ' No bots found. Create one at developers.natureco.me'));
315
+ printDone(L, safeBotName);
316
+ }
317
+ } else {
318
+ console.log(chalk.yellow(lang === 'tr' ? ' Bot listesi alınamadı.' : ' Could not fetch bot list.'));
319
+ printDone(L, safeBotName);
320
+ }
321
+ } catch (e) {
322
+ console.log(chalk.yellow(lang === 'tr' ? ' Bağlantı hatası, varsayılan kullanılıyor.' : ' Connection error, using default.'));
323
+ printDone(L, safeBotName);
324
+ }
325
+ } else {
326
+ const { botName } = await inquirer.prompt([{
327
+ type: 'input',
328
+ name: 'botName',
329
+ message: L.botNameQ,
330
+ default: existingConfig.botName || L.botNameDefault,
331
+ validate: (v) => v.trim() ? true : L.nameRequired,
332
+ }]);
333
+ safeBotName = String(botName || 'NatureBot').trim();
334
+ printDone(L, safeBotName);
335
+ }
295
336
 
296
337
  // ── ADIM 3: Kullanıcı adı ──────────────────────────────────────────────────
297
338
  printStep(L, 3, L.userNameTitle);
@@ -492,6 +533,7 @@ async function setup() {
492
533
  console.log(chalk.cyan(` ${L.chatStart}`));
493
534
  console.log('');
494
535
  const chat = require('./chat');
536
+ // NatureCo provider'da seçilen bot adıyla başlat
495
537
  await chat(safeBotName, {});
496
538
  } else {
497
539
  console.log(chalk.gray(` ${L.chatSkip}`));
package/src/utils/api.js CHANGED
@@ -42,7 +42,8 @@ function loadConversation(convId) {
42
42
  try {
43
43
  fs.mkdirSync(CONV_DIR, { recursive: true });
44
44
  if (fs.existsSync(file)) {
45
- return JSON.parse(fs.readFileSync(file, 'utf8'));
45
+ const parsed = JSON.parse(fs.readFileSync(file, 'utf8'));
46
+ return Array.isArray(parsed) ? parsed : [];
46
47
  }
47
48
  } catch (e) {
48
49
  // Silently fail
@@ -772,9 +773,49 @@ async function validateApiKey(apiKey) {
772
773
  * Get bots (not used in v2.x, kept for compatibility)
773
774
  */
774
775
  async function getBots(apiKey) {
776
+ const config = getConfig();
775
777
  const providerConfig = getProviderConfig();
778
+
779
+ // NatureCo provider — gerçek bot listesini API'den çek
780
+ if (config.providerUrl && config.providerUrl.includes('natureco.me')) {
781
+ try {
782
+ const res = await fetch('https://api.natureco.me/api/v1/bots', {
783
+ headers: {
784
+ 'Authorization': `Bearer ${config.providerApiKey || apiKey}`,
785
+ 'Content-Type': 'application/json',
786
+ },
787
+ });
788
+ if (res.ok) {
789
+ const data = await res.json();
790
+ const bots = Array.isArray(data) ? data : (data.bots || data.data || []);
791
+ if (bots.length > 0) {
792
+ return {
793
+ bots: bots.map(b => ({
794
+ id: b.id,
795
+ name: b.name,
796
+ ai_provider: b.ai_provider || 'natureco',
797
+ model: b.model || 'natureco-default',
798
+ system_prompt: b.system_prompt || '',
799
+ }))
800
+ };
801
+ }
802
+ }
803
+ } catch (e) {
804
+ debugLog('[getBots] NatureCo API error:', e.message);
805
+ }
806
+ // Fallback — API'den bot gelmezse universal provider döndür
807
+ return {
808
+ bots: [{
809
+ id: 'universal-provider',
810
+ name: 'Universal Provider (NatureCo)',
811
+ ai_provider: 'natureco',
812
+ model: 'natureco-default',
813
+ }]
814
+ };
815
+ }
816
+
817
+ // Diğer provider'lar — universal provider döndür
776
818
  const providerName = providerConfig?.isAnthropic ? 'Anthropic' : 'OpenAI-compatible';
777
-
778
819
  return {
779
820
  bots: [
780
821
  {