navada-edge-cli 2.3.0 → 2.4.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.
- package/lib/agent.js +38 -36
- package/package.json +1 -1
package/lib/agent.js
CHANGED
|
@@ -95,49 +95,48 @@ const localTools = {
|
|
|
95
95
|
};
|
|
96
96
|
|
|
97
97
|
// ---------------------------------------------------------------------------
|
|
98
|
-
//
|
|
98
|
+
// Free tier — proxied through NAVADA Edge Dashboard (key stays on ASUS)
|
|
99
99
|
// ---------------------------------------------------------------------------
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
'Authorization': `Bearer ${GROK_KEY}`,
|
|
117
|
-
'Content-Type': 'application/json',
|
|
118
|
-
},
|
|
119
|
-
timeout: 30000,
|
|
120
|
-
});
|
|
100
|
+
// Dashboard proxy endpoints — tries Cloudflare tunnel first, then direct
|
|
101
|
+
// Users on Tailscale hit the direct IP; public users hit the tunnel
|
|
102
|
+
const FREE_TIER_ENDPOINTS = [
|
|
103
|
+
'http://100.88.118.128:7900/api/v1/chat', // Direct (fastest for Tailscale users)
|
|
104
|
+
'https://api.navada-edge-server.uk/api/v1/chat', // Cloudflare tunnel (public fallback)
|
|
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: 30000,
|
|
115
|
+
});
|
|
121
116
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
117
|
+
if (r.status === 429) {
|
|
118
|
+
return {
|
|
119
|
+
content: `Free tier limit reached (30 requests/min).
|
|
125
120
|
|
|
126
|
-
To continue
|
|
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
|
-
|
|
133
|
-
|
|
134
|
-
|
|
127
|
+
isRateLimit: true,
|
|
128
|
+
};
|
|
129
|
+
}
|
|
135
130
|
|
|
136
|
-
|
|
137
|
-
|
|
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
|
-
|
|
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
|
|
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
|
|
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