slash-tokens 0.3.0 → 1.0.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
@@ -4,35 +4,23 @@ Pre-flight checks for API calls. 4.8 KB WASM. Sub-millisecond. Zero dependencies
4
4
 
5
5
  **Fly First. Pay Economy.**
6
6
 
7
- ## Install
8
-
9
7
  ```bash
10
8
  npm install slash-tokens
11
9
  ```
12
10
 
13
- ## Use
14
-
15
11
  ```js
16
- import { slash } from 'slash-tokens'
12
+ import { preflight } from 'slash-tokens'
17
13
 
18
- const tokens = slash(prompt)
19
-
20
- if (tokens > contextWindow) trim(prompt)
21
- if (tokens < cheapThreshold) useHaiku()
14
+ const check = preflight(prompt, 'claude-opus')
15
+ // tokens: 47,000 | cost: $0.71 | 11 cheaper options | save 99%
22
16
  ```
23
17
 
24
- One function. Returns a token estimate. Sub-millisecond. Any model.
25
-
26
- ## Evaluate a repo
18
+ Or one line every API call pre-flighted automatically:
27
19
 
28
- ```bash
29
- bunx slash-tokens
20
+ ```js
21
+ import 'slash-tokens/auto'
30
22
  ```
31
23
 
32
- ## Docs
33
-
34
- Everything is at **[slashtokens.com](https://slashtokens.com)**
35
-
36
- ## License
24
+ Full docs, examples, and model pricing at **[GitHub](https://github.com/Wolfe-Jam/slash-tokens)**
37
25
 
38
- MIT
26
+ [slashtokens.com](https://slashtokens.com) | MIT
package/dist/auto.js CHANGED
@@ -1,9 +1,30 @@
1
1
  import { patchFetch, onIntercept } from './intercept.js';
2
+ import { report } from './transact.js';
3
+ import { hasKey } from './config.js';
2
4
  // Auto mode: import this file and every LLM call is pre-flighted.
3
5
  // Usage: import 'slash-tokens/auto'
6
+ //
7
+ // No key: console logging only (free forever)
8
+ // With key (init or SLASH_KEY): flight records sent to API
9
+ //
10
+ // Auto mode observes every call — it doesn't block.
11
+ // The data shows what you're spending and what you COULD save.
12
+ // When you start acting on preflight results (skip/reduce/route),
13
+ // the savings become real.
4
14
  patchFetch();
5
- // Default handler: log to console
6
15
  onIntercept((event) => {
7
16
  const status = event.fits ? 'OK' : 'OVER LIMIT';
8
17
  console.log(`[slash] ${event.provider} ${event.model} | ${event.tokens.toLocaleString()} tokens | $${event.cost.toFixed(4)} | ${status}`);
18
+ // If key is configured, log the flight record (non-blocking)
19
+ if (hasKey() && event.tokens > 0) {
20
+ report({
21
+ tokens_estimated: event.tokens,
22
+ tokens_saved: 0,
23
+ model: event.model,
24
+ action: 'routed',
25
+ cost_saved_usd: 0,
26
+ }).catch(() => {
27
+ // Silent — never break the app for billing failures
28
+ });
29
+ }
9
30
  });
package/dist/config.d.ts CHANGED
@@ -4,3 +4,4 @@ export declare function init(opts: {
4
4
  }): void;
5
5
  export declare function resolveKey(perCallKey?: string): string;
6
6
  export declare function getEndpoint(): string;
7
+ export declare function hasKey(): boolean;
package/dist/config.js CHANGED
@@ -16,3 +16,6 @@ export function resolveKey(perCallKey) {
16
16
  export function getEndpoint() {
17
17
  return _endpoint;
18
18
  }
19
+ export function hasKey() {
20
+ return !!(_key || process.env.SLASH_KEY);
21
+ }
package/dist/index.d.ts CHANGED
@@ -5,5 +5,5 @@ export { MODELS, listModels } from './models.js';
5
5
  export type { ModelInfo } from './models.js';
6
6
  export { report } from './transact.js';
7
7
  export type { ReportOptions, ReportResult } from './transact.js';
8
- export { init } from './config.js';
8
+ export { init, hasKey } from './config.js';
9
9
  export { resolveKey } from './config.js';
package/dist/index.js CHANGED
@@ -7,5 +7,5 @@ export { MODELS, listModels } from './models.js';
7
7
  // Transaction reporting
8
8
  export { report } from './transact.js';
9
9
  // Configuration
10
- export { init } from './config.js';
10
+ export { init, hasKey } from './config.js';
11
11
  export { resolveKey } from './config.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "slash-tokens",
3
- "version": "0.3.0",
3
+ "version": "1.0.0",
4
4
  "description": "Pre-flight checks for API calls. 4.8 KB WASM. Sub-millisecond. Zero dependencies. Fly First. Pay Economy.",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",