@@ -118,15 +118,16 @@ function renderPayload(elements) {
118118 const eMessage = deltaField ( e , 'message' ) ?? deltaField ( e , 'delta' ) ;
119119 const eName = deltaField ( e , 'name' ) ;
120120 const eType = deltaField ( e , 'type' ) ;
121+ const eRole = deltaField ( e , 'role' ) ;
121122 const marker = deltaMarker ( e ) ;
122123 if ( e === '...' || e === '...*' || e === '---' ) {
123124 continue ;
124- } else if ( eMessage && typeof eMessage === 'object' ) {
125- // OpenAI chat-completion choices wrap the assistant message in here
125+ } else if ( eMessage && typeof eMessage === 'object' && ! Array . isArray ( eMessage ) ) {
126+ // OpenAI chat-completion choices wrap the assistant message in an object here.
126127 payload . push ( ...renderPayload ( [ eMessage ] ) ) ;
127128 } else if (
128129 eType === 'message' ||
129- ( eType === undefined && e . role !== undefined && eContent !== undefined )
130+ ( eType === undefined && eRole !== undefined && eContent !== undefined )
130131 ) {
131132 const contents = Array . isArray ( eContent ) ? eContent : [ eContent ] ;
132133 contents . forEach ( content => {
@@ -135,7 +136,7 @@ function renderPayload(elements) {
135136 }
136137 const text = contentText ( Array . isArray ( eContent ) ? [ content ] : content ) ;
137138 payload . push ( {
138- [ TITLE ] : `${ marker } message(${ esc ( e . role ) } ): ` ,
139+ [ TITLE ] : `${ marker } message(${ esc ( eRole ) } ): ` ,
139140 [ INLINE ] : esc ( short ( text ) ) ,
140141 body : text ,
141142 } ) ;
@@ -166,7 +167,7 @@ function renderPayload(elements) {
166167 const raw = eType === 'function_call' ? JSON . parse ( eArguments ) : eInput ;
167168 const rawArg = raw ?. cmd ?? raw ?. pattern ?? raw ;
168169 arg = typeof rawArg === 'string' ? rawArg : JSON . stringify ( rawArg ?? '' ) ;
169- } catch ( e ) {
170+ } catch {
170171 arg = '...' ;
171172 }
172173 payload . push ( {
0 commit comments