the-token-company 0.2.0 → 0.2.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.
package/README.md CHANGED
@@ -117,8 +117,6 @@ const model = wrapLanguageModel({
117
117
  |------------|------------------------|
118
118
  | `bear-2` | Latest, recommended |
119
119
  | `bear-1.2` | Previous generation |
120
- | `bear-1.1` | Legacy |
121
- | `bear-1` | Legacy |
122
120
 
123
121
  ## Aggressiveness
124
122
 
package/dist/ai-sdk.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { wrapLanguageModel } from "ai";
2
2
  import { TheTokenCompany } from "./client.js";
3
- import { AnalyticsTTC, compressAISDKPrompt, resolveAggressiveness } from "./compress.js";
3
+ import { StatsTTC, compressAISDKPrompt, resolveAggressiveness } from "./compress.js";
4
4
  import { CompressionStats } from "./types.js";
5
5
  /**
6
6
  * Create a Vercel AI SDK middleware that auto-compresses non-assistant messages.
@@ -17,7 +17,7 @@ import { CompressionStats } from "./types.js";
17
17
  */
18
18
  export function compressionMiddleware(options) {
19
19
  const stats = new CompressionStats();
20
- const analytics = new AnalyticsTTC(new TheTokenCompany({ apiKey: options.compressionApiKey, appId: options.appId }), stats);
20
+ const compressor = new StatsTTC(new TheTokenCompany({ apiKey: options.compressionApiKey, appId: options.appId }), stats);
21
21
  const compressionModel = options.model ?? "bear-2";
22
22
  const roleAggr = resolveAggressiveness(options.aggressiveness ?? 0.2);
23
23
  const middleware = {
@@ -26,7 +26,7 @@ export function compressionMiddleware(options) {
26
26
  transformParams: async ({ params }) => {
27
27
  if (params.prompt) {
28
28
  stats._startTurn();
29
- const compressed = await compressAISDKPrompt(analytics, params.prompt, compressionModel, roleAggr);
29
+ const compressed = await compressAISDKPrompt(compressor, params.prompt, compressionModel, roleAggr);
30
30
  stats._endTurn();
31
31
  return { ...params, prompt: compressed };
32
32
  }
package/dist/anthropic.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { TheTokenCompany } from "./client.js";
2
- import { AnalyticsTTC, compressAnthropicMessages, resolveAggressiveness } from "./compress.js";
2
+ import { StatsTTC, compressAnthropicMessages, resolveAggressiveness } from "./compress.js";
3
3
  import { CompressionStats } from "./types.js";
4
4
  /**
5
5
  * Wrap an Anthropic client to auto-compress non-assistant messages.
@@ -24,7 +24,7 @@ import { CompressionStats } from "./types.js";
24
24
  */
25
25
  export function withCompression(client, options) {
26
26
  const stats = new CompressionStats();
27
- const analytics = new AnalyticsTTC(new TheTokenCompany({ apiKey: options.compressionApiKey, appId: options.appId }), stats);
27
+ const compressor = new StatsTTC(new TheTokenCompany({ apiKey: options.compressionApiKey, appId: options.appId }), stats);
28
28
  const model = options.model ?? "bear-2";
29
29
  const roleAggr = resolveAggressiveness(options.aggressiveness ?? 0.2);
30
30
  const systemAggr = roleAggr["system"];
@@ -34,11 +34,11 @@ export function withCompression(client, options) {
34
34
  if (params?.messages) {
35
35
  params = {
36
36
  ...params,
37
- messages: await compressAnthropicMessages(analytics, params.messages, model, roleAggr),
37
+ messages: await compressAnthropicMessages(compressor, params.messages, model, roleAggr),
38
38
  };
39
39
  }
40
40
  if (systemAggr != null && typeof params?.system === "string" && params.system.trim()) {
41
- const result = await analytics.compress(params.system, { model, aggressiveness: systemAggr });
41
+ const result = await compressor.compress(params.system, { model, aggressiveness: systemAggr });
42
42
  params = { ...params, system: result.output };
43
43
  }
44
44
  stats._endTurn();
@@ -7,7 +7,7 @@ export interface Compressor {
7
7
  aggressiveness?: number;
8
8
  }): Promise<CompressResult>;
9
9
  }
10
- export declare class AnalyticsTTC implements Compressor {
10
+ export declare class StatsTTC implements Compressor {
11
11
  private readonly inner;
12
12
  readonly stats: CompressionStats;
13
13
  constructor(inner: TheTokenCompany, stats: CompressionStats);
package/dist/compress.js CHANGED
@@ -1,5 +1,5 @@
1
1
  const DEFAULT_ROLES = ["user", "system", "tool"];
2
- export class AnalyticsTTC {
2
+ export class StatsTTC {
3
3
  inner;
4
4
  stats;
5
5
  constructor(inner, stats) {
package/dist/openai.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { TheTokenCompany } from "./client.js";
2
- import { AnalyticsTTC, compressOpenAIMessages, resolveAggressiveness } from "./compress.js";
2
+ import { StatsTTC, compressOpenAIMessages, resolveAggressiveness } from "./compress.js";
3
3
  import { CompressionStats } from "./types.js";
4
4
  /**
5
5
  * Wrap an OpenAI-compatible client to auto-compress non-assistant messages.
@@ -22,7 +22,7 @@ import { CompressionStats } from "./types.js";
22
22
  */
23
23
  export function withCompression(client, options) {
24
24
  const stats = new CompressionStats();
25
- const analytics = new AnalyticsTTC(new TheTokenCompany({ apiKey: options.compressionApiKey, appId: options.appId }), stats);
25
+ const compressor = new StatsTTC(new TheTokenCompany({ apiKey: options.compressionApiKey, appId: options.appId }), stats);
26
26
  const model = options.model ?? "bear-2";
27
27
  const roleAggr = resolveAggressiveness(options.aggressiveness ?? 0.2);
28
28
  const originalCreate = client.chat.completions.create.bind(client.chat.completions);
@@ -31,7 +31,7 @@ export function withCompression(client, options) {
31
31
  stats._startTurn();
32
32
  params = {
33
33
  ...params,
34
- messages: await compressOpenAIMessages(analytics, params.messages, model, roleAggr),
34
+ messages: await compressOpenAIMessages(compressor, params.messages, model, roleAggr),
35
35
  };
36
36
  stats._endTurn();
37
37
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "the-token-company",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "Node.js SDK for The Token Company — compress LLM prompts to reduce costs and latency",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",