1use std::fmt::{Display, Formatter};
2
3use schemars::JsonSchema;
4use serde::{Deserialize, Serialize};
5
6#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize, JsonSchema)]
8#[serde(transparent)]
9pub struct MessageId(String);
10
11impl MessageId {
12 pub fn new() -> Self {
13 Self(uuid::Uuid::new_v4().to_string())
14 }
15
16 pub fn as_str(&self) -> &str {
17 &self.0
18 }
19
20 pub fn tool_result(tool_call_id: &str) -> Self {
22 Self(format!("tool-result:{tool_call_id}"))
23 }
24
25 pub fn task_result(task_id: &str) -> Self {
26 Self(format!("task-result:{task_id}"))
27 }
28}
29
30impl Default for MessageId {
31 fn default() -> Self {
32 Self::new()
33 }
34}
35
36impl From<String> for MessageId {
37 fn from(value: String) -> Self {
38 Self(value)
39 }
40}
41
42impl From<&str> for MessageId {
43 fn from(value: &str) -> Self {
44 Self(value.to_owned())
45 }
46}
47
48impl std::ops::Deref for MessageId {
49 type Target = str;
50
51 fn deref(&self) -> &Self::Target {
52 self.as_str()
53 }
54}
55
56impl Display for MessageId {
57 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
58 self.0.fmt(f)
59 }
60}