open, interoperable sandbox platform for agents and humans 📦 ✨ pocketenv.io
claude-code atproto sandbox openclaw agent
at main 79 lines 2.0 kB view raw
1import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"; 2import { 3 addVariable, 4 deleteVariable, 5 getVariable, 6 getVariables, 7 updateVariable, 8} from "../api/variable"; 9 10export const useAddVariableMutation = () => { 11 const queryClient = useQueryClient(); 12 return useMutation({ 13 mutationKey: ["addVariable"], 14 mutationFn: async ({ 15 sandboxId, 16 name, 17 value, 18 }: { 19 sandboxId: string; 20 name: string; 21 value: string; 22 }) => addVariable(sandboxId, name, value), 23 onSuccess: () => { 24 queryClient.invalidateQueries({ queryKey: ["variables"] }); 25 }, 26 }); 27}; 28 29export const useDeleteVariableMutation = () => { 30 const queryClient = useQueryClient(); 31 return useMutation({ 32 mutationKey: ["deleteVariable"], 33 mutationFn: async (id: string) => deleteVariable(id), 34 onSuccess: () => { 35 queryClient.invalidateQueries({ queryKey: ["variables"] }); 36 }, 37 }); 38}; 39 40export const useVariablesQuery = ( 41 sandboxId?: string, 42 offset?: number, 43 limit?: number, 44) => 45 useQuery({ 46 queryKey: ["variables", sandboxId, offset, limit], 47 queryFn: async () => getVariables(sandboxId, offset, limit), 48 select: (response) => response.data, 49 }); 50 51export const useVariableQuery = (id: string) => 52 useQuery({ 53 queryKey: ["variable", id], 54 queryFn: () => getVariable(id), 55 select: (response) => response.data, 56 enabled: !!id, 57 }); 58 59export const useUpdateVariableMutation = () => { 60 const queryClient = useQueryClient(); 61 return useMutation({ 62 mutationKey: ["updateVariable"], 63 mutationFn: async ({ 64 id, 65 name, 66 value, 67 sandboxId, 68 }: { 69 id: string; 70 name: string; 71 value: string; 72 sandboxId: string; 73 }) => updateVariable(id, name, value, sandboxId), 74 onSuccess: (_, { id }) => { 75 queryClient.invalidateQueries({ queryKey: ["variable", id] }); 76 queryClient.invalidateQueries({ queryKey: ["variables"] }); 77 }, 78 }); 79};