natureco-cli 2.23.8 → 2.23.10

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.23.8",
3
+ "version": "2.23.10",
4
4
  "description": "NatureCo AI Bot Terminal Interface",
5
5
  "bin": {
6
6
  "natureco": "bin/natureco.js"
@@ -130,7 +130,7 @@ const LANG = {
130
130
  const NATURECO_PROVIDER = {
131
131
  name: 'NatureCo (natureco.me — kendi platformun)',
132
132
  value: 'natureco',
133
- url: 'https://api.natureco.me/v1',
133
+ url: 'https://api.natureco.me',
134
134
  };
135
135
 
136
136
  const PROVIDER_PRESETS = (customLabel) => [
package/src/utils/api.js CHANGED
@@ -18,6 +18,9 @@ const conversationHistory = new Map();
18
18
  // MCP clients (server name -> { client, tools })
19
19
  const mcpClients = {};
20
20
 
21
+ // Cache for NatureCo user_id
22
+ let _cachedUserId = null;
23
+
21
24
  /**
22
25
  * Generate default conversation ID based on provider config
23
26
  */
@@ -424,14 +427,60 @@ function formatToolsForAnthropic() {
424
427
  }));
425
428
  }
426
429
 
430
+ /**
431
+ * Get NatureCo user_id (cached)
432
+ */
433
+ async function getNatureCoUserId(apiKey) {
434
+ if (_cachedUserId) return _cachedUserId;
435
+ const result = await validateApiKey(apiKey);
436
+ if (!result.valid || !result.user?.id) {
437
+ throw new Error('Failed to get user_id: ' + (result.error || 'invalid API key'));
438
+ }
439
+ _cachedUserId = result.user.id;
440
+ return _cachedUserId;
441
+ }
442
+
443
+ /**
444
+ * Send message to NatureCo /api/agent/message endpoint
445
+ */
446
+ async function sendMessageNatureCo(providerConfig, messages, tools) {
447
+ const lastUserMsg = [...messages].reverse().find(m => m.role === 'user');
448
+ if (!lastUserMsg) throw new Error('No user message found');
449
+
450
+ const userId = await getNatureCoUserId(providerConfig.apiKey);
451
+
452
+ const response = await fetch('https://api.natureco.me/api/agent/message', {
453
+ method: 'POST',
454
+ headers: {
455
+ 'Authorization': `Bearer ${providerConfig.apiKey}`,
456
+ 'Content-Type': 'application/json',
457
+ },
458
+ body: JSON.stringify({
459
+ message: lastUserMsg.content,
460
+ user_id: userId,
461
+ }),
462
+ });
463
+
464
+ if (!response.ok) {
465
+ throw new Error(`NatureCo API error: ${response.status} - ${await response.text()}`);
466
+ }
467
+
468
+ const data = await response.json();
469
+ return {
470
+ role: 'assistant',
471
+ content: data.response || '',
472
+ };
473
+ }
474
+
427
475
  /**
428
476
  * Send message to OpenAI-compatible provider (Groq, OpenAI, Together, etc.)
429
477
  */
430
478
  async function sendMessageOpenAICompatible(providerConfig, messages, tools) {
479
+ if (providerConfig.url.includes('api.natureco.me')) {
480
+ return sendMessageNatureCo(providerConfig, messages, tools);
481
+ }
431
482
  const baseUrl = providerConfig.url.replace(/\/+$/, '');
432
- const endpoint = baseUrl.includes('api.natureco.me')
433
- ? `${baseUrl}/api/v1/chat/completions`
434
- : `${baseUrl}/chat/completions`;
483
+ const endpoint = `${baseUrl}/chat/completions`;
435
484
 
436
485
  const requestBody = {
437
486
  model: providerConfig.model,
@@ -871,10 +920,15 @@ async function streamProviderCompletion(providerConfig, messages, tools) {
871
920
  }
872
921
 
873
922
  async function streamOpenAICompletion(providerConfig, messages, tools) {
923
+ // NatureCo endpoint doesn't support streaming — fall back to non-streaming
924
+ if (providerConfig.url.includes('api.natureco.me')) {
925
+ const msg = await sendMessageNatureCo(providerConfig, messages, tools);
926
+ process.stdout.write(msg.content);
927
+ process.stdout.write('\n');
928
+ return { type: 'text', content: msg.content };
929
+ }
874
930
  const baseUrl = providerConfig.url.replace(/\/+$/, '');
875
- const endpoint = baseUrl.includes('api.natureco.me')
876
- ? `${baseUrl}/api/v1/chat/completions`
877
- : `${baseUrl}/chat/completions`;
931
+ const endpoint = `${baseUrl}/chat/completions`;
878
932
 
879
933
  const requestBody = {
880
934
  model: providerConfig.model,