Skip to content

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

fix(frontend): type the chat-service API boundary

dextmorgnf47426d4f2d1
diff --git a/flowsint-app/src/api/chat-service.ts b/flowsint-app/src/api/chat-service.ts
index 449411e6..822fe35f 100644
--- a/flowsint-app/src/api/chat-service.ts
+++ b/flowsint-app/src/api/chat-service.ts
@@ -1,28 +1,29 @@
import { fetchWithAuth } from './api'
+import type { Chat, ChatDetail } from '@/types/chat'
export const chatCRUDService = {
- get: async (): Promise<any> => {
+ get: async (): Promise<Chat[]> => {
return fetchWithAuth('/api/chats', {
method: 'GET'
})
},
- getByInvestigationId: async (investigationId: string): Promise<any> => {
+ getByInvestigationId: async (investigationId: string): Promise<Chat[]> => {
return fetchWithAuth(`/api/chats/investigation/${investigationId}`, {
method: 'GET'
})
},
- getById: async (chatId: string): Promise<any> => {
+ getById: async (chatId: string): Promise<ChatDetail> => {
return fetchWithAuth(`/api/chats/${chatId}`, {
method: 'GET'
})
},
- create: async (body: BodyInit): Promise<any> => {
+ create: async (body: BodyInit): Promise<Chat> => {
return fetchWithAuth(`/api/chats/create`, {
method: 'POST',
body: body
})
},
- delete: async (chatId: string): Promise<any> => {
+ delete: async (chatId: string): Promise<unknown> => {
return fetchWithAuth(`/api/chats/${chatId}`, {
method: 'DELETE'
})
diff --git a/flowsint-app/src/components/chat/chat-history.tsx b/flowsint-app/src/components/chat/chat-history.tsx
index c4a00841..a8186ac4 100644
--- a/flowsint-app/src/components/chat/chat-history.tsx
+++ b/flowsint-app/src/components/chat/chat-history.tsx
@@ -1,22 +1,24 @@
import { chatCRUDService } from '@/api/chat-service'
-import { useQuery } from '@tanstack/react-query'
+import { useQuery, type UseMutationResult } from '@tanstack/react-query'
import { SkeletonList } from '../shared/skeleton-list'
import { Button } from '../ui/button'
import { ArrowLeft, Trash, Sparkles } from 'lucide-react'
import { Chat } from '@/types'
-import { useCallback } from 'react'
+import { useCallback, type Dispatch, type SetStateAction } from 'react'
import { formatDistanceToNow } from 'date-fns'
-import { useConfirm } from '../use-confirm-dialog'
+import { useConfirm, type ConfirmProps } from '../use-confirm-dialog'
import { useChatState } from '@/stores/use-chat-store'
+type DeleteChatMutation = UseMutationResult<unknown, Error, string>
+
const ChatHistory = ({
setView,
deleteChatMutation,
handleCreateNewChat
}: {
- setView: any
- deleteChatMutation: any
- handleCreateNewChat: any
+ setView: Dispatch<SetStateAction<'chat' | 'history'>>
+ deleteChatMutation: DeleteChatMutation
+ handleCreateNewChat: () => void
}) => {
const { confirm } = useConfirm()
const setCurrentChatId = useChatState((s) => s.setCurrentChatId)
@@ -98,9 +100,9 @@ const ChatItem = ({
switchToChat
}: {
chat: Chat
- confirm: any
- deleteChatMutation: any
- switchToChat: any
+ confirm: (props: ConfirmProps) => Promise<boolean>
+ deleteChatMutation: DeleteChatMutation
+ switchToChat: (chatId: string) => void
}) => {
const handleDeleteChat = useCallback(
async (e: { stopPropagation: () => void }) => {
diff --git a/flowsint-app/src/components/use-confirm-dialog.tsx b/flowsint-app/src/components/use-confirm-dialog.tsx
index f257f2d1..b73243f0 100644
--- a/flowsint-app/src/components/use-confirm-dialog.tsx
+++ b/flowsint-app/src/components/use-confirm-dialog.tsx
@@ -23,7 +23,7 @@ import React, {
const defaultFunction = (): Promise<boolean> => Promise.resolve(true)
// Define the props that the ConfirmDialog will use
-interface ConfirmProps {
+export interface ConfirmProps {
title: string
message: string
}
diff --git a/flowsint-app/src/types/chat.ts b/flowsint-app/src/types/chat.ts
index 841c3a4f..8577191d 100644
--- a/flowsint-app/src/types/chat.ts
+++ b/flowsint-app/src/types/chat.ts
@@ -36,6 +36,11 @@ export interface Chat {
last_updated_at: string
}
+// getById returns the chat's messages inline, unlike the list endpoints.
+export interface ChatDetail extends Chat {
+ messages: ChatMessage[]
+}
+
export function toUIMessage(msg: ChatMessage): UIMessage {
return {
id: msg.id,