Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hyperlinked citation + padding + separate new session button #160

Merged
merged 3 commits into from
Nov 14, 2024
Merged
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
2 changes: 1 addition & 1 deletion extensions/vscode/src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ const commandsMap: (
ide.runCommand(text);
},
"pearai.newSession": async () => {
sidebar.webviewProtocol?.request("newSession", undefined);
sidebar.webviewProtocol?.request("newSession", undefined, [PEAR_CONTINUE_VIEW_ID]);
const currentFile = await ide.getCurrentFile();
sidebar.webviewProtocol?.request("setActiveFilePath", currentFile, [PEAR_CONTINUE_VIEW_ID]);
},
Expand Down
2 changes: 2 additions & 0 deletions gui/src/components/gui/StepContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ function StepContainer({
<div>
<div className="relative">
<ContentDiv
className="max-w-4xl mx-auto"
hidden={!open}
isUserInput={isUserInput}
fontSize={getFontSize()}
Expand All @@ -184,6 +185,7 @@ function StepContainer({
isLast={isLast}
messageIndex={index}
integrationSource={source}
citations={isPerplexity ? item.citations : undefined}
/>
)}
</ContentDiv>
Expand Down
16 changes: 16 additions & 0 deletions gui/src/components/markdown/StyledMarkdownPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import PreWithToolbar from "./PreWithToolbar";
import { SyntaxHighlightedPre } from "./SyntaxHighlightedPre";
import "./katex.css";
import "./markdown.css";
import { Citation } from "core";

const StyledMarkdown = styled.div<{
fontSize?: number;
Expand Down Expand Up @@ -94,6 +95,7 @@ interface StyledMarkdownPreviewProps {
isLast?: boolean;
messageIndex?: number;
integrationSource?: "perplexity" | "aider" | "continue";
citations?: Citation[];
}

interface FadeInWordsProps extends StyledMarkdownPreviewProps {
Expand Down Expand Up @@ -211,6 +213,15 @@ const FadeInElement: React.FC<FadeInElementProps> = (props: FadeInElementProps)
return <ElementType {...otherProps}>{words}</ElementType>;
};

const processCitations = (text: string, citations?: Citation[]) => {
if (!citations) return text;

return text.replace(/\[(\d+)\]/g, (match, num) => {
const citation = citations[parseInt(num) - 1];
if (!citation) return match;
return `[[${num}]](${citation.url})`;
});
};


const StyledMarkdownPreview = memo(function StyledMarkdownPreview(
Expand Down Expand Up @@ -385,6 +396,11 @@ const StyledMarkdownPreview = memo(function StyledMarkdownPreview(
setMarkdownSource(props.source || "");
}, [props.source]);

useEffect(() => {
const processedSource = processCitations(props.source || "", props.citations);
setMarkdownSource(processedSource);
}, [props.source, props.citations]);

return (
<StyledMarkdown fontSize={getFontSize()} showBorder={false}>
{reactContent}
Expand Down
2 changes: 1 addition & 1 deletion gui/src/integrations/perplexity/Citations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export const Citations = ({ citations, className, isLast, active}: CitationsProp
<div className="overflow-x-auto pb-2">
<div className="flex space-x-2">
{citations.map((citation, i) => (
<CitationCard
<CitationCard
key={citation.url}
citation={citation}
isLast={isLast}
Expand Down
4 changes: 2 additions & 2 deletions gui/src/integrations/perplexity/perplexitygui.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import React from "react";
import { ChatBubbleOvalLeftIcon } from "@heroicons/react/24/outline";
import { JSONContent } from "@tiptap/react";
import { InputModifiers } from "core";
Expand Down Expand Up @@ -124,7 +125,6 @@ function PerplexityGUI() {
!e.shiftKey
) {
saveSession();
ideMessenger.post("aiderResetSession", undefined);
}
};
window.addEventListener("keydown", listener);
Expand Down Expand Up @@ -319,7 +319,7 @@ function PerplexityGUI() {
}
active={active}
/> }
<StepContainer
<StepContainer
index={index}
isLast={
index === sessionState.perplexityHistory.length - 1
Expand Down