@@ -43,7 +43,16 @@ interface AnthropicTool extends PromptCache {
43
43
interface AnthropicToolResultContentItem {
44
44
type : 'tool_result' ;
45
45
tool_use_id : string ;
46
- content ?: string ;
46
+ content ?:
47
+ | {
48
+ type : string ;
49
+ text ?: string ;
50
+ cache_control ?: {
51
+ type : string ;
52
+ ttl ?: number ;
53
+ } ;
54
+ } [ ]
55
+ | string ;
47
56
}
48
57
49
58
interface AnthropicBase64ImageContentItem {
@@ -138,6 +147,9 @@ const transformAssistantMessage = (msg: Message): AnthropicMessage => {
138
147
input : toolCall . function . arguments ?. length
139
148
? JSON . parse ( toolCall . function . arguments )
140
149
: { } ,
150
+ ...( toolCall . cache_control && {
151
+ cache_control : toolCall . cache_control ,
152
+ } ) ,
141
153
} ) ;
142
154
} ) ;
143
155
}
@@ -155,7 +167,7 @@ const transformToolMessage = (msg: Message): AnthropicMessage => {
155
167
{
156
168
type : 'tool_result' ,
157
169
tool_use_id,
158
- content : msg . content as string ,
170
+ content : msg . content ,
159
171
} ,
160
172
] ,
161
173
} ;
@@ -250,6 +262,9 @@ export const AnthropicChatCompleteConfig: ProviderConfig = {
250
262
251
263
if ( msg . role === 'assistant' ) {
252
264
messages . push ( transformAssistantMessage ( msg ) ) ;
265
+ } else if ( msg . role === 'tool' ) {
266
+ // even though anthropic supports images in tool results, openai doesn't support it yet
267
+ messages . push ( transformToolMessage ( msg ) ) ;
253
268
} else if (
254
269
msg . content &&
255
270
typeof msg . content === 'object' &&
@@ -275,9 +290,6 @@ export const AnthropicChatCompleteConfig: ProviderConfig = {
275
290
}
276
291
} ) ;
277
292
messages . push ( transformedMessage as AnthropicMessage ) ;
278
- } else if ( msg . role === 'tool' ) {
279
- // even though anthropic supports images in tool results, openai doesn't support it yet
280
- messages . push ( transformToolMessage ( msg ) ) ;
281
293
} else {
282
294
messages . push ( {
283
295
role : msg . role ,
0 commit comments