on main help sign in
improve cache
commit8e160488ff1aa29f6b2cb601145e9f3ff5410d07 authorKujtim Hoxha <kujtimii.h@gmail.com> dateSun 20 Apr 2025, 15:56 (2 years ago) parent2de5127
2 files changed+13−7
internal/llm/provider/anthropic.go+7−6 internal/tui/components/dialog/permission.go+6−1
internal/llm/provider/anthropic.go+7−6
@@ -57,16 +57,18 @@ func newAnthropicClient(opts providerClientOptions) AnthropicClient {
5757}
5858
5959func (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
@@ -74,11 +76,10 @@ func (a *anthropicClient) convertMessages(messages []message.Message) (anthropic
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+6−1
@@ -375,6 +375,9 @@ 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,
@@ -382,6 +385,8 @@ func (p *permissionDialogCmp) render() string {
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
403408func (p *permissionDialogCmp) BindingKeys() []key.Binding {
404− return layout.KeyMapToSlice(helpKeys)
409+ return layout.KeyMapToSlice(permissionsKeys)
405410}
406411
407412func (p *permissionDialogCmp) SetSize() tea.Cmd {