Skip to main content

Crate spn_core

Crate spn_core 

Source
Expand description

spn-core: Core types and validation for the SuperNovae ecosystem.

This crate provides:

  • Provider definitions (13+ LLM and MCP service providers)
  • Key format validation with detailed error messages
  • MCP server configuration types
  • Package registry types

§Design Principles

  • Zero dependencies: Pure Rust, fast compilation, WASM-compatible
  • Single source of truth: All provider definitions in one place
  • Shared types: Used by spn-cli, spn-client, spn-keyring, and nika

§Example

use spn_core::{
    Provider, ProviderCategory, KNOWN_PROVIDERS,
    find_provider, provider_to_env_var,
    validate_key_format, mask_key, ValidationResult,
};

// Find a provider
let provider = find_provider("anthropic").unwrap();
assert_eq!(provider.env_var, "ANTHROPIC_API_KEY");

// Validate a key format
match validate_key_format("anthropic", "sk-ant-api03-xxx") {
    ValidationResult::Valid => println!("Key is valid!"),
    ValidationResult::InvalidPrefix { expected, .. } => {
        println!("Key should start with: {}", expected);
    }
    _ => {}
}

// Mask a key for display
let masked = mask_key("sk-ant-secret-key-12345");
assert_eq!(masked, "sk-ant-••••••••");

Structs§

ChatMessage
A message in a chat conversation.
ChatOptions
Options for chat completion.
ChatResponse
Response from a chat completion.
EmbeddingResponse
Response from an embedding request.
GpuInfo
GPU device information.
LoadConfig
Configuration for loading a model.
McpConfig
Complete MCP configuration containing multiple servers.
McpServer
MCP server configuration.
ModelInfo
Information about an installed model.
PackageManifest
Package manifest (spn.yaml content).
PackageRef
Reference to a package in the registry.
Provider
Provider metadata.
PullProgress
Progress information during model pull/download.
RunningModel
Information about a currently running/loaded model.

Enums§

BackendError
Error types for backend operations.
ChatRole
Role in a chat conversation.
McpServerType
Type of MCP server transport.
McpSource
Source of an MCP configuration.
PackageType
Type of package in the registry.
ProviderCategory
Category of provider service.
Source
Source of a package - where to fetch the actual content.
ValidationResult
Result of key format validation.

Statics§

KNOWN_PROVIDERS
All known providers in the SuperNovae ecosystem.

Functions§

find_provider
Find a provider by ID (case-insensitive).
mask_key
Mask an API key for safe display.
provider_to_env_var
Get the environment variable name for a provider.
providers_by_category
Get all providers in a specific category.
validate_key_format
Validate an API key format for a specific provider.