import Markdown from "marked-react" import { useEffect, useState } from "react" import { useClient } from "urql" import { ScrollArea } from "~/components/ui/scroll-area" import { Separator } from "~/components/ui/separator" import { graphql } from "~/generated/gql" import type { AnswersQuery, Subscription } from "~/generated/graphql" const GenerateSummarySubscription = graphql(` subscription generateSummary( $query: String! $docIds: [String!]! ) { generateSummary( query: $query docIds: $docIds ) { summary } } `) type AnswerSummaryProps = { query: string items: NonNullable["answers"]> } export function AnswerSummary({ query, items }: AnswerSummaryProps) { const client = useClient() const [summary, setSummary] = useState() useEffect(() => { setSummary(undefined) const { unsubscribe } = client .subscription(GenerateSummarySubscription, { query, docIds: items.map((x) => x.docId).slice(0, 10), }) .subscribe((result) => { setSummary( (prev) => (prev ?? "") + (result.data?.generateSummary?.summary ?? ""), ) }) return () => { unsubscribe() } }, [query, items, client]) return (

TL;DR

{summary ? (
{summary}
) : (
検索結果がまだありません
)}
) }