Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 10 additions & 14 deletions lua/eca/sidebar.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1224,19 +1224,17 @@ function M:handle_chat_content_received(params)
self:_handle_tool_call_prepare(content)
-- IMPORTANT: Return immediately - do NOT display anything for toolCallPrepare
return
elseif content.type == "toolCallRunning" then
-- Show the accumulated tool call
self:_display_tool_call(content)
elseif content.type == "toolCalled" then
local tool_text = nil
local tool_text = (content.summary or "Tool call")
Copy link

Copilot AI Sep 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line assumes content.summary exists, but for toolCalled messages, content.summary is optional according to the type definition. This could result in unexpected behavior when content.summary is nil.

Copilot uses AI. Check for mistakes.

-- Add diff to current tool call if present in toolCalled content
if self._current_tool_call and content.details then
self._current_tool_call.details = content.details
end

-- Show the final accumulated tool call if we have one
if self._is_tool_call_streaming and self._current_tool_call then
tool_text = self:_display_tool_call()
end

-- Show the tool result
local tool_log = string.format("**Tool Result**: %s", content.name or "unknown")
if content.outputs and #content.outputs > 0 then
Expand All @@ -1254,9 +1252,10 @@ function M:handle_chat_content_received(params)
tool_text_completed = "❌ "
end

tool_text_completed = tool_text_completed .. (content.summary or content.name or "Tool call completed")
local tool_text_running = "🔧 " .. tool_text
tool_text_completed = tool_text_completed .. tool_text

if tool_text == nil or not self:_replace_text(tool_text or "", tool_text_completed) then
if tool_text == nil or not self:_replace_text(tool_text_running, tool_text_completed) then
self:_add_message("assistant", tool_text_completed)
end

Expand Down Expand Up @@ -1562,14 +1561,13 @@ function M:_handle_tool_call_prepare(content)
end
end

---@return string tool text
function M:_display_tool_call()
if not self._current_tool_call then
function M:_display_tool_call(content)
if not self._is_tool_call_streaming or not self._current_tool_call then
Copy link

Copilot AI Sep 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function now requires a content parameter but doesn't validate that it's not nil before using it on line 1570. This could cause a nil dereference error if called with nil content.

Suggested change
if not self._is_tool_call_streaming or not self._current_tool_call then
if not self._is_tool_call_streaming or not self._current_tool_call or not content then

Copilot uses AI. Check for mistakes.
return nil
end

local diff = ""
local tool_text = "🔧 " .. (self._current_tool_call.summary or "Tool call prepared")
local tool_text = "🔧 " .. (content.summary or self._current_tool_call.summary or "Tool call")
local tool_log = string.format("**Tool Call**: %s", self._current_tool_call.name or "unknown")

if self._current_tool_call.arguments and self._current_tool_call.arguments ~= "" then
Expand All @@ -1582,8 +1580,6 @@ function M:_display_tool_call()

Logger.debug(tool_log .. diff)
self:_add_message("assistant", tool_text .. diff)

return tool_text
end

function M:_finalize_tool_call()
Expand Down
9 changes: 9 additions & 0 deletions lua/eca/types.lua
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@
---@field summary string summary text to present about this tool call
---@field details eca.ToolCallDetails extra details for the call. clients may use this to present a different UX for this tool call.

---@class eca.ToolCallRunning
---@field type 'toolCallRunning'
---@field origin eca.ToolCallOrigin
---@field id string the id of the tool call
---@field name string name of the tool
---@field arguments {[string]: string} arguments of the tool call
---@field summary? string summary text to present about this tool call
---@field details? eca.ToolCallDetails extra details for the call. clients may use this to present a different UX for this tool call.

---@class eca.ToolCalled
---@field type 'toolCalled'
---@field id string the id of the tool call
Expand Down