Skip to content

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

feat(app): chat context

dextmorgn19ee40c46d18
diff --git a/flowsint-api/app/api/routes/chat.py b/flowsint-api/app/api/routes/chat.py
index c1bccdd4..f58eb41e 100644
--- a/flowsint-api/app/api/routes/chat.py
+++ b/flowsint-api/app/api/routes/chat.py
@@ -1,16 +1,17 @@
-from fastapi import APIRouter, HTTPException, Depends, status
-from fastapi.responses import StreamingResponse
-from pydantic import BaseModel
-from uuid import UUID
from typing import Dict, List, Optional
-from sqlalchemy.orm import Session
+from uuid import UUID
-from flowsint_core.core.postgre_db import get_db
+from fastapi import APIRouter, Depends, HTTPException, status
+from fastapi.responses import StreamingResponse
from flowsint_core.core.models import Profile
+from flowsint_core.core.postgre_db import get_db
from flowsint_core.core.services import (
- create_chat_service,
NotFoundError,
+ create_chat_service,
)
+from pydantic import BaseModel
+from sqlalchemy.orm import Session
+
from app.api.deps import get_current_user
from app.api.schemas.chat import ChatCreate, ChatRead
@@ -19,7 +20,7 @@ router = APIRouter()
class ChatRequest(BaseModel):
prompt: str
- context: Optional[List[Dict]] = None
+ context: Optional[List[str]] = None
@router.get("/", response_model=List[ChatRead])
diff --git a/flowsint-app/src/components/chat/chat-prompt.tsx b/flowsint-app/src/components/chat/chat-prompt.tsx
index 8cb4ae18..286fa664 100644
--- a/flowsint-app/src/components/chat/chat-prompt.tsx
+++ b/flowsint-app/src/components/chat/chat-prompt.tsx
@@ -13,7 +13,10 @@ interface ChatPanelProps {
}
const formatContext = (context: ChatContextFormat[]): string[] => {
- return context.map((item) => `${item.fromLabel} -> ${item.label} -> ${item.toLabel}`)
+ return context.map((item) => {
+ if (item.type === 'relation') return `${item.fromLabel} -> ${item.label} -> ${item.toLabel}`
+ return item.nodeLabel
+ })
}
export const ChatPanel = ({ onSend, isLoading }: ChatPanelProps) => {
@@ -123,8 +126,22 @@ export const ContextList = memo(({ context }: { context: ChatContextFormat[] })
return (
<div className="flex flex-nowrap overflow-x-auto hide-scrollbar gap-1.5 items-center px-1">
{context.map((item: ChatContextFormat, index: number) => {
- const fromColor = item.fromColor ?? colors[item?.fromType]
- const toColor = item.toColor ?? colors[item?.toType]
+ if (item.type === 'node') {
+ const color = item.nodeColor ?? colors[item.nodeType]
+ return (
+ <Badge
+ key={index}
+ variant="secondary"
+ className="flex items-center border border-border gap-1.5 text-xs"
+ >
+ <span style={{ background: color }} className="w-1.5 h-1.5 rounded-full" />
+ {item.nodeLabel || 'Unknown'}
+ </Badge>
+ )
+ }
+
+ const fromColor = item.fromColor ?? colors[item.fromType]
+ const toColor = item.toColor ?? colors[item.toType]
return (
<Badge
diff --git a/flowsint-app/src/stores/graph-store.ts b/flowsint-app/src/stores/graph-store.ts
index 9d67e0b3..2e425f0c 100644
--- a/flowsint-app/src/stores/graph-store.ts
+++ b/flowsint-app/src/stores/graph-store.ts
@@ -446,8 +446,9 @@ export const useGraphStore = create<GraphState>()(
edgesMapping.forEach((edge) => {
const fromNode = selectedNodesMapping.get(edge.source)
const toNode = selectedNodesMapping.get(edge.target)
- if (fromNode && toNode)
+ if (fromNode && toNode) {
context.push({
+ type: 'relation',
fromLabel: fromNode.nodeLabel,
fromType: fromNode.nodeType,
fromColor: fromNode.nodeColor,
@@ -456,7 +457,18 @@ export const useGraphStore = create<GraphState>()(
toColor: toNode.nodeColor,
label: edge.label
})
+ selectedNodesMapping.delete(edge.source)
+ selectedNodesMapping.delete(edge.target)
+ }
})
+ selectedNodesMapping.forEach((node) =>
+ context.push({
+ type: 'node',
+ nodeType: node.nodeType,
+ nodeLabel: node.nodeLabel,
+ nodeColor: node?.nodeColor
+ })
+ )
return context
},
diff --git a/flowsint-app/src/types/chat.ts b/flowsint-app/src/types/chat.ts
index 66fce917..841c3a4f 100644
--- a/flowsint-app/src/types/chat.ts
+++ b/flowsint-app/src/types/chat.ts
@@ -9,7 +9,10 @@ export interface ChatMessage {
chatId?: string
}
-export type ChatContextFormat = {
+export type ChatContextFormat = ChatContextFormatRel | ChatContextFormatNode
+
+export type ChatContextFormatRel = {
+ type: 'relation'
fromType: string
fromLabel: string
fromColor: string | null
@@ -18,6 +21,12 @@ export type ChatContextFormat = {
toColor: string | null
label: string
}
+export type ChatContextFormatNode = {
+ type: 'node'
+ nodeLabel: string
+ nodeColor: string | null
+ nodeType: string
+}
export interface Chat {
id: string