natureco-cli 2.23.10 → 2.23.11

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/utils/api.js +6 -60
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "natureco-cli",
3
- "version": "2.23.10",
3
+ "version": "2.23.11",
4
4
  "description": "NatureCo AI Bot Terminal Interface",
5
5
  "bin": {
6
6
  "natureco": "bin/natureco.js"
package/src/utils/api.js CHANGED
@@ -18,9 +18,6 @@ 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
-
24
21
  /**
25
22
  * Generate default conversation ID based on provider config
26
23
  */
@@ -427,60 +424,14 @@ function formatToolsForAnthropic() {
427
424
  }));
428
425
  }
429
426
 
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
-
475
427
  /**
476
428
  * Send message to OpenAI-compatible provider (Groq, OpenAI, Together, etc.)
477
429
  */
478
430
  async function sendMessageOpenAICompatible(providerConfig, messages, tools) {
479
- if (providerConfig.url.includes('api.natureco.me')) {
480
- return sendMessageNatureCo(providerConfig, messages, tools);
481
- }
482
431
  const baseUrl = providerConfig.url.replace(/\/+$/, '');
483
- const endpoint = `${baseUrl}/chat/completions`;
432
+ const endpoint = baseUrl.includes('api.natureco.me')
433
+ ? 'https://api.natureco.me/api/v1/chat/completions'
434
+ : `${baseUrl}/chat/completions`;
484
435
 
485
436
  const requestBody = {
486
437
  model: providerConfig.model,
@@ -920,15 +871,10 @@ async function streamProviderCompletion(providerConfig, messages, tools) {
920
871
  }
921
872
 
922
873
  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
- }
930
874
  const baseUrl = providerConfig.url.replace(/\/+$/, '');
931
- const endpoint = `${baseUrl}/chat/completions`;
875
+ const endpoint = baseUrl.includes('api.natureco.me')
876
+ ? 'https://api.natureco.me/api/v1/chat/completions'
877
+ : `${baseUrl}/chat/completions`;
932
878
 
933
879
  const requestBody = {
934
880
  model: providerConfig.model,