MCPcopy Create free account
hub / github.com/SecureAI-Tools/SecureAI-Tools / Chat

Function Chat

apps/web/lib/fe/components/chat.tsx:152–469  ·  view source on GitHub ↗
({
  chat,
  chatMessages,
  documents,
  citations,
  onJumpToPage,
}: {
  chat: ChatResponse;
  chatMessages: ChatMessageResponse[];
  documents?: DocumentsWithIndexingStatus[];
  citations?: CitationResponse[];
  onJumpToPage?: (docId: string, pageIndex: number) => void;
})

Source from the content-addressed store, hash-verified

150};
151
152export function Chat({
153 chat,
154 chatMessages,
155 documents,
156 citations,
157 onJumpToPage,
158}: {
159 chat: ChatResponse;
160 chatMessages: ChatMessageResponse[];
161 documents?: DocumentsWithIndexingStatus[];
162 citations?: CitationResponse[];
163 onJumpToPage?: (docId: string, pageIndex: number) => void;
164}) {
165 const chatId = Id.from<ChatResponse>(chat.id);
166
167 const [title, setTitle] = useState<string | undefined>(DEFAULT_CHAT_TITLE);
168 const [isTitleGenerating, setIsTitleGenerating] = useState<boolean>(false);
169 const [isProcessingDocuments, setIsProcessingDocuments] =
170 useState<boolean>(false);
171 const [numberOfProcessedDocuments, setNumberOfProcessedDocuments] =
172 useState(0);
173 const [processingDocumentName, setProcessingDocumentName] = useState("");
174 const [processingDocumentStatus, setProcessingDocumentStatus] = useState("");
175 const [processingDocumentsError, setProcessingDocumentsError] = useState("");
176 const [messageCitations, setMessageCitations] = useState<
177 Map<string /* messageId */, CitationResponse[]>
178 >(toCitationMap(citations));
179 const formRef = useRef(null);
180 const messagesRef = useRef<Message[]>([]);
181 const {
182 messages,
183 setMessages,
184 input,
185 handleInputChange,
186 handleSubmit,
187 append,
188 isLoading,
189 } = useChat({
190 id: chat.id,
191 api: postChatMessagesGenerateApiPath(chatId),
192 onFinish: async (message) => {
193 if (message.role !== "assistant") {
194 return;
195 }
196
197 // Fetch latest message from backend to get the correct message id
198 const { response: chatMessageResponses } = await get<
199 ChatMessageResponse[]
200 >(
201 getChatMessagesApiPath({
202 chatId: chatId,
203 ordering: {
204 orderBy: "createdAt",
205 order: "desc",
206 },
207 pagination: {
208 page: 1,
209 pageSize: 1,

Callers

nothing calls this directly

Calls 12

getChatMessagesApiPathFunction · 0.90
isEmptyFunction · 0.90
toCitationMapFunction · 0.85
indexDocumentsFunction · 0.85
postChatMessageFunction · 0.70
handleSubmitFunction · 0.70
getMethod · 0.65
fromMethod · 0.45

Tested by

no test coverage detected