Skip to main content

starweaver_core/
ids.rs

1use serde::{Deserialize, Serialize};
2use uuid::Uuid;
3
4/// Runtime agent identifier.
5#[derive(Clone, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)]
6pub struct AgentId(String);
7
8impl AgentId {
9    /// Create an identifier from a caller-provided string.
10    #[must_use]
11    pub fn from_string(value: impl Into<String>) -> Self {
12        Self(value.into())
13    }
14
15    /// Return the string representation.
16    #[must_use]
17    pub fn as_str(&self) -> &str {
18        &self.0
19    }
20}
21
22impl Default for AgentId {
23    fn default() -> Self {
24        Self("main".to_string())
25    }
26}
27
28/// Session identifier shared by SDK, CLI, and service layers.
29#[derive(Clone, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)]
30pub struct SessionId(String);
31
32impl SessionId {
33    /// Create a new random session identifier.
34    #[must_use]
35    pub fn new() -> Self {
36        Self(format!("session_{}", Uuid::new_v4()))
37    }
38
39    /// Create an identifier from a caller-provided string.
40    #[must_use]
41    pub fn from_string(value: impl Into<String>) -> Self {
42        Self(value.into())
43    }
44
45    /// Return the string representation.
46    #[must_use]
47    pub fn as_str(&self) -> &str {
48        &self.0
49    }
50}
51
52impl Default for SessionId {
53    fn default() -> Self {
54        Self::new()
55    }
56}
57
58/// Run identifier.
59#[derive(Clone, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)]
60pub struct RunId(String);
61
62impl RunId {
63    /// Create a new random run identifier.
64    #[must_use]
65    pub fn new() -> Self {
66        Self(format!("run_{}", Uuid::new_v4()))
67    }
68
69    /// Create an identifier from a caller-provided string.
70    #[must_use]
71    pub fn from_string(value: impl Into<String>) -> Self {
72        Self(value.into())
73    }
74
75    /// Return the string representation.
76    #[must_use]
77    pub fn as_str(&self) -> &str {
78        &self.0
79    }
80}
81
82impl Default for RunId {
83    fn default() -> Self {
84        Self::new()
85    }
86}
87
88/// Conversation identifier.
89#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
90pub struct ConversationId(String);
91
92impl ConversationId {
93    /// Create a new random conversation identifier.
94    #[must_use]
95    pub fn new() -> Self {
96        Self(format!("conv_{}", Uuid::new_v4()))
97    }
98
99    /// Create an identifier from a caller-provided string.
100    #[must_use]
101    pub fn from_string(value: impl Into<String>) -> Self {
102        Self(value.into())
103    }
104
105    /// Return the string representation.
106    #[must_use]
107    pub fn as_str(&self) -> &str {
108        &self.0
109    }
110}
111
112impl Default for ConversationId {
113    fn default() -> Self {
114        Self::new()
115    }
116}
117
118/// Checkpoint identifier shared by runtime and service layers.
119#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
120pub struct CheckpointId(String);
121
122impl CheckpointId {
123    /// Create a new random checkpoint identifier.
124    #[must_use]
125    pub fn new() -> Self {
126        Self(format!("ckpt_{}", Uuid::new_v4()))
127    }
128
129    /// Create an identifier from a caller-provided string.
130    #[must_use]
131    pub fn from_string(value: impl Into<String>) -> Self {
132        Self(value.into())
133    }
134
135    /// Return the string representation.
136    #[must_use]
137    pub fn as_str(&self) -> &str {
138        &self.0
139    }
140}
141
142impl Default for CheckpointId {
143    fn default() -> Self {
144        Self::new()
145    }
146}
147
148/// Identifier for one asynchronous subagent execution attempt.
149///
150/// This is deliberately distinct from [`TaskId`], which identifies an optional
151/// task-bundle work item. A resumed waiting execution retains its attempt id;
152/// a new post-terminal conversation turn receives a new attempt id.
153#[derive(Clone, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)]
154pub struct SubagentAttemptId(String);
155
156impl SubagentAttemptId {
157    /// Create a new random subagent attempt identifier.
158    #[must_use]
159    pub fn new() -> Self {
160        Self(format!("subattempt_{}", Uuid::new_v4()))
161    }
162
163    /// Create an identifier from a caller-provided string.
164    #[must_use]
165    pub fn from_string(value: impl Into<String>) -> Self {
166        Self(value.into())
167    }
168
169    /// Return the string representation.
170    #[must_use]
171    pub fn as_str(&self) -> &str {
172        &self.0
173    }
174}
175
176impl Default for SubagentAttemptId {
177    fn default() -> Self {
178        Self::new()
179    }
180}
181
182/// Task identifier shared by runtime, SDK, and service layers.
183#[derive(Clone, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)]
184pub struct TaskId(String);
185
186impl TaskId {
187    /// Create a new random task identifier.
188    #[must_use]
189    pub fn new() -> Self {
190        Self(format!("task_{}", Uuid::new_v4()))
191    }
192
193    /// Create an identifier from a caller-provided string.
194    #[must_use]
195    pub fn from_string(value: impl Into<String>) -> Self {
196        Self(value.into())
197    }
198
199    /// Return the string representation.
200    #[must_use]
201    pub fn as_str(&self) -> &str {
202        &self.0
203    }
204}
205
206impl Default for TaskId {
207    fn default() -> Self {
208        Self::new()
209    }
210}