+ {conversation.length === 0 ? (
+
+
+ I'm trained on docs, examples, and other content. Ask me anything about Trigger.dev.
+
+ {exampleQuestions.map((question, index) => (
+ onExampleClick(question)}
+ variants={{
+ hidden: {
+ opacity: 0,
+ x: 20,
+ },
+ visible: {
+ opacity: 1,
+ x: 0,
+ transition: {
+ opacity: {
+ duration: 0.5,
+ ease: "linear",
+ },
+ x: {
+ type: "spring",
+ stiffness: 300,
+ damping: 25,
+ },
+ },
+ },
+ }}
+ >
+
+
+ {question}
+
+
+ ))}
+
+ ) : (
+ conversation.map((qa) => (
+
+ ))
+ )}
+ {conversation.length > 0 &&
+ !isPreparingAnswer &&
+ !isGeneratingAnswer &&
+ !error &&
+ !latestQA?.id && (
+
+
+ Answer generation was stopped
+
+
}
+ onClick={onReset}
+ className="w-fit pl-1.5"
+ iconSpacing="gap-x-1.5"
+ >
+ Reset chat
+
+
+ )}
+ {conversation.length > 0 &&
+ !isPreparingAnswer &&
+ !isGeneratingAnswer &&
+ !error &&
+ latestQA?.id && (
+
+ {hasFeedbackForLatestQA ? (
+
+
+ Thanks for your feedback!
+
+
+ ) : (
+
+
+ Was this helpful?
+
+
+
+
+
+
+ )}
+
}
+ onClick={onReset}
+ className="w-fit pl-1.5"
+ iconSpacing="gap-x-1.5"
+ >
+ Reset chat
+
+
+ )}
+ {isPreparingAnswer && (
+
+
+
Preparing answer…
+
+ )}
+ {error && (
+
+
+ Error generating answer:
+
+ {error} If the problem persists after retrying, please contact support.
+
+
+
+ }
+ onClick={onReset}
+ className="w-fit pl-1.5"
+ iconSpacing="gap-x-1.5"
+ >
+ Reset chat
+
+
+
+ )}
+
+ );
+}
+
+function ChatInterface({ initialQuery }: { initialQuery?: string }) {
+ const [message, setMessage] = useState("");
+ const [isExpanded, setIsExpanded] = useState(false);
+ const hasSubmittedInitialQuery = useRef(false);
+ const {
+ conversation,
+ submitQuery,
+ isGeneratingAnswer,
+ isPreparingAnswer,
+ resetConversation,
+ stopGeneration,
+ error,
+ addFeedback,
+ } = useChat();
+
+ useEffect(() => {
+ if (initialQuery && !hasSubmittedInitialQuery.current) {
+ hasSubmittedInitialQuery.current = true;
+ setIsExpanded(true);
+ submitQuery(initialQuery);
+ }
+ }, [initialQuery, submitQuery]);
+
+ const handleSubmit = (e: React.FormEvent) => {
+ e.preventDefault();
+ if (message.trim()) {
+ setIsExpanded(true);
+ submitQuery(message);
+ setMessage("");
+ }
+ };
+
+ const handleExampleClick = (question: string) => {
+ setIsExpanded(true);
+ submitQuery(question);
+ };
+
+ const handleReset = () => {
+ resetConversation();
+ setIsExpanded(false);
+ };
+
+ return (
+