@noelclaw/mcp 2.2.1 → 2.2.2
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/dist/llm.js +21 -5
- package/package.json +1 -1
package/dist/llm.js
CHANGED
|
@@ -3,11 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.callLLM = callLLM;
|
|
4
4
|
const ANTHROPIC_URL = "https://api.anthropic.com/v1/messages";
|
|
5
5
|
const BANKR_URL = "https://llm.bankr.bot/v1/chat/completions";
|
|
6
|
+
const CONVEX_SITE = process.env.NOELCLAW_CONVEX_URL ?? "https://api.noelclaw.com";
|
|
6
7
|
/**
|
|
7
8
|
* Call the best available LLM.
|
|
8
|
-
* Priority: ANTHROPIC_API_KEY → BANKR_API_KEY →
|
|
9
|
-
* Claude Desktop automatically injects ANTHROPIC_API_KEY, so users
|
|
10
|
-
* pay for their own AI usage without the server owner absorbing the cost.
|
|
9
|
+
* Priority: ANTHROPIC_API_KEY → BANKR_API_KEY → Convex backend (owner pays)
|
|
11
10
|
*/
|
|
12
11
|
async function callLLM(systemPrompt, userPrompt, maxTokens = 1024, history = [], timeoutMs = 60000) {
|
|
13
12
|
const anthropicKey = process.env.ANTHROPIC_API_KEY;
|
|
@@ -16,8 +15,25 @@ async function callLLM(systemPrompt, userPrompt, maxTokens = 1024, history = [],
|
|
|
16
15
|
return callAnthropic(anthropicKey, systemPrompt, userPrompt, maxTokens, history, timeoutMs);
|
|
17
16
|
if (bankrKey)
|
|
18
17
|
return callBankr(bankrKey, systemPrompt, userPrompt, maxTokens, history, timeoutMs);
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
// Fallback: route through Convex backend — owner covers cost
|
|
19
|
+
return callViaConvex(systemPrompt, userPrompt, history, timeoutMs);
|
|
20
|
+
}
|
|
21
|
+
async function callViaConvex(systemPrompt, userPrompt, history, timeoutMs) {
|
|
22
|
+
const fullQuestion = systemPrompt
|
|
23
|
+
? `[System: ${systemPrompt}]\n\n${userPrompt}`
|
|
24
|
+
: userPrompt;
|
|
25
|
+
const res = await fetch(`${CONVEX_SITE}/mcp/chat`, {
|
|
26
|
+
method: "POST",
|
|
27
|
+
headers: { "Content-Type": "application/json" },
|
|
28
|
+
body: JSON.stringify({ question: fullQuestion, messages: history }),
|
|
29
|
+
signal: AbortSignal.timeout(timeoutMs),
|
|
30
|
+
});
|
|
31
|
+
if (!res.ok) {
|
|
32
|
+
const body = await res.text().catch(() => "");
|
|
33
|
+
throw new Error(`LLM error ${res.status}: ${body.slice(0, 200)}`);
|
|
34
|
+
}
|
|
35
|
+
const data = await res.json();
|
|
36
|
+
return data.answer ?? "";
|
|
21
37
|
}
|
|
22
38
|
async function callAnthropic(apiKey, systemPrompt, userPrompt, maxTokens, history, timeoutMs) {
|
|
23
39
|
const messages = [...history, { role: "user", content: userPrompt }];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@noelclaw/mcp",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.2",
|
|
4
4
|
"description": "Noelclaw as an MCP skill — persistent memory, multi-agent coordination, scenario simulation, DeFi execution, and Sentinel-gated playbooks.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"bin": {
|