- ),
- },
- // 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 (