33 array ,
44 integer ,
55 literal ,
6+ looseObject ,
67 minValue ,
78 nonEmpty ,
89 number ,
@@ -22,11 +23,10 @@ const EMPTY_ARRAY = Object.freeze([]);
2223
2324const streamSequenceSchema = pipe ( number ( ) , integer ( ) , minValue ( 1 ) ) ;
2425
25- const streamingDataSchema = object ( {
26+ const streamingDataSchema = looseObject ( {
2627 streamId : optional ( undefinedable ( string ( ) ) ) ,
2728 streamSequence : optional ( streamSequenceSchema ) ,
28- streamType : union ( [ literal ( 'streaming' ) , literal ( 'informative' ) , literal ( 'final' ) ] ) ,
29- type : optional ( string ( ) )
29+ streamType : union ( [ literal ( 'streaming' ) , literal ( 'informative' ) , literal ( 'final' ) ] )
3030} ) ;
3131
3232const channelDataStreamingActivitySchema = union ( [
@@ -97,14 +97,14 @@ const entitiesStreamingActivitySchema = union([
9797 object ( {
9898 attachments : optional ( array ( any ( ) ) , EMPTY_ARRAY ) ,
9999 entities : array (
100- object ( {
100+ looseObject ( {
101101 // "streamId" is optional for the very first activity in the session.
102102 streamId : optional ( undefinedable ( string ( ) ) ) ,
103103 streamSequence : streamSequenceSchema ,
104104 streamType : literal ( 'streaming' )
105105 } )
106106 ) ,
107- channelData : optional ( any ( ) ) ,
107+ channelData : any ( ) ,
108108 id : string ( ) ,
109109 // "text" is optional. If not set or empty, it presents a contentless activity.
110110 text : optional ( undefinedable ( string ( ) ) ) ,
@@ -114,14 +114,14 @@ const entitiesStreamingActivitySchema = union([
114114 object ( {
115115 attachments : optional ( array ( any ( ) ) , EMPTY_ARRAY ) ,
116116 entities : array (
117- object ( {
117+ looseObject ( {
118118 // "streamId" is optional for the very first activity in the session.
119119 streamId : optional ( undefinedable ( string ( ) ) ) ,
120120 streamSequence : streamSequenceSchema ,
121121 streamType : literal ( 'informative' )
122122 } )
123123 ) ,
124- channelData : optional ( any ( ) ) ,
124+ channelData : any ( ) ,
125125 id : string ( ) ,
126126 // Informative may not have "text", but should have abstract instead (checked later)
127127 text : optional ( undefinedable ( string ( ) ) ) ,
@@ -131,14 +131,14 @@ const entitiesStreamingActivitySchema = union([
131131 object ( {
132132 attachments : optional ( array ( any ( ) ) , EMPTY_ARRAY ) ,
133133 entities : array (
134- object ( {
134+ looseObject ( {
135135 // "streamId" is required for the final activity in the session.
136136 // The final activity must not be the sole activity in the session.
137137 streamId : pipe ( string ( ) , nonEmpty ( ) ) ,
138138 streamType : literal ( 'final' )
139139 } )
140140 ) ,
141- channelData : optional ( any ( ) ) ,
141+ channelData : any ( ) ,
142142 id : string ( ) ,
143143 // If "text" is empty, it represents "regretting" the livestream.
144144 text : optional ( undefinedable ( string ( ) ) ) ,
@@ -148,14 +148,14 @@ const entitiesStreamingActivitySchema = union([
148148 object ( {
149149 attachments : optional ( array ( any ( ) ) , EMPTY_ARRAY ) ,
150150 entities : array (
151- object ( {
151+ looseObject ( {
152152 // "streamId" is required for the final activity in the session.
153153 // The final activity must not be the sole activity in the session.
154154 streamId : pipe ( string ( ) , nonEmpty ( ) ) ,
155155 streamType : literal ( 'final' )
156156 } )
157157 ) ,
158- channelData : optional ( any ( ) ) ,
158+ channelData : any ( ) ,
159159 id : string ( ) ,
160160 // If "text" is not set or empty, it represents "regretting" the livestream.
161161 text : optional ( undefinedable ( literal ( '' ) ) ) ,
@@ -193,21 +193,14 @@ export default function getActivityLivestreamingMetadata(activity: WebChatActivi
193193 if ( activity . entities ) {
194194 activityResult = safeParse ( entitiesStreamingActivitySchema , activity ) ;
195195 streamingDataResult = safeParse ( streamingDataSchema , activity . entities [ 0 ] ) ;
196- } else {
197- activityResult = {
198- success : false
199- } ;
200- streamingDataResult = {
201- success : false
202- } ;
203196 }
204197
205- if ( ! ( activityResult . success && streamingDataResult . success ) && activity . channelData ) {
198+ if ( ! ( activityResult ? .success && streamingDataResult ? .success ) && activity . channelData ) {
206199 activityResult = safeParse ( channelDataStreamingActivitySchema , activity ) ;
207200 streamingDataResult = safeParse ( streamingDataSchema , activity . channelData ) ;
208201 }
209202
210- if ( activityResult . success && streamingDataResult . success ) {
203+ if ( activityResult ? .success && streamingDataResult ? .success ) {
211204 const { output } = activityResult ;
212205 const { output : streamData } = streamingDataResult ;
213206
0 commit comments