A modern platform for visual, flexible, and extensible graph-based investigations. For cybersecurity analysts and investigators.
feat: chat context
dextmorgn87d550a40923
diff --git a/src/app/dashboard/layout.tsx b/src/app/dashboard/layout.tsxindex 23cd92e0..e5658558 100644--- a/src/app/dashboard/layout.tsx+++ b/src/app/dashboard/layout.tsx@@ -2,11 +2,12 @@ import type React from "react"import { createClient } from "@/src/lib/supabase/server"import { redirect } from "next/navigation"import Logo from "@/src/components/logo"-import { Box, Flex, ScrollArea, TextField, Text } from "@radix-ui/themes"+import { Box, Flex, ScrollArea, TextField, Text, IconButton } from "@radix-ui/themes"import NewCase from "@/src/components/dashboard/new-case"import { MagnifyingGlassIcon } from "@radix-ui/react-icons"import User from "@/src/components/user"import Link from "next/link"+import { PlusIcon } from 'lucide-react';const navigation = [{@@ -60,7 +61,11 @@ const DashboardLayout = async ({}}><Logo />- <NewCase />+ <NewCase>+ <IconButton color="gray" size="2" variant="soft">+ <PlusIcon className="h-5" />+ </IconButton>+ </NewCase></Box>{/* Left Panel Content */}diff --git a/src/app/dashboard/page.tsx b/src/app/dashboard/page.tsxindex 5437479e..f63a8aa2 100644--- a/src/app/dashboard/page.tsx+++ b/src/app/dashboard/page.tsx@@ -3,6 +3,7 @@ import { getInvestigations } from '@/src/lib/actions/investigations'import Investigation from '@/src/components/dashboard/investigation'import { Button, Flex } from '@radix-ui/themes'import { DownloadIcon, FolderIcon, PlusIcon } from 'lucide-react'+import NewCase from '@/src/components/dashboard/new-case'const DashboardPage = async () => {const { investigations, error } = await getInvestigations()@@ -16,7 +17,9 @@ const DashboardPage = async () => {</p></div><Flex gap="3">- <Button><PlusIcon className='h-4 w-4' />Create</Button>+ <NewCase>+ <Button><PlusIcon className='h-4 w-4' />Create</Button>+ </NewCase><Button color="gray" variant='soft'><DownloadIcon className='h-4 w-4' />Upload</Button><Button color="gray" variant='soft'><FolderIcon className='h-4 w-4' />Create organization</Button></Flex>diff --git a/src/components/contexts/chatbot-context.tsx b/src/components/contexts/chatbot-context.tsxindex 9cee40b9..1caa9bc8 100644--- a/src/components/contexts/chatbot-context.tsx+++ b/src/components/contexts/chatbot-context.tsx@@ -10,7 +10,7 @@ import ReactMarkdown from 'react-markdown'interface ChatContextType {open: boolean,- setOpen: any+ handleOpenChat: any}const ChatContext = createContext<ChatContextType | undefined>(undefined);@@ -21,16 +21,26 @@ interface ChatProviderProps {export const ChatProvider: React.FC<ChatProviderProps> = ({ children }) => {const [open, setOpen] = useState(false);+ // content is the object passed to the chat, as a secondary object+ const [content, setContent] = useState(false);const { messages, input, handleInputChange, handleSubmit, error, isLoading } = useChat();+ const handleOpenChat = (content: any) => {+ setContent(content)+ setOpen(true)+ }+return (- <ChatContext.Provider value={{ open, setOpen }}>+ <ChatContext.Provider value={{ open, handleOpenChat }}>{children}<Dialog.Root open={open} onOpenChange={setOpen}><Dialog.Content maxWidth={messages?.length > 0 ? "730px" : '480px'} className="w-full p-4"><Dialog.Title>Ask AI</Dialog.Title><Dialog.Description size="2" mb="4">Ask AI chat bot to help you understant patterns.</Dialog.Description>+ {/* <div>+ context: {content?.title || content?.full_name}+ </div> */}<Flex direction={"column"} gap="3" className=" overflow-y-auto w-full">{messages.map(m => (<Flex key={m.id} className='grow'>diff --git a/src/components/contexts/investigation-provider.tsx b/src/components/contexts/investigation-provider.tsxindex 272b6696..479885d2 100644--- a/src/components/contexts/investigation-provider.tsx+++ b/src/components/contexts/investigation-provider.tsx@@ -8,6 +8,8 @@ import { useInvestigation } from "@/src/lib/hooks/investigation/investigation";import { ThemeSwitch } from "../theme-switch";import { useConfirm } from "../use-confirm-dialog";import { supabase } from "@/src/lib/supabase/client";+import FloatingEdge from "../investigations/floating-edge";+import { cn } from "@/src/lib/utils";interface InvestigationContextType {filters: any,@@ -46,7 +48,8 @@ export const InvestigationProvider: React.FC<InvestigationProviderProps> = ({ chshowEdgeLabel: true,showMiniMap: true,showCopyIcon: true,- showNodeToolbar: true+ showNodeToolbar: true,+ floatingEdges: false});const createQueryString = useCallback(@@ -70,15 +73,15 @@ export const InvestigationProvider: React.FC<InvestigationProviderProps> = ({ ch}}- const SettingSwitch = ({ setting, value, title, description }: { setting: string, value: boolean, title: string, description: string }) => (- <div className="flex items-center justify-between gap-4">+ const SettingSwitch = ({ setting, value, title, description, disabled = false }: { setting: string, value: boolean, title: string, description: string, disabled?: boolean }) => (+ <div className={cn("flex items-center justify-between gap-4", disabled && 'opacity-60')}><div className="flex flex-col gap-1"><p className="font-medium">{title}</p><p className="opacity-70 text-sm">{description}</p></div>- <Switch checked={value} onCheckedChange={(val: boolean) => setSettings({ ...settings, [setting]: val })} />+ <Switch disabled={disabled} checked={value} onCheckedChange={(val: boolean) => setSettings({ ...settings, [setting]: val })} /></div>)return (@@ -96,6 +99,7 @@ export const InvestigationProvider: React.FC<InvestigationProviderProps> = ({ ch<SettingSwitch setting={"showMiniMap"} value={settings.showMiniMap} title={"Show minimap on the canva"} description={"Displays the minimap on canva."} /><SettingSwitch setting={"showCopyIcon"} value={settings.showCopyIcon} title={"Show copy button on nodes"} description={"Displays a copy button on the nodes."} /><SettingSwitch setting={"showNodeToolbar"} value={settings.showNodeToolbar} title={"Show toolbar on nodes"} description={"Displays a toolbar with actions on the nodes."} />+ <SettingSwitch disabled setting={"floatingEdges"} value={settings.floatingEdges} title={"Floating edges"} description={"Edges are not stuck to one point."} /><div className="flex items-center justify-between gap-4"><div className="flex flex-col gap-1"><p className="font-medium">Theme</p>diff --git a/src/components/dashboard/new-case.tsx b/src/components/dashboard/new-case.tsxindex 2c76b57d..53b6011e 100644--- a/src/components/dashboard/new-case.tsx+++ b/src/components/dashboard/new-case.tsx@@ -1,11 +1,10 @@"use client"-import { DropdownMenu, Button, IconButton, Dialog, Flex, TextField, Text, Badge, Box } from "@radix-ui/themes";-import { PlusIcon } from 'lucide-react';+import { DropdownMenu, Button, Dialog, Flex, TextField, Text, Badge, Box } from "@radix-ui/themes";import { useState } from "react";import { supabase } from '@/src/lib/supabase/client';import { useRouter } from "next/navigation";-export default function NewCase() {+export default function NewCase({ children }: { children: React.ReactNode }) {const [open, setOpen] = useState(false)const router = useRouter()@@ -27,9 +26,7 @@ export default function NewCase() {<><DropdownMenu.Root><DropdownMenu.Trigger>- <IconButton color="gray" size="2" variant="soft">- <PlusIcon className="h-5" />- </IconButton>+ {children}</DropdownMenu.Trigger><DropdownMenu.Content size="2"><DropdownMenu.Item onClick={() => setOpen(true)} shortcut="⌘ E">New case</DropdownMenu.Item>diff --git a/src/components/dashboard/seach-palette.tsx b/src/components/dashboard/seach-palette.tsxindex 6ec516bb..b95032b7 100644--- a/src/components/dashboard/seach-palette.tsx+++ b/src/components/dashboard/seach-palette.tsx@@ -55,14 +55,14 @@ const SearchModal = ({ investigation_id }: { investigation_id: string }) => {<HighlightersearchWords={search.split(" ")}autoEscape={true}- textToHighlight={item.full_name}+ textToHighlight={item?.full_name}/></span><span className='truncate text-ellipsis text-sm opacity-75'><HighlightersearchWords={search.split(" ")}autoEscape={true}- textToHighlight={item.notes}+ textToHighlight={item?.notes}/></span></span>diff --git a/src/components/investigations/floating-edge.tsx b/src/components/investigations/floating-edge.tsxindex e8798603..4e6c0a20 100644--- a/src/components/investigations/floating-edge.tsx+++ b/src/components/investigations/floating-edge.tsx@@ -47,7 +47,7 @@ function FloatingEdge(props: any) {pointerEvents: 'all',opacity: style?.opacity || 1}}- className="nodrag nopan text-xs px-1">{label} {confidence_level &&+ className="nodrag nopan !text-[.6rem] !px-1 !py-0">{label} {confidence_level &&<>{confidence_level}%</>}</Badge>}</EdgeLabelRenderer></>diff --git a/src/components/investigations/graph.tsx b/src/components/investigations/graph.tsxindex 01d98753..54fb1eac 100644--- a/src/components/investigations/graph.tsx+++ b/src/components/investigations/graph.tsx@@ -13,9 +13,6 @@ import {ColorMode,MiniMap,Node,- Edge,- useNodeConnections,- useInternalNode} from '@xyflow/react';import '@xyflow/react/dist/style.css';import { supabase } from '@/src/lib/supabase/client';@@ -30,16 +27,17 @@ import { AlignCenterHorizontal, AlignCenterVertical, LockOpenIcon, MaximizeIcon,import { useTheme } from 'next-themes';import NewActions from './new-actions';import { IconButton, Tooltip, Spinner, Card, Flex, SegmentedControl } from '@radix-ui/themes';-import { isNode, isEdge, getIncomers, getOutgoers } from "@xyflow/react";+import { getIncomers, getOutgoers } from "@xyflow/react";import { EdgeBase } from '@xyflow/system';import { useInvestigationContext } from '../contexts/investigation-provider';import FloatingEdge from './floating-edge';import FloatingConnectionLine from './floating-connection';+import { useParams } from 'next/navigation';-const nodeTypes = { individual: IndividualNode, phone: PhoneNode, ip: IpNode, email: EmailNode, social: SocialNode, address: AddressNode };const edgeTypes = {- 'custom': FloatingEdge,-};+ "custom": FloatingEdge+}+const nodeTypes = { individual: IndividualNode, phone: PhoneNode, ip: IpNode, email: EmailNode, social: SocialNode, address: AddressNode };const getLayoutedElements = (nodes: any[], edges: any[], options: { direction: any; }) => {const g = new Dagre.graphlib.Graph().setDefaultEdgeLabel(() => ({}));g.setGraph({ rankdir: options.direction });@@ -74,8 +72,14 @@ const LayoutFlow = ({ initialNodes, initialEdges, theme }: { initialNodes: any,const [nodes, setNodes, onNodesChange] = useNodesState(initialNodes);const [edges, setEdges, onEdgesChange] = useEdgesState(initialEdges);const [isLocked, setIsLocked] = useState(false)+ const { investigation_id } = useParams()const { currentNode, setCurrentNode, settings } = useInvestigationContext()const ref = useRef(null);++ // const edgeTypes = useMemo(() => ({+ // 'custom': settings.floatingEdges ? FloatingEdge : CustomEdge,+ // }), [settings.floatingEdges]);+const getAllIncomers = useCallback((node: any, nodes: any[], edges: EdgeBase[], prevIncomers = []) => {const incomers = getIncomers(node, nodes, edges);const result = incomers.reduce(@@ -222,8 +226,9 @@ const LayoutFlow = ({ initialNodes, initialEdges, theme }: { initialNodes: any,);const onConnect = useCallback(async (params: any) => {+ if (!investigation_id) returnawait supabase.from("relationships")- .insert({ individual_a: params.source, individual_b: params.target, relation_type: "relation" })+ .upsert({ individual_a: params.source, individual_b: params.target, investigation_id: investigation_id, relation_type: "relation" })setEdges((els) => addEdge({ ...params, label: "relation", type: "custom" }, els))},[setEdges],diff --git a/src/components/investigations/layout.tsx b/src/components/investigations/layout.tsxindex 7872a0e2..1cbbc2f0 100644--- a/src/components/investigations/layout.tsx+++ b/src/components/investigations/layout.tsx@@ -6,7 +6,7 @@ import NewCase from '../dashboard/new-case';import SearchModal from '../dashboard/seach-palette';import { Flex, IconButton, ScrollArea } from '@radix-ui/themes';import { Panel, PanelGroup, PanelResizeHandle } from 'react-resizable-panels';-import { BotMessageSquareIcon, PanelRightIcon } from 'lucide-react';+import { BotMessageSquareIcon, PanelRightIcon, PlusIcon } from 'lucide-react';import { useChatContext } from '../contexts/chatbot-context';import Logo from '../logo';import { useInvestigationContext } from '../contexts/investigation-provider';@@ -23,8 +23,8 @@ const InvestigationLayout = ({investigation_id: stringuser: any}) => {- const { setOpen: setOpenChat } = useChatContext()- const { panelOpen, setPanelOpen } = useInvestigationContext()+ const { handleOpenChat } = useChatContext()+ const { panelOpen, setPanelOpen, investigation } = useInvestigationContext()return (<PanelGroup autoSaveId="conditional" className='h-screen w-screen flex' direction="horizontal">{panelOpen && <Panel id="left" className='h-screen' defaultSize={20} minSize={10}>@@ -32,9 +32,13 @@ const InvestigationLayout = ({<div className='w-full rounded-none shadow-none h-12 border-b border-gray-400/20 flex items-center gap-1 flex-row justify-between p-2'><Logo /><Flex gap={"1"}>- <IconButton onClick={() => setOpenChat(true)} color="gray" size="2" variant="soft"><BotMessageSquareIcon className="h-4" /></IconButton>+ <IconButton onClick={() => handleOpenChat(investigation)} color="gray" size="2" variant="soft"><BotMessageSquareIcon className="h-4" /></IconButton><SearchModal investigation_id={investigation_id} />- <NewCase />+ <NewCase>+ <IconButton color="gray" size="2" variant="soft">+ <PlusIcon className="h-5" />+ </IconButton>+ </NewCase></Flex></div><ScrollArea type="auto" scrollbars="vertical" className='p-3 h-full grow overflow-y-auto'>diff --git a/src/components/investigations/nodes/email.tsx b/src/components/investigations/nodes/email.tsxindex d34ff1c0..4101cf6f 100644--- a/src/components/investigations/nodes/email.tsx+++ b/src/components/investigations/nodes/email.tsx@@ -50,7 +50,7 @@ function EmailNode({ data }: any) {<Handletype="target"position={Position.Top}- className="w-16 !bg-teal-500 hidden"+ className={cn("w-16 !bg-teal-500 hidden", settings.floatingEdges && "hidden")}/></Box>diff --git a/src/components/investigations/nodes/individual.tsx b/src/components/investigations/nodes/individual.tsxindex 8a36dfdf..6284ef0e 100644--- a/src/components/investigations/nodes/individual.tsx+++ b/src/components/investigations/nodes/individual.tsx@@ -16,7 +16,7 @@ function Custom(props: any) {const { settings, handleOpenIndividualModal, currentNode } = useInvestigationContext()const { setOpenAddNodeModal, handleDuplicateNode, handleDeleteNode, loading } = useNodeContext()const { handleOpenSearchModal } = useSearchContext()- const { setOpen: setOpenChat } = useChatContext()+ const { handleOpenChat } = useChatContext()const showContent = useStore(zoomSelector);const { data } = propsreturn (@@ -29,13 +29,13 @@ function Custom(props: any) {<Card data-radius='full' className='!p-1'><Flex gap={"1"}><Button variant='soft' color='gray' onClick={() => handleOpenIndividualModal(data.id)}><EditIcon className='h-4 w-4' />Edit</Button>- <Button variant='soft' color='gray' onClick={() => setOpenChat(true)}><ZapIcon color='orange' className='h-4 w-4' />Ask AI</Button>+ <Button variant='soft' color='gray' onClick={() => handleOpenChat(data)}><ZapIcon color='orange' className='h-4 w-4' />Ask AI</Button></Flex></Card></NodeToolbar>}<ContextMenu.Root><ContextMenu.Trigger onContextMenu={(e) => { e.stopPropagation() }}>- <Box className={cn(loading ? "!opacity-40" : "!opacity-100", "overflow-hidden")}>{settings.showNodeLabel && showContent ?+ <Box className={cn(loading ? "!opacity-40" : "!opacity-100", "overflow-hidden group")}>{settings.showNodeLabel && showContent ?<Card data-radius='full' onDoubleClick={() => handleOpenIndividualModal(data.id)} className={cn('!p-1 !pr-2 border border-transparent hover:border-sky-400', currentNode === data.id && "border-sky-400")}><Flex gap="2" align="center" className='rounded-full'><Avatar@@ -69,18 +69,18 @@ function Custom(props: any) {<Handletype="target"position={Position.Top}- className={cn("w-16 !bg-teal-500", showContent ? "opacity-100" : "opacity-0")}+ className={cn("w-16 !bg-teal-500", showContent ? "group-hover:opacity-100 opacity-0" : "opacity-0")}/><Handletype="source"position={Position.Bottom}- className={cn("w-16 !bg-teal-500", showContent ? "opacity-100" : "opacity-0")}+ className={cn("w-16 !bg-teal-500", showContent ? "group-hover:opacity-100 opacity-0" : "opacity-0")}/></Box></ContextMenu.Trigger><ContextMenu.Content><ContextMenu.Item className='font-bold' onClick={() => handleOpenSearchModal(data.full_name)}>Launch search<ZapIcon color='orange' className='h-4 w-4' /></ContextMenu.Item>- <ContextMenu.Item className='font-bold' onClick={() => setOpenChat(true)}>Ask AI<BotIcon color='#12A594' className='h-4 w-4' /></ContextMenu.Item>+ <ContextMenu.Item className='font-bold' onClick={() => handleOpenChat(data)}>Ask AI<BotIcon color='#12A594' className='h-4 w-4' /></ContextMenu.Item><ContextMenu.Sub><ContextMenu.SubTrigger >New</ContextMenu.SubTrigger><ContextMenu.SubContent>diff --git a/src/components/investigations/nodes/ip_address.tsx b/src/components/investigations/nodes/ip_address.tsxindex 6b57c507..56a87914 100644--- a/src/components/investigations/nodes/ip_address.tsx+++ b/src/components/investigations/nodes/ip_address.tsx@@ -51,7 +51,7 @@ function Custom({ data }: any) {<Handletype="target"position={Position.Top}- className="w-16 !bg-teal-500 hidden"+ className={cn("w-16 !bg-teal-500 hidden", settings.floatingEdges && "hidden")}/></Box></ContextMenu.Trigger>diff --git a/src/components/investigations/nodes/phone.tsx b/src/components/investigations/nodes/phone.tsxindex 0d4f737f..245beb7c 100644--- a/src/components/investigations/nodes/phone.tsx+++ b/src/components/investigations/nodes/phone.tsx@@ -51,7 +51,7 @@ function Custom({ data }: any) {<Handletype="target"position={Position.Top}- className="w-16 !bg-teal-500 hidden"+ className={cn("w-16 !bg-teal-500 hidden", settings.floatingEdges && "hidden")}/></Box>diff --git a/src/components/investigations/nodes/physical_address.tsx b/src/components/investigations/nodes/physical_address.tsxindex e5c9e72c..c93e5de7 100644--- a/src/components/investigations/nodes/physical_address.tsx+++ b/src/components/investigations/nodes/physical_address.tsx@@ -50,7 +50,7 @@ function AddressNode({ data }: any) {<Handletype="target"position={Position.Top}- className="w-16 !bg-teal-500 hidden"+ className={cn("w-16 !bg-teal-500 hidden", settings.floatingEdges && "hidden")}/></Box>diff --git a/src/components/investigations/nodes/social.tsx b/src/components/investigations/nodes/social.tsxindex 5d87abe6..70fc0a27 100644--- a/src/components/investigations/nodes/social.tsx+++ b/src/components/investigations/nodes/social.tsx@@ -59,7 +59,7 @@ function Custom({ data }: any) {<Handletype="target"position={Position.Top}- className="w-16 !bg-teal-500 hidden"+ className={cn("w-16 !bg-teal-500 hidden", settings.floatingEdges && "hidden")}/></Box></ContextMenu.Trigger>