1pub mod builder;
2pub mod capture;
3pub mod context;
4pub mod eval;
5pub mod events;
6pub mod hitl;
7pub mod replay;
8
9pub use builder::{
10 SpanBuilder, agent as build_agent, llm_call as build_llm_call, tool as build_tool,
11};
12pub use capture::{
13 CaptureConfig, capture_enabled, capture_json, capture_policy, init_capture, redact_text,
14};
15pub use context::{SpanContext, current_span_context, scope_current};
16pub use events::{EventBuilder, event};
17
18pub use hitl::{HitlResponse, get_pending_approvals, register_approval, resolve_approval};
19pub use replay::{ReplayConfig, init_replay};
20
21pub use trace_weft_core::*;
22
23pub use trace_weft_macros::{agent, llm_call, tool};
24pub use trace_weft_recorder::{LocalConfig, LocalRecorder, NullStore, TraceStore};
25
26pub use serde_json;
29pub use uuid;
30
31use std::sync::Arc;
32use tokio::sync::OnceCell;
33
34static RECORDER: OnceCell<Arc<dyn TraceStore>> = OnceCell::const_new();
35
36pub async fn init_local(config: LocalConfig) -> anyhow::Result<()> {
37 let policy = config.capture_content;
38 let blob_dir = config.blob_dir.clone();
39
40 let recorder = LocalRecorder::new(config).await?;
41 init_custom(Arc::new(recorder))?;
42
43 init_capture(CaptureConfig {
44 policy,
45 blobs: Arc::new(capture::FsBlobStore::new(blob_dir)),
46 redactor: Arc::new(trace_weft_core::redactor::RegexRedactor::default()),
47 storage_backend: "local_fs".to_string(),
48 })
49}
50
51pub fn init_custom(store: Arc<dyn TraceStore>) -> anyhow::Result<()> {
52 RECORDER
53 .set(store)
54 .map_err(|_| anyhow::anyhow!("Already initialized"))?;
55
56 if let Some(replay_config) = ReplayConfig::load_from_env() {
58 init_replay(replay_config);
59 }
60
61 Ok(())
62}
63
64pub async fn record_span(span: SpanRecord) {
65 if let Some(recorder) = RECORDER.get() {
66 let _ = recorder.record_span(span).await;
67 }
68}
69
70pub async fn record_event(event: EventRecord) {
71 if let Some(recorder) = RECORDER.get() {
72 let _ = recorder.record_event(event).await;
73 }
74}