agent_core/lib.rs
1//! `agent-core` — foundational types, config, session, auth, logging,
2//! protocol, memory, and pricing. Leaf crate: no in-repo upward deps.
3
4pub mod core;
5pub mod memory;
6pub mod pricing;
7
8// Re-export stream event types at crate root so engine/tui can import them
9// cleanly as `agent_core::{StreamEvent, LlmEvent, ...}` without digging
10// into the internal module path.
11pub use core::stream_types::{AgentEvent, LlmEvent, SessionEvent, StreamEvent};
12
13// Replicate the root lib.rs aliases so internal `crate::config`,
14// `crate::models`, `crate::session`, etc. resolve INSIDE agent-core.
15pub use core::config;
16pub use core::session;
17pub use core::auth;
18pub use core::logging;
19pub use core::protocol;
20pub use core::error;
21pub use core::watcher_types;
22pub use core::models;
23pub use core::chain;
24
25/// Current time as Unix epoch milliseconds. Panics only if system clock is before 1970.
26#[inline]
27pub fn epoch_millis() -> u64 {
28 std::time::SystemTime::now()
29 .duration_since(std::time::UNIX_EPOCH)
30 .expect("system clock before Unix epoch")
31 .as_millis() as u64
32}
33
34// Expose Result + RuntimeError at crate root so `crate::Result<T>` resolves
35// inside agent-core modules (mirrors root lib.rs lines 28-29).
36pub use error::{Result, RuntimeError};
37
38/// Truncate a string to at most `max` bytes at a valid UTF-8 boundary.
39#[inline]
40pub fn truncate_str(s: &str, max: usize) -> &str {
41 if s.len() <= max {
42 return s;
43 }
44 let mut end = max;
45 while end > 0 && !s.is_char_boundary(end) {
46 end -= 1;
47 }
48 &s[..end]
49}