Skip to content

feat(desktop): Display stored totals for Tokens and Cost in Desktop Session Context#28887

Open
OpeOginni wants to merge 2 commits into
anomalyco:devfrom
OpeOginni:fix/desktop-session-totals-fetch
Open

feat(desktop): Display stored totals for Tokens and Cost in Desktop Session Context#28887
OpeOginni wants to merge 2 commits into
anomalyco:devfrom
OpeOginni:fix/desktop-session-totals-fetch

Conversation

@OpeOginni
Copy link
Copy Markdown
Contributor

Issue for this PR

Closes #28836

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Problem
Session cost and token totals were computed from loaded messages only, so they changed when scrolling up to load older messages.

Solution
Use the stored session totals (session.cost and session.tokens) already provided by the server.

  • SessionContextUsage and SessionContextTab now read cost and token totals from info()?.cost / info()?.tokens
  • session-context-metrics.ts simplified: getSessionContext() now only computes context-window usage from the latest assistant message
  • Removed cumulative token/cost calculation from loaded messages
  • Updated tests

Issues is that we don't have nice server side storage for data such as the total messages in a session, so this is currently still using the total rendered messages for its calculation.

How did you verify your code works?

Ran the dev desktop with a large session and this had the complete cost and tokens, without needing me to scroll all the way to load in new messages.

Screenshots / recordings

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@OpeOginni
Copy link
Copy Markdown
Contributor Author

Would need to think of having a sort of COUNT query to get the number of total messages, including user and assistant messages.

But this is a server side thing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Total cost changes based on loaded messages in a session in the Desktop App

1 participant