feat: support ZAI token metadata, trigger compaction on idle sessions, add GLM system prompt #4710
+125
−33
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.
Summary
Fix token extraction for ZAI/Anthropic API, improve auto-compaction timing for idle sessions, and add dedicated system prompt for GLM-4.6 model.
Changes
Token Extraction Fix (
session/index.ts)metadata.anthropic.usageinstead of the top-levelusageobject, causing the sidebar to show 0 tokens.metadata.anthropic.usagewhen top-level values are missing/zero.inputTokens) and snake_case (input_tokens) field names.Compaction Timing Fix (
session/prompt.ts)hasPendingCompactionguard to prevent infinite loops when a compaction task is already queued.GLM System Prompt (
session/prompt/glm.txt)Added a dedicated system prompt optimized for GLM-4.6's capabilities:
anthropic.txtfor maintainability.Testing