Skip to main content

openai_types/beta/
manual.rs

1// Manual: hand-crafted beta types (Assistants, Threads, Runs, Vector Stores).
2// These supplement the auto-generated _gen.rs types.
3
4use serde::{Deserialize, Serialize};
5use std::collections::HashMap;
6
7// Re-export shared types (canonical definitions in shared/common.rs)
8pub use crate::shared::{Role, SortOrder};
9
10/// Status of a thread run.
11#[derive(Debug, Clone, PartialEq, Eq)]
12#[non_exhaustive]
13pub enum RunStatus {
14    Queued,
15    InProgress,
16    RequiresAction,
17    Cancelling,
18    Cancelled,
19    Failed,
20    Completed,
21    Incomplete,
22    Expired,
23    /// Catch-all for unknown variants (forward compatibility).
24    Other(String),
25}
26
27impl serde::Serialize for RunStatus {
28    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
29    where
30        S: serde::Serializer,
31    {
32        match self {
33            Self::Queued => serializer.serialize_str("queued"),
34            Self::InProgress => serializer.serialize_str("in_progress"),
35            Self::RequiresAction => serializer.serialize_str("requires_action"),
36            Self::Cancelling => serializer.serialize_str("cancelling"),
37            Self::Cancelled => serializer.serialize_str("cancelled"),
38            Self::Failed => serializer.serialize_str("failed"),
39            Self::Completed => serializer.serialize_str("completed"),
40            Self::Incomplete => serializer.serialize_str("incomplete"),
41            Self::Expired => serializer.serialize_str("expired"),
42            Self::Other(s) => serializer.serialize_str(s),
43        }
44    }
45}
46
47impl<'de> serde::Deserialize<'de> for RunStatus {
48    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
49    where
50        D: serde::Deserializer<'de>,
51    {
52        let s = String::deserialize(deserializer)?;
53        match s.as_str() {
54            "queued" => Ok(Self::Queued),
55            "in_progress" => Ok(Self::InProgress),
56            "requires_action" => Ok(Self::RequiresAction),
57            "cancelling" => Ok(Self::Cancelling),
58            "cancelled" => Ok(Self::Cancelled),
59            "failed" => Ok(Self::Failed),
60            "completed" => Ok(Self::Completed),
61            "incomplete" => Ok(Self::Incomplete),
62            "expired" => Ok(Self::Expired),
63            _ => Ok(Self::Other(s)),
64        }
65    }
66}
67
68/// Status of a vector store.
69#[derive(Debug, Clone, PartialEq, Eq)]
70#[non_exhaustive]
71pub enum VectorStoreStatus {
72    Expired,
73    InProgress,
74    Completed,
75    /// Catch-all for unknown variants (forward compatibility).
76    Other(String),
77}
78
79impl serde::Serialize for VectorStoreStatus {
80    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
81    where
82        S: serde::Serializer,
83    {
84        match self {
85            Self::Expired => serializer.serialize_str("expired"),
86            Self::InProgress => serializer.serialize_str("in_progress"),
87            Self::Completed => serializer.serialize_str("completed"),
88            Self::Other(s) => serializer.serialize_str(s),
89        }
90    }
91}
92
93impl<'de> serde::Deserialize<'de> for VectorStoreStatus {
94    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
95    where
96        D: serde::Deserializer<'de>,
97    {
98        let s = String::deserialize(deserializer)?;
99        match s.as_str() {
100            "expired" => Ok(Self::Expired),
101            "in_progress" => Ok(Self::InProgress),
102            "completed" => Ok(Self::Completed),
103            _ => Ok(Self::Other(s)),
104        }
105    }
106}
107
108// ── Tool types ──
109
110/// A tool available to an assistant or run.
111#[derive(Debug, Clone, Serialize, Deserialize)]
112#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
113#[serde(tag = "type")]
114#[non_exhaustive]
115pub enum BetaTool {
116    /// Code interpreter tool.
117    #[serde(rename = "code_interpreter")]
118    CodeInterpreter,
119    /// File search tool with optional configuration.
120    #[serde(rename = "file_search")]
121    FileSearch {
122        #[serde(skip_serializing_if = "Option::is_none")]
123        file_search: Option<FileSearchConfig>,
124    },
125    /// Function tool.
126    #[serde(rename = "function")]
127    Function { function: BetaFunctionDef },
128}
129
130/// Configuration for the file search tool.
131#[derive(Debug, Clone, Serialize, Deserialize)]
132#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
133pub struct FileSearchConfig {
134    /// Maximum number of results (1-50).
135    #[serde(skip_serializing_if = "Option::is_none")]
136    pub max_num_results: Option<i64>,
137    /// Ranking options.
138    #[serde(skip_serializing_if = "Option::is_none")]
139    pub ranking_options: Option<FileSearchRankingOptions>,
140}
141
142/// Ranking options for file search.
143#[derive(Debug, Clone, Serialize, Deserialize)]
144#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
145pub struct FileSearchRankingOptions {
146    /// Score threshold (0.0-1.0).
147    pub score_threshold: f64,
148    /// Ranker to use: "auto" or "default_2024_08_21".
149    #[serde(skip_serializing_if = "Option::is_none")]
150    pub ranker: Option<String>,
151}
152
153/// Function definition within a beta tool.
154#[derive(Debug, Clone, Serialize, Deserialize)]
155#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
156pub struct BetaFunctionDef {
157    pub name: String,
158    #[serde(skip_serializing_if = "Option::is_none")]
159    pub description: Option<String>,
160    #[serde(skip_serializing_if = "Option::is_none")]
161    pub parameters: Option<serde_json::Value>,
162}
163
164/// An annotation on message text (file citation or file path).
165#[derive(Debug, Clone, Serialize, Deserialize)]
166#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
167pub struct MessageAnnotation {
168    /// Annotation type: "file_citation" or "file_path".
169    #[serde(rename = "type")]
170    pub type_: String,
171    /// The text in the message content being annotated.
172    #[serde(default)]
173    pub text: Option<String>,
174    /// Start index of the annotation in the text.
175    #[serde(default)]
176    pub start_index: Option<i64>,
177    /// End index of the annotation in the text.
178    #[serde(default)]
179    pub end_index: Option<i64>,
180    /// File citation details (for file_citation type).
181    #[serde(default)]
182    pub file_citation: Option<FileCitation>,
183    /// File path details (for file_path type).
184    #[serde(default)]
185    pub file_path: Option<FilePath>,
186}
187
188/// File citation in an annotation.
189#[derive(Debug, Clone, Serialize, Deserialize)]
190#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
191pub struct FileCitation {
192    pub file_id: String,
193    #[serde(default)]
194    pub quote: Option<String>,
195}
196
197/// File path in an annotation.
198#[derive(Debug, Clone, Serialize, Deserialize)]
199#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
200pub struct FilePath {
201    pub file_id: String,
202}
203
204// ── Assistants ──
205
206/// Request body for creating an assistant.
207#[derive(Debug, Clone, Serialize)]
208#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
209pub struct AssistantCreateRequest {
210    pub model: String,
211    #[serde(skip_serializing_if = "Option::is_none")]
212    pub name: Option<String>,
213    #[serde(skip_serializing_if = "Option::is_none")]
214    pub description: Option<String>,
215    #[serde(skip_serializing_if = "Option::is_none")]
216    pub instructions: Option<String>,
217    #[serde(skip_serializing_if = "Option::is_none")]
218    pub tools: Option<Vec<BetaTool>>,
219    #[serde(skip_serializing_if = "Option::is_none")]
220    pub metadata: Option<HashMap<String, String>>,
221    #[serde(skip_serializing_if = "Option::is_none")]
222    pub temperature: Option<f64>,
223    #[serde(skip_serializing_if = "Option::is_none")]
224    pub top_p: Option<f64>,
225}
226
227impl AssistantCreateRequest {
228    pub fn new(model: impl Into<String>) -> Self {
229        Self {
230            model: model.into(),
231            name: None,
232            description: None,
233            instructions: None,
234            tools: None,
235            metadata: None,
236            temperature: None,
237            top_p: None,
238        }
239    }
240}
241
242/// An assistant object.
243#[derive(Debug, Clone, Serialize, Deserialize)]
244#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
245pub struct Assistant {
246    pub id: String,
247    pub object: String,
248    pub created_at: i64,
249    pub model: String,
250    #[serde(default)]
251    pub name: Option<String>,
252    #[serde(default)]
253    pub description: Option<String>,
254    #[serde(default)]
255    pub instructions: Option<String>,
256    #[serde(default)]
257    pub tools: Vec<BetaTool>,
258    #[serde(default)]
259    pub metadata: Option<HashMap<String, String>>,
260    #[serde(default)]
261    pub temperature: Option<f64>,
262    #[serde(default)]
263    pub top_p: Option<f64>,
264}
265
266/// List of assistants.
267#[derive(Debug, Clone, Serialize, Deserialize)]
268#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
269pub struct AssistantList {
270    pub object: String,
271    pub data: Vec<Assistant>,
272    /// Whether there are more results available.
273    #[serde(default)]
274    pub has_more: Option<bool>,
275    /// ID of the first object in the list.
276    #[serde(default)]
277    pub first_id: Option<String>,
278    /// ID of the last object in the list.
279    #[serde(default)]
280    pub last_id: Option<String>,
281}
282
283/// Deleted assistant response.
284#[derive(Debug, Clone, Serialize, Deserialize)]
285#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
286pub struct AssistantDeleted {
287    pub id: String,
288    pub deleted: bool,
289    pub object: String,
290}
291
292// ── Threads ──
293
294/// Request body for creating a thread.
295#[derive(Debug, Clone, Default, Serialize)]
296#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
297pub struct ThreadCreateRequest {
298    #[serde(skip_serializing_if = "Option::is_none")]
299    pub messages: Option<Vec<ThreadMessage>>,
300    #[serde(skip_serializing_if = "Option::is_none")]
301    pub metadata: Option<HashMap<String, String>>,
302}
303
304/// A message in a thread creation request.
305#[derive(Debug, Clone, Serialize)]
306#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
307pub struct ThreadMessage {
308    pub role: Role,
309    pub content: String,
310}
311
312/// A thread object.
313#[derive(Debug, Clone, Deserialize, Serialize)]
314#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
315pub struct Thread {
316    pub id: String,
317    pub object: String,
318    pub created_at: i64,
319    #[serde(default)]
320    pub metadata: Option<HashMap<String, String>>,
321}
322
323/// Deleted thread response.
324#[derive(Debug, Clone, Serialize, Deserialize)]
325#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
326pub struct ThreadDeleted {
327    pub id: String,
328    pub deleted: bool,
329    pub object: String,
330}
331
332/// A message within a thread.
333#[derive(Debug, Clone, Deserialize, Serialize)]
334#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
335pub struct Message {
336    pub id: String,
337    pub object: String,
338    pub created_at: i64,
339    pub thread_id: String,
340    pub role: Role,
341    pub content: Vec<MessageContent>,
342    #[serde(default)]
343    pub assistant_id: Option<String>,
344    #[serde(default)]
345    pub run_id: Option<String>,
346    #[serde(default)]
347    pub metadata: Option<HashMap<String, String>>,
348}
349
350/// Content block in a message.
351#[derive(Debug, Clone, Serialize, Deserialize)]
352#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
353pub struct MessageContent {
354    #[serde(rename = "type")]
355    pub type_: String,
356    #[serde(default)]
357    pub text: Option<MessageText>,
358}
359
360/// Text content in a message.
361#[derive(Debug, Clone, Serialize, Deserialize)]
362#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
363pub struct MessageText {
364    pub value: String,
365    #[serde(default)]
366    pub annotations: Vec<MessageAnnotation>,
367}
368
369/// Request body for creating a message.
370#[derive(Debug, Clone, Serialize)]
371#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
372pub struct MessageCreateRequest {
373    pub role: Role,
374    pub content: String,
375}
376
377/// List of messages.
378#[derive(Debug, Clone, Serialize, Deserialize)]
379#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
380pub struct MessageList {
381    pub object: String,
382    pub data: Vec<Message>,
383    /// Whether there are more results available.
384    #[serde(default)]
385    pub has_more: Option<bool>,
386    /// ID of the first object in the list.
387    #[serde(default)]
388    pub first_id: Option<String>,
389    /// ID of the last object in the list.
390    #[serde(default)]
391    pub last_id: Option<String>,
392}
393
394// ── Runs ──
395
396/// Request body for creating a run.
397#[derive(Debug, Clone, Serialize)]
398#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
399pub struct RunCreateRequest {
400    pub assistant_id: String,
401    #[serde(skip_serializing_if = "Option::is_none")]
402    pub instructions: Option<String>,
403    #[serde(skip_serializing_if = "Option::is_none")]
404    pub tools: Option<Vec<BetaTool>>,
405    #[serde(skip_serializing_if = "Option::is_none")]
406    pub metadata: Option<HashMap<String, String>>,
407    #[serde(skip_serializing_if = "Option::is_none")]
408    pub model: Option<String>,
409}
410
411impl RunCreateRequest {
412    pub fn new(assistant_id: impl Into<String>) -> Self {
413        Self {
414            assistant_id: assistant_id.into(),
415            instructions: None,
416            tools: None,
417            metadata: None,
418            model: None,
419        }
420    }
421}
422
423/// A run object.
424#[derive(Debug, Clone, Serialize, Deserialize)]
425#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
426pub struct Run {
427    pub id: String,
428    pub object: String,
429    pub created_at: i64,
430    pub thread_id: String,
431    pub assistant_id: String,
432    pub status: RunStatus,
433    #[serde(default)]
434    pub model: Option<String>,
435    #[serde(default)]
436    pub instructions: Option<String>,
437    #[serde(default)]
438    pub tools: Vec<BetaTool>,
439    #[serde(default)]
440    pub started_at: Option<i64>,
441    #[serde(default)]
442    pub completed_at: Option<i64>,
443    #[serde(default)]
444    pub cancelled_at: Option<i64>,
445    #[serde(default)]
446    pub failed_at: Option<i64>,
447    #[serde(default)]
448    pub metadata: Option<HashMap<String, String>>,
449}
450
451/// Submit tool outputs request.
452#[derive(Debug, Clone, Serialize)]
453#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
454pub struct SubmitToolOutputsRequest {
455    pub tool_outputs: Vec<ToolOutput>,
456}
457
458/// A single tool output.
459#[derive(Debug, Clone, Serialize)]
460#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
461pub struct ToolOutput {
462    pub tool_call_id: String,
463    pub output: String,
464}
465
466// ── Vector Stores ──
467
468/// Request body for creating a vector store.
469#[derive(Debug, Clone, Default, Serialize)]
470#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
471pub struct VectorStoreCreateRequest {
472    #[serde(skip_serializing_if = "Option::is_none")]
473    pub name: Option<String>,
474    #[serde(skip_serializing_if = "Option::is_none")]
475    pub file_ids: Option<Vec<String>>,
476    #[serde(skip_serializing_if = "Option::is_none")]
477    pub metadata: Option<HashMap<String, String>>,
478}
479
480/// A vector store object.
481#[derive(Debug, Clone, Serialize, Deserialize)]
482#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
483pub struct VectorStore {
484    pub id: String,
485    pub object: String,
486    pub created_at: i64,
487    #[serde(default)]
488    pub name: Option<String>,
489    pub status: VectorStoreStatus,
490    #[serde(default)]
491    pub file_counts: Option<VectorStoreFileCounts>,
492    #[serde(default)]
493    pub metadata: Option<HashMap<String, String>>,
494}
495
496/// File counts for a vector store.
497#[derive(Debug, Clone, Serialize, Deserialize)]
498#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
499pub struct VectorStoreFileCounts {
500    pub in_progress: i64,
501    pub completed: i64,
502    pub failed: i64,
503    pub cancelled: i64,
504    pub total: i64,
505}
506
507/// List of vector stores.
508#[derive(Debug, Clone, Serialize, Deserialize)]
509#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
510pub struct VectorStoreList {
511    pub object: String,
512    pub data: Vec<VectorStore>,
513    /// Whether there are more results available.
514    #[serde(default)]
515    pub has_more: Option<bool>,
516    /// ID of the first object in the list.
517    #[serde(default)]
518    pub first_id: Option<String>,
519    /// ID of the last object in the list.
520    #[serde(default)]
521    pub last_id: Option<String>,
522}
523
524/// Deleted vector store response.
525#[derive(Debug, Clone, Serialize, Deserialize)]
526#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
527pub struct VectorStoreDeleted {
528    pub id: String,
529    pub deleted: bool,
530    pub object: String,
531}
532
533// ── Pagination params ──
534
535/// Parameters for listing assistants with pagination.
536#[derive(Debug, Clone, Default)]
537pub struct AssistantListParams {
538    /// Cursor for pagination -- fetch results after this assistant ID.
539    pub after: Option<String>,
540    /// Cursor for backward pagination -- fetch results before this assistant ID.
541    pub before: Option<String>,
542    /// Maximum number of results per page (1-100).
543    pub limit: Option<i64>,
544    /// Sort order by `created_at`.
545    pub order: Option<SortOrder>,
546}
547
548impl AssistantListParams {
549    pub fn new() -> Self {
550        Self::default()
551    }
552
553    pub fn after(mut self, after: impl Into<String>) -> Self {
554        self.after = Some(after.into());
555        self
556    }
557
558    pub fn before(mut self, before: impl Into<String>) -> Self {
559        self.before = Some(before.into());
560        self
561    }
562
563    pub fn limit(mut self, limit: i64) -> Self {
564        self.limit = Some(limit);
565        self
566    }
567
568    pub fn order(mut self, order: SortOrder) -> Self {
569        self.order = Some(order);
570        self
571    }
572
573    /// Convert to query parameter pairs for the HTTP request.
574    pub fn to_query(&self) -> Vec<(String, String)> {
575        let mut q = Vec::new();
576        if let Some(ref after) = self.after {
577            q.push(("after".into(), after.clone()));
578        }
579        if let Some(ref before) = self.before {
580            q.push(("before".into(), before.clone()));
581        }
582        if let Some(limit) = self.limit {
583            q.push(("limit".into(), limit.to_string()));
584        }
585        if let Some(ref order) = self.order {
586            q.push((
587                "order".into(),
588                serde_json::to_value(order)
589                    .unwrap()
590                    .as_str()
591                    .unwrap()
592                    .to_string(),
593            ));
594        }
595        q
596    }
597}
598
599/// Parameters for listing messages with pagination.
600#[derive(Debug, Clone, Default)]
601pub struct MessageListParams {
602    /// Cursor for pagination -- fetch results after this message ID.
603    pub after: Option<String>,
604    /// Cursor for backward pagination -- fetch results before this message ID.
605    pub before: Option<String>,
606    /// Maximum number of results per page (1-100).
607    pub limit: Option<i64>,
608    /// Sort order by `created_at`.
609    pub order: Option<SortOrder>,
610    /// Filter by run ID.
611    pub run_id: Option<String>,
612}
613
614impl MessageListParams {
615    pub fn new() -> Self {
616        Self::default()
617    }
618
619    pub fn after(mut self, after: impl Into<String>) -> Self {
620        self.after = Some(after.into());
621        self
622    }
623
624    pub fn before(mut self, before: impl Into<String>) -> Self {
625        self.before = Some(before.into());
626        self
627    }
628
629    pub fn limit(mut self, limit: i64) -> Self {
630        self.limit = Some(limit);
631        self
632    }
633
634    pub fn order(mut self, order: SortOrder) -> Self {
635        self.order = Some(order);
636        self
637    }
638
639    pub fn run_id(mut self, run_id: impl Into<String>) -> Self {
640        self.run_id = Some(run_id.into());
641        self
642    }
643
644    /// Convert to query parameter pairs for the HTTP request.
645    pub fn to_query(&self) -> Vec<(String, String)> {
646        let mut q = Vec::new();
647        if let Some(ref after) = self.after {
648            q.push(("after".into(), after.clone()));
649        }
650        if let Some(ref before) = self.before {
651            q.push(("before".into(), before.clone()));
652        }
653        if let Some(limit) = self.limit {
654            q.push(("limit".into(), limit.to_string()));
655        }
656        if let Some(ref order) = self.order {
657            q.push((
658                "order".into(),
659                serde_json::to_value(order)
660                    .unwrap()
661                    .as_str()
662                    .unwrap()
663                    .to_string(),
664            ));
665        }
666        if let Some(ref run_id) = self.run_id {
667            q.push(("run_id".into(), run_id.clone()));
668        }
669        q
670    }
671}
672
673/// Parameters for listing vector stores with pagination.
674#[derive(Debug, Clone, Default)]
675pub struct VectorStoreListParams {
676    /// Cursor for pagination -- fetch results after this vector store ID.
677    pub after: Option<String>,
678    /// Cursor for backward pagination -- fetch results before this vector store ID.
679    pub before: Option<String>,
680    /// Maximum number of results per page (1-100).
681    pub limit: Option<i64>,
682    /// Sort order by `created_at`.
683    pub order: Option<SortOrder>,
684}
685
686impl VectorStoreListParams {
687    pub fn new() -> Self {
688        Self::default()
689    }
690
691    pub fn after(mut self, after: impl Into<String>) -> Self {
692        self.after = Some(after.into());
693        self
694    }
695
696    pub fn before(mut self, before: impl Into<String>) -> Self {
697        self.before = Some(before.into());
698        self
699    }
700
701    pub fn limit(mut self, limit: i64) -> Self {
702        self.limit = Some(limit);
703        self
704    }
705
706    pub fn order(mut self, order: SortOrder) -> Self {
707        self.order = Some(order);
708        self
709    }
710
711    /// Convert to query parameter pairs for the HTTP request.
712    pub fn to_query(&self) -> Vec<(String, String)> {
713        let mut q = Vec::new();
714        if let Some(ref after) = self.after {
715            q.push(("after".into(), after.clone()));
716        }
717        if let Some(ref before) = self.before {
718            q.push(("before".into(), before.clone()));
719        }
720        if let Some(limit) = self.limit {
721            q.push(("limit".into(), limit.to_string()));
722        }
723        if let Some(ref order) = self.order {
724            q.push((
725                "order".into(),
726                serde_json::to_value(order)
727                    .unwrap()
728                    .as_str()
729                    .unwrap()
730                    .to_string(),
731            ));
732        }
733        q
734    }
735}
736
737/// Parameters for listing runs with pagination.
738#[derive(Debug, Clone, Default)]
739pub struct RunListParams {
740    /// Cursor for pagination -- fetch results after this run ID.
741    pub after: Option<String>,
742    /// Cursor for backward pagination -- fetch results before this run ID.
743    pub before: Option<String>,
744    /// Maximum number of results per page (1-100).
745    pub limit: Option<i64>,
746    /// Sort order by `created_at`.
747    pub order: Option<SortOrder>,
748}
749
750impl RunListParams {
751    pub fn new() -> Self {
752        Self::default()
753    }
754
755    pub fn after(mut self, after: impl Into<String>) -> Self {
756        self.after = Some(after.into());
757        self
758    }
759
760    pub fn before(mut self, before: impl Into<String>) -> Self {
761        self.before = Some(before.into());
762        self
763    }
764
765    pub fn limit(mut self, limit: i64) -> Self {
766        self.limit = Some(limit);
767        self
768    }
769
770    pub fn order(mut self, order: SortOrder) -> Self {
771        self.order = Some(order);
772        self
773    }
774
775    /// Convert to query parameter pairs for the HTTP request.
776    pub fn to_query(&self) -> Vec<(String, String)> {
777        let mut q = Vec::new();
778        if let Some(ref after) = self.after {
779            q.push(("after".into(), after.clone()));
780        }
781        if let Some(ref before) = self.before {
782            q.push(("before".into(), before.clone()));
783        }
784        if let Some(limit) = self.limit {
785            q.push(("limit".into(), limit.to_string()));
786        }
787        if let Some(ref order) = self.order {
788            q.push((
789                "order".into(),
790                serde_json::to_value(order)
791                    .unwrap()
792                    .as_str()
793                    .unwrap()
794                    .to_string(),
795            ));
796        }
797        q
798    }
799}