improve cache

Kujtim Hoxha created

Change summary

internal/llm/provider/anthropic.go           | 13 +++++++------
internal/tui/components/dialog/permission.go |  7 ++++++-
2 files changed, 13 insertions(+), 7 deletions(-)

Detailed changes

internal/llm/provider/anthropic.go 🔗

@@ -57,16 +57,18 @@ func newAnthropicClient(opts providerClientOptions) AnthropicClient {
 }
 
 func (a *anthropicClient) convertMessages(messages []message.Message) (anthropicMessages []anthropic.MessageParam) {
-	cachedBlocks := 0
-	for _, msg := range messages {
+	for i, msg := range messages {
+		cache := false
+		if len(messages)-3 > i {
+			cache = true
+		}
 		switch msg.Role {
 		case message.User:
 			content := anthropic.NewTextBlock(msg.Content().String())
-			if cachedBlocks < 2 && !a.options.disableCache {
+			if cache && !a.options.disableCache {
 				content.OfRequestTextBlock.CacheControl = anthropic.CacheControlEphemeralParam{
 					Type: "ephemeral",
 				}
-				cachedBlocks++
 			}
 			anthropicMessages = append(anthropicMessages, anthropic.NewUserMessage(content))
 
@@ -74,11 +76,10 @@ func (a *anthropicClient) convertMessages(messages []message.Message) (anthropic
 			blocks := []anthropic.ContentBlockParamUnion{}
 			if msg.Content().String() != "" {
 				content := anthropic.NewTextBlock(msg.Content().String())
-				if cachedBlocks < 2 && !a.options.disableCache {
+				if cache && !a.options.disableCache {
 					content.OfRequestTextBlock.CacheControl = anthropic.CacheControlEphemeralParam{
 						Type: "ephemeral",
 					}
-					cachedBlocks++
 				}
 				blocks = append(blocks, content)
 			}

internal/tui/components/dialog/permission.go 🔗

@@ -375,6 +375,9 @@ func (p *permissionDialogCmp) render() string {
 		contentFinal = p.renderDefaultContent()
 	}
 
+	// Add help text
+	helpText := styles.BaseStyle.Width(p.width - 4).Padding(0, 1).Foreground(styles.ForgroundDim).Render("←/→/tab: switch options  a: allow  A: allow for session  d: deny  enter/space: confirm")
+	
 	content := lipgloss.JoinVertical(
 		lipgloss.Top,
 		title,
@@ -382,6 +385,8 @@ func (p *permissionDialogCmp) render() string {
 		headerContent,
 		contentFinal,
 		buttons,
+		styles.BaseStyle.Render(strings.Repeat(" ", p.width - 4)),
+		helpText,
 	)
 
 	return styles.BaseStyle.
@@ -401,7 +406,7 @@ func (p *permissionDialogCmp) View() string {
 }
 
 func (p *permissionDialogCmp) BindingKeys() []key.Binding {
-	return layout.KeyMapToSlice(helpKeys)
+	return layout.KeyMapToSlice(permissionsKeys)
 }
 
 func (p *permissionDialogCmp) SetSize() tea.Cmd {