fix(desktop): pass file attachments through PromptInput onSubmit#3334
fix(desktop): pass file attachments through PromptInput onSubmit#3334
Conversation
…back handlePromptSubmit was ignoring the message argument from PromptInput, causing file attachments to be lost when submitting via Enter. Now converts the already-available FileUIParts and passes them directly to handleCreate, skipping the redundant takeFiles() path.
📝 WalkthroughWalkthroughThe PromptGroup component's file-handling flow was changed so Changes
Sequence Diagram(s)(omitted) Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Greptile SummaryThis PR fixes a bug in
Confidence Score: 5/5Safe to merge — the fix is correct and the change is isolated to one callback in one file. The fix correctly addresses the root cause: No files require special attention beyond the reviewed Important Files Changed
Sequence DiagramsequenceDiagram
participant User
participant PromptInput
participant handlePromptSubmit
participant handleCreate
participant Agent as AgentLaunchRequest
Note over User,Agent: Enter key path (FIXED)
User->>PromptInput: Press Enter (with files attached)
PromptInput->>PromptInput: Convert blob URLs to data URLs
PromptInput->>handlePromptSubmit: onSubmit({ text, files: FileUIPart[] })
handlePromptSubmit->>handlePromptSubmit: Map files to ConvertedFile[]
handlePromptSubmit->>handleCreate: handleCreate(convertedFiles)
handleCreate->>Agent: buildLaunchRequest(prompt, convertedFiles)
Note over User,Agent: Ctrl/Cmd+Enter path (unchanged)
User->>handleCreate: keydown handler calls handleCreate()
handleCreate->>handleCreate: attachments.takeFiles() returns blob URLs
handleCreate->>handleCreate: convertBlobUrlToDataUrl() per file
handleCreate->>Agent: buildLaunchRequest(prompt, convertedFiles)
|
| const handlePromptSubmit = useCallback( | ||
| (message: { files: Array<{ url: string; mediaType: string; filename?: string }> }) => { | ||
| const converted: ConvertedFile[] = message.files | ||
| .filter((f) => f.url) | ||
| .map((f) => ({ | ||
| data: f.url, | ||
| mediaType: f.mediaType, | ||
| filename: f.filename, | ||
| })); | ||
| void handleCreate(converted.length > 0 ? converted : undefined); | ||
| }, | ||
| [handleCreate], | ||
| ); |
There was a problem hiding this comment.
Use exported
PromptInputMessage type instead of inline structural type
The callback's inline parameter type { files: Array<{ url: string; mediaType: string; filename?: string }> } duplicates the structure of the already-exported PromptInputMessage type from @superset/ui/ai-elements/prompt-input. The existing import list at the top of the file imports several members from that module — adding PromptInputMessage here would be more type-safe and consistent.
Note that filename on FileUIPart is not part of the official SDK type; it's an extra field added at object-creation time in prompt-input.tsx. Referencing it through the informal inline type works at runtime (the field is present via the spread in the blob-URL conversion), but using the authoritative imported type makes the dependency explicit.
Or simply add PromptInputMessage to the existing import from @superset/ui/ai-elements/prompt-input.
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
🧹 Preview Cleanup CompleteThe following preview resources have been cleaned up:
Thank you for your contribution! 🎉 |
…erset-sh#3334) * fix(desktop): pass file attachments through PromptInput onSubmit callback handlePromptSubmit was ignoring the message argument from PromptInput, causing file attachments to be lost when submitting via Enter. Now converts the already-available FileUIParts and passes them directly to handleCreate, skipping the redundant takeFiles() path. * style(desktop): format PromptGroup with biome
Summary
handlePromptSubmitwas ignoring themessageargument fromPromptInput'sonSubmit, so file attachments were lost when submitting via Entermessage.files(already-availableFileUIPart[]) intoConvertedFile[]and passes them directly tohandleCreate, bypassing the redundantattachments.takeFiles()pathTest plan
Summary by cubic
Fixes lost attachments when submitting the New Workspace modal with Enter by wiring
PromptInput’sonSubmit(message)to pass files intohandleCreate. Convertsmessage.filestoConvertedFile[], skippingattachments.takeFiles()when provided; also formatsPromptGroupwith Biome.handleCreate(preConvertedFiles?)accepts pre-converted files to avoid duplicate detaching.Written for commit bfcb26f. Summary will update on new commits.
Summary by CodeRabbit