@@ -1212,6 +1212,103 @@ describe("ProviderTransform.message - anthropic empty content filtering", () =>
12121212 expect ( result [ 0 ] . content [ 1 ] ) . toEqual ( { type : "text" , text : "Result" } )
12131213 } )
12141214
1215+ test ( "replaces empty text with placeholder in assistant messages with reasoning" , ( ) => {
1216+ const msgs = [
1217+ {
1218+ role : "assistant" ,
1219+ content : [
1220+ { type : "reasoning" , text : "thinking..." , providerOptions : { anthropic : { signature : "sig_abc" } } } ,
1221+ { type : "text" , text : "" } ,
1222+ { type : "reasoning" , text : "more thinking" , providerOptions : { anthropic : { signature : "sig_xyz" } } } ,
1223+ { type : "text" , text : "Answer" } ,
1224+ ] ,
1225+ } ,
1226+ ] as any [ ]
1227+
1228+ const result = ProviderTransform . message ( msgs , anthropicModel , { } )
1229+
1230+ expect ( result ) . toHaveLength ( 1 )
1231+ expect ( result [ 0 ] . content ) . toHaveLength ( 4 )
1232+ expect ( result [ 0 ] . content [ 0 ] ) . toEqual ( { type : "reasoning" , text : "thinking..." , providerOptions : { anthropic : { signature : "sig_abc" } } } )
1233+ expect ( result [ 0 ] . content [ 1 ] ) . toEqual ( { type : "text" , text : "..." } )
1234+ expect ( result [ 0 ] . content [ 2 ] ) . toEqual ( { type : "reasoning" , text : "more thinking" , providerOptions : { anthropic : { signature : "sig_xyz" } } } )
1235+ expect ( result [ 0 ] . content [ 3 ] ) . toEqual ( { type : "text" , text : "Answer" } )
1236+ } )
1237+
1238+ test ( "replaces empty text and appends fallback when only reasoning remains" , ( ) => {
1239+ const msgs = [
1240+ {
1241+ role : "assistant" ,
1242+ content : [
1243+ { type : "reasoning" , text : "thinking..." , providerOptions : { anthropic : { signature : "sig_abc" } } } ,
1244+ { type : "text" , text : "" } ,
1245+ ] ,
1246+ } ,
1247+ ] as any [ ]
1248+
1249+ const result = ProviderTransform . message ( msgs , anthropicModel , { } )
1250+
1251+ expect ( result ) . toHaveLength ( 1 )
1252+ expect ( result [ 0 ] . content ) . toHaveLength ( 2 )
1253+ expect ( ( result [ 0 ] . content as any [ ] ) [ 0 ] . type ) . toBe ( "reasoning" )
1254+ expect ( result [ 0 ] . content [ 1 ] ) . toEqual ( { type : "text" , text : "..." } )
1255+ } )
1256+
1257+ test ( "appends fallback text when assistant has only reasoning with signature" , ( ) => {
1258+ const msgs = [
1259+ {
1260+ role : "assistant" ,
1261+ content : [
1262+ { type : "reasoning" , text : "deep thought" , providerOptions : { anthropic : { signature : "sig_xyz" } } } ,
1263+ ] ,
1264+ } ,
1265+ ] as any [ ]
1266+
1267+ const result = ProviderTransform . message ( msgs , anthropicModel , { } )
1268+
1269+ expect ( result ) . toHaveLength ( 1 )
1270+ expect ( result [ 0 ] . content ) . toHaveLength ( 2 )
1271+ expect ( ( result [ 0 ] . content as any [ ] ) [ 0 ] . type ) . toBe ( "reasoning" )
1272+ expect ( result [ 0 ] . content [ 1 ] ) . toEqual ( { type : "text" , text : "..." } )
1273+ } )
1274+
1275+ test ( "does not replace text in assistant messages without reasoning" , ( ) => {
1276+ const msgs = [
1277+ {
1278+ role : "assistant" ,
1279+ content : [
1280+ { type : "text" , text : "" } ,
1281+ { type : "text" , text : "Hello" } ,
1282+ { type : "text" , text : "" } ,
1283+ ] ,
1284+ } ,
1285+ ] as any [ ]
1286+
1287+ const result = ProviderTransform . message ( msgs , anthropicModel , { } )
1288+
1289+ expect ( result ) . toHaveLength ( 1 )
1290+ expect ( result [ 0 ] . content ) . toHaveLength ( 1 )
1291+ expect ( result [ 0 ] . content [ 0 ] ) . toEqual ( { type : "text" , text : "Hello" } )
1292+ } )
1293+
1294+ test ( "does not replace empty text in user messages with reasoning" , ( ) => {
1295+ const msgs = [
1296+ {
1297+ role : "user" ,
1298+ content : [
1299+ { type : "reasoning" , text : "user reasoning" , providerOptions : { anthropic : { signature : "sig_abc" } } } ,
1300+ { type : "text" , text : "" } ,
1301+ ] ,
1302+ } ,
1303+ ] as any [ ]
1304+
1305+ const result = ProviderTransform . message ( msgs , anthropicModel , { } )
1306+
1307+ expect ( result ) . toHaveLength ( 1 )
1308+ expect ( result [ 0 ] . content ) . toHaveLength ( 1 )
1309+ expect ( ( result [ 0 ] . content as any [ ] ) [ 0 ] . type ) . toBe ( "reasoning" )
1310+ } )
1311+
12151312 test ( "filters empty content for bedrock provider" , ( ) => {
12161313 const bedrockModel = {
12171314 ...anthropicModel ,
0 commit comments