File size: 1,337 Bytes
d90101d | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | use forge_tracker::{EventKind, ToolCallPayload};
use crate::TRACKER;
/// Helper functions to eliminate duplication of tokio::spawn + TRACKER patterns
/// Generic dispatcher for any event
fn dispatch(event: EventKind) {
tokio::spawn(TRACKER.dispatch(event));
}
/// Dispatches an event blockingly
/// This is useful for events that are not expected to be dispatched in the
/// background
fn dispatch_blocking(event: EventKind) {
tokio::task::block_in_place(|| {
tokio::runtime::Handle::current().block_on(TRACKER.dispatch(event))
})
.ok();
}
/// For error events with Debug formatting
pub fn error<E: std::fmt::Debug>(error: E) {
dispatch(EventKind::Error(format!("{error:?}")));
}
pub fn error_blocking<E: std::fmt::Debug>(error: E) {
dispatch_blocking(EventKind::Error(format!("{error:?}")));
}
/// For error events with string input
pub fn error_string(error: String) {
dispatch(EventKind::Error(error));
}
/// For tool call events
pub fn tool_call(payload: ToolCallPayload) {
dispatch(EventKind::ToolCall(payload));
}
/// For prompt events
pub fn prompt(text: String) {
dispatch(EventKind::Prompt(text));
}
/// For model setting
pub fn set_model(model: String) {
tokio::spawn(TRACKER.set_model(model));
}
pub fn login(login: String) {
tokio::spawn(TRACKER.login(login));
}
|