Skip to content

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

feat(app): add input and output type to enricher template

dextmorgnaacbd5ac8573
diff --git a/flowsint-app/src/api/template-service.ts b/flowsint-app/src/api/template-service.ts
index 79e18a18..5c9fa087 100644
--- a/flowsint-app/src/api/template-service.ts
+++ b/flowsint-app/src/api/template-service.ts
@@ -91,10 +91,18 @@ export const templateService = {
})
},
- generate: async (prompt: string): Promise<GenerateTemplateResponse> => {
+ generate: async (
+ prompt: string,
+ inputType?: string,
+ outputType?: string
+ ): Promise<GenerateTemplateResponse> => {
return fetchWithAuth('/api/enrichers/templates/generate', {
method: 'POST',
- body: JSON.stringify({ prompt })
+ body: JSON.stringify({
+ prompt,
+ input_type: inputType || null,
+ output_type: outputType || null
+ })
})
}
}
diff --git a/flowsint-app/src/components/templates/ai-chat-panel.tsx b/flowsint-app/src/components/templates/ai-chat-panel.tsx
index ea0cc32a..13462088 100644
--- a/flowsint-app/src/components/templates/ai-chat-panel.tsx
+++ b/flowsint-app/src/components/templates/ai-chat-panel.tsx
@@ -1,11 +1,4 @@
-import {
- useState,
- useRef,
- useCallback,
- useEffect,
- forwardRef,
- useImperativeHandle
-} from 'react'
+import { useState, useRef, useCallback, useEffect, forwardRef, useImperativeHandle } from 'react'
import {
Sparkles,
ArrowUp,
@@ -27,10 +20,6 @@ import { MemoizedMarkdown } from '@/components/chat/memoized-markdown'
import { templateService } from '@/api/template-service'
import { cn } from '@/lib/utils'
-// ---------------------------------------------------------------------------
-// Types
-// ---------------------------------------------------------------------------
-
interface ChatMessage {
id: string
role: 'user' | 'assistant'
@@ -42,6 +31,8 @@ interface ChatMessage {
interface AIChatPanelProps {
onApplyYaml: (yaml: string) => void
currentYaml: string
+ inputType: string
+ outputType: string
}
export interface AIChatPanelHandle {
@@ -49,22 +40,13 @@ export interface AIChatPanelHandle {
sendMessage: (prompt: string) => void
}
-// ---------------------------------------------------------------------------
-// Constants
-// ---------------------------------------------------------------------------
-
const SUGGESTED_PROMPTS = [
{ label: 'Generate a basic enricher', icon: Wand2 },
- { label: 'Add an HTTP source', icon: Globe },
- { label: 'Improve performance', icon: Zap }
+ { label: 'Add an HTTP source', icon: Globe }
]
-// ---------------------------------------------------------------------------
-// Main Component
-// ---------------------------------------------------------------------------
-
export const AIChatPanel = forwardRef<AIChatPanelHandle, AIChatPanelProps>(
- ({ onApplyYaml, currentYaml }, ref) => {
+ ({ onApplyYaml, currentYaml, inputType, outputType }, ref) => {
const [messages, setMessages] = useState<ChatMessage[]>([])
const [input, setInput] = useState('')
const [isLoading, setIsLoading] = useState(false)
@@ -92,7 +74,7 @@ export const AIChatPanel = forwardRef<AIChatPanelHandle, AIChatPanelProps>(
? `Current YAML template:\n\`\`\`yaml\n${currentYaml}\n\`\`\`\n\nUser request: ${text}`
: text
- const response = await templateService.generate(contextPrompt)
+ const response = await templateService.generate(contextPrompt, inputType, outputType)
const assistantMessage: ChatMessage = {
id: crypto.randomUUID(),
@@ -115,7 +97,7 @@ export const AIChatPanel = forwardRef<AIChatPanelHandle, AIChatPanelProps>(
setIsLoading(false)
}
},
- [input, isLoading, currentYaml]
+ [input, isLoading, currentYaml, inputType, outputType]
)
useImperativeHandle(
diff --git a/flowsint-app/src/components/templates/template-editor.tsx b/flowsint-app/src/components/templates/template-editor.tsx
index cdd7f4eb..4f1ae314 100644
--- a/flowsint-app/src/components/templates/template-editor.tsx
+++ b/flowsint-app/src/components/templates/template-editor.tsx
@@ -401,7 +401,13 @@ export function TemplateEditor({ templateId, initialContent, importedYaml }: Tem
</ResizablePanel>
<ResizableHandle className="hover:bg-primary/20 active:bg-primary/30 transition-colors data-[resize-handle-state=drag]:bg-primary/30" />
<ResizablePanel defaultSize={40} minSize={25}>
- <AIChatPanel ref={chatRef} onApplyYaml={handleApplyYaml} currentYaml={content} />
+ <AIChatPanel
+ ref={chatRef}
+ onApplyYaml={handleApplyYaml}
+ currentYaml={content}
+ inputType={validationResult.data?.input?.type ?? ''}
+ outputType={validationResult.data?.output?.type ?? ''}
+ />
</ResizablePanel>
</ResizablePanelGroup>
</div>
diff --git a/flowsint-app/src/components/ui/tag-input.tsx b/flowsint-app/src/components/ui/tag-input.tsx
new file mode 100644
index 00000000..996d4e4d
--- /dev/null
+++ b/flowsint-app/src/components/ui/tag-input.tsx
@@ -0,0 +1,196 @@
+import * as React from 'react'
+import { useState, useRef, useCallback, useEffect } from 'react'
+import { X } from 'lucide-react'
+import { Badge } from '@/components/ui/badge'
+import { cn } from '@/lib/utils'
+
+export interface TagInputProps {
+ value: string[]
+ onChange: (value: string[]) => void
+ options?: { label: string; value: string }[]
+ placeholder?: string
+ className?: string
+ disabled?: boolean
+}
+
+export function TagInput({
+ value = [],
+ onChange,
+ options,
+ placeholder = 'Add a value...',
+ className,
+ disabled = false
+}: TagInputProps) {
+ const [inputValue, setInputValue] = useState('')
+ const [isOpen, setIsOpen] = useState(false)
+ const [activeIndex, setActiveIndex] = useState(-1)
+ const inputRef = useRef<HTMLInputElement>(null)
+ const containerRef = useRef<HTMLDivElement>(null)
+ const listRef = useRef<HTMLDivElement>(null)
+
+ const filteredOptions = options?.filter(
+ (opt) =>
+ !value.includes(opt.value) &&
+ opt.label.toLowerCase().includes(inputValue.toLowerCase())
+ )
+
+ const showDropdown = isOpen && filteredOptions && filteredOptions.length > 0
+
+ const addTag = useCallback(
+ (tag: string) => {
+ const trimmed = tag.trim()
+ if (!trimmed || value.includes(trimmed)) return
+ onChange([...value, trimmed])
+ setInputValue('')
+ setActiveIndex(-1)
+ },
+ [value, onChange]
+ )
+
+ const removeTag = useCallback(
+ (tag: string) => {
+ onChange(value.filter((v) => v !== tag))
+ },
+ [value, onChange]
+ )
+
+ const handleKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {
+ if (e.key === 'Enter') {
+ e.preventDefault()
+ if (showDropdown && activeIndex >= 0 && filteredOptions[activeIndex]) {
+ addTag(filteredOptions[activeIndex].value)
+ } else if (inputValue.trim()) {
+ addTag(inputValue)
+ }
+ return
+ }
+
+ if (e.key === 'Backspace' && !inputValue && value.length > 0) {
+ removeTag(value[value.length - 1])
+ return
+ }
+
+ if (e.key === ',' || e.key === 'Tab') {
+ if (inputValue.trim()) {
+ e.preventDefault()
+ addTag(inputValue)
+ }
+ return
+ }
+
+ if (showDropdown) {
+ if (e.key === 'ArrowDown') {
+ e.preventDefault()
+ setActiveIndex((prev) =>
+ prev < filteredOptions!.length - 1 ? prev + 1 : 0
+ )
+ } else if (e.key === 'ArrowUp') {
+ e.preventDefault()
+ setActiveIndex((prev) =>
+ prev > 0 ? prev - 1 : filteredOptions!.length - 1
+ )
+ } else if (e.key === 'Escape') {
+ setIsOpen(false)
+ setActiveIndex(-1)
+ }
+ }
+ }
+
+ useEffect(() => {
+ if (activeIndex >= 0 && listRef.current) {
+ const item = listRef.current.children[activeIndex] as HTMLElement
+ item?.scrollIntoView({ block: 'nearest' })
+ }
+ }, [activeIndex])
+
+ useEffect(() => {
+ const handleClickOutside = (e: MouseEvent) => {
+ if (containerRef.current && !containerRef.current.contains(e.target as Node)) {
+ setIsOpen(false)
+ setActiveIndex(-1)
+ }
+ }
+ document.addEventListener('mousedown', handleClickOutside)
+ return () => document.removeEventListener('mousedown', handleClickOutside)
+ }, [])
+
+ const getLabel = (val: string) => {
+ if (!options) return val
+ return options.find((o) => o.value === val)?.label ?? val
+ }
+
+ return (
+ <div ref={containerRef} className="relative">
+ <div
+ className={cn(
+ 'border-input bg-background flex min-h-9 w-full flex-wrap items-center gap-1.5 rounded-md border px-3 py-1.5 text-sm transition-colors',
+ 'focus-within:border-ring focus-within:ring-ring/50 focus-within:ring-[3px]',
+ disabled && 'cursor-not-allowed opacity-50',
+ className
+ )}
+ onClick={() => inputRef.current?.focus()}
+ >
+ {value.map((tag) => (
+ <Badge
+ key={tag}
+ variant="secondary"
+ className="gap-1 pl-2 pr-1 py-0.5 text-xs font-normal animate-in fade-in-0 zoom-in-95"
+ >
+ <span className="max-w-[150px] truncate">{getLabel(tag)}</span>
+ {!disabled && (
+ <button
+ type="button"
+ onClick={(e) => {
+ e.stopPropagation()
+ removeTag(tag)
+ }}
+ className="text-muted-foreground hover:text-foreground rounded-sm p-0.5 transition-colors"
+ >
+ <X className="h-3 w-3" />
+ </button>
+ )}
+ </Badge>
+ ))}
+ <input
+ ref={inputRef}
+ type="text"
+ value={inputValue}
+ onChange={(e) => {
+ setInputValue(e.target.value)
+ setIsOpen(true)
+ setActiveIndex(-1)
+ }}
+ onFocus={() => setIsOpen(true)}
+ onKeyDown={handleKeyDown}
+ placeholder={value.length === 0 ? placeholder : ''}
+ disabled={disabled}
+ className="flex-1 min-w-[80px] bg-transparent outline-none placeholder:text-muted-foreground text-sm"
+ />
+ </div>
+
+ {showDropdown && (
+ <div
+ ref={listRef}
+ className="bg-popover text-popover-foreground absolute z-50 mt-1 max-h-[200px] w-full overflow-y-auto rounded-md border shadow-md animate-in fade-in-0 zoom-in-95"
+ >
+ {filteredOptions.map((opt, i) => (
+ <div
+ key={opt.value}
+ onMouseDown={(e) => {
+ e.preventDefault()
+ addTag(opt.value)
+ }}
+ onMouseEnter={() => setActiveIndex(i)}
+ className={cn(
+ 'flex cursor-pointer items-center px-3 py-1.5 text-sm transition-colors',
+ i === activeIndex && 'bg-accent text-accent-foreground'
+ )}
+ >
+ {opt.label}
+ </div>
+ ))}
+ </div>
+ )}
+ </div>
+ )
+}
diff --git a/flowsint-app/src/config.ts b/flowsint-app/src/config.ts
index 551e7156..e40bcf10 100644
--- a/flowsint-app/src/config.ts
+++ b/flowsint-app/src/config.ts
@@ -1,4 +1,4 @@
export const CONFIG = {
- ENRICHER_TEMPLATES_FEATURE_FLAG: false,
+ ENRICHER_TEMPLATES_FEATURE_FLAG: true,
SCANS_LIST_FEATURE_FLAG: false
}
diff --git a/flowsint-app/vite.config.ts b/flowsint-app/vite.config.ts
index 80212ac3..e97effac 100644
--- a/flowsint-app/vite.config.ts
+++ b/flowsint-app/vite.config.ts
@@ -49,6 +49,26 @@ export default defineConfig(({ mode }) => {
open: false,
host: '0.0.0.0',
port: 5173
+ },
+ build: {
+ rollupOptions: {
+ output: {
+ manualChunks: {
+ 'vendor-react': ['react', 'react-dom', 'react-dom/client'],
+ 'vendor-xyflow': ['@xyflow/react', '@xyflow/system'],
+ 'vendor-pixi': ['pixi.js'],
+ 'vendor-monaco': ['@monaco-editor/react'],
+ 'vendor-tiptap': [
+ '@tiptap/react',
+ '@tiptap/starter-kit',
+ '@tiptap/core',
+ ],
+ 'vendor-map': ['maplibre-gl'],
+ 'vendor-charts': ['recharts', 'd3', 'd3-force'],
+ 'vendor-motion': ['framer-motion'],
+ }
+ }
+ }
}
}
})