Download src/hooks/query/use-plugin-file-content.ts from SaylorTwift/openhands: direct link, hf CLI and curl.
- Browser
- Download file 1.07 kB
-
https://huggingface.co/SaylorTwift/openhands/resolve/main/src/hooks/query/use-plugin-file-content.ts
- Command line
-
hf download hf://SaylorTwift/openhands/src/hooks/query/use-plugin-file-content.ts
-
curl -L -o use-plugin-file-content.ts https://huggingface.co/SaylorTwift/openhands/resolve/main/src/hooks/query/use-plugin-file-content.ts
1.07 kB
| import { useQuery } from "@tanstack/react-query"; | |
| import { useActiveBackend } from "#/contexts/active-backend-context"; | |
| import PluginsService, { type PluginFileContent } from "#/api/plugins-service"; | |
| /** | |
| * Query hook for one plugin file's content, shown in the plugin detail | |
| * modal's file viewer. Disabled until a file is selected. Local backend only | |
| * (on cloud the plugins page carries no contents, so this never fires). | |
| */ | |
| export const usePluginFileContent = ( | |
| basePath: string | null, | |
| relativePath: string | null, | |
| ) => { | |
| const { backend, orgId } = useActiveBackend(); | |
| return useQuery<PluginFileContent>({ | |
| queryKey: [ | |
| "plugin-file-content", | |
| basePath, | |
| relativePath, | |
| backend.id, | |
| orgId, | |
| ], | |
| queryFn: () => { | |
| if (!basePath || !relativePath) throw new Error("No file selected"); | |
| return PluginsService.getPluginFileContent(basePath, relativePath); | |
| }, | |
| enabled: Boolean(basePath && relativePath), | |
| retry: false, | |
| staleTime: 1000 * 60 * 10, // 10 minutes | |
| refetchOnWindowFocus: false, | |
| }); | |
| }; | |