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, Copy, PartialEq, Eq, Serialize)]
45#[serde(rename_all = "snake_case")]
46pub enum SkillsSourceKind {
47    Local,
48    Github,
49}
50
51impl fmt::Display for SkillsSourceKind {
52    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
53        match self {
54            Self::Local => write!(f, "local"),
55            Self::Github => write!(f, "github"),
56        }
57    }
58}
59
60#[derive(Debug, Clone, Default, PartialEq, Eq)]
61pub struct SkillResolutionMeta {
62    pub warnings: Vec<String>,
63    pub candidates: Vec<String>,
64}
65
66#[derive(Debug, Clone, PartialEq, Eq)]
67pub struct ResolvedSkill {
68    pub uri: String,
69    pub source_kind: SkillsSourceKind,
70    pub skill_name: String,
71    pub source: String,
72    pub resolved_path: String,
73    pub content: String,
74    pub metadata: SkillResolutionMeta,
75}
76
77#[derive(Debug, Clone, PartialEq, Eq)]
78pub struct WriteRequest {
79    pub prompt: String,
80    pub session_id: Option<String>,
81    pub options: WriteOptions,
82}
83
84#[derive(Debug, Clone, PartialEq, Eq)]
85pub struct WriteResult {
86    pub provider: ProviderKind,
87    pub session_id: String,
88    pub final_text: Option<String>,
89    pub warnings: Vec<String>,
90}
91
92#[derive(Debug, Clone, Default, PartialEq, Eq)]
93pub struct WriteOptions {
94    pub params: Vec<(String, Option<String>)>,
95    pub role: Option<String>,
96}
97
98#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)]
99pub enum MessageRole {
100    User,
101    Assistant,
102}
103
104impl fmt::Display for MessageRole {
105    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
106        match self {
107            Self::User => write!(f, "user"),
108            Self::Assistant => write!(f, "assistant"),
109        }
110    }
111}
112
113#[derive(Debug, Clone, PartialEq, Eq)]
114pub struct ThreadMessage {
115    pub role: MessageRole,
116    pub text: String,
117}
118
119#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
120pub struct SubagentQuery {
121    pub provider: String,
122    pub main_thread_id: String,
123    pub agent_id: Option<String>,
124    pub list: bool,
125}
126
127#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize)]
128pub struct SubagentRelation {
129    pub validated: bool,
130    pub evidence: Vec<String>,
131}
132
133#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
134pub struct SubagentLifecycleEvent {
135    pub timestamp: Option<String>,
136    pub event: String,
137    pub detail: String,
138}
139
140#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
141pub struct SubagentExcerptMessage {
142    pub role: MessageRole,
143    pub text: String,
144}
145
146#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
147pub struct SubagentThreadRef {
148    pub thread_id: String,
149    pub path: Option<String>,
150    pub last_updated_at: Option<String>,
151}
152
153#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
154pub struct SubagentDetailView {
155    pub query: SubagentQuery,
156    pub relation: SubagentRelation,
157    pub lifecycle: Vec<SubagentLifecycleEvent>,
158    pub status: String,
159    pub status_source: String,
160    pub child_thread: Option<SubagentThreadRef>,
161    pub excerpt: Vec<SubagentExcerptMessage>,
162    #[serde(skip_serializing)]
163    pub warnings: Vec<String>,
164}
165
166#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
167pub struct SubagentListItem {
168    pub agent_id: String,
169    pub status: String,
170    pub status_source: String,
171    pub last_update: Option<String>,
172    pub relation: SubagentRelation,
173    pub child_thread: Option<SubagentThreadRef>,
174}
175
176#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
177pub struct SubagentListView {
178    pub query: SubagentQuery,
179    pub agents: Vec<SubagentListItem>,
180    #[serde(skip_serializing)]
181    pub warnings: Vec<String>,
182}
183
184#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
185#[serde(tag = "kind", rename_all = "snake_case")]
186pub enum SubagentView {
187    List(SubagentListView),
188    Detail(SubagentDetailView),
189}
190
191#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
192pub struct PiEntryQuery {
193    pub provider: String,
194    pub session_id: String,
195    pub list: bool,
196}
197
198#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
199pub struct PiEntryListItem {
200    pub entry_id: String,
201    pub entry_type: String,
202    pub parent_id: Option<String>,
203    pub timestamp: Option<String>,
204    pub is_leaf: bool,
205    pub preview: Option<String>,
206}
207
208#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
209pub struct PiEntryListView {
210    pub query: PiEntryQuery,
211    pub entries: Vec<PiEntryListItem>,
212    #[serde(skip_serializing)]
213    pub warnings: Vec<String>,
214}
215
216#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
217pub struct ThreadQuery {
218    pub uri: String,
219    pub provider: ProviderKind,
220    pub role: Option<String>,
221    pub q: Option<String>,
222    pub limit: usize,
223    pub ignored_params: Vec<String>,
224}
225
226#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
227pub struct ThreadQueryItem {
228    pub thread_id: String,
229    pub uri: String,
230    pub thread_source: String,
231    pub updated_at: Option<String>,
232    pub matched_preview: Option<String>,
233}
234
235#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
236pub struct ThreadQueryResult {
237    pub query: ThreadQuery,
238    pub items: Vec<ThreadQueryItem>,
239    #[serde(skip_serializing)]
240    pub warnings: Vec<String>,
241}