refactor(agent-modal): revamped UI/UX for the agent modal (#1838)

Co-authored-by: Dax Raad <d@ironbay.co>
Co-authored-by: Dax <mail@thdxr.com>
This commit is contained in:
spoons-and-mirrors
2025-08-12 22:21:57 +02:00
committed by GitHub
parent d16ae1fc4e
commit 81583cddbd
4 changed files with 330 additions and 97 deletions

View File

@@ -16,6 +16,11 @@ type ModelUsage struct {
LastUsed time.Time `toml:"last_used"`
}
type AgentUsage struct {
AgentName string `toml:"agent_name"`
LastUsed time.Time `toml:"last_used"`
}
type AgentModel struct {
ProviderID string `toml:"provider_id"`
ModelID string `toml:"model_id"`
@@ -29,6 +34,7 @@ type State struct {
Model string `toml:"model"`
Agent string `toml:"agent"`
RecentlyUsedModels []ModelUsage `toml:"recently_used_models"`
RecentlyUsedAgents []AgentUsage `toml:"recently_used_agents"`
MessagesRight bool `toml:"messages_right"`
SplitDiff bool `toml:"split_diff"`
MessageHistory []Prompt `toml:"message_history"`
@@ -42,6 +48,7 @@ func NewState() *State {
Agent: "build",
AgentModel: make(map[string]AgentModel),
RecentlyUsedModels: make([]ModelUsage, 0),
RecentlyUsedAgents: make([]AgentUsage, 0),
MessageHistory: make([]Prompt, 0),
}
}
@@ -83,6 +90,42 @@ func (s *State) RemoveModelFromRecentlyUsed(providerID, modelID string) {
}
}
// UpdateAgentUsage updates the recently used agents list with the specified agent
func (s *State) UpdateAgentUsage(agentName string) {
now := time.Now()
// Check if this agent is already in the list
for i, usage := range s.RecentlyUsedAgents {
if usage.AgentName == agentName {
s.RecentlyUsedAgents[i].LastUsed = now
usage := s.RecentlyUsedAgents[i]
copy(s.RecentlyUsedAgents[1:i+1], s.RecentlyUsedAgents[0:i])
s.RecentlyUsedAgents[0] = usage
return
}
}
newUsage := AgentUsage{
AgentName: agentName,
LastUsed: now,
}
// Prepend to slice and limit to last 20 entries
s.RecentlyUsedAgents = append([]AgentUsage{newUsage}, s.RecentlyUsedAgents...)
if len(s.RecentlyUsedAgents) > 20 {
s.RecentlyUsedAgents = s.RecentlyUsedAgents[:20]
}
}
func (s *State) RemoveAgentFromRecentlyUsed(agentName string) {
for i, usage := range s.RecentlyUsedAgents {
if usage.AgentName == agentName {
s.RecentlyUsedAgents = append(s.RecentlyUsedAgents[:i], s.RecentlyUsedAgents[i+1:]...)
return
}
}
}
func (s *State) AddPromptToHistory(prompt Prompt) {
s.MessageHistory = append([]Prompt{prompt}, s.MessageHistory...)
if len(s.MessageHistory) > 50 {