shopify_approver_opencode/
models.rs1use chrono::{DateTime, Utc};
4use serde::{Deserialize, Serialize};
5use std::collections::HashMap;
6
7#[derive(Debug, Clone, Serialize)]
9pub struct IndexRequest {
10 pub name: Option<String>,
12 pub metadata: HashMap<String, String>,
14}
15
16impl IndexRequest {
17 pub fn new() -> Self {
18 Self {
19 name: None,
20 metadata: HashMap::new(),
21 }
22 }
23
24 pub fn with_name(mut self, name: impl Into<String>) -> Self {
25 self.name = Some(name.into());
26 self
27 }
28
29 pub fn with_metadata(mut self, key: impl Into<String>, value: impl Into<String>) -> Self {
30 self.metadata.insert(key.into(), value.into());
31 self
32 }
33}
34
35impl Default for IndexRequest {
36 fn default() -> Self {
37 Self::new()
38 }
39}
40
41#[derive(Debug, Clone, Deserialize)]
43pub struct IndexResponse {
44 pub id: String,
46 pub status: IndexStatus,
48 pub created_at: DateTime<Utc>,
50 pub file_count: Option<usize>,
52 pub total_size: Option<usize>,
54 pub error: Option<String>,
56}
57
58#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
60#[serde(rename_all = "lowercase")]
61pub enum IndexStatus {
62 Pending,
64 Processing,
66 Ready,
68 Failed,
70 Deleted,
72}
73
74impl IndexStatus {
75 pub fn is_ready(&self) -> bool {
76 matches!(self, Self::Ready)
77 }
78
79 pub fn is_pending(&self) -> bool {
80 matches!(self, Self::Pending | Self::Processing)
81 }
82
83 pub fn is_failed(&self) -> bool {
84 matches!(self, Self::Failed)
85 }
86}
87
88#[derive(Debug, Clone, Serialize)]
90pub struct SearchRequest {
91 pub query: String,
93 #[serde(default = "default_limit")]
95 pub limit: usize,
96 #[serde(default)]
98 pub min_score: Option<f32>,
99 #[serde(default)]
101 pub extensions: Vec<String>,
102 #[serde(default)]
104 pub paths: Vec<String>,
105 #[serde(default = "default_context_lines")]
107 pub context_lines: usize,
108}
109
110fn default_limit() -> usize {
111 10
112}
113
114fn default_context_lines() -> usize {
115 3
116}
117
118impl SearchRequest {
119 pub fn new(query: impl Into<String>) -> Self {
120 Self {
121 query: query.into(),
122 limit: default_limit(),
123 min_score: None,
124 extensions: Vec::new(),
125 paths: Vec::new(),
126 context_lines: default_context_lines(),
127 }
128 }
129
130 pub fn with_limit(mut self, limit: usize) -> Self {
131 self.limit = limit;
132 self
133 }
134
135 pub fn with_min_score(mut self, score: f32) -> Self {
136 self.min_score = Some(score);
137 self
138 }
139
140 pub fn with_extensions(mut self, extensions: Vec<String>) -> Self {
141 self.extensions = extensions;
142 self
143 }
144
145 pub fn with_paths(mut self, paths: Vec<String>) -> Self {
146 self.paths = paths;
147 self
148 }
149
150 pub fn with_context_lines(mut self, lines: usize) -> Self {
151 self.context_lines = lines;
152 self
153 }
154}
155
156#[derive(Debug, Clone, Deserialize)]
158pub struct SearchResponse {
159 pub results: Vec<CodeChunk>,
161 pub total: usize,
163 pub took_ms: u64,
165}
166
167#[derive(Debug, Clone, Serialize, Deserialize)]
169pub struct CodeChunk {
170 pub file_path: String,
172 pub start_line: usize,
174 pub end_line: usize,
176 pub content: String,
178 pub score: f32,
180 pub element_type: Option<String>,
182 pub element_name: Option<String>,
184 pub language: Option<String>,
186 pub context: Option<CodeContext>,
188}
189
190#[derive(Debug, Clone, Serialize, Deserialize)]
192pub struct CodeContext {
193 pub before: Vec<String>,
195 pub after: Vec<String>,
197 pub imports: Vec<String>,
199 pub parent: Option<String>,
201}
202
203#[derive(Debug, Clone, Serialize)]
205pub struct ContextRequest {
206 pub file_path: String,
208 #[serde(default = "default_include_related")]
210 pub include_related: bool,
211 #[serde(default = "default_related_depth")]
213 pub related_depth: usize,
214}
215
216fn default_include_related() -> bool {
217 true
218}
219
220fn default_related_depth() -> usize {
221 2
222}
223
224impl ContextRequest {
225 pub fn new(file_path: impl Into<String>) -> Self {
226 Self {
227 file_path: file_path.into(),
228 include_related: default_include_related(),
229 related_depth: default_related_depth(),
230 }
231 }
232
233 pub fn with_related(mut self, include: bool) -> Self {
234 self.include_related = include;
235 self
236 }
237
238 pub fn with_depth(mut self, depth: usize) -> Self {
239 self.related_depth = depth;
240 self
241 }
242}
243
244#[derive(Debug, Clone, Deserialize)]
246pub struct ContextResponse {
247 pub file: FileInfo,
249 pub related: Vec<FileInfo>,
251 pub dependencies: Vec<Dependency>,
253}
254
255#[derive(Debug, Clone, Serialize, Deserialize)]
257pub struct FileInfo {
258 pub path: String,
260 pub content: String,
262 pub language: String,
264 pub size: usize,
266 pub lines: usize,
268 pub ast_summary: Option<AstSummary>,
270}
271
272#[derive(Debug, Clone, Serialize, Deserialize)]
274pub struct AstSummary {
275 pub function_count: usize,
277 pub class_count: usize,
279 pub import_count: usize,
281 pub exports: Vec<String>,
283 pub functions: Vec<FunctionSignature>,
285}
286
287#[derive(Debug, Clone, Serialize, Deserialize)]
289pub struct FunctionSignature {
290 pub name: String,
292 pub line: usize,
294 pub params: Vec<String>,
296 pub return_type: Option<String>,
298 pub is_async: bool,
300 pub is_exported: bool,
302}
303
304#[derive(Debug, Clone, Serialize, Deserialize)]
306pub struct Dependency {
307 pub from: String,
309 pub to: String,
311 pub dep_type: String,
313 pub symbols: Vec<String>,
315}
316
317#[derive(Debug, Clone, Deserialize)]
319pub struct IndexStats {
320 pub file_count: usize,
322 pub total_size: usize,
324 pub languages: HashMap<String, usize>,
326 pub avg_file_size: usize,
328 pub chunk_count: usize,
330 pub created_at: DateTime<Utc>,
332 pub updated_at: DateTime<Utc>,
334}