Skip to content

Commit 3f30dcb

Browse files
authored
fix(nvim): only allow HTTP adapters for codecompanion result summarisation. (#278)
1 parent 84d6d1a commit 3f30dcb

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

lua/vectorcode/integrations/codecompanion/query_tool.lua

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,23 @@ General Guidelines:
8686
},
8787
}
8888

89+
---Returns the adapter if it works with summarysation.
90+
---@return CodeCompanion.HTTPAdapter|nil
91+
local function check_adapter_for_summarisation(adapter)
92+
local resolved_adapter = require("codecompanion.adapters").resolve(adapter)
93+
if resolved_adapter.type == nil or resolved_adapter.type == "http" then
94+
return vim.deepcopy(resolved_adapter) --[[@as CodeCompanion.HTTPAdapter]]
95+
else
96+
vim.schedule_wrap(vim.notify)(
97+
[[VectorCode query summarisation doesn't work with ACP adapters yet.
98+
Summarysation will be disabled.
99+
Please configure an HTTP adapter for it.]],
100+
vim.log.levels.WARN,
101+
vc_config.notify_opts
102+
)
103+
end
104+
end
105+
89106
---@param opts VectorCode.CodeCompanion.QueryToolOpts|{}|nil
90107
---@return VectorCode.CodeCompanion.QueryToolOpts
91108
local get_query_tool_opts = function(opts)
@@ -228,7 +245,7 @@ end
228245

229246
---@alias ChatMessage {role: string, content:string}
230247

231-
---@param adapter CodeCompanion.Adapter
248+
---@param adapter CodeCompanion.HTTPAdapter
232249
---@param system_prompt string
233250
---@param user_messages string|string[]
234251
---@return {messages: ChatMessage[], tools:table?}
@@ -263,9 +280,12 @@ local function generate_summary(result, summarise_opts, cmd, callback)
263280
and type(callback) == "function"
264281
and #result > 0
265282
then
266-
---@type CodeCompanion.Adapter
267-
local adapter =
268-
vim.deepcopy(require("codecompanion.adapters").resolve(summarise_opts.adapter))
283+
---@type CodeCompanion.HTTPAdapter?
284+
local adapter = check_adapter_for_summarisation(summarise_opts.adapter)
285+
if adapter == nil then
286+
summarise_opts.enabled = false
287+
return callback(result_xml)
288+
end
269289

270290
local system_prompt = summarise_opts.system_prompt
271291
if type(system_prompt) == "function" then
@@ -293,10 +313,10 @@ When summarising the code, pay extra attention on information related to the que
293313
vim.deepcopy(adapter:map_schema_to_params(cc_schema.get_default(adapter)))
294314
settings.opts.stream = false
295315

296-
---@type CodeCompanion.Client
316+
---@type CodeCompanion.HTTPClient
297317
local client = http_client.new({ adapter = settings })
298318
client:request(payload, {
299-
---@param _adapter CodeCompanion.Adapter
319+
---@param _adapter CodeCompanion.HTTPAdapter
300320
callback = function(_, data, _adapter)
301321
if data then
302322
local res = _adapter.handlers.chat_output(_adapter, data)

lua/vectorcode/types.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@
130130
--- - `VectorCode.QueryResult[]`: a list of query results.
131131
---@field enabled boolean|(fun(chat: CodeCompanion.Chat, results: VectorCode.QueryResult[]):boolean)|nil
132132
---The adapter used for the summarisation task. When set to `nil`, the adapter from the current chat will be used.
133-
---@field adapter string|CodeCompanion.Adapter|nil
133+
---@field adapter string|CodeCompanion.HTTPAdapter|nil
134134
---The system prompt sent to the summariser model.
135135
---When set to a function, it'll recieve the default system prompt as the only parameter,
136136
---and should return the new (full) system prompt. This allows you to customise or rewrite the system prompt.

0 commit comments

Comments
 (0)