nous-token 0.3.1 → 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.
Files changed (2) hide show
  1. package/index.ts +13 -4
  2. package/package.json +1 -1
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
- // Custom providers use X-Nous-Upstream header instead of shortcut prefix
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.info(`[nous-token] ready${total} providers, usage tracked via gateway`);
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 ──
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nous-token",
3
- "version": "0.3.1",
3
+ "version": "0.3.2",
4
4
  "description": "Open-source AI usage tracker. One command to track all your AI spending.",
5
5
  "type": "module",
6
6
  "main": "index.ts",