diff --git a/src/features/onboarding/actions/generate-edge-key.action.ts b/src/features/onboarding/actions/generate-edge-key.action.ts new file mode 100644 index 00000000..0be806e6 --- /dev/null +++ b/src/features/onboarding/actions/generate-edge-key.action.ts @@ -0,0 +1,14 @@ +"use server"; + +import { userAction } from "@/lib/safe-actions/actions"; +import { z } from "zod"; +import { generateEdgeKey } from "@/utils/edge_key"; +import { env } from "@/env.mjs"; + +export const generateEdgeKeyAction = userAction + .schema(z.object({ agentId: z.string() })) + .action(async ({ parsedInput }) => { + const serverUrl = env.PROJECT_URL ?? "http://localhost:8887"; + const key = await generateEdgeKey(serverUrl, parsedInput.agentId); + return { key }; + }); diff --git a/src/features/onboarding/steps/step-agent-key.tsx b/src/features/onboarding/steps/step-agent-key.tsx new file mode 100644 index 00000000..b2734b0a --- /dev/null +++ b/src/features/onboarding/steps/step-agent-key.tsx @@ -0,0 +1,62 @@ +"use client"; + +import { useOnboarding } from "@onboardjs/react"; +import { useQuery } from "@tanstack/react-query"; +import { Button } from "@/components/ui/button"; +import { Loader2 } from "lucide-react"; +import { CodeSnippet } from "@/components/common/code-snippet"; +import { generateEdgeKeyAction } from "@/features/onboarding/actions/generate-edge-key.action"; +import type { OnboardingAgent } from "@/features/onboarding/onboarding.types"; + +export const StepAgentKey = () => { + const { next, state } = useOnboarding(); + const agents = (state?.context.flowData.agents ?? []) as OnboardingAgent[]; + + return ( +
+
+

Connect your agent

+

+ Run the command below on your server. The next step waits for the agent to connect. +

+
+ {agents.map((agent) => ( + + ))} + +
+ ); +}; + +const AgentKeyBlock = ({ agent }: { agent: OnboardingAgent }) => { + const { data, isLoading } = useQuery({ + queryKey: ["edge-key", agent.id], + queryFn: async () => { + const result = await generateEdgeKeyAction({ agentId: agent.id }); + if (!result?.data?.key) throw new Error("Failed to generate key"); + return result.data.key; + }, + staleTime: Infinity, + }); + + if (isLoading) { + return ( +
+ + Generating key for {agent.name}… +
+ ); + } + + const command = `portabase agent "${agent.name}" --key ${data}`; + + return ( +
+

{agent.name}

+ + +
+ ); +};