File tree Expand file tree Collapse file tree
packages/core/src/services Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -178,23 +178,25 @@ export async function loadConversationRecord(
178178
179179 let firstUserMessage : string | undefined ;
180180 // FAST PREVIEW: Find the first line that is a 'user' message and extract its content
181- const userMsgMatch =
182- headStr . match (
183- / \{ [ ^ { } ] * " t y p e " \s * : \s * " u s e r " [ ^ { } ] * " c o n t e n t " \s * : \s * ( \[ [ ^ \] ] * \] | " (?: [ ^ " \\ \\ ] | \\ \\ .) * " ) [ ^ { } ] * \} / ,
184- ) ||
185- headStr . match (
186- / \{ [ ^ { } ] * " c o n t e n t " \s * : \s * ( \[ [ ^ \] ] * \] | " (?: [ ^ " \\ \\ ] | \\ \\ .) * " ) [ ^ { } ] * " t y p e " \s * : \s * " u s e r " [ ^ { } ] * \} / ,
181+ const userLine = headStr
182+ . split ( '\n' )
183+ . find (
184+ ( line ) =>
185+ line . includes ( '"type":"user"' ) || line . includes ( '"type": "user"' ) ,
187186 ) ;
188187
189- if ( userMsgMatch ) {
188+ if ( userLine ) {
190189 try {
191- const content = JSON . parse ( userMsgMatch [ 1 ] ) as unknown ;
192- if ( Array . isArray ( content ) ) {
193- firstUserMessage = content
194- . map ( ( p : unknown ) => ( isTextPart ( p ) ? p . text : '' ) )
195- . join ( '' ) ;
196- } else if ( typeof content === 'string' ) {
197- firstUserMessage = content ;
190+ const record = JSON . parse ( userLine ) as unknown ;
191+ if ( hasProperty ( record , 'content' ) ) {
192+ const content = record . content ;
193+ if ( Array . isArray ( content ) ) {
194+ firstUserMessage = content
195+ . map ( ( p : unknown ) => ( isTextPart ( p ) ? p . text : '' ) )
196+ . join ( '' ) ;
197+ } else if ( typeof content === 'string' ) {
198+ firstUserMessage = content ;
199+ }
198200 }
199201 } catch {
200202 /* ignore */
You can’t perform that action at this time.
0 commit comments