@@ -164,7 +164,7 @@ local result_tracker = {}
164164--- @param chat CodeCompanion.Chat
165165--- @return VectorCode.QueryResult[]
166166local filter_results = function (results , chat )
167- local existing_refs = chat .context_items or chat . refs or {}
167+ local existing_refs = chat .context_items or {}
168168
169169 existing_refs = vim
170170 .iter (existing_refs )
@@ -316,7 +316,7 @@ When summarising the code, pay extra attention on information related to the que
316316end
317317
318318--- @param opts VectorCode.CodeCompanion.QueryToolOpts ?
319- --- @return CodeCompanion.Agent .Tool
319+ --- @return CodeCompanion.Tools .Tool
320320return check_cli_wrap (function (opts )
321321 opts = get_query_tool_opts (opts )
322322 assert (
@@ -337,10 +337,10 @@ return check_cli_wrap(function(opts)
337337 return {
338338 name = tool_name ,
339339 cmds = {
340- --- @param agent CodeCompanion.Agent
340+ --- @param tools CodeCompanion.Tools
341341 --- @param action QueryToolArgs
342342 --- @return nil |{ status : string , data : string }
343- function (agent , action , _ , cb )
343+ function (tools , action , _ , cb )
344344 logger .info (
345345 " CodeCompanion query tool called with the following arguments:\n " ,
346346 action
@@ -387,12 +387,14 @@ return check_cli_wrap(function(opts)
387387 end
388388 end
389389
390- -- TODO: remove the `chat.refs` compatibility code when the upstream PR is released.
391- local context_items = agent .chat .context_items or agent .chat .refs
392- if opts .no_duplicate and context_items ~= nil and action .deduplicate then
390+ if
391+ opts .no_duplicate
392+ and tools .chat .context_items ~= nil
393+ and action .deduplicate
394+ then
393395 -- exclude files that has been added to the context
394396 local existing_files = { " --exclude" }
395- for _ , ref in pairs (context_items ) do
397+ for _ , ref in pairs (tools . chat . context_items ) do
396398 if ref .source == cc_common .tool_result_source then
397399 table.insert (existing_files , ref .id )
398400 elseif type (ref .path ) == " string" then
@@ -421,7 +423,7 @@ return check_cli_wrap(function(opts)
421423 if vim .islist (result ) and # result > 0 and result [1 ].path ~= nil then --- @cast result VectorCode.QueryResult[]
422424 local summary_opts = vim .deepcopy (opts .summarise ) or {}
423425 if type (summary_opts .enabled ) == " function" then
424- summary_opts .enabled = summary_opts .enabled (agent .chat , result ) --[[ @as boolean]]
426+ summary_opts .enabled = summary_opts .enabled (tools .chat , result ) --[[ @as boolean]]
425427 end
426428
427429 if
@@ -431,7 +433,7 @@ return check_cli_wrap(function(opts)
431433 then
432434 -- NOTE: deduplication in summary mode prevents the model from requesting
433435 -- the same content without summarysation.
434- result = filter_results (result , agent .chat )
436+ result = filter_results (result , tools .chat )
435437 end
436438
437439 local max_result = # result
@@ -457,7 +459,7 @@ return check_cli_wrap(function(opts)
457459 data = error ,
458460 })
459461 end
460- end , agent .chat .bufnr )
462+ end , tools .chat .bufnr )
461463 end ,
462464 },
463465 schema = {
@@ -530,10 +532,10 @@ DO NOT MODIFY UNLESS INSTRUCTED BY THE USER, OR A PREVIOUS QUERY RETURNED NO RES
530532 },
531533 },
532534 output = {
533- --- @param agent CodeCompanion.Agent
535+ --- @param tools CodeCompanion.Tools
534536 --- @param cmd QueryToolArgs
535537 --- @param stderr table | string
536- error = function (self , agent , cmd , stderr )
538+ error = function (self , tools , cmd , stderr )
537539 logger .error (
538540 (" CodeCompanion tool with command %s thrown with the following error: %s" ):format (
539541 vim .inspect (cmd ),
@@ -543,21 +545,21 @@ DO NOT MODIFY UNLESS INSTRUCTED BY THE USER, OR A PREVIOUS QUERY RETURNED NO RES
543545 stderr = cc_common .flatten_table_to_string (stderr )
544546 if string.find (stderr , " InvalidCollectionException" ) then
545547 if cmd .project_root then
546- agent .chat :add_tool_output (
548+ tools .chat :add_tool_output (
547549 self ,
548550 string.format (
549551 " `%s` hasn't been vectorised. Please use the `vectorcode_vectorise` tool or vectorise it from the CLI." ,
550552 cmd .project_root
551553 )
552554 )
553555 else
554- agent .chat :add_tool_output (
556+ tools .chat :add_tool_output (
555557 self ,
556558 " Failed to query from the requested project. Please verify the available projects via the `vectorcode_ls` tool or run it from the CLI."
557559 )
558560 end
559561 else
560- agent .chat :add_tool_output (
562+ tools .chat :add_tool_output (
561563 self ,
562564 string.format (
563565 " **VectorCode `query` Tool**: Failed with error:\n ```\n %s\n ```" ,
@@ -566,17 +568,17 @@ DO NOT MODIFY UNLESS INSTRUCTED BY THE USER, OR A PREVIOUS QUERY RETURNED NO RES
566568 )
567569 end
568570 end ,
569- --- @param agent CodeCompanion.Agent
571+ --- @param tools CodeCompanion.Tools
570572 --- @param cmd QueryToolArgs
571573 --- @param stdout VectorCode.CodeCompanion.QueryToolResult[]
572- success = function (self , agent , cmd , stdout )
574+ success = function (self , tools , cmd , stdout )
573575 stdout = stdout [1 ]
574576 logger .info (
575577 (" CodeCompanion tool with command %s finished." ):format (vim .inspect (cmd ))
576578 )
577579 if vim .tbl_isempty (stdout .raw_results ) then
578580 logger .info (" CodeCompanion query tool recieved empty result." )
579- return agent .chat :add_tool_output (
581+ return tools .chat :add_tool_output (
580582 self ,
581583 string.format (
582584 " `%s` tool returned empty result. Please retry without deduplication." ,
@@ -585,7 +587,7 @@ DO NOT MODIFY UNLESS INSTRUCTED BY THE USER, OR A PREVIOUS QUERY RETURNED NO RES
585587 " **VectorCode `query` Tool**: Retrieved 0 result. Retrying..."
586588 )
587589 end
588- agent .chat :add_tool_output (
590+ tools .chat :add_tool_output (
589591 self ,
590592 stdout .summary
591593 or table.concat (vim
@@ -597,10 +599,9 @@ DO NOT MODIFY UNLESS INSTRUCTED BY THE USER, OR A PREVIOUS QUERY RETURNED NO RES
597599 string.format (" **VectorCode Tool**: Retrieved %d %s(s)" , stdout .count , mode )
598600 )
599601 if not opts .chunk_mode then
600- local context = agent .chat .context or agent .chat .references
601602 for _ , result in pairs (stdout .raw_results ) do
602603 -- skip referencing because there will be multiple chunks with the same path (id).
603- context :add ({
604+ tools . chat . context :add ({
604605 source = cc_common .tool_result_source ,
605606 id = result .path ,
606607 path = result .path ,
0 commit comments