Skip to content

A modern platform for visual, flexible, and extensible graph-based investigations. For cybersecurity analysts and investigators.

feat(app): path finder

dextmorgnc481a1474707
diff --git a/flowsint-app/src/components/chat/chat-history.tsx b/flowsint-app/src/components/chat/chat-history.tsx
index 8327cabe..3c0ae813 100644
--- a/flowsint-app/src/components/chat/chat-history.tsx
+++ b/flowsint-app/src/components/chat/chat-history.tsx
@@ -21,7 +21,7 @@ const ChatHistory = ({
const { confirm } = useConfirm()
const setCurrentChatId = useChatState((s) => s.setCurrentChatId)
const { data: chats, isLoading } = useQuery({
- queryKey: ['chats'],
+ queryKey: ['chats', 'list'],
queryFn: () => chatCRUDService.get()
})
diff --git a/flowsint-app/src/components/chat/resizable-chat.tsx b/flowsint-app/src/components/chat/resizable-chat.tsx
index efbadca9..fad81613 100644
--- a/flowsint-app/src/components/chat/resizable-chat.tsx
+++ b/flowsint-app/src/components/chat/resizable-chat.tsx
@@ -1,6 +1,6 @@
-import React, { useState, useCallback, useRef, useEffect } from 'react'
-import { cn } from '@/lib/utils'
+import React, { useCallback } from 'react'
import { useLayoutStore } from '@/stores/layout-store'
+import { ResizableContainer } from '@/components/ui/resizable-container'
interface ResizableChatProps {
children: React.ReactNode
@@ -18,149 +18,27 @@ export const ResizableChat: React.FC<ResizableChatProps> = ({
maxHeight = 800
}) => {
const { chatWidth, chatHeight, setChatDimensions } = useLayoutStore()
- const [isResizing, setIsResizing] = useState(false)
- const [resizeDirection, setResizeDirection] = useState<'se' | 'sw' | 'ne' | 'nw' | null>(null)
- const [startPos, setStartPos] = useState({ x: 0, y: 0 })
- const [startDimensions, setStartDimensions] = useState({ width: 0, height: 0 })
- const containerRef = useRef<HTMLDivElement>(null)
- const handleMouseDown = useCallback(
- (direction: 'se' | 'sw' | 'ne' | 'nw') => (e: React.MouseEvent) => {
- e.preventDefault()
- e.stopPropagation()
-
- setIsResizing(true)
- setResizeDirection(direction)
- setStartPos({ x: e.clientX, y: e.clientY })
- setStartDimensions({ width: chatWidth, height: chatHeight })
-
- document.body.style.cursor = direction.includes('e') ? 'e-resize' : 'w-resize'
- document.body.style.userSelect = 'none'
- },
- [chatWidth, chatHeight]
- )
-
- const handleMouseMove = useCallback(
- (e: MouseEvent): void => {
- if (!isResizing || !resizeDirection) return
-
- const deltaX = e.clientX - startPos.x
- const deltaY = e.clientY - startPos.y
-
- let newWidth = startDimensions.width
- let newHeight = startDimensions.height
-
- // Calculate new dimensions based on resize direction
- if (resizeDirection.includes('e')) {
- newWidth = Math.max(minWidth, Math.min(maxWidth, startDimensions.width + deltaX))
- } else if (resizeDirection.includes('w')) {
- newWidth = Math.max(minWidth, Math.min(maxWidth, startDimensions.width - deltaX))
- }
-
- if (resizeDirection.includes('s')) {
- newHeight = Math.max(minHeight, Math.min(maxHeight, startDimensions.height + deltaY))
- } else if (resizeDirection.includes('n')) {
- newHeight = Math.max(minHeight, Math.min(maxHeight, startDimensions.height - deltaY))
- }
-
- setChatDimensions(newWidth, newHeight)
+ const handleResize = useCallback(
+ (width: number, height: number) => {
+ setChatDimensions(width, height)
},
- [
- isResizing,
- resizeDirection,
- startPos,
- startDimensions,
- minWidth,
- minHeight,
- maxWidth,
- maxHeight,
- setChatDimensions
- ]
+ [setChatDimensions]
)
- const handleMouseUp = useCallback(() => {
- setIsResizing(false)
- setResizeDirection(null)
- document.body.style.cursor = ''
- document.body.style.userSelect = ''
- }, [])
-
- useEffect(() => {
- if (isResizing) {
- document.addEventListener('mousemove', handleMouseMove)
- document.addEventListener('mouseup', handleMouseUp)
-
- return () => {
- document.removeEventListener('mousemove', handleMouseMove)
- document.removeEventListener('mouseup', handleMouseUp)
- }
- }
- return undefined
- }, [isResizing, handleMouseMove, handleMouseUp])
-
return (
- <div
- ref={containerRef}
- className={cn(
- 'relative group/resize overflow-hidden max-h-[calc(100vh-60px)]',
- isResizing && 'pointer-events-none'
- )}
- style={{
- width: chatWidth,
- height: chatHeight
- }}
+ <ResizableContainer
+ defaultWidth={chatWidth}
+ defaultHeight={chatHeight}
+ onResize={handleResize}
+ minWidth={minWidth}
+ minHeight={minHeight}
+ maxWidth={maxWidth}
+ maxHeight={maxHeight}
+ storageKey="resizable-chat"
+ className="max-h-[calc(100vh-60px)]"
>
{children}
-
- {/* Resize overlay when active */}
- {isResizing && (
- <div className="absolute inset-0 bg-primary/5 border-2 border-primary/30 rounded-2xl pointer-events-none" />
- )}
-
- {/* Resize handles */}
- <div
- className={cn(
- 'absolute bottom-0 right-0 w-4 h-4 cursor-se-resize',
- 'bg-transparent hover:bg-primary/20 transition-colors',
- 'rounded-tl-md border-primary/20',
- 'group-hover/resize:border-primary/40',
- isResizing && 'bg-primary/30 border-primary/50'
- )}
- onMouseDown={handleMouseDown('se')}
- />
-
- <div
- className={cn(
- 'absolute bottom-0 left-0 w-4 h-4 cursor-sw-resize',
- 'bg-transparent hover:bg-primary/20 transition-colors',
- 'rounded-tr-md border-primary/20',
- 'group-hover/resize:border-primary/40',
- isResizing && 'bg-primary/30 border-primary/50'
- )}
- onMouseDown={handleMouseDown('sw')}
- />
-
- <div
- className={cn(
- 'absolute top-0 right-0 w-4 h-4 cursor-ne-resize',
- 'bg-transparent hover:bg-primary/20 transition-colors',
- 'rounded-bl-md border-primary/20',
- 'group-hover/resize:border-primary/40',
- isResizing && 'bg-primary/30 border-primary/50'
- )}
- onMouseDown={handleMouseDown('ne')}
- />
-
- <div
- className={cn(
- 'absolute top-0 left-0 w-4 h-4 cursor-nw-resize',
- 'bg-transparent hover:bg-primary/20 transition-colors',
- 'rounded-br-md border-primary/20',
- 'group-hover/resize:border-primary/40',
- isResizing && 'bg-primary/30 border-primary/50'
- )}
- onMouseDown={handleMouseDown('nw')}
- />
- </div>
+ </ResizableContainer>
)
}
diff --git a/flowsint-app/src/components/sketches/details-panel/resizable-details-panels.tsx b/flowsint-app/src/components/sketches/details-panel/resizable-details-panels.tsx
index 798ce514..9564be8c 100644
--- a/flowsint-app/src/components/sketches/details-panel/resizable-details-panels.tsx
+++ b/flowsint-app/src/components/sketches/details-panel/resizable-details-panels.tsx
@@ -114,7 +114,7 @@ export function ResizableDetailsPanel({
if (currentOpenGroup.length > 0) {
const groupKey = currentOpenGroup.map((s) => s.id).join('-')
result.push(
- <PanelGroup key={groupKey} direction="vertical" className="flex-1 min-h-0">
+ <PanelGroup key={groupKey} direction="vertical" className="flex-1 min-h-0" autoSaveId={`details-panel-${groupKey}`}>
{currentOpenGroup.map((section, index) => {
const isLast = index === currentOpenGroup.length - 1
return (
diff --git a/flowsint-app/src/components/sketches/graph/actions/path-finder.tsx b/flowsint-app/src/components/sketches/graph/actions/path-finder.tsx
new file mode 100644
index 00000000..65385ce1
--- /dev/null
+++ b/flowsint-app/src/components/sketches/graph/actions/path-finder.tsx
@@ -0,0 +1,161 @@
+import { useCallback, useState } from 'react'
+import { Route, X, Loader2 } from 'lucide-react'
+import { toast } from 'sonner'
+import { useGraphStore } from '@/stores/graph-store'
+import { useGraphControls } from '@/stores/graph-controls-store'
+import { usePathfinder } from '@/hooks/use-pathfinder'
+import { ToolbarButton } from '../../toolbar'
+import { Badge } from '@/components/ui/badge'
+import { Button } from '@/components/ui/button'
+import { ResizableContainer } from '@/components/ui/resizable-container'
+import { useNodesDisplaySettings } from '@/stores/node-display-settings'
+
+export function PathFinder() {
+ const [isLoading, setIsLoading] = useState(false)
+ const { findPath } = usePathfinder()
+
+ const selectedNodes = useGraphStore((s) => s.selectedNodes)
+ const nodes = useGraphStore((s) => s.filteredNodes)
+ const edges = useGraphStore((s) => s.filteredEdges)
+ const setHighlightedNodes = useGraphStore((s) => s.setHighlightedNodes)
+ const setPath = useGraphStore((s) => s.setPath)
+ const zoomToSelection = useGraphControls((s) => s.zoomToSelection)
+
+ const areExactlyTwoSelected = selectedNodes.length === 2
+
+ const handleFindPath = useCallback(async () => {
+ if (!areExactlyTwoSelected) return
+
+ const [source, target] = selectedNodes
+ setIsLoading(true)
+
+ try {
+ const result = await findPath(nodes, edges, source.id, target.id)
+
+ if (result) {
+ setPath(result)
+ setHighlightedNodes(result.ids)
+ zoomToSelection()
+ } else {
+ toast.info('No path found between these nodes')
+ }
+ } catch (error) {
+ toast.error('Failed to find path')
+ } finally {
+ setIsLoading(false)
+ }
+ }, [
+ areExactlyTwoSelected,
+ selectedNodes,
+ nodes,
+ edges,
+ findPath,
+ setPath,
+ setHighlightedNodes,
+ zoomToSelection
+ ])
+
+ return (
+ <ToolbarButton
+ icon={
+ isLoading ? (
+ <Loader2 className="h-4 w-4 opacity-70 animate-spin" />
+ ) : (
+ <Route className="h-4 w-4 opacity-70" />
+ )
+ }
+ tooltip="Find Path"
+ onClick={handleFindPath}
+ disabled={!areExactlyTwoSelected || isLoading}
+ badge={areExactlyTwoSelected ? 2 : null}
+ />
+ )
+}
+
+export function PathPanel() {
+ const path = useGraphStore((s) => s.path)
+ const setPath = useGraphStore((s) => s.setPath)
+ const setHighlightedNodes = useGraphStore((s) => s.setHighlightedNodes)
+ const setCurrentNodeId = useGraphStore((s) => s.setCurrentNodeId)
+ const nodesMapping = useGraphStore((s) => s.nodesMapping)
+ const nodeColors = useNodesDisplaySettings((s) => s.colors)
+
+ const handleClose = useCallback(() => {
+ setPath(null)
+ setHighlightedNodes([])
+ }, [setPath, setHighlightedNodes])
+
+ const handleNodeClick = useCallback(
+ (nodeId: string) => {
+ setCurrentNodeId(nodeId)
+ },
+ [setCurrentNodeId]
+ )
+
+ if (!path) return null
+
+ return (
+ <div className="absolute top-2 right-2 z-50">
+ <ResizableContainer
+ defaultWidth={260}
+ defaultHeight={320}
+ minWidth={200}
+ minHeight={160}
+ maxWidth={500}
+ maxHeight={600}
+ handles={['se', 'sw']}
+ storageKey="resizable-path-panel"
+ className="rounded-xl border bg-card shadow-lg"
+ >
+ <div className="flex flex-col h-full">
+ <div className="flex items-center justify-between px-3 py-2 border-b shrink-0">
+ <span className="text-sm font-medium truncate">Path ({path.nodes.length} nodes)</span>
+ <Button variant="ghost" size="icon" className="h-6 w-6 shrink-0" onClick={handleClose}>
+ <X className="h-3.5 w-3.5" />
+ </Button>
+ </div>
+ <div className="flex-1 min-h-0 overflow-y-auto overflow-x-hidden">
+ <div className="p-2 space-y-1">
+ {path.nodes.map((node, index) => {
+ const edge = index < path.edges.length ? path.edges[index] : null
+ const graphNode = nodesMapping.get(node.id)
+ const color =
+ graphNode?.nodeColor ||
+ nodeColors[node.node_type as keyof typeof nodeColors] ||
+ '#888'
+
+ return (
+ <div key={node.id} className="overflow-hidden">
+ <button
+ onClick={() => handleNodeClick(node.id)}
+ className="w-full text-left px-2 py-1.5 rounded hover:bg-muted flex items-center gap-2 overflow-hidden"
+ >
+ <div
+ className="w-2 h-2 rounded-full shrink-0"
+ style={{ backgroundColor: color }}
+ />
+ <div className="min-w-0 flex-1">
+ <div className="text-sm truncate">{node.label}</div>
+ <Badge variant="secondary" className="px-1 max-w-full truncate block">
+ {node.node_type}
+ </Badge>
+ </div>
+ </button>
+ {edge && (
+ <div className="flex items-center gap-2 px-2 py-0.5 ml-3 overflow-hidden">
+ <div className="w-px h-4 bg-border shrink-0" />
+ <span className="text-[10px] text-muted-foreground truncate block min-w-0">
+ {edge.label}
+ </span>
+ </div>
+ )}
+ </div>
+ )
+ })}
+ </div>
+ </div>
+ </div>
+ </ResizableContainer>
+ </div>
+ )
+}
diff --git a/flowsint-app/src/components/sketches/graph/components/graph-main.tsx b/flowsint-app/src/components/sketches/graph/components/graph-main.tsx
index 5631cd4a..fb1558e5 100644
--- a/flowsint-app/src/components/sketches/graph/components/graph-main.tsx
+++ b/flowsint-app/src/components/sketches/graph/components/graph-main.tsx
@@ -5,6 +5,7 @@ import GraphViewer from '../index'
import NodeContextMenu from '../context-menu/node-context-menu'
import BackgroundContextMenu from '../context-menu/background-context-menu'
import EdgeContextMenu from '../context-menu/edge-context-menu'
+import { PathPanel } from '../actions/path-finder'
import { useParams } from '@tanstack/react-router'
import { type GraphNode, GraphEdge } from '@/types'
@@ -190,6 +191,7 @@ const GraphMain = () => {
allowLasso
sketchId={sketchId}
/>
+ <PathPanel />
{nodeMenu && selectedNodes.length === 0 && <NodeContextMenu {...nodeMenu} />}
{edgeMenu && <EdgeContextMenu {...edgeMenu} />}
{(background || (nodeMenu && selectedNodes.length > 0)) && (
diff --git a/flowsint-app/src/components/sketches/graph/hooks/use-computed-highlights.ts b/flowsint-app/src/components/sketches/graph/hooks/use-computed-highlights.ts
new file mode 100644
index 00000000..3a8a8a31
--- /dev/null
+++ b/flowsint-app/src/components/sketches/graph/hooks/use-computed-highlights.ts
@@ -0,0 +1,25 @@
+import { useMemo } from 'react'
+import type { GraphEdge } from '@/types'
+
+export const useComputedHighlights = (highlightedNodeIds: string[], edges: GraphEdge[]) => {
+ const highlightNodes = useMemo(() => new Set(highlightedNodeIds), [highlightedNodeIds])
+
+ const highlightLinks = useMemo(() => {
+ const links = new Set<string>()
+ const nodeIdSet = new Set(highlightedNodeIds)
+
+ edges.forEach((edge) => {
+ const sourceId = edge.source
+ const targetId = edge.target
+
+ // Only highlight links where BOTH nodes are highlighted
+ if (nodeIdSet.has(sourceId) && nodeIdSet.has(targetId)) {
+ links.add(`${sourceId}-${targetId}`)
+ }
+ })
+
+ return links
+ }, [highlightedNodeIds, edges])
+
+ return { highlightNodes, highlightLinks }
+}
diff --git a/flowsint-app/src/components/sketches/graph/index.tsx b/flowsint-app/src/components/sketches/graph/index.tsx
index 376897ef..4ccf5ee5 100644
--- a/flowsint-app/src/components/sketches/graph/index.tsx
+++ b/flowsint-app/src/components/sketches/graph/index.tsx
@@ -19,6 +19,7 @@ import { renderNode } from './node/node-renderer'
import { useKeyboardEvents } from './hooks/use-keyboard-events'
import { renderLink } from './edge/link-renderer'
import { useHighlightState } from './hooks/use-highlight-state'
+import { useComputedHighlights } from './hooks/use-computed-highlights'
import { useTooltip } from './hooks/use-tooltip'
import { transformGraphData } from './utils/graph-data-transformer'
import { useGraphLayout } from './hooks/use-graph-layout'
@@ -92,7 +93,8 @@ const GraphViewer: React.FC<GraphViewerProps> = ({
toggleEdgeSelection,
setCurrentEdgeId,
clearSelectedEdges,
- setOpenMainDialog
+ setOpenMainDialog,
+ highlightedNodeIds
} = useGraphStore(
useShallow((s) => ({
currentNodeId: s.currentNodeId,
@@ -102,7 +104,8 @@ const GraphViewer: React.FC<GraphViewerProps> = ({
toggleEdgeSelection: s.toggleEdgeSelection,
setCurrentEdgeId: s.setCurrentEdgeId,
clearSelectedEdges: s.clearSelectedEdges,
- setOpenMainDialog: s.setOpenMainDialog
+ setOpenMainDialog: s.setOpenMainDialog,
+ highlightedNodeIds: s.highlightedNodeIds
}))
)
@@ -225,14 +228,54 @@ const GraphViewer: React.FC<GraphViewerProps> = ({
)
const {
- highlightNodes,
- highlightLinks,
+ highlightNodes: hoverHighlightNodes,
+ highlightLinks: hoverHighlightLinks,
hoverNode,
handleNodeHover,
handleLinkHover,
clearHighlights
} = useHighlightState()
+ // Current node persistent highlights (neighbors + connected edges)
+ const currentNodeHighlights = useMemo(() => {
+ const nodeSet = new Set<string>()
+ const linkSet = new Set<string>()
+ if (!currentNodeId) return { nodes: nodeSet, links: linkSet }
+
+ nodeSet.add(currentNodeId)
+ edges.forEach((edge) => {
+ const sourceId = typeof edge.source === 'object' ? (edge.source as any).id : edge.source
+ const targetId = typeof edge.target === 'object' ? (edge.target as any).id : edge.target
+ if (sourceId === currentNodeId) {
+ nodeSet.add(targetId)
+ linkSet.add(`${sourceId}-${targetId}`)
+ } else if (targetId === currentNodeId) {
+ nodeSet.add(sourceId)
+ linkSet.add(`${sourceId}-${targetId}`)
+ }
+ })
+ return { nodes: nodeSet, links: linkSet }
+ }, [currentNodeId, edges])
+
+ // Path highlights from pathfinder
+ const { highlightNodes: pathHighlightNodes, highlightLinks: pathHighlightLinks } =
+ useComputedHighlights(highlightedNodeIds, edges)
+
+ // Merge: hover is prioritary over persistent highlights
+ const highlightNodes = useMemo(() => {
+ if (hoverHighlightNodes.size > 0) return hoverHighlightNodes
+ const merged = new Set<string>(currentNodeHighlights.nodes)
+ pathHighlightNodes.forEach((id) => merged.add(id))
+ return merged
+ }, [hoverHighlightNodes, currentNodeHighlights.nodes, pathHighlightNodes])
+
+ const highlightLinks = useMemo(() => {
+ if (hoverHighlightLinks.size > 0) return hoverHighlightLinks
+ const merged = new Set<string>(currentNodeHighlights.links)
+ pathHighlightLinks.forEach((id) => merged.add(id))
+ return merged
+ }, [hoverHighlightLinks, currentNodeHighlights.links, pathHighlightLinks])
+
const { tooltip, showTooltip, hideTooltip } = useTooltip(graphRef)
const handleNodeHoverWithTooltip = useCallback(
diff --git a/flowsint-app/src/components/sketches/toolbar.tsx b/flowsint-app/src/components/sketches/toolbar.tsx
index 8dd2a99b..69c76ec0 100644
--- a/flowsint-app/src/components/sketches/toolbar.tsx
+++ b/flowsint-app/src/components/sketches/toolbar.tsx
@@ -37,6 +37,7 @@ import {
import { sketchService } from '@/api/sketch-service'
import { useParams } from '@tanstack/react-router'
import { exportToPNG } from './graph/utils/export-to-png'
+import { PathFinder } from './graph/actions/path-finder'
// Tooltip wrapper component to avoid repetition
export const ToolbarButton = memo(function ToolbarButton({
@@ -227,6 +228,7 @@ export const Toolbar = memo(function Toolbar({ isLoading }: { isLoading: boolean
disabled={!areMergeable}
badge={areMergeable ? selectedNodes.length : null}
/>
+ <PathFinder />
</div>
<Separator decorative orientation="vertical" />
<div className="flex gap-1">
diff --git a/flowsint-app/src/components/ui/resizable-container.tsx b/flowsint-app/src/components/ui/resizable-container.tsx
new file mode 100644
index 00000000..7406a5fe
--- /dev/null
+++ b/flowsint-app/src/components/ui/resizable-container.tsx
@@ -0,0 +1,203 @@
+import React, { useState, useCallback, useRef, useEffect } from 'react'
+import { cn } from '@/lib/utils'
+
+type ResizeDirection = 'se' | 'sw' | 'ne' | 'nw'
+
+function loadPersistedSize(
+ storageKey: string,
+ defaultWidth: number,
+ defaultHeight: number
+): { width: number; height: number } {
+ try {
+ const raw = localStorage.getItem(storageKey)
+ if (raw) {
+ const parsed = JSON.parse(raw)
+ if (typeof parsed.width === 'number' && typeof parsed.height === 'number') {
+ return parsed
+ }
+ }
+ } catch {}
+ return { width: defaultWidth, height: defaultHeight }
+}
+
+interface ResizableContainerProps {
+ children: React.ReactNode
+ defaultWidth: number
+ defaultHeight: number
+ onResize?: (width: number, height: number) => void
+ minWidth?: number
+ minHeight?: number
+ maxWidth?: number
+ maxHeight?: number
+ handles?: ResizeDirection[]
+ className?: string
+ storageKey?: string
+}
+
+export const ResizableContainer: React.FC<ResizableContainerProps> = ({
+ children,
+ defaultWidth,
+ defaultHeight,
+ onResize,
+ minWidth = 200,
+ minHeight = 200,
+ maxWidth = 800,
+ maxHeight = 800,
+ handles = ['se', 'sw', 'ne', 'nw'],
+ className,
+ storageKey
+}) => {
+ const [size, setSize] = useState(() =>
+ storageKey
+ ? loadPersistedSize(storageKey, defaultWidth, defaultHeight)
+ : { width: defaultWidth, height: defaultHeight }
+ )
+ const [isResizing, setIsResizing] = useState(false)
+ const [resizeDirection, setResizeDirection] = useState<ResizeDirection | null>(null)
+ const [startPos, setStartPos] = useState({ x: 0, y: 0 })
+ const [startDimensions, setStartDimensions] = useState({ width: 0, height: 0 })
+ const containerRef = useRef<HTMLDivElement>(null)
+
+ const handleMouseDown = useCallback(
+ (direction: ResizeDirection) => (e: React.MouseEvent) => {
+ e.preventDefault()
+ e.stopPropagation()
+
+ setIsResizing(true)
+ setResizeDirection(direction)
+ setStartPos({ x: e.clientX, y: e.clientY })
+ setStartDimensions({ width: size.width, height: size.height })
+
+ document.body.style.cursor = direction.includes('e') ? 'e-resize' : 'w-resize'
+ document.body.style.userSelect = 'none'
+ },
+ [size.width, size.height]
+ )
+
+ const handleMouseMove = useCallback(
+ (e: MouseEvent): void => {
+ if (!isResizing || !resizeDirection) return
+
+ const deltaX = e.clientX - startPos.x
+ const deltaY = e.clientY - startPos.y
+
+ let newWidth = startDimensions.width
+ let newHeight = startDimensions.height
+
+ if (resizeDirection.includes('e')) {
+ newWidth = Math.max(minWidth, Math.min(maxWidth, startDimensions.width + deltaX))
+ } else if (resizeDirection.includes('w')) {
+ newWidth = Math.max(minWidth, Math.min(maxWidth, startDimensions.width - deltaX))
+ }
+
+ if (resizeDirection.includes('s')) {
+ newHeight = Math.max(minHeight, Math.min(maxHeight, startDimensions.height + deltaY))
+ } else if (resizeDirection.includes('n')) {
+ newHeight = Math.max(minHeight, Math.min(maxHeight, startDimensions.height - deltaY))
+ }
+
+ setSize({ width: newWidth, height: newHeight })
+ onResize?.(newWidth, newHeight)
+ },
+ [isResizing, resizeDirection, startPos, startDimensions, minWidth, minHeight, maxWidth, maxHeight, onResize]
+ )
+
+ const handleMouseUp = useCallback(() => {
+ setIsResizing(false)
+ setResizeDirection(null)
+ document.body.style.cursor = ''
+ document.body.style.userSelect = ''
+ }, [])
+
+ // Persist to localStorage on resize end
+ useEffect(() => {
+ if (!isResizing && storageKey) {
+ localStorage.setItem(storageKey, JSON.stringify({ width: size.width, height: size.height }))
+ }
+ }, [isResizing, storageKey, size.width, size.height])
+
+ useEffect(() => {
+ if (isResizing) {
+ document.addEventListener('mousemove', handleMouseMove)
+ document.addEventListener('mouseup', handleMouseUp)
+
+ return () => {
+ document.removeEventListener('mousemove', handleMouseMove)
+ document.removeEventListener('mouseup', handleMouseUp)
+ }
+ }
+ return undefined
+ }, [isResizing, handleMouseMove, handleMouseUp])
+
+ const handleSet = new Set(handles)
+
+ return (
+ <div
+ ref={containerRef}
+ className={cn(
+ 'relative group/resize overflow-hidden',
+ isResizing && 'pointer-events-none',
+ className
+ )}
+ style={{ width: size.width, height: size.height }}
+ >
+ {children}
+
+ {isResizing && (
+ <div className="absolute inset-0 bg-primary/5 border-2 border-primary/30 rounded-2xl pointer-events-none" />
+ )}
+
+ {handleSet.has('se') && (
+ <div
+ className={cn(
+ 'absolute bottom-0 right-0 w-4 h-4 cursor-se-resize',
+ 'bg-transparent hover:bg-primary/20 transition-colors',
+ 'rounded-tl-md border-primary/20',
+ 'group-hover/resize:border-primary/40',
+ isResizing && 'bg-primary/30 border-primary/50'
+ )}
+ onMouseDown={handleMouseDown('se')}
+ />
+ )}
+
+ {handleSet.has('sw') && (
+ <div
+ className={cn(
+ 'absolute bottom-0 left-0 w-4 h-4 cursor-sw-resize',
+ 'bg-transparent hover:bg-primary/20 transition-colors',
+ 'rounded-tr-md border-primary/20',
+ 'group-hover/resize:border-primary/40',
+ isResizing && 'bg-primary/30 border-primary/50'
+ )}
+ onMouseDown={handleMouseDown('sw')}
+ />
+ )}
+
+ {handleSet.has('ne') && (
+ <div
+ className={cn(
+ 'absolute top-0 right-0 w-4 h-4 cursor-ne-resize',
+ 'bg-transparent hover:bg-primary/20 transition-colors',
+ 'rounded-bl-md border-primary/20',
+ 'group-hover/resize:border-primary/40',
+ isResizing && 'bg-primary/30 border-primary/50'
+ )}
+ onMouseDown={handleMouseDown('ne')}
+ />
+ )}
+
+ {handleSet.has('nw') && (
+ <div
+ className={cn(
+ 'absolute top-0 left-0 w-4 h-4 cursor-nw-resize',
+ 'bg-transparent hover:bg-primary/20 transition-colors',
+ 'rounded-br-md border-primary/20',
+ 'group-hover/resize:border-primary/40',
+ isResizing && 'bg-primary/30 border-primary/50'
+ )}
+ onMouseDown={handleMouseDown('nw')}
+ />
+ )}
+ </div>
+ )
+}
diff --git a/flowsint-app/src/hooks/use-pathfinder.ts b/flowsint-app/src/hooks/use-pathfinder.ts
new file mode 100644
index 00000000..7e9880e8
--- /dev/null
+++ b/flowsint-app/src/hooks/use-pathfinder.ts
@@ -0,0 +1,58 @@
+import { useCallback, useRef, useEffect } from 'react'
+import type { GraphNode, GraphEdge, Path } from '@/types'
+
+export function usePathfinder() {
+ const workerRef = useRef<Worker | null>(null)
+
+ useEffect(() => {
+ workerRef.current = new Worker(
+ new URL('../workers/pathfinder.worker.ts', import.meta.url),
+ { type: 'module' }
+ )
+ return () => {
+ workerRef.current?.terminate()
+ }
+ }, [])
+
+ const findPath = useCallback(
+ (nodes: GraphNode[], edges: GraphEdge[], sourceId: string, targetId: string): Promise<Path | null> => {
+ if (!workerRef.current) {
+ return Promise.reject(new Error('Pathfinder worker not initialized'))
+ }
+
+ return new Promise((resolve, reject) => {
+ const worker = workerRef.current!
+
+ const handleMessage = (event: MessageEvent) => {
+ worker.removeEventListener('message', handleMessage)
+ worker.removeEventListener('error', handleError)
+
+ if (event.data.type === 'complete') {
+ resolve(event.data.result)
+ } else if (event.data.type === 'error') {
+ reject(new Error(event.data.error))
+ }
+ }
+
+ const handleError = (error: ErrorEvent) => {
+ worker.removeEventListener('message', handleMessage)
+ worker.removeEventListener('error', handleError)
+ reject(error)
+ }
+
+ worker.addEventListener('message', handleMessage)
+ worker.addEventListener('error', handleError)
+
+ worker.postMessage({
+ nodes: nodes.map((n) => ({ id: n.id, nodeLabel: n.nodeLabel, nodeType: n.nodeType })),
+ edges: edges.map((e) => ({ id: e.id, source: e.source, target: e.target, label: e.label, caption: e.caption })),
+ sourceId,
+ targetId,
+ })
+ })
+ },
+ []
+ )
+
+ return { findPath }
+}
diff --git a/flowsint-app/src/stores/graph-store.ts b/flowsint-app/src/stores/graph-store.ts
index ad6eb463..e9488bd1 100644
--- a/flowsint-app/src/stores/graph-store.ts
+++ b/flowsint-app/src/stores/graph-store.ts
@@ -1,6 +1,6 @@
import { create } from 'zustand'
import { persist } from 'zustand/middleware'
-import type { GraphNode, GraphEdge, NodeProperties, ChatContextFormat } from '@/types'
+import type { GraphNode, GraphEdge, NodeProperties, ChatContextFormat, Path } from '@/types'
import { type ActionItem } from '@/lib/action-items'
import { Filters, TypeFilter } from '@/types/filter'
@@ -71,6 +71,12 @@ interface GraphState {
setFilters: (filters: Filters) => void
toggleTypeFilter: (filter: TypeFilter) => void
+ // === Path ===
+ highlightedNodeIds: string[]
+ path: Path | null
+ setHighlightedNodes: (ids: string[]) => void
+ setPath: (path: Path | null) => void
+
// === Utils ===
nodesLength: number
edgesLength: number
@@ -471,6 +477,12 @@ export const useGraphStore = create<GraphState>()(
set({ filters: newFilters, filteredNodes, filteredEdges })
},
+ // === Path ===
+ highlightedNodeIds: [],
+ path: null,
+ setHighlightedNodes: (ids) => set({ highlightedNodeIds: ids }),
+ setPath: (path) => set({ path }),
+
reset: () => {
set({
currentNodeId: null,
@@ -485,7 +497,9 @@ export const useGraphStore = create<GraphState>()(
currentNodeType: null,
filteredNodes: get().nodes,
filteredEdges: get().edges,
- selectedNodesWithEdgesAsList: []
+ selectedNodesWithEdgesAsList: [],
+ highlightedNodeIds: [],
+ path: null
})
},
selectedNodesWithEdgesAsList: [],
diff --git a/flowsint-app/src/types/graph.ts b/flowsint-app/src/types/graph.ts
index 10a5fc3e..19de7344 100644
--- a/flowsint-app/src/types/graph.ts
+++ b/flowsint-app/src/types/graph.ts
@@ -80,3 +80,23 @@ export type ExtendedSetting = {
export type Settings = {
[key: string]: ExtendedSetting
}
+
+export type PathNode = {
+ id: string
+ label: string
+ node_type: string
+}
+
+export type PathEdge = {
+ id: string
+ source: string
+ target: string
+ label: string
+ caption?: string
+}
+
+export type Path = {
+ ids: string[]
+ nodes: PathNode[]
+ edges: PathEdge[]
+}
diff --git a/flowsint-app/src/workers/pathfinder.worker.ts b/flowsint-app/src/workers/pathfinder.worker.ts
new file mode 100644
index 00000000..b92d5649
--- /dev/null
+++ b/flowsint-app/src/workers/pathfinder.worker.ts
@@ -0,0 +1,115 @@
+type WorkerNode = { id: string; nodeLabel: string; nodeType: string }
+type WorkerEdge = { id: string; source: string; target: string; label: string; caption?: string }
+
+interface PathfinderMessage {
+ nodes: WorkerNode[]
+ edges: WorkerEdge[]
+ sourceId: string
+ targetId: string
+}
+
+function bfs(
+ adjacency: Map<string, { nodeId: string; edgeId: string }[]>,
+ sourceId: string,
+ targetId: string
+): string[] | null {
+ if (sourceId === targetId) return [sourceId]
+
+ const visited = new Set<string>([sourceId])
+ const parent = new Map<string, string>()
+ const queue: string[] = [sourceId]
+
+ while (queue.length > 0) {
+ const current = queue.shift()!
+ const neighbors = adjacency.get(current)
+ if (!neighbors) continue
+
+ for (const { nodeId } of neighbors) {
+ if (visited.has(nodeId)) continue
+ visited.add(nodeId)
+ parent.set(nodeId, current)
+
+ if (nodeId === targetId) {
+ // Reconstruct path
+ const path: string[] = []
+ let node: string | undefined = targetId
+ while (node !== undefined) {
+ path.unshift(node)
+ node = parent.get(node)
+ }
+ return path
+ }
+
+ queue.push(nodeId)
+ }
+ }
+
+ return null
+}
+
+self.onmessage = (event: MessageEvent<PathfinderMessage>) => {
+ try {
+ const { nodes, edges, sourceId, targetId } = event.data
+
+ // Build adjacency list (undirected)
+ const adjacency = new Map<string, { nodeId: string; edgeId: string }[]>()
+ for (const node of nodes) {
+ adjacency.set(node.id, [])
+ }
+ for (const edge of edges) {
+ adjacency.get(edge.source)?.push({ nodeId: edge.target, edgeId: edge.id })
+ adjacency.get(edge.target)?.push({ nodeId: edge.source, edgeId: edge.id })
+ }
+
+ const pathIds = bfs(adjacency, sourceId, targetId)
+
+ if (!pathIds) {
+ self.postMessage({ type: 'complete', result: null })
+ return
+ }
+
+ // Build node map for quick lookup
+ const nodeMap = new Map(nodes.map((n) => [n.id, n]))
+
+ // Collect path nodes
+ const pathNodes = pathIds.map((id) => {
+ const n = nodeMap.get(id)!
+ return { id: n.id, label: n.nodeLabel, node_type: n.nodeType }
+ })
+
+ // Collect path edges (edges between consecutive path nodes)
+ const pathEdges: { id: string; source: string; target: string; label: string; caption?: string }[] = []
+
+ for (let i = 0; i < pathIds.length - 1; i++) {
+ const a = pathIds[i]
+ const b = pathIds[i + 1]
+ // Find the edge connecting a and b
+ const edge = edges.find(
+ (e) => (e.source === a && e.target === b) || (e.source === b && e.target === a)
+ )
+ if (edge) {
+ pathEdges.push({
+ id: edge.id,
+ source: edge.source,
+ target: edge.target,
+ label: edge.label,
+ caption: edge.caption,
+ })
+ }
+ }
+
+ self.postMessage({
+ type: 'complete',
+ result: {
+ ids: pathIds,
+ nodes: pathNodes,
+ edges: pathEdges,
+ },
+ })
+ } catch (error) {
+ self.postMessage({
+ type: 'error',
+ error: error instanceof Error ? error.message : 'Unknown error',
+ })
+ }
+}