Skip to main content

xurl_core/
model.rs

1use std::fmt;
2use std::path::PathBuf;
3
4use serde::Serialize;
5
6#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)]
7pub enum ProviderKind {
8    Amp,
9    Codex,
10    Claude,
11    Gemini,
12    Pi,
13    Opencode,
14}
15
16impl fmt::Display for ProviderKind {
17    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
18        match self {
19            Self::Amp => write!(f, "amp"),
20            Self::Codex => write!(f, "codex"),
21            Self::Claude => write!(f, "claude"),
22            Self::Gemini => write!(f, "gemini"),
23            Self::Pi => write!(f, "pi"),
24            Self::Opencode => write!(f, "opencode"),
25        }
26    }
27}
28
29#[derive(Debug, Clone, Default, PartialEq, Eq)]
30pub struct ResolutionMeta {
31    pub source: String,
32    pub candidate_count: usize,
33    pub warnings: Vec<String>,
34}
35
36#[derive(Debug, Clone, PartialEq, Eq)]
37pub struct ResolvedThread {
38    pub provider: ProviderKind,
39    pub session_id: String,
40    pub path: PathBuf,
41    pub metadata: ResolutionMeta,
42}
43
44#[derive(Debug, Clone, PartialEq, Eq)]
45pub struct WriteRequest {
46    pub prompt: String,
47    pub session_id: Option<String>,
48    pub options: WriteOptions,
49}
50
51#[derive(Debug, Clone, PartialEq, Eq)]
52pub struct WriteResult {
53    pub provider: ProviderKind,
54    pub session_id: String,
55    pub final_text: Option<String>,
56    pub warnings: Vec<String>,
57}
58
59#[derive(Debug, Clone, Default, PartialEq, Eq)]
60pub struct WriteOptions {
61    pub params: Vec<(String, Option<String>)>,
62    pub role: Option<String>,
63}
64
65#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)]
66pub enum MessageRole {
67    User,
68    Assistant,
69}
70
71impl fmt::Display for MessageRole {
72    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
73        match self {
74            Self::User => write!(f, "user"),
75            Self::Assistant => write!(f, "assistant"),
76        }
77    }
78}
79
80#[derive(Debug, Clone, PartialEq, Eq)]
81pub struct ThreadMessage {
82    pub role: MessageRole,
83    pub text: String,
84}
85
86#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
87pub struct SubagentQuery {
88    pub provider: String,
89    pub main_thread_id: String,
90    pub agent_id: Option<String>,
91    pub list: bool,
92}
93
94#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize)]
95pub struct SubagentRelation {
96    pub validated: bool,
97    pub evidence: Vec<String>,
98}
99
100#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
101pub struct SubagentLifecycleEvent {
102    pub timestamp: Option<String>,
103    pub event: String,
104    pub detail: String,
105}
106
107#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
108pub struct SubagentExcerptMessage {
109    pub role: MessageRole,
110    pub text: String,
111}
112
113#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
114pub struct SubagentThreadRef {
115    pub thread_id: String,
116    pub path: Option<String>,
117    pub last_updated_at: Option<String>,
118}
119
120#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
121pub struct SubagentDetailView {
122    pub query: SubagentQuery,
123    pub relation: SubagentRelation,
124    pub lifecycle: Vec<SubagentLifecycleEvent>,
125    pub status: String,
126    pub status_source: String,
127    pub child_thread: Option<SubagentThreadRef>,
128    pub excerpt: Vec<SubagentExcerptMessage>,
129    #[serde(skip_serializing)]
130    pub warnings: Vec<String>,
131}
132
133#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
134pub struct SubagentListItem {
135    pub agent_id: String,
136    pub status: String,
137    pub status_source: String,
138    pub last_update: Option<String>,
139    pub relation: SubagentRelation,
140    pub child_thread: Option<SubagentThreadRef>,
141}
142
143#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
144pub struct SubagentListView {
145    pub query: SubagentQuery,
146    pub agents: Vec<SubagentListItem>,
147    #[serde(skip_serializing)]
148    pub warnings: Vec<String>,
149}
150
151#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
152#[serde(tag = "kind", rename_all = "snake_case")]
153pub enum SubagentView {
154    List(SubagentListView),
155    Detail(SubagentDetailView),
156}
157
158#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
159pub struct PiEntryQuery {
160    pub provider: String,
161    pub session_id: String,
162    pub list: bool,
163}
164
165#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
166pub struct PiEntryListItem {
167    pub entry_id: String,
168    pub entry_type: String,
169    pub parent_id: Option<String>,
170    pub timestamp: Option<String>,
171    pub is_leaf: bool,
172    pub preview: Option<String>,
173}
174
175#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
176pub struct PiEntryListView {
177    pub query: PiEntryQuery,
178    pub entries: Vec<PiEntryListItem>,
179    #[serde(skip_serializing)]
180    pub warnings: Vec<String>,
181}
182
183#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
184pub struct ThreadQuery {
185    pub uri: String,
186    pub provider: ProviderKind,
187    pub role: Option<String>,
188    pub q: Option<String>,
189    pub limit: usize,
190    pub ignored_params: Vec<String>,
191}
192
193#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
194pub struct ThreadQueryItem {
195    pub thread_id: String,
196    pub uri: String,
197    pub thread_source: String,
198    pub updated_at: Option<String>,
199    pub matched_preview: Option<String>,
200}
201
202#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
203pub struct ThreadQueryResult {
204    pub query: ThreadQuery,
205    pub items: Vec<ThreadQueryItem>,
206    #[serde(skip_serializing)]
207    pub warnings: Vec<String>,
208}