2024-08-17 15:14:30 +08:00
|
|
|
---NOTE: user will be merged with defaults and
|
|
|
|
---we add a default var_accessor for this table to config values.
|
2024-08-17 14:14:02 -04:00
|
|
|
---
|
2024-08-17 15:14:30 +08:00
|
|
|
---@class avante.CoreConfig: avante.Config
|
2024-08-15 17:45:46 +08:00
|
|
|
local M = {}
|
|
|
|
|
2024-08-17 15:14:30 +08:00
|
|
|
---@class avante.Config
|
|
|
|
M.defaults = {
|
2024-08-19 05:40:57 -04:00
|
|
|
debug = false,
|
2024-08-23 00:21:30 -04:00
|
|
|
---Currently, default supported providers include "claude", "openai", "azure", "gemini"
|
2024-08-19 05:40:57 -04:00
|
|
|
---For custom provider, see README.md
|
2024-08-23 00:21:30 -04:00
|
|
|
---@alias Provider "openai" | "claude" | "azure" | "copilot" | "gemini" | string
|
2024-08-19 05:40:57 -04:00
|
|
|
provider = "claude",
|
2024-08-19 08:35:36 -04:00
|
|
|
---@type AvanteSupportedProvider
|
2024-08-15 17:45:46 +08:00
|
|
|
openai = {
|
|
|
|
endpoint = "https://api.openai.com",
|
|
|
|
model = "gpt-4o",
|
|
|
|
temperature = 0,
|
|
|
|
max_tokens = 4096,
|
2024-08-19 08:35:36 -04:00
|
|
|
["local"] = false,
|
2024-08-15 17:45:46 +08:00
|
|
|
},
|
2024-08-20 14:24:33 -04:00
|
|
|
---@type AvanteCopilotProvider
|
|
|
|
copilot = {
|
|
|
|
endpoint = "https://api.githubcopilot.com",
|
|
|
|
model = "gpt-4o-2024-05-13",
|
|
|
|
proxy = nil, -- [protocol://]host[:port] Use this proxy
|
|
|
|
allow_insecure = false, -- Allow insecure server connections
|
|
|
|
timeout = 30000, -- Timeout in milliseconds
|
|
|
|
temperature = 0,
|
2024-08-23 00:21:30 -04:00
|
|
|
max_tokens = 4096,
|
2024-08-20 14:24:33 -04:00
|
|
|
},
|
2024-08-19 08:35:36 -04:00
|
|
|
---@type AvanteAzureProvider
|
2024-08-15 17:45:46 +08:00
|
|
|
azure = {
|
|
|
|
endpoint = "", -- example: "https://<your-resource-name>.openai.azure.com"
|
|
|
|
deployment = "", -- Azure deployment name (e.g., "gpt-4o", "my-gpt-4o-deployment")
|
|
|
|
api_version = "2024-06-01",
|
|
|
|
temperature = 0,
|
|
|
|
max_tokens = 4096,
|
2024-08-19 08:35:36 -04:00
|
|
|
["local"] = false,
|
2024-08-15 17:45:46 +08:00
|
|
|
},
|
2024-08-19 08:35:36 -04:00
|
|
|
---@type AvanteSupportedProvider
|
2024-08-15 17:45:46 +08:00
|
|
|
claude = {
|
|
|
|
endpoint = "https://api.anthropic.com",
|
|
|
|
model = "claude-3-5-sonnet-20240620",
|
|
|
|
temperature = 0,
|
|
|
|
max_tokens = 4096,
|
2024-08-23 09:36:40 -04:00
|
|
|
["local"] = false,
|
2024-08-15 17:45:46 +08:00
|
|
|
},
|
2024-08-21 17:52:25 +01:00
|
|
|
---@type AvanteGeminiProvider
|
|
|
|
gemini = {
|
2024-08-22 01:48:40 -04:00
|
|
|
endpoint = "https://generativelanguage.googleapis.com/v1beta/models",
|
2024-08-21 17:52:25 +01:00
|
|
|
model = "gemini-1.5-pro",
|
2024-08-23 09:36:40 -04:00
|
|
|
temperature = 0,
|
|
|
|
max_tokens = 4096,
|
|
|
|
["local"] = false,
|
|
|
|
},
|
|
|
|
---@type AvanteGeminiProvider
|
|
|
|
cohere = {
|
|
|
|
endpoint = "https://api.cohere.com",
|
|
|
|
model = "command-r-plus",
|
|
|
|
temperature = 0,
|
|
|
|
max_tokens = 3072,
|
2024-08-22 01:48:40 -04:00
|
|
|
["local"] = false,
|
2024-08-21 17:52:25 +01:00
|
|
|
},
|
2024-08-19 05:40:57 -04:00
|
|
|
---To add support for custom provider, follow the format below
|
|
|
|
---See https://github.com/yetone/avante.nvim/README.md#custom-providers for more details
|
2024-08-19 08:35:36 -04:00
|
|
|
---@type {[string]: AvanteProvider}
|
2024-08-18 22:20:29 -04:00
|
|
|
vendors = {},
|
2024-08-19 05:40:57 -04:00
|
|
|
---Specify the behaviour of avante.nvim
|
|
|
|
---1. auto_apply_diff_after_generation: Whether to automatically apply diff after LLM response.
|
|
|
|
--- This would simulate similar behaviour to cursor. Default to false.
|
2024-08-17 16:31:24 -04:00
|
|
|
behaviour = {
|
2024-08-19 05:40:57 -04:00
|
|
|
auto_apply_diff_after_generation = false,
|
2024-08-17 16:31:24 -04:00
|
|
|
},
|
2024-08-15 17:45:46 +08:00
|
|
|
highlights = {
|
2024-08-17 14:14:02 -04:00
|
|
|
---@type AvanteConflictHighlights
|
2024-08-15 17:45:46 +08:00
|
|
|
diff = {
|
2024-08-19 05:40:57 -04:00
|
|
|
current = "DiffText",
|
|
|
|
incoming = "DiffAdd",
|
2024-08-15 17:45:46 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
mappings = {
|
2024-08-17 22:29:05 +08:00
|
|
|
ask = "<leader>aa",
|
|
|
|
edit = "<leader>ae",
|
2024-08-17 13:41:34 -04:00
|
|
|
refresh = "<leader>ar",
|
2024-08-17 14:14:02 -04:00
|
|
|
--- @class AvanteConflictMappings
|
2024-08-15 17:45:46 +08:00
|
|
|
diff = {
|
|
|
|
ours = "co",
|
|
|
|
theirs = "ct",
|
|
|
|
none = "c0",
|
|
|
|
both = "cb",
|
|
|
|
next = "]x",
|
|
|
|
prev = "[x",
|
|
|
|
},
|
2024-08-17 10:39:59 -04:00
|
|
|
jump = {
|
|
|
|
next = "]]",
|
|
|
|
prev = "[[",
|
|
|
|
},
|
2024-08-15 17:45:46 +08:00
|
|
|
},
|
2024-08-17 15:14:30 +08:00
|
|
|
windows = {
|
2024-08-22 01:48:40 -04:00
|
|
|
wrap = true, -- similar to vim.o.wrap
|
2024-08-17 15:14:30 +08:00
|
|
|
width = 30, -- default % based on available width
|
2024-08-21 23:31:11 +08:00
|
|
|
sidebar_header = {
|
2024-08-21 11:12:10 -04:00
|
|
|
align = "center", -- left, center, right for title
|
2024-08-21 23:31:11 +08:00
|
|
|
rounded = true,
|
2024-08-21 11:12:10 -04:00
|
|
|
},
|
2024-08-22 01:48:40 -04:00
|
|
|
prompt = {
|
|
|
|
prefix = "> ", -- prefix for the prompt
|
|
|
|
},
|
2024-08-17 15:14:30 +08:00
|
|
|
},
|
2024-08-17 14:14:02 -04:00
|
|
|
--- @class AvanteConflictUserConfig
|
|
|
|
diff = {
|
|
|
|
debug = false,
|
|
|
|
autojump = true,
|
|
|
|
---@type string | fun(): any
|
|
|
|
list_opener = "copen",
|
|
|
|
},
|
2024-08-19 12:40:33 +10:00
|
|
|
--- @class AvanteHintsConfig
|
|
|
|
hints = {
|
2024-08-19 05:11:38 -04:00
|
|
|
enabled = true,
|
2024-08-19 12:40:33 +10:00
|
|
|
},
|
2024-08-15 17:45:46 +08:00
|
|
|
}
|
|
|
|
|
2024-08-17 15:14:30 +08:00
|
|
|
---@type avante.Config
|
|
|
|
M.options = {}
|
|
|
|
|
2024-08-17 14:14:02 -04:00
|
|
|
---@class avante.ConflictConfig: AvanteConflictUserConfig
|
|
|
|
---@field mappings AvanteConflictMappings
|
|
|
|
---@field highlights AvanteConflictHighlights
|
|
|
|
M.diff = {}
|
|
|
|
|
2024-08-19 12:40:33 +10:00
|
|
|
---@class AvanteHintsConfig
|
|
|
|
---@field enabled boolean
|
|
|
|
M.hints = {}
|
|
|
|
|
2024-08-17 15:14:30 +08:00
|
|
|
---@param opts? avante.Config
|
|
|
|
function M.setup(opts)
|
|
|
|
M.options = vim.tbl_deep_extend("force", M.defaults, opts or {})
|
2024-08-17 14:14:02 -04:00
|
|
|
|
|
|
|
M.diff = vim.tbl_deep_extend(
|
|
|
|
"force",
|
|
|
|
{},
|
|
|
|
M.options.diff,
|
|
|
|
{ mappings = M.options.mappings.diff, highlights = M.options.highlights.diff }
|
|
|
|
)
|
2024-08-19 18:26:25 -04:00
|
|
|
M.hints = vim.tbl_deep_extend("force", {}, M.options.hints)
|
2024-08-22 01:48:40 -04:00
|
|
|
|
|
|
|
if next(M.options.vendors) ~= nil then
|
|
|
|
for k, v in pairs(M.options.vendors) do
|
|
|
|
M.options.vendors[k] = type(v) == "function" and v() or v
|
|
|
|
end
|
|
|
|
end
|
2024-08-17 15:14:30 +08:00
|
|
|
end
|
|
|
|
|
2024-08-18 22:20:29 -04:00
|
|
|
---@param opts? avante.Config
|
|
|
|
function M.override(opts)
|
2024-08-22 01:48:40 -04:00
|
|
|
opts = opts or {}
|
|
|
|
M.options = vim.tbl_deep_extend("force", M.options, opts)
|
|
|
|
M.diff = vim.tbl_deep_extend(
|
|
|
|
"force",
|
|
|
|
{},
|
|
|
|
M.options.diff,
|
|
|
|
{ mappings = M.options.mappings.diff, highlights = M.options.highlights.diff }
|
|
|
|
)
|
|
|
|
M.hints = vim.tbl_deep_extend("force", {}, M.options.hints)
|
2024-08-18 22:20:29 -04:00
|
|
|
end
|
|
|
|
|
2024-08-17 15:14:30 +08:00
|
|
|
M = setmetatable(M, {
|
|
|
|
__index = function(_, k)
|
|
|
|
if M.options[k] then
|
|
|
|
return M.options[k]
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
|
|
|
function M.get_window_width()
|
|
|
|
return math.ceil(vim.o.columns * (M.windows.width / 100))
|
2024-08-15 17:45:46 +08:00
|
|
|
end
|
|
|
|
|
2024-08-22 01:48:40 -04:00
|
|
|
---@param provider Provider
|
|
|
|
---@return boolean
|
|
|
|
M.has_provider = function(provider)
|
|
|
|
return M.options[provider] ~= nil or M.vendors[provider] ~= nil
|
|
|
|
end
|
|
|
|
|
|
|
|
---get supported providers
|
|
|
|
---@param provider Provider
|
|
|
|
---@return AvanteProvider | fun(): AvanteProvider
|
|
|
|
M.get_provider = function(provider)
|
|
|
|
if M.options[provider] ~= nil then
|
|
|
|
return vim.deepcopy(M.options[provider], true)
|
|
|
|
elseif M.vendors[provider] ~= nil then
|
|
|
|
return vim.deepcopy(M.vendors[provider], true)
|
|
|
|
else
|
|
|
|
error("Failed to find provider: " .. provider, 2)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-08-22 23:52:49 -04:00
|
|
|
M.BASE_PROVIDER_KEYS =
|
|
|
|
{ "endpoint", "model", "local", "deployment", "api_version", "proxy", "allow_insecure", "api_key_name" }
|
2024-08-22 01:48:40 -04:00
|
|
|
|
2024-08-21 21:28:17 +08:00
|
|
|
---@return {width: integer, height: integer}
|
|
|
|
function M.get_sidebar_layout_options()
|
2024-08-17 15:14:30 +08:00
|
|
|
local width = M.get_window_width()
|
|
|
|
local height = vim.o.lines
|
2024-08-21 21:28:17 +08:00
|
|
|
return { width = width, height = height }
|
2024-08-15 17:45:46 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
return M
|