-
-
Notifications
You must be signed in to change notification settings - Fork 297
feat: Add LLM-powered file generator tool #326
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
feat: Add LLM-powered file generator tool #326
Conversation
|
@mrjasonroy is attempting to deploy a commit to the cgoinglove's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
great work, thx. pulled into my project :) |
|
There’s no UI available to toggle that tool on or off. |
Yeah, this was tough because the image UI is separate from the regular tools. I wanted to make this a regular tool but it didn't fit there as well either. I was really trying to repeat what the chat applications from the providers have - they generate files out of the box, so, I wanted to support it as well here. Let me see if I can sneak it into a regular tool, it didn't feel right adding another option on the bottom |
Add a new file-generator tool that allows LLMs to create and save downloadable files. The tool supports various file formats including CSV, JSON, XML, code files, and more. Features: - Generate 1-5 files per invocation with custom content - Automatic MIME type inference from file extensions - Upload to S3/Vercel Blob storage with presigned URLs - Clean UI component with file metadata display - Download functionality with proper filenames - Supports multiple file formats (CSV, JSON, XML, YAML, code files, etc.) Implementation follows the existing image-manager tool pattern: - Server-side file generation and upload - Streaming of download URLs to client - Custom tool invocation UI component - Integration with existing file storage infrastructure 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Add 25 unit tests covering: - MIME type inference for 17 file extensions (CSV, JSON, XML, code files, etc.) - File upload functionality with Buffer conversion - Presigned URL support and fallback to sourceUrl - Multiple file uploads in parallel - Result format validation with file metadata - Error handling for upload failures All tests pass with 100% coverage of core functionality. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
- Add explicit logging to track presigned URL generation - Remove fallback to sourceUrl to ensure presigned URLs are always used - Add file generation capability to system prompts for all models - Update tool description to prevent LLMs from including raw URLs in responses - Add guide field to tool result for better user messaging This ensures all file downloads work correctly with private S3 buckets and improves model awareness of file generation capabilities. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
getDownloadUrl() can return string | null, need to handle null case to fix TypeScript error in build. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
- Fix module mock setup by moving mock definitions before imports - Use direct mock function references instead of vi.mocked() - Fix type import syntax error - Update test assertions to use toMatchObject for partial matching - Add guide field assertion in result format tests All 25 file-generator tests now pass successfully. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
TypeScript couldn't infer the return type from fileGeneratorTool.execute since it could be undefined. Instead of using ReturnType, define the FileGeneratorToolResult type inline in the test file. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Converts file-generator from always-on to a toggleable tool that users can enable/disable in the Tools dropdown, following the same pattern as other default tools like code execution. Changes: - Add FileGenerator to AppDefaultToolkit enum - Register file-generator in APP_DEFAULT_TOOL_KIT - Remove file-generator from always-on tools in chat route - Add File Generator option to tool selector UI with file icon - Add translation for "File Generator" label - Remove file-generator references from system prompts Users can now enable/disable file generation via the Tools dropdown in the chat interface. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Automatically enables the file-generator tool by default if file storage (Vercel Blob or S3) is properly configured. This provides a better out-of-box experience while maintaining the ability for users to toggle it off if desired. Changes: - Add isFileStorageConfigured() helper to detect storage setup - Create /api/storage/config endpoint to expose storage status - Add FileStorageInitializer component to auto-enable tool on mount - Update app layout to include storage initializer - Add comment in store about dynamic FileGenerator addition The tool is now enabled by default when: - BLOB_READ_WRITE_TOKEN is set (Vercel Blob), OR - FILE_STORAGE_TYPE=s3 and FILE_STORAGE_S3_BUCKET are set (S3) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
The middleware.ts file was missing from cn/main branch, causing /admin to return 404 instead of redirecting to /admin/users. This restores the middleware from main branch. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
025e9dc to
b8b1692
Compare
|
@cgoinglove, ok added a toggle! will be enabled by default if you have storage setup |

Summary
Adds a new
file-generatortool that enables LLMs to create and save downloadable files in various formats. Updated: The tool is now toggleable in the UI and automatically enabled by default when file storage is configured.Features
Implementation Details
The tool now follows the same pattern as other default tools (code executor, visualization, web search):
AppDefaultToolkitenum, can be toggled in UIUser Experience
When storage is configured (Vercel Blob or S3):
When storage is NOT configured:
Files Changed
Core file-generator implementation:
src/lib/ai/tools/file-generator/index.ts- Core tool (148 lines)src/lib/ai/tools/file-generator/index.test.ts- Unit tests (405 lines, 25 tests)src/components/tool-invocation/file-generator.tsx- UI component (159 lines)Tool system integration:
src/lib/ai/tools/index.ts- Added FileGenerator to AppDefaultToolkit enumsrc/lib/ai/tools/tool-kit.ts- Registered in APP_DEFAULT_TOOL_KITsrc/app/api/chat/route.ts- Removed from always-on tools, now conditionalsrc/components/tool-select-dropdown.tsx- Added File Generator option with iconsrc/components/message-parts.tsx- Tool rendering integrationAuto-enable functionality:
src/lib/file-storage/is-storage-configured.ts- Storage detection helpersrc/app/api/storage/config/route.ts- API endpoint for storage statussrc/components/file-storage-initializer.tsx- Auto-enable componentsrc/app/layout.tsx- Integrated initializer in app rootsrc/app/store/index.ts- Updated default toolkit commentTranslations:
messages/en.json- Added "File Generator" labelSystem prompts:
src/lib/ai/prompts.ts- Removed file-generator from always-available mentionsExample Use Cases
Testing
Technical Notes
BLOB_READ_WRITE_TOKENorFILE_STORAGE_TYPE=s3+ bucket configMigration Notes