Messages of the session in chronological order: `(id, role)`.
(conn: &Connection, session_id: &str)
| 173 | |
| 174 | /// Messages of the session in chronological order: `(id, role)`. |
| 175 | fn read_messages(conn: &Connection, session_id: &str) -> Option<Vec<(String, String)>> { |
| 176 | let mut stmt = conn |
| 177 | .prepare( |
| 178 | "SELECT id, json_extract(data, '$.role') FROM message \ |
| 179 | WHERE session_id = ?1 ORDER BY time_created, id", |
| 180 | ) |
| 181 | .ok()?; |
| 182 | let rows = stmt |
| 183 | .query_map([session_id], |row| { |
| 184 | Ok((row.get::<_, String>(0)?, row.get::<_, String>(1)?)) |
| 185 | }) |
| 186 | .ok()?; |
| 187 | |
| 188 | let mut out = Vec::new(); |
| 189 | for row in rows { |
| 190 | match row { |
| 191 | Ok((id, role)) => out.push((id, role)), |
| 192 | Err(e) => { |
| 193 | log::debug!("opencode store: skipping message row: {}", e); |
| 194 | } |
| 195 | } |
| 196 | } |
| 197 | Some(out) |
| 198 | } |
| 199 | |
| 200 | /// Content parts of the session in chronological order: |
| 201 | /// `(message_id, data)`. |