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