From 7608dce00ed9ddfdfaaee9eb4cca1e3cebf7b0c4 Mon Sep 17 00:00:00 2001 From: Jie Liu Date: Mon, 29 Dec 2025 19:11:30 +0800 Subject: [PATCH] Support loading ACP sessions if agent can (#2889) --- lua/avante/llm.lua | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/lua/avante/llm.lua b/lua/avante/llm.lua index 6b7be79..b982530 100644 --- a/lua/avante/llm.lua +++ b/lua/avante/llm.lua @@ -1320,8 +1320,7 @@ function M._stream_acp(opts) if not session_id then M._create_acp_session_and_continue(opts, acp_client) else - if opts.just_connect_acp_client then return end - M._continue_stream_acp(opts, acp_client, session_id) + M._load_acp_session_and_continue(opts, acp_client, session_id) end end) return @@ -1357,6 +1356,23 @@ function M._create_acp_session_and_continue(opts, acp_client) end) end +---@param opts AvanteLLMStreamOptions +---@param acp_client avante.acp.ACPClient +---@param session_id string +function M._load_acp_session_and_continue(opts, acp_client, session_id) + local project_root = Utils.root.get() + acp_client:load_session(session_id, project_root, {}, function(_, err) + if err then + -- Failed to load session, create a new one. It happens after switching acp providers + M._create_acp_session_and_continue(opts, acp_client) + return + end + + if opts.just_connect_acp_client then return end + M._continue_stream_acp(opts, acp_client, session_id) + end) +end + ---@param opts AvanteLLMStreamOptions ---@param acp_client avante.acp.ACPClient ---@param session_id string