Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion src/interface/web/app/components/chatMessage/chatMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@ import {
Shapes,
Trash,
Toolbox,
Clipboard,
} from "@phosphor-icons/react";

import DOMPurify from "dompurify";
import { InlineLoading } from "../loading/loading";
import { convertColorToTextClass } from "@/app/common/colorUtils";
import { convertColorToTextClass } from "@/app.common/colorUtils";
import { AgentData } from "@/app/components/agentCard/agentCard";

import renderMathInElement from "katex/contrib/auto-render";
Expand Down Expand Up @@ -678,6 +679,22 @@ const ChatMessage = forwardRef<HTMLDivElement, ChatMessageProps>((props, ref) =>
props.chatMessage.codeContext,
);

const copyReferencesToClipboard = () => {
const allReferencesMarkdown = [
...allReferences.notesReferenceCardData.map(
(note) => `- [${note.title}](#)`,
),
...allReferences.onlineReferenceCardData.map(
(online) => `- [${online.title}](${online.link})`,
),
...allReferences.codeReferenceCardData.map(
(code) => `- [Code Reference](#)`,
),
].join("\n");

navigator.clipboard.writeText(allReferencesMarkdown);
};

return (
<div
ref={ref}
Expand Down Expand Up @@ -808,6 +825,16 @@ const ChatMessage = forwardRef<HTMLDivElement, ChatMessageProps>((props, ref) =>
/>
)}
</button>
<button
title="Copy References"
className={`${styles.copyButton}`}
onClick={copyReferencesToClipboard}
>
<Clipboard
alt="Copy References"
className="hsl(var(--muted-foreground)) hover:text-green-500"
/>
</button>
{props.chatMessage.by === "khoj" &&
(props.chatMessage.intent ? (
<FeedbackButtons
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { useEffect, useState } from "react";

import { ArrowCircleDown, ArrowRight, Code, Note } from "@phosphor-icons/react";
import { ArrowCircleDown, ArrowRight, Code, Note, Clipboard } from "@phosphor-icons/react";

import markdownIt from "markdown-it";
const md = new markdownIt({
Expand Down Expand Up @@ -32,6 +32,7 @@ import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover
import DOMPurify from "dompurify";
import { getIconFromFilename } from "@/app/common/iconUtils";
import Link from "next/link";
import { Button } from "@/components/ui/button";

interface NotesContextReferenceData {
title: string;
Expand Down Expand Up @@ -606,6 +607,22 @@ export default function ReferencePanel(props: ReferencePanelDataProps) {
.slice(0, numTeaserSlots - codeDataToShow.length - notesDataToShow.length)
: [];

const copyReferencesToClipboard = () => {
const allReferences = [
...props.notesReferenceCardData.map(
(note) => `- [${note.title}](#)`,
),
...props.onlineReferenceCardData.map(
(online) => `- [${online.title}](${online.link})`,
),
...props.codeReferenceCardData.map(
(code) => `- [Code Reference](#)`,
),
].join("\n");

navigator.clipboard.writeText(allReferences);
};

return (
<Sheet>
<SheetTrigger className="text-balance w-auto justify-start overflow-hidden break-words p-0 bg-transparent border-none text-gray-400 align-middle items-center m-0 inline-flex">
Expand Down Expand Up @@ -642,6 +659,14 @@ export default function ReferencePanel(props: ReferencePanelDataProps) {
<SheetHeader>
<SheetTitle>References</SheetTitle>
<SheetDescription>View all references for this response</SheetDescription>
<Button
variant="outline"
onClick={copyReferencesToClipboard}
className="mt-4"
>
<Clipboard className="mr-2" />
Copy References
</Button>
</SheetHeader>
<div className="flex flex-wrap gap-2 w-auto mt-2">
{props.codeReferenceCardData.map((code, index) => {
Expand Down