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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
//! # Reputation Types
//!
//! Core data types for the MCP agent reputation system.
//!
//! This crate provides the fundamental data structures used throughout
//! the reputation system, including agent data, reputation scores,
//! and a builder for constructing agent instances.
// Forbid unsafe code to ensure memory safety
//!
//! ## Key Types
//!
//! - [`AgentData`]: Represents an MCP agent with all reputation-relevant data
//! - [`ReputationScore`]: The calculated reputation score with confidence
//! - [`AgentDataBuilder`]: Fluent builder for constructing `AgentData`
//!
//! ## Examples
//!
//! ### Creating Agent Data
//!
//! ```
//! use reputation_types::{AgentData, AgentDataBuilder};
//!
//! // Using the builder (recommended)
//! let agent = AgentDataBuilder::new("did:example:123")
//! .total_interactions(150)
//! .with_reviews(100, 4.5)
//! .mcp_level(2)
//! .identity_verified(true)
//! .build()
//! .unwrap();
//!
//! // Or use the convenience method
//! let agent = AgentData::builder("did:example:456")
//! .total_interactions(60)
//! .with_reviews(50, 3.8)
//! .build()
//! .unwrap();
//! ```
use ;
use ;
pub use ;
/// Confidence level categorization based on confidence value
///
/// This enum categorizes the confidence score into three levels
/// to help users quickly understand how reliable a reputation score is.
///
/// # Thresholds
///
/// - `Low`: confidence < 0.2 (limited data)
/// - `Medium`: 0.2 ≤ confidence < 0.7 (moderate data)
/// - `High`: confidence ≥ 0.7 (substantial data)
/// Detailed breakdown of score components
///
/// Provides transparency into how the final reputation score
/// was calculated, showing the contribution of each component.
/// Breakdown of prior score components
///
/// Shows how each credential and bonus contributes
/// to the total prior reputation score.
/// Represents an MCP agent with all reputation-relevant data
///
/// This struct contains all the information needed to calculate
/// a reputation score for an agent, including credentials,
/// review statistics, and verification status.
///
/// # Fields
///
/// - `did`: Decentralized identifier (must follow did:method:identifier format)
/// - `created_at`: When the agent was first registered
/// - `mcp_level`: MCP certification level (0-3, if any)
/// - `identity_verified`: Whether identity has been verified
/// - `security_audit_passed`: Whether security audit passed
/// - `open_source`: Whether the agent is open source
/// - `total_interactions`: Total number of interactions
/// - `total_reviews`: Total number of reviews received
/// - `average_rating`: Average rating (1.0-5.0 scale)
/// - `positive_reviews`: Count of positive reviews
/// - `negative_reviews`: Count of negative reviews
///
/// # Example
///
/// ```
/// use reputation_types::AgentData;
/// use chrono::Utc;
///
/// let agent = AgentData {
/// did: "did:example:123".to_string(),
/// created_at: Utc::now(),
/// mcp_level: Some(2),
/// identity_verified: true,
/// security_audit_passed: false,
/// open_source: true,
/// total_interactions: 500,
/// total_reviews: 100,
/// average_rating: Some(4.2),
/// positive_reviews: 80,
/// negative_reviews: 20,
/// };
/// ```
/// The calculated reputation score for an agent
///
/// Contains the final reputation score along with detailed metadata
/// about how it was calculated, component breakdowns, and confidence level.
///
/// # Fields
///
/// - `score`: The final reputation score (0-100)
/// - `confidence`: How confident we are in the score (0-1)
/// - `level`: Categorized confidence level (Low/Medium/High)
/// - `components`: Detailed breakdown of score components
/// - `is_provisional`: Whether score is provisional (confidence < 0.2)
/// - `data_points`: Total data points used (interactions + reviews)
/// - `algorithm_version`: Version of algorithm used
/// - `calculated_at`: When the score was calculated
///
/// # Interpretation
///
/// ## Score Ranges
/// - 0-20: Very poor reputation
/// - 20-40: Poor reputation
/// - 40-60: Average reputation
/// - 60-80: Good reputation
/// - 80-100: Excellent reputation
///
/// ## Confidence Levels
/// - Low (0-0.2): Limited data, provisional score
/// - Medium (0.2-0.7): Moderate confidence
/// - High (0.7-1.0): High confidence, substantial data
///
/// # Example
///
/// ```
/// use reputation_types::{ReputationScore, ConfidenceLevel, ScoreComponents, PriorBreakdown};
/// use chrono::Utc;
///
/// # let components = ScoreComponents {
/// # prior_score: 65.0,
/// # prior_breakdown: PriorBreakdown {
/// # base_score: 50.0,
/// # mcp_bonus: 10.0,
/// # identity_bonus: 5.0,
/// # security_audit_bonus: 0.0,
/// # open_source_bonus: 0.0,
/// # age_bonus: 0.0,
/// # total: 65.0,
/// # },
/// # empirical_score: 80.0,
/// # confidence_value: 0.85,
/// # confidence_level: ConfidenceLevel::High,
/// # prior_weight: 0.15,
/// # empirical_weight: 0.85,
/// # };
/// #
/// let score = ReputationScore {
/// score: 75.5,
/// confidence: 0.85,
/// level: ConfidenceLevel::High,
/// components,
/// is_provisional: false,
/// data_points: 150,
/// algorithm_version: "1.0.0".to_string(),
/// calculated_at: Utc::now(),
/// };
///
/// if score.is_provisional {
/// println!("Provisional score: {:.1} (needs more data)", score.score);
/// } else {
/// println!("{:?} confidence score: {:.1}", score.level, score.score);
/// }
/// ```