( session_id: string, kind: TranscriptEvent["kind"], payload: unknown, )
| 121 | } |
| 122 | |
| 123 | export function appendTranscriptEvent( |
| 124 | session_id: string, |
| 125 | kind: TranscriptEvent["kind"], |
| 126 | payload: unknown, |
| 127 | ): void { |
| 128 | const db = getDb(); |
| 129 | const seqRow = db |
| 130 | .prepare("SELECT COALESCE(MAX(seq), 0) + 1 AS next FROM transcript_events WHERE session_id = ?") |
| 131 | .get(session_id) as { next: number }; |
| 132 | const id = randomUUID(); |
| 133 | const seq = seqRow.next; |
| 134 | const created_at = new Date().toISOString(); |
| 135 | const payload_json = JSON.stringify(payload); |
| 136 | db.prepare( |
| 137 | "INSERT INTO transcript_events (id, session_id, seq, kind, payload_json, created_at) VALUES (?, ?, ?, ?, ?, ?)", |
| 138 | ).run(id, session_id, seq, kind, payload_json, created_at); |
| 139 | // Push to live subscribers AFTER the INSERT commits. Inline import to |
| 140 | // keep this module free of the live-events dependency at module load — |
| 141 | // matters for the migration tests that don't want EventEmitter eagerness. |
| 142 | // eslint-disable-next-line @typescript-eslint/no-require-imports |
| 143 | const { publishSessionEvent } = |
| 144 | require("@/server/live-events/emitter") as typeof import("@/server/live-events/emitter"); |
| 145 | publishSessionEvent(session_id, { |
| 146 | id, |
| 147 | session_id, |
| 148 | seq, |
| 149 | kind, |
| 150 | payload_json, |
| 151 | created_at, |
| 152 | }); |
| 153 | } |
| 154 | |
| 155 | export function listTranscriptEvents( |
| 156 | session_id: string, |
no test coverage detected