feat: support codex acp provider (#2774)

This commit is contained in:
yetone
2025-10-16 01:26:04 +08:00
committed by GitHub
parent 4fc83dc308
commit 4a68e29165
6 changed files with 60 additions and 4 deletions

View File

@@ -262,6 +262,13 @@ M._defaults = {
command = "goose",
args = { "acp" },
},
["codex"] = {
command = "codex-acp",
env = {
NODE_NO_WARNINGS = "1",
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY"),
},
},
},
---To add support for custom provider, follow the format below
---See https://github.com/yetone/avante.nvim/wiki#custom-providers for more details

View File

@@ -86,7 +86,11 @@ end
local function thinking_to_lines(item)
local text = item.thinking or item.data or ""
local text_lines = vim.split(text, "\n")
--- trime suffix empty lines
--- trim prefix empty lines
while #text_lines > 0 and text_lines[1] == "" do
table.remove(text_lines, 1)
end
--- trim suffix empty lines
while #text_lines > 0 and text_lines[#text_lines] == "" do
table.remove(text_lines, #text_lines)
end

View File

@@ -509,7 +509,7 @@ function ACPClient:_send_result(id, result)
local data = vim.json.encode(message)
if self.debug_log_file then
self.debug_log_file:write("request: " .. data .. string.rep("=", 100) .. "\n")
self.debug_log_file:write("request: " .. data .. "\n" .. string.rep("=", 100) .. "\n")
self.debug_log_file:flush()
end
self.transport:send(data)

View File

@@ -907,7 +907,7 @@ function M._stream_acp(opts)
end
if opts.on_messages_add then
opts.on_messages_add(messages)
vim.schedule(function() vim.cmd("redraw") end)
-- vim.schedule(function() vim.cmd("redraw") end)
end
end
local function add_tool_call_message(update)
@@ -992,6 +992,24 @@ function M._stream_acp(opts)
end
if update.sessionUpdate == "agent_thought_chunk" then
if update.content.type == "text" then
local messages = opts.get_history_messages()
local last_message = messages[#messages]
if last_message and last_message.message.role == "assistant" then
local is_thinking = false
local content = last_message.message.content
if type(content) == "table" then
for idx, item in ipairs(content) do
if type(item) == "table" and item.type == "thinking" then
is_thinking = true
content[idx].thinking = content[idx].thinking .. update.content.text
end
end
end
if is_thinking then
on_messages_add({ last_message })
return
end
end
local message = History.Message:new("assistant", {
type = "thinking",
thinking = update.content.text,

View File

@@ -1949,7 +1949,7 @@ function Sidebar:get_message_lines(ctx, message, messages, ignore_record_prefix)
if type(item) == "string" then
text_len = text_len + #item
else
for _, subitem in ipairs(item) do
for _, subitem in pairs(item) do
if type(subitem) == "string" then text_len = text_len + #subitem end
end
end