Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4,864 changes: 0 additions & 4,864 deletions crates/pu-engine/src/engine.rs

This file was deleted.

516 changes: 516 additions & 0 deletions crates/pu-engine/src/engine/agent_lifecycle.rs

Large diffs are not rendered by default.

163 changes: 163 additions & 0 deletions crates/pu-engine/src/engine/definitions/agent_defs.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
use std::path::Path;

use pu_core::paths;
use pu_core::protocol::{AgentDefInfo, Response};

use super::super::Engine;

impl Engine {
pub(in crate::engine) async fn handle_list_agent_defs(&self, project_root: &str) -> Response {
let pr = project_root.to_string();
match tokio::task::spawn_blocking(move || {
let root = Path::new(&pr);
let defs = pu_core::agent_def::list_agent_defs(root);
let infos: Vec<AgentDefInfo> = defs
.into_iter()
.map(|d| AgentDefInfo {
name: d.name,
agent_type: d.agent_type,
template: d.template,
inline_prompt: d.inline_prompt,
tags: d.tags,
scope: d.scope,
available_in_command_dialog: d.available_in_command_dialog,
icon: d.icon,
command: d.command,
})
.collect();
infos
})
.await
{
Ok(agent_defs) => Response::AgentDefList { agent_defs },
Err(e) => Response::Error {
code: "INTERNAL_ERROR".into(),
message: format!("task join error: {e}"),
},
}
}

pub(in crate::engine) async fn handle_get_agent_def(
&self,
project_root: &str,
name: &str,
) -> Response {
let pr = project_root.to_string();
let n = name.to_string();
match tokio::task::spawn_blocking(move || {
pu_core::agent_def::find_agent_def(Path::new(&pr), &n)
})
.await
{
Ok(Some(d)) => Response::AgentDefDetail {
name: d.name,
agent_type: d.agent_type,
template: d.template,
inline_prompt: d.inline_prompt,
tags: d.tags,
scope: d.scope,
available_in_command_dialog: d.available_in_command_dialog,
icon: d.icon,
command: d.command,
},
Ok(None) => Response::Error {
code: "NOT_FOUND".into(),
message: format!("agent def '{name}' not found"),
},
Err(e) => Response::Error {
code: "INTERNAL_ERROR".into(),
message: format!("task join error: {e}"),
},
}
}

#[allow(clippy::too_many_arguments)]
pub(in crate::engine) async fn handle_save_agent_def(
&self,
project_root: &str,
name: &str,
agent_type: &str,
template: Option<String>,
inline_prompt: Option<String>,
tags: Vec<String>,
scope: &str,
available_in_command_dialog: bool,
icon: Option<String>,
command: Option<String>,
) -> Response {
let dir = match Self::resolve_scope_dir(
project_root,
scope,
paths::agents_dir,
paths::global_agents_dir,
) {
Ok(d) => d,
Err(msg) => {
return Response::Error {
code: "IO_ERROR".into(),
message: msg,
};
}
};
let def = pu_core::agent_def::AgentDef {
name: name.to_string(),
agent_type: agent_type.to_string(),
template,
inline_prompt,
tags,
scope: scope.to_string(),
available_in_command_dialog,
icon,
command,
};
match tokio::task::spawn_blocking(move || pu_core::agent_def::save_agent_def(&dir, &def))
.await
{
Ok(Ok(())) => Response::Ok,
Ok(Err(e)) => Response::Error {
code: "IO_ERROR".into(),
message: format!("failed to save agent def: {e}"),
},
Err(e) => Response::Error {
code: "INTERNAL_ERROR".into(),
message: format!("task join error: {e}"),
},
}
}

pub(in crate::engine) async fn handle_delete_agent_def(
&self,
project_root: &str,
name: &str,
scope: &str,
) -> Response {
let dir = match Self::resolve_scope_dir(
project_root,
scope,
paths::agents_dir,
paths::global_agents_dir,
) {
Ok(d) => d,
Err(msg) => {
return Response::Error {
code: "IO_ERROR".into(),
message: msg,
};
}
};
let n = name.to_string();
match tokio::task::spawn_blocking(move || pu_core::agent_def::delete_agent_def(&dir, &n))
.await
{
Ok(Ok(_)) => Response::Ok,
Ok(Err(e)) => Response::Error {
code: "IO_ERROR".into(),
message: format!("failed to delete agent def: {e}"),
},
Err(e) => Response::Error {
code: "INTERNAL_ERROR".into(),
message: format!("task join error: {e}"),
},
}
}
}
5 changes: 5 additions & 0 deletions crates/pu-engine/src/engine/definitions/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
mod agent_defs;
mod schedules;
mod swarm_defs;
mod templates;
mod triggers;
Loading
Loading