navada-edge-cli 2.2.2 → 2.3.0

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 (3) hide show
  1. package/lib/agent.js +66 -11
  2. package/lib/cli.js +4 -5
  3. package/package.json +1 -1
package/lib/agent.js CHANGED
@@ -95,7 +95,53 @@ const localTools = {
95
95
  };
96
96
 
97
97
  // ---------------------------------------------------------------------------
98
- // Anthropic Claude API conversational agent
98
+ // Grok (xAI)free tier for all users (30 RPM, 40K TPM)
99
+ // ---------------------------------------------------------------------------
100
+ const GROK_KEY = 'xai-NEmiT3HGX6OoNZ2Xwj5RJtzy1U2AgcDxGrebJbp7dNFCdk9dSF1kEpaoaL6CygcsFYGR3tQuWyhGJAg1';
101
+ const GROK_MODEL = 'grok-3-mini-fast';
102
+
103
+ async function callGrok(messages) {
104
+ const r = await navada.request('https://api.x.ai/v1/chat/completions', {
105
+ method: 'POST',
106
+ body: {
107
+ model: GROK_MODEL,
108
+ messages: [
109
+ { role: 'system', content: IDENTITY.personality },
110
+ ...messages,
111
+ ],
112
+ max_tokens: 2048,
113
+ temperature: 0.7,
114
+ },
115
+ headers: {
116
+ 'Authorization': `Bearer ${GROK_KEY}`,
117
+ 'Content-Type': 'application/json',
118
+ },
119
+ timeout: 30000,
120
+ });
121
+
122
+ if (r.status === 429) {
123
+ return {
124
+ content: `You've hit the free tier rate limit (30 requests/min).
125
+
126
+ To continue chatting, add your own API key:
127
+ /login sk-ant-your-anthropic-key (full agent with tool use)
128
+ /login sk-your-openai-key (GPT-4o)
129
+ /init hfToken hf_your_token (Qwen Coder — FREE unlimited)
130
+
131
+ Or wait a minute and try again.`,
132
+ isRateLimit: true,
133
+ };
134
+ }
135
+
136
+ if (r.status !== 200) {
137
+ throw new Error(`Grok API error ${r.status}: ${JSON.stringify(r.data).slice(0, 200)}`);
138
+ }
139
+
140
+ return { content: r.data?.choices?.[0]?.message?.content || '', isRateLimit: false };
141
+ }
142
+
143
+ // ---------------------------------------------------------------------------
144
+ // Anthropic Claude API — conversational agent with tool use
99
145
  // ---------------------------------------------------------------------------
100
146
  async function chat(userMessage, conversationHistory = []) {
101
147
  // Smart key detection — check all possible locations
@@ -110,8 +156,9 @@ async function chat(userMessage, conversationHistory = []) {
110
156
  || (apiKey && apiKey.startsWith('sk-ant') ? apiKey : '')
111
157
  || '';
112
158
 
159
+ // No personal key — use Grok free tier
113
160
  if (!effectiveKey) {
114
- return fallbackChat(userMessage);
161
+ return grokChat(userMessage, conversationHistory);
115
162
  }
116
163
 
117
164
  const tools = [
@@ -273,8 +320,18 @@ async function executeTool(name, input) {
273
320
  }
274
321
  }
275
322
 
323
+ async function grokChat(userMessage, conversationHistory = []) {
324
+ const messages = [
325
+ ...conversationHistory.slice(-20),
326
+ { role: 'user', content: userMessage },
327
+ ];
328
+
329
+ const result = await callGrok(messages);
330
+ return result.content;
331
+ }
332
+
276
333
  async function fallbackChat(msg) {
277
- // Try MCP → Qwen → OpenAI → helpful error
334
+ // Try MCP → Qwen → OpenAI → Grok free tier
278
335
  if (navada.config.mcp) {
279
336
  try {
280
337
  const r = await navada.mcp.call('chat', { message: msg });
@@ -290,14 +347,12 @@ async function fallbackChat(msg) {
290
347
  if (navada.config.openaiKey) {
291
348
  try { return await navada.ai.openai.chat(msg); } catch {}
292
349
  }
293
- return `I need an API key to chat. Quick fix:
294
-
295
- /login sk-ant-your-anthropic-key (recommended enables full agent with tool use)
296
- /login sk-your-openai-key (GPT-4o)
297
- /init hfToken hf_your_token (Qwen Coder — FREE)
298
- /setup (guided wizard)
299
-
300
- /commands still work without a key — try /help`;
350
+ // Grok is always available as the free fallback
351
+ try {
352
+ const result = await callGrok([{ role: 'user', content: msg }]);
353
+ return result.content;
354
+ } catch {}
355
+ return `All providers failed. Check your internet connection or try again.`;
301
356
  }
302
357
 
303
358
  // ---------------------------------------------------------------------------
package/lib/cli.js CHANGED
@@ -92,11 +92,10 @@ async function run(argv) {
92
92
  // Interactive mode — always start. User can /setup if needed.
93
93
  showWelcome();
94
94
 
95
- // Hint if no key configured
96
- const hasKey = config.getApiKey() || config.get('anthropicKey') || process.env.ANTHROPIC_API_KEY;
97
- if (!hasKey) {
98
- console.log(ui.warn('No API key set. Type /login <key> or /setup to configure.'));
99
- console.log(ui.dim('You can still use /commands. Natural chat requires an API key.'));
95
+ // Show tier info
96
+ const hasPersonalKey = config.getApiKey() || config.get('anthropicKey') || process.env.ANTHROPIC_API_KEY;
97
+ if (!hasPersonalKey) {
98
+ console.log(ui.dim('Free tier active (Grok). /login <your-key> for full agent with tool use.'));
100
99
  console.log('');
101
100
  }
102
101
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "navada-edge-cli",
3
- "version": "2.2.2",
3
+ "version": "2.3.0",
4
4
  "description": "Interactive CLI for the NAVADA Edge Network — explore nodes, agents, Cloudflare, AI, Docker, and MCP from your terminal",
5
5
  "main": "lib/cli.js",
6
6
  "bin": {