From 26ab3e066f1d18a1ffa36af3e60db7f4cf42d24b Mon Sep 17 00:00:00 2001 From: Shantur Rathore Date: Fri, 24 Oct 2025 00:47:02 +0100 Subject: [PATCH] Fix file attachment API format and duplicate attachments - Add required 'url' field to file parts in API request - Use url, mime, filename instead of path field - Prevent duplicate attachments by checking if path already exists - Show all files when picker opens with empty query (use space as query) - Filter git files only when search query provided - Enter key now works correctly when file list has items --- src/components/file-picker.tsx | 18 +++++++----------- src/components/prompt-input.tsx | 10 ++++++++-- src/stores/sessions.ts | 3 ++- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/components/file-picker.tsx b/src/components/file-picker.tsx index 67f66f2f..a1f30a94 100644 --- a/src/components/file-picker.tsx +++ b/src/components/file-picker.tsx @@ -78,16 +78,10 @@ const FilePicker: Component = (props) => { const gitFiles = cachedGitFiles() console.log(`[FilePicker] Using ${gitFiles.length} cached git files`) - if (!searchQuery) { - console.log(`[FilePicker] No search query, showing ${gitFiles.length} git files`) - setFiles(gitFiles) - setSelectedIndex(0) - setLoading(false) - return - } - - console.log(`[FilePicker] Searching files with query: "${searchQuery}"`) - const searchResponse = await props.instanceClient.find.files({ query: { query: searchQuery } }) + console.log(`[FilePicker] Searching files with query: "${searchQuery || "(empty)"}"`) + const searchResponse = await props.instanceClient.find.files({ + query: { query: searchQuery || " " }, + }) const elapsed = Date.now() - startTime console.log(`[FilePicker] Search response received in ${elapsed}ms:`, searchResponse) @@ -99,7 +93,9 @@ const FilePicker: Component = (props) => { isGitFile: false, })) - const filteredGitFiles = gitFiles.filter((f) => f.path.toLowerCase().includes(searchQuery.toLowerCase())) + const filteredGitFiles = searchQuery + ? gitFiles.filter((f) => f.path.toLowerCase().includes(searchQuery.toLowerCase())) + : gitFiles const allFiles = [...filteredGitFiles, ...searchFiles] console.log( diff --git a/src/components/prompt-input.tsx b/src/components/prompt-input.tsx index 5621de5c..05220355 100644 --- a/src/components/prompt-input.tsx +++ b/src/components/prompt-input.tsx @@ -161,8 +161,14 @@ export default function PromptInput(props: PromptInputProps) { function handleFileSelect(path: string) { const filename = path.split("/").pop() || path - const attachment = createFileAttachment(path, filename) - addAttachment(props.instanceId, props.sessionId, attachment) + + const existingAttachments = attachments() + const alreadyAttached = existingAttachments.some((att) => att.source.type === "file" && att.source.path === path) + + if (!alreadyAttached) { + const attachment = createFileAttachment(path, filename) + addAttachment(props.instanceId, props.sessionId, attachment) + } const currentPrompt = prompt() const pos = atPosition() diff --git a/src/stores/sessions.ts b/src/stores/sessions.ts index 92e3bf57..bc2c3a7d 100644 --- a/src/stores/sessions.ts +++ b/src/stores/sessions.ts @@ -652,8 +652,9 @@ async function sendMessage( if (source.type === "file") { parts.push({ type: "file" as const, - path: source.path, + url: att.url, mime: source.mime, + filename: att.filename, }) } else if (source.type === "text") { parts.push({