on main help sign in
refactor: upgrade Anthropic SDK to v1.4.0 and adapt provider code
05b0570Kayvan Sylvan
README.md+2
@@ -203,6 +203,8 @@ OpenCode supports a variety of AI models from different providers:
203
203
204### Anthropic
204### Anthropic
205
205
206+- Claude 4 Sonnet
207+- Claude 4 Opus
206- Claude 3.5 Sonnet
208- Claude 3.5 Sonnet
207- Claude 3.5 Haiku
209- Claude 3.5 Haiku
208- Claude 3.7 Sonnet
210- Claude 3.7 Sonnet
cmd/schema/README.md+1−1
@@ -61,4 +61,4 @@ Here's an example configuration that conforms to the schema:
61 }
61 }
62 }
62 }
63}
63}
64−```
64+```
go.mod+1−1
@@ -7,7 +7,7 @@ require (
7 github.com/JohannesKaufmann/html-to-markdown v1.6.0
7 github.com/JohannesKaufmann/html-to-markdown v1.6.0
8 github.com/PuerkitoBio/goquery v1.9.2
8 github.com/PuerkitoBio/goquery v1.9.2
9 github.com/alecthomas/chroma/v2 v2.15.0
9 github.com/alecthomas/chroma/v2 v2.15.0
10− github.com/anthropics/anthropic-sdk-go v0.2.0-beta.2
10+ github.com/anthropics/anthropic-sdk-go v1.4.0
11 github.com/aymanbagabas/go-udiff v0.2.0
11 github.com/aymanbagabas/go-udiff v0.2.0
12 github.com/bmatcuk/doublestar/v4 v4.8.1
12 github.com/bmatcuk/doublestar/v4 v4.8.1
13 github.com/catppuccin/go v0.3.0
13 github.com/catppuccin/go v0.3.0
go.sum+2−2
@@ -26,8 +26,8 @@ github.com/alecthomas/repr v0.4.0 h1:GhI2A8MACjfegCPVq9f1FLvIBS+DrQ2KQBFZP1iFzXc
26github.com/alecthomas/repr v0.4.0/go.mod h1:Fr0507jx4eOXV7AlPV6AVZLYrLIuIeSOWtW57eE/O/4=
26github.com/alecthomas/repr v0.4.0/go.mod h1:Fr0507jx4eOXV7AlPV6AVZLYrLIuIeSOWtW57eE/O/4=
27github.com/andybalholm/cascadia v1.3.2 h1:3Xi6Dw5lHF15JtdcmAHD3i1+T8plmv7BQ/nsViSLyss=
27github.com/andybalholm/cascadia v1.3.2 h1:3Xi6Dw5lHF15JtdcmAHD3i1+T8plmv7BQ/nsViSLyss=
28github.com/andybalholm/cascadia v1.3.2/go.mod h1:7gtRlve5FxPPgIgX36uWBX58OdBsSS6lUvCFb+h7KvU=
28github.com/andybalholm/cascadia v1.3.2/go.mod h1:7gtRlve5FxPPgIgX36uWBX58OdBsSS6lUvCFb+h7KvU=
29−github.com/anthropics/anthropic-sdk-go v0.2.0-beta.2 h1:h7qxtumNjKPWFv1QM/HJy60MteeW23iKeEtBoY7bYZk=
29+github.com/anthropics/anthropic-sdk-go v1.4.0 h1:fU1jKxYbQdQDiEXCxeW5XZRIOwKevn/PMg8Ay1nnUx0=
30−github.com/anthropics/anthropic-sdk-go v0.2.0-beta.2/go.mod h1:AapDW22irxK2PSumZiQXYUFvsdQgkwIWlpESweWZI/c=
30+github.com/anthropics/anthropic-sdk-go v1.4.0/go.mod h1:AapDW22irxK2PSumZiQXYUFvsdQgkwIWlpESweWZI/c=
31github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4=
31github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4=
32github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI=
32github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI=
33github.com/aws/aws-sdk-go-v2 v1.30.3 h1:jUeBtG0Ih+ZIFH0F4UkmL9w3cSpaMv9tYYDbzILP8dY=
33github.com/aws/aws-sdk-go-v2 v1.30.3 h1:jUeBtG0Ih+ZIFH0F4UkmL9w3cSpaMv9tYYDbzILP8dY=
internal/llm/provider/anthropic.go+6−11
@@ -67,7 +67,7 @@ func (a *anthropicClient) convertMessages(messages []message.Message) (anthropic
67 case message.User:
67 case message.User:
68 content := anthropic.NewTextBlock(msg.Content().String())
68 content := anthropic.NewTextBlock(msg.Content().String())
69 if cache && !a.options.disableCache {
69 if cache && !a.options.disableCache {
70− content.OfRequestTextBlock.CacheControl = anthropic.CacheControlEphemeralParam{
70+ content.OfText.CacheControl = anthropic.CacheControlEphemeralParam{
71 Type: "ephemeral",
71 Type: "ephemeral",
72 }
72 }
73 }
73 }
@@ -85,7 +85,7 @@ func (a *anthropicClient) convertMessages(messages []message.Message) (anthropic
85 if msg.Content().String() != "" {
85 if msg.Content().String() != "" {
86 content := anthropic.NewTextBlock(msg.Content().String())
86 content := anthropic.NewTextBlock(msg.Content().String())
87 if cache && !a.options.disableCache {
87 if cache && !a.options.disableCache {
88− content.OfRequestTextBlock.CacheControl = anthropic.CacheControlEphemeralParam{
88+ content.OfText.CacheControl = anthropic.CacheControlEphemeralParam{
89 Type: "ephemeral",
89 Type: "ephemeral",
90 }
90 }
91 }
91 }
@@ -98,7 +98,7 @@ func (a *anthropicClient) convertMessages(messages []message.Message) (anthropic
98 if err != nil {
98 if err != nil {
99 continue
99 continue
100 }
100 }
101− blocks = append(blocks, anthropic.ContentBlockParamOfRequestToolUseBlock(toolCall.ID, inputMap, toolCall.Name))
101+ blocks = append(blocks, anthropic.NewToolUseBlock(toolCall.ID, inputMap, toolCall.Name))
102 }
102 }
103
103
104 if len(blocks) == 0 {
104 if len(blocks) == 0 {
@@ -167,17 +167,12 @@ func (a *anthropicClient) preparedMessages(messages []anthropic.MessageParam, to
167 temperature := anthropic.Float(0)
167 temperature := anthropic.Float(0)
168 if isUser {
168 if isUser {
169 for _, m := range lastMessage.Content {
169 for _, m := range lastMessage.Content {
170− if m.OfRequestTextBlock != nil && m.OfRequestTextBlock.Text != "" {
170+ if m.OfText != nil && m.OfText.Text != "" {
171− messageContent = m.OfRequestTextBlock.Text
171+ messageContent = m.OfText.Text
172 }
172 }
173 }
173 }
174 if messageContent != "" && a.options.shouldThink != nil && a.options.shouldThink(messageContent) {
174 if messageContent != "" && a.options.shouldThink != nil && a.options.shouldThink(messageContent) {
175− thinkingParam = anthropic.ThinkingConfigParamUnion{
176− OfThinkingConfigEnabled: &anthropic.ThinkingConfigEnabledParam{
177− BudgetTokens: int64(float64(a.providerOptions.maxTokens) * 0.8),
175+ thinkingParam = anthropic.ThinkingConfigParamOfEnabled(int64(float64(a.providerOptions.maxTokens) * 0.8))
178− Type: "enabled",
179− },
180− }
181 temperature = anthropic.Float(1)
176 temperature = anthropic.Float(1)
182 }
177 }
183 }
178 }