natureco-cli 5.20.0 → 5.20.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "natureco-cli",
3
- "version": "5.20.0",
3
+ "version": "5.20.1",
4
4
  "description": "OpenClaw'dan daha güvenli, daha hızlı, daha ucuz AI agent CLI. Multi-agent, self-evolving skills, audit log, maliyet optimizasyonu ve NatureCo platform-native.",
5
5
  "bin": {
6
6
  "natureco": "bin/natureco.js"
@@ -98,7 +98,9 @@ function help() {
98
98
  icon: '🌿',
99
99
  title: 'NatureCo Native',
100
100
  rows: [
101
- { name: 'natureco naturehub post "<text>"', desc: 'Nature Hub\'a içerik yayınla' },
101
+ { name: 'natureco naturehub post "<text>"', desc: 'NatureCo API ile bota mesaj gönder' },
102
+ { name: 'natureco naturehub list', desc: 'Botlarını listele' },
103
+ { name: 'natureco naturehub info [bot_id]', desc: 'Bot detayı' },
102
104
  { name: 'natureco medium draft <file.md>', desc: 'Medium makale taslağı' },
103
105
  { name: 'natureco medium publish <file.md>', desc: 'Medium\'da yayınla' },
104
106
  { name: 'natureco seo audit <url>', desc: 'SEO denetimi (skor 0-100)' },
@@ -1,14 +1,14 @@
1
1
  /**
2
- * natureco naturehub — Nature Hub'a içerik yayınlama (Phase 6)
2
+ * natureco naturehub — NatureCo Bot API iletişimi
3
3
  *
4
- * natureco.me'nin topluluk akışına CLI'dan içerik gönder.
4
+ * natureco.me/api/v1/bots endpoint'lerini kullanır.
5
5
  * Kullanım:
6
- * natureco naturehub post <text> Yeni gönderi
7
- * natureco naturehub list Son gönderiler
8
- * natureco naturehub trending Trend olan konular
9
- * natureco naturehub config Ayarları göster
6
+ * natureco naturehub post <text> Bota mesaj gönder
7
+ * natureco naturehub list Botları listele
8
+ * natureco naturehub info [bot_id] Bot detayı
9
+ * natureco naturehub config Ayarları göster
10
10
  *
11
- * API endpoint: api.natureco.me/naturehub/* (placeholder)
11
+ * API: https://natureco.me/api/v1/bots
12
12
  */
13
13
 
14
14
  const chalk = require('chalk');
@@ -17,20 +17,35 @@ const { URL } = require('url');
17
17
  const audit = require('../utils/audit');
18
18
 
19
19
  const API_BASE = 'https://api.natureco.me';
20
+ const API_PREFIX = '/api/v1';
20
21
  const CONFIG_KEY = 'naturehub';
21
22
 
23
+ function getApiKey() {
24
+ try {
25
+ const { getConfig } = require('../utils/config');
26
+ const cfg = getConfig();
27
+ return cfg?.apiKey || null;
28
+ } catch { return null; }
29
+ }
30
+
31
+ function getBotId() {
32
+ try {
33
+ const { getConfig } = require('../utils/config');
34
+ const cfg = getConfig();
35
+ return cfg?.naturecoBotId || null;
36
+ } catch { return null; }
37
+ }
38
+
22
39
  async function apiCall(path, options = {}) {
23
- // Geliştirme aşamasında placeholder — gerçek API hazır olunca kullanılacak
24
- // Şimdilik simüle edelim ve kullanıcıya rehberlik edelim
25
40
  return new Promise((resolve, reject) => {
26
- const url = new URL(path, API_BASE);
41
+ const url = new URL(API_PREFIX + path, API_BASE);
27
42
  const reqOptions = {
28
43
  hostname: url.hostname,
29
44
  path: url.pathname + url.search,
30
45
  method: options.method || 'GET',
31
46
  headers: {
32
47
  'Content-Type': 'application/json',
33
- 'User-Agent': 'natureco-cli/3.5',
48
+ 'User-Agent': 'natureco-cli/5.20',
34
49
  ...(options.token ? { 'Authorization': `Bearer ${options.token}` } : {}),
35
50
  ...options.headers,
36
51
  },
@@ -54,51 +69,43 @@ async function apiCall(path, options = {}) {
54
69
  });
55
70
  }
56
71
 
57
- async function getToken() {
58
- const { getConfig } = require('../utils/config');
59
- const cfg = getConfig();
60
- return cfg?.naturehubToken || cfg?.apiKey || null;
61
- }
62
-
63
72
  async function cmdPost(args) {
64
73
  const text = args.join(' ').trim();
65
74
  if (!text) {
66
75
  console.log(chalk.red('\n Kullanım: natureco naturehub post "<mesaj>"\n'));
67
76
  return;
68
77
  }
69
- if (text.length > 500) {
70
- console.log(chalk.yellow('\n ⚠️ Mesaj 500 karakteri aşıyor. Kısaltılacak.\n'));
71
- }
72
- const shortText = text.slice(0, 500);
73
-
74
- console.log(chalk.cyan('\n 📤 Nature Hub\'a gönderiliyor...\n'));
75
- console.log(chalk.gray(` "${shortText}"\n`));
76
78
 
77
- const token = await getToken();
79
+ const token = getApiKey();
78
80
  if (!token) {
79
- console.log(chalk.yellow(' ⚠️ Nature Hub token tanımlı değil.\n'));
80
- console.log(chalk.gray(' Ayarlamak için: ') + chalk.cyan('natureco config set naturehubToken <token>'));
81
- console.log(chalk.gray(' Veya genel API key: ') + chalk.cyan('natureco login'));
82
- console.log('');
83
- console.log(chalk.gray(' Şimdilik yerel olarak kaydedildi.\n'));
84
- saveLocal(shortText);
85
- audit.log(audit.ACTIONS.INFO, { source: 'naturehub', action: 'post', local: true });
81
+ console.log(chalk.yellow('\n ⚠️ API key tanımlı değil. Önce `natureco login` ile giriş yapın.\n'));
82
+ saveLocal(text);
86
83
  return;
87
84
  }
88
85
 
86
+ const botId = getBotId();
87
+ if (!botId) {
88
+ console.log(chalk.yellow('\n ⚠️ Bot ID tanımlı değil. `natureco naturehub list` ile botlarınızı görün.\n'));
89
+ console.log(chalk.gray(' Ayarlamak için: natureco config set naturecoBotId <bot_id>\n'));
90
+ saveLocal(text);
91
+ return;
92
+ }
93
+
94
+ console.log(chalk.cyan(`\n 📤 Bota mesaj gönderiliyor (${botId})...\n`));
95
+ console.log(chalk.gray(` "${text.slice(0, 200)}"\n`));
96
+
89
97
  try {
90
- const result = await apiCall('/naturehub/posts', {
98
+ const result = await apiCall(`/bots/${botId}/messages`, {
91
99
  method: 'POST',
92
100
  token,
93
- body: { text: shortText, source: 'cli' },
101
+ body: { message: text, user_id: 'cli' },
94
102
  });
95
103
  console.log(chalk.green(' ✓ Gönderildi!\n'));
96
- if (result.url) console.log(chalk.cyan(` 🔗 ${result.url}\n`));
97
- audit.log(audit.ACTIONS.INFO, { source: 'naturehub', action: 'post', url: result.url });
104
+ if (result.reply) console.log(chalk.cyan(` 💬 Bot: ${result.reply}\n`));
105
+ audit.log(audit.ACTIONS.INFO, { source: 'naturehub', action: 'post', botId });
98
106
  } catch (e) {
99
- console.log(chalk.yellow(` ⚠️ API henüz hazır değil: ${e.message}`));
100
- console.log(chalk.gray(' Yerel olarak kaydedildi.\n'));
101
- saveLocal(shortText);
107
+ console.log(chalk.red(` Hata: ${e.message}\n`));
108
+ saveLocal(text);
102
109
  }
103
110
  }
104
111
 
@@ -114,24 +121,67 @@ function saveLocal(text) {
114
121
  }
115
122
 
116
123
  async function cmdList() {
117
- console.log(chalk.cyan('\n 🌍 Nature Hub — Son Gönderiler\n'));
118
- console.log(chalk.gray(' ' + '─'.repeat(50)));
119
- console.log(chalk.gray('\n Bu özellik api.natureco.me hazır olunca tam çalışacak.\n'));
120
- console.log(chalk.gray(' Şimdilik tarayıcıdan ziyaret edin: ') + chalk.cyan('https://natureco.me/hub\n'));
124
+ const token = getApiKey();
125
+ if (!token) {
126
+ console.log(chalk.yellow('\n ⚠️ API key tanımlı değil.\n'));
127
+ return;
128
+ }
129
+
130
+ console.log(chalk.cyan('\n 🤖 Botlarınız\n'));
131
+
132
+ try {
133
+ const result = await apiCall('/bots', { method: 'GET', token });
134
+ const bots = Array.isArray(result) ? result : (result.bots || result.data || []);
135
+ if (bots.length === 0) {
136
+ console.log(chalk.gray(' Henüz botunuz yok.\n'));
137
+ return;
138
+ }
139
+ for (const b of bots) {
140
+ console.log(` ${chalk.cyan('●')} ${b.name || b.id} ${chalk.gray(`(${b.id})`)}`);
141
+ if (b.description) console.log(` ${chalk.gray(b.description)}`);
142
+ console.log('');
143
+ }
144
+ console.log(chalk.gray(' Bot ID ayarlamak için: natureco config set naturecoBotId <id>\n'));
145
+ } catch (e) {
146
+ console.log(chalk.red(` ✗ Hata: ${e.message}\n`));
147
+ }
121
148
  }
122
149
 
123
- async function cmdTrending() {
124
- console.log(chalk.cyan('\n 🔥 Trend Konular\n'));
125
- console.log(chalk.gray(' ' + '─'.repeat(50)));
126
- console.log(chalk.gray('\n Bu özellik api.natureco.me hazır olunca tam çalışacak.\n'));
150
+ async function cmdInfo(botId) {
151
+ const token = getApiKey();
152
+ if (!token) {
153
+ console.log(chalk.yellow('\n ⚠️ API key tanımlı değil.\n'));
154
+ return;
155
+ }
156
+
157
+ const id = botId || getBotId();
158
+ if (!id) {
159
+ console.log(chalk.yellow('\n Bot ID gerekli: natureco naturehub info <bot_id>\n'));
160
+ return;
161
+ }
162
+
163
+ console.log(chalk.cyan(`\n 🤖 Bot: ${id}\n`));
164
+ try {
165
+ const result = await apiCall(`/bots/${id}`, { method: 'GET', token });
166
+ console.log(` ${chalk.bold('ID:')} ${result.id}`);
167
+ console.log(` ${chalk.bold('İsim:')} ${result.name || '-'}`);
168
+ console.log(` ${chalk.bold('Açıklama:')} ${result.description || '-'}`);
169
+ console.log(` ${chalk.bold('Durum:')} ${result.status || 'active'}`);
170
+ console.log('');
171
+ } catch (e) {
172
+ console.log(chalk.red(` ✗ Hata: ${e.message}\n`));
173
+ }
127
174
  }
128
175
 
129
176
  async function cmdConfig() {
130
177
  const { getConfig } = require('../utils/config');
131
178
  const cfg = getConfig();
132
- console.log(chalk.cyan('\n ⚙️ Nature Hub Ayarları\n'));
133
- console.log(chalk.gray(' Token: ') + (cfg.naturehubToken ? chalk.green('✓ ayarlı') : chalk.yellow('yok')));
134
- console.log(chalk.gray('\n Ayarlamak için: ') + chalk.cyan('natureco config set naturehubToken <token>'));
179
+ console.log(chalk.cyan('\n ⚙️ NatureCo API Ayarları\n'));
180
+ console.log(chalk.gray(' API Key: ') + (cfg.apiKey ? chalk.green('✓ ayarlı') : chalk.yellow('yok')));
181
+ console.log(chalk.gray(' Bot ID: ') + (cfg.naturecoBotId ? chalk.green(cfg.naturecoBotId) : chalk.yellow('ayarlanmamış')));
182
+ console.log(chalk.gray('\n Giriş: ') + chalk.cyan('natureco login'));
183
+ console.log(chalk.gray(' Bot ID: ') + chalk.cyan('natureco config set naturecoBotId <id>'));
184
+ console.log(chalk.gray(' Botlar: ') + chalk.cyan('natureco naturehub list'));
135
185
  console.log('');
136
186
  }
137
187
 
@@ -139,16 +189,16 @@ async function naturehub(args) {
139
189
  const [action, ...params] = args || [];
140
190
  if (!action || action === 'help') {
141
191
  console.log(chalk.yellow('\n Kullanım:'));
142
- console.log(chalk.gray(' natureco naturehub post <text> Yeni gönderi'));
143
- console.log(chalk.gray(' natureco naturehub list Son gönderiler'));
144
- console.log(chalk.gray(' natureco naturehub trending Trend konular'));
145
- console.log(chalk.gray(' natureco naturehub config Ayarlar'));
192
+ console.log(chalk.gray(' natureco naturehub post "<mesaj>" Bota mesaj gönder'));
193
+ console.log(chalk.gray(' natureco naturehub list Botları listele'));
194
+ console.log(chalk.gray(' natureco naturehub info [bot_id] Bot detayı'));
195
+ console.log(chalk.gray(' natureco naturehub config Ayarlar'));
146
196
  console.log('');
147
197
  return;
148
198
  }
149
199
  if (action === 'post') return cmdPost(params);
150
200
  if (action === 'list') return cmdList();
151
- if (action === 'trending') return cmdTrending();
201
+ if (action === 'info') return cmdInfo(params[0]);
152
202
  if (action === 'config') return cmdConfig();
153
203
  console.log(chalk.red(`\n Bilinmeyen action: ${action}\n`));
154
204
  }
@@ -118,7 +118,7 @@ const CLI_COMMANDS = {
118
118
  '/models': { desc: 'Modeller', run: ['models', 'list'] },
119
119
  '/memory-ls': { desc: 'Memory dosyaları', run: ['memory', 'list'] },
120
120
  '/seo': { desc: 'SEO denetimi (URL gerek)', needsArg: true, run: ['seo', 'audit'] },
121
- '/naturehub': { desc: 'Nature Hub post (text gerek)', needsArg: true, run: ['naturehub', 'post'] },
121
+ '/naturehub': { desc: 'Bota mesaj gönder (text gerek)', needsArg: true, run: ['naturehub', 'post'] },
122
122
  '/dashboard': { desc: 'Web dashboard başlat (port 7421)', run: ['dashboard', 'start'] },
123
123
  };
124
124
 
@@ -177,7 +177,12 @@ async function workflow(params) {
177
177
  plan = JSON.parse(jsonStr);
178
178
  if (!plan.steps || !Array.isArray(plan.steps)) throw new Error('Steps bulunamadi');
179
179
  } catch (e) {
180
- return { success: false, error: 'Plan cozumlenemedi: ' + e.message, raw: planResult.choices?.[0]?.message?.content?.slice(0, 500) };
180
+ // JSON parse hatasi modelin ham ciktisini passthrough chat olarak goster
181
+ const rawReply = planResult.choices?.[0]?.message?.content || '';
182
+ if (rawReply) {
183
+ return { success: true, workflowId: 'passthrough', name: 'Direct Chat', status: 'completed', totalSteps: 0, completedSteps: 0, results: [{ step: 0, tool: 'chat', status: 'done', result: { reply: rawReply } }], passthrough: true, reply: rawReply };
184
+ }
185
+ return { success: false, error: 'Plan cozumlenemedi: ' + e.message, raw: rawReply.slice(0, 500) };
181
186
  }
182
187
 
183
188
  // Save plan