mirror of
https://github.com/sipeed/picoclaw.git
synced 2026-06-12 18:08:54 +00:00
6ca7311273
Add a context window usage indicator to the web chat UI and a /context slash command that works across all channels. Backend: - Add computeContextUsage() estimating history + system + tool tokens - Attach ContextUsage to outbound messages via the pico WebSocket protocol - Add /context command showing context stats as formatted text - Add EstimateSystemTokens() on ContextBuilder for system prompt estimation Frontend: - Add ContextUsageRing component (SVG ring + hover/tap popover) - Show usage percentage, token counts, and compression threshold - Hover on desktop (150ms leave delay), tap on mobile - "View Details" sends /context with 1s cooldown - i18n support (en/zh) for popover labels Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
36 lines
1.2 KiB
Go
36 lines
1.2 KiB
Go
package commands
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/sipeed/picoclaw/pkg/config"
|
|
)
|
|
|
|
// ContextStats describes current session context window usage.
|
|
type ContextStats struct {
|
|
UsedTokens int
|
|
TotalTokens int // model context window
|
|
CompressAtTokens int // compression threshold
|
|
UsedPercent int // 0-100
|
|
MessageCount int
|
|
}
|
|
|
|
// Runtime provides runtime dependencies to command handlers. It is constructed
|
|
// per-request by the agent loop so that per-request state (like session scope)
|
|
// can coexist with long-lived callbacks (like GetModelInfo).
|
|
type Runtime struct {
|
|
Config *config.Config
|
|
GetModelInfo func() (name, provider string)
|
|
AskSideQuestion func(ctx context.Context, question string) (string, error)
|
|
ListAgentIDs func() []string
|
|
ListDefinitions func() []Definition
|
|
ListSkillNames func() []string
|
|
GetEnabledChannels func() []string
|
|
GetActiveTurn func() any // Returning any to avoid circular dependency with agent package
|
|
GetContextStats func() *ContextStats
|
|
SwitchModel func(value string) (oldModel string, err error)
|
|
SwitchChannel func(value string) error
|
|
ClearHistory func() error
|
|
ReloadConfig func() error
|
|
}
|