File tree Expand file tree Collapse file tree 1 file changed +27
-14
lines changed
Expand file tree Collapse file tree 1 file changed +27
-14
lines changed Original file line number Diff line number Diff line change @@ -180,25 +180,38 @@ function mapContent(
180180 const hasImage = content . some ( ( block ) => block . type === "image" )
181181 if ( ! hasImage ) {
182182 return content
183- . filter ( ( block ) : block is AnthropicTextBlock | AnthropicThinkingBlock =>
184- block . type === "text" || block . type === "thinking" )
185- . map ( ( block ) => block . type === "text" ? block . text : block . thinking )
183+ . filter (
184+ ( block ) : block is AnthropicTextBlock | AnthropicThinkingBlock =>
185+ block . type === "text" || block . type === "thinking" ,
186+ )
187+ . map ( ( block ) => ( block . type === "text" ? block . text : block . thinking ) )
186188 . join ( "\n\n" )
187189 }
188190
189191 const contentParts : Array < ContentPart > = [ ]
190192 for ( const block of content ) {
191- if ( block . type === "text" ) {
192- contentParts . push ( { type : "text" , text : block . text } )
193- } else if ( block . type === "thinking" ) {
194- contentParts . push ( { type : "text" , text : block . thinking } )
195- } else if ( block . type === "image" ) {
196- contentParts . push ( {
197- type : "image_url" ,
198- image_url : {
199- url : `data:${ block . source . media_type } ;base64,${ block . source . data } ` ,
200- } ,
201- } )
193+ switch ( block . type ) {
194+ case "text" : {
195+ contentParts . push ( { type : "text" , text : block . text } )
196+
197+ break
198+ }
199+ case "thinking" : {
200+ contentParts . push ( { type : "text" , text : block . thinking } )
201+
202+ break
203+ }
204+ case "image" : {
205+ contentParts . push ( {
206+ type : "image_url" ,
207+ image_url : {
208+ url : `data:${ block . source . media_type } ;base64,${ block . source . data } ` ,
209+ } ,
210+ } )
211+
212+ break
213+ }
214+ // No default
202215 }
203216 }
204217 return contentParts
You can’t perform that action at this time.
0 commit comments