summaryrefslogtreecommitdiffhomepage
path: root/packages/tui/internal/components/chat/cache.go
diff options
context:
space:
mode:
authoradamdottv <[email protected]>2025-06-05 15:44:20 -0500
committeradamdottv <[email protected]>2025-06-11 11:43:28 -0500
commit95d5e1f2318e0c62f19196122fc2a448f1114cfd (patch)
tree75369872d32e10896e9263ddbf32cf36e7e418ac /packages/tui/internal/components/chat/cache.go
parent979bad3e64e3fff43d41094a79c73deb31e82ec8 (diff)
downloadopencode-95d5e1f2318e0c62f19196122fc2a448f1114cfd.tar.gz
opencode-95d5e1f2318e0c62f19196122fc2a448f1114cfd.zip
wip: refactoring tui
Diffstat (limited to 'packages/tui/internal/components/chat/cache.go')
-rw-r--r--packages/tui/internal/components/chat/cache.go36
1 files changed, 5 insertions, 31 deletions
diff --git a/packages/tui/internal/components/chat/cache.go b/packages/tui/internal/components/chat/cache.go
index 5219e7092..1586c2cc3 100644
--- a/packages/tui/internal/components/chat/cache.go
+++ b/packages/tui/internal/components/chat/cache.go
@@ -5,8 +5,6 @@ import (
"encoding/hex"
"fmt"
"sync"
-
- "github.com/sst/opencode/pkg/client"
)
// MessageCache caches rendered messages to avoid re-rendering
@@ -23,51 +21,27 @@ func NewMessageCache() *MessageCache {
}
// generateKey creates a unique key for a message based on its content and rendering parameters
-func (c *MessageCache) generateKey(msg client.MessageInfo, width int, showToolMessages bool, appInfo client.AppInfo) string {
- // Create a hash of the message content and rendering parameters
+func (c *MessageCache) GenerateKey(params ...any) string {
h := sha256.New()
-
- // Include message ID and role
- h.Write(fmt.Appendf(nil, "%s:%s", msg.Id, msg.Role))
-
- // Include timestamp
- h.Write(fmt.Appendf(nil, ":%f", msg.Metadata.Time.Created))
-
- // Include width and showToolMessages flag
- h.Write(fmt.Appendf(nil, ":%d:%t", width, showToolMessages))
-
- // Include app path for relative path calculations
- h.Write([]byte(appInfo.Path.Root))
-
- // Include message parts
- for _, part := range msg.Parts {
- h.Write(fmt.Appendf(nil, ":%v", part))
- }
-
- // Include tool metadata if present
- for toolID, metadata := range msg.Metadata.Tool {
- h.Write(fmt.Appendf(nil, ":%s:%v", toolID, metadata))
+ for _, param := range params {
+ h.Write(fmt.Appendf(nil, ":%v", param))
}
-
return hex.EncodeToString(h.Sum(nil))
}
// Get retrieves a cached rendered message
-func (c *MessageCache) Get(msg client.MessageInfo, width int, showToolMessages bool, appInfo client.AppInfo) (string, bool) {
+func (c *MessageCache) Get(key string) (string, bool) {
c.mu.RLock()
defer c.mu.RUnlock()
- key := c.generateKey(msg, width, showToolMessages, appInfo)
content, exists := c.cache[key]
return content, exists
}
// Set stores a rendered message in the cache
-func (c *MessageCache) Set(msg client.MessageInfo, width int, showToolMessages bool, appInfo client.AppInfo, content string) {
+func (c *MessageCache) Set(key string, content string) {
c.mu.Lock()
defer c.mu.Unlock()
-
- key := c.generateKey(msg, width, showToolMessages, appInfo)
c.cache[key] = content
}