Skip to content

Commit d21b6f4

Browse files
committed
feat(nvim)!: switch to new native tool calling schema for codecompanion
1 parent 67c0270 commit d21b6f4

File tree

1 file changed

+68
-71
lines changed

1 file changed

+68
-71
lines changed

lua/vectorcode/integrations/codecompanion.lua

Lines changed: 68 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,16 @@ local make_tool = check_cli_wrap(function(opts)
7878
type(cb) == "function",
7979
"Please upgrade CodeCompanion.nvim to at least 13.5.0"
8080
)
81-
assert(vim.list_contains({ "ls", "query" }, action.command))
81+
if not (vim.list_contains({ "ls", "query" }, action.command)) then
82+
if action.options.query ~= nil then
83+
action.command = "query"
84+
else
85+
return {
86+
status = "error",
87+
data = "Need to specify the command (`ls` or `query`).",
88+
}
89+
end
90+
end
8291
if opts.auto_submit[action.command] then
8392
vim.schedule(function()
8493
vim.api.nvim_input("<Esc>")
@@ -97,14 +106,14 @@ local make_tool = check_cli_wrap(function(opts)
97106
and vim.uv.fs_stat(action.options.project_root).type == "directory"
98107
then
99108
vim.list_extend(args, { "--project_root", action.options.project_root })
100-
vim.list_extend(args, { "--absolute" })
101109
else
102110
agent.chat:add_message(
103111
{ role = "user", content = "INVALID PROJECT ROOT! USE THE LS COMMAND!" },
104112
{ visible = false }
105113
)
106114
end
107115
end
116+
vim.list_extend(args, { "--absolute" })
108117
job_runner.run_async(args, function(result, error)
109118
vim.schedule(function()
110119
if opts.auto_submit[action.command] then
@@ -146,56 +155,47 @@ local make_tool = check_cli_wrap(function(opts)
146155
end,
147156
},
148157
schema = {
149-
{
150-
tool = {
151-
_attr = { name = "vectorcode" },
152-
action = {
153-
command = "query",
154-
options = {
155-
query = { "keyword1", "keyword2" },
156-
count = 5,
158+
type = "function",
159+
["function"] = {
160+
name = "vectorcode",
161+
description = "Retrieves code documents using semantic search or lists indexed projects",
162+
parameters = {
163+
type = "object",
164+
properties = {
165+
command = {
166+
type = "string",
167+
enum = { "query", "ls" },
168+
description = "Action to perform: 'query' for semantic search or 'ls' to list projects",
157169
},
158-
},
159-
},
160-
},
161-
{
162-
tool = {
163-
_attr = { name = "vectorcode" },
164-
action = {
165-
command = "query",
166170
options = {
167-
query = { "keyword1" },
168-
count = 2,
171+
type = "object",
172+
properties = {
173+
query = {
174+
type = "array",
175+
items = { type = "string" },
176+
description = "Search keywords (required for 'query' command). Orthogornal keywords should be in distinct strings.",
177+
},
178+
count = {
179+
type = "integer",
180+
description = "Number of documents to retrieve, must be positive",
181+
},
182+
project_root = {
183+
type = "string",
184+
description = "Project path to search within (must be from 'ls' results)",
185+
},
186+
},
187+
required = { "query" },
188+
additionalProperties = false,
169189
},
170190
},
191+
required = { "command" },
192+
additionalProperties = false,
171193
},
172-
},
173-
{
174-
tool = {
175-
_attr = { name = "vectorcode" },
176-
action = {
177-
command = "query",
178-
options = {
179-
query = { "keyword1" },
180-
count = 3,
181-
project_root = "path/to/other/project",
182-
},
183-
},
184-
},
185-
},
186-
{
187-
tool = {
188-
_attr = { name = "vectorcode" },
189-
action = {
190-
command = "ls",
191-
},
192-
},
194+
strict = true,
193195
},
194196
},
195-
system_prompt = function(schema, xml2lua)
197+
system_prompt = function()
196198
local guidelines = {
197-
" - Ensure XML is **valid and follows the schema**",
198-
" - Make sure the tools xml block is **surrounded by ```xml**",
199199
" - The path of a retrieved file will be wrapped in `<path>` and `</path>` tags. Its content will be right after the `</path>` tag, wrapped by `<content>` and `</content>` tags",
200200
" - If you used the tool, tell users that they may need to wait for the results and there will be a virtual text indicator showing the tool is still running",
201201
" - Include one single command call for VectorCode each time. You may include multiple keywords in the command",
@@ -242,40 +242,37 @@ local make_tool = check_cli_wrap(function(opts)
242242
243243
1. **Purpose**: This gives you the ability to access the repository to find information that you may need to assist the user.
244244
245-
2. **Usage**: Return an XML markdown code block that retrieves relevant documents corresponding to the generated query.
246-
247-
3. **Key Points**:
245+
2. **Key Points**:
248246
%s
249247
250-
4. **Actions**:
251-
252-
a) **Query for 5 documents using 2 keywords: `keyword1` and `keyword2`**:
253-
254-
```xml
255-
%s
248+
3. Example Tool Call
249+
**Querying a project and retrieve the 10 most relevant files with keywords "keyword1" and "keyword2"**
256250
```
257-
258-
b) **Query for 2 documents using one keyword: `keyword1`**:
259-
260-
```xml
261-
%s
251+
{
252+
"_attr": "vectorcode",
253+
{
254+
"action": "query",
255+
"options": {
256+
"query": ["keyword1", "keyword2"],
257+
"count": 10,
258+
"project_root": "/path/to/project",
259+
}
260+
}
261+
}
262262
```
263-
c) **Query for 3 documents using one keyword: `keyword1` in a different project located at `path/to/other/project` (relative to current working directory)**:
264-
```xml
265-
%s
263+
264+
**Listing available projects**
266265
```
267-
d) **Get all indexed project**
268-
```xml
269-
%s
266+
{
267+
"_attr": "vectorcode",
268+
{
269+
"action": "ls"
270+
}
271+
}
270272
```
271273
272-
Remember:
273-
- Minimize explanations unless prompted. Focus on generating correct XML.]],
274-
table.concat(guidelines, "\n"),
275-
xml2lua.toXml({ tools = { schema[1] } }),
276-
xml2lua.toXml({ tools = { schema[2] } }),
277-
xml2lua.toXml({ tools = { schema[3] } }),
278-
xml2lua.toXml({ tools = { schema[4] } })
274+
]],
275+
table.concat(guidelines, "\n")
279276
)
280277
end,
281278
output = {

0 commit comments

Comments
 (0)