@defai.digital/ax-cli 2.7.0 → 3.0.0
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/.ax-cli/checkpoints/2025-11-20/checkpoint-2dd84869-e62d-46c8-9885-7e45f37f36e2.json +69 -0
- package/.ax-cli/checkpoints/2025-11-20/checkpoint-484dc350-353f-4808-9ed1-ebb3cefdab37.json +24 -0
- package/.ax-cli/checkpoints/2025-11-20/checkpoint-74a18b87-6172-4215-962b-44bb9f46a662.json +69 -0
- package/.ax-cli/checkpoints/2025-11-20/checkpoint-870a5fb9-6e82-4ff2-8ec8-af4c251cc514.json +44 -0
- package/.ax-cli/checkpoints/2025-11-20/checkpoint-93946601-0e83-456c-ba47-def9713124dd.json +24 -0
- package/.ax-cli/checkpoints/metadata.json +62 -0
- package/README.md +87 -11
- package/dist/agent/context-manager.d.ts +2 -2
- package/dist/agent/context-manager.js +37 -15
- package/dist/agent/context-manager.js.map +1 -1
- package/dist/agent/dependency-resolver.d.ts +83 -0
- package/dist/agent/dependency-resolver.js +310 -0
- package/dist/agent/dependency-resolver.js.map +1 -0
- package/dist/agent/llm-agent.d.ts +111 -0
- package/dist/agent/llm-agent.js +625 -3
- package/dist/agent/llm-agent.js.map +1 -1
- package/dist/agent/specialized/analysis-agent.d.ts +11 -0
- package/dist/agent/specialized/analysis-agent.js +33 -0
- package/dist/agent/specialized/analysis-agent.js.map +1 -0
- package/dist/agent/specialized/debug-agent.d.ts +11 -0
- package/dist/agent/specialized/debug-agent.js +33 -0
- package/dist/agent/specialized/debug-agent.js.map +1 -0
- package/dist/agent/specialized/documentation-agent.d.ts +11 -0
- package/dist/agent/specialized/documentation-agent.js +33 -0
- package/dist/agent/specialized/documentation-agent.js.map +1 -0
- package/dist/agent/specialized/index.d.ts +11 -0
- package/dist/agent/specialized/index.js +12 -0
- package/dist/agent/specialized/index.js.map +1 -0
- package/dist/agent/specialized/performance-agent.d.ts +11 -0
- package/dist/agent/specialized/performance-agent.js +33 -0
- package/dist/agent/specialized/performance-agent.js.map +1 -0
- package/dist/agent/specialized/refactoring-agent.d.ts +11 -0
- package/dist/agent/specialized/refactoring-agent.js +33 -0
- package/dist/agent/specialized/refactoring-agent.js.map +1 -0
- package/dist/agent/specialized/testing-agent.d.ts +11 -0
- package/dist/agent/specialized/testing-agent.js +33 -0
- package/dist/agent/specialized/testing-agent.js.map +1 -0
- package/dist/agent/subagent-orchestrator.d.ts +128 -0
- package/dist/agent/subagent-orchestrator.js +388 -0
- package/dist/agent/subagent-orchestrator.js.map +1 -0
- package/dist/agent/subagent-types.d.ts +262 -0
- package/dist/agent/subagent-types.js +152 -0
- package/dist/agent/subagent-types.js.map +1 -0
- package/dist/agent/subagent.d.ts +88 -0
- package/dist/agent/subagent.js +426 -0
- package/dist/agent/subagent.js.map +1 -0
- package/dist/checkpoint/index.d.ts +9 -0
- package/dist/checkpoint/index.js +11 -0
- package/dist/checkpoint/index.js.map +1 -0
- package/dist/checkpoint/manager.d.ts +99 -0
- package/dist/checkpoint/manager.js +281 -0
- package/dist/checkpoint/manager.js.map +1 -0
- package/dist/checkpoint/storage.d.ts +31 -0
- package/dist/checkpoint/storage.js +265 -0
- package/dist/checkpoint/storage.js.map +1 -0
- package/dist/checkpoint/types.d.ts +111 -0
- package/dist/checkpoint/types.js +17 -0
- package/dist/checkpoint/types.js.map +1 -0
- package/dist/commands/cache.js +5 -3
- package/dist/commands/cache.js.map +1 -1
- package/dist/commands/memory.js +21 -16
- package/dist/commands/memory.js.map +1 -1
- package/dist/commands/plan.d.ts +43 -0
- package/dist/commands/plan.js +385 -0
- package/dist/commands/plan.js.map +1 -0
- package/dist/commands/rewind.d.ts +19 -0
- package/dist/commands/rewind.js +221 -0
- package/dist/commands/rewind.js.map +1 -0
- package/dist/constants.d.ts +28 -0
- package/dist/constants.js +29 -0
- package/dist/constants.js.map +1 -1
- package/dist/hooks/use-enhanced-input.d.ts +5 -1
- package/dist/hooks/use-enhanced-input.js +23 -10
- package/dist/hooks/use-enhanced-input.js.map +1 -1
- package/dist/hooks/use-input-handler.d.ts +11 -1
- package/dist/hooks/use-input-handler.js +294 -2
- package/dist/hooks/use-input-handler.js.map +1 -1
- package/dist/llm/client.js +2 -1
- package/dist/llm/client.js.map +1 -1
- package/dist/llm/tools.d.ts +5 -0
- package/dist/llm/tools.js +57 -6
- package/dist/llm/tools.js.map +1 -1
- package/dist/mcp/client.d.ts +1 -0
- package/dist/mcp/client.js +30 -8
- package/dist/mcp/client.js.map +1 -1
- package/dist/mcp/transports.d.ts +0 -1
- package/dist/mcp/transports.js +10 -7
- package/dist/mcp/transports.js.map +1 -1
- package/dist/planner/dependency-resolver.d.ts +72 -0
- package/dist/planner/dependency-resolver.js +272 -0
- package/dist/planner/dependency-resolver.js.map +1 -0
- package/dist/planner/index.d.ts +12 -0
- package/dist/planner/index.js +26 -0
- package/dist/planner/index.js.map +1 -0
- package/dist/planner/plan-generator.d.ts +74 -0
- package/dist/planner/plan-generator.js +244 -0
- package/dist/planner/plan-generator.js.map +1 -0
- package/dist/planner/plan-storage.d.ts +98 -0
- package/dist/planner/plan-storage.js +325 -0
- package/dist/planner/plan-storage.js.map +1 -0
- package/dist/planner/prompts/planning-prompt.d.ts +41 -0
- package/dist/planner/prompts/planning-prompt.js +289 -0
- package/dist/planner/prompts/planning-prompt.js.map +1 -0
- package/dist/planner/task-planner.d.ts +135 -0
- package/dist/planner/task-planner.js +493 -0
- package/dist/planner/task-planner.js.map +1 -0
- package/dist/planner/token-estimator.d.ts +63 -0
- package/dist/planner/token-estimator.js +295 -0
- package/dist/planner/token-estimator.js.map +1 -0
- package/dist/planner/types.d.ts +669 -0
- package/dist/planner/types.js +213 -0
- package/dist/planner/types.js.map +1 -0
- package/dist/schemas/api-schemas.js +4 -0
- package/dist/schemas/api-schemas.js.map +1 -1
- package/dist/schemas/confirmation-schemas.d.ts +5 -0
- package/dist/schemas/confirmation-schemas.js +7 -0
- package/dist/schemas/confirmation-schemas.js.map +1 -1
- package/dist/schemas/index.d.ts +4 -4
- package/dist/tools/bash-output.d.ts +25 -0
- package/dist/tools/bash-output.js +145 -0
- package/dist/tools/bash-output.js.map +1 -0
- package/dist/tools/bash.d.ts +46 -2
- package/dist/tools/bash.js +241 -42
- package/dist/tools/bash.js.map +1 -1
- package/dist/tools/search.js +34 -9
- package/dist/tools/search.js.map +1 -1
- package/dist/tools/text-editor.d.ts +16 -0
- package/dist/tools/text-editor.js +37 -2
- package/dist/tools/text-editor.js.map +1 -1
- package/dist/ui/components/chat-history.d.ts +1 -0
- package/dist/ui/components/chat-history.js +125 -41
- package/dist/ui/components/chat-history.js.map +1 -1
- package/dist/ui/components/chat-input.js +10 -3
- package/dist/ui/components/chat-input.js.map +1 -1
- package/dist/ui/components/chat-interface.js +154 -45
- package/dist/ui/components/chat-interface.js.map +1 -1
- package/dist/ui/components/collapsible-tool-result.d.ts +26 -0
- package/dist/ui/components/collapsible-tool-result.js +172 -0
- package/dist/ui/components/collapsible-tool-result.js.map +1 -0
- package/dist/ui/components/command-suggestions.js +2 -1
- package/dist/ui/components/command-suggestions.js.map +1 -1
- package/dist/ui/components/confirmation-dialog.js +25 -36
- package/dist/ui/components/confirmation-dialog.js.map +1 -1
- package/dist/ui/components/index.d.ts +8 -0
- package/dist/ui/components/index.js +9 -0
- package/dist/ui/components/index.js.map +1 -1
- package/dist/ui/components/keyboard-hints.d.ts +35 -0
- package/dist/ui/components/keyboard-hints.js +134 -0
- package/dist/ui/components/keyboard-hints.js.map +1 -0
- package/dist/ui/components/loading-spinner.d.ts +2 -1
- package/dist/ui/components/loading-spinner.js +86 -34
- package/dist/ui/components/loading-spinner.js.map +1 -1
- package/dist/ui/components/phase-progress.d.ts +21 -0
- package/dist/ui/components/phase-progress.js +228 -0
- package/dist/ui/components/phase-progress.js.map +1 -0
- package/dist/ui/components/quick-actions.d.ts +12 -0
- package/dist/ui/components/quick-actions.js +122 -0
- package/dist/ui/components/quick-actions.js.map +1 -0
- package/dist/ui/components/reasoning-display.d.ts +0 -80
- package/dist/ui/components/reasoning-display.js +0 -83
- package/dist/ui/components/reasoning-display.js.map +1 -1
- package/dist/ui/components/status-bar.d.ts +25 -0
- package/dist/ui/components/status-bar.js +125 -0
- package/dist/ui/components/status-bar.js.map +1 -0
- package/dist/ui/components/subagent-monitor.d.ts +29 -0
- package/dist/ui/components/subagent-monitor.js +150 -0
- package/dist/ui/components/subagent-monitor.js.map +1 -0
- package/dist/ui/components/toast-notification.d.ts +123 -0
- package/dist/ui/components/toast-notification.js +143 -0
- package/dist/ui/components/toast-notification.js.map +1 -0
- package/dist/ui/components/welcome-panel.d.ts +10 -0
- package/dist/ui/components/welcome-panel.js +107 -0
- package/dist/ui/components/welcome-panel.js.map +1 -0
- package/dist/utils/background-task-manager.d.ts +95 -0
- package/dist/utils/background-task-manager.js +330 -0
- package/dist/utils/background-task-manager.js.map +1 -0
- package/dist/utils/confirmation-service.js +8 -3
- package/dist/utils/confirmation-service.js.map +1 -1
- package/dist/utils/history-manager.d.ts +1 -0
- package/dist/utils/history-manager.js +40 -5
- package/dist/utils/history-manager.js.map +1 -1
- package/dist/utils/json-utils.d.ts +7 -0
- package/dist/utils/json-utils.js +70 -2
- package/dist/utils/json-utils.js.map +1 -1
- package/dist/utils/message-optimizer.d.ts +1 -0
- package/dist/utils/message-optimizer.js +7 -1
- package/dist/utils/message-optimizer.js.map +1 -1
- package/dist/utils/project-analyzer.js +5 -2
- package/dist/utils/project-analyzer.js.map +1 -1
- package/dist/utils/settings-manager.js +12 -10
- package/dist/utils/settings-manager.js.map +1 -1
- package/dist/utils/text-utils.js +3 -3
- package/dist/utils/text-utils.js.map +1 -1
- package/dist/utils/token-counter.d.ts +5 -0
- package/dist/utils/token-counter.js +18 -3
- package/dist/utils/token-counter.js.map +1 -1
- package/package.json +3 -1
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Token Estimator
|
|
3
|
+
*
|
|
4
|
+
* Estimates token usage for phases and plans.
|
|
5
|
+
* Uses heuristics based on objectives and tools.
|
|
6
|
+
*/
|
|
7
|
+
import { RiskLevel } from "./types.js";
|
|
8
|
+
// ============================================================================
|
|
9
|
+
// Constants
|
|
10
|
+
// ============================================================================
|
|
11
|
+
/**
|
|
12
|
+
* Base token costs per tool type
|
|
13
|
+
*/
|
|
14
|
+
const TOOL_TOKEN_COSTS = {
|
|
15
|
+
// File operations
|
|
16
|
+
view_file: 500,
|
|
17
|
+
str_replace_editor: 800,
|
|
18
|
+
text_editor: 800,
|
|
19
|
+
write_file: 600,
|
|
20
|
+
// Search
|
|
21
|
+
search: 400,
|
|
22
|
+
grep: 300,
|
|
23
|
+
find: 200,
|
|
24
|
+
// Shell
|
|
25
|
+
bash: 1000,
|
|
26
|
+
execute_command: 1000,
|
|
27
|
+
// Navigation
|
|
28
|
+
list_directory: 200,
|
|
29
|
+
read_file: 500,
|
|
30
|
+
// Analysis
|
|
31
|
+
analyze: 1500,
|
|
32
|
+
understand: 1200,
|
|
33
|
+
// Testing
|
|
34
|
+
test: 2000,
|
|
35
|
+
run_tests: 2000,
|
|
36
|
+
// Documentation
|
|
37
|
+
document: 1500,
|
|
38
|
+
write_docs: 1500,
|
|
39
|
+
// Default for unknown tools
|
|
40
|
+
default: 500,
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Complexity multipliers
|
|
44
|
+
*/
|
|
45
|
+
const COMPLEXITY_MULTIPLIERS = {
|
|
46
|
+
simple: 1.0,
|
|
47
|
+
moderate: 1.5,
|
|
48
|
+
complex: 2.5,
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Objective complexity indicators (keywords that increase estimates)
|
|
52
|
+
*/
|
|
53
|
+
const COMPLEX_OBJECTIVE_KEYWORDS = [
|
|
54
|
+
"refactor",
|
|
55
|
+
"rewrite",
|
|
56
|
+
"migrate",
|
|
57
|
+
"implement",
|
|
58
|
+
"create",
|
|
59
|
+
"design",
|
|
60
|
+
"optimize",
|
|
61
|
+
"integrate",
|
|
62
|
+
"test",
|
|
63
|
+
"comprehensive",
|
|
64
|
+
"full",
|
|
65
|
+
"entire",
|
|
66
|
+
"all",
|
|
67
|
+
];
|
|
68
|
+
/**
|
|
69
|
+
* Simple objective keywords (decrease estimates)
|
|
70
|
+
*/
|
|
71
|
+
const SIMPLE_OBJECTIVE_KEYWORDS = [
|
|
72
|
+
"read",
|
|
73
|
+
"view",
|
|
74
|
+
"check",
|
|
75
|
+
"list",
|
|
76
|
+
"find",
|
|
77
|
+
"locate",
|
|
78
|
+
"identify",
|
|
79
|
+
"examine",
|
|
80
|
+
"review",
|
|
81
|
+
];
|
|
82
|
+
// ============================================================================
|
|
83
|
+
// Token Estimator Class
|
|
84
|
+
// ============================================================================
|
|
85
|
+
export class TokenEstimator {
|
|
86
|
+
baseTokensPerPhase;
|
|
87
|
+
tokensPerObjective;
|
|
88
|
+
constructor(options) {
|
|
89
|
+
this.baseTokensPerPhase = options?.baseTokensPerPhase || 2000;
|
|
90
|
+
this.tokensPerObjective = options?.tokensPerObjective || 500;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Estimate tokens for a single phase
|
|
94
|
+
*/
|
|
95
|
+
estimatePhase(phase) {
|
|
96
|
+
let estimate = this.baseTokensPerPhase;
|
|
97
|
+
// Add tokens for each objective
|
|
98
|
+
for (const objective of phase.objectives) {
|
|
99
|
+
let objectiveTokens = this.tokensPerObjective;
|
|
100
|
+
// Adjust based on objective complexity
|
|
101
|
+
const lowerObjective = objective.toLowerCase();
|
|
102
|
+
if (COMPLEX_OBJECTIVE_KEYWORDS.some((kw) => lowerObjective.includes(kw))) {
|
|
103
|
+
objectiveTokens *= 1.5;
|
|
104
|
+
}
|
|
105
|
+
else if (SIMPLE_OBJECTIVE_KEYWORDS.some((kw) => lowerObjective.includes(kw))) {
|
|
106
|
+
objectiveTokens *= 0.7;
|
|
107
|
+
}
|
|
108
|
+
estimate += objectiveTokens;
|
|
109
|
+
}
|
|
110
|
+
// Add tokens for each required tool
|
|
111
|
+
for (const tool of phase.toolsRequired) {
|
|
112
|
+
const toolCost = TOOL_TOKEN_COSTS[tool] || TOOL_TOKEN_COSTS.default;
|
|
113
|
+
estimate += toolCost;
|
|
114
|
+
}
|
|
115
|
+
// Multiply by risk level
|
|
116
|
+
switch (phase.riskLevel) {
|
|
117
|
+
case RiskLevel.HIGH:
|
|
118
|
+
estimate *= 1.3; // Higher risk = more validation/care
|
|
119
|
+
break;
|
|
120
|
+
case RiskLevel.MEDIUM:
|
|
121
|
+
estimate *= 1.1;
|
|
122
|
+
break;
|
|
123
|
+
case RiskLevel.LOW:
|
|
124
|
+
default:
|
|
125
|
+
break;
|
|
126
|
+
}
|
|
127
|
+
return Math.round(estimate);
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Estimate tokens for an entire plan
|
|
131
|
+
*/
|
|
132
|
+
estimatePlan(plan) {
|
|
133
|
+
let total = 0;
|
|
134
|
+
for (const phase of plan.phases) {
|
|
135
|
+
total += this.estimatePhase(phase);
|
|
136
|
+
}
|
|
137
|
+
// Apply complexity multiplier
|
|
138
|
+
const multiplier = COMPLEXITY_MULTIPLIERS[plan.complexity] ||
|
|
139
|
+
COMPLEXITY_MULTIPLIERS.moderate;
|
|
140
|
+
// Add overhead for plan coordination
|
|
141
|
+
const coordinationOverhead = plan.phases.length * 200;
|
|
142
|
+
return Math.round(total * multiplier + coordinationOverhead);
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Estimate tokens for an execution batch
|
|
146
|
+
*/
|
|
147
|
+
estimateBatch(batch) {
|
|
148
|
+
let total = 0;
|
|
149
|
+
for (const phase of batch.phases) {
|
|
150
|
+
total += this.estimatePhase(phase);
|
|
151
|
+
}
|
|
152
|
+
// Parallel execution has some overhead
|
|
153
|
+
if (batch.canRunInParallel && batch.phases.length > 1) {
|
|
154
|
+
total *= 1.1; // 10% overhead for coordination
|
|
155
|
+
}
|
|
156
|
+
return Math.round(total);
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Estimate duration for a phase (in milliseconds)
|
|
160
|
+
*/
|
|
161
|
+
estimatePhaseDuration(phase) {
|
|
162
|
+
const tokens = this.estimatePhase(phase);
|
|
163
|
+
// Rough estimate: 50 tokens per second processing
|
|
164
|
+
const baseTime = (tokens / 50) * 1000;
|
|
165
|
+
// Add time for tool executions
|
|
166
|
+
let toolTime = 0;
|
|
167
|
+
for (const tool of phase.toolsRequired) {
|
|
168
|
+
switch (tool) {
|
|
169
|
+
case "bash":
|
|
170
|
+
case "execute_command":
|
|
171
|
+
toolTime += 5000; // 5 seconds per bash command
|
|
172
|
+
break;
|
|
173
|
+
case "test":
|
|
174
|
+
case "run_tests":
|
|
175
|
+
toolTime += 30000; // 30 seconds for tests
|
|
176
|
+
break;
|
|
177
|
+
case "search":
|
|
178
|
+
case "grep":
|
|
179
|
+
toolTime += 2000; // 2 seconds for search
|
|
180
|
+
break;
|
|
181
|
+
default:
|
|
182
|
+
toolTime += 1000; // 1 second default
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
return Math.round(baseTime + toolTime);
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Estimate total duration for a plan
|
|
189
|
+
*/
|
|
190
|
+
estimatePlanDuration(_plan, batches) {
|
|
191
|
+
let totalDuration = 0;
|
|
192
|
+
for (const batch of batches) {
|
|
193
|
+
if (batch.canRunInParallel && batch.phases.length > 1) {
|
|
194
|
+
// Parallel: take the max duration
|
|
195
|
+
const durations = batch.phases.map((p) => this.estimatePhaseDuration(p));
|
|
196
|
+
totalDuration += Math.max(...durations);
|
|
197
|
+
}
|
|
198
|
+
else {
|
|
199
|
+
// Sequential: sum all durations
|
|
200
|
+
for (const phase of batch.phases) {
|
|
201
|
+
totalDuration += this.estimatePhaseDuration(phase);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
return totalDuration;
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Check if a plan will fit within context limits
|
|
209
|
+
*/
|
|
210
|
+
willFitInContext(plan, contextLimit) {
|
|
211
|
+
const estimatedTokens = this.estimatePlan(plan);
|
|
212
|
+
return {
|
|
213
|
+
fits: estimatedTokens < contextLimit,
|
|
214
|
+
estimatedTokens,
|
|
215
|
+
remainingTokens: contextLimit - estimatedTokens,
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Suggest phase splits if plan is too large
|
|
220
|
+
*/
|
|
221
|
+
suggestSplits(plan, contextLimit) {
|
|
222
|
+
const estimated = this.estimatePlan(plan);
|
|
223
|
+
if (estimated <= contextLimit) {
|
|
224
|
+
return { shouldSplit: false, suggestions: [] };
|
|
225
|
+
}
|
|
226
|
+
const suggestions = [];
|
|
227
|
+
// Find the largest phases
|
|
228
|
+
const phaseEstimates = plan.phases.map((p) => ({
|
|
229
|
+
phase: p,
|
|
230
|
+
tokens: this.estimatePhase(p),
|
|
231
|
+
}));
|
|
232
|
+
phaseEstimates.sort((a, b) => b.tokens - a.tokens);
|
|
233
|
+
// Suggest splitting large phases
|
|
234
|
+
for (const { phase, tokens } of phaseEstimates.slice(0, 3)) {
|
|
235
|
+
if (tokens > contextLimit * 0.3) {
|
|
236
|
+
suggestions.push(`Phase "${phase.name}" is estimated at ${tokens} tokens. ` +
|
|
237
|
+
`Consider breaking it into smaller phases.`);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
// Suggest reducing objectives
|
|
241
|
+
const totalObjectives = plan.phases.reduce((sum, p) => sum + p.objectives.length, 0);
|
|
242
|
+
if (totalObjectives > 15) {
|
|
243
|
+
suggestions.push(`Plan has ${totalObjectives} objectives. Consider reducing scope.`);
|
|
244
|
+
}
|
|
245
|
+
return { shouldSplit: true, suggestions };
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Format token estimate for display
|
|
249
|
+
*/
|
|
250
|
+
formatEstimate(tokens) {
|
|
251
|
+
if (tokens >= 1000000) {
|
|
252
|
+
return `${(tokens / 1000000).toFixed(1)}M`;
|
|
253
|
+
}
|
|
254
|
+
if (tokens >= 1000) {
|
|
255
|
+
return `${(tokens / 1000).toFixed(1)}k`;
|
|
256
|
+
}
|
|
257
|
+
return tokens.toString();
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Format duration for display
|
|
261
|
+
*/
|
|
262
|
+
formatDuration(durationMs) {
|
|
263
|
+
if (durationMs < 1000) {
|
|
264
|
+
return `${durationMs}ms`;
|
|
265
|
+
}
|
|
266
|
+
const seconds = Math.floor(durationMs / 1000);
|
|
267
|
+
if (seconds < 60) {
|
|
268
|
+
return `${seconds}s`;
|
|
269
|
+
}
|
|
270
|
+
const minutes = Math.floor(seconds / 60);
|
|
271
|
+
const remainingSeconds = seconds % 60;
|
|
272
|
+
if (minutes < 60) {
|
|
273
|
+
return remainingSeconds > 0
|
|
274
|
+
? `${minutes}m ${remainingSeconds}s`
|
|
275
|
+
: `${minutes}m`;
|
|
276
|
+
}
|
|
277
|
+
const hours = Math.floor(minutes / 60);
|
|
278
|
+
const remainingMinutes = minutes % 60;
|
|
279
|
+
return `${hours}h ${remainingMinutes}m`;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
// ============================================================================
|
|
283
|
+
// Singleton Instance
|
|
284
|
+
// ============================================================================
|
|
285
|
+
let estimatorInstance = null;
|
|
286
|
+
/**
|
|
287
|
+
* Get the singleton TokenEstimator instance
|
|
288
|
+
*/
|
|
289
|
+
export function getTokenEstimator() {
|
|
290
|
+
if (!estimatorInstance) {
|
|
291
|
+
estimatorInstance = new TokenEstimator();
|
|
292
|
+
}
|
|
293
|
+
return estimatorInstance;
|
|
294
|
+
}
|
|
295
|
+
//# sourceMappingURL=token-estimator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"token-estimator.js","sourceRoot":"","sources":["../../src/planner/token-estimator.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAuB,S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