Skip to content

Commit

Permalink
Linked json generated file to supabase
Browse files Browse the repository at this point in the history
  • Loading branch information
minhanhld committed Feb 13, 2025
1 parent feb3948 commit a97d264
Show file tree
Hide file tree
Showing 4 changed files with 175 additions and 1 deletion.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"@radix-ui/react-dialog": "^1.1.6",
"@radix-ui/react-toast": "^1.2.6",
"@radix-ui/react-tooltip": "^1.1.8",
"@supabase/supabase-js": "^2.48.1",
"@types/react-syntax-highlighter": "^15.5.13",
"class-variance-authority": "^0.7.1",
"clsx": "^2.1.1",
Expand Down
150 changes: 150 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 18 additions & 1 deletion src/app/create-agent/components/AgentForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { useToast } from "@/hooks/use-toast";
import { AgentData } from "../types/agent";
import { v4 as uuidv4 } from "uuid";
import { allPlugins } from "../../../../data/plugins";
import { supabase } from "@/lib/supabase";

const AgentForm = () => {
const { toast } = useToast();
Expand Down Expand Up @@ -77,7 +78,7 @@ const AgentForm = () => {
[formData, setFormData],
);

const handleSubmit = () => {
const handleSubmit = async () => {
const selectedPluginIds = formData.plugins;
const internal_plugins: string[] = [];
const external_plugins: string[] = [];
Expand All @@ -97,6 +98,7 @@ const AgentForm = () => {

// Format the data
try {
const agent_id = uuidv4();
const agentConfig = {
name: formData.name,
bio: formData.bio,
Expand All @@ -109,6 +111,21 @@ const AgentForm = () => {
internal_plugins,
};

// Save to Supabase with our generated ID
const { error } = await supabase.from("agents").insert({
id: agent_id,
config: agentConfig,
});

if (error) throw error;

// Show success message with the agent ID we generated
toast({
title: "Success!",
description: `Agent created successfully! Your agent ID is: ${agent_id}`,
duration: 5000,
});

// Create a Blob containing the JSON data
const jsonString = JSON.stringify(agentConfig, null, 2);
const blob = new Blob([jsonString], { type: "application/json" });
Expand Down
6 changes: 6 additions & 0 deletions src/lib/supabase.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { createClient } from "@supabase/supabase-js";

const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL!;
const supabaseKey = process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!;

export const supabase = createClient(supabaseUrl, supabaseKey);

0 comments on commit a97d264

Please sign in to comment.