/** * AI инструменты для рендеринга и оптимизации производительности * * Предоставляет Claude возможности для анализа производительности, * оптимизации рендеринга и управления ресурсами системы */ import { ClaudeTool } from "../services/claude-service" /** * Render & Performance Tools - 8 инструментов для оптимизации */ export const renderPerformanceTools: ClaudeTool[] = [ { name: "analyze_render_performance", description: "Анализирует производительность рендеринга и выявляет узкие места в проекте", input_schema: { type: "object", properties: { analysisScope: { type: "string", enum: ["full-project", "timeline-range", "specific-clips", "effects-only", "current-view"], description: "Область анализа производительности", default: "full-project", }, timeRange: { type: "object", properties: { start: { type: "number", description: "Начальное время в секундах" }, end: { type: "number", description: "Конечное время в секундах" }, }, description: "Временной диапазон для анализа", }, performanceMetrics: { type: "array", items: { type: "string", enum: [ "render-speed", "memory-usage", "gpu-utilization", "cpu-load", "disk-io", "cache-efficiency", "codec-performance", ], }, description: "Метрики производительности для анализа", default: ["render-speed", "memory-usage", "gpu-utilization", "cpu-load"], }, includeRecommendations: { type: "boolean", description: "Включить рекомендации по оптимизации", default: true, }, benchmarkMode: { type: "boolean", description: "Режим бенчмарка для точных измерений", default: false, }, }, }, }, { name: "optimize_render_settings", description: "Оптимизирует настройки рендеринга для максимальной производительности при сохранении качества", input_schema: { type: "object", properties: { optimizationTarget: { type: "string", enum: ["speed", "quality", "balanced", "memory", "compatibility", "file-size"], description: "Цель оптимизации", default: "balanced", }, outputFormat: { type: "string", enum: ["mp4", "mov", "avi", "webm", "mkv", "mxf", "prores", "dnxhd"], description: "Целевой формат вывода", }, resolution: { type: "object", properties: { width: { type: "number" }, height: { type: "number" }, }, description: "Разрешение для оптимизации", }, systemResources: { type: "object", properties: { cpuCores: { type: "number", description: "Количество ядер CPU" }, ramGB: { type: "number", description: "Объем RAM в GB" }, gpuModel: { type: "string", description: "Модель GPU" }, storageType: { type: "string", enum: ["hdd", "ssd", "nvme"], description: "Тип накопителя" }, }, description: "Ресурсы системы для оптимизации", }, projectComplexity: { type: "string", enum: ["simple", "moderate", "complex", "very-complex"], description: "Сложность проекта", }, reason: { type: "string", description: "Причина оптимизации настроек", }, }, required: ["optimizationTarget", "reason"], }, }, { name: "manage_render_queue", description: "Управляет очередью рендеринга с приоритизацией и батчевой обработкой", input_schema: { type: "object", properties: { queueAction: { type: "string", enum: ["add", "remove", "reorder", "pause", "resume", "clear", "analyze"], description: "Действие с очередью рендеринга", }, renderJobs: { type: "array", items: { type: "object", properties: { jobId: { type: "string", description: "Уникальный ID задания" }, projectPath: { type: "string", description: "Путь к проекту" }, outputPath: { type: "string", description: "Путь для вывода" }, priority: { type: "number", minimum: 1, maximum: 10, description: "Приоритет задания", default: 5, }, renderSettings: { type: "object", description: "Настройки рендеринга для задания", }, estimatedTime: { type: "number", description: "Оценочное время рендеринга в минутах" }, dependencies: { type: "array", items: { type: "string" }, description: "ID заданий, от которых зависит это задание", }, }, required: ["jobId"], }, description: "Задания рендеринга для управления", }, schedulingStrategy: { type: "string", enum: ["priority", "shortest-first", "longest-first", "dependency-based", "resource-aware"], description: "Стратегия планирования заданий", default: "priority", }, resourceLimits: { type: "object", properties: { maxCpuUsage: { type: "number", minimum: 10, maximum: 100, description: "Максимальное использование CPU в %", }, maxMemoryUsage: { type: "number", minimum: 10, maximum: 100, description: "Максимальное использование памяти в %", }, maxConcurrentJobs: { type: "number", minimum: 1, description: "Максимальное количество одновременных заданий", }, }, description: "Ограничения ресурсов для очереди", }, reason: { type: "string", description: "Причина управления очередью", }, }, required: ["queueAction", "reason"], }, }, { name: "optimize_timeline_performance", description: "Оптимизирует производительность воспроизведения таймлайна в реальном времени", input_schema: { type: "object", properties: { optimizationAreas: { type: "array", items: { type: "string", enum: [ "preview-quality", "cache-size", "proxy-media", "effect-processing", "audio-processing", "memory-management", ], }, description: "Области для оптимизации", default: ["preview-quality", "cache-size", "proxy-media"], }, playbackTarget: { type: "string", enum: ["real-time", "quarter-res", "half-res", "full-res", "custom"], description: "Целевое качество воспроизведения", default: "real-time", }, cacheStrategy: { type: "string", enum: ["aggressive", "balanced", "conservative", "disabled", "auto"], description: "Стратегия кэширования", default: "balanced", }, proxySettings: { type: "object", properties: { enabled: { type: "boolean", description: "Включить прокси медиа" }, resolution: { type: "string", enum: ["quarter", "half", "three-quarter", "custom"] }, codec: { type: "string", enum: ["h264", "prores-proxy", "dnxhd", "cineform"] }, autoGenerate: { type: "boolean", description: "Автоматически генерировать прокси" }, }, description: "Настройки прокси медиа", }, realTimeOptimization: { type: "boolean", description: "Оптимизация для воспроизведения в реальном времени", default: true, }, reason: { type: "string", description: "Причина оптимизации таймлайна", }, }, required: ["reason"], }, }, { name: "generate_proxy_media", description: "Создает прокси-файлы для тяжелых медиа файлов для улучшения производительности", input_schema: { type: "object", properties: { targetFiles: { type: "array", items: { type: "string" }, description: "ID файлов для создания прокси (если не указано, автоматический выбор)", }, proxySettings: { type: "object", properties: { resolution: { type: "string", enum: ["quarter", "half", "three-quarter", "custom"], description: "Разрешение прокси относительно оригинала", default: "half", }, codec: { type: "string", enum: ["h264", "h265", "prores-proxy", "prores-lt", "dnxhd", "cineform"], description: "Кодек для прокси файлов", default: "h264", }, quality: { type: "string", enum: ["draft", "preview", "good", "high"], description: "Качество сжатия прокси", default: "preview", }, frameRate: { type: "string", enum: ["match-source", "half", "quarter", "custom"], description: "Частота кадров прокси", default: "match-source", }, }, }, selectionCriteria: { type: "object", properties: { minFileSize: { type: "number", description: "Минимальный размер файла в MB для создания прокси" }, minResolution: { type: "string", description: "Минимальное разрешение для создания прокси (например, 1920x1080)", }, fileTypes: { type: "array", items: { type: "string" }, description: "Типы файлов для создания прокси", }, excludeFormats: { type: "array", items: { type: "string" }, description: "Форматы для исключения из создания прокси", }, }, description: "Критерии автоматического выбора файлов", }, processingOptions: { type: "object", properties: { batchSize: { type: "number", description: "Количество файлов для одновременной обработки" }, priority: { type: "string", enum: ["low", "normal", "high"], description: "Приоритет обработки" }, useGPU: { type: "boolean", description: "Использовать GPU ускорение" }, backgroundProcessing: { type: "boolean", description: "Обработка в фоновом режиме" }, }, }, reason: { type: "string", description: "Причина создания прокси медиа", }, }, required: ["reason"], }, }, { name: "monitor_system_resources", description: "Мониторит использование системных ресурсов во время работы с проектом", input_schema: { type: "object", properties: { monitoringDuration: { type: "number", description: "Длительность мониторинга в секундах", default: 60, }, resourceTypes: { type: "array", items: { type: "string", enum: ["cpu", "memory", "gpu", "disk-io", "network", "temperature", "power"], }, description: "Типы ресурсов для мониторинга", default: ["cpu", "memory", "gpu", "disk-io"], }, samplingInterval: { type: "number", description: "Интервал сбора данных в секундах", default: 1, }, alertThresholds: { type: "object", properties: { cpuUsage: { type: "number", description: "Порог использования CPU в %" }, memoryUsage: { type: "number", description: "Порог использования памяти в %" }, gpuUsage: { type: "number", description: "Порог использования GPU в %" }, diskUsage: { type: "number", description: "Порог использования диска в %" }, temperature: { type: "number", description: "Порог температуры в °C" }, }, description: "Пороги для оповещений о высокой нагрузке", }, includeRecommendations: { type: "boolean", description: "Включить рекомендации по оптимизации", default: true, }, realTimeAlerts: { type: "boolean", description: "Оповещения в реальном времени", default: true, }, }, }, }, { name: "estimate_render_time", description: "Оценивает время рендеринга проекта на основе сложности и ресурсов системы", input_schema: { type: "object", properties: { estimationScope: { type: "string", enum: ["full-project", "timeline-range", "selected-clips", "current-sequence"], description: "Область для оценки времени рендеринга", default: "full-project", }, timeRange: { type: "object", properties: { start: { type: "number" }, end: { type: "number" }, }, description: "Временной диапазон для оценки", }, renderSettings: { type: "object", properties: { resolution: { type: "string", description: "Разрешение рендеринга" }, codec: { type: "string", description: "Кодек для рендеринга" }, quality: { type: "string", enum: ["draft", "preview", "good", "high", "highest"] }, frameRate: { type: "number", description: "Частота кадров" }, bitrate: { type: "number", description: "Битрейт" }, }, description: "Настройки рендеринга для оценки", }, systemSpecs: { type: "object", properties: { cpuModel: { type: "string" }, cpuCores: { type: "number" }, ramGB: { type: "number" }, gpuModel: { type: "string" }, storageType: { type: "string", enum: ["hdd", "ssd", "nvme"] }, }, description: "Характеристики системы для точной оценки", }, includeVariations: { type: "boolean", description: "Включить оценки для разных настроек качества", default: true, }, historicalData: { type: "boolean", description: "Использовать исторические данные рендеринга", default: true, }, }, }, }, { name: "optimize_export_workflow", description: "Оптимизирует рабочий процесс экспорта для различных платформ и использований", input_schema: { type: "object", properties: { exportTargets: { type: "array", items: { type: "object", properties: { platform: { type: "string", enum: [ "youtube", "instagram", "tiktok", "facebook", "twitter", "vimeo", "broadcast", "cinema", "web", "mobile", "custom", ], }, priority: { type: "number", minimum: 1, maximum: 10 }, customSettings: { type: "object", description: "Кастомные настройки для платформы" }, }, required: ["platform"], }, description: "Целевые платформы для экспорта", }, workflowType: { type: "string", enum: ["single-export", "multi-format", "versioning", "batch-processing", "automated"], description: "Тип рабочего процесса экспорта", default: "single-export", }, optimizationGoals: { type: "array", items: { type: "string", enum: ["file-size", "quality", "speed", "compatibility", "accessibility", "automation"], }, description: "Цели оптимизации экспорта", default: ["quality", "file-size"], }, automationLevel: { type: "string", enum: ["manual", "semi-automated", "fully-automated"], description: "Уровень автоматизации процесса", default: "semi-automated", }, qualityControl: { type: "object", properties: { enableQC: { type: "boolean", description: "Включить контроль качества" }, qcChecks: { type: "array", items: { type: "string", enum: ["audio-levels", "video-quality", "metadata", "compliance", "file-integrity"], }, }, autoRetry: { type: "boolean", description: "Автоматически повторить при ошибках" }, }, }, reason: { type: "string", description: "Причина оптимизации экспорта", }, }, required: ["exportTargets", "reason"], }, }, ] /** * Типы результатов выполнения render & performance инструментов */ export interface RenderPerformanceToolResult { success: boolean message: string data?: { performanceMetrics?: any optimizationResults?: any renderQueue?: any[] timelineOptimizations?: any proxyFiles?: string[] systemMonitoring?: any timeEstimation?: any workflowOptimizations?: any recommendations?: string[] warnings?: string[] } errors?: string[] nextActions?: string[] } /** * Интерфейс для доступа к системе рендеринга и производительности */ interface RenderSystemAccess { analyzePerformance: (scope: string, metrics: string[]) => any optimizeRenderSettings: (target: string, settings: any) => any manageRenderQueue: (action: string, jobs: any[], strategy: string) => any optimizeTimeline: (areas: string[], settings: any) => any generateProxyMedia: (files: string[], settings: any) => Promise monitorSystemResources: (duration: number, types: string[]) => any estimateRenderTime: (scope: string, settings: any) => any optimizeExportWorkflow: (targets: any[], type: string, goals: string[]) => any getSystemSpecs: () => any getCurrentResourceUsage: () => any } // Глобальная переменная для доступа к системе рендеринга let renderSystemAccess: RenderSystemAccess | null = null /** * Устанавливает доступ к системе рендеринга */ export function setRenderSystemAccess(access: RenderSystemAccess | null) { renderSystemAccess = access } /** * Выполняет render & performance инструмент */ export async function executeRenderPerformanceTool( toolName: string, input: Record, ): Promise { try { switch (toolName) { case "analyze_render_performance": return await analyzeRenderPerformance(input) case "optimize_render_settings": return await optimizeRenderSettings(input) case "manage_render_queue": return await manageRenderQueue(input) case "optimize_timeline_performance": return await optimizeTimelinePerformance(input) case "generate_proxy_media": return await generateProxyMedia(input) case "monitor_system_resources": return await monitorSystemResources(input) case "estimate_render_time": return await estimateRenderTime(input) case "optimize_export_workflow": return await optimizeExportWorkflow(input) default: return { success: false, message: `Неизвестный render & performance инструмент: ${toolName}`, errors: [`Инструмент ${toolName} не найден`], } } } catch (error) { return { success: false, message: `Ошибка выполнения render & performance инструмента ${toolName}: ${error instanceof Error ? error.message : String(error)}`, errors: [error instanceof Error ? error.message : String(error)], } } } /** * Анализирует производительность рендеринга */ async function analyzeRenderPerformance(input: Record): Promise { const { analysisScope = "full-project", timeRange, performanceMetrics = ["render-speed", "memory-usage", "gpu-utilization", "cpu-load"], includeRecommendations = true, benchmarkMode = false, } = input if (!renderSystemAccess) { return { success: false, message: "Render system access не настроен", errors: ["Доступ к системе рендеринга не сконфигурирован"], } } try { const performanceData = renderSystemAccess.analyzePerformance(analysisScope, performanceMetrics) // Генерируем рекомендации на основе анализа const recommendations: string[] = [] if (includeRecommendations) { if (performanceData.cpuLoad > 90) { recommendations.push("Высокая нагрузка на CPU - рассмотрите снижение качества превью") recommendations.push("Используйте прокси-файлы для тяжелых медиа") } if (performanceData.memoryUsage > 85) { recommendations.push("Высокое использование памяти - закройте неиспользуемые приложения") recommendations.push("Уменьшите размер кэша воспроизведения") } if (performanceData.gpuUtilization < 30 && performanceData.cpuLoad > 70) { recommendations.push("GPU недостаточно используется - включите GPU ускорение") } if (performanceData.renderSpeed < 0.5) { recommendations.push("Медленный рендеринг - оптимизируйте настройки кодека") recommendations.push("Используйте аппаратное ускорение кодирования") } } return { success: true, message: `Анализ производительности завершен для области: ${analysisScope}`, data: { performanceMetrics: performanceData, recommendations, }, nextActions: recommendations.length > 0 ? ["Применить рекомендации по оптимизации", "Оптимизировать настройки рендеринга"] : ["Продолжить работу с проектом"], } } catch (error) { return { success: false, message: `Ошибка анализа производительности: ${String(error)}`, errors: [String(error)], } } } /** * Оптимизирует настройки рендеринга */ async function optimizeRenderSettings(input: Record): Promise { const { optimizationTarget = "balanced", outputFormat, resolution, systemResources, projectComplexity, reason, } = input if (!renderSystemAccess) { return { success: false, message: "Render system access не настроен", errors: ["Доступ к системе рендеринга не сконфигурирован"], } } try { const optimizationSettings = { target: optimizationTarget, format: outputFormat, resolution, systemSpecs: systemResources, complexity: projectComplexity, } const optimizationResults = renderSystemAccess.optimizeRenderSettings(optimizationTarget, optimizationSettings) // Генерируем рекомендации по оптимизированным настройкам const recommendations: string[] = [] switch (optimizationTarget) { case "speed": recommendations.push("Настройки оптимизированы для максимальной скорости") recommendations.push("Качество может быть незначительно снижено") break case "quality": recommendations.push("Настройки оптимизированы для максимального качества") recommendations.push("Время рендеринга может увеличиться") break case "balanced": recommendations.push("Найден оптимальный баланс между качеством и скоростью") break case "memory": recommendations.push("Настройки оптимизированы для экономии памяти") recommendations.push("Используйте батчевую обработку для больших проектов") break default: recommendations.push("Используются стандартные настройки оптимизации") break } return { success: true, message: `Настройки рендеринга оптимизированы для цели: ${optimizationTarget} (${reason})`, data: { optimizationResults, recommendations, }, nextActions: ["Применить оптимизированные настройки", "Протестировать на небольшом фрагменте"], } } catch (error) { return { success: false, message: `Ошибка оптимизации настроек рендеринга: ${String(error)}`, errors: [String(error)], } } } /** * Управляет очередью рендеринга */ async function manageRenderQueue(input: Record): Promise { const { queueAction, renderJobs = [], schedulingStrategy = "priority", resourceLimits, reason } = input if (!renderSystemAccess) { return { success: false, message: "Render system access не настроен", errors: ["Доступ к системе рендеринга не сконфигурирован"], } } try { const queueResults = renderSystemAccess.manageRenderQueue(queueAction, renderJobs, schedulingStrategy) let message = "" const nextActions: string[] = [] switch (queueAction) { case "add": message = `Добавлено ${renderJobs.length} заданий в очередь рендеринга` nextActions.push("Мониторить прогресс рендеринга") break case "remove": message = "Задания удалены из очереди" nextActions.push("Проверить оставшиеся задания") break case "reorder": message = "Очередь рендеринга переупорядочена" nextActions.push("Проверить новый порядок заданий") break case "pause": message = "Очередь рендеринга приостановлена" nextActions.push("Возобновить когда готово") break case "resume": message = "Очередь рендеринга возобновлена" nextActions.push("Мониторить выполнение") break case "analyze": message = "Анализ очереди рендеринга выполнен" nextActions.push("Оптимизировать планирование заданий") break default: message = `Действие ${queueAction} выполнено` } return { success: true, message: `${message} (${reason})`, data: { renderQueue: queueResults, }, nextActions, } } catch (error) { return { success: false, message: `Ошибка управления очередью рендеринга: ${String(error)}`, errors: [String(error)], } } } /** * Оптимизирует производительность таймлайна */ async function optimizeTimelinePerformance(input: Record): Promise { const { optimizationAreas = ["preview-quality", "cache-size", "proxy-media"], playbackTarget = "real-time", cacheStrategy = "balanced", proxySettings, realTimeOptimization = true, reason, } = input if (!renderSystemAccess) { return { success: false, message: "Render system access не настроен", errors: ["Доступ к системе рендеринга не сконфигурирован"], } } try { const timelineSettings = { areas: optimizationAreas, target: playbackTarget, cache: cacheStrategy, proxy: proxySettings, realTime: realTimeOptimization, } const optimizationResults = renderSystemAccess.optimizeTimeline(optimizationAreas, timelineSettings) const recommendations: string[] = [] optimizationAreas.forEach((area: any) => { switch (area) { case "preview-quality": recommendations.push("Качество превью оптимизировано для плавного воспроизведения") break case "cache-size": recommendations.push("Размер кэша настроен под доступную память") break case "proxy-media": recommendations.push("Прокси-медиа настроено для улучшения производительности") break case "effect-processing": recommendations.push("Обработка эффектов оптимизирована") break default: recommendations.push(`Оптимизация области: ${area}`) break } }) return { success: true, message: `Производительность таймлайна оптимизирована (${reason})`, data: { timelineOptimizations: optimizationResults, recommendations, }, nextActions: ["Протестировать воспроизведение", "Настроить дополнительные параметры"], } } catch (error) { return { success: false, message: `Ошибка оптимизации таймлайна: ${String(error)}`, errors: [String(error)], } } } /** * Создает прокси-медиа файлы */ async function generateProxyMedia(input: Record): Promise { const { targetFiles, proxySettings, selectionCriteria, processingOptions, reason } = input if (!renderSystemAccess) { return { success: false, message: "Render system access не настроен", errors: ["Доступ к системе рендеринга не сконфигурирован"], } } try { const settings = { ...proxySettings, selection: selectionCriteria, processing: processingOptions, } const proxyFiles = await renderSystemAccess.generateProxyMedia(targetFiles || [], settings) return { success: true, message: `Создано ${proxyFiles.length} прокси-файлов (${reason})`, data: { proxyFiles, recommendations: [ "Прокси-файлы готовы для использования", "Переключитесь на прокси для улучшения производительности", ], }, nextActions: ["Переключиться на прокси воспроизведение", "Проверить качество прокси"], } } catch (error) { return { success: false, message: `Ошибка создания прокси-медиа: ${String(error)}`, errors: [String(error)], } } } // Заглушки для остальных функций (в реальной реализации они будут полностью развернуты) async function monitorSystemResources(_input: Record): Promise { return { success: true, message: "System monitoring started", data: { systemMonitoring: { status: "active" } }, } } async function estimateRenderTime(_input: Record): Promise { return { success: true, message: "Render time estimated", data: { timeEstimation: { estimatedMinutes: 45 } }, } } async function optimizeExportWorkflow(_input: Record): Promise { return { success: true, message: "Export workflow optimized", data: { workflowOptimizations: {} }, } }