|
| 1 | +/** |
| 2 | + * Type definitions for trace index schema using concrete classes. |
| 3 | + */ |
| 4 | + |
| 5 | +export class TraceFileInfo { |
| 6 | + constructor( |
| 7 | + public path: string, |
| 8 | + public size_bytes: number, |
| 9 | + public sha256: string |
| 10 | + ) {} |
| 11 | + |
| 12 | + toJSON() { |
| 13 | + return { |
| 14 | + path: this.path, |
| 15 | + size_bytes: this.size_bytes, |
| 16 | + sha256: this.sha256, |
| 17 | + }; |
| 18 | + } |
| 19 | +} |
| 20 | + |
| 21 | +export class TraceSummary { |
| 22 | + constructor( |
| 23 | + public first_ts: string, |
| 24 | + public last_ts: string, |
| 25 | + public event_count: number, |
| 26 | + public step_count: number, |
| 27 | + public error_count: number, |
| 28 | + public final_url: string | null |
| 29 | + ) {} |
| 30 | + |
| 31 | + toJSON() { |
| 32 | + return { |
| 33 | + first_ts: this.first_ts, |
| 34 | + last_ts: this.last_ts, |
| 35 | + event_count: this.event_count, |
| 36 | + step_count: this.step_count, |
| 37 | + error_count: this.error_count, |
| 38 | + final_url: this.final_url, |
| 39 | + }; |
| 40 | + } |
| 41 | +} |
| 42 | + |
| 43 | +export class SnapshotInfo { |
| 44 | + constructor( |
| 45 | + public snapshot_id: string | null = null, |
| 46 | + public digest: string | null = null, |
| 47 | + public url: string | null = null |
| 48 | + ) {} |
| 49 | + |
| 50 | + toJSON() { |
| 51 | + return { |
| 52 | + snapshot_id: this.snapshot_id, |
| 53 | + digest: this.digest, |
| 54 | + url: this.url, |
| 55 | + }; |
| 56 | + } |
| 57 | +} |
| 58 | + |
| 59 | +export class ActionInfo { |
| 60 | + constructor( |
| 61 | + public type: string | null = null, |
| 62 | + public target_element_id: number | null = null, |
| 63 | + public args_digest: string | null = null, |
| 64 | + public success: boolean | null = null |
| 65 | + ) {} |
| 66 | + |
| 67 | + toJSON() { |
| 68 | + return { |
| 69 | + type: this.type, |
| 70 | + target_element_id: this.target_element_id, |
| 71 | + args_digest: this.args_digest, |
| 72 | + success: this.success, |
| 73 | + }; |
| 74 | + } |
| 75 | +} |
| 76 | + |
| 77 | +export class StepCounters { |
| 78 | + constructor( |
| 79 | + public events: number = 0, |
| 80 | + public snapshots: number = 0, |
| 81 | + public actions: number = 0, |
| 82 | + public llm_calls: number = 0 |
| 83 | + ) {} |
| 84 | + |
| 85 | + toJSON() { |
| 86 | + return { |
| 87 | + events: this.events, |
| 88 | + snapshots: this.snapshots, |
| 89 | + actions: this.actions, |
| 90 | + llm_calls: this.llm_calls, |
| 91 | + }; |
| 92 | + } |
| 93 | +} |
| 94 | + |
| 95 | +export type StepStatus = 'ok' | 'error' | 'partial'; |
| 96 | + |
| 97 | +export class StepIndex { |
| 98 | + constructor( |
| 99 | + public step_index: number, |
| 100 | + public step_id: string, |
| 101 | + public goal: string | null, |
| 102 | + public status: StepStatus, |
| 103 | + public ts_start: string, |
| 104 | + public ts_end: string, |
| 105 | + public offset_start: number, |
| 106 | + public offset_end: number, |
| 107 | + public url_before: string | null, |
| 108 | + public url_after: string | null, |
| 109 | + public snapshot_before: SnapshotInfo, |
| 110 | + public snapshot_after: SnapshotInfo, |
| 111 | + public action: ActionInfo, |
| 112 | + public counters: StepCounters |
| 113 | + ) {} |
| 114 | + |
| 115 | + toJSON() { |
| 116 | + return { |
| 117 | + step_index: this.step_index, |
| 118 | + step_id: this.step_id, |
| 119 | + goal: this.goal, |
| 120 | + status: this.status, |
| 121 | + ts_start: this.ts_start, |
| 122 | + ts_end: this.ts_end, |
| 123 | + offset_start: this.offset_start, |
| 124 | + offset_end: this.offset_end, |
| 125 | + url_before: this.url_before, |
| 126 | + url_after: this.url_after, |
| 127 | + snapshot_before: this.snapshot_before.toJSON(), |
| 128 | + snapshot_after: this.snapshot_after.toJSON(), |
| 129 | + action: this.action.toJSON(), |
| 130 | + counters: this.counters.toJSON(), |
| 131 | + }; |
| 132 | + } |
| 133 | +} |
| 134 | + |
| 135 | +export class TraceIndex { |
| 136 | + constructor( |
| 137 | + public version: number, |
| 138 | + public run_id: string, |
| 139 | + public created_at: string, |
| 140 | + public trace_file: TraceFileInfo, |
| 141 | + public summary: TraceSummary, |
| 142 | + public steps: StepIndex[] = [] |
| 143 | + ) {} |
| 144 | + |
| 145 | + toJSON() { |
| 146 | + return { |
| 147 | + version: this.version, |
| 148 | + run_id: this.run_id, |
| 149 | + created_at: this.created_at, |
| 150 | + trace_file: this.trace_file.toJSON(), |
| 151 | + summary: this.summary.toJSON(), |
| 152 | + steps: this.steps.map((s) => s.toJSON()), |
| 153 | + }; |
| 154 | + } |
| 155 | +} |
0 commit comments