use crate::event::Properties;
use mesh_llm_build_info::{BUILD_VERSION, is_sha_build};
pub const LIB_NAME: &str = "mesh-llm-rust";
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum BuildChannel {
Release,
Prerelease,
Development,
}
impl BuildChannel {
#[must_use]
pub const fn as_str(self) -> &'static str {
match self {
Self::Release => "release",
Self::Prerelease => "prerelease",
Self::Development => "development",
}
}
#[must_use]
pub fn classify(version: &str) -> Self {
if is_sha_build(version) {
Self::Development
} else if version.contains('-') {
Self::Prerelease
} else {
Self::Release
}
}
}
#[must_use]
pub const fn os_family() -> &'static str {
if cfg!(target_os = "macos") {
"macos"
} else if cfg!(target_os = "linux") {
"linux"
} else if cfg!(target_os = "windows") {
"windows"
} else {
"other"
}
}
#[must_use]
pub fn exec_env() -> &'static str {
if crate::consent::detect_ci() {
"ci"
} else if in_container() {
"container"
} else if in_service_manager() {
"service"
} else {
"plain"
}
}
fn in_container() -> bool {
std::path::Path::new("/.dockerenv").exists()
|| std::path::Path::new("/run/.containerenv").exists()
|| env_is_set("container")
|| env_is_set("KUBERNETES_SERVICE_HOST")
}
fn in_service_manager() -> bool {
env_is_set("INVOCATION_ID")
}
fn env_is_set(key: &str) -> bool {
std::env::var_os(key).is_some_and(|value| !value.is_empty())
}
#[must_use]
pub const fn architecture() -> &'static str {
if cfg!(target_arch = "aarch64") {
"aarch64"
} else if cfg!(target_arch = "x86_64") {
"x86_64"
} else {
"other"
}
}
#[must_use]
pub fn base_properties() -> Properties {
Properties::new()
.with(
"mesh_llm_version",
crate::Label::sanitize_or_redact(BUILD_VERSION),
)
.with(
"build_channel",
BuildChannel::classify(BUILD_VERSION).as_str(),
)
.with("os", os_family())
.with("arch", architecture())
.with("exec_env", exec_env())
.with("$lib", LIB_NAME)
.with(
"$lib_version",
crate::Label::sanitize_or_redact(BUILD_VERSION),
)
}
#[cfg(test)]
#[path = "properties/tests.rs"]
mod tests;