@@ -807,13 +807,14 @@ describe('Agent Routes', () => {
807807 expect ( ( resp . body as any ) . error ) . toContain ( 'not active' ) ;
808808 } ) ;
809809
810- it ( 'should return 200 with agent response for valid request' , async ( ) => {
810+ it ( 'should return 200 with agent response for valid request (stream=false) ' , async ( ) => {
811811 const chatRoute = routes . find ( r => r . method === 'POST' ) ! ;
812812 const resp = await chatRoute . handler ( {
813813 params : { agentName : 'data_chat' } ,
814814 body : {
815815 messages : [ { role : 'user' , content : 'List all tables' } ] ,
816816 context : { objectName : 'account' } ,
817+ stream : false ,
817818 } ,
818819 } ) ;
819820 expect ( resp . status ) . toBe ( 200 ) ;
@@ -862,6 +863,7 @@ describe('Agent Routes', () => {
862863 params : { agentName : 'data_chat' } ,
863864 body : {
864865 messages : [ { role : 'user' , content : 'test' } ] ,
866+ stream : false ,
865867 options : {
866868 tools : [ { name : 'injected_tool' , description : 'Evil' , parameters : { } } ] ,
867869 toolChoice : 'injected_tool' ,
@@ -882,6 +884,7 @@ describe('Agent Routes', () => {
882884 const resp = await chatRoute . handler ( {
883885 params : { agentName : 'data_chat' } ,
884886 body : {
887+ stream : false ,
885888 messages : [
886889 {
887890 role : 'user' ,
@@ -899,6 +902,7 @@ describe('Agent Routes', () => {
899902 const resp = await chatRoute . handler ( {
900903 params : { agentName : 'data_chat' } ,
901904 body : {
905+ stream : false ,
902906 messages : [
903907 { role : 'user' , content : 'Hello' } ,
904908 {
@@ -920,6 +924,7 @@ describe('Agent Routes', () => {
920924 const resp = await chatRoute . handler ( {
921925 params : { agentName : 'data_chat' } ,
922926 body : {
927+ stream : false ,
923928 messages : [
924929 {
925930 role : 'assistant' ,
@@ -946,6 +951,66 @@ describe('Agent Routes', () => {
946951 expect ( resp . status ) . toBe ( 400 ) ;
947952 expect ( ( resp . body as any ) . error ) . toContain ( 'content' ) ;
948953 } ) ;
954+
955+ // ── Vercel Data Stream Protocol (SSE) ──
956+
957+ it ( 'should default to Vercel Data Stream mode when stream is not specified' , async ( ) => {
958+ const chatRoute = routes . find ( r => r . method === 'POST' ) ! ;
959+ const resp = await chatRoute . handler ( {
960+ params : { agentName : 'data_chat' } ,
961+ body : {
962+ messages : [ { role : 'user' , content : 'List all tables' } ] ,
963+ } ,
964+ } ) ;
965+ expect ( resp . status ) . toBe ( 200 ) ;
966+ expect ( resp . stream ) . toBe ( true ) ;
967+ expect ( resp . vercelDataStream ) . toBe ( true ) ;
968+ expect ( resp . events ) . toBeDefined ( ) ;
969+
970+ // Consume the Vercel Data Stream events
971+ const events : unknown [ ] = [ ] ;
972+ for await ( const event of resp . events ! ) {
973+ events . push ( event ) ;
974+ }
975+ expect ( events . length ) . toBeGreaterThan ( 0 ) ;
976+ // Must contain standard SSE lifecycle events
977+ const eventsStr = events . join ( '' ) ;
978+ expect ( eventsStr ) . toContain ( '"type":"start"' ) ;
979+ expect ( eventsStr ) . toContain ( '"type":"text-delta"' ) ;
980+ expect ( eventsStr ) . toContain ( '"type":"finish"' ) ;
981+ expect ( eventsStr ) . toContain ( 'data: [DONE]' ) ;
982+ } ) ;
983+
984+ it ( 'should return Vercel Data Stream when stream=true explicitly' , async ( ) => {
985+ const chatRoute = routes . find ( r => r . method === 'POST' ) ! ;
986+ const resp = await chatRoute . handler ( {
987+ params : { agentName : 'data_chat' } ,
988+ body : {
989+ messages : [ { role : 'user' , content : 'Hello agent' } ] ,
990+ stream : true ,
991+ } ,
992+ } ) ;
993+ expect ( resp . status ) . toBe ( 200 ) ;
994+ expect ( resp . stream ) . toBe ( true ) ;
995+ expect ( resp . vercelDataStream ) . toBe ( true ) ;
996+ expect ( resp . events ) . toBeDefined ( ) ;
997+ } ) ;
998+
999+ it ( 'should return JSON when stream=false' , async ( ) => {
1000+ const chatRoute = routes . find ( r => r . method === 'POST' ) ! ;
1001+ const resp = await chatRoute . handler ( {
1002+ params : { agentName : 'data_chat' } ,
1003+ body : {
1004+ messages : [ { role : 'user' , content : 'Hello agent' } ] ,
1005+ stream : false ,
1006+ } ,
1007+ } ) ;
1008+ expect ( resp . status ) . toBe ( 200 ) ;
1009+ expect ( resp . stream ) . toBeUndefined ( ) ;
1010+ expect ( resp . vercelDataStream ) . toBeUndefined ( ) ;
1011+ expect ( resp . body ) . toBeDefined ( ) ;
1012+ expect ( ( resp . body as any ) . content ) . toBeDefined ( ) ;
1013+ } ) ;
9491014} ) ;
9501015
9511016// ═══════════════════════════════════════════════════════════════════
0 commit comments