Skip to content

Commit 4d2586b

Browse files
authored
fix(functions): properly allow skipping handling for tools (#1257)
Signed-off-by: Tomas Slusny <[email protected]>
1 parent 560d61c commit 4d2586b

File tree

1 file changed

+26
-9
lines changed

1 file changed

+26
-9
lines changed

lua/CopilotChat/init.lua

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -973,23 +973,40 @@ function M.ask(prompt, config)
973973
if not config.headless then
974974
utils.schedule_main()
975975

976+
-- Remove any tool calls that we did not handle
977+
local assistant_message = M.chat:get_message('assistant')
978+
if assistant_message and assistant_message.tool_calls then
979+
local handled_ids = {}
980+
for _, tool in ipairs(resolved_tools) do
981+
handled_ids[tool.id] = true
982+
end
983+
984+
assistant_message.tool_calls = vim
985+
.iter(assistant_message.tool_calls)
986+
:filter(function(tool_call)
987+
return handled_ids[tool_call.id]
988+
end)
989+
:totable()
990+
end
991+
976992
if not utils.empty(resolved_tools) then
993+
-- If we are handling tools, replace user message with tool results
977994
M.chat:remove_message('user')
995+
for _, tool in ipairs(resolved_tools) do
996+
M.chat:add_message({
997+
id = tool.id,
998+
role = 'tool',
999+
tool_call_id = tool.id,
1000+
content = '\n' .. tool.result .. '\n',
1001+
})
1002+
end
9781003
else
1004+
-- Otherwise just replace the user message with resolved prompt
9791005
M.chat:add_message({
9801006
role = 'user',
9811007
content = '\n' .. prompt .. '\n',
9821008
}, true)
9831009
end
984-
985-
for _, tool in ipairs(resolved_tools) do
986-
M.chat:add_message({
987-
id = tool.id,
988-
role = 'tool',
989-
tool_call_id = tool.id,
990-
content = '\n' .. tool.result .. '\n',
991-
})
992-
end
9931010
end
9941011

9951012
if utils.empty(prompt) and utils.empty(resolved_tools) then

0 commit comments

Comments
 (0)