Skip to content

Commit 2022f33

Browse files
authored
Merge pull request #38 from altaidevorg/ask-user
Load associated thread from notification clicks
2 parents 422e1e3 + a1e8392 commit 2022f33

8 files changed

Lines changed: 91 additions & 45 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "isanagent"
3-
version = "0.8.0"
3+
version = "0.9.0"
44
edition = "2021"
55
license = "Apache-2.0"
66
repository = "https://github.com/altaidevorg/isanagent"

src/agent/mod.rs

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,11 @@ fn repair_tool_call_context(context: &mut Vec<crate::utils::ChatMessage>) {
221221
for id in missing {
222222
context.insert(
223223
j,
224-
crate::utils::ChatMessage::tool("[Cancelled — tool execution interrupted]", &id),
224+
crate::utils::ChatMessage::tool(
225+
"[Cancelled — tool execution interrupted]",
226+
&id,
227+
None,
228+
),
225229
);
226230
j += 1;
227231
}
@@ -1604,9 +1608,28 @@ impl AgentLogic {
16041608
// 2. Inject tool response into memory
16051609
if let Some(id) = tool_call_id {
16061610
if let Ok(mut mem) = self.session_manager.get_session(session_key).await {
1607-
mem.add_message(crate::utils::ChatMessage::tool(&inbound.content, id))
1608-
.await
1609-
.map_err(|e| format!("Failed to inject tool response into memory: {}", e))?;
1611+
// Determine tool name from memory
1612+
let mut tool_name_for_resume = None;
1613+
if let Ok(context) = mem.get_context().await {
1614+
for msg in context.iter().rev() {
1615+
if msg.role == "assistant" {
1616+
if let Some(calls) = &msg.tool_calls {
1617+
if let Some(tc) = calls.iter().find(|c| c.id == id) {
1618+
tool_name_for_resume = Some(tc.function.name.clone());
1619+
break;
1620+
}
1621+
}
1622+
}
1623+
}
1624+
}
1625+
1626+
mem.add_message(crate::utils::ChatMessage::tool(
1627+
&inbound.content,
1628+
id,
1629+
tool_name_for_resume.as_deref(),
1630+
))
1631+
.await
1632+
.map_err(|e| format!("Failed to inject tool response into memory: {}", e))?;
16101633
} else {
16111634
return Err(format!("Failed to get session {}", session_key));
16121635
}
@@ -2251,14 +2274,18 @@ impl AgentLogic {
22512274
hook_observe_telemetry(hook_tool_ctx.as_ref(), &inbound, is_subagent, tr);
22522275
let tfin = TelemetryEvent::ToolCallFinished {
22532276
chat_id: inbound.chat_id.clone(),
2254-
tool_name,
2277+
tool_name: tool_name.clone(),
22552278
result: tool_result_text.clone(),
22562279
background_job_id: crate::bus::get_background_job_id(&inbound.metadata),
22572280
};
22582281
let _ = outbound_tx.send(BusMessage::Telemetry(tfin.clone())).await;
22592282
hook_observe_telemetry(hook_tool_ctx.as_ref(), &inbound, is_subagent, tfin);
2260-
mem.add_message(crate::utils::ChatMessage::tool(&tool_result_text, &tc.id))
2261-
.await?;
2283+
mem.add_message(crate::utils::ChatMessage::tool(
2284+
&tool_result_text,
2285+
&tc.id,
2286+
Some(tool_name.as_str()),
2287+
))
2288+
.await?;
22622289
}
22632290
tool_invoked = true;
22642291
} else {
@@ -2356,8 +2383,12 @@ impl AgentLogic {
23562383
let _ = outbound_tx.send(BusMessage::Telemetry(tfin.clone())).await;
23572384
hook_observe_telemetry(hook_tool_ctx.as_ref(), &inbound, is_subagent, tfin);
23582385

2359-
mem.add_message(crate::utils::ChatMessage::tool(&tool_result_text, &tc.id))
2360-
.await?;
2386+
mem.add_message(crate::utils::ChatMessage::tool(
2387+
&tool_result_text,
2388+
&tc.id,
2389+
Some(tool_name.as_str()),
2390+
))
2391+
.await?;
23612392
tool_invoked = true;
23622393
}
23632394
}

src/channels/terminal_ui/run.rs

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2195,11 +2195,13 @@ pub(crate) fn run_ratatui_main(config: RatatuiMainConfig) -> io::Result<()> {
21952195
if app.ui_focus == TerminalUiFocus::Conversations
21962196
|| app.ui_focus == TerminalUiFocus::BackgroundJobs
21972197
{
2198-
let selected_chat_id = if app.ui_focus == TerminalUiFocus::Conversations
2199-
{
2198+
let selected_id = if app.ui_focus == TerminalUiFocus::Conversations {
22002199
if let Some(idx) = app.conversations_selected_idx {
22012200
if idx < app.conversations_items.len() {
2202-
Some(app.conversations_items[idx].thread_id.clone())
2201+
Some((
2202+
app.conversations_items[idx].thread_id.clone(),
2203+
false,
2204+
))
22032205
} else {
22042206
None
22052207
}
@@ -2211,27 +2213,38 @@ pub(crate) fn run_ratatui_main(config: RatatuiMainConfig) -> io::Result<()> {
22112213
if let Some(idx) = app.background_jobs_selected_idx {
22122214
app.background_panel_items()
22132215
.get(idx)
2214-
.map(|item| item.chat_id().to_string())
2216+
.map(|item| (item.chat_id().to_string(), true))
22152217
} else {
22162218
None
22172219
}
22182220
};
22192221

2220-
if let Some(thread_id) = selected_chat_id {
2221-
let new_cid = match chat_id_from_root_thread_id(
2222-
channel_name.as_str(),
2223-
&thread_id,
2224-
) {
2225-
Some(c) => c,
2226-
None => {
2227-
app.set_toast(
2228-
ToastKind::Err,
2229-
"Invalid session row.".into(),
2230-
Duration::from_secs(4),
2231-
);
2232-
continue;
2233-
}
2222+
if let Some((target_id, is_chat_id)) = selected_id {
2223+
let (thread_id, new_cid) = if is_chat_id {
2224+
let tid = crate::bus::clarification_session_key(
2225+
channel_name.as_str(),
2226+
&target_id,
2227+
None,
2228+
);
2229+
(tid, target_id)
2230+
} else {
2231+
let cid = match chat_id_from_root_thread_id(
2232+
channel_name.as_str(),
2233+
&target_id,
2234+
) {
2235+
Some(c) => c,
2236+
None => {
2237+
app.set_toast(
2238+
ToastKind::Err,
2239+
"Invalid session row.".into(),
2240+
Duration::from_secs(4),
2241+
);
2242+
continue;
2243+
}
2244+
};
2245+
(target_id, cid)
22342246
};
2247+
22352248
try_cancel_inflight(&mut app, &bus_tx, &chat_id);
22362249
match load_thread_transcript_cells(&rt, &memory_node, &thread_id) {
22372250
Ok(mut cells) => {

src/utils.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,11 +176,11 @@ impl ChatMessage {
176176
}
177177
}
178178

179-
pub fn tool(content: &str, tool_call_id: &str) -> Self {
179+
pub fn tool(content: &str, tool_call_id: &str, name: Option<&str>) -> Self {
180180
Self {
181181
role: "tool".to_string(),
182182
content: Some(MessageContent::Text(content.to_string())),
183-
name: None,
183+
name: name.map(|s| s.to_string()),
184184
tool_calls: None,
185185
tool_call_id: Some(tool_call_id.to_string()),
186186
reasoning_content: None,

0 commit comments

Comments
 (0)