autoagents_protocol/
task.rs1use crate::SubmissionId;
2use crate::llm::ImageMime;
3use serde::{Deserialize, Serialize};
4use serde_json::Value;
5use uuid::Uuid;
6
7#[derive(Debug, Clone, Serialize, Deserialize)]
9pub struct Task {
10 pub prompt: String,
11 pub image: Option<(ImageMime, Vec<u8>)>,
12 #[serde(default)]
13 pub system_prompt: Option<String>,
14 pub submission_id: SubmissionId,
15 pub completed: bool,
16 pub result: Option<Value>,
17}
18
19impl Task {
20 pub fn new<T: Into<String>>(task: T) -> Self {
22 Self {
23 prompt: task.into(),
24 image: None,
25 system_prompt: None,
26 submission_id: Uuid::new_v4(),
27 completed: false,
28 result: None,
29 }
30 }
31
32 pub fn new_with_image<T: Into<String>>(
34 task: T,
35 image_mime: ImageMime,
36 image_data: Vec<u8>,
37 ) -> Self {
38 Self {
39 prompt: task.into(),
40 image: Some((image_mime, image_data)),
41 system_prompt: None,
42 submission_id: Uuid::new_v4(),
43 completed: false,
44 result: None,
45 }
46 }
47
48 pub fn with_system_prompt<T: Into<String>>(mut self, prompt: T) -> Self {
49 self.system_prompt = Some(prompt.into());
50 self
51 }
52}