Skip to content

Commit b850dee

Browse files
committed
cleaner
1 parent a33e20a commit b850dee

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

backend/windmill-queue/src/jobs.rs

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -746,11 +746,6 @@ lazy_static::lazy_static! {
746746
pub static ref MAX_RESULT_SIZE_MB: usize = std::env::var("MAX_RESULT_SIZE_MB").unwrap_or("500".to_string()).parse().unwrap_or(500);
747747
}
748748

749-
#[derive(Deserialize)]
750-
struct OutputWrapper {
751-
output: String,
752-
}
753-
754749
pub async fn add_completed_job<T: Serialize + Send + Sync + ValidableJson>(
755750
db: &Pool<Postgres>,
756751
queued_job: &MiniPulledJob,
@@ -834,19 +829,26 @@ pub async fn add_completed_job<T: Serialize + Send + Sync + ValidableJson>(
834829
let value = serde_json::to_value(result.0)
835830
.map_err(|e| Error::internal_err(format!("Failed to serialize result: {e}")))?;
836831
if chat_input_enabled.unwrap_or(false) {
837-
let content =
838-
if let Ok(wrapper) = serde_json::from_value::<OutputWrapper>(value.clone()) {
839-
// Successfully deserialized to OutputWrapper, use the output field
840-
wrapper.output
841-
} else {
842-
// No string output field, use the whole result
843-
if let serde_json::Value::String(s) = value {
844-
s
832+
let content = match &value {
833+
// If it's an Object with "output" key AND the output is a String, return it
834+
serde_json::Value::Object(map)
835+
if map.contains_key("output")
836+
&& matches!(map.get("output"), Some(serde_json::Value::String(_))) =>
837+
{
838+
if let Some(serde_json::Value::String(s)) = map.get("output") {
839+
s.clone()
845840
} else {
846-
serde_json::to_string_pretty(&value)
841+
// serialize the whole result
842+
serde_json::to_string(&value)
847843
.unwrap_or_else(|e| format!("Failed to serialize result: {e}"))
848844
}
849-
};
845+
}
846+
// Otherwise, if the whole value is a String, return it
847+
serde_json::Value::String(s) => s.clone(),
848+
// Otherwise, prettify the whole result
849+
_ => serde_json::to_string(&value)
850+
.unwrap_or_else(|e| format!("Failed to serialize result: {e}")),
851+
};
850852

851853
// Update the assistant message
852854
let _ = sqlx::query!(

0 commit comments

Comments
 (0)