summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorKujtim Hoxha <[email protected]>2025-04-20 15:56:36 +0200
committerKujtim Hoxha <[email protected]>2025-04-21 13:42:29 +0200
commit8e160488ff1aa29f6b2cb601145e9f3ff5410d07 (patch)
tree46138a414360ca73be3bb98c24597eebb90d695f
parent2de51274177432b559be3b7deb1f14b9539f2994 (diff)
downloadopencode-8e160488ff1aa29f6b2cb601145e9f3ff5410d07.tar.gz
opencode-8e160488ff1aa29f6b2cb601145e9f3ff5410d07.zip
improve cache
-rw-r--r--internal/llm/provider/anthropic.go13
-rw-r--r--internal/tui/components/dialog/permission.go7
2 files changed, 13 insertions, 7 deletions
diff --git a/internal/llm/provider/anthropic.go b/internal/llm/provider/anthropic.go
index 2c16a0593..86f483f64 100644
--- a/internal/llm/provider/anthropic.go
+++ b/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)
}
diff --git a/internal/tui/components/dialog/permission.go b/internal/tui/components/dialog/permission.go
index 1f8df21a0..16b63815c 100644
--- a/internal/tui/components/dialog/permission.go
+++ b/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 {