"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.toolsProvider = toolsProvider;
const sdk_1 = require("@lmstudio/sdk");
const openai_1 = require("./docs/openai");
const anthropic_1 = require("./docs/anthropic");
const minimax_1 = require("./docs/minimax");
const gemini_1 = require("./docs/gemini");
const mistral_1 = require("./docs/mistral");
const cohere_1 = require("./docs/cohere");
const groq_1 = require("./docs/groq");
const together_1 = require("./docs/together");
const deepseek_1 = require("./docs/deepseek");
const perplexity_1 = require("./docs/perplexity");
const xai_1 = require("./docs/xai");
const ragSearch_1 = require("./ragSearch");
const ALL_DOCS = [
...openai_1.openAIDocs,
...anthropic_1.anthropicDocs,
...minimax_1.minimaxDocs,
...gemini_1.geminiDocs,
...mistral_1.mistralDocs,
...cohere_1.cohereDocs,
...groq_1.groqDocs,
...together_1.togetherDocs,
...deepseek_1.deepseekDocs,
...perplexity_1.perplexityDocs,
...xai_1.xaiDocs,
];
const PROVIDER_NAMES = {
openai: "OpenAI (ChatGPT)",
anthropic: "Anthropic (Claude)",
minimax: "MiniMax",
gemini: "Google Gemini",
mistral: "Mistral AI",
cohere: "Cohere",
groq: "Groq",
together: "Together AI",
deepseek: "DeepSeek",
perplexity: "Perplexity",
xai: "xAI (Grok)",
};
function scoreDoc(doc, query) {
const q = query.toLowerCase();
const words = q.split(/\s+/).filter(w => w.length > 1);
let score = 0;
const titleLower = doc.title.toLowerCase();
const contentLower = doc.content.toLowerCase();
const providerLower = doc.provider.toLowerCase();
for (const word of words) {
if (titleLower.includes(word))
score += 10;
if (providerLower.includes(word))
score += 8;
for (const kw of doc.keywords) {
if (kw.toLowerCase().includes(word))
score += 5;
}
const regex = new RegExp(word, "gi");
const matches = contentLower.match(regex);
if (matches)
score += matches.length;
}
if (contentLower.includes(q))
score += 20;
if (titleLower.includes(q))
score += 15;
return score;
}
function searchDocs(query, provider, category) {
return (0, ragSearch_1.searchDocsRAG)(ALL_DOCS, query, provider, category, 5);
}
function listProviders() {
let result = "## Available API Documentation Providers\n\n";
const providers = new Map();
for (const doc of ALL_DOCS) {
if (!providers.has(doc.provider)) {
providers.set(doc.provider, []);
}
providers.get(doc.provider).push(doc);
}
for (const [provider, docs] of providers) {
result += `### ${PROVIDER_NAMES[provider] || provider}\n`;
for (const doc of docs) {
result += `- **${doc.title}** (category: ${doc.category})\n`;
}
result += "\n";
}
result += "## Usage\n";
result += 'Use `api_docs_search` tool with:\n';
result += '- query: what you are looking for (required)\n';
result += '- provider: filter by provider name (optional)\n';
result += '- category: filter by category (optional)\n\n';
result += "## Categories\n";
result += "- **chat**: Chat/completions endpoints\n";
result += "- **tools**: Function calling / tool use\n";
result += "- **embeddings**: Vector embeddings\n";
result += "- **multimodal**: Image/audio/video input\n";
result += "- **output**: Structured output, JSON mode\n";
result += "- **limits**: Rate limits, pricing\n";
result += "- **optimization**: Caching, performance\n";
result += "- **rerank**: Document reranking\n";
result += "- **completion**: Text completion\n";
return result;
}
async function toolsProvider(ctl) {
const tools = [];
tools.push((0, sdk_1.rawFunctionTool)({
name: "api_docs_search",
description: `
Search AI API documentation for coding references.
USE THIS TOOL when:
- Writing code that calls AI APIs (OpenAI, Claude, Gemini, etc.)
- Need to check API parameters, endpoints, or request formats
- User asks about how to use a specific AI API
- Need to verify correct syntax for function calling, embeddings, etc.
DO NOT hallucinate API details - search this tool instead.
Parameters:
- query: what you are searching for (required)
- provider: filter by provider - "openai", "anthropic", "minimax", "gemini", "mistral", "cohere", "groq", "together", "deepseek", "perplexity", "xai" (optional)
- category: filter by category - "chat", "tools", "embeddings", "multimodal", "output", "limits" (optional)
`,
parametersJsonSchema: {
type: "object",
properties: {
query: { type: "string", description: "What to search for in the documentation" },
provider: { type: "string", description: "Filter by provider: openai, anthropic, minimax, gemini, mistral, cohere, groq, together, deepseek, perplexity, xai" },
category: { type: "string", description: "Filter by category: chat, tools, embeddings, multimodal, output, limits" }
},
required: ["query"]
},
implementation: async (params) => {
const query = String(params.query || "").trim();
const provider = params.provider ? String(params.provider).trim() : undefined;
const category = params.category ? String(params.category).trim() : undefined;
if (!query)
return "Please provide a search query";
return searchDocs(query, provider, category);
},
}));
tools.push((0, sdk_1.rawFunctionTool)({
name: "api_docs_list",
description: `
List all available API documentation providers and their topics.
USE THIS TOOL to see what documentation is available before searching.
`,
parametersJsonSchema: {
type: "object",
properties: {},
required: []
},
implementation: async () => {
return listProviders();
},
}));
return tools;
}
//# sourceMappingURL=toolsProvider.js.map