tripo3d/types.rs
1use serde::{Deserialize, Serialize};
2
3/// A private struct for serializing the text-to-model request body.
4#[derive(Serialize)]
5pub(crate) struct TextToModelRequest<'a> {
6 pub(crate) prompt: &'a str,
7 #[serde(rename = "type")]
8 pub(crate) type_: &'a str,
9}
10
11/// Represents an object stored in an S3-compatible service.
12#[derive(Serialize, Debug)]
13pub struct S3Object {
14 /// The name of the S3 bucket.
15 pub bucket: String,
16 /// The full key (path) of the object within the bucket.
17 pub key: String,
18}
19
20/// Describes the input file for a generation task.
21///
22/// This struct is flexible and can represent a file in one of three ways:
23/// 1. As an object in an S3 bucket (`object`).
24/// 2. As a publicly accessible URL (`url`).
25/// 3. As a token representing a previously uploaded file (`file_token`).
26#[derive(Serialize, Debug, Default)]
27pub struct FileContent {
28 /// The file format, e.g., "png", "jpeg".
29 #[serde(rename = "type")]
30 pub type_: String,
31 /// The S3 object details, if the file was uploaded via STS tokens.
32 #[serde(skip_serializing_if = "Option::is_none")]
33 pub object: Option<S3Object>,
34 /// A direct URL to the image file.
35 #[serde(skip_serializing_if = "Option::is_none")]
36 pub url: Option<String>,
37 /// A token representing a file uploaded via the standard multipart endpoint.
38 #[serde(skip_serializing_if = "Option::is_none")]
39 pub file_token: Option<String>,
40}
41
42/// A request to create an image-to-model task.
43#[derive(Serialize, Debug)]
44pub struct ImageTaskRequest {
45 /// The type of the task, which should be "image_to_model".
46 #[serde(rename = "type")]
47 pub type_: &'static str,
48 /// The file content to be used for the task.
49 pub file: FileContent,
50}
51
52/// The response from an API call that successfully initiates a task.
53#[derive(Deserialize, Debug)]
54pub struct TaskResponse {
55 /// The unique identifier for the newly created task.
56 #[serde(rename = "task_id")]
57 pub task_id: String,
58}
59
60/// (Internal) Holds temporary STS credentials for uploading to S3.
61#[derive(Deserialize, Debug)]
62pub(crate) struct StsTokenData {
63 pub(crate) sts_ak: String,
64 pub(crate) sts_sk: String,
65 pub(crate) session_token: String,
66 pub(crate) resource_bucket: String,
67 pub(crate) resource_uri: String,
68}
69
70/// (Internal) Holds the file token from a standard multipart upload.
71#[derive(Deserialize, Debug)]
72pub(crate) struct StandardUploadData {
73 pub(crate) image_token: String,
74}
75
76/// Represents the lifecycle state of a generation task.
77#[derive(Debug, Deserialize, PartialEq, Eq, Clone, Copy)]
78#[serde(rename_all = "lowercase")]
79pub enum TaskState {
80 /// The task has been submitted but has not yet started processing.
81 Pending,
82 /// The task is actively being processed.
83 Running,
84 /// The task completed successfully.
85 Success,
86 /// The task failed to complete.
87 Failure,
88}
89
90/// A downloadable file asset, typically a 3D model.
91#[derive(Debug, Deserialize, Clone)]
92pub struct ResultFile {
93 /// The direct URL to download the file.
94 pub url: String,
95}
96
97/// The set of output files from a successfully completed task.
98#[derive(Debug, Deserialize, Clone, Default)]
99pub struct TaskResult {
100 /// The primary model output in PBR (Physically-Based Rendering) format, typically GLB.
101 #[serde(default)]
102 pub pbr_model: Option<ResultFile>,
103 /// An alternative model output in GLB format.
104 #[serde(default)]
105 pub glb_model: Option<ResultFile>,
106}
107
108/// A preview image generated during the task.
109#[derive(Debug, Deserialize, Clone)]
110pub struct TaskOutput {
111 /// The URL of the generated preview image.
112 pub generated_image: Option<String>,
113}
114
115/// The detailed status and data of a generation task.
116#[derive(Debug, Deserialize, Clone)]
117pub struct TaskStatus {
118 /// The unique identifier of the task.
119 pub task_id: String,
120 /// The current lifecycle state of the task.
121 pub status: TaskState,
122 /// The completion progress of the task, from 0 to 100.
123 pub progress: u8,
124 /// The Unix timestamp of when the task was created.
125 pub create_time: u64,
126 /// The resulting output files from the task, if successful.
127 pub result: TaskResult,
128 /// A link to a generated preview image, if available.
129 pub output: Option<TaskOutput>,
130}
131
132/// The user's account balance.
133#[derive(Deserialize, Debug)]
134pub struct Balance {
135 /// The available, usable balance.
136 pub balance: f64,
137 /// The amount of credits currently reserved for ongoing tasks.
138 pub frozen: f64,
139}
140
141/// (Internal) A generic wrapper for API responses where the content is nested under a "data" field.
142#[derive(Debug, Deserialize)]
143pub(crate) struct ApiResponse<T> {
144 pub(crate) data: T,
145}