nous-token 0.3.0 → 0.3.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/cli/setup.ts +8 -8
- package/index.ts +13 -4
- package/package.json +1 -1
package/cli/setup.ts
CHANGED
|
@@ -24,8 +24,8 @@ function saveWallet(wallet: string): void {
|
|
|
24
24
|
writeFileSync(NOUS_CONFIG, wallet);
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
function gatewayUrl(
|
|
28
|
-
return wallet ? `${GATEWAY}
|
|
27
|
+
function gatewayUrl(provider: string, apiPath: string, wallet: string): string {
|
|
28
|
+
return wallet ? `${GATEWAY}/${provider}/w/${wallet}${apiPath}` : `${GATEWAY}/${provider}${apiPath}`;
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
interface Tool {
|
|
@@ -67,7 +67,7 @@ const tools: Tool[] = [
|
|
|
67
67
|
try { execSync("which claude", { stdio: "ignore" }); return true; } catch { return false; }
|
|
68
68
|
},
|
|
69
69
|
configure: (wallet: string) => {
|
|
70
|
-
return setShellEnv("ANTHROPIC_BASE_URL", gatewayUrl("
|
|
70
|
+
return setShellEnv("ANTHROPIC_BASE_URL", gatewayUrl("anthropic", "", wallet), "Claude Code");
|
|
71
71
|
},
|
|
72
72
|
},
|
|
73
73
|
|
|
@@ -94,7 +94,7 @@ const tools: Tool[] = [
|
|
|
94
94
|
if (content["openai.baseUrl"]?.includes("nousai")) {
|
|
95
95
|
return { success: true, message: "already configured" };
|
|
96
96
|
}
|
|
97
|
-
content["openai.baseUrl"] = gatewayUrl("
|
|
97
|
+
content["openai.baseUrl"] = gatewayUrl("openai", "/v1", wallet);
|
|
98
98
|
writeFileSync(sp, JSON.stringify(content, null, 2));
|
|
99
99
|
return { success: true, message: `set baseUrl in Cursor settings` };
|
|
100
100
|
} catch {
|
|
@@ -114,7 +114,7 @@ const tools: Tool[] = [
|
|
|
114
114
|
(() => { try { execSync("which codex", { stdio: "ignore" }); return true; } catch { return false; } })();
|
|
115
115
|
},
|
|
116
116
|
configure: (wallet: string) => {
|
|
117
|
-
return setShellEnv("OPENAI_BASE_URL", gatewayUrl("
|
|
117
|
+
return setShellEnv("OPENAI_BASE_URL", gatewayUrl("openai", "/v1", wallet), "Codex");
|
|
118
118
|
},
|
|
119
119
|
},
|
|
120
120
|
|
|
@@ -126,7 +126,7 @@ const tools: Tool[] = [
|
|
|
126
126
|
(() => { try { execSync("which gemini", { stdio: "ignore" }); return true; } catch { return false; } })();
|
|
127
127
|
},
|
|
128
128
|
configure: (wallet: string) => {
|
|
129
|
-
return setShellEnv("GOOGLE_GEMINI_BASE_URL", gatewayUrl("
|
|
129
|
+
return setShellEnv("GOOGLE_GEMINI_BASE_URL", gatewayUrl("gemini", "", wallet), "Gemini CLI");
|
|
130
130
|
},
|
|
131
131
|
},
|
|
132
132
|
|
|
@@ -137,7 +137,7 @@ const tools: Tool[] = [
|
|
|
137
137
|
try { execSync("python3 -c 'import openai'", { stdio: "ignore" }); return true; } catch { return false; }
|
|
138
138
|
},
|
|
139
139
|
configure: (wallet: string) => {
|
|
140
|
-
return setShellEnv("OPENAI_BASE_URL", gatewayUrl("
|
|
140
|
+
return setShellEnv("OPENAI_BASE_URL", gatewayUrl("openai", "/v1", wallet), "Python openai SDK");
|
|
141
141
|
},
|
|
142
142
|
},
|
|
143
143
|
|
|
@@ -148,7 +148,7 @@ const tools: Tool[] = [
|
|
|
148
148
|
try { execSync("python3 -c 'import anthropic'", { stdio: "ignore" }); return true; } catch { return false; }
|
|
149
149
|
},
|
|
150
150
|
configure: (wallet: string) => {
|
|
151
|
-
return setShellEnv("ANTHROPIC_BASE_URL", gatewayUrl("
|
|
151
|
+
return setShellEnv("ANTHROPIC_BASE_URL", gatewayUrl("anthropic", "", wallet), "Python anthropic SDK");
|
|
152
152
|
},
|
|
153
153
|
},
|
|
154
154
|
];
|
package/index.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import type { OpenClawPluginApi } from "openclaw/plugin-sdk";
|
|
2
|
+
import { readFileSync } from "fs";
|
|
3
|
+
import { homedir } from "os";
|
|
4
|
+
import { join } from "path";
|
|
2
5
|
|
|
3
6
|
// nous-token plugin: routes LLM calls through the nous-token gateway
|
|
4
7
|
// for real usage tracking on the global leaderboard.
|
|
@@ -12,6 +15,10 @@ import type { OpenClawPluginApi } from "openclaw/plugin-sdk";
|
|
|
12
15
|
|
|
13
16
|
const GATEWAY = "https://gateway.nousai.cc";
|
|
14
17
|
|
|
18
|
+
function loadWallet(): string {
|
|
19
|
+
try { return readFileSync(join(homedir(), ".nous-token"), "utf-8").trim(); } catch { return ""; }
|
|
20
|
+
}
|
|
21
|
+
|
|
15
22
|
// Built-in providers: prefix maps to gateway shortcut route
|
|
16
23
|
const BUILTIN_PROVIDERS: Record<string, { prefix: string; api: string; envVars: string[] }> = {
|
|
17
24
|
openai: { prefix: "openai", api: "openai-completions", envVars: ["OPENAI_API_KEY"] },
|
|
@@ -34,11 +41,13 @@ interface PluginConfig {
|
|
|
34
41
|
|
|
35
42
|
export default function plugin(api: OpenClawPluginApi): void {
|
|
36
43
|
const cfg = (api.pluginConfig ?? {}) as PluginConfig;
|
|
44
|
+
const wallet = loadWallet();
|
|
45
|
+
const walletSegment = wallet ? `/w/${wallet}` : "";
|
|
37
46
|
|
|
38
47
|
// ── Register built-in providers ──
|
|
39
48
|
for (const [providerKey, { prefix, api: apiType, envVars }] of Object.entries(BUILTIN_PROVIDERS)) {
|
|
40
49
|
registerProvider(api, providerKey, {
|
|
41
|
-
baseUrl: `${GATEWAY}/${prefix}/v1`,
|
|
50
|
+
baseUrl: `${GATEWAY}/${prefix}${walletSegment}/v1`,
|
|
42
51
|
apiType,
|
|
43
52
|
envVars,
|
|
44
53
|
});
|
|
@@ -48,8 +57,7 @@ export default function plugin(api: OpenClawPluginApi): void {
|
|
|
48
57
|
if (cfg.customProviders) {
|
|
49
58
|
for (const [name, { upstream, envVar, api: apiType }] of Object.entries(cfg.customProviders)) {
|
|
50
59
|
registerProvider(api, name, {
|
|
51
|
-
|
|
52
|
-
baseUrl: `${GATEWAY}/v1`,
|
|
60
|
+
baseUrl: `${GATEWAY}${walletSegment}/v1`,
|
|
53
61
|
apiType: apiType || "openai-completions",
|
|
54
62
|
envVars: [envVar],
|
|
55
63
|
upstreamHeader: upstream,
|
|
@@ -58,7 +66,8 @@ export default function plugin(api: OpenClawPluginApi): void {
|
|
|
58
66
|
}
|
|
59
67
|
|
|
60
68
|
const total = Object.keys(BUILTIN_PROVIDERS).length + Object.keys(cfg.customProviders || {}).length;
|
|
61
|
-
api.logger.
|
|
69
|
+
if (!wallet) api.logger.warn(`[nous-token] no wallet found — run "npx nous-token setup 0xYOUR_WALLET" to link usage to your address`);
|
|
70
|
+
api.logger.info(`[nous-token] ready — ${total} providers${wallet ? `, wallet ${wallet.slice(0, 6)}...${wallet.slice(-4)}` : ""}`);
|
|
62
71
|
}
|
|
63
72
|
|
|
64
73
|
// ── Provider registration ──
|