MCPcopy Create free account
hub / github.com/GCWing/BitFun / handle_tool_event

Method handle_tool_event

src/apps/cli/src/chat_state.rs:466–697  ·  view source on GitHub ↗

Handle a tool event. New tools are appended to current_flow_items in chronological order. Existing tools are updated in-place via tool_index for O(1) lookup.

(&mut self, tool_event: &ToolEventData)

Source from the content-addressed store, hash-verified

464 /// New tools are appended to current_flow_items in chronological order.
465 /// Existing tools are updated in-place via tool_index for O(1) lookup.
466 pub fn handle_tool_event(&mut self, tool_event: &ToolEventData) {
467 match tool_event {
468 ToolEventData::EarlyDetected { tool_id, tool_name } => {
469 self.insert_or_update_tool(
470 tool_id,
471 |_existing| {
472 // Should not exist yet, but handle gracefully
473 },
474 || ToolDisplayState {
475 tool_id: tool_id.clone(),
476 tool_name: tool_name.clone(),
477 parameters: serde_json::Value::Null,
478 status: ToolDisplayStatus::EarlyDetected,
479 result: None,
480 progress_message: None,
481 duration_ms: None,
482 metadata: None,
483 subagent_progress: None,
484 },
485 );
486 self.rebuild_streaming_message();
487 }
488
489 ToolEventData::ParamsPartial {
490 tool_id, params, ..
491 } => {
492 self.update_tool(tool_id, |tool| {
493 // Only update status if not yet in an advanced execution state.
494 // Due to priority queue ordering, ParamsPartial (Normal priority) may
495 // arrive after Started (High priority), which would incorrectly
496 // revert the status from Running back to ParamsPartial.
497 if !tool.status.is_execution_phase() {
498 tool.status = ToolDisplayStatus::ParamsPartial;
499 }
500 tool.progress_message = Some(params.clone());
501 });
502 self.rebuild_streaming_message();
503 }
504
505 ToolEventData::Queued {
506 tool_id, position, ..
507 } => {
508 self.update_tool(tool_id, |tool| {
509 if !tool.status.is_execution_phase() {
510 tool.status = ToolDisplayStatus::Queued;
511 }
512 tool.progress_message = Some(format!("Queue position: {}", position));
513 });
514 self.rebuild_streaming_message();
515 }
516
517 ToolEventData::Waiting {
518 tool_id,
519 dependencies,
520 ..
521 } => {
522 self.update_tool(tool_id, |tool| {
523 if !tool.status.is_execution_phase() {

Callers 1

runMethod · 0.80

Calls 7

extract_fallback_summaryFunction · 0.85
insert_or_update_toolMethod · 0.80
update_toolMethod · 0.80
is_execution_phaseMethod · 0.80
cloneMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected