2025-12-20 23:15:49 -08:00
|
|
|
"use client";
|
|
|
|
|
|
|
|
|
|
import type { FC } from "react";
|
|
|
|
|
import { useState } from "react";
|
2025-12-21 00:04:52 -08:00
|
|
|
import { SourceDetailPanel } from "@/components/new-chat/source-detail-panel";
|
2025-12-20 23:15:49 -08:00
|
|
|
|
|
|
|
|
interface InlineCitationProps {
|
|
|
|
|
chunkId: number;
|
2025-12-21 00:04:52 -08:00
|
|
|
citationNumber: number;
|
2026-01-09 18:21:59 +02:00
|
|
|
isDocsChunk?: boolean;
|
2025-12-20 23:15:49 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Inline citation component for the new chat.
|
2025-12-21 00:04:52 -08:00
|
|
|
* Renders a clickable numbered badge that opens the SourceDetailPanel with document chunk details.
|
2026-01-09 18:21:59 +02:00
|
|
|
* Supports both regular knowledge base chunks and Surfsense documentation chunks.
|
2025-12-20 23:15:49 -08:00
|
|
|
*/
|
2026-01-12 14:17:15 -08:00
|
|
|
export const InlineCitation: FC<InlineCitationProps> = ({
|
|
|
|
|
chunkId,
|
|
|
|
|
citationNumber,
|
|
|
|
|
isDocsChunk = false,
|
|
|
|
|
}) => {
|
2025-12-20 23:15:49 -08:00
|
|
|
const [isOpen, setIsOpen] = useState(false);
|
|
|
|
|
|
|
|
|
|
return (
|
2025-12-21 00:04:52 -08:00
|
|
|
<SourceDetailPanel
|
2025-12-20 23:15:49 -08:00
|
|
|
open={isOpen}
|
|
|
|
|
onOpenChange={setIsOpen}
|
|
|
|
|
chunkId={chunkId}
|
2026-01-09 18:21:59 +02:00
|
|
|
sourceType={isDocsChunk ? "SURFSENSE_DOCS" : ""}
|
|
|
|
|
title={isDocsChunk ? "Surfsense Documentation" : "Source"}
|
2025-12-20 23:15:49 -08:00
|
|
|
description=""
|
|
|
|
|
url=""
|
2026-01-09 18:21:59 +02:00
|
|
|
isDocsChunk={isDocsChunk}
|
2025-12-20 23:15:49 -08:00
|
|
|
>
|
2025-12-21 00:04:52 -08:00
|
|
|
<span
|
|
|
|
|
onClick={() => setIsOpen(true)}
|
|
|
|
|
onKeyDown={(e) => e.key === "Enter" && setIsOpen(true)}
|
|
|
|
|
className="text-[10px] font-bold bg-primary/80 hover:bg-primary text-primary-foreground rounded-full min-w-4 h-4 px-1 inline-flex items-center justify-center align-super cursor-pointer transition-colors ml-0.5"
|
|
|
|
|
title={`View source #${citationNumber}`}
|
|
|
|
|
role="button"
|
|
|
|
|
tabIndex={0}
|
|
|
|
|
>
|
|
|
|
|
{citationNumber}
|
|
|
|
|
</span>
|
|
|
|
|
</SourceDetailPanel>
|
2025-12-20 23:15:49 -08:00
|
|
|
);
|
|
|
|
|
};
|