Skip to main content

hyperinfer_core/
lib.rs

1//! Core types, traits, and error handling for HyperInfer
2//!
3//! This crate contains shared data structures, traits, and error definitions
4//! used across the entire HyperInfer monorepo.
5
6#![allow(clippy::double_must_use)]
7
8pub mod error;
9pub mod rate_limiting;
10pub mod redis;
11pub mod telemetry_consumer;
12pub mod traits;
13pub mod types;
14
15pub use error::{ConfigError, DbError, HyperInferError};
16pub use rate_limiting::{RateLimiter, USAGE_REQUESTS_KEY_PREFIX, USAGE_TOKENS_KEY_PREFIX};
17pub use redis::PolicyUpdate;
18pub use telemetry_consumer::TelemetryConsumer;
19pub use traits::{
20    ApiKey, ConfigStore, Database, ModelAlias, NewUsageLog, Quota, Team, UsageLog, UsageSummary,
21    User,
22};
23pub use types::{
24    ChatChunk, ChatMessage, ChatRequest, ChatResponse, Choice, Config, ContentPart,
25    CreateDeploymentRequest, Deployment, ImageUrl, MessageRole, Provider, RoutingConfig,
26    RoutingRule, ToolCall, ToolDefinition, UpdateRoutingConfigRequest, Usage, UsageRecord,
27};
28
29/// SHA-256 hash of a key, returned as a hex string.
30pub fn hash_key(key: &str) -> String {
31    use sha2::{Digest, Sha256};
32    let mut hasher = Sha256::new();
33    hasher.update(key.as_bytes());
34    hex::encode(hasher.finalize())
35}
36
37/// Truncated hash suffix of a key for safe logging (last 8 hex chars).
38pub fn key_id(key: &str) -> String {
39    let hash = hash_key(key);
40    if hash.len() >= 8 {
41        format!("...{}", &hash[hash.len() - 8..])
42    } else {
43        hash
44    }
45}