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.
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +25 -14
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/managers/permissionManager.d.ts +9 -0
- package/dist/managers/permissionManager.d.ts.map +1 -1
- package/dist/managers/permissionManager.js +166 -6
- package/dist/tools/bashTool.d.ts.map +1 -1
- package/dist/tools/bashTool.js +66 -27
- package/dist/types/permissions.d.ts +4 -0
- package/dist/types/permissions.d.ts.map +1 -1
- package/dist/utils/bashParser.d.ts +24 -0
- package/dist/utils/bashParser.d.ts.map +1 -0
- package/dist/utils/bashParser.js +413 -0
- package/dist/utils/pathSafety.d.ts +10 -0
- package/dist/utils/pathSafety.d.ts.map +1 -0
- package/dist/utils/pathSafety.js +23 -0
- package/package.json +5 -2
- package/src/agent.ts +28 -13
- package/src/index.ts +1 -0
- package/src/managers/permissionManager.ts +210 -6
- package/src/tools/bashTool.ts +72 -32
- package/src/types/permissions.ts +4 -0
- package/src/utils/bashParser.ts +444 -0
- package/src/utils/pathSafety.ts +26 -0
- package/dist/utils/largeOutputHandler.d.ts +0 -15
- package/dist/utils/largeOutputHandler.d.ts.map +0 -1
- package/dist/utils/largeOutputHandler.js +0 -40
- package/dist/utils/tokenEstimator.d.ts +0 -39
- package/dist/utils/tokenEstimator.d.ts.map +0 -1
- package/dist/utils/tokenEstimator.js +0 -55
- package/src/utils/largeOutputHandler.ts +0 -55
- package/src/utils/tokenEstimator.ts +0 -68
|
@@ -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
|
-
}
|