summaryrefslogtreecommitdiff
path: root/lua
diff options
context:
space:
mode:
author0xr3ngar <bogdan.nikolov4@outlook.com>2026-02-09 08:18:09 +0100
committer0xr3ngar <bogdan.nikolov4@outlook.com>2026-02-09 08:18:09 +0100
commit3d76c50c68780a99603835deb520b6c63102cd0d (patch)
tree445346fed912216b141bbb8078ca69d07d82f9a3 /lua
parent0fb3b8b2d032289ea7088a37161e1c50bdfccfa9 (diff)
downloada4-3d76c50c68780a99603835deb520b6c63102cd0d.tar.xz
a4-3d76c50c68780a99603835deb520b6c63102cd0d.zip
feat: add fetch_models to all providers
Diffstat (limited to 'lua')
-rw-r--r--lua/99/providers.lua56
1 files changed, 56 insertions, 0 deletions
diff --git a/lua/99/providers.lua b/lua/99/providers.lua
index ab56738..9e55f88 100644
--- a/lua/99/providers.lua
+++ b/lua/99/providers.lua
@@ -29,6 +29,11 @@ end
--- @field _get_provider_name fun(self: _99.Providers.BaseProvider): string
local BaseProvider = {}
+--- @param callback fun(models: string[]|nil, err: string|nil): nil
+function BaseProvider.fetch_models(callback)
+ callback(nil, "This provider does not support listing models")
+end
+
--- @param request _99.Request
function BaseProvider:_retrieve_response(request)
local logger = request.logger:set_area(self:_get_provider_name())
@@ -154,6 +159,19 @@ function OpenCodeProvider._get_default_model()
return "opencode/claude-sonnet-4-5"
end
+function OpenCodeProvider.fetch_models(callback)
+ vim.system({ "opencode", "models" }, { text = true }, function(obj)
+ vim.schedule(function()
+ if obj.code ~= 0 then
+ callback(nil, "Failed to fetch models from opencode")
+ return
+ end
+ local models = vim.split(obj.stdout, "\n", { trimempty = true })
+ callback(models, nil)
+ end)
+ end)
+end
+
--- @class ClaudeCodeProvider : _99.Providers.BaseProvider
local ClaudeCodeProvider = setmetatable({}, { __index = BaseProvider })
@@ -181,6 +199,23 @@ function ClaudeCodeProvider._get_default_model()
return "claude-sonnet-4-5"
end
+-- TODO: the claude CLI has no way to list available models.
+-- We could use the Anthropic API (https://docs.anthropic.com/en/api/models)
+-- but that requires the user to have an ANTHROPIC_API_KEY set which isn't ideal.
+-- Until Anthropic adds a CLI command for this, we have to hardcode the list here.
+function ClaudeCodeProvider.fetch_models(callback)
+ callback({
+ "claude-opus-4-6",
+ "claude-sonnet-4-5",
+ "claude-haiku-4-5",
+ "claude-opus-4-5",
+ "claude-opus-4-1",
+ "claude-sonnet-4-0",
+ "claude-opus-4-0",
+ "claude-3-7-sonnet-latest",
+ }, nil)
+end
+
--- @class CursorAgentProvider : _99.Providers.BaseProvider
local CursorAgentProvider = setmetatable({}, { __index = BaseProvider })
@@ -201,6 +236,27 @@ function CursorAgentProvider._get_default_model()
return "sonnet-4.5"
end
+function CursorAgentProvider.fetch_models(callback)
+ vim.system({ "cursor-agent", "models" }, { text = true }, function(obj)
+ vim.schedule(function()
+ if obj.code ~= 0 then
+ callback(nil, "Failed to fetch models from cursor-agent")
+ return
+ end
+ local models = {}
+ for _, line in ipairs(vim.split(obj.stdout, "\n", { trimempty = true })) do
+ -- `cursor-agent models` outputs lines like "model-id - description",
+ -- so we grab everything before the first " - " separator
+ local id = line:match("^(%S+)%s+%-")
+ if id then
+ table.insert(models, id)
+ end
+ end
+ callback(models, nil)
+ end)
+ end)
+end
+
--- @class KiroProvider : _99.Providers.BaseProvider
local KiroProvider = setmetatable({}, { __index = BaseProvider })