fix issues with token counting #33
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What does this PR do?
This pull request introduces enhancements to token counting functionality, updates the user interface for better token count display, and includes a version bump for the package. Key changes focus on improving token management in the agent, refining the UI, and adding a utility function for formatting token counts.
Token management improvements:
src/agent/grok-agent.ts
: Updated real-time token counting to include tool calls and added a final token count update after processing all tool calls. This ensures more accurate token tracking during streaming and tool interactions. [1] [2]src/agent/grok-agent.ts
: Changedconst
tolet
forinputTokens
to allow updates after processing tool calls.UI enhancements:
src/ui/components/loading-spinner.tsx
: Integrated the newformatTokenCount
utility to display token counts in a user-friendly format (e.g., "1.2k" for 1200 tokens). [1] [2]Utility function addition:
src/utils/token-counter.ts
: AddedformatTokenCount
function to format token counts for display, supporting compact representations like "k" for thousands and "m" for millions.Version update:
package.json
: Bumped the package version from0.0.5
to0.0.6
.Fixes #2
Checklist