feat: support codex acp provider (#2774)
This commit is contained in:
27
README.md
27
README.md
@@ -1208,6 +1208,22 @@ To use ACP-compatible agents with Avante.nvim, you need to configure an ACP prov
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### Goose with ACP
|
||||||
|
```lua
|
||||||
|
{
|
||||||
|
provider = "goose",
|
||||||
|
-- other configuration options...
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Codex with ACP
|
||||||
|
```lua
|
||||||
|
{
|
||||||
|
provider = "codex",
|
||||||
|
-- other configuration options...
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
### ACP Configuration
|
### ACP Configuration
|
||||||
|
|
||||||
ACP providers are configured in the `acp_providers` section of your configuration:
|
ACP providers are configured in the `acp_providers` section of your configuration:
|
||||||
@@ -1231,6 +1247,17 @@ ACP providers are configured in the `acp_providers` section of your configuratio
|
|||||||
ANTHROPIC_API_KEY = os.getenv("ANTHROPIC_API_KEY"),
|
ANTHROPIC_API_KEY = os.getenv("ANTHROPIC_API_KEY"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
["goose"] = {
|
||||||
|
command = "goose",
|
||||||
|
args = { "acp" },
|
||||||
|
},
|
||||||
|
["codex"] = {
|
||||||
|
command = "codex-acp",
|
||||||
|
env = {
|
||||||
|
NODE_NO_WARNINGS = "1",
|
||||||
|
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY"),
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
-- other configuration options...
|
-- other configuration options...
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -262,6 +262,13 @@ M._defaults = {
|
|||||||
command = "goose",
|
command = "goose",
|
||||||
args = { "acp" },
|
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
|
---To add support for custom provider, follow the format below
|
||||||
---See https://github.com/yetone/avante.nvim/wiki#custom-providers for more details
|
---See https://github.com/yetone/avante.nvim/wiki#custom-providers for more details
|
||||||
|
|||||||
@@ -86,7 +86,11 @@ end
|
|||||||
local function thinking_to_lines(item)
|
local function thinking_to_lines(item)
|
||||||
local text = item.thinking or item.data or ""
|
local text = item.thinking or item.data or ""
|
||||||
local text_lines = vim.split(text, "\n")
|
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
|
while #text_lines > 0 and text_lines[#text_lines] == "" do
|
||||||
table.remove(text_lines, #text_lines)
|
table.remove(text_lines, #text_lines)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -509,7 +509,7 @@ function ACPClient:_send_result(id, result)
|
|||||||
|
|
||||||
local data = vim.json.encode(message)
|
local data = vim.json.encode(message)
|
||||||
if self.debug_log_file then
|
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()
|
self.debug_log_file:flush()
|
||||||
end
|
end
|
||||||
self.transport:send(data)
|
self.transport:send(data)
|
||||||
|
|||||||
@@ -907,7 +907,7 @@ function M._stream_acp(opts)
|
|||||||
end
|
end
|
||||||
if opts.on_messages_add then
|
if opts.on_messages_add then
|
||||||
opts.on_messages_add(messages)
|
opts.on_messages_add(messages)
|
||||||
vim.schedule(function() vim.cmd("redraw") end)
|
-- vim.schedule(function() vim.cmd("redraw") end)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
local function add_tool_call_message(update)
|
local function add_tool_call_message(update)
|
||||||
@@ -992,6 +992,24 @@ function M._stream_acp(opts)
|
|||||||
end
|
end
|
||||||
if update.sessionUpdate == "agent_thought_chunk" then
|
if update.sessionUpdate == "agent_thought_chunk" then
|
||||||
if update.content.type == "text" 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", {
|
local message = History.Message:new("assistant", {
|
||||||
type = "thinking",
|
type = "thinking",
|
||||||
thinking = update.content.text,
|
thinking = update.content.text,
|
||||||
|
|||||||
@@ -1949,7 +1949,7 @@ function Sidebar:get_message_lines(ctx, message, messages, ignore_record_prefix)
|
|||||||
if type(item) == "string" then
|
if type(item) == "string" then
|
||||||
text_len = text_len + #item
|
text_len = text_len + #item
|
||||||
else
|
else
|
||||||
for _, subitem in ipairs(item) do
|
for _, subitem in pairs(item) do
|
||||||
if type(subitem) == "string" then text_len = text_len + #subitem end
|
if type(subitem) == "string" then text_len = text_len + #subitem end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user