nous-token 0.3.1 → 0.3.3
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 +5 -4
- package/index.ts +13 -4
- package/package.json +1 -1
package/cli/setup.ts
CHANGED
|
@@ -156,10 +156,10 @@ const tools: Tool[] = [
|
|
|
156
156
|
// ── Shell env helper ──
|
|
157
157
|
|
|
158
158
|
// Collect env vars to set — don't write to shell rc file
|
|
159
|
-
const envCommands: string
|
|
159
|
+
const envCommands: Map<string, string> = new Map();
|
|
160
160
|
|
|
161
161
|
function setShellEnv(key: string, value: string, toolName: string): ConfigResult {
|
|
162
|
-
envCommands.
|
|
162
|
+
envCommands.set(key, `export ${key}="${value}"`);
|
|
163
163
|
return { success: true, message: `${key}` };
|
|
164
164
|
}
|
|
165
165
|
|
|
@@ -233,13 +233,14 @@ for (const tool of tools) {
|
|
|
233
233
|
console.log("");
|
|
234
234
|
|
|
235
235
|
if (configured > 0) {
|
|
236
|
+
const cmds = [...envCommands.values()];
|
|
236
237
|
console.log(` \x1b[32m${configured} tool(s) detected.\x1b[0m\n`);
|
|
237
238
|
console.log(" \x1b[1mThis terminal only:\x1b[0m");
|
|
238
|
-
console.log(` \x1b[36m${
|
|
239
|
+
console.log(` \x1b[36m${cmds.join(" && ")}\x1b[0m\n`);
|
|
239
240
|
console.log(" \x1b[1mAll terminals (permanent):\x1b[0m");
|
|
240
241
|
const shell = process.env.SHELL || "/bin/bash";
|
|
241
242
|
const rcFile = shell.includes("zsh") ? "~/.zshrc" : "~/.bashrc";
|
|
242
|
-
console.log(` \x1b[36mecho '${
|
|
243
|
+
console.log(` \x1b[36mecho '${cmds.join("\\n")}' >> ${rcFile} && source ${rcFile}\x1b[0m\n`);
|
|
243
244
|
console.log(` See your usage at \x1b[4mhttps://token.nousai.cc\x1b[0m`);
|
|
244
245
|
} else {
|
|
245
246
|
console.log(" No AI tools found. Install Claude Code, Cursor, or any OpenAI-compatible tool.");
|
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 ──
|