Skip to content

AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.

feat(frontend) Remove "credentials" from export & import of agents (#9081)

Bently4f15da99f9a9
diff --git a/autogpt_platform/frontend/src/components/agent-import-form.tsx b/autogpt_platform/frontend/src/components/agent-import-form.tsx
index a17b9963e2..34808c27ae 100644
--- a/autogpt_platform/frontend/src/components/agent-import-form.tsx
+++ b/autogpt_platform/frontend/src/components/agent-import-form.tsx
@@ -15,7 +15,7 @@ import { Button } from "@/components/ui/button";
import { Switch } from "@/components/ui/switch";
import { Textarea } from "@/components/ui/textarea";
import { Graph, GraphCreatable } from "@/lib/autogpt-server-api";
-import { cn } from "@/lib/utils";
+import { cn, removeCredentials } from "@/lib/utils";
import { EnterIcon } from "@radix-ui/react-icons";
import { useBackendAPI } from "@/lib/autogpt-server-api/context";
@@ -150,6 +150,7 @@ export const AgentImportForm: React.FC<
);
}
const agent = obj as Graph;
+ removeCredentials(agent);
updateBlockIDs(agent);
setAgentObject(agent);
form.setValue("agentName", agent.name);
diff --git a/autogpt_platform/frontend/src/lib/utils.ts b/autogpt_platform/frontend/src/lib/utils.ts
index 5111198776..5f5d4683a5 100644
--- a/autogpt_platform/frontend/src/lib/utils.ts
+++ b/autogpt_platform/frontend/src/lib/utils.ts
@@ -120,9 +120,28 @@ const applyExceptions = (str: string): string => {
return str;
};
+/** Recursively remove all "credentials" properties from exported JSON files */
+export function removeCredentials(obj: any) {
+ if (obj && typeof obj === "object") {
+ if (Array.isArray(obj)) {
+ obj.forEach((item) => removeCredentials(item));
+ } else {
+ delete obj.credentials;
+ Object.values(obj).forEach((value) => removeCredentials(value));
+ }
+ }
+ return obj;
+}
+
export function exportAsJSONFile(obj: object, filename: string): void {
+ // Deep clone the object to avoid modifying the original
+ const sanitizedObj = JSON.parse(JSON.stringify(obj));
+
+ // Sanitize the object
+ removeCredentials(sanitizedObj);
+
// Create downloadable blob
- const jsonString = JSON.stringify(obj, null, 2);
+ const jsonString = JSON.stringify(sanitizedObj, null, 2);
const blob = new Blob([jsonString], { type: "application/json" });
const url = URL.createObjectURL(blob);