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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
//! Business event types for LLM operations.
//!
//! This module provides types for tracking LLM interactions for observability,
//! analytics, and debugging. Events can track request/response cycles, cache
//! hits/misses, errors, and custom application events.
//!
//! # Feature Flag
//!
//! This module requires the `events` feature:
//!
//! ```toml
//! [dependencies]
//! multi-llm = { version = "...", features = ["events"] }
//! ```
//!
//! # Usage
//!
//! ```rust,ignore
//! use multi_llm::{BusinessEvent, EventScope, event_types};
//!
//! // Create a custom event
//! let event = BusinessEvent::new(event_types::LLM_REQUEST)
//! .with_metadata("model", "gpt-4")
//! .with_metadata("prompt_tokens", 150);
//!
//! // Specify event scope
//! let scope = EventScope::User("user_123".to_string());
//! ```
//!
//! # Event Types
//!
//! Pre-defined event types are available in [`event_types`]:
//! - `LLM_REQUEST`: LLM request initiated
//! - `LLM_RESPONSE`: LLM response received
//! - `LLM_ERROR`: LLM request failed
//! - `CACHE_HIT`: Prompt cache hit
//! - `CACHE_MISS`: Prompt cache miss
//! - `ERROR`: Generic error event
use ;
use ;
use Uuid;
/// Business event for analytics and observability.
///
/// Events capture significant moments during LLM operations. Each event has:
/// - A unique ID for deduplication
/// - An event type for categorization
/// - Flexible metadata as JSON
/// - A creation timestamp
///
/// # Example
///
/// ```rust,ignore
/// use multi_llm::BusinessEvent;
///
/// let event = BusinessEvent::new("custom_event")
/// .with_metadata("user_id", "u123")
/// .with_metadata("action", "query")
/// .with_metadata("duration_ms", 150);
/// ```
///
/// # Feature Flag
///
/// Requires the `events` feature to be enabled.
/// Scope determining where events should be stored.
///
/// Events can be scoped to individual users (for user-specific analytics)
/// or to the system level (for global metrics and monitoring).
///
/// # Example
///
/// ```rust,ignore
/// use multi_llm::EventScope;
///
/// // User-specific event
/// let user_scope = EventScope::User("user_123".to_string());
///
/// // System-wide event
/// let system_scope = EventScope::System;
/// ```
///
/// # Feature Flag
///
/// Requires the `events` feature to be enabled.
/// Pre-defined event type constants for consistency.
///
/// Use these constants when creating events to ensure consistent
/// event type strings across your application.
///
/// # Example
///
/// ```rust,ignore
/// use multi_llm::{BusinessEvent, event_types};
///
/// let event = BusinessEvent::new(event_types::LLM_REQUEST);
/// ```
///
/// # Feature Flag
///
/// Requires the `events` feature to be enabled.