MCPcopy Index your code
hub / github.com/ChrisFeldmeier/OpenCodeRust / list_for_session

Method list_for_session

crates/opencode-storage/src/repository.rs:454–507  ·  view source on GitHub ↗
(
        &self,
        session_id: &str,
    )

Source from the content-addressed store, hash-verified

452 }
453
454 pub async fn list_for_session(
455 &self,
456 session_id: &str,
457 ) -> Result<Vec<SessionMessage>, DatabaseError> {
458 #[derive(FromRow)]
459 struct MessageRow {
460 id: String,
461 session_id: String,
462 role: String,
463 created_at: i64,
464 data: Option<String>,
465 }
466
467 let rows = sqlx::query_as::<_, MessageRow>(
468 r#"SELECT id, session_id, role, created_at, data
469 FROM messages WHERE session_id = ? ORDER BY created_at ASC"#,
470 )
471 .bind(session_id)
472 .fetch_all(&self.pool)
473 .await
474 .map_err(|e| DatabaseError::QueryError(e.to_string()))?;
475
476 let messages: Vec<SessionMessage> = rows
477 .into_iter()
478 .filter_map(|row| {
479 let msg_role = match row.role.as_str() {
480 "user" => MessageRole::User,
481 "assistant" => MessageRole::Assistant,
482 "system" => MessageRole::System,
483 "tool" => MessageRole::Tool,
484 _ => return None,
485 };
486
487 let parts: Vec<MessagePart> = row
488 .data
489 .and_then(|c| serde_json::from_str(&c).ok())
490 .unwrap_or_default();
491
492 let created =
493 DateTime::from_timestamp_millis(row.created_at).unwrap_or_else(Utc::now);
494
495 Some(SessionMessage {
496 id: row.id,
497 session_id: row.session_id,
498 role: msg_role,
499 parts,
500 created_at: created,
501 metadata: HashMap::new(),
502 })
503 })
504 .collect();
505
506 Ok(messages)
507 }
508
509 pub async fn get(&self, id: &str) -> Result<Option<SessionMessage>, DatabaseError> {
510 #[derive(FromRow)]

Callers 5

handle_stats_commandFunction · 0.80
handle_session_commandFunction · 0.80
export_session_dataFunction · 0.80
getMethod · 0.80

Calls 2

newFunction · 0.85
as_strMethod · 0.45

Tested by

no test coverage detected