send tool call log as .md file, deploy assets, fix status(&mut self)
This commit is contained in:
1
Makefile
1
Makefile
@@ -35,6 +35,7 @@ deploy: test build
|
||||
scp config.suite.yaml $(SUITE):/data/noc/config.yaml
|
||||
scp noc.service.in $(SUITE):/data/noc/
|
||||
rsync -a tools/ $(SUITE):/data/noc/tools/
|
||||
rsync -a assets/ $(SUITE):/data/noc/assets/
|
||||
ssh $(SUITE) 'bash -lc "\
|
||||
cd /data/noc \
|
||||
&& sed -e \"s|@REPO@|/data/noc|g\" -e \"s|@PATH@|\$$PATH|g\" noc.service.in > ~/.config/systemd/user/noc.service \
|
||||
|
||||
@@ -18,7 +18,7 @@ pub trait Output: Send + Sync {
|
||||
async fn finalize(&mut self, text: &str) -> Result<()>;
|
||||
|
||||
/// Send a status/notification line (e.g. "[tool: bash] running...")
|
||||
async fn status(&self, text: &str) -> Result<()>;
|
||||
async fn status(&mut self, text: &str) -> Result<()>;
|
||||
|
||||
/// Send a file. Returns Ok(true) if sent, Ok(false) if not supported.
|
||||
async fn send_file(&self, path: &Path, caption: &str) -> Result<bool>;
|
||||
@@ -43,6 +43,7 @@ pub struct TelegramOutput {
|
||||
use_draft: bool,
|
||||
last_edit: Instant,
|
||||
http: reqwest::Client,
|
||||
tool_log: Vec<String>,
|
||||
}
|
||||
|
||||
impl TelegramOutput {
|
||||
@@ -55,6 +56,7 @@ impl TelegramOutput {
|
||||
use_draft: is_private,
|
||||
last_edit: Instant::now(),
|
||||
http: reqwest::Client::new(),
|
||||
tool_log: Vec::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -118,11 +120,23 @@ impl Output for TelegramOutput {
|
||||
text,
|
||||
)
|
||||
.await;
|
||||
|
||||
// send tool call log as .md file if any
|
||||
if !self.tool_log.is_empty() {
|
||||
let md = self.tool_log.join("\n");
|
||||
let tmp = format!("/tmp/noc_tools_{}.md", std::process::id());
|
||||
if std::fs::write(&tmp, &md).is_ok() {
|
||||
let input_file = InputFile::file(std::path::Path::new(&tmp));
|
||||
let _ = self.bot.send_document(self.chat_id, input_file).await;
|
||||
let _ = std::fs::remove_file(&tmp);
|
||||
}
|
||||
self.tool_log.clear();
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn status(&self, text: &str) -> Result<()> {
|
||||
let _ = self.bot.send_message(self.chat_id, text).await;
|
||||
async fn status(&mut self, text: &str) -> Result<()> {
|
||||
self.tool_log.push(text.to_string());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -162,7 +176,7 @@ impl Output for GiteaOutput {
|
||||
.await
|
||||
}
|
||||
|
||||
async fn status(&self, _text: &str) -> Result<()> {
|
||||
async fn status(&mut self, _text: &str) -> Result<()> {
|
||||
// No status updates for Gitea
|
||||
Ok(())
|
||||
}
|
||||
@@ -201,7 +215,7 @@ impl Output for BufferOutput {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn status(&self, _text: &str) -> Result<()> {
|
||||
async fn status(&mut self, _text: &str) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
@@ -625,7 +625,7 @@ pub async fn spawn_agent(
|
||||
id: &str,
|
||||
task: &str,
|
||||
state: &Arc<AppState>,
|
||||
output: &dyn Output,
|
||||
output: &mut dyn Output,
|
||||
sid: &str,
|
||||
_config: &Arc<Config>,
|
||||
chat_id: i64,
|
||||
|
||||
Reference in New Issue
Block a user