From 71445a96542bfc677ab1a788d0e370c64da1165f Mon Sep 17 00:00:00 2001 From: Chandrapal Badshah <12944530+Chan9390@users.noreply.github.com> Date: Tue, 6 May 2025 17:46:27 +0530 Subject: [PATCH] Nudge users to add OpenAI key --- ui/app/(prowler)/lighthouse/chat.tsx | 29 ++++++++++++++++++++++++++-- ui/app/(prowler)/lighthouse/page.tsx | 7 +++++-- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/ui/app/(prowler)/lighthouse/chat.tsx b/ui/app/(prowler)/lighthouse/chat.tsx index 201f49c038..f47916c454 100644 --- a/ui/app/(prowler)/lighthouse/chat.tsx +++ b/ui/app/(prowler)/lighthouse/chat.tsx @@ -1,6 +1,7 @@ "use client"; import { useChat } from "@ai-sdk/react"; +import Link from "next/link"; import { useEffect, useRef } from "react"; import { MemoizedMarkdown } from "@/components/memoized-markdown"; @@ -12,7 +13,11 @@ interface SuggestedAction { action: string; } -export default function Chat() { +interface ChatProps { + hasApiKey: boolean; +} + +export default function Chat({ hasApiKey }: ChatProps) { const { messages, input, handleSubmit, handleInputChange, append, status } = useChat({ api: "/api/lighthouse/analyst", @@ -82,7 +87,27 @@ export default function Chat() { }; return ( -
+
+ {!hasApiKey && ( +
+
+

+ OpenAI API Key Required +

+

+ Please configure your OpenAI API key to use the Lighthouse Cloud + Security Analyst. +

+ + Configure API Key + +
+
+ )} + {messages.length === 0 ? (
diff --git a/ui/app/(prowler)/lighthouse/page.tsx b/ui/app/(prowler)/lighthouse/page.tsx index 8c27686aef..4de467dec6 100644 --- a/ui/app/(prowler)/lighthouse/page.tsx +++ b/ui/app/(prowler)/lighthouse/page.tsx @@ -1,11 +1,14 @@ +import { getAIKey } from "@/actions/lighthouse/lighthouse"; import { ContentLayout } from "@/components/ui"; import Chat from "./chat"; -export default function AIChatbot() { +export default async function AIChatbot() { + const apiKey = await getAIKey(); + return ( - + ); }