Skip to main content

spn_core/
lib.rs

1//! spn-core: Core types and validation for the SuperNovae ecosystem.
2//!
3//! This crate provides:
4//! - Provider definitions (13+ LLM and MCP service providers)
5//! - Key format validation with detailed error messages
6//! - MCP server configuration types
7//! - Package registry types
8//!
9//! # Design Principles
10//!
11//! - **Zero dependencies**: Pure Rust, fast compilation, WASM-compatible
12//! - **Single source of truth**: All provider definitions in one place
13//! - **Shared types**: Used by spn-cli, spn-client, spn-keyring, and nika
14//!
15//! # Example
16//!
17//! ```
18//! use spn_core::{
19//!     Provider, ProviderCategory, KNOWN_PROVIDERS,
20//!     find_provider, provider_to_env_var,
21//!     validate_key_format, mask_key, ValidationResult,
22//! };
23//!
24//! // Find a provider
25//! let provider = find_provider("anthropic").unwrap();
26//! assert_eq!(provider.env_var, "ANTHROPIC_API_KEY");
27//!
28//! // Validate a key format
29//! match validate_key_format("anthropic", "sk-ant-api03-xxx") {
30//!     ValidationResult::Valid => println!("Key is valid!"),
31//!     ValidationResult::InvalidPrefix { expected, .. } => {
32//!         println!("Key should start with: {}", expected);
33//!     }
34//!     _ => {}
35//! }
36//!
37//! // Mask a key for display
38//! let masked = mask_key("sk-ant-secret-key-12345");
39//! assert_eq!(masked, "sk-ant-••••••••");
40//! ```
41
42#![forbid(unsafe_code)]
43#![warn(missing_docs)]
44#![warn(clippy::all)]
45
46mod backend;
47mod mcp;
48mod providers;
49mod registry;
50mod validation;
51
52// Re-export everything at crate root for ergonomic imports
53pub use providers::{
54    find_provider, provider_to_env_var, providers_by_category, Provider, ProviderCategory,
55    KNOWN_PROVIDERS,
56};
57
58pub use validation::{mask_key, validate_key_format, ValidationResult};
59
60pub use mcp::{McpConfig, McpServer, McpServerType, McpSource};
61
62pub use registry::{PackageManifest, PackageRef, PackageType, Source};
63
64pub use backend::{
65    BackendError, ChatMessage, ChatOptions, ChatResponse, ChatRole, EmbeddingResponse, GpuInfo,
66    LoadConfig, ModelInfo, PullProgress, RunningModel,
67};