Skip to content

Commit 07bcd20

Browse files
committed
fix: correct agent handling in chat client
Improves agent handling in the chat client by: - Fixing agent config extension when agent is not provided - Correcting URL generation for agent endpoints - Fixing agent list mapping to use proper agent IDs - Improving type annotations for provider options These changes make the agent-related functionality more robust and type-safe throughout the codebase.
1 parent b53a028 commit 07bcd20

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

lua/CopilotChat/client.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -394,8 +394,8 @@ function Client:ask(prompt, opts)
394394
end
395395

396396
local agents = self:fetch_agents()
397-
local agent_config = agent and agents[agent] or {}
398-
if not agent_config then
397+
local agent_config = agent and agents[agent]
398+
if agent and not agent_config then
399399
error('Agent not found: ' .. agent)
400400
end
401401

@@ -412,7 +412,7 @@ function Client:ask(prompt, opts)
412412
model = vim.tbl_extend('force', model_config, {
413413
id = opts.model:gsub(':' .. provider_name .. '$', ''),
414414
}),
415-
agent = vim.tbl_extend('force', agent_config, {
415+
agent = agent_config and vim.tbl_extend('force', agent_config, {
416416
id = opts.agent and opts.agent:gsub(':' .. provider_name .. '$', ''),
417417
}),
418418
temperature = temperature,
@@ -612,7 +612,7 @@ function Client:ask(prompt, opts)
612612
args.stream = stream_func
613613
end
614614

615-
local response, err = utils.curl_post(provider.get_url(opts), args)
615+
local response, err = utils.curl_post(provider.get_url(options), args)
616616

617617
if self.current_job ~= job_id then
618618
return

lua/CopilotChat/config/providers.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ local utils = require('CopilotChat.utils')
2020

2121
---@class CopilotChat.Provider.options
2222
---@field model CopilotChat.Provider.model
23-
---@field agent CopilotChat.Provider.agent
23+
---@field agent CopilotChat.Provider.agent?
2424
---@field temperature number?
2525

2626
---@class CopilotChat.Provider.input
@@ -46,7 +46,7 @@ local utils = require('CopilotChat.utils')
4646
---@field embed nil|string|fun(inputs:table<string>, headers:table):table<CopilotChat.Provider.embed>
4747
---@field prepare_input nil|fun(inputs:table<CopilotChat.Provider.input>, opts:CopilotChat.Provider.options):table
4848
---@field prepare_output nil|fun(output:table, opts:CopilotChat.Provider.options):CopilotChat.Provider.output
49-
---@field get_url nil|fun(opts:table):string
49+
---@field get_url nil|fun(opts:CopilotChat.Provider.options):string
5050

5151
local EDITOR_VERSION = 'Neovim/'
5252
.. vim.version().major
@@ -270,7 +270,7 @@ M.copilot = {
270270

271271
get_url = function(opts)
272272
if opts.agent then
273-
return 'https://api.githubcopilot.com/agents/' .. opts.agent .. '?chat'
273+
return 'https://api.githubcopilot.com/agents/' .. opts.agent.id .. '?chat'
274274
end
275275

276276
return 'https://api.githubcopilot.com/chat/completions'

lua/CopilotChat/init.lua

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,10 @@ end
277277
---@param prompt string
278278
---@param config CopilotChat.config.shared
279279
function M.resolve_agent(prompt, config)
280-
local agents = vim.tbl_keys(client:list_agents())
280+
local agents = vim.tbl_map(function(agent)
281+
return agent.id
282+
end, client:list_agents())
283+
281284
local selected_agent = config.agent
282285
prompt = prompt:gsub('@' .. WORD, function(match)
283286
if vim.tbl_contains(agents, match) then

0 commit comments

Comments
 (0)