@@ -31,6 +31,7 @@ import {
3131 extractJsonNullableStringFieldPrefix ,
3232 extractJsonNumberFieldPrefix ,
3333 extractJsonStringFieldPrefix ,
34+ normalizeOptionalString ,
3435} from "./session-transcript-json.js" ;
3536import type { SessionPreviewItem } from "./session-utils.types.js" ;
3637
@@ -350,48 +351,19 @@ function extractJsonStringFieldWindow(
350351 }
351352 try {
352353 const decoded = JSON . parse ( `"${ match [ 1 ] } "` ) as unknown ;
353- return normalizeTailEntryString ( decoded ) ;
354+ return normalizeOptionalString ( decoded ) ;
354355 } catch {
355356 return undefined ;
356357 }
357358 }
358359 return undefined ;
359360}
360361
361- function extractJsonStringFieldPrefix ( prefix : string , field : string ) : string | undefined {
362- return extractJsonStringFieldWindow ( prefix , field ) ;
363- }
364-
365362function extractJsonStringFieldSuffix ( source : string , field : string ) : string | undefined {
366363 const startIndex = Math . max ( 0 , source . length - OVERSIZED_TRANSCRIPT_METADATA_SUFFIX_CHARS ) ;
367364 return extractJsonStringFieldWindow ( source , field , startIndex ) ;
368365}
369366
370- function extractJsonNullableStringFieldPrefix (
371- prefix : string ,
372- field : string ,
373- ) : string | null | undefined {
374- if ( new RegExp ( `"${ escapeRegExp ( field ) } "\\s*:\\s*null` ) . test ( prefix ) ) {
375- return null ;
376- }
377- return extractJsonStringFieldPrefix ( prefix , field ) ;
378- }
379-
380- function extractJsonNumberFieldPrefix ( prefix : string , field : string ) : number | undefined {
381- const match = new RegExp (
382- `"${ escapeRegExp ( field ) } "\\s*:\\s*(-?\\d+(?:\\.\\d+)?(?:[eE][+-]?\\d+)?)` ,
383- ) . exec ( prefix ) ;
384- if ( ! match ) {
385- return undefined ;
386- }
387- const decoded = Number ( match [ 1 ] ) ;
388- return Number . isFinite ( decoded ) ? decoded : undefined ;
389- }
390-
391- function normalizeTailEntryString ( value : unknown ) : string | undefined {
392- return typeof value === "string" && value . trim ( ) . length > 0 ? value : undefined ;
393- }
394-
395367function buildOversizedTranscriptRecord ( line : string ) : TailTranscriptRecord {
396368 const prefix = line . slice ( 0 , OVERSIZED_TRANSCRIPT_METADATA_PREFIX_CHARS ) ;
397369 const messageMatch = / " m e s s a g e " \s * : / . exec ( prefix ) ;
0 commit comments