Skip to content

An AI-powered search engine with a generative UI

Merge branch 'main' of https://github.com/miurla/morphic into fixes

Lee Robinsond357c63f8f97
diff --cc app/page.tsx
index 1ceeeb1b,e39980fd..9e90758a
--- a/app/page.tsx
+++ b/app/page.tsx
@@@ -1,5 -1,14 +1,12 @@@
import { Chat } from '@/components/chat'
+ import { nanoid } from 'ai'
+ import { AI } from './actions'
-export const runtime = 'edge'
-
export default function Page() {
- return <Chat />
+ const id = nanoid()
+ return (
+ <AI initialAIState={{ chatId: id, messages: [] }}>
+ <Chat id={id} />
+ </AI>
+ )
}
diff --cc bun.lockb
index 998c9859,0e7c92c1..64ece83d
Binary files differ
diff --cc components/chat-messages.tsx
index c8ddd0d8,88b797c8..6bfa3642
--- a/components/chat-messages.tsx
+++ b/components/chat-messages.tsx
@@@ -1,11 -1,41 +1,43 @@@
+'use client'
+
import { StreamableValue, useUIState } from 'ai/rsc'
- import type { AI } from '@/app/action'
+ import type { AI, UIState } from '@/app/actions'
import { CollapsibleMessage } from './collapsible-message'
- export function ChatMessages() {
- const [messages, setMessages] = useUIState<typeof AI>()
+ interface ChatMessagesProps {
+ messages: UIState
+ }
+
+ export function ChatMessages({ messages }: ChatMessagesProps) {
+ if (!messages.length) {
+ return null
+ }
+
+ // Group messages based on ID, and if there are multiple messages with the same ID, combine them into one message
+ const groupedMessages = messages.reduce(
+ (acc: { [key: string]: any }, message) => {
+ if (!acc[message.id]) {
+ acc[message.id] = {
+ id: message.id,
+ components: [],
+ isCollapsed: message.isCollapsed
+ }
+ }
+ acc[message.id].components.push(message.component)
+ return acc
+ },
+ {}
+ )
+
+ // Convert grouped messages into an array with explicit type
+ const groupedMessagesArray = Object.values(groupedMessages).map(group => ({
+ ...group,
+ components: group.components as React.ReactNode[]
+ })) as {
+ id: string
+ components: React.ReactNode[]
+ isCollapsed?: StreamableValue<boolean>
+ }[]
return (
<>
diff --cc components/chat-panel.tsx
index 25247ab3,a64dda4a..1dda2b63
--- a/components/chat-panel.tsx
+++ b/components/chat-panel.tsx
@@@ -1,8 -1,7 +1,9 @@@
+'use client'
+
import { useEffect, useState, useRef } from 'react'
- import type { AI } from '@/app/action'
- import { useUIState, useActions, useAIState } from 'ai/rsc'
+ import { useRouter } from 'next/navigation'
+ import type { AI, UIState } from '@/app/actions'
+ import { useUIState, useActions } from 'ai/rsc'
import { cn } from '@/lib/utils'
import { UserMessage } from './user-message'
import { Input } from './ui/input'