From ee69ce7cc10db828424b468e7b54b3f06b18e22c Mon Sep 17 00:00:00 2001 From: Thuc Pham <51660321+thucpn@users.noreply.github.com> Date: Tue, 25 Feb 2025 09:38:31 +0700 Subject: [PATCH] bump: chat-ui and tailwind v4 (#509) --- .changeset/rare-eyes-protect.md | 5 + .../nextjs/app/components/header.tsx | 4 +- .../nextjs/app/components/ui/button.tsx | 2 +- .../nextjs/app/components/ui/card.tsx | 2 +- .../app/components/ui/chat/chat-avatar.tsx | 4 +- .../ui/chat/chat-message-content.tsx | 49 +++------- .../ui/chat/custom/deep-research-card.tsx | 31 +++--- .../components/ui/chat/tools/chat-tools.tsx | 10 +- .../nextjs/app/components/ui/input.tsx | 2 +- .../nextjs/app/components/ui/select.tsx | 4 +- .../nextjs/app/components/ui/tabs.tsx | 4 +- .../nextjs/app/components/ui/textarea.tsx | 2 +- .../types/streaming/nextjs/app/globals.css | 94 ++++++++++++++++++- templates/types/streaming/nextjs/package.json | 6 +- .../types/streaming/nextjs/postcss.config.js | 3 +- .../types/streaming/nextjs/tailwind.config.ts | 82 ---------------- 16 files changed, 142 insertions(+), 162 deletions(-) create mode 100644 .changeset/rare-eyes-protect.md delete mode 100644 templates/types/streaming/nextjs/tailwind.config.ts diff --git a/.changeset/rare-eyes-protect.md b/.changeset/rare-eyes-protect.md new file mode 100644 index 000000000..7bada6858 --- /dev/null +++ b/.changeset/rare-eyes-protect.md @@ -0,0 +1,5 @@ +--- +"create-llama": patch +--- + +bump: chat-ui and tailwind v4 diff --git a/templates/types/streaming/nextjs/app/components/header.tsx b/templates/types/streaming/nextjs/app/components/header.tsx index f02ce732e..2e5ce8f8a 100644 --- a/templates/types/streaming/nextjs/app/components/header.tsx +++ b/templates/types/streaming/nextjs/app/components/header.tsx @@ -3,11 +3,11 @@ import Image from "next/image"; export default function Header() { return (
-

+

Get started by editing  app/page.tsx

-
+
+
); } return ( -
+
- ), - }, - // add the deep research card - { - position: ContentPosition.CHAT_EVENTS, - component: , - }, - { - // add the tool annotations after events - position: ContentPosition.AFTER_EVENTS, - component: , - }, - ]; return ( - + + + + + + + + + + + ); } diff --git a/templates/types/streaming/nextjs/app/components/ui/chat/custom/deep-research-card.tsx b/templates/types/streaming/nextjs/app/components/ui/chat/custom/deep-research-card.tsx index 03d0bd8c1..bc6118e61 100644 --- a/templates/types/streaming/nextjs/app/components/ui/chat/custom/deep-research-card.tsx +++ b/templates/types/streaming/nextjs/app/components/ui/chat/custom/deep-research-card.tsx @@ -1,6 +1,6 @@ "use client"; -import { Message } from "@llamaindex/chat-ui"; +import { getCustomAnnotation, useChatMessage } from "@llamaindex/chat-ui"; import { AlertCircle, CheckCircle2, @@ -54,7 +54,6 @@ type DeepResearchCardState = { }; interface DeepResearchCardProps { - message: Message; className?: string; } @@ -143,25 +142,19 @@ const deepResearchEventsToState = ( ); }; -export function DeepResearchCard({ - message, - className, -}: DeepResearchCardProps) { - const deepResearchEvents = message.annotations as - | DeepResearchEvent[] - | undefined; - const hasDeepResearchEvents = deepResearchEvents?.some( - (event) => event.type === "deep_research_event", - ); +export function DeepResearchCard({ className }: DeepResearchCardProps) { + const { message } = useChatMessage(); - const state = useMemo( - () => deepResearchEventsToState(deepResearchEvents), - [deepResearchEvents], - ); + const state = useMemo(() => { + const deepResearchEvents = getCustomAnnotation( + message.annotations, + (annotation) => annotation?.type === "deep_research_event", + ); + if (!deepResearchEvents.length) return null; + return deepResearchEventsToState(deepResearchEvents); + }, [message.annotations]); - if (!hasDeepResearchEvents) { - return null; - } + if (!state) return null; return ( diff --git a/templates/types/streaming/nextjs/app/components/ui/chat/tools/chat-tools.tsx b/templates/types/streaming/nextjs/app/components/ui/chat/tools/chat-tools.tsx index 71acda6d6..a7e4eb218 100644 --- a/templates/types/streaming/nextjs/app/components/ui/chat/tools/chat-tools.tsx +++ b/templates/types/streaming/nextjs/app/components/ui/chat/tools/chat-tools.tsx @@ -1,7 +1,8 @@ import { Message, MessageAnnotation, - getAnnotationData, + getChatUIAnnotation, + useChatMessage, useChatUI, } from "@llamaindex/chat-ui"; import { JSONValue } from "ai"; @@ -9,10 +10,11 @@ import { useMemo } from "react"; import { Artifact, CodeArtifact } from "./artifact"; import { WeatherCard, WeatherData } from "./weather-card"; -export function ToolAnnotations({ message }: { message: Message }) { +export function ToolAnnotations() { // TODO: This is a bit of a hack to get the artifact version. better to generate the version in the tool call and // store it in CodeArtifact const { messages } = useChatUI(); + const { message } = useChatMessage(); const artifactVersion = useMemo( () => getArtifactVersion(messages, message), [messages, message], @@ -20,7 +22,7 @@ export function ToolAnnotations({ message }: { message: Message }) { // Get the tool data from the message annotations const annotations = message.annotations as MessageAnnotation[] | undefined; const toolData = annotations - ? (getAnnotationData(annotations, "tools") as unknown as ToolData[]) + ? (getChatUIAnnotation(annotations, "tools") as unknown as ToolData[]) : null; return toolData?.[0] ? ( @@ -87,7 +89,7 @@ function getArtifactVersion( let versionIndex = 1; for (const m of messages) { const toolData = m.annotations - ? (getAnnotationData(m.annotations, "tools") as unknown as ToolData[]) + ? (getChatUIAnnotation(m.annotations, "tools") as unknown as ToolData[]) : null; if (toolData?.some((t) => t.toolCall.name === "artifact")) { diff --git a/templates/types/streaming/nextjs/app/components/ui/input.tsx b/templates/types/streaming/nextjs/app/components/ui/input.tsx index edfa129e6..10091d957 100644 --- a/templates/types/streaming/nextjs/app/components/ui/input.tsx +++ b/templates/types/streaming/nextjs/app/components/ui/input.tsx @@ -11,7 +11,7 @@ const Input = React.forwardRef( span]:line-clamp-1", + "flex h-10 w-full items-center justify-between rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus:outline-hidden focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1", className, )} {...props} @@ -117,7 +117,7 @@ const SelectItem = React.forwardRef< ( return (