MCPcopy
hub / github.com/marimo-team/marimo / createNewThread

Function createNewThread

frontend/src/components/chat/chat-panel.tsx:603–650  ·  view source on GitHub ↗
(
    initialMessage: string,
    initialAttachments?: File[],
  )

Source from the content-addressed store, hash-verified

601 }, [activeChatId]);
602
603 const createNewThread = async (
604 initialMessage: string,
605 initialAttachments?: File[],
606 ) => {
607 const now = Date.now();
608 const newChat: Chat = {
609 id: chatId as ChatId,
610 title: generateChatTitle(initialMessage),
611 messages: [],
612 createdAt: now,
613 updatedAt: now,
614 };
615
616 // Create new chat and set as active
617 setChatState((prev) => {
618 const newChats = new Map(prev.chats);
619 newChats.set(newChat.id, newChat);
620 const newState = {
621 ...prev,
622 chats: newChats,
623 activeChatId: newChat.id,
624 };
625 return newState;
626 });
627
628 const fileParts =
629 initialAttachments && initialAttachments.length > 0
630 ? await convertToFileUIPart(initialAttachments)
631 : undefined;
632 const { contextPart, attachments } =
633 await resolveChatContext(initialMessage);
634
635 // Trigger AI conversation with append
636 sendMessage({
637 role: "user",
638 parts: [
639 {
640 type: "text" as const,
641 text: initialMessage,
642 },
643 ...(contextPart ? [contextPart] : []),
644 ...(fileParts ?? []),
645 ...attachments,
646 ],
647 });
648 clearFiles();
649 setInput("");
650 };
651
652 const handleNewChat = useEvent(() => {
653 setActiveChat(null);

Callers 1

ChatPanelBodyFunction · 0.85

Calls 6

generateChatTitleFunction · 0.90
convertToFileUIPartFunction · 0.90
resolveChatContextFunction · 0.90
clearFilesFunction · 0.85
setMethod · 0.65
nowMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…