Stirling-PDF/frontend/src/utils/toolOperationTracker.ts
Reece Browne dcadada7d3 feat: Implement shared hooks for tool operations
- Introduced `useToolApiCalls` for handling API calls with file processing and cancellation support.
- Created `useToolOperation` to manage tool operations, including state management, error handling, and file processing.
- Added `useToolResources` for managing blob URLs and generating thumbnails.
- Developed `useToolState` for centralized state management of tool operations.
- Refactored `useSplitOperation` to utilize the new shared hooks, simplifying the execution of split operations.
- Updated `useSplitParameters` to remove mode state and integrate with the new parameter structure.
- Enhanced error handling with `toolErrorHandler` utilities for standardized error extraction and messaging.
- Implemented `toolOperationTracker` for creating operation tracking data for file context integration.
- Added `toolResponseProcessor` for processing API response blobs based on handler configuration.
2025-08-04 11:59:32 +01:00

28 lines
869 B
TypeScript

import { FileOperation } from '../types/fileContext';
/**
* Creates operation tracking data for FileContext integration
*/
export const createOperation = <TParams = void>(
operationType: string,
params: TParams,
selectedFiles: File[]
): { operation: FileOperation; operationId: string; fileId: string } => {
const operationId = `${operationType}-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
const fileId = selectedFiles.map(f => f.name).join(',');
const operation: FileOperation = {
id: operationId,
type: operationType,
timestamp: Date.now(),
fileIds: selectedFiles.map(f => f.name),
status: 'pending',
metadata: {
originalFileName: selectedFiles[0]?.name,
parameters: params,
fileSize: selectedFiles.reduce((sum, f) => sum + f.size, 0)
}
};
return { operation, operationId, fileId };
};