wave-agent-sdk 0.0.10 → 0.0.11

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.
@@ -1,68 +0,0 @@
1
- /**
2
- * Simple token estimation utility for text content
3
- *
4
- * This provides a fast approximation of token count without requiring
5
- * actual tokenization, which would be expensive for large content.
6
- */
7
-
8
- /**
9
- * Estimate the number of tokens in a text string
10
- *
11
- * Uses a simple heuristic based on character count and common patterns:
12
- * - Average token length varies by language and content type
13
- * - English text: ~4-5 characters per token
14
- * - Code/structured text: ~3-4 characters per token
15
- * - Numbers/symbols: ~2-3 characters per token
16
- *
17
- * This function uses a conservative estimate of 4 characters per token
18
- * which works well for mixed content (text + code + symbols).
19
- *
20
- * @param text - The text to estimate tokens for
21
- * @returns Estimated number of tokens
22
- */
23
- export function estimateTokenCount(text: string): number {
24
- if (!text || text.length === 0) {
25
- return 0;
26
- }
27
-
28
- // Base estimation: 4 characters per token (conservative)
29
- const baseEstimate = Math.ceil(text.length / 4);
30
-
31
- // Adjust for whitespace (spaces don't contribute much to token count)
32
- const whitespaceCount = (text.match(/\s/g) || []).length;
33
- const adjustedEstimate = Math.ceil((text.length - whitespaceCount * 0.5) / 4);
34
-
35
- // Use the more conservative (higher) estimate
36
- return Math.max(baseEstimate, adjustedEstimate);
37
- }
38
-
39
- /**
40
- * Check if estimated token count exceeds a threshold
41
- *
42
- * @param text - The text to check
43
- * @param threshold - Token threshold (default: 20,000)
44
- * @returns True if estimated tokens exceed threshold
45
- */
46
- export function exceedsTokenThreshold(
47
- text: string,
48
- threshold: number = 20000,
49
- ): boolean {
50
- return estimateTokenCount(text) > threshold;
51
- }
52
-
53
- /**
54
- * Get a human-readable description of estimated token usage
55
- *
56
- * @param text - The text to analyze
57
- * @param threshold - Token threshold for comparison
58
- * @returns Description string with token count and threshold info
59
- */
60
- export function getTokenUsageDescription(
61
- text: string,
62
- threshold: number = 20000,
63
- ): string {
64
- const estimatedTokens = estimateTokenCount(text);
65
- const exceedsThreshold = estimatedTokens > threshold;
66
-
67
- return `${estimatedTokens.toLocaleString()} tokens (${exceedsThreshold ? "exceeds" : "within"} ${threshold.toLocaleString()} limit)`;
68
- }