Fix file path format and initialization issues

- Remove leading slash from file paths (use relative paths from workspace)
- Server expects relative paths like 'file.md' not '/file.md'
- Convert isInitialized from let to signal to persist across renders
- Fix file picker not showing files on first open
- Paths from find.files() are already relative to workspace
This commit is contained in:
Shantur Rathore
2025-10-24 00:50:30 +01:00
parent 26ab3e066f
commit b6dc4ba249
2 changed files with 6 additions and 7 deletions

View File

@@ -22,6 +22,7 @@ const FilePicker: Component<FilePickerProps> = (props) => {
const [selectedIndex, setSelectedIndex] = createSignal(0)
const [loading, setLoading] = createSignal(false)
const [cachedGitFiles, setCachedGitFiles] = createSignal<FileItem[]>([])
const [isInitialized, setIsInitialized] = createSignal(false)
let containerRef: HTMLDivElement | undefined
let gitFilesFetched = false
@@ -113,15 +114,14 @@ const FilePicker: Component<FilePickerProps> = (props) => {
}
let lastQuery = ""
let isInitialized = false
createEffect(() => {
console.log(
`[FilePicker] Effect triggered - open: ${props.open}, query: "${props.searchQuery}", gitFilesFetched: ${gitFilesFetched}, isInitialized: ${isInitialized}`,
`[FilePicker] Effect triggered - open: ${props.open}, query: "${props.searchQuery}", gitFilesFetched: ${gitFilesFetched}, isInitialized: ${isInitialized()}`,
)
if (props.open && !isInitialized) {
isInitialized = true
if (props.open && !isInitialized()) {
setIsInitialized(true)
console.log("[FilePicker] First open - fetching git files and initial files")
fetchGitFiles()
fetchFiles(props.searchQuery)

View File

@@ -53,17 +53,16 @@ export function createFileAttachment(
mime: string = "text/plain",
data?: Uint8Array,
): Attachment {
const absolutePath = path.startsWith("/") ? path : `/${path}`
return {
id: crypto.randomUUID(),
type: "file",
display: `@${filename}`,
url: `file://${absolutePath}`,
url: path,
filename,
mediaType: mime,
source: {
type: "file",
path: absolutePath,
path: path,
mime,
data,
},