UNPKG

solver-sdk

Version:

SDK for WorkAI API - AI-powered code analysis with WorkCoins billing system

82 lines 3.11 kB
/** * 🔧 API для работы с инструментами ИИ */ export class ToolsApi { constructor(httpClient) { this.httpClient = httpClient; } /** * 📋 Получает все доступные схемы инструментов * @returns Список всех инструментов с их схемами */ async getSchemas() { try { const response = await this.httpClient.get('/api/v1/tools/schemas'); return response; } catch (error) { throw new Error(`Ошибка получения схем инструментов: ${error instanceof Error ? error.message : String(error)}`); } } /** * 🔍 Поиск инструмента по имени * @param name Имя инструмента * @returns Схема инструмента или null */ async findToolByName(name) { const { tools } = await this.getSchemas(); return tools.find(tool => tool.name === name) || null; } /** * 📊 Получает статистику доступных инструментов * @returns Информация о количестве и типах инструментов */ async getToolsStats() { const { tools } = await this.getSchemas(); // Простая категоризация по префиксам названий const categories = {}; tools.forEach(tool => { const category = tool.name.split('_')[0] || 'other'; categories[category] = (categories[category] || 0) + 1; }); return { total: tools.length, categories, // TODO: Добавить статистику использования если будет доступна на бэкенде }; } /** * ✅ Валидирует схему инструмента * @param tool Схема инструмента для валидации * @returns true если схема корректна */ validateToolSchema(tool) { if (!tool.name || !tool.description) { return false; } if (!tool.input_schema || tool.input_schema.type !== 'object') { return false; } return true; } /** * 🔧 Создает базовую схему инструмента * @param name Имя инструмента * @param description Описание * @param properties Свойства входных параметров * @param required Обязательные параметры * @returns Готовая схема инструмента */ createToolSchema(name, description, properties, required = []) { return { name, description, input_schema: { type: 'object', properties, required: required.length > 0 ? required : undefined, }, }; } } //# sourceMappingURL=tools-api.js.map