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
This commit is contained in:
@@ -78,16 +78,10 @@ const FilePicker: Component<FilePickerProps> = (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<FilePickerProps> = (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(
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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({
|
||||
|
||||
Reference in New Issue
Block a user