open, interoperable sandbox platform for agents and humans 📦 ✨
pocketenv.io
claude-code
atproto
sandbox
openclaw
agent
1import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
2import {
3 addFile,
4 deleteFile,
5 getFile,
6 getFiles,
7 updateFile,
8} from "../api/file";
9
10export const useAddFileMutation = () => {
11 const queryClient = useQueryClient();
12 return useMutation({
13 mutationKey: ["addFile"],
14 mutationFn: async ({
15 sandboxId,
16 path,
17 content,
18 }: {
19 sandboxId: string;
20 path: string;
21 content: string;
22 }) => addFile(sandboxId, path, content),
23 onSuccess: () => {
24 queryClient.invalidateQueries({ queryKey: ["files"] });
25 },
26 });
27};
28
29export const useDeleteFileMutation = () => {
30 const queryClient = useQueryClient();
31 return useMutation({
32 mutationKey: ["deleteFile"],
33 mutationFn: async (id: string) => deleteFile(id),
34 onSuccess: () => {
35 queryClient.invalidateQueries({ queryKey: ["files"] });
36 },
37 });
38};
39
40export const useFilesQuery = (
41 sandboxId?: string,
42 offset?: number,
43 limit?: number,
44) =>
45 useQuery({
46 queryKey: ["files", sandboxId, offset, limit],
47 queryFn: () => getFiles(sandboxId, offset, limit),
48 select: (response) => response.data,
49 });
50
51export const useFileQuery = (id: string) =>
52 useQuery({
53 queryKey: ["file", id],
54 queryFn: () => getFile(id),
55 select: (response) => response.data,
56 enabled: !!id,
57 });
58
59export const useUpdateFileMutation = () => {
60 const queryClient = useQueryClient();
61 return useMutation({
62 mutationKey: ["updateFile"],
63 mutationFn: async ({
64 id,
65 path,
66 content,
67 }: {
68 id: string;
69 path: string;
70 content: string;
71 }) => updateFile(id, path, content),
72 onSuccess: (_, { id }) => {
73 queryClient.invalidateQueries({ queryKey: ["files"] });
74 queryClient.invalidateQueries({ queryKey: ["file", id] });
75 },
76 });
77};