Skip to content

Commit c4792cf

Browse files
authored
fix: show Anthropic Opus 4.7+ thinking (#26026)
## Summary - Updates Coder's pinned `github.com/coder/fantasy` fork to include coder/fantasy#39. - Exposes Anthropic `thinking_display` as a typed chat model provider option with `summarized` and `omitted` values. - Validates configured `thinking_display` values and maps them to `fantasyanthropic.ProviderOptions.ThinkingDisplay`. - Regenerates the API/UI option schemas so the admin model config form gets a generated select field. ## Tests - `go mod tidy` - `make gen` - `go test ./codersdk ./coderd/x/chatd/chatprovider ./coderd -run 'TestChatModelProviderOptions|TestAnthropicThinkingDisplayFromChat|TestProviderOptionsFromChatModelConfig_AnthropicThinkingDisplay|TestMergeMissingProviderOptions_AnthropicThinkingDisplay|TestValidateChatModelProviderOptions_AnthropicThinkingDisplay'` - `go test ./coderd/x/chatd/... ./codersdk` - `go test ./coderd -run 'TestValidateChatModelProviderOptions_AnthropicThinkingDisplay'` - `pnpm --dir site exec -- biome lint --error-on-warnings src/api/chatModelOptionsGenerated.json src/api/typesGenerated.ts` - pre-commit hook, including fmt, lint, and slim build > Mux working on behalf of Mike.
1 parent 5578ac5 commit c4792cf

10 files changed

Lines changed: 174 additions & 8 deletions

File tree

‎coderd/exp_chats.go‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7469,7 +7469,19 @@ func validateChatModelCallConfig(modelConfig *codersdk.ChatModelCallConfig) erro
74697469
}
74707470
}
74717471

7472-
return nil
7472+
return validateChatModelProviderOptions(modelConfig.ProviderOptions)
7473+
}
7474+
7475+
func validateChatModelProviderOptions(options *codersdk.ChatModelProviderOptions) error {
7476+
if options == nil || options.Anthropic == nil || options.Anthropic.ThinkingDisplay == nil {
7477+
return nil
7478+
}
7479+
7480+
if strings.TrimSpace(*options.Anthropic.ThinkingDisplay) == "" ||
7481+
chatprovider.AnthropicThinkingDisplayFromChat(options.Anthropic.ThinkingDisplay) != nil {
7482+
return nil
7483+
}
7484+
return xerrors.Errorf("provider_options.anthropic.thinking_display must be one of summarized, omitted")
74737485
}
74747486

