cc-haha/desktop/src/api/filesystem.ts
程序员阿江(Relakkes) ad4ba88a62 feat: add @-triggered file search popup with directory navigation
- Input @ in composer to open file search popup showing project root
- Filter files/directories by typing, navigate with keyboard or mouse
- Click directory to enter subdirectory, type / to navigate deeper
- Enter selects item and inserts path text at cursor, popup closes
- Parse filter path (e.g. @src/components/) to auto-navigate and search
- Desktop: filesystem browse/search API supports includeFiles and search
- Web: directory tree browser with real-time search filtering
2026-04-07 19:05:01 +08:00

31 lines
768 B
TypeScript

import { api } from './client'
type DirEntry = {
name: string
path: string
isDirectory: boolean
}
type BrowseResult = {
currentPath: string
parentPath: string
entries: DirEntry[]
query?: string
}
export const filesystemApi = {
browse(path?: string, options?: { includeFiles?: boolean }) {
const q = new URLSearchParams()
if (path) q.set('path', path)
if (options?.includeFiles) q.set('includeFiles', 'true')
const qs = q.toString()
return api.get<BrowseResult>(`/api/filesystem/browse${qs ? `?${qs}` : ''}`)
},
search(query: string, cwd?: string) {
const q = new URLSearchParams({ search: query, maxResults: '200' })
if (cwd) q.set('path', cwd)
return api.get<BrowseResult>(`/api/filesystem/browse?${q}`)
},
}