feat(ui): send finding context to Lighthouse chat

This commit is contained in:
alejandrobailo
2026-03-20 14:37:50 +01:00
parent 91fe7bc3c4
commit 895fb80ea5
3 changed files with 22 additions and 2 deletions

View File

@@ -10,7 +10,15 @@ import { ContentLayout } from "@/components/ui";
export const dynamic = "force-dynamic";
export default async function AIChatbot() {
export default async function AIChatbot({
searchParams,
}: {
searchParams: Promise<Record<string, string | string[] | undefined>>;
}) {
const params = await searchParams;
const initialPrompt =
typeof params.prompt === "string" ? params.prompt : undefined;
const hasConfig = await isLighthouseConfigured();
if (!hasConfig) {
@@ -33,6 +41,7 @@ export default async function AIChatbot() {
providers={providersConfig.providers}
defaultProviderId={providersConfig.defaultProviderId}
defaultModelId={providersConfig.defaultModelId}
initialPrompt={initialPrompt}
/>
</div>
</ContentLayout>

View File

@@ -608,7 +608,7 @@ export function ResourceDetailDrawerContent({
{/* Lighthouse AI button */}
<a
href="/lighthouse"
href={`/lighthouse?${new URLSearchParams({ prompt: `Analyze this security finding and provide remediation guidance:\n\n- **Finding**: ${checkMeta.checkTitle}\n- **Check ID**: ${checkMeta.checkId}\n- **Severity**: ${f?.severity ?? "unknown"}\n- **Status**: ${f?.status ?? "unknown"}${f?.statusExtended ? `\n- **Detail**: ${f.statusExtended}` : ""}${checkMeta.risk ? `\n- **Risk**: ${checkMeta.risk}` : ""}` }).toString()}`}
className="flex items-center gap-1.5 rounded-lg px-4 py-3 text-sm font-bold text-slate-950 transition-opacity hover:opacity-90"
style={{
background: "linear-gradient(96deg, #2EE59B 3.55%, #62DFF0 98.85%)",

View File

@@ -61,6 +61,7 @@ interface ChatProps {
providers: Provider[];
defaultProviderId?: LighthouseProvider;
defaultModelId?: string;
initialPrompt?: string;
}
interface SelectedModel {
@@ -102,6 +103,7 @@ export const Chat = ({
providers: initialProviders,
defaultProviderId,
defaultModelId,
initialPrompt,
}: ChatProps) => {
const { toast } = useToast();
@@ -306,6 +308,15 @@ export const Chat = ({
}
};
// Auto-send initial prompt from URL (e.g., finding context from drawer)
const initialPromptSentRef = useRef(false);
useEffect(() => {
if (initialPrompt && !initialPromptSentRef.current) {
initialPromptSentRef.current = true;
sendMessage({ text: initialPrompt });
}
}, [initialPrompt, sendMessage]);
// Handlers
const handleNewChat = () => {
setMessages([]);