@@ -6,14 +6,16 @@ export class TraceFileInfo {
66 constructor (
77 public path : string ,
88 public size_bytes : number ,
9- public sha256 : string
9+ public sha256 : string ,
10+ public line_count : number | null = null // Number of lines in the trace file
1011 ) { }
1112
1213 toJSON ( ) {
1314 return {
1415 path : this . path ,
1516 size_bytes : this . size_bytes ,
1617 sha256 : this . sha256 ,
18+ line_count : this . line_count ,
1719 } ;
1820 }
1921}
@@ -25,7 +27,11 @@ export class TraceSummary {
2527 public event_count : number ,
2628 public step_count : number ,
2729 public error_count : number ,
28- public final_url : string | null
30+ public final_url : string | null ,
31+ public status : 'success' | 'failure' | 'partial' | 'unknown' | null = null ,
32+ public agent_name : string | null = null , // Agent name from run_start event
33+ public duration_ms : number | null = null , // Calculated duration in milliseconds
34+ public counters : { snapshot_count : number ; action_count : number ; error_count : number } | null = null // Aggregated counters
2935 ) { }
3036
3137 toJSON ( ) {
@@ -36,6 +42,10 @@ export class TraceSummary {
3642 step_count : this . step_count ,
3743 error_count : this . error_count ,
3844 final_url : this . final_url ,
45+ status : this . status ,
46+ agent_name : this . agent_name ,
47+ duration_ms : this . duration_ms ,
48+ counters : this . counters ,
3949 } ;
4050 }
4151}
@@ -92,7 +102,7 @@ export class StepCounters {
92102 }
93103}
94104
95- export type StepStatus = 'ok ' | 'error ' | 'partial' ;
105+ export type StepStatus = 'success ' | 'failure ' | 'partial' | 'unknown ';
96106
97107export class StepIndex {
98108 constructor (
@@ -104,6 +114,7 @@ export class StepIndex {
104114 public ts_end : string ,
105115 public offset_start : number ,
106116 public offset_end : number ,
117+ public line_number : number | null = null , // Line number for byte-range fetching
107118 public url_before : string | null ,
108119 public url_after : string | null ,
109120 public snapshot_before : SnapshotInfo ,
@@ -122,6 +133,7 @@ export class StepIndex {
122133 ts_end : this . ts_end ,
123134 offset_start : this . offset_start ,
124135 offset_end : this . offset_end ,
136+ line_number : this . line_number ,
125137 url_before : this . url_before ,
126138 url_after : this . url_after ,
127139 snapshot_before : this . snapshot_before . toJSON ( ) ,
@@ -152,4 +164,73 @@ export class TraceIndex {
152164 steps : this . steps . map ( ( s ) => s . toJSON ( ) ) ,
153165 } ;
154166 }
167+
168+ /**
169+ * Convert to SS format.
170+ *
171+ * Maps SDK field names to frontend expectations:
172+ * - created_at -> generated_at
173+ * - first_ts -> start_time
174+ * - last_ts -> end_time
175+ * - step_index -> step (already 1-based, good!)
176+ * - ts_start -> timestamp
177+ * - Filters out "unknown" status
178+ */
179+ toSentienceStudioJSON ( ) : any {
180+ // Calculate duration if not already set
181+ let durationMs = this . summary . duration_ms ;
182+ if ( durationMs === null && this . summary . first_ts && this . summary . last_ts ) {
183+ const start = new Date ( this . summary . first_ts ) ;
184+ const end = new Date ( this . summary . last_ts ) ;
185+ durationMs = end . getTime ( ) - start . getTime ( ) ;
186+ }
187+
188+ // Aggregate counters if not already set
189+ let counters = this . summary . counters ;
190+ if ( counters === null ) {
191+ const snapshotCount = this . steps . reduce ( ( sum , s ) => sum + s . counters . snapshots , 0 ) ;
192+ const actionCount = this . steps . reduce ( ( sum , s ) => sum + s . counters . actions , 0 ) ;
193+ counters = {
194+ snapshot_count : snapshotCount ,
195+ action_count : actionCount ,
196+ error_count : this . summary . error_count ,
197+ } ;
198+ }
199+
200+ return {
201+ version : this . version ,
202+ run_id : this . run_id ,
203+ generated_at : this . created_at , // Renamed from created_at
204+ trace_file : {
205+ path : this . trace_file . path ,
206+ size_bytes : this . trace_file . size_bytes ,
207+ line_count : this . trace_file . line_count , // Added
208+ } ,
209+ summary : {
210+ agent_name : this . summary . agent_name , // Added
211+ total_steps : this . summary . step_count , // Renamed from step_count
212+ status : this . summary . status !== 'unknown' ? this . summary . status : null , // Filter out unknown
213+ start_time : this . summary . first_ts , // Renamed from first_ts
214+ end_time : this . summary . last_ts , // Renamed from last_ts
215+ duration_ms : durationMs , // Added
216+ counters : counters , // Added
217+ } ,
218+ steps : this . steps . map ( ( s ) => ( {
219+ step : s . step_index , // Already 1-based ✅
220+ byte_offset : s . offset_start ,
221+ line_number : s . line_number , // Added
222+ timestamp : s . ts_start , // Use start time
223+ action : {
224+ type : s . action . type || '' ,
225+ goal : s . goal , // Move goal into action
226+ digest : s . action . args_digest ,
227+ } ,
228+ snapshot : s . snapshot_after . url ? {
229+ url : s . snapshot_after . url ,
230+ digest : s . snapshot_after . digest ,
231+ } : undefined ,
232+ status : s . status !== 'unknown' ? s . status : undefined , // Filter out unknown
233+ } ) ) ,
234+ } ;
235+ }
155236}
0 commit comments