1pub mod agent;
14pub mod chat_history;
15pub mod council_approvals;
16pub mod council_repository;
17pub mod download;
18pub mod download_event_emitter;
19pub mod download_manager;
20pub mod download_state;
21pub mod event_emitter;
22pub mod gguf_parser;
23pub mod huggingface;
24pub mod llm_completion;
25pub mod mcp_dto;
26pub mod mcp_error;
27pub mod mcp_repository;
28pub mod model_catalog;
29pub mod model_registrar;
30pub mod model_repository;
31pub mod model_runtime;
32pub mod process_runner;
33pub mod server_health;
34pub mod server_log_sink;
35pub mod settings_repository;
36pub mod structured_llm;
37pub mod system_probe;
38pub mod tool_executor_filter;
39pub mod tool_support;
40
41use std::sync::Arc;
42use thiserror::Error;
43
44pub use agent::{AgentError, AgentLoopPort, AgentRunOutput, ToolExecutorPort};
46pub use llm_completion::{LlmCompletionPort, ResponseFormat};
48pub use structured_llm::StructuredOutputError;
50pub use tool_executor_filter::{EmptyToolExecutor, FilteredToolExecutor, TOOL_NOT_AVAILABLE_MSG};
52
53pub use chat_history::{ChatHistoryError, ChatHistoryRepository};
55pub use council_approvals::{ApprovalDecision, CouncilApprovalRegistryPort};
56pub use council_repository::CouncilRepositoryPort;
57pub use download::{QuantizationResolver, Resolution, ResolvedFile};
58pub use download_event_emitter::{AppEventBridge, DownloadEventEmitterPort, NoopDownloadEmitter};
59pub use download_manager::{DownloadManagerConfig, DownloadManagerPort, DownloadRequest};
60pub use download_state::DownloadStateRepositoryPort;
61pub use event_emitter::{AppEventEmitter, NoopEmitter};
62pub use gguf_parser::{
63 GgufCapabilities, GgufMetadata, GgufParseError, GgufParserPort, NoopGgufParser,
64};
65pub use huggingface::{
66 HfClientPort, HfFileInfo, HfPortError, HfQuantInfo, HfRepoInfo, HfSearchOptions, HfSearchResult,
67};
68pub use mcp_dto::{ResolutionAttempt, ResolutionStatus};
69pub use mcp_error::{McpErrorCategory, McpErrorInfo, McpServiceError};
70pub use mcp_repository::{McpRepositoryError, McpServerRepository};
71pub use model_catalog::{CatalogError, ModelCatalogPort, ModelLaunchSpec, ModelSummary};
72pub use model_registrar::{CompletedDownload, ModelRegistrarPort};
73pub use model_repository::ModelRepository;
74pub use model_runtime::{ModelRuntimeError, ModelRuntimePort, RunningTarget};
75pub use process_runner::{ProcessHandle, ProcessRunner, ServerConfig, ServerHealth};
76pub use server_health::ServerHealthStatus;
77pub use server_log_sink::ServerLogSinkPort;
78pub use settings_repository::SettingsRepository;
79pub use system_probe::{SystemProbeError, SystemProbePort, SystemProbeResult};
80pub use tool_support::{
81 ModelSource, ToolFormat, ToolSupportDetection, ToolSupportDetectionInput,
82 ToolSupportDetectorPort,
83};
84
85#[derive(Clone)]
102pub struct Repos {
103 pub models: Arc<dyn ModelRepository>,
105 pub settings: Arc<dyn SettingsRepository>,
107 pub mcp_servers: Arc<dyn McpServerRepository>,
109 pub chat_history: Arc<dyn ChatHistoryRepository>,
111}
112
113impl Repos {
114 pub fn new(
116 models: Arc<dyn ModelRepository>,
117 settings: Arc<dyn SettingsRepository>,
118 mcp_servers: Arc<dyn McpServerRepository>,
119 chat_history: Arc<dyn ChatHistoryRepository>,
120 ) -> Self {
121 Self {
122 models,
123 settings,
124 mcp_servers,
125 chat_history,
126 }
127 }
128}
129
130#[derive(Debug, Error)]
135pub enum RepositoryError {
136 #[error("Not found: {0}")]
138 NotFound(String),
139
140 #[error("Already exists: {0}")]
142 AlreadyExists(String),
143
144 #[error("Storage error: {0}")]
146 Storage(String),
147
148 #[error("Serialization error: {0}")]
150 Serialization(String),
151
152 #[error("Constraint violation: {0}")]
154 Constraint(String),
155}
156
157#[derive(Debug, Error)]
162pub enum ProcessError {
163 #[error("Failed to start: {0}")]
165 StartFailed(String),
166
167 #[error("Failed to stop: {0}")]
169 StopFailed(String),
170
171 #[error("Process not running: {0}")]
173 NotRunning(String),
174
175 #[error("Health check failed: {0}")]
177 HealthCheckFailed(String),
178
179 #[error("Configuration error: {0}")]
181 Configuration(String),
182
183 #[error("Resource exhaustion: {0}")]
185 ResourceExhausted(String),
186
187 #[error("Internal error: {0}")]
189 Internal(String),
190}
191
192#[derive(Debug, Error)]
198pub enum CoreError {
199 #[error(transparent)]
201 Repository(#[from] RepositoryError),
202
203 #[error(transparent)]
205 Process(#[from] ProcessError),
206
207 #[error(transparent)]
209 Settings(#[from] crate::settings::SettingsError),
210
211 #[error("Validation error: {0}")]
213 Validation(String),
214
215 #[error("Configuration error: {0}")]
217 Configuration(String),
218
219 #[error("External service error: {0}")]
221 ExternalService(String),
222
223 #[error("Internal error: {0}")]
225 Internal(String),
226}