Skip to content

Commit

Permalink
Added search and memory bug fixes (#265)
Browse files Browse the repository at this point in the history
* Mem0 add memory fix

* Search new chat fix
  • Loading branch information
nang-dev authored Feb 11, 2025
1 parent 353982e commit a5081b7
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 37 deletions.
1 change: 0 additions & 1 deletion core/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,6 @@ export class Core {
msg: Message<ToCoreProtocol["llm/streamChat"][0]>,
) {
const model = await configHandler.llmFromTitle(msg.data.title);
console.log("IM HERE99")
console.log(model)
const gen = model.streamChat(
msg.data.messages,
Expand Down
2 changes: 2 additions & 0 deletions core/protocol/ideWebview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export type ToIdeFromWebviewProtocol = ToIdeFromWebviewOrCoreProtocol & {
lastChat: [undefined, void];
closeChat: [undefined, void];
openHistory: [undefined, void];
openHistorySearch: [undefined, void];
appendSelected: [undefined, void];
pearaiLogin: [undefined, void];
closePearAIOverlay: [undefined, void];
Expand Down Expand Up @@ -98,6 +99,7 @@ export type ToWebviewFromIdeProtocol = ToWebviewFromIdeOrCoreProtocol & {
openSettings: [undefined, void];
viewHistory: [undefined, void];
newSession: [undefined, void];
newSessionSearch: [undefined, void];
quickEdit: [undefined, void];
acceptedOrRejectedDiff: [undefined, void];
setTheme: [{ theme: any }, void];
Expand Down
2 changes: 1 addition & 1 deletion extensions/vscode/src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ const commandsMap: (
sidebar.webviewProtocol?.request("setActiveFilePath", currentFile, [PEARAI_CHAT_VIEW_ID]);
},
"pearai.newSessionSearch": async () => {
sidebar.webviewProtocol?.request("newSession", undefined, [PEARAI_SEARCH_VIEW_ID]);
sidebar.webviewProtocol?.request("newSessionSearch", undefined, [PEARAI_SEARCH_VIEW_ID]);
const currentFile = await ide.getCurrentFile();
sidebar.webviewProtocol?.request("setActiveFilePath", currentFile, [PEARAI_SEARCH_VIEW_ID]);
},
Expand Down
10 changes: 5 additions & 5 deletions gui/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ const router = createMemoryRouter(
},
{
path: "/",
element: window.viewType === 'pearai.chatView' ? <GUI /> :
window.viewType === 'pearai.searchView' ? <PerplexityGUI /> :
window.viewType === 'pearai.mem0View' ? <Mem0SidebarGUI /> :
element: window.viewType === 'pearai.chatView' ? <GUI /> :
window.viewType === 'pearai.searchView' ? <PerplexityGUI /> :
window.viewType === 'pearai.mem0View' ? <Mem0SidebarGUI /> :
<GUI />, // default to GUI if viewType is undefined or different

},
Expand All @@ -70,7 +70,7 @@ const router = createMemoryRouter(
element: <History from={
window.viewType === 'pearai.chatView' ? 'continue' :
window.viewType === 'pearai.searchView' ? 'perplexity' :
window.viewType === 'pearai.mem0View' ? 'aider' :
window.viewType === 'pearai.mem0View' ? 'aider' :
'continue' // default fallback
}/>
},
Expand Down Expand Up @@ -143,7 +143,7 @@ const router = createMemoryRouter(
// FOR DEV'ing welcome:
// initialEntries: [window.isPearOverlay ? "/welcome" : window.initialRoute],
},

);


Expand Down
2 changes: 1 addition & 1 deletion gui/src/integrations/mem0/Mem0SidebarGUI.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ export default function Mem0SidebarGUI() {
}

if (memories.length === 0) {
return <EmptyView />;
return <EmptyView onAddMemory={handleAddNewMemory} />;
}

if (filteredMemories.length === 0) {
Expand Down
10 changes: 7 additions & 3 deletions gui/src/integrations/mem0/StatusViews.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export const LoadingView = () => (
</StatusViewLayout>
);

export const EmptyView = () => (
export const EmptyView = ({ onAddMemory }: { onAddMemory: () => void }) => (
<StatusViewLayout>
<ContentWrapper>
<div className="text-2xl font-['SF Pro']">PearAI Memory</div>
Expand All @@ -95,7 +95,11 @@ export const EmptyView = () => (
<div className="w-[300px] text-left opacity-50 text-xs font-normal font-['SF Pro'] leading-[18px]">
No memories yet– PearAI Memory automatically remembers coding information as you use PearAI Chat.
</div>
<Button variant="secondary" className="w-[300px] flex items-center gap-2">
<Button
variant="secondary"
className="w-[300px] flex items-center gap-2"
onClick={onAddMemory}
>
<div className="flex items-center gap-2">
<PencilSquareIcon className="w-5 h-5" />
<span className="flex items-center">Add Memory</span>
Expand All @@ -113,4 +117,4 @@ export const NoResultsView = () => (
</div>
</ContentWrapper>
</StatusViewLayout>
);
);
46 changes: 23 additions & 23 deletions gui/src/integrations/mem0/mem0gui.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ function formatTimestamp(timestamp: string): string {
yesterday.setDate(yesterday.getDate() - 1);
const oneWeekAgo = new Date(now);
oneWeekAgo.setDate(oneWeekAgo.getDate() - 7);

// Check if same day
if (date.toDateString() === now.toDateString()) {
return 'Today';
Expand All @@ -96,7 +96,7 @@ function formatTimestamp(timestamp: string): string {
return 'This week';
}
// Otherwise return formatted date
return date.toLocaleDateString('en-US', {
return date.toLocaleDateString('en-US', {
year: 'numeric',
month: 'short',
day: 'numeric'
Expand Down Expand Up @@ -186,7 +186,7 @@ export default function Mem0GUI() {
const response = await ideMessenger.request('mem0/updateMemories', {
changes: unsavedChanges
});

if (response) {
await fetchMemories();
}
Expand Down Expand Up @@ -250,15 +250,15 @@ export default function Mem0GUI() {
}];
}
});

dispatch(setMem0Memories(
memories.map(memory =>
memories.map(memory =>
memory.id === editingId
? { ...memory, content: editedContent, isModified: true }
: memory
)
));

setEditingId(null);
setEditedContent("");
};
Expand Down Expand Up @@ -301,11 +301,11 @@ export default function Mem0GUI() {

// Update filteredMemories to use memories state
const filteredMemories = useMemo(() => {
return memories.filter(memory =>
return memories.filter(memory =>
memory.content.toLowerCase().includes(searchQuery.toLowerCase())
);
}, [searchQuery, memories]);


// Get total pages based on filtered results
const totalPages = Math.ceil(filteredMemories.length / memoriesPerPage);
Expand Down Expand Up @@ -348,7 +348,7 @@ export default function Mem0GUI() {
});

dispatch(setMem0Memories(memories.map(memory =>
memory.id === memoryId
memory.id === memoryId
? { ...memory, isDeleted: true }
: memory
)));
Expand Down Expand Up @@ -378,7 +378,7 @@ export default function Mem0GUI() {
}

if (memories.length === 0) {
return <EmptyView />;
return <EmptyView onAddMemory={handleAddNewMemory} />;
}

if (filteredMemories.length === 0) {
Expand Down Expand Up @@ -465,8 +465,8 @@ export default function Mem0GUI() {
/>
) :
getCurrentPageMemories().map((memory: Memory) => (
<Card
key={memory.id}
<Card
key={memory.id}
className={`p-2 bg-input hover:bg-input/90 hover:cursor-pointer transition-colors mx-auto
${memory.isDeleted ? 'opacity-50' : ''}
${memory.isModified ? 'border-l-4 border-l-yellow-500' : ''}`}
Expand Down Expand Up @@ -511,19 +511,19 @@ export default function Mem0GUI() {
) : memory.isDeleted ? (
<div className="flex-row items-center gap-2">
<span className="text-xs text-red-500">(deleted)</span>
<Button
variant="ghost"
<Button
variant="ghost"
size="sm"
onClick={(e) => {
e.stopPropagation();
// Remove the delete change
setUnsavedChanges(prev => prev.filter(change =>
setUnsavedChanges(prev => prev.filter(change =>
!(change.type === 'delete' && change.id === memory.id)
));

// Restore the memory
dispatch(setMem0Memories(memories.map(m =>
m.id === memory.id
dispatch(setMem0Memories(memories.map(m =>
m.id === memory.id
? { ...m, isDeleted: false }
: m
)));
Expand Down Expand Up @@ -569,8 +569,8 @@ export default function Mem0GUI() {
</Card>
))}
</div>


<div className="mt-6 mb-4 flex items-center">
{/* Centered Save/Cancel buttons */}
{unsavedChanges.length > 0 && (
Expand All @@ -590,7 +590,7 @@ export default function Mem0GUI() {
</Button>
</div>
)}

<div className="flex flex-1 justify-end mb-4">
<div className="flex items-center gap-2 text-sm text-muted-foreground">
{filteredMemories.length > 0 && (
Expand All @@ -600,7 +600,7 @@ export default function Mem0GUI() {
className={`px-2 py-1 ${currentPage === 1 ? 'opacity-50 cursor-not-allowed' : 'hover:text-foreground'}`}
>
<ChevronLeftIcon
color={lightGray}
color={lightGray}
width="1.2em"
height="1.2em"
onClick={handlePrevPage}
Expand All @@ -612,7 +612,7 @@ export default function Mem0GUI() {
className={`px-2 py-1 ${currentPage === totalPages ? 'opacity-50 cursor-not-allowed' : 'hover:text-foreground'}`}
>
<ChevronRightIcon
color={lightGray}
color={lightGray}
width="1.2em"
height="1.2em"
onClick={handleNextPage}
Expand Down
3 changes: 2 additions & 1 deletion gui/src/integrations/perplexity/PerplexitySidebarGUI.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ function PerplexitySidebarGUI() {
async () => {
saveSession();
sessionKeyRef.current += 1;
mainTextInputRef.current?.focus?.();
},
[saveSession],
);
Expand Down Expand Up @@ -513,7 +514,7 @@ function PerplexitySidebarGUI() {
{!active && (
<div className="flex justify-center p-3">
<div className="max-w-3xl w-full">
<InputContainer
<InputContainer
ref={inputContainerRef}
isNewSession={state.perplexityHistory.length === 0}
>
Expand Down
4 changes: 2 additions & 2 deletions gui/src/integrations/perplexity/perplexitygui.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,9 @@ function PerplexityGUI() {
const sessionKeyRef = useRef(0);

useWebviewListener(
"newSession",
"newSessionSearch",
async () => {
saveSession();
await saveSession();
sessionKeyRef.current += 1;
},
[saveSession],
Expand Down

0 comments on commit a5081b7

Please sign in to comment.