nous-token 0.2.2 → 0.3.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.
Files changed (2) hide show
  1. package/cli/setup.ts +20 -32
  2. 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(path: string, wallet: string): string {
28
- return wallet ? `${GATEWAY}${path}/w/${wallet}` : `${GATEWAY}${path}`;
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("/anthropic", wallet), "Claude Code");
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("/openai/v1", wallet);
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("/openai/v1", wallet), "Codex");
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("/gemini", wallet), "Gemini CLI");
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("/openai/v1", wallet), "Python openai SDK");
140
+ return setShellEnv("OPENAI_BASE_URL", gatewayUrl("openai", "/v1", wallet), "Python openai SDK");
141
141
  },
142
142
  },
143
143
 
@@ -148,36 +148,19 @@ 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("/anthropic", wallet), "Python anthropic SDK");
151
+ return setShellEnv("ANTHROPIC_BASE_URL", gatewayUrl("anthropic", "", wallet), "Python anthropic SDK");
152
152
  },
153
153
  },
154
154
  ];
155
155
 
156
156
  // ── Shell env helper ──
157
157
 
158
- function setShellEnv(key: string, value: string, toolName: string): ConfigResult {
159
- const shell = process.env.SHELL || "/bin/bash";
160
- const rcFile = shell.includes("zsh") ? join(HOME, ".zshrc") : join(HOME, ".bashrc");
158
+ // Collect env vars to set don't write to shell rc file
159
+ const envCommands: string[] = [];
161
160
 
162
- if (existsSync(rcFile)) {
163
- const content = readFileSync(rcFile, "utf-8");
164
- // Check if already configured with the exact same value
165
- if (content.includes(`${key}="${value}"`)) {
166
- return { success: true, message: "already configured" };
167
- }
168
- // Remove old nous-token setting if exists, then write new one
169
- const lines = content.split("\n").filter(l => !(l.includes(`${key}=`) && l.includes("nousai")));
170
- lines.push(`export ${key}="${value}" # nous-token gateway`);
171
- writeFileSync(rcFile, lines.join("\n"));
172
- } else {
173
- writeFileSync(rcFile, `export ${key}="${value}" # nous-token gateway\n`);
174
- }
175
-
176
- // Also set in current process
177
- process.env[key] = value;
178
-
179
- const rcName = rcFile.includes("zsh") ? "~/.zshrc" : "~/.bashrc";
180
- return { success: true, message: `set ${key} in ${rcName}` };
161
+ function setShellEnv(key: string, value: string, toolName: string): ConfigResult {
162
+ envCommands.push(`export ${key}="${value}"`);
163
+ return { success: true, message: `${key}` };
181
164
  }
182
165
 
183
166
 
@@ -250,9 +233,14 @@ for (const tool of tools) {
250
233
  console.log("");
251
234
 
252
235
  if (configured > 0) {
253
- console.log(` \x1b[32m${configured} tool(s) configured.\x1b[0m`);
236
+ console.log(` \x1b[32m${configured} tool(s) detected.\x1b[0m\n`);
237
+ console.log(" \x1b[1mThis terminal only:\x1b[0m");
238
+ console.log(` \x1b[36m${envCommands.join(" && ")}\x1b[0m\n`);
239
+ console.log(" \x1b[1mAll terminals (permanent):\x1b[0m");
240
+ const shell = process.env.SHELL || "/bin/bash";
241
+ const rcFile = shell.includes("zsh") ? "~/.zshrc" : "~/.bashrc";
242
+ console.log(` \x1b[36mecho '${envCommands.join("\\n")}' >> ${rcFile} && source ${rcFile}\x1b[0m\n`);
254
243
  console.log(` See your usage at \x1b[4mhttps://token.nousai.cc\x1b[0m`);
255
- console.log(` Run \x1b[1msource ~/.zshrc\x1b[0m to apply changes in this terminal.`);
256
244
  } else {
257
245
  console.log(" No AI tools found. Install Claude Code, Cursor, or any OpenAI-compatible tool.");
258
246
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nous-token",
3
- "version": "0.2.2",
3
+ "version": "0.3.1",
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",