Skip to content
Merged
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
35 changes: 26 additions & 9 deletions lua/CopilotChat/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -973,23 +973,40 @@ function M.ask(prompt, config)
if not config.headless then
utils.schedule_main()

-- Remove any tool calls that we did not handle
local assistant_message = M.chat:get_message('assistant')
if assistant_message and assistant_message.tool_calls then
local handled_ids = {}
for _, tool in ipairs(resolved_tools) do
handled_ids[tool.id] = true
end

assistant_message.tool_calls = vim
.iter(assistant_message.tool_calls)
:filter(function(tool_call)
return handled_ids[tool_call.id]
end)
:totable()
end

if not utils.empty(resolved_tools) then
-- If we are handling tools, replace user message with tool results
M.chat:remove_message('user')
for _, tool in ipairs(resolved_tools) do
M.chat:add_message({
id = tool.id,
role = 'tool',
tool_call_id = tool.id,
content = '\n' .. tool.result .. '\n',
})
end
else
-- Otherwise just replace the user message with resolved prompt
M.chat:add_message({
role = 'user',
content = '\n' .. prompt .. '\n',
}, true)
end

for _, tool in ipairs(resolved_tools) do
M.chat:add_message({
id = tool.id,
role = 'tool',
tool_call_id = tool.id,
content = '\n' .. tool.result .. '\n',
})
end
end

if utils.empty(prompt) and utils.empty(resolved_tools) then
Expand Down
Loading