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