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