navada-edge-cli 2.3.0 → 2.4.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.
Files changed (2) hide show
  1. package/lib/agent.js +38 -36
  2. package/package.json +1 -1
package/lib/agent.js CHANGED
@@ -95,49 +95,48 @@ const localTools = {
95
95
  };
96
96
 
97
97
  // ---------------------------------------------------------------------------
98
- // Grok (xAI)free tier for all users (30 RPM, 40K TPM)
98
+ // Free tierproxied through NAVADA Edge Dashboard (key stays on ASUS)
99
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
- });
100
+ // Dashboard proxy endpoints — tries Cloudflare tunnel first (works for everyone),
101
+ // then falls back to direct Tailscale IP (faster but only works on VPN)
102
+ const FREE_TIER_ENDPOINTS = [
103
+ 'https://api.navada-edge-server.uk/api/v1/chat', // Cloudflare tunnel (public, works for all)
104
+ 'http://100.88.118.128:7900/api/v1/chat', // Direct Tailscale (VPN users only)
105
+ ];
106
+
107
+ async function callFreeTier(messages) {
108
+ // Try each endpoint (public first, then Tailscale)
109
+ for (const endpoint of FREE_TIER_ENDPOINTS) {
110
+ try {
111
+ const r = await navada.request(endpoint, {
112
+ method: 'POST',
113
+ body: { messages },
114
+ timeout: endpoint.includes('navada-edge-server.uk') ? 30000 : 5000,
115
+ });
121
116
 
122
- if (r.status === 429) {
123
- return {
124
- content: `You've hit the free tier rate limit (30 requests/min).
117
+ if (r.status === 429) {
118
+ return {
119
+ content: `Free tier limit reached (30 requests/min).
125
120
 
126
- To continue chatting, add your own API key:
121
+ To continue, add your own API key:
127
122
  /login sk-ant-your-anthropic-key (full agent with tool use)
128
123
  /login sk-your-openai-key (GPT-4o)
129
124
  /init hfToken hf_your_token (Qwen Coder — FREE unlimited)
130
125
 
131
126
  Or wait a minute and try again.`,
132
- isRateLimit: true,
133
- };
134
- }
127
+ isRateLimit: true,
128
+ };
129
+ }
135
130
 
136
- if (r.status !== 200) {
137
- throw new Error(`Grok API error ${r.status}: ${JSON.stringify(r.data).slice(0, 200)}`);
131
+ if (r.status === 200) {
132
+ return { content: r.data?.choices?.[0]?.message?.content || '', isRateLimit: false };
133
+ }
134
+ } catch {
135
+ continue; // Try next endpoint
136
+ }
138
137
  }
139
138
 
140
- return { content: r.data?.choices?.[0]?.message?.content || '', isRateLimit: false };
139
+ throw new Error('Free tier unavailable. Add your own key: /login <key>');
141
140
  }
142
141
 
143
142
  // ---------------------------------------------------------------------------
@@ -322,12 +321,15 @@ async function executeTool(name, input) {
322
321
 
323
322
  async function grokChat(userMessage, conversationHistory = []) {
324
323
  const messages = [
325
- ...conversationHistory.slice(-20),
324
+ ...conversationHistory.slice(-20).map(m => ({
325
+ role: m.role,
326
+ content: typeof m.content === 'string' ? m.content : JSON.stringify(m.content),
327
+ })),
326
328
  { role: 'user', content: userMessage },
327
329
  ];
328
330
 
329
- const result = await callGrok(messages);
330
- return result.content;
331
+ const result = await callFreeTier(messages);
332
+ return result.content || 'No response from free tier. Try /login <key> for full agent.';
331
333
  }
332
334
 
333
335
  async function fallbackChat(msg) {
@@ -349,7 +351,7 @@ async function fallbackChat(msg) {
349
351
  }
350
352
  // Grok is always available as the free fallback
351
353
  try {
352
- const result = await callGrok([{ role: 'user', content: msg }]);
354
+ const result = await callFreeTier([{ role: 'user', content: msg }]);
353
355
  return result.content;
354
356
  } catch {}
355
357
  return `All providers failed. Check your internet connection or try again.`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "navada-edge-cli",
3
- "version": "2.3.0",
3
+ "version": "2.4.1",
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": {