|
| 1 | +return function() |
| 2 | + local icons = { aichat = require("modules.utils.icons").get("aichat", true) } |
| 3 | + local secret_key = require("core.settings").chat_api_key |
| 4 | + local chat_lang = require("core.settings").chat_lang |
| 5 | + local models = require("core.settings").chat_models |
| 6 | + local current_model = models[1] |
| 7 | + vim.g.current_chat_model = current_model |
| 8 | + |
| 9 | + require("modules.utils").load_plugin("codecompanion", { |
| 10 | + opts = { |
| 11 | + language = chat_lang, |
| 12 | + }, |
| 13 | + strategies = { |
| 14 | + chat = { |
| 15 | + adapter = "openrouter", |
| 16 | + roles = { |
| 17 | + llm = function(adapter) |
| 18 | + return icons.aichat.Copilot .. "CodeCompanion (" .. adapter.formatted_name .. ")" |
| 19 | + end, |
| 20 | + user = icons.aichat.Me .. "Me", |
| 21 | + }, |
| 22 | + keymaps = { |
| 23 | + submit = { |
| 24 | + modes = { n = "<CR>" }, |
| 25 | + description = "Submit", |
| 26 | + callback = function(chat) |
| 27 | + chat:apply_model(current_model) |
| 28 | + chat:submit() |
| 29 | + end, |
| 30 | + }, |
| 31 | + }, |
| 32 | + }, |
| 33 | + inline = { |
| 34 | + adapter = "openrouter", |
| 35 | + }, |
| 36 | + }, |
| 37 | + adapters = { |
| 38 | + openrouter = function() |
| 39 | + return require("codecompanion.adapters").extend("openai_compatible", { |
| 40 | + env = { |
| 41 | + url = "https://openrouter.ai/api", |
| 42 | + api_key = secret_key, |
| 43 | + chat_url = "/v1/chat/completions", |
| 44 | + }, |
| 45 | + schema = { |
| 46 | + model = { |
| 47 | + default = vim.g.current_chat_model, |
| 48 | + }, |
| 49 | + }, |
| 50 | + }) |
| 51 | + end, |
| 52 | + }, |
| 53 | + display = { |
| 54 | + diff = { |
| 55 | + enabled = true, |
| 56 | + close_chat_at = 240, -- Close an open chat buffer if the total columns of your display are less than... |
| 57 | + layout = "vertical", -- vertical|horizontal split for default provider |
| 58 | + opts = { "internal", "filler", "closeoff", "algorithm:patience", "followwrap", "linematch:120" }, |
| 59 | + provider = "default", -- default|mini_diff |
| 60 | + }, |
| 61 | + chat = { |
| 62 | + window = { |
| 63 | + layout = "vertical", -- float|vertical|horizontal|buffer |
| 64 | + position = "right", -- left|right|top|bottom (nil will default depending on vim.opt.plitright|vim.opt.splitbelow) |
| 65 | + border = "single", |
| 66 | + width = 0.25, |
| 67 | + relative = "editor", |
| 68 | + full_height = true, -- when set to false, vsplit will be used to open the chat buffer vs. botright/topleft vsplit |
| 69 | + }, |
| 70 | + }, |
| 71 | + }, |
| 72 | + extensions = { |
| 73 | + history = { |
| 74 | + enabled = true, |
| 75 | + opts = { |
| 76 | + -- Keymap to open history from chat buffer (default: gh) |
| 77 | + keymap = "gh", |
| 78 | + -- Automatically generate titles for new chats |
| 79 | + auto_generate_title = true, |
| 80 | + ---On exiting and entering neovim, loads the last chat on opening chat |
| 81 | + continue_last_chat = false, |
| 82 | + ---When chat is cleared with `gx` delete the chat from history |
| 83 | + delete_on_clearing_chat = false, |
| 84 | + -- Picker interface ("telescope", "snacks" or "default") |
| 85 | + picker = "telescope", |
| 86 | + ---Enable detailed logging for history extension |
| 87 | + enable_logging = false, |
| 88 | + ---Directory path to save the chats |
| 89 | + dir_to_save = vim.fn.stdpath("data") .. "/codecompanion-history", |
| 90 | + -- Save all chats by default |
| 91 | + auto_save = true, |
| 92 | + -- Keymap to save the current chat manually |
| 93 | + save_chat_keymap = "sc", |
| 94 | + -- Number of days after which chats are automatically deleted (0 to disable) |
| 95 | + expiration_days = 0, |
| 96 | + }, |
| 97 | + }, |
| 98 | + }, |
| 99 | + }) |
| 100 | +end |
0 commit comments