the-token-company 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.
package/dist/anthropic.js CHANGED
@@ -31,9 +31,9 @@ function hasSearchToolUse(response) {
31
31
  function formatSearchResults(results) {
32
32
  return results.map(r => `Source: ${r.title}\nURL: ${r.url}\n${r.content}`).join("\n\n");
33
33
  }
34
- async function handleSearchLoop(response, params, originalCreate, ttcClient, rest) {
34
+ async function handleSearchLoop(response, params, originalCreate, ttcClient, stats, rest) {
35
+ const messages = [...(params.messages || [])];
35
36
  while (hasSearchToolUse(response)) {
36
- const messages = [...(params.messages || [])];
37
37
  // Add assistant response
38
38
  const assistantContent = response.content.map((b) => {
39
39
  if (typeof b.toJSON === 'function')
@@ -47,6 +47,7 @@ async function handleSearchLoop(response, params, originalCreate, ttcClient, res
47
47
  if (block.type === "tool_use" && block.name === "ttc_web_search") {
48
48
  const query = block.input?.query || "";
49
49
  const searchResult = await ttcClient.search(query);
50
+ stats._recordSearch(searchResult);
50
51
  toolResults.push({
51
52
  type: "tool_result",
52
53
  tool_use_id: block.id,
@@ -119,7 +120,7 @@ export function withCompression(client, options) {
119
120
  let response = await originalCreate(params, ...rest);
120
121
  // Handle search tool loop
121
122
  if (webSearch) {
122
- response = await handleSearchLoop(response, params, originalCreate, ttcClient, rest);
123
+ response = await handleSearchLoop(response, params, originalCreate, ttcClient, stats, rest);
123
124
  }
124
125
  return response;
125
126
  };
package/dist/types.d.ts CHANGED
@@ -76,6 +76,7 @@ export declare class CompressionStats {
76
76
  private _accumulator;
77
77
  _startTurn(): void;
78
78
  _record(result: CompressResult): void;
79
+ _recordSearch(result: SearchResult): void;
79
80
  _endTurn(): void;
80
81
  get totalInputTokens(): number;
81
82
  get totalOutputTokens(): number;
package/dist/types.js CHANGED
@@ -7,6 +7,16 @@ export class CompressionStats {
7
7
  _record(result) {
8
8
  this._accumulator.push(result);
9
9
  }
10
+ _recordSearch(result) {
11
+ this.history.push({
12
+ inputTokens: result.originalInputTokens,
13
+ outputTokens: result.outputTokens,
14
+ tokensSaved: result.tokensSaved,
15
+ messagesCompressed: 0,
16
+ ratio: result.outputTokens === 0 ? 0 : result.originalInputTokens / result.outputTokens,
17
+ timestamp: Date.now(),
18
+ });
19
+ }
10
20
  _endTurn() {
11
21
  if (this._accumulator.length > 0) {
12
22
  const inputTokens = this._accumulator.reduce((s, r) => s + r.inputTokens, 0);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "the-token-company",
3
- "version": "0.3.1",
3
+ "version": "0.3.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",