oxirs_chat/
types.rs

1//! Core types for OxiRS Chat
2//!
3//! This module contains the fundamental types used throughout the chat system,
4//! including messages, rich content elements, and associated metadata.
5
6use chrono::{DateTime, Utc};
7use serde::{Deserialize, Serialize};
8use std::time::Duration;
9
10/// Chat session configuration
11#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
12pub struct ChatConfig {
13    pub max_context_length: usize,
14    pub temperature: f32,
15    pub max_retrieval_results: usize,
16    pub enable_sparql_generation: bool,
17    pub session_timeout: Duration,
18    pub max_conversation_turns: usize,
19    pub enable_context_summarization: bool,
20    pub sliding_window_size: usize,
21}
22
23impl Default for ChatConfig {
24    fn default() -> Self {
25        Self {
26            max_context_length: 4096,
27            temperature: 0.7,
28            max_retrieval_results: 10,
29            enable_sparql_generation: true,
30            session_timeout: Duration::from_secs(3600),
31            max_conversation_turns: 100,
32            enable_context_summarization: true,
33            sliding_window_size: 20,
34        }
35    }
36}
37
38/// Chat message with rich content support
39#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
40pub struct Message {
41    pub id: String,
42    pub role: MessageRole,
43    pub content: MessageContent,
44    pub timestamp: chrono::DateTime<chrono::Utc>,
45    pub metadata: Option<MessageMetadata>,
46    pub thread_id: Option<String>,
47    pub parent_message_id: Option<String>,
48    pub token_count: Option<usize>,
49    pub reactions: Vec<MessageReaction>,
50    pub attachments: Vec<MessageAttachment>,
51    pub rich_elements: Vec<RichContentElement>,
52}
53
54/// Message content supporting both plain text and rich content
55#[derive(Debug, Clone, Serialize, Deserialize)]
56pub enum MessageContent {
57    /// Plain text content
58    Text(String),
59    /// Rich content with multiple elements
60    Rich {
61        text: String,
62        elements: Vec<RichContentElement>,
63    },
64}
65
66impl MessageContent {
67    pub fn to_text(&self) -> &str {
68        match self {
69            MessageContent::Text(text) => text,
70            MessageContent::Rich { text, .. } => text,
71        }
72    }
73
74    pub fn from_text(text: String) -> Self {
75        MessageContent::Text(text)
76    }
77
78    pub fn add_element(&mut self, element: RichContentElement) {
79        match self {
80            MessageContent::Text(text) => {
81                let text = std::mem::take(text);
82                *self = MessageContent::Rich {
83                    text,
84                    elements: vec![element],
85                };
86            }
87            MessageContent::Rich { elements, .. } => {
88                elements.push(element);
89            }
90        }
91    }
92
93    pub fn len(&self) -> usize {
94        self.to_text().len()
95    }
96
97    pub fn contains(&self, pat: char) -> bool {
98        self.to_text().contains(pat)
99    }
100
101    pub fn to_lowercase(&self) -> String {
102        self.to_text().to_lowercase()
103    }
104
105    pub fn chars(&self) -> std::str::Chars<'_> {
106        self.to_text().chars()
107    }
108
109    pub fn is_empty(&self) -> bool {
110        self.to_text().is_empty()
111    }
112}
113
114impl std::fmt::Display for MessageContent {
115    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
116        write!(f, "{}", self.to_text())
117    }
118}
119
120/// Message role enumeration
121#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
122pub enum MessageRole {
123    User,
124    Assistant,
125    System,
126}
127
128/// Message metadata for analytics and context
129#[derive(Debug, Clone, Serialize, Deserialize)]
130pub struct MessageMetadata {
131    pub session_id: String,
132    pub turn_number: usize,
133    pub processing_time_ms: Option<u64>,
134    pub retrieval_results: Option<usize>,
135    pub sparql_query: Option<String>,
136    pub confidence_score: Option<f32>,
137    pub intent: Option<String>,
138    pub entities: Vec<String>,
139    pub topics: Vec<String>,
140    pub quality_score: Option<f32>,
141    pub user_feedback: Option<UserFeedback>,
142    pub error_details: Option<ErrorDetails>,
143}
144
145/// User feedback for quality assessment
146#[derive(Debug, Clone, Serialize, Deserialize)]
147pub struct UserFeedback {
148    pub rating: u8, // 1-5 stars
149    pub helpful: Option<bool>,
150    pub comment: Option<String>,
151    pub timestamp: chrono::DateTime<chrono::Utc>,
152}
153
154/// Error details for debugging
155#[derive(Debug, Clone, Serialize, Deserialize)]
156pub struct ErrorDetails {
157    pub error_type: String,
158    pub error_message: String,
159    pub error_code: Option<String>,
160    pub stack_trace: Option<String>,
161    pub recovery_suggestions: Vec<String>,
162}
163
164/// Message reaction for user engagement
165#[derive(Debug, Clone, Serialize, Deserialize)]
166pub struct MessageReaction {
167    pub reaction_type: ReactionType,
168    pub user_id: Option<String>,
169    pub timestamp: chrono::DateTime<chrono::Utc>,
170}
171
172/// Reaction type enumeration
173#[derive(Debug, Clone, Serialize, Deserialize)]
174pub enum ReactionType {
175    Like,
176    Dislike,
177    Helpful,
178    NotHelpful,
179    Accurate,
180    Inaccurate,
181    Clear,
182    Confusing,
183}
184
185/// Message attachment for file uploads
186#[derive(Debug, Clone, Serialize, Deserialize)]
187pub struct MessageAttachment {
188    pub id: String,
189    pub filename: String,
190    pub file_type: String,
191    pub size_bytes: u64,
192    pub url: Option<String>,
193    pub thumbnail_url: Option<String>,
194    pub metadata: AttachmentMetadata,
195    pub upload_timestamp: chrono::DateTime<chrono::Utc>,
196    pub processing_status: AttachmentProcessingStatus,
197}
198
199/// Attachment metadata
200#[derive(Debug, Clone, Serialize, Deserialize)]
201pub struct AttachmentMetadata {
202    pub extracted_text: Option<String>,
203    pub language: Option<String>,
204    pub format_detected: Option<String>,
205    pub processing_notes: Vec<String>,
206}
207
208/// Attachment processing status
209#[derive(Debug, Clone, Serialize, Deserialize)]
210pub enum AttachmentProcessingStatus {
211    Pending,
212    Processing,
213    Completed,
214    Failed(String),
215    PartiallyProcessed(String),
216}
217
218/// Rich content elements that can be embedded in messages
219#[derive(Debug, Clone, Serialize, Deserialize)]
220pub enum RichContentElement {
221    /// Code snippet with syntax highlighting
222    CodeBlock {
223        language: String,
224        code: String,
225        title: Option<String>,
226        line_numbers: bool,
227        highlight_lines: Vec<usize>,
228    },
229    /// SPARQL query block with execution metadata
230    SparqlQuery {
231        query: String,
232        execution_time_ms: Option<u64>,
233        result_count: Option<usize>,
234        status: QueryExecutionStatus,
235        explanation: Option<String>,
236    },
237    /// Data table with formatting options
238    Table {
239        headers: Vec<String>,
240        rows: Vec<Vec<String>>,
241        title: Option<String>,
242        pagination: Option<TablePagination>,
243        sorting: Option<TableSorting>,
244        formatting: TableFormatting,
245    },
246    /// Graph visualization configuration
247    GraphVisualization {
248        graph_type: GraphType,
249        data: GraphData,
250        layout: GraphLayout,
251        styling: GraphStyling,
252        interactive: bool,
253    },
254    /// Chart or plot
255    Chart {
256        chart_type: ChartType,
257        data: ChartData,
258        title: Option<String>,
259        axes: ChartAxes,
260        styling: ChartStyling,
261    },
262    /// File upload reference
263    FileReference {
264        file_id: String,
265        filename: String,
266        file_type: String,
267        size_bytes: u64,
268        preview: Option<FilePreview>,
269    },
270    /// Interactive widget
271    Widget {
272        widget_type: WidgetType,
273        data: serde_json::Value,
274        config: WidgetConfig,
275    },
276    /// Timeline visualization
277    Timeline {
278        events: Vec<TimelineEvent>,
279        range: TimelineRange,
280        styling: TimelineStyling,
281    },
282    /// Quantum-enhanced search results visualization
283    QuantumVisualization {
284        results: Vec<QuantumSearchResult>,
285        entanglement_map: std::collections::HashMap<String, f32>,
286    },
287    /// Consciousness-aware processing insights
288    ConsciousnessInsights {
289        insights: Vec<ConsciousnessInsight>,
290        awareness_level: f32,
291    },
292    /// Advanced reasoning chain visualization
293    ReasoningChain {
294        reasoning_steps: Vec<ReasoningStep>,
295        confidence_score: f32,
296    },
297    /// SPARQL query results with execution metadata
298    SPARQLResults {
299        query: String,
300        results: Vec<std::collections::HashMap<String, String>>,
301        execution_time: Duration,
302    },
303}
304
305/// Query execution status for SPARQL queries
306#[derive(Debug, Clone, Serialize, Deserialize)]
307pub enum QueryExecutionStatus {
308    Success,
309    Error(String),
310    Timeout,
311    Cancelled,
312    ValidationError(String),
313}
314
315/// Table pagination information
316#[derive(Debug, Clone, Serialize, Deserialize)]
317pub struct TablePagination {
318    pub current_page: usize,
319    pub total_pages: usize,
320    pub page_size: usize,
321    pub total_rows: usize,
322}
323
324/// Table sorting configuration
325#[derive(Debug, Clone, Serialize, Deserialize)]
326pub struct TableSorting {
327    pub column: String,
328    pub direction: SortDirection,
329}
330
331#[derive(Debug, Clone, Serialize, Deserialize)]
332pub enum SortDirection {
333    Ascending,
334    Descending,
335}
336
337/// Table formatting options
338#[derive(Debug, Clone, Serialize, Deserialize)]
339pub struct TableFormatting {
340    pub striped_rows: bool,
341    pub borders: bool,
342    pub compact: bool,
343    pub theme: TableTheme,
344    pub cell_padding: CellPadding,
345    pub column_widths: Vec<ColumnWidth>,
346}
347
348impl Default for TableFormatting {
349    fn default() -> Self {
350        Self {
351            striped_rows: true,
352            borders: true,
353            compact: false,
354            theme: TableTheme::Default,
355            cell_padding: CellPadding::Medium,
356            column_widths: vec![],
357        }
358    }
359}
360
361/// Table theme enumeration
362#[derive(Debug, Clone, Serialize, Deserialize)]
363pub enum TableTheme {
364    Default,
365    Dark,
366    Light,
367    Minimal,
368    Professional,
369}
370
371/// Cell padding options
372#[derive(Debug, Clone, Serialize, Deserialize)]
373pub enum CellPadding {
374    None,
375    Small,
376    Medium,
377    Large,
378}
379
380/// Column width specification
381#[derive(Debug, Clone, Serialize, Deserialize)]
382pub enum ColumnWidth {
383    Auto,
384    Fixed(u32),
385    Percentage(f32),
386    MinMax { min: u32, max: u32 },
387}
388
389/// Graph type enumeration
390#[derive(Debug, Clone, Serialize, Deserialize)]
391pub enum GraphType {
392    Network,
393    Tree,
394    Hierarchy,
395    Flow,
396    Timeline,
397    Circular,
398    Force,
399}
400
401/// Graph data structure
402#[derive(Debug, Clone, Serialize, Deserialize)]
403pub struct GraphData {
404    pub nodes: Vec<GraphNode>,
405    pub edges: Vec<GraphEdge>,
406    pub metadata: GraphMetadata,
407}
408
409/// Graph node representation
410#[derive(Debug, Clone, Serialize, Deserialize)]
411pub struct GraphNode {
412    pub id: String,
413    pub label: String,
414    pub node_type: String,
415    pub properties: std::collections::HashMap<String, serde_json::Value>,
416    pub styling: NodeStyling,
417}
418
419/// Graph edge representation
420#[derive(Debug, Clone, Serialize, Deserialize)]
421pub struct GraphEdge {
422    pub id: String,
423    pub source: String,
424    pub target: String,
425    pub label: Option<String>,
426    pub edge_type: String,
427    pub weight: Option<f64>,
428    pub properties: std::collections::HashMap<String, serde_json::Value>,
429    pub styling: EdgeStyling,
430}
431
432/// Graph metadata
433#[derive(Debug, Clone, Serialize, Deserialize)]
434pub struct GraphMetadata {
435    pub title: Option<String>,
436    pub description: Option<String>,
437    pub source: Option<String>,
438    pub node_count: usize,
439    pub edge_count: usize,
440    pub creation_time: chrono::DateTime<chrono::Utc>,
441}
442
443/// Graph layout configuration
444#[derive(Debug, Clone, Serialize, Deserialize)]
445pub struct GraphLayout {
446    pub algorithm: LayoutAlgorithm,
447    pub parameters: std::collections::HashMap<String, serde_json::Value>,
448    pub constraints: Vec<LayoutConstraint>,
449}
450
451/// Layout algorithm enumeration
452#[derive(Debug, Clone, Serialize, Deserialize)]
453pub enum LayoutAlgorithm {
454    ForceDirected,
455    Hierarchical,
456    Circular,
457    Grid,
458    Random,
459    Manual,
460}
461
462/// Layout constraint
463#[derive(Debug, Clone, Serialize, Deserialize)]
464pub struct LayoutConstraint {
465    pub constraint_type: ConstraintType,
466    pub target: String,
467    pub parameters: std::collections::HashMap<String, serde_json::Value>,
468}
469
470/// Constraint type enumeration
471#[derive(Debug, Clone, Serialize, Deserialize)]
472pub enum ConstraintType {
473    FixedPosition,
474    MinDistance,
475    MaxDistance,
476    Alignment,
477    Grouping,
478}
479
480/// Graph styling configuration
481#[derive(Debug, Clone, Serialize, Deserialize)]
482pub struct GraphStyling {
483    pub theme: GraphTheme,
484    pub colors: ColorScheme,
485    pub fonts: FontConfiguration,
486    pub effects: VisualEffects,
487}
488
489/// Graph theme enumeration
490#[derive(Debug, Clone, Serialize, Deserialize)]
491pub enum GraphTheme {
492    Light,
493    Dark,
494    HighContrast,
495    Minimal,
496    Professional,
497}
498
499/// Color scheme configuration
500#[derive(Debug, Clone, Serialize, Deserialize)]
501pub struct ColorScheme {
502    pub primary: String,
503    pub secondary: String,
504    pub accent: String,
505    pub background: String,
506    pub text: String,
507    pub edge: String,
508}
509
510/// Font configuration
511#[derive(Debug, Clone, Serialize, Deserialize)]
512pub struct FontConfiguration {
513    pub family: String,
514    pub size: u32,
515    pub weight: FontWeight,
516    pub style: FontStyle,
517}
518
519/// Font weight enumeration
520#[derive(Debug, Clone, Serialize, Deserialize)]
521pub enum FontWeight {
522    Normal,
523    Bold,
524    Light,
525    ExtraBold,
526}
527
528/// Font style enumeration
529#[derive(Debug, Clone, Serialize, Deserialize)]
530pub enum FontStyle {
531    Normal,
532    Italic,
533    Oblique,
534}
535
536/// Visual effects configuration
537#[derive(Debug, Clone, Serialize, Deserialize)]
538pub struct VisualEffects {
539    pub shadows: bool,
540    pub animations: bool,
541    pub hover_effects: bool,
542    pub selection_highlight: bool,
543    pub zoom_effects: bool,
544}
545
546/// Node styling configuration
547#[derive(Debug, Clone, Serialize, Deserialize)]
548pub struct NodeStyling {
549    pub shape: NodeShape,
550    pub size: NodeSize,
551    pub color: String,
552    pub border: BorderStyle,
553    pub icon: Option<String>,
554}
555
556/// Node shape enumeration
557#[derive(Debug, Clone, Serialize, Deserialize)]
558pub enum NodeShape {
559    Circle,
560    Square,
561    Triangle,
562    Diamond,
563    Hexagon,
564    Star,
565}
566
567/// Node size specification
568#[derive(Debug, Clone, Serialize, Deserialize)]
569pub enum NodeSize {
570    Small,
571    Medium,
572    Large,
573    Custom(u32),
574}
575
576/// Border style configuration
577#[derive(Debug, Clone, Serialize, Deserialize)]
578pub struct BorderStyle {
579    pub width: u32,
580    pub color: String,
581    pub style: LineStyle,
582}
583
584/// Line style enumeration
585#[derive(Debug, Clone, Serialize, Deserialize)]
586pub enum LineStyle {
587    Solid,
588    Dashed,
589    Dotted,
590    Double,
591}
592
593/// Edge styling configuration
594#[derive(Debug, Clone, Serialize, Deserialize)]
595pub struct EdgeStyling {
596    pub line_style: LineStyle,
597    pub color: String,
598    pub width: u32,
599    pub arrow: ArrowStyle,
600    pub curvature: Curvature,
601}
602
603/// Arrow style enumeration
604#[derive(Debug, Clone, Serialize, Deserialize)]
605pub enum ArrowStyle {
606    None,
607    Simple,
608    Filled,
609    Open,
610    Diamond,
611}
612
613/// Curvature specification
614#[derive(Debug, Clone, Serialize, Deserialize)]
615pub enum Curvature {
616    Straight,
617    Curved(f32),
618    Bezier { cp1: (f32, f32), cp2: (f32, f32) },
619}
620
621/// Chart type enumeration
622#[derive(Debug, Clone, Serialize, Deserialize)]
623pub enum ChartType {
624    Line,
625    Bar,
626    Pie,
627    Scatter,
628    Area,
629    Histogram,
630    Box,
631    Violin,
632    Heatmap,
633}
634
635/// Chart data structure
636#[derive(Debug, Clone, Serialize, Deserialize)]
637pub struct ChartData {
638    pub series: Vec<DataSeries>,
639    pub categories: Vec<String>,
640    pub metadata: ChartMetadata,
641}
642
643/// Data series for charts
644#[derive(Debug, Clone, Serialize, Deserialize)]
645pub struct DataSeries {
646    pub name: String,
647    pub data: Vec<DataPoint>,
648    pub color: Option<String>,
649    pub line_style: Option<LineStyle>,
650}
651
652/// Data point representation
653#[derive(Debug, Clone, Serialize, Deserialize)]
654pub struct DataPoint {
655    pub x: serde_json::Value,
656    pub y: serde_json::Value,
657    pub label: Option<String>,
658    pub metadata: Option<std::collections::HashMap<String, serde_json::Value>>,
659}
660
661/// Chart metadata
662#[derive(Debug, Clone, Serialize, Deserialize)]
663pub struct ChartMetadata {
664    pub source: Option<String>,
665    pub description: Option<String>,
666    pub units: Option<String>,
667    pub creation_time: chrono::DateTime<chrono::Utc>,
668}
669
670/// Chart axes configuration
671#[derive(Debug, Clone, Serialize, Deserialize)]
672pub struct ChartAxes {
673    pub x_axis: AxisConfiguration,
674    pub y_axis: AxisConfiguration,
675    pub secondary_y: Option<AxisConfiguration>,
676}
677
678/// Axis configuration
679#[derive(Debug, Clone, Serialize, Deserialize)]
680pub struct AxisConfiguration {
681    pub title: Option<String>,
682    pub scale: AxisScale,
683    pub range: Option<AxisRange>,
684    pub tick_format: Option<String>,
685    pub grid_lines: bool,
686}
687
688/// Axis scale enumeration
689#[derive(Debug, Clone, Serialize, Deserialize)]
690pub enum AxisScale {
691    Linear,
692    Logarithmic,
693    Time,
694    Category,
695}
696
697/// Axis range specification
698#[derive(Debug, Clone, Serialize, Deserialize)]
699pub struct AxisRange {
700    pub min: serde_json::Value,
701    pub max: serde_json::Value,
702}
703
704/// Chart styling configuration
705#[derive(Debug, Clone, Serialize, Deserialize)]
706pub struct ChartStyling {
707    pub theme: ChartTheme,
708    pub colors: Vec<String>,
709    pub fonts: FontConfiguration,
710    pub legend: LegendConfiguration,
711}
712
713/// Chart theme enumeration
714#[derive(Debug, Clone, Serialize, Deserialize)]
715pub enum ChartTheme {
716    Default,
717    Dark,
718    Light,
719    Minimal,
720    Professional,
721}
722
723/// Legend configuration
724#[derive(Debug, Clone, Serialize, Deserialize)]
725pub struct LegendConfiguration {
726    pub position: LegendPosition,
727    pub visible: bool,
728    pub orientation: LegendOrientation,
729}
730
731/// Legend position enumeration
732#[derive(Debug, Clone, Serialize, Deserialize)]
733pub enum LegendPosition {
734    Top,
735    Bottom,
736    Left,
737    Right,
738    TopLeft,
739    TopRight,
740    BottomLeft,
741    BottomRight,
742}
743
744/// Legend orientation enumeration
745#[derive(Debug, Clone, Serialize, Deserialize)]
746pub enum LegendOrientation {
747    Horizontal,
748    Vertical,
749}
750
751/// File preview for attachments
752#[derive(Debug, Clone, Serialize, Deserialize)]
753pub struct FilePreview {
754    pub preview_type: PreviewType,
755    pub content: String,
756    pub thumbnail_url: Option<String>,
757}
758
759/// Preview type enumeration
760#[derive(Debug, Clone, Serialize, Deserialize)]
761pub enum PreviewType {
762    Text,
763    Image,
764    Video,
765    Audio,
766    Document,
767    Code,
768}
769
770/// Widget type enumeration
771#[derive(Debug, Clone, Serialize, Deserialize)]
772pub enum WidgetType {
773    Slider,
774    Button,
775    Input,
776    Dropdown,
777    Toggle,
778    DatePicker,
779    ColorPicker,
780    Progress,
781}
782
783/// Widget configuration
784#[derive(Debug, Clone, Serialize, Deserialize)]
785pub struct WidgetConfig {
786    pub interactive: bool,
787    pub validation: Option<ValidationRules>,
788    pub events: Vec<WidgetEvent>,
789}
790
791/// Validation rules for widgets
792#[derive(Debug, Clone, Serialize, Deserialize)]
793pub struct ValidationRules {
794    pub required: bool,
795    pub min_value: Option<serde_json::Value>,
796    pub max_value: Option<serde_json::Value>,
797    pub pattern: Option<String>,
798    pub custom_validator: Option<String>,
799}
800
801/// Widget event configuration
802#[derive(Debug, Clone, Serialize, Deserialize)]
803pub struct WidgetEvent {
804    pub event_type: String,
805    pub handler: String,
806    pub parameters: std::collections::HashMap<String, serde_json::Value>,
807}
808
809/// Timeline event representation
810#[derive(Debug, Clone, Serialize, Deserialize)]
811pub struct TimelineEvent {
812    pub id: String,
813    pub title: String,
814    pub description: Option<String>,
815    pub timestamp: chrono::DateTime<chrono::Utc>,
816    pub duration: Option<Duration>,
817    pub event_type: String,
818    pub metadata: std::collections::HashMap<String, serde_json::Value>,
819}
820
821/// Timeline range specification
822#[derive(Debug, Clone, Serialize, Deserialize)]
823pub struct TimelineRange {
824    pub start: chrono::DateTime<chrono::Utc>,
825    pub end: chrono::DateTime<chrono::Utc>,
826    pub scale: TimelineScale,
827}
828
829/// Timeline scale enumeration
830#[derive(Debug, Clone, Serialize, Deserialize)]
831pub enum TimelineScale {
832    Minutes,
833    Hours,
834    Days,
835    Weeks,
836    Months,
837    Years,
838}
839
840/// Timeline styling configuration
841#[derive(Debug, Clone, Serialize, Deserialize)]
842pub struct TimelineStyling {
843    pub theme: TimelineTheme,
844    pub orientation: TimelineOrientation,
845    pub marker_style: MarkerStyle,
846    pub line_style: LineStyle,
847}
848
849/// Timeline theme enumeration
850#[derive(Debug, Clone, Serialize, Deserialize)]
851pub enum TimelineTheme {
852    Default,
853    Minimal,
854    Detailed,
855    Compact,
856}
857
858/// Timeline orientation enumeration
859#[derive(Debug, Clone, Serialize, Deserialize)]
860pub enum TimelineOrientation {
861    Horizontal,
862    Vertical,
863}
864
865/// Marker style for timeline events
866#[derive(Debug, Clone, Serialize, Deserialize)]
867pub struct MarkerStyle {
868    pub shape: MarkerShape,
869    pub size: u32,
870    pub color: String,
871    pub border: BorderStyle,
872}
873
874/// Marker shape enumeration
875#[derive(Debug, Clone, Serialize, Deserialize)]
876pub enum MarkerShape {
877    Circle,
878    Square,
879    Triangle,
880    Diamond,
881    Star,
882}
883
884/// Streaming response chunk for real-time communication
885#[derive(Debug, Clone, Serialize, Deserialize)]
886pub enum StreamResponseChunk {
887    /// Status update with processing stage and progress
888    Status {
889        stage: ProcessingStage,
890        progress: f32, // 0.0 to 1.0
891        message: Option<String>,
892    },
893    /// Context information found during retrieval
894    Context {
895        facts: Vec<String>,
896        sparql_results: Option<std::collections::HashMap<String, String>>,
897        entities: Vec<String>,
898    },
899    /// Incremental content being generated
900    Content { text: String, is_complete: bool },
901    /// Error occurred during processing
902    Error {
903        error: StructuredError,
904        recoverable: bool,
905    },
906    /// Processing complete with final message
907    Complete {
908        total_time: Duration,
909        token_count: usize,
910        final_message: Option<String>,
911    },
912}
913
914/// Stream processing stage identifiers
915#[derive(Debug, Clone, Serialize, Deserialize)]
916pub enum ProcessingStage {
917    Initializing,
918    RetrievingContext,
919    GeneratingSparql,
920    ExecutingQuery,
921    QuantumProcessing,
922    ConsciousnessProcessing,
923    AdvancedReasoning,
924    GeneratingResponse,
925    Finalizing,
926}
927
928impl ProcessingStage {
929    /// Get the human-readable name for the stage
930    pub fn display_name(&self) -> &'static str {
931        match self {
932            ProcessingStage::Initializing => "Initializing",
933            ProcessingStage::RetrievingContext => "Retrieving Context",
934            ProcessingStage::GeneratingSparql => "Generating SPARQL",
935            ProcessingStage::ExecutingQuery => "Executing Query",
936            ProcessingStage::QuantumProcessing => "Quantum Processing",
937            ProcessingStage::ConsciousnessProcessing => "Consciousness Processing",
938            ProcessingStage::AdvancedReasoning => "Advanced Reasoning",
939            ProcessingStage::GeneratingResponse => "Generating Response",
940            ProcessingStage::Finalizing => "Finalizing",
941        }
942    }
943
944    /// Get expected progress for each stage
945    pub fn expected_progress(&self) -> f32 {
946        match self {
947            ProcessingStage::Initializing => 0.0,
948            ProcessingStage::RetrievingContext => 0.1,
949            ProcessingStage::GeneratingSparql => 0.3,
950            ProcessingStage::ExecutingQuery => 0.5,
951            ProcessingStage::QuantumProcessing => 0.6,
952            ProcessingStage::ConsciousnessProcessing => 0.7,
953            ProcessingStage::AdvancedReasoning => 0.8,
954            ProcessingStage::GeneratingResponse => 0.9,
955            ProcessingStage::Finalizing => 1.0,
956        }
957    }
958}
959
960/// Quantum search result for quantum-enhanced visualizations
961#[derive(Debug, Clone, Serialize, Deserialize)]
962pub struct QuantumSearchResult {
963    pub triple: String,
964    pub score: f32,
965    pub quantum_amplitude: f32,
966    pub phase: f32,
967    pub entanglement_factor: f32,
968    pub coherence_time: f32,
969}
970
971/// Consciousness processing insight
972#[derive(Debug, Clone, Serialize, Deserialize)]
973pub struct ConsciousnessInsight {
974    pub content: String,
975    pub confidence: f32,
976    pub insight_type: ConsciousnessInsightType,
977    pub timestamp: chrono::DateTime<chrono::Utc>,
978}
979
980/// Type of consciousness insight
981#[derive(Debug, Clone, Serialize, Deserialize)]
982pub enum ConsciousnessInsightType {
983    MemoryTrace,
984    EmotionalResonance,
985    AttentionFocus,
986    MetacognitiveLearning,
987    TemporalCoherence,
988}
989
990/// Reasoning step in an advanced reasoning chain
991#[derive(Debug, Clone, Serialize, Deserialize)]
992pub struct ReasoningStep {
993    pub reasoning_type: ReasoningType,
994    pub premise_triples: Vec<String>,
995    pub conclusion_triple: Option<String>,
996    pub confidence: f32,
997    pub explanation: String,
998}
999
1000/// Type of reasoning used in a step
1001#[derive(Debug, Clone, Serialize, Deserialize)]
1002pub enum ReasoningType {
1003    Deductive,
1004    Inductive,
1005    Causal,
1006    Temporal,
1007    Analogical,
1008    Probabilistic,
1009}
1010
1011/// Enhanced streaming response chunk with more detailed error handling
1012#[derive(Debug, Clone, Serialize, Deserialize)]
1013pub enum EnhancedStreamResponseChunk {
1014    /// Status update with detailed stage information
1015    Status {
1016        stage: ProcessingStage,
1017        progress: f32,
1018        stage_details: String,
1019        estimated_remaining_ms: Option<u64>,
1020    },
1021    /// Context information with categorization
1022    Context {
1023        content: String,
1024        context_type: ContextType,
1025        confidence: f32,
1026    },
1027    /// Incremental content with metadata
1028    Content {
1029        content: String,
1030        is_final: bool,
1031        content_type: ContentType,
1032        word_count: usize,
1033    },
1034    /// Structured error with recovery suggestions
1035    Error {
1036        error: StructuredError,
1037        recovery_suggestions: Vec<String>,
1038        can_retry: bool,
1039    },
1040    /// Processing complete with comprehensive metadata
1041    Complete {
1042        message: Box<crate::Message>,
1043        total_time: Duration,
1044        performance_metrics: ProcessingMetrics,
1045    },
1046}
1047
1048/// Type of context information being streamed
1049#[derive(Debug, Clone, Serialize, Deserialize)]
1050pub enum ContextType {
1051    KnowledgeGraphFacts,
1052    EntityExtraction,
1053    SparqlGeneration,
1054    SparqlExecution,
1055    QuantumEnhancement,
1056    ConsciousnessInsights,
1057    ReasoningAnalysis,
1058}
1059
1060/// Type of content being streamed
1061#[derive(Debug, Clone, Serialize, Deserialize)]
1062pub enum ContentType {
1063    PlainText,
1064    FormattedText,
1065    RichContent,
1066    CodeBlock,
1067    Table,
1068    Visualization,
1069}
1070
1071/// Structured error information for better error handling
1072#[derive(Debug, Clone, Serialize, Deserialize)]
1073pub struct StructuredError {
1074    pub error_type: ErrorType,
1075    pub message: String,
1076    pub error_code: Option<String>,
1077    pub component: String,
1078    pub timestamp: chrono::DateTime<chrono::Utc>,
1079    pub context: std::collections::HashMap<String, serde_json::Value>,
1080}
1081
1082/// Type of error that occurred
1083#[derive(Debug, Clone, Serialize, Deserialize)]
1084pub enum ErrorType {
1085    RagRetrievalError,
1086    SparqlGenerationError,
1087    SparqlExecutionError,
1088    LlmGenerationError,
1089    QuantumProcessingError,
1090    ConsciousnessProcessingError,
1091    ReasoningError,
1092    NetworkError,
1093    TimeoutError,
1094    ValidationError,
1095    InternalError,
1096}
1097
1098/// Performance metrics for processing
1099#[derive(Debug, Clone, Serialize, Deserialize)]
1100pub struct ProcessingMetrics {
1101    pub total_time_ms: u64,
1102    pub rag_retrieval_time_ms: u64,
1103    pub sparql_generation_time_ms: u64,
1104    pub sparql_execution_time_ms: u64,
1105    pub llm_generation_time_ms: u64,
1106    pub quantum_processing_time_ms: u64,
1107    pub consciousness_processing_time_ms: u64,
1108    pub reasoning_time_ms: u64,
1109    pub memory_usage_mb: f32,
1110    pub cpu_usage_percent: f32,
1111    pub cache_hit_rate: f32,
1112    pub token_count: usize,
1113    pub request_size_bytes: usize,
1114    pub response_size_bytes: usize,
1115}
1116
1117// Enhanced context preservation types
1118
1119/// Conversation analysis for intelligent context compression
1120#[derive(Debug, Default, Clone)]
1121pub struct ConversationAnalysis {
1122    pub question_count: usize,
1123    pub resolved_questions: usize,
1124    pub unresolved_questions: usize,
1125    pub assistant_response_count: usize,
1126    pub error_mentions: usize,
1127    pub code_examples: usize,
1128}
1129
1130/// Key concept extracted from conversation
1131#[derive(Debug, Clone)]
1132pub struct KeyConcept {
1133    pub name: String,
1134    pub frequency: usize,
1135    pub importance: f32,
1136    pub context: String,
1137}
1138
1139/// Key outcome or decision from conversation
1140#[derive(Debug, Clone)]
1141pub struct KeyOutcome {
1142    pub description: String,
1143    pub message_id: String,
1144    pub outcome_type: OutcomeType,
1145    pub confidence: f32,
1146}
1147
1148/// Type of outcome identified in conversation
1149#[derive(Debug, Clone)]
1150pub enum OutcomeType {
1151    Solution,
1152    Decision,
1153    Example,
1154    Error,
1155    Recommendation,
1156}
1157
1158/// User interaction patterns for personalization
1159#[derive(Debug, Default, Clone)]
1160pub struct InteractionPatterns {
1161    pub user_message_count: usize,
1162    pub average_user_message_length: usize,
1163    pub complex_questions: usize,
1164    pub simple_questions: usize,
1165    pub technical_messages: usize,
1166    pub preferred_response_style: Option<String>,
1167}
1168
1169// Additional types for compatibility with server.rs
1170
1171/// Thread information for message threads
1172#[derive(Debug, Clone, Serialize, Deserialize)]
1173pub struct ThreadInfo {
1174    pub thread_id: String,
1175    pub title: Option<String>,
1176    pub message_count: usize,
1177    pub created_at: DateTime<Utc>,
1178    pub last_activity: DateTime<Utc>,
1179}
1180
1181/// Session statistics for system monitoring
1182// Updated SessionStats with all fields
1183#[derive(Debug, Clone, Serialize, Deserialize)]
1184pub struct SessionStats {
1185    pub total_sessions: usize,
1186    pub active_sessions: usize,
1187    pub idle_sessions: usize,
1188    pub expired_sessions: usize,
1189    pub suspended_sessions: usize,
1190    pub total_messages: usize,
1191    pub total_tokens: usize,
1192    pub avg_response_time_ms: f64,
1193    pub uptime_seconds: u64,
1194}