pub mod tutorial;
use std::sync::Arc;
use thiserror::Error;
use uuid::Uuid;
use cognee_database::{
DatabaseError, Notebook, NotebookDb, NotebookUpdatePatch, seed_tutorials_if_first_call,
};
pub use tutorial::{TUTORIAL_BASICS_ID, TUTORIAL_PYTHON_DEV_ID};
#[derive(Debug, Error)]
pub enum NotebookError {
#[error("database error: {0}")]
Database(#[from] DatabaseError),
}
pub async fn list_notebooks(
db: &Arc<dyn NotebookDb>,
user_id: Uuid,
) -> Result<Vec<Notebook>, NotebookError> {
seed_tutorials_if_first_call(db.as_ref(), user_id).await?;
Ok(db.list_by_owner(user_id).await?)
}
pub async fn create_notebook(
db: &Arc<dyn NotebookDb>,
user_id: Uuid,
name: String,
cells: serde_json::Value,
_deletable: bool,
) -> Result<Notebook, NotebookError> {
Ok(db.create(user_id, name, cells, true).await?)
}
pub async fn update_notebook(
db: &Arc<dyn NotebookDb>,
id: Uuid,
user_id: Uuid,
patch: NotebookUpdatePatch,
) -> Result<Option<Notebook>, NotebookError> {
Ok(db.update(id, user_id, patch).await?)
}
pub async fn delete_notebook(
db: &Arc<dyn NotebookDb>,
id: Uuid,
user_id: Uuid,
) -> Result<bool, NotebookError> {
Ok(db.delete(id, user_id).await?)
}