(
initialMessage: string,
initialAttachments?: File[],
)
| 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); |
no test coverage detected
searching dependent graphs…