feat: Allow inline buttons and popup confirmation for both ACP and normal Providers (#2760)
Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
This commit is contained in:
@@ -14,7 +14,8 @@ local Providers = require("avante.providers")
|
||||
local LLMToolHelpers = require("avante.llm_tools.helpers")
|
||||
local LLMTools = require("avante.llm_tools")
|
||||
local History = require("avante.history")
|
||||
local Highlights = require("avante.highlights")
|
||||
local HistoryRender = require("avante.history.render")
|
||||
local ACPConfirmAdapter = require("avante.ui.acp_confirm_adapter")
|
||||
|
||||
---@class avante.LLM
|
||||
local M = {}
|
||||
@@ -49,10 +50,9 @@ function M.summarize_memory(prev_memory, history_messages, cb)
|
||||
cb(nil)
|
||||
return
|
||||
end
|
||||
local Render = require("avante.history.render")
|
||||
local conversation_items = vim
|
||||
.iter(history_messages)
|
||||
:map(function(msg) return msg.message.role .. ": " .. Render.message_to_text(msg, history_messages) end)
|
||||
:map(function(msg) return msg.message.role .. ": " .. HistoryRender.message_to_text(msg, history_messages) end)
|
||||
:totable()
|
||||
local conversation_text = table.concat(conversation_items, "\n")
|
||||
local user_prompt = "Here is the conversation so far:\n"
|
||||
@@ -1040,33 +1040,9 @@ function M._stream_acp(opts)
|
||||
Utils.error("Avante sidebar not found")
|
||||
return
|
||||
end
|
||||
|
||||
---@cast tool_call avante.acp.ToolCall
|
||||
local items = vim
|
||||
.iter(options)
|
||||
:map(function(item)
|
||||
local icon = item.kind == "allow_once" and "" or ""
|
||||
if item.kind == "allow_always" then icon = "" end
|
||||
local hl = nil
|
||||
if item.kind == "reject_once" or item.kind == "reject_always" then
|
||||
hl = Highlights.BUTTON_DANGER_HOVER
|
||||
end
|
||||
return {
|
||||
id = item.optionId,
|
||||
name = item.name,
|
||||
icon = icon,
|
||||
hl = hl,
|
||||
}
|
||||
end)
|
||||
:totable()
|
||||
sidebar.permission_button_options = items
|
||||
sidebar.permission_handler = function(id)
|
||||
callback(id)
|
||||
sidebar.scroll = true
|
||||
sidebar.permission_button_options = nil
|
||||
sidebar.permission_handler = nil
|
||||
sidebar._history_cache_invalidated = true
|
||||
sidebar:update_content("")
|
||||
end
|
||||
|
||||
local message = tool_call_messages[tool_call.toolCallId]
|
||||
if not message then
|
||||
message = add_tool_call_message(tool_call)
|
||||
@@ -1076,7 +1052,29 @@ function M._stream_acp(opts)
|
||||
message.acp_tool_call = vim.tbl_deep_extend("force", message.acp_tool_call, tool_call)
|
||||
end
|
||||
end
|
||||
|
||||
on_messages_add({ message })
|
||||
|
||||
local description = HistoryRender.get_tool_display_name(message)
|
||||
LLMToolHelpers.confirm(description, function(ok)
|
||||
local acp_mapped_options = ACPConfirmAdapter.map_acp_options(options)
|
||||
|
||||
if ok and opts.session_ctx and opts.session_ctx.always_yes then
|
||||
callback(acp_mapped_options.all)
|
||||
elseif ok then
|
||||
callback(acp_mapped_options.yes)
|
||||
else
|
||||
callback(acp_mapped_options.no)
|
||||
end
|
||||
|
||||
sidebar.scroll = true
|
||||
sidebar._history_cache_invalidated = true
|
||||
sidebar:update_content("")
|
||||
end, {
|
||||
focus = true,
|
||||
skip_reject_prompt = true,
|
||||
permission_options = options,
|
||||
}, opts.session_ctx, tool_call.kind)
|
||||
end,
|
||||
on_read_file = function(path, line, limit, callback)
|
||||
local abs_path = Utils.to_absolute_path(path)
|
||||
|
||||
Reference in New Issue
Block a user