slash-tokens 1.1.2 → 1.2.0

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/README.md CHANGED
@@ -14,12 +14,30 @@ const check = preflight(prompt, 'claude-opus')
14
14
  // tokens: 47,000 | cost: $0.71 | 11 cheaper options | save 99%
15
15
  ```
16
16
 
17
- Or one line — every API call checked pre-call:
17
+ Or one line — every API call optimized pre-call:
18
18
 
19
19
  ```js
20
20
  import 'slash-tokens/auto'
21
21
  ```
22
22
 
23
+ Every call routed to the cheapest model that can execute it efficiently. Session summary on exit:
24
+
25
+ ```
26
+ [slash] Session: 47 calls | 23 routed | $0.89 salvaged — The more you build, the more you save
27
+ ```
28
+
29
+ ## Next.js Starter
30
+
31
+ One-click deploy with Vercel AI SDK + slash-tokens built in:
32
+
33
+ [![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https://github.com/Wolfe-Jam/slash-nextjs&project-name=slash-nextjs&env=ANTHROPIC_API_KEY)
34
+
35
+ → [slash-nextjs on GitHub](https://github.com/Wolfe-Jam/slash-nextjs)
36
+
37
+ ## Dashboard
38
+
39
+ Track savings across all your apps. Free key at [mcpaas.live/slash/setup](https://mcpaas.live/slash/setup)
40
+
23
41
  Full docs, examples, and model pricing at **[GitHub](https://github.com/Wolfe-Jam/slash-tokens)**
24
42
 
25
43
  [slashtokens.com](https://slashtokens.com) | MIT
package/dist/auto.js CHANGED
@@ -19,6 +19,20 @@ const R = '\x1b[0m';
19
19
  const B = '\x1b[1m';
20
20
  const GREEN = '\x1b[38;2;74;222;128m';
21
21
  const GOLD = '\x1b[38;2;230;161;65m';
22
+ const DIM = '\x1b[2m';
23
+ // Session summary on exit — print total saved when the process ends
24
+ function printSummary() {
25
+ if (totalCalls === 0)
26
+ return;
27
+ const savedStr = totalSalvaged > 0 ? `${GREEN}${B}$${totalSalvaged.toFixed(4)} salvaged${R}` : `$0 salvaged`;
28
+ const routedStr = totalRouted > 0 ? ` | ${GOLD}${totalRouted} routed${R}` : '';
29
+ console.log(`\n${GREEN}[slash]${R} Session: ${totalCalls} calls${routedStr} | ${savedStr} ${DIM}— The more you build, the more you save${R}`);
30
+ }
31
+ if (typeof process !== 'undefined') {
32
+ process.once('exit', printSummary);
33
+ process.once('SIGINT', () => { printSummary(); process.exit(0); });
34
+ process.once('SIGTERM', () => { printSummary(); process.exit(0); });
35
+ }
22
36
  patchFetch();
23
37
  onIntercept((event) => {
24
38
  totalCalls++;
package/dist/config.js CHANGED
@@ -24,7 +24,7 @@ export function resolveKey(perCallKey) {
24
24
  return key;
25
25
  }
26
26
  export function getEndpoint() {
27
- return _endpoint;
27
+ return process.env.SLASH_ENDPOINT || _endpoint;
28
28
  }
29
29
  export function hasKey() {
30
30
  return !!(_key || process.env.SLASH_KEY);
package/dist/intercept.js CHANGED
@@ -37,7 +37,11 @@ const AI_ENDPOINTS = [
37
37
  {
38
38
  pattern: /generativelanguage\.googleapis\.com/,
39
39
  provider: 'Google',
40
- modelExtractor: (body) => 'gemini-2.5-flash',
40
+ modelExtractor: (_body, url) => {
41
+ // Model is in the URL path: /v1beta/models/gemini-2.0-flash:generateContent
42
+ const match = url?.match(/\/models\/([^/:]+)/);
43
+ return match ? match[1] : 'gemini-2.5-flash';
44
+ },
41
45
  },
42
46
  {
43
47
  pattern: /api\.x\.ai/,
@@ -140,7 +144,7 @@ export function patchFetch() {
140
144
  if (bodyStr) {
141
145
  const body = JSON.parse(bodyStr);
142
146
  const content = extractContent(body);
143
- const rawModel = match.modelExtractor(body);
147
+ const rawModel = match.modelExtractor(body, url);
144
148
  const originalModel = normalizeModel(rawModel);
145
149
  const tokens = slash(content);
146
150
  const originalInfo = getModel(originalModel);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "slash-tokens",
3
- "version": "1.1.2",
3
+ "version": "1.2.0",
4
4
  "description": "Token Optimization for Context Engineers. 4.8 KB WASM. Sub-millisecond. Zero dependencies.",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",