Skip to content
This repository was archived by the owner on Sep 18, 2025. It is now read-only.

Commit 8e16048

Browse files
committed
improve cache
1 parent 2de5127 commit 8e16048

2 files changed

Lines changed: 13 additions & 7 deletions

File tree

internal/llm/provider/anthropic.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,28 +57,29 @@ func newAnthropicClient(opts providerClientOptions) AnthropicClient {
5757
}
5858

5959
func (a *anthropicClient) convertMessages(messages []message.Message) (anthropicMessages []anthropic.MessageParam) {
60-
cachedBlocks := 0
61-
for _, msg := range messages {
60+
for i, msg := range messages {
61+
cache := false
62+
if len(messages)-3 > i {
63+
cache = true
64+
}
6265
switch msg.Role {
6366
case message.User:
6467
content := anthropic.NewTextBlock(msg.Content().String())
65-
if cachedBlocks < 2 && !a.options.disableCache {
68+
if cache && !a.options.disableCache {
6669
content.OfRequestTextBlock.CacheControl = anthropic.CacheControlEphemeralParam{
6770
Type: "ephemeral",
6871
}
69-
cachedBlocks++
7072
}
7173
anthropicMessages = append(anthropicMessages, anthropic.NewUserMessage(content))
7274

7375
case message.Assistant:
7476
blocks := []anthropic.ContentBlockParamUnion{}
7577
if msg.Content().String() != "" {
7678
content := anthropic.NewTextBlock(msg.Content().String())
77-
if cachedBlocks < 2 && !a.options.disableCache {
79+
if cache && !a.options.disableCache {
7880
content.OfRequestTextBlock.CacheControl = anthropic.CacheControlEphemeralParam{
7981
Type: "ephemeral",
8082
}
81-
cachedBlocks++
8283
}
8384
blocks = append(blocks, content)
8485
}

internal/tui/components/dialog/permission.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,13 +375,18 @@ func (p *permissionDialogCmp) render() string {
375375
contentFinal = p.renderDefaultContent()
376376
}
377377

378+
// Add help text
379+
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")
380+
378381
content := lipgloss.JoinVertical(
379382
lipgloss.Top,
380383
title,
381384
styles.BaseStyle.Render(strings.Repeat(" ", lipgloss.Width(title))),
382385
headerContent,
383386
contentFinal,
384387
buttons,
388+
styles.BaseStyle.Render(strings.Repeat(" ", p.width - 4)),
389+
helpText,
385390
)
386391

387392
return styles.BaseStyle.
@@ -401,7 +406,7 @@ func (p *permissionDialogCmp) View() string {
401406
}
402407

403408
func (p *permissionDialogCmp) BindingKeys() []key.Binding {
404-
return layout.KeyMapToSlice(helpKeys)
409+
return layout.KeyMapToSlice(permissionsKeys)
405410
}
406411

407412
func (p *permissionDialogCmp) SetSize() tea.Cmd {

0 commit comments

Comments
 (0)