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

Function handleSubmit

apps/web/lib/fe/components/new-chat.tsx:59–102  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

57 const [toasts, addToast] = useToasts();
58
59 const handleSubmit = async () => {
60 setIsSubmitting(true);
61
62 try {
63 const selectedDocumentsList = Array.from(selectedDocuments.values()).flat();
64
65 const chatType: ChatType =
66 selectedDocumentsList.length === 0
67 ? ChatType.CHAT_WITH_LLM
68 : ChatType.CHAT_WITH_DOCS;
69
70 let documentCollectionId: Id<DocumentCollectionResponse> | undefined =
71 undefined;
72 if (chatType === ChatType.CHAT_WITH_DOCS) {
73 const documentCollection = await createDocumentCollection(orgSlug, {});
74 documentCollectionId = Id.from(documentCollection.id);
75 await createDocuments(documentCollectionId, selectedDocumentsList);
76 }
77
78 const chatResponse = await postChat(orgSlug, {
79 type: chatType,
80 documentCollectionId: documentCollectionId?.toString(),
81 });
82 const chatId = Id.from(chatResponse.id);
83
84 const chatMessageResponse = await postChatMessage(chatId, {
85 message: {
86 content: input,
87 role: "user",
88 },
89 });
90
91 router.push(
92 `${FrontendRoutes.getChatRoute(orgSlug, chatId)}?src=new-chat`,
93 );
94 } catch (e) {
95 console.log("couldn't create chat/chat-message", e);
96 addToast({
97 type: "failure",
98 children: <p>Something went wrong. Please try again later.</p>,
99 });
100 setIsSubmitting(false);
101 }
102 };
103
104 // Fetch organization
105 const { data: organizationResponse, error: fetchOrganizationError } = useSWR(

Callers 2

NewChatFunction · 0.70
ChatFunction · 0.70

Calls 6

createDocumentCollectionFunction · 0.90
postChatFunction · 0.90
postChatMessageFunction · 0.90
toStringMethod · 0.80
createDocumentsFunction · 0.70
fromMethod · 0.45

Tested by

no test coverage detected