Skip to content

Conversation

@jmacAJ
Copy link
Contributor

@jmacAJ jmacAJ commented Dec 21, 2025

This pull request enhances the Cortex File Handler's support for converted files by ensuring that both the original and converted files have proper short-lived URLs and MIME type information in responses, while keeping persistent storage clean of transient data. It also updates tests to verify these behaviors and improves file parsing logic to prefer converted file data when available.

Short-lived URL and MIME type handling for converted files:

  • Added generation of shortLivedUrl and detection of mimeType for converted files in both upload and file handler logic, ensuring these are included in API responses but not persisted to Redis. [1] [2] [3] [4] [5] [6] [7]

API response consistency and code improvements:

  • Ensured that the API response always includes a converted block (when available) with url, shortLivedUrl, gcs, and mimeType fields, and clarified the distinction between original and converted file URLs in the response. [1] [2]

Testing enhancements:

  • Added a new test verifying that the upload response includes a shortLivedUrl for the converted file and that it points to the correct file type.

File parsing improvements:

  • Updated file parsing logic to prefer the converted file's URL, GCS, and MIME type when present, marking such files as converted for downstream logic.

Dependency and version updates:

  • Bumped the package version to 2.8.0 and added the mime-types import where necessary. [1] [2] [3] [4]

- Implemented functionality to generate short-lived URLs for converted files during the upload process.
- Updated response structure to include `shortLivedUrl` for both original and converted files, allowing for flexible use cases.
- Enhanced error handling to log warnings if short-lived URL generation fails, ensuring fallback to regular URLs.
- Added comprehensive tests to verify the presence and correctness of `shortLivedUrl` in upload responses, ensuring robust functionality for file handling.
- Added functionality to determine and attach the MIME type of converted files based on their URLs during the upload process.
- Updated response structure to include `mimeType` for both original and converted files, ensuring accurate content type representation.
- Improved error handling for URL parsing to ensure robust MIME type extraction, enhancing overall file handling capabilities.
- Updated `parseRawFileData` to prioritize converted values (URL, GCS, mimeType) when available, ensuring accurate representation of processed content.
- Implemented checks to prevent editing of converted files, providing clear error messages to users attempting to modify them.
- Added tests to verify that file collection correctly uses converted values and enforces editing restrictions on converted files, enhancing overall file management capabilities.
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request enhances converted file handling in the Cortex File Handler by ensuring proper short-lived URLs and MIME type information for both original and converted files in API responses, while keeping Redis storage clean of transient data.

  • Adds short-lived URL generation for converted files alongside original files in upload and checkHash responses
  • Implements MIME type detection for converted files based on file extensions
  • Updates file parsing logic to prefer converted file data (URL, GCS, MIME type) as primary values when available while preserving original displayFilename
  • Prevents persistence of transient shortLivedUrl fields to Redis storage

Reviewed changes

Copilot reviewed 12 out of 13 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
helper-apps/cortex-file-handler/src/blobHandler.js Adds short-lived URL and MIME type generation for converted files in both busboy and uploadFile flows
helper-apps/cortex-file-handler/src/index.js Implements short-lived URL generation for converted files in checkHash operations with MIME type detection
helper-apps/cortex-file-handler/src/redis.js Removes shortLivedUrl fields before persisting to Redis to keep storage clean of transient data
helper-apps/cortex-file-handler/src/services/storage/StorageService.js Adds mimeType field to converted file responses in retention update operations
lib/fileUtils.js Updates parseRawFileData to prefer converted values, adds getActualContentMimeType utility, enhances isTextMimeType detection, and updates file resolution logic
pathways/system/entity/tools/sys_tool_readfile.js Expands KNOWN_TEXT_EXTENSIONS set with comprehensive list of code file extensions for better text file detection
pathways/system/entity/tools/sys_tool_editfile.js Adds converted file edit prevention and uses getActualContentMimeType for proper MIME type determination
tests/unit/core/shortLivedUrl.test.js Updates test expectations to verify converted.shortLivedUrl preference in URL resolution
tests/unit/core/fileCollection.test.js Adds comprehensive tests for MIME type detection from URLs vs displayFilename
tests/integration/features/tools/fileCollection.test.js Adds integration tests verifying converted file handling across multiple scenarios
helper-apps/cortex-file-handler/tests/shortLivedUrlConversion.test.js Adds test verifying upload response includes shortLivedUrl for converted files
helper-apps/cortex-file-handler/package.json Bumps version to 2.8.0
helper-apps/cortex-file-handler/package-lock.json Updates version lock to 2.8.0
Files not reviewed (1)
  • helper-apps/cortex-file-handler/package-lock.json: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

import logger from '../../../../lib/logger.js';
import { axios } from '../../../../lib/requestExecutor.js';
import { uploadFileToCloud, findFileInCollection, loadFileCollection, getMimeTypeFromFilename, resolveFileParameter, deleteFileByHash, isTextMimeType, updateFileMetadata, writeFileDataToRedis, invalidateFileCollectionCache } from '../../../../lib/fileUtils.js';
import { uploadFileToCloud, findFileInCollection, loadFileCollection, getMimeTypeFromFilename, resolveFileParameter, deleteFileByHash, isTextMimeType, updateFileMetadata, writeFileDataToRedis, invalidateFileCollectionCache, getActualContentMimeType } from '../../../../lib/fileUtils.js';
Copy link

Copilot AI Dec 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused import resolveFileParameter.

Suggested change
import { uploadFileToCloud, findFileInCollection, loadFileCollection, getMimeTypeFromFilename, resolveFileParameter, deleteFileByHash, isTextMimeType, updateFileMetadata, writeFileDataToRedis, invalidateFileCollectionCache, getActualContentMimeType } from '../../../../lib/fileUtils.js';
import { uploadFileToCloud, findFileInCollection, loadFileCollection, getMimeTypeFromFilename, deleteFileByHash, isTextMimeType, updateFileMetadata, writeFileDataToRedis, invalidateFileCollectionCache, getActualContentMimeType } from '../../../../lib/fileUtils.js';

Copilot uses AI. Check for mistakes.
@jmacAJ jmacAJ merged commit d080ca4 into main Dec 21, 2025
1 check passed
@jmacAJ jmacAJ deleted the jmac_fix_converted_files branch December 21, 2025 17:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants