vantaverse-ai-reviewer 0.1.5 โ 0.2.1
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 +55 -15
- package/dist/ai/agent.d.ts +1 -1
- package/dist/ai/agent.d.ts.map +1 -1
- package/dist/ai/agent.js +23 -11
- package/dist/ai/agent.js.map +1 -1
- package/dist/commands/scan.d.ts +7 -2
- package/dist/commands/scan.d.ts.map +1 -1
- package/dist/commands/scan.js +209 -27
- package/dist/commands/scan.js.map +1 -1
- package/dist/core/diff-analyzer.d.ts +22 -0
- package/dist/core/diff-analyzer.d.ts.map +1 -0
- package/dist/core/diff-analyzer.js +71 -0
- package/dist/core/diff-analyzer.js.map +1 -0
- package/dist/core/framework-detector.d.ts.map +1 -1
- package/dist/core/framework-detector.js +48 -17
- package/dist/core/framework-detector.js.map +1 -1
- package/dist/core/security-scanner.d.ts +36 -0
- package/dist/core/security-scanner.d.ts.map +1 -0
- package/dist/core/security-scanner.js +130 -0
- package/dist/core/security-scanner.js.map +1 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -1
- package/dist/utils/interactive-logger.d.ts +49 -0
- package/dist/utils/interactive-logger.d.ts.map +1 -0
- package/dist/utils/interactive-logger.js +190 -0
- package/dist/utils/interactive-logger.js.map +1 -0
- package/dist/utils/token-estimator.d.ts +26 -0
- package/dist/utils/token-estimator.d.ts.map +1 -0
- package/dist/utils/token-estimator.js +92 -0
- package/dist/utils/token-estimator.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Interactive Logger - Agentic CLI output with motivating messages
|
|
3
|
+
*/
|
|
4
|
+
import chalk from 'chalk';
|
|
5
|
+
import ora from 'ora';
|
|
6
|
+
// Agentic thinking messages for different phases
|
|
7
|
+
const AGENTIC_MESSAGES = {
|
|
8
|
+
scanning: [
|
|
9
|
+
'๐ Scanning project structure...',
|
|
10
|
+
'๐ Discovering source files...',
|
|
11
|
+
'๐งฌ Analyzing file patterns...',
|
|
12
|
+
'๐ Indexing codebase...',
|
|
13
|
+
'๐ Building file tree...'
|
|
14
|
+
],
|
|
15
|
+
security: [
|
|
16
|
+
'๐ Analyzing security patterns...',
|
|
17
|
+
'๐ก๏ธ Checking for vulnerabilities...',
|
|
18
|
+
'๐ Scanning for exposed secrets...',
|
|
19
|
+
'โ ๏ธ Reviewing authentication flows...',
|
|
20
|
+
'๐ Validating access controls...'
|
|
21
|
+
],
|
|
22
|
+
codeQuality: [
|
|
23
|
+
'๐งน Reviewing code quality...',
|
|
24
|
+
'๐ง Analyzing code patterns...',
|
|
25
|
+
'๐ Checking architecture...',
|
|
26
|
+
'๐ฏ Identifying code smells...',
|
|
27
|
+
'โจ Evaluating best practices...'
|
|
28
|
+
],
|
|
29
|
+
accessibility: [
|
|
30
|
+
'โฟ Checking accessibility...',
|
|
31
|
+
'๐จ Reviewing WCAG compliance...',
|
|
32
|
+
'๐ฅ๏ธ Analyzing screen reader support...',
|
|
33
|
+
'โจ๏ธ Testing keyboard navigation...',
|
|
34
|
+
'๐๏ธ Checking color contrast...'
|
|
35
|
+
],
|
|
36
|
+
uiux: [
|
|
37
|
+
'๐จ Analyzing user experience...',
|
|
38
|
+
'๐ฑ Reviewing responsive design...',
|
|
39
|
+
'โก Checking loading states...',
|
|
40
|
+
'๐ซ Reviewing interactions...',
|
|
41
|
+
'๐ญ Analyzing UI patterns...'
|
|
42
|
+
],
|
|
43
|
+
testing: [
|
|
44
|
+
'๐งช Analyzing test coverage...',
|
|
45
|
+
'โ
Reviewing test patterns...',
|
|
46
|
+
'๐ฌ Identifying test gaps...',
|
|
47
|
+
'๐ Suggesting test cases...',
|
|
48
|
+
'๐ฏ Finding edge cases...'
|
|
49
|
+
],
|
|
50
|
+
overview: [
|
|
51
|
+
'๐ Building project overview...',
|
|
52
|
+
'๐๏ธ Analyzing architecture...',
|
|
53
|
+
'๐ Evaluating project health...',
|
|
54
|
+
'๐ฏ Identifying priorities...',
|
|
55
|
+
'๐ก Generating recommendations...'
|
|
56
|
+
]
|
|
57
|
+
};
|
|
58
|
+
// Motivational messages during AI analysis
|
|
59
|
+
const MOTIVATIONAL_MESSAGES = [
|
|
60
|
+
'๐ค AI is thinking deeply...',
|
|
61
|
+
'๐ง Processing code patterns...',
|
|
62
|
+
'๐ญ Formulating insights...',
|
|
63
|
+
'๐ฎ Generating recommendations...',
|
|
64
|
+
'๐ Crafting detailed analysis...',
|
|
65
|
+
'โจ Almost there...',
|
|
66
|
+
'๐ฏ Focusing on key issues...',
|
|
67
|
+
'๐ก Finding improvements...',
|
|
68
|
+
'๐ Deep diving into code...',
|
|
69
|
+
'๐ Building comprehensive report...'
|
|
70
|
+
];
|
|
71
|
+
/**
|
|
72
|
+
* Create an interactive spinner with rotating agentic messages
|
|
73
|
+
*/
|
|
74
|
+
export function createAgenticSpinner(initialText) {
|
|
75
|
+
const spin = ora({
|
|
76
|
+
text: initialText,
|
|
77
|
+
color: 'cyan',
|
|
78
|
+
spinner: 'dots'
|
|
79
|
+
});
|
|
80
|
+
let messageInterval = null;
|
|
81
|
+
let currentPhase = 'scanning';
|
|
82
|
+
let messageIndex = 0;
|
|
83
|
+
const updatePhase = (phase) => {
|
|
84
|
+
currentPhase = phase;
|
|
85
|
+
messageIndex = 0;
|
|
86
|
+
const messages = AGENTIC_MESSAGES[phase];
|
|
87
|
+
if (messages && messages.length > 0) {
|
|
88
|
+
spin.text = messages[0];
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
const updateFile = (fileName, action) => {
|
|
92
|
+
const shortName = fileName.length > 40
|
|
93
|
+
? '...' + fileName.slice(-37)
|
|
94
|
+
: fileName;
|
|
95
|
+
spin.text = `${action} ${chalk.cyan(shortName)}`;
|
|
96
|
+
};
|
|
97
|
+
const showThinking = () => {
|
|
98
|
+
if (messageInterval)
|
|
99
|
+
clearInterval(messageInterval);
|
|
100
|
+
let thinkingIndex = 0;
|
|
101
|
+
messageInterval = setInterval(() => {
|
|
102
|
+
spin.text = MOTIVATIONAL_MESSAGES[thinkingIndex % MOTIVATIONAL_MESSAGES.length];
|
|
103
|
+
thinkingIndex++;
|
|
104
|
+
}, 2000);
|
|
105
|
+
};
|
|
106
|
+
const stop = () => {
|
|
107
|
+
if (messageInterval) {
|
|
108
|
+
clearInterval(messageInterval);
|
|
109
|
+
messageInterval = null;
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
return { spinner: spin, updatePhase, updateFile, showThinking, stop };
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Display file scanning progress
|
|
116
|
+
*/
|
|
117
|
+
export function showFileScanProgress(files, onFile) {
|
|
118
|
+
for (const file of files) {
|
|
119
|
+
const ext = file.split('.').pop() || '';
|
|
120
|
+
const icon = getFileIcon(ext);
|
|
121
|
+
const shortName = file.length > 50 ? '...' + file.slice(-47) : file;
|
|
122
|
+
console.log(` ${icon} ${chalk.gray(shortName)} ${chalk.green('[scanned]')}`);
|
|
123
|
+
onFile?.(file);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Get icon for file extension
|
|
128
|
+
*/
|
|
129
|
+
function getFileIcon(ext) {
|
|
130
|
+
const icons = {
|
|
131
|
+
'ts': '๐',
|
|
132
|
+
'tsx': 'โ๏ธ',
|
|
133
|
+
'js': '๐',
|
|
134
|
+
'jsx': 'โ๏ธ',
|
|
135
|
+
'py': '๐',
|
|
136
|
+
'vue': '๐',
|
|
137
|
+
'svelte': '๐งก',
|
|
138
|
+
'css': '๐จ',
|
|
139
|
+
'scss': '๐จ',
|
|
140
|
+
'html': '๐',
|
|
141
|
+
'json': '๐',
|
|
142
|
+
'md': '๐',
|
|
143
|
+
'yaml': 'โ๏ธ',
|
|
144
|
+
'yml': 'โ๏ธ',
|
|
145
|
+
'test': '๐งช',
|
|
146
|
+
'spec': '๐งช'
|
|
147
|
+
};
|
|
148
|
+
return icons[ext] || '๐';
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Show analysis phase header with agentic messaging
|
|
152
|
+
*/
|
|
153
|
+
export function showAnalysisPhase(phase, fileCount) {
|
|
154
|
+
console.log();
|
|
155
|
+
console.log(chalk.bold.cyan(` โโ ${phase}`));
|
|
156
|
+
console.log(chalk.gray(` โ Analyzing ${fileCount} files...`));
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Show analysis complete for a phase
|
|
160
|
+
*/
|
|
161
|
+
export function showAnalysisComplete(phase, duration, findings) {
|
|
162
|
+
const icon = findings > 0 ? 'โ ๏ธ' : 'โ
';
|
|
163
|
+
console.log(chalk.gray(` โ ${icon} ${findings} findings (${duration}ms)`));
|
|
164
|
+
console.log(chalk.cyan(` โโ Complete`));
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Show real-time AI thinking indicator
|
|
168
|
+
*/
|
|
169
|
+
export function showAIThinking(message) {
|
|
170
|
+
process.stdout.write(`\r ${chalk.yellow('๐ค')} ${chalk.gray(message)} `);
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Display test file detection
|
|
174
|
+
*/
|
|
175
|
+
export function showTestFileSearch(pattern) {
|
|
176
|
+
console.log(chalk.gray(` ๐ Searching for ${chalk.cyan(pattern)} files...`));
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Create boxed status display
|
|
180
|
+
*/
|
|
181
|
+
export function showStatusBox(items) {
|
|
182
|
+
const maxKeyLen = Math.max(...Object.keys(items).map(k => k.length));
|
|
183
|
+
console.log(chalk.cyan(' โ' + 'โ'.repeat(50) + 'โ'));
|
|
184
|
+
for (const [key, value] of Object.entries(items)) {
|
|
185
|
+
const paddedKey = key.padEnd(maxKeyLen);
|
|
186
|
+
console.log(chalk.cyan(' โ') + ` ${paddedKey}: ${chalk.white(value)}`.padEnd(50) + chalk.cyan('โ'));
|
|
187
|
+
}
|
|
188
|
+
console.log(chalk.cyan(' โ' + 'โ'.repeat(50) + 'โ'));
|
|
189
|
+
}
|
|
190
|
+
//# sourceMappingURL=interactive-logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interactive-logger.js","sourceRoot":"","sources":["../../src/utils/interactive-logger.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,GAAiB,MAAM,KAAK,CAAC;AAEpC,iDAAiD;AACjD,MAAM,gBAAgB,GAAG;IACrB,QAAQ,EAAE;QACN,kCAAkC;QAClC,gCAAgC;QAChC,+BAA+B;QAC/B,yBAAyB;QACzB,0BAA0B;KAC7B;IACD,QAAQ,EAAE;QACN,mCAAmC;QACnC,qCAAqC;QACrC,oCAAoC;QACpC,sCAAsC;QACtC,kCAAkC;KACrC;IACD,WAAW,EAAE;QACT,8BAA8B;QAC9B,+BAA+B;QAC/B,6BAA6B;QAC7B,+BAA+B;QAC/B,gCAAgC;KACnC;IACD,aAAa,EAAE;QACX,6BAA6B;QAC7B,iCAAiC;QACjC,wCAAwC;QACxC,mCAAmC;QACnC,gCAAgC;KACnC;IACD,IAAI,EAAE;QACF,iCAAiC;QACjC,mCAAmC;QACnC,8BAA8B;QAC9B,8BAA8B;QAC9B,6BAA6B;KAChC;IACD,OAAO,EAAE;QACL,+BAA+B;QAC/B,8BAA8B;QAC9B,6BAA6B;QAC7B,6BAA6B;QAC7B,0BAA0B;KAC7B;IACD,QAAQ,EAAE;QACN,iCAAiC;QACjC,+BAA+B;QAC/B,iCAAiC;QACjC,8BAA8B;QAC9B,kCAAkC;KACrC;CACJ,CAAC;AAEF,2CAA2C;AAC3C,MAAM,qBAAqB,GAAG;IAC1B,6BAA6B;IAC7B,gCAAgC;IAChC,4BAA4B;IAC5B,kCAAkC;IAClC,kCAAkC;IAClC,mBAAmB;IACnB,8BAA8B;IAC9B,4BAA4B;IAC5B,6BAA6B;IAC7B,qCAAqC;CACxC,CAAC;AAEF;;GAEG;AACH,MAAM,UAAU,oBAAoB,C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CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC;AAClF,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,aAAa,CAAC,KAAsC;IAChE,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;IAErE,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,GAAG,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC;IACtD,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QAC/C,MAAM,SAAS,GAAG,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;QACxC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,IAAI,SAAS,KAAK,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC,MAAM,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;IACzG,CAAC;IACD,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,GAAG,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC;AAC1D,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Token Estimator - Pre-scan cost estimation
|
|
3
|
+
*/
|
|
4
|
+
import type { ScannedFile } from '../core/scanner.js';
|
|
5
|
+
import type { PromptType } from '../ai/prompts.js';
|
|
6
|
+
export interface TokenEstimate {
|
|
7
|
+
inputTokens: number;
|
|
8
|
+
outputTokens: number;
|
|
9
|
+
totalTokens: number;
|
|
10
|
+
estimatedCost: number;
|
|
11
|
+
breakdown: Partial<Record<PromptType, number>>;
|
|
12
|
+
warning?: string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Estimate token count from file content
|
|
16
|
+
*/
|
|
17
|
+
export declare function estimateTokens(content: string): number;
|
|
18
|
+
/**
|
|
19
|
+
* Estimate total cost for scanning files
|
|
20
|
+
*/
|
|
21
|
+
export declare function estimateScanCost(files: ScannedFile[], analysisTypes: PromptType[], maxCharsPerBatch?: number): TokenEstimate;
|
|
22
|
+
/**
|
|
23
|
+
* Format estimate for display
|
|
24
|
+
*/
|
|
25
|
+
export declare function formatEstimate(estimate: TokenEstimate): string;
|
|
26
|
+
//# sourceMappingURL=token-estimator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"token-estimator.d.ts","sourceRoot":"","sources":["../../src/utils/token-estimator.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEnD,MAAM,WAAW,aAAa;IAC1B,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;IACpB,aAAa,EAAE,MAAM,CAAC;IACtB,SAAS,EAAE,OAAO,CAAC,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC,CAAC;IAC/C,OAAO,CAAC,EAAE,MAAM,CAAC;CACpB;AA6BD;;GAEG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAEtD;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAC5B,KAAK,EAAE,WAAW,EAAE,EACpB,aAAa,EAAE,UAAU,EAAE,EAC3B,gBAAgB,GAAE,MAAc,GACjC,aAAa,CAgDf;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,aAAa,GAAG,MAAM,CAc9D"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Token Estimator - Pre-scan cost estimation
|
|
3
|
+
*/
|
|
4
|
+
// Approximate characters per token for code
|
|
5
|
+
const CHARS_PER_TOKEN = 4;
|
|
6
|
+
// Gemini pricing (as of 2024) - adjust as needed
|
|
7
|
+
const PRICE_PER_1M_INPUT_TOKENS = 0.075; // $0.075 per 1M input tokens
|
|
8
|
+
const PRICE_PER_1M_OUTPUT_TOKENS = 0.30; // $0.30 per 1M output tokens
|
|
9
|
+
// Average output tokens per analysis type
|
|
10
|
+
const OUTPUT_TOKENS_BY_TYPE = {
|
|
11
|
+
security: 800,
|
|
12
|
+
codeQuality: 1000,
|
|
13
|
+
accessibility: 600,
|
|
14
|
+
uiux: 700,
|
|
15
|
+
testing: 900,
|
|
16
|
+
overview: 1200
|
|
17
|
+
};
|
|
18
|
+
// Base prompt sizes (approximate)
|
|
19
|
+
const PROMPT_TOKENS_BY_TYPE = {
|
|
20
|
+
security: 200,
|
|
21
|
+
codeQuality: 250,
|
|
22
|
+
accessibility: 220,
|
|
23
|
+
uiux: 200,
|
|
24
|
+
testing: 230,
|
|
25
|
+
overview: 300
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Estimate token count from file content
|
|
29
|
+
*/
|
|
30
|
+
export function estimateTokens(content) {
|
|
31
|
+
return Math.ceil(content.length / CHARS_PER_TOKEN);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Estimate total cost for scanning files
|
|
35
|
+
*/
|
|
36
|
+
export function estimateScanCost(files, analysisTypes, maxCharsPerBatch = 50000) {
|
|
37
|
+
let totalInputTokens = 0;
|
|
38
|
+
let totalOutputTokens = 0;
|
|
39
|
+
const breakdown = {};
|
|
40
|
+
// Calculate input tokens from files (estimate based on size)
|
|
41
|
+
const totalFileSize = files.reduce((sum, f) => sum + f.size, 0);
|
|
42
|
+
const fileTokens = Math.ceil(totalFileSize / CHARS_PER_TOKEN);
|
|
43
|
+
// Cap at max batch size
|
|
44
|
+
const effectiveFileTokens = Math.min(fileTokens, maxCharsPerBatch / CHARS_PER_TOKEN);
|
|
45
|
+
for (const type of analysisTypes) {
|
|
46
|
+
// Input: prompt + context + files
|
|
47
|
+
const promptTokens = PROMPT_TOKENS_BY_TYPE[type];
|
|
48
|
+
const contextTokens = 200; // Estimated context size
|
|
49
|
+
const typeInputTokens = promptTokens + contextTokens + (effectiveFileTokens / analysisTypes.length);
|
|
50
|
+
// Output: estimated response size
|
|
51
|
+
const typeOutputTokens = OUTPUT_TOKENS_BY_TYPE[type];
|
|
52
|
+
breakdown[type] = Math.ceil(typeInputTokens + typeOutputTokens);
|
|
53
|
+
totalInputTokens += typeInputTokens;
|
|
54
|
+
totalOutputTokens += typeOutputTokens;
|
|
55
|
+
}
|
|
56
|
+
const inputCost = (totalInputTokens / 1_000_000) * PRICE_PER_1M_INPUT_TOKENS;
|
|
57
|
+
const outputCost = (totalOutputTokens / 1_000_000) * PRICE_PER_1M_OUTPUT_TOKENS;
|
|
58
|
+
const totalCost = inputCost + outputCost;
|
|
59
|
+
const totalTokens = totalInputTokens + totalOutputTokens;
|
|
60
|
+
let warning;
|
|
61
|
+
if (totalCost > 0.10) {
|
|
62
|
+
warning = `โ ๏ธ High cost estimate: $${totalCost.toFixed(4)}. Consider using --diff mode.`;
|
|
63
|
+
}
|
|
64
|
+
if (totalTokens > 100000) {
|
|
65
|
+
warning = `โ ๏ธ High token usage: ${(totalTokens / 1000).toFixed(1)}k tokens. Consider using --diff mode.`;
|
|
66
|
+
}
|
|
67
|
+
return {
|
|
68
|
+
inputTokens: Math.ceil(totalInputTokens),
|
|
69
|
+
outputTokens: Math.ceil(totalOutputTokens),
|
|
70
|
+
totalTokens: Math.ceil(totalTokens),
|
|
71
|
+
estimatedCost: totalCost,
|
|
72
|
+
breakdown,
|
|
73
|
+
warning
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Format estimate for display
|
|
78
|
+
*/
|
|
79
|
+
export function formatEstimate(estimate) {
|
|
80
|
+
const lines = [
|
|
81
|
+
`๐ Token Estimate:`,
|
|
82
|
+
` Input: ~${(estimate.inputTokens / 1000).toFixed(1)}k tokens`,
|
|
83
|
+
` Output: ~${(estimate.outputTokens / 1000).toFixed(1)}k tokens`,
|
|
84
|
+
` Total: ~${(estimate.totalTokens / 1000).toFixed(1)}k tokens`,
|
|
85
|
+
` Est. Cost: $${estimate.estimatedCost.toFixed(4)}`
|
|
86
|
+
];
|
|
87
|
+
if (estimate.warning) {
|
|
88
|
+
lines.push(`\n ${estimate.warning}`);
|
|
89
|
+
}
|
|
90
|
+
return lines.join('\n');
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=token-estimator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"token-estimator.js","sourceRoot":"","sources":["../../src/utils/token-estimator.ts"],"names":[],"mappings":"AAAA;;GAEG;AAcH,4CAA4C;AAC5C,MAAM,eAAe,GAAG,CAAC,CAAC;AAE1B,iDAAiD;AACjD,MAAM,yBAAyB,GAAG,KAAK,CAAC,CAAE,6BAA6B;AACvE,MAAM,0BAA0B,GAAG,IAAI,CAAC,CAAE,6BAA6B;AAEvE,0CAA0C;AAC1C,MAAM,qBAAqB,GAA+B;IACtD,QAAQ,EAAE,GAAG;IACb,WAAW,EAAE,IAAI;IACjB,aAAa,EAAE,GAAG;IAClB,IAAI,EAAE,GAAG;IACT,OAAO,EAAE,GAAG;IACZ,QAAQ,EAAE,IAAI;CACjB,CAAC;AAEF,kCAAkC;AAClC,MAAM,qBAAqB,GAA+B;IACtD,QAAQ,EAAE,GAAG;IACb,WAAW,EAAE,GAAG;IAChB,aAAa,EAAE,GAAG;IAClB,IAAI,EAAE,GAAG;IACT,OAAO,EAAE,GAAG;IACZ,QAAQ,EAAE,GAAG;CAChB,CAAC;AAEF;;GAEG;AACH,MAAM,UAAU,cAAc,CAAC,OAA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