// bazarr's tools — its own code (novox/hq ADR 0039), importing bazarr's client. They return // structured data; the mesh serves them through the sdk's tool harness. import { registerModuleTools, type ToolDefinition } from "@novox/mesh-sdk/tools"; import { BazarrClient } from "../client.js"; export function getBazarrTools(bazarr: BazarrClient): ToolDefinition[] { return [ { name: "bazarr_wanted", description: "Episodes and movies still missing subtitles, with the languages each still needs.", input: { limit: { type: "number", description: "max items per kind (default 50)" } }, run: async (args) => { const wanted = await bazarr.getWanted(args.limit ? Number(args.limit) : 50); return { count: wanted.length, wanted }; }, }, { name: "bazarr_search_subtitles", description: "Manually search subtitle providers for one wanted item — pass an episodeId or a radarrId.", input: { episodeId: { type: "number", description: "a Sonarr episode id (from bazarr_wanted)" }, radarrId: { type: "number", description: "a Radarr movie id (from bazarr_wanted)" }, }, run: async (args) => { if (args.episodeId !== undefined) { const results = await bazarr.searchEpisode(Number(args.episodeId)); return { kind: "episode", episodeId: Number(args.episodeId), count: results.length, results }; } if (args.radarrId !== undefined) { const results = await bazarr.searchMovie(Number(args.radarrId)); return { kind: "movie", radarrId: Number(args.radarrId), count: results.length, results }; } throw new Error("pass either episodeId or radarrId"); }, }, { name: "bazarr_history", description: "Recent subtitle-download history — what was downloaded, for which title, from which provider.", input: { limit: { type: "number", description: "max entries per kind (default 40)" } }, run: async (args) => { const history = await bazarr.getHistory(args.limit ? Number(args.limit) : 40); return { count: history.length, history }; }, }, ]; } // Exposed only when Bazarr is configured; otherwise bazarr contributes no tools rather than // failing the whole runtime. registerModuleTools("bazarr", (env) => { try { return getBazarrTools(BazarrClient.fromEnv(env)); } catch { return []; } });