74757487
func validateNonNegativeDecimalField(name string, value *decimal.Decimal) error {

‎coderd/exp_chats_internal_test.go‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,42 @@ import (
99
"github.com/coder/coder/v2/codersdk"
1010
)
1111

12+
func TestValidateChatModelProviderOptions_AnthropicThinkingDisplay(t *testing.T) {
13+
t.Parallel()
14+
15+
tests := []struct {
16+
name string
17+
display string
18+
wantErr string
19+
}{
20+
{name: "Summarized", display: "summarized"},
21+
{name: "Omitted", display: " omitted "},
22+
{name: "Empty", display: " "},
23+
{
24+
name: "Invalid",
25+
display: "summrized",
26+
wantErr: "provider_options.anthropic.thinking_display must be one of summarized, omitted",
27+
},
28+
}
29+
30+
for _, tt := range tests {
31+
t.Run(tt.name, func(t *testing.T) {
32+
t.Parallel()
33+
display := tt.display
34+
err := validateChatModelProviderOptions(&codersdk.ChatModelProviderOptions{
35+
Anthropic: &codersdk.ChatModelAnthropicProviderOptions{
36+
ThinkingDisplay: &display,
37+
},
38+
})
39+
if tt.wantErr != "" {
40+
require.EqualError(t, err, tt.wantErr)
41+
return
42+
}
43+
require.NoError(t, err)
44+
})
45+
}
46+
}
47+
1248
func TestValidateChatModelConfigProviderModel(t *testing.T) {
1349
t.Parallel()
1450

‎coderd/x/chatd/chatprovider/chatprovider.go‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -771,6 +771,30 @@ func ReasoningEffortFromChat(provider string, value *string) *string {
771771
}
772772
}
773773

774+
// AnthropicThinkingDisplayFromChat normalizes chat-config thinking display
775+
// values for Anthropic and returns the canonical provider display value.
776+
func AnthropicThinkingDisplayFromChat(value *string) *fantasyanthropic.ThinkingDisplay {
777+
if value == nil {
778+
return nil
779+
}
780+
781+
normalized := strings.ToLower(strings.TrimSpace(*value))
782+
if normalized == "" {
783+
return nil
784+
}
785+
786+
display := chatutil.NormalizedEnumValue(
787+
normalized,
788+
string(fantasyanthropic.ThinkingDisplaySummarized),
789+
string(fantasyanthropic.ThinkingDisplayOmitted),
790+
)
791+
if display == nil {
792+
return nil
793+
}
794+
valueCopy := fantasyanthropic.ThinkingDisplay(*display)
795+
return &valueCopy
796+
}
797+
774798
// MergeMissingModelCostConfig fills unset pricing metadata from defaults.
775799
func MergeMissingModelCostConfig(
776800
dst **codersdk.ModelCostConfig,
@@ -919,6 +943,9 @@ func MergeMissingProviderOptions(
919943
if dstAnthropic.Effort == nil {
920944
dstAnthropic.Effort = defaultAnthropic.Effort
921945
}
946+
if dstAnthropic.ThinkingDisplay == nil {
947+
dstAnthropic.ThinkingDisplay = defaultAnthropic.ThinkingDisplay
948+
}
922949
if dstAnthropic.DisableParallelToolUse == nil {
923950
dstAnthropic.DisableParallelToolUse = defaultAnthropic.DisableParallelToolUse
924951
}
@@ -1408,6 +1435,7 @@ func anthropicProviderOptionsFromChatConfig(
14081435
result := &fantasyanthropic.ProviderOptions{
14091436
SendReasoning: options.SendReasoning,
14101437
Effort: anthropicEffortFromChat(options.Effort),
1438+
ThinkingDisplay: AnthropicThinkingDisplayFromChat(options.ThinkingDisplay),
14111439
DisableParallelToolUse: options.DisableParallelToolUse,
14121440
}
14131441
if options.Thinking != nil && options.Thinking.BudgetTokens != nil {

‎coderd/x/chatd/chatprovider/chatprovider_test.go‎

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,77 @@ func TestReasoningEffortFromChat(t *testing.T) {
371371
}
372372
}
373373

374+
func TestAnthropicThinkingDisplayFromChat(t *testing.T) {
375+
t.Parallel()
376+
377+
tests := []struct {
378+
name string
379+
input *string
380+
want *fantasyanthropic.ThinkingDisplay
381+
}{
382+
{
383+
name: "Summarized",
384+
input: ptr.Ref(" SUMMARIZED "),
385+
want: ptr.Ref(fantasyanthropic.ThinkingDisplaySummarized),
386+
},
387+
{
388+
name: "Omitted",
389+
input: ptr.Ref("omitted"),
390+
want: ptr.Ref(fantasyanthropic.ThinkingDisplayOmitted),
391+
},
392+
{
393+
name: "InvalidReturnsNil",
394+
input: ptr.Ref("summary"),
395+
},
396+
{
397+
name: "NilInputReturnsNil",
398+
input: nil,
399+
},
400+
}
401+
402+
for _, tt := range tests {
403+
t.Run(tt.name, func(t *testing.T) {
404+
t.Parallel()
405+
got := chatprovider.AnthropicThinkingDisplayFromChat(tt.input)
406+
require.Equal(t, tt.want, got)
407+
})
408+
}
409+
}
410+
411+
func TestProviderOptionsFromChatModelConfig_AnthropicThinkingDisplay(t *testing.T) {
412+
t.Parallel()
413+
414+
providerOptions := chatprovider.ProviderOptionsFromChatModelConfig(nil, &codersdk.ChatModelProviderOptions{
415+
Anthropic: &codersdk.ChatModelAnthropicProviderOptions{
416+
ThinkingDisplay: ptr.Ref(" SUMMARIZED "),
417+
},
418+
})
419+
420+
require.NotNil(t, providerOptions)
421+
anthropicOptions, ok := providerOptions[fantasyanthropic.Name].(*fantasyanthropic.ProviderOptions)
422+
require.True(t, ok)
423+
require.NotNil(t, anthropicOptions.ThinkingDisplay)
424+
require.Equal(t, fantasyanthropic.ThinkingDisplaySummarized, *anthropicOptions.ThinkingDisplay)
425+
}
426+
427+
func TestMergeMissingProviderOptions_AnthropicThinkingDisplay(t *testing.T) {
428+
t.Parallel()
429+
430+
options := &codersdk.ChatModelProviderOptions{
431+
Anthropic: &codersdk.ChatModelAnthropicProviderOptions{},
432+
}
433+
defaults := &codersdk.ChatModelProviderOptions{
434+
Anthropic: &codersdk.ChatModelAnthropicProviderOptions{
435+
ThinkingDisplay: ptr.Ref("summarized"),
436+
},
437+
}
438+
439+
chatprovider.MergeMissingProviderOptions(&options, defaults)
440+
441+
require.NotNil(t, options.Anthropic.ThinkingDisplay)
442+
require.Equal(t, "summarized", *options.Anthropic.ThinkingDisplay)
443+
}
444+
374445
func TestResolveUserProviderKeys_UnavailableReason(t *testing.T) {
375446
t.Parallel()
376447

‎codersdk/chats.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1229,6 +1229,7 @@ type ChatModelAnthropicProviderOptions struct {
12291229
SendReasoning *bool `json:"send_reasoning,omitempty" description:"Whether to include reasoning content in the response"`
12301230
Thinking *ChatModelAnthropicThinkingOptions `json:"thinking,omitempty" description:"Configuration for extended thinking"`
12311231
Effort *string `json:"effort,omitempty" label:"Reasoning Effort" description:"Controls the level of reasoning effort" enum:"low,medium,high,xhigh,max"`
1232+
ThinkingDisplay *string `json:"thinking_display,omitempty" label:"Thinking Display" description:"Controls how Anthropic returns thinking content" enum:"summarized,omitted"`
12321233
DisableParallelToolUse *bool `json:"disable_parallel_tool_use,omitempty" description:"Whether to disable parallel tool execution"`
12331234
WebSearchEnabled *bool `json:"web_search_enabled,omitempty" description:"Enable Anthropic web search tool for grounding responses with real-time information"`
12341235
AllowedDomains []string `json:"allowed_domains,omitempty" label:"Web Search: Allowed Domains" description:"Restrict web search to these domains (cannot be used with blocked_domains)"`

‎codersdk/chats_test.go‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,21 @@ func TestChatModelProviderOptions_MarshalJSON_UsesPlainProviderPayload(t *testin
2424

2525
sendReasoning := true
2626
effort := "high"
27+
thinkingDisplay := "summarized"
2728

2829
raw, err := json.Marshal(codersdk.ChatModelProviderOptions{
2930
Anthropic: &codersdk.ChatModelAnthropicProviderOptions{
30-
SendReasoning: &sendReasoning,
31-
Effort: &effort,
31+
SendReasoning: &sendReasoning,
32+
Effort: &effort,
33+
ThinkingDisplay: &thinkingDisplay,
3234
},
3335
})
3436
require.NoError(t, err)
3537
require.NotContains(t, string(raw), `"type":"anthropic.options"`)
3638
require.NotContains(t, string(raw), `"data":`)
3739
require.Contains(t, string(raw), `"send_reasoning":true`)
3840
require.Contains(t, string(raw), `"effort":"high"`)
41+
require.Contains(t, string(raw), `"thinking_display":"summarized"`)
3942
}
4043

4144
func TestChatModelProviderOptions_UnmarshalJSON_ParsesPlainProviderPayloads(t *testing.T) {
@@ -44,7 +47,8 @@ func TestChatModelProviderOptions_UnmarshalJSON_ParsesPlainProviderPayloads(t *t
4447
raw := []byte(`{
4548
"anthropic": {
4649
"send_reasoning": true,
47-
"effort": "high"
50+
"effort": "high",
51+
"thinking_display": "summarized"
4852
}
4953
}`)
5054

@@ -60,6 +64,8 @@ func TestChatModelProviderOptions_UnmarshalJSON_ParsesPlainProviderPayloads(t *t
6064
"high",
6165
*decoded.Anthropic.Effort,
6266
)
67+
require.NotNil(t, decoded.Anthropic.ThinkingDisplay)
68+
require.Equal(t, "summarized", *decoded.Anthropic.ThinkingDisplay)
6369
}
6470

6571
func TestChatUsageLimitExceededFrom(t *testing.T) {

‎go.mod‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,9 @@ replace github.com/spf13/afero => github.com/aslilac/afero v0.0.0-20250403163713
9494
// emit a Base64 PDF document block for application/pdf FileParts on the
9595
// Anthropic provider so user-uploaded PDFs actually reach Claude/Bedrock
9696
// instead of being silently dropped.
97-
// See: https://github.com/coder/fantasy/commits/7d46e640327a
98-
replace charm.land/fantasy => github.com/coder/fantasy v0.0.0-20260602023814-7d46e640327a
97+
// 11) coder/fantasy#39, support Anthropic thinking_display natively.
98+
// See: https://github.com/coder/fantasy/commits/a2a3f2171ec8
99+
replace charm.land/fantasy => github.com/coder/fantasy v0.0.0-20260604204802-a2a3f2171ec8
99100

100101
// coder/coder uses a fork of charmbracelet's fork of the Anthropic Go SDK
101102
// with performance improvements and Bedrock header cleanup.

‎go.sum‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,8 +324,8 @@ github.com/coder/bubbletea v1.2.2-0.20241212190825-007a1cdb2c41 h1:SBN/DA63+ZHwu
324324
github.com/coder/bubbletea v1.2.2-0.20241212190825-007a1cdb2c41/go.mod h1:I9ULxr64UaOSUv7hcb3nX4kowodJCVS7vt7VVJk/kW4=
325325
github.com/coder/clistat v1.2.1 h1:P9/10njXMyj5cWzIU5wkRsSy5LVQH49+tcGMsAgWX0w=
326326
github.com/coder/clistat v1.2.1/go.mod h1:m7SC0uj88eEERgvF8Kn6+w6XF21BeSr+15f7GoLAw0A=
327-
github.com/coder/fantasy v0.0.0-20260602023814-7d46e640327a h1:ffQixHAwjJLHgFfe4rtrAsFNRGhEyWnBSpInnLIxDPo=
328-
github.com/coder/fantasy v0.0.0-20260602023814-7d46e640327a/go.mod h1:wZ0e3lEPqrM0XiIdAUQLvMKCLYhc3gi96MRX2wjbX44=
327+
github.com/coder/fantasy v0.0.0-20260604204802-a2a3f2171ec8 h1:+8QmiW3qKSqS4pkEQQbK7Rg3UGWnD/c5BXp1tPpX1sU=
328+
github.com/coder/fantasy v0.0.0-20260604204802-a2a3f2171ec8/go.mod h1:RdKpE+blFnbGx4XmNc952AXAdBL1ZXg9iTnXHjdn9Bk=
329329
github.com/coder/flog v1.1.0 h1:kbAes1ai8fIS5OeV+QAnKBQE22ty1jRF/mcAwHpLBa4=
330330
github.com/coder/flog v1.1.0/go.mod h1:UQlQvrkJBvnRGo69Le8E24Tcl5SJleAAR7gYEHzAmdQ=
331331
github.com/coder/go-httpstat v0.0.0-20230801153223-321c88088322 h1:m0lPZjlQ7vdVpRBPKfYIFlmgevoTkBxB10wv6l2gOaU=

‎site/src/api/chatModelOptionsGenerated.json‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,16 @@
112112
"enum": ["low", "medium", "high", "xhigh", "max"],
113113
"input_type": "select"
114114
},
115+
{
116+
"json_name": "thinking_display",
117+
"go_name": "ThinkingDisplay",
118+
"type": "string",
119+
"description": "Controls how Anthropic returns thinking content",
120+
"label": "Thinking Display",
121+
"required": false,
122+
"enum": ["summarized", "omitted"],
123+
"input_type": "select"
124+
},
115125
{
116126
"json_name": "disable_parallel_tool_use",
117127
"go_name": "DisableParallelToolUse",

‎site/src/api/typesGenerated.ts‎

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)