feat: Hooks (#9093)
This commit is contained in:
@@ -500,6 +500,28 @@ impl CliSession {
|
||||
|
||||
/// Start an interactive session, optionally with an initial message
|
||||
pub async fn interactive(&mut self, prompt: Option<String>) -> Result<()> {
|
||||
self.agent
|
||||
.emit_hook(goose::hooks::HookEvent::SessionStart, &self.session_id)
|
||||
.await;
|
||||
|
||||
let result = self.run_interactive(prompt).await;
|
||||
|
||||
self.agent
|
||||
.emit_hook(goose::hooks::HookEvent::SessionEnd, &self.session_id)
|
||||
.await;
|
||||
|
||||
if result.is_ok() {
|
||||
println!(
|
||||
"\n {} {}",
|
||||
console::style("●").red(),
|
||||
console::style(format!("session closed · {}", &self.session_id)).dim()
|
||||
);
|
||||
}
|
||||
|
||||
result
|
||||
}
|
||||
|
||||
async fn run_interactive(&mut self, prompt: Option<String>) -> Result<()> {
|
||||
if let Some(prompt) = prompt {
|
||||
let msg = Message::user().with_text(&prompt);
|
||||
self.process_message(msg, CancellationToken::default(), true)
|
||||
@@ -536,12 +558,6 @@ impl CliSession {
|
||||
.await?;
|
||||
}
|
||||
|
||||
println!(
|
||||
"\n {} {}",
|
||||
console::style("●").red(),
|
||||
console::style(format!("session closed · {}", &self.session_id)).dim()
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1044,9 +1060,17 @@ impl CliSession {
|
||||
|
||||
/// Process a single message and exit
|
||||
pub async fn headless(&mut self, prompt: String) -> Result<()> {
|
||||
self.agent
|
||||
.emit_hook(goose::hooks::HookEvent::SessionStart, &self.session_id)
|
||||
.await;
|
||||
let message = Message::user().with_text(&prompt);
|
||||
self.process_message(message, CancellationToken::default(), false)
|
||||
.await?;
|
||||
let result = self
|
||||
.process_message(message, CancellationToken::default(), false)
|
||||
.await;
|
||||
self.agent
|
||||
.emit_hook(goose::hooks::HookEvent::SessionEnd, &self.session_id)
|
||||
.await;
|
||||
result?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user