@caravo/mcp 0.1.0 → 0.1.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.
- package/dist/index.js +15 -5
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -20,8 +20,9 @@ import { z } from "zod";
|
|
|
20
20
|
import { loadOrCreateWallet } from "./wallet.js";
|
|
21
21
|
import { fetchWithX402 } from "./x402.js";
|
|
22
22
|
const API_BASE = process.env.CARAVO_URL ?? "https://caravo.ai";
|
|
23
|
-
// Optional API key: if
|
|
24
|
-
const
|
|
23
|
+
// Optional API key: if it looks like a real key (am_ prefix), uses balance auth; otherwise x402
|
|
24
|
+
const RAW_KEY = process.env.CARAVO_API_KEY;
|
|
25
|
+
const API_KEY = RAW_KEY && RAW_KEY.startsWith("am_") ? RAW_KEY : undefined;
|
|
25
26
|
const wallet = loadOrCreateWallet();
|
|
26
27
|
process.stderr.write(`[caravo] wallet: ${wallet.address}\n`);
|
|
27
28
|
process.stderr.write(API_KEY
|
|
@@ -45,9 +46,18 @@ async function apiPost(path, body) {
|
|
|
45
46
|
headers: baseHeaders(),
|
|
46
47
|
body: JSON.stringify(body),
|
|
47
48
|
};
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
49
|
+
if (!API_KEY)
|
|
50
|
+
return (await fetchWithX402(url, opts, wallet)).json();
|
|
51
|
+
const r = await fetch(url, opts);
|
|
52
|
+
if (r.status === 401 || r.status === 403) {
|
|
53
|
+
process.stderr.write("[caravo] API key auth failed, falling back to x402\n");
|
|
54
|
+
const x402Opts = {
|
|
55
|
+
method: "POST",
|
|
56
|
+
headers: { "Content-Type": "application/json" },
|
|
57
|
+
body: JSON.stringify(body),
|
|
58
|
+
};
|
|
59
|
+
return (await fetchWithX402(url, x402Opts, wallet)).json();
|
|
60
|
+
}
|
|
51
61
|
return r.json();
|
|
52
62
|
}
|
|
53
63
|
async function apiDelete(path, body) {
|