Skip to content

[BUG] Error in tool_transformers.lua when use vectorise ls in codecomanion.nvim #251

@leosh1d

Description

@leosh1d

Hello!
I'm using VectorCode together with codecompanion.nvim and Anthropic API integration.
When I try to use the vectorcode_ls tool (and other VectorCode tools) as a CodeCompanion tool, I encounter the following error:

E5108: Error executing lua: ...anion.nvim/lua/codecompanion/utils/tool_transformers.lua:14: attempt to index field 'parameters' (a nil value)
stack traceback:
	...anion.nvim/lua/codecompanion/utils/tool_transformers.lua:14: in function 'to_anthropic'
	...ecompanion.nvim/lua/codecompanion/adapters/anthropic.lua:319: in function 'form_tools'
	.../nvim/lazy/codecompanion.nvim/lua/codecompanion/http.lua:96: in function 'request'
	...ompanion.nvim/lua/codecompanion/strategies/chat/init.lua:935: in function 'submit'
	/Users/leosh1d/.config/nvim/lua/plugins/codecompanion.lua:94: in function 'rhs'
	...y/codecompanion.nvim/lua/codecompanion/utils/keymaps.lua:81: in function 
<...y/codecompanion.nvim/lua/codecompanion/utils/keymaps.lua:78>

This happens when a tool schema does not include the parameters field inside the "function" object.
Currently, the to_anthropic function in tool_transformers.lua assumes that parameters always exists, and does not handle the case when it is missing.

Example problematic code:

M.to_anthropic = function(schema)
  local function_def = schema["function"]
  return {
    name = function_def.name,
    description = function_def.description,
    input_schema = {
      type = function_def.parameters.type,         -- error if parameters is nil
      properties = function_def.parameters.properties,
      required = function_def.parameters.required,
    },
  }
end

Suggestion:
Please make tool_transformers.lua more robust by adding a check for the existence of the parameters field, and providing a default value if it is missing.
For example:

local parameters = function_def.parameters or {
  type = "object",
}

This will prevent runtime errors when integrating with tools that do not strictly follow the OpenAI/Anthropic tool schema, and will make the integration more user-friendly.

Thank you!

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions