- local forge = require("forge")
- function PLUGIN:BackendSearchTools(ctx)
- local base_url = forge.base_url(nil)
- local repos = forge.list_repos(base_url)
- local query = string.lower(tostring((ctx and ctx.query) or ""))
- local tools = {}
- for _, repo in ipairs(repos) do
- if type(repo) == "table" and type(repo.name) == "string" and repo.name ~= "" then
- if type(repo.latest_release) == "string" and repo.latest_release ~= "" then
- local name = repo.name
- local desc = type(repo.description) == "string" and repo.description or ""
- local match = (query == "")
- or (string.lower(name):find(query, 1, true) ~= nil)
- or (string.lower(desc):find(query, 1, true) ~= nil)
- if not match and type(repo.topics) == "table" then
- for _, topic in ipairs(repo.topics) do
- if type(topic) == "string" and string.lower(topic):find(query, 1, true) ~= nil then
- match = true
- break
- end
- end
- end
- if match then
- table.insert(tools, {
- name = name,
- description = desc,
- })
- end
- end
- end
- end
- return { tools = tools }
- end