Skip to content

Commit 8510f30

Browse files
authored
fix(functions): do not filter schema enum when entering input (CopilotC-Nvim#1264)
It still need to be filtered when preparing tool use as we cant send json functions to API. Closes CopilotC-Nvim#1263 Signed-off-by: Tomas Slusny <slusnucky@gmail.com>
1 parent 831db05 commit 8510f30

1 file changed

Lines changed: 12 additions & 15 deletions

File tree

lua/CopilotChat/functions.lua

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -114,15 +114,16 @@ function M.match_uri(uri, pattern)
114114
return result
115115
end
116116

117-
---@param tool CopilotChat.config.functions.Function
118-
function M.parse_schema(tool)
119-
local schema = tool.schema
117+
--- Parse function schema and return a JSON schema object
118+
---@param fn CopilotChat.config.functions.Function
119+
function M.parse_schema(fn)
120+
local schema = fn.schema
120121

121122
-- If schema is missing but uri is present, generate a default schema from uri
122-
if not schema and tool.uri then
123+
if not schema and fn.uri then
123124
-- Extract parameter names from the uri pattern, e.g. file://{path}
124125
local param_names = {}
125-
for param in tool.uri:gmatch(URI_PARAM_PATTERN) do
126+
for param in fn.uri:gmatch(URI_PARAM_PATTERN) do
126127
table.insert(param_names, param)
127128
end
128129
if #param_names > 0 then
@@ -138,26 +139,22 @@ function M.parse_schema(tool)
138139
end
139140
end
140141

141-
if schema then
142-
schema = filter_schema(schema, true)
143-
end
144-
145142
return schema
146143
end
147144

148-
--- Prepare the schema for use
149-
---@param tools table<string, CopilotChat.config.functions.Function>
145+
--- Prepare functions for tool use
146+
---@param functions table<string, CopilotChat.config.functions.Function>
150147
---@return table<CopilotChat.client.Tool>
151-
function M.parse_tools(tools)
152-
local tool_names = vim.tbl_keys(tools)
148+
function M.parse_tools(functions)
149+
local tool_names = vim.tbl_keys(functions)
153150
table.sort(tool_names)
154151
return vim.tbl_map(function(name)
155-
local tool = tools[name]
152+
local tool = functions[name]
156153

157154
return {
158155
name = name,
159156
description = tool.description,
160-
schema = M.parse_schema(tool),
157+
schema = filter_schema(M.parse_schema(tool), true),
161158
}
162159
end, tool_names)
163160
end

0 commit comments

Comments
 (0)