lc/lib.rs
1//! LC (LLM Client) Library
2//!
3//! This library provides the core functionality for the LC CLI tool,
4//! including configuration management, provider handling, and chat functionality.
5//!
6//! # Platform Differences
7//!
8//! This crate includes platform-specific features that are only available on certain operating systems:
9//!
10//! ## Unix Socket Support
11//!
12//! Unix socket functionality is only available on Unix-like systems (Linux, macOS, BSD, WSL2) and requires
13//! the `unix-sockets` feature to be enabled.
14//!
15//! ### MCP Daemon
16//!
17//! The MCP (Model Context Protocol) daemon functionality uses Unix domain sockets for inter-process
18//! communication and is therefore only available on Unix systems:
19//!
20//! - **Unix systems** (Linux, macOS, WSL2): Full MCP daemon support with persistent connections
21//! - **Windows**: MCP daemon is not supported; direct MCP connections work on all platforms
22//!
23//! ## Usage Statistics
24//!
25//! Usage statistics functionality works on all platforms (Windows, macOS, Linux, WSL2).
26//! It uses SQLite database which has full cross-platform support.
27//!
28//! ### Feature Flags
29//!
30//! - `unix-sockets`: Enables Unix socket functionality (default on Unix systems)
31//! - `pdf`: Enables PDF processing support (default)
32//!
33//! To build without Unix socket support:
34//! ```bash
35//! cargo build --no-default-features --features pdf
36//! ```
37//!
38//! To build with all features:
39//! ```bash
40//! cargo build --features "unix-sockets,pdf"
41//! ```
42
43// CLI modules
44pub mod cli;
45
46// Core modules
47pub mod core;
48// Re-export core modules at the top level for compatibility
49pub use core::chat;
50pub use core::completion;
51pub use core::http_client;
52pub use core::provider;
53pub use core::provider_installer;
54
55// Data modules
56pub mod data;
57// Re-export data modules at the top level for compatibility
58pub use data::config;
59pub use data::database;
60pub use data::keys;
61pub use data::vector_db;
62
63// Model-related modules
64pub mod models;
65// Re-export models modules at the top level for compatibility
66pub use models::cache as models_cache;
67pub use models::dump_metadata;
68pub use models::metadata as model_metadata;
69pub use models::unified_cache;
70
71// Service modules
72pub mod services;
73// Re-export service modules at the top level for compatibility
74pub use services::mcp;
75pub use services::proxy;
76// MCP daemon module - Unix implementation with Windows stubs
77// On Windows, all daemon functions return appropriate "unsupported" errors
78pub use services::mcp_daemon;
79pub use services::webchatproxy;
80
81// Utility modules
82pub mod utils;
83// Re-export utility modules at the top level for compatibility
84pub use utils::audio as audio_utils;
85pub use utils::image as image_utils;
86pub use utils::input;
87pub use utils::template_processor;
88pub use utils::test as test_utils;
89pub use utils::token as token_utils;
90
91// Analytics modules
92pub mod analytics;
93// Re-export analytics modules at the top level for compatibility
94pub use analytics::usage_stats;
95
96// Standalone modules (not yet categorized)
97pub mod error;
98pub mod readers;
99pub mod search;
100pub mod sync;
101
102// Global debug flag
103use std::sync::atomic::AtomicBool;
104pub static DEBUG_MODE: AtomicBool = AtomicBool::new(false);
105
106// Debug logging macro
107#[macro_export]
108macro_rules! debug_log {
109 ($($arg:tt)*) => {
110 if $crate::DEBUG_MODE.load(std::sync::atomic::Ordering::Relaxed) {
111 use colored::Colorize;
112 eprintln!("{} {}", "[DEBUG]".dimmed(), format!($($arg)*));
113 }
114 };
115}
116
117// Re-export commonly used types for easier access in tests
118pub use config::{CachedToken, Config, ProviderConfig};
119pub use provider::{ChatRequest, Message, OpenAIClient};