summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authoradamdottv <[email protected]>2025-05-02 10:21:34 -0500
committerAdam <[email protected]>2025-05-02 15:24:47 -0500
commitf004a0b8c3a0babe96dea65ad2a524d6b446fd71 (patch)
treee1dcec37a20d9a14c9d2271f64cbdef3305a32a8
parent49423da081d6fdffb0bd7275e070a2edeb28e3b5 (diff)
downloadopencode-f004a0b8c3a0babe96dea65ad2a524d6b446fd71.tar.gz
opencode-f004a0b8c3a0babe96dea65ad2a524d6b446fd71.zip
fix: anthropic non-empty blocks
-rw-r--r--internal/llm/provider/anthropic.go21
-rw-r--r--internal/message/content.go11
2 files changed, 20 insertions, 12 deletions
diff --git a/internal/llm/provider/anthropic.go b/internal/llm/provider/anthropic.go
index fc131d348..a96fe83ee 100644
--- a/internal/llm/provider/anthropic.go
+++ b/internal/llm/provider/anthropic.go
@@ -74,14 +74,19 @@ func (a *anthropicClient) convertMessages(messages []message.Message) (anthropic
case message.Assistant:
blocks := []anthropic.ContentBlockParamUnion{}
- if msg.Content().String() != "" {
- content := anthropic.NewTextBlock(msg.Content().String())
+
+ if msg.Content() != nil {
+ content := msg.Content().String()
+ if strings.TrimSpace(content) == "" {
+ content = " "
+ }
+ block := anthropic.NewTextBlock(content)
if cache && !a.options.disableCache {
- content.OfRequestTextBlock.CacheControl = anthropic.CacheControlEphemeralParam{
+ block.OfRequestTextBlock.CacheControl = anthropic.CacheControlEphemeralParam{
Type: "ephemeral",
}
}
- blocks = append(blocks, content)
+ blocks = append(blocks, block)
}
for _, toolCall := range msg.ToolCalls() {
@@ -196,8 +201,8 @@ func (a *anthropicClient) send(ctx context.Context, messages []message.Message,
preparedMessages := a.preparedMessages(a.convertMessages(messages), a.convertTools(tools))
cfg := config.Get()
if cfg.Debug {
- // jsonData, _ := json.Marshal(preparedMessages)
- // logging.Debug("Prepared messages", "messages", string(jsonData))
+ jsonData, _ := json.Marshal(preparedMessages)
+ logging.Debug("Prepared messages", "messages", string(jsonData))
}
attempts := 0
for {
@@ -243,8 +248,8 @@ func (a *anthropicClient) stream(ctx context.Context, messages []message.Message
preparedMessages := a.preparedMessages(a.convertMessages(messages), a.convertTools(tools))
cfg := config.Get()
if cfg.Debug {
- // jsonData, _ := json.Marshal(preparedMessages)
- // logging.Debug("Prepared messages", "messages", string(jsonData))
+ jsonData, _ := json.Marshal(preparedMessages)
+ logging.Debug("Prepared messages", "messages", string(jsonData))
}
attempts := 0
eventChan := make(chan ProviderEvent)
diff --git a/internal/message/content.go b/internal/message/content.go
index 1ea2bccaa..c42154cfd 100644
--- a/internal/message/content.go
+++ b/internal/message/content.go
@@ -48,7 +48,10 @@ type TextContent struct {
Text string `json:"text"`
}
-func (tc TextContent) String() string {
+func (tc *TextContent) String() string {
+ if tc == nil {
+ return ""
+ }
return tc.Text
}
@@ -115,13 +118,13 @@ type Message struct {
UpdatedAt int64
}
-func (m *Message) Content() TextContent {
+func (m *Message) Content() *TextContent {
for _, part := range m.Parts {
if c, ok := part.(TextContent); ok {
- return c
+ return &c
}
}
- return TextContent{}
+ return nil
}
func (m *Message) ReasoningContent() ReasoningContent {