@@ -2,6 +2,7 @@ local adapter_utils = require("codecompanion.utils.adapters")
22local log = require (" codecompanion.utils.log" )
33local transform = require (" codecompanion.utils.tool_transformers" )
44
5+
56--- @class CodeCompanion.HTTPAdapter.Anthropic : CodeCompanion.HTTPAdapter
67return {
78 name = " anthropic" ,
@@ -15,7 +16,7 @@ return {
1516 text = true ,
1617 },
1718 opts = {
18- context_management = true ,
19+ -- context_management = true,
1920 stream = true ,
2021 tools = true ,
2122 vision = true ,
@@ -39,8 +40,7 @@ return {
3940 --- @param self CodeCompanion.HTTPAdapter.Anthropic
4041 --- @param meta { tools : table }
4142 callback = function (self , meta )
42- local beta = self .headers [" anthropic-beta" ]
43- self .headers [" anthropic-beta" ] = (beta and (beta .. " ," ) or " " ) .. " code-execution-2025-08-25"
43+ adapter_utils .add_header (self .headers , " anthropic-beta" , " code-execution-2025-08-25" )
4444
4545 table.insert (meta .tools , {
4646 type = " code_execution_20250825" ,
@@ -53,8 +53,7 @@ return {
5353 --- @param self CodeCompanion.HTTPAdapter.Anthropic
5454 --- @param meta { tools : table }
5555 callback = function (self , meta )
56- local beta = self .headers [" anthropic-beta" ]
57- self .headers [" anthropic-beta" ] = (beta and (beta .. " ," ) or " " ) .. " context-management-2025-06-27"
56+ adapter_utils .add_header (self .headers , " anthropic-beta" , " context-management-2025-06-27" )
5857
5958 table.insert (meta .tools , {
6059 type = " memory_20250818" ,
@@ -71,8 +70,7 @@ return {
7170 --- @param self CodeCompanion.HTTPAdapter.Anthropic
7271 --- @param meta { tools : table }
7372 callback = function (self , meta )
74- local beta = self .headers [" anthropic-beta" ]
75- self .headers [" anthropic-beta" ] = (beta and (beta .. " ," ) or " " ) .. " web-fetch-2025-09-10"
73+ adapter_utils .add_header (self .headers , " anthropic-beta" , " web-fetch-2025-09-10" )
7674
7775 table.insert (meta .tools , {
7876 type = " web_fetch_20250910" ,
@@ -114,21 +112,18 @@ return {
114112
115113 -- Add the extended output header if enabled
116114 if self .temp .extended_output then
117- local beta = self .headers [" anthropic-beta" ]
118- self .headers [" anthropic-beta" ] = (beta and (beta .. " ," ) or " " ) .. " output-128k-2025-02-19"
115+ adapter_utils .add_header (self .headers , " anthropic-beta" , " output-128k-2025-02-19" )
119116 end
120117
121118 -- Ref: https://docs.anthropic.com/en/docs/build-with-claude/tool-use/token-efficient-tool-use
122119 if self .opts .has_token_efficient_tools then
123- local beta = self .headers [" anthropic-beta" ]
124- self .headers [" anthropic-beta" ] = (beta and (beta .. " ," ) or " " ) .. " token-efficient-tools-2025-02-19"
120+ adapter_utils .add_header (self .headers , " anthropic-beta" , " token-efficient-tools-2025-02-19" )
125121 end
126122
127123 -- Ref: https://platform.claude.com/docs/en/build-with-claude/context-editing#tool-result-clearing-usage
128- if self .opts .context_management then
129- local beta = self .headers [" anthropic-beta" ]
130- self .headers [" anthropic-beta" ] = (beta and (beta .. " ," ) or " " ) .. " context-management-2025-06-27"
131- end
124+ -- if self.opts.context_management then
125+ -- adapter_utils.add_header(self.headers, "anthropic-beta", "context-management-2025-06-27")
126+ -- end
132127
133128 return true
134129 end ,
@@ -322,39 +317,46 @@ return {
322317 end
323318 end
324319
325- local context_management = nil
326- if self .opts .context_management then
327- context_management = {
328- [" edits" ] = {
329- {
330- type = " clear_thinking_20251015" ,
331- keep = {
332- type = " thinking_turns" ,
333- value = 3 ,
334- },
335- },
336- {
337- type = " clear_tool_uses_20250919" ,
338- keep = {
339- type = " tool_uses" ,
340- value = 5 ,
341- },
342- trigger = {
343- type = " input_tokens" ,
344- value = 50000 ,
345- },
346- },
347- },
348- }
349- end
320+ -- local context_management = nil
321+ -- if self.opts.context_management then
322+ -- context_management = {
323+ -- ["edits"] = {
324+ -- {
325+ -- type = "clear_thinking_20251015",
326+ -- keep = {
327+ -- type = "thinking_turns",
328+ -- value = 3,
329+ -- },
330+ -- },
331+ -- {
332+ -- type = "clear_tool_uses_20250919",
333+ -- keep = {
334+ -- type = "tool_uses",
335+ -- value = 5,
336+ -- },
337+ -- trigger = {
338+ -- type = "input_tokens",
339+ -- value = 50000,
340+ -- },
341+ -- },
342+ -- -- {
343+ -- -- type = "compact_20260112",
344+ -- -- trigger = {
345+ -- -- type = "input_tokens",
346+ -- -- value = 100000,
347+ -- -- },
348+ -- -- },
349+ -- },
350+ -- }
351+ -- end
350352
351353 -- 11. Enable automatic prompt caching
352354 -- Ref: https://platform.claude.com/docs/en/build-with-claude/prompt-caching#automatic-caching
353355 return {
354356 cache_control = { type = " ephemeral" },
355357 system = system ,
356358 messages = messages ,
357- context_management = context_management ,
359+ -- context_management = context_management,
358360 }
359361 end ,
360362
0 commit comments