/** * AI инструменты для обработки медиа контента * * Предоставляет Claude возможности для конвертации, * сжатия и технической обработки медиафайлов */ import { ClaudeTool } from "../services/claude-service" /** * Media Processing Tools - 6 инструментов для обработки медиа */ export const mediaProcessingTools: ClaudeTool[] = [ { name: "analyze_media_quality", description: "Анализирует техническое качество медиафайлов и выявляет проблемы", input_schema: { type: "object", properties: { targetFiles: { type: "array", items: { type: "string" }, description: "ID файлов для анализа качества", }, qualityMetrics: { type: "array", items: { type: "string", enum: [ "resolution", "bitrate", "compression", "noise", "artifacts", "sharpness", "color-accuracy", "frame-drops", ], }, description: "Метрики качества для анализа", default: ["resolution", "bitrate", "noise", "artifacts"], }, analysisDepth: { type: "string", enum: ["quick", "standard", "comprehensive", "forensic"], description: "Глубина анализа", default: "standard", }, samplingRate: { type: "string", enum: ["every-frame", "keyframes-only", "custom-interval", "scene-changes"], description: "Частота сэмплирования для анализа", default: "keyframes-only", }, thresholds: { type: "object", properties: { minResolution: { type: "string", description: "Минимальное разрешение (например, 1920x1080)" }, minBitrate: { type: "number", description: "Минимальный битрейт в Mbps" }, maxNoise: { type: "number", description: "Максимальный уровень шума" }, minSharpness: { type: "number", description: "Минимальная резкость" }, }, }, generateReport: { type: "boolean", description: "Создать подробный отчет", default: true, }, includeRecommendations: { type: "boolean", description: "Включить рекомендации по улучшению", default: true, }, }, }, }, { name: "optimize_media_compression", description: "Оптимизирует сжатие медиафайлов для различных целей и платформ", input_schema: { type: "object", properties: { targetFiles: { type: "array", items: { type: "string" }, description: "ID файлов для оптимизации", }, optimizationGoal: { type: "string", enum: ["file-size", "quality", "streaming", "archival", "web-delivery", "mobile-playback"], description: "Цель оптимизации", }, targetPlatforms: { type: "array", items: { type: "string", enum: ["youtube", "instagram", "tiktok", "vimeo", "broadcast", "web", "mobile", "cinema"], }, description: "Целевые платформы для оптимизации", }, compressionSettings: { type: "object", properties: { videoCodec: { type: "string", enum: ["h264", "h265", "av1", "vp9", "prores", "dnxhd"], description: "Видеокодек для сжатия", }, audioCodec: { type: "string", enum: ["aac", "mp3", "opus", "flac", "pcm"], description: "Аудиокодек для сжатия", }, qualityLevel: { type: "string", enum: ["maximum", "high", "medium", "low", "custom"], description: "Уровень качества", default: "high", }, targetBitrate: { type: "object", properties: { video: { type: "number", description: "Целевой битрейт видео в Mbps" }, audio: { type: "number", description: "Целевой битрейт аудио в kbps" }, }, }, twoPassEncoding: { type: "boolean", description: "Двухпроходное кодирование" }, hardwareAcceleration: { type: "boolean", description: "Аппаратное ускорение" }, }, }, constraintsSettings: { type: "object", properties: { maxFileSize: { type: "number", description: "Максимальный размер файла в MB" }, maxDuration: { type: "number", description: "Максимальная длительность в секундах" }, maintainAspectRatio: { type: "boolean", description: "Сохранять соотношение сторон" }, preserveMetadata: { type: "boolean", description: "Сохранять метаданные" }, }, }, batchProcessing: { type: "object", properties: { enabled: { type: "boolean", description: "Пакетная обработка" }, parallelJobs: { type: "number", minimum: 1, maximum: 8, description: "Количество параллельных заданий" }, priorityOrder: { type: "string", enum: ["size", "duration", "importance", "creation-date"] }, }, }, reason: { type: "string", description: "Цель оптимизации сжатия", }, }, required: ["targetFiles", "optimizationGoal", "reason"], }, }, { name: "convert_media_formats", description: "Конвертирует медиафайлы между различными форматами с сохранением качества", input_schema: { type: "object", properties: { sourceFiles: { type: "array", items: { type: "string" }, description: "ID исходных файлов для конвертации", }, conversionTargets: { type: "array", items: { type: "object", properties: { outputFormat: { type: "string", enum: ["mp4", "mov", "avi", "mkv", "webm", "wav", "mp3", "flac", "jpg", "png", "tiff"], }, resolution: { type: "string", description: "Разрешение вывода" }, frameRate: { type: "number", description: "Частота кадров" }, outputPath: { type: "string", description: "Путь для сохранения" }, customSettings: { type: "object", description: "Дополнительные настройки" }, }, required: ["outputFormat"], }, description: "Цели конвертации", }, conversionQuality: { type: "string", enum: ["lossless", "high", "medium", "optimized", "draft"], description: "Качество конвертации", default: "high", }, processingOptions: { type: "object", properties: { deinterlace: { type: "boolean", description: "Деинтерлейсинг" }, denoise: { type: "boolean", description: "Шумоподавление" }, sharpen: { type: "boolean", description: "Повышение резкости" }, colorSpaceConversion: { type: "string", description: "Конвертация цветового пространства" }, audioNormalization: { type: "boolean", description: "Нормализация аудио" }, }, }, automationSettings: { type: "object", properties: { autoDetectSettings: { type: "boolean", description: "Автоматическое определение настроек" }, preserveStructure: { type: "boolean", description: "Сохранять структуру папок" }, overwriteExisting: { type: "boolean", description: "Перезаписывать существующие файлы" }, generateThumbnails: { type: "boolean", description: "Генерировать миниатюры" }, }, }, progressTracking: { type: "object", properties: { showProgress: { type: "boolean", description: "Показывать прогресс" }, logDetails: { type: "boolean", description: "Детальное логирование" }, pauseOnError: { type: "boolean", description: "Приостановка при ошибке" }, retryOnFailure: { type: "boolean", description: "Повторить при неудаче" }, }, }, reason: { type: "string", description: "Цель конвертации форматов", }, }, required: ["sourceFiles", "conversionTargets", "reason"], }, }, { name: "repair_corrupted_media", description: "Восстанавливает поврежденные медиафайлы и исправляет ошибки", input_schema: { type: "object", properties: { damagedFiles: { type: "array", items: { type: "string" }, description: "ID поврежденных файлов", }, damageTypes: { type: "array", items: { type: "string", enum: [ "header-corruption", "data-loss", "sync-issues", "incomplete-file", "codec-errors", "metadata-corruption", ], }, description: "Типы повреждений для исправления", }, repairMethods: { type: "array", items: { type: "string", enum: [ "header-reconstruction", "data-interpolation", "frame-recovery", "sync-restoration", "metadata-repair", ], }, description: "Методы восстановления", default: ["header-reconstruction", "data-interpolation"], }, recoverySettings: { type: "object", properties: { aggressiveRecovery: { type: "boolean", description: "Агрессивное восстановление" }, preserveOriginal: { type: "boolean", description: "Сохранить оригинал" }, qualityThreshold: { type: "number", minimum: 0, maximum: 1, description: "Порог качества для восстановления", default: 0.7, }, maxRecoveryTime: { type: "number", description: "Максимальное время восстановления в минутах" }, }, }, fallbackOptions: { type: "object", properties: { useBackup: { type: "boolean", description: "Использовать резервную копию" }, partialRecovery: { type: "boolean", description: "Частичное восстановление" }, transcodeOption: { type: "boolean", description: "Транскодирование как запасной вариант" }, reportUnrecoverable: { type: "boolean", description: "Сообщать о невосстановимых файлах" }, }, }, validationSettings: { type: "object", properties: { verifyIntegrity: { type: "boolean", description: "Проверить целостность" }, compareWithOriginal: { type: "boolean", description: "Сравнить с оригиналом" }, testPlayback: { type: "boolean", description: "Тестировать воспроизведение" }, generateReport: { type: "boolean", description: "Создать отчет о восстановлении" }, }, }, reason: { type: "string", description: "Причина восстановления файлов", }, }, required: ["damagedFiles", "reason"], }, }, { name: "batch_process_media", description: "Выполняет пакетную обработку множества медиафайлов с различными операциями", input_schema: { type: "object", properties: { batchFiles: { type: "array", items: { type: "string" }, description: "ID файлов для пакетной обработки", }, processingTasks: { type: "array", items: { type: "object", properties: { taskType: { type: "string", enum: ["resize", "convert", "compress", "watermark", "metadata-edit", "color-correct", "audio-process"], }, parameters: { type: "object", description: "Параметры задачи" }, order: { type: "number", description: "Порядок выполнения" }, conditional: { type: "boolean", description: "Условное выполнение" }, conditions: { type: "object", description: "Условия выполнения" }, }, required: ["taskType", "parameters"], }, description: "Задачи для пакетной обработки", }, executionSettings: { type: "object", properties: { parallelism: { type: "number", minimum: 1, maximum: 16, description: "Количество параллельных процессов", default: 4, }, priority: { type: "string", enum: ["low", "normal", "high", "urgent"], description: "Приоритет обработки", default: "normal", }, scheduledStart: { type: "string", description: "Запланированное время начала" }, resourceLimits: { type: "object", properties: { maxCpuUsage: { type: "number", minimum: 10, maximum: 100 }, maxMemoryUsage: { type: "number", minimum: 10, maximum: 100 }, maxDiskUsage: { type: "number", minimum: 10, maximum: 100 }, }, }, }, }, errorHandling: { type: "object", properties: { continueOnError: { type: "boolean", description: "Продолжать при ошибках" }, retryAttempts: { type: "number", minimum: 0, maximum: 5, description: "Количество попыток" }, errorNotification: { type: "boolean", description: "Уведомления об ошибках" }, logLevel: { type: "string", enum: ["minimal", "standard", "detailed", "debug"] }, }, }, outputSettings: { type: "object", properties: { outputDirectory: { type: "string", description: "Папка для результатов" }, namingConvention: { type: "string", description: "Соглашение о наименовании" }, preserveStructure: { type: "boolean", description: "Сохранять структуру папок" }, createManifest: { type: "boolean", description: "Создать манифест обработки" }, }, }, monitoringSettings: { type: "object", properties: { progressUpdates: { type: "boolean", description: "Обновления прогресса" }, estimateCompletion: { type: "boolean", description: "Оценка времени завершения" }, resourceMonitoring: { type: "boolean", description: "Мониторинг ресурсов" }, qualityCheck: { type: "boolean", description: "Проверка качества результата" }, }, }, reason: { type: "string", description: "Цель пакетной обработки", }, }, required: ["batchFiles", "processingTasks", "reason"], }, }, { name: "create_media_derivatives", description: "Создает производные версии медиафайлов для различных целей и устройств", input_schema: { type: "object", properties: { sourceFiles: { type: "array", items: { type: "string" }, description: "ID исходных файлов", }, derivativeTypes: { type: "array", items: { type: "object", properties: { type: { type: "string", enum: ["proxy", "thumbnail", "preview", "web-optimized", "mobile", "social-media", "archival"], }, specifications: { type: "object", properties: { resolution: { type: "string", description: "Разрешение" }, bitrate: { type: "number", description: "Битрейт" }, format: { type: "string", description: "Формат файла" }, quality: { type: "string", enum: ["low", "medium", "high", "max"] }, duration: { type: "number", description: "Длительность (для превью)" }, }, }, platform: { type: "string", description: "Целевая платформа" }, useCase: { type: "string", description: "Случай использования" }, }, required: ["type", "specifications"], }, description: "Типы производных файлов", }, generationSettings: { type: "object", properties: { autoOptimize: { type: "boolean", description: "Автоматическая оптимизация" }, maintainQuality: { type: "boolean", description: "Поддерживать качество" }, adaptiveBitrate: { type: "boolean", description: "Адаптивный битрейт" }, smartCropping: { type: "boolean", description: "Умная обрезка" }, watermarkSettings: { type: "object", properties: { enabled: { type: "boolean" }, watermarkPath: { type: "string" }, position: { type: "string", enum: ["top-left", "top-right", "bottom-left", "bottom-right", "center"] }, opacity: { type: "number", minimum: 0, maximum: 1 }, }, }, }, }, organizationSettings: { type: "object", properties: { outputStructure: { type: "string", enum: ["flat", "by-type", "by-source", "by-platform", "custom"], description: "Структура выходных файлов", }, namingTemplate: { type: "string", description: "Шаблон наименования" }, metadataInheritance: { type: "boolean", description: "Наследование метаданных" }, linkToOriginal: { type: "boolean", description: "Связать с оригиналом" }, }, }, qualityControl: { type: "object", properties: { validateOutput: { type: "boolean", description: "Валидация выходных файлов" }, compareWithSource: { type: "boolean", description: "Сравнение с источником" }, qualityThresholds: { type: "object", properties: { minPSNR: { type: "number", description: "Минимальный PSNR" }, maxFileSizeDelta: { type: "number", description: "Максимальное отклонение размера файла" }, audioQualityCheck: { type: "boolean", description: "Проверка качества аудио" }, }, }, }, }, automationRules: { type: "array", items: { type: "object", properties: { condition: { type: "string", description: "Условие" }, action: { type: "string", description: "Действие" }, parameters: { type: "object", description: "Параметры действия" }, }, }, description: "Правила автоматизации создания производных", }, reason: { type: "string", description: "Цель создания производных файлов", }, }, required: ["sourceFiles", "derivativeTypes", "reason"], }, }, ] /** * Типы результатов выполнения media processing инструментов */ export interface MediaProcessingToolResult { success: boolean message: string data?: { qualityAnalysis?: any compressionResults?: any conversionResults?: any repairResults?: any batchResults?: any derivativeFiles?: string[] recommendations?: string[] warnings?: string[] processingStats?: any } errors?: string[] nextActions?: string[] } /** * Интерфейс для доступа к системе обработки медиа */ interface MediaProcessingSystemAccess { analyzeMediaQuality: (files: string[], metrics: string[], depth: string) => Promise optimizeCompression: (files: string[], goal: string, platforms: string[], settings: any) => Promise convertMediaFormats: (sources: string[], targets: any[], quality: string, options: any) => Promise repairCorruptedMedia: (files: string[], types: string[], methods: string[], settings: any) => Promise batchProcessMedia: (files: string[], tasks: any[], execution: any, monitoring: any) => Promise createMediaDerivatives: (sources: string[], types: any[], settings: any, quality: any) => Promise getMediaInfo: (fileId: string) => any validateMediaFile: (fileId: string) => Promise getProcessingCapabilities: () => any } // Глобальная переменная для доступа к системе обработки медиа let mediaProcessingSystemAccess: MediaProcessingSystemAccess | null = null /** * Устанавливает доступ к системе обработки медиа */ export function setMediaProcessingSystemAccess(access: MediaProcessingSystemAccess | null) { mediaProcessingSystemAccess = access } /** * Выполняет media processing инструмент */ export async function executeMediaProcessingTool( toolName: string, input: Record, ): Promise { try { switch (toolName) { case "analyze_media_quality": return await analyzeMediaQuality(input) case "optimize_media_compression": return await optimizeMediaCompression(input) case "convert_media_formats": return await convertMediaFormats(input) case "repair_corrupted_media": return await repairCorruptedMedia(input) case "batch_process_media": return await batchProcessMedia(input) case "create_media_derivatives": return await createMediaDerivatives(input) default: return { success: false, message: `Неизвестный media processing инструмент: ${toolName}`, errors: [`Инструмент ${toolName} не найден`], } } } catch (error) { return { success: false, message: `Ошибка выполнения media processing инструмента ${toolName}: ${error instanceof Error ? error.message : String(error)}`, errors: [error instanceof Error ? error.message : String(error)], } } } // Заглушки для функций (в реальной реализации они будут полностью развернуты) async function analyzeMediaQuality(_input: Record): Promise { return { success: true, message: "Media quality analyzed", data: { qualityAnalysis: {} } } } async function optimizeMediaCompression(_input: Record): Promise { return { success: true, message: "Media compression optimized", data: { compressionResults: {} } } } async function convertMediaFormats(_input: Record): Promise { return { success: true, message: "Media formats converted", data: { conversionResults: {} } } } async function repairCorruptedMedia(_input: Record): Promise { return { success: true, message: "Corrupted media repaired", data: { repairResults: {} } } } async function batchProcessMedia(_input: Record): Promise { return { success: true, message: "Batch processing completed", data: { batchResults: {} } } } async function createMediaDerivatives(_input: Record): Promise { return { success: true, message: "Media derivatives created", data: { derivativeFiles: [] } } }