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

Method insert_or_update_tool

src/apps/cli/src/chat_state.rs:905–925  ·  view source on GitHub ↗

Insert a new tool into current_flow_items (appended at end, preserving chronological order), or update an existing tool in-place if it already exists.

(
        &mut self,
        tool_id: &str,
        update_fn: impl FnOnce(&mut ToolDisplayState),
        create_fn: impl FnOnce() -> ToolDisplayState,
    )

Source from the content-addressed store, hash-verified

903 /// Insert a new tool into current_flow_items (appended at end, preserving chronological order),
904 /// or update an existing tool in-place if it already exists.
905 fn insert_or_update_tool(
906 &mut self,
907 tool_id: &str,
908 update_fn: impl FnOnce(&mut ToolDisplayState),
909 create_fn: impl FnOnce() -> ToolDisplayState,
910 ) {
911 if let Some(&idx) = self.tool_index.get(tool_id) {
912 // Tool already exists — update in-place
913 if let Some(FlowItem::Tool { tool_state }) = self.current_flow_items.get_mut(idx) {
914 update_fn(tool_state);
915 }
916 } else {
917 // New tool — append to flow items in chronological order
918 let new_state = create_fn();
919 let idx = self.current_flow_items.len();
920 self.current_flow_items.push(FlowItem::Tool {
921 tool_state: new_state,
922 });
923 self.tool_index.insert(tool_id.to_string(), idx);
924 }
925 }
926
927 /// Update an existing tool in current_flow_items via tool_index.
928 /// No-op if the tool_id is not found (defensive).

Callers 1

handle_tool_eventMethod · 0.80

Calls 5

get_mutMethod · 0.80
getMethod · 0.45
lenMethod · 0.45
pushMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected