Skip to main content

cognee_http_server/dto/
datasets.rs

1//! DTOs for `/api/v1/datasets/*`.
2
3use chrono::{DateTime, Utc};
4use serde::{Deserialize, Serialize};
5use serde_json::Value;
6use std::collections::HashMap;
7use utoipa::{IntoParams, ToSchema};
8use uuid::Uuid;
9
10/// `DatasetDTO` — Python `OutDTO` (camelCase wire).
11#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
12#[serde(rename_all = "camelCase")]
13pub struct DatasetDTO {
14    pub id: Uuid,
15    pub name: String,
16    pub created_at: DateTime<Utc>,
17    pub updated_at: Option<DateTime<Utc>>,
18    pub owner_id: Uuid,
19}
20
21/// `DataDTO` — Python `OutDTO` (camelCase wire).
22#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
23#[serde(rename_all = "camelCase")]
24pub struct DataDTO {
25    pub id: Uuid,
26    pub name: String,
27    pub created_at: DateTime<Utc>,
28    pub updated_at: Option<DateTime<Utc>>,
29    pub extension: String,
30    pub mime_type: String,
31    pub raw_data_location: String,
32    pub dataset_id: Option<Uuid>,
33}
34
35/// `GraphDTO` — Python `OutDTO` (camelCase wire).
36#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
37#[serde(rename_all = "camelCase")]
38pub struct GraphDTO {
39    pub nodes: Vec<GraphNodeDTO>,
40    pub edges: Vec<GraphEdgeDTO>,
41}
42
43#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
44#[serde(rename_all = "camelCase")]
45pub struct GraphNodeDTO {
46    pub id: Uuid,
47    pub label: String,
48    pub r#type: String,
49    pub properties: serde_json::Map<String, Value>,
50}
51
52#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
53#[serde(rename_all = "camelCase")]
54pub struct GraphEdgeDTO {
55    pub source: Uuid,
56    pub target: Uuid,
57    pub label: String,
58}
59
60/// Request body for `POST /api/v1/datasets`.
61/// Python `InDTO` — camelCase aliases. Single-field DTO so the wire is `{"name": "..."}`.
62#[derive(Debug, Deserialize, ToSchema)]
63#[serde(rename_all = "camelCase")]
64pub struct DatasetCreationPayload {
65    pub name: String,
66}
67
68/// Request body for `PUT /api/v1/datasets/{id}/schema`.
69#[derive(Debug, Deserialize, ToSchema)]
70#[serde(rename_all = "camelCase")]
71pub struct DatasetSchemaPayloadDTO {
72    /// Free-form JSON object describing the dataset's graph schema.
73    /// `Option<T>` does not distinguish explicit `null` from omission, so the
74    /// handler treats both as "leave unchanged" on update and `NULL` on insert.
75    #[serde(default, skip_serializing_if = "Option::is_none")]
76    pub graph_schema: Option<Value>,
77    #[serde(default, skip_serializing_if = "Option::is_none")]
78    pub custom_prompt: Option<String>,
79}
80
81/// Response body for `GET /api/v1/datasets/{id}/schema`.
82/// **snake_case** wire — Python returns a raw dict, not an `OutDTO`.
83#[derive(Debug, Serialize, ToSchema)]
84pub struct DatasetSchemaResponseDTO {
85    pub graph_schema: Option<Value>,
86    pub custom_prompt: Option<String>,
87}
88
89/// Query string for `GET /api/v1/datasets/status`.
90#[derive(Debug, Deserialize, IntoParams)]
91pub struct DatasetStatusQuery {
92    /// Repeated query param `?dataset=<uuid>&dataset=<uuid>`.
93    /// Defaults to an empty list when the parameter is absent.
94    #[serde(rename = "dataset", default)]
95    pub dataset: Vec<Uuid>,
96}
97
98/// `PipelineRunStatus` enum — wire is the raw string discriminator.
99#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
100pub enum PipelineRunStatus {
101    #[serde(rename = "DATASET_PROCESSING_INITIATED")]
102    DatasetProcessingInitiated,
103    #[serde(rename = "DATASET_PROCESSING_STARTED")]
104    DatasetProcessingStarted,
105    #[serde(rename = "DATASET_PROCESSING_COMPLETED")]
106    DatasetProcessingCompleted,
107    #[serde(rename = "DATASET_PROCESSING_ERRORED")]
108    DatasetProcessingErrored,
109}
110
111/// Response body for `GET /api/v1/datasets/status`.
112pub type DatasetStatusResponseDTO = HashMap<Uuid, PipelineRunStatus>;
113
114/// `ErrorMessageDTO` — `{message: String}` envelope used by 2.3's 404.
115#[derive(Debug, Serialize, ToSchema)]
116pub struct ErrorMessageDTO {
117    pub message: String,
118}